agents: Show settings file in an agent row's menu (InkCoalW on X)

InkCoalW asked on X for agent config files (settings.json, config.yaml
and the like) to be managed as CC Switch does it. magpie already sets
what is managed in those files: providers, models, effort, MCP servers,
skills, hooks and the agent's own options. So the rest of the file gets
an entry point, not an editor. An agent row's menu has "Show settings
file", which shows the file magpie writes (agent.Path) in the file
manager. A file not written yet shows its folder. An in-app raw editor
would race magpie's own writes and the agent's live sessions, so there is
none.

POST /api/agents/reveal takes only the agent's id and looks the path up
in agent.Detected(). A path or an unknown id shows nothing. The page
served to a browser (magpie web) is refused, and the item isn't drawn
there or in the tray panel.

app.js and the core scripts' budgets are raised by 182: one item, packed
to the shortest form. openAgentMenu draws every agent's menu, so there is
no page to move it to. The route is named in the CLI parity list as the
window's own.

Run, on mote via mote-run, at this head rebased on eb1da1572:
- go test -tags nogui -run 'TestAgentReveal|TestAgentOpen|TestCoreScriptBudget|TestEveryRouteIsNamedForTheCLI' ./internal/gui: ok
- the internal/gui package in full: the only reds are TestBuiltinsTranslated
  (#7257) and TestSettingsSaveKeepsWhatItDoesNotSend (#7240), which fail
  the same on a fresh origin/main eb1da1572 copy.
- go vet with GOOS=darwin, linux and windows on ./internal/gui: ok.
  gofmt: empty.
- agent-open-terminal.test.cjs: 24/24 in Chromium and WebKit, in five
  languages, at 980 and 420 wide. On the old app.js it is 20 of 24 red.
- i18n-keys: ok.

Broken by hand:
- the route at the old sessions.go: TestAgentRevealShowsOnlyItsFile red
- the isWeb check removed: red ("the browser's page showed a file: 204")

Not tried: a real Finder, Explorer or Linux file-manager reveal, and
Windows or Linux runs.
This commit is contained in:
yetone
2026-11-20 15:53:23 +08:00
parent aebc65c18e
commit 6635dec7cd
7 changed files with 134 additions and 10 deletions
+1
View File
@@ -517,6 +517,7 @@ var notYet = map[string]string{
"GET /api/sessions/progress": U, // sessions.go
"GET /api/sessions/stats": U, // sessions.go
"POST /api/agents/open": W, // sessions.go
"POST /api/agents/reveal": W, // sessions.go
"POST /api/sessions/carry": U, // sessions.go
"POST /api/sessions/export": U, // sessions.go
"POST /api/sessions/terminal": W, // sessions.go
+67
View File
@@ -191,3 +191,70 @@ func TestCodexOpenButton(t *testing.T) {
t.Fatalf("Open in terminal opened the app: %v", apps)
}
}
// revealHost is the app's windows, keeping what they were asked to show.
type revealHost struct {
folderOnly
shown *[]string
}
func (h revealHost) RevealFolder(p string) error { *h.shown = append(*h.shown, p); return nil }
func (h revealHost) OpenFolder(p string) error { *h.shown = append(*h.shown, p); return nil }
// Show settings file on an Agents row (InkCoalW on X): the file shown is
// the agent's own, as detected. The page sends only the id; an id that
// isn't an agent's, or a path, shows nothing, and the page served to a
// browser shows nothing on the computer it runs on.
func TestAgentRevealShowsOnlyItsFile(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("claude here is a POSIX shell's program")
}
h := sandboxHome(t)
dir := t.TempDir()
prog := filepath.Join(dir, "claude")
if err := os.WriteFile(prog, []byte("#!/bin/sh\n"), 0o755); err != nil {
t.Fatal(err)
}
t.Setenv("PATH", dir)
proc.Forget()
t.Cleanup(proc.Forget)
a, err := agent.Find("claude")
if err != nil {
t.Fatal(err)
}
if a.Path == "" || !strings.HasPrefix(a.Path, h) {
t.Fatalf("claude's file is %q, not in the sandbox %q", a.Path, h)
}
if err := os.MkdirAll(filepath.Dir(a.Path), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(a.Path, []byte("{}"), 0o644); err != nil {
t.Fatal(err)
}
var shown []string
post := func(w Windows, id string) int {
t.Helper()
b, _ := json.Marshal(map[string]string{"agent": id})
rec := httptest.NewRecorder()
Handler(w, nil).ServeHTTP(rec, httptest.NewRequest("POST", "/api/agents/reveal", strings.NewReader(string(b))))
return rec.Code
}
for _, id := range []string{"nope", a.Path, "../claude", ""} {
if code := post(revealHost{shown: &shown}, id); code == http.StatusNoContent || len(shown) != 0 {
t.Fatalf("%q: %d, shown %q", id, code, shown)
}
}
if code := post(webTab{}, "claude"); code == http.StatusNoContent {
t.Fatalf("the browser's page showed a file: %d", code)
}
if code := post(revealHost{shown: &shown}, "claude"); code != http.StatusNoContent || len(shown) != 1 || shown[0] != a.Path {
t.Fatalf("claude: %d, shown %q, want %q", code, shown, a.Path)
}
// not written yet: its folder
os.Remove(a.Path)
shown = nil
if code := post(revealHost{shown: &shown}, "claude"); code != http.StatusNoContent || len(shown) != 1 || shown[0] != filepath.Dir(a.Path) {
t.Fatalf("claude with no file: %d, shown %q", code, shown)
}
}
+3 -1
View File
@@ -3902,7 +3902,9 @@ function openAgentMenu(anchor, a, inFold, at) {
// coolmantou, lileo0668
// Codex's desktop app, by the setting Open Codex with (Yink88564391 on
// X): in the menu, not on the row, so the row lines up with the others
const app = a.openApp && mode != "panel" && !web, o = a.terminal && mode != "panel" && !web, term = [...app ? [{ name: "Open the Codex app", icon: LAUNCH_GLYPH, sep: !0, run: () => api("agents/open", { agent: a.id }).catch(statusErr) }] : [], ...o ? [{ name: "Open in terminal", icon: LAUNCH_GLYPH, sep: !app, run: () => api("agents/open", { agent: a.id, terminal: !0 }).catch(statusErr) }] : [], ...a.command ? [{ name: "Copy launch command", icon: COPY_ICON, sep: !o && !app, run: () => copy(a.command, t("Launch command")) }] : []];
const app = a.openApp && mode != "panel" && !web, o = a.terminal && mode != "panel" && !web, term = [...app ? [{ name: "Open the Codex app", icon: LAUNCH_GLYPH, sep: !0, run: () => api("agents/open", { agent: a.id }).catch(statusErr) }] : [], ...o ? [{ name: "Open in terminal", icon: LAUNCH_GLYPH, sep: !app, run: () => api("agents/open", { agent: a.id, terminal: !0 }).catch(statusErr) }] : [], ...a.command ? [{ name: "Copy launch command", icon: COPY_ICON, sep: !o && !app, run: () => copy(a.command, t("Launch command")) }] : [],
// its whole file at hand, as CC Switch has it (InkCoalW on X)
...a.path && mode != "panel" && !web ? [{ name: "Show settings file", icon: "M4.5 2.5h5l2.5 2.5v8.5h-7.5zM9.5 2.5V5H12", run: () => api("agents/reveal", { agent: a.id }).catch(statusErr) }] : []];
const acts = inFold && isHidden(a)
? [{ name: "Show", icon: EYE, run: () => setAgentHidden(a, false) }]
: inFold
+4
View File
@@ -3949,6 +3949,7 @@ const I18N = {
"Type {command} in a new terminal to start {name} on magpie · click to copy the command for a terminal open now:": "在新终端输入 {command} 即可让 {name} 走 magpie · 点击复制在已打开终端中用的命令:",
"Launch command": "启动命令",
"Copy launch command": "复制启动命令",
"Show settings file": "在文件夹中显示设置文件",
"Open in terminal": "在终端中打开",
"Copied — run it to start {name} on magpie": "已复制,运行它即可让 {name} 走 magpie",
// the Sessions page (sessions.js)
@@ -9451,6 +9452,7 @@ const I18N = {
"Type {command} in a new terminal to start {name} on magpie · click to copy the command for a terminal open now:": "在新終端機輸入 {command} 即可讓 {name} 走 magpie · 點選複製在已開啟終端機中用的命令:",
"Launch command": "啟動命令",
"Copy launch command": "複製啟動命令",
"Show settings file": "在資料夾中顯示設定檔",
"Open in terminal": "在終端機中開啟",
"Copied — run it to start {name} on magpie": "已複製,執行它即可讓 {name} 走 magpie",
"Filter sessions": "篩選會話",
@@ -14954,6 +14956,7 @@ const I18N = {
"Type {command} in a new terminal to start {name} on magpie · click to copy the command for a terminal open now:": "新しいターミナルで {command} と入力すると {name} が magpie 経由で起動します · クリックで開いているターミナル用のコマンドをコピー:",
"Launch command": "起動コマンド",
"Copy launch command": "起動コマンドをコピー",
"Show settings file": "設定ファイルをフォルダで表示",
"Open in terminal": "ターミナルで開く",
"Copied — run it to start {name} on magpie": "コピーしました。実行すると {name} が magpie 経由で起動します",
"Filter sessions": "セッションを絞り込む",
@@ -20478,6 +20481,7 @@ const I18N = {
"Type {command} in a new terminal to start {name} on magpie · click to copy the command for a terminal open now:": "In einem neuen Terminal startet {command} {name} über magpie · klicken, um den Befehl für ein schon offenes Terminal zu kopieren:",
"Launch command": "Startbefehl",
"Copy launch command": "Startbefehl kopieren",
"Show settings file": "Einstellungsdatei im Ordner zeigen",
"Open in terminal": "Im Terminal öffnen",
"Copied — run it to start {name} on magpie": "Kopiert — ausführen, um {name} über magpie zu starten",
"Filter sessions": "Sitzungen filtern",
File diff suppressed because one or more lines are too long
+37
View File
@@ -10,6 +10,7 @@ import (
"math"
"net/http"
"os"
"path/filepath"
"reflect"
"runtime"
"runtime/debug"
@@ -463,6 +464,42 @@ func sessionRoutes(mux *http.ServeMux, w Windows) {
}
rw.WriteHeader(http.StatusNoContent)
})
// agents/reveal shows an agent's settings file, the one magpie writes,
// in the file manager, from its row's menu (InkCoalW on X: its whole
// file at hand, as CC Switch has it). The page sends only the agent's
// id; the path is the agent's as detected, never one the page names.
mux.HandleFunc("POST /api/agents/reveal", func(rw http.ResponseWriter, r *http.Request) {
var in struct{ Agent string }
if err := json.NewDecoder(r.Body).Decode(&in); err != nil {
fail(rw, err)
return
}
if isWeb(w) {
fail(rw, errors.New("showing a file is only for the desktop app"))
return
}
path := ""
for _, a := range agent.Detected() {
if a.ID == in.Agent {
path = a.Path
}
}
if path == "" {
fail(rw, errors.New("no settings file for this agent"))
return
}
var err error
if _, e := os.Stat(path); e == nil {
err = revealIn(w, path)
} else {
err = w.OpenFolder(filepath.Dir(path))
}
if err != nil {
fail(rw, err)
return
}
rw.WriteHeader(http.StatusNoContent)
})
// carry converts a session for another agent (one its Carry offers with
// Convert): a new session of that agent's, in its own folder, the
// source only read. It runs only when the user picks the agent, never
@@ -8,7 +8,9 @@
// API is faked here. lileo0668 on Discord: every agent with a program has
// "Copy launch command" there too, the line the server made, on every
// system, the web build and the panel included; a desktop app has none.
// Narrow too.
// Narrow too. InkCoalW on X: "Show settings file" posts agents/reveal with
// the id alone (the server finds the file), on the window, not in the web
// build or the panel.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
@@ -33,6 +35,7 @@ function server(lang, web, posts) {
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:${web}};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json({ ...state, settings: { lang, theme: "light" } });
if (url.pathname === "/api/agents/reveal") { posts.push([url.pathname, req.postData()]); return route.fulfill({ status: 204, body: "" }); }
if (url.pathname === "/api/agents/open") { posts.push([url.pathname, req.postData()]); return route.fulfill({ status: 204, body: "" }); }
if (url.pathname === "/api/copy") { posts.push([url.pathname, req.postData()]); return route.fulfill({ status: 204, body: "" }); }
if (url.pathname === "/api/usage/quotas") return json([]);
@@ -48,11 +51,11 @@ function server(lang, web, posts) {
}
const words = {
en: { item: "Open in terminal", copy: "Copy launch command" },
zh: { item: "在终端中打开", copy: "复制启动命令" },
"zh-TW": { item: "在終端機中開啟", copy: "複製啟動命令" },
ja: { item: "ターミナルで開く", copy: "起動コマンドをコピー" },
de: { item: "Im Terminal öffnen", copy: "Startbefehl kopieren" },
en: { item: "Open in terminal", copy: "Copy launch command", show: "Show settings file" },
zh: { item: "在终端中打开", copy: "复制启动命令", show: "在文件夹中显示设置文件" },
"zh-TW": { item: "在終端機中開啟", copy: "複製啟動命令", show: "在資料夾中顯示設定檔" },
ja: { item: "ターミナルで開く", copy: "起動コマンドをコピー", show: "設定ファイルをフォルダで表示" },
de: { item: "Im Terminal öffnen", copy: "Startbefehl kopieren", show: "Einstellungsdatei im Ordner zeigen" },
};
const row = (id) => `.row.agent[data-id="${id}"]`;
@@ -107,7 +110,15 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await item().click();
await sent;
await page.locator(".pop.row-menu").waitFor({ state: "detached" });
assert.deepEqual(posts.map(([p, b]) => [p, JSON.parse(b)]), [["/api/agents/open", { agent: "codex", terminal: true }]], "the id, and the terminal asked for");
assert.deepEqual(posts.splice(0).map(([p, b]) => [p, JSON.parse(b)]), [["/api/agents/open", { agent: "codex", terminal: true }]], "the id, and the terminal asked for");
await menu("codex");
const show = page.locator(".pop.row-menu .rm-item", { hasText: w.show });
assert.equal(await show.count(), 1, "its settings file can be shown");
const shown = page.waitForResponse((r) => new URL(r.url()).pathname === "/api/agents/reveal");
await show.click();
await shown;
assert.deepEqual(posts.map(([p, b]) => [p, JSON.parse(b)]), [["/api/agents/reveal", { agent: "codex" }]], "the id alone");
assert.deepEqual(errors, []);
});
}
@@ -119,6 +130,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.locator(".pop.row-menu").waitFor();
assert.equal(await page.locator(".pop.row-menu .rm-item", { hasText: "Open in terminal" }).count(), 0);
assert.equal(await page.locator(".pop.row-menu .rm-item", { hasText: "Copy launch command" }).count(), 1, "copying is for the web too");
assert.equal(await page.locator(".pop.row-menu .rm-item", { hasText: "Show settings file" }).count(), 0, "a file on the server's computer isn't shown");
assert.deepEqual(errors, []);
});
@@ -129,6 +141,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.locator(".pop.row-menu").waitFor();
assert.equal(await page.locator(".rm-item", { hasText: "Open in terminal" }).count(), 0);
assert.equal(await page.locator(".rm-item", { hasText: "Copy launch command" }).count(), 1, "copying is for the panel too");
assert.equal(await page.locator(".rm-item", { hasText: "Show settings file" }).count(), 0);
assert.deepEqual(posts, []);
assert.deepEqual(errors, []);
});