@orion-agents/orion-code 0.4.7 → 0.4.9

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.
Files changed (142) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/README.md +8 -9
  3. package/README.zh-CN.md +8 -8
  4. package/dist/acp/session-updates.js +1 -0
  5. package/dist/cli.js +42 -3
  6. package/dist/commands/session-command-handlers.js +8 -3
  7. package/dist/commands/system-commands.js +3 -3
  8. package/dist/commands/types.d.ts +3 -0
  9. package/dist/framework/loop-progress.js +3 -1
  10. package/dist/framework/query.d.ts +6 -8
  11. package/dist/framework/query.js +39 -76
  12. package/dist/framework/tool-serializer.d.ts +12 -0
  13. package/dist/framework/tool-serializer.js +35 -0
  14. package/dist/framework/tool.d.ts +2 -0
  15. package/dist/framework/verification-command.d.ts +21 -0
  16. package/dist/framework/verification-command.js +53 -4
  17. package/dist/harness/context-harness.d.ts +3 -9
  18. package/dist/harness/context-harness.js +43 -163
  19. package/dist/harness/ledger.js +2 -1
  20. package/dist/harness/state.d.ts +3 -0
  21. package/dist/harness/state.js +37 -4
  22. package/dist/harness/task-checklist.d.ts +1 -1
  23. package/dist/harness/task-checklist.js +1 -1
  24. package/dist/harness/types.d.ts +1 -0
  25. package/dist/harness/verification.js +5 -4
  26. package/dist/print-ui/delivery.d.ts +15 -0
  27. package/dist/print-ui/delivery.js +131 -0
  28. package/dist/print-ui/event-stream.d.ts +6 -1
  29. package/dist/print-ui/event-stream.js +56 -10
  30. package/dist/print-ui/launch.d.ts +5 -0
  31. package/dist/print-ui/launch.js +66 -9
  32. package/dist/runtime/agent-loop.d.ts +3 -1
  33. package/dist/runtime/agent-loop.js +26 -41
  34. package/dist/runtime/agent-runtime-controller.d.ts +4 -1
  35. package/dist/runtime/agent-runtime-controller.js +36 -22
  36. package/dist/runtime/agent-runtime-runner.d.ts +4 -0
  37. package/dist/runtime/agent-runtime-runner.js +9 -0
  38. package/dist/runtime/builtin-tool-provider.js +6 -5
  39. package/dist/runtime/composer/layout.d.ts +1 -1
  40. package/dist/runtime/composer/layout.js +5 -5
  41. package/dist/runtime/core-tools/descriptors.d.ts +1 -1
  42. package/dist/runtime/core-tools/descriptors.js +39 -1
  43. package/dist/runtime/first-party-core-provider.js +1 -0
  44. package/dist/runtime/first-party-tool-services.js +10 -0
  45. package/dist/runtime/goal-lifecycle-v2.js +5 -0
  46. package/dist/runtime/goal-runtime-coordinator.js +6 -2
  47. package/dist/runtime/goals/evidence.js +2 -0
  48. package/dist/runtime/legacy-thread-materializer.d.ts +7 -0
  49. package/dist/runtime/legacy-thread-materializer.js +32 -6
  50. package/dist/runtime/orion-runtime-v1.d.ts +2 -1
  51. package/dist/runtime/orion-runtime-v1.js +34 -6
  52. package/dist/runtime/product-bootstrap.d.ts +2 -0
  53. package/dist/runtime/product-bootstrap.js +1 -0
  54. package/dist/runtime/product-orion-runtime.d.ts +2 -1
  55. package/dist/runtime/product-orion-runtime.js +7 -2
  56. package/dist/runtime/rich-text/layout.d.ts +3 -1
  57. package/dist/runtime/rich-text/layout.js +37 -22
  58. package/dist/runtime/shell-process-sessions.d.ts +41 -0
  59. package/dist/runtime/shell-process-sessions.js +258 -0
  60. package/dist/runtime/step-snapshot.js +61 -11
  61. package/dist/runtime/subagents/presets.d.ts +1 -1
  62. package/dist/runtime/subagents/presets.js +1 -0
  63. package/dist/runtime/task-context-recovery.js +14 -3
  64. package/dist/runtime/task-context-service.d.ts +2 -6
  65. package/dist/runtime/task-context-service.js +3 -12
  66. package/dist/runtime/thread-event-store.d.ts +3 -0
  67. package/dist/runtime/thread-event-store.js +35 -22
  68. package/dist/runtime/thread-session-index.d.ts +15 -3
  69. package/dist/runtime/thread-session-index.js +152 -45
  70. package/dist/runtime/thread-session-view.js +1 -1
  71. package/dist/runtime/thread-ui-adapter.d.ts +1 -1
  72. package/dist/runtime/thread-ui-adapter.js +23 -5
  73. package/dist/runtime/tool-gateway.d.ts +1 -0
  74. package/dist/runtime/tool-gateway.js +1 -0
  75. package/dist/runtime/tool-transcript-entry.d.ts +8 -1
  76. package/dist/runtime/tool-transcript-entry.js +35 -7
  77. package/dist/runtime/ui-events.d.ts +10 -0
  78. package/dist/runtime/verification-feedback.d.ts +4 -0
  79. package/dist/runtime/verification-feedback.js +61 -0
  80. package/dist/services/global-config.d.ts +1 -1
  81. package/dist/services/global-config.js +2 -0
  82. package/dist/services/llm.d.ts +3 -0
  83. package/dist/services/llm.js +48 -4
  84. package/dist/terminal-ui/raw-editor.js +2 -1
  85. package/dist/tools/bash_security.d.ts +1 -24
  86. package/dist/tools/bash_security.js +7 -124
  87. package/dist/tools/core/exec-command.js +51 -42
  88. package/dist/tools/core/index.d.ts +2 -1
  89. package/dist/tools/core/index.js +4 -1
  90. package/dist/tools/core/process-session.d.ts +2 -0
  91. package/dist/tools/core/process-session.js +54 -0
  92. package/dist/tools/todo.js +9 -13
  93. package/dist/tui-core/frame.d.ts +2 -0
  94. package/dist/tui-core/frame.js +19 -0
  95. package/dist/tui-core/input-parser.d.ts +4 -1
  96. package/dist/tui-core/input-parser.js +22 -0
  97. package/dist/tui-ui/chrome-view-model.d.ts +0 -2
  98. package/dist/tui-ui/chrome-view-model.js +54 -56
  99. package/dist/tui-ui/launch.js +133 -202
  100. package/dist/tui-ui/layout.d.ts +16 -41
  101. package/dist/tui-ui/layout.js +408 -295
  102. package/dist/tui-ui/render-scheduler.d.ts +2 -5
  103. package/dist/tui-ui/render-scheduler.js +10 -10
  104. package/dist/tui-ui/response-clipboard.d.ts +17 -0
  105. package/dist/tui-ui/response-clipboard.js +201 -0
  106. package/dist/tui-ui/runner.d.ts +65 -80
  107. package/dist/tui-ui/runner.js +545 -738
  108. package/dist/tui-ui/session-picker-preview.d.ts +8 -0
  109. package/dist/tui-ui/session-picker-preview.js +119 -0
  110. package/dist/tui-ui/session-picker.d.ts +20 -0
  111. package/dist/tui-ui/session-picker.js +42 -0
  112. package/dist/tui-ui/state.d.ts +34 -81
  113. package/dist/tui-ui/state.js +155 -288
  114. package/dist/tui-ui/terminal-image.d.ts +3 -7
  115. package/dist/tui-ui/terminal-image.js +18 -47
  116. package/dist/tui-ui/terminal-viewport.d.ts +55 -0
  117. package/dist/tui-ui/terminal-viewport.js +221 -0
  118. package/dist/tui-ui/transcript-layout.d.ts +5 -0
  119. package/dist/tui-ui/transcript-layout.js +43 -28
  120. package/dist/tui-ui/transcript-pager.d.ts +39 -0
  121. package/dist/tui-ui/transcript-pager.js +278 -0
  122. package/dist/tui-ui/transcript-tool-output.d.ts +16 -0
  123. package/dist/tui-ui/transcript-tool-output.js +102 -0
  124. package/dist/utils/bounded-file.d.ts +4 -0
  125. package/dist/utils/bounded-file.js +30 -0
  126. package/dist/utils/command-process.d.ts +4 -0
  127. package/dist/utils/command-process.js +23 -0
  128. package/dist/utils/shell-command.d.ts +29 -0
  129. package/dist/utils/shell-command.js +185 -0
  130. package/docs/cli-guide.md +50 -6
  131. package/npm-shrinkwrap.json +115 -15
  132. package/package.json +4 -1
  133. package/dist/tui-ui/inline-surface.d.ts +0 -191
  134. package/dist/tui-ui/inline-surface.js +0 -644
  135. package/dist/tui-ui/input-ownership.d.ts +0 -46
  136. package/dist/tui-ui/input-ownership.js +0 -74
  137. package/dist/tui-ui/transcript-inspector-layout.d.ts +0 -9
  138. package/dist/tui-ui/transcript-inspector-layout.js +0 -107
  139. package/dist/tui-ui/transcript-inspector-surface.d.ts +0 -18
  140. package/dist/tui-ui/transcript-inspector-surface.js +0 -91
  141. package/dist/tui-ui/transcript-inspector.d.ts +0 -36
  142. package/dist/tui-ui/transcript-inspector.js +0 -129
