@lune_99/pi-subagent 0.1.0 → 0.2.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/CHANGELOG.md +33 -0
- package/README.md +25 -9
- package/docs/reference.md +62 -38
- package/package.json +6 -6
- package/skills/create-lune-subagent/SKILL.md +21 -17
- package/src/auto-model.ts +46 -37
- package/src/definition-file.ts +36 -1
- package/src/definitions.ts +6 -0
- package/src/dock/dock-contribution.ts +19 -9
- package/src/index.ts +36 -10
- package/src/inspector/details.ts +9 -3
- package/src/inspector/inspector.ts +67 -43
- package/src/models.ts +24 -9
- package/src/notify/notification-box.ts +42 -15
- package/src/notify/notifier.ts +23 -6
- package/src/run/guide.ts +5 -0
- package/src/run/run-file.ts +1 -0
- package/src/run/run-manager.ts +123 -26
- package/src/run/run.ts +130 -38
- package/src/run/types.ts +12 -4
- package/src/settings/agents-menu.ts +37 -24
- package/src/settings/panel.ts +50 -8
- package/src/settings/schema.ts +5 -1
- package/src/settings/thinking-choices.ts +92 -0
- package/src/tools/format.ts +65 -43
- package/src/tools/subagent-tools.ts +95 -207
|
@@ -11,8 +11,8 @@ import {
|
|
|
11
11
|
type TuiMouseEventResult,
|
|
12
12
|
} from "@earendil-works/pi-tui";
|
|
13
13
|
|
|
14
|
-
import { reportColor, stateColor } from "../notify/notification-box.ts";
|
|
15
|
-
import { displayLine, fitRanked, type RankedPart } from "../render/text.ts";
|
|
14
|
+
import { displayedStatus, reportColor, stateColor } from "../notify/notification-box.ts";
|
|
15
|
+
import { clipToWidth, displayLine, fitRanked, type RankedPart } from "../render/text.ts";
|
|
16
16
|
import type { RunManager } from "../run/run-manager.ts";
|
|
17
17
|
import type { Run } from "../run/run.ts";
|
|
18
18
|
import { formatPercent } from "../tools/format.ts";
|
|
@@ -65,13 +65,16 @@ export async function openSubagentInspector(options: InspectorOptions): Promise<
|
|
|
65
65
|
interface FrameLayout {
|
|
66
66
|
geometry: PaneGeometry;
|
|
67
67
|
listStart: number;
|
|
68
|
+
/** Run IDs as the list showed them, so a click selects the run the user saw in that row. */
|
|
69
|
+
order: readonly string[];
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
/**
|
|
71
73
|
* The `/agents` panel: runs on the left, the selected run's live transcript on the right.
|
|
72
74
|
*
|
|
73
75
|
* Runs of the current branch come first; runs of other branches follow, dimmed, so their reports
|
|
74
|
-
* can be copied over. Every write goes through the manager, which
|
|
76
|
+
* can be copied over. Running runs lead each group. Every write goes through the manager, which
|
|
77
|
+
* enforces read-only runs.
|
|
75
78
|
*/
|
|
76
79
|
export class SubagentInspector implements Component {
|
|
77
80
|
private readonly ctx: ExtensionContext;
|
|
@@ -108,7 +111,8 @@ export class SubagentInspector implements Component {
|
|
|
108
111
|
this.terminalRows = terminalRows;
|
|
109
112
|
this.theme = options.ctx.ui.theme;
|
|
110
113
|
this.transcripts = new TranscriptRenderer(this.theme);
|
|
111
|
-
|
|
114
|
+
// A remembered run that is no longer listed falls back to the first one on render.
|
|
115
|
+
this.selectedId = this.manager.inspectorRunId ?? this.entries()[0]?.run.id;
|
|
112
116
|
// The list shows states only, so another run's streamed tokens change nothing on screen.
|
|
113
117
|
this.unsubscribe = this.manager.subscribe((change, run) => {
|
|
114
118
|
if (change === "state" || run?.id === this.selectedId) {
|
|
@@ -200,13 +204,13 @@ export class SubagentInspector implements Component {
|
|
|
200
204
|
return undefined;
|
|
201
205
|
}
|
|
202
206
|
|
|
203
|
-
const
|
|
207
|
+
const runId = layout.order[layout.listStart + row];
|
|
204
208
|
|
|
205
|
-
if (
|
|
209
|
+
if (runId === undefined) {
|
|
206
210
|
return undefined;
|
|
207
211
|
}
|
|
208
212
|
|
|
209
|
-
this.select(
|
|
213
|
+
this.select(runId);
|
|
210
214
|
|
|
211
215
|
return { handled: true };
|
|
212
216
|
}
|
|
@@ -259,7 +263,7 @@ export class SubagentInspector implements Component {
|
|
|
259
263
|
right = [cell(this.theme.fg("muted", "No subagent runs in this session."), rightWidth)];
|
|
260
264
|
}
|
|
261
265
|
|
|
262
|
-
this.layout = { geometry, listStart };
|
|
266
|
+
this.layout = { geometry, listStart, order: entries.map((entry) => entry.run.id) };
|
|
263
267
|
|
|
264
268
|
return assembleFrame(this.theme, geometry, {
|
|
265
269
|
header: cell(this.header(entries), geometry.innerWidth),
|
|
@@ -292,6 +296,7 @@ export class SubagentInspector implements Component {
|
|
|
292
296
|
}
|
|
293
297
|
|
|
294
298
|
this.disposed = true;
|
|
299
|
+
this.manager.inspectorRunId = this.selectedId;
|
|
295
300
|
clearInterval(this.refreshTimer);
|
|
296
301
|
clearTimeout(this.noticeTimer);
|
|
297
302
|
this.unsubscribe?.();
|
|
@@ -302,8 +307,8 @@ export class SubagentInspector implements Component {
|
|
|
302
307
|
const { here, elsewhere } = this.manager.runsByBranch();
|
|
303
308
|
|
|
304
309
|
return [
|
|
305
|
-
...here.map((run) => ({ run, elsewhere: false })),
|
|
306
|
-
...elsewhere.map((run) => ({ run, elsewhere: true })),
|
|
310
|
+
...runningFirst(here).map((run) => ({ run, elsewhere: false })),
|
|
311
|
+
...runningFirst(elsewhere).map((run) => ({ run, elsewhere: true })),
|
|
307
312
|
];
|
|
308
313
|
}
|
|
309
314
|
|
|
@@ -319,30 +324,33 @@ export class SubagentInspector implements Component {
|
|
|
319
324
|
height: number,
|
|
320
325
|
): string[] {
|
|
321
326
|
const rows: string[] = [];
|
|
327
|
+
const contentWidth = width - 2;
|
|
322
328
|
|
|
323
329
|
for (let index = start; index < Math.min(entries.length, start + height); index++) {
|
|
324
330
|
const { run, elsewhere } = entries[index]!;
|
|
331
|
+
// One status per run, as in the Dock, so that it fits whole in the narrowest list.
|
|
325
332
|
const report =
|
|
326
|
-
run.
|
|
327
|
-
? (run.lastTurn.report?.status
|
|
333
|
+
run.state === "idle" && run.lastTurn
|
|
334
|
+
? displayedStatus(run.state, run.lastTurn.report?.status, run.lastTurn.cutShort)
|
|
328
335
|
: undefined;
|
|
336
|
+
const status = report ?? run.state;
|
|
329
337
|
const marker = elsewhere ? "↪" : run.state === "running" ? "◐" : "●";
|
|
338
|
+
// The cursor and marker take four columns, and one more separates title and status.
|
|
339
|
+
const name = clipToWidth(run.title, Math.max(0, contentWidth - 5 - status.length));
|
|
340
|
+
const title = this.theme.fg(elsewhere ? "muted" : "text", name);
|
|
341
|
+
const gap = Math.max(1, contentWidth - 4 - visibleWidth(name) - status.length);
|
|
330
342
|
const text =
|
|
331
|
-
this.theme.fg(
|
|
343
|
+
(index === selected ? this.theme.fg("accent", "›") : " ") +
|
|
332
344
|
" " +
|
|
333
|
-
this.theme.fg(elsewhere ? "
|
|
345
|
+
this.theme.fg(elsewhere ? "dim" : stateColor(run.state), marker) +
|
|
334
346
|
" " +
|
|
335
|
-
this.theme.
|
|
336
|
-
|
|
337
|
-
|
|
347
|
+
(index === selected ? this.theme.bold(title) : title) +
|
|
348
|
+
" ".repeat(gap) +
|
|
349
|
+
this.theme.fg(report ? reportColor(report) : stateColor(run.state), status);
|
|
338
350
|
rows.push(cell(text, width));
|
|
339
351
|
}
|
|
340
352
|
|
|
341
|
-
|
|
342
|
-
// background wraps the row in escape sequences.
|
|
343
|
-
return paintScrollbar(this.theme, rows, start, height, entries.length).map((row, offset) =>
|
|
344
|
-
start + offset === selected ? this.theme.bg("selectedBg", row) : row,
|
|
345
|
-
);
|
|
353
|
+
return paintScrollbar(this.theme, rows, start, height, entries.length);
|
|
346
354
|
}
|
|
347
355
|
|
|
348
356
|
private header(entries: readonly Entry[]): string {
|
|
@@ -360,19 +368,22 @@ export class SubagentInspector implements Component {
|
|
|
360
368
|
return `${this.theme.bold("Subagents")} ${this.theme.fg("muted", counts)}`;
|
|
361
369
|
}
|
|
362
370
|
|
|
363
|
-
/** The run's
|
|
371
|
+
/** The run's title and every label that fits; a narrow pane leaves out the least useful first. */
|
|
364
372
|
private title(entry: Entry, newestHidden: number, width: number): string {
|
|
365
373
|
const { run } = entry;
|
|
366
|
-
const report =
|
|
367
|
-
|
|
374
|
+
const report =
|
|
375
|
+
run.lastTurn &&
|
|
376
|
+
displayedStatus(run.state, run.lastTurn.report?.status, run.lastTurn.cutShort);
|
|
377
|
+
const title = this.theme.bold(run.title);
|
|
368
378
|
const parts: Array<RankedPart | undefined> = [
|
|
369
379
|
// A run without a readable snapshot is already named by its ID.
|
|
370
|
-
run.
|
|
380
|
+
run.title !== run.id ? { text: this.theme.fg("dim", run.id), rank: 1 } : undefined,
|
|
371
381
|
{ text: this.theme.fg(stateColor(run.state), run.state), rank: 5 },
|
|
372
382
|
report && run.state !== "running"
|
|
373
383
|
? { text: this.theme.fg(reportColor(report), report), rank: 4 }
|
|
374
384
|
: undefined,
|
|
375
385
|
entry.elsewhere ? { text: this.theme.fg("muted", "other branch"), rank: 3 } : undefined,
|
|
386
|
+
run.readOnly ? { text: this.theme.fg("muted", "read-only"), rank: 3 } : undefined,
|
|
376
387
|
this.details ? { text: this.theme.fg("accent", "details"), rank: 2 } : undefined,
|
|
377
388
|
newestHidden > 0
|
|
378
389
|
? { text: this.theme.fg("accent", `↓ ${newestHidden} newer · End`), rank: 6 }
|
|
@@ -383,8 +394,8 @@ export class SubagentInspector implements Component {
|
|
|
383
394
|
fitRanked(
|
|
384
395
|
parts.filter((part) => part !== undefined),
|
|
385
396
|
width,
|
|
386
|
-
(texts) => [
|
|
387
|
-
) ??
|
|
397
|
+
(texts) => [title, ...texts].join(this.theme.fg("dim", " · ")),
|
|
398
|
+
) ?? title
|
|
388
399
|
);
|
|
389
400
|
}
|
|
390
401
|
|
|
@@ -470,7 +481,9 @@ export class SubagentInspector implements Component {
|
|
|
470
481
|
|
|
471
482
|
private footer(width: number, entry: Entry | undefined): string {
|
|
472
483
|
if (this.chat) {
|
|
473
|
-
const
|
|
484
|
+
const targetWidth = Math.max(0, Math.floor((width - 2) / 2) - 5);
|
|
485
|
+
const target = clipToWidth(entry?.run.title ?? "run", targetWidth);
|
|
486
|
+
const prompt = this.theme.fg("accent", `To ${target}: `);
|
|
474
487
|
const input = this.chat.render(Math.max(1, width - 2 - visibleWidth(prompt)))[0] ?? "";
|
|
475
488
|
|
|
476
489
|
return ` ${prompt}${input}`;
|
|
@@ -529,7 +542,7 @@ export class SubagentInspector implements Component {
|
|
|
529
542
|
|
|
530
543
|
if (entry.elsewhere) {
|
|
531
544
|
this.showNotice(
|
|
532
|
-
`${run.
|
|
545
|
+
`${run.title} belongs to another branch; switch to it to write to the run.`,
|
|
533
546
|
"warning",
|
|
534
547
|
);
|
|
535
548
|
return;
|
|
@@ -537,7 +550,7 @@ export class SubagentInspector implements Component {
|
|
|
537
550
|
|
|
538
551
|
if (run.readOnly) {
|
|
539
552
|
this.showNotice(
|
|
540
|
-
`${run.
|
|
553
|
+
`${run.title} is read-only: it came here through /fork or /clone.`,
|
|
541
554
|
"warning",
|
|
542
555
|
);
|
|
543
556
|
return;
|
|
@@ -561,39 +574,39 @@ export class SubagentInspector implements Component {
|
|
|
561
574
|
}
|
|
562
575
|
|
|
563
576
|
private send(run: Run, text: string): void {
|
|
564
|
-
this.showNotice(`Sending to ${run.
|
|
577
|
+
this.showNotice(`Sending to ${run.title}…`, "muted");
|
|
565
578
|
|
|
566
579
|
this.manager.send(run, text, "user").then(
|
|
567
580
|
(outcome) => {
|
|
568
581
|
this.showNotice(
|
|
569
582
|
outcome === "steered"
|
|
570
|
-
? `Sent to ${run.
|
|
583
|
+
? `Sent to ${run.title}; it steers the running turn.`
|
|
571
584
|
: outcome === "deferred"
|
|
572
|
-
? `Sent to ${run.
|
|
573
|
-
: `Sent to ${run.
|
|
585
|
+
? `Sent to ${run.title}; it starts the next turn.`
|
|
586
|
+
: `Sent to ${run.title}; a new turn started.`,
|
|
574
587
|
"success",
|
|
575
588
|
);
|
|
576
589
|
this.viewport.follow();
|
|
577
590
|
},
|
|
578
|
-
(error: unknown) => this.showError(`Sending to ${run.
|
|
591
|
+
(error: unknown) => this.showError(`Sending to ${run.title} failed`, error),
|
|
579
592
|
);
|
|
580
593
|
}
|
|
581
594
|
|
|
582
595
|
private stop(run: Run): void {
|
|
583
596
|
if (run.state !== "running") {
|
|
584
|
-
this.showNotice(`${run.
|
|
597
|
+
this.showNotice(`${run.title} is not running.`, "muted");
|
|
585
598
|
return;
|
|
586
599
|
}
|
|
587
600
|
|
|
588
601
|
if (run.readOnly || !this.manager.isOnBranch(run)) {
|
|
589
|
-
this.showNotice(`${run.
|
|
602
|
+
this.showNotice(`${run.title} cannot be stopped from here.`, "warning");
|
|
590
603
|
return;
|
|
591
604
|
}
|
|
592
605
|
|
|
593
|
-
this.showNotice(`Stopping ${run.
|
|
606
|
+
this.showNotice(`Stopping ${run.title}…`, "muted");
|
|
594
607
|
this.manager.stop(run, "user").then(
|
|
595
|
-
() => this.showNotice(`Stopped ${run.
|
|
596
|
-
(error: unknown) => this.showError(`Stopping ${run.
|
|
608
|
+
() => this.showNotice(`Stopped ${run.title}.`, "success"),
|
|
609
|
+
(error: unknown) => this.showError(`Stopping ${run.title} failed`, error),
|
|
597
610
|
);
|
|
598
611
|
}
|
|
599
612
|
|
|
@@ -605,9 +618,12 @@ export class SubagentInspector implements Component {
|
|
|
605
618
|
|
|
606
619
|
try {
|
|
607
620
|
this.manager.copyReport(entry.run);
|
|
608
|
-
this.showNotice(
|
|
621
|
+
this.showNotice(
|
|
622
|
+
`Copied the last turn of ${entry.run.title} to this branch.`,
|
|
623
|
+
"success",
|
|
624
|
+
);
|
|
609
625
|
} catch (error) {
|
|
610
|
-
this.showError(`Copying ${entry.run.
|
|
626
|
+
this.showError(`Copying ${entry.run.title} failed`, error);
|
|
611
627
|
}
|
|
612
628
|
}
|
|
613
629
|
|
|
@@ -646,6 +662,14 @@ export class SubagentInspector implements Component {
|
|
|
646
662
|
}
|
|
647
663
|
}
|
|
648
664
|
|
|
665
|
+
/** Both parts keep start order, so a row moves only when its run starts or ends a turn. */
|
|
666
|
+
function runningFirst(runs: readonly Run[]): Run[] {
|
|
667
|
+
return [
|
|
668
|
+
...runs.filter((run) => run.state === "running"),
|
|
669
|
+
...runs.filter((run) => run.state !== "running"),
|
|
670
|
+
];
|
|
671
|
+
}
|
|
672
|
+
|
|
649
673
|
interface Entry {
|
|
650
674
|
run: Run;
|
|
651
675
|
/** The run belongs to another branch: read it, copy its report, nothing else. */
|
package/src/models.ts
CHANGED
|
@@ -25,19 +25,34 @@ export function formatModelRef(model: ModelRef): string {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
* or every available model
|
|
28
|
+
* A nonempty selection replaces the parent's model scope (`--models` or `enabledModels`).
|
|
29
|
+
* Without a selection or scope, every available model is allowed.
|
|
30
30
|
*/
|
|
31
|
-
export function allowedModelRefs(
|
|
32
|
-
|
|
31
|
+
export function allowedModelRefs(
|
|
32
|
+
ctx: ExtensionContext,
|
|
33
|
+
selection: readonly ModelRef[] = [],
|
|
34
|
+
): string[] {
|
|
35
|
+
return allowedModels(ctx, selection).map((model) => formatModelRef(model));
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
/** The models of `allowedModelRefs`, once each, in scope order. */
|
|
36
|
-
export function allowedModels(
|
|
38
|
+
/** The models of `allowedModelRefs`, once each, in selection or scope order. */
|
|
39
|
+
export function allowedModels(
|
|
40
|
+
ctx: ExtensionContext,
|
|
41
|
+
selection: readonly ModelRef[] = [],
|
|
42
|
+
): Model<Api>[] {
|
|
43
|
+
const available = ctx.modelRegistry.getAvailable();
|
|
37
44
|
const models =
|
|
38
|
-
|
|
39
|
-
?
|
|
40
|
-
|
|
45
|
+
selection.length > 0
|
|
46
|
+
? selection.flatMap((ref) => {
|
|
47
|
+
const model = available.find(
|
|
48
|
+
(model) => model.provider === ref.provider && model.id === ref.id,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return model ? [model] : [];
|
|
52
|
+
})
|
|
53
|
+
: ctx.scopedModels.length > 0
|
|
54
|
+
? ctx.scopedModels.map((scoped) => scoped.model)
|
|
55
|
+
: available;
|
|
41
56
|
const seen = new Set<string>();
|
|
42
57
|
|
|
43
58
|
return models.filter((model) => {
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
type LuneThemeRenderer,
|
|
19
19
|
} from "../render/lune-theme.ts";
|
|
20
20
|
import { bandRow, clipToWidth, displayLines, EXPAND_KEY } from "../render/text.ts";
|
|
21
|
+
import type { ReportStatus, RunState } from "../run/types.ts";
|
|
21
22
|
import { formatDuration } from "../tools/format.ts";
|
|
22
23
|
import type {
|
|
23
24
|
ContentSlice,
|
|
@@ -92,7 +93,7 @@ class RunNotificationBox implements Component {
|
|
|
92
93
|
return this.themed?.component.handleMouse?.(event);
|
|
93
94
|
}
|
|
94
95
|
|
|
95
|
-
render(width: number): string[] {
|
|
96
|
+
render(width: number): readonly string[] {
|
|
96
97
|
const renderer = luneThemeRenderer();
|
|
97
98
|
|
|
98
99
|
if (renderer) {
|
|
@@ -172,13 +173,14 @@ class RunNotificationBox implements Component {
|
|
|
172
173
|
name: run.name,
|
|
173
174
|
summary: run.question ?? run.reason ?? firstLine(this.body(run)),
|
|
174
175
|
status: activityStatus(run.state),
|
|
175
|
-
detail:
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
176
|
+
detail:
|
|
177
|
+
[
|
|
178
|
+
activityDetailStatus(run),
|
|
179
|
+
earlierCount(run),
|
|
180
|
+
run.copied ? "copied" : undefined,
|
|
181
|
+
]
|
|
182
|
+
.filter((part) => part !== undefined)
|
|
183
|
+
.join(" · ") || undefined,
|
|
182
184
|
durationMs: run.durationMs,
|
|
183
185
|
error: run.error,
|
|
184
186
|
output: displayLines(
|
|
@@ -209,14 +211,14 @@ class RunNotificationBox implements Component {
|
|
|
209
211
|
return `${this.runs.length} subagent turns ended`;
|
|
210
212
|
}
|
|
211
213
|
|
|
212
|
-
/** `<name> · <state> · <report status> · <duration>`; the name is clipped first. */
|
|
214
|
+
/** `<name> · <state> · <report status, if any> · <duration>`; the name is clipped first. */
|
|
213
215
|
private runRow(run: RunNotificationRun, width: number): string {
|
|
214
|
-
const
|
|
215
|
-
const report =
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
const parts = [this.theme.fg(stateColor(run.state), run.state)];
|
|
217
|
+
const report = displayedStatus(run.state, run.reportStatus, run.cutShort);
|
|
218
|
+
|
|
219
|
+
if (report) {
|
|
220
|
+
parts.push(this.theme.fg(reportColor(report), report));
|
|
221
|
+
}
|
|
220
222
|
|
|
221
223
|
if (run.durationMs !== undefined && Number.isFinite(run.durationMs)) {
|
|
222
224
|
parts.push(this.theme.fg("muted", formatDuration(run.durationMs)));
|
|
@@ -327,6 +329,17 @@ function notes(run: RunNotificationRun): string[] {
|
|
|
327
329
|
return lines;
|
|
328
330
|
}
|
|
329
331
|
|
|
332
|
+
/**
|
|
333
|
+
* The status part of a run's activity detail. The card marks an idle run like a finished one, so a
|
|
334
|
+
* turn without a task status names its state; the card words a failed or interrupted run itself.
|
|
335
|
+
*/
|
|
336
|
+
function activityDetailStatus(run: RunNotificationRun): string | undefined {
|
|
337
|
+
return (
|
|
338
|
+
displayedStatus(run.state, run.reportStatus, run.cutShort) ??
|
|
339
|
+
(run.state === "idle" ? run.state : undefined)
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
330
343
|
function earlierCount(run: RunNotificationRun): string | undefined {
|
|
331
344
|
const count = run.earlierReports?.length ?? 0;
|
|
332
345
|
|
|
@@ -367,6 +380,20 @@ export function stateColor(state: string): ThemeColor {
|
|
|
367
380
|
}
|
|
368
381
|
}
|
|
369
382
|
|
|
383
|
+
/**
|
|
384
|
+
* The task status the user sees. A turn that ended normally without a report shows as done: its last
|
|
385
|
+
* message reaches the main agent anyway, and a separate label read as if nothing had been sent. A
|
|
386
|
+
* turn that was cut short shows only its state, because its work may not be finished. The main agent
|
|
387
|
+
* is still told that such a turn has no task status.
|
|
388
|
+
*/
|
|
389
|
+
export function displayedStatus(
|
|
390
|
+
state: RunState,
|
|
391
|
+
report: ReportStatus | undefined,
|
|
392
|
+
cutShort: boolean | undefined,
|
|
393
|
+
): ReportStatus | undefined {
|
|
394
|
+
return report ?? (state === "idle" && !cutShort ? "done" : undefined);
|
|
395
|
+
}
|
|
396
|
+
|
|
370
397
|
export function reportColor(status: string | undefined): ThemeColor {
|
|
371
398
|
switch (status) {
|
|
372
399
|
case "done":
|
package/src/notify/notifier.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
SessionEntry,
|
|
5
5
|
} from "@earendil-works/pi-coding-agent";
|
|
6
6
|
|
|
7
|
+
import { userMessageHeading } from "../run/guide.ts";
|
|
7
8
|
import type {
|
|
8
9
|
ReportStatus,
|
|
9
10
|
RunReport,
|
|
@@ -21,6 +22,8 @@ const SECTION_SEPARATOR = "\n\n---\n\n";
|
|
|
21
22
|
export interface RunNotice {
|
|
22
23
|
runId: string;
|
|
23
24
|
name: string;
|
|
25
|
+
/** The user-facing title; the model-facing text names the run by its ID only. */
|
|
26
|
+
title?: string;
|
|
24
27
|
record: TurnRecord;
|
|
25
28
|
/** The user copied it from the inspector; the run belongs to another branch. */
|
|
26
29
|
copied?: boolean;
|
|
@@ -51,6 +54,7 @@ export interface RunNotificationRun {
|
|
|
51
54
|
endedAt?: string;
|
|
52
55
|
state: SettledState;
|
|
53
56
|
reportStatus?: ReportStatus;
|
|
57
|
+
cutShort?: boolean;
|
|
54
58
|
reason?: string;
|
|
55
59
|
question?: string;
|
|
56
60
|
error?: string;
|
|
@@ -75,7 +79,7 @@ export function buildRunNotification(batch: readonly RunNotice[]): {
|
|
|
75
79
|
let content = "";
|
|
76
80
|
const runs: RunNotificationRun[] = [];
|
|
77
81
|
|
|
78
|
-
for (const { runId, name, record, copied } of batch) {
|
|
82
|
+
for (const { runId, name, title, record, copied } of batch) {
|
|
79
83
|
if (content !== "") {
|
|
80
84
|
content += SECTION_SEPARATOR;
|
|
81
85
|
}
|
|
@@ -86,14 +90,18 @@ export function buildRunNotification(batch: readonly RunNotice[]): {
|
|
|
86
90
|
|
|
87
91
|
if (copied) {
|
|
88
92
|
section.line(
|
|
89
|
-
`The user copied the last turn of subagent run ${
|
|
90
|
-
`
|
|
93
|
+
`The user copied the last turn of subagent run ${runId} from another branch. ` +
|
|
94
|
+
`It ended: ${record.state}.`,
|
|
91
95
|
);
|
|
92
96
|
section.line(
|
|
93
97
|
"The run belongs to that branch, so the subagent tools cannot reach it from here.",
|
|
94
98
|
);
|
|
95
99
|
} else {
|
|
96
|
-
section.line(`Subagent run ${
|
|
100
|
+
section.line(`Subagent run ${runId} ended its turn: ${record.state}.`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (title !== undefined) {
|
|
104
|
+
section.line(`Title: ${title}`);
|
|
97
105
|
}
|
|
98
106
|
|
|
99
107
|
if (record.stoppedBy === "user") {
|
|
@@ -107,6 +115,14 @@ export function buildRunNotification(batch: readonly RunNotice[]): {
|
|
|
107
115
|
"The user wrote to this run during the turn, so its report may answer the user " +
|
|
108
116
|
"rather than only your task.",
|
|
109
117
|
);
|
|
118
|
+
|
|
119
|
+
const userMessages = record.userMessages ?? [];
|
|
120
|
+
|
|
121
|
+
userMessages.forEach((text, index) => {
|
|
122
|
+
section.line(userMessageHeading(index, userMessages.length));
|
|
123
|
+
section.text(text);
|
|
124
|
+
section.line("");
|
|
125
|
+
});
|
|
110
126
|
}
|
|
111
127
|
|
|
112
128
|
if (record.error) {
|
|
@@ -140,7 +156,7 @@ export function buildRunNotification(batch: readonly RunNotice[]): {
|
|
|
140
156
|
} else {
|
|
141
157
|
const message = record.unreportedMessage ?? "";
|
|
142
158
|
|
|
143
|
-
section.line("
|
|
159
|
+
section.line("No task status: the turn ended without a report.");
|
|
144
160
|
section.line("");
|
|
145
161
|
section.line(message === "" ? "The run left no message." : "The run's last message:");
|
|
146
162
|
body = section.text(message);
|
|
@@ -149,11 +165,12 @@ export function buildRunNotification(batch: readonly RunNotice[]): {
|
|
|
149
165
|
content += section.content;
|
|
150
166
|
runs.push({
|
|
151
167
|
runId,
|
|
152
|
-
name,
|
|
168
|
+
name: title ?? name,
|
|
153
169
|
...(copied ? { copied } : {}),
|
|
154
170
|
endedAt: record.endedAt,
|
|
155
171
|
state: record.state,
|
|
156
172
|
reportStatus: report?.status,
|
|
173
|
+
...(record.cutShort ? { cutShort: true } : {}),
|
|
157
174
|
reason: report?.reason,
|
|
158
175
|
question: report?.question,
|
|
159
176
|
error: record.error,
|
package/src/run/guide.ts
CHANGED
|
@@ -24,3 +24,8 @@ export function isUserMessage(text: string): boolean {
|
|
|
24
24
|
export function stripUserMarker(text: string): string {
|
|
25
25
|
return isUserMessage(text) ? text.slice(USER_MESSAGE_MARKER.length).replace(/^\n/, "") : text;
|
|
26
26
|
}
|
|
27
|
+
|
|
28
|
+
/** The heading of one user message in the main agent's view of a turn. */
|
|
29
|
+
export function userMessageHeading(index: number, count: number): string {
|
|
30
|
+
return count === 1 ? "The user's message:" : `The user's message ${index + 1} of ${count}:`;
|
|
31
|
+
}
|
package/src/run/run-file.ts
CHANGED
|
@@ -167,6 +167,7 @@ function parseSnapshot(data: unknown, file: string): RunSnapshot {
|
|
|
167
167
|
!snapshot ||
|
|
168
168
|
typeof snapshot.runId !== "string" ||
|
|
169
169
|
typeof snapshot.name !== "string" ||
|
|
170
|
+
(snapshot.title !== undefined && typeof snapshot.title !== "string") ||
|
|
170
171
|
typeof snapshot.task !== "string" ||
|
|
171
172
|
typeof snapshot.model !== "string" ||
|
|
172
173
|
typeof snapshot.cwd !== "string" ||
|