A catalog sync asked about each agent's files many times a round
(GetJSON, GetTOMLTop, settings.load from each agent's Sync): on Windows
an empty sandbox's start stat'ed settings.json 1065 times and
config.toml 569 in 25s, almost all from SyncCatalog. Each round now
holds what was read (filememo.Hold), as the GUI's read-only requests and
the gateway already do.
What a hold serves may be up to a second old, so nothing is written from
it any more:
- edit.Read, which every Set*/Del* helper and the agents' own
read-modify-write code start from, looks at the disk even under a
hold (filememo.ReadNow). The getters (GetJSON, GetJSONRaw,
GetJSONItem, GetEnvFile, GetYAMLTop, the YAML getters, GetTOMLTop's
line reader) read through the hold.
- settings: a write's load under fileMu (lockFile) reads the disk too.
Before this, a GUI request's hold could already hand a Set* stale
bytes; that is closed as well.
WriteAtomic forgot every held file even when it left the file as it
was, and a sync writes each agent's files each round, almost always
unchanged: it now forgets only after a real write.
Measured on xiaomi-gpu (Windows 11), as in the steady commit before
this one (second start, 27s, stats counted by an uncommitted build):
before 2307 stats, sync 1318 of them, round 1308ms
this alone 1787 stats, sync 864, round 1273ms
with steady's 988 stats, sync 96, round 96ms
First start of an empty sandbox: 2448 stats before, 1041 after.
Run:
- TestHeldReadIsNotWhatAWriteIsMadeFrom (json, toml, yaml),
TestUnchangedWriteKeepsWhatIsHeld, TestHeldSettingsAreNotWhatAWriteIsMadeFrom:
with edit.Read and the settings write load put back on the held read
and WriteAtomic's Forget removed by hand, json and yaml lost the other
app's key, the settings case wrote "light" over "dark", and the
forget case went red; green with the change, on mote.
- mote, at the pushed head: gofmt -l internal clean; GOOS=linux/windows/
darwin go vet of steady, edit, filememo, settings and agent clean;
go test -count=1 of steady, edit, filememo, settings, agent, provider,
catalog and library ok; internal/gui red only on TestMainWindowCorners
(#3949, macOS 27, red on main before this).
- xiaomi-gpu: go test of edit, filememo and settings ok.
What changed: delItem read the "is the element alone on its line" check
from the comment-blanked copy, so a JSONC comment written before the
element on the same line (VS Code's chatLanguageModels.json carries the
user's notes beside their groups) counted as blank space, the delete took
the line from its start, and the comment went with the element. It reads
raw now, as delJSONBytes does for the same check on an object member, so
only the element (and its comma, or its line) goes.
Test: TestDelJSONItemKeepsACommentBeforeTheElement (edit.DelJSONItem,
three shapes) fails on the old code with "the comment before the element
went with it" and passes now; the edit package's other tests, among them
the CRLF and among-others deletes, pass unchanged.
Run: go test -tags nogui -count=1 ./internal/edit ./internal/agent; the
full go test -tags nogui ./... in a sandbox HOME (TestOffline red as on
the baseline; gateway's TestSearchFollowsTheSearchersProxy red once under
the full run, passes alone, no path from this diff); gofmt -l; go vet and
go build on darwin, GOOS=linux -tags nogui and GOOS=windows.
Review: the test fails on main (3f5702421) with "the comment before the
element went with it". Added a fourth shape, a block comment that ends on
the element's line: on the old code DelJSONItem cut from the line start
into the comment and refused the result as "invalid JSON/JSONC", so the
group could not be taken out at all; now it goes and the comment stays.
Re-run: go test ./internal/edit, green with the fix and red with
stripped[ls:a] put back by hand.
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
DelJSON, PatchJSON's deletes and DelJSONItem cut a member that sits on a
line of its own together with that line's end, but only looked for a bare
\n after it. In a file with \r\n line ends (a Windows settings.json,
VS Code's chatLanguageModels.json) the \r stopped the line end from going,
so each set-then-delete left one more blank \r\n line, e.g. magpie
connecting and disconnecting Claude Code. pastLineEnd now takes \r\n or \n.
Found while writing #1534's round-trip test on a CRLF settings.json.
Run: TestDelJSONTakesCRLFLine and TestDelJSONItemTakesCRLFLine fail on the
old code (a "\r\n\r\n" left where the key was) and pass now;
go test -tags nogui ./internal/edit/ passes.
Validate the complete comment-stripped document before object and array edits, including previews. Regression tests fail on the old implementation because edits and VS Code Connect succeed and alter malformed files. Targeted edit and VS Code tests pass in an isolated HOME.
VS Code Stable takes other vendors' models through its Custom Endpoint provider since 1.122 (customoai, the older OpenAI Compatible one, is Insiders only), signed in to GitHub or not. The provider groups live in chatLanguageModels.json beside settings.json in the default profile's User folder (~/Library/Application Support/Code/User, ~/.config/Code/User, %APPDATA%\Code\User), a JSONC array VS Code watches. magpie adds {"vendor":"customendpoint","name":"magpie","apiType":"chat-completions","models":[...]} with each catalog model at the gateway's /v1/chat/completions, toolCalling true (agent mode lists only tool-calling models), vision, contextWindow and maxOutputTokens (capped at a quarter of the window, as VS Code keeps the output budget out of the prompt's), and the model's efforts as supportsReasoningEffort. A group's apiKey is a secret property that VS Code reads from its secret storage only (languageModels.ts _resolveConfiguration), so it can't be written to the file; each model instead sends Authorization: Bearer magpie in requestHeaders, which CustomEndpointOAIEndpoint lets through and which stops it sending its own key header. The model a new chat starts on is chat.defaultModel in settings.json (matched by model id, so the catalog id); its old value is stashed and put back. The group is the agent's Joined: picking one of VS Code's own (auto) keeps magpie's models listed, and switching off (Unwire) takes the group out and puts chat.defaultModel back. Sync rewrites the group as the catalog changes, Check says when its url or header no longer reach the gateway, the Notice says where the models are and to reload the window if they don't show, and requests are credited to it by GitHubCopilotChat/<version>, a User-Agent a model's headers can't change.
internal/edit: SetJSONItem/GetJSONItem/DelJSONItem edit one element of a JSONC file's top-level array, found by its members, keeping comments, trailing commas and the other elements; SetJSON/DelJSON take a backslash-escaped dot as part of a key, as gjson does, for VS Code's flat "chat.defaultModel".
TestVSCode (connect keeps the user's settings and groups with their comments, the group's url/header/toolCalling/window and no apiKey or discovery url, Sync, Check, an own model keeping the group, disconnect back to the user's last own model), TestVSCodeRoundTrip (on and off leaves both files byte for byte; no files at all) and TestVSCodeUA; TestJSONItem, TestDelJSONItemAmongOthers and TestJSONEscapedDot. go vet ./internal/..., go build -tags nogui ./..., GOOS=windows and GOOS=linux builds pass; go test of internal/agent, edit, usage and gateway (each sandboxes HOME in TestMain) and internal/gui's page and agent connect tests pass; the full go test under a temp HOME was not run (the sandbox refused the HOME override). No GUI code changed (the generic connected wording fits), so no webkit test. VS Code itself is not installed here: not tried against a real VS Code.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>