@@ -9,6 +9,7 @@ const query_1 = require("../framework/query");
9
9
  const terminal_text_1 = require("../utils/terminal-text");
10
10
  const task_checklist_1 = require("../harness/task-checklist");
11
11
  const ui_view_model_1 = require("./ui-view-model");
12
+ const shell_process_sessions_1 = require("./shell-process-sessions");
12
13
  const tool_serializer_1 = require("../framework/tool-serializer");
13
14
  const redaction_1 = require("../services/redaction");
14
15
  const bash_security_1 = require("../tools/bash_security");
@@ -44,6 +45,15 @@ class AgentLoopV1 {
44
45
  this.serviceId = 'agent-loop';
45
46
  }
46
47
  async run(context) {
48
+ const shellProcesses = new shell_process_sessions_1.TurnShellProcesses(context.abortSignal);
49
+ try {
50
+ return await this.runTurn(context, shellProcesses);
51
+ }
52
+ finally {
53
+ await shellProcesses.close();
54
+ }
55
+ }
56
+ async runTurn(context, shellProcesses) {
47
57
  const progressAtAdmission = this.options.taskContext.progressState();
48
58
  const bindRecovery = this.options.previousCommitDigest
49
59
  ? (0, task_context_recovery_1.createTaskRecoveryBinder)(this.options.taskContext, this.options.previousCommitDigest, progressAtAdmission)
@@ -123,12 +133,9 @@ class AgentLoopV1 {
123
133
  },
124
134
  };
