@orion-agents/orion-code 0.4.8 → 0.5.0

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 (124) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +5 -5
  3. package/README.zh-CN.md +5 -5
  4. package/dist/acp/sessions.js +1 -1
  5. package/dist/acp/stdio.js +17 -2
  6. package/dist/cli.js +45 -4
  7. package/dist/commands/session-command-handlers.js +8 -3
  8. package/dist/commands/system-commands.js +3 -3
  9. package/dist/commands/types.d.ts +3 -0
  10. package/dist/framework/loop-progress.js +3 -1
  11. package/dist/framework/query.d.ts +3 -1
  12. package/dist/framework/query.js +18 -3
  13. package/dist/framework/tool-serializer.d.ts +12 -0
  14. package/dist/framework/tool-serializer.js +35 -0
  15. package/dist/framework/tool.d.ts +2 -0
  16. package/dist/harness/ledger.js +2 -1
  17. package/dist/print-ui/delivery.d.ts +15 -0
  18. package/dist/print-ui/delivery.js +131 -0
  19. package/dist/print-ui/event-stream.d.ts +6 -1
  20. package/dist/print-ui/event-stream.js +56 -10
  21. package/dist/print-ui/launch.d.ts +5 -0
  22. package/dist/print-ui/launch.js +66 -9
  23. package/dist/runtime/agent-loop.d.ts +3 -1
  24. package/dist/runtime/agent-loop.js +20 -8
  25. package/dist/runtime/agent-runtime-controller.d.ts +4 -1
  26. package/dist/runtime/agent-runtime-controller.js +36 -22
  27. package/dist/runtime/agent-runtime-runner.d.ts +4 -0
  28. package/dist/runtime/agent-runtime-runner.js +9 -0
  29. package/dist/runtime/builtin-tool-provider.js +6 -5
  30. package/dist/runtime/composer/layout.d.ts +1 -1
  31. package/dist/runtime/composer/layout.js +5 -5
  32. package/dist/runtime/core-tools/descriptors.d.ts +1 -1
  33. package/dist/runtime/core-tools/descriptors.js +39 -1
  34. package/dist/runtime/first-party-core-provider.js +1 -0
  35. package/dist/runtime/first-party-tool-services.js +10 -0
  36. package/dist/runtime/goals/evidence.js +2 -0
  37. package/dist/runtime/legacy-thread-materializer.d.ts +7 -0
  38. package/dist/runtime/legacy-thread-materializer.js +32 -6
  39. package/dist/runtime/orion-runtime-v1.d.ts +2 -1
  40. package/dist/runtime/orion-runtime-v1.js +1 -0
  41. package/dist/runtime/product-bootstrap.d.ts +2 -0
  42. package/dist/runtime/product-bootstrap.js +1 -0
  43. package/dist/runtime/product-orion-runtime.d.ts +2 -1
  44. package/dist/runtime/product-orion-runtime.js +1 -0
  45. package/dist/runtime/release-receipts.d.ts +0 -1
  46. package/dist/runtime/release-receipts.js +8 -3
  47. package/dist/runtime/rich-text/layout.d.ts +3 -1
  48. package/dist/runtime/rich-text/layout.js +37 -22
  49. package/dist/runtime/shell-process-sessions.d.ts +41 -0
  50. package/dist/runtime/shell-process-sessions.js +258 -0
  51. package/dist/runtime/step-snapshot.js +4 -1
  52. package/dist/runtime/subagents/presets.d.ts +1 -1
  53. package/dist/runtime/subagents/presets.js +1 -0
  54. package/dist/runtime/task-context-recovery.js +7 -0
  55. package/dist/runtime/thread-event-store.d.ts +3 -0
  56. package/dist/runtime/thread-event-store.js +35 -22
  57. package/dist/runtime/thread-session-index.d.ts +15 -3
  58. package/dist/runtime/thread-session-index.js +152 -45
  59. package/dist/runtime/thread-session-view.js +1 -1
  60. package/dist/runtime/thread-ui-adapter.d.ts +1 -1
  61. package/dist/runtime/thread-ui-adapter.js +14 -8
  62. package/dist/runtime/tool-gateway.d.ts +1 -0
  63. package/dist/runtime/tool-gateway.js +1 -0
  64. package/dist/runtime/tool-transcript-entry.d.ts +8 -1
  65. package/dist/runtime/tool-transcript-entry.js +35 -7
  66. package/dist/runtime/ui-events.d.ts +7 -0
  67. package/dist/services/global-config.d.ts +1 -1
  68. package/dist/services/global-config.js +2 -0
  69. package/dist/services/llm.d.ts +3 -0
  70. package/dist/services/llm.js +48 -4
  71. package/dist/terminal-ui/raw-editor.js +2 -1
  72. package/dist/tools/core/exec-command.js +51 -42
  73. package/dist/tools/core/index.d.ts +2 -1
  74. package/dist/tools/core/index.js +4 -1
  75. package/dist/tools/core/process-session.d.ts +2 -0
  76. package/dist/tools/core/process-session.js +54 -0
  77. package/dist/tui-core/frame.d.ts +2 -0
  78. package/dist/tui-core/frame.js +19 -0
  79. package/dist/tui-core/input-parser.d.ts +4 -1
  80. package/dist/tui-core/input-parser.js +22 -0
  81. package/dist/tui-ui/chrome-view-model.d.ts +0 -2
  82. package/dist/tui-ui/chrome-view-model.js +54 -56
  83. package/dist/tui-ui/launch.js +133 -202
  84. package/dist/tui-ui/layout.d.ts +16 -41
  85. package/dist/tui-ui/layout.js +408 -295
  86. package/dist/tui-ui/render-scheduler.d.ts +2 -5
  87. package/dist/tui-ui/render-scheduler.js +10 -10
  88. package/dist/tui-ui/response-clipboard.d.ts +17 -0
  89. package/dist/tui-ui/response-clipboard.js +201 -0
  90. package/dist/tui-ui/runner.d.ts +65 -80
  91. package/dist/tui-ui/runner.js +545 -738
  92. package/dist/tui-ui/session-picker-preview.d.ts +8 -0
  93. package/dist/tui-ui/session-picker-preview.js +119 -0
  94. package/dist/tui-ui/session-picker.d.ts +20 -0
  95. package/dist/tui-ui/session-picker.js +42 -0
  96. package/dist/tui-ui/state.d.ts +34 -81
  97. package/dist/tui-ui/state.js +155 -288
  98. package/dist/tui-ui/terminal-image.d.ts +3 -7
  99. package/dist/tui-ui/terminal-image.js +18 -47
  100. package/dist/tui-ui/terminal-viewport.d.ts +55 -0
  101. package/dist/tui-ui/terminal-viewport.js +221 -0
  102. package/dist/tui-ui/transcript-layout.d.ts +5 -0
  103. package/dist/tui-ui/transcript-layout.js +43 -28
  104. package/dist/tui-ui/transcript-pager.d.ts +39 -0
  105. package/dist/tui-ui/transcript-pager.js +278 -0
  106. package/dist/tui-ui/transcript-tool-output.d.ts +16 -0
  107. package/dist/tui-ui/transcript-tool-output.js +102 -0
  108. package/dist/utils/bounded-file.d.ts +4 -0
  109. package/dist/utils/bounded-file.js +30 -0
  110. package/dist/utils/command-process.d.ts +4 -0
  111. package/dist/utils/command-process.js +23 -0
  112. package/docs/cli-guide.md +50 -6
  113. package/npm-shrinkwrap.json +115 -15
  114. package/package.json +4 -1
  115. package/dist/tui-ui/inline-surface.d.ts +0 -191
  116. package/dist/tui-ui/inline-surface.js +0 -644
  117. package/dist/tui-ui/input-ownership.d.ts +0 -46
  118. package/dist/tui-ui/input-ownership.js +0 -74
  119. package/dist/tui-ui/transcript-inspector-layout.d.ts +0 -9
  120. package/dist/tui-ui/transcript-inspector-layout.js +0 -107
  121. package/dist/tui-ui/transcript-inspector-surface.d.ts +0 -18
  122. package/dist/tui-ui/transcript-inspector-surface.js +0 -91
  123. package/dist/tui-ui/transcript-inspector.d.ts +0 -36
  124. package/dist/tui-ui/transcript-inspector.js +0 -129
