fix(cli): strip removed library from AGENTS.md on ask remove#98
Merged
fix(cli): strip removed library from AGENTS.md on ask remove#98
Conversation
When the last library was removed from ask.json, the auto-generated block in AGENTS.md lingered because both runInstall (short-circuit on empty targets) and generateAgentsMd (early return on empty input) skipped regeneration. Now runInstall explicitly regenerates AGENTS.md when the full install has zero targets, and generateAgentsMd strips the existing marker block (deleting AGENTS.md when only the block remains, preserving any user-authored content otherwise).
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Deploying ask-registry with
|
| Latest commit: |
1675e4e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://1d4de86c.ask-registry.pages.dev |
| Branch Preview URL: | https://amondnet-fix-remove-agents-m.ask-registry.pages.dev |
4 tasks
Contributor
There was a problem hiding this comment.
No issues found across 3 files
Requires human review: Modifies core CLI logic and handles file deletions based on manual string parsing of project files. This logic change in a core path warrants human review to ensure no data loss edge cases.
Architecture diagram
sequenceDiagram
participant User
participant CLI as CLI Engine
participant Install as runInstall()
participant Agents as generateAgentsMd()
participant FS as File System (AGENTS.md)
participant Ignore as manageIgnoreFiles()
User->>CLI: ask remove [library]
CLI->>FS: Update ask.json
CLI->>Install: sync state
Note over Install,FS: Handling Last Library Removal
alt targets.length == 0
Install->>Install: Detect empty targets
rect rgb(240, 240, 240)
Note right of Install: CHANGED: Previously short-circuited here
Install->>Agents: NEW: generateAgentsMd(projectDir, [])
Agents->>FS: Check if AGENTS.md exists
opt File exists
Agents->>FS: Read AGENTS.md content
Agents->>Agents: NEW: Strip <!-- BEGIN/END --> block
alt Only auto-generated block existed
Agents->>FS: NEW: Delete AGENTS.md (fs.rmSync)
else User-authored content remains
Agents->>FS: NEW: Overwrite AGENTS.md (fs.writeFileSync)
end
end
Agents-->>Install: return empty string
end
Install->>Ignore: NEW: manageIgnoreFiles(projectDir, 'remove')
else targets.length > 0
Install->>Install: Resolve remaining libraries
Install->>Agents: generateAgentsMd(projectDir, libraries)
Agents->>FS: Update AGENTS.md block
Install->>Ignore: manageIgnoreFiles(projectDir, 'add')
end
Install-->>CLI: Return summary
CLI-->>User: Operation complete
…markers Iteration 1 review surfaced four concerns: - `--only-specs` guard in runInstall was untested - Malformed marker pairs (only BEGIN or only END) in AGENTS.md were silently skipped in the strip branch, and a follow-up install would splice new content into the orphan, compounding corruption - Block-at-top layout (user content after) was not exercised - The strip branch had no diagnostic when it encountered mismatched markers This commit adds a `consola.warn` for the mismatched-marker case so operators can repair AGENTS.md by hand instead of watching further corruption stack up, and adds three regression tests covering each gap.
Iteration 2 review flagged that the orphan-marker regression only exercised the BEGIN-only branch, leaving the END-only side of the OR guard (agents.ts:44) uncovered. Parametrize the case table so both halves of the guard are locked in.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ask removeleaving the removed library's section (or the whole auto-generated block) inAGENTS.mdwhen the last entry is removed fromask.jsonrunInstallnow regeneratesAGENTS.mdeven when the full install has zero targets (previously short-circuited without touching the file)generateAgentsMdnow strips the existing<!-- BEGIN:ask-docs-auto-generated --> … <!-- END -->block on empty input: deletesAGENTS.mdwhen only the block remained, preserves user-authored content otherwiseRoot cause
Two cooperating early returns skipped regeneration when
askJson.librariesbecame empty:runInstallshort-circuited ontargets.length === 0before callinggenerateAgentsMdgenerateAgentsMdreturned''onlibraries.length === 0without touchingAGENTS.mdThe happy path (remove a non-last library) worked because
runInstallstill hit the regeneration call with the remaining libraries.Test plan
bun run --cwd packages/cli test test/install/remove.test.ts— 4 passbun run --cwd packages/cli test— 473 pass / 0 failbun run --cwd packages/cli lint— cleanbun run --cwd packages/cli build— typecheck cleanFollow-up (not in this PR)
ask removestill does not callremoveFromIntentSkillsBlock, so intent-format packages leave their<!-- intent-skills:start -->entries behind. Tracked for a separate PR.Summary by cubic
Fixes
ask removeleaving stale entries inAGENTS.md, ensures the file is cleaned when the last library is removed, and warns on orphaned markers to prevent silent corruption.generateAgentsMd: on empty input, strips the auto-generated block; deletesAGENTS.mdif only the block remained; preserves user content; logs aconsola.warnand leaves the file untouched when markers are mismatched.runInstall: when not scoped with--only-specsand targets are empty, regeneratesAGENTS.mdand updates ignore files; when scoped and no specs match, skips regeneration.--only-specsno-match case.Written for commit 1675e4e. Summary will update on new commits.