@dirgha/code 1.20.25 → 1.20.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/keypool.js +40 -26
- package/dist/auth/keypool.js.map +1 -1
- package/dist/auth/keystore.js +16 -11
- package/dist/auth/keystore.js.map +1 -1
- package/dist/cli/config.js +23 -2
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/first-run.js +40 -24
- package/dist/cli/first-run.js.map +1 -1
- package/dist/cli/flows/wizard.js +12 -18
- package/dist/cli/flows/wizard.js.map +1 -1
- package/dist/cli/interactive.d.ts +4 -0
- package/dist/cli/interactive.js +29 -1
- package/dist/cli/interactive.js.map +1 -1
- package/dist/cli/main.js +59 -17
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/slash/fleet.js +19 -1
- package/dist/cli/slash/fleet.js.map +1 -1
- package/dist/cli/slash/models.js +4 -2
- package/dist/cli/slash/models.js.map +1 -1
- package/dist/cli/slash.js +26 -10
- package/dist/cli/slash.js.map +1 -1
- package/dist/cli/subcommands/telemetry.d.ts +2 -1
- package/dist/cli/subcommands/telemetry.js +47 -34
- package/dist/cli/subcommands/telemetry.js.map +1 -1
- package/dist/context/branch.d.ts +2 -2
- package/dist/context/branch.js +40 -23
- package/dist/context/branch.js.map +1 -1
- package/dist/context/compaction.js +38 -18
- package/dist/context/compaction.js.map +1 -1
- package/dist/context/git-state.js +31 -18
- package/dist/context/git-state.js.map +1 -1
- package/dist/context/knowledge.js +31 -20
- package/dist/context/knowledge.js.map +1 -1
- package/dist/context/memory.js +7 -0
- package/dist/context/memory.js.map +1 -1
- package/dist/context/mode-enforcement.js +11 -2
- package/dist/context/mode-enforcement.js.map +1 -1
- package/dist/context/mode.js +67 -30
- package/dist/context/mode.js.map +1 -1
- package/dist/context/primer.js +15 -3
- package/dist/context/primer.js.map +1 -1
- package/dist/fleet/apply-back.js +5 -1
- package/dist/fleet/apply-back.js.map +1 -1
- package/dist/fleet/cli-command.d.ts +2 -0
- package/dist/fleet/cli-command.js +15 -1
- package/dist/fleet/cli-command.js.map +1 -1
- package/dist/fleet/runner.js +35 -2
- package/dist/fleet/runner.js.map +1 -1
- package/dist/fleet/scratchpad.js +1 -2
- package/dist/fleet/scratchpad.js.map +1 -1
- package/dist/fleet/state.d.ts +4 -0
- package/dist/fleet/state.js +11 -2
- package/dist/fleet/state.js.map +1 -1
- package/dist/fleet/templates.d.ts +4 -0
- package/dist/fleet/templates.js.map +1 -1
- package/dist/fleet/types.d.ts +4 -0
- package/dist/fleet/types.js.map +1 -1
- package/dist/intelligence/prices.d.ts +6 -4
- package/dist/intelligence/prices.js +36 -10
- package/dist/intelligence/prices.js.map +1 -1
- package/dist/kernel/agent-loop.js +49 -15
- package/dist/kernel/agent-loop.js.map +1 -1
- package/dist/lsp/client.js +29 -16
- package/dist/lsp/client.js.map +1 -1
- package/dist/lsp/detector.js +7 -6
- package/dist/lsp/detector.js.map +1 -1
- package/dist/mcp/client.d.ts +1 -1
- package/dist/mcp/client.js +19 -16
- package/dist/mcp/client.js.map +1 -1
- package/dist/mcp/transport.js +46 -38
- package/dist/mcp/transport.js.map +1 -1
- package/dist/providers/dispatch.js +15 -1
- package/dist/providers/dispatch.js.map +1 -1
- package/dist/providers/index.d.ts +11 -0
- package/dist/providers/index.js +29 -2
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/openai-compat.js +4 -2
- package/dist/providers/openai-compat.js.map +1 -1
- package/dist/safety/audit-log.d.ts +15 -0
- package/dist/safety/audit-log.js +21 -0
- package/dist/safety/audit-log.js.map +1 -1
- package/dist/telemetry/gateway-push.d.ts +17 -0
- package/dist/telemetry/gateway-push.js +48 -0
- package/dist/telemetry/gateway-push.js.map +1 -0
- package/dist/telemetry/index.d.ts +9 -0
- package/dist/telemetry/index.js +9 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/tools/browser.js +24 -16
- package/dist/tools/browser.js.map +1 -1
- package/dist/tools/checkpoint.d.ts +6 -1
- package/dist/tools/checkpoint.js +79 -62
- package/dist/tools/checkpoint.js.map +1 -1
- package/dist/tools/cron.js +1 -3
- package/dist/tools/cron.js.map +1 -1
- package/dist/tools/diff.js +25 -21
- package/dist/tools/diff.js.map +1 -1
- package/dist/tools/exec.d.ts +2 -0
- package/dist/tools/exec.js +13 -0
- package/dist/tools/exec.js.map +1 -1
- package/dist/tools/fs-edit.d.ts +3 -5
- package/dist/tools/fs-edit.js +8 -23
- package/dist/tools/fs-edit.js.map +1 -1
- package/dist/tools/fs-ls.js +6 -8
- package/dist/tools/fs-ls.js.map +1 -1
- package/dist/tools/fs-read.d.ts +1 -1
- package/dist/tools/fs-read.js +37 -28
- package/dist/tools/fs-read.js.map +1 -1
- package/dist/tools/fs-write.d.ts +1 -1
- package/dist/tools/fs-write.js +33 -33
- package/dist/tools/fs-write.js.map +1 -1
- package/dist/tools/git.js +12 -6
- package/dist/tools/git.js.map +1 -1
- package/dist/tools/index.d.ts +3 -1
- package/dist/tools/index.js +4 -3
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/multimodal.js +11 -12
- package/dist/tools/multimodal.js.map +1 -1
- package/dist/tools/rtk.js +22 -9
- package/dist/tools/rtk.js.map +1 -1
- package/dist/tools/search-glob.d.ts +1 -1
- package/dist/tools/search-glob.js +42 -24
- package/dist/tools/search-glob.js.map +1 -1
- package/dist/tools/search-grep.d.ts +1 -1
- package/dist/tools/search-grep.js +56 -32
- package/dist/tools/search-grep.js.map +1 -1
- package/dist/tools/shell.d.ts +1 -1
- package/dist/tools/shell.js +78 -54
- package/dist/tools/shell.js.map +1 -1
- package/dist/tui/ink/App.js +90 -42
- package/dist/tui/ink/App.js.map +1 -1
- package/dist/tui/ink/components/DenseToolMessage.js +5 -1
- package/dist/tui/ink/components/DenseToolMessage.js.map +1 -1
- package/dist/tui/ink/components/InputBox.js +16 -15
- package/dist/tui/ink/components/InputBox.js.map +1 -1
- package/dist/tui/ink/components/ModelPicker.d.ts +2 -2
- package/dist/tui/ink/components/ModelPicker.js +34 -26
- package/dist/tui/ink/components/ModelPicker.js.map +1 -1
- package/dist/tui/ink/components/SpinnerGlyph.d.ts +4 -4
- package/dist/tui/ink/components/SpinnerGlyph.js +34 -14
- package/dist/tui/ink/components/SpinnerGlyph.js.map +1 -1
- package/dist/tui/ink/components/StatusBar.js +0 -2
- package/dist/tui/ink/components/StatusBar.js.map +1 -1
- package/dist/tui/ink/components/ToolBox.js +1 -3
- package/dist/tui/ink/components/ToolBox.js.map +1 -1
- package/dist/tui/ink/components/VirtualTranscript.js +3 -1
- package/dist/tui/ink/components/VirtualTranscript.js.map +1 -1
- package/dist/tui/ink/use-declined-versions.js +6 -2
- package/dist/tui/ink/use-declined-versions.js.map +1 -1
- package/dist/tui/ink/use-event-projection.js +12 -0
- package/dist/tui/ink/use-event-projection.js.map +1 -1
- package/dist/tui/ink/use-overlays.js +16 -17
- package/dist/tui/ink/use-overlays.js.map +1 -1
- package/dist/tui/ink/use-render-metrics.js +6 -2
- package/dist/tui/ink/use-render-metrics.js.map +1 -1
- package/dist/utils/env.d.ts +1 -0
- package/dist/utils/env.js +60 -0
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/fs.d.ts +10 -0
- package/dist/utils/fs.js +37 -0
- package/dist/utils/fs.js.map +1 -0
- package/package.json +1 -1
package/dist/tools/shell.js
CHANGED
|
@@ -7,45 +7,54 @@
|
|
|
7
7
|
* the model does not misread a capped stream as a complete one.
|
|
8
8
|
*
|
|
9
9
|
* Platform routing (1.13.0):
|
|
10
|
-
* posix → spawn(
|
|
10
|
+
* posix → spawn('/bin/sh', ['-c', command])
|
|
11
11
|
* win32 → prefer pwsh > powershell > cmd.exe via env detection;
|
|
12
12
|
* fall back to cmd if PowerShell isn't on PATH. PowerShell
|
|
13
13
|
* handles quoting + UTF-8 + multi-line scripts more cleanly
|
|
14
14
|
* than cmd.exe's relic Windows-95 parser.
|
|
15
15
|
*/
|
|
16
|
-
import { spawn,
|
|
17
|
-
|
|
16
|
+
import { spawn, execFile } from "node:child_process";
|
|
17
|
+
import { StringDecoder } from "node:string_decoder";
|
|
18
|
+
import { resolve, sep } from "node:path";
|
|
19
|
+
import { promisify } from "node:util";
|
|
20
|
+
const execFileAsync = promisify(execFile);
|
|
21
|
+
/** Cached PowerShell executable detection (probed async at first use). */
|
|
18
22
|
let cachedWindowsShell = null;
|
|
19
|
-
|
|
23
|
+
let windowsShellPromise = null;
|
|
24
|
+
async function resolveWindowsShell() {
|
|
20
25
|
if (cachedWindowsShell)
|
|
21
26
|
return cachedWindowsShell;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
if (!windowsShellPromise) {
|
|
28
|
+
windowsShellPromise = (async () => {
|
|
29
|
+
for (const exe of ["pwsh", "powershell"]) {
|
|
30
|
+
try {
|
|
31
|
+
await execFileAsync(exe, ["-NoLogo", "-Command", "exit 0"], {
|
|
32
|
+
timeout: 3000,
|
|
33
|
+
});
|
|
34
|
+
cachedWindowsShell = {
|
|
35
|
+
cmd: exe,
|
|
36
|
+
args: (script) => [
|
|
37
|
+
"-NoLogo",
|
|
38
|
+
"-NoProfile",
|
|
39
|
+
"-NonInteractive",
|
|
40
|
+
"-OutputFormat",
|
|
41
|
+
"Text",
|
|
42
|
+
"-Command",
|
|
43
|
+
script,
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
return cachedWindowsShell;
|
|
47
|
+
}
|
|
48
|
+
catch { }
|
|
49
|
+
}
|
|
28
50
|
cachedWindowsShell = {
|
|
29
|
-
cmd: exe,
|
|
30
|
-
args: (script) => [
|
|
31
|
-
"-NoLogo",
|
|
32
|
-
"-NoProfile",
|
|
33
|
-
"-NonInteractive",
|
|
34
|
-
"-OutputFormat",
|
|
35
|
-
"Text",
|
|
36
|
-
"-Command",
|
|
37
|
-
script,
|
|
38
|
-
],
|
|
51
|
+
cmd: process.env.ComSpec ?? "cmd.exe",
|
|
52
|
+
args: (script) => ["/d", "/s", "/c", script],
|
|
39
53
|
};
|
|
40
54
|
return cachedWindowsShell;
|
|
41
|
-
}
|
|
55
|
+
})();
|
|
42
56
|
}
|
|
43
|
-
|
|
44
|
-
cachedWindowsShell = {
|
|
45
|
-
cmd: process.env.ComSpec ?? "cmd.exe",
|
|
46
|
-
args: (script) => ["/d", "/s", "/c", script],
|
|
47
|
-
};
|
|
48
|
-
return cachedWindowsShell;
|
|
57
|
+
return windowsShellPromise;
|
|
49
58
|
}
|
|
50
59
|
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
51
60
|
const MAX_OUTPUT_BYTES = 256 * 1024;
|
|
@@ -69,39 +78,41 @@ export const shellTool = {
|
|
|
69
78
|
const input = rawInput;
|
|
70
79
|
const cwd = input.cwd ?? ctx.cwd;
|
|
71
80
|
const timeoutMs = input.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
// (= /bin/sh -c).
|
|
81
|
+
if (cwd !== ctx.cwd) {
|
|
82
|
+
const resolved = resolve(cwd);
|
|
83
|
+
const base = resolve(ctx.cwd);
|
|
84
|
+
const baseSep = base.endsWith(sep) ? base : base + sep;
|
|
85
|
+
if (resolved !== base && !resolved.startsWith(baseSep)) {
|
|
86
|
+
return { content: `cwd escapes workspace: ${cwd}`, isError: true };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
81
89
|
const child = process.platform === "win32"
|
|
82
|
-
? (() => {
|
|
83
|
-
const shell = resolveWindowsShell();
|
|
90
|
+
? (async () => {
|
|
91
|
+
const shell = await resolveWindowsShell();
|
|
84
92
|
return spawn(shell.cmd, shell.args(input.command), {
|
|
85
93
|
cwd,
|
|
86
94
|
env: ctx.env,
|
|
87
|
-
stdio: ["
|
|
95
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
88
96
|
windowsHide: true,
|
|
89
97
|
});
|
|
90
98
|
})()
|
|
91
|
-
: spawn(input.command, {
|
|
99
|
+
: spawn("/bin/sh", ["-c", input.command], {
|
|
92
100
|
cwd,
|
|
93
101
|
env: ctx.env,
|
|
94
|
-
stdio: ["
|
|
95
|
-
shell: true,
|
|
102
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
96
103
|
});
|
|
104
|
+
const childProcess = await (child instanceof Promise
|
|
105
|
+
? child
|
|
106
|
+
: Promise.resolve(child));
|
|
97
107
|
const stdoutChunks = [];
|
|
98
108
|
const stderrChunks = [];
|
|
99
109
|
let stdoutBytes = 0;
|
|
100
110
|
let stderrBytes = 0;
|
|
101
111
|
let truncated = false;
|
|
102
|
-
// Shared total so combined stdout+stderr never exceeds MAX_OUTPUT_BYTES.
|
|
103
112
|
let totalBytes = 0;
|
|
104
|
-
const
|
|
113
|
+
const stdoutDecoder = new StringDecoder("utf8");
|
|
114
|
+
const stderrDecoder = new StringDecoder("utf8");
|
|
115
|
+
const onData = (chunks, decoder, trackBytes) => (buf) => {
|
|
105
116
|
const remaining = MAX_OUTPUT_BYTES - totalBytes;
|
|
106
117
|
if (remaining <= 0) {
|
|
107
118
|
truncated = true;
|
|
@@ -113,30 +124,43 @@ export const shellTool = {
|
|
|
113
124
|
trackBytes(slice.length);
|
|
114
125
|
if (buf.length > remaining)
|
|
115
126
|
truncated = true;
|
|
116
|
-
const text =
|
|
127
|
+
const text = decoder.write(slice);
|
|
117
128
|
if (text.trim().length > 0)
|
|
118
129
|
ctx.onProgress?.(text.trimEnd());
|
|
119
130
|
};
|
|
120
|
-
|
|
131
|
+
childProcess.stdout.on("data", onData(stdoutChunks, stdoutDecoder, (n) => {
|
|
121
132
|
stdoutBytes += n;
|
|
122
133
|
}));
|
|
123
|
-
|
|
134
|
+
childProcess.stderr.on("data", onData(stderrChunks, stderrDecoder, (n) => {
|
|
124
135
|
stderrBytes += n;
|
|
125
136
|
}));
|
|
126
137
|
const timer = setTimeout(() => {
|
|
127
|
-
|
|
138
|
+
if (process.platform === "win32") {
|
|
139
|
+
childProcess.kill("SIGTERM");
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
childProcess.kill("SIGKILL");
|
|
143
|
+
}
|
|
128
144
|
}, timeoutMs);
|
|
129
|
-
// Wire abort signal so Esc/cancel kills the child immediately.
|
|
130
145
|
const onAbort = () => {
|
|
131
|
-
|
|
146
|
+
if (process.platform === "win32") {
|
|
147
|
+
childProcess.kill("SIGTERM");
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
childProcess.kill("SIGKILL");
|
|
151
|
+
}
|
|
132
152
|
};
|
|
133
|
-
ctx.signal
|
|
153
|
+
if (ctx.signal) {
|
|
154
|
+
ctx.signal.addEventListener("abort", onAbort, { once: true });
|
|
155
|
+
}
|
|
134
156
|
const exitCode = await new Promise((resolveExit) => {
|
|
135
|
-
|
|
136
|
-
|
|
157
|
+
childProcess.once("error", () => resolveExit(-1));
|
|
158
|
+
childProcess.once("close", (code) => resolveExit(code ?? -1));
|
|
137
159
|
});
|
|
138
160
|
clearTimeout(timer);
|
|
139
|
-
ctx.signal
|
|
161
|
+
if (ctx.signal) {
|
|
162
|
+
ctx.signal.removeEventListener("abort", onAbort);
|
|
163
|
+
}
|
|
140
164
|
const stdout = Buffer.concat(stdoutChunks).toString("utf8");
|
|
141
165
|
const stderr = Buffer.concat(stderrChunks).toString("utf8");
|
|
142
166
|
const banner = `exit=${exitCode}${truncated ? " [output truncated]" : ""}`;
|
package/dist/tools/shell.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell.js","sourceRoot":"","sources":["../../src/tools/shell.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"shell.js","sourceRoot":"","sources":["../../src/tools/shell.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,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C,MAAM,CAC1B,YAAgD,CACjD,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACnB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAC1B,YAAgD,CACjD,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACnB,MAAM,MAAM,GAAG,QAAQ,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QAC3E,MAAM,IAAI,GAAG;YACX,MAAM;YACN,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE;YAC7C,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE;SAC9C;aACE,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,MAAM,CAAC,CAAC;QAEhB,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM;YACxC,IAAI,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE;YACvD,OAAO,EAAE,QAAQ,KAAK,CAAC;SACxB,CAAC;IACJ,CAAC;CACF,CAAC"}
|
package/dist/tui/ink/App.js
CHANGED
|
@@ -27,6 +27,7 @@ import { loadProjectPrimer, composeSystemPrompt, } from "../../context/primer.js
|
|
|
27
27
|
import { queryKb } from "../../context/kb-query.js";
|
|
28
28
|
import { probeGitState, renderGitState } from "../../context/git-state.js";
|
|
29
29
|
import { loadSoul } from "../../context/soul.js";
|
|
30
|
+
import { routeModel } from "../../providers/dispatch.js";
|
|
30
31
|
import { isAutoApprove, modePreamble } from "../../context/mode.js";
|
|
31
32
|
import { runAgentLoop } from "../../kernel/agent-loop.js";
|
|
32
33
|
import { createErrorClassifier } from "../../intelligence/error-classifier.js";
|
|
@@ -57,6 +58,7 @@ import { ThemeProvider, useTheme } from "./theme-context.js";
|
|
|
57
58
|
import { SpinnerContext } from "./spinner-context.js";
|
|
58
59
|
import { SpinnerGlyph } from "./components/SpinnerGlyph.js";
|
|
59
60
|
import { writeFile, mkdir, readFile } from "node:fs/promises";
|
|
61
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
60
62
|
import { homedir } from "node:os";
|
|
61
63
|
import { join as pathJoin } from "node:path";
|
|
62
64
|
import { useEventProjection, } from "./use-event-projection.js";
|
|
@@ -80,6 +82,10 @@ const VERSION = (() => {
|
|
|
80
82
|
return "0.0.0-dev";
|
|
81
83
|
}
|
|
82
84
|
})();
|
|
85
|
+
// Cache for initialHistory — avoids sync fs I/O in the render phase
|
|
86
|
+
// on re-calls (e.g. /clear). The underlying files rarely change within
|
|
87
|
+
// a session so a single snapshot is sufficient.
|
|
88
|
+
let _cachedInitialMessages = null;
|
|
83
89
|
export function App(props) {
|
|
84
90
|
const { exit } = useApp();
|
|
85
91
|
const sessionIdRef = React.useRef(randomUUID());
|
|
@@ -303,6 +309,9 @@ export function App(props) {
|
|
|
303
309
|
setThinkingStreaming(false);
|
|
304
310
|
}
|
|
305
311
|
else if (ev.type === "text_delta" || ev.type === "thinking_delta") {
|
|
312
|
+
// Approximate tokens as chars ÷ 4 — a common heuristic for English
|
|
313
|
+
// text where avg token length is ~4 characters. Not exact but keeps
|
|
314
|
+
// the tok/s rate plausible without an expensive tokenizer.
|
|
306
315
|
liveOutputTokensAccRef.current += (ev.delta?.length ?? 0) / 4;
|
|
307
316
|
}
|
|
308
317
|
else if (ev.type === "usage") {
|
|
@@ -405,7 +414,7 @@ export function App(props) {
|
|
|
405
414
|
});
|
|
406
415
|
// A new submission supersedes any pending failover prompt.
|
|
407
416
|
setPendingFailover(null);
|
|
408
|
-
if (value === "/exit" || value === "/quit") {
|
|
417
|
+
if (value === "/exit" || value === "/quit" || value === "/stop") {
|
|
409
418
|
exit();
|
|
410
419
|
return;
|
|
411
420
|
}
|
|
@@ -423,23 +432,36 @@ export function App(props) {
|
|
|
423
432
|
if (value.startsWith("/model ")) {
|
|
424
433
|
const id = value.slice("/model ".length).trim();
|
|
425
434
|
if (id !== "") {
|
|
426
|
-
|
|
427
|
-
|
|
435
|
+
// Exact match first, then suffix fallback — mirrors slash.ts /model handler.
|
|
436
|
+
const exactMatch = PRICES.find((p) => p.model === id);
|
|
437
|
+
if (exactMatch) {
|
|
438
|
+
setCurrentModel(exactMatch.model);
|
|
428
439
|
const note = {
|
|
429
440
|
kind: "notice",
|
|
430
441
|
id: randomUUID(),
|
|
431
|
-
text: `
|
|
442
|
+
text: `Model set to ${exactMatch.model}`,
|
|
432
443
|
};
|
|
433
444
|
setTranscript((prev) => [...prev, note]);
|
|
434
445
|
}
|
|
435
446
|
else {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
447
|
+
const suffixMatch = PRICES.find((p) => p.model.endsWith("/" + id));
|
|
448
|
+
if (suffixMatch) {
|
|
449
|
+
setCurrentModel(suffixMatch.model);
|
|
450
|
+
const note = {
|
|
451
|
+
kind: "notice",
|
|
452
|
+
id: randomUUID(),
|
|
453
|
+
text: `Model set to ${suffixMatch.model}`,
|
|
454
|
+
};
|
|
455
|
+
setTranscript((prev) => [...prev, note]);
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
const note = {
|
|
459
|
+
kind: "notice",
|
|
460
|
+
id: randomUUID(),
|
|
461
|
+
text: `Invalid model: ${id}. Use /models to see the catalogue.`,
|
|
462
|
+
};
|
|
463
|
+
setTranscript((prev) => [...prev, note]);
|
|
464
|
+
}
|
|
443
465
|
}
|
|
444
466
|
}
|
|
445
467
|
return;
|
|
@@ -529,7 +551,11 @@ export function App(props) {
|
|
|
529
551
|
exit();
|
|
530
552
|
process.exit(code);
|
|
531
553
|
},
|
|
532
|
-
getToken: () =>
|
|
554
|
+
getToken: () => {
|
|
555
|
+
// Token loads asynchronously after mount; return null
|
|
556
|
+
// gracefully so slash commands don't crash on first call.
|
|
557
|
+
return tokenRef.current;
|
|
558
|
+
},
|
|
533
559
|
setToken: (newToken) => {
|
|
534
560
|
tokenRef.current = newToken;
|
|
535
561
|
},
|
|
@@ -718,7 +744,10 @@ export function App(props) {
|
|
|
718
744
|
}
|
|
719
745
|
catch (err) {
|
|
720
746
|
const msg = err instanceof Error ? err.message : String(err);
|
|
721
|
-
|
|
747
|
+
// Only match provider-key errors, not errors from deep inside the agent
|
|
748
|
+
// loop that happen to contain a similar pattern. The message must start
|
|
749
|
+
// with the key name and end with "is required" to qualify.
|
|
750
|
+
const keyMatch = /^([A-Z][A-Z0-9_]+_API_KEY) is required$/.exec(msg);
|
|
722
751
|
if (keyMatch?.[1]) {
|
|
723
752
|
setPendingKey({
|
|
724
753
|
keyName: keyMatch[1],
|
|
@@ -741,7 +770,12 @@ export function App(props) {
|
|
|
741
770
|
abortRef.current = null;
|
|
742
771
|
}
|
|
743
772
|
};
|
|
744
|
-
runTurnRef
|
|
773
|
+
// Keep runTurnRef pointed at the latest runTurn closure so
|
|
774
|
+
// handleSubmit always calls the current version without adding
|
|
775
|
+
// runTurn's deps to handleSubmit's dependency array.
|
|
776
|
+
React.useEffect(() => {
|
|
777
|
+
runTurnRef.current = runTurn;
|
|
778
|
+
});
|
|
745
779
|
// Drain the prompt queue when a turn finishes. Pops the oldest queued
|
|
746
780
|
// prompt and re-submits it through handleSubmit (which transitions
|
|
747
781
|
// back into busy=true via runTurn). Guarded on `!busy` so we never
|
|
@@ -761,6 +795,8 @@ export function App(props) {
|
|
|
761
795
|
// 2. If a turn is streaming → abort it (cancels the in-flight LLM
|
|
762
796
|
// request via the AbortController plumbed through runAgentLoop).
|
|
763
797
|
// 3. If the input box has draft text → clear it.
|
|
798
|
+
// (step 3 is skipped when vimMode is on — InputBox's own handler
|
|
799
|
+
// enters NORMAL mode; clearing here would destroy the text.)
|
|
764
800
|
// Always active so Esc behaves like the user expects regardless of
|
|
765
801
|
// which surface they're looking at. The atfile overlay handles its
|
|
766
802
|
// own Esc (cancel completion) so we skip step 1 there.
|
|
@@ -780,12 +816,13 @@ export function App(props) {
|
|
|
780
816
|
});
|
|
781
817
|
return;
|
|
782
818
|
}
|
|
783
|
-
if (input.length > 0)
|
|
819
|
+
if (input.length > 0 && props.config.vimMode !== true)
|
|
784
820
|
setInput("");
|
|
785
821
|
});
|
|
786
822
|
// Ctrl-C handler: if a turn is running, abort it and show "[Interrupted]"
|
|
787
823
|
// in the transcript (matching the readline path in src/cli/interactive.ts).
|
|
788
|
-
//
|
|
824
|
+
// Idle exit is handled by InputBox's own Ctrl-C handler (2-press safety
|
|
825
|
+
// within 1.5s) — we don't override that here.
|
|
789
826
|
useInput((ch, key) => {
|
|
790
827
|
if (!(key.ctrl && ch === "c"))
|
|
791
828
|
return;
|
|
@@ -797,9 +834,6 @@ export function App(props) {
|
|
|
797
834
|
text: "[Interrupted]",
|
|
798
835
|
});
|
|
799
836
|
}
|
|
800
|
-
else {
|
|
801
|
-
exit();
|
|
802
|
-
}
|
|
803
837
|
});
|
|
804
838
|
const handleModelPick = React.useCallback((id) => {
|
|
805
839
|
overlays.closeOverlay();
|
|
@@ -824,7 +858,7 @@ export function App(props) {
|
|
|
824
858
|
}
|
|
825
859
|
catch (err) {
|
|
826
860
|
const msg = err instanceof Error ? err.message : String(err);
|
|
827
|
-
const m =
|
|
861
|
+
const m = /^([A-Z][A-Z0-9_]+_API_KEY) is required$/.exec(msg);
|
|
828
862
|
if (m?.[1]) {
|
|
829
863
|
// Open inline key entry instead of a static hint — the user can
|
|
830
864
|
// paste their key right here without leaving the REPL.
|
|
@@ -1105,6 +1139,8 @@ function GeneratingIndicator() {
|
|
|
1105
1139
|
return (_jsxs(Box, { gap: 1, marginBottom: 1, children: [_jsx(SpinnerGlyph, { isActive: true, color: palette.text.secondary }), _jsx(Text, { color: palette.text.secondary, dimColor: true, children: "generating\u2026" })] }));
|
|
1106
1140
|
}
|
|
1107
1141
|
function initialHistory(props) {
|
|
1142
|
+
if (_cachedInitialMessages !== null)
|
|
1143
|
+
return _cachedInitialMessages;
|
|
1108
1144
|
const base = props.initialMessages ? [...props.initialMessages] : [];
|
|
1109
1145
|
// Boot context: mode preamble + project primer (DIRGHA.md) +
|
|
1110
1146
|
// caller's --system. Without this, the Ink TUI starts with zero
|
|
@@ -1121,30 +1157,18 @@ function initialHistory(props) {
|
|
|
1121
1157
|
userSystem: props.systemPrompt,
|
|
1122
1158
|
});
|
|
1123
1159
|
base.unshift({ role: "system", content: composedSystem });
|
|
1160
|
+
_cachedInitialMessages = base;
|
|
1124
1161
|
return base;
|
|
1125
1162
|
}
|
|
1126
1163
|
function providerIdForModel(model) {
|
|
1127
|
-
//
|
|
1128
|
-
//
|
|
1129
|
-
|
|
1130
|
-
return
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
if (model.includes("deepseek"))
|
|
1136
|
-
return "deepseek";
|
|
1137
|
-
if (model.includes("kimi") || model.includes("moonshot"))
|
|
1138
|
-
return "nvidia";
|
|
1139
|
-
if (model.includes("llama") ||
|
|
1140
|
-
model.includes("nvidia") ||
|
|
1141
|
-
model.includes("minimax"))
|
|
1142
|
-
return "nvidia";
|
|
1143
|
-
if (model.includes("fireworks"))
|
|
1144
|
-
return "fireworks";
|
|
1145
|
-
if (model.includes("/"))
|
|
1146
|
-
return "openrouter";
|
|
1147
|
-
return "local";
|
|
1164
|
+
// Delegate to providers/dispatch.ts so the StatusBar readout
|
|
1165
|
+
// matches the actual runtime routing at all times.
|
|
1166
|
+
try {
|
|
1167
|
+
return routeModel(model);
|
|
1168
|
+
}
|
|
1169
|
+
catch {
|
|
1170
|
+
return "local";
|
|
1171
|
+
}
|
|
1148
1172
|
}
|
|
1149
1173
|
const PROVIDER_BLURB = {
|
|
1150
1174
|
anthropic: "Claude — Opus, Sonnet, Haiku",
|
|
@@ -1203,6 +1227,24 @@ const PROVIDER_LABEL = {
|
|
|
1203
1227
|
zai: "Z.AI / GLM",
|
|
1204
1228
|
local: "Local",
|
|
1205
1229
|
};
|
|
1230
|
+
/**
|
|
1231
|
+
* Synchronously check whether an env var exists in ~/.dirgha/keys.json.
|
|
1232
|
+
* Used by buildProviderEntries as a fallback when process.env doesn't
|
|
1233
|
+
* contain the key yet (race with startup hydration).
|
|
1234
|
+
*/
|
|
1235
|
+
function tryReadKeyFromStore(envVar) {
|
|
1236
|
+
try {
|
|
1237
|
+
const path = pathJoin(homedir(), ".dirgha", "keys.json");
|
|
1238
|
+
if (!existsSync(path))
|
|
1239
|
+
return false;
|
|
1240
|
+
const raw = readFileSync(path, "utf8");
|
|
1241
|
+
const store = JSON.parse(raw);
|
|
1242
|
+
return typeof store[envVar] === "string" && store[envVar].length > 0;
|
|
1243
|
+
}
|
|
1244
|
+
catch {
|
|
1245
|
+
return false;
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1206
1248
|
/**
|
|
1207
1249
|
* Group the flat model catalogue into per-provider entries for stage 1
|
|
1208
1250
|
* of the picker. Skips providers with zero models in the catalogue.
|
|
@@ -1218,7 +1260,13 @@ function buildProviderEntries(models, currentModel) {
|
|
|
1218
1260
|
const out = [];
|
|
1219
1261
|
for (const [id, items] of buckets) {
|
|
1220
1262
|
const env = PROVIDER_ENV[id];
|
|
1221
|
-
|
|
1263
|
+
// Check env vars AND keys.json (env vars win). keys.json is hydrated
|
|
1264
|
+
// into process.env by hydrateEnvFromKeyStore at startup, but this
|
|
1265
|
+
// synchronous fallback handles the edge case where hydration hasn't
|
|
1266
|
+
// run yet (e.g. TUI mounts before startup hydration completes).
|
|
1267
|
+
const hasKey = env
|
|
1268
|
+
? !!process.env[env] || !!tryReadKeyFromStore(env)
|
|
1269
|
+
: true; // local providers don't need keys
|
|
1222
1270
|
out.push({
|
|
1223
1271
|
id,
|
|
1224
1272
|
label: PROVIDER_LABEL[id] ?? id,
|