@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.
- package/CHANGELOG.md +17 -1
- package/README.md +8 -9
- package/README.zh-CN.md +8 -8
- package/dist/acp/session-updates.js +1 -0
- package/dist/cli.js +42 -3
- package/dist/commands/session-command-handlers.js +8 -3
- package/dist/commands/system-commands.js +3 -3
- package/dist/commands/types.d.ts +3 -0
- package/dist/framework/loop-progress.js +3 -1
- package/dist/framework/query.d.ts +6 -8
- package/dist/framework/query.js +39 -76
- package/dist/framework/tool-serializer.d.ts +12 -0
- package/dist/framework/tool-serializer.js +35 -0
- package/dist/framework/tool.d.ts +2 -0
- package/dist/framework/verification-command.d.ts +21 -0
- package/dist/framework/verification-command.js +53 -4
- package/dist/harness/context-harness.d.ts +3 -9
- package/dist/harness/context-harness.js +43 -163
- package/dist/harness/ledger.js +2 -1
- package/dist/harness/state.d.ts +3 -0
- package/dist/harness/state.js +37 -4
- package/dist/harness/task-checklist.d.ts +1 -1
- package/dist/harness/task-checklist.js +1 -1
- package/dist/harness/types.d.ts +1 -0
- package/dist/harness/verification.js +5 -4
- package/dist/print-ui/delivery.d.ts +15 -0
- package/dist/print-ui/delivery.js +131 -0
- package/dist/print-ui/event-stream.d.ts +6 -1
- package/dist/print-ui/event-stream.js +56 -10
- package/dist/print-ui/launch.d.ts +5 -0
- package/dist/print-ui/launch.js +66 -9
- package/dist/runtime/agent-loop.d.ts +3 -1
- package/dist/runtime/agent-loop.js +26 -41
- package/dist/runtime/agent-runtime-controller.d.ts +4 -1
- package/dist/runtime/agent-runtime-controller.js +36 -22
- package/dist/runtime/agent-runtime-runner.d.ts +4 -0
- package/dist/runtime/agent-runtime-runner.js +9 -0
- package/dist/runtime/builtin-tool-provider.js +6 -5
- package/dist/runtime/composer/layout.d.ts +1 -1
- package/dist/runtime/composer/layout.js +5 -5
- package/dist/runtime/core-tools/descriptors.d.ts +1 -1
- package/dist/runtime/core-tools/descriptors.js +39 -1
- package/dist/runtime/first-party-core-provider.js +1 -0
- package/dist/runtime/first-party-tool-services.js +10 -0
- package/dist/runtime/goal-lifecycle-v2.js +5 -0
- package/dist/runtime/goal-runtime-coordinator.js +6 -2
- package/dist/runtime/goals/evidence.js +2 -0
- package/dist/runtime/legacy-thread-materializer.d.ts +7 -0
- package/dist/runtime/legacy-thread-materializer.js +32 -6
- package/dist/runtime/orion-runtime-v1.d.ts +2 -1
- package/dist/runtime/orion-runtime-v1.js +34 -6
- package/dist/runtime/product-bootstrap.d.ts +2 -0
- package/dist/runtime/product-bootstrap.js +1 -0
- package/dist/runtime/product-orion-runtime.d.ts +2 -1
- package/dist/runtime/product-orion-runtime.js +7 -2
- package/dist/runtime/rich-text/layout.d.ts +3 -1
- package/dist/runtime/rich-text/layout.js +37 -22
- package/dist/runtime/shell-process-sessions.d.ts +41 -0
- package/dist/runtime/shell-process-sessions.js +258 -0
- package/dist/runtime/step-snapshot.js +61 -11
- package/dist/runtime/subagents/presets.d.ts +1 -1
- package/dist/runtime/subagents/presets.js +1 -0
- package/dist/runtime/task-context-recovery.js +14 -3
- package/dist/runtime/task-context-service.d.ts +2 -6
- package/dist/runtime/task-context-service.js +3 -12
- package/dist/runtime/thread-event-store.d.ts +3 -0
- package/dist/runtime/thread-event-store.js +35 -22
- package/dist/runtime/thread-session-index.d.ts +15 -3
- package/dist/runtime/thread-session-index.js +152 -45
- package/dist/runtime/thread-session-view.js +1 -1
- package/dist/runtime/thread-ui-adapter.d.ts +1 -1
- package/dist/runtime/thread-ui-adapter.js +23 -5
- package/dist/runtime/tool-gateway.d.ts +1 -0
- package/dist/runtime/tool-gateway.js +1 -0
- package/dist/runtime/tool-transcript-entry.d.ts +8 -1
- package/dist/runtime/tool-transcript-entry.js +35 -7
- package/dist/runtime/ui-events.d.ts +10 -0
- package/dist/runtime/verification-feedback.d.ts +4 -0
- package/dist/runtime/verification-feedback.js +61 -0
- package/dist/services/global-config.d.ts +1 -1
- package/dist/services/global-config.js +2 -0
- package/dist/services/llm.d.ts +3 -0
- package/dist/services/llm.js +48 -4
- package/dist/terminal-ui/raw-editor.js +2 -1
- package/dist/tools/bash_security.d.ts +1 -24
- package/dist/tools/bash_security.js +7 -124
- package/dist/tools/core/exec-command.js +51 -42
- package/dist/tools/core/index.d.ts +2 -1
- package/dist/tools/core/index.js +4 -1
- package/dist/tools/core/process-session.d.ts +2 -0
- package/dist/tools/core/process-session.js +54 -0
- package/dist/tools/todo.js +9 -13
- package/dist/tui-core/frame.d.ts +2 -0
- package/dist/tui-core/frame.js +19 -0
- package/dist/tui-core/input-parser.d.ts +4 -1
- package/dist/tui-core/input-parser.js +22 -0
- package/dist/tui-ui/chrome-view-model.d.ts +0 -2
- package/dist/tui-ui/chrome-view-model.js +54 -56
- package/dist/tui-ui/launch.js +133 -202
- package/dist/tui-ui/layout.d.ts +16 -41
- package/dist/tui-ui/layout.js +408 -295
- package/dist/tui-ui/render-scheduler.d.ts +2 -5
- package/dist/tui-ui/render-scheduler.js +10 -10
- package/dist/tui-ui/response-clipboard.d.ts +17 -0
- package/dist/tui-ui/response-clipboard.js +201 -0
- package/dist/tui-ui/runner.d.ts +65 -80
- package/dist/tui-ui/runner.js +545 -738
- package/dist/tui-ui/session-picker-preview.d.ts +8 -0
- package/dist/tui-ui/session-picker-preview.js +119 -0
- package/dist/tui-ui/session-picker.d.ts +20 -0
- package/dist/tui-ui/session-picker.js +42 -0
- package/dist/tui-ui/state.d.ts +34 -81
- package/dist/tui-ui/state.js +155 -288
- package/dist/tui-ui/terminal-image.d.ts +3 -7
- package/dist/tui-ui/terminal-image.js +18 -47
- package/dist/tui-ui/terminal-viewport.d.ts +55 -0
- package/dist/tui-ui/terminal-viewport.js +221 -0
- package/dist/tui-ui/transcript-layout.d.ts +5 -0
- package/dist/tui-ui/transcript-layout.js +43 -28
- package/dist/tui-ui/transcript-pager.d.ts +39 -0
- package/dist/tui-ui/transcript-pager.js +278 -0
- package/dist/tui-ui/transcript-tool-output.d.ts +16 -0
- package/dist/tui-ui/transcript-tool-output.js +102 -0
- package/dist/utils/bounded-file.d.ts +4 -0
- package/dist/utils/bounded-file.js +30 -0
- package/dist/utils/command-process.d.ts +4 -0
- package/dist/utils/command-process.js +23 -0
- package/dist/utils/shell-command.d.ts +29 -0
- package/dist/utils/shell-command.js +185 -0
- package/docs/cli-guide.md +50 -6
- package/npm-shrinkwrap.json +115 -15
- package/package.json +4 -1
- package/dist/tui-ui/inline-surface.d.ts +0 -191
- package/dist/tui-ui/inline-surface.js +0 -644
- package/dist/tui-ui/input-ownership.d.ts +0 -46
- package/dist/tui-ui/input-ownership.js +0 -74
- package/dist/tui-ui/transcript-inspector-layout.d.ts +0 -9
- package/dist/tui-ui/transcript-inspector-layout.js +0 -107
- package/dist/tui-ui/transcript-inspector-surface.d.ts +0 -18
- package/dist/tui-ui/transcript-inspector-surface.js +0 -91
- package/dist/tui-ui/transcript-inspector.d.ts +0 -36
- 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
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result of a quote-aware scan over a whole command line.
|
|
3
|
+
*/
|
|
4
|
+
export interface ShellCommandScan {
|
|
5
|
+
/** The individual commands on the line, split on unquoted separators. */
|
|
6
|
+
segments: string[];
|
|
7
|
+
/**
|
|
8
|
+
* False when the line uses a construct this scanner cannot reason about --
|
|
9
|
+
* command substitution, process substitution or an unbalanced quote. Such a
|
|
10
|
+
* line can hide an arbitrary command and must never be auto-approved.
|
|
11
|
+
*/
|
|
12
|
+
supported: boolean;
|
|
13
|
+
/** True when the line redirects output somewhere other than /dev/null. */
|
|
14
|
+
writesFile: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Split a command line into the individual commands it will actually run.
|
|
18
|
+
*
|
|
19
|
+
* The classifier below hands out "run without confirmation" verdicts, so it has
|
|
20
|
+
* to see every command on the line rather than just the leading token. Quote
|
|
21
|
+
* state is tracked so `echo "a && b"` stays one segment, and substitutions are
|
|
22
|
+
* reported as unsupported instead of being silently skipped over.
|
|
23
|
+
*/
|
|
24
|
+
type ShellCommandOperator = ';' | '\n' | '&' | '|' | '&&' | '||';
|
|
25
|
+
export declare function scanShellCommand(cmd: string, onOperator?: (operator: ShellCommandOperator) => void): ShellCommandScan;
|
|
26
|
+
/** Read literal arguments of an already scanned single command. */
|
|
27
|
+
export declare function literalShellWords(command: string): string[] | undefined;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=shell-command.d.ts.map
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.scanShellCommand = scanShellCommand;
|
|
4
|
+
exports.literalShellWords = literalShellWords;
|
|
5
|
+
/** The one redirect target that does not count as writing to the filesystem. */
|
|
6
|
+
const DISCARD_REDIRECT_TARGET = '/dev/null';
|
|
7
|
+
function scanShellCommand(cmd, onOperator) {
|
|
8
|
+
const segments = [];
|
|
9
|
+
let current = '';
|
|
10
|
+
let supported = true;
|
|
11
|
+
let writesFile = false;
|
|
12
|
+
let inSingleQuote = false;
|
|
13
|
+
let inDoubleQuote = false;
|
|
14
|
+
let wordStarted = false;
|
|
15
|
+
const pushSegment = () => {
|
|
16
|
+
const segment = current.trim();
|
|
17
|
+
if (segment.length > 0) {
|
|
18
|
+
segments.push(segment);
|
|
19
|
+
}
|
|
20
|
+
current = '';
|
|
21
|
+
wordStarted = false;
|
|
22
|
+
};
|
|
23
|
+
for (let i = 0; i < cmd.length; i++) {
|
|
24
|
+
const ch = cmd[i];
|
|
25
|
+
const next = cmd[i + 1];
|
|
26
|
+
if (ch === '\\' && !inSingleQuote && next !== undefined) {
|
|
27
|
+
current += ch + next;
|
|
28
|
+
if (next !== '\n')
|
|
29
|
+
wordStarted = true;
|
|
30
|
+
i++;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (ch === "'" && !inDoubleQuote) {
|
|
34
|
+
inSingleQuote = !inSingleQuote;
|
|
35
|
+
current += ch;
|
|
36
|
+
wordStarted = true;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (ch === '"' && !inSingleQuote) {
|
|
40
|
+
inDoubleQuote = !inDoubleQuote;
|
|
41
|
+
current += ch;
|
|
42
|
+
wordStarted = true;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (inSingleQuote) {
|
|
46
|
+
// Single quotes disable every expansion, so the contents stay inert.
|
|
47
|
+
current += ch;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (inDoubleQuote) {
|
|
51
|
+
// Double quotes only suppress globbing and word splitting -- bash still
|
|
52
|
+
// expands `$(...)` and backticks inside them. Skipping the substitution
|
|
53
|
+
// check here made `echo "$(rm -rf $HOME)"` classify as safe/read-only and
|
|
54
|
+
// auto-approve, i.e. a straight command-execution bypass.
|
|
55
|
+
if (ch === '`' || (ch === '$' && next === '(')) {
|
|
56
|
+
supported = false;
|
|
57
|
+
}
|
|
58
|
+
current += ch;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (ch === '#' && !wordStarted) {
|
|
62
|
+
while (i + 1 < cmd.length && cmd[i + 1] !== '\n')
|
|
63
|
+
i++;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
// Command and process substitution can hide an arbitrary command inside an
|
|
67
|
+
// otherwise innocent-looking line, and neither is worth modelling here.
|
|
68
|
+
if (ch === '`' ||
|
|
69
|
+
(ch === '$' && next === '(') ||
|
|
70
|
+
((ch === '<' || ch === '>') && next === '(')) {
|
|
71
|
+
supported = false;
|
|
72
|
+
current += ch;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (ch === ';' || ch === '\n') {
|
|
76
|
+
pushSegment();
|
|
77
|
+
onOperator?.(ch);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if ((ch === '&' && next === '&') || (ch === '|' && next === '|')) {
|
|
81
|
+
pushSegment();
|
|
82
|
+
onOperator?.(ch === '&' ? '&&' : '||');
|
|
83
|
+
i++;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (ch === '&' || ch === '|') {
|
|
87
|
+
pushSegment();
|
|
88
|
+
onOperator?.(ch);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (ch === '>') {
|
|
92
|
+
let cursor = i + 1;
|
|
93
|
+
if (cmd[cursor] === '>') {
|
|
94
|
+
cursor++;
|
|
95
|
+
}
|
|
96
|
+
if (cmd[cursor] === '&') {
|
|
97
|
+
// `>&1` / `2>&1` duplicate a descriptor and `>&-` closes one; nothing
|
|
98
|
+
// reaches the filesystem. Consume the whole reference so its `&` is not
|
|
99
|
+
// mistaken for a background-job separator.
|
|
100
|
+
let end = cursor + 1;
|
|
101
|
+
while (end < cmd.length && cmd[end] >= '0' && cmd[end] <= '9') {
|
|
102
|
+
end++;
|
|
103
|
+
}
|
|
104
|
+
if (cmd[end] === '-') {
|
|
105
|
+
end++;
|
|
106
|
+
}
|
|
107
|
+
current += cmd.slice(i, end);
|
|
108
|
+
wordStarted = false;
|
|
109
|
+
i = end - 1;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
while (cursor < cmd.length && (cmd[cursor] === ' ' || cmd[cursor] === '\t')) {
|
|
113
|
+
cursor++;
|
|
114
|
+
}
|
|
115
|
+
const target = cmd.slice(cursor).split(/[\s;&|<>]/)[0];
|
|
116
|
+
if (target !== DISCARD_REDIRECT_TARGET) {
|
|
117
|
+
writesFile = true;
|
|
118
|
+
}
|
|
119
|
+
current += ch;
|
|
120
|
+
wordStarted = false;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
current += ch;
|
|
124
|
+
wordStarted = !/[\s<]/u.test(ch);
|
|
125
|
+
}
|
|
126
|
+
pushSegment();
|
|
127
|
+
return {
|
|
128
|
+
segments,
|
|
129
|
+
supported: supported && !inSingleQuote && !inDoubleQuote,
|
|
130
|
+
writesFile,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/** Read literal arguments of an already scanned single command. */
|
|
134
|
+
function literalShellWords(command) {
|
|
135
|
+
const words = [];
|
|
136
|
+
let word = '';
|
|
137
|
+
let quote;
|
|
138
|
+
let started = false;
|
|
139
|
+
const flush = () => {
|
|
140
|
+
if (started)
|
|
141
|
+
words.push(word);
|
|
142
|
+
word = '';
|
|
143
|
+
started = false;
|
|
144
|
+
};
|
|
145
|
+
for (let index = 0; index < command.length; index++) {
|
|
146
|
+
const char = command[index];
|
|
147
|
+
const next = command[index + 1];
|
|
148
|
+
if (char === '\\' && quote !== "'") {
|
|
149
|
+
if (next === undefined)
|
|
150
|
+
return;
|
|
151
|
+
if (quote === '"' && !['\\', '"', '$', '`', '\n'].includes(next)) {
|
|
152
|
+
word += char;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
index++;
|
|
156
|
+
if (next !== '\n') {
|
|
157
|
+
word += next;
|
|
158
|
+
started = true;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (char === quote || (!quote && (char === "'" || char === '"'))) {
|
|
164
|
+
quote = quote ? undefined : char;
|
|
165
|
+
started = true;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (quote !== "'" && (char === '$' || char === '`'))
|
|
169
|
+
return;
|
|
170
|
+
if (!quote && char === '#' && !started)
|
|
171
|
+
break;
|
|
172
|
+
if (!quote && /[\s<>]/u.test(char)) {
|
|
173
|
+
flush();
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
word += char;
|
|
177
|
+
started = true;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (quote)
|
|
181
|
+
return;
|
|
182
|
+
flush();
|
|
183
|
+
return words;
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=shell-command.js.map
|