@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
@@ -1,14 +1,14 @@
1
1
  import { ToolCapability } from './capabilities.js';
2
2
  import { lstatSync } from 'fs';
3
3
  import { homedir } from 'os';
4
- import { resolve, isAbsolute, relative, sep } from 'path';
4
+ import { dirname, resolve, isAbsolute, relative, sep } from 'path';
5
5
  import { parseCheckedCommandPlan } from './checked_commands.js';
6
6
  import { formatCheckedStageCommand } from '../../utils/checked_shell.js';
7
7
  import { canonicalPath, isWellFormedText, sameFileKey } from '../../utils/canonical_path.js';
8
8
  import { gitDirectoryComponent, gitDirectoryPlantedByWriteSet, linkedGitDirectoryHolding } from '../../utils/git_directory_names.js';
9
- import { gitProgramFiles } from '../../utils/git_program_files.js';
9
+ import { gitProgramFiles, outermostRoots } from '../../utils/git_program_files.js';
10
10
  import { profileLimitsAgent } from '../../config/profile_limits.js';
11
- import { commandsRequireOsSandbox, sandboxSystemReadRoots } from '../../utils/sandbox.js';
11
+ import { commandsRequireOsSandbox, linkedRootAdvice, profileRootLooks, sandboxSystemReadRoots, unreadableRootReason } from '../../utils/sandbox.js';
12
12
  import { dockerTarget } from '../../utils/docker_target.js';
13
13
  import { ztcOwnStateHolding, ztcOwnStateHoldingForRead } from '../../utils/ztc_own_state.js';
14
14
  /**
@@ -44,6 +44,29 @@ export class AllowAllPolicy {
44
44
  return { allowed: true };
45
45
  }
46
46
  }
47
+ /**
48
+ * Why every call is refused under a profile that denies ENTRY (PATH, as named), which ZTC can't look up (CODE: a folder
49
+ * above it it can't look into, `chmod 000 config`): it can't tell what the denial covers. The deepest folder above PATH
50
+ * that ZTC can look at is the one to give back its mode. The policy threw "EACCES: permission denied, realpath" on every
51
+ * call (the review of fix/r9-release-blockers, RV6-PATH).
52
+ */
53
+ function deniedLookupRefusal(entry, path, code) {
54
+ const folder = lookableFolderAbove(path);
55
+ return `Permission denied: this profile denies ${entry} (${path}), and ZTC can't look into ${folder} to find it (${code}), so it can't `
56
+ + `tell what the denial covers. Give the folder back its mode (chmod u+rx ${folder}), or remove the denial from the profile's deniedPaths.`;
57
+ }
58
+ /** The deepest folder above PATH that ZTC can look at (lstat), the one whose mode keeps ZTC from looking further down. */
59
+ function lookableFolderAbove(path) {
60
+ let folder = dirname(path);
61
+ for (; folder !== dirname(folder); folder = dirname(folder)) {
62
+ try {
63
+ lstatSync(folder);
64
+ break;
65
+ }
66
+ catch { /* further up */ }
67
+ }
68
+ return folder;
69
+ }
47
70
  export class CapabilityPolicy {
48
71
  permissions;
49
72
  profile;
@@ -137,18 +160,47 @@ export class CapabilityPolicy {
137
160
  }
138
161
  return { allowed: true };
139
162
  }
140
- /** The roots the profile allows and denies, canonical, a relative one this policy's folder's. */
163
+ /**
164
+ * The roots the profile allows and denies, canonical, a relative one this policy's folder's. Those it allows by one look
165
+ * at each (utils/sandbox.ts's profileRootLooks), each by the real path that look found, which no check after it resolves
166
+ * again: the policy canonicalized each root again after the look, so a command left running in the background that
167
+ * swapped a root, or a folder above it, between a folder and a link to a folder outside every root had read_file and
168
+ * write_file act there (the review of fix/r9-release-blockers' repair, R9C-ESCAPE-1). A root it names that is, or is
169
+ * named through, a link a command could have made (LINKED) allows nothing: canonicalized through the link on every call,
170
+ * it let write_file write HOME/.bashrc once a command had made a root not made yet (`./build`) a link there (the review
171
+ * of fix/r9-release-blockers, RV8-LINK). Nor does one ZTC couldn't look at (UNREADABLE: below a folder it can't look
172
+ * into), which threw on every call, whatever the call (R9C-TRUTH-5). A denial ZTC can't look up (a folder above it it
173
+ * can't look into) refuses every call, saying which folder and why (LOOKUP): it threw too (RV6-PATH).
174
+ */
141
175
  profileRoots() {
176
+ const looks = profileRootLooks(this.profile, this.cwd);
177
+ const denied = [];
178
+ let lookup;
179
+ for (const path of this.profile?.deniedPaths || []) {
180
+ try {
181
+ denied.push(normalizeRoot(path, this.cwd));
182
+ }
183
+ catch (error) {
184
+ const code = error.code;
185
+ if (code !== 'EACCES' && code !== 'EPERM')
186
+ throw error;
187
+ lookup ??= deniedLookupRefusal(path, resolve(this.cwd, expandHome(path)), code);
188
+ }
189
+ }
142
190
  return {
143
- allowed: (this.profile?.allowedPaths || []).map(path => normalizeRoot(path, this.cwd)),
144
- denied: (this.profile?.deniedPaths || []).map(path => normalizeRoot(path, this.cwd)),
191
+ allowed: Array.from(new Set(looks.roots.map(({ real }) => real))),
192
+ denied,
193
+ linked: looks.linked,
194
+ unreadable: looks.unreadable,
195
+ ...(lookup === undefined ? {} : { lookup }),
145
196
  };
146
197
  }
