@zergai/ztc 0.19.0-beta.1 → 0.20.0-beta.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 (196) hide show
  1. package/README.md +222 -6
  2. package/bin/zmux-darwin-arm64 +0 -0
  3. package/bin/ztc-audio-darwin-arm64 +0 -0
  4. package/bin/ztc-capture-darwin-arm64 +0 -0
  5. package/bin/ztc-tui-darwin-arm64 +0 -0
  6. package/bin/zterm-darwin-arm64 +2 -2
  7. package/dist/agent/agent.d.ts +17 -0
  8. package/dist/agent/agent.js +77 -4
  9. package/dist/agent/backends/index.js +5 -3
  10. package/dist/agent/backends/zrouter_stream.js +8 -4
  11. package/dist/agent/commands/goal.d.ts +2 -0
  12. package/dist/agent/commands/goal.js +7 -2
  13. package/dist/agent/factory.d.ts +2 -0
  14. package/dist/agent/factory.js +1 -0
  15. package/dist/agent/request_encoder.d.ts +2 -1
  16. package/dist/agent/request_encoder.js +4 -3
  17. package/dist/agent/runtime/policy.d.ts +1 -0
  18. package/dist/agent/runtime/policy.js +23 -3
  19. package/dist/agent/runtime/tool_runtime.js +13 -12
  20. package/dist/agent/subagent.js +2 -1
  21. package/dist/agent/tools/ask_user.d.ts +1 -1
  22. package/dist/agent/tools/ask_user.js +15 -8
  23. package/dist/agent/tools/pane.d.ts +6 -0
  24. package/dist/agent/tools/pane.js +18 -4
  25. package/dist/agent/tools/search.js +1 -1
  26. package/dist/agent/tools/sim_domain_tools.d.ts +4 -0
  27. package/dist/agent/tools/sim_domain_tools.js +28 -2
  28. package/dist/agent/tools/types.d.ts +3 -0
  29. package/dist/app/correlated_turn.d.ts +14 -0
  30. package/dist/app/correlated_turn.js +78 -0
  31. package/dist/app/prompt_turn.d.ts +2 -1
  32. package/dist/app/prompt_turn.js +15 -2
  33. package/dist/app/session_manager.d.ts +17 -11
  34. package/dist/app/session_manager.js +74 -30
  35. package/dist/app/tool_callbacks.d.ts +1 -1
  36. package/dist/app/workspace_layout_controller.d.ts +21 -2
  37. package/dist/app/workspace_layout_controller.js +61 -10
  38. package/dist/app/workspace_monitor.js +67 -7
  39. package/dist/app/workspace_presets.d.ts +1 -0
  40. package/dist/app/workspace_presets.js +2 -2
  41. package/dist/cli.js +6 -2
  42. package/dist/cli_args.js +1 -0
  43. package/dist/cli_main.js +48 -2
  44. package/dist/cli_ratatui.d.ts +56 -8
  45. package/dist/cli_ratatui.js +689 -109
  46. package/dist/config/permissions.js +1 -1
  47. package/dist/config/router_required.d.ts +11 -0
  48. package/dist/config/router_required.js +23 -0
  49. package/dist/config/types.d.ts +5 -0
  50. package/dist/config.d.ts +3 -1
  51. package/dist/config.js +66 -49
  52. package/dist/desktop/daily/broker.d.ts +26 -0
  53. package/dist/desktop/daily/broker.js +140 -0
  54. package/dist/desktop/daily/codex_config.d.ts +2 -0
  55. package/dist/desktop/daily/codex_config.js +119 -0
  56. package/dist/desktop/daily/codex_exec_adapter.d.ts +42 -0
  57. package/dist/desktop/daily/codex_exec_adapter.js +251 -0
  58. package/dist/desktop/daily/control_client.d.ts +4 -0
  59. package/dist/desktop/daily/control_client.js +214 -0
  60. package/dist/desktop/daily/control_credentials.d.ts +15 -0
  61. package/dist/desktop/daily/control_credentials.js +85 -0
  62. package/dist/desktop/daily/control_hello.d.ts +10 -0
  63. package/dist/desktop/daily/control_hello.js +6 -0
  64. package/dist/desktop/daily/control_protocol.d.ts +39 -0
  65. package/dist/desktop/daily/control_protocol.js +4 -0
  66. package/dist/desktop/daily/control_schema.d.ts +9 -0
  67. package/dist/desktop/daily/control_schema.js +25 -0
  68. package/dist/desktop/daily/control_server.d.ts +44 -0
  69. package/dist/desktop/daily/control_server.js +286 -0
  70. package/dist/desktop/daily/daily_store.d.ts +71 -0
  71. package/dist/desktop/daily/daily_store.js +290 -0
  72. package/dist/desktop/daily/delegated_ztc_contract.d.ts +37 -0
  73. package/dist/desktop/daily/delegated_ztc_contract.js +90 -0
  74. package/dist/desktop/daily/desktop_wiring.d.ts +112 -0
  75. package/dist/desktop/daily/desktop_wiring.js +1048 -0
  76. package/dist/desktop/daily/enrollment.d.ts +74 -0
  77. package/dist/desktop/daily/enrollment.js +77 -0
  78. package/dist/desktop/daily/file_facts.d.ts +2 -0
  79. package/dist/desktop/daily/file_facts.js +41 -0
  80. package/dist/desktop/daily/lease.d.ts +57 -0
  81. package/dist/desktop/daily/lease.js +332 -0
  82. package/dist/desktop/daily/legacy_codex_homes.d.ts +1 -0
  83. package/dist/desktop/daily/legacy_codex_homes.js +26 -0
  84. package/dist/desktop/daily/native_pane_launcher.d.ts +31 -0
  85. package/dist/desktop/daily/native_pane_launcher.js +226 -0
  86. package/dist/desktop/daily/native_records.d.ts +13 -0
  87. package/dist/desktop/daily/native_records.js +81 -0
  88. package/dist/desktop/daily/native_status.d.ts +4 -0
  89. package/dist/desktop/daily/native_status.js +28 -0
  90. package/dist/desktop/daily/native_tool.d.ts +134 -0
  91. package/dist/desktop/daily/native_tool.js +91 -0
  92. package/dist/desktop/daily/owner_files.d.ts +3 -0
  93. package/dist/desktop/daily/owner_files.js +88 -0
  94. package/dist/desktop/daily/owner_seals.d.ts +9 -0
  95. package/dist/desktop/daily/owner_seals.js +56 -0
  96. package/dist/desktop/daily/process_identity.d.ts +13 -0
  97. package/dist/desktop/daily/process_identity.js +137 -0
  98. package/dist/desktop/daily/profile_bootstrap.d.ts +60 -0
  99. package/dist/desktop/daily/profile_bootstrap.js +194 -0
  100. package/dist/desktop/daily/raw_receipts.d.ts +1 -0
  101. package/dist/desktop/daily/raw_receipts.js +18 -0
  102. package/dist/desktop/daily/recipes.d.ts +36 -0
  103. package/dist/desktop/daily/recipes.js +177 -0
  104. package/dist/desktop/daily/router_state.d.ts +33 -0
  105. package/dist/desktop/daily/router_state.js +39 -0
  106. package/dist/desktop/daily/schema_registry.d.ts +19 -0
  107. package/dist/desktop/daily/schema_registry.js +71 -0
  108. package/dist/desktop/daily/source_baseline.d.ts +13 -0
  109. package/dist/desktop/daily/source_baseline.js +44 -0
  110. package/dist/desktop/daily/status_restore.d.ts +9 -0
  111. package/dist/desktop/daily/status_restore.js +114 -0
  112. package/dist/desktop/daily/summary.d.ts +59 -0
  113. package/dist/desktop/daily/summary.js +75 -0
  114. package/dist/desktop/daily/worker_provenance.d.ts +2 -0
  115. package/dist/desktop/daily/worker_provenance.js +18 -0
  116. package/dist/desktop/daily/worker_stop.d.ts +2 -0
  117. package/dist/desktop/daily/worker_stop.js +26 -0
  118. package/dist/desktop/daily/ztc_headless_adapter.d.ts +40 -0
  119. package/dist/desktop/daily/ztc_headless_adapter.js +194 -0
  120. package/dist/domain.d.ts +1 -1
  121. package/dist/domain.js +1 -1
  122. package/dist/events.d.ts +23 -1
  123. package/dist/headless.d.ts +9 -0
  124. package/dist/headless.js +161 -26
  125. package/dist/headless_approval.d.ts +29 -0
  126. package/dist/headless_approval.js +69 -0
  127. package/dist/headless_cli.js +2 -0
  128. package/dist/headless_cli_args.d.ts +4 -0
  129. package/dist/headless_cli_args.js +5 -0
  130. package/dist/library.d.ts +20 -0
  131. package/dist/library.js +66 -12
  132. package/dist/mcp/client.d.ts +16 -1
  133. package/dist/mcp/client.js +11 -5
  134. package/dist/mcp/registry.d.ts +3 -1
  135. package/dist/mcp/registry.js +10 -1
  136. package/dist/panes/pane_registry.js +14 -3
  137. package/dist/panes/types.d.ts +7 -1
  138. package/dist/panes/ztc_launch.d.ts +5 -0
  139. package/dist/panes/ztc_launch.js +30 -14
  140. package/dist/session.d.ts +6 -3
  141. package/dist/session.js +21 -2
  142. package/dist/simulation/domain_types.d.ts +2 -0
  143. package/dist/simulation/domains/loader.d.ts +7 -1
  144. package/dist/simulation/domains/loader.js +33 -1
  145. package/dist/simulation/living/context.d.ts +19 -19
  146. package/dist/simulation/living/definition.d.ts +2 -2
  147. package/dist/simulation/living/frame.d.ts +1 -1
  148. package/dist/simulation/living/open-world.d.ts +3 -3
  149. package/dist/simulation/living/types.d.ts +24 -24
  150. package/dist/simulation/toolkit/dynamic_state.d.ts +1 -1
  151. package/dist/skills/bundled/init-context/SKILL.md +16 -0
  152. package/dist/skills/registry.js +7 -3
  153. package/dist/tools.d.ts +6 -0
  154. package/dist/tools.js +14 -0
  155. package/dist/types.d.ts +30 -0
  156. package/dist/ui/ratatui/mux_persistence.d.ts +3 -1
  157. package/dist/ui/ratatui/mux_persistence.js +9 -2
  158. package/dist/ui/ratatui/pane_credential_broker.d.ts +8 -4
  159. package/dist/ui/ratatui/pane_credential_broker.js +26 -11
  160. package/dist/ui/ratatui/pane_relay.d.ts +2 -0
  161. package/dist/ui/ratatui/process.d.ts +6 -0
  162. package/dist/ui/ratatui/process.js +104 -6
  163. package/dist/ui/ratatui/protocol.d.ts +13 -0
  164. package/dist/ui/ratatui/protocol.js +1 -0
  165. package/dist/utils/compaction.js +6 -4
  166. package/dist/utils/subprocess_env.js +2 -0
  167. package/dist/web/browser_events.d.ts +10 -0
  168. package/dist/web/browser_events.js +9 -0
  169. package/dist/web/mirror_stream.d.ts +17 -5
  170. package/dist/web/mirror_stream.js +105 -13
  171. package/dist/web/pane_credentials.d.ts +6 -3
  172. package/dist/web/pane_credentials.js +20 -12
  173. package/dist/web/pane_registry.js +1 -0
  174. package/dist/workspace_agent.d.ts +2 -1
  175. package/dist/workspace_agent.js +7 -1
  176. package/dist/workspace_collision.d.ts +3 -0
  177. package/dist/workspace_collision.js +1 -1
  178. package/dist/workspace_layout.d.ts +3 -2
  179. package/dist/workspace_layout.js +8 -2
  180. package/dist/workspace_runtime.d.ts +7 -1
  181. package/dist/workspace_runtime.js +3 -3
  182. package/dist/zerg/manifest_builder_tools.js +35 -4
  183. package/dist/zerg/manifest_validator.js +55 -0
  184. package/dist/zlm-embed.mjs +261 -116
  185. package/node_modules/@zerg/model-contracts/README.md +19 -0
  186. package/node_modules/@zerg/model-contracts/index.js +19 -1
  187. package/node_modules/@ztc/sim-graph/dist/index.d.ts +1 -0
  188. package/node_modules/@ztc/sim-graph/dist/index.js +1 -0
  189. package/node_modules/@ztc/sim-graph/dist/sim_graph.d.ts +351 -0
  190. package/node_modules/@ztc/sim-graph/dist/sim_graph.js +795 -0
  191. package/node_modules/@ztc/sim-graph/package.json +37 -0
  192. package/node_modules/@ztc/sim-graph/src/index.ts +1 -0
  193. package/node_modules/@ztc/sim-graph/src/sim_graph.ts +1305 -0
  194. package/package.json +25 -24
  195. package/packages/model-contracts/README.md +19 -0
  196. package/packages/model-contracts/index.js +19 -1
