@av-pi-studio/cli 0.0.1

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.
Files changed (54) hide show
  1. package/dist/.tsbuildinfo +1 -0
  2. package/dist/agent-commands.d.ts +70 -0
  3. package/dist/agent-commands.d.ts.map +1 -0
  4. package/dist/agent-commands.js +296 -0
  5. package/dist/agent-commands.js.map +1 -0
  6. package/dist/cli-core.d.ts +55 -0
  7. package/dist/cli-core.d.ts.map +1 -0
  8. package/dist/cli-core.js +85 -0
  9. package/dist/cli-core.js.map +1 -0
  10. package/dist/cli.d.ts +3 -0
  11. package/dist/cli.d.ts.map +1 -0
  12. package/dist/cli.js +16 -0
  13. package/dist/cli.js.map +1 -0
  14. package/dist/client-id.d.ts +12 -0
  15. package/dist/client-id.d.ts.map +1 -0
  16. package/dist/client-id.js +47 -0
  17. package/dist/client-id.js.map +1 -0
  18. package/dist/connection.d.ts +44 -0
  19. package/dist/connection.d.ts.map +1 -0
  20. package/dist/connection.js +83 -0
  21. package/dist/connection.js.map +1 -0
  22. package/dist/daemon-commands.d.ts +10 -0
  23. package/dist/daemon-commands.d.ts.map +1 -0
  24. package/dist/daemon-commands.js +108 -0
  25. package/dist/daemon-commands.js.map +1 -0
  26. package/dist/daemon-control.d.ts +67 -0
  27. package/dist/daemon-control.d.ts.map +1 -0
  28. package/dist/daemon-control.js +140 -0
  29. package/dist/daemon-control.js.map +1 -0
  30. package/dist/feature-commands.d.ts +56 -0
  31. package/dist/feature-commands.d.ts.map +1 -0
  32. package/dist/feature-commands.js +250 -0
  33. package/dist/feature-commands.js.map +1 -0
  34. package/dist/index.d.ts +15 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +18 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/output.d.ts +25 -0
  39. package/dist/output.d.ts.map +1 -0
  40. package/dist/output.js +65 -0
  41. package/dist/output.js.map +1 -0
  42. package/dist/pairing.d.ts +17 -0
  43. package/dist/pairing.d.ts.map +1 -0
  44. package/dist/pairing.js +33 -0
  45. package/dist/pairing.js.map +1 -0
  46. package/dist/program.d.ts +17 -0
  47. package/dist/program.d.ts.map +1 -0
  48. package/dist/program.js +75 -0
  49. package/dist/program.js.map +1 -0
  50. package/dist/qr.d.ts +6 -0
  51. package/dist/qr.d.ts.map +1 -0
  52. package/dist/qr.js +9 -0
  53. package/dist/qr.js.map +1 -0
  54. package/package.json +34 -0
