@geohar/un-bien 0.8.0 → 0.14.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 (175) hide show
  1. package/README.md +258 -320
  2. package/dist/actions/handlers.js.map +1 -1
  3. package/dist/actions/registry.js.map +1 -1
  4. package/dist/bin/launcher.js +38 -0
  5. package/dist/bin/launcher.js.map +1 -0
  6. package/dist/commands/deps.d.ts +156 -0
  7. package/dist/commands/deps.js +2 -0
  8. package/dist/commands/deps.js.map +1 -0
  9. package/dist/commands/fork_link.d.ts +4 -0
  10. package/dist/commands/fork_link.js +45 -0
  11. package/dist/commands/fork_link.js.map +1 -0
  12. package/dist/commands/housekeeping.d.ts +34 -0
  13. package/dist/commands/housekeeping.js +275 -0
  14. package/dist/commands/housekeeping.js.map +1 -0
  15. package/dist/commands/info.d.ts +43 -0
  16. package/dist/commands/info.js +127 -0
  17. package/dist/commands/info.js.map +1 -0
  18. package/dist/commands/lifecycle.d.ts +45 -0
  19. package/dist/commands/lifecycle.js +708 -0
  20. package/dist/commands/lifecycle.js.map +1 -0
  21. package/dist/commands/pairing.d.ts +26 -0
  22. package/dist/commands/pairing.js +167 -0
  23. package/dist/commands/pairing.js.map +1 -0
  24. package/dist/commands/register.d.ts +12 -0
  25. package/dist/commands/register.js +255 -0
  26. package/dist/commands/register.js.map +1 -0
  27. package/dist/commands/relay.d.ts +28 -0
  28. package/dist/commands/relay.js +81 -0
  29. package/dist/commands/relay.js.map +1 -0
  30. package/dist/commands/session_ops.d.ts +52 -0
  31. package/dist/commands/session_ops.js +75 -0
  32. package/dist/commands/session_ops.js.map +1 -0
  33. package/dist/config.d.ts +30 -2
  34. package/dist/config.js.map +1 -1
  35. package/dist/daemon/install.d.ts +36 -37
  36. package/dist/daemon/install.js +49 -73
  37. package/dist/daemon/install.js.map +1 -1
  38. package/dist/enrich_tool_args.d.ts +9 -0
  39. package/dist/enrich_tool_args.js +171 -0
  40. package/dist/enrich_tool_args.js.map +1 -0
  41. package/dist/extension_ui_bridge.js.map +1 -1
  42. package/dist/image_codec.d.ts +22 -0
  43. package/dist/image_codec.js +149 -0
  44. package/dist/image_codec.js.map +1 -0
  45. package/dist/index.d.ts +32 -127
  46. package/dist/index.js +957 -4042
  47. package/dist/index.js.map +1 -1
  48. package/dist/launch.d.ts +42 -0
  49. package/dist/launch.js +206 -0
  50. package/dist/launch.js.map +1 -0
  51. package/dist/launcher/launcher.d.ts +6 -0
  52. package/dist/launcher/launcher.js +207 -0
  53. package/dist/launcher/launcher.js.map +1 -0
  54. package/dist/mcp/mesh_result.js.map +1 -1
  55. package/dist/mcp/mesh_server.js.map +1 -1
  56. package/dist/mesh/canonical.js +1 -1
  57. package/dist/mesh/canonical.js.map +1 -1
  58. package/dist/mesh/client.js.map +1 -1
  59. package/dist/mesh/encoding.js.map +1 -1
  60. package/dist/mesh/self_revoke.js.map +1 -1
  61. package/dist/mesh/siblings.js.map +1 -1
  62. package/dist/mesh/verify.js +1 -1
  63. package/dist/mesh/verify.js.map +1 -1
  64. package/dist/pairing/crypto.js +0 -1
  65. package/dist/pairing/crypto.js.map +1 -1
  66. package/dist/pairing/peer_trust.d.ts +20 -0
  67. package/dist/pairing/peer_trust.js +82 -0
  68. package/dist/pairing/peer_trust.js.map +1 -0
  69. package/dist/pairing/qr.js.map +1 -1
  70. package/dist/pairing/storage.js +4 -3
  71. package/dist/pairing/storage.js.map +1 -1
  72. package/dist/panel_bridge.d.ts +3 -1
  73. package/dist/panel_bridge.js +11 -10
  74. package/dist/panel_bridge.js.map +1 -1
  75. package/dist/paths.d.ts +22 -8
  76. package/dist/paths.js +37 -10
  77. package/dist/paths.js.map +1 -1
  78. package/dist/protocol/codec.js.map +1 -1
  79. package/dist/rooms.d.ts +16 -0
  80. package/dist/rooms.js +23 -4
  81. package/dist/rooms.js.map +1 -1
  82. package/dist/session/bridge.js.map +1 -1
  83. package/dist/session/broker.js.map +1 -1
  84. package/dist/session/broker_remote.js.map +1 -1
  85. package/dist/session/capabilities.d.ts +11 -0
  86. package/dist/session/capabilities.js +35 -0
  87. package/dist/session/capabilities.js.map +1 -0
  88. package/dist/session/cwd_lock.js +3 -3
  89. package/dist/session/cwd_lock.js.map +1 -1
  90. package/dist/session/debug_log.js +15 -5
  91. package/dist/session/debug_log.js.map +1 -1
  92. package/dist/session/envelope.js.map +1 -1
  93. package/dist/session/global_config.d.ts +1 -1
  94. package/dist/session/global_config.js +1 -1
  95. package/dist/session/global_config.js.map +1 -1
  96. package/dist/session/ipc.d.ts +2 -2
  97. package/dist/session/ipc.js.map +1 -1
  98. package/dist/session/leader_election.js.map +1 -1
  99. package/dist/session/local_config.d.ts +37 -0
  100. package/dist/session/local_config.js +47 -1
  101. package/dist/session/local_config.js.map +1 -1
  102. package/dist/session/mesh_node.d.ts +1 -1
  103. package/dist/session/mesh_node.js +1 -1
  104. package/dist/session/mesh_node.js.map +1 -1
  105. package/dist/session/peer.js.map +1 -1
  106. package/dist/session/peer_inventory.js.map +1 -1
  107. package/dist/session/peer_limits.js.map +1 -1
  108. package/dist/session/received_images.d.ts +63 -0
  109. package/dist/session/received_images.js +273 -0
  110. package/dist/session/received_images.js.map +1 -0
  111. package/dist/session/relay_lifecycle.d.ts +219 -0
  112. package/dist/session/relay_lifecycle.js +764 -0
  113. package/dist/session/relay_lifecycle.js.map +1 -0
  114. package/dist/session/rpc_envelope.d.ts +28 -0
  115. package/dist/session/rpc_envelope.js +10 -1
  116. package/dist/session/rpc_envelope.js.map +1 -1
  117. package/dist/session/rpc_handlers.d.ts +53 -0
  118. package/dist/session/rpc_handlers.js +268 -0
  119. package/dist/session/rpc_handlers.js.map +1 -0
  120. package/dist/session/rpc_inbound.d.ts +42 -7
  121. package/dist/session/rpc_inbound.js +56 -1
  122. package/dist/session/rpc_inbound.js.map +1 -1
  123. package/dist/session/setup_wizard.js.map +1 -1
  124. package/dist/session/tools.js.map +1 -1
  125. package/dist/session/wizard.js.map +1 -1
  126. package/dist/state_migration.d.ts +45 -0
  127. package/dist/state_migration.js +104 -0
  128. package/dist/state_migration.js.map +1 -0
  129. package/dist/subagent_rooms.d.ts +68 -0
  130. package/dist/subagent_rooms.js +919 -0
  131. package/dist/subagent_rooms.js.map +1 -0
  132. package/dist/test_hooks.d.ts +180 -0
  133. package/dist/test_hooks.js +98 -0
  134. package/dist/test_hooks.js.map +1 -0
  135. package/dist/transport/peer_channel.d.ts +18 -1
  136. package/dist/transport/peer_channel.js +42 -12
  137. package/dist/transport/peer_channel.js.map +1 -1
  138. package/dist/transport/pi_forward_client.js.map +1 -1
  139. package/dist/transport/relay_client.d.ts +24 -2
  140. package/dist/transport/relay_client.js +6 -3
  141. package/dist/transport/relay_client.js.map +1 -1
  142. package/dist/ui/footer.js.map +1 -1
  143. package/docs/daemon.md +170 -179
  144. package/package.json +13 -11
  145. package/service-templates/launchd.plist.template +8 -7
  146. package/service-templates/systemd.service.template +5 -4
  147. package/service-templates/task-launcher.vbs.template +5 -5
  148. package/service-templates/task-scheduler.xml.template +1 -1
  149. package/dist/bin/supervisord.js +0 -86
  150. package/dist/bin/supervisord.js.map +0 -1
  151. package/dist/daemon/client.d.ts +0 -20
  152. package/dist/daemon/client.js +0 -131
  153. package/dist/daemon/client.js.map +0 -1
  154. package/dist/daemon/control_protocol.d.ts +0 -176
  155. package/dist/daemon/control_protocol.js +0 -63
  156. package/dist/daemon/control_protocol.js.map +0 -1
  157. package/dist/daemon/cron_log.d.ts +0 -45
  158. package/dist/daemon/cron_log.js +0 -71
  159. package/dist/daemon/cron_log.js.map +0 -1
  160. package/dist/daemon/cron_registry.d.ts +0 -80
  161. package/dist/daemon/cron_registry.js +0 -198
  162. package/dist/daemon/cron_registry.js.map +0 -1
  163. package/dist/daemon/id.d.ts +0 -24
  164. package/dist/daemon/id.js +0 -36
  165. package/dist/daemon/id.js.map +0 -1
  166. package/dist/daemon/registry.d.ts +0 -63
  167. package/dist/daemon/registry.js +0 -153
  168. package/dist/daemon/registry.js.map +0 -1
  169. package/dist/daemon/rpc_child.d.ts +0 -194
  170. package/dist/daemon/rpc_child.js +0 -419
  171. package/dist/daemon/rpc_child.js.map +0 -1
  172. package/dist/daemon/supervisor.d.ts +0 -93
  173. package/dist/daemon/supervisor.js +0 -666
  174. package/dist/daemon/supervisor.js.map +0 -1
  175. /package/dist/bin/{supervisord.d.ts → launcher.d.ts} +0 -0
