@zergai/ztc 0.26.2-dev.202611210149 → 0.26.4-dev.202611231953

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 (275) hide show
  1. package/README.md +590 -28
  2. package/bin/zmux-darwin-arm64 +0 -0
  3. package/bin/zmux-linux-x64 +0 -0
  4. package/bin/ztc-audio-darwin-arm64 +0 -0
  5. package/bin/ztc-capture-darwin-arm64 +0 -0
  6. package/bin/ztc-tui-darwin-arm64 +0 -0
  7. package/bin/ztc-tui-linux-x64 +0 -0
  8. package/bin/zterm-darwin-arm64 +2 -2
  9. package/dist/App.js +18 -1
  10. package/dist/agent/agent.d.ts +25 -1
  11. package/dist/agent/agent.js +26 -1
  12. package/dist/agent/attached_images.d.ts +58 -0
  13. package/dist/agent/attached_images.js +145 -0
  14. package/dist/agent/backends/anthropic.d.ts +14 -0
  15. package/dist/agent/backends/anthropic.js +49 -2
  16. package/dist/agent/backends/codex_app_server.d.ts +3 -1
  17. package/dist/agent/backends/codex_app_server.js +9 -6
  18. package/dist/agent/backends/codex_auth.js +3 -0
  19. package/dist/agent/backends/gemini.js +3 -0
  20. package/dist/agent/backends/host_effort_policy.js +14 -2
  21. package/dist/agent/backends/http_error.d.ts +17 -0
  22. package/dist/agent/backends/http_error.js +50 -1
  23. package/dist/agent/backends/index.js +2 -1
  24. package/dist/agent/backends/model_redirect.d.ts +47 -0
  25. package/dist/agent/backends/model_redirect.js +97 -0
  26. package/dist/agent/backends/openai_compatible.js +5 -0
  27. package/dist/agent/backends/openai_responses.d.ts +9 -1
  28. package/dist/agent/backends/openai_responses.js +21 -12
  29. package/dist/agent/backends/prompt_cache.d.ts +8 -0
  30. package/dist/agent/backends/prompt_cache.js +10 -0
  31. package/dist/agent/backends/provider_ids.d.ts +1 -1
  32. package/dist/agent/backends/provider_ids.js +1 -1
  33. package/dist/agent/backends/types.d.ts +8 -0
  34. package/dist/agent/backends/zerg-api.js +5 -1
  35. package/dist/agent/backends/zrouter_stream.d.ts +75 -9
  36. package/dist/agent/backends/zrouter_stream.js +250 -49
  37. package/dist/agent/commands/config.js +51 -4
  38. package/dist/agent/commands/connect.js +20 -0
  39. package/dist/agent/commands/credential_status.js +5 -3
  40. package/dist/agent/commands/debug.js +3 -0
  41. package/dist/agent/commands/diff.js +9 -5
  42. package/dist/agent/commands/emulation.js +7 -1
  43. package/dist/agent/commands/inbox.js +4 -3
  44. package/dist/agent/commands/mcp.js +3 -0
  45. package/dist/agent/commands/models.js +20 -3
  46. package/dist/agent/commands/permissions.js +16 -2
  47. package/dist/agent/commands/provider_selection.js +13 -6
  48. package/dist/agent/commands/settings.js +15 -4
  49. package/dist/agent/commands/status.js +23 -1
  50. package/dist/agent/commands/types.d.ts +34 -3
  51. package/dist/agent/commands/update.d.ts +2 -1
  52. package/dist/agent/commands/update.js +8 -3
  53. package/dist/agent/commands/zerg.d.ts +6 -0
  54. package/dist/agent/commands/zerg.js +152 -28
  55. package/dist/agent/commands/ztc_pane.js +8 -5
  56. package/dist/agent/factory.js +22 -4
  57. package/dist/agent/request_encoder.js +11 -2
  58. package/dist/agent/runtime/command_jobs.js +16 -1
  59. package/dist/agent/runtime/command_panes.js +4 -1
  60. package/dist/agent/runtime/execution_context.d.ts +8 -1
  61. package/dist/agent/runtime/execution_context.js +8 -2
  62. package/dist/agent/runtime/policy.d.ts +66 -5
  63. package/dist/agent/runtime/policy.js +161 -33
  64. package/dist/agent/runtime/remote_broker_transport.d.ts +7 -0
  65. package/dist/agent/runtime/remote_broker_transport.js +33 -3
  66. package/dist/agent/runtime/remote_resource_errors.d.ts +7 -0
  67. package/dist/agent/runtime/remote_resource_errors.js +10 -0
  68. package/dist/agent/runtime/remote_resources.d.ts +1 -1
  69. package/dist/agent/runtime/remote_resources.js +7 -3
  70. package/dist/agent/runtime/source_verification.js +15 -12
  71. package/dist/agent/runtime/tool_runtime.js +165 -58
  72. package/dist/agent/runtime/verifier_capture.d.ts +1 -1
  73. package/dist/agent/runtime/verifier_capture.js +6 -0
  74. package/dist/agent/runtime/work_base.js +46 -14
  75. package/dist/agent/tools/adaptation.js +29 -12
  76. package/dist/agent/tools/apply_patch.js +62 -5
  77. package/dist/agent/tools/background.js +2 -0
  78. package/dist/agent/tools/benchmark_cpu.js +2 -0
  79. package/dist/agent/tools/bus_message.d.ts +4 -2
  80. package/dist/agent/tools/bus_message.js +21 -3
  81. package/dist/agent/tools/delegate.js +2 -0
  82. package/dist/agent/tools/file.d.ts +12 -1
  83. package/dist/agent/tools/file.js +92 -11
  84. package/dist/agent/tools/lsp.d.ts +12 -0
  85. package/dist/agent/tools/lsp.js +61 -5
  86. package/dist/agent/tools/pane.js +20 -45
  87. package/dist/agent/tools/project_context.js +5 -2
  88. package/dist/agent/tools/routine.js +20 -4
  89. package/dist/agent/tools/screenshot.d.ts +8 -0
  90. package/dist/agent/tools/screenshot.js +39 -25
  91. package/dist/agent/tools/search.js +31 -3
  92. package/dist/agent/tools/shell.js +7 -1
  93. package/dist/agent/tools/supervision.js +6 -0
  94. package/dist/agent/tools/types.d.ts +18 -0
  95. package/dist/agent/tools/zerg.js +15 -19
  96. package/dist/agent/tools/ztc_command.d.ts +15 -4
  97. package/dist/agent/tools/ztc_command.js +48 -34
  98. package/dist/app/agent_runner.js +8 -6
  99. package/dist/app/conversation_compaction.d.ts +6 -3
  100. package/dist/app/conversation_compaction.js +6 -3
  101. package/dist/app/tool_callbacks.js +1 -0
  102. package/dist/audio/sfx.js +6 -0
  103. package/dist/batch/worktree.js +22 -10
  104. package/dist/board/client.js +2 -1
  105. package/dist/cli_main.d.ts +1 -0
  106. package/dist/cli_main.js +141 -45
  107. package/dist/cli_ratatui.d.ts +49 -4
  108. package/dist/cli_ratatui.js +355 -79
  109. package/dist/conductor_branch.js +4 -1
  110. package/dist/config/host_credentials.d.ts +157 -0
  111. package/dist/config/host_credentials.js +589 -0
  112. package/dist/config/model_pin.d.ts +111 -0
  113. package/dist/config/model_pin.js +182 -0
  114. package/dist/config/own_state_files.d.ts +35 -0
  115. package/dist/config/own_state_files.js +161 -0
  116. package/dist/config/permission_pin.d.ts +148 -0
  117. package/dist/config/permission_pin.js +203 -0
  118. package/dist/config/permissions.d.ts +9 -2
  119. package/dist/config/permissions.js +14 -3
  120. package/dist/config/platform_login.d.ts +72 -0
  121. package/dist/config/platform_login.js +111 -0
  122. package/dist/config/profile_limits.d.ts +34 -0
  123. package/dist/config/profile_limits.js +66 -0
  124. package/dist/config/provider_api_key_env.js +3 -2
  125. package/dist/config/provider_models.d.ts +6 -1
  126. package/dist/config/provider_models.js +38 -11
  127. package/dist/config/repo_config.d.ts +22 -0
  128. package/dist/config/repo_config.js +77 -3
  129. package/dist/config/router_runtime_grant.d.ts +53 -0
  130. package/dist/config/router_runtime_grant.js +131 -0
  131. package/dist/config/settings_merge.d.ts +22 -0
  132. package/dist/config/settings_merge.js +75 -0
  133. package/dist/config/types.d.ts +8 -0
  134. package/dist/config.d.ts +334 -4
  135. package/dist/config.js +1024 -41
  136. package/dist/context/project_intelligence.d.ts +11 -2
  137. package/dist/context/project_intelligence.js +38 -15
  138. package/dist/desktop/daily/desktop_wiring.js +8 -6
  139. package/dist/desktop/daily/native_pane_launcher.js +2 -1
  140. package/dist/desktop/daily/native_tool.d.ts +1 -1
  141. package/dist/desktop/daily/native_tool.js +4 -3
  142. package/dist/desktop/daily/process_identity.js +10 -2
  143. package/dist/desktop/daily/source_baseline.js +4 -3
  144. package/dist/diagnostics/native_terminal_benchmark.js +3 -2
  145. package/dist/diagnostics/session_export.js +27 -14
  146. package/dist/embedded/anempa_runtime.js +3 -3
  147. package/dist/embedded/gameboy_runtime.js +5 -4
  148. package/dist/embedded/zergpod_runtime.js +5 -4
  149. package/dist/emulation/catalog.js +6 -1
  150. package/dist/emulation/tool_adapters.js +13 -3
  151. package/dist/environment/store.js +5 -4
  152. package/dist/extension_discovery.d.ts +12 -2
  153. package/dist/extension_discovery.js +52 -7
  154. package/dist/headless.d.ts +8 -0
  155. package/dist/headless.js +52 -13
  156. package/dist/headless_cli.js +16 -1
  157. package/dist/headless_workflow_trigger.js +1 -1
  158. package/dist/hooks/dispatcher.d.ts +8 -0
  159. package/dist/hooks/dispatcher.js +22 -2
  160. package/dist/hooks/lifecycle.d.ts +6 -0
  161. package/dist/hooks/lifecycle.js +1 -0
  162. package/dist/hooks/program_files.d.ts +10 -0
  163. package/dist/hooks/program_files.js +175 -0
  164. package/dist/hooks/runner.d.ts +11 -1
  165. package/dist/hooks/runner.js +112 -11
  166. package/dist/hooks/types.d.ts +2 -0
  167. package/dist/host_credentials_startup.d.ts +6 -0
  168. package/dist/host_credentials_startup.js +17 -0
  169. package/dist/instance_registry.d.ts +6 -2
  170. package/dist/instance_registry.js +9 -15
  171. package/dist/intake/format.d.ts +6 -0
  172. package/dist/intake/format.js +9 -0
  173. package/dist/intake/notifications.js +2 -1
  174. package/dist/lsp/manager.d.ts +1 -1
  175. package/dist/lsp/manager.js +4 -5
  176. package/dist/mcp/client.d.ts +2 -0
  177. package/dist/mcp/client.js +116 -18
  178. package/dist/mcp/registry.d.ts +12 -0
  179. package/dist/mcp/registry.js +15 -1
  180. package/dist/modes/handlers.js +14 -5
  181. package/dist/panes/agent_cli.d.ts +23 -1
  182. package/dist/panes/agent_cli.js +96 -1
  183. package/dist/panes/agent_panes.d.ts +27 -4
  184. package/dist/panes/agent_panes.js +73 -11
  185. package/dist/panes/editor_program.d.ts +8 -0
  186. package/dist/panes/editor_program.js +25 -0
  187. package/dist/panes/motsi.d.ts +11 -1
  188. package/dist/panes/motsi.js +14 -1
  189. package/dist/panes/pane_registry.d.ts +28 -1
  190. package/dist/panes/pane_registry.js +25 -0
  191. package/dist/panes/worker_route.js +5 -3
  192. package/dist/panes/ztc_launch.d.ts +8 -0
  193. package/dist/panes/ztc_launch.js +26 -1
  194. package/dist/profile_baseline.js +2 -0
  195. package/dist/router_auth.d.ts +8 -3
  196. package/dist/router_auth.js +34 -2
  197. package/dist/runtime_info.js +56 -38
  198. package/dist/session.js +12 -2
  199. package/dist/shannon/runtime.js +13 -1
  200. package/dist/simulation/domains/loader.d.ts +2 -1
  201. package/dist/simulation/domains/loader.js +19 -2
  202. package/dist/simulation/living/context.d.ts +8 -8
  203. package/dist/simulation/living/types.d.ts +2 -2
  204. package/dist/simulation/memory/embedding.d.ts +2 -1
  205. package/dist/simulation/memory/embedding.js +25 -6
  206. package/dist/terminal_attach.js +2 -1
  207. package/dist/types.d.ts +21 -0
  208. package/dist/ui/ratatui/headless_pane_manager.d.ts +12 -6
  209. package/dist/ui/ratatui/headless_pane_manager.js +65 -21
  210. package/dist/ui/ratatui/ipc_path.d.ts +41 -2
  211. package/dist/ui/ratatui/ipc_path.js +164 -5
  212. package/dist/ui/ratatui/pane_credential_broker.d.ts +17 -4
  213. package/dist/ui/ratatui/pane_credential_broker.js +23 -5
  214. package/dist/ui/ratatui/pane_relay.d.ts +74 -0
  215. package/dist/ui/ratatui/pane_relay.js +188 -13
  216. package/dist/ui/ratatui/process.d.ts +15 -1
  217. package/dist/ui/ratatui/process.js +129 -163
  218. package/dist/ui/ratatui/protocol.d.ts +11 -1
  219. package/dist/ui/ratatui/protocol.js +6 -0
  220. package/dist/ui/ratatui/ztc_launch_trust.d.ts +87 -0
  221. package/dist/ui/ratatui/ztc_launch_trust.js +249 -0
  222. package/dist/utils/admitted_open.d.ts +40 -0
  223. package/dist/utils/admitted_open.js +111 -0
  224. package/dist/utils/clipboard.js +2 -1
  225. package/dist/utils/computer_native.js +12 -56
  226. package/dist/utils/dictation.js +15 -12
  227. package/dist/utils/dictation_native.js +17 -60
  228. package/dist/utils/git_probe_options.d.ts +28 -0
  229. package/dist/utils/git_probe_options.js +30 -0
  230. package/dist/utils/git_program_files.d.ts +145 -0
  231. package/dist/utils/git_program_files.js +1282 -0
  232. package/dist/utils/git_repository_programs.d.ts +13 -0
  233. package/dist/utils/git_repository_programs.js +38 -0
  234. package/dist/utils/host_shell.js +2 -1
  235. package/dist/utils/idle_compaction.js +8 -1
  236. package/dist/utils/image_fit.d.ts +4 -1
  237. package/dist/utils/image_fit.js +6 -2
  238. package/dist/utils/image_preview.js +3 -2
  239. package/dist/utils/mirror_media.d.ts +22 -4
  240. package/dist/utils/mirror_media.js +87 -86
  241. package/dist/utils/ml_native.js +11 -56
  242. package/dist/utils/native_install.d.ts +55 -0
  243. package/dist/utils/native_install.js +107 -0
  244. package/dist/utils/open_url.js +2 -0
  245. package/dist/utils/process_end.d.ts +16 -0
  246. package/dist/utils/process_end.js +73 -0
  247. package/dist/utils/router_catalog.js +9 -2
  248. package/dist/utils/sandbox.d.ts +64 -1
  249. package/dist/utils/sandbox.js +397 -89
  250. package/dist/utils/shell.js +31 -12
  251. package/dist/utils/subprocess_env.d.ts +218 -2
  252. package/dist/utils/subprocess_env.js +429 -11
  253. package/dist/utils/system_ps.d.ts +5 -0
  254. package/dist/utils/system_ps.js +30 -0
  255. package/dist/utils/tts.js +5 -0
  256. package/dist/utils/tts_native.js +13 -60
  257. package/dist/utils/zlicky_overlay.js +17 -50
  258. package/dist/utils/ztc_own_state.d.ts +58 -0
  259. package/dist/utils/ztc_own_state.js +236 -0
  260. package/dist/web/mirror_authenticator.d.ts +67 -6
  261. package/dist/web/mirror_authenticator.js +131 -22
  262. package/dist/web/mirror_stream.d.ts +54 -10
  263. package/dist/web/mirror_stream.js +379 -92
  264. package/dist/web/observer_query_redaction.js +53 -13
  265. package/dist/web/observer_secret_redaction.d.ts +59 -0
  266. package/dist/web/observer_secret_redaction.js +714 -0
  267. package/dist/web/pane_credentials.d.ts +20 -2
  268. package/dist/web/pane_credentials.js +58 -5
  269. package/dist/worker/executor.js +3 -1
  270. package/dist/workspace_collision.js +19 -15
  271. package/dist/zerg/local_zerg_launches.d.ts +27 -0
  272. package/dist/zerg/local_zerg_launches.js +198 -0
  273. package/dist/zlm-embed.mjs +6257 -2791
  274. package/npm-shrinkwrap.json +1 -1
  275. package/package.json +42 -15
