@orion-agents/orion-code 0.4.4 → 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 +8 -0
- package/README.md +4 -4
- package/README.zh-CN.md +4 -4
- package/dist/core/tool-artifacts.js +17 -4
- package/dist/framework/query.js +150 -16
- package/dist/framework/tool-state.d.ts +4 -0
- package/dist/harness/context-harness.d.ts +6 -2
- package/dist/harness/context-harness.js +221 -47
- 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/ledger.js +16 -3
- package/dist/harness/state.js +3 -0
- package/dist/harness/task-checklist.d.ts +11 -1
- package/dist/harness/task-checklist.js +48 -4
- package/dist/harness/types.d.ts +10 -0
- package/dist/harness/verification.d.ts +11 -1
- package/dist/harness/verification.js +47 -2
- package/dist/runtime/agent-loop.js +4 -1
- package/dist/runtime/batch-read-service.js +21 -4
- package/dist/runtime/goal-runtime-coordinator.js +1 -0
- package/dist/runtime/product-orion-runtime.js +24 -2
- package/dist/runtime/task-context-recovery.js +21 -5
- package/dist/runtime/task-context-service.d.ts +3 -1
- package/dist/runtime/task-context-service.js +3 -0
- package/dist/runtime/workspace-verification.d.ts +2 -2
- package/dist/runtime/workspace-verification.js +24 -9
- 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/llm.d.ts +1 -1
- package/dist/services/llm.js +165 -292
- package/dist/services/provider-diagnostics.d.ts +1 -1
- package/dist/services/provider-diagnostics.js +7 -2
- 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 +57 -86
- 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/todo.d.ts +2 -2
- package/dist/tools/todo.js +13 -10
- package/dist/utils/utf8.d.ts +6 -0
- package/dist/utils/utf8.js +14 -0
- package/docs/cli-guide.md +7 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/harness/ledger.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
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");
|
|
6
7
|
const bash_security_1 = require("../tools/bash_security");
|
|
7
8
|
const verification_1 = require("./verification");
|
|
@@ -14,14 +15,14 @@ function parseToolPayload(result) {
|
|
|
14
15
|
const parsed = JSON.parse(result);
|
|
15
16
|
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
16
17
|
const record = parsed;
|
|
18
|
+
const metadata = record.metadata;
|
|
19
|
+
const exitCode = record.exitCode ?? metadata?.exitCode;
|
|
17
20
|
return {
|
|
18
21
|
structured: typeof record.success === 'boolean',
|
|
19
22
|
success: typeof record.success === 'boolean' ? record.success : undefined,
|
|
20
23
|
output: typeof record.output === 'string' ? record.output : undefined,
|
|
21
24
|
error: typeof record.error === 'string' ? record.error : undefined,
|
|
22
|
-
exitCode: typeof
|
|
23
|
-
? record.exitCode
|
|
24
|
-
: undefined,
|
|
25
|
+
exitCode: typeof exitCode === 'number' && Number.isInteger(exitCode) ? exitCode : undefined,
|
|
25
26
|
sourceSha: typeof record.sourceSha === 'string' ? record.sourceSha : undefined,
|
|
26
27
|
artifactHash: typeof record.artifactHash === 'string' ? record.artifactHash : undefined,
|
|
27
28
|
};
|
|
@@ -32,6 +33,15 @@ function parseToolPayload(result) {
|
|
|
32
33
|
}
|
|
33
34
|
return { structured: false, output: result };
|
|
34
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
|
+
}
|
|
35
45
|
function commandFromArgs(args) {
|
|
36
46
|
return typeof args.command === 'string' ? args.command : undefined;
|
|
37
47
|
}
|
|
@@ -169,6 +179,9 @@ class ContextLedger {
|
|
|
169
179
|
freshness: 'current_run',
|
|
170
180
|
verificationKind,
|
|
171
181
|
...(isVerification ? { workspaceRevision: this.workspaceRevision } : {}),
|
|
182
|
+
...(isVerification && evidenceSuccess === false
|
|
183
|
+
? { verificationFailureFingerprint: verificationFailureFingerprint(parsed, params.error) }
|
|
184
|
+
: {}),
|
|
172
185
|
toolReceiptDigest: receipt?.toolReceiptDigest ?? params.toolReceiptDigest,
|
|
173
186
|
taskContractId,
|
|
174
187
|
success: evidenceSuccess,
|
package/dist/harness/state.js
CHANGED
|
@@ -90,6 +90,9 @@ function upgradeHarnessState(state, options = {}) {
|
|
|
90
90
|
: {}),
|
|
91
91
|
...(state?.taskChecklistTargets ? { taskChecklistTargets: state.taskChecklistTargets } : {}),
|
|
92
92
|
...(state?.goalTaskId ? { goalTaskId: state.goalTaskId } : {}),
|
|
93
|
+
...(state?.goalVerificationBlocker
|
|
94
|
+
? { goalVerificationBlocker: state.goalVerificationBlocker }
|
|
95
|
+
: {}),
|
|
93
96
|
...(state?.taskTodos ? { taskTodos: state.taskTodos } : {}),
|
|
94
97
|
...(state?.taskTodoReceipts ? { taskTodoReceipts: state.taskTodoReceipts } : {}),
|
|
95
98
|
rootObjective,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TodoItem } from '../framework/tool-state';
|
|
2
2
|
import type { TaskTodoItem } from './types';
|
|
3
|
-
export declare const TASK_CHECKLIST_REQUIRED = "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
5
|
export declare const TASK_RECOVERY_STRATEGY_HISTORY_LIMIT = 4;
|
|
6
6
|
/** Deferral is applied from explicit user input. Tool arguments cannot defer work. */
|
|
@@ -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
|
|
@@ -6,8 +6,11 @@ exports.requestedTaskDeferral = requestedTaskDeferral;
|
|
|
6
6
|
exports.taskTodoDisplayStatus = taskTodoDisplayStatus;
|
|
7
7
|
exports.requestedWorkspaceChanges = requestedWorkspaceChanges;
|
|
8
8
|
exports.isImplementationTodo = isImplementationTodo;
|
|
9
|
+
exports.todoFileTargets = todoFileTargets;
|
|
10
|
+
exports.clarifiesTodoFileTarget = clarifiesTodoFileTarget;
|
|
9
11
|
exports.workspaceChangeTargets = workspaceChangeTargets;
|
|
10
12
|
exports.executionChecklistIssue = executionChecklistIssue;
|
|
13
|
+
const path_1 = require("path");
|
|
11
14
|
const verification_1 = require("./verification");
|
|
12
15
|
const writeInstruction = /^(?:(?:please|first|then|also)\s+)*(?:implement|add|apply|edit|update|modify|change|adjust|fix|refactor|migrate|remove|rename|replace|rewrite|create|patch|write|wire|introduce|optimi[sz]e)\b|^(?:(?:请|帮我|先|再|同时)\s*)*(?:实现|开发|接入|新增|添加|应用|修改|改动|更新|调整|修复|重构|迁移|移除|删除|替换|重写|创建|编写|优化)/iu;
|
|
13
16
|
const multipleChanges = /\b(?:multi[- ](?:file|step)|cross[- ]file|multiple files|several files|across (?:the )?(?:files|modules|packages))\b|跨文件|跨模块|多步骤|多个文件|多处改动/iu;
|
|
@@ -16,7 +19,7 @@ const fileExtension = /\.[a-z][a-z0-9]{0,7}$/iu;
|
|
|
16
19
|
const referenceClause = /\s+(?:to (?:match|follow|use)|based on|according to|using|after reading|as (?:in|described in))\s+|(?:,|\s)*(?:参考|参照|依据|基于|对照|按照)/iu;
|
|
17
20
|
const checkInstruction = /^(?:(?:verify|validate|check|review)\b|验收|验证|核对|检查|审阅)/iu;
|
|
18
21
|
const sameFileScope = /^(?:(?:edit|modify|change|update)\s+(?:only\s+)?(?:this|that|the same)\s+file(?:\s+only)?|(?:只)?(?:修改|编辑|更新)(?:这个|该|同一)文件)[.,,。]?$/iu;
|
|
19
|
-
exports.TASK_CHECKLIST_REQUIRED = 'Create an execution checklist with todo_write before changing the workspace. Include
|
|
22
|
+
exports.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.';
|
|
20
23
|
function supportsExecutionChecklist(mode) {
|
|
21
24
|
return mode === 'build' || mode === 'auto' || mode === 'goal';
|
|
22
25
|
}
|
|
@@ -51,10 +54,13 @@ function modificationClauses(instruction) {
|
|
|
51
54
|
function pathsInActions(actions) {
|
|
52
55
|
return [
|
|
53
56
|
...new Set(actions.flatMap(action => (action.split(referenceClause, 1)[0].match(pathToken) ?? [])
|
|
54
|
-
.map(
|
|
57
|
+
.map(normalizePathToken)
|
|
55
58
|
.filter(token => fileExtension.test(token)))),
|
|
56
59
|
];
|
|
57
60
|
}
|
|
61
|
+
function normalizePathToken(token) {
|
|
62
|
+
return token.replace(/^\x60|\x60$|\.+$/gu, '');
|
|
63
|
+
}
|
|
58
64
|
function requestedWorkspaceChanges(instruction) {
|
|
59
65
|
const actions = modificationClauses(instruction);
|
|
60
66
|
const paths = pathsInActions(actions);
|
|
@@ -72,7 +78,45 @@ function isVerification(todo) {
|
|
|
72
78
|
return Boolean(todo.verification?.length) || checkInstruction.test(todo.content);
|
|
73
79
|
}
|
|
74
80
|
function isImplementationTodo(todo) {
|
|
75
|
-
return
|
|
81
|
+
return modificationClauses(todo.content).length > 0;
|
|
82
|
+
}
|
|
83
|
+
function isBasename(path) {
|
|
84
|
+
return !/[\\/]/u.test(path);
|
|
85
|
+
}
|
|
86
|
+
function todoFileTargets(content, cwd, taskTargets) {
|
|
87
|
+
return requestedWorkspaceChanges(content).paths.map(declared => {
|
|
88
|
+
const path = (0, verification_1.workspaceArtifactPath)(cwd, declared);
|
|
89
|
+
if (!path)
|
|
90
|
+
return { declared, candidates: [], unscopedBasename: false };
|
|
91
|
+
const bare = isBasename(declared);
|
|
92
|
+
const scoped = bare ? taskTargets.filter(target => (0, path_1.basename)(target) === path) : [];
|
|
93
|
+
return {
|
|
94
|
+
declared,
|
|
95
|
+
candidates: scoped.length ? scoped : [path],
|
|
96
|
+
unscopedBasename: bare && scoped.length === 0,
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/** A clarification changes only an unresolved file token, retaining the todo and its evidence. */
|
|
101
|
+
function clarifiesTodoFileTarget(previous, next, cwd, taskTargets) {
|
|
102
|
+
const original = todoFileTargets(previous.content, cwd, taskTargets);
|
|
103
|
+
const replacement = todoFileTargets(next.content, cwd, taskTargets);
|
|
104
|
+
if (original.length !== replacement.length)
|
|
105
|
+
return false;
|
|
106
|
+
const changed = original.flatMap((from, index) => from.declared === replacement[index].declared ? [] : [{ from, to: replacement[index] }]);
|
|
107
|
+
if (changed.length !== 1)
|
|
108
|
+
return false;
|
|
109
|
+
const [{ from, to }] = changed;
|
|
110
|
+
if (!isBasename(from.declared) || isBasename(to.declared) || (0, path_1.isAbsolute)(to.declared))
|
|
111
|
+
return false;
|
|
112
|
+
const destination = to.candidates[0];
|
|
113
|
+
return (destination !== undefined &&
|
|
114
|
+
(0, path_1.basename)(destination) === from.declared &&
|
|
115
|
+
(from.unscopedBasename || from.candidates.includes(destination)) &&
|
|
116
|
+
withoutTarget(previous.content, from.declared) === withoutTarget(next.content, to.declared));
|
|
117
|
+
}
|
|
118
|
+
function withoutTarget(content, target) {
|
|
119
|
+
return content.replace(pathToken, token => normalizePathToken(token) === target ? '<path>' : token);
|
|
76
120
|
}
|
|
77
121
|
function workspaceChangeTargets(root, paths) {
|
|
78
122
|
return [
|
|
@@ -85,7 +129,7 @@ function executionChecklistIssue(todos, targets, cwd) {
|
|
|
85
129
|
const implementation = todos.filter(isImplementationTodo);
|
|
86
130
|
if (!todos.some(isVerification) || implementation.length === 0)
|
|
87
131
|
return exports.TASK_CHECKLIST_REQUIRED;
|
|
88
|
-
const planned = new Set(
|
|
132
|
+
const planned = new Set(implementation.flatMap(todo => todoFileTargets(todo.content, cwd, targets).flatMap(target => target.candidates.length === 1 ? target.candidates : [])));
|
|
89
133
|
const missing = targets.filter(path => !planned.has(path));
|
|
90
134
|
return missing.length ? `${exports.TASK_CHECKLIST_REQUIRED} Include: ${missing.join(', ')}.` : undefined;
|
|
91
135
|
}
|
package/dist/harness/types.d.ts
CHANGED
|
@@ -252,6 +252,7 @@ export interface HarnessState {
|
|
|
252
252
|
taskChecklistRequired?: boolean;
|
|
253
253
|
taskChecklistTargets?: string[];
|
|
254
254
|
goalTaskId?: string;
|
|
255
|
+
goalVerificationBlocker?: string;
|
|
255
256
|
taskTodos?: (Omit<TaskTodoItem, 'id'> & {
|
|
256
257
|
id?: string;
|
|
257
258
|
})[];
|
|
@@ -310,10 +311,19 @@ export interface CompletionCriterionResult {
|
|
|
310
311
|
status: TaskCriterionStatus;
|
|
311
312
|
applicable: boolean;
|
|
312
313
|
evidenceRefs: string[];
|
|
314
|
+
verificationProblems?: VerificationProblem[];
|
|
313
315
|
requiredKinds: VerificationKind[];
|
|
314
316
|
missingKinds: VerificationKind[];
|
|
315
317
|
failedKinds: VerificationKind[];
|
|
316
318
|
}
|
|
319
|
+
export interface VerificationProblem {
|
|
320
|
+
kind: VerificationKind;
|
|
321
|
+
status: 'failed' | 'stale' | 'missing';
|
|
322
|
+
command?: string;
|
|
323
|
+
cwd?: string;
|
|
324
|
+
exitCode?: number;
|
|
325
|
+
failureFingerprint?: string;
|
|
326
|
+
}
|
|
317
327
|
export interface ProgressSnapshot {
|
|
318
328
|
fingerprint: string;
|
|
319
329
|
criterionStates: Array<{
|
|
@@ -9,13 +9,23 @@ export declare function workspaceArtifactPath(root: string, path: string): strin
|
|
|
9
9
|
export declare function latestArtifactWrite(ledger: readonly ContextLedgerEntry[], contractId: string, cwd: string, path: string): ContextLedgerEntry | undefined;
|
|
10
10
|
export declare function classifyVerificationCommand(command: string | undefined): VerificationKind;
|
|
11
11
|
export declare function requiredVerificationKinds(statement: string): VerificationKind[];
|
|
12
|
-
interface RequestedCheck {
|
|
12
|
+
export interface RequestedCheck {
|
|
13
13
|
readonly kind: VerificationCommandKind;
|
|
14
14
|
readonly command: string;
|
|
15
15
|
readonly cwd?: string;
|
|
16
16
|
}
|
|
17
17
|
/** Quoted commands preserve user-specified test selectors and workspace scope. */
|
|
18
18
|
export declare function requestedLocalChecks(statement: string): RequestedCheck[];
|
|
19
|
+
interface LocatedCheck extends RequestedCheck {
|
|
20
|
+
readonly start: number;
|
|
21
|
+
readonly end: number;
|
|
22
|
+
readonly cwdStart?: number;
|
|
23
|
+
readonly cwdEnd?: number;
|
|
24
|
+
}
|
|
25
|
+
export declare function locateRequestedChecks(statement: string): LocatedCheck[];
|
|
26
|
+
export declare function equalRequestedChecks(left: RequestedCheck, right: RequestedCheck, workspace: string): boolean;
|
|
27
|
+
/** Rewrite only the selected command and its own directory literal. */
|
|
28
|
+
export declare function replaceRequestedCheck(statement: string, previous: RequestedCheck, next: RequestedCheck, workspace: string): string;
|
|
19
29
|
export declare function matchesRequestedCheck(entry: ContextLedgerEntry, check: RequestedCheck, workspace: string): boolean;
|
|
20
30
|
export declare function verificationKindForEntry(entry: ContextLedgerEntry, requireLocalReceipt?: boolean): VerificationKind;
|
|
21
31
|
export declare function isTrustedEvidence(entry: ContextLedgerEntry): boolean;
|
|
@@ -6,6 +6,9 @@ exports.latestArtifactWrite = latestArtifactWrite;
|
|
|
6
6
|
exports.classifyVerificationCommand = classifyVerificationCommand;
|
|
7
7
|
exports.requiredVerificationKinds = requiredVerificationKinds;
|
|
8
8
|
exports.requestedLocalChecks = requestedLocalChecks;
|
|
9
|
+
exports.locateRequestedChecks = locateRequestedChecks;
|
|
10
|
+
exports.equalRequestedChecks = equalRequestedChecks;
|
|
11
|
+
exports.replaceRequestedCheck = replaceRequestedCheck;
|
|
9
12
|
exports.matchesRequestedCheck = matchesRequestedCheck;
|
|
10
13
|
exports.verificationKindForEntry = verificationKindForEntry;
|
|
11
14
|
exports.isTrustedEvidence = isTrustedEvidence;
|
|
@@ -152,6 +155,9 @@ function requiredVerificationKinds(statement) {
|
|
|
152
155
|
}
|
|
153
156
|
/** Quoted commands preserve user-specified test selectors and workspace scope. */
|
|
154
157
|
function requestedLocalChecks(statement) {
|
|
158
|
+
return locateRequestedChecks(statement).map(({ kind, command, cwd }) => ({ kind, command, cwd }));
|
|
159
|
+
}
|
|
160
|
+
function locateRequestedChecks(statement) {
|
|
155
161
|
const checks = [];
|
|
156
162
|
for (const match of statement.matchAll(/\x60([^\x60\r\n]+)\x60/gu)) {
|
|
157
163
|
const [span, literal] = match;
|
|
@@ -164,11 +170,50 @@ function requestedLocalChecks(statement) {
|
|
|
164
170
|
const after = statement.slice(index + span.length);
|
|
165
171
|
const trailing = after.match(/^\s*(?:(?:in|inside|under)\s+|在\s*)\x60([^\x60\r\n]+)\x60/iu);
|
|
166
172
|
const leading = before.match(/(?:\b(?:in|inside|under)\s+|在\s*)\x60([^\x60\r\n]+)\x60\s*(?:中|内|下)?\s*[,,]?\s*(?:run|execute|运行|执行)\s*$/iu);
|
|
167
|
-
const
|
|
168
|
-
|
|
173
|
+
const cwdMatch = trailing ?? leading;
|
|
174
|
+
const cwd = cwdMatch?.[1].trim();
|
|
175
|
+
const cwdStart = cwdMatch
|
|
176
|
+
? (trailing ? index + span.length : (leading?.index ?? 0)) + cwdMatch[0].indexOf('`') + 1
|
|
177
|
+
: undefined;
|
|
178
|
+
checks.push({
|
|
179
|
+
kind,
|
|
180
|
+
command,
|
|
181
|
+
cwd,
|
|
182
|
+
start: index,
|
|
183
|
+
end: index + span.length,
|
|
184
|
+
...(cwdStart === undefined
|
|
185
|
+
? {}
|
|
186
|
+
: { cwdStart, cwdEnd: cwdStart + (cwdMatch?.[1].length ?? 0) }),
|
|
187
|
+
});
|
|
169
188
|
}
|
|
170
189
|
return checks;
|
|
171
190
|
}
|
|
191
|
+
function equalRequestedChecks(left, right, workspace) {
|
|
192
|
+
return (left.kind === right.kind &&
|
|
193
|
+
left.command === right.command &&
|
|
194
|
+
(0, path_1.resolve)(workspace, left.cwd ?? '.') === (0, path_1.resolve)(workspace, right.cwd ?? '.'));
|
|
195
|
+
}
|
|
196
|
+
/** Rewrite only the selected command and its own directory literal. */
|
|
197
|
+
function replaceRequestedCheck(statement, previous, next, workspace) {
|
|
198
|
+
const edits = [];
|
|
199
|
+
for (const check of locateRequestedChecks(statement)) {
|
|
200
|
+
if (!equalRequestedChecks(check, previous, workspace))
|
|
201
|
+
continue;
|
|
202
|
+
const needsDirectory = next.cwd && !check.cwd && (0, path_1.resolve)(workspace, next.cwd) !== workspace;
|
|
203
|
+
edits.push({
|
|
204
|
+
start: check.start,
|
|
205
|
+
end: check.end,
|
|
206
|
+
text: '\x60' + next.command + '\x60' + (needsDirectory ? ' in \x60' + next.cwd + '\x60' : ''),
|
|
207
|
+
});
|
|
208
|
+
if (check.cwdStart !== undefined && check.cwdEnd !== undefined && next.cwd !== check.cwd) {
|
|
209
|
+
edits.push({ start: check.cwdStart, end: check.cwdEnd, text: next.cwd ?? '.' });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
for (const { start, end, text } of edits.sort((left, right) => right.start - left.start)) {
|
|
213
|
+
statement = statement.slice(0, start) + text + statement.slice(end);
|
|
214
|
+
}
|
|
215
|
+
return statement;
|
|
216
|
+
}
|
|
172
217
|
function matchesRequestedCheck(entry, check, workspace) {
|
|
173
218
|
const { command, cwd } = entry.metadata ?? {};
|
|
174
219
|
return (typeof command === 'string' &&
|
|
@@ -186,7 +186,10 @@ class AgentLoopV1 {
|
|
|
186
186
|
const inputs = context.takePendingSteering?.(closeIfEmpty) ?? [];
|
|
187
187
|
for (const input of inputs) {
|
|
188
188
|
taskContextCompletion = undefined;
|
|
189
|
-
|
|
189
|
+
if (goal)
|
|
190
|
+
this.options.taskContext.observeGoalSteering(input, goal.goalId);
|
|
191
|
+
else
|
|
192
|
+
this.options.taskContext.observeUserInput(input);
|
|
190
193
|
}
|
|
191
194
|
return inputs;
|
|
192
195
|
},
|
|
@@ -5,6 +5,7 @@ exports.createBatchReadToolV1 = createBatchReadToolV1;
|
|
|
5
5
|
exports.parseBatchReadStepsV1 = parseBatchReadStepsV1;
|
|
6
6
|
const crypto_1 = require("crypto");
|
|
7
7
|
const tool_artifacts_1 = require("../core/tool-artifacts");
|
|
8
|
+
const utf8_1 = require("../utils/utf8");
|
|
8
9
|
exports.BATCH_READ_SERVICE_VERSION_V1 = 1;
|
|
9
10
|
exports.BATCH_READ_MAX_STEPS_V1 = 8;
|
|
10
11
|
exports.BATCH_READ_CHILD_OUTPUT_BYTES_V1 = 1600;
|
|
@@ -115,13 +116,28 @@ class BatchReadExecutionServiceV1 {
|
|
|
115
116
|
skipped,
|
|
116
117
|
steps: results,
|
|
117
118
|
};
|
|
118
|
-
const
|
|
119
|
+
const stepsPreview = results.map(step => {
|
|
120
|
+
const clipped = (0, utf8_1.truncateToBytes)(step.output, exports.BATCH_READ_CHILD_OUTPUT_BYTES_V1);
|
|
121
|
+
return clipped.text === step.output
|
|
122
|
+
? step
|
|
123
|
+
: { ...step, output: clipped.text, truncated: true };
|
|
124
|
+
});
|
|
125
|
+
const completeOutput = JSON.stringify(payload);
|
|
126
|
+
const outputBytes = Buffer.byteLength(completeOutput, 'utf8');
|
|
127
|
+
const hasClippedStep = stepsPreview.some((step, index) => step !== results[index]);
|
|
128
|
+
const artifact = hasClippedStep
|
|
129
|
+
? (0, tool_artifacts_1.storeArtifact)(input.invocation.context.cwd, 'batch_read', completeOutput, outputBytes)
|
|
130
|
+
: undefined;
|
|
131
|
+
const output = hasClippedStep
|
|
132
|
+
? JSON.stringify({ ...payload, steps: stepsPreview })
|
|
133
|
+
: completeOutput;
|
|
119
134
|
const result = {
|
|
120
135
|
schemaVersion: 1,
|
|
121
136
|
success,
|
|
122
137
|
output,
|
|
123
138
|
summary,
|
|
124
|
-
outputBytes
|
|
139
|
+
outputBytes,
|
|
140
|
+
...(artifact ? { artifactRef: { id: artifact.id, outputBytes: artifact.outputBytes } } : {}),
|
|
125
141
|
...(!success
|
|
126
142
|
? { error: interrupted ? 'batch_read was interrupted.' : `${failed} child step(s) failed.` }
|
|
127
143
|
: {}),
|
|
@@ -181,8 +197,9 @@ function completedStep(index, step, child) {
|
|
|
181
197
|
state: 'completed',
|
|
182
198
|
success: child.receipt.success,
|
|
183
199
|
summary: child.result.summary ?? summarize(raw),
|
|
184
|
-
output:
|
|
185
|
-
outputBytes: Buffer.byteLength(raw, 'utf8'),
|
|
200
|
+
output: raw,
|
|
201
|
+
outputBytes: child.result.outputBytes ?? Buffer.byteLength(raw, 'utf8'),
|
|
202
|
+
...(child.result.artifactRef ? { truncated: true, artifactRef: child.result.artifactRef } : {}),
|
|
186
203
|
invocationId: child.receipt.invocationId,
|
|
187
204
|
receiptDigest: child.receipt.digest,
|
|
188
205
|
terminal: child.receipt.terminal,
|
|
@@ -608,6 +608,7 @@ function defaultContinuationInput(state) {
|
|
|
608
608
|
return [
|
|
609
609
|
'Continue the active Goal using saved state and receipts.',
|
|
610
610
|
`Objective: ${objective}`,
|
|
611
|
+
'Use the current TaskContext verification requirements when the user has corrected a check.',
|
|
611
612
|
'Do not claim completion unless the TaskContext completion gate verifies every criterion.',
|
|
612
613
|
].join('\n');
|
|
613
614
|
}
|
|
@@ -9,6 +9,7 @@ const prompt_context_1 = require("../memory/prompt-context");
|
|
|
9
9
|
const file_context_1 = require("../services/file-context");
|
|
10
10
|
const goal_storage_1 = require("../services/goal-storage");
|
|
11
11
|
const llm_1 = require("../services/llm");
|
|
12
|
+
const redaction_1 = require("../services/redaction");
|
|
12
13
|
const session_storage_1 = require("../services/session-storage");
|
|
13
14
|
const model_registry_1 = require("../services/model-registry");
|
|
14
15
|
const token_estimate_1 = require("../utils/token-estimate");
|
|
@@ -1105,7 +1106,7 @@ async function resolveMcpToolsForStep(input, runtime, catalog) {
|
|
|
1105
1106
|
execute: async (args, context) => {
|
|
1106
1107
|
try {
|
|
1107
1108
|
const result = await binding.invoke(args, context.abortSignal);
|
|
1108
|
-
return
|
|
1109
|
+
return projectMcpResult(result);
|
|
1109
1110
|
}
|
|
1110
1111
|
catch (error) {
|
|
1111
1112
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -1151,11 +1152,32 @@ function normalizeLookup(value) {
|
|
|
1151
1152
|
.replace(/[^\p{L}\p{N}]+/gu, ' ')
|
|
1152
1153
|
.trim();
|
|
1153
1154
|
}
|
|
1155
|
+
function projectMcpResult(value) {
|
|
1156
|
+
const output = renderMcpResult(value);
|
|
1157
|
+
if (!value || typeof value !== 'object' || !('isError' in value) || value.isError !== true) {
|
|
1158
|
+
return { success: true, output };
|
|
1159
|
+
}
|
|
1160
|
+
const content = 'content' in value && Array.isArray(value.content) ? value.content : [];
|
|
1161
|
+
const diagnostic = content.find((item) => !!item &&
|
|
1162
|
+
typeof item === 'object' &&
|
|
1163
|
+
'type' in item &&
|
|
1164
|
+
item.type === 'text' &&
|
|
1165
|
+
'text' in item &&
|
|
1166
|
+
typeof item.text === 'string' &&
|
|
1167
|
+
!!item.text.trim());
|
|
1168
|
+
return {
|
|
1169
|
+
success: false,
|
|
1170
|
+
output,
|
|
1171
|
+
error: diagnostic
|
|
1172
|
+
? (0, redaction_1.redactTraceText)(diagnostic.text.trim()).slice(0, 2048)
|
|
1173
|
+
: 'MCP tool reported an error.',
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1154
1176
|
function renderMcpResult(value) {
|
|
1155
1177
|
if (typeof value === 'string')
|
|
1156
1178
|
return value;
|
|
1157
1179
|
try {
|
|
1158
|
-
return JSON.stringify(value);
|
|
1180
|
+
return JSON.stringify(value) ?? String(value);
|
|
1159
1181
|
}
|
|
1160
1182
|
catch {
|
|
1161
1183
|
return String(value);
|
|
@@ -142,10 +142,8 @@ function recoverInterruptedTaskContext(input) {
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
const goalState = restoreGoalState();
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
'status' in goalState &&
|
|
148
|
-
goalState.status === 'paused' &&
|
|
145
|
+
const interruptedGoal = turn.mode === 'goal' && goalState && 'status' in goalState ? goalState : undefined;
|
|
146
|
+
const goalInterruptedBeforeTools = interruptedGoal?.status === 'paused' &&
|
|
149
147
|
turn.itemIds.every(itemId => projection.items[itemId].kind !== 'command');
|
|
150
148
|
// A Goal can crash on its first provider request, before a task seed is
|
|
151
149
|
// bound to any tool. Persist its pause or a later reopen will see only the
|
|
@@ -178,7 +176,13 @@ function recoverInterruptedTaskContext(input) {
|
|
|
178
176
|
});
|
|
179
177
|
let unconfirmedWorkspaceRevisions = 0;
|
|
180
178
|
for (const event of events) {
|
|
181
|
-
if (
|
|
179
|
+
if (event.seq < checkpoint.event.seq)
|
|
180
|
+
continue;
|
|
181
|
+
if (interruptedGoal && event.payload.type === 'turn.steered') {
|
|
182
|
+
taskContext.observeGoalSteering(event.payload.data.input, interruptedGoal.goalId);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
if (!event.itemId)
|
|
182
186
|
continue;
|
|
183
187
|
const bound = intents.get(event.itemId);
|
|
184
188
|
if (!bound ||
|
|
@@ -207,6 +211,18 @@ function recoverInterruptedTaskContext(input) {
|
|
|
207
211
|
taskContextState = taskContext.exportState();
|
|
208
212
|
taskContextRevision = taskContext.revision;
|
|
209
213
|
}
|
|
214
|
+
else if (interruptedGoal && events.some(event => event.payload.type === 'turn.steered')) {
|
|
215
|
+
// A user correction is durable independently of the first tool in a turn.
|
|
216
|
+
const taskContext = (0, task_context_service_1.createTaskContextService)(taskOptions);
|
|
217
|
+
taskContext.observeUserInput(interruptedGoal.objective, interruptedGoal.goalId);
|
|
218
|
+
for (const event of events) {
|
|
219
|
+
if (event.payload.type === 'turn.steered') {
|
|
220
|
+
taskContext.observeGoalSteering(event.payload.data.input, interruptedGoal.goalId);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
taskContextState = taskContext.exportState();
|
|
224
|
+
taskContextRevision = taskContext.revision;
|
|
225
|
+
}
|
|
210
226
|
if (!taskContextState || taskContextRevision === undefined)
|
|
211
227
|
return;
|
|
212
228
|
const openItems = turn.itemIds
|
|
@@ -3,6 +3,7 @@ import type { PromptAssemblyOptions } from '../harness/assembler';
|
|
|
3
3
|
import type { CreateTurnSummaryInput } from '../harness/turn-summary';
|
|
4
4
|
import type { CapabilityProfileInput, CompletionGateResult, ContextCapsule, DriftCheckResult, HarnessConfig, HarnessProgressState, HarnessState, IntentUpdate, TaskContract, TaskTodoObservation, TaskWorkspaceAction, ToolResultObservation, TurnSummary } from '../harness/types';
|
|
5
5
|
import type { LLMResponse, Message } from '../services/llm';
|
|
6
|
+
import type { TodoWriteAdjustment } from '../framework/tool-state';
|
|
6
7
|
export type DeepReadonly<T> = T extends (...args: never[]) => unknown ? T : T extends readonly (infer U)[] ? readonly DeepReadonly<U>[] : T extends object ? {
|
|
7
8
|
readonly [K in keyof T]: DeepReadonly<T[K]>;
|
|
8
9
|
} : T;
|
|
@@ -63,6 +64,7 @@ export interface TaskContextService {
|
|
|
63
64
|
readonly serviceId: 'task-context';
|
|
64
65
|
readonly revision: number;
|
|
65
66
|
observeUserInput(input: string, goalTaskId?: string): DeepReadonly<IntentUpdate> | undefined;
|
|
67
|
+
observeGoalSteering(input: string, goalId: string): void;
|
|
66
68
|
classifyIntent(input: string): DeepReadonly<IntentUpdate>;
|
|
67
69
|
observeCapability(input: CapabilityProfileInput): DeepReadonly<HarnessState['capabilityProfile']>;
|
|
68
70
|
assembleMessages(messages: Message[], options?: PromptAssemblyOptions): Message[];
|
|
@@ -80,7 +82,7 @@ export interface TaskContextService {
|
|
|
80
82
|
prepareTaskPlanStopCheck(): ReturnType<HarnessKernel['prepareTaskPlanStopCheck']>;
|
|
81
83
|
requiresVerification(): boolean;
|
|
82
84
|
recordTaskTodoReceipt(step: string, observation: TaskTodoObservation): void;
|
|
83
|
-
updateTaskTodos(todos: NonNullable<HarnessState['taskTodos']>, blockedReason?: string): string | undefined;
|
|
85
|
+
updateTaskTodos(todos: NonNullable<HarnessState['taskTodos']>, blockedReason?: string): TodoWriteAdjustment | string | undefined;
|
|
84
86
|
progressState(): HarnessProgressState;
|
|
85
87
|
recordProgress(baseline: HarnessProgressState, unconfirmedWorkspaceRevisions?: number): void;
|
|
86
88
|
auditCompletion(enforceTaskTodos?: boolean, requireEveryCriterion?: boolean): TaskContextCompletionDecisionV1;
|
|
@@ -42,6 +42,9 @@ class HarnessKernelTaskContextService {
|
|
|
42
42
|
this.refreshVerificationWorkspace();
|
|
43
43
|
return result ? immutableClone(result) : undefined;
|
|
44
44
|
}
|
|
45
|
+
observeGoalSteering(input, goalId) {
|
|
46
|
+
this.mutate(() => this.kernel.observeGoalSteering(input, goalId));
|
|
47
|
+
}
|
|
45
48
|
classifyIntent(input) {
|
|
46
49
|
return immutableClone(this.kernel.classifyIntent(input));
|
|
47
50
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Observe file identities at verification boundaries without reading file contents.
|
|
3
|
-
* Git supplies the tracked and nonignored file scope
|
|
4
|
-
*
|
|
3
|
+
* Git supplies the tracked and nonignored file scope, plus the staged object
|
|
4
|
+
* and HEAD identities used by diff checks. Other projects use the filesystem walk.
|
|
5
5
|
*/
|
|
6
6
|
export declare function captureVerificationWorkspace(workspace: string, runtimeDirectories: readonly string[]): string | null;
|
|
7
7
|
//# sourceMappingURL=workspace-verification.d.ts.map
|
|
@@ -15,8 +15,8 @@ const ignoredDirectories = new Set([
|
|
|
15
15
|
]);
|
|
16
16
|
/**
|
|
17
17
|
* Observe file identities at verification boundaries without reading file contents.
|
|
18
|
-
* Git supplies the tracked and nonignored file scope
|
|
19
|
-
*
|
|
18
|
+
* Git supplies the tracked and nonignored file scope, plus the staged object
|
|
19
|
+
* and HEAD identities used by diff checks. Other projects use the filesystem walk.
|
|
20
20
|
*/
|
|
21
21
|
function captureVerificationWorkspace(workspace, runtimeDirectories) {
|
|
22
22
|
try {
|
|
@@ -26,8 +26,13 @@ function captureVerificationWorkspace(workspace, runtimeDirectories) {
|
|
|
26
26
|
.filter(path => path && path !== '..' && !path.startsWith('..' + node_path_1.sep) && !(0, node_path_1.isAbsolute)(path))
|
|
27
27
|
.map(path => path.split(node_path_1.sep).join('/')));
|
|
28
28
|
const gitScope = listGitScope(root);
|
|
29
|
-
const digest = (0, node_crypto_1.createHash)('sha256').update('workspace-verification-
|
|
29
|
+
const digest = (0, node_crypto_1.createHash)('sha256').update('workspace-verification-v2\0' + root + '\0');
|
|
30
30
|
const visit = (directory, prefix, scope, scopeOffset = 0) => {
|
|
31
|
+
if (scope) {
|
|
32
|
+
digest.update('git\0' + prefix + '\0');
|
|
33
|
+
digest.update(scope.head + '\0');
|
|
34
|
+
digest.update(scope.indexDigest + '\0');
|
|
35
|
+
}
|
|
31
36
|
const entries = (0, node_fs_1.readdirSync)(directory, { withFileTypes: true }).sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
|
|
32
37
|
for (const entry of entries) {
|
|
33
38
|
const path = prefix + entry.name;
|
|
@@ -42,7 +47,8 @@ function captureVerificationWorkspace(workspace, runtimeDirectories) {
|
|
|
42
47
|
// A gitlink lists the directory itself only. Inspect its worktree
|
|
43
48
|
// against its own ignore rules rather than hashing the gitlink alone.
|
|
44
49
|
if (scope?.files.has(scopedPath) && !scope.ancestors.has(scopedPath)) {
|
|
45
|
-
|
|
50
|
+
const nested = (0, node_fs_1.existsSync)((0, node_path_1.join)(absolute, '.git')) ? listGitScope(absolute) : undefined;
|
|
51
|
+
visit(absolute, path + '/', nested, path.length + 1);
|
|
46
52
|
}
|
|
47
53
|
else {
|
|
48
54
|
visit(absolute, path + '/', scope, scopeOffset);
|
|
@@ -68,16 +74,25 @@ function listGitScope(root) {
|
|
|
68
74
|
return undefined;
|
|
69
75
|
search = parent;
|
|
70
76
|
}
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
77
|
+
const options = { cwd: root, timeout: 2000, maxBuffer: 8 * 1024 * 1024 };
|
|
78
|
+
const listed = (0, node_child_process_1.spawnSync)('git', ['ls-files', '--cached', '--others', '--exclude-standard', '-z', '--', '.'], options);
|
|
79
|
+
const staged = (0, node_child_process_1.spawnSync)('git', ['ls-files', '--stage', '-z', '--', '.'], options);
|
|
80
|
+
const head = (0, node_child_process_1.spawnSync)('git', ['rev-parse', '--verify', '--quiet', 'HEAD'], options);
|
|
81
|
+
if (listed.status !== 0 || staged.status !== 0 || (head.status !== 0 && head.status !== 1)) {
|
|
82
|
+
throw new Error('Git verification scope could not be observed.');
|
|
83
|
+
}
|
|
84
|
+
const files = new Set(listed.stdout.toString('utf8').split('\0').filter(Boolean));
|
|
75
85
|
const ancestors = new Set();
|
|
76
86
|
for (const path of files) {
|
|
77
87
|
for (let slash = path.indexOf('/'); slash >= 0; slash = path.indexOf('/', slash + 1)) {
|
|
78
88
|
ancestors.add(path.slice(0, slash));
|
|
79
89
|
}
|
|
80
90
|
}
|
|
81
|
-
return {
|
|
91
|
+
return {
|
|
92
|
+
files,
|
|
93
|
+
ancestors,
|
|
94
|
+
head: head.stdout.toString('utf8').trim(),
|
|
95
|
+
indexDigest: (0, node_crypto_1.createHash)('sha256').update(staged.stdout).digest('hex'),
|
|
96
|
+
};
|
|
82
97
|
}
|
|
83
98
|
//# sourceMappingURL=workspace-verification.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
import { Stream } from 'openai/core/streaming';
|
|
3
|
+
/** Keep the SDK's SSE framing while exposing the Chat Completions end marker. */
|
|
4
|
+
export declare class ChatCompletionSseStream<Chunk> extends Stream<Chunk> {
|
|
5
|
+
private doneEvent;
|
|
6
|
+
get sawDoneEvent(): boolean;
|
|
7
|
+
static fromSSEResponse<Item>(response: Response, controller: AbortController, client?: OpenAI): ChatCompletionSseStream<Item>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=chat-completion-sse.d.ts.map
|