@eddyskywalker/dsh-chatgpt-subscription 1.0.0 → 1.1.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.
Files changed (58) hide show
  1. package/lib/client.js +92 -11
  2. package/lib/client.js.map +1 -1
  3. package/lib/codemode.js +139 -7
  4. package/lib/index.js +545 -90
  5. package/lib/{preset-sync-DWOAwSyl.js → preset-sync-RBsYhDY3.js} +2 -1
  6. package/lib/{tool-result-pruner-C6CDvZtG.js → tool-result-pruner-DsaDg_l1.js} +4 -3
  7. package/lib/tool-result-pruner.js +1 -1
  8. package/lib/types/client/features/progress-updates/locales.d.ts +3 -3
  9. package/lib/types/client/features/progress-updates/settings-section.d.ts +2 -2
  10. package/lib/types/client/locales-ru/qoder.d.ts.map +1 -1
  11. package/lib/types/client/providers/qoder/QoderComposerQuota.d.ts.map +1 -1
  12. package/lib/types/client/providers/qoder/QoderSection.d.ts.map +1 -1
  13. package/lib/types/client/providers/qoder/locales.d.ts +7 -1
  14. package/lib/types/client/providers/qoder/locales.d.ts.map +1 -1
  15. package/lib/types/client/providers/qoder/styles.d.ts.map +1 -1
  16. package/lib/types/client/providers/qoder/useQoderSection.d.ts +15 -0
  17. package/lib/types/client/providers/qoder/useQoderSection.d.ts.map +1 -1
  18. package/lib/types/compat.d.ts +1 -1
  19. package/lib/types/entries/tool-result-pruner.d.ts.map +1 -1
  20. package/lib/types/host/providers/antigravity-acp/adapter.d.ts.map +1 -1
  21. package/lib/types/host/providers/qoder/account-affinity.d.ts +16 -0
  22. package/lib/types/host/providers/qoder/account-affinity.d.ts.map +1 -0
  23. package/lib/types/host/providers/qoder/account-pool.d.ts +4 -2
  24. package/lib/types/host/providers/qoder/account-pool.d.ts.map +1 -1
  25. package/lib/types/host/providers/qoder/adapter.d.ts +15 -0
  26. package/lib/types/host/providers/qoder/adapter.d.ts.map +1 -1
  27. package/lib/types/host/providers/qoder/cache-diagnostics.d.ts +20 -0
  28. package/lib/types/host/providers/qoder/cache-diagnostics.d.ts.map +1 -0
  29. package/lib/types/host/providers/qoder/cosy.d.ts +12 -5
  30. package/lib/types/host/providers/qoder/cosy.d.ts.map +1 -1
  31. package/lib/types/host/providers/qoder/mapper.d.ts +15 -0
  32. package/lib/types/host/providers/qoder/mapper.d.ts.map +1 -1
  33. package/lib/types/host/providers/qoder/model-catalog.d.ts +18 -0
  34. package/lib/types/host/providers/qoder/model-catalog.d.ts.map +1 -1
  35. package/lib/types/host/providers/qoder/queue-state.d.ts +8 -1
  36. package/lib/types/host/providers/qoder/queue-state.d.ts.map +1 -1
  37. package/lib/types/host/providers/qoder/traffic-guard.d.ts +13 -0
  38. package/lib/types/host/providers/qoder/traffic-guard.d.ts.map +1 -0
  39. package/lib/types/host/providers/qoder/types.d.ts +6 -6
  40. package/lib/types/host/providers/qoder/types.d.ts.map +1 -1
  41. package/lib/types/host/runtime/advisor/catalog-route.d.ts +20 -0
  42. package/lib/types/host/runtime/advisor/catalog-route.d.ts.map +1 -0
  43. package/lib/types/host/runtime/advisor/index.d.ts.map +1 -1
  44. package/lib/types/host/runtime/advisor/selection-store.d.ts +9 -1
  45. package/lib/types/host/runtime/advisor/selection-store.d.ts.map +1 -1
  46. package/lib/types/host/runtime/codemode/rules.d.ts.map +1 -1
  47. package/lib/types/host/runtime/codemode/transport.d.ts +5 -0
  48. package/lib/types/host/runtime/codemode/transport.d.ts.map +1 -1
  49. package/lib/types/host/runtime/deepseek-v41-flash/state-anchor.d.ts +8 -0
  50. package/lib/types/host/runtime/deepseek-v41-flash/state-anchor.d.ts.map +1 -1
  51. package/lib/types/host/runtime/open-models/profiles.d.ts.map +1 -1
  52. package/lib/types/host/runtime/open-models/state-anchor.d.ts.map +1 -1
  53. package/lib/types/index.d.ts.map +1 -1
  54. package/lib/types/shared/advisor-contracts.d.ts +9 -2
  55. package/lib/types/shared/advisor-contracts.d.ts.map +1 -1
  56. package/lib/types/shared/qoder-contracts.d.ts +30 -1
  57. package/lib/types/shared/qoder-contracts.d.ts.map +1 -1
  58. package/package.json +2 -2
