@linimin/pi-letscook 0.1.50 → 0.1.52
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/CHANGELOG.md +19 -0
- package/README.md +87 -52
- package/extensions/completion/driver.ts +199 -134
- package/extensions/completion/index.ts +20 -7
- package/extensions/completion/input-routing.ts +818 -0
- package/extensions/completion/prompt-surfaces.ts +375 -1
- package/extensions/completion/proposal.ts +1 -1
- package/extensions/completion/role-runner.ts +310 -3
- package/extensions/completion/types.ts +114 -0
- package/package.json +1 -1
- package/scripts/cook-trigger-routing-test.sh +1122 -0
- package/scripts/release-check.sh +29 -21
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
CompletionStateSnapshot,
|
|
5
|
+
CookNaturalLanguageHandoff,
|
|
6
|
+
CookTriggerAdoptedArtifact,
|
|
7
|
+
CookTriggerClarificationActionItem,
|
|
8
|
+
CookTriggerClarificationLayout,
|
|
9
|
+
CookTriggerClassification,
|
|
10
|
+
CookTriggerConfirmationActionItem,
|
|
11
|
+
CookTriggerConfirmationLayout,
|
|
12
|
+
CookTriggerRecoveryActionItem,
|
|
13
|
+
CookTriggerRecoveryLayout,
|
|
14
|
+
CookTriggerWorkflowBias,
|
|
15
|
+
LiveRoleActivity,
|
|
16
|
+
} from "./types";
|
|
4
17
|
import type {
|
|
5
18
|
ContextProposal,
|
|
6
19
|
ContextProposalAnalysis,
|
|
@@ -187,6 +200,367 @@ export function maybeWriteContextProposalSnapshot(proposal: ContextProposal, sna
|
|
|
187
200
|
}
|
|
188
201
|
}
|
|
189
202
|
|
|
203
|
+
function writeJsonSnapshot(snapshotPath: string | undefined, value: unknown): void {
|
|
204
|
+
if (!snapshotPath) return;
|
|
205
|
+
try {
|
|
206
|
+
fs.mkdirSync(path.dirname(snapshotPath), { recursive: true });
|
|
207
|
+
fs.writeFileSync(snapshotPath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
208
|
+
} catch {
|
|
209
|
+
// ignore malformed or unwritable test snapshot paths
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export function buildCookTriggerClassifierPrompt(args: {
|
|
214
|
+
projectName: string;
|
|
215
|
+
inputText: string;
|
|
216
|
+
recentDiscussion: string;
|
|
217
|
+
workflowContextLines?: string[];
|
|
218
|
+
}): string {
|
|
219
|
+
const lines = [
|
|
220
|
+
`Project: ${args.projectName}`,
|
|
221
|
+
"Classify whether the current input should stay in the main chat or be intercepted by the workflow-aware router into the canonical /cook workflow before the primary agent starts implementation work.",
|
|
222
|
+
"Assume router mode reviews every non-bypass normal user turn. Do not require short trigger phrases or explicit /cook text before choosing offer_workflow.",
|
|
223
|
+
"Return JSON only with keys: decision, confidence, workflow_bias, reason, evidence, riskFlags, focusHint. You may also include optional keys requires_clarification, clarification_slots, and adopted_artifact when clearly supported.",
|
|
224
|
+
"decision must be exactly one of offer_workflow, normal_prompt, or unclear.",
|
|
225
|
+
"Use offer_workflow when the user is directly asking to start, resume, refocus, or continue workflow-worthy repo work through the completion boundary, or explicitly asking to let /cook take over.",
|
|
226
|
+
"Use normal_prompt for ordinary questions, explanations, analysis-only requests, or direct agent requests that should stay in the main chat.",
|
|
227
|
+
"Use unclear for ambiguous approvals, short acknowledgements, or cases where false-positive routing risk is material.",
|
|
228
|
+
"workflow_bias must be exactly one of startup, resume, refocus, next_round, or unknown.",
|
|
229
|
+
"Use startup when there is no active workflow yet, resume when the user is clearly continuing the current workflow, refocus when the user is clearly switching the active workflow to a different goal, and next_round when the previous workflow is done and the user is starting a new round.",
|
|
230
|
+
"When decision is not offer_workflow, prefer workflow_bias=unknown unless a stronger routing hint is still useful for later debugging.",
|
|
231
|
+
"focusHint is optional, must stay short, and must never rewrite the workflow mission or invent scope.",
|
|
232
|
+
"When explicit user adoption of a recent plan or repo markdown artifact is evident, adopted_artifact may describe it with kind recent_plan|repo_markdown, path when known, and basis explicit_user_adoption.",
|
|
233
|
+
"requires_clarification may be true when chooser-style disambiguation is safer than guessing, and clarification_slots may list short needs such as goal, scope, or non_goal.",
|
|
234
|
+
"evidence and riskFlags must be arrays of short grounded strings.",
|
|
235
|
+
];
|
|
236
|
+
if (args.workflowContextLines?.length) lines.push("", "Canonical workflow context:", ...args.workflowContextLines);
|
|
237
|
+
lines.push("", `Current input: ${args.inputText}`, "", "Recent discussion:", args.recentDiscussion || "(none)");
|
|
238
|
+
return lines.join("\n");
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function cookTriggerOfferCopyForBias(
|
|
242
|
+
workflowBias: CookTriggerWorkflowBias,
|
|
243
|
+
mainChatRerunGuidance: string,
|
|
244
|
+
): { title: string; intro: string; startAction: CookTriggerConfirmationActionItem; sendAsNormalChat: CookTriggerConfirmationActionItem; cancel: CookTriggerConfirmationActionItem } {
|
|
245
|
+
switch (workflowBias) {
|
|
246
|
+
case "startup":
|
|
247
|
+
return {
|
|
248
|
+
title: "Start a completion workflow from the recent discussion?",
|
|
249
|
+
intro:
|
|
250
|
+
"This input looks like a startup handoff into the completion workflow. The shared /cook entry would initialize or continue the canonical workflow boundary only after you confirm.",
|
|
251
|
+
startAction: {
|
|
252
|
+
id: "start_workflow",
|
|
253
|
+
label: "Start workflow",
|
|
254
|
+
description: "Enter the shared /cook workflow entry from the recent discussion before the primary agent starts implementation work.",
|
|
255
|
+
},
|
|
256
|
+
sendAsNormalChat: {
|
|
257
|
+
id: "send_as_normal_chat",
|
|
258
|
+
label: "Send as normal chat",
|
|
259
|
+
description: "Replay the original message exactly once to the primary agent and bypass router interception for that replay.",
|
|
260
|
+
},
|
|
261
|
+
cancel: {
|
|
262
|
+
id: "cancel",
|
|
263
|
+
label: "Cancel",
|
|
264
|
+
description: `Stop here without routing or replaying the original message. ${mainChatRerunGuidance}`,
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
case "resume":
|
|
268
|
+
return {
|
|
269
|
+
title: "Resume the current completion workflow?",
|
|
270
|
+
intro:
|
|
271
|
+
"This input looks like a resume handoff for the current completion workflow. The shared /cook entry would continue from canonical state only after you confirm.",
|
|
272
|
+
startAction: {
|
|
273
|
+
id: "start_workflow",
|
|
274
|
+
label: "Resume workflow",
|
|
275
|
+
description: "Resume the current canonical completion workflow through the shared /cook entry.",
|
|
276
|
+
},
|
|
277
|
+
sendAsNormalChat: {
|
|
278
|
+
id: "send_as_normal_chat",
|
|
279
|
+
label: "Send as normal chat",
|
|
280
|
+
description: "Replay the original message exactly once to the primary agent and bypass router interception for that replay.",
|
|
281
|
+
},
|
|
282
|
+
cancel: {
|
|
283
|
+
id: "cancel",
|
|
284
|
+
label: "Cancel",
|
|
285
|
+
description: `Stop here without resuming or replaying the original message. ${mainChatRerunGuidance}`,
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
case "refocus":
|
|
289
|
+
return {
|
|
290
|
+
title: "Refocus the completion workflow from the recent discussion?",
|
|
291
|
+
intro:
|
|
292
|
+
"This input looks like a refocus handoff. The shared /cook entry would keep the existing chooser and confirmation semantics before any canonical workflow state is rewritten.",
|
|
293
|
+
startAction: {
|
|
294
|
+
id: "start_workflow",
|
|
295
|
+
label: "Refocus workflow",
|
|
296
|
+
description: "Review the recent discussion through the shared /cook entry and refocus the canonical workflow only if the follow-up confirmations agree.",
|
|
297
|
+
},
|
|
298
|
+
sendAsNormalChat: {
|
|
299
|
+
id: "send_as_normal_chat",
|
|
300
|
+
label: "Send as normal chat",
|
|
301
|
+
description: "Replay the original message exactly once to the primary agent and bypass router interception for that replay.",
|
|
302
|
+
},
|
|
303
|
+
cancel: {
|
|
304
|
+
id: "cancel",
|
|
305
|
+
label: "Cancel",
|
|
306
|
+
description: `Stop here without refocusing or replaying the original message. ${mainChatRerunGuidance}`,
|
|
307
|
+
},
|
|
308
|
+
};
|
|
309
|
+
case "next_round":
|
|
310
|
+
return {
|
|
311
|
+
title: "Start the next completion workflow round from the recent discussion?",
|
|
312
|
+
intro:
|
|
313
|
+
"This input looks like a next-round handoff after a completed workflow. The shared /cook entry would preserve the same canonical workflow boundary while starting the next round only after you confirm.",
|
|
314
|
+
startAction: {
|
|
315
|
+
id: "start_workflow",
|
|
316
|
+
label: "Start next round",
|
|
317
|
+
description: "Start the next workflow round through the shared /cook entry using the recent discussion as the new focus.",
|
|
318
|
+
},
|
|
319
|
+
sendAsNormalChat: {
|
|
320
|
+
id: "send_as_normal_chat",
|
|
321
|
+
label: "Send as normal chat",
|
|
322
|
+
description: "Replay the original message exactly once to the primary agent and bypass router interception for that replay.",
|
|
323
|
+
},
|
|
324
|
+
cancel: {
|
|
325
|
+
id: "cancel",
|
|
326
|
+
label: "Cancel",
|
|
327
|
+
description: `Stop here without starting a new workflow round or replaying the original message. ${mainChatRerunGuidance}`,
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
case "unknown":
|
|
331
|
+
default:
|
|
332
|
+
return {
|
|
333
|
+
title: "Let the completion workflow take over from the recent discussion?",
|
|
334
|
+
intro:
|
|
335
|
+
"This input looks like a natural-language handoff into the completion workflow. The shared /cook entry would keep the existing approval-only startup, continue, refocus, and next-round semantics before canonical state changes.",
|
|
336
|
+
startAction: {
|
|
337
|
+
id: "start_workflow",
|
|
338
|
+
label: "Start workflow",
|
|
339
|
+
description: "Enter the shared /cook workflow entry before the primary agent starts implementation work.",
|
|
340
|
+
},
|
|
341
|
+
sendAsNormalChat: {
|
|
342
|
+
id: "send_as_normal_chat",
|
|
343
|
+
label: "Send as normal chat",
|
|
344
|
+
description: "Replay the original message exactly once to the primary agent and bypass router interception for that replay.",
|
|
345
|
+
},
|
|
346
|
+
cancel: {
|
|
347
|
+
id: "cancel",
|
|
348
|
+
label: "Cancel",
|
|
349
|
+
description: `Stop here without routing or replaying the original message. ${mainChatRerunGuidance}`,
|
|
350
|
+
},
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export function buildCookTriggerConfirmationActions(
|
|
356
|
+
workflowBias: CookTriggerWorkflowBias,
|
|
357
|
+
mainChatRerunGuidance: string,
|
|
358
|
+
): CookTriggerConfirmationActionItem[] {
|
|
359
|
+
const copy = cookTriggerOfferCopyForBias(workflowBias, mainChatRerunGuidance);
|
|
360
|
+
return [copy.startAction, copy.sendAsNormalChat, copy.cancel];
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function summarizeAdoptedArtifact(adoptedArtifact: CookTriggerAdoptedArtifact | undefined): string | undefined {
|
|
364
|
+
if (!adoptedArtifact) return undefined;
|
|
365
|
+
const lines = [
|
|
366
|
+
`- kind: ${adoptedArtifact.kind}`,
|
|
367
|
+
`- basis: ${adoptedArtifact.basis}`,
|
|
368
|
+
`- title: ${adoptedArtifact.title}`,
|
|
369
|
+
];
|
|
370
|
+
if (adoptedArtifact.path) lines.push(`- path: ${adoptedArtifact.path}`);
|
|
371
|
+
if (adoptedArtifact.preview) lines.push(`- preview: ${adoptedArtifact.preview}`);
|
|
372
|
+
return lines.join("\n");
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export function buildCookTriggerClarificationLayout(args: {
|
|
376
|
+
currentMission?: string;
|
|
377
|
+
candidateMission?: string;
|
|
378
|
+
workflowBiases: CookTriggerWorkflowBias[];
|
|
379
|
+
mainChatRerunGuidance: string;
|
|
380
|
+
adoptedArtifact?: CookTriggerAdoptedArtifact;
|
|
381
|
+
}): CookTriggerClarificationLayout {
|
|
382
|
+
const actions: CookTriggerClarificationActionItem[] = [];
|
|
383
|
+
if (args.workflowBiases.includes("startup")) {
|
|
384
|
+
actions.push({
|
|
385
|
+
id: "route_startup",
|
|
386
|
+
label: "Start workflow",
|
|
387
|
+
description: "Treat this as a startup handoff into the shared /cook workflow from the recent discussion.",
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
if (args.workflowBiases.includes("resume")) {
|
|
391
|
+
actions.push({
|
|
392
|
+
id: "route_resume",
|
|
393
|
+
label: "Resume workflow",
|
|
394
|
+
description: "Keep the current canonical mission and resume the active workflow through the shared /cook entry.",
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
if (args.workflowBiases.includes("refocus")) {
|
|
398
|
+
actions.push({
|
|
399
|
+
id: "route_refocus",
|
|
400
|
+
label: "Refocus from recent discussion",
|
|
401
|
+
description: "Route into the shared /cook entry and keep its existing chooser + approval flow before any canonical state rewrite.",
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
if (args.workflowBiases.includes("next_round")) {
|
|
405
|
+
actions.push({
|
|
406
|
+
id: "route_next_round",
|
|
407
|
+
label: "Start next round",
|
|
408
|
+
description: "Treat this as a next-round handoff into the shared /cook entry after the finished workflow.",
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
actions.push(
|
|
412
|
+
{
|
|
413
|
+
id: "send_as_normal_chat",
|
|
414
|
+
label: "Send as normal chat",
|
|
415
|
+
description: "Replay the original message exactly once to the primary agent and bypass router interception for that replay.",
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
id: "cancel",
|
|
419
|
+
label: "Cancel",
|
|
420
|
+
description: `Stop here without routing or replaying the original message. ${args.mainChatRerunGuidance}`,
|
|
421
|
+
},
|
|
422
|
+
);
|
|
423
|
+
return {
|
|
424
|
+
title: "Clarify how the completion workflow should proceed",
|
|
425
|
+
intro:
|
|
426
|
+
"This start-intent looks workflow-related, but not enough to safely choose startup, resume, refocus, or next-round automatically. Pick the minimal next step or cancel without changing canonical workflow state.",
|
|
427
|
+
currentMissionHeading: args.currentMission ? "Current mission" : undefined,
|
|
428
|
+
currentMissionBody: args.currentMission,
|
|
429
|
+
candidateMissionHeading: args.candidateMission ? "Recent-discussion candidate" : undefined,
|
|
430
|
+
candidateMissionBody: args.candidateMission,
|
|
431
|
+
adoptedArtifactHeading: args.adoptedArtifact ? "Adopted artifact" : undefined,
|
|
432
|
+
adoptedArtifactBody: summarizeAdoptedArtifact(args.adoptedArtifact),
|
|
433
|
+
actionsHeading: "Actions",
|
|
434
|
+
actions,
|
|
435
|
+
footer: "↑↓ navigate • enter select • esc cancel",
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export function buildCookTriggerAssistConfirmationLayout(args: {
|
|
440
|
+
classification: CookTriggerClassification;
|
|
441
|
+
mainChatRerunGuidance: string;
|
|
442
|
+
}): CookTriggerConfirmationLayout {
|
|
443
|
+
const evidenceBody =
|
|
444
|
+
args.classification.evidence.length > 0
|
|
445
|
+
? args.classification.evidence.map((item) => `- ${item}`).join("\n")
|
|
446
|
+
: "- No additional evidence was captured beyond the current handoff signal.";
|
|
447
|
+
const riskBody = args.classification.riskFlags.length > 0 ? args.classification.riskFlags.map((item) => `- ${item}`).join("\n") : undefined;
|
|
448
|
+
const copy = cookTriggerOfferCopyForBias(args.classification.workflowBias, args.mainChatRerunGuidance);
|
|
449
|
+
return {
|
|
450
|
+
title: copy.title,
|
|
451
|
+
intro: copy.intro,
|
|
452
|
+
evidenceHeading: "Why it matched",
|
|
453
|
+
evidenceBody,
|
|
454
|
+
riskHeading: riskBody ? "Risk checks" : undefined,
|
|
455
|
+
riskBody,
|
|
456
|
+
focusHintHeading: args.classification.focusHint ? "Optional focus hint" : undefined,
|
|
457
|
+
focusHintBody: args.classification.focusHint,
|
|
458
|
+
actionsHeading: "Actions",
|
|
459
|
+
actions: [copy.startAction, copy.sendAsNormalChat, copy.cancel],
|
|
460
|
+
footer: "↑↓ navigate • enter select • esc cancel",
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
export function buildCookTriggerRecoveryLayout(args: {
|
|
465
|
+
failureLabel: string;
|
|
466
|
+
mainChatRerunGuidance: string;
|
|
467
|
+
}): CookTriggerRecoveryLayout {
|
|
468
|
+
const actions: CookTriggerRecoveryActionItem[] = [
|
|
469
|
+
{
|
|
470
|
+
id: "retry_routing",
|
|
471
|
+
label: "Retry routing",
|
|
472
|
+
description: "Run the workflow-aware router classifier once more before deciding whether /cook should take over.",
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
id: "send_as_normal_chat",
|
|
476
|
+
label: "Send as normal chat",
|
|
477
|
+
description: "Replay the original message exactly once to the primary agent and bypass router interception for that replay.",
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
id: "cancel",
|
|
481
|
+
label: "Cancel",
|
|
482
|
+
description: `Stop here without routing or replaying the original message. ${args.mainChatRerunGuidance}`,
|
|
483
|
+
},
|
|
484
|
+
];
|
|
485
|
+
return {
|
|
486
|
+
title: "Router recovery needed before this prompt can continue",
|
|
487
|
+
intro:
|
|
488
|
+
"The workflow-aware router could not safely classify this prompt, so it stayed fail-closed instead of silently sending the prompt to the primary agent. Choose an explicit recovery path or cancel.",
|
|
489
|
+
failureHeading: "Router failure",
|
|
490
|
+
failureBody: args.failureLabel,
|
|
491
|
+
actionsHeading: "Actions",
|
|
492
|
+
actions,
|
|
493
|
+
footer: "↑↓ navigate • enter select • esc cancel",
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export function maybeWriteCookTriggerClassifierSnapshot(snapshot: Record<string, unknown>, snapshotPath: string | undefined): void {
|
|
498
|
+
writeJsonSnapshot(snapshotPath, snapshot);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
export function maybeWriteCookTriggerConfirmationSnapshot(
|
|
502
|
+
layout: CookTriggerConfirmationLayout,
|
|
503
|
+
snapshotPath: string | undefined,
|
|
504
|
+
): void {
|
|
505
|
+
writeJsonSnapshot(snapshotPath, layout);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
export function maybeWriteCookTriggerClarificationSnapshot(
|
|
509
|
+
layout: CookTriggerClarificationLayout,
|
|
510
|
+
snapshotPath: string | undefined,
|
|
511
|
+
): void {
|
|
512
|
+
writeJsonSnapshot(snapshotPath, layout);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
export function maybeWriteCookTriggerRecoverySnapshot(layout: CookTriggerRecoveryLayout, snapshotPath: string | undefined): void {
|
|
516
|
+
writeJsonSnapshot(snapshotPath, layout);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
export function maybeWriteCookTriggerRoutingSnapshot(snapshot: Record<string, unknown>, snapshotPath: string | undefined): void {
|
|
520
|
+
writeJsonSnapshot(snapshotPath, snapshot);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function buildNaturalLanguageHandoffArtifactLines(adoptedArtifact: CookTriggerAdoptedArtifact | undefined): string[] {
|
|
524
|
+
if (!adoptedArtifact) return [];
|
|
525
|
+
const lines = [
|
|
526
|
+
`- adopted_artifact_kind: ${adoptedArtifact.kind}`,
|
|
527
|
+
`- adopted_artifact_basis: ${adoptedArtifact.basis}`,
|
|
528
|
+
`- adopted_artifact_title: ${adoptedArtifact.title}`,
|
|
529
|
+
];
|
|
530
|
+
if (adoptedArtifact.path) lines.push(`- adopted_artifact_path: ${adoptedArtifact.path}`);
|
|
531
|
+
if (adoptedArtifact.preview) lines.push(`- adopted_artifact_preview: ${adoptedArtifact.preview}`);
|
|
532
|
+
return lines;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function buildNaturalLanguageHandoffClarificationLines(
|
|
536
|
+
clarificationCapsule: CookNaturalLanguageHandoff["clarificationCapsule"] | undefined,
|
|
537
|
+
): string[] {
|
|
538
|
+
if (!clarificationCapsule) return [];
|
|
539
|
+
const lines = [
|
|
540
|
+
`- clarification_selected_bias: ${clarificationCapsule.selectedWorkflowBias}`,
|
|
541
|
+
`- clarification_reason: ${clarificationCapsule.reason}`,
|
|
542
|
+
];
|
|
543
|
+
if (clarificationCapsule.goal) lines.push(`- clarification_goal: ${clarificationCapsule.goal}`);
|
|
544
|
+
if (clarificationCapsule.scope?.length) lines.push(`- clarification_scope: ${clarificationCapsule.scope.join(" | ")}`);
|
|
545
|
+
if (clarificationCapsule.nonGoal?.length) lines.push(`- clarification_non_goal: ${clarificationCapsule.nonGoal.join(" | ")}`);
|
|
546
|
+
if (clarificationCapsule.doneWhen?.length) lines.push(`- clarification_done_when: ${clarificationCapsule.doneWhen.join(" | ")}`);
|
|
547
|
+
return lines;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
export function buildNaturalLanguageHandoffMetadataLines(handoff: CookNaturalLanguageHandoff | undefined): string[] {
|
|
551
|
+
if (!handoff) return [];
|
|
552
|
+
return [
|
|
553
|
+
"Natural-language handoff metadata:",
|
|
554
|
+
`- source: natural_language_handoff`,
|
|
555
|
+
`- preferred_routing_bias: ${handoff.preferredRoutingBias ?? "unknown"}`,
|
|
556
|
+
`- trigger_text: ${handoff.triggerText ?? "(none)"}`,
|
|
557
|
+
`- focus_hint: ${handoff.hintText ?? "(none)"}`,
|
|
558
|
+
...buildNaturalLanguageHandoffArtifactLines(handoff.adoptedArtifact),
|
|
559
|
+
...buildNaturalLanguageHandoffClarificationLines(handoff.clarificationCapsule),
|
|
560
|
+
"",
|
|
561
|
+
];
|
|
562
|
+
}
|
|
563
|
+
|
|
190
564
|
export function buildContextProposalConfirmationSelectItems(layout: ContextProposalConfirmationLayout) {
|
|
191
565
|
return layout.actions.map((action) => ({
|
|
192
566
|
value: action.id,
|
|
@@ -350,7 +350,7 @@ function contextHintEntry(hintText: string | undefined): RecentDiscussionEntry[]
|
|
|
350
350
|
const RECENT_DISCUSSION_IMPLEMENTATION_INTENT_REGEX =
|
|
351
351
|
/(?:\b(?:fix|update|add|remove|restore|refactor|ship|support|wire|route|rewrite|replace|preserve|filter|separate|refresh|reroute|suppress|align|convert|reconcile|repair|correct|implement|build|land|block|allow|keep|edit|document|write)\b|(?:修正|修復|修复|更新|新增|移除|恢復|恢复|重構|重构|調整|调整|過濾|过滤|分離|分离|刷新|替換|替换|抑制|對齊|对齐|實作|实现|落地|修補|修补|阻止|允許|允许|轉換|转换|保留|保持))/iu;
|
|
352
352
|
|
|
353
|
-
function hasRecentDiscussionImplementationIntent(text: string, stripCodeBlocksFn: (text: string) => string): boolean {
|
|
353
|
+
export function hasRecentDiscussionImplementationIntent(text: string, stripCodeBlocksFn: (text: string) => string): boolean {
|
|
354
354
|
const cleaned = stripCodeBlocksFn(text).replace(/\r/g, " ").trim();
|
|
355
355
|
if (!cleaned) return false;
|
|
356
356
|
return hasStructuredContextProposalSignal(cleaned, stripCodeBlocksFn) || RECENT_DISCUSSION_IMPLEMENTATION_INTENT_REGEX.test(cleaned);
|