@dirgha/code 1.20.15 → 1.20.25
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/cli/first-run.d.ts +6 -5
- package/dist/cli/first-run.js +79 -37
- package/dist/cli/first-run.js.map +1 -1
- package/dist/cli/flows/wizard.js +1 -1
- package/dist/cli/flows/wizard.js.map +1 -1
- package/dist/cli/interactive.js +25 -9
- package/dist/cli/interactive.js.map +1 -1
- package/dist/cli/main.js +8 -1
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/setup.js +4 -2
- package/dist/cli/setup.js.map +1 -1
- package/dist/cli/slash/keys.js +49 -0
- package/dist/cli/slash/keys.js.map +1 -1
- package/dist/cli/slash/login.js +7 -3
- package/dist/cli/slash/login.js.map +1 -1
- package/dist/cli/slash/models.d.ts +1 -1
- package/dist/cli/slash/models.js +142 -18
- package/dist/cli/slash/models.js.map +1 -1
- package/dist/cli/slash/provider.js +1 -1
- package/dist/cli/slash/provider.js.map +1 -1
- package/dist/cli/subcommands/doctor.d.ts +1 -1
- package/dist/cli/subcommands/doctor.js +362 -84
- package/dist/cli/subcommands/doctor.js.map +1 -1
- package/dist/cli/subcommands/keys.js +44 -0
- package/dist/cli/subcommands/keys.js.map +1 -1
- package/dist/cli/subcommands/login.js +8 -3
- package/dist/cli/subcommands/login.js.map +1 -1
- package/dist/cli/update-check.d.ts +1 -0
- package/dist/cli/update-check.js +31 -7
- package/dist/cli/update-check.js.map +1 -1
- package/dist/context/compaction.js +8 -5
- package/dist/context/compaction.js.map +1 -1
- package/dist/context/session.d.ts +1 -0
- package/dist/context/session.js +4 -1
- package/dist/context/session.js.map +1 -1
- package/dist/intelligence/error-classifier.js +37 -8
- package/dist/intelligence/error-classifier.js.map +1 -1
- package/dist/intelligence/failover-chain.d.ts +24 -0
- package/dist/intelligence/failover-chain.js +79 -6
- package/dist/intelligence/failover-chain.js.map +1 -1
- package/dist/intelligence/health-monitor.d.ts +27 -0
- package/dist/intelligence/health-monitor.js +242 -0
- package/dist/intelligence/health-monitor.js.map +1 -0
- package/dist/intelligence/index.d.ts +7 -5
- package/dist/intelligence/index.js +7 -5
- package/dist/intelligence/index.js.map +1 -1
- package/dist/intelligence/prices.js +134 -31
- package/dist/intelligence/prices.js.map +1 -1
- package/dist/intelligence/remote-catalogue.d.ts +31 -0
- package/dist/intelligence/remote-catalogue.js +174 -0
- package/dist/intelligence/remote-catalogue.js.map +1 -0
- package/dist/intelligence/remote-config.d.ts +26 -0
- package/dist/intelligence/remote-config.js +80 -0
- package/dist/intelligence/remote-config.js.map +1 -0
- package/dist/kernel/agent-loop.js +24 -1
- package/dist/kernel/agent-loop.js.map +1 -1
- package/dist/parity/scenarios.d.ts +3 -3
- package/dist/parity/scenarios.js +77 -36
- package/dist/parity/scenarios.js.map +1 -1
- package/dist/providers/anthropic-catalogue.d.ts +9 -0
- package/dist/providers/anthropic-catalogue.js +90 -0
- package/dist/providers/anthropic-catalogue.js.map +1 -0
- package/dist/providers/anthropic.js +3 -1
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/catalogue.d.ts +34 -0
- package/dist/providers/catalogue.js +20 -0
- package/dist/providers/catalogue.js.map +1 -0
- package/dist/providers/cerebras-catalogue.d.ts +9 -0
- package/dist/providers/cerebras-catalogue.js +54 -0
- package/dist/providers/cerebras-catalogue.js.map +1 -0
- package/dist/providers/cohere-catalogue.d.ts +9 -0
- package/dist/providers/cohere-catalogue.js +54 -0
- package/dist/providers/cohere-catalogue.js.map +1 -0
- package/dist/providers/deepseek-catalogue.d.ts +15 -0
- package/dist/providers/deepseek-catalogue.js +81 -0
- package/dist/providers/deepseek-catalogue.js.map +1 -0
- package/dist/providers/deepseek.d.ts +4 -2
- package/dist/providers/deepseek.js +7 -23
- package/dist/providers/deepseek.js.map +1 -1
- package/dist/providers/dispatch.js +22 -27
- package/dist/providers/dispatch.js.map +1 -1
- package/dist/providers/extra-providers.js +21 -0
- package/dist/providers/extra-providers.js.map +1 -1
- package/dist/providers/family-fallback.js +3 -3
- package/dist/providers/family-fallback.js.map +1 -1
- package/dist/providers/gemini-catalogue.d.ts +9 -0
- package/dist/providers/gemini-catalogue.js +73 -0
- package/dist/providers/gemini-catalogue.js.map +1 -0
- package/dist/providers/gemini.js +12 -3
- package/dist/providers/gemini.js.map +1 -1
- package/dist/providers/groq-catalogue.d.ts +9 -0
- package/dist/providers/groq-catalogue.js +82 -0
- package/dist/providers/groq-catalogue.js.map +1 -0
- package/dist/providers/mistral-catalogue.d.ts +9 -0
- package/dist/providers/mistral-catalogue.js +68 -0
- package/dist/providers/mistral-catalogue.js.map +1 -0
- package/dist/providers/nim-catalogue.d.ts +31 -0
- package/dist/providers/nim-catalogue.js +122 -0
- package/dist/providers/nim-catalogue.js.map +1 -0
- package/dist/providers/nvidia.js +33 -10
- package/dist/providers/nvidia.js.map +1 -1
- package/dist/providers/openai-catalogue.d.ts +9 -0
- package/dist/providers/openai-catalogue.js +82 -0
- package/dist/providers/openai-catalogue.js.map +1 -0
- package/dist/providers/perplexity-catalogue.d.ts +10 -0
- package/dist/providers/perplexity-catalogue.js +69 -0
- package/dist/providers/perplexity-catalogue.js.map +1 -0
- package/dist/providers/together-catalogue.d.ts +9 -0
- package/dist/providers/together-catalogue.js +54 -0
- package/dist/providers/together-catalogue.js.map +1 -0
- package/dist/providers/xai-catalogue.d.ts +9 -0
- package/dist/providers/xai-catalogue.js +54 -0
- package/dist/providers/xai-catalogue.js.map +1 -0
- package/dist/state/db-telemetry.d.ts +21 -0
- package/dist/state/db-telemetry.js +106 -0
- package/dist/state/db-telemetry.js.map +1 -0
- package/dist/state/db.js +7 -4
- package/dist/state/db.js.map +1 -1
- package/dist/tui/ink/App.d.ts +5 -1
- package/dist/tui/ink/App.js +220 -31
- package/dist/tui/ink/App.js.map +1 -1
- package/dist/tui/ink/components/DenseToolMessage.js +19 -8
- package/dist/tui/ink/components/DenseToolMessage.js.map +1 -1
- package/dist/tui/ink/components/InputBox.d.ts +2 -0
- package/dist/tui/ink/components/InputBox.js +7 -11
- package/dist/tui/ink/components/InputBox.js.map +1 -1
- package/dist/tui/ink/components/KeySetOverlay.d.ts +1 -1
- package/dist/tui/ink/components/KeySetOverlay.js +18 -16
- package/dist/tui/ink/components/KeySetOverlay.js.map +1 -1
- package/dist/tui/ink/components/PasteCollapse.d.ts +3 -1
- package/dist/tui/ink/components/PasteCollapse.js +11 -9
- package/dist/tui/ink/components/PasteCollapse.js.map +1 -1
- package/dist/tui/ink/components/StatusBar.d.ts +7 -0
- package/dist/tui/ink/components/StatusBar.js +11 -3
- package/dist/tui/ink/components/StatusBar.js.map +1 -1
- package/dist/tui/ink/components/ThinkingBlock.d.ts +15 -4
- package/dist/tui/ink/components/ThinkingBlock.js +34 -17
- package/dist/tui/ink/components/ThinkingBlock.js.map +1 -1
- package/dist/tui/ink/components/ToolBox.js +23 -11
- package/dist/tui/ink/components/ToolBox.js.map +1 -1
- package/dist/tui/ink/components/VirtualTranscript.d.ts +19 -0
- package/dist/tui/ink/components/VirtualTranscript.js +29 -0
- package/dist/tui/ink/components/VirtualTranscript.js.map +1 -0
- package/dist/tui/ink/index.d.ts +5 -1
- package/dist/tui/ink/index.js +19 -7
- package/dist/tui/ink/index.js.map +1 -1
- package/dist/tui/ink/markdown/syntax-highlight.d.ts +13 -0
- package/dist/tui/ink/markdown/syntax-highlight.js +91 -0
- package/dist/tui/ink/markdown/syntax-highlight.js.map +1 -0
- package/dist/tui/ink/use-declined-versions.d.ts +14 -0
- package/dist/tui/ink/use-declined-versions.js +57 -0
- package/dist/tui/ink/use-declined-versions.js.map +1 -0
- package/dist/tui/ink/use-elapsed.d.ts +6 -0
- package/dist/tui/ink/use-elapsed.js +46 -0
- package/dist/tui/ink/use-elapsed.js.map +1 -0
- package/dist/tui/ink/use-flicker-detector.d.ts +12 -0
- package/dist/tui/ink/use-flicker-detector.js +37 -0
- package/dist/tui/ink/use-flicker-detector.js.map +1 -0
- package/dist/tui/ink/use-render-metrics.d.ts +14 -0
- package/dist/tui/ink/use-render-metrics.js +93 -0
- package/dist/tui/ink/use-render-metrics.js.map +1 -0
- package/dist/tui/ink/use-startup-health.d.ts +10 -0
- package/dist/tui/ink/use-startup-health.js +125 -0
- package/dist/tui/ink/use-startup-health.js.map +1 -0
- package/dist/tui/ink/use-transcript-scroll.d.ts +19 -0
- package/dist/tui/ink/use-transcript-scroll.js +83 -0
- package/dist/tui/ink/use-transcript-scroll.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DB write telemetry.
|
|
3
|
+
*
|
|
4
|
+
* Tracks SQLite write failures so they are not silently swallowed.
|
|
5
|
+
* Stores counts in ~/.dirgha/state.json under `dbErrors`. When 10+
|
|
6
|
+
* errors accumulate in a single process lifetime, a warning is
|
|
7
|
+
* written to stderr so the user knows session data may not persist.
|
|
8
|
+
*/
|
|
9
|
+
import { homedir } from "node:os";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
12
|
+
const DIRGHA_DIR = join(homedir(), ".dirgha");
|
|
13
|
+
const STATE_PATH = join(DIRGHA_DIR, "state.json");
|
|
14
|
+
let telemetry = {
|
|
15
|
+
totalWrites: 0,
|
|
16
|
+
failedWrites: 0,
|
|
17
|
+
lastError: "",
|
|
18
|
+
lastErrorTime: "",
|
|
19
|
+
};
|
|
20
|
+
let warned = false;
|
|
21
|
+
let loaded = false;
|
|
22
|
+
async function ensureLoaded() {
|
|
23
|
+
if (loaded)
|
|
24
|
+
return;
|
|
25
|
+
loaded = true;
|
|
26
|
+
await loadDbTelemetry();
|
|
27
|
+
}
|
|
28
|
+
async function persist() {
|
|
29
|
+
try {
|
|
30
|
+
await mkdir(DIRGHA_DIR, { recursive: true });
|
|
31
|
+
let existing = {};
|
|
32
|
+
try {
|
|
33
|
+
const raw = await readFile(STATE_PATH, "utf8");
|
|
34
|
+
existing = JSON.parse(raw);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
/* first write */
|
|
38
|
+
}
|
|
39
|
+
existing.dbErrors = {
|
|
40
|
+
totalWrites: telemetry.totalWrites,
|
|
41
|
+
failedWrites: telemetry.failedWrites,
|
|
42
|
+
lastError: telemetry.lastError,
|
|
43
|
+
lastErrorTime: telemetry.lastErrorTime,
|
|
44
|
+
};
|
|
45
|
+
await writeFile(STATE_PATH, JSON.stringify(existing, null, 2), "utf8");
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
/* best-effort; don't recurse on persist failure */
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
let persistTimer = null;
|
|
52
|
+
function schedulePersist() {
|
|
53
|
+
if (persistTimer)
|
|
54
|
+
clearTimeout(persistTimer);
|
|
55
|
+
persistTimer = setTimeout(() => {
|
|
56
|
+
persistTimer = null;
|
|
57
|
+
void persist();
|
|
58
|
+
}, 5000);
|
|
59
|
+
}
|
|
60
|
+
export function recordDbError(err) {
|
|
61
|
+
void ensureLoaded();
|
|
62
|
+
telemetry.totalWrites++;
|
|
63
|
+
telemetry.failedWrites++;
|
|
64
|
+
telemetry.lastError = err instanceof Error ? err.message : String(err);
|
|
65
|
+
telemetry.lastErrorTime = new Date().toISOString();
|
|
66
|
+
if (!warned && telemetry.failedWrites >= 10) {
|
|
67
|
+
warned = true;
|
|
68
|
+
process.stderr.write("[Dirgha] DB writes failing — session data may not persist.\n");
|
|
69
|
+
}
|
|
70
|
+
schedulePersist();
|
|
71
|
+
}
|
|
72
|
+
export function recordDbSuccess() {
|
|
73
|
+
void ensureLoaded();
|
|
74
|
+
telemetry.totalWrites++;
|
|
75
|
+
schedulePersist();
|
|
76
|
+
}
|
|
77
|
+
export function getDbErrorCount() {
|
|
78
|
+
void ensureLoaded();
|
|
79
|
+
return telemetry.failedWrites;
|
|
80
|
+
}
|
|
81
|
+
export function getDbTelemetry() {
|
|
82
|
+
void ensureLoaded();
|
|
83
|
+
return { ...telemetry };
|
|
84
|
+
}
|
|
85
|
+
export async function flushDbTelemetry() {
|
|
86
|
+
if (persistTimer) {
|
|
87
|
+
clearTimeout(persistTimer);
|
|
88
|
+
persistTimer = null;
|
|
89
|
+
}
|
|
90
|
+
await persist();
|
|
91
|
+
}
|
|
92
|
+
export async function loadDbTelemetry() {
|
|
93
|
+
try {
|
|
94
|
+
await mkdir(DIRGHA_DIR, { recursive: true });
|
|
95
|
+
const raw = await readFile(STATE_PATH, "utf8");
|
|
96
|
+
const existing = JSON.parse(raw);
|
|
97
|
+
const dbErrors = existing.dbErrors;
|
|
98
|
+
if (dbErrors) {
|
|
99
|
+
telemetry = { ...dbErrors };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
/* no prior state */
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=db-telemetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-telemetry.js","sourceRoot":"","sources":["../../src/state/db-telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9D,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;AAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;AASlD,IAAI,SAAS,GAAoB;IAC/B,WAAW,EAAE,CAAC;IACd,YAAY,EAAE,CAAC;IACf,SAAS,EAAE,EAAE;IACb,aAAa,EAAE,EAAE;CAClB,CAAC;AAEF,IAAI,MAAM,GAAG,KAAK,CAAC;AACnB,IAAI,MAAM,GAAG,KAAK,CAAC;AAEnB,KAAK,UAAU,YAAY;IACzB,IAAI,MAAM;QAAE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G,QAAQ,CAAC,QAAuC,CAAC;QAClE,IAAI,QAAQ,EAAE,CAAC;YACb,SAAS,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,oBAAoB;IACtB,CAAC;AACH,CAAC"}
|
package/dist/state/db.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import { join } from "node:path";
|
|
12
12
|
import { homedir } from "node:os";
|
|
13
13
|
import { mkdirSync } from "node:fs";
|
|
14
|
+
import { recordDbError, recordDbSuccess } from "./db-telemetry.js";
|
|
14
15
|
const DB_DIR = join(homedir(), ".dirgha");
|
|
15
16
|
const DB_PATH = join(DB_DIR, "dirgha.db");
|
|
16
17
|
// Lazy singleton — only opened when first needed.
|
|
@@ -72,9 +73,10 @@ export function dbCloseSession(id) {
|
|
|
72
73
|
try {
|
|
73
74
|
const db = getDb();
|
|
74
75
|
db.prepare("UPDATE sessions SET ended_at = ? WHERE id = ?").run(Date.now(), id);
|
|
76
|
+
recordDbSuccess();
|
|
75
77
|
}
|
|
76
|
-
catch {
|
|
77
|
-
|
|
78
|
+
catch (err) {
|
|
79
|
+
recordDbError(err);
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
82
|
export function dbAppendMessage(sessionId, message) {
|
|
@@ -84,9 +86,10 @@ export function dbAppendMessage(sessionId, message) {
|
|
|
84
86
|
? message.content
|
|
85
87
|
: JSON.stringify(message.content);
|
|
86
88
|
db.prepare("INSERT INTO messages(session_id, role, content, ts) VALUES (?, ?, ?, ?)").run(sessionId, message.role, content, Date.now());
|
|
89
|
+
recordDbSuccess();
|
|
87
90
|
}
|
|
88
|
-
catch {
|
|
89
|
-
|
|
91
|
+
catch (err) {
|
|
92
|
+
recordDbError(err);
|
|
90
93
|
}
|
|
91
94
|
}
|
|
92
95
|
export function dbSearchChats(query, limit = 20) {
|
package/dist/state/db.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/state/db.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/state/db.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEnE,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;AAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAE1C,kDAAkD;AAClD,IAAI,GAAG,GAA6C,IAAI,CAAC;AAEzD,SAAS,KAAK;IACZ,IAAI,GAAG;QAAE,OAAO,GAAG,CAAC;IAEpB,IAAI,CAAC;QACH,MAAM,QAAQ,GACZ,OAAO,CAAC,gBAAgB,CAAoC,CAAC;QAC/D,SAAS,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACvC,GAAG,GAAG,IAAK,QAG4B,CAAC,OAAO,CAAC,CAAC;QAChD,GAAyC,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;QACvE,GAAyC,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC;QAC1E,UAAU,CAAC,GAAwC,CAAC,CAAC;QACrD,OAAO,GAAwC,CAAC;IAClD,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACb,mFAAmF,CACpF,CAAC;IACJ,C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,eAAe,EAAE,CAAC;IACpB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,aAAa,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;AACH,CAAC;AASD,MAAM,UAAU,aAAa,CAAC,KAAa,EAAE,KAAK,GAAG,EAAE;IACrD,IAAI,CAAC;QACH,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;QACnB,OAAO,EAAE;aACN,OAAO,CACN;;;;;;;KAOH,CACE;aACA,GAAG,CAAC,KAAK,EAAE,KAAK,CAAiB,CAAC;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,IAAI,CAAC;QACH,KAAK,EAAE,CAAC;QACR,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAK,GAAG,EAAE;IAOvC,IAAI,CAAC;QACH,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;QACnB,OAAO,EAAE;aACN,OAAO,CACN;;;;;;;;KAQH,CACE;aACA,GAAG,CAAC,KAAK,CAMV,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
package/dist/tui/ink/App.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import type { Message } from "../../kernel/types.js";
|
|
|
18
18
|
import type { EventStream } from "../../kernel/event-stream.js";
|
|
19
19
|
import type { ProviderRegistry } from "../../providers/index.js";
|
|
20
20
|
import type { ToolRegistry } from "../../tools/registry.js";
|
|
21
|
-
import type { SessionStore } from "../../context/session.js";
|
|
21
|
+
import type { SessionStore, Session } from "../../context/session.js";
|
|
22
22
|
import type { DirghaConfig } from "../../cli/config.js";
|
|
23
23
|
import type { SlashRegistry } from "../../cli/slash.js";
|
|
24
24
|
import { type ModelEntry } from "./components/ModelPicker.js";
|
|
@@ -40,5 +40,9 @@ export interface AppProps {
|
|
|
40
40
|
slashRegistry: SlashRegistry;
|
|
41
41
|
/** Cross-session memory/ledger context injected into system prompt. */
|
|
42
42
|
ledgerContext?: string;
|
|
43
|
+
/** Mutable ref — write the active session here so runInkTUI can flush on exit. */
|
|
44
|
+
sessionHandle?: {
|
|
45
|
+
session: Session | null;
|
|
46
|
+
};
|
|
43
47
|
}
|
|
44
48
|
export declare function App(props: AppProps): React.JSX.Element;
|
package/dist/tui/ink/App.js
CHANGED
|
@@ -17,6 +17,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
17
17
|
import * as React from "react";
|
|
18
18
|
import { Box, Static, Text, useApp, useInput } from "ink";
|
|
19
19
|
import { randomUUID } from "node:crypto";
|
|
20
|
+
import { VirtualTranscript } from "./components/VirtualTranscript.js";
|
|
20
21
|
import { appendAudit } from "../../audit/writer.js";
|
|
21
22
|
import { maybeCompact } from "../../context/compaction.js";
|
|
22
23
|
import { contextWindowFor } from "../../intelligence/prices.js";
|
|
@@ -36,7 +37,7 @@ import { PRICES } from "../../intelligence/prices.js";
|
|
|
36
37
|
import { Logo } from "./components/Logo.js";
|
|
37
38
|
import { StatusBar } from "./components/StatusBar.js";
|
|
38
39
|
import { StreamingText } from "./components/StreamingText.js";
|
|
39
|
-
import { ThinkingBlock } from "./components/ThinkingBlock.js";
|
|
40
|
+
import { ThinkingBlock, ThinkingBlockGroup, } from "./components/ThinkingBlock.js";
|
|
40
41
|
import { ToolBox } from "./components/ToolBox.js";
|
|
41
42
|
import { ToolGroup } from "./components/ToolGroup.js";
|
|
42
43
|
import { InputBox } from "./components/InputBox.js";
|
|
@@ -48,16 +49,23 @@ import { HelpOverlay, } from "./components/HelpOverlay.js";
|
|
|
48
49
|
import { KeySetOverlay } from "./components/KeySetOverlay.js";
|
|
49
50
|
import { saveKey } from "../../auth/keystore.js";
|
|
50
51
|
import { loadToken, migrateLegacyAuth, } from "../../integrations/device-auth.js";
|
|
52
|
+
import { getUpdateBannerVersion } from "../../cli/update-check.js";
|
|
51
53
|
import { AtFileComplete } from "./components/AtFileComplete.js";
|
|
52
54
|
import { SlashComplete } from "./components/SlashComplete.js";
|
|
53
55
|
import { ThemePicker } from "./components/ThemePicker.js";
|
|
54
|
-
import { ThemeProvider } from "./theme-context.js";
|
|
56
|
+
import { ThemeProvider, useTheme } from "./theme-context.js";
|
|
55
57
|
import { SpinnerContext } from "./spinner-context.js";
|
|
58
|
+
import { SpinnerGlyph } from "./components/SpinnerGlyph.js";
|
|
56
59
|
import { writeFile, mkdir, readFile } from "node:fs/promises";
|
|
57
60
|
import { homedir } from "node:os";
|
|
58
61
|
import { join as pathJoin } from "node:path";
|
|
59
62
|
import { useEventProjection, } from "./use-event-projection.js";
|
|
60
63
|
import { useOverlays } from "./use-overlays.js";
|
|
64
|
+
import { useDeclinedVersions } from "./use-declined-versions.js";
|
|
65
|
+
import { useStartupHealth } from "./use-startup-health.js";
|
|
66
|
+
import { useFlickerDetector } from "./use-flicker-detector.js";
|
|
67
|
+
import { useRenderMetrics, } from "./use-render-metrics.js";
|
|
68
|
+
import { getRemoteConfig, isVersionBelowMin, } from "../../intelligence/remote-config.js";
|
|
61
69
|
import { createRequire } from "node:module";
|
|
62
70
|
// Pulled from the installed package.json so the TUI title matches the
|
|
63
71
|
// shipped binary version. Falls back to '0.0.0-dev' if the file isn't
|
|
@@ -78,9 +86,31 @@ export function App(props) {
|
|
|
78
86
|
const historyRef = React.useRef(initialHistory(props));
|
|
79
87
|
const abortRef = React.useRef(null);
|
|
80
88
|
const pendingModelRef = React.useRef(null);
|
|
89
|
+
const sessionRef = React.useRef(null);
|
|
90
|
+
React.useEffect(() => {
|
|
91
|
+
const id = sessionIdRef.current;
|
|
92
|
+
void props.sessions.create(id).then((s) => {
|
|
93
|
+
sessionRef.current = s;
|
|
94
|
+
if (props.sessionHandle)
|
|
95
|
+
props.sessionHandle.session = s;
|
|
96
|
+
});
|
|
97
|
+
return () => {
|
|
98
|
+
if (sessionRef.current) {
|
|
99
|
+
try {
|
|
100
|
+
sessionRef.current.close();
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
/* swallow */
|
|
104
|
+
}
|
|
105
|
+
if (props.sessionHandle)
|
|
106
|
+
props.sessionHandle.session = null;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}, [props.sessions, props.sessionHandle]);
|
|
81
110
|
const [transcript, setTranscript] = React.useState([]);
|
|
82
111
|
const [input, setInput] = React.useState("");
|
|
83
112
|
const [busy, setBusy] = React.useState(false);
|
|
113
|
+
const [thinkingStreaming, setThinkingStreaming] = React.useState(false);
|
|
84
114
|
// Prompt queue: while a turn is streaming the user can still type and
|
|
85
115
|
// press Enter. Submissions land here instead of being dropped, then
|
|
86
116
|
// drain FIFO when the turn finishes (see useEffect below).
|
|
@@ -147,6 +177,116 @@ export function App(props) {
|
|
|
147
177
|
const [liveDurationMs, setLiveDurationMs] = React.useState(0);
|
|
148
178
|
const turnStartRef = React.useRef(0);
|
|
149
179
|
const liveOutputTokensAccRef = React.useRef(0);
|
|
180
|
+
const [updateVersion, setUpdateVersion] = React.useState(null);
|
|
181
|
+
const updateShownRef = React.useRef(false);
|
|
182
|
+
const declined = useDeclinedVersions();
|
|
183
|
+
React.useEffect(() => {
|
|
184
|
+
if (updateShownRef.current)
|
|
185
|
+
return;
|
|
186
|
+
updateShownRef.current = true;
|
|
187
|
+
getUpdateBannerVersion(VERSION).then((v) => {
|
|
188
|
+
if (v && !declined.isDeclined(v))
|
|
189
|
+
setUpdateVersion(v);
|
|
190
|
+
});
|
|
191
|
+
}, [declined]);
|
|
192
|
+
// Startup health check — non-blocking, cached for 24h.
|
|
193
|
+
const healthResult = useStartupHealth();
|
|
194
|
+
// Flicker detector — compares estimated tree height to terminal rows.
|
|
195
|
+
const estimatedLineCount = (transcript.length + projection.liveItems.length) * 2 + 15;
|
|
196
|
+
const flicker = useFlickerDetector(estimatedLineCount);
|
|
197
|
+
// Render performance metrics — track frame timing, expose for StatusBar.
|
|
198
|
+
const renderMetrics = useRenderMetrics();
|
|
199
|
+
const [showRenderMetrics, setShowRenderMetrics] = React.useState(false);
|
|
200
|
+
// Alt+M toggles the render-metrics display in the StatusBar.
|
|
201
|
+
useInput((ch, key) => {
|
|
202
|
+
if (key.meta && ch === "m") {
|
|
203
|
+
setShowRenderMetrics((v) => !v);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
// Remote config: fetch once on mount, set model default, show MOTD.
|
|
207
|
+
const [remoteConfig, setRemoteConfig] = React.useState(null);
|
|
208
|
+
const [motdShown, setMotdShown] = React.useState(false);
|
|
209
|
+
const [remoteConfigFetched, setRemoteConfigFetched] = React.useState(false);
|
|
210
|
+
React.useEffect(() => {
|
|
211
|
+
if (remoteConfigFetched)
|
|
212
|
+
return;
|
|
213
|
+
setRemoteConfigFetched(true);
|
|
214
|
+
void getRemoteConfig().then((cfg) => {
|
|
215
|
+
if (cfg)
|
|
216
|
+
setRemoteConfig(cfg);
|
|
217
|
+
});
|
|
218
|
+
}, [remoteConfigFetched]);
|
|
219
|
+
// Apply remote config model default on first load if no explicit model set.
|
|
220
|
+
const remoteModelAppliedRef = React.useRef(false);
|
|
221
|
+
React.useEffect(() => {
|
|
222
|
+
if (!remoteConfig || remoteModelAppliedRef.current)
|
|
223
|
+
return;
|
|
224
|
+
remoteModelAppliedRef.current = true;
|
|
225
|
+
const explicit = props.config.model;
|
|
226
|
+
const hasDefault = explicit !== undefined &&
|
|
227
|
+
explicit !== "" &&
|
|
228
|
+
explicit !== "accounts/fireworks/routers/kimi-k2p5-turbo";
|
|
229
|
+
if (!hasDefault && remoteConfig.recommendedModel) {
|
|
230
|
+
setCurrentModel(remoteConfig.recommendedModel);
|
|
231
|
+
}
|
|
232
|
+
}, [remoteConfig, props.config.model]);
|
|
233
|
+
// Show MOTD once per session.
|
|
234
|
+
React.useEffect(() => {
|
|
235
|
+
if (!remoteConfig?.motd || motdShown)
|
|
236
|
+
return;
|
|
237
|
+
setMotdShown(true);
|
|
238
|
+
const note = {
|
|
239
|
+
kind: "notice",
|
|
240
|
+
id: randomUUID(),
|
|
241
|
+
text: remoteConfig.motd,
|
|
242
|
+
};
|
|
243
|
+
setTranscript((prev) => [...prev, note]);
|
|
244
|
+
}, [remoteConfig, motdShown]);
|
|
245
|
+
// Warn about deprecated models if the current model is in the list.
|
|
246
|
+
const deprecatedWarnedRef = React.useRef(false);
|
|
247
|
+
React.useEffect(() => {
|
|
248
|
+
if (!remoteConfig || deprecatedWarnedRef.current)
|
|
249
|
+
return;
|
|
250
|
+
if (remoteConfig.deprecatedModels.length > 0 &&
|
|
251
|
+
remoteConfig.deprecatedModels.includes(currentModel)) {
|
|
252
|
+
deprecatedWarnedRef.current = true;
|
|
253
|
+
const note = {
|
|
254
|
+
kind: "notice",
|
|
255
|
+
id: randomUUID(),
|
|
256
|
+
text: `[DEPRECATED] Model ${currentModel} is deprecated. Switch to ${remoteConfig.recommendedModel ?? "a supported model"} via /model.`,
|
|
257
|
+
};
|
|
258
|
+
setTranscript((prev) => [...prev, note]);
|
|
259
|
+
}
|
|
260
|
+
}, [remoteConfig, currentModel]);
|
|
261
|
+
// Minimum version nag: show upgrade banner immediately if below minimum.
|
|
262
|
+
const [minVersionNagShown, setMinVersionNagShown] = React.useState(false);
|
|
263
|
+
React.useEffect(() => {
|
|
264
|
+
if (!remoteConfig || minVersionNagShown)
|
|
265
|
+
return;
|
|
266
|
+
if (isVersionBelowMin(VERSION, remoteConfig.minimumVersion)) {
|
|
267
|
+
setMinVersionNagShown(true);
|
|
268
|
+
setUpdateVersion(remoteConfig.minimumVersion);
|
|
269
|
+
}
|
|
270
|
+
}, [remoteConfig, minVersionNagShown]);
|
|
271
|
+
// Self-upgrade handler (Ctrl+U or /upgrade).
|
|
272
|
+
const handleUpgrade = React.useCallback(() => {
|
|
273
|
+
void (async () => {
|
|
274
|
+
try {
|
|
275
|
+
const { execFileSync } = await import("node:child_process");
|
|
276
|
+
const isWin = process.platform === "win32";
|
|
277
|
+
const npmBin = isWin ? "npm.cmd" : "npm";
|
|
278
|
+
execFileSync(npmBin, ["i", "-g", "@dirgha/code@latest"], {
|
|
279
|
+
stdio: "inherit",
|
|
280
|
+
shell: isWin,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
catch {
|
|
284
|
+
/* fall through to exit */
|
|
285
|
+
}
|
|
286
|
+
exit();
|
|
287
|
+
process.exit(0);
|
|
288
|
+
})();
|
|
289
|
+
}, [exit]);
|
|
150
290
|
React.useEffect(() => {
|
|
151
291
|
const unsub = props.events.subscribe((ev) => {
|
|
152
292
|
if (ev.type === "agent_start") {
|
|
@@ -154,6 +294,13 @@ export function App(props) {
|
|
|
154
294
|
liveOutputTokensAccRef.current = 0;
|
|
155
295
|
setLiveOutputTokens(0);
|
|
156
296
|
setLiveDurationMs(0);
|
|
297
|
+
setThinkingStreaming(false);
|
|
298
|
+
}
|
|
299
|
+
else if (ev.type === "thinking_start") {
|
|
300
|
+
setThinkingStreaming(true);
|
|
301
|
+
}
|
|
302
|
+
else if (ev.type === "thinking_end") {
|
|
303
|
+
setThinkingStreaming(false);
|
|
157
304
|
}
|
|
158
305
|
else if (ev.type === "text_delta" || ev.type === "thinking_delta") {
|
|
159
306
|
liveOutputTokensAccRef.current += (ev.delta?.length ?? 0) / 4;
|
|
@@ -306,14 +453,28 @@ export function App(props) {
|
|
|
306
453
|
overlays.openOverlay("theme");
|
|
307
454
|
return;
|
|
308
455
|
}
|
|
456
|
+
// /upgrade and /self-update trigger npm install + restart.
|
|
457
|
+
if (value === "/upgrade" ||
|
|
458
|
+
value === "/self-update" ||
|
|
459
|
+
value === "/update --self") {
|
|
460
|
+
const note = {
|
|
461
|
+
kind: "notice",
|
|
462
|
+
id: randomUUID(),
|
|
463
|
+
text: "Upgrading @dirgha/code to latest via npm…",
|
|
464
|
+
};
|
|
465
|
+
setTranscript((prev) => [...prev, note]);
|
|
466
|
+
handleUpgrade();
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
309
469
|
// Anything else starting with `/` goes through the SlashRegistry — that
|
|
310
470
|
// covers /init /keys /memory /compact /setup /login /status /resume
|
|
311
|
-
// /session /history /fleet /account /
|
|
312
|
-
// The hardcoded branches above (clear/help/model[s]/theme) ran first
|
|
313
|
-
// because they open Ink overlays and don't fit
|
|
314
|
-
// contract. Without this dispatch,
|
|
315
|
-
// through to runTurn() and were sent
|
|
316
|
-
// surprising behaviour that S1/2026-04-27
|
|
471
|
+
// /session /history /fleet /account /config /mode and friends.
|
|
472
|
+
// The hardcoded branches above (clear/help/model[s]/theme/upgrade) ran first
|
|
473
|
+
// because they open Ink overlays or trigger self-upgrade and don't fit
|
|
474
|
+
// the registry string-output contract. Without this dispatch,
|
|
475
|
+
// unrecognised slash commands fell through to runTurn() and were sent
|
|
476
|
+
// to the LLM as user prompts — surprising behaviour that S1/2026-04-27
|
|
477
|
+
// fixes.
|
|
317
478
|
if (value.startsWith("/")) {
|
|
318
479
|
const ctx = {
|
|
319
480
|
get model() {
|
|
@@ -436,6 +597,11 @@ export function App(props) {
|
|
|
436
597
|
};
|
|
437
598
|
setTranscript((prev) => [...prev, userItem]);
|
|
438
599
|
historyRef.current.push({ role: "user", content: value });
|
|
600
|
+
void sessionRef.current?.append({
|
|
601
|
+
type: "message",
|
|
602
|
+
ts: new Date().toISOString(),
|
|
603
|
+
message: { role: "user", content: value },
|
|
604
|
+
});
|
|
439
605
|
void runTurnRef.current();
|
|
440
606
|
}, [
|
|
441
607
|
busy,
|
|
@@ -456,6 +622,7 @@ export function App(props) {
|
|
|
456
622
|
overlays.setSlashQuery,
|
|
457
623
|
overlays.setActive,
|
|
458
624
|
overlays.active,
|
|
625
|
+
handleUpgrade,
|
|
459
626
|
]);
|
|
460
627
|
const runTurn = async () => {
|
|
461
628
|
setBusy(true);
|
|
@@ -523,6 +690,7 @@ export function App(props) {
|
|
|
523
690
|
const userHooks = buildAgentHooksFromConfig(props.config);
|
|
524
691
|
const composedHooks = composeHooks(enforceMode(mode), userHooks);
|
|
525
692
|
const autoApprove = isAutoApprove(mode);
|
|
693
|
+
const prevHistoryLen = historyRef.current.length;
|
|
526
694
|
const result = await runAgentLoop({
|
|
527
695
|
sessionId: sessionIdRef.current,
|
|
528
696
|
model: currentModel,
|
|
@@ -540,6 +708,13 @@ export function App(props) {
|
|
|
540
708
|
...(composedHooks !== undefined ? { hooks: composedHooks } : {}),
|
|
541
709
|
});
|
|
542
710
|
historyRef.current = result.messages;
|
|
711
|
+
for (const msg of result.messages.slice(prevHistoryLen)) {
|
|
712
|
+
void sessionRef.current?.append({
|
|
713
|
+
type: "message",
|
|
714
|
+
ts: new Date().toISOString(),
|
|
715
|
+
message: msg,
|
|
716
|
+
});
|
|
717
|
+
}
|
|
543
718
|
}
|
|
544
719
|
catch (err) {
|
|
545
720
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -789,19 +964,10 @@ export function App(props) {
|
|
|
789
964
|
}
|
|
790
965
|
})();
|
|
791
966
|
}, [overlays]);
|
|
792
|
-
const
|
|
793
|
-
// Gemini CLI approach: freeze committed history inside <Static>
|
|
794
|
-
// so Ink caches the output and never re-renders it. Without this,
|
|
795
|
-
// every streaming flush tick re-conciles the entire transcript
|
|
796
|
-
// against the terminal — causing visible flicker/jitter.
|
|
797
|
-
const committedStaticItems = React.useMemo(() => committedJsx.map((el, i) => ({
|
|
798
|
-
key: el?.key ?? `c-${i}`,
|
|
799
|
-
el,
|
|
800
|
-
})), [committedJsx]);
|
|
801
|
-
const liveJsx = React.useMemo(() => renderTranscript(projection.liveItems), [projection.liveItems]);
|
|
967
|
+
const liveJsx = React.useMemo(() => renderTranscript(projection.liveItems, thinkingStreaming), [projection.liveItems, thinkingStreaming]);
|
|
802
968
|
const providerEntries = React.useMemo(() => buildProviderEntries(models, currentModel), [models, currentModel]);
|
|
803
969
|
const LOGO_ITEMS = React.useMemo(() => [{ key: "logo" }], []);
|
|
804
|
-
return (_jsx(ThemeProvider, { activeTheme: themeName, children: _jsx(SpinnerContext.Provider, { value: { busy, frame: 0 }, children: _jsxs(Box, { flexDirection: "column", children: [_jsx(Static, { items: LOGO_ITEMS, children: () => _jsx(Logo, { version: VERSION }, "logo") }), _jsx(
|
|
970
|
+
return (_jsx(ThemeProvider, { activeTheme: themeName, children: _jsx(SpinnerContext.Provider, { value: { busy, frame: 0 }, children: _jsxs(Box, { flexDirection: "column", children: [_jsx(Static, { items: LOGO_ITEMS, children: () => _jsx(Logo, { version: VERSION }, "logo") }), _jsx(VirtualTranscript, { items: transcript, renderItem: (item) => _jsx(TranscriptRow, { item: item }, item.id), autoScroll: true, inputFocus: inputFocus }), _jsx(Box, { flexDirection: "column", children: liveJsx }), busy && projection.liveItems.length === 0 && _jsx(GeneratingIndicator, {}), pendingApproval !== null && approvalBusRef.current && (_jsx(ApprovalPrompt, { request: pendingApproval, onResolve: (decision) => {
|
|
805
971
|
approvalBusRef.current?.resolve(pendingApproval.id, decision);
|
|
806
972
|
} })), pendingFailover !== null && (_jsx(ModelSwitchPrompt, { failedModel: pendingFailover.failedModel, failoverModel: pendingFailover.failoverModel, onAccept: (failover) => {
|
|
807
973
|
const lastPrompt = pendingFailover.lastPrompt;
|
|
@@ -827,7 +993,7 @@ export function App(props) {
|
|
|
827
993
|
: "YOLO mode OFF — back to standard confirmation.",
|
|
828
994
|
},
|
|
829
995
|
]);
|
|
830
|
-
}, inputFocus: inputFocus }), overlays.active === "atfile" && overlays.atQuery !== null && (_jsx(AtFileComplete, { cwd: props.cwd, query: overlays.atQuery, onPick: handleAtPick, onCancel: () => {
|
|
996
|
+
}, onRequestUpgrade: handleUpgrade, inputFocus: inputFocus }), healthResult !== null && !healthResult.allOk && (_jsx(Box, { paddingX: 1, children: _jsxs(Text, { color: "yellow", children: ["[! System check: ", healthResult.failures.length, " issue", healthResult.failures.length !== 1 ? "s" : "", " found \u2014 run 'dirgha doctor' for details]"] }) })), overlays.active === "atfile" && overlays.atQuery !== null && (_jsx(AtFileComplete, { cwd: props.cwd, query: overlays.atQuery, onPick: handleAtPick, onCancel: () => {
|
|
831
997
|
overlays.setAtQuery(null);
|
|
832
998
|
overlays.setActive(null);
|
|
833
999
|
} })), overlays.active === "slash" && overlays.slashQuery !== null && (_jsx(SlashComplete, { commands: slashCommands, query: overlays.slashQuery, onPick: handleSlashPick, onCancel: () => {
|
|
@@ -856,28 +1022,40 @@ export function App(props) {
|
|
|
856
1022
|
// Esc inside ModelPicker → back to ProviderPicker (NOT close).
|
|
857
1023
|
setPickerStage("provider");
|
|
858
1024
|
setPickerProvider(null);
|
|
859
|
-
} })), overlays.active === "help" && (_jsx(HelpOverlay, { slashCommands: slashCommands, onClose: overlays.closeOverlay })), overlays.active === "theme" && (_jsx(ThemePicker, { current: themeName, onPick: handleThemePick, onCancel: overlays.closeOverlay })), pendingKey && (_jsx(KeySetOverlay, { keyName: pendingKey.keyName, onSave: handleKeySetSave, onCancel: () => setPendingKey(null) })), _jsx(StatusBar, { model: currentModel, provider: providerIdForModel(currentModel), inputTokens: projection.totals.inputTokens, outputTokens: projection.totals.outputTokens, costUsd: projection.totals.costUsd, cwd: props.cwd, busy: busy, mode: mode, contextWindow: contextWindowFor(currentModel), liveOutputTokens: liveOutputTokens, liveDurationMs: liveDurationMs })] }) }) }));
|
|
1025
|
+
} })), overlays.active === "help" && (_jsx(HelpOverlay, { slashCommands: slashCommands, onClose: overlays.closeOverlay })), overlays.active === "theme" && (_jsx(ThemePicker, { current: themeName, onPick: handleThemePick, onCancel: overlays.closeOverlay })), pendingKey && (_jsx(KeySetOverlay, { keyName: pendingKey.keyName, onSave: handleKeySetSave, onCancel: () => setPendingKey(null) })), updateVersion !== null && (_jsx(Box, { paddingX: 1, children: _jsxs(Text, { color: "yellow", children: ["[v", updateVersion, " available \u2014 press Ctrl+U or /upgrade to upgrade]"] }) })), _jsx(StatusBar, { model: currentModel, provider: providerIdForModel(currentModel), inputTokens: projection.totals.inputTokens, outputTokens: projection.totals.outputTokens, costUsd: projection.totals.costUsd, cwd: props.cwd, busy: busy, mode: mode, contextWindow: contextWindowFor(currentModel), liveOutputTokens: liveOutputTokens, liveDurationMs: liveDurationMs, overflowDetected: flicker.overflowDetected, showMetrics: showRenderMetrics, renderMetrics: renderMetrics })] }) }) }));
|
|
860
1026
|
}
|
|
861
1027
|
/**
|
|
862
1028
|
* Walk the transcript and fold consecutive `tool` items into a single
|
|
863
|
-
* <ToolGroup>.
|
|
864
|
-
*
|
|
865
|
-
*
|
|
866
|
-
* `text` spans of the same turn.
|
|
1029
|
+
* <ToolGroup>. Fold 3+ consecutive `thinking` items into a single
|
|
1030
|
+
* <ThinkingBlockGroup>. Non-tool / non-thinking items render via
|
|
1031
|
+
* <TranscriptRow>.
|
|
867
1032
|
*/
|
|
868
|
-
function renderTranscript(items) {
|
|
1033
|
+
function renderTranscript(items, thinkingStreaming) {
|
|
869
1034
|
const out = [];
|
|
870
1035
|
let toolBuf = [];
|
|
1036
|
+
let thinkBuf = [];
|
|
871
1037
|
const flushTools = () => {
|
|
872
1038
|
if (toolBuf.length === 0)
|
|
873
1039
|
return;
|
|
874
|
-
// Key on the stable ID of the first tool so React never unmounts/remounts
|
|
875
|
-
// the ToolGroup subtree when the counter resets (which caused flicker).
|
|
876
1040
|
out.push(_jsx(ToolGroup, { tools: toolBuf }, toolBuf[0].id));
|
|
877
1041
|
toolBuf = [];
|
|
878
1042
|
};
|
|
1043
|
+
const flushThinking = () => {
|
|
1044
|
+
if (thinkBuf.length === 0)
|
|
1045
|
+
return;
|
|
1046
|
+
if (thinkBuf.length >= 3) {
|
|
1047
|
+
out.push(_jsx(ThinkingBlockGroup, { blocks: thinkBuf }, thinkBuf[0].id));
|
|
1048
|
+
}
|
|
1049
|
+
else {
|
|
1050
|
+
for (const tb of thinkBuf) {
|
|
1051
|
+
out.push(_jsx(TranscriptRow, { item: { kind: "thinking", id: tb.id, content: tb.content }, isStreaming: thinkingStreaming }, tb.id));
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
thinkBuf = [];
|
|
1055
|
+
};
|
|
879
1056
|
for (const item of items) {
|
|
880
1057
|
if (item.kind === "tool") {
|
|
1058
|
+
flushThinking();
|
|
881
1059
|
toolBuf.push({
|
|
882
1060
|
id: item.id,
|
|
883
1061
|
name: item.name,
|
|
@@ -890,20 +1068,27 @@ function renderTranscript(items) {
|
|
|
890
1068
|
});
|
|
891
1069
|
continue;
|
|
892
1070
|
}
|
|
1071
|
+
if (item.kind === "thinking") {
|
|
1072
|
+
flushTools();
|
|
1073
|
+
thinkBuf.push({ id: item.id, content: item.content });
|
|
1074
|
+
continue;
|
|
1075
|
+
}
|
|
893
1076
|
flushTools();
|
|
894
|
-
|
|
1077
|
+
flushThinking();
|
|
1078
|
+
out.push(_jsx(TranscriptRow, { item: item, isStreaming: thinkingStreaming }, item.id));
|
|
895
1079
|
}
|
|
896
1080
|
flushTools();
|
|
1081
|
+
flushThinking();
|
|
897
1082
|
return out;
|
|
898
1083
|
}
|
|
899
|
-
function TranscriptRow({ item, }) {
|
|
1084
|
+
function TranscriptRow({ item, isStreaming = false, }) {
|
|
900
1085
|
switch (item.kind) {
|
|
901
1086
|
case "user":
|
|
902
1087
|
return (_jsxs(Box, { gap: 2, marginBottom: 1, children: [_jsx(Text, { color: "magenta", children: "\u276F" }), _jsx(Text, { color: "white", children: item.text })] }));
|
|
903
1088
|
case "text":
|
|
904
1089
|
return _jsx(StreamingText, { content: item.content });
|
|
905
1090
|
case "thinking":
|
|
906
|
-
return _jsx(ThinkingBlock, { content: item.content });
|
|
1091
|
+
return _jsx(ThinkingBlock, { content: item.content, isStreaming: isStreaming });
|
|
907
1092
|
case "tool":
|
|
908
1093
|
// Should not be reached — tools are folded by renderTranscript() into
|
|
909
1094
|
// <ToolGroup>. Kept as a safety net so an unexpected tool item still
|
|
@@ -915,6 +1100,10 @@ function TranscriptRow({ item, }) {
|
|
|
915
1100
|
return (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { color: "yellow", children: item.text }) }));
|
|
916
1101
|
}
|
|
917
1102
|
}
|
|
1103
|
+
function GeneratingIndicator() {
|
|
1104
|
+
const palette = useTheme();
|
|
1105
|
+
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
|
+
}
|
|
918
1107
|
function initialHistory(props) {
|
|
919
1108
|
const base = props.initialMessages ? [...props.initialMessages] : [];
|
|
920
1109
|
// Boot context: mode preamble + project primer (DIRGHA.md) +
|