@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,100 @@
1
+ import { type LivingKindDefinition } from './open-world.js';
2
+ import { type LivingErrorCode } from './types.js';
3
+ import { type LivingCalendar } from './scale.js';
4
+ export declare function answerReach(speed: number): number;
5
+ type Beat = {
6
+ id: string;
7
+ placeId: string;
8
+ concerns?: string;
9
+ unless?: {
10
+ settled: string;
11
+ };
12
+ then?: {
13
+ tension?: {
14
+ id: string;
15
+ };
16
+ facts?: readonly {
17
+ aspect: string;
18
+ }[];
19
+ shifts?: readonly {
20
+ slot: string;
21
+ fromId: string | null;
22
+ toId: string | null;
23
+ }[];
24
+ };
25
+ };
26
+ type EntityChoices = {
27
+ placeIds: ReadonlySet<string>;
28
+ peopleIds: ReadonlySet<string>;
29
+ entityIds: ReadonlySet<string>;
30
+ objectIds: ReadonlySet<string>;
31
+ entityKinds: ReadonlyMap<string, string>;
32
+ tensionId: string;
33
+ };
34
+ type ReachDefinition = {
35
+ startClock: number;
36
+ calendar: LivingCalendar;
37
+ tension: {
38
+ id: string;
39
+ };
40
+ beats: readonly {
41
+ id: string;
42
+ inMinutes: number;
43
+ concerns?: string;
44
+ then?: {
45
+ tension?: {
46
+ id: string;
47
+ };
48
+ };
49
+ }[];
50
+ entities: readonly {
51
+ id: string;
52
+ kindId: string;
53
+ properties: Record<string, unknown>;
54
+ }[];
55
+ kinds: readonly LivingKindDefinition[];
56
+ sharedKinds: Record<string, LivingKindDefinition>;
57
+ };
58
+ type PaceDefinition = {
59
+ calendar: LivingCalendar;
60
+ clock?: {
61
+ rate: number;
62
+ };
63
+ };
64
+ type BeatChoices = {
65
+ aspects: readonly string[];
66
+ placeIds: ReadonlySet<string>;
67
+ thingIds: ReadonlySet<string>;
68
+ peopleIds: ReadonlySet<string>;
69
+ tensionId: string;
70
+ numberIds: ReadonlySet<string>;
71
+ holders: readonly {
72
+ id: string;
73
+ numbers: Record<string, number>;
74
+ }[];
75
+ };
76
+ export declare function choiceText(label: string, values: Iterable<string>, declarePath: string, removePath: string): string;
77
+ export declare function checkKindDefinition(kind: LivingKindDefinition, kindIds: ReadonlySet<string>, channelIds: ReadonlySet<string>, path: string, code: LivingErrorCode): void;
78
+ export declare function checkEntityProperties(entity: {
79
+ id: string;
80
+ kindId: string;
81
+ properties: Record<string, unknown>;
82
+ relations: Record<string, string>;
83
+ }, kind: LivingKindDefinition, path: string, choices: EntityChoices, code: LivingErrorCode): void;
84
+ export declare function checkBeat(happening: Beat, path: string, choices: BeatChoices): void;
85
+ export declare function worldRuleLines(): string[];
86
+ export declare function checkAnswerPace(definition: PaceDefinition): void;
87
+ export declare function checkSessionReach(definition: ReachDefinition): void;
88
+ export declare function definitionProblem(path: string, value: unknown, problem: string, valid: string): never;
89
+ export declare function checkDistinctIds(items: readonly {
90
+ id: string;
91
+ path: string;
92
+ }[], label: string, declarePath: string): void;
93
+ export declare function checkCalendar(calendar: {
94
+ day: number;
95
+ rest: {
96
+ from: number;
97
+ until: number;
98
+ } | null;
99
+ }): void;
100
+ export {};
@@ -0,0 +1,267 @@
1
+ import { lawProblems, levelSchema, valueMatchesType } from './open-world.js';
2
+ import { LivingWorldError } from './types.js';
3
+ import { phrase } from './phrases.js';
4
+ import { PACING, clockLabel, pace } from './scale.js';
5
+ import { LIVING_ANSWER_BUDGET_MS } from './inference.js';
6
+ export function answerReach(speed) {
7
+ return Math.floor(LIVING_ANSWER_BUDGET_MS * speed / 60_000);
8
+ }
9
+ const ID_TYPE = 'id';
10
+ const AT_TYPE = 'time';
11
+ const TENSION_TARGET = 'tension';
12
+ export function choiceText(label, values, declarePath, removePath) {
13
+ const items = [...values];
14
+ if (items.length === 0)
15
+ return phrase('definition.noChoices', { label, declare: declarePath, remove: removePath });
16
+ return phrase('definition.choices', { label, values: items.join(',') });
17
+ }
18
+ function typeChoices(type) {
19
+ switch (type) {
20
+ case 'flag': return phrase('choices.flag');
21
+ case 'level': return choiceText(phrase('definition.label.levels'), levelSchema.options, 'property', 'property');
22
+ case 'number': return phrase('choices.number');
23
+ case 'time': return phrase('choices.time');
24
+ case 'id': return phrase('choices.id');
25
+ case 'text': return phrase('choices.text');
26
+ case 'series': return phrase('choices.series');
27
+ default: return phrase('choices.any');
28
+ }
29
+ }
30
+ function referenceCategory(value, choices) {
31
+ if (choices.peopleIds.has(value))
32
+ return phrase('definition.category.person');
33
+ if (choices.placeIds.has(value))
34
+ return phrase('definition.category.place');
35
+ if (choices.objectIds.has(value))
36
+ return phrase('definition.category.object');
37
+ if (value === choices.tensionId)
38
+ return phrase('definition.category.problem');
39
+ return null;
40
+ }
41
+ function referenceForm(kind, kindPath, entityPath, value, category) {
42
+ const properties = kind.properties;
43
+ const idProperty = properties.find(property => property.type === ID_TYPE && (property.target !== TENSION_TARGET || category === phrase('definition.category.problem')));
44
+ if (idProperty !== undefined) {
45
+ return phrase('definition.referenceForm.use', { propertyId: idProperty.id, kind: kind.id, kindPath, entityPath, value });
46
+ }
47
+ return phrase('definition.referenceForm.add', { kind: kind.id, kindPath, entityPath, value });
48
+ }
49
+ function referenceMessage(fieldPath, entityPath, kindPath, kind, value, category, required) {
50
+ return phrase('definition.referenceCategory', { value, category, path: fieldPath, required, form: referenceForm(kind, kindPath, entityPath, value, category), removePath: fieldPath });
51
+ }
52
+ function mechanicPath(path, index) {
53
+ return `${path}.mechanics[${index}]`;
54
+ }
55
+ export function checkKindDefinition(kind, kindIds, channelIds, path, code) {
56
+ const properties = kind.properties;
57
+ const relations = kind.relations;
58
+ const propertyIds = new Set(properties.map(property => property.id));
59
+ const relationIds = new Set(relations.map(relation => relation.id));
60
+ if (propertyIds.size !== properties.length || relationIds.size !== relations.length) {
61
+ throw new LivingWorldError(code, `${path}: kind "${kind.id}" repeats a slot id; ${choiceText(phrase('definition.label.properties'), propertyIds, `${path}.properties`, path)}; ${choiceText(phrase('definition.label.relations'), relationIds, `${path}.relations`, path)}`);
62
+ }
63
+ for (const [index, relation] of relations.entries()) {
64
+ if (relation.targetKindId !== kind.id && !kindIds.has(relation.targetKindId)) {
65
+ throw new LivingWorldError(code, `${path}.relations[${index}].targetKindId: "${relation.targetKindId}" is not a kind in this world; ${choiceText(phrase('definition.label.kinds'), kindIds, 'kinds', `${path}.relations[${index}]`)}`);
66
+ }
67
+ }
68
+ for (const [index, mechanic] of kind.mechanics.entries()) {
69
+ const at = mechanicPath(path, index);
70
+ if ('channel' in mechanic && !channelIds.has(mechanic.channel)) {
71
+ throw new LivingWorldError(code, `${at}.channel: "${mechanic.channel}" is not a channel of this world; ${choiceText(phrase('definition.label.channels'), channelIds, 'channels', at)}`);
72
+ }
73
+ const propertyId = 'propertyId' in mechanic ? mechanic.propertyId : null;
74
+ const relationId = 'relationId' in mechanic ? mechanic.relationId : null;
75
+ const targetProperty = propertyId === null ? undefined : properties.find(property => property.id === propertyId);
76
+ if (propertyId !== null && !propertyIds.has(propertyId)) {
77
+ throw new LivingWorldError(code, `${at}.propertyId: "${propertyId}" is not a property of kind "${kind.id}"; ${choiceText(phrase('definition.label.properties'), properties.map(property => `${property.id}:${property.type}`), `${path}.properties`, at)}`);
78
+ }
79
+ if (relationId !== null && !relationIds.has(relationId)) {
80
+ throw new LivingWorldError(code, `${at}.relationId: "${relationId}" is not a relation of kind "${kind.id}"; ${choiceText(phrase('definition.label.relations'), relationIds, `${path}.relations`, at)}`);
81
+ }
82
+ if ('relationId' in mechanic && !('channel' in mechanic) && targetProperty?.type !== 'level') {
83
+ throw new LivingWorldError(code, `${at}.propertyId: "${mechanic.propertyId}" has type "${targetProperty?.type ?? 'missing'}"; a spread rule needs a level property; ${choiceText(phrase('definition.label.levelProperties'), properties.filter(property => property.type === 'level').map(property => property.id), `${path}.properties`, at)}`);
84
+ }
85
+ if ('deltaPerMinute' in mechanic) {
86
+ if (mechanic.onEvent) {
87
+ if (mechanic.deltaPerMinute !== 0) {
88
+ throw new LivingWorldError(code, `${at}.deltaPerMinute: ${mechanic.deltaPerMinute} is not 0; an event change needs deltaPerMinute 0`);
89
+ }
90
+ if (targetProperty === undefined) {
91
+ throw new LivingWorldError(code, `${at}.propertyId: "${mechanic.propertyId}" is not a property of kind "${kind.id}"; ${choiceText(phrase('definition.label.properties'), properties.map(property => `${property.id}:${property.type}`), `${path}.properties`, at)}`);
92
+ }
93
+ if (!valueMatchesType(targetProperty.type, mechanic.onEvent.value)) {
94
+ throw new LivingWorldError(code, `${at}.onEvent.value: ${JSON.stringify(mechanic.onEvent.value)} is not a ${targetProperty.type} value; ${typeChoices(targetProperty.type)}`);
95
+ }
96
+ const subject = properties.find(property => property.id === mechanic.onEvent.subjectPropertyId);
97
+ if (subject?.type !== 'id') {
98
+ throw new LivingWorldError(code, `${at}.onEvent.subjectPropertyId: "${mechanic.onEvent.subjectPropertyId}" has type "${subject?.type ?? 'missing'}"; an event change needs an id property; ${choiceText(phrase('definition.label.idProperties'), properties.filter(property => property.type === 'id').map(property => property.id), `${path}.properties`, at)}`);
99
+ }
100
+ }
101
+ else if (targetProperty?.type !== 'number') {
102
+ throw new LivingWorldError(code, `${at}.propertyId: "${mechanic.propertyId}" has type "${targetProperty?.type ?? 'missing'}"; a change rule needs a number property; ${choiceText(phrase('definition.label.numberProperties'), properties.filter(property => property.type === 'number').map(property => property.id), `${path}.properties`, at)}`);
103
+ }
104
+ }
105
+ }
106
+ for (const [index, law] of (kind.laws ?? []).entries()) {
107
+ const problems = lawProblems(law, kind);
108
+ if (problems.length > 0)
109
+ throw new LivingWorldError(code, `${path}.laws[${index}]: ${problems.join('; ')}`);
110
+ }
111
+ }
112
+ export function checkEntityProperties(entity, kind, path, choices, code) {
113
+ const properties = kind.properties;
114
+ const relations = kind.relations;
115
+ for (const [propertyId, value] of Object.entries(entity.properties)) {
116
+ const property = properties.find(candidate => candidate.id === propertyId);
117
+ if (property === undefined) {
118
+ throw new LivingWorldError(code, `${path}.properties.${propertyId}: kind "${kind.id}" has no property "${propertyId}"; ${choiceText(phrase('definition.label.properties'), properties.map(property => `${property.id}:${property.type}`), `kinds.${kind.id}.properties`, `${path}.properties.${propertyId}`)}`);
119
+ }
120
+ if (!valueMatchesType(property.type, value)) {
121
+ throw new LivingWorldError(code, `${path}.properties.${propertyId}: ${JSON.stringify(value)} is not a ${property.type} value; ${typeChoices(property.type)}`);
122
+ }
123
+ if (property.type === 'id') {
124
+ const valid = new Set([...choices.placeIds, ...choices.peopleIds, ...choices.entityIds, ...choices.objectIds, ...(property.target === 'tension' ? [choices.tensionId] : [])]);
125
+ if (!valid.has(String(value))) {
126
+ throw new LivingWorldError(code, `${path}.properties.${propertyId}: "${String(value)}" is not a known id; ${choiceText(phrase('definition.label.ids'), valid, 'places,player,cast,objects,entities,tension', `${path}.properties.${propertyId}`)}`);
127
+ }
128
+ }
129
+ }
130
+ for (const [relationId, targetId] of Object.entries(entity.relations)) {
131
+ const relation = relations.find(candidate => candidate.id === relationId);
132
+ if (relation === undefined) {
133
+ throw new LivingWorldError(code, `${path}.relations.${relationId}: kind "${kind.id}" has no relation "${relationId}"; ${choiceText(phrase('definition.label.relations'), relations.map(candidate => candidate.id), `kinds.${kind.id}.relations`, `${path}.relations.${relationId}`)}`);
134
+ }
135
+ const targetKind = choices.entityKinds.get(targetId);
136
+ if (targetKind === undefined) {
137
+ const category = referenceCategory(targetId, choices);
138
+ if (category !== null) {
139
+ throw new LivingWorldError(code, `${path}.relations.${relationId}: ${referenceMessage(`${path}.relations.${relationId}`, path, `kinds.${kind.id}`, kind, targetId, category, phrase('definition.label.entities'))}`);
140
+ }
141
+ throw new LivingWorldError(code, `${path}.relations.${relationId}: target "${targetId}" is not an entity of this world; ${choiceText(phrase('definition.label.entities'), choices.entityIds, 'entities', `${path}.relations.${relationId}`)}`);
142
+ }
143
+ if (targetKind !== relation.targetKindId) {
144
+ throw new LivingWorldError(code, `${path}.relations.${relationId}: target "${targetId}" has kind "${targetKind}"; relation "${relationId}" needs a "${relation.targetKindId}"`);
145
+ }
146
+ }
147
+ }
148
+ export function checkBeat(happening, path, choices) {
149
+ const suffix = phrase('message.beat', { id: happening.id });
150
+ if (!choices.placeIds.has(happening.placeId)) {
151
+ throw new LivingWorldError('definition-invalid', `${path}.placeId: "${happening.placeId}" is not a place of this world; ${choiceText(phrase('definition.label.places'), choices.placeIds, 'places', path)}${suffix}`);
152
+ }
153
+ if (happening.concerns !== undefined && !choices.thingIds.has(happening.concerns) && !choices.peopleIds.has(happening.concerns)
154
+ && !choices.placeIds.has(happening.concerns) && happening.concerns !== choices.tensionId) {
155
+ throw new LivingWorldError('definition-invalid', `${path}.concerns: "${happening.concerns}" is not a thing, person, place or problem of this world; ${choiceText(phrase('definition.label.concerns'), [...choices.thingIds, ...choices.peopleIds, ...choices.placeIds, choices.tensionId], 'objects,entities,player,cast,places,tension', `${path}.concerns`)}${suffix}`);
156
+ }
157
+ if (happening.unless !== undefined && happening.unless.settled !== choices.tensionId) {
158
+ throw new LivingWorldError('definition-invalid', `${path}.unless.settled: "${happening.unless.settled}" is not this world's problem; valid problem: ${choices.tensionId}${suffix}`);
159
+ }
160
+ if (happening.then?.tension !== undefined && happening.then.tension.id !== choices.tensionId) {
161
+ throw new LivingWorldError('definition-invalid', `${path}.then.tension.id: "${happening.then.tension.id}" is not this world's problem; valid problem: ${choices.tensionId}${suffix}`);
162
+ }
163
+ for (const [index, fact] of (happening.then?.facts ?? []).entries()) {
164
+ if (!choices.aspects.includes(fact.aspect)) {
165
+ throw new LivingWorldError('definition-invalid', `${path}.then.facts[${index}].aspect: "${fact.aspect}" is not a fact aspect of this world; ${choiceText(phrase('definition.label.aspects'), choices.aspects, 'facts', `${path}.then.facts[${index}]`)}${suffix}`);
166
+ }
167
+ }
168
+ for (const [index, shift] of (happening.then?.shifts ?? []).entries()) {
169
+ if (!choices.numberIds.has(shift.slot)) {
170
+ throw new LivingWorldError('definition-invalid', `${path}.then.shifts[${index}].slot: "${shift.slot}" is not a number slot of this world; ${choiceText(phrase('definition.label.numberSlots'), choices.numberIds, 'numbers', `${path}.then.shifts[${index}]`)}${suffix}`);
171
+ }
172
+ for (const [side, end] of [['fromId', shift.fromId], ['toId', shift.toId]]) {
173
+ if (end === null)
174
+ continue;
175
+ const holder = choices.holders.find(candidate => candidate.id === end);
176
+ if (holder === undefined) {
177
+ throw new LivingWorldError('definition-invalid', `${path}.then.shifts[${index}].${side}: "${end}" is not a holder of this world; ${choiceText(phrase('definition.label.holders'), choices.holders.map(candidate => candidate.id), 'player,cast,places,entities', `${path}.then.shifts[${index}]`)}${suffix}`);
178
+ }
179
+ if (holder.numbers[shift.slot] === undefined) {
180
+ throw new LivingWorldError('definition-invalid', `${path}.then.shifts[${index}].${side}: "${end}" holds no amount of "${shift.slot}"; ${choiceText(phrase('definition.label.holders'), choices.holders.filter(candidate => candidate.numbers[shift.slot] !== undefined).map(candidate => candidate.id), 'player,cast,places,entities', `${path}.then.shifts[${index}]`)}${suffix}`);
181
+ }
182
+ }
183
+ }
184
+ }
185
+ export function worldRuleLines() {
186
+ return [
187
+ phrase('rule.factAspect'),
188
+ phrase('rule.changeNumber'),
189
+ phrase('rule.levelValue'),
190
+ phrase('rule.relationTarget'),
191
+ phrase('rule.spreadLevel'),
192
+ phrase('rule.signalChannel'),
193
+ phrase('rule.eventChange'),
194
+ phrase('rule.entityProperty'),
195
+ phrase('rule.entityRelation'),
196
+ phrase('rule.sessionReach', { reach: PACING.sessionReach }),
197
+ phrase('rule.answerBudget', { budgetMs: answerBudgetMs() }),
198
+ ];
199
+ }
200
+ function answerBudgetMs() {
201
+ return LIVING_ANSWER_BUDGET_MS;
202
+ }
203
+ function units() {
204
+ return 60_000;
205
+ }
206
+ export function checkAnswerPace(definition) {
207
+ if (definition.clock === undefined)
208
+ return;
209
+ const x = definition.calendar.beat * units() / definition.clock.rate;
210
+ const allowed = answerBudgetMs();
211
+ if (answerReach(definition.clock.rate) >= definition.calendar.beat)
212
+ return;
213
+ throw new LivingWorldError('definition-invalid', phrase('definition.answerPace', { a: definition.calendar.beat, b: definition.clock.rate, c: Math.round(x), d: allowed }));
214
+ }
215
+ export function checkSessionReach(definition) {
216
+ const tension = definition.tension.id;
217
+ const reach = pace(definition.calendar, 'sessionReach');
218
+ const reachLabel = clockLabel(definition.calendar, definition.startClock + reach);
219
+ const moments = [];
220
+ definition.beats.forEach((moment, index) => {
221
+ if (moment.concerns === tension || moment.then?.tension?.id === tension) {
222
+ moments.push({ at: moment.inMinutes, path: `beats[${index}]`, label: phrase('definition.beatLabel', { id: moment.id }) });
223
+ }
224
+ });
225
+ definition.entities.forEach((entity, index) => {
226
+ const kind = definition.kinds.find(candidate => candidate.id === entity.kindId) ?? definition.sharedKinds[entity.kindId];
227
+ if (kind === undefined)
228
+ return;
229
+ const properties = kind.properties;
230
+ const settles = properties.find(property => property.type === ID_TYPE && property.target === TENSION_TARGET);
231
+ const closes = properties.find(property => property.type === AT_TYPE);
232
+ if (settles === undefined || closes === undefined)
233
+ return;
234
+ const settlesValue = entity.properties[settles.id];
235
+ const closesValue = entity.properties[closes.id];
236
+ if (settlesValue === tension && Number.isFinite(closesValue)) {
237
+ moments.push({ at: Number(closesValue) - definition.startClock, path: `entities[${index}]`, label: phrase('definition.entityLabel', { id: entity.id }) });
238
+ }
239
+ });
240
+ moments.sort((left, right) => left.at - right.at);
241
+ const first = moments[0];
242
+ if (first === undefined)
243
+ throw new LivingWorldError('definition-invalid', phrase('definition.sessionReachMissing', { reach, reachLabel }));
244
+ if (first.at <= reach)
245
+ return;
246
+ throw new LivingWorldError('definition-invalid', phrase('definition.sessionReachBeyond', { path: first.path, label: first.label, at: first.at, atLabel: clockLabel(definition.calendar, definition.startClock + first.at), reach, reachLabel }));
247
+ }
248
+ export function definitionProblem(path, value, problem, valid) {
249
+ throw new LivingWorldError('definition-invalid', `${path}: ${JSON.stringify(value)} ${problem}; ${valid}`);
250
+ }
251
+ export function checkDistinctIds(items, label, declarePath) {
252
+ const seen = new Set();
253
+ for (const item of items) {
254
+ if (seen.has(item.id))
255
+ definitionProblem(item.path, item.id, phrase('definition.repeatsId', { label }), phrase('definition.distinctIds', { label, ids: choiceText(label, seen, declarePath, item.path) }));
256
+ seen.add(item.id);
257
+ }
258
+ }
259
+ export function checkCalendar(calendar) {
260
+ if (calendar.rest === null)
261
+ return;
262
+ const last = calendar.day - 1;
263
+ if (calendar.rest.from >= calendar.day)
264
+ definitionProblem('calendar.rest.from', calendar.rest.from, phrase('definition.notWithinDay'), phrase('definition.restRange', { count: calendar.day, last }));
265
+ if (calendar.rest.until >= calendar.day)
266
+ definitionProblem('calendar.rest.until', calendar.rest.until, phrase('definition.notWithinDay'), phrase('definition.restRange', { count: calendar.day, last }));
267
+ }
@@ -46,6 +46,7 @@ import { homedir } from 'node:os';
46
46
  import { dirname, isAbsolute, join, resolve } from 'node:path';