@@ -7,7 +7,8 @@
7
7
  * whose launcher asked for one, then gets a fresh credential from the mirror it will talk to: the one its owner's
8
8
  * command names or, when it names none, the one it inherits (see the constructor). A pane a pane opens through the
9
9
  * relay always talks to the mirror its transport's owner runs now (setOwnerMirrorPort), or the one it inherits while
10
- * its owner names none, whatever its command names. A ZTC pane and a workspace monitor are handed theirs in a one-time
10
+ * its owner names none, whatever its command names. A ZTC pane (a native ZTC pane, a process pane, by its launcher's
11
+ * ZTC_PANE_CREDENTIAL_REQUEST) and a workspace monitor are handed theirs in a one-time
11
12
  * owner-only file their command line names (PANE_CREDENTIAL_FILE_FLAG), since any program running as this user can read
12
13
  * the environment a pane's program starts with; a pane whose launcher asked for a plain one (a Claude Code or Codex
13
14
  * pane, whose CLI starts the workspace tools with its environment) gets it in its environment. The file is removed with
@@ -72,9 +73,11 @@ export declare class PaneCredentialBroker {
72
73
  /**
73
74
  * The replace_pane to send for CMD. A ZTC pane its owner has the renderer start again in place (a resumed agent
74
75
  * session) gets a fresh credential from the mirror it inherits, bound when pane_created reports it, as a new pane's
75
- * is. replace_pane carries no environment, so the credential goes in a one-time owner-only file whose path is
76
- * added to the command line (PANE_CREDENTIAL_FILE_FLAG); the ZTC deletes it as it starts, and the file is removed if
77
- * the pane never appears or closes first. A pane that asks the relay to replace a pane gets none for it.
76
+ * is; the desktop's Status, a workspace monitor its owner starts again in place to recover it (desktop_status), gets
77
+ * a fresh workspace monitor's credential from the mirror its owner runs now, which its command line names. replace_pane
78
+ * carries no environment, so the credential goes in a one-time owner-only file whose path is added to the command
79
+ * line (PANE_CREDENTIAL_FILE_FLAG); the program deletes it as it starts, and the file is removed if the pane never
80
+ * appears or closes first. A pane that asks the relay to replace a pane gets none for it.
78
81
  */
79
82
  prepareReplace(cmd: ReplacePane): ReplacePane;
80
83
  /**
@@ -93,6 +96,7 @@ export declare class PaneCredentialBroker {
93
96
  * for): revoke it.
94
97
  */
95
98
  created(paneId: number, requestId?: string): string | undefined;
99
+ failed(requestId?: string): string | undefined;
96
100
  /** The pane closed: its credential stops working, and a handoff its program never took is removed. */
97
101
  closed(paneId: number): void;
98
102
  /** The renderer is gone: every credential it was given stops working. */
@@ -7,7 +7,8 @@
7
7
  * whose launcher asked for one, then gets a fresh credential from the mirror it will talk to: the one its owner's
8
8
  * command names or, when it names none, the one it inherits (see the constructor). A pane a pane opens through the
9
9
  * relay always talks to the mirror its transport's owner runs now (setOwnerMirrorPort), or the one it inherits while
10
- * its owner names none, whatever its command names. A ZTC pane and a workspace monitor are handed theirs in a one-time
10
+ * its owner names none, whatever its command names. A ZTC pane (a native ZTC pane, a process pane, by its launcher's
11
+ * ZTC_PANE_CREDENTIAL_REQUEST) and a workspace monitor are handed theirs in a one-time
11
12
  * owner-only file their command line names (PANE_CREDENTIAL_FILE_FLAG), since any program running as this user can read
12
13
  * the environment a pane's program starts with; a pane whose launcher asked for a plain one (a Claude Code or Codex
13
14
  * pane, whose CLI starts the workspace tools with its environment) gets it in its environment. The file is removed with