package/lib/codemode.js CHANGED
@@ -1,4 +1,4 @@
1
- import { c as PLUGIN_MESSAGE_SOURCE_KIND, t as candidatePackageRoots } from "./preset-sync-DWOAwSyl.js";
1
+ import { c as PLUGIN_MESSAGE_SOURCE_KIND, t as candidatePackageRoots } from "./preset-sync-RBsYhDY3.js";
2
2
  import { createRequire } from "node:module";
3
3
  import * as dshLlm from "@deepseek-ai/dsh-llm";
4
4
  import { HarnessError, createUserMessage } from "@deepseek-ai/dsh-llm";
@@ -655,6 +655,7 @@ function buildCodemodeSectionText(input) {
655
655
  !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.",
656
656
  "- 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):",
657
657
  " `read` → `{ path, offset, lines: [{ number, text }], totalLines }` · `glob` → `{ root, paths }` · `grep` → `{ matches: [{ path, lineNumber, line }] }` · `edit` → `{ path, before, after }` · `write` → `{ path, operation, before, after }` · `bash` / `pwsh` → foreground `{ kind, cwd, exitCode, stdout: { text, truncated }, stderr: { text, truncated } }` (background/promoted variants also exist) · `win_bash` → `{ exitCode, stdout, stderr }` with plain-string streams · `web_fetch` → `{ url, statusCode, body, truncated }` · `job_output` → `{ text, job }` · `read_image` → `{ path, image }` · `skill` → `{ name, content }` · `subagent` → `{ kind, name }`.",
658
+ "- When a result is marked `truncated: true`, its text is an incomplete prefix: do not `JSON.parse` it as a complete payload; fetch a narrower URL, page the endpoint, or request a smaller representation.",
658
659
  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.",
659
660
  "- 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.",
660
661
  "- 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? }`.",
@@ -1047,7 +1048,7 @@ function currentCatalogSnapshot() {
1047
1048
  /** 传输工具名(与 {@link DEFAULT_RUN_TOOL_NAME} 一致,导出方便测试引用)。 */
1048
1049
  const TRANSPORT_TOOL_NAME = "code_run";
1049
1050
  const TRANSPORT_TOOL_TIMEOUT_MS = 6e5;
1050
- const ADVISOR_CALL_PATTERN = /\btools\s*\.\s*consult_advisor\s*\(/;
1051
+ const ADVISOR_CALL_PATTERN = /\bconsult_advisor\b/;
1051
1052
  /** 进展汇报工具名:融合参数里救回来的简报用它补发。 */
1052
1053
  const PROGRESS_UPDATE_TOOL = "progress_update";
1053
1054
  /** 允许单次提权的目标沙箱模式(对齐 `@deepseek-ai/dsh-sandbox` 的 `ESCALATION_TARGETS`)。 */
@@ -1337,6 +1338,15 @@ function createTransportDefinition(host, rules) {
1337
1338
  return [...inspection.blocks];
1338
1339
  },
1339
1340
  presentCall(args) {
1341
+ const directShell = directShellCallOf(args);
1342
+ if (directShell !== void 0) {
1343
+ const command = stringOf(directShell.record["command"]) ?? "";
1344
+ return {
1345
+ card: "generic",
1346
+ title: directShell.description ?? descriptionFromCode(command),
1347
+ kind: "execute"
1348
+ };
1349
+ }
1340
1350
  try {
1341
1351
  const input = readArguments(args);
1342
1352
  return {
@@ -1350,7 +1360,8 @@ function createTransportDefinition(host, rules) {
1350
1360
  }
1351
1361
  },
1352
1362
  async execute(args, exec) {
1353
- const input = readArguments(args);
1363
+ const directShell = directShellCallOf(args);
1364
+ const input = directShell === void 0 ? readArguments(args) : readShellArguments(directShell);
1354
1365
  const runtime = host.runtime();
1355
1366
  if (runtime === void 0) throw new CodemodeContextUnavailableError("codemode: no PTC runtime is mounted (ctx.ptcRuntime); the program transport is unavailable");
1356
1367
  if (input.timeoutMs !== void 0 && runtime.timeout !== void 0 === false && isStrictTimeoutUnsupported(runtime)) throw new CodemodeArgsError("timeoutMs is not available for this PTC runtime");
@@ -1359,6 +1370,12 @@ function createTransportDefinition(host, rules) {
1359
1370
  const prevalidatedEscalation = hasRawEscalation && runtime.sandboxMode !== void 0 ? validateEscalationArgs(input.rawSandboxPermissions, input.rawJustification) : void 0;
1360
1371
  await host.awaitPredecessors?.(exec.agent, exec.signal);
1361
1372
  const catalog = host.catalog(exec.agent, exec.toolStep ?? exec.toolSet);
1373
+ let code = input.code;
1374
+ if (directShell !== void 0) {
1375
+ const shell = shellToolOf(catalog);
1376
+ if (shell === void 0) throw missingCodeError(directShell.record, directShell.raw);
1377
+ code = shellProgramFor(shell, directShell.record);
1378
+ }
1362
1379
  const runController = new AbortController();
1363
1380
  const onOuterAbort = () => {
1364
1381
  runController.abort(exec.signal.reason);
@@ -1505,7 +1522,7 @@ function createTransportDefinition(host, rules) {
1505
1522
  controller: runController,
1506
1523
  signal: nestedSignal
1507
1524
  }) ?? (() => {});
1508
- const sanitizedCode = sanitizeReplTopLevelReturn(input.code, runtime.programFormat, runtime.language);
1525
+ const sanitizedCode = sanitizeReplTopLevelReturn(code, runtime.programFormat, runtime.language);
1509
1526
  const attempt = async () => {
1510
1527
  deferredProgramImages.length = 0;
1511
1528
  const authority = await host.runAuthority?.(exec.agent, nestedSignal);
@@ -1549,7 +1566,7 @@ function createTransportDefinition(host, rules) {
1549
1566
  signal: nestedSignal,
1550
1567
  mode: runMode
1551
1568
  }) ?? untrackRun;
1552
- const timeoutMs = input.timeoutMs ?? (ADVISOR_CALL_PATTERN.test(sanitizedCode) ? 305e3 : void 0);
1569
+ const timeoutMs = input.timeoutMs ?? (ADVISOR_CALL_PATTERN.test(sanitizedCode) ? 6e5 : void 0);
1553
1570
  const request = {
1554
1571
  program: sanitizedCode,
1555
1572
  bindings: [{
@@ -1894,6 +1911,27 @@ const CODE_KEYS = Object.freeze([
1894
1911
  "program_source",
1895
1912
  "programSource"
1896
1913
  ]);
1914
+ /** 模型把 Shell 工具入参直接发给 `code_run` 时可能出现的键。 */
1915
+ const SHELL_ARG_KEYS = /* @__PURE__ */ new Set([
1916
+ "command",
1917
+ "workdir",
1918
+ "cwd",
1919
+ "workingDirectory",
1920
+ "working_directory",
1921
+ "timeoutMs",
1922
+ "timeout_ms",
1923
+ "run_in_background",
1924
+ "runInBackground",
1925
+ "description",
1926
+ "desc",
1927
+ "summary"
1928
+ ]);
1929
+ /** 可接住直接 Shell 调用的工具名;顺序即同场竞争时的优先级。 */
1930
+ const SHELL_TOOL_NAMES = Object.freeze([
1931
+ "win_bash",
1932
+ "bash",
1933
+ "pwsh"
1934
+ ]);
1897
1935
  /** 模型把「先汇报再执行」写成一次调用时,简报落在 `progress_update` 的那两个键上。 */
1898
1936
  const NARRATION_TITLE_KEY = "title";
1899
1937
  /** 见 {@link NARRATION_TITLE_KEY}。 */
@@ -1954,12 +1992,20 @@ function topLevelJsonObjects(text) {
1954
1992
  }
1955
1993
  return fragments;
1956
1994
  }
1957
- /** 从一个参数对象里读出程序源码。 */
1995
+ /**
1996
+ * 从一个参数对象里读出程序源码。
1997
+ *
1998
+ * `content` 是模型把「写文件」参数误发进 `code_run` 时最常见的键,但也可能真的是
1999
+ * 文件正文。只有它明显像一段程序时才当源码,否则留给调用方报参数错误,绝不执行
2000
+ * 一段普通文本。
2001
+ */
1958
2002
  function codeOf(record) {
1959
2003
  for (const key of CODE_KEYS) {
1960
2004
  const value = record[key];
1961
2005
  if (typeof value === "string" && value.trim().length > 0) return value;
1962
2006
  }
2007
+ const content = record["content"];
2008
+ if (typeof content === "string" && content.trim().length > 0 && looksLikeProgram(content) && /\b(?:tools\.|await\s|inspect\s*\(|return\b|const\b|let\b|import\s)/.test(content)) return content;
1963
2009
  }
1964
2010
  /** 从一个参数对象里读出进展简报(`title` / `message` 至少有一个)。 */
1965
2011
  function narrationOf(record) {
@@ -1993,6 +2039,73 @@ function missingCodeError(record, raw) {
1993
2039
  const keys = Object.keys(record);
1994
2040
  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\")"));
1995
2041
  }
2042
+ /**
2043
+ * 认出「Shell 工具参数被直接发进 code_run」的形态。
2044
+ *
2045
+ * 审计(session-4ad29c19 turn 后期,约 37 万 token):模型连续 11 次把
2046
+ * `description`/`command`/`workdir` 直接发给 `code_run`,即使错误已要求程序源码,
2047
+ * 下一步仍重复同一形状。这里只接受字段集合完全吻合、且可选键类型正确的壳状参数;
2048
+ * 多一个陌生键就交给原来的拒绝路径,绝不把畸形对象猜成命令。
2049
+ *
2050
+ * @param args - 工具收到的原始参数。
2051
+ * @returns 壳状调用;不像时返回 `undefined`。
2052
+ */
2053
+ function directShellCallOf(args) {
2054
+ let parsed;
2055
+ try {
2056
+ parsed = parseArguments(args);
2057
+ } catch {
2058
+ return;
2059
+ }
2060
+ const record = parsed.record;
2061
+ if (codeOf(record) !== void 0) return void 0;
2062
+ if (stringOf(record["command"]) === void 0) return void 0;
2063
+ const keys = Object.keys(record);
2064
+ if (keys.length === 0 || keys.some((key) => !SHELL_ARG_KEYS.has(key))) return void 0;
2065
+ for (const key of [
2066
+ "workdir",
2067
+ "cwd",
2068
+ "workingDirectory",
2069
+ "working_directory"
2070
+ ]) if (record[key] !== void 0 && typeof record[key] !== "string") return void 0;
2071
+ for (const key of ["timeoutMs", "timeout_ms"]) {
2072
+ const value = record[key];
2073
+ if (value !== void 0 && (typeof value !== "number" || !Number.isFinite(value) || value <= 0)) return void 0;
2074
+ }
2075
+ for (const key of ["run_in_background", "runInBackground"]) if (record[key] !== void 0 && typeof record[key] !== "boolean") return void 0;
2076
+ const description = stringOf(record["description"])?.trim() ?? stringOf(record["desc"])?.trim() ?? stringOf(record["summary"])?.trim();
2077
+ return {
2078
+ record,
2079
+ ...description === void 0 ? {} : { description },
2080
+ raw: parsed.raw
2081
+ };
2082
+ }
2083
+ /** 在工具清单里挑一个能承接 Shell 参数的工具。 */
2084
+ function shellToolOf(catalog) {
2085
+ for (const name of SHELL_TOOL_NAMES) {
2086
+ const entry = catalog.find((candidate) => candidate.name === name);
2087
+ if (entry !== void 0) return entry;
2088
+ }
2089
+ }
2090
+ /** 把壳状参数包成一条调用真实 Shell 工具的程序。 */
2091
+ function shellProgramFor(entry, record) {
2092
+ const workdir = record["workdir"] ?? record["cwd"] ?? record["workingDirectory"] ?? record["working_directory"];
2093
+ const timeoutMs = record["timeoutMs"] ?? record["timeout_ms"];
2094
+ const runInBackground = record["run_in_background"] ?? record["runInBackground"];
2095
+ const args = { command: record["command"] };
2096
+ if (workdir !== void 0) args["workdir"] = workdir;
2097
+ if (timeoutMs !== void 0) args["timeoutMs"] = timeoutMs;
2098
+ if (runInBackground !== void 0) args["run_in_background"] = runInBackground;
2099
+ return "return await tools." + entry.name + "(" + JSON.stringify(args) + ")";
2100
+ }
2101
+ /** 把壳状调用读成程序传输的标题(真正源码要等工具清单才能生成)。 */
2102
+ function readShellArguments(direct) {
2103
+ const command = stringOf(direct.record["command"]) ?? "";
2104
+ return {
2105
+ code: "",
2106
+ description: direct.description ?? descriptionFromCode(command)
2107
+ };
2108
+ }
1996
2109
  /** 一段文本像不像程序源码(模型把源码直接发成字符串时判这个)。 */
1997
2110
  function looksLikeProgram(text) {
1998
2111
  return text.includes("\n") || /\b(await|return|const|let|function|import|console\.)\b/.test(text);
@@ -2454,10 +2567,15 @@ const SEARCH_PATH_TOOLS = /* @__PURE__ */ new Set(["glob", "grep"]);
2454
2567
  * @returns 归一化后的参数值。
2455
2568
  */
2456
2569
  function normalizeSubCallArgs(entry, value) {
2570
+ if (entry?.name === "apply_patch" && typeof value === "string" && value.trim().length > 0) return { input: value };
2457
2571
  if (!isRecord(value)) return value;
2458
2572
  const name = entry?.name ?? "";
2459
- const schemaProps = isRecord(entry?.parameters) && isRecord(entry.parameters.properties) ? entry.parameters.properties : void 0;
2573
+ const rawParameters = isRecord(entry?.parameters) ? entry.parameters : void 0;
2574
+ const nestedProperties = isRecord(rawParameters?.["properties"]) ? rawParameters["properties"] : void 0;
2575
+ const schemaProps = nestedProperties ?? rawParameters;
2576
+ const required = nestedProperties !== void 0 ? Array.isArray(rawParameters?.["required"]) ? rawParameters["required"].filter((key) => typeof key === "string") : void 0 : schemaProps === void 0 ? void 0 : Object.entries(schemaProps).filter(([, spec]) => isRecord(spec) && spec["required"] === true).map(([key]) => key);
2460
2577
  const declares = (key) => schemaProps !== void 0 && Object.prototype.hasOwnProperty.call(schemaProps, key);
2578
+ const requires = (key) => required?.includes(key) === true;
2461
2579
  const out = { ...value };
2462
2580
  const remap = (target, aliases, predicate) => {
2463
2581
  if (out[target] !== void 0) return;
@@ -2481,6 +2599,19 @@ function normalizeSubCallArgs(entry, value) {
2481
2599
  remap("new_string", ["newString"], isString);
2482
2600
  remap("replace_all", ["replaceAll"], isBoolean);
2483
2601
  }
2602
+ if (name === "apply_patch" || declares("input")) remap("input", ["patch", "diff"], isString);
2603
+ if (name === "web_search" || declares("queries")) {
2604
+ if (out["queries"] === void 0 && !declares("query")) {
2605
+ const query = out["query"];
2606
+ if (typeof query === "string" && query.trim().length > 0) {
2607
+ out["queries"] = [query];
2608
+ delete out["query"];
2609
+ } else if (Array.isArray(query) && query.every((item) => typeof item === "string")) {
2610
+ out["queries"] = query;
2611
+ delete out["query"];
2612
+ }
2613
+ }
2614
+ }
2484
2615
  if (name === "win_bash" || declares("workdir")) {
2485
2616
  remap("workdir", [
2486
2617
  "cwd",
@@ -2494,6 +2625,7 @@ function normalizeSubCallArgs(entry, value) {
2494
2625
  remap("job_id", ["jobId"], isString);
2495
2626
  if (name === "job_output" || declares("timeout_ms")) remap("timeout_ms", ["timeoutMs"], isNumber);
2496
2627
  }
2628
+ if (requires("description") && out["description"] === void 0 && typeof out["command"] === "string") out["description"] = descriptionFromCode(out["command"]);
2497
2629
  return out;
2498
2630
  }
2499
2631
  /** 一个工具的调用是否可以与兄弟调用重叠(只有明确 true 才算)。 */