package/dist/index.d.ts CHANGED
@@ -31,84 +31,11 @@
31
31
  */
32
32
  import type { ExtensionContext, ExtensionFactory } from "@earendil-works/pi-coding-agent";
33
33
  import type { ClientMessage } from "./protocol/types.js";
34
- import { PlainPeerChannel } from "./transport/peer_channel.js";
34
+ import type { PlainPeerChannel } from "./transport/peer_channel.js";
35
+ import { CTRL_PREFIX, type RelayConnectivity } from "./session/relay_lifecycle.js";
36
+ export { CTRL_PREFIX };
37
+ export type { RelayConnectivity };
35
38
  export type RemoteState = "idle" | "started";
36
- /** Relay connectivity as seen by an RPC client (Cockpit). Derived from
37
- * `_state` + `_relay`: "disconnected" = relay off (idle); "connected" = live
38
- * WS; "reconnecting" = was on, WS dropped, retrying. Surfaced via the
39
- * `un-bien:relay-state` custom message (see `_emitRelayState`). */
40
- export type RelayConnectivity = "connected" | "reconnecting" | "disconnected";
41
- /** Sentinel prefix for a transparent control message an RPC client sends on the
42
- * `prompt` channel (stdin). The `input` hook intercepts it, runs the action,
43
- * and swallows it (`action:"handled"`) so it never becomes an LLM turn or a
44
- * transcript entry. Starts with NUL so it can't collide with real user input
45
- * and doesn't begin with "/" (which would route to the command parser). */
46
- export declare const CTRL_PREFIX = "\0un-bien-ctrl:";
47
- type MeshEnvelope = {
48
- id: string;
49
- from: string;
50
- re: string | null;
51
- body: unknown;
52
- };
53
- /** Test-only override of the message buffer. */
54
- /**
55
- * Test-only: emulate what `/unbien` does on the returning-user path
56
- * (join the local mesh, then start the relay) without touching the FS for
57
- * a `localConfigExists()` lookup. Lets tests bring the relay up without
58
- * mocking the wizard or the local config storage.
59
- *
60
- * Typed loosely to accept any ctx shape with `ui.notify` + `cwd` — the
61
- * unit tests use minimal mocks that don't satisfy the full
62
- * `ExtensionContext` interface.
63
- */
64
- export declare function _connectForTest(ctx: unknown): Promise<void>;
65
- /** Test-only: tear everything down (mirrors `/unbien stop`). */
66
- export declare function _stopForTest(ctx: unknown): Promise<void>;
67
- /** Test-only: read/reset the `_disposed` flag. Production clears it only when
68
- * a host reuses this module for a replacement session; tests share one module
69
- * across cases, so they also reset it to avoid cross-test pollution. */
70
- export declare function _getDisposedForTest(): boolean;
71
- export declare function _setDisposedForTest(v: boolean): void;
72
- /** Test-only: reset the once-per-session auto-init gate so session_start re-runs it. */
73
- export declare function _resetAutoInitedForTest(): void;
74
- /** Test-only: clear the globalThis panel/ui bridge ownership so each fresh
75
- * `extension(pi)` in a shared test process can (re)claim and rebuild bridges. */
76
- export declare function _resetBridgeOwnersForTest(): void;
77
- /** Test-only: reset the keyed per-session state at a TEST BOUNDARY (beforeEach).
78
- * Must NOT be folded into _resetBridgeOwnersForTest — that fires mid-test on
79
- * every captureEventHandler call and would wipe state a test seeds across two
80
- * captures (e.g. input seeds turnId, message_update reads it). */
81
- export declare function _resetSessionsForTest(): void;
82
- /** Test-only: set the auto-init gate for lifecycle replacement tests. */
83
- export declare function _setAutoInitedForTest(value: boolean): void;
84
- /** Test-only: true when this instance holds a live local-mesh node. */
85
- export declare function _hasMeshNodeForTest(): boolean;
86
- /** Test-only: drive the current real SelfRevoke producer through one sweep. */
87
- export declare function _checkSelfRevokeForTest(): Promise<void>;
88
- /** Test-only: the effective (possibly `#N`-suffixed) name the cwd-lock reserved. */
89
- export declare function _getLockedNameForTest(): string | null;
90
- /** Test-only: release + clear the cwd lock (the lock normally survives stop). */
91
- export declare function _resetCwdLockForTest(): void;
92
- /**
93
- * Test-only: relay-only startup, no UDS mesh join. Replaces the old
94
- * `unbien relay start` handler that some tests captured to bring up
95
- * the relay in isolation (e.g. ping/pong tests that don't care about the
96
- * agent-network broker).
97
- */
98
- export declare function _startRelayForTest(ctx: unknown): Promise<void>;
99
- /** Test-only: public marker for canceled-keypair cache regression checks. */
100
- export declare function _getCachedPublicKeyForTest(): string | null;
101
- /** Test-only override of session started timestamp. */
102
- export declare function _setSessionStartedAtForTest(ts: number | null): void;
103
- /** Test-only: reset the cached model name (between tests). */
104
- export declare function _setCurrentModelForTest(name: string | undefined): void;
105
- /** Test-only: read the active turn id used for plain `cancel` routing. */
106
- export declare function _getCurrentTurnIdForTest(): string | null;
107
- /** Test-only: override the bound AgentSession so a spy can capture the
108
- * content handed to `sendUserMessage` (plan/30 multimodal ingest). */
109
- export declare function _setPiForTest(pi: unknown): void;
110
- /** Test-only: exposes pending reconnect timer state. */
111
- export declare function _hasPendingReconnect(): boolean;
112
39
  /**
113
40
  * Public state-snapshot helper. Returns the derived UX state, not the raw
114
41
  * `_state` enum: the W2D refactor collapsed the internal machine to
@@ -117,37 +44,38 @@ export declare function _hasPendingReconnect(): boolean;
117
44
  * mental model via this getter.
118
45
  */
