@byok-sdk/client 0.13.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 (39) hide show
  1. package/README.md +80 -0
  2. package/dist/adapters/claude/process-client.d.ts +24 -0
  3. package/dist/adapters/codex/process-runner.d.ts +46 -1
  4. package/dist/adapters/index.js +359 -28
  5. package/dist/adapters/index.js.map +1 -1
  6. package/dist/adapters/pi/events.d.ts +1 -1
  7. package/dist/adapters/pi/rpc-client.d.ts +47 -1
  8. package/dist/adapters/pi/subagents-policy-extension.js +1 -1
  9. package/dist/adapters/pi/subagents-policy-extension.js.map +1 -1
  10. package/dist/adapters/pi/team-interaction-extension.d.ts +24 -0
  11. package/dist/adapters/pi/team-interaction-extension.js +81 -0
  12. package/dist/adapters/pi/team-interaction-extension.js.map +1 -0
  13. package/dist/adapters/process-tree.d.ts +74 -4
  14. package/dist/adapters/provider-credential-environment.d.ts +1 -1
  15. package/dist/adapters/win32-job-object.d.ts +101 -0
  16. package/dist/bin/byok-agent-memory-mcp.js.map +1 -1
  17. package/dist/bin/byok-agent-message-mcp.js.map +1 -1
  18. package/dist/bin/byok-agent-team-mcp.js.map +1 -1
  19. package/dist/bin/byok-agent.js +9305 -7988
  20. package/dist/bin/byok-agent.js.map +1 -1
  21. package/dist/bin/byok-approval-mcp.js.map +1 -1
  22. package/dist/bin/commands/team-pi-relay.d.ts +24 -0
  23. package/dist/bin/commands/team-relay.d.ts +11 -0
  24. package/dist/bin/team-codex-relay.d.ts +32 -0
  25. package/dist/bin/team-notification-relay.d.ts +40 -0
  26. package/dist/bin/team-pi-session.d.ts +59 -0
  27. package/dist/daemon/agent-egress-policy.d.ts +8 -0
  28. package/dist/daemon/connection-manager.d.ts +6 -100
  29. package/dist/daemon/control-protocol.d.ts +2 -0
  30. package/dist/daemon/create-daemon.d.ts +32 -0
  31. package/dist/daemon/event-spill.d.ts +90 -0
  32. package/dist/daemon/journal/journal.d.ts +15 -3
  33. package/dist/daemon/journal/sqlite-journal.d.ts +7 -2
  34. package/dist/daemon/long-poll-transport.d.ts +2 -50
  35. package/dist/daemon/task-runner.d.ts +13 -0
  36. package/dist/daemon/team-workspace.d.ts +9 -0
  37. package/dist/index.js +897 -241
  38. package/dist/index.js.map +1 -1
  39. package/package.json +8 -5
package/README.md CHANGED
@@ -354,4 +354,84 @@ plain watcher. Native Windows returns `unsupported_platform` for the tmux view.
354
354
  The launcher never uses `send-keys` or `capture-pane`; tmux displays the
355
355
  daemon-owned stream but is never message transport or protocol authority.
356
356
 
