Skip to content

refactor(cli): share agent detect/write traversal helpers - #2296

Merged
fengmk2 merged 4 commits into
voidzero-dev:mainfrom
jong-kyung:refactor/agent-traversal-dedupe
Aug 3, 2026
Merged

refactor(cli): share agent detect/write traversal helpers#2296
fengmk2 merged 4 commits into
voidzero-dev:mainfrom
jong-kyung:refactor/agent-traversal-dedupe

Conversation

@jong-kyung

Copy link
Copy Markdown
Collaborator

Summary

detectAgentConflicts and writeAgentInstructions in packages/cli/src/utils/agent.ts duplicated ~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 feed conflictDecisions back 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 as symlink, duplicate, markers, or conflict, registering realpaths in a caller-owned set.

A yielding-iterator extraction was considered and rejected because writeAgentInstructions mutates 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 dedupeNames from approve-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-existing versions.spec.ts imports of unbuilt dist/versions.js, unrelated to this change.

@netlify

netlify Bot commented Aug 2, 2026

Copy link
Copy Markdown

Deploy Preview for viteplus-preview ready!

Name Link
🔨 Latest commit 05c8615
🔍 Latest deploy log https://app.netlify.com/projects/viteplus-preview/deploys/6a700749d39ec1000854a4e8
😎 Deploy Preview https://deploy-preview-2296--viteplus-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@jong-kyung

Copy link
Copy Markdown
Collaborator Author

@codex review

@jong-kyung jong-kyung self-assigned this Aug 2, 2026
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.
@jong-kyung
jong-kyung force-pushed the refactor/agent-traversal-dedupe branch from 1ace6b2 to a769fde Compare August 2, 2026 13:38
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 4f673ffb04

ℹ️ 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".

@jong-kyung

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread packages/cli/src/utils/agent.ts Outdated
path.resolve(projectRoot, p) discards projectRoot for absolute-looking
inputs, while writes go through path.join. Match the dedupe key to the
actual destination.
@jong-kyung

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 7e18cea83b

ℹ️ 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".

@jong-kyung
jong-kyung marked this pull request as ready for review August 2, 2026 13:51
@jong-kyung
jong-kyung requested a review from fengmk2 August 2, 2026 13:51
@fengmk2
fengmk2 merged commit 60d35d1 into voidzero-dev:main Aug 3, 2026
44 checks passed
@jong-kyung
jong-kyung deleted the refactor/agent-traversal-dedupe branch August 3, 2026 03:25
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.

2 participants