119
46
  export declare function _getState(): "idle" | "started" | "paired";
120
- /** Test-only: number of owners currently attached via PlainPeerChannel. */
121
- export declare function _getActivePeerCountForTest(): number;
122
- /** Test-only: true if a specific peer (base64 std) has an attached channel. */
123
- export declare function _hasActivePeerForTest(appPeerIdStd: string): boolean;
124
- /**
125
- * Handle a transparent control command from an RPC client (Cockpit), received
126
- * as a `CTRL_PREFIX`-tagged input the `input` hook swallowed. Toggles the relay
127
- * WITHOUT leaving the local mesh (relay-only: `_cmdStart` up / `_goIdle` down),
128
- * then emits the fresh state. `relay:status` just re-emits (no change) so the
129
- * client can sync its button after (re)attaching to the RPC stream.
130
- */
131
47
  export declare function _handleControl(cmd: string): Promise<void>;
132
- /**
133
- * Per-owner disconnect callback. Fires when one specific owner's channel
134
- * detaches (e.g. relay told us the peer is gone). Other owners' channels
135
- * keep running — relay stays "started".
136
- *
137
- * Exported so tests can trigger the disconnect path for a specific peer.
138
- *
139
- * Backward-compat: a no-arg call (legacy tests / pre-W2D callers) falls
140
- * back to detaching the most recently attached peer, mirroring the old
141
- * singleton semantics.
142
- */
143
48
  export declare function _onPeerDisconnect(appPeerId?: string): void;
