@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
@@ -277,12 +277,22 @@ function normalizeCompleteStreamToolCall(call) {
277
277
  call.function.arguments = JSON.stringify(args);
278
278
  return true;
279
279
  }
280
+ function rejectsStructuredOutput(error) {
281
+ if (!(error instanceof openai_1.default.APIError) || (error.status !== 400 && error.status !== 422)) {
282
+ return false;
283
+ }
284
+ return (error.param === 'response_format' ||
285
+ error.param?.startsWith('response_format.') === true ||
286
+ error.code === 'unsupported_response_format' ||
287
+ /(?:response[_ ]format|json_schema).{0,100}(?:unsupported|not supported|not recognized|unknown)|(?:unsupported|unknown).{0,100}(?:response[_ ]format|json_schema)/iu.test(error.message));
288
+ }
280
289
  class LLMService {
281
290
  constructor(config) {
282
291
  this.providerKey = 'default';
283
292
  this.compactTransportRevision = 0;
284
293
  this.consecutive529Errors = 0;
285
294
  this.usingFallback = false;
295
+ this.structuredOutputFallbackRoutes = new Set();
286
296
  this.usageObservers = new Set();
287
297
  // v0.2.25: disable SDK built-in retry (maxRetries=0). Orion Code owns retry policy.
288
298
  this.client = new openai_1.default({
@@ -500,7 +510,7 @@ class LLMService {
500
510
  return visibleStreamText;
501
511
  };
502
512
  let incompleteAttempt;
503
- const readAttempt = async (route, model, signal, reporter) => {
513
+ const readAttempt = async (route, model, attempt, signal, reporter) => {
504
514
  const params = {
505
515
  model,
506
516
  messages: this.toOpenAIMessages(messages),
@@ -511,8 +521,42 @@ class LLMService {
511
521
  ...(0, effort_1.buildProviderEffortParams)(route.effort),
512
522
  ...(tools?.length ? { tools: tools } : {}),
513
523
  };
524
+ const schema = options?.outputSchema;
525
+ const routeKey = typeof schema === 'object' &&
526
+ schema.type === 'object' &&
527
+ route.effort.protocol === 'openai-completions'
528
+ ? JSON.stringify([route.providerKey, model])
529
+ : undefined;
530
+ if (routeKey !== undefined && !this.structuredOutputFallbackRoutes.has(routeKey)) {
531
+ params.response_format = {
532
+ type: 'json_schema',
533
+ json_schema: { name: 'orion_print_result', schema, strict: false },
534
+ };
535
+ }
514
536
  onThinking?.();
515
- const stream = (await route.client.chat.completions.create(params, { ...(signal ? { signal } : {}), __streamClass: chat_completion_sse_1.ChatCompletionSseStream }));
537
+ const openStream = async () => (await route.client.chat.completions.create(params, {
538
+ ...(signal ? { signal } : {}),
539
+ __streamClass: chat_completion_sse_1.ChatCompletionSseStream,
540
+ }));
541
+ let stream;
542
+ try {
543
+ stream = await openStream();
544
+ }
545
+ catch (error) {
546
+ if (routeKey === undefined || !params.response_format || !rejectsStructuredOutput(error)) {
547
+ throw error;
548
+ }
549
+ this.structuredOutputFallbackRoutes.add(routeKey);
550
+ delete params.response_format;
551
+ throwIfAborted(signal);
552
+ await this.assertProviderRequestAllowed('chat_stream', attempt + 1, messages, model);
553
+ const diagnostic = (0, provider_diagnostics_1.diagnoseProviderError)(error);
554
+ requestDiagnostics.retryCount++;
555
+ requestDiagnostics.retryErrorTypes.push(diagnostic.type);
556
+ requestDiagnostics.lastRetryErrorType = diagnostic.type;
557
+ requestDiagnostics.lastRetryStatus = diagnostic.status;
558
+ stream = await openStream();
559
+ }
516
560
  let content = '';
517
561
  let usedModel = model;
518
562
  let usage;
@@ -657,7 +701,7 @@ class LLMService {
657
701
  throwIfAborted(signal);
658
702
  await this.assertProviderRequestAllowed('chat_stream', attempt, messages, model);
659
703
  const route = this.requestRoute(modelSnapshot, model, providerKey);
660
- return readAttempt(route, model, signal, reporter);
704
+ return readAttempt(route, model, attempt, signal, reporter);
661
705
  });
662
706
  // Unpack resilience result
663
707
  const response = streamResult.result;
@@ -678,7 +722,7 @@ class LLMService {
678
722
  const route = this.usingFallback && modelSnapshot.fallback
679
723
  ? modelSnapshot.fallback
680
724
  : this.requestRoute(modelSnapshot, this.config.model);
681
- const { response } = await readAttempt(route, this.config.model, options?.abortSignal);
725
+ const { response } = await readAttempt(route, this.config.model, attempt, options?.abortSignal);
682
726
  this.consecutive529Errors = 0;
683
727
  return response;
684
728
  }, retryConfig);
@@ -227,7 +227,8 @@ class RawTerminalEditor {
227
227
  }
228
228
  return;
229
229
  }
230
- this.applyKey(event.key);
230
+ if (event.type === 'key')
231
+ this.applyKey(event.key);
231
232
  }
232
233
  emitPasteNotice(value) {
233
234
  const lines = (0, input_parser_1.normalizePastedText)(value).split('\n').length;
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * Provides safety checks and sandbox options for command execution.
5
5
  */
6
+ export { scanShellCommand, type ShellCommandScan } from '../utils/shell-command';
6
7
  /**
7
8
  * Commands that are considered read-only and safe to execute without confirmation.
8
9
  * These commands only read data and do not modify the filesystem.
@@ -42,30 +43,6 @@ export declare const DANGEROUS_PATTERNS: {
42
43
  * Potentially destructive patterns that should ask for confirmation.
43
44
  */
44
45
  export declare const POTENTIALLY_DESTRUCTIVE_PATTERNS: RegExp[];
45
- /**
46
- * Result of a quote-aware scan over a whole command line.
47
- */
48
- export interface ShellCommandScan {
49
- /** The individual commands on the line, split on unquoted separators. */
50
- segments: string[];
51
- /**
52
- * False when the line uses a construct this scanner cannot reason about --
53
- * command substitution, process substitution or an unbalanced quote. Such a
54
- * line can hide an arbitrary command and must never be auto-approved.
55
- */
56
- supported: boolean;
57
- /** True when the line redirects output somewhere other than /dev/null. */
58
- writesFile: boolean;
59
- }
60
- /**
61
- * Split a command line into the individual commands it will actually run.
62
- *
63
- * The classifier below hands out "run without confirmation" verdicts, so it has
64
- * to see every command on the line rather than just the leading token. Quote
65
- * state is tracked so `echo "a && b"` stays one segment, and substitutions are
66
- * reported as unsupported instead of being silently skipped over.
67
- */
68
- export declare function scanShellCommand(cmd: string): ShellCommandScan;
69
46
  /**
70
47
  * Check if a command is read-only and safe to execute without confirmation.
71
48
  *
@@ -5,8 +5,7 @@
5
5
  * Provides safety checks and sandbox options for command execution.
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.POTENTIALLY_DESTRUCTIVE_PATTERNS = exports.DANGEROUS_PATTERNS = exports.VALIDATION_COMMAND_PATTERNS = exports.READ_ONLY_SUBCOMMANDS = exports.READ_ONLY_COMMANDS = void 0;
9
- exports.scanShellCommand = scanShellCommand;
8
+ exports.POTENTIALLY_DESTRUCTIVE_PATTERNS = exports.DANGEROUS_PATTERNS = exports.VALIDATION_COMMAND_PATTERNS = exports.READ_ONLY_SUBCOMMANDS = exports.READ_ONLY_COMMANDS = exports.scanShellCommand = void 0;
10
9
  exports.isReadOnlyCommand = isReadOnlyCommand;
11
10
  exports.isValidationCommand = isValidationCommand;
12
11
  exports.containsRecursiveRm = containsRecursiveRm;
@@ -15,6 +14,9 @@ exports.checkDangerousCommand = checkDangerousCommand;
15
14
  exports.isPotentiallyDestructive = isPotentiallyDestructive;
16
15
  exports.assessCommandSecurity = assessCommandSecurity;
17
16
  const path_1 = require("path");
17
+ const shell_command_1 = require("../utils/shell-command");
18
+ var shell_command_2 = require("../utils/shell-command");
19
+ Object.defineProperty(exports, "scanShellCommand", { enumerable: true, get: function () { return shell_command_2.scanShellCommand; } });
18
20
  /**
19
21
  * Commands that are considered read-only and safe to execute without confirmation.
20
22
  * These commands only read data and do not modify the filesystem.
@@ -251,125 +253,6 @@ exports.POTENTIALLY_DESTRUCTIVE_PATTERNS = [
251
253
  /curl.*>\s*\//,
252
254
  /wget.*-O\s*\//,
253
255
  ];
254
- /** The one redirect target that does not count as writing to the filesystem. */
255
- const DISCARD_REDIRECT_TARGET = '/dev/null';
256
- /**
257
- * Split a command line into the individual commands it will actually run.
258
- *
259
- * The classifier below hands out "run without confirmation" verdicts, so it has
260
- * to see every command on the line rather than just the leading token. Quote
261
- * state is tracked so `echo "a && b"` stays one segment, and substitutions are
262
- * reported as unsupported instead of being silently skipped over.
263
- */
264
- function scanShellCommand(cmd) {
265
- const segments = [];
266
- let current = '';
267
- let supported = true;
268
- let writesFile = false;
269
- let inSingleQuote = false;
270
- let inDoubleQuote = false;
271
- const pushSegment = () => {
272
- const segment = current.trim();
273
- if (segment.length > 0) {
274
- segments.push(segment);
275
- }
276
- current = '';
277
- };
278
- for (let i = 0; i < cmd.length; i++) {
279
- const ch = cmd[i];
280
- const next = cmd[i + 1];
281
- if (ch === '\\' && !inSingleQuote && next !== undefined) {
282
- current += ch + next;
283
- i++;
284
- continue;
285
- }
286
- if (ch === "'" && !inDoubleQuote) {
287
- inSingleQuote = !inSingleQuote;
288
- current += ch;
289
- continue;
290
- }
291
- if (ch === '"' && !inSingleQuote) {
292
- inDoubleQuote = !inDoubleQuote;
293
- current += ch;
294
- continue;
295
- }
296
- if (inSingleQuote) {
297
- // Single quotes disable every expansion, so the contents stay inert.
298
- current += ch;
299
- continue;
300
- }
301
- if (inDoubleQuote) {
302
- // Double quotes only suppress globbing and word splitting -- bash still
303
- // expands `$(...)` and backticks inside them. Skipping the substitution
304
- // check here made `echo "$(rm -rf $HOME)"` classify as safe/read-only and
305
- // auto-approve, i.e. a straight command-execution bypass.
306
- if (ch === '`' || (ch === '$' && next === '(')) {
307
- supported = false;
308
- }
309
- current += ch;
310
- continue;
311
- }
312
- // Command and process substitution can hide an arbitrary command inside an
313
- // otherwise innocent-looking line, and neither is worth modelling here.
314
- if (ch === '`' ||
315
- (ch === '$' && next === '(') ||
316
- ((ch === '<' || ch === '>') && next === '(')) {
317
- supported = false;
318
- current += ch;
319
- continue;
320
- }
321
- if (ch === ';' || ch === '\n') {
322
- pushSegment();
323
- continue;
324
- }
325
- if ((ch === '&' && next === '&') || (ch === '|' && next === '|')) {
326
- pushSegment();
327
- i++;
328
- continue;
329
- }
330
- if (ch === '&' || ch === '|') {
331
- pushSegment();
332
- continue;
333
- }
334
- if (ch === '>') {
335
- let cursor = i + 1;
336
- if (cmd[cursor] === '>') {
337
- cursor++;
338
- }
339
- if (cmd[cursor] === '&') {
340
- // `>&1` / `2>&1` duplicate a descriptor and `>&-` closes one; nothing
341
- // reaches the filesystem. Consume the whole reference so its `&` is not
342
- // mistaken for a background-job separator.
343
- let end = cursor + 1;
344
- while (end < cmd.length && cmd[end] >= '0' && cmd[end] <= '9') {
345
- end++;
346
- }
347
- if (cmd[end] === '-') {
348
- end++;
349
- }
350
- current += cmd.slice(i, end);
351
- i = end - 1;
352
- continue;
353
- }
354
- while (cursor < cmd.length && (cmd[cursor] === ' ' || cmd[cursor] === '\t')) {
355
- cursor++;
356
- }
357
- const target = cmd.slice(cursor).split(/[\s;&|<>]/)[0];
358
- if (target !== DISCARD_REDIRECT_TARGET) {
359
- writesFile = true;
360
- }
361
- current += ch;
362
- continue;
363
- }
364
- current += ch;
365
- }
366
- pushSegment();
367
- return {
368
- segments,
369
- supported: supported && !inSingleQuote && !inDoubleQuote,
370
- writesFile,
371
- };
372
- }
373
256
  /**
374
257
  * Require every command on the line to satisfy `predicate`.
375
258
  *
@@ -377,7 +260,7 @@ function scanShellCommand(cmd) {
377
260
  * is what stops `echo hi && rm -rf ~` from inheriting `echo`'s verdict.
378
261
  */
379
262
  function everySegmentSatisfies(cmd, predicate) {
380
- const scan = scanShellCommand(cmd.trim());
263
+ const scan = (0, shell_command_1.scanShellCommand)(cmd.trim());
381
264
  if (!scan.supported || scan.writesFile || scan.segments.length === 0) {
382
265
  return false;
383
266
  }
@@ -758,7 +641,7 @@ function parseRmInvocation(segment) {
758
641
  * misclassify recursive deletion as an ordinary state write.
759
642
  */
760
643
  function containsRecursiveRm(cmd) {
761
- const scan = scanShellCommand(cmd);
644
+ const scan = (0, shell_command_1.scanShellCommand)(cmd);
762
645
  if (!scan.supported) {
763
646
  // Unsupported substitutions remain non-read-only and therefore require an
764
647
  // explicit policy decision, but uncertainty alone is not proof that the
@@ -784,7 +667,7 @@ function containsRecursiveRm(cmd) {
784
667
  * on GNU coreutils.
785
668
  */
786
669
  function findDestructiveRmTarget(cmd) {
787
- for (const segment of scanShellCommand(cmd).segments) {
670
+ for (const segment of (0, shell_command_1.scanShellCommand)(cmd).segments) {
788
671
  const invocation = parseRmInvocation(segment);
789
672
  if (!invocation)
790
673
  continue;
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.coreTool = void 0;
4
- const child_process_1 = require("child_process");
5
4
  const fs_1 = require("fs");
6
5
  const path_1 = require("path");
7
6
  const tool_1 = require("../../framework/tool");
8
7
  const descriptors_1 = require("../../runtime/core-tools/descriptors");
8
+ const shell_process_sessions_1 = require("../../runtime/shell-process-sessions");
9
+ const command_process_1 = require("../../utils/command-process");
9
10
  const utf8_1 = require("../../utils/utf8");
10
11
  const bash_security_1 = require("../bash_security");
11
12
  const sandbox_1 = require("../sandbox");
@@ -26,11 +27,17 @@ exports.coreTool = (0, tool_1.buildTool)({
26
27
  if (!command || typeof command !== 'string') {
27
28
  return { success: false, output: '', error: 'exec_command requires a command parameter' };
28
29
  }
29
- // Issue #32 #3.2: 传递 abortSignal
30
- return execCommand_(command, args.cwd, args.timeout, args.maxOutput, context.abortSignal, context.cwd);
30
+ return execCommand(command, args, context);
31
31
  },
32
32
  validateInput: args => (0, common_1.validateOptionalSafeInteger)(args, 'exec_command', 'timeout', EXEC_COMMAND_MIN_TIMEOUT_MS, EXEC_COMMAND_MAX_TIMEOUT_MS) ??
33
- (0, common_1.validateOptionalSafeInteger)(args, 'exec_command', 'maxOutput', EXEC_COMMAND_MIN_OUTPUT_BYTES, EXEC_COMMAND_MAX_OUTPUT_BYTES),
33
+ (0, common_1.validateOptionalSafeInteger)(args, 'exec_command', 'maxOutput', EXEC_COMMAND_MIN_OUTPUT_BYTES, EXEC_COMMAND_MAX_OUTPUT_BYTES) ??
34
+ (args.interactive !== undefined && typeof args.interactive !== 'boolean'
35
+ ? 'exec_command interactive must be a boolean'
36
+ : undefined) ??
37
+ (args.yieldMs !== undefined && args.interactive !== true
38
+ ? 'exec_command yieldMs requires interactive: true'
39
+ : undefined) ??
40
+ (0, common_1.validateOptionalSafeInteger)(args, 'exec_command', 'yieldMs', 0, shell_process_sessions_1.MAX_PROCESS_YIELD_MS),
34
41
  isDestructive: args => {
35
42
  const cmd = args.command || '';
36
43
  return (0, bash_security_1.containsRecursiveRm)(cmd) || /(?:^|[;&|]\s*)(?:[^\s]+\/)?(?:mkfs|dd)(?:\s|$)/.test(cmd);
@@ -74,7 +81,7 @@ exports.coreTool = (0, tool_1.buildTool)({
74
81
  }
75
82
  sandboxNote = ` [${(0, sandbox_1.describeSandboxPlan)(plan)}]`;
76
83
  }
77
- if (security.level === 'safe' && security.isReadOnly) {
84
+ if (security.level === 'safe' && security.isReadOnly && args.interactive !== true) {
78
85
  return { behavior: 'allow' };
79
86
  }
80
87
  if (security.level === 'caution') {
@@ -88,11 +95,11 @@ exports.coreTool = (0, tool_1.buildTool)({
88
95
  },
89
96
  isReadOnly: args => {
90
97
  const cmd = args.command || '';
91
- return (0, bash_security_1.isReadOnlyCommand)(cmd);
98
+ return args.interactive !== true && (0, bash_security_1.isReadOnlyCommand)(cmd);
92
99
  },
93
100
  isConcurrencySafe: args => {
94
101
  const cmd = args.command || '';
95
- return (0, bash_security_1.isReadOnlyCommand)(cmd);
102
+ return args.interactive !== true && (0, bash_security_1.isReadOnlyCommand)(cmd);
96
103
  },
97
104
  userFacingName: args => `Exec ${(0, common_1.compactOneLine)(args.command || '', 80)}`,
98
105
  getSummary: (args, result) => {
@@ -165,10 +172,10 @@ function resolveExecCommandPaths(cwd, baseCwd) {
165
172
  projectRoot,
166
173
  };
167
174
  }
168
- async function execCommand_(command, cwd, timeout, maxOutput, abortSignal, baseCwd, sandbox) {
175
+ async function execCommand(command, args, context) {
169
176
  let paths;
170
177
  try {
171
- paths = resolveExecCommandPaths(cwd, baseCwd);
178
+ paths = resolveExecCommandPaths(args.cwd, context.cwd);
172
179
  }
173
180
  catch (error) {
174
181
  return {
@@ -184,7 +191,7 @@ async function execCommand_(command, cwd, timeout, maxOutput, abortSignal, baseC
184
191
  const plan = (0, sandbox_1.planSandboxedCommand)(command, {
185
192
  cwd: workdir,
186
193
  projectRoot,
187
- settings: sandbox ?? (0, sandbox_1.resolveSandboxSettings)(projectRoot),
194
+ settings: (0, sandbox_1.resolveSandboxSettings)(projectRoot),
188
195
  });
189
196
  if (!plan.ok) {
190
197
  return {
@@ -194,9 +201,37 @@ async function execCommand_(command, cwd, timeout, maxOutput, abortSignal, baseC
194
201
  'Set sandbox.profile to "none" to run without isolation.',
195
202
  };
196
203
  }
204
+ const timeoutMs = args.timeout ?? 30000;
205
+ const maxBytes = args.maxOutput ?? 51200;
206
+ const { abortSignal } = context;
207
+ if (args.interactive === true) {
208
+ if (!context.shellProcesses) {
209
+ return {
210
+ success: false,
211
+ output: '',
212
+ error: 'Interactive processes require an active runtime turn.',
213
+ };
214
+ }
215
+ if (plan.backend === 'docker') {
216
+ return {
217
+ success: false,
218
+ output: '',
219
+ error: 'The Docker sandbox does not support interactive process sessions.',
220
+ };
221
+ }
222
+ return context.shellProcesses.start({
223
+ file: plan.file,
224
+ args: plan.args,
225
+ cwd: workdir,
226
+ projectRoot,
227
+ backend: plan.backend,
228
+ timeoutMs,
229
+ maxOutputBytes: maxBytes,
230
+ yieldMs: args.yieldMs ?? shell_process_sessions_1.DEFAULT_PROCESS_YIELD_MS,
231
+ signal: abortSignal,
232
+ });
233
+ }
197
234
  return new Promise(resolve => {
198
- const timeoutMs = timeout ?? 30000;
199
- const maxBytes = maxOutput ?? 51200; // Default 50KB, Issue #28 fix
200
235
  // The docker backend bind-mounts `workdir` into the container; the host
201
236
  // directory must exist at container-creation time or the mount fails with a
202
237
  // confusing "nonexistent directory" error. Create it deterministically
@@ -211,11 +246,7 @@ async function execCommand_(command, cwd, timeout, maxOutput, abortSignal, baseC
211
246
  }
212
247
  // Use spawn for streaming output with truncation support. The user command
213
248
  // is a single argv element, so no intermediate shell re-parses it.
214
- const useProcessGroup = process.platform !== 'win32';
215
- const child = (0, child_process_1.spawn)(plan.file, plan.args, {
216
- cwd: workdir,
217
- detached: useProcessGroup,
218
- });
249
+ const child = (0, command_process_1.spawnCommandProcess)(plan.file, plan.args, workdir);
219
250
  // Issue #53: exec_command runs a complete command as a single argv element
220
251
  // and never pipes input into it. If stdin stays open, stdin-reading commands
221
252
  // (cat, sort, grep, `python3 -`, ...) block waiting for EOF until the timeout.
@@ -246,33 +277,11 @@ async function execCommand_(command, cwd, timeout, maxOutput, abortSignal, baseC
246
277
  resolve(result);
247
278
  };
248
279
  const terminateChild = () => {
249
- if (!child.pid || child.killed)
280
+ if (killTimerId || !(0, command_process_1.signalCommandProcess)(child, 'SIGTERM'))
250
281
  return;
251
- try {
252
- if (useProcessGroup) {
253
- process.kill(-child.pid, 'SIGTERM');
254
- }
255
- else {
256
- child.kill('SIGTERM');
257
- }
258
- }
259
- catch {
260
- child.kill('SIGTERM');
261
- }
262
282
  killTimerId = setTimeout(() => {
263
- if (!child.pid || child.killed || settled)
264
- return;
265
- try {
266
- if (useProcessGroup) {
267
- process.kill(-child.pid, 'SIGKILL');
268
- }
269
- else {
270
- child.kill('SIGKILL');
271
- }
272
- }
273
- catch {
274
- child.kill('SIGKILL');
275
- }
283
+ if (!settled)
284
+ (0, command_process_1.signalCommandProcess)(child, 'SIGKILL');
276
285
  }, 500);
277
286
  killTimerId.unref?.();
278
287
  };
@@ -4,6 +4,7 @@ import { coreTool as execCommandTool } from './exec-command';
4
4
  import { coreTool as globTool } from './glob';
5
5
  import { coreTool as grepTool } from './grep';
6
6
  import { coreTool as listFilesTool } from './list-files';
7
+ import { coreTool as processSessionTool } from './process-session';
7
8
  import { coreTool as readFileTool } from './read-file';
8
9
  import { coreTool as writeFileTool } from './write-file';
9
10
  /**
@@ -11,5 +12,5 @@ import { coreTool as writeFileTool } from './write-file';
11
12
  * Production lazy callers import an individual shard directly instead.
12
13
  */
13
14
  export declare const CORE_TOOLS: readonly OrionCodeTool[];
14
- export { editFileTool, execCommandTool, globTool, grepTool, listFilesTool, readFileTool, writeFileTool, };
15
+ export { editFileTool, execCommandTool, globTool, grepTool, listFilesTool, processSessionTool, readFileTool, writeFileTool, };
15
16
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeFileTool = exports.readFileTool = exports.listFilesTool = exports.grepTool = exports.globTool = exports.execCommandTool = exports.editFileTool = exports.CORE_TOOLS = void 0;
3
+ exports.writeFileTool = exports.readFileTool = exports.processSessionTool = exports.listFilesTool = exports.grepTool = exports.globTool = exports.execCommandTool = exports.editFileTool = exports.CORE_TOOLS = void 0;
4
4
  const edit_file_1 = require("./edit-file");
5
5
  Object.defineProperty(exports, "editFileTool", { enumerable: true, get: function () { return edit_file_1.coreTool; } });
6
6
  const exec_command_1 = require("./exec-command");
@@ -11,6 +11,8 @@ const grep_1 = require("./grep");
11
11
  Object.defineProperty(exports, "grepTool", { enumerable: true, get: function () { return grep_1.coreTool; } });
12
12
  const list_files_1 = require("./list-files");
13
13
  Object.defineProperty(exports, "listFilesTool", { enumerable: true, get: function () { return list_files_1.coreTool; } });
14
+ const process_session_1 = require("./process-session");
15
+ Object.defineProperty(exports, "processSessionTool", { enumerable: true, get: function () { return process_session_1.coreTool; } });
14
16
  const read_file_1 = require("./read-file");
15
17
  Object.defineProperty(exports, "readFileTool", { enumerable: true, get: function () { return read_file_1.coreTool; } });
16
18
  const write_file_1 = require("./write-file");
@@ -24,6 +26,7 @@ exports.CORE_TOOLS = Object.freeze([
24
26
  write_file_1.coreTool,
25
27
  list_files_1.coreTool,
26
28
  exec_command_1.coreTool,
29
+ process_session_1.coreTool,
27
30
  edit_file_1.coreTool,
28
31
  glob_1.coreTool,
29
32
  grep_1.coreTool,
@@ -0,0 +1,2 @@
1
+ export declare const coreTool: import("../../framework/tool").OrionCodeTool;
2
+ //# sourceMappingURL=process-session.d.ts.map
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.coreTool = void 0;
4
+ const tool_1 = require("../../framework/tool");
5
+ const descriptors_1 = require("../../runtime/core-tools/descriptors");
6
+ const shell_process_sessions_1 = require("../../runtime/shell-process-sessions");
7
+ const common_1 = require("./common");
8
+ const descriptor = (0, descriptors_1.coreToolDescriptorV1)('process_session');
9
+ exports.coreTool = (0, tool_1.buildTool)({
10
+ name: descriptor.name,
11
+ aliases: [...descriptor.aliases],
12
+ description: descriptor.description,
13
+ parameters: structuredClone(descriptor.parameters),
14
+ async execute(args, context) {
15
+ const { action, input, processId, yieldMs } = args;
16
+ if (!context.shellProcesses) {
17
+ return {
18
+ success: false,
19
+ output: '',
20
+ error: 'Process sessions require an active runtime turn.',
21
+ };
22
+ }
23
+ return context.shellProcesses.operate({
24
+ processId: processId,
25
+ action: action,
26
+ input: input,
27
+ projectRoot: context.cwd,
28
+ yieldMs: yieldMs ?? shell_process_sessions_1.DEFAULT_PROCESS_YIELD_MS,
29
+ signal: context.abortSignal,
30
+ });
31
+ },
32
+ validateInput(args) {
33
+ if (typeof args.processId !== 'string' || !args.processId.trim()) {
34
+ return 'process_session requires a processId';
35
+ }
36
+ if (args.action !== 'poll' && args.action !== 'write' && args.action !== 'cancel') {
37
+ return 'process_session action must be poll, write, or cancel';
38
+ }
39
+ if (args.action === 'write') {
40
+ if (typeof args.input !== 'string' ||
41
+ Buffer.byteLength(args.input, 'utf8') > shell_process_sessions_1.MAX_PROCESS_INPUT_BYTES) {
42
+ return `process_session write requires input of at most ${shell_process_sessions_1.MAX_PROCESS_INPUT_BYTES} UTF-8 bytes`;
43
+ }
44
+ }
45
+ else if (args.input !== undefined) {
46
+ return 'process_session input is only valid for write';
47
+ }
48
+ return (0, common_1.validateOptionalSafeInteger)(args, 'process_session', 'yieldMs', 0, shell_process_sessions_1.MAX_PROCESS_YIELD_MS);
49
+ },
50
+ isReadOnly: () => false,
51
+ isConcurrencySafe: () => false,
52
+ userFacingName: args => `Process ${String(args.action)}`,
53
+ });
54
+ //# sourceMappingURL=process-session.js.map
@@ -21,15 +21,13 @@ const TODO_PROMPT = `Use this tool to create and manage a structured task list f
21
21
 
22
22
  ## When to Use This Tool
23
23
 
24
- If the task context requires a checklist, create it before changing the workspace. Name the exact target paths in the implementation steps and include verification.
24
+ For multi-step work, a checklist can track implementation paths and planned checks.
25
25
 
26
26
  1. Complex multi-step tasks - When a task requires 3 or more distinct steps
27
27
  2. Non-trivial tasks - Tasks that require careful planning or multiple operations
28
28
  3. User explicitly requests todo list
29
29
  4. User provides multiple tasks (numbered or comma-separated)
30
30
  5. After receiving new instructions - Immediately capture user requirements
31
- 6. When you start working on a task - Mark it as in_progress BEFORE beginning
32
- 7. After completing a task - Mark it completed immediately
33
31
 
34
32
  ## When NOT to Use
35
33
 
@@ -41,7 +39,7 @@ If the task context requires a checklist, create it before changing the workspac
41
39
 
42
40
  - pending: Task not yet started
43
41
  - in_progress: Currently working on (limit to ONE task at a time)
44
- - completed: Task finished successfully
42
+ - completed: You consider this step finished. Verification evidence is tracked separately.
45
43
 
46
44
  ## Task Format
47
45
 
@@ -50,16 +48,14 @@ Each todo must have:
50
48
  - activeForm: Present continuous form ("Running tests")
51
49
  - status: pending | in_progress | completed
52
50
 
53
- For verification steps, also include verification with the required check kinds (${verification_command_1.LOCAL_VERIFICATION_KINDS.join(', ')}).
51
+ For verification steps, you can include expected check kinds (${verification_command_1.LOCAL_VERIFICATION_KINDS.join(', ')}).
54
52
 
55
53
  ## Rules
56
54
 
57
55
  - Keep at most ONE task in_progress at a time
58
- - Mark tasks complete IMMEDIATELY after finishing
59
- - Keep descriptions stable. To clarify an unfinished step, replace its bare filename with the exact workspace-relative path.
60
- - Only mark a step completed after running its work and checks while it is in progress.
61
- - An implementation step with verification requires both a file change and a passing check.
62
- - Run each verification command directly with exec_command and use its cwd argument for the project directory. If a check fails, retry that check successfully before completing the step.`;
56
+ - Keep descriptions stable when possible so evidence can stay linked to the same step.
57
+ - An update can succeed while verification is missing. Report any unverified work in your answer.
58
+ - Use tool results and the user's instructions to decide whether to verify, change approach, ask, or finish. Repeating an unchanged checklist update does not add evidence.`;
63
59
  exports.MAX_TODOS = 8;
64
60
  exports.MAX_TODO_TEXT = 120;
65
61
  function createTodoWriteTool(save) {
@@ -73,7 +69,7 @@ ${TODO_PROMPT}`,
73
69
  properties: {
74
70
  blockedReason: {
75
71
  type: 'string',
76
- description: 'Report a concrete blocker and finish the current turn with the active step open.',
72
+ description: 'Record a concrete blocker on the active step.',
77
73
  },
78
74
  todos: {
79
75
  type: 'array',
@@ -87,7 +83,7 @@ ${TODO_PROMPT}`,
87
83
  activeForm: { type: 'string', description: 'Step in present continuous form.' },
88
84
  verification: {
89
85
  type: 'array',
90
- description: 'Check kinds that must pass before completing this step.',
86
+ description: 'Expected verification kinds for this step.',
91
87
  minItems: 1,
92
88
  maxItems: verification_command_1.LOCAL_VERIFICATION_KINDS.length,
93
89
  items: { type: 'string', enum: [...verification_command_1.LOCAL_VERIFICATION_KINDS] },
@@ -177,7 +173,7 @@ ${TODO_PROMPT}`,
177
173
  return {
178
174
  success: true,
179
175
  output,
180
- summary: `${completed}/${applied.length} complete${current ? ` · ${current.activeForm}` : ''}`,
176
+ summary: `${completed}/${applied.length} marked complete${current ? ` · ${current.activeForm}` : ''}`,
181
177
  metadata: { taskTodos: applied },
182
178
  };
183
179
  },