opencode-dux 1.0.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/LICENSE +21 -0
- package/README.md +452 -0
- package/dist/agents/descriptions.d.ts +6 -0
- package/dist/agents/designer.d.ts +2 -0
- package/dist/agents/explorer.d.ts +2 -0
- package/dist/agents/fixer.d.ts +2 -0
- package/dist/agents/index.d.ts +22 -0
- package/dist/agents/interpreter.d.ts +2 -0
- package/dist/agents/librarian.d.ts +2 -0
- package/dist/agents/oracle.d.ts +2 -0
- package/dist/agents/orchestrator.d.ts +27 -0
- package/dist/agents/overrides.d.ts +18 -0
- package/dist/agents/prompt-blocks.d.ts +97 -0
- package/dist/agents/steward.d.ts +3 -0
- package/dist/cli/config-io.d.ts +24 -0
- package/dist/cli/config-manager.d.ts +4 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +1006 -0
- package/dist/cli/install.d.ts +2 -0
- package/dist/cli/mcps.d.ts +13 -0
- package/dist/cli/model-key-normalization.d.ts +1 -0
- package/dist/cli/paths.d.ts +35 -0
- package/dist/cli/providers.d.ts +137 -0
- package/dist/cli/skills.d.ts +22 -0
- package/dist/cli/system.d.ts +5 -0
- package/dist/cli/types.d.ts +38 -0
- package/dist/config/constants.d.ts +12 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/loader.d.ts +40 -0
- package/dist/config/runtime-preset.d.ts +12 -0
- package/dist/config/schema.d.ts +281 -0
- package/dist/config/utils.d.ts +10 -0
- package/dist/discovery/local/types.d.ts +79 -0
- package/dist/discovery/local.d.ts +73 -0
- package/dist/discovery/mcp-servers.d.ts +88 -0
- package/dist/discovery/skills.d.ts +94 -0
- package/dist/hooks/apply-patch/codec.d.ts +7 -0
- package/dist/hooks/apply-patch/errors.d.ts +25 -0
- package/dist/hooks/apply-patch/execution-context.d.ts +27 -0
- package/dist/hooks/apply-patch/index.d.ts +15 -0
- package/dist/hooks/apply-patch/matching.d.ts +26 -0
- package/dist/hooks/apply-patch/operations.d.ts +3 -0
- package/dist/hooks/apply-patch/patch.d.ts +2 -0
- package/dist/hooks/apply-patch/prepared-changes.d.ts +17 -0
- package/dist/hooks/apply-patch/resolution.d.ts +19 -0
- package/dist/hooks/apply-patch/rewrite.d.ts +7 -0
- package/dist/hooks/apply-patch/test-helpers.d.ts +6 -0
- package/dist/hooks/apply-patch/types.d.ts +80 -0
- package/dist/hooks/auto-update-checker/cache.d.ts +11 -0
- package/dist/hooks/auto-update-checker/checker.d.ts +32 -0
- package/dist/hooks/auto-update-checker/constants.d.ts +11 -0
- package/dist/hooks/auto-update-checker/index.d.ts +18 -0
- package/dist/hooks/auto-update-checker/types.d.ts +22 -0
- package/dist/hooks/chat-headers.d.ts +16 -0
- package/dist/hooks/context-pressure-reminder/index.d.ts +33 -0
- package/dist/hooks/delegate-task-retry/guidance.d.ts +2 -0
- package/dist/hooks/delegate-task-retry/hook.d.ts +8 -0
- package/dist/hooks/delegate-task-retry/index.d.ts +4 -0
- package/dist/hooks/delegate-task-retry/patterns.d.ts +11 -0
- package/dist/hooks/filter-available-skills/index.d.ts +32 -0
- package/dist/hooks/foreground-fallback/index.d.ts +72 -0
- package/dist/hooks/image-hook.d.ts +5 -0
- package/dist/hooks/index.d.ts +14 -0
- package/dist/hooks/json-error-recovery/hook.d.ts +18 -0
- package/dist/hooks/json-error-recovery/index.d.ts +1 -0
- package/dist/hooks/phase-reminder/index.d.ts +26 -0
- package/dist/hooks/post-file-tool-nudge/index.d.ts +19 -0
- package/dist/hooks/task-session-manager/index.d.ts +52 -0
- package/dist/hooks/todo-continuation/index.d.ts +53 -0
- package/dist/hooks/todo-continuation/todo-hygiene.d.ts +35 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +31782 -0
- package/dist/mcp/context7.d.ts +6 -0
- package/dist/mcp/grep-app.d.ts +6 -0
- package/dist/mcp/index.d.ts +13 -0
- package/dist/mcp/types.d.ts +12 -0
- package/dist/mcp/websearch.d.ts +9 -0
- package/dist/skills/registry.d.ts +29 -0
- package/dist/subscriptions/accounts-store.d.ts +57 -0
- package/dist/subscriptions/index.d.ts +13 -0
- package/dist/subscriptions/neuralwatt-scraper.d.ts +14 -0
- package/dist/subscriptions/opencode-go-scraper.d.ts +27 -0
- package/dist/subscriptions/types.d.ts +115 -0
- package/dist/subscriptions/usage-service.d.ts +74 -0
- package/dist/tools/ast-grep/cli.d.ts +15 -0
- package/dist/tools/ast-grep/constants.d.ts +25 -0
- package/dist/tools/ast-grep/downloader.d.ts +5 -0
- package/dist/tools/ast-grep/index.d.ts +10 -0
- package/dist/tools/ast-grep/tools.d.ts +3 -0
- package/dist/tools/ast-grep/types.d.ts +30 -0
- package/dist/tools/ast-grep/utils.d.ts +4 -0
- package/dist/tools/delegate.d.ts +14 -0
- package/dist/tools/index.d.ts +5 -0
- package/dist/tools/preset-manager.d.ts +27 -0
- package/dist/tools/smartfetch/binary.d.ts +3 -0
- package/dist/tools/smartfetch/cache.d.ts +6 -0
- package/dist/tools/smartfetch/constants.d.ts +12 -0
- package/dist/tools/smartfetch/index.d.ts +3 -0
- package/dist/tools/smartfetch/network.d.ts +38 -0
- package/dist/tools/smartfetch/secondary-model.d.ts +28 -0
- package/dist/tools/smartfetch/tool.d.ts +3 -0
- package/dist/tools/smartfetch/types.d.ts +122 -0
- package/dist/tools/smartfetch/utils.d.ts +18 -0
- package/dist/tui-state.d.ts +168 -0
- package/dist/tui.d.ts +37 -0
- package/dist/tui.js +1896 -0
- package/dist/utils/agent-variant.d.ts +63 -0
- package/dist/utils/compat.d.ts +30 -0
- package/dist/utils/env.d.ts +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/internal-initiator.d.ts +6 -0
- package/dist/utils/logger.d.ts +8 -0
- package/dist/utils/polling.d.ts +21 -0
- package/dist/utils/session-manager.d.ts +55 -0
- package/dist/utils/session.d.ts +90 -0
- package/dist/utils/subagent-depth.d.ts +35 -0
- package/dist/utils/system-collapse.d.ts +6 -0
- package/dist/utils/task.d.ts +4 -0
- package/dist/utils/zip-extractor.d.ts +1 -0
- package/index.ts +1 -0
- package/opencode-dux.schema.json +634 -0
- package/package.json +103 -0
- package/src/agents/descriptions.ts +55 -0
- package/src/agents/designer.test.ts +86 -0
- package/src/agents/designer.ts +154 -0
- package/src/agents/display-name.test.ts +186 -0
- package/src/agents/explorer.test.ts +79 -0
- package/src/agents/explorer.ts +144 -0
- package/src/agents/fixer.test.ts +79 -0
- package/src/agents/fixer.ts +145 -0
- package/src/agents/index.test.ts +472 -0
- package/src/agents/index.ts +248 -0
- package/src/agents/interpreter.ts +136 -0
- package/src/agents/librarian.test.ts +80 -0
- package/src/agents/librarian.ts +145 -0
- package/src/agents/oracle.test.ts +89 -0
- package/src/agents/oracle.ts +184 -0
- package/src/agents/orchestrator.test.ts +116 -0
- package/src/agents/orchestrator.ts +574 -0
- package/src/agents/overrides.ts +95 -0
- package/src/agents/prompt-blocks.test.ts +114 -0
- package/src/agents/prompt-blocks.ts +640 -0
- package/src/agents/steward.ts +146 -0
- package/src/cli/config-io.test.ts +536 -0
- package/src/cli/config-io.ts +473 -0
- package/src/cli/config-manager.test.ts +141 -0
- package/src/cli/config-manager.ts +4 -0
- package/src/cli/index.ts +88 -0
- package/src/cli/install.ts +282 -0
- package/src/cli/mcps.test.ts +62 -0
- package/src/cli/mcps.ts +39 -0
- package/src/cli/model-key-normalization.test.ts +21 -0
- package/src/cli/model-key-normalization.ts +60 -0
- package/src/cli/paths.test.ts +167 -0
- package/src/cli/paths.ts +144 -0
- package/src/cli/providers.test.ts +118 -0
- package/src/cli/providers.ts +141 -0
- package/src/cli/skills.test.ts +111 -0
- package/src/cli/skills.ts +103 -0
- package/src/cli/system.test.ts +91 -0
- package/src/cli/system.ts +180 -0
- package/src/cli/types.ts +43 -0
- package/src/config/constants.ts +58 -0
- package/src/config/index.ts +4 -0
- package/src/config/loader.test.ts +1194 -0
- package/src/config/loader.ts +269 -0
- package/src/config/model-resolution.test.ts +176 -0
- package/src/config/runtime-preset.test.ts +61 -0
- package/src/config/runtime-preset.ts +37 -0
- package/src/config/schema.ts +248 -0
- package/src/config/utils.test.ts +41 -0
- package/src/config/utils.ts +23 -0
- package/src/discovery/local/types.ts +85 -0
- package/src/discovery/local.ts +322 -0
- package/src/discovery/mcp-servers.ts +804 -0
- package/src/discovery/skills.ts +959 -0
- package/src/hooks/apply-patch/codec.test.ts +184 -0
- package/src/hooks/apply-patch/codec.ts +352 -0
- package/src/hooks/apply-patch/errors.ts +117 -0
- package/src/hooks/apply-patch/execution-context.ts +432 -0
- package/src/hooks/apply-patch/hook.test.ts +768 -0
- package/src/hooks/apply-patch/index.ts +126 -0
- package/src/hooks/apply-patch/matching.test.ts +215 -0
- package/src/hooks/apply-patch/matching.ts +586 -0
- package/src/hooks/apply-patch/operations.test.ts +1535 -0
- package/src/hooks/apply-patch/operations.ts +3 -0
- package/src/hooks/apply-patch/patch.ts +9 -0
- package/src/hooks/apply-patch/prepared-changes.ts +400 -0
- package/src/hooks/apply-patch/resolution.test.ts +420 -0
- package/src/hooks/apply-patch/resolution.ts +437 -0
- package/src/hooks/apply-patch/rewrite.ts +496 -0
- package/src/hooks/apply-patch/test-helpers.ts +52 -0
- package/src/hooks/apply-patch/types.ts +111 -0
- package/src/hooks/auto-update-checker/cache.test.ts +179 -0
- package/src/hooks/auto-update-checker/cache.ts +188 -0
- package/src/hooks/auto-update-checker/checker.test.ts +159 -0
- package/src/hooks/auto-update-checker/checker.ts +308 -0
- package/src/hooks/auto-update-checker/constants.ts +33 -0
- package/src/hooks/auto-update-checker/index.test.ts +282 -0
- package/src/hooks/auto-update-checker/index.ts +225 -0
- package/src/hooks/auto-update-checker/types.ts +26 -0
- package/src/hooks/chat-headers.test.ts +236 -0
- package/src/hooks/chat-headers.ts +97 -0
- package/src/hooks/context-pressure-reminder/index.test.ts +179 -0
- package/src/hooks/context-pressure-reminder/index.ts +137 -0
- package/src/hooks/delegate-task-retry/guidance.ts +41 -0
- package/src/hooks/delegate-task-retry/hook.ts +23 -0
- package/src/hooks/delegate-task-retry/index.test.ts +38 -0
- package/src/hooks/delegate-task-retry/index.ts +7 -0
- package/src/hooks/delegate-task-retry/patterns.ts +79 -0
- package/src/hooks/filter-available-skills/index.test.ts +297 -0
- package/src/hooks/filter-available-skills/index.ts +160 -0
- package/src/hooks/foreground-fallback/index.test.ts +624 -0
- package/src/hooks/foreground-fallback/index.ts +374 -0
- package/src/hooks/image-hook.ts +6 -0
- package/src/hooks/index.ts +17 -0
- package/src/hooks/json-error-recovery/hook.ts +73 -0
- package/src/hooks/json-error-recovery/index.test.ts +111 -0
- package/src/hooks/json-error-recovery/index.ts +6 -0
- package/src/hooks/phase-reminder/index.test.ts +74 -0
- package/src/hooks/phase-reminder/index.ts +85 -0
- package/src/hooks/post-file-tool-nudge/index.test.ts +94 -0
- package/src/hooks/post-file-tool-nudge/index.ts +63 -0
- package/src/hooks/task-session-manager/index.test.ts +833 -0
- package/src/hooks/task-session-manager/index.ts +434 -0
- package/src/hooks/todo-continuation/index.test.ts +3026 -0
- package/src/hooks/todo-continuation/index.ts +878 -0
- package/src/hooks/todo-continuation/todo-hygiene.test.ts +204 -0
- package/src/hooks/todo-continuation/todo-hygiene.ts +207 -0
- package/src/index.ts +1672 -0
- package/src/mcp/context7.ts +14 -0
- package/src/mcp/grep-app.ts +11 -0
- package/src/mcp/index.test.ts +96 -0
- package/src/mcp/index.ts +66 -0
- package/src/mcp/types.ts +16 -0
- package/src/mcp/websearch.ts +47 -0
- package/src/skills/codemap/README.md +60 -0
- package/src/skills/codemap/SKILL.md +174 -0
- package/src/skills/codemap/scripts/codemap.mjs +483 -0
- package/src/skills/codemap/scripts/codemap.test.ts +129 -0
- package/src/skills/registry.ts +218 -0
- package/src/skills/simplify/README.md +19 -0
- package/src/skills/simplify/SKILL.md +138 -0
- package/src/subscriptions/accounts-store.test.ts +236 -0
- package/src/subscriptions/accounts-store.ts +184 -0
- package/src/subscriptions/index.ts +30 -0
- package/src/subscriptions/neuralwatt-scraper.ts +108 -0
- package/src/subscriptions/opencode-go-scraper.ts +301 -0
- package/src/subscriptions/types.ts +145 -0
- package/src/subscriptions/usage-service.test.ts +202 -0
- package/src/subscriptions/usage-service.ts +651 -0
- package/src/tools/ast-grep/cli.ts +257 -0
- package/src/tools/ast-grep/constants.ts +214 -0
- package/src/tools/ast-grep/downloader.ts +131 -0
- package/src/tools/ast-grep/index.ts +24 -0
- package/src/tools/ast-grep/tools.ts +117 -0
- package/src/tools/ast-grep/types.ts +51 -0
- package/src/tools/ast-grep/utils.ts +126 -0
- package/src/tools/delegate-handoff.test.ts +18 -0
- package/src/tools/delegate.ts +508 -0
- package/src/tools/index.ts +8 -0
- package/src/tools/preset-manager.test.ts +795 -0
- package/src/tools/preset-manager.ts +332 -0
- package/src/tools/smartfetch/binary.ts +58 -0
- package/src/tools/smartfetch/cache.test.ts +34 -0
- package/src/tools/smartfetch/cache.ts +112 -0
- package/src/tools/smartfetch/constants.ts +29 -0
- package/src/tools/smartfetch/index.ts +8 -0
- package/src/tools/smartfetch/network.test.ts +178 -0
- package/src/tools/smartfetch/network.ts +614 -0
- package/src/tools/smartfetch/secondary-model.test.ts +85 -0
- package/src/tools/smartfetch/secondary-model.ts +276 -0
- package/src/tools/smartfetch/tool.test.ts +60 -0
- package/src/tools/smartfetch/tool.ts +832 -0
- package/src/tools/smartfetch/types.ts +135 -0
- package/src/tools/smartfetch/utils.test.ts +24 -0
- package/src/tools/smartfetch/utils.ts +456 -0
- package/src/tui-state.test.ts +867 -0
- package/src/tui-state.ts +1255 -0
- package/src/tui.test.ts +336 -0
- package/src/tui.ts +1539 -0
- package/src/utils/agent-variant.test.ts +244 -0
- package/src/utils/agent-variant.ts +187 -0
- package/src/utils/compat.ts +91 -0
- package/src/utils/env.ts +12 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/internal-initiator.ts +28 -0
- package/src/utils/logger.test.ts +220 -0
- package/src/utils/logger.ts +136 -0
- package/src/utils/polling.test.ts +191 -0
- package/src/utils/polling.ts +67 -0
- package/src/utils/session-manager.test.ts +173 -0
- package/src/utils/session-manager.ts +356 -0
- package/src/utils/session.test.ts +110 -0
- package/src/utils/session.ts +389 -0
- package/src/utils/subagent-depth.test.ts +170 -0
- package/src/utils/subagent-depth.ts +75 -0
- package/src/utils/system-collapse.test.ts +86 -0
- package/src/utils/system-collapse.ts +24 -0
- package/src/utils/task.test.ts +24 -0
- package/src/utils/task.ts +20 -0
- package/src/utils/zip-extractor.ts +102 -0
package/src/tui.test.ts
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import {
|
|
3
|
+
aggregateOrchestrationUsage,
|
|
4
|
+
formatDuration,
|
|
5
|
+
formatSessionUsageRows,
|
|
6
|
+
formatSidebarModelAndVariant,
|
|
7
|
+
formatSidebarModelName,
|
|
8
|
+
formatTokenAbbrev,
|
|
9
|
+
formatTokenAbbrevDecimal,
|
|
10
|
+
getSidebarAgentNames,
|
|
11
|
+
} from './tui';
|
|
12
|
+
import type {
|
|
13
|
+
SessionUsageEntry,
|
|
14
|
+
TuiSessionBundle,
|
|
15
|
+
TuiSnapshot,
|
|
16
|
+
} from './tui-state';
|
|
17
|
+
|
|
18
|
+
function bundleFixture(
|
|
19
|
+
rootSessionId: string,
|
|
20
|
+
overrides: Partial<TuiSessionBundle> & Pick<TuiSessionBundle, 'tree'>,
|
|
21
|
+
): TuiSessionBundle {
|
|
22
|
+
return {
|
|
23
|
+
rootSessionId,
|
|
24
|
+
lastActivityAt: overrides.lastActivityAt ?? 0,
|
|
25
|
+
projectPath: overrides.projectPath,
|
|
26
|
+
tree: overrides.tree,
|
|
27
|
+
orchestrationSigmaAccum: overrides.orchestrationSigmaAccum,
|
|
28
|
+
orchestrationUsageLastSeen: overrides.orchestrationUsageLastSeen ?? {},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function createSnapshot(): TuiSnapshot {
|
|
33
|
+
return {
|
|
34
|
+
version: 6,
|
|
35
|
+
updatedAt: 0,
|
|
36
|
+
sessions: {},
|
|
37
|
+
subscriptionUsage: {},
|
|
38
|
+
activeSubscriptionByProvider: {},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('tui sidebar agents', () => {
|
|
43
|
+
test('lists agents that have sidebar description entries', () => {
|
|
44
|
+
const agentNames = getSidebarAgentNames(createSnapshot());
|
|
45
|
+
|
|
46
|
+
expect(agentNames).toContain('explorer');
|
|
47
|
+
expect(agentNames).toContain('fixer');
|
|
48
|
+
expect(agentNames).toContain('orchestrator');
|
|
49
|
+
expect(agentNames).not.toContain('nonexistent-agent');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('sorts sidebar agents using AGENT_SORT_PRIORITY', () => {
|
|
53
|
+
const agentNames = getSidebarAgentNames(createSnapshot());
|
|
54
|
+
expect(agentNames.indexOf('orchestrator')).toBeLessThan(
|
|
55
|
+
agentNames.indexOf('explorer'),
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('formatSidebarModelName', () => {
|
|
61
|
+
test('keeps only the segment after the last slash', () => {
|
|
62
|
+
expect(formatSidebarModelName('openai/gpt-5.5-fast')).toBe('gpt-5.5-fast');
|
|
63
|
+
expect(
|
|
64
|
+
formatSidebarModelName(
|
|
65
|
+
'fireworks-ai/accounts/fireworks/routers/kimi-k2p5-turbo',
|
|
66
|
+
),
|
|
67
|
+
).toBe('kimi-k2p5-turbo');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('leaves model names without slashes unchanged', () => {
|
|
71
|
+
expect(formatSidebarModelName('pending')).toBe('pending');
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('formatSidebarModelAndVariant', () => {
|
|
76
|
+
test('long basename stacks hyphen segments then ellipsis; variant stays full', () => {
|
|
77
|
+
expect(
|
|
78
|
+
formatSidebarModelAndVariant('opencode/Qwen3.5-397B-A17B-FP8', 'High'),
|
|
79
|
+
).toBe('Qwen3.5-397B-A17B… - High');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('long basename without OpenCode variant uses segment ellipsis only', () => {
|
|
83
|
+
expect(
|
|
84
|
+
formatSidebarModelAndVariant('opencode/Qwen3.5-397B-A17B-FP8', undefined),
|
|
85
|
+
).toBe('Qwen3.5-397B-A17B…');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('smaller maxModelDisplayLen yields a shorter hyphen-safe prefix', () => {
|
|
89
|
+
expect(
|
|
90
|
+
formatSidebarModelAndVariant(
|
|
91
|
+
'opencode/Qwen3.5-397B-A17B-FP8',
|
|
92
|
+
'High',
|
|
93
|
+
14,
|
|
94
|
+
),
|
|
95
|
+
).toBe('Qwen3.5-397B… - High');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('larger cap fits full basename before OpenCode variant', () => {
|
|
99
|
+
expect(
|
|
100
|
+
formatSidebarModelAndVariant(
|
|
101
|
+
'opencode/Qwen3.5-397B-A17B-FP8',
|
|
102
|
+
'High',
|
|
103
|
+
28,
|
|
104
|
+
),
|
|
105
|
+
).toBe('Qwen3.5-397B-A17B-FP8 - High');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('short basenames show full id; variant appended', () => {
|
|
109
|
+
expect(formatSidebarModelAndVariant('openai/gpt-4o', 'High')).toBe(
|
|
110
|
+
'gpt-4o - High',
|
|
111
|
+
);
|
|
112
|
+
expect(formatSidebarModelAndVariant('openai/gpt-4o', undefined)).toBe(
|
|
113
|
+
'gpt-4o',
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('long basename without hyphen falls back to character truncate', () => {
|
|
118
|
+
const long = 'abcdefghijklmnopqrstu';
|
|
119
|
+
expect(formatSidebarModelAndVariant(`x/${long}`, undefined)).toBe(
|
|
120
|
+
'abcdefghijklmnopqrs…',
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('formatDuration', () => {
|
|
126
|
+
test('formats milliseconds as MM:SS under 1 hour', () => {
|
|
127
|
+
expect(formatDuration(0)).toBe('0:00');
|
|
128
|
+
expect(formatDuration(1_000)).toBe('0:01');
|
|
129
|
+
expect(formatDuration(60_000)).toBe('1:00');
|
|
130
|
+
expect(formatDuration(699_000)).toBe('11:39');
|
|
131
|
+
expect(formatDuration(3_599_000)).toBe('59:59');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('formats as H:MM:SS for 1 hour or more', () => {
|
|
135
|
+
expect(formatDuration(3_600_000)).toBe('1:00:00');
|
|
136
|
+
expect(formatDuration(5_019_000)).toBe('1:23:39');
|
|
137
|
+
expect(formatDuration(7_200_000)).toBe('2:00:00');
|
|
138
|
+
expect(formatDuration(86_400_000)).toBe('24:00:00');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('handles edge cases', () => {
|
|
142
|
+
expect(formatDuration(-1)).toBe('0:00');
|
|
143
|
+
expect(formatDuration(Infinity)).toBe('0:00');
|
|
144
|
+
expect(formatDuration(NaN)).toBe('0:00');
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('orchestrating usage metrics formatters', () => {
|
|
149
|
+
test('abbreviates token counts for sidebar rows', () => {
|
|
150
|
+
expect(formatTokenAbbrev(950)).toBe('950');
|
|
151
|
+
expect(formatTokenAbbrev(1_500)).toBe('2K');
|
|
152
|
+
expect(formatTokenAbbrev(8_200)).toBe('8K');
|
|
153
|
+
expect(formatTokenAbbrev(150_000)).toBe('150K');
|
|
154
|
+
expect(formatTokenAbbrev(999_500)).toBe('1M');
|
|
155
|
+
expect(formatTokenAbbrev(1_150_000)).toBe('1M');
|
|
156
|
+
expect(formatTokenAbbrev(1_500_000)).toBe('2M');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('abbreviates with 1 decimal for context used values', () => {
|
|
160
|
+
expect(formatTokenAbbrevDecimal(100)).toBe('100');
|
|
161
|
+
expect(formatTokenAbbrevDecimal(999)).toBe('999');
|
|
162
|
+
expect(formatTokenAbbrevDecimal(1_000)).toBe('1.0K');
|
|
163
|
+
expect(formatTokenAbbrevDecimal(1_100)).toBe('1.1K');
|
|
164
|
+
expect(formatTokenAbbrevDecimal(8_200)).toBe('8.2K');
|
|
165
|
+
expect(formatTokenAbbrevDecimal(150_000)).toBe('150.0K');
|
|
166
|
+
expect(formatTokenAbbrevDecimal(999_000)).toBe('999.0K');
|
|
167
|
+
expect(formatTokenAbbrevDecimal(1_200_000)).toBe('1.2M');
|
|
168
|
+
expect(formatTokenAbbrevDecimal(1_500_000)).toBe('1.5M');
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('formats context/input/output/cache rows for a session', () => {
|
|
172
|
+
const snapshot = createSnapshot();
|
|
173
|
+
snapshot.sessions['session-1'] = bundleFixture('session-1', {
|
|
174
|
+
tree: {
|
|
175
|
+
'session-1': {
|
|
176
|
+
title: '',
|
|
177
|
+
agent: 'explorer',
|
|
178
|
+
model: '',
|
|
179
|
+
childIds: [],
|
|
180
|
+
status: 'busy',
|
|
181
|
+
createdAt: 0,
|
|
182
|
+
usage: {
|
|
183
|
+
contextUsed: 150_000,
|
|
184
|
+
contextLimit: 400_000,
|
|
185
|
+
contextPct: 38,
|
|
186
|
+
input: 8_000,
|
|
187
|
+
output: 900,
|
|
188
|
+
reasoning: 200,
|
|
189
|
+
cacheRead: 200,
|
|
190
|
+
cacheWrite: 300,
|
|
191
|
+
updatedAt: 0,
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
expect(formatSessionUsageRows(snapshot, 'session-1')).toEqual({
|
|
198
|
+
contextPct: 38,
|
|
199
|
+
ctxLabel: 'CTX',
|
|
200
|
+
ctxValue: '150,000/400,000 (38%)',
|
|
201
|
+
ioInputAbbrev: '8K',
|
|
202
|
+
ioOutputAbbrev: '900',
|
|
203
|
+
cacheLabel: 'CACHE',
|
|
204
|
+
cacheValue: '500',
|
|
205
|
+
cacheReadAbbrev: '200',
|
|
206
|
+
cacheWriteAbbrev: '300',
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test('formats context with different abbreviation styles when abbreviateLeft is true', () => {
|
|
211
|
+
const snapshot = createSnapshot();
|
|
212
|
+
snapshot.sessions['session-1'] = bundleFixture('session-1', {
|
|
213
|
+
tree: {
|
|
214
|
+
'session-1': {
|
|
215
|
+
title: '',
|
|
216
|
+
agent: 'explorer',
|
|
217
|
+
model: '',
|
|
218
|
+
childIds: [],
|
|
219
|
+
status: 'busy',
|
|
220
|
+
createdAt: 0,
|
|
221
|
+
usage: {
|
|
222
|
+
contextUsed: 150_000,
|
|
223
|
+
contextLimit: 400_000,
|
|
224
|
+
contextPct: 38,
|
|
225
|
+
input: 8_000,
|
|
226
|
+
output: 900,
|
|
227
|
+
reasoning: 200,
|
|
228
|
+
cacheRead: 200,
|
|
229
|
+
cacheWrite: 300,
|
|
230
|
+
updatedAt: 0,
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
expect(
|
|
237
|
+
formatSessionUsageRows(snapshot, 'session-1', { abbreviateLeft: true }),
|
|
238
|
+
).toEqual({
|
|
239
|
+
contextPct: 38,
|
|
240
|
+
ctxLabel: 'CTX',
|
|
241
|
+
ctxValue: '150.0K/400K (38%)',
|
|
242
|
+
ioInputAbbrev: '8K',
|
|
243
|
+
ioOutputAbbrev: '900',
|
|
244
|
+
cacheLabel: 'CACHE',
|
|
245
|
+
cacheValue: '500',
|
|
246
|
+
cacheReadAbbrev: '200',
|
|
247
|
+
cacheWriteAbbrev: '300',
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test('aggregates totals across orchestrator and descendants', () => {
|
|
252
|
+
const orchUsage: SessionUsageEntry = {
|
|
253
|
+
contextUsed: 0,
|
|
254
|
+
contextLimit: 0,
|
|
255
|
+
contextPct: 0,
|
|
256
|
+
input: 1_000,
|
|
257
|
+
output: 200,
|
|
258
|
+
reasoning: 50,
|
|
259
|
+
cacheRead: 100,
|
|
260
|
+
cacheWrite: 20,
|
|
261
|
+
updatedAt: 0,
|
|
262
|
+
};
|
|
263
|
+
const childAUsage: SessionUsageEntry = {
|
|
264
|
+
contextUsed: 0,
|
|
265
|
+
contextLimit: 0,
|
|
266
|
+
contextPct: 0,
|
|
267
|
+
input: 2_000,
|
|
268
|
+
output: 400,
|
|
269
|
+
reasoning: 80,
|
|
270
|
+
cacheRead: 300,
|
|
271
|
+
cacheWrite: 40,
|
|
272
|
+
updatedAt: 0,
|
|
273
|
+
};
|
|
274
|
+
const childBUsage: SessionUsageEntry = {
|
|
275
|
+
contextUsed: 0,
|
|
276
|
+
contextLimit: 0,
|
|
277
|
+
contextPct: 0,
|
|
278
|
+
input: 500,
|
|
279
|
+
output: 120,
|
|
280
|
+
reasoning: 30,
|
|
281
|
+
cacheRead: 50,
|
|
282
|
+
cacheWrite: 10,
|
|
283
|
+
updatedAt: 0,
|
|
284
|
+
};
|
|
285
|
+
const tree = {
|
|
286
|
+
orch: {
|
|
287
|
+
title: 'orch',
|
|
288
|
+
agent: 'orchestrator',
|
|
289
|
+
model: 'openai/gpt-5',
|
|
290
|
+
childIds: [],
|
|
291
|
+
status: 'busy',
|
|
292
|
+
createdAt: 0,
|
|
293
|
+
usage: orchUsage,
|
|
294
|
+
},
|
|
295
|
+
childA: {
|
|
296
|
+
title: 'childA',
|
|
297
|
+
agent: 'explorer',
|
|
298
|
+
model: 'openai/gpt-5-mini',
|
|
299
|
+
parentId: 'orch',
|
|
300
|
+
childIds: [],
|
|
301
|
+
status: 'busy',
|
|
302
|
+
createdAt: 0,
|
|
303
|
+
usage: childAUsage,
|
|
304
|
+
},
|
|
305
|
+
childB: {
|
|
306
|
+
title: 'childB',
|
|
307
|
+
agent: 'oracle',
|
|
308
|
+
model: 'openai/gpt-5',
|
|
309
|
+
parentId: 'childA',
|
|
310
|
+
childIds: [],
|
|
311
|
+
status: 'busy',
|
|
312
|
+
createdAt: 0,
|
|
313
|
+
usage: childBUsage,
|
|
314
|
+
},
|
|
315
|
+
};
|
|
316
|
+
const snapshot = createSnapshot();
|
|
317
|
+
snapshot.sessions.orch = bundleFixture('orch', {
|
|
318
|
+
tree,
|
|
319
|
+
orchestrationSigmaAccum: {
|
|
320
|
+
contextUsed: 15_200,
|
|
321
|
+
input: 12_000,
|
|
322
|
+
output: 2_000,
|
|
323
|
+
cacheRead: 800,
|
|
324
|
+
cacheWrite: 120,
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
expect(aggregateOrchestrationUsage(snapshot, 'orch')).toEqual({
|
|
329
|
+
inputTotal: 12_000,
|
|
330
|
+
outputTotal: 2_000,
|
|
331
|
+
cacheRead: 800,
|
|
332
|
+
cacheWrite: 120,
|
|
333
|
+
contextUsed: 15_200,
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
});
|