diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md index 9b7b6841a..e0998aa13 100644 --- a/docs/subsystems/agent-wiring.md +++ b/docs/subsystems/agent-wiring.md @@ -85,6 +85,7 @@ something else shows up as drift. - Each of magpie's routes has `streamIdleTimeoutMs: 600000` (`dshIdleWait`), the gateway's own wait for a reply's headers (`upstreamHeaderWait`, 10 minutes). llm-pi-ai gives a turn up after 5 minutes without a pi-ai event (`DEFAULT_STREAM_IDLE_TIMEOUT_MS`, 0.1.5 to 0.2.2), and the gateway's `: keepalive` comments (`keepQueued`, `keepQuiet`) are not events: real dsh 0.2.1-rc.2 timed out at a route's 3000ms with comments every second. A turn queued behind dsh's own title request on a plugin serving one request at a time (magpie-gemini-web, `maxConcurrency: 1`) was cut while the gateway and the plugin still waited, and recorded as 499 (tim on Discord). A value already on the route, set in dsh or by hand, stays (`TestDshRoutesWaitAsLongAsTheGateway`, `TestDshRouteKeepsTheUsersIdleWait`). Codex's comment-blind limit is met in the gateway instead (`agentQuietMost`). - While magpie serves, `KeepDshWired` writes the routes again every 30 seconds, since dsh writes over its patch list. A round that writes nothing is kept (`dshRounds`), and the next round does nothing when nothing it reads has changed since. It checks the bytes of dsh's files (every profile's `cordis.patch.yml`, the home layer, `settings.yaml`, `.env`, `.credentials.yaml`, `config.yaml`) and the gateway's address. It also checks `provider.StampNow`: no Changed, plugin change or `filememo.Forget`, the same environment, and the providers', settings' and catalog's files unchanged. The models are built again when that stamp moves, and at least every `dshModelsFor` (5 minutes) for what no stamp sees, such as another app's account file or a date-retired model. Building the whole catalog and every route each round allocated 12 GB of a user's 35.7 GB in 48 minutes (`TestDshRoundWithNothingChangedBuildsNothing`, `TestDshRoundAfterAChangeWritesAgain`). - DeepSeek Harness Desktop (macOS arm64 and Windows x64; no Linux build) reads the same `$DSH_HOME` or `~/.dsh` as the CLI, as its own profile `profiles/desktop` (`resolveDshHome` and `resolveDesktopPaths` in the app's `lib/main.js`; `defaultDshHome` in github.com/deepseek-ai/deepseek-harness's `packages/util/home-paths/src/index.ts` and `apps/desktop/src/paths.ts`), so it takes magpie's routes with no wiring of its own (#2279, liangjinyuan-sihan). A profile dsh makes after another was wired (the app opened for the first time after the CLI's web profile) is given magpie's routes by the catalog sync and the serving round (`dshFillNewProfiles`), with the start model the wired ones start on when that is one of magpie's, and with no start when the user picked one of dsh's own there: only the routes, beside dsh's models. That second case was left as dsh's empty template, so the app's picker listed only the DeepSeek account (zyh6036 on X, `TestDshFillNewProfilesWhenTheStartIsTheUsers`). With no profile wired, none is filled. Only that app, from deepseek-ai/deepseek-harness (bundle id `com.deepseek.dsh`, productName DeepSeek Harness in `apps/desktop/scripts/electron-builder-config.mjs`), is dsh's: the community "DeepSeek Hermes" (motongv/deepseek-hermes-desktop) v0.1.1337 took for it is not listed or written for (WuSix on Discord, `TestDshOnlyTheOfficialApp`). It is found by `/Applications/DeepSeek Harness.app`, by `%LOCALAPPDATA%\Programs\DeepSeek Harness`, or by the folder its current-user installer records under `HKCU\Software\1bf39983-50d0-5fe0-9ef4-cece76f67c5e` (`InstallLocation`), whose Uninstall key gives the version (`registered` in [`desktopapp.go`](../../internal/agent/desktopapp.go)), so a user who picked another folder is found. With the app installed but never opened there is no `~/.dsh`: the row is still listed, and connecting writes `profiles/desktop/cordis.patch.yml` from dsh's own template (`dshProfileTemplate`) with magpie's routes, which the app keeps on its first start, since it writes only the files that are missing. The notice says the app starts on it the first time it opens (`noticeDsh5`). Disconnect before that first start removes the profile magpie made when nothing else is in it (`dshTidyUnopened`); once the app has opened it, the profile stays and only magpie's entries go (`TestDshDesktopNeverOpened`, `TestDshDesktopRegisteredFolder`; the registry as 0.2.1-rc.2's installer writes it, `TestDshWindowsAsTheInstallerRegistersIt`). +- DS Bot (github.com/Fei2411/DS-Bot, Apache-2.0; rnhung on Discord) is a DSH plugin and an Electron app built on it. The plugin, loaded into DSH Desktop or `dsh web`, runs on `~/.dsh` and so takes the dsh row's routes. The app ships its own DSH (0.2.2-rc.1 in DS Bot 0.3.0) and runs it with `DSH_HOME` at a data folder of its own, booting the profile `ds-bot`, and never reads `~/.dsh`, so it is a row of its own, `ds-bot` ([`dsbot.go`](../../internal/agent/dsbot.go)), wired by dsh's code on that folder (`dshOn`). The folder is `$DS_BOT_HOME`, else `dataDir` in `locations.json` in the app's Electron userData (`$DS_BOT_SHELL_DATA`, else `/DS Bot`, or `DeepSeek Bot`, its name before, while that one is there and DS Bot's has no `locations.json`), else `~/.ds-bot` (`chooseLocations` and `configureIdentity` in the app's `app/src/first-run.mjs` and `legacy.mjs`). A `locations.json` that can't be read or names no folder is unknown: nothing is read or written, never `~/.ds-bot` in its place. The models listed are DS Bot's own on the Agents page: `dshApps` notes the folder as DS Bot's, and every route written under it is built from `magpieModels("ds-bot")` (`dshListFor`), including the serving round's (`dshHomesRounds`). A new Bot starts on DSH's `agent-default-model` unless a default Bot model is set in the app, and a Bot made before keeps its own (the notice says so). It is found by `DS Bot.app` (`io.github.fei2411.dsbot`) or the Windows per-user install under `HKCU\Software\32c46dfc-ed78-5d41-85a4-a3c7f083f2e0`; Linux's AppImage and deb aren't looked for, so there the folder its first start makes finds it. Installed and never opened, connecting writes `profiles/ds-bot/cordis.patch.yml` from dsh's template, which DS Bot 0.3.0's first start keeps (its template is dsh's byte for byte), and Disconnect before then takes it out (`TestDsBotWired`, `TestDsBotDataFolder`, `TestDsBotProfileMadeWhileServing`, `TestDsBotOwnModels`). - Ante's `catalog.json` keeps user-added fields in `providers.magpie` the same way (`ante` in [`ante.go`](../../internal/agent/ante.go)); its `auth`, `http_headers`, `extra_body` and `stream_idle_timeout_secs` are what a gateway shared on the local network or reached from WSL needs to send a key. Ante starts a session on the `provider` and `model` of `settings.json`, not on what its catalog holds (#1210), so magpie sets that pair and puts back what it found there; a pick the user makes in Ante while magpie is wired is theirs and stands. - QwenPaw keeps each agent's model in `active_model` of its workspace's `agent.json` (the agents listed in `config.json` under `$QWENPAW_WORKING_DIR`, a legacy `~/.copaw`, or `~/.qwenpaw`) and its providers as files under its secret folder (`$QWENPAW_SECRET_DIR`, also read from the working folder's `.env`, else `.secret`) (`qwenpaw` and `qwenpawAgents` in [`qwenpaw.go`](../../internal/agent/qwenpaw.go)). magpie writes `providers/custom/magpie.json` as QwenPaw's console saves a custom provider (OpenAI Chat at the gateway's `/v1`, the key in plain text, which QwenPaw encrypts at its next start, magpie's models in `extra_models`), keeps what the user changes there (a model's `config_overrides`, headers, generation settings), and sets the agent's `active_model` to `magpie`/`/`, putting back what it found there. A model with reasoning levels is declared `thinking_param_style: "effort"` with the levels QwenPaw names in `reasoning_effort_options` (no `none`: QwenPaw turns an off into Qwen's and DeepSeek's `extra_body` switches), since QwenPaw applies an agent's `thinking_level` only to a model whose card says how it thinks; the effort field is that `thinking_level` in `agent.json`, written with no `thinking_budget`, `inherit` when cleared. Each QwenPaw agent on QwenPaw's own backend is a row (`qwenpaw#` beside the default's `qwenpaw`); the provider file goes when no agent's model, fallback or subagent model names it. QwenPaw reads `agent.json` again when it changes but its providers only at start-up, so the notice says to restart it after the first connect. - AstrBot keeps its providers in `data/cmd_config.json` under its root (`$ASTRBOT_ROOT`, else `~/.astrbot`, the desktop app's, else `~/astrbot`), written with a UTF-8 BOM, which magpie keeps (`astrbot` in [`astrbot.go`](../../internal/agent/astrbot.go)). magpie adds a `magpie` entry to `provider_sources` and one `magpie/` entry per model to `provider`, keeps the user's own entries byte for byte and keeps what the user changes in magpie's (timeout, proxy, enable), and sets the default chat model (`agent_runner.config.model.provider_id`, or `provider_settings.default_provider_id` before the agent runner), putting back what it found there. A pick the user makes while magpie is wired is theirs and stands. The first connect copies the file to `cmd_config.json.before-magpie`. AstrBot reads the file only at start-up and its WebUI writes it back whole on save, so the agent's notice says to restart AstrBot before saving in the WebUI. A Docker install's root is inside its container, which magpie doesn't reach. diff --git a/internal/agent/agents.go b/internal/agent/agents.go index ba7bddd96..f6a00b028 100644 --- a/internal/agent/agents.go +++ b/internal/agent/agents.go @@ -270,6 +270,7 @@ func onMachine(home, cfg string) []*Agent { copilot(home), crush(home, cfg), dsh(home), + dsbot(home), reasonix(home), commandCode(home), fx(home), diff --git a/internal/agent/desktopapp.go b/internal/agent/desktopapp.go index ff0065828..b8085673d 100644 --- a/internal/agent/desktopapp.go +++ b/internal/agent/desktopapp.go @@ -64,6 +64,13 @@ var desktopApps = map[string]desktopApp{ // registers it under HKCU\Software\1bf39983-… (#2279, read from // 0.2.0-rc.2's dsh-latest-windows-x64.exe installer script). "dsh": {id: "com.deepseek.dsh", names: []string{"DeepSeek Harness.app"}, win: filepath.Join("DeepSeek Harness", "DeepSeek Harness.exe"), guid: "1bf39983-50d0-5fe0-9ef4-cece76f67c5e"}, + // DS Bot's desktop app (app/electron-builder.yml, 0.3.0: appId + // io.github.fei2411.dsbot, productName DS Bot, DS Bot.app; DeepSeek + // Bot, its name before) runs a DSH of its own on its data folder + // (dsbot.go) and needs no CLI. On Windows its per-user NSIS installer + // puts it under %LOCALAPPDATA%\Programs by default, lets the folder be + // changed, and registers it under the guid its config names. + "ds-bot": {id: "io.github.fei2411.dsbot", names: []string{"DS Bot.app", "DeepSeek Bot.app"}, win: filepath.Join("DS Bot", "DS Bot.exe"), guid: "32c46dfc-ed78-5d41-85a4-a3c7f083f2e0"}, // PenguinHarness's desktop app (packages/desktop's electron-builder.yml, // desktop 0.2.17: appId com.prismshadow.penguinharness, productName // PenguinHarness) runs its own server on the CLI's data root, diff --git a/internal/agent/dsbot.go b/internal/agent/dsbot.go new file mode 100644 index 000000000..6071e4c04 --- /dev/null +++ b/internal/agent/dsbot.go @@ -0,0 +1,136 @@ +package agent + +// DS Bot (github.com/Fei2411/DS-Bot, Apache-2.0) is a DSH plugin and an +// Electron desktop app built on it. The plugin, loaded into DSH Desktop or +// `dsh web`, runs on ~/.dsh and is magpie's dsh row. The desktop app ships +// its own DSH (0.2.2-rc.1 in DS Bot 0.3.0) and runs it with DSH_HOME at a +// data folder of its own (app/src/main.mjs), booting the profile ds-bot +// (app/src/profile.mjs). Its models are that DSH's llm-pi-ai routes and +// its new Bots start on DSH's agent-default-model (ds-bot/src/host/ +// models.js), so magpie wires that home as it wires ~/.dsh: its route in +// each profile's patch list, the key in .env and DSH's key store, and the +// start in agent-default-model (dshOn). + +import ( + "encoding/json" + "errors" + "os" + "path/filepath" + "strings" + + "github.com/yetone/magpie/internal/appdir" + "github.com/yetone/magpie/internal/gateway" +) + +const dsbotID = "ds-bot" + +// dsbotProfile is the profile the app's DSH boots, under its data folder +// (PROFILE in app/src/profile.mjs). +const dsbotProfile = "ds-bot" + +// dsbotFile is the app's profile's patch list in its data folder dir. The +// app's initProfile writes each of the profile's files only where it is +// missing, as dsh's does: one magpie made before the app first opened is +// kept (seen with DS Bot 0.3.0, whose template is dsh's byte for byte). +func dsbotFile(dir string) string { + return filepath.Join(dir, "profiles", dsbotProfile, "cordis.patch.yml") +} + +// dsbotHome is the app's data folder, the DSH_HOME its DSH runs on, and +// whether it is known. chooseLocations (app/src/first-run.mjs) takes it +// from DS_BOT_HOME, which runs the app on throwaway folders, else from +// locations.json's dataDir in the app's Electron userData (DS_BOT_SHELL_DATA +// when set, else /DS Bot, or /DeepSeek Bot, its name +// before, while that one is there and DS Bot's has no locations.json: +// configureIdentity in app/src/legacy.mjs), else ~/.ds-bot, the folder its +// first run saves when the user keeps the default. A locations.json that +// can't be read or names no folder is unknown: never taken for the default, +// where magpie would wire a folder the app doesn't run on. +func dsbotHome() (string, bool) { + if dir := appdir.Getenv("DS_BOT_HOME"); dir != "" { + return dir, true + } + userData := appdir.Getenv("DS_BOT_SHELL_DATA") + if userData == "" { + cfg, err := os.UserConfigDir() + if err != nil { + return "", false + } + userData = filepath.Join(cfg, "DS Bot") + if legacy := filepath.Join(cfg, "DeepSeek Bot"); !isFile(filepath.Join(userData, "locations.json")) && isDir(legacy) { + userData = legacy + } + } + b, err := os.ReadFile(filepath.Join(userData, "locations.json")) + if errors.Is(err, os.ErrNotExist) { + home, err := os.UserHomeDir() + if err != nil { + return "", false + } + return filepath.Join(home, ".ds-bot"), true + } + if err != nil { + return "", false + } + var places struct { + DataDir string `json:"dataDir"` + } + if json.Unmarshal(b, &places) != nil || strings.TrimSpace(places.DataDir) == "" { + return "", false + } + return places.DataDir, true +} + +// dsbotDataDir is dsbotHome, "" when it is unknown, with the folder noted +// as DS Bot's (dshApps): the routes written there are DS Bot's models. +func dsbotDataDir() string { + dir, ok := dsbotHome() + if !ok { + return "" + } + dshApps.Store(filepath.Clean(dir), dsbotID) + return dir +} + +func dsbot(home string) *Agent { + dir := dsbotDataDir() + // the app, installed on this machine (Linux's AppImage and deb aren't + // looked for: there the data folder its first start makes finds it) + app := func() bool { return (&Agent{ID: dsbotID}).HasApp() } + if dir == "" { + // its data folder can't be told: nothing to read or write + return &Agent{ID: dsbotID, Name: "DS Bot", Icon: "deepseek-color", detect: app} + } + fresh := func() string { return dsbotFile(dir) } + a := dshOn(here(home), dir, dsbotID, fresh, func() string { return dsbotProfile }) + a.ID, a.Name, a.Icon = dsbotID, "DS Bot", "deepseek-color" + a.Aliases = []string{"dsbot", "deepseek-bot"} + // no Bin: its command (dsbot, on Linux) is the app itself, which a + // version check would open + // installed and not opened yet, it has no data folder + a.sign = app + a.Notice = func() string { + var notes []string + if app() && dshUnbooted(dsbotFile(dir)) { + notes = append(notes, noticeDsbotUnopened.String()) + } else { + // a Bot has its own model, kept when the start changes: only + // a new one starts on agent-default-model, and only while no + // default Bot model is set in the app (defaultBotModel) + notes = append(notes, noticeDsbotNewBots.String()) + } + if dshSearchesHere(dir) && !gateway.CanSearch() { + notes = append(notes, noticeDsbotSearch.String()) + } + return strings.Join(notes, " ") + } + // what magpie made for an app never opened goes + a.Restore = func() error { return dshTidyMade(dir, dsbotFile(dir)) } + return a +} + +var ( + noticeDsbotUnopened = newNotice("DS Bot hasn't been opened yet: it starts on this the first time it opens.") + noticeDsbotNewBots = newNotice("New Bots in DS Bot start on this, unless a default model for Bots is set in DS Bot. A Bot made before keeps its own model until you pick another for it.") + noticeDsbotSearch = newNotice("DS Bot's web search goes through magpie, which has nothing to search with yet: set up a provider that searches by itself (DeepSeek, Claude, Codex, …) or a search API under Settings › Web search.") +) diff --git a/internal/agent/dsbot_test.go b/internal/agent/dsbot_test.go new file mode 100644 index 000000000..8b3d1732f --- /dev/null +++ b/internal/agent/dsbot_test.go @@ -0,0 +1,293 @@ +package agent + +import ( + "os" + "path/filepath" + "strings" + "testing" + + "github.com/yetone/magpie/internal/provider" +) + +// dsbotAppPlist is DS Bot's Info.plist as its 0.3.0 macOS build ships it +// (github.com/Fei2411/DS-Bot's release), cut to the keys around the ones +// read, in their order and indentation. +const dsbotAppPlist = ` + + + + CFBundleDisplayName + DS Bot + CFBundleExecutable + DS Bot + CFBundleIconFile + icon.icns + CFBundleIdentifier + io.github.fei2411.dsbot + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + DS Bot + CFBundlePackageType + APPL + CFBundleShortVersionString + 0.3.0 + CFBundleVersion + 0.3.0 + + +` + +// dsbotSandbox is dshRouteHome with DS Bot's own places in it: its +// Electron userData (DS_BOT_SHELL_DATA) and an app folder, both empty. +func dsbotSandbox(t *testing.T) (home, dsh, userData, apps string) { + t.Helper() + home, dsh, _ = dshRouteHome(t) + t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming")) + t.Setenv("DS_BOT_HOME", "") + userData = filepath.Join(home, "shell") + t.Setenv("DS_BOT_SHELL_DATA", userData) + t.Setenv("PATH", t.TempDir()) + apps = t.TempDir() + was := appFolders + appFolders = func() []string { return []string{apps} } + t.Cleanup(func() { appFolders = was }) + return home, dsh, userData, apps +} + +func dsbotRead(p string) string { b, _ := os.ReadFile(p); return string(b) } + +// rnhung (Discord): DS Bot (dsbot.app) asked for. The app runs a DSH of +// its own on its data folder, ~/.ds-bot by default, booting the profile +// ds-bot, and never reads ~/.dsh: magpie's dsh row didn't reach it. It is +// its own row now, found by its bundle, and a model picked there goes into +// its profile, DSH's key store and .env in that folder, with ~/.dsh left +// alone. Not opened yet, the profile is made as its first start makes it, +// which the app keeps (seen with 0.3.0); Disconnect before then takes it +// out again. +func TestDsBotWired(t *testing.T) { + judgeFor(t, "darwin") + home, dshDir, _, apps := dsbotSandbox(t) + if err := os.RemoveAll(dshDir); err != nil { + t.Fatal(err) + } + data := filepath.Join(home, ".ds-bot") + file := filepath.Join(data, "profiles", "ds-bot", "cordis.patch.yml") + + if a := dsbot(home); a.Detected() { + t.Fatal("no app and no data folder, yet detected") + } + installApp(t, apps, "DS Bot.app", strings.Replace(dsbotAppPlist, "io.github.fei2411.dsbot", "com.example.other", 1)) + if dsbot(home).Detected() { + t.Fatal("another bundle under DS Bot's name taken for it") + } + if err := os.RemoveAll(filepath.Join(apps, "DS Bot.app")); err != nil { + t.Fatal(err) + } + installApp(t, apps, "DS Bot.app", dsbotAppPlist) + a := dsbot(home) + if !a.Detected() || a.CLIMissing() { + t.Fatalf("the app: detected %v, CLI missing %v", a.Detected(), a.CLIMissing()) + } + if c, ok := a.CLI(); !ok || c.App != "0.3.0" { + t.Fatalf("the app's version: %+v %v", c, ok) + } + if a.Path != file { + t.Fatalf("names %s, not DS Bot's profile", a.Path) + } + + if err := a.Pick("model", "magpie/deepseek/flash"); err != nil { + t.Fatal(err) + } + s := dsbotRead(file) + if !strings.HasPrefix(s, strings.TrimSuffix(dshProfileTemplate, "[]\n")) || !strings.Contains(s, "apiKeyEnv: "+dshKeyRef) || !strings.Contains(s, "provider: "+dshRoute) || !strings.Contains(s, "- id: deepseek/pro") { + t.Fatalf("DS Bot's profile:\n%s", s) + } + if c := dsbotRead(filepath.Join(data, ".credentials.yaml")); !strings.Contains(c, dshKeyRef+": ") { + t.Fatalf("no key in DS Bot's DSH store:\n%s", c) + } + if e := dsbotRead(filepath.Join(data, ".env")); !strings.Contains(e, dshKeyRef+"=") { + t.Fatalf("no key in DS Bot's .env:\n%s", e) + } + if _, err := os.Stat(dshDir); !os.IsNotExist(err) { + t.Fatalf("~/.dsh written for DS Bot: %v", err) + } + a = dsbot(home) + if got := a.Field("model").Get(); got != "magpie/deepseek/flash" { + t.Fatalf("model reads %q", got) + } + if !a.Wired() || a.Check() != "" || a.Drift() != nil { + t.Fatalf("not wired: wired %v, check %q, drift %+v", a.Wired(), a.Check(), a.Drift()) + } + if n := a.Notice(); !strings.Contains(n, noticeDsbotUnopened.String()) { + t.Fatalf("notice before the app opened: %q", n) + } + + // Disconnect before the app ever opened: what magpie made goes + if err := a.Disconnect(); err != nil { + t.Fatal(err) + } + if _, err := os.Stat(filepath.Join(data, "profiles")); !os.IsNotExist(err) { + t.Fatalf("the profile magpie made outlived Disconnect: %v\n%s", err, dsbotRead(file)) + } + + // connected again, and the app's first start beside it + a = dsbot(home) + if err := a.Pick("model", "magpie/deepseek/flash"); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(filepath.Dir(file), "package.json"), []byte("{}\n"), 0o644); err != nil { + t.Fatal(err) + } + if n := dsbot(home).Notice(); !strings.Contains(n, noticeDsbotNewBots.String()) || strings.Contains(n, noticeDsbotUnopened.String()) { + t.Fatalf("notice after the app opened: %q", n) + } + // dsh's own row still has no ~/.dsh + if dsh(home).Detected() { + t.Fatal("DS Bot's folder taken for dsh's") + } +} + +// DS Bot's data folder is where its first run's choice put it +// (locations.json in its userData), its legacy userData (DeepSeek Bot) +// while DS Bot's has none, or DS_BOT_HOME. A locations.json that can't be +// read is unknown: nothing is written, least of all to ~/.ds-bot, which +// the app doesn't run on then. +func TestDsBotDataFolder(t *testing.T) { + home, _, userData, _ := dsbotSandbox(t) + if dir, ok := dsbotHome(); !ok || dir != filepath.Join(home, ".ds-bot") { + t.Fatalf("no locations.json: %q %v", dir, ok) + } + picked := filepath.Join(home, "Documents", "bot-data") + if err := os.MkdirAll(userData, 0o755); err != nil { + t.Fatal(err) + } + loc := filepath.Join(userData, "locations.json") + if err := os.WriteFile(loc, []byte(`{"dataDir":"`+filepath.ToSlash(picked)+`","workspace":"x","freeAtStart":false}`), 0o644); err != nil { + t.Fatal(err) + } + if dir, ok := dsbotHome(); !ok || filepath.Clean(dir) != picked { + t.Fatalf("locations.json's dataDir: %q %v", dir, ok) + } + a := dsbot(home) + if err := a.Pick("model", "magpie/deepseek/flash"); err != nil { + t.Fatal(err) + } + if s := dsbotRead(dsbotFile(picked)); !strings.Contains(s, "provider: "+dshRoute) { + t.Fatalf("the picked folder's profile:\n%s", s) + } + + t.Setenv("DS_BOT_HOME", filepath.Join(home, "throwaway")) + if dir, ok := dsbotHome(); !ok || dir != filepath.Join(home, "throwaway") { + t.Fatalf("DS_BOT_HOME: %q %v", dir, ok) + } + t.Setenv("DS_BOT_HOME", "") + + for _, bad := range []string{"{", `{"dataDir":""}`, `{"workspace":"x"}`} { + if err := os.WriteFile(loc, []byte(bad), 0o644); err != nil { + t.Fatal(err) + } + if dir, ok := dsbotHome(); ok { + t.Fatalf("%s taken for %q", bad, dir) + } + a := dsbot(home) + if a.Detected() || len(a.Fields) != 0 { + t.Fatalf("%s: detected %v, fields %d", bad, a.Detected(), len(a.Fields)) + } + } + if _, err := os.Stat(filepath.Join(home, ".ds-bot")); !os.IsNotExist(err) { + t.Fatalf("~/.ds-bot made: %v", err) + } + + // the userData of DS Bot's name before, while DS Bot's has none + t.Setenv("DS_BOT_SHELL_DATA", "") + cfg, err := os.UserConfigDir() + if err != nil { + t.Fatal(err) + } + legacy := filepath.Join(cfg, "DeepSeek Bot") + if err := os.MkdirAll(legacy, 0o755); err != nil { + t.Fatal(err) + } + old := filepath.Join(home, "old-bot") + if err := os.WriteFile(filepath.Join(legacy, "locations.json"), []byte(`{"dataDir":"`+filepath.ToSlash(old)+`"}`), 0o644); err != nil { + t.Fatal(err) + } + if dir, ok := dsbotHome(); !ok || filepath.Clean(dir) != old { + t.Fatalf("legacy userData: %q %v", dir, ok) + } + now := filepath.Join(cfg, "DS Bot") + if err := os.MkdirAll(now, 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(now, "locations.json"), []byte(`{"dataDir":"`+filepath.ToSlash(picked)+`"}`), 0o644); err != nil { + t.Fatal(err) + } + if dir, ok := dsbotHome(); !ok || filepath.Clean(dir) != picked { + t.Fatalf("DS Bot's own userData beside the legacy one: %q %v", dir, ok) + } +} + +// A Bot made in DS Bot starts in the app's own profile; one the app makes +// while magpie serves (empty, as DSH makes them) is filled by the serving +// round as ~/.dsh's are, with DS Bot's models. +func TestDsBotProfileMadeWhileServing(t *testing.T) { + home, _, _, _ := dsbotSandbox(t) + data := filepath.Join(home, ".ds-bot") + if err := dsbot(home).Pick("model", "magpie/deepseek/flash"); err != nil { + t.Fatal(err) + } + other := filepath.Join(data, "profiles", "import-check", "cordis.patch.yml") + if err := os.MkdirAll(filepath.Dir(other), 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(other, []byte(dshProfileTemplate), 0o644); err != nil { + t.Fatal(err) + } + if trouble := dshWiredOnce(); trouble != "" { + t.Fatal(trouble) + } + if s := dsbotRead(other); !strings.Contains(s, "apiKeyEnv: "+dshKeyRef) || !strings.Contains(s, "- id: deepseek/pro") { + t.Fatalf("the round left DS Bot's new profile bare:\n%s", s) + } + if d := dsbot(home).Check(); d != "" { + t.Fatalf("after the round: %s", d) + } +} + +// The models shown for DS Bot on the Agents page are its own: one hidden +// for it is out of its route and still in dsh's, and the other way round. +func TestDsBotOwnModels(t *testing.T) { + home, dshDir, _, _ := dsbotSandbox(t) + data := filepath.Join(home, ".ds-bot") + if err := provider.SetHiddenModels(dsbotID, []string{"deepseek/pro"}); err != nil { + t.Fatal(err) + } + if err := dsbot(home).Pick("model", "magpie/deepseek/flash"); err != nil { + t.Fatal(err) + } + if err := dsh(home).Pick("model", "magpie/deepseek/flash"); err != nil { + t.Fatal(err) + } + bot := dsbotRead(dsbotFile(data)) + web := dsbotRead(filepath.Join(dshDir, "profiles", "web", "cordis.patch.yml")) + if strings.Contains(bot, "- id: deepseek/pro") || !strings.Contains(bot, "- id: deepseek/flash") { + t.Fatalf("DS Bot's route with pro hidden for it:\n%s", bot) + } + if !strings.Contains(web, "- id: deepseek/pro") { + t.Fatalf("dsh's route lost a model hidden for DS Bot only:\n%s", web) + } + if d := dsbot(home).Check(); d != "" { + t.Fatalf("DS Bot's check: %s", d) + } + if d := dsh(home).Check(); d != "" { + t.Fatalf("dsh's check: %s", d) + } + // the serving round keeps each to its own + if trouble := dshWiredOnce(); trouble != "" { + t.Fatal(trouble) + } + if strings.Contains(dsbotRead(dsbotFile(data)), "- id: deepseek/pro") { + t.Fatal("the round put pro back in DS Bot's route") + } +} diff --git a/internal/agent/dsh.go b/internal/agent/dsh.go index bc2cad88e..b557c41d2 100644 --- a/internal/agent/dsh.go +++ b/internal/agent/dsh.go @@ -95,7 +95,6 @@ func dshIn(at place) *Agent { return dshAt(at) } // dshAt is DeepSeek Harness with its home at at.home, reaching the gateway // as at does. A distro's DSH_HOME can't be read, so there it is ~/.dsh. func dshAt(at place) *Agent { - gw := at.gw dir := at.getenv("DSH_HOME") if dir == "" { dir = at.join(".dsh") @@ -119,8 +118,66 @@ func dshAt(at place) *Agent { } return dshWebFile(dir) } + // the desktop app's profile is the one whose start is shown (#5222) + lead := func() string { + if desktop() { + return "desktop" + } + return "" + } + a := dshOn(at, dir, "dsh", fresh, lead) + a.ID, a.Name, a.Icon, a.Aliases = "dsh", "DeepSeek Harness", "deepseek-color", []string{"deepseek-harness"} + a.UA = []string{"deepseek-harness"} + a.Bin = "dsh" + // the desktop app installed and not opened yet has no ~/.dsh (#2279) + a.sign = desktop + a.Notice = func() string { + var notes []string + if desktop() && dshUnopened(dir) { + // nothing of dsh's runs on it yet to be restarted + notes = append(notes, noticeDsh5.String()) + } else if len(dshProfiles(dir)) > 0 { + // a session dsh already has keeps the model it was on, + // running or not: agent-default-model is read for new + // ones only (#2359) + notes = append(notes, noticeDsh1.String()) + } else if Running(`DeepSeek Harness\.app/`, `(^|/)dsh( |$)`) { + notes = append(notes, noticeDsh2.String()) + } + if dshSearchesHere(dir) && !gateway.CanSearch() { + notes = append(notes, noticeDsh3.String()) + } + // only before 0.1.5 does magpie go through llm-deepseek + if !dshModern(dir, fresh) && dshSettingsEndpoint(filepath.Join(dir, "settings.yaml")) { + notes = append(notes, noticeDsh4.String()) + } + return strings.Join(notes, " ") + } + // what magpie made for a desktop app never opened goes (#2279) + a.Restore = func() error { + if err := dshTidyUnopened(dir); err != nil { + return err + } + return dshTidyUnbooted(dir) + } + return a +} + +// dshModern says a dsh home's patch lists are its profiles' (dsh 0.1.5 +// on): it has one, or fresh names the one magpie makes. +func dshModern(dir string, fresh func() string) bool { + return len(dshProfiles(dir)) > 0 || fresh() != "" +} + +// dshOn is what a dsh home at dir is wired by, for the agent whose models +// list names (see dshListFor): fresh is the patch list magpie makes there +// while it has no profile ("" for config.yaml), and lead the profile whose +// start is shown ("" for the first). The caller names the agent, and gives +// it its sign, notice and restore. +func dshOn(at place, dir, list string, fresh, lead func() string) *Agent { + gw := at.gw // profiles' patch lists, or one magpie makes, are what dsh reads - modern := func() bool { return len(dshProfiles(dir)) > 0 || fresh() != "" } + modern := func() bool { return dshModern(dir, fresh) } path := filepath.Join(dir, "config.yaml") // a stopped distro's folder is never listed: that starts it (#3896) var files []string @@ -133,34 +190,9 @@ func dshAt(at place) *Agent { path = f } return &Agent{ - ID: "dsh", Name: "DeepSeek Harness", Icon: "deepseek-color", Aliases: []string{"deepseek-harness"}, Spelled: prefixed, - UA: []string{"deepseek-harness"}, - Bin: "dsh", Dir: dir, Path: path, - // the desktop app installed and not opened yet has no ~/.dsh (#2279) - sign: desktop, - Sync: func() error { return dshSyncFresh(at, dir, gw(), fresh) }, - Notice: func() string { - var notes []string - if desktop() && dshUnopened(dir) { - // nothing of dsh's runs on it yet to be restarted - notes = append(notes, noticeDsh5.String()) - } else if len(dshProfiles(dir)) > 0 { - // a session dsh already has keeps the model it was on, - // running or not: agent-default-model is read for new - // ones only (#2359) - notes = append(notes, noticeDsh1.String()) - } else if Running(`DeepSeek Harness\.app/`, `(^|/)dsh( |$)`) { - notes = append(notes, noticeDsh2.String()) - } - if dshSearchesHere(dir) && !gateway.CanSearch() { - notes = append(notes, noticeDsh3.String()) - } - // only before 0.1.5 does magpie go through llm-deepseek - if !modern() && dshSettingsEndpoint(filepath.Join(dir, "settings.yaml")) { - notes = append(notes, noticeDsh4.String()) - } - return strings.Join(notes, " ") - }, + Spelled: prefixed, + Dir: dir, Path: path, + Sync: func() error { return dshSyncFresh(at, dir, gw(), fresh) }, Check: func() string { return dshCheck(dir, gw()) }, // a model of DeepSeek's own picked in dsh (saved in its settings) // leaves magpie's route in its list: dsh is still connected, its @@ -177,7 +209,7 @@ func dshAt(at place) *Agent { // connected so, Disconnect takes the route out, the start magpie // wrote and its key; the model picked in dsh stays its own Unwire: func() error { - if usesMagpie(dshGet(dir, false)) { + if usesMagpie(dshGet(dir, "")) { return nil // the model set back does it all } dshWrites.Lock() @@ -198,16 +230,9 @@ func dshAt(at place) *Agent { } return dshEnv(at, dir, gw(), false, false) }, - // what magpie made for a desktop app never opened goes (#2279) - Restore: func() error { - if err := dshTidyUnopened(dir); err != nil { - return err - } - return dshTidyUnbooted(dir) - }, Fields: []Field{{ Key: "model", Label: "model", - Get: func() string { return dshGet(dir, desktop()) }, + Get: func() string { return dshGet(dir, lead()) }, Set: func(v string) error { // the desktop app not opened yet, or a dsh that hasn't // booted a profile: the profile is made as dsh makes it, @@ -231,7 +256,7 @@ func dshAt(at place) *Agent { own[i].Direct = "DeepSeek" } } - return withVia(own, "dsh", magpieID+"/") + return withVia(own, list, magpieID+"/") }, }, { // the thinking effort sessions start with: agent-default-model's @@ -239,14 +264,14 @@ func dshAt(at place) *Agent { // own levels), llm-deepseek's before (off, low, high or max; // dsh's own default is high) Key: "effort", Label: "thinking", - Get: func() string { return dshGetEffort(dir, desktop()) }, - Set: func(v string) error { return dshSetEffort(dir, v, gw(), desktop()) }, + Get: func() string { return dshGetEffort(dir, lead()) }, + Set: func(v string) error { return dshSetEffort(dir, v, gw(), lead()) }, Options: func(cur map[string]string) []Option { // a model through magpie that lists no levels has none in // dsh (its route gives it no reasoningEfforts), so none is // offered: dsh's own four were, and each was turned away if ref, ok := strings.CutPrefix(cur["model"], magpieID+"/"); ok && modern() { - return static(dshLevels(ref)...) + return static(dshLevels(list, ref)...) } return static(dshEfforts...) }, @@ -254,6 +279,30 @@ func dshAt(at place) *Agent { } } +// dshApps are the homes of the apps that run a dsh of their own on a home +// apart from ~/.dsh (DS Bot's), by folder, each with the id of the agent +// whose model list magpie writes there: a model taken out of DS Bot's list +// in magpie is not written into its home. Filled as each agent is built. +var dshApps sync.Map + +// dshListFor is the agent whose models magpie writes into the dsh file or +// home at path: the app's whose home holds it, else dsh's. +func dshListFor(path string) string { + id := "dsh" + if path == "" { + return id + } + p := filepath.Clean(path) + dshApps.Range(func(k, v any) bool { + if rel, err := filepath.Rel(k.(string), p); err == nil && rel != ".." && !strings.HasPrefix(rel, ".."+string(filepath.Separator)) { + id = v.(string) + return false + } + return true + }) + return id +} + // dshProfiles are the profiles' patch lists (dsh 0.1.5 on), web's first. func dshProfiles(dir string) []string { files, _ := filepath.Glob(filepath.Join(dir, "profiles", "*", "cordis.patch.yml")) @@ -801,8 +850,8 @@ func dshWired(items []dshItem) bool { return len(dshRoutesIn(items)) > 0 } // dshServes reports whether magpie gives dsh this model now: the route // written again would list it, where one naming a model magpie no longer // gives dsh would not. -func dshServes(id string) bool { - for _, m := range sharedModels("dsh") { +func dshServes(dir, id string) bool { + for _, m := range sharedModels(dshListFor(dir)) { if m.ID == id { return true } @@ -827,21 +876,22 @@ func dshRouteLists(route *yaml.Node, id string) bool { var dshModelLine = regexp.MustCompile(`^\s+model:\s*(.+?)\s*$`) -// dshLead is the profile whose start magpie shows: the desktop app's when -// DeepSeek Harness Desktop is installed (desktop), else the first, web's; -// "" before profiles. dsh saves a model picked in it into the profile in +// dshLead is the profile whose start magpie shows: the one named lead +// when there is one (the desktop app's when DeepSeek Harness Desktop is +// installed, DS Bot's in its home), else the first, web's; "" before +// profiles. dsh saves a model picked in it into the profile in // use alone (ConfigEditor.edit in dsh-config-editor), so the profiles can // start on different models, each the user's own. Read from web's alone, // the Agents page showed a model the desktop app's sessions don't start // on, and picking what it showed changed nothing there (#5222). -func dshLead(dir string, desktop bool) string { +func dshLead(dir, lead string) string { files := dshProfiles(dir) if len(files) == 0 { return "" } - if desktop { + if lead != "" { for _, f := range files { - if filepath.Base(filepath.Dir(f)) == "desktop" { + if filepath.Base(filepath.Dir(f)) == lead { return f } } @@ -852,8 +902,8 @@ func dshLead(dir string, desktop bool) string { // dshGet reads the model new sessions start on: the one last picked in dsh, // saved in its settings (0.1.x), else the patch list's, the lead profile's // (dshLead). -func dshGet(dir string, desktop bool) string { - f := dshLead(dir, desktop) +func dshGet(dir, lead string) string { + f := dshLead(dir, lead) if f == "" { return dshGetLegacy(filepath.Join(dir, "config.yaml")) } @@ -923,7 +973,7 @@ func dshGetLegacy(path string) string { // 0.1.5 — the key it names gone from .env, or another key under that name in // dsh's own store, which it reads first. func dshCheck(dir, gw string) string { - if !usesMagpie(dshGet(dir, false)) { + if !usesMagpie(dshGet(dir, "")) { return "" } files := dshProfiles(dir) @@ -958,7 +1008,7 @@ func dshCheck(dir, gw string) string { // for the round to write it from. A profile taken off magpie for real, // its start with it, is said as before, and so is one still on the old // wiring, which dshSync moves rather than this round writing beside. - canWriteBack := len(sharedModels("dsh")) > 0 + canWriteBack := len(sharedModels(dshListFor(dir))) > 0 for _, f := range files[1:] { _, items, err := dshRead(f) if err != nil || dshWired(dshOver(dir, items)) { @@ -1035,7 +1085,7 @@ func dshCheck(dir, gw string) string { // a model of magpie's in dsh, does it; one naming a model magpie // no longer gives dsh is not, so that one asks for another model // rather than for a click that cannot help - if dshServes(ref) { + if dshServes(dir, ref) { return "DeepSeek Harness starts on " + magpieID + "/" + ref + ", which magpie's route in " + f + " doesn't list: a session there fails with no such configured model until that route is written again (Apply again, or pick one of magpie's models in dsh)" } return "DeepSeek Harness starts on " + magpieID + "/" + ref + ", which magpie no longer gives dsh: a session there fails with no such configured model until another of magpie's is picked in dsh" @@ -1064,7 +1114,7 @@ func dshCheck(dir, gw string) string { // nothing can (no catalog to write it from — the key check still runs, since // a route written without its key would fail the turn all the same). func dshCheckStripped(dir, gw string) string { - if len(sharedModels("dsh")) == 0 { + if len(sharedModels(dshListFor(dir))) == 0 { return "DeepSeek Harness starts on one of magpie's models, but magpie's route is out of " + dshHomePatch(dir) + " and the profiles' and there is no model list to write it back from; pick a model of magpie's again once it has one" } env := filepath.Join(dir, ".env") @@ -1113,7 +1163,7 @@ func dshSetLocked(at place, dir, v, gw string) error { return fmt.Errorf("unknown model %q", v) } legacy := filepath.Join(dir, "config.yaml") - models := magpieModels("dsh") + models := magpieModels(dshListFor(dir)) files := dshProfiles(dir) if len(files) == 0 { return dshSetFile(legacy, v, false, models, gw) @@ -1508,7 +1558,7 @@ func dshSetFile(path, v string, modern bool, models []catalog.Model, gw string) if items, err = dshPutRoute(items, true, models, gw); err != nil { return err } - if !contains(dshLevels(ref), effort) { + if !contains(dshLevels(dshListFor(path), ref), effort) { effort = "" } put("agent-default-model", dshDefaultLines(dshRouteFor(ref, models), ref, effort)) @@ -1883,8 +1933,8 @@ func dshModelLevels(efforts []string) ([]string, *dshPiLevels) { } // dshLevels are the thinking levels dsh offers for a catalog model. -func dshLevels(ref string) []string { - for _, m := range sharedModels("dsh") { +func dshLevels(list, ref string) []string { + for _, m := range sharedModels(list) { if m.ID == ref { levels, _ := dshModelLevels(m.Efforts) return levels @@ -2112,7 +2162,7 @@ func dshSync(dir, gw string) error { func dshSyncFresh(at place, dir, gw string, fresh func() string) error { dshWrites.Lock() defer dshWrites.Unlock() - models := magpieModels("dsh") + models := magpieModels(dshListFor(dir)) files := dshProfiles(dir) made := "" if len(files) == 0 { @@ -2314,9 +2364,9 @@ func KeepDshWired(ctx context.Context) { // that could not write something is said once rather than every round. func keepDshWired(ctx context.Context, every time.Duration) { var said dshSaidOnce - var rounds dshRounds + rounds := dshHomesRounds() for { - if trouble := rounds.once(); said.first(trouble) { + if trouble := dshRoundsOnce(rounds); said.first(trouble) { log.Print(trouble) } select { @@ -2347,6 +2397,24 @@ func (s *dshSaidOnce) first(trouble string) bool { // reaches dsh's lists within it. const dshModelsFor = 5 * time.Minute +// dshHomesRounds are a round for each dsh home magpie keeps wired: dsh's +// own, and DS Bot's, whose app runs its own dsh on a home of its own +// (dsbotHome) and reads its patch list live as dsh does. +func dshHomesRounds() []*dshRounds { + return []*dshRounds{{}, {home: dsbotDataDir, list: dsbotID}} +} + +// dshRoundsOnce does each of rounds once, and says what any could not write. +func dshRoundsOnce(rounds []*dshRounds) string { + var trouble []string + for _, r := range rounds { + if t := r.once(); t != "" { + trouble = append(trouble, t) + } + } + return strings.Join(trouble, "; ") +} + // dshRounds is what keepDshWired's last round read, so that a round with // nothing changed since does nothing. Every 30 seconds a round built // magpie's whole catalog and every route again to write nothing: 12 GB of @@ -2355,6 +2423,11 @@ const dshModelsFor = 5 * time.Minute // or magpie's models are other than when the last one found nothing to // write. The zero dshRounds does every round. type dshRounds struct { + // home is the dsh home the rounds keep wired, "" when there is none + // or it can't be told; nil: dsh's own (dshHome). list is the agent + // whose models are written there; "": dsh's. + home func() string + list string // the models, and the stamp and time they were built at models []catalog.Model stamp provider.Stamp @@ -2417,10 +2490,10 @@ func dshModelsSum(models []catalog.Model) uint64 { } // dshWiredOnce writes magpie's route again in every patch list whose route -// is not what magpie would write now, and says what could not be written. +// is not what magpie would write now, in each dsh home, and says what could +// not be written. func dshWiredOnce() string { - var r dshRounds - return r.once() + return dshRoundsOnce(dshHomesRounds()) } // once is dshWiredOnce, done only when something the round reads changed @@ -2428,8 +2501,16 @@ func dshWiredOnce() string { func (r *dshRounds) once() string { dshWrites.Lock() defer dshWrites.Unlock() - dir := dshHome() + home, list := r.home, r.list + if home == nil { + home = dshHome + } + if list == "" { + list = "dsh" + } + dir := home() if dir == "" { + r.done = false return "" } files := dshProfiles(dir) @@ -2443,7 +2524,7 @@ func (r *dshRounds) once() string { // the stamp is read before the models are built: a change while they // are moves it past the one kept, and the next round builds them again if stamp := provider.StampNow(); !r.built || stamp != r.stamp || time.Since(r.at) >= dshModelsFor { - r.models, r.stamp, r.at, r.built = magpieModels("dsh"), stamp, time.Now(), true + r.models, r.stamp, r.at, r.built = magpieModels(list), stamp, time.Now(), true key.models = dshModelsSum(r.models) } if r.done && key == r.last { @@ -2672,8 +2753,8 @@ func DshPatchFiles(dir string) []string { return dshFiles(dir) } // dshGetEffort reads the effort sessions start with, in the lead profile // (dshLead). -func dshGetEffort(dir string, desktop bool) string { - f := dshLead(dir, desktop) +func dshGetEffort(dir, lead string) string { + f := dshLead(dir, lead) if f == "" { _, items, err := dshRead(filepath.Join(dir, "config.yaml")) if err != nil { @@ -2692,7 +2773,7 @@ func dshGetEffort(dir string, desktop bool) string { // agent-default-model (0.1.5 on), or into magpie's llm-deepseek entry // before, dsh's own row being used whole when there is none. The levels // offered are the lead profile's model's (dshLead), as the picker shows it. -func dshSetEffort(dir, v, gw string, desktop bool) error { +func dshSetEffort(dir, v, gw, lead string) error { dshWrites.Lock() defer dshWrites.Unlock() files := dshProfiles(dir) @@ -2700,15 +2781,15 @@ func dshSetEffort(dir, v, gw string, desktop bool) error { if dshHomeHas(dir, "agent-default-model") { files = append(files, dshHomePatch(dir)) } - model := dshGet(dir, desktop) + model := dshGet(dir, lead) ref, viaGateway := strings.CutPrefix(model, magpieID+"/") levels := dshEfforts if viaGateway { - levels = dshLevels(ref) + levels = dshLevels(dshListFor(dir), ref) } route := dshRoute if viaGateway { - route = dshRouteFor(ref, magpieModels("dsh")) + route = dshRouteFor(ref, magpieModels(dshListFor(dir))) } if v != "" && len(levels) == 0 { return fmt.Errorf("DeepSeek Harness has no thinking levels for %s: magpie knows of none the model takes", ref) @@ -2764,7 +2845,7 @@ func dshSetEffort(dir, v, gw string, desktop bool) error { head, items, err := dshRead(f) if err == nil { if i := dshFind(items, "llm-deepseek"); i >= 0 && items[i].magpie { - models := magpieModels("dsh") + models := magpieModels(dshListFor(dir)) if len(models) == 0 { return fmt.Errorf("DeepSeek Harness has no models to write: magpie has none to hand it") } diff --git a/internal/agent/dsh_test.go b/internal/agent/dsh_test.go index 0ba0e1911..7ceaffd9e 100644 --- a/internal/agent/dsh_test.go +++ b/internal/agent/dsh_test.go @@ -290,7 +290,7 @@ func TestDshSetEffortLeavesALegacyEntryWithNoCatalogAlone(t *testing.T) { if err := os.WriteFile(path, []byte(own), 0o644); err != nil { t.Fatal(err) } - if err := dshSetEffort(dir, "high", gateway.URL(), false); err == nil { + if err := dshSetEffort(dir, "high", gateway.URL(), ""); err == nil { t.Fatal("an empty catalog should refuse the write") } if b, _ := os.ReadFile(path); string(b) != own { @@ -312,7 +312,7 @@ func TestDshSetEffortWritesALegacyEntryWithTheCatalog(t *testing.T) { if err := os.WriteFile(path, []byte("# mine\n- id: llm-deepseek # magpie\n config:\n models:\n - id: \"deepseek/pro\"\n"), 0o644); err != nil { t.Fatal(err) } - if err := dshSetEffort(dir, "high", gateway.URL(), false); err != nil { + if err := dshSetEffort(dir, "high", gateway.URL(), ""); err != nil { t.Fatal(err) } b, _ := os.ReadFile(path) diff --git a/internal/agent/handwired_test.go b/internal/agent/handwired_test.go index db63fcda0..753e47ca5 100644 --- a/internal/agent/handwired_test.go +++ b/internal/agent/handwired_test.go @@ -139,7 +139,7 @@ func TestPiConnectedBeforeStaysConnected(t *testing.T) { // a provider magpie didn't put there as the user's, as Pi does. func TestHandWiredMagpieProviderSiblings(t *testing.T) { ids := []string{"agy", "opencode", "openchamber", "mimocode", "deveco", "pi", "aside", "omo", "prime-agent", "goose", "zed", "vscode", - "crush", "dsh", "commandcode", "fx", "omp", "hermes", "morph", "kimi", "empryo", "minimax-code", "droid", + "crush", "dsh", "ds-bot", "commandcode", "fx", "omp", "hermes", "morph", "kimi", "empryo", "minimax-code", "droid", "qoder", "qoder-cn", "grok", "atomcode", "cline", "snow"} for _, id := range ids { t.Run(id, func(t *testing.T) { diff --git a/internal/agent/spelled_test.go b/internal/agent/spelled_test.go index 0357162e0..05aea284b 100644 --- a/internal/agent/spelled_test.go +++ b/internal/agent/spelled_test.go @@ -13,7 +13,7 @@ import ( // own deepseek/deepseek-v4-pro). func TestOwnProviderNamedAsMagpies(t *testing.T) { ids := []string{"agy", "opencode", "openchamber", "mimocode", "deveco", "pi", "aside", "omo", "prime-agent", "goose", "zed", "vscode", - "crush", "dsh", "commandcode", "fx", "omp", "hermes", "morph", "kimi", "empryo", "minimax-code", "droid", + "crush", "dsh", "ds-bot", "commandcode", "fx", "omp", "hermes", "morph", "kimi", "empryo", "minimax-code", "droid", "qoder", "qoder-cn", "grok", "atomcode", "cline", "snow", "qwenpaw"} for _, id := range ids { t.Run(id, func(t *testing.T) { diff --git a/internal/agent/sync_test.go b/internal/agent/sync_test.go index 4155aa1d6..42a4ae995 100644 --- a/internal/agent/sync_test.go +++ b/internal/agent/sync_test.go @@ -38,6 +38,8 @@ func syncHome(t *testing.T) string { t.Setenv("DEVECO_CONFIG_DIR", "") t.Setenv("HANA_HOME", "") t.Setenv("DSH_HOME", "") + t.Setenv("DS_BOT_HOME", "") + t.Setenv("DS_BOT_SHELL_DATA", "") t.Setenv("OMO_CODING_AGENT_DIR", "") t.Setenv("SENPI_CODING_AGENT_DIR", "") t.Setenv("PRIME_AGENT_CODING_AGENT_DIR", "") diff --git a/internal/agent/wsl.go b/internal/agent/wsl.go index c77154c0a..7bcc3f6fd 100644 --- a/internal/agent/wsl.go +++ b/internal/agent/wsl.go @@ -666,7 +666,7 @@ var wslKinds = []wslKind{ } return func(cur map[string]string) []Option { if ref, ok := strings.CutPrefix(cur["model"], magpieID+"/"); ok { - return static(dshLevels(ref)...) + return static(dshLevels("dsh", ref)...) } return static(dshEfforts...) } diff --git a/internal/agentenv/agentenv.go b/internal/agentenv/agentenv.go index 9f17b7309..6aa4b3770 100644 --- a/internal/agentenv/agentenv.go +++ b/internal/agentenv/agentenv.go @@ -84,6 +84,8 @@ var Vars = []string{ // MiMo Code, MiniMax Code, OpenHanako, Hermes, dsh, WorkBuddy, CodeBuddy Code "MIMOCODE_HOME", "MINIMAX_DATA_DIR", "HANA_HOME", "HERMES_HOME", "DSH_HOME", "WORKBUDDY_CONFIG_DIR", "CODEBUDDY_CONFIG_DIR", + // DS Bot's data folder, and its Electron userData holding locations.json + "DS_BOT_HOME", "DS_BOT_SHELL_DATA", // DevEco Code's extra config folder, read after ~/.config/deveco "DEVECO_CONFIG_DIR", // alma-server's data folder (Alma without a desktop, on Linux) diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index a9b736f33..8975b0cd6 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -4474,6 +4474,9 @@ const I18N = { "Type agy in a new terminal: magpie added it to {profiles}, to start agy on magpie's gateway and model (in a terminal open now: {command}).": "在新终端中直接输入 agy 即可:magpie 已把它加入 {profiles},会用 magpie 的网关和模型启动 agy(已打开的终端中请用:{command})。", "dsh reads its config at start-up — restart open dsh sessions to use this.": "dsh 启动时读取配置,需重启已打开的 dsh 会话才会生效。", "dsh's web search goes through magpie, which has nothing to search with yet: set up a provider that searches by itself (DeepSeek, Claude, Codex, …) or a search API under Settings › Web search.": "dsh 的联网搜索经过 magpie,而 magpie 目前还没有可用的搜索方式:请添加一个自带搜索的供应商(DeepSeek、Claude、Codex 等),或在“设置 › 联网搜索”中配置搜索 API。", + "DS Bot hasn't been opened yet: it starts on this the first time it opens.": "DS Bot 还没打开过:第一次打开时就会使用这项设置。", + "New Bots in DS Bot start on this, unless a default model for Bots is set in DS Bot. A Bot made before keeps its own model until you pick another for it.": "DS Bot 里新建的 Bot 会使用这项设置,除非在 DS Bot 中设置了 Bot 的默认模型。之前建好的 Bot 保留自己的模型,直到你为它另选一个。", + "DS Bot's web search goes through magpie, which has nothing to search with yet: set up a provider that searches by itself (DeepSeek, Claude, Codex, …) or a search API under Settings › Web search.": "DS Bot 的联网搜索经过 magpie,而 magpie 目前还没有可用的搜索方式:请添加一个自带搜索的供应商(DeepSeek、Claude、Codex 等),或在“设置 › 联网搜索”中配置搜索 API。", "fx reads its settings at start-up — restart open fx sessions to use this.": "fx 启动时读取设置,需重启已打开的 fx 会话才会生效。", "magpie couldn't ask WSL {distro} its networking mode (it has no wslinfo) and %UserProfile%\\.wslconfig doesn't set it to mirrored, so its {agent} was pointed at Windows ({url}) rather than 127.0.0.1; magpie listens there for WSL, and it answers once Windows' firewall lets WSL in. For 127.0.0.1, set networkingMode=mirrored under [wsl2] in %UserProfile%\\.wslconfig and run wsl --shutdown, then pick the model again.": "magpie 无法获取 WSL {distro} 的网络模式(其中没有 wslinfo),且 %UserProfile%\\.wslconfig 未将其设为 mirrored,因此其中的 {agent} 指向 Windows({url})而不是 127.0.0.1;magpie 会在该地址为 WSL 监听,Windows 防火墙放行 WSL 后即可连通。若要使用 127.0.0.1,请在 %UserProfile%\\.wslconfig 的 [wsl2] 下设置 networkingMode=mirrored 并运行 wsl --shutdown,然后重新选择模型。", "magpie restarted the app-server codex sessions share, which none was on, so new codex sessions have this; restart the Codex app, if it is open, to see it there.": "magpie 已重启 codex 会话共用的 app-server(当时没有会话连着它),新的 codex 会话已生效;如果 Codex 应用开着,需重启它才能看到。", @@ -9123,6 +9126,9 @@ const I18N = { "Type agy in a new terminal: magpie added it to {profiles}, to start agy on magpie's gateway and model (in a terminal open now: {command}).": "在新終端機中直接輸入 agy 即可:magpie 已把它加入 {profiles},會用 magpie 的閘道和模型啟動 agy(已開啟的終端機中請用:{command})。", "dsh reads its config at start-up — restart open dsh sessions to use this.": "dsh 啟動時讀取設定,需重啟已打開的 dsh 會話才會生效。", "dsh's web search goes through magpie, which has nothing to search with yet: set up a provider that searches by itself (DeepSeek, Claude, Codex, …) or a search API under Settings › Web search.": "dsh 的聯網搜尋經過 magpie,而 magpie 目前還沒有可用的搜尋方式:請新增一個自帶搜尋的供應商(DeepSeek、Claude、Codex 等),或在“設定 › 聯網搜尋”中設定搜尋 API。", + "DS Bot hasn't been opened yet: it starts on this the first time it opens.": "DS Bot 還沒開啟過:第一次開啟時就會使用這項設定。", + "New Bots in DS Bot start on this, unless a default model for Bots is set in DS Bot. A Bot made before keeps its own model until you pick another for it.": "DS Bot 裡新建的 Bot 會使用這項設定,除非在 DS Bot 中設定了 Bot 的預設模型。之前建好的 Bot 保留自己的模型,直到你為它另選一個。", + "DS Bot's web search goes through magpie, which has nothing to search with yet: set up a provider that searches by itself (DeepSeek, Claude, Codex, …) or a search API under Settings › Web search.": "DS Bot 的聯網搜尋經過 magpie,而 magpie 目前還沒有可用的搜尋方式:請新增一個自帶搜尋的供應商(DeepSeek、Claude、Codex 等),或在“設定 › 聯網搜尋”中設定搜尋 API。", "fx reads its settings at start-up — restart open fx sessions to use this.": "fx 啟動時讀取設定,需重啟已打開的 fx 會話才會生效。", "magpie couldn't ask WSL {distro} its networking mode (it has no wslinfo) and %UserProfile%\\.wslconfig doesn't set it to mirrored, so its {agent} was pointed at Windows ({url}) rather than 127.0.0.1; magpie listens there for WSL, and it answers once Windows' firewall lets WSL in. For 127.0.0.1, set networkingMode=mirrored under [wsl2] in %UserProfile%\\.wslconfig and run wsl --shutdown, then pick the model again.": "magpie 無法取得 WSL {distro} 的網路模式(其中沒有 wslinfo),且 %UserProfile%\\.wslconfig 未將其設為 mirrored,因此其中的 {agent} 指向 Windows({url})而不是 127.0.0.1;magpie 會在該位址為 WSL 監聽,Windows 防火牆放行 WSL 後即可連通。若要使用 127.0.0.1,請在 %UserProfile%\\.wslconfig 的 [wsl2] 下設定 networkingMode=mirrored 並執行 wsl --shutdown,然後重新選擇模型。", "magpie restarted the app-server codex sessions share, which none was on, so new codex sessions have this; restart the Codex app, if it is open, to see it there.": "magpie 已重啟 codex 會話共用的 app-server(當時沒有會話連著它),新的 codex 會話已生效;如果 Codex 應用開著,需重啟它才能看到。", @@ -13774,6 +13780,9 @@ const I18N = { "Type agy in a new terminal: magpie added it to {profiles}, to start agy on magpie's gateway and model (in a terminal open now: {command}).": "新しいターミナルで agy と入力するだけです:magpie が {profiles} に追加し、magpie のゲートウェイとモデルで agy を起動します(開いているターミナルでは:{command})。", "dsh reads its config at start-up — restart open dsh sessions to use this.": "dsh は起動時に設定を読み込みます。反映するには開いている dsh セッションを再起動してください。", "dsh's web search goes through magpie, which has nothing to search with yet: set up a provider that searches by itself (DeepSeek, Claude, Codex, …) or a search API under Settings › Web search.": "dsh のウェブ検索は magpie を経由しますが、magpie にはまだ検索手段がありません。自前で検索するプロバイダ(DeepSeek、Claude、Codex など)を追加するか、「設定 › ウェブ検索」で検索 API を設定してください。", + "DS Bot hasn't been opened yet: it starts on this the first time it opens.": "DS Bot はまだ一度も開かれていません。初めて開いたときからこの設定で始まります。", + "New Bots in DS Bot start on this, unless a default model for Bots is set in DS Bot. A Bot made before keeps its own model until you pick another for it.": "DS Bot で新しく作る Bot はこの設定で始まります(DS Bot で Bot の既定モデルを設定している場合を除く)。以前に作った Bot は、別のモデルを選ぶまで自分のモデルのままです。", + "DS Bot's web search goes through magpie, which has nothing to search with yet: set up a provider that searches by itself (DeepSeek, Claude, Codex, …) or a search API under Settings › Web search.": "DS Bot のウェブ検索は magpie を経由しますが、magpie にはまだ検索手段がありません。自前で検索するプロバイダ(DeepSeek、Claude、Codex など)を追加するか、「設定 › ウェブ検索」で検索 API を設定してください。", "fx reads its settings at start-up — restart open fx sessions to use this.": "fx は起動時に設定を読み込みます。反映するには開いている fx セッションを再起動してください。", "magpie couldn't ask WSL {distro} its networking mode (it has no wslinfo) and %UserProfile%\\.wslconfig doesn't set it to mirrored, so its {agent} was pointed at Windows ({url}) rather than 127.0.0.1; magpie listens there for WSL, and it answers once Windows' firewall lets WSL in. For 127.0.0.1, set networkingMode=mirrored under [wsl2] in %UserProfile%\\.wslconfig and run wsl --shutdown, then pick the model again.": "magpie は WSL {distro} のネットワークモードを取得できず(wslinfo がありません)、%UserProfile%\\.wslconfig でも mirrored に設定されていないため、{agent} の接続先は 127.0.0.1 ではなく Windows({url})にしました。magpie はそこで WSL 向けに待ち受けており、Windows のファイアウォールが WSL を通せば応答します。127.0.0.1 にするには %UserProfile%\\.wslconfig の [wsl2] に networkingMode=mirrored を設定して wsl --shutdown を実行し、モデルを選び直してください。", "magpie restarted the app-server codex sessions share, which none was on, so new codex sessions have this; restart the Codex app, if it is open, to see it there.": "magpie は codex セッションが共有する app-server を再起動しました(接続中のセッションはありませんでした)。新しい codex セッションには反映されています。Codex アプリが開いている場合は、再起動すると反映されます。", @@ -18425,6 +18434,9 @@ const I18N = { "Type agy in a new terminal: magpie added it to {profiles}, to start agy on magpie's gateway and model (in a terminal open now: {command}).": "Tippe agy in einem neuen Terminal: magpie hat es zu {profiles} hinzugefügt und startet agy mit magpies Gateway und Modell (in einem schon offenen Terminal: {command}).", "dsh reads its config at start-up — restart open dsh sessions to use this.": "dsh liest seine Konfiguration beim Start – offene dsh-Sitzungen neu starten, damit es gilt.", "dsh's web search goes through magpie, which has nothing to search with yet: set up a provider that searches by itself (DeepSeek, Claude, Codex, …) or a search API under Settings › Web search.": "Die Websuche von dsh läuft über magpie, das noch nichts zum Suchen hat: einen Anbieter einrichten, der selbst sucht (DeepSeek, Claude, Codex, …), oder eine Such-API unter Einstellungen › Websuche.", + "DS Bot hasn't been opened yet: it starts on this the first time it opens.": "DS Bot wurde noch nie geöffnet: Beim ersten Öffnen startet es mit dieser Einstellung.", + "New Bots in DS Bot start on this, unless a default model for Bots is set in DS Bot. A Bot made before keeps its own model until you pick another for it.": "Neue Bots in DS Bot starten damit, sofern in DS Bot kein Standardmodell für Bots gesetzt ist. Ein schon angelegter Bot behält sein eigenes Modell, bis du ein anderes für ihn wählst.", + "DS Bot's web search goes through magpie, which has nothing to search with yet: set up a provider that searches by itself (DeepSeek, Claude, Codex, …) or a search API under Settings › Web search.": "Die Websuche von DS Bot läuft über magpie, das noch nichts zum Suchen hat: einen Anbieter einrichten, der selbst sucht (DeepSeek, Claude, Codex, …), oder eine Such-API unter Einstellungen › Websuche.", "fx reads its settings at start-up — restart open fx sessions to use this.": "fx liest seine Einstellungen beim Start – offene fx-Sitzungen neu starten, damit es gilt.", "magpie couldn't ask WSL {distro} its networking mode (it has no wslinfo) and %UserProfile%\\.wslconfig doesn't set it to mirrored, so its {agent} was pointed at Windows ({url}) rather than 127.0.0.1; magpie listens there for WSL, and it answers once Windows' firewall lets WSL in. For 127.0.0.1, set networkingMode=mirrored under [wsl2] in %UserProfile%\\.wslconfig and run wsl --shutdown, then pick the model again.": "magpie konnte WSL {distro} nicht nach seinem Netzwerkmodus fragen (es hat kein wslinfo), und %UserProfile%\\.wslconfig setzt ihn nicht auf mirrored, daher zeigt sein {agent} auf Windows ({url}) statt auf 127.0.0.1; dort lauscht magpie für WSL, und es antwortet, sobald die Windows-Firewall WSL durchlässt. Für 127.0.0.1 networkingMode=mirrored unter [wsl2] in %UserProfile%\\.wslconfig setzen, wsl --shutdown ausführen und das Modell erneut wählen.", "magpie restarted the app-server codex sessions share, which none was on, so new codex sessions have this; restart the Codex app, if it is open, to see it there.": "magpie hat den App-Server, den codex-Sitzungen teilen, neu gestartet (keine war verbunden), neue codex-Sitzungen haben es also; die Codex-App, falls offen, neu starten, um es dort zu sehen.", @@ -18694,6 +18706,9 @@ const NOTICES = [ "an open Claude Code session keeps the ultracode it started with — restart it to use this.", "dsh reads its config at start-up — restart open dsh sessions to use this.", "dsh's web search goes through magpie, which has nothing to search with yet: set up a provider that searches by itself (DeepSeek, Claude, Codex, …) or a search API under Settings › Web search.", + "DS Bot hasn't been opened yet: it starts on this the first time it opens.", + "New Bots in DS Bot start on this, unless a default model for Bots is set in DS Bot. A Bot made before keeps its own model until you pick another for it.", + "DS Bot's web search goes through magpie, which has nothing to search with yet: set up a provider that searches by itself (DeepSeek, Claude, Codex, …) or a search API under Settings › Web search.", "fx reads its settings at start-up — restart open fx sessions to use this.", "magpie couldn't ask WSL {distro} its networking mode (it has no wslinfo) and %UserProfile%\\.wslconfig doesn't set it to mirrored, so its {agent} was pointed at Windows ({url}) rather than 127.0.0.1; magpie listens there for WSL, and it answers once Windows' firewall lets WSL in. For 127.0.0.1, set networkingMode=mirrored under [wsl2] in %UserProfile%\\.wslconfig and run wsl --shutdown, then pick the model again.", "magpie restarted the app-server codex sessions share, which none was on, so new codex sessions have this; restart the Codex app, if it is open, to see it there.",