pi-famulus 0.2.2-beta.2 → 0.2.2-beta.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/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.3",
|
|
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.3",
|
|
58
|
+
"pi-famulus-linux-arm64": "0.2.2-beta.3",
|
|
59
|
+
"pi-famulus-darwin-x64": "0.2.2-beta.3",
|
|
60
|
+
"pi-famulus-darwin-arm64": "0.2.2-beta.3",
|
|
61
|
+
"pi-famulus-win-x64": "0.2.2-beta.3",
|
|
62
|
+
"pi-famulus-win-arm64": "0.2.2-beta.3"
|
|
63
63
|
},
|
|
64
64
|
"pi": {
|
|
65
65
|
"extensions": [
|
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.3";
|
|
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).
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* whether messaging reaches its relay, and the settings pages.
|
|
4
4
|
*/
|
|
5
5
|
import { execFile } from "node:child_process";
|
|
6
|
+
import { dirname } from "node:path";
|
|
6
7
|
import { stripVTControlCharacters } from "node:util";
|
|
7
8
|
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
8
9
|
import type { ManagerClient, MessagingStatus } from "../manager-client";
|
|
@@ -20,6 +21,8 @@ export interface FamulusCommandDeps {
|
|
|
20
21
|
messagingEnabled?: boolean;
|
|
21
22
|
/** `<binary> --version`; null when it cannot be run. */
|
|
22
23
|
binaryVersion?: (path: string) => Promise<string | null>;
|
|
24
|
+
/** Exchange an enrollment token using the current messaging configuration. */
|
|
25
|
+
enrollMessagingToken?: (token: string) => Promise<void>;
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
export interface FamulusInfo {
|
|
@@ -80,6 +83,17 @@ export function readBinaryVersion(path: string): Promise<string | null> {
|
|
|
80
83
|
});
|
|
81
84
|
}
|
|
82
85
|
|
|
86
|
+
export function exchangeMessagingToken(managerPath: string | null, configPath: string, token: string): Promise<void> {
|
|
87
|
+
if (!managerPath) return Promise.reject(new Error("pi-famulus binary is unavailable."));
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
execFile(managerPath, ["--home", dirname(configPath), "intercom", "enroll", "--token", token],
|
|
90
|
+
{ timeout: 25_000, windowsHide: true }, (error, _stdout, stderr) => {
|
|
91
|
+
if (error) reject(new Error(stderr.trim() || `Device enrollment failed (${error.code ?? "command failed"}).`));
|
|
92
|
+
else resolve();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
83
97
|
const STATUS_TIMEOUT_MS = 2000;
|
|
84
98
|
|
|
85
99
|
async function readMessaging(client: ManagerClient): Promise<MessagingStatus | null> {
|
|
@@ -115,7 +129,12 @@ export async function collectFamulusInfo(deps: FamulusCommandDeps): Promise<Famu
|
|
|
115
129
|
type OverviewChoice = "edit-raw" | "reload" | undefined;
|
|
116
130
|
|
|
117
131
|
/** Status first, then one row per settings section and the two actions. */
|
|
118
|
-
function showOverview(
|
|
132
|
+
function showOverview(
|
|
133
|
+
ctx: ExtensionCommandContext,
|
|
134
|
+
info: FamulusInfo,
|
|
135
|
+
configPath: string,
|
|
136
|
+
enrollMessagingToken: (token: string) => Promise<void>,
|
|
137
|
+
): Promise<OverviewChoice> {
|
|
119
138
|
const piTui = loadPiTui();
|
|
120
139
|
if (!piTui) {
|
|
121
140
|
ctx.ui.notify(formatFamulusInfo(info), "info");
|
|
@@ -127,6 +146,7 @@ function showOverview(ctx: ExtensionCommandContext, info: FamulusInfo, configPat
|
|
|
127
146
|
tui: piTui,
|
|
128
147
|
theme,
|
|
129
148
|
configPath,
|
|
149
|
+
enrollMessagingToken,
|
|
130
150
|
requestRender: () => tui.requestRender(),
|
|
131
151
|
notice: (text: string, error = false) => {
|
|
132
152
|
notice = theme.fg(error ? "error" : "success", text);
|
|
@@ -171,7 +191,7 @@ function showOverview(ctx: ExtensionCommandContext, info: FamulusInfo, configPat
|
|
|
171
191
|
const error = singleLine(info.messaging?.error ?? "");
|
|
172
192
|
if (error) lines.push(...wrapTextWithAnsi(theme.fg("error", `Messaging error: ${error}`), width));
|
|
173
193
|
lines.push("", ...list.render(width));
|
|
174
|
-
if (notice) lines.push("", notice);
|
|
194
|
+
if (notice) lines.push("", ...wrapTextWithAnsi(notice, width));
|
|
175
195
|
return lines.map((line) => truncateToWidth(line, width));
|
|
176
196
|
},
|
|
177
197
|
invalidate: () => list.invalidate(),
|
|
@@ -193,7 +213,8 @@ export function registerFamulusCommand(pi: ExtensionAPI, deps: FamulusCommandDep
|
|
|
193
213
|
return;
|
|
194
214
|
}
|
|
195
215
|
while (true) {
|
|
196
|
-
const action = await showOverview(ctx, await collectFamulusInfo(deps), deps.configPath
|
|
216
|
+
const action = await showOverview(ctx, await collectFamulusInfo(deps), deps.configPath,
|
|
217
|
+
deps.enrollMessagingToken ?? ((token) => exchangeMessagingToken(deps.managerPath, deps.configPath, token)));
|
|
197
218
|
if (action === "reload") {
|
|
198
219
|
await ctx.reload();
|
|
199
220
|
return;
|
|
@@ -99,7 +99,7 @@ export const SETTINGS_SECTIONS: SettingsSection[] = [
|
|
|
99
99
|
{ path: ["messaging", "enabled"], kind: "bool", default: "false", description: "Opt in to cross-session messaging tools, commands, and connections.", applies: "reload the extension and restart the manager daemon to apply" },
|
|
100
100
|
{ path: ["messaging", "name"], kind: "text", default: hostname(), description: "Device name shown to peers; the hostname when unset." },
|
|
101
101
|
{ path: ["messaging", "server"], kind: "text", default: "https://127.0.0.1:8443", description: "Relay server URL." },
|
|
102
|
-
{ path: ["messaging", "token"], kind: "secret", default: "not set", description: "
|
|
102
|
+
{ path: ["messaging", "token"], kind: "secret", default: "not set", description: "Enrollment token; Enter exchanges it for a saved device credential. The token is not stored.", applies: "exchanges immediately" },
|
|
103
103
|
{ path: ["messaging", "localOnly"], kind: "bool", default: "false", description: "Only local sessions, no relay. Enable explicitly for local-only messaging." },
|
|
104
104
|
{ path: ["messaging", "remoteMessages"], kind: "enum", values: ["allow", "refuse"], default: "allow", description: "Whether messages from other machines are accepted." },
|
|
105
105
|
{ path: ["messaging", "tlsInsecure"], kind: "bool", default: "false", description: "Skip relay TLS certificate verification." },
|
|
@@ -212,6 +212,7 @@ export interface SettingsPageDeps {
|
|
|
212
212
|
tui: PiTuiModule;
|
|
213
213
|
theme: { fg(color: string, text: string): string };
|
|
214
214
|
configPath: string;
|
|
215
|
+
enrollMessagingToken(token: string): Promise<void>;
|
|
215
216
|
requestRender(): void;
|
|
216
217
|
/** Report a save or its failure under the list. */
|
|
217
218
|
notice(text: string, error?: boolean): void;
|
|
@@ -239,7 +240,7 @@ function valueEditor(
|
|
|
239
240
|
deps: SettingsPageDeps,
|
|
240
241
|
spec: SettingSpec,
|
|
241
242
|
raw: unknown,
|
|
242
|
-
save: (value: unknown) => boolean
|
|
243
|
+
save: (value: unknown) => boolean | Promise<boolean>,
|
|
243
244
|
done: (shown?: string) => void,
|
|
244
245
|
): PiTuiInteractive {
|
|
245
246
|
const input = new deps.tui.Input();
|
|
@@ -253,6 +254,7 @@ function valueEditor(
|
|
|
253
254
|
? "enter save · empty keeps the current value · esc cancel"
|
|
254
255
|
: `enter save · empty resets to ${spec.default} · esc cancel`;
|
|
255
256
|
let error = "";
|
|
257
|
+
let pending = false;
|
|
256
258
|
input.onSubmit = (text) => {
|
|
257
259
|
if (spec.kind === "secret" && text.trim() === "") return done();
|
|
258
260
|
const parsed = parseInput(spec, text);
|
|
@@ -261,7 +263,19 @@ function valueEditor(
|
|
|
261
263
|
deps.requestRender();
|
|
262
264
|
return;
|
|
263
265
|
}
|
|
264
|
-
|
|
266
|
+
error = "";
|
|
267
|
+
const saved = save(parsed.value);
|
|
268
|
+
if (typeof saved === "boolean") {
|
|
269
|
+
if (saved) done(displayValue(spec, parsed.value));
|
|
270
|
+
} else {
|
|
271
|
+
pending = true;
|
|
272
|
+
deps.requestRender();
|
|
273
|
+
void saved.then((success) => {
|
|
274
|
+
pending = false;
|
|
275
|
+
if (success) done("exchanged");
|
|
276
|
+
deps.requestRender();
|
|
277
|
+
});
|
|
278
|
+
}
|
|
265
279
|
};
|
|
266
280
|
input.onEscape = () => done();
|
|
267
281
|
return {
|
|
@@ -269,12 +283,12 @@ function valueEditor(
|
|
|
269
283
|
deps.theme.fg("accent", keyOf(spec)),
|
|
270
284
|
deps.theme.fg("dim", spec.description),
|
|
271
285
|
"",
|
|
272
|
-
...input.render(width),
|
|
286
|
+
...(pending ? [deps.theme.fg("dim", "Exchanging token...")] : input.render(width)),
|
|
273
287
|
"",
|
|
274
|
-
error ? deps.theme.fg("error", error) : deps.theme.fg("dim", hint),
|
|
288
|
+
error ? deps.theme.fg("error", error) : deps.theme.fg("dim", pending ? "Waiting for enrollment response" : hint),
|
|
275
289
|
],
|
|
276
290
|
invalidate: () => input.invalidate(),
|
|
277
|
-
handleInput: (data) => input.handleInput(data),
|
|
291
|
+
handleInput: (data) => { if (!pending) input.handleInput(data); },
|
|
278
292
|
};
|
|
279
293
|
}
|
|
280
294
|
|
|
@@ -288,7 +302,19 @@ export function sectionPage(deps: SettingsPageDeps, section: SettingsSection, cl
|
|
|
288
302
|
config = {};
|
|
289
303
|
}
|
|
290
304
|
const specs = new Map(section.specs.map((spec) => [keyOf(spec), spec]));
|
|
291
|
-
const
|
|
305
|
+
const enroll = async (token: string): Promise<boolean> => {
|
|
306
|
+
try {
|
|
307
|
+
await deps.enrollMessagingToken(token);
|
|
308
|
+
setConfigValue(deps.configPath, ["messaging", "token"], undefined);
|
|
309
|
+
deps.notice("Device enrolled; device credential saved.");
|
|
310
|
+
return true;
|
|
311
|
+
} catch (error) {
|
|
312
|
+
deps.notice(`Device enrollment failed: ${(error as Error).message.replaceAll(token, "[redacted]")}`, true);
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
const save = (spec: SettingSpec & { applies?: string }, value: unknown): boolean | Promise<boolean> => {
|
|
317
|
+
if (keyOf(spec) === "messaging.token") return enroll(value as string);
|
|
292
318
|
try {
|
|
293
319
|
setConfigValue(deps.configPath, spec.path, value);
|
|
294
320
|
} catch (error) {
|