357
+ ### Automatic notification for two existing Codex sessions
358
+
359
+ Configure two operator-owned Codex app-server sessions with their respective
360
+ `team join` MCP grants. Record each exact native thread UUID and local endpoint.
361
+ The relay does not create sessions or verify your member-to-session mapping.
362
+ Write an absolute-path JSON file with mode `0600` (its contexts are bearer secrets):
363
+
364
+ ```json
365
+ {"version":1,"bindings":[
366
+ {"context":"<member-a-context>","threadId":"<native-thread-a-uuid>","endpoint":"ws://127.0.0.1:9101","afterSeq":0},
367
+ {"context":"<member-b-context>","threadId":"<native-thread-b-uuid>","endpoint":"ws://127.0.0.1:9102","afterSeq":0}
368
+ ]}
369
+ ```
370
+
371
+ ```bash
372
+ byok-agent team relay dev --bindings /absolute/private-bindings.json --codex-bin /absolute/codex --max-notifications 2 --config /absolute/agent.json
373
+ ```
374
+
375
+ POSIX only; the executable must report `codex-cli 0.153.4`, the qualified native
376
+ queue version. Endpoints must be explicit loopback `ws://127.0.0.1:<port>` /
377
+ `ws://[::1]:<port>` or `unix:///absolute/socket`. No remote server discovery. Loopback app-server queue endpoints trust local
378
+ processes; the relay does not add authentication to the native Codex endpoint.
379
+ Keep the foreground command open and enter `pause`, `resume`, `status`, or `stop`;
380
+ SIGINT/SIGTERM also stop. Output includes queue attempts/receipts and redacted
381
+ state. A successful queue receipt means accepted notification, not completed work.
382
+ The model reads, replies and acknowledges with the existing Team MCP tools.
383
+
384
+ The required budget counts every attempt, capped at 100. Unknown delivery,
385
+ revoked/expired grant or control failure stops without retry. An operator stop
386
+ during enqueue can report `stopped` with `queue_delivery_unknown`: aborting the
387
+ local queue process cannot prove the native server rejected the notification. Pause does not undo
388
+ queued work. A room lock rejects concurrent relays; inspect the recorded owner
389
+ before manually removing a stale `<storeDir>/team-relay-locks/<room>.lock`.
390
+ Watermarks are process-local. On restart choose `afterSeq` explicitly from prior
391
+ status and actual room receipts; do not assume automatic crash replay, exactly-once
392
+ or guaranteed at-least-once delivery. Renewing grants requires explicitly updating
393
+ both the session MCP grant and binding file. tmux remains an optional view.
394
+
395
+ ### Codex + Pi through a GUI host
396
+
397
+ `team pi-relay` owns a fresh Pi **0.85.1** RPC child alongside your existing Codex
398
+ session. Prepare a private `0600` absolute-path binding document:
399
+
400
+ ```json
401
+ {"version":1,"codex":{"context":"<codex-grant>","threadId":"<uuid>","endpoint":"ws://127.0.0.1:9101","afterSeq":0},"pi":{"context":"<pi-grant>","afterSeq":0,"cwd":"/absolute/workspace","sessionDir":"/absolute/new-session-dir","provider":"<provider>","model":"<model>","systemPrompt":"<explicit instructions>","extensionPaths":[]}}
402
+ ```
403
+
404
+ The session directory must not exist; its parent must exist. The SDK supplies the
405
+ Pi Team MCP tools and guard extension. Additional absolute extension paths are
406
+ operator-trusted code, loaded after the guard. Ambient extension loading is off.
407
+
408
+ ```bash
409
+ byok-agent team pi-relay dev --bindings /absolute/private.json --codex-bin /absolute/codex --max-notifications 2 --config /absolute/agent.json
410
+ ```
411
+
412
+ Connect a GUI backend to stdin/stdout JSONL. This command provides the interface;
413
+ it does not include a GUI app. Keep stdin open while the session runs.
414
+
415
+ ```json
416
+ {"command":"status"}
417
+ {"command":"pause"}
418
+ {"command":"resume"}
419
+ {"command":"input","sessionId":"<pi_ready sessionId>","message":"<operator input>"}
420
+ {"command":"respond","sessionId":"<ui_request sessionId>","requestId":"<request.id>","response":{"cancelled":true}}
421
+ {"command":"stop"}
422
+ ```
423
+
424
+ For confirm, use `{"confirmed":true}` or `false`; for select/input/editor, use
425
+ `{"value":"..."}`. Exactly one response field is accepted. Wrong session, stale ID,
426
+ duplicate answer or mismatched shape is rejected. `ui_response_sent` confirms pipe
427
+ write only: Pi may have expired that ID. Expiry leaves the GUI item pending until
428
+ you explicitly dismiss it. Render `ui_request.request` as untrusted display data.
429
+
430
+ The first-loaded native guard holds input/provider admission during Pi UI spans.
431
+ `pi_gate` reports that state; `pi_settled` reports completed native work. Busy Pi
432
+ waits for readiness. A 30-second unresolved RPC stops the owned process, without
433
+ retry. Budget exhaustion drains accepted Pi work for up to 120 seconds; explicit
434
+ stop or stdin EOF terminates it. Neither pause nor a new dialog recalls already
435
+ admitted work. Runtime/grants remain separate from the native Codex session.
436
+
357
437
  MIT licensed. Node.js 22.22.0 or newer.
@@ -7,6 +7,17 @@ export interface ClaudeProcessClientOptions {
7
7
  cwd: string;
8
8
  env: NodeJS.ProcessEnv;
9
9
  spawnFn?: SpawnFn;
10
+ /**
11
+ * DI seam scoped to ADOPTION only (`../process-tree.ts`'s
12
+ * `adoptOwnedProcessTree`), so the win32 job-object branch is exercisable
13
+ * from POSIX. Disposal keeps `process.platform` as its own authority — this
14
+ * must never silently reroute the taskkill sweep on a real host.
15
+ */
16
+ platform?: NodeJS.Platform;
17
+ /** DI seam for the win32 job-object backstop; see `../win32-job-object.ts`. */
18
+ jobObject?: {
19
+ assign(pid: number): Promise<void>;
20
+ };
10
21
  }
11
22
  /**
12
23
  * NDJSON process transport for `claude -p --input-format stream-json
@@ -55,6 +66,10 @@ export declare class ClaudeProcessClient {
55
66
  private readonly closedPromise;
56
67
  private resolveClosed;
57
68
  private disposalAttempt;
69
+ /** Resolves once this tree is backstopped (see `adoptOwnedProcessTree`); rejects with the adoption failure, having already terminated the tree. */
70
+ private readonly adopted;
71
+ /** Set before the fail-closed termination starts, so it — not the exit code of the kill we ourselves requested — becomes this client's exit error. */
72
+ private adoptionFailure;
58
73
  private readonly stderrRing;
