# AgentTeam Insight Domain Graph Generation

> Canonical path: `specs/architecture/agentteam-insight-domain-generation.md`

## Contract

`agentteam-insight domain` derives `.agentteam-insight/domain-graph.json` from an existing
`.agentteam-insight/knowledge-graph.json`. The command implements Understand
Anything's existing-graph domain-analysis path; it does not scan or sample the
source repository. Callers must run `agentteam-insight graph` first.

The generation path is deliberately single-stage:

1. resolve the same input/output layout used by `agentteam-insight graph`;
2. read and validate the complete knowledge graph;
3. invoke the pinned Understand Anything `domain-analyzer` prompt once, with
   the complete graph as structured context;
4. validate the response through the standard graph schema plus the
   domain/flow/step hierarchy rules; and
5. atomically replace `domain-graph.json`.

An invalid input graph must fail before an LLM call. An LLM, parse, or
validation failure must leave an existing domain graph unchanged.

## Ownership and reuse

The graph builder owns this behavior:

- `graphbuilder` owns command orchestration and artifact layout;
- `graphbuilder/semantic` owns the pinned prompt and uses the same OpenCode
  runner, model, agent, timeout, isolation, and credential lifecycle as graph
  semantic generation;
- `graphbuilder/schema` owns the shared graph schema and the small domain-shape
  invariant; and
- `graphbuilder/persistence` owns validated atomic writes.

Domain generation must not introduce a separate provider client, credential
resolver, OpenCode server, scanner, partitioner, queue, checkpoint, recovery
journal, or persistent run state. It is one bounded transformation of one
existing artifact.

## Output shape

The output contains only `domain`, `flow`, and `step` nodes, connected by
`contains_flow`, `flow_step`, and optional `cross_domain` edges. Every flow and
step has a parent edge. `layers` and `tour` are empty because the dashboard uses
the domain view for this artifact.