144
- /** Build the argv for a detached tmux launch of `pi` in `cwd`. Args are an
145
- * ARRAY (never a shell string) so cwd/name can't inject. Exported for tests. */
146
- export declare function _buildTmuxLaunchArgs(name: string, cwd: string): string[];
49
+ export declare const _connectForTest: (ctx: unknown) => Promise<void>;
50
+ export declare const _stopForTest: (ctx: unknown) => Promise<void>;
51
+ export declare const _getDisposedForTest: () => boolean;
52
+ export declare const _setDisposedForTest: (v: boolean) => void;
53
+ export declare const _resetAutoInitedForTest: () => void;
54
+ export declare const _resetBridgeOwnersForTest: () => void;
55
+ export declare const _resetSessionsForTest: () => void;
56
+ export declare const _seedRootSessionForTest: (sid?: string) => void;
57
+ export declare const _setAutoInitedForTest: (value: boolean) => void;
58
+ export declare const _hasMeshNodeForTest: () => boolean;
59
+ export declare const _checkSelfRevokeForTest: () => Promise<void>;
60
+ export declare const _getLockedNameForTest: () => string | null;
61
+ export declare const _resetCwdLockForTest: () => void;
62
+ export declare const _startRelayForTest: (ctx: unknown) => Promise<void>;
63
+ export declare const _getCachedPublicKeyForTest: () => string | null;
64
+ export declare const _setSessionStartedAtForTest: (ts: number | null) => void;
65
+ export declare const _setCurrentModelForTest: (name: string | undefined) => void;
66
+ export declare const _getCurrentTurnIdForTest: () => string | null;
67
+ export declare const _setPiForTest: (pi: unknown) => void;
68
+ export declare const _hasPendingReconnect: () => boolean;
69
+ export declare const _getActivePeerCountForTest: () => number;
70
+ export declare const _hasActivePeerForTest: (appPeerIdStd: string) => boolean;
71
+ export declare const _deliverMeshMessageToAgentForTest: (env: {
72
+ id: string;
73
+ from: string;
74
+ re: string | null;
75
+ body: unknown;
76
+ }) => void;
147
77
  declare const extension: ExtensionFactory;
