@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
|
@@ -4,6 +4,8 @@ exports.hasExplicitVerificationNeed = hasExplicitVerificationNeed;
|
|
|
4
4
|
exports.checkToolDrift = checkToolDrift;
|
|
5
5
|
exports.evaluateCompletionGate = evaluateCompletionGate;
|
|
6
6
|
const path_1 = require("path");
|
|
7
|
+
const redaction_1 = require("../services/redaction");
|
|
8
|
+
const terminal_text_1 = require("../utils/terminal-text");
|
|
7
9
|
const contract_1 = require("./contract");
|
|
8
10
|
const verification_1 = require("./verification");
|
|
9
11
|
const PATH_ARGUMENT_KEYS = new Set([
|
|
@@ -311,9 +313,10 @@ function evaluateCompletionGate(params) {
|
|
|
311
313
|
if (artifact)
|
|
312
314
|
requiredKinds.push('file');
|
|
313
315
|
const applicable = requiredKinds.length > 0;
|
|
314
|
-
const
|
|
316
|
+
const allLinked = criterion.evidenceRefs
|
|
315
317
|
.map(ref => ({ ref, entry: byEvidenceRef.get(ref) }))
|
|
316
|
-
.filter((item) => item.entry !== undefined
|
|
318
|
+
.filter((item) => item.entry !== undefined);
|
|
319
|
+
const linked = allLinked.filter(item => (0, verification_1.isFreshVerification)(item.entry, params.workspaceRevision));
|
|
317
320
|
if ((0, verification_1.criterionHasAuthorizedWaiver)(criterion)) {
|
|
318
321
|
return {
|
|
319
322
|
criterionId: criterion.id,
|
|
@@ -326,13 +329,14 @@ function evaluateCompletionGate(params) {
|
|
|
326
329
|
failedKinds: [],
|
|
327
330
|
};
|
|
328
331
|
}
|
|
329
|
-
const trusted =
|
|
332
|
+
const trusted = allLinked
|
|
330
333
|
.map(item => item.entry)
|
|
331
334
|
.filter(verification_1.isTrustedEvidence)
|
|
332
335
|
.sort((left, right) => position.get(right.id) - position.get(left.id));
|
|
333
336
|
const checks = (0, verification_1.requestedLocalChecks)(criterion.statement);
|
|
334
337
|
const failedKinds = [];
|
|
335
338
|
const missingKinds = [];
|
|
339
|
+
const verificationProblems = [];
|
|
336
340
|
for (const kind of requiredKinds) {
|
|
337
341
|
if (kind === 'file' && artifact) {
|
|
338
342
|
const write = (0, verification_1.latestArtifactWrite)(params.ledger, contract.id, contract.allowedScope.cwd, artifact.path);
|
|
@@ -354,18 +358,26 @@ function evaluateCompletionGate(params) {
|
|
|
354
358
|
!params.requireLocalReceipt ||
|
|
355
359
|
(entry.type === 'verification' &&
|
|
356
360
|
typeof entry.metadata?.toolReceiptDigest === 'string')));
|
|
361
|
+
const workspace = contract.allowedScope.cwd;
|
|
357
362
|
const expected = checks.filter(check => check.kind === kind);
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
363
|
+
const selectors = expected.length ? expected : [undefined];
|
|
364
|
+
for (const selector of selectors) {
|
|
365
|
+
const matching = selector
|
|
366
|
+
? candidates.filter(entry => (0, verification_1.matchesRequestedCheck)(entry, selector, workspace))
|
|
367
|
+
: candidates;
|
|
368
|
+
const current = matching.find(entry => (0, verification_1.isFreshVerification)(entry, params.workspaceRevision));
|
|
369
|
+
if (current?.metadata?.success === true) {
|
|
370
|
+
if (!evidence.includes(current.content))
|
|
371
|
+
evidence.push(current.content);
|
|
372
|
+
continue;
|
|
368
373
|
}
|
|
374
|
+
if (!missingKinds.includes(kind))
|
|
375
|
+
missingKinds.push(kind);
|
|
376
|
+
const status = current ? 'failed' : matching[0] ? 'stale' : 'missing';
|
|
377
|
+
if (status === 'failed' && !failedKinds.includes(kind))
|
|
378
|
+
failedKinds.push(kind);
|
|
379
|
+
const last = current ?? matching[0];
|
|
380
|
+
verificationProblems.push(verificationProblem(kind, status, workspace, selector, last?.metadata));
|
|
369
381
|
}
|
|
370
382
|
}
|
|
371
383
|
const status = !applicable
|
|
@@ -386,6 +398,7 @@ function evaluateCompletionGate(params) {
|
|
|
386
398
|
requiredKinds,
|
|
387
399
|
missingKinds,
|
|
388
400
|
failedKinds,
|
|
401
|
+
...(verificationProblems.length ? { verificationProblems } : {}),
|
|
389
402
|
};
|
|
390
403
|
});
|
|
391
404
|
const unsatisfied = criterionResults.filter(result => (params.requireEveryCriterion || result.applicable) &&
|
|
@@ -393,11 +406,15 @@ function evaluateCompletionGate(params) {
|
|
|
393
406
|
result.status !== 'waived');
|
|
394
407
|
if (unsatisfied.length > 0 ||
|
|
395
408
|
(criterionResults.length === 0 && hasExplicitVerificationNeed(contract))) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
missing.push(
|
|
409
|
+
for (const result of unsatisfied) {
|
|
410
|
+
if (result.verificationProblems?.length) {
|
|
411
|
+
missing.push(...result.verificationProblems.map(problem => describeVerificationProblem(problem, result.statement)));
|
|
412
|
+
}
|
|
413
|
+
else if (params.requireEveryCriterion) {
|
|
414
|
+
missing.push(`Verify the Goal criterion: ${safeFeedback(result.statement)}`);
|
|
415
|
+
}
|
|
399
416
|
}
|
|
400
|
-
|
|
417
|
+
if (!missing.length && !params.requireEveryCriterion) {
|
|
401
418
|
missing.push('Required verification has not passed yet.');
|
|
402
419
|
}
|
|
403
420
|
}
|
|
@@ -411,4 +428,37 @@ function evaluateCompletionGate(params) {
|
|
|
411
428
|
criterionResults,
|
|
412
429
|
};
|
|
413
430
|
}
|
|
431
|
+
function safeFeedback(text, limit = 240) {
|
|
432
|
+
return (0, terminal_text_1.sanitizeTerminalText)((0, redaction_1.redactTraceText)(text)).replace(/\s+/gu, ' ').trim().slice(0, limit);
|
|
433
|
+
}
|
|
434
|
+
function verificationProblem(kind, status, workspace, selector, metadata) {
|
|
435
|
+
const command = selector?.command ?? metadata?.command;
|
|
436
|
+
const cwd = selector?.cwd ?? metadata?.cwd;
|
|
437
|
+
const scoped = typeof cwd === 'string' ? (0, path_1.relative)(workspace, (0, path_1.resolve)(workspace, cwd)) : '';
|
|
438
|
+
return {
|
|
439
|
+
kind,
|
|
440
|
+
status,
|
|
441
|
+
...(typeof command === 'string'
|
|
442
|
+
? {
|
|
443
|
+
command: safeFeedback(command),
|
|
444
|
+
cwd: scoped === '..' || (0, path_1.isAbsolute)(scoped) || scoped.startsWith(`..${path_1.sep}`)
|
|
445
|
+
? '(outside workspace)'
|
|
446
|
+
: safeFeedback(scoped || '.'),
|
|
447
|
+
}
|
|
448
|
+
: {}),
|
|
449
|
+
...(status === 'failed' && typeof metadata?.exitCode === 'number'
|
|
450
|
+
? { exitCode: metadata.exitCode }
|
|
451
|
+
: {}),
|
|
452
|
+
...(status === 'failed' && typeof metadata?.verificationFailureFingerprint === 'string'
|
|
453
|
+
? { failureFingerprint: metadata.verificationFailureFingerprint }
|
|
454
|
+
: {}),
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
function describeVerificationProblem(problem, statement) {
|
|
458
|
+
const subject = problem.command
|
|
459
|
+
? `\`${problem.command}\` in \`${problem.cwd}\``
|
|
460
|
+
: safeFeedback(statement);
|
|
461
|
+
const exit = problem.exitCode === undefined ? '' : ` (exit ${problem.exitCode})`;
|
|
462
|
+
return `Verification ${problem.status} for ${subject}${exit}.`;
|
|
463
|
+
}
|
|
414
464
|
//# sourceMappingURL=drift-guard.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TaskContract } from './types';
|
|
2
|
+
import { type RequestedCheck } from './verification';
|
|
3
|
+
export type GoalVerificationCorrection = {
|
|
4
|
+
readonly previous: RequestedCheck;
|
|
5
|
+
readonly next: RequestedCheck;
|
|
6
|
+
} | {
|
|
7
|
+
readonly blocker: string;
|
|
8
|
+
};
|
|
9
|
+
/** Only explicit user correction can supersede a required verification selector. */
|
|
10
|
+
export declare function goalVerificationCorrection(contract: TaskContract, input: string): GoalVerificationCorrection | undefined;
|
|
11
|
+
//# sourceMappingURL=goal-verification.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.goalVerificationCorrection = goalVerificationCorrection;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const verification_1 = require("./verification");
|
|
6
|
+
const clarification = 'The Goal check could not be identified. Specify “Replace `old command` with `new command`”, with each workspace directory if needed.';
|
|
7
|
+
/** Only explicit user correction can supersede a required verification selector. */
|
|
8
|
+
function goalVerificationCorrection(contract, input) {
|
|
9
|
+
const prose = input.replace(/\x60[^\x60]+\x60/gu, ' ');
|
|
10
|
+
const nextFirst = /\b(?:instead of|rather than)\b|而不是|取代|代替/u.test(prose.toLowerCase());
|
|
11
|
+
const oldFirst = /\b(?:replace|supersede|switch from|change from)\b|替换|改为|换成/u.test(prose.toLowerCase());
|
|
12
|
+
if (!nextFirst && !oldFirst)
|
|
13
|
+
return undefined;
|
|
14
|
+
const requested = (0, verification_1.locateRequestedChecks)(input);
|
|
15
|
+
const refersToCheck = /\b(?:replace|supersede|change|switch)\s+(?:(?:the|earlier|previous|old|existing|required|original|goal)\s+)*(?:check|verification|test)\b/iu.test(prose) ||
|
|
16
|
+
/\b(?:instead of|rather than)\s+(?:(?:the|earlier|previous|old|existing|required|original|goal)\s+)*(?:check|verification|test)\b/iu.test(prose) ||
|
|
17
|
+
/(?:替换|更改|修改).{0,10}(?:验证|检查|测试)|(?:验证|检查|测试).{0,10}(?:改为|换成|替换)|(?:取代|代替|而不是).{0,10}(?:验证|检查|测试)/u.test(prose);
|
|
18
|
+
const [first, second] = requested;
|
|
19
|
+
const between = second
|
|
20
|
+
? input.slice(first.end, second.start).replace(/\x60[^\x60]+\x60/gu, ' ')
|
|
21
|
+
: '';
|
|
22
|
+
const replacementFirst = /\b(?:instead of|rather than|to replace|to supersede)\b|而不是|取代|代替|替换(?![成为])/iu.test(between);
|
|
23
|
+
const originalFirst = oldFirst && /\b(?:with|to)\b|改为|换成|替换[成为]/iu.test(between);
|
|
24
|
+
if (!(refersToCheck || replacementFirst || originalFirst))
|
|
25
|
+
return undefined;
|
|
26
|
+
if (!first || requested.length > 2 || (second && !replacementFirst && !originalFirst)) {
|
|
27
|
+
return { blocker: clarification };
|
|
28
|
+
}
|
|
29
|
+
const workspace = contract.allowedScope.cwd;
|
|
30
|
+
const existing = [];
|
|
31
|
+
for (const criterion of contract.criteria ?? []) {
|
|
32
|
+
for (const check of (0, verification_1.requestedLocalChecks)(criterion.statement)) {
|
|
33
|
+
if (!existing.some(prior => (0, verification_1.equalRequestedChecks)(prior, check, workspace)))
|
|
34
|
+
existing.push(check);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const wanted = !second || replacementFirst ? first : second;
|
|
38
|
+
const oldSelector = !second ? undefined : replacementFirst ? second : first;
|
|
39
|
+
const matching = existing.filter(check => oldSelector
|
|
40
|
+
? check.command === oldSelector.command &&
|
|
41
|
+
(oldSelector.cwd === undefined || (0, verification_1.equalRequestedChecks)(check, oldSelector, workspace))
|
|
42
|
+
: check.kind === wanted.kind);
|
|
43
|
+
if (!matching.length &&
|
|
44
|
+
oldSelector &&
|
|
45
|
+
existing.some(check => (0, verification_1.equalRequestedChecks)(check, wanted, workspace)))
|
|
46
|
+
return undefined;
|
|
47
|
+
if (matching.length !== 1)
|
|
48
|
+
return { blocker: clarification };
|
|
49
|
+
const [previous] = matching;
|
|
50
|
+
const next = { kind: wanted.kind, command: wanted.command, cwd: wanted.cwd ?? previous.cwd };
|
|
51
|
+
const scoped = (0, path_1.relative)(workspace, (0, path_1.resolve)(workspace, next.cwd ?? '.'));
|
|
52
|
+
if (scoped === '..' || (0, path_1.isAbsolute)(scoped) || scoped.startsWith(`..${path_1.sep}`)) {
|
|
53
|
+
return { blocker: 'Choose a replacement check inside this Goal’s workspace.' };
|
|
54
|
+
}
|
|
55
|
+
if (previous.kind !== next.kind) {
|
|
56
|
+
return {
|
|
57
|
+
blocker: 'Replace the Goal check with a direct check of the same kind. For a different verification requirement, specify the corrected Goal objective.',
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return { previous, next };
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=goal-verification.js.map
|
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
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ContextLedger = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
|
+
const redaction_1 = require("../services/redaction");
|
|
5
6
|
const verification_command_1 = require("../framework/verification-command");
|
|
7
|
+
const bash_security_1 = require("../tools/bash_security");
|
|
6
8
|
const verification_1 = require("./verification");
|
|
7
9
|
function truncate(text, max = 900) {
|
|
8
10
|
const normalized = text.replace(/\s+/g, ' ').trim();
|
|
@@ -13,14 +15,14 @@ function parseToolPayload(result) {
|
|
|
13
15
|
const parsed = JSON.parse(result);
|
|
14
16
|
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
15
17
|
const record = parsed;
|
|
18
|
+
const metadata = record.metadata;
|
|
19
|
+
const exitCode = record.exitCode ?? metadata?.exitCode;
|
|
16
20
|
return {
|
|
17
21
|
structured: typeof record.success === 'boolean',
|
|
18
22
|
success: typeof record.success === 'boolean' ? record.success : undefined,
|
|
19
23
|
output: typeof record.output === 'string' ? record.output : undefined,
|
|
20
24
|
error: typeof record.error === 'string' ? record.error : undefined,
|
|
21
|
-
exitCode: typeof
|
|
22
|
-
? record.exitCode
|
|
23
|
-
: undefined,
|
|
25
|
+
exitCode: typeof exitCode === 'number' && Number.isInteger(exitCode) ? exitCode : undefined,
|
|
24
26
|
sourceSha: typeof record.sourceSha === 'string' ? record.sourceSha : undefined,
|
|
25
27
|
artifactHash: typeof record.artifactHash === 'string' ? record.artifactHash : undefined,
|
|
26
28
|
};
|
|
@@ -31,6 +33,15 @@ function parseToolPayload(result) {
|
|
|
31
33
|
}
|
|
32
34
|
return { structured: false, output: result };
|
|
33
35
|
}
|
|
36
|
+
function verificationFailureFingerprint(parsed, error) {
|
|
37
|
+
const diagnostic = (0, redaction_1.redactTraceText)([parsed.error ?? error, parsed.output].filter(Boolean).join('\n'))
|
|
38
|
+
.replace(/^\s*(?:time|duration|elapsed):\s*\d[^\r\n]*$/gimu, '')
|
|
39
|
+
.replace(/\s+/gu, ' ')
|
|
40
|
+
.trim();
|
|
41
|
+
return (0, crypto_1.createHash)('sha256')
|
|
42
|
+
.update(JSON.stringify([parsed.exitCode, diagnostic]))
|
|
43
|
+
.digest('hex');
|
|
44
|
+
}
|
|
34
45
|
function commandFromArgs(args) {
|
|
35
46
|
return typeof args.command === 'string' ? args.command : undefined;
|
|
36
47
|
}
|
|
@@ -61,6 +72,12 @@ class ContextLedger {
|
|
|
61
72
|
advanceWorkspaceRevision() {
|
|
62
73
|
this.workspaceRevisionValue++;
|
|
63
74
|
}
|
|
75
|
+
forgetVerificationBindings() {
|
|
76
|
+
this.entries = this.entries.map(entry => (entry.type === 'verification' || entry.type === 'test_result') &&
|
|
77
|
+
entry.metadata?.workspaceRevision === this.workspaceRevisionValue
|
|
78
|
+
? { ...entry, metadata: { ...entry.metadata, workspaceRevision: undefined } }
|
|
79
|
+
: entry);
|
|
80
|
+
}
|
|
64
81
|
add(input) {
|
|
65
82
|
const entry = {
|
|
66
83
|
id: (0, crypto_1.randomUUID)(),
|
|
@@ -115,6 +132,9 @@ class ContextLedger {
|
|
|
115
132
|
// Use summary when available to reduce evidence size
|
|
116
133
|
const output = params.summary || parsed.error || params.error || parsed.output || params.result;
|
|
117
134
|
const shell = params.name === 'exec_command' || params.name === 'bash';
|
|
135
|
+
// A production shell descriptor is conservatively write-capable. Its
|
|
136
|
+
// individual invocation can still be a recognized read for task progress.
|
|
137
|
+
const readOnly = params.readOnly === true || (shell && !!command && (0, bash_security_1.isReadOnlyCommand)(command));
|
|
118
138
|
const classified = shell ? (0, verification_1.classifyVerificationCommand)(command) : 'generic';
|
|
119
139
|
const verificationKind = receipt?.kind ??
|
|
120
140
|
(requireLocalReceipt && (0, verification_command_1.isLocalVerificationKind)(classified) ? 'generic' : classified);
|
|
@@ -159,13 +179,17 @@ class ContextLedger {
|
|
|
159
179
|
freshness: 'current_run',
|
|
160
180
|
verificationKind,
|
|
161
181
|
...(isVerification ? { workspaceRevision: this.workspaceRevision } : {}),
|
|
182
|
+
...(isVerification && evidenceSuccess === false
|
|
183
|
+
? { verificationFailureFingerprint: verificationFailureFingerprint(parsed, params.error) }
|
|
184
|
+
: {}),
|
|
162
185
|
toolReceiptDigest: receipt?.toolReceiptDigest ?? params.toolReceiptDigest,
|
|
163
186
|
taskContractId,
|
|
164
187
|
success: evidenceSuccess,
|
|
165
188
|
resultTrust: parsed.structured ? 'structured' : 'opaque',
|
|
166
189
|
error: params.error || parsed.error,
|
|
167
190
|
changedFile,
|
|
168
|
-
...(
|
|
191
|
+
...(readOnly ? { readOnly: true } : {}),
|
|
192
|
+
...(readOnly && evidenceSuccess
|
|
169
193
|
? {
|
|
170
194
|
readOnlyOutputHash: (0, crypto_1.createHash)('sha256')
|
|
171
195
|
.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,
|
|
@@ -89,6 +90,9 @@ function upgradeHarnessState(state, options = {}) {
|
|
|
89
90
|
: {}),
|
|
90
91
|
...(state?.taskChecklistTargets ? { taskChecklistTargets: state.taskChecklistTargets } : {}),
|
|
91
92
|
...(state?.goalTaskId ? { goalTaskId: state.goalTaskId } : {}),
|
|
93
|
+
...(state?.goalVerificationBlocker
|
|
94
|
+
? { goalVerificationBlocker: state.goalVerificationBlocker }
|
|
95
|
+
: {}),
|
|
92
96
|
...(state?.taskTodos ? { taskTodos: state.taskTodos } : {}),
|
|
93
97
|
...(state?.taskTodoReceipts ? { taskTodoReceipts: state.taskTodoReceipts } : {}),
|
|
94
98
|
rootObjective,
|
|
@@ -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,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { TodoItem } from '../framework/tool-state';
|
|
2
2
|
import type { TaskTodoItem } from './types';
|
|
3
|
-
export declare const TASK_CHECKLIST_REQUIRED = "Create an execution checklist with todo_write before changing the workspace. Include
|
|
3
|
+
export declare const TASK_CHECKLIST_REQUIRED = "Create an execution checklist with todo_write before changing the workspace. Include the implementation work and a verification check. 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;
|
|
@@ -11,6 +11,16 @@ export declare function requestedWorkspaceChanges(instruction: string): {
|
|
|
11
11
|
paths: string[];
|
|
12
12
|
};
|
|
13
13
|
export declare function isImplementationTodo(todo: TodoItem): boolean;
|
|
14
|
+
interface TodoFileTarget {
|
|
15
|
+
readonly declared: string;
|
|
16
|
+
readonly candidates: readonly string[];
|
|
17
|
+
/** Write evidence for another location may be kept until the user scope is clarified. */
|
|
18
|
+
readonly unscopedBasename: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare function todoFileTargets(content: string, cwd: string, taskTargets: readonly string[]): TodoFileTarget[];
|
|
21
|
+
/** A clarification changes only an unresolved file token, retaining the todo and its evidence. */
|
|
22
|
+
export declare function clarifiesTodoFileTarget(previous: TodoItem, next: TodoItem, cwd: string, taskTargets: readonly string[]): boolean;
|
|
14
23
|
export declare function workspaceChangeTargets(root: string, paths: readonly string[]): string[];
|
|
15
24
|
export declare function executionChecklistIssue(todos: readonly TodoItem[], targets: readonly string[], cwd: string): string | undefined;
|
|
25
|
+
export {};
|
|
16
26
|
//# sourceMappingURL=task-checklist.d.ts.map
|