@@ -24,7 +25,7 @@
24
25
  * credential from a file, which it deleted, starts again without it.)
25
26
  */
26
27
  import { randomUUID } from 'node:crypto';
27
- import { OWNER_MIRROR_CREDENTIAL_ENV, PANE_CREDENTIAL_ENV, PANE_CREDENTIAL_FILE_FLAG, WORKSPACE_MONITOR_CREDENTIAL_REQUEST, paneCredentialStoreForPort, removePaneCredentialHandoff, writePaneCredentialHandoff, } from '../../web/pane_credentials.js';
28
+ import { OWNER_MIRROR_CREDENTIAL_ENV, PANE_CREDENTIAL_ENV, PANE_CREDENTIAL_FILE_FLAG, WORKSPACE_MONITOR_CREDENTIAL_REQUEST, ZTC_PANE_CREDENTIAL_REQUEST, paneCredentialStoreForPort, removePaneCredentialHandoff, writePaneCredentialHandoff, } from '../../web/pane_credentials.js';
28
29
  /** How long an unbound credential waits for its pane_created (the store drops it then too). */
29
30
  const PENDING_BIND_MS = 30_000;
30
31
  const RELAYED = Symbol('ztc.paneRelayed');
@@ -94,9 +95,11 @@ export class PaneCredentialBroker {
94
95
  issue(cmd, paneId, paneType) {
95
96
  const env = { ...(cmd.env ?? {}) };
96
97
  const requested = env[PANE_CREDENTIAL_ENV];
98
+ // A ZTC, by its pane type or its launcher's word (a native ZTC pane runs as a process pane).
99
+ const ztc = isZtcPane(paneType) || requested === ZTC_PANE_CREDENTIAL_REQUEST;
97
100
  const scope = requested === WORKSPACE_MONITOR_CREDENTIAL_REQUEST && !isRelayed(cmd)
98
101
  ? 'workspace-monitor'
99
- : requested || isZtcPane(paneType) ? 'pane' : null;
102
+ : requested || ztc ? 'pane' : null;
100
103
  // A renderer merges a pane's environment over its own, so the names are cleared there. A transport that assigns
101
104
  // ids builds each pane's whole environment itself, without them (computePaneSpawnEnv), so they are left out.
102
105
  for (const name of OWNER_MIRROR_CREDENTIAL_ENV) {
@@ -117,7 +120,7 @@ export class PaneCredentialBroker {
117
120
  return { command: { ...cmd, env } };
118
121
  const credential = store.issue(scope, paneId);
119
122
  let handoff;
120
- if (scope === 'workspace-monitor' || isZtcPane(paneType)) {
123
+ if (scope === 'workspace-monitor' || ztc) {
121
124
  // Never in its environment, which any program running as this user can read: in a file only it is told of.
122
125
  try {
123
126
  handoff = writePaneCredentialHandoff(credential.token);
@@ -144,18 +147,22 @@ export class PaneCredentialBroker {
144
147
  /**
145
148
  * The replace_pane to send for CMD. A ZTC pane its owner has the renderer start again in place (a resumed agent
146
149
  * session) gets a fresh credential from the mirror it inherits, bound when pane_created reports it, as a new pane's
147
- * is. replace_pane carries no environment, so the credential goes in a one-time owner-only file whose path is
148
- * added to the command line (PANE_CREDENTIAL_FILE_FLAG); the ZTC deletes it as it starts, and the file is removed if
149
- * the pane never appears or closes first. A pane that asks the relay to replace a pane gets none for it.
150
+ * is; the desktop's Status, a workspace monitor its owner starts again in place to recover it (desktop_status), gets
151
+ * a fresh workspace monitor's credential from the mirror its owner runs now, which its command line names. replace_pane
152
+ * carries no environment, so the credential goes in a one-time owner-only file whose path is added to the command
153
+ * line (PANE_CREDENTIAL_FILE_FLAG); the program deletes it as it starts, and the file is removed if the pane never
154
+ * appears or closes first. A pane that asks the relay to replace a pane gets none for it.
150
155
  */
151
156
  prepareReplace(cmd) {
152
- if (!isZtcPane(cmd.pane_type) || isRelayed(cmd))
157
+ const status = cmd.desktop_status === true;
158
+ if (!(isZtcPane(cmd.pane_type) || status) || isRelayed(cmd))
153
159
  return cmd;
154
- // replace_pane carries no environment: the program talks to the mirror the renderer's own environment names.
155
- const store = paneCredentialStoreForPort(Number(this.inheritedMirrorPort()));
160
+ // replace_pane carries no environment: a ZTC talks to the mirror the renderer's own environment names.
161
+ const port = status ? this.ownerMirrorPort ?? Number(this.inheritedMirrorPort()) : Number(this.inheritedMirrorPort());
162
+ const store = paneCredentialStoreForPort(port);
156
163
  if (!store)
157
164
  return cmd;
158
- const credential = store.issue('pane');
165
+ const credential = store.issue(status ? 'workspace-monitor' : 'pane');
159
166
  let handoff;
160
167
  try {
161
168
  handoff = writePaneCredentialHandoff(credential.token);
@@ -195,6 +202,14 @@ export class PaneCredentialBroker {
195
202
  this.hold(paneId, waiting.held);
196
203
  return waiting.requestId;
197
204
  }
205
+ failed(requestId) {
206
+ const waiting = requestId === undefined ? undefined : this.pending.get(requestId);
207
+ if (!waiting)
208
+ return requestId;
209
+ this.pending.delete(requestId);
210
+ release(waiting.held);
211
+ return waiting.requestId;
212
+ }
198
213
  /** The pane closed: its credential stops working, and a handoff its program never took is removed. */
199
214
  closed(paneId) {
200
215
  const held = this.bound.get(paneId);
@@ -12,6 +12,8 @@
12
12
  import type { RustCommand, RustEvent } from './protocol.js';
13
13
  export type PaneEventHandler = (event: RustEvent) => void;
14
14
  export interface PaneCommandTransport {
15
+ isOnlyPendingPaneCreate?(requestId: string): boolean;
16
+ launcherParentPid?(): number | null;
15
17
  send(cmd: RustCommand): boolean;
16
18
  on(handler: PaneEventHandler): () => void;
17
19
  readonly isMuxMode: boolean;
@@ -85,6 +85,10 @@ export declare function isTransientSocketConnectError(code: string | undefined):
85
85
  */
86
86
  export declare class TuiProcess {
87
87
  private readonly options;
88
+ private readonly pendingPaneCreations;
89
+ private readonly timedOutPaneRequestIds;
90
+ isOnlyPendingPaneCreate(requestId: string): boolean;
91
+ launcherParentPid(): number | null;
88
92
  /** Host-selected unmanaged renderer; validated bundle admission takes precedence. */
89
93
  constructor(options?: {
90
94
  desktopBinaryPath?: string;
@@ -164,6 +168,8 @@ export declare class TuiProcess {
164
168
  * Emit an event to all handlers
165
169
  */
166
170
  private emit;
171
+ private dispatchPaneMutation;
172
+ private timeoutPaneMutation;
167
173
  /** Whether zmux (multiplexer mode) is active */
168
174
  get isMuxMode(): boolean;
169
175
  hasCapability(name: string): boolean;
@@ -9,6 +9,7 @@
9
9
  * a fullscreen multiplexer with split panes (alternate screen mode).
10
10
  */
11
11
  import { spawn } from 'child_process';
12
+ import { randomUUID } from 'node:crypto';
12
13
  import { existsSync, unlinkSync } from 'fs';
13
14
  import { createInterface } from 'readline';
14
15
  import { join, dirname, resolve } from 'path';
@@ -330,6 +331,13 @@ export function isTransientSocketConnectError(code) {
330
331
  */
331
332
  export class TuiProcess {
332
333
  options;
334
+ pendingPaneCreations = new Set();
335
+ timedOutPaneRequestIds = new Set();
336
+ isOnlyPendingPaneCreate(requestId) {
337
+ const pending = [...this.pendingPaneCreations].find(item => item.dispatched);
338
+ return pending?.command.type === 'create_pane' && pending.requestId === requestId;
339
+ }
340
+ launcherParentPid() { return this.process?.pid ?? null; }
333
341
  /** Host-selected unmanaged renderer; validated bundle admission takes precedence. */
334
342
  constructor(options = {}) {
335
343
  this.options = options;
@@ -430,15 +438,38 @@ export class TuiProcess {
430
438
  * Emit an event to all handlers
431
439
  */
432
440
  emit(event) {
441
+ const pending = [...this.pendingPaneCreations].find(item => item.dispatched);
442
+ let completed;
433
443
  if (event.type === 'pane_created') {
434
444
  // The renderer reports a pane that carries a credential under the broker's own request id: its listeners hear of
435
445
  // it under the one its sender chose (see PaneCredentialBroker).
436
446
  const requestId = this.paneCredentials.created(event.pane_id, event.request_id);
437
- if (requestId !== event.request_id)
438
- event = { ...event, request_id: requestId };
447
+ if (pending?.wireRequestId === event.request_id)
448
+ completed = pending;
449
+ const senderId = completed?.requestId ?? requestId;
450
+ if (senderId !== event.request_id)
451
+ event = { ...event, request_id: senderId };
439
452
  }
440
453
  else if (event.type === 'pane_closed')
441
454
  this.paneCredentials.closed(event.pane_id);
455
+ else if (event.type === 'error') {
456
+ if (event.request_id !== undefined) {
457
+ const requestId = this.paneCredentials.failed(event.request_id);
458
+ if (pending?.wireRequestId === event.request_id)
459
+ completed = pending;
460
+ const senderId = completed?.requestId ?? requestId;
461
+ if (senderId !== event.request_id)
462
+ event = { ...event, request_id: senderId };
463
+ }
464
+ else if (pending && (event.message.startsWith(`${pending.command.type} failed`)
465
+ || pending.command.desktop_status && event.message === 'Status admission requires a unique owner process pane')) {
466
+ completed = pending;
467
+ this.paneCredentials.failed(pending.wireRequestId);
468
+ event = { ...event, request_id: pending.requestId };
469
+ }
470
+ }
471
+ if (completed?.timer)
472
+ clearTimeout(completed.timer);
442
473
  for (const handler of this.eventHandlers) {
443
474
  try {
444
475
  handler(event);
@@ -447,6 +478,39 @@ export class TuiProcess {
447
478
  // Ignore handler errors
448
479
  }
449
480
  }
481
+ if (completed) {
482
+ this.pendingPaneCreations.delete(completed);
483
+ const next = [...this.pendingPaneCreations][0];
484
+ if (next && !next.dispatched) {
485
+ try {
486
+ this.dispatchPaneMutation(next);
487
+ }
488
+ catch {
489
+ this.emit({ type: 'error', request_id: next.wireRequestId ?? next.requestId, message: 'Native pane renderer unavailable' });
490
+ }
491
+ }
492
+ }
493
+ }
494
+ dispatchPaneMutation(pending) {
495
+ pending.dispatched = true;
496
+ pending.wireRequestId = pending.requestId;
497
+ if (!this.socket || !this.ready)
498
+ throw new Error('Native pane renderer unavailable');
499
+ let command = pending.command.type === 'create_pane' ? this.paneCredentials.prepare(pending.command)
500
+ : this.paneCredentials.prepareReplace(pending.command);
501
+ if (command.request_id !== undefined && this.timedOutPaneRequestIds.has(command.request_id))
502
+ command = { ...command, request_id: randomUUID() };
503
+ pending.wireRequestId = command.request_id;
504
+ pending.timer = setTimeout(() => this.timeoutPaneMutation(pending), 5000);
505
+ pending.timer.unref();
506
+ this.socket.write(serializeCommand(command) + '\n');
507
+ }
508
+ timeoutPaneMutation(pending) {
509
+ if (!this.pendingPaneCreations.has(pending) || !pending.dispatched)
510
+ return;
511
+ if (pending.wireRequestId !== undefined)
512
+ this.timedOutPaneRequestIds.add(pending.wireRequestId);
513
+ this.emit({ type: 'error', request_id: pending.wireRequestId ?? pending.requestId, message: 'Native pane renderer timed out' });
450
514
  }
451
515
  /** Whether zmux (multiplexer mode) is active */
452
516
  get isMuxMode() {
@@ -528,6 +592,7 @@ export class TuiProcess {
528
592
  this.desktopStartupAdmitted = false;
529
593
  this._capabilities.clear();
530
594
  this.stopping = false;
595
+ this.timedOutPaneRequestIds.clear();
531
596
  let binaryPath;
532
597
  if (this._desktopMode) {
533
598
  const runtime = options?.desktopRuntime === undefined ? loadDesktopRuntime() : options.desktopRuntime;
@@ -843,6 +908,17 @@ export class TuiProcess {
843
908
  this.readyResolve = null;
844
909
  this.readyReject = null;
845
910
  }
911
+ if ((event.type === 'pane_created' || event.type === 'error') && event.request_id !== undefined
912
+ && this.timedOutPaneRequestIds.has(event.request_id)) {
913
+ if (event.type === 'pane_created' && Number.isSafeInteger(event.pane_id) && event.pane_id > 0) {
914
+ this.send({ type: 'close_pane', pane_id: event.pane_id });
915
+ }
916
+ return;
917
+ }
918
+ if (event.type === 'error' && event.request_id === undefined && this.timedOutPaneRequestIds.size > 0
919
+ && (event.message.startsWith('create_pane failed') || event.message.startsWith('replace_pane failed')
920
+ || event.message === 'Status admission requires a unique owner process pane'))
921
+ return;
846
922
  this.emit(event);
847
923
  });
848
924
  this.readline.on('close', () => {
@@ -856,14 +932,32 @@ export class TuiProcess {
856
932
  if (!this.socket || !this.ready) {
857
933
  return false;
858
934
  }
935
+ const outgoing = cmd.type === 'create_pane' || cmd.type === 'replace_pane' ? { ...cmd, request_id: cmd.request_id ?? randomUUID() } : cmd;
936
+ if (outgoing !== cmd)
937
+ for (const symbol of Object.getOwnPropertySymbols(cmd))
938
+ Object.defineProperty(outgoing, symbol, Object.getOwnPropertyDescriptor(cmd, symbol));
939
+ let pending;
859
940
  try {
860
- // A pane the renderer opens, or starts again in place, gets its own mirror credential (PaneCredentialBroker).
861
- const json = serializeCommand(cmd.type === 'create_pane' ? this.paneCredentials.prepare(cmd)
862
- : cmd.type === 'replace_pane' ? this.paneCredentials.prepareReplace(cmd) : cmd);
863
- this.socket.write(json + '\n');
941
+ const json = serializeCommand(outgoing);
942
+ if (outgoing.type === 'create_pane' || outgoing.type === 'replace_pane') {
943
+ pending = { requestId: outgoing.request_id, command: outgoing, dispatched: false };
944
+ this.pendingPaneCreations.add(pending);
945
+ if (this.pendingPaneCreations.size > 1)
946
+ return true;
947
+ this.dispatchPaneMutation(pending);
948
+ }
949
+ else {
950
+ this.socket.write(json + '\n');
951
+ }
864
952
  return true;
865
953
  }
866
954
  catch {
955
+ if (pending) {
956
+ if (pending.timer)
957
+ clearTimeout(pending.timer);
958
+ this.paneCredentials.failed(pending.wireRequestId);
959
+ this.pendingPaneCreations.delete(pending);
960
+ }
867
961
  return false;
868
962
  }
869
963
  }
@@ -877,6 +971,10 @@ export class TuiProcess {
877
971
  * Clean up resources
878
972
  */
879
973
  cleanup() {
974
+ for (const pending of this.pendingPaneCreations)
975
+ if (pending.timer)
976
+ clearTimeout(pending.timer);
977
+ this.pendingPaneCreations.clear();
880
978
  this.ready = false;
881
979
  // The renderer is gone, and with it every pane it opened.
882
980
  this.paneCredentials.revokeAll();
@@ -31,6 +31,7 @@ export interface TranscriptAnchor {
31
31
  export declare const CAPABILITY_PANE_DELIVERY_ACK = "pane_delivery_ack_v1";
32
32
  export declare const CAPABILITY_SCROLLBACK_ANCHOR = "scrollback_anchor";
33
33
  export declare const CAPABILITY_DESKTOP_UPDATE_RESTART = "desktop_update_restart_v1";
34
+ export declare const CAPABILITY_DESKTOP_ROUTER_CHROME = "desktop_router_chrome_v1";
34
35
  export declare const CAPABILITY_DESKTOP_TASK_CONTROLS = "desktop_task_controls_v1";
35
36
  export declare const CAPABILITY_DESKTOP_RUNTIME_CONTROLS = "desktop_runtime_controls_v1";
36
37
  export declare const CAPABILITY_DESKTOP_SESSION_SHARE = "desktop_session_share_v1";
@@ -145,6 +146,7 @@ export interface MuxPaneState {
145
146
  inferred_title?: string;
146
147
  labels?: PaneLabels;
147
148
  pane_type: string;
149
+ desktop_status?: boolean;
148
150
  command?: string;
149
151
  args?: string[];
150
152
  cwd?: string;
@@ -206,7 +208,13 @@ export interface DesktopTaskControlEntry {
206
208
  delivery: 'subturn' | 'end-of-turn';
207
209
  attachments: DesktopTaskControlAttachment[];
208
210
  }
211
+ export interface DesktopRouterState {
212
+ auth: 'signed_out' | 'expired' | 'authentication_rejected' | 'unavailable' | 'authenticated' | 'stale' | 'unknown';
213
+ status?: number;
214
+ funding: 'ready' | 'needs_payment' | 'payment_pending' | 'payment_failed' | 'cap_reached' | 'unavailable' | 'unknown';
215
+ }
209
216
  export interface DesktopTaskControlState {
217
+ router?: DesktopRouterState;
210
218
  version: 1;
211
219
  session_id: string;
212
220
  owner_id: string;
@@ -379,6 +387,7 @@ export type RustCommand = {
379
387
  target?: number;
380
388
  new_window?: boolean;
381
389
  pane_type?: string;
390
+ desktop_status?: boolean;
382
391
  env?: Record<string, string>;
383
392
  request_id?: string;
384
393
  persona?: string;
@@ -431,6 +440,7 @@ export type RustCommand = {
431
440
  cwd?: string;
432
441
  title?: string;
433
442
  pane_type?: string;
443
+ desktop_status?: boolean;
434
444
  content?: string;
435
445
  request_id?: string;
436
446
  } | {
@@ -473,6 +483,7 @@ export type RustCommand = {
473
483
  } | {
474
484
  type: 'restore_session_state';
475
485
  state: MuxSessionState;
486
+ preserve_pane_ids?: number[];
476
487
  } | {
477
488
  type: 'workspace_layout';
478
489
  action: 'save' | 'list' | 'restore' | 'delete';
@@ -489,6 +500,7 @@ export type RustCommand = {
489
500
  } | {
490
501
  type: 'zoom_pane';
491
502
  pane_id: number;
503
+ return_focus_pane_id?: number;
492
504
  } | {
493
505
  type: 'attach_mirror';
494
506
  socket_path: string;
@@ -571,6 +583,7 @@ export type RustEvent = DesktopTaskAction | DesktopRuntimeAction | DesktopSessio
571
583
  } | {
572
584
  type: 'error';
573
585
  message: string;
586
+ request_id?: string;
574
587
  } | {
575
588
  type: 'quit_requested';
576
589
  } | {
@@ -8,6 +8,7 @@
8
8
  export const CAPABILITY_PANE_DELIVERY_ACK = 'pane_delivery_ack_v1';
9
9
  export const CAPABILITY_SCROLLBACK_ANCHOR = 'scrollback_anchor';
10
10
  export const CAPABILITY_DESKTOP_UPDATE_RESTART = 'desktop_update_restart_v1';
11
+ export const CAPABILITY_DESKTOP_ROUTER_CHROME = 'desktop_router_chrome_v1';
11
12
  export const CAPABILITY_DESKTOP_TASK_CONTROLS = 'desktop_task_controls_v1';
12
13
  export const CAPABILITY_DESKTOP_RUNTIME_CONTROLS = 'desktop_runtime_controls_v1';
13
14
  export const CAPABILITY_DESKTOP_SESSION_SHARE = 'desktop_session_share_v1';
@@ -7,6 +7,7 @@ import { getDefaultModel } from './models.js';
7
7
  import { compactWithJev, collectJevCalls, resolveJevOptions, } from './jev_compaction.js';
8
8
  import { createRouterJevAsker } from './jev_client.js';
9
9
  import { DEFAULT_JEV_SETTINGS } from '../config/compaction.js';
10
+ import { requiredRouterModel } from '../config/router_required.js';
10
11
  import { isIncompleteModelResponse } from '../agent/completion_state.js';
11
12
  /**
12
13
  * The prompt-prefix identity of a conversation, or undefined while that prefix is
@@ -35,9 +36,10 @@ export function resolvePromptPrefixId(messages) {
35
36
  */
36
37
  export function getSummarizationModel(provider) {
37
38
  if (process.env.ZTC_ROUTER_REQUIRED === '1') {
38
- if (provider !== 'openai')
39
- throw new Error('Required Router compaction permits only openai/gpt-6.1-sol');
40
- return 'gpt-6.1-sol';
39
+ const required = requiredRouterModel();
40
+ if (provider !== required.provider)
41
+ throw new Error(`Required Router compaction permits only ${required.provider}/${required.model}`);
42
+ return required.model;
41
43
  }
42
44
  if (isCodexAppServerProvider(provider) || isCodexLegacyProvider(provider)) {
43
45
  return 'gpt-5.6-luna';
@@ -324,7 +326,7 @@ export async function makeBackendForProvider(provider, apiKey) {
324
326
  if (process.env.ZTC_ROUTER_REQUIRED === '1') {
325
327
  const { configStore } = await import('../config.js');
326
328
  const { ZRouterStreamBackend } = await loadBackendsModule();
327
- const resolved = configStore.resolveLLMBackendConfig({ provider, model: 'gpt-6.1-sol' });
329
+ const resolved = configStore.resolveLLMBackendConfig({ provider, model: requiredRouterModel().model });
328
330
  return new ZRouterStreamBackend({ provider: resolved.provider, model: resolved.model,
329
331
  apiKey: resolved.authToken, proxyUrl: resolved.proxyUrl });
330
332
  }
@@ -1,5 +1,6 @@
1
1
  import { PROVIDER_API_KEY_ENV } from '../config/provider_api_key_env.js';
2
2
  const USER_SUBPROCESS_STRIPPED_ZTC_ENV = [
3
+ 'ZTC_APPROVAL_TOKEN',
3
4
  'ZERG_ROUTER_BASE_URL',
4
5
  'ZTC_AUTH_TOKEN',
5
6
  'ZTC_BROKER_TOKEN',
@@ -111,6 +112,7 @@ export function restoreModelRouteCredentials(env, source) {
111
112
  /** Keep pane-local control fields while removing host RPC credentials. */
112
113
  export function removeUserSubprocessCredentials(source) {
113
114
  const env = { ...source };
115
+ delete env.ZTC_APPROVAL_TOKEN;
114
116
  delete env.ZTC_BROKER_TOKEN;
115
117
  delete env.ZTC_DESKTOP_RUNTIME_MANIFEST;
116
118
  delete env.ZTC_DESKTOP_RUNTIME_LEASE;
@@ -0,0 +1,10 @@
1
+ /** Pure canonical event projections consumed by browser views of ZTC. */
2
+ export { parseGoalView, retainGoalView } from '../goal_contract.js';
3
+ export { parseTaskHandoffView, retainTaskHandoffView } from './view_plugin.js';
4
+ export { parseEvidenceSnapshot } from '../agent/runtime/evidence.js';
5
+ export type * from '../events.js';
6
+ export { parseBenchmarkComparisonDecision } from '../agent/runtime/benchmark_comparison.js';
7
+ export { parseCommandVerificationReceipt, parseCurrentVerificationProjection } from '../agent/runtime/source_verification_contract.js';
8
+ export { parseHostVerifierDecision } from '../agent/runtime/verifier_contract.js';
9
+ export { parseCheckedCommandResult } from '../agent/runtime/checked_commands.js';
10
+ export { parseCommandExecutionObservation, parseCommandExecutionPolicy } from '../agent/runtime/command_execution_policy.js';
@@ -0,0 +1,9 @@
1
+ /** Pure canonical event projections consumed by browser views of ZTC. */
2
+ export { parseGoalView, retainGoalView } from '../goal_contract.js';
3
+ export { parseTaskHandoffView, retainTaskHandoffView } from './view_plugin.js';
4
+ export { parseEvidenceSnapshot } from '../agent/runtime/evidence.js';
5
+ export { parseBenchmarkComparisonDecision } from '../agent/runtime/benchmark_comparison.js';
6
+ export { parseCommandVerificationReceipt, parseCurrentVerificationProjection } from '../agent/runtime/source_verification_contract.js';
7
+ export { parseHostVerifierDecision } from '../agent/runtime/verifier_contract.js';
8
+ export { parseCheckedCommandResult } from '../agent/runtime/checked_commands.js';
9
+ export { parseCommandExecutionObservation, parseCommandExecutionPolicy } from '../agent/runtime/command_execution_policy.js';
@@ -1,3 +1,4 @@
1
+ import type { DailyDesktopSnapshot } from '../desktop/daily/desktop_wiring.js';
1
2
  import { type GoalView } from '../goal_contract.js';
2
3
  import { type EvidenceSnapshot } from '../agent/runtime/evidence.js';
3
4
  import type { TaskHandoffProjection } from '../session_handoff_contract.js';
@@ -7,7 +8,7 @@ import type { ViewPlugin } from './view_plugin.js';
7
8
  import { type TaskHandoffView } from './view_plugin.js';
8
9
  import type { HookApprovalDecision, HookApprovalKind, HookEventName } from '../hooks/types.js';
9
10
  import type { SlashCommandUsage } from '../agent/commands/index.js';
10
- import type { MessageAttachment, MessageInput } from '../types.js';
11
+ import type { MessageAttachment, MessageInput, CorrelatedInputResult, PromptTurnReceipt } from '../types.js';
11
12
  import type { HostedSessionSettings } from '../hosted/session_settings.js';
12
13
  import { type PaneStateUpdate } from './pane_registry.js';
13
14
  import { type WorkspaceRuntimeSnapshot, type WorkspaceTodo } from '../workspace_runtime.js';
@@ -209,6 +210,8 @@ export interface MirrorPaneRecord {
209
210
  todos?: WorkspaceTodo[];
210
211
  usage?: UsageSnapshot;
211
212
  usageSessionId?: string;
213
+ /** Actual conversation identity, available before the first usage receipt. */
214
+ sessionId?: string;
212
215
  toolProgress?: import('../types.js').AgentState['toolProgress'];
213
216
  evidence?: {
214
217
  sessionId: string;
@@ -420,6 +423,9 @@ export declare class MirrorStreamServer implements MirrorPublisher {
420
423
  private startedAt;
421
424
  private runtimeStatsProvider;
422
425
  private inputCallback;
426
+ private correlatedInputCallback;
427
+ private correlatedInputAvailable;
428
+ private promptTurnsProvider;
423
429
  private readonly mediaDir;
424
430
  private readonly toolImageJobs;
425
431
  private readonly mediaById;
@@ -429,6 +435,9 @@ export declare class MirrorStreamServer implements MirrorPublisher {
429
435
  /** Active requests belong to a pane; retained transcript capacity is not their lifecycle. */
430
436
  private readonly pendingQuestions;
431
437
  private readonly workspaceOwnerId;
438
+ private dailyProvider;
439
+ private dailyRefresh;
440
+ private dailyAction;
432
441
  private widgetAnswerCallback;
433
442
  private hookApprovalCallback;
434
443
  private zlickyCaptures;
@@ -474,6 +483,8 @@ export declare class MirrorStreamServer implements MirrorPublisher {
474
483
  private accountOperationHook;
475
484
  setLogBuffer(fn: () => readonly string[]): void;
476
485
  setRuntimeStatsProvider(fn: () => MirrorRuntimeStats): void;
486
+ setPromptTurnsProvider(fn: () => PromptTurnReceipt[]): void;
487
+ onCorrelatedInput(callback: (input: MessageInput) => Promise<CorrelatedInputResult>, available?: () => boolean): void;
477
488
  /**
478
489
  * Number of live SSE viewers — browser clients on `GET /events`. zmux and
479
490
  * other native renderers use their own socket, not `/events`, so this counts
@@ -499,7 +510,7 @@ export declare class MirrorStreamServer implements MirrorPublisher {
499
510
  private busMembers;
500
511
  private busObservers;
501
512
  private eventObservers;
502
- constructor(port?: number, host?: string, persistEvents?: boolean, persistenceKey?: string);
513
+ constructor(port?: number, host?: string, persistEvents?: boolean, persistenceKey?: string, primarySessionId?: string);
503
514
  /** Broadcast the display-only active-account summary to mirror clients. */
504
515
  publishAccounts(): void;
505
516
  /**
@@ -529,6 +540,7 @@ export declare class MirrorStreamServer implements MirrorPublisher {
529
540
  private findPaneRecord;
530
541
  getPort(): number;
531
542
  getEventHistory(): MirrorEvent[];
543
+ setDailyDesktop(provider: (() => DailyDesktopSnapshot) | null, refresh: (() => Promise<void>) | null, action: ((action: 'zoom' | 'collapse', paneId: number) => boolean) | null): void;
532
544
  getWorkspaceRuntimeSnapshot(): WorkspaceRuntimeSnapshot;
533
545
  setSuperuser(value: boolean): void;
534
546
  setSfxConfig(config: {
@@ -993,7 +1005,7 @@ export declare class MirrorStreamServer implements MirrorPublisher {
993
1005
  private handleRequest;
994
1006
  }
995
1007
  export declare function getMirrorStreamServer(): MirrorStreamServer | null;
996
- export declare function createIsolatedMirrorStreamServer(port?: number, persistEvents?: boolean, persistenceKey?: string, host?: string): MirrorStreamServer;
997
- export declare function createMirrorStreamServer(port?: number, persistEvents?: boolean, persistenceKey?: string, host?: string): MirrorStreamServer;
998
- export declare function startMirrorStreamServer(port?: number, persistenceKey?: string): Promise<MirrorStreamServer>;
1008
+ export declare function createIsolatedMirrorStreamServer(port?: number, persistEvents?: boolean, persistenceKey?: string, host?: string, primarySessionId?: string): MirrorStreamServer;
1009
+ export declare function createMirrorStreamServer(port?: number, persistEvents?: boolean, persistenceKey?: string, host?: string, primarySessionId?: string): MirrorStreamServer;
1010
+ export declare function startMirrorStreamServer(port?: number, persistenceKey?: string, primarySessionId?: string): Promise<MirrorStreamServer>;
999
1011
  export declare function stopMirrorStreamServer(): Promise<void>;