@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ToolCapability } from './capabilities.js';
|
|
2
|
-
import type { ZTCPermissionProfile } from '../../config/types.js';
|
|
2
|
+
import type { ZTCPermissionProfile, ZTCSandboxSettings } from '../../config/types.js';
|
|
3
3
|
export interface ToolPolicyRequest {
|
|
4
4
|
name: string;
|
|
5
5
|
args: Record<string, unknown>;
|
|
@@ -8,6 +8,13 @@ export interface ToolPolicyRequest {
|
|
|
8
8
|
executionCwd?: string;
|
|
9
9
|
/** The tool's commands run through run_command's OS sandbox (Tool.sandboxedCommands). */
|
|
10
10
|
sandboxedCommands?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The call starts no program the agent chose or wrote outside that sandbox (Tool.confinedCommands; for ztc_command,
|
|
13
|
+
* a command that declares no shell_exec of its own).
|
|
14
|
+
*/
|
|
15
|
+
confinedCommands?: boolean;
|
|
16
|
+
/** The person approved this call before the policy judged it: ask_before_mutation's prompt, or a PreToolUse hook's ask. */
|
|
17
|
+
approved?: boolean;
|
|
11
18
|
/** Host-declared shell text the call runs, after adapter mapping (exec_command runs `cmd` before `command`). The
|
|
12
19
|
* shell policy checks it in place of a `command` or `checked` argument. */
|
|
13
20
|
executionCommand?: string;
|
|
@@ -26,6 +33,25 @@ export interface ToolPolicyRequest {
|
|
|
26
33
|
* run_and_capture, Claude Code's Task and WebFetch) would run theirs outside it, so such a profile admits none of them.
|
|
27
34
|
*/
|
|
28
35
|
export declare function shellOutsideSandbox(fileWriteAllowed: boolean, capabilities: readonly ToolCapability[], sandboxedCommands?: boolean): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Whether a shell-capable tool starts a program the agent chose or wrote outside run_command's OS sandbox: one neither
|
|
38
|
+
* sandboxedCommands nor confinedCommands vouches for (Tool). run_and_capture runs its command directly, the pane tools
|
|
39
|
+
* run theirs in a pane, /claude and /codex open a CLI that runs commands, a workflow script runs in ZTC's own process.
|
|
40
|
+
* A profile whose commands run only inside an OS sandbox admits none of them unless it asks the person first
|
|
41
|
+
* (commandsSandboxOnly): the agent's own run_command was held there while these read past it (the reviewer's resident
|
|
42
|
+
* probe, 2026-11-21).
|
|
43
|
+
*/
|
|
44
|
+
export declare function startsProgramsOutsideSandbox(capabilities: readonly ToolCapability[], marks: {
|
|
45
|
+
sandboxedCommands?: boolean;
|
|
46
|
+
confinedCommands?: boolean;
|
|
47
|
+
}): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Whether a profile runs the agent's commands only inside an OS sandbox and nobody is asked before one: it requires OS
|
|
50
|
+
* enforcement, in itself or in the host's sandbox SETTINGS, or writes nothing (commandsRequireOsSandbox), and asks the
|
|
51
|
+
* person before no shell command (approvalRequiredCapabilities). Under it a tool that would start a program outside the
|
|
52
|
+
* sandbox (startsProgramsOutsideSandbox) is refused; where the person is asked first, they decide, as for any command.
|
|
53
|
+
*/
|
|
54
|
+
export declare function commandsSandboxOnly(profile: ZTCPermissionProfile | undefined, settings: ZTCSandboxSettings | undefined, approvalRequired?: readonly string[]): boolean;
|
|
29
55
|
export interface ToolPolicyDecision {
|
|
30
56
|
allowed: boolean;
|
|
31
57
|
reason?: string;
|
|
@@ -42,17 +68,52 @@ export declare class CapabilityPolicy implements Policy {
|
|
|
42
68
|
private permissions;
|
|
43
69
|
private profile?;
|
|
44
70
|
private cwd;
|
|
71
|
+
/** The host's sandbox settings, whose requireOsEnforcement holds the agent's commands to the OS sandbox too. */
|
|
72
|
+
private sandbox?;
|
|
45
73
|
/** Each write set a caller names, resolved once, so admitting a call's N paths reads its set once, not N times. */
|
|
46
74
|
private readonly resolvedWriteSets;
|
|
47
|
-
constructor(permissions?: Partial<Record<string, boolean>>, profile?: ZTCPermissionProfile, cwd?: string
|
|
75
|
+
constructor(permissions?: Partial<Record<string, boolean>>, profile?: ZTCPermissionProfile, cwd?: string, options?: {
|
|
76
|
+
sandbox?: ZTCSandboxSettings;
|
|
77
|
+
});
|
|
48
78
|
evaluateTool(request: ToolPolicyRequest): ToolPolicyDecision;
|
|
49
79
|
private evaluatePathPolicy;
|
|
80
|
+
/** The roots the profile allows and denies, canonical, a relative one this policy's folder's. */
|
|
81
|
+
private profileRoots;
|
|
82
|
+
/**
|
|
83
|
+
* Why PATH is refused under this profile, SUBJECT naming what it is (a path a call names, a command's working
|
|
84
|
+
* directory), or null: it is in ZTC's own state (OWN_STATE_HOLDING says where; null checks none) under a profile that
|
|
85
|
+
* limits the agent, in a root the profile denies, or outside the roots it allows (ROOTS, profileRoots) and the folders
|
|
86
|
+
* ALSO_READ gives (canonical), which a command may read as its roots.
|
|
87
|
+
*/
|
|
88
|
+
private refusePath;
|
|
89
|
+
/**
|
|
90
|
+
* The folder a shell tool runs its command in (its declared executionCwd: run_command's `cwd`, the emulated shells'
|
|
91
|
+
* workdir), under a profile that holds the agent's commands to the OS sandbox (commandsRequireOsSandbox). The sandbox
|
|
92
|
+
* holds the command's writes to the profile's roots, but lets it read the folder it runs in, so a folder outside those
|
|
93
|
+
* roots, or in one the profile denies, is refused as a read there is, naming the working directory: the agent named a
|
|
94
|
+
* folder its file tools may not read (the reviewer's pinned-resident probe, 2026-11-22). ZTC's own state stays the
|
|
95
|
+
* sandbox's to deny, as it denies it to the paths a command names. A tool that reads or writes files has its folder
|
|
96
|
+
* checked with its paths already (evaluatePathPolicy). Where the commands may run without the sandbox, nothing holds a
|
|
97
|
+
* command to the roots (its own text may change folder), so its folder is not checked, as before; nor in Docker mode,
|
|
98
|
+
* where it is a folder in the container. A folder the sandbox lets every command read (the system's and its tools',
|
|
99
|
+
* sandboxSystemReadRoots) gives a command there nothing it couldn't read already, so it runs there unless the profile
|
|
100
|
+
* denies it: `ls` in /usr/bin ran before the check (the reviewer's resident probe, 2026-11-22). A refusal says where to
|
|
101
|
+
* run the command instead.
|
|
102
|
+
*/
|
|
103
|
+
private evaluateWorkingDirectory;
|
|
104
|
+
/**
|
|
105
|
+
* REFUSED, the refusal of DIRECTORY as a command's working directory, with where to run the command instead: a folder
|
|
106
|
+
* inside the profile's roots (ROOTS) that it doesn't deny, or, where the session's folder is one, none at all.
|
|
107
|
+
*/
|
|
108
|
+
private workingDirectoryRefusal;
|
|
50
109
|
/**
|
|
51
110
|
* Rules for the files a call writes, under a profile that limits the agent. Such a write may not reach git's own
|
|
52
111
|
* directory: a setting there (a filter, core.fsmonitor) is a command any git ZTC starts in that work tree runs as
|
|
53
|
-
* ZTC, outside the profile and any OS sandbox. Nor
|
|
54
|
-
*
|
|
55
|
-
*
|
|
112
|
+
* ZTC, outside the profile and any OS sandbox. Nor anywhere else the repository names the programs git starts: the
|
|
113
|
+
* folder core.hooksPath names and the file a .git/config that is a link leads to (utils/git_program_files.ts), as the
|
|
114
|
+
* OS sandbox keeps them from a command. Nor may it replace an allowed root itself when that root is a directory (or
|
|
115
|
+
* does not exist yet), since an atomic write makes its temporary file beside its target, which for such a root is
|
|
116
|
+
* outside it.
|
|
56
117
|
*/
|
|
57
118
|
private evaluateWriteTargets;
|
|
58
119
|
/** `named` resolved against this policy's working directory, once per array (a fresh one each admission pass). */
|
|
@@ -6,6 +6,11 @@ import { parseCheckedCommandPlan } from './checked_commands.js';
|
|
|
6
6
|
import { formatCheckedStageCommand } from '../../utils/checked_shell.js';
|
|
7
7
|
import { canonicalPath, isWellFormedText, sameFileKey } from '../../utils/canonical_path.js';
|
|
8
8
|
import { gitDirectoryComponent, gitDirectoryPlantedByWriteSet, linkedGitDirectoryHolding } from '../../utils/git_directory_names.js';
|
|
9
|
+
import { gitProgramFiles } from '../../utils/git_program_files.js';
|
|
10
|
+
import { profileLimitsAgent } from '../../config/profile_limits.js';
|
|
11
|
+
import { commandsRequireOsSandbox, sandboxSystemReadRoots } from '../../utils/sandbox.js';
|
|
12
|
+
import { dockerTarget } from '../../utils/docker_target.js';
|
|
13
|
+
import { ztcOwnStateHolding, ztcOwnStateHoldingForRead } from '../../utils/ztc_own_state.js';
|
|
9
14
|
/**
|
|
10
15
|
* Whether a tool would run commands outside run_command's OS sandbox under a profile that writes nothing. read_only runs
|
|
11
16
|
* commands only there, where they can write nothing and reach no network; other shell-capable tools (agents, panes,
|
|
@@ -14,6 +19,26 @@ import { gitDirectoryComponent, gitDirectoryPlantedByWriteSet, linkedGitDirector
|
|
|
14
19
|
export function shellOutsideSandbox(fileWriteAllowed, capabilities, sandboxedCommands) {
|
|
15
20
|
return !fileWriteAllowed && capabilities.includes(ToolCapability.SHELL_EXEC) && sandboxedCommands !== true;
|
|
16
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Whether a shell-capable tool starts a program the agent chose or wrote outside run_command's OS sandbox: one neither
|
|
24
|
+
* sandboxedCommands nor confinedCommands vouches for (Tool). run_and_capture runs its command directly, the pane tools
|
|
25
|
+
* run theirs in a pane, /claude and /codex open a CLI that runs commands, a workflow script runs in ZTC's own process.
|
|
26
|
+
* A profile whose commands run only inside an OS sandbox admits none of them unless it asks the person first
|
|
27
|
+
* (commandsSandboxOnly): the agent's own run_command was held there while these read past it (the reviewer's resident
|
|
28
|
+
* probe, 2026-11-21).
|
|
29
|
+
*/
|
|
30
|
+
export function startsProgramsOutsideSandbox(capabilities, marks) {
|
|
31
|
+
return capabilities.includes(ToolCapability.SHELL_EXEC) && marks.sandboxedCommands !== true && marks.confinedCommands !== true;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Whether a profile runs the agent's commands only inside an OS sandbox and nobody is asked before one: it requires OS
|
|
35
|
+
* enforcement, in itself or in the host's sandbox SETTINGS, or writes nothing (commandsRequireOsSandbox), and asks the
|
|
36
|
+
* person before no shell command (approvalRequiredCapabilities). Under it a tool that would start a program outside the
|
|
37
|
+
* sandbox (startsProgramsOutsideSandbox) is refused; where the person is asked first, they decide, as for any command.
|
|
38
|
+
*/
|
|
39
|
+
export function commandsSandboxOnly(profile, settings, approvalRequired = profile?.approvalRequiredCapabilities ?? []) {
|
|
40
|
+
return commandsRequireOsSandbox({ profile, sandbox: settings }) && !approvalRequired.includes(ToolCapability.SHELL_EXEC);
|
|
41
|
+
}
|
|
17
42
|
export class AllowAllPolicy {
|
|
18
43
|
evaluateTool() {
|
|
19
44
|
return { allowed: true };
|
|
@@ -23,9 +48,11 @@ export class CapabilityPolicy {
|
|
|
23
48
|
permissions;
|
|
24
49
|
profile;
|
|
25
50
|
cwd;
|
|
51
|
+
/** The host's sandbox settings, whose requireOsEnforcement holds the agent's commands to the OS sandbox too. */
|
|
52
|
+
sandbox;
|
|
26
53
|
/** Each write set a caller names, resolved once, so admitting a call's N paths reads its set once, not N times. */
|
|
27
54
|
resolvedWriteSets = new WeakMap();
|
|
28
|
-
constructor(permissions, profile, cwd = process.cwd()) {
|
|
55
|
+
constructor(permissions, profile, cwd = process.cwd(), options = {}) {
|
|
29
56
|
this.permissions = {
|
|
30
57
|
file_read: true,
|
|
31
58
|
file_write: true,
|
|
@@ -38,6 +65,7 @@ export class CapabilityPolicy {
|
|
|
38
65
|
};
|
|
39
66
|
this.profile = profile;
|
|
40
67
|
this.cwd = cwd;
|
|
68
|
+
this.sandbox = options.sandbox;
|
|
41
69
|
}
|
|
42
70
|
evaluateTool(request) {
|
|
43
71
|
for (const capability of request.capabilities) {
|
|
@@ -53,10 +81,24 @@ export class CapabilityPolicy {
|
|
|
53
81
|
if (shellOutsideSandbox(fileWriteAllowed, request.capabilities, request.sandboxedCommands)) {
|
|
54
82
|
return { allowed: false, reason: 'Permission denied: shell_exec outside the OS sandbox; this profile runs commands only through run_command' };
|
|
55
83
|
}
|
|
84
|
+
// A profile that holds commands to the OS sandbox and asks nobody first: nothing the agent chose runs outside it.
|
|
85
|
+
// The person who approved this call (ask_before_mutation asks before the policy) decided it, as they do a command.
|
|
86
|
+
if (request.approved !== true && commandsSandboxOnly(this.profile, this.sandbox)
|
|
87
|
+
&& startsProgramsOutsideSandbox(request.capabilities, request)) {
|
|
88
|
+
return {
|
|
89
|
+
allowed: false,
|
|
90
|
+
reason: 'Permission denied: shell_exec outside the OS sandbox; this profile runs the agent\'s commands only inside '
|
|
91
|
+
+ 'an OS sandbox, through run_command, and starts no program of the agent\'s outside it',
|
|
92
|
+
};
|
|
93
|
+
}
|
|
56
94
|
const pathDecision = this.evaluatePathPolicy(request);
|
|
57
95
|
if (!pathDecision.allowed) {
|
|
58
96
|
return pathDecision;
|
|
59
97
|
}
|
|
98
|
+
const directoryDecision = this.evaluateWorkingDirectory(request);
|
|
99
|
+
if (!directoryDecision.allowed) {
|
|
100
|
+
return directoryDecision;
|
|
101
|
+
}
|
|
60
102
|
const targetDecision = this.evaluateWriteTargets(request);
|
|
61
103
|
if (!targetDecision.allowed) {
|
|
62
104
|
return targetDecision;
|
|
@@ -84,45 +126,114 @@ export class CapabilityPolicy {
|
|
|
84
126
|
if (paths.length === 0) {
|
|
85
127
|
return { allowed: true };
|
|
86
128
|
}
|
|
87
|
-
|
|
88
|
-
const
|
|
129
|
+
// A call that only reads may read the person's skills folder in ZTC's own state; one that writes may not.
|
|
130
|
+
const ownStateHolding = request.capabilities.includes(ToolCapability.FILE_WRITE) || request.writeTargets === true
|
|
131
|
+
? ztcOwnStateHolding : ztcOwnStateHoldingForRead;
|
|
132
|
+
const roots = this.profileRoots();
|
|
89
133
|
for (const path of paths) {
|
|
90
|
-
|
|
91
|
-
if (
|
|
92
|
-
return { allowed: false, reason:
|
|
93
|
-
}
|
|
94
|
-
const absolutePath = normalizeRoot(path, this.cwd);
|
|
95
|
-
const allowed = allowedRoots.filter(root => isWithinRoot(absolutePath, root));
|
|
96
|
-
// Canonical paths carry each existing component as the filesystem
|
|
97
|
-
// stores it, but a denied root that does not exist yet has no stored
|
|
98
|
-
// spelling: on a volume that ignores case or Unicode normalization,
|
|
99
|
-
// creating SECRETS or café (decomposed) creates the denied secrets or
|
|
100
|
-
// café. A denial therefore matches every spelling that can name the
|
|
101
|
-
// same file. An allowance stays exact, since on a filesystem that keeps
|
|
102
|
-
// those spellings apart, folding would allow a different directory.
|
|
103
|
-
const denied = deniedRoots.filter(root => isWithinRoot(sameFileKey(absolutePath), sameFileKey(root)));
|
|
104
|
-
const exception = this.profile.pathPrecedence === 'specific' && allowed.some(root => denied.every(blocked => root.length > blocked.length));
|
|
105
|
-
if (denied.length > 0 && !exception) {
|
|
106
|
-
return {
|
|
107
|
-
allowed: false,
|
|
108
|
-
reason: `Permission denied: path is blocked by profile (${path})`,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
if (allowedRoots.length > 0 && !allowedRoots.some(root => isWithinRoot(absolutePath, root))) {
|
|
112
|
-
return {
|
|
113
|
-
allowed: false,
|
|
114
|
-
reason: `Permission denied: path is outside allowed profile roots (${path})`,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
134
|
+
const refused = this.refusePath(path, roots, ownStateHolding, 'path');
|
|
135
|
+
if (refused !== null)
|
|
136
|
+
return { allowed: false, reason: refused };
|
|
117
137
|
}
|
|
118
138
|
return { allowed: true };
|
|
119
139
|
}
|
|
140
|
+
/** The roots the profile allows and denies, canonical, a relative one this policy's folder's. */
|
|
141
|
+
profileRoots() {
|
|
142
|
+
return {
|
|
143
|
+
allowed: (this.profile?.allowedPaths || []).map(path => normalizeRoot(path, this.cwd)),
|
|
144
|
+
denied: (this.profile?.deniedPaths || []).map(path => normalizeRoot(path, this.cwd)),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Why PATH is refused under this profile, SUBJECT naming what it is (a path a call names, a command's working
|
|
149
|
+
* directory), or null: it is in ZTC's own state (OWN_STATE_HOLDING says where; null checks none) under a profile that
|
|
150
|
+
* limits the agent, in a root the profile denies, or outside the roots it allows (ROOTS, profileRoots) and the folders
|
|
151
|
+
* ALSO_READ gives (canonical), which a command may read as its roots.
|
|
152
|
+
*/
|
|
153
|
+
refusePath(path, roots, ownStateHolding, subject, alsoRead) {
|
|
154
|
+
const profile = this.profile;
|
|
155
|
+
// Node writes a lone surrogate as U+FFFD, so such a path names a file other than the one its string spells.
|
|
156
|
+
if (!isWellFormedText(path)) {
|
|
157
|
+
return `Permission denied: a path must be well-formed Unicode text (${JSON.stringify(path)})`;
|
|
158
|
+
}
|
|
159
|
+
const { allowed: allowedRoots, denied: deniedRoots } = roots;
|
|
160
|
+
const absolutePath = normalizeRoot(path, this.cwd);
|
|
161
|
+
// ZTC's own state (its config folder, ~/.ztc, its runtime's hand-offs) is never the agent's under a profile that
|
|
162
|
+
// limits it, whatever allowedPaths or pathPrecedence say: a hook and its approval, an MCP server or a looser
|
|
163
|
+
// profile written there would run outside the profile and any sandbox. As named and as it resolves.
|
|
164
|
+
const ownState = ownStateHolding && profileLimitsAgent(profile)
|
|
165
|
+
? ownStateHolding(resolve(this.cwd, expandHome(path))) ?? ownStateHolding(absolutePath) : null;
|
|
166
|
+
if (ownState !== null) {
|
|
167
|
+
return `Permission denied: ${subject} is in ZTC's own state (${ownState}), which no profile that limits the agent reaches (${path})`;
|
|
168
|
+
}
|
|
169
|
+
const allowed = allowedRoots.filter(root => isWithinRoot(absolutePath, root));
|
|
170
|
+
// Canonical paths carry each existing component as the filesystem
|
|
171
|
+
// stores it, but a denied root that does not exist yet has no stored
|
|
172
|
+
// spelling: on a volume that ignores case or Unicode normalization,
|
|
173
|
+
// creating SECRETS or café (decomposed) creates the denied secrets or
|
|
174
|
+
// café. A denial therefore matches every spelling that can name the
|
|
175
|
+
// same file. An allowance stays exact, since on a filesystem that keeps
|
|
176
|
+
// those spellings apart, folding would allow a different directory.
|
|
177
|
+
const denied = deniedRoots.filter(root => isWithinRoot(sameFileKey(absolutePath), sameFileKey(root)));
|
|
178
|
+
const exception = profile.pathPrecedence === 'specific' && allowed.some(root => denied.every(blocked => root.length > blocked.length));
|
|
179
|
+
if (denied.length > 0 && !exception) {
|
|
180
|
+
return `Permission denied: ${subject} is blocked by profile (${path})`;
|
|
181
|
+
}
|
|
182
|
+
if (allowedRoots.length > 0 && allowed.length === 0 && !alsoRead?.().some(root => isWithinRoot(absolutePath, root))) {
|
|
183
|
+
return `Permission denied: ${subject} is outside allowed profile roots (${path})`;
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The folder a shell tool runs its command in (its declared executionCwd: run_command's `cwd`, the emulated shells'
|
|
189
|
+
* workdir), under a profile that holds the agent's commands to the OS sandbox (commandsRequireOsSandbox). The sandbox
|
|
190
|
+
* holds the command's writes to the profile's roots, but lets it read the folder it runs in, so a folder outside those
|
|
191
|
+
* roots, or in one the profile denies, is refused as a read there is, naming the working directory: the agent named a
|
|
192
|
+
* folder its file tools may not read (the reviewer's pinned-resident probe, 2026-11-22). ZTC's own state stays the
|
|
193
|
+
* sandbox's to deny, as it denies it to the paths a command names. A tool that reads or writes files has its folder
|
|
194
|
+
* checked with its paths already (evaluatePathPolicy). Where the commands may run without the sandbox, nothing holds a
|
|
195
|
+
* command to the roots (its own text may change folder), so its folder is not checked, as before; nor in Docker mode,
|
|
196
|
+
* where it is a folder in the container. A folder the sandbox lets every command read (the system's and its tools',
|
|
197
|
+
* sandboxSystemReadRoots) gives a command there nothing it couldn't read already, so it runs there unless the profile
|
|
198
|
+
* denies it: `ls` in /usr/bin ran before the check (the reviewer's resident probe, 2026-11-22). A refusal says where to
|
|
199
|
+
* run the command instead.
|
|
200
|
+
*/
|
|
201
|
+
evaluateWorkingDirectory(request) {
|
|
202
|
+
const directory = request.executionCwd;
|
|
203
|
+
if (!this.profile || directory === undefined || !request.capabilities.includes(ToolCapability.SHELL_EXEC)
|
|
204
|
+
|| request.capabilities.some(capability => capability === ToolCapability.FILE_READ || capability === ToolCapability.FILE_WRITE)
|
|
205
|
+
|| !commandsRequireOsSandbox({ profile: this.profile, sandbox: this.sandbox }) || dockerTarget() !== null) {
|
|
206
|
+
return { allowed: true };
|
|
207
|
+
}
|
|
208
|
+
const roots = this.profileRoots();
|
|
209
|
+
const systemReads = () => sandboxSystemReadRoots({ profile: this.profile, sandbox: this.sandbox }, this.cwd)
|
|
210
|
+
.map(root => canonicalPolicyPath(root, this.cwd));
|
|
211
|
+
const refused = this.refusePath(directory, roots, null, 'working directory', systemReads);
|
|
212
|
+
return refused === null ? { allowed: true } : { allowed: false, reason: this.workingDirectoryRefusal(refused, directory, roots) };
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* REFUSED, the refusal of DIRECTORY as a command's working directory, with where to run the command instead: a folder
|
|
216
|
+
* inside the profile's roots (ROOTS) that it doesn't deny, or, where the session's folder is one, none at all.
|
|
217
|
+
*/
|
|
218
|
+
workingDirectoryRefusal(refused, directory, roots) {
|
|
219
|
+
const denied = refused.startsWith('Permission denied: working directory is blocked by profile ');
|
|
220
|
+
if (!denied && !refused.startsWith('Permission denied: working directory is outside allowed profile roots '))
|
|
221
|
+
return refused;
|
|
222
|
+
const within = roots.allowed.length > 0 ? ` inside this profile's roots (${roots.allowed.join(', ')})` : '';
|
|
223
|
+
const folder = denied ? (within ? `a folder${within} that it doesn't deny` : 'a folder this profile doesn\'t deny') : `a folder${within}`;
|
|
224
|
+
const session = normalizeRoot(directory, this.cwd) !== normalizeRoot(this.cwd, this.cwd)
|
|
225
|
+
&& this.refusePath(this.cwd, roots, null, 'working directory') === null;
|
|
226
|
+
return `${refused}. Run the command in ${folder}: give it one${within ? ' there' : ''} as its working directory`
|
|
227
|
+
+ `${session ? ', or none to run it in the session\'s folder' : ''}.`;
|
|
228
|
+
}
|
|
120
229
|
/**
|
|
121
230
|
* Rules for the files a call writes, under a profile that limits the agent. Such a write may not reach git's own
|
|
122
231
|
* directory: a setting there (a filter, core.fsmonitor) is a command any git ZTC starts in that work tree runs as
|
|
123
|
-
* ZTC, outside the profile and any OS sandbox. Nor
|
|
124
|
-
*
|
|
125
|
-
*
|
|
232
|
+
* ZTC, outside the profile and any OS sandbox. Nor anywhere else the repository names the programs git starts: the
|
|
233
|
+
* folder core.hooksPath names and the file a .git/config that is a link leads to (utils/git_program_files.ts), as the
|
|
234
|
+
* OS sandbox keeps them from a command. Nor may it replace an allowed root itself when that root is a directory (or
|
|
235
|
+
* does not exist yet), since an atomic write makes its temporary file beside its target, which for such a root is
|
|
236
|
+
* outside it.
|
|
126
237
|
*/
|
|
127
238
|
evaluateWriteTargets(request) {
|
|
128
239
|
if (request.writeTargets !== true || !this.limitsAgent()) {
|
|
@@ -137,6 +248,12 @@ export class CapabilityPolicy {
|
|
|
137
248
|
const writeSet = request.writeSet === undefined
|
|
138
249
|
? extractPathArgs(request.args, request.executionCwd).map(path => resolve(this.cwd, expandHome(path)))
|
|
139
250
|
: this.resolvedWriteSet(request.writeSet);
|
|
251
|
+
// Where the repositories the agent may write name programs, read once per call: git's own answer, as the sandbox
|
|
252
|
+
// reads it, for the work tree's repository and each one a walk of the allowed roots finds (a session started in a
|
|
253
|
+
// folder that holds repositories), with each one an earlier plan of this process found. A profile that names no
|
|
254
|
+
// roots walks none.
|
|
255
|
+
let programs;
|
|
256
|
+
const programPaths = () => programs ??= gitProgramFiles([this.cwd, ...allowedRoots], allowedRoots.length > 0 ? allowedRoots : [sep], { walk: allowedRoots });
|
|
140
257
|
for (const path of extractPathArgs(request.args, request.executionCwd)) {
|
|
141
258
|
// As the path policy refuses under a profile: the file Node writes is not the one the string spells.
|
|
142
259
|
if (!isWellFormedText(path)) {
|
|
@@ -168,6 +285,17 @@ export class CapabilityPolicy {
|
|
|
168
285
|
reason: `Permission denied: this write would make a git directory (${planted}), which a confined write may not create (${path})`,
|
|
169
286
|
};
|
|
170
287
|
}
|
|
288
|
+
// As written and as resolved, in any spelling that names the same file.
|
|
289
|
+
const named = [spelled, canonical].map(sameFileKey);
|
|
290
|
+
const { files, folders } = programPaths();
|
|
291
|
+
const program = files.find(file => named.includes(sameFileKey(file)))
|
|
292
|
+
?? folders.find(folder => named.some(name => isWithinRoot(name, sameFileKey(folder))));
|
|
293
|
+
if (program !== undefined) {
|
|
294
|
+
return {
|
|
295
|
+
allowed: false,
|
|
296
|
+
reason: `Permission denied: path is where the repository names the programs git starts (${program}), which a confined write may not change (${path})`,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
171
299
|
}
|
|
172
300
|
return { allowed: true };
|
|
173
301
|
}
|
|
@@ -6,5 +6,12 @@ export interface RemoteBrokerConfiguration {
|
|
|
6
6
|
/** Explicit host-only development exception, limited to numeric loopback addresses. */
|
|
7
7
|
allowInsecureLoopback?: boolean;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Why RESOURCE's broker can't take its credential from the variable its tokenEnv names, or undefined when it can: that
|
|
11
|
+
* variable is reserved for a credential ZTC sends only where it is for (subprocess_env.ts reservedCredentialEnv), or it
|
|
12
|
+
* holds the host's Router runtime grant under another name. A broker is sent its tokenEnv's value, so it never gets one
|
|
13
|
+
* of those. The refusal names the variable, never its value. A malformed name is refused where it is read, as before.
|
|
14
|
+
*/
|
|
15
|
+
export declare function brokerCredentialRefusal(resource: Readonly<RemoteResource>, env?: NodeJS.ProcessEnv): string | undefined;
|
|
9
16
|
/** Resolve the host endpoint and credential before reserving a mutation. */
|
|
10
17
|
export declare function makeRemoteBrokerTransport(resource: Readonly<RemoteResource>): RemoteResourceTransport;
|
|
@@ -1,7 +1,33 @@
|
|
|
1
1
|
import { isIP } from 'node:net';
|
|
2
2
|
import { remoteResourceEndpoint } from './remote_resource_endpoint.js';
|
|
3
|
-
import { RemoteResourceRejectedError } from './remote_resource_errors.js';
|
|
3
|
+
import { RemoteResourceConfigurationError, RemoteResourceRejectedError } from './remote_resource_errors.js';
|
|
4
|
+
import { holdsHostRouterGrant } from '../../config/router_runtime_grant.js';
|
|
5
|
+
import { hostEnvironmentValue } from '../../config/host_credentials.js';
|
|
6
|
+
import { reservedCredentialEnv } from '../../utils/subprocess_env.js';
|
|
4
7
|
const maximumBytes = 8 * 1024 * 1024;
|
|
8
|
+
const ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
|
|
9
|
+
/** What a reserved variable holds, as a broker's refusal says it. */
|
|
10
|
+
const RESERVED_CREDENTIALS = {
|
|
11
|
+
host_router_grant: 'the host\'s Router runtime grant, which ZTC sends only to the Router the host named',
|
|
12
|
+
ztc_credential: 'one of ZTC\'s own credentials, which ZTC sends only where it is for',
|
|
13
|
+
model_route: 'a model route\'s credential, which ZTC sends only on that route',
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Why RESOURCE's broker can't take its credential from the variable its tokenEnv names, or undefined when it can: that
|
|
17
|
+
* variable is reserved for a credential ZTC sends only where it is for (subprocess_env.ts reservedCredentialEnv), or it
|
|
18
|
+
* holds the host's Router runtime grant under another name. A broker is sent its tokenEnv's value, so it never gets one
|
|
19
|
+
* of those. The refusal names the variable, never its value. A malformed name is refused where it is read, as before.
|
|
20
|
+
*/
|
|
21
|
+
export function brokerCredentialRefusal(resource, env = process.env) {
|
|
22
|
+
const name = resource.broker?.tokenEnv;
|
|
23
|
+
if (typeof name !== 'string' || !ENV_NAME.test(name))
|
|
24
|
+
return undefined;
|
|
25
|
+
const reserved = reservedCredentialEnv(name) ?? (holdsHostRouterGrant(hostEnvironmentValue(name, env), env) ? 'host_router_grant' : undefined);
|
|
26
|
+
if (!reserved)
|
|
27
|
+
return undefined;
|
|
28
|
+
return `Remote resource "${resource.id}" can't use ${name} for its broker's credential: it holds ${RESERVED_CREDENTIALS[reserved]}. `
|
|
29
|
+
+ 'Give the broker a credential of its own.';
|
|
30
|
+
}
|
|
5
31
|
/** Resolve the host endpoint and credential before reserving a mutation. */
|
|
6
32
|
export function makeRemoteBrokerTransport(resource) {
|
|
7
33
|
const broker = resource.broker;
|
|
@@ -16,9 +42,13 @@ export function makeRemoteBrokerTransport(resource) {
|
|
|
16
42
|
|| (url.protocol !== 'https:' && !(url.protocol === 'http:' && broker.allowInsecureLoopback === true && loopback && isIP(url.hostname.replace(/^\[|\]$/g, ''))))) {
|
|
17
43
|
throw new Error('Remote broker requires HTTPS at /v1/resources; only explicitly enabled numeric loopback HTTP is permitted');
|
|
18
44
|
}
|
|
19
|
-
if (typeof broker.tokenEnv !== 'string' ||
|
|
45
|
+
if (typeof broker.tokenEnv !== 'string' || !ENV_NAME.test(broker.tokenEnv))
|
|
20
46
|
throw new Error('Invalid host broker credential environment variable');
|
|
21
|
-
const
|
|
47
|
+
const refusal = brokerCredentialRefusal(resource);
|
|
48
|
+
if (refusal)
|
|
49
|
+
throw new RemoteResourceConfigurationError(refusal);
|
|
50
|
+
// ZTC_BROKER_TOKEN, ZTC's own, is held by the host-credential store; any other variable is read where it is.
|
|
51
|
+
const token = hostEnvironmentValue(broker.tokenEnv);
|
|
22
52
|
if (!token || !/^[!-~]{32,4096}$/.test(token))
|
|
23
53
|
throw new Error('Host broker credential must contain 32 to 4096 ASCII non-whitespace characters');
|
|
24
54
|
const endpoint = url.href;
|
|
@@ -3,3 +3,10 @@ export declare class RemoteResourceRejectedError extends Error {
|
|
|
3
3
|
readonly operationId: string;
|
|
4
4
|
constructor(message: string, operationId: string);
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* A host's remote resource configuration ZTC refuses before connecting, in words that name what to change and never a
|
|
8
|
+
* credential: a broker that would be sent a credential ZTC keeps for somewhere else.
|
|
9
|
+
*/
|
|
10
|
+
export declare class RemoteResourceConfigurationError extends Error {
|
|
11
|
+
constructor(message: string);
|
|
12
|
+
}
|
|
@@ -7,3 +7,13 @@ export class RemoteResourceRejectedError extends Error {
|
|
|
7
7
|
this.name = 'RemoteResourceRejectedError';
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* A host's remote resource configuration ZTC refuses before connecting, in words that name what to change and never a
|
|
12
|
+
* credential: a broker that would be sent a credential ZTC keeps for somewhere else.
|
|
13
|
+
*/
|
|
14
|
+
export class RemoteResourceConfigurationError extends Error {
|
|
15
|
+
constructor(message) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = 'RemoteResourceConfigurationError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Tool } from '../tools/types.js';
|
|
2
2
|
import { type RemoteBrokerConfiguration } from './remote_broker_transport.js';
|
|
3
|
-
export { RemoteResourceRejectedError } from './remote_resource_errors.js';
|
|
3
|
+
export { RemoteResourceConfigurationError, RemoteResourceRejectedError } from './remote_resource_errors.js';
|
|
4
4
|
export interface RemoteResource {
|
|
5
5
|
id: string;
|
|
6
6
|
host: string;
|
|
@@ -3,10 +3,10 @@ import { randomUUID } from 'node:crypto';
|
|
|
3
3
|
import { posix } from 'node:path';
|
|
4
4
|
import { ToolCapability } from './capabilities.js';
|
|
5
5
|
import { remoteResourceEndpoint } from './remote_resource_endpoint.js';
|
|
6
|
-
import { makeRemoteBrokerTransport } from './remote_broker_transport.js';
|
|
7
|
-
import { RemoteResourceRejectedError } from './remote_resource_errors.js';
|
|
6
|
+
import { brokerCredentialRefusal, makeRemoteBrokerTransport } from './remote_broker_transport.js';
|
|
7
|
+
import { RemoteResourceConfigurationError, RemoteResourceRejectedError } from './remote_resource_errors.js';
|
|
8
8
|
import { reserveUserSubprocessCredentials } from '../../utils/subprocess_env.js';
|
|
9
|
-
export { RemoteResourceRejectedError } from './remote_resource_errors.js';
|
|
9
|
+
export { RemoteResourceConfigurationError, RemoteResourceRejectedError } from './remote_resource_errors.js';
|
|
10
10
|
import { admitRemoteMutation, findRemoteMutation, pendingRemoteMutations, remoteMutationJournalDirectory, resolveRemoteMutation } from './remote_mutation_journal.js';
|
|
11
11
|
const identities = new Map();
|
|
12
12
|
const sessions = new Map();
|
|
@@ -51,6 +51,10 @@ function validateResource(resource) {
|
|
|
51
51
|
|| (resource.port !== undefined && (!Number.isSafeInteger(resource.port) || resource.port < 1 || resource.port > 65535))) {
|
|
52
52
|
throw new Error('Invalid host-managed remote resource configuration');
|
|
53
53
|
}
|
|
54
|
+
// A broker is sent its credential: never one ZTC keeps for somewhere else, the host's Router runtime grant among them.
|
|
55
|
+
const refusal = brokerCredentialRefusal(resource);
|
|
56
|
+
if (refusal)
|
|
57
|
+
throw new RemoteResourceConfigurationError(refusal);
|
|
54
58
|
}
|
|
55
59
|
/** Legacy entry point retained to refuse unsafe callers explicitly. */
|
|
56
60
|
export const sshRemoteResourceTransport = async () => {
|
|
@@ -4,7 +4,9 @@ import { constants } from 'node:fs';
|
|
|
4
4
|
import { lstat, open, realpath } from 'node:fs/promises';
|
|
5
5
|
import { dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
6
6
|
import { promisify } from 'node:util';
|
|
7
|
-
import {
|
|
7
|
+
import { GIT_PROBE_OPTIONS } from '../../utils/git_probe_options.js';
|
|
8
|
+
import { GIT_NO_REPOSITORY_PROGRAM_OPTIONS, gitProbesStartNoRepositoryProgram } from '../../utils/git_repository_programs.js';
|
|
9
|
+
import { buildGitSubprocessEnv } from '../../utils/subprocess_env.js';
|
|
8
10
|
import { canonicalSourceContent, canonicalSourceIdentity, parseCommandVerificationReceipt, parseSourceSnapshot, SOURCE_SNAPSHOT_MAX_BYTES } from './source_verification_contract.js';
|
|
9
11
|
export const SOURCE_FILE_MAX_BYTES = 2 * 1024 * 1024;
|
|
10
12
|
export const SOURCE_CAPTURE_MAX_BYTES = 8 * 1024 * 1024;
|
|
@@ -40,22 +42,23 @@ async function assertScopedLocation(root, path) {
|
|
|
40
42
|
async function gitIdentity(cwd) {
|
|
41
43
|
// Read-only Git probes are bounded process-boundary observations, never shell text.
|
|
42
44
|
try {
|
|
43
|
-
// Repo config can make `git status` run filters: use the tool-child env.
|
|
44
|
-
const env = { ...
|
|
45
|
-
for (const key of ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE', 'GIT_OBJECT_DIRECTORY', 'GIT_ALTERNATE_OBJECT_DIRECTORIES'])
|
|
46
|
-
delete env[key];
|
|
45
|
+
// Repo config can make `git status` run filters: use the tool-child env, with no repository of ZTC's own environment.
|
|
46
|
+
const env = { ...buildGitSubprocessEnv(), GIT_OPTIONAL_LOCKS: '0' };
|
|
47
47
|
const options = { cwd, timeout: 2000, maxBuffer: 256 * 1024, encoding: 'utf8',
|
|
48
48
|
env };
|
|
49
|
-
// core.fsmonitor=false stops a repository fsmonitor command on
|
|
50
|
-
// git from discovering a planted directory as an implicit bare
|
|
51
|
-
// repo's HEAD and status are not adopted as this work tree's.
|
|
52
|
-
const probe =
|
|
49
|
+
// Under every profile (utils/git_probe_options.ts): core.fsmonitor=false stops a repository fsmonitor command on
|
|
50
|
+
// the status; safe.bareRepository=explicit stops git from discovering a planted directory as an implicit bare
|
|
51
|
+
// repository and reading its config, so a planted repo's HEAD and status are not adopted as this work tree's.
|
|
52
|
+
const probe = GIT_PROBE_OPTIONS;
|
|
53
|
+
// Where the agent may have written the repository's config, its programs never run here, and a status would run its
|
|
54
|
+
// clean filter on a changed file: the commit alone, and dirty unknown (utils/git_repository_programs.ts).
|
|
55
|
+
const barred = gitProbesStartNoRepositoryProgram();
|
|
53
56
|
const [head, status] = await Promise.all([
|
|
54
|
-
exec('git', [...probe, 'rev-parse', '--verify', 'HEAD'], options),
|
|
55
|
-
exec('git', [...probe, 'status', '--porcelain=v1', '--untracked-files=normal'], options),
|
|
57
|
+
exec('git', [...(barred ? GIT_NO_REPOSITORY_PROGRAM_OPTIONS : probe), 'rev-parse', '--verify', 'HEAD'], options),
|
|
58
|
+
barred ? Promise.resolve(null) : exec('git', [...probe, 'status', '--porcelain=v1', '--untracked-files=normal'], options),
|
|
56
59
|
]);
|
|
57
60
|
const commit = head.stdout.trim();
|
|
58
|
-
return { commit: /^[a-f0-9]{40}(?:[a-f0-9]{24})?$/.test(commit) ? commit : null, dirty: status.stdout.length > 0 };
|
|
61
|
+
return { commit: /^[a-f0-9]{40}(?:[a-f0-9]{24})?$/.test(commit) ? commit : null, dirty: status === null ? null : status.stdout.length > 0 };
|
|
59
62
|
}
|
|
60
63
|
catch {
|
|
61
64
|
return { commit: null, dirty: null };
|