148
78
  export default extension;
149
- /** Test-only entry point for verifying mesh-to-agent delivery semantics. */
150
- export declare function _deliverMeshMessageToAgentForTest(env: MeshEnvelope): void;
151
79
  export declare function _routeClientMessageFrom(sender: PlainPeerChannel, msg: ClientMessage, ctx: Pick<ExtensionContext, "abort">): void;
152
80
  /**
153
81
  * Backward-compatible shim for legacy callers + tests that didn't track
@@ -155,29 +83,6 @@ export declare function _routeClientMessageFrom(sender: PlainPeerChannel, msg: C
155
83
  * mirroring the pre-W2D singleton behavior.
156
84
  */
157
85
  export declare function routeClientMessage(msg: ClientMessage, ctx: Pick<ExtensionContext, "abort">): void;
158
- type ToolArgs = Record<string, unknown>;
159
- export declare function _enrichToolArgs(tool: string, args: unknown): ToolArgs;
160
- /**
161
- * `unbien restart-supervisor` — restarts the `pi-supervisord` PROCESS
162
- * (not the daemons). The supervisor is a long-running Node process with no
163
- * hot-reload, so after a `dist` rebuild the old code keeps running until the
164
- * process is restarted. The Cockpit "Restart supervisor" button shells out to
165
- * this; the OS-specific restart lives here so the app stays cross-platform.
166
- *
167
- * Restarting the supervisor re-spawns every daemon as a side effect. Exits 0
168
- * on success, non-zero on failure (the Cockpit detects failure by exit code).
169
- */
170
- /** One step of a restart sequence. `ignoreFailure` steps (e.g. `schtasks /End`
171
- * when the task isn't running) don't abort the sequence. */
172
- export interface RestartStep {
173
- cmd: string;
174
- args: string[];
175
- ignoreFailure?: boolean;
176
- }
177
- /** Pure: the OS command sequence that restarts the supervisor service, or null
178
- * when the platform isn't supported. Most platforms are 1 step; Windows is 2
179
- * (`schtasks /End` then `/Run`). Exported for tests. */
180
- export declare function _restartSupervisorCommand(platform: NodeJS.Platform, uid: number): RestartStep[] | null;
181
86
  /**
182
87
  * Read-only probe of the local UDS broker for the mesh roster, backing
183
88
  * `unbien peers`. Opens a raw connection to `sockPath`, sends a single