@eddyskywalker/dsh-chatgpt-subscription 0.73.0 → 0.74.0
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/CHANGELOG.md +21 -0
- package/lib/client.js.map +1 -1
- package/lib/codemode.js +125 -60
- package/lib/{entry-plan-mode-5DBZA4Il.js → entry-plan-mode-EShP3ndV.js} +34 -8
- package/lib/index.js +591 -477
- package/lib/{llm-compat-u9mor0uu.js → llm-compat--WsaC9K6.js} +25 -1
- package/lib/plan-mode.js +2 -2
- package/lib/types/compat.d.ts +1 -1
- package/lib/types/entry-codemode.d.ts.map +1 -1
- package/lib/types/entry-plan-mode.d.ts +14 -0
- package/lib/types/entry-plan-mode.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/errors.d.ts +1 -1
- package/lib/types/host/antigravity-acp/errors.d.ts.map +1 -1
- package/lib/types/host/cache-warmup/contracts.d.ts +11 -1
- package/lib/types/host/cache-warmup/contracts.d.ts.map +1 -1
- package/lib/types/host/cache-warmup/result-tool.d.ts +4 -0
- package/lib/types/host/cache-warmup/result-tool.d.ts.map +1 -1
- package/lib/types/host/cache-warmup/store.d.ts.map +1 -1
- package/lib/types/host/claude/adapter.d.ts +2 -1
- package/lib/types/host/claude/adapter.d.ts.map +1 -1
- package/lib/types/host/cline-pass/adapter.d.ts.map +1 -1
- package/lib/types/host/cline-pass/mapper.d.ts +1 -1
- package/lib/types/host/cline-pass/mapper.d.ts.map +1 -1
- package/lib/types/host/codemode/rules.d.ts.map +1 -1
- package/lib/types/host/codemode/transport.d.ts +23 -1
- package/lib/types/host/codemode/transport.d.ts.map +1 -1
- package/lib/types/host/command-code/adapter.d.ts.map +1 -1
- package/lib/types/host/common/llm-compat.d.ts +15 -2
- package/lib/types/host/common/llm-compat.d.ts.map +1 -1
- package/lib/types/host/common/stream-error.d.ts +1 -1
- package/lib/types/host/common/stream-error.d.ts.map +1 -1
- package/lib/types/host/common/tool-runaway.d.ts +91 -3
- package/lib/types/host/common/tool-runaway.d.ts.map +1 -1
- package/lib/types/host/compaction-policy-guard.d.ts.map +1 -1
- package/lib/types/host/glm-coding-plan/adapter.d.ts.map +1 -1
- package/lib/types/host/kimi-code/adapter.d.ts.map +1 -1
- package/lib/types/host/kimi-code/repeat-breaker.d.ts +3 -1
- package/lib/types/host/kimi-code/repeat-breaker.d.ts.map +1 -1
- package/lib/types/host/minimax-code/adapter.d.ts.map +1 -1
- package/lib/types/host/minimax-code/runtime-enhancements.d.ts +10 -97
- package/lib/types/host/minimax-code/runtime-enhancements.d.ts.map +1 -1
- package/lib/types/host/ollama/adapter.d.ts.map +1 -1
- package/lib/types/host/opendesign/adapter.d.ts.map +1 -1
- package/lib/types/host/opendesign/mapper.d.ts +1 -1
- package/lib/types/host/opendesign/mapper.d.ts.map +1 -1
- package/lib/types/host/qoder/adapter.d.ts.map +1 -1
- package/lib/types/host/responses-client.d.ts.map +1 -1
- package/lib/types/host/step-code/adapter.d.ts.map +1 -1
- package/lib/types/host/workbuddy/account-pool.d.ts +1 -1
- package/lib/types/host/workbuddy/account-pool.d.ts.map +1 -1
- package/lib/types/host/workbuddy/adapter.d.ts +2 -1
- package/lib/types/host/workbuddy/adapter.d.ts.map +1 -1
- package/lib/types/index.d.ts +2 -2
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +42 -42
- package/presets/dispatch/README.md +2 -2
- package/presets/dispatch/agent.cordis.yml +2 -2
package/lib/codemode.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as PLUGIN_MESSAGE_SOURCE_KIND } from "./llm-compat
|
|
1
|
+
import { n as PLUGIN_MESSAGE_SOURCE_KIND } from "./llm-compat--WsaC9K6.js";
|
|
2
2
|
import * as dshLlm from "@deepseek-ai/dsh-llm";
|
|
3
3
|
import { HarnessError, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
4
4
|
import { NativeToolExecutor } from "@deepseek-ai/dsh-tool-executor-native";
|
|
@@ -647,17 +647,17 @@ function buildCodemodeSectionText(input) {
|
|
|
647
647
|
...example,
|
|
648
648
|
"",
|
|
649
649
|
python ? retained ? "- A retained Python REPL: top-level await and a final expression. Its variables and imported modules survive into your later programs in this session." : "- Async Python program: top-level await works; print or evaluate a final expression to produce output." : retained ? "- A retained TypeScript REPL: top-level declarations, await, and a final expression. Its variables and imported modules survive into your later programs in this session." : "- Erasable TypeScript, run as the body of an async function: top-level await and return work.",
|
|
650
|
-
"- Only what you inspect(...values), return, or console.log reaches the conversation; every intermediate result stays in the program, so filter and aggregate there instead of returning raw payloads.",
|
|
650
|
+
!python && retained ? "- Only what you pass to inspect(...values) (or a sole final expression when nothing was inspected) reaches the conversation; every intermediate result stays in the program, so filter and aggregate there. Never write a top-level `return` (an early `return` inside `if` is a SyntaxError in the REPL)." : "- Only what you inspect(...values), return, or console.log reaches the conversation; every intermediate result stays in the program, so filter and aggregate there instead of returning raw payloads.",
|
|
651
651
|
"- File, search, and shell tool results are named-field objects, never bare strings — read the field, not the envelope (`job_list` and `list_agents` are the only bare arrays):",
|
|
652
|
-
" `read` → `{ path, offset, lines: [{ number, text }], totalLines }` · `glob` → `{ root, paths }` · `grep` → `{ matches: [{ path, lineNumber, line }] }` · `edit` → `{ path, before, after }` · `write` → `{ path, operation, before, after }` · `win_bash` → `{ stdout, stderr, exitCode }` · `web_fetch` → `{ url, statusCode, body, truncated }` · `job_output` → `{ text, job }` · `read_image` → `{ path, image }` · `skill` → `{ name, content }`.",
|
|
652
|
+
" `read` → `{ path, offset, lines: [{ number, text }], totalLines }` · `glob` → `{ root, paths }` · `grep` → `{ matches: [{ path, lineNumber, line }] }` · `edit` → `{ path, before, after }` · `write` → `{ path, operation, before, after }` · `win_bash` → `{ stdout, stderr, exitCode }` · `web_fetch` → `{ url, statusCode, body, truncated }` · `job_output` → `{ text, job }` · `read_image` → `{ path, image }` · `skill` → `{ name, content }` · `subagent` → `{ kind, name }`.",
|
|
653
653
|
python ? "- Read the field: `page[\"lines\"]`, `match[\"text\"]`. Calling `.split()`, `.splitlines()` or `in` on the envelope itself is always wrong." : "- Read the field: `r.lines.map((l) => l.text)`. Calling `.map`, `.filter`, `.split` or `in` on the envelope itself is always wrong.",
|
|
654
654
|
"- Anything not listed above (MCP tools, hidden plugin tools) answers with its **declared output schema**: call `" + describeTool + "({ name })` and read the top-level keys before picking a field. One discovery call is far cheaper than the `TypeError` that loses the whole program.",
|
|
655
655
|
"- Discovery returns whole objects too: `" + listTool + "` answers `{ tools: [{ name, description, namespace }] }`, `" + searchTool + "` answers `{ tools: [{ name, namespace, description, parameters, output? }], fallback? }`, and `" + describeTool + "` answers `{ found, name?, namespace?, description?, parameters?, output? }`.",
|
|
656
|
-
"- Tool argument objects and `return` values must be lossless JSON: **never leave `undefined` in an object property value** — `{ a: x.opt }` fails the call when `x.opt === undefined`. Omit the key, write `x.opt ?? null`, or print it with `inspect` / `console.log`.",
|
|
656
|
+
!python && retained ? "- Tool argument objects and evaluated values must be lossless JSON: **never leave `undefined` in an object property value** — `{ a: x.opt }` fails the call when `x.opt === undefined`. Omit the key, write `x.opt ?? null`, or inspect it with `inspect(x)`." : "- Tool argument objects and `return` values must be lossless JSON: **never leave `undefined` in an object property value** — `{ a: x.opt }` fails the call when `x.opt === undefined`. Omit the key, write `x.opt ?? null`, or print it with `inspect` / `console.log`.",
|
|
657
657
|
"- Parameter keys: `read`, `edit`, `write`, and `read_image` take `file_path` (not `path`); `glob` and `grep` take `path`; `win_bash` takes `workdir` (not `cwd`).",
|
|
658
658
|
...python ? [] : [
|
|
659
659
|
"- Paths and regexes: write a Windows path with forward slashes (`C:/Users/...`) or wrap it in `String.raw`; a literal `C:\\Users` inside an ordinary string is read as the escape `\\U` and the program never starts (`Expected unicode escape`). Regex backslashes (`\\d`, `\\.`) have the same trap — double them or use `String.raw`.",
|
|
660
|
-
"- A program is not a module: `import('./src/x.ts')` and `import('vscode')` cannot resolve — the program runs in a fresh process with no module graph. Read files with `tools.read`; `await import('node:fs')` works only for Node built-ins.",
|
|
660
|
+
...retained ? ["- Modules in the retained REPL: CommonJS `require` / `module` and host packages like `import('vscode')` are unavailable; dynamic `await import('./src/x.ts')` resolves relative to the session's initial working directory (whereas `process.cwd()` and relative file paths follow the current session directory on each call).", "- Retained REPL scope: each call copies prior top-level bindings into a fresh scope (mutating an object persists; reassigning a primitive only updates that call's copy). Either use a copied name or redeclare it — never self-reference in `let x = x + 1`, avoid `var` inside blocks, and never declare `__$binding_*` identifiers."] : ["- A program is not a module: `import('./src/x.ts')` and `import('vscode')` cannot resolve — the program runs in a fresh process with no module graph. Read files with `tools.read`; `await import('node:fs')` works only for Node built-ins."],
|
|
661
661
|
"- `process.env` is empty inside the program: `os.tmpdir()` and credentialed CLIs (`gh`, `git`, `npm`) spawned via `node:child_process` miss `TEMP`, `HOME`, `APPDATA`, and auth tokens. Run shell and CLI commands through `await tools.win_bash({ command })` instead."
|
|
662
662
|
],
|
|
663
663
|
"- Prefer batching multi-step read/search chains inside one " + run + " program instead of issuing many sequential single-tool turns.",
|
|
@@ -945,8 +945,8 @@ var ToolCallLimitExceededError = class extends Error {
|
|
|
945
945
|
* 程序运行自身失败时抛出的结构化错误(对齐内核 `CodeRunFailedError`,`code: 'CODE_RUN_FAILED'`)。
|
|
946
946
|
*/
|
|
947
947
|
var CodeRunFailedError = class extends HarnessError {
|
|
948
|
-
constructor(message) {
|
|
949
|
-
super(message, "CODE_RUN_FAILED");
|
|
948
|
+
constructor(message, options) {
|
|
949
|
+
super(message, "CODE_RUN_FAILED", options);
|
|
950
950
|
this.name = "CodeRunFailedError";
|
|
951
951
|
}
|
|
952
952
|
};
|
|
@@ -959,6 +959,37 @@ var CodeResetFailedError = class extends HarnessError {
|
|
|
959
959
|
this.name = "CodeResetFailedError";
|
|
960
960
|
}
|
|
961
961
|
};
|
|
962
|
+
/**
|
|
963
|
+
* Code Mode 参数校验失败(对齐 `@deepseek-ai/dsh-tools` 的 `ToolArgsError`,`code: 'INVALID_ARGS'`)。
|
|
964
|
+
*/
|
|
965
|
+
var CodemodeArgsError = class extends HarnessError {
|
|
966
|
+
violations;
|
|
967
|
+
constructor(message) {
|
|
968
|
+
super(message, "INVALID_ARGS");
|
|
969
|
+
this.name = "ToolArgsError";
|
|
970
|
+
this.violations = [message];
|
|
971
|
+
}
|
|
972
|
+
};
|
|
973
|
+
/**
|
|
974
|
+
* Code Mode 缺少必须宿主上下文时抛出的结构化错误(对齐 `@deepseek-ai/dsh-tools` 的 `ToolContextUnavailableError`)。
|
|
975
|
+
*/
|
|
976
|
+
var CodemodeContextUnavailableError = class extends HarnessError {
|
|
977
|
+
constructor(message, options) {
|
|
978
|
+
super(message, "TOOL_CONTEXT_UNAVAILABLE", options);
|
|
979
|
+
this.name = "ToolContextUnavailableError";
|
|
980
|
+
}
|
|
981
|
+
};
|
|
982
|
+
/**
|
|
983
|
+
* 单次沙箱提权未获准时抛出的结构化错误(对齐 `@deepseek-ai/dsh-sandbox` 的 `SandboxEscalationError`)。
|
|
984
|
+
*/
|
|
985
|
+
var SandboxEscalationError = class extends HarnessError {
|
|
986
|
+
code;
|
|
987
|
+
constructor(message, code) {
|
|
988
|
+
super(message, code);
|
|
989
|
+
this.name = "SandboxEscalationError";
|
|
990
|
+
this.code = code;
|
|
991
|
+
}
|
|
992
|
+
};
|
|
962
993
|
/** 与内核 `run_code` 一致的 `description` 参数说明。 */
|
|
963
994
|
const DESCRIPTION_PARAM_DESCRIPTION = "Clear, concise description of what this program does in active voice, 5-10 words (shown in the UI). Examples: \"Count TODO markers across packages\"; \"Read failing test and its fixture\"; \"Rename config key in every cordis.yml\".";
|
|
964
995
|
/** 与 `@deepseek-ai/dsh-ptc-runtime` 的 `PTC_IMAGE_TAG` 对齐的跨包协议符号。 */
|
|
@@ -1148,8 +1179,11 @@ function createTransportDefinition(host, rules) {
|
|
|
1148
1179
|
async execute(args, exec) {
|
|
1149
1180
|
const input = readArguments(args);
|
|
1150
1181
|
const runtime = host.runtime();
|
|
1151
|
-
if (runtime === void 0) throw new
|
|
1152
|
-
if (input.timeoutMs !== void 0 && runtime.timeout !== void 0 === false && isStrictTimeoutUnsupported(runtime)) throw new
|
|
1182
|
+
if (runtime === void 0) throw new CodemodeContextUnavailableError("codemode: no PTC runtime is mounted (ctx.ptcRuntime); the program transport is unavailable");
|
|
1183
|
+
if (input.timeoutMs !== void 0 && runtime.timeout !== void 0 === false && isStrictTimeoutUnsupported(runtime)) throw new CodemodeArgsError("timeoutMs is not available for this PTC runtime");
|
|
1184
|
+
const hasRawEscalation = input.rawSandboxPermissions !== void 0 || input.rawJustification !== void 0;
|
|
1185
|
+
if (hasRawEscalation && isStrictSandboxUnsupported(runtime)) throw new CodemodeArgsError("sandbox_permissions and justification are not available for this PTC runtime");
|
|
1186
|
+
const prevalidatedEscalation = hasRawEscalation && runtime.sandboxMode !== void 0 ? validateEscalationArgs(input.rawSandboxPermissions, input.rawJustification) : void 0;
|
|
1153
1187
|
await host.awaitPredecessors?.(exec.agent, exec.signal);
|
|
1154
1188
|
const catalog = host.catalog(exec.agent, exec.toolSet);
|
|
1155
1189
|
const runController = new AbortController();
|
|
@@ -1293,25 +1327,28 @@ function createTransportDefinition(host, rules) {
|
|
|
1293
1327
|
}) ?? untrackRun;
|
|
1294
1328
|
let effectivePolicy = standingPolicy;
|
|
1295
1329
|
let escalated = false;
|
|
1296
|
-
if (
|
|
1297
|
-
if (standingPolicy === void 0 || typeof host.escalateSandbox !== "function") throw new
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1330
|
+
if (hasRawEscalation) {
|
|
1331
|
+
if (standingPolicy === void 0 || typeof host.escalateSandbox !== "function") throw new CodemodeArgsError("sandbox_permissions and justification are not available for this PTC runtime");
|
|
1332
|
+
const escalation = prevalidatedEscalation ?? validateEscalationArgs(input.rawSandboxPermissions, input.rawJustification);
|
|
1333
|
+
if (escalation.sandboxPermissions !== void 0 && escalation.justification !== void 0) {
|
|
1334
|
+
if (approvedEscalatedMode === void 0) {
|
|
1335
|
+
const nextPolicy = await host.escalateSandbox({
|
|
1336
|
+
requestedMode: escalation.sandboxPermissions,
|
|
1337
|
+
justification: escalation.justification,
|
|
1338
|
+
standingPolicy,
|
|
1339
|
+
agent: exec.agent,
|
|
1340
|
+
callId: String(exec.callId),
|
|
1341
|
+
toolName: runToolName,
|
|
1342
|
+
signal: nestedSignal
|
|
1343
|
+
});
|
|
1344
|
+
effectivePolicy = nextPolicy;
|
|
1345
|
+
approvedEscalatedMode = modeOfPolicy(nextPolicy);
|
|
1346
|
+
} else if (typeof standingPolicy === "object" && standingPolicy !== null) effectivePolicy = {
|
|
1347
|
+
...standingPolicy,
|
|
1348
|
+
mode: approvedEscalatedMode
|
|
1349
|
+
};
|
|
1350
|
+
escalated = modeOfPolicy(effectivePolicy) !== modeOfPolicy(standingPolicy);
|
|
1351
|
+
}
|
|
1315
1352
|
}
|
|
1316
1353
|
const runMode = standingMode ?? modeOfPolicy(effectivePolicy);
|
|
1317
1354
|
if (runMode !== void 0) untrackRun = host.trackRun?.({
|
|
@@ -1345,10 +1382,14 @@ function createTransportDefinition(host, rules) {
|
|
|
1345
1382
|
try {
|
|
1346
1383
|
result = await attempt();
|
|
1347
1384
|
} catch (error) {
|
|
1348
|
-
if (!isRetainedPolicyChange(error))
|
|
1385
|
+
if (!isRetainedPolicyChange(error)) rethrowClassifiedRunError(error, exec.signal, runtime);
|
|
1349
1386
|
await host.releaseOwner(owner);
|
|
1350
1387
|
host.stateOwner(exec.agent);
|
|
1351
|
-
|
|
1388
|
+
try {
|
|
1389
|
+
result = await attempt();
|
|
1390
|
+
} catch (retryError) {
|
|
1391
|
+
rethrowClassifiedRunError(retryError, exec.signal, runtime);
|
|
1392
|
+
}
|
|
1352
1393
|
}
|
|
1353
1394
|
} finally {
|
|
1354
1395
|
runController.abort(runToolName + " settled");
|
|
@@ -1385,9 +1426,11 @@ function createTransportDefinition(host, rules) {
|
|
|
1385
1426
|
const failureText = limitError === void 0 || limitError.message === result.error.message ? result.error.message : `${limitError.message}\n${result.error.message}`;
|
|
1386
1427
|
throw new CodeRunFailedError("program failed (" + result.error.kind + "): " + failureText + logsText + sandboxText + hint);
|
|
1387
1428
|
}
|
|
1429
|
+
const logs = extractLogsList(result);
|
|
1430
|
+
const effectiveValue = hasStructuredOutput && hasExplicitOutputBlocks(outputBlocks) ? void 0 : result.value;
|
|
1388
1431
|
const output = {
|
|
1389
|
-
logs
|
|
1390
|
-
...
|
|
1432
|
+
logs,
|
|
1433
|
+
...effectiveValue === void 0 ? {} : { result: effectiveValue },
|
|
1391
1434
|
...result.sandbox === void 0 ? {} : { sandbox: {
|
|
1392
1435
|
mode: result.sandbox.mode,
|
|
1393
1436
|
denied: result.sandbox.denied,
|
|
@@ -1396,7 +1439,7 @@ function createTransportDefinition(host, rules) {
|
|
|
1396
1439
|
};
|
|
1397
1440
|
if (hasStructuredOutput) {
|
|
1398
1441
|
structuredOutputs.set(output, outputBlocks);
|
|
1399
|
-
if (hasImages && typeof exec === "object" && exec !== null) inspections.set(exec, { blocks: renderStructuredOutputBlocks(outputBlocks,
|
|
1442
|
+
if (hasImages && typeof exec === "object" && exec !== null) inspections.set(exec, { blocks: renderStructuredOutputBlocks(outputBlocks, effectiveValue, output.sandbox, runtime.sandboxMode, runToolName) });
|
|
1400
1443
|
}
|
|
1401
1444
|
return output;
|
|
1402
1445
|
} finally {
|
|
@@ -1427,6 +1470,24 @@ function safeRuntime(host) {
|
|
|
1427
1470
|
function isStrictTimeoutUnsupported(runtime) {
|
|
1428
1471
|
return Object.prototype.hasOwnProperty.call(runtime, "timeout") && runtime.timeout === void 0;
|
|
1429
1472
|
}
|
|
1473
|
+
/** 判断运行时是否显式不支持单次沙箱提权参数(Python 运行时或显式声明 `sandboxMode: undefined`)。 */
|
|
1474
|
+
function isStrictSandboxUnsupported(runtime) {
|
|
1475
|
+
return runtime.language === "python" || Object.prototype.hasOwnProperty.call(runtime, "sandboxMode") && runtime.sandboxMode === void 0;
|
|
1476
|
+
}
|
|
1477
|
+
/** 将 `attempt()` 阶段的底层运行异常按上游 `ptc.ts:668` 契约分类并抛出。 */
|
|
1478
|
+
function rethrowClassifiedRunError(error, execSignal, runtime) {
|
|
1479
|
+
if (error instanceof HarnessError) throw error;
|
|
1480
|
+
if (execSignal.aborted) {
|
|
1481
|
+
const abortError = new HarnessError(runtime.retainsState ? `tool call aborted: ${messageOf$2(error)}` : "tool call aborted", "ABORTED");
|
|
1482
|
+
abortError.name = "AbortError";
|
|
1483
|
+
throw abortError;
|
|
1484
|
+
}
|
|
1485
|
+
throw new CodeRunFailedError("code run failed: " + messageOf$2(error), { cause: error });
|
|
1486
|
+
}
|
|
1487
|
+
/** 判定结构化 `result.output` 是否已经包含显式输出(图片或非空文本)。 */
|
|
1488
|
+
function hasExplicitOutputBlocks(blocks) {
|
|
1489
|
+
return blocks.some((block) => block.type === "image" || block.type === "text" && typeof block.text === "string" && block.text.length > 0);
|
|
1490
|
+
}
|
|
1430
1491
|
function modeOfPolicy(policy) {
|
|
1431
1492
|
if (typeof policy !== "object" || policy === null) return void 0;
|
|
1432
1493
|
const mode = policy.mode;
|
|
@@ -1489,10 +1550,8 @@ function renderStructuredOutputBlocks(blocks, resultValue, sandbox, sandboxMode,
|
|
|
1489
1550
|
attachment: block.attachment
|
|
1490
1551
|
});
|
|
1491
1552
|
}
|
|
1492
|
-
const renderedValue = resultValue
|
|
1493
|
-
if (renderedValue.length > 0)
|
|
1494
|
-
if ((pendingText.endsWith("\n") ? pendingText.slice(0, -1) : pendingText) !== renderedValue) pendingText = pendingText.length === 0 ? renderedValue : pendingText.endsWith("\n") ? pendingText + renderedValue : pendingText + "\n" + renderedValue;
|
|
1495
|
-
}
|
|
1553
|
+
const renderedValue = !hasExplicitOutputBlocks(blocks) && resultValue !== void 0 ? renderProgramValue(resultValue) : "";
|
|
1554
|
+
if (renderedValue.length > 0) pendingText = pendingText.length === 0 ? renderedValue : pendingText.endsWith("\n") ? pendingText + renderedValue : pendingText + "\n" + renderedValue;
|
|
1496
1555
|
const sandboxNotes = [];
|
|
1497
1556
|
if (sandbox?.enforcement === "partial") sandboxNotes.push("File sandbox enforcement is partial on this host.");
|
|
1498
1557
|
if (sandbox?.denied === true) sandboxNotes.push("The " + sandbox.mode + " file sandbox denied an operation." + escalationGuidance(sandboxMode));
|
|
@@ -1613,11 +1672,11 @@ function isRetainedPolicyChange(error) {
|
|
|
1613
1672
|
}
|
|
1614
1673
|
/** 校验单次沙箱提权参数配对(对齐 `@deepseek-ai/dsh-sandbox` 的 `validateEscalationArgs`)。 */
|
|
1615
1674
|
function validateEscalationArgs(sandboxPermissions, justification) {
|
|
1616
|
-
if (sandboxPermissions !== void 0 && justification === void 0) throw new
|
|
1617
|
-
if (justification !== void 0 && sandboxPermissions === void 0) throw new
|
|
1675
|
+
if (sandboxPermissions !== void 0 && justification === void 0) throw new SandboxEscalationError("invalid escalation: sandbox_permissions requires a justification", "SANDBOX_ESCALATION_INVALID_ARGUMENT");
|
|
1676
|
+
if (justification !== void 0 && sandboxPermissions === void 0) throw new SandboxEscalationError("invalid escalation: justification is only valid together with sandbox_permissions", "SANDBOX_ESCALATION_INVALID_ARGUMENT");
|
|
1618
1677
|
if (sandboxPermissions === void 0 && justification === void 0) return {};
|
|
1619
|
-
if (typeof sandboxPermissions !== "string" || !ESCALATION_TARGETS.includes(sandboxPermissions)) throw new
|
|
1620
|
-
if (typeof justification !== "string" || justification.trim().length === 0) throw new
|
|
1678
|
+
if (typeof sandboxPermissions !== "string" || !ESCALATION_TARGETS.includes(sandboxPermissions)) throw new SandboxEscalationError("invalid sandbox_permissions: expected \"workspace-write\" or \"danger-full-access\"", "SANDBOX_ESCALATION_INVALID_ARGUMENT");
|
|
1679
|
+
if (typeof justification !== "string" || justification.trim().length === 0) throw new SandboxEscalationError("invalid justification: expected a non-empty sentence", "SANDBOX_ESCALATION_INVALID_ARGUMENT");
|
|
1621
1680
|
return {
|
|
1622
1681
|
sandboxPermissions,
|
|
1623
1682
|
justification
|
|
@@ -1722,17 +1781,16 @@ function excerpt(text) {
|
|
|
1722
1781
|
}
|
|
1723
1782
|
/** 参数完全不成形时的错误。 */
|
|
1724
1783
|
function invalidArgumentsError(args, raw, keys) {
|
|
1725
|
-
if (args === null) return
|
|
1726
|
-
if (typeof args !== "string") return
|
|
1727
|
-
if (keys !== void 0 && keys.length > 0) return
|
|
1728
|
-
if (raw.trim().length === 0) return
|
|
1729
|
-
return
|
|
1784
|
+
if (args === null) return new CodemodeArgsError("codemode: invalid arguments: expected an object with \"code\" and \"description\" (received null)");
|
|
1785
|
+
if (typeof args !== "string") return new CodemodeArgsError("codemode: invalid arguments: expected an object with \"code\" and \"description\" (received " + typeof args + ")");
|
|
1786
|
+
if (keys !== void 0 && keys.length > 0) return new CodemodeArgsError("codemode: invalid arguments: expected an object with \"code\" and \"description\" (received keys: " + keys.join(", ") + ")");
|
|
1787
|
+
if (raw.trim().length === 0) return new CodemodeArgsError("codemode: invalid arguments: expected an object with \"code\" and \"description\" (received an empty string)");
|
|
1788
|
+
return new CodemodeArgsError("codemode: invalid arguments: expected an object with \"code\" and \"description\" (received a string that is not a JSON object: " + excerpt(raw) + ")");
|
|
1730
1789
|
}
|
|
1731
1790
|
/** 参数里没有程序源码、又不是可救形态时的错误。 */
|
|
1732
1791
|
function missingCodeError(record, raw) {
|
|
1733
1792
|
const keys = Object.keys(record);
|
|
1734
|
-
|
|
1735
|
-
return /* @__PURE__ */ new Error("codemode: invalid code: expected a non-empty string" + note);
|
|
1793
|
+
return new CodemodeArgsError("codemode: invalid code: expected a non-empty string" + (keys.length === 0 ? "" : " (received keys: " + keys.join(", ") + (raw.trim().length > 0 ? "; raw: " + excerpt(raw) : "") + "; pass program source in \"code\")"));
|
|
1736
1794
|
}
|
|
1737
1795
|
/** 一段文本像不像程序源码(模型把源码直接发成字符串时判这个)。 */
|
|
1738
1796
|
function looksLikeProgram(text) {
|
|
@@ -1797,7 +1855,7 @@ function splicedMember(text, key) {
|
|
|
1797
1855
|
}
|
|
1798
1856
|
/** 参数是「被切坏的 JSON」时的错误:说明形态,并把下一步写清楚。 */
|
|
1799
1857
|
function damagedArgumentsError(args, raw) {
|
|
1800
|
-
return
|
|
1858
|
+
return new CodemodeArgsError(invalidArgumentsError(args, raw).message + "; the payload looks damaged (embedded tool-call markup or a truncated JSON object) — resend one complete call with \"code\" holding the program source");
|
|
1801
1859
|
}
|
|
1802
1860
|
/** 从源码首行兜底出一句描述。 */
|
|
1803
1861
|
function descriptionFromCode(code) {
|
|
@@ -1910,16 +1968,18 @@ function readArguments(args) {
|
|
|
1910
1968
|
const code = codeOf(record);
|
|
1911
1969
|
if (code === void 0) throw missingCodeError(record, parsed.raw);
|
|
1912
1970
|
const description = stringOf(record["description"])?.trim() ?? stringOf(record["desc"])?.trim() ?? stringOf(record["summary"])?.trim() ?? parsed.narration?.title ?? descriptionFromCode(code);
|
|
1913
|
-
const escalation = validateEscalationArgs(record["sandbox_permissions"], record["justification"]);
|
|
1914
1971
|
const timeoutMs = record["timeoutMs"];
|
|
1915
1972
|
if (timeoutMs !== void 0) {
|
|
1916
|
-
if (typeof timeoutMs !== "number" || !Number.isFinite(timeoutMs) || timeoutMs <= 0) throw new
|
|
1973
|
+
if (typeof timeoutMs !== "number" || !Number.isFinite(timeoutMs) || timeoutMs <= 0) throw new CodemodeArgsError("codemode: invalid timeoutMs: expected a positive finite number");
|
|
1917
1974
|
}
|
|
1975
|
+
const rawSandboxPermissions = record["sandbox_permissions"];
|
|
1976
|
+
const rawJustification = record["justification"];
|
|
1918
1977
|
return {
|
|
1919
1978
|
code,
|
|
1920
1979
|
description,
|
|
1921
1980
|
...timeoutMs === void 0 ? {} : { timeoutMs },
|
|
1922
|
-
...
|
|
1981
|
+
...rawSandboxPermissions === void 0 ? {} : { rawSandboxPermissions },
|
|
1982
|
+
...rawJustification === void 0 ? {} : { rawJustification },
|
|
1923
1983
|
...parsed.narration === void 0 ? {} : { narration: parsed.narration }
|
|
1924
1984
|
};
|
|
1925
1985
|
}
|
|
@@ -3000,12 +3060,12 @@ function apply(ctx, config = {}) {
|
|
|
3000
3060
|
const escalateSandbox = async (input) => {
|
|
3001
3061
|
const record = typeof input.standingPolicy === "object" && input.standingPolicy !== null ? input.standingPolicy : void 0;
|
|
3002
3062
|
const effectiveMode = typeof record?.["mode"] === "string" ? record["mode"] : void 0;
|
|
3003
|
-
if (record === void 0 || effectiveMode === void 0) throw new
|
|
3063
|
+
if (record === void 0 || effectiveMode === void 0) throw new CodemodeArgsError("sandbox_permissions and justification are not available for this PTC runtime");
|
|
3004
3064
|
if (input.requestedMode === effectiveMode) return input.standingPolicy;
|
|
3005
|
-
if (!(WIDER_SANDBOX_MODES[effectiveMode] ?? []).includes(input.requestedMode)) throw new
|
|
3065
|
+
if (!(WIDER_SANDBOX_MODES[effectiveMode] ?? []).includes(input.requestedMode)) throw new SandboxEscalationError(`sandbox escalation to "${input.requestedMode}" is not strictly wider than this call's current "${effectiveMode}" mode`, "SANDBOX_ESCALATION_INVALID_ARGUMENT");
|
|
3006
3066
|
const approver = serviceOf("approval");
|
|
3007
|
-
if (typeof approver?.request !== "function") throw new
|
|
3008
|
-
if (input.agent === void 0) throw new
|
|
3067
|
+
if (typeof approver?.request !== "function") throw new SandboxEscalationError(`sandbox escalation to "${input.requestedMode}" requires approval, but no approval service is composed`, "SANDBOX_ESCALATION_UNAVAILABLE");
|
|
3068
|
+
if (input.agent === void 0) throw new SandboxEscalationError(`sandbox escalation to "${input.requestedMode}" requires approval, but the call has no agent to route it through`, "SANDBOX_ESCALATION_UNAVAILABLE");
|
|
3009
3069
|
const outcome = await approver.request({
|
|
3010
3070
|
agent: input.agent,
|
|
3011
3071
|
toolName: input.toolName,
|
|
@@ -3022,9 +3082,11 @@ function apply(ctx, config = {}) {
|
|
|
3022
3082
|
...record,
|
|
3023
3083
|
mode: input.requestedMode
|
|
3024
3084
|
};
|
|
3025
|
-
case "rejected": throw new
|
|
3026
|
-
case "cancelled":
|
|
3027
|
-
|
|
3085
|
+
case "rejected": throw new SandboxEscalationError(`the user rejected escalating this program to "${input.requestedMode}"; it stays denied, so stop and explain instead of working around it`, "SANDBOX_ESCALATION_REJECTED");
|
|
3086
|
+
case "cancelled":
|
|
3087
|
+
input.signal.throwIfAborted();
|
|
3088
|
+
throw new SandboxEscalationError(`approval for escalating to "${input.requestedMode}" was cancelled`, "SANDBOX_ESCALATION_CANCELLED");
|
|
3089
|
+
case "unavailable": throw new SandboxEscalationError(`sandbox escalation to "${input.requestedMode}" requires approval, but no approval channel is available`, "SANDBOX_ESCALATION_UNAVAILABLE");
|
|
3028
3090
|
default: throw new Error(`unexpected approval outcome: ${String(outcome)}`);
|
|
3029
3091
|
}
|
|
3030
3092
|
};
|
|
@@ -3049,7 +3111,10 @@ function apply(ctx, config = {}) {
|
|
|
3049
3111
|
if (!isImageAttachmentRefLike(attachment)) return void 0;
|
|
3050
3112
|
const resolveAccess = dshLlm["resolveImageAttachmentAccess"];
|
|
3051
3113
|
if (typeof resolveAccess === "function") try {
|
|
3052
|
-
const
|
|
3114
|
+
const attachments = serviceOf("attachments");
|
|
3115
|
+
const fsService = serviceOf("fs");
|
|
3116
|
+
const mapHostPath = typeof fsService?.processPathFromHostPath === "function" ? (hostPath) => fsService.processPathFromHostPath(hostPath) : void 0;
|
|
3117
|
+
const access = attachments !== void 0 && mapHostPath !== void 0 ? resolveAccess(attachments, mapHostPath, attachment) : resolveAccess.length <= 1 ? resolveAccess(attachment) : void 0;
|
|
3053
3118
|
if (typeof access?.readonlyPath === "string" && access.readonlyPath.length > 0) return new PtcImageLike(access.readonlyPath, attachment);
|
|
3054
3119
|
} catch {}
|
|
3055
3120
|
if (typeof fallbackPath === "string" && fallbackPath.length > 0) return new PtcImageLike(fallbackPath, attachment);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
1
|
+
import { HarnessError, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
2
2
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { Service } from "@deepseek-ai/cordis";
|
|
@@ -716,6 +716,31 @@ const APPROVE_LABEL = "Approve";
|
|
|
716
716
|
const KEEP_PLANNING_LABEL = "Keep planning";
|
|
717
717
|
/** 尾部通知消息的来源 kind(本包自有,见下方 MessageSourceMap 增补)。 */
|
|
718
718
|
const PLAN_NOTICE_SOURCE_KIND = "plan-mode-notice";
|
|
719
|
+
/** 计划模式结构化错误(基于全世代通用的 `HarnessError`)。 */
|
|
720
|
+
var PlanModeError = class extends HarnessError {
|
|
721
|
+
code;
|
|
722
|
+
constructor(message, code, options) {
|
|
723
|
+
super(message, code, options);
|
|
724
|
+
this.code = code;
|
|
725
|
+
this.name = "PlanModeError";
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
/** 与 `@deepseek-ai/dsh-tools` `ToolArgsError` 同码的结构化参数错误,不引入 `<0.2.x` 缺失的导出。 */
|
|
729
|
+
var PlanToolArgsError = class extends HarnessError {
|
|
730
|
+
violations;
|
|
731
|
+
constructor(message, violations) {
|
|
732
|
+
super(message, "INVALID_ARGS");
|
|
733
|
+
this.violations = violations;
|
|
734
|
+
this.name = "ToolArgsError";
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
/** 与 `@deepseek-ai/dsh-tools` `ToolContextUnavailableError` 同码的上下文缺失错误,不引入 `<0.2.x` 缺失的导出。 */
|
|
738
|
+
var PlanToolContextUnavailableError = class extends HarnessError {
|
|
739
|
+
constructor(message, options) {
|
|
740
|
+
super(message, "TOOL_CONTEXT_UNAVAILABLE", options);
|
|
741
|
+
this.name = "ToolContextUnavailableError";
|
|
742
|
+
}
|
|
743
|
+
};
|
|
719
744
|
/**
|
|
720
745
|
* 校验部署方配置。缺失、空白、类型不符与未知字段都在**挂载时**失败,而不是被忽略。
|
|
721
746
|
* @param config - 原始插件配置。
|
|
@@ -1325,11 +1350,12 @@ var PlanModeController = class extends Service {
|
|
|
1325
1350
|
async execute(args, exec) {
|
|
1326
1351
|
const execution = exec;
|
|
1327
1352
|
const agent = execution.agent;
|
|
1328
|
-
if (agent === void 0 || agent === null
|
|
1353
|
+
if (agent === void 0 || agent === null) throw new PlanToolContextUnavailableError("exit_plan_mode is only available in plan mode");
|
|
1354
|
+
if (!controller.loggedActive(agent.session)) throw new PlanModeError("exit_plan_mode is only available in plan mode", "PLAN_NOT_ACTIVE");
|
|
1329
1355
|
const plan = typeof args.plan === "string" ? args.plan : "";
|
|
1330
|
-
if (!/^#\s+\S/.test(plan.trim())) throw new
|
|
1356
|
+
if (!/^#\s+\S/.test(plan.trim())) throw new PlanToolArgsError("exit_plan_mode requires a non-empty markdown plan starting with a # heading", ["plan: exit_plan_mode requires a non-empty markdown plan starting with a # heading"]);
|
|
1331
1357
|
const interaction = serviceOf(ctx, "userQuestions");
|
|
1332
|
-
if (interaction === void 0 || typeof interaction.ask !== "function") throw new
|
|
1358
|
+
if (interaction === void 0 || typeof interaction.ask !== "function") throw new PlanToolContextUnavailableError("no user-questions channel is available to review the plan; ask the user to switch the session mode instead");
|
|
1333
1359
|
let answer;
|
|
1334
1360
|
try {
|
|
1335
1361
|
answer = await interaction.ask({
|
|
@@ -1360,16 +1386,16 @@ var PlanModeController = class extends Service {
|
|
|
1360
1386
|
execution.concludeTurn();
|
|
1361
1387
|
return { approved: false };
|
|
1362
1388
|
}
|
|
1363
|
-
throw new
|
|
1389
|
+
throw new PlanToolContextUnavailableError("the user dismissed the plan review and this harness generation cannot conclude the turn from a tool; present the plan again or switch the session mode instead");
|
|
1364
1390
|
}
|
|
1365
1391
|
throw cause;
|
|
1366
1392
|
}
|
|
1367
|
-
if (controller.disposed) throw new
|
|
1393
|
+
if (controller.disposed) throw new PlanModeError("the plan-mode service was reloaded while the plan was under review; present the plan again", "PLAN_REVIEW_INTERRUPTED");
|
|
1368
1394
|
const items = (answer?.answers ?? []).filter((entry) => entry.id === REVIEW_ID);
|
|
1369
1395
|
const item = items.length === 1 ? items[0] : void 0;
|
|
1370
1396
|
if (item?.selected.length !== 1 || item.selected[0] !== "Approve" || item.custom !== void 0) {
|
|
1371
1397
|
const feedback = typeof item?.custom === "string" ? item.custom : "";
|
|
1372
|
-
throw new
|
|
1398
|
+
throw new PlanModeError(feedback === "" ? "The user chose to keep planning; revise the plan and present it again." : "The user chose to keep planning; their feedback: " + feedback, "PLAN_REVISION_REQUESTED");
|
|
1373
1399
|
}
|
|
1374
1400
|
const key = objectKey(agent.session);
|
|
1375
1401
|
if (key !== void 0) controller.pendingIntents.set(key, {
|
|
@@ -1814,4 +1840,4 @@ function createPlanNotice(text, section, summary) {
|
|
|
1814
1840
|
});
|
|
1815
1841
|
}
|
|
1816
1842
|
//#endregion
|
|
1817
|
-
export {
|
|
1843
|
+
export { resolveDispatchExecutionGuardEnabled as S, name as _, PLAN_EXIT_REMINDER_TEXT as a, resolveConfig as b, PLAN_POLICY_SECTION as c, PlanModeController as d, PlanModeError as f, installPlanModeExitReminder as g, createPlanProjectionDefinition as h, LEGACY_PLAN_STATE_VERSION as i, PLAN_PROJECTION_KEY as l, createPlanNotice as m, EXIT_PLAN_MODE as n, PLAN_MODE_EVENT as o, REVIEW_ID as p, KEEP_PLANNING_LABEL as r, PLAN_NOTICE_SOURCE_KIND as s, APPROVE_LABEL as t, PLAN_STATE_VERSION as u, planProjectionDefinition as v, installDispatchExecutionGuard as x, registeredPlanControllerActive as y };
|