@orion-agents/orion-code 0.4.4 → 0.4.6
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 +15 -0
- package/README.md +4 -4
- package/README.zh-CN.md +4 -4
- package/dist/commands/context-commands.js +16 -28
- package/dist/commands/context-tool-command-handlers.d.ts +2 -3
- package/dist/commands/context-tool-command-handlers.js +2 -20
- package/dist/commands/registry.js +24 -61
- package/dist/commands/retired-commands.d.ts +2 -0
- package/dist/commands/retired-commands.js +24 -0
- package/dist/commands/session-command-handlers.d.ts +3 -2
- package/dist/commands/session-command-handlers.js +41 -42
- package/dist/commands/session-commands.js +21 -0
- package/dist/commands/system-commands.js +2 -27
- package/dist/commands/tool-commands.js +0 -10
- package/dist/commands/types.d.ts +6 -4
- package/dist/commands/workflow-commands.js +0 -24
- package/dist/core/tool-artifacts.js +17 -4
- package/dist/framework/query.js +151 -17
- package/dist/framework/tool-state.d.ts +4 -0
- package/dist/harness/context-harness.d.ts +7 -3
- package/dist/harness/context-harness.js +222 -48
- 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/stop-controller.js +1 -1
- 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/agent-runtime-controller.d.ts +4 -2
- package/dist/runtime/agent-runtime-controller.js +115 -30
- package/dist/runtime/batch-read-service.js +21 -4
- package/dist/runtime/goal-runtime-coordinator.js +1 -0
- package/dist/runtime/orion-session-runner.js +3 -5
- package/dist/runtime/product-bootstrap.js +24 -11
- 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/ui-events.d.ts +4 -1
- package/dist/runtime/ui-view-model.js +7 -3
- 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/skills/builtin/security-check/SKILL.md +2 -2
- package/dist/skills/builtin/test-gen/SKILL.md +2 -2
- package/dist/terminal-ui/launch.js +1 -1
- 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/tui-ui/launch.js +4 -1
- package/dist/tui-ui/layout.d.ts +2 -2
- package/dist/tui-ui/layout.js +59 -47
- package/dist/tui-ui/pickers.d.ts +3 -1
- package/dist/tui-ui/pickers.js +17 -11
- package/dist/tui-ui/runner.d.ts +1 -1
- package/dist/tui-ui/runner.js +61 -68
- package/dist/tui-ui/state.d.ts +4 -0
- package/dist/tui-ui/state.js +33 -2
- package/dist/utils/utf8.d.ts +6 -0
- package/dist/utils/utf8.js +14 -0
- package/docs/cli-guide.md +27 -3
- 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
|
},
|
|
@@ -74,6 +74,7 @@ export declare class AgentRuntimeController {
|
|
|
74
74
|
private readonly agentModeLifecycle;
|
|
75
75
|
private readonly pendingPermissions;
|
|
76
76
|
private activeRun;
|
|
77
|
+
private sessionChange?;
|
|
77
78
|
private activeReview?;
|
|
78
79
|
private pendingAgentMode;
|
|
79
80
|
private readonly goalControlRuns;
|
|
@@ -111,8 +112,6 @@ export declare class AgentRuntimeController {
|
|
|
111
112
|
};
|
|
112
113
|
/** Goal controls remain available while a turn is active only when they can stop or inspect it. */
|
|
113
114
|
canInterceptTargetCommand(input: string, duringActiveTurn: boolean): boolean;
|
|
114
|
-
/** v0.1.1: emit clear_view event through the renderer protocol. */
|
|
115
|
-
emitClearView(): void;
|
|
116
115
|
/** v0.1.1: emit shutdown_requested event through the renderer protocol. */
|
|
117
116
|
emitShutdownRequested(reason?: string): void;
|
|
118
117
|
setVerificationState(state: 'pending' | 'running' | 'passed' | 'failed' | 'gated'): void;
|
|
@@ -129,9 +128,12 @@ export declare class AgentRuntimeController {
|
|
|
129
128
|
private nextPendingFollowup;
|
|
130
129
|
private manageFollowupQueue;
|
|
131
130
|
submit(input: string): AgentRuntimeSubmitResult;
|
|
131
|
+
private rejectDuringSessionChange;
|
|
132
132
|
private emitImmediateCommandSnapshot;
|
|
133
133
|
private runTrackedReview;
|
|
134
134
|
private runCommand;
|
|
135
|
+
private activateSessionRuntime;
|
|
136
|
+
private startNewSession;
|
|
135
137
|
private createCommandContext;
|
|
136
138
|
private submitTurnRequest;
|
|
137
139
|
interrupt(): AgentRuntimeInterruptResult;
|
|
@@ -4,6 +4,7 @@ exports.AgentRuntimeController = exports.FollowupQueueConflictError = void 0;
|
|
|
4
4
|
const async_hooks_1 = require("async_hooks");
|
|
5
5
|
const commands_1 = require("../commands");
|
|
6
6
|
const parser_1 = require("../commands/parser");
|
|
7
|
+
const retired_commands_1 = require("../commands/retired-commands");
|
|
7
8
|
const target_command_1 = require("../commands/target-command");
|
|
8
9
|
const agent_runtime_protocol_1 = require("./agent-runtime-protocol");
|
|
9
10
|
const agent_status_1 = require("./agent-status");
|
|
@@ -11,6 +12,7 @@ const ui_events_1 = require("./ui-events");
|
|
|
11
12
|
const turn_controller_1 = require("./turn-controller");
|
|
12
13
|
const agent_mode_1 = require("../framework/agent-mode");
|
|
13
14
|
const redaction_1 = require("../services/redaction");
|
|
15
|
+
const session_storage_1 = require("../services/session-storage");
|
|
14
16
|
const style_1 = require("../tui-core/style");
|
|
15
17
|
const followup_queue_store_1 = require("./followup-queue-store");
|
|
16
18
|
const runtime_protocol_v1_1 = require("./protocol/runtime-protocol-v1");
|
|
@@ -23,10 +25,6 @@ class FollowupQueueConflictError extends Error {
|
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
exports.FollowupQueueConflictError = FollowupQueueConflictError;
|
|
26
|
-
function isExitInput(input) {
|
|
27
|
-
const parsed = (0, parser_1.parseInput)(input.trim());
|
|
28
|
-
return parsed.isCommand && ['exit', 'quit', 'q'].includes(parsed.name);
|
|
29
|
-
}
|
|
30
28
|
function submittedEntry(input) {
|
|
31
29
|
const parsed = (0, parser_1.parseInput)(input.trim());
|
|
32
30
|
return {
|
|
@@ -180,6 +178,9 @@ class AgentRuntimeController {
|
|
|
180
178
|
}
|
|
181
179
|
/** Thin /goal control surface; GoalRuntimeCoordinatorV2 owns every mutation. */
|
|
182
180
|
handleTargetInput(rawInput) {
|
|
181
|
+
if (this.sessionChange) {
|
|
182
|
+
return { handled: true, runtimeResult: this.rejectDuringSessionChange() };
|
|
183
|
+
}
|
|
183
184
|
const parsed = (0, target_command_1.parseTargetCommand)(rawInput);
|
|
184
185
|
if (!parsed.ok) {
|
|
185
186
|
this.emitAppend({
|
|
@@ -209,10 +210,6 @@ class AgentRuntimeController {
|
|
|
209
210
|
return true;
|
|
210
211
|
return ['status', 'pause', 'clear'].includes(parsed.input.action);
|
|
211
212
|
}
|
|
212
|
-
/** v0.1.1: emit clear_view event through the renderer protocol. */
|
|
213
|
-
emitClearView() {
|
|
214
|
-
this.eventSink.emit({ type: 'clear_view' });
|
|
215
|
-
}
|
|
216
213
|
/** v0.1.1: emit shutdown_requested event through the renderer protocol. */
|
|
217
214
|
emitShutdownRequested(reason) {
|
|
218
215
|
this.runner.interrupt?.(reason ?? 'shutdown requested');
|
|
@@ -234,7 +231,9 @@ class AgentRuntimeController {
|
|
|
234
231
|
case 'queue_followup':
|
|
235
232
|
return this.queueFollowup(input.text, input.resolvedText);
|
|
236
233
|
case 'manage_followup_queue':
|
|
237
|
-
return this.
|
|
234
|
+
return this.sessionChange
|
|
235
|
+
? this.rejectDuringSessionChange()
|
|
236
|
+
: this.manageFollowupQueue(input.action, input.itemId);
|
|
238
237
|
case 'select_session':
|
|
239
238
|
return this.submit(resumeSessionInput(input.sessionId, input.allProjects));
|
|
240
239
|
case 'permission_decision':
|
|
@@ -247,13 +246,15 @@ class AgentRuntimeController {
|
|
|
247
246
|
case 'goal_control':
|
|
248
247
|
return this.startGoalControl(input);
|
|
249
248
|
case 'cycle_agent_mode':
|
|
250
|
-
return this.cycleAgentMode();
|
|
249
|
+
return this.sessionChange ? this.rejectDuringSessionChange() : this.cycleAgentMode();
|
|
251
250
|
case 'set_agent_mode':
|
|
252
251
|
return this.setAgentMode(input.mode);
|
|
253
252
|
}
|
|
254
253
|
}
|
|
255
254
|
/** Set an exact mode immediately while idle, or at the next logical-request boundary. */
|
|
256
255
|
setAgentMode(mode) {
|
|
256
|
+
if (this.sessionChange)
|
|
257
|
+
return this.rejectDuringSessionChange();
|
|
257
258
|
const deferred = this.turnController.hasActiveTurn();
|
|
258
259
|
if (!deferred) {
|
|
259
260
|
this.pendingAgentMode = null;
|
|
@@ -413,30 +414,37 @@ class AgentRuntimeController {
|
|
|
413
414
|
const submitted = input.trim();
|
|
414
415
|
if (!submitted)
|
|
415
416
|
return { type: 'empty' };
|
|
416
|
-
|
|
417
|
+
const parsedInput = (0, parser_1.parseInput)(submitted);
|
|
418
|
+
const command = parsedInput.canonicalName ? (0, commands_1.findCommand)(parsedInput.canonicalName) : undefined;
|
|
419
|
+
if (command?.name === 'quit') {
|
|
417
420
|
this.emitShutdownRequested('user request');
|
|
418
421
|
return { type: 'exit_requested' };
|
|
419
422
|
}
|
|
423
|
+
if (parsedInput.isCommand) {
|
|
424
|
+
const retired = (0, retired_commands_1.retiredCommandNotice)(parsedInput.name, parsedInput.args);
|
|
425
|
+
if (retired || !command) {
|
|
426
|
+
const message = retired ?? `Unknown command /${parsedInput.name}. Use /help to list supported commands.`;
|
|
427
|
+
this.emitAppend({
|
|
428
|
+
role: 'error',
|
|
429
|
+
title: retired ? 'retired command' : 'unknown command',
|
|
430
|
+
content: message,
|
|
431
|
+
});
|
|
432
|
+
this.emitStatus(message);
|
|
433
|
+
return { type: 'command_handled' };
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
if (this.sessionChange)
|
|
437
|
+
return this.rejectDuringSessionChange(command);
|
|
420
438
|
if ((0, target_command_1.isTargetCommand)(submitted)) {
|
|
421
439
|
return this.handleTargetInput(submitted).runtimeResult;
|
|
422
440
|
}
|
|
423
|
-
|
|
424
|
-
if (parsedInput.isCommand && parsedInput.name === 'clear') {
|
|
425
|
-
this.emitClearView();
|
|
426
|
-
this.emitStatus('View cleared. Conversation context is preserved.');
|
|
427
|
-
return { type: 'command_handled' };
|
|
428
|
-
}
|
|
429
|
-
if (parsedInput.isCommand && !(0, commands_1.findCommand)(parsedInput.name)) {
|
|
430
|
-
const message = `Unknown command /${parsedInput.name}. Use /help to list supported commands.`;
|
|
431
|
-
this.emitAppend({ role: 'error', title: 'unknown command', content: message });
|
|
432
|
-
this.emitStatus(message);
|
|
433
|
-
return { type: 'command_handled' };
|
|
434
|
-
}
|
|
435
|
-
if (parsedInput.isCommand) {
|
|
436
|
-
const command = (0, commands_1.findCommand)(parsedInput.name);
|
|
441
|
+
if (command) {
|
|
437
442
|
const isReview = command.name === 'review';
|
|
438
|
-
|
|
439
|
-
|
|
443
|
+
const changesSession = ['new', 'rename', 'resume'].includes(command.name) ||
|
|
444
|
+
(command.name === 'session' && /^rename(?:\s|$)/u.test(parsedInput.args));
|
|
445
|
+
if ((isReview || changesSession) &&
|
|
446
|
+
(this.activeRun || this.goalControlRuns.size > 0 || this.goalRuntimeActive || this.stopping)) {
|
|
447
|
+
this.emitStatus(`/${command.name} rejected: an agent operation is active.`);
|
|
440
448
|
return { type: 'command_rejected_busy', commandId: command.id };
|
|
441
449
|
}
|
|
442
450
|
if (this.hasActiveTurn()) {
|
|
@@ -458,11 +466,15 @@ class AgentRuntimeController {
|
|
|
458
466
|
this.emitStatus(`Queued /${command.name}; it will apply after the active logical request.`);
|
|
459
467
|
return { type: 'command_queued', commandId: command.id };
|
|
460
468
|
}
|
|
469
|
+
if (changesSession)
|
|
470
|
+
this.sessionChange = command.name;
|
|
461
471
|
const run = (isReview
|
|
462
472
|
? this.runTrackedReview(command, parsedInput.args)
|
|
463
473
|
: this.runCommand(command, parsedInput.args))
|
|
464
474
|
.catch(error => this.handleCommandError(command, error))
|
|
465
475
|
.finally(() => {
|
|
476
|
+
if (changesSession)
|
|
477
|
+
this.sessionChange = undefined;
|
|
466
478
|
if (this.activeRun === run)
|
|
467
479
|
this.activeRun = null;
|
|
468
480
|
});
|
|
@@ -495,6 +507,12 @@ class AgentRuntimeController {
|
|
|
495
507
|
};
|
|
496
508
|
return this.submitTurnRequest(request);
|
|
497
509
|
}
|
|
510
|
+
rejectDuringSessionChange(command) {
|
|
511
|
+
this.emitStatus(`Wait for /${this.sessionChange} to finish changing the session.`);
|
|
512
|
+
return command
|
|
513
|
+
? { type: 'command_rejected_busy', commandId: command.id }
|
|
514
|
+
: { type: 'command_ignored' };
|
|
515
|
+
}
|
|
498
516
|
emitImmediateCommandSnapshot(name) {
|
|
499
517
|
const snapshot = this.options.runtime.store.getSnapshot?.() ?? {
|
|
500
518
|
currentModel: this.options.runtime.config.model ?? 'unknown',
|
|
@@ -615,7 +633,70 @@ class AgentRuntimeController {
|
|
|
615
633
|
});
|
|
616
634
|
}
|
|
617
635
|
}
|
|
636
|
+
async activateSessionRuntime(selected, activation, projection) {
|
|
637
|
+
const { runtime } = this.options;
|
|
638
|
+
const previous = runtime.getSession();
|
|
639
|
+
const snapshot = runtime.store.getSnapshot();
|
|
640
|
+
const previousGoalActive = this.goalRuntimeActive;
|
|
641
|
+
try {
|
|
642
|
+
runtime.setSession(selected);
|
|
643
|
+
if (projection)
|
|
644
|
+
runtime.store.setState(projection);
|
|
645
|
+
await this.runner.restoreSession?.(activation);
|
|
646
|
+
}
|
|
647
|
+
catch (error) {
|
|
648
|
+
runtime.setSession(previous);
|
|
649
|
+
this.goalRuntimeActive = previousGoalActive;
|
|
650
|
+
runtime.store.setState({
|
|
651
|
+
conversationHistory: snapshot.conversationHistory,
|
|
652
|
+
tokenUsage: snapshot.tokenUsage,
|
|
653
|
+
contextUsage: snapshot.contextUsage,
|
|
654
|
+
harnessState: snapshot.harnessState,
|
|
655
|
+
lastLoopStats: snapshot.lastLoopStats,
|
|
656
|
+
currentPlan: snapshot.currentPlan,
|
|
657
|
+
todos: snapshot.todos,
|
|
658
|
+
agentMode: snapshot.agentMode,
|
|
659
|
+
planMode: snapshot.planMode,
|
|
660
|
+
planReturnMode: snapshot.planReturnMode,
|
|
661
|
+
});
|
|
662
|
+
if (previous) {
|
|
663
|
+
try {
|
|
664
|
+
(0, session_storage_1.resumeSession)(previous.id);
|
|
665
|
+
await this.runner.restoreSession?.();
|
|
666
|
+
}
|
|
667
|
+
catch (restoreError) {
|
|
668
|
+
const startFailure = error instanceof Error ? error.message : String(error);
|
|
669
|
+
const rollbackFailure = restoreError instanceof Error ? restoreError.message : String(restoreError);
|
|
670
|
+
throw new Error(`Could not switch sessions (${startFailure}) or reopen the previous runtime (${rollbackFailure}).`);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
throw error;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
async startNewSession(createSession) {
|
|
677
|
+
if (this.stopping)
|
|
678
|
+
throw new Error('The runtime is shutting down.');
|
|
679
|
+
const created = createSession();
|
|
680
|
+
await this.activateSessionRuntime(created);
|
|
681
|
+
this.queuedCommands.length = 0;
|
|
682
|
+
this.turnController.clearExitIntent();
|
|
683
|
+
this.agentModeLifecycle.setMode('interactive');
|
|
684
|
+
this.eventSink.emit({ type: 'transcript_replace', entries: [] });
|
|
685
|
+
this.eventSink.emit({
|
|
686
|
+
type: 'session_restored',
|
|
687
|
+
event: {
|
|
688
|
+
reason: 'new',
|
|
689
|
+
sessionId: created.id,
|
|
690
|
+
projectPath: created.projectPath,
|
|
691
|
+
model: created.model,
|
|
692
|
+
restoredMessages: 0,
|
|
693
|
+
messageCount: 0,
|
|
694
|
+
},
|
|
695
|
+
});
|
|
696
|
+
return created;
|
|
697
|
+
}
|
|
618
698
|
createCommandContext(abortSignal) {
|
|
699
|
+
const createFreshSession = this.options.runtime.createFreshSession;
|
|
619
700
|
const renderer = this.options.uiRenderer ?? this.options.runtime.config.ui?.renderer ?? 'terminal';
|
|
620
701
|
return {
|
|
621
702
|
cwd: this.options.runtime.cwd,
|
|
@@ -628,9 +709,12 @@ class AgentRuntimeController {
|
|
|
628
709
|
sessionComposerControls: this.options.runtime.sessionComposerControls,
|
|
629
710
|
sessionId: this.options.runtime.getSession()?.id,
|
|
630
711
|
ensureSession: this.options.runtime.ensureSession,
|
|
712
|
+
startNewSession: createFreshSession
|
|
713
|
+
? () => this.startNewSession(createFreshSession)
|
|
714
|
+
: undefined,
|
|
631
715
|
setSession: session => this.options.runtime.setSession(session),
|
|
632
|
-
|
|
633
|
-
? activation => this.
|
|
716
|
+
activateSessionRuntime: this.runner.restoreSession
|
|
717
|
+
? (session, activation, projection) => this.activateSessionRuntime(session, activation, projection)
|
|
634
718
|
: undefined,
|
|
635
719
|
sessionRestored: event => this.eventSink.emit({ type: 'session_restored', event }),
|
|
636
720
|
...((renderer === 'terminal' || renderer === 'tui') && {
|
|
@@ -645,7 +729,6 @@ class AgentRuntimeController {
|
|
|
645
729
|
if (text?.trim())
|
|
646
730
|
this.emitAppend({ role: 'system', content: text });
|
|
647
731
|
},
|
|
648
|
-
clearView: () => this.emitClearView(),
|
|
649
732
|
requestShutdown: reason => this.emitShutdownRequested(reason),
|
|
650
733
|
uiRenderer: renderer,
|
|
651
734
|
uiCapabilities: (0, ui_events_1.resolveUiRendererCapabilities)(this.options.uiCapabilities, renderer),
|
|
@@ -1065,6 +1148,8 @@ class AgentRuntimeController {
|
|
|
1065
1148
|
});
|
|
1066
1149
|
}
|
|
1067
1150
|
startGoalControl(control) {
|
|
1151
|
+
if (this.sessionChange)
|
|
1152
|
+
return this.rejectDuringSessionChange();
|
|
1068
1153
|
const goalControl = normalizeGoalRuntimeControl(control);
|
|
1069
1154
|
if (!this.runner.controlGoal) {
|
|
1070
1155
|
const message = 'Goal runtime is unavailable for the active product session.';
|