Repository navigation
Description
Summary
While auditing target writers (codex, pi, opencode) across src/targets/ and src/commands/, we found and reproduced three issues in how managed artifacts and backups are written and cleaned up:
- Prompts & extensions bypass symlink and unmanaged-file guards (
src/targets/codex.ts,src/targets/pi.ts,src/commands/cleanup.ts) — clobbering user symlinks oninstall/syncand deleting preserved symlinks on cleanup. - Idempotent OpenCode installs accumulate unbounded
.bak.<timestamp>files inside.opencode/commands/andopencode.json(src/targets/opencode.ts:123, 169-174) — unlikesrc/targets/codex.ts:218-227, which diffs content before backing up. - CLI
--helpdocuments--permissions from-command(singular) whilepermissionModesrequiresfrom-commands(plural) (src/commands/install.ts:15, 59, 86-90).
1. Prompts & extensions clobber user symlinks and unmanaged files (codex.ts, pi.ts)
Skills and agents explicitly preserve user symlinks and unmanaged files via cleanupCurrentManagedSkillDir and cleanupCurrentManagedAgentFile (src/targets/codex.ts:364-403, src/targets/pi.ts:454-490), and skip symlinks during removal via if (await isPreservedSymlink(entryPath)) continue (codex.ts:321, 351, pi.ts:402, 446).
However, prompts and extensions bypass these guards:
- Writes through symlinks & claims manifest ownership:
src/targets/codex.ts:57-61andsrc/targets/pi.ts:95-99, 150-154callawait writeText(targetPath, ...)(fs.writeFile) directly without checking whethertargetPathis a symlink or an unmanaged file, and then record all bundle prompt/extension names inwriteInstallManifest(codex.ts:177,pi.ts:174-175). Becausefs.writeFilefollows symlinks, if a user has symlinked a custom prompt or Pi extension into~/.codex/prompts/,.pi/prompts/, or.pi/extensions/,install/syncoverwrites the symlink target on disk and claims ownership ininstall-manifest.json.
- Deletes preserved symlinks on removal:
cleanupRemovedPrompts(src/targets/codex.ts:326-338,src/targets/pi.ts:407-419) andcleanupRemovedExtensions(src/targets/pi.ts:421-433) omitif (await isPreservedSymlink(entryPath)) continue.
- Legacy Pi prompt cleanup skips ownership check:
cleanupKnownLegacyPiArtifacts(src/targets/pi.ts:532-535) andcleanupPi(src/commands/cleanup.ts:411-413) move matching prompt files without checkingownedPrompts(whereassrc/targets/codex.ts:428-430checksif (ownedPrompts !== null && !ownedPrompts.has(promptName)) continue).
Runnable Reproduction (node -e)
node -e '
import("node:fs/promises").then(async (fs) => {
const os = await import("node:os");
const path = await import("node:path");
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "cep-repro-"));
const userRepoPrompt = path.join(tmp, "my-dotfiles-review.md");
const codexPromptsDir = path.join(tmp, ".codex-prompts");
await fs.mkdir(codexPromptsDir, { recursive: true });
await fs.writeFile(userRepoPrompt, "# User custom prompt (DO NOT CLOBBER)\n", "utf8");
// User symlinks their dotfile prompt into ~/.codex/prompts/review.md
const targetPath = path.join(codexPromptsDir, "review.md");
await fs.symlink(userRepoPrompt, targetPath);
// writeCodex (src/targets/codex.ts:57-61) calls writeText(targetPath, content) without symlink guard
await fs.writeFile(targetPath, "# Overwritten by plugin writeText\n", "utf8");
const afterContent = await fs.readFile(userRepoPrompt, "utf8");
console.log("User dotfile target after writeText:", JSON.stringify(afterContent.trim()));
await fs.rm(tmp, { recursive: true, force: true });
});
'Output:
User dotfile target after writeText: "# Overwritten by plugin writeText"
Suggested Fix:
- Gate prompt and extension writes with a
cleanupCurrentManagedFilecheck mirroringcleanupCurrentManagedAgentFile(codex.ts:386-403), and only record actually-written names inwriteInstallManifest. - Add
if (await isPreservedSymlink(entryPath)) continuetocleanupRemovedPrompts(codex.ts:331,pi.ts:412) andcleanupRemovedExtensions(pi.ts:426). - Guard legacy prompt cleanup in
pi.ts:532-535andcleanup.ts:411-413withif (ownedPrompts !== null && !ownedPrompts.has(promptName)) continue.
2. Unbounded .bak.<timestamp> accumulation inside .opencode/commands/ (src/targets/opencode.ts:123, 169-174)
In src/targets/codex.ts:218-227, hooks.json is only backed up and written when mergedContent !== existingContent.
By contrast, src/targets/opencode.ts:123 and 169-174 call backupFile unconditionally before every write:
// src/targets/opencode.ts:169-174
for (const [name, content] of Object.entries(bundle.commandFiles)) {
const commandPath = path.join(paths.commandsDir, `${name}.md`)
const backupPath = await backupFile(commandPath)
...
await writeText(commandPath, `${content}\n`)
}Every idempotent install or sync run creates a new opencode.json.bak.<timestamp> and a new <cmd>.md.bak.<timestamp> inside the live .opencode/commands/ directory for every command in the bundle, polluting .opencode/commands/.
Suggested Fix:
Read existingContent via await fs.readFile(commandPath, "utf8").catch(() => null) (and similarly for paths.configPath at line 123); when existingContent === ${content}\n``, skip both backupFile and `writeText`.
3. CLI --permissions from-command help text mismatch (src/commands/install.ts:15, 59, 86-90)
src/commands/install.ts:59documents:
--permissions <mode> Permission seeding mode (none | broad | from-command)src/commands/install.ts:15defines:
const permissionModes: PermissionsMode[] = ["none", "broad", "from-commands"]- Passing the documented
--permissions from-commandflag throwsError: Unknown permissions mode: from-commandat line 87. (Also incloneGitHubRepoatsrc/commands/install.ts:330-334, passing"--", source, destinationtogit cloneprevents option injection on positional args.)
Note on Falsified Findings (Filtered Out Before Filing)
We ran this audit using a 4-pass Ponder session (Builder, Skeptic, Dreamer, Empath). On Pass 1, custom relative paths in manifest.hooks / manifest.skills (src/parsers/claude.ts:135-141, 237-249) were flagged as a potential path-traversal vector; on Pass 2, Skeptic inspected resolveWithinRoot (src/parsers/claude.ts:263-270), verified that all manifest paths are strictly checked against resolvedRoot + path.sep, and retracted that finding (op: "delete") so no maintainer time is wasted on a false alarm.
- Full 4-pass convergence report & apply plan:
studies/ecosystem-audits/compound-engineering-plugin/report.md
Generated by Ponder — AI that knows when to speak, and when to shut up.
Activity