@zergai/ztc 0.26.6-dev.202611240947 → 0.27.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 (268) hide show
  1. package/README.md +629 -167
  2. package/RUST_THIRD_PARTY_LICENSES.txt +5 -5
  3. package/bin/zmux-darwin-arm64 +0 -0
  4. package/bin/zmux-linux-x64 +0 -0
  5. package/bin/ztc-audio-darwin-arm64 +0 -0
  6. package/bin/ztc-capture-darwin-arm64 +0 -0
  7. package/bin/ztc-computer-darwin-arm64 +0 -0
  8. package/bin/ztc-llm-darwin-arm64 +0 -0
  9. package/bin/ztc-tts-darwin-arm64 +0 -0
  10. package/bin/ztc-tui-darwin-arm64 +0 -0
  11. package/bin/ztc-tui-linux-x64 +0 -0
  12. package/bin/zterm-darwin-arm64 +2 -2
  13. package/dist/App.js +6 -1
  14. package/dist/agent/agent.d.ts +21 -15
  15. package/dist/agent/agent.js +389 -163
  16. package/dist/agent/backends/codex_app_server.d.ts +7 -1
  17. package/dist/agent/backends/codex_app_server.js +11 -1
  18. package/dist/agent/backends/gemini.js +22 -8
  19. package/dist/agent/commands/batch.js +8 -0
  20. package/dist/agent/commands/config.js +10 -0
  21. package/dist/agent/commands/environment.js +5 -5
  22. package/dist/agent/commands/goal.d.ts +1 -0
  23. package/dist/agent/commands/goal.js +2 -1
  24. package/dist/agent/commands/index.js +2 -1
  25. package/dist/agent/commands/manifest.js +4 -0
  26. package/dist/agent/commands/optimize.js +5 -2
  27. package/dist/agent/commands/pane_cli.d.ts +29 -0
  28. package/dist/agent/commands/pane_cli.js +303 -0
  29. package/dist/agent/commands/settings.js +13 -3
  30. package/dist/agent/commands/shannon.js +8 -0
  31. package/dist/agent/commands/update.js +15 -3
  32. package/dist/agent/commands/zerg.js +31 -1
  33. package/dist/agent/commands/ztc_pane.js +3 -1
  34. package/dist/agent/factory.d.ts +4 -0
  35. package/dist/agent/factory.js +11 -1
  36. package/dist/agent/loop_policy.d.ts +42 -5
  37. package/dist/agent/loop_policy.js +206 -3
  38. package/dist/agent/runtime/command_jobs.d.ts +5 -0
  39. package/dist/agent/runtime/command_jobs.js +241 -31
  40. package/dist/agent/runtime/command_wait.d.ts +2 -0
  41. package/dist/agent/runtime/command_wait.js +1 -0
  42. package/dist/agent/runtime/done_report.d.ts +18 -0
  43. package/dist/agent/runtime/done_report.js +130 -0
  44. package/dist/agent/runtime/execution_context.js +4 -1
  45. package/dist/agent/runtime/failure_cause.d.ts +2 -0
  46. package/dist/agent/runtime/failure_cause.js +35 -0
  47. package/dist/agent/runtime/policy.d.ts +14 -2
  48. package/dist/agent/runtime/policy.js +104 -12
  49. package/dist/agent/runtime/quiet_job.d.ts +18 -0
  50. package/dist/agent/runtime/quiet_job.js +48 -0
  51. package/dist/agent/runtime/recovery.d.ts +1 -5
  52. package/dist/agent/runtime/recovery.js +2 -44
  53. package/dist/agent/runtime/tool_runtime.d.ts +1 -0
  54. package/dist/agent/runtime/tool_runtime.js +2 -0
  55. package/dist/agent/subagent.js +6 -1
  56. package/dist/agent/tools/deferred.js +1 -0
  57. package/dist/agent/tools/index.d.ts +2 -0
  58. package/dist/agent/tools/index.js +1 -0
  59. package/dist/agent/tools/outcome.d.ts +15 -0
  60. package/dist/agent/tools/outcome.js +107 -0
  61. package/dist/agent/tools/pane.d.ts +2 -1
  62. package/dist/agent/tools/pane.js +21 -3
  63. package/dist/agent/tools/registry.js +2 -0
  64. package/dist/agent/tools/shell.d.ts +1 -0
  65. package/dist/agent/tools/shell.js +128 -17
  66. package/dist/agent/tools/sim_domain_tools.js +4 -2
  67. package/dist/agent/tools/supervision.js +4 -2
  68. package/dist/agent/tools/types.d.ts +3 -0
  69. package/dist/app/command_context.js +5 -9
  70. package/dist/app/conversation_compaction.d.ts +4 -2
  71. package/dist/app/conversation_compaction.js +16 -5
  72. package/dist/app/headless_shell_mode.d.ts +14 -0
  73. package/dist/app/headless_shell_mode.js +7 -0
  74. package/dist/app/hosted_resident.d.ts +356 -0
  75. package/dist/app/hosted_resident.js +677 -0
  76. package/dist/app/restart.js +11 -2
  77. package/dist/app/session_manager.d.ts +5 -0
  78. package/dist/app/session_manager.js +21 -6
  79. package/dist/app/session_messages.js +6 -6
  80. package/dist/app/workspace_layout_controller.js +7 -0
  81. package/dist/batch/worktree.d.ts +10 -0
  82. package/dist/batch/worktree.js +15 -0
  83. package/dist/bench/registry.js +4 -2
  84. package/dist/cli_args.js +1 -1
  85. package/dist/cli_main.js +80 -10
  86. package/dist/cli_ratatui.d.ts +75 -0
  87. package/dist/cli_ratatui.js +485 -84
  88. package/dist/components/InputArea.js +4 -4
  89. package/dist/config/execution.d.ts +10 -0
  90. package/dist/config/execution.js +10 -0
  91. package/dist/config/hosted_runtime.d.ts +4 -1
  92. package/dist/config/hosted_runtime.js +4 -1
  93. package/dist/config/permission_pin.d.ts +34 -2
  94. package/dist/config/permission_pin.js +52 -2
  95. package/dist/config/person_command_policy.d.ts +38 -0
  96. package/dist/config/person_command_policy.js +11 -0
  97. package/dist/config/profiles.d.ts +21 -0
  98. package/dist/config/profiles.js +56 -2
  99. package/dist/config/types.d.ts +4 -1
  100. package/dist/config.js +34 -19
  101. package/dist/desktop/daily/codex_exec_adapter.js +7 -2
  102. package/dist/desktop/daily/desktop_wiring.d.ts +7 -1
  103. package/dist/desktop/daily/desktop_wiring.js +11 -3
  104. package/dist/desktop/daily/recipes.js +20 -4
  105. package/dist/desktop/health.d.ts +24 -0
  106. package/dist/desktop/health.js +151 -0
  107. package/dist/desktop/native_dialogs.d.ts +37 -0
  108. package/dist/desktop/native_dialogs.js +105 -0
  109. package/dist/diagnostics/session_export.d.ts +1 -0
  110. package/dist/diagnostics/session_export.js +28 -0
  111. package/dist/embedded/registry.js +4 -2
  112. package/dist/emulation/tool_adapters.js +9 -4
  113. package/dist/emulation/ztc_addendum.js +3 -0
  114. package/dist/headless.d.ts +11 -4
  115. package/dist/headless.js +99 -34
  116. package/dist/headless_approval.d.ts +6 -0
  117. package/dist/headless_cli.js +1 -1
  118. package/dist/hooks/runner.js +7 -6
  119. package/dist/library.d.ts +4 -0
  120. package/dist/library.js +3 -0
  121. package/dist/mcp/client.js +3 -3
  122. package/dist/modes/registry.js +13 -4
  123. package/dist/onboarding/setup_environment.js +13 -1
  124. package/dist/optimize/adapters/kernelbench.js +88 -10
  125. package/dist/optimize/adapters/types.d.ts +5 -0
  126. package/dist/optimize/executor.js +21 -0
  127. package/dist/panes/cli_install.d.ts +54 -0
  128. package/dist/panes/cli_install.js +157 -0
  129. package/dist/panes/model_catalog.js +3 -0
  130. package/dist/panes/new_pane_choices.d.ts +6 -2
  131. package/dist/panes/new_pane_choices.js +24 -12
  132. package/dist/panes/pane_cli_launch.d.ts +50 -0
  133. package/dist/panes/pane_cli_launch.js +124 -0
  134. package/dist/panes/pane_clis.d.ts +171 -0
  135. package/dist/panes/pane_clis.js +325 -0
  136. package/dist/panes/person_only_panes.d.ts +45 -0
  137. package/dist/panes/person_only_panes.js +117 -0
  138. package/dist/plugin/simulation_living.js +0 -2
  139. package/dist/plugin/simulation_living_engine.d.ts +1 -0
  140. package/dist/plugin/simulation_living_engine.js +1 -0
  141. package/dist/plugin/simulation_living_labels.d.ts +3 -0
  142. package/dist/plugin/simulation_living_labels.js +2 -0
  143. package/dist/router_auth.js +12 -1
  144. package/dist/session.js +26 -1
  145. package/dist/simulation/art/gemini_image.js +11 -5
  146. package/dist/simulation/domains/loader.js +25 -3
  147. package/dist/simulation/living/cold.d.ts +23 -0
  148. package/dist/simulation/living/cold.js +41 -0
  149. package/dist/simulation/living/context.d.ts +591 -1283
  150. package/dist/simulation/living/context.js +378 -244
  151. package/dist/simulation/living/contradictions.d.ts +14 -0
  152. package/dist/simulation/living/contradictions.js +282 -0
  153. package/dist/simulation/living/core/ids.d.ts +53 -0
  154. package/dist/simulation/living/core/ids.js +39 -0
  155. package/dist/simulation/living/core/kind.d.ts +20 -0
  156. package/dist/simulation/living/core/kind.js +15 -0
  157. package/dist/simulation/living/core/laws.d.ts +179 -0
  158. package/dist/simulation/living/core/laws.js +184 -0
  159. package/dist/simulation/living/core/ops.d.ts +257 -0
  160. package/dist/simulation/living/core/ops.js +34 -0
  161. package/dist/simulation/living/definer.d.ts +17 -1
  162. package/dist/simulation/living/definer.js +130 -51
  163. package/dist/simulation/living/definition.d.ts +174 -65
  164. package/dist/simulation/living/definition.js +287 -180
  165. package/dist/simulation/living/director.d.ts +80 -0
  166. package/dist/simulation/living/director.js +363 -0
  167. package/dist/simulation/living/frame.d.ts +108 -21
  168. package/dist/simulation/living/frame.js +111 -66
  169. package/dist/simulation/living/identifiers.d.ts +0 -1
  170. package/dist/simulation/living/identifiers.js +0 -3
  171. package/dist/simulation/living/index.d.ts +18 -9
  172. package/dist/simulation/living/index.js +18 -9
  173. package/dist/simulation/living/inference.d.ts +92 -50
  174. package/dist/simulation/living/inference.js +319 -175
  175. package/dist/simulation/living/knowledge.d.ts +28 -0
  176. package/dist/simulation/living/knowledge.js +73 -0
  177. package/dist/simulation/living/library.json +1177 -0
  178. package/dist/simulation/living/mechanics.d.ts +31 -34
  179. package/dist/simulation/living/mechanics.js +222 -138
  180. package/dist/simulation/living/model-input.d.ts +6 -3
  181. package/dist/simulation/living/model-input.js +18 -26
  182. package/dist/simulation/living/open-world.d.ts +74 -94
  183. package/dist/simulation/living/open-world.js +151 -30
  184. package/dist/simulation/living/phrases.d.ts +3 -0
  185. package/dist/simulation/living/phrases.js +37 -0
  186. package/dist/simulation/living/phrases.json +560 -0
  187. package/dist/simulation/living/projection.d.ts +316 -2
  188. package/dist/simulation/living/projection.js +50 -2
  189. package/dist/simulation/living/prompts/example-spec.json +11 -0
  190. package/dist/simulation/living/prompts/role-text.json +14 -0
  191. package/dist/simulation/living/prompts.d.ts +5 -0
  192. package/dist/simulation/living/prompts.js +275 -0
  193. package/dist/simulation/living/recall.d.ts +2 -2
  194. package/dist/simulation/living/reduce.d.ts +51 -14
  195. package/dist/simulation/living/reduce.js +941 -579
  196. package/dist/simulation/living/replay.d.ts +5 -4
  197. package/dist/simulation/living/replay.js +10 -9
  198. package/dist/simulation/living/runtime.d.ts +135 -25
  199. package/dist/simulation/living/runtime.js +1641 -583
  200. package/dist/simulation/living/scale.d.ts +96 -0
  201. package/dist/simulation/living/scale.js +124 -0
  202. package/dist/simulation/living/script.d.ts +5 -0
  203. package/dist/simulation/living/script.js +115 -0
  204. package/dist/simulation/living/shared-kinds.d.ts +4 -11
  205. package/dist/simulation/living/shared-kinds.js +11 -81
  206. package/dist/simulation/living/space.d.ts +14 -0
  207. package/dist/simulation/living/space.js +132 -0
  208. package/dist/simulation/living/state.d.ts +100 -0
  209. package/dist/simulation/living/state.js +393 -0
  210. package/dist/simulation/living/types.d.ts +829 -512
  211. package/dist/simulation/living/types.js +162 -187
  212. package/dist/simulation/living/world-rules.d.ts +100 -0
  213. package/dist/simulation/living/world-rules.js +267 -0
  214. package/dist/simulation/plugins/loader.js +11 -0
  215. package/dist/skills/loader.js +4 -0
  216. package/dist/tools.d.ts +1 -0
  217. package/dist/tools.js +1 -0
  218. package/dist/ui/ratatui/headless_pane_manager.d.ts +4 -1
  219. package/dist/ui/ratatui/headless_pane_manager.js +13 -9
  220. package/dist/ui/ratatui/pane_relay.js +29 -0
  221. package/dist/ui/ratatui/pane_type.d.ts +10 -0
  222. package/dist/ui/ratatui/pane_type.js +11 -0
  223. package/dist/ui/ratatui/process.d.ts +30 -0
  224. package/dist/ui/ratatui/process.js +133 -19
  225. package/dist/ui/ratatui/protocol.d.ts +124 -2
  226. package/dist/ui/ratatui/protocol.js +35 -0
  227. package/dist/ui/ratatui/relay_policy.js +3 -0
  228. package/dist/ui/ratatui/ztc_launch_trust.d.ts +2 -1
  229. package/dist/ui/ratatui/ztc_launch_trust.js +8 -1
  230. package/dist/ui/terminal_image.d.ts +12 -0
  231. package/dist/ui/terminal_image.js +21 -1
  232. package/dist/utils/codex_project_trust.d.ts +19 -0
  233. package/dist/utils/codex_project_trust.js +37 -0
  234. package/dist/utils/compaction.js +103 -20
  235. package/dist/utils/git_program_files.d.ts +19 -12
  236. package/dist/utils/git_program_files.js +411 -83
  237. package/dist/utils/host_shell.d.ts +10 -1
  238. package/dist/utils/host_shell.js +14 -1
  239. package/dist/utils/mid_turn_compaction.d.ts +2 -0
  240. package/dist/utils/mid_turn_compaction.js +2 -0
  241. package/dist/utils/models.js +6 -1
  242. package/dist/utils/sandbox.d.ts +109 -8
  243. package/dist/utils/sandbox.js +981 -187
  244. package/dist/utils/shell.d.ts +2 -0
  245. package/dist/utils/shell.js +10 -4
  246. package/dist/utils/subprocess_env.d.ts +47 -11
  247. package/dist/utils/subprocess_env.js +107 -15
  248. package/dist/utils/system_ps.d.ts +8 -0
  249. package/dist/utils/system_ps.js +39 -7
  250. package/dist/utils/unattended_compaction.d.ts +9 -0
  251. package/dist/utils/unattended_compaction.js +13 -0
  252. package/dist/utils/ztc_own_state.d.ts +8 -5
  253. package/dist/utils/ztc_own_state.js +17 -11
  254. package/dist/web/mirror_client.js +1 -0
  255. package/dist/web/mirror_stream.d.ts +50 -6
  256. package/dist/web/mirror_stream.js +160 -15
  257. package/dist/workflows/registry.js +3 -1
  258. package/dist/workspace/controller.js +12 -0
  259. package/dist/workspace_collision.d.ts +3 -0
  260. package/dist/workspace_collision.js +14 -1
  261. package/dist/workspace_session_context.js +2 -1
  262. package/dist/zlm-embed.mjs +3823 -1970
  263. package/node_modules/@zerg/model-contracts/README.md +16 -4
  264. package/node_modules/@zerg/model-contracts/index.js +6 -1
  265. package/npm-shrinkwrap.json +1 -1
  266. package/package.json +42 -24
  267. package/packages/model-contracts/README.md +16 -4
  268. package/packages/model-contracts/index.js +6 -1