47
47
  import { pathToFileURL } from 'node:url';
48
48
  import { parse as parseYaml } from 'yaml';
49
+ import { loadsExtensionFile } from '../../app/hosted_resident.js';
49
50
  import { extensionPathsFromEnvironment, isExplicitExtensionDiscovery, } from '../../extension_discovery.js';
50
51
  import { createStagedZtcPluginContext, runtimePluginRegistry, } from '../../plugin/runtime_registry.js';
51
52
  export const ZTC_PLUGIN_API_VERSION = '1';
@@ -125,6 +126,9 @@ const SCAN_SKIP = new Set([
125
126
  function readManifest(manifestPath) {
126
127
  if (!existsSync(manifestPath))
127
128
  return undefined;
129
+ // A hosted resident's ZTC pane loads none whose real path is in its workspace (app/hosted_resident.ts).
130
+ if (!loadsExtensionFile(manifestPath))
131
+ return undefined;
128
132
  try {
129
133
  const raw = parseYaml(readFileSync(manifestPath, 'utf-8'));
130
134
  if (!raw?.name) {
@@ -264,6 +268,8 @@ async function loadPlugin(plugin) {
264
268
  pluginDebug(`[ztc/plugins] ${plugin.manifest.name}: optional module not found at ${abs}`);
265
269
  continue;
266
270
  }
271
+ if (!loadsExtensionFile(abs))
272
+ continue;
267
273
  try {
268
274
  await import(pathToFileURL(abs).href);
269
275
  }
@@ -286,6 +292,11 @@ async function loadPlugin(plugin) {
286
292
  pluginDebug(`[ztc/plugins] ${plugin.manifest.name}: optional ztc_plugin module not found at ${abs}`);
287
293
  return;
288
294
  }
295
+ if (!loadsExtensionFile(abs)) {
296
+ if (m.ztc_plugin.required === true)
297
+ throw new Error(`artifact ${abs} is not loaded here`);
298
+ return;
299
+ }
289
300
  try {
290
301
  const mod = await import(pathToFileURL(abs).href);
291
302
  if (typeof mod.activate !== 'function') {
@@ -1,6 +1,7 @@
1
1
  import { homedir } from 'os';
2
2
  import { join, resolve, basename } from 'path';
3
3
  import { readdir, readFile } from 'fs/promises';
4
+ import { loadsExtensionFile } from '../app/hosted_resident.js';
4
5
  import { debugLog } from '../debug/logger.js';
5
6
  import { extensionPathsFromEnvironment, isExplicitExtensionDiscovery, } from '../extension_discovery.js';
6
7
  const MAX_DEPTH = 4;
@@ -179,6 +180,9 @@ export async function loadSkills(roots = defaultMarkdownRoots()) {
179
180
  if (seenFiles.has(filePath))
180
181
  continue;
181
182
  seenFiles.add(filePath);
183
+ // A hosted resident's ZTC pane loads none whose real path is in its workspace (app/hosted_resident.ts).
184
+ if (!loadsExtensionFile(filePath))
185
+ continue;
182
186
  try {
183
187
  const content = await readFile(filePath, 'utf-8');
184
188
  const { meta, body } = parseFrontmatter(content);
package/dist/tools.d.ts CHANGED
@@ -2,5 +2,6 @@ import type { Tool } from './agent/tools/types.js';
2
2
  export type { Tool, ToolContext } from './agent/tools/types.js';
3
3
  export { ToolCapability } from './agent/runtime/capabilities.js';
4
4
  export type { ToolEffectKind } from './agent/runtime/tool_effects.js';
5
+ export { declareOutcomeTool } from './agent/tools/outcome.js';
5
6
  export declare function defaultTools(): Tool[];
6
7
  export declare function selectTools(names: Iterable<string>): Tool[];
package/dist/tools.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { defaultTools as cliTools } from './agent/tools/index.js';
2
2
  export { ToolCapability } from './agent/runtime/capabilities.js';
3
+ export { declareOutcomeTool } from './agent/tools/outcome.js';
3
4
  export function defaultTools() {
4
5
  return [...cliTools];
5
6
  }
@@ -26,7 +26,10 @@ export declare function encodeZtcPaneInput(input: string): string;
26
26
  * panes and colony cells as a pair, both or neither, and no other pane. So
27
27
  * does the host's Router runtime grant, with the Router it names
28
28
  * (hostRouterGrantForZtcChild), when it takes effect: merged last, so no
29
- * `commandEnv` sends it elsewhere.
29
+ * `commandEnv` sends it elsewhere. Where ZTC runs as its host's or under its
30
+ * host's pin, a pane that is not a ZTC is given no ZergAI platform or Zerg
31
+ * Router bearer from its `commandEnv` either, nor a variable holding one's
32
+ * value (withoutWithheldBearers), as a user subprocess is given none.
30
33
  */
31
34
  export declare function computePaneSpawnEnv(paneType: string, paneId: number, options?: {
32
35
  persona?: string;
@@ -19,9 +19,10 @@ import { accessSync, chmodSync, constants, existsSync, statSync } from 'fs';
19
19
  import { delimiter, dirname, isAbsolute, join, resolve } from 'path';
20
20
  import { createRequire } from 'module';
21
21
  import { isMuxPaneRestorable, resolveMuxPersistenceOptions, sanitizeMuxSessionState, validateWorkspaceState } from './mux_persistence.js';
22
- import { buildUserSubprocessEnv, hostRouterGrantForZtcChild, removeUserSubprocessCredentials, restoreHostEffortPolicy, restoreModelRouteCredentials, withoutZtcCredentials } from '../../utils/subprocess_env.js';
22
+ import { buildUserSubprocessEnv, hostRouterGrantForZtcChild, removeUserSubprocessCredentials, restoreHostEffortPolicy, restoreModelRouteCredentials, withoutWithheldBearers, withoutZtcCredentials } from '../../utils/subprocess_env.js';
23
23
  import { hostLaunchEnvironment } from '../../config/host_credentials.js';
24
24
  import { isZtcLaunchTrusted, PaneCredentialBroker } from './pane_credential_broker.js';
25
+ import { createdPaneType } from './pane_type.js';
25
26
  import { handleWorkspaceLayout } from '../../workspace_layout.js';
26
27
  let _ptyMod;
27
28
  function loadPty() {
@@ -122,7 +123,10 @@ export function encodeZtcPaneInput(input) {
122
123
  * panes and colony cells as a pair, both or neither, and no other pane. So
123
124
  * does the host's Router runtime grant, with the Router it names
124
125
  * (hostRouterGrantForZtcChild), when it takes effect: merged last, so no
125
- * `commandEnv` sends it elsewhere.
126
+ * `commandEnv` sends it elsewhere. Where ZTC runs as its host's or under its
127
+ * host's pin, a pane that is not a ZTC is given no ZergAI platform or Zerg
128
+ * Router bearer from its `commandEnv` either, nor a variable holding one's
129
+ * value (withoutWithheldBearers), as a user subprocess is given none.
126
130
  */
127
131
  export function computePaneSpawnEnv(paneType, paneId, options = {}, ownEnvironment = process.env) {
128
132
  // This process's environment as ZTC was started with it: the host-credential store holds ZTC's credentials, and a
@@ -141,7 +145,7 @@ export function computePaneSpawnEnv(paneType, paneId, options = {}, ownEnvironme
141
145
  const childEnv = removeUserSubprocessCredentials(env);
142
146
  return paneType === 'ztc'
143
147
  ? { ...restoreHostEffortPolicy(restoreModelRouteCredentials(childEnv, parent), parent), ...hostRouterGrantForZtcChild(source) }
144
- : childEnv;
148
+ : withoutWithheldBearers(childEnv, ownEnvironment);
145
149
  }
146
150
  /**
147
151
  * Inverse of encodeZtcPaneInput: recover the original input from a stdin line a
@@ -474,12 +478,12 @@ export class HeadlessPaneManager {
474
478
  const title = cmd.title || cmd.command;
475
479
  const args = cmd.args || [];
476
480
  const cwd = cmd.cwd || process.cwd();
477
- // Detect whether this is a ZTC child or a generic process. A pane a child asks for through the relay is a ZTC pane
478
- // only on a launch nonce the relay issued it (ztc_launch_trust.ts), whatever its type or arguments say.
479
- const trusted = isZtcLaunchTrusted(cmd);
480
- const isZtc = trusted && (args[0] === '--ztc-cli' || args.some(a => /cli_(main|ratatui)\.(js|ts)$/.test(a))) && args.includes('--pane');
481
- const declaredType = cmd.pane_type || (isZtc ? 'ztc' : 'process');
482
- const paneType = !trusted && isZtcPaneType(declaredType) ? 'process' : declaredType;
481
+ // Detect whether this is a ZTC child or a generic process: the type the command names, else 'ztc' for a ZTC launch,
482
+ // else 'process' (createdPaneType, as a hosted resident types the panes its agent's tools ask for). A pane a child
483
+ // asks for through the relay is a ZTC pane only on a launch nonce the relay issued it (ztc_launch_trust.ts), whatever
484
+ // its type or arguments say.
485
+ const declaredType = createdPaneType(cmd);
486
+ const paneType = !isZtcLaunchTrusted(cmd) && isZtcPaneType(declaredType) ? 'process' : declaredType;
483
487
  const groupId = cmd.env?.ZTC_MIRROR_GROUP || '';
484
488
  // Reuse the shared env builder (dev's computePaneSpawnEnv) — behaviourally
485
489
  // identical to the old inline childEnv. The actual spawn (PTY-aware) lives
@@ -16,6 +16,7 @@ import { serializeCommand, parseEvent, CAPABILITY_PANE_DELIVERY_ACK, CAPABILITY_
16
16
  import { hostCredential, ROUTER_RUNTIME_GRANT_ENV, withoutHostHandoff } from '../../config/host_credentials.js';
17
17
  import { withoutExtensionRootFlags } from '../../extension_discovery.js';
18
18
  import { throughMotsi } from '../../panes/motsi.js';
19
+ import { personOnlyPaneRefusal, personOnlyProgramRefusal } from '../../panes/person_only_panes.js';
19
20
  import { debugLog, runtimeDiag } from '../../utils/debug_log.js';
20
21
  import { onProcessEnd } from '../../utils/process_end.js';
21
22
  import { ztcChildDiscoversExplicitly } from '../../utils/subprocess_env.js';
@@ -51,6 +52,24 @@ function isLaunchNonceRequest(value) {
51
52
  function isZtcPaneType(paneType) {
52
53
  return paneType === 'ztc' || paneType === 'colony_ztc';
53
54
  }
55
+ /**
56
+ * The answer to a child's COMMAND that would type into, restart or replace a pane only the person drives, or start that
57
+ * CLI in a pane of its own (person_only_panes.ts); null for anything else. A write is answered as the renderer answers
58
+ * one it didn't deliver, so the child's tool says why.
59
+ */
60
+ function personOnlyAnswer(command) {
61
+ const requestId = 'request_id' in command && typeof command.request_id === 'string' ? { request_id: command.request_id } : {};
62
+ if (command.type === 'write_pane') {
63
+ const refused = personOnlyPaneRefusal(command.pane_id, 'type');
64
+ return refused ? { type: 'pane_write_result', pane_id: command.pane_id, delivered: false, error: refused, ...requestId } : null;
65
+ }
66
+ const refused = command.type === 'restart_pane' ? personOnlyPaneRefusal(command.pane_id, 'restart')
67
+ : command.type === 'replace_pane' ? personOnlyPaneRefusal(command.pane_id, 'replace')
68
+ ?? (command.command ? personOnlyProgramRefusal(command.command, command.args ?? []) : null)
69
+ : command.type === 'create_pane' ? personOnlyProgramRefusal(command.command, command.args ?? [])
70
+ : null;
71
+ return refused ? { type: 'error', message: refused, ...requestId } : null;
72
+ }
54
73
  /** The relays bound or listening in this process, which stop as it ends (stopListeningRelaysAtExit). */
55
74
  const listeningRelays = new Set();
56
75
  let stopsRelaysAtExit = false;
@@ -273,6 +292,16 @@ export class PaneRelayServer {
273
292
  return;
274
293
  }
275
294
  }
295
+ // A pane only the person drives (Antigravity's) takes no child's typing, restart or replacement, and no child starts
296
+ // its CLI (person_only_panes.ts): answered here, to this child alone, saying why; the renderer is never asked.
297
+ const personOnly = personOnlyAnswer(verdict.command);
298
+ if (personOnly) {
299
+ try {
300
+ client.write(JSON.stringify(personOnly) + '\n');
301
+ }
302
+ catch { /* the close handler retires this client */ }
303
+ return;
304
+ }
276
305
  // A pane a child opens or relaunches is a ZTC pane only on a launch nonce this relay issued it; else a process
277
306
  // pane (launchTrust). A nonce it was not issued for opens nothing.
278
307
  const launch = this.launchTrust(client, verdict.command);
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The type the headless pane manager gives a pane it is asked to create (HeadlessPaneManager.handleCreatePane): the one
3
+ * the command names, else 'ztc' for a ZTC launch with --pane (its first argument --ztc-cli, or a cli_main or cli_ratatui
4
+ * .js or .ts among its arguments), else 'process'. A hosted resident types the panes its agent's tools ask for the same
5
+ * way (hostedResidentAgentPaneTransport), so no pane is a ZTC pane to the one and not to the other.
6
+ */
7
+ export declare function createdPaneType(command: {
8
+ pane_type?: string;
9
+ args?: string[];
10
+ }): string;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The type the headless pane manager gives a pane it is asked to create (HeadlessPaneManager.handleCreatePane): the one
3
+ * the command names, else 'ztc' for a ZTC launch with --pane (its first argument --ztc-cli, or a cli_main or cli_ratatui
4
+ * .js or .ts among its arguments), else 'process'. A hosted resident types the panes its agent's tools ask for the same
5
+ * way (hostedResidentAgentPaneTransport), so no pane is a ZTC pane to the one and not to the other.
6
+ */
7
+ export function createdPaneType(command) {
8
+ const args = command.args || [];
9
+ const isZtc = (args[0] === '--ztc-cli' || args.some(arg => /cli_(main|ratatui)\.(js|ts)$/.test(arg))) && args.includes('--pane');
10
+ return command.pane_type || (isZtc ? 'ztc' : 'process');
11
+ }
@@ -123,6 +123,12 @@ export declare class TuiProcess {
123
123
  private _muxMode;
124
124
  /** Whether zterm is being used as the native desktop renderer */
125
125
  private _desktopMode;
126
+ /** Whether this owner attached to an already-running ZTerm via `owner_reattach_v1`. */
127
+ private _reattached;
128
+ /** True while detaching cleanly for an in-situ owner handoff (never send shutdown / unlink socket / SIGTERM zterm). */
129
+ private detachingForReattach;
130
+ /** First-line reattach token waiting to be written immediately upon socket connect. */
131
+ private pendingReattachToken;
126
132
  private desktopCompatibility;
127
133
  /** Retained across socket cleanup so an admitted renderer can request owner exit. */
128
134
  private desktopStartupAdmitted;
@@ -211,6 +217,12 @@ export declare class TuiProcess {
211
217
  * (non-zmux mode, bind failed, or announcement not received yet).
212
218
  */
213
219
  get zmuxMirrorSocketPath(): string | null;
220
+ /** Whether this owner reattached to an existing ZTerm instance. */
221
+ get isReattached(): boolean;
222
+ /** Active Unix socket path for the current renderer connection. */
223
+ get activeSocketPath(): string | null;
224
+ /** Sibling 0600 reattach token file path for the current renderer socket. */
225
+ get reattachTokenPath(): string | null;
214
226
  /**
215
227
  * Start the Rust TUI process
216
228
  * @param options.mux - If true, spawn zmux instead of ztc-tui
@@ -225,6 +237,12 @@ export declare class TuiProcess {
225
237
  /** Admission from this host's CLI bootstrap, never an environment cache. */
226
238
  desktopRuntime?: DesktopRuntime | null;
227
239
  desktopUpdateRelaunch?: string;
240
+ /** Reattach to a live ZTerm Unix socket (`owner_reattach_v1`) instead of spawning a new window. */
241
+ reattachSocket?: string;
242
+ /** Path to the 0600 rotating reattach token file (defaults to `<reattachSocket>.reattach-token`). */
243
+ reattachTokenFile?: string;
244
+ /** Explicit reattach token override (primarily for tests). */
245
+ reattachToken?: string;
228
246
  /** Extra environment for the renderer process (e.g. the zmux keymap). */
229
247
  env?: Record<string, string>;
230
248
  }): Promise<{
@@ -247,6 +265,16 @@ export declare class TuiProcess {
247
265
  * Check if the process is running and ready
248
266
  */
249
267
  isReady(): boolean;
268
+ /**
269
+ * Disconnect cleanly from a live ZTerm window WITHOUT sending `shutdown`,
270
+ * WITHOUT unlinking the socket, and WITHOUT signalling the ZTerm process,
271
+ * so a replacement ZTC harness can reattach via `owner_reattach_v1` while
272
+ * every shell/agent pane and detached OS window keeps running.
273
+ */
274
+ disconnectForReattach(): {
275
+ socketPath: string;
276
+ tokenFilePath: string;
277
+ } | null;
250
278
  /**
251
279
  * Clean up resources
252
280
  */
@@ -296,6 +324,8 @@ export declare class NullTuiProcess {
296
324
  export declare function getNullTuiProcess(options?: {
297
325
  mux?: boolean;
298
326
  }): NullTuiProcess;
327
+ /** Sibling 0600 rotating reattach token path created by ZTerm (`owner_reattach_v1`). */
328
+ export declare function reattachTokenPathForSocket(socketPath: string): string;
299
329
  /**
300
330
  * Get the singleton TUI process instance
301
331
  */