@orion-agents/orion-code 0.4.7 → 0.4.8
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 +9 -1
- package/README.md +8 -9
- package/README.zh-CN.md +8 -8
- package/dist/acp/session-updates.js +1 -0
- package/dist/framework/query.d.ts +3 -7
- package/dist/framework/query.js +22 -74
- package/dist/framework/verification-command.d.ts +21 -0
- package/dist/framework/verification-command.js +53 -4
- package/dist/harness/context-harness.d.ts +3 -9
- package/dist/harness/context-harness.js +43 -163
- package/dist/harness/state.d.ts +3 -0
- package/dist/harness/state.js +37 -4
- package/dist/harness/task-checklist.d.ts +1 -1
- package/dist/harness/task-checklist.js +1 -1
- package/dist/harness/types.d.ts +1 -0
- package/dist/harness/verification.js +5 -4
- package/dist/runtime/agent-loop.js +6 -33
- package/dist/runtime/goal-lifecycle-v2.js +5 -0
- package/dist/runtime/goal-runtime-coordinator.js +6 -2
- package/dist/runtime/orion-runtime-v1.js +33 -6
- package/dist/runtime/product-orion-runtime.js +6 -2
- package/dist/runtime/step-snapshot.js +57 -10
- package/dist/runtime/task-context-recovery.js +7 -3
- package/dist/runtime/task-context-service.d.ts +2 -6
- package/dist/runtime/task-context-service.js +3 -12
- package/dist/runtime/thread-ui-adapter.js +13 -1
- package/dist/runtime/ui-events.d.ts +3 -0
- package/dist/runtime/verification-feedback.d.ts +4 -0
- package/dist/runtime/verification-feedback.js +61 -0
- package/dist/tools/bash_security.d.ts +1 -24
- package/dist/tools/bash_security.js +7 -124
- package/dist/tools/todo.js +9 -13
- package/dist/utils/shell-command.d.ts +29 -0
- package/dist/utils/shell-command.js +185 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -7,7 +7,6 @@ const crypto_1 = require("crypto");
|
|
|
7
7
|
const path_1 = require("path");
|
|
8
8
|
const redaction_1 = require("../services/redaction");
|
|
9
9
|
const tool_serializer_1 = require("../framework/tool-serializer");
|
|
10
|
-
const stop_decision_1 = require("../framework/stop-decision");
|
|
11
10
|
const verification_command_1 = require("../framework/verification-command");
|
|
12
11
|
const assembler_1 = require("./assembler");
|
|
13
12
|
const capability_profile_1 = require("./capability-profile");
|
|
@@ -21,7 +20,6 @@ const intent_1 = require("./intent");
|
|
|
21
20
|
const ledger_1 = require("./ledger");
|
|
22
21
|
const progress_controller_1 = require("./progress-controller");
|
|
23
22
|
const state_1 = require("./state");
|
|
24
|
-
const stop_controller_1 = require("./stop-controller");
|
|
25
23
|
const task_checklist_1 = require("./task-checklist");
|
|
26
24
|
const turn_summary_1 = require("./turn-summary");
|
|
27
25
|
const verification_1 = require("./verification");
|
|
@@ -32,7 +30,6 @@ const DEFAULT_CONFIG = {
|
|
|
32
30
|
maxRecentTurns: 8,
|
|
33
31
|
evidenceBudgetRatio: 0.3,
|
|
34
32
|
driftGuard: 'warn',
|
|
35
|
-
completionGate: 'warn',
|
|
36
33
|
};
|
|
37
34
|
/** Canonical v0.1.9 task-state owner; ContextHarness remains a compatibility alias. */
|
|
38
35
|
class HarnessKernel {
|
|
@@ -46,7 +43,6 @@ class HarnessKernel {
|
|
|
46
43
|
this.ledger = new ledger_1.ContextLedger(state.ledger, state.workspaceRevision);
|
|
47
44
|
this.verificationWorkspace = state.verificationWorkspace;
|
|
48
45
|
this.capsule = state.capsule;
|
|
49
|
-
this.completionBlockCount = state.completionBlockCount ?? 0;
|
|
50
46
|
this.taskEpoch = state.taskEpoch ?? 1;
|
|
51
47
|
this.goalTaskId = state.goalTaskId;
|
|
52
48
|
this.goalVerificationBlocker = state.goalVerificationBlocker;
|
|
@@ -60,11 +56,7 @@ class HarnessKernel {
|
|
|
60
56
|
byDescription.get(savedId) ?? savedId,
|
|
61
57
|
...receipt,
|
|
62
58
|
]);
|
|
63
|
-
this.taskTodos = todos
|
|
64
|
-
return todo.status === 'completed' && this.missingTodoEvidence(todo)
|
|
65
|
-
? { ...todo, status: 'pending' }
|
|
66
|
-
: todo;
|
|
67
|
-
});
|
|
59
|
+
this.taskTodos = todos;
|
|
68
60
|
this.rootObjective = state.rootObjective;
|
|
69
61
|
this.activeInstruction = state.activeInstruction;
|
|
70
62
|
this.intentHistory = state.intentHistory ?? [];
|
|
@@ -78,14 +70,12 @@ class HarnessKernel {
|
|
|
78
70
|
this.promptAssemblyStats = state.promptAssemblyStats;
|
|
79
71
|
this.diagnostics = state.diagnostics ?? [];
|
|
80
72
|
this.progressController = new progress_controller_1.ProgressController(state.progressState);
|
|
81
|
-
this.stopController = new stop_controller_1.StopController();
|
|
82
73
|
this.capabilityProfile = state.capabilityProfile;
|
|
83
74
|
this.capabilityHistory = state.capabilityHistory ?? [];
|
|
84
75
|
this.reconciledAt = state.reconciledAt;
|
|
85
76
|
this.updatedAt = state.updatedAt;
|
|
86
77
|
}
|
|
87
78
|
updateContractFromUserInput(input, goalTaskId) {
|
|
88
|
-
this.reportedTaskBlocker = undefined;
|
|
89
79
|
if (this.config.enabled === false)
|
|
90
80
|
return;
|
|
91
81
|
if (goalTaskId && this.goalTaskId === goalTaskId && this.contract)
|
|
@@ -124,7 +114,6 @@ class HarnessKernel {
|
|
|
124
114
|
this.taskTodos = [];
|
|
125
115
|
this.taskTodoReceipts.length = 0;
|
|
126
116
|
this.goalVerificationBlocker = undefined;
|
|
127
|
-
this.completionBlockCount = 0;
|
|
128
117
|
this.activeConstraints = [];
|
|
129
118
|
this.nonGoals = [];
|
|
130
119
|
this.openQuestions = [];
|
|
@@ -241,18 +230,13 @@ class HarnessKernel {
|
|
|
241
230
|
hasTaskTodos() {
|
|
242
231
|
return this.taskTodos.length > 0;
|
|
243
232
|
}
|
|
244
|
-
|
|
233
|
+
deferredWorkspaceWriteReason(action) {
|
|
245
234
|
if (this.hasOnlyDeferredWork()) {
|
|
246
235
|
return 'The user deferred the remaining steps. Wait for explicit continuation.';
|
|
247
236
|
}
|
|
248
|
-
if (
|
|
249
|
-
|
|
250
|
-
if (scoped)
|
|
251
|
-
return scoped;
|
|
237
|
+
if (this.taskTodos.some(todo => todo.deferredReason)) {
|
|
238
|
+
return this.checkDeferredWorkspaceAction(action);
|
|
252
239
|
}
|
|
253
|
-
if (!this.taskChecklistRequired)
|
|
254
|
-
return undefined;
|
|
255
|
-
return (0, task_checklist_1.executionChecklistIssue)(this.taskTodos, this.taskChecklistTargets, this.cwd);
|
|
256
240
|
}
|
|
257
241
|
checkDeferredWorkspaceAction(action) {
|
|
258
242
|
const target = action.path ? (0, verification_1.workspaceArtifactPath)(this.cwd, action.path) : undefined;
|
|
@@ -273,19 +257,6 @@ class HarnessKernel {
|
|
|
273
257
|
}
|
|
274
258
|
return 'The user deferred part of the checklist. Use a file tool for the active step or run its required check before making other workspace changes.';
|
|
275
259
|
}
|
|
276
|
-
prepareTaskPlanStopCheck() {
|
|
277
|
-
return () => {
|
|
278
|
-
if (this.hasOnlyDeferredWork()) {
|
|
279
|
-
return {
|
|
280
|
-
code: 'task_deferred',
|
|
281
|
-
message: 'The remaining checklist steps are deferred at your request. Say “continue” to resume them.',
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
const blocker = this.reportedTaskBlocker;
|
|
285
|
-
this.reportedTaskBlocker = undefined;
|
|
286
|
-
return blocker;
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
260
|
hasOnlyDeferredWork() {
|
|
290
261
|
return (this.taskTodos.some(todo => todo.deferredReason) &&
|
|
291
262
|
this.taskTodos.every(todo => todo.deferredReason || todo.status === 'completed'));
|
|
@@ -307,13 +278,6 @@ class HarnessKernel {
|
|
|
307
278
|
this.refreshCapsule();
|
|
308
279
|
this.touch();
|
|
309
280
|
}
|
|
310
|
-
requiresVerification() {
|
|
311
|
-
if (this.config.enabled === false ||
|
|
312
|
-
(this.config.completionGate !== 'block' && this.config.completionGate !== true))
|
|
313
|
-
return false;
|
|
314
|
-
return (this.contract?.criteria?.some(item => (0, verification_1.requiredVerificationKinds)(item.statement).length > 0) ||
|
|
315
|
-
(0, drift_guard_1.hasExplicitVerificationNeed)(this.contract));
|
|
316
|
-
}
|
|
317
281
|
recordTaskTodoReceipt(step, observation) {
|
|
318
282
|
const todo = this.taskTodos.find(item => item.status === 'in_progress');
|
|
319
283
|
if (todo?.id !== step)
|
|
@@ -367,62 +331,48 @@ class HarnessKernel {
|
|
|
367
331
|
const previousByRequest = new Map();
|
|
368
332
|
if (requested.size !== todos.length)
|
|
369
333
|
return 'Todo descriptions must be unique.';
|
|
370
|
-
|
|
334
|
+
const hasDeferredTodos = this.taskTodos.some(todo => todo.deferredReason);
|
|
335
|
+
if (hasDeferredTodos && todos.length > this.taskTodos.length) {
|
|
371
336
|
return 'The user deferred part of the checklist. Wait for their continuation before adding steps.';
|
|
372
337
|
}
|
|
373
338
|
for (const previous of this.taskTodos) {
|
|
374
339
|
let replacement = requested.get(previous.content);
|
|
375
|
-
if (!replacement &&
|
|
340
|
+
if (!replacement &&
|
|
341
|
+
!previous.deferredReason &&
|
|
342
|
+
(previous.status !== 'completed' || this.missingTodoEvidence(previous))) {
|
|
376
343
|
const refinements = todos.filter(todo => !originalNames.has(todo.content) &&
|
|
377
344
|
!previousByRequest.has(todo.content) &&
|
|
378
345
|
(0, task_checklist_1.clarifiesTodoFileTarget)(previous, todo, this.cwd, this.taskChecklistTargets));
|
|
379
346
|
if (refinements.length === 1)
|
|
380
347
|
replacement = refinements[0];
|
|
381
348
|
}
|
|
382
|
-
if (
|
|
383
|
-
return `Keep the existing todo "${previous.content}" in the checklist.`;
|
|
384
|
-
if (previous.deferredReason && replacement.status !== 'pending') {
|
|
349
|
+
if (previous.deferredReason && replacement?.status !== 'pending') {
|
|
385
350
|
return `The user deferred "${previous.content}". Keep it pending until they explicitly continue.`;
|
|
386
351
|
}
|
|
387
|
-
if (
|
|
388
|
-
|
|
389
|
-
!this.missingTodoEvidence(previous)) {
|
|
390
|
-
return `Add a new todo for further work on "${previous.content}".`;
|
|
352
|
+
if (hasDeferredTodos && !replacement) {
|
|
353
|
+
return `Keep the existing todo "${previous.content}" while the user has deferred steps.`;
|
|
391
354
|
}
|
|
392
|
-
|
|
355
|
+
if (replacement)
|
|
356
|
+
previousByRequest.set(replacement.content, previous);
|
|
393
357
|
}
|
|
394
|
-
const warnings = [];
|
|
395
|
-
let hasIndependentUpdate = false;
|
|
396
|
-
let triedToAdvanceActiveTodo = false;
|
|
397
358
|
const next = todos.map(input => {
|
|
398
359
|
const previous = previousByRequest.get(input.content);
|
|
399
|
-
|
|
400
|
-
const missing = todo.status === 'completed' ? this.missingTodoEvidence(todo) : undefined;
|
|
401
|
-
if (missing) {
|
|
402
|
-
warnings.push(missing);
|
|
403
|
-
triedToAdvanceActiveTodo || (triedToAdvanceActiveTodo = previous?.status === 'in_progress');
|
|
404
|
-
return { ...todo, status: 'pending' };
|
|
405
|
-
}
|
|
406
|
-
hasIndependentUpdate || (hasIndependentUpdate = !previous ||
|
|
407
|
-
previous.status !== todo.status ||
|
|
408
|
-
previous.content !== todo.content ||
|
|
409
|
-
previous.verification?.length !== todo.verification?.length);
|
|
410
|
-
return todo;
|
|
360
|
+
return withTodoVerification(input, previous?.id ?? this.taskTodoId(input.content), previous);
|
|
411
361
|
});
|
|
412
|
-
|
|
413
|
-
// can supply it. Repeated stale claims on inactive steps can stay pending.
|
|
414
|
-
if (warnings.length && (triedToAdvanceActiveTodo || !hasIndependentUpdate)) {
|
|
415
|
-
return warnings.join('\n');
|
|
416
|
-
}
|
|
362
|
+
const warnings = [];
|
|
417
363
|
if (blockedReason !== undefined) {
|
|
418
364
|
const active = next.find(todo => todo.status === 'in_progress');
|
|
419
365
|
if (!active || !blockedReason.trim())
|
|
420
366
|
return 'Report the blocker on an active todo.';
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
367
|
+
warnings.push(`Reported blocker for “${active.content}”. ${(0, redaction_1.redactTraceText)(blockedReason.trim())}`);
|
|
368
|
+
}
|
|
369
|
+
for (const todo of next) {
|
|
370
|
+
const missing = todo.status === 'completed' ? this.missingTodoEvidence(todo) : undefined;
|
|
371
|
+
if (missing)
|
|
372
|
+
warnings.push(missing);
|
|
425
373
|
}
|
|
374
|
+
const retained = new Set(next.map(todo => todo.id));
|
|
375
|
+
this.taskTodoReceipts = this.taskTodoReceipts.filter(([id]) => retained.has(id));
|
|
426
376
|
this.taskTodos = next;
|
|
427
377
|
this.touch();
|
|
428
378
|
if (warnings.length) {
|
|
@@ -445,7 +395,6 @@ class HarnessKernel {
|
|
|
445
395
|
const receipts = this.taskTodoReceipts.filter(([step]) => step === todo.id);
|
|
446
396
|
const description = (0, redaction_1.redactTraceText)(todo.content);
|
|
447
397
|
const problems = [];
|
|
448
|
-
let missingChecks = [];
|
|
449
398
|
const implementation = (0, task_checklist_1.isImplementationTodo)(todo);
|
|
450
399
|
if (todo.verification?.length) {
|
|
451
400
|
const expected = todoChecks(todo.content);
|
|
@@ -455,7 +404,7 @@ class HarnessKernel {
|
|
|
455
404
|
result.workspaceRevision === this.ledger.workspaceRevision
|
|
456
405
|
? [result]
|
|
457
406
|
: []);
|
|
458
|
-
missingChecks = todo.verification.flatMap(kind => {
|
|
407
|
+
const missingChecks = todo.verification.flatMap(kind => {
|
|
459
408
|
const selectors = expected.filter(check => check.kind === kind);
|
|
460
409
|
if (selectors.length) {
|
|
461
410
|
return selectors
|
|
@@ -467,7 +416,7 @@ class HarnessKernel {
|
|
|
467
416
|
return [kind === 'diff' ? this.diffTodoCheckHint() : kind];
|
|
468
417
|
});
|
|
469
418
|
if (missingChecks.length) {
|
|
470
|
-
problems.push(
|
|
419
|
+
problems.push(`No matching passing check was recorded for ${missingChecks.join(', ')}.`);
|
|
471
420
|
if (missingChecks.some(item => item.includes('git diff'))) {
|
|
472
421
|
problems.push('A patch display only shows the changes. A compound shell call reports its overall result. A direct diff check records the verification receipt.');
|
|
473
422
|
}
|
|
@@ -481,29 +430,20 @@ class HarnessKernel {
|
|
|
481
430
|
!changedFiles.has(target.candidates[0]) &&
|
|
482
431
|
[...changedFiles].some(path => (0, path_1.basename)(path) === target.declared)));
|
|
483
432
|
if (needsClarification.length) {
|
|
484
|
-
problems.push(`
|
|
433
|
+
problems.push(`The workspace-relative path is ambiguous for ${needsClarification.map(target => target.declared).join(', ')}.`);
|
|
485
434
|
}
|
|
486
435
|
const remaining = targets.filter(target => !needsClarification.includes(target) &&
|
|
487
436
|
(target.candidates.length !== 1 || !changedFiles.has(target.candidates[0])));
|
|
488
437
|
if (remaining.length) {
|
|
489
438
|
const paths = remaining.map(target => target.candidates[0] ?? target.declared).join(', ');
|
|
490
|
-
problems.push(`
|
|
439
|
+
problems.push(`No matching file change was recorded for ${(0, redaction_1.redactTraceText)(paths)}.`);
|
|
491
440
|
}
|
|
492
441
|
else if (!targets.length && !changedFiles.size) {
|
|
493
|
-
problems.push('
|
|
442
|
+
problems.push('No successful workspace change was recorded for this step.');
|
|
494
443
|
}
|
|
495
444
|
}
|
|
496
|
-
if (problems.length)
|
|
497
|
-
|
|
498
|
-
? ` until its required checks pass: ${missingChecks.join(', ')}`
|
|
499
|
-
: '';
|
|
500
|
-
return `Keep "${description}" open${required}. ${problems.join(' ')}`;
|
|
501
|
-
}
|
|
502
|
-
if (implementation || todo.verification?.length)
|
|
503
|
-
return undefined;
|
|
504
|
-
if (receipts.some(([, , result]) => !result))
|
|
505
|
-
return undefined;
|
|
506
|
-
return `Keep "${description}" open until a successful tool receipt is recorded for that step.`;
|
|
445
|
+
if (problems.length)
|
|
446
|
+
return `"${description}" is unverified. ${problems.join(' ')}`;
|
|
507
447
|
}
|
|
508
448
|
formatTodoCheck(command, cwd) {
|
|
509
449
|
const path = (0, path_1.relative)(this.cwd, (0, path_1.resolve)(this.cwd, cwd ?? '.'));
|
|
@@ -759,76 +699,20 @@ class HarnessKernel {
|
|
|
759
699
|
};
|
|
760
700
|
}
|
|
761
701
|
if (enforceTaskTodos) {
|
|
762
|
-
const checklist = this.missingExecutionChecklist();
|
|
763
|
-
if (checklist)
|
|
764
|
-
result.missing.push(checklist);
|
|
765
702
|
for (const todo of this.taskTodos) {
|
|
766
|
-
|
|
767
|
-
|
|
703
|
+
const remaining = todo.status === 'completed'
|
|
704
|
+
? this.missingTodoEvidence(todo)
|
|
705
|
+
: `Unfinished todo: ${todo.content}`;
|
|
706
|
+
if (remaining)
|
|
707
|
+
result.missing.push(remaining);
|
|
768
708
|
}
|
|
769
|
-
if (result.missing.length > 0)
|
|
770
|
-
result.canComplete = false;
|
|
771
|
-
}
|
|
772
|
-
const goalBlocker = requireEveryCriterion ? this.goalVerificationBlocker : undefined;
|
|
773
|
-
if (goalBlocker) {
|
|
774
|
-
result.missing.push(goalBlocker);
|
|
775
|
-
result.canComplete = false;
|
|
776
|
-
}
|
|
777
|
-
const progressDelta = this.recordProgress();
|
|
778
|
-
result.progressDelta = progressDelta;
|
|
779
|
-
const completion = this.stopController.decideCompletion(result, progressDelta);
|
|
780
|
-
result.stopDecision = goalBlocker
|
|
781
|
-
? (0, stop_decision_1.createStopDecision)({
|
|
782
|
-
...completion,
|
|
783
|
-
status: 'blocked',
|
|
784
|
-
reason: { code: 'task_step_blocked', message: goalBlocker },
|
|
785
|
-
nextActions: [
|
|
786
|
-
{
|
|
787
|
-
kind: 'resume',
|
|
788
|
-
label: 'Resume and send the exact replacement check.',
|
|
789
|
-
command: '/goal resume',
|
|
790
|
-
},
|
|
791
|
-
],
|
|
792
|
-
})
|
|
793
|
-
: completion;
|
|
794
|
-
const mode = this.config.completionGate === true
|
|
795
|
-
? 'block'
|
|
796
|
-
: this.config.completionGate === false
|
|
797
|
-
? 'off'
|
|
798
|
-
: (this.config.completionGate ?? 'warn');
|
|
799
|
-
if (!result.canComplete && mode !== 'off') {
|
|
800
|
-
this.ledger.add({
|
|
801
|
-
type: mode === 'block' ? 'blocker' : 'risk',
|
|
802
|
-
content: `Completion gate missing: ${result.missing.join('; ')}`,
|
|
803
|
-
source: { kind: 'system', ref: 'completion_gate' },
|
|
804
|
-
importance: 5,
|
|
805
|
-
ttl: 'task',
|
|
806
|
-
metadata: { missing: result.missing, mode },
|
|
807
|
-
});
|
|
808
|
-
this.refreshCapsule();
|
|
809
|
-
this.touch();
|
|
810
|
-
}
|
|
811
|
-
// Block completion until evidence is provided. Track consecutive blocks
|
|
812
|
-
// so callers can detect a stalled loop, but never silently pass the gate
|
|
813
|
-
// without evidence.
|
|
814
|
-
if (!result.canComplete && (mode === 'block' || requireEveryCriterion)) {
|
|
815
|
-
this.completionBlockCount++;
|
|
816
|
-
this.touch();
|
|
817
|
-
return result;
|
|
818
709
|
}
|
|
819
|
-
if (
|
|
820
|
-
|
|
821
|
-
this.completionBlockCount = 0;
|
|
822
|
-
if (changed)
|
|
823
|
-
this.touch();
|
|
710
|
+
if (requireEveryCriterion && this.goalVerificationBlocker) {
|
|
711
|
+
result.missing.push(this.goalVerificationBlocker);
|
|
824
712
|
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
return {
|
|
829
|
-
role: 'user',
|
|
830
|
-
content: `[Harness Completion Gate]\nThe task is not ready to finish.\nMissing:\n${result.missing.map(item => `- ${item}`).join('\n')}\nContinue working or explicitly explain why verification cannot be run.`,
|
|
831
|
-
};
|
|
713
|
+
result.canComplete = result.missing.length === 0;
|
|
714
|
+
result.progressDelta = this.recordProgress();
|
|
715
|
+
return result;
|
|
832
716
|
}
|
|
833
717
|
asToolBlockedResult(result) {
|
|
834
718
|
return JSON.stringify({
|
|
@@ -918,7 +802,6 @@ class HarnessKernel {
|
|
|
918
802
|
workspaceRevision: this.ledger.workspaceRevision,
|
|
919
803
|
...(this.verificationWorkspace ? { verificationWorkspace: this.verificationWorkspace } : {}),
|
|
920
804
|
capsule: this.capsule,
|
|
921
|
-
completionBlockCount: this.completionBlockCount,
|
|
922
805
|
taskEpoch: this.taskEpoch,
|
|
923
806
|
...(this.taskChecklistRequired ? { taskChecklistRequired: true } : {}),
|
|
924
807
|
...(this.taskChecklistTargets.length
|
|
@@ -995,9 +878,6 @@ class HarnessKernel {
|
|
|
995
878
|
: criterion),
|
|
996
879
|
};
|
|
997
880
|
}
|
|
998
|
-
this.taskTodos = this.taskTodos.map(todo => todo.status === 'completed' && todo.verification?.length && this.missingTodoEvidence(todo)
|
|
999
|
-
? { ...todo, status: 'pending' }
|
|
1000
|
-
: todo);
|
|
1001
881
|
}
|
|
1002
882
|
autoLinkVerificationEvidence(entry) {
|
|
1003
883
|
if (!this.contract?.criteria || !(0, verification_1.isTrustedEvidence)(entry))
|
|
@@ -1143,8 +1023,8 @@ function diffCheckSelector(command) {
|
|
|
1143
1023
|
}
|
|
1144
1024
|
function matchesTodoCheck(observed, check, workspace) {
|
|
1145
1025
|
return (observed.kind === check.kind &&
|
|
1146
|
-
observed.command
|
|
1147
|
-
(
|
|
1026
|
+
observed.command !== undefined &&
|
|
1027
|
+
(0, verification_1.matchesRequestedCheckInvocation)(observed.command, observed.cwd, check, workspace));
|
|
1148
1028
|
}
|
|
1149
1029
|
function sameTodoEvidenceTarget(previous, next) {
|
|
1150
1030
|
if (!previous || !next)
|
package/dist/harness/state.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ interface TranscriptMessage {
|
|
|
3
3
|
role: string;
|
|
4
4
|
content: string;
|
|
5
5
|
}
|
|
6
|
+
/** Matches feedback inserted by older runtimes as a synthetic user message. */
|
|
7
|
+
export declare function isLegacyCompletionFeedback(message: TranscriptMessage): boolean;
|
|
8
|
+
export declare function withoutLegacyGoalGate(content: string): string | undefined;
|
|
6
9
|
export declare function upgradeHarnessState(state?: Partial<HarnessState> | null, options?: {
|
|
7
10
|
cwd?: string;
|
|
8
11
|
messages?: TranscriptMessage[];
|
package/dist/harness/state.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLegacyCompletionFeedback = isLegacyCompletionFeedback;
|
|
4
|
+
exports.withoutLegacyGoalGate = withoutLegacyGoalGate;
|
|
3
5
|
exports.upgradeHarnessState = upgradeHarnessState;
|
|
4
6
|
exports.summarizeHarnessStateForMeta = summarizeHarnessStateForMeta;
|
|
5
7
|
const capsule_1 = require("./capsule");
|
|
@@ -7,6 +9,19 @@ const clarification_1 = require("./clarification");
|
|
|
7
9
|
const contract_1 = require("./contract");
|
|
8
10
|
const evidence_1 = require("./evidence");
|
|
9
11
|
const intent_1 = require("./intent");
|
|
12
|
+
/** Matches feedback inserted by older runtimes as a synthetic user message. */
|
|
13
|
+
function isLegacyCompletionFeedback(message) {
|
|
14
|
+
return (message.role === 'user' &&
|
|
15
|
+
message.content.startsWith('[Harness Completion Gate]\nThe task is not ready to finish.\nMissing:\n- ') &&
|
|
16
|
+
message.content.endsWith('\nContinue working or explicitly explain why verification cannot be run.'));
|
|
17
|
+
}
|
|
18
|
+
const legacyGoalGate = '\nDo not claim completion unless the TaskContext completion gate verifies every criterion.';
|
|
19
|
+
function withoutLegacyGoalGate(content) {
|
|
20
|
+
if (content.startsWith('Continue the active Goal using saved state and receipts.\nObjective: ') &&
|
|
21
|
+
content.endsWith(legacyGoalGate)) {
|
|
22
|
+
return content.slice(0, -legacyGoalGate.length);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
10
25
|
function unique(items) {
|
|
11
26
|
return [...new Set(items.map(item => item.trim()).filter(Boolean))];
|
|
12
27
|
}
|
|
@@ -27,13 +42,19 @@ function firstRealUserMessage(messages) {
|
|
|
27
42
|
}
|
|
28
43
|
function upgradeHarnessState(state, options = {}) {
|
|
29
44
|
const now = Date.now();
|
|
30
|
-
const ledger = state?.ledger ?? [];
|
|
45
|
+
const ledger = (state?.ledger ?? []).filter(entry => entry.source.kind !== 'system' || entry.source.ref !== 'completion_gate');
|
|
31
46
|
const diagnostics = [...(state?.diagnostics ?? [])].filter(message => message !==
|
|
32
47
|
'latest transcript user message differs from active instruction; using stored active instruction' &&
|
|
33
48
|
message !==
|
|
34
49
|
'root objective does not exactly match the first transcript user message; preserving harness root objective');
|
|
35
|
-
const
|
|
36
|
-
|
|
50
|
+
const recordedUserInputs = new Set([
|
|
51
|
+
state?.activeInstruction,
|
|
52
|
+
state?.contract?.userIntent,
|
|
53
|
+
...ledger.filter(entry => entry.source.kind === 'user').map(entry => entry.content),
|
|
54
|
+
]);
|
|
55
|
+
const messages = options.messages?.filter(message => !isLegacyCompletionFeedback(message) || recordedUserInputs.has(message.content));
|
|
56
|
+
const firstUser = firstRealUserMessage(messages);
|
|
57
|
+
const lastUser = latestRealUserMessage(messages);
|
|
37
58
|
const explicitObjective = firstUser ? (0, contract_1.extractExplicitObjective)(firstUser) : undefined;
|
|
38
59
|
const storedContract = state?.contract
|
|
39
60
|
? {
|
|
@@ -61,7 +82,13 @@ function upgradeHarnessState(state, options = {}) {
|
|
|
61
82
|
(0, intent_1.shouldReplaceActiveInstruction)(intent) &&
|
|
62
83
|
!(0, clarification_1.isReadOnlyQuestion)(intent.input))?.activeInstruction ?? rootObjective)
|
|
63
84
|
: storedInstruction;
|
|
64
|
-
const turnSummaries = state?.turnSummaries ?? []
|
|
85
|
+
const turnSummaries = (state?.turnSummaries ?? []).map(summary => summary.assistantOutcome.startsWith('Completion gate stopped this turn: ')
|
|
86
|
+
? {
|
|
87
|
+
...summary,
|
|
88
|
+
assistantOutcome: 'The previous turn ended with incomplete verification.',
|
|
89
|
+
decisions: summary.decisions.filter(decision => decision !== summary.assistantOutcome),
|
|
90
|
+
}
|
|
91
|
+
: summary);
|
|
65
92
|
const evidenceIndex = (0, evidence_1.buildEvidenceIndex)({
|
|
66
93
|
ledger,
|
|
67
94
|
turnSummaries,
|
|
@@ -72,6 +99,12 @@ function upgradeHarnessState(state, options = {}) {
|
|
|
72
99
|
: contract || ledger.length > 0
|
|
73
100
|
? (0, capsule_1.createContextCapsule)(contract, ledger, state?.workspaceRevision)
|
|
74
101
|
: undefined;
|
|
102
|
+
if (capsule?.verification) {
|
|
103
|
+
capsule.verification = {
|
|
104
|
+
...capsule.verification,
|
|
105
|
+
warnings: capsule.verification.warnings.filter(warning => !warning.startsWith('Completion gate missing: ')),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
75
108
|
if (state && state.version !== 2) {
|
|
76
109
|
diagnostics.push('upgraded legacy harness state to v2');
|
|
77
110
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TodoItem } from '../framework/tool-state';
|
|
2
2
|
import type { TaskTodoItem } from './types';
|
|
3
|
-
export declare const TASK_CHECKLIST_REQUIRED = "
|
|
3
|
+
export declare const TASK_CHECKLIST_REQUIRED = "Consider using todo_write to track implementation paths and verification for this multi-step task.";
|
|
4
4
|
export declare function supportsExecutionChecklist(mode: string): boolean;
|
|
5
5
|
export declare const TASK_RECOVERY_STRATEGY_HISTORY_LIMIT = 4;
|
|
6
6
|
/** Deferral is applied from explicit user input. Tool arguments cannot defer work. */
|
|
@@ -19,7 +19,7 @@ const fileExtension = /\.[a-z][a-z0-9]{0,7}$/iu;
|
|
|
19
19
|
const referenceClause = /\s+(?:to (?:match|follow|use)|based on|according to|using|after reading|as (?:in|described in))\s+|(?:,|\s)*(?:参考|参照|依据|基于|对照|按照)/iu;
|
|
20
20
|
const checkInstruction = /^(?:(?:verify|validate|check|review)\b|验收|验证|核对|检查|审阅)/iu;
|
|
21
21
|
const sameFileScope = /^(?:(?:edit|modify|change|update)\s+(?:only\s+)?(?:this|that|the same)\s+file(?:\s+only)?|(?:只)?(?:修改|编辑|更新)(?:这个|该|同一)文件)[.,,。]?$/iu;
|
|
22
|
-
exports.TASK_CHECKLIST_REQUIRED = '
|
|
22
|
+
exports.TASK_CHECKLIST_REQUIRED = 'Consider using todo_write to track implementation paths and verification for this multi-step task.';
|
|
23
23
|
function supportsExecutionChecklist(mode) {
|
|
24
24
|
return mode === 'build' || mode === 'auto' || mode === 'goal';
|
|
25
25
|
}
|
package/dist/harness/types.d.ts
CHANGED
|
@@ -289,6 +289,7 @@ export interface HarnessConfig {
|
|
|
289
289
|
maxRecentTurns?: number;
|
|
290
290
|
evidenceBudgetRatio?: number;
|
|
291
291
|
driftGuard?: 'off' | 'warn' | 'block';
|
|
292
|
+
/** @deprecated Accepted for older callers. Completion evidence is advisory. */
|
|
292
293
|
completionGate?: boolean | 'off' | 'warn' | 'block';
|
|
293
294
|
}
|
|
294
295
|
export interface DriftCheckResult {
|
|
@@ -82,11 +82,13 @@ function uniqueKinds(kinds) {
|
|
|
82
82
|
}
|
|
83
83
|
function classifyVerificationCommand(command) {
|
|
84
84
|
const normalized = command?.trim();
|
|
85
|
-
if (!normalized
|
|
85
|
+
if (!normalized)
|
|
86
86
|
return 'generic';
|
|
87
87
|
const local = (0, verification_command_1.classifyDirectVerificationCommand)(normalized);
|
|
88
88
|
if (local)
|
|
89
89
|
return local;
|
|
90
|
+
if (verification_command_1.SHELL_CONTROL_OPERATOR.test(normalized))
|
|
91
|
+
return 'generic';
|
|
90
92
|
if (/^(?:npm\s+publish|gh\s+release|git\s+tag)(?=\s|$)/u.test(normalized)) {
|
|
91
93
|
return 'release';
|
|
92
94
|
}
|
|
@@ -228,9 +230,8 @@ function matchesRequestedCheck(entry, check, workspace) {
|
|
|
228
230
|
}
|
|
229
231
|
function matchesRequestedCheckInvocation(command, cwd, check, workspace) {
|
|
230
232
|
return (command.trim() === check.command &&
|
|
231
|
-
(check.kind
|
|
232
|
-
|
|
233
|
-
: !check.cwd || (0, path_1.resolve)(workspace, cwd ?? '.') === (0, path_1.resolve)(workspace, check.cwd)));
|
|
233
|
+
(check.kind !== 'generic' || cwd !== undefined) &&
|
|
234
|
+
(0, path_1.resolve)(workspace, cwd ?? '.') === (0, path_1.resolve)(workspace, check.cwd ?? '.'));
|
|
234
235
|
}
|
|
235
236
|
function verificationKindForEntry(entry, requireLocalReceipt = false) {
|
|
236
237
|
const stored = entry.metadata?.verificationKind;
|
|
@@ -123,12 +123,9 @@ class AgentLoopV1 {
|
|
|
123
123
|
},
|
|
124
124
|
};
|
|
125
125
|
const executionChecklist = this.options.enableTaskTodos === true && (0, task_checklist_1.supportsExecutionChecklist)(context.mode);
|
|
126
|
-
const checkTaskPlanStop = executionChecklist
|
|
127
|
-
? this.options.taskContext.prepareTaskPlanStopCheck()
|
|
128
|
-
: undefined;
|
|
129
126
|
const harness = createQueryTaskContextAdapter(this.options.taskContext, decision => {
|
|
130
127
|
taskContextCompletion = decision;
|
|
131
|
-
},
|
|
128
|
+
}, executionChecklist, context.mode === 'goal', () => answeringQuestion);
|
|
132
129
|
try {
|
|
133
130
|
for await (const event of (0, query_1.query)({
|
|
134
131
|
messages,
|
|
@@ -166,16 +163,6 @@ class AgentLoopV1 {
|
|
|
166
163
|
llm: this.options.llm,
|
|
167
164
|
abortSignal: context.abortSignal,
|
|
168
165
|
streamCallbacks,
|
|
169
|
-
holdAssistantUntilCompletionCheck: () => !answeringQuestion &&
|
|
170
|
-
context.mode !== 'plan' &&
|
|
171
|
-
(context.mode === 'goal' ||
|
|
172
|
-
this.options.taskContext.requiresVerification() ||
|
|
173
|
-
(executionChecklist &&
|
|
174
|
-
(this.options.taskContext.hasTaskTodos() ||
|
|
175
|
-
!!this.options.taskContext.missingExecutionChecklist()))),
|
|
176
|
-
...(checkTaskPlanStop
|
|
177
|
-
? { checkTaskPlanStop: () => (answeringQuestion ? undefined : checkTaskPlanStop()) }
|
|
178
|
-
: {}),
|
|
179
166
|
harness,
|
|
180
167
|
input: context.input,
|
|
181
168
|
toolContext: {
|
|
@@ -223,15 +210,6 @@ class AgentLoopV1 {
|
|
|
223
210
|
break;
|
|
224
211
|
}
|
|
225
212
|
case 'complete':
|
|
226
|
-
if (executionChecklist &&
|
|
227
|
-
(event.stats?.finishReason === 'completion_gate' ||
|
|
228
|
-
event.stats?.stopDecision?.reason.code === 'task_step_blocked')) {
|
|
229
|
-
const item = context.startItem({ kind: 'message', role: 'system' });
|
|
230
|
-
context.completeItem(item, {
|
|
231
|
-
content: event.content,
|
|
232
|
-
summary: compactSummary(event.content),
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
213
|
completeEvent = event;
|
|
236
214
|
break;
|
|
237
215
|
case 'prompt_assembly':
|
|
@@ -344,7 +322,7 @@ class AgentLoopV1 {
|
|
|
344
322
|
prerequisiteFailure = 'Answer the current question without modifying the task or workspace.';
|
|
345
323
|
}
|
|
346
324
|
else if (executionChecklist && workspaceWrite) {
|
|
347
|
-
prerequisiteFailure = this.options.taskContext.
|
|
325
|
+
prerequisiteFailure = this.options.taskContext.deferredWorkspaceWriteReason({
|
|
348
326
|
path: (name === 'write_file' || name === 'edit_file') && typeof args.path === 'string'
|
|
349
327
|
? args.path
|
|
350
328
|
: undefined,
|
|
@@ -538,7 +516,7 @@ function createSnapshotToolFacade(descriptor) {
|
|
|
538
516
|
isFileEdit: () => descriptor.risk.fileEdit,
|
|
539
517
|
};
|
|
540
518
|
}
|
|
541
|
-
function createQueryTaskContextAdapter(taskContext, onCompletion,
|
|
519
|
+
function createQueryTaskContextAdapter(taskContext, onCompletion, enforceTaskTodos, requireEveryCriterion, answeringQuestion) {
|
|
542
520
|
return {
|
|
543
521
|
updateCapabilityProfile: input => structuredClone(taskContext.observeCapability(input)),
|
|
544
522
|
assembleMessages: (messages, options) => taskContext.assembleMessages(messages, {
|
|
@@ -563,16 +541,11 @@ function createQueryTaskContextAdapter(taskContext, onCompletion, planningPhase,
|
|
|
563
541
|
beforeComplete: () => {
|
|
564
542
|
if (answeringQuestion())
|
|
565
543
|
return { canComplete: true, missing: [], evidence: [] };
|
|
566
|
-
|
|
544
|
+
// Goal verification is based on its criteria. The checklist tracks model progress.
|
|
545
|
+
const decision = taskContext.auditCompletion(enforceTaskTodos && !requireEveryCriterion, requireEveryCriterion);
|
|
567
546
|
onCompletion(decision);
|
|
568
|
-
|
|
569
|
-
// Persist the unmodified audit for the PlanReceipt, while allowing the
|
|
570
|
-
// query to stop after its decision-complete plan. BUILD/AUTO will enforce
|
|
571
|
-
// the same TaskContext criteria in the following logical turn.
|
|
572
|
-
const queryDecision = planningPhase ? { ...decision, canComplete: true } : decision;
|
|
573
|
-
return structuredClone(queryDecision);
|
|
547
|
+
return structuredClone(decision);
|
|
574
548
|
},
|
|
575
|
-
asCompletionBlockedMessage: result => taskContext.completionBlockedMessage(result),
|
|
576
549
|
};
|
|
577
550
|
}
|
|
578
551
|
function compactSummary(content) {
|
|
@@ -152,6 +152,11 @@ class GoalLifecycleServiceV2 {
|
|
|
152
152
|
resources: resourceSnapshot,
|
|
153
153
|
});
|
|
154
154
|
}
|
|
155
|
+
else if (observation.requestDecision?.status === 'completed' &&
|
|
156
|
+
observation.taskContextCompletion) {
|
|
157
|
+
status = 'paused';
|
|
158
|
+
decision = goalDecision('stopped', 'pause_scope', 'goal_verification_pending', 'The model ended the turn. Goal verification is still pending.', resourceSnapshot);
|
|
159
|
+
}
|
|
155
160
|
else if (observation.continuationMode === 'manual') {
|
|
156
161
|
status = 'paused';
|
|
157
162
|
decision = goalDecision('stopped', 'pause_scope', 'goal_manual_continuation', 'Goal checkpoint saved. Manual continuation is enabled; use /goal resume for the next turn.', resourceSnapshot);
|
|
@@ -260,7 +260,11 @@ class GoalRuntimeCoordinatorV2 {
|
|
|
260
260
|
});
|
|
261
261
|
const observation = this.observeTurn(turn, requestDecision);
|
|
262
262
|
const resolution = candidate.finalizeTurn(observation);
|
|
263
|
-
|
|
263
|
+
// The Goal keeps its own resumable state. Its open criteria do not turn
|
|
264
|
+
// the model's normal reply into a refused request.
|
|
265
|
+
const stopDecision = resolution.decision?.reason.code === 'goal_verification_pending'
|
|
266
|
+
? requestDecision
|
|
267
|
+
: (resolution.decision ?? requestDecision);
|
|
264
268
|
const receipt = persist({
|
|
265
269
|
goalState: resolution.state,
|
|
266
270
|
...(stopDecision ? { stopDecision } : {}),
|
|
@@ -609,7 +613,7 @@ function defaultContinuationInput(state) {
|
|
|
609
613
|
'Continue the active Goal using saved state and receipts.',
|
|
610
614
|
`Objective: ${objective}`,
|
|
611
615
|
'Use the current TaskContext verification requirements when the user has corrected a check.',
|
|
612
|
-
'
|
|
616
|
+
'Report which checks passed and which remain unverified. End the turn when you have an answer for the user.',
|
|
613
617
|
].join('\n');
|
|
614
618
|
}
|
|
615
619
|
function deepFreeze(value) {
|