@@ -1,3 +1,4 @@
1
+ import { type FileIdentity } from '../utils/ztc_own_state.js';
1
2
  export declare const PROJECT_CONTEXT_SOURCE_LIMIT = 16;
2
3
  export declare const PROJECT_CONTEXT_FILE_BYTES: number;
3
4
  export declare const PROJECT_CONTEXT_TOTAL_BYTES: number;
@@ -40,5 +41,13 @@ export interface ProjectContextQueryResult {
40
41
  indexPath: string;
41
42
  omittedMatches: number;
42
43
  }
43
- export declare function indexProjectContext(root: string, paths: string[]): Promise<ProjectContextIndexResult>;
44
- export declare function queryProjectContext(root: string, query: string, paths?: string[]): Promise<ProjectContextQueryResult>;
44
+ /**
45
+ * How the index reads the files the agent names. `ownStateLink`: under a profile that limits the agent, the check that
46
+ * a file is not one of ZTC's own under another name, a hard link into its config, approvals or sessions, which the
47
+ * policy's check of the path cannot see (utils/ztc_own_state.ts ownStateLinkGuard). Such a file refuses the call.
48
+ */
49
+ export interface ProjectContextReadOptions {
50
+ ownStateLink?: (file: FileIdentity) => Promise<string | null>;
51
+ }
52
+ export declare function indexProjectContext(root: string, paths: string[], options?: ProjectContextReadOptions): Promise<ProjectContextIndexResult>;
53
+ export declare function queryProjectContext(root: string, query: string, paths?: string[], options?: ProjectContextReadOptions): Promise<ProjectContextQueryResult>;
@@ -5,6 +5,9 @@ import { mkdir, open, realpath } from 'node:fs/promises';
5
5
  import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
