pi-famulus 0.2.2-beta.3 → 0.2.2-beta.4
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/package.json +7 -7
- package/src/intercom/intercom.ts +44 -8
- package/src/manager-client.ts +19 -1
- package/src/tui/famulus-command.ts +58 -5
- package/src/tui/famulus-settings.ts +15 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-famulus",
|
|
3
|
-
"version": "0.2.2-beta.
|
|
3
|
+
"version": "0.2.2-beta.4",
|
|
4
4
|
"description": "Keep your main agent's context clean: subagents on cheaper models, long bash in the background, and monitors that wake the agent. One Rust daemon runs the shells.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -54,12 +54,12 @@
|
|
|
54
54
|
"pi-famulus": "./bin/pi-famulus.js"
|
|
55
55
|
},
|
|
56
56
|
"optionalDependencies": {
|
|
57
|
-
"pi-famulus-linux-x64": "0.2.2-beta.
|
|
58
|
-
"pi-famulus-linux-arm64": "0.2.2-beta.
|
|
59
|
-
"pi-famulus-darwin-x64": "0.2.2-beta.
|
|
60
|
-
"pi-famulus-darwin-arm64": "0.2.2-beta.
|
|
61
|
-
"pi-famulus-win-x64": "0.2.2-beta.
|
|
62
|
-
"pi-famulus-win-arm64": "0.2.2-beta.
|
|
57
|
+
"pi-famulus-linux-x64": "0.2.2-beta.4",
|
|
58
|
+
"pi-famulus-linux-arm64": "0.2.2-beta.4",
|
|
59
|
+
"pi-famulus-darwin-x64": "0.2.2-beta.4",
|
|
60
|
+
"pi-famulus-darwin-arm64": "0.2.2-beta.4",
|
|
61
|
+
"pi-famulus-win-x64": "0.2.2-beta.4",
|
|
62
|
+
"pi-famulus-win-arm64": "0.2.2-beta.4"
|
|
63
63
|
},
|
|
64
64
|
"pi": {
|
|
65
65
|
"extensions": [
|
package/src/intercom/intercom.ts
CHANGED
|
@@ -21,8 +21,9 @@ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-a
|
|
|
21
21
|
import { createRequire } from "node:module";
|
|
22
22
|
import fs from "node:fs";
|
|
23
23
|
import os from "node:os";
|
|
24
|
+
import { stripVTControlCharacters } from "node:util";
|
|
24
25
|
import path from "node:path";
|
|
25
|
-
import { ManagerClient } from "../manager-client";
|
|
26
|
+
import { ManagerClient, type MessagingStatus } from "../manager-client";
|
|
26
27
|
import type { IntercomFrame, SessionRow } from "./types";
|
|
27
28
|
import { createManagerTransport, IntercomError, type IntercomTransport } from "./transport";
|
|
28
29
|
import { ChatCard, ChatText, formatTimestamp } from "./widgets";
|
|
@@ -207,7 +208,11 @@ export function registerIntercom(pi: ExtensionAPI, deps: IntercomDeps): void {
|
|
|
207
208
|
let lastCtx: ExtensionContext | undefined;
|
|
208
209
|
let retryTimer: ReturnType<typeof setInterval> | undefined;
|
|
209
210
|
let manualCompactionRefresh: ReturnType<typeof setTimeout> | undefined;
|
|
210
|
-
let
|
|
211
|
+
let lastMessagingFooter: string | undefined;
|
|
212
|
+
/** The current outage already produced its notice; later texts only update the footer. */
|
|
213
|
+
let outageNotified = false;
|
|
214
|
+
/** A relay outage was reported, so the next healthy status is a recovery. */
|
|
215
|
+
let relayOutage = false;
|
|
211
216
|
let statusCheckEpoch: number | undefined;
|
|
212
217
|
let legacyPluginNotified = false;
|
|
213
218
|
let autocompleteBound = false;
|
|
@@ -278,11 +283,32 @@ export function registerIntercom(pi: ExtensionAPI, deps: IntercomDeps): void {
|
|
|
278
283
|
}
|
|
279
284
|
};
|
|
280
285
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
+
/** Notify once per outage; `footer` (default: the message) is the live status line. */
|
|
287
|
+
function updateMessagingError(message?: string, level: "warning" | "error" = "error", footer = message) {
|
|
288
|
+
if (footer !== lastMessagingFooter) {
|
|
289
|
+
lastMessagingFooter = footer;
|
|
290
|
+
lastCtx?.ui.setStatus?.("famulus-messaging", footer);
|
|
291
|
+
}
|
|
292
|
+
if (!message) {
|
|
293
|
+
outageNotified = false;
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (outageNotified) return;
|
|
297
|
+
outageNotified = true;
|
|
298
|
+
notify(message, level);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const FOOTER_ERROR_MAX = 60;
|
|
302
|
+
|
|
303
|
+
function messagingFooter(m: MessagingStatus): string {
|
|
304
|
+
let error = stripVTControlCharacters(m.error || "").replace(/\s+/g, " ").trim();
|
|
305
|
+
if (error.length > FOOTER_ERROR_MAX) error = `${error.slice(0, FOOTER_ERROR_MAX - 1)}…`;
|
|
306
|
+
const retry = m.state === "disconnected" && typeof m.retry_at_ms === "number"
|
|
307
|
+
? Math.ceil((m.retry_at_ms - Date.now()) / 1000)
|
|
308
|
+
: undefined;
|
|
309
|
+
const label = retry === undefined ? m.state : "reconnecting";
|
|
310
|
+
const when = retry === undefined ? "" : retry > 0 ? ` · retry in ${retry}s` : " · retrying";
|
|
311
|
+
return `msg: ${label}${when}${error ? ` · ${error}` : ""}`;
|
|
286
312
|
}
|
|
287
313
|
|
|
288
314
|
async function checkMessagingStatus() {
|
|
@@ -294,11 +320,20 @@ export function registerIntercom(pi: ExtensionAPI, deps: IntercomDeps): void {
|
|
|
294
320
|
const { messaging } = await client.status();
|
|
295
321
|
if (stopped || epoch !== expectedEpoch || !lastCtx || !useContext(lastCtx)) return;
|
|
296
322
|
if (!messaging || messaging.state === "disabled") {
|
|
323
|
+
relayOutage = false;
|
|
297
324
|
updateMessagingError();
|
|
298
325
|
} else if (messaging.error || messaging.state === "disconnected" || messaging.state === "unavailable") {
|
|
299
|
-
|
|
326
|
+
relayOutage = true;
|
|
327
|
+
updateMessagingError(
|
|
328
|
+
`pi-famulus messaging ${messaging.state}: ${messaging.error || "relay not connected"}`,
|
|
329
|
+
"error",
|
|
330
|
+
messagingFooter(messaging),
|
|
331
|
+
);
|
|
300
332
|
} else {
|
|
301
333
|
updateMessagingError();
|
|
334
|
+
// The outage notice was the only signal; say when it is over.
|
|
335
|
+
if (relayOutage) notify("pi-famulus messaging reconnected", "info");
|
|
336
|
+
relayOutage = false;
|
|
302
337
|
}
|
|
303
338
|
} catch (error) {
|
|
304
339
|
if (!stopped && epoch === expectedEpoch && lastCtx && useContext(lastCtx)) {
|
|
@@ -735,6 +770,7 @@ export function registerIntercom(pi: ExtensionAPI, deps: IntercomDeps): void {
|
|
|
735
770
|
readiness = undefined;
|
|
736
771
|
started = false;
|
|
737
772
|
listCache = undefined;
|
|
773
|
+
relayOutage = false;
|
|
738
774
|
updateMessagingError();
|
|
739
775
|
lastCtx = undefined;
|
|
740
776
|
stopPromise = (async () => {
|
package/src/manager-client.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { famulusPaths } from "./config";
|
|
|
18
18
|
import { realClock, type Clock, type ClockTimer } from "./clock";
|
|
19
19
|
|
|
20
20
|
const MAX_FRAME_BYTES = 4 * 1024 * 1024; // 4 MiB (§3.3)
|
|
21
|
-
const EXTENSION_VERSION = "0.2.2-beta.
|
|
21
|
+
const EXTENSION_VERSION = "0.2.2-beta.4";
|
|
22
22
|
export { EXTENSION_VERSION };
|
|
23
23
|
// 6: hosted subagents. 7: the extension's messaging bridge (`intercom`
|
|
24
24
|
// request plus `intercom`/`intercom_reset` events).
|
|
@@ -188,6 +188,19 @@ export interface MessagingStatus {
|
|
|
188
188
|
name: string;
|
|
189
189
|
/** Why the bridge is not running. */
|
|
190
190
|
error?: string;
|
|
191
|
+
/** Epoch ms of the next reconnect attempt; only while disconnected with one scheduled. */
|
|
192
|
+
retry_at_ms?: number;
|
|
193
|
+
/** Enrolled device id for the configured server; absent or empty when not enrolled. */
|
|
194
|
+
device_id?: string;
|
|
195
|
+
/** Local sessions the relay assigns to another device; peers cannot reach them. */
|
|
196
|
+
conflicts?: RelayConflict[];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface RelayConflict {
|
|
200
|
+
id: string;
|
|
201
|
+
name: string;
|
|
202
|
+
/** Owning device name or id; empty when the relay does not list the session. */
|
|
203
|
+
owner: string;
|
|
191
204
|
}
|
|
192
205
|
|
|
193
206
|
export interface SessionInfo {
|
|
@@ -657,6 +670,11 @@ export class ManagerClient {
|
|
|
657
670
|
};
|
|
658
671
|
}
|
|
659
672
|
|
|
673
|
+
/** Ask the daemon to retry the relay connection now instead of at the next scheduled attempt. */
|
|
674
|
+
async messagingReconnect(): Promise<void> {
|
|
675
|
+
await this.request({ type: "messaging_reconnect" });
|
|
676
|
+
}
|
|
677
|
+
|
|
660
678
|
/** Connected sessions (status). Older managers may reject this for extension clients. */
|
|
661
679
|
async sessions(): Promise<SessionInfo[]> {
|
|
662
680
|
return (await this.status()).sessions;
|
|
@@ -6,7 +6,7 @@ import { execFile } from "node:child_process";
|
|
|
6
6
|
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
|
-
import type
|
|
9
|
+
import { ManagerError, type ManagerClient, type MessagingStatus } from "../manager-client";
|
|
10
10
|
import { SETTINGS_SECTIONS, listTheme, readConfigText, sectionPage, writeConfigText } from "./famulus-settings";
|
|
11
11
|
import { loadPiTui, truncateToWidth, wrapTextWithAnsi } from "./pi-tui-load";
|
|
12
12
|
|
|
@@ -52,9 +52,28 @@ 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
|
-
|
|
55
|
+
let label = m.name && RELAY_STATES[m.state] ? `${state} · name ${singleLine(m.name)}` : state;
|
|
56
|
+
if (m.state === "disconnected" && typeof m.retry_at_ms === "number") {
|
|
57
|
+
const seconds = Math.ceil((m.retry_at_ms - Date.now()) / 1000);
|
|
58
|
+
label += seconds > 0 ? ` · retry in ${seconds}s` : " · retrying";
|
|
59
|
+
}
|
|
56
60
|
const error = singleLine(m.error ?? "");
|
|
57
|
-
|
|
61
|
+
const count = m.conflicts?.length ?? 0;
|
|
62
|
+
const conflicts = count ? ` · ${count} session${count === 1 ? "" : "s"} unpublished` : "";
|
|
63
|
+
return `${label}${conflicts}${error ? ` (${error})` : ""}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Why some local sessions are invisible to peers, one entry per session. */
|
|
67
|
+
export function formatConflicts(m: MessagingStatus | null): string {
|
|
68
|
+
if (!m?.conflicts?.length) return "";
|
|
69
|
+
const rows = m.conflicts.map((c) => {
|
|
70
|
+
const id = singleLine(c.id);
|
|
71
|
+
const name = singleLine(c.name);
|
|
72
|
+
const who = name && name !== id ? `${name} (${id})` : id;
|
|
73
|
+
const owner = singleLine(c.owner);
|
|
74
|
+
return owner ? `${who} owned by ${owner}` : `${who} not listed`;
|
|
75
|
+
});
|
|
76
|
+
return `Unpublished: the relay assigns these sessions to another device, so peers cannot reach them until they restart: ${rows.join("; ")}`;
|
|
58
77
|
}
|
|
59
78
|
|
|
60
79
|
export function formatFamulusInfo(info: FamulusInfo): string {
|
|
@@ -126,7 +145,26 @@ export async function collectFamulusInfo(deps: FamulusCommandDeps): Promise<Famu
|
|
|
126
145
|
};
|
|
127
146
|
}
|
|
128
147
|
|
|
129
|
-
type OverviewChoice = "edit-raw" | "reload" | undefined;
|
|
148
|
+
type OverviewChoice = "edit-raw" | "reload" | "reconnect" | undefined;
|
|
149
|
+
|
|
150
|
+
/** Whether "Reconnect messaging now" makes sense for what the manager reported. */
|
|
151
|
+
const canReconnect = (m: MessagingStatus | null) => m?.state === "disconnected" || m?.state === "unavailable";
|
|
152
|
+
|
|
153
|
+
/** Ask the manager to retry the relay now; the notice text says how that went. */
|
|
154
|
+
export async function requestMessagingReconnect(client: ManagerClient | null): Promise<{ text: string; error: boolean }> {
|
|
155
|
+
if (!client?.isAvailable()) return { text: "The manager is not connected.", error: true };
|
|
156
|
+
try {
|
|
157
|
+
await client.messagingReconnect();
|
|
158
|
+
return { text: "Reconnect requested; the status refreshes below.", error: false };
|
|
159
|
+
} catch (error) {
|
|
160
|
+
const message = (error as Error).message;
|
|
161
|
+
// An older daemon rejects the request type itself.
|
|
162
|
+
if (error instanceof ManagerError && error.code === "E_BAD_REQUEST" && /unknown|unrecognized|unsupported/i.test(message)) {
|
|
163
|
+
return { text: "The manager is too old to reconnect on demand; restart it.", error: true };
|
|
164
|
+
}
|
|
165
|
+
return { text: `Reconnect failed: ${singleLine(message)}`, error: true };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
130
168
|
|
|
131
169
|
/** Status first, then one row per settings section and the two actions. */
|
|
132
170
|
function showOverview(
|
|
@@ -146,6 +184,7 @@ function showOverview(
|
|
|
146
184
|
tui: piTui,
|
|
147
185
|
theme,
|
|
148
186
|
configPath,
|
|
187
|
+
messaging: info.messaging,
|
|
149
188
|
enrollMessagingToken,
|
|
150
189
|
requestRender: () => tui.requestRender(),
|
|
151
190
|
notice: (text: string, error = false) => {
|
|
@@ -160,6 +199,13 @@ function showOverview(
|
|
|
160
199
|
currentValue: "›",
|
|
161
200
|
submenu: (_current: string, close: (value?: string) => void) => sectionPage(deps, section, () => close()),
|
|
162
201
|
})),
|
|
202
|
+
...(canReconnect(info.messaging) ? [{
|
|
203
|
+
id: "reconnect",
|
|
204
|
+
label: "Reconnect messaging now",
|
|
205
|
+
description: "Retry the relay connection immediately instead of waiting for the next attempt",
|
|
206
|
+
currentValue: "",
|
|
207
|
+
values: [""],
|
|
208
|
+
}] : []),
|
|
163
209
|
{
|
|
164
210
|
id: "edit-raw",
|
|
165
211
|
label: "Edit config.json",
|
|
@@ -174,7 +220,7 @@ function showOverview(
|
|
|
174
220
|
10,
|
|
175
221
|
listTheme(theme),
|
|
176
222
|
(id) => {
|
|
177
|
-
if (id === "edit-raw" || id === "reload") done(id);
|
|
223
|
+
if (id === "edit-raw" || id === "reload" || id === "reconnect") done(id);
|
|
178
224
|
},
|
|
179
225
|
() => done(undefined),
|
|
180
226
|
);
|
|
@@ -190,6 +236,8 @@ function showOverview(
|
|
|
190
236
|
})];
|
|
191
237
|
const error = singleLine(info.messaging?.error ?? "");
|
|
192
238
|
if (error) lines.push(...wrapTextWithAnsi(theme.fg("error", `Messaging error: ${error}`), width));
|
|
239
|
+
const conflicts = formatConflicts(info.messaging);
|
|
240
|
+
if (conflicts) lines.push(...wrapTextWithAnsi(theme.fg("warning", conflicts), width));
|
|
193
241
|
lines.push("", ...list.render(width));
|
|
194
242
|
if (notice) lines.push("", ...wrapTextWithAnsi(notice, width));
|
|
195
243
|
return lines.map((line) => truncateToWidth(line, width));
|
|
@@ -215,6 +263,11 @@ export function registerFamulusCommand(pi: ExtensionAPI, deps: FamulusCommandDep
|
|
|
215
263
|
while (true) {
|
|
216
264
|
const action = await showOverview(ctx, await collectFamulusInfo(deps), deps.configPath,
|
|
217
265
|
deps.enrollMessagingToken ?? ((token) => exchangeMessagingToken(deps.managerPath, deps.configPath, token)));
|
|
266
|
+
if (action === "reconnect") {
|
|
267
|
+
const outcome = await requestMessagingReconnect(deps.getClient());
|
|
268
|
+
ctx.ui.notify(outcome.text, outcome.error ? "error" : "info");
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
218
271
|
if (action === "reload") {
|
|
219
272
|
await ctx.reload();
|
|
220
273
|
return;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { hostname } from "node:os";
|
|
7
7
|
import { dirname } from "node:path";
|
|
8
|
+
import type { MessagingStatus } from "../manager-client";
|
|
8
9
|
import type { PiTuiInteractive, PiTuiModule, PiTuiSettingItem, PiTuiSettingsListTheme } from "./pi-tui-load";
|
|
9
10
|
|
|
10
11
|
type Kind = "int" | "text" | "secret" | "bool" | "enum" | "duration";
|
|
@@ -212,6 +213,8 @@ export interface SettingsPageDeps {
|
|
|
212
213
|
tui: PiTuiModule;
|
|
213
214
|
theme: { fg(color: string, text: string): string };
|
|
214
215
|
configPath: string;
|
|
216
|
+
/** What the manager reported; null when it is unreachable or silent. */
|
|
217
|
+
messaging?: MessagingStatus | null;
|
|
215
218
|
enrollMessagingToken(token: string): Promise<void>;
|
|
216
219
|
requestRender(): void;
|
|
217
220
|
/** Report a save or its failure under the list. */
|
|
@@ -230,6 +233,12 @@ export function listTheme(theme: SettingsPageDeps["theme"]): PiTuiSettingsListTh
|
|
|
230
233
|
|
|
231
234
|
const keyOf = (spec: SettingSpec) => spec.path.join(".");
|
|
232
235
|
|
|
236
|
+
/** The token is removed after enrollment, so the row shows enrollment instead. */
|
|
237
|
+
function enrollmentValue(messaging: SettingsPageDeps["messaging"]): string {
|
|
238
|
+
if (!messaging) return "unknown";
|
|
239
|
+
return messaging.device_id ? `enrolled · device ${messaging.device_id.slice(0, 8)}` : "not enrolled";
|
|
240
|
+
}
|
|
241
|
+
|
|
233
242
|
function describe(spec: SettingSpec & { applies?: string }, section: SettingsSection, raw: unknown): string {
|
|
234
243
|
const state = raw === undefined ? `not set (default ${spec.default})` : `default ${spec.default}`;
|
|
235
244
|
return `${spec.description} · ${state} · ${spec.applies ?? section.applies}`;
|
|
@@ -272,7 +281,7 @@ function valueEditor(
|
|
|
272
281
|
deps.requestRender();
|
|
273
282
|
void saved.then((success) => {
|
|
274
283
|
pending = false;
|
|
275
|
-
if (success) done("
|
|
284
|
+
if (success) done("enrolled");
|
|
276
285
|
deps.requestRender();
|
|
277
286
|
});
|
|
278
287
|
}
|
|
@@ -326,11 +335,14 @@ export function sectionPage(deps: SettingsPageDeps, section: SettingsSection, cl
|
|
|
326
335
|
};
|
|
327
336
|
const items: PiTuiSettingItem[] = section.specs.map((spec) => {
|
|
328
337
|
const raw = lookup(config, spec.path);
|
|
338
|
+
const isToken = keyOf(spec) === "messaging.token";
|
|
329
339
|
const item: PiTuiSettingItem = {
|
|
330
340
|
id: keyOf(spec),
|
|
331
341
|
label: spec.path[spec.path.length - 1],
|
|
332
|
-
description:
|
|
333
|
-
|
|
342
|
+
description: isToken
|
|
343
|
+
? `Entering a token ${deps.messaging?.device_id ? "re-enrolls" : "enrolls"} this device. ${spec.description} · ${spec.applies}`
|
|
344
|
+
: describe(spec, section, raw),
|
|
345
|
+
currentValue: isToken ? enrollmentValue(deps.messaging) : displayValue(spec, raw),
|
|
334
346
|
};
|
|
335
347
|
if (spec.kind === "bool") item.values = ["true", "false"];
|
|
336
348
|
else if (spec.kind === "enum") item.values = spec.values;
|