@@ -0,0 +1,278 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TranscriptPager = void 0;
4
+ const explorationTools = new Map([
5
+ ['read_file', 'reads'],
6
+ ['glob', 'searches'],
7
+ ['grep', 'searches'],
8
+ ['list_files', 'listings'],
9
+ ]);
10
+ function completedExploration(record) {
11
+ const activity = record?.toolActivity;
12
+ if (!record?.finalized ||
13
+ record.role !== 'tool' ||
14
+ record.errorLayer ||
15
+ activity?.state !== 'success' ||
16
+ !activity.turnId ||
17
+ activity.command ||
18
+ activity.error) {
19
+ return undefined;
20
+ }
21
+ const kind = explorationTools.get(activity.name);
22
+ return kind ? { kind, turnId: activity.turnId } : undefined;
23
+ }
24
+ /**
25
+ * An application-owned viewport into semantic history. Following the tail is
26
+ * explicit; while reading, the first visible row is anchored to its record.
27
+ */
28
+ class TranscriptPager {
29
+ constructor() {
30
+ this.anchor = null;
31
+ this.pendingRows = 0;
32
+ this.pageRows = 1;
33
+ }
34
+ get isFollowing() {
35
+ return this.anchor === null;
36
+ }
37
+ get nearStart() {
38
+ return this.earlierAnchor !== undefined;
39
+ }
40
+ /** Keep the visible passage when older records are about to be prepended. */
41
+ keepEarlierAnchor() {
42
+ if (this.earlierAnchor)
43
+ this.anchor = this.earlierAnchor;
44
+ }
45
+ reset() {
46
+ this.earlierAnchor = undefined;
47
+ this.last();
48
+ }
49
+ first() {
50
+ this.anchor = 'start';
51
+ this.pendingRows = 0;
52
+ }
53
+ last() {
54
+ this.anchor = null;
55
+ this.pendingRows = 0;
56
+ }
57
+ scroll(deltaRows) {
58
+ this.pendingRows += Math.trunc(deltaRows);
59
+ }
60
+ page(direction, overlap = 1) {
61
+ this.scroll(direction * Math.max(1, this.pageRows - overlap));
62
+ }
63
+ halfPage(direction) {
64
+ this.scroll(direction * Math.ceil(this.pageRows / 2));
65
+ }
66
+ rows(records, width, height, layout, options = {}) {
67
+ this.pageRows = height;
68
+ const delta = this.pendingRows;
69
+ this.pendingRows = 0;
70
+ this.earlierAnchor = undefined;
71
+ const history = new TranscriptRows(options.head ?? [], records, options.tail ?? [], width, layout, options.layoutExploration);
72
+ if (height <= 0 || history.length === 0)
73
+ return [];
74
+ const { onVisibleRecord } = options;
75
+ if (this.isFollowing && delta >= 0) {
76
+ const end = history.seek(history.length - 1, -1);
77
+ if (options.hasEarlier)
78
+ this.rememberEarlierAnchor(history, history.move(end, 1 - height));
79
+ return history.take(end, height, -1, onVisibleRecord).reverse();
80
+ }
81
+ const top = this.anchor === 'start'
82
+ ? history.seek(0, 1)
83
+ : this.anchor
84
+ ? history.resolve(this.anchor)
85
+ : history.move(history.seek(history.length - 1, -1), 1 - height);
86
+ const next = history.move(top, delta);
87
+ if (!top || !next)
88
+ return [];
89
+ const visible = history.take(next, height, 1, onVisibleRecord);
90
+ if (delta > 0) {
91
+ const end = history.move(next, visible.length - 1);
92
+ if (end && !history.hasNext(end)) {
93
+ this.last();
94
+ if (options.hasEarlier)
95
+ this.rememberEarlierAnchor(history, history.move(end, 1 - height));
96
+ return history.take(end, height, -1, onVisibleRecord).reverse();
97
+ }
98
+ }
99
+ if (options.hasEarlier)
100
+ this.rememberEarlierAnchor(history, next);
101
+ if (delta !== 0 && (top.index !== next.index || top.row !== next.row)) {
102
+ this.anchor = history.anchor(next);
103
+ }
104
+ else if (this.anchor && this.anchor !== 'start') {
105
+ const record = history.entry(top.index);
106
+ this.anchor =
107
+ record.id === this.anchor.id
108
+ ? { ...this.anchor, ...top, width, revision: record.revision }
109
+ : history.anchor(top);
110
+ }
111
+ return visible;
112
+ }
113
+ rememberEarlierAnchor(history, top) {
114
+ if (!top)
115
+ return;
116
+ const pageUp = history.move(top, -this.pageRows);
117
+ if (pageUp?.row === 0 && !history.seek(pageUp.index - 1, -1)) {
118
+ this.earlierAnchor = history.anchor(top);
119
+ }
120
+ }
121
+ }
122
+ exports.TranscriptPager = TranscriptPager;
123
+ /** A lazy row cursor. Only records reached by the viewport or scroll are laid out. */
124
+ class TranscriptRows {
125
+ constructor(head, records, tail, width, layout, layoutExploration) {
126
+ this.head = head;
127
+ this.records = records;
128
+ this.tail = tail;
129
+ this.width = width;
130
+ this.layout = layout;
131
+ this.layoutExploration = layoutExploration;
132
+ this.cache = new Map();
133
+ }
134
+ get length() {
135
+ return this.head.length + this.records.length + this.tail.length;
136
+ }
137
+ entry(index) {
138
+ if (index < this.head.length)
139
+ return this.head[index];
140
+ const offset = index - this.head.length;
141
+ return offset < this.records.length
142
+ ? this.records[offset]
143
+ : this.tail[offset - this.records.length];
144
+ }
145
+ seek(index, direction) {
146
+ for (let next = index; next >= 0 && next < this.length; next += direction) {
147
+ const count = this.at(next).length;
148
+ if (count)
149
+ return { index: next, row: direction === 1 ? 0 : count - 1 };
150
+ }
151
+ return undefined;
152
+ }
153
+ resolve(anchor) {
154
+ let index = anchor.index;
155
+ if (this.entry(index)?.id !== anchor.id) {
156
+ let offset = 0;
157
+ for (const records of [this.head, this.records, this.tail]) {
158
+ index = records.findIndex(record => record.id === anchor.id);
159
+ if (index >= 0) {
160
+ index += offset;
161
+ break;
162
+ }
163
+ offset += records.length;
164
+ }
165
+ }
166
+ if (index < 0) {
167
+ const neighbor = Math.min(anchor.index, this.length - 1);
168
+ return this.seek(neighbor, 1) ?? this.seek(neighbor, -1);
169
+ }
170
+ const rows = this.at(index);
171
+ if (!rows.length)
172
+ return this.seek(index - 1, -1) ?? this.seek(index + 1, 1);
173
+ if (anchor.width === this.width && anchor.revision === this.entry(index).revision) {
174
+ return { index, row: Math.min(anchor.row, rows.length - 1) };
175
+ }
176
+ // Retain a text offset through successive reflows and appended stream
177
+ // deltas. A space consumed by wrapping must not move the reading anchor.
178
+ let remaining = anchor.textOffset;
179
+ let row = 0;
180
+ while (row < rows.length - 1) {
181
+ const length = rowTextLength(rows[row]);
182
+ if (remaining < length)
183
+ break;
184
+ remaining -= length;
185
+ row += 1;
186
+ }
187
+ return { index, row };
188
+ }
189
+ anchor(position) {
190
+ const rows = this.at(position.index);
191
+ let textOffset = 0;
192
+ for (let row = 0; row < position.row; row += 1) {
193
+ textOffset += rowTextLength(rows[row]);
194
+ }
195
+ return {
196
+ ...position,
197
+ id: this.entry(position.index).id,
198
+ width: this.width,
199
+ revision: this.entry(position.index).revision,
200
+ textOffset,
201
+ };
202
+ }
203
+ move(start, delta) {
204
+ if (!start || delta === 0)
205
+ return start;
206
+ const direction = delta < 0 ? -1 : 1;
207
+ let remaining = Math.abs(delta);
208
+ let position = start;
209
+ while (remaining > 0) {
210
+ const { index, row } = position;
211
+ const edge = direction === -1 ? 0 : this.at(index).length - 1;
212
+ const available = Math.abs(edge - row);
213
+ if (remaining <= available)
214
+ return { index, row: row + remaining * direction };
215
+ const next = this.seek(index + direction, direction);
216
+ if (!next)
217
+ return { index, row: edge };
218
+ position = next;
219
+ remaining -= available + 1;
220
+ }
221
+ return position;
222
+ }
223
+ hasNext(position) {
224
+ return (position.row + 1 < this.at(position.index).length ||
225
+ this.seek(position.index + 1, 1) !== undefined);
226
+ }
227
+ take(start, count, direction, onVisibleRecord) {
228
+ const visible = [];
229
+ let position = start;
230
+ while (position && visible.length < count) {
231
+ const { index, row } = position;
232
+ const rows = this.at(index);
233
+ onVisibleRecord?.(this.entry(index));
234
+ for (let offset = row; offset >= 0 && offset < rows.length && visible.length < count; offset += direction) {
235
+ visible.push(rows[offset]);
236
+ }
237
+ if (visible.length < count)
238
+ position = this.seek(index + direction, direction);
239
+ }
240
+ return visible;
241
+ }
242
+ at(index) {
243
+ let rows = this.cache.get(index);
244
+ if (!rows) {
245
+ rows = this.explorationRows(index) ?? this.layout(this.entry(index), this.width);
246
+ this.cache.set(index, rows);
247
+ }
248
+ return rows;
249
+ }
250
+ /** Keep the first call as the visible anchor. Detail and replay still work on raw records. */
251
+ explorationRows(index) {
252
+ if (!this.layoutExploration)
253
+ return undefined;
254
+ const first = completedExploration(this.entry(index));
255
+ if (!first)
256
+ return undefined;
257
+ if (index > 0 && completedExploration(this.entry(index - 1))?.turnId === first.turnId) {
258
+ return [];
259
+ }
260
+ const counts = { reads: 0, searches: 0, listings: 0 };
261
+ counts[first.kind] = 1;
262
+ let end = index + 1;
263
+ for (; end < this.length; end += 1) {
264
+ const next = completedExploration(this.entry(end));
265
+ if (next?.turnId !== first.turnId)
266
+ break;
267
+ counts[next.kind] += 1;
268
+ }
269
+ return end > index + 1 ? this.layoutExploration(counts, this.width) : undefined;
270
+ }
271
+ }
272
+ function rowTextLength(row) {
273
+ return Math.max(1, row
274
+ .map(span => span.text)
275
+ .join('')
276
+ .replace(/\s/gu, '').length);
277
+ }
278
+ //# sourceMappingURL=transcript-pager.js.map
@@ -0,0 +1,16 @@
1
+ import type { ToolDetailRepository } from '../runtime/tool-detail-repository';
2
+ import type { TuiTranscriptRecord } from './state';
3
+ /** Lazily resolves safe tool output for the cells on the transcript page. */
4
+ export declare class TranscriptToolOutput {
5
+ private readonly repository;
6
+ private readonly cwd;
7
+ private readonly cache;
8
+ private generation;
9
+ private loading;
10
+ constructor(repository: ToolDetailRepository, cwd: string);
11
+ reset(): void;
12
+ get(entry: TuiTranscriptRecord): string | undefined;
13
+ observe(records: Iterable<TuiTranscriptRecord>, updated: () => void): void;
14
+ private read;
15
+ }
16
+ //# sourceMappingURL=transcript-tool-output.d.ts.map
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TranscriptToolOutput = void 0;
4
+ const redaction_1 = require("../services/redaction");
5
+ const style_1 = require("../tui-core/style");
6
+ const READ_BYTES = 64 * 1024;
7
+ const MAX_OUTPUT_BYTES = 1024 * 1024;
8
+ const PREVIEW_LINES = 50;
9
+ const MAX_CACHED_OUTPUTS = 32;
10
+ function artifactRef(entry) {
11
+ const tool = entry.toolActivity;
12
+ const detail = tool?.outputView?.detailRef;
13
+ const artifactId = tool?.artifactRef?.id ?? detail?.artifactId;
14
+ const callId = tool?.callId ?? detail?.callId;
15
+ if (!artifactId || !callId)
16
+ return undefined;
17
+ return {
18
+ artifactId,
19
+ callId,
20
+ sequence: tool?.seq ?? detail?.sequence ?? 0,
21
+ outputBytes: tool?.artifactRef?.outputBytes ?? detail?.outputBytes ?? 0,
22
+ };
23
+ }
24
+ /** Lazily resolves safe tool output for the cells on the transcript page. */
25
+ class TranscriptToolOutput {
26
+ constructor(repository, cwd) {
27
+ this.repository = repository;
28
+ this.cwd = cwd;
29
+ this.cache = new Map();
30
+ this.generation = 0;
31
+ this.loading = false;
32
+ }
33
+ reset() {
34
+ this.generation += 1;
35
+ this.loading = false;
36
+ this.cache.clear();
37
+ }
38
+ get(entry) {
39
+ const id = artifactRef(entry)?.artifactId;
40
+ return id ? this.cache.get(id) : undefined;
41
+ }
42
+ observe(records, updated) {
43
+ if (this.loading)
44
+ return;
45
+ const refs = new Map();
46
+ for (const record of records) {
47
+ const ref = artifactRef(record);
48
+ if (ref?.artifactId)
49
+ refs.set(ref.artifactId, ref);
50
+ }
51
+ const next = [...refs].find(([id]) => !this.cache.has(id));
52
+ if (!next)
53
+ return;
54
+ const [id, ref] = next;
55
+ const generation = this.generation;
56
+ this.loading = true;
57
+ void this.read(ref)
58
+ .catch(() => undefined)
59
+ .then(output => {
60
+ if (generation !== this.generation)
61
+ return;
62
+ this.loading = false;
63
+ this.cache.set(id, output);
64
+ // Keep current page entries stable while results arrive one by one.
65
+ for (const key of this.cache.keys()) {
66
+ if (this.cache.size <= MAX_CACHED_OUTPUTS)
67
+ break;
68
+ if (!refs.has(key))
69
+ this.cache.delete(key);
70
+ }
71
+ updated();
72
+ });
73
+ }
74
+ async read(ref) {
75
+ const readAt = (offsetBytes) => this.repository.read(ref, { offsetBytes, limitBytes: READ_BYTES }, this.cwd);
76
+ const first = await readAt(0);
77
+ // The repository uses a zero-length receipt when the safe artifact is missing.
78
+ if (first.totalBytes === 0)
79
+ return undefined;
80
+ if (first.totalBytes > MAX_OUTPUT_BYTES) {
81
+ const last = await readAt(Math.max(READ_BYTES, first.totalBytes - READ_BYTES));
82
+ const head = first.content.split('\n').slice(0, PREVIEW_LINES).join('\n');
83
+ const tail = last.content.trimEnd().split('\n').slice(-PREVIEW_LINES).join('\n');
84
+ return safeOutput([head, '… Tool output truncated …', tail].join('\n'));
85
+ }
86
+ const pages = [first.content];
87
+ let nextOffset = first.nextOffsetBytes;
88
+ while (nextOffset !== undefined && nextOffset < MAX_OUTPUT_BYTES) {
89
+ const page = await readAt(nextOffset);
90
+ pages.push(page.content);
91
+ if (page.nextOffsetBytes === undefined || page.nextOffsetBytes <= nextOffset)
92
+ break;
93
+ nextOffset = page.nextOffsetBytes;
94
+ }
95
+ return safeOutput(pages.join(''));
96
+ }
97
+ }
98
+ exports.TranscriptToolOutput = TranscriptToolOutput;
99
+ function safeOutput(text) {
100
+ return (0, redaction_1.redactTraceText)((0, style_1.sanitizeTerminalText)(text));
101
+ }
102
+ //# sourceMappingURL=transcript-tool-output.js.map
@@ -0,0 +1,4 @@
1
+ export declare const READ_REGULAR_FILE_FLAGS: number;
2
+ /** Read an existing regular file with a hard limit, including on concurrent growth. */
3
+ export declare function readBoundedRegularFileSync(path: string, maxBytes: number): Buffer | undefined;
4
+ //# sourceMappingURL=bounded-file.d.ts.map
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.READ_REGULAR_FILE_FLAGS = void 0;
4
+ exports.readBoundedRegularFileSync = readBoundedRegularFileSync;
5
+ const fs_1 = require("fs");
6
+ exports.READ_REGULAR_FILE_FLAGS = fs_1.constants.O_RDONLY | (fs_1.constants.O_NOFOLLOW ?? 0) | (fs_1.constants.O_NONBLOCK ?? 0);
7
+ /** Read an existing regular file with a hard limit, including on concurrent growth. */
8
+ function readBoundedRegularFileSync(path, maxBytes) {
9
+ let fd;
10
+ try {
11
+ fd = (0, fs_1.openSync)(path, exports.READ_REGULAR_FILE_FLAGS);
12
+ const stats = (0, fs_1.fstatSync)(fd);
13
+ if (!stats.isFile() || stats.size > maxBytes)
14
+ return undefined;
15
+ const buffer = Buffer.allocUnsafe(stats.size);
16
+ let offset = 0;
17
+ while (offset < buffer.length) {
18
+ const read = (0, fs_1.readSync)(fd, buffer, offset, buffer.length - offset, offset);
19
+ if (read === 0)
20
+ return undefined;
21
+ offset += read;
22
+ }
23
+ return buffer;
24
+ }
25
+ finally {
26
+ if (fd !== undefined)
27
+ (0, fs_1.closeSync)(fd);
28
+ }
29
+ }
30
+ //# sourceMappingURL=bounded-file.js.map
@@ -0,0 +1,4 @@
1
+ import { type ChildProcessWithoutNullStreams } from 'child_process';
2
+ export declare function spawnCommandProcess(file: string, args: string[], cwd: string): ChildProcessWithoutNullStreams;
3
+ export declare function signalCommandProcess(child: ChildProcessWithoutNullStreams, signal: NodeJS.Signals): boolean;
4
+ //# sourceMappingURL=command-process.d.ts.map
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.spawnCommandProcess = spawnCommandProcess;
4
+ exports.signalCommandProcess = signalCommandProcess;
5
+ const child_process_1 = require("child_process");
6
+ function spawnCommandProcess(file, args, cwd) {
7
+ return (0, child_process_1.spawn)(file, args, { cwd, detached: process.platform !== 'win32' });
8
+ }
9
+ function signalCommandProcess(child, signal) {
10
+ if (!child.pid)
11
+ return false;
12
+ if (process.platform !== 'win32') {
13
+ try {
14
+ process.kill(-child.pid, signal);
15
+ return true;
16
+ }
17
+ catch {
18
+ // A child that exits before its process group is established needs a direct signal.
19
+ }
20
+ }
21
+ return child.kill(signal);
22
+ }
23
+ //# sourceMappingURL=command-process.js.map
package/docs/cli-guide.md CHANGED
@@ -53,11 +53,29 @@ orion doctor
53
53
 
