Fix agent-gen output location: route templates to af source tree#3
Fix agent-gen output location: route templates to af source tree#3stempeck wants to merge 3 commits into
Conversation
Analyzes the agent-gen output location problem across 6 dimensions: API, Data, UX, Scale, Security, and Integration. Recommends a shared config.ResolveSourceRoot() function that reuses the existing AF_SOURCE_ROOT pattern to route .md.tmpl files to the af source tree. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unified design for fixing agent-gen output location. Adds config.ResolveSourceRoot() to route templates to the af source tree while keeping workspace artifacts in the factory root. Reuses existing AF_SOURCE_ROOT pattern. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
agentfactory seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Add config.ResolveSourceRoot() that determines the agentfactory source tree via go.mod detection, build-time path, or AF_SOURCE_ROOT env var. Update formula.go to write .md.tmpl files to the resolved source root while keeping workspace artifacts in the factory root. Update agent-gen-all.sh to export AF_SOURCE_ROOT. Closes #4 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
stempeck
left a comment
There was a problem hiding this comment.
Code Review: agent-gen source root routing
Reviewer: investigate agent (automated)
Summary
PR adds config.ResolveSourceRoot() to route agent-gen .md.tmpl template writes to the af source tree instead of the factory root. The implementation is clean, follows the existing mcpstore pattern, and all non-delete tests pass.
Affected Files
| File | Status | Purpose |
|---|---|---|
internal/config/source_root.go |
NEW | Three-tier resolution: factoryRoot go.mod → buildSourceRoot → envSourceRoot |
internal/config/source_root_test.go |
NEW | 8 tests covering all tiers, priority, and edge cases |
internal/cmd/formula.go |
MODIFIED | Create/delete paths now use srcRoot for templates |
internal/cmd/formula_test.go |
MODIFIED | Test fixtures updated with go.mod |
cmd/af/main.go |
MODIFIED | Wires SetBuildSourceRoot/SetEnvSourceRoot at startup |
agent-gen-all.sh |
MODIFIED | Exports AF_SOURCE_ROOT |
Findings
- Three-tier resolution is correct — factoryRoot wins (self-hosted), then build-time, then env var. Priority tests confirm this.
- formula.go integration is correct — Templates go to
srcRoot/internal/templates/roles/, workspace artifacts stay infactoryRoot/.agentfactory/agents/. Source root resolution happens after-oearly return (no unnecessary resolution on dry run). - Tests are thorough — 8 unit tests for source_root.go, plus existing formula_test.go updated.
- Delete test failures are pre-existing — 6 delete tests fail due to live tmux session collision, not caused by this PR.
Gotchas
- Package-level mutable state (
buildSourceRoot/envSourceRoot) — tests must reset them. Current tests handle this correctly. - Loose go.mod matching —
strings.Contains(line, "agentfactory")could match unintended module names. Adequate for now; could be tightened to exact module path match later. - Duplicate pattern —
config.ResolveSourceRootandmcpstore.ResolvePyPathsolve the same fundamental problem with slightly different validation. Potential unification is out of scope. - Strict error on invalid buildSourceRoot — Hard-errors if set but invalid (stricter than mcpstore's silent fallthrough). This is the better approach — catches misconfiguration early.
Verdict
Approve with minor notes. Implementation is clean, well-tested, and solves the stated problem. The loose go.mod matching (gotcha #2) is the only thing worth tightening in a follow-up.
|
Example pull request testing a one-shot end-to-end workflow after providing the The github issue associated with this PR: #4 |
Summary
config.ResolveSourceRoot()with three-tier resolution: go.mod detection (self-hosted), build-time path,AF_SOURCE_ROOTenv varformula.goto write.md.tmpltemplates to the resolved source root while keeping workspace artifacts in factory rootAF_SOURCE_ROOTinagent-gen-all.shCloses #4
Implementation
Phase 1 —
internal/config/source_root.go:ResolveSourceRoot(),isAgentFactorySourceTree(),SetBuildSourceRoot(),SetEnvSourceRoot()Phase 2 —
internal/cmd/formula.go: routes template writes to source root in both create and delete pathsPhase 3 —
agent-gen-all.sh: exportsAF_SOURCE_ROOT="$AF_SRC"Test plan
ResolveSourceRoot()returns factory root when it contains agentfactory go.modResolveSourceRoot()returnsAF_SOURCE_ROOTwhen factory root is not source treeResolveSourceRoot()returns error when neither is availableinternal/templates/roles/.agentfactory/agents/-oearly return--deleteremoves template from source rootagent-gen-all.shsetsAF_SOURCE_ROOTbefore calling agent-gen🤖 Generated with Claude Code