Cohere.Project (Cohere v0.1.0)

Copy Markdown View Source

Discovers the host project: its OTP app, module inventory, namespaces, and which coherence-relevant capabilities are present.

Capability detection is probing, never requiring: cohere has zero runtime dependencies, so every capability is checked with Code.ensure_loaded?/1 against a marker module. More installed → more derived; nothing installed beyond Elixir is still a working (if sparse) map.

Summary

Functions

Files changed on this branch relative to base — the merge base's diff plus untracked source. Plumbing only, never porcelain, so it is stable across git versions. Shared by mix cohere.packet --diff and mix cohere.design context inference; never called from check paths, which stay git-free (INV-DRI-001).

Directory holding authored design docs.

Whether a capability was detected.

Directory holding authored intent cards.

Loads the project description for the current Mix project.

Path to the derived map file.

Maps each source file (relative to the project root) to the modules compiled from it, by reflecting over module_info(:compile).

Types

derived_registration()

@type derived_registration() ::
  {name :: String.t(), path :: String.t(), {module(), atom()},
   fix :: String.t()}

t()

@type t() :: %Cohere.Project{
  app: atom(),
  capabilities: %{required(atom()) => String.t() | nil},
  derived: [derived_registration()],
  dir: String.t(),
  modules: [module()],
  namespace: module(),
  web_namespace: module() | nil
}

Functions

changed_files(base)

@spec changed_files(String.t()) :: {:ok, [String.t()]} | {:error, String.t()}

Files changed on this branch relative to base — the merge base's diff plus untracked source. Plumbing only, never porcelain, so it is stable across git versions. Shared by mix cohere.packet --diff and mix cohere.design context inference; never called from check paths, which stay git-free (INV-DRI-001).

Returns {:ok, files} or {:error, message}.

design_dir(project)

Directory holding authored design docs.

has?(project, cap)

Whether a capability was detected.

intent_dir(project)

Directory holding authored intent cards.

load(opts \\ [])

@spec load(keyword()) :: t()

Loads the project description for the current Mix project.

Options (all default to Mix/application-derived values, overridable via config :cohere, ... in the host app):

  • :app — the OTP app to introspect
  • :namespace — base module namespace (default: camelized app name)
  • :web_namespace — web namespace (default: <Namespace>Web when present)
  • :modules — explicit module list (used by tests)
  • :dir — directory where cohere artifacts live (default "cohere")

map_path(project)

Path to the derived map file.

source_index(project)

@spec source_index(t()) :: %{required(String.t()) => [module()]}

Maps each source file (relative to the project root) to the modules compiled from it, by reflecting over module_info(:compile).

This is how a set of changed files becomes the contexts they belong to: reflection over compiled artifacts, never a path→module naming convention. A file compiled outside the current root (e.g. a build cache on another machine) relativizes to an absolute path and simply won't match a repo-relative diff entry — it drops out rather than mapping wrongly.