@zergai/ztc 0.19.0-beta.1 → 0.20.0-beta.1
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 +222 -6
- package/bin/zmux-darwin-arm64 +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/zterm-darwin-arm64 +2 -2
- package/dist/agent/agent.d.ts +17 -0
- package/dist/agent/agent.js +77 -4
- package/dist/agent/backends/index.js +5 -3
- package/dist/agent/backends/zrouter_stream.js +8 -4
- package/dist/agent/commands/goal.d.ts +2 -0
- package/dist/agent/commands/goal.js +7 -2
- package/dist/agent/factory.d.ts +2 -0
- package/dist/agent/factory.js +1 -0
- package/dist/agent/request_encoder.d.ts +2 -1
- package/dist/agent/request_encoder.js +4 -3
- package/dist/agent/runtime/policy.d.ts +1 -0
- package/dist/agent/runtime/policy.js +23 -3
- package/dist/agent/runtime/tool_runtime.js +13 -12
- package/dist/agent/subagent.js +2 -1
- package/dist/agent/tools/ask_user.d.ts +1 -1
- package/dist/agent/tools/ask_user.js +15 -8
- package/dist/agent/tools/pane.d.ts +6 -0
- package/dist/agent/tools/pane.js +18 -4
- package/dist/agent/tools/search.js +1 -1
- package/dist/agent/tools/sim_domain_tools.d.ts +4 -0
- package/dist/agent/tools/sim_domain_tools.js +28 -2
- package/dist/agent/tools/types.d.ts +3 -0
- package/dist/app/correlated_turn.d.ts +14 -0
- package/dist/app/correlated_turn.js +78 -0
- package/dist/app/prompt_turn.d.ts +2 -1
- package/dist/app/prompt_turn.js +15 -2
- package/dist/app/session_manager.d.ts +17 -11
- package/dist/app/session_manager.js +74 -30
- package/dist/app/tool_callbacks.d.ts +1 -1
- package/dist/app/workspace_layout_controller.d.ts +21 -2
- package/dist/app/workspace_layout_controller.js +61 -10
- package/dist/app/workspace_monitor.js +67 -7
- package/dist/app/workspace_presets.d.ts +1 -0
- package/dist/app/workspace_presets.js +2 -2
- package/dist/cli.js +6 -2
- package/dist/cli_args.js +1 -0
- package/dist/cli_main.js +48 -2
- package/dist/cli_ratatui.d.ts +56 -8
- package/dist/cli_ratatui.js +689 -109
- package/dist/config/permissions.js +1 -1
- package/dist/config/router_required.d.ts +11 -0
- package/dist/config/router_required.js +23 -0
- package/dist/config/types.d.ts +5 -0
- package/dist/config.d.ts +3 -1
- package/dist/config.js +66 -49
- package/dist/desktop/daily/broker.d.ts +26 -0
- package/dist/desktop/daily/broker.js +140 -0
- package/dist/desktop/daily/codex_config.d.ts +2 -0
- package/dist/desktop/daily/codex_config.js +119 -0
- package/dist/desktop/daily/codex_exec_adapter.d.ts +42 -0
- package/dist/desktop/daily/codex_exec_adapter.js +251 -0
- package/dist/desktop/daily/control_client.d.ts +4 -0
- package/dist/desktop/daily/control_client.js +214 -0
- package/dist/desktop/daily/control_credentials.d.ts +15 -0
- package/dist/desktop/daily/control_credentials.js +85 -0
- package/dist/desktop/daily/control_hello.d.ts +10 -0
- package/dist/desktop/daily/control_hello.js +6 -0
- package/dist/desktop/daily/control_protocol.d.ts +39 -0
- package/dist/desktop/daily/control_protocol.js +4 -0
- package/dist/desktop/daily/control_schema.d.ts +9 -0
- package/dist/desktop/daily/control_schema.js +25 -0
- package/dist/desktop/daily/control_server.d.ts +44 -0
- package/dist/desktop/daily/control_server.js +286 -0
- package/dist/desktop/daily/daily_store.d.ts +71 -0
- package/dist/desktop/daily/daily_store.js +290 -0
- package/dist/desktop/daily/delegated_ztc_contract.d.ts +37 -0
- package/dist/desktop/daily/delegated_ztc_contract.js +90 -0
- package/dist/desktop/daily/desktop_wiring.d.ts +112 -0
- package/dist/desktop/daily/desktop_wiring.js +1048 -0
- package/dist/desktop/daily/enrollment.d.ts +74 -0
- package/dist/desktop/daily/enrollment.js +77 -0
- package/dist/desktop/daily/file_facts.d.ts +2 -0
- package/dist/desktop/daily/file_facts.js +41 -0
- package/dist/desktop/daily/lease.d.ts +57 -0
- package/dist/desktop/daily/lease.js +332 -0
- package/dist/desktop/daily/legacy_codex_homes.d.ts +1 -0
- package/dist/desktop/daily/legacy_codex_homes.js +26 -0
- package/dist/desktop/daily/native_pane_launcher.d.ts +31 -0
- package/dist/desktop/daily/native_pane_launcher.js +226 -0
- package/dist/desktop/daily/native_records.d.ts +13 -0
- package/dist/desktop/daily/native_records.js +81 -0
- package/dist/desktop/daily/native_status.d.ts +4 -0
- package/dist/desktop/daily/native_status.js +28 -0
- package/dist/desktop/daily/native_tool.d.ts +134 -0
- package/dist/desktop/daily/native_tool.js +91 -0
- package/dist/desktop/daily/owner_files.d.ts +3 -0
- package/dist/desktop/daily/owner_files.js +88 -0
- package/dist/desktop/daily/owner_seals.d.ts +9 -0
- package/dist/desktop/daily/owner_seals.js +56 -0
- package/dist/desktop/daily/process_identity.d.ts +13 -0
- package/dist/desktop/daily/process_identity.js +137 -0
- package/dist/desktop/daily/profile_bootstrap.d.ts +60 -0
- package/dist/desktop/daily/profile_bootstrap.js +194 -0
- package/dist/desktop/daily/raw_receipts.d.ts +1 -0
- package/dist/desktop/daily/raw_receipts.js +18 -0
- package/dist/desktop/daily/recipes.d.ts +36 -0
- package/dist/desktop/daily/recipes.js +177 -0
- package/dist/desktop/daily/router_state.d.ts +33 -0
- package/dist/desktop/daily/router_state.js +39 -0
- package/dist/desktop/daily/schema_registry.d.ts +19 -0
- package/dist/desktop/daily/schema_registry.js +71 -0
- package/dist/desktop/daily/source_baseline.d.ts +13 -0
- package/dist/desktop/daily/source_baseline.js +44 -0
- package/dist/desktop/daily/status_restore.d.ts +9 -0
- package/dist/desktop/daily/status_restore.js +114 -0
- package/dist/desktop/daily/summary.d.ts +59 -0
- package/dist/desktop/daily/summary.js +75 -0
- package/dist/desktop/daily/worker_provenance.d.ts +2 -0
- package/dist/desktop/daily/worker_provenance.js +18 -0
- package/dist/desktop/daily/worker_stop.d.ts +2 -0
- package/dist/desktop/daily/worker_stop.js +26 -0
- package/dist/desktop/daily/ztc_headless_adapter.d.ts +40 -0
- package/dist/desktop/daily/ztc_headless_adapter.js +194 -0
- package/dist/domain.d.ts +1 -1
- package/dist/domain.js +1 -1
- package/dist/events.d.ts +23 -1
- package/dist/headless.d.ts +9 -0
- package/dist/headless.js +161 -26
- package/dist/headless_approval.d.ts +29 -0
- package/dist/headless_approval.js +69 -0
- package/dist/headless_cli.js +2 -0
- package/dist/headless_cli_args.d.ts +4 -0
- package/dist/headless_cli_args.js +5 -0
- package/dist/library.d.ts +20 -0
- package/dist/library.js +66 -12
- package/dist/mcp/client.d.ts +16 -1
- package/dist/mcp/client.js +11 -5
- package/dist/mcp/registry.d.ts +3 -1
- package/dist/mcp/registry.js +10 -1
- package/dist/panes/pane_registry.js +14 -3
- package/dist/panes/types.d.ts +7 -1
- package/dist/panes/ztc_launch.d.ts +5 -0
- package/dist/panes/ztc_launch.js +30 -14
- package/dist/session.d.ts +6 -3
- package/dist/session.js +21 -2
- package/dist/simulation/domain_types.d.ts +2 -0
- package/dist/simulation/domains/loader.d.ts +7 -1
- package/dist/simulation/domains/loader.js +33 -1
- package/dist/simulation/living/context.d.ts +19 -19
- package/dist/simulation/living/definition.d.ts +2 -2
- package/dist/simulation/living/frame.d.ts +1 -1
- package/dist/simulation/living/open-world.d.ts +3 -3
- package/dist/simulation/living/types.d.ts +24 -24
- package/dist/simulation/toolkit/dynamic_state.d.ts +1 -1
- package/dist/skills/bundled/init-context/SKILL.md +16 -0
- package/dist/skills/registry.js +7 -3
- package/dist/tools.d.ts +6 -0
- package/dist/tools.js +14 -0
- package/dist/types.d.ts +30 -0
- package/dist/ui/ratatui/mux_persistence.d.ts +3 -1
- package/dist/ui/ratatui/mux_persistence.js +9 -2
- package/dist/ui/ratatui/pane_credential_broker.d.ts +8 -4
- package/dist/ui/ratatui/pane_credential_broker.js +26 -11
- package/dist/ui/ratatui/pane_relay.d.ts +2 -0
- package/dist/ui/ratatui/process.d.ts +6 -0
- package/dist/ui/ratatui/process.js +104 -6
- package/dist/ui/ratatui/protocol.d.ts +13 -0
- package/dist/ui/ratatui/protocol.js +1 -0
- package/dist/utils/compaction.js +6 -4
- package/dist/utils/subprocess_env.js +2 -0
- package/dist/web/browser_events.d.ts +10 -0
- package/dist/web/browser_events.js +9 -0
- package/dist/web/mirror_stream.d.ts +17 -5
- package/dist/web/mirror_stream.js +105 -13
- package/dist/web/pane_credentials.d.ts +6 -3
- package/dist/web/pane_credentials.js +20 -12
- package/dist/web/pane_registry.js +1 -0
- package/dist/workspace_agent.d.ts +2 -1
- package/dist/workspace_agent.js +7 -1
- package/dist/workspace_collision.d.ts +3 -0
- package/dist/workspace_collision.js +1 -1
- package/dist/workspace_layout.d.ts +3 -2
- package/dist/workspace_layout.js +8 -2
- package/dist/workspace_runtime.d.ts +7 -1
- package/dist/workspace_runtime.js +3 -3
- package/dist/zerg/manifest_builder_tools.js +35 -4
- package/dist/zerg/manifest_validator.js +55 -0
- package/dist/zlm-embed.mjs +261 -116
- package/node_modules/@zerg/model-contracts/README.md +19 -0
- package/node_modules/@zerg/model-contracts/index.js +19 -1
- package/node_modules/@ztc/sim-graph/dist/index.d.ts +1 -0
- package/node_modules/@ztc/sim-graph/dist/index.js +1 -0
- package/node_modules/@ztc/sim-graph/dist/sim_graph.d.ts +351 -0
- package/node_modules/@ztc/sim-graph/dist/sim_graph.js +795 -0
- package/node_modules/@ztc/sim-graph/package.json +37 -0
- package/node_modules/@ztc/sim-graph/src/index.ts +1 -0
- package/node_modules/@ztc/sim-graph/src/sim_graph.ts +1305 -0
- package/package.json +25 -24
- package/packages/model-contracts/README.md +19 -0
- package/packages/model-contracts/index.js +19 -1
package/dist/zlm-embed.mjs
CHANGED
|
@@ -445,9 +445,27 @@ var init_model_contracts = __esm({
|
|
|
445
445
|
["nemotron-3-ultra-nvfp4", { reasoningEfforts: [], maxOutputTokens: null, fallbackRouting: false }],
|
|
446
446
|
["inkling", { reasoningEfforts: [], maxOutputTokens: null, fallbackRouting: false }],
|
|
447
447
|
["kimi-k2p6", { reasoningEfforts: [], maxOutputTokens: null, fallbackRouting: false }]
|
|
448
|
+
])],
|
|
449
|
+
["deepinfra", /* @__PURE__ */ new Map([
|
|
450
|
+
// DeepInfra's shared DeepSeek V4.1 Flash (fp8), verified 2026-11-07 against
|
|
451
|
+
// https://api.deepinfra.com/v1/openai/models and chat/completions. DeepInfra
|
|
452
|
+
// also accepts minimal, medium and xhigh; these are DeepSeek's own levels.
|
|
453
|
+
["deepseek-ai/deepseek-v4.1-flash", { reasoningEfforts: ["none", "low", "high", "max"], contextWindow: 1048576, maxOutputTokens: { "min": 256, "max": 384e3 }, fallbackRouting: true }],
|
|
454
|
+
["deepseek-ai/deepseek-v4.1-flash-1017", { reasoningEfforts: ["none", "low", "high", "max"], contextWindow: 1048576, maxOutputTokens: { "min": 256, "max": 384e3 }, fallbackRouting: true }]
|
|
455
|
+
])],
|
|
456
|
+
["morph", /* @__PURE__ */ new Map([
|
|
457
|
+
// Morph's personal-subscription models, measured 2026-11-10 against
|
|
458
|
+
// https://api.morphllm.com/v1/chat/completions. Morph accepts none,
|
|
459
|
+
// minimal, low, medium, high, xhigh and max for every model; "none" turns
|
|
460
|
+
// thinking off. DeepSeek keeps its own levels (as on DeepInfra); Kimi K3.1
|
|
461
|
+
// thinks measurably deeper at each listed step. DeepSeek took a 945K-token
|
|
462
|
+
// prompt; Kimi K3.1 took 300K, declared conservatively at 256K.
|
|
463
|
+
["morph-dsv41flash-1017", { reasoningEfforts: ["none", "low", "high", "max"], contextWindow: 1048576, maxOutputTokens: { "min": 256, "max": 384e3 }, fallbackRouting: true }],
|
|
464
|
+
["morph-dsv41flash", { reasoningEfforts: ["none", "low", "high", "max"], contextWindow: 1048576, maxOutputTokens: { "min": 256, "max": 384e3 }, fallbackRouting: true }],
|
|
465
|
+
["morph-kimik31", { reasoningEfforts: ["none", "low", "medium", "high", "max"], contextWindow: 262144, maxOutputTokens: { "min": 256, "max": 64e3 }, fallbackRouting: true }]
|
|
448
466
|
])]
|
|
449
467
|
]);
|
|
450
|
-
CONTRACT_PROVIDERS = Object.freeze(["anthropic", "openai", "gemini", "deepseek", "fireworks", "openrouter", "kimi", "voyage", "cohere", "elevenlabs", "replicate", "fal", "zai", "modal", "codex", "self_hosted", "openai_compatible", "typesafe"]);
|
|
468
|
+
CONTRACT_PROVIDERS = Object.freeze(["anthropic", "openai", "gemini", "deepseek", "fireworks", "openrouter", "deepinfra", "morph", "kimi", "voyage", "cohere", "elevenlabs", "replicate", "fal", "zai", "modal", "codex", "self_hosted", "openai_compatible", "typesafe"]);
|
|
451
469
|
}
|
|
452
470
|
});
|
|
453
471
|
|
|
@@ -1756,6 +1774,9 @@ function retiredProviderMessage(provider, replacement) {
|
|
|
1756
1774
|
const instead = replacement ? ` ZTC keeps using ${replacement}.` : "";
|
|
1757
1775
|
return `${provider.trim()} is no longer a ZTC model provider: ${CLAUDE_SUBSCRIPTION_POLICY}.${instead} ${CLAUDE_SUBSCRIPTION_ALTERNATIVES}`;
|
|
1758
1776
|
}
|
|
1777
|
+
function retiredModelMessage(model) {
|
|
1778
|
+
return `${model.trim()} was a Claude Code model alias, and Claude Code is no longer a ZTC model provider: ${CLAUDE_SUBSCRIPTION_POLICY}. Pick a model with /model (for example ${anthropicModelFor(model)} with an Anthropic API key or Zerg Router). To use your Claude subscription, open Claude Code in a pane with /claude.`;
|
|
1779
|
+
}
|
|
1759
1780
|
function assertProviderNotRetired(provider, replacement) {
|
|
1760
1781
|
if (isRetiredProvider(provider)) throw new RetiredProviderError(provider, replacement);
|
|
1761
1782
|
}
|
|
@@ -6822,6 +6843,25 @@ var init_router_auth = __esm({
|
|
|
6822
6843
|
}
|
|
6823
6844
|
});
|
|
6824
6845
|
|
|
6846
|
+
// src/config/router_required.ts
|
|
6847
|
+
function requiredRouterModel() {
|
|
6848
|
+
const pinned = process.env.ZTC_ROUTER_REQUIRED_MODEL?.trim();
|
|
6849
|
+
if (!pinned) return { provider: "openai", model: "gpt-6.1-sol" };
|
|
6850
|
+
const slash = pinned.indexOf("/");
|
|
6851
|
+
if (slash <= 0 || slash === pinned.length - 1) throw new Error("ZTC_ROUTER_REQUIRED_MODEL must be provider/model");
|
|
6852
|
+
const provider = pinned.slice(0, slash);
|
|
6853
|
+
const model = pinned.slice(slash + 1);
|
|
6854
|
+
if (isRetiredProvider(provider)) throw new RetiredProviderError(provider);
|
|
6855
|
+
if (isRetiredModel(model)) throw new Error(retiredModelMessage(model));
|
|
6856
|
+
return { provider, model };
|
|
6857
|
+
}
|
|
6858
|
+
var init_router_required = __esm({
|
|
6859
|
+
"src/config/router_required.ts"() {
|
|
6860
|
+
"use strict";
|
|
6861
|
+
init_retired_routes();
|
|
6862
|
+
}
|
|
6863
|
+
});
|
|
6864
|
+
|
|
6825
6865
|
// src/types.ts
|
|
6826
6866
|
var AGENT_STATUS_LABELS;
|
|
6827
6867
|
var init_types3 = __esm({
|
|
@@ -9963,11 +10003,12 @@ var init_status_line_config = __esm({
|
|
|
9963
10003
|
|
|
9964
10004
|
// src/config.ts
|
|
9965
10005
|
import { dirname as dirname7, join as join12, resolve as resolve5 } from "path";
|
|
9966
|
-
import { stat, readFile as readFile2, readlink, writeFile as writeFile3, mkdir as mkdir3, rm, unlink as unlink4, rename as rename3, realpath } from "fs/promises";
|
|
10006
|
+
import { stat, readFile as readFile2, readlink, writeFile as writeFile3, mkdir as mkdir3, chmod as chmod2, rm, unlink as unlink4, rename as rename3, realpath, copyFile } from "fs/promises";
|
|
9967
10007
|
import { readFileSync as readFileSync6, statSync as statSync2 } from "fs";
|
|
9968
10008
|
import { homedir as homedir5 } from "os";
|
|
9969
10009
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
9970
10010
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "util";
|
|
10011
|
+
import { constants as fsConstants } from "node:fs";
|
|
9971
10012
|
function isLocalEndpoint(url2) {
|
|
9972
10013
|
try {
|
|
9973
10014
|
const parsed = new URL(url2);
|
|
@@ -10061,6 +10102,7 @@ function build_default_config() {
|
|
|
10061
10102
|
emulationId: void 0,
|
|
10062
10103
|
spinnerVerbs: DEFAULT_SPINNER_VERBS,
|
|
10063
10104
|
toolPermissions: { ...DEFAULT_TOOL_PERMISSIONS },
|
|
10105
|
+
desktopDelegatedSkillRoots: [],
|
|
10064
10106
|
permissionProfile: "trusted",
|
|
10065
10107
|
permissionProfiles: { ...DEFAULT_PERMISSION_PROFILES },
|
|
10066
10108
|
sandbox: { ...DEFAULT_SANDBOX },
|
|
@@ -10226,6 +10268,48 @@ function configFile() {
|
|
|
10226
10268
|
function maskApiKey(key) {
|
|
10227
10269
|
return key.length >= 12 ? `\u2022\u2022\u2022\u2022${key.slice(-4)}` : "\u2022\u2022\u2022\u2022";
|
|
10228
10270
|
}
|
|
10271
|
+
async function copyProfileFiles(source2, requestedName) {
|
|
10272
|
+
const name2 = validateProfileName(requestedName.trim());
|
|
10273
|
+
const from = validateProfileName(source2);
|
|
10274
|
+
if (name2 === "default" || builtinProfileEmulation(name2)) {
|
|
10275
|
+
throw new Error(`Cannot duplicate onto "${name2}": it is a built-in profile sharing the default settings. Pick another name.`);
|
|
10276
|
+
}
|
|
10277
|
+
if (name2 === from || (await listConfigProfiles()).includes(name2)) {
|
|
10278
|
+
throw new Error(`Config profile "${name2}" already exists. Pick another name.`);
|
|
10279
|
+
}
|
|
10280
|
+
const sourceDir = profileConfigDir(from);
|
|
10281
|
+
const emulation = builtinProfileEmulation(from);
|
|
10282
|
+
if (from !== "default" && !emulation && !(await stat(sourceDir)).isDirectory()) {
|
|
10283
|
+
throw new Error(`Config profile "${from}" does not exist.`);
|
|
10284
|
+
}
|
|
10285
|
+
let saved2 = {};
|
|
10286
|
+
try {
|
|
10287
|
+
const parsed = JSON.parse(await readFile2(join12(sourceDir, "config.json"), "utf8"));
|
|
10288
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
10289
|
+
throw new Error(`Invalid config profile "${from}": expected an object.`);
|
|
10290
|
+
}
|
|
10291
|
+
saved2 = parsed;
|
|
10292
|
+
} catch (error62) {
|
|
10293
|
+
if (error62.code !== "ENOENT") throw error62;
|
|
10294
|
+
}
|
|
10295
|
+
if (emulation) saved2.emulationId = emulation;
|
|
10296
|
+
const destination = profileConfigDir(name2);
|
|
10297
|
+
await mkdir3(dirname7(destination), { recursive: true, mode: 448 });
|
|
10298
|
+
await mkdir3(destination, { mode: 448 });
|
|
10299
|
+
try {
|
|
10300
|
+
await writeFile3(join12(destination, "config.json"), JSON.stringify(saved2, null, 2), { flag: "wx", mode: 384 });
|
|
10301
|
+
try {
|
|
10302
|
+
await copyFile(join12(sourceDir, "router-auth.json"), join12(destination, "router-auth.json"), fsConstants.COPYFILE_EXCL);
|
|
10303
|
+
await chmod2(join12(destination, "router-auth.json"), 384);
|
|
10304
|
+
} catch (error62) {
|
|
10305
|
+
if (error62.code !== "ENOENT") throw error62;
|
|
10306
|
+
}
|
|
10307
|
+
} catch (error62) {
|
|
10308
|
+
await rm(destination, { recursive: true, force: true });
|
|
10309
|
+
throw error62;
|
|
10310
|
+
}
|
|
10311
|
+
return name2;
|
|
10312
|
+
}
|
|
10229
10313
|
var API_ENDPOINTS, DEFAULT_TOOL_PERMISSIONS, DEFAULT_PERMISSION_PROFILES, DEFAULT_INTENTS, DEFAULT_SANDBOX, DEFAULT_CONTEXT_PROGRESS_BAR, DEFAULT_WORKFLOWS, SETTINGS_DEFAULTS_VERSION, PERSONAL_DEFAULT_PROVIDER, PERSONAL_DEFAULT_MODEL, PERSONAL_DEFAULT_PROXY_URL, ROUTE_CREDENTIAL_ENV, DEFAULT_TERMINAL_INTERACTION, ADOPTED_DEFAULT_KEYS, ROUTING_SETTING_KEYS, ENVIRONMENT_SETTING_KEYS, SUPERUSER_STATUS_TIMEOUT_MS, ConfigStore, configStore;
|
|
10230
10314
|
var init_config = __esm({
|
|
10231
10315
|
"src/config.ts"() {
|
|
@@ -10247,6 +10331,7 @@ var init_config = __esm({
|
|
|
10247
10331
|
init_agent_profiles();
|
|
10248
10332
|
init_router_auth();
|
|
10249
10333
|
init_provider_ids();
|
|
10334
|
+
init_router_required();
|
|
10250
10335
|
init_spinner_verbs();
|
|
10251
10336
|
init_tool_response_store();
|
|
10252
10337
|
init_message_display();
|
|
@@ -10674,8 +10759,8 @@ var init_config = __esm({
|
|
|
10674
10759
|
}
|
|
10675
10760
|
}
|
|
10676
10761
|
}
|
|
10677
|
-
async load(force = false) {
|
|
10678
|
-
if (this.loaded && !force) return this.config;
|
|
10762
|
+
async load(force = false, options = {}) {
|
|
10763
|
+
if (this.loaded && !force && !options.strictConfig) return this.config;
|
|
10679
10764
|
this.profileEmulation = builtinProfileEmulation(activeProfile());
|
|
10680
10765
|
this.routerCredentialsError = null;
|
|
10681
10766
|
try {
|
|
@@ -10696,6 +10781,7 @@ var init_config = __esm({
|
|
|
10696
10781
|
}
|
|
10697
10782
|
saved2 = parsed;
|
|
10698
10783
|
} catch {
|
|
10784
|
+
if (options.strictConfig) throw new Error("Required profile config.json is missing or invalid");
|
|
10699
10785
|
this.config = build_default_config();
|
|
10700
10786
|
this.legacyApiKeyFromEnvironment = true;
|
|
10701
10787
|
this.applyEnvOverrides();
|
|
@@ -10772,44 +10858,11 @@ var init_config = __esm({
|
|
|
10772
10858
|
*/
|
|
10773
10859
|
async duplicateProfile(requestedName, source2 = activeProfile(), activate = () => {
|
|
10774
10860
|
}) {
|
|
10775
|
-
const name2 =
|
|
10776
|
-
const from = validateProfileName(source2);
|
|
10777
|
-
if (name2 === "default" || builtinProfileEmulation(name2)) {
|
|
10778
|
-
throw new Error(`Cannot duplicate onto "${name2}": it is a built-in profile sharing the default settings. Pick another name.`);
|
|
10779
|
-
}
|
|
10780
|
-
if (name2 === from || (await listConfigProfiles()).includes(name2)) {
|
|
10781
|
-
throw new Error(`Config profile "${name2}" already exists. Pick another name.`);
|
|
10782
|
-
}
|
|
10783
|
-
const sourceDir = profileConfigDir(from);
|
|
10784
|
-
const emulation = builtinProfileEmulation(from);
|
|
10785
|
-
if (from !== "default" && !emulation && !(await stat(sourceDir)).isDirectory()) {
|
|
10786
|
-
throw new Error(`Config profile "${from}" does not exist.`);
|
|
10787
|
-
}
|
|
10788
|
-
let saved2 = {};
|
|
10861
|
+
const name2 = await copyProfileFiles(source2, requestedName);
|
|
10789
10862
|
try {
|
|
10790
|
-
const parsed = JSON.parse(await readFile2(join12(sourceDir, "config.json"), "utf8"));
|
|
10791
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
10792
|
-
throw new Error(`Invalid config profile "${from}": expected an object.`);
|
|
10793
|
-
}
|
|
10794
|
-
saved2 = parsed;
|
|
10795
|
-
} catch (error62) {
|
|
10796
|
-
if (error62.code !== "ENOENT") throw error62;
|
|
10797
|
-
}
|
|
10798
|
-
if (emulation) saved2.emulationId = emulation;
|
|
10799
|
-
const destination = profileConfigDir(name2);
|
|
10800
|
-
await mkdir3(dirname7(destination), { recursive: true, mode: 448 });
|
|
10801
|
-
await mkdir3(destination, { mode: 448 });
|
|
10802
|
-
try {
|
|
10803
|
-
await writeFile3(join12(destination, "config.json"), JSON.stringify(saved2, null, 2), { flag: "wx", mode: 384 });
|
|
10804
|
-
try {
|
|
10805
|
-
const auth = await readFile2(join12(sourceDir, "router-auth.json"));
|
|
10806
|
-
await writeFile3(join12(destination, "router-auth.json"), auth, { flag: "wx", mode: 384 });
|
|
10807
|
-
} catch (error62) {
|
|
10808
|
-
if (error62.code !== "ENOENT") throw error62;
|
|
10809
|
-
}
|
|
10810
10863
|
await this.switchProfile(name2, activate);
|
|
10811
10864
|
} catch (error62) {
|
|
10812
|
-
await rm(
|
|
10865
|
+
await rm(profileConfigDir(name2), { recursive: true, force: true });
|
|
10813
10866
|
throw error62;
|
|
10814
10867
|
}
|
|
10815
10868
|
return name2;
|
|
@@ -11727,7 +11780,7 @@ var init_config = __esm({
|
|
|
11727
11780
|
const structured = cfg.openaiCompatible || {};
|
|
11728
11781
|
const envBaseUrl = process.env.OPENAI_COMPAT_BASE_URL || process.env.OPENAI_COMPATIBLE_BASE_URL || (process.env.OLLAMA_HOST ? `${process.env.OLLAMA_HOST.replace(/\/+$/, "")}/v1` : void 0);
|
|
11729
11782
|
return {
|
|
11730
|
-
baseUrl: structured.baseUrl || cfg.openaiCompatibleBaseUrl || envBaseUrl,
|
|
11783
|
+
baseUrl: process.env.ZTC_OPENAI_COMPATIBLE_BASE_URL || structured.baseUrl || cfg.openaiCompatibleBaseUrl || envBaseUrl,
|
|
11731
11784
|
apiPath: structured.apiPath,
|
|
11732
11785
|
defaultModel: structured.defaultModel || process.env.OPENAI_COMPAT_MODEL,
|
|
11733
11786
|
apiKey: structured.apiKey,
|
|
@@ -11979,9 +12032,12 @@ var init_config = __esm({
|
|
|
11979
12032
|
resolveLLMBackendConfig(opts = {}) {
|
|
11980
12033
|
if (!opts.asChosen) this.assertRouteChosen(opts.provider || opts.config?.provider);
|
|
11981
12034
|
if (process.env.ZTC_ROUTER_REQUIRED === "1") {
|
|
11982
|
-
const
|
|
11983
|
-
const
|
|
11984
|
-
|
|
12035
|
+
const required2 = requiredRouterModel();
|
|
12036
|
+
const provider2 = normalizeProviderId(opts.provider ?? opts.config?.provider ?? required2.provider);
|
|
12037
|
+
const model2 = opts.model ?? opts.config?.model ?? required2.model;
|
|
12038
|
+
if (provider2 !== normalizeProviderId(required2.provider) || model2 !== required2.model) {
|
|
12039
|
+
throw new Error(`Required Router profile permits only ${required2.provider}/${required2.model}`);
|
|
12040
|
+
}
|
|
11985
12041
|
const proxyUrl2 = normalizedOrigin(process.env.ZERG_PROXY_URL);
|
|
11986
12042
|
const authToken2 = process.env.ZERG_AUTH_TOKEN?.trim();
|
|
11987
12043
|
if (!proxyUrl2 || !authToken2) throw new Error("Required Router origin and service credential are unavailable");
|
|
@@ -12945,6 +13001,7 @@ var init_zrouter_stream = __esm({
|
|
|
12945
13001
|
init_router_refusal();
|
|
12946
13002
|
init_router_gate();
|
|
12947
13003
|
init_router_requests();
|
|
13004
|
+
init_router_required();
|
|
12948
13005
|
ZROUTER_HEADERS_TIMEOUT_MS = 9e4;
|
|
12949
13006
|
routerClientSession = randomUUID4();
|
|
12950
13007
|
ROUTER_PIN_MAX_LENGTH = 128;
|
|
@@ -12969,7 +13026,7 @@ var init_zrouter_stream = __esm({
|
|
|
12969
13026
|
clientName;
|
|
12970
13027
|
openRouterPreferences;
|
|
12971
13028
|
constructor(config2) {
|
|
12972
|
-
this.preservesNativeHistory = config2.provider === "openai" &&
|
|
13029
|
+
this.preservesNativeHistory = config2.provider === "openai" && config2.model === "gpt-6.1-sol";
|
|
12973
13030
|
this.initialCatalog = config2.catalog ? structuredClone(config2.catalog) : void 0;
|
|
12974
13031
|
this.apiKey = config2.apiKey;
|
|
12975
13032
|
this.proxyUrl = config2.proxyUrl.replace(/\/+$/, "");
|
|
@@ -12996,8 +13053,11 @@ var init_zrouter_stream = __esm({
|
|
|
12996
13053
|
return !this.usesNativeResponses(request2);
|
|
12997
13054
|
}
|
|
12998
13055
|
usesNativeResponses(request2) {
|
|
12999
|
-
if (process.env.ZTC_ROUTER_REQUIRED === "1"
|
|
13000
|
-
|
|
13056
|
+
if (process.env.ZTC_ROUTER_REQUIRED === "1") {
|
|
13057
|
+
const required2 = requiredRouterModel();
|
|
13058
|
+
if (this.provider !== required2.provider || request2.model !== required2.model || request2.routePlan?.allow_fallbacks || request2.routePlan?.fallbacks.length) {
|
|
13059
|
+
throw new Error(`Required Router profile permits only ${required2.provider}/${required2.model} without fallbacks`);
|
|
13060
|
+
}
|
|
13001
13061
|
}
|
|
13002
13062
|
return this.provider === "openai" && request2.model === "gpt-6.1-sol";
|
|
13003
13063
|
}
|
|
@@ -13473,13 +13533,14 @@ function traced(provider, backend) {
|
|
|
13473
13533
|
}
|
|
13474
13534
|
function createBackendForProvider(provider, opts) {
|
|
13475
13535
|
if (process.env.ZTC_ROUTER_REQUIRED === "1") {
|
|
13476
|
-
|
|
13536
|
+
const required2 = requiredRouterModel();
|
|
13537
|
+
if (provider !== required2.provider) throw new Error(`Required Router profile permits only ${required2.provider}/${required2.model}`);
|
|
13477
13538
|
const proxyUrl = process.env.ZERG_PROXY_URL;
|
|
13478
13539
|
const apiKey = process.env.ZERG_AUTH_TOKEN?.trim();
|
|
13479
13540
|
if (!proxyUrl || !apiKey) throw new Error("Required Router origin and service credential are unavailable");
|
|
13480
13541
|
const origin = new URL(proxyUrl);
|
|
13481
13542
|
if (origin.protocol !== "https:" || origin.username || origin.password || origin.pathname !== "/" || origin.search || origin.hash) throw new Error("Required Router origin must be a credential-free HTTPS origin");
|
|
13482
|
-
return traced(provider, new ZRouterStreamBackend({ provider, model:
|
|
13543
|
+
return traced(provider, new ZRouterStreamBackend({ provider, model: required2.model, apiKey, proxyUrl: origin.origin }));
|
|
13483
13544
|
}
|
|
13484
13545
|
assertProviderNotRetired(provider);
|
|
13485
13546
|
const resolvedProvider = normalizeProviderId(provider);
|
|
@@ -13587,6 +13648,7 @@ var init_backends = __esm({
|
|
|
13587
13648
|
init_clarifai();
|
|
13588
13649
|
init_kimi_code_auth();
|
|
13589
13650
|
init_zrouter_stream();
|
|
13651
|
+
init_router_required();
|
|
13590
13652
|
init_provider_ids();
|
|
13591
13653
|
init_trace();
|
|
13592
13654
|
init_retired_routes();
|
|
@@ -14071,14 +14133,14 @@ var init_zlm_stdio = __esm({
|
|
|
14071
14133
|
});
|
|
14072
14134
|
|
|
14073
14135
|
// src/zlm.ts
|
|
14074
|
-
import { realpathSync as
|
|
14136
|
+
import { realpathSync as realpathSync7 } from "node:fs";
|
|
14075
14137
|
import { resolve as resolve21 } from "node:path";
|
|
14076
14138
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
14077
14139
|
|
|
14078
14140
|
// src/agent/agent.ts
|
|
14079
14141
|
import { createHash as createHash21, randomUUID as randomUUID13 } from "node:crypto";
|
|
14080
14142
|
import { isDeepStrictEqual as isDeepStrictEqual4 } from "node:util";
|
|
14081
|
-
import { existsSync as existsSync6, readFileSync as readFileSync10, realpathSync as
|
|
14143
|
+
import { existsSync as existsSync6, readFileSync as readFileSync10, realpathSync as realpathSync6 } from "fs";
|
|
14082
14144
|
import { extname, resolve as resolve18 } from "path";
|
|
14083
14145
|
|
|
14084
14146
|
// src/session_handoff_contract.ts
|
|
@@ -14550,6 +14612,7 @@ import { spawnSync } from "child_process";
|
|
|
14550
14612
|
// src/utils/subprocess_env.ts
|
|
14551
14613
|
init_provider_api_key_env();
|
|
14552
14614
|
var USER_SUBPROCESS_STRIPPED_ZTC_ENV = [
|
|
14615
|
+
"ZTC_APPROVAL_TOKEN",
|
|
14553
14616
|
"ZERG_ROUTER_BASE_URL",
|
|
14554
14617
|
"ZTC_AUTH_TOKEN",
|
|
14555
14618
|
"ZTC_BROKER_TOKEN",
|
|
@@ -14583,6 +14646,7 @@ var MODEL_ROUTE_CREDENTIAL_ENV = Object.freeze([.../* @__PURE__ */ new Set([
|
|
|
14583
14646
|
])]);
|
|
14584
14647
|
function removeUserSubprocessCredentials(source2) {
|
|
14585
14648
|
const env = { ...source2 };
|
|
14649
|
+
delete env.ZTC_APPROVAL_TOKEN;
|
|
14586
14650
|
delete env.ZTC_BROKER_TOKEN;
|
|
14587
14651
|
delete env.ZTC_DESKTOP_RUNTIME_MANIFEST;
|
|
14588
14652
|
delete env.ZTC_DESKTOP_RUNTIME_LEASE;
|
|
@@ -36124,6 +36188,7 @@ var profileSchema = external_exports.object({
|
|
|
36124
36188
|
approvalRequiredCapabilities: external_exports.array(external_exports.enum(PERMISSION_CAPABILITIES)).max(7).optional(),
|
|
36125
36189
|
allowedPaths: strings.optional(),
|
|
36126
36190
|
deniedPaths: strings.optional(),
|
|
36191
|
+
pathPrecedence: external_exports.enum(["deny_first", "specific"]).optional(),
|
|
36127
36192
|
allowedShellCommands: strings.optional(),
|
|
36128
36193
|
deniedShellCommands: strings.optional(),
|
|
36129
36194
|
networkHosts: external_exports.object({ allow: strings.optional(), deny: strings.optional() }).strict().optional(),
|
|
@@ -36276,8 +36341,9 @@ function commandStillRunning(content2) {
|
|
|
36276
36341
|
// src/agent/runtime/policy.ts
|
|
36277
36342
|
init_capabilities();
|
|
36278
36343
|
init_checked_commands();
|
|
36344
|
+
import { realpathSync as realpathSync2 } from "node:fs";
|
|
36279
36345
|
import { homedir as homedir9 } from "os";
|
|
36280
|
-
import { resolve as resolve9, isAbsolute as isAbsolute4, sep as sep3 } from "path";
|
|
36346
|
+
import { resolve as resolve9, isAbsolute as isAbsolute4, sep as sep3, dirname as dirname11, basename as basename4 } from "path";
|
|
36281
36347
|
var AllowAllPolicy = class {
|
|
36282
36348
|
evaluateTool() {
|
|
36283
36349
|
return { allowed: true };
|
|
@@ -36338,7 +36404,10 @@ var CapabilityPolicy = class {
|
|
|
36338
36404
|
const allowedRoots2 = (this.profile.allowedPaths || []).map((path2) => normalizeRoot2(path2, this.cwd));
|
|
36339
36405
|
for (const path2 of paths) {
|
|
36340
36406
|
const absolutePath = normalizeRoot2(path2, this.cwd);
|
|
36341
|
-
|
|
36407
|
+
const allowed = allowedRoots2.filter((root) => isWithinRoot(absolutePath, root));
|
|
36408
|
+
const denied = deniedRoots2.filter((root) => isWithinRoot(absolutePath, root));
|
|
36409
|
+
const exception = this.profile.pathPrecedence === "specific" && allowed.some((root) => denied.every((blocked) => root.length > blocked.length));
|
|
36410
|
+
if (denied.length > 0 && !exception) {
|
|
36342
36411
|
return {
|
|
36343
36412
|
allowed: false,
|
|
36344
36413
|
reason: `Permission denied: path is blocked by profile (${path2})`
|
|
@@ -36435,7 +36504,7 @@ function extractPathArgs(args, executionCwd) {
|
|
|
36435
36504
|
}
|
|
36436
36505
|
function normalizeRoot2(path2, cwd) {
|
|
36437
36506
|
const expanded = path2 === "~" ? homedir9() : path2.replace(/^~(?=\/|$)/, homedir9());
|
|
36438
|
-
return resolve9(isAbsolute4(expanded) ? expanded : resolve9(cwd, expanded));
|
|
36507
|
+
return canonicalPolicyPath(resolve9(isAbsolute4(expanded) ? expanded : resolve9(cwd, expanded)), cwd);
|
|
36439
36508
|
}
|
|
36440
36509
|
function isWithinRoot(path2, root) {
|
|
36441
36510
|
return path2 === root || path2.startsWith(root.endsWith(sep3) ? root : `${root}${sep3}`);
|
|
@@ -36481,6 +36550,19 @@ function hostMatchesPattern(host, pattern) {
|
|
|
36481
36550
|
}
|
|
36482
36551
|
return normalizedHost === normalizedPattern;
|
|
36483
36552
|
}
|
|
36553
|
+
function canonicalPolicyPath(path2, cwd) {
|
|
36554
|
+
const expanded = path2 === "~" ? homedir9() : path2.replace(/^~(?=\/|$)/, homedir9());
|
|
36555
|
+
const absolute = resolve9(cwd, expanded);
|
|
36556
|
+
try {
|
|
36557
|
+
return realpathSync2(absolute);
|
|
36558
|
+
} catch (error62) {
|
|
36559
|
+
const code = error62.code;
|
|
36560
|
+
if (code !== "ENOENT" && code !== "ENOTDIR") throw error62;
|
|
36561
|
+
const parent = dirname11(absolute);
|
|
36562
|
+
if (parent === absolute) return absolute;
|
|
36563
|
+
return resolve9(canonicalPolicyPath(parent, cwd), basename4(absolute));
|
|
36564
|
+
}
|
|
36565
|
+
}
|
|
36484
36566
|
|
|
36485
36567
|
// src/agent/runtime/tracing.ts
|
|
36486
36568
|
var NoopTracer = class {
|
|
@@ -37048,12 +37130,12 @@ init_evidence();
|
|
|
37048
37130
|
init_atomic_write();
|
|
37049
37131
|
|
|
37050
37132
|
// src/utils/path_lock.ts
|
|
37051
|
-
import { realpathSync as
|
|
37052
|
-
import { basename as
|
|
37133
|
+
import { realpathSync as realpathSync3 } from "fs";
|
|
37134
|
+
import { basename as basename5, dirname as dirname12, join as join16 } from "path";
|
|
37053
37135
|
var chains = /* @__PURE__ */ new Map();
|
|
37054
37136
|
function canonicalKey2(path2) {
|
|
37055
37137
|
try {
|
|
37056
|
-
return join16(
|
|
37138
|
+
return join16(realpathSync3(dirname12(path2)), basename5(path2));
|
|
37057
37139
|
} catch {
|
|
37058
37140
|
return path2;
|
|
37059
37141
|
}
|
|
@@ -37081,9 +37163,9 @@ import {
|
|
|
37081
37163
|
lstatSync as lstatSync3,
|
|
37082
37164
|
openSync as openSync4,
|
|
37083
37165
|
readSync as readSync3,
|
|
37084
|
-
realpathSync as
|
|
37166
|
+
realpathSync as realpathSync4
|
|
37085
37167
|
} from "node:fs";
|
|
37086
|
-
import { basename as
|
|
37168
|
+
import { basename as basename6, dirname as dirname13, isAbsolute as isAbsolute5, join as join18, resolve as resolve11, sep as sep5 } from "node:path";
|
|
37087
37169
|
|
|
37088
37170
|
// src/utils/mirror_media.ts
|
|
37089
37171
|
import { tmpdir as tmpdir3 } from "os";
|
|
@@ -37120,7 +37202,7 @@ function canonicalCheckpoint(path2) {
|
|
|
37120
37202
|
if (!isAbsolute5(path2) || /[\u0000-\u001f\u007f]/u.test(path2)) {
|
|
37121
37203
|
throw new SessionMediaError("invalid_reference", "Image checkpoint must be an absolute canonical file path.");
|
|
37122
37204
|
}
|
|
37123
|
-
return join18(
|
|
37205
|
+
return join18(realpathSync4(dirname13(path2)), basename6(path2));
|
|
37124
37206
|
}
|
|
37125
37207
|
function imageType(data) {
|
|
37126
37208
|
if (data.length >= 8 && data.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))) {
|
|
@@ -37409,7 +37491,7 @@ init_capabilities();
|
|
|
37409
37491
|
// src/agent/tools/file.ts
|
|
37410
37492
|
init_capabilities();
|
|
37411
37493
|
import { readFile as readFile3, readdir as readdir2, stat as stat2 } from "fs/promises";
|
|
37412
|
-
import { basename as
|
|
37494
|
+
import { basename as basename7, dirname as dirname14, resolve as resolve13, posix as posix2 } from "path";
|
|
37413
37495
|
import { homedir as homedir10 } from "os";
|
|
37414
37496
|
import { createHash as createHash15, randomBytes as randomBytes3 } from "crypto";
|
|
37415
37497
|
import { exec as exec2 } from "child_process";
|
|
@@ -37846,7 +37928,7 @@ var readFileTool = {
|
|
|
37846
37928
|
type: "image",
|
|
37847
37929
|
mediaType: image.mediaType,
|
|
37848
37930
|
data: raw.toString("base64"),
|
|
37849
|
-
description: `Read image ${
|
|
37931
|
+
description: `Read image ${basename7(path2)} (${raw.length.toLocaleString()} bytes)`,
|
|
37850
37932
|
path: path2
|
|
37851
37933
|
});
|
|
37852
37934
|
}
|
|
@@ -37980,7 +38062,7 @@ var writeFileTool = {
|
|
|
37980
38062
|
} else {
|
|
37981
38063
|
const { mkdir: mkdir5 } = await import("fs/promises");
|
|
37982
38064
|
const written = await withPathLock(path2, async () => {
|
|
37983
|
-
await mkdir5(
|
|
38065
|
+
await mkdir5(dirname14(path2), { recursive: true });
|
|
37984
38066
|
let before = "";
|
|
37985
38067
|
try {
|
|
37986
38068
|
before = await readFile3(path2, { encoding: "utf-8" });
|
|
@@ -39344,7 +39426,7 @@ var RequestEncoder = class {
|
|
|
39344
39426
|
const frozen = this.deps.frozenResultContent?.(result.tool_use_id);
|
|
39345
39427
|
if (frozen !== void 0) {
|
|
39346
39428
|
content2 = frozen;
|
|
39347
|
-
} else if (!this.deps.currentTurnToolIds.has(result.tool_use_id) && content2.length > STABLE_RESULT_LIMIT) {
|
|
39429
|
+
} else if (!this.deps.currentTurnToolIds.has(result.tool_use_id) && !this.deps.selectorVerdict?.has(result.tool_use_id) && content2.length > STABLE_RESULT_LIMIT) {
|
|
39348
39430
|
const copy = this.deps.saveFullResult?.(result.tool_use_id, result.source ?? content2) ?? null;
|
|
39349
39431
|
content2 = content2.slice(0, OLD_RESULT_CAP) + `
|
|
39350
39432
|
[truncated \u2014 ${content2.length} chars total${copy ? `; ${resultCopyNote(result.tool_use_id, copy)}; ${COPY_ADVICE}` : ""}]`;
|
|
@@ -39508,8 +39590,8 @@ init_loop_policy();
|
|
|
39508
39590
|
init_tool_compression();
|
|
39509
39591
|
|
|
39510
39592
|
// src/agent/runtime/tool_runtime.ts
|
|
39511
|
-
import { basename as
|
|
39512
|
-
import { realpathSync as
|
|
39593
|
+
import { basename as basename9, dirname as dirname17, join as join22, relative as relative3, resolve as resolve17 } from "path";
|
|
39594
|
+
import { realpathSync as realpathSync5 } from "node:fs";
|
|
39513
39595
|
import { appendFile } from "node:fs/promises";
|
|
39514
39596
|
|
|
39515
39597
|
// src/agent/tools/helper_requirements.ts
|
|
@@ -39534,7 +39616,7 @@ init_config();
|
|
|
39534
39616
|
|
|
39535
39617
|
// src/context/intents_loader.ts
|
|
39536
39618
|
import { appendFileSync as appendFileSync5, existsSync as existsSync5, mkdirSync as mkdirSync7, readFileSync as readFileSync9, statSync as statSync5, writeFileSync as writeFileSync8 } from "fs";
|
|
39537
|
-
import { basename as
|
|
39619
|
+
import { basename as basename8, dirname as dirname15, join as join19, relative as relative2, resolve as resolve15 } from "path";
|
|
39538
39620
|
var DEFAULT_MAX_BYTES = 32 * 1024;
|
|
39539
39621
|
var DEFAULT_FILE_INTENT_THRESHOLD_LINES = 400;
|
|
39540
39622
|
function loadIntentsContext(cwd = process.cwd(), settings, options = {}) {
|
|
@@ -39561,7 +39643,7 @@ function loadIntentsContextDetailed(cwd = process.cwd(), settings, options = {})
|
|
|
39561
39643
|
bytes: loaded.bytes,
|
|
39562
39644
|
truncated: loaded.truncated
|
|
39563
39645
|
});
|
|
39564
|
-
const label = relative2(cwd, candidate) ||
|
|
39646
|
+
const label = relative2(cwd, candidate) || basename8(candidate);
|
|
39565
39647
|
sections.push([
|
|
39566
39648
|
`# Intent Context: ${label}`,
|
|
39567
39649
|
"",
|
|
@@ -39591,11 +39673,11 @@ function maybeAutoUpdateIntents(options) {
|
|
|
39591
39673
|
const absolutePath = resolve15(options.cwd, changedPath);
|
|
39592
39674
|
const target = selectIntentTarget(options.cwd, absolutePath, threshold);
|
|
39593
39675
|
ensureIntentFile(target);
|
|
39594
|
-
const relChanged = relative2(options.cwd, absolutePath) ||
|
|
39676
|
+
const relChanged = relative2(options.cwd, absolutePath) || basename8(absolutePath);
|
|
39595
39677
|
const note = `- ${(/* @__PURE__ */ new Date()).toISOString()}: tool \`${options.toolName}\` changed \`${relChanged}\`. Keep this file's higher-level intent current if behavior changed.
|
|
39596
39678
|
`;
|
|
39597
39679
|
appendFileSync5(target, note, "utf-8");
|
|
39598
|
-
updated.add(relative2(options.cwd, target) ||
|
|
39680
|
+
updated.add(relative2(options.cwd, target) || basename8(target));
|
|
39599
39681
|
}
|
|
39600
39682
|
return [...updated];
|
|
39601
39683
|
}
|
|
@@ -39622,7 +39704,7 @@ function findRootToCwd(cwd) {
|
|
|
39622
39704
|
if (existsSync5(join19(current, ".git"))) {
|
|
39623
39705
|
break;
|
|
39624
39706
|
}
|
|
39625
|
-
const parent =
|
|
39707
|
+
const parent = dirname15(current);
|
|
39626
39708
|
if (parent === current) {
|
|
39627
39709
|
break;
|
|
39628
39710
|
}
|
|
@@ -39634,7 +39716,7 @@ function selectIntentTarget(cwd, absolutePath, threshold) {
|
|
|
39634
39716
|
if (isLargeFile(absolutePath, threshold)) {
|
|
39635
39717
|
return fileIntentPath(absolutePath);
|
|
39636
39718
|
}
|
|
39637
|
-
const dir = existsSync5(absolutePath) && statSync5(absolutePath).isDirectory() ? absolutePath :
|
|
39719
|
+
const dir = existsSync5(absolutePath) && statSync5(absolutePath).isDirectory() ? absolutePath : dirname15(absolutePath);
|
|
39638
39720
|
const normalizedCwd = resolve15(cwd);
|
|
39639
39721
|
const normalizedDir = resolve15(dir);
|
|
39640
39722
|
if (!isInside(normalizedDir, normalizedCwd)) {
|
|
@@ -39643,11 +39725,11 @@ function selectIntentTarget(cwd, absolutePath, threshold) {
|
|
|
39643
39725
|
return join19(normalizedDir, ".ztc-intents.md");
|
|
39644
39726
|
}
|
|
39645
39727
|
function ensureIntentFile(path2) {
|
|
39646
|
-
mkdirSync7(
|
|
39728
|
+
mkdirSync7(dirname15(path2), { recursive: true });
|
|
39647
39729
|
if (existsSync5(path2)) {
|
|
39648
39730
|
return;
|
|
39649
39731
|
}
|
|
39650
|
-
const title =
|
|
39732
|
+
const title = basename8(path2) === ".ztc-intents.md" ? "ZTC Folder Intents" : `ZTC File Intents for ${basename8(path2).replace(/^\.ztc-intents-/, "").replace(/\.md$/, "")}`;
|
|
39651
39733
|
writeFileSync8(path2, [
|
|
39652
39734
|
`# ${title}`,
|
|
39653
39735
|
"",
|
|
@@ -39658,7 +39740,7 @@ function ensureIntentFile(path2) {
|
|
|
39658
39740
|
].join("\n") + "\n", "utf-8");
|
|
39659
39741
|
}
|
|
39660
39742
|
function fileIntentPath(absolutePath) {
|
|
39661
|
-
return join19(
|
|
39743
|
+
return join19(dirname15(absolutePath), `.ztc-intents-${basename8(absolutePath)}.md`);
|
|
39662
39744
|
}
|
|
39663
39745
|
function isLargeFile(path2, threshold) {
|
|
39664
39746
|
try {
|
|
@@ -39706,7 +39788,7 @@ function pushUnique(paths, seen, path2) {
|
|
|
39706
39788
|
paths.push(normalized);
|
|
39707
39789
|
}
|
|
39708
39790
|
function isIntentFile(path2) {
|
|
39709
|
-
return
|
|
39791
|
+
return basename8(path2).startsWith(".ztc-intents");
|
|
39710
39792
|
}
|
|
39711
39793
|
function isInside(path2, root) {
|
|
39712
39794
|
return path2 === root || path2.startsWith(`${root}/`);
|
|
@@ -39859,13 +39941,14 @@ Example: [{"question": "Which framework?", "options": [{"label": "React", "descr
|
|
|
39859
39941
|
required: []
|
|
39860
39942
|
}
|
|
39861
39943
|
},
|
|
39862
|
-
execute: async (args) => {
|
|
39944
|
+
execute: async (args, context) => {
|
|
39945
|
+
const callback = context?.askUser ?? askUserCallback;
|
|
39863
39946
|
const question = args.question ? String(args.question) : "";
|
|
39864
39947
|
const optionsJson = args.options_json ? String(args.options_json) : "";
|
|
39865
39948
|
const questionsJson = args.questions_json ? String(args.questions_json) : "";
|
|
39866
39949
|
const allowOther = args.allow_other !== void 0 ? Boolean(args.allow_other) : true;
|
|
39867
39950
|
debugLog3("execute called:", { hasQuestion: !!question, hasOptionsJson: !!optionsJson, hasQuestionsJson: !!questionsJson, alreadyCalled: askUserCalledThisTurn });
|
|
39868
|
-
if (!
|
|
39951
|
+
if (!callback) {
|
|
39869
39952
|
debugLog3("ERROR: no callback registered");
|
|
39870
39953
|
return "Error: ask_user is not available in this context. Use an interactive ZTC session with question input enabled.";
|
|
39871
39954
|
}
|
|
@@ -39910,10 +39993,11 @@ Example: [{"question": "Which framework?", "options": [{"label": "React", "descr
|
|
|
39910
39993
|
}
|
|
39911
39994
|
questions.push({ question: q.question, options: opts, allow_other: allowOther });
|
|
39912
39995
|
}
|
|
39913
|
-
const error63 =
|
|
39996
|
+
const error63 = await callback(questions);
|
|
39997
|
+
if (typeof error63 === "object" && error63 !== null) return error63.answer;
|
|
39914
39998
|
if (error63 !== null) return registrationFailure(error63);
|
|
39915
|
-
const wasDuplicate2 = askUserCalledThisTurn;
|
|
39916
|
-
askUserCalledThisTurn = true;
|
|
39999
|
+
const wasDuplicate2 = !context?.askUser && askUserCalledThisTurn;
|
|
40000
|
+
if (!context?.askUser) askUserCalledThisTurn = true;
|
|
39917
40001
|
if (wasDuplicate2) {
|
|
39918
40002
|
return "Question merged with previous ask_user call in this turn. All questions will be shown together. Do NOT call ask_user again.";
|
|
39919
40003
|
}
|
|
@@ -39929,10 +40013,11 @@ Example: [{"question": "Which framework?", "options": [{"label": "React", "descr
|
|
|
39929
40013
|
if (typeof parsed === "string") {
|
|
39930
40014
|
return `Error: ${parsed}`;
|
|
39931
40015
|
}
|
|
39932
|
-
const error62 =
|
|
40016
|
+
const error62 = await callback([{ question, options: parsed, allow_other: allowOther }]);
|
|
40017
|
+
if (typeof error62 === "object" && error62 !== null) return error62.answer;
|
|
39933
40018
|
if (error62 !== null) return registrationFailure(error62);
|
|
39934
|
-
const wasDuplicate = askUserCalledThisTurn;
|
|
39935
|
-
askUserCalledThisTurn = true;
|
|
40019
|
+
const wasDuplicate = !context?.askUser && askUserCalledThisTurn;
|
|
40020
|
+
if (!context?.askUser) askUserCalledThisTurn = true;
|
|
39936
40021
|
if (wasDuplicate) {
|
|
39937
40022
|
return "Question merged with previous ask_user call in this turn. All questions will be shown together. Do NOT call ask_user again.";
|
|
39938
40023
|
}
|
|
@@ -40099,7 +40184,7 @@ init_source_verification_contract();
|
|
|
40099
40184
|
import { createHash as createHash18 } from "node:crypto";
|
|
40100
40185
|
import { constants as constants4 } from "node:fs";
|
|
40101
40186
|
import { lstat as lstat5, open as open4, realpath as realpath3 } from "node:fs/promises";
|
|
40102
|
-
import { dirname as
|
|
40187
|
+
import { dirname as dirname16, resolve as resolve16 } from "node:path";
|
|
40103
40188
|
var VERIFIER_INPUT_MAX_BYTES = 65536;
|
|
40104
40189
|
var hash4 = (bytes4) => createHash18("sha256").update(bytes4).digest("hex");
|
|
40105
40190
|
function seal(source2) {
|
|
@@ -40138,7 +40223,7 @@ async function captureVerifierInputs(context, paths) {
|
|
|
40138
40223
|
const absolute = resolve16(cwd, row.path);
|
|
40139
40224
|
try {
|
|
40140
40225
|
if (context.signal?.aborted || context.canInspectVerificationSource && !await context.canInspectVerificationSource(seal(structuredClone(source2)))) continue;
|
|
40141
|
-
if (await realpath3(
|
|
40226
|
+
if (await realpath3(dirname16(absolute)) !== dirname16(absolute)) continue;
|
|
40142
40227
|
const location = await lstat5(absolute);
|
|
40143
40228
|
row.bytes = Number.isSafeInteger(location.size) && location.size >= 0 ? location.size : 0;
|
|
40144
40229
|
row.mode = location.mode & 4095;
|
|
@@ -40157,7 +40242,7 @@ async function captureVerifierInputs(context, paths) {
|
|
|
40157
40242
|
}
|
|
40158
40243
|
const after = await handle.stat();
|
|
40159
40244
|
const current = await lstat5(absolute);
|
|
40160
|
-
if (context.signal?.aborted || used !== before.size || before.dev !== after.dev || before.ino !== after.ino || before.size !== after.size || before.mtimeMs !== after.mtimeMs || before.ctimeMs !== after.ctimeMs || current.dev !== before.dev || current.ino !== before.ino || await realpath3(
|
|
40245
|
+
if (context.signal?.aborted || used !== before.size || before.dev !== after.dev || before.ino !== after.ino || before.size !== after.size || before.mtimeMs !== after.mtimeMs || before.ctimeMs !== after.ctimeMs || current.dev !== before.dev || current.ino !== before.ino || await realpath3(dirname16(absolute)) !== dirname16(absolute)) continue;
|
|
40161
40246
|
if (context.canInspectVerificationSource && !await context.canInspectVerificationSource(seal(structuredClone(source2)))) continue;
|
|
40162
40247
|
if (context.signal?.aborted) continue;
|
|
40163
40248
|
const captured = bytes4.subarray(0, used);
|
|
@@ -40584,7 +40669,7 @@ function isHostControlPlaneWrite(tool, args, cwd) {
|
|
|
40584
40669
|
try {
|
|
40585
40670
|
const noFollowLeaf = (path2) => {
|
|
40586
40671
|
const absolute = resolve17(path2);
|
|
40587
|
-
return join22(
|
|
40672
|
+
return join22(realpathSync5(dirname17(absolute)), basename9(absolute));
|
|
40588
40673
|
};
|
|
40589
40674
|
return noFollowLeaf(resolve17(cwd, args.path)) === noFollowLeaf(tool.hostControlPlaneWritePath);
|
|
40590
40675
|
} catch {
|
|
@@ -40596,13 +40681,13 @@ function canonicalSourcePath(path2) {
|
|
|
40596
40681
|
const missing = [];
|
|
40597
40682
|
while (true) {
|
|
40598
40683
|
try {
|
|
40599
|
-
return join22(
|
|
40684
|
+
return join22(realpathSync5(probe), ...missing);
|
|
40600
40685
|
} catch (error62) {
|
|
40601
40686
|
const code = error62.code;
|
|
40602
40687
|
if (code !== "ENOENT" && code !== "ENOTDIR") throw error62;
|
|
40603
|
-
const parent =
|
|
40688
|
+
const parent = dirname17(probe);
|
|
40604
40689
|
if (parent === probe) throw error62;
|
|
40605
|
-
missing.unshift(
|
|
40690
|
+
missing.unshift(basename9(probe));
|
|
40606
40691
|
probe = parent;
|
|
40607
40692
|
}
|
|
40608
40693
|
}
|
|
@@ -40699,9 +40784,10 @@ async function recordToolTrace(entry) {
|
|
|
40699
40784
|
}
|
|
40700
40785
|
async function executeToolWithRuntime(name2, args, options) {
|
|
40701
40786
|
const tool = getTool(name2, options.tools);
|
|
40787
|
+
const sourceTool = tool?.outputSource ?? tool;
|
|
40702
40788
|
const traceStartedAt = Date.now();
|
|
40703
40789
|
const ordinaryCapabilities = getRuntimeCapabilities(tool);
|
|
40704
|
-
const requiredCapabilities = (input2) =>
|
|
40790
|
+
const requiredCapabilities = (input2) => sourceTool === runCommandTool && Object.hasOwn(input2, "verification") ? [.../* @__PURE__ */ new Set([...ordinaryCapabilities, "file_read" /* FILE_READ */])] : ordinaryCapabilities;
|
|
40705
40791
|
let capabilities = requiredCapabilities(args);
|
|
40706
40792
|
let effectiveArgs = args;
|
|
40707
40793
|
let approvalGranted = false;
|
|
@@ -40710,7 +40796,7 @@ async function executeToolWithRuntime(name2, args, options) {
|
|
|
40710
40796
|
let verifierDecision;
|
|
40711
40797
|
let benchmarkComparisonDecision;
|
|
40712
40798
|
let policyExecutionCwd;
|
|
40713
|
-
if (options.remoteResourceSession && (!tool || !isManagedRemoteResourceTool(tool, options.remoteResourceSession) &&
|
|
40799
|
+
if (options.remoteResourceSession && (!tool || !isManagedRemoteResourceTool(tool, options.remoteResourceSession) && sourceTool !== askUserTool && sourceTool !== recallToolResponseTool2 && sourceTool !== sessionEvidenceTool)) {
|
|
40714
40800
|
return {
|
|
40715
40801
|
content: "Guarded remote session: use the host-managed remote_resource tool under a required lease. Unrestricted shell, network and plugin execution is blocked.",
|
|
40716
40802
|
isError: true,
|
|
@@ -40860,9 +40946,9 @@ async function executeToolWithRuntime(name2, args, options) {
|
|
|
40860
40946
|
}
|
|
40861
40947
|
}
|
|
40862
40948
|
const verificationAdmission = () => {
|
|
40863
|
-
const adapter =
|
|
40864
|
-
const measured =
|
|
40865
|
-
if (!adapter && (
|
|
40949
|
+
const adapter = sourceTool === verifyArtifactTool || sourceTool === benchmarkCPUTool;
|
|
40950
|
+
const measured = sourceTool === benchmarkCPUTool;
|
|
40951
|
+
if (!adapter && (sourceTool !== runCommandTool || !Object.hasOwn(effectiveArgs, "verification"))) return void 0;
|
|
40866
40952
|
if (!options.context) return {
|
|
40867
40953
|
content: "Source verification requires a host execution context.",
|
|
40868
40954
|
isError: true,
|
|
@@ -40964,20 +41050,20 @@ async function executeToolWithRuntime(name2, args, options) {
|
|
|
40964
41050
|
if (dispatchAdmission) return dispatchAdmission;
|
|
40965
41051
|
const toolContext = options.context ? {
|
|
40966
41052
|
...options.context,
|
|
40967
|
-
onOutput:
|
|
40968
|
-
canInspectVerificationSource:
|
|
40969
|
-
managedCommandWaitSliceMs:
|
|
40970
|
-
onManagedCommand:
|
|
41053
|
+
onOutput: sourceTool === runCommandTool || tool?.outputSource === runCommandTool ? options.context.onOutput : void 0,
|
|
41054
|
+
canInspectVerificationSource: sourceTool === runCommandTool || sourceTool === readCommandTool || sourceTool === stopCommandTool || sourceTool === verifyArtifactTool || sourceTool === benchmarkCPUTool ? canInspectVerificationSource : void 0,
|
|
41055
|
+
managedCommandWaitSliceMs: sourceTool === readCommandTool || sourceTool === runCommandTool ? options.context.managedCommandWaitSliceMs : void 0,
|
|
41056
|
+
onManagedCommand: sourceTool === readCommandTool || sourceTool === runCommandTool ? (observation) => {
|
|
40971
41057
|
managedCommand = observation;
|
|
40972
41058
|
} : void 0,
|
|
40973
|
-
onVerificationReceipt:
|
|
41059
|
+
onVerificationReceipt: sourceTool === runCommandTool || sourceTool === stopCommandTool || sourceTool === benchmarkCPUTool ? (receipt2) => {
|
|
40974
41060
|
verificationReceipt = structuredClone(receipt2);
|
|
40975
41061
|
} : void 0,
|
|
40976
|
-
onHostVerifier:
|
|
41062
|
+
onHostVerifier: sourceTool === verifyArtifactTool || sourceTool === benchmarkCPUTool ? (receipt2, decision) => {
|
|
40977
41063
|
verificationReceipt = structuredClone(receipt2);
|
|
40978
41064
|
verifierDecision = structuredClone(decision);
|
|
40979
41065
|
} : void 0,
|
|
40980
|
-
onHostBenchmarkComparison:
|
|
41066
|
+
onHostBenchmarkComparison: sourceTool === compareBenchmarksTool ? (decision) => {
|
|
40981
41067
|
benchmarkComparisonDecision = structuredClone(decision);
|
|
40982
41068
|
} : void 0
|
|
40983
41069
|
} : void 0;
|
|
@@ -41193,6 +41279,7 @@ init_token_usage();
|
|
|
41193
41279
|
|
|
41194
41280
|
// src/utils/compaction.ts
|
|
41195
41281
|
init_compaction();
|
|
41282
|
+
init_router_required();
|
|
41196
41283
|
init_completion_state();
|
|
41197
41284
|
function resolvePromptPrefixId(messages) {
|
|
41198
41285
|
const head = messages.find((message) => message.role !== "system" && message.role !== "tool");
|
|
@@ -41428,6 +41515,7 @@ function isContextOverflowMessage(message) {
|
|
|
41428
41515
|
var ROUTER_RATE_LIMIT_CODES = /* @__PURE__ */ new Set(["rate_limit_exceeded", "free_model_daily_limit"]);
|
|
41429
41516
|
var RATE_LIMITED_ATTEMPTS = 10;
|
|
41430
41517
|
var DEFAULT_LLM_REQUEST_TIMEOUT_MS = 12e4;
|
|
41518
|
+
var HEADLESS_AUTONOMY_NUDGE = "No human is available in this run, so nobody will answer questions. Decide yourself with your best judgment (state the choice and why in one line), then keep working through your next steps until the task is complete and verified. Stop only when the work is done or you are blocked by something you cannot resolve yourself, and then say exactly what blocks you. Stay within what the task asked for: leave steps beyond it, such as publishing, deploying or messaging people, to whoever reads the result.";
|
|
41431
41519
|
function resolveLlmRequestTimeoutMs(configured, fromSettings) {
|
|
41432
41520
|
if (configured !== void 0 && Number.isFinite(configured) && configured > 0) {
|
|
41433
41521
|
return Math.floor(configured);
|
|
@@ -41493,6 +41581,7 @@ function handoffSubstance(text5) {
|
|
|
41493
41581
|
}
|
|
41494
41582
|
var Agent = class _Agent {
|
|
41495
41583
|
config;
|
|
41584
|
+
questionRequester;
|
|
41496
41585
|
onMidTurnCompact;
|
|
41497
41586
|
midTurnCompactThresholdPercent;
|
|
41498
41587
|
midTurnCompactWindow;
|
|
@@ -41661,7 +41750,7 @@ var Agent = class _Agent {
|
|
|
41661
41750
|
let admitted = !this.remoteResourceSession && receipt2.source.origin === "local";
|
|
41662
41751
|
if (admitted) {
|
|
41663
41752
|
try {
|
|
41664
|
-
admitted =
|
|
41753
|
+
admitted = realpathSync6(this._cwd) === receipt2.source.cwd;
|
|
41665
41754
|
} catch {
|
|
41666
41755
|
admitted = false;
|
|
41667
41756
|
}
|
|
@@ -41746,9 +41835,11 @@ var Agent = class _Agent {
|
|
|
41746
41835
|
autoContinue: config2.autoContinue ?? true,
|
|
41747
41836
|
completionCheck: config2.completionCheck ?? false,
|
|
41748
41837
|
maxConsecutiveAutoContinues: config2.maxConsecutiveAutoContinues ?? 3,
|
|
41838
|
+
noHumanAvailable: config2.noHumanAvailable ?? false,
|
|
41749
41839
|
pinTaskHeader: config2.pinTaskHeader ?? true,
|
|
41750
41840
|
deferToolSchemas: config2.deferToolSchemas ?? true
|
|
41751
41841
|
};
|
|
41842
|
+
this.questionRequester = config2.questionRequester;
|
|
41752
41843
|
this.onMidTurnCompact = config2.onMidTurnCompact;
|
|
41753
41844
|
this.midTurnCompactThresholdPercent = config2.midTurnCompactThresholdPercent;
|
|
41754
41845
|
this.midTurnCompactWindow = config2.midTurnCompactWindow;
|
|
@@ -41813,6 +41904,16 @@ var Agent = class _Agent {
|
|
|
41813
41904
|
execution: { ...this.config.execution }
|
|
41814
41905
|
});
|
|
41815
41906
|
}
|
|
41907
|
+
questionHandler(signal) {
|
|
41908
|
+
const requester = this.questionRequester;
|
|
41909
|
+
if (!requester) return void 0;
|
|
41910
|
+
return async (questions) => {
|
|
41911
|
+
const answers = await requester(questions, signal);
|
|
41912
|
+
signal?.throwIfAborted();
|
|
41913
|
+
if (answers.length !== questions.length || answers.some((answer) => typeof answer !== "string")) return "Question answer count does not match";
|
|
41914
|
+
return { answer: questions.length === 1 ? answers[0] : JSON.stringify(questions.map((question, index) => ({ question: question.question, answer: answers[index] }))) };
|
|
41915
|
+
};
|
|
41916
|
+
}
|
|
41816
41917
|
setAutoContinue(enabled2) {
|
|
41817
41918
|
this._autoContinue = enabled2 && this.backend.getModelCapabilities?.(this.config.model)?.tools !== false;
|
|
41818
41919
|
}
|
|
@@ -41857,6 +41958,28 @@ var Agent = class _Agent {
|
|
|
41857
41958
|
];
|
|
41858
41959
|
return continuePatterns.some((p) => p.test(content2));
|
|
41859
41960
|
}
|
|
41961
|
+
/**
|
|
41962
|
+
* With nobody to answer, a turn may not end on a question to the user or on a
|
|
41963
|
+
* list of steps the model says it has not done yet.
|
|
41964
|
+
*/
|
|
41965
|
+
needsAutonomousContinuation(content2) {
|
|
41966
|
+
if (!this._autoContinue || !this.config.noHumanAvailable) return false;
|
|
41967
|
+
const asksUser = [
|
|
41968
|
+
/\b(do|would) you (want|like|prefer)\b/i,
|
|
41969
|
+
/\b(should|shall) I\b[^.?!\n]*\?/i,
|
|
41970
|
+
/\blet me know\b/i,
|
|
41971
|
+
/\b(need|want) your (call|input|decision|confirmation|approval|go-ahead)\b/i,
|
|
41972
|
+
/\bplease (confirm|advise|choose|decide)\b/i,
|
|
41973
|
+
/\bwhich (option|approach|one|variant)\b[^.?!\n]*\?/i
|
|
41974
|
+
];
|
|
41975
|
+
const unfinished = [
|
|
41976
|
+
/\bmy next steps? (are|is|would be)\b/i,
|
|
41977
|
+
/\bnext steps?:/i,
|
|
41978
|
+
/\bstatus:[^\n]*\b(unverified|in progress|incomplete|pending|not yet)\b/i,
|
|
41979
|
+
/\bI have(n't| not) (yet )?(run|built|tested|verified|measured|rendered)\b/i
|
|
41980
|
+
];
|
|
41981
|
+
return [...asksUser, ...unfinished].some((pattern) => pattern.test(content2));
|
|
41982
|
+
}
|
|
41860
41983
|
hasApiKey() {
|
|
41861
41984
|
return this.config.runtimeCredentialsAvailable || this._authenticationManagedByBackend || !!this.config.apiKey && this.config.apiKey.length > 0;
|
|
41862
41985
|
}
|
|
@@ -43278,15 +43401,17 @@ ${this.runtimeContext}` : this.config.systemPrompt;
|
|
|
43278
43401
|
continue;
|
|
43279
43402
|
}
|
|
43280
43403
|
}
|
|
43281
|
-
|
|
43404
|
+
const unattended = this.needsAutonomousContinuation(iterationText);
|
|
43405
|
+
if (!this.remoteResourceSession && (unattended || this.shouldContinue(iterationText)) && this._consecutiveAutoContinues < this.config.maxConsecutiveAutoContinues) {
|
|
43282
43406
|
this._consecutiveAutoContinues++;
|
|
43283
43407
|
const acTodos = getLatestTodos();
|
|
43284
43408
|
const incomplete = acTodos.filter((t) => t.status !== "completed");
|
|
43285
|
-
let continueMsg = "continue";
|
|
43286
|
-
let reason = "";
|
|
43409
|
+
let continueMsg = unattended ? HEADLESS_AUTONOMY_NUDGE : "continue";
|
|
43410
|
+
let reason = unattended ? "no human available to answer" : "";
|
|
43287
43411
|
if (incomplete.length > 0) {
|
|
43288
43412
|
const remaining = incomplete.map((t) => t.content).join(", ");
|
|
43289
|
-
|
|
43413
|
+
const todoMsg = `You still have ${incomplete.length} incomplete task(s): ${remaining}. Continue working on them.`;
|
|
43414
|
+
continueMsg = unattended ? `${HEADLESS_AUTONOMY_NUDGE} ${todoMsg}` : todoMsg;
|
|
43290
43415
|
reason = `${incomplete.length} incomplete task(s): ${remaining}`;
|
|
43291
43416
|
}
|
|
43292
43417
|
this.emit({ type: "auto_continue", reason });
|
|
@@ -43543,6 +43668,7 @@ ${this.runtimeContext}` : this.config.systemPrompt;
|
|
|
43543
43668
|
sessionId: this.config.sessionId,
|
|
43544
43669
|
managedCommandWaitSliceMs: 0,
|
|
43545
43670
|
signal,
|
|
43671
|
+
askUser: this.questionHandler(signal),
|
|
43546
43672
|
toolResponseStore: this.toolResponseStore,
|
|
43547
43673
|
discoveredTools: this.discoveredTools,
|
|
43548
43674
|
backgroundWorkers: this.backgroundWorkers,
|
|
@@ -43579,6 +43705,7 @@ ${this.runtimeContext}` : this.config.systemPrompt;
|
|
|
43579
43705
|
sessionId: this.config.sessionId,
|
|
43580
43706
|
managedCommandWaitSliceMs: 0,
|
|
43581
43707
|
signal,
|
|
43708
|
+
askUser: this.questionHandler(signal),
|
|
43582
43709
|
toolResponseStore: this.toolResponseStore,
|
|
43583
43710
|
discoveredTools: this.discoveredTools,
|
|
43584
43711
|
backgroundWorkers: this.backgroundWorkers,
|
|
@@ -43933,6 +44060,7 @@ ${this.runtimeContext}` : this.config.systemPrompt;
|
|
|
43933
44060
|
sessionId: this.config.sessionId,
|
|
43934
44061
|
signal: options.signal,
|
|
43935
44062
|
onUsage: options.onUsage,
|
|
44063
|
+
askUser: this.questionHandler(options.signal),
|
|
43936
44064
|
toolResponseStore: this.toolResponseStore,
|
|
43937
44065
|
discoveredTools: this.discoveredTools,
|
|
43938
44066
|
backgroundWorkers: this.backgroundWorkers,
|
|
@@ -44318,6 +44446,21 @@ ${this.runtimeContext}` : this.config.systemPrompt;
|
|
|
44318
44446
|
const message = error62.message.slice(0, 64 * 1024);
|
|
44319
44447
|
const statusMatch = message.match(/API error \((\d+)\)/);
|
|
44320
44448
|
const statusCode = statusMatch ? parseInt(statusMatch[1], 10) : 0;
|
|
44449
|
+
if (statusCode === 429) {
|
|
44450
|
+
try {
|
|
44451
|
+
const diagnostic = message.slice(0, 64 * 1024);
|
|
44452
|
+
const record11 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
44453
|
+
const payload = record11(JSON.parse(diagnostic.slice(diagnostic.indexOf("{"), diagnostic.lastIndexOf("}") + 1)));
|
|
44454
|
+
const detail = record11(payload.error);
|
|
44455
|
+
const data = record11(payload.data);
|
|
44456
|
+
const counts = [payload.message, payload.statusMessage, detail.message, payload.error].map((value) => typeof value === "string" ? /^Token quota exceeded ?\((\d{1,20})\/(\d{1,20})\)$/.exec(value) : null).find((value) => value !== null);
|
|
44457
|
+
if ([payload.code, detail.code, data.code].includes("personal_token_quota_exceeded") || counts) {
|
|
44458
|
+
const usage = counts ? ` (${counts[1]}/${counts[2]} tokens)` : "";
|
|
44459
|
+
return { retryable: false, reason: `Token quota exhausted${usage}. Review your Router quota or wait for its reset before retrying.` };
|
|
44460
|
+
}
|
|
44461
|
+
} catch {
|
|
44462
|
+
}
|
|
44463
|
+
}
|
|
44321
44464
|
let errorType = "";
|
|
44322
44465
|
let errorCode = "";
|
|
44323
44466
|
let errorMessage = "";
|
|
@@ -44453,7 +44596,7 @@ init_capabilities();
|
|
|
44453
44596
|
init_logger();
|
|
44454
44597
|
init_extension_discovery();
|
|
44455
44598
|
import { homedir as homedir11 } from "os";
|
|
44456
|
-
import { join as join23, resolve as resolve19, basename as
|
|
44599
|
+
import { join as join23, resolve as resolve19, basename as basename10 } from "path";
|
|
44457
44600
|
import { readdir as readdir3, readFile as readFile5 } from "fs/promises";
|
|
44458
44601
|
var MAX_DEPTH = 4;
|
|
44459
44602
|
function defaultMarkdownRoots() {
|
|
@@ -44578,7 +44721,7 @@ function deriveSkillId(path2, meta3) {
|
|
|
44578
44721
|
if (explicit) return explicit;
|
|
44579
44722
|
const name2 = meta3.name ? String(meta3.name) : "";
|
|
44580
44723
|
if (name2) return name2.toLowerCase().replace(/\s+/g, "-");
|
|
44581
|
-
return
|
|
44724
|
+
return basename10(resolve19(path2, "..")) || "skill";
|
|
44582
44725
|
}
|
|
44583
44726
|
async function loadSkills(roots = defaultMarkdownRoots()) {
|
|
44584
44727
|
const skills = [];
|
|
@@ -44617,7 +44760,7 @@ async function loadSkills(roots = defaultMarkdownRoots()) {
|
|
|
44617
44760
|
}
|
|
44618
44761
|
|
|
44619
44762
|
// src/skills/bundled/index.ts
|
|
44620
|
-
import { dirname as
|
|
44763
|
+
import { dirname as dirname18, resolve as resolve20 } from "path";
|
|
44621
44764
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
44622
44765
|
|
|
44623
44766
|
// src/skills/bundled/init-context.ts
|
|
@@ -44771,7 +44914,7 @@ var bundledCodeSkills = [
|
|
|
44771
44914
|
initContextSkill
|
|
44772
44915
|
];
|
|
44773
44916
|
function bundledMarkdownRoot() {
|
|
44774
|
-
const here =
|
|
44917
|
+
const here = dirname18(fileURLToPath2(import.meta.url));
|
|
44775
44918
|
return resolve20(here);
|
|
44776
44919
|
}
|
|
44777
44920
|
|
|
@@ -44796,21 +44939,22 @@ async function loadIsolatedSkills(roots) {
|
|
|
44796
44939
|
return dedupeById(await loadSkills([...roots]));
|
|
44797
44940
|
}
|
|
44798
44941
|
async function loadAll() {
|
|
44942
|
+
const explicit = isExplicitExtensionDiscovery();
|
|
44799
44943
|
const cfg = configStore.get();
|
|
44800
|
-
const extraRoots =
|
|
44944
|
+
const extraRoots = explicit ? [] : cfg.skills?.roots ?? [];
|
|
44801
44945
|
const bundledRoot = bundledMarkdownRoot();
|
|
44802
44946
|
const mdRoots = [
|
|
44803
44947
|
...defaultMarkdownRoots(),
|
|
44804
44948
|
...extraRoots,
|
|
44805
44949
|
bundledRoot
|
|
44806
44950
|
];
|
|
44807
|
-
const markdownSkills = await loadSkills(mdRoots);
|
|
44951
|
+
const markdownSkills = (await loadSkills(mdRoots)).filter((skill) => explicit || skill.sourceRoot !== bundledRoot || !bundledCodeSkills.some((builtin) => builtin.id === skill.id));
|
|
44808
44952
|
for (const skill of markdownSkills) {
|
|
44809
44953
|
if (skill.sourceRoot === bundledRoot) {
|
|
44810
44954
|
skill.sourceRoot = "bundled:md";
|
|
44811
44955
|
}
|
|
44812
44956
|
}
|
|
44813
|
-
return dedupeById([...markdownSkills, ...bundledCodeSkills]);
|
|
44957
|
+
return dedupeById([...markdownSkills, ...explicit ? [] : bundledCodeSkills]);
|
|
44814
44958
|
}
|
|
44815
44959
|
async function getSkills(force = false) {
|
|
44816
44960
|
if (!force && cached2 && Date.now() - cached2.loadedAt < CACHE_TTL_MS) {
|
|
@@ -44856,6 +45000,7 @@ function applyDisabledFilter(skills) {
|
|
|
44856
45000
|
return skills.filter((skill) => !disabled.has(skill.id));
|
|
44857
45001
|
}
|
|
44858
45002
|
async function getVisibleSkills() {
|
|
45003
|
+
if (isExplicitExtensionDiscovery()) return applyDisabledFilter(await loadAll());
|
|
44859
45004
|
return applyDisabledFilter(await getSkills());
|
|
44860
45005
|
}
|
|
44861
45006
|
|
|
@@ -44950,7 +45095,7 @@ var invokeSkillTool = makeInvokeSkillTool(resolveAmbientSkills);
|
|
|
44950
45095
|
// src/zlm.ts
|
|
44951
45096
|
var ZLM_EMBED_API_VERSION = "zerglang.ztc-embed/1";
|
|
44952
45097
|
var ZLM_STDIO_PROTOCOL = "zerglang.ztc-host/1";
|
|
44953
|
-
var ZLM_ZTC_VERSION = true ? "0.
|
|
45098
|
+
var ZLM_ZTC_VERSION = true ? "0.20.0-beta.1" : "development";
|
|
44954
45099
|
var ZLM_MAX_HOST_TOOLS = 64;
|
|
44955
45100
|
var ZLM_MAX_SYSTEM_PROMPT_BYTES = 128 * 1024;
|
|
44956
45101
|
var ZLM_HOST_APPROVAL_CAPABILITIES = Object.freeze([
|
|
@@ -45207,7 +45352,7 @@ async function runDirectEntry() {
|
|
|
45207
45352
|
var directEntry = false;
|
|
45208
45353
|
if (process.argv[1]) {
|
|
45209
45354
|
try {
|
|
45210
|
-
directEntry =
|
|
45355
|
+
directEntry = realpathSync7(resolve21(process.argv[1])) === realpathSync7(fileURLToPath3(import.meta.url));
|
|
45211
45356
|
} catch {
|
|
45212
45357
|
directEntry = resolve21(process.argv[1]) === fileURLToPath3(import.meta.url);
|
|
45213
45358
|
}
|