54
54
  ## TUI 命令与会话
55
55
 
56
- 从 v0.4.6 起,在输入框开头键入 `/` 可查看命令。候选根据命令名和别名筛选,并贴近输入框显示。
57
- 用方向键选中候选,Tab 补全命令名并保留已经输入的参数,Enter 执行。Esc 关闭候选并保留草稿。
56
+ 在输入框开头键入 `/` 查看命令,键入 `@` 选择文件。候选在输入框下方显示。
57
+ 用方向键选中候选,Tab 补全并保留已经输入的参数,Enter 执行命令。Esc 关闭候选并保留草稿。
58
58
  光标进入参数区后,可以继续编辑并直接提交。
59
59
 
60
- - `/new` 创建独立会话,`/resume` 可回到原会话。进行中的回合结束后即可切换。
60
+ Ctrl+T 打开或关闭完整会话历史。对话、Thinking 摘要及工具详情按时间顺序显示。
61
+ 用滚轮、方向键或 PgUp/PgDn 翻阅,Home/End 跳到最早/最新。回到最新位置后恢复跟随。
62
+ 恢复会话后,翻到已载记录的开头可继续加载较早记录。窗口缩放和新输出会保留当前阅读位置。TUI 退出时把当前会话最近最多 2,000 行已完成内容追加到终端的原生滚回区。
63
+
64
+ 在主对话按 Ctrl+O 将当前会话最近的已完成回复复制到剪贴板,保留原始 Markdown 格式。
65
+ 新回复仍在生成时,复制先前已完成的回复。恢复会话后可以复制该会话已有的回复。
66
+
67
+ 长草稿随终端宽度自动换行。↑/↓ 在可视行之间移动,行首尾仍沿用当前逻辑行。`?` 打开快捷键说明。
68
+ 运行信息位于输入框上方,显示执行阶段、中断键和可容纳的工具详情。模式、模型和上下文显示在下方。
69
+ 同一轮里连续成功的读取、搜索和目录浏览合并为一条探索记录。失败、写入和命令各自显示。
70
+ 用 Ctrl+T 查看逐条调用和输出,或用 `/tool-output full` 在主对话显示明细。
71
+
72
+ 运行中按 Enter 补充当前任务,按 Tab 将消息排到下一轮。输入框上方的 `Next turn` 预览显示待发数量和前两条消息。
73
+ 用 `/queue` 打开管理视图。↑/↓ 选中条目,Enter 编辑,`[`/`]` 移动,Delete 撤回。
74
+ 编辑时 Enter 保存,Ctrl+J 换行,Esc 返回。支持 Alt+↑ 的终端可直接编辑最后一条待发消息,主输入草稿会保留。
75
+ 用 `/queue resume` 继续已暂停的队列,`/queue clear` 清空。
76
+
77
+ - `/new` 创建独立会话。回合结束后用 `/resume` 搜索当前项目,或用 `/resume --all` 查全部项目。
78
+ 支持按标题、摘要、项目和 ID 筛选。方向键切换预览,Enter 恢复选中会话,Esc 返回。
61
79
  - `/rename <name>` 重命名当前会话,`/session rename` 仍支持指定其他会话。
