Skip to content

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

Open
stempeck wants to merge 3 commits into
mainfrom
af/manager-e4d75b
Open

Fix agent-gen output location: route templates to af source tree#3
stempeck wants to merge 3 commits into
mainfrom
af/manager-e4d75b

Conversation

@stempeck

@stempeck stempeck commented May 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add config.ResolveSourceRoot() with three-tier resolution: go.mod detection (self-hosted), build-time path, AF_SOURCE_ROOT env var
  • Update formula.go to write .md.tmpl templates to the resolved source root while keeping workspace artifacts in factory root
  • Export AF_SOURCE_ROOT in agent-gen-all.sh

Closes #4

Implementation

Phase 1internal/config/source_root.go: ResolveSourceRoot(), isAgentFactorySourceTree(), SetBuildSourceRoot(), SetEnvSourceRoot()

Phase 2internal/cmd/formula.go: routes template writes to source root in both create and delete paths

Phase 3agent-gen-all.sh: exports AF_SOURCE_ROOT="$AF_SRC"

Test plan

  • 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
  • All existing tests pass (except pre-existing unrelated sling test)

🤖 Generated with Claude Code

agentfactory and others added 2 commits May 5, 2026 03:04
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>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


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 stempeck changed the title design: agent-gen output location fix (af-5836e28c) Fix agent-gen output location: route templates to af source tree May 5, 2026

@stempeck stempeck left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Three-tier resolution is correct — factoryRoot wins (self-hosted), then build-time, then env var. Priority tests confirm this.
  2. formula.go integration is correct — Templates go to srcRoot/internal/templates/roles/, workspace artifacts stay in factoryRoot/.agentfactory/agents/. Source root resolution happens after -o early return (no unnecessary resolution on dry run).
  3. Tests are thorough — 8 unit tests for source_root.go, plus existing formula_test.go updated.
  4. Delete test failures are pre-existing — 6 delete tests fail due to live tmux session collision, not caused by this PR.

Gotchas

  1. Package-level mutable state (buildSourceRoot/envSourceRoot) — tests must reset them. Current tests handle this correctly.
  2. Loose go.mod matchingstrings.Contains(line, "agentfactory") could match unintended module names. Adequate for now; could be tightened to exact module path match later.
  3. Duplicate patternconfig.ResolveSourceRoot and mcpstore.ResolvePyPath solve the same fundamental problem with slightly different validation. Potential unification is out of scope.
  4. 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.

@stempeck

stempeck commented May 5, 2026

Copy link
Copy Markdown
Owner Author

Example pull request testing a one-shot end-to-end workflow after providing the manager this guidance:

I need to go to bed for the night. Here is what I need from you. 1. maintain a progress report and mail yourself a reminder to not delete your mail and read your progress report. Also mention the CEO has gone to bed and its up to you to keep the factory running all night. 2. When design-v3 is done, make sure it puts it up in a Pull Request. 3. Create a /github-issue that includes all links to design-v3's documentation and relevant information for implementation. 4. sling the github issue to the rapid-implement agent. 5. rapid-implement will end with a PR, you'll have to check it and maybe sling another agent as-appropriate to do a code review and comment on the PR. Make sense?

The github issue associated with this PR: #4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants