@lune_99/pi-subagent 0.0.0-stage → 0.1.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 +24 -0
- package/LICENSE +21 -0
- package/README.md +169 -2
- package/docs/capture.json +30 -0
- package/docs/previews.md +22 -0
- package/docs/reference.md +240 -0
- package/docs/subagent-auto-tiers.png +0 -0
- package/docs/subagent-inspector.png +0 -0
- package/docs/subagent-overview.png +0 -0
- package/package.json +82 -5
- package/skills/create-lune-subagent/SKILL.md +186 -0
- package/src/auto-model.ts +592 -0
- package/src/catalog.ts +111 -0
- package/src/definition-file.ts +112 -0
- package/src/definitions.ts +324 -0
- package/src/dock/dock-alert.ts +78 -0
- package/src/dock/dock-contribution.ts +318 -0
- package/src/extension-tools.ts +46 -0
- package/src/index.ts +168 -0
- package/src/inspector/details.ts +113 -0
- package/src/inspector/inspector.ts +653 -0
- package/src/inspector/layout.ts +119 -0
- package/src/inspector/transcript.ts +735 -0
- package/src/inspector/viewport.ts +62 -0
- package/src/inspector/wrap.ts +136 -0
- package/src/models.ts +54 -0
- package/src/notify/notification-box.ts +381 -0
- package/src/notify/notifier.ts +569 -0
- package/src/paths.ts +34 -0
- package/src/render/lune-theme.ts +68 -0
- package/src/render/text.ts +121 -0
- package/src/run/guide.ts +26 -0
- package/src/run/report-tool.ts +90 -0
- package/src/run/run-file.ts +193 -0
- package/src/run/run-manager.ts +838 -0
- package/src/run/run-session.ts +307 -0
- package/src/run/run.ts +681 -0
- package/src/run/session-start.ts +283 -0
- package/src/run/types.ts +167 -0
- package/src/run/worktree.ts +138 -0
- package/src/schema.ts +9 -0
- package/src/settings/agents-menu.ts +363 -0
- package/src/settings/panel.ts +179 -0
- package/src/settings/schema.ts +71 -0
- package/src/tools/format.ts +375 -0
- package/src/tools/subagent-tools.ts +467 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import type { Run } from "../run/run.ts";
|
|
2
|
+
import type { AutoRating, AutoRisk, RunSnapshot, RunUsage, TurnRecord } from "../run/types.ts";
|
|
3
|
+
|
|
4
|
+
/** How much of a summary or task a run list shows; one run shows all of it. */
|
|
5
|
+
const PREVIEW_CHARS = 200;
|
|
6
|
+
const DIAGNOSTICS_SHOWN = 5;
|
|
7
|
+
|
|
8
|
+
/** The workspace lines `subagent_start` and `subagent_status` return. */
|
|
9
|
+
export function workspaceLines(run: Run): string[] {
|
|
10
|
+
const snapshot = run.snapshot;
|
|
11
|
+
|
|
12
|
+
if (!snapshot) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const lines = [`Isolation: ${snapshot.isolation}`, `Working directory: ${snapshot.cwd}`];
|
|
17
|
+
|
|
18
|
+
if (snapshot.worktree) {
|
|
19
|
+
lines.push(
|
|
20
|
+
`Worktree: ${snapshot.worktree.path}`,
|
|
21
|
+
`Base commit: ${snapshot.worktree.baseCommit}`,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return lines;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The start values and where each came from. */
|
|
29
|
+
export function startValueLines(run: Run): string[] {
|
|
30
|
+
const snapshot = run.snapshot;
|
|
31
|
+
|
|
32
|
+
if (!snapshot) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return [
|
|
37
|
+
`Agent: ${snapshot.definition ? snapshot.definition.name : "inline"}`,
|
|
38
|
+
`Model: ${snapshot.model} (${modelOrigin(snapshot)})`,
|
|
39
|
+
`Thinking: ${snapshot.thinking} (${thinkingOrigin(snapshot)})`,
|
|
40
|
+
`Tools: ${snapshot.tools.join(", ")} (from ${snapshot.sources.tools})`,
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function modelOrigin(snapshot: RunSnapshot): string {
|
|
45
|
+
const auto = snapshot.autoModel;
|
|
46
|
+
|
|
47
|
+
if (!auto) {
|
|
48
|
+
return `from ${snapshot.sources.model}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const origin = `auto from ${snapshot.sources.model}`;
|
|
52
|
+
|
|
53
|
+
switch (auto.by) {
|
|
54
|
+
case "rating": {
|
|
55
|
+
const { tier, modelFrom, risk } = auto;
|
|
56
|
+
const lowest = risk?.floor ?? tier.used;
|
|
57
|
+
const model =
|
|
58
|
+
modelFrom === lowest
|
|
59
|
+
? `the ${lowest} tier's model`
|
|
60
|
+
: modelFrom === "main"
|
|
61
|
+
? `no tier from ${lowest} up has a model, so the main agent's model`
|
|
62
|
+
: `the ${lowest} tier has no model, so the ${modelFrom} tier's model`;
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
`${origin}: the classifier ${auto.classifier} rated the task ${ratingText(tier)}` +
|
|
66
|
+
(risk ? `, ${riskText(risk)}` : "") +
|
|
67
|
+
`; ${model}`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
case "no-classifier":
|
|
71
|
+
return `${origin}: no classifier is selected, so the main agent's model`;
|
|
72
|
+
case "nothing-to-rate":
|
|
73
|
+
return `${origin}: no auto tier has a model and the thinking is set, so the main agent's model`;
|
|
74
|
+
case "classifier-failed":
|
|
75
|
+
return `${origin}: the main agent's model. ${auto.error}`;
|
|
76
|
+
default:
|
|
77
|
+
// A run that an earlier version started records its auto choice in another form.
|
|
78
|
+
return origin;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function thinkingOrigin(snapshot: RunSnapshot): string {
|
|
83
|
+
const auto = snapshot.autoModel;
|
|
84
|
+
|
|
85
|
+
return snapshot.sources.thinking === "auto" && auto?.by === "rating" && auto.thinking
|
|
86
|
+
? `auto: the classifier rated the thinking ${ratingText(auto.thinking)}`
|
|
87
|
+
: `from ${snapshot.sources.thinking}`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** `complex (71%)`, and the level used instead when the classifier was unsure. */
|
|
91
|
+
export function ratingText(rating: AutoRating<string>): string {
|
|
92
|
+
const share = rating.probabilities[rating.rated];
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
rating.rated +
|
|
96
|
+
(share === undefined ? "" : ` (${formatPercent(share)})`) +
|
|
97
|
+
(rating.used === rating.rated
|
|
98
|
+
? ""
|
|
99
|
+
: `, unsure at ${formatPercent(rating.confidence)} confidence, so ${rating.used}`)
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** `high risk (72%), so at least the deep tier`, or `not high risk (12%)`. */
|
|
104
|
+
export function riskText(risk: AutoRisk): string {
|
|
105
|
+
return risk.high
|
|
106
|
+
? `high risk (${formatPercent(risk.probability)})` +
|
|
107
|
+
(risk.floor ? `, so at least the ${risk.floor} tier` : "")
|
|
108
|
+
: `not high risk (${formatPercent(risk.probability)})`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** One entry of a `tasks` call: the run it started, or why it did not start. */
|
|
112
|
+
export type StartOutcome = { run: Run } | { error: string };
|
|
113
|
+
|
|
114
|
+
export function formatStarted(run: Run): string {
|
|
115
|
+
return [
|
|
116
|
+
startedHeading(run),
|
|
117
|
+
...startValueLines(run),
|
|
118
|
+
...workspaceLines(run),
|
|
119
|
+
"The run works in the background. A message arrives when its turn ends.",
|
|
120
|
+
].join("\n");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** A `tasks` call: a summary, then one block per entry, named by its index in `tasks`. */
|
|
124
|
+
export function formatStartedBatch(outcomes: readonly StartOutcome[]): string {
|
|
125
|
+
const started = outcomes.flatMap((outcome) => ("run" in outcome ? [outcome.run] : []));
|
|
126
|
+
const failed = outcomes.flatMap((outcome, index) =>
|
|
127
|
+
"error" in outcome ? [`tasks[${index}]`] : [],
|
|
128
|
+
);
|
|
129
|
+
const blocks = outcomes.map((outcome, index) =>
|
|
130
|
+
"error" in outcome
|
|
131
|
+
? `tasks[${index}] failed: ${outcome.error}`
|
|
132
|
+
: [
|
|
133
|
+
`tasks[${index}]: ${startedHeading(outcome.run)}`,
|
|
134
|
+
...startValueLines(outcome.run),
|
|
135
|
+
...workspaceLines(outcome.run),
|
|
136
|
+
].join("\n"),
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
if (started.length === 0) {
|
|
140
|
+
return ["No run started; every entry of tasks failed.", ...blocks].join("\n\n");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const count = started.length === outcomes.length ? "" : `${started.length} of `;
|
|
144
|
+
const summary =
|
|
145
|
+
`Started ${count}${outcomes.length} run${outcomes.length === 1 ? "" : "s"}: ` +
|
|
146
|
+
`${started.map((run) => `${run.name} (${run.id})`).join(", ")}.` +
|
|
147
|
+
(failed.length > 0 ? ` Failed: ${failed.join(", ")}.` : "");
|
|
148
|
+
|
|
149
|
+
return [
|
|
150
|
+
summary,
|
|
151
|
+
...blocks,
|
|
152
|
+
started.length === 1
|
|
153
|
+
? "The run works in the background. A message arrives when its turn ends."
|
|
154
|
+
: "The runs work in the background. A message arrives when each run's turn ends.",
|
|
155
|
+
].join("\n\n");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** One run in full: everything `subagent_status` knows, the last turn's whole report included. */
|
|
159
|
+
export function formatRunStatus(run: Run): string {
|
|
160
|
+
const lines = [heading(run)];
|
|
161
|
+
|
|
162
|
+
if (run.loadError) {
|
|
163
|
+
lines.push(`The run file could not be read: ${run.loadError}`);
|
|
164
|
+
|
|
165
|
+
return lines.join("\n");
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
lines.push(...startValueLines(run), ...workspaceLines(run));
|
|
169
|
+
lines.push(`Turns: ${run.turns}`, `Usage: ${formatUsage(run.usage)}`);
|
|
170
|
+
lines.push(...runningLines(run));
|
|
171
|
+
lines.push(...diagnosticLines(run));
|
|
172
|
+
lines.push("", "Task:", run.snapshot?.task ?? "");
|
|
173
|
+
|
|
174
|
+
if (run.lastTurn) {
|
|
175
|
+
lines.push("", ...turnLines(run.lastTurn, false));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return lines.join("\n");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** The runs of the current branch, one block each, with previews instead of whole reports. */
|
|
182
|
+
export function formatRunList(runs: readonly Run[], elsewhere: number): string {
|
|
183
|
+
const blocks = runs.map((run) => {
|
|
184
|
+
if (run.loadError) {
|
|
185
|
+
return [heading(run), `The run file could not be read: ${run.loadError}`].join("\n");
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return [
|
|
189
|
+
heading(run),
|
|
190
|
+
...startValueLines(run).slice(0, 1),
|
|
191
|
+
...workspaceLines(run),
|
|
192
|
+
`Turns: ${run.turns} · Usage: ${formatUsage(run.usage)}`,
|
|
193
|
+
...runningLines(run),
|
|
194
|
+
...diagnosticLines(run),
|
|
195
|
+
...(run.lastTurn ? turnLines(run.lastTurn, true) : []),
|
|
196
|
+
].join("\n");
|
|
197
|
+
});
|
|
198
|
+
const notes: string[] = [];
|
|
199
|
+
|
|
200
|
+
if (runs.length === 0) {
|
|
201
|
+
notes.push("No subagent runs on the current branch.");
|
|
202
|
+
} else {
|
|
203
|
+
notes.push("Call subagent_status with a runId for a run's whole report.");
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (elsewhere > 0) {
|
|
207
|
+
notes.push(
|
|
208
|
+
`${elsewhere} run${elsewhere === 1 ? " belongs" : "s belong"} to other branches and ` +
|
|
209
|
+
`${elsewhere === 1 ? "is" : "are"} not listed.`,
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return [...blocks, notes.join(" ")].join("\n\n");
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function formatUsage(usage: RunUsage): string {
|
|
217
|
+
return [
|
|
218
|
+
`${formatTokens(usage.input)} input`,
|
|
219
|
+
`${formatTokens(usage.output)} output`,
|
|
220
|
+
`${formatTokens(usage.cacheRead)} cache read`,
|
|
221
|
+
`${formatTokens(usage.cacheWrite)} cache write`,
|
|
222
|
+
`$${usage.cost.toFixed(3)}`,
|
|
223
|
+
].join(" · ");
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function formatTokens(count: number): string {
|
|
227
|
+
if (count < 1000) {
|
|
228
|
+
return String(count);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (count < 1_000_000) {
|
|
232
|
+
return `${(count / 1000).toFixed(1)}k`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return `${(count / 1_000_000).toFixed(1)}M`;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** `4.2s` / `1m 4s` / `1h 2m`. */
|
|
239
|
+
export function formatDuration(ms: number): string {
|
|
240
|
+
const seconds = ms / 1000;
|
|
241
|
+
|
|
242
|
+
if (seconds < 60) {
|
|
243
|
+
return `${seconds.toFixed(1)}s`;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const totalSeconds = Math.floor(seconds);
|
|
247
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
248
|
+
|
|
249
|
+
if (minutes < 60) {
|
|
250
|
+
return `${minutes}m ${totalSeconds % 60}s`;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return `${Math.floor(minutes / 60)}h ${minutes % 60}m`;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** `82%`: a value from 0 to 1 as a whole percentage. */
|
|
257
|
+
export function formatPercent(value: number): string {
|
|
258
|
+
return `${Math.round(value * 100)}%`;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function heading(run: Run): string {
|
|
262
|
+
return `Run ${run.name} (${run.id}): ${run.state}${run.readOnly ? ", read-only" : ""}`;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function startedHeading(run: Run): string {
|
|
266
|
+
return `Started run ${run.name} (${run.id}): ${run.state}.`;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function runningLines(run: Run): string[] {
|
|
270
|
+
if (run.state !== "running") {
|
|
271
|
+
return [];
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const started = run.turnStartedAt;
|
|
275
|
+
const lines = [
|
|
276
|
+
started
|
|
277
|
+
? `Turn running for ${formatDuration(Date.now() - Date.parse(started))}`
|
|
278
|
+
: "Turn running",
|
|
279
|
+
];
|
|
280
|
+
|
|
281
|
+
if (run.activity) {
|
|
282
|
+
lines.push(run.activity);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return lines;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function diagnosticLines(run: Run): string[] {
|
|
289
|
+
const shown = run.diagnostics
|
|
290
|
+
.filter((diagnostic) => diagnostic.level !== "info")
|
|
291
|
+
.slice(-DIAGNOSTICS_SHOWN);
|
|
292
|
+
|
|
293
|
+
if (shown.length === 0) {
|
|
294
|
+
return [];
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return [
|
|
298
|
+
"Diagnostics:",
|
|
299
|
+
...shown.map((diagnostic) => ` ${diagnostic.level}: ${diagnostic.message}`),
|
|
300
|
+
];
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function turnLines(turn: TurnRecord, preview: boolean): string[] {
|
|
304
|
+
const duration = Date.parse(turn.endedAt) - Date.parse(turn.startedAt);
|
|
305
|
+
const lines = [
|
|
306
|
+
`Last turn: ${turn.state}, ended ${turn.endedAt}` +
|
|
307
|
+
(Number.isFinite(duration) ? ` after ${formatDuration(duration)}` : ""),
|
|
308
|
+
];
|
|
309
|
+
|
|
310
|
+
if (turn.stoppedBy) {
|
|
311
|
+
lines.push(`Stopped by: ${turn.stoppedBy}`);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (turn.userWrote) {
|
|
315
|
+
lines.push("The user wrote to the run during that turn.");
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (turn.error) {
|
|
319
|
+
lines.push(`Error: ${turn.error}`);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
for (const earlier of turn.earlierReports ?? []) {
|
|
323
|
+
lines.push(`Earlier report in that turn, replaced by a later one: ${earlier.status}`);
|
|
324
|
+
|
|
325
|
+
if (preview) {
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (earlier.reason) {
|
|
330
|
+
lines.push(`Reason: ${earlier.reason}`);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (earlier.question) {
|
|
334
|
+
lines.push(`Question: ${earlier.question}`);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
lines.push("Summary:", earlier.summary, "");
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (turn.report) {
|
|
341
|
+
lines.push(`Report: ${turn.report.status}`);
|
|
342
|
+
|
|
343
|
+
if (turn.report.reason) {
|
|
344
|
+
lines.push(`Reason: ${turn.report.reason}`);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (turn.report.question) {
|
|
348
|
+
lines.push(`Question: ${turn.report.question}`);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
lines.push(preview ? `Summary: ${clip(turn.report.summary)}` : "Summary:");
|
|
352
|
+
|
|
353
|
+
if (!preview) {
|
|
354
|
+
lines.push(turn.report.summary);
|
|
355
|
+
}
|
|
356
|
+
} else {
|
|
357
|
+
const message = turn.unreportedMessage ?? "";
|
|
358
|
+
|
|
359
|
+
lines.push("Unreported: the turn ended without a report, so it has no task status.");
|
|
360
|
+
|
|
361
|
+
if (preview) {
|
|
362
|
+
lines.push(`Last message: ${message === "" ? "none" : clip(message)}`);
|
|
363
|
+
} else {
|
|
364
|
+
lines.push(message === "" ? "The run left no message." : "Last message:", message);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
return lines;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function clip(text: string): string {
|
|
372
|
+
const line = text.replace(/\s+/g, " ").trim();
|
|
373
|
+
|
|
374
|
+
return line.length > PREVIEW_CHARS ? `${line.slice(0, PREVIEW_CHARS)}…` : line;
|
|
375
|
+
}
|