147
198
  /**
148
199
  * Why PATH is refused under this profile, SUBJECT naming what it is (a path a call names, a command's working
149
200
  * directory), or null: it is in ZTC's own state (OWN_STATE_HOLDING says where; null checks none) under a profile that
150
201
  * limits the agent, in a root the profile denies, or outside the roots it allows (ROOTS, profileRoots) and the folders
151
- * ALSO_READ gives (canonical), which a command may read as its roots.
202
+ * ALSO_READ gives (canonical), which a command may read as its roots; one in a root it names that is a link a command
203
+ * could have made (ROOTS.linked), as named or where the link leads, is refused naming the link.
152
204
  */
153
205
  refusePath(path, roots, ownStateHolding, subject, alsoRead) {
154
206
  const profile = this.profile;
@@ -156,8 +208,29 @@ export class CapabilityPolicy {
156
208
  if (!isWellFormedText(path)) {
157
209
  return `Permission denied: a path must be well-formed Unicode text (${JSON.stringify(path)})`;
158
210
  }
211
+ if (roots.lookup !== undefined)
212
+ return roots.lookup;
159
213
  const { allowed: allowedRoots, denied: deniedRoots } = roots;
160
- const absolutePath = normalizeRoot(path, this.cwd);
214
+ let absolutePath;
215
+ try {
216
+ absolutePath = normalizeRoot(path, this.cwd);
217
+ }
218
+ catch (error) {
219
+ // A path ZTC can't look up (a folder above it it can't look into): in a root it couldn't look at either, as that
220
+ // root's refusal says; elsewhere, naming the folder. Any other error is the caller's, as before.
221
+ const code = error.code;
222
+ if (code !== 'EACCES' && code !== 'EPERM')
223
+ throw error;
224
+ const spelled = resolve(this.cwd, expandHome(path));
225
+ const unreadable = roots.unreadable.find(({ root }) => isWithinRoot(spelled, root));
226
+ if (unreadable !== undefined) {
227
+ return `Permission denied: ${subject} ${path} is in ${unreadable.root}, a root this profile names that ZTC couldn't look at: `
228
+ + unreadableRootReason(unreadable);
229
+ }
230
+ const folder = lookableFolderAbove(spelled);
231
+ return `Permission denied: ZTC can't look up ${subject} ${path} (${code}): it can't look into ${folder}, a folder above it. Give the folder `
232
+ + `back its mode (chmod u+rx ${folder}).`;
233
+ }
161
234
  // ZTC's own state (its config folder, ~/.ztc, its runtime's hand-offs) is never the agent's under a profile that
162
235
  // limits it, whatever allowedPaths or pathPrecedence say: a hook and its approval, an MCP server or a looser
163
236
  // profile written there would run outside the profile and any sandbox. As named and as it resolves.
@@ -179,7 +252,24 @@ export class CapabilityPolicy {
179
252
  if (denied.length > 0 && !exception) {
180
253
  return `Permission denied: ${subject} is blocked by profile (${path})`;
181
254
  }
182
- if (allowedRoots.length > 0 && allowed.length === 0 && !alsoRead?.().some(root => isWithinRoot(absolutePath, root))) {
255
+ // A profile whose every root is such a link, or one ZTC couldn't look at, allows nothing, not everything.
256
+ if ((allowedRoots.length > 0 || roots.linked.length > 0 || roots.unreadable.length > 0) && allowed.length === 0
257
+ && !alsoRead?.().some(root => isWithinRoot(absolutePath, root))) {
258
+ // As named, or by its real path where the root is now (where a root that is itself a link, a dangling one too, leads).
259
+ const spelled = resolve(this.cwd, expandHome(path));
260
+ const linked = roots.linked.find(({ root, link, leads, real }) => isWithinRoot(spelled, root)
261
+ || isWithinRoot(absolutePath, link === root ? leads : real));
262
+ if (linked !== undefined) {
263
+ // The refused path first: after the advice, it read as the entry to add (R9C-REGRESSION-6).
264
+ return `Permission denied: ${subject} ${path} is in ${linked.root}, a root this profile names that `
265
+ + `${linked.link === linked.root ? 'is' : `is named through ${linked.link},`} a link in a folder a command may write, which a command could `
266
+ + `have made, to ${linked.leads}: ZTC follows no such link. ${linkedRootAdvice(linked, allowedRoots, resolve(this.cwd))}`;
267
+ }
268
+ const unreadable = roots.unreadable.find(({ root }) => isWithinRoot(spelled, root));
269
+ if (unreadable !== undefined) {
270
+ return `Permission denied: ${subject} ${path} is in ${unreadable.root}, a root this profile names that ZTC couldn't look at: `
271
+ + unreadableRootReason(unreadable);
272
+ }
183
273
  return `Permission denied: ${subject} is outside allowed profile roots (${path})`;
184
274
  }
185
275
  return null;
@@ -240,7 +330,8 @@ export class CapabilityPolicy {
240
330
  return { allowed: true };
241
331
  }
242
332
  const allowed = this.profile?.allowedPaths || [];
243
- const allowedRoots = allowed.map(path => normalizeRoot(path, this.cwd));
333
+ // A root that is a link a command could have made allows nothing (profileRoots), and is walked for no repository.
334
+ const allowedRoots = this.profileRoots().allowed;
244
335
  const spelledRoots = allowed.map(path => resolve(this.cwd, expandHome(path)));
245
336
  // Every path the whole call writes, so a set that completes a git directory across several of them (or several
246
337
  // calls, with the disk carrying the earlier ones) is refused as one. The request's own path stands in when a
@@ -251,9 +342,10 @@ export class CapabilityPolicy {
251
342
  // Where the repositories the agent may write name programs, read once per call: git's own answer, as the sandbox
252
343
  // reads it, for the work tree's repository and each one a walk of the allowed roots finds (a session started in a
253
344
  // folder that holds repositories), with each one an earlier plan of this process found. A profile that names no
254
- // roots walks none.
345
+ // roots walks none. A root inside another is that root's, as the OS sandbox takes it (outermostRoots).
255
346
  let programs;
256
- const programPaths = () => programs ??= gitProgramFiles([this.cwd, ...allowedRoots], allowedRoots.length > 0 ? allowedRoots : [sep], { walk: allowedRoots });
347
+ const outerRoots = outermostRoots(allowedRoots);
348
+ const programPaths = () => programs ??= gitProgramFiles([this.cwd, ...outerRoots], outerRoots.length > 0 ? outerRoots : [sep], { walk: allowedRoots });
257
349
  for (const path of extractPathArgs(request.args, request.executionCwd)) {
258
350
  // As the path policy refuses under a profile: the file Node writes is not the one the string spells.
259
351
  if (!isWellFormedText(path)) {
@@ -0,0 +1,18 @@
1
+ import type { ZTCPermissionProfile } from '../../config/types.js';
2
+ /** A job quiet for less than this is only between lines. */
3
+ export declare const QUIET_JOB_MS = 60000;
4
+ /** What a quiet-job note reads: a running job's receipt with the output a wait brought. */
5
+ export interface QuietJobReceipt {
6
+ status: string;
7
+ log_path: string;
8
+ output?: string;
9
+ output_truncated?: boolean;
10
+ followed_file?: string;
11
+ cwd: string;
12
+ }
13
+ /**
14
+ * A note for a running job a wait brought nothing from, when it has written nothing for a minute or more: not to its
15
+ * log, nor to the file its command sends output to (one the profile lets read_file read). The next step is then a
16
+ * look at the job, not the same wait again. A log that reached its limit (output_truncated) is no sign of quiet.
17
+ */
18
+ export declare function quietJobNote(result: QuietJobReceipt, profile: ZTCPermissionProfile | undefined, waitedMs?: number): string | undefined;
@@ -0,0 +1,48 @@
1
+ import { realpathSync, statSync } from 'node:fs';
2
+ import { ToolCapability } from './capabilities.js';
3
+ import { CapabilityPolicy } from './policy.js';
4
+ /** A job quiet for less than this is only between lines. */
5
+ export const QUIET_JOB_MS = 60_000;
6
+ /**
7
+ * A note for a running job a wait brought nothing from, when it has written nothing for a minute or more: not to its
8
+ * log, nor to the file its command sends output to (one the profile lets read_file read). The next step is then a
9
+ * look at the job, not the same wait again. A log that reached its limit (output_truncated) is no sign of quiet.
10
+ */
11
+ export function quietJobNote(result, profile, waitedMs) {
12
+ if (result.status !== 'running' || (result.output ?? '') !== '' || result.output_truncated)
13
+ return undefined;
14
+ const followed = result.followed_file ? followedChangedAt(result.followed_file, profile, result.cwd) : undefined;
15
+ const changes = [changedAt(result.log_path), followed].filter((at) => at !== undefined);
16
+ const quietMs = changes.length > 0 ? Date.now() - Math.max(...changes) : 0;
17
+ if (quietMs < QUIET_JOB_MS)
18
+ return undefined;
19
+ const wait = waitedMs === undefined ? '' : ` in a ${Math.round(waitedMs / 1000)}s wait`;
20
+ return `Nothing new from this job${wait}; its log${followed === undefined ? '' : ' and the file it writes to'} last changed `
21
+ + `${Math.round(quietMs / 1000)}s ago. It may be waiting on something: inspect its log, and the service or file it `
22
+ + 'drives, before waiting again; stop_command ends it if it cannot progress.';
23
+ }
24
+ function changedAt(path) {
25
+ try {
26
+ return statSync(path).mtimeMs;
27
+ }
28
+ catch {
29
+ return undefined;
30
+ }
31
+ }
32
+ /**
33
+ * When the followed file last changed, if the profile lets read_file read where it really is, and it is a regular file
34
+ * with no other name: a hard link to a blocked file passes the path check (as for its tail in shell.ts).
35
+ */
36
+ function followedChangedAt(path, profile, cwd) {
37
+ try {
38
+ const real = realpathSync(path);
39
+ if (profile && !new CapabilityPolicy(undefined, profile, cwd)
40
+ .evaluateTool({ name: 'read_file', args: { path: real }, capabilities: [ToolCapability.FILE_READ] }).allowed)
41
+ return undefined;
42
+ const stat = statSync(real);
43
+ return stat.isFile() && stat.nlink === 1 ? stat.mtimeMs : undefined;
44
+ }
45
+ catch {
46
+ return undefined;
47
+ }
48
+ }
@@ -1,10 +1,6 @@
1
1
  import { type ExecutionSettings } from '../../config/execution.js';
2
2
  import type { ManagedCommandObservation } from './command_jobs.js';
3
- /**
4
- * Group failures by cause rather than command spelling, paths, or changing IDs. A failed command is keyed by its
5
- * exit code and its error line, so probes that fail for different reasons are different causes (scan-lab, 2026-11-12).
6
- */
7
- export declare function normalizeFailure(content: string): string;
3
+ export { normalizeFailure } from './failure_cause.js';
8
4
  /** One budget per run; a new, substantive successful observation resets it. */
9
5
  export declare function createRecoveryGuard(settings: ExecutionSettings): (results: readonly {
10
6
  name: string;
@@ -1,49 +1,7 @@
1
1
  import { resolveExecutionSettings } from '../../config/execution.js';
2
2
  import { isHealthyManagedCommandRead } from '../loop_policy.js';
3
- import { failureWithoutExecutionSuffix } from './command_execution_policy.js';
4
- /** Quoted values and numbers out, so the same error at another path or ID reads the same. */
5
- function squash(line) {
6
- return line.replace(/['"`][^'"`]*['"`]/g, '<value>').replace(/\d+/g, '#').trim().slice(0, 240);
7
- }
8
- /**
9
- * The line of a failed command's output that says what went wrong, the last one: an exception (`ValueError: …`) or
10
- * an error message (`error: …`, `fatal: …`, `file.c:3: error: …`). ZTC's own notes after the output are not it.
11
- */
12
- function errorLine(output) {
13
- const lines = output.split('\n').map(line => line.trim()).filter(Boolean);
14
- for (let index = lines.length - 1; index >= 0; index--) {
15
- const line = lines[index];
16
- if (/^(?:pipe stages exited|hint:|command failed \(exit)/.test(line))
17
- continue;
18
- if (/^(?:[\w.]+\.)?\w*(?:error|exception)\b\s*:/.test(line) || /^(?:error|fatal)\b[:\s]/.test(line) || /\berror(?:\[\w+\])?:/.test(line))
19
- return line;
20
- }
21
- return undefined;
22
- }
23
- /**
24
- * Group failures by cause rather than command spelling, paths, or changing IDs. A failed command is keyed by its
25
- * exit code and its error line, so probes that fail for different reasons are different causes (scan-lab, 2026-11-12).
26
- */
27
- export function normalizeFailure(content) {
28
- const text = failureWithoutExecutionSuffix(content).toLowerCase();
29
- if (/not_executed/.test(text))
30
- return '';
31
- for (const [pattern, cause] of [
32
- [/heredoc|unexpected end of file|unterminated/, 'unfinished shell input'],
33
- [/permission denied|eacces/, 'permission denied'],
34
- [/not found|enoent|unknown tool|unavailable/, 'capability or file unavailable'],
35
- [/timeout|timed out/, 'timeout'],
36
- [/syntaxerror|syntax error|invalid.*syntax/, 'syntax error'],
37
- ])
38
- if (pattern.test(text))
39
- return cause;
40
- const exit = text.match(/command failed \(exit (\d+)\)/);
41
- if (exit) {
42
- const line = errorLine(text);
43
- return `command exit ${exit[1]}${line ? `: ${squash(line)}` : ''}`;
44
- }
45
- return squash(text.split('\n')[0]);
46
- }
3
+ import { normalizeFailure } from './failure_cause.js';
4
+ export { normalizeFailure } from './failure_cause.js';
47
5
  /** One budget per run; a new, substantive successful observation resets it. */
48
6
  export function createRecoveryGuard(settings) {
49
7
  const limits = resolveExecutionSettings(settings);
@@ -35,6 +35,7 @@ export interface HostApprovalContext {
35
35
  export interface ToolRuntimeResult {
36
36
  /** Host applied the tool-result cap; the captured text is incomplete. */
37
37
  contentTruncated?: boolean;
38
+ timedOut?: boolean;
38
39
  content: string;
39
40
  isError: boolean;
40
41
  effectiveArgs: Record<string, unknown>;
@@ -792,6 +792,7 @@ export async function executeToolWithRuntime(name, args, options) {
792
792
  }
793
793
  async function handleToolFailure(error) {
794
794
  let message = error instanceof Error ? error.message : String(error);
795
+ const timedOut = error instanceof Error && error.timedOut === true;
795
796
  if (options.hooks) {
796
797
  const failureHook = await options.hooks.dispatch('PostToolUseFailure', {
797
798
  toolName: name,
@@ -813,6 +814,7 @@ export async function executeToolWithRuntime(name, args, options) {
813
814
  content: message,
814
815
  isError: true,
815
816
  effectiveArgs,
817
+ ...(timedOut ? { timedOut: true } : {}),
816
818
  ...(managedCommand ? { managedCommand } : {}),
817
819
  ...(verificationReceipt ? { verificationReceipt } : {}),
818
820
  };
@@ -22,6 +22,7 @@ import { describeExecutionContext, resolveExecutionSettings } from './runtime/ex
22
22
  import { createRecoveryGuard } from './runtime/recovery.js';
23
23
  import { listCommandJobs, shutdownCommandJobs } from './runtime/command_jobs.js';
24
24
  import { awaitManagedCommandProgress, formatManagedCommandObservations } from './runtime/command_wait.js';
25
+ import { quietJobNote } from './runtime/quiet_job.js';
25
26
  import { scheduleToolBatch, describeBlockingResult, unfinishedCommand } from './runtime/tool_scheduler.js';
26
27
  import { configStore } from '../config.js';
27
28
  import { hostModelContextBudget, hostModelContextError } from './host_model_context.js';
@@ -563,6 +564,7 @@ export class SubAgent {
563
564
  messages.push({ id: `recovery_${iterations}`, role: 'user',
564
565
  content: 'Repeated failures: inspect current capabilities, then try one changed recovery approach. Do not repeat the failing sequence.', timestamp: new Date() });
565
566
  if (iterations < maxIterations && toolResults.every(result => !result.is_error && result.managedCommand !== undefined)) {
567
+ const waitStartedAt = Date.now();
566
568
  const waiting = await awaitManagedCommandProgress(toolResults.map(result => ({
567
569
  ...result.managedCommand, toolCallId: result.tool_use_id,
568
570
  })), { signal: runSignal, deadlineAt, emit: opts?.onEvent });
@@ -576,7 +578,10 @@ export class SubAgent {
576
578
  }
577
579
  if (waiting.waited)
578
580
  messages.push({ id: `command_observation_${randomUUID()}`, role: 'user',
579
- content: formatManagedCommandObservations(waiting.observations), timestamp: new Date(),
581
+ content: formatManagedCommandObservations(waiting.observations.map(item => {
582
+ const note = quietJobNote(item.result, this.config.commandPolicy?.profile, Date.now() - waitStartedAt);
583
+ return note ? { ...item, note } : item;
584
+ })), timestamp: new Date(),
580
585
  metadata: { synthetic: true, hostContext: true } });
581
586
  }
582
587
  }
@@ -44,6 +44,7 @@ export const ALWAYS_LOADED_TOOL_NAMES = new Set([
44
44
  'shell_command',
45
45
  'update_plan',
46
46
  'workflow',
47
+ 'declare_outcome',
47
48
  // Skills surface — the manifest in the system prompt instructs the model
48
49
  // to call invoke_skill directly; shipping the schema every turn keeps the
49
50
  // single-hop contract honest. Mode-level allowlists can still filter
@@ -17,6 +17,8 @@ export { delegateTaskTool } from './delegate.js';
17
17
  export { spawnBackgroundAgentTool, setBackgroundRegistry, clearBackgroundRegistry, getBackgroundRegistry } from './background.js';
18
18
  export { workflowTool } from './workflow.js';
19
19
  export { finishTaskTool, todoWriteTool, setTodoUpdateCallback, clearTodoUpdateCallback, getLatestTodos } from './todo.js';
20
+ export { declareOutcomeTool, parseOutcomeDeclaration } from './outcome.js';
21
+ export type { DeclaredOutcome, OutcomeDeclaration } from './outcome.js';
20
22
  export { gotoDefinitionTool, findReferencesTool, hoverTool, diagnosticsTool, lspStatusTool, } from './lsp.js';
21
23
  export type { Tool } from './types.js';
22
24
  export { planModeTool, submitPlanTool, setPlanModeCallback, setSubmitPlanCallback, clearPlanCallbacks } from './plan.js';
@@ -39,6 +39,7 @@ export { delegateTaskTool } from './delegate.js';
39
39
  export { spawnBackgroundAgentTool, setBackgroundRegistry, clearBackgroundRegistry, getBackgroundRegistry } from './background.js';
40
40
  export { workflowTool } from './workflow.js';
41
41
  export { finishTaskTool, todoWriteTool, setTodoUpdateCallback, clearTodoUpdateCallback, getLatestTodos } from './todo.js';
42
+ export { declareOutcomeTool, parseOutcomeDeclaration } from './outcome.js';
42
43
  export { gotoDefinitionTool, findReferencesTool, hoverTool, diagnosticsTool, lspStatusTool, } from './lsp.js';
43
44
  export { planModeTool, submitPlanTool, setPlanModeCallback, setSubmitPlanCallback, clearPlanCallbacks } from './plan.js';
44
45
  export { askUserTool, setAskUserCallback, clearAskUserCallback, resetAskUserTurnFlag } from './ask_user.js';
@@ -0,0 +1,15 @@
1
+ import { Tool } from './types.js';
2
+ export type DeclaredOutcome = 'done' | 'blocked' | 'needs_input';
3
+ export interface OutcomeDeclaration {
4
+ outcome: DeclaredOutcome;
5
+ text: string;
6
+ }
7
+ /**
8
+ * One refusal for every Done-when item the report says was not met, all of them named at once, and once for each item
9
+ * of a session however the next report words it: the agent has been asked. It starts "Refused:", so the run's
10
+ * repeated-failure guard does not count it: reports that each name one more unmet item are answers, not failures.
11
+ */
12
+ export declare function doneOutcomeChallenge(outcome: DeclaredOutcome, text: string, doneWhen?: readonly string[], sessionId?: string): string | undefined;
13
+ export declare function blockedOutcomeChallenge(outcome: DeclaredOutcome, text: string): string | undefined;
14
+ export declare function parseOutcomeDeclaration(result: string): OutcomeDeclaration | undefined;
15
+ export declare const declareOutcomeTool: Tool;
@@ -0,0 +1,107 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { unmetDoneItems } from '../runtime/done_report.js';
3
+ const OPERATOR_ASK = /\?|\b(?:only (?:someone else|the operator|a human|you)|you (?:need|must|can|could|should)|your (?:input|decision|approval|access|account|credentials)|needs? (?:your|operator|human)|grant(?:ed|ing)?\b|approv\w*|permission|credentials?|in scope|out of scope)\b/i;
4
+ const OWN_STEP = new RegExp('\\b(?:I(?:\'ll| will| can| could| should| need to| must| am going to)|let me|next (?:step|I))\\b'
5
+ + '[^.!?\\n]{0,120}?\\b(?:restart|rebuild|re-?run|rerun|inspect|check|read|look|test|try|fix|patch|update|add|remove|'
6
+ + 'retry|deploy|start|stop|kill|clean|migrate|write|edit|investigate|debug|verify|collect|trace)\\b', 'i');
7
+ const CHALLENGED = new Map();
8
+ /**
9
+ * The Done-when items each session was asked about, for the 256 sessions that asked last. A session's own items are
10
+ * kept whole: a shared cap on items let a long Done-when, or other sessions' questions, push out an item asked about,
11
+ * and with refusals outside the repeated-failure guard nothing would then end the run.
12
+ */
13
+ const ASKED = new Map();
14
+ /**
15
+ * One refusal for every Done-when item the report says was not met, all of them named at once, and once for each item
16
+ * of a session however the next report words it: the agent has been asked. It starts "Refused:", so the run's
17
+ * repeated-failure guard does not count it: reports that each name one more unmet item are answers, not failures.
18
+ */
19
+ export function doneOutcomeChallenge(outcome, text, doneWhen = [], sessionId = '') {
20
+ if (outcome !== 'done' || doneWhen.length === 0)
21
+ return undefined;
22
+ const asked = ASKED.get(sessionId) ?? new Set();
23
+ const unmet = unmetDoneItems(doneWhen.filter(item => !asked.has(item)), text);
24
+ if (unmet.length === 0)
25
+ return undefined;
26
+ for (const { item } of unmet)
27
+ asked.add(item);
28
+ ASKED.delete(sessionId);
29
+ if (ASKED.size >= 256)
30
+ ASKED.delete(ASKED.keys().next().value);
31
+ ASKED.set(sessionId, asked);
32
+ const one = unmet.length === 1;
33
+ const named = unmet.slice(0, 3).map(({ item, line }) => `"${clip(item)}" ("${clip(line)}")`).join('; ')
34
+ + (unmet.length > 3 ? `; and ${unmet.length - 3} more` : '');
35
+ return 'Refused: declare_outcome: "done" says the task is complete, but this report reads as if '
36
+ + (one ? 'a Done-when item of the task was not met: ' : `${unmet.length} Done-when items of the task were not met: `)
37
+ + `${named}. If ${one ? 'it is' : 'they are'} met, or the task asks only for a report on ${one ? 'it' : 'them'}, `
38
+ + 'declare "done" again with the same report, its limits and caveats included. If not, finish '
39
+ + `${one ? 'it' : 'them'} first, or declare "blocked" or "needs_input" naming what only someone else can resolve or answer.`;
40
+ }
41
+ function clip(text) {
42
+ return text.length <= 200 ? text : `${text.slice(0, 199).replace(/[\uD800-\uDBFF]$/u, '')}…`;
43
+ }
44
+ export function blockedOutcomeChallenge(outcome, text) {
45
+ if (outcome !== 'blocked' || OPERATOR_ASK.test(text))
46
+ return undefined;
47
+ const step = OWN_STEP.exec(text);
48
+ if (!step)
49
+ return undefined;
50
+ const key = createHash('sha256').update(text).digest('hex');
51
+ if (CHALLENGED.has(key))
52
+ return undefined;
53
+ if (CHALLENGED.size >= 64)
54
+ CHALLENGED.delete(CHALLENGED.keys().next().value);
55
+ CHALLENGED.set(key, true);
56
+ return 'declare_outcome: "blocked" means something only someone else can resolve, but this reason names work you '
57
+ + `can still do: "${step[0].trim()}". Do that work and declare again when it is done, or, if only someone else `
58
+ + 'can resolve it, name the question only they can answer (what to grant, decide or provide) and declare '
59
+ + '"blocked" or "needs_input" with that question.';
60
+ }
61
+ export function parseOutcomeDeclaration(result) {
62
+ try {
63
+ const parsed = JSON.parse(result);
64
+ if (parsed.success !== true)
65
+ return undefined;
66
+ if (parsed.outcome !== 'done' && parsed.outcome !== 'blocked' && parsed.outcome !== 'needs_input')
67
+ return undefined;
68
+ if (typeof parsed.text !== 'string' || !parsed.text.trim())
69
+ return undefined;
70
+ return { outcome: parsed.outcome, text: parsed.text };
71
+ }
72
+ catch {
73
+ return undefined;
74
+ }
75
+ }
76
+ export const declareOutcomeTool = {
77
+ definition: {
78
+ name: 'declare_outcome',
79
+ description: 'End an unattended run by declaring its outcome. Call alone, only when the task is done, blocked by something only someone else can resolve, or needs input from the user. A plain final message without this call is not an outcome and the run continues. A done report that says one of the task\'s own Done-when items was not met is refused once.',
80
+ parameters: {
81
+ type: 'object',
82
+ properties: {
83
+ outcome: { type: 'string', enum: ['done', 'blocked', 'needs_input'],
84
+ description: "done: the task is complete. blocked: something only someone else can resolve stops it; name what they must grant, decide or provide, because a reason that names your own next step is refused once. needs_input: the user must answer or decide." },
85
+ text: { type: 'string',
86
+ description: 'For done, the final answer. For blocked or needs_input, the reason, naming what only someone else can resolve or what input is needed.' },
87
+ },
88
+ required: ['outcome', 'text'],
89
+ },
90
+ },
91
+ execute: async (args, context) => {
92
+ const outcome = args.outcome;
93
+ if (outcome !== 'done' && outcome !== 'blocked' && outcome !== 'needs_input') {
94
+ throw new Error("declare_outcome: outcome must be 'done', 'blocked' or 'needs_input'.");
95
+ }
96
+ const text = typeof args.text === 'string' ? args.text.trim() : '';
97
+ if (!text)
98
+ throw new Error('declare_outcome: text must be a non-empty final answer or reason.');
99
+ const challenge = blockedOutcomeChallenge(outcome, text)
100
+ ?? doneOutcomeChallenge(outcome, text, context?.doneWhen ?? [], context?.sessionId);
101
+ if (challenge)
102
+ throw new Error(challenge);
103
+ return JSON.stringify({ success: true, outcome, text });
104
+ },
105
+ finalResponse: result => parseOutcomeDeclaration(result)?.text,
106
+ finalOutcome: result => parseOutcomeDeclaration(result)?.outcome,
107
+ };
@@ -68,7 +68,8 @@ export declare function childZtcPaneEnv(): Record<string, string>;
68
68
  /**
69
69
  * The environment of a ZTC pane an agent opens: childZtcPaneEnv's, and the pane's launch task, when its arguments carry
70
70
  * one, is the agent's, so the pane sends it to its own agent as a message and never runs it as the person's command
71
- * (PANE_TASK_AS_MESSAGE_ENV), as an agent's /ztc task.
71
+ * (PANE_TASK_AS_MESSAGE_ENV), as an agent's /ztc task. It is a nested run of this ZTC, as a ztc the agent's shell starts
72
+ * is (config/profiles.ts nestedRunEnv); a pane the person opens is none, and saves its settings as any ZTC of theirs does.
72
73
  */
73
74
  export declare function agentZtcPaneEnv(): Record<string, string>;
74
75
  export declare function buildChildZtcPaneLaunch(extraArgs?: string[], childSessionId?: string, options?: {
@@ -1,5 +1,6 @@
1
1
  import { configStore } from '../../config.js';
2
2
  import { permissionPinChildEnv } from '../../config/permission_pin.js';
3
+ import { nestedRunEnv } from '../../config/profiles.js';
3
4
  import { isRetiredModel, isRetiredProvider, retiredProviderMessage, ROUTE_AWAITS_A_CHOICE } from '../../config/retired_routes.js';
4
5
  /**
5
6
  * Terminal pane management tools for zmux mode.
@@ -15,6 +16,7 @@ import { isRatatuiBinaryAvailable, ztcPaneRendererMissing } from '../../ui/ratat
15
16
  import { CHILD_ZTC_SCRIPT_RE, resolveChildZtcEntrypoint } from '../../ui/ratatui/ztc_launch_trust.js';
16
17
  import { CAPABILITY_PANE_DELIVERY_ACK } from '../../ui/ratatui/protocol.js';
17
18
  import { paneReadRefusal } from '../../ui/ratatui/screen_privacy.js';
19
+ import { personOnlyPaneRefusal, personOnlyProgramRefusal } from '../../panes/person_only_panes.js';
18
20
  import { generateSessionId } from '../../session.js';
19
21
  import { isPaneProvider, resolveModelAndProvider } from '../../panes/model_catalog.js';
20
22
  import { buildZtcPaneLaunchCommand, createZtcLaunchSpec, ztcPaneRoutingRefusal } from '../../panes/ztc_launch.js';
@@ -385,6 +387,9 @@ function filterChildZtcArgs(args) {
385
387
  '--mode',
386
388
  '--prompt',
387
389
  '--voyager-task',
390
+ // A child ZTC starts under the session's permission settings, never a profile its launch names.
391
+ '--permission-profile',
392
+ '--profile',
388
393
  ]);
389
394
  const filtered = [];
390
395
  for (let i = 0; i < args.length; i++) {
@@ -456,10 +461,11 @@ export function childZtcPaneEnv() {
456
461
  /**
457
462
  * The environment of a ZTC pane an agent opens: childZtcPaneEnv's, and the pane's launch task, when its arguments carry
458
463
  * one, is the agent's, so the pane sends it to its own agent as a message and never runs it as the person's command
459
- * (PANE_TASK_AS_MESSAGE_ENV), as an agent's /ztc task.
464
+ * (PANE_TASK_AS_MESSAGE_ENV), as an agent's /ztc task. It is a nested run of this ZTC, as a ztc the agent's shell starts
465
+ * is (config/profiles.ts nestedRunEnv); a pane the person opens is none, and saves its settings as any ZTC of theirs does.
460
466
  */
461
467
  export function agentZtcPaneEnv() {
462
- return { ...childZtcPaneEnv(), [PANE_TASK_AS_MESSAGE_ENV]: '1' };
468
+ return { ...childZtcPaneEnv(), ...nestedRunEnv(), [PANE_TASK_AS_MESSAGE_ENV]: '1' };
463
469
  }
464
470
  function isLegacyChildZtcLaunch(command, args) {
465
471
  const commandName = command.split(/[\\/]/).pop()?.toLowerCase() || command.toLowerCase();
@@ -617,6 +623,10 @@ Returns the pane ID which you can use with read_terminal_pane, write_terminal_pa
617
623
  return 'Error: args must be a valid JSON array.';
618
624
  }
619
625
  }
626
+ // A CLI only the person drives (Antigravity's agy) is never started in an agent's pane (panes/person_only_panes.ts).
627
+ const personOnly = personOnlyProgramRefusal(command, (parsedArgs ?? []).map(String));
628
+ if (personOnly)
629
+ return `Error: ${personOnly}`;
620
630
  const cwd = args.cwd ? String(args.cwd) : undefined;
621
631
  const title = args.title ? String(args.title) : undefined;
622
632
  const direction = parseOptionalSplitDirection(args.direction);
@@ -1029,6 +1039,10 @@ For raw keystrokes set submit=false; input bytes are preserved and Enter is \\r
1029
1039
  throw new Error('Pane 0 is ZTC\'s main session, where only the person types, so write_terminal_pane can\'t write to it. '
1030
1040
  + 'To reach it from a pane, use send_message.');
1031
1041
  }
1042
+ // A pane only the person drives (Antigravity's) takes no agent's typing (panes/person_only_panes.ts).
1043
+ const personOnly = personOnlyPaneRefusal(paneId, 'type');
1044
+ if (personOnly)
1045
+ throw new Error(personOnly);
1032
1046
  let input = String(args.input || '');
1033
1047
  if (!input) {
1034
1048
  throw new Error('input is required.');
@@ -1806,6 +1820,10 @@ export const restartPaneTool = {
1806
1820
  if (paneId instanceof Error) {
1807
1821
  return paneId.message;
1808
1822
  }
1823
+ // Restarting a pane only the person drives starts its CLI again, which no agent does (panes/person_only_panes.ts).
1824
+ const personOnly = personOnlyPaneRefusal(paneId, 'restart');
1825
+ if (personOnly)
1826
+ return `Error: ${personOnly}`;
1809
1827
  const eventPromise = waitForEvent(tui, (event) => event.type === 'error' || (event.type === 'pane_created' && event.pane_id === paneId), 15000);
1810
1828
  const sent = tui.send({ type: 'restart_pane', pane_id: paneId });
1811
1829
  if (!sent) {
@@ -1851,5 +1869,5 @@ export const paneTools = [
1851
1869
  // read_terminal_pane returns program output, which may itself begin with "Error:";
1852
1870
  // its own failures are thrown, so only tool-authored messages are classified.
1853
1871
  isErrorResult: tool === readTerminalPaneTool ? undefined : (content) => /^Error[: ]/i.test(content),
1854
- capabilities: tool.capabilities ?? ([createTerminalPaneTool, createZtcPaneTool, restartPaneTool, closeTerminalPaneTool].includes(tool)
1872
+ capabilities: tool.capabilities ?? ([createTerminalPaneTool, createZtcPaneTool, restartPaneTool, closeTerminalPaneTool, openEditorPaneTool].includes(tool)
1855
1873
  ? [ToolCapability.SHELL_EXEC] : [ToolCapability.FILE_READ]), }));
@@ -17,6 +17,7 @@ import { delegateTaskTool } from './delegate.js';
17
17
  import { spawnBackgroundAgentTool } from './background.js';
18
18
  import { workflowTool } from './workflow.js';
19
19
  import { finishTaskTool, todoWriteTool } from './todo.js';
20
+ import { declareOutcomeTool } from './outcome.js';
20
21
  import { planModeTool, submitPlanTool } from './plan.js';
21
22
  import { askUserTool } from './ask_user.js';
22
23
  import { sessionEvidenceTool } from './session_evidence.js';
@@ -55,6 +56,7 @@ export const defaultTools = [
55
56
  workflowTool,
56
57
  todoWriteTool,
57
58
  finishTaskTool,
59
+ declareOutcomeTool,
58
60
  planModeTool,
59
61
  submitPlanTool,
60
62
  askUserTool,
@@ -15,6 +15,7 @@ export declare function summarizeCommandFailure(output: string, limit?: number,
15
15
  export declare function shellErrorHint(exitCode: number, stderr: string, hasStdout: boolean, timedOut?: boolean): string | null;
16
16
  /** Which shell runs shell text here, so the model writes text that shell reads. */
17
17
  export declare const SHELL_TEXT_NOTE: string;
18
+ export declare function sleepPollingRefusal(command: string, timeoutMs?: number): string | null;
18
19
  export declare const runCommandTool: Tool;
19
20
  export declare const readCommandTool: Tool;
20
21
  export declare const stopCommandTool: Tool;