@narumitw/pi-starship 0.62.0 → 0.64.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.
- package/README.md +23 -11
- package/dist/chunks/{chunk-PWTSHSP3.ts → chunk-A65IOGL6.ts} +6 -7
- package/dist/chunks/chunk-A65IOGL6.ts.map +7 -0
- package/dist/chunks/{chunk-HPZTMIZS.ts → chunk-DIHVBO5Z.ts} +41 -8
- package/dist/chunks/chunk-DIHVBO5Z.ts.map +7 -0
- package/dist/chunks/{chunk-43VIENBN.ts → chunk-UIKPE4UC.ts} +7 -7
- package/dist/chunks/{chunk-43VIENBN.ts.map → chunk-UIKPE4UC.ts.map} +2 -2
- package/dist/chunks/{command-configuration-menu-S2LXCOJG.ts → command-configuration-menu-ZN2VXU4L.ts} +3 -3
- package/dist/chunks/{command-settings-chat-O34BEU4X.ts → command-settings-chat-KLUVZXMO.ts} +632 -196
- package/dist/chunks/command-settings-chat-KLUVZXMO.ts.map +7 -0
- package/dist/chunks/{commands-ZYIJVIEJ.ts → commands-UAUSSHVS.ts} +25 -20
- package/dist/chunks/commands-UAUSSHVS.ts.map +7 -0
- package/dist/index.ts +116 -59
- package/dist/index.ts.map +3 -3
- package/package.json +1 -1
- package/skills/configure-pi-starship/SKILL.md +3 -1
- package/skills/configure-pi-starship/references/configuration.md +14 -12
- package/src/command-commit.ts +41 -7
- package/src/command-configuration.ts +8 -10
- package/src/command-settings-chat.ts +18 -48
- package/src/commands.ts +23 -26
- package/src/config.ts +6 -6
- package/src/pi-starship.ts +155 -88
- package/src/settings-chat-display.ts +11 -0
- package/src/settings-chat-fullscreen.ts +264 -0
- package/src/settings-chat-scroll.ts +17 -0
- package/src/settings-chat-tools.ts +207 -0
- package/src/settings-chat-transcript.ts +133 -62
- package/src/settings-chat-ui.ts +109 -98
- package/dist/chunks/chunk-HPZTMIZS.ts.map +0 -7
- package/dist/chunks/chunk-PWTSHSP3.ts.map +0 -7
- package/dist/chunks/command-settings-chat-O34BEU4X.ts.map +0 -7
- package/dist/chunks/commands-ZYIJVIEJ.ts.map +0 -7
- /package/dist/chunks/{command-configuration-menu-S2LXCOJG.ts.map → command-configuration-menu-ZN2VXU4L.ts.map} +0 -0
|
@@ -5,24 +5,23 @@ import {
|
|
|
5
5
|
commitActiveDocument,
|
|
6
6
|
commitOwnerCurrent,
|
|
7
7
|
saveAsProfile
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-DIHVBO5Z.ts";
|
|
9
9
|
import {
|
|
10
10
|
assertProfileUnchanged,
|
|
11
|
-
configurationPresentation
|
|
12
|
-
|
|
13
|
-
} from "./chunk-43VIENBN.ts";
|
|
11
|
+
configurationPresentation
|
|
12
|
+
} from "./chunk-UIKPE4UC.ts";
|
|
14
13
|
import {
|
|
15
14
|
BUILT_IN_EXAMPLE,
|
|
16
15
|
MODULE_DEFINITIONS,
|
|
17
16
|
validateConfigDocument
|
|
18
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-A65IOGL6.ts";
|
|
19
18
|
import "./chunk-IYDZ3R2T.ts";
|
|
20
19
|
import "./chunk-KP33I6BR.ts";
|
|
21
20
|
|
|
22
21
|
// src/command-settings-chat.ts
|
|
23
22
|
import { withFileMutationQueue as withFileMutationQueue2 } from "@earendil-works/pi-coding-agent";
|
|
24
23
|
import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
|
|
25
|
-
import { sanitizeTerminalDocument as
|
|
24
|
+
import { sanitizeTerminalDocument as sanitizeTerminalDocument5 } from "@narumitw/pi-tui-kit/terminal-document";
|
|
26
25
|
|
|
27
26
|
// src/settings-agent.ts
|
|
28
27
|
import { randomUUID } from "node:crypto";
|
|
@@ -101,46 +100,449 @@ import {
|
|
|
101
100
|
CURSOR_MARKER,
|
|
102
101
|
Editor,
|
|
103
102
|
getKeybindings,
|
|
104
|
-
isKeyRelease,
|
|
103
|
+
isKeyRelease as isKeyRelease2,
|
|
105
104
|
Key,
|
|
106
|
-
matchesKey,
|
|
105
|
+
matchesKey as matchesKey2,
|
|
107
106
|
parseKey,
|
|
108
107
|
TUI_KEYBINDINGS,
|
|
109
|
-
truncateToWidth
|
|
108
|
+
truncateToWidth,
|
|
109
|
+
VStack
|
|
110
110
|
} from "@earendil-works/pi-tui";
|
|
111
|
-
import { HorizontalRule, renderBoundedFrame
|
|
112
|
-
import { sanitizeTerminalDocument as
|
|
111
|
+
import { HorizontalRule, renderBoundedFrame } from "@narumitw/pi-tui-kit";
|
|
112
|
+
import { sanitizeTerminalDocument as sanitizeTerminalDocument4 } from "@narumitw/pi-tui-kit/terminal-document";
|
|
113
113
|
|
|
114
|
-
// src/settings-chat-
|
|
114
|
+
// src/settings-chat-fullscreen.ts
|
|
115
115
|
import {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
116
|
+
isKeyRelease,
|
|
117
|
+
matchesKey,
|
|
118
|
+
TuiAltScreen
|
|
119
|
+
} from "@earendil-works/pi-tui";
|
|
120
|
+
var SettingsChatTui = class extends TuiAltScreen {
|
|
121
|
+
addInputListener(listener) {
|
|
122
|
+
if (!this.guardInstalled) {
|
|
123
|
+
this.guardInstalled = true;
|
|
124
|
+
super.addInputListener((data) => this.guard?.(data));
|
|
125
|
+
}
|
|
126
|
+
return super.addInputListener(listener);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
async function runSettingsChatFullscreen(ctx, owner, create, cancelledValue, dependencies = {}) {
|
|
130
|
+
const current = () => !owner.signal.aborted && !ctx.signal?.aborted && owner.isCurrent();
|
|
131
|
+
const canRestoreTerminal = () => (owner.canRestoreTerminal ?? owner.isSessionCurrent ?? owner.isCurrent)();
|
|
132
|
+
if (ctx.mode !== "tui" || !current()) return cancelledValue;
|
|
133
|
+
let mount;
|
|
134
|
+
let releaseHost;
|
|
135
|
+
let completedOutcome;
|
|
136
|
+
const outcome = await ctx.ui.custom(
|
|
137
|
+
(parent, theme, keybindings, done) => {
|
|
138
|
+
const controller = new AbortController();
|
|
139
|
+
let child;
|
|
140
|
+
let component;
|
|
141
|
+
let overlay;
|
|
142
|
+
let parentStopped = false;
|
|
143
|
+
let entry;
|
|
144
|
+
let entryDrainStarted = false;
|
|
145
|
+
let finished = false;
|
|
146
|
+
let closing = false;
|
|
147
|
+
let cleanup;
|
|
148
|
+
let pasting = false;
|
|
149
|
+
let result = { value: cancelledValue };
|
|
150
|
+
const errors = [];
|
|
151
|
+
const removers = [];
|
|
152
|
+
const attempt = (action) => {
|
|
153
|
+
try {
|
|
154
|
+
action();
|
|
155
|
+
} catch (error) {
|
|
156
|
+
errors.push(error);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const finish = (next) => {
|
|
160
|
+
if (closing) return cleanup;
|
|
161
|
+
closing = true;
|
|
162
|
+
result = next;
|
|
163
|
+
controller.abort();
|
|
164
|
+
cleanup = Promise.resolve().then(async () => {
|
|
165
|
+
await entry;
|
|
166
|
+
if (parentStopped) {
|
|
167
|
+
try {
|
|
168
|
+
await parent.terminal.drainInput?.();
|
|
169
|
+
} catch (error) {
|
|
170
|
+
errors.push(error);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (entryDrainStarted && !parentStopped) {
|
|
174
|
+
parentStopped = true;
|
|
175
|
+
attempt(() => parent.stop({ preserveScreen: true }));
|
|
176
|
+
}
|
|
177
|
+
for (const remove of removers.splice(0)) attempt(remove);
|
|
178
|
+
attempt(() => component?.dispose?.());
|
|
179
|
+
if (child) attempt(() => child?.stop({ preserveScreen: true }));
|
|
180
|
+
if (parentStopped) {
|
|
181
|
+
attempt(() => overlay?.setHidden(true));
|
|
182
|
+
attempt(() => {
|
|
183
|
+
if (canRestoreTerminal()) {
|
|
184
|
+
attempt(() => parent.start());
|
|
185
|
+
attempt(() => parent.renderNow(false));
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
await component?.waitForPending?.();
|
|
191
|
+
} catch (error) {
|
|
192
|
+
errors.push(error);
|
|
193
|
+
}
|
|
194
|
+
attempt(() => {
|
|
195
|
+
if (!current() && !("error" in result)) result = { value: cancelledValue };
|
|
196
|
+
});
|
|
197
|
+
finished = true;
|
|
198
|
+
if ("error" in result) errors.unshift(result.error);
|
|
199
|
+
completedOutcome = errors.length ? { error: errors.length === 1 ? errors[0] : new AggregateError(errors, "Fullscreen cleanup failed") } : result;
|
|
200
|
+
done(completedOutcome);
|
|
201
|
+
});
|
|
202
|
+
return cleanup;
|
|
203
|
+
};
|
|
204
|
+
releaseHost = () => finish({ value: cancelledValue }) ?? Promise.resolve();
|
|
205
|
+
const cancel = () => finish({ value: cancelledValue });
|
|
206
|
+
const guard = (data) => {
|
|
207
|
+
if (closing) return { consume: true };
|
|
208
|
+
if (!current()) {
|
|
209
|
+
cancel();
|
|
210
|
+
return { consume: true };
|
|
211
|
+
}
|
|
212
|
+
const wasPasting = pasting;
|
|
213
|
+
for (const part of data.split("\x1B").slice(1)) {
|
|
214
|
+
if (part.startsWith("[200~")) pasting = true;
|
|
215
|
+
else if (part.startsWith("[201~")) pasting = false;
|
|
216
|
+
}
|
|
217
|
+
if (wasPasting || pasting || data.includes("\x1B[200~") || data.includes("\x1B[201~")) {
|
|
218
|
+
try {
|
|
219
|
+
child?.getFocusedComponent()?.handleInput?.(data);
|
|
220
|
+
child?.requestRender();
|
|
221
|
+
} catch (error) {
|
|
222
|
+
finish({ error });
|
|
223
|
+
}
|
|
224
|
+
return { consume: true };
|
|
225
|
+
}
|
|
226
|
+
if (!isKeyRelease(data) && matchesKey(data, "ctrl+c")) {
|
|
227
|
+
cancel();
|
|
228
|
+
return { consume: true };
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
for (const signal of /* @__PURE__ */ new Set([owner.signal, ctx.signal])) {
|
|
232
|
+
if (!signal) continue;
|
|
233
|
+
signal.addEventListener("abort", cancel, { once: true });
|
|
234
|
+
removers.push(() => signal.removeEventListener("abort", cancel));
|
|
235
|
+
}
|
|
236
|
+
const host = {
|
|
237
|
+
render: () => [],
|
|
238
|
+
invalidate() {
|
|
239
|
+
},
|
|
240
|
+
dispose() {
|
|
241
|
+
if (!finished) cancel();
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
mount = (handle) => {
|
|
245
|
+
overlay = handle;
|
|
246
|
+
queueMicrotask(() => {
|
|
247
|
+
if (closing) return;
|
|
248
|
+
entry = (async () => {
|
|
249
|
+
try {
|
|
250
|
+
if (!current()) {
|
|
251
|
+
cancel();
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
entryDrainStarted = parent.terminal.drainInput !== void 0;
|
|
255
|
+
await parent.terminal.drainInput?.();
|
|
256
|
+
if (closing) return;
|
|
257
|
+
if (!current()) {
|
|
258
|
+
cancel();
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
parentStopped = true;
|
|
262
|
+
parent.stop({ preserveScreen: true });
|
|
263
|
+
if (closing) return;
|
|
264
|
+
const createDefault = () => new SettingsChatTui(parent.terminal, parent.getShowHardwareCursor(), void 0, { mouse: true });
|
|
265
|
+
child = dependencies.createTui?.(parent, createDefault) ?? createDefault();
|
|
266
|
+
if (child instanceof SettingsChatTui) child.guard = guard;
|
|
267
|
+
else removers.push(child.addInputListener(guard));
|
|
268
|
+
component = create({
|
|
269
|
+
tui: child,
|
|
270
|
+
theme,
|
|
271
|
+
keybindings,
|
|
272
|
+
signal: controller.signal,
|
|
273
|
+
complete: (value) => finish({ value })
|
|
274
|
+
});
|
|
275
|
+
if (closing) return;
|
|
276
|
+
if (!current()) {
|
|
277
|
+
cancel();
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
child.setLayoutRoot(component.getFullscreenLayout?.() ?? component);
|
|
281
|
+
child.setFocus(component);
|
|
282
|
+
child.start();
|
|
283
|
+
} catch (error) {
|
|
284
|
+
if (closing) errors.push(error);
|
|
285
|
+
else finish({ error });
|
|
286
|
+
}
|
|
287
|
+
})();
|
|
288
|
+
});
|
|
289
|
+
};
|
|
290
|
+
if (!current()) cancel();
|
|
291
|
+
return host;
|
|
292
|
+
},
|
|
293
|
+
{ overlay: true, onHandle: (handle) => mount?.(handle) }
|
|
294
|
+
).catch(async (error) => {
|
|
295
|
+
await releaseHost?.();
|
|
296
|
+
if (completedOutcome && "error" in completedOutcome) {
|
|
297
|
+
throw new AggregateError([error, completedOutcome.error], "Fullscreen mount and cleanup failed");
|
|
298
|
+
}
|
|
299
|
+
throw error;
|
|
300
|
+
});
|
|
301
|
+
await releaseHost?.();
|
|
302
|
+
const completion = completedOutcome ?? outcome;
|
|
303
|
+
if (!completion) return cancelledValue;
|
|
304
|
+
if ("error" in completion) throw completion.error;
|
|
305
|
+
return completion.value;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// src/settings-chat-scroll.ts
|
|
309
|
+
import { ScrollView } from "@earendil-works/pi-tui";
|
|
310
|
+
var SettingsChatScrollView = class extends ScrollView {
|
|
311
|
+
anchor;
|
|
312
|
+
restoreAnchor;
|
|
313
|
+
updateLayout(contentHeight, viewportHeight, requestRender) {
|
|
314
|
+
const manual = !this.isFollowingEnd;
|
|
315
|
+
const target = manual && this.anchor ? this.restoreAnchor?.(this.anchor) : void 0;
|
|
316
|
+
super.updateLayout(contentHeight, viewportHeight, requestRender);
|
|
317
|
+
if (manual) this.scrollTo(target ?? this.scrollTop, { disableFollow: true });
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
// src/settings-chat-transcript.ts
|
|
322
|
+
import { stripVTControlCharacters } from "node:util";
|
|
323
|
+
import { AssistantMessageComponent, UserMessageComponent } from "@earendil-works/pi-coding-agent";
|
|
324
|
+
import { sanitizeTerminalDocument as sanitizeTerminalDocument3 } from "@narumitw/pi-tui-kit/terminal-document";
|
|
325
|
+
|
|
326
|
+
// src/settings-chat-display.ts
|
|
123
327
|
import { sanitizeTerminalDocument } from "@narumitw/pi-tui-kit/terminal-document";
|
|
124
|
-
function
|
|
328
|
+
function settingsChatDisplayValue(value) {
|
|
125
329
|
if (typeof value === "string") return sanitizeTerminalDocument(value);
|
|
126
|
-
if (Array.isArray(value)) return value.map(
|
|
330
|
+
if (Array.isArray(value)) return value.map(settingsChatDisplayValue);
|
|
127
331
|
if (value && typeof value === "object") {
|
|
128
|
-
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key,
|
|
332
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, settingsChatDisplayValue(item)]));
|
|
129
333
|
}
|
|
130
334
|
return value;
|
|
131
335
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
336
|
+
|
|
337
|
+
// src/settings-chat-tools.ts
|
|
338
|
+
import { resolve } from "node:path";
|
|
339
|
+
import {
|
|
340
|
+
createEditToolDefinition,
|
|
341
|
+
createReadToolDefinition,
|
|
342
|
+
createWriteToolDefinition,
|
|
343
|
+
ToolExecutionComponent
|
|
344
|
+
} from "@earendil-works/pi-coding-agent";
|
|
345
|
+
import { sanitizeTerminalDocument as sanitizeTerminalDocument2 } from "@narumitw/pi-tui-kit/terminal-document";
|
|
346
|
+
function createSettingsChatTools(tui, cwd, initialExpanded, editablePath) {
|
|
347
|
+
const rows = /* @__PURE__ */ new Map();
|
|
348
|
+
const pending = /* @__PURE__ */ new Set();
|
|
349
|
+
const edit = createEditToolDefinition(cwd);
|
|
350
|
+
const renderEditCall = edit.renderCall;
|
|
351
|
+
if (renderEditCall) {
|
|
352
|
+
edit.renderCall = (args, theme, context) => {
|
|
353
|
+
const path = typeof args?.path === "string" ? args.path : args && "file_path" in args ? args.file_path : void 0;
|
|
354
|
+
const allowed = editablePath !== void 0 && typeof path === "string" && resolve(cwd, path) === resolve(editablePath);
|
|
355
|
+
return renderEditCall(args, theme, { ...context, argsComplete: context.argsComplete && allowed });
|
|
356
|
+
};
|
|
357
|
+
}
|
|
135
358
|
const definitions = {
|
|
136
359
|
read: createReadToolDefinition(cwd),
|
|
137
360
|
write: createWriteToolDefinition(cwd),
|
|
138
|
-
edit
|
|
361
|
+
edit
|
|
362
|
+
};
|
|
363
|
+
let disposed = false;
|
|
364
|
+
let expanded = initialExpanded;
|
|
365
|
+
const ensure = (id, name, args) => {
|
|
366
|
+
let row = rows.get(id);
|
|
367
|
+
if (!row) {
|
|
368
|
+
row = { name, args, complete: false, started: false, partial: true };
|
|
369
|
+
rows.set(id, row);
|
|
370
|
+
}
|
|
371
|
+
if (!row.component) {
|
|
372
|
+
const toolName = row.name;
|
|
373
|
+
const definition = toolName === "read" || toolName === "write" || toolName === "edit" ? definitions[toolName] : void 0;
|
|
374
|
+
const ownedRow = row;
|
|
375
|
+
const toolUi = new Proxy(tui, {
|
|
376
|
+
get(target, property) {
|
|
377
|
+
if (property === "requestRender")
|
|
378
|
+
return () => {
|
|
379
|
+
if (!disposed && rows.get(id) === ownedRow && ownedRow.component === component) target.requestRender();
|
|
380
|
+
};
|
|
381
|
+
const value = Reflect.get(target, property, target);
|
|
382
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
const Component = class extends ToolExecutionComponent {
|
|
386
|
+
setExpanded(value) {
|
|
387
|
+
ownedRow.expanded = value;
|
|
388
|
+
super.setExpanded(value);
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
const component = new Component(
|
|
392
|
+
sanitizeTerminalDocument2(toolName),
|
|
393
|
+
sanitizeTerminalDocument2(id),
|
|
394
|
+
settingsChatDisplayValue(row.args),
|
|
395
|
+
{ showImages: false, outputPad: 1 },
|
|
396
|
+
definition,
|
|
397
|
+
toolUi,
|
|
398
|
+
sanitizeTerminalDocument2(cwd)
|
|
399
|
+
);
|
|
400
|
+
row.component = component;
|
|
401
|
+
component.setExpanded(row.expanded ?? expanded);
|
|
402
|
+
if (row.complete && (!row.result || row.partial)) component.setArgsComplete();
|
|
403
|
+
if (row.started) component.markExecutionStarted();
|
|
404
|
+
if (row.result) component.updateResult(settingsChatDisplayValue(row.result), row.partial);
|
|
405
|
+
}
|
|
406
|
+
return row;
|
|
407
|
+
};
|
|
408
|
+
const updateArgs = (call) => {
|
|
409
|
+
const row = ensure(call.id, call.name, call.arguments);
|
|
410
|
+
row.args = call.arguments;
|
|
411
|
+
row.component?.updateArgs(settingsChatDisplayValue(call.arguments));
|
|
412
|
+
return row;
|
|
413
|
+
};
|
|
414
|
+
const completeArgs = (row) => {
|
|
415
|
+
if (row.complete) return;
|
|
416
|
+
row.complete = true;
|
|
417
|
+
row.component?.setArgsComplete();
|
|
139
418
|
};
|
|
419
|
+
const result = (row, value, partial = false) => {
|
|
420
|
+
row.result = value;
|
|
421
|
+
row.partial = partial;
|
|
422
|
+
row.component?.updateResult(settingsChatDisplayValue(value), partial);
|
|
423
|
+
};
|
|
424
|
+
const failure = (message) => ({
|
|
425
|
+
content: [
|
|
426
|
+
{ type: "text", text: message.stopReason === "aborted" ? "Operation aborted" : message.errorMessage || "Error" }
|
|
427
|
+
],
|
|
428
|
+
isError: true
|
|
429
|
+
});
|
|
430
|
+
return {
|
|
431
|
+
onEvent(event) {
|
|
432
|
+
if (disposed) return;
|
|
433
|
+
if (event.type === "message_update" && event.message.role === "assistant") {
|
|
434
|
+
for (const call of event.message.content) {
|
|
435
|
+
if (call.type !== "toolCall") continue;
|
|
436
|
+
updateArgs(call);
|
|
437
|
+
pending.add(call.id);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
if (event.type === "message_end" && event.message.role === "assistant") {
|
|
441
|
+
const failed = event.message.stopReason === "aborted" || event.message.stopReason === "error";
|
|
442
|
+
for (const call of event.message.content) {
|
|
443
|
+
if (call.type !== "toolCall") continue;
|
|
444
|
+
updateArgs(call);
|
|
445
|
+
pending.add(call.id);
|
|
446
|
+
}
|
|
447
|
+
for (const id of pending) {
|
|
448
|
+
const row = rows.get(id);
|
|
449
|
+
if (!row) continue;
|
|
450
|
+
if (failed) result(row, failure(event.message));
|
|
451
|
+
else completeArgs(row);
|
|
452
|
+
}
|
|
453
|
+
if (failed) pending.clear();
|
|
454
|
+
}
|
|
455
|
+
if (event.type === "tool_execution_start" && !("parentToolCallId" in event && event.parentToolCallId)) {
|
|
456
|
+
const row = ensure(event.toolCallId, event.toolName, event.args);
|
|
457
|
+
pending.add(event.toolCallId);
|
|
458
|
+
row.started = true;
|
|
459
|
+
row.component?.markExecutionStarted();
|
|
460
|
+
}
|
|
461
|
+
if (event.type === "tool_execution_update") {
|
|
462
|
+
const row = pending.has(event.toolCallId) ? rows.get(event.toolCallId) : void 0;
|
|
463
|
+
if (row) result(row, { ...event.partialResult, isError: false }, true);
|
|
464
|
+
}
|
|
465
|
+
if (event.type === "tool_execution_end") {
|
|
466
|
+
const row = pending.has(event.toolCallId) ? rows.get(event.toolCallId) : void 0;
|
|
467
|
+
if (row) result(row, { ...event.result, isError: event.isError, durationMs: event.durationMs });
|
|
468
|
+
pending.delete(event.toolCallId);
|
|
469
|
+
}
|
|
470
|
+
if (event.type === "agent_end") pending.clear();
|
|
471
|
+
},
|
|
472
|
+
render(call, message, historyResult, width) {
|
|
473
|
+
const row = ensure(call.id, call.name, call.arguments);
|
|
474
|
+
if (historyResult && row.historyResult !== historyResult) {
|
|
475
|
+
row.historyResult = historyResult;
|
|
476
|
+
result(row, historyResult);
|
|
477
|
+
}
|
|
478
|
+
if (!historyResult && !row.result && (message.stopReason === "aborted" || message.stopReason === "error"))
|
|
479
|
+
result(row, failure(message));
|
|
480
|
+
return row.component?.render(width) ?? [];
|
|
481
|
+
},
|
|
482
|
+
handleMouse(id, event) {
|
|
483
|
+
if (disposed) return void 0;
|
|
484
|
+
return rows.get(id)?.component?.handleMouse(event);
|
|
485
|
+
},
|
|
486
|
+
retain(ids) {
|
|
487
|
+
for (const id of rows.keys())
|
|
488
|
+
if (!ids.has(id)) {
|
|
489
|
+
rows.delete(id);
|
|
490
|
+
pending.delete(id);
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
toggle() {
|
|
494
|
+
if (!disposed) {
|
|
495
|
+
expanded = !expanded;
|
|
496
|
+
for (const row of rows.values()) {
|
|
497
|
+
row.expanded = expanded;
|
|
498
|
+
row.component?.setExpanded(expanded);
|
|
499
|
+
}
|
|
500
|
+
tui.requestRender();
|
|
501
|
+
}
|
|
502
|
+
return expanded;
|
|
503
|
+
},
|
|
504
|
+
invalidate() {
|
|
505
|
+
for (const row of rows.values()) row.component = void 0;
|
|
506
|
+
},
|
|
507
|
+
dispose() {
|
|
508
|
+
disposed = true;
|
|
509
|
+
pending.clear();
|
|
510
|
+
rows.clear();
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// src/settings-chat-transcript.ts
|
|
516
|
+
function createSettingsChatTranscript(agent, tui, cwd, initialExpanded = false, editablePath) {
|
|
517
|
+
const messages = /* @__PURE__ */ new Map();
|
|
518
|
+
const tools = createSettingsChatTools(tui, cwd, initialExpanded, editablePath);
|
|
519
|
+
const identities = /* @__PURE__ */ new WeakMap();
|
|
520
|
+
let streamingIdentity;
|
|
521
|
+
const initial = agent.state.streamingMessage;
|
|
522
|
+
if (initial?.role === "assistant") {
|
|
523
|
+
streamingIdentity = /* @__PURE__ */ Symbol();
|
|
524
|
+
identities.set(initial, streamingIdentity);
|
|
525
|
+
}
|
|
526
|
+
const unsubscribe = agent.subscribe((event) => {
|
|
527
|
+
if (disposed) return;
|
|
528
|
+
tools.onEvent(event);
|
|
529
|
+
if (event.type === "agent_end") streamingIdentity = void 0;
|
|
530
|
+
if ((event.type === "message_start" || event.type === "message_update" || event.type === "message_end") && event.message.role === "assistant") {
|
|
531
|
+
if (event.type === "message_start") streamingIdentity = /* @__PURE__ */ Symbol();
|
|
532
|
+
streamingIdentity ??= /* @__PURE__ */ Symbol();
|
|
533
|
+
identities.set(event.message, streamingIdentity);
|
|
534
|
+
if (event.type === "message_end") streamingIdentity = void 0;
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
let spans = [];
|
|
538
|
+
let toolSpans = [];
|
|
539
|
+
let renderedWidth = 0;
|
|
140
540
|
let streaming;
|
|
141
541
|
let disposed = false;
|
|
142
542
|
return {
|
|
143
543
|
render(width) {
|
|
544
|
+
spans = [];
|
|
545
|
+
toolSpans = [];
|
|
144
546
|
if (disposed || width <= 0) return [];
|
|
145
547
|
const results = new Map(
|
|
146
548
|
agent.state.messages.flatMap(
|
|
@@ -151,81 +553,123 @@ function createSettingsChatTranscript(agent, tui, cwd) {
|
|
|
151
553
|
const activeMessages = /* @__PURE__ */ new Set();
|
|
152
554
|
const activeTools = /* @__PURE__ */ new Set();
|
|
153
555
|
const lines = [];
|
|
556
|
+
renderedWidth = width;
|
|
557
|
+
const recordSpan = (message, start) => {
|
|
558
|
+
let offset = 0;
|
|
559
|
+
let text = "";
|
|
560
|
+
const offsets = lines.slice(start).map((line) => {
|
|
561
|
+
const before = offset;
|
|
562
|
+
const content = stripVTControlCharacters(line).replace(/\s/gu, "");
|
|
563
|
+
text += content;
|
|
564
|
+
offset += content.length;
|
|
565
|
+
return before;
|
|
566
|
+
});
|
|
567
|
+
spans.push({ message, start, end: lines.length, offsets, text });
|
|
568
|
+
};
|
|
154
569
|
const appendAssistant = (message, component) => {
|
|
155
570
|
lines.push(...component.render(width));
|
|
156
571
|
for (const call of message.content) {
|
|
157
572
|
if (call.type !== "toolCall") continue;
|
|
158
573
|
activeTools.add(call.id);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const component2 = new ToolExecutionComponent(
|
|
163
|
-
sanitizeTerminalDocument(call.name),
|
|
164
|
-
sanitizeTerminalDocument(call.id),
|
|
165
|
-
displayValue(call.arguments),
|
|
166
|
-
{ showImages: false, outputPad: 1 },
|
|
167
|
-
definition,
|
|
168
|
-
tui,
|
|
169
|
-
sanitizeTerminalDocument(cwd)
|
|
170
|
-
);
|
|
171
|
-
component2.setExpanded(true);
|
|
172
|
-
component2.setArgsComplete();
|
|
173
|
-
component2.markExecutionStarted();
|
|
174
|
-
tool = { component: component2 };
|
|
175
|
-
tools.set(call.id, tool);
|
|
176
|
-
}
|
|
177
|
-
const result = results.get(call.id);
|
|
178
|
-
if (result && tool.result !== result) {
|
|
179
|
-
tool.component.updateResult({
|
|
180
|
-
content: displayValue(result.content),
|
|
181
|
-
details: displayValue(result.details),
|
|
182
|
-
isError: result.isError,
|
|
183
|
-
durationMs: result.durationMs
|
|
184
|
-
});
|
|
185
|
-
tool.result = result;
|
|
186
|
-
}
|
|
187
|
-
lines.push(...tool.component.render(width));
|
|
574
|
+
const start = lines.length;
|
|
575
|
+
lines.push(...tools.render(call, message, results.get(call.id), width));
|
|
576
|
+
toolSpans.push({ id: call.id, start, end: lines.length });
|
|
188
577
|
}
|
|
189
578
|
};
|
|
190
579
|
for (const message of visible) {
|
|
191
580
|
activeMessages.add(message);
|
|
581
|
+
let start = lines.length;
|
|
192
582
|
let component = messages.get(message);
|
|
193
583
|
if (message.role === "user") {
|
|
194
584
|
if (lines.length) lines.push("");
|
|
585
|
+
start = lines.length;
|
|
195
586
|
if (!component) {
|
|
196
587
|
const text = typeof message.content === "string" ? message.content : message.content.filter((part) => part.type === "text").map((part) => part.text).join("\n");
|
|
197
|
-
component = new UserMessageComponent(
|
|
588
|
+
component = new UserMessageComponent(sanitizeTerminalDocument3(text));
|
|
198
589
|
messages.set(message, component);
|
|
199
590
|
}
|
|
200
591
|
lines.push(...component.render(width));
|
|
201
592
|
} else if (message.role === "assistant") {
|
|
202
593
|
if (!component) {
|
|
203
|
-
component = new AssistantMessageComponent(
|
|
594
|
+
component = new AssistantMessageComponent(settingsChatDisplayValue(message), true);
|
|
204
595
|
messages.set(message, component);
|
|
205
596
|
}
|
|
206
597
|
appendAssistant(message, component);
|
|
207
598
|
}
|
|
599
|
+
recordSpan(identities.get(message) ?? message, start);
|
|
208
600
|
}
|
|
209
601
|
const partial = agent.state.streamingMessage;
|
|
210
602
|
if (partial?.role === "assistant") {
|
|
211
603
|
streaming ??= new AssistantMessageComponent(void 0, true);
|
|
212
|
-
streaming.updateContent(
|
|
213
|
-
lines.
|
|
604
|
+
streaming.updateContent(settingsChatDisplayValue(partial), true);
|
|
605
|
+
const start = lines.length;
|
|
606
|
+
appendAssistant(partial, streaming);
|
|
607
|
+
recordSpan(identities.get(partial) ?? partial, start);
|
|
214
608
|
} else streaming = void 0;
|
|
215
609
|
for (const message of messages.keys()) if (!activeMessages.has(message)) messages.delete(message);
|
|
216
|
-
|
|
610
|
+
tools.retain(activeTools);
|
|
217
611
|
return lines;
|
|
218
612
|
},
|
|
613
|
+
handleMouse(event) {
|
|
614
|
+
if (disposed) return void 0;
|
|
615
|
+
const span = toolSpans.find((item) => event.y >= item.start && event.y < item.end);
|
|
616
|
+
return span ? tools.handleMouse(span.id, { ...event, y: event.y - span.start, height: span.end - span.start }) : void 0;
|
|
617
|
+
},
|
|
618
|
+
anchorAt(row) {
|
|
619
|
+
const span = spans.find((item) => row < item.end);
|
|
620
|
+
return span ? {
|
|
621
|
+
message: span.message,
|
|
622
|
+
row: row - span.start,
|
|
623
|
+
width: renderedWidth,
|
|
624
|
+
offset: span.offsets[Math.max(0, row - span.start)] ?? 0,
|
|
625
|
+
text: span.text.slice(
|
|
626
|
+
span.offsets[Math.max(0, row - span.start)] ?? 0,
|
|
627
|
+
span.offsets[Math.max(0, row - span.start) + 1]
|
|
628
|
+
)
|
|
629
|
+
} : void 0;
|
|
630
|
+
},
|
|
631
|
+
rowAt(anchor) {
|
|
632
|
+
const span = spans.find((item) => item.message === anchor.message);
|
|
633
|
+
if (!span) return 0;
|
|
634
|
+
let row = anchor.row;
|
|
635
|
+
const currentText = span.text.slice(span.offsets[Math.max(0, row)], span.offsets[Math.max(0, row) + 1]);
|
|
636
|
+
if (anchor.width !== renderedWidth || currentText !== anchor.text) {
|
|
637
|
+
let offset = anchor.offset;
|
|
638
|
+
if (anchor.text) {
|
|
639
|
+
let match = span.text.indexOf(anchor.text);
|
|
640
|
+
let best = -1;
|
|
641
|
+
while (match >= 0) {
|
|
642
|
+
if (best < 0 || Math.abs(match - anchor.offset) < Math.abs(best - anchor.offset)) best = match;
|
|
643
|
+
match = span.text.indexOf(anchor.text, match + 1);
|
|
644
|
+
}
|
|
645
|
+
if (best >= 0) offset = best;
|
|
646
|
+
}
|
|
647
|
+
row = 0;
|
|
648
|
+
for (let index = 0; index < span.offsets.length; index++) {
|
|
649
|
+
if (span.offsets[index] > offset) break;
|
|
650
|
+
row = index;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return Math.max(0, span.start + Math.min(row, span.end - span.start - 1));
|
|
654
|
+
},
|
|
655
|
+
toggleTools() {
|
|
656
|
+
return tools.toggle();
|
|
657
|
+
},
|
|
219
658
|
invalidate() {
|
|
220
659
|
if (disposed) return;
|
|
221
660
|
messages.clear();
|
|
222
|
-
tools.
|
|
661
|
+
tools.invalidate();
|
|
223
662
|
streaming = void 0;
|
|
224
663
|
},
|
|
225
664
|
dispose() {
|
|
665
|
+
if (disposed) return;
|
|
226
666
|
disposed = true;
|
|
667
|
+
unsubscribe();
|
|
668
|
+
streamingIdentity = void 0;
|
|
669
|
+
spans = [];
|
|
670
|
+
toolSpans = [];
|
|
227
671
|
messages.clear();
|
|
228
|
-
tools.
|
|
672
|
+
tools.dispose();
|
|
229
673
|
streaming = void 0;
|
|
230
674
|
}
|
|
231
675
|
};
|
|
@@ -240,28 +684,23 @@ function saveKeyReserved(data, keybindings) {
|
|
|
240
684
|
const editorKeys = getKeybindings();
|
|
241
685
|
return Object.keys(TUI_KEYBINDINGS).some(
|
|
242
686
|
(action) => editorKeys.matches(data, action) || keybindings.matches(data, action)
|
|
243
|
-
) || [
|
|
687
|
+
) || [
|
|
688
|
+
"app.clipboard.pasteImage",
|
|
689
|
+
"app.interrupt",
|
|
690
|
+
"app.exit",
|
|
691
|
+
"app.message.followUp",
|
|
692
|
+
"app.message.dequeue",
|
|
693
|
+
"app.tools.expand"
|
|
694
|
+
].some((action) => keybindings.matches(data, action));
|
|
244
695
|
}
|
|
245
696
|
function settingsChatSaveShortcut(keybindings) {
|
|
246
697
|
return SAVE_SHORTCUTS.find(({ key, inputs }) => {
|
|
247
|
-
const matching = inputs.filter((data) =>
|
|
698
|
+
const matching = inputs.filter((data) => matchesKey2(data, key));
|
|
248
699
|
return matching.length > 0 && matching.every((data) => !saveKeyReserved(data, keybindings));
|
|
249
700
|
})?.key;
|
|
250
701
|
}
|
|
251
|
-
function renderSettingsChatPreview(width, preview, theme) {
|
|
252
|
-
if (width <= 0) return [];
|
|
253
|
-
const ruleStyle = (text) => theme.fg("border", text);
|
|
254
|
-
const top = new HorizontalRule({
|
|
255
|
-
label: "Preview",
|
|
256
|
-
labelAlignment: "left",
|
|
257
|
-
ruleStyle,
|
|
258
|
-
labelStyle: (text) => theme.fg("dim", text)
|
|
259
|
-
});
|
|
260
|
-
const bottom = new HorizontalRule({ ruleStyle });
|
|
261
|
-
return [top.render(width)[0] ?? "", ...preview, bottom.render(width)[0] ?? ""];
|
|
262
|
-
}
|
|
263
702
|
var SettingsChatEditor = class extends CustomEditor {
|
|
264
|
-
constructor(tui, chromeTheme, labels,
|
|
703
|
+
constructor(tui, chromeTheme, labels, chatKeys) {
|
|
265
704
|
super(
|
|
266
705
|
tui,
|
|
267
706
|
{
|
|
@@ -274,7 +713,7 @@ var SettingsChatEditor = class extends CustomEditor {
|
|
|
274
713
|
noMatch: (text) => chromeTheme.fg("warning", text)
|
|
275
714
|
}
|
|
276
715
|
},
|
|
277
|
-
|
|
716
|
+
chatKeys
|
|
278
717
|
);
|
|
279
718
|
this.chromeTheme = chromeTheme;
|
|
280
719
|
this.labels = labels;
|
|
@@ -300,28 +739,28 @@ var SettingsChatEditor = class extends CustomEditor {
|
|
|
300
739
|
}).render(width)[0] ?? "";
|
|
301
740
|
}
|
|
302
741
|
};
|
|
303
|
-
|
|
742
|
+
var ROOT_VIEWPORT_ACTIONS = [
|
|
743
|
+
"tui.altScreen.search",
|
|
744
|
+
"tui.altScreen.pageUp",
|
|
745
|
+
"tui.altScreen.pageDown",
|
|
746
|
+
"tui.altScreen.halfPageUp",
|
|
747
|
+
"tui.altScreen.halfPageDown",
|
|
748
|
+
"tui.altScreen.lineUp",
|
|
749
|
+
"tui.altScreen.lineDown",
|
|
750
|
+
"tui.altScreen.previousPrompt",
|
|
751
|
+
"tui.altScreen.nextPrompt",
|
|
752
|
+
"tui.altScreen.top",
|
|
753
|
+
"tui.altScreen.bottom"
|
|
754
|
+
];
|
|
755
|
+
function settingsChatStopInput(data, keybindings) {
|
|
304
756
|
const editorKeys = getKeybindings();
|
|
305
757
|
const parsed = parseKey(data);
|
|
306
758
|
const textKey = parsed?.startsWith("shift+") ? parsed.slice(6) : parsed;
|
|
307
759
|
const printable = data.charCodeAt(0) >= 32 || textKey !== void 0 && (Array.from(textKey).length === 1 || textKey === "space");
|
|
308
|
-
const nativeEditing = printable ||
|
|
760
|
+
const nativeEditing = printable || matchesKey2(data, "shift+backspace") || matchesKey2(data, "shift+delete") || data.charCodeAt(0) === 10 || data === "\x1B\r" || data === "\x1B[13;2~" || data.includes("\x1B") && data.includes("\r");
|
|
309
761
|
const editing = nativeEditing || Object.keys(TUI_KEYBINDINGS).filter((key) => key.startsWith("tui.editor.") || key.startsWith("tui.input.")).some((key) => editorKeys.matches(data, key));
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
function settingsChatTranscript(agent) {
|
|
313
|
-
return [...agent.state.messages, ...agent.state.streamingMessage ? [agent.state.streamingMessage] : []].filter((message) => message.role !== "system").flatMap((message) => {
|
|
314
|
-
if (!("content" in message) || !Array.isArray(message.content)) return [];
|
|
315
|
-
const label = message.role === "user" ? "You" : message.role === "assistant" ? "Agent" : "Tool";
|
|
316
|
-
const text = message.content.map((part) => {
|
|
317
|
-
if (part.type === "text") return part.text;
|
|
318
|
-
if (part.type === "toolCall") return `Using ${part.name}\u2026`;
|
|
319
|
-
return "";
|
|
320
|
-
}).filter(Boolean).join("\n");
|
|
321
|
-
const error = message.role === "assistant" ? message.errorMessage : void 0;
|
|
322
|
-
const output = [text, error].filter(Boolean).join("\n");
|
|
323
|
-
return output ? [`${label}: ${sanitizeTerminalDocument2(output)}`] : [];
|
|
324
|
-
});
|
|
762
|
+
const viewport = ROOT_VIEWPORT_ACTIONS.some((action) => editorKeys.matches(data, action));
|
|
763
|
+
return !viewport && !editing && (keybindings.matches(data, "tui.select.cancel") || matchesKey2(data, Key.escape));
|
|
325
764
|
}
|
|
326
765
|
function createSettingsChatComponent(options) {
|
|
327
766
|
const { agent, draft, state, tui, theme, keybindings, signal } = options;
|
|
@@ -336,9 +775,10 @@ function createSettingsChatComponent(options) {
|
|
|
336
775
|
() => {
|
|
337
776
|
const status = state.error || agent.state.errorMessage ? "Agent error" : !draft.candidate ? "Invalid" : draft.diagnostics ? "Warnings" : "Valid";
|
|
338
777
|
const saveKey = !pending && !inPaste && draft.candidate ? settingsChatSaveShortcut(keybindings) : void 0;
|
|
778
|
+
const working = !inPaste && settingsChatStopInput("\x1B", keybindings) ? "Working \xB7 esc to interrupt" : "Working";
|
|
339
779
|
return {
|
|
340
780
|
top: queued.length > 0 ? `pi-starship \xB7 ${queued.length} queued` : "pi-starship",
|
|
341
|
-
bottom: `${status} \xB7 unsaved \xB7 ${pending ?
|
|
781
|
+
bottom: `${status} \xB7 unsaved \xB7 ${pending ? working : saveKey ? `${saveKey} to save profile` : "Idle"} \xB7 ctrl+c to discard`
|
|
342
782
|
};
|
|
343
783
|
},
|
|
344
784
|
keybindings
|
|
@@ -347,6 +787,13 @@ function createSettingsChatComponent(options) {
|
|
|
347
787
|
const render = () => {
|
|
348
788
|
if (!disposed && !signal.aborted) tui.requestRender();
|
|
349
789
|
};
|
|
790
|
+
const transcript = createSettingsChatTranscript(
|
|
791
|
+
agent,
|
|
792
|
+
tui,
|
|
793
|
+
draft.directory,
|
|
794
|
+
state.toolsExpanded ?? false,
|
|
795
|
+
draft.path
|
|
796
|
+
);
|
|
350
797
|
const unsubscribe = agent.subscribe((event) => {
|
|
351
798
|
if (event.type === "message_start") {
|
|
352
799
|
const index = queued.findIndex((item) => item.message === event.message);
|
|
@@ -373,7 +820,6 @@ function createSettingsChatComponent(options) {
|
|
|
373
820
|
};
|
|
374
821
|
signal.addEventListener("abort", abort, { once: true });
|
|
375
822
|
const rule = new HorizontalRule({ ruleStyle: (text) => theme.fg("border", text) });
|
|
376
|
-
const transcript = createSettingsChatTranscript(agent, tui, draft.directory);
|
|
377
823
|
const failed = () => {
|
|
378
824
|
const last = agent.state.messages.at(-1);
|
|
379
825
|
return last?.role === "assistant" && (last.stopReason === "error" || last.stopReason === "aborted");
|
|
@@ -416,24 +862,21 @@ function createSettingsChatComponent(options) {
|
|
|
416
862
|
editor.onSubmit = (input) => submit(input, "steer");
|
|
417
863
|
editor.onAction("app.message.followUp", () => submit(editor.getExpandedText().trim(), "followUp"));
|
|
418
864
|
editor.onAction("app.message.dequeue", restoreQueue);
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
set focused(value) {
|
|
424
|
-
editor.focused = value;
|
|
425
|
-
},
|
|
865
|
+
editor.onAction("app.tools.expand", () => {
|
|
866
|
+
state.toolsExpanded = transcript.toggleTools();
|
|
867
|
+
});
|
|
868
|
+
const dock = {
|
|
426
869
|
render(width) {
|
|
427
870
|
if (disposed || signal.aborted || width <= 0) return [];
|
|
428
871
|
const rows = Math.max(0, Math.floor(Number.isFinite(tui.terminal.rows) ? tui.terminal.rows : 24));
|
|
429
872
|
if (rows === 0) return [];
|
|
430
|
-
const input = editor.render(width);
|
|
873
|
+
const input = editor.render(Math.max(3, width)).map((line) => truncateToWidth(line, width, ""));
|
|
431
874
|
const cursor = Math.max(
|
|
432
875
|
0,
|
|
433
876
|
input.findIndex((line) => line.includes(CURSOR_MARKER))
|
|
434
877
|
);
|
|
435
878
|
const preview = options.preview(width);
|
|
436
|
-
const diagnostics =
|
|
879
|
+
const diagnostics = sanitizeTerminalDocument4(state.error || agent.state.errorMessage || draft.diagnostics).split("\n").filter(Boolean).slice(0, 3);
|
|
437
880
|
const details = diagnostics.map((line) => theme.fg("muted", line));
|
|
438
881
|
if (input.length + preview.length > rows) {
|
|
439
882
|
return renderBoundedFrame({
|
|
@@ -453,40 +896,73 @@ function createSettingsChatComponent(options) {
|
|
|
453
896
|
].slice(0, Math.min(3, rows - input.length - preview.length - detailLines.length)).map(
|
|
454
897
|
(item) => theme.fg(
|
|
455
898
|
"dim",
|
|
456
|
-
`${item.kind === "steer" ? "Steering" : "Follow-up"}: ${
|
|
899
|
+
`${item.kind === "steer" ? "Steering" : "Follow-up"}: ${sanitizeTerminalDocument4(item.text).replace(/\n/gu, " ")}`
|
|
457
900
|
)
|
|
458
901
|
);
|
|
459
902
|
const content = [...queueLines, ...input, ...detailLines, ...preview];
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
903
|
+
return content.map((line) => truncateToWidth(line, width, ""));
|
|
904
|
+
},
|
|
905
|
+
invalidate() {
|
|
906
|
+
editor.invalidate();
|
|
907
|
+
}
|
|
908
|
+
};
|
|
909
|
+
const history = {
|
|
910
|
+
render(width) {
|
|
911
|
+
scroll.anchor = scroll.isFollowingEnd ? void 0 : transcript.anchorAt(scroll.scrollTop);
|
|
912
|
+
return transcript.render(width);
|
|
913
|
+
},
|
|
914
|
+
invalidate() {
|
|
915
|
+
transcript.invalidate();
|
|
916
|
+
},
|
|
917
|
+
handleMouse: (event) => transcript.handleMouse(event)
|
|
918
|
+
};
|
|
919
|
+
const scroll = new SettingsChatScrollView(history, {
|
|
920
|
+
primary: true,
|
|
921
|
+
follow: "end",
|
|
922
|
+
scrollbar: "auto",
|
|
923
|
+
scrollbarTrackStyle: (text) => theme.fg("scrollbarTrack", text),
|
|
924
|
+
scrollbarThumbStyle: (text) => theme.fg("scrollbarThumb", text)
|
|
925
|
+
});
|
|
926
|
+
scroll.restoreAnchor = (anchor) => transcript.rowAt(anchor);
|
|
927
|
+
const layout = new VStack([
|
|
928
|
+
{ component: scroll, basis: 0, grow: 1, minSize: 0 },
|
|
929
|
+
{ component: dock, basis: "auto", shrink: 1, minSize: 1 }
|
|
930
|
+
]);
|
|
931
|
+
return {
|
|
932
|
+
getFullscreenLayout() {
|
|
933
|
+
return layout;
|
|
934
|
+
},
|
|
935
|
+
get focused() {
|
|
936
|
+
return editor.focused;
|
|
937
|
+
},
|
|
938
|
+
set focused(value) {
|
|
939
|
+
editor.focused = value;
|
|
940
|
+
},
|
|
941
|
+
render(width) {
|
|
942
|
+
if (disposed || signal.aborted || width <= 0 || tui.terminal.rows <= 0) return [];
|
|
943
|
+
return layout.render(width);
|
|
465
944
|
},
|
|
466
945
|
invalidate() {
|
|
467
946
|
editor.invalidate();
|
|
468
947
|
transcript.invalidate();
|
|
469
948
|
},
|
|
470
949
|
handleInput(data) {
|
|
471
|
-
if (disposed || signal.aborted ||
|
|
950
|
+
if (disposed || signal.aborted || isKeyRelease2(data)) return;
|
|
472
951
|
const saveKey = !pending && draft.candidate ? settingsChatSaveShortcut(keybindings) : void 0;
|
|
473
952
|
if (inPaste || data.includes("\x1B[200~")) {
|
|
474
953
|
inPaste = !data.includes("\x1B[201~");
|
|
475
954
|
editor.handlePasteInput(data);
|
|
476
|
-
} else if (
|
|
955
|
+
} else if (matchesKey2(data, Key.ctrl("c"))) {
|
|
477
956
|
abort();
|
|
478
957
|
options.complete("discard");
|
|
479
|
-
} else if (saveKey &&
|
|
958
|
+
} else if (saveKey && matchesKey2(data, saveKey) && !saveKeyReserved(data, keybindings)) {
|
|
480
959
|
state.input = editor.getExpandedText();
|
|
481
960
|
options.complete("save");
|
|
482
|
-
} else if (
|
|
961
|
+
} else if (settingsChatStopInput(data, keybindings)) {
|
|
483
962
|
if (pending) {
|
|
484
963
|
stopping = true;
|
|
485
964
|
restoreQueue();
|
|
486
965
|
agent.abort();
|
|
487
|
-
} else {
|
|
488
|
-
state.input = editor.getExpandedText();
|
|
489
|
-
options.complete("review");
|
|
490
966
|
}
|
|
491
967
|
} else editor.handleInput(data);
|
|
492
968
|
render();
|
|
@@ -498,6 +974,8 @@ function createSettingsChatComponent(options) {
|
|
|
498
974
|
signal.removeEventListener("abort", abort);
|
|
499
975
|
unsubscribe();
|
|
500
976
|
transcript.dispose();
|
|
977
|
+
scroll.setScrollbarActive(false);
|
|
978
|
+
scroll.setScrollbar("hidden");
|
|
501
979
|
abort();
|
|
502
980
|
},
|
|
503
981
|
async waitForPending() {
|
|
@@ -507,33 +985,13 @@ function createSettingsChatComponent(options) {
|
|
|
507
985
|
};
|
|
508
986
|
}
|
|
509
987
|
async function showSettingsChat(ctx, agent, draft, state, owner, preview) {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
})
|
|
518
|
-
}
|
|
519
|
-
};
|
|
520
|
-
const result = await runCustomInteraction(fullscreenContext, {
|
|
521
|
-
signal: owner.signal,
|
|
522
|
-
isCurrent: owner.isCurrent,
|
|
523
|
-
create: ({ tui, theme, keybindings, signal, complete }) => createSettingsChatComponent({
|
|
524
|
-
agent,
|
|
525
|
-
draft,
|
|
526
|
-
state,
|
|
527
|
-
tui,
|
|
528
|
-
theme,
|
|
529
|
-
keybindings,
|
|
530
|
-
signal,
|
|
531
|
-
preview,
|
|
532
|
-
complete
|
|
533
|
-
})
|
|
534
|
-
});
|
|
535
|
-
if (result.kind === "error") throw result.error;
|
|
536
|
-
return result.kind === "completed" ? result.value : "discard";
|
|
988
|
+
state.toolsExpanded ??= ctx.ui.getToolsExpanded?.() ?? false;
|
|
989
|
+
return runSettingsChatFullscreen(
|
|
990
|
+
ctx,
|
|
991
|
+
owner,
|
|
992
|
+
({ tui, theme, keybindings, signal, complete }) => createSettingsChatComponent({ agent, draft, state, tui, theme, keybindings, signal, preview, complete }),
|
|
993
|
+
"discard"
|
|
994
|
+
);
|
|
537
995
|
}
|
|
538
996
|
|
|
539
997
|
// src/settings-draft.ts
|
|
@@ -550,7 +1008,7 @@ import {
|
|
|
550
1008
|
writeFileSync
|
|
551
1009
|
} from "node:fs";
|
|
552
1010
|
import { tmpdir } from "node:os";
|
|
553
|
-
import { isAbsolute, join as join2, relative, resolve } from "node:path";
|
|
1011
|
+
import { isAbsolute, join as join2, relative, resolve as resolve2 } from "node:path";
|
|
554
1012
|
import {
|
|
555
1013
|
createEditTool,
|
|
556
1014
|
createReadTool,
|
|
@@ -580,7 +1038,7 @@ function createSettingsDraft(options) {
|
|
|
580
1038
|
};
|
|
581
1039
|
const assertDraft = (target) => {
|
|
582
1040
|
assertCurrent();
|
|
583
|
-
if (
|
|
1041
|
+
if (resolve2(target) !== path || realpathSync(directory) !== directory || realpathSync(path) !== path) {
|
|
584
1042
|
throw new Error("Only the owned settings draft can be changed");
|
|
585
1043
|
}
|
|
586
1044
|
};
|
|
@@ -625,13 +1083,13 @@ function createSettingsDraft(options) {
|
|
|
625
1083
|
}
|
|
626
1084
|
const readAllowed = (target) => {
|
|
627
1085
|
assertCurrent();
|
|
628
|
-
if (
|
|
1086
|
+
if (resolve2(target) === resolve2(options.settingsPath)) {
|
|
629
1087
|
if (!baseline) throw new Error("The active settings file was missing when this preview started");
|
|
630
1088
|
return Buffer.from(baseline);
|
|
631
1089
|
}
|
|
632
|
-
if (
|
|
633
|
-
if (snapshots.has(
|
|
634
|
-
const content = snapshots.get(
|
|
1090
|
+
if (resolve2(target) === path) return readDraft();
|
|
1091
|
+
if (snapshots.has(resolve2(target))) {
|
|
1092
|
+
const content = snapshots.get(resolve2(target));
|
|
635
1093
|
if (content === void 0)
|
|
636
1094
|
throw new Error(
|
|
637
1095
|
"No exact loaded settings document is available; read active-state.json for its source and diagnostics"
|
|
@@ -870,10 +1328,12 @@ async function showSettingsAgentChat(ctx, options, base) {
|
|
|
870
1328
|
return captureCommitExpectation(options);
|
|
871
1329
|
});
|
|
872
1330
|
if (!expected || base.signal.aborted || !base.isCurrent()) return "close";
|
|
1331
|
+
const chatLifetime = new AbortController();
|
|
873
1332
|
const owner = {
|
|
874
|
-
signal: base.signal,
|
|
875
|
-
isCurrent: () => commitOwnerCurrent(options, base, expected),
|
|
876
|
-
isSessionCurrent: base.isSessionCurrent ?? base.isCurrent
|
|
1333
|
+
signal: AbortSignal.any([base.signal, chatLifetime.signal]),
|
|
1334
|
+
isCurrent: () => !chatLifetime.signal.aborted && commitOwnerCurrent(options, base, expected),
|
|
1335
|
+
isSessionCurrent: base.isSessionCurrent ?? base.isCurrent,
|
|
1336
|
+
canRestoreTerminal: base.canRestoreTerminal
|
|
877
1337
|
};
|
|
878
1338
|
const packageRoot = starshipPackageRoot();
|
|
879
1339
|
const draft = createSettingsDraft({
|
|
@@ -888,12 +1348,15 @@ async function showSettingsAgentChat(ctx, options, base) {
|
|
|
888
1348
|
});
|
|
889
1349
|
let agent;
|
|
890
1350
|
let closing;
|
|
1351
|
+
let activeChat;
|
|
891
1352
|
const cleanup = () => {
|
|
892
1353
|
if (closing) return closing;
|
|
1354
|
+
chatLifetime.abort();
|
|
893
1355
|
agent?.abort();
|
|
1356
|
+
const pendingChat = activeChat;
|
|
894
1357
|
closing = (async () => {
|
|
895
1358
|
try {
|
|
896
|
-
await agent?.waitForIdle();
|
|
1359
|
+
await Promise.all([agent?.waitForIdle(), pendingChat]);
|
|
897
1360
|
} finally {
|
|
898
1361
|
agent?.reset();
|
|
899
1362
|
draft.dispose();
|
|
@@ -915,42 +1378,15 @@ async function showSettingsAgentChat(ctx, options, base) {
|
|
|
915
1378
|
if (!owner.isCurrent()) return "close";
|
|
916
1379
|
agent = createSettingsAgent(ctx, draft, packageRoot);
|
|
917
1380
|
while (owner.isCurrent()) {
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
"The agent has not changed the active settings file.",
|
|
925
|
-
"Preview uses cached data; enabling modules here does not run commands or network requests.",
|
|
926
|
-
...renderSettingsChatPreview(width, preview(width), theme),
|
|
927
|
-
...sanitizeTerminalDocument3(draft.diagnostics).split("\n")
|
|
928
|
-
],
|
|
929
|
-
[
|
|
930
|
-
{ value: "continue", label: "Continue conversation" },
|
|
931
|
-
{ value: "document", label: "Review exact draft\u2026" },
|
|
932
|
-
{ value: "transcript", label: "Review full conversation\u2026" },
|
|
933
|
-
...draft.candidate ? [{ value: "save", label: "Save draft as profile\u2026" }] : [],
|
|
934
|
-
{ value: "discard", label: "Discard preview and close" }
|
|
935
|
-
],
|
|
936
|
-
owner.signal,
|
|
937
|
-
owner.isCurrent
|
|
938
|
-
);
|
|
939
|
-
if (!owner.isCurrent() || !result || result.kind === "closed") return "close";
|
|
940
|
-
if (result?.kind !== "selected") continue;
|
|
941
|
-
if (result.value === "discard") return "close";
|
|
942
|
-
if (result.value === "document" || result.value === "transcript") {
|
|
943
|
-
const reviewed2 = await reviewText(
|
|
944
|
-
ctx,
|
|
945
|
-
owner,
|
|
946
|
-
result.value === "document" ? "Settings draft" : "Configuration conversation",
|
|
947
|
-
result.value === "document" ? draft.rawDocument : settingsChatTranscript(agent).join("\n\n"),
|
|
948
|
-
result.value === "document"
|
|
949
|
-
);
|
|
950
|
-
if (!owner.isCurrent() || !reviewed2) return "close";
|
|
951
|
-
continue;
|
|
1381
|
+
activeChat = showSettingsChat(ctx, agent, draft, state, owner, preview);
|
|
1382
|
+
let action;
|
|
1383
|
+
try {
|
|
1384
|
+
action = await activeChat;
|
|
1385
|
+
} finally {
|
|
1386
|
+
activeChat = void 0;
|
|
952
1387
|
}
|
|
953
|
-
if (
|
|
1388
|
+
if (!owner.isCurrent() || action === "discard") return "close";
|
|
1389
|
+
if (!draft.candidate) continue;
|
|
954
1390
|
const candidate = draft.candidate;
|
|
955
1391
|
const revision = draft.revision;
|
|
956
1392
|
const reviewed = await reviewText(ctx, owner, "Review draft before saving", candidate.rawDocument ?? "", true);
|
|
@@ -969,7 +1405,7 @@ async function showSettingsAgentChat(ctx, options, base) {
|
|
|
969
1405
|
const confirmed = await ctx.ui.confirm(
|
|
970
1406
|
"Apply saved profile?",
|
|
971
1407
|
[
|
|
972
|
-
`Profile saved: ${
|
|
1408
|
+
`Profile saved: ${sanitizeTerminalDocument5(saved.name)}. Apply it to the current footer without reload?`,
|
|
973
1409
|
"This replaces the complete active settings document. Declining keeps the profile and leaves active settings unchanged.",
|
|
974
1410
|
"Applying can run enabled module commands and network requests; review their configuration before accepting.",
|
|
975
1411
|
"The previous file is retained in History. Detected concurrent edits block replacement.",
|
|
@@ -981,16 +1417,16 @@ async function showSettingsAgentChat(ctx, options, base) {
|
|
|
981
1417
|
if (!owner.isCurrent()) return "close";
|
|
982
1418
|
if (!confirmed) return "close";
|
|
983
1419
|
try {
|
|
984
|
-
const
|
|
1420
|
+
const result = await commitActiveDocument(ctx, options, candidate, owner, expected, repair, () => {
|
|
985
1421
|
draft.assertRevision(revision);
|
|
986
1422
|
assertProfileUnchanged(options.settingsPath, saved);
|
|
987
1423
|
});
|
|
988
|
-
if (
|
|
1424
|
+
if (result === "applied") return "applied";
|
|
989
1425
|
return "close";
|
|
990
1426
|
} catch (error) {
|
|
991
1427
|
if (!base.signal.aborted && base.isCurrent())
|
|
992
1428
|
ctx.ui.notify(
|
|
993
|
-
`Profile was saved as ${
|
|
1429
|
+
`Profile was saved as ${sanitizeTerminalDocument5(saved.name)}. Settings were not applied: ${sanitizeTerminalDocument5(error instanceof Error ? error.message : String(error))}`,
|
|
994
1430
|
"error"
|
|
995
1431
|
);
|
|
996
1432
|
}
|
|
@@ -1038,4 +1474,4 @@ async function reviewText(ctx, owner, title, content, toml) {
|
|
|
1038
1474
|
export {
|
|
1039
1475
|
showSettingsAgentChat
|
|
1040
1476
|
};
|
|
1041
|
-
//# sourceMappingURL=command-settings-chat-
|
|
1477
|
+
//# sourceMappingURL=command-settings-chat-KLUVZXMO.ts.map
|