@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
@@ -0,0 +1,589 @@
1
+ /**
2
+ * The host-credential store: ZTC's own credentials, held outside process.env.
3
+ *
4
+ * A program ZTC starts with no environment of its own inherits all of process.env: read_file's image scalers, the `ps`
5
+ * run_command's cleanup runs, a helper's `git`, and any spawn written later. So ZTC keeps none of its credentials there.
6
+ * At startup, before any other module of the CLI runs (host_credentials_startup.ts, cli_main's first import), the store
7
+ * takes each of ZTC_CREDENTIAL_ENV out of process.env, and with it every other variable holding one of their values (a
8
+ * host can hand the same credential twice: ZergCloud passes its Router grant as ZERG_API_TOKEN too) and the setting a
9
+ * credential is read with (CREDENTIAL_SETTINGS: the host's effort policy URL, which goes with its token), keeping each
10
+ * under its name. A credential ZTC mints at runtime (the mirror's shared secret and process-wide token) goes into the
11
+ * store, never into process.env.
12
+ *
13
+ * ZTC reads them through the store (hostCredential, hostEnvironmentValue), and a child that needs one gets it explicitly
14
+ * from it: a ZTC pane and a colony cell the grant (utils/subprocess_env.ts hostRouterGrantForZtcChild), a colony cell
15
+ * its host's transport, ZTC's own relaunch everything it was started with (hostCredentialRelaunchEnv). The store holds
16
+ * values in this process's memory only; it never writes one anywhere, and never shows one.
17
+ *
18
+ * A process the store was never initialized in (a unit test, ZTC used as a library) keeps its credentials in process.env:
19
+ * reads fall back to process.env there, as they always did, and a credential minted there still goes into the store.
20
+ *
21
+ * A host can hand the grant and the mirror's shared secret over in a file instead (HOST_CREDENTIAL_FILE_ENV:
22
+ * ZTC_ROUTER_RUNTIME_GRANT_FILE, ZTC_MIRROR_SHARED_SECRET_FILE): startup reads the file once into the store and removes
23
+ * it, so the value is never in the environment this process was started with. It refuses a file that is a symbolic
24
+ * link, is not a regular file, has another name (a hard link, which removing this one would leave holding the
25
+ * credential), is empty, or that its group or others can read or change, a variable set together with its file, and one
26
+ * file that two of these variables name, or one and the handoff below, by one path or two spellings of it, since it would
27
+ * make one credential the other's too (HostCredentialFileError).
28
+ *
29
+ * A ZTC can hand another ZTC it starts the variables that ZTC is to be started with but that the program starting it
30
+ * doesn't hold, in a one-time handoff that ZTC's command line names (HOST_HANDOFF_FLAG, writeHostHandoff): its own
31
+ * relaunch in a new terminal window, which the terminal starts with a user subprocess's environment, and a ZTC pane a
32
+ * renderer starts again in place, which a replace_pane gives no environment. Startup takes it first, as if this
33
+ * process had been started with them.
34
+ *
35
+ * Startup takes all of these together or none of them: it reads and checks the handoff and every file before it removes
36
+ * any, so a refusal of one (the second file empty, or swapped for a link between ZTC's look at it and its open) leaves
37
+ * every one where it was, and a start the host retries once it has fixed that one takes them all. Before, the first
38
+ * file was gone by then and no retry could start (found by the ZergCloud hub's review, ze-0d, whose supervisor takes
39
+ * them in the same order).
40
+ *
41
+ * What it cannot do: the environment this process was started with stays readable by any program running as its user
42
+ * (`ps -E`, /proc/<pid>/environ) whatever the store removes from process.env, so a credential handed over there is
43
+ * still in reach of such a program; one handed over in a file is not. And a program running as this user or as root
44
+ * can still read this process's memory, where the store holds them.
45
+ *
46
+ * Self-contained (node builtins only): it runs before every other module body of the CLI.
47
+ */
48
+ import { closeSync, constants, fstatSync, lstatSync, mkdtempSync, openSync, readFileSync, realpathSync, rmdirSync, rmSync, unlinkSync, writeFileSync } from 'node:fs';
49
+ import { tmpdir } from 'node:os';
50
+ import { basename, dirname, join } from 'node:path';
51
+ /** The host-only variable that holds the host's Router runtime grant (config/router_runtime_grant.ts). */
52
+ export const ROUTER_RUNTIME_GRANT_ENV = 'ZTC_ROUTER_RUNTIME_GRANT';
53
+ /**
54
+ * The variables whose values are ZTC's own credentials: what speaks for this ZTC (its mirror's shared secret and
55
+ * process-wide token, its own pane credential, the platform login or Router grant it infers with, the host's Router
56
+ * runtime grant, its host's approval, broker and effort-policy tokens) and the zerg service's session secret. No child
57
+ * inherits one (utils/subprocess_env.ts), and the store holds them outside process.env.
58
+ */
59
+ export const ZTC_CREDENTIAL_ENV = Object.freeze([
60
+ 'ZTC_EFFORT_POLICY_TOKEN',
61
+ 'ZTC_APPROVAL_TOKEN',
62
+ 'ZTC_AUTH_TOKEN',
63
+ ROUTER_RUNTIME_GRANT_ENV,
64
+ 'ZTC_BROKER_TOKEN',
65
+ 'ZTC_MIRROR_INTERNAL_TOKEN',
66
+ 'ZTC_MIRROR_PANE_TOKEN',
67
+ 'ZTC_MIRROR_SHARED_SECRET',
68
+ 'ZERG_RUNTIME_SESSION_SECRET',
69
+ ]);
70
+ const CREDENTIAL_NAMES = new Set(ZTC_CREDENTIAL_ENV);
71
+ /**
72
+ * The settings ZTC reads together with one of its credentials, which the store holds outside process.env with it: the
73
+ * host's effort policy is ZTC_EFFORT_POLICY_URL read with ZTC_EFFORT_POLICY_TOKEN, and a ZTC holding one of them
74
+ * without the other fails every turn as an invalid configuration. So no program ZTC starts with no environment of its
75
+ * own, and no renderer (whose environment every pane it starts alone inherits), holds one half of the pair.
76
+ */
77
+ const CREDENTIAL_SETTINGS = Object.freeze(['ZTC_EFFORT_POLICY_URL']);
78
+ /**
79
+ * The shortest value taken for a credential when another variable holds it as well. A shorter one (a port, a flag, a
80
+ * word) could be anyone's.
81
+ */
82
+ export const CREDENTIAL_COPY_MIN_LENGTH = 12;
83
+ /**
84
+ * The credentials a host may hand over in a file instead of in this process's environment, each with the variable that
85
+ * names its file.
86
+ */
87
+ export const HOST_CREDENTIAL_FILE_ENV = Object.freeze({
88
+ [ROUTER_RUNTIME_GRANT_ENV]: `${ROUTER_RUNTIME_GRANT_ENV}_FILE`,
89
+ ZTC_MIRROR_SHARED_SECRET: 'ZTC_MIRROR_SHARED_SECRET_FILE',
90
+ });
91
+ /** The most a credential file holds: a grant is at most 16 KiB (router_runtime_grant.ts). */
92
+ const CREDENTIAL_FILE_MAX_BYTES = 64 * 1024;
93
+ /** Why startup refused a credential a host handed over (HOST_CREDENTIAL_FILE_ENV). It never repeats a value. */
94
+ export class HostCredentialFileError extends Error {
95
+ constructor(message) {
96
+ super(message);
97
+ this.name = 'HostCredentialFileError';
98
+ }
99
+ }
100
+ /** The credentials the store holds, by name. */
101
+ const held = new Map();
102
+ /** The other variables startup took out of process.env because each held one of those credentials' values, by name. */
103
+ const copies = new Map();
104
+ /** The settings startup took out of process.env with the credential each is read with (CREDENTIAL_SETTINGS), by name. */
105
+ const settings = new Map();
106
+ let initialized = false;
107
+ /** The error code an operating-system error names, or its message. */
108
+ function reason(error) {
109
+ return error.code ?? error.message;
110
+ }
111
+ /** The refusal for the file VARIABLE names at PATH, which WHY. */
112
+ function refusal(variable, path, why) {
113
+ return new HostCredentialFileError(`${variable} names ${path}, which ${why}. ZTC takes a credential only from a regular `
114
+ + 'file that its owner alone can read (chmod 600); it read nothing and did not start.');
115
+ }
116
+ /**
117
+ * Why the file at PATH, as lstat or fstat saw it (INFO), can't hold a credential; undefined when it can. The descriptor
118
+ * ZTC opened is checked as well as the path, so a name or link made between the two is seen.
119
+ */
120
+ function unfit(info) {
121
+ if (info.isSymbolicLink())
122
+ return 'is a symbolic link';
123
+ if (!info.isFile())
124
+ return 'is not a regular file';
125
+ // ZTC removes the name it was given once it has read the credential: another name would keep it readable, under
126
+ // every profile, by whoever can open that one.
127
+ if (info.nlink > 1)
128
+ return `has ${info.nlink} names, and another would keep the credential readable after ZTC removes this one`;
129
+ if (process.platform !== 'win32' && (info.mode & 0o066) !== 0) {
130
+ return `its group or others can read or change (mode ${(info.mode & 0o777).toString(8).padStart(3, '0')})`;
131
+ }
132
+ if (info.size > CREDENTIAL_FILE_MAX_BYTES)
133
+ return `is larger than a credential (${info.size} bytes)`;
134
+ return undefined;
135
+ }
136
+ /** A handoff folder ZTC's relaunch wrote (hostCredentialRelaunchEnv): an owner-only folder of its own in the temp folder. */
137
+ const RELAUNCH_HANDOFF = /^ztc-host-credential-[A-Za-z0-9]{6}$/;
138
+ /** The one file in a handoff folder (writeRelaunchHandoff). */
139
+ const HANDOFF_FILE = 'credential';
140
+ /**
141
+ * The flag on a ZTC's command line that names a one-time handoff of variables that ZTC is to be started with but that
142
+ * the program starting it doesn't hold in its environment: ZTC's own relaunch in a new terminal window (--new-window),
143
+ * which the terminal starts with a user subprocess's environment, and a ZTC pane a renderer starts again in place
144
+ * (replace_pane), which carries no environment. The handoff (writeHostHandoff) is a JSON object of variable names and
145
+ * values in an owner-only file, in an owner-only folder of its own in the temp folder: never in an environment, which
146
+ * any program running as this user can read, nor on a command line, which any local user can. The ZTC it is for takes
147
+ * it as it starts, as if it had been started with those variables, and removes it (initHostCredentials).
148
+ */
149
+ export const HOST_HANDOFF_FLAG = '--host-credential-file';
150
+ /**
151
+ * ARGS, launch flags of a ZTC that ZTC starts but did not write all of (the extra_args an agent gives create_ztc_pane,
152
+ * the arguments a pane relay client asks a launch nonce for, the flags this process was started with), without a
153
+ * handoff they name (HOST_HANDOFF_FLAG with the path after it, or written as one word with '='), before an end of
154
+ * options ('--'), after which a ZTC pane's task is literal text. A ZTC is handed variables only in a handoff ZTC wrote
155
+ * for that launch itself (writeHostHandoff): one another program put in the temp folder, shaped as ZTC's own, could set
156
+ * the ZERG_ROUTER_BASE_URL the grant goes to, or switch extension discovery off, in a ZTC that holds the grant.
157
+ */
158
+ export function withoutHostHandoff(args) {
159
+ const kept = [];
160
+ for (let i = 0; i < args.length; i++) {
161
+ const arg = args[i];
162
+ if (arg === '--') {
163
+ kept.push(...args.slice(i));
164
+ break;
165
+ }
166
+ if (arg === HOST_HANDOFF_FLAG) {
167
+ if (args[i + 1] !== undefined && !args[i + 1].startsWith('-'))
168
+ i++;
169
+ continue;
170
+ }
171
+ if (arg.startsWith(`${HOST_HANDOFF_FLAG}=`))
172
+ continue;
173
+ kept.push(arg);
174
+ }
175
+ return kept;
176
+ }
177
+ /** A variable's name, as a handoff may hold one. */
178
+ const VARIABLE_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
179
+ /** The refusal for the handoff at PATH, which WHY. */
180
+ function handoffRefusal(path, why) {
181
+ return new HostCredentialFileError(`${HOST_HANDOFF_FLAG} names ${path}, which ${why}. ZTC takes a handoff only from the `
182
+ + 'one-time file another ZTC wrote for it; it read nothing and did not start.');
183
+ }
184
+ /**
185
+ * The variables the handoff ARGV names (HOST_HANDOFF_FLAG), read and checked, with the folder that holds it, which
186
+ * initHostCredentials removes once everything else it takes has passed its checks too; null when ARGV names none. The
187
+ * flag and its path are dropped from ARGV, so nothing that relaunches this process or starts a pane from its arguments
188
+ * passes them on. Only ARGV's options name one: what follows an end of options ('--') is a ZTC pane's task, literal
189
+ * text, whatever it says. A handoff that is gone, that isn't a regular file of this user's that its owner alone can
190
+ * read, in an owner-only folder of this user's own in the temp folder, or that holds anything but variables (a JSON
191
+ * object of names and string values, none of them a file variable of HOST_CREDENTIAL_FILE_ENV), is refused
192
+ * (HostCredentialFileError) and, when it lies in a folder of this user's, removed: no ZTC could take it, so it is used
193
+ * once all the same, and what it holds leaves the disk with it. The ZTC it was for starts with what it was meant to
194
+ * start with, or not at all.
195
+ */
196
+ function readHostHandoff(argv) {
197
+ const end = argv.indexOf('--');
198
+ const at = argv.indexOf(HOST_HANDOFF_FLAG);
199
+ if (at < 0 || (end >= 0 && at > end))
200
+ return null;
201
+ const named = argv[at + 1];
202
+ const path = named !== undefined && !named.startsWith('-') ? named : '';
203
+ argv.splice(at, path ? 2 : 1);
204
+ if (!path)
205
+ throw new HostCredentialFileError(`${HOST_HANDOFF_FLAG} names no file. ZTC read nothing and did not start.`);
206
+ const folder = dirname(path);
207
+ let shaped;
208
+ try {
209
+ shaped = basename(path) === HANDOFF_FILE && RELAUNCH_HANDOFF.test(basename(folder)) && dirname(folder) === realpathSync(tmpdir());
210
+ }
211
+ catch {
212
+ shaped = false;
213
+ }
214
+ if (!shaped)
215
+ throw handoffRefusal(path, 'is not a handoff in a folder of its own in the temp folder');
216
+ const uid = process.platform === 'win32' ? undefined : process.getuid?.();
217
+ let ours = false;
218
+ try {
219
+ let directory;
220
+ try {
221
+ directory = lstatSync(folder);
222
+ }
223
+ catch (error) {
224
+ throw handoffRefusal(path, `ZTC can't open (${reason(error)})`);
225
+ }
226
+ if (!directory.isDirectory() || (uid !== undefined && directory.uid !== uid))
227
+ throw handoffRefusal(path, 'is not in a folder of this user\'s');
228
+ ours = true;
229
+ if (uid !== undefined && (directory.mode & 0o077) !== 0)
230
+ throw handoffRefusal(path, 'is in a folder others can open');
231
+ let info;
232
+ try {
233
+ info = lstatSync(path);
234
+ }
235
+ catch (error) {
236
+ throw handoffRefusal(path, `ZTC can't open (${reason(error)})`);
237
+ }
238
+ const before = unfit(info);
239
+ if (before)
240
+ throw handoffRefusal(path, before);
241
+ let text;
242
+ let descriptor;
243
+ let opened;
244
+ try {
245
+ descriptor = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
246
+ }
247
+ catch (error) {
248
+ throw handoffRefusal(path, `ZTC can't open (${reason(error)})`);
249
+ }
250
+ try {
251
+ opened = fstatSync(descriptor);
252
+ const after = unfit(opened);
253
+ if (after)
254
+ throw handoffRefusal(path, after);
255
+ if (opened.dev !== info.dev || opened.ino !== info.ino)
256
+ throw handoffRefusal(path, 'changed while ZTC opened it');
257
+ if (uid !== undefined && opened.uid !== uid)
258
+ throw handoffRefusal(path, 'is not this user\'s');
259
+ text = readFileSync(descriptor, 'utf8');
260
+ }
261
+ finally {
262
+ closeSync(descriptor);
263
+ }
264
+ let parsed;
265
+ try {
266
+ parsed = JSON.parse(text);
267
+ }
268
+ catch {
269
+ parsed = undefined;
270
+ }
271
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
272
+ throw handoffRefusal(path, 'holds no variables');
273
+ const fileVariables = new Set(Object.values(HOST_CREDENTIAL_FILE_ENV));
274
+ const variables = new Map();
275
+ for (const [name, value] of Object.entries(parsed)) {
276
+ if (!VARIABLE_NAME.test(name) || name === '__proto__' || fileVariables.has(name) || typeof value !== 'string' || value.includes('\0')) {
277
+ throw handoffRefusal(path, 'holds something other than variables');
278
+ }
279
+ variables.set(name, value);
280
+ }
281
+ return { variables, path, folder, dev: opened.dev, ino: opened.ino };
282
+ }
283
+ catch (error) {
284
+ // Refused, and one-time all the same: whatever it held, no other ZTC takes it.
285
+ if (ours)
286
+ removeHandoffFolder(folder);
287
+ throw error;
288
+ }
289
+ }
290
+ /** Remove a handoff's FOLDER, this user's own, with the handoff in it. */
291
+ function removeHandoffFolder(folder) {
292
+ try {
293
+ rmSync(folder, { recursive: true, force: true });
294
+ }
295
+ catch { /* this user's own; gone already */ }
296
+ }
297
+ /**
298
+ * The credential in the file VARIABLE names at PATH, read and checked but not removed (removeCredentialFile), with
299
+ * which file ZTC opened: refused when the file is unfit (unfit), changed between ZTC's look at it and its open, or
300
+ * empty.
301
+ */
302
+ function readCredentialFile(variable, path) {
303
+ let info;
304
+ try {
305
+ info = lstatSync(path);
306
+ }
307
+ catch (error) {
308
+ throw refusal(variable, path, `ZTC can't open (${reason(error)})`);
309
+ }
310
+ const before = unfit(info);
311
+ if (before)
312
+ throw refusal(variable, path, before);
313
+ let text;
314
+ let descriptor;
315
+ let opened;
316
+ // Never through a link put there since: open it as the file looked at, and check that is what was opened.
317
+ try {
318
+ descriptor = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
319
+ }
320
+ catch (error) {
321
+ throw refusal(variable, path, `ZTC can't open (${reason(error)})`);
322
+ }
323
+ try {
324
+ opened = fstatSync(descriptor);
325
+ const after = unfit(opened);
326
+ if (after)
327
+ throw refusal(variable, path, after);
328
+ if (opened.dev !== info.dev || opened.ino !== info.ino)
329
+ throw refusal(variable, path, 'changed while ZTC opened it');
330
+ text = readFileSync(descriptor, 'utf8');
331
+ }
332
+ finally {
333
+ closeSync(descriptor);
334
+ }
335
+ const value = text.replace(/\r?\n$/, '');
336
+ if (!value.trim())
337
+ throw refusal(variable, path, 'is empty');
338
+ return { value, dev: opened.dev, ino: opened.ino };
339
+ }
340
+ /**
341
+ * Refuse one file that two of the names a start takes credentials from name (TAKEN: the handoff and each credential
342
+ * file, as each was opened), by one path or by two spellings of it (/tmp and /private/tmp, a linked folder): taking it
343
+ * for both would make one credential the other's too (the Router grant the key mirror sign-ins are checked with), and
344
+ * the second removal would warn of a file the first already removed. Nothing has been consumed yet.
345
+ */
346
+ function refuseOneFileTwice(taken) {
347
+ for (const [index, file] of taken.entries()) {
348
+ const first = taken.slice(0, index).find(other => other.dev === file.dev && other.ino === file.ino);
349
+ if (!first)
350
+ continue;
351
+ const named = first.path === file.path ? file.path : `${first.path} and ${file.path}`;
352
+ throw new HostCredentialFileError(`${first.variable} and ${file.variable} name one file (${named}): give each credential a `
353
+ + 'file of its own. ZTC took neither and did not start.');
354
+ }
355
+ }
356
+ /**
357
+ * Remove the file VARIABLE named at PATH, whose credential ZTC has taken, with the folder ZTC's relaunch put it in. A
358
+ * file that can't be removed is said so through WARN, and ZTC starts all the same: it holds the credential already.
359
+ */
360
+ function removeCredentialFile(variable, path, warn) {
361
+ try {
362
+ unlinkSync(path);
363
+ const folder = dirname(path);
364
+ if (RELAUNCH_HANDOFF.test(basename(folder)) && dirname(folder) === realpathSync(tmpdir()))
365
+ rmdirSync(folder);
366
+ }
367
+ catch (error) {
368
+ warn(`${variable}: ZTC took the credential from ${path} but could not remove the file (${reason(error)}); remove it.`);
369
+ }
370
+ }
371
+ /**
372
+ * Take ZTC's credentials out of this process's environment into the store. First what was handed over to it: a
373
+ * handoff on ARGV (HOST_HANDOFF_FLAG), as if this process had been started with it (its credentials into the store, its
374
+ * other variables into ENV over what ENV holds), and each credential a host handed over in a file
375
+ * (HOST_CREDENTIAL_FILE_ENV), its variable taken out too. All of them are read and checked before any is taken or
376
+ * removed: a handoff that isn't one, a variable set together with its file (or with a credential the handoff holds), a
377
+ * file that is unfit, changed as ZTC opened it, or empty, one file named twice (refuseOneFileTwice), is refused
378
+ * (HostCredentialFileError), and then nothing is
379
+ * consumed: every file, and a handoff that passed, is left where it was for a start that takes them all. Only once
380
+ * every one has passed are their files removed, with the folders ZTC's relaunch put them in, and they are taken. Then
381
+ * each of ZTC_CREDENTIAL_ENV, the settings read with one of them (CREDENTIAL_SETTINGS), and every other variable whose
382
+ * value (blanks around it aside) is one of the credentials', of CREDENTIAL_COPY_MIN_LENGTH characters or more. Each is
383
+ * kept under its name, so a read of a setting or a copy ZTC itself makes still finds it (hostEnvironmentValue). Runs
384
+ * once; later calls change nothing.
385
+ */
386
+ export function initHostCredentials(env = process.env, warn = message => { process.stderr.write(`[ztc] ${message}\n`); }, argv = process.argv) {
387
+ if (initialized)
388
+ return;
389
+ initialized = true;
390
+ // Everything handed over, read and checked first; nothing is removed or taken until all of it has passed.
391
+ const handoff = readHostHandoff(argv);
392
+ const handedCredentials = new Map();
393
+ const handedVariables = new Map();
394
+ for (const [name, value] of handoff?.variables ?? [])
395
+ (CREDENTIAL_NAMES.has(name) ? handedCredentials : handedVariables).set(name, value);
396
+ const files = Object.entries(HOST_CREDENTIAL_FILE_ENV).filter(([, variable]) => env[variable] !== undefined);
397
+ for (const [name, variable] of files) {
398
+ if (env[name] !== undefined || handedCredentials.has(name)) {
399
+ throw new HostCredentialFileError(`${name} and ${variable} are both set: set one of them. ZTC read neither and did not start.`);
400
+ }
401
+ }
402
+ const fromFiles = files.map(([name, variable]) => ({ name, variable, path: env[variable], ...readCredentialFile(variable, env[variable]) }));
403
+ refuseOneFileTwice([...(handoff ? [{ ...handoff, variable: HOST_HANDOFF_FLAG }] : []), ...fromFiles]);
404
+ // Every one passed: each is consumed now, its file removed, and taken.
405
+ if (handoff)
406
+ removeHandoffFolder(handoff.folder);
407
+ for (const { variable, path } of fromFiles)
408
+ removeCredentialFile(variable, path, warn);
409
+ for (const [name, value] of handedCredentials)
410
+ held.set(name, { value, origin: 'file' });
411
+ for (const [name, value] of handedVariables)
412
+ env[name] = value;
413
+ for (const { name, variable, value } of fromFiles) {
414
+ held.set(name, { value, origin: 'file' });
415
+ delete env[variable];
416
+ }
417
+ for (const name of ZTC_CREDENTIAL_ENV) {
418
+ const value = env[name];
419
+ if (value !== undefined && !held.has(name))
420
+ held.set(name, { value, origin: 'environment' });
421
+ delete env[name];
422
+ }
423
+ // Whichever half of a pair is set: one alone is an invalid configuration, which no child gets either.
424
+ for (const name of CREDENTIAL_SETTINGS) {
425
+ const value = env[name];
426
+ if (value !== undefined)
427
+ settings.set(name, value);
428
+ delete env[name];
429
+ }
430
+ const values = new Set([...held.values()].map(entry => entry.value.trim()).filter(value => value.length >= CREDENTIAL_COPY_MIN_LENGTH));
431
+ if (values.size === 0)
432
+ return;
433
+ for (const [name, value] of Object.entries(env)) {
434
+ if (typeof value !== 'string' || !values.has(value.trim()))
435
+ continue;
436
+ copies.set(name, value);
437
+ delete env[name];
438
+ }
439
+ }
440
+ /** Whether this process took its credentials out of its environment (initHostCredentials). */
441
+ export function hostCredentialsInitialized() {
442
+ return initialized;
443
+ }
444
+ /**
445
+ * The credential NAME (one of ZTC_CREDENTIAL_ENV): the store's, once startup took them out of process.env; before
446
+ * that, or where it never did, process.env's, else one ZTC minted.
447
+ */
448
+ export function hostCredential(name) {
449
+ const entry = held.get(name);
450
+ if (initialized)
451
+ return entry?.value;
452
+ return process.env[name] ?? entry?.value;
453
+ }
454
+ /** Keep VALUE, a credential ZTC minted for NAME (the mirror's shared secret, its process-wide token), in the store. */
455
+ export function holdMintedCredential(name, value) {
456
+ if (!CREDENTIAL_NAMES.has(name))
457
+ throw new Error(`Not a ZTC credential: ${name}`);
458
+ held.set(name, { value, origin: 'minted' });
459
+ }
460
+ /**
461
+ * The value NAME has in ENV. For this process's own environment, as ZTC was started with it: a credential from the
462
+ * store (hostCredential), and a setting or a copy startup took out with the credentials from the store too. Any other
463
+ * environment (a child's, one a test builds) is read as it is.
464
+ */
465
+ export function hostEnvironmentValue(name, env = process.env) {
466
+ if (env !== process.env)
467
+ return env[name];
468
+ if (CREDENTIAL_NAMES.has(name))
469
+ return hostCredential(name);
470
+ return process.env[name] ?? settings.get(name) ?? copies.get(name);
471
+ }
472
+ /**
473
+ * SOURCE as ZTC was started with it, for working out what a child of ZTC gets: this process's environment with the
474
+ * credentials the store holds, and the settings and copies it took out with them, put back; any other environment as
475
+ * it is. It is a picture that the child-environment rules strip (utils/subprocess_env.ts); never start a child with it
476
+ * whole.
477
+ */
478
+ export function hostLaunchEnvironment(source = process.env) {
479
+ if (source !== process.env)
480
+ return source;
481
+ const environment = { ...process.env };
482
+ for (const [name, value] of [...settings, ...copies])
483
+ if (environment[name] === undefined)
484
+ environment[name] = value;
485
+ for (const name of ZTC_CREDENTIAL_ENV) {
486
+ const value = hostCredential(name);
487
+ if (value !== undefined)
488
+ environment[name] = value;
489
+ }
490
+ return environment;
491
+ }
492
+ /**
493
+ * Every credential value the store holds, and every copy's, of CREDENTIAL_COPY_MIN_LENGTH characters or more (blanks
494
+ * around each aside), longest first: what no child may hold under any name.
495
+ */
496
+ export function heldCredentialValues() {
497
+ const values = new Set();
498
+ for (const value of [...[...held.values()].map(entry => entry.value), ...copies.values()]) {
499
+ const trimmed = value.trim();
500
+ if (trimmed.length >= CREDENTIAL_COPY_MIN_LENGTH)
501
+ values.add(trimmed);
502
+ }
503
+ return [...values].sort((a, b) => b.length - a.length);
504
+ }
505
+ /**
506
+ * The credential values to withhold wherever they appear, for a redactor (the mirror's observer projection, a
507
+ * diagnostics export): what each of NAMES holds in ENV (this process's own environment read as ZTC was started with
508
+ * it, hostEnvironmentValue), and, for this process's environment, every credential the store holds and every copy it
509
+ * took out (heldCredentialValues), named or not; each of CREDENTIAL_COPY_MIN_LENGTH characters or more (blanks around it
510
+ * aside), longest first. Scrubbing process.env takes nothing off it.
511
+ */
512
+ export function liveCredentialValues(names = ZTC_CREDENTIAL_ENV, env = process.env) {
513
+ const values = new Set();
514
+ for (const name of names) {
515
+ const value = hostEnvironmentValue(name, env)?.trim();
516
+ if (value && value.length >= CREDENTIAL_COPY_MIN_LENGTH)
517
+ values.add(value);
518
+ }
519
+ if (env === process.env)
520
+ for (const value of heldCredentialValues())
521
+ values.add(value);
522
+ return [...values].sort((a, b) => b.length - a.length);
523
+ }
524
+ /**
525
+ * A fresh one-time handoff of VALUE for ZTC's relaunch: an owner-only file in an owner-only folder of its own in the
526
+ * temp folder, which the relaunched ZTC reads and removes, folder and all, once it has read every other it takes too
527
+ * (initHostCredentials). Null when it can't be written.
528
+ */
529
+ function writeRelaunchHandoff(value) {
530
+ let folder;
531
+ try {
532
+ folder = mkdtempSync(join(realpathSync(tmpdir()), 'ztc-host-credential-'));
533
+ const path = join(folder, HANDOFF_FILE);
534
+ writeFileSync(path, value, { mode: 0o600, flag: 'wx' });
535
+ return path;
536
+ }
537
+ catch {
538
+ if (folder)
539
+ rmSync(folder, { recursive: true, force: true });
540
+ return null;
541
+ }
542
+ }
543
+ /**
544
+ * A fresh one-time handoff of VARIABLES for a ZTC to be started with (HOST_HANDOFF_FLAG): the path its command line
545
+ * names after the flag. Null when VARIABLES is empty, or when the handoff can't be written or would be larger than a
546
+ * handoff ZTC takes.
547
+ */
548
+ export function writeHostHandoff(variables) {
549
+ const entries = Object.entries(variables);
550
+ if (entries.length === 0)
551
+ return null;
552
+ const text = JSON.stringify(Object.fromEntries(entries));
553
+ return Buffer.byteLength(text, 'utf8') > CREDENTIAL_FILE_MAX_BYTES ? null : writeRelaunchHandoff(text);
554
+ }
555
+ /** Remove a handoff (writeHostHandoff) its ZTC never took: the program never started, or ended before it took it. */
556
+ export function removeHostHandoff(path) {
557
+ const folder = dirname(path);
558
+ try {
559
+ if (basename(path) !== HANDOFF_FILE || !RELAUNCH_HANDOFF.test(basename(folder)) || dirname(folder) !== realpathSync(tmpdir()))
560
+ return;
561
+ rmSync(folder, { recursive: true, force: true });
562
+ }
563
+ catch { /* gone already */ }
564
+ }
565
+ /**
566
+ * What ZTC's own relaunch (a hot restart in place, which is this ZTC again) is started with besides process.env:
567
+ * everything the store took out of it and everything ZTC minted, so the ZTC that takes this one's place keeps the
568
+ * host's grant, its platform login, its effort policy and the mirror's secret and token, and takes them out of its own
569
+ * environment again. A credential the host handed over in a file, or another ZTC handed this one in a handoff, goes
570
+ * over in a fresh one-time file when it has a file variable (HOST_CREDENTIAL_FILE_ENV), never in that ZTC's environment;
571
+ * in its environment only when no such file can be written.
572
+ */
573
+ export function hostCredentialRelaunchEnv() {
574
+ const environment = {};
575
+ for (const [name, value] of [...settings, ...copies])
576
+ environment[name] = value;
577
+ for (const name of ZTC_CREDENTIAL_ENV) {
578
+ const value = hostCredential(name);
579
+ if (value === undefined)
580
+ continue;
581
+ const variable = HOST_CREDENTIAL_FILE_ENV[name];
582
+ const handoff = variable && held.get(name)?.origin === 'file' ? writeRelaunchHandoff(value) : null;
583
+ if (variable && handoff)
584
+ environment[variable] = handoff;
585
+ else
586
+ environment[name] = value;
587
+ }
588
+ return environment;
589
+ }