pantheon-opencode 1.7.0 → 2.0.0-beta.2
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 +2 -2
- package/AGENTS.md +3 -3
- package/CHANGELOG.md +85 -59
- package/README.md +74 -48
- package/README.pt-BR.md +19 -19
- package/bin/pantheon-init.mjs +11 -48
- package/package.json +9 -13
- package/plugin.json +2 -2
- package/pyproject.toml +1 -1
- package/scripts/build-agents-md.mjs +7 -6
- package/scripts/{check-plugin-v2-coverage.mjs → check-plugin-coverage.mjs} +7 -7
- package/scripts/{decision-router-v2-budget.mjs → decision-router-budget-gates.mjs} +1 -1
- package/scripts/{decision-router-v2-egress.mjs → decision-router-egress.mjs} +1 -1
- package/scripts/decision-router.mjs +2 -2
- package/scripts/docs-media.mjs +1 -1
- package/scripts/doctor.mjs +225 -136
- package/scripts/install/behavior-overrides.bundle.mjs +123 -0
- package/scripts/install/{v2-capabilities.mjs → capabilities.mjs} +7 -7
- package/scripts/install/config-migration.mjs +60 -253
- package/scripts/install/file-inventory.mjs +6 -4
- package/scripts/install/interactive.mjs +1 -1
- package/scripts/install/opencode-state.mjs +13 -12
- package/scripts/install/opencode-version.mjs +97 -162
- package/scripts/install/opencode.mjs +271 -428
- package/scripts/install/plan.mjs +1 -9
- package/scripts/install/plugin.mjs +19 -35
- package/scripts/install/shared.mjs +40 -1
- package/scripts/package-evidence.mjs +1 -4
- package/scripts/probe-pantheon-cost.mjs +1 -1
- package/scripts/reconcile.mjs +5 -7
- package/scripts/release-gates.mjs +22 -61
- package/scripts/setup-v2-config.mjs +10 -8
- package/scripts/setup.mjs +12 -22
- package/scripts/sync-tui.mjs +9 -17
- package/scripts/{test-opencode-v2-sandbox.sh → test-opencode-sandbox.sh} +9 -9
- package/scripts/update-skills-lock.mjs +24 -12
- package/scripts/update.mjs +17 -1
- package/scripts/validate-routing.mjs +79 -4
- package/scripts/validate-sandbox-install.mjs +3 -3
- package/skills-lock.json +25 -8
- package/src/agents/zeus.md +1 -0
- package/src/pantheon/behavior-overrides.ts +191 -0
- package/src/pantheon/{v2-bounded-read.ts → bounded-read.ts} +1 -1
- package/src/pantheon/cost-command.ts +1 -1
- package/src/pantheon/{v2-decision-contracts.ts → decision-contracts.ts} +3 -3
- package/src/pantheon/{v2-decision-points → decision-points}/p1-agent.ts +3 -3
- package/src/pantheon/{v2-decision-points → decision-points}/p10-claims.ts +2 -2
- package/src/pantheon/{v2-decision-points → decision-points}/p11-catalog.ts +2 -2
- package/src/pantheon/{v2-decision-points → decision-points}/p2-skill.ts +3 -3
- package/src/pantheon/{v2-decision-points → decision-points}/p3-complexity.ts +6 -6
- package/src/pantheon/{v2-decision-points → decision-points}/p4-memory.ts +2 -2
- package/src/pantheon/{v2-decision-points → decision-points}/p5-themis-verify.ts +2 -2
- package/src/pantheon/{v2-decision-points → decision-points}/p6-council.ts +3 -3
- package/src/pantheon/{v2-decision-points → decision-points}/p7-loop.ts +5 -5
- package/src/pantheon/{v2-decision-points → decision-points}/p8-guardrail.ts +2 -2
- package/src/pantheon/{v2-decision-points → decision-points}/p9-memory-compaction.ts +2 -2
- package/src/pantheon/{v2-decision-points.ts → decision-points.ts} +5 -5
- package/src/pantheon/{v2-decision-policy.ts → decision-policy.ts} +2 -2
- package/src/pantheon/{v2-decision-prompt-surface.ts → decision-prompt-surface.ts} +3 -3
- package/src/pantheon/{v2-decision-registry.ts → decision-registry.ts} +10 -13
- package/src/pantheon/{v2-decision-resource-ids.ts → decision-resource-ids.ts} +1 -1
- package/src/pantheon/{v2-decision-shadow.ts → decision-shadow.ts} +1 -1
- package/src/pantheon/{v2-decision-telemetry.ts → decision-telemetry.ts} +1 -1
- package/src/pantheon/{v2-execute-after.ts → execute-after.ts} +4 -4
- package/src/pantheon/goal-store.ts +7 -0
- package/src/pantheon/{v2-hook-engine.ts → hook-engine.ts} +3 -3
- package/src/pantheon/jev-decision-tool.ts +3 -3
- package/src/pantheon/jev-decisions.ts +12 -6
- package/src/pantheon/jev-escalation.ts +6 -6
- package/src/pantheon/jev-quality-score.ts +2 -2
- package/src/pantheon/jev-rank-verify.ts +2 -2
- package/src/pantheon/jev-risk-gate.ts +4 -4
- package/src/pantheon/local-decision-agents.ts +1 -1
- package/src/pantheon/local-decision-router.ts +1 -1
- package/src/pantheon/local-decision-tool.ts +2 -2
- package/src/pantheon/local-orchestration.ts +1 -1
- package/src/pantheon/model-command.ts +1 -1
- package/src/pantheon/{v2-vision.ts → native-vision.ts} +12 -15
- package/src/pantheon/pantheon-decision-catalog.ts +12 -0
- package/src/pantheon/{v2-shell-hooks.ts → shell-hooks.ts} +4 -4
- package/src/pantheon/{v2-tools.ts → tools.ts} +4 -4
- package/src/pantheon/{v2-unsupported.d.mts → unsupported.d.mts} +3 -3
- package/src/pantheon/{v2-unsupported.mjs → unsupported.mjs} +8 -8
- package/src/pantheon/update-notifier.ts +101 -0
- package/src/pantheon/vision-local.ts +12 -3
- package/src/pantheon/vision.ts +120 -2
- package/src/{plugin-v2 → plugin}/index.ts +7 -7
- package/src/plugin.ts +2870 -500
- package/src/plugins/hook-runner.ts +3 -3
- package/src/plugins/tui/dist/server.d.ts +23 -9
- package/src/plugins/tui/dist/server.d.ts.map +1 -1
- package/src/plugins/tui/dist/server.js +25 -12
- package/src/plugins/tui/dist/server.js.map +1 -1
- package/src/plugins/tui/dist/tui.d.ts +1023 -494
- package/src/plugins/tui/dist/tui.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui.js +5612 -2086
- package/src/plugins/tui/dist/tui.js.map +1 -1
- package/src/plugins/tui/{index-v2.ts → index.ts} +1 -1
- package/src/plugins/tui/package-lock.json +2 -42
- package/src/plugins/tui/package.json +4 -10
- package/src/plugins/tui/src/cost-data.ts +1 -1
- package/src/plugins/tui/src/decision-router-state.ts +242 -0
- package/src/plugins/tui/src/doctor-state.ts +198 -0
- package/src/plugins/tui/src/index.tsx +4222 -2822
- package/src/plugins/tui/src/j1-gate-status.ts +85 -0
- package/src/plugins/tui/src/pantheon-settings-state.ts +245 -0
- package/src/plugins/tui/src/pantheon-settings.tsx +442 -0
- package/src/plugins/tui/src/preset-state.ts +143 -0
- package/src/plugins/tui/src/server.ts +23 -10
- package/src/plugins/tui/src/update-notice.ts +90 -0
- package/src/plugins/tui/src/update-status.ts +98 -0
- package/src/plugins/tui/tsconfig.typecheck.json +9 -2
- package/src/plugins/tui/tsdown.config.ts +3 -5
- package/src/plugins/tui/tui.ts +1 -2
- package/src/routing.yml +36 -0
- package/src/skills/README.md +16 -1
- package/src/skills/artifact-management/SKILL.md +10 -67
- package/src/skills/artifact-management/references/artifact-templates.md +71 -0
- package/src/skills/auto-continue/SKILL.md +10 -0
- package/src/skills/code-review-checklist/SKILL.md +11 -44
- package/src/skills/code-review-checklist/references/review-checklists.md +54 -0
- package/src/skills/instruction-forge/SKILL.md +57 -0
- package/src/skills/instruction-forge/references/agents-md-doctrine.md +50 -0
- package/src/skills/instruction-forge/references/eval-doctrine.md +37 -0
- package/src/skills/instruction-forge/references/skill-doctrine.md +62 -0
- package/src/skills/memory-bank/SKILL.md +11 -90
- package/src/skills/memory-bank/references/anti-patterns.md +33 -0
- package/src/skills/memory-bank/references/product-adoption.md +19 -0
- package/src/skills/memory-bank/references/storage-model.md +21 -0
- package/src/skills/memory-bank/references/structure-and-frequency.md +44 -0
- package/src/skills/reflect/SKILL.md +1 -0
- package/src/skills/session-goal/SKILL.md +7 -54
- package/src/skills/session-goal/references/goal-format.md +26 -0
- package/src/skills/session-goal/references/session-reuse.md +44 -0
- package/src/skills/tdd-with-agents/SKILL.md +11 -101
- package/src/skills/tdd-with-agents/references/advanced-testing-patterns.md +58 -0
- package/src/skills/tdd-with-agents/references/testing-by-layer.md +60 -0
- package/src/skills/visual-review-pipeline/SKILL.md +11 -120
- package/src/skills/visual-review-pipeline/references/findings-schema.md +49 -0
- package/src/skills/visual-review-pipeline/references/workflow-steps.md +111 -0
- package/scripts/hooks/log-session-start.sh +0 -48
- package/scripts/hooks/validate-post-conditions.sh +0 -21
- package/scripts/hooks/validate-talos-scope.sh +0 -50
- package/scripts/hooks/validate-tool-safety.sh +0 -49
- package/src/pantheon/goal-loop.ts +0 -314
- package/src/pantheon/idle-continuation.ts +0 -52
- package/src/pantheon/todo-preserve.ts +0 -301
- package/src/pantheon/tool-ceiling.ts +0 -159
- package/src/pantheon/v2-bridge.ts +0 -153
- package/src/plugin-v2.ts +0 -2954
- package/src/plugins/pantheon-hooks.ts +0 -1433
- package/src/plugins/tui/dist/server-v2.d.ts +0 -30
- package/src/plugins/tui/dist/server-v2.d.ts.map +0 -1
- package/src/plugins/tui/dist/server-v2.js +0 -33
- package/src/plugins/tui/dist/server-v2.js.map +0 -1
- package/src/plugins/tui/dist/tui-v2.d.ts +0 -1039
- package/src/plugins/tui/dist/tui-v2.d.ts.map +0 -1
- package/src/plugins/tui/dist/tui-v2.js +0 -4597
- package/src/plugins/tui/dist/tui-v2.js.map +0 -1
- package/src/plugins/tui/src/index-v2.tsx +0 -4496
- package/src/plugins/tui/src/server-v2.ts +0 -28
- package/src/plugins/tui/tui-v2.ts +0 -2
- /package/src/pantheon/{v2-decision-budget.ts → decision-budget.ts} +0 -0
- /package/src/pantheon/{v2-decision-egress.ts → decision-egress.ts} +0 -0
- /package/src/pantheon/{v2-decision-events.ts → decision-events.ts} +0 -0
- /package/src/pantheon/{v2-decision-heuristic.ts → decision-heuristic.ts} +0 -0
- /package/src/pantheon/{v2-decision-premises.ts → decision-premises.ts} +0 -0
- /package/src/pantheon/{v2-decision-rank.ts → decision-rank.ts} +0 -0
- /package/src/pantheon/{v2-decision-verify.ts → decision-verify.ts} +0 -0
- /package/src/pantheon/{v2-delegation-enforce.ts → delegation-policy.ts} +0 -0
- /package/src/pantheon/{v2-model-overrides.ts → model-overrides.ts} +0 -0
- /package/src/pantheon/{v2-native-decisions.ts → native-decisions.ts} +0 -0
- /package/src/plugins/tui/src/{opencode-v2.d.ts → opencode.d.ts} +0 -0
|
@@ -1,510 +1,1039 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Accessor } from "solid-js";
|
|
2
|
+
import { Context, KeymapLayer, PanelInput } from "@opencode/plugin/tui/context";
|
|
3
|
+
//#region src/context-gauge.d.ts
|
|
4
|
+
/** Shared, data-only formatting and visual helpers for compact context gauges. */
|
|
5
|
+
type ContextProgressTone = 'info' | 'success' | 'warning' | 'error';
|
|
6
|
+
export declare const CONTEXT_BAR_CELLS = 12;
|
|
7
|
+
export declare const CONTEXT_BAR_FILLED_CELL = "▰";
|
|
8
|
+
export declare const CONTEXT_BAR_EMPTY_CELL = "▱";
|
|
9
|
+
export declare function contextUsageTone(percent: number): ContextProgressTone;
|
|
10
|
+
export declare function formatTokenCount(tokens: number | null | undefined): string | null;
|
|
11
|
+
export declare function formatContextWindow(limit: number | null | undefined): string | null;
|
|
12
|
+
export declare function contextBarFilled(percent: number, cells?: number): number;
|
|
13
|
+
export declare function contextBar(percent: number | null | undefined, cells?: number): {
|
|
14
|
+
filled: string;
|
|
15
|
+
empty: string;
|
|
16
|
+
} | null;
|
|
17
|
+
export declare function formatSpent(cost: number | null | undefined): string | null;
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/model-usage-limits.d.ts
|
|
20
|
+
/** Shared bounds for cached recent model-usage aggregation. */
|
|
21
|
+
export declare const MODEL_USAGE_VISIBLE_CEILING = 3;
|
|
22
|
+
export declare const MODEL_USAGE_MESSAGE_LIMIT = 400;
|
|
23
|
+
export declare const MODEL_USAGE_SESSION_LIMIT = 8;
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/sidebar-width.d.ts
|
|
26
|
+
/** Terminal cells `value` occupies — the unit every column in this plugin is
|
|
27
|
+
* measured in. Mirrors the host (that is how `@opentui/core` sizes a text
|
|
28
|
+
* run): emoji count as two cells, East Asian Wide/Fullwidth as two, East
|
|
29
|
+
* Asian Ambiguous as one, combining marks and variation selectors as none.
|
|
30
|
+
* Pure. */
|
|
31
|
+
export declare function cellWidth(value: string): number;
|
|
32
|
+
//#endregion
|
|
2
33
|
//#region src/index.d.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
*
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
*
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
*
|
|
59
|
-
export declare function
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
*
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
export declare function
|
|
79
|
-
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
*
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
*
|
|
103
|
-
|
|
104
|
-
export declare
|
|
105
|
-
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
export declare
|
|
115
|
-
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* `
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
*
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
export
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
*
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
34
|
+
/** Sidebar body shown while the host has not published a session yet. */
|
|
35
|
+
export declare const SIDEBAR_WAITING_LABEL = "Aguardando sessão…";
|
|
36
|
+
/** Marker before the preset label (fixed header, home status, prompt footer).
|
|
37
|
+
* `▸` U+25B8 is one cell; the previous bolt (U+26A1) carries
|
|
38
|
+
* Emoji_Presentation and is measured as two cells, which misaligned the line. */
|
|
39
|
+
export declare const PRESET_MARKER = "▸";
|
|
40
|
+
/** Git ahead / behind arrows (U+2191 / U+2193), one cell each — the glyphs the
|
|
41
|
+
* reference sidebars use for `↑ahead ↓behind`. */
|
|
42
|
+
export declare const GIT_ARROW_UP = "↑";
|
|
43
|
+
export declare const GIT_ARROW_DOWN = "↓";
|
|
44
|
+
/** One event name the host publishes on `data.on` — the OpenCode V2 union. */
|
|
45
|
+
export type SidebarDataEvent = Parameters<Context['data']['on']>[0];
|
|
46
|
+
/** V2 events that refresh the sidebar. V1 also listened to `session.updated`,
|
|
47
|
+
* but that name is absent from the OpenCode V2 event union (verified against
|
|
48
|
+
* `@opencode/client`'s `OpenCodeEvent`), so the valid events that carry the
|
|
49
|
+
* same state changes are used instead: `session.renamed` /
|
|
50
|
+
* `session.metadata.updated` / `session.moved` (the mutations `session.updated`
|
|
51
|
+
* used to stand for) and `session.idle` (a child finishing). `satisfies` keeps
|
|
52
|
+
* the literals while making a name outside the union a type error (surfaced by
|
|
53
|
+
* `tsc -p tsconfig.build.json`), and the sidebar test asserts the same names
|
|
54
|
+
* against the installed union at runtime. */
|
|
55
|
+
export declare const SIDEBAR_REFRESH_EVENTS: readonly ["session.created", "session.renamed", "session.metadata.updated", "session.moved", "session.idle", "session.status", "session.deleted"];
|
|
56
|
+
export type PresetInfo = {
|
|
57
|
+
name: string | null;
|
|
58
|
+
source: 'env' | 'file' | null;
|
|
59
|
+
};
|
|
60
|
+
/** One `overrides.agents[<agent>]` entry from active-preset.json. */
|
|
61
|
+
export type AgentModelOverride = {
|
|
62
|
+
model?: string;
|
|
63
|
+
variant?: string;
|
|
64
|
+
};
|
|
65
|
+
/** The override map the CLI wrote into active-preset.json. */
|
|
66
|
+
export type PresetOverrides = {
|
|
67
|
+
agents: Record<string, AgentModelOverride>;
|
|
68
|
+
};
|
|
69
|
+
/** A preset plus the explicit overrides stored next to it. */
|
|
70
|
+
export type ActivePresetDetail = {
|
|
71
|
+
info: PresetInfo;
|
|
72
|
+
overrides: PresetOverrides;
|
|
73
|
+
};
|
|
74
|
+
/** Keep only well-formed per-agent overrides: unknown keys are ignored and a
|
|
75
|
+
* non-string model/variant is dropped instead of leaking into the render. */
|
|
76
|
+
export declare function parsePresetOverrides(value: unknown): PresetOverrides;
|
|
77
|
+
/** Env leg of resolution: PANTHEON_MODEL_PRESET set and !== 'none' wins. */
|
|
78
|
+
export declare function presetFromEnv(env: Record<string, string | undefined>): PresetInfo;
|
|
79
|
+
/** Resolve the active preset plus its per-agent overrides: env > file > default.
|
|
80
|
+
* An env-selected preset has no file overrides by construction. */
|
|
81
|
+
export declare function resolveActivePresetForTui(env: Record<string, string | undefined>, cwd: string): Promise<ActivePresetDetail>;
|
|
82
|
+
/** `SessionInfo.id` is always a `ses…` handle. Guarded so a placeholder or a
|
|
83
|
+
* foreign id never reaches the status/navigate APIs. */
|
|
84
|
+
export declare function isValidSessionID(id: unknown): id is string;
|
|
85
|
+
/** Model reference shapes the host publishes: `ModelRef` objects, bare ids, or
|
|
86
|
+
* `provider/model` strings. Returns the id part, never throws. */
|
|
87
|
+
export declare function modelRefID(ref: unknown): string | null;
|
|
88
|
+
/** Short display id: the segment after the last `/` (`opencode-go/kimi-k3` →
|
|
89
|
+
* `kimi-k3`), truncated so a long id never wraps the sidebar. */
|
|
90
|
+
export declare function shortModelID(ref: unknown, max?: number): string | null;
|
|
91
|
+
/** `providerID` of a model reference, trimmed; null when absent/blank. Derived
|
|
92
|
+
* only from what the host already published — never a lookup table. */
|
|
93
|
+
export declare function providerIDFromRef(ref: unknown): string | null;
|
|
94
|
+
/** Provider for a bare-string model reference: match its id (or bare segment)
|
|
95
|
+
* in the host model list. Null when the list cannot answer. */
|
|
96
|
+
export declare function providerIDFromModels(models: unknown, ref: unknown): string | null;
|
|
97
|
+
/** Resolve `model.limit.context` for a model reference. Match order: the
|
|
98
|
+
* provider-qualified id, then the bare id (the host's `id`/`modelID` fields).
|
|
99
|
+
* Absent/ambiguous models degrade to null so the gauge is simply omitted. */
|
|
100
|
+
export declare function resolveContextLimit(models: readonly any[], ref: unknown): number | null;
|
|
101
|
+
export type ModelContextSnapshot = {
|
|
102
|
+
tokens: number;
|
|
103
|
+
percent: number;
|
|
104
|
+
limit: number;
|
|
105
|
+
};
|
|
106
|
+
/** Snapshot for one exact model identity in the bounded active transcript. */
|
|
107
|
+
export declare function resolveModelContextSnapshot(messages: readonly unknown[], modelRef: unknown, models: readonly unknown[], revertMessageID?: string | null): ModelContextSnapshot | null;
|
|
108
|
+
/** Select the pinned chat model before transcript or configured-agent fallbacks. */
|
|
109
|
+
export declare function resolveActiveModelRef(sessionModel: unknown, activeMessages: readonly unknown[], fallbackModel?: unknown): unknown;
|
|
110
|
+
/** Native token total: input + output + reasoning + cache read + cache write. */
|
|
111
|
+
export declare function messageTokensTotal(tokens: any): number;
|
|
112
|
+
export type ContextUsage = {
|
|
113
|
+
tokens: number;
|
|
114
|
+
percent: number;
|
|
115
|
+
limit: number;
|
|
116
|
+
};
|
|
117
|
+
/** The part of a transcript that still counts: everything before the revert
|
|
118
|
+
* boundary (when a revert is active), then after the last compaction. Both
|
|
119
|
+
* derived numbers that read "the last assistant with usage" — the context
|
|
120
|
+
* gauge and the cache hit rate — share this window, so a reverted-away or
|
|
121
|
+
* compacted-away message can never feed either one. Pure. */
|
|
122
|
+
export declare function transcriptWindow(messages: readonly any[], revertMessageID?: string | null): {
|
|
123
|
+
start: number;
|
|
124
|
+
end: number;
|
|
125
|
+
};
|
|
126
|
+
/** Context usage for a message list. Scope: the live window (see
|
|
127
|
+
* `transcriptWindow`). The last assistant message carrying `tokens` in that
|
|
128
|
+
* window wins. Null when there is no limit or no such message — the caller
|
|
129
|
+
* then omits the block. */
|
|
130
|
+
export declare function computeContextUsage(messages: readonly any[], contextLimit: number | null | undefined, revertMessageID?: string | null): ContextUsage | null;
|
|
131
|
+
/** Color for one gauge stage. Filled cells and the percent value both come from
|
|
132
|
+
* this one call, so the bar and its number can never disagree. `theme` is the
|
|
133
|
+
* host's resolved theme (loosely typed at runtime); a missing token falls back
|
|
134
|
+
* to the theme's base text instead of an unstyled cell. Pure. */
|
|
135
|
+
export declare function contextProgressColor(stage: ContextProgressTone, theme: any): any;
|
|
136
|
+
/** The muted extra line under the gauge: `cache 92% · 42.3 tok/s`. Either half
|
|
137
|
+
* may be missing (no cache read, no measurable turn); no data at all yields
|
|
138
|
+
* null so no empty line is rendered. The speed keeps the host's own one
|
|
139
|
+
* decimal and `tok/s` label. Pure. */
|
|
140
|
+
export declare function contextPerformanceLine(performance: ContextPerformance | null | undefined): string | null;
|
|
141
|
+
/** Cache hit rate of one message: `cache.read / (input + cache.read)` as a
|
|
142
|
+
* percentage. The denominator must be > 0, otherwise the ratio is meaningless
|
|
143
|
+
* (a message that only wrote to the cache has no input to hit). Null when the
|
|
144
|
+
* numbers are absent. Pure. */
|
|
145
|
+
export declare function cacheHitPercent(tokens: any): number | null;
|
|
146
|
+
/** The message the cache hit rate comes from: the last assistant of the live
|
|
147
|
+
* window (see `transcriptWindow`) that actually carries `tokens`. Later
|
|
148
|
+
* messages without usage — a streaming placeholder that the host publishes
|
|
149
|
+
* before any step completes, a step that reports no usage — are skipped
|
|
150
|
+
* instead of blanking a ratio the previous message already measured. Null
|
|
151
|
+
* when nothing in the window has usage. Pure. */
|
|
152
|
+
export declare function lastAssistantWithTokens(messages: readonly any[] | null | undefined, revertMessageID?: string | null): any | null;
|
|
153
|
+
/** Tokens per second of the current turn. Mirrors the host's
|
|
154
|
+
* `turnTokensPerSecond` (anomalyco/opencode v2.0.30,
|
|
155
|
+
* `packages/tui/src/routes/session/rows.ts`) so the sidebar and the native
|
|
156
|
+
* session footer can never disagree: the numerator is `output + reasoning`
|
|
157
|
+
* summed over every assistant step of the turn and the denominator is the
|
|
158
|
+
* summed active streaming time `max(0, time.streamed - time.created)`, so the
|
|
159
|
+
* division happens once, after aggregating — each step weighs by its own
|
|
160
|
+
* duration instead of each step voting equally. `completed` is never used; a
|
|
161
|
+
* turn with a step that has no `time.streamed` has no measurable speed. The
|
|
162
|
+
* turn starts after the last `user` message; with no user message only the
|
|
163
|
+
* last assistant step counts (degraded: there is no boundary to group by).
|
|
164
|
+
* Pure and fail-open. */
|
|
165
|
+
export declare function turnTokensPerSecond(messages: readonly any[] | null | undefined, position?: number | null): number | null;
|
|
166
|
+
/** Last-message telemetry the Context block renders in muted text. Both halves
|
|
167
|
+
* are optional; the block renders no line when neither is available. */
|
|
168
|
+
export type ContextPerformance = {
|
|
169
|
+
cacheHit: number | null;
|
|
170
|
+
tokensPerSecond: number | null;
|
|
171
|
+
};
|
|
172
|
+
/** One rendered context row. `lead` and `tail` carry the gauge bar when the row
|
|
173
|
+
* has one (`lead` is toned with the value, `tail` is muted), so the 12 cells
|
|
174
|
+
* stay contiguous while the empty half still reads as background. */
|
|
175
|
+
export type ContextRow = {
|
|
176
|
+
lead: string | null;
|
|
177
|
+
value: string;
|
|
178
|
+
tail: string | null;
|
|
179
|
+
suffix: string | null;
|
|
180
|
+
tone: ContextProgressTone | null;
|
|
181
|
+
};
|
|
182
|
+
/** The `Context` block's data rows; null rows are not rendered. */
|
|
183
|
+
export type ContextBlockRows = {
|
|
184
|
+
tokens: ContextRow | null;
|
|
185
|
+
percent: ContextRow | null;
|
|
186
|
+
spent: ContextRow | null;
|
|
187
|
+
};
|
|
188
|
+
/** Rows for the `Context` block:
|
|
189
|
+
* `<tokens> tokens` / `▰▰▰▰▰▱▱▱▱▱▱▱ <percent>% of <window>` /
|
|
190
|
+
* `$<spent> spent`. The percentage row carries the only semantic tone, the
|
|
191
|
+
* gauge bar (12 cells) and is omitted entirely when the percentage is
|
|
192
|
+
* unavailable (never `undefined%`). A block with neither tokens nor cost
|
|
193
|
+
* yields null. Pure. */
|
|
194
|
+
export declare function contextBlockRows(usage: ContextUsage | null, cost: number | null | undefined): ContextBlockRows | null;
|
|
195
|
+
/** Column widths for one model row (labels are muted, numbers right-aligned). */
|
|
196
|
+
export declare const MODEL_USAGE_MODEL_WIDTH = 12;
|
|
197
|
+
export declare const MODEL_USAGE_TOKEN_WIDTH = 6;
|
|
198
|
+
export declare const MODEL_USAGE_COST_WIDTH = 8;
|
|
199
|
+
/** Session events arrive in bursts; model rows are recomputed at most once
|
|
200
|
+
* per window (same cadence as the git-count revalidation). */
|
|
201
|
+
export declare const MODEL_USAGE_DEBOUNCE_MS = 400;
|
|
202
|
+
/** Real usage for one model, summed across the assistant messages that used it. */
|
|
203
|
+
export type ModelUsage = {
|
|
204
|
+
model: string;
|
|
205
|
+
tokens: number;
|
|
206
|
+
cost: number;
|
|
207
|
+
};
|
|
208
|
+
/** Totals per model from assistant messages: sums `cost` and `tokens`, drops
|
|
209
|
+
* models whose real cost is 0/absent, and orders by cost (then tokens, then
|
|
210
|
+
* name). `providerID` participates in the key so two providers exposing the
|
|
211
|
+
* same bare id are not merged. Pure. */
|
|
212
|
+
export declare function collectModelUsage(messages: readonly any[]): ModelUsage[];
|
|
213
|
+
/** Visible rows plus the aggregate of the models that did not fit. Pure. */
|
|
214
|
+
export type ModelUsageCeiling = {
|
|
215
|
+
visible: ModelUsage[];
|
|
216
|
+
hidden: number;
|
|
217
|
+
hiddenCost: number;
|
|
218
|
+
hiddenTokens: number;
|
|
219
|
+
};
|
|
220
|
+
/** Cap the model list at `maxVisible`; the rest is aggregated (still real
|
|
221
|
+
* totals) for the `… +N` line. Pure. */
|
|
222
|
+
export declare function ceilingModelUsage(rows: readonly ModelUsage[], maxVisible?: number): ModelUsageCeiling;
|
|
223
|
+
/** Compact tokens for a model row (`80,000` → `80K`); `0` stays explicit. Pure. */
|
|
224
|
+
export declare function formatUsageTokens(tokens: number | null | undefined): string;
|
|
225
|
+
/** Real per-model cost with adaptive precision: cents for `>= $0.01`, up to
|
|
226
|
+
* four decimals below that (a real `$0.0031` must not render as `$0.00`), and
|
|
227
|
+
* an explicit `< $0.0001` for the remainder. Pure. */
|
|
228
|
+
export declare function formatUsageCost(cost: number | null | undefined): string | null;
|
|
229
|
+
/** One formatted model row: truncated label + compact tokens + real cost. */
|
|
230
|
+
export type ModelUsageRow = {
|
|
231
|
+
model: string;
|
|
232
|
+
tokens: string;
|
|
233
|
+
cost: string;
|
|
234
|
+
};
|
|
235
|
+
/** Format the visible model rows for rendering. Labels are already short ids
|
|
236
|
+
* (12 chars); the second truncation only guards host drift. Pure. */
|
|
237
|
+
export declare function modelUsageRows(rows: readonly ModelUsage[]): ModelUsageRow[];
|
|
238
|
+
/** Exact single-line text of a model row, with numbers right-aligned. Pure. */
|
|
239
|
+
export declare function modelUsageRowText(row: ModelUsageRow): string;
|
|
240
|
+
/** Wrap sidebar text by terminal cells, preserving the complete values. */
|
|
241
|
+
export declare function sidebarTextLines(value: string): string[];
|
|
242
|
+
/** Align a monetary value when it fits, otherwise preserve it on a new line. */
|
|
243
|
+
export declare function sidebarMoneyLines(label: string, value: string): string[];
|
|
244
|
+
/** Keep the existing OpenCode periods together when possible. */
|
|
245
|
+
export declare function contextSpendLines(value: string): string[];
|
|
246
|
+
/** Keep ordinary rows aligned; give oversized values their own lines. */
|
|
247
|
+
export declare function modelUsageRowLines(row: ModelUsageRow): string[];
|
|
248
|
+
/** Muted aggregate line for the models beyond the cap (`… +2 $0.03`). Null
|
|
249
|
+
* when every model fits. Pure. */
|
|
250
|
+
export declare function hiddenModelUsageText(hidden: number, hiddenCost: number): string | null;
|
|
251
|
+
/** Bucket for a session the host published without an agent id. */
|
|
252
|
+
export declare const UNKNOWN_AGENT = "?";
|
|
253
|
+
/** Agent key of a session or message: the trimmed id when it is a non-empty
|
|
254
|
+
* string, else the `?` bucket — never `undefined`. Pure. */
|
|
255
|
+
export declare function agentKey(value: unknown): string;
|
|
256
|
+
export type TodoStatus = 'in_progress' | 'pending' | 'completed' | 'cancelled';
|
|
257
|
+
/** One rendered todo row. `priority` is carried by the tool but not rendered:
|
|
258
|
+
* the reference block uses a single marker column. */
|
|
259
|
+
export type TodoItem = {
|
|
260
|
+
content: string;
|
|
261
|
+
status: TodoStatus;
|
|
262
|
+
};
|
|
263
|
+
/** Rows rendered before the `… +N` line. */
|
|
264
|
+
export declare const TODO_VISIBLE_CEILING = 6;
|
|
265
|
+
/** Content width before the ellipsis — the block has ~30-34 usable columns. */
|
|
266
|
+
export declare const TODO_TEXT_WIDTH = 28;
|
|
267
|
+
/** Narrow a loose `status` value to the tool's four states. */
|
|
268
|
+
export declare function isTodoStatus(value: unknown): value is TodoStatus;
|
|
269
|
+
/** Items from a `todowrite` `input` payload. A missing/malformed `input`,
|
|
270
|
+
* absent `todos`, an unknown `status` or an empty/missing `content` drops the
|
|
271
|
+
* entry instead of throwing; a list with nothing readable yields `[]`. Pure. */
|
|
272
|
+
export declare function parseTodoItems(input: unknown): TodoItem[];
|
|
273
|
+
/** Newest completed `todowrite` in a transcript. The tool replaces the list
|
|
274
|
+
* wholesale, so the last write wins; a write with `todos: []` returns null
|
|
275
|
+
* (the block disappears rather than showing the previous list) and a
|
|
276
|
+
* not-yet-completed write is ignored. Null when the transcript carries no
|
|
277
|
+
* such part, so the block never renders a guess. Pure. */
|
|
278
|
+
export declare function latestTodoItems(messages: readonly any[] | null | undefined): TodoItem[] | null;
|
|
279
|
+
/** Stable group order (in_progress → pending → completed → cancelled); within a
|
|
280
|
+
* group the transcript order is preserved. Pure. */
|
|
281
|
+
export declare function orderTodoItems(items: readonly TodoItem[]): TodoItem[];
|
|
282
|
+
/** Row color channel: `accent` for live work, `muted` for closed items, base
|
|
283
|
+
* for pending. Kept separate from the theme so it is testable. Pure. */
|
|
284
|
+
export type TodoTone = 'accent' | 'muted' | 'base';
|
|
285
|
+
/** Tone for one status — no rainbow, a single accent. Pure. */
|
|
286
|
+
export declare function todoTone(status: TodoStatus): TodoTone;
|
|
287
|
+
/** Exact rendered text of one row: `[•] <content truncated to 28>`. Pure. */
|
|
288
|
+
export declare function todoRowText(item: TodoItem): string;
|
|
289
|
+
/** Ordered rows capped for the sidebar, plus how many did not fit. Pure. */
|
|
290
|
+
export type TodoCeiling = {
|
|
291
|
+
visible: TodoItem[];
|
|
292
|
+
hidden: number;
|
|
293
|
+
};
|
|
294
|
+
/** Order then cap the list at `maxVisible`. Pure. */
|
|
295
|
+
export declare function ceilingTodoItems(items: readonly TodoItem[], maxVisible?: number): TodoCeiling;
|
|
296
|
+
/** Overflow line (`… +3`); null when every item fits. Pure. */
|
|
297
|
+
export declare function hiddenTodoText(hidden: number): string | null;
|
|
298
|
+
export type GitChangeCounts = {
|
|
299
|
+
added: number;
|
|
300
|
+
modified: number;
|
|
301
|
+
deleted: number;
|
|
302
|
+
};
|
|
303
|
+
/** Files per status from a `VcsFileStatus[]` payload. Unknown statuses and
|
|
304
|
+
* malformed entries are ignored. Pure. */
|
|
305
|
+
export declare function countGitChanges(files: readonly any[] | null | undefined): GitChangeCounts;
|
|
306
|
+
/** `+1 ±2 −3` for the file counts; each zero term is omitted, and an empty
|
|
307
|
+
* change set returns null so the row is not rendered at all. Pure. */
|
|
308
|
+
export declare function formatGitChanges(files: readonly any[] | null | undefined): string | null;
|
|
309
|
+
/** Wall-clock ceiling for one git call. A stuck git (index lock, network
|
|
310
|
+
* filesystem) is killed instead of holding the row forever. */
|
|
311
|
+
export declare const GIT_CLI_TIMEOUT_MS = 2000;
|
|
312
|
+
/** Session events arrive in bursts; a git probe is scheduled at most once per
|
|
313
|
+
* window instead of once per event. */
|
|
314
|
+
export declare const GIT_CLI_DEBOUNCE_MS = 1000;
|
|
315
|
+
/** Minimum spacing between two probe starts. Five seconds keeps a chatty event
|
|
316
|
+
* stream from spawning a git process per step while staying fresh enough to
|
|
317
|
+
* show a file appearing mid-turn. */
|
|
318
|
+
export declare const GIT_CLI_MIN_INTERVAL_MS = 5000;
|
|
319
|
+
/** Stdout ceiling for one git call. `status --porcelain=v1 -uall` lists every
|
|
320
|
+
* untracked file, so a large worktree easily passes the 1 MB `execFile`
|
|
321
|
+
* default — which would reject and silently hand the row back to the
|
|
322
|
+
* `vcs.status` fallback. 4 MB is far above a realistic porcelain listing. */
|
|
323
|
+
export declare const GIT_CLI_MAX_BUFFER: number;
|
|
324
|
+
/** One `execFile` call: `(file, args, options) → { stdout }`. Injectable so the
|
|
325
|
+
* parsing/gating logic is testable without spawning processes. */
|
|
326
|
+
export type GitExec = (file: string, args: readonly string[], options: {
|
|
327
|
+
cwd: string;
|
|
328
|
+
timeout: number;
|
|
329
|
+
windowsHide: boolean;
|
|
330
|
+
maxBuffer: number;
|
|
331
|
+
}) => Promise<{
|
|
332
|
+
stdout: string;
|
|
333
|
+
}>;
|
|
334
|
+
/** Default runner: the promisified `node:child_process.execFile`. A non-zero
|
|
335
|
+
* exit (no repository, no upstream) rejects and the caller decides. */
|
|
336
|
+
export declare const defaultGitExec: GitExec;
|
|
337
|
+
/** Files per status from `git status --porcelain=v1 -uall`, including the two
|
|
338
|
+
* columns the protocol cannot report. Each line starts with `XY` (index and
|
|
339
|
+
* worktree state); a rename prints `R old -> new`, and `??` / `!!` are
|
|
340
|
+
* untracked / ignored. Precedence per file: deleted > added > modified, so
|
|
341
|
+
* `AM` counts once as added and `AD` once as deleted. Renames, copies and
|
|
342
|
+
* unmerged entries count as modified. Pure. */
|
|
343
|
+
export type GitPorcelainCounts = {
|
|
344
|
+
added: number;
|
|
345
|
+
modified: number;
|
|
346
|
+
deleted: number;
|
|
347
|
+
untracked: number;
|
|
348
|
+
};
|
|
349
|
+
/** Parse porcelain v1 output into file counts. Empty/malformed output yields
|
|
350
|
+
* zero counts (a clean tree), never a throw. Pure. */
|
|
351
|
+
export declare function parseGitStatusPorcelain(output: string | null | undefined): GitPorcelainCounts;
|
|
352
|
+
/** `git rev-list --count --left-right @{upstream}...HEAD` prints two numbers:
|
|
353
|
+
* commits only on the upstream (behind) then commits only on HEAD (ahead).
|
|
354
|
+
* Null when the output is not that pair — e.g. the command failed because the
|
|
355
|
+
* branch has no upstream, in which case the arrows are simply omitted. Pure. */
|
|
356
|
+
export declare function parseGitAheadBehind(output: string | null | undefined): {
|
|
357
|
+
ahead: number;
|
|
358
|
+
behind: number;
|
|
188
359
|
} | null;
|
|
189
|
-
/**
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
360
|
+
/** One git observation: file counts plus the upstream distance (either arrow
|
|
361
|
+
* may be unknown when the branch has no upstream). */
|
|
362
|
+
export type GitCliSnapshot = {
|
|
363
|
+
changes: GitPorcelainCounts;
|
|
364
|
+
ahead: number | null;
|
|
365
|
+
behind: number | null;
|
|
366
|
+
};
|
|
367
|
+
/** One probe: `git status --porcelain=v1 -uall` for the counts, then
|
|
368
|
+
* `git rev-list --count --left-right @{upstream}...HEAD` for the arrows (a
|
|
369
|
+
* failure there only drops the arrows). A status failure rejects — the caller
|
|
370
|
+
* then falls back to `client.vcs.status`. */
|
|
371
|
+
export declare function readGitSnapshot(directory: string, exec?: GitExec): Promise<GitCliSnapshot>;
|
|
372
|
+
/** Rendered git row: `+1 ±2 −1 ?2 ↑3 ↓1`, zero terms omitted. Null when the
|
|
373
|
+
* tree is clean and in sync, so the block keeps only its branch line. Pure. */
|
|
374
|
+
export declare function formatGitSnapshot(snapshot: GitCliSnapshot | null | undefined): string | null;
|
|
375
|
+
/** Whether a new probe may start. An in-flight probe always wins (no queue), and
|
|
376
|
+
* the previous start must be older than the cooldown. Pure. */
|
|
377
|
+
export declare function gitProbeAllowed(state: {
|
|
378
|
+
now: number;
|
|
379
|
+
lastRunAt: number | null;
|
|
380
|
+
inFlight: boolean;
|
|
381
|
+
}, cooldownMs?: number): boolean;
|
|
382
|
+
/** Spend window labels, in render order. */
|
|
383
|
+
export declare const SPEND_TODAY_LABEL = "hoje";
|
|
384
|
+
export declare const SPEND_30D_LABEL = "30d";
|
|
385
|
+
/** Separator between the two windows on the Context footer line. */
|
|
386
|
+
export declare const SPEND_LINE_SEPARATOR = " · ";
|
|
387
|
+
/** `30d` window: 30 × 24 h, measured back from "now". */
|
|
388
|
+
export declare const SPEND_30D_MS: number;
|
|
389
|
+
/** Probe window: one hour, narrow enough that a unit mix-up cannot line up. */
|
|
390
|
+
export declare const SPEND_PROBE_WINDOW_MS: number;
|
|
391
|
+
/** The echoed `range` may be rounded server-side; 120 s absorbs that. */
|
|
392
|
+
export declare const SPEND_PROBE_TOLERANCE_MS = 120000;
|
|
393
|
+
/** Session events arrive in bursts — same 400 ms window as the other blocks. */
|
|
394
|
+
export declare const SPEND_REFRESH_DEBOUNCE_MS = 400;
|
|
395
|
+
/** Spend per window in USD. Either side may be unknown (kept `null`). */
|
|
396
|
+
export type SpendTotals = {
|
|
397
|
+
today: number | null;
|
|
398
|
+
thirtyDays: number | null;
|
|
399
|
+
};
|
|
400
|
+
/** `from`/`to` unit accepted by the route. `SessionStatsInput` declares both as
|
|
401
|
+
* bare `number` and does not say which unit, so it is measured once per
|
|
402
|
+
* process (`ms` unless the server echoes seconds) instead of guessed. */
|
|
403
|
+
type SpendUnit = 'ms' | 's' | 'unavailable';
|
|
404
|
+
/** Test-only: forget the process-wide unit resolution. Never called at runtime. */
|
|
405
|
+
export declare function resetSpendUnit(): void;
|
|
406
|
+
/** Resolved unit (`ms` / `s` / `unavailable`) or null while still unknown. */
|
|
407
|
+
export declare function resolvedSpendUnit(): SpendUnit | null;
|
|
408
|
+
/** Local midnight for `now`: `new Date()` with the clock fields zeroed in the
|
|
409
|
+
* current timezone (DST-safe, unlike subtracting hours). Pure. */
|
|
410
|
+
export declare function startOfLocalDay(now: number): number;
|
|
411
|
+
/** The two windows the block shows: `hoje` (local midnight → now) and `30d`
|
|
412
|
+
* (now − 30 days → now). Pure. */
|
|
413
|
+
export declare function spendWindows(now: number): {
|
|
414
|
+
today: {
|
|
415
|
+
from: number;
|
|
416
|
+
to: number;
|
|
417
|
+
};
|
|
418
|
+
thirtyDays: {
|
|
419
|
+
from: number;
|
|
420
|
+
to: number;
|
|
216
421
|
};
|
|
217
422
|
};
|
|
218
|
-
/**
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
423
|
+
/** USD with two decimals (`$0.42`), four for a positive sub-cent amount
|
|
424
|
+
* (`$0.0031`), and `<$0.0001` when even four decimals would read `$0.0000`.
|
|
425
|
+
* `0` prints `$0.00`. Null for a missing/negative/non-finite value. Pure. */
|
|
426
|
+
export declare function formatSpendUSD(cost: number | null | undefined): string | null;
|
|
427
|
+
/** `cost` off a `SessionStatsInfo` (`MoneyUSD` = number) or null when the
|
|
428
|
+
* payload is malformed/negative, so a bad value never reaches a row. Pure. */
|
|
429
|
+
export declare function statsCost(result: unknown): number | null;
|
|
430
|
+
/** True when the server echoed the window we sent, within 120 s. `scale` is how
|
|
431
|
+
* many milliseconds one unit of the sent window is worth (`1` for `ms`, `1000`
|
|
432
|
+
* for `s`). The echo is accepted either as the same numbers we sent (the route
|
|
433
|
+
* keeps the caller's unit) or converted to millisecond epoch (`DateTime.Utc`),
|
|
434
|
+
* so the probe pins the unit without assuming which of the two it gets. Pure. */
|
|
435
|
+
export declare function statsRangeMatches(range: unknown, sent: {
|
|
436
|
+
from: number;
|
|
437
|
+
to: number;
|
|
438
|
+
}, scale: number): boolean;
|
|
439
|
+
/** The `Context` block's last line: OpenCode stats source and both spend windows
|
|
440
|
+
* on one muted row (`OpenCode · hoje $0.42 · 30d $9.80`). A window without a
|
|
441
|
+
* usable amount is omitted, and no usable window at all yields null so the
|
|
442
|
+
* line (and not the block) is dropped. Pure. */
|
|
443
|
+
export declare function contextSpendLine(totals: SpendTotals | null): string | null;
|
|
444
|
+
/** Grapheme iterator: a cut never splits a surrogate pair, a combining mark
|
|
445
|
+
* from its base or a ZWJ emoji sequence, so truncation stays cell-exact. */
|
|
446
|
+
/** Clamp a free-form label to `max` terminal cells without wrapping. The width
|
|
447
|
+
* is measured in display cells, never in UTF-16 code units: a CJK or emoji
|
|
448
|
+
* label used to overflow the column it was cut for (`計画の移行` is 5 code
|
|
449
|
+
* units but 10 cells, `🚀` is 2 units and 2 cells). Pure. */
|
|
450
|
+
export declare function truncateLabel(value: string, max?: number): string;
|
|
451
|
+
/** Right-pad `value` with spaces to exactly `cells` display columns (a wider
|
|
452
|
+
* value is truncated first). `padEnd` counts code units, so it under-pads a
|
|
453
|
+
* CJK/emoji cell and the next column drifts. Pure. */
|
|
454
|
+
export declare function padCell(value: string, cells: number): string;
|
|
455
|
+
/** Columns the fixed header may use before it would wrap the sidebar. */
|
|
456
|
+
export declare const HEADER_MAX_WIDTH = 34;
|
|
457
|
+
/** Preset row of the fixed header: `▸ <preset> · <provider>`. The provider is
|
|
458
|
+
* cut first when the row overflows, so the preset name is never the casualty;
|
|
459
|
+
* a missing provider leaves the preset alone (no `unknown` placeholder). */
|
|
460
|
+
export declare function presetHeaderLine(presetName: string, providerID: string | null): string;
|
|
461
|
+
export type DispatchKind = 'coun' | 'plan' | 'revw' | 'hot' | 'disc' | 'oth';
|
|
462
|
+
export type DispatchKindOrigin = 'prefix' | 'agent' | 'unavailable';
|
|
463
|
+
/** One classification plus the evidence that produced it. */
|
|
464
|
+
export type DispatchKindLabel = {
|
|
465
|
+
kind: DispatchKind | null;
|
|
466
|
+
origin: DispatchKindOrigin;
|
|
237
467
|
};
|
|
238
|
-
/**
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
468
|
+
/** Kind declared by a leading `[prefix]` on the description: case-insensitive
|
|
469
|
+
* and tolerant of spaces inside the brackets. Null when none is declared. */
|
|
470
|
+
export declare function dispatchKindFromPrefix(description: unknown): DispatchKind | null;
|
|
471
|
+
/** Kind implied by the child's agent, null for an agent that implies none. */
|
|
472
|
+
export declare function dispatchKindFromAgent(agent: unknown): DispatchKind | null;
|
|
473
|
+
/** Classify one dispatch. The description prefix always wins over the agent;
|
|
474
|
+
* otherwise the agent decides, and anything else is `oth` (a real dispatch we
|
|
475
|
+
* simply cannot name). A missing call is the only `unavailable` outcome. Pure. */
|
|
476
|
+
export declare function classifyDispatchKind(call: {
|
|
477
|
+
description?: unknown;
|
|
478
|
+
agent?: unknown;
|
|
479
|
+
} | null | undefined): DispatchKindLabel;
|
|
480
|
+
/** A `subagent` tool call the parent made, as its own transcript records it. */
|
|
481
|
+
export type SubagentCall = {
|
|
482
|
+
/** Child session id the call created — the correlation key. */
|
|
242
483
|
sessionID: string;
|
|
243
|
-
tool: 'task';
|
|
244
|
-
/** Agent name from the task input args ('agent' fallback when absent). */
|
|
245
484
|
agent: string;
|
|
246
485
|
description: string;
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
*
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
export
|
|
258
|
-
/**
|
|
259
|
-
*
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
*
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
* compaction/attach. */
|
|
272
|
-
export declare function collectDelegationToolParts(messages: readonly {
|
|
273
|
-
id?: string;
|
|
274
|
-
parts?: unknown[];
|
|
275
|
-
}[] | undefined, getParts?: (messageID: string) => readonly unknown[] | undefined): DelegationToolPart[];
|
|
276
|
-
/** Apply a batch of tool parts (in message order) to the live map. Used on
|
|
277
|
-
* mount to re-seed entries that `message.part.removed` (compaction) wiped,
|
|
278
|
-
* from the session's existing tool parts. Returns how many parts changed
|
|
279
|
-
* the map (0 on the second identical seed — idempotent, no extra bumps). */
|
|
280
|
-
export declare function seedLiveDelegationMap(map: Map<string, LiveDelegationEntry>, parts: readonly DelegationToolPart[], now?: number): number;
|
|
281
|
-
/** Convert a live entry into the shared display shape. Alias falls back to
|
|
282
|
-
* a `live-<callID>` prefix while the task call has not completed yet. */
|
|
283
|
-
export declare function toDelegationEntry(live: LiveDelegationEntry): DelegationEntry;
|
|
284
|
-
/** Combine the live channel with the md (historical) channel into one
|
|
285
|
-
* display list. Dedupes by (sessionID, alias) — aliases are per-parent-
|
|
286
|
-
* session, so the same alias in different sessions stays separate. A
|
|
287
|
-
* terminal md entry is authoritative over a live running entry for the
|
|
288
|
-
* same job (it carries Finalized/timedOut/cancelled from finalize). */
|
|
289
|
-
export declare function mergeDelegationSources(live: readonly LiveDelegationEntry[], md: readonly DelegationEntry[]): DelegationEntry[];
|
|
290
|
-
/** Scope a fully-merged display list to the ACTIVE session only.
|
|
291
|
-
*
|
|
292
|
-
* The panel is session-scoped: rows from other sessions (md history under
|
|
293
|
-
* `.pantheon/delegations/<other-session>/`) and rows with no
|
|
294
|
-
* attributable session (empty sessionID) are DROPPED. The previous
|
|
295
|
-
* cross-session behavior rendered those rows and clicking them led to
|
|
296
|
-
* "Session not found" — there is no cross-session channel anymore.
|
|
297
|
-
*
|
|
298
|
-
* The md channel still feeds the merge UNFILTERED so it can ENRICH an
|
|
299
|
-
* active-session row with state/alias/agent (dedup by taskID), but it can
|
|
300
|
-
* never introduce a row for another session: this filter is applied
|
|
301
|
-
* ONCE, after every merge (children + live + md).
|
|
302
|
-
*
|
|
303
|
-
* Returns [] when no active session resolves (null/placeholder) — there is no
|
|
304
|
-
* scope to show. Native children always carry the active session id (stamped
|
|
305
|
-
* by `childrenToDelegationEntries`), so they survive the filter. Pure. */
|
|
306
|
-
export declare function filterDelegationsToSession(entries: readonly DelegationEntry[], activeSessionID: string | null | undefined): DelegationEntry[];
|
|
307
|
-
/** Server-aligned session id validity: opencode rejects anything not starting
|
|
308
|
-
* with "ses" (SchemaError). This deliberately mirrors that exact contract —
|
|
309
|
-
* nothing stricter, nothing looser — so a template placeholder ("{sessionID}"),
|
|
310
|
-
* its URL-encoded form ("%7BsessionID%7D", what the server reported in the
|
|
311
|
-
* schema error), an empty/undefined value, or a foreign id (e.g. "wrk_") can
|
|
312
|
-
* never reach a path and error-spam the log. Confirmed: "{sessionID}" starts
|
|
313
|
-
* with "{" and "%7BsessionID%7D" with "%" — both fail startsWith("ses"), so
|
|
314
|
-
* the placeholder is rejected WITHOUT an explicit denylist (covered by tests). */
|
|
315
|
-
export declare function isValidSessionId(id: unknown): id is string;
|
|
316
|
-
/** Sources the sidebar can resolve the CURRENT session id from. Duck-typed
|
|
317
|
-
* subsets of TuiPluginApi / TuiState / TuiRouteCurrent so the helper stays
|
|
318
|
-
* pure and testable without the TUI runtime. */
|
|
319
|
-
export type TuiSessionSources = {
|
|
320
|
-
/** sidebar_content slot prop (`session_id`). */
|
|
321
|
-
sessionID?: string | null;
|
|
322
|
-
api?: {
|
|
323
|
-
/** Runtime state superset — may expose the current session id. */
|
|
324
|
-
state?: {
|
|
325
|
-
sessionID?: unknown;
|
|
326
|
-
};
|
|
327
|
-
/** Typed route: { name: 'session', params: { sessionID } } when in one. */
|
|
328
|
-
route?: {
|
|
329
|
-
current?: {
|
|
330
|
-
name?: string;
|
|
331
|
-
params?: Record<string, unknown>;
|
|
332
|
-
};
|
|
333
|
-
};
|
|
334
|
-
} | null;
|
|
335
|
-
};
|
|
336
|
-
/** Resolve the current session id for the sidebar. Order: slot prop →
|
|
337
|
-
* api.state.sessionID (runtime superset) → api.route.current.params.sessionID
|
|
338
|
-
* (typed route). Every source is validated; invalid/absent → next source.
|
|
339
|
-
* NEVER returns a placeholder or non-ses id. Null → callers MUST skip the
|
|
340
|
-
* fetch (empty panel, zero errors). Pure — no I/O, no runtime required. */
|
|
341
|
-
export declare function resolveCurrentSessionID(sources: TuiSessionSources): string | null;
|
|
342
|
-
/** THE single choke point for every `session.children` / session-API path.
|
|
343
|
-
* Returns the v2 SDK parameter shape `{ sessionID }` ONLY for a
|
|
344
|
-
* server-valid session id; returns null for anything else (placeholder,
|
|
345
|
-
* empty, foreign id) so the caller skips the call entirely instead of
|
|
346
|
-
* sending an unsubstituted placeholder (the "%7BsessionID%7D" regression).
|
|
347
|
-
* The TUI client is `@opencode-ai/sdk/v2`, whose session methods take a
|
|
348
|
-
* FLAT parameter object (`{ sessionID }`), NOT the v1 `{ path: { id } }`
|
|
349
|
-
* envelope — passing the v1 shape left the v2 `{sessionID}` URL template
|
|
350
|
-
* unsubstituted (`/session/%7BsessionID%7D/children`). Every session-API
|
|
351
|
-
* call site MUST go through this function (enforced by the source-scan
|
|
352
|
-
* test in tests/pantheon/tui-delegations.test.ts). */
|
|
353
|
-
export declare function safeSessionPath(id: unknown): {
|
|
354
|
-
sessionID: string;
|
|
355
|
-
} | null;
|
|
356
|
-
/** Build the `session.children` parameters ONLY from a validated session id.
|
|
357
|
-
* Delegates to {@link safeSessionPath} — the single choke point. Returns
|
|
358
|
-
* the v2 SDK shape `{ sessionID }`; null for null/invalid ids so the caller
|
|
359
|
-
* skips the fetch instead of sending an unsubstituted placeholder (the
|
|
360
|
-
* "%7BsessionID%7D" regression). */
|
|
361
|
-
export declare function buildChildrenPath(id: string | null | undefined): {
|
|
362
|
-
sessionID: string;
|
|
363
|
-
} | null;
|
|
364
|
-
/** Duck-typed subset of a child Session (+ its live status type). */
|
|
365
|
-
export type ChildDelegationLike = {
|
|
366
|
-
/** Child session id (= task id). */
|
|
486
|
+
background: boolean;
|
|
487
|
+
};
|
|
488
|
+
/** Correlate the parent transcript's `subagent` calls with the children they
|
|
489
|
+
* spawned: child session id → `{ agent, description, background }`. One pass
|
|
490
|
+
* over the list the sidebar already holds — no request, no `message.sync` on
|
|
491
|
+
* the child. `streaming`/`pending` states carry their input as *partial JSON
|
|
492
|
+
* text*, so they are skipped rather than parsed. Fail-open: a malformed part
|
|
493
|
+
* contributes nothing. Pure. */
|
|
494
|
+
export declare function collectSubagentCalls(messages: readonly any[] | null | undefined): Map<string, SubagentCall>;
|
|
495
|
+
export type DelegationState = 'running' | 'completed' | 'failed' | 'interrupted';
|
|
496
|
+
export type DelegationTone = 'warning' | 'error' | 'success';
|
|
497
|
+
/** Grace window for a child that has not started yet. V2's `session.status()`
|
|
498
|
+
* returns `idle` both for "created but not started" and for "finished", so an
|
|
499
|
+
* idle/unknown/absent child whose own last activity (`time.updated`, falling
|
|
500
|
+
* back to `time.created`) is this recent still reads as running — otherwise a
|
|
501
|
+
* just-spawned child renders a premature ✓. Trade-off (V1 parity: it had the
|
|
502
|
+
* same window for its absent statuses): a child that finished within the window
|
|
503
|
+
* and reports no `outcome` reads as running until the window closes, at which
|
|
504
|
+
* point it turns terminal and its completion toast fires. A child that reports
|
|
505
|
+
* a terminal `outcome` is never held back by the window. */
|
|
506
|
+
export declare const DELEGATION_CHILD_STATUS_GRACE_MS: number;
|
|
507
|
+
/** One delegated child job as the sidebar renders it. */
|
|
508
|
+
export type DelegationView = {
|
|
509
|
+
/** Child session id — also the click-through target. */
|
|
367
510
|
id: string;
|
|
368
|
-
/**
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
511
|
+
/** Alias shown on the row: the child title, else agent, else short id. */
|
|
512
|
+
label: string;
|
|
513
|
+
state: DelegationState;
|
|
514
|
+
/** Epoch ms of the child's `time.created`. */
|
|
515
|
+
startedAt: number | null;
|
|
516
|
+
/** Epoch ms of the child's `time.updated`. */
|
|
517
|
+
updatedAt: number | null;
|
|
518
|
+
/** Child agent id, when the host published one. */
|
|
519
|
+
agent: string | null;
|
|
520
|
+
/** Resolved child model, shortened to its bare id. */
|
|
521
|
+
model: string | null;
|
|
522
|
+
/** Real `SessionInfo.cost` for the child, null when the host published none. */
|
|
523
|
+
cost: number | null;
|
|
524
|
+
/** Why the child exists — see `classifyDispatchKind`. Null when no `subagent`
|
|
525
|
+
* call in the parent transcript could be correlated with this child. */
|
|
526
|
+
kind: DispatchKind | null;
|
|
527
|
+
/** Which evidence produced `kind`. */
|
|
528
|
+
kindOrigin: DispatchKindOrigin;
|
|
529
|
+
/** The parent asked for this child to run in the background. */
|
|
530
|
+
background: boolean;
|
|
380
531
|
};
|
|
381
|
-
/** Map
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
|
|
389
|
-
* "197 children, all active" regression), so an absent status is terminal
|
|
390
|
-
* (done) UNLESS the child was active within `graceMs` — a just-spawned child
|
|
391
|
-
* that the status API has not registered yet must still render as running.
|
|
392
|
-
*
|
|
393
|
-
* @param status the `api.state.session.status(id)?.type`, or undefined
|
|
394
|
-
* @param time the child session time fields (`created`/`updated`)
|
|
395
|
-
* @param now current wall-clock ms (injectable for tests)
|
|
396
|
-
* @param graceMs recency window for the absent-status running assumption
|
|
397
|
-
* Pure — no I/O. */
|
|
398
|
-
export declare function childStatusToState(status: string | undefined, time?: {
|
|
532
|
+
/** Map the host's live session status to a display state. V2 exposes only
|
|
533
|
+
* `"idle" | "running"` through the TUI context (the client union adds `retry`
|
|
534
|
+
* and `busy`); `error`/`failed` are handled defensively for host drift.
|
|
535
|
+
* `idle`, `retry` and unknown/absent statuses are terminal only once the
|
|
536
|
+
* child's own activity is older than the grace window — within it the child
|
|
537
|
+
* reads as running (see `DELEGATION_CHILD_STATUS_GRACE_MS`). An interruption is
|
|
538
|
+
* not part of this union: it arrives as a terminal `outcome`. Pure. */
|
|
539
|
+
export declare function delegationStateFromStatus(status: string | undefined, time?: {
|
|
399
540
|
created?: number;
|
|
400
541
|
updated?: number;
|
|
401
|
-
}, now?: number, graceMs?: number):
|
|
402
|
-
/**
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
export declare function
|
|
418
|
-
/**
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
*
|
|
429
|
-
export
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
/**
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
*
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
*
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
*
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
export declare
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
*
|
|
493
|
-
export
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
declare const
|
|
542
|
+
}, now?: number, graceMs?: number): DelegationState;
|
|
543
|
+
/** Map a V2 child `outcome` to a display state. `interrupted` (user abort,
|
|
544
|
+
* shutdown, superseded, inactivity) is distinct from both success and failure,
|
|
545
|
+
* so an aborted child never renders the ✓ of a completed one. Returns null for
|
|
546
|
+
* an absent/unrecognised outcome so the live status decides. Pure. */
|
|
547
|
+
export declare function delegationStateFromOutcome(outcome: unknown): DelegationState | null;
|
|
548
|
+
/** Build a delegation row from a child session + its live status, plus the
|
|
549
|
+
* `subagent` call that spawned it (when the parent transcript had one). A
|
|
550
|
+
* terminal `outcome` wins when present (the only V2 primitive that surfaces a
|
|
551
|
+
* delegation failure/interruption once the status is back to idle); otherwise
|
|
552
|
+
* the live status decides, with the absent/idle grace window applied. The
|
|
553
|
+
* `call` only ever *adds* the purpose and the background flag — an absent one
|
|
554
|
+
* leaves the row fully renderable. Pure. */
|
|
555
|
+
export declare function toDelegationView(child: any, status: string | undefined, now?: number, call?: SubagentCall | null): DelegationView;
|
|
556
|
+
/** Spinner glyph for a frame counter (incremented every ~80ms while any job is
|
|
557
|
+
* running). Pure. */
|
|
558
|
+
export declare function spinnerFrame(frame: number): string;
|
|
559
|
+
/** Token totals published on `SessionInfo.tokens`, one entry per counter. */
|
|
560
|
+
export type DispatchTokens = {
|
|
561
|
+
input: number | null;
|
|
562
|
+
output: number | null;
|
|
563
|
+
reasoning: number | null;
|
|
564
|
+
cacheRead: number | null;
|
|
565
|
+
cacheWrite: number | null;
|
|
566
|
+
};
|
|
567
|
+
/** One child of the dispatch tree: the delegation row plus the fields only the
|
|
568
|
+
* panel's detail view needs (`SessionInfo.title`/`parentID`/`tokens` and the
|
|
569
|
+
* spawning call's description). */
|
|
570
|
+
export type DispatchEntry = {
|
|
571
|
+
view: DelegationView;
|
|
572
|
+
title: string | null;
|
|
573
|
+
description: string | null;
|
|
574
|
+
parentID: string | null;
|
|
575
|
+
tokens: DispatchTokens | null;
|
|
576
|
+
};
|
|
577
|
+
/** Optional inputs of `collectDispatch`: a fixed clock (tests/render ticks) and
|
|
578
|
+
* an already-computed `agent` map, so a caller that walked the parent
|
|
579
|
+
* transcript anyway never pays for a second walk. */
|
|
580
|
+
export type CollectDispatchOptions = {
|
|
581
|
+
now?: number;
|
|
582
|
+
calls?: Map<string, SubagentCall>;
|
|
583
|
+
};
|
|
584
|
+
/** Token counters of a child, null when the host published none of them. Pure. */
|
|
585
|
+
export declare function dispatchTokens(tokens: unknown): DispatchTokens | null;
|
|
586
|
+
/** One child `SessionInfo` + its live status → `DispatchEntry`. The call only
|
|
587
|
+
* ever adds the kind and the description; an absent one leaves the entry fully
|
|
588
|
+
* renderable. Pure. */
|
|
589
|
+
export declare function toDispatchEntry(child: any, status: string | undefined, now?: number, call?: SubagentCall | null): DispatchEntry;
|
|
590
|
+
/** The delegation tree of `sessionID` — every child `session.family` returns,
|
|
591
|
+
* root excluded, each enriched from `session.get`/`session.status` and the
|
|
592
|
+
* parent's `subagent` calls. Empty when the family API is unavailable or the
|
|
593
|
+
* session id is not a real handle (never falls back to the root). Ordered by
|
|
594
|
+
* the shared `compareDelegations`, so callers render the same list in the same
|
|
595
|
+
* order. A family that repeats an id yields one row per child: the id is
|
|
596
|
+
* deduplicated before the walk, so a duplicate can never double a row or its
|
|
597
|
+
* cost. */
|
|
598
|
+
export declare function collectDispatch(context: any, sessionID: string | undefined, options?: CollectDispatchOptions): DispatchEntry[];
|
|
599
|
+
/** Sidebar blocks in render order. Spacing is derived from this list instead of
|
|
600
|
+
* from the view, so a hidden block can never leave an empty gap behind. */
|
|
601
|
+
export type SidebarBlockKey = 'context' | 'git' | 'todo' | 'dispatch';
|
|
602
|
+
/** One rendered block: its key, and whether a blank line precedes it. */
|
|
603
|
+
export type SidebarBlock = {
|
|
604
|
+
key: SidebarBlockKey;
|
|
605
|
+
spacer: boolean;
|
|
606
|
+
};
|
|
607
|
+
/** Header glyph per block — one codepoint each, rendered muted before the bold
|
|
608
|
+
* label. The fixed header (version/preset/session) takes none.
|
|
609
|
+
* Measured as one terminal cell by the host (`@opentui/core` counts
|
|
610
|
+
* `emoji-regex` matches as two): ▤ U+25A4 (EAW=A), ◆ U+25C6 (A), ▾ U+25BE (N),
|
|
611
|
+
* ◈ U+25C8 (A). `☑` U+2611 was rejected for the Todo header because it matches
|
|
612
|
+
* `emoji-regex` and would occupy two cells; `⌁` U+2301 (the old Dispatch glyph)
|
|
613
|
+
* was replaced by the host's own Notice glyph. */
|
|
614
|
+
export declare const BLOCK_ICONS: Record<SidebarBlockKey, string>;
|
|
615
|
+
/** Tag every block that has content with its spacer: never before the first
|
|
616
|
+
* (the view puts a single blank line after the fixed header instead), one
|
|
617
|
+
* blank line before every later block. A repeated key collapses instead of
|
|
618
|
+
* stacking spacers, so an absent optional block can never leave a double gap.
|
|
619
|
+
* Pure. */
|
|
620
|
+
export declare function withBlockSpacers(keys: readonly SidebarBlockKey[]): SidebarBlock[];
|
|
621
|
+
/** Live children rendered one row each; the rest collapse into `… +N rodando`. */
|
|
622
|
+
export declare const DISPATCH_RUNNING_CEILING = 3;
|
|
623
|
+
/** Agent rollup rows rendered before the `… +K $<soma>` line. */
|
|
624
|
+
export declare const DISPATCH_AGENT_CEILING = 3;
|
|
625
|
+
/** Hard cap on the block's rendered rows, header included. The sidebar is
|
|
626
|
+
* short; live work is served first, then the finished rollup. */
|
|
627
|
+
export declare const DISPATCH_MAX_LINES = 8;
|
|
628
|
+
/** Marker of the aggregated "finished" section. */
|
|
629
|
+
export declare const DISPATCH_DONE_MARKER = "✓";
|
|
630
|
+
/** Column width of the agent (or of its title/id fallback). */
|
|
631
|
+
export declare const DISPATCH_AGENT_WIDTH = 12;
|
|
632
|
+
/** Narrowest agent column a row may fall back to before the cost is kept whole
|
|
633
|
+
* and the label truncates further. */
|
|
634
|
+
export declare const DISPATCH_MIN_AGENT_WIDTH = 8;
|
|
635
|
+
/** Column width of the short model id — the model is dropped before the agent
|
|
636
|
+
* or the cost so a row always fits. */
|
|
637
|
+
export declare const DISPATCH_MODEL_WIDTH = 7;
|
|
638
|
+
/** Column width of the per-dispatch cost (`$0.04`; a sub-cent cost widens it). */
|
|
639
|
+
export declare const DISPATCH_COST_WIDTH = 5;
|
|
640
|
+
/** Column width of the duration (`12.7s` / `1m04s` / `820ms`). */
|
|
641
|
+
export declare const DISPATCH_DURATION_WIDTH = 5;
|
|
642
|
+
/** Column width of the `×<count>` cell of an agent rollup row. */
|
|
643
|
+
export declare const DISPATCH_COUNT_WIDTH = 3;
|
|
644
|
+
/** Column width of an agent rollup cost (`$0.0051` still fits). */
|
|
645
|
+
export declare const DISPATCH_GROUP_COST_WIDTH = 7;
|
|
646
|
+
/** Hard column budget for one row — a Dispatch line never wraps:
|
|
647
|
+
* marker(2) + agent(12) + model(7) + cost(5) + duration(5) + 3 spaces = 34.
|
|
648
|
+
* The kind suffix (`·disc`, `·disc~`) is wider evidence than the model, so a
|
|
649
|
+
* classified row spends the model's columns first: marker(2) + agent(≤12) +
|
|
650
|
+
* suffix(≤6) + cost(5) + duration(5) + 2 spaces ≤ 32, still inside 34. */
|
|
651
|
+
export declare const DISPATCH_MAX_WIDTH = 34;
|
|
652
|
+
/** Kind suffix glued to a row's label: `·disc`, `·disc~` for a background run,
|
|
653
|
+
* and empty when the child could not be classified (the row then reads exactly
|
|
654
|
+
* as before). Pure. */
|
|
655
|
+
export declare function dispatchKindSuffix(kind: DispatchKind | null | undefined, background?: boolean): string;
|
|
656
|
+
/** Header summary: `2 rodando · $3.49`. The live count is omitted when nothing
|
|
657
|
+
* runs, and the total spend is always printed (the header only renders while
|
|
658
|
+
* the tree has children, so `$0.00` is a real answer). Pure. */
|
|
659
|
+
export declare function dispatchHeaderSummary(running: number | null | undefined, cost: number | null | undefined): string | null;
|
|
660
|
+
/** Compact duration without an internal space: `820` → `820ms`, `12_400` →
|
|
661
|
+
* `12.4s`, `64_000` → `1m04s`, `3_780_000` → `1h03m`, `172_800_000` → `2d`.
|
|
662
|
+
* An absent or negative value renders an em dash, never `NaN`s. Pure. */
|
|
663
|
+
export declare function formatDispatchDuration(ms: number | null | undefined): string;
|
|
664
|
+
/** Elapsed label for one row: a live child measures `now - created`, a finished
|
|
665
|
+
* one freezes at `updated - created` (em dash when a timestamp is missing).
|
|
666
|
+
* Pure. */
|
|
667
|
+
export declare function dispatchElapsed(view: DelegationView, now?: number): string;
|
|
668
|
+
/** Name column: the agent when the host published one, else the child title,
|
|
669
|
+
* else the short id — never `undefined`. Truncated to the column width. Pure. */
|
|
670
|
+
export declare function dispatchAgentText(view: Pick<DelegationView, 'agent' | 'label' | 'id'>, max?: number): string;
|
|
671
|
+
/** Model column, empty when the host published none. Pure. */
|
|
672
|
+
export declare function dispatchModelText(view: Pick<DelegationView, 'model'>): string;
|
|
673
|
+
/** Cost column: the child's real `SessionInfo.cost` with two decimals (up to
|
|
674
|
+
* four below a cent, so `$0.0031` never collapses to `$0.00`), `$0.00` for a
|
|
675
|
+
* zero cost, and an em dash when the host published no numeric cost. Pure. */
|
|
676
|
+
export declare function formatDispatchCost(cost: number | null | undefined): string;
|
|
677
|
+
/** Total spend of every child (live + finished), `0` when none published a
|
|
678
|
+
* numeric cost. Pure. */
|
|
679
|
+
export declare function dispatchTotalCost(views: readonly DelegationView[]): number;
|
|
680
|
+
/** One live child: `⠸ <agent 12>·<kind> <custo> <duração>`, with the model as a
|
|
681
|
+
* fourth column only when the row still fits and the child is unclassified —
|
|
682
|
+
* the kind is the stronger evidence at this width, so it takes the model's
|
|
683
|
+
* columns. The kind rides glued to the label (never a column of its own) and
|
|
684
|
+
* disappears with the label's truncation; then the agent column shrinks (never
|
|
685
|
+
* below `DISPATCH_MIN_AGENT_WIDTH`); the cost is always present — `$0.00` for a
|
|
686
|
+
* zero cost, an em dash for a missing one. Pure. */
|
|
687
|
+
export declare function runningChildRowText(view: DelegationView, now?: number, frame?: number, max?: number): string;
|
|
688
|
+
/** Sessions and spend attributed to one agent in the finished section. `kind`
|
|
689
|
+
* is only set when every finished session of the group agrees on it — a mixed
|
|
690
|
+
* group carries no single purpose, so the row omits it rather than picking one.
|
|
691
|
+
* `background` follows the same rule (all of them background). */
|
|
692
|
+
export type ChildAgentUsage = {
|
|
693
|
+
agent: string;
|
|
694
|
+
count: number;
|
|
695
|
+
cost: number;
|
|
696
|
+
kind: DispatchKind | null;
|
|
697
|
+
background: boolean;
|
|
698
|
+
};
|
|
699
|
+
/** Rollup of the finished children by agent: `×count` sessions and the summed
|
|
700
|
+
* `SessionInfo.cost`. Failed and interrupted children are included (they are
|
|
701
|
+
* finished); running ones are not. The group's kind survives only when the
|
|
702
|
+
* whole group agrees, so an aggregate row never claims a purpose it cannot
|
|
703
|
+
* prove. Ordered by cost, then count, then name. Pure. */
|
|
704
|
+
export declare function collectChildAgentUsage(views: readonly DelegationView[]): ChildAgentUsage[];
|
|
705
|
+
/** One agent rollup row: `<agent 12> ×<count 3>·<kind> <custo 7>`. The kind is
|
|
706
|
+
* glued to the count (the row's only label) and omitted for a mixed group; the
|
|
707
|
+
* agent column shrinks (never below the minimum) before the cost, which is
|
|
708
|
+
* what the row is for. Pure. */
|
|
709
|
+
export declare function childAgentRowText(row: ChildAgentUsage, max?: number): string;
|
|
710
|
+
/** The `… +K $<soma>` line for agents beyond the rollup cap. Null when every
|
|
711
|
+
* agent fits. Pure. */
|
|
712
|
+
export declare function hiddenChildAgentsText(hidden: number, hiddenCost: number): string | null;
|
|
713
|
+
/** Summary of the finished section: `✓ 70 · $3.40 · 9 agentes`. `· $<soma>` is
|
|
714
|
+
* omitted when nothing was spent and `· 1 agente` when a single agent owns
|
|
715
|
+
* every finished child; `✓ <total>` always prints. Null when nothing finished.
|
|
716
|
+
* Pure. */
|
|
717
|
+
export declare function completedSummaryText(completed: number | null | undefined, cost: number | null | undefined, agents: number | null | undefined): string | null;
|
|
718
|
+
/** The `· <F> falhas` suffix of the finished summary, null when nothing failed.
|
|
719
|
+
* Pure. */
|
|
720
|
+
export declare function failedSuffixText(failures: number | null | undefined): string | null;
|
|
721
|
+
/** One rendered live row: its text plus the session it navigates to. */
|
|
722
|
+
export type DispatchRunningLine = {
|
|
723
|
+
id: string;
|
|
724
|
+
text: string;
|
|
725
|
+
};
|
|
726
|
+
/** Everything the `Dispatch` block renders, already joined and capped. */
|
|
727
|
+
export type DispatchBlockView = {
|
|
728
|
+
runningCount: number;
|
|
729
|
+
completedCount: number;
|
|
730
|
+
agentCount: number;
|
|
731
|
+
failures: number;
|
|
732
|
+
totalCost: number;
|
|
733
|
+
running: DispatchRunningLine[];
|
|
734
|
+
runningHidden: number;
|
|
735
|
+
summary: string | null;
|
|
736
|
+
agents: ChildAgentUsage[];
|
|
737
|
+
agentsHidden: number;
|
|
738
|
+
agentsHiddenCost: number;
|
|
739
|
+
};
|
|
740
|
+
/** Build the whole block from the child set. Null when there is no child, so
|
|
741
|
+
* the block (and its spacer) never renders empty. Live work is capped at
|
|
742
|
+
* `DISPATCH_RUNNING_CEILING` and the finished rollup at
|
|
743
|
+
* `DISPATCH_AGENT_CEILING`, with the rollup giving up rows first to keep the
|
|
744
|
+
* block inside `DISPATCH_MAX_LINES`. Pure. */
|
|
745
|
+
export declare function buildDispatchBlock(views: readonly DelegationView[], now?: number, frame?: number, max?: number): DispatchBlockView | null;
|
|
746
|
+
/** Panel content name, registered by the `session.panel` claim and passed to
|
|
747
|
+
* `ui.panel.open`. */
|
|
748
|
+
export declare const DISPATCH_PANEL_NAME = "pantheon.dispatch";
|
|
749
|
+
/** Toast shown when `ui.panel.open` refuses (no session route is active). The
|
|
750
|
+
* panel only exists inside a session, so there is no alternative route. */
|
|
751
|
+
export declare const DISPATCH_PANEL_TOAST = "Abra uma sessão para ver o Dispatch";
|
|
752
|
+
/** Panel title marker — the same glyph the sidebar block header uses. */
|
|
753
|
+
export declare const DISPATCH_PANEL_HEADER_MARKER = "◈";
|
|
754
|
+
/** Selected-row gutter marker (`▸`, one cell). */
|
|
755
|
+
export declare const DISPATCH_PANEL_SELECTION_MARKER = "▸";
|
|
756
|
+
/** Cells the selection gutter occupies before a row's own text. */
|
|
757
|
+
export declare const DISPATCH_PANEL_SELECTION_GUTTER = 2;
|
|
758
|
+
/** Column of the horizontal rule under the header. */
|
|
759
|
+
export declare const DISPATCH_PANEL_RULE_CHAR = "─";
|
|
760
|
+
/** Em dash for any datum the host did not publish. */
|
|
761
|
+
export declare const DISPATCH_PANEL_DASH = "—";
|
|
762
|
+
/** Body of an empty panel (the claim still renders, the list is just empty). */
|
|
763
|
+
export declare const DISPATCH_PANEL_EMPTY_TEXT = "Nenhuma sessão delegada";
|
|
764
|
+
/** Width at or above which the list and the detail sit side by side. */
|
|
765
|
+
export declare const DISPATCH_PANEL_WIDE_MIN_WIDTH = 72;
|
|
766
|
+
/** Rows the viewport holds; pageup/pagedown move by exactly this many rows. */
|
|
767
|
+
export declare const DISPATCH_PANEL_PAGE_SIZE = 10;
|
|
768
|
+
/** Panel row columns: marker(2) + agent(12) + kind(4) + cost(≥7) + duration(8).
|
|
769
|
+
* The cost column is at least this wide; a sub-cent cost widens it per row. */
|
|
770
|
+
export declare const DISPATCH_PANEL_AGENT_WIDTH = 12;
|
|
771
|
+
export declare const DISPATCH_PANEL_MIN_AGENT_WIDTH = 6;
|
|
772
|
+
export declare const DISPATCH_PANEL_KIND_WIDTH = 4;
|
|
773
|
+
export declare const DISPATCH_PANEL_COST_WIDTH = 7;
|
|
774
|
+
export declare const DISPATCH_PANEL_DURATION_WIDTH = 8;
|
|
775
|
+
/** Title column budget (`◈ Dispatch — <sessão>`). */
|
|
776
|
+
export declare const DISPATCH_PANEL_TITLE_WIDTH = 44;
|
|
777
|
+
/** Badge appended to the title while the host presents the panel full screen. */
|
|
778
|
+
export declare const DISPATCH_PANEL_FULLSCREEN_BADGE = "[fullscreen]";
|
|
779
|
+
/** Human labels of a kind's evidence, as the detail line prints them. */
|
|
780
|
+
export declare const DISPATCH_KIND_ORIGIN_LABELS: Readonly<Record<DispatchKindOrigin, string>>;
|
|
781
|
+
/** Entries in row order: live work first, then most recent activity — the same
|
|
782
|
+
* comparator the sidebar block uses. Pure. */
|
|
783
|
+
export declare function orderDispatchEntries(entries: readonly DispatchEntry[]): DispatchEntry[];
|
|
784
|
+
/** `◈ Dispatch — <sessão>`, with the session title truncated (never wrapped),
|
|
785
|
+
* plus the `[fullscreen]` badge while the host presents the panel full screen.
|
|
786
|
+
* An absent title leaves the marker and the name alone. Pure. */
|
|
787
|
+
export declare function dispatchPanelTitle(sessionTitle: string | null | undefined, max?: number, presentation?: string): string;
|
|
788
|
+
/** Header counters: `2 rodando · 70 concluídos · 1 falha · $3.59`. A zero
|
|
789
|
+
* counter is omitted (never `0 rodando`); the total spend is printed whenever
|
|
790
|
+
* the tree has a child, because `$0.00` is then a real answer. Null for an
|
|
791
|
+
* empty tree, so the header renders no counter line at all. Pure. */
|
|
792
|
+
export declare function dispatchPanelHeader(entries: readonly DispatchEntry[] | null | undefined): string | null;
|
|
793
|
+
/** Horizontal rule under the header, clamped to the panel's own width. Pure. */
|
|
794
|
+
export declare function dispatchPanelRule(width: number, max?: number): string;
|
|
795
|
+
/** Row marker: animated spinner while running, `✓` done, `✗` failed, `○`
|
|
796
|
+
* cancelled/interrupted, `?` for a state the host never publishes. Every glyph
|
|
797
|
+
* is one cell wide and `?` is the only fallback, so an unknown state is visible
|
|
798
|
+
* instead of silently rendering as success. Pure. */
|
|
799
|
+
export declare function dispatchPanelMarker(state: DelegationState | string, frame?: number): string;
|
|
800
|
+
/** One padded, truncated cell: an absent/blank value becomes the em dash, and
|
|
801
|
+
* the value is cut to the cell's own width (never to the line's length, so one
|
|
802
|
+
* long cell cannot squeeze its neighbours out of alignment). Pure. */
|
|
803
|
+
export declare function dispatchPanelCell(value: unknown, width: number): string;
|
|
804
|
+
/** One list row: `⠋ prometheus plan $0.09 14m34s`. The agent cell absorbs
|
|
805
|
+
* the width difference (down to `DISPATCH_PANEL_MIN_AGENT_WIDTH`), so a narrow
|
|
806
|
+
* panel truncates the label rather than the numbers; the cost column grows by
|
|
807
|
+
* itself for a sub-cent value so the row never spends more than its budget.
|
|
808
|
+
* Pure. */
|
|
809
|
+
export declare function dispatchPanelRowText(entry: DispatchEntry, options?: {
|
|
810
|
+
now?: number;
|
|
811
|
+
frame?: number;
|
|
812
|
+
max?: number;
|
|
813
|
+
}): string;
|
|
814
|
+
/** `ses_ab12cd`, short enough for a detail line. Full id when it already fits. */
|
|
815
|
+
export declare function shortSessionID(id: string | null | undefined, max?: number): string;
|
|
816
|
+
/** Token counters of one child on a single line (`in 1.2K · out 430 · r 120 ·
|
|
817
|
+
* cache 8K/1K`), or `tokens —` when the host published none. Pure. */
|
|
818
|
+
export declare function dispatchTokenLine(tokens: DispatchTokens | null | undefined): string;
|
|
819
|
+
/** Detail lines of the selected child: heading (title, else the spawning
|
|
820
|
+
* description, else the row label), short id + model, token counters, and the
|
|
821
|
+
* kind plus its evidence and the parent id. Two to four lines; `expanded:
|
|
822
|
+
* false` keeps only the heading. Every missing datum prints `—`. Pure. */
|
|
823
|
+
export declare function dispatchPanelDetail(entry: DispatchEntry | null | undefined, options?: {
|
|
824
|
+
expanded?: boolean;
|
|
825
|
+
max?: number;
|
|
826
|
+
}): string[];
|
|
827
|
+
/** Panel geometry for its input width: wide (≥72) puts the detail in a second
|
|
828
|
+
* column, narrow stacks it under the list. `rowWidth` is what a list row may
|
|
829
|
+
* spend after the selection gutter. Pure. */
|
|
830
|
+
export type DispatchPanelLayout = {
|
|
831
|
+
mode: 'wide' | 'narrow';
|
|
832
|
+
listWidth: number;
|
|
833
|
+
detailWidth: number;
|
|
834
|
+
rowWidth: number;
|
|
835
|
+
};
|
|
836
|
+
export declare function dispatchPanelLayout(width: number): DispatchPanelLayout;
|
|
837
|
+
/** Viewport of the list: the page holding the selection, scrolled so the
|
|
838
|
+
* selected row stays visible with its predecessors. Bounded, so a 71-child
|
|
839
|
+
* tree renders ten rows, never all of them. Pure. */
|
|
840
|
+
export declare function dispatchPanelWindow(total: number, selectedIndex: number, pageSize?: number): {
|
|
841
|
+
start: number;
|
|
842
|
+
end: number;
|
|
843
|
+
size: number;
|
|
844
|
+
};
|
|
845
|
+
/** `1-10 de 71` while the list is longer than one page; null when everything
|
|
846
|
+
* fits (and for an empty list), so the footer never pads itself. Pure. */
|
|
847
|
+
export declare function dispatchPanelRangeText(start: number, end: number, total: number): string | null;
|
|
848
|
+
/** One rendered list row, selection resolved by the view against the model's
|
|
849
|
+
* selected id. */
|
|
850
|
+
export type DispatchPanelRow = {
|
|
851
|
+
id: string;
|
|
852
|
+
state: DelegationState;
|
|
853
|
+
text: string;
|
|
854
|
+
};
|
|
855
|
+
/** Every entry as a row, ordered by the shared comparator. Pure. */
|
|
856
|
+
export declare function dispatchPanelRows(entries: readonly DispatchEntry[] | null | undefined, options?: {
|
|
857
|
+
now?: number;
|
|
858
|
+
frame?: number;
|
|
859
|
+
max?: number;
|
|
860
|
+
}): DispatchPanelRow[];
|
|
861
|
+
/** Panel action, one per command. */
|
|
862
|
+
export type DispatchPanelAction = 'up' | 'down' | 'home' | 'end' | 'pageup' | 'pagedown' | 'toggle' | 'fullscreen' | 'close';
|
|
863
|
+
/** One namespaced command: stable id, explicit binding, and the action it runs. */
|
|
864
|
+
export type DispatchPanelCommandSpec = {
|
|
865
|
+
action: DispatchPanelAction;
|
|
866
|
+
id: string;
|
|
867
|
+
title: string;
|
|
868
|
+
bind: string;
|
|
869
|
+
};
|
|
870
|
+
/** The panel's whole keymap, in table order. `bind` is explicit for every
|
|
871
|
+
* command (no auto-binding), and every id is namespaced, so a `k`/`q`/`f`
|
|
872
|
+
* binding can never collide with the host's own keys. */
|
|
873
|
+
export declare const DISPATCH_PANEL_COMMANDS: readonly DispatchPanelCommandSpec[];
|
|
874
|
+
/** Run one action against the model and the host-owned panel input. Kept apart
|
|
875
|
+
* from the keymap so the whole command surface is testable without a renderer.
|
|
876
|
+
*/
|
|
877
|
+
export declare function performDispatchPanelAction(action: DispatchPanelAction, model: Pick<DispatchPanelModel, 'move' | 'first' | 'last' | 'pageUp' | 'pageDown' | 'toggle'>, panel: Pick<PanelInput, 'close' | 'toggleFullscreen'>): void;
|
|
878
|
+
/** Footer: the keys the host reports for each command (`keymap.shortcuts`) with
|
|
879
|
+
* an em dash whenever a command has no binding, so the hint can never advertise
|
|
880
|
+
* a key that does nothing. Pure. */
|
|
881
|
+
export declare function dispatchPanelFooter(shortcutsOf: (id: string) => readonly string[]): string;
|
|
882
|
+
/** The subset of `PanelInput` the model reads, so tests can drive it with a
|
|
883
|
+
* plain object. */
|
|
884
|
+
export type DispatchPanelInput = {
|
|
885
|
+
readonly name: string;
|
|
886
|
+
readonly sessionID: string;
|
|
887
|
+
readonly width: number;
|
|
888
|
+
readonly presentation?: string;
|
|
889
|
+
};
|
|
890
|
+
/** Open the panel from the command palette / slash command. `ui.panel.open`
|
|
891
|
+
* only accepts a `session` route, so a refusal (no session open) is answered
|
|
892
|
+
* with a toast — never a fallback route, never a silent no-op. Returns whether
|
|
893
|
+
* the panel opened. */
|
|
894
|
+
export declare function openDispatchPanel(context: any): boolean;
|
|
895
|
+
/** Reactive state the panel view renders. Selection is held by session id, so
|
|
896
|
+
* it survives list updates; the index is derived (and falls back to the first
|
|
897
|
+
* row when the selected child disappears). */
|
|
898
|
+
export type DispatchPanelModel = {
|
|
899
|
+
entries: Accessor<DispatchEntry[]>;
|
|
900
|
+
rows: Accessor<DispatchPanelRow[]>;
|
|
901
|
+
title: Accessor<string>;
|
|
902
|
+
header: Accessor<string | null>;
|
|
903
|
+
detail: Accessor<string[]>;
|
|
904
|
+
layout: Accessor<DispatchPanelLayout>;
|
|
905
|
+
visible: Accessor<{
|
|
906
|
+
start: number;
|
|
907
|
+
rows: DispatchPanelRow[];
|
|
908
|
+
}>;
|
|
909
|
+
selectedID: Accessor<string | null>;
|
|
910
|
+
selectedIndex: Accessor<number>;
|
|
911
|
+
expanded: Accessor<boolean>;
|
|
912
|
+
hasRunning: Accessor<boolean>;
|
|
913
|
+
frame: Accessor<number>;
|
|
914
|
+
footer: Accessor<string>;
|
|
915
|
+
move: (delta: number) => void;
|
|
916
|
+
first: () => void;
|
|
917
|
+
last: () => void;
|
|
918
|
+
pageUp: () => void;
|
|
919
|
+
pageDown: () => void;
|
|
920
|
+
toggle: () => void;
|
|
921
|
+
};
|
|
922
|
+
/** Model behind the panel. Mounted only while the panel claim renders (the
|
|
923
|
+
* `Show` in `session.panel`), so the 80 ms tick it arms exists exactly while
|
|
924
|
+
* the panel is open; it also stops on `isOpen()` going false and on dispose.
|
|
925
|
+
* It performs no `message.sync`, writes no `session.metadata` and makes no
|
|
926
|
+
* request: `collectDispatch` reads only host-cached state. */
|
|
927
|
+
export declare function createDispatchPanelModel(context: any, panel: () => DispatchPanelInput): DispatchPanelModel;
|
|
928
|
+
/** Session ids to eagerly sync at load (deduped, bounded). Pure. */
|
|
929
|
+
export declare function collectWarmupTargets(sessions: readonly any[], limit?: number): string[];
|
|
930
|
+
/** Body a sidebar instance renders when the host has not published a real
|
|
931
|
+
* session id yet. OpenCode V2 scopes the `sidebar.content` slot to a session
|
|
932
|
+
* (`SlotMap["sidebar.content"] = { sessionID: string }`), so before the first
|
|
933
|
+
* prompt the slot may not mount at all — see the `home.footer.status`
|
|
934
|
+
* contribution for the pre-prompt degradation. Pure. */
|
|
935
|
+
export declare function sidebarPlaceholder(sessionID: string | undefined): string | null;
|
|
936
|
+
/** Navigate to a session through the V2 router. Fail-open: an absent router or
|
|
937
|
+
* a removed session must never break the sidebar. Returns whether a valid
|
|
938
|
+
* navigation was dispatched. Pure. */
|
|
939
|
+
export declare function navigateToSession(router: {
|
|
940
|
+
navigate?: (destination: any) => void;
|
|
941
|
+
} | undefined, sessionID: string | undefined): boolean;
|
|
942
|
+
export type DelegationCompletion = {
|
|
943
|
+
id: string;
|
|
944
|
+
label: string;
|
|
945
|
+
state: DelegationState;
|
|
946
|
+
};
|
|
947
|
+
/** Diff two delegation observations: entries that were `running` and are no
|
|
948
|
+
* longer running count as completions, fired once per transition. Returns the
|
|
949
|
+
* next snapshot so callers can keep a single tracker. First observation never
|
|
950
|
+
* reports a completion (no toast spam on mount). Pure. */
|
|
951
|
+
export declare function detectDelegationCompletions(previous: ReadonlyMap<string, DelegationState>, current: ReadonlyArray<DelegationCompletion>): {
|
|
952
|
+
completed: DelegationCompletion[];
|
|
953
|
+
snapshot: Map<string, DelegationState>;
|
|
954
|
+
};
|
|
955
|
+
/** Debounce for the git file-count revalidation. `vcs.status` is an HTTP call;
|
|
956
|
+
* session events arrive in bursts, so the row is refreshed at most once per
|
|
957
|
+
* window instead of on every event. */
|
|
958
|
+
export declare const GIT_CHANGES_DEBOUNCE_MS = 400;
|
|
959
|
+
/** Reactive state the sidebar view renders. Accessors keep the view reactive
|
|
960
|
+
* while the model itself stays free of JSX, so its effects are exercisable
|
|
961
|
+
* without a TUI renderer. */
|
|
962
|
+
export type SidebarModel = {
|
|
963
|
+
activeSessionID: Accessor<string>;
|
|
964
|
+
session: Accessor<any>;
|
|
965
|
+
branch: Accessor<string | null>;
|
|
966
|
+
/** `+N ±N −N` file counts from `vcs.status` (fallback only), null when
|
|
967
|
+
* clean/unavailable. */
|
|
968
|
+
gitChanges: Accessor<string | null>;
|
|
969
|
+
/** The rendered git row: CLI counts with `?untracked ↑ahead ↓behind` when git
|
|
970
|
+
* answered, else the `vcs.status` counts, else null. */
|
|
971
|
+
gitLine: Accessor<string | null>;
|
|
972
|
+
/** Last successful git CLI observation (counts + upstream distance), null
|
|
973
|
+
* while git has never answered. */
|
|
974
|
+
gitCli: Accessor<GitCliSnapshot | null>;
|
|
975
|
+
/** Cache hit rate + output speed of the active session's newest messages. */
|
|
976
|
+
performance: Accessor<ContextPerformance | null>;
|
|
977
|
+
/** The rendered `Dispatch` block: live rows, the finished rollup and the
|
|
978
|
+
* spend totals. Null when the session has no child (block hidden). */
|
|
979
|
+
dispatch: Accessor<DispatchBlockView | null>;
|
|
980
|
+
/** Blocks that have content, in render order, each tagged with its spacer. */
|
|
981
|
+
blocks: Accessor<SidebarBlock[]>;
|
|
982
|
+
hasRunning: Accessor<boolean>;
|
|
983
|
+
frame: Accessor<number>;
|
|
984
|
+
preset: Accessor<PresetInfo>;
|
|
985
|
+
/** Provider of the model in use, derived from the session, its transcript or
|
|
986
|
+
* the host location; null when nothing resolves (the header omits it). */
|
|
987
|
+
provider: Accessor<string | null>;
|
|
988
|
+
/** Resolved preset override map (explicit per-agent models). */
|
|
989
|
+
presetOverrides: Accessor<PresetOverrides>;
|
|
990
|
+
/** Family cost in USD (root + delegations), null when the host cannot answer. */
|
|
991
|
+
cost: Accessor<number | null>;
|
|
992
|
+
/** Real per-model totals from assistant messages, capped for the sidebar. */
|
|
993
|
+
modelUsage: Accessor<ModelUsageCeiling>;
|
|
994
|
+
/** Todo rows derived from the newest completed `todowrite`, ordered + capped. */
|
|
995
|
+
todo: Accessor<TodoCeiling>;
|
|
996
|
+
/** Local spend for `hoje` / `30d`, null when stats is unavailable/unknown.
|
|
997
|
+
* Rendered as the Context block's last line, not as its own block. */
|
|
998
|
+
spend: Accessor<SpendTotals | null>;
|
|
999
|
+
/** Context gauge; null when there is no limit or no token-carrying message. */
|
|
1000
|
+
contextUsage: Accessor<ContextUsage | null>;
|
|
1001
|
+
/** Current agent and its resolved short model id (`*` = explicit override). */
|
|
1002
|
+
agentModel: Accessor<{
|
|
1003
|
+
agent: string;
|
|
1004
|
+
model: string;
|
|
1005
|
+
overridden: boolean;
|
|
1006
|
+
} | null>;
|
|
1007
|
+
};
|
|
1008
|
+
/** Reactive wiring behind the sidebar: refresh subscription, warm syncs, the
|
|
1009
|
+
* running-only spinner and the completion-toast effect. `context` stays loosely
|
|
1010
|
+
* typed (the host API only exists at runtime) but the refresh event names are
|
|
1011
|
+
* narrowed to the V2 union at the subscription site. */
|
|
1012
|
+
export declare function createSidebarModel(context: any, sessionID: () => string | undefined, gitExec?: GitExec): SidebarModel;
|
|
1013
|
+
/** One command: runs only while the panel owns the keyboard, and reports
|
|
1014
|
+
* `false` (the host keeps the key) when it cannot act. `undefined` means the
|
|
1015
|
+
* key was consumed. */
|
|
1016
|
+
export declare function runDispatchPanelCommand(action: DispatchPanelAction, panel: Pick<PanelInput, 'focused' | 'close' | 'toggleFullscreen'>, model: Pick<DispatchPanelModel, 'rows' | 'move' | 'first' | 'last' | 'pageUp' | 'pageDown' | 'toggle'>): false | undefined;
|
|
1017
|
+
/** Keymap layer of the panel, as data. It is registered inside the
|
|
1018
|
+
* `session.panel` claim, but the host mounts the effects of *every* panel
|
|
1019
|
+
* contribution, so the layer itself is not proof of focus: without `enabled`
|
|
1020
|
+
* the `j/k/f/q/enter/escape` bindings were consumed while the panel was not
|
|
1021
|
+
* focused and the composer lost its keys. `enabled` (the documented gate) makes
|
|
1022
|
+
* the whole layer inert until `panel.focused` is true. Pure. */
|
|
1023
|
+
export declare function dispatchPanelKeymapLayer(panel: Pick<PanelInput, 'focused' | 'close' | 'toggleFullscreen'>, model: DispatchPanelModel): KeymapLayer;
|
|
1024
|
+
/** Lean footer model: only the preset label and the live delegation count. It
|
|
1025
|
+
* deliberately does not reuse `createSidebarModel` — that model owns the
|
|
1026
|
+
* completion toasts and the spinner, and a second instance would double-toast.
|
|
1027
|
+
* No session id in the slot input is a graceful no-op (count 0). */
|
|
1028
|
+
export type FooterModel = {
|
|
1029
|
+
preset: Accessor<PresetInfo>;
|
|
1030
|
+
running: Accessor<number>;
|
|
1031
|
+
};
|
|
1032
|
+
export declare function createFooterModel(context: any, sessionID: () => string | undefined): FooterModel;
|
|
1033
|
+
declare const plugin: {
|
|
505
1034
|
id: string;
|
|
506
|
-
setup: () =>
|
|
1035
|
+
setup(context: Context): (() => void) | undefined;
|
|
507
1036
|
};
|
|
508
1037
|
//#endregion
|
|
509
|
-
export { plugin as default };
|
|
1038
|
+
export { type ContextProgressTone, plugin as default };
|
|
510
1039
|
//# sourceMappingURL=tui.d.ts.map
|