@orion-agents/orion-code 0.4.5 → 0.4.7
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 +7 -7
- package/README.zh-CN.md +7 -7
- 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/framework/query.js +1 -1
- package/dist/framework/verification-command.d.ts +2 -0
- package/dist/framework/verification-command.js +16 -4
- package/dist/harness/assembler.d.ts +1 -0
- package/dist/harness/assembler.js +5 -2
- package/dist/harness/clarification.d.ts +3 -0
- package/dist/harness/clarification.js +56 -0
- package/dist/harness/context-harness.d.ts +1 -1
- package/dist/harness/context-harness.js +33 -5
- package/dist/harness/contract.js +36 -10
- package/dist/harness/drift-guard.js +12 -4
- package/dist/harness/goal-verification.d.ts +2 -0
- package/dist/harness/goal-verification.js +42 -0
- package/dist/harness/intent.js +10 -12
- package/dist/harness/state.js +15 -2
- package/dist/harness/stop-controller.js +1 -1
- package/dist/harness/task-checklist.js +1 -1
- package/dist/harness/verification.d.ts +2 -0
- package/dist/harness/verification.js +16 -5
- package/dist/runtime/agent-loop.js +49 -27
- package/dist/runtime/agent-runtime-controller.d.ts +4 -2
- package/dist/runtime/agent-runtime-controller.js +116 -31
- package/dist/runtime/orion-session-runner.js +3 -5
- package/dist/runtime/plan-review.d.ts +1 -0
- package/dist/runtime/plan-review.js +12 -7
- package/dist/runtime/product-bootstrap.js +24 -11
- package/dist/runtime/product-orion-runtime.js +1 -1
- package/dist/runtime/step-snapshot.d.ts +1 -0
- package/dist/runtime/step-snapshot.js +2 -1
- package/dist/runtime/task-context-recovery.js +15 -7
- package/dist/runtime/tool-gateway.js +1 -0
- package/dist/runtime/ui-events.d.ts +4 -1
- package/dist/runtime/ui-view-model.js +7 -3
- 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/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/docs/cli-guide.md +24 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@ export declare function requestedFileArtifact(statement: string): {
|
|
|
8
8
|
export declare function workspaceArtifactPath(root: string, path: string): string | undefined;
|
|
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
|
+
export declare function isVerificationReplacement(statement: string): boolean;
|
|
11
12
|
export declare function requiredVerificationKinds(statement: string): VerificationKind[];
|
|
12
13
|
export interface RequestedCheck {
|
|
13
14
|
readonly kind: VerificationCommandKind;
|
|
@@ -27,6 +28,7 @@ export declare function equalRequestedChecks(left: RequestedCheck, right: Reques
|
|
|
27
28
|
/** Rewrite only the selected command and its own directory literal. */
|
|
28
29
|
export declare function replaceRequestedCheck(statement: string, previous: RequestedCheck, next: RequestedCheck, workspace: string): string;
|
|
29
30
|
export declare function matchesRequestedCheck(entry: ContextLedgerEntry, check: RequestedCheck, workspace: string): boolean;
|
|
31
|
+
export declare function matchesRequestedCheckInvocation(command: string, cwd: string | undefined, check: RequestedCheck, workspace: string): boolean;
|
|
30
32
|
export declare function verificationKindForEntry(entry: ContextLedgerEntry, requireLocalReceipt?: boolean): VerificationKind;
|
|
31
33
|
export declare function isTrustedEvidence(entry: ContextLedgerEntry): boolean;
|
|
32
34
|
export declare function isFreshVerification(entry: ContextLedgerEntry, workspaceRevision?: number): boolean;
|
|
@@ -4,12 +4,14 @@ exports.requestedFileArtifact = requestedFileArtifact;
|
|
|
4
4
|
exports.workspaceArtifactPath = workspaceArtifactPath;
|
|
5
5
|
exports.latestArtifactWrite = latestArtifactWrite;
|
|
6
6
|
exports.classifyVerificationCommand = classifyVerificationCommand;
|
|
7
|
+
exports.isVerificationReplacement = isVerificationReplacement;
|
|
7
8
|
exports.requiredVerificationKinds = requiredVerificationKinds;
|
|
8
9
|
exports.requestedLocalChecks = requestedLocalChecks;
|
|
9
10
|
exports.locateRequestedChecks = locateRequestedChecks;
|
|
10
11
|
exports.equalRequestedChecks = equalRequestedChecks;
|
|
11
12
|
exports.replaceRequestedCheck = replaceRequestedCheck;
|
|
12
13
|
exports.matchesRequestedCheck = matchesRequestedCheck;
|
|
14
|
+
exports.matchesRequestedCheckInvocation = matchesRequestedCheckInvocation;
|
|
13
15
|
exports.verificationKindForEntry = verificationKindForEntry;
|
|
14
16
|
exports.isTrustedEvidence = isTrustedEvidence;
|
|
15
17
|
exports.isFreshVerification = isFreshVerification;
|
|
@@ -96,6 +98,11 @@ function classifyVerificationCommand(command) {
|
|
|
96
98
|
}
|
|
97
99
|
return 'generic';
|
|
98
100
|
}
|
|
101
|
+
function isVerificationReplacement(statement) {
|
|
102
|
+
const prose = statement.replace(/\x60[^\x60]+\x60/gu, ' ').trim();
|
|
103
|
+
return (/^(?:please\s+)?(?:replace|change|switch)\s+(?:(?:the|previous|old|current|required|generic|unbound|unspecified|workflow)\s+)*(?:verification|check)\s+(?:with|to)\b/iu.test(prose) ||
|
|
104
|
+
/^(?:请\s*)?(?:(?:把|将)\s*)?(?:原来的?|之前的?|前面的?|当前的?|通用的?|未指定的?|工作流的?)*(?:验证|检查)\s*(?:改为|改成|换成|换为|替换为|指定为|绑定到)/u.test(prose));
|
|
105
|
+
}
|
|
99
106
|
function requiredVerificationKinds(statement) {
|
|
100
107
|
const normalized = statement.toLowerCase();
|
|
101
108
|
const englishAction = /^(?:please\s+)?(?:run|execute|verify|validate|check|ensure)\b/u.test(normalized) ||
|
|
@@ -107,7 +114,7 @@ function requiredVerificationKinds(statement) {
|
|
|
107
114
|
// do not add an obligation to pass a separate verification command.
|
|
108
115
|
const chineseAction = /(?:必须|需要|要求|确保|请|(?<!可)(?:运行|执行)|通过|完成|成功).{0,60}(?:测试|验证|构建|编译|检查|发布|提交|推送|流水线)/u.test(statement) ||
|
|
109
116
|
/(?:测试|验证|构建|编译|检查|发布|提交|推送|流水线).{0,60}(?:必须|需要|要求|确保|通过|成功|(?<!可)(?:运行|执行)|完成)/u.test(statement);
|
|
110
|
-
if (!englishAction && !chineseAction)
|
|
117
|
+
if (!englishAction && !chineseAction && !isVerificationReplacement(statement))
|
|
111
118
|
return [];
|
|
112
119
|
const checks = requestedLocalChecks(statement);
|
|
113
120
|
const prose = normalized.replace(/\x60[^\x60]+\x60/gu, '');
|
|
@@ -162,7 +169,7 @@ function locateRequestedChecks(statement) {
|
|
|
162
169
|
for (const match of statement.matchAll(/\x60([^\x60\r\n]+)\x60/gu)) {
|
|
163
170
|
const [span, literal] = match;
|
|
164
171
|
const command = literal.trim();
|
|
165
|
-
const kind = (0, verification_command_1.
|
|
172
|
+
const kind = (0, verification_command_1.classifyVerificationSelector)(command);
|
|
166
173
|
if (!kind)
|
|
167
174
|
continue;
|
|
168
175
|
const index = match.index ?? 0;
|
|
@@ -217,9 +224,13 @@ function replaceRequestedCheck(statement, previous, next, workspace) {
|
|
|
217
224
|
function matchesRequestedCheck(entry, check, workspace) {
|
|
218
225
|
const { command, cwd } = entry.metadata ?? {};
|
|
219
226
|
return (typeof command === 'string' &&
|
|
220
|
-
command
|
|
221
|
-
|
|
222
|
-
|
|
227
|
+
matchesRequestedCheckInvocation(command, typeof cwd === 'string' ? cwd : undefined, check, workspace));
|
|
228
|
+
}
|
|
229
|
+
function matchesRequestedCheckInvocation(command, cwd, check, workspace) {
|
|
230
|
+
return (command.trim() === check.command &&
|
|
231
|
+
(check.kind === 'generic'
|
|
232
|
+
? cwd !== undefined && (0, path_1.resolve)(workspace, cwd) === (0, path_1.resolve)(workspace, check.cwd ?? '.')
|
|
233
|
+
: !check.cwd || (0, path_1.resolve)(workspace, cwd ?? '.') === (0, path_1.resolve)(workspace, check.cwd)));
|
|
223
234
|
}
|
|
224
235
|
function verificationKindForEntry(entry, requireLocalReceipt = false) {
|
|
225
236
|
const stored = entry.metadata?.verificationKind;
|
|
@@ -49,7 +49,8 @@ class AgentLoopV1 {
|
|
|
49
49
|
? (0, task_context_recovery_1.createTaskRecoveryBinder)(this.options.taskContext, this.options.previousCommitDigest, progressAtAdmission)
|
|
50
50
|
: undefined;
|
|
51
51
|
const goal = context.mode === 'goal' ? this.options.resolveGoalTask?.() : undefined;
|
|
52
|
-
this.options.taskContext.observeUserInput(goal?.objective ?? context.input, goal?.goalId);
|
|
52
|
+
const intent = this.options.taskContext.observeUserInput(goal?.objective ?? context.input, goal?.goalId);
|
|
53
|
+
let answeringQuestion = (context.mode === 'build' || context.mode === 'auto') && intent?.kind === 'clarification';
|
|
53
54
|
const messages = (await this.options.loadBaseMessages(context)).map(message => ({
|
|
54
55
|
...message,
|
|
55
56
|
}));
|
|
@@ -122,9 +123,12 @@ class AgentLoopV1 {
|
|
|
122
123
|
},
|
|
123
124
|
};
|
|
124
125
|
const executionChecklist = this.options.enableTaskTodos === true && (0, task_checklist_1.supportsExecutionChecklist)(context.mode);
|
|
126
|
+
const checkTaskPlanStop = executionChecklist
|
|
127
|
+
? this.options.taskContext.prepareTaskPlanStopCheck()
|
|
128
|
+
: undefined;
|
|
125
129
|
const harness = createQueryTaskContextAdapter(this.options.taskContext, decision => {
|
|
126
130
|
taskContextCompletion = decision;
|
|
127
|
-
}, context.mode === 'plan', executionChecklist, context.mode === 'goal');
|
|
131
|
+
}, context.mode === 'plan', executionChecklist, context.mode === 'goal', () => answeringQuestion);
|
|
128
132
|
try {
|
|
129
133
|
for await (const event of (0, query_1.query)({
|
|
130
134
|
messages,
|
|
@@ -154,7 +158,7 @@ class AgentLoopV1 {
|
|
|
154
158
|
activeStep = await this.bindStep(context, prepared, router, bindingInput);
|
|
155
159
|
return {
|
|
156
160
|
receiptDigest: activeStep.digest,
|
|
157
|
-
toolExecutor: (name, args, abortSignal, metadata) => this.invokeTool(context, activeStep, name, args, bindRecovery, abortSignal, metadata),
|
|
161
|
+
toolExecutor: (name, args, abortSignal, metadata) => this.invokeTool(context, activeStep, name, args, answeringQuestion, bindRecovery, abortSignal, metadata),
|
|
158
162
|
};
|
|
159
163
|
},
|
|
160
164
|
};
|
|
@@ -162,14 +166,15 @@ class AgentLoopV1 {
|
|
|
162
166
|
llm: this.options.llm,
|
|
163
167
|
abortSignal: context.abortSignal,
|
|
164
168
|
streamCallbacks,
|
|
165
|
-
holdAssistantUntilCompletionCheck: () =>
|
|
169
|
+
holdAssistantUntilCompletionCheck: () => !answeringQuestion &&
|
|
170
|
+
context.mode !== 'plan' &&
|
|
166
171
|
(context.mode === 'goal' ||
|
|
167
172
|
this.options.taskContext.requiresVerification() ||
|
|
168
173
|
(executionChecklist &&
|
|
169
174
|
(this.options.taskContext.hasTaskTodos() ||
|
|
170
175
|
!!this.options.taskContext.missingExecutionChecklist()))),
|
|
171
|
-
...(
|
|
172
|
-
? { checkTaskPlanStop:
|
|
176
|
+
...(checkTaskPlanStop
|
|
177
|
+
? { checkTaskPlanStop: () => (answeringQuestion ? undefined : checkTaskPlanStop()) }
|
|
173
178
|
: {}),
|
|
174
179
|
harness,
|
|
175
180
|
input: context.input,
|
|
@@ -186,10 +191,13 @@ class AgentLoopV1 {
|
|
|
186
191
|
const inputs = context.takePendingSteering?.(closeIfEmpty) ?? [];
|
|
187
192
|
for (const input of inputs) {
|
|
188
193
|
taskContextCompletion = undefined;
|
|
189
|
-
if (goal)
|
|
194
|
+
if (goal) {
|
|
190
195
|
this.options.taskContext.observeGoalSteering(input, goal.goalId);
|
|
191
|
-
|
|
192
|
-
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
const steering = this.options.taskContext.observeUserInput(input);
|
|
199
|
+
answeringQuestion && (answeringQuestion = steering?.kind === 'clarification');
|
|
200
|
+
}
|
|
193
201
|
}
|
|
194
202
|
return inputs;
|
|
195
203
|
},
|
|
@@ -322,22 +330,28 @@ class AgentLoopV1 {
|
|
|
322
330
|
await this.options.onStepCaptured?.(snapshot);
|
|
323
331
|
return snapshot;
|
|
324
332
|
}
|
|
325
|
-
async invokeTool(context, snapshot, name, args, bindRecovery, abortSignal, metadata) {
|
|
333
|
+
async invokeTool(context, snapshot, name, args, answeringQuestion, bindRecovery, abortSignal, metadata) {
|
|
326
334
|
if (!metadata)
|
|
327
335
|
throw new Error('ToolGateway execution requires provider call identity');
|
|
328
336
|
const executionChecklist = this.options.enableTaskTodos === true && (0, task_checklist_1.supportsExecutionChecklist)(context.mode);
|
|
329
337
|
const descriptor = snapshot.toolRouter.resolveDescriptor(name);
|
|
330
|
-
const
|
|
331
|
-
|
|
338
|
+
const workspaceWrite = mayChangeWorkspace(descriptor, args);
|
|
339
|
+
let prerequisiteFailure;
|
|
340
|
+
if (answeringQuestion &&
|
|
341
|
+
descriptor &&
|
|
342
|
+
!descriptor.risk.readOnly &&
|
|
343
|
+
(descriptor.name !== 'exec_command' || workspaceWrite)) {
|
|
344
|
+
prerequisiteFailure = 'Answer the current question without modifying the task or workspace.';
|
|
345
|
+
}
|
|
346
|
+
else if (executionChecklist && workspaceWrite) {
|
|
347
|
+
prerequisiteFailure = this.options.taskContext.missingExecutionChecklist({
|
|
332
348
|
path: (name === 'write_file' || name === 'edit_file') && typeof args.path === 'string'
|
|
333
349
|
? args.path
|
|
334
350
|
: undefined,
|
|
335
|
-
command: name === 'exec_command' && typeof args.command === 'string'
|
|
336
|
-
? args.command
|
|
337
|
-
: undefined,
|
|
351
|
+
command: name === 'exec_command' && typeof args.command === 'string' ? args.command : undefined,
|
|
338
352
|
cwd: typeof args.cwd === 'string' ? args.cwd : undefined,
|
|
339
|
-
})
|
|
340
|
-
|
|
353
|
+
});
|
|
354
|
+
}
|
|
341
355
|
const invocationId = deterministicRuntimeId([
|
|
342
356
|
context.threadId,
|
|
343
357
|
context.turnId,
|
|
@@ -349,7 +363,7 @@ class AgentLoopV1 {
|
|
|
349
363
|
cwd: snapshot.environment.cwd,
|
|
350
364
|
config: { name: 'orion-code', mode: context.mode },
|
|
351
365
|
};
|
|
352
|
-
const activeTodo = executionChecklist && name !== 'todo_write'
|
|
366
|
+
const activeTodo = executionChecklist && !answeringQuestion && name !== 'todo_write'
|
|
353
367
|
? this.options.taskContext.activeTaskTodo()
|
|
354
368
|
: undefined;
|
|
355
369
|
const invoked = await this.options.gateway.invoke({
|
|
@@ -360,13 +374,15 @@ class AgentLoopV1 {
|
|
|
360
374
|
context: toolContext,
|
|
361
375
|
abortSignal,
|
|
362
376
|
prerequisiteFailure,
|
|
363
|
-
taskRecovery:
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
377
|
+
taskRecovery: answeringQuestion
|
|
378
|
+
? undefined
|
|
379
|
+
: bindRecovery?.({
|
|
380
|
+
descriptor,
|
|
381
|
+
name,
|
|
382
|
+
args,
|
|
383
|
+
cwd: toolContext.cwd,
|
|
384
|
+
activeTodoId: activeTodo,
|
|
385
|
+
}),
|
|
370
386
|
});
|
|
371
387
|
const receipt = invoked.receipt;
|
|
372
388
|
const evidence = (0, task_context_recovery_1.projectTaskToolEvidence)(receipt, args, toolContext.cwd);
|
|
@@ -522,10 +538,14 @@ function createSnapshotToolFacade(descriptor) {
|
|
|
522
538
|
isFileEdit: () => descriptor.risk.fileEdit,
|
|
523
539
|
};
|
|
524
540
|
}
|
|
525
|
-
function createQueryTaskContextAdapter(taskContext, onCompletion, planningPhase, enforceTaskTodos, requireEveryCriterion) {
|
|
541
|
+
function createQueryTaskContextAdapter(taskContext, onCompletion, planningPhase, enforceTaskTodos, requireEveryCriterion, answeringQuestion) {
|
|
526
542
|
return {
|
|
527
543
|
updateCapabilityProfile: input => structuredClone(taskContext.observeCapability(input)),
|
|
528
|
-
assembleMessages: (messages, options) => taskContext.assembleMessages(messages, {
|
|
544
|
+
assembleMessages: (messages, options) => taskContext.assembleMessages(messages, {
|
|
545
|
+
...options,
|
|
546
|
+
includeTaskTodos: enforceTaskTodos,
|
|
547
|
+
answeringQuestion: answeringQuestion(),
|
|
548
|
+
}),
|
|
529
549
|
getCapsule: () => {
|
|
530
550
|
const capsule = taskContext.getCapsule();
|
|
531
551
|
return capsule
|
|
@@ -541,6 +561,8 @@ function createQueryTaskContextAdapter(taskContext, onCompletion, planningPhase,
|
|
|
541
561
|
taskContext.observeToolResult(input);
|
|
542
562
|
},
|
|
543
563
|
beforeComplete: () => {
|
|
564
|
+
if (answeringQuestion())
|
|
565
|
+
return { canComplete: true, missing: [], evidence: [] };
|
|
544
566
|
const decision = taskContext.auditCompletion(enforceTaskTodos, requireEveryCriterion);
|
|
545
567
|
onCompletion(decision);
|
|
546
568
|
// PLAN completes a planning phase, not the parent implementation task.
|
|
@@ -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),
|
|
@@ -873,7 +956,7 @@ class AgentRuntimeController {
|
|
|
873
956
|
else if (completedPlan) {
|
|
874
957
|
nextRequest = {
|
|
875
958
|
inputKind: 'plan_execution',
|
|
876
|
-
text: `Execute the saved plan now. Continue autonomously
|
|
959
|
+
text: `Execute the saved plan now. Continue autonomously and follow the plan's verification steps.\n\n${completedPlan}`,
|
|
877
960
|
sessionId: this.options.runtime.getSession()?.id ?? request.sessionId,
|
|
878
961
|
persistAsUserMessage: false,
|
|
879
962
|
echoToTranscript: false,
|
|
@@ -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.';
|
|
@@ -73,11 +73,9 @@ class OrionSessionRunnerV1 {
|
|
|
73
73
|
if (this.transition === transition)
|
|
74
74
|
this.transition = undefined;
|
|
75
75
|
}
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
// replacement and must preserve the current renderer window.
|
|
80
|
-
if (activation || this.options.replayHistoryOnRestore !== false) {
|
|
76
|
+
// Interactive commands publish their bounded replacement only after the
|
|
77
|
+
// new owner starts. A runner that replays from the beginning owns its view.
|
|
78
|
+
if (this.options.replayHistoryOnRestore !== false) {
|
|
81
79
|
this.options.eventSink.clearTranscript();
|
|
82
80
|
}
|
|
83
81
|
active.adapter.flush();
|
|
@@ -35,5 +35,6 @@ export declare function resolvePlanReviewV1(runtime: OrionRuntimeV1, input: {
|
|
|
35
35
|
/** Recover the crash gap between a durable resolution and its turn admission. */
|
|
36
36
|
export declare function recoverResolvedPlanReviewV1(runtime: OrionRuntimeV1): PlanReviewResolutionReceiptV1['admission'];
|
|
37
37
|
export declare function findPlanReceiptForReviewV1(projection: ThreadProjectionV1, review: PlanReviewProjectionV1): PlanReceiptV1;
|
|
38
|
+
export declare function isPlanReviewTurnInput(review: PlanReviewProjectionV1, input: string): boolean;
|
|
38
39
|
export declare function planReviewTurnInput(review: PlanReviewProjectionV1): string;
|
|
39
40
|
//# sourceMappingURL=plan-review.d.ts.map
|
|
@@ -5,6 +5,7 @@ exports.ensurePlanReviewRequestedV1 = ensurePlanReviewRequestedV1;
|
|
|
5
5
|
exports.resolvePlanReviewV1 = resolvePlanReviewV1;
|
|
6
6
|
exports.recoverResolvedPlanReviewV1 = recoverResolvedPlanReviewV1;
|
|
7
7
|
exports.findPlanReceiptForReviewV1 = findPlanReceiptForReviewV1;
|
|
8
|
+
exports.isPlanReviewTurnInput = isPlanReviewTurnInput;
|
|
8
9
|
exports.planReviewTurnInput = planReviewTurnInput;
|
|
9
10
|
const crypto_1 = require("crypto");
|
|
10
11
|
const canonical_1 = require("./protocol/canonical");
|
|
@@ -118,8 +119,8 @@ function admitResolvedPlanReviewV1(runtime, review) {
|
|
|
118
119
|
}
|
|
119
120
|
const input = planReviewTurnInput(review);
|
|
120
121
|
const projection = runtime.thread.getProjection();
|
|
121
|
-
if (Object.values(projection.turns).some(turn => turn.input
|
|
122
|
-
projection.queue.some(item => item.input
|
|
122
|
+
if (Object.values(projection.turns).some(turn => isPlanReviewTurnInput(review, turn.input)) ||
|
|
123
|
+
projection.queue.some(item => isPlanReviewTurnInput(review, item.input))) {
|
|
123
124
|
return { status: 'already_admitted' };
|
|
124
125
|
}
|
|
125
126
|
const result = runtime.thread.dispatch({
|
|
@@ -138,6 +139,14 @@ function admitResolvedPlanReviewV1(runtime, review) {
|
|
|
138
139
|
reason: result.status === 'rejected' ? result.reason : `unexpected_${result.status}`,
|
|
139
140
|
};
|
|
140
141
|
}
|
|
142
|
+
const approvedPlanInstruction = 'Execute the approved durable plan in BUILD mode. Follow its verification steps before finishing.';
|
|
143
|
+
const priorApprovedPlanInstruction = 'Execute the approved durable plan in BUILD mode. Verify the implementation before finishing.';
|
|
144
|
+
function isPlanReviewTurnInput(review, input) {
|
|
145
|
+
const current = planReviewTurnInput(review);
|
|
146
|
+
return (input === current ||
|
|
147
|
+
(review.status === 'approved' &&
|
|
148
|
+
input === current.slice(0, -approvedPlanInstruction.length) + priorApprovedPlanInstruction));
|
|
149
|
+
}
|
|
141
150
|
function planReviewTurnInput(review) {
|
|
142
151
|
const authority = [
|
|
143
152
|
'[Orion Plan Review V1]',
|
|
@@ -145,11 +154,7 @@ function planReviewTurnInput(review) {
|
|
|
145
154
|
`planDigest=${review.planDigest}`,
|
|
146
155
|
];
|
|
147
156
|
if (review.status === 'approved') {
|
|
148
|
-
return [
|
|
149
|
-
...authority,
|
|
150
|
-
'action=approve',
|
|
151
|
-
'Execute the approved durable plan in BUILD mode. Verify the implementation before finishing.',
|
|
152
|
-
].join('\n');
|
|
157
|
+
return [...authority, 'action=approve', approvedPlanInstruction].join('\n');
|
|
153
158
|
}
|
|
154
159
|
return [
|
|
155
160
|
...authority,
|