@orion-agents/orion-code 0.4.8 → 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 (120) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +5 -5
  3. package/README.zh-CN.md +5 -5
  4. package/dist/cli.js +42 -3
  5. package/dist/commands/session-command-handlers.js +8 -3
  6. package/dist/commands/system-commands.js +3 -3
  7. package/dist/commands/types.d.ts +3 -0
  8. package/dist/framework/loop-progress.js +3 -1
  9. package/dist/framework/query.d.ts +3 -1
  10. package/dist/framework/query.js +18 -3
  11. package/dist/framework/tool-serializer.d.ts +12 -0
  12. package/dist/framework/tool-serializer.js +35 -0
  13. package/dist/framework/tool.d.ts +2 -0
  14. package/dist/harness/ledger.js +2 -1
  15. package/dist/print-ui/delivery.d.ts +15 -0
  16. package/dist/print-ui/delivery.js +131 -0
  17. package/dist/print-ui/event-stream.d.ts +6 -1
  18. package/dist/print-ui/event-stream.js +56 -10
  19. package/dist/print-ui/launch.d.ts +5 -0
  20. package/dist/print-ui/launch.js +66 -9
  21. package/dist/runtime/agent-loop.d.ts +3 -1
  22. package/dist/runtime/agent-loop.js +20 -8
  23. package/dist/runtime/agent-runtime-controller.d.ts +4 -1
  24. package/dist/runtime/agent-runtime-controller.js +36 -22
  25. package/dist/runtime/agent-runtime-runner.d.ts +4 -0
  26. package/dist/runtime/agent-runtime-runner.js +9 -0
  27. package/dist/runtime/builtin-tool-provider.js +6 -5
  28. package/dist/runtime/composer/layout.d.ts +1 -1
  29. package/dist/runtime/composer/layout.js +5 -5
  30. package/dist/runtime/core-tools/descriptors.d.ts +1 -1
  31. package/dist/runtime/core-tools/descriptors.js +39 -1
  32. package/dist/runtime/first-party-core-provider.js +1 -0
  33. package/dist/runtime/first-party-tool-services.js +10 -0
  34. package/dist/runtime/goals/evidence.js +2 -0
  35. package/dist/runtime/legacy-thread-materializer.d.ts +7 -0
  36. package/dist/runtime/legacy-thread-materializer.js +32 -6
  37. package/dist/runtime/orion-runtime-v1.d.ts +2 -1
  38. package/dist/runtime/orion-runtime-v1.js +1 -0
  39. package/dist/runtime/product-bootstrap.d.ts +2 -0
  40. package/dist/runtime/product-bootstrap.js +1 -0
  41. package/dist/runtime/product-orion-runtime.d.ts +2 -1
  42. package/dist/runtime/product-orion-runtime.js +1 -0
  43. package/dist/runtime/rich-text/layout.d.ts +3 -1
  44. package/dist/runtime/rich-text/layout.js +37 -22
  45. package/dist/runtime/shell-process-sessions.d.ts +41 -0
  46. package/dist/runtime/shell-process-sessions.js +258 -0
  47. package/dist/runtime/step-snapshot.js +4 -1
  48. package/dist/runtime/subagents/presets.d.ts +1 -1
  49. package/dist/runtime/subagents/presets.js +1 -0
  50. package/dist/runtime/task-context-recovery.js +7 -0
  51. package/dist/runtime/thread-event-store.d.ts +3 -0
  52. package/dist/runtime/thread-event-store.js +35 -22
  53. package/dist/runtime/thread-session-index.d.ts +15 -3
  54. package/dist/runtime/thread-session-index.js +152 -45
  55. package/dist/runtime/thread-session-view.js +1 -1
  56. package/dist/runtime/thread-ui-adapter.d.ts +1 -1
  57. package/dist/runtime/thread-ui-adapter.js +14 -8
  58. package/dist/runtime/tool-gateway.d.ts +1 -0
  59. package/dist/runtime/tool-gateway.js +1 -0
  60. package/dist/runtime/tool-transcript-entry.d.ts +8 -1
  61. package/dist/runtime/tool-transcript-entry.js +35 -7
  62. package/dist/runtime/ui-events.d.ts +7 -0
  63. package/dist/services/global-config.d.ts +1 -1
  64. package/dist/services/global-config.js +2 -0
  65. package/dist/services/llm.d.ts +3 -0
  66. package/dist/services/llm.js +48 -4
  67. package/dist/terminal-ui/raw-editor.js +2 -1
  68. package/dist/tools/core/exec-command.js +51 -42
  69. package/dist/tools/core/index.d.ts +2 -1
  70. package/dist/tools/core/index.js +4 -1
  71. package/dist/tools/core/process-session.d.ts +2 -0
  72. package/dist/tools/core/process-session.js +54 -0
  73. package/dist/tui-core/frame.d.ts +2 -0
  74. package/dist/tui-core/frame.js +19 -0
  75. package/dist/tui-core/input-parser.d.ts +4 -1
  76. package/dist/tui-core/input-parser.js +22 -0
  77. package/dist/tui-ui/chrome-view-model.d.ts +0 -2
  78. package/dist/tui-ui/chrome-view-model.js +54 -56
  79. package/dist/tui-ui/launch.js +133 -202
  80. package/dist/tui-ui/layout.d.ts +16 -41
  81. package/dist/tui-ui/layout.js +408 -295
  82. package/dist/tui-ui/render-scheduler.d.ts +2 -5
  83. package/dist/tui-ui/render-scheduler.js +10 -10
  84. package/dist/tui-ui/response-clipboard.d.ts +17 -0
  85. package/dist/tui-ui/response-clipboard.js +201 -0
  86. package/dist/tui-ui/runner.d.ts +65 -80
  87. package/dist/tui-ui/runner.js +545 -738
  88. package/dist/tui-ui/session-picker-preview.d.ts +8 -0
  89. package/dist/tui-ui/session-picker-preview.js +119 -0
  90. package/dist/tui-ui/session-picker.d.ts +20 -0
  91. package/dist/tui-ui/session-picker.js +42 -0
  92. package/dist/tui-ui/state.d.ts +34 -81
  93. package/dist/tui-ui/state.js +155 -288
  94. package/dist/tui-ui/terminal-image.d.ts +3 -7
  95. package/dist/tui-ui/terminal-image.js +18 -47
  96. package/dist/tui-ui/terminal-viewport.d.ts +55 -0
  97. package/dist/tui-ui/terminal-viewport.js +221 -0
  98. package/dist/tui-ui/transcript-layout.d.ts +5 -0
  99. package/dist/tui-ui/transcript-layout.js +43 -28
  100. package/dist/tui-ui/transcript-pager.d.ts +39 -0
  101. package/dist/tui-ui/transcript-pager.js +278 -0
  102. package/dist/tui-ui/transcript-tool-output.d.ts +16 -0
  103. package/dist/tui-ui/transcript-tool-output.js +102 -0
  104. package/dist/utils/bounded-file.d.ts +4 -0
  105. package/dist/utils/bounded-file.js +30 -0
  106. package/dist/utils/command-process.d.ts +4 -0
  107. package/dist/utils/command-process.js +23 -0
  108. package/docs/cli-guide.md +50 -6
  109. package/npm-shrinkwrap.json +115 -15
  110. package/package.json +4 -1
  111. package/dist/tui-ui/inline-surface.d.ts +0 -191
  112. package/dist/tui-ui/inline-surface.js +0 -644
  113. package/dist/tui-ui/input-ownership.d.ts +0 -46
  114. package/dist/tui-ui/input-ownership.js +0 -74
  115. package/dist/tui-ui/transcript-inspector-layout.d.ts +0 -9
  116. package/dist/tui-ui/transcript-inspector-layout.js +0 -107
  117. package/dist/tui-ui/transcript-inspector-surface.d.ts +0 -18
  118. package/dist/tui-ui/transcript-inspector-surface.js +0 -91
  119. package/dist/tui-ui/transcript-inspector.d.ts +0 -36
  120. package/dist/tui-ui/transcript-inspector.js +0 -129
