@orion-agents/orion-code 0.4.3 → 0.4.4
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 +6 -0
- package/README.md +4 -4
- package/README.zh-CN.md +4 -4
- package/dist/acp/session-updates.d.ts +4 -3
- package/dist/acp/session-updates.js +23 -2
- package/dist/acp/sessions.js +19 -6
- package/dist/commands/core-command-handlers.js +10 -22
- package/dist/commands/diagnostic-command-handlers.js +48 -52
- package/dist/commands/registry.js +1 -1
- package/dist/commands/target-command.js +49 -6
- package/dist/commands/workflow-commands.js +2 -2
- package/dist/framework/loop-budget-contract.d.ts +1 -12
- package/dist/framework/loop-budget-contract.js +1 -7
- package/dist/framework/loop-progress.d.ts +3 -7
- package/dist/framework/loop-progress.js +7 -23
- package/dist/framework/query.d.ts +12 -24
- package/dist/framework/query.js +146 -287
- package/dist/harness/assembler.js +1 -1
- package/dist/harness/context-harness.d.ts +7 -1
- package/dist/harness/context-harness.js +68 -14
- package/dist/harness/index.d.ts +1 -1
- package/dist/harness/ledger.d.ts +1 -0
- package/dist/harness/ledger.js +12 -1
- package/dist/harness/progress-controller.js +57 -35
- package/dist/harness/state.js +1 -0
- package/dist/harness/stop-controller.d.ts +0 -5
- package/dist/harness/stop-controller.js +11 -31
- package/dist/harness/task-checklist.d.ts +1 -1
- package/dist/harness/task-checklist.js +2 -5
- package/dist/harness/types.d.ts +5 -0
- package/dist/print-ui/event-stream.d.ts +5 -0
- package/dist/print-ui/event-stream.js +22 -5
- package/dist/runtime/agent-loop.d.ts +2 -1
- package/dist/runtime/agent-loop.js +20 -17
- package/dist/runtime/agent-runtime-controller.d.ts +1 -1
- package/dist/runtime/agent-runtime-controller.js +21 -11
- package/dist/runtime/goal-lifecycle-v2.d.ts +6 -4
- package/dist/runtime/goal-lifecycle-v2.js +164 -56
- package/dist/runtime/goal-runtime-coordinator.d.ts +6 -3
- package/dist/runtime/goal-runtime-coordinator.js +90 -36
- package/dist/runtime/goals/presentation.js +3 -1
- package/dist/runtime/goals/types.d.ts +1 -3
- package/dist/runtime/goals/types.js +0 -3
- package/dist/runtime/loop-budget.d.ts +0 -7
- package/dist/runtime/loop-budget.js +8 -54
- package/dist/runtime/orion-runtime-v1.js +55 -14
- package/dist/runtime/product-orion-runtime.js +6 -11
- package/dist/runtime/rsi/evaluation.js +1 -7
- package/dist/runtime/step-snapshot.d.ts +3 -1
- package/dist/runtime/step-snapshot.js +11 -1
- package/dist/runtime/subagent-thread-runtime.js +27 -5
- package/dist/runtime/subagents/production.js +0 -4
- package/dist/runtime/task-context-recovery.js +9 -2
- package/dist/runtime/task-context-service.d.ts +5 -1
- package/dist/runtime/task-context-service.js +37 -8
- package/dist/runtime/thread-admission.d.ts +2 -0
- package/dist/runtime/thread-admission.js +9 -1
- package/dist/runtime/thread-runtime.d.ts +3 -0
- package/dist/runtime/thread-runtime.js +42 -3
- package/dist/runtime/thread-ui-adapter.js +1 -11
- package/dist/runtime/tool-gateway.d.ts +2 -0
- package/dist/runtime/tool-gateway.js +4 -0
- package/dist/runtime/tool-receipt-validator.js +4 -0
- package/dist/runtime/ui-events.d.ts +3 -1
- package/dist/runtime/ui-view-model.js +62 -59
- package/dist/runtime/workspace-verification.d.ts +7 -0
- package/dist/runtime/workspace-verification.js +83 -0
- package/dist/services/config.js +3 -7
- package/dist/services/global-config.d.ts +3 -11
- package/dist/services/global-config.js +36 -26
- package/dist/services/llm.d.ts +2 -0
- package/dist/services/llm.js +13 -0
- package/dist/services/provider-diagnostics.d.ts +1 -0
- package/dist/services/provider-diagnostics.js +8 -2
- package/dist/tools/core/edit-file.js +4 -2
- package/dist/tools/core/write-file.js +5 -3
- package/dist/tools/todo.d.ts +1 -1
- package/dist/tools/todo.js +17 -1
- package/dist/tui-ui/chrome-view-model.js +15 -6
- package/docs/cli-guide.md +53 -40
- package/docs/orion.example.yaml +4 -3
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -132,7 +132,7 @@ function buildHarnessContext(state, modelId, config = {}, options = {}) {
|
|
|
132
132
|
: '';
|
|
133
133
|
coreLines.push(`- [${todo.deferredReason ? 'deferred' : todo.status}] ${compact(todo.content, 120)}${checks}`);
|
|
134
134
|
if (todo.status === 'in_progress' && todo.recovery?.consecutiveFailures) {
|
|
135
|
-
coreLines.push(` ${todo.recovery.consecutiveFailures} consecutive failed attempts, ${todo.recovery.strategies.length} distinct strategies. Last result: ${todo.recovery.lastFailure}
|
|
135
|
+
coreLines.push(` ${todo.recovery.consecutiveFailures} consecutive failed attempts, ${todo.recovery.strategies.length} recent distinct strategies. Last result: ${todo.recovery.lastFailure}.`);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
if (todos.some(todo => todo.deferredReason)) {
|
|
@@ -23,8 +23,10 @@ export declare class HarnessKernel {
|
|
|
23
23
|
private taskEpoch;
|
|
24
24
|
private taskChecklistRequired;
|
|
25
25
|
private taskChecklistTargets;
|
|
26
|
+
private verificationWorkspace?;
|
|
26
27
|
private goalTaskId?;
|
|
27
28
|
private taskTodos;
|
|
29
|
+
private reportedTaskBlocker?;
|
|
28
30
|
private readonly taskTodoReceipts;
|
|
29
31
|
private rootObjective?;
|
|
30
32
|
private activeInstruction?;
|
|
@@ -54,7 +56,7 @@ export declare class HarnessKernel {
|
|
|
54
56
|
private deferTaskTodos;
|
|
55
57
|
requiresVerification(): boolean;
|
|
56
58
|
recordTaskTodoReceipt(step: string, observation: TaskTodoObservation): void;
|
|
57
|
-
updateTaskTodos(todos: TodoItem[]): string | undefined;
|
|
59
|
+
updateTaskTodos(todos: TodoItem[], blockedReason?: string): string | undefined;
|
|
58
60
|
private taskTodoId;
|
|
59
61
|
private missingTodoEvidence;
|
|
60
62
|
updateCapabilityProfile(input: CapabilityProfileInput): HarnessState['capabilityProfile'];
|
|
@@ -73,6 +75,8 @@ export declare class HarnessKernel {
|
|
|
73
75
|
private recordTaskStepAttempt;
|
|
74
76
|
/** A crash left a write intent without enough evidence to prove its effect. */
|
|
75
77
|
noteIndeterminateWorkspaceChange(): void;
|
|
78
|
+
hasCurrentWorkspaceVerification(activeTaskOnly?: boolean): boolean;
|
|
79
|
+
observeVerificationWorkspace(fingerprint: string | null): void;
|
|
76
80
|
ingestTurn(params: Omit<CreateTurnSummaryInput, 'turn' | 'taskEpoch' | 'intent'> & {
|
|
77
81
|
intent?: IntentUpdate;
|
|
78
82
|
}): TurnSummary | undefined;
|
|
@@ -108,6 +112,8 @@ export declare class HarnessKernel {
|
|
|
108
112
|
private refreshEvidenceIndex;
|
|
109
113
|
private mergeList;
|
|
110
114
|
private resolveRecentTurnLimit;
|
|
115
|
+
/** An unbound result must be rerun without recording a filesystem mutation. */
|
|
116
|
+
private invalidateUnboundVerification;
|
|
111
117
|
private invalidateVerificationAfterWrite;
|
|
112
118
|
private autoLinkVerificationEvidence;
|
|
113
119
|
private autoLinkArtifactReadback;
|
|
@@ -5,6 +5,7 @@ exports.createHarnessKernel = createHarnessKernel;
|
|
|
5
5
|
exports.createContextHarness = createContextHarness;
|
|
6
6
|
const crypto_1 = require("crypto");
|
|
7
7
|
const path_1 = require("path");
|
|
8
|
+
const redaction_1 = require("../services/redaction");
|
|
8
9
|
const tool_serializer_1 = require("../framework/tool-serializer");
|
|
9
10
|
const verification_command_1 = require("../framework/verification-command");
|
|
10
11
|
const assembler_1 = require("./assembler");
|
|
@@ -40,6 +41,7 @@ class HarnessKernel {
|
|
|
40
41
|
const state = (0, state_1.upgradeHarnessState)(options.state, { cwd: options.cwd });
|
|
41
42
|
this.contract = state.contract;
|
|
42
43
|
this.ledger = new ledger_1.ContextLedger(state.ledger, state.workspaceRevision);
|
|
44
|
+
this.verificationWorkspace = state.verificationWorkspace;
|
|
43
45
|
this.capsule = state.capsule;
|
|
44
46
|
this.completionBlockCount = state.completionBlockCount ?? 0;
|
|
45
47
|
this.taskEpoch = state.taskEpoch ?? 1;
|
|
@@ -79,6 +81,7 @@ class HarnessKernel {
|
|
|
79
81
|
this.updatedAt = state.updatedAt;
|
|
80
82
|
}
|
|
81
83
|
updateContractFromUserInput(input, goalTaskId) {
|
|
84
|
+
this.reportedTaskBlocker = undefined;
|
|
82
85
|
if (this.config.enabled === false)
|
|
83
86
|
return;
|
|
84
87
|
if (goalTaskId && this.goalTaskId === goalTaskId && this.contract)
|
|
@@ -123,10 +126,16 @@ class HarnessKernel {
|
|
|
123
126
|
this.taskEpoch = intent.taskEpoch;
|
|
124
127
|
const changes = (0, task_checklist_1.requestedWorkspaceChanges)(input);
|
|
125
128
|
this.taskChecklistRequired || (this.taskChecklistRequired = changes.checklistRequired);
|
|
129
|
+
const previousTargets = this.taskChecklistTargets;
|
|
126
130
|
this.taskChecklistTargets = (0, task_checklist_1.workspaceChangeTargets)(this.cwd, [
|
|
127
|
-
...
|
|
131
|
+
...previousTargets,
|
|
128
132
|
...changes.paths,
|
|
129
133
|
]);
|
|
134
|
+
if (intent.kind !== 'new_task' &&
|
|
135
|
+
this.taskChecklistTargets.some(target => !previousTargets.includes(target)) &&
|
|
136
|
+
this.hasCurrentWorkspaceVerification(true)) {
|
|
137
|
+
this.invalidateUnboundVerification();
|
|
138
|
+
}
|
|
130
139
|
if (intent.rootObjectiveChanged || !this.rootObjective) {
|
|
131
140
|
this.rootObjective = this.contract.objective;
|
|
132
141
|
}
|
|
@@ -183,7 +192,6 @@ class HarnessKernel {
|
|
|
183
192
|
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.';
|
|
184
193
|
}
|
|
185
194
|
prepareTaskPlanStopCheck() {
|
|
186
|
-
const initialFailures = new Map(this.taskTodos.map(todo => [todo.id, todo.recovery?.failures ?? 0]));
|
|
187
195
|
return () => {
|
|
188
196
|
if (this.hasOnlyDeferredWork()) {
|
|
189
197
|
return {
|
|
@@ -191,16 +199,9 @@ class HarnessKernel {
|
|
|
191
199
|
message: 'The remaining checklist steps are deferred at your request. Say “continue” to resume them.',
|
|
192
200
|
};
|
|
193
201
|
}
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
!recovery ||
|
|
198
|
-
Math.min(recovery.consecutiveFailures, recovery.failures - (initialFailures.get(step.id) ?? 0)) < task_checklist_1.MAX_TASK_STEP_FAILURES)
|
|
199
|
-
return;
|
|
200
|
-
return {
|
|
201
|
-
code: 'task_step_blocked',
|
|
202
|
-
message: `Blocked at “${step.content}” after ${recovery.consecutiveFailures} failed attempts (${recovery.strategies.length} distinct strategies). Last failure: ${recovery.lastFailure}. Inspect the results before resuming.`,
|
|
203
|
-
};
|
|
202
|
+
const blocker = this.reportedTaskBlocker;
|
|
203
|
+
this.reportedTaskBlocker = undefined;
|
|
204
|
+
return blocker;
|
|
204
205
|
};
|
|
205
206
|
}
|
|
206
207
|
hasOnlyDeferredWork() {
|
|
@@ -278,7 +279,7 @@ class HarnessKernel {
|
|
|
278
279
|
}
|
|
279
280
|
this.touch();
|
|
280
281
|
}
|
|
281
|
-
updateTaskTodos(todos) {
|
|
282
|
+
updateTaskTodos(todos, blockedReason) {
|
|
282
283
|
const previousTodos = new Map(this.taskTodos.map(todo => [todo.content, todo]));
|
|
283
284
|
const next = new Map(todos.map(todo => {
|
|
284
285
|
const previous = previousTodos.get(todo.content);
|
|
@@ -310,6 +311,15 @@ class HarnessKernel {
|
|
|
310
311
|
if (missing)
|
|
311
312
|
return missing;
|
|
312
313
|
}
|
|
314
|
+
if (blockedReason !== undefined) {
|
|
315
|
+
const active = [...next.values()].find(todo => todo.status === 'in_progress');
|
|
316
|
+
if (!active || !blockedReason.trim())
|
|
317
|
+
return 'Report the blocker on an active todo.';
|
|
318
|
+
this.reportedTaskBlocker = {
|
|
319
|
+
code: 'task_step_blocked',
|
|
320
|
+
message: `Blocked at “${active.content}”. ${(0, redaction_1.redactTraceText)(blockedReason.trim())}`,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
313
323
|
this.taskTodos = [...next.values()];
|
|
314
324
|
this.touch();
|
|
315
325
|
return undefined;
|
|
@@ -491,7 +501,7 @@ class HarnessKernel {
|
|
|
491
501
|
recovery: {
|
|
492
502
|
failures: (previous?.failures ?? 0) + 1,
|
|
493
503
|
consecutiveFailures: (previous?.consecutiveFailures ?? 0) + 1,
|
|
494
|
-
strategies: [...new Set([...(previous?.strategies ?? []), strategy])].slice(-task_checklist_1.
|
|
504
|
+
strategies: [...new Set([...(previous?.strategies ?? []), strategy])].slice(-task_checklist_1.TASK_RECOVERY_STRATEGY_HISTORY_LIMIT),
|
|
495
505
|
lastFailure: params.verification
|
|
496
506
|
? `${params.verification.kind} verification failed`
|
|
497
507
|
: `${params.name} failed`,
|
|
@@ -507,6 +517,33 @@ class HarnessKernel {
|
|
|
507
517
|
this.refreshCapsule();
|
|
508
518
|
this.touch();
|
|
509
519
|
}
|
|
520
|
+
hasCurrentWorkspaceVerification(activeTaskOnly = false) {
|
|
521
|
+
const revision = this.ledger.workspaceRevision;
|
|
522
|
+
return (this.ledger
|
|
523
|
+
.getEntries()
|
|
524
|
+
.some(entry => entry.type === 'verification' &&
|
|
525
|
+
typeof entry.metadata?.toolReceiptDigest === 'string' &&
|
|
526
|
+
entry.metadata.workspaceRevision === revision &&
|
|
527
|
+
(!activeTaskOnly || entry.metadata.taskContractId === this.contract?.id)) ||
|
|
528
|
+
this.taskTodoReceipts.some(([, , evidence]) => evidence && 'kind' in evidence ? evidence.workspaceRevision === revision : false));
|
|
529
|
+
}
|
|
530
|
+
observeVerificationWorkspace(fingerprint) {
|
|
531
|
+
if (this.config.enabled === false || fingerprint === this.verificationWorkspace)
|
|
532
|
+
return;
|
|
533
|
+
const previous = this.verificationWorkspace;
|
|
534
|
+
this.verificationWorkspace = fingerprint ?? undefined;
|
|
535
|
+
if (this.hasCurrentWorkspaceVerification()) {
|
|
536
|
+
if (previous && fingerprint) {
|
|
537
|
+
this.ledger.advanceWorkspaceRevision();
|
|
538
|
+
this.invalidateVerificationAfterWrite();
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
this.invalidateUnboundVerification();
|
|
542
|
+
}
|
|
543
|
+
this.refreshCapsule();
|
|
544
|
+
}
|
|
545
|
+
this.touch();
|
|
546
|
+
}
|
|
510
547
|
ingestTurn(params) {
|
|
511
548
|
if (this.config.enabled === false)
|
|
512
549
|
return undefined;
|
|
@@ -700,6 +737,7 @@ class HarnessKernel {
|
|
|
700
737
|
contract: this.contract,
|
|
701
738
|
ledger: this.ledger.toJSON(),
|
|
702
739
|
workspaceRevision: this.ledger.workspaceRevision,
|
|
740
|
+
...(this.verificationWorkspace ? { verificationWorkspace: this.verificationWorkspace } : {}),
|
|
703
741
|
capsule: this.capsule,
|
|
704
742
|
completionBlockCount: this.completionBlockCount,
|
|
705
743
|
taskEpoch: this.taskEpoch,
|
|
@@ -749,6 +787,22 @@ class HarnessKernel {
|
|
|
749
787
|
return DEFAULT_CONFIG.maxRecentTurns;
|
|
750
788
|
return Math.max(0, Math.min(80, Math.floor(configured)));
|
|
751
789
|
}
|
|
790
|
+
/** An unbound result must be rerun without recording a filesystem mutation. */
|
|
791
|
+
invalidateUnboundVerification() {
|
|
792
|
+
this.ledger.forgetVerificationBindings();
|
|
793
|
+
for (const [index, [step, receipt, evidence]] of this.taskTodoReceipts.entries()) {
|
|
794
|
+
if (evidence &&
|
|
795
|
+
'kind' in evidence &&
|
|
796
|
+
evidence.workspaceRevision === this.ledger.workspaceRevision) {
|
|
797
|
+
this.taskTodoReceipts[index] = [
|
|
798
|
+
step,
|
|
799
|
+
receipt,
|
|
800
|
+
{ ...evidence, workspaceRevision: undefined },
|
|
801
|
+
];
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
this.invalidateVerificationAfterWrite();
|
|
805
|
+
}
|
|
752
806
|
invalidateVerificationAfterWrite() {
|
|
753
807
|
if (this.contract?.criteria) {
|
|
754
808
|
this.contract = {
|
package/dist/harness/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export { buildEvidenceIndex, bumpIncludedEvidence, estimateTokens, rankEvidence
|
|
|
11
11
|
export { classifyIntent, shouldReplaceActiveInstruction } from './intent';
|
|
12
12
|
export { summarizeHarnessStateForMeta, upgradeHarnessState } from './state';
|
|
13
13
|
export { ProgressController } from './progress-controller';
|
|
14
|
-
export { StopController
|
|
14
|
+
export { StopController } from './stop-controller';
|
|
15
15
|
export { createTurnSummary } from './turn-summary';
|
|
16
16
|
export { COMPACT_BENCHMARK_CORPUS_V1, canonicalCompactBenchmarkCorpus, compactBenchmarkCorpusHash, type CompactBenchmarkCase, } from './compact-benchmark-corpus';
|
|
17
17
|
export type { CreateTurnSummaryInput, SessionMessageLike } from './turn-summary';
|
package/dist/harness/ledger.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare class ContextLedger {
|
|
|
14
14
|
constructor(entries?: ContextLedgerEntry[], workspaceRevision?: number);
|
|
15
15
|
get workspaceRevision(): number;
|
|
16
16
|
advanceWorkspaceRevision(): void;
|
|
17
|
+
forgetVerificationBindings(): void;
|
|
17
18
|
add(input: AddLedgerEntryInput): ContextLedgerEntry;
|
|
18
19
|
recordUserRequirement(content: string): ContextLedgerEntry;
|
|
19
20
|
recordAssistantDecision(content: string): ContextLedgerEntry | null;
|
package/dist/harness/ledger.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ContextLedger = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
5
|
const verification_command_1 = require("../framework/verification-command");
|
|
6
|
+
const bash_security_1 = require("../tools/bash_security");
|
|
6
7
|
const verification_1 = require("./verification");
|
|
7
8
|
function truncate(text, max = 900) {
|
|
8
9
|
const normalized = text.replace(/\s+/g, ' ').trim();
|
|
@@ -61,6 +62,12 @@ class ContextLedger {
|
|
|
61
62
|
advanceWorkspaceRevision() {
|
|
62
63
|
this.workspaceRevisionValue++;
|
|
63
64
|
}
|
|
65
|
+
forgetVerificationBindings() {
|
|
66
|
+
this.entries = this.entries.map(entry => (entry.type === 'verification' || entry.type === 'test_result') &&
|
|
67
|
+
entry.metadata?.workspaceRevision === this.workspaceRevisionValue
|
|
68
|
+
? { ...entry, metadata: { ...entry.metadata, workspaceRevision: undefined } }
|
|
69
|
+
: entry);
|
|
70
|
+
}
|
|
64
71
|
add(input) {
|
|
65
72
|
const entry = {
|
|
66
73
|
id: (0, crypto_1.randomUUID)(),
|
|
@@ -115,6 +122,9 @@ class ContextLedger {
|
|
|
115
122
|
// Use summary when available to reduce evidence size
|
|
116
123
|
const output = params.summary || parsed.error || params.error || parsed.output || params.result;
|
|
117
124
|
const shell = params.name === 'exec_command' || params.name === 'bash';
|
|
125
|
+
// A production shell descriptor is conservatively write-capable. Its
|
|
126
|
+
// individual invocation can still be a recognized read for task progress.
|
|
127
|
+
const readOnly = params.readOnly === true || (shell && !!command && (0, bash_security_1.isReadOnlyCommand)(command));
|
|
118
128
|
const classified = shell ? (0, verification_1.classifyVerificationCommand)(command) : 'generic';
|
|
119
129
|
const verificationKind = receipt?.kind ??
|
|
120
130
|
(requireLocalReceipt && (0, verification_command_1.isLocalVerificationKind)(classified) ? 'generic' : classified);
|
|
@@ -165,7 +175,8 @@ class ContextLedger {
|
|
|
165
175
|
resultTrust: parsed.structured ? 'structured' : 'opaque',
|
|
166
176
|
error: params.error || parsed.error,
|
|
167
177
|
changedFile,
|
|
168
|
-
...(
|
|
178
|
+
...(readOnly ? { readOnly: true } : {}),
|
|
179
|
+
...(readOnly && evidenceSuccess
|
|
169
180
|
? {
|
|
170
181
|
readOnlyOutputHash: (0, crypto_1.createHash)('sha256')
|
|
171
182
|
.update(parsed.output ?? '')
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ProgressController = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
|
+
const verification_command_1 = require("../framework/verification-command");
|
|
5
6
|
const verification_1 = require("./verification");
|
|
6
7
|
function unique(values) {
|
|
7
8
|
return [
|
|
@@ -37,9 +38,17 @@ function latestToolSignature(ledger) {
|
|
|
37
38
|
error: metadataString(entry, 'error'),
|
|
38
39
|
});
|
|
39
40
|
}
|
|
41
|
+
function isVerificationObservation(entry) {
|
|
42
|
+
if (entry.type !== 'verification' && entry.type !== 'test_result')
|
|
43
|
+
return false;
|
|
44
|
+
if (entry.metadata?.readOnly !== true && !metadataString(entry, 'readOnlyOutputHash'))
|
|
45
|
+
return true;
|
|
46
|
+
const command = metadataString(entry, 'command');
|
|
47
|
+
return !!command && (0, verification_command_1.classifyDirectVerificationCommand)(command) !== undefined;
|
|
48
|
+
}
|
|
40
49
|
function buildSnapshot(params) {
|
|
41
50
|
const states = criterionStates(params.contract);
|
|
42
|
-
const checks = params.ledger.filter(entry => (entry
|
|
51
|
+
const checks = params.ledger.filter(entry => isVerificationObservation(entry) &&
|
|
43
52
|
(0, verification_1.isFreshVerification)(entry, params.workspaceRevision) &&
|
|
44
53
|
(0, verification_1.isTrustedEvidence)(entry));
|
|
45
54
|
const verificationByTarget = new Map();
|
|
@@ -51,7 +60,7 @@ function buildSnapshot(params) {
|
|
|
51
60
|
]);
|
|
52
61
|
verificationByTarget.set(target, canonicalHash([target, entry.metadata?.success]));
|
|
53
62
|
}
|
|
54
|
-
const reads = params.ledger.filter(entry => metadataString(entry, 'readOnlyOutputHash'));
|
|
63
|
+
const reads = params.ledger.filter(entry => metadataString(entry, 'readOnlyOutputHash') && !isVerificationObservation(entry));
|
|
55
64
|
const explorationObservations = reads.map(entry => canonicalHash([
|
|
56
65
|
metadataString(entry, 'toolName'),
|
|
57
66
|
metadataString(entry, 'command'),
|
|
@@ -60,7 +69,9 @@ function buildSnapshot(params) {
|
|
|
60
69
|
metadataString(entry, 'readOnlyOutputHash'),
|
|
61
70
|
]));
|
|
62
71
|
const changedFiles = unique(params.ledger.map(entry => metadataString(entry, 'changedFile')));
|
|
63
|
-
const
|
|
72
|
+
const decisionContents = params.ledger
|
|
73
|
+
.filter(entry => entry.type === 'decision')
|
|
74
|
+
.map(entry => entry.content);
|
|
64
75
|
const blockers = unique(params.ledger
|
|
65
76
|
.filter(entry => entry.type === 'blocker' || entry.type === 'risk')
|
|
66
77
|
.map(entry => entry.content)).slice(-20);
|
|
@@ -78,7 +89,8 @@ function buildSnapshot(params) {
|
|
|
78
89
|
todoStateHash: params.taskTodos?.length
|
|
79
90
|
? canonicalHash(params.taskTodos.map(todo => [todo.id, todo.status]).sort())
|
|
80
91
|
: undefined,
|
|
81
|
-
decisions,
|
|
92
|
+
decisions: unique(decisionContents.slice(-20)),
|
|
93
|
+
decisionObservations: unique(decisionContents.map(canonicalHash)),
|
|
82
94
|
blockers,
|
|
83
95
|
diagnostics,
|
|
84
96
|
toolSignature,
|
|
@@ -90,26 +102,31 @@ function difference(current, previous) {
|
|
|
90
102
|
const before = new Set(previous);
|
|
91
103
|
return current.filter(item => !before.has(item));
|
|
92
104
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
const PROGRESS_REASONS = [
|
|
106
|
+
'workspace_change',
|
|
107
|
+
'verification_change',
|
|
108
|
+
'explicit_task_state',
|
|
109
|
+
'readonly_exploration',
|
|
110
|
+
'agent_output',
|
|
111
|
+
];
|
|
112
|
+
function measureProgress(snapshot, previous, unconfirmedWorkspaceRevisions = 0) {
|
|
113
|
+
const previousStates = new Map(previous?.criterionStates.map(item => [item.id, item.status]));
|
|
114
|
+
const criterionChanges = snapshot.criterionStates
|
|
115
|
+
.filter(item => previousStates.get(item.id) !== item.status)
|
|
116
|
+
.map(item => ({ id: item.id, from: previousStates.get(item.id), to: item.status }));
|
|
117
|
+
const newChangedFiles = difference(snapshot.changedFiles, previous?.changedFiles ?? []);
|
|
118
|
+
const newDecisions = difference(snapshot.decisions, previous?.decisions ?? []);
|
|
119
|
+
const revisionChange = (snapshot.workspaceRevision ?? 0) - (previous?.workspaceRevision ?? 0);
|
|
120
|
+
const previousChecks = revisionChange === 0 ? previous?.verificationObservations : undefined;
|
|
121
|
+
const counts = {
|
|
122
|
+
workspace_change: Math.max(newChangedFiles.length, revisionChange - unconfirmedWorkspaceRevisions),
|
|
123
|
+
verification_change: difference(snapshot.verificationObservations ?? [], previousChecks ?? [])
|
|
124
|
+
.length,
|
|
125
|
+
explicit_task_state: Number(criterionChanges.length > 0 || snapshot.todoStateHash !== previous?.todoStateHash),
|
|
126
|
+
readonly_exploration: difference(snapshot.explorationObservations ?? [], previous?.explorationObservations ?? []).length,
|
|
127
|
+
agent_output: difference(snapshot.decisionObservations ?? [], previous?.decisionObservations ?? previous?.decisions.map(canonicalHash) ?? []).length,
|
|
128
|
+
};
|
|
129
|
+
return { counts, criterionChanges, newChangedFiles, newDecisions };
|
|
113
130
|
}
|
|
114
131
|
/** Harness-owned deterministic progress tracker used by all completion adapters. */
|
|
115
132
|
class ProgressController {
|
|
@@ -119,24 +136,29 @@ class ProgressController {
|
|
|
119
136
|
observe(params, baseline = this.state) {
|
|
120
137
|
const snapshot = buildSnapshot(params);
|
|
121
138
|
const previous = baseline.snapshot;
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
|
|
139
|
+
const progress = measureProgress(snapshot, previous, params.unconfirmedWorkspaceRevisions);
|
|
140
|
+
const reason = PROGRESS_REASONS.find(kind => progress.counts[kind] > 0) ?? 'no_effect';
|
|
141
|
+
// The caller may need a turn-wide delta for lifecycle decisions. Counters
|
|
142
|
+
// still start at the last observation, so the final audit cannot recount
|
|
143
|
+
// changes that were already seen by an intermediate completion audit.
|
|
144
|
+
const counted = baseline === this.state
|
|
145
|
+
? progress
|
|
146
|
+
: measureProgress(snapshot, this.state.snapshot, params.unconfirmedWorkspaceRevisions);
|
|
147
|
+
const progressCountedByReason = { ...counted.counts };
|
|
148
|
+
for (const kind of PROGRESS_REASONS) {
|
|
149
|
+
progressCountedByReason[kind] += this.state.progressCountedByReason?.[kind] ?? 0;
|
|
150
|
+
}
|
|
129
151
|
const changed = reason !== 'no_effect';
|
|
130
152
|
const repeatedSignatureCount = previous && !changed ? (baseline.lastDelta?.repeatedSignatureCount ?? 0) + 1 : 0;
|
|
131
153
|
const delta = {
|
|
132
154
|
schemaVersion: 1,
|
|
133
155
|
changed,
|
|
134
156
|
reason,
|
|
135
|
-
criterionChanges,
|
|
157
|
+
criterionChanges: progress.criterionChanges,
|
|
136
158
|
newEvidenceRefs: difference(snapshot.evidenceRefs, previous?.evidenceRefs ?? []),
|
|
137
|
-
newChangedFiles,
|
|
159
|
+
newChangedFiles: progress.newChangedFiles,
|
|
138
160
|
newExploredPaths: difference(snapshot.exploredPaths ?? [], previous?.exploredPaths ?? []),
|
|
139
|
-
newDecisions,
|
|
161
|
+
newDecisions: progress.newDecisions,
|
|
140
162
|
newBlockers: difference(snapshot.blockers, previous?.blockers ?? []),
|
|
141
163
|
newDiagnostics: difference(snapshot.diagnostics, previous?.diagnostics ?? []),
|
|
142
164
|
toolSignature: snapshot.toolSignature,
|
|
@@ -144,7 +166,7 @@ class ProgressController {
|
|
|
144
166
|
repeatedSignatureCount,
|
|
145
167
|
recordedAt: params.now ?? Date.now(),
|
|
146
168
|
};
|
|
147
|
-
this.state = { schemaVersion: 1, snapshot, lastDelta: delta };
|
|
169
|
+
this.state = { schemaVersion: 1, snapshot, lastDelta: delta, progressCountedByReason };
|
|
148
170
|
return structuredClone(delta);
|
|
149
171
|
}
|
|
150
172
|
toJSON() {
|
package/dist/harness/state.js
CHANGED
|
@@ -81,6 +81,7 @@ function upgradeHarnessState(state, options = {}) {
|
|
|
81
81
|
contract,
|
|
82
82
|
ledger,
|
|
83
83
|
workspaceRevision: state?.workspaceRevision,
|
|
84
|
+
...(state?.verificationWorkspace ? { verificationWorkspace: state.verificationWorkspace } : {}),
|
|
84
85
|
capsule,
|
|
85
86
|
completionBlockCount: state?.completionBlockCount ?? 0,
|
|
86
87
|
taskEpoch,
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { type StopDecision } from '../framework/stop-decision';
|
|
2
2
|
import type { CompletionGateResult, ProgressDelta } from './types';
|
|
3
|
-
export interface StopControllerOptions {
|
|
4
|
-
noProgressThreshold?: number;
|
|
5
|
-
}
|
|
6
3
|
/**
|
|
7
4
|
* Harness-owned completion boundary. It never converts a missing receipt or
|
|
8
5
|
* repeated state into task completion; callers may continue or persist a pause.
|
|
9
6
|
*/
|
|
10
7
|
export declare class StopController {
|
|
11
|
-
private readonly noProgressThreshold;
|
|
12
|
-
constructor(options?: StopControllerOptions);
|
|
13
8
|
decideCompletion(gate: CompletionGateResult, progress: ProgressDelta): StopDecision;
|
|
14
9
|
}
|
|
15
10
|
//# sourceMappingURL=stop-controller.d.ts.map
|
|
@@ -7,9 +7,6 @@ const stop_decision_1 = require("../framework/stop-decision");
|
|
|
7
7
|
* repeated state into task completion; callers may continue or persist a pause.
|
|
8
8
|
*/
|
|
9
9
|
class StopController {
|
|
10
|
-
constructor(options = {}) {
|
|
11
|
-
this.noProgressThreshold = Math.max(2, Math.floor(options.noProgressThreshold ?? 3));
|
|
12
|
-
}
|
|
13
10
|
decideCompletion(gate, progress) {
|
|
14
11
|
const criterionStates = (gate.criterionResults ?? []).map(item => ({
|
|
15
12
|
id: item.criterionId,
|
|
@@ -37,44 +34,27 @@ class StopController {
|
|
|
37
34
|
resumable: false,
|
|
38
35
|
});
|
|
39
36
|
}
|
|
40
|
-
const noProgress = progress.repeatedSignatureCount >= this.noProgressThreshold;
|
|
41
37
|
return (0, stop_decision_1.createStopDecision)({
|
|
42
38
|
scope: 'request',
|
|
43
39
|
status: 'stopped',
|
|
44
|
-
disposition:
|
|
40
|
+
disposition: 'resume_allowed',
|
|
45
41
|
reason: {
|
|
46
|
-
code:
|
|
47
|
-
message:
|
|
48
|
-
? `No observable progress for ${progress.repeatedSignatureCount} repeated completion states.`
|
|
49
|
-
: gate.missing.join('; ') || 'Required criterion evidence is missing.',
|
|
42
|
+
code: 'completion_gate',
|
|
43
|
+
message: gate.missing.join('; ') || 'Required criterion evidence is missing.',
|
|
50
44
|
},
|
|
51
45
|
evidence: evidenceRefs.map(ref => ({
|
|
52
46
|
kind: 'verification',
|
|
53
47
|
source: ref,
|
|
54
48
|
detail: 'Bound criterion evidence',
|
|
55
49
|
})),
|
|
56
|
-
nextActions:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
{ kind: 'resume', label: 'Resume after changing the strategy', command: '继续' },
|
|
65
|
-
]
|
|
66
|
-
: [
|
|
67
|
-
{
|
|
68
|
-
kind: 'continue',
|
|
69
|
-
label: 'Run the missing verification and continue',
|
|
70
|
-
command: '继续',
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
kind: 'inspect',
|
|
74
|
-
label: 'Inspect missing criterion evidence',
|
|
75
|
-
command: '/harness explain',
|
|
76
|
-
},
|
|
77
|
-
],
|
|
50
|
+
nextActions: [
|
|
51
|
+
{ kind: 'continue', label: 'Run the missing verification and continue', command: '继续' },
|
|
52
|
+
{
|
|
53
|
+
kind: 'inspect',
|
|
54
|
+
label: 'Inspect missing criterion evidence',
|
|
55
|
+
command: '/harness explain',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
78
58
|
resources: {},
|
|
79
59
|
criterionStates,
|
|
80
60
|
progressDelta: progress,
|
|
@@ -2,7 +2,7 @@ import type { TodoItem } from '../framework/tool-state';
|
|
|
2
2
|
import type { TaskTodoItem } from './types';
|
|
3
3
|
export declare const TASK_CHECKLIST_REQUIRED = "Create an execution checklist with todo_write before changing the workspace. Include distinct implementation and verification steps. You can inspect files first.";
|
|
4
4
|
export declare function supportsExecutionChecklist(mode: string): boolean;
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const TASK_RECOVERY_STRATEGY_HISTORY_LIMIT = 4;
|
|
6
6
|
/** Deferral is applied from explicit user input. Tool arguments cannot defer work. */
|
|
7
7
|
export declare function requestedTaskDeferral(input: string): 'first' | 'current' | 'all' | undefined;
|
|
8
8
|
export declare function taskTodoDisplayStatus(todo: Omit<TaskTodoItem, 'id'>): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.TASK_RECOVERY_STRATEGY_HISTORY_LIMIT = exports.TASK_CHECKLIST_REQUIRED = void 0;
|
|
4
4
|
exports.supportsExecutionChecklist = supportsExecutionChecklist;
|
|
5
5
|
exports.requestedTaskDeferral = requestedTaskDeferral;
|
|
6
6
|
exports.taskTodoDisplayStatus = taskTodoDisplayStatus;
|
|
@@ -20,7 +20,7 @@ exports.TASK_CHECKLIST_REQUIRED = 'Create an execution checklist with todo_write
|
|
|
20
20
|
function supportsExecutionChecklist(mode) {
|
|
21
21
|
return mode === 'build' || mode === 'auto' || mode === 'goal';
|
|
22
22
|
}
|
|
23
|
-
exports.
|
|
23
|
+
exports.TASK_RECOVERY_STRATEGY_HISTORY_LIMIT = 4;
|
|
24
24
|
/** Deferral is applied from explicit user input. Tool arguments cannot defer work. */
|
|
25
25
|
function requestedTaskDeferral(input) {
|
|
26
26
|
const text = input.trim();
|
|
@@ -39,9 +39,6 @@ function requestedTaskDeferral(input) {
|
|
|
39
39
|
function taskTodoDisplayStatus(todo) {
|
|
40
40
|
if (todo.deferredReason)
|
|
41
41
|
return 'deferred';
|
|
42
|
-
if (todo.status === 'in_progress' &&
|
|
43
|
-
(todo.recovery?.consecutiveFailures ?? 0) >= exports.MAX_TASK_STEP_FAILURES)
|
|
44
|
-
return 'blocked';
|
|
45
42
|
return todo.status;
|
|
46
43
|
}
|
|
47
44
|
function modificationClauses(instruction) {
|
package/dist/harness/types.d.ts
CHANGED
|
@@ -245,6 +245,7 @@ export interface HarnessState {
|
|
|
245
245
|
ledger: ContextLedgerEntry[];
|
|
246
246
|
/** Monotonic revision of observed workspace writes, retained independently of the ledger. */
|
|
247
247
|
workspaceRevision?: number;
|
|
248
|
+
verificationWorkspace?: string;
|
|
248
249
|
capsule?: ContextCapsule;
|
|
249
250
|
completionBlockCount?: number;
|
|
250
251
|
taskEpoch?: number;
|
|
@@ -325,6 +326,7 @@ export interface ProgressSnapshot {
|
|
|
325
326
|
verificationObservations?: string[];
|
|
326
327
|
exploredPaths?: string[];
|
|
327
328
|
explorationObservations?: string[];
|
|
329
|
+
decisionObservations?: string[];
|
|
328
330
|
todoStateHash?: string;
|
|
329
331
|
decisions: string[];
|
|
330
332
|
blockers: string[];
|
|
@@ -333,6 +335,7 @@ export interface ProgressSnapshot {
|
|
|
333
335
|
workspaceStateHash: string;
|
|
334
336
|
}
|
|
335
337
|
export type ProgressReason = 'workspace_change' | 'verification_change' | 'explicit_task_state' | 'readonly_exploration' | 'agent_output' | 'no_effect';
|
|
338
|
+
export type ProgressCounts = Record<Exclude<ProgressReason, 'no_effect'>, number>;
|
|
336
339
|
export interface ProgressDelta {
|
|
337
340
|
schemaVersion: 1;
|
|
338
341
|
changed: boolean;
|
|
@@ -357,6 +360,8 @@ export interface HarnessProgressState {
|
|
|
357
360
|
schemaVersion: 1;
|
|
358
361
|
snapshot?: ProgressSnapshot;
|
|
359
362
|
lastDelta?: ProgressDelta;
|
|
363
|
+
/** Cumulative observations by category since progress counting began for this thread. */
|
|
364
|
+
progressCountedByReason?: ProgressCounts;
|
|
360
365
|
}
|
|
361
366
|
export interface CapabilityProfile {
|
|
362
367
|
schemaVersion: 1;
|
|
@@ -10,7 +10,12 @@ declare const EXIT_CODES: {
|
|
|
10
10
|
export interface PrintOutcome {
|
|
11
11
|
status: keyof typeof EXIT_CODES;
|
|
12
12
|
reasonCode: string;
|
|
13
|
+
reasonMessage?: string;
|
|
13
14
|
resumable: boolean;
|
|
15
|
+
metrics?: {
|
|
16
|
+
llmRequests: number;
|
|
17
|
+
toolCalls: number;
|
|
18
|
+
};
|
|
14
19
|
}
|
|
15
20
|
/** Versioned shell protocol. Internal receipts, tool arguments and reasoning stay in Runtime. */
|
|
16
21
|
export declare class PrintEventStreamV1 {
|