@@ -0,0 +1,45 @@
1
+ /**
2
+ * The panes that run a CLI only the person drives (pane_clis.ts: Antigravity), and why each thing an agent asks of one
3
+ * is refused.
4
+ *
5
+ * The main ZTC notes such a pane as it opens it (pane_cli_launch.ts openPaneCli; only Main opens one, for the person),
6
+ * and every path by which something other than the person reaches a pane asks here first: Main's own pane tools
7
+ * (write_terminal_pane, restart_pane, and create_terminal_pane, which won't start the CLI itself), the pane relay, for
8
+ * what every other pane's programs send (a ZTC pane's tools, a Claude Code or Codex pane's workspace-mcp), the message
9
+ * bus, and the mirror's other typing (/broadcast, and what its process-wide token posts to /pane-input or /mux/command,
10
+ * mirror_stream.ts). What the person types into the pane, at the keyboard or in their own browser mirror, never comes
11
+ * here. It reads what ZTC opens, types and relays; an agent's own shell tools can still run any program on the person's
12
+ * PATH, the CLI's among them.
13
+ *
14
+ * A pane keeps its id until ZTC exits (the renderers never give a closed pane's id to another), so a pane is never
15
+ * forgotten. A restart in place (the desktop app keeps every live pane and the new ZTC adopts it) keeps it the person's:
16
+ * the ZTC that takes this one's place is handed the marks (personOnlyPanesRelaunchEnv) and reads them as it loads. A
17
+ * child ZTC notes none: its pane tools reach the renderer only through the main ZTC's relay, which asks.
18
+ */
19
+ import { type PaneCliId } from './pane_clis.js';
20
+ /** The marks for the ZTC that takes this one's place in a restart in place, as one environment variable. */
21
+ export declare function personOnlyPanesRelaunchEnv(): Record<string, string>;
22
+ /** Read the marks a restart in place handed this ZTC in ENV, and take them out of it. Only person-only CLIs are marked. */
23
+ export declare function restorePersonOnlyPanes(env?: NodeJS.ProcessEnv): void;
24
+ /** Pane PANE_ID runs CLI, which only the person drives. */
25
+ export declare function notePersonOnlyPane(paneId: number, cli: PaneCliId): void;
26
+ /** The person-only CLI pane PANE_ID runs, if it runs one. */
27
+ export declare function personOnlyPaneCli(paneId: number): PaneCliId | null;
28
+ /** What an agent asked of the pane: to type into it, message it, restart it in place or replace what runs in it. */
29
+ export type PersonOnlyAct = 'type' | 'message' | 'restart' | 'replace';
30
+ /** Why an agent can't ACT on pane PANE_ID, or null when it runs no person-only CLI. */
31
+ export declare function personOnlyPaneRefusal(paneId: number, act: PersonOnlyAct): string | null;
32
+ /** Why an agent can't open CLI, a person-only one, or null. */
33
+ export declare function personOnlyLaunchRefusal(cli: PaneCliId): string | null;
34
+ /**
35
+ * Why a ZTC whose choices answer themselves (a headless run, its input the program's that runs it) doesn't open CLI, a
36
+ * person-only one, or null: no one types into such a pane but that program.
37
+ */
38
+ export declare function personOnlyHeadlessRefusal(cli: PaneCliId): string | null;
39
+ /**
40
+ * Why an agent can't start COMMAND with ARGS in a pane of its own, or null: the program, one of its arguments (as a
41
+ * login shell's `exec "$0" "$@"` takes the program), or a word of the script a shell or an interpreter is handed to run
42
+ * (`sh -c 'agy -p …'`), is a person-only CLI's executable. It reads what an agent's pane would start, not every way a
43
+ * program can be named: an agent's own shell can still run what the person's PATH holds (README).
44
+ */
45
+ export declare function personOnlyProgramRefusal(command: string, args?: readonly string[]): string | null;
@@ -0,0 +1,117 @@
1
+ /**
2
+ * The panes that run a CLI only the person drives (pane_clis.ts: Antigravity), and why each thing an agent asks of one
3
+ * is refused.
4
+ *
5
+ * The main ZTC notes such a pane as it opens it (pane_cli_launch.ts openPaneCli; only Main opens one, for the person),
6
+ * and every path by which something other than the person reaches a pane asks here first: Main's own pane tools
7
+ * (write_terminal_pane, restart_pane, and create_terminal_pane, which won't start the CLI itself), the pane relay, for
8
+ * what every other pane's programs send (a ZTC pane's tools, a Claude Code or Codex pane's workspace-mcp), the message
9
+ * bus, and the mirror's other typing (/broadcast, and what its process-wide token posts to /pane-input or /mux/command,
10
+ * mirror_stream.ts). What the person types into the pane, at the keyboard or in their own browser mirror, never comes
11
+ * here. It reads what ZTC opens, types and relays; an agent's own shell tools can still run any program on the person's
12
+ * PATH, the CLI's among them.
13
+ *
14
+ * A pane keeps its id until ZTC exits (the renderers never give a closed pane's id to another), so a pane is never
15
+ * forgotten. A restart in place (the desktop app keeps every live pane and the new ZTC adopts it) keeps it the person's:
16
+ * the ZTC that takes this one's place is handed the marks (personOnlyPanesRelaunchEnv) and reads them as it loads. A
17
+ * child ZTC notes none: its pane tools reach the renderer only through the main ZTC's relay, which asks.
18
+ */
19
+ import { basename } from 'node:path';
20
+ import { PANE_CLIS, isPersonOnlyCli, paneCliByBinary } from './pane_clis.js';
21
+ const panes = new Map();
22
+ const RELAUNCH_VARIABLE = 'ZTC_PERSON_ONLY_PANES';
23
+ /** The marks for the ZTC that takes this one's place in a restart in place, as one environment variable. */
24
+ export function personOnlyPanesRelaunchEnv() {
25
+ return panes.size > 0 ? { [RELAUNCH_VARIABLE]: JSON.stringify([...panes]) } : {};
26
+ }
27
+ /** Read the marks a restart in place handed this ZTC in ENV, and take them out of it. Only person-only CLIs are marked. */
28
+ export function restorePersonOnlyPanes(env = process.env) {
29
+ const raw = env[RELAUNCH_VARIABLE];
30
+ delete env[RELAUNCH_VARIABLE];
31
+ if (!raw)
32
+ return;
33
+ let rows;
34
+ try {
35
+ rows = JSON.parse(raw);
36
+ }
37
+ catch {
38
+ return;
39
+ }
40
+ if (!Array.isArray(rows))
41
+ return;
42
+ for (const row of rows) {
43
+ if (!Array.isArray(row) || !Number.isSafeInteger(row[0]) || typeof row[1] !== 'string')
44
+ continue;
45
+ if (row[1] in PANE_CLIS)
46
+ notePersonOnlyPane(row[0], row[1]);
47
+ }
48
+ }
49
+ /** Pane PANE_ID runs CLI, which only the person drives. */
50
+ export function notePersonOnlyPane(paneId, cli) {
51
+ if (isPersonOnlyCli(cli))
52
+ panes.set(paneId, cli);
53
+ }
54
+ /** The person-only CLI pane PANE_ID runs, if it runs one. */
55
+ export function personOnlyPaneCli(paneId) {
56
+ return panes.get(paneId) ?? null;
57
+ }
58
+ const VERBS = Object.freeze({
59
+ type: 'type into it',
60
+ message: 'message it',
61
+ restart: 'restart it',
62
+ replace: 'replace it',
63
+ });
64
+ /** Why an agent can't ACT on pane PANE_ID, or null when it runs no person-only CLI. */
65
+ export function personOnlyPaneRefusal(paneId, act) {
66
+ const cli = panes.get(paneId);
67
+ if (!cli)
68
+ return null;
69
+ const spec = PANE_CLIS[cli];
70
+ return `Pane ${paneId} runs ${spec.label}, which only the person drives: ${spec.personOnlyWhy}. So no agent, ZTC's or another pane's, `
71
+ + `can ${VERBS[act]}; ask the person to.`;
72
+ }
73
+ /** Why an agent can't open CLI, a person-only one, or null. */
74
+ export function personOnlyLaunchRefusal(cli) {
75
+ if (!isPersonOnlyCli(cli))
76
+ return null;
77
+ const spec = PANE_CLIS[cli];
78
+ return `${spec.label} opens only for the person, who types /${spec.command} in Main (pane 0) or picks it in the new-pane menu: `
79
+ + `${spec.personOnlyWhy}. So no agent, nor a message or another pane's input, opens it or drives it.`;
80
+ }
81
+ /**
82
+ * Why a ZTC whose choices answer themselves (a headless run, its input the program's that runs it) doesn't open CLI, a
83
+ * person-only one, or null: no one types into such a pane but that program.
84
+ */
85
+ export function personOnlyHeadlessRefusal(cli) {
86
+ if (!isPersonOnlyCli(cli))
87
+ return null;
88
+ const spec = PANE_CLIS[cli];
89
+ return `${spec.label} opens only where you type into it yourself, in ZTC's terminal or the desktop app: this ZTC runs headless, `
90
+ + `taking its input from the program that runs it, and ${spec.personOnlyWhy}. Run ${spec.binaries[0]} in a terminal of your own.`;
91
+ }
92
+ /** A flag that hands a shell (sh -c, zsh -lc, bash -ec) or an interpreter (python3 -c) the script to run next. */
93
+ const SCRIPT_FLAG = /^-[A-Za-z]*c[A-Za-z]*$/;
94
+ /** The words of SCRIPT a shell would run, roughly: split at blanks and at its operators, with quotes and escapes taken off. */
95
+ function scriptWords(script) {
96
+ return script.split(/[\s;&|()<>`$"'\\{}]+/).filter(Boolean);
97
+ }
98
+ /**
99
+ * Why an agent can't start COMMAND with ARGS in a pane of its own, or null: the program, one of its arguments (as a
100
+ * login shell's `exec "$0" "$@"` takes the program), or a word of the script a shell or an interpreter is handed to run
101
+ * (`sh -c 'agy -p …'`), is a person-only CLI's executable. It reads what an agent's pane would start, not every way a
102
+ * program can be named: an agent's own shell can still run what the person's PATH holds (README).
103
+ */
104
+ export function personOnlyProgramRefusal(command, args = []) {
105
+ const argv = [command, ...args].filter((word) => typeof word === 'string');
106
+ const words = argv.flatMap((word, index) => (index > 0 && SCRIPT_FLAG.test(argv[index - 1]) ? [word, ...scriptWords(word)] : [word]));
107
+ for (const word of words) {
108
+ const cli = paneCliByBinary(basename(word.trim()));
109
+ if (cli && isPersonOnlyCli(cli)) {
110
+ const spec = PANE_CLIS[cli];
111
+ return `An agent can't start ${spec.label} (${spec.binaries[0]}): only the person opens it, with /${spec.command}, since `
112
+ + `${spec.personOnlyWhy}.`;
113
+ }
114
+ }
115
+ return null;
116
+ }
117
+ restorePersonOnlyPanes();
@@ -1,3 +1 @@
1
- // Public boundary for the living-world engine: one inhabited character, a cast with
2
- // their own minds, a Game Master that resolves attempts, and replayable saved events.
3
1
  export * from '../simulation/living/index.js';
