@narumitw/pi-starship 0.62.0 → 0.63.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 +10 -9
- package/dist/chunks/{chunk-HPZTMIZS.ts → chunk-63R6R5DH.ts} +41 -8
- package/dist/chunks/chunk-63R6R5DH.ts.map +7 -0
- package/dist/chunks/{chunk-PWTSHSP3.ts → chunk-A65IOGL6.ts} +6 -7
- package/dist/chunks/chunk-A65IOGL6.ts.map +7 -0
- package/dist/chunks/{chunk-43VIENBN.ts → chunk-Y24TJYG6.ts} +7 -7
- package/dist/chunks/{chunk-43VIENBN.ts.map → chunk-Y24TJYG6.ts.map} +2 -2
- package/dist/chunks/{command-configuration-menu-S2LXCOJG.ts → command-configuration-menu-YOLN2SPR.ts} +3 -3
- package/dist/chunks/{command-settings-chat-O34BEU4X.ts → command-settings-chat-5AHP3JGV.ts} +162 -79
- package/dist/chunks/command-settings-chat-5AHP3JGV.ts.map +7 -0
- package/dist/chunks/{commands-ZYIJVIEJ.ts → commands-IOG2PL67.ts} +23 -19
- package/dist/chunks/commands-IOG2PL67.ts.map +7 -0
- package/dist/index.ts +114 -58
- 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 +6 -10
- package/src/command-settings-chat.ts +2 -44
- package/src/commands.ts +22 -26
- package/src/config.ts +6 -6
- package/src/pi-starship.ts +154 -88
- package/src/settings-chat-transcript.ts +54 -2
- package/src/settings-chat-ui.ts +150 -50
- 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-YOLN2SPR.ts.map} +0 -0
package/src/pi-starship.ts
CHANGED
|
@@ -95,6 +95,9 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
95
95
|
let chatCleanup: (() => Promise<void>) | undefined;
|
|
96
96
|
let sessionOwner: ExtensionContext["sessionManager"] | undefined;
|
|
97
97
|
let activeTarget: RefreshTarget | undefined;
|
|
98
|
+
let footerContext: ExtensionContext | undefined;
|
|
99
|
+
let disposeFooter: (() => void) | undefined;
|
|
100
|
+
let footerCollecting = false;
|
|
98
101
|
let eventDebounceTimer: ReturnType<typeof setTimeout> | undefined;
|
|
99
102
|
let githubPrRefreshTimer: ReturnType<typeof setInterval> | undefined;
|
|
100
103
|
let githubPrExpiryTimer: ReturnType<typeof setTimeout> | undefined;
|
|
@@ -166,20 +169,22 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
166
169
|
clearTimeout(eventDebounceTimer);
|
|
167
170
|
eventDebounceTimer = undefined;
|
|
168
171
|
};
|
|
169
|
-
const isActiveTarget = (target: RefreshTarget) =>
|
|
170
|
-
activeTarget?.cwd === target.cwd &&
|
|
171
|
-
activeTarget.generation === target.generation &&
|
|
172
|
-
activeTarget.sessionManager === target.sessionManager &&
|
|
173
|
-
target.generation === sessionGeneration;
|
|
172
|
+
const isActiveTarget = (target: RefreshTarget) => activeTarget === target && target.generation === sessionGeneration;
|
|
174
173
|
|
|
175
174
|
const requestRefresh = (target: RefreshTarget, reason: WorkspaceRefreshInput["reason"] = "event") => {
|
|
176
|
-
if (!loaded || !isActiveTarget(target)) return;
|
|
175
|
+
if (!loaded || isNativeFooter(loaded) || !isActiveTarget(target)) return;
|
|
177
176
|
gitController.request({ cwd: target.cwd, config: loaded.config });
|
|
178
177
|
workspaceController.request(workspaceInput(target.cwd, loaded.config, reason, runtime.workspace));
|
|
179
178
|
};
|
|
180
179
|
const scheduleRefresh = (ctx: ExtensionContext) => {
|
|
181
180
|
const target = activeTarget;
|
|
182
|
-
if (
|
|
181
|
+
if (
|
|
182
|
+
!loaded ||
|
|
183
|
+
isNativeFooter(loaded) ||
|
|
184
|
+
!target ||
|
|
185
|
+
target.cwd !== ctx.cwd ||
|
|
186
|
+
target.sessionManager !== ctx.sessionManager
|
|
187
|
+
) {
|
|
183
188
|
return;
|
|
184
189
|
}
|
|
185
190
|
clearDebounce();
|
|
@@ -190,7 +195,7 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
190
195
|
};
|
|
191
196
|
|
|
192
197
|
function restartLocalControllers(target: RefreshTarget) {
|
|
193
|
-
if (!isActiveTarget(target)) return;
|
|
198
|
+
if (!loaded || isNativeFooter(loaded) || !isActiveTarget(target)) return;
|
|
194
199
|
gitController.start(target.generation);
|
|
195
200
|
workspaceController.start(target.generation);
|
|
196
201
|
}
|
|
@@ -209,7 +214,7 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
209
214
|
}
|
|
210
215
|
|
|
211
216
|
function githubPrReachable(): boolean {
|
|
212
|
-
return Boolean(loaded && reachableModuleRequirements(loaded.config).has("github_pr"));
|
|
217
|
+
return Boolean(loaded && !isNativeFooter(loaded) && reachableModuleRequirements(loaded.config).has("github_pr"));
|
|
213
218
|
}
|
|
214
219
|
|
|
215
220
|
function startGithubPr(target: RefreshTarget): boolean {
|
|
@@ -253,14 +258,14 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
253
258
|
githubPrExpiryTimer.unref?.();
|
|
254
259
|
}
|
|
255
260
|
|
|
256
|
-
const
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
261
|
+
const releaseFooter = () => {
|
|
262
|
+
const context = footerContext;
|
|
263
|
+
footerContext = undefined;
|
|
264
|
+
const dispose = disposeFooter;
|
|
265
|
+
disposeFooter = undefined;
|
|
266
|
+
footerCollecting = false;
|
|
267
|
+
dispose?.();
|
|
268
|
+
activeTarget = undefined;
|
|
264
269
|
clearDebounce();
|
|
265
270
|
gitController.stop();
|
|
266
271
|
workspaceController.stop();
|
|
@@ -271,12 +276,32 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
271
276
|
runtime.renderPreview = undefined;
|
|
272
277
|
runtime.inspect = undefined;
|
|
273
278
|
runtime.footerWidth = undefined;
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
279
|
+
context?.ui.setFooter(undefined);
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const syncFooter = (ctx: ExtensionContext) => {
|
|
283
|
+
const current = previewLoaded ?? loaded;
|
|
284
|
+
if (ctx.mode !== "tui" || !current || isNativeFooter(current)) {
|
|
285
|
+
releaseFooter();
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
// A preview can replace the visible footer, but only applied settings own collectors.
|
|
289
|
+
const collect = Boolean(loaded && !isNativeFooter(loaded));
|
|
290
|
+
if (activeTarget && footerCollecting === collect) return;
|
|
291
|
+
if (activeTarget) releaseFooter();
|
|
292
|
+
footerCollecting = collect;
|
|
293
|
+
const target: RefreshTarget = {
|
|
294
|
+
cwd: ctx.cwd,
|
|
295
|
+
generation: sessionGeneration,
|
|
296
|
+
sessionManager: ctx.sessionManager,
|
|
297
|
+
};
|
|
298
|
+
activeTarget = target;
|
|
299
|
+
footerContext = ctx;
|
|
300
|
+
if (collect) {
|
|
301
|
+
gitController.start(target.generation);
|
|
302
|
+
workspaceController.start(target.generation);
|
|
303
|
+
startGithubPr(target);
|
|
304
|
+
}
|
|
280
305
|
|
|
281
306
|
ctx.ui.setFooter((tui, theme, footerData) => {
|
|
282
307
|
runtime.requestRender = () => tui.requestRender();
|
|
@@ -291,6 +316,10 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
291
316
|
inspectStatuslineModules(current.config, runtimeSnapshot(ctx, footerData, runtime), runtime.footerWidth ?? 80);
|
|
292
317
|
const unsubscribe = footerData.onBranchChange(() => {
|
|
293
318
|
if (!isActiveTarget(target)) return;
|
|
319
|
+
if (!collect) {
|
|
320
|
+
tui.requestRender();
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
294
323
|
runtime.git = undefined;
|
|
295
324
|
restartLocalControllers(target);
|
|
296
325
|
clearDebounce();
|
|
@@ -307,62 +336,67 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
307
336
|
width: number;
|
|
308
337
|
}
|
|
309
338
|
| undefined;
|
|
310
|
-
const timer =
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
339
|
+
const timer = collect
|
|
340
|
+
? setInterval(() => {
|
|
341
|
+
if (!isActiveTarget(target)) return;
|
|
342
|
+
clearDebounce();
|
|
343
|
+
requestRefresh(target, "periodic");
|
|
344
|
+
// Collectors publish only changed snapshots. The clock is the sole value
|
|
345
|
+
// that changes without publication; reuse the last render's session data.
|
|
346
|
+
if (!lastRender) return;
|
|
347
|
+
const clock = reachableModuleRequirements(lastRender.config).get("time");
|
|
348
|
+
const range = lastRender.config.modules.time.options.time_range;
|
|
349
|
+
if (!clock || (!clock.has("time") && (!range || range === "-"))) return;
|
|
350
|
+
const now = new Date();
|
|
351
|
+
const previous = lastRender.snapshot.now;
|
|
352
|
+
if (
|
|
353
|
+
!lastRender.config.modules.time.options.time_format &&
|
|
354
|
+
lastRender.config.modules.time.options.utc_time_offset === "local" &&
|
|
355
|
+
(!range || range === "-") &&
|
|
356
|
+
now.getHours() === previous.getHours() &&
|
|
357
|
+
now.getMinutes() === previous.getMinutes()
|
|
358
|
+
)
|
|
359
|
+
return;
|
|
360
|
+
const lines = wrapFormattedStatusline(
|
|
361
|
+
renderStatusline(
|
|
362
|
+
lastRender.config,
|
|
363
|
+
{ ...lastRender.snapshot, now },
|
|
364
|
+
lastRender.width,
|
|
365
|
+
getCapabilities().trueColor,
|
|
366
|
+
theme.colors,
|
|
367
|
+
).ansi,
|
|
368
|
+
lastRender.width,
|
|
369
|
+
);
|
|
370
|
+
const previousLines = lastRender.lines;
|
|
371
|
+
if (lines.length !== previousLines.length || lines.some((line, index) => line !== previousLines[index]))
|
|
372
|
+
tui.requestRender();
|
|
373
|
+
}, REFRESH_INTERVAL_MS)
|
|
374
|
+
: undefined;
|
|
344
375
|
let disposed = false;
|
|
345
376
|
|
|
377
|
+
const dispose = () => {
|
|
378
|
+
if (disposed) return;
|
|
379
|
+
disposed = true;
|
|
380
|
+
unsubscribe();
|
|
381
|
+
clearInterval(timer);
|
|
382
|
+
if (isActiveTarget(target)) {
|
|
383
|
+
activeTarget = undefined;
|
|
384
|
+
footerCollecting = false;
|
|
385
|
+
clearDebounce();
|
|
386
|
+
gitController.stop();
|
|
387
|
+
workspaceController.stop();
|
|
388
|
+
stopGithubPr();
|
|
389
|
+
runtime.git = undefined;
|
|
390
|
+
runtime.workspace = undefined;
|
|
391
|
+
runtime.requestRender = undefined;
|
|
392
|
+
runtime.renderPreview = undefined;
|
|
393
|
+
runtime.inspect = undefined;
|
|
394
|
+
runtime.footerWidth = undefined;
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
disposeFooter = dispose;
|
|
346
398
|
return {
|
|
347
|
-
dispose
|
|
348
|
-
if (disposed) return;
|
|
349
|
-
disposed = true;
|
|
350
|
-
unsubscribe();
|
|
351
|
-
clearInterval(timer);
|
|
352
|
-
if (isActiveTarget(target)) {
|
|
353
|
-
activeTarget = undefined;
|
|
354
|
-
clearDebounce();
|
|
355
|
-
gitController.stop();
|
|
356
|
-
workspaceController.stop();
|
|
357
|
-
stopGithubPr();
|
|
358
|
-
runtime.git = undefined;
|
|
359
|
-
runtime.workspace = undefined;
|
|
360
|
-
runtime.requestRender = undefined;
|
|
361
|
-
runtime.renderPreview = undefined;
|
|
362
|
-
runtime.inspect = undefined;
|
|
363
|
-
runtime.footerWidth = undefined;
|
|
364
|
-
}
|
|
365
|
-
},
|
|
399
|
+
dispose,
|
|
366
400
|
invalidate() {},
|
|
367
401
|
render(width: number): string[] {
|
|
368
402
|
runtime.footerWidth = width;
|
|
@@ -382,6 +416,18 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
382
416
|
requestGithubPr(target);
|
|
383
417
|
};
|
|
384
418
|
|
|
419
|
+
const installFooter = (ctx: ExtensionContext) => {
|
|
420
|
+
releaseFooter();
|
|
421
|
+
sessionGeneration += 1;
|
|
422
|
+
commandInFlight = undefined;
|
|
423
|
+
sessionOwner = ctx.sessionManager;
|
|
424
|
+
previewLoaded = undefined;
|
|
425
|
+
menuController.abort(new DOMException("Starship session context replaced", "AbortError"));
|
|
426
|
+
menuController = new AbortController();
|
|
427
|
+
ctx.ui.setStatus("starship", undefined);
|
|
428
|
+
syncFooter(ctx);
|
|
429
|
+
};
|
|
430
|
+
|
|
385
431
|
const configPath = settingsFilePath(getAgentDir());
|
|
386
432
|
const commandOptions: StarshipCommandOptions = {
|
|
387
433
|
settingsPath: configPath,
|
|
@@ -411,8 +457,10 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
411
457
|
previewLoaded = undefined;
|
|
412
458
|
loaded = next;
|
|
413
459
|
loadedRevision += 1;
|
|
460
|
+
const previousTarget = activeTarget;
|
|
461
|
+
syncFooter(ctx);
|
|
414
462
|
const target = activeTarget;
|
|
415
|
-
if (target) {
|
|
463
|
+
if (target && target === previousTarget) {
|
|
416
464
|
restartLocalControllers(target);
|
|
417
465
|
startGithubPr(target);
|
|
418
466
|
requestRefresh(target);
|
|
@@ -423,10 +471,31 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
423
471
|
preview(next, ctx) {
|
|
424
472
|
if (sessionOwner !== ctx.sessionManager) return;
|
|
425
473
|
previewLoaded = next;
|
|
474
|
+
syncFooter(ctx);
|
|
426
475
|
refresh();
|
|
427
476
|
},
|
|
428
|
-
renderPreview(preview, width) {
|
|
429
|
-
|
|
477
|
+
renderPreview(preview, width, ctx) {
|
|
478
|
+
if (isNativeFooter(preview)) return ["Pi built-in footer"];
|
|
479
|
+
if (runtime.renderPreview) return runtime.renderPreview(preview, width);
|
|
480
|
+
// Native mode has no custom footer provider. Render the candidate with
|
|
481
|
+
// session data only; collectors start when a custom footer is installed.
|
|
482
|
+
return wrapFormattedStatusline(
|
|
483
|
+
renderStatusline(
|
|
484
|
+
preview.config,
|
|
485
|
+
runtimeSnapshot(
|
|
486
|
+
ctx,
|
|
487
|
+
{
|
|
488
|
+
getGitBranch: () => null,
|
|
489
|
+
getExtensionStatuses: () => new Map(),
|
|
490
|
+
},
|
|
491
|
+
runtime,
|
|
492
|
+
),
|
|
493
|
+
width,
|
|
494
|
+
getCapabilities().trueColor,
|
|
495
|
+
ctx.ui.theme.colors,
|
|
496
|
+
).ansi,
|
|
497
|
+
width,
|
|
498
|
+
);
|
|
430
499
|
},
|
|
431
500
|
};
|
|
432
501
|
pi.registerCommand("starship", {
|
|
@@ -477,13 +546,7 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
477
546
|
previewLoaded = undefined;
|
|
478
547
|
sessionGeneration += 1;
|
|
479
548
|
menuController.abort(new DOMException("Starship session shut down", "AbortError"));
|
|
480
|
-
|
|
481
|
-
clearDebounce();
|
|
482
|
-
gitController.stop();
|
|
483
|
-
workspaceController.stop();
|
|
484
|
-
stopGithubPr();
|
|
485
|
-
runtime.git = undefined;
|
|
486
|
-
runtime.workspace = undefined;
|
|
549
|
+
releaseFooter();
|
|
487
550
|
runtime.activeTools.clear();
|
|
488
551
|
runtime.isStreaming = false;
|
|
489
552
|
runtime.uiPrompt = undefined;
|
|
@@ -492,7 +555,6 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
492
555
|
runtime.renderPreview = undefined;
|
|
493
556
|
runtime.inspect = undefined;
|
|
494
557
|
runtime.footerWidth = undefined;
|
|
495
|
-
ctx.ui.setFooter(undefined);
|
|
496
558
|
ctx.ui.setStatus("starship", undefined);
|
|
497
559
|
const cleanup = chatCleanup;
|
|
498
560
|
chatCleanup = undefined;
|
|
@@ -547,6 +609,10 @@ export default function piStarship(pi: ExtensionAPI, options: PiStarshipOptions
|
|
|
547
609
|
});
|
|
548
610
|
}
|
|
549
611
|
|
|
612
|
+
function isNativeFooter(loaded: LoadedStarshipConfig): boolean {
|
|
613
|
+
return loaded.rawDocument === undefined && loaded.diagnostics.length === 0;
|
|
614
|
+
}
|
|
615
|
+
|
|
550
616
|
function workspaceInput(
|
|
551
617
|
cwd: string,
|
|
552
618
|
config: StarshipConfig,
|
|
@@ -639,7 +705,7 @@ function safeUsername(): string {
|
|
|
639
705
|
|
|
640
706
|
function runtimeSnapshot(
|
|
641
707
|
ctx: ExtensionContext,
|
|
642
|
-
footerData: ReadonlyFooterDataProvider,
|
|
708
|
+
footerData: Pick<ReadonlyFooterDataProvider, "getGitBranch" | "getExtensionStatuses">,
|
|
643
709
|
runtime: RuntimeState,
|
|
644
710
|
): StarshipRuntimeSnapshot {
|
|
645
711
|
return {
|
|
@@ -21,6 +21,11 @@ function displayValue<T>(value: T): T {
|
|
|
21
21
|
return value;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
export interface SettingsChatAnchor {
|
|
25
|
+
message: AgentMessage | symbol;
|
|
26
|
+
row: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
24
29
|
/** Reuse Pi's public message components, not another extension's renderer or private settings. */
|
|
25
30
|
export function createSettingsChatTranscript(agent: Agent, tui: TUI, cwd: string) {
|
|
26
31
|
const messages = new Map<AgentMessage, Component>();
|
|
@@ -30,10 +35,34 @@ export function createSettingsChatTranscript(agent: Agent, tui: TUI, cwd: string
|
|
|
30
35
|
write: createWriteToolDefinition(cwd),
|
|
31
36
|
edit: createEditToolDefinition(cwd),
|
|
32
37
|
};
|
|
38
|
+
// Agent emits a new object for each partial update and another at finalization.
|
|
39
|
+
// Keep one response identity across those events, including frames with no render.
|
|
40
|
+
const identities = new WeakMap<AgentMessage, symbol>();
|
|
41
|
+
let streamingIdentity: symbol | undefined;
|
|
42
|
+
const initial = agent.state.streamingMessage;
|
|
43
|
+
if (initial?.role === "assistant") {
|
|
44
|
+
streamingIdentity = Symbol();
|
|
45
|
+
identities.set(initial, streamingIdentity);
|
|
46
|
+
}
|
|
47
|
+
const unsubscribe = agent.subscribe((event) => {
|
|
48
|
+
if (event.type === "agent_end") streamingIdentity = undefined;
|
|
49
|
+
if (
|
|
50
|
+
(event.type === "message_start" || event.type === "message_update" || event.type === "message_end") &&
|
|
51
|
+
event.message.role === "assistant"
|
|
52
|
+
) {
|
|
53
|
+
if (event.type === "message_start") streamingIdentity = Symbol();
|
|
54
|
+
streamingIdentity ??= Symbol();
|
|
55
|
+
identities.set(event.message, streamingIdentity);
|
|
56
|
+
if (event.type === "message_end") streamingIdentity = undefined;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
let spans: Array<{ message: AgentMessage | symbol; start: number; end: number }> = [];
|
|
33
60
|
let streaming: AssistantMessageComponent | undefined;
|
|
34
61
|
let disposed = false;
|
|
62
|
+
let expanded = true;
|
|
35
63
|
return {
|
|
36
64
|
render(width: number): string[] {
|
|
65
|
+
spans = [];
|
|
37
66
|
if (disposed || width <= 0) return [];
|
|
38
67
|
const results = new Map(
|
|
39
68
|
agent.state.messages.flatMap((message) =>
|
|
@@ -66,8 +95,7 @@ export function createSettingsChatTranscript(agent: Agent, tui: TUI, cwd: string
|
|
|
66
95
|
tui,
|
|
67
96
|
sanitizeTerminalDocument(cwd),
|
|
68
97
|
);
|
|
69
|
-
|
|
70
|
-
component.setExpanded(true);
|
|
98
|
+
component.setExpanded(expanded);
|
|
71
99
|
component.setArgsComplete();
|
|
72
100
|
component.markExecutionStarted();
|
|
73
101
|
tool = { component };
|
|
@@ -88,9 +116,11 @@ export function createSettingsChatTranscript(agent: Agent, tui: TUI, cwd: string
|
|
|
88
116
|
};
|
|
89
117
|
for (const message of visible) {
|
|
90
118
|
activeMessages.add(message);
|
|
119
|
+
let start = lines.length;
|
|
91
120
|
let component = messages.get(message);
|
|
92
121
|
if (message.role === "user") {
|
|
93
122
|
if (lines.length) lines.push("");
|
|
123
|
+
start = lines.length;
|
|
94
124
|
if (!component) {
|
|
95
125
|
const text =
|
|
96
126
|
typeof message.content === "string"
|
|
@@ -110,18 +140,36 @@ export function createSettingsChatTranscript(agent: Agent, tui: TUI, cwd: string
|
|
|
110
140
|
}
|
|
111
141
|
appendAssistant(message, component as AssistantMessageComponent);
|
|
112
142
|
}
|
|
143
|
+
spans.push({ message: identities.get(message) ?? message, start, end: lines.length });
|
|
113
144
|
}
|
|
114
145
|
const partial = agent.state.streamingMessage;
|
|
115
146
|
if (partial?.role === "assistant") {
|
|
116
147
|
streaming ??= new AssistantMessageComponent(undefined, true);
|
|
117
148
|
streaming.updateContent(displayValue(partial), true);
|
|
118
149
|
// Tool calls are rendered after finalization, not from incomplete streaming arguments.
|
|
150
|
+
const start = lines.length;
|
|
119
151
|
lines.push(...streaming.render(width));
|
|
152
|
+
spans.push({ message: identities.get(partial) ?? partial, start, end: lines.length });
|
|
120
153
|
} else streaming = undefined;
|
|
121
154
|
for (const message of messages.keys()) if (!activeMessages.has(message)) messages.delete(message);
|
|
122
155
|
for (const id of tools.keys()) if (!activeTools.has(id)) tools.delete(id);
|
|
123
156
|
return lines;
|
|
124
157
|
},
|
|
158
|
+
anchorAt(row: number): SettingsChatAnchor | undefined {
|
|
159
|
+
const span = spans.find((item) => row < item.end);
|
|
160
|
+
return span ? { message: span.message, row: row - span.start } : undefined;
|
|
161
|
+
},
|
|
162
|
+
rowAt(anchor: SettingsChatAnchor): number {
|
|
163
|
+
const span = spans.find((item) => item.message === anchor.message);
|
|
164
|
+
// If the anchored message was evicted, show the oldest retained content.
|
|
165
|
+
return span ? Math.max(0, span.start + Math.min(anchor.row, span.end - span.start - 1)) : 0;
|
|
166
|
+
},
|
|
167
|
+
toggleTools() {
|
|
168
|
+
if (disposed) return;
|
|
169
|
+
expanded = !expanded;
|
|
170
|
+
for (const { component } of tools.values()) component.setExpanded(expanded);
|
|
171
|
+
tui.requestRender();
|
|
172
|
+
},
|
|
125
173
|
invalidate() {
|
|
126
174
|
if (disposed) return;
|
|
127
175
|
// Native Markdown themes can retain concrete colors. Recreate display components
|
|
@@ -131,7 +179,11 @@ export function createSettingsChatTranscript(agent: Agent, tui: TUI, cwd: string
|
|
|
131
179
|
streaming = undefined;
|
|
132
180
|
},
|
|
133
181
|
dispose() {
|
|
182
|
+
if (disposed) return;
|
|
134
183
|
disposed = true;
|
|
184
|
+
unsubscribe();
|
|
185
|
+
streamingIdentity = undefined;
|
|
186
|
+
spans = [];
|
|
135
187
|
messages.clear();
|
|
136
188
|
tools.clear();
|
|
137
189
|
streaming = undefined;
|