6
6
  import { promisify } from 'node:util';
7
7
  import { writeFileAtomic } from '../utils/atomic_write.js';
8
+ import { GIT_PROBE_OPTIONS } from '../utils/git_probe_options.js';
9
+ import { buildGitSubprocessEnvFor } from '../utils/subprocess_env.js';
10
+ import { ownStateLinkRefusal } from '../utils/ztc_own_state.js';
8
11
  export const PROJECT_CONTEXT_SOURCE_LIMIT = 16;
9
12
  export const PROJECT_CONTEXT_FILE_BYTES = 16 * 1024;
10
13
  export const PROJECT_CONTEXT_TOTAL_BYTES = 128 * 1024;
@@ -30,8 +33,11 @@ function sourcePaths(paths) {
30
33
  throw new TypeError('Project context paths must be strings');
31
34
  return [...new Set(paths.map(sourcePath))].sort();
32
35
  }
36
+ /** A source that is one of ZTC's own under another name: the call is refused, before a byte of it is read. */
37
+ class OwnStateLinkError extends Error {
38
+ }
33
39
  /** One regular source at a time; even a growing file cannot exceed limit + 1 bytes. */
34
- async function readBounded(root, path, limit) {
40
+ async function readBounded(root, path, limit, options = {}) {
35
41
  let readBytes = 0;
36
42
  try {
37
43
  const absolute = join(root, path);
@@ -42,6 +48,9 @@ async function readBounded(root, path, limit) {
42
48
  const stat = await handle.stat();
43
49
  if (!stat.isFile())
44
50
  return { reason: 'unreadable', readBytes };
51
+ const holding = options.ownStateLink ? await options.ownStateLink(stat) : null;
52
+ if (holding !== null)
53
+ throw new OwnStateLinkError(ownStateLinkRefusal(path, holding));
45
54
  if (stat.size > limit)
46
55
  return { reason: 'oversized', readBytes };
47
56
  const buffer = Buffer.alloc(limit + 1);
@@ -58,43 +67,56 @@ async function readBounded(root, path, limit) {
58
67
  }
59
68
  }
60
69
  catch (error) {
70
+ if (error instanceof OwnStateLinkError)
71
+ throw error;
61
72
  return { reason: error instanceof Error && 'code' in error && error.code === 'ENOENT' ? 'missing' : 'unreadable', readBytes };
62
73
  }
63
74
  }
64
- async function git(root, args, maxBytes) {
75
+ /**
76
+ * The environment of ROOT's git: a user subprocess's, since git runs the repository's hooks and helpers with it, so
77
+ * none of ZTC's credentials; a ROOT with a repository of its own takes no repository variable of ZTC's environment,
78
+ * so it reads ROOT's, and a vcsh or yadm work tree, which has none, keeps those that name its repository
79
+ * (buildGitSubprocessEnvFor).
80
+ */
81
+ function gitEnvironment(root) {
82
+ return { ...buildGitSubprocessEnvFor(root), GIT_OPTIONAL_LOCKS: '0' };
83
+ }
84
+ async function git(root, env, args, maxBytes) {
65
85
  try {
66
- const result = await execute('git', ['--no-pager', '-C', root, ...args], { encoding: null, timeout: 2000, maxBuffer: maxBytes,
67
- env: { ...process.env, GIT_OPTIONAL_LOCKS: '0' }, windowsHide: true });
86
+ // ZTC's own git in the work tree: no program the repository's config names (utils/git_probe_options.ts).
87
+ const result = await execute('git', ['--no-pager', '-C', root, ...GIT_PROBE_OPTIONS, ...args], { encoding: null, timeout: 2000, maxBuffer: maxBytes,
88
+ env, windowsHide: true });
68
89
  return result.stdout;
69
90
  }
70
91
  catch {
71
92
  return null;
72
93
  } // Missing Git/objects are unknown provenance, never a positive binding.
73
94
  }
74
- async function committedSource(root, path, head, sha256) {
95
+ async function committedSource(root, env, path, head, sha256) {
75
96
  if (!head)
76
97
  return false;
77
- const top = await git(root, ['rev-parse', '--show-toplevel'], 4096);
98
+ const top = await git(root, env, ['rev-parse', '--show-toplevel'], 4096);
78
99
  if (!top)
79
100
  return false;
80
101
  const repository = await realpath(top.toString('utf8').trim()).catch(() => null);
81
102
  if (!repository || !within(repository, root))
82
103
  return false;
83
104
  const name = relative(repository, join(root, path)).split(sep).join('/');
84
- const original = await git(root, ['show', `${head}:${name}`], PROJECT_CONTEXT_FILE_BYTES + 1);
105
+ const original = await git(root, env, ['show', `${head}:${name}`], PROJECT_CONTEXT_FILE_BYTES + 1);
85
106
  return original !== null && digest(original) === sha256;
86
107
  }
87
- export async function indexProjectContext(root, paths) {
108
+ export async function indexProjectContext(root, paths, options = {}) {
88
109
  const selected = sourcePaths(paths);
89
110
  const canonical = await realpath(resolve(root));
90
111
  const snapshot = { schemaVersion: 1, root: canonical, sources: [], skipped: [] };
91
- const rawHead = await git(canonical, ['rev-parse', '--verify', 'HEAD'], 256);
112
+ const env = gitEnvironment(canonical);
113
+ const rawHead = await git(canonical, env, ['rev-parse', '--verify', 'HEAD'], 256);
92
114
  const candidateHead = rawHead?.toString('utf8').trim() ?? '';
93
115
  const head = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(candidateHead) ? candidateHead : null;
94
116
  let sourceBytes = 0;
95
117
  let readBytes = 0;
96
118
  for (const path of selected) {
97
- const loaded = await readBounded(canonical, path, PROJECT_CONTEXT_FILE_BYTES);
119
+ const loaded = await readBounded(canonical, path, PROJECT_CONTEXT_FILE_BYTES, options);
98
120
  readBytes += loaded.readBytes;
99
121
  if ('reason' in loaded) {
100
122
  snapshot.skipped.push({ path, reason: loaded.reason });
@@ -110,7 +132,7 @@ export async function indexProjectContext(root, paths) {
110
132
  }
111
133
  const sha256 = digest(loaded.content);
112
134
  const entry = { path, content, sha256, bytes: loaded.content.length,
113
- git: { head, committed: await committedSource(canonical, path, head, sha256) } };
135
+ git: { head, committed: await committedSource(canonical, env, path, head, sha256) } };
114
136
  if (sourceBytes + entry.bytes > PROJECT_CONTEXT_TOTAL_BYTES
115
137
  || Buffer.byteLength(JSON.stringify({ ...snapshot, sources: [...snapshot.sources, entry] })) > PROJECT_CONTEXT_INDEX_BYTES - 4096) {
116
138
  snapshot.skipped.push({ path, reason: 'budget' });
@@ -196,7 +218,7 @@ function excerpt(line) {
196
218
  }
197
219
  return { excerpt: text };
198
220
  }
199
- export async function queryProjectContext(root, query, paths) {
221
+ export async function queryProjectContext(root, query, paths, options = {}) {
200
222
  if (typeof query !== 'string' || !query.trim() || Buffer.byteLength(query) > 256) {
201
223
  throw new RangeError('Project context query must contain 1 to 256 UTF-8 bytes');
202
224
  }
@@ -204,7 +226,7 @@ export async function queryProjectContext(root, query, paths) {
204
226
  const canonical = await realpath(resolve(root));
205
227
  const indexPath = join(canonical, PROJECT_CONTEXT_INDEX_PATH);
206
228
  const base = { matches: [], unknownSources: [], indexPath, omittedMatches: 0 };
207
- const loaded = await readBounded(canonical, PROJECT_CONTEXT_INDEX_PATH, PROJECT_CONTEXT_INDEX_BYTES);
229
+ const loaded = await readBounded(canonical, PROJECT_CONTEXT_INDEX_PATH, PROJECT_CONTEXT_INDEX_BYTES, options);
208
230
  if ('reason' in loaded)
209
231
  return { ...base, status: loaded.reason === 'missing' ? 'missing_index' : 'invalid_index' };
210
232
  let snapshot;
@@ -217,6 +239,7 @@ export async function queryProjectContext(root, query, paths) {
217
239
  const matches = [];
218
240
  let omittedMatches = 0;
219
241
  const unknownSources = snapshot.skipped.filter(entry => !selected || selected.has(entry.path));
242
+ const env = gitEnvironment(canonical);
220
243
  for (const source of snapshot.sources) {
221
244
  if (selected && !selected.has(source.path))
222
245
  continue;
@@ -228,12 +251,12 @@ export async function queryProjectContext(root, query, paths) {
228
251
  omittedMatches += 1;
229
252
  continue;
230
253
  }
231
- const current = await readBounded(canonical, source.path, PROJECT_CONTEXT_FILE_BYTES);
254
+ const current = await readBounded(canonical, source.path, PROJECT_CONTEXT_FILE_BYTES, options);
232
255
  const state = 'reason' in current ? current.reason === 'missing' ? 'missing' : 'unreadable'
233
256
  : digest(current.content) === source.sha256 ? 'current' : 'stale';
234
257
  const original = summary(source);
235
258
  original.git = { ...original.git, committed: original.git.committed
236
- && await committedSource(canonical, source.path, original.git.head, original.sha256) };
259
+ && await committedSource(canonical, env, source.path, original.git.head, original.sha256) };
237
260
  matches.push({ source: original, state, ...excerpt(lines[line]), line: line + 1 });
238
261
  }
239
262
  if (selected)
@@ -2,6 +2,7 @@ import { OwnerSeals } from './owner_seals.js';
2
2
  import { ownerDirectory, atomicOwnerFile } from './owner_files.js';
3
3
  import { removeLegacyCodexHomes } from './legacy_codex_homes.js';
4
4
  import { execFile } from 'node:child_process';
5
+ import { buildUserSubprocessEnv } from '../../utils/subprocess_env.js';
5
6
  import { constants } from 'node:fs';
6
7
  import { access, mkdir, realpath, open } from 'node:fs/promises';
7
8
  import { homedir } from 'node:os';
@@ -12,8 +13,8 @@ import { setTimeout as delay } from 'node:timers/promises';
12
13
  import { inspectWorkspaceSessions, prepareWorkspaceIsolation } from '../../workspace_collision.js';
13
14
  import { getVersion } from '../../utils/version.js';
14
15
  import { newZtcPaneRouteArgs } from '../../panes/ztc_launch.js';
15
- import { agentPermissionsSetting, permissionDefaultArgs } from '../../panes/agent_cli.js';
16
- import { configStore } from '../../config.js';
16
+ import { permissionDefaultArgs } from '../../panes/agent_cli.js';
17
+ import { personPanePermissions } from '../../panes/agent_panes.js';
17
18
  import { DailyStore } from './daily_store.js';
18
19
  import { createControlServer, readTaskFile } from './control_server.js';
19
20
  import { createApprovalBroker } from './broker.js';
@@ -542,11 +543,12 @@ export class DesktopDaily {
542
543
  if (record.launch.tool === 'ztc')
543
544
  record.launch.args = [...record.launch.args, ...newZtcPaneRouteArgs()];
544
545
  // A native Claude Code or Codex pane is one the person types into, as any ZTC opens: it starts without permission
545
- // prompts unless ZTC's setting says ask (panes.agentPermissions), or the CLI would refuse its flag here (Claude Code
546
- // as root). A delegated worker never gets here.
546
+ // prompts unless ZTC's setting says ask (panes.agentPermissions, here or in config.json as it is saved now, which
547
+ // another pane may have changed since this ZTC read it), or the CLI would refuse its flag here (Claude Code as root).
548
+ // A delegated worker never gets here.
547
549
  if (record.launch.tool === 'claude_code' || record.launch.tool === 'codex') {
548
550
  const cli = record.launch.tool === 'codex' ? 'codex' : 'claude';
549
- record.launch.args = [...permissionDefaultArgs(cli, record.launch.args, agentPermissionsSetting(configStore.get().panes), { env: this.host.env ?? process.env }), ...record.launch.args];
551
+ record.launch.args = [...permissionDefaultArgs(cli, record.launch.args, await personPanePermissions(), { env: this.host.env ?? process.env }), ...record.launch.args];
550
552
  }
551
553
  let lease = await this.lease(record, !saved);
552
554
  let accepted = false;
@@ -944,7 +946,7 @@ export class DesktopDaily {
944
946
  live.lease = await bindLeaseSession(live.lease, live.record.identity.canonicalId, this.leaseOptions());
945
947
  if (live.record.process && Date.now() - live.lastHeartbeat > 10000) {
946
948
  const start = await observeProcessStart(live.record.process.leaderPid);
947
- const status = await exec('/bin/ps', ['-p', String(live.record.process.leaderPid), '-o', 'state=']).then(result => result.stdout.trim()).catch(() => '');
949
+ const status = await exec('/bin/ps', ['-p', String(live.record.process.leaderPid), '-o', 'state='], { env: buildUserSubprocessEnv() }).then(result => result.stdout.trim()).catch(() => '');
948
950
  if (!status.startsWith('T') && start !== null && Math.abs(start - live.record.process.leaderStartMs) <= 2000) {
949
951
  live.lease = await heartbeat(live.lease, this.leaseOptions(), live.record.process);
950
952
  live.lastHeartbeat = Date.now();
@@ -1,4 +1,5 @@
1
1
  import { execFile } from 'node:child_process';
2
+ import { buildUserSubprocessEnv } from '../../utils/subprocess_env.js';
2
3
  import { constants, lstatSync, renameSync } from 'node:fs';
3
4
  import { open, unlink, realpath } from 'node:fs/promises';
4
5
  import { join, basename, dirname } from 'node:path';
@@ -48,7 +49,7 @@ async function receiptFile(path) {
48
49
  }
49
50
  }
50
51
  async function parentOf(pid) {
51
- return exec('/bin/ps', ['-p', String(pid), '-o', 'ppid=']).then(value => Number(value.stdout.trim()) || null).catch(() => null);
52
+ return exec('/bin/ps', ['-p', String(pid), '-o', 'ppid='], { env: buildUserSubprocessEnv() }).then(value => Number(value.stdout.trim()) || null).catch(() => null);
52
53
  }
53
54
  export async function prepareNativeLauncher(directory, record, control, env = process.env, resume = false) {
54
55
  if (record.launch.mode !== 'interactive' || record.launch.task !== undefined)
@@ -103,9 +103,9 @@ export interface NativeToolPaneRecord {
103
103
  export declare const nativeIdentitySchema: z.ZodObject<{
104
104
  canonicalId: z.ZodNullable<z.ZodUUID>;
105
105
  source: z.ZodEnum<{
106
+ none: "none";
106
107
  launcher_assigned: "launcher_assigned";
107
108
  tool_reported: "tool_reported";
108
- none: "none";
109
109
  }>;
110
110
  state: z.ZodEnum<{
111
111
  bound: "bound";
@@ -4,6 +4,7 @@ import { realpath } from 'node:fs/promises';
4
4
  import { isAbsolute } from 'node:path';
5
5
  import { promisify } from 'node:util';
6
6
  import { z } from 'zod';
7
+ import { buildGitSubprocessEnv } from '../../utils/subprocess_env.js';
7
8
  const count = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
8
9
  const pid = count.min(1);
9
10
  const text = z.string().max(65536);
@@ -55,9 +56,9 @@ export function parseNativeToolPaneRecord(value) {
55
56
  }
56
57
  const exec = promisify(execFile);
57
58
  export async function readWorktreeIdentity(cwd) {
58
- const env = { ...process.env, GIT_OPTIONAL_LOCKS: '0', GIT_TERMINAL_PROMPT: '0' };
59
- for (const key of ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_COMMON_DIR', 'GIT_INDEX_FILE'])
60
- delete env[key];
59
+ // CWD's worktree, whatever repository this process's environment names (REPOSITORY_GIT_ENV). git runs the programs its
60
+ // config names and writes the variables trace2.envVars names, so it gets a user subprocess's environment.
61
+ const env = { ...buildGitSubprocessEnv(), GIT_OPTIONAL_LOCKS: '0', GIT_TERMINAL_PROMPT: '0' };
61
62
  const git = async (args) => {
62
63
  const result = await exec('git', ['-C', cwd, ...args], { env, timeout: 2000, maxBuffer: 1024 * 1024, windowsHide: true });
63
64
  return result.stdout.trim();
@@ -1,9 +1,17 @@
1
1
  import { execFile } from 'node:child_process';
2
2
  import { setTimeout as delay } from 'node:timers/promises';
3
3
  import { promisify } from 'node:util';
4
+ import { buildUserSubprocessEnv } from '../../utils/subprocess_env.js';
4
5
  import { observedProcessStart } from '../../workspace_collision.js';
5
6
  import { processIdentitySchema } from './native_tool.js';
6
7
  const exec = promisify(execFile);
8
+ /*
9
+ * The ps a launch's processes are read with is the one found on PATH, where a command the agent runs can put a
10
+ * program of its own under that name, so each call gives it a user subprocess's environment, as the workspace check's
11
+ * ps does (workspace_collision.observedProcessStart): the person's own and none of ZTC's credentials (the mirror's
12
+ * token minted at runtime, a Router grant) or a copy of one. The env is written at each call, where the child-process
13
+ * lint (tests/unit/child_process_env_lint.test.ts) reads it.
14
+ */
7
15
  export async function observeProcessStart(pid) {
8
16
  if (!Number.isSafeInteger(pid) || pid < 1)
9
17
  return null;
@@ -11,7 +19,7 @@ export async function observeProcessStart(pid) {
11
19
  }
12
20
  async function processes() {
13
21
  try {
14
- const result = await exec('ps', ['-axo', 'pid=,ppid=,pgid=,stat='], { timeout: 2000, maxBuffer: 4 * 1024 * 1024 });
22
+ const result = await exec('ps', ['-axo', 'pid=,ppid=,pgid=,stat='], { timeout: 2000, maxBuffer: 4 * 1024 * 1024, env: buildUserSubprocessEnv() });
15
23
  const rows = [];
16
24
  for (const line of result.stdout.trim().split('\n')) {
17
25
  const [pid, ppid, pgid, stat] = line.trim().split(/\s+/);
@@ -30,7 +38,7 @@ export async function processGroupOf(pid) {
30
38
  if (!Number.isSafeInteger(pid) || pid < 1)
31
39
  return null;
32
40
  try {
33
- const result = await exec('ps', ['-o', 'pgid=', '-p', String(pid)], { timeout: 2000, maxBuffer: 1024 });
41
+ const result = await exec('ps', ['-o', 'pgid=', '-p', String(pid)], { timeout: 2000, maxBuffer: 1024, env: buildUserSubprocessEnv() });
34
42
  const value = Number(result.stdout.trim());
35
43
  return Number.isSafeInteger(value) && value > 0 ? value : null;
36
44
  }
@@ -4,6 +4,7 @@ import { lstat, readdir, readlink, realpath } from 'node:fs/promises';
4
4
  import { join } from 'node:path';
5
5
  import { execFile } from 'node:child_process';
6
6
  import { promisify } from 'node:util';
7
+ import { GIT_PROBE_OPTIONS } from '../../utils/git_probe_options.js';
7
8
  async function files(root) {
8
9
  const result = Object.create(null);
9
10
  const walk = async (directory, prefix = '') => {
@@ -31,9 +32,9 @@ async function files(root) {
31
32
  }
32
33
  export async function observeSource(root) {
33
34
  const canonical = await realpath(root);
34
- // The agent the daily driver launches writes this work tree: git runs no core.fsmonitor command from its config,
35
- // and safe.bareRepository=explicit stops it reading a planted implicit bare repository's config.
36
- const dirty = await promisify(execFile)('git', ['-c', 'core.fsmonitor=false', '-c', 'safe.bareRepository=explicit', '-C', canonical, 'status', '--porcelain', '--untracked-files=all'], { env: { PATH: process.env.PATH, GIT_OPTIONAL_LOCKS: '0', GIT_TERMINAL_PROMPT: '0' }, timeout: 5000 }).then(value => !!value.stdout.trim()).catch(() => false);
35
+ // The agent the daily driver launches writes this work tree: git runs no program its config names, and reads no
36
+ // planted implicit bare repository's config (utils/git_probe_options.ts).
37
+ const dirty = await promisify(execFile)('git', [...GIT_PROBE_OPTIONS, '-C', canonical, 'status', '--porcelain', '--untracked-files=all'], { env: { PATH: process.env.PATH, GIT_OPTIONAL_LOCKS: '0', GIT_TERMINAL_PROMPT: '0' }, timeout: 5000 }).then(value => !!value.stdout.trim()).catch(() => false);
37
38
  return { root: canonical, dirty, files: await files(canonical) };
38
39
  }
39
40
  export async function sourceChanged(baseline) {
@@ -1,4 +1,5 @@
1
1
  import cp from 'node:child_process';
2
+ import { buildUserSubprocessEnv } from '../utils/subprocess_env.js';
2
3
  import { createHash } from 'node:crypto';
3
4
  import { createWriteStream } from 'node:fs';
4
5
  import { access, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
@@ -442,7 +443,7 @@ async function echoSamples(session, pane, condition, count, active) {
442
443
  sampleIntervalMs: 40, readPollDelayMs: 2, boundary: 'Public write_pane to public read_pane echoed marker; includes IPC/polling; no physical keyboard' };
443
444
  }
444
445
  async function resources(pid) {
445
- const { stdout } = await execFile('/bin/ps', ['-o', 'rss=,time=', '-p', String(pid)]);
446
+ const { stdout } = await execFile('/bin/ps', ['-o', 'rss=,time=', '-p', String(pid)], { env: buildUserSubprocessEnv() });
446
447
  const [rss, clock] = stdout.trim().split(/\s+/);
447
448
  const pieces = clock.split(':').map(Number);
448
449
  const cpuSeconds = pieces.reduce((total, value) => total * 60 + value, 0);
@@ -488,7 +489,7 @@ async function fileAbsent(path) {
488
489
  async function hostInventory() {
489
490
  const query = async (command, args) => {
490
491
  try {
491
- return (await execFile(command, args)).stdout.trim();
492
+ return (await execFile(command, args, { env: buildUserSubprocessEnv() })).stdout.trim();
492
493
  }
493
494
  catch {
494
495
  return null;
@@ -1,4 +1,6 @@
1
1
  import { createHash } from 'node:crypto';
2
+ import { liveCredentialValues } from '../config/host_credentials.js';
3
+ import { isLivePaneCredential, PANE_CREDENTIAL_ENV } from '../web/pane_credentials.js';
2
4
  export const DIAGNOSTIC_LIMITS = Object.freeze({
3
5
  events: 1024,
4
6
  snapshotBytes: 1024 * 1024,
@@ -89,6 +91,17 @@ function collectCredentials(value, found, depth = 0) {
89
91
  collectCredentials(item, found, depth + 1);
90
92
  }
91
93
  }
94
+ /**
95
+ * The credentials to withhold wherever they appear in VALUE: every one ZTC holds (the host's Router runtime grant, its
96
+ * platform login, the mirror's secret and token, ...: liveCredentialValues, backed by the host-credential store, so a
97
+ * scrubbed process.env can't switch this off), whether or not VALUE names it, and each string VALUE's sensitive keys
98
+ * hold.
99
+ */
100
+ function credentialsIn(value) {
101
+ const found = new Set(liveCredentialValues());
102
+ collectCredentials(value, found);
103
+ return found;
104
+ }
92
105
  function redactKnownCredentials(value, credentials) {
93
106
  let result = value;
94
107
  for (const credential of credentials)
@@ -111,8 +124,15 @@ function redactString(value, credentials) {
111
124
  }
112
125
  return current;
113
126
  }
127
+ /** A run of base64url characters as long as a pane credential, which the pane credential store knows by digest. */
128
+ const PANE_CREDENTIAL_RUN = /(?<![A-Za-z0-9_-])[A-Za-z0-9_-]{43}(?![A-Za-z0-9_-])/g;
129
+ /** What follows ZTC_MIRROR_PANE_TOKEN=, a pane's own mirror credential, live or not. */
130
+ const PANE_CREDENTIAL_ASSIGNMENT = new RegExp(`(\\b${PANE_CREDENTIAL_ENV}["']?\\s*[=:]\\s*)(?!\\[REDACTED\\])(?:"[^"\\r\\n]*"|'[^'\\r\\n]*'|[^\\s,;"']+)`, 'g');
114
131
  function redactStringOnce(value, credentials) {
115
132
  return redactKnownCredentials(value, credentials)
133
+ // A live pane credential (web/pane_credentials.ts), wherever it appears, and a pane's credential by its name.
134
+ .replace(PANE_CREDENTIAL_RUN, run => isLivePaneCredential(run) ? '[REDACTED]' : run)
135
+ .replace(PANE_CREDENTIAL_ASSIGNMENT, '$1[REDACTED]')
116
136
  .replace(/-----BEGIN (?:[A-Z ]*PRIVATE KEY|OPENSSH PRIVATE KEY)-----[\s\S]*?(?:-----END (?:[A-Z ]*PRIVATE KEY|OPENSSH PRIVATE KEY)-----|$)/g, '[REDACTED PRIVATE KEY]')
117
137
  .replace(/\b(?:Bearer|Basic)\s+[A-Za-z0-9_~+/=.:-]+/gi, match => `${match.split(/\s/)[0]} [REDACTED]`)
118
138
  .replace(/\b(?:sk-[A-Za-z0-9_-]{10,}|gh[pousr]_[A-Za-z0-9_]{10,}|xox[baprs]-[A-Za-z0-9-]{10,})\b/g, '[REDACTED]')
@@ -180,8 +200,7 @@ function redactJson(value, credentials, depth = 0, options = {}, path = []) {
180
200
  export function redactDiagnosticValue(value, options = {}) {
181
201
  if (!jsonValid(value))
182
202
  throw new DiagnosticExportError('Invalid, cyclic, or excessively deep JSON diagnostic value', 'INVALID_EXPORT');
183
- const credentials = new Set();
184
- collectCredentials(value, credentials);
203
+ const credentials = credentialsIn(value);
185
204
  return redactJson(value, [...credentials].sort((a, b) => b.length - a.length), 0, options);
186
205
  }
187
206
  function truncation(field, full, retained, availability) {
@@ -190,8 +209,7 @@ function truncation(field, full, retained, availability) {
190
209
  reference: `sha256:${digest}`, availability };
191
210
  }
192
211
  export function describeDiagnosticTruncation(field, fullText, retainedText, availability) {
193
- const credentials = new Set();
194
- collectCredentials([fullText, retainedText], credentials);
212
+ const credentials = credentialsIn([fullText, retainedText]);
195
213
  const known = [...credentials].sort((a, b) => b.length - a.length);
196
214
  const full = redactJson(fullText, known);
197
215
  const retained = redactJson(retainedText, known);
@@ -309,8 +327,7 @@ export function recordDiagnosticEvent(snapshot, event) {
309
327
  throw new DiagnosticExportError('Invalid, cyclic, or excessively deep JSON diagnostic event', 'INVALID_EXPORT');
310
328
  }
311
329
  const present = Object.fromEntries(Object.entries(event).filter(([, value]) => value !== undefined));
312
- const credentials = new Set();
313
- collectCredentials(event, credentials);
330
+ const credentials = credentialsIn(event);
314
331
  const admitted = boundEvent({ ...present, recordType: 'event' }, [...credentials].sort((a, b) => b.length - a.length));
315
332
  if (!eventValid(admitted))
316
333
  throw new DiagnosticExportError('Diagnostic event has invalid kind, origin, identity, or timestamp', 'INVALID_EXPORT');
@@ -777,8 +794,7 @@ export function captureSessionDiagnosticSnapshot(input) {
777
794
  const projected = projectMessages(input.messages.filter(retainedMessage));
778
795
  // Credential context includes provisional rows even though their mutable
779
796
  // facts are excluded from retention; another admitted row can echo a secret.
780
- const credentials = new Set();
781
- collectCredentials([input.messages, history.events], credentials);
797
+ const credentials = credentialsIn([input.messages, history.events]);
782
798
  const known = [...credentials].sort((a, b) => b.length - a.length);
783
799
  const prior = history.events.map(event => boundEvent(event, known));
784
800
  const current = projected.map(event => boundEvent(event, known));
@@ -815,8 +831,7 @@ export function repairLoadedDiagnosticSnapshot(snapshot, messages) {
815
831
  });
816
832
  if (differing.length === 0)
817
833
  return snapshot;
818
- const credentials = new Set();
819
- collectCredentials([messages, history.events], credentials);
834
+ const credentials = credentialsIn([messages, history.events]);
820
835
  const known = [...credentials].sort((a, b) => b.length - a.length);
821
836
  const fresh = new Map(differing.map(event => [event.id, boundEvent(event, known)]));
822
837
  let repaired = 0;
@@ -846,8 +861,7 @@ export function buildSessionDiagnosticDocument(input) {
846
861
  throw new DiagnosticExportError('Diagnostic session header identity exceeds its 16384-byte limit', 'LIMIT_EXCEEDED');
847
862
  }
848
863
  let snapshot = captureSessionDiagnosticSnapshot(input);
849
- const credentials = new Set();
850
- collectCredentials([input.messages, input.diagnostics?.events ?? []], credentials);
864
+ const credentials = credentialsIn([input.messages, input.diagnostics?.events ?? []]);
851
865
  const known = [...credentials].sort((a, b) => b.length - a.length);
852
866
  // Pending inputs and mutable display cards remain useful live observations,
853
867
  // but never enter the durable ledger as immutable admitted source facts.
@@ -886,8 +900,7 @@ export function parseDiagnosticExport(text) {
886
900
  const ids = events.flatMap(item => item.id === null ? [] : [item.id]);
887
901
  if (new Set(ids).size !== ids.length)
888
902
  throw new DiagnosticExportError('Diagnostic export contains duplicate event identity', 'INVALID_EXPORT');
889
- const credentials = new Set();
890
- collectCredentials(events, credentials);
903
+ const credentials = credentialsIn(events);
891
904
  const known = [...credentials].sort((a, b) => b.length - a.length);
892
905
  return { header: { ...header, sessionId: header.sessionId === null ? null : redactString(header.sessionId, known) },
893
906
  events: events.map(item => boundEvent(item, known)) };
@@ -1,7 +1,7 @@
1
1
  import { spawn } from 'child_process';
2
2
  import { existsSync, mkdirSync, readFileSync } from 'fs';
3
3
  import { join } from 'path';
4
- import { withoutMirrorCredentials } from '../web/pane_credentials.js';
4
+ import { buildUserSubprocessEnv } from '../utils/subprocess_env.js';
5
5
  const DEFAULT_REFRESH_MS = 5000;
6
6
  const EVENT_LIMIT = 28;
7
7
  function runtime_refresh_ms(system) {
@@ -196,8 +196,8 @@ export class AnempaRuntimeSession {
196
196
  const child = spawn(join(this.context.system.projectDir, 'scripts', 'run_simulator.sh'), [], {
197
197
  cwd: this.context.system.projectDir,
198
198
  stdio: ['ignore', 'ignore', 'pipe'],
199
- // Without the mirror credentials this process holds, which any program running as this user could read there.
200
- env: withoutMirrorCredentials(process.env),
199
+ // A program of the project: the person's own environment, none of ZTC's credentials.
200
+ env: buildUserSubprocessEnv(process.env),
201
201
  });
202
202
  this.activeChild = child;
203
203
  let stderr = '';
@@ -2,7 +2,7 @@ import { spawn } from 'child_process';
2
2
  import { existsSync, mkdirSync, writeFileSync } from 'fs';
3
3
  import { join } from 'path';
4
4
  import { createInterface } from 'readline';
5
- import { withoutMirrorCredentials } from '../web/pane_credentials.js';
5
+ import { buildUserSubprocessEnv } from '../utils/subprocess_env.js';
6
6
  const DEFAULT_TICK_MS = 33;
7
7
  const DEFAULT_FRAME_BUDGET = 12000;
8
8
  const DEFAULT_WARMUP_FRAME_BUDGET = 96000;
@@ -188,8 +188,8 @@ async function run_script(projectDir, scriptPath) {
188
188
  const child = spawn('zsh', ['-lc', `cd "${projectDir}" && "${scriptPath}"`], {
189
189
  cwd: projectDir,
190
190
  stdio: ['ignore', 'ignore', 'pipe'],
191
- // Without the mirror credentials this process holds, which any program running as this user could read there.
192
- env: withoutMirrorCredentials(process.env),
191
+ // A program of the project: the person's own environment, none of ZTC's credentials.
192
+ env: buildUserSubprocessEnv(process.env),
193
193
  });
194
194
  let stderr = '';
195
195
  child.stderr.on('data', (chunk) => {
@@ -264,7 +264,8 @@ export class GameboyRuntimeSession {
264
264
  cwd: this.system.projectDir,
265
265
  stdio: ['pipe', 'pipe', 'pipe'],
266
266
  env: {
267
- ...withoutMirrorCredentials(process.env),
267
+ // A program of the project: the person's own environment, none of ZTC's credentials, and the runtime's settings.
268
+ ...buildUserSubprocessEnv(process.env),
268
269
  PYTHONDONTWRITEBYTECODE: '1',
269
270
  },
270
271
  });
@@ -2,7 +2,7 @@ import { spawn } from 'child_process';
2
2
  import { existsSync, mkdirSync, readFileSync } from 'fs';
3
3
  import { join } from 'path';
4
4
  import { createInterface } from 'readline';
5
- import { withoutMirrorCredentials } from '../web/pane_credentials.js';
5
+ import { buildUserSubprocessEnv } from '../utils/subprocess_env.js';
6
6
  const DEFAULT_TICK_MS = 180;
7
7
  const DEFAULT_FRAME_BUDGET = 64;
8
8
  const ARTIFACT_REFRESH_MS = 1000;
@@ -349,8 +349,8 @@ async function run_script(projectDir, scriptPath) {
349
349
  const child = spawn('zsh', ['-lc', `cd "${projectDir}" && "${scriptPath}"`], {
350
350
  cwd: projectDir,
351
351
  stdio: ['ignore', 'ignore', 'pipe'],
352
- // Without the mirror credentials this process holds, which any program running as this user could read there.
353
- env: withoutMirrorCredentials(process.env),
352
+ // A program of the project: the person's own environment, none of ZTC's credentials.
353
+ env: buildUserSubprocessEnv(process.env),
354
354
  });
355
355
  let stderr = '';
356
356
  child.stderr.on('data', (chunk) => {
@@ -419,7 +419,8 @@ export class ZergpodRuntimeSession {
419
419
  cwd: this.system.projectDir,
420
420
  stdio: ['pipe', 'pipe', 'pipe'],
421
421
  env: {
422
- ...withoutMirrorCredentials(process.env),
422
+ // A program of the project: the person's own environment, none of ZTC's credentials, and the runtime's settings.
423
+ ...buildUserSubprocessEnv(process.env),
423
424
  PYTHONDONTWRITEBYTECODE: '1',
424
425
  ...(this.hardwareProfileId ? { ZERGPOD_HARDWARE_PROFILE: this.hardwareProfileId } : {}),
425
426
  },
@@ -318,7 +318,12 @@ export function buildRuntimeContext(context) {
318
318
  const porcelain = snapshot.porcelain;
319
319
  const commits = snapshot.recentCommits;
320
320
  lines.push('', 'gitStatus: This is the git status at the start of the conversation.', `Current branch: ${branch}`, `Main branch (you will usually use this for PRs): ${mainBranch}`);
321
- if (porcelain.length > 0) {
321
+ if (snapshot.git.status === 'unknown') {
322
+ // Unread (a probe that failed, or one ZTC does not run where the agent may have written the repository's config,
323
+ // see utils/git_repository_programs.ts): not clean.
324
+ lines.push('', 'Status:', '(not read: run `git status` to see it)');
325
+ }
326
+ else if (porcelain.length > 0) {
322
327
  const staged = [];
323
328
  const unstaged = [];
324
329
  const untracked = [];
@@ -1,5 +1,5 @@
1
1
  import { ToolCapability } from '../agent/runtime/capabilities.js';
2
- import { admitLockedWrite, applyExactReplace, resolvePath, updateFileAtomic, writeAdmissionPath } from '../agent/tools/file.js';
2
+ import { admitLockedWrite, applyExactReplace, openAdmission, resolvePath, updateFileAtomic, writeAdmissionPath } from '../agent/tools/file.js';
3
3
  import { buildSimpleDiffMeta } from '../utils/diff.js';
4
4
  import { runCommandTool, SHELL_TEXT_NOTE } from '../agent/tools/shell.js';
5
5
  const CLAUDE_PROFILE_IDS = new Set(['claude-code']);
@@ -104,6 +104,8 @@ function makeClaudeAdapters(tools) {
104
104
  const readCursors = new Map();
105
105
  return [
106
106
  {
107
+ // Its command runs through run_command, in the OS sandbox the profile asks for.
108
+ sandboxedCommands: true,
107
109
  capabilities: [ToolCapability.SHELL_EXEC, ToolCapability.FILE_WRITE],
108
110
  resolveExecutionCwd: (args, context) => resolveClaudeBashCwd(tools, args, context),
109
111
  // Bash runs its command and drops any `checked` plan beside it.
@@ -258,6 +260,8 @@ function makeClaudeAdapters(tools) {
258
260
  execute: async (args, context) => multiEditFile(tools, args, context),
259
261
  },
260
262
  {
263
+ // Its rg runs through run_command (see Tool.confinedCommands).
264
+ confinedCommands: true,
261
265
  capabilities: [ToolCapability.FILE_READ, ToolCapability.SHELL_EXEC],
262
266
  definition: {
263
267
  name: 'Glob',
@@ -316,6 +320,8 @@ function makeClaudeAdapters(tools) {
316
320
  }, context),
317
321
  },
318
322
  {
323
+ // delegate_task's workers run their commands through run_command (see Tool.confinedCommands).
324
+ confinedCommands: true,
319
325
  capabilities: [ToolCapability.FILE_READ, ToolCapability.SHELL_EXEC],
320
326
  definition: {
321
327
  name: 'Task',
@@ -330,6 +336,8 @@ function makeClaudeAdapters(tools) {
330
336
  }, context),
331
337
  },
332
338
  {
339
+ // Its curl runs through run_command (see Tool.confinedCommands).
340
+ confinedCommands: true,
333
341
  capabilities: [ToolCapability.NETWORK, ToolCapability.SHELL_EXEC],
334
342
  definition: {
335
343
  name: 'WebFetch',
@@ -368,6 +376,8 @@ function makeCodexAdapters(tools) {
368
376
  execute: (args, context) => executeCodexShell(tools, args, context),
369
377
  },
370
378
  {
379
+ // As exec_command: its command runs through run_command, in the OS sandbox the profile asks for.
380
+ sandboxedCommands: true,
371
381
  capabilities: [ToolCapability.SHELL_EXEC, ToolCapability.FILE_WRITE],
372
382
  definition: {
373
383
  name: 'shell_command',
@@ -531,7 +541,7 @@ async function editFile(tools, args, context) {
531
541
  const newString = requiredString(args, ['new_string']);
532
542
  const replaceAll = parseReplaceAllFlag(args.replace_all);
533
543
  const resolved = resolvePath(path, context);
534
- const { before, after } = await updateFileAtomic(resolved, content => applyExactReplace(content, oldString, newString, replaceAll), () => admitLockedWrite(resolved, path, context));
544
+ const { before, after } = await updateFileAtomic(resolved, content => applyExactReplace(content, oldString, newString, replaceAll), () => admitLockedWrite(resolved, path, context), openAdmission(context, path));
535
545
  const replacements = replaceAll ? before.split(oldString).length - 1 : 1;
536
546
  const { diff, truncated } = buildSimpleDiffMeta(before, after);
537
547
  return JSON.stringify({
@@ -560,7 +570,7 @@ async function multiEditFile(tools, args, context) {
560
570
  content = applyExactReplace(content, record.oldString, record.newString, record.replaceAll);
561
571
  }
562
572
  return content;
563
- }, () => admitLockedWrite(resolved, path, context));
573
+ }, () => admitLockedWrite(resolved, path, context), openAdmission(context, path));
564
574
  const { diff, truncated } = buildSimpleDiffMeta(before, after);
565
575
  return JSON.stringify({
566
576
  path,