@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,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A host's pin of this session's permission profile and sandbox. A host that runs ZTC as a resident under limits it
|
|
3
|
+
* chose (ZergCloud's hub, which sets it next to ZTC_MODEL_PINNED) sets ZTC_PERMISSION_PROFILE_PINNED=1: the permission
|
|
4
|
+
* settings the session holds once its startup is done are then its only ones. That is the launch's --permission-profile,
|
|
5
|
+
* or the profile and sandbox of the hosted thread it started on, or the profile its config.json saves, with that
|
|
6
|
+
* profile's definition, the sandbox settings and the tool permissions as ZTC holds them. The resident's mirror is
|
|
7
|
+
* reachable by several clients (a controller, a relayed line, the host's own settings route), so only a refusal inside
|
|
8
|
+
* ZTC holds them.
|
|
9
|
+
*
|
|
10
|
+
* Every later change is refused at one point (ConfigStore), whoever asks, with pinnedPermissionsMessage, which names the
|
|
11
|
+
* variable and nothing of the profile: /permissions use and set, a /profile switch, create or duplicate that would
|
|
12
|
+
* change them, the settings panel's rows for them, a hosted thread's later set_session_settings revision that names
|
|
13
|
+
* another profile, and a store write of any of them; and so is a restart in place while config.json holds an edit to
|
|
14
|
+
* them, which the ZTC started again would pin (pinnedSettingsARestartWouldTake), and a factory reset, which would remove
|
|
15
|
+
* config.json (pinnedFactoryResetMessage). A clear of the session's own settings leaves them, a reload takes no
|
|
16
|
+
* config.json edit to them (nor to the rest of what could widen the profile, the MCP servers among them, as under a
|
|
17
|
+
* profile that limits the agent), and save() never writes them as the person's. Under it no saved setting gives a
|
|
18
|
+
* Claude Code or Codex pane ZTC's bypass of its permission prompts.
|
|
19
|
+
* /permissions still shows them, and says they are pinned. The pinned profile's relative file roots (workspace_autonomous's
|
|
20
|
+
* `.`) are resolved once, against the folder the session started in, its mounted workspace (profileRootedAt): a
|
|
21
|
+
* controller's /cd, an environment the session opens, or the agent built again in another folder moves none of them. A
|
|
22
|
+
* restart in place starts the next ZTC in that folder, and hands it what this pin was taken from (PermissionPinSource):
|
|
23
|
+
* one whose own differs, config.json or the host's thread edited after the restart's check, doesn't start
|
|
24
|
+
* (PermissionPinChangedError).
|
|
25
|
+
*
|
|
26
|
+
* A host that pins the permission settings means them to limit the agent: where the profile a session would pin limits
|
|
27
|
+
* nothing (trusted, the default; local_full), whatever gave it (no launch flag, config.json, a host's thread with no
|
|
28
|
+
* settings yet), or lets the agent's commands run outside an OS sandbox (one that only turns a capability off), where
|
|
29
|
+
* they reach ZTC's own state and the config.json the pin is taken from, it doesn't start, and says so
|
|
30
|
+
* (PermissionPinUnlimitedError).
|
|
31
|
+
*
|
|
32
|
+
* Read once, as the session starts (ConfigStore.pinStartupPermissions): nothing later in the process unsets it (a
|
|
33
|
+
* command, a config.json edit, a change of the process's environment), and a ZTC pane started from a pinned process is
|
|
34
|
+
* given the variable (permissionPinChildEnv), and one a pinned pane opens through the relay keeps it, so it pins what it
|
|
35
|
+
* starts on itself, as a colony cell, which inherits the environment, does. Without the variable, or with one that isn't
|
|
36
|
+
* 1 or true, nothing is pinned.
|
|
37
|
+
*
|
|
38
|
+
* Self-contained (no config store), as config/model_pin.ts, so the commands, the panes and the store can all read it.
|
|
39
|
+
*/
|
|
40
|
+
import { realpathSync } from 'node:fs';
|
|
41
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
42
|
+
/** The variable a host sets to 1 to pin the session's permission profile and sandbox. */
|
|
43
|
+
export const PERMISSION_PIN_ENV = 'ZTC_PERMISSION_PROFILE_PINNED';
|
|
44
|
+
/**
|
|
45
|
+
* PROFILE with its relative file roots (allowedPaths and deniedPaths that are neither absolute nor under `~`) resolved
|
|
46
|
+
* against FOLDER, as a pin holds them: the agent's file tools and its commands' OS sandbox resolve a relative root
|
|
47
|
+
* against the folder the agent works in, which a controller's /cd or an environment the session opens moves, so under
|
|
48
|
+
* the pin the roots are those of the folder the session started in. A root under `~` is the person's home whatever the
|
|
49
|
+
* folder, as both read it. A profile with no relative root is PROFILE as it is.
|
|
50
|
+
*/
|
|
51
|
+
export function profileRootedAt(profile, folder) {
|
|
52
|
+
const rooted = (paths) => paths?.map(path => (isAbsolute(path) || path === '~' || path.startsWith('~/') ? path : resolve(folder, path)));
|
|
53
|
+
return {
|
|
54
|
+
...profile,
|
|
55
|
+
...(profile.allowedPaths ? { allowedPaths: rooted(profile.allowedPaths) } : {}),
|
|
56
|
+
...(profile.deniedPaths ? { deniedPaths: rooted(profile.deniedPaths) } : {}),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** Whether the host asked for the pin: ZTC_PERMISSION_PROFILE_PINNED is 1 or true, as model_pin.ts reads ZTC_MODEL_PINNED. */
|
|
60
|
+
export function permissionPinRequested(env = process.env) {
|
|
61
|
+
return /^(?:1|true)$/i.test(env[PERMISSION_PIN_ENV]?.trim() ?? '');
|
|
62
|
+
}
|
|
63
|
+
/** The settings a pin holds, which no store write may change while it holds. */
|
|
64
|
+
export const PINNED_PERMISSION_SETTINGS = ['permissionProfile', 'permissionProfiles', 'sandbox', 'toolPermissions'];
|
|
65
|
+
/**
|
|
66
|
+
* What a refused change of a pinned session's permission settings says, and what /permissions shows under the pin: the
|
|
67
|
+
* variable, and nothing of the profile.
|
|
68
|
+
*/
|
|
69
|
+
export function pinnedPermissionsMessage() {
|
|
70
|
+
return `This session's permission profile and sandbox are pinned by its host (${PERMISSION_PIN_ENV}): they stay as the `
|
|
71
|
+
+ 'session started, with its tool permissions, and nothing in it can change them.';
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* What a refused factory reset says under the pin: the reset would remove config.json, which a ZTC started again reads
|
|
75
|
+
* its permission settings from, so nothing is reset; the person resets it from a ZTC its host doesn't pin.
|
|
76
|
+
*/
|
|
77
|
+
export function pinnedFactoryResetMessage() {
|
|
78
|
+
return `${pinnedPermissionsMessage()} A factory reset would remove config.json, so nothing was reset. To reset it, start `
|
|
79
|
+
+ `ZTC without ${PERMISSION_PIN_ENV}.`;
|
|
80
|
+
}
|
|
81
|
+
/** What a refused config-profile switch says: NAME would hold other permission settings; the session stays on CURRENT. */
|
|
82
|
+
export function pinnedPermissionsSwitchMessage(name, current) {
|
|
83
|
+
return `Config profile "${name}" holds another permission profile, sandbox or tool permissions than this session. `
|
|
84
|
+
+ `${pinnedPermissionsMessage()} This session stays on config profile "${current}".`;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Of UNTAKEN, what config.json changed since this ZTC started that a ZTC started again in place would take
|
|
88
|
+
* (ConfigStore.listSettingsARestartWouldTake), the pinned settings, and a config.json that can't be read again: a ZTC
|
|
89
|
+
* started again in place reads config.json afresh and pins what it says of them, so under the pin a restart in place
|
|
90
|
+
* that would take any of them is refused, whoever asks for it.
|
|
91
|
+
*/
|
|
92
|
+
export function pinnedSettingsARestartWouldTake(untaken) {
|
|
93
|
+
return untaken.filter(entry => PINNED_PERMISSION_SETTINGS.includes(entry) || entry.startsWith('config.json ('));
|
|
94
|
+
}
|
|
95
|
+
/** What a refused restart in place says under the pin: the settings config.json changed (EDITED), and the variable. */
|
|
96
|
+
export function pinnedRestartMessage(edited) {
|
|
97
|
+
return `ZTC did not start again in place: config.json changed ${edited.join(', ')} since this ZTC started, which a ZTC `
|
|
98
|
+
+ `started again in place would take. ${pinnedPermissionsMessage()} Put those settings back to start it again in place.`;
|
|
99
|
+
}
|
|
100
|
+
/** Whether FOLDER is PIN_FOLDER, the folder a pinned session started in, by real path; false where either is gone. */
|
|
101
|
+
export function isPinFolder(folder, pinFolder) {
|
|
102
|
+
try {
|
|
103
|
+
return realpathSync(folder) === realpathSync(pinFolder);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* What a refused restart in place says under the pin where it would start in WANTED, not FOLDER, the folder the session
|
|
111
|
+
* started in, whose relative roots the pin holds: a ZTC started again in place pins them at the folder it starts in, so
|
|
112
|
+
* it starts in FOLDER or not at all (a session the resume panel picks that works elsewhere, FOLDER gone).
|
|
113
|
+
*/
|
|
114
|
+
export function pinnedRestartFolderMessage(folder, wanted) {
|
|
115
|
+
const where = wanted === folder ? `the folder this session started in (${folder}) is gone`
|
|
116
|
+
: `it would start in ${wanted}, and a ZTC started again in place starts in the folder this session started in (${folder})`;
|
|
117
|
+
return `ZTC did not start again in place: ${where}. ${pinnedPermissionsMessage()} Its relative file roots are that folder's. `
|
|
118
|
+
+ 'Start ZTC yourself in the folder you want it to work in.';
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The variable a ZTC started again in place under the pin is handed, by the ZTC it replaces: what that ZTC's pin was
|
|
122
|
+
* taken from (PermissionPinSource), as JSON. Taken out of the environment as the pin is taken (takePermissionPinSource).
|
|
123
|
+
*/
|
|
124
|
+
export const PERMISSION_PIN_SOURCE_ENV = 'ZTC_PERMISSION_PIN_SOURCE';
|
|
125
|
+
/**
|
|
126
|
+
* What a ZTC started again in place in this one's stead is handed under the pin: the variable itself, whatever this
|
|
127
|
+
* process's environment says of it now (permissionPinChildEnv), so it pins itself, and SOURCE, this pin's.
|
|
128
|
+
*/
|
|
129
|
+
export function permissionPinRestartEnv(source) {
|
|
130
|
+
return source === undefined ? {} : { ...permissionPinChildEnv(true), [PERMISSION_PIN_SOURCE_ENV]: JSON.stringify(source) };
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The pin source this ZTC was handed, if it was started again in place under the pin, taken out of ENV so no program it
|
|
134
|
+
* starts inherits it: undefined without one, null for one that doesn't read as a source.
|
|
135
|
+
*/
|
|
136
|
+
export function takePermissionPinSource(env = process.env) {
|
|
137
|
+
const value = env[PERMISSION_PIN_SOURCE_ENV];
|
|
138
|
+
delete env[PERMISSION_PIN_SOURCE_ENV];
|
|
139
|
+
if (value === undefined)
|
|
140
|
+
return undefined;
|
|
141
|
+
try {
|
|
142
|
+
const source = JSON.parse(value);
|
|
143
|
+
return source !== null && typeof source === 'object' && typeof source.profileId === 'string' && typeof source.folder === 'string'
|
|
144
|
+
? source : null;
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* What a ZTC started again in place under the pin says as it exits, where the permission settings it would pin aren't
|
|
152
|
+
* those the ZTC it replaces pinned: config.json, or the host's thread, was edited after that ZTC's restart check.
|
|
153
|
+
*/
|
|
154
|
+
export function pinnedRestartChangedMessage() {
|
|
155
|
+
return 'ZTC did not start again in place: the permission settings it would pin changed after the ZTC it replaces '
|
|
156
|
+
+ 'checked them: config.json, or the host\'s thread, gives the profile, its definition, the sandbox or the tool '
|
|
157
|
+
+ `permissions otherwise now, or it started in another folder. ${pinnedPermissionsMessage()} Start ZTC again to pin `
|
|
158
|
+
+ 'them as they are now.';
|
|
159
|
+
}
|
|
160
|
+
/** A ZTC started again in place under the pin whose permission settings changed since its restart's check. */
|
|
161
|
+
export class PermissionPinChangedError extends Error {
|
|
162
|
+
name = 'PermissionPinChangedError';
|
|
163
|
+
constructor() { super(pinnedRestartChangedMessage()); }
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* What ZTC says as it refuses to start where its host asked for the pin and the permission profile it would pin,
|
|
167
|
+
* PROFILE_ID, limits nothing (config/profile_limits.ts), or, UNSANDBOXED, lets the agent's commands run outside an OS
|
|
168
|
+
* sandbox, where they reach ZTC's own state, config.json among it: a host that pins the permission settings means them
|
|
169
|
+
* to limit the agent. LAUNCH_FLAG: the entry point takes --permission-profile (zerg-ztc-headless takes the one
|
|
170
|
+
* config.json saves).
|
|
171
|
+
*/
|
|
172
|
+
export function pinnedUnlimitedMessage(profileId, launchFlag = true, unsandboxed = false) {
|
|
173
|
+
const limiting = unsandboxed ? 'a profile that keeps them in one (sandbox.requireOsEnforcement, as workspace_autonomous has) or runs none'
|
|
174
|
+
: 'a profile that limits the agent, such as workspace_autonomous';
|
|
175
|
+
const instead = launchFlag ? `Start ZTC with --permission-profile and ${limiting}` : `Save ${limiting}, as permissionProfile in config.json`;
|
|
176
|
+
const why = unsandboxed ? 'lets the agent\'s commands run outside an OS sandbox, where they reach ZTC\'s own state and the config.json '
|
|
177
|
+
+ 'the pin is taken from' : 'limits nothing';
|
|
178
|
+
return `ZTC did not start: its host pins this session's permission profile and sandbox (${PERMISSION_PIN_ENV}), and the `
|
|
179
|
+
+ `permission profile it would pin, ${profileId}, ${why}. ${instead}, or unset ${PERMISSION_PIN_ENV}.`;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* A session its host asked to pin whose permission profile limits nothing, or, UNSANDBOXED, lets the agent's commands run
|
|
183
|
+
* outside an OS sandbox: it doesn't start (pinnedUnlimitedMessage).
|
|
184
|
+
*/
|
|
185
|
+
export class PermissionPinUnlimitedError extends Error {
|
|
186
|
+
profileId;
|
|
187
|
+
unsandboxed;
|
|
188
|
+
name = 'PermissionPinUnlimitedError';
|
|
189
|
+
constructor(profileId, unsandboxed = false) {
|
|
190
|
+
super(pinnedUnlimitedMessage(profileId, true, unsandboxed));
|
|
191
|
+
this.profileId = profileId;
|
|
192
|
+
this.unsandboxed = unsandboxed;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/** A change of a pinned session's permission settings: its message names the variable and nothing of the profile. */
|
|
196
|
+
export class PermissionsPinnedError extends Error {
|
|
197
|
+
name = 'PermissionsPinnedError';
|
|
198
|
+
constructor(message = pinnedPermissionsMessage()) { super(message); }
|
|
199
|
+
}
|
|
200
|
+
/** What a ZTC pane a pinned process starts is given, so it pins itself whatever this process's environment says now. */
|
|
201
|
+
export function permissionPinChildEnv(pinned) {
|
|
202
|
+
return pinned ? { [PERMISSION_PIN_ENV]: '1' } : {};
|
|
203
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type SandboxBackendStatus } from '../utils/sandbox.js';
|
|
1
|
+
import { type SandboxBackendStatus, type SandboxCommandOptions } from '../utils/sandbox.js';
|
|
2
2
|
import type { ZTCConfig, ZTCPermissionProfile, ZTCToolCapability } from './types.js';
|
|
3
3
|
export declare const PERMISSION_CAPABILITIES: readonly ["file_read", "file_write", "shell_exec", "network", "screen_capture", "computer_control", "ml_inference"];
|
|
4
4
|
export interface PermissionPolicySnapshot {
|
|
@@ -12,6 +12,11 @@ export interface PermissionPolicySnapshot {
|
|
|
12
12
|
scope: string;
|
|
13
13
|
}
|
|
14
14
|
export declare function resolvePermissionProfile(config: ZTCConfig): ZTCPermissionProfile;
|
|
15
|
+
/**
|
|
16
|
+
* The command policy CONFIG's permission settings give the agent, as the agent factory hands it to run_command: its
|
|
17
|
+
* profile and sandbox settings. A hook's command runs under it too (hooks/runner.ts).
|
|
18
|
+
*/
|
|
19
|
+
export declare function commandPolicyFor(config: ZTCConfig): SandboxCommandOptions;
|
|
15
20
|
export declare function projectPermissionPolicy(config: ZTCConfig): PermissionPolicySnapshot;
|
|
16
21
|
/**
|
|
17
22
|
* The permission settings a ZTC pane starting now runs under: the profile's saved ones in PATH (its config.json), read
|
|
@@ -25,8 +30,10 @@ export declare function savedPermissionSettings(path: string): ZTCConfig;
|
|
|
25
30
|
* NEXT allows nothing more. A capability counts when NEXT turns on one CURRENT keeps off, or lets it run without the
|
|
26
31
|
* host's approval CURRENT asks for; so does leaving off an OS command sandbox CURRENT requests or requires; and, when
|
|
27
32
|
* CURRENT limits files, commands or network hosts, any other limits: limits aren't ordered, so other ones count as more.
|
|
33
|
+
* FOLDER, where given, is the folder the pane under NEXT starts in: both profiles' relative roots are resolved against
|
|
34
|
+
* it, as a pane under a host's pin holds its own (the pinned one's `.` held there counts as `.`).
|
|
28
35
|
*/
|
|
29
|
-
export declare function permissionsBeyond(next: ZTCConfig, current: ZTCConfig): string[];
|
|
36
|
+
export declare function permissionsBeyond(next: ZTCConfig, current: ZTCConfig, folder?: string): string[];
|
|
30
37
|
/** A permission profile the chosen provider cannot enforce: its message says what to change, so a run shows it as is. */
|
|
31
38
|
export declare class PermissionProfileUnsupportedError extends Error {
|
|
32
39
|
constructor(message: string);
|
|
@@ -8,6 +8,7 @@ import { build_default_config, DEFAULT_PERMISSION_PROFILES, withBuiltInProfiles
|
|
|
8
8
|
import { getSandboxPolicyStatus } from '../utils/sandbox.js';
|
|
9
9
|
import { isCodexAppServerProvider, isLocalSubscriptionProvider } from '../agent/backends/provider_ids.js';
|
|
10
10
|
import { assertProviderNotRetired } from './retired_routes.js';
|
|
11
|
+
import { profileRootedAt } from './permission_pin.js';
|
|
11
12
|
export const PERMISSION_CAPABILITIES = ['file_read', 'file_write', 'shell_exec', 'network', 'screen_capture', 'computer_control', 'ml_inference'];
|
|
12
13
|
const strings = z.array(z.string().min(1).max(2048)).max(128);
|
|
13
14
|
const profileSchema = z.object({
|
|
@@ -30,6 +31,13 @@ export function resolvePermissionProfile(config) {
|
|
|
30
31
|
throw new Error(`Invalid permission profile: ${id}`);
|
|
31
32
|
return parsed.data;
|
|
32
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* The command policy CONFIG's permission settings give the agent, as the agent factory hands it to run_command: its
|
|
36
|
+
* profile and sandbox settings. A hook's command runs under it too (hooks/runner.ts).
|
|
37
|
+
*/
|
|
38
|
+
export function commandPolicyFor(config) {
|
|
39
|
+
return { profileId: config.permissionProfile ?? 'trusted', profile: resolvePermissionProfile(config), sandbox: config.sandbox };
|
|
40
|
+
}
|
|
33
41
|
export function projectPermissionPolicy(config) {
|
|
34
42
|
const id = config.permissionProfile ?? 'trusted', profile = resolvePermissionProfile(config);
|
|
35
43
|
const capabilities = Object.fromEntries(PERMISSION_CAPABILITIES.map(cap => [cap,
|
|
@@ -93,8 +101,10 @@ function limitsOf(profile) {
|
|
|
93
101
|
* NEXT allows nothing more. A capability counts when NEXT turns on one CURRENT keeps off, or lets it run without the
|
|
94
102
|
* host's approval CURRENT asks for; so does leaving off an OS command sandbox CURRENT requests or requires; and, when
|
|
95
103
|
* CURRENT limits files, commands or network hosts, any other limits: limits aren't ordered, so other ones count as more.
|
|
104
|
+
* FOLDER, where given, is the folder the pane under NEXT starts in: both profiles' relative roots are resolved against
|
|
105
|
+
* it, as a pane under a host's pin holds its own (the pinned one's `.` held there counts as `.`).
|
|
96
106
|
*/
|
|
97
|
-
export function permissionsBeyond(next, current) {
|
|
107
|
+
export function permissionsBeyond(next, current, folder) {
|
|
98
108
|
const after = projectPermissionPolicy(next);
|
|
99
109
|
const before = projectPermissionPolicy(current);
|
|
100
110
|
const beyond = PERMISSION_CAPABILITIES.filter(cap => standing(after, cap) > standing(before, cap))
|
|
@@ -102,10 +112,11 @@ export function permissionsBeyond(next, current) {
|
|
|
102
112
|
if ((before.commandSandbox.requested && !after.commandSandbox.requested) || (before.commandSandbox.required && !after.commandSandbox.required)) {
|
|
103
113
|
beyond.push('no OS command sandbox');
|
|
104
114
|
}
|
|
105
|
-
const
|
|
115
|
+
const rooted = (profile) => (folder === undefined ? profile : profileRootedAt(profile, folder));
|
|
116
|
+
const limits = limitsOf(rooted(resolvePermissionProfile(current)));
|
|
106
117
|
const limited = [limits.allowedPaths, limits.deniedPaths, limits.allowedShellCommands, limits.deniedShellCommands, limits.allowedHosts,
|
|
107
118
|
limits.deniedHosts].some(list => list.length > 0);
|
|
108
|
-
if (limited && !isDeepStrictEqual(limitsOf(resolvePermissionProfile(next)), limits))
|
|
119
|
+
if (limited && !isDeepStrictEqual(limitsOf(rooted(resolvePermissionProfile(next))), limits))
|
|
109
120
|
beyond.push('other file, command or network limits');
|
|
110
121
|
return beyond;
|
|
111
122
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where ZTC sends a ZergAI platform login.
|
|
3
|
+
*
|
|
4
|
+
* The platform login (config.auth: one an older release's /auth login saved, or ZTC_AUTH_TOKEN, which a launcher hands
|
|
5
|
+
* over) authenticates ZTC to a ZergAI platform API, the one getApiBaseUrl() returns: as `Authorization: Token` on that
|
|
6
|
+
* API's own calls (the account check at startup, /zerg, the zerg tools, zerg mode's commands and the platform's legacy
|
|
7
|
+
* LLM endpoint), and as the bearer of that API's Router proxy (`<API>/api/zrouter`) for model turns.
|
|
8
|
+
*
|
|
9
|
+
* A launcher can hand ZTC_AUTH_TOKEN something else: a person's Zerg Router key, a Router inference token, a Router
|
|
10
|
+
* runtime grant. ZTC once took any of them as the platform login and sent it to whatever getApiBaseUrl() fell back to
|
|
11
|
+
* when nothing named a platform API: https://api.zergai.com, or http://localhost:8000 under the zerg entrypoint's
|
|
12
|
+
* default tier. So (ConfigStore.platformLoginRefusal):
|
|
13
|
+
*
|
|
14
|
+
* - A login from the environment goes only to a platform API someone named (ConfigStore.platformApiNamed:
|
|
15
|
+
* ZTC_API_BASE_URL, a colony's COLONY_PORT, an apiEnvironment the person chose, or that API's own Router proxy named
|
|
16
|
+
* in ZERG_PROXY_URL by the launcher, not filled in by the zerg image from its tier: PROXY_URL_SOURCE_ENV). With none,
|
|
17
|
+
* it goes nowhere, and ZTC says so once (PLATFORM_LOGIN_NOT_NAMED).
|
|
18
|
+
* - A Zerg Router credential ZTC can recognize goes to no platform API call, named or not
|
|
19
|
+
* (PLATFORM_LOGIN_IS_ROUTER_CREDENTIAL): one of Router's own shapes (looksLikeRouterCredential), or a value ZTC holds
|
|
20
|
+
* as a Router credential too (the host's Router runtime grant, the required Router's ZERG_AUTH_TOKEN, the profile's
|
|
21
|
+
* Router sign-in). A model turn through the named API's own Router proxy still goes with it, as it always did: that
|
|
22
|
+
* is inference, which none of this changes.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Where the zerg image's entrypoint (zerg/docker-entrypoint.sh) says it filled ZERG_PROXY_URL in itself, and from what:
|
|
26
|
+
* ZERG_DEPLOY_TIER (for a launcher that names a dev or prod tier, so zrouter mode, and no proxy, the tier's ZergAI
|
|
27
|
+
* platform proxy, https://api-dev.zergai.com/api/zrouter say) or ZERG_ROUTER_BASE_URL. The launcher named a tier or a
|
|
28
|
+
* Router, neither of which names a platform API, so a proxy so filled in names none either; one the launcher named
|
|
29
|
+
* itself (the ZergAI platform's own launch) does.
|
|
30
|
+
*/
|
|
31
|
+
export declare const PROXY_URL_SOURCE_ENV = "ZERG_PROXY_URL_SOURCE";
|
|
32
|
+
/**
|
|
33
|
+
* The prefixes of the credentials Zerg Router issues (zapps/zergrouter/server/lib): its API keys, workspace keys and the
|
|
34
|
+
* CLI device keys a device login exchanges for alike (router-keys.ts KEY_PREFIX, cli-device-auth.ts), Scholar workflow
|
|
35
|
+
* grants (scholar-workflow-grants.ts), delegated inference capabilities (delegated-inference-auth.ts), budget-bound
|
|
36
|
+
* continuation credentials (benchmark-continuations.ts) and Router Connect consent sessions (router-connect.ts). No
|
|
37
|
+
* ZergAI platform login has one: the platform's own tokens are hex (its API and zerg tokens) or zlm_access_....
|
|
38
|
+
*/
|
|
39
|
+
export declare const ROUTER_CREDENTIAL_PREFIXES: readonly string[];
|
|
40
|
+
/**
|
|
41
|
+
* Whether VALUE is a JSON Web Token whose audience (aud) is Zerg Router, as the runtime tokens ZergAI and Router mint for
|
|
42
|
+
* a zerg (runtime-tokens.ts: iss zergai, aud zergrouter) and Router's operator tokens are. Its claims are read, never
|
|
43
|
+
* its signature checked: the question is only what it is for.
|
|
44
|
+
*/
|
|
45
|
+
export declare function isRouterAudienceToken(value: string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Whether VALUE (blanks around it aside) is, by its shape alone, a credential Zerg Router issued: it begins with one of
|
|
48
|
+
* ROUTER_CREDENTIAL_PREFIXES, or it is a JSON Web Token for Router (isRouterAudienceToken). An opaque token (a Router
|
|
49
|
+
* inference token is 43 base64url characters) has no shape to tell; ZTC knows it as a Router credential only when it
|
|
50
|
+
* holds it as one too.
|
|
51
|
+
*/
|
|
52
|
+
export declare function looksLikeRouterCredential(value: string | undefined): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Why ZTC sends the platform login it holds to no platform API: ZTC_AUTH_TOKEN holds the host's Router runtime grant,
|
|
55
|
+
* which is never taken as a login at all; the login is a Zerg Router credential; or it came from the environment and
|
|
56
|
+
* no platform API is named for it.
|
|
57
|
+
*/
|
|
58
|
+
export type PlatformLoginRefusal = 'host_grant' | 'router_credential' | 'not_named';
|
|
59
|
+
/**
|
|
60
|
+
* What ZTC says once, at startup, when ZTC_AUTH_TOKEN is set but no platform API is named for it. It never repeats the
|
|
61
|
+
* value.
|
|
62
|
+
*/
|
|
63
|
+
export declare const PLATFORM_LOGIN_NOT_NAMED: string;
|
|
64
|
+
/** What ZTC says once, at startup, when ZTC_AUTH_TOKEN holds a Zerg Router credential. It never repeats the value. */
|
|
65
|
+
export declare const PLATFORM_LOGIN_IS_ROUTER_CREDENTIAL: string;
|
|
66
|
+
/**
|
|
67
|
+
* Why there is no platform login when the one config.json holds (the legacy token an older release's /auth login saved)
|
|
68
|
+
* is a Zerg Router credential, as /zerg, the zerg tools and zerg mode say it: no variable holds it, so none is named.
|
|
69
|
+
*/
|
|
70
|
+
export declare const SAVED_LOGIN_IS_ROUTER_CREDENTIAL: string;
|
|
71
|
+
/** Why there is no platform login (REFUSAL), as /zerg, the zerg tools and zerg mode say it. */
|
|
72
|
+
export declare function noPlatformLoginReason(refusal: PlatformLoginRefusal): string;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where ZTC sends a ZergAI platform login.
|
|
3
|
+
*
|
|
4
|
+
* The platform login (config.auth: one an older release's /auth login saved, or ZTC_AUTH_TOKEN, which a launcher hands
|
|
5
|
+
* over) authenticates ZTC to a ZergAI platform API, the one getApiBaseUrl() returns: as `Authorization: Token` on that
|
|
6
|
+
* API's own calls (the account check at startup, /zerg, the zerg tools, zerg mode's commands and the platform's legacy
|
|
7
|
+
* LLM endpoint), and as the bearer of that API's Router proxy (`<API>/api/zrouter`) for model turns.
|
|
8
|
+
*
|
|
9
|
+
* A launcher can hand ZTC_AUTH_TOKEN something else: a person's Zerg Router key, a Router inference token, a Router
|
|
10
|
+
* runtime grant. ZTC once took any of them as the platform login and sent it to whatever getApiBaseUrl() fell back to
|
|
11
|
+
* when nothing named a platform API: https://api.zergai.com, or http://localhost:8000 under the zerg entrypoint's
|
|
12
|
+
* default tier. So (ConfigStore.platformLoginRefusal):
|
|
13
|
+
*
|
|
14
|
+
* - A login from the environment goes only to a platform API someone named (ConfigStore.platformApiNamed:
|
|
15
|
+
* ZTC_API_BASE_URL, a colony's COLONY_PORT, an apiEnvironment the person chose, or that API's own Router proxy named
|
|
16
|
+
* in ZERG_PROXY_URL by the launcher, not filled in by the zerg image from its tier: PROXY_URL_SOURCE_ENV). With none,
|
|
17
|
+
* it goes nowhere, and ZTC says so once (PLATFORM_LOGIN_NOT_NAMED).
|
|
18
|
+
* - A Zerg Router credential ZTC can recognize goes to no platform API call, named or not
|
|
19
|
+
* (PLATFORM_LOGIN_IS_ROUTER_CREDENTIAL): one of Router's own shapes (looksLikeRouterCredential), or a value ZTC holds
|
|
20
|
+
* as a Router credential too (the host's Router runtime grant, the required Router's ZERG_AUTH_TOKEN, the profile's
|
|
21
|
+
* Router sign-in). A model turn through the named API's own Router proxy still goes with it, as it always did: that
|
|
22
|
+
* is inference, which none of this changes.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Where the zerg image's entrypoint (zerg/docker-entrypoint.sh) says it filled ZERG_PROXY_URL in itself, and from what:
|
|
26
|
+
* ZERG_DEPLOY_TIER (for a launcher that names a dev or prod tier, so zrouter mode, and no proxy, the tier's ZergAI
|
|
27
|
+
* platform proxy, https://api-dev.zergai.com/api/zrouter say) or ZERG_ROUTER_BASE_URL. The launcher named a tier or a
|
|
28
|
+
* Router, neither of which names a platform API, so a proxy so filled in names none either; one the launcher named
|
|
29
|
+
* itself (the ZergAI platform's own launch) does.
|
|
30
|
+
*/
|
|
31
|
+
export const PROXY_URL_SOURCE_ENV = 'ZERG_PROXY_URL_SOURCE';
|
|
32
|
+
/**
|
|
33
|
+
* The prefixes of the credentials Zerg Router issues (zapps/zergrouter/server/lib): its API keys, workspace keys and the
|
|
34
|
+
* CLI device keys a device login exchanges for alike (router-keys.ts KEY_PREFIX, cli-device-auth.ts), Scholar workflow
|
|
35
|
+
* grants (scholar-workflow-grants.ts), delegated inference capabilities (delegated-inference-auth.ts), budget-bound
|
|
36
|
+
* continuation credentials (benchmark-continuations.ts) and Router Connect consent sessions (router-connect.ts). No
|
|
37
|
+
* ZergAI platform login has one: the platform's own tokens are hex (its API and zerg tokens) or zlm_access_....
|
|
38
|
+
*/
|
|
39
|
+
export const ROUTER_CREDENTIAL_PREFIXES = Object.freeze(['sk-zr-', 'zr_swf_', 'zr_fid_', 'zrcb_', 'zrc_consent_']);
|
|
40
|
+
/** The audience of every JSON Web Token Zerg Router takes (zapps/zergrouter/server/lib/jwt.ts). */
|
|
41
|
+
const ROUTER_AUDIENCE = 'zergrouter';
|
|
42
|
+
/** The longest token read as a JSON Web Token: a Router bearer is at most 16 KiB (router_runtime_grant.ts). */
|
|
43
|
+
const MAX_TOKEN_LENGTH = 16 * 1024;
|
|
44
|
+
const BASE64URL = /^[A-Za-z0-9_-]+$/;
|
|
45
|
+
/**
|
|
46
|
+
* Whether VALUE is a JSON Web Token whose audience (aud) is Zerg Router, as the runtime tokens ZergAI and Router mint for
|
|
47
|
+
* a zerg (runtime-tokens.ts: iss zergai, aud zergrouter) and Router's operator tokens are. Its claims are read, never
|
|
48
|
+
* its signature checked: the question is only what it is for.
|
|
49
|
+
*/
|
|
50
|
+
export function isRouterAudienceToken(value) {
|
|
51
|
+
if (value.length > MAX_TOKEN_LENGTH)
|
|
52
|
+
return false;
|
|
53
|
+
const parts = value.split('.');
|
|
54
|
+
if (parts.length !== 3 || !parts.every(part => BASE64URL.test(part)))
|
|
55
|
+
return false;
|
|
56
|
+
try {
|
|
57
|
+
const claims = JSON.parse(Buffer.from(parts[1], 'base64url').toString('utf8'));
|
|
58
|
+
if (!claims || typeof claims !== 'object' || Array.isArray(claims))
|
|
59
|
+
return false;
|
|
60
|
+
const audience = claims.aud;
|
|
61
|
+
return audience === ROUTER_AUDIENCE || (Array.isArray(audience) && audience.includes(ROUTER_AUDIENCE));
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Whether VALUE (blanks around it aside) is, by its shape alone, a credential Zerg Router issued: it begins with one of
|
|
69
|
+
* ROUTER_CREDENTIAL_PREFIXES, or it is a JSON Web Token for Router (isRouterAudienceToken). An opaque token (a Router
|
|
70
|
+
* inference token is 43 base64url characters) has no shape to tell; ZTC knows it as a Router credential only when it
|
|
71
|
+
* holds it as one too.
|
|
72
|
+
*/
|
|
73
|
+
export function looksLikeRouterCredential(value) {
|
|
74
|
+
const token = value?.trim();
|
|
75
|
+
if (!token)
|
|
76
|
+
return false;
|
|
77
|
+
return ROUTER_CREDENTIAL_PREFIXES.some(prefix => token.startsWith(prefix)) || isRouterAudienceToken(token);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* What ZTC says once, at startup, when ZTC_AUTH_TOKEN is set but no platform API is named for it. It never repeats the
|
|
81
|
+
* value.
|
|
82
|
+
*/
|
|
83
|
+
export const PLATFORM_LOGIN_NOT_NAMED = '[ztc] ZTC_AUTH_TOKEN is set, but no ZergAI platform API is named for it, so ZTC takes '
|
|
84
|
+
+ 'it as no platform login and sends it nowhere. A platform login goes with ZTC_API_BASE_URL, the platform API that issued it. '
|
|
85
|
+
+ 'For Zerg Router, sign in with `ztc auth login`, or have the host set ZTC_ROUTER_RUNTIME_GRANT (or '
|
|
86
|
+
+ 'ZTC_ROUTER_RUNTIME_GRANT_FILE) with ZERG_ROUTER_BASE_URL.';
|
|
87
|
+
/** What ZTC says once, at startup, when ZTC_AUTH_TOKEN holds a Zerg Router credential. It never repeats the value. */
|
|
88
|
+
export const PLATFORM_LOGIN_IS_ROUTER_CREDENTIAL = '[ztc] ZTC_AUTH_TOKEN holds a Zerg Router credential, so ZTC takes it as no '
|
|
89
|
+
+ 'ZergAI platform login: no platform API call is sent it (no account check, /zerg or zerg tool). A host runs model turns on a '
|
|
90
|
+
+ 'Router credential with ZTC_ROUTER_RUNTIME_GRANT (or ZTC_ROUTER_RUNTIME_GRANT_FILE) and ZERG_ROUTER_BASE_URL; a platform '
|
|
91
|
+
+ 'login goes in ZTC_AUTH_TOKEN with ZTC_API_BASE_URL; or sign in with `ztc auth login`.';
|
|
92
|
+
/** Why there is no platform login, as /zerg, the zerg tools and zerg mode say it; never the value. */
|
|
93
|
+
const NO_PLATFORM_LOGIN = Object.freeze({
|
|
94
|
+
host_grant: 'ZTC_AUTH_TOKEN holds the host\'s Router runtime grant, which goes only to the Router ZERG_ROUTER_BASE_URL names: '
|
|
95
|
+
+ 'it is no ZergAI platform login, so nothing was sent.',
|
|
96
|
+
router_credential: 'ZTC_AUTH_TOKEN holds a Zerg Router credential, which ZTC never sends to the ZergAI platform API: it is no '
|
|
97
|
+
+ 'platform login, so nothing was sent. A platform login goes in ZTC_AUTH_TOKEN with ZTC_API_BASE_URL.',
|
|
98
|
+
not_named: 'ZTC_AUTH_TOKEN is set, but no ZergAI platform API is named for it, so it is no platform login and nothing was '
|
|
99
|
+
+ 'sent. Set ZTC_API_BASE_URL to the platform API that issued it.',
|
|
100
|
+
});
|
|
101
|
+
/**
|
|
102
|
+
* Why there is no platform login when the one config.json holds (the legacy token an older release's /auth login saved)
|
|
103
|
+
* is a Zerg Router credential, as /zerg, the zerg tools and zerg mode say it: no variable holds it, so none is named.
|
|
104
|
+
*/
|
|
105
|
+
export const SAVED_LOGIN_IS_ROUTER_CREDENTIAL = 'The ZergAI login saved in config.json holds a Zerg Router credential, which ZTC '
|
|
106
|
+
+ 'never sends to the ZergAI platform API: it is no platform login, so nothing was sent. For Zerg Router, sign in with '
|
|
107
|
+
+ '`ztc auth login`.';
|
|
108
|
+
/** Why there is no platform login (REFUSAL), as /zerg, the zerg tools and zerg mode say it. */
|
|
109
|
+
export function noPlatformLoginReason(refusal) {
|
|
110
|
+
return NO_PLATFORM_LOGIN[refusal];
|
|
111
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ZTCPermissionProfile, ZTCSandboxSettings } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Whether PROFILE limits the agent: it names file roots (allowedPaths, deniedPaths), shell-command or network-host
|
|
4
|
+
* limits, turns a capability off or asks the host before one, or keeps commands in an OS sandbox (requireOsEnforcement,
|
|
5
|
+
* a sandbox backend of its own, no network there); or the host's sandbox SETTINGS require OS enforcement. Under such a
|
|
6
|
+
* profile ZTC's own state is never the agent's (utils/ztc_own_state.ts) and what could widen the profile is taken as it
|
|
7
|
+
* was at startup (ConfigStore). ZTC's default profile, trusted, which desktop owners run, and local_full limit nothing.
|
|
8
|
+
*/
|
|
9
|
+
export declare function profileLimitsAgent(profile: ZTCPermissionProfile | undefined, settings?: ZTCSandboxSettings): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Whether commands under PROFILE, and the host's sandbox SETTINGS, run only inside an OS sandbox, or not at all: what
|
|
12
|
+
* the sandbox refuses to plan without one (utils/sandbox.ts). The settings or the profile require OS enforcement, or the
|
|
13
|
+
* profile writes nothing, which has no other way to keep a command from writing: a custom no-write profile with no
|
|
14
|
+
* sandbox block ran run_command without one (Idan's review of #884, round 2).
|
|
15
|
+
*/
|
|
16
|
+
export declare function osSandboxRequired(profile: ZTCPermissionProfile | undefined, settings?: ZTCSandboxSettings): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Whether commands under PROFILE, and the host's sandbox SETTINGS, are planned in an OS sandbox at all, whether or not
|
|
19
|
+
* this host has one: what /status calls requested. Where it is required (osSandboxRequired), and otherwise, unless the
|
|
20
|
+
* settings turn the sandbox off, where the profile names a backend of its own, file roots or denials, or keeps commands
|
|
21
|
+
* off the network, by its capabilities or its sandbox block. One that said so only in its sandbox block ran its
|
|
22
|
+
* commands with no sandbox, so they kept the network and read ZTC's own config.json (the reviewer's recheck of round 2,
|
|
23
|
+
* 2026-11-23).
|
|
24
|
+
*/
|
|
25
|
+
export declare function osSandboxRequested(profile: ZTCPermissionProfile | undefined, settings?: ZTCSandboxSettings): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether the agent can change what a git in its work tree starts, under PROFILE: one that limits it (profileLimitsAgent)
|
|
28
|
+
* and lets its commands write, whose sandboxed command can write the work tree's .git/config (an external diff, a clean
|
|
29
|
+
* filter, a textconv or signature program, a hooks folder). The file tools refuse that, but the sandbox, which lets a
|
|
30
|
+
* command commit, does not. ZTC's own git there runs outside the sandbox, as ZTC, so it then starts none of them
|
|
31
|
+
* (utils/git_repository_programs.ts). A profile whose agent writes nothing (read_only) or runs no command (safe_edits)
|
|
32
|
+
* leaves the repository's config as the person keeps it.
|
|
33
|
+
*/
|
|
34
|
+
export declare function agentWritesGitConfig(profile: ZTCPermissionProfile | undefined, settings?: ZTCSandboxSettings): boolean;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether PROFILE limits the agent: it names file roots (allowedPaths, deniedPaths), shell-command or network-host
|
|
3
|
+
* limits, turns a capability off or asks the host before one, or keeps commands in an OS sandbox (requireOsEnforcement,
|
|
4
|
+
* a sandbox backend of its own, no network there); or the host's sandbox SETTINGS require OS enforcement. Under such a
|
|
5
|
+
* profile ZTC's own state is never the agent's (utils/ztc_own_state.ts) and what could widen the profile is taken as it
|
|
6
|
+
* was at startup (ConfigStore). ZTC's default profile, trusted, which desktop owners run, and local_full limit nothing.
|
|
7
|
+
*/
|
|
8
|
+
export function profileLimitsAgent(profile, settings) {
|
|
9
|
+
if (settings?.requireOsEnforcement === true)
|
|
10
|
+
return true;
|
|
11
|
+
if (!profile)
|
|
12
|
+
return false;
|
|
13
|
+
const named = (list) => (list?.length ?? 0) > 0;
|
|
14
|
+
const backend = profile.sandbox?.backend;
|
|
15
|
+
return named(profile.allowedPaths) || named(profile.deniedPaths)
|
|
16
|
+
|| named(profile.allowedShellCommands) || named(profile.deniedShellCommands)
|
|
17
|
+
|| named(profile.networkHosts?.allow) || named(profile.networkHosts?.deny)
|
|
18
|
+
|| named(profile.approvalRequiredCapabilities)
|
|
19
|
+
|| Object.values(profile.capabilities ?? {}).some(enabled => enabled === false)
|
|
20
|
+
|| profile.sandbox?.requireOsEnforcement === true
|
|
21
|
+
|| profile.sandbox?.network === false
|
|
22
|
+
|| (backend !== undefined && backend !== 'auto' && backend !== 'none');
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Whether commands under PROFILE, and the host's sandbox SETTINGS, run only inside an OS sandbox, or not at all: what
|
|
26
|
+
* the sandbox refuses to plan without one (utils/sandbox.ts). The settings or the profile require OS enforcement, or the
|
|
27
|
+
* profile writes nothing, which has no other way to keep a command from writing: a custom no-write profile with no
|
|
28
|
+
* sandbox block ran run_command without one (Idan's review of #884, round 2).
|
|
29
|
+
*/
|
|
30
|
+
export function osSandboxRequired(profile, settings) {
|
|
31
|
+
return Boolean(settings?.requireOsEnforcement || profile?.sandbox?.requireOsEnforcement)
|
|
32
|
+
|| (profile !== undefined && profile.capabilities?.file_write === false);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Whether commands under PROFILE, and the host's sandbox SETTINGS, are planned in an OS sandbox at all, whether or not
|
|
36
|
+
* this host has one: what /status calls requested. Where it is required (osSandboxRequired), and otherwise, unless the
|
|
37
|
+
* settings turn the sandbox off, where the profile names a backend of its own, file roots or denials, or keeps commands
|
|
38
|
+
* off the network, by its capabilities or its sandbox block. One that said so only in its sandbox block ran its
|
|
39
|
+
* commands with no sandbox, so they kept the network and read ZTC's own config.json (the reviewer's recheck of round 2,
|
|
40
|
+
* 2026-11-23).
|
|
41
|
+
*/
|
|
42
|
+
export function osSandboxRequested(profile, settings) {
|
|
43
|
+
if (osSandboxRequired(profile, settings))
|
|
44
|
+
return true;
|
|
45
|
+
if (settings?.enabled === false)
|
|
46
|
+
return false;
|
|
47
|
+
const backend = profile?.sandbox?.backend;
|
|
48
|
+
if (backend && backend !== 'auto' && backend !== 'none')
|
|
49
|
+
return true;
|
|
50
|
+
if (profile?.allowedPaths?.length || profile?.deniedPaths?.length)
|
|
51
|
+
return true;
|
|
52
|
+
return profile?.capabilities?.network === false || profile?.sandbox?.network === false;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Whether the agent can change what a git in its work tree starts, under PROFILE: one that limits it (profileLimitsAgent)
|
|
56
|
+
* and lets its commands write, whose sandboxed command can write the work tree's .git/config (an external diff, a clean
|
|
57
|
+
* filter, a textconv or signature program, a hooks folder). The file tools refuse that, but the sandbox, which lets a
|
|
58
|
+
* command commit, does not. ZTC's own git there runs outside the sandbox, as ZTC, so it then starts none of them
|
|
59
|
+
* (utils/git_repository_programs.ts). A profile whose agent writes nothing (read_only) or runs no command (safe_edits)
|
|
60
|
+
* leaves the repository's config as the person keeps it.
|
|
61
|
+
*/
|
|
62
|
+
export function agentWritesGitConfig(profile, settings) {
|
|
63
|
+
if (!profileLimitsAgent(profile, settings))
|
|
64
|
+
return false;
|
|
65
|
+
return profile?.capabilities?.file_write !== false && profile?.capabilities?.shell_exec !== false;
|
|
66
|
+
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* instead. Only variable NAMES live here and in config.json; values are read
|
|
5
5
|
* from the process environment when a key is needed.
|
|
6
6
|
*/
|
|
7
|
+
import { hostEnvironmentValue } from './host_credentials.js';
|
|
7
8
|
/** Standard variables per provider, in lookup order. The one table config and defaults share. */
|
|
8
9
|
export const PROVIDER_API_KEY_ENV = {
|
|
9
10
|
anthropic: ['ANTHROPIC_API_KEY'],
|
|
@@ -24,7 +25,7 @@ export function providerApiKeyEnvNames(provider) {
|
|
|
24
25
|
/** The first standard variable that is set for a provider; blank counts as unset, as for a named one. */
|
|
25
26
|
export function readProviderApiKeyEnv(provider, env = process.env) {
|
|
26
27
|
for (const name of providerApiKeyEnvNames(provider)) {
|
|
27
|
-
const value = env
|
|
28
|
+
const value = hostEnvironmentValue(name, env)?.trim();
|
|
28
29
|
if (value)
|
|
29
30
|
return { name, value };
|
|
30
31
|
}
|
|
@@ -129,7 +130,7 @@ export function parseApiKeyEnvName(input, provider) {
|
|
|
129
130
|
export function readApiKeyEnvReference(name, provider, env = process.env) {
|
|
130
131
|
if (nameProblem(name, provider))
|
|
131
132
|
return undefined;
|
|
132
|
-
return env
|
|
133
|
+
return hostEnvironmentValue(name, env)?.trim() || undefined;
|
|
133
134
|
}
|
|
134
135
|
/**
|
|
135
136
|
* Set variables whose names suggest they hold this provider's key, standard
|
|
@@ -13,7 +13,12 @@ export declare function mergeProviderModels(...views: ProviderModels[]): Provide
|
|
|
13
13
|
export declare function readProviderModels(directory?: string): ProviderModels;
|
|
14
14
|
/** The model last used with `choiceId`, if the profile remembers one. */
|
|
15
15
|
export declare function rememberedModel(choiceId: string, directory?: string): string | undefined;
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Merge `updates` into the profile's file: read it, keep each provider's newest entry, and replace it atomically. Two
|
|
18
|
+
* writes at once, in this process or another, each read the file before the other replaced it, and the second dropped
|
|
19
|
+
* the first's entry (PR #902 UPG-4): a write waits for any other in this process, then holds the file's lock against
|
|
20
|
+
* other processes while it reads, merges and replaces it.
|
|
21
|
+
*/
|
|
17
22
|
export declare function recordProviderModels(updates: ProviderModels, directory?: string): Promise<void>;
|
|
18
23
|
/** Remember that `choiceId` was last used with `model`, now unless `usedAt` says when. */
|
|
19
24
|
export declare function rememberProviderModel(choiceId: string, model: string, options?: {
|