forked from github/copilot-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-chat-continuity-prompting.js
More file actions
322 lines (285 loc) · 14.1 KB
/
test-chat-continuity-prompting.js
File metadata and controls
322 lines (285 loc) · 14.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/usr/bin/env node
const assert = require('assert');
const fs = require('fs');
const os = require('os');
const path = require('path');
const { createMessageBuilder } = require(path.join(__dirname, '..', 'src', 'main', 'ai-service', 'message-builder.js'));
const {
createSessionIntentStateStore,
formatChatContinuityContext
} = require(path.join(__dirname, '..', 'src', 'main', 'session-intent-state.js'));
const PAPER_AWARE_CONTINUITY_FIXTURES = JSON.parse(
fs.readFileSync(path.join(__dirname, 'fixtures', 'tradingview', 'paper-aware-continuity.json'), 'utf8')
);
async function test(name, fn) {
try {
await fn();
console.log(`PASS ${name}`);
} catch (error) {
console.error(`FAIL ${name}`);
console.error(error.stack || error.message);
process.exitCode = 1;
}
}
async function buildContinuitySystemMessage(chatContinuityContext) {
const builder = createMessageBuilder({
getBrowserSessionState: () => ({ lastUpdated: null }),
getCurrentProvider: () => 'copilot',
getForegroundWindowInfo: async () => null,
getInspectService: () => ({ isInspectModeActive: () => false }),
getLatestVisualContext: () => null,
getPreferencesSystemContext: () => '',
getPreferencesSystemContextForApp: () => '',
getRecentConversationHistory: () => [],
getSemanticDOMContextText: () => '',
getUIWatcher: () => null,
maxHistory: 0,
systemPrompt: 'base system prompt'
});
const messages = await builder.buildMessages('continue', false, {
chatContinuityContext
});
return messages.find((entry) => entry.role === 'system' && entry.content.includes('## Recent Action Continuity'));
}
function createTempStore() {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'liku-continuity-prompt-'));
return {
tempDir,
stateFile: path.join(tempDir, 'session-intent-state.json'),
cwd: path.join(__dirname, '..')
};
}
async function main() {
await test('prompting includes verified multi-turn execution facts', async () => {
const { tempDir, stateFile, cwd } = createTempStore();
const store = createSessionIntentStateStore({ stateFile });
const state = store.recordExecutedTurn({
userMessage: 'help me make a confident synthesis of ticker LUNR in tradingview',
executionIntent: 'Inspect the active TradingView chart and gather evidence for synthesis',
committedSubgoal: 'Inspect the active TradingView chart',
actionPlan: [
{ type: 'focus_window', title: 'TradingView', processName: 'tradingview', windowHandle: 777 },
{ type: 'screenshot', scope: 'active-window' }
],
results: [
{ type: 'focus_window', success: true, message: 'focused' },
{ type: 'screenshot', success: true, message: 'captured chart' }
],
success: true,
executionResult: {
executedCount: 2,
successCount: 2,
failureCount: 0
},
observationEvidence: {
captureMode: 'window-copyfromscreen',
captureTrusted: true,
visualContextRef: 'window-copyfromscreen@123',
uiWatcherFresh: true,
uiWatcherAgeMs: 320
},
verification: {
status: 'verified',
checks: [{ name: 'target-window-focused', status: 'verified' }]
},
targetWindowHandle: 777,
windowTitle: 'TradingView - LUNR',
nextRecommendedStep: 'Summarize the visible chart state before modifying indicators.'
}, { cwd });
const context = formatChatContinuityContext(state);
const continuityMessage = await buildContinuitySystemMessage(context);
assert(continuityMessage, 'continuity section is injected');
assert(continuityMessage.content.includes('lastExecutionCounts: success=2, failed=0'));
assert(continuityMessage.content.includes('targetWindow: TradingView - LUNR [777]'));
assert(continuityMessage.content.includes('actionOutcomes: focus_window:ok | screenshot:ok'));
assert(continuityMessage.content.includes('continuationReady: yes'));
assert(continuityMessage.content.includes('nextRecommendedStep: Summarize the visible chart state before modifying indicators.'));
fs.rmSync(tempDir, { recursive: true, force: true });
});
await test('prompting surfaces paper trading continuity facts and assist-only rules', async () => {
const continuityMessage = await buildContinuitySystemMessage(
formatChatContinuityContext(PAPER_AWARE_CONTINUITY_FIXTURES.verifiedPaperAssistContinuation)
);
assert(continuityMessage, 'continuity section is injected');
assert(continuityMessage.content.includes('tradingMode: paper (high)'));
assert(continuityMessage.content.includes('tradingModeEvidence: paper trading | paper account'));
assert(continuityMessage.content.includes('continuationReady: yes'));
assert(continuityMessage.content.includes('Rule: Paper Trading was observed; continue with assist-only verification and guidance, not order execution.'));
});
await test('prompting surfaces cancelled paper continuity recovery requirements', async () => {
const continuityMessage = await buildContinuitySystemMessage(
formatChatContinuityContext(PAPER_AWARE_CONTINUITY_FIXTURES.cancelledPaperAssistContinuation)
);
assert(continuityMessage, 'continuity section is injected');
assert(continuityMessage.content.includes('tradingMode: paper (high)'));
assert(continuityMessage.content.includes('lastExecutionStatus: cancelled'));
assert(continuityMessage.content.includes('continuationReady: no'));
assert(continuityMessage.content.includes('degradedReason: The last action batch was cancelled before completion.'));
assert(continuityMessage.content.includes('nextRecommendedStep: Ask whether to retry the interrupted paper-trading setup step before continuing.'));
});
await test('prompting surfaces degraded screenshot trust for recovery-oriented continuation', async () => {
const { tempDir, stateFile, cwd } = createTempStore();
const store = createSessionIntentStateStore({ stateFile });
const state = store.recordExecutedTurn({
userMessage: 'continue',
executionIntent: 'Continue chart inspection after fallback capture.',
committedSubgoal: 'Inspect the active TradingView chart',
actionPlan: [{ type: 'screenshot', scope: 'screen' }],
results: [{ type: 'screenshot', success: true, message: 'fullscreen fallback captured' }],
success: true,
observationEvidence: {
captureMode: 'screen-copyfromscreen',
captureTrusted: false,
visualContextRef: 'screen-copyfromscreen@222',
uiWatcherFresh: false,
uiWatcherAgeMs: 2600
},
verification: {
status: 'verified',
checks: [{ name: 'target-window-focused', status: 'verified' }]
},
nextRecommendedStep: 'Recapture the target window before continuing with chart-specific claims.'
}, { cwd });
const context = formatChatContinuityContext(state);
const continuityMessage = await buildContinuitySystemMessage(context);
assert(continuityMessage, 'continuity section is injected');
assert(continuityMessage.content.includes('lastCaptureMode: screen-copyfromscreen'));
assert(continuityMessage.content.includes('lastCaptureTrusted: no'));
assert(continuityMessage.content.includes('uiWatcherFresh: no'));
assert(continuityMessage.content.includes('continuationReady: no'));
assert(continuityMessage.content.includes('degradedReason: Visual evidence fell back to full-screen capture instead of a trusted target-window capture.'));
fs.rmSync(tempDir, { recursive: true, force: true });
});
await test('prompting blocks overclaiming on contradicted and cancelled turns', async () => {
const { tempDir, stateFile, cwd } = createTempStore();
const store = createSessionIntentStateStore({ stateFile });
let state = store.recordExecutedTurn({
userMessage: 'continue',
executionIntent: 'Verify the indicator was added.',
committedSubgoal: 'Verify indicator presence on chart',
actionPlan: [{ type: 'screenshot', scope: 'active-window' }],
results: [{ type: 'screenshot', success: true, message: 'captured chart' }],
success: true,
observationEvidence: {
captureMode: 'window-copyfromscreen',
captureTrusted: true,
visualContextRef: 'window-copyfromscreen@333'
},
verification: {
status: 'contradicted',
checks: [{ name: 'indicator-present', status: 'contradicted', detail: 'indicator not visible on chart' }]
},
nextRecommendedStep: 'Retry indicator search before claiming success.'
}, { cwd });
let continuityMessage = await buildContinuitySystemMessage(formatChatContinuityContext(state));
assert(continuityMessage.content.includes('lastVerificationStatus: contradicted'));
assert(continuityMessage.content.includes('continuationReady: no'));
assert(continuityMessage.content.includes('Rule: Do not claim the requested UI change is complete unless the latest evidence verifies it.'));
state = store.recordExecutedTurn({
userMessage: 'continue',
executionIntent: 'Resume alert setup.',
committedSubgoal: 'Open and complete the alert dialog',
actionPlan: [{ type: 'key', key: 'alt+a' }],
results: [{ type: 'key', success: false, error: 'cancelled by user' }],
cancelled: true,
success: false,
verification: {
status: 'not-applicable',
checks: []
},
nextRecommendedStep: 'Ask whether to retry the interrupted step or choose a different path.'
}, { cwd });
continuityMessage = await buildContinuitySystemMessage(formatChatContinuityContext(state));
assert(continuityMessage.content.includes('lastExecutionStatus: cancelled'));
assert(continuityMessage.content.includes('continuationReady: no'));
assert(continuityMessage.content.includes('nextRecommendedStep: Ask whether to retry the interrupted step or choose a different path.'));
fs.rmSync(tempDir, { recursive: true, force: true });
});
await test('prompting scopes stale chart continuity on fresh advisory pivots', async () => {
const { tempDir, stateFile, cwd } = createTempStore();
const store = createSessionIntentStateStore({ stateFile });
const state = store.recordExecutedTurn({
userMessage: 'help me make a confident synthesis of ticker LUNR in tradingview',
executionIntent: 'Inspect the active TradingView chart and gather evidence for synthesis',
committedSubgoal: 'Inspect the active TradingView chart',
actionPlan: [
{ type: 'focus_window', title: 'TradingView', processName: 'tradingview', windowHandle: 777 },
{ type: 'screenshot', scope: 'active-window' }
],
results: [
{ type: 'focus_window', success: true, message: 'focused' },
{ type: 'screenshot', success: true, message: 'captured chart' }
],
success: true,
observationEvidence: {
captureMode: 'window-copyfromscreen',
captureTrusted: true,
visualContextRef: 'window-copyfromscreen@987'
},
verification: {
status: 'verified',
checks: [{ name: 'target-window-focused', status: 'verified' }]
},
targetWindowHandle: 777,
windowTitle: 'TradingView - LUNR',
nextRecommendedStep: 'Summarize the visible chart state before modifying indicators.'
}, { cwd });
const builder = createMessageBuilder({
getBrowserSessionState: () => ({ lastUpdated: null }),
getCurrentProvider: () => 'copilot',
getForegroundWindowInfo: async () => null,
getInspectService: () => ({ isInspectModeActive: () => false }),
getLatestVisualContext: () => null,
getPreferencesSystemContext: () => '',
getPreferencesSystemContextForApp: () => '',
getRecentConversationHistory: () => [],
getSemanticDOMContextText: () => '',
getUIWatcher: () => null,
maxHistory: 0,
systemPrompt: 'base system prompt'
});
const messages = await builder.buildMessages('what would help me have confidence about investing in LUNR? visualizations, indicators, data?', false, {
chatContinuityContext: formatChatContinuityContext(state, { userMessage: 'what would help me have confidence about investing in LUNR? visualizations, indicators, data?' })
});
const continuityMessage = messages.find((entry) => entry.role === 'system' && entry.content.includes('## Recent Action Continuity'));
assert(continuityMessage, 'continuity section is injected');
assert(continuityMessage.content.includes('continuityScope: advisory-pivot'));
assert(continuityMessage.content.includes('Rule: The current user turn is broad advisory planning, not an explicit continuation of the prior chart-analysis step.'));
assert(!continuityMessage.content.includes('lastExecutedActions:'), 'advisory pivot continuity should omit stale chart-execution detail');
assert(!continuityMessage.content.includes('lastVerificationStatus:'), 'advisory pivot continuity should omit stale chart-verification detail');
fs.rmSync(tempDir, { recursive: true, force: true });
});
await test('prompting surfaces stale-but-recoverable freshness before minimal continuation', async () => {
const continuityMessage = await buildContinuitySystemMessage(
formatChatContinuityContext({
chatContinuity: {
activeGoal: 'Produce a confident synthesis of ticker LUNR in TradingView',
currentSubgoal: 'Inspect the active TradingView chart',
continuationReady: true,
degradedReason: null,
lastTurn: {
recordedAt: new Date(Date.now() - (4 * 60 * 1000)).toISOString(),
actionSummary: 'focus_window -> screenshot',
executionStatus: 'succeeded',
verificationStatus: 'verified',
captureMode: 'window-copyfromscreen',
captureTrusted: true,
targetWindowHandle: 777,
windowTitle: 'TradingView - LUNR',
nextRecommendedStep: 'Continue from the latest chart evidence.'
}
}
})
);
assert(continuityMessage, 'continuity section is injected');
assert(continuityMessage.content.includes('continuityFreshness: stale-recoverable'));
assert(continuityMessage.content.includes('continuationReady: no'));
assert(/Stored continuity is stale/i.test(continuityMessage.content));
assert(continuityMessage.content.includes('Rule: Stored continuity is stale-but-recoverable; re-observe the target window before treating prior UI facts as current.'));
});
}
main().catch((error) => {
console.error('FAIL chat continuity prompting');
console.error(error.stack || error.message);
process.exit(1);
});