62
80
  - `/quit` 退出,`/memories` 查看本地记忆状态。旧拼写 `/exit` 和 `/memory` 仍可输入。
63
81
 
@@ -103,6 +121,32 @@ JSONL stdout 每行是一个独立的 JSON 对象。每条记录有 `schemaVersi
103
121
  在原工作目录和 profile 下传入 `--resume`,通过新提示继续已保存的会话。新进程使用之前的
104
122
  历史与工具回执,JSONL 流只发出本次请求的事件。也可通过 stdin 管道传入新提示。
105
123
 
124
+ ### 按 JSON Schema 校验并保存最终回复
125
+
126
+ ```bash
127
+ orion -p --output-format jsonl --output-schema ./report.schema.json -o ./report.json -- "输出本次审查结果"
128
+ orion -p --output-last-message ./summary.txt -- "用三句话总结当前计划"
129
+ ```
130
+
131
+ - `--output-schema` 支持 JSON Schema Draft 7 和 2020-12,可使用同一文件内的引用。CLI 在请求模型前编译
132
+ Schema,并在当前回合完成后校验最终回复。兼容路由在 Provider 明确拒绝原生结构化输出时改用提示指引,始终执行本地校验。
133
+ - `-o` 和 `--output-last-message` 含义相同,只保存本回合最终模型回复。路径相对当前目录,目标父目录须已存在。
134
+ 文件通过原子替换写入,正文以换行结尾。旧文件在失败或中断时保留。
135
+ - 使用任一交付参数即启用严格退出状态。JSONL 会返回单一的 `result`,例如
136
+ `invalid_output_schema`、`invalid_final_json`、`output_schema_mismatch` 或 `output_write_failed`。
137
+ text 和 JSON 模式维持原有 stdout 格式,交付错误写入 stderr。
138
+
139
+ ### 在回合内继续操作 Shell 进程
140
+
141
+ Agent 可以用 `exec_command` 的 `interactive: true` 启动需要 stdin 或持续输出的命令。
142
+ `yieldMs` 控制单次等待,`timeout` 控制进程总时限。工具通过 `processId` 返回句柄。
143
+ 后续调用 `process_session`,以 `poll` 读新增输出、以 `write` 向 stdin 写入 `input`、以
144
+ `cancel` 停止进程。需要换行的命令须在 `input` 中包含换行。交互进程由当前回合持有,回合结束或中断会回收。
145
+
146
+ JSONL 的交互工具终态会带上 `processId`、`processStatus` 和 `outputTruncated`,
147
+ 实际退出时可带 `exitCode`。默认一次性命令继续在完成后返回输出,并在启动时关闭 stdin。
148
+ 交互方式使用管道,适用于行式程序,当前不支持 Docker sandbox 或要求 PTY 的程序。
149
+
106
150
  ## ACP 接入
107
151
 
108
152
  在 ACP 客户端中将 Agent 启动命令配置为 `orion`,参数设为 `["acp"]`。如果客户端进程的 PATH
@@ -490,12 +534,12 @@ ui:
490
534
  | --- | --- |
491
535
  | `theme` | `orion-pixel / classic / high-contrast / auto`;默认 `orion-pixel` |
492
536
  | `motion` | `full / reduced / off`;默认 `reduced` |
493
- | `mascot` | 布尔值,默认 `true` |
537
+ | `mascot` | 布尔值,默认 `false`,设为 `true` 可在启动区显示 Orion 像素形象 |
494
538
  | `statusLine` | 有序数组,可用项为示例中的七项,省略时按终端空间展示 |
495
539
  | `keymap` | 动作到按键数组的映射;省略使用默认快捷键 |
496
540
 
497
- keymap 动作为 `submit / queue / interrupt / history-search / external-editor / transcript / redraw / exit`。
498
- 允许的绑定为 `enter / tab / escape / ctrl+c / ctrl+d / ctrl+e / ctrl+l / ctrl+o / ctrl+r`;
541
+ keymap 动作为 `submit / queue / interrupt / history-search / external-editor / transcript / copy / redraw / exit`。
542
+ 允许的绑定为 `enter / tab / escape / ctrl+c / ctrl+d / ctrl+e / ctrl+l / ctrl+o / ctrl+r / ctrl+t`;
499
543
  配置不能重复占用同一个绑定,不接受原始 ANSI escape sequence。
500
544
  `ui.renderer` 不能写入 YAML;产品默认为 TUI,诊断界面使用 `orion --ui terminal`。
501
545