pantheon-opencode 1.6.0-beta.8 → 1.6.0
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/AGENTS.global.md +118 -0
- package/AGENTS.md +18 -168
- package/CHANGELOG.md +126 -346
- package/README.md +83 -608
- package/README.pt-BR.md +120 -345
- package/bin/pantheon-init.mjs +366 -132
- package/commands/pantheon-audit.md +7 -1
- package/commands/pantheon-consolidate.md +1 -1
- package/commands/pantheon-deepwork.md +14 -3
- package/commands/pantheon-focus.md +17 -0
- package/commands/pantheon-vision.md +61 -12
- package/package.json +19 -11
- package/plugin.json +1 -1
- package/pyproject.toml +6 -2
- package/scripts/_pantheon_paths.py +24 -0
- package/scripts/build-agents-md.mjs +368 -69
- package/scripts/changelog-merge.mjs +161 -0
- package/scripts/check-plugin-v2-coverage.mjs +11 -8
- package/scripts/docs-check-changelog.mjs +204 -0
- package/scripts/docs-link-check.mjs +314 -0
- package/scripts/docs-media.mjs +157 -0
- package/scripts/doctor.mjs +828 -40
- package/scripts/install/agents-md.mjs +2 -2
- package/scripts/install/backup.mjs +648 -0
- package/scripts/install/cli-ui.mjs +303 -72
- package/scripts/install/component-selection.mjs +61 -0
- package/scripts/install/config-migration.mjs +583 -27
- package/scripts/install/exit-codes.mjs +26 -0
- package/scripts/install/file-inventory.mjs +555 -0
- package/scripts/install/health-check.mjs +31 -25
- package/scripts/install/interactive.mjs +78 -383
- package/scripts/install/migrate.mjs +49 -25
- package/scripts/install/model-picker.mjs +218 -250
- package/scripts/install/opencode-version.mjs +83 -21
- package/scripts/install/opencode.mjs +1465 -180
- package/scripts/install/plan-artifact.mjs +517 -0
- package/scripts/install/plan.mjs +475 -0
- package/scripts/install/plugin.mjs +251 -30
- package/scripts/install/prompt-result.mjs +2 -0
- package/scripts/install/shared.mjs +256 -99
- package/scripts/install/state.mjs +63 -8
- package/scripts/install/strings.mjs +60 -4
- package/scripts/install/venv.mjs +90 -47
- package/scripts/install/verify.mjs +128 -0
- package/scripts/install/vision-prompt.mjs +173 -0
- package/scripts/install-mcp.mjs +2 -2
- package/scripts/manifest-inventory.mjs +49 -3
- package/scripts/mcp_persistence.py +1535 -1050
- package/scripts/memory_mcp.py +12 -843
- package/scripts/node-engine-policy.mjs +85 -0
- package/scripts/package-evidence.mjs +10 -2
- package/scripts/postinstall.mjs +26 -26
- package/scripts/probe-pantheon-cost.mjs +118 -19
- package/scripts/prune.mjs +9 -3
- package/scripts/reconcile.mjs +325 -0
- package/scripts/release-gates.mjs +682 -0
- package/scripts/restore.mjs +222 -0
- package/scripts/run-node-tests.mjs +24 -8
- package/scripts/sync-artifacts.mjs +20 -7
- package/scripts/sync-tui.mjs +29 -4
- package/scripts/test-opencode-v2-sandbox.sh +36 -123
- package/scripts/uninstall.mjs +369 -34
- package/scripts/update.mjs +164 -0
- package/scripts/validate-node-engine-policy.mjs +13 -0
- package/scripts/version-check.mjs +34 -1
- package/scripts/versioning.mjs +23 -3
- package/scripts/vision-status.mjs +682 -0
- package/skills-lock.json +8 -8
- package/src/agents/aphrodite.md +13 -10
- package/src/agents/apollo.md +4 -5
- package/src/agents/athena.md +74 -46
- package/src/agents/demeter.md +10 -7
- package/src/agents/gaia.md +0 -1
- package/src/agents/hephaestus.md +4 -3
- package/src/agents/hermes.md +10 -9
- package/src/agents/iris.md +6 -1
- package/src/agents/mnemosyne.md +14 -15
- package/src/agents/nyx.md +4 -4
- package/src/agents/prometheus.md +12 -11
- package/src/agents/talos.md +6 -0
- package/src/agents/zeus.md +84 -56
- package/src/instructions/agent-return-format.instructions.md +12 -41
- package/src/instructions/memory-protocol.instructions.md +5 -11
- package/src/instructions/test-economy.instructions.md +12 -0
- package/src/instructions/yagni.instructions.md +6 -15
- package/src/instructions/zeus-anti-stall.instructions.md +6 -6
- package/src/instructions/zeus-communication-rules.instructions.md +6 -6
- package/src/instructions/zeus-council-synthesis.instructions.md +11 -12
- package/src/instructions/zeus-memory-operations.instructions.md +13 -7
- package/src/instructions/zeus-timeout-retry.instructions.md +36 -10
- package/src/mcp/_pantheon_paths.py +24 -0
- package/src/mcp/mcp_codemap_module.py +86 -18
- package/src/mcp/mcp_persistence.py +1535 -1050
- package/src/mcp/memory_mcp.py +444 -94
- package/src/mcp/pantheon_vision.py +285 -41
- package/src/mcp/requirements-mcp.txt +5 -0
- package/src/pantheon/context-pruner.ts +541 -0
- package/src/pantheon/cost-command.ts +814 -60
- package/src/pantheon/goal-loop.ts +11 -8
- package/src/pantheon/memory-context.ts +1017 -0
- package/src/pantheon/model-agents.ts +19 -0
- package/src/pantheon/model-command.ts +218 -56
- package/src/pantheon/model-pricing.ts +536 -0
- package/src/pantheon/presets.mjs +2 -0
- package/src/pantheon/task-result-guard.ts +50 -14
- package/src/pantheon/v2-bounded-read.ts +640 -0
- package/src/pantheon/v2-delegation-enforce.ts +133 -6
- package/src/pantheon/v2-execute-after.ts +135 -24
- package/src/pantheon/v2-model-overrides.ts +275 -0
- package/src/pantheon/v2-tools.ts +89 -35
- package/src/pantheon/v2-unsupported.mjs +2 -3
- package/src/pantheon/v2-vision.ts +622 -0
- package/src/pantheon/vision-local.ts +531 -0
- package/src/pantheon/vision.ts +1160 -115
- package/src/plugin-v2.ts +654 -162
- package/src/plugin.ts +15 -11
- package/src/plugins/tui/dist/tui-v2.d.ts +1036 -0
- package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -0
- package/src/plugins/tui/dist/tui-v2.js +3808 -0
- package/src/plugins/tui/dist/tui-v2.js.map +1 -0
- package/src/plugins/tui/dist/tui.js +4 -4
- package/src/plugins/tui/index-v2.ts +6 -0
- package/src/plugins/tui/package-lock.json +5416 -1297
- package/src/plugins/tui/package.json +14 -10
- package/src/plugins/tui/src/index-v2.tsx +4372 -0
- package/src/plugins/tui/src/index.tsx +3 -3
- package/src/plugins/tui/src/opencode-v2.d.ts +13 -0
- package/src/plugins/tui/tsconfig.typecheck.json +5 -0
- package/src/plugins/tui/tsdown.config.ts +2 -2
- package/src/plugins/tui/tui-v2.ts +2 -0
- package/src/plugins/tui/tui.ts +3 -0
- package/src/routing.yml +50 -5
- package/src/skills/agent-coordination/SKILL.md +7 -2
- package/src/skills/artifact-management/SKILL.md +5 -1
- package/src/skills/auto-continue/SKILL.md +14 -6
- package/src/skills/codemap/SKILL.md +1 -1
- package/src/skills/memory-bank/SKILL.md +21 -13
- package/src/skills/session-goal/SKILL.md +14 -15
- package/src/skills/spec-driven-development/SKILL.md +3 -1
- package/src/skills/worktrees/SKILL.md +30 -11
- package/scripts/probe-context-rehydrate.mjs +0 -263
|
@@ -0,0 +1,3808 @@
|
|
|
1
|
+
import { createComponent, createElement, createTextNode, effect, insert, insertNode, memo, setProp } from "@opentui/solid";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { For, Show, createEffect, createMemo, createSignal, on, onCleanup, onMount } from "solid-js";
|
|
6
|
+
import { execFile } from "node:child_process";
|
|
7
|
+
import { Plugin } from "@opencode/plugin/tui";
|
|
8
|
+
//#region src/index-v2.tsx
|
|
9
|
+
/** @jsxImportSource @opentui/solid */
|
|
10
|
+
const SINGLETON = Symbol.for("pantheon.tui.v2.loaded");
|
|
11
|
+
/** How often the sidebar re-reads .pantheon/active-preset.json (V1 parity) so
|
|
12
|
+
* `set-tier` changes made while opencode is open show up within ~30s. */
|
|
13
|
+
const PRESET_REFRESH_MS = 3e4;
|
|
14
|
+
/** Running-row spinner cadence — matches V1's animation tick. */
|
|
15
|
+
const SPINNER_INTERVAL_MS = 80;
|
|
16
|
+
/** Bounded warm-up: sync at most this many sessions at plugin load. */
|
|
17
|
+
const WARMUP_SESSION_LIMIT = 24;
|
|
18
|
+
/** Sidebar body shown while the host has not published a session yet. */
|
|
19
|
+
const SIDEBAR_WAITING_LABEL = "Aguardando sessão…";
|
|
20
|
+
/** Delegate-completion toast title. */
|
|
21
|
+
const TOAST_TITLE = "Pantheon";
|
|
22
|
+
/** Marker before the preset label (fixed header, home status, prompt footer).
|
|
23
|
+
* `▸` U+25B8 is one cell; the previous bolt (U+26A1) carries
|
|
24
|
+
* Emoji_Presentation and is measured as two cells, which misaligned the line. */
|
|
25
|
+
const PRESET_MARKER = "▸";
|
|
26
|
+
/** Git ahead / behind arrows (U+2191 / U+2193), one cell each — the glyphs the
|
|
27
|
+
* reference sidebars use for `↑ahead ↓behind`. */
|
|
28
|
+
const GIT_ARROW_UP = "↑";
|
|
29
|
+
const GIT_ARROW_DOWN = "↓";
|
|
30
|
+
/** One event name the host publishes on `data.on` — the OpenCode V2 union. */
|
|
31
|
+
/** V2 events that refresh the sidebar. V1 also listened to `session.updated`,
|
|
32
|
+
* but that name is absent from the OpenCode V2 event union (verified against
|
|
33
|
+
* `@opencode/client`'s `OpenCodeEvent`), so the valid events that carry the
|
|
34
|
+
* same state changes are used instead: `session.renamed` /
|
|
35
|
+
* `session.metadata.updated` / `session.moved` (the mutations `session.updated`
|
|
36
|
+
* used to stand for) and `session.idle` (a child finishing). `satisfies` keeps
|
|
37
|
+
* the literals while making a name outside the union a type error (surfaced by
|
|
38
|
+
* `tsc -p tsconfig.build.json`), and the sidebar test asserts the same names
|
|
39
|
+
* against the installed union at runtime. */
|
|
40
|
+
const SIDEBAR_REFRESH_EVENTS = [
|
|
41
|
+
"session.created",
|
|
42
|
+
"session.renamed",
|
|
43
|
+
"session.metadata.updated",
|
|
44
|
+
"session.moved",
|
|
45
|
+
"session.idle",
|
|
46
|
+
"session.status",
|
|
47
|
+
"session.deleted"
|
|
48
|
+
];
|
|
49
|
+
/** One `overrides.agents[<agent>]` entry from active-preset.json. */
|
|
50
|
+
/** The override map the CLI wrote into active-preset.json. */
|
|
51
|
+
/** A preset plus the explicit overrides stored next to it. */
|
|
52
|
+
function emptyOverrides() {
|
|
53
|
+
return { agents: {} };
|
|
54
|
+
}
|
|
55
|
+
/** Keep only well-formed per-agent overrides: unknown keys are ignored and a
|
|
56
|
+
* non-string model/variant is dropped instead of leaking into the render. */
|
|
57
|
+
function parsePresetOverrides(value) {
|
|
58
|
+
const overrides = emptyOverrides();
|
|
59
|
+
if (!value || typeof value !== "object") return overrides;
|
|
60
|
+
const agents = value.agents;
|
|
61
|
+
if (!agents || typeof agents !== "object") return overrides;
|
|
62
|
+
for (const [agent, entry] of Object.entries(agents)) {
|
|
63
|
+
if (agent === "" || !entry || typeof entry !== "object") continue;
|
|
64
|
+
const model = entry.model;
|
|
65
|
+
const variant = entry.variant;
|
|
66
|
+
const override = {};
|
|
67
|
+
if (typeof model === "string" && model !== "") override.model = model;
|
|
68
|
+
if (typeof variant === "string" && variant !== "") override.variant = variant;
|
|
69
|
+
if (override.model !== void 0 || override.variant !== void 0) overrides.agents[agent] = override;
|
|
70
|
+
}
|
|
71
|
+
return overrides;
|
|
72
|
+
}
|
|
73
|
+
/** Read .pantheon/active-preset.json — first existing candidate wins; malformed
|
|
74
|
+
* JSON or a `preset` that is missing, empty or "none" → null (no fall-through
|
|
75
|
+
* to lower candidates). The explicit per-agent overrides stored in the same
|
|
76
|
+
* file come along so the sidebar can mark them with `*`. */
|
|
77
|
+
async function readActivePresetDetail(cwd) {
|
|
78
|
+
const xdgConfig = process.env.XDG_CONFIG_HOME ?? join(homedir(), ".config");
|
|
79
|
+
const candidates = [
|
|
80
|
+
join(cwd, ".pantheon", "active-preset.json"),
|
|
81
|
+
join(xdgConfig, "opencode", ".pantheon", "active-preset.json"),
|
|
82
|
+
join(homedir(), ".opencode", ".pantheon", "active-preset.json")
|
|
83
|
+
];
|
|
84
|
+
for (const candidate of candidates) {
|
|
85
|
+
let raw;
|
|
86
|
+
try {
|
|
87
|
+
raw = await readFile(candidate, "utf8");
|
|
88
|
+
} catch {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
const parsed = JSON.parse(raw);
|
|
93
|
+
const name = parsed && typeof parsed === "object" ? parsed.preset : void 0;
|
|
94
|
+
if (typeof name !== "string" || name.length === 0 || name === "none") return null;
|
|
95
|
+
return {
|
|
96
|
+
info: {
|
|
97
|
+
name,
|
|
98
|
+
source: "file"
|
|
99
|
+
},
|
|
100
|
+
overrides: parsePresetOverrides(parsed.overrides)
|
|
101
|
+
};
|
|
102
|
+
} catch {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
/** Env leg of resolution: PANTHEON_MODEL_PRESET set and !== 'none' wins. */
|
|
109
|
+
function presetFromEnv(env) {
|
|
110
|
+
const name = env.PANTHEON_MODEL_PRESET;
|
|
111
|
+
if (name !== void 0 && name !== "" && name !== "none") return {
|
|
112
|
+
name,
|
|
113
|
+
source: "env"
|
|
114
|
+
};
|
|
115
|
+
return {
|
|
116
|
+
name: null,
|
|
117
|
+
source: null
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/** Resolve the active preset plus its per-agent overrides: env > file > default.
|
|
121
|
+
* An env-selected preset has no file overrides by construction. */
|
|
122
|
+
async function resolveActivePresetForTui(env, cwd) {
|
|
123
|
+
const envPreset = presetFromEnv(env);
|
|
124
|
+
if (envPreset.source === "env") return {
|
|
125
|
+
info: envPreset,
|
|
126
|
+
overrides: emptyOverrides()
|
|
127
|
+
};
|
|
128
|
+
return await readActivePresetDetail(cwd) ?? {
|
|
129
|
+
info: {
|
|
130
|
+
name: null,
|
|
131
|
+
source: null
|
|
132
|
+
},
|
|
133
|
+
overrides: emptyOverrides()
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/** `SessionInfo.id` is always a `ses…` handle. Guarded so a placeholder or a
|
|
137
|
+
* foreign id never reaches the status/navigate APIs. */
|
|
138
|
+
function isValidSessionID(id) {
|
|
139
|
+
return typeof id === "string" && id.startsWith("ses");
|
|
140
|
+
}
|
|
141
|
+
function numberOrNull(value) {
|
|
142
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
143
|
+
}
|
|
144
|
+
/** Model reference shapes the host publishes: `ModelRef` objects, bare ids, or
|
|
145
|
+
* `provider/model` strings. Returns the id part, never throws. */
|
|
146
|
+
function modelRefID(ref) {
|
|
147
|
+
if (typeof ref === "string") return ref === "" ? null : ref;
|
|
148
|
+
if (ref && typeof ref === "object") {
|
|
149
|
+
const id = ref.id;
|
|
150
|
+
if (typeof id === "string" && id !== "") return id;
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
/** Short display id: the segment after the last `/` (`opencode-go/kimi-k3` →
|
|
155
|
+
* `kimi-k3`), truncated so a long id never wraps the sidebar. */
|
|
156
|
+
function shortModelID(ref, max = 24) {
|
|
157
|
+
const id = modelRefID(ref);
|
|
158
|
+
if (id === null) return null;
|
|
159
|
+
const segment = id.slice(id.lastIndexOf("/") + 1);
|
|
160
|
+
if (segment === "") return null;
|
|
161
|
+
return segment.length > max ? `${segment.slice(0, Math.max(1, max - 1))}…` : segment;
|
|
162
|
+
}
|
|
163
|
+
/** `providerID` of a model reference, trimmed; null when absent/blank. Derived
|
|
164
|
+
* only from what the host already published — never a lookup table. */
|
|
165
|
+
function providerIDFromRef(ref) {
|
|
166
|
+
if (ref === null || typeof ref !== "object") return null;
|
|
167
|
+
const providerID = ref.providerID;
|
|
168
|
+
return typeof providerID === "string" && providerID.trim() !== "" ? providerID.trim() : null;
|
|
169
|
+
}
|
|
170
|
+
/** Provider for a bare-string model reference: match its id (or bare segment)
|
|
171
|
+
* in the host model list. Null when the list cannot answer. */
|
|
172
|
+
function providerIDFromModels(models, ref) {
|
|
173
|
+
if (!Array.isArray(models)) return null;
|
|
174
|
+
const id = modelRefID(ref);
|
|
175
|
+
if (id === null) return null;
|
|
176
|
+
const segment = id.slice(id.lastIndexOf("/") + 1);
|
|
177
|
+
for (const model of models) {
|
|
178
|
+
if (!model || typeof model !== "object") continue;
|
|
179
|
+
const modelID = typeof model.modelID === "string" ? model.modelID : "";
|
|
180
|
+
const rowID = typeof model.id === "string" ? model.id : "";
|
|
181
|
+
if (modelID !== id && rowID !== id && modelID !== segment && rowID !== segment) continue;
|
|
182
|
+
const providerID = providerIDFromRef(model);
|
|
183
|
+
if (providerID !== null) return providerID;
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
/** Resolve `model.limit.context` for a model reference. Match order: the
|
|
188
|
+
* provider-qualified id, then the bare id (the host's `id`/`modelID` fields).
|
|
189
|
+
* Absent/ambiguous models degrade to null so the gauge is simply omitted. */
|
|
190
|
+
function resolveContextLimit(models, ref) {
|
|
191
|
+
const id = modelRefID(ref);
|
|
192
|
+
if (id === null) return null;
|
|
193
|
+
const providerID = ref && typeof ref === "object" ? ref.providerID : void 0;
|
|
194
|
+
const segment = id.slice(id.lastIndexOf("/") + 1);
|
|
195
|
+
const matches = models.filter((model) => {
|
|
196
|
+
if (!model || typeof model !== "object") return false;
|
|
197
|
+
const modelID = typeof model.modelID === "string" ? model.modelID : "";
|
|
198
|
+
const rowID = typeof model.id === "string" ? model.id : "";
|
|
199
|
+
if (!(modelID === id || rowID === id || modelID === segment || rowID === segment)) return false;
|
|
200
|
+
if (typeof providerID !== "string" || providerID === "") return true;
|
|
201
|
+
return model.providerID === providerID;
|
|
202
|
+
});
|
|
203
|
+
const candidates = matches.length > 0 ? matches : models.filter((model) => {
|
|
204
|
+
const modelID = typeof model?.modelID === "string" ? model.modelID : "";
|
|
205
|
+
const rowID = typeof model?.id === "string" ? model.id : "";
|
|
206
|
+
return modelID === segment || rowID === segment;
|
|
207
|
+
});
|
|
208
|
+
for (const model of candidates) {
|
|
209
|
+
const limit = model?.limit?.context;
|
|
210
|
+
if (typeof limit === "number" && Number.isFinite(limit) && limit > 0) return limit;
|
|
211
|
+
}
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
/** Native token total: input + output + reasoning + cache read + cache write. */
|
|
215
|
+
function messageTokensTotal(tokens) {
|
|
216
|
+
const cacheRead = numberOrNull(tokens?.cache?.read) ?? 0;
|
|
217
|
+
const cacheWrite = numberOrNull(tokens?.cache?.write) ?? 0;
|
|
218
|
+
return (numberOrNull(tokens?.input) ?? 0) + (numberOrNull(tokens?.output) ?? 0) + (numberOrNull(tokens?.reasoning) ?? 0) + cacheRead + cacheWrite;
|
|
219
|
+
}
|
|
220
|
+
/** The part of a transcript that still counts: everything before the revert
|
|
221
|
+
* boundary (when a revert is active), then after the last compaction. Both
|
|
222
|
+
* derived numbers that read "the last assistant with usage" — the context
|
|
223
|
+
* gauge and the cache hit rate — share this window, so a reverted-away or
|
|
224
|
+
* compacted-away message can never feed either one. Pure. */
|
|
225
|
+
function transcriptWindow(messages, revertMessageID) {
|
|
226
|
+
let end = messages.length;
|
|
227
|
+
if (typeof revertMessageID === "string" && revertMessageID !== "") {
|
|
228
|
+
const boundary = messages.findIndex((message) => message?.id === revertMessageID);
|
|
229
|
+
if (boundary >= 0) end = boundary;
|
|
230
|
+
}
|
|
231
|
+
let start = 0;
|
|
232
|
+
for (let index = end - 1; index >= 0; index--) if (messages[index]?.type === "compaction") {
|
|
233
|
+
start = index + 1;
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
return {
|
|
237
|
+
start,
|
|
238
|
+
end
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/** Context usage for a message list. Scope: the live window (see
|
|
242
|
+
* `transcriptWindow`). The last assistant message carrying `tokens` in that
|
|
243
|
+
* window wins. Null when there is no limit or no such message — the caller
|
|
244
|
+
* then omits the block. */
|
|
245
|
+
function computeContextUsage(messages, contextLimit, revertMessageID) {
|
|
246
|
+
const limit = numberOrNull(contextLimit);
|
|
247
|
+
if (limit === null || limit <= 0) return null;
|
|
248
|
+
if (!Array.isArray(messages) || messages.length === 0) return null;
|
|
249
|
+
const { start, end } = transcriptWindow(messages, revertMessageID);
|
|
250
|
+
for (let index = end - 1; index >= start; index--) {
|
|
251
|
+
const message = messages[index];
|
|
252
|
+
if (message?.type !== "assistant" || !message.tokens) continue;
|
|
253
|
+
const tokens = messageTokensTotal(message.tokens);
|
|
254
|
+
if (!Number.isFinite(tokens) || tokens <= 0) continue;
|
|
255
|
+
return {
|
|
256
|
+
tokens,
|
|
257
|
+
percent: Math.round(tokens / limit * 100),
|
|
258
|
+
limit
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
/** Semantic tone for a context percentage, inclusive at the top of each band:
|
|
264
|
+
* info (blue) up to 25%, success (green) up to 50%, warning (yellow) up to
|
|
265
|
+
* 90%, error (red) above it. Four explicit stages, each backed by a feedback
|
|
266
|
+
* token, so the gauge follows the active theme. Pure. */
|
|
267
|
+
function contextUsageTone(percent) {
|
|
268
|
+
if (percent > 90) return "error";
|
|
269
|
+
if (percent > 50) return "warning";
|
|
270
|
+
if (percent > 25) return "success";
|
|
271
|
+
return "info";
|
|
272
|
+
}
|
|
273
|
+
/** The gauge's four stages, one per theme feedback token. */
|
|
274
|
+
/** Color for one gauge stage. Filled cells and the percent value both come from
|
|
275
|
+
* this one call, so the bar and its number can never disagree. `theme` is the
|
|
276
|
+
* host's resolved theme (loosely typed at runtime); a missing token falls back
|
|
277
|
+
* to the theme's base text instead of an unstyled cell. Pure. */
|
|
278
|
+
function contextProgressColor(stage, theme) {
|
|
279
|
+
return theme?.text?.feedback?.[stage]?.base ?? theme?.text?.base;
|
|
280
|
+
}
|
|
281
|
+
/** The muted extra line under the gauge: `cache 92% · 42.3 tok/s`. Either half
|
|
282
|
+
* may be missing (no cache read, no measurable turn); no data at all yields
|
|
283
|
+
* null so no empty line is rendered. The speed keeps the host's own one
|
|
284
|
+
* decimal and `tok/s` label. Pure. */
|
|
285
|
+
function contextPerformanceLine(performance) {
|
|
286
|
+
if (!performance) return null;
|
|
287
|
+
const parts = [];
|
|
288
|
+
const cacheHit = numberOrNull(performance.cacheHit);
|
|
289
|
+
if (cacheHit !== null) parts.push(`cache ${Math.round(cacheHit)}%`);
|
|
290
|
+
const tokensPerSecond = numberOrNull(performance.tokensPerSecond);
|
|
291
|
+
if (tokensPerSecond !== null) parts.push(`${tokensPerSecond.toFixed(1)} tok/s`);
|
|
292
|
+
return parts.length === 0 ? null : parts.join(SPEND_LINE_SEPARATOR);
|
|
293
|
+
}
|
|
294
|
+
/** Cache hit rate of one message: `cache.read / (input + cache.read)` as a
|
|
295
|
+
* percentage. The denominator must be > 0, otherwise the ratio is meaningless
|
|
296
|
+
* (a message that only wrote to the cache has no input to hit). Null when the
|
|
297
|
+
* numbers are absent. Pure. */
|
|
298
|
+
function cacheHitPercent(tokens) {
|
|
299
|
+
const read = numberOrNull(tokens?.cache?.read);
|
|
300
|
+
const input = numberOrNull(tokens?.input);
|
|
301
|
+
if (read === null || input === null) return null;
|
|
302
|
+
const denominator = input + read;
|
|
303
|
+
if (!(denominator > 0)) return null;
|
|
304
|
+
return read / denominator * 100;
|
|
305
|
+
}
|
|
306
|
+
/** The message the cache hit rate comes from: the last assistant of the live
|
|
307
|
+
* window (see `transcriptWindow`) that actually carries `tokens`. Later
|
|
308
|
+
* messages without usage — a streaming placeholder that the host publishes
|
|
309
|
+
* before any step completes, a step that reports no usage — are skipped
|
|
310
|
+
* instead of blanking a ratio the previous message already measured. Null
|
|
311
|
+
* when nothing in the window has usage. Pure. */
|
|
312
|
+
function lastAssistantWithTokens(messages, revertMessageID) {
|
|
313
|
+
if (!Array.isArray(messages) || messages.length === 0) return null;
|
|
314
|
+
const { start, end } = transcriptWindow(messages, revertMessageID);
|
|
315
|
+
for (let index = end - 1; index >= start; index--) {
|
|
316
|
+
const message = messages[index];
|
|
317
|
+
if (message?.type !== "assistant" || !message.tokens) continue;
|
|
318
|
+
return message;
|
|
319
|
+
}
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
/** Tokens per second of the current turn. Mirrors the host's
|
|
323
|
+
* `turnTokensPerSecond` (anomalyco/opencode v2.0.30,
|
|
324
|
+
* `packages/tui/src/routes/session/rows.ts`) so the sidebar and the native
|
|
325
|
+
* session footer can never disagree: the numerator is `output + reasoning`
|
|
326
|
+
* summed over every assistant step of the turn and the denominator is the
|
|
327
|
+
* summed active streaming time `max(0, time.streamed - time.created)`, so the
|
|
328
|
+
* division happens once, after aggregating — each step weighs by its own
|
|
329
|
+
* duration instead of each step voting equally. `completed` is never used; a
|
|
330
|
+
* turn with a step that has no `time.streamed` has no measurable speed. The
|
|
331
|
+
* turn starts after the last `user` message; with no user message only the
|
|
332
|
+
* last assistant step counts (degraded: there is no boundary to group by).
|
|
333
|
+
* Pure and fail-open. */
|
|
334
|
+
function turnTokensPerSecond(messages, position) {
|
|
335
|
+
if (!Array.isArray(messages) || messages.length === 0) return null;
|
|
336
|
+
let anchor = -1;
|
|
337
|
+
if (typeof position === "number" && Number.isInteger(position) && position >= 0 && position < messages.length) anchor = position;
|
|
338
|
+
else for (let index = messages.length - 1; index >= 0; index--) if (messages[index]?.type === "assistant") {
|
|
339
|
+
anchor = index;
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
if (anchor === -1 || messages[anchor]?.type !== "assistant") return null;
|
|
343
|
+
let start = -1;
|
|
344
|
+
for (let index = anchor - 1; index >= 0; index--) if (messages[index]?.type === "user") {
|
|
345
|
+
start = index;
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
const steps = start === -1 ? [messages[anchor]] : messages.slice(start + 1, anchor + 1).filter((item) => item?.type === "assistant");
|
|
349
|
+
if (steps.length === 0) return null;
|
|
350
|
+
let output = 0;
|
|
351
|
+
let duration = 0;
|
|
352
|
+
for (const step of steps) {
|
|
353
|
+
output += (numberOrNull(step?.tokens?.output) ?? 0) + (numberOrNull(step?.tokens?.reasoning) ?? 0);
|
|
354
|
+
const created = numberOrNull(step?.time?.created);
|
|
355
|
+
const streamed = numberOrNull(step?.time?.streamed);
|
|
356
|
+
if (created === null || streamed === null) return null;
|
|
357
|
+
duration += Math.max(0, streamed - created);
|
|
358
|
+
}
|
|
359
|
+
if (output <= 0 || duration <= 0) return null;
|
|
360
|
+
const rate = output / (duration / 1e3);
|
|
361
|
+
return Number.isFinite(rate) && rate > 0 ? rate : null;
|
|
362
|
+
}
|
|
363
|
+
/** Last-message telemetry the Context block renders in muted text. Both halves
|
|
364
|
+
* are optional; the block renders no line when neither is available. */
|
|
365
|
+
/** Thousands-separated token total: `55320` → `55,320` (en-US, matching the
|
|
366
|
+
* native block this one replaces). Null for a missing/invalid value. Pure. */
|
|
367
|
+
function formatTokenCount(tokens) {
|
|
368
|
+
const value = numberOrNull(tokens);
|
|
369
|
+
if (value === null || value < 0) return null;
|
|
370
|
+
return Math.round(value).toLocaleString("en-US");
|
|
371
|
+
}
|
|
372
|
+
/** Context-window label: `1_000_000` → `1.0M`, `200_000` → `200K`,
|
|
373
|
+
* `128_000` → `128K`, `32_768` → `32K`. Sub-million limits truncate to whole K
|
|
374
|
+
* so the printed window never overstates the model's capacity. Pure. */
|
|
375
|
+
function formatContextWindow(limit) {
|
|
376
|
+
const value = numberOrNull(limit);
|
|
377
|
+
if (value === null || value <= 0) return null;
|
|
378
|
+
if (value >= 1e6) return `${(value / 1e6).toFixed(1)}M`;
|
|
379
|
+
if (value >= 1e3) return `${Math.floor(value / 1e3)}K`;
|
|
380
|
+
return `${Math.floor(value)}`;
|
|
381
|
+
}
|
|
382
|
+
/** Cells in the Context gauge: always rendered in full, so the bar never
|
|
383
|
+
* changes width between refreshes. With the space, the percent and the
|
|
384
|
+
* `of <window>` tail (at most 9 columns) the line stays inside 34 columns. */
|
|
385
|
+
const CONTEXT_BAR_CELLS = 12;
|
|
386
|
+
/** Filled cell (U+25B0) and empty cell (U+25B1), both single-width. */
|
|
387
|
+
const CONTEXT_BAR_FILLED_CELL = "▰";
|
|
388
|
+
const CONTEXT_BAR_EMPTY_CELL = "▱";
|
|
389
|
+
/** Filled cells for a percentage: rounded, clamped to `0..cells`, so 0% is an
|
|
390
|
+
* empty bar and anything at or above 100% is a full one. Pure. */
|
|
391
|
+
function contextBarFilled(percent, cells = 12) {
|
|
392
|
+
const total = Math.max(1, Math.floor(cells));
|
|
393
|
+
const filled = Math.round(percent / 100 * total);
|
|
394
|
+
if (!Number.isFinite(filled)) return 0;
|
|
395
|
+
return Math.min(total, Math.max(0, filled));
|
|
396
|
+
}
|
|
397
|
+
/** The gauge split into its toned half (filled cells) and its muted half (empty
|
|
398
|
+
* cells), so the caller colors each side. Null when the percentage is missing:
|
|
399
|
+
* the Context block then keeps its tokens + cost rows and renders no bar. Pure. */
|
|
400
|
+
function contextBar(percent, cells = 12) {
|
|
401
|
+
const value = numberOrNull(percent);
|
|
402
|
+
if (value === null) return null;
|
|
403
|
+
const total = Math.max(1, Math.floor(cells));
|
|
404
|
+
const filled = contextBarFilled(value, total);
|
|
405
|
+
return {
|
|
406
|
+
filled: "▰".repeat(filled),
|
|
407
|
+
empty: "▱".repeat(total - filled)
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
/** USD spent with two decimals (`$0.18`), the native block's format. Null for
|
|
411
|
+
* a missing/negative value. Pure. */
|
|
412
|
+
function formatSpent(cost) {
|
|
413
|
+
const value = numberOrNull(cost);
|
|
414
|
+
if (value === null || value < 0) return null;
|
|
415
|
+
return `$${value.toFixed(2)}`;
|
|
416
|
+
}
|
|
417
|
+
/** One rendered context row. `lead` and `tail` carry the gauge bar when the row
|
|
418
|
+
* has one (`lead` is toned with the value, `tail` is muted), so the 12 cells
|
|
419
|
+
* stay contiguous while the empty half still reads as background. */
|
|
420
|
+
/** The `Context` block's data rows; null rows are not rendered. */
|
|
421
|
+
/** Rows for the `Context` block:
|
|
422
|
+
* `<tokens> tokens` / `▰▰▰▰▰▱▱▱▱▱▱▱ <percent>% of <window>` /
|
|
423
|
+
* `$<spent> spent`. The percentage row carries the only semantic tone, the
|
|
424
|
+
* gauge bar (12 cells) and is omitted entirely when the percentage is
|
|
425
|
+
* unavailable (never `undefined%`). A block with neither tokens nor cost
|
|
426
|
+
* yields null. Pure. */
|
|
427
|
+
function contextBlockRows(usage, cost) {
|
|
428
|
+
const spentValue = formatSpent(cost);
|
|
429
|
+
const spent = spentValue === null ? null : {
|
|
430
|
+
lead: null,
|
|
431
|
+
value: spentValue,
|
|
432
|
+
tail: null,
|
|
433
|
+
suffix: " spent",
|
|
434
|
+
tone: null
|
|
435
|
+
};
|
|
436
|
+
if (usage === null) return spent === null ? null : {
|
|
437
|
+
tokens: null,
|
|
438
|
+
percent: null,
|
|
439
|
+
spent
|
|
440
|
+
};
|
|
441
|
+
const tokensValue = formatTokenCount(usage.tokens);
|
|
442
|
+
const tokens = tokensValue === null ? null : {
|
|
443
|
+
lead: null,
|
|
444
|
+
value: tokensValue,
|
|
445
|
+
tail: null,
|
|
446
|
+
suffix: " tokens",
|
|
447
|
+
tone: null
|
|
448
|
+
};
|
|
449
|
+
const percentValue = numberOrNull(usage.percent);
|
|
450
|
+
const window = formatContextWindow(usage.limit);
|
|
451
|
+
const bar = contextBar(percentValue);
|
|
452
|
+
const percent = bar === null || percentValue === null ? null : {
|
|
453
|
+
lead: bar.filled,
|
|
454
|
+
value: ` ${Math.round(percentValue)}%`,
|
|
455
|
+
tail: bar.empty,
|
|
456
|
+
suffix: window === null ? null : ` of ${window}`,
|
|
457
|
+
tone: contextUsageTone(percentValue)
|
|
458
|
+
};
|
|
459
|
+
if (tokens === null && percent === null && spent === null) return null;
|
|
460
|
+
return {
|
|
461
|
+
tokens,
|
|
462
|
+
percent,
|
|
463
|
+
spent
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
/** Models rendered in the Context block before the aggregate `… +N` line. */
|
|
467
|
+
const MODEL_USAGE_VISIBLE_CEILING = 3;
|
|
468
|
+
/** Newest messages read per session — bounds the O(n) walk on long sessions. */
|
|
469
|
+
const MODEL_USAGE_MESSAGE_LIMIT = 400;
|
|
470
|
+
/** Sessions read per family (root + delegations) for the aggregate. */
|
|
471
|
+
const MODEL_USAGE_SESSION_LIMIT = 8;
|
|
472
|
+
/** Column widths for one model row (labels are muted, numbers right-aligned). */
|
|
473
|
+
const MODEL_USAGE_MODEL_WIDTH = 12;
|
|
474
|
+
const MODEL_USAGE_TOKEN_WIDTH = 6;
|
|
475
|
+
const MODEL_USAGE_COST_WIDTH = 8;
|
|
476
|
+
/** Session events arrive in bursts; model rows are recomputed at most once
|
|
477
|
+
* per window (same cadence as the git-count revalidation). */
|
|
478
|
+
const MODEL_USAGE_DEBOUNCE_MS = 400;
|
|
479
|
+
/** Real usage for one model, summed across the assistant messages that used it. */
|
|
480
|
+
/** Totals per model from assistant messages: sums `cost` and `tokens`, drops
|
|
481
|
+
* models whose real cost is 0/absent, and orders by cost (then tokens, then
|
|
482
|
+
* name). `providerID` participates in the key so two providers exposing the
|
|
483
|
+
* same bare id are not merged. Pure. */
|
|
484
|
+
function collectModelUsage(messages) {
|
|
485
|
+
if (!Array.isArray(messages)) return [];
|
|
486
|
+
const totals = /* @__PURE__ */ new Map();
|
|
487
|
+
for (const message of messages) {
|
|
488
|
+
if (message?.type !== "assistant") continue;
|
|
489
|
+
const id = modelRefID(message.model);
|
|
490
|
+
const model = shortModelID(message.model, 12);
|
|
491
|
+
if (id === null || model === null) continue;
|
|
492
|
+
const key = `${typeof message.model?.providerID === "string" ? message.model.providerID : ""}\u0000${id}`;
|
|
493
|
+
const tokenCount = message.tokens ? messageTokensTotal(message.tokens) : 0;
|
|
494
|
+
const cost = numberOrNull(message.cost) ?? 0;
|
|
495
|
+
const current = totals.get(key);
|
|
496
|
+
if (current) {
|
|
497
|
+
current.tokens += Math.max(0, tokenCount);
|
|
498
|
+
current.cost += Math.max(0, cost);
|
|
499
|
+
} else totals.set(key, {
|
|
500
|
+
model,
|
|
501
|
+
tokens: Math.max(0, tokenCount),
|
|
502
|
+
cost: Math.max(0, cost)
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
return [...totals.values()].filter((row) => row.cost > 0).sort((a, b) => b.cost - a.cost || b.tokens - a.tokens || a.model.localeCompare(b.model));
|
|
506
|
+
}
|
|
507
|
+
/** Visible rows plus the aggregate of the models that did not fit. Pure. */
|
|
508
|
+
/** Cap the model list at `maxVisible`; the rest is aggregated (still real
|
|
509
|
+
* totals) for the `… +N` line. Pure. */
|
|
510
|
+
function ceilingModelUsage(rows, maxVisible = 3) {
|
|
511
|
+
const limit = Math.max(0, maxVisible);
|
|
512
|
+
const visible = rows.slice(0, limit);
|
|
513
|
+
const rest = rows.slice(visible.length);
|
|
514
|
+
return {
|
|
515
|
+
visible,
|
|
516
|
+
hidden: rest.length,
|
|
517
|
+
hiddenCost: rest.reduce((sum, row) => sum + row.cost, 0),
|
|
518
|
+
hiddenTokens: rest.reduce((sum, row) => sum + row.tokens, 0)
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
/** Compact tokens for a model row (`80,000` → `80K`); `0` stays explicit. Pure. */
|
|
522
|
+
function formatUsageTokens(tokens) {
|
|
523
|
+
const value = numberOrNull(tokens);
|
|
524
|
+
if (value === null || value <= 0) return "0";
|
|
525
|
+
return formatContextWindow(value) ?? String(Math.round(value));
|
|
526
|
+
}
|
|
527
|
+
/** Real per-model cost with adaptive precision: cents for `>= $0.01`, up to
|
|
528
|
+
* four decimals below that (a real `$0.0031` must not render as `$0.00`), and
|
|
529
|
+
* an explicit `< $0.0001` for the remainder. Pure. */
|
|
530
|
+
function formatUsageCost(cost) {
|
|
531
|
+
const value = numberOrNull(cost);
|
|
532
|
+
if (value === null || value < 0) return null;
|
|
533
|
+
if (value === 0) return "$0.00";
|
|
534
|
+
if (value >= .01) return `$${value.toFixed(2)}`;
|
|
535
|
+
if (value >= 1e-4) return `$${value.toFixed(4).replace(/0+$/, "").replace(/\.$/, "")}`;
|
|
536
|
+
return "<$0.0001";
|
|
537
|
+
}
|
|
538
|
+
/** One formatted model row: truncated label + compact tokens + real cost. */
|
|
539
|
+
/** Format the visible model rows for rendering. Labels are already short ids
|
|
540
|
+
* (12 chars); the second truncation only guards host drift. Pure. */
|
|
541
|
+
function modelUsageRows(rows) {
|
|
542
|
+
return rows.map((row) => ({
|
|
543
|
+
model: truncateLabel(row.model, 12),
|
|
544
|
+
tokens: formatUsageTokens(row.tokens),
|
|
545
|
+
cost: formatUsageCost(row.cost) ?? "$0.00"
|
|
546
|
+
}));
|
|
547
|
+
}
|
|
548
|
+
/** Exact single-line text of a model row, with numbers right-aligned. Pure. */
|
|
549
|
+
function modelUsageRowText(row) {
|
|
550
|
+
return `${row.model.padEnd(12)} ${row.tokens.padStart(6)} ${row.cost.padStart(8)}`;
|
|
551
|
+
}
|
|
552
|
+
/** Muted aggregate line for the models beyond the cap (`… +2 $0.03`). Null
|
|
553
|
+
* when every model fits. Pure. */
|
|
554
|
+
function hiddenModelUsageText(hidden, hiddenCost) {
|
|
555
|
+
if (!Number.isFinite(hidden) || hidden <= 0) return null;
|
|
556
|
+
const cost = formatUsageCost(hiddenCost);
|
|
557
|
+
return cost === null ? `… +${hidden}` : `… +${hidden} ${cost}`;
|
|
558
|
+
}
|
|
559
|
+
/** Bucket for a session the host published without an agent id. */
|
|
560
|
+
const UNKNOWN_AGENT = "?";
|
|
561
|
+
/** Agent key of a session or message: the trimmed id when it is a non-empty
|
|
562
|
+
* string, else the `?` bucket — never `undefined`. Pure. */
|
|
563
|
+
function agentKey(value) {
|
|
564
|
+
if (typeof value !== "string") return "?";
|
|
565
|
+
const text = value.trim();
|
|
566
|
+
return text === "" ? "?" : text;
|
|
567
|
+
}
|
|
568
|
+
/** One rendered todo row. `priority` is carried by the tool but not rendered:
|
|
569
|
+
* the reference block uses a single marker column. */
|
|
570
|
+
/** Rows rendered before the `… +N` line. */
|
|
571
|
+
const TODO_VISIBLE_CEILING = 6;
|
|
572
|
+
/** Content width before the ellipsis — the block has ~30-34 usable columns. */
|
|
573
|
+
const TODO_TEXT_WIDTH = 28;
|
|
574
|
+
/** Row markers (`•` in progress, `−` cancelled with U+2212, as in the git row). */
|
|
575
|
+
const TODO_MARKERS = {
|
|
576
|
+
in_progress: "[•]",
|
|
577
|
+
pending: "[ ]",
|
|
578
|
+
completed: "[x]",
|
|
579
|
+
cancelled: "[−]"
|
|
580
|
+
};
|
|
581
|
+
/** Group order: live work first, then open, then closed. */
|
|
582
|
+
const TODO_STATUS_ORDER = [
|
|
583
|
+
"in_progress",
|
|
584
|
+
"pending",
|
|
585
|
+
"completed",
|
|
586
|
+
"cancelled"
|
|
587
|
+
];
|
|
588
|
+
/** Narrow a loose `status` value to the tool's four states. */
|
|
589
|
+
function isTodoStatus(value) {
|
|
590
|
+
return value === "in_progress" || value === "pending" || value === "completed" || value === "cancelled";
|
|
591
|
+
}
|
|
592
|
+
/** Items from a `todowrite` `input` payload. A missing/malformed `input`,
|
|
593
|
+
* absent `todos`, an unknown `status` or an empty/missing `content` drops the
|
|
594
|
+
* entry instead of throwing; a list with nothing readable yields `[]`. Pure. */
|
|
595
|
+
function parseTodoItems(input) {
|
|
596
|
+
const raw = input?.todos;
|
|
597
|
+
if (!Array.isArray(raw)) return [];
|
|
598
|
+
const items = [];
|
|
599
|
+
for (const entry of raw) {
|
|
600
|
+
const content = entry?.content;
|
|
601
|
+
const status = entry?.status;
|
|
602
|
+
if (typeof content !== "string" || content.trim() === "") continue;
|
|
603
|
+
if (!isTodoStatus(status)) continue;
|
|
604
|
+
items.push({
|
|
605
|
+
content: content.trim(),
|
|
606
|
+
status
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
return items;
|
|
610
|
+
}
|
|
611
|
+
/** Newest completed `todowrite` in a transcript. The tool replaces the list
|
|
612
|
+
* wholesale, so the last write wins; a write with `todos: []` returns null
|
|
613
|
+
* (the block disappears rather than showing the previous list) and a
|
|
614
|
+
* not-yet-completed write is ignored. Null when the transcript carries no
|
|
615
|
+
* such part, so the block never renders a guess. Pure. */
|
|
616
|
+
function latestTodoItems(messages) {
|
|
617
|
+
if (!Array.isArray(messages)) return null;
|
|
618
|
+
for (let index = messages.length - 1; index >= 0; index--) {
|
|
619
|
+
const message = messages[index];
|
|
620
|
+
if (message?.type !== "assistant" || !Array.isArray(message.content)) continue;
|
|
621
|
+
const parts = message.content;
|
|
622
|
+
for (let position = parts.length - 1; position >= 0; position--) {
|
|
623
|
+
const part = parts[position];
|
|
624
|
+
if (part?.type !== "tool" || part?.name !== "todowrite") continue;
|
|
625
|
+
if (part?.state?.status !== "completed") continue;
|
|
626
|
+
const items = parseTodoItems(part.state.input);
|
|
627
|
+
return items.length === 0 ? null : items;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
return null;
|
|
631
|
+
}
|
|
632
|
+
/** Stable group order (in_progress → pending → completed → cancelled); within a
|
|
633
|
+
* group the transcript order is preserved. Pure. */
|
|
634
|
+
function orderTodoItems(items) {
|
|
635
|
+
return [...items].sort((a, b) => TODO_STATUS_ORDER.indexOf(a.status) - TODO_STATUS_ORDER.indexOf(b.status));
|
|
636
|
+
}
|
|
637
|
+
/** Row color channel: `accent` for live work, `muted` for closed items, base
|
|
638
|
+
* for pending. Kept separate from the theme so it is testable. Pure. */
|
|
639
|
+
/** Tone for one status — no rainbow, a single accent. Pure. */
|
|
640
|
+
function todoTone(status) {
|
|
641
|
+
if (status === "in_progress") return "accent";
|
|
642
|
+
if (status === "completed" || status === "cancelled") return "muted";
|
|
643
|
+
return "base";
|
|
644
|
+
}
|
|
645
|
+
/** Exact rendered text of one row: `[•] <content truncated to 28>`. Pure. */
|
|
646
|
+
function todoRowText(item) {
|
|
647
|
+
return `${TODO_MARKERS[item.status]} ${truncateLabel(item.content, 28)}`;
|
|
648
|
+
}
|
|
649
|
+
/** Ordered rows capped for the sidebar, plus how many did not fit. Pure. */
|
|
650
|
+
/** Order then cap the list at `maxVisible`. Pure. */
|
|
651
|
+
function ceilingTodoItems(items, maxVisible = 6) {
|
|
652
|
+
const ordered = orderTodoItems(items);
|
|
653
|
+
const visible = ordered.slice(0, Math.max(0, maxVisible));
|
|
654
|
+
return {
|
|
655
|
+
visible,
|
|
656
|
+
hidden: Math.max(0, ordered.length - visible.length)
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
/** Overflow line (`… +3`); null when every item fits. Pure. */
|
|
660
|
+
function hiddenTodoText(hidden) {
|
|
661
|
+
if (!Number.isFinite(hidden) || hidden <= 0) return null;
|
|
662
|
+
return `… +${Math.round(hidden)}`;
|
|
663
|
+
}
|
|
664
|
+
/** Narrow a `VcsFileStatus["status"]` value read off a loose payload. */
|
|
665
|
+
function isGitChangeStatus(value) {
|
|
666
|
+
return value === "added" || value === "modified" || value === "deleted";
|
|
667
|
+
}
|
|
668
|
+
/** Files per status from a `VcsFileStatus[]` payload. Unknown statuses and
|
|
669
|
+
* malformed entries are ignored. Pure. */
|
|
670
|
+
function countGitChanges(files) {
|
|
671
|
+
const counts = {
|
|
672
|
+
added: 0,
|
|
673
|
+
modified: 0,
|
|
674
|
+
deleted: 0
|
|
675
|
+
};
|
|
676
|
+
if (!Array.isArray(files)) return counts;
|
|
677
|
+
for (const entry of files) {
|
|
678
|
+
const status = entry?.status;
|
|
679
|
+
if (isGitChangeStatus(status)) counts[status] += 1;
|
|
680
|
+
}
|
|
681
|
+
return counts;
|
|
682
|
+
}
|
|
683
|
+
/** `+1 ±2 −3` for the file counts; each zero term is omitted, and an empty
|
|
684
|
+
* change set returns null so the row is not rendered at all. Pure. */
|
|
685
|
+
function formatGitChanges(files) {
|
|
686
|
+
const { added, modified, deleted } = countGitChanges(files);
|
|
687
|
+
const parts = [];
|
|
688
|
+
if (added > 0) parts.push(`+${added}`);
|
|
689
|
+
if (modified > 0) parts.push(`±${modified}`);
|
|
690
|
+
if (deleted > 0) parts.push(`\u2212${deleted}`);
|
|
691
|
+
return parts.length === 0 ? null : parts.join(" ");
|
|
692
|
+
}
|
|
693
|
+
/** Wall-clock ceiling for one git call. A stuck git (index lock, network
|
|
694
|
+
* filesystem) is killed instead of holding the row forever. */
|
|
695
|
+
const GIT_CLI_TIMEOUT_MS = 2e3;
|
|
696
|
+
/** Session events arrive in bursts; a git probe is scheduled at most once per
|
|
697
|
+
* window instead of once per event. */
|
|
698
|
+
const GIT_CLI_DEBOUNCE_MS = 1e3;
|
|
699
|
+
/** Minimum spacing between two probe starts. Five seconds keeps a chatty event
|
|
700
|
+
* stream from spawning a git process per step while staying fresh enough to
|
|
701
|
+
* show a file appearing mid-turn. */
|
|
702
|
+
const GIT_CLI_MIN_INTERVAL_MS = 5e3;
|
|
703
|
+
/** Stdout ceiling for one git call. `status --porcelain=v1 -uall` lists every
|
|
704
|
+
* untracked file, so a large worktree easily passes the 1 MB `execFile`
|
|
705
|
+
* default — which would reject and silently hand the row back to the
|
|
706
|
+
* `vcs.status` fallback. 4 MB is far above a realistic porcelain listing. */
|
|
707
|
+
const GIT_CLI_MAX_BUFFER = 4194304;
|
|
708
|
+
/** One `execFile` call: `(file, args, options) → { stdout }`. Injectable so the
|
|
709
|
+
* parsing/gating logic is testable without spawning processes. */
|
|
710
|
+
/** Default runner: the promisified `node:child_process.execFile`. A non-zero
|
|
711
|
+
* exit (no repository, no upstream) rejects and the caller decides. */
|
|
712
|
+
const defaultGitExec = (file, args, options) => new Promise((resolve, reject) => {
|
|
713
|
+
execFile(file, [...args], {
|
|
714
|
+
cwd: options.cwd,
|
|
715
|
+
timeout: options.timeout,
|
|
716
|
+
windowsHide: options.windowsHide,
|
|
717
|
+
maxBuffer: options.maxBuffer
|
|
718
|
+
}, (error, stdout) => {
|
|
719
|
+
if (error) reject(error);
|
|
720
|
+
else resolve({ stdout: typeof stdout === "string" ? stdout : String(stdout ?? "") });
|
|
721
|
+
});
|
|
722
|
+
});
|
|
723
|
+
/** Files per status from `git status --porcelain=v1 -uall`, including the two
|
|
724
|
+
* columns the protocol cannot report. Each line starts with `XY` (index and
|
|
725
|
+
* worktree state); a rename prints `R old -> new`, and `??` / `!!` are
|
|
726
|
+
* untracked / ignored. Precedence per file: deleted > added > modified, so
|
|
727
|
+
* `AM` counts once as added and `AD` once as deleted. Renames, copies and
|
|
728
|
+
* unmerged entries count as modified. Pure. */
|
|
729
|
+
/** Parse porcelain v1 output into file counts. Empty/malformed output yields
|
|
730
|
+
* zero counts (a clean tree), never a throw. Pure. */
|
|
731
|
+
function parseGitStatusPorcelain(output) {
|
|
732
|
+
const counts = {
|
|
733
|
+
added: 0,
|
|
734
|
+
modified: 0,
|
|
735
|
+
deleted: 0,
|
|
736
|
+
untracked: 0
|
|
737
|
+
};
|
|
738
|
+
if (typeof output !== "string" || output === "") return counts;
|
|
739
|
+
for (const line of output.split("\n")) {
|
|
740
|
+
if (line.length < 2) continue;
|
|
741
|
+
const index = line[0];
|
|
742
|
+
const worktree = line[1];
|
|
743
|
+
if (index === "!" && worktree === "!") continue;
|
|
744
|
+
if (index === "?" && worktree === "?") {
|
|
745
|
+
counts.untracked += 1;
|
|
746
|
+
continue;
|
|
747
|
+
}
|
|
748
|
+
if (index === " " && worktree === " ") continue;
|
|
749
|
+
if (index === "D" || worktree === "D") counts.deleted += 1;
|
|
750
|
+
else if (index === "A" || worktree === "A") counts.added += 1;
|
|
751
|
+
else counts.modified += 1;
|
|
752
|
+
}
|
|
753
|
+
return counts;
|
|
754
|
+
}
|
|
755
|
+
/** `git rev-list --count --left-right @{upstream}...HEAD` prints two numbers:
|
|
756
|
+
* commits only on the upstream (behind) then commits only on HEAD (ahead).
|
|
757
|
+
* Null when the output is not that pair — e.g. the command failed because the
|
|
758
|
+
* branch has no upstream, in which case the arrows are simply omitted. Pure. */
|
|
759
|
+
function parseGitAheadBehind(output) {
|
|
760
|
+
if (typeof output !== "string") return null;
|
|
761
|
+
const match = /^\s*(\d+)\s+(\d+)\s*$/.exec(output);
|
|
762
|
+
if (match === null) return null;
|
|
763
|
+
const behind = Number(match[1]);
|
|
764
|
+
const ahead = Number(match[2]);
|
|
765
|
+
if (!Number.isFinite(ahead) || !Number.isFinite(behind)) return null;
|
|
766
|
+
return {
|
|
767
|
+
ahead,
|
|
768
|
+
behind
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
/** One git observation: file counts plus the upstream distance (either arrow
|
|
772
|
+
* may be unknown when the branch has no upstream). */
|
|
773
|
+
/** One probe: `git status --porcelain=v1 -uall` for the counts, then
|
|
774
|
+
* `git rev-list --count --left-right @{upstream}...HEAD` for the arrows (a
|
|
775
|
+
* failure there only drops the arrows). A status failure rejects — the caller
|
|
776
|
+
* then falls back to `client.vcs.status`. */
|
|
777
|
+
async function readGitSnapshot(directory, exec = defaultGitExec) {
|
|
778
|
+
const options = {
|
|
779
|
+
cwd: directory,
|
|
780
|
+
timeout: GIT_CLI_TIMEOUT_MS,
|
|
781
|
+
windowsHide: true,
|
|
782
|
+
maxBuffer: GIT_CLI_MAX_BUFFER
|
|
783
|
+
};
|
|
784
|
+
const changes = parseGitStatusPorcelain((await exec("git", [
|
|
785
|
+
"status",
|
|
786
|
+
"--porcelain=v1",
|
|
787
|
+
"-uall"
|
|
788
|
+
], options))?.stdout);
|
|
789
|
+
let ahead = null;
|
|
790
|
+
let behind = null;
|
|
791
|
+
try {
|
|
792
|
+
const parsed = parseGitAheadBehind((await exec("git", [
|
|
793
|
+
"rev-list",
|
|
794
|
+
"--count",
|
|
795
|
+
"--left-right",
|
|
796
|
+
"@{upstream}...HEAD"
|
|
797
|
+
], options))?.stdout);
|
|
798
|
+
if (parsed !== null) {
|
|
799
|
+
ahead = parsed.ahead;
|
|
800
|
+
behind = parsed.behind;
|
|
801
|
+
}
|
|
802
|
+
} catch {}
|
|
803
|
+
return {
|
|
804
|
+
changes,
|
|
805
|
+
ahead,
|
|
806
|
+
behind
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
/** Rendered git row: `+1 ±2 −1 ?2 ↑3 ↓1`, zero terms omitted. Null when the
|
|
810
|
+
* tree is clean and in sync, so the block keeps only its branch line. Pure. */
|
|
811
|
+
function formatGitSnapshot(snapshot) {
|
|
812
|
+
if (!snapshot?.changes) return null;
|
|
813
|
+
const { added, modified, deleted, untracked } = snapshot.changes;
|
|
814
|
+
const parts = [];
|
|
815
|
+
if (added > 0) parts.push(`+${added}`);
|
|
816
|
+
if (modified > 0) parts.push(`±${modified}`);
|
|
817
|
+
if (deleted > 0) parts.push(`\u2212${deleted}`);
|
|
818
|
+
if (untracked > 0) parts.push(`?${untracked}`);
|
|
819
|
+
if ((snapshot.ahead ?? 0) > 0) parts.push(`↑${snapshot.ahead}`);
|
|
820
|
+
if ((snapshot.behind ?? 0) > 0) parts.push(`↓${snapshot.behind}`);
|
|
821
|
+
return parts.length === 0 ? null : parts.join(" ");
|
|
822
|
+
}
|
|
823
|
+
/** Whether a new probe may start. An in-flight probe always wins (no queue), and
|
|
824
|
+
* the previous start must be older than the cooldown. Pure. */
|
|
825
|
+
function gitProbeAllowed(state, cooldownMs = GIT_CLI_MIN_INTERVAL_MS) {
|
|
826
|
+
if (state.inFlight) return false;
|
|
827
|
+
if (state.lastRunAt === null) return true;
|
|
828
|
+
const elapsed = state.now - state.lastRunAt;
|
|
829
|
+
return !Number.isFinite(elapsed) || elapsed >= cooldownMs;
|
|
830
|
+
}
|
|
831
|
+
/** Spend window labels, in render order. */
|
|
832
|
+
const SPEND_TODAY_LABEL = "hoje";
|
|
833
|
+
const SPEND_30D_LABEL = "30d";
|
|
834
|
+
/** Separator between the two windows on the Context footer line. */
|
|
835
|
+
const SPEND_LINE_SEPARATOR = " · ";
|
|
836
|
+
/** `30d` window: 30 × 24 h, measured back from "now". */
|
|
837
|
+
const SPEND_30D_MS = 2592e6;
|
|
838
|
+
/** Probe window: one hour, narrow enough that a unit mix-up cannot line up. */
|
|
839
|
+
const SPEND_PROBE_WINDOW_MS = 36e5;
|
|
840
|
+
/** The echoed `range` may be rounded server-side; 120 s absorbs that. */
|
|
841
|
+
const SPEND_PROBE_TOLERANCE_MS = 12e4;
|
|
842
|
+
/** Session events arrive in bursts — same 400 ms window as the other blocks. */
|
|
843
|
+
const SPEND_REFRESH_DEBOUNCE_MS = 400;
|
|
844
|
+
/** Spend per window in USD. Either side may be unknown (kept `null`). */
|
|
845
|
+
/** `from`/`to` unit accepted by the route. `SessionStatsInput` declares both as
|
|
846
|
+
* bare `number` and does not say which unit, so it is measured once per
|
|
847
|
+
* process (`ms` unless the server echoes seconds) instead of guessed. */
|
|
848
|
+
/** Resolved unit for this process; `null` until the mount probe answers. */
|
|
849
|
+
let spendUnit = null;
|
|
850
|
+
/** In-flight probe, so two refreshes cannot each burn the 2-call budget. */
|
|
851
|
+
let spendProbe = null;
|
|
852
|
+
/** Test-only: forget the process-wide unit resolution. Never called at runtime. */
|
|
853
|
+
function resetSpendUnit() {
|
|
854
|
+
spendUnit = null;
|
|
855
|
+
spendProbe = null;
|
|
856
|
+
}
|
|
857
|
+
/** Resolved unit (`ms` / `s` / `unavailable`) or null while still unknown. */
|
|
858
|
+
function resolvedSpendUnit() {
|
|
859
|
+
return spendUnit;
|
|
860
|
+
}
|
|
861
|
+
/** Local midnight for `now`: `new Date()` with the clock fields zeroed in the
|
|
862
|
+
* current timezone (DST-safe, unlike subtracting hours). Pure. */
|
|
863
|
+
function startOfLocalDay(now) {
|
|
864
|
+
const date = new Date(now);
|
|
865
|
+
date.setHours(0, 0, 0, 0);
|
|
866
|
+
return date.getTime();
|
|
867
|
+
}
|
|
868
|
+
/** The two windows the block shows: `hoje` (local midnight → now) and `30d`
|
|
869
|
+
* (now − 30 days → now). Pure. */
|
|
870
|
+
function spendWindows(now) {
|
|
871
|
+
return {
|
|
872
|
+
today: {
|
|
873
|
+
from: startOfLocalDay(now),
|
|
874
|
+
to: now
|
|
875
|
+
},
|
|
876
|
+
thirtyDays: {
|
|
877
|
+
from: now - SPEND_30D_MS,
|
|
878
|
+
to: now
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
/** USD with two decimals (`$0.42`), four for a positive sub-cent amount
|
|
883
|
+
* (`$0.0031`), and `<$0.0001` when even four decimals would read `$0.0000`.
|
|
884
|
+
* `0` prints `$0.00`. Null for a missing/negative/non-finite value. Pure. */
|
|
885
|
+
function formatSpendUSD(cost) {
|
|
886
|
+
const value = numberOrNull(cost);
|
|
887
|
+
if (value === null || value < 0) return null;
|
|
888
|
+
if (value === 0) return "$0.00";
|
|
889
|
+
if (value >= .01) return `$${value.toFixed(2)}`;
|
|
890
|
+
const cents = value.toFixed(2);
|
|
891
|
+
if (cents !== "0.00") return `$${cents}`;
|
|
892
|
+
const cents4 = value.toFixed(4);
|
|
893
|
+
return cents4 === "0.0000" ? "<$0.0001" : `$${cents4}`;
|
|
894
|
+
}
|
|
895
|
+
/** `cost` off a `SessionStatsInfo` (`MoneyUSD` = number) or null when the
|
|
896
|
+
* payload is malformed/negative, so a bad value never reaches a row. Pure. */
|
|
897
|
+
function statsCost(result) {
|
|
898
|
+
const cost = numberOrNull(result?.cost);
|
|
899
|
+
return cost !== null && cost >= 0 ? cost : null;
|
|
900
|
+
}
|
|
901
|
+
/** True when the server echoed the window we sent, within 120 s. `scale` is how
|
|
902
|
+
* many milliseconds one unit of the sent window is worth (`1` for `ms`, `1000`
|
|
903
|
+
* for `s`). The echo is accepted either as the same numbers we sent (the route
|
|
904
|
+
* keeps the caller's unit) or converted to millisecond epoch (`DateTime.Utc`),
|
|
905
|
+
* so the probe pins the unit without assuming which of the two it gets. Pure. */
|
|
906
|
+
function statsRangeMatches(range, sent, scale) {
|
|
907
|
+
const from = numberOrNull(range?.from);
|
|
908
|
+
const to = numberOrNull(range?.to);
|
|
909
|
+
if (from === null || to === null) return false;
|
|
910
|
+
const tolerance = SPEND_PROBE_TOLERANCE_MS / scale;
|
|
911
|
+
const sameUnit = Math.abs(from - sent.from) <= tolerance && Math.abs(to - sent.to) <= tolerance;
|
|
912
|
+
const asMilliseconds = Math.abs(from - sent.from * scale) <= 12e4 && Math.abs(to - sent.to * scale) <= 12e4;
|
|
913
|
+
return sameUnit || asMilliseconds;
|
|
914
|
+
}
|
|
915
|
+
/** The `Context` block's last line: both spend windows on one muted row
|
|
916
|
+
* (`hoje $0.42 · 30d $9.80`). A window without a usable amount is omitted, and
|
|
917
|
+
* no usable window at all yields null so the line (and not the block) is
|
|
918
|
+
* dropped. Pure. */
|
|
919
|
+
function contextSpendLine(totals) {
|
|
920
|
+
if (totals === null) return null;
|
|
921
|
+
const parts = [];
|
|
922
|
+
const today = formatSpendUSD(totals.today);
|
|
923
|
+
if (today !== null) parts.push(`${SPEND_TODAY_LABEL} ${today}`);
|
|
924
|
+
const thirtyDays = formatSpendUSD(totals.thirtyDays);
|
|
925
|
+
if (thirtyDays !== null) parts.push(`30d ${thirtyDays}`);
|
|
926
|
+
return parts.length === 0 ? null : parts.join(SPEND_LINE_SEPARATOR);
|
|
927
|
+
}
|
|
928
|
+
/** Grapheme iterator: a cut never splits a surrogate pair, a combining mark
|
|
929
|
+
* from its base or a ZWJ emoji sequence, so truncation stays cell-exact. */
|
|
930
|
+
const GRAPHEMES = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
931
|
+
/** A grapheme the host draws two cells wide: emoji presentation, an extended
|
|
932
|
+
* pictograph (a bare `❤` counts too, exactly as the host's `emoji-regex`
|
|
933
|
+
* does) and a regional-indicator pair (a flag). */
|
|
934
|
+
const EMOJI_GLYPH = /\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{Regional_Indicator}/u;
|
|
935
|
+
/** VS16 asks for emoji presentation; without it `1` is one cell, with it the
|
|
936
|
+
* keycap sequence is drawn as one two-cell glyph. */
|
|
937
|
+
const EMOJI_PRESENTATION_SELECTOR = "️";
|
|
938
|
+
/** Unicode default-ignorable code points carry no width of their own. */
|
|
939
|
+
const IGNORABLE_GLYPH = /^\p{Default_Ignorable_Code_Point}$/u;
|
|
940
|
+
/** East Asian Wide/Fullwidth ranges — two cells, never the ambiguous width
|
|
941
|
+
* (the host measures ambiguous as narrow, so `▸`/`✓`/`—` stay one cell).
|
|
942
|
+
* Generated from the host's own measurement (`string-width` over every code
|
|
943
|
+
* point, emoji excluded), so this table can be regenerated verbatim when the
|
|
944
|
+
* host upgrades its Unicode data instead of being hand-edited. */
|
|
945
|
+
const CELL_WIDE_RANGES = [
|
|
946
|
+
[4352, 4446],
|
|
947
|
+
[9001, 9002],
|
|
948
|
+
[9776, 9783],
|
|
949
|
+
[9866, 9871],
|
|
950
|
+
[11904, 11929],
|
|
951
|
+
[11931, 12019],
|
|
952
|
+
[12032, 12245],
|
|
953
|
+
[12272, 12335],
|
|
954
|
+
[12337, 12348],
|
|
955
|
+
[12350, 12350],
|
|
956
|
+
[12353, 12438],
|
|
957
|
+
[12441, 12543],
|
|
958
|
+
[12549, 12591],
|
|
959
|
+
[12593, 12643],
|
|
960
|
+
[12645, 12686],
|
|
961
|
+
[12688, 12773],
|
|
962
|
+
[12783, 12830],
|
|
963
|
+
[12832, 12871],
|
|
964
|
+
[12880, 12950],
|
|
965
|
+
[12952, 12952],
|
|
966
|
+
[12954, 42124],
|
|
967
|
+
[42128, 42182],
|
|
968
|
+
[43360, 43388],
|
|
969
|
+
[44032, 55203],
|
|
970
|
+
[63744, 64255],
|
|
971
|
+
[65040, 65049],
|
|
972
|
+
[65072, 65106],
|
|
973
|
+
[65108, 65126],
|
|
974
|
+
[65128, 65131],
|
|
975
|
+
[65281, 65376],
|
|
976
|
+
[65504, 65510],
|
|
977
|
+
[94176, 94180],
|
|
978
|
+
[94192, 94198],
|
|
979
|
+
[94208, 101594],
|
|
980
|
+
[101631, 101664],
|
|
981
|
+
[101760, 101874],
|
|
982
|
+
[101888, 102801],
|
|
983
|
+
[102816, 102866],
|
|
984
|
+
[110576, 110579],
|
|
985
|
+
[110581, 110587],
|
|
986
|
+
[110589, 110590],
|
|
987
|
+
[110592, 110888],
|
|
988
|
+
[110898, 110898],
|
|
989
|
+
[110928, 110930],
|
|
990
|
+
[110933, 110933],
|
|
991
|
+
[110948, 110952],
|
|
992
|
+
[110960, 111355],
|
|
993
|
+
[119552, 119638],
|
|
994
|
+
[119648, 119670],
|
|
995
|
+
[127488, 127488],
|
|
996
|
+
[127504, 127513],
|
|
997
|
+
[127515, 127534],
|
|
998
|
+
[127536, 127537],
|
|
999
|
+
[127547, 127547],
|
|
1000
|
+
[127552, 127560],
|
|
1001
|
+
[127584, 127589],
|
|
1002
|
+
[131072, 196605],
|
|
1003
|
+
[196608, 262141]
|
|
1004
|
+
];
|
|
1005
|
+
/** One code point the terminal draws no cell for: control characters, the
|
|
1006
|
+
* zero-width joiners/marks, combining marks and variation selectors. */
|
|
1007
|
+
function isZeroWidthCodePoint(code, glyph) {
|
|
1008
|
+
if (code <= 31 || code >= 127 && code <= 159) return true;
|
|
1009
|
+
if (code >= 8203 && code <= 8207) return true;
|
|
1010
|
+
if (code === 65279) return true;
|
|
1011
|
+
if (code >= 768 && code <= 879) return true;
|
|
1012
|
+
if (code >= 6832 && code <= 6911) return true;
|
|
1013
|
+
if (code >= 7616 && code <= 7679) return true;
|
|
1014
|
+
if (code >= 8400 && code <= 8447) return true;
|
|
1015
|
+
if (code >= 65024 && code <= 65039) return true;
|
|
1016
|
+
if (code >= 65056 && code <= 65071) return true;
|
|
1017
|
+
if (code >= 917760 && code <= 917999) return true;
|
|
1018
|
+
if (code >= 55296 && code <= 57343) return true;
|
|
1019
|
+
return IGNORABLE_GLYPH.test(glyph);
|
|
1020
|
+
}
|
|
1021
|
+
function isWideCodePoint(code) {
|
|
1022
|
+
for (const [low, high] of CELL_WIDE_RANGES) {
|
|
1023
|
+
if (code < low) return false;
|
|
1024
|
+
if (code <= high) return true;
|
|
1025
|
+
}
|
|
1026
|
+
return false;
|
|
1027
|
+
}
|
|
1028
|
+
/** Cells one grapheme occupies. */
|
|
1029
|
+
function graphemeWidth(segment) {
|
|
1030
|
+
if (EMOJI_GLYPH.test(segment)) return 2;
|
|
1031
|
+
if (segment.length > 1 && segment.includes(EMOJI_PRESENTATION_SELECTOR)) return 2;
|
|
1032
|
+
let width = 0;
|
|
1033
|
+
for (const glyph of segment) {
|
|
1034
|
+
const code = glyph.codePointAt(0) ?? 0;
|
|
1035
|
+
if (isZeroWidthCodePoint(code, glyph)) continue;
|
|
1036
|
+
width += isWideCodePoint(code) ? 2 : 1;
|
|
1037
|
+
}
|
|
1038
|
+
return width;
|
|
1039
|
+
}
|
|
1040
|
+
/** Terminal cells `value` occupies — the unit every column in this plugin is
|
|
1041
|
+
* measured in. Mirrors the host (that is how `@opentui/core` sizes a text
|
|
1042
|
+
* run): emoji count as two cells, East Asian Wide/Fullwidth as two, East
|
|
1043
|
+
* Asian Ambiguous as one, combining marks and variation selectors as none.
|
|
1044
|
+
* Pure. */
|
|
1045
|
+
function cellWidth(value) {
|
|
1046
|
+
let width = 0;
|
|
1047
|
+
for (const { segment } of GRAPHEMES.segment(value)) width += graphemeWidth(segment);
|
|
1048
|
+
return width;
|
|
1049
|
+
}
|
|
1050
|
+
/** Clamp a free-form label to `max` terminal cells without wrapping. The width
|
|
1051
|
+
* is measured in display cells, never in UTF-16 code units: a CJK or emoji
|
|
1052
|
+
* label used to overflow the column it was cut for (`計画の移行` is 5 code
|
|
1053
|
+
* units but 10 cells, `🚀` is 2 units and 2 cells). Pure. */
|
|
1054
|
+
function truncateLabel(value, max = 28) {
|
|
1055
|
+
const text = value.trim();
|
|
1056
|
+
const budget = Math.max(1, Math.floor(numberOrNull(max) ?? 1));
|
|
1057
|
+
if (cellWidth(text) <= budget) return text;
|
|
1058
|
+
const ellipsis = "…";
|
|
1059
|
+
const room = budget - cellWidth(ellipsis);
|
|
1060
|
+
let cut = "";
|
|
1061
|
+
let used = 0;
|
|
1062
|
+
for (const { segment } of GRAPHEMES.segment(text)) {
|
|
1063
|
+
const width = cellWidth(segment);
|
|
1064
|
+
if (used + width > room) break;
|
|
1065
|
+
cut += segment;
|
|
1066
|
+
used += width;
|
|
1067
|
+
}
|
|
1068
|
+
return `${cut.replace(/\s+$/, "")}${ellipsis}`;
|
|
1069
|
+
}
|
|
1070
|
+
/** Right-pad `value` with spaces to exactly `cells` display columns (a wider
|
|
1071
|
+
* value is truncated first). `padEnd` counts code units, so it under-pads a
|
|
1072
|
+
* CJK/emoji cell and the next column drifts. Pure. */
|
|
1073
|
+
function padCell(value, cells) {
|
|
1074
|
+
const width = Math.max(0, Math.floor(numberOrNull(cells) ?? 0));
|
|
1075
|
+
if (width === 0) return "";
|
|
1076
|
+
const text = truncateLabel(value, width);
|
|
1077
|
+
return `${text}${" ".repeat(Math.max(0, width - cellWidth(text)))}`;
|
|
1078
|
+
}
|
|
1079
|
+
/** Columns the fixed header may use before it would wrap the sidebar. */
|
|
1080
|
+
const HEADER_MAX_WIDTH = 34;
|
|
1081
|
+
/** Preset row of the fixed header: `▸ <preset> · <provider>`. The provider is
|
|
1082
|
+
* cut first when the row overflows, so the preset name is never the casualty;
|
|
1083
|
+
* a missing provider leaves the preset alone (no `unknown` placeholder). */
|
|
1084
|
+
function presetHeaderLine(presetName, providerID) {
|
|
1085
|
+
const base = `▸ ${presetName.trim() === "" ? "default" : presetName.trim()}`;
|
|
1086
|
+
const provider = providerID === null ? "" : providerID.trim();
|
|
1087
|
+
if (provider === "") return truncateLabel(base, 34);
|
|
1088
|
+
const room = 34 - `${base} · `.length;
|
|
1089
|
+
if (room < 2) return truncateLabel(base, 34);
|
|
1090
|
+
return `${base} · ${truncateLabel(provider, room)}`;
|
|
1091
|
+
}
|
|
1092
|
+
/** One classification plus the evidence that produced it. */
|
|
1093
|
+
/** Bracketed description prefix → short label (`[council]` → `coun`). */
|
|
1094
|
+
const DISPATCH_PREFIX_KINDS = [
|
|
1095
|
+
["council", "coun"],
|
|
1096
|
+
["discovery", "disc"],
|
|
1097
|
+
["hotfix", "hot"],
|
|
1098
|
+
["plan", "plan"],
|
|
1099
|
+
["review", "revw"]
|
|
1100
|
+
];
|
|
1101
|
+
/** Agent → kind, consulted only when the description declares no prefix.
|
|
1102
|
+
* `council` is deliberately absent — see the section comment. */
|
|
1103
|
+
const DISPATCH_AGENT_KINDS = {
|
|
1104
|
+
apollo: "disc",
|
|
1105
|
+
athena: "plan",
|
|
1106
|
+
talos: "hot",
|
|
1107
|
+
themis: "revw"
|
|
1108
|
+
};
|
|
1109
|
+
/** Kind declared by a leading `[prefix]` on the description: case-insensitive
|
|
1110
|
+
* and tolerant of spaces inside the brackets. Null when none is declared. */
|
|
1111
|
+
function dispatchKindFromPrefix(description) {
|
|
1112
|
+
if (typeof description !== "string") return null;
|
|
1113
|
+
const match = /^\s*\[\s*([a-z]+)\s*\]/i.exec(description);
|
|
1114
|
+
if (match === null) return null;
|
|
1115
|
+
const token = (match[1] ?? "").toLowerCase();
|
|
1116
|
+
for (const [word, kind] of DISPATCH_PREFIX_KINDS) if (word === token) return kind;
|
|
1117
|
+
return null;
|
|
1118
|
+
}
|
|
1119
|
+
/** Kind implied by the child's agent, null for an agent that implies none. */
|
|
1120
|
+
function dispatchKindFromAgent(agent) {
|
|
1121
|
+
if (typeof agent !== "string") return null;
|
|
1122
|
+
return DISPATCH_AGENT_KINDS[agent.trim().toLowerCase()] ?? null;
|
|
1123
|
+
}
|
|
1124
|
+
/** Classify one dispatch. The description prefix always wins over the agent;
|
|
1125
|
+
* otherwise the agent decides, and anything else is `oth` (a real dispatch we
|
|
1126
|
+
* simply cannot name). A missing call is the only `unavailable` outcome. Pure. */
|
|
1127
|
+
function classifyDispatchKind(call) {
|
|
1128
|
+
if (call === null || call === void 0) return {
|
|
1129
|
+
kind: null,
|
|
1130
|
+
origin: "unavailable"
|
|
1131
|
+
};
|
|
1132
|
+
const fromPrefix = dispatchKindFromPrefix(call.description);
|
|
1133
|
+
if (fromPrefix !== null) return {
|
|
1134
|
+
kind: fromPrefix,
|
|
1135
|
+
origin: "prefix"
|
|
1136
|
+
};
|
|
1137
|
+
return {
|
|
1138
|
+
kind: dispatchKindFromAgent(call.agent) ?? "oth",
|
|
1139
|
+
origin: "agent"
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
/** A `subagent` tool call the parent made, as its own transcript records it. */
|
|
1143
|
+
/** Host tool that spawns a child (V2 name; it is not `task`). */
|
|
1144
|
+
const SUBAGENT_TOOL = "subagent";
|
|
1145
|
+
/** The tool result also names its child: `<subagent sessionID="ses_…" …>`. */
|
|
1146
|
+
const SUBAGENT_SESSION_PATTERN = /sessionID="([^"]+)"/;
|
|
1147
|
+
/** Text of a tool `content` payload, joined; tolerant of the string form. */
|
|
1148
|
+
function toolContentText(content) {
|
|
1149
|
+
if (typeof content === "string") return content;
|
|
1150
|
+
if (!Array.isArray(content)) return "";
|
|
1151
|
+
const chunks = [];
|
|
1152
|
+
for (const part of content) {
|
|
1153
|
+
const text = part?.text;
|
|
1154
|
+
if (typeof text === "string") chunks.push(text);
|
|
1155
|
+
}
|
|
1156
|
+
return chunks.join("\n");
|
|
1157
|
+
}
|
|
1158
|
+
/** Child session id of one `subagent` call: the exact `metadata.sessionID`
|
|
1159
|
+
* first, then an `output`/`result` id, then the `<subagent sessionID="…">` tag
|
|
1160
|
+
* in the result text. Null when the call has not produced a child yet. */
|
|
1161
|
+
function subagentSessionID(state) {
|
|
1162
|
+
const direct = [
|
|
1163
|
+
state?.metadata?.sessionID,
|
|
1164
|
+
state?.output?.sessionID,
|
|
1165
|
+
state?.result?.sessionID
|
|
1166
|
+
];
|
|
1167
|
+
for (const candidate of direct) if (typeof candidate === "string" && candidate !== "") return candidate;
|
|
1168
|
+
return SUBAGENT_SESSION_PATTERN.exec(toolContentText(state?.content))?.[1] ?? null;
|
|
1169
|
+
}
|
|
1170
|
+
/** Correlate the parent transcript's `subagent` calls with the children they
|
|
1171
|
+
* spawned: child session id → `{ agent, description, background }`. One pass
|
|
1172
|
+
* over the list the sidebar already holds — no request, no `message.sync` on
|
|
1173
|
+
* the child. `streaming`/`pending` states carry their input as *partial JSON
|
|
1174
|
+
* text*, so they are skipped rather than parsed. Fail-open: a malformed part
|
|
1175
|
+
* contributes nothing. Pure. */
|
|
1176
|
+
function collectSubagentCalls(messages) {
|
|
1177
|
+
const calls = /* @__PURE__ */ new Map();
|
|
1178
|
+
if (!Array.isArray(messages)) return calls;
|
|
1179
|
+
for (const message of messages) {
|
|
1180
|
+
if (message?.type !== "assistant" || !Array.isArray(message.content)) continue;
|
|
1181
|
+
for (const part of message.content) {
|
|
1182
|
+
if (part?.type !== "tool" || part?.name !== SUBAGENT_TOOL) continue;
|
|
1183
|
+
const state = part.state;
|
|
1184
|
+
if (state === null || typeof state !== "object") continue;
|
|
1185
|
+
if (state.status === "streaming" || state.status === "pending") continue;
|
|
1186
|
+
const sessionID = subagentSessionID(state);
|
|
1187
|
+
if (!isValidSessionID(sessionID)) continue;
|
|
1188
|
+
const input = state.input !== null && typeof state.input === "object" ? state.input : {};
|
|
1189
|
+
const agent = typeof input.agent === "string" ? input.agent : "";
|
|
1190
|
+
const description = typeof input.description === "string" ? input.description : "";
|
|
1191
|
+
calls.set(sessionID, {
|
|
1192
|
+
sessionID,
|
|
1193
|
+
agent,
|
|
1194
|
+
description,
|
|
1195
|
+
background: input.background === true
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
return calls;
|
|
1200
|
+
}
|
|
1201
|
+
/** Grace window for a child that has not started yet. V2's `session.status()`
|
|
1202
|
+
* returns `idle` both for "created but not started" and for "finished", so an
|
|
1203
|
+
* idle/unknown/absent child whose own last activity (`time.updated`, falling
|
|
1204
|
+
* back to `time.created`) is this recent still reads as running — otherwise a
|
|
1205
|
+
* just-spawned child renders a premature ✓. Trade-off (V1 parity: it had the
|
|
1206
|
+
* same window for its absent statuses): a child that finished within the window
|
|
1207
|
+
* and reports no `outcome` reads as running until the window closes, at which
|
|
1208
|
+
* point it turns terminal and its completion toast fires. A child that reports
|
|
1209
|
+
* a terminal `outcome` is never held back by the window. */
|
|
1210
|
+
const DELEGATION_CHILD_STATUS_GRACE_MS = 6e4;
|
|
1211
|
+
/** One delegated child job as the sidebar renders it. */
|
|
1212
|
+
/** Map the host's live session status to a display state. V2 exposes only
|
|
1213
|
+
* `"idle" | "running"` through the TUI context (the client union adds `retry`
|
|
1214
|
+
* and `busy`); `error`/`failed` are handled defensively for host drift.
|
|
1215
|
+
* `idle`, `retry` and unknown/absent statuses are terminal only once the
|
|
1216
|
+
* child's own activity is older than the grace window — within it the child
|
|
1217
|
+
* reads as running (see `DELEGATION_CHILD_STATUS_GRACE_MS`). An interruption is
|
|
1218
|
+
* not part of this union: it arrives as a terminal `outcome`. Pure. */
|
|
1219
|
+
function delegationStateFromStatus(status, time, now = Date.now(), graceMs = DELEGATION_CHILD_STATUS_GRACE_MS) {
|
|
1220
|
+
switch (status) {
|
|
1221
|
+
case "running":
|
|
1222
|
+
case "busy": return "running";
|
|
1223
|
+
case "error":
|
|
1224
|
+
case "failed": return "failed";
|
|
1225
|
+
default: {
|
|
1226
|
+
const lastActivity = Math.max(time?.updated ?? 0, time?.created ?? 0);
|
|
1227
|
+
if (lastActivity > 0 && now - lastActivity < graceMs) return "running";
|
|
1228
|
+
return "completed";
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
/** Map a V2 child `outcome` to a display state. `interrupted` (user abort,
|
|
1233
|
+
* shutdown, superseded, inactivity) is distinct from both success and failure,
|
|
1234
|
+
* so an aborted child never renders the ✓ of a completed one. Returns null for
|
|
1235
|
+
* an absent/unrecognised outcome so the live status decides. Pure. */
|
|
1236
|
+
function delegationStateFromOutcome(outcome) {
|
|
1237
|
+
switch (outcome) {
|
|
1238
|
+
case "succeeded": return "completed";
|
|
1239
|
+
case "failed": return "failed";
|
|
1240
|
+
case "interrupted": return "interrupted";
|
|
1241
|
+
default: return null;
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
/** Build a delegation row from a child session + its live status, plus the
|
|
1245
|
+
* `subagent` call that spawned it (when the parent transcript had one). A
|
|
1246
|
+
* terminal `outcome` wins when present (the only V2 primitive that surfaces a
|
|
1247
|
+
* delegation failure/interruption once the status is back to idle); otherwise
|
|
1248
|
+
* the live status decides, with the absent/idle grace window applied. The
|
|
1249
|
+
* `call` only ever *adds* the purpose and the background flag — an absent one
|
|
1250
|
+
* leaves the row fully renderable. Pure. */
|
|
1251
|
+
function toDelegationView(child, status, now = Date.now(), call) {
|
|
1252
|
+
const id = typeof child?.id === "string" ? child.id : "";
|
|
1253
|
+
const title = typeof child?.title === "string" && child.title !== "" ? child.title : "";
|
|
1254
|
+
const agent = typeof child?.agent === "string" && child.agent !== "" ? child.agent : "";
|
|
1255
|
+
const label = title !== "" ? title : agent !== "" ? agent : id.slice(0, 8);
|
|
1256
|
+
const state = delegationStateFromOutcome(child?.outcome) ?? delegationStateFromStatus(status, child?.time, now);
|
|
1257
|
+
const classification = classifyDispatchKind(call);
|
|
1258
|
+
return {
|
|
1259
|
+
id,
|
|
1260
|
+
label,
|
|
1261
|
+
state,
|
|
1262
|
+
startedAt: numberOrNull(child?.time?.created),
|
|
1263
|
+
updatedAt: numberOrNull(child?.time?.updated),
|
|
1264
|
+
agent: agent !== "" ? agent : null,
|
|
1265
|
+
model: shortModelID(child?.model),
|
|
1266
|
+
cost: numberOrNull(child?.cost),
|
|
1267
|
+
kind: classification.kind,
|
|
1268
|
+
kindOrigin: classification.origin,
|
|
1269
|
+
background: call?.background === true
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1272
|
+
const SPINNER_FRAMES = [
|
|
1273
|
+
"⠋",
|
|
1274
|
+
"⠙",
|
|
1275
|
+
"⠹",
|
|
1276
|
+
"⠸",
|
|
1277
|
+
"⠼",
|
|
1278
|
+
"⠴",
|
|
1279
|
+
"⠦",
|
|
1280
|
+
"⠧",
|
|
1281
|
+
"⠇",
|
|
1282
|
+
"⠏"
|
|
1283
|
+
];
|
|
1284
|
+
/** Spinner glyph for a frame counter (incremented every ~80ms while any job is
|
|
1285
|
+
* running). Pure. */
|
|
1286
|
+
function spinnerFrame(frame) {
|
|
1287
|
+
const index = Math.abs(Math.floor(frame)) % SPINNER_FRAMES.length;
|
|
1288
|
+
return SPINNER_FRAMES[index] ?? SPINNER_FRAMES[0];
|
|
1289
|
+
}
|
|
1290
|
+
/** Shared order: live work first, then most recent activity. One comparator for
|
|
1291
|
+
* every consumer of the dispatch tree (sidebar block and panel list), so the
|
|
1292
|
+
* two views can never disagree about which child comes first. Pure. */
|
|
1293
|
+
function compareDelegations(a, b) {
|
|
1294
|
+
const activeA = a.state === "running" ? 1 : 0;
|
|
1295
|
+
const activeB = b.state === "running" ? 1 : 0;
|
|
1296
|
+
if (activeA !== activeB) return activeB - activeA;
|
|
1297
|
+
return (b.updatedAt ?? 0) - (a.updatedAt ?? 0);
|
|
1298
|
+
}
|
|
1299
|
+
/** Token totals published on `SessionInfo.tokens`, one entry per counter. */
|
|
1300
|
+
/** One child of the dispatch tree: the delegation row plus the fields only the
|
|
1301
|
+
* panel's detail view needs (`SessionInfo.title`/`parentID`/`tokens` and the
|
|
1302
|
+
* spawning call's description). */
|
|
1303
|
+
/** Optional inputs of `collectDispatch`: a fixed clock (tests/render ticks) and
|
|
1304
|
+
* an already-computed `agent` map, so a caller that walked the parent
|
|
1305
|
+
* transcript anyway never pays for a second walk. */
|
|
1306
|
+
/** `message.list` of one session, degrades to an empty list. The host's list is
|
|
1307
|
+
* a cached directory read, not a request. */
|
|
1308
|
+
function readSessionMessages(context, sessionID) {
|
|
1309
|
+
try {
|
|
1310
|
+
const result = context?.data?.session?.message?.list?.(sessionID);
|
|
1311
|
+
return Array.isArray(result) ? result : [];
|
|
1312
|
+
} catch {
|
|
1313
|
+
return [];
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
/** Token counters of a child, null when the host published none of them. Pure. */
|
|
1317
|
+
function dispatchTokens(tokens) {
|
|
1318
|
+
if (tokens === null || typeof tokens !== "object") return null;
|
|
1319
|
+
const source = tokens;
|
|
1320
|
+
const cache = source.cache !== null && typeof source.cache === "object" ? source.cache : {};
|
|
1321
|
+
const totals = {
|
|
1322
|
+
input: numberOrNull(source.input),
|
|
1323
|
+
output: numberOrNull(source.output),
|
|
1324
|
+
reasoning: numberOrNull(source.reasoning),
|
|
1325
|
+
cacheRead: numberOrNull(cache.read),
|
|
1326
|
+
cacheWrite: numberOrNull(cache.write)
|
|
1327
|
+
};
|
|
1328
|
+
return [
|
|
1329
|
+
totals.input,
|
|
1330
|
+
totals.output,
|
|
1331
|
+
totals.reasoning,
|
|
1332
|
+
totals.cacheRead,
|
|
1333
|
+
totals.cacheWrite
|
|
1334
|
+
].every((value) => value === null) ? null : totals;
|
|
1335
|
+
}
|
|
1336
|
+
/** One child `SessionInfo` + its live status → `DispatchEntry`. The call only
|
|
1337
|
+
* ever adds the kind and the description; an absent one leaves the entry fully
|
|
1338
|
+
* renderable. Pure. */
|
|
1339
|
+
function toDispatchEntry(child, status, now = Date.now(), call) {
|
|
1340
|
+
const title = typeof child?.title === "string" && child.title !== "" ? child.title : null;
|
|
1341
|
+
const parentID = typeof child?.parentID === "string" && child.parentID !== "" ? child.parentID : null;
|
|
1342
|
+
const description = typeof call?.description === "string" && call.description !== "" ? call.description : null;
|
|
1343
|
+
return {
|
|
1344
|
+
view: toDelegationView(child, status, now, call),
|
|
1345
|
+
title,
|
|
1346
|
+
description,
|
|
1347
|
+
parentID,
|
|
1348
|
+
tokens: dispatchTokens(child?.tokens)
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
/** The delegation tree of `sessionID` — every child `session.family` returns,
|
|
1352
|
+
* root excluded, each enriched from `session.get`/`session.status` and the
|
|
1353
|
+
* parent's `subagent` calls. Empty when the family API is unavailable or the
|
|
1354
|
+
* session id is not a real handle (never falls back to the root). Ordered by
|
|
1355
|
+
* the shared `compareDelegations`, so callers render the same list in the same
|
|
1356
|
+
* order. A family that repeats an id yields one row per child: the id is
|
|
1357
|
+
* deduplicated before the walk, so a duplicate can never double a row or its
|
|
1358
|
+
* cost. */
|
|
1359
|
+
function collectDispatch(context, sessionID, options = {}) {
|
|
1360
|
+
if (!isValidSessionID(sessionID)) return [];
|
|
1361
|
+
let family = [];
|
|
1362
|
+
try {
|
|
1363
|
+
const result = context?.data?.session?.family?.(sessionID);
|
|
1364
|
+
if (Array.isArray(result)) family = result;
|
|
1365
|
+
} catch {
|
|
1366
|
+
return [];
|
|
1367
|
+
}
|
|
1368
|
+
const now = numberOrNull(options.now) ?? Date.now();
|
|
1369
|
+
const calls = options.calls ?? collectSubagentCalls(readSessionMessages(context, sessionID));
|
|
1370
|
+
const entries = [];
|
|
1371
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1372
|
+
for (const childID of family) {
|
|
1373
|
+
if (childID === sessionID || !isValidSessionID(childID)) continue;
|
|
1374
|
+
if (seen.has(childID)) continue;
|
|
1375
|
+
seen.add(childID);
|
|
1376
|
+
let child;
|
|
1377
|
+
try {
|
|
1378
|
+
child = context.data.session.get(childID);
|
|
1379
|
+
} catch {
|
|
1380
|
+
continue;
|
|
1381
|
+
}
|
|
1382
|
+
if (!child) continue;
|
|
1383
|
+
entries.push(toDispatchEntry(child, sessionStatusOf(context, childID), now, calls.get(childID) ?? null));
|
|
1384
|
+
}
|
|
1385
|
+
return entries.sort((a, b) => compareDelegations(a.view, b.view));
|
|
1386
|
+
}
|
|
1387
|
+
/** Sidebar blocks in render order. Spacing is derived from this list instead of
|
|
1388
|
+
* from the view, so a hidden block can never leave an empty gap behind. */
|
|
1389
|
+
/** One rendered block: its key, and whether a blank line precedes it. */
|
|
1390
|
+
/** Header glyph per block — one codepoint each, rendered muted before the bold
|
|
1391
|
+
* label. The fixed header (version/preset/session) takes none.
|
|
1392
|
+
* Measured as one terminal cell by the host (`@opentui/core` counts
|
|
1393
|
+
* `emoji-regex` matches as two): ▤ U+25A4 (EAW=A), ◆ U+25C6 (A), ▾ U+25BE (N),
|
|
1394
|
+
* ◈ U+25C8 (A). `☑` U+2611 was rejected for the Todo header because it matches
|
|
1395
|
+
* `emoji-regex` and would occupy two cells; `⌁` U+2301 (the old Dispatch glyph)
|
|
1396
|
+
* was replaced by the host's own Notice glyph. */
|
|
1397
|
+
const BLOCK_ICONS = {
|
|
1398
|
+
context: "▤",
|
|
1399
|
+
git: "◆",
|
|
1400
|
+
todo: "▾",
|
|
1401
|
+
dispatch: "◈"
|
|
1402
|
+
};
|
|
1403
|
+
/** Tag every block that has content with its spacer: never before the first
|
|
1404
|
+
* (the view puts a single blank line after the fixed header instead), one
|
|
1405
|
+
* blank line before every later block. A repeated key collapses instead of
|
|
1406
|
+
* stacking spacers, so an absent optional block can never leave a double gap.
|
|
1407
|
+
* Pure. */
|
|
1408
|
+
function withBlockSpacers(keys) {
|
|
1409
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1410
|
+
const blocks = [];
|
|
1411
|
+
for (const key of keys) {
|
|
1412
|
+
if (seen.has(key)) continue;
|
|
1413
|
+
seen.add(key);
|
|
1414
|
+
blocks.push({
|
|
1415
|
+
key,
|
|
1416
|
+
spacer: blocks.length > 0
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
return blocks;
|
|
1420
|
+
}
|
|
1421
|
+
/** Live children rendered one row each; the rest collapse into `… +N rodando`. */
|
|
1422
|
+
const DISPATCH_RUNNING_CEILING = 3;
|
|
1423
|
+
/** Agent rollup rows rendered before the `… +K $<soma>` line. */
|
|
1424
|
+
const DISPATCH_AGENT_CEILING = 3;
|
|
1425
|
+
/** Hard cap on the block's rendered rows, header included. The sidebar is
|
|
1426
|
+
* short; live work is served first, then the finished rollup. */
|
|
1427
|
+
const DISPATCH_MAX_LINES = 8;
|
|
1428
|
+
/** Marker of the aggregated "finished" section. */
|
|
1429
|
+
const DISPATCH_DONE_MARKER = "✓";
|
|
1430
|
+
/** Column width of the agent (or of its title/id fallback). */
|
|
1431
|
+
const DISPATCH_AGENT_WIDTH = 12;
|
|
1432
|
+
/** Narrowest agent column a row may fall back to before the cost is kept whole
|
|
1433
|
+
* and the label truncates further. */
|
|
1434
|
+
const DISPATCH_MIN_AGENT_WIDTH = 8;
|
|
1435
|
+
/** Column width of the short model id — the model is dropped before the agent
|
|
1436
|
+
* or the cost so a row always fits. */
|
|
1437
|
+
const DISPATCH_MODEL_WIDTH = 7;
|
|
1438
|
+
/** Column width of the per-dispatch cost (`$0.04`; a sub-cent cost widens it). */
|
|
1439
|
+
const DISPATCH_COST_WIDTH = 5;
|
|
1440
|
+
/** Column width of the duration (`12.7s` / `1m04s` / `820ms`). */
|
|
1441
|
+
const DISPATCH_DURATION_WIDTH = 5;
|
|
1442
|
+
/** Column width of the `×<count>` cell of an agent rollup row. */
|
|
1443
|
+
const DISPATCH_COUNT_WIDTH = 3;
|
|
1444
|
+
/** Column width of an agent rollup cost (`$0.0051` still fits). */
|
|
1445
|
+
const DISPATCH_GROUP_COST_WIDTH = 7;
|
|
1446
|
+
/** Hard column budget for one row — a Dispatch line never wraps:
|
|
1447
|
+
* marker(2) + agent(12) + model(7) + cost(5) + duration(5) + 3 spaces = 34.
|
|
1448
|
+
* The kind suffix (`·disc`, `·disc~`) is wider evidence than the model, so a
|
|
1449
|
+
* classified row spends the model's columns first: marker(2) + agent(≤12) +
|
|
1450
|
+
* suffix(≤6) + cost(5) + duration(5) + 2 spaces ≤ 32, still inside 34. */
|
|
1451
|
+
const DISPATCH_MAX_WIDTH = 34;
|
|
1452
|
+
/** Middle dot used between a label and its kind (`apollo·disc`). */
|
|
1453
|
+
const DISPATCH_KIND_SEPARATOR = "·";
|
|
1454
|
+
/** Background marker: the parent asked the child to run in the background. */
|
|
1455
|
+
const DISPATCH_BACKGROUND_MARKER = "~";
|
|
1456
|
+
/** Kind suffix glued to a row's label: `·disc`, `·disc~` for a background run,
|
|
1457
|
+
* and empty when the child could not be classified (the row then reads exactly
|
|
1458
|
+
* as before). Pure. */
|
|
1459
|
+
function dispatchKindSuffix(kind, background) {
|
|
1460
|
+
if (kind === null || kind === void 0) return "";
|
|
1461
|
+
const text = `${DISPATCH_KIND_SEPARATOR}${kind}`;
|
|
1462
|
+
return background === true ? `${text}${DISPATCH_BACKGROUND_MARKER}` : text;
|
|
1463
|
+
}
|
|
1464
|
+
/** Header summary: `2 rodando · $3.49`. The live count is omitted when nothing
|
|
1465
|
+
* runs, and the total spend is always printed (the header only renders while
|
|
1466
|
+
* the tree has children, so `$0.00` is a real answer). Pure. */
|
|
1467
|
+
function dispatchHeaderSummary(running, cost) {
|
|
1468
|
+
const parts = [];
|
|
1469
|
+
const live = numberOrNull(running) ?? 0;
|
|
1470
|
+
if (live > 0) parts.push(`${Math.round(live)} rodando`);
|
|
1471
|
+
const formatted = formatSpendUSD(numberOrNull(cost) ?? 0);
|
|
1472
|
+
if (formatted !== null) parts.push(formatted);
|
|
1473
|
+
return parts.length === 0 ? null : parts.join(SPEND_LINE_SEPARATOR);
|
|
1474
|
+
}
|
|
1475
|
+
/** Compact duration without an internal space: `820` → `820ms`, `12_400` →
|
|
1476
|
+
* `12.4s`, `64_000` → `1m04s`, `3_780_000` → `1h03m`, `172_800_000` → `2d`.
|
|
1477
|
+
* An absent or negative value renders an em dash, never `NaN`s. Pure. */
|
|
1478
|
+
function formatDispatchDuration(ms) {
|
|
1479
|
+
const value = numberOrNull(ms);
|
|
1480
|
+
if (value === null || value < 0) return "—";
|
|
1481
|
+
if (value < 1e3) return `${Math.round(value)}ms`;
|
|
1482
|
+
const seconds = value / 1e3;
|
|
1483
|
+
if (seconds < 59.95) return `${seconds.toFixed(1)}s`;
|
|
1484
|
+
const total = Math.round(seconds);
|
|
1485
|
+
const hours = Math.floor(total / 3600);
|
|
1486
|
+
const minutes = Math.floor(total % 3600 / 60);
|
|
1487
|
+
if (hours >= 24) return `${Math.floor(hours / 24)}d`;
|
|
1488
|
+
if (hours > 0) return `${hours}h${String(minutes).padStart(2, "0")}m`;
|
|
1489
|
+
return `${minutes}m${String(total % 60).padStart(2, "0")}s`;
|
|
1490
|
+
}
|
|
1491
|
+
/** Elapsed label for one row: a live child measures `now - created`, a finished
|
|
1492
|
+
* one freezes at `updated - created` (em dash when a timestamp is missing).
|
|
1493
|
+
* Pure. */
|
|
1494
|
+
function dispatchElapsed(view, now = Date.now()) {
|
|
1495
|
+
if (view.startedAt === null) return "—";
|
|
1496
|
+
if (view.state === "running") return formatDispatchDuration(now - view.startedAt);
|
|
1497
|
+
if (view.updatedAt === null) return "—";
|
|
1498
|
+
return formatDispatchDuration(view.updatedAt - view.startedAt);
|
|
1499
|
+
}
|
|
1500
|
+
/** Name column: the agent when the host published one, else the child title,
|
|
1501
|
+
* else the short id — never `undefined`. Truncated to the column width. Pure. */
|
|
1502
|
+
function dispatchAgentText(view, max = 12) {
|
|
1503
|
+
const agent = typeof view.agent === "string" ? view.agent.trim() : "";
|
|
1504
|
+
const label = typeof view.label === "string" ? view.label.trim() : "";
|
|
1505
|
+
const id = typeof view.id === "string" ? view.id.trim() : "";
|
|
1506
|
+
const name = agent !== "" ? agent : label !== "" ? label : id;
|
|
1507
|
+
return name === "" ? "—" : truncateLabel(name, max);
|
|
1508
|
+
}
|
|
1509
|
+
/** Model column, empty when the host published none. Pure. */
|
|
1510
|
+
function dispatchModelText(view) {
|
|
1511
|
+
const model = typeof view.model === "string" ? view.model.trim() : "";
|
|
1512
|
+
return model === "" ? "" : truncateLabel(model, 7);
|
|
1513
|
+
}
|
|
1514
|
+
/** Cost column: the child's real `SessionInfo.cost` with two decimals (up to
|
|
1515
|
+
* four below a cent, so `$0.0031` never collapses to `$0.00`), `$0.00` for a
|
|
1516
|
+
* zero cost, and an em dash when the host published no numeric cost. Pure. */
|
|
1517
|
+
function formatDispatchCost(cost) {
|
|
1518
|
+
return formatUsageCost(cost) ?? "—";
|
|
1519
|
+
}
|
|
1520
|
+
/** Total spend of every child (live + finished), `0` when none published a
|
|
1521
|
+
* numeric cost. Pure. */
|
|
1522
|
+
function dispatchTotalCost(views) {
|
|
1523
|
+
let total = 0;
|
|
1524
|
+
for (const view of views ?? []) {
|
|
1525
|
+
const cost = numberOrNull(view?.cost);
|
|
1526
|
+
if (cost !== null && cost >= 0) total += cost;
|
|
1527
|
+
}
|
|
1528
|
+
return total;
|
|
1529
|
+
}
|
|
1530
|
+
/** One live child: `⠸ <agent 12>·<kind> <custo> <duração>`, with the model as a
|
|
1531
|
+
* fourth column only when the row still fits and the child is unclassified —
|
|
1532
|
+
* the kind is the stronger evidence at this width, so it takes the model's
|
|
1533
|
+
* columns. The kind rides glued to the label (never a column of its own) and
|
|
1534
|
+
* disappears with the label's truncation; then the agent column shrinks (never
|
|
1535
|
+
* below `DISPATCH_MIN_AGENT_WIDTH`); the cost is always present — `$0.00` for a
|
|
1536
|
+
* zero cost, an em dash for a missing one. Pure. */
|
|
1537
|
+
function runningChildRowText(view, now = Date.now(), frame = 0, max = 34) {
|
|
1538
|
+
const marker = `${spinnerFrame(frame)} `;
|
|
1539
|
+
const duration = dispatchElapsed(view, now).padStart(5);
|
|
1540
|
+
const cost = formatDispatchCost(view.cost).padStart(5);
|
|
1541
|
+
const model = dispatchModelText(view);
|
|
1542
|
+
const suffix = dispatchKindSuffix(view.kind, view.background);
|
|
1543
|
+
const limit = Math.max(1, max);
|
|
1544
|
+
const row = (agentWidth, withModel, withSuffix = true) => {
|
|
1545
|
+
const kind = withSuffix ? suffix : "";
|
|
1546
|
+
const name = dispatchAgentText(view, agentWidth);
|
|
1547
|
+
const cell = kind === "" ? name.padEnd(agentWidth) : `${name}${kind}`;
|
|
1548
|
+
const tail = withModel ? `${model.padEnd(7)} ${cost} ${duration}` : `${cost} ${duration}`;
|
|
1549
|
+
return `${marker}${cell} ${tail}`;
|
|
1550
|
+
};
|
|
1551
|
+
if (model !== "" && suffix === "") {
|
|
1552
|
+
const withModel = row(12, true);
|
|
1553
|
+
if (withModel.length <= limit) return withModel;
|
|
1554
|
+
}
|
|
1555
|
+
const full = row(12, false);
|
|
1556
|
+
if (full.length <= limit) return full;
|
|
1557
|
+
for (let width = 11; width >= 8; width -= 1) {
|
|
1558
|
+
const narrowed = row(width, false);
|
|
1559
|
+
if (narrowed.length <= limit) return narrowed;
|
|
1560
|
+
}
|
|
1561
|
+
if (suffix !== "") return row(8, false, false);
|
|
1562
|
+
return row(8, false);
|
|
1563
|
+
}
|
|
1564
|
+
/** Sessions and spend attributed to one agent in the finished section. `kind`
|
|
1565
|
+
* is only set when every finished session of the group agrees on it — a mixed
|
|
1566
|
+
* group carries no single purpose, so the row omits it rather than picking one.
|
|
1567
|
+
* `background` follows the same rule (all of them background). */
|
|
1568
|
+
/** Rollup of the finished children by agent: `×count` sessions and the summed
|
|
1569
|
+
* `SessionInfo.cost`. Failed and interrupted children are included (they are
|
|
1570
|
+
* finished); running ones are not. The group's kind survives only when the
|
|
1571
|
+
* whole group agrees, so an aggregate row never claims a purpose it cannot
|
|
1572
|
+
* prove. Ordered by cost, then count, then name. Pure. */
|
|
1573
|
+
function collectChildAgentUsage(views) {
|
|
1574
|
+
const totals = /* @__PURE__ */ new Map();
|
|
1575
|
+
for (const view of views ?? []) {
|
|
1576
|
+
if (!view || view.state === "running") continue;
|
|
1577
|
+
const agent = agentKey(view.agent);
|
|
1578
|
+
const current = totals.get(agent) ?? {
|
|
1579
|
+
agent,
|
|
1580
|
+
count: 0,
|
|
1581
|
+
cost: 0,
|
|
1582
|
+
kinds: /* @__PURE__ */ new Set(),
|
|
1583
|
+
background: true
|
|
1584
|
+
};
|
|
1585
|
+
current.count += 1;
|
|
1586
|
+
current.kinds.add(view.kind ?? null);
|
|
1587
|
+
if (view.background !== true) current.background = false;
|
|
1588
|
+
const cost = numberOrNull(view.cost);
|
|
1589
|
+
if (cost !== null && cost >= 0) current.cost += cost;
|
|
1590
|
+
totals.set(agent, current);
|
|
1591
|
+
}
|
|
1592
|
+
return [...totals.values()].map((entry) => {
|
|
1593
|
+
const shared = entry.kinds.size === 1 ? [...entry.kinds][0] ?? null : null;
|
|
1594
|
+
return {
|
|
1595
|
+
agent: entry.agent,
|
|
1596
|
+
count: entry.count,
|
|
1597
|
+
cost: entry.cost,
|
|
1598
|
+
kind: shared,
|
|
1599
|
+
background: entry.background
|
|
1600
|
+
};
|
|
1601
|
+
}).sort((a, b) => b.cost - a.cost || b.count - a.count || a.agent.localeCompare(b.agent));
|
|
1602
|
+
}
|
|
1603
|
+
/** One agent rollup row: `<agent 12> ×<count 3>·<kind> <custo 7>`. The kind is
|
|
1604
|
+
* glued to the count (the row's only label) and omitted for a mixed group; the
|
|
1605
|
+
* agent column shrinks (never below the minimum) before the cost, which is
|
|
1606
|
+
* what the row is for. Pure. */
|
|
1607
|
+
function childAgentRowText(row, max = 34) {
|
|
1608
|
+
const suffix = dispatchKindSuffix(row?.kind, row?.background);
|
|
1609
|
+
const count = `\u00D7${String(Math.max(0, Math.round(numberOrNull(row?.count) ?? 0))).padStart(3)}`;
|
|
1610
|
+
const cost = formatDispatchCost(row?.cost).padStart(7);
|
|
1611
|
+
const limit = Math.max(1, max);
|
|
1612
|
+
const text = (agentWidth, withSuffix = true) => {
|
|
1613
|
+
const kind = withSuffix ? suffix : "";
|
|
1614
|
+
return `${truncateLabel(agentKey(row?.agent), agentWidth).padEnd(agentWidth)} ${count}${kind} ${cost}`;
|
|
1615
|
+
};
|
|
1616
|
+
const full = text(12);
|
|
1617
|
+
if (full.length <= limit) return full;
|
|
1618
|
+
for (let width = 11; width >= 8; width -= 1) {
|
|
1619
|
+
const narrowed = text(width);
|
|
1620
|
+
if (narrowed.length <= limit) return narrowed;
|
|
1621
|
+
}
|
|
1622
|
+
if (suffix !== "") return text(8, false);
|
|
1623
|
+
return text(8);
|
|
1624
|
+
}
|
|
1625
|
+
/** The `… +K $<soma>` line for agents beyond the rollup cap. Null when every
|
|
1626
|
+
* agent fits. Pure. */
|
|
1627
|
+
function hiddenChildAgentsText(hidden, hiddenCost) {
|
|
1628
|
+
const count = numberOrNull(hidden) ?? 0;
|
|
1629
|
+
if (count <= 0) return null;
|
|
1630
|
+
const cost = formatSpendUSD(numberOrNull(hiddenCost) ?? 0);
|
|
1631
|
+
return cost === null ? `\u2026 +${Math.round(count)}` : `\u2026 +${Math.round(count)} ${cost}`;
|
|
1632
|
+
}
|
|
1633
|
+
/** Summary of the finished section: `✓ 70 · $3.40 · 9 agentes`. `· $<soma>` is
|
|
1634
|
+
* omitted when nothing was spent and `· 1 agente` when a single agent owns
|
|
1635
|
+
* every finished child; `✓ <total>` always prints. Null when nothing finished.
|
|
1636
|
+
* Pure. */
|
|
1637
|
+
function completedSummaryText(completed, cost, agents) {
|
|
1638
|
+
const total = numberOrNull(completed) ?? 0;
|
|
1639
|
+
if (total <= 0) return null;
|
|
1640
|
+
const parts = [`✓ ${Math.round(total)}`];
|
|
1641
|
+
const spend = numberOrNull(cost) ?? 0;
|
|
1642
|
+
if (spend > 0) {
|
|
1643
|
+
const formatted = formatSpendUSD(spend);
|
|
1644
|
+
if (formatted !== null) parts.push(formatted);
|
|
1645
|
+
}
|
|
1646
|
+
const groups = Math.round(numberOrNull(agents) ?? 0);
|
|
1647
|
+
if (groups > 1) parts.push(`${groups} agentes`);
|
|
1648
|
+
return parts.join(SPEND_LINE_SEPARATOR);
|
|
1649
|
+
}
|
|
1650
|
+
/** The `· <F> falhas` suffix of the finished summary, null when nothing failed.
|
|
1651
|
+
* Pure. */
|
|
1652
|
+
function failedSuffixText(failures) {
|
|
1653
|
+
const count = numberOrNull(failures) ?? 0;
|
|
1654
|
+
if (count <= 0) return null;
|
|
1655
|
+
const rounded = Math.round(count);
|
|
1656
|
+
return `${rounded} ${rounded === 1 ? "falha" : "falhas"}`;
|
|
1657
|
+
}
|
|
1658
|
+
/** One rendered live row: its text plus the session it navigates to. */
|
|
1659
|
+
/** Everything the `Dispatch` block renders, already joined and capped. */
|
|
1660
|
+
/** Newest activity first, so the live rows that just moved lead the section.
|
|
1661
|
+
* Pure. */
|
|
1662
|
+
function lastActivity(view) {
|
|
1663
|
+
return Math.max(numberOrNull(view?.updatedAt) ?? 0, numberOrNull(view?.startedAt) ?? 0);
|
|
1664
|
+
}
|
|
1665
|
+
/** Build the whole block from the child set. Null when there is no child, so
|
|
1666
|
+
* the block (and its spacer) never renders empty. Live work is capped at
|
|
1667
|
+
* `DISPATCH_RUNNING_CEILING` and the finished rollup at
|
|
1668
|
+
* `DISPATCH_AGENT_CEILING`, with the rollup giving up rows first to keep the
|
|
1669
|
+
* block inside `DISPATCH_MAX_LINES`. Pure. */
|
|
1670
|
+
function buildDispatchBlock(views, now = Date.now(), frame = 0, max = 34) {
|
|
1671
|
+
const list = Array.isArray(views) ? views.filter((view) => view && typeof view.id === "string") : [];
|
|
1672
|
+
if (list.length === 0) return null;
|
|
1673
|
+
const running = list.filter((view) => view.state === "running").sort((a, b) => lastActivity(b) - lastActivity(a));
|
|
1674
|
+
const finished = list.filter((view) => view.state !== "running");
|
|
1675
|
+
const groups = collectChildAgentUsage(finished);
|
|
1676
|
+
const finishedCost = groups.reduce((sum, group) => sum + group.cost, 0);
|
|
1677
|
+
const failures = finished.filter((view) => view.state === "failed").length;
|
|
1678
|
+
const totalCost = dispatchTotalCost(list);
|
|
1679
|
+
const runningSlots = Math.min(3, running.length);
|
|
1680
|
+
const runningHidden = running.length - runningSlots;
|
|
1681
|
+
const runningLines = running.map((view) => ({
|
|
1682
|
+
id: view.id,
|
|
1683
|
+
text: runningChildRowText(view, now, frame, max)
|
|
1684
|
+
}));
|
|
1685
|
+
const summary = completedSummaryText(finished.length, finishedCost, groups.length);
|
|
1686
|
+
const runningRows = runningSlots + (runningHidden > 0 ? 1 : 0);
|
|
1687
|
+
const room = Math.max(0, 7 - runningRows - (summary === null ? 0 : 1));
|
|
1688
|
+
const wanted = Math.min(3, groups.length);
|
|
1689
|
+
const agentSlots = groups.length > wanted ? Math.min(wanted, Math.max(0, room - 1)) : Math.min(wanted, room);
|
|
1690
|
+
const visibleAgents = groups.slice(0, agentSlots);
|
|
1691
|
+
const hiddenAgents = groups.slice(agentSlots);
|
|
1692
|
+
return {
|
|
1693
|
+
runningCount: running.length,
|
|
1694
|
+
completedCount: finished.length,
|
|
1695
|
+
agentCount: groups.length,
|
|
1696
|
+
failures,
|
|
1697
|
+
totalCost,
|
|
1698
|
+
running: runningLines.slice(0, runningSlots),
|
|
1699
|
+
runningHidden,
|
|
1700
|
+
summary,
|
|
1701
|
+
agents: visibleAgents,
|
|
1702
|
+
agentsHidden: hiddenAgents.length,
|
|
1703
|
+
agentsHiddenCost: hiddenAgents.reduce((sum, group) => sum + group.cost, 0)
|
|
1704
|
+
};
|
|
1705
|
+
}
|
|
1706
|
+
/** Panel content name, registered by the `session.panel` claim and passed to
|
|
1707
|
+
* `ui.panel.open`. */
|
|
1708
|
+
const DISPATCH_PANEL_NAME = "pantheon.dispatch";
|
|
1709
|
+
/** Toast shown when `ui.panel.open` refuses (no session route is active). The
|
|
1710
|
+
* panel only exists inside a session, so there is no alternative route. */
|
|
1711
|
+
const DISPATCH_PANEL_TOAST = "Abra uma sessão para ver o Dispatch";
|
|
1712
|
+
/** Panel title marker — the same glyph the sidebar block header uses. */
|
|
1713
|
+
const DISPATCH_PANEL_HEADER_MARKER = "◈";
|
|
1714
|
+
/** Selected-row gutter marker (`▸`, one cell). */
|
|
1715
|
+
const DISPATCH_PANEL_SELECTION_MARKER = "▸";
|
|
1716
|
+
/** Cells the selection gutter occupies before a row's own text. */
|
|
1717
|
+
const DISPATCH_PANEL_SELECTION_GUTTER = 2;
|
|
1718
|
+
/** Column of the horizontal rule under the header. */
|
|
1719
|
+
const DISPATCH_PANEL_RULE_CHAR = "─";
|
|
1720
|
+
/** Em dash for any datum the host did not publish. */
|
|
1721
|
+
const DISPATCH_PANEL_DASH = "—";
|
|
1722
|
+
/** Body of an empty panel (the claim still renders, the list is just empty). */
|
|
1723
|
+
const DISPATCH_PANEL_EMPTY_TEXT = "Nenhuma sessão delegada";
|
|
1724
|
+
/** Width at or above which the list and the detail sit side by side. */
|
|
1725
|
+
const DISPATCH_PANEL_WIDE_MIN_WIDTH = 72;
|
|
1726
|
+
/** Rows the viewport holds; pageup/pagedown move by exactly this many rows. */
|
|
1727
|
+
const DISPATCH_PANEL_PAGE_SIZE = 10;
|
|
1728
|
+
/** Panel row columns: marker(2) + agent(12) + kind(4) + cost(≥7) + duration(8).
|
|
1729
|
+
* The cost column is at least this wide; a sub-cent cost widens it per row. */
|
|
1730
|
+
const DISPATCH_PANEL_AGENT_WIDTH = 12;
|
|
1731
|
+
const DISPATCH_PANEL_MIN_AGENT_WIDTH = 6;
|
|
1732
|
+
const DISPATCH_PANEL_KIND_WIDTH = 4;
|
|
1733
|
+
const DISPATCH_PANEL_COST_WIDTH = 7;
|
|
1734
|
+
const DISPATCH_PANEL_DURATION_WIDTH = 8;
|
|
1735
|
+
/** Title column budget (`◈ Dispatch — <sessão>`). */
|
|
1736
|
+
const DISPATCH_PANEL_TITLE_WIDTH = 44;
|
|
1737
|
+
/** Badge appended to the title while the host presents the panel full screen. */
|
|
1738
|
+
const DISPATCH_PANEL_FULLSCREEN_BADGE = "[fullscreen]";
|
|
1739
|
+
/** Columns a row spends before the agent cell, cost column excluded
|
|
1740
|
+
* (2 marker + 1 + 4 kind + 1 + 8 duration). The cost is measured per row
|
|
1741
|
+
* because `<$0.0001` is one cell wider than `DISPATCH_PANEL_COST_WIDTH`. */
|
|
1742
|
+
const DISPATCH_PANEL_ROW_FIXED_WIDTH = 16;
|
|
1743
|
+
/** Human labels of a kind's evidence, as the detail line prints them. */
|
|
1744
|
+
const DISPATCH_KIND_ORIGIN_LABELS = {
|
|
1745
|
+
prefix: "prefixo",
|
|
1746
|
+
agent: "agente",
|
|
1747
|
+
unavailable: "indisponível"
|
|
1748
|
+
};
|
|
1749
|
+
/** Entries in row order: live work first, then most recent activity — the same
|
|
1750
|
+
* comparator the sidebar block uses. Pure. */
|
|
1751
|
+
function orderDispatchEntries(entries) {
|
|
1752
|
+
return [...entries].sort((a, b) => compareDelegations(a.view, b.view));
|
|
1753
|
+
}
|
|
1754
|
+
/** `◈ Dispatch — <sessão>`, with the session title truncated (never wrapped),
|
|
1755
|
+
* plus the `[fullscreen]` badge while the host presents the panel full screen.
|
|
1756
|
+
* An absent title leaves the marker and the name alone. Pure. */
|
|
1757
|
+
function dispatchPanelTitle(sessionTitle, max = 44, presentation) {
|
|
1758
|
+
const base = `◈ Dispatch`;
|
|
1759
|
+
const badge = presentation === "fullscreen" ? ` ${DISPATCH_PANEL_FULLSCREEN_BADGE}` : "";
|
|
1760
|
+
const title = typeof sessionTitle === "string" ? sessionTitle.trim() : "";
|
|
1761
|
+
if (title === "") return `${base}${badge}`;
|
|
1762
|
+
return `${base} — ${truncateLabel(title, Math.max(4, max))}${badge}`;
|
|
1763
|
+
}
|
|
1764
|
+
/** Header counters: `2 rodando · 70 concluídos · 1 falha · $3.59`. A zero
|
|
1765
|
+
* counter is omitted (never `0 rodando`); the total spend is printed whenever
|
|
1766
|
+
* the tree has a child, because `$0.00` is then a real answer. Null for an
|
|
1767
|
+
* empty tree, so the header renders no counter line at all. Pure. */
|
|
1768
|
+
function dispatchPanelHeader(entries) {
|
|
1769
|
+
const list = Array.isArray(entries) ? entries.filter((entry) => entry?.view) : [];
|
|
1770
|
+
if (list.length === 0) return null;
|
|
1771
|
+
let running = 0;
|
|
1772
|
+
let completed = 0;
|
|
1773
|
+
let failed = 0;
|
|
1774
|
+
for (const entry of list) switch (entry.view.state) {
|
|
1775
|
+
case "running":
|
|
1776
|
+
running += 1;
|
|
1777
|
+
break;
|
|
1778
|
+
case "completed":
|
|
1779
|
+
completed += 1;
|
|
1780
|
+
break;
|
|
1781
|
+
case "failed": failed += 1;
|
|
1782
|
+
}
|
|
1783
|
+
const parts = [];
|
|
1784
|
+
if (running > 0) parts.push(`${running} rodando`);
|
|
1785
|
+
if (completed > 0) parts.push(`${completed} ${completed === 1 ? "concluído" : "concluídos"}`);
|
|
1786
|
+
if (failed > 0) parts.push(`${failed} ${failed === 1 ? "falha" : "falhas"}`);
|
|
1787
|
+
const cost = formatSpendUSD(dispatchTotalCost(list.map((entry) => entry.view)));
|
|
1788
|
+
if (cost !== null) parts.push(cost);
|
|
1789
|
+
return parts.length === 0 ? null : parts.join(SPEND_LINE_SEPARATOR);
|
|
1790
|
+
}
|
|
1791
|
+
/** Horizontal rule under the header, clamped to the panel's own width. Pure. */
|
|
1792
|
+
function dispatchPanelRule(width, max = 200) {
|
|
1793
|
+
const columns = Math.max(0, Math.min(max, Math.floor(numberOrNull(width) ?? 0)));
|
|
1794
|
+
return "─".repeat(columns);
|
|
1795
|
+
}
|
|
1796
|
+
/** Row marker: animated spinner while running, `✓` done, `✗` failed, `○`
|
|
1797
|
+
* cancelled/interrupted, `?` for a state the host never publishes. Every glyph
|
|
1798
|
+
* is one cell wide and `?` is the only fallback, so an unknown state is visible
|
|
1799
|
+
* instead of silently rendering as success. Pure. */
|
|
1800
|
+
function dispatchPanelMarker(state, frame = 0) {
|
|
1801
|
+
switch (state) {
|
|
1802
|
+
case "running": return `${spinnerFrame(frame)} `;
|
|
1803
|
+
case "completed": return "✓ ";
|
|
1804
|
+
case "failed": return "✗ ";
|
|
1805
|
+
case "interrupted": return "○ ";
|
|
1806
|
+
default: return "? ";
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
/** One padded, truncated cell: an absent/blank value becomes the em dash, and
|
|
1810
|
+
* the value is cut to the cell's own width (never to the line's length, so one
|
|
1811
|
+
* long cell cannot squeeze its neighbours out of alignment). Pure. */
|
|
1812
|
+
function dispatchPanelCell(value, width) {
|
|
1813
|
+
const cells = Math.max(1, Math.floor(numberOrNull(width) ?? 1));
|
|
1814
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
1815
|
+
return padCell(text === "" ? "—" : text, cells);
|
|
1816
|
+
}
|
|
1817
|
+
/** One list row: `⠋ prometheus plan $0.09 14m34s`. The agent cell absorbs
|
|
1818
|
+
* the width difference (down to `DISPATCH_PANEL_MIN_AGENT_WIDTH`), so a narrow
|
|
1819
|
+
* panel truncates the label rather than the numbers; the cost column grows by
|
|
1820
|
+
* itself for a sub-cent value so the row never spends more than its budget.
|
|
1821
|
+
* Pure. */
|
|
1822
|
+
function dispatchPanelRowText(entry, options = {}) {
|
|
1823
|
+
const view = entry?.view;
|
|
1824
|
+
if (!view) return "";
|
|
1825
|
+
const now = numberOrNull(options.now) ?? Date.now();
|
|
1826
|
+
const frame = numberOrNull(options.frame) ?? 0;
|
|
1827
|
+
const width = Math.floor(numberOrNull(options.max) ?? 35);
|
|
1828
|
+
const costText = formatDispatchCost(view.cost);
|
|
1829
|
+
const costWidth = Math.max(7, cellWidth(costText));
|
|
1830
|
+
const agentWidth = Math.max(6, Math.min(12, width - (DISPATCH_PANEL_ROW_FIXED_WIDTH + costWidth)));
|
|
1831
|
+
return `${dispatchPanelMarker(view.state, frame)}${dispatchPanelCell(dispatchAgentText(view, 12), agentWidth)} ${dispatchPanelCell(view.kind, 4)} ${costText.padStart(costWidth)}${truncateLabel(dispatchElapsed(view, now), 8).padStart(8)}`;
|
|
1832
|
+
}
|
|
1833
|
+
/** `ses_ab12cd`, short enough for a detail line. Full id when it already fits. */
|
|
1834
|
+
function shortSessionID(id, max = 10) {
|
|
1835
|
+
const text = typeof id === "string" ? id.trim() : "";
|
|
1836
|
+
if (text === "") return "—";
|
|
1837
|
+
return text.length <= max ? text : `${text.slice(0, Math.max(1, max - 1))}\u2026`;
|
|
1838
|
+
}
|
|
1839
|
+
/** Token counters of one child on a single line (`in 1.2K · out 430 · r 120 ·
|
|
1840
|
+
* cache 8K/1K`), or `tokens —` when the host published none. Pure. */
|
|
1841
|
+
function dispatchTokenLine(tokens) {
|
|
1842
|
+
if (!tokens) return `tokens —`;
|
|
1843
|
+
const value = (token) => token === null ? "—" : formatContextWindow(token) ?? String(token);
|
|
1844
|
+
return [
|
|
1845
|
+
`in ${value(tokens.input)}`,
|
|
1846
|
+
`out ${value(tokens.output)}`,
|
|
1847
|
+
`r ${value(tokens.reasoning)}`,
|
|
1848
|
+
`cache ${value(tokens.cacheRead)}/${value(tokens.cacheWrite)}`
|
|
1849
|
+
].join(SPEND_LINE_SEPARATOR);
|
|
1850
|
+
}
|
|
1851
|
+
/** Detail lines of the selected child: heading (title, else the spawning
|
|
1852
|
+
* description, else the row label), short id + model, token counters, and the
|
|
1853
|
+
* kind plus its evidence and the parent id. Two to four lines; `expanded:
|
|
1854
|
+
* false` keeps only the heading. Every missing datum prints `—`. Pure. */
|
|
1855
|
+
function dispatchPanelDetail(entry, options = {}) {
|
|
1856
|
+
if (!entry?.view) return ["—"];
|
|
1857
|
+
const max = Math.max(8, Math.floor(numberOrNull(options.max) ?? 60));
|
|
1858
|
+
const view = entry.view;
|
|
1859
|
+
const lines = [truncateLabel(entry.title ?? entry.description ?? (typeof view.label === "string" && view.label !== "" ? view.label : null) ?? view.id, max)];
|
|
1860
|
+
if (options.expanded === false) return lines;
|
|
1861
|
+
lines.push(truncateLabel(`${shortSessionID(view.id)}${SPEND_LINE_SEPARATOR}${view.model ?? "—"}`, max));
|
|
1862
|
+
lines.push(truncateLabel(dispatchTokenLine(entry.tokens), max));
|
|
1863
|
+
const origin = DISPATCH_KIND_ORIGIN_LABELS[view.kindOrigin] ?? DISPATCH_KIND_ORIGIN_LABELS.unavailable;
|
|
1864
|
+
lines.push(truncateLabel(`kind ${view.kind ?? "—"} (${origin})${SPEND_LINE_SEPARATOR}parent ${entry.parentID ?? "—"}`, max));
|
|
1865
|
+
return lines;
|
|
1866
|
+
}
|
|
1867
|
+
/** Panel geometry for its input width: wide (≥72) puts the detail in a second
|
|
1868
|
+
* column, narrow stacks it under the list. `rowWidth` is what a list row may
|
|
1869
|
+
* spend after the selection gutter. Pure. */
|
|
1870
|
+
function dispatchPanelLayout(width) {
|
|
1871
|
+
const columns = Math.max(20, Math.floor(numberOrNull(width) ?? 0));
|
|
1872
|
+
if (columns >= 72) {
|
|
1873
|
+
const listWidth = Math.max(40, Math.min(64, columns - 26));
|
|
1874
|
+
return {
|
|
1875
|
+
mode: "wide",
|
|
1876
|
+
listWidth,
|
|
1877
|
+
detailWidth: Math.max(24, columns - listWidth - 2),
|
|
1878
|
+
rowWidth: listWidth - 2
|
|
1879
|
+
};
|
|
1880
|
+
}
|
|
1881
|
+
return {
|
|
1882
|
+
mode: "narrow",
|
|
1883
|
+
listWidth: columns,
|
|
1884
|
+
detailWidth: columns,
|
|
1885
|
+
rowWidth: columns - 2
|
|
1886
|
+
};
|
|
1887
|
+
}
|
|
1888
|
+
/** Viewport of the list: the page holding the selection, scrolled so the
|
|
1889
|
+
* selected row stays visible with its predecessors. Bounded, so a 71-child
|
|
1890
|
+
* tree renders ten rows, never all of them. Pure. */
|
|
1891
|
+
function dispatchPanelWindow(total, selectedIndex, pageSize = 10) {
|
|
1892
|
+
const count = Math.max(0, Math.floor(numberOrNull(total) ?? 0));
|
|
1893
|
+
const size = Math.max(1, Math.floor(numberOrNull(pageSize) ?? 10));
|
|
1894
|
+
if (count === 0) return {
|
|
1895
|
+
start: 0,
|
|
1896
|
+
end: 0,
|
|
1897
|
+
size
|
|
1898
|
+
};
|
|
1899
|
+
const index = Math.min(count - 1, Math.max(0, Math.floor(numberOrNull(selectedIndex) ?? 0)));
|
|
1900
|
+
const start = Math.min(Math.max(0, index - size + 1), Math.max(0, count - size));
|
|
1901
|
+
return {
|
|
1902
|
+
start,
|
|
1903
|
+
end: Math.min(count, start + size),
|
|
1904
|
+
size
|
|
1905
|
+
};
|
|
1906
|
+
}
|
|
1907
|
+
/** `1-10 de 71` while the list is longer than one page; null when everything
|
|
1908
|
+
* fits (and for an empty list), so the footer never pads itself. Pure. */
|
|
1909
|
+
function dispatchPanelRangeText(start, end, total) {
|
|
1910
|
+
const count = Math.max(0, Math.floor(numberOrNull(total) ?? 0));
|
|
1911
|
+
const first = Math.max(0, Math.floor(numberOrNull(start) ?? 0));
|
|
1912
|
+
const last = Math.min(count, Math.floor(numberOrNull(end) ?? 0));
|
|
1913
|
+
if (count === 0 || first === 0 && last >= count) return null;
|
|
1914
|
+
return `${first + 1}-${last} de ${count}`;
|
|
1915
|
+
}
|
|
1916
|
+
/** One rendered list row, selection resolved by the view against the model's
|
|
1917
|
+
* selected id. */
|
|
1918
|
+
/** Every entry as a row, ordered by the shared comparator. Pure. */
|
|
1919
|
+
function dispatchPanelRows(entries, options = {}) {
|
|
1920
|
+
return orderDispatchEntries(Array.isArray(entries) ? entries.filter((entry) => entry?.view && typeof entry.view.id === "string") : []).map((entry) => ({
|
|
1921
|
+
id: entry.view.id,
|
|
1922
|
+
state: entry.view.state,
|
|
1923
|
+
text: dispatchPanelRowText(entry, options)
|
|
1924
|
+
}));
|
|
1925
|
+
}
|
|
1926
|
+
/** Panel action, one per command. */
|
|
1927
|
+
/** One namespaced command: stable id, explicit binding, and the action it runs. */
|
|
1928
|
+
/** The panel's whole keymap, in table order. `bind` is explicit for every
|
|
1929
|
+
* command (no auto-binding), and every id is namespaced, so a `k`/`q`/`f`
|
|
1930
|
+
* binding can never collide with the host's own keys. */
|
|
1931
|
+
const DISPATCH_PANEL_COMMANDS = [
|
|
1932
|
+
{
|
|
1933
|
+
action: "up",
|
|
1934
|
+
id: "pantheon.dispatch.up",
|
|
1935
|
+
title: "Dispatch: selecionar anterior",
|
|
1936
|
+
bind: "k,up"
|
|
1937
|
+
},
|
|
1938
|
+
{
|
|
1939
|
+
action: "down",
|
|
1940
|
+
id: "pantheon.dispatch.down",
|
|
1941
|
+
title: "Dispatch: selecionar próxima",
|
|
1942
|
+
bind: "j,down"
|
|
1943
|
+
},
|
|
1944
|
+
{
|
|
1945
|
+
action: "home",
|
|
1946
|
+
id: "pantheon.dispatch.home",
|
|
1947
|
+
title: "Dispatch: primeira",
|
|
1948
|
+
bind: "home"
|
|
1949
|
+
},
|
|
1950
|
+
{
|
|
1951
|
+
action: "end",
|
|
1952
|
+
id: "pantheon.dispatch.end",
|
|
1953
|
+
title: "Dispatch: última",
|
|
1954
|
+
bind: "end"
|
|
1955
|
+
},
|
|
1956
|
+
{
|
|
1957
|
+
action: "pageup",
|
|
1958
|
+
id: "pantheon.dispatch.pageup",
|
|
1959
|
+
title: "Dispatch: página acima",
|
|
1960
|
+
bind: "pageup"
|
|
1961
|
+
},
|
|
1962
|
+
{
|
|
1963
|
+
action: "pagedown",
|
|
1964
|
+
id: "pantheon.dispatch.pagedown",
|
|
1965
|
+
title: "Dispatch: página abaixo",
|
|
1966
|
+
bind: "pagedown"
|
|
1967
|
+
},
|
|
1968
|
+
{
|
|
1969
|
+
action: "toggle",
|
|
1970
|
+
id: "pantheon.dispatch.toggle",
|
|
1971
|
+
title: "Dispatch: expandir detalhe",
|
|
1972
|
+
bind: "enter"
|
|
1973
|
+
},
|
|
1974
|
+
{
|
|
1975
|
+
action: "fullscreen",
|
|
1976
|
+
id: "pantheon.dispatch.fullscreen",
|
|
1977
|
+
title: "Dispatch: tela cheia",
|
|
1978
|
+
bind: "f"
|
|
1979
|
+
},
|
|
1980
|
+
{
|
|
1981
|
+
action: "close",
|
|
1982
|
+
id: "pantheon.dispatch.close",
|
|
1983
|
+
title: "Dispatch: fechar",
|
|
1984
|
+
bind: "escape,q"
|
|
1985
|
+
}
|
|
1986
|
+
];
|
|
1987
|
+
/** Run one action against the model and the host-owned panel input. Kept apart
|
|
1988
|
+
* from the keymap so the whole command surface is testable without a renderer.
|
|
1989
|
+
*/
|
|
1990
|
+
function performDispatchPanelAction(action, model, panel) {
|
|
1991
|
+
switch (action) {
|
|
1992
|
+
case "up":
|
|
1993
|
+
model.move(-1);
|
|
1994
|
+
return;
|
|
1995
|
+
case "down":
|
|
1996
|
+
model.move(1);
|
|
1997
|
+
return;
|
|
1998
|
+
case "home":
|
|
1999
|
+
model.first();
|
|
2000
|
+
return;
|
|
2001
|
+
case "end":
|
|
2002
|
+
model.last();
|
|
2003
|
+
return;
|
|
2004
|
+
case "pageup":
|
|
2005
|
+
model.pageUp();
|
|
2006
|
+
return;
|
|
2007
|
+
case "pagedown":
|
|
2008
|
+
model.pageDown();
|
|
2009
|
+
return;
|
|
2010
|
+
case "toggle":
|
|
2011
|
+
model.toggle();
|
|
2012
|
+
return;
|
|
2013
|
+
case "fullscreen":
|
|
2014
|
+
panel.toggleFullscreen();
|
|
2015
|
+
return;
|
|
2016
|
+
case "close":
|
|
2017
|
+
panel.close();
|
|
2018
|
+
return;
|
|
2019
|
+
default: return;
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
/** Footer: the keys the host reports for each command (`keymap.shortcuts`) with
|
|
2023
|
+
* an em dash whenever a command has no binding, so the hint can never advertise
|
|
2024
|
+
* a key that does nothing. Pure. */
|
|
2025
|
+
function dispatchPanelFooter(shortcutsOf) {
|
|
2026
|
+
const keys = (id) => {
|
|
2027
|
+
let list = [];
|
|
2028
|
+
try {
|
|
2029
|
+
const result = shortcutsOf(id);
|
|
2030
|
+
list = Array.isArray(result) ? result : [];
|
|
2031
|
+
} catch {
|
|
2032
|
+
list = [];
|
|
2033
|
+
}
|
|
2034
|
+
const text = list.map((key) => String(key ?? "").trim()).filter((key) => key !== "").join("/");
|
|
2035
|
+
return text === "" ? "—" : text;
|
|
2036
|
+
};
|
|
2037
|
+
return [
|
|
2038
|
+
`${keys("pantheon.dispatch.up")} ${keys("pantheon.dispatch.down")} mover`,
|
|
2039
|
+
`${keys("pantheon.dispatch.toggle")} detalhe`,
|
|
2040
|
+
`${keys("pantheon.dispatch.fullscreen")} fullscreen`,
|
|
2041
|
+
`${keys("pantheon.dispatch.close")} fechar`
|
|
2042
|
+
].join(SPEND_LINE_SEPARATOR);
|
|
2043
|
+
}
|
|
2044
|
+
/** The subset of `PanelInput` the model reads, so tests can drive it with a
|
|
2045
|
+
* plain object. */
|
|
2046
|
+
/** `keymap.shortcuts` of one command; empty when the keymap is unavailable. */
|
|
2047
|
+
function keymapShortcuts(context, id) {
|
|
2048
|
+
try {
|
|
2049
|
+
const list = context?.keymap?.shortcuts?.(id);
|
|
2050
|
+
return Array.isArray(list) ? list : [];
|
|
2051
|
+
} catch {
|
|
2052
|
+
return [];
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
/** Open the panel from the command palette / slash command. `ui.panel.open`
|
|
2056
|
+
* only accepts a `session` route, so a refusal (no session open) is answered
|
|
2057
|
+
* with a toast — never a fallback route, never a silent no-op. Returns whether
|
|
2058
|
+
* the panel opened. */
|
|
2059
|
+
function openDispatchPanel(context) {
|
|
2060
|
+
let opened = false;
|
|
2061
|
+
try {
|
|
2062
|
+
opened = context?.ui?.panel?.open?.(DISPATCH_PANEL_NAME) === true;
|
|
2063
|
+
} catch {
|
|
2064
|
+
opened = false;
|
|
2065
|
+
}
|
|
2066
|
+
if (opened) return true;
|
|
2067
|
+
try {
|
|
2068
|
+
context?.ui?.toast?.show?.({
|
|
2069
|
+
message: DISPATCH_PANEL_TOAST,
|
|
2070
|
+
variant: "warning"
|
|
2071
|
+
});
|
|
2072
|
+
} catch {}
|
|
2073
|
+
return false;
|
|
2074
|
+
}
|
|
2075
|
+
/** Reactive state the panel view renders. Selection is held by session id, so
|
|
2076
|
+
* it survives list updates; the index is derived (and falls back to the first
|
|
2077
|
+
* row when the selected child disappears). */
|
|
2078
|
+
/** Model behind the panel. Mounted only while the panel claim renders (the
|
|
2079
|
+
* `Show` in `session.panel`), so the 80 ms tick it arms exists exactly while
|
|
2080
|
+
* the panel is open; it also stops on `isOpen()` going false and on dispose.
|
|
2081
|
+
* It performs no `message.sync`, writes no `session.metadata` and makes no
|
|
2082
|
+
* request: `collectDispatch` reads only host-cached state. */
|
|
2083
|
+
function createDispatchPanelModel(context, panel) {
|
|
2084
|
+
const [revision, setRevision] = createSignal(0);
|
|
2085
|
+
const [frame, setFrame] = createSignal(0);
|
|
2086
|
+
const [expanded, setExpanded] = createSignal(true);
|
|
2087
|
+
const [selectedID, setSelectedID] = createSignal(null);
|
|
2088
|
+
const isOpen = () => panel().name === DISPATCH_PANEL_NAME;
|
|
2089
|
+
const activeSessionID = () => {
|
|
2090
|
+
const id = panel().sessionID;
|
|
2091
|
+
return isValidSessionID(id) ? id : "";
|
|
2092
|
+
};
|
|
2093
|
+
const entries = createMemo(() => {
|
|
2094
|
+
revision();
|
|
2095
|
+
if (!isOpen()) return [];
|
|
2096
|
+
return collectDispatch(context, activeSessionID());
|
|
2097
|
+
});
|
|
2098
|
+
const layout = createMemo(() => dispatchPanelLayout(panel().width));
|
|
2099
|
+
const rows = createMemo(() => {
|
|
2100
|
+
const mode = layout();
|
|
2101
|
+
return dispatchPanelRows(entries(), {
|
|
2102
|
+
now: Date.now(),
|
|
2103
|
+
frame: frame(),
|
|
2104
|
+
max: mode.rowWidth
|
|
2105
|
+
});
|
|
2106
|
+
});
|
|
2107
|
+
const selectedIndex = createMemo(() => {
|
|
2108
|
+
const list = rows();
|
|
2109
|
+
if (list.length === 0) return 0;
|
|
2110
|
+
const id = selectedID();
|
|
2111
|
+
if (id === null) return 0;
|
|
2112
|
+
const index = list.findIndex((row) => row.id === id);
|
|
2113
|
+
return index === -1 ? 0 : index;
|
|
2114
|
+
});
|
|
2115
|
+
const selectedIDAccessor = createMemo(() => rows()[selectedIndex()]?.id ?? null);
|
|
2116
|
+
const selectedEntry = createMemo(() => entries()[selectedIndex()] ?? null);
|
|
2117
|
+
const session = createMemo(() => {
|
|
2118
|
+
revision();
|
|
2119
|
+
const id = activeSessionID();
|
|
2120
|
+
if (id === "") return void 0;
|
|
2121
|
+
try {
|
|
2122
|
+
return context.data.session.get(id);
|
|
2123
|
+
} catch {
|
|
2124
|
+
return;
|
|
2125
|
+
}
|
|
2126
|
+
});
|
|
2127
|
+
const title = createMemo(() => dispatchPanelTitle(session()?.title, 44, panel().presentation));
|
|
2128
|
+
const header = createMemo(() => dispatchPanelHeader(entries()));
|
|
2129
|
+
const detail = createMemo(() => dispatchPanelDetail(selectedEntry(), {
|
|
2130
|
+
expanded: expanded(),
|
|
2131
|
+
max: layout().detailWidth
|
|
2132
|
+
}));
|
|
2133
|
+
const visible = createMemo(() => {
|
|
2134
|
+
const list = rows();
|
|
2135
|
+
const window = dispatchPanelWindow(list.length, selectedIndex());
|
|
2136
|
+
return {
|
|
2137
|
+
start: window.start,
|
|
2138
|
+
rows: list.slice(window.start, window.end)
|
|
2139
|
+
};
|
|
2140
|
+
});
|
|
2141
|
+
const hasRunning = createMemo(() => rows().some((row) => row.state === "running"));
|
|
2142
|
+
const footer = createMemo(() => {
|
|
2143
|
+
const list = rows();
|
|
2144
|
+
const window = dispatchPanelWindow(list.length, selectedIndex());
|
|
2145
|
+
const range = dispatchPanelRangeText(window.start, window.end, list.length);
|
|
2146
|
+
const hints = dispatchPanelFooter((id) => keymapShortcuts(context, id));
|
|
2147
|
+
return range === null ? hints : `${range}${SPEND_LINE_SEPARATOR}${hints}`;
|
|
2148
|
+
});
|
|
2149
|
+
const select = (index) => {
|
|
2150
|
+
const list = rows();
|
|
2151
|
+
if (list.length === 0) return;
|
|
2152
|
+
const clamped = Math.min(list.length - 1, Math.max(0, Math.round(index)));
|
|
2153
|
+
setSelectedID(list[clamped]?.id ?? null);
|
|
2154
|
+
};
|
|
2155
|
+
onMount(() => {
|
|
2156
|
+
onCleanup(subscribeSidebarRefresh(context, () => setRevision((value) => value + 1)));
|
|
2157
|
+
});
|
|
2158
|
+
createEffect(() => {
|
|
2159
|
+
if (!isOpen() || !hasRunning()) return;
|
|
2160
|
+
const spinner = setInterval(() => setFrame((value) => value + 1), SPINNER_INTERVAL_MS);
|
|
2161
|
+
onCleanup(() => clearInterval(spinner));
|
|
2162
|
+
});
|
|
2163
|
+
return {
|
|
2164
|
+
entries,
|
|
2165
|
+
rows,
|
|
2166
|
+
title,
|
|
2167
|
+
header,
|
|
2168
|
+
detail,
|
|
2169
|
+
layout,
|
|
2170
|
+
visible,
|
|
2171
|
+
selectedID: selectedIDAccessor,
|
|
2172
|
+
selectedIndex,
|
|
2173
|
+
expanded,
|
|
2174
|
+
hasRunning,
|
|
2175
|
+
frame,
|
|
2176
|
+
footer,
|
|
2177
|
+
move: (delta) => select(selectedIndex() + (numberOrNull(delta) ?? 0)),
|
|
2178
|
+
first: () => select(0),
|
|
2179
|
+
last: () => select(rows().length - 1),
|
|
2180
|
+
pageUp: () => select(selectedIndex() - 10),
|
|
2181
|
+
pageDown: () => select(selectedIndex() + 10),
|
|
2182
|
+
toggle: () => setExpanded((value) => !value)
|
|
2183
|
+
};
|
|
2184
|
+
}
|
|
2185
|
+
/** Session ids to eagerly sync at load (deduped, bounded). Pure. */
|
|
2186
|
+
function collectWarmupTargets(sessions, limit = WARMUP_SESSION_LIMIT) {
|
|
2187
|
+
const ids = [];
|
|
2188
|
+
for (const session of sessions) {
|
|
2189
|
+
if (!isValidSessionID(session?.id) || ids.includes(session.id)) continue;
|
|
2190
|
+
ids.push(session.id);
|
|
2191
|
+
if (ids.length >= limit) break;
|
|
2192
|
+
}
|
|
2193
|
+
return ids;
|
|
2194
|
+
}
|
|
2195
|
+
/** Body a sidebar instance renders when the host has not published a real
|
|
2196
|
+
* session id yet. OpenCode V2 scopes the `sidebar.content` slot to a session
|
|
2197
|
+
* (`SlotMap["sidebar.content"] = { sessionID: string }`), so before the first
|
|
2198
|
+
* prompt the slot may not mount at all — see the `home.footer.status`
|
|
2199
|
+
* contribution for the pre-prompt degradation. Pure. */
|
|
2200
|
+
function sidebarPlaceholder(sessionID) {
|
|
2201
|
+
return isValidSessionID(sessionID) ? null : SIDEBAR_WAITING_LABEL;
|
|
2202
|
+
}
|
|
2203
|
+
/** Navigate to a session through the V2 router. Fail-open: an absent router or
|
|
2204
|
+
* a removed session must never break the sidebar. Returns whether a valid
|
|
2205
|
+
* navigation was dispatched. Pure. */
|
|
2206
|
+
function navigateToSession(router, sessionID) {
|
|
2207
|
+
if (typeof router?.navigate !== "function" || !isValidSessionID(sessionID)) return false;
|
|
2208
|
+
try {
|
|
2209
|
+
router.navigate({
|
|
2210
|
+
type: "session",
|
|
2211
|
+
sessionID
|
|
2212
|
+
});
|
|
2213
|
+
return true;
|
|
2214
|
+
} catch {
|
|
2215
|
+
return false;
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
/** Diff two delegation observations: entries that were `running` and are no
|
|
2219
|
+
* longer running count as completions, fired once per transition. Returns the
|
|
2220
|
+
* next snapshot so callers can keep a single tracker. First observation never
|
|
2221
|
+
* reports a completion (no toast spam on mount). Pure. */
|
|
2222
|
+
function detectDelegationCompletions(previous, current) {
|
|
2223
|
+
const snapshot = /* @__PURE__ */ new Map();
|
|
2224
|
+
const completed = [];
|
|
2225
|
+
for (const entry of current) {
|
|
2226
|
+
snapshot.set(entry.id, entry.state);
|
|
2227
|
+
if (previous.get(entry.id) === "running" && entry.state !== "running") completed.push(entry);
|
|
2228
|
+
}
|
|
2229
|
+
return {
|
|
2230
|
+
completed,
|
|
2231
|
+
snapshot
|
|
2232
|
+
};
|
|
2233
|
+
}
|
|
2234
|
+
function resolveLocation(context) {
|
|
2235
|
+
try {
|
|
2236
|
+
return context?.location ?? context?.data?.location?.default();
|
|
2237
|
+
} catch {
|
|
2238
|
+
return;
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
function resolveSidebarCwd(context) {
|
|
2242
|
+
const location = resolveLocation(context);
|
|
2243
|
+
if (location && typeof location.directory === "string" && location.directory !== "") return location.directory;
|
|
2244
|
+
return process.cwd();
|
|
2245
|
+
}
|
|
2246
|
+
function sessionStatusOf(context, sessionID) {
|
|
2247
|
+
try {
|
|
2248
|
+
const status = context?.data?.session?.status?.(sessionID);
|
|
2249
|
+
return typeof status === "string" ? status : void 0;
|
|
2250
|
+
} catch {
|
|
2251
|
+
return;
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
/** Subscribe `refresh` to every V2 event that can change sidebar state. Returns
|
|
2255
|
+
* a disposer that releases exactly the subscriptions the host handed out. The
|
|
2256
|
+
* event names come from the V2 union; the cast turns an unknown name into a
|
|
2257
|
+
* compile error instead of a silent no-op subscription. */
|
|
2258
|
+
function subscribeSidebarRefresh(context, refresh) {
|
|
2259
|
+
const stop = [];
|
|
2260
|
+
const data = context?.data;
|
|
2261
|
+
if (typeof data?.on === "function") for (const type of SIDEBAR_REFRESH_EVENTS) try {
|
|
2262
|
+
const unsubscribe = data.on(type, refresh);
|
|
2263
|
+
if (typeof unsubscribe === "function") stop.push(unsubscribe);
|
|
2264
|
+
} catch {}
|
|
2265
|
+
return () => {
|
|
2266
|
+
for (const unsubscribe of stop) if (typeof unsubscribe === "function") unsubscribe();
|
|
2267
|
+
};
|
|
2268
|
+
}
|
|
2269
|
+
/** Populate the cached data at load so the sidebar has content before the first
|
|
2270
|
+
* prompt (Known Issue guard). Fire-and-forget: a missing API or a failed sync
|
|
2271
|
+
* degrades silently and the sidebar still renders its static header. */
|
|
2272
|
+
function warmUpSidebarData(context, location) {
|
|
2273
|
+
try {
|
|
2274
|
+
Promise.resolve(context?.data?.location?.vcs?.sync?.(location)).catch(() => {});
|
|
2275
|
+
} catch {}
|
|
2276
|
+
let listed = [];
|
|
2277
|
+
try {
|
|
2278
|
+
const result = context?.data?.session?.list?.();
|
|
2279
|
+
if (Array.isArray(result)) listed = result;
|
|
2280
|
+
} catch {}
|
|
2281
|
+
for (const id of collectWarmupTargets(listed)) try {
|
|
2282
|
+
Promise.resolve(context?.data?.session?.sync?.(id)).catch(() => {});
|
|
2283
|
+
} catch {}
|
|
2284
|
+
}
|
|
2285
|
+
function showDelegationToast(context, done) {
|
|
2286
|
+
const variant = done.state === "failed" ? "error" : done.state === "interrupted" ? "warning" : "success";
|
|
2287
|
+
const verb = done.state === "failed" ? "falhou" : done.state === "interrupted" ? "interrompida" : "concluída";
|
|
2288
|
+
try {
|
|
2289
|
+
context?.ui?.toast?.show?.({
|
|
2290
|
+
title: TOAST_TITLE,
|
|
2291
|
+
message: `${done.label} ${verb}`,
|
|
2292
|
+
variant,
|
|
2293
|
+
sessionID: done.id
|
|
2294
|
+
});
|
|
2295
|
+
} catch {}
|
|
2296
|
+
}
|
|
2297
|
+
/** Active preset signal with mount + 30s refresh. Shared by the sidebar and the
|
|
2298
|
+
* home-screen status contribution. */
|
|
2299
|
+
function useActivePreset(context) {
|
|
2300
|
+
const [preset, setPreset] = createSignal(presetFromEnv(process.env));
|
|
2301
|
+
const [overrides, setOverrides] = createSignal(emptyOverrides());
|
|
2302
|
+
onMount(() => {
|
|
2303
|
+
const cwd = resolveSidebarCwd(context);
|
|
2304
|
+
let cancelled = false;
|
|
2305
|
+
const refresh = async () => {
|
|
2306
|
+
try {
|
|
2307
|
+
const detail = await resolveActivePresetForTui(process.env, cwd);
|
|
2308
|
+
if (!cancelled) {
|
|
2309
|
+
setPreset(detail.info);
|
|
2310
|
+
setOverrides(detail.overrides);
|
|
2311
|
+
}
|
|
2312
|
+
} catch {}
|
|
2313
|
+
};
|
|
2314
|
+
refresh();
|
|
2315
|
+
const timer = setInterval(() => void refresh(), PRESET_REFRESH_MS);
|
|
2316
|
+
onCleanup(() => {
|
|
2317
|
+
cancelled = true;
|
|
2318
|
+
clearInterval(timer);
|
|
2319
|
+
});
|
|
2320
|
+
});
|
|
2321
|
+
return {
|
|
2322
|
+
preset,
|
|
2323
|
+
overrides
|
|
2324
|
+
};
|
|
2325
|
+
}
|
|
2326
|
+
/** Debounce for the git file-count revalidation. `vcs.status` is an HTTP call;
|
|
2327
|
+
* session events arrive in bursts, so the row is refreshed at most once per
|
|
2328
|
+
* window instead of on every event. */
|
|
2329
|
+
const GIT_CHANGES_DEBOUNCE_MS = 400;
|
|
2330
|
+
/** `context.client.vcs.status(input?, requestOptions?)` →
|
|
2331
|
+
* `Promise<{ data: VcsFileStatus[] }>` (`GET /api/vcs/status`). Returns the
|
|
2332
|
+
* callable or null when the host does not expose it, so callers degrade to
|
|
2333
|
+
* the branch-only row instead of throwing. */
|
|
2334
|
+
function vcsStatusCall(context) {
|
|
2335
|
+
const status = context?.client?.vcs?.status;
|
|
2336
|
+
return typeof status === "function" ? status.bind(context.client.vcs) : null;
|
|
2337
|
+
}
|
|
2338
|
+
/** `context.client.session.stats(input?, requestOptions?)` →
|
|
2339
|
+
* `Promise<SessionStatsInfo>` (`GET /api/experimental/session/stats`), served
|
|
2340
|
+
* by the local process. Returns the callable or null when the host does not
|
|
2341
|
+
* expose it, so the Context spend line simply does not render. */
|
|
2342
|
+
function statsCall(context) {
|
|
2343
|
+
const stats = context?.client?.session?.stats;
|
|
2344
|
+
return typeof stats === "function" ? stats.bind(context.client.session) : null;
|
|
2345
|
+
}
|
|
2346
|
+
/** Local IANA zone for the stats call (`America/Sao_Paulo`); omitted when the
|
|
2347
|
+
* runtime cannot resolve one. */
|
|
2348
|
+
function localTimezone() {
|
|
2349
|
+
try {
|
|
2350
|
+
const zone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
2351
|
+
return typeof zone === "string" && zone !== "" ? zone : void 0;
|
|
2352
|
+
} catch {
|
|
2353
|
+
return;
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
/** Fields every stats call sends. `tools: 'none'` skips the tool aggregation
|
|
2357
|
+
* the block never renders; `project` is omitted (no cheap id in hand) rather
|
|
2358
|
+
* than guessed. */
|
|
2359
|
+
function statsInput() {
|
|
2360
|
+
const timezone = localTimezone();
|
|
2361
|
+
return timezone === void 0 ? { tools: "none" } : {
|
|
2362
|
+
tools: "none",
|
|
2363
|
+
timezone
|
|
2364
|
+
};
|
|
2365
|
+
}
|
|
2366
|
+
/** Convert a millisecond instant to the unit the route accepted. */
|
|
2367
|
+
function spendInstant(ms, unit) {
|
|
2368
|
+
return unit === "s" ? Math.floor(ms / 1e3) : ms;
|
|
2369
|
+
}
|
|
2370
|
+
/** Measure the `from`/`to` unit once: millisecond epoch first, then a single
|
|
2371
|
+
* seconds attempt. Bounded to two calls and never throws; anything the route
|
|
2372
|
+
* rejects (mismatch, throw, malformed echo) ends as `unavailable`, which hides
|
|
2373
|
+
* the block for the rest of the process instead of retrying forever. */
|
|
2374
|
+
async function probeSpendUnit(call) {
|
|
2375
|
+
const now = Date.now();
|
|
2376
|
+
const fromMs = now - SPEND_PROBE_WINDOW_MS;
|
|
2377
|
+
const attempts = [{
|
|
2378
|
+
sent: {
|
|
2379
|
+
from: fromMs,
|
|
2380
|
+
to: now
|
|
2381
|
+
},
|
|
2382
|
+
scale: 1,
|
|
2383
|
+
unit: "ms"
|
|
2384
|
+
}, {
|
|
2385
|
+
sent: {
|
|
2386
|
+
from: Math.floor(fromMs / 1e3),
|
|
2387
|
+
to: Math.floor(now / 1e3)
|
|
2388
|
+
},
|
|
2389
|
+
scale: 1e3,
|
|
2390
|
+
unit: "s"
|
|
2391
|
+
}];
|
|
2392
|
+
for (const attempt of attempts) try {
|
|
2393
|
+
if (statsRangeMatches((await call({
|
|
2394
|
+
...statsInput(),
|
|
2395
|
+
...attempt.sent
|
|
2396
|
+
}))?.range, attempt.sent, attempt.scale)) return attempt.unit;
|
|
2397
|
+
} catch {}
|
|
2398
|
+
return "unavailable";
|
|
2399
|
+
}
|
|
2400
|
+
/** Resolve (and cache) the unit for this process. Concurrent callers share one
|
|
2401
|
+
* probe, so a burst of refreshes cannot spend more than two calls on it. */
|
|
2402
|
+
function ensureSpendUnit(call) {
|
|
2403
|
+
if (spendUnit !== null) return Promise.resolve(spendUnit);
|
|
2404
|
+
if (spendProbe === null) spendProbe = probeSpendUnit(call).then((unit) => {
|
|
2405
|
+
spendUnit = unit;
|
|
2406
|
+
spendProbe = null;
|
|
2407
|
+
return unit;
|
|
2408
|
+
}, () => {
|
|
2409
|
+
spendUnit = "unavailable";
|
|
2410
|
+
spendProbe = null;
|
|
2411
|
+
return "unavailable";
|
|
2412
|
+
});
|
|
2413
|
+
return spendProbe;
|
|
2414
|
+
}
|
|
2415
|
+
/** Reactive state the sidebar view renders. Accessors keep the view reactive
|
|
2416
|
+
* while the model itself stays free of JSX, so its effects are exercisable
|
|
2417
|
+
* without a TUI renderer. */
|
|
2418
|
+
/** Reactive wiring behind the sidebar: refresh subscription, warm syncs, the
|
|
2419
|
+
* running-only spinner and the completion-toast effect. `context` stays loosely
|
|
2420
|
+
* typed (the host API only exists at runtime) but the refresh event names are
|
|
2421
|
+
* narrowed to the V2 union at the subscription site. */
|
|
2422
|
+
function createSidebarModel(context, sessionID, gitExec = defaultGitExec) {
|
|
2423
|
+
const [revision, setRevision] = createSignal(0);
|
|
2424
|
+
const [metricsRevision, setMetricsRevision] = createSignal(0);
|
|
2425
|
+
const [frame, setFrame] = createSignal(0);
|
|
2426
|
+
const location = resolveLocation(context);
|
|
2427
|
+
const activePreset = useActivePreset(context);
|
|
2428
|
+
const preset = activePreset.preset;
|
|
2429
|
+
const presetOverrides = activePreset.overrides;
|
|
2430
|
+
let observedStates = /* @__PURE__ */ new Map();
|
|
2431
|
+
let metricsDebounce;
|
|
2432
|
+
const scheduleMetrics = () => {
|
|
2433
|
+
if (metricsDebounce !== void 0) clearTimeout(metricsDebounce);
|
|
2434
|
+
metricsDebounce = setTimeout(() => {
|
|
2435
|
+
metricsDebounce = void 0;
|
|
2436
|
+
setMetricsRevision((value) => value + 1);
|
|
2437
|
+
}, 400);
|
|
2438
|
+
};
|
|
2439
|
+
const refresh = () => {
|
|
2440
|
+
setRevision((value) => value + 1);
|
|
2441
|
+
scheduleMetrics();
|
|
2442
|
+
};
|
|
2443
|
+
const activeSessionID = () => {
|
|
2444
|
+
const id = sessionID();
|
|
2445
|
+
return isValidSessionID(id) ? id : "";
|
|
2446
|
+
};
|
|
2447
|
+
const session = createMemo(() => {
|
|
2448
|
+
revision();
|
|
2449
|
+
const id = activeSessionID();
|
|
2450
|
+
if (id === "") return void 0;
|
|
2451
|
+
try {
|
|
2452
|
+
return context.data.session.get(id);
|
|
2453
|
+
} catch {
|
|
2454
|
+
return;
|
|
2455
|
+
}
|
|
2456
|
+
});
|
|
2457
|
+
const branch = createMemo(() => {
|
|
2458
|
+
revision();
|
|
2459
|
+
try {
|
|
2460
|
+
return context.data.location.vcs.info(location)?.branch?.current ?? null;
|
|
2461
|
+
} catch {
|
|
2462
|
+
return null;
|
|
2463
|
+
}
|
|
2464
|
+
});
|
|
2465
|
+
const [gitChangesRead, setGitChangesRead] = createSignal({
|
|
2466
|
+
session: activeSessionID(),
|
|
2467
|
+
text: null
|
|
2468
|
+
});
|
|
2469
|
+
const [gitCliRead, setGitCliRead] = createSignal({
|
|
2470
|
+
session: activeSessionID(),
|
|
2471
|
+
snapshot: null
|
|
2472
|
+
});
|
|
2473
|
+
const gitChanges = createMemo(() => {
|
|
2474
|
+
const read = gitChangesRead();
|
|
2475
|
+
return read.session === activeSessionID() ? read.text : null;
|
|
2476
|
+
});
|
|
2477
|
+
const gitCli = createMemo(() => {
|
|
2478
|
+
const read = gitCliRead();
|
|
2479
|
+
return read.session === activeSessionID() ? read.snapshot : null;
|
|
2480
|
+
});
|
|
2481
|
+
let gitRequest = 0;
|
|
2482
|
+
let gitDebounce;
|
|
2483
|
+
let gitProbeDebounce;
|
|
2484
|
+
let gitProbeSessionID = activeSessionID();
|
|
2485
|
+
let gitProbeStartedAt = null;
|
|
2486
|
+
let gitProbeInFlight = false;
|
|
2487
|
+
let disposed = false;
|
|
2488
|
+
const loadGitChanges = async () => {
|
|
2489
|
+
const status = vcsStatusCall(context);
|
|
2490
|
+
if (status === null) return;
|
|
2491
|
+
const session = activeSessionID();
|
|
2492
|
+
const request = ++gitRequest;
|
|
2493
|
+
try {
|
|
2494
|
+
const result = await status({ location: { directory: resolveSidebarCwd(context) } });
|
|
2495
|
+
if (request !== gitRequest || session !== activeSessionID()) return;
|
|
2496
|
+
const files = Array.isArray(result?.data) ? result.data : Array.isArray(result) ? result : [];
|
|
2497
|
+
setGitChangesRead({
|
|
2498
|
+
session,
|
|
2499
|
+
text: formatGitChanges(files)
|
|
2500
|
+
});
|
|
2501
|
+
} catch {}
|
|
2502
|
+
};
|
|
2503
|
+
const runGitProbe = async () => {
|
|
2504
|
+
const session = activeSessionID();
|
|
2505
|
+
if (session !== gitProbeSessionID) {
|
|
2506
|
+
gitProbeSessionID = session;
|
|
2507
|
+
gitProbeStartedAt = null;
|
|
2508
|
+
gitProbeInFlight = false;
|
|
2509
|
+
}
|
|
2510
|
+
if (!gitProbeAllowed({
|
|
2511
|
+
now: Date.now(),
|
|
2512
|
+
lastRunAt: gitProbeStartedAt,
|
|
2513
|
+
inFlight: gitProbeInFlight
|
|
2514
|
+
})) return;
|
|
2515
|
+
gitProbeInFlight = true;
|
|
2516
|
+
gitProbeStartedAt = Date.now();
|
|
2517
|
+
try {
|
|
2518
|
+
const snapshot = await readGitSnapshot(resolveSidebarCwd(context), gitExec);
|
|
2519
|
+
if (!disposed && session === activeSessionID()) setGitCliRead({
|
|
2520
|
+
session,
|
|
2521
|
+
snapshot
|
|
2522
|
+
});
|
|
2523
|
+
} catch {} finally {
|
|
2524
|
+
if (session === gitProbeSessionID) gitProbeInFlight = false;
|
|
2525
|
+
}
|
|
2526
|
+
};
|
|
2527
|
+
const scheduleGitChanges = () => {
|
|
2528
|
+
if (vcsStatusCall(context) === null) return;
|
|
2529
|
+
if (gitCli() !== null) return;
|
|
2530
|
+
if (gitDebounce !== void 0) clearTimeout(gitDebounce);
|
|
2531
|
+
gitDebounce = setTimeout(() => {
|
|
2532
|
+
gitDebounce = void 0;
|
|
2533
|
+
loadGitChanges();
|
|
2534
|
+
}, 400);
|
|
2535
|
+
};
|
|
2536
|
+
const scheduleGitProbe = () => {
|
|
2537
|
+
if (gitProbeDebounce !== void 0) clearTimeout(gitProbeDebounce);
|
|
2538
|
+
gitProbeDebounce = setTimeout(() => {
|
|
2539
|
+
gitProbeDebounce = void 0;
|
|
2540
|
+
runGitProbe();
|
|
2541
|
+
}, GIT_CLI_DEBOUNCE_MS);
|
|
2542
|
+
};
|
|
2543
|
+
const gitLine = createMemo(() => {
|
|
2544
|
+
const snapshot = gitCli();
|
|
2545
|
+
if (snapshot !== null) return formatGitSnapshot(snapshot);
|
|
2546
|
+
return gitChanges();
|
|
2547
|
+
});
|
|
2548
|
+
createEffect(on(activeSessionID, (id) => {
|
|
2549
|
+
if (disposed || id === "") return;
|
|
2550
|
+
runGitProbe();
|
|
2551
|
+
loadGitChanges();
|
|
2552
|
+
}, { defer: true }));
|
|
2553
|
+
const [spend, setSpend] = createSignal(null);
|
|
2554
|
+
let spendTotals = {
|
|
2555
|
+
today: null,
|
|
2556
|
+
thirtyDays: null
|
|
2557
|
+
};
|
|
2558
|
+
let spendRequest = 0;
|
|
2559
|
+
let spendDebounce;
|
|
2560
|
+
const loadSpend = async () => {
|
|
2561
|
+
const stats = statsCall(context);
|
|
2562
|
+
if (stats === null) return;
|
|
2563
|
+
try {
|
|
2564
|
+
const unit = await ensureSpendUnit(stats);
|
|
2565
|
+
if (unit === "unavailable") return;
|
|
2566
|
+
const request = ++spendRequest;
|
|
2567
|
+
const windows = spendWindows(Date.now());
|
|
2568
|
+
const settled = await Promise.allSettled([stats({
|
|
2569
|
+
...statsInput(),
|
|
2570
|
+
from: spendInstant(windows.today.from, unit),
|
|
2571
|
+
to: spendInstant(windows.today.to, unit)
|
|
2572
|
+
}), stats({
|
|
2573
|
+
...statsInput(),
|
|
2574
|
+
from: spendInstant(windows.thirtyDays.from, unit),
|
|
2575
|
+
to: spendInstant(windows.thirtyDays.to, unit)
|
|
2576
|
+
})]);
|
|
2577
|
+
if (request !== spendRequest) return;
|
|
2578
|
+
const next = { ...spendTotals };
|
|
2579
|
+
for (const [index, key] of ["today", "thirtyDays"].entries()) {
|
|
2580
|
+
const result = settled[index];
|
|
2581
|
+
if (result === void 0 || result.status !== "fulfilled") continue;
|
|
2582
|
+
const cost = statsCost(result.value);
|
|
2583
|
+
if (cost === null) continue;
|
|
2584
|
+
next[key] = cost;
|
|
2585
|
+
}
|
|
2586
|
+
spendTotals = next;
|
|
2587
|
+
setSpend(next);
|
|
2588
|
+
} catch {}
|
|
2589
|
+
};
|
|
2590
|
+
const scheduleSpend = () => {
|
|
2591
|
+
if (statsCall(context) === null) return;
|
|
2592
|
+
if (spendDebounce !== void 0) clearTimeout(spendDebounce);
|
|
2593
|
+
spendDebounce = setTimeout(() => {
|
|
2594
|
+
spendDebounce = void 0;
|
|
2595
|
+
loadSpend();
|
|
2596
|
+
}, 400);
|
|
2597
|
+
};
|
|
2598
|
+
const messages = createMemo(() => {
|
|
2599
|
+
revision();
|
|
2600
|
+
const id = activeSessionID();
|
|
2601
|
+
if (id === "") return [];
|
|
2602
|
+
try {
|
|
2603
|
+
const result = context.data.session.message?.list?.(id);
|
|
2604
|
+
return Array.isArray(result) ? result : [];
|
|
2605
|
+
} catch {
|
|
2606
|
+
return [];
|
|
2607
|
+
}
|
|
2608
|
+
});
|
|
2609
|
+
const familySessionIDs = createMemo(() => {
|
|
2610
|
+
revision();
|
|
2611
|
+
const id = activeSessionID();
|
|
2612
|
+
if (id === "") return [];
|
|
2613
|
+
const ids = [id];
|
|
2614
|
+
try {
|
|
2615
|
+
const result = context.data.session.family?.(id);
|
|
2616
|
+
if (Array.isArray(result)) for (const childID of result) {
|
|
2617
|
+
if (!isValidSessionID(childID) || ids.includes(childID)) continue;
|
|
2618
|
+
ids.push(childID);
|
|
2619
|
+
if (ids.length >= 8) break;
|
|
2620
|
+
}
|
|
2621
|
+
} catch {}
|
|
2622
|
+
return ids;
|
|
2623
|
+
});
|
|
2624
|
+
const transcript = createMemo(() => {
|
|
2625
|
+
metricsRevision();
|
|
2626
|
+
const rootID = activeSessionID();
|
|
2627
|
+
const collected = [];
|
|
2628
|
+
let todo = [];
|
|
2629
|
+
for (const id of familySessionIDs()) {
|
|
2630
|
+
let list = [];
|
|
2631
|
+
try {
|
|
2632
|
+
const result = context.data.session.message?.list?.(id);
|
|
2633
|
+
if (Array.isArray(result)) list = result;
|
|
2634
|
+
} catch {}
|
|
2635
|
+
collected.push(...list.slice(-400));
|
|
2636
|
+
if (id === rootID) todo = latestTodoItems(list) ?? [];
|
|
2637
|
+
}
|
|
2638
|
+
return {
|
|
2639
|
+
messages: collected,
|
|
2640
|
+
todo
|
|
2641
|
+
};
|
|
2642
|
+
});
|
|
2643
|
+
const usageMessages = createMemo(() => transcript().messages);
|
|
2644
|
+
const todo = createMemo(() => ceilingTodoItems(transcript().todo, 6));
|
|
2645
|
+
const messageCostTotal = createMemo(() => {
|
|
2646
|
+
let total = 0;
|
|
2647
|
+
for (const message of usageMessages()) {
|
|
2648
|
+
if (message?.type !== "assistant") continue;
|
|
2649
|
+
const cost = numberOrNull(message.cost);
|
|
2650
|
+
if (cost !== null && cost > 0) total += cost;
|
|
2651
|
+
}
|
|
2652
|
+
return total;
|
|
2653
|
+
});
|
|
2654
|
+
const cost = createMemo(() => {
|
|
2655
|
+
revision();
|
|
2656
|
+
const ids = familySessionIDs();
|
|
2657
|
+
if (ids.length === 0) return null;
|
|
2658
|
+
let total = 0;
|
|
2659
|
+
let found = false;
|
|
2660
|
+
for (const id of ids) {
|
|
2661
|
+
let value;
|
|
2662
|
+
try {
|
|
2663
|
+
value = context.data.session.cost?.(id);
|
|
2664
|
+
} catch {
|
|
2665
|
+
value = void 0;
|
|
2666
|
+
}
|
|
2667
|
+
let resolved = numberOrNull(value);
|
|
2668
|
+
if (resolved === null) try {
|
|
2669
|
+
resolved = numberOrNull(context.data.session.get(id)?.cost);
|
|
2670
|
+
} catch {
|
|
2671
|
+
resolved = null;
|
|
2672
|
+
}
|
|
2673
|
+
if (resolved !== null && resolved >= 0) {
|
|
2674
|
+
total += resolved;
|
|
2675
|
+
found = true;
|
|
2676
|
+
}
|
|
2677
|
+
}
|
|
2678
|
+
if (found) return Math.max(total, messageCostTotal());
|
|
2679
|
+
const fallback = messageCostTotal();
|
|
2680
|
+
return fallback > 0 ? fallback : null;
|
|
2681
|
+
});
|
|
2682
|
+
const modelUsage = createMemo(() => {
|
|
2683
|
+
metricsRevision();
|
|
2684
|
+
return ceilingModelUsage(collectModelUsage(usageMessages()), 3);
|
|
2685
|
+
});
|
|
2686
|
+
const modelRefs = createMemo(() => {
|
|
2687
|
+
revision();
|
|
2688
|
+
const current = session();
|
|
2689
|
+
const agent = typeof current?.agent === "string" && current.agent !== "" ? current.agent : "";
|
|
2690
|
+
let agentRef;
|
|
2691
|
+
if (agent !== "") try {
|
|
2692
|
+
const agents = context.data.location?.agent?.list?.(location);
|
|
2693
|
+
if (Array.isArray(agents)) agentRef = agents.find((entry) => entry?.id === agent)?.model;
|
|
2694
|
+
} catch {}
|
|
2695
|
+
const override = agent === "" ? void 0 : presetOverrides().agents[agent]?.model;
|
|
2696
|
+
return {
|
|
2697
|
+
agent,
|
|
2698
|
+
sessionRef: current?.model,
|
|
2699
|
+
agentRef,
|
|
2700
|
+
override: typeof override === "string" && override !== "" ? override : null
|
|
2701
|
+
};
|
|
2702
|
+
});
|
|
2703
|
+
const agentModel = createMemo(() => {
|
|
2704
|
+
const { agent, sessionRef, agentRef, override } = modelRefs();
|
|
2705
|
+
const model = shortModelID(override) ?? shortModelID(sessionRef) ?? shortModelID(agentRef);
|
|
2706
|
+
if (model === null) return null;
|
|
2707
|
+
return {
|
|
2708
|
+
agent,
|
|
2709
|
+
model,
|
|
2710
|
+
overridden: override !== null
|
|
2711
|
+
};
|
|
2712
|
+
});
|
|
2713
|
+
const provider = createMemo(() => {
|
|
2714
|
+
revision();
|
|
2715
|
+
const fromSession = providerIDFromRef(session()?.model);
|
|
2716
|
+
if (fromSession !== null) return fromSession;
|
|
2717
|
+
const list = messages();
|
|
2718
|
+
for (let index = list.length - 1; index >= 0; index -= 1) {
|
|
2719
|
+
const message = list[index];
|
|
2720
|
+
if (message?.type !== "assistant") continue;
|
|
2721
|
+
const fromMessage = providerIDFromRef(message.model);
|
|
2722
|
+
if (fromMessage !== null) return fromMessage;
|
|
2723
|
+
}
|
|
2724
|
+
const { agentRef } = modelRefs();
|
|
2725
|
+
const fromAgent = providerIDFromRef(agentRef);
|
|
2726
|
+
if (fromAgent !== null) return fromAgent;
|
|
2727
|
+
try {
|
|
2728
|
+
return providerIDFromModels(context.data.location?.model?.list?.(location), agentRef);
|
|
2729
|
+
} catch {
|
|
2730
|
+
return null;
|
|
2731
|
+
}
|
|
2732
|
+
});
|
|
2733
|
+
const contextUsage = createMemo(() => {
|
|
2734
|
+
const list = messages();
|
|
2735
|
+
if (list.length === 0) return null;
|
|
2736
|
+
const refs = modelRefs();
|
|
2737
|
+
const ref = [...list].reverse().find((message) => message?.type === "assistant" && message?.model)?.model ?? refs.sessionRef ?? refs.agentRef ?? refs.override;
|
|
2738
|
+
let limit = null;
|
|
2739
|
+
try {
|
|
2740
|
+
const models = context.data.location?.model?.list?.(location);
|
|
2741
|
+
limit = resolveContextLimit(Array.isArray(models) ? models : [], ref);
|
|
2742
|
+
} catch {
|
|
2743
|
+
limit = null;
|
|
2744
|
+
}
|
|
2745
|
+
return computeContextUsage(list, limit, session()?.revert?.messageID);
|
|
2746
|
+
});
|
|
2747
|
+
const cachePerformance = createMemo(() => {
|
|
2748
|
+
const message = lastAssistantWithTokens(messages(), session()?.revert?.messageID);
|
|
2749
|
+
return message === null ? null : cacheHitPercent(message.tokens);
|
|
2750
|
+
});
|
|
2751
|
+
const turnPerformance = createMemo(() => {
|
|
2752
|
+
const list = messages();
|
|
2753
|
+
let anchor = -1;
|
|
2754
|
+
for (let index = list.length - 1; index >= 0; index--) if (list[index]?.type === "assistant") {
|
|
2755
|
+
anchor = index;
|
|
2756
|
+
break;
|
|
2757
|
+
}
|
|
2758
|
+
return anchor === -1 ? null : turnTokensPerSecond(list, anchor);
|
|
2759
|
+
});
|
|
2760
|
+
const performance = createMemo(() => {
|
|
2761
|
+
const cacheHit = cachePerformance();
|
|
2762
|
+
const tokensPerSecond = turnPerformance();
|
|
2763
|
+
if (cacheHit === null && tokensPerSecond === null) return null;
|
|
2764
|
+
return {
|
|
2765
|
+
cacheHit,
|
|
2766
|
+
tokensPerSecond
|
|
2767
|
+
};
|
|
2768
|
+
});
|
|
2769
|
+
const subagentCalls = createMemo(() => collectSubagentCalls(messages()));
|
|
2770
|
+
const dispatchEntries = createMemo(() => {
|
|
2771
|
+
revision();
|
|
2772
|
+
const id = activeSessionID();
|
|
2773
|
+
if (id === "") return [];
|
|
2774
|
+
return collectDispatch(context, id, {
|
|
2775
|
+
now: Date.now(),
|
|
2776
|
+
calls: subagentCalls()
|
|
2777
|
+
});
|
|
2778
|
+
});
|
|
2779
|
+
/** What the sidebar block renders: the collector's rows, nothing else. */
|
|
2780
|
+
const allDelegations = createMemo(() => dispatchEntries().map((entry) => entry.view));
|
|
2781
|
+
const hasRunning = createMemo(() => allDelegations().some((view) => view.state === "running"));
|
|
2782
|
+
const dispatch = createMemo(() => {
|
|
2783
|
+
frame();
|
|
2784
|
+
return buildDispatchBlock(allDelegations(), Date.now(), frame());
|
|
2785
|
+
});
|
|
2786
|
+
const blocks = createMemo(() => {
|
|
2787
|
+
const present = [];
|
|
2788
|
+
if (contextBlockRows(contextUsage(), cost()) !== null || contextSpendLine(spend()) !== null) present.push("context");
|
|
2789
|
+
if (branch() !== null || gitLine() !== null) present.push("git");
|
|
2790
|
+
if (todo().visible.length > 0) present.push("todo");
|
|
2791
|
+
if (dispatch() !== null) present.push("dispatch");
|
|
2792
|
+
return withBlockSpacers(present);
|
|
2793
|
+
});
|
|
2794
|
+
onMount(() => {
|
|
2795
|
+
const unsubscribeAll = subscribeSidebarRefresh(context, () => {
|
|
2796
|
+
refresh();
|
|
2797
|
+
scheduleGitChanges();
|
|
2798
|
+
scheduleGitProbe();
|
|
2799
|
+
scheduleSpend();
|
|
2800
|
+
});
|
|
2801
|
+
const id = activeSessionID();
|
|
2802
|
+
if (id !== "") {
|
|
2803
|
+
try {
|
|
2804
|
+
Promise.resolve(context.data.session.sync(id)).then(refresh);
|
|
2805
|
+
} catch {}
|
|
2806
|
+
try {
|
|
2807
|
+
Promise.resolve(context.data.session.message?.sync?.(id)).then(refresh);
|
|
2808
|
+
} catch {}
|
|
2809
|
+
}
|
|
2810
|
+
try {
|
|
2811
|
+
Promise.resolve(context.data.location.vcs.sync(location)).then(refresh);
|
|
2812
|
+
} catch {}
|
|
2813
|
+
loadGitChanges();
|
|
2814
|
+
runGitProbe();
|
|
2815
|
+
loadSpend();
|
|
2816
|
+
createEffect(() => {
|
|
2817
|
+
if (!hasRunning()) return;
|
|
2818
|
+
const spinner = setInterval(() => setFrame((value) => value + 1), SPINNER_INTERVAL_MS);
|
|
2819
|
+
onCleanup(() => clearInterval(spinner));
|
|
2820
|
+
});
|
|
2821
|
+
onCleanup(() => {
|
|
2822
|
+
disposed = true;
|
|
2823
|
+
if (gitDebounce !== void 0) clearTimeout(gitDebounce);
|
|
2824
|
+
if (gitProbeDebounce !== void 0) clearTimeout(gitProbeDebounce);
|
|
2825
|
+
if (spendDebounce !== void 0) clearTimeout(spendDebounce);
|
|
2826
|
+
if (metricsDebounce !== void 0) clearTimeout(metricsDebounce);
|
|
2827
|
+
});
|
|
2828
|
+
onCleanup(unsubscribeAll);
|
|
2829
|
+
});
|
|
2830
|
+
let observedSessionID = activeSessionID();
|
|
2831
|
+
createEffect(() => {
|
|
2832
|
+
const id = activeSessionID();
|
|
2833
|
+
const views = allDelegations();
|
|
2834
|
+
if (id !== observedSessionID) {
|
|
2835
|
+
observedSessionID = id;
|
|
2836
|
+
observedStates = /* @__PURE__ */ new Map();
|
|
2837
|
+
}
|
|
2838
|
+
if (id === "") {
|
|
2839
|
+
observedStates = /* @__PURE__ */ new Map();
|
|
2840
|
+
return;
|
|
2841
|
+
}
|
|
2842
|
+
const { completed, snapshot } = detectDelegationCompletions(observedStates, views.map((view) => ({
|
|
2843
|
+
id: view.id,
|
|
2844
|
+
label: view.label,
|
|
2845
|
+
state: view.state
|
|
2846
|
+
})));
|
|
2847
|
+
observedStates = snapshot;
|
|
2848
|
+
for (const done of completed) showDelegationToast(context, done);
|
|
2849
|
+
});
|
|
2850
|
+
return {
|
|
2851
|
+
activeSessionID,
|
|
2852
|
+
session,
|
|
2853
|
+
branch,
|
|
2854
|
+
gitChanges,
|
|
2855
|
+
gitLine,
|
|
2856
|
+
gitCli,
|
|
2857
|
+
performance,
|
|
2858
|
+
dispatch,
|
|
2859
|
+
blocks,
|
|
2860
|
+
hasRunning,
|
|
2861
|
+
frame,
|
|
2862
|
+
preset,
|
|
2863
|
+
provider,
|
|
2864
|
+
presetOverrides,
|
|
2865
|
+
cost,
|
|
2866
|
+
modelUsage,
|
|
2867
|
+
todo,
|
|
2868
|
+
spend,
|
|
2869
|
+
contextUsage,
|
|
2870
|
+
agentModel
|
|
2871
|
+
};
|
|
2872
|
+
}
|
|
2873
|
+
/** One `Context` row: an optional toned lead segment (the gauge's filled
|
|
2874
|
+
* cells), the value, the muted gauge tail (empty cells) and the muted unit
|
|
2875
|
+
* suffix (`tokens` / `of 200K` / `spent`). */
|
|
2876
|
+
function ContextRowView(props) {
|
|
2877
|
+
return (() => {
|
|
2878
|
+
var _el$ = createElement("box"), _el$2 = createElement("text");
|
|
2879
|
+
insertNode(_el$, _el$2);
|
|
2880
|
+
setProp(_el$, "flexDirection", "row");
|
|
2881
|
+
insert(_el$, createComponent(Show, {
|
|
2882
|
+
get when() {
|
|
2883
|
+
return props.row.lead;
|
|
2884
|
+
},
|
|
2885
|
+
children: (lead) => (() => {
|
|
2886
|
+
var _el$3 = createElement("text");
|
|
2887
|
+
insert(_el$3, lead);
|
|
2888
|
+
effect((_$p) => setProp(_el$3, "fg", props.fg, _$p));
|
|
2889
|
+
return _el$3;
|
|
2890
|
+
})()
|
|
2891
|
+
}), _el$2);
|
|
2892
|
+
insert(_el$, createComponent(Show, {
|
|
2893
|
+
get when() {
|
|
2894
|
+
return props.row.tail;
|
|
2895
|
+
},
|
|
2896
|
+
children: (tail) => (() => {
|
|
2897
|
+
var _el$4 = createElement("text");
|
|
2898
|
+
insert(_el$4, tail);
|
|
2899
|
+
effect((_$p) => setProp(_el$4, "fg", props.muted, _$p));
|
|
2900
|
+
return _el$4;
|
|
2901
|
+
})()
|
|
2902
|
+
}), _el$2);
|
|
2903
|
+
insert(_el$2, () => props.row.value);
|
|
2904
|
+
insert(_el$, createComponent(Show, {
|
|
2905
|
+
get when() {
|
|
2906
|
+
return props.row.suffix;
|
|
2907
|
+
},
|
|
2908
|
+
children: (suffix) => (() => {
|
|
2909
|
+
var _el$5 = createElement("text");
|
|
2910
|
+
insert(_el$5, suffix);
|
|
2911
|
+
effect((_$p) => setProp(_el$5, "fg", props.muted, _$p));
|
|
2912
|
+
return _el$5;
|
|
2913
|
+
})()
|
|
2914
|
+
}), null);
|
|
2915
|
+
effect((_$p) => setProp(_el$2, "fg", props.fg, _$p));
|
|
2916
|
+
return _el$;
|
|
2917
|
+
})();
|
|
2918
|
+
}
|
|
2919
|
+
/** Block title: a muted single-width glyph, then the bold label. The fixed
|
|
2920
|
+
* header at the top of the sidebar deliberately renders no icon. `summary` is
|
|
2921
|
+
* the muted tail some blocks carry (`· 2 rodando · $0.47`), so the header
|
|
2922
|
+
* stays one line. */
|
|
2923
|
+
function BlockHeader(props) {
|
|
2924
|
+
return (() => {
|
|
2925
|
+
var _el$6 = createElement("box"), _el$7 = createElement("text"), _el$8 = createElement("text");
|
|
2926
|
+
insertNode(_el$6, _el$7);
|
|
2927
|
+
insertNode(_el$6, _el$8);
|
|
2928
|
+
setProp(_el$6, "flexDirection", "row");
|
|
2929
|
+
insert(_el$7, () => `${props.icon} `);
|
|
2930
|
+
setProp(_el$8, "attributes", 1);
|
|
2931
|
+
insert(_el$8, () => props.label);
|
|
2932
|
+
insert(_el$6, createComponent(Show, {
|
|
2933
|
+
get when() {
|
|
2934
|
+
return props.summary;
|
|
2935
|
+
},
|
|
2936
|
+
children: (summary) => (() => {
|
|
2937
|
+
var _el$9 = createElement("text");
|
|
2938
|
+
insert(_el$9, () => `${SPEND_LINE_SEPARATOR}${summary()}`);
|
|
2939
|
+
effect((_$p) => setProp(_el$9, "fg", props.muted, _$p));
|
|
2940
|
+
return _el$9;
|
|
2941
|
+
})()
|
|
2942
|
+
}), null);
|
|
2943
|
+
effect((_p$) => {
|
|
2944
|
+
var _v$ = props.muted, _v$2 = props.fg;
|
|
2945
|
+
_v$ !== _p$.e && (_p$.e = setProp(_el$7, "fg", _v$, _p$.e));
|
|
2946
|
+
_v$2 !== _p$.t && (_p$.t = setProp(_el$8, "fg", _v$2, _p$.t));
|
|
2947
|
+
return _p$;
|
|
2948
|
+
}, {
|
|
2949
|
+
e: void 0,
|
|
2950
|
+
t: void 0
|
|
2951
|
+
});
|
|
2952
|
+
return _el$6;
|
|
2953
|
+
})();
|
|
2954
|
+
}
|
|
2955
|
+
function Sidebar(props) {
|
|
2956
|
+
const { context } = props;
|
|
2957
|
+
const model = createSidebarModel(context, () => props.sessionID);
|
|
2958
|
+
const text = () => context.theme.text?.base;
|
|
2959
|
+
const muted = () => context.theme.text?.muted ?? text();
|
|
2960
|
+
const tone = (value) => context.theme?.text?.feedback?.[value]?.base ?? text();
|
|
2961
|
+
const todoFg = (status) => {
|
|
2962
|
+
const rowTone = todoTone(status);
|
|
2963
|
+
if (rowTone === "accent") return tone("warning");
|
|
2964
|
+
return rowTone === "muted" ? muted() : text();
|
|
2965
|
+
};
|
|
2966
|
+
const open = (sessionID) => () => navigateToSession(context.ui?.router, sessionID);
|
|
2967
|
+
const block = (key) => model.blocks().find((entry) => entry.key === key);
|
|
2968
|
+
const spacer = (key) => block(key)?.spacer === true;
|
|
2969
|
+
const usageRows = () => modelUsageRows(model.modelUsage().visible);
|
|
2970
|
+
const usageHidden = () => hiddenModelUsageText(model.modelUsage().hidden, model.modelUsage().hiddenCost);
|
|
2971
|
+
const contextRows = () => contextBlockRows(model.contextUsage(), model.cost());
|
|
2972
|
+
const spendLine = () => contextSpendLine(model.spend());
|
|
2973
|
+
const performanceLine = () => contextPerformanceLine(model.performance());
|
|
2974
|
+
const gaugeFg = (row) => contextProgressColor(row.tone ?? "warning", context.theme);
|
|
2975
|
+
const dispatchView = () => model.dispatch();
|
|
2976
|
+
const dispatchSummary = () => {
|
|
2977
|
+
const view = dispatchView();
|
|
2978
|
+
return view === null ? null : dispatchHeaderSummary(view.runningCount, view.totalCost);
|
|
2979
|
+
};
|
|
2980
|
+
const failedSuffix = () => failedSuffixText(dispatchView()?.failures);
|
|
2981
|
+
return (() => {
|
|
2982
|
+
var _el$0 = createElement("box"), _el$1 = createElement("text"), _el$10 = createElement("text");
|
|
2983
|
+
insertNode(_el$0, _el$1);
|
|
2984
|
+
insertNode(_el$0, _el$10);
|
|
2985
|
+
setProp(_el$0, "flexDirection", "column");
|
|
2986
|
+
setProp(_el$0, "width", "100%");
|
|
2987
|
+
setProp(_el$0, "padding", 1);
|
|
2988
|
+
setProp(_el$1, "attributes", 1);
|
|
2989
|
+
insert(_el$1, `Pantheon v1.6.0`);
|
|
2990
|
+
insert(_el$10, () => presetHeaderLine(model.preset().name ?? "", model.provider()));
|
|
2991
|
+
insert(_el$0, createComponent(Show, {
|
|
2992
|
+
get when() {
|
|
2993
|
+
return memo(() => model.activeSessionID() !== "")() && model.session();
|
|
2994
|
+
},
|
|
2995
|
+
get fallback() {
|
|
2996
|
+
return (() => {
|
|
2997
|
+
var _el$21 = createElement("text");
|
|
2998
|
+
insert(_el$21, () => sidebarPlaceholder(props.sessionID));
|
|
2999
|
+
effect((_$p) => setProp(_el$21, "fg", muted(), _$p));
|
|
3000
|
+
return _el$21;
|
|
3001
|
+
})();
|
|
3002
|
+
},
|
|
3003
|
+
children: (current) => (() => {
|
|
3004
|
+
var _el$22 = createElement("text");
|
|
3005
|
+
insert(_el$22, () => `Sessão: ${truncateLabel(current().title || current().id)}`);
|
|
3006
|
+
effect((_$p) => setProp(_el$22, "fg", text(), _$p));
|
|
3007
|
+
return _el$22;
|
|
3008
|
+
})()
|
|
3009
|
+
}), null);
|
|
3010
|
+
insert(_el$0, createComponent(Show, {
|
|
3011
|
+
get when() {
|
|
3012
|
+
return model.blocks().length > 0;
|
|
3013
|
+
},
|
|
3014
|
+
get children() {
|
|
3015
|
+
var _el$11 = createElement("box");
|
|
3016
|
+
setProp(_el$11, "height", 1);
|
|
3017
|
+
return _el$11;
|
|
3018
|
+
}
|
|
3019
|
+
}), null);
|
|
3020
|
+
insert(_el$0, createComponent(Show, {
|
|
3021
|
+
get when() {
|
|
3022
|
+
return block("context");
|
|
3023
|
+
},
|
|
3024
|
+
get children() {
|
|
3025
|
+
var _el$12 = createElement("box");
|
|
3026
|
+
setProp(_el$12, "flexDirection", "column");
|
|
3027
|
+
insert(_el$12, createComponent(Show, {
|
|
3028
|
+
get when() {
|
|
3029
|
+
return spacer("context");
|
|
3030
|
+
},
|
|
3031
|
+
get children() {
|
|
3032
|
+
var _el$13 = createElement("box");
|
|
3033
|
+
setProp(_el$13, "height", 1);
|
|
3034
|
+
return _el$13;
|
|
3035
|
+
}
|
|
3036
|
+
}), null);
|
|
3037
|
+
insert(_el$12, createComponent(BlockHeader, {
|
|
3038
|
+
get icon() {
|
|
3039
|
+
return BLOCK_ICONS.context;
|
|
3040
|
+
},
|
|
3041
|
+
label: "Context",
|
|
3042
|
+
get fg() {
|
|
3043
|
+
return text();
|
|
3044
|
+
},
|
|
3045
|
+
get muted() {
|
|
3046
|
+
return muted();
|
|
3047
|
+
}
|
|
3048
|
+
}), null);
|
|
3049
|
+
insert(_el$12, createComponent(Show, {
|
|
3050
|
+
get when() {
|
|
3051
|
+
return contextRows();
|
|
3052
|
+
},
|
|
3053
|
+
children: (rows) => (() => {
|
|
3054
|
+
var _el$23 = createElement("box");
|
|
3055
|
+
setProp(_el$23, "flexDirection", "column");
|
|
3056
|
+
insert(_el$23, createComponent(Show, {
|
|
3057
|
+
get when() {
|
|
3058
|
+
return rows().tokens;
|
|
3059
|
+
},
|
|
3060
|
+
children: (row) => createComponent(ContextRowView, {
|
|
3061
|
+
get row() {
|
|
3062
|
+
return row();
|
|
3063
|
+
},
|
|
3064
|
+
get fg() {
|
|
3065
|
+
return text();
|
|
3066
|
+
},
|
|
3067
|
+
get muted() {
|
|
3068
|
+
return muted();
|
|
3069
|
+
}
|
|
3070
|
+
})
|
|
3071
|
+
}), null);
|
|
3072
|
+
insert(_el$23, createComponent(Show, {
|
|
3073
|
+
get when() {
|
|
3074
|
+
return rows().percent;
|
|
3075
|
+
},
|
|
3076
|
+
children: (row) => createComponent(ContextRowView, {
|
|
3077
|
+
get row() {
|
|
3078
|
+
return row();
|
|
3079
|
+
},
|
|
3080
|
+
get fg() {
|
|
3081
|
+
return gaugeFg(row());
|
|
3082
|
+
},
|
|
3083
|
+
get muted() {
|
|
3084
|
+
return muted();
|
|
3085
|
+
}
|
|
3086
|
+
})
|
|
3087
|
+
}), null);
|
|
3088
|
+
insert(_el$23, createComponent(Show, {
|
|
3089
|
+
get when() {
|
|
3090
|
+
return rows().spent;
|
|
3091
|
+
},
|
|
3092
|
+
children: (row) => createComponent(ContextRowView, {
|
|
3093
|
+
get row() {
|
|
3094
|
+
return row();
|
|
3095
|
+
},
|
|
3096
|
+
get fg() {
|
|
3097
|
+
return text();
|
|
3098
|
+
},
|
|
3099
|
+
get muted() {
|
|
3100
|
+
return muted();
|
|
3101
|
+
}
|
|
3102
|
+
})
|
|
3103
|
+
}), null);
|
|
3104
|
+
insert(_el$23, createComponent(For, {
|
|
3105
|
+
get each() {
|
|
3106
|
+
return usageRows();
|
|
3107
|
+
},
|
|
3108
|
+
children: (row) => (() => {
|
|
3109
|
+
var _el$24 = createElement("box"), _el$25 = createElement("text"), _el$26 = createElement("text"), _el$27 = createElement("text");
|
|
3110
|
+
insertNode(_el$24, _el$25);
|
|
3111
|
+
insertNode(_el$24, _el$26);
|
|
3112
|
+
insertNode(_el$24, _el$27);
|
|
3113
|
+
setProp(_el$24, "flexDirection", "row");
|
|
3114
|
+
insert(_el$25, () => row.model.padEnd(12));
|
|
3115
|
+
insert(_el$26, () => ` ${row.tokens.padStart(6)}`);
|
|
3116
|
+
insert(_el$27, () => ` ${row.cost.padStart(8)}`);
|
|
3117
|
+
effect((_p$) => {
|
|
3118
|
+
var _v$5 = muted(), _v$6 = text(), _v$7 = text();
|
|
3119
|
+
_v$5 !== _p$.e && (_p$.e = setProp(_el$25, "fg", _v$5, _p$.e));
|
|
3120
|
+
_v$6 !== _p$.t && (_p$.t = setProp(_el$26, "fg", _v$6, _p$.t));
|
|
3121
|
+
_v$7 !== _p$.a && (_p$.a = setProp(_el$27, "fg", _v$7, _p$.a));
|
|
3122
|
+
return _p$;
|
|
3123
|
+
}, {
|
|
3124
|
+
e: void 0,
|
|
3125
|
+
t: void 0,
|
|
3126
|
+
a: void 0
|
|
3127
|
+
});
|
|
3128
|
+
return _el$24;
|
|
3129
|
+
})()
|
|
3130
|
+
}), null);
|
|
3131
|
+
insert(_el$23, createComponent(Show, {
|
|
3132
|
+
get when() {
|
|
3133
|
+
return usageHidden();
|
|
3134
|
+
},
|
|
3135
|
+
children: (line) => (() => {
|
|
3136
|
+
var _el$28 = createElement("text");
|
|
3137
|
+
insert(_el$28, line);
|
|
3138
|
+
effect((_$p) => setProp(_el$28, "fg", muted(), _$p));
|
|
3139
|
+
return _el$28;
|
|
3140
|
+
})()
|
|
3141
|
+
}), null);
|
|
3142
|
+
return _el$23;
|
|
3143
|
+
})()
|
|
3144
|
+
}), null);
|
|
3145
|
+
insert(_el$12, createComponent(Show, {
|
|
3146
|
+
get when() {
|
|
3147
|
+
return performanceLine();
|
|
3148
|
+
},
|
|
3149
|
+
children: (line) => (() => {
|
|
3150
|
+
var _el$29 = createElement("text");
|
|
3151
|
+
insert(_el$29, line);
|
|
3152
|
+
effect((_$p) => setProp(_el$29, "fg", muted(), _$p));
|
|
3153
|
+
return _el$29;
|
|
3154
|
+
})()
|
|
3155
|
+
}), null);
|
|
3156
|
+
insert(_el$12, createComponent(Show, {
|
|
3157
|
+
get when() {
|
|
3158
|
+
return spendLine();
|
|
3159
|
+
},
|
|
3160
|
+
children: (line) => (() => {
|
|
3161
|
+
var _el$30 = createElement("text");
|
|
3162
|
+
insert(_el$30, line);
|
|
3163
|
+
effect((_$p) => setProp(_el$30, "fg", muted(), _$p));
|
|
3164
|
+
return _el$30;
|
|
3165
|
+
})()
|
|
3166
|
+
}), null);
|
|
3167
|
+
return _el$12;
|
|
3168
|
+
}
|
|
3169
|
+
}), null);
|
|
3170
|
+
insert(_el$0, createComponent(Show, {
|
|
3171
|
+
get when() {
|
|
3172
|
+
return block("git");
|
|
3173
|
+
},
|
|
3174
|
+
get children() {
|
|
3175
|
+
var _el$14 = createElement("box");
|
|
3176
|
+
setProp(_el$14, "flexDirection", "column");
|
|
3177
|
+
insert(_el$14, createComponent(Show, {
|
|
3178
|
+
get when() {
|
|
3179
|
+
return spacer("git");
|
|
3180
|
+
},
|
|
3181
|
+
get children() {
|
|
3182
|
+
var _el$15 = createElement("box");
|
|
3183
|
+
setProp(_el$15, "height", 1);
|
|
3184
|
+
return _el$15;
|
|
3185
|
+
}
|
|
3186
|
+
}), null);
|
|
3187
|
+
insert(_el$14, createComponent(BlockHeader, {
|
|
3188
|
+
get icon() {
|
|
3189
|
+
return BLOCK_ICONS.git;
|
|
3190
|
+
},
|
|
3191
|
+
label: "Git status",
|
|
3192
|
+
get fg() {
|
|
3193
|
+
return text();
|
|
3194
|
+
},
|
|
3195
|
+
get muted() {
|
|
3196
|
+
return muted();
|
|
3197
|
+
}
|
|
3198
|
+
}), null);
|
|
3199
|
+
insert(_el$14, createComponent(Show, {
|
|
3200
|
+
get when() {
|
|
3201
|
+
return model.branch();
|
|
3202
|
+
},
|
|
3203
|
+
children: (value) => (() => {
|
|
3204
|
+
var _el$31 = createElement("box"), _el$32 = createElement("text"), _el$34 = createElement("text");
|
|
3205
|
+
insertNode(_el$31, _el$32);
|
|
3206
|
+
insertNode(_el$31, _el$34);
|
|
3207
|
+
setProp(_el$31, "flexDirection", "row");
|
|
3208
|
+
insertNode(_el$32, createTextNode(`⎇ `));
|
|
3209
|
+
insert(_el$34, () => truncateLabel(value(), 32));
|
|
3210
|
+
effect((_p$) => {
|
|
3211
|
+
var _v$8 = muted(), _v$9 = text();
|
|
3212
|
+
_v$8 !== _p$.e && (_p$.e = setProp(_el$32, "fg", _v$8, _p$.e));
|
|
3213
|
+
_v$9 !== _p$.t && (_p$.t = setProp(_el$34, "fg", _v$9, _p$.t));
|
|
3214
|
+
return _p$;
|
|
3215
|
+
}, {
|
|
3216
|
+
e: void 0,
|
|
3217
|
+
t: void 0
|
|
3218
|
+
});
|
|
3219
|
+
return _el$31;
|
|
3220
|
+
})()
|
|
3221
|
+
}), null);
|
|
3222
|
+
insert(_el$14, createComponent(Show, {
|
|
3223
|
+
get when() {
|
|
3224
|
+
return model.gitLine();
|
|
3225
|
+
},
|
|
3226
|
+
children: (line) => (() => {
|
|
3227
|
+
var _el$35 = createElement("text");
|
|
3228
|
+
insert(_el$35, line);
|
|
3229
|
+
effect((_$p) => setProp(_el$35, "fg", text(), _$p));
|
|
3230
|
+
return _el$35;
|
|
3231
|
+
})()
|
|
3232
|
+
}), null);
|
|
3233
|
+
return _el$14;
|
|
3234
|
+
}
|
|
3235
|
+
}), null);
|
|
3236
|
+
insert(_el$0, createComponent(Show, {
|
|
3237
|
+
get when() {
|
|
3238
|
+
return block("todo");
|
|
3239
|
+
},
|
|
3240
|
+
get children() {
|
|
3241
|
+
var _el$16 = createElement("box");
|
|
3242
|
+
setProp(_el$16, "flexDirection", "column");
|
|
3243
|
+
insert(_el$16, createComponent(Show, {
|
|
3244
|
+
get when() {
|
|
3245
|
+
return spacer("todo");
|
|
3246
|
+
},
|
|
3247
|
+
get children() {
|
|
3248
|
+
var _el$17 = createElement("box");
|
|
3249
|
+
setProp(_el$17, "height", 1);
|
|
3250
|
+
return _el$17;
|
|
3251
|
+
}
|
|
3252
|
+
}), null);
|
|
3253
|
+
insert(_el$16, createComponent(Show, {
|
|
3254
|
+
get when() {
|
|
3255
|
+
return model.todo().visible.length > 0;
|
|
3256
|
+
},
|
|
3257
|
+
get children() {
|
|
3258
|
+
var _el$18 = createElement("box");
|
|
3259
|
+
setProp(_el$18, "flexDirection", "column");
|
|
3260
|
+
insert(_el$18, createComponent(BlockHeader, {
|
|
3261
|
+
get icon() {
|
|
3262
|
+
return BLOCK_ICONS.todo;
|
|
3263
|
+
},
|
|
3264
|
+
label: "Todo",
|
|
3265
|
+
get fg() {
|
|
3266
|
+
return tone("warning");
|
|
3267
|
+
},
|
|
3268
|
+
get muted() {
|
|
3269
|
+
return muted();
|
|
3270
|
+
}
|
|
3271
|
+
}), null);
|
|
3272
|
+
insert(_el$18, createComponent(For, {
|
|
3273
|
+
get each() {
|
|
3274
|
+
return model.todo().visible;
|
|
3275
|
+
},
|
|
3276
|
+
children: (item) => (() => {
|
|
3277
|
+
var _el$36 = createElement("text");
|
|
3278
|
+
insert(_el$36, () => todoRowText(item));
|
|
3279
|
+
effect((_$p) => setProp(_el$36, "fg", todoFg(item.status), _$p));
|
|
3280
|
+
return _el$36;
|
|
3281
|
+
})()
|
|
3282
|
+
}), null);
|
|
3283
|
+
insert(_el$18, createComponent(Show, {
|
|
3284
|
+
get when() {
|
|
3285
|
+
return hiddenTodoText(model.todo().hidden);
|
|
3286
|
+
},
|
|
3287
|
+
children: (line) => (() => {
|
|
3288
|
+
var _el$37 = createElement("text");
|
|
3289
|
+
insert(_el$37, line);
|
|
3290
|
+
effect((_$p) => setProp(_el$37, "fg", muted(), _$p));
|
|
3291
|
+
return _el$37;
|
|
3292
|
+
})()
|
|
3293
|
+
}), null);
|
|
3294
|
+
return _el$18;
|
|
3295
|
+
}
|
|
3296
|
+
}), null);
|
|
3297
|
+
return _el$16;
|
|
3298
|
+
}
|
|
3299
|
+
}), null);
|
|
3300
|
+
insert(_el$0, createComponent(Show, {
|
|
3301
|
+
get when() {
|
|
3302
|
+
return block("dispatch");
|
|
3303
|
+
},
|
|
3304
|
+
get children() {
|
|
3305
|
+
var _el$19 = createElement("box");
|
|
3306
|
+
setProp(_el$19, "flexDirection", "column");
|
|
3307
|
+
insert(_el$19, createComponent(Show, {
|
|
3308
|
+
get when() {
|
|
3309
|
+
return spacer("dispatch");
|
|
3310
|
+
},
|
|
3311
|
+
get children() {
|
|
3312
|
+
var _el$20 = createElement("box");
|
|
3313
|
+
setProp(_el$20, "height", 1);
|
|
3314
|
+
return _el$20;
|
|
3315
|
+
}
|
|
3316
|
+
}), null);
|
|
3317
|
+
insert(_el$19, createComponent(Show, {
|
|
3318
|
+
get when() {
|
|
3319
|
+
return dispatchView();
|
|
3320
|
+
},
|
|
3321
|
+
children: (view) => (() => {
|
|
3322
|
+
var _el$38 = createElement("box");
|
|
3323
|
+
setProp(_el$38, "flexDirection", "column");
|
|
3324
|
+
insert(_el$38, createComponent(BlockHeader, {
|
|
3325
|
+
get icon() {
|
|
3326
|
+
return BLOCK_ICONS.dispatch;
|
|
3327
|
+
},
|
|
3328
|
+
label: "Dispatch",
|
|
3329
|
+
get fg() {
|
|
3330
|
+
return memo(() => view().runningCount > 0)() ? tone("success") : muted();
|
|
3331
|
+
},
|
|
3332
|
+
get muted() {
|
|
3333
|
+
return muted();
|
|
3334
|
+
},
|
|
3335
|
+
get summary() {
|
|
3336
|
+
return dispatchSummary();
|
|
3337
|
+
}
|
|
3338
|
+
}), null);
|
|
3339
|
+
insert(_el$38, createComponent(For, {
|
|
3340
|
+
get each() {
|
|
3341
|
+
return view().running;
|
|
3342
|
+
},
|
|
3343
|
+
children: (row) => (() => {
|
|
3344
|
+
var _el$40 = createElement("box"), _el$41 = createElement("text");
|
|
3345
|
+
insertNode(_el$40, _el$41);
|
|
3346
|
+
setProp(_el$40, "flexShrink", 0);
|
|
3347
|
+
insert(_el$41, () => row.text);
|
|
3348
|
+
effect((_p$) => {
|
|
3349
|
+
var _v$0 = open(row.id), _v$1 = tone("success");
|
|
3350
|
+
_v$0 !== _p$.e && (_p$.e = setProp(_el$40, "onMouseDown", _v$0, _p$.e));
|
|
3351
|
+
_v$1 !== _p$.t && (_p$.t = setProp(_el$41, "fg", _v$1, _p$.t));
|
|
3352
|
+
return _p$;
|
|
3353
|
+
}, {
|
|
3354
|
+
e: void 0,
|
|
3355
|
+
t: void 0
|
|
3356
|
+
});
|
|
3357
|
+
return _el$40;
|
|
3358
|
+
})()
|
|
3359
|
+
}), null);
|
|
3360
|
+
insert(_el$38, createComponent(Show, {
|
|
3361
|
+
get when() {
|
|
3362
|
+
return view().runningHidden > 0;
|
|
3363
|
+
},
|
|
3364
|
+
get children() {
|
|
3365
|
+
var _el$39 = createElement("text");
|
|
3366
|
+
insert(_el$39, () => `\u2026 +${view().runningHidden} rodando`);
|
|
3367
|
+
effect((_$p) => setProp(_el$39, "fg", muted(), _$p));
|
|
3368
|
+
return _el$39;
|
|
3369
|
+
}
|
|
3370
|
+
}), null);
|
|
3371
|
+
insert(_el$38, createComponent(Show, {
|
|
3372
|
+
get when() {
|
|
3373
|
+
return view().summary;
|
|
3374
|
+
},
|
|
3375
|
+
children: (line) => (() => {
|
|
3376
|
+
var _el$42 = createElement("box"), _el$43 = createElement("text");
|
|
3377
|
+
insertNode(_el$42, _el$43);
|
|
3378
|
+
setProp(_el$42, "flexDirection", "row");
|
|
3379
|
+
setProp(_el$42, "flexShrink", 0);
|
|
3380
|
+
insert(_el$43, line);
|
|
3381
|
+
insert(_el$42, createComponent(Show, {
|
|
3382
|
+
get when() {
|
|
3383
|
+
return failedSuffix();
|
|
3384
|
+
},
|
|
3385
|
+
children: (suffix) => (() => {
|
|
3386
|
+
var _el$44 = createElement("text");
|
|
3387
|
+
insert(_el$44, () => `${SPEND_LINE_SEPARATOR}${suffix()}`);
|
|
3388
|
+
effect((_$p) => setProp(_el$44, "fg", tone("error"), _$p));
|
|
3389
|
+
return _el$44;
|
|
3390
|
+
})()
|
|
3391
|
+
}), null);
|
|
3392
|
+
effect((_$p) => setProp(_el$43, "fg", muted(), _$p));
|
|
3393
|
+
return _el$42;
|
|
3394
|
+
})()
|
|
3395
|
+
}), null);
|
|
3396
|
+
insert(_el$38, createComponent(For, {
|
|
3397
|
+
get each() {
|
|
3398
|
+
return view().agents;
|
|
3399
|
+
},
|
|
3400
|
+
children: (row) => (() => {
|
|
3401
|
+
var _el$45 = createElement("text");
|
|
3402
|
+
insert(_el$45, () => childAgentRowText(row));
|
|
3403
|
+
effect((_$p) => setProp(_el$45, "fg", muted(), _$p));
|
|
3404
|
+
return _el$45;
|
|
3405
|
+
})()
|
|
3406
|
+
}), null);
|
|
3407
|
+
insert(_el$38, createComponent(Show, {
|
|
3408
|
+
get when() {
|
|
3409
|
+
return hiddenChildAgentsText(view().agentsHidden, view().agentsHiddenCost);
|
|
3410
|
+
},
|
|
3411
|
+
children: (line) => (() => {
|
|
3412
|
+
var _el$46 = createElement("text");
|
|
3413
|
+
insert(_el$46, line);
|
|
3414
|
+
effect((_$p) => setProp(_el$46, "fg", muted(), _$p));
|
|
3415
|
+
return _el$46;
|
|
3416
|
+
})()
|
|
3417
|
+
}), null);
|
|
3418
|
+
return _el$38;
|
|
3419
|
+
})()
|
|
3420
|
+
}), null);
|
|
3421
|
+
return _el$19;
|
|
3422
|
+
}
|
|
3423
|
+
}), null);
|
|
3424
|
+
effect((_p$) => {
|
|
3425
|
+
var _v$3 = text(), _v$4 = muted();
|
|
3426
|
+
_v$3 !== _p$.e && (_p$.e = setProp(_el$1, "fg", _v$3, _p$.e));
|
|
3427
|
+
_v$4 !== _p$.t && (_p$.t = setProp(_el$10, "fg", _v$4, _p$.t));
|
|
3428
|
+
return _p$;
|
|
3429
|
+
}, {
|
|
3430
|
+
e: void 0,
|
|
3431
|
+
t: void 0
|
|
3432
|
+
});
|
|
3433
|
+
return _el$0;
|
|
3434
|
+
})();
|
|
3435
|
+
}
|
|
3436
|
+
/** Panel actions that only make sense with a row selected. A panel over an
|
|
3437
|
+
* empty tree still owns `f`/`escape`, but the navigation keys fall through
|
|
3438
|
+
* instead of being swallowed by a no-op. */
|
|
3439
|
+
const DISPATCH_PANEL_ROW_ACTIONS = /* @__PURE__ */ new Set([
|
|
3440
|
+
"up",
|
|
3441
|
+
"down",
|
|
3442
|
+
"home",
|
|
3443
|
+
"end",
|
|
3444
|
+
"pageup",
|
|
3445
|
+
"pagedown",
|
|
3446
|
+
"toggle"
|
|
3447
|
+
]);
|
|
3448
|
+
/** One command: runs only while the panel owns the keyboard, and reports
|
|
3449
|
+
* `false` (the host keeps the key) when it cannot act. `undefined` means the
|
|
3450
|
+
* key was consumed. */
|
|
3451
|
+
function runDispatchPanelCommand(action, panel, model) {
|
|
3452
|
+
if (panel.focused !== true) return false;
|
|
3453
|
+
if (DISPATCH_PANEL_ROW_ACTIONS.has(action) && model.rows().length === 0) return false;
|
|
3454
|
+
performDispatchPanelAction(action, model, panel);
|
|
3455
|
+
}
|
|
3456
|
+
/** Keymap layer of the panel, as data. It is registered inside the
|
|
3457
|
+
* `session.panel` claim, but the host mounts the effects of *every* panel
|
|
3458
|
+
* contribution, so the layer itself is not proof of focus: without `enabled`
|
|
3459
|
+
* the `j/k/f/q/enter/escape` bindings were consumed while the panel was not
|
|
3460
|
+
* focused and the composer lost its keys. `enabled` (the documented gate) makes
|
|
3461
|
+
* the whole layer inert until `panel.focused` is true. Pure. */
|
|
3462
|
+
function dispatchPanelKeymapLayer(panel, model) {
|
|
3463
|
+
const focused = () => panel.focused === true;
|
|
3464
|
+
return {
|
|
3465
|
+
mode: "global",
|
|
3466
|
+
enabled: focused,
|
|
3467
|
+
commands: DISPATCH_PANEL_COMMANDS.map((spec) => ({
|
|
3468
|
+
id: spec.id,
|
|
3469
|
+
title: spec.title,
|
|
3470
|
+
bind: spec.bind,
|
|
3471
|
+
run: () => focused() ? runDispatchPanelCommand(spec.action, panel, model) : false
|
|
3472
|
+
}))
|
|
3473
|
+
};
|
|
3474
|
+
}
|
|
3475
|
+
/** Keymap layer of the panel. Created inside the `session.panel` claim, so the
|
|
3476
|
+
* host removes it with the panel; it renders nothing. */
|
|
3477
|
+
function DispatchPanelKeymap(props) {
|
|
3478
|
+
props.context.keymap.layer(() => dispatchPanelKeymapLayer(props.panel, props.model));
|
|
3479
|
+
return null;
|
|
3480
|
+
}
|
|
3481
|
+
/** The full-width dispatch panel: header counters, one row per child session,
|
|
3482
|
+
* the detail of the selected child and the key hints. Wide panels put the
|
|
3483
|
+
* detail beside the list; narrow ones stack it under the list and every cell is
|
|
3484
|
+
* truncated to its own column instead of wrapping. */
|
|
3485
|
+
function DispatchPanel(props) {
|
|
3486
|
+
const model = createDispatchPanelModel(props.context, () => props.panel);
|
|
3487
|
+
const text = () => props.context.theme.text?.base;
|
|
3488
|
+
const muted = () => props.context.theme.text?.muted ?? text();
|
|
3489
|
+
const tone = (value) => props.context.theme?.text?.feedback?.[value]?.base ?? text();
|
|
3490
|
+
const rowFg = (state) => {
|
|
3491
|
+
if (state === "failed") return tone("error");
|
|
3492
|
+
if (state === "running") return tone("success");
|
|
3493
|
+
if (state === "interrupted") return tone("warning");
|
|
3494
|
+
return text();
|
|
3495
|
+
};
|
|
3496
|
+
const selected = (id) => id === model.selectedID();
|
|
3497
|
+
const rows = () => createComponent(For, {
|
|
3498
|
+
get each() {
|
|
3499
|
+
return model.visible().rows;
|
|
3500
|
+
},
|
|
3501
|
+
children: (row) => (() => {
|
|
3502
|
+
var _el$47 = createElement("box"), _el$48 = createElement("text"), _el$49 = createElement("text");
|
|
3503
|
+
insertNode(_el$47, _el$48);
|
|
3504
|
+
insertNode(_el$47, _el$49);
|
|
3505
|
+
setProp(_el$47, "flexDirection", "row");
|
|
3506
|
+
setProp(_el$47, "flexShrink", 0);
|
|
3507
|
+
insert(_el$48, () => selected(row.id) ? `▸ ` : " ");
|
|
3508
|
+
insert(_el$49, () => row.text);
|
|
3509
|
+
effect((_p$) => {
|
|
3510
|
+
var _v$10 = selected(row.id) ? text() : muted(), _v$11 = rowFg(row.state), _v$12 = selected(row.id) ? 1 : 0;
|
|
3511
|
+
_v$10 !== _p$.e && (_p$.e = setProp(_el$48, "fg", _v$10, _p$.e));
|
|
3512
|
+
_v$11 !== _p$.t && (_p$.t = setProp(_el$49, "fg", _v$11, _p$.t));
|
|
3513
|
+
_v$12 !== _p$.a && (_p$.a = setProp(_el$49, "attributes", _v$12, _p$.a));
|
|
3514
|
+
return _p$;
|
|
3515
|
+
}, {
|
|
3516
|
+
e: void 0,
|
|
3517
|
+
t: void 0,
|
|
3518
|
+
a: void 0
|
|
3519
|
+
});
|
|
3520
|
+
return _el$47;
|
|
3521
|
+
})()
|
|
3522
|
+
});
|
|
3523
|
+
const detail = () => createComponent(For, {
|
|
3524
|
+
get each() {
|
|
3525
|
+
return model.detail();
|
|
3526
|
+
},
|
|
3527
|
+
children: (line, index) => (() => {
|
|
3528
|
+
var _el$50 = createElement("text");
|
|
3529
|
+
insert(_el$50, line);
|
|
3530
|
+
effect((_$p) => setProp(_el$50, "fg", index() === 0 ? text() : muted(), _$p));
|
|
3531
|
+
return _el$50;
|
|
3532
|
+
})()
|
|
3533
|
+
});
|
|
3534
|
+
const empty = () => (() => {
|
|
3535
|
+
var _el$51 = createElement("text");
|
|
3536
|
+
insertNode(_el$51, createTextNode(`Nenhuma sessão delegada`));
|
|
3537
|
+
effect((_$p) => setProp(_el$51, "fg", muted(), _$p));
|
|
3538
|
+
return _el$51;
|
|
3539
|
+
})();
|
|
3540
|
+
return (() => {
|
|
3541
|
+
var _el$53 = createElement("box"), _el$54 = createElement("text"), _el$55 = createElement("text"), _el$59 = createElement("box"), _el$60 = createElement("text");
|
|
3542
|
+
insertNode(_el$53, _el$54);
|
|
3543
|
+
insertNode(_el$53, _el$55);
|
|
3544
|
+
insertNode(_el$53, _el$59);
|
|
3545
|
+
insertNode(_el$53, _el$60);
|
|
3546
|
+
setProp(_el$53, "flexDirection", "column");
|
|
3547
|
+
setProp(_el$53, "width", "100%");
|
|
3548
|
+
setProp(_el$53, "padding", 1);
|
|
3549
|
+
insert(_el$53, createComponent(DispatchPanelKeymap, {
|
|
3550
|
+
get context() {
|
|
3551
|
+
return props.context;
|
|
3552
|
+
},
|
|
3553
|
+
get panel() {
|
|
3554
|
+
return props.panel;
|
|
3555
|
+
},
|
|
3556
|
+
model
|
|
3557
|
+
}), _el$54);
|
|
3558
|
+
setProp(_el$54, "attributes", 1);
|
|
3559
|
+
insert(_el$54, () => model.title());
|
|
3560
|
+
insert(_el$53, createComponent(Show, {
|
|
3561
|
+
get when() {
|
|
3562
|
+
return model.header();
|
|
3563
|
+
},
|
|
3564
|
+
children: (line) => (() => {
|
|
3565
|
+
var _el$61 = createElement("text");
|
|
3566
|
+
insert(_el$61, line);
|
|
3567
|
+
effect((_$p) => setProp(_el$61, "fg", muted(), _$p));
|
|
3568
|
+
return _el$61;
|
|
3569
|
+
})()
|
|
3570
|
+
}), _el$55);
|
|
3571
|
+
insert(_el$55, () => dispatchPanelRule(props.panel.width - 2));
|
|
3572
|
+
insert(_el$53, createComponent(Show, {
|
|
3573
|
+
get when() {
|
|
3574
|
+
return model.layout().mode === "wide";
|
|
3575
|
+
},
|
|
3576
|
+
get fallback() {
|
|
3577
|
+
return (() => {
|
|
3578
|
+
var _el$62 = createElement("box");
|
|
3579
|
+
setProp(_el$62, "flexDirection", "column");
|
|
3580
|
+
insert(_el$62, createComponent(Show, {
|
|
3581
|
+
get when() {
|
|
3582
|
+
return model.rows().length > 0;
|
|
3583
|
+
},
|
|
3584
|
+
get fallback() {
|
|
3585
|
+
return empty();
|
|
3586
|
+
},
|
|
3587
|
+
get children() {
|
|
3588
|
+
var _el$63 = createElement("box");
|
|
3589
|
+
setProp(_el$63, "flexDirection", "column");
|
|
3590
|
+
insert(_el$63, rows);
|
|
3591
|
+
return _el$63;
|
|
3592
|
+
}
|
|
3593
|
+
}), null);
|
|
3594
|
+
insert(_el$62, createComponent(Show, {
|
|
3595
|
+
get when() {
|
|
3596
|
+
return model.selectedID();
|
|
3597
|
+
},
|
|
3598
|
+
get children() {
|
|
3599
|
+
var _el$64 = createElement("box"), _el$65 = createElement("box");
|
|
3600
|
+
insertNode(_el$64, _el$65);
|
|
3601
|
+
setProp(_el$64, "flexDirection", "column");
|
|
3602
|
+
setProp(_el$65, "height", 1);
|
|
3603
|
+
insert(_el$64, detail, null);
|
|
3604
|
+
return _el$64;
|
|
3605
|
+
}
|
|
3606
|
+
}), null);
|
|
3607
|
+
return _el$62;
|
|
3608
|
+
})();
|
|
3609
|
+
},
|
|
3610
|
+
get children() {
|
|
3611
|
+
var _el$56 = createElement("box"), _el$57 = createElement("box");
|
|
3612
|
+
insertNode(_el$56, _el$57);
|
|
3613
|
+
setProp(_el$56, "flexDirection", "row");
|
|
3614
|
+
setProp(_el$57, "flexDirection", "column");
|
|
3615
|
+
insert(_el$57, createComponent(Show, {
|
|
3616
|
+
get when() {
|
|
3617
|
+
return model.rows().length > 0;
|
|
3618
|
+
},
|
|
3619
|
+
get fallback() {
|
|
3620
|
+
return empty();
|
|
3621
|
+
},
|
|
3622
|
+
get children() {
|
|
3623
|
+
return rows();
|
|
3624
|
+
}
|
|
3625
|
+
}));
|
|
3626
|
+
insert(_el$56, createComponent(Show, {
|
|
3627
|
+
get when() {
|
|
3628
|
+
return model.selectedID();
|
|
3629
|
+
},
|
|
3630
|
+
get children() {
|
|
3631
|
+
var _el$58 = createElement("box");
|
|
3632
|
+
setProp(_el$58, "flexDirection", "column");
|
|
3633
|
+
insert(_el$58, detail);
|
|
3634
|
+
effect((_$p) => setProp(_el$58, "width", model.layout().detailWidth, _$p));
|
|
3635
|
+
return _el$58;
|
|
3636
|
+
}
|
|
3637
|
+
}), null);
|
|
3638
|
+
effect((_$p) => setProp(_el$57, "width", model.layout().listWidth, _$p));
|
|
3639
|
+
return _el$56;
|
|
3640
|
+
}
|
|
3641
|
+
}), _el$59);
|
|
3642
|
+
setProp(_el$59, "height", 1);
|
|
3643
|
+
insert(_el$60, () => model.footer());
|
|
3644
|
+
effect((_p$) => {
|
|
3645
|
+
var _v$13 = text(), _v$14 = muted(), _v$15 = muted();
|
|
3646
|
+
_v$13 !== _p$.e && (_p$.e = setProp(_el$54, "fg", _v$13, _p$.e));
|
|
3647
|
+
_v$14 !== _p$.t && (_p$.t = setProp(_el$55, "fg", _v$14, _p$.t));
|
|
3648
|
+
_v$15 !== _p$.a && (_p$.a = setProp(_el$60, "fg", _v$15, _p$.a));
|
|
3649
|
+
return _p$;
|
|
3650
|
+
}, {
|
|
3651
|
+
e: void 0,
|
|
3652
|
+
t: void 0,
|
|
3653
|
+
a: void 0
|
|
3654
|
+
});
|
|
3655
|
+
return _el$53;
|
|
3656
|
+
})();
|
|
3657
|
+
}
|
|
3658
|
+
/** App-level command claim: the only way into the panel. It registers the
|
|
3659
|
+
* `pantheon.dispatch.open` command (palette + `/dispatch`) and renders nothing;
|
|
3660
|
+
* the panel itself lives behind its own `session.panel` claim. */
|
|
3661
|
+
function DispatchCommandLayer(props) {
|
|
3662
|
+
props.context.keymap.layer(() => ({
|
|
3663
|
+
mode: "global",
|
|
3664
|
+
commands: [{
|
|
3665
|
+
id: "pantheon.dispatch.open",
|
|
3666
|
+
title: "Pantheon: Dispatch",
|
|
3667
|
+
group: "Pantheon",
|
|
3668
|
+
palette: true,
|
|
3669
|
+
slash: {
|
|
3670
|
+
name: "dispatch",
|
|
3671
|
+
aliases: ["pantheon-dispatch"]
|
|
3672
|
+
},
|
|
3673
|
+
run: () => {
|
|
3674
|
+
openDispatchPanel(props.context);
|
|
3675
|
+
}
|
|
3676
|
+
}]
|
|
3677
|
+
}));
|
|
3678
|
+
return null;
|
|
3679
|
+
}
|
|
3680
|
+
/** Home-screen status contribution. The sidebar slot is session-scoped, so
|
|
3681
|
+
* before the first prompt the sidebar may not mount at all (Known Issue) —
|
|
3682
|
+
* this keeps a compact Pantheon line visible on the home footer meanwhile. */
|
|
3683
|
+
function HomeStatus(props) {
|
|
3684
|
+
const preset = useActivePreset(props.context).preset;
|
|
3685
|
+
const muted = () => props.context.theme?.text?.muted ?? props.context.theme?.text?.base;
|
|
3686
|
+
return (() => {
|
|
3687
|
+
var _el$66 = createElement("text");
|
|
3688
|
+
insert(_el$66, () => `Pantheon v1.6.0${preset().name ? ` ▸ ${preset().name}` : ""}`);
|
|
3689
|
+
effect((_$p) => setProp(_el$66, "fg", muted(), _$p));
|
|
3690
|
+
return _el$66;
|
|
3691
|
+
})();
|
|
3692
|
+
}
|
|
3693
|
+
/** Lean footer model: only the preset label and the live delegation count. It
|
|
3694
|
+
* deliberately does not reuse `createSidebarModel` — that model owns the
|
|
3695
|
+
* completion toasts and the spinner, and a second instance would double-toast.
|
|
3696
|
+
* No session id in the slot input is a graceful no-op (count 0). */
|
|
3697
|
+
function createFooterModel(context, sessionID) {
|
|
3698
|
+
const [revision, setRevision] = createSignal(0);
|
|
3699
|
+
const preset = useActivePreset(context).preset;
|
|
3700
|
+
const activeSessionID = () => {
|
|
3701
|
+
const id = sessionID();
|
|
3702
|
+
return isValidSessionID(id) ? id : "";
|
|
3703
|
+
};
|
|
3704
|
+
const running = createMemo(() => {
|
|
3705
|
+
revision();
|
|
3706
|
+
const id = activeSessionID();
|
|
3707
|
+
if (id === "") return 0;
|
|
3708
|
+
let family = [];
|
|
3709
|
+
try {
|
|
3710
|
+
const result = context.data.session.family?.(id);
|
|
3711
|
+
if (Array.isArray(result)) family = result;
|
|
3712
|
+
} catch {
|
|
3713
|
+
return 0;
|
|
3714
|
+
}
|
|
3715
|
+
const now = Date.now();
|
|
3716
|
+
let count = 0;
|
|
3717
|
+
for (const childID of family) {
|
|
3718
|
+
if (childID === id || !isValidSessionID(childID)) continue;
|
|
3719
|
+
try {
|
|
3720
|
+
const child = context.data.session.get(childID);
|
|
3721
|
+
if (child?.parentID !== id) continue;
|
|
3722
|
+
if (toDelegationView(child, sessionStatusOf(context, childID), now).state === "running") count += 1;
|
|
3723
|
+
} catch {}
|
|
3724
|
+
}
|
|
3725
|
+
return count;
|
|
3726
|
+
});
|
|
3727
|
+
onMount(() => {
|
|
3728
|
+
onCleanup(subscribeSidebarRefresh(context, () => setRevision((value) => value + 1)));
|
|
3729
|
+
});
|
|
3730
|
+
return {
|
|
3731
|
+
preset,
|
|
3732
|
+
running
|
|
3733
|
+
};
|
|
3734
|
+
}
|
|
3735
|
+
/** Prompt-footer contribution: `▸<preset> · ✦<n> ativos`, appended next to the
|
|
3736
|
+
* native line (never replacing it) and only while a delegation is running. */
|
|
3737
|
+
function PromptFooter(props) {
|
|
3738
|
+
const model = createFooterModel(props.context, () => props.sessionID);
|
|
3739
|
+
const muted = () => props.context.theme?.text?.muted ?? props.context.theme?.text?.base;
|
|
3740
|
+
return createComponent(Show, {
|
|
3741
|
+
get when() {
|
|
3742
|
+
return model.running() > 0;
|
|
3743
|
+
},
|
|
3744
|
+
get children() {
|
|
3745
|
+
var _el$67 = createElement("text");
|
|
3746
|
+
insert(_el$67, () => `▸${model.preset().name ?? "default"} · ✦${model.running()} ativos`);
|
|
3747
|
+
effect((_$p) => setProp(_el$67, "fg", muted(), _$p));
|
|
3748
|
+
return _el$67;
|
|
3749
|
+
}
|
|
3750
|
+
});
|
|
3751
|
+
}
|
|
3752
|
+
const plugin = Plugin.define({
|
|
3753
|
+
id: "pantheon.tui",
|
|
3754
|
+
setup(context) {
|
|
3755
|
+
const globalState = globalThis;
|
|
3756
|
+
if (globalState[SINGLETON]) return;
|
|
3757
|
+
globalState[SINGLETON] = true;
|
|
3758
|
+
warmUpSidebarData(context, resolveLocation(context));
|
|
3759
|
+
const unregisterSidebar = context.ui.slot({
|
|
3760
|
+
append: "sidebar.content",
|
|
3761
|
+
render: ({ sessionID }) => createComponent(Sidebar, {
|
|
3762
|
+
context,
|
|
3763
|
+
sessionID
|
|
3764
|
+
})
|
|
3765
|
+
});
|
|
3766
|
+
const unregisterHome = context.ui.slot({
|
|
3767
|
+
append: "home.footer.status",
|
|
3768
|
+
render: () => createComponent(HomeStatus, { context })
|
|
3769
|
+
});
|
|
3770
|
+
const unregisterPromptFooter = context.ui.slot({
|
|
3771
|
+
append: "prompt.footer",
|
|
3772
|
+
render: ({ sessionID }) => createComponent(PromptFooter, {
|
|
3773
|
+
context,
|
|
3774
|
+
sessionID
|
|
3775
|
+
})
|
|
3776
|
+
});
|
|
3777
|
+
const unregisterPanel = context.ui.slot({
|
|
3778
|
+
append: "session.panel",
|
|
3779
|
+
render: (panel) => createComponent(Show, {
|
|
3780
|
+
get when() {
|
|
3781
|
+
return panel.name === DISPATCH_PANEL_NAME;
|
|
3782
|
+
},
|
|
3783
|
+
get children() {
|
|
3784
|
+
return createComponent(DispatchPanel, {
|
|
3785
|
+
context,
|
|
3786
|
+
panel
|
|
3787
|
+
});
|
|
3788
|
+
}
|
|
3789
|
+
})
|
|
3790
|
+
});
|
|
3791
|
+
const unregisterCommands = context.ui.slot({
|
|
3792
|
+
append: "app",
|
|
3793
|
+
render: () => createComponent(DispatchCommandLayer, { context })
|
|
3794
|
+
});
|
|
3795
|
+
return () => {
|
|
3796
|
+
if (typeof unregisterSidebar === "function") unregisterSidebar();
|
|
3797
|
+
if (typeof unregisterHome === "function") unregisterHome();
|
|
3798
|
+
if (typeof unregisterPromptFooter === "function") unregisterPromptFooter();
|
|
3799
|
+
if (typeof unregisterPanel === "function") unregisterPanel();
|
|
3800
|
+
if (typeof unregisterCommands === "function") unregisterCommands();
|
|
3801
|
+
delete globalState[SINGLETON];
|
|
3802
|
+
};
|
|
3803
|
+
}
|
|
3804
|
+
});
|
|
3805
|
+
//#endregion
|
|
3806
|
+
export { BLOCK_ICONS, CONTEXT_BAR_CELLS, CONTEXT_BAR_EMPTY_CELL, CONTEXT_BAR_FILLED_CELL, DELEGATION_CHILD_STATUS_GRACE_MS, DISPATCH_AGENT_CEILING, DISPATCH_AGENT_WIDTH, DISPATCH_COST_WIDTH, DISPATCH_COUNT_WIDTH, DISPATCH_DONE_MARKER, DISPATCH_DURATION_WIDTH, DISPATCH_GROUP_COST_WIDTH, DISPATCH_KIND_ORIGIN_LABELS, DISPATCH_MAX_LINES, DISPATCH_MAX_WIDTH, DISPATCH_MIN_AGENT_WIDTH, DISPATCH_MODEL_WIDTH, DISPATCH_PANEL_AGENT_WIDTH, DISPATCH_PANEL_COMMANDS, DISPATCH_PANEL_COST_WIDTH, DISPATCH_PANEL_DASH, DISPATCH_PANEL_DURATION_WIDTH, DISPATCH_PANEL_EMPTY_TEXT, DISPATCH_PANEL_FULLSCREEN_BADGE, DISPATCH_PANEL_HEADER_MARKER, DISPATCH_PANEL_KIND_WIDTH, DISPATCH_PANEL_MIN_AGENT_WIDTH, DISPATCH_PANEL_NAME, DISPATCH_PANEL_PAGE_SIZE, DISPATCH_PANEL_RULE_CHAR, DISPATCH_PANEL_SELECTION_GUTTER, DISPATCH_PANEL_SELECTION_MARKER, DISPATCH_PANEL_TITLE_WIDTH, DISPATCH_PANEL_TOAST, DISPATCH_PANEL_WIDE_MIN_WIDTH, DISPATCH_RUNNING_CEILING, GIT_ARROW_DOWN, GIT_ARROW_UP, GIT_CHANGES_DEBOUNCE_MS, GIT_CLI_DEBOUNCE_MS, GIT_CLI_MAX_BUFFER, GIT_CLI_MIN_INTERVAL_MS, GIT_CLI_TIMEOUT_MS, HEADER_MAX_WIDTH, MODEL_USAGE_COST_WIDTH, MODEL_USAGE_DEBOUNCE_MS, MODEL_USAGE_MESSAGE_LIMIT, MODEL_USAGE_MODEL_WIDTH, MODEL_USAGE_SESSION_LIMIT, MODEL_USAGE_TOKEN_WIDTH, MODEL_USAGE_VISIBLE_CEILING, PRESET_MARKER, SIDEBAR_REFRESH_EVENTS, SIDEBAR_WAITING_LABEL, SPEND_30D_LABEL, SPEND_30D_MS, SPEND_LINE_SEPARATOR, SPEND_PROBE_TOLERANCE_MS, SPEND_PROBE_WINDOW_MS, SPEND_REFRESH_DEBOUNCE_MS, SPEND_TODAY_LABEL, TODO_TEXT_WIDTH, TODO_VISIBLE_CEILING, UNKNOWN_AGENT, agentKey, buildDispatchBlock, cacheHitPercent, ceilingModelUsage, ceilingTodoItems, cellWidth, childAgentRowText, classifyDispatchKind, collectChildAgentUsage, collectDispatch, collectModelUsage, collectSubagentCalls, collectWarmupTargets, completedSummaryText, computeContextUsage, contextBar, contextBarFilled, contextBlockRows, contextPerformanceLine, contextProgressColor, contextSpendLine, contextUsageTone, countGitChanges, createDispatchPanelModel, createFooterModel, createSidebarModel, plugin as default, defaultGitExec, delegationStateFromOutcome, delegationStateFromStatus, detectDelegationCompletions, dispatchAgentText, dispatchElapsed, dispatchHeaderSummary, dispatchKindFromAgent, dispatchKindFromPrefix, dispatchKindSuffix, dispatchModelText, dispatchPanelCell, dispatchPanelDetail, dispatchPanelFooter, dispatchPanelHeader, dispatchPanelKeymapLayer, dispatchPanelLayout, dispatchPanelMarker, dispatchPanelRangeText, dispatchPanelRowText, dispatchPanelRows, dispatchPanelRule, dispatchPanelTitle, dispatchPanelWindow, dispatchTokenLine, dispatchTokens, dispatchTotalCost, failedSuffixText, formatContextWindow, formatDispatchCost, formatDispatchDuration, formatGitChanges, formatGitSnapshot, formatSpendUSD, formatSpent, formatTokenCount, formatUsageCost, formatUsageTokens, gitProbeAllowed, hiddenChildAgentsText, hiddenModelUsageText, hiddenTodoText, isTodoStatus, isValidSessionID, lastAssistantWithTokens, latestTodoItems, messageTokensTotal, modelRefID, modelUsageRowText, modelUsageRows, navigateToSession, openDispatchPanel, orderDispatchEntries, orderTodoItems, padCell, parseGitAheadBehind, parseGitStatusPorcelain, parsePresetOverrides, parseTodoItems, performDispatchPanelAction, presetFromEnv, presetHeaderLine, providerIDFromModels, providerIDFromRef, readGitSnapshot, resetSpendUnit, resolveActivePresetForTui, resolveContextLimit, resolvedSpendUnit, runDispatchPanelCommand, runningChildRowText, shortModelID, shortSessionID, sidebarPlaceholder, spendWindows, spinnerFrame, startOfLocalDay, statsCost, statsRangeMatches, toDelegationView, toDispatchEntry, todoRowText, todoTone, transcriptWindow, truncateLabel, turnTokensPerSecond, withBlockSpacers };
|
|
3807
|
+
|
|
3808
|
+
//# sourceMappingURL=tui-v2.js.map
|