Skip to content

Fix agent-gen output location: route templates to af source tree #4

Description

@stempeck

Problem

When agent-gen or agent-gen-all.sh runs from a target project (e.g., ~/af/myproject/), it writes all artifacts — including Go role templates (.md.tmpl) — relative to the factory root. Templates need to be in the af source tree's internal/templates/roles/ directory for Go's //go:embed to compile them into the binary. Users must manually mv/cp files before running make build. This is too many steps for newcomers.

Goal

After running agent-gen, the only step a user needs is quickstart.sh — no manual file moves.

Design

Full design document and PR: #3

Design artifacts in .designs/af-5836e28c/:

  • [design-doc.md] — Synthesized design with implementation plan
  • [api.md] — API & interface design
  • [data.md] — Data model analysis
  • [ux.md] — User experience analysis
  • [security.md] — Security analysis
  • [integration.md] — Integration analysis
  • [scale.md] — Scalability analysis
  • [constraints.md] — Constraint definitions
  • [constraint-audit.md] — Constraint verification
  • [conflicts.md] — Conflict matrix
  • [dependencies.md] — Dependency graph
  • [problem-summary.md] — Problem analysis

Implementation Plan (from design-doc.md)

Phase 1: Source Root Resolution (Small)

  • New file internal/config/source_root.go with ResolveSourceRoot(), isAgentFactorySourceTree(), SetBuildSourceRoot()
  • Unit tests in internal/config/source_root_test.go
  • One-line addition to cmd/af/main.go

Phase 2: Formula.go Integration (Small)

  • Update runFormulaAgentGen() to route templates to source root
  • Update runFormulaAgentGenDelete() for cleanup
  • Update output messages and existing tests

Phase 3: Script Updates (Trivial)

  • Add export AF_SOURCE_ROOT="$AF_SRC" to agent-gen-all.sh
  • Verify quickstart.sh already handles it (it does)

Acceptance Criteria

  • ResolveSourceRoot() returns factory root when it contains agentfactory go.mod
  • ResolveSourceRoot() returns AF_SOURCE_ROOT when factory root is not source tree
  • ResolveSourceRoot() returns error when neither is available
  • All resolution paths validated with go.mod check
  • Templates written to source root's internal/templates/roles/
  • Workspace artifacts written to factory root's .agentfactory/agents/
  • Source root resolution happens AFTER -o early return
  • --delete removes template from source root
  • agent-gen-all.sh sets AF_SOURCE_ROOT before calling agent-gen
  • quickstart.sh continues to work unchanged
  • make test passes

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions