@geohar/un-bien 0.7.0 → 0.9.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.
Files changed (89) hide show
  1. package/README.md +237 -268
  2. package/dist/bin/launcher.js +38 -0
  3. package/dist/bin/launcher.js.map +1 -0
  4. package/dist/config.d.ts +41 -1
  5. package/dist/config.js.map +1 -1
  6. package/dist/daemon/install.d.ts +33 -35
  7. package/dist/daemon/install.js +43 -73
  8. package/dist/daemon/install.js.map +1 -1
  9. package/dist/enrich_tool_args.d.ts +9 -0
  10. package/dist/enrich_tool_args.js +171 -0
  11. package/dist/enrich_tool_args.js.map +1 -0
  12. package/dist/image_codec.d.ts +22 -0
  13. package/dist/image_codec.js +149 -0
  14. package/dist/image_codec.js.map +1 -0
  15. package/dist/index.d.ts +0 -26
  16. package/dist/index.js +235 -1237
  17. package/dist/index.js.map +1 -1
  18. package/dist/launch.d.ts +34 -0
  19. package/dist/launch.js +171 -0
  20. package/dist/launch.js.map +1 -0
  21. package/dist/launcher/launcher.d.ts +6 -0
  22. package/dist/launcher/launcher.js +188 -0
  23. package/dist/launcher/launcher.js.map +1 -0
  24. package/dist/pairing/crypto.d.ts +4 -0
  25. package/dist/pairing/crypto.js +10 -0
  26. package/dist/pairing/crypto.js.map +1 -1
  27. package/dist/pairing/peer_trust.d.ts +20 -0
  28. package/dist/pairing/peer_trust.js +82 -0
  29. package/dist/pairing/peer_trust.js.map +1 -0
  30. package/dist/pairing/storage.d.ts +51 -26
  31. package/dist/pairing/storage.js +346 -136
  32. package/dist/pairing/storage.js.map +1 -1
  33. package/dist/panel_bridge.d.ts +3 -1
  34. package/dist/panel_bridge.js +10 -10
  35. package/dist/panel_bridge.js.map +1 -1
  36. package/dist/rooms.d.ts +16 -0
  37. package/dist/rooms.js +22 -0
  38. package/dist/rooms.js.map +1 -1
  39. package/dist/session/debug_log.js +2 -2
  40. package/dist/session/debug_log.js.map +1 -1
  41. package/dist/session/local_config.js +2 -0
  42. package/dist/session/local_config.js.map +1 -1
  43. package/dist/session/rpc_envelope.d.ts +18 -0
  44. package/dist/session/rpc_envelope.js +1 -1
  45. package/dist/session/rpc_envelope.js.map +1 -1
  46. package/dist/session/rpc_inbound.d.ts +2 -2
  47. package/dist/session/rpc_inbound.js +1 -1
  48. package/dist/session/rpc_inbound.js.map +1 -1
  49. package/dist/subagent_rooms.d.ts +49 -0
  50. package/dist/subagent_rooms.js +787 -0
  51. package/dist/subagent_rooms.js.map +1 -0
  52. package/dist/transport/peer_channel.d.ts +7 -1
  53. package/dist/transport/peer_channel.js +8 -1
  54. package/dist/transport/peer_channel.js.map +1 -1
  55. package/dist/transport/relay_client.d.ts +19 -0
  56. package/dist/transport/relay_client.js.map +1 -1
  57. package/docs/daemon.md +65 -64
  58. package/package.json +13 -11
  59. package/service-templates/launchd.plist.template +5 -5
  60. package/service-templates/systemd.service.template +2 -2
  61. package/service-templates/task-launcher.vbs.template +5 -5
  62. package/service-templates/task-scheduler.xml.template +1 -1
  63. package/dist/bin/supervisord.js +0 -86
  64. package/dist/bin/supervisord.js.map +0 -1
  65. package/dist/daemon/client.d.ts +0 -20
  66. package/dist/daemon/client.js +0 -131
  67. package/dist/daemon/client.js.map +0 -1
  68. package/dist/daemon/control_protocol.d.ts +0 -176
  69. package/dist/daemon/control_protocol.js +0 -63
  70. package/dist/daemon/control_protocol.js.map +0 -1
  71. package/dist/daemon/cron_log.d.ts +0 -45
  72. package/dist/daemon/cron_log.js +0 -71
  73. package/dist/daemon/cron_log.js.map +0 -1
  74. package/dist/daemon/cron_registry.d.ts +0 -80
  75. package/dist/daemon/cron_registry.js +0 -198
  76. package/dist/daemon/cron_registry.js.map +0 -1
  77. package/dist/daemon/id.d.ts +0 -24
  78. package/dist/daemon/id.js +0 -36
  79. package/dist/daemon/id.js.map +0 -1
  80. package/dist/daemon/registry.d.ts +0 -63
  81. package/dist/daemon/registry.js +0 -153
  82. package/dist/daemon/registry.js.map +0 -1
  83. package/dist/daemon/rpc_child.d.ts +0 -194
  84. package/dist/daemon/rpc_child.js +0 -419
  85. package/dist/daemon/rpc_child.js.map +0 -1
  86. package/dist/daemon/supervisor.d.ts +0 -93
  87. package/dist/daemon/supervisor.js +0 -666
  88. package/dist/daemon/supervisor.js.map +0 -1
  89. /package/dist/bin/{supervisord.d.ts → launcher.d.ts} +0 -0
@@ -1,86 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * `pi-supervisord` — long-running daemon supervisor.
4
- *
5
- * Entry point of the `pi-supervisord` binary (plan/26 W2). Run by
6
- * systemd/launchd in production, or directly during dev:
7
- *
8
- * pnpm build
9
- * node dist/bin/supervisord.js
10
- *
11
- * Once running, it:
12
- * - Reads `~/.pi/un-bien/daemons.json`
13
- * - Spawns `pi --mode rpc -e <un-bien/dist/index.js>` per entry
14
- * - Listens on `~/.pi/un-bien/supervisor.sock` for CLI control requests
15
- * - Restarts crashed children with exponential backoff
16
- *
17
- * Exits cleanly on SIGTERM/SIGINT (used by `unbien uninstall`).
18
- */
19
- import { fileURLToPath } from "node:url";
20
- import { dirname, join } from "node:path";
21
- import { Supervisor, SupervisorAlreadyRunningError, } from "../daemon/supervisor.js";
22
- const HELP_TEXT = `pi-supervisord — Remote Pi daemon supervisor
23
-
24
- Usage: pi-supervisord
25
-
26
- Runs the long-lived supervisor: reads ~/.pi/un-bien/daemons.json, spawns one
27
- \`pi --mode rpc\` child per entry, and listens on ~/.pi/un-bien/supervisor.sock
28
- for control requests from the \`un-bien\` CLI.
29
-
30
- This binary takes NO arguments — it is normally launched by systemd/launchd
31
- (via \`unbien install\`), not by hand. Manage the fleet with:
32
- unbien daemon start | stop | restart | status
33
- unbien daemons
34
-
35
- Options:
36
- -h, --help Show this help and exit
37
- -v, --version Print version and exit
38
- `;
39
- async function main() {
40
- // Guard: any stray argument used to fall through and start a FULL
41
- // supervisor (a `pi-supervisord --help` once ran for days). Handle the
42
- // conventional flags explicitly and reject unknown args instead of
43
- // silently spawning the daemon fleet.
44
- const args = process.argv.slice(2);
45
- if (args.includes("-h") || args.includes("--help")) {
46
- process.stdout.write(HELP_TEXT);
47
- return;
48
- }
49
- if (args.includes("-v") || args.includes("--version")) {
50
- process.stdout.write("pi-supervisord (un-bien)\n");
51
- return;
52
- }
53
- if (args.length > 0) {
54
- process.stderr.write(`pi-supervisord: unexpected argument(s): ${args.join(" ")}\n` +
55
- "This binary takes no arguments. Run `pi-supervisord --help`.\n");
56
- process.exit(2);
57
- }
58
- // The supervisor needs to point each spawned Pi at the extension
59
- // entry it's bundled with. We're at `dist/bin/supervisord.js` after
60
- // build; the extension is the sibling `dist/index.js`.
61
- const here = fileURLToPath(import.meta.url);
62
- const distRoot = dirname(dirname(here)); // dist/bin → dist
63
- const extensionPath = join(distRoot, "index.js");
64
- const supervisor = new Supervisor({ extensionPath });
65
- await supervisor.start();
66
- process.stderr.write(`[pi-supervisord] up — UDS: ~/.pi/un-bien/supervisor.sock, extension: ${extensionPath}\n`);
67
- const shutdown = async (signal) => {
68
- process.stderr.write(`[pi-supervisord] received ${signal}, shutting down\n`);
69
- await supervisor.stop();
70
- process.exit(0);
71
- };
72
- process.on("SIGTERM", () => void shutdown("SIGTERM"));
73
- process.on("SIGINT", () => void shutdown("SIGINT"));
74
- }
75
- main().catch((err) => {
76
- // "Already running" is a normal, expected condition (systemd/launchd may
77
- // race a manual start, or the user double-launches) — not a crash. Report
78
- // it calmly and exit 0 so service managers don't flag a failure loop.
79
- if (err instanceof SupervisorAlreadyRunningError) {
80
- process.stderr.write(`[pi-supervisord] ${err.message}\n`);
81
- process.exit(0);
82
- }
83
- process.stderr.write(`[pi-supervisord] fatal: ${String(err)}\n`);
84
- process.exit(1);
85
- });
86
- //# sourceMappingURL=supervisord.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"supervisord.js","sourceRoot":"","sources":["../../src/bin/supervisord.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,UA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C,CAAC;IAEjD,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC;IACrD,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;IACzB,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,wEAAwE,aAAa,IAAI,CAC1F,CAAC;IAEF,MAAM,QAAQ,GAAG,KAAK,EAAE,MAAc,EAAE,EAAE;QACxC,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,6BAA6B,MAAM,mBAAmB,CACvD,CAAC;QACF,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC;QACxB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC;IACF,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,KAAK,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;IACtD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;AACtD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,yEAAyE;IACzE,0EAA0E;IAC1E,sEAAsE;IACtE,IAAI,GAAG,YAAY,6BAA6B,EAAE,CAAC;QACjD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC;QAC1D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACjE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -1,20 +0,0 @@
1
- import { type ControlReplyFor, type ControlRequest } from "./control_protocol.js";
2
- export declare class SupervisorOfflineError extends Error {
3
- readonly sockPath: string;
4
- constructor(sockPath: string);
5
- }
6
- /**
7
- * Sends a single request and returns the typed reply data.
8
- *
9
- * Throws:
10
- * - `SupervisorOfflineError` when the supervisor isn't reachable.
11
- * - `Error` from `parseReply` when the reply line is malformed.
12
- * - The supervisor's own error string when `ok: false`.
13
- */
14
- export declare function callSupervisor<Op extends ControlRequest["op"]>(req: Extract<ControlRequest, {
15
- op: Op;
16
- }>): Promise<ControlReplyFor<Op>>;
17
- /** Returns true when the supervisor is reachable. Used by `/unbien
18
- * daemons` to decide whether to query runtime state or fall back to
19
- * registry-only listing. */
20
- export declare function supervisorOnline(): Promise<boolean>;
@@ -1,131 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { createConnection } from "node:net";
3
- import { encodeRequest, parseReply, } from "./control_protocol.js";
4
- import { getSupervisorSockPath } from "./supervisor.js";
5
- import { usesNamedPipe } from "../session/ipc.js";
6
- /**
7
- * Tiny client for the `un-bien` CLI to call the supervisor over the
8
- * `~/.pi/un-bien/supervisor.sock` UDS.
9
- *
10
- * Each call opens a fresh connection, sends one request line, reads one
11
- * reply line, closes. No connection pooling — the CLI is short-lived,
12
- * latency is dominated by the socket round-trip (<1ms).
13
- *
14
- * `SupervisorOfflineError` is the common error: thrown when the socket
15
- * file is missing OR the connect fails (no listener). The CLI handler
16
- * formats it as a friendly "Run `unbien install` first" message.
17
- */
18
- const CONNECT_TIMEOUT_MS = 1000;
19
- const REPLY_TIMEOUT_MS = 5000;
20
- export class SupervisorOfflineError extends Error {
21
- sockPath;
22
- constructor(sockPath) {
23
- super(`Supervisor is not running. UDS not responding at ${sockPath}.\n` +
24
- "Run `unbien install` to set it up, or start it manually with `pi-supervisord`.");
25
- this.sockPath = sockPath;
26
- this.name = "SupervisorOfflineError";
27
- }
28
- }
29
- /**
30
- * Sends a single request and returns the typed reply data.
31
- *
32
- * Throws:
33
- * - `SupervisorOfflineError` when the supervisor isn't reachable.
34
- * - `Error` from `parseReply` when the reply line is malformed.
35
- * - The supervisor's own error string when `ok: false`.
36
- */
37
- export async function callSupervisor(req) {
38
- const sockPath = getSupervisorSockPath();
39
- // POSIX fast-fail on a missing socket file. Windows pipes have no file —
40
- // skip the check and let `_connect` fail fast if the pipe isn't there.
41
- if (!usesNamedPipe() && !existsSync(sockPath))
42
- throw new SupervisorOfflineError(sockPath);
43
- const sock = await _connect(sockPath);
44
- try {
45
- sock.write(encodeRequest(req));
46
- const line = await _readLine(sock);
47
- const reply = parseReply(line);
48
- if (!reply.ok)
49
- throw new Error(reply.error);
50
- return reply.data;
51
- }
52
- finally {
53
- sock.destroy();
54
- }
55
- }
56
- /** Returns true when the supervisor is reachable. Used by `/unbien
57
- * daemons` to decide whether to query runtime state or fall back to
58
- * registry-only listing. */
59
- export async function supervisorOnline() {
60
- const sockPath = getSupervisorSockPath();
61
- if (!usesNamedPipe() && !existsSync(sockPath))
62
- return false;
63
- try {
64
- const sock = await _connect(sockPath);
65
- sock.destroy();
66
- return true;
67
- }
68
- catch {
69
- return false;
70
- }
71
- }
72
- // ── internals ───────────────────────────────────────────────────────────────
73
- function _connect(sockPath) {
74
- return new Promise((resolve, reject) => {
75
- const sock = createConnection({ path: sockPath });
76
- let settled = false;
77
- const timer = setTimeout(() => {
78
- if (settled)
79
- return;
80
- settled = true;
81
- sock.destroy();
82
- reject(new SupervisorOfflineError(sockPath));
83
- }, CONNECT_TIMEOUT_MS);
84
- sock.once("connect", () => {
85
- if (settled)
86
- return;
87
- settled = true;
88
- clearTimeout(timer);
89
- sock.setEncoding("utf8");
90
- resolve(sock);
91
- });
92
- sock.once("error", () => {
93
- if (settled)
94
- return;
95
- settled = true;
96
- clearTimeout(timer);
97
- reject(new SupervisorOfflineError(sockPath));
98
- });
99
- });
100
- }
101
- function _readLine(sock) {
102
- return new Promise((resolve, reject) => {
103
- let buf = "";
104
- const timer = setTimeout(() => {
105
- reject(new Error("supervisor reply timeout"));
106
- sock.destroy();
107
- }, REPLY_TIMEOUT_MS);
108
- sock.on("data", (chunk) => {
109
- buf += chunk;
110
- const nl = buf.indexOf("\n");
111
- if (nl >= 0) {
112
- clearTimeout(timer);
113
- resolve(buf.slice(0, nl));
114
- }
115
- });
116
- sock.on("end", () => {
117
- clearTimeout(timer);
118
- const nl = buf.indexOf("\n");
119
- if (nl >= 0)
120
- return resolve(buf.slice(0, nl));
121
- if (buf.length > 0)
122
- return resolve(buf);
123
- reject(new Error("supervisor closed connection without replying"));
124
- });
125
- sock.on("error", (err) => {
126
- clearTimeout(timer);
127
- reject(err);
128
- });
129
- });
130
- }
131
- //# sourceMappingURL=client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/daemon/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAe,MAAM,UAAU,CAAC;AACzD,OAAO,EAIL,aAAa,EACb,UAAU,GACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;;;;;;;;GAWG;AAEH,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAChC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IACnB;IAA5B,YAA4B,QAAgB;QAC1C,KAAK,CACH,oDAAoD,QAAQ,KAAK;YAC/D,gFAAgF,CACnF,CAAC;QAJwB,aAAQ,GAAR,QAAQ,CAAQ;QAK1C,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,GAAwC;IAExC,MAAM,QAAQ,GAAG,qBAAqB,EAAE,CAAC;IACzC,yEAAyE;IACzE,uEAAuE;IACvE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;QAC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AC;gBACZ,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YAClB,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC7B,IAAI,EAAE,IAAI,CAAC;gBAAE,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;YAC9C,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC;gBAAE,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC;YACxC,MAAM,CAAC,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC,CAAC;QACrE,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YACvB,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,176 +0,0 @@
1
- /**
2
- * CLI ↔ supervisor IPC contract for `~/.pi/un-bien/supervisor.sock`.
3
- *
4
- * Framing: one JSON object per line, newline-terminated. The CLI sends a
5
- * single `ControlRequest`, the supervisor sends a single `ControlReply`,
6
- * both close the connection. No multiplexing, no streaming — each command
7
- * is a short round-trip.
8
- *
9
- * Plan/26 W2. The Pi RPC protocol (`pi --mode rpc`) used by the daemon
10
- * children themselves is a separate contract — see
11
- * `node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-types.d.ts`.
12
- * This file is strictly the supervisor's own control plane.
13
- */
14
- import type { CronJob } from "./cron_registry.js";
15
- import type { CronLogEntry } from "./cron_log.js";
16
- /** Per-daemon runtime state observable through the supervisor. */
17
- export type DaemonState = "running" | "stopped" | "starting" | "crashed";
18
- export interface DaemonInfo {
19
- id: string;
20
- cwd: string;
21
- name: string;
22
- state: DaemonState;
23
- pid?: number;
24
- uptime_s?: number;
25
- restart_count?: number;
26
- }
27
- /** Requests sent CLI → supervisor. */
28
- export type ControlRequest = {
29
- op: "list";
30
- } | {
31
- op: "status";
32
- } | {
33
- op: "start_all";
34
- } | {
35
- op: "start";
36
- id: string;
37
- } | {
38
- op: "stop_all";
39
- } | {
40
- op: "stop";
41
- id: string;
42
- } | {
43
- op: "restart_all";
44
- } | {
45
- op: "restart";
46
- id: string;
47
- } | {
48
- op: "send";
49
- id: string;
50
- text: string;
51
- } | {
52
- op: "register";
53
- cwd: string;
54
- } | {
55
- op: "unregister";
56
- id: string;
57
- } | {
58
- op: "cron_add";
59
- daemon_id: string;
60
- schedule: string;
61
- prompt: string;
62
- tz?: string;
63
- skip_if_busy?: boolean;
64
- wake?: boolean;
65
- catchup?: boolean;
66
- } | {
67
- op: "cron_list";
68
- } | {
69
- op: "cron_remove";
70
- job_id: string;
71
- } | {
72
- op: "cron_enable";
73
- job_id: string;
74
- enabled: boolean;
75
- } | {
76
- op: "cron_run";
77
- job_id: string;
78
- } | {
79
- op: "cron_log";
80
- job_id?: string;
81
- tail?: number;
82
- };
83
- /** Replies sent supervisor → CLI. Tagged by `ok` boolean. */
84
- export type ControlReply<T = unknown> = {
85
- ok: true;
86
- data?: T;
87
- } | {
88
- ok: false;
89
- error: string;
90
- };
91
- /**
92
- * Response shapes per op. Keep in sync with the supervisor handlers in
93
- * `daemon/supervisor.ts`. Used for typed client calls.
94
- */
95
- export interface ControlReplyShapes {
96
- list: {
97
- daemons: DaemonInfo[];
98
- };
99
- status: {
100
- daemons: DaemonInfo[];
101
- };
102
- start_all: {
103
- started: string[];
104
- already_running: string[];
105
- };
106
- start: {
107
- id: string;
108
- state: DaemonState;
109
- started: boolean;
110
- };
111
- stop_all: {
112
- stopped: string[];
113
- already_stopped: string[];
114
- };
115
- stop: {
116
- id: string;
117
- state: DaemonState;
118
- stopped: boolean;
119
- };
120
- restart_all: {
121
- restarted: string[];
122
- };
123
- restart: {
124
- id: string;
125
- state: DaemonState;
126
- restarted: boolean;
127
- };
128
- send: {
129
- id: string;
130
- delivered: boolean;
131
- };
132
- register: {
133
- id: string;
134
- cwd: string;
135
- };
136
- unregister: {
137
- removed: boolean;
138
- cwd?: string;
139
- };
140
- cron_add: {
141
- job: CronJobView;
142
- };
143
- cron_list: {
144
- jobs: CronJobView[];
145
- };
146
- cron_remove: {
147
- removed: boolean;
148
- };
149
- cron_enable: {
150
- job_id: string;
151
- enabled: boolean;
152
- updated: boolean;
153
- };
154
- cron_run: {
155
- job_id: string;
156
- result: string;
157
- };
158
- cron_log: {
159
- entries: CronLogEntry[];
160
- };
161
- }
162
- /** A cron job plus its computed `next_run` (ISO), for `cron list`. */
163
- export type CronJobView = CronJob & {
164
- next_run?: string | null;
165
- };
166
- /** Convenience for typed `Client.request<...>("op")` calls. */
167
- export type ControlReplyFor<Op extends ControlRequest["op"]> = Op extends keyof ControlReplyShapes ? ControlReplyShapes[Op] : never;
168
- export declare function encodeRequest(req: ControlRequest): string;
169
- export declare function encodeReply<T>(reply: ControlReply<T>): string;
170
- /**
171
- * Parses a single JSON line into a request. Throws on malformed input —
172
- * the supervisor catches and replies `{ok:false, error}` so the client
173
- * gets a clean error rather than an unframed disconnect.
174
- */
175
- export declare function parseRequest(line: string): ControlRequest;
176
- export declare function parseReply(line: string): ControlReply<unknown>;
@@ -1,63 +0,0 @@
1
- /**
2
- * CLI ↔ supervisor IPC contract for `~/.pi/un-bien/supervisor.sock`.
3
- *
4
- * Framing: one JSON object per line, newline-terminated. The CLI sends a
5
- * single `ControlRequest`, the supervisor sends a single `ControlReply`,
6
- * both close the connection. No multiplexing, no streaming — each command
7
- * is a short round-trip.
8
- *
9
- * Plan/26 W2. The Pi RPC protocol (`pi --mode rpc`) used by the daemon
10
- * children themselves is a separate contract — see
11
- * `node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-types.d.ts`.
12
- * This file is strictly the supervisor's own control plane.
13
- */
14
- // ── Serialization helpers ────────────────────────────────────────────────────
15
- const TRAILING_NEWLINE = "\n";
16
- export function encodeRequest(req) {
17
- return JSON.stringify(req) + TRAILING_NEWLINE;
18
- }
19
- export function encodeReply(reply) {
20
- return JSON.stringify(reply) + TRAILING_NEWLINE;
21
- }
22
- /**
23
- * Parses a single JSON line into a request. Throws on malformed input —
24
- * the supervisor catches and replies `{ok:false, error}` so the client
25
- * gets a clean error rather than an unframed disconnect.
26
- */
27
- export function parseRequest(line) {
28
- let obj;
29
- try {
30
- obj = JSON.parse(line);
31
- }
32
- catch (e) {
33
- throw new Error(`malformed control request: ${e.message}`);
34
- }
35
- if (!obj || typeof obj !== "object") {
36
- throw new Error("control request must be a JSON object");
37
- }
38
- const op = obj.op;
39
- if (typeof op !== "string") {
40
- throw new Error("control request missing string `op` field");
41
- }
42
- // We don't validate every field shape here — supervisor handlers do it
43
- // per-op since the error messages are more specific that way.
44
- return obj;
45
- }
46
- export function parseReply(line) {
47
- let obj;
48
- try {
49
- obj = JSON.parse(line);
50
- }
51
- catch (e) {
52
- throw new Error(`malformed control reply: ${e.message}`);
53
- }
54
- if (!obj || typeof obj !== "object") {
55
- throw new Error("control reply must be a JSON object");
56
- }
57
- const ok = obj.ok;
58
- if (typeof ok !== "boolean") {
59
- throw new Error("control reply missing boolean `ok` field");
60
- }
61
- return obj;
62
- }
63
- //# sourceMappingURL=control_protocol.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"control_protocol.js","sourceRoot":"","sources":["../../src/daemon/control_protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAoFH,gFAAgF;AAEhF,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,MAAM,UAAU,aAAa,CAAC,GAAmB;IAC/C,OAAO,IAAI,CAAC,SAAS,CAAC,GAA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AC;IACxC,IAAI,OAAO,EAAE,KAAK,SAAS,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,GAA4B,CAAC;AACtC,CAAC"}
@@ -1,45 +0,0 @@
1
- /**
2
- * Append-only audit trail for cron fires at `~/.pi/un-bien/cron.jsonl`.
3
- *
4
- * One JSON line per scheduler decision — **every fire AND every skip** — so an
5
- * operator can see exactly what ran and what didn't (the agent's output goes
6
- * fire-and-forget to the relay/mesh, so the dispatch itself needs its own
7
- * trail). Plan/39 decision E.
8
- */
9
- /** Outcome of a single `fireJob` decision. */
10
- export type CronResult = "delivered" | "deliver_failed" | "woke_and_delivered" | "skipped_busy" | "skipped_down" | "skipped_disabled";
11
- export interface CronLogEntry {
12
- /** epoch ms */
13
- ts: number;
14
- job_id: string;
15
- daemon_id: string;
16
- schedule: string;
17
- /** true when a prompt was actually sent (delivered / woke_and_delivered). */
18
- fired: boolean;
19
- result: CronResult;
20
- /** First chars of the prompt, for at-a-glance log reading. */
21
- prompt_preview: string;
22
- }
23
- /** Test/diag-only: the on-disk path. */
24
- export declare function cronLogPath(): string;
25
- /** Maps a result to whether a prompt was actually delivered. */
26
- export declare function firedFor(result: CronResult): boolean;
27
- /**
28
- * Appends one entry. Best-effort: creates the parent dir + file when absent;
29
- * never throws into the scheduler (a logging failure must not abort a fire).
30
- */
31
- export declare function appendCronLog(entry: {
32
- job_id: string;
33
- daemon_id: string;
34
- schedule: string;
35
- result: CronResult;
36
- prompt: string;
37
- }): void;
38
- /**
39
- * Reads the log, newest-last. Optional `jobId` filter and `tail` (last N).
40
- * Missing file → []. Malformed lines are skipped.
41
- */
42
- export declare function readCronLog(opts?: {
43
- jobId?: string;
44
- tail?: number;
45
- }): CronLogEntry[];
@@ -1,71 +0,0 @@
1
- import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
2
- import { dirname, join } from "node:path";
3
- import { unbienStateHome } from "../paths.js";
4
- const PREVIEW_LEN = 80;
5
- function logPath() {
6
- return join(unbienStateHome(), "cron.jsonl");
7
- }
8
- /** Test/diag-only: the on-disk path. */
9
- export function cronLogPath() {
10
- return logPath();
11
- }
12
- /** Maps a result to whether a prompt was actually delivered. */
13
- export function firedFor(result) {
14
- return result === "delivered" || result === "woke_and_delivered";
15
- }
16
- /**
17
- * Appends one entry. Best-effort: creates the parent dir + file when absent;
18
- * never throws into the scheduler (a logging failure must not abort a fire).
19
- */
20
- export function appendCronLog(entry) {
21
- const line = JSON.stringify({
22
- ts: Date.now(),
23
- job_id: entry.job_id,
24
- daemon_id: entry.daemon_id,
25
- schedule: entry.schedule,
26
- fired: firedFor(entry.result),
27
- result: entry.result,
28
- prompt_preview: entry.prompt.slice(0, PREVIEW_LEN),
29
- }) + "\n";
30
- try {
31
- mkdirSync(dirname(logPath()), { recursive: true });
32
- appendFileSync(logPath(), line, "utf8");
33
- }
34
- catch {
35
- /* audit is best-effort — don't break the scheduler on a write error */
36
- }
37
- }
38
- /**
39
- * Reads the log, newest-last. Optional `jobId` filter and `tail` (last N).
40
- * Missing file → []. Malformed lines are skipped.
41
- */
42
- export function readCronLog(opts = {}) {
43
- if (!existsSync(logPath()))
44
- return [];
45
- let raw;
46
- try {
47
- raw = readFileSync(logPath(), "utf8");
48
- }
49
- catch {
50
- return [];
51
- }
52
- const entries = [];
53
- for (const line of raw.split("\n")) {
54
- if (!line.trim())
55
- continue;
56
- try {
57
- const e = JSON.parse(line);
58
- if (opts.jobId && e.job_id !== opts.jobId)
59
- continue;
60
- entries.push(e);
61
- }
62
- catch {
63
- /* skip malformed */
64
- }
65
- }
66
- if (opts.tail !== undefined && opts.tail >= 0 && entries.length > opts.tail) {
67
- return entries.slice(entries.length - opts.tail);
68
- }
69
- return entries;
70
- }
71
- //# sourceMappingURL=cron_log.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cron_log.js","sourceRoot":"","sources":["../../src/daemon/cron_log.ts"],"names":[],"mappings":"AAAA,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