@@ -0,0 +1 @@
1
+ export { parseReaction, reactionProblems, presenceProblems, reactionAnswerProblems, type ReactionProblem, type ReactionProblemFacts } from '../simulation/living/index.js';
@@ -0,0 +1 @@
1
+ export { parseReaction, reactionProblems, presenceProblems, reactionAnswerProblems } from '../simulation/living/index.js';
@@ -0,0 +1,3 @@
1
+ export { clockLabel } from '../simulation/living/scale.js';
2
+ export { DEFAULT_CALENDAR } from '../simulation/living/scale.js';
3
+ export type { LivingCalendar } from '../simulation/living/scale.js';
@@ -0,0 +1,2 @@
1
+ export { clockLabel } from '../simulation/living/scale.js';
2
+ export { DEFAULT_CALENDAR } from '../simulation/living/scale.js';
@@ -8,7 +8,7 @@ import { buildUserSubprocessEnv } from './utils/subprocess_env.js';
8
8
  import { setTimeout as delay } from 'node:timers/promises';
9
9
  import { getVersion } from './utils/version.js';
10
10
  import { browserLaunchAllowed } from './utils/session_interactivity.js';
11
- import { activeProfile, profileConfigDir } from './config/profiles.js';
11
+ import { activeProfile, profileConfigDir, sharesParentSettings } from './config/profiles.js';
12
12
  import { FIREWORKS_FUNDED_MODEL, getFireworksModelName } from './utils/fireworks.js';
