providers: Claude Code runs as is a pill above the accounts, its hover card saying what TUI and -p each are and are good for
The owner asked for this design, and for it to replace the row535371c8fadded ("这个页面已经有一个重复的解释 claude code 运行方式的了,那个其实 可以用你这个代替掉"). The provider editor's Claude subscription now has one "Claude Code runs as" row, above Accounts. It has: - a pill, green when the interactive mode (TUI) is in use, else "claude -p"; - a line beside it with why -p, or how the last request went ("Last request 3 min ago: interactive mode", "… ran as -p: the request asked for a JSON schema"); - on hover or focus of the pill, a card with both modes, the one in use marked, each with what it is, its advantage and (for -p) its cost, and where it is switched; - when it is off in Settings, Change in Settings, which opens Settings › Models at #claudeTuiRow. Gateway: GET /api/claude/mode gains last {tui, why, at}, the last request's mode. claudeTUI returns the code why a request is -p (the machine's: off, broken, os, wsl-home, missing; or the request's: safeguards, cache, schema, image, big; wslread), and a TUI start that fell back to -p records "start". main's row and its 9 strings per language are gone; the 2 kept ones are reused. openSettingsAt looked a selector up before Settings had drawn from its read, so a row Settings draws anew (#claudeTuiRow) was found stale and the lit row was gone; it now looks it up once show()'s read is in (settingsLoad). Budget: the core is 1,533,105 (147 over), with the comment cut; raised to it with no room added. Run at2e9df9b1b(rebased on origin/main just fetched), on mote: - gofmt -l: clean; go vet darwin, GOOS=windows, GOOS=linux -tags nogui for internal/gateway and internal/gui: ok - go test ./internal/gateway -run Claude: ok (TestClaudeModeLast, TestClaudeTUICodes new) - go test ./internal/gui: TestCoreScriptBudget ok after the raise; red TestSettingsSaveKeepsWhatItDoesNotSend (#4514), TestMainWindowCorners (#3949), TestColdTurnsTaken (#4510), each known on main - GUI: claude-mode.test.cjs 54/54 (Chromium and WebKit; en, zh, zh-TW, ja, de; 900 and 420 wide; Codex and Only switch read nothing), old-webkit ok, i18n-keys red only on "Unmarked" (#4524) Again at0565c0bba(main moved before the push): the budgets and go test ./internal/gateway -run Claude ok; claude-mode, old-webkit and i18n-keys 64/64, i18n-keys green now that #4524 is fixed. v0.1.2443 was first pushed at 3525a6542, this commit before that rebase, while main's push was refused; it was moved here at once. Broken by hand, each red: the pill's mouseenter (hover test, both engines), the settingsLoad lookup (Change in Settings' lit row, both engines), noteClaudeRun("start") (TestClaudeModeLast). Not tried: the real app with a real Claude subscription; the pill and card are drawn from the faked /api/claude/mode.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// The provider editor's row says how the last run went: the interactive
|
||||
// mode, -p with claudeTUI's code, or -p after the helper couldn't start
|
||||
// the interactive mode.
|
||||
func TestClaudeModeLast(t *testing.T) {
|
||||
claudeLast.Lock()
|
||||
before := claudeLast.run
|
||||
claudeLast.Unlock()
|
||||
t.Cleanup(func() { claudeLast.Lock(); claudeLast.run = before; claudeLast.Unlock() })
|
||||
|
||||
noteClaudeRun("schema")
|
||||
if m := ClaudeModeNow(); m.Last == nil || m.Last.TUI || m.Last.Why != "schema" || m.Last.At.IsZero() {
|
||||
t.Fatalf("after a schema run: %+v", m.Last)
|
||||
}
|
||||
noteClaudeRun("")
|
||||
if m := ClaudeModeNow(); m.Last == nil || !m.Last.TUI || m.Last.Why != "" {
|
||||
t.Fatalf("after an interactive run: %+v", m.Last)
|
||||
}
|
||||
// the helper becoming -p after it started is the last run's mode too
|
||||
w := &lockedWriter{run: &subscriptionRun{}}
|
||||
_, _ = w.Write([]byte("claude-tui: Claude Code ended before it showed its prompt (exit status 1): B; this run is -p\n"))
|
||||
if m := ClaudeModeNow(); m.Last == nil || m.Last.TUI || m.Last.Why != "start" {
|
||||
t.Fatalf("after the helper became -p: %+v", m.Last)
|
||||
}
|
||||
}
|
||||
|
||||
// claudeTUI's code names what sent a run to -p, as a word the GUI
|
||||
// translates.
|
||||
func TestClaudeTUICodes(t *testing.T) {
|
||||
was := claudeTUIRuns
|
||||
claudeTUIRuns = true
|
||||
t.Cleanup(func() { claudeTUIRuns = was })
|
||||
req := &Request{Messages: []Message{{Role: "user", Parts: []Part{{Kind: Text, Text: "hi"}}}}, Safeguards: []byte(`{"a":1}`)}
|
||||
if tui, code := claudeTUI(req, claudeCLI{path: "/usr/local/bin/claude"}, []map[string]any{{"type": "text", "text": "hi"}}); tui || code != "safeguards" {
|
||||
t.Fatalf("with safeguards: %v %q", tui, code)
|
||||
}
|
||||
if tui, code := claudeTUI(req, claudeCLI{}, nil); tui || code != "missing" {
|
||||
t.Fatalf("no Claude Code: %v %q", tui, code)
|
||||
}
|
||||
}
|
||||
@@ -860,14 +860,15 @@ func (b *subscriptionBridge) startRun(ctx context.Context, req *Request, model,
|
||||
// Claude Code's interactive mode, where a run allows it (claudeTUI):
|
||||
// the shim (claudetui) is handed the -p arguments, and becomes that -p
|
||||
// run when the interactive one doesn't start
|
||||
tui := claudeTUI(req, binary, prompt)
|
||||
tui, code := claudeTUI(req, binary, prompt)
|
||||
if tui && binary.wsl != nil {
|
||||
// the helper would wait for a transcript it can't see
|
||||
if dir := binary.tuiWSLUnread(configDir); dir != "" {
|
||||
log.Printf("claude: this run is -p: Windows can't read %s, where Claude Code in WSL writes its transcripts", dir)
|
||||
tui = false
|
||||
tui, code = false, "wslread"
|
||||
}
|
||||
}
|
||||
noteClaudeRun(code)
|
||||
var cmd *exec.Cmd
|
||||
if tui {
|
||||
helper := exe
|
||||
@@ -1069,17 +1070,24 @@ const tuiPromptMost = 400 << 10
|
||||
// (ClaudePrintMode), on macOS, Linux and Windows, Claude Code in WSL too (its home
|
||||
// known, so its transcripts are found); not for what only -p takes: safeguards and a client's
|
||||
// cache marks (control requests and an extra body), a JSON schema, and
|
||||
// images. prompt is the run's first message.
|
||||
func claudeTUI(req *Request, binary claudeCLI, prompt []map[string]any) bool {
|
||||
why := claudePrintWhy(req, binary, prompt)
|
||||
// images. prompt is the run's first message. The code is claudePrint's,
|
||||
// for the provider editor's last run (ClaudeMode.Last).
|
||||
func claudeTUI(req *Request, binary claudeCLI, prompt []map[string]any) (bool, string) {
|
||||
code, why := claudePrint(req, binary, prompt)
|
||||
if why != "" && claudeTUIRuns {
|
||||
log.Printf("claude: this run is -p: %s", why)
|
||||
}
|
||||
return why == ""
|
||||
return why == "", code
|
||||
}
|
||||
|
||||
// claudePrintWhy is why a run is -p, "" when it is the interactive mode.
|
||||
func claudePrintWhy(req *Request, binary claudeCLI, prompt []map[string]any) string {
|
||||
_, why := claudePrint(req, binary, prompt)
|
||||
return why
|
||||
}
|
||||
|
||||
// claudePrint is claudePrintWhy with a code the GUI names it by.
|
||||
func claudePrint(req *Request, binary claudeCLI, prompt []map[string]any) (code, why string) {
|
||||
var words []map[string]any
|
||||
for _, bl := range prompt {
|
||||
if bl["type"] != "image" {
|
||||
@@ -1087,24 +1095,24 @@ func claudePrintWhy(req *Request, binary claudeCLI, prompt []map[string]any) str
|
||||
}
|
||||
}
|
||||
b, _ := json.Marshal(words)
|
||||
if _, why := claudeMachineWhy(binary); why != "" {
|
||||
return why
|
||||
if code, why := claudeMachineWhy(binary); why != "" {
|
||||
return code, why
|
||||
}
|
||||
for _, c := range []struct {
|
||||
is bool
|
||||
why string
|
||||
is bool
|
||||
code, why string
|
||||
}{
|
||||
{len(req.Safeguards) > 0, "safeguards"},
|
||||
{req.clientCache != nil, "the client's cache marks"},
|
||||
{len(req.Format.schema()) > 0, "a JSON schema"},
|
||||
{urlImages(req.Messages) > 0, "an image known by its URL"},
|
||||
{len(b) > tuiPromptMost, "a first message over 400KB"},
|
||||
{len(req.Safeguards) > 0, "safeguards", "safeguards"},
|
||||
{req.clientCache != nil, "cache", "the client's cache marks"},
|
||||
{len(req.Format.schema()) > 0, "schema", "a JSON schema"},
|
||||
{urlImages(req.Messages) > 0, "image", "an image known by its URL"},
|
||||
{len(b) > tuiPromptMost, "big", "a first message over 400KB"},
|
||||
} {
|
||||
if c.is {
|
||||
return c.why
|
||||
return c.code, c.why
|
||||
}
|
||||
}
|
||||
return ""
|
||||
return "", ""
|
||||
}
|
||||
|
||||
// claudeMachineWhy is why every run on this machine is -p, whatever it
|
||||
@@ -1139,19 +1147,49 @@ type ClaudeMode struct {
|
||||
Why string `json:"why,omitempty"`
|
||||
Broken time.Time `json:"broken,omitzero"` // since when, for "broken"
|
||||
WSL bool `json:"wsl,omitempty"` // Claude Code in WSL
|
||||
// how the last run since magpie started went (noteClaudeRun)
|
||||
Last *ClaudeLastRun `json:"last,omitempty"`
|
||||
}
|
||||
|
||||
// ClaudeLastRun is how one run went: Why is claudePrint's code when it was
|
||||
// -p, wslread when Windows couldn't read Claude Code in WSL's transcripts,
|
||||
// start when the interactive mode didn't start and the helper became -p.
|
||||
type ClaudeLastRun struct {
|
||||
TUI bool `json:"tui"`
|
||||
Why string `json:"why,omitempty"`
|
||||
At time.Time `json:"at"`
|
||||
}
|
||||
|
||||
// claudeLast is the last run's, since magpie started
|
||||
var claudeLast struct {
|
||||
sync.Mutex
|
||||
run ClaudeLastRun
|
||||
}
|
||||
|
||||
// noteClaudeRun records a run's mode: "" is the interactive mode, else
|
||||
// why it is -p.
|
||||
func noteClaudeRun(why string) {
|
||||
claudeLast.Lock()
|
||||
claudeLast.run = ClaudeLastRun{TUI: why == "", Why: why, At: time.Now()}
|
||||
claudeLast.Unlock()
|
||||
}
|
||||
|
||||
// ClaudeModeNow is ClaudeMode as of now.
|
||||
func ClaudeModeNow() ClaudeMode {
|
||||
binary, err := claudeBinary()
|
||||
if err != nil {
|
||||
return ClaudeMode{Why: "missing"}
|
||||
m := ClaudeMode{Why: "missing"}
|
||||
if binary, err := claudeBinary(); err == nil {
|
||||
code, _ := claudeMachineWhy(binary)
|
||||
m = ClaudeMode{TUI: code == "", Why: code, WSL: binary.wsl != nil}
|
||||
if code == "broken" {
|
||||
m.Broken, _ = claudetui.BrokenSince()
|
||||
}
|
||||
}
|
||||
code, _ := claudeMachineWhy(binary)
|
||||
m := ClaudeMode{TUI: code == "", Why: code, WSL: binary.wsl != nil}
|
||||
if code == "broken" {
|
||||
m.Broken, _ = claudetui.BrokenSince()
|
||||
claudeLast.Lock()
|
||||
if !claudeLast.run.At.IsZero() {
|
||||
r := claudeLast.run
|
||||
m.Last = &r
|
||||
}
|
||||
claudeLast.Unlock()
|
||||
return m
|
||||
}
|
||||
|
||||
@@ -2391,6 +2429,9 @@ func (w *lockedWriter) Write(p []byte) (int, error) {
|
||||
for _, l := range strings.Split(string(p), "\n") {
|
||||
if why, ok := strings.CutPrefix(l, "claude-tui: "); ok {
|
||||
log.Printf("claude: %s", why)
|
||||
if strings.HasSuffix(why, "this run is -p") {
|
||||
noteClaudeRun("start")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func TestClaudeTUIChosen(t *testing.T) {
|
||||
if err := settings.Save(st); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := claudeTUI(c.req, c.binary, c.prompt); got != c.want {
|
||||
if got, _ := claudeTUI(c.req, c.binary, c.prompt); got != c.want {
|
||||
t.Errorf("%s: claudeTUI = %v, want %v", c.name, got, c.want)
|
||||
}
|
||||
if got := claudePrintWhy(c.req, c.binary, c.prompt); on && got != c.why {
|
||||
|
||||
@@ -2640,14 +2640,24 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
|
||||
.editor .accts .keep-login, .editor .accts .switch-only, .editor .accts .pool-ends { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; min-height: 34px; padding: 6px 11px; font-size: 12px; border-top: 1px solid var(--line-2); }
|
||||
.editor .accts .keep-login .keep-as { max-width: 240px; }
|
||||
/* Claude Code's interactive mode or -p, with why (claudeModeRow) */
|
||||
.accts > .claude-mode + .acc { border-top: 1px solid var(--line-2); }
|
||||
.editor .accts .claude-mode { display: grid; gap: 4px; padding: 7px 11px; font-size: 12px; border-top: 1px solid var(--line-2); }
|
||||
.claude-mode .mode-head { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; }
|
||||
.claude-mode .mode-name { font-weight: 500; margin-right: auto; }
|
||||
.claude-mode .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
|
||||
.claude-mode .dot.on { background: var(--green); }
|
||||
.claude-mode .note { color: var(--fg-2); margin: 0; }
|
||||
.claude-mode .link { font-size: 12px; }
|
||||
.claude-mode { display: contents; }
|
||||
.cc-run { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; min-height: 26px; }
|
||||
.cc-pill { display: inline-flex; align-items: center; gap: 7px; height: 26px; padding: 0 10px 0 9px; border-radius: 7px; border: 1px solid var(--line); background: var(--card); font-size: 12px; color: var(--fg); cursor: default; }
|
||||
.cc-pill:hover { border-color: var(--muted); }
|
||||
.cc-pill:focus-visible { border-color: var(--muted); }
|
||||
.cc-pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
|
||||
.cc-pill.tui i { background: var(--green); }
|
||||
.cc-said { font-size: 12px; color: var(--muted); }
|
||||
.cc-tip { position: fixed; z-index: 1000; width: min(400px, calc(100vw - 16px)); padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--card); box-shadow: 0 12px 32px rgba(0, 0, 0, .18); font-size: 12px; line-height: 1.5; color: var(--fg); pointer-events: none; animation: mask-tip .16s var(--ease); }
|
||||
.cc-m + .cc-m { margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--line-2); }
|
||||
.cc-m .h { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
|
||||
.cc-m .now { padding: 0 6px; border-radius: 5px; background: var(--green-soft); color: var(--green); font-size: 11px; line-height: 17px; }
|
||||
.cc-m p { margin: 2px 0 0; color: var(--muted); }
|
||||
.cc-m p.good, .cc-m p.bad { padding-left: 14px; text-indent: -14px; color: var(--fg-2); }
|
||||
.cc-m p.good::before, .cc-m p.bad::before { display: inline-block; width: 14px; text-indent: 0; content: "+"; color: var(--green); font-weight: 600; }
|
||||
.cc-m p.bad::before { content: "−"; color: var(--muted); }
|
||||
.cc-tip .foot { margin-top: 9px; padding-top: 7px; border-top: 1px solid var(--line-2); font-size: 11px; color: var(--faint); }
|
||||
@media (prefers-reduced-motion: reduce) { .cc-tip { animation: none; } }
|
||||
.editor .accts .pool-ends .note { flex-basis: 100%; color: var(--fg-2); }
|
||||
.acc .n { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.acc .plan { color: var(--muted); font-size: 11px; padding: 1px 6px; border-radius: 5px; background: var(--pill); white-space: nowrap; }
|
||||
|
||||
@@ -9321,6 +9321,7 @@ function drawEditor(p, presetID) {
|
||||
const a = p.account;
|
||||
if (subOf(a.agent)) {
|
||||
// no Claude Code on Windows: the gateway runs the one in WSL
|
||||
if (a.agent === "claude" && !p.switchOnly) ed.append(claudeModeRow());
|
||||
const via = a.wsl ? t("Runs through WSL · {distro}: Claude Code there signs in and answers; Windows has none of its own.", { distro: a.wsl }) + " " : "";
|
||||
ed.append(...field(t("Accounts"), renderAccounts(a, p), via + (p.routing ? t("Tick every account to use; Routing says how requests spread over them.") : subOf(a.agent).single ? t("{agent} keeps one account; the gateway runs it for every request. Signing in to another replaces it.", { agent: a.agentName }) : subOf(a.agent).own && (a.logins || []).some((l) => l.own) ? t("The gateway uses the first. Tick more and it moves on to the next when the one before it is out of quota. {agent} itself stays signed in as it is.", { agent: a.agentName && a.agentName !== a.agent ? a.agentName : p.name }) : subOf(a.agent).own || subOf(a.agent).plugin ? t("The gateway uses the first. Tick more and it moves on to the next when the one before it is out of quota.") : t("{agent} signs in to the first. Tick more and magpie moves on to the next when the one before it is out of quota. Sessions already running keep theirs until restarted.", { agent: a.agentName }))));
|
||||
if ((a.logins || []).filter((l) => l.active || l.on).length > 1) ed.append(...renderRouting(p));
|
||||
@@ -13285,8 +13286,6 @@ function renderAccounts(a, p) {
|
||||
cb.onchange = () => accountAction("provider/switchonly", { id: p.id, switchOnly: cb.checked }, cb.checked ? on : off);
|
||||
list.append(el("div", "switch-only", only));
|
||||
}
|
||||
// whether these accounts' runs are Claude Code's interactive mode or -p
|
||||
if (p && a.agent === "claude" && !p.switchOnly) list.append(claudeModeRow());
|
||||
// how a pool ends at its caps (plugins#349)
|
||||
const capped = (l) => accountCapOf(p, l.user) || windowCapsOf(p, l.user);
|
||||
if (p && (ls.some(capped) || p.capStop || p.capCareful)) {
|
||||
@@ -13324,7 +13323,6 @@ function renderAccounts(a, p) {
|
||||
let claudeMode = null, claudeModeAt = 0, claudeModeRead = null;
|
||||
function claudeModeRow() {
|
||||
const box = el("div", "claude-mode");
|
||||
box.hidden = true;
|
||||
const draw = () => window.claudeModeDraw(box, claudeMode);
|
||||
if (claudeMode && Date.now() - claudeModeAt < 30000) draw();
|
||||
else {
|
||||
@@ -23166,6 +23164,7 @@ for (const v of document.querySelectorAll(".view")) {
|
||||
}, { passive: true });
|
||||
}
|
||||
|
||||
let settingsLoad = Promise.resolve(); // show()'s read of Settings, for openSettingsAt
|
||||
async function show(v) {
|
||||
// a built-in page a plugin's page replaces (magpie.page.replaces) opens that
|
||||
v = magpie.replacing?.(v) || v;
|
||||
@@ -23224,7 +23223,7 @@ async function show(v) {
|
||||
// Routing's accounts show their windows as the Usage page read them
|
||||
// (#1833): what is kept, read in an ordinary way, never an asked read
|
||||
if (v === "routing" && (!quotas || Date.now() - quotasAt > 60e3)) loadQuotas();
|
||||
if (v === "settings") loadSettings().then(back, statusErr);
|
||||
if (v === "settings") (settingsLoad = loadSettings()).then(back, statusErr);
|
||||
if (v === "plugins") window.loadPlugins?.()?.then(back);
|
||||
syncTitle();
|
||||
syncURL();
|
||||
@@ -23366,6 +23365,8 @@ async function openSettingsAt(e, tab, row) {
|
||||
if (!await show("settings")) return;
|
||||
if (setQuery) { $("#setQ").value = ""; searchSettings(""); }
|
||||
setSetTab(tab, true);
|
||||
// a selector: the row as drawn from the page's read
|
||||
if (typeof row == "string") row = await settingsLoad.then(() => $(row), () => null);
|
||||
if (!row) return;
|
||||
if (go) { row.scrollIntoView({ block: "center" }); arrived($("#view-settings")); }
|
||||
row.classList.remove("flash");
|
||||
|
||||
@@ -1,28 +1,86 @@
|
||||
// The Claude Code provider editor's row saying whether a Claude
|
||||
// subscription's runs are Claude Code's interactive mode (TUI) or claude
|
||||
// -p, why -p, and what tells them apart. app.js imports this with the
|
||||
// The Claude Code provider editor's "Claude Code runs as" row: whether a
|
||||
// Claude subscription's runs are Claude Code's interactive mode (TUI) or
|
||||
// claude -p, why -p, how the last request went, and on hover what each is
|
||||
// and what it is good for (the owner, 10-31). app.js imports this with the
|
||||
// row's first read of /api/claude/mode (claudeModeRow), so it weighs
|
||||
// nothing on the core.
|
||||
let open = false;
|
||||
window.claudeModeDraw = function draw(box, m) {
|
||||
if (!m) return;
|
||||
box.hidden = false;
|
||||
const why = {
|
||||
off: "The interactive mode is turned off in Settings",
|
||||
broken: "The interactive mode failed to start on this computer lately; magpie tries it again after a while",
|
||||
"wsl-home": "magpie couldn't find the home folder of Claude Code in WSL",
|
||||
missing: "Claude Code isn't installed on this computer",
|
||||
}[m.why] || (m.why ? "This system has no interactive mode for it" : "A request with safeguards, a JSON schema, an image known by its URL or a first message over 400KB still runs as -p");
|
||||
const head = el("div", "mode-head");
|
||||
const more = el("button", "link", t("TUI or -p?"));
|
||||
more.setAttribute("aria-expanded", String(open));
|
||||
more.onclick = () => { open = !open; draw(box, m); };
|
||||
const set = el("button", "link", t("Change in Settings"));
|
||||
set.onclick = (e) => openSettingsAt(e, "models", $("#claudeTuiRow"));
|
||||
head.append(el("span", "dot" + (m.tui ? " on" : "")),
|
||||
el("span", "mode-name", t(m.tui ? "Running as Claude Code's interactive mode (TUI)" : "Running as claude -p (CLI)")), more, set);
|
||||
box.replaceChildren(head, el("div", "note", t(why)), ...(open ? [
|
||||
"TUI: magpie runs Claude Code as a person does, in its interactive screen, and gives it each request there. Anthropic sees Claude Code's own interactive use (entrypoint cli), and the plan counts a request at about half of what -p uses, so the same plan lasts about twice as long.",
|
||||
"-p (CLI): claude -p, Claude Code's mode for scripts (entrypoint sdk-cli). It takes everything a request can carry, but the plan counts each request at about twice the interactive mode's. magpie uses it only when the interactive mode is off, can't run here, or a request needs what only -p takes.",
|
||||
].map((s) => el("p", "note wraps", t(s))) : []));
|
||||
|
||||
// why a run is -p, by the gateway's code (claudeMachineWhy, claudePrint)
|
||||
const CC_WHY = {
|
||||
off: "the interactive mode is off in Settings",
|
||||
broken: "the interactive mode failed to start lately, and is tried again later",
|
||||
os: "this system can't run the interactive mode",
|
||||
"wsl-home": "magpie couldn't find the home folder of Claude Code in WSL",
|
||||
missing: "Claude Code isn't installed on this computer",
|
||||
start: "the interactive mode didn't start",
|
||||
safeguards: "the request carried safeguards",
|
||||
cache: "the client marked its own cache points",
|
||||
schema: "the request asked for a JSON schema",
|
||||
image: "the request had an image by its URL",
|
||||
big: "its first message was over 400KB",
|
||||
wslread: "Windows can't read the transcripts of Claude Code in WSL",
|
||||
};
|
||||
const ccWhy = (code) => t(CC_WHY[code] || CC_WHY.os);
|
||||
|
||||
// ccTip: the two modes side by side, the one in use marked
|
||||
let ccTipEl = null;
|
||||
function ccTip(anchor, tui) {
|
||||
ccTipOff();
|
||||
const tip = ccTipEl = el("div", "cc-tip");
|
||||
tip.setAttribute("role", "tooltip");
|
||||
const mode = (on, name, what, good, bad) => {
|
||||
const m = el("div", "cc-m" + (on ? " on" : ""));
|
||||
const h = el("div", "h");
|
||||
h.append(el("b", "", name));
|
||||
if (on) h.append(el("span", "now", t("In use")));
|
||||
m.append(h, el("p", "", what), el("p", "good", good));
|
||||
if (bad) m.append(el("p", "bad", bad));
|
||||
return m;
|
||||
};
|
||||
tip.append(
|
||||
mode(tui, t("Interactive mode (TUI)"),
|
||||
t("magpie opens Claude Code as a person does, in a terminal of its own that you don't see, types each request in and reads the reply from its transcript."),
|
||||
t("Your plan counts these requests as Claude Code's own use, at about half of the 5-hour allowance that -p uses for the same work.")),
|
||||
mode(!tui, "claude -p",
|
||||
t("Claude Code's print mode, the one scripts and the Agent SDK use: a request in, its reply out."),
|
||||
t("It starts at once, and takes what the interactive mode can't: a JSON schema, an image by its URL, safeguards, a client's own cache points, a first message over 400KB. Such a request runs as -p even with the interactive mode on."),
|
||||
t("The plan counts a -p request at about twice the interactive mode's.")),
|
||||
el("div", "foot", t("Turned on or off in Settings › Models › Replies. When the interactive mode fails to start, requests run as -p for a while and it is tried again later.")));
|
||||
document.body.append(tip);
|
||||
const a = anchor.getBoundingClientRect(), b = tip.getBoundingClientRect();
|
||||
tip.style.left = Math.max(8, Math.min(a.left, innerWidth - b.width - 8)) + "px";
|
||||
tip.style.top = (a.bottom + 8 + b.height < innerHeight - 8 ? a.bottom + 8 : Math.max(8, a.top - b.height - 8)) + "px";
|
||||
}
|
||||
function ccTipOff() {
|
||||
ccTipEl?.remove();
|
||||
ccTipEl = null;
|
||||
}
|
||||
|
||||
// claudeModeDraw fills box, the row app.js put in the editor, from m, a
|
||||
// read of /api/claude/mode
|
||||
window.claudeModeDraw = function (box, m) {
|
||||
if (!m) return;
|
||||
const v = el("div", "cc-run");
|
||||
const pill = el("span", "cc-pill" + (m.tui ? " tui" : ""));
|
||||
pill.tabIndex = 0;
|
||||
pill.append(el("i"), el("span", "", m.tui ? t("Interactive mode (TUI)") : "claude -p"));
|
||||
pill.onmouseenter = pill.onfocus = () => ccTip(pill, m.tui);
|
||||
pill.onmouseleave = pill.onblur = ccTipOff;
|
||||
v.append(pill);
|
||||
const last = m.last;
|
||||
let said = "";
|
||||
if (!m.tui) said = ccWhy(m.why);
|
||||
else if (last && last.tui) said = t("Last request {ago}: interactive mode", { ago: ago(last.at) });
|
||||
else if (last) said = t("Last request {ago} ran as -p: {why}", { ago: ago(last.at), why: ccWhy(last.why) });
|
||||
if (said) v.append(el("span", "cc-said", said));
|
||||
if (m.why === "off") {
|
||||
const b = el("button", "text action", t("Change in Settings"));
|
||||
b.type = "button";
|
||||
b.hidden = gatewayMode; // Settings has no such row then
|
||||
b.onclick = (e) => { ccTipOff(); openSettingsAt(e, "models", "#claudeTuiRow"); };
|
||||
v.append(b);
|
||||
}
|
||||
box.replaceChildren(...field(t("Claude Code runs as"), v, ""));
|
||||
};
|
||||
// the editor going away takes its tip with it
|
||||
addEventListener("pointerdown", ccTipOff, true);
|
||||
|
||||
+80
-36
@@ -4,6 +4,26 @@
|
||||
// works. {name} slots are filled by t(str, vars).
|
||||
const I18N = {
|
||||
zh: {
|
||||
"Claude Code runs as": "Claude Code 运行方式",
|
||||
"Interactive mode (TUI)": "交互模式(TUI)",
|
||||
"Last request {ago}: interactive mode": "上次请求 {ago}:交互模式",
|
||||
"Last request {ago} ran as -p: {why}": "上次请求 {ago} 用了 -p:{why}",
|
||||
"the interactive mode is off in Settings": "设置里关闭了交互模式",
|
||||
"the interactive mode failed to start lately, and is tried again later": "交互模式最近启动失败,稍后会再试",
|
||||
"this system can't run the interactive mode": "这个系统不能运行交互模式",
|
||||
"the interactive mode didn't start": "交互模式没能启动",
|
||||
"the request carried safeguards": "请求带有安全护栏",
|
||||
"the client marked its own cache points": "客户端自己标了缓存点",
|
||||
"the request asked for a JSON schema": "请求要求按 JSON schema 回复",
|
||||
"the request had an image by its URL": "请求里有按 URL 给的图片",
|
||||
"its first message was over 400KB": "第一条消息超过 400KB",
|
||||
"Windows can't read the transcripts of Claude Code in WSL": "Windows 读不到 WSL 里 Claude Code 的会话记录",
|
||||
"magpie opens Claude Code as a person does, in a terminal of its own that you don't see, types each request in and reads the reply from its transcript.": "magpie 像人一样打开 Claude Code:在一个你看不到的终端里输入每个请求,再从它的会话记录里读出回复。",
|
||||
"Your plan counts these requests as Claude Code's own use, at about half of the 5-hour allowance that -p uses for the same work.": "套餐把这些请求算作 Claude Code 自身的使用,同样的工作只消耗 -p 约一半的 5 小时额度。",
|
||||
"Claude Code's print mode, the one scripts and the Agent SDK use: a request in, its reply out.": "Claude Code 的打印模式,脚本和 Agent SDK 用的就是它:一个请求进去,一个回复出来。",
|
||||
"It starts at once, and takes what the interactive mode can't: a JSON schema, an image by its URL, safeguards, a client's own cache points, a first message over 400KB. Such a request runs as -p even with the interactive mode on.": "启动即用,并且支持交互模式做不到的:JSON schema、按 URL 给的图片、安全护栏、客户端自己的缓存点、超过 400KB 的第一条消息。这类请求即使开着交互模式也会用 -p。",
|
||||
"The plan counts a -p request at about twice the interactive mode's.": "套餐对 -p 请求的计量约为交互模式的两倍。",
|
||||
"Turned on or off in Settings › Models › Replies. When the interactive mode fails to start, requests run as -p for a while and it is tried again later.": "在 设置 › 模型 › 回复 里开关。交互模式启动失败时,请求会先用 -p 一段时间,之后再试交互模式。",
|
||||
"MCP router": "MCP 路由",
|
||||
"in {agents}": "用于 {agents}",
|
||||
"Browser access": "浏览器访问",
|
||||
@@ -337,17 +357,8 @@ const I18N = {
|
||||
"Stop looping replies": "停止循环的回复",
|
||||
"Short Claude system prompt": "精简 Claude 系统提示词",
|
||||
"Claude Code's interactive mode": "Claude Code 交互模式",
|
||||
"The interactive mode is turned off in Settings": "交互模式已在设置中关闭",
|
||||
"The interactive mode failed to start on this computer lately; magpie tries it again after a while": "交互模式最近在这台电脑上没能启动,magpie 过一段时间会再试",
|
||||
"magpie couldn't find the home folder of Claude Code in WSL": "magpie 找不到 WSL 里 Claude Code 的主目录",
|
||||
"Claude Code isn't installed on this computer": "这台电脑上没有安装 Claude Code",
|
||||
"This system has no interactive mode for it": "这个系统上不能用交互模式",
|
||||
"Running as Claude Code's interactive mode (TUI)": "当前走 Claude Code 交互模式(TUI)",
|
||||
"Running as claude -p (CLI)": "当前走 claude -p(CLI)",
|
||||
"TUI or -p?": "TUI 和 -p 有什么区别?",
|
||||
"A request with safeguards, a JSON schema, an image known by its URL or a first message over 400KB still runs as -p": "带安全防护、JSON schema、以 URL 给出的图片,或首条消息超过 400KB 的请求,仍然走 -p",
|
||||
"TUI: magpie runs Claude Code as a person does, in its interactive screen, and gives it each request there. Anthropic sees Claude Code's own interactive use (entrypoint cli), and the plan counts a request at about half of what -p uses, so the same plan lasts about twice as long.": "TUI:magpie 像人一样在 Claude Code 的交互界面里运行它,把每个请求交给它。Anthropic 看到的是 Claude Code 自己的交互式使用(entrypoint cli),套餐对一个请求的计量大约只有 -p 的一半,同样的套餐大约能用两倍久。",
|
||||
"-p (CLI): claude -p, Claude Code's mode for scripts (entrypoint sdk-cli). It takes everything a request can carry, but the plan counts each request at about twice the interactive mode's. magpie uses it only when the interactive mode is off, can't run here, or a request needs what only -p takes.": "-p(CLI):claude -p,Claude Code 给脚本用的模式(entrypoint sdk-cli)。它能接收请求可携带的一切,但套餐对每个请求的计量大约是交互模式的两倍。只有交互模式关闭、在这里跑不了,或请求需要只有 -p 才支持的东西时,magpie 才会用它。",
|
||||
"A Claude subscription runs Claude Code as a person does, in its interactive mode, where the plan counts a request at about half of what -p uses. Off runs it as claude -p": "Claude 订阅像人一样以交互模式运行 Claude Code,套餐对每次请求的计量约为 -p 的一半。关闭则以 claude -p 运行",
|
||||
"A Claude subscription answers with the agent's own instructions as its system prompt, in place of Claude Code's, about 1K fewer tokens each request. Still the real Claude Code, but its requests look less like Claude Code's own, which can put the account more at risk": "Claude 订阅以智能体自己的指令作为系统提示词,代替 Claude Code 的,每次请求约少 1K token。仍是真正的 Claude Code,但请求不再那么像 Claude Code 自己发出的,账号风险可能更高",
|
||||
"Ask again after a refusal": "被拒答后再问",
|
||||
@@ -4290,6 +4301,26 @@ const I18N = {
|
||||
"This report is no longer kept: magpie keeps the last 5.": "这份报告已经不在了:magpie 只保留最近 5 份。",
|
||||
},
|
||||
"zh-TW": {
|
||||
"Claude Code runs as": "Claude Code 執行方式",
|
||||
"Interactive mode (TUI)": "互動模式(TUI)",
|
||||
"Last request {ago}: interactive mode": "上次請求 {ago}:互動模式",
|
||||
"Last request {ago} ran as -p: {why}": "上次請求 {ago} 用了 -p:{why}",
|
||||
"the interactive mode is off in Settings": "設定裡關閉了互動模式",
|
||||
"the interactive mode failed to start lately, and is tried again later": "互動模式最近啟動失敗,稍後會再試",
|
||||
"this system can't run the interactive mode": "這個系統無法執行互動模式",
|
||||
"the interactive mode didn't start": "互動模式沒能啟動",
|
||||
"the request carried safeguards": "請求帶有安全護欄",
|
||||
"the client marked its own cache points": "用戶端自己標了快取點",
|
||||
"the request asked for a JSON schema": "請求要求依 JSON schema 回覆",
|
||||
"the request had an image by its URL": "請求裡有以 URL 提供的圖片",
|
||||
"its first message was over 400KB": "第一則訊息超過 400KB",
|
||||
"Windows can't read the transcripts of Claude Code in WSL": "Windows 讀不到 WSL 裡 Claude Code 的對話記錄",
|
||||
"magpie opens Claude Code as a person does, in a terminal of its own that you don't see, types each request in and reads the reply from its transcript.": "magpie 像人一樣開啟 Claude Code:在一個你看不到的終端機裡輸入每個請求,再從它的對話記錄讀出回覆。",
|
||||
"Your plan counts these requests as Claude Code's own use, at about half of the 5-hour allowance that -p uses for the same work.": "方案把這些請求算作 Claude Code 本身的使用,同樣的工作只消耗 -p 約一半的 5 小時額度。",
|
||||
"Claude Code's print mode, the one scripts and the Agent SDK use: a request in, its reply out.": "Claude Code 的列印模式,腳本和 Agent SDK 用的就是它:一個請求進去,一個回覆出來。",
|
||||
"It starts at once, and takes what the interactive mode can't: a JSON schema, an image by its URL, safeguards, a client's own cache points, a first message over 400KB. Such a request runs as -p even with the interactive mode on.": "啟動即用,並且支援互動模式做不到的:JSON schema、以 URL 提供的圖片、安全護欄、用戶端自己的快取點、超過 400KB 的第一則訊息。這類請求即使開著互動模式也會用 -p。",
|
||||
"The plan counts a -p request at about twice the interactive mode's.": "方案對 -p 請求的計量約為互動模式的兩倍。",
|
||||
"Turned on or off in Settings › Models › Replies. When the interactive mode fails to start, requests run as -p for a while and it is tried again later.": "在 設定 › 模型 › 回覆 裡開關。互動模式啟動失敗時,請求會先用 -p 一段時間,之後再試互動模式。",
|
||||
"MCP router": "MCP 路由",
|
||||
"in {agents}": "用於 {agents}",
|
||||
"Browser access": "瀏覽器存取",
|
||||
@@ -4631,17 +4662,8 @@ const I18N = {
|
||||
"Stop looping replies": "停止循環的回覆",
|
||||
"Short Claude system prompt": "精簡 Claude 系統提示詞",
|
||||
"Claude Code's interactive mode": "Claude Code 互動模式",
|
||||
"The interactive mode is turned off in Settings": "互動模式已在設定中關閉",
|
||||
"The interactive mode failed to start on this computer lately; magpie tries it again after a while": "互動模式最近在這台電腦上無法啟動,magpie 過一段時間會再試",
|
||||
"magpie couldn't find the home folder of Claude Code in WSL": "magpie 找不到 WSL 中 Claude Code 的主目錄",
|
||||
"Claude Code isn't installed on this computer": "這台電腦上沒有安裝 Claude Code",
|
||||
"This system has no interactive mode for it": "這個系統上無法使用互動模式",
|
||||
"Running as Claude Code's interactive mode (TUI)": "目前走 Claude Code 互動模式(TUI)",
|
||||
"Running as claude -p (CLI)": "目前走 claude -p(CLI)",
|
||||
"TUI or -p?": "TUI 和 -p 有什麼不同?",
|
||||
"A request with safeguards, a JSON schema, an image known by its URL or a first message over 400KB still runs as -p": "帶安全防護、JSON schema、以 URL 提供的圖片,或首則訊息超過 400KB 的請求,仍然走 -p",
|
||||
"TUI: magpie runs Claude Code as a person does, in its interactive screen, and gives it each request there. Anthropic sees Claude Code's own interactive use (entrypoint cli), and the plan counts a request at about half of what -p uses, so the same plan lasts about twice as long.": "TUI:magpie 像人一樣在 Claude Code 的互動介面裡執行它,把每個請求交給它。Anthropic 看到的是 Claude Code 本身的互動式使用(entrypoint cli),方案對一個請求的計量大約只有 -p 的一半,同樣的方案大約能用兩倍久。",
|
||||
"-p (CLI): claude -p, Claude Code's mode for scripts (entrypoint sdk-cli). It takes everything a request can carry, but the plan counts each request at about twice the interactive mode's. magpie uses it only when the interactive mode is off, can't run here, or a request needs what only -p takes.": "-p(CLI):claude -p,Claude Code 給腳本用的模式(entrypoint sdk-cli)。它能接收請求可攜帶的一切,但方案對每個請求的計量大約是互動模式的兩倍。只有互動模式關閉、在這裡無法執行,或請求需要只有 -p 才支援的東西時,magpie 才會用它。",
|
||||
"A Claude subscription runs Claude Code as a person does, in its interactive mode, where the plan counts a request at about half of what -p uses. Off runs it as claude -p": "Claude 訂閱像人一樣以互動模式執行 Claude Code,方案對每次請求的計量約為 -p 的一半。關閉則以 claude -p 執行",
|
||||
"A Claude subscription answers with the agent's own instructions as its system prompt, in place of Claude Code's, about 1K fewer tokens each request. Still the real Claude Code, but its requests look less like Claude Code's own, which can put the account more at risk": "Claude 訂閱以代理自己的指令作為系統提示詞,取代 Claude Code 的,每次請求約少 1K token。仍是真正的 Claude Code,但請求不再那麼像 Claude Code 自己發出的,帳號風險可能更高",
|
||||
"Ask again after a refusal": "被拒答後再問",
|
||||
@@ -8561,6 +8583,26 @@ const I18N = {
|
||||
"This report is no longer kept: magpie keeps the last 5.": "這份報告已經不在了:magpie 只保留最近 5 份。",
|
||||
},
|
||||
ja: {
|
||||
"Claude Code runs as": "Claude Code の実行方式",
|
||||
"Interactive mode (TUI)": "対話モード(TUI)",
|
||||
"Last request {ago}: interactive mode": "前回のリクエスト({ago}):対話モード",
|
||||
"Last request {ago} ran as -p: {why}": "前回のリクエスト({ago})は -p で実行:{why}",
|
||||
"the interactive mode is off in Settings": "設定で対話モードがオフになっています",
|
||||
"the interactive mode failed to start lately, and is tried again later": "対話モードが最近起動に失敗しました。後でもう一度試します",
|
||||
"this system can't run the interactive mode": "このシステムでは対話モードを実行できません",
|
||||
"the interactive mode didn't start": "対話モードが起動しませんでした",
|
||||
"the request carried safeguards": "リクエストにセーフガードが含まれていました",
|
||||
"the client marked its own cache points": "クライアントが独自のキャッシュ位置を指定しました",
|
||||
"the request asked for a JSON schema": "リクエストが JSON schema での応答を求めました",
|
||||
"the request had an image by its URL": "リクエストに URL で指定された画像がありました",
|
||||
"its first message was over 400KB": "最初のメッセージが 400KB を超えていました",
|
||||
"Windows can't read the transcripts of Claude Code in WSL": "Windows から WSL の Claude Code のトランスクリプトを読めません",
|
||||
"magpie opens Claude Code as a person does, in a terminal of its own that you don't see, types each request in and reads the reply from its transcript.": "magpie は人と同じように Claude Code を開きます。見えない専用のターミナルで各リクエストを入力し、トランスクリプトから応答を読み取ります。",
|
||||
"Your plan counts these requests as Claude Code's own use, at about half of the 5-hour allowance that -p uses for the same work.": "プランはこれらのリクエストを Claude Code 自身の利用として数え、同じ作業で -p の約半分の 5 時間枠しか使いません。",
|
||||
"Claude Code's print mode, the one scripts and the Agent SDK use: a request in, its reply out.": "Claude Code の print モードで、スクリプトや Agent SDK が使うものです。リクエストを渡し、応答を受け取ります。",
|
||||
"It starts at once, and takes what the interactive mode can't: a JSON schema, an image by its URL, safeguards, a client's own cache points, a first message over 400KB. Such a request runs as -p even with the interactive mode on.": "すぐに起動し、対話モードにできないものも扱えます:JSON schema、URL で指定された画像、セーフガード、クライアント独自のキャッシュ位置、400KB を超える最初のメッセージ。こうしたリクエストは対話モードがオンでも -p で実行されます。",
|
||||
"The plan counts a -p request at about twice the interactive mode's.": "プランは -p のリクエストを対話モードの約 2 倍として数えます。",
|
||||
"Turned on or off in Settings › Models › Replies. When the interactive mode fails to start, requests run as -p for a while and it is tried again later.": "設定 › モデル › 応答 でオン・オフできます。対話モードが起動に失敗すると、しばらく -p で実行し、後でもう一度試します。",
|
||||
"MCP router": "MCP ルーター",
|
||||
"in {agents}": "{agents} で使用",
|
||||
"Browser access": "ブラウザからのアクセス",
|
||||
@@ -8894,17 +8936,8 @@ const I18N = {
|
||||
"Stop looping replies": "ループする応答を止める",
|
||||
"Short Claude system prompt": "Claude のシステムプロンプトを短く",
|
||||
"Claude Code's interactive mode": "Claude Code の対話モード",
|
||||
"The interactive mode is turned off in Settings": "対話モードは設定でオフになっています",
|
||||
"The interactive mode failed to start on this computer lately; magpie tries it again after a while": "対話モードは最近このコンピュータで起動できませんでした。magpie はしばらくしてからもう一度試します",
|
||||
"magpie couldn't find the home folder of Claude Code in WSL": "magpie は WSL 内の Claude Code のホームフォルダを見つけられませんでした",
|
||||
"Claude Code isn't installed on this computer": "このコンピュータには Claude Code がインストールされていません",
|
||||
"This system has no interactive mode for it": "このシステムでは対話モードを使えません",
|
||||
"Running as Claude Code's interactive mode (TUI)": "Claude Code の対話モード(TUI)で実行中",
|
||||
"Running as claude -p (CLI)": "claude -p(CLI)で実行中",
|
||||
"TUI or -p?": "TUI と -p の違いは?",
|
||||
"A request with safeguards, a JSON schema, an image known by its URL or a first message over 400KB still runs as -p": "セーフガード、JSON スキーマ、URL で示された画像、または 400KB を超える最初のメッセージを含むリクエストは引き続き -p で実行されます",
|
||||
"TUI: magpie runs Claude Code as a person does, in its interactive screen, and gives it each request there. Anthropic sees Claude Code's own interactive use (entrypoint cli), and the plan counts a request at about half of what -p uses, so the same plan lasts about twice as long.": "TUI:magpie は人と同じように Claude Code を対話画面で動かし、各リクエストをそこで渡します。Anthropic からは Claude Code 本来の対話的な利用(entrypoint cli)に見え、プランは 1 リクエストを -p の約半分として数えるため、同じプランが約 2 倍長く持ちます。",
|
||||
"-p (CLI): claude -p, Claude Code's mode for scripts (entrypoint sdk-cli). It takes everything a request can carry, but the plan counts each request at about twice the interactive mode's. magpie uses it only when the interactive mode is off, can't run here, or a request needs what only -p takes.": "-p(CLI):claude -p、スクリプト向けの Claude Code のモード(entrypoint sdk-cli)。リクエストが運べるものはすべて受け付けますが、プランは各リクエストを対話モードの約 2 倍として数えます。magpie がこれを使うのは、対話モードがオフのとき、ここで動かせないとき、またはリクエストが -p だけが受け付けるものを必要とするときだけです。",
|
||||
"A Claude subscription runs Claude Code as a person does, in its interactive mode, where the plan counts a request at about half of what -p uses. Off runs it as claude -p": "Claude サブスクリプションは人と同じように Claude Code を対話モードで実行し、プランはリクエストを -p の約半分として数えます。オフにすると claude -p で実行します",
|
||||
"A Claude subscription answers with the agent's own instructions as its system prompt, in place of Claude Code's, about 1K fewer tokens each request. Still the real Claude Code, but its requests look less like Claude Code's own, which can put the account more at risk": "Claude サブスクリプションは Claude Code のものの代わりにエージェント自身の指示をシステムプロンプトとして応答し、リクエストごとに約 1K トークン少なくなります。本物の Claude Code のままですが、リクエストが Claude Code 自身のものらしくなくなるため、アカウントのリスクが高まる可能性があります",
|
||||
"Ask again after a refusal": "拒否のあと聞き直す",
|
||||
@@ -12834,6 +12867,26 @@ const I18N = {
|
||||
"This report is no longer kept: magpie keeps the last 5.": "このレポートはもう残っていません。magpie は最新の 5 件だけを保存します。",
|
||||
},
|
||||
de: {
|
||||
"Claude Code runs as": "Claude Code läuft als",
|
||||
"Interactive mode (TUI)": "Interaktiver Modus (TUI)",
|
||||
"Last request {ago}: interactive mode": "Letzte Anfrage {ago}: interaktiver Modus",
|
||||
"Last request {ago} ran as -p: {why}": "Letzte Anfrage {ago} lief als -p: {why}",
|
||||
"the interactive mode is off in Settings": "der interaktive Modus ist in den Einstellungen aus",
|
||||
"the interactive mode failed to start lately, and is tried again later": "der interaktive Modus ist zuletzt nicht gestartet und wird später erneut versucht",
|
||||
"this system can't run the interactive mode": "dieses System kann den interaktiven Modus nicht ausführen",
|
||||
"the interactive mode didn't start": "der interaktive Modus ist nicht gestartet",
|
||||
"the request carried safeguards": "die Anfrage enthielt Safeguards",
|
||||
"the client marked its own cache points": "der Client hat eigene Cache-Punkte gesetzt",
|
||||
"the request asked for a JSON schema": "die Anfrage verlangte ein JSON-Schema",
|
||||
"the request had an image by its URL": "die Anfrage enthielt ein Bild per URL",
|
||||
"its first message was over 400KB": "die erste Nachricht war größer als 400 KB",
|
||||
"Windows can't read the transcripts of Claude Code in WSL": "Windows kann die Transkripte von Claude Code in WSL nicht lesen",
|
||||
"magpie opens Claude Code as a person does, in a terminal of its own that you don't see, types each request in and reads the reply from its transcript.": "magpie öffnet Claude Code wie ein Mensch, in einem eigenen Terminal, das du nicht siehst, tippt jede Anfrage ein und liest die Antwort aus dem Transkript.",
|
||||
"Your plan counts these requests as Claude Code's own use, at about half of the 5-hour allowance that -p uses for the same work.": "Dein Plan zählt diese Anfragen als Claude Codes eigene Nutzung, mit etwa der Hälfte des 5-Stunden-Kontingents, das -p für dieselbe Arbeit braucht.",
|
||||
"Claude Code's print mode, the one scripts and the Agent SDK use: a request in, its reply out.": "Der Print-Modus von Claude Code, den Skripte und das Agent SDK nutzen: eine Anfrage hinein, ihre Antwort heraus.",
|
||||
"It starts at once, and takes what the interactive mode can't: a JSON schema, an image by its URL, safeguards, a client's own cache points, a first message over 400KB. Such a request runs as -p even with the interactive mode on.": "Er startet sofort und kann, was der interaktive Modus nicht kann: ein JSON-Schema, ein Bild per URL, Safeguards, eigene Cache-Punkte des Clients, eine erste Nachricht über 400 KB. Solche Anfragen laufen auch bei eingeschaltetem interaktivem Modus als -p.",
|
||||
"The plan counts a -p request at about twice the interactive mode's.": "Der Plan zählt eine -p-Anfrage etwa doppelt so hoch wie eine im interaktiven Modus.",
|
||||
"Turned on or off in Settings › Models › Replies. When the interactive mode fails to start, requests run as -p for a while and it is tried again later.": "Ein- und ausgeschaltet unter Einstellungen › Modelle › Antworten. Startet der interaktive Modus nicht, laufen Anfragen eine Weile als -p, und er wird später erneut versucht.",
|
||||
"MCP router": "MCP-Router",
|
||||
"in {agents}": "in {agents}",
|
||||
"Browser access": "Browserzugriff",
|
||||
@@ -13167,17 +13220,8 @@ const I18N = {
|
||||
"Stop looping replies": "Schleifende Antworten beenden",
|
||||
"Short Claude system prompt": "Kurzer Claude-Systemprompt",
|
||||
"Claude Code's interactive mode": "Interaktiver Modus von Claude Code",
|
||||
"The interactive mode is turned off in Settings": "Der interaktive Modus ist in den Einstellungen ausgeschaltet",
|
||||
"The interactive mode failed to start on this computer lately; magpie tries it again after a while": "Der interaktive Modus ließ sich auf diesem Computer zuletzt nicht starten; magpie versucht es nach einer Weile erneut",
|
||||
"magpie couldn't find the home folder of Claude Code in WSL": "magpie hat den Home-Ordner von Claude Code in WSL nicht gefunden",
|
||||
"Claude Code isn't installed on this computer": "Claude Code ist auf diesem Computer nicht installiert",
|
||||
"This system has no interactive mode for it": "Auf diesem System gibt es den interaktiven Modus nicht",
|
||||
"Running as Claude Code's interactive mode (TUI)": "Läuft im interaktiven Modus von Claude Code (TUI)",
|
||||
"Running as claude -p (CLI)": "Läuft als claude -p (CLI)",
|
||||
"TUI or -p?": "TUI oder -p?",
|
||||
"A request with safeguards, a JSON schema, an image known by its URL or a first message over 400KB still runs as -p": "Eine Anfrage mit Safeguards, einem JSON-Schema, einem per URL angegebenen Bild oder einer ersten Nachricht über 400 KB läuft weiterhin als -p",
|
||||
"TUI: magpie runs Claude Code as a person does, in its interactive screen, and gives it each request there. Anthropic sees Claude Code's own interactive use (entrypoint cli), and the plan counts a request at about half of what -p uses, so the same plan lasts about twice as long.": "TUI: magpie führt Claude Code wie ein Mensch in seiner interaktiven Oberfläche aus und gibt ihm dort jede Anfrage. Anthropic sieht die eigene interaktive Nutzung von Claude Code (entrypoint cli), und der Plan zählt eine Anfrage mit etwa der Hälfte dessen, was -p verbraucht, sodass derselbe Plan etwa doppelt so lange reicht.",
|
||||
"-p (CLI): claude -p, Claude Code's mode for scripts (entrypoint sdk-cli). It takes everything a request can carry, but the plan counts each request at about twice the interactive mode's. magpie uses it only when the interactive mode is off, can't run here, or a request needs what only -p takes.": "-p (CLI): claude -p, der Modus von Claude Code für Skripte (entrypoint sdk-cli). Er nimmt alles an, was eine Anfrage enthalten kann, aber der Plan zählt jede Anfrage mit etwa dem Doppelten des interaktiven Modus. magpie nutzt ihn nur, wenn der interaktive Modus aus ist, hier nicht laufen kann oder eine Anfrage etwas braucht, das nur -p annimmt.",
|
||||
"A Claude subscription runs Claude Code as a person does, in its interactive mode, where the plan counts a request at about half of what -p uses. Off runs it as claude -p": "Ein Claude-Abo führt Claude Code wie ein Mensch im interaktiven Modus aus, wo der Plan eine Anfrage mit etwa der Hälfte von -p anrechnet. Aus führt es als claude -p aus",
|
||||
"A Claude subscription answers with the agent's own instructions as its system prompt, in place of Claude Code's, about 1K fewer tokens each request. Still the real Claude Code, but its requests look less like Claude Code's own, which can put the account more at risk": "Ein Claude-Abo antwortet mit den eigenen Anweisungen des Agenten als Systemprompt statt mit dem von Claude Code, etwa 1K Token weniger pro Anfrage. Weiterhin das echte Claude Code, aber seine Anfragen sehen Claude Codes eigenen weniger ähnlich, was das Konto stärker gefährden kann",
|
||||
"Ask again after a refusal": "Nach einer Ablehnung erneut fragen",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,12 +1,19 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// The owner: the Claude Code provider page says whether its runs are
|
||||
// Claude Code's interactive mode (TUI) or claude -p (CLI), and what tells
|
||||
// them apart. Under Claude's accounts a row says which, read from
|
||||
// /api/claude/mode once as the page opens, with why when -p; "TUI or -p?"
|
||||
// opens what each is and why the TUI is better, and "Change in Settings"
|
||||
// goes to the setting. Only switch (nothing served) shows no row. In
|
||||
// English, Chinese, Japanese and German, Chromium and WebKit, at 1100 and
|
||||
// 420 wide.
|
||||
// A Claude subscription's editor says whether its requests run Claude
|
||||
// Code's interactive mode (TUI) or claude -p, and hovering it shows what
|
||||
// each is and what each is good for (the owner, 10-31). Here:
|
||||
// - on, its last request interactive: a green pill naming the interactive
|
||||
// mode, and the last request said;
|
||||
// - on, its last request -p for a JSON schema: why that one was -p;
|
||||
// - turned off: the pill says claude -p and why, and Change in Settings
|
||||
// opens Settings › Models at the row that turns it on;
|
||||
// - hovering or focusing the pill shows both modes, the one in use marked,
|
||||
// each with its advantage, inside the window; moving away hides it;
|
||||
// - Claude Code in WSL whose home wasn't found says so;
|
||||
// - another subscription (Codex), and Only switch, which serves nothing,
|
||||
// have no such row, and /api/claude/mode isn't read for them.
|
||||
// The mode is read from /api/claude/mode once as the editor opens.
|
||||
// Chromium and WebKit, 900 and 420 wide, in every language, the API faked.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
@@ -14,133 +21,170 @@ const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
const claude = ({ switchOnly = false } = {}) => ({
|
||||
id: "claude", name: "Claude", icon: "claude-color", chat: "", responses: "", anthropic: "", catalog: "", routing: "", switchOnly,
|
||||
models: [{ id: "claude-sonnet-5", name: "Claude Sonnet 5", on: true }], agents: [], fallback: [], headers: {}, keyList: [],
|
||||
account: {
|
||||
agent: "claude", agentName: "Claude Code", user: "work@example.com", plan: "MAX",
|
||||
logins: [{ user: "work@example.com", plan: "MAX", active: true, on: true }],
|
||||
},
|
||||
});
|
||||
const ago = (min) => new Date(Date.now() - min * 60e3).toISOString();
|
||||
const USER = "me@example.invalid";
|
||||
const claude = (switchOnly) => ({ id: "claude", name: "Claude Code", icon: "claude", models: [{ id: "claude-opus-5-5", on: true }], agents: [], key: {}, switchOnly,
|
||||
account: { agent: "claude", agentName: "Claude Code", agentIcon: "claude", user: USER, logins: [{ user: USER, plan: "max", active: true, on: true }] } });
|
||||
const codex = { id: "codex", name: "Codex", icon: "codex", models: [{ id: "gpt-6", on: true }], agents: [], key: {},
|
||||
account: { agent: "codex", agentName: "Codex", agentIcon: "codex", user: USER, logins: [{ user: USER, plan: "plus", active: true, on: true }] } };
|
||||
|
||||
function serve(lang, first, mode, reads) {
|
||||
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
||||
const providers = () => ({ providers: [first], presets: [], excluded: [], gateway: { running: true, window: true } });
|
||||
const RUNS = {
|
||||
tui: { tui: true, last: { tui: true, at: ago(3) } },
|
||||
schema: { tui: true, last: { tui: false, why: "schema", at: ago(3) } },
|
||||
off: { tui: false, why: "off", last: { tui: false, why: "off", at: ago(3) } },
|
||||
wsl: { tui: false, why: "wsl-home", wsl: true },
|
||||
};
|
||||
|
||||
// each language's words, as the i18n table has them
|
||||
const W = {
|
||||
en: { row: "Claude Code runs as", tui: "Interactive mode (TUI)", inUse: "In use", lastTui: "interactive mode", schema: "the request asked for a JSON schema", off: "the interactive mode is off in Settings", change: "Change in Settings", wsl: "WSL" },
|
||||
zh: { row: "Claude Code 运行方式", tui: "交互模式(TUI)", inUse: "使用中", lastTui: "交互模式", schema: "请求要求按 JSON schema 回复", off: "设置里关闭了交互模式", change: "在设置中修改", wsl: "WSL" },
|
||||
"zh-TW": { row: "Claude Code 執行方式", tui: "互動模式(TUI)", inUse: "使用中", lastTui: "互動模式", schema: "請求要求依 JSON schema 回覆", off: "設定裡關閉了互動模式", change: "在設定中修改", wsl: "WSL" },
|
||||
ja: { row: "Claude Code の実行方式", tui: "対話モード(TUI)", inUse: "使用中", lastTui: "対話モード", schema: "リクエストが JSON schema での応答を求めました", off: "設定で対話モードがオフになっています", change: "設定で変更", wsl: "WSL" },
|
||||
de: { row: "Claude Code läuft als", tui: "Interaktiver Modus (TUI)", inUse: "In Verwendung", lastTui: "interaktiver Modus", schema: "die Anfrage verlangte ein JSON-Schema", off: "der interaktive Modus ist in den Einstellungen aus", change: "In den Einstellungen ändern", wsl: "WSL" },
|
||||
};
|
||||
|
||||
function serve(lang, run, switchOnly, reads) {
|
||||
return async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json(state);
|
||||
if (url.pathname === "/api/providers") return json(providers());
|
||||
if (url.pathname === "/api/claude/mode") { reads.n++; return json(mode); }
|
||||
if (url.pathname === "/api/settings") return json(state.settings);
|
||||
if (url.pathname === "/api/groups") return json({ models: [], groups: [], pools: [] });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light", claudePrintMode: run.why === "off" } });
|
||||
if (url.pathname === "/api/providers") return json({ providers: [claude(switchOnly), codex], presets: [], excluded: [], gateway: { running: true, window: true }, plugins: [] });
|
||||
if (url.pathname === "/api/claude/mode") { reads.n++; return json(run); }
|
||||
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
if (!/^\/[\w./-]*$/.test(url.pathname) || url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" });
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
await route.fulfill({ body: await fs.readFile(file), contentType });
|
||||
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
||||
};
|
||||
}
|
||||
|
||||
const words = {
|
||||
en: { tui: "Running as Claude Code's interactive mode (TUI)", cli: "Running as claude -p (CLI)", off: "turned off in Settings", wsl: "WSL", why: "about half" },
|
||||
zh: { tui: "当前走 Claude Code 交互模式(TUI)", cli: "当前走 claude -p(CLI)", off: "设置中关闭", wsl: "WSL", why: "一半" },
|
||||
ja: { tui: "Claude Code の対話モード(TUI)で実行中", cli: "claude -p(CLI)で実行中", off: "設定でオフ", wsl: "WSL", why: "約半分" },
|
||||
de: { tui: "Läuft im interaktiven Modus von Claude Code (TUI)", cli: "Läuft als claude -p (CLI)", off: "Einstellungen ausgeschaltet", wsl: "WSL", why: "Hälfte" },
|
||||
};
|
||||
const strings = [
|
||||
"The interactive mode is turned off in Settings",
|
||||
"The interactive mode failed to start on this computer lately; magpie tries it again after a while",
|
||||
"magpie couldn't find the home folder of Claude Code in WSL",
|
||||
"Claude Code isn't installed on this computer",
|
||||
"This system has no interactive mode for it",
|
||||
"Running as Claude Code's interactive mode (TUI)",
|
||||
"Running as claude -p (CLI)",
|
||||
"TUI or -p?",
|
||||
"Change in Settings",
|
||||
"A request with safeguards, a JSON schema, an image known by its URL or a first message over 400KB still runs as -p",
|
||||
"TUI: magpie runs Claude Code as a person does, in its interactive screen, and gives it each request there. Anthropic sees Claude Code's own interactive use (entrypoint cli), and the plan counts a request at about half of what -p uses, so the same plan lasts about twice as long.",
|
||||
"-p (CLI): claude -p, Claude Code's mode for scripts (entrypoint sdk-cli). It takes everything a request can carry, but the plan counts each request at about twice the interactive mode's. magpie uses it only when the interactive mode is off, can't run here, or a request needs what only -p takes.",
|
||||
];
|
||||
async function openEditor(browser, lang, run, { id = "claude", width = 900, switchOnly = false } = {}) {
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 760 } })).newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [], reads = { n: 0 };
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, run, switchOnly, reads));
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
// the first draw waits on the page's first reads: a load's room, not a click's (#4470)
|
||||
const row = page.locator(`.row.provider[data-id="${id}"]`);
|
||||
await row.waitFor({ timeout: 60000 });
|
||||
await row.click();
|
||||
await page.locator("#modal .ebody").waitFor();
|
||||
return { page, errors, reads };
|
||||
}
|
||||
|
||||
// the row's label and value, in a slot that lays out as the editor's rows
|
||||
const runRow = (page) => page.locator("#modal .claude-mode", { has: page.locator(".cc-run") });
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const width of [1100, 420]) {
|
||||
for (const lang of Object.keys(words)) {
|
||||
const w = words[lang];
|
||||
const open = async (t, mode, opts = {}) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" })).newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [], reads = { n: 0 };
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, claude(opts), mode, reads));
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
// the first draw waits on the page's first reads: a load's room, not a click's (#4470)
|
||||
const row = page.locator(".row.provider", { hasText: "Claude" }).first();
|
||||
await row.waitFor({ timeout: 60000 });
|
||||
await row.click();
|
||||
await page.locator(".editor .acc").first().waitFor();
|
||||
return { page, errors, reads };
|
||||
};
|
||||
const fits = async (page, sel) => {
|
||||
const box = await page.locator(sel).boundingBox();
|
||||
assert.ok(box.x >= 0 && box.x + box.width <= width, `${sel} fits across ${width}`);
|
||||
};
|
||||
for (const width of [900, 420]) for (const lang of Object.keys(W)) {
|
||||
const w = W[lang];
|
||||
test(`${engine} ${width} ${lang}: the interactive mode in use, its last request said, both modes on hover`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const { page, errors, reads } = await openEditor(browser, lang, RUNS.tui, { width });
|
||||
const row = runRow(page);
|
||||
await row.waitFor();
|
||||
assert.equal((await row.locator(":scope > label").textContent()).trim(), w.row);
|
||||
assert(await row.locator(":scope > label").evaluate((l) => l.compareDocumentPosition(document.querySelector("#modal .accts")) & Node.DOCUMENT_POSITION_FOLLOWING), "the row is above the accounts");
|
||||
const pill = row.locator(".cc-pill");
|
||||
assert.equal(await pill.evaluate((e) => e.classList.contains("tui")), true, "the pill is the interactive mode's");
|
||||
assert.equal((await pill.textContent()).trim(), w.tui);
|
||||
assert.match(await row.locator(".cc-said").textContent(), new RegExp(w.lastTui.replace(/[()]/g, "\\$&") + "$"));
|
||||
assert.equal(await row.locator("button", { hasText: w.change }).count(), 0, "nothing to change while it's on");
|
||||
assert.equal(await page.locator(".cc-tip").count(), 0);
|
||||
await pill.hover();
|
||||
const tip = page.locator(".cc-tip");
|
||||
await tip.waitFor();
|
||||
const modes = await tip.locator(".cc-m").evaluateAll((ms) => ms.map((m) => ({ on: m.classList.contains("on"), name: m.querySelector(".h b").textContent, now: m.querySelector(".now")?.textContent || "", good: m.querySelectorAll("p.good").length, bad: m.querySelectorAll("p.bad").length })));
|
||||
assert.deepEqual(modes, [
|
||||
{ on: true, name: w.tui, now: w.inUse, good: 1, bad: 0 },
|
||||
{ on: false, name: "claude -p", now: "", good: 1, bad: 1 },
|
||||
]);
|
||||
const box = await tip.boundingBox();
|
||||
assert(box.x >= 0 && box.y >= 0 && box.x + box.width <= width && box.y + box.height <= 760, `the card is inside the window: ${JSON.stringify(box)}`);
|
||||
if (lang !== "en") {
|
||||
// every line of the card is in the reader's language
|
||||
const text = await tip.textContent();
|
||||
assert(!/magpie opens Claude Code as a person does|Your plan counts|It starts at once|Turned on or off in Settings/.test(text), `English left in the card: ${text}`);
|
||||
}
|
||||
await page.mouse.move(5, 5);
|
||||
await tip.waitFor({ state: "detached" });
|
||||
// the keyboard reaches it too
|
||||
await pill.focus();
|
||||
await tip.waitFor();
|
||||
assert.equal(reads.n, 1, "the mode is read once, not on each draw");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test(`${engine} ${width} ${lang}: the TUI is said, and what tells it from -p opens`, async (t) => {
|
||||
const { page, errors, reads } = await open(t, { tui: true });
|
||||
const mode = page.locator(".editor .accts .claude-mode");
|
||||
await mode.locator(".mode-name").waitFor();
|
||||
assert.equal((await mode.locator(".mode-name").textContent()).trim(), w.tui);
|
||||
assert.ok(await mode.locator(".dot.on").count(), "the TUI's dot is lit");
|
||||
assert.match(await mode.locator(".note").first().textContent(), /400 ?KB/, "what still runs as -p is said");
|
||||
if (lang === "en") {
|
||||
const missing = await page.evaluate((ks) => ["zh", "zh-TW", "ja", "de"].flatMap((l) => ks.filter((k) => !I18N[l][k]).map((k) => `${l}: ${k}`)), strings);
|
||||
assert.deepEqual(missing, [], "every string has its translations");
|
||||
}
|
||||
await mode.scrollIntoViewIfNeeded();
|
||||
await fits(page, ".editor .accts .claude-mode");
|
||||
const more = mode.locator("button.link").first();
|
||||
assert.equal(await more.getAttribute("aria-expanded"), "false");
|
||||
await more.click();
|
||||
await page.locator(".editor .accts .claude-mode p.note").nth(1).waitFor();
|
||||
const said = await mode.locator("p.note").allTextContents();
|
||||
assert.match(said[0], new RegExp(w.why), "the TUI's saving is said");
|
||||
assert.match(said[0], /entrypoint cli/);
|
||||
assert.match(said[1], /entrypoint sdk-cli/);
|
||||
assert.equal(await mode.locator("button.link").first().getAttribute("aria-expanded"), "true");
|
||||
await fits(page, ".editor .accts .claude-mode");
|
||||
assert.equal(reads.n, 1, "the mode is read once, not on each draw");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
if (width !== 900) continue;
|
||||
test(`${engine} ${lang}: a request that was -p for a JSON schema says so`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const { page, errors } = await openEditor(browser, lang, RUNS.schema);
|
||||
const row = runRow(page);
|
||||
await row.waitFor();
|
||||
assert.equal(await row.locator(".cc-pill.tui").count(), 1, "still the interactive mode");
|
||||
assert((await row.locator(".cc-said").textContent()).endsWith(w.schema), "why the last one was -p");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test(`${engine} ${width} ${lang}: -p says why, and Change in Settings goes to the setting`, async (t) => {
|
||||
const { page, errors } = await open(t, { tui: false, why: "off" });
|
||||
const mode = page.locator(".editor .accts .claude-mode");
|
||||
await mode.locator(".mode-name").waitFor();
|
||||
assert.equal((await mode.locator(".mode-name").textContent()).trim(), w.cli);
|
||||
assert.equal(await mode.locator(".dot.on").count(), 0);
|
||||
assert.match(await mode.locator(".note").first().textContent(), new RegExp(w.off));
|
||||
await mode.locator("button.link").nth(1).click();
|
||||
await page.locator("#claudeTuiRow").waitFor();
|
||||
assert.ok(await page.locator("#setPage-models").isVisible(), "Settings opens on the setting's page");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
test(`${engine} ${lang}: turned off, it says claude -p and why, and goes to the setting`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const { page, errors } = await openEditor(browser, lang, RUNS.off);
|
||||
const row = runRow(page);
|
||||
await row.waitFor();
|
||||
const pill = row.locator(".cc-pill");
|
||||
assert.equal(await pill.evaluate((e) => e.classList.contains("tui")), false);
|
||||
assert.equal((await pill.textContent()).trim(), "claude -p");
|
||||
assert.equal((await row.locator(".cc-said").textContent()).trim(), w.off);
|
||||
await pill.hover();
|
||||
assert.deepEqual(await page.locator(".cc-tip .cc-m").evaluateAll((ms) => ms.map((m) => m.classList.contains("on"))), [false, true], "-p is the one in use");
|
||||
await row.locator("button", { hasText: w.change }).click();
|
||||
await page.locator("#view-settings").waitFor();
|
||||
// the row that turns it on, lit, and still the page's after it lit
|
||||
await page.locator("#view-settings #claudeTuiRow.flash").waitFor();
|
||||
await page.waitForTimeout(300);
|
||||
assert(await page.locator("#claudeTuiRow.flash").isVisible(), "the interactive mode's row is shown, lit");
|
||||
assert.equal(await page.locator(".cc-tip").count(), 0, "the card went with the editor");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test(`${engine} ${width} ${lang}: Claude Code in WSL whose home is unknown says so; Only switch shows no row`, async (t) => {
|
||||
const wsl = await open(t, { tui: false, why: "wsl-home", wsl: true });
|
||||
await wsl.page.locator(".editor .accts .claude-mode .mode-name").waitFor();
|
||||
assert.match(await wsl.page.locator(".editor .accts .claude-mode .note").first().textContent(), new RegExp(w.wsl));
|
||||
const only = await open(t, { tui: true }, { switchOnly: true });
|
||||
await only.page.locator(".editor .accts .switch-only").waitFor();
|
||||
assert.equal(await only.page.locator(".editor .accts .claude-mode").count(), 0);
|
||||
assert.equal(only.reads.n, 0, "nothing is read for a row not shown");
|
||||
assert.deepEqual([...wsl.errors, ...only.errors], []);
|
||||
});
|
||||
}
|
||||
test(`${engine} ${lang}: Claude Code in WSL whose home wasn't found says so`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const { page, errors } = await openEditor(browser, lang, RUNS.wsl);
|
||||
const row = runRow(page);
|
||||
await row.waitFor();
|
||||
assert.match(await row.locator(".cc-said").textContent(), new RegExp(w.wsl));
|
||||
assert.equal(await row.locator("button", { hasText: w.change }).count(), 0);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
|
||||
test(`${engine}: another subscription has no such row`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const { page, errors, reads } = await openEditor(browser, "en", RUNS.tui, { id: "codex" });
|
||||
await page.locator("#modal .acc").first().waitFor();
|
||||
assert.equal(await page.locator("#modal .cc-run, #modal .claude-mode").count(), 0);
|
||||
assert.equal(reads.n, 0, "nothing is read for a row not shown");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test(`${engine}: Only switch, which serves nothing, has no such row`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const { page, errors, reads } = await openEditor(browser, "en", RUNS.tui, { switchOnly: true });
|
||||
await page.locator("#modal .acc").first().waitFor();
|
||||
assert.equal(await page.locator("#modal .cc-run, #modal .claude-mode").count(), 0);
|
||||
assert.equal(reads.n, 0, "nothing is read for a row not shown");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user