gsd-pi 2.18.0 → 2.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/cli.js +3 -3
- package/dist/onboarding.d.ts +3 -1
- package/dist/onboarding.js +77 -3
- package/dist/remote-questions-config.d.ts +1 -1
- package/dist/resources/extensions/google-search/index.ts +164 -47
- package/dist/resources/extensions/gsd/auto-dashboard.ts +14 -2
- package/dist/resources/extensions/gsd/auto-prompts.ts +148 -39
- package/dist/resources/extensions/gsd/auto-worktree.ts +93 -9
- package/dist/resources/extensions/gsd/auto.ts +690 -39
- package/dist/resources/extensions/gsd/captures.ts +384 -0
- package/dist/resources/extensions/gsd/commands.ts +654 -36
- package/dist/resources/extensions/gsd/complexity-classifier.ts +322 -0
- package/dist/resources/extensions/gsd/context-budget.ts +243 -0
- package/dist/resources/extensions/gsd/context-store.ts +195 -0
- package/dist/resources/extensions/gsd/dashboard-overlay.ts +51 -3
- package/dist/resources/extensions/gsd/db-writer.ts +341 -0
- package/dist/resources/extensions/gsd/debug-logger.ts +178 -0
- package/dist/resources/extensions/gsd/dispatch-guard.ts +0 -1
- package/dist/resources/extensions/gsd/docs/preferences-reference.md +54 -0
- package/dist/resources/extensions/gsd/doctor-proactive.ts +286 -0
- package/dist/resources/extensions/gsd/doctor.ts +283 -2
- package/dist/resources/extensions/gsd/export.ts +81 -2
- package/dist/resources/extensions/gsd/files.ts +39 -9
- package/dist/resources/extensions/gsd/git-service.ts +6 -0
- package/dist/resources/extensions/gsd/gsd-db.ts +752 -0
- package/dist/resources/extensions/gsd/guided-flow.ts +26 -1
- package/dist/resources/extensions/gsd/history.ts +0 -1
- package/dist/resources/extensions/gsd/index.ts +277 -1
- package/dist/resources/extensions/gsd/md-importer.ts +526 -0
- package/dist/resources/extensions/gsd/metrics.ts +84 -0
- package/dist/resources/extensions/gsd/model-cost-table.ts +65 -0
- package/dist/resources/extensions/gsd/model-router.ts +256 -0
- package/dist/resources/extensions/gsd/notifications.ts +0 -1
- package/dist/resources/extensions/gsd/post-unit-hooks.ts +72 -2
- package/dist/resources/extensions/gsd/preferences.ts +198 -150
- package/dist/resources/extensions/gsd/prompt-loader.ts +45 -9
- package/dist/resources/extensions/gsd/prompts/execute-task.md +3 -5
- package/dist/resources/extensions/gsd/prompts/heal-skill.md +45 -0
- package/dist/resources/extensions/gsd/prompts/plan-slice.md +5 -1
- package/dist/resources/extensions/gsd/prompts/quick-task.md +48 -0
- package/dist/resources/extensions/gsd/prompts/reassess-roadmap.md +6 -0
- package/dist/resources/extensions/gsd/prompts/replan-slice.md +8 -0
- package/dist/resources/extensions/gsd/prompts/system.md +2 -1
- package/dist/resources/extensions/gsd/prompts/triage-captures.md +62 -0
- package/dist/resources/extensions/gsd/quick.ts +156 -0
- package/dist/resources/extensions/gsd/skill-discovery.ts +5 -3
- package/dist/resources/extensions/gsd/skill-health.ts +417 -0
- package/dist/resources/extensions/gsd/skill-telemetry.ts +127 -0
- package/dist/resources/extensions/gsd/state.ts +30 -0
- package/dist/resources/extensions/gsd/templates/preferences.md +1 -0
- package/dist/resources/extensions/gsd/tests/captures.test.ts +438 -0
- package/dist/resources/extensions/gsd/tests/complexity-classifier.test.ts +181 -0
- package/dist/resources/extensions/gsd/tests/context-budget.test.ts +283 -0
- package/dist/resources/extensions/gsd/tests/context-compression.test.ts +1 -1
- package/dist/resources/extensions/gsd/tests/context-store.test.ts +462 -0
- package/dist/resources/extensions/gsd/tests/continue-here.test.ts +204 -0
- package/dist/resources/extensions/gsd/tests/dashboard-budget.test.ts +346 -0
- package/dist/resources/extensions/gsd/tests/db-writer.test.ts +602 -0
- package/dist/resources/extensions/gsd/tests/debug-logger.test.ts +185 -0
- package/dist/resources/extensions/gsd/tests/derive-state-db.test.ts +406 -0
- package/dist/resources/extensions/gsd/tests/dispatch-guard.test.ts +0 -1
- package/dist/resources/extensions/gsd/tests/dist-redirect.mjs +22 -0
- package/dist/resources/extensions/gsd/tests/doctor-proactive.test.ts +244 -0
- package/dist/resources/extensions/gsd/tests/doctor-runtime.test.ts +303 -0
- package/dist/resources/extensions/gsd/tests/feature-branch-lifecycle-integration.test.ts +434 -0
- package/dist/resources/extensions/gsd/tests/gsd-db.test.ts +353 -0
- package/dist/resources/extensions/gsd/tests/gsd-inspect.test.ts +125 -0
- package/dist/resources/extensions/gsd/tests/gsd-tools.test.ts +326 -0
- package/dist/resources/extensions/gsd/tests/integration-edge.test.ts +228 -0
- package/dist/resources/extensions/gsd/tests/integration-lifecycle.test.ts +277 -0
- package/dist/resources/extensions/gsd/tests/md-importer.test.ts +411 -0
- package/dist/resources/extensions/gsd/tests/metrics.test.ts +197 -0
- package/dist/resources/extensions/gsd/tests/milestone-transition-worktree.test.ts +144 -0
- package/dist/resources/extensions/gsd/tests/model-cost-table.test.ts +69 -0
- package/dist/resources/extensions/gsd/tests/model-isolation.test.ts +99 -0
- package/dist/resources/extensions/gsd/tests/model-router.test.ts +167 -0
- package/dist/resources/extensions/gsd/tests/parsers.test.ts +40 -0
- package/dist/resources/extensions/gsd/tests/post-unit-hooks.test.ts +41 -1
- package/dist/resources/extensions/gsd/tests/preferences-git.test.ts +0 -1
- package/dist/resources/extensions/gsd/tests/preferences-hooks.test.ts +0 -1
- package/dist/resources/extensions/gsd/tests/preferences-mode.test.ts +110 -0
- package/dist/resources/extensions/gsd/tests/preferences-models.test.ts +0 -1
- package/dist/resources/extensions/gsd/tests/prompt-budget-enforcement.test.ts +464 -0
- package/dist/resources/extensions/gsd/tests/prompt-db.test.ts +385 -0
- package/dist/resources/extensions/gsd/tests/remote-questions.test.ts +488 -1
- package/dist/resources/extensions/gsd/tests/resolve-ts-hooks.mjs +17 -29
- package/dist/resources/extensions/gsd/tests/resolve-ts.mjs +2 -8
- package/dist/resources/extensions/gsd/tests/routing-history.test.ts +215 -62
- package/dist/resources/extensions/gsd/tests/skill-lifecycle.test.ts +126 -0
- package/dist/resources/extensions/gsd/tests/stop-auto-remote.test.ts +31 -8
- package/dist/resources/extensions/gsd/tests/token-savings.test.ts +366 -0
- package/dist/resources/extensions/gsd/tests/triage-dispatch.test.ts +224 -0
- package/dist/resources/extensions/gsd/tests/triage-resolution.test.ts +215 -0
- package/dist/resources/extensions/gsd/tests/unit-runtime.test.ts +25 -1
- package/dist/resources/extensions/gsd/tests/visualizer-critical-path.test.ts +145 -0
- package/dist/resources/extensions/gsd/tests/visualizer-data.test.ts +290 -0
- package/dist/resources/extensions/gsd/tests/visualizer-overlay.test.ts +120 -0
- package/dist/resources/extensions/gsd/tests/visualizer-views.test.ts +478 -0
- package/dist/resources/extensions/gsd/tests/worktree-db-integration.test.ts +205 -0
- package/dist/resources/extensions/gsd/tests/worktree-db.test.ts +442 -0
- package/dist/resources/extensions/gsd/tests/worktree-post-create-hook.test.ts +165 -0
- package/dist/resources/extensions/gsd/triage-resolution.ts +200 -0
- package/dist/resources/extensions/gsd/triage-ui.ts +175 -0
- package/dist/resources/extensions/gsd/types.ts +29 -0
- package/dist/resources/extensions/gsd/undo.ts +0 -1
- package/dist/resources/extensions/gsd/unit-runtime.ts +5 -1
- package/dist/resources/extensions/gsd/visualizer-data.ts +505 -0
- package/dist/resources/extensions/gsd/visualizer-overlay.ts +337 -0
- package/dist/resources/extensions/gsd/visualizer-views.ts +755 -0
- package/dist/resources/extensions/gsd/worktree-command.ts +18 -0
- package/dist/resources/extensions/gsd/worktree-manager.ts +11 -4
- package/dist/resources/extensions/remote-questions/config.ts +4 -2
- package/dist/resources/extensions/remote-questions/discord-adapter.ts +35 -4
- package/dist/resources/extensions/remote-questions/format.ts +166 -14
- package/dist/resources/extensions/remote-questions/manager.ts +14 -4
- package/dist/resources/extensions/remote-questions/remote-command.ts +100 -4
- package/dist/resources/extensions/remote-questions/slack-adapter.ts +58 -2
- package/dist/resources/extensions/remote-questions/telegram-adapter.ts +161 -0
- package/dist/resources/extensions/remote-questions/types.ts +2 -1
- package/dist/resources/extensions/ttsr/ttsr-manager.ts +26 -0
- package/dist/resources/extensions/voice/index.ts +4 -3
- package/package.json +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session.js +12 -1
- package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.js +5 -0
- package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/client.d.ts +6 -0
- package/packages/pi-coding-agent/dist/core/lsp/client.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/client.js +25 -0
- package/packages/pi-coding-agent/dist/core/lsp/client.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/index.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/lsp/index.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/index.js +106 -3
- package/packages/pi-coding-agent/dist/core/lsp/index.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/lsp.md +6 -0
- package/packages/pi-coding-agent/dist/core/lsp/types.d.ts +35 -0
- package/packages/pi-coding-agent/dist/core/lsp/types.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/types.js +6 -0
- package/packages/pi-coding-agent/dist/core/lsp/types.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/utils.d.ts +3 -1
- package/packages/pi-coding-agent/dist/core/lsp/utils.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/utils.js +45 -0
- package/packages/pi-coding-agent/dist/core/lsp/utils.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/settings-manager.d.ts +6 -0
- package/packages/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/settings-manager.js +43 -11
- package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/system-prompt.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/system-prompt.js +7 -1
- package/packages/pi-coding-agent/dist/core/system-prompt.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/tools/edit.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/tools/edit.js +5 -0
- package/packages/pi-coding-agent/dist/core/tools/edit.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/tools/index.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/tools/index.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/tools/write.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/tools/write.js +5 -0
- package/packages/pi-coding-agent/dist/core/tools/write.js.map +1 -1
- package/packages/pi-coding-agent/src/core/agent-session.ts +13 -1
- package/packages/pi-coding-agent/src/core/extensions/loader.ts +6 -0
- package/packages/pi-coding-agent/src/core/lsp/client.ts +26 -0
- package/packages/pi-coding-agent/src/core/lsp/index.ts +157 -2
- package/packages/pi-coding-agent/src/core/lsp/lsp.md +6 -0
- package/packages/pi-coding-agent/src/core/lsp/types.ts +53 -0
- package/packages/pi-coding-agent/src/core/lsp/utils.ts +56 -0
- package/packages/pi-coding-agent/src/core/settings-manager.ts +41 -11
- package/packages/pi-coding-agent/src/core/system-prompt.ts +7 -1
- package/packages/pi-coding-agent/src/core/tools/edit.ts +3 -0
- package/packages/pi-coding-agent/src/core/tools/write.ts +3 -0
- package/src/resources/extensions/google-search/index.ts +164 -47
- package/src/resources/extensions/gsd/auto-dashboard.ts +14 -2
- package/src/resources/extensions/gsd/auto-prompts.ts +148 -39
- package/src/resources/extensions/gsd/auto-worktree.ts +93 -9
- package/src/resources/extensions/gsd/auto.ts +690 -39
- package/src/resources/extensions/gsd/captures.ts +384 -0
- package/src/resources/extensions/gsd/commands.ts +654 -36
- package/src/resources/extensions/gsd/complexity-classifier.ts +322 -0
- package/src/resources/extensions/gsd/context-budget.ts +243 -0
- package/src/resources/extensions/gsd/context-store.ts +195 -0
- package/src/resources/extensions/gsd/dashboard-overlay.ts +51 -3
- package/src/resources/extensions/gsd/db-writer.ts +341 -0
- package/src/resources/extensions/gsd/debug-logger.ts +178 -0
- package/src/resources/extensions/gsd/dispatch-guard.ts +0 -1
- package/src/resources/extensions/gsd/docs/preferences-reference.md +54 -0
- package/src/resources/extensions/gsd/doctor-proactive.ts +286 -0
- package/src/resources/extensions/gsd/doctor.ts +283 -2
- package/src/resources/extensions/gsd/export.ts +81 -2
- package/src/resources/extensions/gsd/files.ts +39 -9
- package/src/resources/extensions/gsd/git-service.ts +6 -0
- package/src/resources/extensions/gsd/gsd-db.ts +752 -0
- package/src/resources/extensions/gsd/guided-flow.ts +26 -1
- package/src/resources/extensions/gsd/history.ts +0 -1
- package/src/resources/extensions/gsd/index.ts +277 -1
- package/src/resources/extensions/gsd/md-importer.ts +526 -0
- package/src/resources/extensions/gsd/metrics.ts +84 -0
- package/src/resources/extensions/gsd/model-cost-table.ts +65 -0
- package/src/resources/extensions/gsd/model-router.ts +256 -0
- package/src/resources/extensions/gsd/notifications.ts +0 -1
- package/src/resources/extensions/gsd/post-unit-hooks.ts +72 -2
- package/src/resources/extensions/gsd/preferences.ts +198 -150
- package/src/resources/extensions/gsd/prompt-loader.ts +45 -9
- package/src/resources/extensions/gsd/prompts/execute-task.md +3 -5
- package/src/resources/extensions/gsd/prompts/heal-skill.md +45 -0
- package/src/resources/extensions/gsd/prompts/plan-slice.md +5 -1
- package/src/resources/extensions/gsd/prompts/quick-task.md +48 -0
- package/src/resources/extensions/gsd/prompts/reassess-roadmap.md +6 -0
- package/src/resources/extensions/gsd/prompts/replan-slice.md +8 -0
- package/src/resources/extensions/gsd/prompts/system.md +2 -1
- package/src/resources/extensions/gsd/prompts/triage-captures.md +62 -0
- package/src/resources/extensions/gsd/quick.ts +156 -0
- package/src/resources/extensions/gsd/skill-discovery.ts +5 -3
- package/src/resources/extensions/gsd/skill-health.ts +417 -0
- package/src/resources/extensions/gsd/skill-telemetry.ts +127 -0
- package/src/resources/extensions/gsd/state.ts +30 -0
- package/src/resources/extensions/gsd/templates/preferences.md +1 -0
- package/src/resources/extensions/gsd/tests/captures.test.ts +438 -0
- package/src/resources/extensions/gsd/tests/complexity-classifier.test.ts +181 -0
- package/src/resources/extensions/gsd/tests/context-budget.test.ts +283 -0
- package/src/resources/extensions/gsd/tests/context-compression.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/context-store.test.ts +462 -0
- package/src/resources/extensions/gsd/tests/continue-here.test.ts +204 -0
- package/src/resources/extensions/gsd/tests/dashboard-budget.test.ts +346 -0
- package/src/resources/extensions/gsd/tests/db-writer.test.ts +602 -0
- package/src/resources/extensions/gsd/tests/debug-logger.test.ts +185 -0
- package/src/resources/extensions/gsd/tests/derive-state-db.test.ts +406 -0
- package/src/resources/extensions/gsd/tests/dispatch-guard.test.ts +0 -1
- package/src/resources/extensions/gsd/tests/dist-redirect.mjs +22 -0
- package/src/resources/extensions/gsd/tests/doctor-proactive.test.ts +244 -0
- package/src/resources/extensions/gsd/tests/doctor-runtime.test.ts +303 -0
- package/src/resources/extensions/gsd/tests/feature-branch-lifecycle-integration.test.ts +434 -0
- package/src/resources/extensions/gsd/tests/gsd-db.test.ts +353 -0
- package/src/resources/extensions/gsd/tests/gsd-inspect.test.ts +125 -0
- package/src/resources/extensions/gsd/tests/gsd-tools.test.ts +326 -0
- package/src/resources/extensions/gsd/tests/integration-edge.test.ts +228 -0
- package/src/resources/extensions/gsd/tests/integration-lifecycle.test.ts +277 -0
- package/src/resources/extensions/gsd/tests/md-importer.test.ts +411 -0
- package/src/resources/extensions/gsd/tests/metrics.test.ts +197 -0
- package/src/resources/extensions/gsd/tests/milestone-transition-worktree.test.ts +144 -0
- package/src/resources/extensions/gsd/tests/model-cost-table.test.ts +69 -0
- package/src/resources/extensions/gsd/tests/model-isolation.test.ts +99 -0
- package/src/resources/extensions/gsd/tests/model-router.test.ts +167 -0
- package/src/resources/extensions/gsd/tests/parsers.test.ts +40 -0
- package/src/resources/extensions/gsd/tests/post-unit-hooks.test.ts +41 -1
- package/src/resources/extensions/gsd/tests/preferences-git.test.ts +0 -1
- package/src/resources/extensions/gsd/tests/preferences-hooks.test.ts +0 -1
- package/src/resources/extensions/gsd/tests/preferences-mode.test.ts +110 -0
- package/src/resources/extensions/gsd/tests/preferences-models.test.ts +0 -1
- package/src/resources/extensions/gsd/tests/prompt-budget-enforcement.test.ts +464 -0
- package/src/resources/extensions/gsd/tests/prompt-db.test.ts +385 -0
- package/src/resources/extensions/gsd/tests/remote-questions.test.ts +488 -1
- package/src/resources/extensions/gsd/tests/resolve-ts-hooks.mjs +17 -29
- package/src/resources/extensions/gsd/tests/resolve-ts.mjs +2 -8
- package/src/resources/extensions/gsd/tests/routing-history.test.ts +215 -62
- package/src/resources/extensions/gsd/tests/skill-lifecycle.test.ts +126 -0
- package/src/resources/extensions/gsd/tests/stop-auto-remote.test.ts +31 -8
- package/src/resources/extensions/gsd/tests/token-savings.test.ts +366 -0
- package/src/resources/extensions/gsd/tests/triage-dispatch.test.ts +224 -0
- package/src/resources/extensions/gsd/tests/triage-resolution.test.ts +215 -0
- package/src/resources/extensions/gsd/tests/unit-runtime.test.ts +25 -1
- package/src/resources/extensions/gsd/tests/visualizer-critical-path.test.ts +145 -0
- package/src/resources/extensions/gsd/tests/visualizer-data.test.ts +290 -0
- package/src/resources/extensions/gsd/tests/visualizer-overlay.test.ts +120 -0
- package/src/resources/extensions/gsd/tests/visualizer-views.test.ts +478 -0
- package/src/resources/extensions/gsd/tests/worktree-db-integration.test.ts +205 -0
- package/src/resources/extensions/gsd/tests/worktree-db.test.ts +442 -0
- package/src/resources/extensions/gsd/tests/worktree-post-create-hook.test.ts +165 -0
- package/src/resources/extensions/gsd/triage-resolution.ts +200 -0
- package/src/resources/extensions/gsd/triage-ui.ts +175 -0
- package/src/resources/extensions/gsd/types.ts +29 -0
- package/src/resources/extensions/gsd/undo.ts +0 -1
- package/src/resources/extensions/gsd/unit-runtime.ts +5 -1
- package/src/resources/extensions/gsd/visualizer-data.ts +505 -0
- package/src/resources/extensions/gsd/visualizer-overlay.ts +337 -0
- package/src/resources/extensions/gsd/visualizer-views.ts +755 -0
- package/src/resources/extensions/gsd/worktree-command.ts +18 -0
- package/src/resources/extensions/gsd/worktree-manager.ts +11 -4
- package/src/resources/extensions/remote-questions/config.ts +4 -2
- package/src/resources/extensions/remote-questions/discord-adapter.ts +35 -4
- package/src/resources/extensions/remote-questions/format.ts +166 -14
- package/src/resources/extensions/remote-questions/manager.ts +14 -4
- package/src/resources/extensions/remote-questions/remote-command.ts +100 -4
- package/src/resources/extensions/remote-questions/slack-adapter.ts +58 -2
- package/src/resources/extensions/remote-questions/telegram-adapter.ts +161 -0
- package/src/resources/extensions/remote-questions/types.ts +2 -1
- package/src/resources/extensions/ttsr/ttsr-manager.ts +26 -0
- package/src/resources/extensions/voice/index.ts +4 -3
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for dashboard budget indicator rendering.
|
|
3
|
+
*
|
|
4
|
+
* Tests the rendering logic that wires budget data from the metrics
|
|
5
|
+
* aggregation layer into the dashboard overlay's three sections:
|
|
6
|
+
* Completed (per-unit ▼N and → wrap-up), By Model (context window),
|
|
7
|
+
* and Cost & Usage (aggregate budget summary line).
|
|
8
|
+
*
|
|
9
|
+
* Since the overlay class depends on global state (auto module, file system),
|
|
10
|
+
* we test the rendering patterns directly using the real formatting and
|
|
11
|
+
* aggregation functions, verifying the exact strings that would appear.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
type UnitMetrics,
|
|
16
|
+
type MetricsLedger,
|
|
17
|
+
aggregateByModel,
|
|
18
|
+
getProjectTotals,
|
|
19
|
+
formatTokenCount,
|
|
20
|
+
} from "../metrics.js";
|
|
21
|
+
import { createTestContext } from './test-helpers.ts';
|
|
22
|
+
|
|
23
|
+
const { assertEq, assertTrue, assertMatch, assertNoMatch, report } = createTestContext();
|
|
24
|
+
|
|
25
|
+
// ─── Test helpers ─────────────────────────────────────────────────────────────
|
|
26
|
+
|
|
27
|
+
function makeUnit(overrides: Partial<UnitMetrics> = {}): UnitMetrics {
|
|
28
|
+
return {
|
|
29
|
+
type: "execute-task",
|
|
30
|
+
id: "M001/S01/T01",
|
|
31
|
+
model: "claude-sonnet-4-20250514",
|
|
32
|
+
startedAt: 1000,
|
|
33
|
+
finishedAt: 2000,
|
|
34
|
+
tokens: { input: 1000, output: 500, cacheRead: 200, cacheWrite: 100, total: 1800 },
|
|
35
|
+
cost: 0.05,
|
|
36
|
+
toolCalls: 3,
|
|
37
|
+
assistantMessages: 2,
|
|
38
|
+
userMessages: 1,
|
|
39
|
+
...overrides,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Simulate the Completed section's budget marker rendering logic.
|
|
45
|
+
* This replicates the exact logic from buildContentLines() in dashboard-overlay.ts.
|
|
46
|
+
*/
|
|
47
|
+
function renderCompletedBudgetMarkers(
|
|
48
|
+
completedUnit: { type: string; id: string },
|
|
49
|
+
ledgerUnits: UnitMetrics[],
|
|
50
|
+
): string {
|
|
51
|
+
// Build lookup (same logic as dashboard-overlay.ts)
|
|
52
|
+
const ledgerLookup = new Map<string, UnitMetrics>();
|
|
53
|
+
for (const lu of ledgerUnits) {
|
|
54
|
+
ledgerLookup.set(`${lu.type}:${lu.id}`, lu);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const ledgerEntry = ledgerLookup.get(`${completedUnit.type}:${completedUnit.id}`);
|
|
58
|
+
let budgetMarkers = "";
|
|
59
|
+
if (ledgerEntry) {
|
|
60
|
+
if (ledgerEntry.truncationSections && ledgerEntry.truncationSections > 0) {
|
|
61
|
+
budgetMarkers += ` ▼${ledgerEntry.truncationSections}`;
|
|
62
|
+
}
|
|
63
|
+
if (ledgerEntry.continueHereFired === true) {
|
|
64
|
+
budgetMarkers += " → wrap-up";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return budgetMarkers;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Simulate the Cost & Usage budget summary line rendering logic.
|
|
72
|
+
* Returns the plain text version (without ANSI colors).
|
|
73
|
+
*/
|
|
74
|
+
function renderCostBudgetLine(units: UnitMetrics[]): string | null {
|
|
75
|
+
const totals = getProjectTotals(units);
|
|
76
|
+
if (totals.totalTruncationSections > 0 || totals.continueHereFiredCount > 0) {
|
|
77
|
+
const parts: string[] = [];
|
|
78
|
+
if (totals.totalTruncationSections > 0) {
|
|
79
|
+
parts.push(`${totals.totalTruncationSections} sections truncated`);
|
|
80
|
+
}
|
|
81
|
+
if (totals.continueHereFiredCount > 0) {
|
|
82
|
+
parts.push(`${totals.continueHereFiredCount} continue-here fired`);
|
|
83
|
+
}
|
|
84
|
+
return parts.join(" · ");
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Simulate the By Model context window rendering logic.
|
|
91
|
+
* Returns the context window label for a given model's aggregate.
|
|
92
|
+
*/
|
|
93
|
+
function renderModelContextWindow(units: UnitMetrics[], modelName: string): string | null {
|
|
94
|
+
const models = aggregateByModel(units);
|
|
95
|
+
const m = models.find(agg => agg.model === modelName);
|
|
96
|
+
if (!m) return null;
|
|
97
|
+
if (m.contextWindowTokens !== undefined) {
|
|
98
|
+
return `[${formatTokenCount(m.contextWindowTokens)}]`;
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// ─── Completed section: budget indicators ─────────────────────────────────────
|
|
104
|
+
|
|
105
|
+
console.log("\n=== Completed section: truncation + continue-here markers ===");
|
|
106
|
+
|
|
107
|
+
{
|
|
108
|
+
// Unit with truncation and continue-here — both markers appear
|
|
109
|
+
const ledgerUnits = [
|
|
110
|
+
makeUnit({ type: "execute-task", id: "M001/S01/T01", truncationSections: 3, continueHereFired: true }),
|
|
111
|
+
];
|
|
112
|
+
const markers = renderCompletedBudgetMarkers(
|
|
113
|
+
{ type: "execute-task", id: "M001/S01/T01" },
|
|
114
|
+
ledgerUnits,
|
|
115
|
+
);
|
|
116
|
+
assertMatch(markers, /▼3/, "completed: shows ▼3 for 3 truncation sections");
|
|
117
|
+
assertMatch(markers, /→ wrap-up/, "completed: shows → wrap-up when continueHereFired");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
{
|
|
121
|
+
// Unit with truncation only — no wrap-up marker
|
|
122
|
+
const ledgerUnits = [
|
|
123
|
+
makeUnit({ type: "execute-task", id: "M001/S01/T01", truncationSections: 5, continueHereFired: false }),
|
|
124
|
+
];
|
|
125
|
+
const markers = renderCompletedBudgetMarkers(
|
|
126
|
+
{ type: "execute-task", id: "M001/S01/T01" },
|
|
127
|
+
ledgerUnits,
|
|
128
|
+
);
|
|
129
|
+
assertMatch(markers, /▼5/, "completed: shows ▼5 truncation only");
|
|
130
|
+
assertNoMatch(markers, /wrap-up/, "completed: no wrap-up when continueHereFired=false");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
{
|
|
134
|
+
// Unit with continue-here only — no truncation marker
|
|
135
|
+
const ledgerUnits = [
|
|
136
|
+
makeUnit({ type: "execute-task", id: "M001/S01/T01", truncationSections: 0, continueHereFired: true }),
|
|
137
|
+
];
|
|
138
|
+
const markers = renderCompletedBudgetMarkers(
|
|
139
|
+
{ type: "execute-task", id: "M001/S01/T01" },
|
|
140
|
+
ledgerUnits,
|
|
141
|
+
);
|
|
142
|
+
assertNoMatch(markers, /▼/, "completed: no ▼ when truncationSections=0");
|
|
143
|
+
assertMatch(markers, /→ wrap-up/, "completed: shows → wrap-up");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ─── Completed section: missing ledger match ──────────────────────────────────
|
|
147
|
+
|
|
148
|
+
console.log("\n=== Completed section: missing ledger match ===");
|
|
149
|
+
|
|
150
|
+
{
|
|
151
|
+
// Completed unit with no matching ledger entry — no crash, no markers
|
|
152
|
+
const ledgerUnits = [
|
|
153
|
+
makeUnit({ type: "execute-task", id: "M001/S01/T99", truncationSections: 3 }),
|
|
154
|
+
];
|
|
155
|
+
const markers = renderCompletedBudgetMarkers(
|
|
156
|
+
{ type: "execute-task", id: "M001/S01/T01" },
|
|
157
|
+
ledgerUnits,
|
|
158
|
+
);
|
|
159
|
+
assertEq(markers, "", "missing match: empty markers when no ledger entry matches");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
{
|
|
163
|
+
// Empty ledger — no crash, no markers
|
|
164
|
+
const markers = renderCompletedBudgetMarkers(
|
|
165
|
+
{ type: "execute-task", id: "M001/S01/T01" },
|
|
166
|
+
[],
|
|
167
|
+
);
|
|
168
|
+
assertEq(markers, "", "empty ledger: empty markers");
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ─── Completed section: retry handling (last entry wins) ──────────────────────
|
|
172
|
+
|
|
173
|
+
console.log("\n=== Completed section: retry handling ===");
|
|
174
|
+
|
|
175
|
+
{
|
|
176
|
+
// Two ledger entries for same unit (retry) — last entry wins
|
|
177
|
+
const ledgerUnits = [
|
|
178
|
+
makeUnit({ type: "execute-task", id: "M001/S01/T01", truncationSections: 1 }),
|
|
179
|
+
makeUnit({ type: "execute-task", id: "M001/S01/T01", truncationSections: 7 }),
|
|
180
|
+
];
|
|
181
|
+
const markers = renderCompletedBudgetMarkers(
|
|
182
|
+
{ type: "execute-task", id: "M001/S01/T01" },
|
|
183
|
+
ledgerUnits,
|
|
184
|
+
);
|
|
185
|
+
assertMatch(markers, /▼7/, "retry: last entry's truncation count (7) wins over first (1)");
|
|
186
|
+
assertNoMatch(markers, /▼1/, "retry: first entry's count (1) is not shown");
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// ─── By Model section: context window display ─────────────────────────────────
|
|
190
|
+
|
|
191
|
+
console.log("\n=== By Model section: context window ===");
|
|
192
|
+
|
|
193
|
+
{
|
|
194
|
+
// Model with context window — shows formatted token count
|
|
195
|
+
const units = [
|
|
196
|
+
makeUnit({ model: "claude-sonnet-4-20250514", contextWindowTokens: 200000 }),
|
|
197
|
+
];
|
|
198
|
+
const label = renderModelContextWindow(units, "claude-sonnet-4-20250514");
|
|
199
|
+
assertEq(label, "[200.0k]", "by model: shows [200.0k] for 200000 context window");
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
{
|
|
203
|
+
// Model without context window — no label
|
|
204
|
+
const units = [
|
|
205
|
+
makeUnit({ model: "claude-sonnet-4-20250514" }),
|
|
206
|
+
];
|
|
207
|
+
const label = renderModelContextWindow(units, "claude-sonnet-4-20250514");
|
|
208
|
+
assertEq(label, null, "by model: null when no contextWindowTokens");
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
{
|
|
212
|
+
// Multiple models — each gets its own context window
|
|
213
|
+
const units = [
|
|
214
|
+
makeUnit({ model: "claude-sonnet-4-20250514", contextWindowTokens: 200000, cost: 0.05 }),
|
|
215
|
+
makeUnit({ model: "claude-opus-4-20250514", contextWindowTokens: 200000, cost: 0.30 }),
|
|
216
|
+
];
|
|
217
|
+
const sonnetLabel = renderModelContextWindow(units, "claude-sonnet-4-20250514");
|
|
218
|
+
const opusLabel = renderModelContextWindow(units, "claude-opus-4-20250514");
|
|
219
|
+
assertEq(sonnetLabel, "[200.0k]", "by model multi: sonnet has context window");
|
|
220
|
+
assertEq(opusLabel, "[200.0k]", "by model multi: opus has context window");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// ─── By Model section: single model visibility ───────────────────────────────
|
|
224
|
+
|
|
225
|
+
console.log("\n=== By Model section: single model visibility ===");
|
|
226
|
+
|
|
227
|
+
{
|
|
228
|
+
// With guard changed to >= 1, single model aggregation should produce results
|
|
229
|
+
const units = [
|
|
230
|
+
makeUnit({ model: "claude-sonnet-4-20250514" }),
|
|
231
|
+
];
|
|
232
|
+
const models = aggregateByModel(units);
|
|
233
|
+
assertTrue(models.length >= 1, "single model: aggregateByModel returns >= 1 entry");
|
|
234
|
+
assertEq(models.length, 1, "single model: exactly 1 model aggregate");
|
|
235
|
+
assertEq(models[0].model, "claude-sonnet-4-20250514", "single model: correct model name");
|
|
236
|
+
// The guard `models.length >= 1` (changed from > 1) means this section now renders
|
|
237
|
+
assertTrue(models.length >= 1, "single model: passes >= 1 guard (section will render)");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// ─── Cost & Usage: aggregate budget line ──────────────────────────────────────
|
|
241
|
+
|
|
242
|
+
console.log("\n=== Cost & Usage: aggregate budget line ===");
|
|
243
|
+
|
|
244
|
+
{
|
|
245
|
+
// Units with truncation and continue-here — both stats appear
|
|
246
|
+
const units = [
|
|
247
|
+
makeUnit({ truncationSections: 3, continueHereFired: true }),
|
|
248
|
+
makeUnit({ truncationSections: 2, continueHereFired: false }),
|
|
249
|
+
makeUnit({ truncationSections: 1, continueHereFired: true }),
|
|
250
|
+
];
|
|
251
|
+
const line = renderCostBudgetLine(units);
|
|
252
|
+
assertTrue(line !== null, "cost budget: line rendered when budget data exists");
|
|
253
|
+
assertMatch(line!, /6 sections truncated/, "cost budget: shows total truncation count (3+2+1=6)");
|
|
254
|
+
assertMatch(line!, /2 continue-here fired/, "cost budget: shows continue-here count");
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
{
|
|
258
|
+
// Only truncation, no continue-here
|
|
259
|
+
const units = [
|
|
260
|
+
makeUnit({ truncationSections: 4, continueHereFired: false }),
|
|
261
|
+
];
|
|
262
|
+
const line = renderCostBudgetLine(units);
|
|
263
|
+
assertTrue(line !== null, "cost budget truncation-only: line rendered");
|
|
264
|
+
assertMatch(line!, /4 sections truncated/, "cost budget truncation-only: shows count");
|
|
265
|
+
assertNoMatch(line!, /continue-here/, "cost budget truncation-only: no continue-here text");
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
{
|
|
269
|
+
// Only continue-here, no truncation
|
|
270
|
+
const units = [
|
|
271
|
+
makeUnit({ truncationSections: 0, continueHereFired: true }),
|
|
272
|
+
];
|
|
273
|
+
const line = renderCostBudgetLine(units);
|
|
274
|
+
assertTrue(line !== null, "cost budget continue-only: line rendered");
|
|
275
|
+
assertNoMatch(line!, /truncated/, "cost budget continue-only: no truncation text");
|
|
276
|
+
assertMatch(line!, /1 continue-here fired/, "cost budget continue-only: shows count");
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// ─── Backward compat: no budget fields ────────────────────────────────────────
|
|
280
|
+
|
|
281
|
+
console.log("\n=== Backward compat: no budget data ===");
|
|
282
|
+
|
|
283
|
+
{
|
|
284
|
+
// Old-format units without budget fields — no indicators anywhere
|
|
285
|
+
const oldUnits = [
|
|
286
|
+
makeUnit(), // no budget fields
|
|
287
|
+
makeUnit({ id: "M001/S01/T02" }),
|
|
288
|
+
];
|
|
289
|
+
|
|
290
|
+
// Completed section: no markers
|
|
291
|
+
const markers = renderCompletedBudgetMarkers(
|
|
292
|
+
{ type: "execute-task", id: "M001/S01/T01" },
|
|
293
|
+
oldUnits,
|
|
294
|
+
);
|
|
295
|
+
assertNoMatch(markers, /▼/, "backward compat completed: no truncation marker");
|
|
296
|
+
assertNoMatch(markers, /wrap-up/, "backward compat completed: no wrap-up marker");
|
|
297
|
+
assertEq(markers, "", "backward compat completed: empty markers string");
|
|
298
|
+
|
|
299
|
+
// By Model section: no context window label
|
|
300
|
+
const label = renderModelContextWindow(oldUnits, "claude-sonnet-4-20250514");
|
|
301
|
+
assertEq(label, null, "backward compat by-model: no context window label");
|
|
302
|
+
|
|
303
|
+
// Cost & Usage: no budget line
|
|
304
|
+
const line = renderCostBudgetLine(oldUnits);
|
|
305
|
+
assertEq(line, null, "backward compat cost: no budget summary line");
|
|
306
|
+
|
|
307
|
+
// Aggregation still works
|
|
308
|
+
const totals = getProjectTotals(oldUnits);
|
|
309
|
+
assertEq(totals.totalTruncationSections, 0, "backward compat: truncation total = 0");
|
|
310
|
+
assertEq(totals.continueHereFiredCount, 0, "backward compat: continueHere count = 0");
|
|
311
|
+
assertEq(totals.units, 2, "backward compat: unit count correct");
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// ─── Edge cases ───────────────────────────────────────────────────────────────
|
|
315
|
+
|
|
316
|
+
console.log("\n=== Edge cases ===");
|
|
317
|
+
|
|
318
|
+
{
|
|
319
|
+
// formatTokenCount for context window values
|
|
320
|
+
assertEq(formatTokenCount(200000), "200.0k", "format: 200000 → 200.0k");
|
|
321
|
+
assertEq(formatTokenCount(128000), "128.0k", "format: 128000 → 128.0k");
|
|
322
|
+
assertEq(formatTokenCount(1000000), "1.00M", "format: 1000000 → 1.00M");
|
|
323
|
+
assertEq(formatTokenCount(32000), "32.0k", "format: 32000 → 32.0k");
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
{
|
|
327
|
+
// Completed unit key includes type — different types don't collide
|
|
328
|
+
const ledgerUnits = [
|
|
329
|
+
makeUnit({ type: "research-slice", id: "M001/S01", truncationSections: 2 }),
|
|
330
|
+
makeUnit({ type: "plan-slice", id: "M001/S01", truncationSections: 5 }),
|
|
331
|
+
];
|
|
332
|
+
const researchMarkers = renderCompletedBudgetMarkers(
|
|
333
|
+
{ type: "research-slice", id: "M001/S01" },
|
|
334
|
+
ledgerUnits,
|
|
335
|
+
);
|
|
336
|
+
const planMarkers = renderCompletedBudgetMarkers(
|
|
337
|
+
{ type: "plan-slice", id: "M001/S01" },
|
|
338
|
+
ledgerUnits,
|
|
339
|
+
);
|
|
340
|
+
assertMatch(researchMarkers, /▼2/, "type-keying: research unit gets its own truncation count");
|
|
341
|
+
assertMatch(planMarkers, /▼5/, "type-keying: plan unit gets its own truncation count");
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// ─── Summary ──────────────────────────────────────────────────────────────────
|
|
345
|
+
|
|
346
|
+
report();
|