@orion-agents/orion-code 0.4.3 → 0.4.5
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 +14 -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/core/tool-artifacts.js +17 -4
- 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 +294 -301
- package/dist/framework/tool-state.d.ts +4 -0
- package/dist/harness/assembler.js +1 -1
- package/dist/harness/context-harness.d.ts +12 -2
- package/dist/harness/context-harness.js +288 -60
- package/dist/harness/contract.js +3 -1
- package/dist/harness/drift-guard.js +67 -17
- package/dist/harness/goal-verification.d.ts +11 -0
- package/dist/harness/goal-verification.js +62 -0
- package/dist/harness/index.d.ts +1 -1
- package/dist/harness/ledger.d.ts +1 -0
- package/dist/harness/ledger.js +28 -4
- package/dist/harness/progress-controller.js +57 -35
- package/dist/harness/state.js +4 -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 +12 -2
- package/dist/harness/task-checklist.js +50 -9
- package/dist/harness/types.d.ts +15 -0
- package/dist/harness/verification.d.ts +11 -1
- package/dist/harness/verification.js +47 -2
- 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 +23 -17
- package/dist/runtime/agent-runtime-controller.d.ts +1 -1
- package/dist/runtime/agent-runtime-controller.js +21 -11
- package/dist/runtime/batch-read-service.js +21 -4
- 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 +91 -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 +30 -13
- 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 +30 -7
- package/dist/runtime/task-context-service.d.ts +7 -1
- package/dist/runtime/task-context-service.js +40 -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 +98 -0
- package/dist/services/chat-completion-sse.d.ts +9 -0
- package/dist/services/chat-completion-sse.js +50 -0
- package/dist/services/compact/summary-generator.d.ts +1 -1
- package/dist/services/compact/summary-generator.js +12 -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 +3 -1
- package/dist/services/llm.js +171 -285
- package/dist/services/provider-diagnostics.d.ts +2 -1
- package/dist/services/provider-diagnostics.js +15 -4
- package/dist/services/provider-resilience/error-classifier.d.ts +3 -0
- package/dist/services/provider-resilience/error-classifier.js +14 -0
- package/dist/tools/core/common.d.ts +0 -11
- package/dist/tools/core/common.js +0 -18
- package/dist/tools/core/edit-file.js +61 -88
- package/dist/tools/core/exec-command.js +61 -80
- package/dist/tools/core/grep.js +84 -24
- package/dist/tools/core/read-file.js +3 -2
- package/dist/tools/core/write-file.js +5 -3
- package/dist/tools/todo.d.ts +2 -2
- package/dist/tools/todo.js +29 -10
- package/dist/tui-ui/chrome-view-model.js +15 -6
- package/dist/utils/utf8.d.ts +6 -0
- package/dist/utils/utf8.js +14 -0
- package/docs/cli-guide.md +58 -40
- package/docs/orion.example.yaml +4 -3
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -11,6 +11,10 @@ export interface TodoItem {
|
|
|
11
11
|
activeForm: string;
|
|
12
12
|
verification?: LocalVerificationKind[];
|
|
13
13
|
}
|
|
14
|
+
export interface TodoWriteAdjustment {
|
|
15
|
+
todos: TodoItem[];
|
|
16
|
+
warnings: string[];
|
|
17
|
+
}
|
|
14
18
|
export interface ToolState {
|
|
15
19
|
todos: TodoItem[];
|
|
16
20
|
/** v0.2.24 — Goal target mode (set by create_goal / update_goal) */
|
|
@@ -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)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LLMResponse, Message } from '../services/llm';
|
|
2
|
-
import type { TodoItem } from '../framework/tool-state';
|
|
2
|
+
import type { TodoItem, TodoWriteAdjustment } from '../framework/tool-state';
|
|
3
3
|
import { type PromptAssemblyOptions } from './assembler';
|
|
4
4
|
import { type CreateTurnSummaryInput } from './turn-summary';
|
|
5
5
|
import type { CompletionGateResult, CapabilityProfileInput, ContextCapsule, DriftCheckResult, HarnessConfig, HarnessProgressState, HarnessState, IntentUpdate, ProgressDelta, TaskPlanStop, TaskTodoObservation, TaskWorkspaceAction, ToolResultObservation, TurnSummary } from './types';
|
|
@@ -23,8 +23,11 @@ export declare class HarnessKernel {
|
|
|
23
23
|
private taskEpoch;
|
|
24
24
|
private taskChecklistRequired;
|
|
25
25
|
private taskChecklistTargets;
|
|
26
|
+
private verificationWorkspace?;
|
|
26
27
|
private goalTaskId?;
|
|
28
|
+
private goalVerificationBlocker?;
|
|
27
29
|
private taskTodos;
|
|
30
|
+
private reportedTaskBlocker?;
|
|
28
31
|
private readonly taskTodoReceipts;
|
|
29
32
|
private rootObjective?;
|
|
30
33
|
private activeInstruction?;
|
|
@@ -45,6 +48,7 @@ export declare class HarnessKernel {
|
|
|
45
48
|
constructor(options: ContextHarnessOptions);
|
|
46
49
|
updateContractFromUserInput(input: string, goalTaskId?: string): IntentUpdate | undefined;
|
|
47
50
|
classifyIntent(input: string): IntentUpdate;
|
|
51
|
+
observeGoalSteering(input: string, goalId: string): void;
|
|
48
52
|
activeTaskTodo(): string | undefined;
|
|
49
53
|
hasTaskTodos(): boolean;
|
|
50
54
|
missingExecutionChecklist(action?: TaskWorkspaceAction): string | undefined;
|
|
@@ -54,9 +58,11 @@ export declare class HarnessKernel {
|
|
|
54
58
|
private deferTaskTodos;
|
|
55
59
|
requiresVerification(): boolean;
|
|
56
60
|
recordTaskTodoReceipt(step: string, observation: TaskTodoObservation): void;
|
|
57
|
-
updateTaskTodos(todos: TodoItem[]): string | undefined;
|
|
61
|
+
updateTaskTodos(todos: TodoItem[], blockedReason?: string): TodoWriteAdjustment | string | undefined;
|
|
58
62
|
private taskTodoId;
|
|
59
63
|
private missingTodoEvidence;
|
|
64
|
+
private formatTodoCheck;
|
|
65
|
+
private diffTodoCheckHint;
|
|
60
66
|
updateCapabilityProfile(input: CapabilityProfileInput): HarnessState['capabilityProfile'];
|
|
61
67
|
assembleMessages(messages: Message[], options?: PromptAssemblyOptions): Message[];
|
|
62
68
|
recordAssistantResponse(response: LLMResponse): void;
|
|
@@ -73,6 +79,8 @@ export declare class HarnessKernel {
|
|
|
73
79
|
private recordTaskStepAttempt;
|
|
74
80
|
/** A crash left a write intent without enough evidence to prove its effect. */
|
|
75
81
|
noteIndeterminateWorkspaceChange(): void;
|
|
82
|
+
hasCurrentWorkspaceVerification(activeTaskOnly?: boolean): boolean;
|
|
83
|
+
observeVerificationWorkspace(fingerprint: string | null): void;
|
|
76
84
|
ingestTurn(params: Omit<CreateTurnSummaryInput, 'turn' | 'taskEpoch' | 'intent'> & {
|
|
77
85
|
intent?: IntentUpdate;
|
|
78
86
|
}): TurnSummary | undefined;
|
|
@@ -108,6 +116,8 @@ export declare class HarnessKernel {
|
|
|
108
116
|
private refreshEvidenceIndex;
|
|
109
117
|
private mergeList;
|
|
110
118
|
private resolveRecentTurnLimit;
|
|
119
|
+
/** An unbound result must be rerun without recording a filesystem mutation. */
|
|
120
|
+
private invalidateUnboundVerification;
|
|
111
121
|
private invalidateVerificationAfterWrite;
|
|
112
122
|
private autoLinkVerificationEvidence;
|
|
113
123
|
private autoLinkArtifactReadback;
|
|
@@ -5,7 +5,9 @@ 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");
|
|
10
|
+
const stop_decision_1 = require("../framework/stop-decision");
|
|
9
11
|
const verification_command_1 = require("../framework/verification-command");
|
|
10
12
|
const assembler_1 = require("./assembler");
|
|
11
13
|
const capability_profile_1 = require("./capability-profile");
|
|
@@ -13,6 +15,7 @@ const capsule_1 = require("./capsule");
|
|
|
13
15
|
const contract_1 = require("./contract");
|
|
14
16
|
const drift_guard_1 = require("./drift-guard");
|
|
15
17
|
const evidence_1 = require("./evidence");
|
|
18
|
+
const goal_verification_1 = require("./goal-verification");
|
|
16
19
|
const intent_1 = require("./intent");
|
|
17
20
|
const ledger_1 = require("./ledger");
|
|
18
21
|
const progress_controller_1 = require("./progress-controller");
|
|
@@ -40,10 +43,12 @@ class HarnessKernel {
|
|
|
40
43
|
const state = (0, state_1.upgradeHarnessState)(options.state, { cwd: options.cwd });
|
|
41
44
|
this.contract = state.contract;
|
|
42
45
|
this.ledger = new ledger_1.ContextLedger(state.ledger, state.workspaceRevision);
|
|
46
|
+
this.verificationWorkspace = state.verificationWorkspace;
|
|
43
47
|
this.capsule = state.capsule;
|
|
44
48
|
this.completionBlockCount = state.completionBlockCount ?? 0;
|
|
45
49
|
this.taskEpoch = state.taskEpoch ?? 1;
|
|
46
50
|
this.goalTaskId = state.goalTaskId;
|
|
51
|
+
this.goalVerificationBlocker = state.goalVerificationBlocker;
|
|
47
52
|
const restoredChanges = (0, task_checklist_1.requestedWorkspaceChanges)(state.activeInstruction ?? this.contract?.userIntent ?? '');
|
|
48
53
|
this.taskChecklistRequired = state.taskChecklistRequired ?? restoredChanges.checklistRequired;
|
|
49
54
|
this.taskChecklistTargets =
|
|
@@ -79,6 +84,7 @@ class HarnessKernel {
|
|
|
79
84
|
this.updatedAt = state.updatedAt;
|
|
80
85
|
}
|
|
81
86
|
updateContractFromUserInput(input, goalTaskId) {
|
|
87
|
+
this.reportedTaskBlocker = undefined;
|
|
82
88
|
if (this.config.enabled === false)
|
|
83
89
|
return;
|
|
84
90
|
if (goalTaskId && this.goalTaskId === goalTaskId && this.contract)
|
|
@@ -111,6 +117,7 @@ class HarnessKernel {
|
|
|
111
117
|
this.taskChecklistTargets = [];
|
|
112
118
|
this.taskTodos = [];
|
|
113
119
|
this.taskTodoReceipts.length = 0;
|
|
120
|
+
this.goalVerificationBlocker = undefined;
|
|
114
121
|
this.completionBlockCount = 0;
|
|
115
122
|
this.activeConstraints = [];
|
|
116
123
|
this.nonGoals = [];
|
|
@@ -123,10 +130,16 @@ class HarnessKernel {
|
|
|
123
130
|
this.taskEpoch = intent.taskEpoch;
|
|
124
131
|
const changes = (0, task_checklist_1.requestedWorkspaceChanges)(input);
|
|
125
132
|
this.taskChecklistRequired || (this.taskChecklistRequired = changes.checklistRequired);
|
|
133
|
+
const previousTargets = this.taskChecklistTargets;
|
|
126
134
|
this.taskChecklistTargets = (0, task_checklist_1.workspaceChangeTargets)(this.cwd, [
|
|
127
|
-
...
|
|
135
|
+
...previousTargets,
|
|
128
136
|
...changes.paths,
|
|
129
137
|
]);
|
|
138
|
+
if (intent.kind !== 'new_task' &&
|
|
139
|
+
this.taskChecklistTargets.some(target => !previousTargets.includes(target)) &&
|
|
140
|
+
this.hasCurrentWorkspaceVerification(true)) {
|
|
141
|
+
this.invalidateUnboundVerification();
|
|
142
|
+
}
|
|
130
143
|
if (intent.rootObjectiveChanged || !this.rootObjective) {
|
|
131
144
|
this.rootObjective = this.contract.objective;
|
|
132
145
|
}
|
|
@@ -145,6 +158,60 @@ class HarnessKernel {
|
|
|
145
158
|
classifyIntent(input) {
|
|
146
159
|
return (0, intent_1.classifyIntent)(input, this.toJSON());
|
|
147
160
|
}
|
|
161
|
+
observeGoalSteering(input, goalId) {
|
|
162
|
+
const contract = this.contract;
|
|
163
|
+
if (!contract || this.goalTaskId !== goalId || this.config.enabled === false)
|
|
164
|
+
return;
|
|
165
|
+
const correction = (0, goal_verification_1.goalVerificationCorrection)(contract, input);
|
|
166
|
+
if (!correction)
|
|
167
|
+
return;
|
|
168
|
+
this.ledger.recordUserRequirement(input);
|
|
169
|
+
if ('blocker' in correction) {
|
|
170
|
+
this.goalVerificationBlocker = correction.blocker;
|
|
171
|
+
this.touch();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const { previous, next } = correction;
|
|
175
|
+
const rewrite = (statement) => (0, verification_1.replaceRequestedCheck)(statement, previous, next, contract.allowedScope.cwd);
|
|
176
|
+
const priorEvidence = new Set(this.ledger
|
|
177
|
+
.getEntries()
|
|
178
|
+
.filter(entry => (0, verification_1.matchesRequestedCheck)(entry, previous, contract.allowedScope.cwd))
|
|
179
|
+
.flatMap(entry => [entry.id, `ledger:${entry.id}`]));
|
|
180
|
+
this.contract = {
|
|
181
|
+
...contract,
|
|
182
|
+
objective: rewrite(contract.objective),
|
|
183
|
+
userIntent: input.trim(),
|
|
184
|
+
requirements: contract.requirements.map(rewrite),
|
|
185
|
+
successCriteria: contract.successCriteria.map(rewrite),
|
|
186
|
+
criteria: contract.criteria?.map(item => {
|
|
187
|
+
const statement = rewrite(item.statement);
|
|
188
|
+
if (statement === item.statement)
|
|
189
|
+
return item;
|
|
190
|
+
return {
|
|
191
|
+
...item,
|
|
192
|
+
statement,
|
|
193
|
+
status: 'pending',
|
|
194
|
+
waiver: undefined,
|
|
195
|
+
evidenceRefs: item.evidenceRefs.filter(ref => !priorEvidence.has(ref)),
|
|
196
|
+
};
|
|
197
|
+
}),
|
|
198
|
+
updatedAt: Math.max(Date.now(), contract.updatedAt + 1),
|
|
199
|
+
};
|
|
200
|
+
this.taskTodos = this.taskTodos.map(todo => {
|
|
201
|
+
const content = rewrite(todo.content);
|
|
202
|
+
if (content === todo.content)
|
|
203
|
+
return todo;
|
|
204
|
+
return {
|
|
205
|
+
...todo,
|
|
206
|
+
content,
|
|
207
|
+
status: todo.status === 'completed' ? 'pending' : todo.status,
|
|
208
|
+
};
|
|
209
|
+
});
|
|
210
|
+
this.activeInstruction = input.trim();
|
|
211
|
+
this.goalVerificationBlocker = undefined;
|
|
212
|
+
this.refreshCapsule();
|
|
213
|
+
this.touch();
|
|
214
|
+
}
|
|
148
215
|
activeTaskTodo() {
|
|
149
216
|
return this.taskTodos.find(todo => todo.status === 'in_progress' && !todo.deferredReason)?.id;
|
|
150
217
|
}
|
|
@@ -167,7 +234,8 @@ class HarnessKernel {
|
|
|
167
234
|
checkDeferredWorkspaceAction(action) {
|
|
168
235
|
const target = action.path ? (0, verification_1.workspaceArtifactPath)(this.cwd, action.path) : undefined;
|
|
169
236
|
if (target) {
|
|
170
|
-
const covering = this.taskTodos.filter(todo => (0, task_checklist_1.
|
|
237
|
+
const covering = this.taskTodos.filter(todo => (0, task_checklist_1.todoFileTargets)(todo.content, this.cwd, this.taskChecklistTargets).some(scope => scope.candidates.includes(target) ||
|
|
238
|
+
(scope.unscopedBasename && (0, path_1.basename)(target) === scope.declared)));
|
|
171
239
|
return covering.length > 0 && covering.every(todo => todo.deferredReason)
|
|
172
240
|
? `The user deferred the checklist step that changes ${target}.`
|
|
173
241
|
: undefined;
|
|
@@ -183,7 +251,6 @@ class HarnessKernel {
|
|
|
183
251
|
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
252
|
}
|
|
185
253
|
prepareTaskPlanStopCheck() {
|
|
186
|
-
const initialFailures = new Map(this.taskTodos.map(todo => [todo.id, todo.recovery?.failures ?? 0]));
|
|
187
254
|
return () => {
|
|
188
255
|
if (this.hasOnlyDeferredWork()) {
|
|
189
256
|
return {
|
|
@@ -191,16 +258,9 @@ class HarnessKernel {
|
|
|
191
258
|
message: 'The remaining checklist steps are deferred at your request. Say “continue” to resume them.',
|
|
192
259
|
};
|
|
193
260
|
}
|
|
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
|
-
};
|
|
261
|
+
const blocker = this.reportedTaskBlocker;
|
|
262
|
+
this.reportedTaskBlocker = undefined;
|
|
263
|
+
return blocker;
|
|
204
264
|
};
|
|
205
265
|
}
|
|
206
266
|
hasOnlyDeferredWork() {
|
|
@@ -239,10 +299,9 @@ class HarnessKernel {
|
|
|
239
299
|
if (this.taskTodoReceipts.some(([, recordedDigest]) => recordedDigest === digest))
|
|
240
300
|
return;
|
|
241
301
|
const required = todo.verification ?? [];
|
|
302
|
+
const implementation = (0, task_checklist_1.isImplementationTodo)(todo);
|
|
242
303
|
let evidence;
|
|
243
|
-
if (required.
|
|
244
|
-
if (!kind || !required.includes(kind))
|
|
245
|
-
return;
|
|
304
|
+
if (kind && required.includes(kind)) {
|
|
246
305
|
const requested = todoChecks(todo.content).filter(check => check.kind === kind);
|
|
247
306
|
if (requested.length &&
|
|
248
307
|
!requested.some(check => matchesTodoCheck(observation, check, this.cwd)))
|
|
@@ -254,16 +313,17 @@ class HarnessKernel {
|
|
|
254
313
|
...(requested.length ? { command, cwd: (0, path_1.resolve)(this.cwd, cwd ?? '.') } : {}),
|
|
255
314
|
};
|
|
256
315
|
}
|
|
257
|
-
else if (
|
|
258
|
-
if (!passed || !changedFile)
|
|
259
|
-
return;
|
|
316
|
+
else if (passed && changedFile && implementation) {
|
|
260
317
|
const path = (0, verification_1.workspaceArtifactPath)(this.cwd, changedFile);
|
|
261
|
-
const targets = (0, task_checklist_1.
|
|
262
|
-
if (!path ||
|
|
318
|
+
const targets = (0, task_checklist_1.todoFileTargets)(todo.content, this.cwd, this.taskChecklistTargets);
|
|
319
|
+
if (!path ||
|
|
320
|
+
(targets.length &&
|
|
321
|
+
!targets.some(target => target.candidates.includes(path) ||
|
|
322
|
+
(target.unscopedBasename && (0, path_1.basename)(path) === target.declared))))
|
|
263
323
|
return;
|
|
264
324
|
evidence = { changedFile: path };
|
|
265
325
|
}
|
|
266
|
-
else if (!passed) {
|
|
326
|
+
else if (required.length || implementation || !passed) {
|
|
267
327
|
return;
|
|
268
328
|
}
|
|
269
329
|
const index = this.taskTodoReceipts.findIndex(([name, , previous]) => name === step && sameTodoEvidenceTarget(previous, evidence));
|
|
@@ -278,41 +338,79 @@ class HarnessKernel {
|
|
|
278
338
|
}
|
|
279
339
|
this.touch();
|
|
280
340
|
}
|
|
281
|
-
updateTaskTodos(todos) {
|
|
282
|
-
const
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
todo.content,
|
|
287
|
-
withTodoVerification(todo, previous?.id ?? this.taskTodoId(todo.content), previous),
|
|
288
|
-
];
|
|
289
|
-
}));
|
|
290
|
-
if (next.size !== todos.length)
|
|
341
|
+
updateTaskTodos(todos, blockedReason) {
|
|
342
|
+
const requested = new Map(todos.map(todo => [todo.content, todo]));
|
|
343
|
+
const originalNames = new Set(this.taskTodos.map(todo => todo.content));
|
|
344
|
+
const previousByRequest = new Map();
|
|
345
|
+
if (requested.size !== todos.length)
|
|
291
346
|
return 'Todo descriptions must be unique.';
|
|
292
|
-
if (this.taskTodos.some(todo => todo.deferredReason) &&
|
|
347
|
+
if (this.taskTodos.some(todo => todo.deferredReason) && todos.length > this.taskTodos.length) {
|
|
293
348
|
return 'The user deferred part of the checklist. Wait for their continuation before adding steps.';
|
|
294
349
|
}
|
|
295
350
|
for (const previous of this.taskTodos) {
|
|
296
|
-
|
|
351
|
+
let replacement = requested.get(previous.content);
|
|
352
|
+
if (!replacement && previous.status !== 'completed' && !previous.deferredReason) {
|
|
353
|
+
const refinements = todos.filter(todo => !originalNames.has(todo.content) &&
|
|
354
|
+
!previousByRequest.has(todo.content) &&
|
|
355
|
+
(0, task_checklist_1.clarifiesTodoFileTarget)(previous, todo, this.cwd, this.taskChecklistTargets));
|
|
356
|
+
if (refinements.length === 1)
|
|
357
|
+
replacement = refinements[0];
|
|
358
|
+
}
|
|
297
359
|
if (!replacement)
|
|
298
360
|
return `Keep the existing todo "${previous.content}" in the checklist.`;
|
|
299
361
|
if (previous.deferredReason && replacement.status !== 'pending') {
|
|
300
362
|
return `The user deferred "${previous.content}". Keep it pending until they explicitly continue.`;
|
|
301
363
|
}
|
|
302
|
-
if (previous.status === 'completed' &&
|
|
364
|
+
if (previous.status === 'completed' &&
|
|
365
|
+
replacement.status !== 'completed' &&
|
|
366
|
+
!this.missingTodoEvidence(previous)) {
|
|
303
367
|
return `Add a new todo for further work on "${previous.content}".`;
|
|
304
368
|
}
|
|
369
|
+
previousByRequest.set(replacement.content, previous);
|
|
305
370
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
371
|
+
const warnings = [];
|
|
372
|
+
let hasIndependentUpdate = false;
|
|
373
|
+
let triedToAdvanceActiveTodo = false;
|
|
374
|
+
const next = todos.map(input => {
|
|
375
|
+
const previous = previousByRequest.get(input.content);
|
|
376
|
+
const todo = withTodoVerification(input, previous?.id ?? this.taskTodoId(input.content), previous);
|
|
377
|
+
const missing = todo.status === 'completed' ? this.missingTodoEvidence(todo) : undefined;
|
|
378
|
+
if (missing) {
|
|
379
|
+
warnings.push(missing);
|
|
380
|
+
triedToAdvanceActiveTodo || (triedToAdvanceActiveTodo = previous?.status === 'in_progress');
|
|
381
|
+
return { ...todo, status: 'pending' };
|
|
382
|
+
}
|
|
383
|
+
hasIndependentUpdate || (hasIndependentUpdate = !previous ||
|
|
384
|
+
previous.status !== todo.status ||
|
|
385
|
+
previous.content !== todo.content ||
|
|
386
|
+
previous.verification?.length !== todo.verification?.length);
|
|
387
|
+
return todo;
|
|
388
|
+
});
|
|
389
|
+
// Keep the active step if it still needs evidence so its next tool call
|
|
390
|
+
// can supply it. Repeated stale claims on inactive steps can stay pending.
|
|
391
|
+
if (warnings.length && (triedToAdvanceActiveTodo || !hasIndependentUpdate)) {
|
|
392
|
+
return warnings.join('\n');
|
|
393
|
+
}
|
|
394
|
+
if (blockedReason !== undefined) {
|
|
395
|
+
const active = next.find(todo => todo.status === 'in_progress');
|
|
396
|
+
if (!active || !blockedReason.trim())
|
|
397
|
+
return 'Report the blocker on an active todo.';
|
|
398
|
+
this.reportedTaskBlocker = {
|
|
399
|
+
code: 'task_step_blocked',
|
|
400
|
+
message: `Blocked at “${active.content}”. ${(0, redaction_1.redactTraceText)(blockedReason.trim())}`,
|
|
401
|
+
};
|
|
312
402
|
}
|
|
313
|
-
this.taskTodos =
|
|
403
|
+
this.taskTodos = next;
|
|
314
404
|
this.touch();
|
|
315
|
-
|
|
405
|
+
if (warnings.length) {
|
|
406
|
+
const applied = next.map(({ content, activeForm, status, verification }) => ({
|
|
407
|
+
content,
|
|
408
|
+
activeForm,
|
|
409
|
+
status,
|
|
410
|
+
...(verification ? { verification } : {}),
|
|
411
|
+
}));
|
|
412
|
+
return { todos: applied, warnings };
|
|
413
|
+
}
|
|
316
414
|
}
|
|
317
415
|
taskTodoId(content) {
|
|
318
416
|
return (0, crypto_1.createHash)('sha256')
|
|
@@ -322,6 +420,10 @@ class HarnessKernel {
|
|
|
322
420
|
}
|
|
323
421
|
missingTodoEvidence(todo) {
|
|
324
422
|
const receipts = this.taskTodoReceipts.filter(([step]) => step === todo.id);
|
|
423
|
+
const description = (0, redaction_1.redactTraceText)(todo.content);
|
|
424
|
+
const problems = [];
|
|
425
|
+
let missingChecks = [];
|
|
426
|
+
const implementation = (0, task_checklist_1.isImplementationTodo)(todo);
|
|
325
427
|
if (todo.verification?.length) {
|
|
326
428
|
const expected = todoChecks(todo.content);
|
|
327
429
|
const verified = receipts.flatMap(([, , result]) => result &&
|
|
@@ -330,32 +432,77 @@ class HarnessKernel {
|
|
|
330
432
|
result.workspaceRevision === this.ledger.workspaceRevision
|
|
331
433
|
? [result]
|
|
332
434
|
: []);
|
|
333
|
-
|
|
435
|
+
missingChecks = todo.verification.flatMap(kind => {
|
|
334
436
|
const selectors = expected.filter(check => check.kind === kind);
|
|
335
437
|
if (selectors.length) {
|
|
336
438
|
return selectors
|
|
337
439
|
.filter(check => !verified.some(result => matchesTodoCheck(result, check, this.cwd)))
|
|
338
|
-
.map(check => check.command);
|
|
440
|
+
.map(check => this.formatTodoCheck(check.command, check.cwd));
|
|
339
441
|
}
|
|
340
|
-
|
|
442
|
+
if (verified.some(result => result.kind === kind))
|
|
443
|
+
return [];
|
|
444
|
+
return [kind === 'diff' ? this.diffTodoCheckHint() : kind];
|
|
341
445
|
});
|
|
342
|
-
if (
|
|
343
|
-
|
|
344
|
-
|
|
446
|
+
if (missingChecks.length) {
|
|
447
|
+
problems.push('Run each check directly with exec_command while this todo is in progress.');
|
|
448
|
+
if (missingChecks.some(item => item.includes('git diff'))) {
|
|
449
|
+
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.');
|
|
450
|
+
}
|
|
451
|
+
}
|
|
345
452
|
}
|
|
346
|
-
if (
|
|
453
|
+
if (implementation) {
|
|
347
454
|
const changedFiles = new Set(receipts.flatMap(([, , result]) => result && 'changedFile' in result ? [result.changedFile] : []));
|
|
348
|
-
const targets = (0, task_checklist_1.
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
455
|
+
const targets = (0, task_checklist_1.todoFileTargets)(todo.content, this.cwd, this.taskChecklistTargets);
|
|
456
|
+
const needsClarification = targets.filter(target => target.candidates.length > 1 ||
|
|
457
|
+
(target.unscopedBasename &&
|
|
458
|
+
!changedFiles.has(target.candidates[0]) &&
|
|
459
|
+
[...changedFiles].some(path => (0, path_1.basename)(path) === target.declared)));
|
|
460
|
+
if (needsClarification.length) {
|
|
461
|
+
problems.push(`Clarify the exact workspace-relative path for ${needsClarification.map(target => target.declared).join(', ')} in this todo.`);
|
|
462
|
+
}
|
|
463
|
+
const remaining = targets.filter(target => !needsClarification.includes(target) &&
|
|
464
|
+
(target.candidates.length !== 1 || !changedFiles.has(target.candidates[0])));
|
|
465
|
+
if (remaining.length) {
|
|
466
|
+
const paths = remaining.map(target => target.candidates[0] ?? target.declared).join(', ');
|
|
467
|
+
problems.push(`Wait for verified file changes for: ${(0, redaction_1.redactTraceText)(paths)}.`);
|
|
468
|
+
}
|
|
469
|
+
else if (!targets.length && !changedFiles.size) {
|
|
470
|
+
problems.push('Record a successful workspace change for this step.');
|
|
471
|
+
}
|
|
355
472
|
}
|
|
473
|
+
if (problems.length) {
|
|
474
|
+
const required = missingChecks.length
|
|
475
|
+
? ` until its required checks pass: ${missingChecks.join(', ')}`
|
|
476
|
+
: '';
|
|
477
|
+
return `Keep "${description}" open${required}. ${problems.join(' ')}`;
|
|
478
|
+
}
|
|
479
|
+
if (implementation || todo.verification?.length)
|
|
480
|
+
return undefined;
|
|
356
481
|
if (receipts.some(([, , result]) => !result))
|
|
357
482
|
return undefined;
|
|
358
|
-
return `Keep "${
|
|
483
|
+
return `Keep "${description}" open until a successful tool receipt is recorded for that step.`;
|
|
484
|
+
}
|
|
485
|
+
formatTodoCheck(command, cwd) {
|
|
486
|
+
const path = (0, path_1.relative)(this.cwd, (0, path_1.resolve)(this.cwd, cwd ?? '.'));
|
|
487
|
+
const inWorkspace = path !== '..' && !path.startsWith('..' + path_1.sep) && !(0, path_1.isAbsolute)(path);
|
|
488
|
+
const safeCommand = (0, redaction_1.redactTraceText)(command);
|
|
489
|
+
return inWorkspace
|
|
490
|
+
? `exec_command(${JSON.stringify({ cwd: (0, redaction_1.redactTraceText)(path || '.'), command: safeCommand })})`
|
|
491
|
+
: `${safeCommand} in the required working directory`;
|
|
492
|
+
}
|
|
493
|
+
diffTodoCheckHint() {
|
|
494
|
+
for (const { metadata } of this.ledger.getEntries().reverse()) {
|
|
495
|
+
if (metadata?.taskContractId !== this.contract?.id)
|
|
496
|
+
continue;
|
|
497
|
+
if (metadata?.toolName !== 'exec_command' || typeof metadata.command !== 'string')
|
|
498
|
+
continue;
|
|
499
|
+
const selector = diffCheckSelector(metadata.command);
|
|
500
|
+
if (!selector)
|
|
501
|
+
continue;
|
|
502
|
+
const cwd = typeof metadata.cwd === 'string' ? metadata.cwd : '.';
|
|
503
|
+
return this.formatTodoCheck(selector.command, (0, path_1.resolve)(this.cwd, cwd, selector.cwd ?? '.'));
|
|
504
|
+
}
|
|
505
|
+
return this.formatTodoCheck('git diff --check');
|
|
359
506
|
}
|
|
360
507
|
updateCapabilityProfile(input) {
|
|
361
508
|
if (this.config.enabled === false)
|
|
@@ -491,7 +638,7 @@ class HarnessKernel {
|
|
|
491
638
|
recovery: {
|
|
492
639
|
failures: (previous?.failures ?? 0) + 1,
|
|
493
640
|
consecutiveFailures: (previous?.consecutiveFailures ?? 0) + 1,
|
|
494
|
-
strategies: [...new Set([...(previous?.strategies ?? []), strategy])].slice(-task_checklist_1.
|
|
641
|
+
strategies: [...new Set([...(previous?.strategies ?? []), strategy])].slice(-task_checklist_1.TASK_RECOVERY_STRATEGY_HISTORY_LIMIT),
|
|
495
642
|
lastFailure: params.verification
|
|
496
643
|
? `${params.verification.kind} verification failed`
|
|
497
644
|
: `${params.name} failed`,
|
|
@@ -507,6 +654,33 @@ class HarnessKernel {
|
|
|
507
654
|
this.refreshCapsule();
|
|
508
655
|
this.touch();
|
|
509
656
|
}
|
|
657
|
+
hasCurrentWorkspaceVerification(activeTaskOnly = false) {
|
|
658
|
+
const revision = this.ledger.workspaceRevision;
|
|
659
|
+
return (this.ledger
|
|
660
|
+
.getEntries()
|
|
661
|
+
.some(entry => entry.type === 'verification' &&
|
|
662
|
+
typeof entry.metadata?.toolReceiptDigest === 'string' &&
|
|
663
|
+
entry.metadata.workspaceRevision === revision &&
|
|
664
|
+
(!activeTaskOnly || entry.metadata.taskContractId === this.contract?.id)) ||
|
|
665
|
+
this.taskTodoReceipts.some(([, , evidence]) => evidence && 'kind' in evidence ? evidence.workspaceRevision === revision : false));
|
|
666
|
+
}
|
|
667
|
+
observeVerificationWorkspace(fingerprint) {
|
|
668
|
+
if (this.config.enabled === false || fingerprint === this.verificationWorkspace)
|
|
669
|
+
return;
|
|
670
|
+
const previous = this.verificationWorkspace;
|
|
671
|
+
this.verificationWorkspace = fingerprint ?? undefined;
|
|
672
|
+
if (this.hasCurrentWorkspaceVerification()) {
|
|
673
|
+
if (previous && fingerprint) {
|
|
674
|
+
this.ledger.advanceWorkspaceRevision();
|
|
675
|
+
this.invalidateVerificationAfterWrite();
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
this.invalidateUnboundVerification();
|
|
679
|
+
}
|
|
680
|
+
this.refreshCapsule();
|
|
681
|
+
}
|
|
682
|
+
this.touch();
|
|
683
|
+
}
|
|
510
684
|
ingestTurn(params) {
|
|
511
685
|
if (this.config.enabled === false)
|
|
512
686
|
return undefined;
|
|
@@ -572,9 +746,28 @@ class HarnessKernel {
|
|
|
572
746
|
if (result.missing.length > 0)
|
|
573
747
|
result.canComplete = false;
|
|
574
748
|
}
|
|
749
|
+
const goalBlocker = requireEveryCriterion ? this.goalVerificationBlocker : undefined;
|
|
750
|
+
if (goalBlocker) {
|
|
751
|
+
result.missing.push(goalBlocker);
|
|
752
|
+
result.canComplete = false;
|
|
753
|
+
}
|
|
575
754
|
const progressDelta = this.recordProgress();
|
|
576
755
|
result.progressDelta = progressDelta;
|
|
577
|
-
|
|
756
|
+
const completion = this.stopController.decideCompletion(result, progressDelta);
|
|
757
|
+
result.stopDecision = goalBlocker
|
|
758
|
+
? (0, stop_decision_1.createStopDecision)({
|
|
759
|
+
...completion,
|
|
760
|
+
status: 'blocked',
|
|
761
|
+
reason: { code: 'task_step_blocked', message: goalBlocker },
|
|
762
|
+
nextActions: [
|
|
763
|
+
{
|
|
764
|
+
kind: 'resume',
|
|
765
|
+
label: 'Resume and send the exact replacement check.',
|
|
766
|
+
command: '/goal resume',
|
|
767
|
+
},
|
|
768
|
+
],
|
|
769
|
+
})
|
|
770
|
+
: completion;
|
|
578
771
|
const mode = this.config.completionGate === true
|
|
579
772
|
? 'block'
|
|
580
773
|
: this.config.completionGate === false
|
|
@@ -700,6 +893,7 @@ class HarnessKernel {
|
|
|
700
893
|
contract: this.contract,
|
|
701
894
|
ledger: this.ledger.toJSON(),
|
|
702
895
|
workspaceRevision: this.ledger.workspaceRevision,
|
|
896
|
+
...(this.verificationWorkspace ? { verificationWorkspace: this.verificationWorkspace } : {}),
|
|
703
897
|
capsule: this.capsule,
|
|
704
898
|
completionBlockCount: this.completionBlockCount,
|
|
705
899
|
taskEpoch: this.taskEpoch,
|
|
@@ -708,6 +902,9 @@ class HarnessKernel {
|
|
|
708
902
|
? { taskChecklistTargets: this.taskChecklistTargets }
|
|
709
903
|
: {}),
|
|
710
904
|
...(this.goalTaskId ? { goalTaskId: this.goalTaskId } : {}),
|
|
905
|
+
...(this.goalVerificationBlocker
|
|
906
|
+
? { goalVerificationBlocker: this.goalVerificationBlocker }
|
|
907
|
+
: {}),
|
|
711
908
|
...(this.taskTodos.length ? { taskTodos: this.taskTodos } : {}),
|
|
712
909
|
...(this.taskTodoReceipts.length ? { taskTodoReceipts: [...this.taskTodoReceipts] } : {}),
|
|
713
910
|
rootObjective: this.rootObjective,
|
|
@@ -749,6 +946,22 @@ class HarnessKernel {
|
|
|
749
946
|
return DEFAULT_CONFIG.maxRecentTurns;
|
|
750
947
|
return Math.max(0, Math.min(80, Math.floor(configured)));
|
|
751
948
|
}
|
|
949
|
+
/** An unbound result must be rerun without recording a filesystem mutation. */
|
|
950
|
+
invalidateUnboundVerification() {
|
|
951
|
+
this.ledger.forgetVerificationBindings();
|
|
952
|
+
for (const [index, [step, receipt, evidence]] of this.taskTodoReceipts.entries()) {
|
|
953
|
+
if (evidence &&
|
|
954
|
+
'kind' in evidence &&
|
|
955
|
+
evidence.workspaceRevision === this.ledger.workspaceRevision) {
|
|
956
|
+
this.taskTodoReceipts[index] = [
|
|
957
|
+
step,
|
|
958
|
+
receipt,
|
|
959
|
+
{ ...evidence, workspaceRevision: undefined },
|
|
960
|
+
];
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
this.invalidateVerificationAfterWrite();
|
|
964
|
+
}
|
|
752
965
|
invalidateVerificationAfterWrite() {
|
|
753
966
|
if (this.contract?.criteria) {
|
|
754
967
|
this.contract = {
|
|
@@ -885,6 +1098,21 @@ function todoChecks(content) {
|
|
|
885
1098
|
requested.push({ kind: direct, command });
|
|
886
1099
|
return requested;
|
|
887
1100
|
}
|
|
1101
|
+
/** Reuse a recognizable diff selector only as a hint. No inspection call becomes evidence here. */
|
|
1102
|
+
function diffCheckSelector(command) {
|
|
1103
|
+
if ((0, verification_command_1.classifyDirectVerificationCommand)(command) === 'diff')
|
|
1104
|
+
return { command: command.trim() };
|
|
1105
|
+
const match = /^(?:cd\s+([\w./-]+)\s+&&\s+)?git\s+diff(?:\s+(--cached|--staged))?(?:\s+--check)?(?:\s+--(?:\s+([\w./-]+(?:\s+[\w./-]+)*))?)?$/u.exec(command.trim());
|
|
1106
|
+
if (!match)
|
|
1107
|
+
return undefined;
|
|
1108
|
+
const [, cwd, staged, paths] = match;
|
|
1109
|
+
return {
|
|
1110
|
+
cwd,
|
|
1111
|
+
command: ['git diff', staged, '--check', paths ? '-- ' + paths : undefined]
|
|
1112
|
+
.filter(Boolean)
|
|
1113
|
+
.join(' '),
|
|
1114
|
+
};
|
|
1115
|
+
}
|
|
888
1116
|
function matchesTodoCheck(observed, check, workspace) {
|
|
889
1117
|
return (observed.kind === check.kind &&
|
|
890
1118
|
observed.command === check.command &&
|
package/dist/harness/contract.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.normalizeTaskContract = normalizeTaskContract;
|
|
|
5
5
|
exports.createTaskContract = createTaskContract;
|
|
6
6
|
exports.updateTaskContract = updateTaskContract;
|
|
7
7
|
const crypto_1 = require("crypto");
|
|
8
|
+
const verification_1 = require("./verification");
|
|
8
9
|
function normalizeLine(text) {
|
|
9
10
|
return text.trim().replace(/\s+/g, ' ');
|
|
10
11
|
}
|
|
@@ -166,7 +167,8 @@ function createTaskContract(input, cwd) {
|
|
|
166
167
|
const requirements = unique(lines.filter(line => requirementHints.test(line)));
|
|
167
168
|
const prohibitions = unique(lines.filter(line => prohibitionHints.test(line)));
|
|
168
169
|
const successCriteria = unique([
|
|
169
|
-
...lines.filter(line => verificationHints.test(line)
|
|
170
|
+
...lines.filter(line => verificationHints.test(line) ||
|
|
171
|
+
((0, verification_1.requestedLocalChecks)(line).length > 0 && (0, verification_1.requiredVerificationKinds)(line).length > 0)),
|
|
170
172
|
requirements.length === 0 ? `Address the objective: ${objective}` : '',
|
|
171
173
|
]);
|
|
172
174
|
return normalizeTaskContract({
|