125
135
  const executionChecklist = this.options.enableTaskTodos === true && (0, task_checklist_1.supportsExecutionChecklist)(context.mode);
126
- const checkTaskPlanStop = executionChecklist
127
- ? this.options.taskContext.prepareTaskPlanStopCheck()
128
- : undefined;
129
136
  const harness = createQueryTaskContextAdapter(this.options.taskContext, decision => {
130
137
  taskContextCompletion = decision;
131
- }, context.mode === 'plan', executionChecklist, context.mode === 'goal', () => answeringQuestion);
138
+ }, executionChecklist, context.mode === 'goal', () => answeringQuestion);
132
139
  try {
133
140
  for await (const event of (0, query_1.query)({
134
141
  messages,
@@ -158,24 +165,15 @@ class AgentLoopV1 {
158
165
  activeStep = await this.bindStep(context, prepared, router, bindingInput);
159
166
  return {
160
167
  receiptDigest: activeStep.digest,
161
- toolExecutor: (name, args, abortSignal, metadata) => this.invokeTool(context, activeStep, name, args, answeringQuestion, bindRecovery, abortSignal, metadata),
168
+ toolExecutor: (name, args, abortSignal, metadata) => this.invokeTool(context, shellProcesses, activeStep, name, args, answeringQuestion, bindRecovery, abortSignal, metadata),
162
169
  };
163
170
  },
164
171
  };
165
172
  },
166
173
  llm: this.options.llm,
174
+ outputSchema: this.options.outputSchema,
167
175
  abortSignal: context.abortSignal,
168
176
  streamCallbacks,
169
- holdAssistantUntilCompletionCheck: () => !answeringQuestion &&
170
- context.mode !== 'plan' &&
171
- (context.mode === 'goal' ||
172
- this.options.taskContext.requiresVerification() ||
173
- (executionChecklist &&
174
- (this.options.taskContext.hasTaskTodos() ||
175
- !!this.options.taskContext.missingExecutionChecklist()))),
176
- ...(checkTaskPlanStop
177
- ? { checkTaskPlanStop: () => (answeringQuestion ? undefined : checkTaskPlanStop()) }
178
- : {}),
179
177
  harness,
180
178
  input: context.input,
181
179
  toolContext: {
@@ -223,15 +221,6 @@ class AgentLoopV1 {
223
221
  break;
224
222
  }
225
223
  case 'complete':
226
- if (executionChecklist &&
227
- (event.stats?.finishReason === 'completion_gate' ||
228
- event.stats?.stopDecision?.reason.code === 'task_step_blocked')) {
229
- const item = context.startItem({ kind: 'message', role: 'system' });
230
- context.completeItem(item, {
231
- content: event.content,
232
- summary: compactSummary(event.content),
233
- });
234
- }
235
224
  completeEvent = event;
236
225
  break;
237
226
  case 'prompt_assembly':
@@ -330,21 +319,20 @@ class AgentLoopV1 {
330
319
  await this.options.onStepCaptured?.(snapshot);
331
320
  return snapshot;
332
321
  }
333
- async invokeTool(context, snapshot, name, args, answeringQuestion, bindRecovery, abortSignal, metadata) {
322
+ async invokeTool(context, shellProcesses, snapshot, name, args, answeringQuestion, bindRecovery, abortSignal, metadata) {
334
323
  if (!metadata)
335
324
  throw new Error('ToolGateway execution requires provider call identity');
336
325
  const executionChecklist = this.options.enableTaskTodos === true && (0, task_checklist_1.supportsExecutionChecklist)(context.mode);
337
326
  const descriptor = snapshot.toolRouter.resolveDescriptor(name);
338
327
  const workspaceWrite = mayChangeWorkspace(descriptor, args);
328
+ const readOnlyShellCall = (descriptor?.name === 'exec_command' || descriptor?.name === 'process_session') &&
329
+ !workspaceWrite;
339
330
  let prerequisiteFailure;
340
- if (answeringQuestion &&
341
- descriptor &&
342
- !descriptor.risk.readOnly &&
343
- (descriptor.name !== 'exec_command' || workspaceWrite)) {
331
+ if (answeringQuestion && descriptor && !descriptor.risk.readOnly && !readOnlyShellCall) {
344
332
  prerequisiteFailure = 'Answer the current question without modifying the task or workspace.';
345
333
  }
346
334
  else if (executionChecklist && workspaceWrite) {
347
- prerequisiteFailure = this.options.taskContext.missingExecutionChecklist({
335
+ prerequisiteFailure = this.options.taskContext.deferredWorkspaceWriteReason({
348
336
  path: (name === 'write_file' || name === 'edit_file') && typeof args.path === 'string'
349
337
  ? args.path
350
338
  : undefined,
@@ -371,7 +359,7 @@ class AgentLoopV1 {
371
359
  snapshot,
372
360
  toolName: name,
373
361
  args,
374
- context: toolContext,
362
+ context: { ...toolContext, shellProcesses },
375
363
  abortSignal,
376
364
  prerequisiteFailure,
377
365
  taskRecovery: answeringQuestion
@@ -402,10 +390,12 @@ exports.AgentLoopV1 = AgentLoopV1;
402
390
  function mayChangeWorkspace(descriptor, args) {
403
391
  if (descriptor?.risk.effect !== 'workspace_write')
404
392
  return false;
393
+ if (descriptor.name === 'process_session')
394
+ return args.action === 'write';
405
395
  if (descriptor.name === 'edit_file' && args.preview === true)
406
396
  return false;
407
397
  if (descriptor.name === 'exec_command' && typeof args.command === 'string') {
408
- return !(0, bash_security_1.isReadOnlyCommand)(args.command);
398
+ return args.interactive === true || !(0, bash_security_1.isReadOnlyCommand)(args.command);
409
399
  }
410
400
  return true;
411
401
  }
@@ -538,7 +528,7 @@ function createSnapshotToolFacade(descriptor) {
538
528
  isFileEdit: () => descriptor.risk.fileEdit,
539
529
  };
540
530
  }
541
- function createQueryTaskContextAdapter(taskContext, onCompletion, planningPhase, enforceTaskTodos, requireEveryCriterion, answeringQuestion) {
531
+ function createQueryTaskContextAdapter(taskContext, onCompletion, enforceTaskTodos, requireEveryCriterion, answeringQuestion) {
542
532
  return {
543
533
  updateCapabilityProfile: input => structuredClone(taskContext.observeCapability(input)),
544
534
  assembleMessages: (messages, options) => taskContext.assembleMessages(messages, {
@@ -563,16 +553,11 @@ function createQueryTaskContextAdapter(taskContext, onCompletion, planningPhase,
563
553
  beforeComplete: () => {
564
554
  if (answeringQuestion())
565
555
  return { canComplete: true, missing: [], evidence: [] };
566
- const decision = taskContext.auditCompletion(enforceTaskTodos, requireEveryCriterion);
556
+ // Goal verification is based on its criteria. The checklist tracks model progress.
557
+ const decision = taskContext.auditCompletion(enforceTaskTodos && !requireEveryCriterion, requireEveryCriterion);
567
558
  onCompletion(decision);
568
- // PLAN completes a planning phase, not the parent implementation task.
569
- // Persist the unmodified audit for the PlanReceipt, while allowing the
570
- // query to stop after its decision-complete plan. BUILD/AUTO will enforce
571
- // the same TaskContext criteria in the following logical turn.
572
- const queryDecision = planningPhase ? { ...decision, canComplete: true } : decision;
573
- return structuredClone(queryDecision);
559
+ return structuredClone(decision);
574
560
  },
575
- asCompletionBlockedMessage: result => taskContext.completionBlockedMessage(result),
576
561
  };
577
562
  }
578
563
  function compactSummary(content) {
@@ -1,6 +1,7 @@
1
1
  import type { AgentMode } from '../commands/types';
2
2
  import type { AgentRuntimeEventSink, AgentRuntimeInput, AgentRuntimeInputResult, AgentRuntimeInterruptResult, AgentRuntimeSubmitResult } from './agent-runtime-protocol';
3
- import type { AgentRuntimeRunnerV1, AgentRuntimeRunInputOptionsV1 } from './agent-runtime-runner';
3
+ import { type AgentRuntimeRunnerV1, type AgentRuntimeRunInputOptionsV1 } from './agent-runtime-runner';
4
+ import type { ThreadTranscriptHistorySource } from './thread-session-index';
4
5
  import type { OrionCodeUiRuntime, FollowupQueueItem, FollowupQueueSnapshot, UiEventSink, UiRendererCapabilities } from './ui-events';
5
6
  import type { CommandUiRenderer } from '../commands/types';
6
7
  import { type TurnControllerOptions } from './turn-controller';
@@ -42,6 +43,8 @@ export interface AgentRuntimeControllerOptions extends TurnControllerOptions {
42
43
  uiCapabilities?: UiRendererCapabilities;
43
44
  /** Active renderer adapter identity for renderer-layer diagnostics. */
44
45
  uiRenderer?: CommandUiRenderer;
46
+ /** Hand a resumed TUI its process-local durable history reader. */
47
+ onRestoreTranscriptHistory?: (source: ThreadTranscriptHistorySource | undefined) => void;
45
48
  echoSubmittedInput?: boolean;
46
49
  runningStatus?: string | ((input: string) => string);
47
50
  readyStatus?: string | (() => string);
@@ -8,6 +8,7 @@ const retired_commands_1 = require("../commands/retired-commands");
8
8
  const target_command_1 = require("../commands/target-command");
9
9
  const agent_runtime_protocol_1 = require("./agent-runtime-protocol");
10
10
  const agent_status_1 = require("./agent-status");
11
+ const agent_runtime_runner_1 = require("./agent-runtime-runner");
11
12
  const ui_events_1 = require("./ui-events");
12
13
  const turn_controller_1 = require("./turn-controller");
13
14
  const agent_mode_1 = require("../framework/agent-mode");
@@ -372,7 +373,7 @@ class AgentRuntimeController {
372
373
  if (this.followupsPaused || !item || sessionId !== this.followupSessionId)
373
374
  return;
374
375
  return {
375
- id: item.id,
376
+ item,
376
377
  request: {
377
378
  inputKind: 'user',
378
379
  text: item.resolvedText,
@@ -394,7 +395,7 @@ class AgentRuntimeController {
394
395
  this.followupsPaused = false;
395
396
  const pending = this.nextPendingFollowup();
396
397
  if (pending)
397
- return this.submitTurnRequest(pending.request, pending.id);
398
+ return this.submitTurnRequest(pending.request, pending.item);
398
399
  }
399
400
  else if (this.followupQueue.length > 0) {
400
401
  try {
@@ -559,7 +560,7 @@ class AgentRuntimeController {
559
560
  if (!this.stopping) {
560
561
  const pending = this.nextPendingFollowup();
561
562
  if (pending)
562
- await this.runTurn(pending.request, pending.id);
563
+ await this.runTurn(pending.request, pending.item);
563
564
  }
564
565
  }
565
566
  async runCommand(command, args, abortSignal) {
@@ -619,7 +620,7 @@ class AgentRuntimeController {
619
620
  if (command.name === 'compact' && !this.stopping) {
620
621
  const pending = this.nextPendingFollowup();
621
622
  if (pending)
622
- await this.runTurn(pending.request, pending.id);
623
+ await this.runTurn(pending.request, pending.item);
623
624
  }
624
625
  if (result.continueAsChat) {
625
626
  const session = this.options.runtime.getSession() ?? this.options.runtime.ensureSession();
@@ -720,6 +721,7 @@ class AgentRuntimeController {
720
721
  ...((renderer === 'terminal' || renderer === 'tui') && {
721
722
  replaceTranscript: (entries) => this.eventSink.emit({ type: 'transcript_replace', entries: [...entries] }),
722
723
  }),
724
+ onRestoreTranscriptHistory: renderer === 'tui' ? this.options.onRestoreTranscriptHistory : undefined,
723
725
  getSession: this.options.runtime.getSession,
724
726
  writeOutput: text => {
725
727
  if (text.trim())
@@ -748,12 +750,12 @@ class AgentRuntimeController {
748
750
  : undefined,
749
751
  };
750
752
  }
751
- submitTurnRequest(request, followupId) {
753
+ submitTurnRequest(request, followup) {
752
754
  if (this.hasActiveTurn())
753
755
  return { type: 'command_ignored' };
754
756
  if (!this.requestIsCurrent(request))
755
757
  return { type: 'command_ignored' };
756
- this.activeRun = this.runTurn(request, followupId)
758
+ this.activeRun = this.runTurn(request, followup)
757
759
  .catch(error => {
758
760
  this.handleRunLoopError(error);
759
761
  })
@@ -802,7 +804,7 @@ class AgentRuntimeController {
802
804
  const result = await this.runTrackedCompact({});
803
805
  const pending = this.nextPendingFollowup();
804
806
  if (pending && !this.stopping)
805
- this.submitTurnRequest(pending.request, pending.id);
807
+ this.submitTurnRequest(pending.request, pending.item);
806
808
  return result;
807
809
  }
808
810
  async runTrackedCompact(input) {
@@ -835,21 +837,32 @@ class AgentRuntimeController {
835
837
  throw new Error('Plan review is unavailable for this Runtime.');
836
838
  return this.runner.reviewPlan(input);
837
839
  }
838
- async runTurn(firstRequest, firstFollowupId) {
840
+ async runTurn(firstRequest, firstFollowup) {
839
841
  let nextRequest = firstRequest;
840
- let nextFollowupId = firstFollowupId;
842
+ let nextFollowup = firstFollowup;
841
843
  while (nextRequest && !this.stopping) {
842
844
  if (!this.requestIsCurrent(nextRequest))
843
845
  break;
844
846
  const request = nextRequest;
845
- const followupId = nextFollowupId;
846
- nextFollowupId = undefined;
847
+ const followup = nextFollowup;
848
+ nextFollowup = undefined;
847
849
  let followupAdmitted = false;
850
+ let followupChangedBeforeAdmission = false;
851
+ const isPending = () => {
852
+ const first = this.followupQueue[0];
853
+ return Boolean(followup &&
854
+ first &&
855
+ !this.stopping &&
856
+ !this.followupsPaused &&
857
+ this.requestIsCurrent(request) &&
858
+ first.id === followup.id &&
859
+ first.revision === followup.revision);
860
+ };
848
861
  const onFollowupAdmitted = () => {
849
862
  if ((this.followupSessionId ?? 'pending-session') !== request.sessionId)
850
863
  return;
851
864
  try {
852
- this.saveFollowupQueue(this.followupQueue.filter(item => item.id !== followupId));
865
+ this.saveFollowupQueue(this.followupQueue.filter(item => item.id !== followup?.id));
853
866
  followupAdmitted = true;
854
867
  }
855
868
  catch (error) {
@@ -872,23 +885,22 @@ class AgentRuntimeController {
872
885
  if (!settingsReady)
873
886
  break;
874
887
  }
888
+ if (followup && !isPending())
889
+ throw new agent_runtime_runner_1.PendingFollowupChangedError();
875
890
  this.options.runtime.store.setProcessing(true);
876
891
  this.emitProcessing(true);
877
892
  const runningStatus = statusText(this.options.runningStatus, nextInput);
878
893
  if (runningStatus)
879
894
  this.emitStatus(runningStatus);
880
- const durableFollowup = followupId && this.options.runtime.followupQueueStore;
895
+ const durableFollowup = followup && this.options.runtime.followupQueueStore;
881
896
  const options = {
882
897
  abortSignal: turn.abortSignal,
883
898
  turnId: turn.id,
884
899
  ...(durableFollowup && {
885
900
  followup: {
886
- id: followupId,
901
+ id: followup.id,
887
902
  sessionId: request.sessionId,
888
- isPending: () => !this.stopping &&
889
- this.requestIsCurrent(request) &&
890
- this.followupQueue[0]?.id === followupId &&
891
- this.followupQueue[0].resolvedText === request.text,
903
+ isPending,
892
904
  onAdmitted: onFollowupAdmitted,
893
905
  },
894
906
  }),
@@ -903,11 +915,12 @@ class AgentRuntimeController {
903
915
  inputKind: request.inputKind,
904
916
  });
905
917
  }
906
- if (followupId && !durableFollowup)
918
+ if (followup && !durableFollowup)
907
919
  onFollowupAdmitted();
908
920
  }
909
921
  catch (error) {
910
- if (!turn.abortSignal.aborted) {
922
+ followupChangedBeforeAdmission = error instanceof agent_runtime_runner_1.PendingFollowupChangedError;
923
+ if (!turn.abortSignal.aborted && !followupChangedBeforeAdmission) {
911
924
  if (this.options.onTurnError)
912
925
  this.options.onTurnError(error);
913
926
  else {
@@ -918,8 +931,9 @@ class AgentRuntimeController {
918
931
  }
919
932
  finally {
920
933
  const revision = this.turnController.finishTurn(turn.id);
921
- if (followupId && !followupAdmitted)
934
+ if (followup && !followupAdmitted && !followupChangedBeforeAdmission) {
922
935
  this.followupsPaused = true;
936
+ }
923
937
  if (settingsReady) {
924
938
  // Durable request runners commit and enqueue Plan execution at the Thread boundary.
925
939
  // The legacy runInput path still needs the controller-owned compatibility follow-up.
@@ -967,7 +981,7 @@ class AgentRuntimeController {
967
981
  else {
968
982
  const queuedCommand = this.queuedCommands.shift();
969
983
  const pending = queuedCommand ? undefined : this.nextPendingFollowup();
970
- nextFollowupId = pending?.id;
984
+ nextFollowup = pending?.item;
971
985
  nextRequest = queuedCommand
972
986
  ? {
973
987
  inputKind: 'user',
@@ -3,6 +3,10 @@ import type { GoalRuntimeControlResultV2, GoalRuntimeControlV2 } from './goal-ru
3
3
  import type { ThreadSessionRuntimeActivationV1 } from './thread-session-view';
4
4
  import type { PlanReviewActionV1, PlanReviewResolutionReceiptV1 } from './plan-review';
5
5
  import type { PlanReviewProjectionV1 } from './thread-projection';
6
+ /** The queue changed before this selection crossed the durable admission boundary. */
7
+ export declare class PendingFollowupChangedError extends Error {
8
+ constructor();
9
+ }
6
10
  /** Renderer-neutral options for one admitted runtime request. */
7
11
  export interface AgentRuntimeRunInputOptionsV1 {
8
12
  readonly abortSignal?: AbortSignal;
@@ -1,3 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PendingFollowupChangedError = void 0;
4
+ /** The queue changed before this selection crossed the durable admission boundary. */
5
+ class PendingFollowupChangedError extends Error {
6
+ constructor() {
7
+ super('Pending follow-up changed before admission.');
8
+ this.name = 'PendingFollowupChangedError';
9
+ }
10
+ }
11
+ exports.PendingFollowupChangedError = PendingFollowupChangedError;
3
12
  //# sourceMappingURL=agent-runtime-runner.js.map
@@ -9,6 +9,7 @@ const CORE = new Set([
9
9
  'glob',
10
10
  'grep',
11
11
  'list_files',
12
+ 'process_session',
12
13
  'read_file',
13
14
  'subtask',
14
15
  'todo_write',
@@ -17,7 +18,8 @@ const CORE = new Set([
17
18
  const LONG_TAIL = new Set(['web_fetch', 'web_search']);
18
19
  const EXCLUDED_LEGACY_TOOLS = new Set(['mcp_call', 'mcp_list']);
19
20
  const NETWORK_READ = new Set(['web_fetch', 'web_search']);
20
- const NETWORK_WRITE = new Set(['git_push']);
21
+ const EXTERNAL_WRITES = new Set(['git_push']);
22
+ const NETWORK_WRITE = new Set([...EXTERNAL_WRITES, 'exec_command', 'process_session']);
21
23
  const WORKSPACE_WRITES = new Set([
22
24
  'edit_file',
23
25
  'exec_command',
@@ -25,6 +27,7 @@ const WORKSPACE_WRITES = new Set([
25
27
  'git_commit',
26
28
  'memory_forget',
27
29
  'memory_save',
30
+ 'process_session',
28
31
  'write_file',
29
32
  ]);
30
33
  const FILE_EDITS = new Set(['edit_file', 'write_file']);
@@ -175,10 +178,8 @@ function policyFor(name) {
175
178
  ? 'write'
176
179
  : NETWORK_READ.has(name)
177
180
  ? 'read'
178
- : name === 'exec_command'
179
- ? 'write'
180
- : 'none';
181
- const effect = NETWORK_WRITE.has(name)
181
+ : 'none';
182
+ const effect = EXTERNAL_WRITES.has(name)
182
183
  ? 'external_write'
183
184
  : WORKSPACE_WRITES.has(name)
184
185
  ? 'workspace_write'
@@ -25,7 +25,7 @@ export declare const PROMPT_CURSOR_GLYPH = "\u258C";
25
25
  export declare function promptContentWidth(width: number): number;
26
26
  export declare function promptTextWidth(width: number): number;
27
27
  export declare function splitByVisualWidth(text: string, maxWidth: number): string[];
28
- export declare function getPromptVisualLines(value: string, width: number): PromptVisualLine[];
28
+ export declare function getPromptVisualLines(value: string, width: number, reservedColumns?: number): PromptVisualLine[];
29
29
  export declare function getVisiblePromptVisualLines(value: string, width: number, maxRows: number): {
30
30
  lines: PromptVisualLine[];
31
31
  hiddenRows: number;
@@ -66,8 +66,9 @@ function splitByVisualWidthWithOffsets(text, maxWidth) {
66
66
  chunks.push({ content: current, start: currentStart, end: text.length });
67
67
  return chunks;
68
68
  }
69
- function getPromptVisualLines(value, width) {
70
- return buildPromptVisualLines(value, width).lines;
69
+ function getPromptVisualLines(value, width, reservedColumns) {
70
+ const textWidth = reservedColumns === undefined ? promptTextWidth(width) : Math.max(1, width - reservedColumns);
71
+ return buildPromptVisualLines(value, textWidth).lines;
71
72
  }
72
73
  function getVisiblePromptVisualLines(value, width, maxRows) {
73
74
  const lines = getPromptVisualLines(value, width);
@@ -81,7 +82,7 @@ function getVisiblePromptVisualLines(value, width, maxRows) {
81
82
  };
82
83
  }
83
84
  function getPromptInputViewport(value, width, maxRows, cursor = value.length) {
84
- const layout = buildPromptVisualLines(value, width, cursor);
85
+ const layout = buildPromptVisualLines(value, promptTextWidth(width), cursor);
85
86
  const allLines = layout.lines;
86
87
  const rowLimit = Math.max(1, maxRows);
87
88
  const showHiddenIndicator = allLines.length > rowLimit && rowLimit > 1;
@@ -102,9 +103,8 @@ function getPromptInputViewport(value, width, maxRows, cursor = value.length) {
102
103
  rowsUpFromPromptBottom: Math.max(1, contentRows - cursorLineIndex + 1),
103
104
  };
104
105
  }
105
- function buildPromptVisualLines(value, width, cursor = value.length) {
106
+ function buildPromptVisualLines(value, maxTextWidth, cursor = value.length) {
106
107
  const logicalLines = value.length > 0 ? value.split('\n') : [''];
107
- const maxTextWidth = promptTextWidth(width);
108
108
  const clampedCursor = Math.min(Math.max(0, cursor), value.length);
109
109
  const visualLines = [];
110
110
  let cursorLineIndex = 0;
@@ -1,5 +1,5 @@
1
1
  import type { ToolInputJSONSchema } from '../../framework/tool';
2
- export type FirstPartyCoreToolNameV1 = 'edit_file' | 'exec_command' | 'glob' | 'grep' | 'list_files' | 'read_file' | 'write_file';
2
+ export type FirstPartyCoreToolNameV1 = 'edit_file' | 'exec_command' | 'glob' | 'grep' | 'list_files' | 'process_session' | 'read_file' | 'write_file';
3
3
  export interface CoreToolDescriptorSpecV1 {
4
4
  readonly name: FirstPartyCoreToolNameV1;
5
5
  readonly aliases: readonly string[];
@@ -70,7 +70,7 @@ exports.CORE_TOOL_DESCRIPTORS = deepFreeze([
70
70
  {
71
71
  name: 'exec_command',
72
72
  aliases: [],
73
- description: '执行一个 shell 命令。返回 stdout 和 stderr。输出超过 maxOutput 会自动截断。',
73
+ description: '执行一个 shell 命令并返回输出。默认关闭 stdin 并等待退出。设置 interactive: true 可提前返回仍在运行的 processId,再用 process_session 读取输出、写 stdin 或取消。',
74
74
  parameters: {
75
75
  type: 'object',
76
76
  properties: {
@@ -88,6 +88,16 @@ exports.CORE_TOOL_DESCRIPTORS = deepFreeze([
88
88
  minimum: 1024,
89
89
  maximum: 10485760,
90
90
  },
91
+ interactive: {
92
+ type: 'boolean',
93
+ description: '保留 stdin 并允许同一回合内继续交互(默认 false)',
94
+ },
95
+ yieldMs: {
96
+ type: 'number',
97
+ description: '仅交互模式,首次等输出或退出的时长 ms(默认 500)',
98
+ minimum: 0,
99
+ maximum: 5000,
100
+ },
91
101
  },
92
102
  required: ['command'],
93
103
  },
@@ -98,6 +108,34 @@ exports.CORE_TOOL_DESCRIPTORS = deepFreeze([
98
108
  destructive: true,
99
109
  fileEdit: false,
100
110
  },
111
+ {
112
+ name: 'process_session',
113
+ aliases: [],
114
+ description: '操作本回合由 exec_command 启动的交互进程。poll 读取新增输出,write 发送原样输入,cancel 终止进程。最后一段输出和退出状态可读取一次。此工具不用于交付验证通过的证据。',
115
+ parameters: {
116
+ type: 'object',
117
+ properties: {
118
+ processId: { type: 'string', description: 'exec_command 返回的 metadata.processId' },
119
+ action: { type: 'string', enum: ['poll', 'write', 'cancel'] },
120
+ input: {
121
+ type: 'string',
122
+ description: 'write 时必填,不自动追加换行,最多 65536 UTF-8 字节',
123
+ },
124
+ yieldMs: {
125
+ type: 'number',
126
+ description: '等新增输出或退出的最长时长 ms(默认 500)',
127
+ minimum: 0,
128
+ maximum: 5000,
129
+ },
130
+ },
131
+ required: ['processId', 'action'],
132
+ },
133
+ permission: 'allow',
134
+ readOnly: false,
135
+ concurrencySafe: false,
136
+ destructive: false,
137
+ fileEdit: false,
138
+ },
101
139
  {
102
140
  name: 'edit_file',
103
141
  aliases: [],
@@ -180,6 +180,7 @@ const DEFAULT_CORE_TOOL_IMPORTERS = Object.freeze({
180
180
  glob: () => Promise.resolve().then(() => __importStar(require('../tools/core/glob'))),
181
181
  grep: () => Promise.resolve().then(() => __importStar(require('../tools/core/grep'))),
182
182
  list_files: () => Promise.resolve().then(() => __importStar(require('../tools/core/list-files'))),
183
+ process_session: () => Promise.resolve().then(() => __importStar(require('../tools/core/process-session'))),
183
184
  read_file: () => Promise.resolve().then(() => __importStar(require('../tools/core/read-file'))),
184
185
  write_file: () => Promise.resolve().then(() => __importStar(require('../tools/core/write-file'))),
185
186
  });
@@ -113,6 +113,13 @@ class FirstPartySandboxServiceV1 {
113
113
  const descriptor = input.descriptor;
114
114
  if (descriptor.name === 'exec_command')
115
115
  return this.prepareCommand(input);
116
+ if (descriptor.name === 'process_session') {
117
+ const id = typeof input.args.processId === 'string' ? input.args.processId : '';
118
+ const backend = input.context?.shellProcesses?.backendFor(id, input.snapshot.authority.projectRoot);
119
+ return backend && backend !== 'none'
120
+ ? sandbox(backend, 'full', 'Process I/O inherits the sandbox of its authorized launch.')
121
+ : sandbox('unavailable', 'partial', 'No sandboxed process is bound to this handle.');
122
+ }
116
123
  if (descriptor.risk.network === 'none' &&
117
124
  (descriptor.risk.effect === 'none' ||
118
125
  descriptor.risk.effect === 'workspace_read' ||
@@ -139,6 +146,9 @@ class FirstPartySandboxServiceV1 {
139
146
  });
140
147
  if (!plan.ok)
141
148
  return sandbox('unavailable', 'partial', plan.reason);
149
+ if (plan.backend === 'docker' && input.args.interactive === true) {
150
+ return sandbox('docker', 'partial', 'The Docker sandbox does not support interactive process sessions.');
151
+ }
142
152
  if (plan.backend === 'none') {
143
153
  return sandbox('none', 'none', 'Configured shell execution has no sandbox backend.');
144
154
  }
@@ -152,6 +152,11 @@ class GoalLifecycleServiceV2 {
152
152
  resources: resourceSnapshot,
153
153
  });
154
154
  }
155
+ else if (observation.requestDecision?.status === 'completed' &&
156
+ observation.taskContextCompletion) {
157
+ status = 'paused';
158
+ decision = goalDecision('stopped', 'pause_scope', 'goal_verification_pending', 'The model ended the turn. Goal verification is still pending.', resourceSnapshot);
159
+ }
155
160
  else if (observation.continuationMode === 'manual') {
156
161
  status = 'paused';
157
162
  decision = goalDecision('stopped', 'pause_scope', 'goal_manual_continuation', 'Goal checkpoint saved. Manual continuation is enabled; use /goal resume for the next turn.', resourceSnapshot);
@@ -260,7 +260,11 @@ class GoalRuntimeCoordinatorV2 {
260
260
  });
261
261
  const observation = this.observeTurn(turn, requestDecision);
262
262
  const resolution = candidate.finalizeTurn(observation);
263
- const stopDecision = resolution.decision ?? requestDecision;
263
+ // The Goal keeps its own resumable state. Its open criteria do not turn
264
+ // the model's normal reply into a refused request.
265
+ const stopDecision = resolution.decision?.reason.code === 'goal_verification_pending'
266
+ ? requestDecision
267
+ : (resolution.decision ?? requestDecision);
264
268
  const receipt = persist({
265
269
  goalState: resolution.state,
266
270
  ...(stopDecision ? { stopDecision } : {}),
@@ -609,7 +613,7 @@ function defaultContinuationInput(state) {
609
613
  'Continue the active Goal using saved state and receipts.',
610
614
  `Objective: ${objective}`,
611
615
  'Use the current TaskContext verification requirements when the user has corrected a check.',
612
- 'Do not claim completion unless the TaskContext completion gate verifies every criterion.',
616
+ 'Report which checks passed and which remain unverified. End the turn when you have an answer for the user.',
613
617
  ].join('\n');
614
618
  }
615
619
  function deepFreeze(value) {
@@ -285,6 +285,8 @@ function classifyGoalEvidenceKind(name, args) {
285
285
  if (normalizedName === 'get_goal' || normalizedName === 'update_goal_plan')
286
286
  return 'runtime';
287
287
  if (normalizedName === 'exec_command') {
288
+ if (args.interactive === true)
289
+ return null;
288
290
  const command = typeof args.command === 'string' ? args.command : '';
289
291
  if (hasStatusMaskingControlFlow(command))
290
292
  return null;
@@ -94,6 +94,13 @@ export declare function resolveSessionStorageV1(projectPathInput: string, sessio
94
94
  * authoritative open once and rebuild the derived checkpoint.
95
95
  */
96
96
  export declare function openSessionCheckpointStorageV1(projectPathInput: string, sessionId: string): OpenedSessionCheckpointStorageV1 | undefined;
97
+ /** Classify the storage binding even when its cached checkpoint is unavailable. */
98
+ export declare function peekSessionCheckpointStorageV1(projectPathInput: string, sessionId: string, maxBytes: number): {
99
+ readonly kind: 'legacy';
100
+ } | {
101
+ readonly kind: 'thread';
102
+ readonly checkpoint: OpenedSessionCheckpointStorageV1 | undefined;
103
+ };
97
104
  /**
98
105
  * Resolve and verify one storage generation while retaining the verified
99
106
  * ThreadEventStore. Read-side projections can then capture transcript and