@@ -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
@@ -24,6 +24,8 @@ export declare function createTuiFrame(width: number, height: number): TuiFrame;
24
24
  export declare function writeFrameText(frame: TuiFrame, row: number, column: number, text: string, style?: TuiStyle): void;
25
25
  export declare function setFrameCursor(frame: TuiFrame, row: number, column: number, visible?: boolean): void;
26
26
  export declare function renderFrameRows(frame: TuiFrame): string[];
27
+ /** Match printed cells. A uniform background suffix can be painted with erase-to-line-end. */
28
+ export declare function trimFrameRow(row: TuiCell[]): TuiCell[];
27
29
  export declare function diffTuiFrames(previous: TuiFrame | null, next: TuiFrame): TuiFrameDiff;
28
30
  /**
29
31
  * Render a single frame row into styled spans by merging consecutive cells
@@ -7,6 +7,7 @@ exports.createTuiFrame = createTuiFrame;
7
7
  exports.writeFrameText = writeFrameText;
8
8
  exports.setFrameCursor = setFrameCursor;
9
9
  exports.renderFrameRows = renderFrameRows;
10
+ exports.trimFrameRow = trimFrameRow;
10
11
  exports.diffTuiFrames = diffTuiFrames;
11
12
  exports.renderStyledFrameRow = renderStyledFrameRow;
12
13
  const string_width_1 = __importDefault(require("string-width"));
@@ -60,6 +61,24 @@ function setFrameCursor(frame, row, column, visible = true) {
60
61
  function renderFrameRows(frame) {
61
62
  return frame.rows.map(row => row.map(cell => (cell.width === 0 ? '' : cell.char)).join(''));
62
63
  }
64
+ /** Match printed cells. A uniform background suffix can be painted with erase-to-line-end. */
65
+ function trimFrameRow(row) {
66
+ const last = row.at(-1);
67
+ if (!last || last.char !== ' ')
68
+ return row;
69
+ const suffixKey = (0, style_1.styleKey)(last.style);
70
+ const backgroundKey = (0, style_1.styleKey)({ background: last.style.background });
71
+ if (suffixKey !== backgroundKey)
72
+ return row;
73
+ let end = row.length;
74
+ while (end > 0) {
75
+ const cell = row[end - 1];
76
+ if (cell.char !== ' ' || (0, style_1.styleKey)(cell.style) !== suffixKey)
77
+ break;
78
+ end -= 1;
79
+ }
80
+ return row.slice(0, end);
81
+ }
63
82
  function diffTuiFrames(previous, next) {
64
83
  if (!previous || previous.width !== next.width || previous.height !== next.height) {
65
84
  return {
@@ -4,12 +4,15 @@ export type TuiInputEvent = {
4
4
  } | {
5
5
  type: 'paste';
6
6
  value: string;
7
+ } | {
8
+ type: 'wheel';
9
+ direction: -1 | 1;
7
10
  } | {
8
11
  type: 'key';
9
12
  key: TuiKey;
10
13
  raw: string;
11
14
  };
12
- export type TuiKey = 'enter' | 'tab' | 'shift+tab' | 'escape' | 'backspace' | 'delete' | 'ctrl+c' | 'ctrl+u' | 'ctrl+w' | 'ctrl+l' | 'ctrl+o' | 'ctrl+r' | 'ctrl+e' | 'ctrl+d' | 'newline' | 'left' | 'right' | 'up' | 'down' | 'home' | 'end' | 'pageup' | 'pagedown';
15
+ export type TuiKey = 'enter' | 'tab' | 'shift+tab' | 'escape' | 'backspace' | 'delete' | 'ctrl+b' | 'ctrl+c' | 'ctrl+u' | 'ctrl+w' | 'ctrl+l' | 'ctrl+o' | 'ctrl+r' | 'ctrl+t' | 'ctrl+e' | 'ctrl+f' | 'ctrl+d' | 'newline' | 'left' | 'right' | 'up' | 'alt+up' | 'down' | 'home' | 'end' | 'pageup' | 'pagedown';
13
16
  export interface TuiInputParserState {
14
17
  mode: 'normal' | 'paste';
15
18
  incompleteUtf8: Buffer;
@@ -14,6 +14,7 @@ const PASTE_END = '\x1b[201~';
14
14
  const CSI_KEYS = {
15
15
  '\x1b[Z': 'shift+tab',
16
16
  '\x1b[A': 'up',
17
+ '\x1b[1;3A': 'alt+up',
17
18
  '\x1b[B': 'down',
18
19
  '\x1b[C': 'right',
19
20
  '\x1b[D': 'left',
@@ -118,6 +119,18 @@ class TuiInputParser {
118
119
  index += PASTE_END.length;
119
120
  continue;
120
121
  }
122
+ const mouse = /^\x1b\[<(\d{1,5});\d{1,5};\d{1,5}([Mm])/u.exec(slice);
123
+ if (mouse) {
124
+ const button = Number(mouse[1]) & ~28; // Ignore Shift, Alt and Ctrl modifier bits.
125
+ if (this.state.mode === 'paste') {
126
+ this.state.pasteBuffer += mouse[0];
127
+ }
128
+ else if (mouse[2] === 'M' && (button === 64 || button === 65)) {
129
+ events.push({ type: 'wheel', direction: button === 64 ? -1 : 1 });
130
+ }
131
+ index += mouse[0].length;
132
+ continue;
133
+ }
121
134
  const csiKey = readCsiKey(slice);
122
135
  if (csiKey) {
123
136
  if (this.state.mode === 'paste') {
@@ -182,6 +195,9 @@ exports.TuiInputParser = TuiInputParser;
182
195
  function readIncompleteEscapePrefix(value) {
183
196
  if (!value.startsWith('\x1b'))
184
197
  return null;
198
+ // Mouse reports may be split across input chunks, like bracketed paste and CSI keys.
199
+ if (/^\x1b\[<(?:\d{1,5};){0,2}\d{0,5}$/u.test(value))
200
+ return value;
185
201
  const knownSequences = [PASTE_START, PASTE_END, ...Object.keys(CSI_KEYS)];
186
202
  return knownSequences.some(sequence => sequence.startsWith(value)) ? value : null;
187
203
  }
@@ -203,6 +219,10 @@ function controlKeyFromChar(char) {
203
219
  case '\x7f':
204
220
  case '\b':
205
221
  return 'backspace';
222
+ case '\x02':
223
+ return 'ctrl+b';
224
+ case '\x06':
225
+ return 'ctrl+f';
206
226
  case '\x03':
207
227
  return 'ctrl+c';
208
228
  case '\x15':
@@ -215,6 +235,8 @@ function controlKeyFromChar(char) {
215
235
  return 'ctrl+o';
216
236
  case '\x12':
217
237
  return 'ctrl+r';
238
+ case '\x14':
239
+ return 'ctrl+t';
218
240
  case '\x05':
219
241
  return 'ctrl+e';
220
242
  case '\x04':
@@ -11,9 +11,7 @@ export interface TuiChromeSegment {
11
11
  export interface TuiChromeViewModel {
12
12
  phase: 'ready' | 'working' | 'waiting' | 'error' | 'paused';
13
13
  pose: PixelHunterPose;
14
- promptMode: 'normal' | 'plan' | 'auto' | 'goal';
15
14
  segments: TuiChromeSegment[];
16
- hint: string;
17
15
  }
18
16
  export declare function createTuiChromeViewModel(state: TuiUiState, requested?: readonly TuiStatusItem[]): TuiChromeViewModel;
19
17
  //# sourceMappingURL=chrome-view-model.d.ts.map
@@ -11,6 +11,14 @@ const DEFAULT_ITEMS = [
11
11
  'queue',
12
12
  'activity',
13
13
  ];
14
+ const MODE_LABELS = { interactive: 'BUILD', plan: 'PLAN', auto: 'AUTO' };
15
+ // Exact presentation formats from statusSnapshotString and the runtime status emitters.
16
+ // Messages with additional user-facing text stay available as notices.
17
+ const SNAPSHOT_STATUS = /^model=(\S+)(?:\s+(?:ctx=\d+%(?: (?:auto-compact|\/compact))?|session=\S+|tokens=\S+))*$/u;
18
+ const SNAPSHOT_CONTEXT = /(?:^|\s)(ctx=\d+%(?: (?:auto-compact|\/compact))?)(?:\s|$)/u;
19
+ const RUNNER_STATUS = /^(?:Ready|Running(?: · (?:BUILD|PLAN|AUTO|INTERACTIVE))?|Working(?:: (?:thinking|reading tool results|running (?:tool|\d+ tools)))?|Waiting: permission required for \S+)$/u;
20
+ const GOAL_DECISION_NOTICE = /^Goal (?:(?:evidence|audit) (?:passed|failed)|complete)\b/u;
21
+ const GOAL_ACTION_NOTICE = /^Goal (?:paused|blocked|budget_limited|usage_limited)\b/u;
14
22
  function createTuiChromeViewModel(state, requested = DEFAULT_ITEMS) {
15
23
  const waiting = state.overlay?.type === 'permission';
16
24
  const errored = state.statusState.phase === 'error';
@@ -38,14 +46,9 @@ function createTuiChromeViewModel(state, requested = DEFAULT_ITEMS) {
38
46
  ? 'success'
39
47
  : 'ready';
40
48
  const all = new Map();
41
- const baseModeLabel = state.agentMode.baseMode === 'interactive' ? 'BUILD' : state.agentMode.baseMode.toUpperCase();
42
- const pendingModeLabel = state.agentMode.pendingBaseMode
43
- ? state.agentMode.pendingBaseMode === 'interactive'
44
- ? 'BUILD'
45
- : state.agentMode.pendingBaseMode.toUpperCase()
46
- : null;
49
+ const status = state.statusMessage.trim();
50
+ const snapshotStatus = SNAPSHOT_STATUS.exec(status);
47
51
  const goalMode = state.goal?.status === 'active';
48
- const modeLabel = `${goalMode ? `GOAL · ${baseModeLabel}` : baseModeLabel}${pendingModeLabel ? ` → ${pendingModeLabel} NEXT` : ''}`;
49
52
  const baseTone = state.agentMode.baseMode === 'plan'
50
53
  ? 'mode-plan'
51
54
  : state.agentMode.baseMode === 'auto'
@@ -53,7 +56,7 @@ function createTuiChromeViewModel(state, requested = DEFAULT_ITEMS) {
53
56
  : 'mode-build';
54
57
  all.set('mode', {
55
58
  id: 'mode',
56
- label: modeLabel,
59
+ label: MODE_LABELS[state.agentMode.baseMode],
57
60
  priority: Number.MAX_SAFE_INTEGER,
58
61
  tone: goalMode ? 'mode-goal' : baseTone,
59
62
  });
@@ -71,13 +74,18 @@ function createTuiChromeViewModel(state, requested = DEFAULT_ITEMS) {
71
74
  const time = timeLimit === undefined
72
75
  ? ''
73
76
  : ` time:${Math.floor(state.goal.timeUsedMs / 1000)}/${timeLimit / 1000}s`;
74
- const statusShowsAudit = state.statusMessage.startsWith('Goal audit failed (');
77
+ const statusShowsAudit = status.startsWith('Goal audit failed (');
75
78
  const audit = !statusShowsAudit && state.goal.auditRemaining?.[0]
76
79
  ? ` audit:${state.goal.auditRemaining[0]}`
77
80
  : '';
78
- const next = state.goal.nextAction && !state.statusMessage.includes(state.goal.nextAction)
81
+ const next = state.goal.nextAction && !status.includes(state.goal.nextAction)
79
82
  ? ` next:${state.goal.nextAction}`
80
83
  : '';
84
+ const reason = state.goal.status !== 'complete' &&
85
+ state.goal.stopReason &&
86
+ !status.includes(state.goal.stopReason)
87
+ ? ` reason:${state.goal.stopReason}`
88
+ : '';
81
89
  const actions = budgetLimited
82
90
  ? ' /goal budget'
83
91
  : ['paused', 'blocked', 'usage_limited'].includes(state.goal.status)
@@ -89,38 +97,38 @@ function createTuiChromeViewModel(state, requested = DEFAULT_ITEMS) {
89
97
  // Usage is the durable progress signal operators need most. Keep it at
90
98
  // the left edge so objective/plan text can be clipped on narrow frames
91
99
  // without hiding how much this Goal has consumed.
92
- label: `${progressLabel}${objective}${plan}${audit}${next}`,
100
+ label: `${progressLabel}${objective}${plan}${audit}${next}${reason}`,
93
101
  compactLabel: progressLabel,
94
102
  priority: 115,
95
103
  });
96
104
  }
97
105
  const snapshot = state.statusState.snapshot;
98
- const modelStatus = snapshot?.model
99
- ? `model=${snapshot.model}`
100
- : state.statusMessage.match(/\bmodel=[^\s]+/u)
101
- ? state.statusMessage
102
- : undefined;
103
- if (modelStatus) {
106
+ const model = snapshot?.model || snapshotStatus?.[1];
107
+ if (model) {
104
108
  all.set('model', {
105
109
  id: 'model',
106
- label: modelStatus,
110
+ label: model,
107
111
  priority: 105,
108
112
  });
109
113
  }
110
114
  if (state.effort) {
111
- const value = 'effective' in state.effort ? (state.effort.effective ?? 'auto') : 'off';
112
- all.set('effort', { id: 'effort', label: `EFFORT ${value}`, priority: 35 });
115
+ const value = state.effort.type === 'effort_unavailable' ? 'off' : (state.effort.effective ?? 'auto');
116
+ all.set('effort', {
117
+ id: 'effort',
118
+ label: `effort ${value}`,
119
+ compactLabel: value,
120
+ priority: 35,
121
+ });
113
122
  }
114
- const contextMeter = (0, ui_view_model_1.contextUsageStatusText)(snapshot?.context);
123
+ const contextMeter = (0, ui_view_model_1.contextUsageStatusText)(snapshot?.context) ||
124
+ (snapshotStatus ? (SNAPSHOT_CONTEXT.exec(status)?.[1] ?? '') : '');
115
125
  const background = (0, ui_view_model_1.backgroundCompactStatusText)(snapshot?.backgroundCompact);
116
126
  const context = [contextMeter, background].filter(Boolean).join(' ');
117
127
  if (context) {
118
128
  all.set('context', {
119
129
  id: 'context',
120
130
  label: context.toUpperCase(),
121
- compactLabel: (background || contextMeter.split(' ')[0])
122
- .replace(/ history$/u, '')
123
- .toUpperCase(),
131
+ compactLabel: (background || contextMeter.split(' ')[0]).toUpperCase(),
124
132
  priority: background ? 130 : 107,
125
133
  });
126
134
  }
@@ -132,48 +140,38 @@ function createTuiChromeViewModel(state, requested = DEFAULT_ITEMS) {
132
140
  priority: 125,
133
141
  });
134
142
  }
135
- const active = state.statusState.activeTools + state.statusState.activeSubtasks;
136
- const statusDuplicatesGoal = Boolean(state.goal &&
137
- (state.statusMessage.startsWith('Goal restored ') ||
138
- (state.goal.status !== 'complete' &&
139
- state.statusMessage.startsWith(`Goal ${state.goal.status}:`))));
140
- const researchStatus = state.research ? (0, ui_view_model_1.researchProjectionLabel)(state.research) : '';
141
- const working = active > 0 ? `Tools ${active}` : state.processing ? 'Working' : '';
142
- const attention = errored ? 'Error' : waiting ? 'Approval' : working;
143
- const message = !statusDuplicatesGoal && !state.statusMessage.startsWith(modelStatus ?? '\0') && !researchStatus
144
- ? state.statusMessage
145
- : '';
146
- const activityParts = [attention, researchStatus, message].filter(Boolean);
147
- if (activityParts.length > 0) {
148
- const lifecycleDecision = state.statusMessage.startsWith('Goal complete:') ||
149
- /^Goal (?:evidence|audit) (?:passed|failed)/u.test(state.statusMessage);
150
- const compactDecision = /^Goal (?:(?:evidence|audit) (?:passed|failed)|complete)/u.exec(state.statusMessage)?.[0];
143
+ const goal = state.goal;
144
+ const statusDuplicatesGoal = goal &&
145
+ (status === `Goal restored ${goal.status}: ${goal.objective}` ||
146
+ (goal.status === 'active' && status === `Goal active: ${goal.objective}`));
147
+ const message = snapshotStatus || statusDuplicatesGoal || RUNNER_STATUS.test(status) ? '' : status;
148
+ const lastResearchEvent = state.researchEvents.at(-1);
149
+ const research = state.research;
150
+ const notice = research &&
151
+ (!message ||
152
+ (lastResearchEvent && message === (0, ui_view_model_1.formatResearchLifecycleEvent)(lastResearchEvent, 'tui')))
153
+ ? (0, ui_view_model_1.researchProjectionLabel)(research)
154
+ : message;
155
+ const pendingMode = state.agentMode.pendingBaseMode;
156
+ const pendingModeNotice = pendingMode ? `${MODE_LABELS[pendingMode]} next` : '';
157
+ if (notice || pendingModeNotice) {
158
+ const decision = GOAL_DECISION_NOTICE.exec(notice)?.[0];
159
+ const action = GOAL_ACTION_NOTICE.exec(notice)?.[0];
151
160
  all.set('activity', {
152
161
  id: 'activity',
153
- label: activityParts.join(' · '),
154
- compactLabel: compactDecision ?? (attention || undefined),
155
- // Evidence/audit decisions are state transitions, not decorative activity.
156
- // Keep them visible ahead of the model and Goal summary so operators and
157
- // PTY automation can observe the transition before the next tool prompt.
158
- priority: errored || waiting ? 140 : lifecycleDecision ? 120 : working ? 110 : 70,
162
+ label: [notice, pendingModeNotice].filter(Boolean).join(' · '),
163
+ compactLabel: decision ?? action ?? (pendingModeNotice || undefined),
164
+ // Keep evidence and audit decisions visible before the next tool prompt.
165
+ // Recovery actions in the Goal segment take priority over the stop reason.
166
+ priority: errored || waiting ? 140 : decision ? 120 : action || pendingMode ? 110 : 70,
159
167
  });
160
168
  }
161
169
  return {
162
170
  phase,
163
171
  pose,
164
- promptMode: state.goal
165
- ? 'goal'
166
- : state.agentMode.baseMode === 'plan'
167
- ? 'plan'
168
- : state.agentMode.baseMode === 'auto'
169
- ? 'auto'
170
- : 'normal',
171
172
  segments: ['mode', ...requested.filter(id => id !== 'mode')]
172
173
  .map(id => all.get(id))
173
174
  .filter((item) => Boolean(item)),
174
- hint: state.processing
175
- ? 'Enter steer · Tab queue · Shift+Tab mode · Esc stop · ? help'
176
- : 'Enter send · Shift+Tab mode · / commands · @ files · ? help',
177
175
  };
178
176
  }
179
177
  function formatGoalTokenUsage(tokens) {