The sibling of the StepCode fix before this, and of omp's (e6753190).
Renaming a provider moved Pi's defaultModel and appended the new ref to
settings.json's enabledModels (piScopeWith), but left the magpie/<old>/
entries, which name nothing after the rename; Pi then leaves those models
out of Ctrl+P. piLikeKeyed, which Pi, OmO and Prime Agent are all built
from, now has a RenameRefs hook: magpie/<old>/ entries are renamed, a
glob or a :level kept, and the copy the move just appended is dropped so
the model stays where the user had it. The user's own entries and a name
that only shares a prefix (magpie/deepseekx/...) stay; a list naming none
of the provider's models isn't rewritten. Pi keeps no scope stash of its
own (Disconnect's before-magpie copy is from before magpie wrote), so
there is nothing else to rename.
StepCode's rename helpers move to rename.go as renameRef/renameRefList
so both use one list rule.
Run:
- TestPiEnabledModelsFollowRename (new), for pi, omo and prime-agent:
red with the hook returning early (old entries kept, magpie/ds/pro
appended beside magpie/deepseek/pro), green with it.
- go test -tags nogui -count=1 -timeout 80m ./internal/agent on this
tree (StepCode commit + this): ok, 999s, under a temp HOME. Load
average ~120 from other sessions; the earlier run of the StepCode
commit alone hit the default 10m timeout for that reason, not a hang.
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows.
Renaming a provider moved StepCode's defaultModel to the new id and
appended it to enabledModels, but the list kept magpie/<old>/ entries
(the model it was on, others the user listed, a glob), which name nothing
after the rename. StepCode now has a RenameRefs hook, as omp has
(e6753190): it renames magpie/<old>/ entries in config.toml's
enabledModels, drops the copy the move just appended, and renames the
scopes kept for Disconnect (OrigScope, LastScope, AppendedScope), so a
reset neither puts the old id back nor leaves the appended one. An entry
that only shares a prefix (magpie/deepseekx/...) and the user's own
entries stay; a list naming none of the provider's models is not
rewritten.
ggbdpq's patch from #1919, taken as written.
Run:
- go test -tags nogui -count=1 -run 'TestStepCode' ./internal/agent: ok.
- With only the RenameRefs hook removed, TestStepCodeEnabledModelsFollowRename
fails with the scope the issue quotes; TestStepCodeRenameLeavesUserScope
is a guard and passes on the old code too.
- -race -count=5 on the two new tests: ok.
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows: ok.
- The full ./internal/agent package timed out at the default 10m on a
machine at load ~120 (many sessions testing at once); the run with
this and the Pi sibling together is in the next commit's body.
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
stash.json holds every agent's config from before magpie wired it. stash,
forget and unstash read it, changed it and wrote it back with
os.WriteFile, with no lock, and a read that didn't parse came back empty.
Two changes at once (Connect all, a gateway move setting each agent again)
could leave the file half written, and the next change read that as no
stash and wrote it back: every agent's originals gone, so Disconnect had
nothing to put back. Now each change runs under stashMu and is written
with edit.WriteAtomic; a file that doesn't parse is copied to
stash.json.bad-<time> first; a new file is made 0600, since it holds keys.
rewire.go's stashPut and StepCode's stepcodeStoreState go through the same
stashWrite (StepCode keeps its own strict read).
TestStashKeepsChangesMadeAtOnce runs 40 stashes at once;
TestUnreadStashKeptAside stashes over a half-written file.
Ran: both new tests on origin/main's stash.go (red: "0 of 40 agents'
originals kept", "kept aside: []") and with the change (green); go vet on
darwin, GOOS=linux and GOOS=windows for internal/agent; go test -count=1
./internal/agent/ (ok, 278s); go test -race -count=3 on the stash and
StepCode tests (ok).
StepCode (StepFun's coding CLI, `step`) is a Pi fork that keeps Pi's
settings as TOML in ~/.stepcode/config.toml and Pi's models.json beside
it. It is now an agent target: Connect sets defaultProvider/defaultModel
to magpie, appends the magpie pattern to enabledModels when the user
scopes models, and writes providers.magpie into models.json with the
per-agent key. Disconnect puts back the user's own provider, model and
scope (only the patterns magpie added are taken out if the user changed
the scope since), restores or removes providers.magpie, and removes a
models.json magpie created. STEP_CODING_AGENT_DIR and STEPCODE_CONFIG_DIR
move the folder as StepCode's own resolveStepConfigRoot does; WSL is
covered.
The patch is BUKOWSKIREAL's (7cc88463 in their fork), reviewed line by
line: no network, telemetry or credential reads, writes only to the two
StepCode files and magpie's stash. Added here: a test that StepCode's
real User-Agent, "step (darwin 25.2.0; arm64)", counts as StepCode, and
the real-CLI test now looks for a "magpie" row in `step --list-models`
rather than the word anywhere (the docs path step prints can contain it).
Run:
- Config format checked against stepfun-ai/Step-Code at 3d70bae5 and the
official 0.1.3 darwin-arm64 binary (sha256 matches latest.json):
`step config path --json` names ~/.stepcode/config.toml and models.json.
- Sandbox HOME, sandbox gateway on 127.0.0.1:3647: a user config with
defaultProvider "step", step-3.7-flash, thinking high, two scoped
models, telemetry off. `magpie stepcode magpie/deepseek/deepseek-flash`,
then `step -p` answered PONG through the gateway (usage record: agent
stepcode, deepseek-flash, 200). `magpie stepcode default` put
config.toml back value for value, removed models.json, and
`step --list-models` no longer listed magpie.
- The same round trip from the real web page (sandbox `magpie web`),
switch on, then off through the disconnect preview, which listed the
three values it puts back; config.toml came back byte-identical. The
row and icon checked in Chromium and WebKit, en and zh; no GUI assets
change.
- Broke the guarantee: with unwire never restoring the defaults,
TestStepCodeLifecycle, ...NativeChangedAndPreexisting and
...StrictValidationAndRollback go red. Without the "step" alias the
new UA check goes red.
- MAGPIE_TEST_STEPCODE_BIN=<0.1.3> go test -run TestStepCodeRealCLISandbox
passes (it failed before the row check above).
- go test -tags nogui ./... ; gofmt -l; go vet (darwin, GOOS=linux,
GOOS=windows) on internal/agent and internal/agentenv; go build for
darwin, linux (nogui) and windows.
Not tried on a real Windows, Linux or WSL machine.
Co-authored-by: BUKOWSKIREAL <233685554+BUKOWSKIREAL@users.noreply.github.com>