defmodule Vibe do @moduledoc """ Vibe Coding - Help LLMs interact with your Elixir codebase. This package provides mix tasks that make it easier for LLM agents to interact with Elixir codebases in a fun, playful, but practical way. ## Usage To enable tracing in a module: use Vibe, enabled: true def my_function do vibe("This is a tracing log", variable: value) end The `vibe/1` function will only output logs when enabled is set to true. """ defmacro __using__(opts) do enabled = Keyword.get(opts, :enabled, false) quote do use ExDbug, enabled: unquote(enabled) def vibe(message, vars \\ []) do dbug(message, vars) end end end @doc """ Get the configured output format. ## Examples iex> Vibe.output_format() :markdown """ def output_format do Application.get_env(:vibe, :output_format, :markdown) end @doc """ Check if showing timing information is enabled. ## Examples iex> Vibe.show_timing?() true """ def show_timing? do Application.get_env(:vibe, :show_timing, true) end @doc """ Check if verbose mode is enabled. ## Examples iex> Vibe.verbose?() false """ def verbose? do Application.get_env(:vibe, :verbose, false) end @doc """ Format output based on the configured output format. ## Examples iex> Vibe.format_output("Hello world") "Hello world" iex> map = %{hello: "world"} iex> result = Vibe.format_output(map) iex> String.contains?(result, "hello") and String.contains?(result, "world") true """ def format_output(data, format \\ nil) do format = format || output_format() case format do :json -> Jason.encode!(data, pretty: true) :markdown when is_map(data) or is_list(data) -> "```json\n#{Jason.encode!(data, pretty: true)}\n```" :markdown when is_binary(data) -> if String.contains?(data, "\n") do "```\n#{data}\n```" else data end _ -> if is_map(data) or is_list(data) do Jason.encode!(data, pretty: true) else to_string(data) end end end end