13
13
  export const DEFAULT_ROUTER_ORIGIN = 'https://zergrouter.com';
14
14
  /** The Routers a login can name instead of giving their URL: `/login dev`, `ztc auth login prod`. */
@@ -52,6 +52,14 @@ const terminalOutput = (message, stream) => { process[stream].write(message); };
52
52
  function authCommandName(surface, subcommand) {
53
53
  return surface === 'session' ? `/auth ${subcommand}` : `ztc auth ${subcommand}`;
54
54
  }
55
+ /** A ZTC started by another ZTC on the same settings would change that ZTC's login, so it signs neither in nor out. */
56
+ function refuseInParentSettings(surface, subcommand) {
57
+ if (!sharesParentSettings())
58
+ return;
59
+ throw new Error(`This ZTC was started by another ZTC process and shares its settings in ${profileConfigDir()}, so it cannot `
60
+ + `sign ${subcommand === 'login' ? 'in' : 'out'} here without changing that ZTC's login. Run ${authCommandName(surface, subcommand)} `
61
+ + 'from a top-level ZTC.');
62
+ }
55
63
  /** A Router money amount (a decimal string) as dollars and cents. */
56
64
  function formatUsd(amount) {
57
65
  if (amount === null)
@@ -591,6 +599,7 @@ export async function runRouterAuthCommand(args, output = terminalOutput, { orig
591
599
  else
592
600
  throw new Error(`Usage: ${authCommandName(surface, 'login')} [dev|prod] [--url <router-origin>] [--no-browser]`);
593
601
  }
602
+ refuseInParentSettings(surface, 'login');
594
603
  await login(origin ?? await configuredRouterOrigin(), noBrowser, output, surface, hooks);
595
604
  return;
596
605
  }
@@ -651,6 +660,8 @@ export async function runRouterAuthCommand(args, output = terminalOutput, { orig
651
660
  + (saved?.origin === router ? `A saved sign-in to ${router} is not used while the host provides one.\n` : ''), 'stdout');
652
661
  return;
653
662
  }
663
+ if (action === 'logout')
664
+ refuseInParentSettings(surface, 'logout');
654
665
  // Local removal must remain usable even if the stored JSON is corrupt.
655
666
  const credentials = action === 'logout' && options.includes('--local-only')
656
667
  ? await loadRouterCredentials().catch(() => null) : await loadRouterCredentials();
package/dist/session.js CHANGED
@@ -27,6 +27,7 @@ import { prepareSessionMedia } from './session_media.js';
27
27
  import { stripEphemeralMessages } from './utils/ephemeral.js';
28
28
  import { stripEphemeralToolPayloads } from './utils/ephemeral_tools.js';
29
29
  import { activeProfile } from './config/profiles.js';
30
+ import { liveCredentialValues } from './config/host_credentials.js';
30
31
  import { retainSessionForProcess, retainedSessionIds, withSessionCleanupBarrier } from './session_ownership.js';
31
32
  import { admitTaskHandoff, canonicalHandoffCwd, deriveTaskHandoff, taskHandoffFingerprints, TaskHandoffAdmissionError } from './session_handoff.js';
32
33
  import { projectTaskHandoff } from './session_handoff_contract.js';
@@ -1202,10 +1203,28 @@ async function retainManagedSessionFile(path) {
1202
1203
  await retainSessionForProcess(makeGlobalColonyStorage(getProjectHash(dirname(dirname(storage)))).sessionDir, id);
1203
1204
  }
1204
1205
  }
