claude-code-session-manager 0.58.0 → 0.60.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 +2 -2
- package/dist/assets/{TiptapBody-BEBLdJl_.js → TiptapBody-BtVPGBaq.js} +1 -1
- package/dist/assets/{index-DwUffaDq.css → index-CPMP2XZ_.css} +1 -1
- package/dist/assets/{index-DEQzGYa6.js → index-DtNip-Zx.js} +1076 -1081
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/src/main/__tests__/classifyTranscriptLine.test.cjs +128 -17
- package/src/main/__tests__/epicContextDigest.test.cjs +41 -1
- package/src/main/__tests__/epicValidationHook.test.cjs +291 -0
- package/src/main/__tests__/prdMigration.test.cjs +160 -0
- package/src/main/__tests__/projectPages.test.cjs +151 -0
- package/src/main/__tests__/promptSessionEvents.test.cjs +74 -0
- package/src/main/__tests__/scheduler-effective-concurrency.test.cjs +32 -12
- package/src/main/__tests__/scheduler-epic-digest.test.cjs +9 -2
- package/src/main/__tests__/scheduler-heal-refusal.test.cjs +61 -0
- package/src/main/__tests__/scheduler-notify-originating-tab.test.cjs +74 -0
- package/src/main/__tests__/transcripts-doFlush-array.test.cjs +118 -0
- package/src/main/__tests__/transcripts-paged-reads.test.cjs +233 -0
- package/src/main/__tests__/uniquePrdNumbers.test.cjs +7 -2
- package/src/main/health.cjs +5 -1
- package/src/main/index.cjs +1 -1
- package/src/main/ipcSchemas.cjs +26 -3
- package/src/main/lib/__tests__/schedulerBatchDepends.test.cjs +130 -0
- package/src/main/lib/classifyTranscriptLine.cjs +131 -48
- package/src/main/lib/epicContextDigest.cjs +36 -0
- package/src/main/lib/epicMint.cjs +6 -1
- package/src/main/lib/epicValidationHook.cjs +192 -0
- package/src/main/lib/prdMigration.cjs +76 -5
- package/src/main/lib/promptSessionSchema.cjs +16 -0
- package/src/main/lib/promptSessionsCreateEpic.cjs +5 -3
- package/src/main/lib/schedulerBatch.cjs +70 -111
- package/src/main/lib/schedulerConfig.cjs +0 -1
- package/src/main/otel.cjs +3 -1
- package/src/main/projectPages.cjs +60 -14
- package/src/main/promptSessionEvents.cjs +16 -1
- package/src/main/scheduler.cjs +228 -49
- package/src/main/templates/project-pages-default-home.html +123 -0
- package/src/main/transcripts.cjs +191 -32
- package/src/main/webRemote.cjs +8 -7
- package/src/preload/api.d.ts +75 -9
- package/src/preload/index.cjs +3 -0
package/dist/index.html
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
8
8
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
9
9
|
<link href="https://fonts.googleapis.com/css2?family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,500;0,6..72,600;0,6..72,700;1,6..72,400&family=Geist:wght@300;400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap" rel="stylesheet">
|
|
10
|
-
<script type="module" crossorigin src="./assets/index-
|
|
10
|
+
<script type="module" crossorigin src="./assets/index-DtNip-Zx.js"></script>
|
|
11
11
|
<link rel="modulepreload" crossorigin href="./assets/monaco-editor-BW5C4Iv1.js">
|
|
12
12
|
<link rel="stylesheet" crossorigin href="./assets/monaco-editor-BTnBOi8r.css">
|
|
13
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
13
|
+
<link rel="stylesheet" crossorigin href="./assets/index-CPMP2XZ_.css">
|
|
14
14
|
</head>
|
|
15
15
|
<body class="bg-bg text-fg font-sans antialiased">
|
|
16
16
|
<div id="root"></div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-code-session-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.60.0",
|
|
4
4
|
"description": "Local cockpit for the Claude Code CLI — multi-tab terminal, full config surface, scheduler, voice dictation, and live observability.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/main/index.cjs",
|
|
@@ -8,21 +8,29 @@
|
|
|
8
8
|
|
|
9
9
|
import { test, expect } from 'vitest';
|
|
10
10
|
|
|
11
|
-
const {
|
|
11
|
+
const {
|
|
12
|
+
classifyLine,
|
|
13
|
+
trimContentArray,
|
|
14
|
+
makeRaw,
|
|
15
|
+
buildPreviewText,
|
|
16
|
+
MAX_RAW_STR,
|
|
17
|
+
PREVIEW_CHARS,
|
|
18
|
+
EXEMPT_TYPES,
|
|
19
|
+
} = require('../lib/classifyTranscriptLine.cjs');
|
|
12
20
|
|
|
13
|
-
test('classifyLine returns
|
|
14
|
-
expect(classifyLine(null)).
|
|
15
|
-
expect(classifyLine('not an object')).
|
|
21
|
+
test('classifyLine returns [] for non-object input', () => {
|
|
22
|
+
expect(classifyLine(null)).toEqual([]);
|
|
23
|
+
expect(classifyLine('not an object')).toEqual([]);
|
|
16
24
|
});
|
|
17
25
|
|
|
18
26
|
test('classifyLine tags usage events', () => {
|
|
19
|
-
const ev = classifyLine({ usage: { input_tokens: 10, output_tokens: 5 } });
|
|
27
|
+
const [ev] = classifyLine({ usage: { input_tokens: 10, output_tokens: 5 } });
|
|
20
28
|
expect(ev.kind).toBe('usage');
|
|
21
29
|
expect(ev.data).toEqual({ input_tokens: 10, output_tokens: 5 });
|
|
22
30
|
});
|
|
23
31
|
|
|
24
32
|
test('classifyLine tags TodoWrite tool_use as todo_write', () => {
|
|
25
|
-
const ev = classifyLine({
|
|
33
|
+
const [ev] = classifyLine({
|
|
26
34
|
message: { content: [{ type: 'tool_use', name: 'TodoWrite', input: { todos: [{ content: 'x' }] } }] },
|
|
27
35
|
});
|
|
28
36
|
expect(ev.kind).toBe('todo_write');
|
|
@@ -30,14 +38,14 @@ test('classifyLine tags TodoWrite tool_use as todo_write', () => {
|
|
|
30
38
|
});
|
|
31
39
|
|
|
32
40
|
test('classifyLine tags ExitPlanMode as plan', () => {
|
|
33
|
-
const ev = classifyLine({
|
|
41
|
+
const [ev] = classifyLine({
|
|
34
42
|
message: { content: [{ type: 'tool_use', name: 'ExitPlanMode', input: { plan: 'do things' } }] },
|
|
35
43
|
});
|
|
36
44
|
expect(ev.kind).toBe('plan');
|
|
37
45
|
});
|
|
38
46
|
|
|
39
47
|
test('classifyLine tags Agent/Task tool_use as agent_spawn with toolUseId', () => {
|
|
40
|
-
const ev = classifyLine({
|
|
48
|
+
const [ev] = classifyLine({
|
|
41
49
|
message: { content: [{ type: 'tool_use', name: 'Agent', id: 'tool-1', input: { description: 'do work' } }] },
|
|
42
50
|
});
|
|
43
51
|
expect(ev.kind).toBe('agent_spawn');
|
|
@@ -45,7 +53,7 @@ test('classifyLine tags Agent/Task tool_use as agent_spawn with toolUseId', () =
|
|
|
45
53
|
});
|
|
46
54
|
|
|
47
55
|
test('classifyLine tags generic tool_use blocks', () => {
|
|
48
|
-
const ev = classifyLine({
|
|
56
|
+
const [ev] = classifyLine({
|
|
49
57
|
message: { content: [{ type: 'tool_use', name: 'Bash', id: 'tool-2', input: { command: 'ls' } }] },
|
|
50
58
|
});
|
|
51
59
|
expect(ev.kind).toBe('tool_use');
|
|
@@ -53,18 +61,62 @@ test('classifyLine tags generic tool_use blocks', () => {
|
|
|
53
61
|
});
|
|
54
62
|
|
|
55
63
|
test('classifyLine tags tool_result blocks with toolUseId', () => {
|
|
56
|
-
const ev = classifyLine({
|
|
64
|
+
const [ev] = classifyLine({
|
|
57
65
|
message: { content: [{ type: 'tool_result', tool_use_id: 'tool-1' }] },
|
|
58
66
|
});
|
|
59
67
|
expect(ev.kind).toBe('tool_result');
|
|
60
68
|
expect(ev.data).toEqual({ toolUseId: 'tool-1' });
|
|
61
69
|
});
|
|
62
70
|
|
|
63
|
-
test('classifyLine falls back to message kind', () => {
|
|
64
|
-
const ev = classifyLine({ type: 'assistant', message: { content: 'hello' } });
|
|
71
|
+
test('classifyLine falls back to message kind for non-array content', () => {
|
|
72
|
+
const [ev] = classifyLine({ type: 'assistant', message: { content: 'hello' } });
|
|
65
73
|
expect(ev.kind).toBe('assistant');
|
|
66
74
|
});
|
|
67
75
|
|
|
76
|
+
test('CORE: a content array of [text, tool_use, tool_use] emits exactly 3 events, not 1', () => {
|
|
77
|
+
const events = classifyLine({
|
|
78
|
+
type: 'assistant',
|
|
79
|
+
message: {
|
|
80
|
+
content: [
|
|
81
|
+
{ type: 'text', text: 'doing two things' },
|
|
82
|
+
{ type: 'tool_use', name: 'Bash', id: 'tu-1', input: { command: 'ls' } },
|
|
83
|
+
{ type: 'tool_use', name: 'Bash', id: 'tu-2', input: { command: 'pwd' } },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
expect(events).toHaveLength(3);
|
|
88
|
+
expect(events[0].kind).toBe('assistant'); // text block inherits the message's own type
|
|
89
|
+
expect(events[0].data).toBe('doing two things');
|
|
90
|
+
expect(events[1].kind).toBe('tool_use');
|
|
91
|
+
expect(events[1].data.id).toBe('tu-1');
|
|
92
|
+
expect(events[2].kind).toBe('tool_use');
|
|
93
|
+
expect(events[2].data.id).toBe('tu-2');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('CORE: a message carrying both usage AND non-empty content emits the usage event AND the content event(s)', () => {
|
|
97
|
+
const events = classifyLine({
|
|
98
|
+
type: 'assistant',
|
|
99
|
+
usage: { input_tokens: 100, output_tokens: 40 },
|
|
100
|
+
message: { content: [{ type: 'text', text: 'hello' }] },
|
|
101
|
+
});
|
|
102
|
+
expect(events).toHaveLength(2);
|
|
103
|
+
expect(events.map((e) => e.kind).sort()).toEqual(['assistant', 'usage']);
|
|
104
|
+
const usageEv = events.find((e) => e.kind === 'usage');
|
|
105
|
+
expect(usageEv.data).toEqual({ input_tokens: 100, output_tokens: 40 });
|
|
106
|
+
const textEv = events.find((e) => e.kind === 'assistant');
|
|
107
|
+
expect(textEv.data).toBe('hello');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('unknown/future content block types are surfaced, not dropped', () => {
|
|
111
|
+
const events = classifyLine({
|
|
112
|
+
type: 'assistant',
|
|
113
|
+
message: { content: [{ type: 'server_tool_use', id: 'x', input: {} }] },
|
|
114
|
+
});
|
|
115
|
+
expect(events).toHaveLength(1);
|
|
116
|
+
expect(events[0].kind).toBe('content_server_tool_use');
|
|
117
|
+
expect(events[0].data).toEqual({ type: 'server_tool_use', id: 'x', input: {} });
|
|
118
|
+
});
|
|
119
|
+
|
|
68
120
|
test('trimContentArray passes through non-array input', () => {
|
|
69
121
|
expect(trimContentArray('not-an-array')).toBe('not-an-array');
|
|
70
122
|
});
|
|
@@ -76,15 +128,74 @@ test('trimContentArray truncates long text fields past MAX_RAW_STR', () => {
|
|
|
76
128
|
expect(block.text.endsWith('…')).toBe(true);
|
|
77
129
|
});
|
|
78
130
|
|
|
79
|
-
test('trimContentArray
|
|
80
|
-
expect(EXEMPT_TYPES.
|
|
81
|
-
expect(EXEMPT_TYPES.has('tool_use')).toBe(true);
|
|
131
|
+
test('trimContentArray now trims tool_use/tool_result blocks too (EXEMPT_TYPES is empty — orchestrator.ts/race.ts, the sole prior consumers, were deleted 2026-07-30)', () => {
|
|
132
|
+
expect(EXEMPT_TYPES.size).toBe(0);
|
|
82
133
|
const longText = 'a'.repeat(MAX_RAW_STR + 100);
|
|
83
134
|
const [block] = trimContentArray([{ type: 'tool_use', text: longText }]);
|
|
84
|
-
expect(block.text.length).toBe(
|
|
135
|
+
expect(block.text.length).toBe(MAX_RAW_STR + 1);
|
|
136
|
+
expect(block.text.endsWith('…')).toBe(true);
|
|
85
137
|
});
|
|
86
138
|
|
|
87
|
-
test('makeRaw builds
|
|
139
|
+
test('makeRaw builds a projection from message content', () => {
|
|
88
140
|
const raw = makeRaw({ message: { content: [{ type: 'text', text: 'hi' }] } });
|
|
89
141
|
expect(raw.message.content).toEqual([{ type: 'text', text: 'hi' }]);
|
|
90
142
|
});
|
|
143
|
+
|
|
144
|
+
test('CORE: makeRaw preserves every top-level field on the line, not just message.content', () => {
|
|
145
|
+
const line = {
|
|
146
|
+
type: 'assistant',
|
|
147
|
+
message: { content: [{ type: 'text', text: 'hi' }] },
|
|
148
|
+
attributionSkill: 'develop',
|
|
149
|
+
attributionPlugin: 'session-manager-dev',
|
|
150
|
+
attributionMcpServer: 'some-server',
|
|
151
|
+
attributionMcpTool: 'some_tool',
|
|
152
|
+
effort: 'high',
|
|
153
|
+
gitBranch: 'main',
|
|
154
|
+
isSidechain: false,
|
|
155
|
+
isMeta: true,
|
|
156
|
+
requestId: 'req-123',
|
|
157
|
+
isApiErrorMessage: false,
|
|
158
|
+
interruptedByShutdown: false,
|
|
159
|
+
permissionMode: 'default',
|
|
160
|
+
promptSource: 'user',
|
|
161
|
+
toolUseResult: { ok: true },
|
|
162
|
+
};
|
|
163
|
+
const raw = makeRaw(line);
|
|
164
|
+
for (const key of [
|
|
165
|
+
'attributionSkill',
|
|
166
|
+
'attributionPlugin',
|
|
167
|
+
'attributionMcpServer',
|
|
168
|
+
'attributionMcpTool',
|
|
169
|
+
'effort',
|
|
170
|
+
'gitBranch',
|
|
171
|
+
'isSidechain',
|
|
172
|
+
'isMeta',
|
|
173
|
+
'requestId',
|
|
174
|
+
'isApiErrorMessage',
|
|
175
|
+
'interruptedByShutdown',
|
|
176
|
+
'permissionMode',
|
|
177
|
+
'promptSource',
|
|
178
|
+
'toolUseResult',
|
|
179
|
+
]) {
|
|
180
|
+
expect(raw[key]).toEqual(line[key]);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('CORE: every event carries a bounded previewText and, when a ref is passed, the ref survives untouched', () => {
|
|
185
|
+
const ref = { filePath: '/tmp/fake.jsonl', byteOffset: 128, byteLength: 64 };
|
|
186
|
+
const [ev] = classifyLine({ type: 'user', message: { content: 'a'.repeat(PREVIEW_CHARS + 500) } }, ref);
|
|
187
|
+
expect(ev.ref).toEqual(ref);
|
|
188
|
+
expect(ev.previewText.length).toBeLessThanOrEqual(PREVIEW_CHARS + 1);
|
|
189
|
+
expect(ev.previewText.endsWith('…')).toBe(true);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test('classifyLine omits ref (null) when the caller has no file context', () => {
|
|
193
|
+
const [ev] = classifyLine({ usage: { input_tokens: 1, output_tokens: 1 } });
|
|
194
|
+
expect(ev.ref).toBeNull();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test('buildPreviewText caps at PREVIEW_CHARS', () => {
|
|
198
|
+
const s = buildPreviewText('x'.repeat(PREVIEW_CHARS + 50));
|
|
199
|
+
expect(s.length).toBe(PREVIEW_CHARS + 1);
|
|
200
|
+
expect(s.endsWith('…')).toBe(true);
|
|
201
|
+
});
|
|
@@ -13,7 +13,7 @@ import { test, expect, afterEach } from 'vitest';
|
|
|
13
13
|
const fsp = require('node:fs/promises');
|
|
14
14
|
const os = require('node:os');
|
|
15
15
|
const path = require('node:path');
|
|
16
|
-
const { buildContextDigest } = require('../lib/epicContextDigest.cjs');
|
|
16
|
+
const { buildContextDigest, composeExecutorPrompt } = require('../lib/epicContextDigest.cjs');
|
|
17
17
|
const { ensureEpic, MINT_AUTHORITY_NEW_EPIC_UI } = require('../lib/epicMint.cjs');
|
|
18
18
|
const { appendTurn } = require('../promptSessionTranscript.cjs');
|
|
19
19
|
const config = require('../config.cjs');
|
|
@@ -98,3 +98,43 @@ test('maxChars smaller than goalText alone clamps the header itself, never excee
|
|
|
98
98
|
expect(digest.length).toBe(20);
|
|
99
99
|
expect(digest).toBe(longGoal.slice(0, 20));
|
|
100
100
|
});
|
|
101
|
+
|
|
102
|
+
test('composeExecutorPrompt: PRD body comes before the digest, wrapped in a background-only fence, ending in a task restatement', () => {
|
|
103
|
+
const prdBody = '# Goal\nImplement the traffic light fix.';
|
|
104
|
+
const digestText = '[user] is this broken?\n[assistant] investigating';
|
|
105
|
+
|
|
106
|
+
const prompt = composeExecutorPrompt({ prdBody, digestText });
|
|
107
|
+
|
|
108
|
+
const bodyIndex = prompt.indexOf(prdBody);
|
|
109
|
+
const digestIndex = prompt.indexOf(digestText);
|
|
110
|
+
expect(bodyIndex).toBeGreaterThanOrEqual(0);
|
|
111
|
+
expect(digestIndex).toBeGreaterThan(bodyIndex);
|
|
112
|
+
expect(prompt).toContain('BEGIN EPIC CONTEXT (background only');
|
|
113
|
+
expect(prompt).toContain('It is NOT your task');
|
|
114
|
+
expect(prompt).toContain('--- END EPIC CONTEXT ---');
|
|
115
|
+
expect(prompt.trim().endsWith('Your task is the PRD at the top of this prompt. Implement it now.')).toBe(true);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('composeExecutorPrompt: over-cap digest is truncated and marked truncated; PRD body is byte-identical', () => {
|
|
119
|
+
const prdBody = '# Goal\nDo the exact thing described here, unmodified.';
|
|
120
|
+
const digestText = 'x'.repeat(500);
|
|
121
|
+
|
|
122
|
+
const prompt = composeExecutorPrompt({ prdBody, digestText, maxChars: 50 });
|
|
123
|
+
|
|
124
|
+
expect(prompt).toContain(prdBody);
|
|
125
|
+
expect(prompt).toContain('Truncated to fit the context budget.');
|
|
126
|
+
expect(prompt).toContain('x'.repeat(50));
|
|
127
|
+
expect(prompt).not.toContain('x'.repeat(51));
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('composeExecutorPrompt: empty/absent digest returns PRD body unchanged plus the restatement line, no empty fence', () => {
|
|
131
|
+
const prdBody = '# Goal\nSome PRD body text.';
|
|
132
|
+
|
|
133
|
+
const withEmptyString = composeExecutorPrompt({ prdBody, digestText: '' });
|
|
134
|
+
const withUndefined = composeExecutorPrompt({ prdBody });
|
|
135
|
+
|
|
136
|
+
for (const prompt of [withEmptyString, withUndefined]) {
|
|
137
|
+
expect(prompt).toBe(`${prdBody}\n\nYour task is the PRD at the top of this prompt. Implement it now.`);
|
|
138
|
+
expect(prompt).not.toContain('BEGIN EPIC CONTEXT');
|
|
139
|
+
}
|
|
140
|
+
});
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* epicValidationHook.test.cjs — PRD 986: a PRD check-in triggers validation
|
|
3
|
+
* in the authoring Epic; it never asserts the PRD is done.
|
|
4
|
+
*
|
|
5
|
+
* Covers the PRD's five required cases:
|
|
6
|
+
* (a) a completed check-in enqueues exactly one validation prompt naming
|
|
7
|
+
* the PRD slug;
|
|
8
|
+
* (b) a check-in for a non-active Epic enqueues nothing;
|
|
9
|
+
* (c) a second check-in for the same (epicId, prdSlug) enqueues nothing;
|
|
10
|
+
* (d) the enqueued prompt contains the PRD's absolute path and the
|
|
11
|
+
* VERIFIED/REFUTED instruction (plus the not-evidence warning and the
|
|
12
|
+
* git diff --stat / empty-diff-is-REFUTED rule);
|
|
13
|
+
* (e) LOOP GUARD — an appended event that is a validation result never
|
|
14
|
+
* enqueues a further prompt.
|
|
15
|
+
* Plus: the SM_EPIC_VALIDATION_DISABLE kill-switch, the born-'unvalidated'
|
|
16
|
+
* stamp, and end-to-end wiring through notifyOriginatingTab.
|
|
17
|
+
*
|
|
18
|
+
* Run: timeout 300 npx vitest run src/main/__tests__/epicValidationHook.test.cjs
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
'use strict';
|
|
22
|
+
|
|
23
|
+
import { test, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
24
|
+
const {
|
|
25
|
+
maybeEnqueueValidationPrompt,
|
|
26
|
+
buildValidationPrompt,
|
|
27
|
+
__resetForTests,
|
|
28
|
+
} = require('../lib/epicValidationHook.cjs');
|
|
29
|
+
const { notifyOriginatingTab } = require('../scheduler.cjs');
|
|
30
|
+
|
|
31
|
+
const EPIC = 'epic-986';
|
|
32
|
+
const SLUG = '986-example-prd';
|
|
33
|
+
const PRD_PATH = '/abs/path/to/session-manager-operations/scheduler/epics/epic-986/prds-archived/986-example-prd.md';
|
|
34
|
+
|
|
35
|
+
/** An active-index snapshot AS IT LOOKS RIGHT AFTER the scheduler's check-in
|
|
36
|
+
* append: exactly one validation-stamped response event for this prdSlug. */
|
|
37
|
+
function indexAfterCheckin({ status = 'active', extraEvents = [] } = {}) {
|
|
38
|
+
return {
|
|
39
|
+
sessions: { [EPIC]: { id: EPIC, status } },
|
|
40
|
+
events: {
|
|
41
|
+
[EPIC]: [
|
|
42
|
+
{ id: 'e1', promptSessionId: EPIC, kind: 'prompt', causedByEventId: null, at: '2026-08-02T00:00:00Z', text: 'goal' },
|
|
43
|
+
{
|
|
44
|
+
id: 'e2', promptSessionId: EPIC, kind: 'response', causedByEventId: 'e1',
|
|
45
|
+
at: '2026-08-02T01:00:00Z', text: `PRD ${SLUG} finished: completed.`,
|
|
46
|
+
prdSlug: SLUG, outcome: 'completed', validation: 'unvalidated',
|
|
47
|
+
},
|
|
48
|
+
...extraEvents,
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function callArgs(overrides = {}) {
|
|
55
|
+
return {
|
|
56
|
+
cwd: '/some/cwd',
|
|
57
|
+
epicId: EPIC,
|
|
58
|
+
prdSlug: SLUG,
|
|
59
|
+
prdPath: PRD_PATH,
|
|
60
|
+
outcome: 'completed',
|
|
61
|
+
eventValidation: 'unvalidated',
|
|
62
|
+
...overrides,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
__resetForTests();
|
|
68
|
+
delete process.env.SM_EPIC_VALIDATION_DISABLE;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
afterEach(() => {
|
|
72
|
+
delete process.env.SM_EPIC_VALIDATION_DISABLE;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// ─── (a) completed check-in → exactly one prompt naming the slug ────────────
|
|
76
|
+
|
|
77
|
+
test('(a) a completed check-in enqueues exactly one validation prompt naming the PRD slug', () => {
|
|
78
|
+
const sendPrompt = vi.fn();
|
|
79
|
+
const readActiveIndex = vi.fn(() => indexAfterCheckin());
|
|
80
|
+
|
|
81
|
+
const res = maybeEnqueueValidationPrompt(callArgs(), { sendPrompt, readActiveIndex });
|
|
82
|
+
|
|
83
|
+
expect(res.enqueued).toBe(true);
|
|
84
|
+
expect(sendPrompt).toHaveBeenCalledTimes(1);
|
|
85
|
+
expect(sendPrompt).toHaveBeenCalledWith(EPIC, expect.stringContaining(SLUG));
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// ─── (b) non-active Epic → nothing ──────────────────────────────────────────
|
|
89
|
+
|
|
90
|
+
test('(b) a check-in for a completed (non-active) Epic enqueues nothing', () => {
|
|
91
|
+
const sendPrompt = vi.fn();
|
|
92
|
+
const readActiveIndex = vi.fn(() => indexAfterCheckin({ status: 'completed' }));
|
|
93
|
+
|
|
94
|
+
const res = maybeEnqueueValidationPrompt(callArgs(), { sendPrompt, readActiveIndex });
|
|
95
|
+
|
|
96
|
+
expect(res).toEqual({ enqueued: false, reason: 'epic-not-active' });
|
|
97
|
+
expect(sendPrompt).not.toHaveBeenCalled();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('(b) an unknown Epic (no active-index entry) enqueues nothing — join-only, never creates an Epic', () => {
|
|
101
|
+
const sendPrompt = vi.fn();
|
|
102
|
+
const readActiveIndex = vi.fn(() => ({ sessions: {}, events: {} }));
|
|
103
|
+
|
|
104
|
+
const res = maybeEnqueueValidationPrompt(callArgs(), { sendPrompt, readActiveIndex });
|
|
105
|
+
|
|
106
|
+
expect(res).toEqual({ enqueued: false, reason: 'epic-not-active' });
|
|
107
|
+
expect(sendPrompt).not.toHaveBeenCalled();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// ─── (c) second check-in for the same (epicId, prdSlug) → nothing ───────────
|
|
111
|
+
|
|
112
|
+
test('(c) a second check-in for the same (epicId, prdSlug) enqueues nothing (in-memory guard)', () => {
|
|
113
|
+
const sendPrompt = vi.fn();
|
|
114
|
+
const readActiveIndex = vi.fn(() => indexAfterCheckin());
|
|
115
|
+
|
|
116
|
+
expect(maybeEnqueueValidationPrompt(callArgs(), { sendPrompt, readActiveIndex }).enqueued).toBe(true);
|
|
117
|
+
const second = maybeEnqueueValidationPrompt(callArgs(), { sendPrompt, readActiveIndex });
|
|
118
|
+
|
|
119
|
+
expect(second).toEqual({ enqueued: false, reason: 'already-fired' });
|
|
120
|
+
expect(sendPrompt).toHaveBeenCalledTimes(1);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('(c) durable guard: two validation-stamped check-in events already on the chain skip even after a process restart emptied the in-memory set', () => {
|
|
124
|
+
const sendPrompt = vi.fn();
|
|
125
|
+
// Chain carries the current check-in PLUS an earlier one for the same slug
|
|
126
|
+
// (a re-notify after restart appends a second response event).
|
|
127
|
+
const readActiveIndex = vi.fn(() => indexAfterCheckin({
|
|
128
|
+
extraEvents: [{
|
|
129
|
+
id: 'e3', promptSessionId: EPIC, kind: 'response', causedByEventId: 'e2',
|
|
130
|
+
at: '2026-08-02T02:00:00Z', text: `PRD ${SLUG} finished: completed.`,
|
|
131
|
+
prdSlug: SLUG, outcome: 'completed', validation: 'unvalidated',
|
|
132
|
+
}],
|
|
133
|
+
}));
|
|
134
|
+
|
|
135
|
+
__resetForTests(); // simulate the restart: in-memory set is empty
|
|
136
|
+
const res = maybeEnqueueValidationPrompt(callArgs(), { sendPrompt, readActiveIndex });
|
|
137
|
+
|
|
138
|
+
expect(res).toEqual({ enqueued: false, reason: 'already-fired-durable' });
|
|
139
|
+
expect(sendPrompt).not.toHaveBeenCalled();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test('(c) a different PRD slug for the same Epic still fires — the guard is per (epicId, prdSlug) pair, not per Epic', () => {
|
|
143
|
+
const sendPrompt = vi.fn();
|
|
144
|
+
const readActiveIndex = vi.fn(() => indexAfterCheckin());
|
|
145
|
+
|
|
146
|
+
expect(maybeEnqueueValidationPrompt(callArgs(), { sendPrompt, readActiveIndex }).enqueued).toBe(true);
|
|
147
|
+
const other = maybeEnqueueValidationPrompt(
|
|
148
|
+
callArgs({ prdSlug: '987-other-prd', prdPath: '/abs/987-other-prd.md' }),
|
|
149
|
+
{ sendPrompt, readActiveIndex: vi.fn(() => ({ sessions: { [EPIC]: { id: EPIC, status: 'active' } }, events: { [EPIC]: [{ id: 'x', kind: 'response', prdSlug: '987-other-prd', validation: 'unvalidated' }] } })) },
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
expect(other.enqueued).toBe(true);
|
|
153
|
+
expect(sendPrompt).toHaveBeenCalledTimes(2);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// ─── (d) prompt content ─────────────────────────────────────────────────────
|
|
157
|
+
|
|
158
|
+
test('(d) the enqueued prompt contains the PRD absolute path, the unverified-claim label, and the VERIFIED/REFUTED instruction', () => {
|
|
159
|
+
const sendPrompt = vi.fn();
|
|
160
|
+
const readActiveIndex = vi.fn(() => indexAfterCheckin());
|
|
161
|
+
|
|
162
|
+
maybeEnqueueValidationPrompt(callArgs(), { sendPrompt, readActiveIndex });
|
|
163
|
+
|
|
164
|
+
const prompt = sendPrompt.mock.calls[0][1];
|
|
165
|
+
expect(prompt).toContain(PRD_PATH);
|
|
166
|
+
expect(prompt).toContain(SLUG);
|
|
167
|
+
expect(prompt).toContain('UNVERIFIED CLAIM');
|
|
168
|
+
expect(prompt).toContain('"completed"');
|
|
169
|
+
expect(prompt).toContain('VERIFIED or REFUTED');
|
|
170
|
+
expect(prompt).toMatch(/file:line|command output/);
|
|
171
|
+
// AC #3: the not-evidence warning + the git diff --stat / empty-diff rule.
|
|
172
|
+
expect(prompt).toContain('exit code of 0');
|
|
173
|
+
expect(prompt).toContain('NOT evidence');
|
|
174
|
+
expect(prompt).toContain('git diff --stat');
|
|
175
|
+
expect(prompt).toMatch(/empty diff.*REFUTED/i);
|
|
176
|
+
// Acceptance-criteria-against-working-tree instruction.
|
|
177
|
+
expect(prompt).toMatch(/Acceptance criteria/i);
|
|
178
|
+
expect(prompt).toMatch(/working tree/i);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test('(d) buildValidationPrompt degrades gracefully when the PRD path could not be resolved', () => {
|
|
182
|
+
const prompt = buildValidationPrompt({ prdSlug: SLUG, prdPath: null, outcome: 'failed' });
|
|
183
|
+
expect(prompt).toContain(SLUG);
|
|
184
|
+
expect(prompt).toContain('path could not be resolved');
|
|
185
|
+
expect(prompt).toContain('"failed"');
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// ─── (e) LOOP GUARD ─────────────────────────────────────────────────────────
|
|
189
|
+
|
|
190
|
+
test('(e) LOOP GUARD: an appended event that is a validation result never enqueues a further prompt', () => {
|
|
191
|
+
const sendPrompt = vi.fn();
|
|
192
|
+
const readActiveIndex = vi.fn(() => indexAfterCheckin());
|
|
193
|
+
|
|
194
|
+
for (const eventValidation of ['verified', 'refuted', 'validating', undefined]) {
|
|
195
|
+
const res = maybeEnqueueValidationPrompt(callArgs({ eventValidation }), { sendPrompt, readActiveIndex });
|
|
196
|
+
expect(res).toEqual({ enqueued: false, reason: 'not-a-checkin' });
|
|
197
|
+
}
|
|
198
|
+
expect(sendPrompt).not.toHaveBeenCalled();
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// ─── kill-switch ────────────────────────────────────────────────────────────
|
|
202
|
+
|
|
203
|
+
test('SM_EPIC_VALIDATION_DISABLE=1 turns the hook off entirely', () => {
|
|
204
|
+
process.env.SM_EPIC_VALIDATION_DISABLE = '1';
|
|
205
|
+
const sendPrompt = vi.fn();
|
|
206
|
+
const readActiveIndex = vi.fn(() => indexAfterCheckin());
|
|
207
|
+
|
|
208
|
+
const res = maybeEnqueueValidationPrompt(callArgs(), { sendPrompt, readActiveIndex });
|
|
209
|
+
|
|
210
|
+
expect(res).toEqual({ enqueued: false, reason: 'disabled' });
|
|
211
|
+
expect(sendPrompt).not.toHaveBeenCalled();
|
|
212
|
+
expect(readActiveIndex).not.toHaveBeenCalled();
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// ─── never throws ───────────────────────────────────────────────────────────
|
|
216
|
+
|
|
217
|
+
test('a sendPrompt that throws is swallowed and logged, never propagated (fire-and-forget contract)', () => {
|
|
218
|
+
const sendPrompt = vi.fn(() => { throw new Error('IPC gone'); });
|
|
219
|
+
const readActiveIndex = vi.fn(() => indexAfterCheckin());
|
|
220
|
+
const log = { error: vi.fn() };
|
|
221
|
+
|
|
222
|
+
let res;
|
|
223
|
+
expect(() => {
|
|
224
|
+
res = maybeEnqueueValidationPrompt(callArgs(), { sendPrompt, readActiveIndex, log });
|
|
225
|
+
}).not.toThrow();
|
|
226
|
+
expect(res).toEqual({ enqueued: false, reason: 'error' });
|
|
227
|
+
expect(log.error).toHaveBeenCalled();
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// ─── wiring through notifyOriginatingTab ────────────────────────────────────
|
|
231
|
+
|
|
232
|
+
test('notifyOriginatingTab: a routed check-in stamps validation:unvalidated and fires the validation hook once with the Epic id + slug', async () => {
|
|
233
|
+
const sendPrompt = vi.fn();
|
|
234
|
+
const appendResponseEvent = vi.fn(async () => true);
|
|
235
|
+
const enqueueValidation = vi.fn(() => ({ enqueued: true }));
|
|
236
|
+
const parsePrdRaw = vi.fn(async () => ({ sourcePromptId: EPIC, path: PRD_PATH }));
|
|
237
|
+
const loadSessions = vi.fn(async () => ({ tabs: [] }));
|
|
238
|
+
|
|
239
|
+
await notifyOriginatingTab(
|
|
240
|
+
{ slug: SLUG, status: 'completed', cwd: '/some/cwd' },
|
|
241
|
+
{ parsePrdRaw, loadSessions, sendPrompt, appendResponseEvent, enqueueValidation },
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
expect(appendResponseEvent).toHaveBeenCalledWith(
|
|
245
|
+
'/some/cwd', EPIC, expect.stringContaining(SLUG),
|
|
246
|
+
expect.objectContaining({ prdSlug: SLUG, outcome: 'completed', validation: 'unvalidated' }),
|
|
247
|
+
);
|
|
248
|
+
expect(enqueueValidation).toHaveBeenCalledTimes(1);
|
|
249
|
+
expect(enqueueValidation).toHaveBeenCalledWith(
|
|
250
|
+
expect.objectContaining({
|
|
251
|
+
cwd: '/some/cwd',
|
|
252
|
+
epicId: EPIC,
|
|
253
|
+
prdSlug: SLUG,
|
|
254
|
+
outcome: 'completed',
|
|
255
|
+
eventValidation: 'unvalidated',
|
|
256
|
+
}),
|
|
257
|
+
expect.objectContaining({ sendPrompt }),
|
|
258
|
+
);
|
|
259
|
+
// The check-in routed into the Epic chain — no tab-prompt fallback fires.
|
|
260
|
+
expect(sendPrompt).not.toHaveBeenCalled();
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test('notifyOriginatingTab: a REFUSED append (unknown/completed Epic) never fires the validation hook', async () => {
|
|
264
|
+
const sendPrompt = vi.fn();
|
|
265
|
+
const appendResponseEvent = vi.fn(async () => false);
|
|
266
|
+
const enqueueValidation = vi.fn();
|
|
267
|
+
const parsePrdRaw = vi.fn(async () => ({ sourcePromptId: EPIC, sourceTabId: 'tab-x' }));
|
|
268
|
+
const loadSessions = vi.fn(async () => ({ tabs: [] }));
|
|
269
|
+
|
|
270
|
+
await notifyOriginatingTab(
|
|
271
|
+
{ slug: SLUG, status: 'completed', cwd: '/some/cwd' },
|
|
272
|
+
{ parsePrdRaw, loadSessions, sendPrompt, appendResponseEvent, enqueueValidation },
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
expect(enqueueValidation).not.toHaveBeenCalled();
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
test('notifyOriginatingTab: a validation hook that throws never blocks the notification path', async () => {
|
|
279
|
+
const sendPrompt = vi.fn();
|
|
280
|
+
const appendResponseEvent = vi.fn(async () => true);
|
|
281
|
+
const enqueueValidation = vi.fn(() => { throw new Error('boom'); });
|
|
282
|
+
const parsePrdRaw = vi.fn(async () => ({ sourcePromptId: EPIC, path: PRD_PATH }));
|
|
283
|
+
const loadSessions = vi.fn(async () => ({ tabs: [] }));
|
|
284
|
+
|
|
285
|
+
await expect(
|
|
286
|
+
notifyOriginatingTab(
|
|
287
|
+
{ slug: SLUG, status: 'failed', cwd: '/some/cwd' },
|
|
288
|
+
{ parsePrdRaw, loadSessions, sendPrompt, appendResponseEvent, enqueueValidation },
|
|
289
|
+
),
|
|
290
|
+
).resolves.not.toThrow();
|
|
291
|
+
});
|