@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.
- package/README.md +590 -28
- package/bin/zmux-darwin-arm64 +0 -0
- package/bin/zmux-linux-x64 +0 -0
- package/bin/ztc-audio-darwin-arm64 +0 -0
- package/bin/ztc-capture-darwin-arm64 +0 -0
- package/bin/ztc-tui-darwin-arm64 +0 -0
- package/bin/ztc-tui-linux-x64 +0 -0
- package/bin/zterm-darwin-arm64 +2 -2
- package/dist/App.js +18 -1
- package/dist/agent/agent.d.ts +25 -1
- package/dist/agent/agent.js +26 -1
- package/dist/agent/attached_images.d.ts +58 -0
- package/dist/agent/attached_images.js +145 -0
- package/dist/agent/backends/anthropic.d.ts +14 -0
- package/dist/agent/backends/anthropic.js +49 -2
- package/dist/agent/backends/codex_app_server.d.ts +3 -1
- package/dist/agent/backends/codex_app_server.js +9 -6
- package/dist/agent/backends/codex_auth.js +3 -0
- package/dist/agent/backends/gemini.js +3 -0
- package/dist/agent/backends/host_effort_policy.js +14 -2
- package/dist/agent/backends/http_error.d.ts +17 -0
- package/dist/agent/backends/http_error.js +50 -1
- package/dist/agent/backends/index.js +2 -1
- package/dist/agent/backends/model_redirect.d.ts +47 -0
- package/dist/agent/backends/model_redirect.js +97 -0
- package/dist/agent/backends/openai_compatible.js +5 -0
- package/dist/agent/backends/openai_responses.d.ts +9 -1
- package/dist/agent/backends/openai_responses.js +21 -12
- package/dist/agent/backends/prompt_cache.d.ts +8 -0
- package/dist/agent/backends/prompt_cache.js +10 -0
- package/dist/agent/backends/provider_ids.d.ts +1 -1
- package/dist/agent/backends/provider_ids.js +1 -1
- package/dist/agent/backends/types.d.ts +8 -0
- package/dist/agent/backends/zerg-api.js +5 -1
- package/dist/agent/backends/zrouter_stream.d.ts +75 -9
- package/dist/agent/backends/zrouter_stream.js +250 -49
- package/dist/agent/commands/config.js +51 -4
- package/dist/agent/commands/connect.js +20 -0
- package/dist/agent/commands/credential_status.js +5 -3
- package/dist/agent/commands/debug.js +3 -0
- package/dist/agent/commands/diff.js +9 -5
- package/dist/agent/commands/emulation.js +7 -1
- package/dist/agent/commands/inbox.js +4 -3
- package/dist/agent/commands/mcp.js +3 -0
- package/dist/agent/commands/models.js +20 -3
- package/dist/agent/commands/permissions.js +16 -2
- package/dist/agent/commands/provider_selection.js +13 -6
- package/dist/agent/commands/settings.js +15 -4
- package/dist/agent/commands/status.js +23 -1
- package/dist/agent/commands/types.d.ts +34 -3
- package/dist/agent/commands/update.d.ts +2 -1
- package/dist/agent/commands/update.js +8 -3
- package/dist/agent/commands/zerg.d.ts +6 -0
- package/dist/agent/commands/zerg.js +152 -28
- package/dist/agent/commands/ztc_pane.js +8 -5
- package/dist/agent/factory.js +22 -4
- package/dist/agent/request_encoder.js +11 -2
- package/dist/agent/runtime/command_jobs.js +16 -1
- package/dist/agent/runtime/command_panes.js +4 -1
- package/dist/agent/runtime/execution_context.d.ts +8 -1
- package/dist/agent/runtime/execution_context.js +8 -2
- package/dist/agent/runtime/policy.d.ts +66 -5
- package/dist/agent/runtime/policy.js +161 -33
- package/dist/agent/runtime/remote_broker_transport.d.ts +7 -0
- package/dist/agent/runtime/remote_broker_transport.js +33 -3
- package/dist/agent/runtime/remote_resource_errors.d.ts +7 -0
- package/dist/agent/runtime/remote_resource_errors.js +10 -0
- package/dist/agent/runtime/remote_resources.d.ts +1 -1
- package/dist/agent/runtime/remote_resources.js +7 -3
- package/dist/agent/runtime/source_verification.js +15 -12
- package/dist/agent/runtime/tool_runtime.js +165 -58
- package/dist/agent/runtime/verifier_capture.d.ts +1 -1
- package/dist/agent/runtime/verifier_capture.js +6 -0
- package/dist/agent/runtime/work_base.js +46 -14
- package/dist/agent/tools/adaptation.js +29 -12
- package/dist/agent/tools/apply_patch.js +62 -5
- package/dist/agent/tools/background.js +2 -0
- package/dist/agent/tools/benchmark_cpu.js +2 -0
- package/dist/agent/tools/bus_message.d.ts +4 -2
- package/dist/agent/tools/bus_message.js +21 -3
- package/dist/agent/tools/delegate.js +2 -0
- package/dist/agent/tools/file.d.ts +12 -1
- package/dist/agent/tools/file.js +92 -11
- package/dist/agent/tools/lsp.d.ts +12 -0
- package/dist/agent/tools/lsp.js +61 -5
- package/dist/agent/tools/pane.js +20 -45
- package/dist/agent/tools/project_context.js +5 -2
- package/dist/agent/tools/routine.js +20 -4
- package/dist/agent/tools/screenshot.d.ts +8 -0
- package/dist/agent/tools/screenshot.js +39 -25
- package/dist/agent/tools/search.js +31 -3
- package/dist/agent/tools/shell.js +7 -1
- package/dist/agent/tools/supervision.js +6 -0
- package/dist/agent/tools/types.d.ts +18 -0
- package/dist/agent/tools/zerg.js +15 -19
- package/dist/agent/tools/ztc_command.d.ts +15 -4
- package/dist/agent/tools/ztc_command.js +48 -34
- package/dist/app/agent_runner.js +8 -6
- package/dist/app/conversation_compaction.d.ts +6 -3
- package/dist/app/conversation_compaction.js +6 -3
- package/dist/app/tool_callbacks.js +1 -0
- package/dist/audio/sfx.js +6 -0
- package/dist/batch/worktree.js +22 -10
- package/dist/board/client.js +2 -1
- package/dist/cli_main.d.ts +1 -0
- package/dist/cli_main.js +141 -45
- package/dist/cli_ratatui.d.ts +49 -4
- package/dist/cli_ratatui.js +355 -79
- package/dist/conductor_branch.js +4 -1
- package/dist/config/host_credentials.d.ts +157 -0
- package/dist/config/host_credentials.js +589 -0
- package/dist/config/model_pin.d.ts +111 -0
- package/dist/config/model_pin.js +182 -0
- package/dist/config/own_state_files.d.ts +35 -0
- package/dist/config/own_state_files.js +161 -0
- package/dist/config/permission_pin.d.ts +148 -0
- package/dist/config/permission_pin.js +203 -0
- package/dist/config/permissions.d.ts +9 -2
- package/dist/config/permissions.js +14 -3
- package/dist/config/platform_login.d.ts +72 -0
- package/dist/config/platform_login.js +111 -0
- package/dist/config/profile_limits.d.ts +34 -0
- package/dist/config/profile_limits.js +66 -0
- package/dist/config/provider_api_key_env.js +3 -2
- package/dist/config/provider_models.d.ts +6 -1
- package/dist/config/provider_models.js +38 -11
- package/dist/config/repo_config.d.ts +22 -0
- package/dist/config/repo_config.js +77 -3
- package/dist/config/router_runtime_grant.d.ts +53 -0
- package/dist/config/router_runtime_grant.js +131 -0
- package/dist/config/settings_merge.d.ts +22 -0
- package/dist/config/settings_merge.js +75 -0
- package/dist/config/types.d.ts +8 -0
- package/dist/config.d.ts +334 -4
- package/dist/config.js +1024 -41
- package/dist/context/project_intelligence.d.ts +11 -2
- package/dist/context/project_intelligence.js +38 -15
- package/dist/desktop/daily/desktop_wiring.js +8 -6
- package/dist/desktop/daily/native_pane_launcher.js +2 -1
- package/dist/desktop/daily/native_tool.d.ts +1 -1
- package/dist/desktop/daily/native_tool.js +4 -3
- package/dist/desktop/daily/process_identity.js +10 -2
- package/dist/desktop/daily/source_baseline.js +4 -3
- package/dist/diagnostics/native_terminal_benchmark.js +3 -2
- package/dist/diagnostics/session_export.js +27 -14
- package/dist/embedded/anempa_runtime.js +3 -3
- package/dist/embedded/gameboy_runtime.js +5 -4
- package/dist/embedded/zergpod_runtime.js +5 -4
- package/dist/emulation/catalog.js +6 -1
- package/dist/emulation/tool_adapters.js +13 -3
- package/dist/environment/store.js +5 -4
- package/dist/extension_discovery.d.ts +12 -2
- package/dist/extension_discovery.js +52 -7
- package/dist/headless.d.ts +8 -0
- package/dist/headless.js +52 -13
- package/dist/headless_cli.js +16 -1
- package/dist/headless_workflow_trigger.js +1 -1
- package/dist/hooks/dispatcher.d.ts +8 -0
- package/dist/hooks/dispatcher.js +22 -2
- package/dist/hooks/lifecycle.d.ts +6 -0
- package/dist/hooks/lifecycle.js +1 -0
- package/dist/hooks/program_files.d.ts +10 -0
- package/dist/hooks/program_files.js +175 -0
- package/dist/hooks/runner.d.ts +11 -1
- package/dist/hooks/runner.js +112 -11
- package/dist/hooks/types.d.ts +2 -0
- package/dist/host_credentials_startup.d.ts +6 -0
- package/dist/host_credentials_startup.js +17 -0
- package/dist/instance_registry.d.ts +6 -2
- package/dist/instance_registry.js +9 -15
- package/dist/intake/format.d.ts +6 -0
- package/dist/intake/format.js +9 -0
- package/dist/intake/notifications.js +2 -1
- package/dist/lsp/manager.d.ts +1 -1
- package/dist/lsp/manager.js +4 -5
- package/dist/mcp/client.d.ts +2 -0
- package/dist/mcp/client.js +116 -18
- package/dist/mcp/registry.d.ts +12 -0
- package/dist/mcp/registry.js +15 -1
- package/dist/modes/handlers.js +14 -5
- package/dist/panes/agent_cli.d.ts +23 -1
- package/dist/panes/agent_cli.js +96 -1
- package/dist/panes/agent_panes.d.ts +27 -4
- package/dist/panes/agent_panes.js +73 -11
- package/dist/panes/editor_program.d.ts +8 -0
- package/dist/panes/editor_program.js +25 -0
- package/dist/panes/motsi.d.ts +11 -1
- package/dist/panes/motsi.js +14 -1
- package/dist/panes/pane_registry.d.ts +28 -1
- package/dist/panes/pane_registry.js +25 -0
- package/dist/panes/worker_route.js +5 -3
- package/dist/panes/ztc_launch.d.ts +8 -0
- package/dist/panes/ztc_launch.js +26 -1
- package/dist/profile_baseline.js +2 -0
- package/dist/router_auth.d.ts +8 -3
- package/dist/router_auth.js +34 -2
- package/dist/runtime_info.js +56 -38
- package/dist/session.js +12 -2
- package/dist/shannon/runtime.js +13 -1
- package/dist/simulation/domains/loader.d.ts +2 -1
- package/dist/simulation/domains/loader.js +19 -2
- package/dist/simulation/living/context.d.ts +8 -8
- package/dist/simulation/living/types.d.ts +2 -2
- package/dist/simulation/memory/embedding.d.ts +2 -1
- package/dist/simulation/memory/embedding.js +25 -6
- package/dist/terminal_attach.js +2 -1
- package/dist/types.d.ts +21 -0
- package/dist/ui/ratatui/headless_pane_manager.d.ts +12 -6
- package/dist/ui/ratatui/headless_pane_manager.js +65 -21
- package/dist/ui/ratatui/ipc_path.d.ts +41 -2
- package/dist/ui/ratatui/ipc_path.js +164 -5
- package/dist/ui/ratatui/pane_credential_broker.d.ts +17 -4
- package/dist/ui/ratatui/pane_credential_broker.js +23 -5
- package/dist/ui/ratatui/pane_relay.d.ts +74 -0
- package/dist/ui/ratatui/pane_relay.js +188 -13
- package/dist/ui/ratatui/process.d.ts +15 -1
- package/dist/ui/ratatui/process.js +129 -163
- package/dist/ui/ratatui/protocol.d.ts +11 -1
- package/dist/ui/ratatui/protocol.js +6 -0
- package/dist/ui/ratatui/ztc_launch_trust.d.ts +87 -0
- package/dist/ui/ratatui/ztc_launch_trust.js +249 -0
- package/dist/utils/admitted_open.d.ts +40 -0
- package/dist/utils/admitted_open.js +111 -0
- package/dist/utils/clipboard.js +2 -1
- package/dist/utils/computer_native.js +12 -56
- package/dist/utils/dictation.js +15 -12
- package/dist/utils/dictation_native.js +17 -60
- package/dist/utils/git_probe_options.d.ts +28 -0
- package/dist/utils/git_probe_options.js +30 -0
- package/dist/utils/git_program_files.d.ts +145 -0
- package/dist/utils/git_program_files.js +1282 -0
- package/dist/utils/git_repository_programs.d.ts +13 -0
- package/dist/utils/git_repository_programs.js +38 -0
- package/dist/utils/host_shell.js +2 -1
- package/dist/utils/idle_compaction.js +8 -1
- package/dist/utils/image_fit.d.ts +4 -1
- package/dist/utils/image_fit.js +6 -2
- package/dist/utils/image_preview.js +3 -2
- package/dist/utils/mirror_media.d.ts +22 -4
- package/dist/utils/mirror_media.js +87 -86
- package/dist/utils/ml_native.js +11 -56
- package/dist/utils/native_install.d.ts +55 -0
- package/dist/utils/native_install.js +107 -0
- package/dist/utils/open_url.js +2 -0
- package/dist/utils/process_end.d.ts +16 -0
- package/dist/utils/process_end.js +73 -0
- package/dist/utils/router_catalog.js +9 -2
- package/dist/utils/sandbox.d.ts +64 -1
- package/dist/utils/sandbox.js +397 -89
- package/dist/utils/shell.js +31 -12
- package/dist/utils/subprocess_env.d.ts +218 -2
- package/dist/utils/subprocess_env.js +429 -11
- package/dist/utils/system_ps.d.ts +5 -0
- package/dist/utils/system_ps.js +30 -0
- package/dist/utils/tts.js +5 -0
- package/dist/utils/tts_native.js +13 -60
- package/dist/utils/zlicky_overlay.js +17 -50
- package/dist/utils/ztc_own_state.d.ts +58 -0
- package/dist/utils/ztc_own_state.js +236 -0
- package/dist/web/mirror_authenticator.d.ts +67 -6
- package/dist/web/mirror_authenticator.js +131 -22
- package/dist/web/mirror_stream.d.ts +54 -10
- package/dist/web/mirror_stream.js +379 -92
- package/dist/web/observer_query_redaction.js +53 -13
- package/dist/web/observer_secret_redaction.d.ts +59 -0
- package/dist/web/observer_secret_redaction.js +714 -0
- package/dist/web/pane_credentials.d.ts +20 -2
- package/dist/web/pane_credentials.js +58 -5
- package/dist/worker/executor.js +3 -1
- package/dist/workspace_collision.js +19 -15
- package/dist/zerg/local_zerg_launches.d.ts +27 -0
- package/dist/zerg/local_zerg_launches.js +198 -0
- package/dist/zlm-embed.mjs +6257 -2791
- package/npm-shrinkwrap.json +1 -1
- package/package.json +42 -15
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { accessSync, closeSync, constants, openSync, readSync, realpathSync, statSync } from 'node:fs';
|
|
2
|
+
import { basename, delimiter, isAbsolute, join, resolve } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Programs that run the script they are given as their first argument that is a file: a shell, or a language's
|
|
5
|
+
* interpreter. A hook's command line that starts one names that script as the hook's own code (hookProgramFiles).
|
|
6
|
+
*/
|
|
7
|
+
const INTERPRETERS = /^(?:sh|bash|zsh|dash|ksh|fish|node|nodejs|deno|bun|tsx|ts-node|python|python[23](?:\.\d+)?|ruby|perl|php|lua|osascript)$/;
|
|
8
|
+
/** The longest #! line read from a script, in bytes. */
|
|
9
|
+
const SHEBANG_MAX_BYTES = 256;
|
|
10
|
+
/** Shell words of COMMAND (quotes removed, unquoted operators as words of their own), enough to find what it starts. */
|
|
11
|
+
function shellWords(command) {
|
|
12
|
+
const words = [];
|
|
13
|
+
let word = '';
|
|
14
|
+
let inWord = false;
|
|
15
|
+
let quote = null;
|
|
16
|
+
const end = () => { if (inWord)
|
|
17
|
+
words.push(word); word = ''; inWord = false; };
|
|
18
|
+
for (let index = 0; index < command.length; index++) {
|
|
19
|
+
const char = command[index];
|
|
20
|
+
if (quote) {
|
|
21
|
+
if (char === quote)
|
|
22
|
+
quote = null;
|
|
23
|
+
else if (char === '\\' && quote === '"' && index + 1 < command.length)
|
|
24
|
+
word += command[++index];
|
|
25
|
+
else
|
|
26
|
+
word += char;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (char === '"' || char === '\'') {
|
|
30
|
+
quote = char;
|
|
31
|
+
inWord = true;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (char === '\\' && index + 1 < command.length) {
|
|
35
|
+
word += command[++index];
|
|
36
|
+
inWord = true;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (/\s/.test(char)) {
|
|
40
|
+
end();
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (';|&()<>'.includes(char)) {
|
|
44
|
+
end();
|
|
45
|
+
words.push(char);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
word += char;
|
|
49
|
+
inWord = true;
|
|
50
|
+
}
|
|
51
|
+
end();
|
|
52
|
+
return words;
|
|
53
|
+
}
|
|
54
|
+
/** WORD with $NAME, ${NAME} and a leading ~ expanded from ENV, as the hook's shell would. */
|
|
55
|
+
function expand(word, env) {
|
|
56
|
+
const home = env.HOME ?? '';
|
|
57
|
+
const tilde = word === '~' ? home : word.startsWith('~/') ? `${home}${word.slice(1)}` : word;
|
|
58
|
+
return tilde.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g, (_, braced, bare) => env[braced ?? bare] ?? '');
|
|
59
|
+
}
|
|
60
|
+
/** The regular file PATH names, through its links, or undefined. */
|
|
61
|
+
function regularFile(path) {
|
|
62
|
+
try {
|
|
63
|
+
return statSync(path).isFile() ? path : undefined;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Where the program NAME, a word without a slash, is found on ENV's PATH, as the hook's shell would find it. */
|
|
70
|
+
function onPath(name, env) {
|
|
71
|
+
for (const directory of (env.PATH ?? '').split(delimiter).filter(Boolean)) {
|
|
72
|
+
const candidate = join(directory, name);
|
|
73
|
+
if (!regularFile(candidate))
|
|
74
|
+
continue;
|
|
75
|
+
try {
|
|
76
|
+
accessSync(candidate, constants.X_OK);
|
|
77
|
+
return candidate;
|
|
78
|
+
}
|
|
79
|
+
catch { /* not executable here; the shell looks further */ }
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
/** The program WORD names: a path, from CWD, or a name found on ENV's PATH. */
|
|
84
|
+
function programFile(word, cwd, env) {
|
|
85
|
+
if (!word)
|
|
86
|
+
return undefined;
|
|
87
|
+
if (word.includes('/'))
|
|
88
|
+
return regularFile(isAbsolute(word) ? word : resolve(cwd, word));
|
|
89
|
+
return onPath(word, env);
|
|
90
|
+
}
|
|
91
|
+
/** The interpreter FILE's #! line names, with /usr/bin/env's program found on ENV's PATH. */
|
|
92
|
+
function shebangInterpreter(file, env) {
|
|
93
|
+
let line = '';
|
|
94
|
+
let fd;
|
|
95
|
+
try {
|
|
96
|
+
fd = openSync(file, 'r');
|
|
97
|
+
const buffer = Buffer.alloc(SHEBANG_MAX_BYTES);
|
|
98
|
+
line = buffer.subarray(0, readSync(fd, buffer, 0, SHEBANG_MAX_BYTES, 0)).toString('utf8').split('\n')[0] ?? '';
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
if (fd !== undefined)
|
|
105
|
+
closeSync(fd);
|
|
106
|
+
}
|
|
107
|
+
if (!line.startsWith('#!'))
|
|
108
|
+
return undefined;
|
|
109
|
+
const [interpreter, ...rest] = line.slice(2).trim().split(/\s+/);
|
|
110
|
+
if (!interpreter)
|
|
111
|
+
return undefined;
|
|
112
|
+
if (basename(interpreter) !== 'env')
|
|
113
|
+
return regularFile(interpreter);
|
|
114
|
+
const program = rest.find(arg => !arg.startsWith('-') && !arg.includes('='));
|
|
115
|
+
return program ? programFile(program, '/', env) : undefined;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The files a hook's COMMAND starts, run from CWD with ENV (its PATH and HOME): the program of each of its commands,
|
|
119
|
+
* found as its shell would find it; the interpreter a script's #! names, /usr/bin/env's program found on PATH; and the
|
|
120
|
+
* script an interpreter (INTERPRETERS) is given, its first argument that is a file. Each is given with the file its
|
|
121
|
+
* links lead to. Under a profile that limits the agent and lets it write, a hook's OS sandbox reads these beside the
|
|
122
|
+
* system and the project (hooks/runner.ts): the hook's own code, which its command line names. That command line is
|
|
123
|
+
* the person's, held as it was at startup under such a profile; no path the agent chooses is among them, and nothing
|
|
124
|
+
* else a hook reads or writes is.
|
|
125
|
+
*/
|
|
126
|
+
export function hookProgramFiles(command, cwd, env) {
|
|
127
|
+
const words = shellWords(command);
|
|
128
|
+
const files = new Set();
|
|
129
|
+
const add = (file) => {
|
|
130
|
+
if (!file)
|
|
131
|
+
return;
|
|
132
|
+
files.add(file);
|
|
133
|
+
try {
|
|
134
|
+
files.add(realpathSync(file));
|
|
135
|
+
}
|
|
136
|
+
catch { /* gone since it was found */ }
|
|
137
|
+
};
|
|
138
|
+
let atCommand = true;
|
|
139
|
+
for (let index = 0; index < words.length; index++) {
|
|
140
|
+
const word = words[index];
|
|
141
|
+
if (';|&()'.includes(word) && word.length === 1) {
|
|
142
|
+
atCommand = true;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (word === '<' || word === '>') {
|
|
146
|
+
index++;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (!atCommand)
|
|
150
|
+
continue;
|
|
151
|
+
// Assignments before a command, and the words that start the program after them, are not the program.
|
|
152
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*=/.test(word) || word === 'exec' || word === 'command' || word === 'env' || word.startsWith('-'))
|
|
153
|
+
continue;
|
|
154
|
+
atCommand = false;
|
|
155
|
+
const program = programFile(expand(word, env), cwd, env);
|
|
156
|
+
if (!program)
|
|
157
|
+
continue;
|
|
158
|
+
add(program);
|
|
159
|
+
add(shebangInterpreter(program, env));
|
|
160
|
+
if (!INTERPRETERS.test(basename(program)))
|
|
161
|
+
continue;
|
|
162
|
+
for (let next = index + 1; next < words.length; next++) {
|
|
163
|
+
const argument = words[next];
|
|
164
|
+
if (';|&()<>'.includes(argument) && argument.length === 1)
|
|
165
|
+
break;
|
|
166
|
+
if (argument.startsWith('-'))
|
|
167
|
+
continue;
|
|
168
|
+
const script = regularFile(resolve(cwd, expand(argument, env)));
|
|
169
|
+
if (script)
|
|
170
|
+
add(script);
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return [...files];
|
|
175
|
+
}
|
package/dist/hooks/runner.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
+
import { type SandboxCommandOptions } from '../utils/sandbox.js';
|
|
1
2
|
import type { HookCommandConfig, HookDispatchResult, HookEnvelope, HookEventName } from './types.js';
|
|
2
|
-
|
|
3
|
+
/** How hooks run beyond their configuration. */
|
|
4
|
+
export interface HookRunOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The agent's command policy (its permission profile and sandbox settings). Under one that runs commands only inside
|
|
7
|
+
* an OS sandbox (commandsRequireOsSandbox) and lets the agent write, a hook's command runs inside the same sandbox and
|
|
8
|
+
* roots as run_command's, with the environment buildHookEnv gives it, or not at all (see hookSandboxPlan).
|
|
9
|
+
*/
|
|
10
|
+
commandPolicy?: SandboxCommandOptions;
|
|
11
|
+
}
|
|
12
|
+
export declare function runHookEntries(event: HookEventName, entries: HookCommandConfig[], envelope: HookEnvelope, options?: HookRunOptions): Promise<HookDispatchResult>;
|
package/dist/hooks/runner.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'child_process';
|
|
2
|
+
import { refusedPassEnvNames } from '../utils/subprocess_env.js';
|
|
3
|
+
import { buildSandboxCommandPlan, commandsRequireOsSandbox, sandboxNoticesToTell } from '../utils/sandbox.js';
|
|
4
|
+
import { hookProgramFiles } from './program_files.js';
|
|
2
5
|
// Per-stream cap. Unbounded buffering lets a runaway hook (e.g.
|
|
3
6
|
// `yes | head -c 1G`) drive the parent OOM — 1MB is more than enough
|
|
4
7
|
// for the structured output we consume.
|
|
@@ -14,11 +17,18 @@ function isSafeEnvName(name) {
|
|
|
14
17
|
return true;
|
|
15
18
|
return SAFE_ENV_PREFIXES.some(prefix => name.startsWith(prefix));
|
|
16
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* A hook's environment: the safe names above and what its passEnv lists, but never a name passEnv may not give it
|
|
22
|
+
* (refusedPassEnvNames: ZTC's own credentials and variables, and any variable holding a copy of one of its credentials).
|
|
23
|
+
* Those it is refused, and the hook's result says so.
|
|
24
|
+
*/
|
|
17
25
|
function buildHookEnv(entry) {
|
|
26
|
+
const refused = refusedPassEnvNames(entry.passEnv ?? []);
|
|
27
|
+
const refusedSet = new Set(refused);
|
|
18
28
|
const passSet = new Set(entry.passEnv ?? []);
|
|
19
29
|
const out = {};
|
|
20
30
|
for (const [name, value] of Object.entries(process.env)) {
|
|
21
|
-
if (value === undefined)
|
|
31
|
+
if (value === undefined || refusedSet.has(name))
|
|
22
32
|
continue;
|
|
23
33
|
if (passSet.has(name)) {
|
|
24
34
|
out[name] = value;
|
|
@@ -29,7 +39,15 @@ function buildHookEnv(entry) {
|
|
|
29
39
|
if (isSafeEnvName(name))
|
|
30
40
|
out[name] = value;
|
|
31
41
|
}
|
|
32
|
-
return out;
|
|
42
|
+
return { env: out, refused };
|
|
43
|
+
}
|
|
44
|
+
/** What a hook's result says when its passEnv named what no hook is given (refusedPassEnvNames). */
|
|
45
|
+
function refusedPassEnvMessage(event, entry, refused) {
|
|
46
|
+
return {
|
|
47
|
+
level: 'warning',
|
|
48
|
+
text: `${event} hook (${entry.command}) ran without ${refused.join(', ')}, which its passEnv names: ZTC gives no hook `
|
|
49
|
+
+ 'its own credentials or variables, or another variable holding one of its credentials.',
|
|
50
|
+
};
|
|
33
51
|
}
|
|
34
52
|
function trimHookOutput(value) {
|
|
35
53
|
return value.trim();
|
|
@@ -105,14 +123,62 @@ function mergeDispatchResult(target, partial) {
|
|
|
105
123
|
target.failureReason = partial.failureReason;
|
|
106
124
|
}
|
|
107
125
|
}
|
|
108
|
-
|
|
126
|
+
/**
|
|
127
|
+
* The OS sandbox plan a hook's command runs in under POLICY, as run_command's would, keeping the hook's own environment
|
|
128
|
+
* (ENV); undefined under a policy that does not require one. Throws when the policy requires one and none is available.
|
|
129
|
+
* A profile whose agent writes nothing (read_only, hosted_read_only) requires one for the agent's commands, but leaves
|
|
130
|
+
* the agent nothing a hook could run of its making: it writes no hook, approval or file a hook runs, and the hooks are
|
|
131
|
+
* held as they were at startup. The person's own hooks there run as before, outside the sandbox: in its read-only,
|
|
132
|
+
* no-network one every hook that logged or notified failed (the reviewer's owner run, 2026-11-21).
|
|
133
|
+
*/
|
|
134
|
+
function hookSandboxPlan(entry, envelope, env, policy) {
|
|
135
|
+
if (!policy || !commandsRequireOsSandbox(policy) || policy.profile?.capabilities?.file_write === false)
|
|
136
|
+
return undefined;
|
|
137
|
+
// Beside the roots run_command has, the hook's own code: the program its command line starts, the interpreter a
|
|
138
|
+
// script's #! names and the script an interpreter is given, wherever the person keeps them (~/bin, nvm's node), read-only.
|
|
139
|
+
return buildSandboxCommandPlan(entry.command, envelope.cwd, { ...policy, env, keepEnvironment: true,
|
|
140
|
+
readPaths: hookProgramFiles(entry.command, envelope.cwd, env) });
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* What a hook's result says when the OS sandbox it ran in under PROFILE_ID refused it something: the hook was not run
|
|
144
|
+
* outside it, and what a hook there may reach.
|
|
145
|
+
*/
|
|
146
|
+
function sandboxRefusalNote(profileId) {
|
|
147
|
+
return `[ztc] The OS sandbox this hook runs in under the permission profile "${profileId}" refused it: there a hook reads `
|
|
148
|
+
+ 'only the system\'s folders, the project and its own program, interpreter and script, and writes only where the agent\'s '
|
|
149
|
+
+ 'commands may. Keep what the hook reads and writes there, or run ZTC under a profile whose agent writes nothing '
|
|
150
|
+
+ '(read_only), where hooks run outside the sandbox.';
|
|
151
|
+
}
|
|
152
|
+
async function runHookCommand(entry, envelope, env, policy) {
|
|
153
|
+
let plan;
|
|
154
|
+
try {
|
|
155
|
+
plan = hookSandboxPlan(entry, envelope, env, policy);
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
// Never outside the sandbox the profile requires: the hook is not run, and its result says why.
|
|
159
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
160
|
+
return { stdout: '', stderr: '', exitCode: 1, timedOut: false, stdoutTruncated: false, stderrTruncated: false, refused: reason };
|
|
161
|
+
}
|
|
109
162
|
return new Promise((resolve) => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
163
|
+
// Either start is stored in `child` itself, whose 'error' listener below hears a hook (or the sandbox it runs in)
|
|
164
|
+
// that cannot start, before Node can report it: a ?: around the two starts hides that from the spawn lint.
|
|
165
|
+
let child;
|
|
166
|
+
if (plan) {
|
|
167
|
+
child = spawn(plan.executable, plan.args, {
|
|
168
|
+
cwd: plan.cwd,
|
|
169
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
170
|
+
env: plan.env ?? env,
|
|
171
|
+
...(plan.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
child = spawn(entry.command, {
|
|
176
|
+
cwd: envelope.cwd,
|
|
177
|
+
shell: true,
|
|
178
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
179
|
+
env,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
116
182
|
let stdout = '';
|
|
117
183
|
let stderr = '';
|
|
118
184
|
let stdoutTruncated = false;
|
|
@@ -124,6 +190,22 @@ async function runHookCommand(entry, envelope) {
|
|
|
124
190
|
if (settled)
|
|
125
191
|
return;
|
|
126
192
|
settled = true;
|
|
193
|
+
// The sandbox's step after the hook, as after any command (utils/sandbox.ts afterCommand): what it undid, the hook's
|
|
194
|
+
// result says.
|
|
195
|
+
let said = plan ? sandboxNoticesToTell(plan) : [];
|
|
196
|
+
try {
|
|
197
|
+
said = [...said, ...(plan?.afterCommand?.() ?? [])];
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
said = [...said, `ZTC could not check what the hook left where the repository names the programs git starts: ${error.message}`];
|
|
201
|
+
}
|
|
202
|
+
plan?.cleanup?.();
|
|
203
|
+
if (said.length > 0)
|
|
204
|
+
stderr = [stderr, ...said.map(line => `[ztc] ${line}`)].filter(Boolean).join('\n');
|
|
205
|
+
// A hook the sandbox refused something says so, and what a hook there may reach.
|
|
206
|
+
if (plan?.enforcement === 'os' && exitCode !== 0 && /Operation not permitted/.test(stderr)) {
|
|
207
|
+
stderr = [stderr, sandboxRefusalNote(policy?.profileId ?? 'this profile')].join('\n');
|
|
208
|
+
}
|
|
127
209
|
resolve({ stdout, stderr, exitCode, timedOut, stdoutTruncated, stderrTruncated });
|
|
128
210
|
};
|
|
129
211
|
let killTimer = null;
|
|
@@ -197,7 +279,15 @@ function buildFailureMessage(event, entry, outcome) {
|
|
|
197
279
|
: `${event} hook failed (${entry.command}) with exit code ${outcome.exitCode}`,
|
|
198
280
|
};
|
|
199
281
|
}
|
|
200
|
-
|
|
282
|
+
/** What a hook's result says when its profile requires an OS sandbox that is unavailable, so it was not run. */
|
|
283
|
+
function refusedHookMessage(event, entry, reason) {
|
|
284
|
+
return {
|
|
285
|
+
level: 'error',
|
|
286
|
+
text: `${event} hook (${entry.command}) was not run: its permission profile runs commands only inside an OS sandbox, `
|
|
287
|
+
+ `which is unavailable here (${reason}).`,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
export async function runHookEntries(event, entries, envelope, options = {}) {
|
|
201
291
|
const result = {
|
|
202
292
|
matched: entries.length,
|
|
203
293
|
executed: 0,
|
|
@@ -208,7 +298,18 @@ export async function runHookEntries(event, entries, envelope) {
|
|
|
208
298
|
// later entry. All other events run every configured hook independently.
|
|
209
299
|
const haltOnExitFailure = event === 'PreToolUse';
|
|
210
300
|
for (const entry of entries) {
|
|
211
|
-
const
|
|
301
|
+
const { env, refused } = buildHookEnv(entry);
|
|
302
|
+
if (refused.length > 0)
|
|
303
|
+
result.messages.push(refusedPassEnvMessage(event, entry, refused));
|
|
304
|
+
const outcome = await runHookCommand(entry, envelope, env, options.commandPolicy);
|
|
305
|
+
if (outcome.refused !== undefined) {
|
|
306
|
+
result.failed = true;
|
|
307
|
+
result.failureReason = `${event} hook refused: no OS sandbox`;
|
|
308
|
+
result.messages.push(refusedHookMessage(event, entry, outcome.refused));
|
|
309
|
+
if (haltOnExitFailure)
|
|
310
|
+
break;
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
212
313
|
result.executed += 1;
|
|
213
314
|
if (outcome.stdoutTruncated) {
|
|
214
315
|
result.truncated = { ...result.truncated, stdout: true };
|
package/dist/hooks/types.d.ts
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Takes ZTC's credentials out of this process's environment into the host-credential store (config/host_credentials.ts)
|
|
3
|
+
* before any other module of the CLI runs. cli_main imports it first: no other module body sees a credential in
|
|
4
|
+
* process.env, and no program ZTC starts without an environment of its own inherits one.
|
|
5
|
+
*/
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Takes ZTC's credentials out of this process's environment into the host-credential store (config/host_credentials.ts)
|
|
3
|
+
* before any other module of the CLI runs. cli_main imports it first: no other module body sees a credential in
|
|
4
|
+
* process.env, and no program ZTC starts without an environment of its own inherits one.
|
|
5
|
+
*/
|
|
6
|
+
import { HostCredentialFileError, initHostCredentials } from './config/host_credentials.js';
|
|
7
|
+
try {
|
|
8
|
+
initHostCredentials();
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
// A credential file the host named that ZTC won't read (or a variable set with its file) is the host's to fix: say
|
|
12
|
+
// why, never the value, and start nothing.
|
|
13
|
+
if (!(error instanceof HostCredentialFileError))
|
|
14
|
+
throw error;
|
|
15
|
+
process.stderr.write(`[ztc] ${error.message}\n`);
|
|
16
|
+
process.exit(2);
|
|
17
|
+
}
|
|
@@ -97,8 +97,12 @@ export declare function heartbeatAgeMs(inst: ZtcInstance, now?: number): number
|
|
|
97
97
|
*/
|
|
98
98
|
export declare function hasStaleHeartbeat(inst: ZtcInstance, now?: number): boolean;
|
|
99
99
|
/**
|
|
100
|
-
* Single-character process state from
|
|
101
|
-
*
|
|
100
|
+
* Single-character process state from the system's ps (`R`, `S`, `T`, `Z`, …), or null when the state could not be
|
|
101
|
+
* read (non-POSIX host, no system ps, PID gone).
|
|
102
|
+
*
|
|
103
|
+
* Every heartbeat reads it for each quiet entry in the registry (`reapStoppedInstances`), and the registry is a file in
|
|
104
|
+
* this user's HOME that any program it runs can write, so a ps found on PATH would be started on an entry anyone can
|
|
105
|
+
* plant. It is the system's own, given nothing of ZTC's environment (utils/system_ps.ts).
|
|
102
106
|
*/
|
|
103
107
|
export declare function probeProcessState(pid: number): string | null;
|
|
104
108
|
/**
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
* owner's next heartbeat puts it back.
|
|
22
22
|
*/
|
|
23
23
|
import { chmodSync, closeSync, openSync, readFileSync, statSync, writeFileSync, mkdirSync, renameSync, unlinkSync } from 'fs';
|
|
24
|
-
import { execFileSync } from 'child_process';
|
|
25
24
|
import { join } from 'path';
|
|
26
25
|
import { homedir } from 'os';
|
|
27
26
|
import { randomUUID } from 'crypto';
|
|
27
|
+
import { systemPsOutput } from './utils/system_ps.js';
|
|
28
28
|
// ── Liveness policy ──────────────────────────────────────────────────────────
|
|
29
29
|
/** How often a live instance refreshes its `heartbeatAt`. */
|
|
30
30
|
export const INSTANCE_HEARTBEAT_MS = 15_000;
|
|
@@ -160,22 +160,16 @@ function isInstanceLive(inst) {
|
|
|
160
160
|
return typeof inst.parentPid === 'number' && isAlive(inst.parentPid);
|
|
161
161
|
}
|
|
162
162
|
/**
|
|
163
|
-
* Single-character process state from
|
|
164
|
-
*
|
|
163
|
+
* Single-character process state from the system's ps (`R`, `S`, `T`, `Z`, …), or null when the state could not be
|
|
164
|
+
* read (non-POSIX host, no system ps, PID gone).
|
|
165
|
+
*
|
|
166
|
+
* Every heartbeat reads it for each quiet entry in the registry (`reapStoppedInstances`), and the registry is a file in
|
|
167
|
+
* this user's HOME that any program it runs can write, so a ps found on PATH would be started on an entry anyone can
|
|
168
|
+
* plant. It is the system's own, given nothing of ZTC's environment (utils/system_ps.ts).
|
|
165
169
|
*/
|
|
166
170
|
export function probeProcessState(pid) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
encoding: 'utf-8',
|
|
170
|
-
timeout: 2_000,
|
|
171
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
172
|
-
});
|
|
173
|
-
const state = out.trim().charAt(0);
|
|
174
|
-
return state === '' ? null : state;
|
|
175
|
-
}
|
|
176
|
-
catch {
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
171
|
+
const state = systemPsOutput(['-o', 'state=', '-p', String(pid)], 2_000)?.trim().charAt(0) ?? '';
|
|
172
|
+
return state === '' ? null : state;
|
|
179
173
|
}
|
|
180
174
|
// ── File I/O (atomic) ────────────────────────────────────────────────────────
|
|
181
175
|
function readRaw() {
|
package/dist/intake/format.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import type { IntakeReceipt } from './store.js';
|
|
2
|
+
/**
|
|
3
|
+
* A request's action on one line, cut to LENGTH characters with an ellipsis saying so when it is longer. A notice or a
|
|
4
|
+
* listing shows it, perhaps to a read-only observer of the mirror, which withholds what may start a credential before
|
|
5
|
+
* the mark.
|
|
6
|
+
*/
|
|
7
|
+
export declare function actionPreview(action: string, length: number): string;
|
|
2
8
|
export declare function formatIntakeReceipt(receipt: IntakeReceipt): string;
|
package/dist/intake/format.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A request's action on one line, cut to LENGTH characters with an ellipsis saying so when it is longer. A notice or a
|
|
3
|
+
* listing shows it, perhaps to a read-only observer of the mirror, which withholds what may start a credential before
|
|
4
|
+
* the mark.
|
|
5
|
+
*/
|
|
6
|
+
export function actionPreview(action, length) {
|
|
7
|
+
const line = action.replace(/\s+/g, ' ');
|
|
8
|
+
return line.length > length ? `${line.slice(0, length)}…` : line;
|
|
9
|
+
}
|
|
1
10
|
export function formatIntakeReceipt(receipt) {
|
|
2
11
|
return [receipt.intakeId, `Task: ${receipt.taskId}`,
|
|
3
12
|
`Source: ${receipt.source.channel} · ${receipt.source.account} · ${receipt.source.eventId}`,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { actionPreview } from './format.js';
|
|
1
2
|
import { getIntakeReceipt, listIntakeReceipts } from './store.js';
|
|
2
3
|
import { watch } from 'node:fs';
|
|
3
4
|
import { lstat } from 'node:fs/promises';
|
|
@@ -122,7 +123,7 @@ export class IntakeNotifications {
|
|
|
122
123
|
for (const receipt of pending)
|
|
123
124
|
this.seen.add(receipt.intakeId);
|
|
124
125
|
return [`Inbox: ${pending.length} new request${pending.length === 1 ? '' : 's'} awaiting your review.`,
|
|
125
|
-
...pending.slice(0, 3).map(receipt => `${receipt.source.channel} · ${receipt.action
|
|
126
|
+
...pending.slice(0, 3).map(receipt => `${receipt.source.channel} · ${actionPreview(receipt.action, 80)}\n/inbox show ${receipt.intakeId}`),
|
|
126
127
|
'Receipt only. Use /inbox to review; nothing has been started.'].join('\n');
|
|
127
128
|
}
|
|
128
129
|
finally {
|
package/dist/lsp/manager.d.ts
CHANGED
|
@@ -100,6 +100,6 @@ export declare class LSPManager extends EventEmitter {
|
|
|
100
100
|
*/
|
|
101
101
|
export declare function getLSPManager(rootPath?: string): LSPManager;
|
|
102
102
|
/**
|
|
103
|
-
* Shutdown the LSP manager
|
|
103
|
+
* Shutdown the LSP manager. A call made while its servers stop gets a new one, not one being stopped.
|
|
104
104
|
*/
|
|
105
105
|
export declare function shutdownLSPManager(): Promise<void>;
|
package/dist/lsp/manager.js
CHANGED
|
@@ -353,11 +353,10 @@ export function getLSPManager(rootPath) {
|
|
|
353
353
|
return managerInstance;
|
|
354
354
|
}
|
|
355
355
|
/**
|
|
356
|
-
* Shutdown the LSP manager
|
|
356
|
+
* Shutdown the LSP manager. A call made while its servers stop gets a new one, not one being stopped.
|
|
357
357
|
*/
|
|
358
358
|
export async function shutdownLSPManager() {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
359
|
+
const manager = managerInstance;
|
|
360
|
+
managerInstance = null;
|
|
361
|
+
await manager?.stopAll();
|
|
363
362
|
}
|
package/dist/mcp/client.d.ts
CHANGED
|
@@ -22,4 +22,6 @@ export declare function adaptTool(client: Pick<Client, 'callTool'>, serverName:
|
|
|
22
22
|
export declare function initMcpServers(servers: Record<string, MCPServerConfig> | undefined, options?: {
|
|
23
23
|
ambientDiscovery?: boolean;
|
|
24
24
|
serverSet?: string;
|
|
25
|
+
/** The variables the profile names as provider keys (config apiKeyEnv), which no stdio server is started with unless its passEnv names one. */
|
|
26
|
+
providerKeyEnv?: Readonly<Record<string, string>>;
|
|
25
27
|
}): Promise<void>;
|