@@ -0,0 +1,85 @@
1
+ import { DaemonClient, RpcError, RpcTimeoutError } from "@av-pi-studio/client";
2
+ import { connectDaemon } from "./connection.js";
3
+ import { consoleSink, renderJson } from "./output.js";
4
+ /**
5
+ * CLI core (features/cli.md § Behavior — main): connect a `DaemonClient`, dispatch a subcommand to
6
+ * one or more WS RPCs, render output, and produce an exit code. The Commander program (program.ts)
7
+ * is a thin shell over these helpers; tests drive the helpers directly with an injected transport.
8
+ */
9
+ /** Process exit codes. */
10
+ export const EXIT_OK = 0;
11
+ export const EXIT_ERROR = 1;
12
+ export const EXIT_CONNECTION = 2;
13
+ /** Default production context. */
14
+ export function defaultContext() {
15
+ return {
16
+ connect: (opts) => connectDaemon(opts),
17
+ sink: consoleSink,
18
+ };
19
+ }
20
+ /** Resolve the output format from global options. */
21
+ export function formatOf(opts) {
22
+ return opts.json ? "json" : "table";
23
+ }
24
+ /** Map global options + context overrides into ConnectOptions. */
25
+ export function connectOptionsFrom(ctx, opts) {
26
+ return {
27
+ host: opts.host,
28
+ password: opts.password,
29
+ home: ctx.connectOverrides?.home ?? opts.home,
30
+ transport: ctx.connectOverrides?.transport,
31
+ clientId: ctx.connectOverrides?.clientId,
32
+ rpcTimeoutMs: ctx.rpcTimeoutMs,
33
+ };
34
+ }
35
+ /**
36
+ * Run an action with a connected daemon client, translating connection/RPC failures into the
37
+ * appropriate exit code + error message. Always closes the client.
38
+ */
39
+ export async function withDaemon(ctx, opts, action) {
40
+ let client;
41
+ try {
42
+ const result = await ctx.connect(connectOptionsFrom(ctx, opts));
43
+ client = result.client;
44
+ }
45
+ catch (error) {
46
+ ctx.sink.error(`connection error: ${errorMessage(error)}`);
47
+ return EXIT_CONNECTION;
48
+ }
49
+ try {
50
+ const code = await action(client, ctx, opts);
51
+ return typeof code === "number" ? code : EXIT_OK;
52
+ }
53
+ catch (error) {
54
+ if (error instanceof RpcError) {
55
+ ctx.sink.error(`error: ${error.message}${error.code ? ` (${error.code})` : ""}`);
56
+ return EXIT_ERROR;
57
+ }
58
+ if (error instanceof RpcTimeoutError) {
59
+ ctx.sink.error(`error: request timed out`);
60
+ return EXIT_ERROR;
61
+ }
62
+ ctx.sink.error(`error: ${errorMessage(error)}`);
63
+ return EXIT_ERROR;
64
+ }
65
+ finally {
66
+ client?.close();
67
+ }
68
+ }
69
+ /**
70
+ * Convenience: run a single RPC and render its payload, then return an exit code. `render` turns the
71
+ * payload into text for the table view; the JSON view always prints the raw payload.
72
+ */
73
+ export async function runRpc(ctx, opts, type, params, render) {
74
+ return withDaemon(ctx, opts, async (client) => {
75
+ const payload = await client.request(type, params);
76
+ ctx.sink.write(opts.json ? renderJson(payload) : render(payload));
77
+ return EXIT_OK;
78
+ });
79
+ }
80
+ export function errorMessage(error) {
81
+ if (error instanceof Error)
82
+ return error.message;
83
+ return String(error);
84
+ }
85
+ //# sourceMappingURL=cli-core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-core.js","sourceRoot":"","sources":["../src/cli-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE/E,OAAO,EAAuB,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErE,OAAO,EAAsC,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE1F;;;;GAIG;AAEH,0BAA0B;AAC1B,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAC;AACzB,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC;AAC5B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CAAC;QAClE,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC;IACjD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * `pi-studio` CLI entrypoint. Parses argv (skipping `node` + script), runs the program, and exits
4
+ * with the resolved code.
5
+ */
6
+ import { run } from "./program.js";
7
+ const argv = process.argv.slice(2);
8
+ run(argv)
9
+ .then((code) => {
10
+ process.exitCode = code;
11
+ })
12
+ .catch((error) => {
13
+ process.stderr.write(`fatal: ${error instanceof Error ? error.message : String(error)}\n`);
14
+ process.exitCode = 1;
15
+ });
16
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;GAGG;AACH,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,GAAG,CAAC,IAAI,CAAC;KACN,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;IACb,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;AAC1B,CAAC,CAAC;KACD,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IACxB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3F,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Resolve the `$PI_STUDIO_HOME` directory (CLI side). Defaults to `~/.pi-studio`.
3
+ * (features/cli.md § Data & Persistence; architecture/config.md.)
4
+ */
5
+ export declare function resolveHome(env?: Record<string, string | undefined>): string;
6
+ /**
7
+ * Resolve a stable local client id, persisted under `$PI_STUDIO_HOME/cli-client-id` so the CLI
8
+ * presents the same `clientId` across invocations in its hello handshake. The daemon owns all real
9
+ * state; this id is just a stable identity (features/cli.md § Data & Persistence).
10
+ */
11
+ export declare function resolveClientId(home?: string, generate?: () => string): string;
12
+ //# sourceMappingURL=client-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-id.d.ts","sourceRoot":"","sources":["../src/client-id.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GAAG,MAAM,CAIzF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,IAAI,GAAE,MAAsB,EAC5B,QAAQ,GAAE,MAAM,MAAwB,GACvC,MAAM,CAmBR"}
@@ -0,0 +1,47 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ /**
5
+ * Resolve the `$PI_STUDIO_HOME` directory (CLI side). Defaults to `~/.pi-studio`.
6
+ * (features/cli.md § Data & Persistence; architecture/config.md.)
7
+ */
8
+ export function resolveHome(env = process.env) {
9
+ const fromEnv = env.PI_STUDIO_HOME?.trim();
10
+ if (fromEnv)
11
+ return fromEnv;
12
+ return join(homedir(), ".pi-studio");
13
+ }
14
+ /**
15
+ * Resolve a stable local client id, persisted under `$PI_STUDIO_HOME/cli-client-id` so the CLI
16
+ * presents the same `clientId` across invocations in its hello handshake. The daemon owns all real
17
+ * state; this id is just a stable identity (features/cli.md § Data & Persistence).
18
+ */
19
+ export function resolveClientId(home = resolveHome(), generate = defaultGenerate) {
20
+ const file = join(home, "cli-client-id");
21
+ try {
22
+ if (existsSync(file)) {
23
+ const existing = readFileSync(file, "utf8").trim();
24
+ if (existing)
25
+ return existing;
26
+ }
27
+ }
28
+ catch {
29
+ // Unreadable — fall through and mint a fresh (in-memory) id.
30
+ }
31
+ const id = generate();
32
+ try {
33
+ mkdirSync(home, { recursive: true });
34
+ writeFileSync(file, `${id}\n`, "utf8");
35
+ }
36
+ catch {
37
+ // Best-effort persistence; a non-writable home still yields a usable (ephemeral) id.
38
+ }
39
+ return id;
40
+ }
41
+ function defaultGenerate() {
42
+ const rand = typeof crypto !== "undefined" && typeof crypto.randomUUID === "function"
43
+ ? crypto.randomUUID()
44
+ : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
45
+ return `cli-${rand}`;
46
+ }
47
+ //# sourceMappingURL=client-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-id.js","sourceRoot":"","sources":["../src/client-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,MAA0C,OAAO,CAAC,GAAG;IAC/E,MAAM,OAAO,GAAG,GAAG,CAAC,cAAc,EAAE,IAAI,EAAE,CAAC;IAC3C,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC;IAC5B,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC;AACvC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,OAAe,WAAW,EAAE,EAC5B,WAAyB,eAAe;IAExC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IACzC,IAAI,CAAC;QACH,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACrB,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;YACnD,IAAI,QAAQ;gBAAE,OAAO,QAAQ,CAAC;QAChC,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,6DAA6D;IAC/D,CAAC;IAED,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC;IACtB,IAAI,CAAC;QACH,SAAS,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACrC,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,qFAAqF;IACvF,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,SAAS,eAAe;IACtB,MAAM,IAAI,GACR,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU;QACtE,CAAC,CAAC,MAAM,CAAC,UAAU,EAAE;QACrB,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;IAC9E,OAAO,OAAO,IAAI,EAAE,CAAC;AACvB,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { DaemonClient, type Transport } from "@av-pi-studio/client";
2
+ /** Default local daemon target (architecture/daemon-bootstrap.md). */
3
+ export declare const DEFAULT_HOST = "127.0.0.1";
4
+ export declare const DEFAULT_PORT = 6767;
5
+ export interface ParsedHost {
6
+ host: string;
7
+ port: number;
8
+ /** True when the value looked remote (explicit host given), false for the implicit local daemon. */
9
+ explicit: boolean;
10
+ }
11
+ /**
12
+ * Parse a `--host` value into host + port. Accepts `host`, `host:port`, `ws://host:port`,
13
+ * `wss://host:port`. Missing port defaults to 6767 (features/cli.md § Global options).
14
+ */
15
+ export declare function parseHost(value?: string): ParsedHost;
16
+ /** Build the WebSocket URL for a parsed host. */
17
+ export declare function hostToUrl(parsed: ParsedHost, secure?: boolean): string;
18
+ /** The WS subprotocol that carries the daemon password (browsers cannot set custom headers). */
19
+ export declare function bearerSubprotocol(password: string): string;
20
+ export interface ConnectOptions {
21
+ /** Raw `--host` value. */
22
+ host?: string;
23
+ /** Daemon password (for password-protected daemons). */
24
+ password?: string;
25
+ /** `$PI_STUDIO_HOME` override (for the client-id store). */
26
+ home?: string;
27
+ /** Inject a transport (tests / relay). Defaults to a direct WebSocket transport. */
28
+ transport?: Transport;
29
+ /** Override the resolved client id (tests). */
30
+ clientId?: string;
31
+ /** RPC timeout (ms). */
32
+ rpcTimeoutMs?: number;
33
+ }
34
+ /**
35
+ * Build (but do not connect) a `DaemonClient` for the given global options. The CLI presents a
36
+ * stable `clientId` with `clientType: "cli"` (features/cli.md § Data & Persistence).
37
+ */
38
+ export declare function buildDaemonClient(opts: ConnectOptions): DaemonClient;
39
+ /** Build and connect a `DaemonClient`, completing the hello handshake. */
40
+ export declare function connectDaemon(opts: ConnectOptions): Promise<{
41
+ client: DaemonClient;
42
+ serverInfo: Awaited<ReturnType<DaemonClient["connect"]>>;
43
+ }>;
44
+ //# sourceMappingURL=connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EAEZ,KAAK,SAAS,EACf,MAAM,sBAAsB,CAAC;AAI9B,sEAAsE;AACtE,eAAO,MAAM,YAAY,cAAc,CAAC;AACxC,eAAO,MAAM,YAAY,OAAO,CAAC;AAEjC,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,oGAAoG;IACpG,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,CAyBpD;AAED,iDAAiD;AACjD,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,UAAQ,GAAG,MAAM,CAGpE;AAED,gGAAgG;AAChG,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE1D;AAcD,MAAM,WAAW,cAAc;IAC7B,0BAA0B;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oFAAoF;IACpF,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wBAAwB;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,cAAc,GAAG,YAAY,CAepE;AAED,0EAA0E;AAC1E,wBAAsB,aAAa,CACjC,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC;IAAE,MAAM,EAAE,YAAY,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC,CAI7F"}
@@ -0,0 +1,83 @@
1
+ import { createWebSocketTransport, DaemonClient, } from "@av-pi-studio/client";
2
+ import { resolveClientId, resolveHome } from "./client-id.js";
3
+ /** Default local daemon target (architecture/daemon-bootstrap.md). */
4
+ export const DEFAULT_HOST = "127.0.0.1";
5
+ export const DEFAULT_PORT = 6767;
6
+ /**
7
+ * Parse a `--host` value into host + port. Accepts `host`, `host:port`, `ws://host:port`,
8
+ * `wss://host:port`. Missing port defaults to 6767 (features/cli.md § Global options).
9
+ */
10
+ export function parseHost(value) {
11
+ if (!value || !value.trim()) {
12
+ return { host: DEFAULT_HOST, port: DEFAULT_PORT, explicit: false };
13
+ }
14
+ let raw = value.trim();
15
+ let secure = false;
16
+ if (raw.startsWith("ws://"))
17
+ raw = raw.slice(5);
18
+ else if (raw.startsWith("wss://")) {
19
+ raw = raw.slice(6);
20
+ secure = true;
21
+ }
22
+ else if (raw.startsWith("http://"))
23
+ raw = raw.slice(7);
24
+ else if (raw.startsWith("https://")) {
25
+ raw = raw.slice(8);
26
+ secure = true;
27
+ }
28
+ raw = raw.replace(/\/+$/, "");
29
+ const idx = raw.lastIndexOf(":");
30
+ let host = raw;
31
+ let port = secure ? 443 : DEFAULT_PORT;
32
+ if (idx !== -1 && /^\d+$/.test(raw.slice(idx + 1))) {
33
+ host = raw.slice(0, idx) || DEFAULT_HOST;
34
+ port = Number(raw.slice(idx + 1));
35
+ }
36
+ return { host, port, explicit: true };
37
+ }
38
+ /** Build the WebSocket URL for a parsed host. */
39
+ export function hostToUrl(parsed, secure = false) {
40
+ const scheme = secure ? "wss" : "ws";
41
+ return `${scheme}://${parsed.host}:${parsed.port}`;
42
+ }
43
+ /** The WS subprotocol that carries the daemon password (browsers cannot set custom headers). */
44
+ export function bearerSubprotocol(password) {
45
+ return `pi-studio.bearer.${password}`;
46
+ }
47
+ /**
48
+ * Build a direct WebSocket transport, optionally carrying the daemon password as a subprotocol
49
+ * (architecture/auth-security.md § Password auth).
50
+ */
51
+ function directTransport(password) {
52
+ if (!password)
53
+ return createWebSocketTransport();
54
+ const protocols = [bearerSubprotocol(password)];
55
+ const factory = ((url) => new WebSocket(url, protocols));
56
+ return createWebSocketTransport(factory);
57
+ }
58
+ /**
59
+ * Build (but do not connect) a `DaemonClient` for the given global options. The CLI presents a
60
+ * stable `clientId` with `clientType: "cli"` (features/cli.md § Data & Persistence).
61
+ */
62
+ export function buildDaemonClient(opts) {
63
+ const parsed = parseHost(opts.host);
64
+ const home = opts.home ?? resolveHome();
65
+ const clientId = opts.clientId ?? resolveClientId(home);
66
+ const capabilities = {};
67
+ const clientOptions = {
68
+ url: hostToUrl(parsed),
69
+ clientId,
70
+ clientType: "cli",
71
+ capabilities,
72
+ transport: opts.transport ?? directTransport(opts.password),
73
+ ...(opts.rpcTimeoutMs !== undefined ? { rpcTimeoutMs: opts.rpcTimeoutMs } : {}),
74
+ };
75
+ return new DaemonClient(clientOptions);
76
+ }
77
+ /** Build and connect a `DaemonClient`, completing the hello handshake. */
78
+ export async function connectDaemon(opts) {
79
+ const client = buildDaemonClient(opts);
80
+ const serverInfo = await client.connect();
81
+ return { client, serverInfo };
82
+ }
83
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,YAAY,GAGb,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE9D,sEAAsE;AACtE,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC;AACxC,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC;AASjC;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;QAC5B,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IACrE,CAAC;IACD,IAAI,GAAG,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IACvB,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,GAAG,CAAC,UA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AAE,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChF,CAAC;IACF,OAAO,IAAI,YAAY,CAAC,aAAa,CAAC,CAAC;AACzC,CAAC;AAED,0EAA0E;AAC1E,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAAoB;IAEpB,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACvC,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IAC1C,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AAChC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { Command } from "commander";
2
+ import { type CliContext, type GlobalOptions } from "./cli-core.js";
3
+ /** Render the pairing QR + link for the daemon at `home`. Returns an exit code. */
4
+ export declare function printPairing(ctx: CliContext, home: string, hostArg: string | undefined): Promise<number>;
5
+ /** Ensure a local daemon is running (start it if not), then print the pairing QR. */
6
+ export declare function ensureLocalDaemonAndPair(ctx: CliContext, opts: GlobalOptions, startOpts?: {
7
+ sleep?: (ms: number) => Promise<void>;
8
+ }): Promise<number>;
9
+ export declare function registerDaemonCommands(program: Command, ctx: CliContext, setExit: (code: number) => void): void;
10
+ //# sourceMappingURL=daemon-commands.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"daemon-commands.d.ts","sourceRoot":"","sources":["../src/daemon-commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,aAAa,EAAuB,MAAM,eAAe,CAAC;AA4BzF,mFAAmF;AACnF,wBAAsB,YAAY,CAChC,GAAG,EAAE,UAAU,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GAAG,SAAS,GAC1B,OAAO,CAAC,MAAM,CAAC,CAYjB;AAED,qFAAqF;AACrF,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,UAAU,EACf,IAAI,EAAE,aAAa,EACnB,SAAS,GAAE;IAAE,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAAO,GACxD,OAAO,CAAC,MAAM,CAAC,CAmBjB;AAED,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAC9B,IAAI,CA6DN"}
@@ -0,0 +1,108 @@
1
+ import { EXIT_ERROR, EXIT_OK } from "./cli-core.js";
2
+ import { resolveHome } from "./client-id.js";
3
+ import { parseHost } from "./connection.js";
4
+ import { daemonStatus, defaultDaemonRuntime, setDaemonPassword, stopDaemon, waitForDaemon, } from "./daemon-control.js";
5
+ import { buildPairingUrl, readDaemonPublicKey } from "./pairing.js";
6
+ import { renderQrToTerminal } from "./qr.js";
7
+ /**
8
+ * Daemon command group + local spawn + QR pairing (features/cli.md § Command tree (daemon),
9
+ * § Behavior; architecture/daemon-bootstrap.md; architecture/relay-e2ee.md § Pairing).
10
+ */
11
+ /** Resolve the effective `$PI_STUDIO_HOME` for control operations. */
12
+ function resolveCtxHome(ctx, opts) {
13
+ return ctx.connectOverrides?.home ?? opts.home ?? resolveHome();
14
+ }
15
+ function runtimeOf(ctx) {
16
+ return ctx.daemon ?? defaultDaemonRuntime();
17
+ }
18
+ /** Render the pairing QR + link for the daemon at `home`. Returns an exit code. */
19
+ export async function printPairing(ctx, home, hostArg) {
20
+ const publicKey = readDaemonPublicKey(home);
21
+ if (!publicKey) {
22
+ ctx.sink.error("no daemon keypair found — start the daemon first (`pi-studio daemon start`).");
23
+ return EXIT_ERROR;
24
+ }
25
+ const { host, port } = parseHost(hostArg);
26
+ const url = buildPairingUrl(publicKey, { host: `${host}:${port}` });
27
+ const qr = await renderQrToTerminal(url);
28
+ ctx.sink.write(qr);
29
+ ctx.sink.write(`Pairing link: ${url}`);
30
+ return EXIT_OK;
31
+ }
32
+ /** Ensure a local daemon is running (start it if not), then print the pairing QR. */
33
+ export async function ensureLocalDaemonAndPair(ctx, opts, startOpts = {}) {
34
+ const runtime = runtimeOf(ctx);
35
+ const home = resolveCtxHome(ctx, opts);
36
+ const { host, port } = parseHost(opts.host);
37
+ if (await runtime.probe(host, port)) {
38
+ ctx.sink.write(`daemon already running at ${host}:${port}`);
39
+ return printPairing(ctx, home, opts.host);
40
+ }
41
+ ctx.sink.write(`starting local daemon at ${host}:${port} …`);
42
+ await runtime.start({ home, listen: `${host}:${port}` });
43
+ const up = await waitForDaemon(runtime, host, port, { sleep: startOpts.sleep });
44
+ if (!up) {
45
+ ctx.sink.error("daemon did not become healthy in time.");
46
+ return EXIT_ERROR;
47
+ }
48
+ ctx.sink.write(`daemon listening at ${host}:${port}`);
49
+ return printPairing(ctx, home, opts.host);
50
+ }
51
+ export function registerDaemonCommands(program, ctx, setExit) {
52
+ const g = () => program.opts();
53
+ const daemon = program.command("daemon").description("manage the local daemon");
54
+ daemon
55
+ .command("status")
56
+ .description("report daemon health")
57
+ .action(async () => {
58
+ const { up, host, port } = await daemonStatus(runtimeOf(ctx), g().host);
59
+ if (g().json)
60
+ ctx.sink.write(JSON.stringify({ up, host, port }));
61
+ else
62
+ ctx.sink.write(`daemon ${up ? "up" : "down"} at ${host}:${port}`);
63
+ setExit(up ? EXIT_OK : EXIT_ERROR);
64
+ });
65
+ daemon
66
+ .command("start")
67
+ .description("start a local daemon and show a pairing QR code")
68
+ .action(async () => {
69
+ setExit(await ensureLocalDaemonAndPair(ctx, g()));
70
+ });
71
+ daemon
72
+ .command("stop")
73
+ .description("stop the local daemon")
74
+ .action(() => {
75
+ const stopped = stopDaemon(resolveCtxHome(ctx, g()), runtimeOf(ctx));
76
+ ctx.sink.write(stopped ? "daemon stopped" : "no running daemon found");
77
+ setExit(stopped ? EXIT_OK : EXIT_ERROR);
78
+ });
79
+ daemon
80
+ .command("restart")
81
+ .description("restart the local daemon")
82
+ .action(async () => {
83
+ stopDaemon(resolveCtxHome(ctx, g()), runtimeOf(ctx));
84
+ setExit(await ensureLocalDaemonAndPair(ctx, g()));
85
+ });
86
+ daemon
87
+ .command("pair")
88
+ .description("render the pairing QR code / link")
89
+ .action(async () => {
90
+ setExit(await printPairing(ctx, resolveCtxHome(ctx, g()), g().host));
91
+ });
92
+ daemon
93
+ .command("set-password <password>")
94
+ .description("set the daemon password (bcrypt-hashed into config.json)")
95
+ .action((password) => {
96
+ setDaemonPassword(resolveCtxHome(ctx, g()), password, runtimeOf(ctx));
97
+ ctx.sink.write("password set; restart the daemon to enforce it.");
98
+ setExit(EXIT_OK);
99
+ });
100
+ // top-level `onboard` — start/connect + show QR.
101
+ program
102
+ .command("onboard")
103
+ .description("start a local daemon (if needed) and show a pairing QR code")
104
+ .action(async () => {
105
+ setExit(await ensureLocalDaemonAndPair(ctx, g()));
106
+ });
107
+ }
108
+ //# sourceMappingURL=daemon-commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"daemon-commands.js","sourceRoot":"","sources":["../src/daemon-commands.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuC,UAAU,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAEL,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,aAAa,GACd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C;;;GAGG;AAEH,sEAAsE;AACtE,SAAS,cAAc,CAAC,GAAe,EAAE,IAAmB;IAC1D,OAAO,GAAG,CAAC,gBAAgB,EAAE,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,WAAW,EAAE,CAAC;A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IAAI,EAAE;QACjB,UAAU,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;QACrD,OAAO,CAAC,MAAM,wBAAwB,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEL,MAAM;SACH,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,mCAAmC,CAAC;SAChD,MAAM,CAAC,KAAK,IAAI,EAAE;QACjB,OAAO,CAAC,MAAM,YAAY,CAAC,GAAG,EAAE,cAAc,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEL,MAAM;SACH,OAAO,CAAC,yBAAyB,CAAC;SAClC,WAAW,CAAC,0DAA0D,CAAC;SACvE,MAAM,CAAC,CAAC,QAAgB,EAAE,EAAE;QAC3B,iBAAiB,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;QACtE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,iDAAiD,CAAC,CAAC;QAClE,OAAO,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;IAEL,iDAAiD;IACjD,OAAO;SACJ,OAAO,CAAC,SAAS,CAAC;SAClB,WAAW,CAAC,6DAA6D,CAAC;SAC1E,MAAM,CAAC,KAAK,IAAI,EAAE;QACjB,OAAO,CAAC,MAAM,wBAAwB,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Local daemon control (features/cli.md § Command tree (daemon), § Behavior). The CLI and daemon
3
+ * share `$PI_STUDIO_HOME`, so control operations read/write that directory directly
4
+ * (`config.json`, `pi-studio.pid`, `daemon-keypair.json`) and probe the HTTP health endpoint.
5
+ *
6
+ * Side-effecting operations (process spawn/kill, network probe, password hashing) are injectable so
7
+ * the command layer is unit-testable without touching real processes or sockets.
8
+ */
9
+ export declare const PID_FILE = "pi-studio.pid";
10
+ export declare const CONFIG_FILE = "config.json";
11
+ export declare const HEALTH_PATH = "/api/health";
12
+ export interface DaemonPaths {
13
+ config: string;
14
+ pid: string;
15
+ keypair: string;
16
+ }
17
+ export declare function daemonPaths(home: string): DaemonPaths;
18
+ /** Read the recorded daemon pid (or null when no live lock file). */
19
+ export declare function readDaemonPid(home: string): number | null;
20
+ /** Probe whether a daemon answers the health endpoint at host:port. */
21
+ export type HealthProbe = (host: string, port: number) => Promise<boolean>;
22
+ /** Hash a plaintext password (bcrypt). */
23
+ export type PasswordHasher = (plaintext: string) => string;
24
+ /** Send a signal to a pid; returns true on success. */
25
+ export type ProcessKiller = (pid: number, signal?: NodeJS.Signals) => boolean;
26
+ /** Start a detached daemon process; returns its pid. */
27
+ export type DaemonStarter = (opts: {
28
+ home: string;
29
+ listen: string;
30
+ }) => Promise<number>;
31
+ export interface DaemonRuntime {
32
+ probe: HealthProbe;
33
+ hash: PasswordHasher;
34
+ kill: ProcessKiller;
35
+ start: DaemonStarter;
36
+ }
37
+ /** Default health probe via node:http GET /api/health (200 ⇒ up). */
38
+ export declare const httpHealthProbe: HealthProbe;
39
+ export declare const bcryptHasher: PasswordHasher;
40
+ export declare const signalKiller: ProcessKiller;
41
+ /**
42
+ * Default daemon starter: spawn a detached Node process that boots the daemon from
43
+ * `@av-pi-studio/server`. Resolves once the process is spawned (health is then polled by the
44
+ * caller). The server entry is resolved lazily so the CLI does not hard-depend on the server build.
45
+ */
46
+ export declare const subprocessStarter: DaemonStarter;
47
+ export declare function defaultDaemonRuntime(): DaemonRuntime;
48
+ /** Report whether the daemon at the given host is reachable. */
49
+ export declare function daemonStatus(runtime: DaemonRuntime, hostArg?: string): Promise<{
50
+ up: boolean;
51
+ host: string;
52
+ port: number;
53
+ }>;
54
+ /**
55
+ * Write a bcrypt-hashed password into `config.json` (daemon.auth.password). The daemon enforces it
56
+ * on its next (re)start. Preserves existing config; creates the file/home if missing.
57
+ */
58
+ export declare function setDaemonPassword(home: string, plaintext: string, runtime: DaemonRuntime): void;
59
+ /** Stop the local daemon by signaling its recorded pid. Returns false when no daemon was found. */
60
+ export declare function stopDaemon(home: string, runtime: DaemonRuntime): boolean;
61
+ /** Poll the health endpoint until the daemon is up or attempts are exhausted. */
62
+ export declare function waitForDaemon(runtime: DaemonRuntime, host: string, port: number, opts?: {
63
+ attempts?: number;
64
+ delayMs?: number;
65
+ sleep?: (ms: number) => Promise<void>;
66
+ }): Promise<boolean>;
67
+ //# sourceMappingURL=daemon-control.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"daemon-control.d.ts","sourceRoot":"","sources":["../src/daemon-control.ts"],"names":[],"mappings":"AASA;;;;;;;GAOG;AAEH,eAAO,MAAM,QAAQ,kBAAkB,CAAC;AACxC,eAAO,MAAM,WAAW,gBAAgB,CAAC;AACzC,eAAO,MAAM,WAAW,gBAAgB,CAAC;AAEzC,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAMrD;AAED,qEAAqE;AACrE,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CASzD;AAID,uEAAuE;AACvE,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAE3E,0CAA0C;AAC1C,MAAM,MAAM,cAAc,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;AAE3D,uDAAuD;AACvD,MAAM,MAAM,a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