mix foundry.project.context (Foundry v0.4.0)

Copy Markdown View Source

Generates project context for Foundry modules.

Usage

mix foundry.project.context <Module>            # Per-module context
mix foundry.project.context <Module> --json     # Same (--json accepted, output is always JSON)
mix foundry.project.context                     # Bulk project context
mix foundry.project.context --output ctx.json   # Bulk context, written to a file
mix foundry.project.context --check             # Check lock freshness

Options

  • --json - Accepted for agent compatibility; output is always JSON regardless of this flag.
  • --check - Check if context.lock is current instead of generating context.
  • --output PATH - Write the JSON to PATH instead of stdout.

Why --output exists (ADR-036)

The Studio reads a target project's context by running this task inside that project as a subprocess, rather than loading the target's BEAM files into its own VM. That only works if the JSON can be recovered unambiguously, and it cannot be recovered from stdout: this task runs mix compile first, and the compiler writes to the same stream. With --output the JSON lands in a file the caller named and stdout is free to carry whatever the build says.

Exit codes

  • 0 - the context was produced. With --output, the file exists and parses.
  • 1 - .foundry/manifest.exs is absent or unparseable.
  • 2 - the target project failed to compile.

Forms

  • mix foundry.project.context <Module>: Returns JSON context for a single module
  • mix foundry.project.context: Returns bulk context for all modules in project
  • mix foundry.project.context --check: Checks if mix.lock is current

Summary

Functions

Callback implementation for Mix.Task.run/1.

Emit bulk JSON context for all modules. Separated from run/1 so tests can call this without triggering Mix.Task.run("compile") / Mix.Sync.PubSub startup. Returns {:ok, json_string}.

Check if context.lock is current. Returns :ok or {:error, reason}.

Emit JSON context for a single module. Separated from run/1 so tests can call this without triggering Mix.Task.run("compile") / Mix.Sync.PubSub startup. Returns {:ok, json_string} or {:error, reason}.

Functions

run(args)

Callback implementation for Mix.Task.run/1.

run_bulk(project_root, output \\ nil)

Emit bulk JSON context for all modules. Separated from run/1 so tests can call this without triggering Mix.Task.run("compile") / Mix.Sync.PubSub startup. Returns {:ok, json_string}.

run_check(project_root)

Check if context.lock is current. Returns :ok or {:error, reason}.

run_single(module_name, project_root)

Emit JSON context for a single module. Separated from run/1 so tests can call this without triggering Mix.Task.run("compile") / Mix.Sync.PubSub startup. Returns {:ok, json_string} or {:error, reason}.