refactor(cli): share agent detect/write traversal helpers - #2296
Conversation
✅ Deploy Preview for viteplus-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
@codex review |
detectAgentConflicts and writeAgentInstructions duplicated the same per-path scaffolding: AGENTS.md-first ordering, destination-path dedupe, symlink skip, realpath dedupe, and marker-section check. Since detected conflicts feed conflictDecisions back into the write pass, the two traversals must stay in sync. Extract the identical pure pieces into orderAgentTargetPaths (ordering + destination dedupe) and classifyExistingAgentTarget (per-path classification with caller-owned realpath state). Callers keep their own loops and side effects, so write's mid-loop filesystem mutations still see fresh state.
1ace6b2 to
a769fde
Compare
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a769fdea09
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
path.resolve(projectRoot, p) discards projectRoot for absolute-looking inputs, while writes go through path.join. Match the dedupe key to the actual destination.
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
detectAgentConflictsandwriteAgentInstructionsinpackages/cli/src/utils/agent.tsduplicated ~50 lines of per-path scaffolding: AGENTS.md-first ordering, destination-path dedupe, symlink skip, realpath dedupe, and the marker-section check. Because detected conflicts feedconflictDecisionsback into the write pass, the two traversals must apply identical rules, so the duplication was a real divergence risk rather than just noise.This PR extracts the genuinely identical pure pieces into two helpers while each caller keeps its own loop and side effects:
orderAgentTargetPaths(projectRoot, paths)combines the AGENTS.md-first ordering with dedupe by resolved destination path.classifyExistingAgentTarget(destinationPath, incomingContent, seenRealPaths)classifies an existing file assymlink,duplicate,markers, orconflict, registering realpaths in a caller-owned set.A yielding-iterator extraction was considered and rejected because
writeAgentInstructionsmutates the filesystem mid-loop (writes AGENTS.md first, links later paths to it, registers realpaths of freshly written files), so traversal state must be read at call time per path instead of being precomputed or owned by a generator.Not included: promoting the order-preserving dedupe loops onto
dedupeNamesfromapprove-builds.ts. Only 2 of the 4 inline loops match its return shape, so that is left for a separate change if wanted.Test plan
pnpm test:unit packages/cli/src/utils/__tests__/agent.spec.ts— 25 tests pass.vp check— the only errors are pre-existingversions.spec.tsimports of unbuiltdist/versions.js, unrelated to this change.