@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,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where ZTC's own native programs are: in ZTC's install only, never where a resident's agent can write. This is the one
|
|
3
|
+
* place that says so (tests/unit/native_helper_resolution_lint.test.ts keeps it the only one).
|
|
4
|
+
*
|
|
5
|
+
* The native helpers (ztc-audio for dictation, ztc-computer, ztc-ml, ztc-tts, the zlicky overlay) and the renderers
|
|
6
|
+
* (ztc-tui, zmux, zterm) are looked for (findNativeProgram) only in:
|
|
7
|
+
* - the package's bin/ beside dist (an npm install, the npm launcher's copy of one, and the desktop app's bundle, which
|
|
8
|
+
* holds the package at <app>.app/Contents/Resources/runtime/ztc), under their packaged names (bin/<name>-<os>-<cpu>,
|
|
9
|
+
* packagedName);
|
|
10
|
+
* - in a source checkout, the package's own build of them: packages/<crate>/target/release for a cargo crate, and its
|
|
11
|
+
* target/debug where the install has no other copy (a debug build is what `cargo build` and `cargo test` leave, and
|
|
12
|
+
* one left stale must not run ahead of the release copy in bin/), and native/zlicky-overlay for the overlay (with its
|
|
13
|
+
* main.swift, which /usr/bin/swift runs where no build is: zlickyOverlaySource).
|
|
14
|
+
* The package is the one this module is in, found from import.meta.url (ZTC_PACKAGE_ROOT), never from the working
|
|
15
|
+
* directory, HOME or the agent's work tree. Never the working directory, ~/.ztc/bin or a folder above the install: an
|
|
16
|
+
* agent writes those, and a binary planted there ran as ZTC's own (a ztc-tui file planted in ~/.ztc/bin let
|
|
17
|
+
* create_ztc_pane open panes where the image ships no renderer). No installer, launcher or the desktop app puts a binary
|
|
18
|
+
* in ~/.ztc/bin (scripts/build-rust.sh writes bin/, the desktop's /desktop install-cli its shim to ~/.local/bin). A
|
|
19
|
+
* packed install ships no build, so none is looked for there: a build put into one was put there afterwards.
|
|
20
|
+
*
|
|
21
|
+
* What a host chooses instead comes from ZTC's launch, which the agent can't change: the desktop app's bundle names its
|
|
22
|
+
* ZTerm in the runtime manifest ZTC_DESKTOP_RUNTIME_MANIFEST names (desktop/runtime.ts, which checks the app's lease), a
|
|
23
|
+
* host that embeds ZTC can hand TuiProcess a renderer of its own (desktopBinaryPath), an installed ZTerm.app in
|
|
24
|
+
* /Applications or ~/Applications comes ahead of the package's zterm, and ZTC_ZLICKY_DISABLE_NATIVE_OVERLAY=1 starts no
|
|
25
|
+
* overlay. No variable names another helper's path.
|
|
26
|
+
*/
|
|
27
|
+
import { existsSync } from 'node:fs';
|
|
28
|
+
import { basename, dirname, extname, join, resolve } from 'node:path';
|
|
29
|
+
import { fileURLToPath } from 'node:url';
|
|
30
|
+
/** ZTC's package root: two levels above this module, which is in src/utils or dist/utils. */
|
|
31
|
+
export const ZTC_PACKAGE_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..', '..');
|
|
32
|
+
/**
|
|
33
|
+
* Whether ZTC's install is a packed one, which ships no build: an npm install, and the npm launcher's copy of one that
|
|
34
|
+
* every npm launch runs ZTC from (each carries the launcher, npm-cli/run.cjs, which packing makes, and none of the
|
|
35
|
+
* package's sources), or the desktop app's bundle, which holds the package at <app>.app/Contents/Resources/runtime/ztc.
|
|
36
|
+
* Packing writes the launcher into the package root and nothing removes it, so a source checkout packing ran in has
|
|
37
|
+
* one too: its sources (src/cli_main.ts), which packing never ships (package.json "files"), keep it a checkout.
|
|
38
|
+
*/
|
|
39
|
+
export function isPackedZtcInstall(root = ZTC_PACKAGE_ROOT) {
|
|
40
|
+
if (existsSync(join(root, 'npm-cli', 'run.cjs')) && !existsSync(join(root, 'src', 'cli_main.ts')))
|
|
41
|
+
return true;
|
|
42
|
+
const contents = resolve(root, '..', '..', '..');
|
|
43
|
+
return basename(contents) === 'Contents' && extname(dirname(contents)) === '.app'
|
|
44
|
+
&& root === join(contents, 'Resources', 'runtime', 'ztc');
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Each program's build, and whether a source checkout's release build of it comes ahead of the copy in bin/:
|
|
48
|
+
* dictation's and ztc-computer's do, as each always did (a build a developer just made, ahead of a committed copy); the
|
|
49
|
+
* others' bin/ comes first. A debug build comes last for every program.
|
|
50
|
+
*/
|
|
51
|
+
const PROGRAMS = Object.freeze({
|
|
52
|
+
'ztc-audio': { build: { crate: 'ztc-dictation' }, buildFirst: true },
|
|
53
|
+
'ztc-computer': { build: { crate: 'ztc-computer' }, buildFirst: true },
|
|
54
|
+
'ztc-ml': { build: { crate: 'ztc-ml' }, buildFirst: false },
|
|
55
|
+
'ztc-tts': { build: { crate: 'ztc-tts' }, buildFirst: false },
|
|
56
|
+
'ztc-zlicky-overlay': { build: { folder: ['native', 'zlicky-overlay'] }, buildFirst: false },
|
|
57
|
+
'ztc-tui': { build: { crate: 'ztc-tui' }, buildFirst: false },
|
|
58
|
+
zmux: { build: { crate: 'zmux' }, buildFirst: false },
|
|
59
|
+
zterm: { build: { crate: 'zterm' }, buildFirst: false },
|
|
60
|
+
});
|
|
61
|
+
/** The platform as bin/ names it: darwin, linux or win. */
|
|
62
|
+
function packagedOs(platform) {
|
|
63
|
+
return platform === 'win32' ? 'win' : platform;
|
|
64
|
+
}
|
|
65
|
+
/** PROGRAM's name in the package's bin/: <name>-<os>-<cpu>, with .exe on Windows (zmux-darwin-arm64, ztc-tui-linux-x64). */
|
|
66
|
+
export function packagedName(program, platform = process.platform, arch = process.arch) {
|
|
67
|
+
return `${program}-${packagedOs(platform)}-${arch}${platform === 'win32' ? '.exe' : ''}`;
|
|
68
|
+
}
|
|
69
|
+
/** Where cargo puts PROGRAM's executable, crate CRATE, in PROFILE, under the package. */
|
|
70
|
+
function cargoBuild(crate, profile, program) {
|
|
71
|
+
return join(ZTC_PACKAGE_ROOT, 'packages', crate, 'target', profile, `${program}${process.platform === 'win32' ? '.exe' : ''}`);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Every place ZTC looks for PROGRAM, in order: its copy in the package's bin/ and a source checkout's build of it (the
|
|
75
|
+
* release build ahead of bin/ for a buildFirst program), then that checkout's debug build, which runs only where the
|
|
76
|
+
* install has no other copy.
|
|
77
|
+
*/
|
|
78
|
+
export function nativeProgramCandidates(program) {
|
|
79
|
+
const { build, buildFirst } = PROGRAMS[program];
|
|
80
|
+
const packaged = join(ZTC_PACKAGE_ROOT, 'bin', packagedName(program));
|
|
81
|
+
if (isPackedZtcInstall())
|
|
82
|
+
return [packaged];
|
|
83
|
+
const built = 'crate' in build ? cargoBuild(build.crate, 'release', program)
|
|
84
|
+
: join(ZTC_PACKAGE_ROOT, ...build.folder, program);
|
|
85
|
+
const debug = 'crate' in build ? [cargoBuild(build.crate, 'debug', program)] : [];
|
|
86
|
+
return [...(buildFirst ? [built, packaged] : [packaged, built]), ...debug];
|
|
87
|
+
}
|
|
88
|
+
/** PROGRAM's executable in ZTC's own install (nativeProgramCandidates), or null when the install has none. */
|
|
89
|
+
export function findNativeProgram(program) {
|
|
90
|
+
return nativeProgramCandidates(program).find(candidate => existsSync(candidate)) ?? null;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The command that builds PROGRAM in a source checkout, for a message that says how to get one: a packed install ships
|
|
94
|
+
* its copy and runs no build.
|
|
95
|
+
*/
|
|
96
|
+
export function nativeProgramBuildCommand(program) {
|
|
97
|
+
const { build } = PROGRAMS[program];
|
|
98
|
+
return 'crate' in build ? `cd packages/${build.crate} && cargo build --release` : 'npm run build:rust';
|
|
99
|
+
}
|
|
100
|
+
/** A source checkout's zlicky overlay source, which /usr/bin/swift can run where no build is; a packed install ships none. */
|
|
101
|
+
export function zlickyOverlaySource() {
|
|
102
|
+
if (isPackedZtcInstall())
|
|
103
|
+
return null;
|
|
104
|
+
const { build } = PROGRAMS['ztc-zlicky-overlay'];
|
|
105
|
+
const source = join(ZTC_PACKAGE_ROOT, ...('folder' in build ? build.folder : []), 'main.swift');
|
|
106
|
+
return existsSync(source) ? source : null;
|
|
107
|
+
}
|
package/dist/utils/open_url.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
+
import { buildUserSubprocessEnv } from './subprocess_env.js';
|
|
2
3
|
import { readFileSync } from 'node:fs';
|
|
3
4
|
import { browserLaunchAllowed } from './session_interactivity.js';
|
|
4
5
|
/** The launcher gate refused: ZTC_NO_BROWSER=1, or an automated run (CI, node --test). */
|
|
@@ -25,6 +26,7 @@ export function openUrlInBrowser(url) {
|
|
|
25
26
|
child = spawn(cmd, args, {
|
|
26
27
|
detached: true,
|
|
27
28
|
stdio: 'ignore',
|
|
29
|
+
env: buildUserSubprocessEnv(),
|
|
28
30
|
});
|
|
29
31
|
}
|
|
30
32
|
catch (err) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cleanups that run however this process ends, short of SIGKILL: as it exits (process.exit, or its event loop running
|
|
3
|
+
* out), and on a SIGINT, SIGTERM or SIGHUP that nothing else in the process handles, which would otherwise end it with
|
|
4
|
+
* no exit event at all (a process a test starts, ZTC before its own handlers are in place). Such a signal still ends
|
|
5
|
+
* the process as it would have: once the cleanups have run, it is raised again with no listener. A signal something
|
|
6
|
+
* else handles is that handler's to act on, and it may keep the process running; when the process then exits, the
|
|
7
|
+
* cleanups run.
|
|
8
|
+
*
|
|
9
|
+
* signal-exit's listeners handle no signal: once nothing but signal-exit listens, they end the process with the signal
|
|
10
|
+
* again (proper-lockfile loads signal-exit 3, and a Codex token refresh loads proper-lockfile). When only they listen
|
|
11
|
+
* besides this, the cleanups run and this steps aside for them to end the process.
|
|
12
|
+
*
|
|
13
|
+
* Each cleanup is synchronous and must not throw; one that does keeps no other from running.
|
|
14
|
+
*/
|
|
15
|
+
/** Run CLEANUP as this process ends (see above). Returns a function that withdraws it. */
|
|
16
|
+
export declare function onProcessEnd(cleanup: () => void): () => void;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cleanups that run however this process ends, short of SIGKILL: as it exits (process.exit, or its event loop running
|
|
3
|
+
* out), and on a SIGINT, SIGTERM or SIGHUP that nothing else in the process handles, which would otherwise end it with
|
|
4
|
+
* no exit event at all (a process a test starts, ZTC before its own handlers are in place). Such a signal still ends
|
|
5
|
+
* the process as it would have: once the cleanups have run, it is raised again with no listener. A signal something
|
|
6
|
+
* else handles is that handler's to act on, and it may keep the process running; when the process then exits, the
|
|
7
|
+
* cleanups run.
|
|
8
|
+
*
|
|
9
|
+
* signal-exit's listeners handle no signal: once nothing but signal-exit listens, they end the process with the signal
|
|
10
|
+
* again (proper-lockfile loads signal-exit 3, and a Codex token refresh loads proper-lockfile). When only they listen
|
|
11
|
+
* besides this, the cleanups run and this steps aside for them to end the process.
|
|
12
|
+
*
|
|
13
|
+
* Each cleanup is synchronous and must not throw; one that does keeps no other from running.
|
|
14
|
+
*/
|
|
15
|
+
const cleanups = new Set();
|
|
16
|
+
let installed = false;
|
|
17
|
+
/** The signals whose default ends the process without an exit event, and which ZTC is commonly ended by. */
|
|
18
|
+
const ENDING_SIGNALS = ['SIGINT', 'SIGTERM', 'SIGHUP'];
|
|
19
|
+
/**
|
|
20
|
+
* How many of a signal's listeners are signal-exit's: one for each loaded copy, of version 3 (counted on
|
|
21
|
+
* process.__signal_exit_emitter__) and of version 4 (on globalThis[Symbol.for('signal-exit emitter')]).
|
|
22
|
+
*/
|
|
23
|
+
function signalExitListeners() {
|
|
24
|
+
const emitters = [
|
|
25
|
+
process.__signal_exit_emitter__,
|
|
26
|
+
globalThis[Symbol.for('signal-exit emitter')],
|
|
27
|
+
];
|
|
28
|
+
let listeners = 0;
|
|
29
|
+
for (const emitter of emitters) {
|
|
30
|
+
const loaded = emitter?.count;
|
|
31
|
+
if (typeof loaded === 'number' && loaded > 0)
|
|
32
|
+
listeners += loaded;
|
|
33
|
+
}
|
|
34
|
+
return listeners;
|
|
35
|
+
}
|
|
36
|
+
function runCleanups() {
|
|
37
|
+
for (const cleanup of [...cleanups]) {
|
|
38
|
+
try {
|
|
39
|
+
cleanup();
|
|
40
|
+
}
|
|
41
|
+
catch { /* the others still run */ }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function install() {
|
|
45
|
+
if (installed)
|
|
46
|
+
return;
|
|
47
|
+
installed = true;
|
|
48
|
+
// Ahead of every other exit listener: one that throws skips the listeners after it.
|
|
49
|
+
process.prependListener('exit', runCleanups);
|
|
50
|
+
if (process.platform === 'win32')
|
|
51
|
+
return;
|
|
52
|
+
for (const signal of ENDING_SIGNALS) {
|
|
53
|
+
// Ahead of the others too, so it counts every listener the signal reaches, a once() listener's included.
|
|
54
|
+
const onSignal = () => {
|
|
55
|
+
const others = process.listenerCount(signal) - 1;
|
|
56
|
+
if (others > signalExitListeners())
|
|
57
|
+
return;
|
|
58
|
+
runCleanups();
|
|
59
|
+
process.removeListener(signal, onSignal);
|
|
60
|
+
// signal-exit's listeners run after this one in this emit and now find only signal-exit listening, so they raise
|
|
61
|
+
// the signal again. With nothing left listening, it is raised again here.
|
|
62
|
+
if (others === 0)
|
|
63
|
+
process.kill(process.pid, signal);
|
|
64
|
+
};
|
|
65
|
+
process.prependListener(signal, onSignal);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Run CLEANUP as this process ends (see above). Returns a function that withdraws it. */
|
|
69
|
+
export function onProcessEnd(cleanup) {
|
|
70
|
+
cleanups.add(cleanup);
|
|
71
|
+
install();
|
|
72
|
+
return () => { cleanups.delete(cleanup); };
|
|
73
|
+
}
|
|
@@ -4,6 +4,7 @@ import { mkdir, readdir, rename, stat, unlink, writeFile } from 'node:fs/promise
|
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
5
5
|
import { profileConfigDir } from '../config/profiles.js';
|
|
6
6
|
import { parsePriceRange } from './openrouter_prices.js';
|
|
7
|
+
import { MODEL_REQUEST_REDIRECT, refuseRouterRedirect } from '../agent/backends/model_redirect.js';
|
|
7
8
|
/**
|
|
8
9
|
* The model a switch to a provider lands on: its default, unless the account
|
|
9
10
|
* cannot use it, then the first model it can. Undefined for no rows.
|
|
@@ -163,10 +164,16 @@ export async function fetchRouterCatalog(connection, signal, provider) {
|
|
|
163
164
|
const file = routerCatalogScope(connection);
|
|
164
165
|
const timeout = AbortSignal.timeout(8000);
|
|
165
166
|
const suffix = provider === undefined ? '' : `?provider=${encodeURIComponent(provider)}`;
|
|
166
|
-
const
|
|
167
|
-
|
|
167
|
+
const url = `${connection.origin.replace(/\/+$/, '')}/v1/models${suffix}`;
|
|
168
|
+
// The read carries the Router's bearer and workspace, which go to this Router alone: a redirect is not followed, and
|
|
169
|
+
// what another address would say is never taken for its catalog.
|
|
170
|
+
const headers = { Authorization: `Bearer ${connection.token}`, ...(connection.workspaceId ? { 'X-Zerg-Workspace-ID': connection.workspaceId } : {}) };
|
|
171
|
+
const response = await fetch(url, {
|
|
172
|
+
headers,
|
|
168
173
|
signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
|
|
174
|
+
redirect: MODEL_REQUEST_REDIRECT,
|
|
169
175
|
});
|
|
176
|
+
await refuseRouterRedirect(response, url, 'the model catalog read', headers);
|
|
170
177
|
if (response.status === 401 || response.status === 403) {
|
|
171
178
|
const cached = memo.get(file);
|
|
172
179
|
if (cached)
|
package/dist/utils/sandbox.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ZTCPermissionProfile, ZTCSandboxBackend, ZTCSandboxSettings } from '../config/types.js';
|
|
2
2
|
import { ToolCapability } from '../agent/runtime/capabilities.js';
|
|
3
|
+
import { type GitProgramFiles } from './git_program_files.js';
|
|
3
4
|
export type SandboxEnforcement = 'none' | 'os' | 'partial' | 'unsupported';
|
|
4
5
|
export interface SandboxCommandOptions {
|
|
5
6
|
profile?: ZTCPermissionProfile;
|
|
@@ -8,6 +9,22 @@ export interface SandboxCommandOptions {
|
|
|
8
9
|
capabilities?: ToolCapability[];
|
|
9
10
|
/** Effective child environment used to resolve macOS developer-tool shims. */
|
|
10
11
|
env?: NodeJS.ProcessEnv;
|
|
12
|
+
/**
|
|
13
|
+
* The command keeps the environment it is started with, which its caller already built (a hook's: hooks/runner.ts),
|
|
14
|
+
* instead of bwrap's credential-safe allowlist: no value of it goes into bwrap's argv.
|
|
15
|
+
*/
|
|
16
|
+
keepEnvironment?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The session's working directory, where the command's cwd is another (run_command's `cwd`): its repository is
|
|
19
|
+
* protected wherever the command runs (utils/git_program_files.ts), and the profile's relative roots (`.`, `./build`)
|
|
20
|
+
* are its, as the agent's file tools resolve them: the folder a command runs in is no root of its own.
|
|
21
|
+
*/
|
|
22
|
+
sessionCwd?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Files the command may also read, read-only, beside its roots: a hook's own program, interpreter and script
|
|
25
|
+
* (hooks/program_files.ts). What ZTC hides of its own state stays hidden, and none of them is writable.
|
|
26
|
+
*/
|
|
27
|
+
readPaths?: readonly string[];
|
|
11
28
|
}
|
|
12
29
|
export interface SandboxCommandPlan {
|
|
13
30
|
executable: string;
|
|
@@ -23,6 +40,19 @@ export interface SandboxCommandPlan {
|
|
|
23
40
|
env?: NodeJS.ProcessEnv;
|
|
24
41
|
/** Release temporary policy files after execution; persistent audits remain. */
|
|
25
42
|
cleanup?: () => void;
|
|
43
|
+
/**
|
|
44
|
+
* What the command's result is to say about its sandbox, beside what it printed: a core.hooksPath folder its repository
|
|
45
|
+
* tracks, which stays the command's to write, and where the plan stopped looking for repositories to protect
|
|
46
|
+
* (utils/git_program_files.ts). sandboxNoticesToTell says each once.
|
|
47
|
+
*/
|
|
48
|
+
notices?: string[];
|
|
49
|
+
/**
|
|
50
|
+
* The step after the command, once it has ended and before its result is read: it undoes what the sandbox could not
|
|
51
|
+
* refuse the command where a repository names the programs git starts (bwrap: undoGitProgramWrites), puts back what
|
|
52
|
+
* the command broke of a repository the plan knew so that git took its folder for none (both backends:
|
|
53
|
+
* putBackBrokenRepositories), and says what it did. Its caller calls it once.
|
|
54
|
+
*/
|
|
55
|
+
afterCommand?: () => string[];
|
|
26
56
|
}
|
|
27
57
|
export interface SandboxBackendStatus {
|
|
28
58
|
backend: Exclude<ZTCSandboxBackend, 'auto'> | 'unsupported';
|
|
@@ -30,18 +60,44 @@ export interface SandboxBackendStatus {
|
|
|
30
60
|
available: boolean;
|
|
31
61
|
notes: string[];
|
|
32
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Whether a command under OPTIONS runs only inside an OS sandbox, or not at all: what buildSandboxCommandPlan refuses
|
|
65
|
+
* to plan without one. A hook's command follows the same rule as run_command's (hooks/runner.ts).
|
|
66
|
+
*/
|
|
67
|
+
export declare function commandsRequireOsSandbox(options: SandboxCommandOptions): boolean;
|
|
33
68
|
export declare function getSandboxBackendStatus(options?: SandboxCommandOptions): SandboxBackendStatus;
|
|
34
69
|
/** Runner admission facts, distinct from session-wide isolation or an executed receipt. */
|
|
35
70
|
export declare function getSandboxPolicyStatus(options?: SandboxCommandOptions): SandboxBackendStatus & {
|
|
36
71
|
requested: boolean;
|
|
37
72
|
required: boolean;
|
|
38
73
|
};
|
|
74
|
+
/** PLAN's notices that this ZTC process has not said yet, each now counted as said: a result that shows them says them. */
|
|
75
|
+
export declare function sandboxNoticesToTell(plan: Pick<SandboxCommandPlan, 'notices'>): string[];
|
|
76
|
+
/**
|
|
77
|
+
* The folders every command the OS sandbox runs under OPTIONS here reads, whatever its profile's roots: the system and
|
|
78
|
+
* its tools, and on macOS the selected Xcode's developer folders (as CWD's xcode-select names them). A command whose
|
|
79
|
+
* working directory is one of them reads nothing there its roots don't already give it.
|
|
80
|
+
*/
|
|
81
|
+
export declare function sandboxSystemReadRoots(options: SandboxCommandOptions, cwd: string): string[];
|
|
39
82
|
/**
|
|
40
83
|
* A seccomp filter, as bwrap --seccomp reads it, that refuses socket(AF_UNIX, …) with EACCES, and io_uring, whose
|
|
41
84
|
* socket requests seccomp does not see. Pathname sockets are files, so no mount hides every one: this keeps a command
|
|
42
85
|
* of a profile without network from any host service. Null on an architecture it does not know.
|
|
43
86
|
*/
|
|
44
87
|
export declare function unixSocketFilter(arch?: string): Buffer | null;
|
|
88
|
+
/** How buildBubblewrapArgs plans a command beyond its profile. */
|
|
89
|
+
export interface BubblewrapPlanOptions {
|
|
90
|
+
/** Hide ZTC's own state (utils/ztc_own_state.ts): by default, under a profile that limits the agent. */
|
|
91
|
+
hideOwnState?: boolean;
|
|
92
|
+
/** Keep the environment bwrap is started with (SandboxCommandOptions.keepEnvironment): no --clearenv, no --setenv. */
|
|
93
|
+
keepEnvironment?: boolean;
|
|
94
|
+
/** The session's working directory, whose repository is protected wherever the command runs (SandboxCommandOptions). */
|
|
95
|
+
sessionCwd?: string;
|
|
96
|
+
/** What the plan already found of the repositories the command can write (commandGitProgramFiles), not found again. */
|
|
97
|
+
gitPrograms?: GitProgramFiles | null;
|
|
98
|
+
/** Files the command may also read, read-only (SandboxCommandOptions.readPaths). */
|
|
99
|
+
readPaths?: readonly string[];
|
|
100
|
+
}
|
|
45
101
|
/**
|
|
46
102
|
* bwrap argv for one sandboxed shell command. Beyond the filesystem view, the
|
|
47
103
|
* child gets its own pid, ipc and uts namespaces (it cannot see or signal host
|
|
@@ -55,5 +111,12 @@ export declare function unixSocketFilter(arch?: string): Buffer | null;
|
|
|
55
111
|
*/
|
|
56
112
|
export declare function buildBubblewrapArgs(command: string, cwd: string, profile?: ZTCPermissionProfile, env?: NodeJS.ProcessEnv,
|
|
57
113
|
/** The descriptor bwrap reads a seccomp filter from (see unixSocketFilter), for a profile without network. */
|
|
58
|
-
seccompFd?: number): string[];
|
|
114
|
+
seccompFd?: number, plan?: BubblewrapPlanOptions): string[];
|
|
115
|
+
/**
|
|
116
|
+
* The bwrap plan for COMMAND in CWD under OPTIONS, which buildSandboxCommandPlan makes once it has found bwrap on this
|
|
117
|
+
* host: its argv (buildBubblewrapArgs), and the step after the command (afterCommand) that undoes what bwrap could not
|
|
118
|
+
* refuse it where a repository names the programs git starts, then puts back what it broke of a repository the plan
|
|
119
|
+
* knew, both from what the plan found before it ran.
|
|
120
|
+
*/
|
|
121
|
+
export declare function buildBubblewrapCommandPlan(command: string, cwd: string, options?: SandboxCommandOptions): SandboxCommandPlan;
|
|
59
122
|
export declare function buildSandboxCommandPlan(command: string, cwd: string, options?: SandboxCommandOptions): SandboxCommandPlan;
|