agent: StepCode can be connected to magpie, and Disconnect puts back its own model (#1526, BUKOWSKIREAL)

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>
This commit is contained in:
yetone
2026-10-11 04:03:29 +08:00
co-authored by BUKOWSKIREAL
parent 63c382bb66
commit 8b393938f5
7 changed files with 1644 additions and 2 deletions
+8 -1
View File
@@ -92,6 +92,7 @@ line; agents connected to magpie lose it when it quits.
| OpenChamber | `~/.config/openchamber/preferences.json` (`$OPENCHAMBER_DATA_DIR`; magpie's provider in OpenCode's config) | model, small (its own defaults, over OpenCode's) |
| MiMo Code | `~/.config/mimocode/mimocode.json(c)` | model, small |
| Pi | `~/.pi/agent/settings.json` | model |
| StepCode | `~/.stepcode/config.toml` (+ `models.json`; `$STEP_CODING_AGENT_DIR`, `$STEPCODE_CONFIG_DIR`) | model |
| Aside | `~/.aside/u/0/settings.json` (+ `models.json`; the first account, the only one magpie wires) | model, effort, fast, standard, deep, visual, image |
| OmO (omo-ai) | `~/.omo/agent/settings.json` (+ `models.json`; `$OMO_CODING_AGENT_DIR`, `$SENPI_CODING_AGENT_DIR`) | model |
| Prime Agent | `~/.prime/agent/settings.json` (+ `models.json`; `$PRIME_AGENT_CODING_AGENT_DIR`) | model, thinking (Pi's fields; its key `magpie-prime-agent` names it, since its requests carry no User-Agent; the global settings alone, `allowedModels` and `subagentDefaultModel` left as they are) |
@@ -135,11 +136,17 @@ line; agents connected to magpie lose it when it quits.
| Snow CLI | `~/.snow/profiles/magpie.json` (`$SNOW_CONFIG_DIR`), made the active profile and copied to `config.json` | model (the user's other profiles' models too; Snow App takes the profile in with "Sync Snow CLI API config") |
| Alma | Alma's local API (`localhost:23001`, while Alma runs; alma-server's data in `$ALMA_DATA_DIR`, `$XDG_DATA_HOME/alma` or `~/.local/share/alma` on Linux) | model (Alma's default; magpie's models as a provider), and Image Generation's model when it is Auto: the one magpie draws with |
Provider-scoped agents (OpenCode, MiMo Code, Pi, OmO, Aside, Goose, Crush, omp, Hermes Agent) take `provider/model`.
Provider-scoped agents (OpenCode, MiMo Code, Pi, OmO, StepCode, Aside, Goose, Crush, omp, Hermes Agent) take `provider/model`.
Only agents that are installed or configured are shown.
### Notes on some agents
#### StepCode
StepCode is configured via [`stepcode.go`](../internal/agent/stepcode.go). Magpie manages global `defaultProvider` and `defaultModel` in `~/.stepcode/config.toml` (or the parent of an absolute `STEP_CODING_AGENT_DIR`) and writes its catalog into `~/.stepcode/models.json` using Pi's provider format. Magpie only manages model selection; StepCode controls thinking levels itself. Project-local `.stepcode/config.toml` overlays take precedence over global settings. Restart StepCode or begin a new session after changing models. Detection is strictly directory-based (`~/.stepcode`), so having Smallstep's unrelated `step` certificate CLI on `PATH` is never mistaken for StepCode.
The optional real CLI verification test is run with `MAGPIE_TEST_STEPCODE_BIN=/path/to/step go test ./internal/agent -run '^TestStepCodeRealCLISandbox$' -count=1`. It runs StepCode in an isolated temporary sandbox with telemetry disabled and without live credentials.
#### Reasonix Studio
Reasonix Studio is detected from its desktop installation or a native Go
+2
View File
@@ -63,11 +63,13 @@ something else shows up as drift.
- An agent's config is written in the form the installed version reads, taken from what that version declares, not the latest one. VSCodium has no Copilot Chat of its own, and the Marketplace's last one (0.48.1) has no Custom Endpoint provider, only OpenAI Compatible (`customoai`, #1014). magpie reads the provider list in the package.json of the `github.copilot-chat` installed under `~/.vscode-oss/extensions` (`vscodeChatOf`). It writes its group for `customendpoint` when that is declared, for `customoai` when only that is, with each model's window as `maxInputTokens` + `maxOutputTokens` and the token as `x-api-key` (that version drops an Authorization in `requestHeaders`). A missing or unreadable extension keeps `customendpoint`. Sync rewrites a group written for the other provider, and Check reports it, as it does a Copilot Chat declaring neither. That Copilot Chat registers its providers only while signed in to GitHub with a personal Copilot plan, which the Notice says.
- Tuned settings are written only on the user's click, never by Sync or Connect. The value there before is stashed once (`tune.<agent>.<knob>[.<model>]` in `stash.json`), so Undo puts it back, or takes the key out (and a `modelSettings` entry left empty). A value the user changed after the click is theirs: Undo then only forgets the stash. A variable that comes before the setting (`CLAUDE_CODE_AUTO_COMPACT_WINDOW`, `FORCE_PROMPT_CACHING_5M`, `CLAUDE_CODE_PROMPT_CACHE_TTL`, `CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL`, in settings.json's `env` or magpie's own) is shown as `locked` and Apply refuses, since the setting would change nothing. Claude Code compacts at the smaller of the window set and the model's own (its `/autocompact` says "capped to 200k by model"), so advice starts from that, and a model that isn't Claude's has no window here (magpie's own compact wiring serves it). Advice changes a value only when the replay saves 3% or more, and of the windows within 1% of the cheapest takes the largest. Tokens are weighed as billed: cache reads 0.1, 5-minute writes 1.25, hour writes 2, output 5 for Claude; reads 0.1, writes 1, output 8 otherwise.
- A plugin's agent writes each key in place (JSON, YAML or env), the user's comments and other keys kept. What each key held before the first write is stashed under `plugin:<id>:<path>`, typed, and its own model or Disconnect puts every key back and takes out the ones that weren't there; the file is never written whole. A `connect` that throws or takes over a second writes nothing and says why. Its gateway key is `magpie-<id>` (`agentKeyAt`), and usage names its requests by that key or by its `ua` words (`usage.PluginAgents`).
- StepCode config root resolves to the parent of an absolute `STEP_CODING_AGENT_DIR` (agent resources directory differs from config root; relative values ignored), or `STEPCODE_CONFIG_DIR` under home when native, defaulting to `~/.stepcode` ([`stepcode.go`](../../internal/agent/stepcode.go)). Project configs override global configs in StepCode, but magpie manages global configuration only (`config.toml` and `models.json`). Detection is strictly directory-only via `agentDir`, avoiding collision with Smallstep's bare `step` command on `PATH`. Wiring performs an atomic two-file edit (`models.json` provider block and `config.toml` top-level defaults/scope) backed by `stash.json`. Custom fields within `providers.magpie` are preserved during sync, and the original provider block is restored on disconnect. Disconnect restores original defaults, preserves user native changes and custom scope edits, and removes newly created files only when empty.
- Tests never touch the real machine. `TestMain` uses `testenv`, which points HOME, USERPROFILE, the XDG folders and APPDATA into a temporary folder, clears `agentenv.Vars` and puts failing stand-ins for keychain tools and agent CLIs on PATH. Agent-specific side effects (Aside, the Zed keychain, Codex's usage check) are also stubbed in `TestMain`.
## Verification
```sh
go test -tags nogui ./internal/agent -run '^TestStepCode'
go test -tags nogui ./internal/agent -run 'TestConnect|TestDisconnect|Drift|TestKeptAddress|TestWSLAgentAddress|TestReachProbe|TestDryRunKnowsTheAskersProviders|TestReseat|TestPort|TestWSL|TestClaudeKeepsItsClaudeAISignIn|TestClaudeSignIn|TestClaudeOwnEndpointWithAnEmptyKey|TestClaudeAtAnOlderGatewayAddress'
go test -tags nogui ./internal/agent
go test -tags nogui ./internal/agent -run '^TestAir'
+1
View File
@@ -91,6 +91,7 @@ func builtins(home, cfg string) []*Agent {
openChamber(home, cfg),
mimocode(home, cfg),
pi(home),
stepcode(home),
aside(home),
omo(home),
primeAgent(home),
+584
View File
@@ -0,0 +1,584 @@
package agent
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"slices"
"strings"
"github.com/pelletier/go-toml/v2"
"github.com/tidwall/gjson"
"github.com/tidwall/jsonc"
"github.com/yetone/magpie/internal/edit"
)
// StepCode keeps its configuration in ~/.stepcode/config.toml (or
// the parent of an absolute STEP_CODING_AGENT_DIR) and its models in
// models.json using Pi's provider format.
// magpie manages defaultProvider and defaultModel in config.toml, and one
// providers.magpie entry in models.json.
func stepcode(home string) *Agent { return stepcodeIn(here(home)) }
func stepcodeDir(at place) string {
if d := strings.TrimSpace(at.getenv("STEP_CODING_AGENT_DIR")); filepath.IsAbs(d) {
return filepath.Dir(filepath.Clean(d))
}
name := ".stepcode"
if at.spell == nil {
if custom := strings.TrimSpace(at.getenv("STEPCODE_CONFIG_DIR")); custom != "" {
name = custom
}
}
return filepath.Join(at.home, name)
}
func stepcodeProvider(at place) any {
ms := make([]map[string]any, 0)
for _, m := range magpieModels("stepcode") {
ms = append(ms, piModelJSON(m, at.gw(), true))
}
return map[string]any{
"name": "magpie",
"baseUrl": at.v1(),
"api": "openai-completions",
"apiKey": agentKeyAt("stepcode", at.gw()),
"models": ms,
}
}
type stepcodeTOML struct {
Provider *string `toml:"defaultProvider"`
Model *string `toml:"defaultModel"`
Scope *[]string `toml:"enabledModels"`
}
func readStepcodeTOML(path string) (stepcodeTOML, error) {
var out stepcodeTOML
b, err := os.ReadFile(path)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
return out, nil
}
return out, err
}
if len(bytes.TrimSpace(b)) == 0 {
return out, nil
}
if err := toml.Unmarshal(b, &out); err != nil {
return out, fmt.Errorf("%s: %w", path, err)
}
return out, nil
}
func stepcodeValue(s *string) string {
if s == nil {
return ""
}
return *s
}
func stepcodeSetString(path, key string, val *string) error {
if val == nil {
return edit.DelTOMLTop(path, key)
}
return edit.SetTOMLTopPreserving(path, edit.KV{Path: key, Value: *val})
}
func stepcodeScopeRaw(pats []string) (edit.Raw, error) {
b, err := toml.Marshal(map[string]any{"enabledModels": pats})
if err != nil {
return "", err
}
_, rhs, ok := strings.Cut(string(b), "=")
if !ok {
return "", fmt.Errorf("unexpected toml output for enabledModels: %s", string(b))
}
return edit.Raw(strings.TrimSpace(rhs)), nil
}
func stepcodeValidateModels(path string) error {
b, err := os.ReadFile(path)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
return nil
}
return err
}
if len(bytes.TrimSpace(b)) == 0 {
return nil
}
normalized := jsonc.ToJSON(b)
if !gjson.ValidBytes(normalized) {
return fmt.Errorf("%s: invalid JSON", path)
}
root := gjson.ParseBytes(normalized)
if !root.IsObject() {
return fmt.Errorf("%s: root must be a JSON object", path)
}
if prov := root.Get("providers"); prov.Exists() {
if !prov.IsObject() {
return fmt.Errorf("%s: 'providers' must be a JSON object", path)
}
if mag := prov.Get(magpieID); mag.Exists() {
if !mag.IsObject() {
return fmt.Errorf("%s: 'providers.%s' must be a JSON object", path, magpieID)
}
}
}
return nil
}
func stepcodeJSONEmpty(b []byte) bool {
if len(bytes.TrimSpace(b)) == 0 {
return true
}
if bytes.Contains(b, []byte("//")) || bytes.Contains(b, []byte("/*")) {
return false
}
normalized := jsonc.ToJSON(b)
res := gjson.ParseBytes(normalized)
if !res.IsObject() {
return false
}
return len(res.Map()) == 0
}
func stepcodeFileExists(p string) bool {
_, err := os.Stat(p)
return err == nil
}
type stepcodeState struct {
OrigProvider *string `json:"orig_provider,omitempty"`
OrigModel *string `json:"orig_model,omitempty"`
OrigHasScope bool `json:"orig_has_scope"`
OrigScope []string `json:"orig_scope,omitempty"`
LastHasScope bool `json:"last_has_scope"`
LastScope []string `json:"last_scope,omitempty"`
AppendedScope []string `json:"appended_scope,omitempty"`
OrigMagpieRaw *string `json:"orig_magpie_raw,omitempty"`
ConfigFileExisted bool `json:"config_file_existed"`
ModelsFileExisted bool `json:"models_file_existed"`
ProvidersMapExisted bool `json:"providers_map_existed"`
}
func stepcodeReadStash() (map[string]string, error) {
b, err := os.ReadFile(stashPath())
if errors.Is(err, fs.ErrNotExist) {
return map[string]string{}, nil
}
if err != nil {
return nil, fmt.Errorf("stepcode stash: %w", err)
}
var m map[string]string
if err := json.Unmarshal(b, &m); err != nil {
return nil, fmt.Errorf("stepcode stash: %w", err)
}
if m == nil {
return nil, fmt.Errorf("stepcode stash: expected an object")
}
return m, nil
}
func loadStepcodeState(at place) (*stepcodeState, error) {
m, err := stepcodeReadStash()
if err != nil {
return nil, err
}
raw, ok := m[at.key("stepcode.wiring")]
if !ok {
return nil, nil
}
var state *stepcodeState
if err := json.Unmarshal([]byte(raw), &state); err != nil {
return nil, fmt.Errorf("stepcode wiring state: %w", err)
}
if state == nil {
return nil, fmt.Errorf("stepcode wiring state: expected an object")
}
return state, nil
}
func stepcodeStoreState(at place, state *stepcodeState) error {
m, err := stepcodeReadStash()
if err != nil {
return err
}
key := at.key("stepcode.wiring")
if state == nil {
delete(m, key)
} else {
b, err := json.Marshal(state)
if err != nil {
return err
}
m[key] = string(b)
}
data, err := json.MarshalIndent(m, "", " ")
if err != nil {
return err
}
if err := os.MkdirAll(filepath.Dir(stashPath()), 0o700); err != nil {
return err
}
f, err := os.OpenFile(stashPath(), os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0o600)
if err == nil {
if err := f.Close(); err != nil {
return err
}
} else if !errors.Is(err, fs.ErrExist) {
return err
}
return edit.WriteAtomic(stashPath(), data)
}
func stepcodeStartup(cfg stepcodeTOML) string {
p := stepcodeValue(cfg.Provider)
m := stepcodeValue(cfg.Model)
def := ""
switch {
case m == "":
def = ""
case p == "":
def = m
default:
def = p + "/" + m
}
if cfg.Scope == nil || len(*cfg.Scope) == 0 {
return def
}
scope := *cfg.Scope
if def != "" && slices.ContainsFunc(scope, func(pat string) bool { return piTakes(pat, def) }) {
return def
}
first := strings.TrimSpace(scope[0])
if i := strings.LastIndex(first, ":"); i >= 0 && slices.Contains(piLevels, first[i+1:]) {
first = first[:i]
}
if strings.ContainsAny(first, "*?[") || !strings.Contains(first, "/") {
return def
}
return first
}
func stepcodeIn(at place) *Agent {
dir := stepcodeDir(at)
path := filepath.Join(dir, "config.toml")
modelsPath := filepath.Join(dir, "models.json")
authPath := filepath.Join(dir, "auth.json")
block := theirsKept(modelsPath, "providers."+magpieID, func() any { return stepcodeProvider(at) }, "models")
startup := func() string {
curTOML, err := readStepcodeTOML(path)
if err != nil {
return ""
}
return stepcodeStartup(curTOML)
}
unwire := func() error {
state, err := loadStepcodeState(at)
if err != nil {
return err
}
if state == nil {
return nil
}
curTOML, err := readStepcodeTOML(path)
if err != nil {
return err
}
if err := stepcodeValidateModels(modelsPath); err != nil {
return err
}
if stepcodeValue(curTOML.Provider) == magpieID {
if err := stepcodeSetString(path, "defaultProvider", state.OrigProvider); err != nil {
return err
}
if err := stepcodeSetString(path, "defaultModel", state.OrigModel); err != nil {
return err
}
}
curTOML, err = readStepcodeTOML(path)
if err != nil {
return err
}
curHasScope := (curTOML.Scope != nil)
var curList []string
if curHasScope {
curList = *curTOML.Scope
}
if curHasScope == state.LastHasScope && slices.Equal(curList, state.LastScope) {
if state.OrigHasScope {
raw, err := stepcodeScopeRaw(state.OrigScope)
if err != nil {
return err
}
if err := edit.SetTOMLTopPreserving(path, edit.KV{Path: "enabledModels", Value: raw}); err != nil {
return err
}
} else {
if err := edit.DelTOMLTop(path, "enabledModels"); err != nil {
return err
}
}
} else if curHasScope && len(state.AppendedScope) > 0 {
kept := slices.DeleteFunc(slices.Clone(curList), func(p string) bool {
return slices.Contains(state.AppendedScope, p)
})
if !slices.Equal(kept, curList) {
raw, err := stepcodeScopeRaw(kept)
if err != nil {
return err
}
if err := edit.SetTOMLTopPreserving(path, edit.KV{Path: "enabledModels", Value: raw}); err != nil {
return err
}
}
}
if state.OrigMagpieRaw != nil {
if err := edit.SetJSON(modelsPath, edit.KV{Path: "providers." + magpieID, Value: json.RawMessage(*state.OrigMagpieRaw)}); err != nil {
return err
}
} else {
if err := edit.DelJSON(modelsPath, "providers."+magpieID); err != nil {
return err
}
if !state.ProvidersMapExisted {
if rawP, ok := edit.GetJSON(modelsPath, "providers"); ok && strings.TrimSpace(rawP) == "{}" {
if err := edit.DelJSON(modelsPath, "providers"); err != nil {
return err
}
}
}
}
if !state.ModelsFileExisted {
if b, err := os.ReadFile(modelsPath); err == nil {
if stepcodeJSONEmpty(b) {
if err := edit.Remove(modelsPath); err != nil {
return err
}
}
}
}
if !state.ConfigFileExisted {
if b, err := os.ReadFile(path); err == nil {
if len(bytes.TrimSpace(b)) == 0 {
if err := edit.Remove(path); err != nil {
return err
}
}
}
}
return stepcodeStoreState(at, nil)
}
a := &Agent{
ID: "stepcode",
Name: "StepCode",
Icon: "stepfun-color",
Bin: "step",
Aliases: []string{"step"},
Dir: dir,
Path: path,
Spelled: prefixed,
UA: []string{"stepcode"},
detect: func() bool {
return agentDir(dir)
},
Beside: func() bool {
s, err := loadStepcodeState(at)
return err == nil && s != nil
},
Unwire: unwire,
Check: func() string {
cur, err := readStepcodeTOML(path)
if err != nil {
return "StepCode's config (config.toml) is unreadable or malformed"
}
if err := stepcodeValidateModels(modelsPath); err != nil {
return "StepCode's models.json is unreadable or malformed"
}
if stepcodeValue(cur.Provider) != magpieID {
return ""
}
return wiringOff("StepCode", modelsPath, func(k string) (string, bool) {
return edit.GetJSON(modelsPath, "providers."+magpieID+"."+k)
}, "baseUrl", at.v1(), "apiKey", agentKeyAt("stepcode", at.gw()))
},
Sync: func() error {
state, err := loadStepcodeState(at)
if err != nil {
return err
}
if state == nil {
return nil
}
if err := stepcodeValidateModels(modelsPath); err != nil {
return err
}
return syncJSON(modelsPath, "providers."+magpieID, block)
},
Fields: []Field{
{
Key: "model",
Label: "model",
Get: startup,
Set: func(v string) error {
if v == "" {
return unwire()
}
ref, isMag := strings.CutPrefix(v, magpieID+"/")
if !isMag || !isMagpie(ref) {
p, m, ok := strings.Cut(v, "/")
if !ok || p == "" || m == "" {
return fmt.Errorf("expected provider/model, got %q", v)
}
if err := unwire(); err != nil {
return err
}
cur, err := readStepcodeTOML(path)
if err != nil {
return err
}
if err := edit.SetTOMLTopPreserving(path, edit.KV{Path: "defaultProvider", Value: p}, edit.KV{Path: "defaultModel", Value: m}); err != nil {
return err
}
if cur.Scope != nil && len(*cur.Scope) > 0 {
if !slices.ContainsFunc(*cur.Scope, func(pat string) bool { return piTakes(pat, v) }) {
newScope := append(*cur.Scope, v)
raw, err := stepcodeScopeRaw(newScope)
if err != nil {
return err
}
if err := edit.SetTOMLTopPreserving(path, edit.KV{Path: "enabledModels", Value: raw}); err != nil {
return err
}
}
}
return nil
}
curTOML, err := readStepcodeTOML(path)
if err != nil {
return err
}
if err := stepcodeValidateModels(modelsPath); err != nil {
return err
}
state, err := loadStepcodeState(at)
if err != nil {
return err
}
if state == nil {
state = &stepcodeState{}
state.ConfigFileExisted = stepcodeFileExists(path)
state.ModelsFileExisted = stepcodeFileExists(modelsPath)
if rawP, ok := edit.GetJSON(modelsPath, "providers"); ok && rawP != "" {
state.ProvidersMapExisted = true
}
if rawMagpie, ok := edit.GetJSON(modelsPath, "providers."+magpieID); ok {
state.OrigMagpieRaw = &rawMagpie
}
state.OrigProvider = curTOML.Provider
state.OrigModel = curTOML.Model
if curTOML.Scope != nil {
state.OrigHasScope = true
state.OrigScope = slices.Clone(*curTOML.Scope)
}
} else {
if stepcodeValue(curTOML.Provider) != magpieID {
state.OrigProvider = curTOML.Provider
state.OrigModel = curTOML.Model
}
curHasScope := (curTOML.Scope != nil)
var curList []string
if curHasScope {
curList = *curTOML.Scope
}
scopeChanged := false
if curHasScope != state.LastHasScope {
scopeChanged = true
} else if curHasScope && !slices.Equal(curList, state.LastScope) {
scopeChanged = true
}
if scopeChanged {
state.OrigHasScope = curHasScope
if curHasScope {
filtered := slices.DeleteFunc(slices.Clone(curList), func(p string) bool {
return slices.Contains(state.AppendedScope, p)
})
state.OrigScope = filtered
} else {
state.OrigScope = nil
}
}
}
// Update target scope
if curTOML.Scope != nil && len(*curTOML.Scope) > 0 {
pats := *curTOML.Scope
if !slices.ContainsFunc(pats, func(p string) bool { return piTakes(p, v) }) {
newScope := append(slices.Clone(pats), v)
state.AppendedScope = append(state.AppendedScope, v)
state.LastHasScope = true
state.LastScope = newScope
} else {
state.LastHasScope = true
state.LastScope = slices.Clone(pats)
}
} else {
state.LastHasScope = (curTOML.Scope != nil)
if curTOML.Scope != nil {
state.LastScope = slices.Clone(*curTOML.Scope)
} else {
state.LastScope = nil
}
}
// Save state before config edits
if err := stepcodeStoreState(at, state); err != nil {
return err
}
if err := edit.SetJSON(modelsPath, edit.KV{Path: "providers." + magpieID, Value: block()}); err != nil {
return err
}
if err := edit.SetTOMLTopPreserving(path, edit.KV{Path: "defaultProvider", Value: magpieID}, edit.KV{Path: "defaultModel", Value: ref}); err != nil {
return err
}
if state.LastHasScope && (curTOML.Scope == nil || !slices.Equal(*curTOML.Scope, state.LastScope)) {
raw, err := stepcodeScopeRaw(state.LastScope)
if err != nil {
return err
}
if err := edit.SetTOMLTopPreserving(path, edit.KV{Path: "enabledModels", Value: raw}); err != nil {
return err
}
}
return nil
},
Options: func(cur map[string]string) []Option {
return append(ownOptions(authPath, cur["model"]), viaMagpie("stepcode", magpieID+"/")...)
},
},
},
}
return atomic(a, path, modelsPath, stashPath())
}
File diff suppressed because it is too large Load Diff
+2
View File
@@ -301,6 +301,8 @@ var wslKinds = []wslKind{
}
return nil
}},
{id: "stepcode", name: "StepCode", dir: ".stepcode", in: stepcodeIn,
asleep: wslOwnAsleep("stepcode", "model")},
// only its settings.json: its sign-in, sessions and prompt history,
// read on this machine for Claude Code here, aren't read in a distro
{id: "claude", name: "Claude Code", dir: ".claude", bin: "claude", in: claudeIn,
+4 -1
View File
@@ -44,6 +44,8 @@ var Vars = []string{
"PI_CODING_AGENT_DIR", "PI_CODING_AGENT_SESSION_DIR", "PI_CONFIG_DIR", "PI_PROFILE",
"OMO_CODING_AGENT_DIR", "SENPI_CODING_AGENT_DIR",
"PRIME_AGENT_CODING_AGENT_DIR",
// StepCode: config root resolution and folder overrides
"STEP_CODING_AGENT_DIR", "STEPCODE_CONFIG_DIR",
// omp
"OMP_PROFILE",
// Qoder's two builds, the global site's and China's
@@ -94,5 +96,6 @@ var NotPaths = map[string]bool{
"PI_PROFILE": true, "OMP_PROFILE": true,
"WINDSURF_API_SERVER_URL": true, "ZCODE_CREDENTIAL_SECRET": true,
"PI_CONFIG_DIR": true, "OPENCODE_DB": true,
"MAGPIE_ZED_BIN": true, "MAGPIE_ZED_PROCESS_NAMES": true,
"STEPCODE_CONFIG_DIR": true,
"MAGPIE_ZED_BIN": true, "MAGPIE_ZED_PROCESS_NAMES": true,
}