Repository navigation
fix(targets): extend user-symlink preservation to codex and opencode writers - #1094
Merged
tmchow merged 1 commit intoJul 10, 2026
Conversation
…writers The lstat-based preservation contract from the Pi writer fix now covers the Codex and OpenCode writers and the shared cleanup plumbing. The shared moveLegacyArtifactToBackup guard alone protects the OpenCode and Kiro legacy sweeps plus all eight targets of the standalone cleanup command. Codex agent .toml writes, previously fully unconditional, gain manifest-gated guards, and the orphan-sidecar rm in the agent write loop is guarded to match its twin in cleanupRemovedAgents; OpenCode guards run before backupFile so nothing is copied or written through a user symlink. Pi imports the now-shared helpers instead of private copies. The cleanup command's ~/.agents/skills sweep legitimately relocates CE-owned symlinks after verifying their resolved target sits inside a managed root, so it opts out of the blanket guard via an explicit, documented skipSymlinkGuard flag with exactly one call site. Co-Authored-By: Claude Code <[email protected]>
Collaborator
|
nice work @anishekkamal |
Merged
This was referenced Oct 28, 2026
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
The user-managed-symlink preservation that #1089 gave the Pi writer now covers the Codex and OpenCode writers and the shared cleanup plumbing — closing the "same pattern in two other writers" gap that PR's scope notes disclosed. Before this,
install --to codexandinstall --to opencodestill replaced a user's symlink override (or manually authored path) with a fresh upstream copy, and the standalonecleanupcommand could relocate a user's symlink node intolegacy-backupon all eight of its targets, because every one of those paths funnels through one unguardedfs.renameinmanaged-artifacts.ts. Codex agent files were the worst case: written with no existence check of any kind.Related: #1048.
Fix
Same four-row contract as #1089, applied per writer:
managed-artifacts.tsnow owns the sharedlstatOrNull/isPreservedSymlinkhelpers, and guardscleanupCurrentManagedDirectory, both removed-entry sweeps, andmoveLegacyArtifactToBackup. That last one is the highest-leverage line in the PR: it protects the OpenCode and Kiro legacy sweeps and every target of the standalonecleanupcommand (codex/opencode/pi/kiro/copilot/droid/qwen/windsurf) in one place.codex.tsgets the pi-shaped guards across its skill loops, removed-entry sweeps, legacy backup, and previous-store cleanup — plus a newcleanupCurrentManagedAgentFile, since agent.tomlwrites previously had no existence check at all, and a guard on the orphan-sidecarfs.rmin the agent write loop (the one destructive write-path op the first pass missed — its twin incleanupRemovedAgentswas already guarded). Preserved names are excluded from the written manifest. Its localmoveLegacyArtifactToBackupstays separate from the shared one (backup-path shapes differ materially) and gets the same guard.opencode.tsapplies the full contract to skills, agents, commands, and plugins — all four have ownership records in the manifest'sgroupsmap. For commands the guard runs beforebackupFile, which otherwise copies through the symlink and then overwrites through it, corrupting the fork while producing a "backup" of the fork's own content.pi.tsdrops its private helper copies and imports the shared ones. No behavior change; its 20 preservation tests pass unmodified.One design decision reviewers should weigh
moveLegacyArtifactToBackupaccepts an explicitskipSymlinkGuard: trueescape hatch, used by exactly one caller:moveIfSymlinkManagedin thecleanupcommand's~/.agents/skills/sweep. That sweep's entire job is relocating symlinks — but only afterisManagedCodexAgentsSymlinkverifies the link resolves inside a CE-managed root, a strictly stronger ownership signal than the blanket guard. Without the hatch, the new guard broke that legitimate relocation (caught by the existingcleanup only backs up CE-owned symlinkstest mid-implementation). The invariant is documented at the parameter definition; a repo-wide grep confirms the single call site. The alternative — having that caller do its own rename — was considered and rejected as duplicating the backup-path logic for no added safety.Verification
.bakchurn when preserved.src/changes stashed, 9 of the initially added 11 tests fail (the two "still replaces" positive rows pass either way); restored, all pass..tomlagent write and its manifest tracking landed in the same commit (c2d60b47, refactor(install): prefer native plugin install across targets #609) — before it, Codex emitted agents as skill dirs — so no released version wrote a codex agent file without recording it, and the preserve branch can only fire on genuinely user-authored files.bun testfailure count identical to unmodified main on the same machine (pre-existing, environment-related set; verified by name-level diff, not count alone).Scope notes
kiro.ts's legacy sweep inherits the symlink guard through the sharedmoveLegacyArtifactToBackup— intentional and contract-consistent, though the Kiro writer itself is currently unreachable from the CLI (not registered intargets/index.ts).~/.codex/prompts/<name>.md) remain unguarded bare writes — pre-existing, and the Pi reference implementation has the same surface, so aligning both is left as a follow-up rather than widening this PR's contract.antigravity.tshas no manifest/ownership concept at all (every write unconditional); giving it preservation needs a design decision about what "owned" means there, not a mirror of this pattern.lstatfollows every ancestor. A user who symlinks a whole store directory (e.g.~/.codex/skills/<plugin>→ a fork) still hasfs.rm/copy operate through the parent link into the fork. This predates both PRs, affects every writer including Pi, and the right fix is a containment check (realpath-inside-managed-root before any destructive op) applied uniformly — a design change, not a mirror of this leaf contract. Adversarial review surfaced it during this PR's pre-flight; flagging it here so it's tracked rather than discovered.ensureDirthrow and abort the install (crash, no data loss).