Repository navigation
fix(mocactl): write Bob's config once when its two filenames are linked - #684
Conversation
Bob's two filenames hold the same entry, so keeping them in step with a link (`ln -s settings.json .bob/mcp.json`) is a natural thing for a developer to do -- and it leaves `writeAgentConfig` with two Docs over one file, since `loadDoc` resolves through `target()`. Both merge the same key into the same bytes and so agree, but the file was considered twice: `up` named it twice in `configured Claude Code, OpenCode and IBM Bob: ..., .bob/settings.json, .bob/settings.json, ...` and wrote it a second time for nothing. The Markdown loop has guarded exactly this since CLAUDE.md started being a link to AGENTS.md; the JSON loop had no reason to until #676 gave Bob a second filename. This adds the same guard, keyed on the resolved path. Seen-set rather than "already in writes": the first of an aliased pair may be skipped by the unchanged-file check below, which would let the second through. Verified by reverting the guard with the test in place: `changed` then holds `.bob/settings.json` twice. Behaviour is otherwise unchanged -- the content was always correct, and the manifest already recorded one entry per op, since both Docs resolve to the same `rel`. 202 tests pass across sbx-agent-config, sbx-up and sbx-doctor. The two failures in a full run are the known TUI flakes (overlay-onboarding, overlay-credentials); all 21 overlay tests pass in isolation and this touches no TUI code. tsc --noEmit and Prettier clean. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Mariusz Sabath <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Small, well-scoped fix: dedupes the JSON write loop on the resolved path, mirroring the Markdown loop guard (agent-config.ts:1089). The new test covers the linked Bob pair end to end (single name in changed, link preserved, both names read the merged entry, doctor clean, sbx rm restores). One suggestion inline: make the guard check that aliased Docs agree, rather than assume it, since it applies to all five Docs.
Author: mrsabath (MEMBER — maintainer)
Areas reviewed: TypeScript (mocactl sbx agent-config + tests), security
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, signed-off: yes
CI status: passing. Exception: deploy-scripts-bash32 was cancelled because no macOS runner was available ("not acquired by Runner … capacity constraints"). That is infra, not this PR, which touches no shell.
| // Seen, not "already in writes": the first of the pair may be skipped as unchanged below. | ||
| const seenDocs = new Set<string>(); | ||
| for (const d of [mcp, settings, oc, bob, bobMcp]) { | ||
| if (seenDocs.has(d.abs)) continue; |
There was a problem hiding this comment.
suggestion: The guard covers all five Docs, not only the Bob pair, and "both merge the same key into the same bytes and so agree" holds for only some aliasings. It holds for .bob/mcp.json ↔ .bob/settings.json, and also for .mcp.json ↔ either Bob file, because CLAUDE_SERVER and BOB_SERVER are identical. It does not hold for .claude/settings.json ↔ .bob/settings.json: settings gets permissions.allow/deny + enabledMcpjsonServers, while bob gets mcpServers.sandbox, so finalText differs between the two Docs over the same file. With this change the first Doc wins and the second Doc's merge is silently dropped, while its recs still go into the manifest. Before this change the last write won, which silently dropped the Claude deny list, so this is not a regression; it is arguably safer now. But the case stays silent either way. Suggest checking agreement instead of assuming it: keep a Map<abs, body>, and when a later Doc over the same abs has a different finalText, throw ConfigConflict(d.rel, d.rel, is the same file as ${first.rel}, which needs different settings). A one-line test with ln -s ../.bob/settings.json .claude/settings.json would pin it.
Follow-up to the review of #677, which is already merged. Not a regression from it: #677 is what makes the case reachable, by giving Bob a second filename holding the same entry.
Summary
writeAgentConfigloads each config file throughloadDoc→target(), which resolves symlinks. Bob's two filenames carry an identical entry, so keeping them in step with a link is a natural thing for a developer to do:That leaves two
Docs over one real file. Both merge the same key into the same bytes and so agree, but the file was considered twice:— the name reported twice, and the file written a second time for nothing.
The Markdown loop has guarded exactly this since
CLAUDE.mdbecame a link toAGENTS.md(agent-config.ts:1089, with a test atsbx-agent-config.test.ts:852). The JSON loop had no reason to until #676 gave Bob a second filename. This adds the same guard, keyed on the resolved path.A seen-set rather than checking
writes: the first of an aliased pair may be skipped by the unchanged-file check just below, which would let the second through.Significance: low
Worth stating plainly, so this is reviewed at the right altitude.
upnever creates one, the guide never suggests it, andbob mcp adddoes not do it.sbx doctorand.sbx/agent-config.jsonwere all correct already — the manifest records one entry per op regardless, since bothDocs resolve to the samerel. What was wrong is a duplicated name in one line of output, plus a redundant write.What argues for fixing it anyway is the asymmetry: the Markdown path has carried this guard, with a test, for a long time, and #676 is what made the JSON path able to hit the same case.
Testing
Verified the fix is load-bearing by reverting just the guard with the new test in place —
changedthen holds.bob/settings.jsontwice, and the test fails.sbx-agent-config,sbx-upandsbx-doctorsbx rmleaves the developer's file and link as they weretsc --noEmitand Prettier cleanRelated
up's agent-config files be pushed to the sandbox? (gitignoring them in #677 changed it by side effect) #683, the other finding from that review (whetherup's agent-config files should be pushed to the sandbox) — a decision to discuss, independent of this