59
74
  private readonly unmappedFrameCounts;
60
75
  private sessionId;
@@ -108,6 +123,15 @@ export declare class ClaudeProcessClient {
108
123
  waitClosed(): Promise<void>;
109
124
  dispose(): Promise<void>;
110
125
  private processTreeOptions;
126
+ /**
127
+ * Backstop this tree, or tear it down. Adoption failure is a start-time
128
+ * precondition, not a degraded mode: the child is terminated through the one
129
+ * disposal authority and the failure is re-thrown, which is what makes
130
+ * `waitForInit()` — and therefore `ClaudeAdapter.start()` — fail before any
131
+ * session is published. Both cleanup attempts are best-effort because the
132
+ * adoption failure, not a terminator's own complaint, is the reason to report.
133
+ */
134
+ private adoptOwnedTree;
111
135
  private onData;
112
136
  private onLine;
113
137
  private onStderr;
@@ -19,6 +19,17 @@ export interface CodexProcessOptions {
19
19
  spawnFn?: SpawnFn;
20
20
  /** Called once per parsed JSONL line, in arrival order. */
21
21
  onEvent: (evt: CodexRawEvent) => void;
22
+ /**
23
+ * DI seam scoped to ADOPTION only (`../process-tree.ts`'s
24
+ * `adoptOwnedProcessTree`), so the win32 job-object branch is exercisable
25
+ * from POSIX. Disposal keeps `process.platform` as its own authority — this
26
+ * must never silently reroute the taskkill sweep on a real host.
27
+ */
28
+ platform?: NodeJS.Platform;
29
+ /** DI seam for the win32 job-object backstop; see `../win32-job-object.ts`. */
30
+ jobObject?: {
31
+ assign(pid: number): Promise<void>;
32
+ };
22
33
  }
23
34
  /**
24
35
  * Spawns and streams ONE `codex exec` / `codex exec resume` invocation — i.e.
@@ -60,6 +71,19 @@ export declare class CodexProcessRunner {
60
71
  private readonly closedPromise;
61
72
  private resolveClosed;
62
73
  private disposalAttempt;
74
+ /** Resolves once this tree is backstopped (see `adoptOwnedProcessTree`); rejects with the adoption failure, having already terminated the tree. */
75
+ private readonly adopted;
76
+ /** Set before the fail-closed termination starts; `buildExitError` reports it instead of the exit status of the kill we ourselves requested. */
77
+ private adoptionFailure;
78
+ private adoption;
79
+ /**
80
+ * Lines parsed before adoption settled. Unlike pi and claude, this runner has
81
+ * no first awaited operation of its own to gate on — its caller reads the
82
+ * FIRST event as the authoritative thread id. Holding events until the tree
83
+ * is backstopped is what keeps that caller from publishing a session for a
84
+ * tree the job object never took.
85
+ */
86
+ private readonly deferredEvents;
63
87
  constructor(options: CodexProcessOptions);
64
88
  private finishClosing;
65
89
  /** Resolves once the child process has fully exited (both exit and stdio-flush guaranteed — see the `close` listener above). Never rejects. */
@@ -86,7 +110,28 @@ export declare class CodexProcessRunner {
86
110
  kill(): void;
87
111
  dispose(): Promise<void>;
88
112
  private processTreeOptions;
89
- /** Builds a descriptive error folding in the exit code/signal and the stderr tail — mirrors `PiRpcClient.buildExitError`'s reasoning: a post-mortem on a failed start/resume should never need separately re-running codex by hand with a raw JSONL logger to learn why. */
113
+ /**
114
+ * Backstop this tree, or tear it down. Adoption failure is a start-time
115
+ * precondition, not a degraded mode: the child is terminated through the one
116
+ * disposal authority, every parsed line is dropped instead of delivered, and
117
+ * the resulting close makes the caller's own `waitClosed()` race reject with
118
+ * the adoption failure (`buildExitError`) before a thread id is published.
119
+ * Both cleanup attempts are best-effort because the adoption failure, not a
120
+ * terminator's own complaint, is the reason to report.
121
+ */
122
+ private adoptOwnedTree;
123
+ /** Arrival-order delivery, held back until the tree is backstopped (see `deferredEvents`). */
124
+ private deliver;
125
+ /**
126
+ * Builds a descriptive error folding in the exit code/signal and the stderr
127
+ * tail — mirrors `PiRpcClient.buildExitError`'s reasoning: a post-mortem on a
128
+ * failed start/resume should never need separately re-running codex by hand
129
+ * with a raw JSONL logger to learn why.
130
+ *
131
+ * A tree this runner could not backstop is the one exception: that process
132
+ * exited because THIS runner killed it, so `exit code=null, signal=SIGKILL`
133
+ * plus an empty stderr tail would bury the only reason anyone can act on.
134
+ */
90
135
  buildExitError(context: string): Error;
91
136
  private onData;
92
137
  private parseLine;