@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
|
@@ -17,6 +17,7 @@ import { fileURLToPath } from 'url';
|
|
|
17
17
|
import { ToolCapability } from '../runtime/capabilities.js';
|
|
18
18
|
import { loadDesktopRuntime } from '../../desktop/runtime.js';
|
|
19
19
|
import { buildComputerRoutineLaunch } from '../../desktop/worker_launch.js';
|
|
20
|
+
import { buildUserSubprocessEnv } from '../../utils/subprocess_env.js';
|
|
20
21
|
const __filename = fileURLToPath(import.meta.url);
|
|
21
22
|
const __dirname = dirname(__filename);
|
|
22
23
|
// --- Constants ---
|
|
@@ -54,6 +55,9 @@ function runRoutineSubprocess(payload) {
|
|
|
54
55
|
const child = spawn(launch.command, launch.args, {
|
|
55
56
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
56
57
|
timeout: timeout + 15000, // Hard kill buffer beyond routine timeout
|
|
58
|
+
// The runner runs the routine's code, which the agent writes: a user subprocess's environment, the person's own
|
|
59
|
+
// and none of ZTC's credentials. (The desktop worker takes its own runtime lease and manifest.)
|
|
60
|
+
env: buildUserSubprocessEnv(),
|
|
57
61
|
});
|
|
58
62
|
let stdout = '';
|
|
59
63
|
let stderr = '';
|
|
@@ -130,8 +134,20 @@ function formatRunnerResult(result) {
|
|
|
130
134
|
return text;
|
|
131
135
|
}
|
|
132
136
|
// --- Tools ---
|
|
137
|
+
/**
|
|
138
|
+
* What each routine tool declares: computer control, and a program started outside the OS sandbox. The runner runs the
|
|
139
|
+
* agent's JavaScript in a child process ZTC starts outside any sandbox, and its host functions reach all of Node (a
|
|
140
|
+
* routine's `sleep.constructor('return process')()`); a saved routine is that code kept to run later, and list and delete
|
|
141
|
+
* tend what runs. So a profile that runs the agent's commands only inside an OS sandbox neither offers nor admits them,
|
|
142
|
+
* whatever it says of computer_control (startsProgramsOutsideSandbox), and one that asks before each command asks, as for
|
|
143
|
+
* the LSP tools and run_and_capture: declaring computer_control alone let a routine write outside a workspace_autonomous
|
|
144
|
+
* session's workspace while its run_command was held there (the reviewer's sweep probe, 2026-11-23).
|
|
145
|
+
*/
|
|
146
|
+
function routineCapabilities() {
|
|
147
|
+
return [ToolCapability.COMPUTER_CONTROL, ToolCapability.SHELL_EXEC];
|
|
148
|
+
}
|
|
133
149
|
export const computerRunRoutineTool = {
|
|
134
|
-
capabilities:
|
|
150
|
+
capabilities: routineCapabilities(),
|
|
135
151
|
definition: {
|
|
136
152
|
name: 'computer_run_routine',
|
|
137
153
|
description: `Execute JavaScript code at native speed in a sandboxed subprocess with a dedicated ztc-computer instance.
|
|
@@ -229,7 +245,7 @@ Pass either 'code' for inline JS or 'name' to run a saved routine.`,
|
|
|
229
245
|
},
|
|
230
246
|
};
|
|
231
247
|
export const computerSaveRoutineTool = {
|
|
232
|
-
capabilities:
|
|
248
|
+
capabilities: routineCapabilities(),
|
|
233
249
|
definition: {
|
|
234
250
|
name: 'computer_save_routine',
|
|
235
251
|
description: 'Save a verified routine for reuse. Only save routines after confirming they work correctly via computer_run_routine. Routines are stored in ~/.ztc/computer_use/routines/.',
|
|
@@ -299,7 +315,7 @@ export const computerSaveRoutineTool = {
|
|
|
299
315
|
},
|
|
300
316
|
};
|
|
301
317
|
export const computerListRoutinesTool = {
|
|
302
|
-
capabilities:
|
|
318
|
+
capabilities: routineCapabilities(),
|
|
303
319
|
definition: {
|
|
304
320
|
name: 'computer_list_routines',
|
|
305
321
|
description: 'List all saved computer use routines with their descriptions and tags.',
|
|
@@ -340,7 +356,7 @@ export const computerListRoutinesTool = {
|
|
|
340
356
|
},
|
|
341
357
|
};
|
|
342
358
|
export const computerDeleteRoutineTool = {
|
|
343
|
-
capabilities:
|
|
359
|
+
capabilities: routineCapabilities(),
|
|
344
360
|
definition: {
|
|
345
361
|
name: 'computer_delete_routine',
|
|
346
362
|
description: 'Delete a saved routine by name.',
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { Tool } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Whether this machine has a screen these tools reach. On Linux that takes a desktop session: an X display (DISPLAY) or
|
|
4
|
+
* a Wayland one (WAYLAND_DISPLAY). A Linux server, ZergCloud's resident among them, has neither, and every helper there
|
|
5
|
+
* can only fail, so the agent is not offered the tools (agent/factory.ts). macOS and Windows always have their screen.
|
|
6
|
+
*/
|
|
7
|
+
export declare function screenCaptureAvailable(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): boolean;
|
|
2
8
|
export interface ScreenshotResult {
|
|
3
9
|
type: 'image';
|
|
4
10
|
mediaType: string;
|
|
@@ -20,3 +26,5 @@ export interface WindowInfo {
|
|
|
20
26
|
export declare const screenshotTool: Tool;
|
|
21
27
|
export declare const listWindowsTool: Tool;
|
|
22
28
|
export declare const runAndMonitorTool: Tool;
|
|
29
|
+
/** The tools that need a screen: a machine without one (screenCaptureAvailable) is not offered them. */
|
|
30
|
+
export declare const SCREEN_TOOLS: readonly Tool[];
|
|
@@ -6,6 +6,24 @@ import { join } from 'path';
|
|
|
6
6
|
import { ToolCapability } from '../runtime/capabilities.js';
|
|
7
7
|
import { buildUserSubprocessEnv } from '../../utils/subprocess_env.js';
|
|
8
8
|
const execAsync = promisify(exec);
|
|
9
|
+
/**
|
|
10
|
+
* Run one of these tools' helpers (swift, osascript, screencapture and sips on macOS; wmctrl, xdotool, import,
|
|
11
|
+
* xwd | convert, gnome-screenshot and scrot on Linux; PowerShell on Windows). The shell finds each on PATH, where
|
|
12
|
+
* anything that can write a folder on PATH can put a program of its own under that name, so a helper gets what any user
|
|
13
|
+
* subprocess gets (buildUserSubprocessEnv): the person's own environment, their desktop session (DISPLAY, XAUTHORITY,
|
|
14
|
+
* WAYLAND_DISPLAY) among it, and none of ZTC's credentials or a copy of one.
|
|
15
|
+
*/
|
|
16
|
+
function runHelper(command, timeout) {
|
|
17
|
+
return execAsync(command, { timeout, env: buildUserSubprocessEnv() });
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Whether this machine has a screen these tools reach. On Linux that takes a desktop session: an X display (DISPLAY) or
|
|
21
|
+
* a Wayland one (WAYLAND_DISPLAY). A Linux server, ZergCloud's resident among them, has neither, and every helper there
|
|
22
|
+
* can only fail, so the agent is not offered the tools (agent/factory.ts). macOS and Windows always have their screen.
|
|
23
|
+
*/
|
|
24
|
+
export function screenCaptureAvailable(env = process.env, platform = process.platform) {
|
|
25
|
+
return platform !== 'linux' || Boolean(env.DISPLAY?.trim() || env.WAYLAND_DISPLAY?.trim());
|
|
26
|
+
}
|
|
9
27
|
// --- Helper Functions ---
|
|
10
28
|
async function getWindowListMac() {
|
|
11
29
|
// Use Swift to get window list via CGWindowListCopyWindowInfo
|
|
@@ -55,9 +73,7 @@ if let windowList = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .excludeDes
|
|
|
55
73
|
const scriptPath = join(tmpdir(), `ztc-windowlist-${Date.now()}.swift`);
|
|
56
74
|
await writeFile(scriptPath, swiftScript);
|
|
57
75
|
try {
|
|
58
|
-
const { stdout } = await
|
|
59
|
-
timeout: 15000
|
|
60
|
-
});
|
|
76
|
+
const { stdout } = await runHelper(`swift "${scriptPath}"`, 15000);
|
|
61
77
|
await unlinkFile(scriptPath).catch(() => { });
|
|
62
78
|
const parsed = JSON.parse(stdout.trim());
|
|
63
79
|
if (Array.isArray(parsed) && parsed.length > 0) {
|
|
@@ -95,9 +111,7 @@ async function getWindowListMacFallback() {
|
|
|
95
111
|
end tell
|
|
96
112
|
`;
|
|
97
113
|
try {
|
|
98
|
-
const { stdout } = await
|
|
99
|
-
timeout: 10000
|
|
100
|
-
});
|
|
114
|
+
const { stdout } = await runHelper(`osascript -e '${script.replace(/'/g, "'\"'\"'")}'`, 10000);
|
|
101
115
|
const lines = stdout.trim().split(', ');
|
|
102
116
|
return lines.map((line, idx) => {
|
|
103
117
|
const [appName, pid, title] = line.split('|||');
|
|
@@ -116,7 +130,7 @@ async function getWindowListMacFallback() {
|
|
|
116
130
|
async function getWindowListLinux() {
|
|
117
131
|
try {
|
|
118
132
|
// Try wmctrl first
|
|
119
|
-
const { stdout } = await
|
|
133
|
+
const { stdout } = await runHelper('wmctrl -l -p', 5000);
|
|
120
134
|
const lines = stdout.trim().split('\n');
|
|
121
135
|
return lines.map(line => {
|
|
122
136
|
const parts = line.split(/\s+/);
|
|
@@ -134,13 +148,13 @@ async function getWindowListLinux() {
|
|
|
134
148
|
catch {
|
|
135
149
|
// Try xdotool as fallback
|
|
136
150
|
try {
|
|
137
|
-
const { stdout } = await
|
|
151
|
+
const { stdout } = await runHelper('xdotool search --onlyvisible --name ""', 5000);
|
|
138
152
|
const windowIds = stdout.trim().split('\n').filter(Boolean);
|
|
139
153
|
const windows = [];
|
|
140
154
|
for (const id of windowIds.slice(0, 20)) { // Limit to 20 windows
|
|
141
155
|
try {
|
|
142
|
-
const { stdout: name } = await
|
|
143
|
-
const { stdout: pid } = await
|
|
156
|
+
const { stdout: name } = await runHelper(`xdotool getwindowname ${id}`, 1000);
|
|
157
|
+
const { stdout: pid } = await runHelper(`xdotool getwindowpid ${id}`, 1000);
|
|
144
158
|
windows.push({
|
|
145
159
|
windowId: parseInt(id),
|
|
146
160
|
pid: parseInt(pid.trim()) || 0,
|
|
@@ -208,9 +222,7 @@ async function getWindowListWindows() {
|
|
|
208
222
|
[WindowHelper]::GetWindows() | ForEach-Object { $_ }
|
|
209
223
|
`;
|
|
210
224
|
try {
|
|
211
|
-
const { stdout } = await
|
|
212
|
-
timeout: 15000
|
|
213
|
-
});
|
|
225
|
+
const { stdout } = await runHelper(`powershell -Command "${psScript.replace(/"/g, '\\"').replace(/\n/g, ' ')}"`, 15000);
|
|
214
226
|
return stdout.trim().split('\n').filter(Boolean).map(line => {
|
|
215
227
|
const [windowId, pid, appName, title] = line.split('|||');
|
|
216
228
|
return {
|
|
@@ -262,7 +274,7 @@ async function checkScreenRecordingPermission() {
|
|
|
262
274
|
try {
|
|
263
275
|
// Try to capture a tiny region - if it fails with permission error, we know
|
|
264
276
|
const testPath = join(tmpdir(), `ztc-perm-test-${Date.now()}.png`);
|
|
265
|
-
await
|
|
277
|
+
await runHelper(`screencapture -x -R0,0,1,1 "${testPath}"`, 5000);
|
|
266
278
|
await unlink(testPath).catch(() => { });
|
|
267
279
|
return true;
|
|
268
280
|
}
|
|
@@ -292,21 +304,21 @@ async function compressImageIfNeeded(imagePath) {
|
|
|
292
304
|
const maxDimension = Math.max(800, Math.floor(2000 * ratio)); // At least 800px, scale from 2000px base
|
|
293
305
|
try {
|
|
294
306
|
// Convert to JPEG and resize - sips uses pixel values, not percentages
|
|
295
|
-
await
|
|
307
|
+
await runHelper(`sips -s format jpeg -s formatOptions 70 -Z ${maxDimension} "${imagePath}" --out "${compressedPath}"`, 30000);
|
|
296
308
|
const compressedBuffer = await readFile(compressedPath);
|
|
297
309
|
await unlink(compressedPath).catch(() => { });
|
|
298
310
|
if (compressedBuffer.length <= MAX_IMAGE_SIZE) {
|
|
299
311
|
return compressedBuffer;
|
|
300
312
|
}
|
|
301
313
|
// If still too large, try more aggressive compression
|
|
302
|
-
await
|
|
314
|
+
await runHelper(`sips -s format jpeg -s formatOptions 50 -Z 1200 "${imagePath}" --out "${compressedPath}"`, 30000);
|
|
303
315
|
const moreCompressedBuffer = await readFile(compressedPath);
|
|
304
316
|
await unlink(compressedPath).catch(() => { });
|
|
305
317
|
if (moreCompressedBuffer.length <= MAX_IMAGE_SIZE) {
|
|
306
318
|
return moreCompressedBuffer;
|
|
307
319
|
}
|
|
308
320
|
// Last resort: very aggressive compression
|
|
309
|
-
await
|
|
321
|
+
await runHelper(`sips -s format jpeg -s formatOptions 40 -Z 800 "${imagePath}" --out "${compressedPath}"`, 30000);
|
|
310
322
|
const finalBuffer = await readFile(compressedPath);
|
|
311
323
|
await unlink(compressedPath).catch(() => { });
|
|
312
324
|
return finalBuffer;
|
|
@@ -322,7 +334,7 @@ async function compressImageIfNeeded(imagePath) {
|
|
|
322
334
|
const ratio = Math.sqrt(MAX_IMAGE_SIZE / imageBuffer.length) * 0.8;
|
|
323
335
|
const scalePercent = Math.max(20, Math.min(90, Math.floor(ratio * 100)));
|
|
324
336
|
try {
|
|
325
|
-
await
|
|
337
|
+
await runHelper(`convert "${imagePath}" -resize ${scalePercent}% -quality 70 "${compressedPath}"`, 30000);
|
|
326
338
|
const compressedBuffer = await readFile(compressedPath);
|
|
327
339
|
await unlink(compressedPath).catch(() => { });
|
|
328
340
|
return compressedBuffer;
|
|
@@ -339,7 +351,7 @@ async function captureWindow(windowId, tempPath) {
|
|
|
339
351
|
if (platform === 'darwin') {
|
|
340
352
|
// macOS: screencapture -l <windowID>
|
|
341
353
|
try {
|
|
342
|
-
await
|
|
354
|
+
await runHelper(`screencapture -x -l ${windowId} "${tempPath}"`, 30000);
|
|
343
355
|
}
|
|
344
356
|
catch (err) {
|
|
345
357
|
const message = err.message;
|
|
@@ -357,11 +369,11 @@ async function captureWindow(windowId, tempPath) {
|
|
|
357
369
|
else if (platform === 'linux') {
|
|
358
370
|
// Linux: try import with window ID
|
|
359
371
|
try {
|
|
360
|
-
await
|
|
372
|
+
await runHelper(`import -window ${windowId} "${tempPath}"`, 30000);
|
|
361
373
|
}
|
|
362
374
|
catch {
|
|
363
375
|
// Fallback to xwd + convert
|
|
364
|
-
await
|
|
376
|
+
await runHelper(`xwd -id ${windowId} | convert xwd:- "${tempPath}"`, 30000);
|
|
365
377
|
}
|
|
366
378
|
}
|
|
367
379
|
else if (platform === 'win32') {
|
|
@@ -399,7 +411,7 @@ async function captureWindow(windowId, tempPath) {
|
|
|
399
411
|
$graphics.Dispose()
|
|
400
412
|
$bitmap.Dispose()
|
|
401
413
|
`;
|
|
402
|
-
await
|
|
414
|
+
await runHelper(`powershell -Command "${psScript.replace(/"/g, '\\"').replace(/\n/g, '; ')}"`, 30000);
|
|
403
415
|
}
|
|
404
416
|
else {
|
|
405
417
|
throw new Error(`Window capture not supported on platform: ${platform}`);
|
|
@@ -416,7 +428,7 @@ async function captureFullScreen(tempPath, display, delay) {
|
|
|
416
428
|
cmd += ` -D${display}`;
|
|
417
429
|
}
|
|
418
430
|
cmd += ` "${tempPath}"`;
|
|
419
|
-
await
|
|
431
|
+
await runHelper(cmd, 30000 + (delay || 0) * 1000);
|
|
420
432
|
}
|
|
421
433
|
else if (platform === 'linux') {
|
|
422
434
|
if (delay && delay > 0) {
|
|
@@ -430,7 +442,7 @@ async function captureFullScreen(tempPath, display, delay) {
|
|
|
430
442
|
let success = false;
|
|
431
443
|
for (const cmd of commands) {
|
|
432
444
|
try {
|
|
433
|
-
await
|
|
445
|
+
await runHelper(cmd, 30000);
|
|
434
446
|
success = true;
|
|
435
447
|
break;
|
|
436
448
|
}
|
|
@@ -456,7 +468,7 @@ async function captureFullScreen(tempPath, display, delay) {
|
|
|
456
468
|
$graphics.Dispose()
|
|
457
469
|
$bitmap.Dispose()
|
|
458
470
|
`;
|
|
459
|
-
await
|
|
471
|
+
await runHelper(`powershell -Command "${psScript.replace(/\n/g, '; ')}"`, 30000);
|
|
460
472
|
}
|
|
461
473
|
else {
|
|
462
474
|
throw new Error(`Screenshot not supported on platform: ${platform}`);
|
|
@@ -744,3 +756,5 @@ export const runAndMonitorTool = {
|
|
|
744
756
|
}
|
|
745
757
|
}
|
|
746
758
|
};
|
|
759
|
+
/** The tools that need a screen: a machine without one (screenCaptureAvailable) is not offered them. */
|
|
760
|
+
export const SCREEN_TOOLS = Object.freeze([screenshotTool, listWindowsTool, runAndMonitorTool]);
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { spawn } from 'child_process';
|
|
2
2
|
import { basename, dirname, isAbsolute, relative, resolve } from 'path';
|
|
3
3
|
import { existsSync, statSync } from 'fs';
|
|
4
|
+
import { stat } from 'fs/promises';
|
|
4
5
|
import { ToolCapability } from '../runtime/capabilities.js';
|
|
5
|
-
import { buildUserSubprocessEnv } from '../../utils/subprocess_env.js';
|
|
6
|
+
import { buildUserSubprocessEnv, withoutRepositoryGitEnv } from '../../utils/subprocess_env.js';
|
|
6
7
|
import { containerPath, dockerTarget } from '../../utils/docker_target.js';
|
|
8
|
+
import { profileLimitsAgent } from '../../config/profile_limits.js';
|
|
9
|
+
import { ztcOwnStateHoldingForRead, ztcOwnStateLinkCheck } from '../../utils/ztc_own_state.js';
|
|
7
10
|
const SEARCH_TIMEOUT_MS = 30_000;
|
|
8
11
|
const MAX_OUTPUT_BYTES = 1_048_576;
|
|
9
12
|
/** ripgrep's --max-filesize 1M, kept by the in-process search. */
|
|
@@ -82,7 +85,9 @@ function runCommand(command, args, cwd, opts) {
|
|
|
82
85
|
const timeoutMs = opts?.timeoutMs ?? SEARCH_TIMEOUT_MS;
|
|
83
86
|
const maxBytes = opts?.maxBytes ?? MAX_OUTPUT_BYTES;
|
|
84
87
|
return new Promise((resolveResult, reject) => {
|
|
85
|
-
|
|
88
|
+
// git grep names its repository (-C): no repository variable of the environment overrides it.
|
|
89
|
+
const env = buildUserSubprocessEnv(opts?.env);
|
|
90
|
+
const child = spawn(command, args, { cwd, env: command === 'git' ? withoutRepositoryGitEnv(env) : env });
|
|
86
91
|
let stdout = '';
|
|
87
92
|
let stderr = '';
|
|
88
93
|
let outBytes = 0;
|
|
@@ -416,12 +421,33 @@ export const searchTool = {
|
|
|
416
421
|
error: `Search timed out after ${SEARCH_TIMEOUT_MS / 1000}s — try a narrower path or more specific pattern`,
|
|
417
422
|
});
|
|
418
423
|
}
|
|
424
|
+
// Under a profile that limits the agent, a search of a folder that holds ZTC's own state (a workspace with HOME or
|
|
425
|
+
// ZTC_CONFIG_DIR inside it) shows nothing of that state: the path policy refuses a search of it by name, and its
|
|
426
|
+
// lines are dropped here, as are those of a file that is one of ZTC's own under another name, a hard link
|
|
427
|
+
// (utils/ztc_own_state.ts). A matched file that can no longer be looked at is not shown either.
|
|
428
|
+
const limited = !docker && profileLimitsAgent(context?.commandPolicy?.profile, context?.commandPolicy?.sandbox);
|
|
429
|
+
const ownStateLink = ztcOwnStateLinkCheck();
|
|
430
|
+
const verdicts = new Map();
|
|
431
|
+
const shown = (path) => {
|
|
432
|
+
let verdict = verdicts.get(path);
|
|
433
|
+
if (verdict === undefined) {
|
|
434
|
+
const absolute = resolve(baseCwd, path);
|
|
435
|
+
verdict = ztcOwnStateHoldingForRead(absolute) !== null
|
|
436
|
+
? Promise.resolve(false)
|
|
437
|
+
: stat(absolute).then(async (file) => await ownStateLink(file) === null, () => false);
|
|
438
|
+
verdicts.set(path, verdict);
|
|
439
|
+
}
|
|
440
|
+
return verdict;
|
|
441
|
+
};
|
|
419
442
|
const stdout = result.stdout.trim();
|
|
420
443
|
if (!stdout) {
|
|
421
444
|
return JSON.stringify({ pattern, path: searchPath, matches: [], count: 0, truncated: false });
|
|
422
445
|
}
|
|
423
446
|
if (outputMode === 'files') {
|
|
424
|
-
const
|
|
447
|
+
const listed = stdout.split('\n').filter(l => l.trim() && !l.startsWith('['));
|
|
448
|
+
const allFiles = limited
|
|
449
|
+
? (await Promise.all(listed.map(async (l) => (await shown(l) ? [l] : [])))).flat()
|
|
450
|
+
: listed;
|
|
425
451
|
const files = allFiles.slice(0, maxResults);
|
|
426
452
|
return JSON.stringify({
|
|
427
453
|
pattern,
|
|
@@ -443,6 +469,8 @@ export const searchTool = {
|
|
|
443
469
|
const withoutColumn = withColumn ? null : line.match(/^(.+?):(\d+):(.*)$/);
|
|
444
470
|
if (!withColumn && !withoutColumn)
|
|
445
471
|
continue;
|
|
472
|
+
if (limited && !(await shown((withColumn ?? withoutColumn)[1])))
|
|
473
|
+
continue;
|
|
446
474
|
if (matches.length >= maxResults) {
|
|
447
475
|
outputTruncated = true;
|
|
448
476
|
break;
|
|
@@ -335,6 +335,8 @@ async function executeRunCommand(args, context, run) {
|
|
|
335
335
|
profile,
|
|
336
336
|
sandbox,
|
|
337
337
|
capabilities: [ToolCapability.SHELL_EXEC],
|
|
338
|
+
// The session's own repository is protected wherever in the workspace the command runs (utils/git_program_files.ts).
|
|
339
|
+
sessionCwd: context?.cwd || process.cwd(),
|
|
338
340
|
temporaryWriteRoot,
|
|
339
341
|
stdin,
|
|
340
342
|
env: context?.subprocessEnv,
|
|
@@ -480,6 +482,7 @@ async function executeRunCommand(args, context, run) {
|
|
|
480
482
|
return JSON.stringify({ command: result.command, cwd: result.cwd, stdout: result.stdout, stderr: result.stderr,
|
|
481
483
|
truncated: result.truncated, exit_code: result.exitCode,
|
|
482
484
|
...(result.sandboxAudit ? { sandbox_audit: result.sandboxAudit } : {}),
|
|
485
|
+
...(result.sandboxNotes ? { sandbox_notes: result.sandboxNotes } : {}),
|
|
483
486
|
...observation,
|
|
484
487
|
status: outcome === 'passed' ? 'completed' : outcome === 'timed_out' ? 'timed_out' : outcome === 'cancelled' ? 'cancelled' : 'failed',
|
|
485
488
|
...(result.checked ? { checked: result.checked } : {}), verification,
|
|
@@ -489,6 +492,7 @@ async function executeRunCommand(args, context, run) {
|
|
|
489
492
|
return JSON.stringify({ command: result.command, cwd: result.cwd, stdout: result.stdout,
|
|
490
493
|
stderr: result.stderr, truncated: result.truncated, exit_code: result.exitCode,
|
|
491
494
|
...(result.sandboxAudit ? { sandbox_audit: result.sandboxAudit } : {}),
|
|
495
|
+
...(result.sandboxNotes ? { sandbox_notes: result.sandboxNotes } : {}),
|
|
492
496
|
...observation,
|
|
493
497
|
status: result.checked.status === 'passed' ? 'completed' : result.checked.status === 'timed_out'
|
|
494
498
|
? 'timed_out' : result.checked.status === 'cancelled' ? 'cancelled' : 'failed', checked: result.checked });
|
|
@@ -508,7 +512,8 @@ async function executeRunCommand(args, context, run) {
|
|
|
508
512
|
// unknown completeness without guessing which compound stage failed.
|
|
509
513
|
const hint = shellErrorHint(result.exitCode, result.stderr ?? '', Boolean(result.stdout?.trim()), result.timedOut === true);
|
|
510
514
|
const stages = result.pipelineExitCodes ? `\npipe stages exited ${result.pipelineExitCodes.join(' ')}` : '';
|
|
511
|
-
|
|
515
|
+
const sandboxSaid = result.sandboxNotes ? `\nsandbox: ${result.sandboxNotes.join(' ')}` : '';
|
|
516
|
+
throw new Error(`Command failed (exit ${result.exitCode}):\n${outputSnippet}${stages}${sandboxSaid}${result.execution_policy ? `\nexecution: ${JSON.stringify(observation)}` : ''}${hint ? `\n\nhint: ${hint}` : ''}`);
|
|
512
517
|
}
|
|
513
518
|
const warning = pipelineWarning(result.pipelineExitCodes, result.earlierPipelineExitCodes);
|
|
514
519
|
// Named first: output cut in the middle reads as whole, and an agent parsed 62 KB of JSON cut that way (forge3d, 2026-11-06).
|
|
@@ -525,6 +530,7 @@ async function executeRunCommand(args, context, run) {
|
|
|
525
530
|
...(result.pipelineExitCodes ? { pipeline_exit_codes: result.pipelineExitCodes } : {}),
|
|
526
531
|
...(result.earlierPipelineExitCodes ? { earlier_pipeline_exit_codes: result.earlierPipelineExitCodes } : {}),
|
|
527
532
|
...(result.sandboxAudit ? { sandbox_audit: result.sandboxAudit } : {}),
|
|
533
|
+
...(result.sandboxNotes ? { sandbox_notes: result.sandboxNotes } : {}),
|
|
528
534
|
...observation
|
|
529
535
|
});
|
|
530
536
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { request } from 'http';
|
|
2
|
+
import { ToolCapability } from '../runtime/capabilities.js';
|
|
2
3
|
import { configStore } from '../../config.js';
|
|
3
4
|
import { ROUTE_AWAITS_A_CHOICE } from '../../config/retired_routes.js';
|
|
4
5
|
import { PANE_TASK_AS_MESSAGE_ENV } from '../../panes/initial_input.js';
|
|
@@ -131,6 +132,11 @@ async function createPaneAndWait(transport, command, expectedTitle, expectedPane
|
|
|
131
132
|
return event;
|
|
132
133
|
}
|
|
133
134
|
export const createSupervisedZtcPaneTool = {
|
|
135
|
+
// It starts a child ZTC that runs the agent's commands outside this pane's OS sandbox, on CLI arguments the agent gives
|
|
136
|
+
// it, as create_ztc_pane does: a profile that runs the agent's commands only inside an OS sandbox neither offers nor
|
|
137
|
+
// admits it, and one that asks before each command asks. Declaring nothing let a workspace_autonomous pane start a
|
|
138
|
+
// child under --permission-profile trusted (the reviewer's sweep probe, 2026-11-23).
|
|
139
|
+
capabilities: [ToolCapability.SHELL_EXEC],
|
|
134
140
|
definition: {
|
|
135
141
|
name: 'create_supervised_ztc_pane',
|
|
136
142
|
description: 'Create a child ZTC pane plus a live supervision feed pane. The feed captures the child pane\'s messages, tool activity, status changes, and bus traffic so the supervisor can monitor and intervene in real time.',
|
|
@@ -59,6 +59,10 @@ export interface ToolContext {
|
|
|
59
59
|
* of these paths is refused now. A tool that writes files calls it inside its path locks, just before its first
|
|
60
60
|
* write, so the check sees the filesystem that write will see. */
|
|
61
61
|
admitWrites?: (targets: readonly ToolWritePath[]) => void;
|
|
62
|
+
/** Runtime-owned read admission under the host's permission policy: throws, naming the path and the rule, when any of
|
|
63
|
+
* these paths (absolute) is refused now. A file tool that checks what it opened (utils/admitted_open.ts) calls it with
|
|
64
|
+
* the real path it is about to open. */
|
|
65
|
+
admitReads?: (paths: readonly string[]) => void;
|
|
62
66
|
}
|
|
63
67
|
/** One path a call will create, change, move or delete. */
|
|
64
68
|
export interface ToolWritePath {
|
|
@@ -88,6 +92,11 @@ export interface Tool {
|
|
|
88
92
|
* dispatch, and one refusal refuses the whole call. Throws when the
|
|
89
93
|
* arguments are malformed, as execution would. */
|
|
90
94
|
writePaths?: (args: Record<string, unknown>, context?: ToolContext) => Promise<readonly ToolWritePath[]>;
|
|
95
|
+
/** Every file this call reads that an argument the policy doesn't read as a path names (an LSP tool's `file`), as the
|
|
96
|
+
* tool will resolve it (absolute on this host). The runtime admits each as read_file's `path` before anyone is asked
|
|
97
|
+
* about the call, and the tool admits it again as it reads (ToolContext.admitReads). Throws when the arguments are
|
|
98
|
+
* malformed, as execution would. */
|
|
99
|
+
readPaths?: (args: Record<string, unknown>, context?: ToolContext) => readonly string[];
|
|
91
100
|
/** Explicit scheduling opt-in; only read effects may run concurrently. */
|
|
92
101
|
parallelSafe?: boolean;
|
|
93
102
|
/** Per-call opt-in for a tool whose effect depends on its arguments: true
|
|
@@ -100,6 +109,15 @@ export interface Tool {
|
|
|
100
109
|
* writes nothing admits a shell-capable tool only with this (see shellOutsideSandbox).
|
|
101
110
|
*/
|
|
102
111
|
sandboxedCommands?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* It starts no program the agent chose or wrote outside run_command's OS sandbox: what it runs goes through
|
|
114
|
+
* run_command (WebFetch's curl, the workers of delegate_task and spawn_background_agent), is a program of ZTC's own
|
|
115
|
+
* on the agent's input (Glob's rg, benchmark_cpu's registered recipe), or is a server the host configured (an MCP
|
|
116
|
+
* tool), and ztc_command's own slash commands declare what they start (Command.agentCapabilities). A profile whose
|
|
117
|
+
* commands run only inside an OS sandbox admits a shell-capable tool only with this or sandboxedCommands, unless it
|
|
118
|
+
* asks the person first (see startsProgramsOutsideSandbox). One that writes nothing still asks for sandboxedCommands.
|
|
119
|
+
*/
|
|
120
|
+
confinedCommands?: boolean;
|
|
103
121
|
/** Host scheduling boundary. When omitted, capabilities are mapped
|
|
104
122
|
* conservatively by `resolveToolEffect`. */
|
|
105
123
|
effect?: ToolEffectKind;
|
package/dist/agent/tools/zerg.js
CHANGED
|
@@ -32,6 +32,15 @@ async function zergApiRequest(endpoint, options = {}) {
|
|
|
32
32
|
}
|
|
33
33
|
return response.json();
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* What a zerg tool answers with no ZergAI platform login to send: why, when ZTC holds a login it sends to no platform
|
|
37
|
+
* API (a Zerg Router credential, the host's grant, or a ZTC_AUTH_TOKEN no platform API is named for); else that there is
|
|
38
|
+
* none. Nothing was sent either way.
|
|
39
|
+
*/
|
|
40
|
+
function notAuthenticated() {
|
|
41
|
+
const why = configStore.getPlatformLoginRefusal();
|
|
42
|
+
return JSON.stringify({ status: 'error', message: why ? `Not authenticated: ${why}` : 'Not authenticated. Use /auth login first.' });
|
|
43
|
+
}
|
|
35
44
|
/**
|
|
36
45
|
* Find a running Zerg agent to delegate to
|
|
37
46
|
*/
|
|
@@ -117,13 +126,8 @@ export const zergQueryTool = {
|
|
|
117
126
|
}
|
|
118
127
|
},
|
|
119
128
|
execute: async (args) => {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return JSON.stringify({
|
|
123
|
-
status: 'error',
|
|
124
|
-
message: 'Not authenticated. Use /auth login first.',
|
|
125
|
-
});
|
|
126
|
-
}
|
|
129
|
+
if (!configStore.isAuthenticated())
|
|
130
|
+
return notAuthenticated();
|
|
127
131
|
const query = String(args.query);
|
|
128
132
|
const context = args.context ? String(args.context) : undefined;
|
|
129
133
|
const preferredZergId = args.zerg_id ? Number(args.zerg_id) : undefined;
|
|
@@ -205,12 +209,8 @@ export const zergTaskStatusTool = {
|
|
|
205
209
|
}
|
|
206
210
|
},
|
|
207
211
|
execute: async (args) => {
|
|
208
|
-
if (!configStore.isAuthenticated())
|
|
209
|
-
return
|
|
210
|
-
status: 'error',
|
|
211
|
-
message: 'Not authenticated. Use /auth login first.',
|
|
212
|
-
});
|
|
213
|
-
}
|
|
212
|
+
if (!configStore.isAuthenticated())
|
|
213
|
+
return notAuthenticated();
|
|
214
214
|
const zergId = Number(args.zerg_id);
|
|
215
215
|
const taskId = String(args.task_id);
|
|
216
216
|
if (isNaN(zergId)) {
|
|
@@ -258,12 +258,8 @@ export const zergListTool = {
|
|
|
258
258
|
}
|
|
259
259
|
},
|
|
260
260
|
execute: async (args) => {
|
|
261
|
-
if (!configStore.isAuthenticated())
|
|
262
|
-
return
|
|
263
|
-
status: 'error',
|
|
264
|
-
message: 'Not authenticated. Use /auth login first.',
|
|
265
|
-
});
|
|
266
|
-
}
|
|
261
|
+
if (!configStore.isAuthenticated())
|
|
262
|
+
return notAuthenticated();
|
|
267
263
|
const statusFilter = args.status_filter ? String(args.status_filter).toUpperCase() : undefined;
|
|
268
264
|
try {
|
|
269
265
|
const response = await zergApiRequest('/api/ztc/zergs/');
|
|
@@ -25,9 +25,12 @@ export interface CommandCatalogEntry {
|
|
|
25
25
|
agentRunnable: boolean;
|
|
26
26
|
/**
|
|
27
27
|
* What running the command does that the agent's permission profile governs (Command.agentCapabilities): the tool
|
|
28
|
-
* runtime checks them as the ztc_command call's own (ztcCommandCapabilities).
|
|
28
|
+
* runtime checks them as the ztc_command call's own (ztcCommandCapabilities). A function of the command's arguments
|
|
29
|
+
* where only some of them start a program (/zerg launch).
|
|
29
30
|
*/
|
|
30
|
-
capabilities?: readonly ToolCapability[];
|
|
31
|
+
capabilities?: readonly ToolCapability[] | ((args: readonly string[]) => readonly ToolCapability[]);
|
|
32
|
+
/** What the command starts keeps the agent's commands in its OS sandbox, though it declares shell_exec (Command.agentConfined). */
|
|
33
|
+
confined?: boolean;
|
|
31
34
|
}
|
|
32
35
|
export interface CommandCatalogProvider {
|
|
33
36
|
getEntries: () => CommandCatalogEntry[];
|
|
@@ -44,10 +47,18 @@ export declare function setZtcCommandCatalog(provider: CommandCatalogProvider):
|
|
|
44
47
|
export declare function clearZtcCommandCatalog(): void;
|
|
45
48
|
/**
|
|
46
49
|
* What a ztc_command call's command does that the agent's permission profile governs, which the tool runtime checks as
|
|
47
|
-
* the call's own capabilities: /claude and /codex start a program that runs commands (shell_exec), so
|
|
48
|
-
* them, or asks before them, as it does a shell. None for a command
|
|
50
|
+
* the call's own capabilities: /claude and /codex start a program that runs commands (shell_exec), and so do /zerg
|
|
51
|
+
* launch and /debug headlines, so a profile refuses them, or asks before them, as it does a shell. None for a command
|
|
52
|
+
* the agent can't run, nor for arguments execute refuses.
|
|
49
53
|
*/
|
|
50
54
|
export declare function ztcCommandCapabilities(args: Record<string, unknown>): ToolCapability[];
|
|
55
|
+
/**
|
|
56
|
+
* Whether a ztc_command call starts no program of the agent's outside run_command's OS sandbox: its command declares
|
|
57
|
+
* no shell_exec, or what it starts holds the agent's commands where this pane's are (the ZTC pane /ztc opens). /claude
|
|
58
|
+
* and /codex open a CLI that runs commands of its own, outside that sandbox. A command the agent can't run starts
|
|
59
|
+
* nothing; execute refuses it.
|
|
60
|
+
*/
|
|
61
|
+
export declare function ztcCommandConfined(args: Record<string, unknown>): boolean;
|
|
51
62
|
/** Group entries by scope (global first, modes alphabetical) then by category. */
|
|
52
63
|
export declare function buildZtcCommandDescription(provider: CommandCatalogProvider): string;
|
|
53
64
|
export declare const ztcCommandTool: Tool;
|
|
@@ -33,6 +33,28 @@ function formatEntryLine(e) {
|
|
|
33
33
|
const desc = e.description?.trim() || '';
|
|
34
34
|
return desc ? `- ${usage} — ${desc}` : `- ${usage}`;
|
|
35
35
|
}
|
|
36
|
+
/** A ztc_command call's `args`: a JSON array of strings, or one string that is not JSON; else why it is neither. */
|
|
37
|
+
function commandArguments(raw) {
|
|
38
|
+
if (!raw)
|
|
39
|
+
return { args: [] };
|
|
40
|
+
if (typeof raw === 'string') {
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(raw);
|
|
43
|
+
if (!Array.isArray(parsed))
|
|
44
|
+
return { args: [raw] };
|
|
45
|
+
const validated = validateStringArgs(parsed);
|
|
46
|
+
return typeof validated === 'string' ? { error: validated } : { args: validated };
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return { args: [raw] };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (Array.isArray(raw)) {
|
|
53
|
+
const validated = validateStringArgs(raw);
|
|
54
|
+
return typeof validated === 'string' ? { error: validated } : { args: validated };
|
|
55
|
+
}
|
|
56
|
+
return { error: 'args must be a JSON array of strings, or a single non-JSON string argument.' };
|
|
57
|
+
}
|
|
36
58
|
function validateStringArgs(value) {
|
|
37
59
|
if (!Array.isArray(value)) {
|
|
38
60
|
return 'args must be a JSON array of strings, or a single non-JSON string argument.';
|
|
@@ -92,12 +114,28 @@ function catalogEntry(command) {
|
|
|
92
114
|
}
|
|
93
115
|
/**
|
|
94
116
|
* What a ztc_command call's command does that the agent's permission profile governs, which the tool runtime checks as
|
|
95
|
-
* the call's own capabilities: /claude and /codex start a program that runs commands (shell_exec), so
|
|
96
|
-
* them, or asks before them, as it does a shell. None for a command
|
|
117
|
+
* the call's own capabilities: /claude and /codex start a program that runs commands (shell_exec), and so do /zerg
|
|
118
|
+
* launch and /debug headlines, so a profile refuses them, or asks before them, as it does a shell. None for a command
|
|
119
|
+
* the agent can't run, nor for arguments execute refuses.
|
|
97
120
|
*/
|
|
98
121
|
export function ztcCommandCapabilities(args) {
|
|
99
122
|
const entry = typeof args.command === 'string' ? catalogEntry(args.command) : undefined;
|
|
100
|
-
|
|
123
|
+
if (!entry?.agentRunnable || !entry.capabilities)
|
|
124
|
+
return [];
|
|
125
|
+
if (typeof entry.capabilities !== 'function')
|
|
126
|
+
return [...entry.capabilities];
|
|
127
|
+
const parsed = commandArguments(args.args);
|
|
128
|
+
return 'error' in parsed ? [] : [...entry.capabilities(parsed.args)];
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Whether a ztc_command call starts no program of the agent's outside run_command's OS sandbox: its command declares
|
|
132
|
+
* no shell_exec, or what it starts holds the agent's commands where this pane's are (the ZTC pane /ztc opens). /claude
|
|
133
|
+
* and /codex open a CLI that runs commands of its own, outside that sandbox. A command the agent can't run starts
|
|
134
|
+
* nothing; execute refuses it.
|
|
135
|
+
*/
|
|
136
|
+
export function ztcCommandConfined(args) {
|
|
137
|
+
const entry = typeof args.command === 'string' ? catalogEntry(args.command) : undefined;
|
|
138
|
+
return entry?.confined === true || !ztcCommandCapabilities(args).includes(ToolCapability.SHELL_EXEC);
|
|
101
139
|
}
|
|
102
140
|
/** Group entries by scope (global first, modes alphabetical) then by category. */
|
|
103
141
|
export function buildZtcCommandDescription(provider) {
|
|
@@ -171,40 +209,16 @@ export const ztcCommandTool = {
|
|
|
171
209
|
// A slash command can change settings, open panes that run other agents and start Zergs, so a profile that
|
|
172
210
|
// forbids writing, commands or the network forbids this tool too.
|
|
173
211
|
capabilities: [ToolCapability.FILE_WRITE, ToolCapability.SHELL_EXEC, ToolCapability.NETWORK],
|
|
212
|
+
// It runs no program itself: a command that starts one declares shell_exec (Command.agentCapabilities), and the tool
|
|
213
|
+
// runtime judges that call by it (see Tool.confinedCommands).
|
|
214
|
+
confinedCommands: true,
|
|
174
215
|
definition: ztcCommandDefinition,
|
|
175
216
|
async execute(args, _context) {
|
|
176
217
|
const command = args.command;
|
|
177
|
-
|
|
178
|
-
if (
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const parsed = JSON.parse(args.args);
|
|
182
|
-
if (Array.isArray(parsed)) {
|
|
183
|
-
const validated = validateStringArgs(parsed);
|
|
184
|
-
if (typeof validated === 'string') {
|
|
185
|
-
return `Error: ${validated}`;
|
|
186
|
-
}
|
|
187
|
-
cmdArgs = validated;
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
cmdArgs = [args.args];
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
catch {
|
|
194
|
-
cmdArgs = [args.args];
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
else if (Array.isArray(args.args)) {
|
|
198
|
-
const validated = validateStringArgs(args.args);
|
|
199
|
-
if (typeof validated === 'string') {
|
|
200
|
-
return `Error: ${validated}`;
|
|
201
|
-
}
|
|
202
|
-
cmdArgs = validated;
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
return 'Error: args must be a JSON array of strings, or a single non-JSON string argument.';
|
|
206
|
-
}
|
|
207
|
-
}
|
|
218
|
+
const parsedArgs = commandArguments(args.args);
|
|
219
|
+
if ('error' in parsedArgs)
|
|
220
|
+
return `Error: ${parsedArgs.error}`;
|
|
221
|
+
const cmdArgs = parsedArgs.args;
|
|
208
222
|
const timeoutMs = parseTimeoutMs(args.timeout_seconds);
|
|
209
223
|
if (typeof timeoutMs === 'string') {
|
|
210
224
|
return `Error: ${timeoutMs}`;
|