pi-famulus 0.2.2 → 0.2.3
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 +3 -2
- package/package.json +7 -7
- package/src/format.ts +43 -0
- package/src/index.ts +170 -18
- package/src/intercom/intercom.ts +19 -22
- package/src/manager-client.ts +1 -1
- package/src/monitor-batching.ts +562 -13
- package/src/monitor.ts +124 -32
- package/src/notify.ts +428 -14
- package/src/prompts.generated.ts +11 -5
- package/src/task-tools.ts +20 -1
- package/src/tui/famulus-command.ts +5 -30
- package/src/tui/message-renderers.ts +30 -0
- package/src/wake.ts +110 -13
|
@@ -7,7 +7,7 @@ import { dirname } from "node:path";
|
|
|
7
7
|
import { stripVTControlCharacters } from "node:util";
|
|
8
8
|
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
9
9
|
import { ManagerError, type ManagerClient, type MessagingStatus } from "../manager-client";
|
|
10
|
-
import { SETTINGS_SECTIONS, listTheme,
|
|
10
|
+
import { SETTINGS_SECTIONS, listTheme, sectionPage } from "./famulus-settings";
|
|
11
11
|
import { loadPiTui, truncateToWidth, wrapTextWithAnsi } from "./pi-tui-load";
|
|
12
12
|
|
|
13
13
|
export interface FamulusCommandDeps {
|
|
@@ -52,7 +52,7 @@ export function formatMessaging(info: FamulusInfo): string {
|
|
|
52
52
|
const m = info.messaging;
|
|
53
53
|
if (!m) return info.daemon ? "not reported by this manager" : "unknown (manager not connected)";
|
|
54
54
|
const state = RELAY_STATES[m.state] ?? "unavailable";
|
|
55
|
-
let label = m.name && RELAY_STATES[m.state] ? `${state} ·
|
|
55
|
+
let label = m.name && RELAY_STATES[m.state] ? `${state} · ${singleLine(m.name)}` : state;
|
|
56
56
|
if (m.state === "disconnected" && typeof m.retry_at_ms === "number") {
|
|
57
57
|
const seconds = Math.ceil((m.retry_at_ms - Date.now()) / 1000);
|
|
58
58
|
label += seconds > 0 ? ` · retry in ${seconds}s` : " · retrying";
|
|
@@ -145,7 +145,7 @@ export async function collectFamulusInfo(deps: FamulusCommandDeps): Promise<Famu
|
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
type OverviewChoice = "
|
|
148
|
+
type OverviewChoice = "reload" | "reconnect" | undefined;
|
|
149
149
|
|
|
150
150
|
/** Whether "Reconnect messaging now" makes sense for what the manager reported. */
|
|
151
151
|
const canReconnect = (m: MessagingStatus | null) => m?.state === "disconnected" || m?.state === "unavailable";
|
|
@@ -206,13 +206,6 @@ function showOverview(
|
|
|
206
206
|
currentValue: "",
|
|
207
207
|
values: [""],
|
|
208
208
|
}] : []),
|
|
209
|
-
{
|
|
210
|
-
id: "edit-raw",
|
|
211
|
-
label: "Edit config.json",
|
|
212
|
-
description: "The whole file in the editor, for webhook endpoints and anything not listed",
|
|
213
|
-
currentValue: "",
|
|
214
|
-
values: [""],
|
|
215
|
-
},
|
|
216
209
|
{ id: "reload", label: "Reload extension", description: "Apply extension settings now", currentValue: "", values: [""] },
|
|
217
210
|
];
|
|
218
211
|
const list = new piTui.SettingsList(
|
|
@@ -220,7 +213,7 @@ function showOverview(
|
|
|
220
213
|
10,
|
|
221
214
|
listTheme(theme),
|
|
222
215
|
(id) => {
|
|
223
|
-
if (id === "
|
|
216
|
+
if (id === "reload" || id === "reconnect") done(id);
|
|
224
217
|
},
|
|
225
218
|
() => done(undefined),
|
|
226
219
|
);
|
|
@@ -272,25 +265,7 @@ export function registerFamulusCommand(pi: ExtensionAPI, deps: FamulusCommandDep
|
|
|
272
265
|
await ctx.reload();
|
|
273
266
|
return;
|
|
274
267
|
}
|
|
275
|
-
|
|
276
|
-
let current: string;
|
|
277
|
-
try {
|
|
278
|
-
current = readConfigText(deps.configPath);
|
|
279
|
-
} catch (error) {
|
|
280
|
-
ctx.ui.notify(`Cannot read ${deps.configPath}: ${(error as Error).message}`, "error");
|
|
281
|
-
continue;
|
|
282
|
-
}
|
|
283
|
-
const edited = await ctx.ui.editor(`Edit ${deps.configPath}`, current);
|
|
284
|
-
if (edited === undefined) continue;
|
|
285
|
-
try {
|
|
286
|
-
writeConfigText(deps.configPath, edited);
|
|
287
|
-
ctx.ui.notify(
|
|
288
|
-
`Saved ${deps.configPath}. Reload the extension for extension settings; restart the manager daemon for messaging settings.`,
|
|
289
|
-
"info",
|
|
290
|
-
);
|
|
291
|
-
} catch (error) {
|
|
292
|
-
ctx.ui.notify(`Configuration was not saved: ${(error as Error).message}`, "error");
|
|
293
|
-
}
|
|
268
|
+
return;
|
|
294
269
|
}
|
|
295
270
|
},
|
|
296
271
|
});
|
|
@@ -117,6 +117,17 @@ function collapsedText(details: FamulusWake, theme: Theme): string {
|
|
|
117
117
|
].join("\n");
|
|
118
118
|
case "supervisor-update":
|
|
119
119
|
return `${theme.fg("muted", "↑")} ${theme.fg("muted", "supervisor update")} ${details.message.slice(0, 100)}`;
|
|
120
|
+
case "monitor-session-end": {
|
|
121
|
+
const n = details.ids.length || details.monitors.length;
|
|
122
|
+
return `${theme.fg("warning", "✗")} ${theme.fg("muted", "session monitors")} ${n} stopped · ${details.reason}`;
|
|
123
|
+
}
|
|
124
|
+
case "running-monitors":
|
|
125
|
+
return `${theme.fg("accent", "›")} ${theme.fg("muted", "running")} ${details.monitors.length} monitor${details.monitors.length === 1 ? "" : "s"}`;
|
|
126
|
+
case "monitor-terminal": {
|
|
127
|
+
const n = details.ids.length || details.monitors.length;
|
|
128
|
+
const statuses = countStatuses(details.monitors.map((monitor) => monitor.status));
|
|
129
|
+
return `${theme.fg("warning", "✗")} ${theme.fg("muted", "monitors")} ${n} stopped · ${statuses}`;
|
|
130
|
+
}
|
|
120
131
|
}
|
|
121
132
|
}
|
|
122
133
|
|
|
@@ -195,6 +206,25 @@ export function expandedWakeText(details: FamulusWake | undefined, content: stri
|
|
|
195
206
|
return [`Decision requested by ${details.name} (${details.from})`, `Request: ${details.message}`, `Reply with /reply ${details.from} <decision>`].join("\n");
|
|
196
207
|
case "supervisor-update":
|
|
197
208
|
return [`Update from ${details.name} (${details.from})`, details.message].join("\n");
|
|
209
|
+
case "monitor-session-end":
|
|
210
|
+
return [
|
|
211
|
+
`Session monitors stopped (${details.reason}). They are no longer watched.`,
|
|
212
|
+
...details.monitors.map((monitor) =>
|
|
213
|
+
`${monitor.id} "${monitor.description}" elapsed ${formatDuration(monitor.elapsedMs)}; original output: task_output({task_id: "${monitor.id}"}) ${monitor.outputPath} while the log is retained`,
|
|
214
|
+
),
|
|
215
|
+
].join("\n");
|
|
216
|
+
case "running-monitors":
|
|
217
|
+
return [
|
|
218
|
+
`Still running after compaction (${details.monitors.length})`,
|
|
219
|
+
...details.monitors.map((monitor) => `${monitor.id} — ${monitor.description} — ${monitor.remaining}`),
|
|
220
|
+
].join("\n");
|
|
221
|
+
case "monitor-terminal":
|
|
222
|
+
return [
|
|
223
|
+
details.summary,
|
|
224
|
+
...details.monitors.map((monitor) =>
|
|
225
|
+
`${monitor.id} "${monitor.description}" · ${monitor.status}${monitor.detail ? `: ${monitor.detail}` : ""}`,
|
|
226
|
+
),
|
|
227
|
+
].join("\n");
|
|
198
228
|
}
|
|
199
229
|
}
|
|
200
230
|
|
package/src/wake.ts
CHANGED
|
@@ -166,7 +166,30 @@ type FamulusWakeBody =
|
|
|
166
166
|
additional?: SubagentOverrunChild[];
|
|
167
167
|
}
|
|
168
168
|
| { kind: "supervisor-request"; from: string; name: string; message: string }
|
|
169
|
-
| { kind: "supervisor-update"; from: string; name: string; message: string }
|
|
169
|
+
| { kind: "supervisor-update"; from: string; name: string; message: string }
|
|
170
|
+
| {
|
|
171
|
+
kind: "monitor-session-end";
|
|
172
|
+
reason: "new" | "resumed" | "forked" | "handoff-ended" | "session-mismatch";
|
|
173
|
+
ids: string[];
|
|
174
|
+
monitors: Array<{ id: string; description: string; elapsedMs: number; outputPath: string }>;
|
|
175
|
+
}
|
|
176
|
+
| {
|
|
177
|
+
kind: "running-monitors";
|
|
178
|
+
monitors: { id: string; description: string; remaining: string }[];
|
|
179
|
+
}
|
|
180
|
+
| {
|
|
181
|
+
kind: "monitor-terminal";
|
|
182
|
+
ids: string[];
|
|
183
|
+
summary: string;
|
|
184
|
+
monitors: Array<{
|
|
185
|
+
id: string;
|
|
186
|
+
description: string;
|
|
187
|
+
status: "timeout" | "exited" | "stopped";
|
|
188
|
+
detail: string;
|
|
189
|
+
droppedLines?: number;
|
|
190
|
+
output?: MonitorOutputInfo;
|
|
191
|
+
}>;
|
|
192
|
+
};
|
|
170
193
|
|
|
171
194
|
export interface FormattedWake {
|
|
172
195
|
customType: typeof FAMULUS_WAKE_CUSTOM_TYPE;
|
|
@@ -207,8 +230,16 @@ export function wakeIds(details: { kind?: string }): string[] {
|
|
|
207
230
|
from?: string;
|
|
208
231
|
};
|
|
209
232
|
if (d.kind === "task") return (d.tasks ?? []).map((task) => task.id);
|
|
233
|
+
if (d.kind === "running-monitors") {
|
|
234
|
+
return ((details as { monitors?: { id: string }[] }).monitors ?? []).map((monitor) => monitor.id);
|
|
235
|
+
}
|
|
210
236
|
if (d.kind === "subagent-done") return (d.children ?? []).map((child) => child.childId);
|
|
211
237
|
if (d.kind === "subagent-overrun") return [d.childId, ...((d as { additional?: { childId: string }[] }).additional ?? []).map((child) => child.childId)].filter((id): id is string => Boolean(id));
|
|
238
|
+
if (d.kind === "monitor-session-end" || d.kind === "monitor-terminal") {
|
|
239
|
+
const ids = (d as { ids?: string[] }).ids;
|
|
240
|
+
if (ids && ids.length > 0) return ids;
|
|
241
|
+
return ((d as { monitors?: { id: string }[] }).monitors ?? []).map((monitor) => monitor.id);
|
|
242
|
+
}
|
|
212
243
|
return [d.id ?? d.taskId ?? d.childId ?? d.from].filter((id): id is string => Boolean(id));
|
|
213
244
|
}
|
|
214
245
|
|
|
@@ -284,6 +315,12 @@ function renderWakeBody(details: FamulusWake): string {
|
|
|
284
315
|
return renderRequest(details);
|
|
285
316
|
case "supervisor-update":
|
|
286
317
|
return renderUpdate(details);
|
|
318
|
+
case "monitor-session-end":
|
|
319
|
+
return renderMonitorSessionEnd(details);
|
|
320
|
+
case "running-monitors":
|
|
321
|
+
return renderRunningMonitors(details);
|
|
322
|
+
case "monitor-terminal":
|
|
323
|
+
return renderMonitorTerminal(details);
|
|
287
324
|
}
|
|
288
325
|
}
|
|
289
326
|
|
|
@@ -317,6 +354,19 @@ function renderTask(details: Extract<FamulusWake, { kind: "task" }>): string {
|
|
|
317
354
|
return parts.join("\n");
|
|
318
355
|
}
|
|
319
356
|
|
|
357
|
+
function renderMonitorOutputElement(output: MonitorOutputInfo | undefined, indent: string): string | undefined {
|
|
358
|
+
if (output?.cursorStart === undefined) return undefined;
|
|
359
|
+
const fields: string[] = [];
|
|
360
|
+
if (output.firstObservedAt !== undefined) fields.push(`first-observed-at="${wakeTimestamp(output.firstObservedAt)}"`);
|
|
361
|
+
if (output.lastObservedAt !== undefined) fields.push(`last-observed-at="${wakeTimestamp(output.lastObservedAt)}"`);
|
|
362
|
+
fields.push(`cursor-start="${output.cursorStart}"`);
|
|
363
|
+
if (output.cursorEnd !== undefined) fields.push(`cursor-end="${output.cursorEnd}"`);
|
|
364
|
+
if (output.truncated) fields.push('truncated="true"');
|
|
365
|
+
if (output.suppressedCount) fields.push(`duplicates-suppressed="${output.suppressedCount}"`);
|
|
366
|
+
if (output.omittedChars) fields.push(`omitted-chars="${output.omittedChars}"`);
|
|
367
|
+
return `${indent}<output ${fields.join(" ")}>${escapeXml(PROMPTS["wakes.monitor.output-hint"])}</output>`;
|
|
368
|
+
}
|
|
369
|
+
|
|
320
370
|
function renderMonitor(details: Extract<FamulusWake, { kind: "monitor" }>): string {
|
|
321
371
|
const attrs = [
|
|
322
372
|
'kind="monitor"',
|
|
@@ -328,19 +378,9 @@ function renderMonitor(details: Extract<FamulusWake, { kind: "monitor" }>): stri
|
|
|
328
378
|
if (details.droppedLines !== undefined && details.droppedLines > 0) {
|
|
329
379
|
attrs.push(`dropped-lines="${details.droppedLines}"`);
|
|
330
380
|
}
|
|
331
|
-
const output = details.output;
|
|
332
381
|
const parts = [`<pi-famulus-wake ${attrs.join(" ")}>`, ` <event>${escapeXml(details.event)}</event>`];
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
if (output.firstObservedAt !== undefined) fields.push(`first-observed-at="${wakeTimestamp(output.firstObservedAt)}"`);
|
|
336
|
-
if (output.lastObservedAt !== undefined) fields.push(`last-observed-at="${wakeTimestamp(output.lastObservedAt)}"`);
|
|
337
|
-
fields.push(`cursor-start="${output.cursorStart}"`);
|
|
338
|
-
if (output.cursorEnd !== undefined) fields.push(`cursor-end="${output.cursorEnd}"`);
|
|
339
|
-
if (output.truncated) fields.push('truncated="true"');
|
|
340
|
-
if (output.suppressedCount) fields.push(`duplicates-suppressed="${output.suppressedCount}"`);
|
|
341
|
-
if (output.omittedChars) fields.push(`omitted-chars="${output.omittedChars}"`);
|
|
342
|
-
parts.push(` <output ${fields.join(" ")}>${escapeXml(PROMPTS["wakes.monitor.output-hint"])}</output>`);
|
|
343
|
-
}
|
|
382
|
+
const outputXml = renderMonitorOutputElement(details.output, " ");
|
|
383
|
+
if (outputXml) parts.push(outputXml);
|
|
344
384
|
parts.push("</pi-famulus-wake>");
|
|
345
385
|
return parts.join("\n");
|
|
346
386
|
}
|
|
@@ -499,6 +539,20 @@ function renderRequest(details: Extract<FamulusWake, { kind: "supervisor-request
|
|
|
499
539
|
].join("\n");
|
|
500
540
|
}
|
|
501
541
|
|
|
542
|
+
function renderRunningMonitors(details: Extract<FamulusWake, { kind: "running-monitors" }>): string {
|
|
543
|
+
const parts = [
|
|
544
|
+
'<pi-famulus-wake kind="running-monitors">',
|
|
545
|
+
PROMPTS["wakes.running-monitors.guidance"],
|
|
546
|
+
];
|
|
547
|
+
for (const monitor of details.monitors) {
|
|
548
|
+
parts.push(
|
|
549
|
+
` <monitor id="${escapeXmlAttr(monitor.id)}" remaining="${escapeXmlAttr(monitor.remaining)}">${escapeXml(monitor.description)}</monitor>`,
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
parts.push("</pi-famulus-wake>");
|
|
553
|
+
return parts.join("\n");
|
|
554
|
+
}
|
|
555
|
+
|
|
502
556
|
function renderUpdate(details: Extract<FamulusWake, { kind: "supervisor-update" }>): string {
|
|
503
557
|
return [
|
|
504
558
|
`<pi-famulus-wake kind="supervisor-update" from="${escapeXmlAttr(details.from)}" name="${escapeXmlAttr(details.name)}">`,
|
|
@@ -506,3 +560,46 @@ function renderUpdate(details: Extract<FamulusWake, { kind: "supervisor-update"
|
|
|
506
560
|
"</pi-famulus-wake>",
|
|
507
561
|
].join("\n");
|
|
508
562
|
}
|
|
563
|
+
|
|
564
|
+
function renderMonitorTerminal(details: Extract<FamulusWake, { kind: "monitor-terminal" }>): string {
|
|
565
|
+
const parts = [
|
|
566
|
+
`<pi-famulus-wake kind="monitor-terminal">`,
|
|
567
|
+
` <summary>${escapeXml(details.summary)}</summary>`,
|
|
568
|
+
];
|
|
569
|
+
for (const monitor of details.monitors) {
|
|
570
|
+
const attrs = [
|
|
571
|
+
`id="${escapeXmlAttr(monitor.id)}"`,
|
|
572
|
+
`description="${escapeXmlAttr(monitor.description)}"`,
|
|
573
|
+
`status="${escapeXmlAttr(monitor.status)}"`,
|
|
574
|
+
];
|
|
575
|
+
if (monitor.droppedLines !== undefined && monitor.droppedLines > 0) {
|
|
576
|
+
attrs.push(`dropped-lines="${monitor.droppedLines}"`);
|
|
577
|
+
}
|
|
578
|
+
const outputXml = renderMonitorOutputElement(monitor.output, " ");
|
|
579
|
+
if (outputXml) {
|
|
580
|
+
parts.push(` <monitor ${attrs.join(" ")}>`);
|
|
581
|
+
if (monitor.detail) parts.push(` ${escapeXml(monitor.detail)}`);
|
|
582
|
+
parts.push(outputXml);
|
|
583
|
+
parts.push(" </monitor>");
|
|
584
|
+
} else {
|
|
585
|
+
parts.push(` <monitor ${attrs.join(" ")}>${escapeXml(monitor.detail)}</monitor>`);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
parts.push("</pi-famulus-wake>");
|
|
589
|
+
return parts.join("\n");
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function renderMonitorSessionEnd(details: Extract<FamulusWake, { kind: "monitor-session-end" }>): string {
|
|
593
|
+
const parts = [
|
|
594
|
+
`<pi-famulus-wake kind="monitor-session-end" reason="${escapeXmlAttr(details.reason)}">`,
|
|
595
|
+
` <summary>${escapeXml(`These monitors stopped (${details.reason}). They are no longer watched.`)}</summary>`,
|
|
596
|
+
];
|
|
597
|
+
for (const monitor of details.monitors) {
|
|
598
|
+
const pointer = `task_output({task_id: "${monitor.id}"}) ${monitor.outputPath} while the log is retained`;
|
|
599
|
+
parts.push(
|
|
600
|
+
` <monitor id="${escapeXmlAttr(monitor.id)}" description="${escapeXmlAttr(monitor.description)}" elapsed-ms="${Math.round(monitor.elapsedMs)}">${escapeXml(pointer)}</monitor>`,
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
parts.push("</pi-famulus-wake>");
|
|
604
|
+
return parts.join("\n");
|
|
605
|
+
}
|