1206
+ const LOADED_SESSION_CHARACTERS = 32 * 1024 * 1024;
1207
+ const loadedSessions = new Map();
1208
+ function rememberLoadedSession(path, content, credentials, session) {
1209
+ loadedSessions.delete(path);
1210
+ if (content.length > LOADED_SESSION_CHARACTERS / 2)
1211
+ return;
1212
+ loadedSessions.set(path, { content, credentials, session: structuredClone(session) });
1213
+ let characters = 0;
1214
+ for (const entry of loadedSessions.values())
1215
+ characters += entry.content.length;
1216
+ for (const [oldest, entry] of loadedSessions) {
1217
+ if (characters <= LOADED_SESSION_CHARACTERS)
1218
+ break;
1219
+ characters -= entry.content.length;
1220
+ loadedSessions.delete(oldest);
1221
+ }
1222
+ }
1205
1223
  /** Load a managed session or an arbitrary file owned by an embedder. */
1206
1224
  export async function loadSessionFromFile(path, retain = true) {
1207
1225
  if (retain && existsSync(path))
1208
1226
  await retainManagedSessionFile(path);
1227
+ const key = resolve(path);
1209
1228
  let content;
1210
1229
  try {
1211
1230
  content = await readFile(path, 'utf-8');
@@ -1215,6 +1234,10 @@ export async function loadSessionFromFile(path, retain = true) {
1215
1234
  return null;
1216
1235
  throw new SessionLoadError(`Failed to read session file ${path}: ${err?.message || String(err)}`, 'unreadable', path, err);
1217
1236
  }
1237
+ const credentials = createHash('sha256').update(liveCredentialValues().join('\0')).digest('hex');
1238
+ const remembered = loadedSessions.get(key);
1239
+ if (remembered?.content === content && remembered.credentials === credentials)
1240
+ return structuredClone(remembered.session);
1218
1241
  let parsed;
1219
1242
  try {
1220
1243
  parsed = JSON.parse(content);
@@ -1232,7 +1255,9 @@ export async function loadSessionFromFile(path, retain = true) {
1232
1255
  throw new SessionLoadError(`Session file ${path} declares schemaVersion=${declaredVersion}; this ZTC build only understands up to v${SESSION_SCHEMA_VERSION}`, 'schema-mismatch', path);
1233
1256
  }
1234
1257
  try {
1235
- return normalizeLoadedSession(parsed, path);
1258
+ const session = normalizeLoadedSession(parsed, path);
1259
+ rememberLoadedSession(key, content, credentials, session);
1260
+ return session;
1236
1261
  }
1237
1262
  catch (error) {
1238
1263
  if (!(error instanceof TaskHandoffAdmissionError))
@@ -6,6 +6,8 @@
6
6
  * to bind a key (and optionally a fetch implementation) into the `ArtProvider`
7
7
  * shape the ArtService consumes.
8
8
  */
9
+ import { redactSentCredentials } from '../../agent/backends/http_error.js';
10
+ import { MODEL_REQUEST_REDIRECT, refuseModelRedirect } from '../../agent/backends/model_redirect.js';
9
11
  function extensionForMimeType(mimeType) {
10
12
  if (mimeType.includes('png'))
11
13
  return 'png';
@@ -18,11 +20,14 @@ function extensionForMimeType(mimeType) {
18
20
  export async function generateGeminiImage(prompt, model, apiKey, fetchImpl = fetch) {
19
21
  if (!apiKey)
20
22
  throw new Error('Missing Gemini API key');
21
- const response = await fetchImpl(`https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=${apiKey}`, {
23
+ // The key goes in x-goog-api-key, never in the URL; fetch would take that header on to where a redirect points, so a
24
+ // redirect is refused, and an answer that echoes the request has the key withheld.
25
+ const url = `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent`;
26
+ const headers = { 'Content-Type': 'application/json', 'x-goog-api-key': apiKey };
27
+ const response = await fetchImpl(url, {
22
28
  method: 'POST',
23
- headers: {
24
- 'Content-Type': 'application/json',
25
- },
29
+ headers,
30
+ redirect: MODEL_REQUEST_REDIRECT,
26
31
  body: JSON.stringify({
27
32
  contents: [
28
33
  {
@@ -35,9 +40,10 @@ export async function generateGeminiImage(prompt, model, apiKey, fetchImpl = fet
35
40
  },
36
41
  }),
37
42
  });
43
+ await refuseModelRedirect(response, url, headers);
38
44
  if (!response.ok) {
39
45
  const body = await response.text();
40
- throw new Error(`Gemini image request failed (${response.status}): ${body.slice(0, 240)}`);
46
+ throw new Error(`Gemini image request failed (${response.status}): ${redactSentCredentials(body, headers).slice(0, 240)}`);
41
47
  }
42
48
  const data = await response.json();
43
49
  const parts = data.candidates?.[0]?.content?.parts ?? [];
@@ -8,6 +8,7 @@
8
8
  * Builtin handlers (builtin:xlsx, etc.) provide reusable tool implementations.
9
9
  */
10
10
  import { parse as parseYaml } from 'yaml';
11
+ import { loadsExtensionFile } from '../../app/hosted_resident.js';
11
12
  import { extensionPathsFromEnvironment, isExplicitExtensionDiscovery, } from '../../extension_discovery.js';
12
13
  import { createRequire } from 'node:module';
13
14
  import { closeSync, openSync, readSync, readFileSync, existsSync } from 'node:fs';
@@ -39,6 +40,22 @@ function getNunjucksEnv() {
39
40
  export function renderTemplate(template, context) {
40
41
  return getNunjucksEnv().renderString(template, context);
41
42
  }
43
+ /**
44
+ * The loader of a domain's template_dir: nunjucks' FileSystemLoader, except that a template whose file a hosted
45
+ * resident's ZTC pane does not load (loadsExtensionFile) is not found, however it is asked for (a render, or another
46
+ * template's include, import or extends). The directory itself was checked, but a template in it may be a link into
47
+ * the workspace, where the agent writes, and a template runs code. What it read of a refused one is never compiled.
48
+ */
49
+ function extensionTemplateLoader(nunjucks, templateDir) {
50
+ const loader = new nunjucks.FileSystemLoader(templateDir);
51
+ const read = loader.getSource.bind(loader);
52
+ loader.getSource = (name) => {
53
+ const source = read(name);
54
+ // nunjucks' own answer for a template it does not find.
55
+ return (source === null || loadsExtensionFile(source.path) ? source : null);
56
+ };
57
+ return loader;
58
+ }
42
59
  /**
43
60
  * Load prompts from .j2 files in a template directory (FileSystemLoader)
44
61
  * or from inline strings in YAML. Matches zerg's PromptManager pattern.
@@ -48,8 +65,10 @@ function compilePrompts(raw, yamlDir) {
48
65
  // Same pattern as zerg/agent/prompt/templates/*.j2
49
66
  if (raw?.template_dir) {
50
67
  const templateDir = resolve(yamlDir, raw.template_dir);
68
+ if (!loadsExtensionFile(templateDir))
69
+ throw new Error(`Domain template directory ${templateDir} is not loaded here`);
51
70
  const nunjucks = loadNunjucks();
52
- const fileEnv = new nunjucks.Environment(new nunjucks.FileSystemLoader(templateDir), { autoescape: false, trimBlocks: true, lstripBlocks: true });
71
+ const fileEnv = new nunjucks.Environment(extensionTemplateLoader(nunjucks, templateDir), { autoescape: false, trimBlocks: true, lstripBlocks: true });
53
72
  return {
54
73
  render(name, context) {
55
74
  const fileName = name.endsWith('.j2') ? name : `${name}.j2`;
@@ -412,19 +431,22 @@ export function resolveDomainYamlPath(name) {
412
431
  return { yamlPath: null, tried: [] };
413
432
  const tried = [];
414
433
  for (const root of getDomainSearchRoots()) {
434
+ // A hosted resident's ZTC pane loads none whose real path is in its workspace (app/hosted_resident.ts).
415
435
  const dirPath = resolve(root, name, `${name}.yaml`);
416
436
  tried.push(dirPath);
417
- if (existsSync(dirPath))
437
+ if (existsSync(dirPath) && loadsExtensionFile(dirPath))
418
438
  return { yamlPath: dirPath, tried };
419
439
  const flatPath = resolve(root, `${name}.yaml`);
420
440
  tried.push(flatPath);
421
- if (existsSync(flatPath))
441
+ if (existsSync(flatPath) && loadsExtensionFile(flatPath))
422
442
  return { yamlPath: flatPath, tried };
423
443
  }
424
444
  return { yamlPath: null, tried };
425
445
  }
426
446
  export class DomainFactory {
427
447
  static loadData(path) {
448
+ if (!loadsExtensionFile(path))
449
+ throw new Error(`Owner domain ${path} is not loaded here`);
428
450
  const descriptor = openSync(path, 'r');
429
451
  const bytes = Buffer.alloc(1_048_577);
430
452
  let length = 0;
@@ -0,0 +1,23 @@
1
+ export type ColdRecord = {
2
+ id: string;
3
+ value: unknown;
4
+ };
5
+ export interface ColdStore {
6
+ park(record: ColdRecord): void;
7
+ has(id: string): boolean;
8
+ load(id: string): unknown | null;
9
+ parkMemory?(personId: string, memory: unknown): void;
10
+ }
11
+ export declare class MemoryColdStore implements ColdStore {
12
+ private readonly records;
13
+ private readonly memories;
14
+ park(record: ColdRecord): void;
15
+ has(id: string): boolean;
16
+ load(id: string): unknown | null;
17
+ parkMemory(personId: string, memory: unknown): void;
18
+ memoryCount(): number;
19
+ get size(): number;
20
+ ids(): string[];
21
+ snapshot(): ColdRecord[];
22
+ static from(records: readonly ColdRecord[]): MemoryColdStore;
23
+ }
@@ -0,0 +1,41 @@
1
+ export class MemoryColdStore {
2
+ records = new Map();
3
+ memories = new Map();
4
+ park(record) {
5
+ this.records.set(record.id, structuredClone(record.value));
6
+ }
7
+ has(id) {
8
+ return this.records.has(id);
9
+ }
10
+ load(id) {
11
+ if (!this.records.has(id))
12
+ return null;
13
+ return structuredClone(this.records.get(id));
14
+ }
15
+ parkMemory(personId, memory) {
16
+ const kept = this.memories.get(personId) ?? [];
17
+ kept.push(structuredClone(memory));
18
+ this.memories.set(personId, kept);
19
+ }
20
+ memoryCount() {
21
+ let total = 0;
22
+ for (const kept of this.memories.values())
23
+ total += kept.length;
24
+ return total;
25
+ }
26
+ get size() {
27
+ return this.records.size;
28
+ }
29
+ ids() {
30
+ return [...this.records.keys()].sort();
31
+ }
32
+ snapshot() {
33
+ return this.ids().map(id => ({ id, value: structuredClone(this.records.get(id)) }));
34
+ }
35
+ static from(records) {
36
+ const store = new MemoryColdStore();
37
+ for (const record of records)
38
+ store.park(record);
39
+ return store;
40
+ }
41
+ }