@eddyskywalker/dsh-chatgpt-subscription 0.90.2 → 0.91.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/lib/client.js +536 -184
- package/lib/client.js.map +1 -1
- package/lib/codemode.js +376 -76
- package/lib/index.js +2379 -1503
- package/lib/{plan-mode-CoublSCJ.js → plan-mode-cY8pp0PZ.js} +1 -1
- package/lib/{plan-mode-pipeline-DvVmLaxR.js → plan-mode-pipeline-DQ8TM6mP.js} +21 -18
- package/lib/plan-mode-pipeline.js +1 -1
- package/lib/plan-mode.js +1 -1
- package/lib/{preset-sync-B9yKbQPc.js → preset-sync-gvhSzmlr.js} +44 -1
- package/lib/{progress-updates-DwpfBXOx.js → progress-updates-jiHnSAmz.js} +12 -1
- package/lib/progress-updates.js +1 -1
- package/lib/{tool-result-pruner-Dy6X17gv.js → tool-result-pruner-Baz9Lrov.js} +85 -41
- package/lib/tool-result-pruner.js +1 -1
- package/lib/types/client/features/subagent/SubagentCard.d.ts.map +1 -1
- package/lib/types/client/features/subagent/locales.d.ts +11 -2
- package/lib/types/client/features/subagent/locales.d.ts.map +1 -1
- package/lib/types/client/features/subagent/styles.d.ts +1 -1
- package/lib/types/client/features/subagent/styles.d.ts.map +1 -1
- package/lib/types/client/features/subagent/subagent-card-controller.d.ts +13 -0
- package/lib/types/client/features/subagent/subagent-card-controller.d.ts.map +1 -1
- package/lib/types/client/locales-ru/claude-api.d.ts.map +1 -1
- package/lib/types/client/locales-ru/claude.d.ts.map +1 -1
- package/lib/types/client/providers/claude/ClaudeSection.d.ts.map +1 -1
- package/lib/types/client/providers/claude/locales.d.ts +8 -2
- package/lib/types/client/providers/claude/locales.d.ts.map +1 -1
- package/lib/types/client/providers/claude/useClaudeSection.d.ts +1 -0
- package/lib/types/client/providers/claude/useClaudeSection.d.ts.map +1 -1
- package/lib/types/client/providers/claude-api/ClaudeApiSection.d.ts.map +1 -1
- package/lib/types/client/providers/claude-api/api.d.ts +4 -2
- package/lib/types/client/providers/claude-api/api.d.ts.map +1 -1
- package/lib/types/client/providers/claude-api/locales.d.ts +87 -5
- package/lib/types/client/providers/claude-api/locales.d.ts.map +1 -1
- package/lib/types/client/providers/claude-api/styles.d.ts.map +1 -1
- package/lib/types/client/providers/claude-api/useClaudeApiSection.d.ts +16 -7
- package/lib/types/client/providers/claude-api/useClaudeApiSection.d.ts.map +1 -1
- package/lib/types/compat.d.ts +1 -1
- package/lib/types/entries/codemode.d.ts.map +1 -1
- package/lib/types/entries/plan-mode-pipeline.d.ts.map +1 -1
- package/lib/types/host/common/llm-compat.d.ts +14 -0
- package/lib/types/host/common/llm-compat.d.ts.map +1 -1
- package/lib/types/host/providers/claude/routes.d.ts.map +1 -1
- package/lib/types/host/providers/claude/token-store.d.ts +3 -0
- package/lib/types/host/providers/claude/token-store.d.ts.map +1 -1
- package/lib/types/host/providers/claude-api/account-pool.d.ts +44 -0
- package/lib/types/host/providers/claude-api/account-pool.d.ts.map +1 -0
- package/lib/types/host/providers/claude-api/adapter.d.ts +10 -2
- package/lib/types/host/providers/claude-api/adapter.d.ts.map +1 -1
- package/lib/types/host/providers/claude-api/catalog-manager.d.ts +3 -2
- package/lib/types/host/providers/claude-api/catalog-manager.d.ts.map +1 -1
- package/lib/types/host/providers/claude-api/routes.d.ts +3 -7
- package/lib/types/host/providers/claude-api/routes.d.ts.map +1 -1
- package/lib/types/host/providers/claude-api/token-store.d.ts +4 -0
- package/lib/types/host/providers/claude-api/token-store.d.ts.map +1 -1
- package/lib/types/host/providers/cline-pass/adapter.d.ts.map +1 -1
- package/lib/types/host/providers/glm-coding-plan/adapter.d.ts.map +1 -1
- package/lib/types/host/providers/glm-coding-plan/mapper-anthropic.d.ts +1 -1
- package/lib/types/host/providers/glm-coding-plan/mapper-anthropic.d.ts.map +1 -1
- package/lib/types/host/providers/glm-coding-plan/mapper-openai.d.ts.map +1 -1
- package/lib/types/host/providers/glm-coding-plan/model-catalog.d.ts.map +1 -1
- package/lib/types/host/providers/minimax-code/adapter.d.ts.map +1 -1
- package/lib/types/host/providers/opendesign/adapter.d.ts.map +1 -1
- package/lib/types/host/providers/qianwen-token-plan/adapter.d.ts.map +1 -1
- package/lib/types/host/providers/step-code/adapter.d.ts.map +1 -1
- package/lib/types/host/runtime/cache-warmup/install.d.ts.map +1 -1
- package/lib/types/host/runtime/cache-warmup/retrieval-intent.d.ts.map +1 -1
- package/lib/types/host/runtime/codemode/executor.d.ts +50 -0
- package/lib/types/host/runtime/codemode/executor.d.ts.map +1 -1
- package/lib/types/host/runtime/codemode/transport.d.ts +6 -2
- package/lib/types/host/runtime/codemode/transport.d.ts.map +1 -1
- package/lib/types/host/runtime/compact-after-turn/index.d.ts +34 -3
- package/lib/types/host/runtime/compact-after-turn/index.d.ts.map +1 -1
- package/lib/types/host/runtime/deepseek-v41-flash/index.d.ts +2 -2
- package/lib/types/host/runtime/deepseek-v41-flash/index.d.ts.map +1 -1
- package/lib/types/host/runtime/deepseek-v41-flash/observation-tagger.d.ts.map +1 -1
- package/lib/types/host/runtime/deepseek-v41-flash/state-anchor.d.ts +17 -3
- package/lib/types/host/runtime/deepseek-v41-flash/state-anchor.d.ts.map +1 -1
- package/lib/types/host/runtime/guards/compaction-policy-guard.d.ts.map +1 -1
- package/lib/types/host/runtime/guards/plan-mode-cache-guard.d.ts.map +1 -1
- package/lib/types/host/runtime/guards/ptc-sdk-cache-guard.d.ts.map +1 -1
- package/lib/types/host/runtime/guards/subagent-model-authorization.d.ts +11 -3
- package/lib/types/host/runtime/guards/subagent-model-authorization.d.ts.map +1 -1
- package/lib/types/host/runtime/guards/subagent-route-audit.d.ts +0 -11
- package/lib/types/host/runtime/guards/subagent-route-audit.d.ts.map +1 -1
- package/lib/types/host/runtime/guards/team-policy-cache-guard.d.ts +2 -0
- package/lib/types/host/runtime/guards/team-policy-cache-guard.d.ts.map +1 -1
- package/lib/types/host/runtime/guards/timeline-cache-guard.d.ts.map +1 -1
- package/lib/types/host/runtime/open-models/index.d.ts +2 -2
- package/lib/types/host/runtime/open-models/index.d.ts.map +1 -1
- package/lib/types/host/runtime/open-models/observation-guard.d.ts.map +1 -1
- package/lib/types/host/runtime/open-models/profiles.d.ts +10 -2
- package/lib/types/host/runtime/open-models/profiles.d.ts.map +1 -1
- package/lib/types/host/runtime/open-models/state-anchor.d.ts +3 -0
- package/lib/types/host/runtime/open-models/state-anchor.d.ts.map +1 -1
- package/lib/types/host/runtime/presets/agent-preset.d.ts +12 -7
- package/lib/types/host/runtime/presets/agent-preset.d.ts.map +1 -1
- package/lib/types/host/runtime/progress-updates/index.d.ts.map +1 -1
- package/lib/types/index.d.ts +3 -2
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/shared/claude-api-contracts.d.ts +18 -0
- package/lib/types/shared/claude-api-contracts.d.ts.map +1 -1
- package/lib/types/shared/claude-contracts.d.ts +3 -0
- package/lib/types/shared/claude-contracts.d.ts.map +1 -1
- package/package.json +56 -52
- package/presets/dispatch/agent.cordis.yml +5 -4
package/lib/codemode.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { a as PLUGIN_MESSAGE_SOURCE_KIND, t as candidatePackageRoots } from "./preset-sync-
|
|
1
|
+
import { a as PLUGIN_MESSAGE_SOURCE_KIND, t as candidatePackageRoots } from "./preset-sync-gvhSzmlr.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";
|
|
5
5
|
import { dirname, join, resolve } from "node:path";
|
|
6
6
|
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
7
7
|
import { pathToFileURL } from "node:url";
|
|
8
|
-
import { NativeToolExecutor } from "@deepseek-ai/dsh-tool-executor-native";
|
|
9
8
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10
9
|
//#region src/host/runtime/codemode/discovery.ts
|
|
11
10
|
/**
|
|
@@ -889,6 +888,120 @@ function sectionOrderOf(ctx) {
|
|
|
889
888
|
return 5e3;
|
|
890
889
|
}
|
|
891
890
|
}
|
|
891
|
+
/**
|
|
892
|
+
* 造一个面向 DSH 0.2.3-alpha.3+ `ctx.tools.setRoot()` 的 Code Mode 根注册表。
|
|
893
|
+
*
|
|
894
|
+
* - `include(registrations)` 接收 `ctx.tools` 自动注入的未遮蔽注册表视图;
|
|
895
|
+
* - `get()` / `getAll()` 仅暴露原生白名单与传输工具,模型直呼被遮蔽工具时由内核自动以
|
|
896
|
+
* `UNKNOWN_TOOL` 拒绝;
|
|
897
|
+
* - `bindings()` / `binding()` 向程序传输层暴露完整未遮蔽绑定,并按 `ToolStep` 钉死步骤视图。
|
|
898
|
+
*/
|
|
899
|
+
function createCodemodeRootRegistry(rules, hooks) {
|
|
900
|
+
const own = /* @__PURE__ */ new Map();
|
|
901
|
+
const sources = [];
|
|
902
|
+
const stepBindings = /* @__PURE__ */ new WeakMap();
|
|
903
|
+
const resolveRaw = (name, scope) => {
|
|
904
|
+
const direct = own.get(name);
|
|
905
|
+
if (direct !== void 0) return direct;
|
|
906
|
+
for (const source of sources) {
|
|
907
|
+
const found = source.get(name, scope);
|
|
908
|
+
if (found !== void 0) return found;
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
const resolveAllRaw = (scope) => {
|
|
912
|
+
const out = [...own.values()];
|
|
913
|
+
for (const source of sources) {
|
|
914
|
+
const entries = source.getAll(scope);
|
|
915
|
+
if (Array.isArray(entries)) for (const entry of entries) out.push(entry);
|
|
916
|
+
}
|
|
917
|
+
return out;
|
|
918
|
+
};
|
|
919
|
+
const dedupeBindings = (list) => {
|
|
920
|
+
const map = /* @__PURE__ */ new Map();
|
|
921
|
+
for (const entry of list) {
|
|
922
|
+
const name = nameOf(entry);
|
|
923
|
+
if (name === void 0 || map.has(name)) continue;
|
|
924
|
+
map.set(name, entry);
|
|
925
|
+
}
|
|
926
|
+
return map;
|
|
927
|
+
};
|
|
928
|
+
const ensureStepBindings = (toolStep, fallbackScope) => {
|
|
929
|
+
let declared = stepBindings.get(toolStep);
|
|
930
|
+
if (declared === void 0) {
|
|
931
|
+
const stepAgent = toolStep.agent;
|
|
932
|
+
declared = dedupeBindings(resolveAllRaw(typeof stepAgent === "object" && stepAgent !== null ? stepAgent : fallbackScope));
|
|
933
|
+
stepBindings.set(toolStep, declared);
|
|
934
|
+
}
|
|
935
|
+
return declared;
|
|
936
|
+
};
|
|
937
|
+
const sourceView = { get: (name, scope) => resolveRaw(name, scope) };
|
|
938
|
+
return {
|
|
939
|
+
sourceView,
|
|
940
|
+
register(tool) {
|
|
941
|
+
const toolName = nameOf(tool);
|
|
942
|
+
if (toolName === void 0) return () => {};
|
|
943
|
+
if (own.has(toolName)) throw new Error(`tool "${toolName}" is already registered in codemode root registry`);
|
|
944
|
+
own.set(toolName, tool);
|
|
945
|
+
return () => {
|
|
946
|
+
if (own.get(toolName) === tool) own.delete(toolName);
|
|
947
|
+
};
|
|
948
|
+
},
|
|
949
|
+
include(source) {
|
|
950
|
+
sources.push(source);
|
|
951
|
+
return () => {
|
|
952
|
+
const index = sources.indexOf(source);
|
|
953
|
+
if (index >= 0) sources.splice(index, 1);
|
|
954
|
+
};
|
|
955
|
+
},
|
|
956
|
+
get(name, scope) {
|
|
957
|
+
const raw = resolveRaw(name, scope);
|
|
958
|
+
if (raw === void 0) return void 0;
|
|
959
|
+
if (rules.options.guard && name !== rules.options.runToolName) {
|
|
960
|
+
if (isMaskedName(name, rules, hooks.viewForName(name, sourceView))) return void 0;
|
|
961
|
+
}
|
|
962
|
+
return raw;
|
|
963
|
+
},
|
|
964
|
+
getAll(scope) {
|
|
965
|
+
const all = resolveAllRaw(scope);
|
|
966
|
+
hooks.onCatalog?.(all);
|
|
967
|
+
const names = [];
|
|
968
|
+
for (const tool of all) {
|
|
969
|
+
const name = nameOf(tool);
|
|
970
|
+
if (name !== void 0) names.push(name);
|
|
971
|
+
}
|
|
972
|
+
const view = hooks.view(names, sourceView);
|
|
973
|
+
const visible = [];
|
|
974
|
+
const visibleNames = [];
|
|
975
|
+
const masked = [];
|
|
976
|
+
for (const tool of all) {
|
|
977
|
+
const name = nameOf(tool);
|
|
978
|
+
if (name === void 0) continue;
|
|
979
|
+
if (isMaskedName(name, rules, view)) masked.push(name);
|
|
980
|
+
else {
|
|
981
|
+
visible.push(tool);
|
|
982
|
+
visibleNames.push(name);
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
if (hooks.isProbing?.() !== true) hooks.onDescribe?.({
|
|
986
|
+
visible: visibleNames,
|
|
987
|
+
masked
|
|
988
|
+
});
|
|
989
|
+
return visible;
|
|
990
|
+
},
|
|
991
|
+
bindings(scope, toolStep) {
|
|
992
|
+
if (typeof toolStep === "object" && toolStep !== null) return [...ensureStepBindings(toolStep, scope).values()];
|
|
993
|
+
return [...dedupeBindings(resolveAllRaw(scope)).values()];
|
|
994
|
+
},
|
|
995
|
+
binding(name, scope, toolStep) {
|
|
996
|
+
const current = resolveRaw(name, scope);
|
|
997
|
+
if (current === void 0 || typeof toolStep !== "object" || toolStep === null) return current;
|
|
998
|
+
return ensureStepBindings(toolStep, scope).get(name) === current ? current : void 0;
|
|
999
|
+
},
|
|
1000
|
+
...typeof hooks.reset === "function" ? { async reset(agent) {
|
|
1001
|
+
await hooks.reset(agent);
|
|
1002
|
+
} } : {}
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
892
1005
|
//#endregion
|
|
893
1006
|
//#region src/host/runtime/codemode/transport.ts
|
|
894
1007
|
/**
|
|
@@ -1242,7 +1355,7 @@ function createTransportDefinition(host, rules) {
|
|
|
1242
1355
|
if (hasRawEscalation && isStrictSandboxUnsupported(runtime)) throw new CodemodeArgsError("sandbox_permissions and justification are not available for this PTC runtime");
|
|
1243
1356
|
const prevalidatedEscalation = hasRawEscalation && runtime.sandboxMode !== void 0 ? validateEscalationArgs(input.rawSandboxPermissions, input.rawJustification) : void 0;
|
|
1244
1357
|
await host.awaitPredecessors?.(exec.agent, exec.signal);
|
|
1245
|
-
const catalog = host.catalog(exec.agent, exec.toolSet);
|
|
1358
|
+
const catalog = host.catalog(exec.agent, exec.toolStep ?? exec.toolSet);
|
|
1246
1359
|
const runController = new AbortController();
|
|
1247
1360
|
const onOuterAbort = () => {
|
|
1248
1361
|
runController.abort(exec.signal.reason);
|
|
@@ -1289,7 +1402,8 @@ function createTransportDefinition(host, rules) {
|
|
|
1289
1402
|
callId,
|
|
1290
1403
|
signal: nestedSignal,
|
|
1291
1404
|
agent: exec.agent,
|
|
1292
|
-
toolSet: exec.toolSet
|
|
1405
|
+
toolSet: exec.toolSet,
|
|
1406
|
+
...exec.toolStep === void 0 ? {} : { toolStep: exec.toolStep }
|
|
1293
1407
|
}),
|
|
1294
1408
|
/**
|
|
1295
1409
|
* 提交阶段:按**提交顺序**逐条执行,落在会话里的副作用因此与提交顺序一致。
|
|
@@ -2089,7 +2203,8 @@ async function forwardNarration(host, narration, exec, signal) {
|
|
|
2089
2203
|
callId: String(exec.callId) + ":ptc:0",
|
|
2090
2204
|
signal,
|
|
2091
2205
|
agent: exec.agent,
|
|
2092
|
-
toolSet: exec.toolSet
|
|
2206
|
+
toolSet: exec.toolSet,
|
|
2207
|
+
...exec.toolStep === void 0 ? {} : { toolStep: exec.toolStep }
|
|
2093
2208
|
});
|
|
2094
2209
|
} catch {}
|
|
2095
2210
|
}
|
|
@@ -3033,6 +3148,99 @@ const inject = ["tools", "systemPrompt"];
|
|
|
3033
3148
|
const DEBUG_RING = 50;
|
|
3034
3149
|
const CORDIS_ORIGINAL_DESCRIPTION = "cordis.original";
|
|
3035
3150
|
const PTC_RUNTIME_PACKAGE = "@deepseek-ai/dsh-ptc-runtime";
|
|
3151
|
+
const LEGACY_NATIVE_EXECUTOR_PACKAGE = "@deepseek-ai/dsh-tool-executor-native";
|
|
3152
|
+
const TOOLS_PIPELINE_PACKAGE = "@deepseek-ai/dsh-tools/pipeline";
|
|
3153
|
+
let cachedToolsPipelinePromise;
|
|
3154
|
+
/** 从给定根目录解析包(或子路径)的真实入口 file:// URL(经过 realpathSync 归一化)。 */
|
|
3155
|
+
function resolvePackageModuleUrl(rootDir, specifier) {
|
|
3156
|
+
let req;
|
|
3157
|
+
try {
|
|
3158
|
+
req = createRequire(join(rootDir, "package.json"));
|
|
3159
|
+
} catch {
|
|
3160
|
+
return;
|
|
3161
|
+
}
|
|
3162
|
+
let entryPath;
|
|
3163
|
+
try {
|
|
3164
|
+
entryPath = req.resolve(specifier);
|
|
3165
|
+
} catch {
|
|
3166
|
+
const parts = specifier.split("/");
|
|
3167
|
+
const pkgName = specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
|
|
3168
|
+
const subpath = specifier.slice(pkgName.length);
|
|
3169
|
+
const exportKey = subpath === "" ? "." : `.${subpath}`;
|
|
3170
|
+
try {
|
|
3171
|
+
const manifestPath = req.resolve(`${pkgName}/package.json`);
|
|
3172
|
+
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
3173
|
+
const target = manifest.exports?.[exportKey];
|
|
3174
|
+
const rel = typeof target === "string" ? target : typeof target === "object" && target !== null ? target["import"] ?? target["default"] : exportKey === "." ? manifest.main : void 0;
|
|
3175
|
+
if (typeof rel === "string" && rel.length > 0) {
|
|
3176
|
+
const candidate = resolve(dirname(manifestPath), rel);
|
|
3177
|
+
if (existsSync(candidate)) entryPath = candidate;
|
|
3178
|
+
}
|
|
3179
|
+
} catch {
|
|
3180
|
+
return;
|
|
3181
|
+
}
|
|
3182
|
+
}
|
|
3183
|
+
if (entryPath === void 0) return void 0;
|
|
3184
|
+
try {
|
|
3185
|
+
return pathToFileURL(realpathSync(entryPath)).href;
|
|
3186
|
+
} catch {
|
|
3187
|
+
return pathToFileURL(entryPath).href;
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3190
|
+
/** 同步加载旧代(0.2.2–0.2.3-alpha.2)的 `@deepseek-ai/dsh-tool-executor-native`。 */
|
|
3191
|
+
function loadLegacyNativeToolExecutor(ctx) {
|
|
3192
|
+
const roots = /* @__PURE__ */ new Set();
|
|
3193
|
+
contextBaseDirs(ctx, roots);
|
|
3194
|
+
for (const dir of candidatePackageRoots()) roots.add(dir);
|
|
3195
|
+
const tryRequire = (req) => {
|
|
3196
|
+
try {
|
|
3197
|
+
const mod = req(LEGACY_NATIVE_EXECUTOR_PACKAGE);
|
|
3198
|
+
return typeof mod?.NativeToolExecutor === "function" ? mod.NativeToolExecutor : void 0;
|
|
3199
|
+
} catch {
|
|
3200
|
+
return;
|
|
3201
|
+
}
|
|
3202
|
+
};
|
|
3203
|
+
for (const rootDir of roots) try {
|
|
3204
|
+
const found = tryRequire(createRequire(join(rootDir, "package.json")));
|
|
3205
|
+
if (found !== void 0) return found;
|
|
3206
|
+
} catch {}
|
|
3207
|
+
try {
|
|
3208
|
+
return tryRequire(createRequire(import.meta.url));
|
|
3209
|
+
} catch {
|
|
3210
|
+
return;
|
|
3211
|
+
}
|
|
3212
|
+
}
|
|
3213
|
+
/** 按需加载 DSH 0.2.3-alpha.3+ `@deepseek-ai/dsh-tools/pipeline`,供程序内子调用走完整策略管线。 */
|
|
3214
|
+
async function loadToolsPipeline(ctx) {
|
|
3215
|
+
if (cachedToolsPipelinePromise !== void 0) return cachedToolsPipelinePromise;
|
|
3216
|
+
cachedToolsPipelinePromise = (async () => {
|
|
3217
|
+
const roots = /* @__PURE__ */ new Set();
|
|
3218
|
+
contextBaseDirs(ctx, roots);
|
|
3219
|
+
for (const dir of candidatePackageRoots()) roots.add(dir);
|
|
3220
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3221
|
+
const tryImport = async (specifier) => {
|
|
3222
|
+
if (seen.has(specifier)) return void 0;
|
|
3223
|
+
seen.add(specifier);
|
|
3224
|
+
try {
|
|
3225
|
+
const mod = await import(specifier);
|
|
3226
|
+
if (typeof mod["ToolExecutionPipeline"] === "function" && typeof mod["executeToolBatch"] === "function") return {
|
|
3227
|
+
ToolExecutionPipeline: mod["ToolExecutionPipeline"],
|
|
3228
|
+
executeToolBatch: mod["executeToolBatch"]
|
|
3229
|
+
};
|
|
3230
|
+
} catch {}
|
|
3231
|
+
};
|
|
3232
|
+
for (const rootDir of roots) {
|
|
3233
|
+
const url = resolvePackageModuleUrl(rootDir, TOOLS_PIPELINE_PACKAGE);
|
|
3234
|
+
if (url === void 0) continue;
|
|
3235
|
+
const loaded = await tryImport(url);
|
|
3236
|
+
if (loaded !== void 0) return loaded;
|
|
3237
|
+
}
|
|
3238
|
+
return tryImport(TOOLS_PIPELINE_PACKAGE);
|
|
3239
|
+
})();
|
|
3240
|
+
const resolved = await cachedToolsPipelinePromise;
|
|
3241
|
+
if (resolved === void 0) cachedToolsPipelinePromise = void 0;
|
|
3242
|
+
return resolved;
|
|
3243
|
+
}
|
|
3036
3244
|
const resolvedPtcClassesByProto = /* @__PURE__ */ new WeakMap();
|
|
3037
3245
|
const pendingPtcClassesByProto = /* @__PURE__ */ new WeakMap();
|
|
3038
3246
|
/** 展开 Cordis 代理链,拿到最底层真实的 runtime 对象。 */
|
|
@@ -3061,26 +3269,35 @@ function isRealPtcRuntimeInstance(runtime) {
|
|
|
3061
3269
|
}
|
|
3062
3270
|
return false;
|
|
3063
3271
|
}
|
|
3272
|
+
/** 安全读取可能是 Cordis Context 代理对象上的属性:未声明 inject 的服务属性优先走 `get()` 并吞掉反射异常。 */
|
|
3273
|
+
function safeReadProp(target, key) {
|
|
3274
|
+
if (typeof target !== "object" || target === null) return void 0;
|
|
3275
|
+
const record = target;
|
|
3276
|
+
if (typeof record["get"] === "function" && key !== "root" && key !== "ctx") try {
|
|
3277
|
+
const viaGet = record["get"].call(target, key);
|
|
3278
|
+
if (viaGet !== void 0) return viaGet;
|
|
3279
|
+
} catch {}
|
|
3280
|
+
try {
|
|
3281
|
+
return record[key];
|
|
3282
|
+
} catch {
|
|
3283
|
+
return;
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3064
3286
|
/** 从 Cordis ctx / loader 上尽量收集宿主运行根目录。 */
|
|
3065
3287
|
function contextBaseDirs(source, roots) {
|
|
3066
3288
|
if (typeof source !== "object" || source === null) return;
|
|
3067
|
-
const record = source;
|
|
3068
3289
|
const addDir = (value) => {
|
|
3069
3290
|
if (typeof value === "string" && value.trim().length > 0) roots.add(value.trim());
|
|
3070
3291
|
};
|
|
3071
|
-
addDir(
|
|
3072
|
-
const root =
|
|
3292
|
+
addDir(safeReadProp(source, "baseDir"));
|
|
3293
|
+
const root = safeReadProp(source, "root");
|
|
3073
3294
|
if (typeof root === "object" && root !== null && root !== source) {
|
|
3074
|
-
addDir(root
|
|
3075
|
-
const rootLoader = root
|
|
3076
|
-
if (typeof rootLoader === "object" && rootLoader !== null) addDir(rootLoader
|
|
3077
|
-
}
|
|
3078
|
-
const loader =
|
|
3079
|
-
if (typeof loader === "object" && loader !== null) addDir(loader
|
|
3080
|
-
if (typeof record["get"] === "function") try {
|
|
3081
|
-
const loaderService = record["get"].call(source, "loader");
|
|
3082
|
-
if (typeof loaderService === "object" && loaderService !== null) addDir(loaderService["baseDir"]);
|
|
3083
|
-
} catch {}
|
|
3295
|
+
addDir(safeReadProp(root, "baseDir"));
|
|
3296
|
+
const rootLoader = safeReadProp(root, "loader");
|
|
3297
|
+
if (typeof rootLoader === "object" && rootLoader !== null) addDir(safeReadProp(rootLoader, "baseDir"));
|
|
3298
|
+
}
|
|
3299
|
+
const loader = safeReadProp(source, "loader");
|
|
3300
|
+
if (typeof loader === "object" && loader !== null) addDir(safeReadProp(loader, "baseDir"));
|
|
3084
3301
|
}
|
|
3085
3302
|
/** 从给定根目录解析 `@deepseek-ai/dsh-ptc-runtime` 的真实入口 file:// URL(经过 realpathSync 归一化)。 */
|
|
3086
3303
|
function resolvePtcRuntimeModuleUrl(rootDir) {
|
|
@@ -3142,7 +3359,7 @@ async function resolveHostPtcRuntimeClasses(runtime, ctx, extraRoots) {
|
|
|
3142
3359
|
for (const dir of extraRoots) if (typeof dir === "string" && dir.trim().length > 0) roots.add(dir.trim());
|
|
3143
3360
|
}
|
|
3144
3361
|
contextBaseDirs(ctx, roots);
|
|
3145
|
-
contextBaseDirs(rawRuntime
|
|
3362
|
+
contextBaseDirs(safeReadProp(rawRuntime, "ctx"), roots);
|
|
3146
3363
|
for (const dir of candidatePackageRoots()) roots.add(dir);
|
|
3147
3364
|
const seenUrls = /* @__PURE__ */ new Set();
|
|
3148
3365
|
const tryModule = async (specifier) => {
|
|
@@ -3292,20 +3509,32 @@ function apply(ctx, config = {}) {
|
|
|
3292
3509
|
};
|
|
3293
3510
|
const scopeKey = findScopeKey(ctx);
|
|
3294
3511
|
if (rules.options.nativeScope && scopeKey === void 0) log("warn", "[codemode] no registry scope tag on this context: masking falls back to name rules only (" + rules.options.hiddenPrefixes.join(", ") + "). Mount this row inside an agent preset to hide every tool the preset does not own.");
|
|
3295
|
-
/** 最近一次 describe
|
|
3512
|
+
/** 最近一次 describe / getAll 收到的完整定义集(含被遮蔽的),作为兜底快照。 */
|
|
3296
3513
|
let catalog = [];
|
|
3297
3514
|
const debugRing = [];
|
|
3298
3515
|
let firstDescribeLogged = false;
|
|
3516
|
+
let rootRegistry;
|
|
3517
|
+
let rootPipelineInstance;
|
|
3518
|
+
let rootPipelineModule;
|
|
3299
3519
|
/**
|
|
3300
|
-
* 解析当前调用方 agent
|
|
3520
|
+
* 解析当前调用方 agent 与步骤准入下的完整未遮蔽工具清单。
|
|
3301
3521
|
*
|
|
3302
|
-
*
|
|
3303
|
-
*
|
|
3304
|
-
* `
|
|
3522
|
+
* - DSH 0.2.3-alpha.3+(`setRoot` 模式):从 `rootRegistry.bindings(agent, toolStep)` 读取
|
|
3523
|
+
* `ctx.tools` 注入的未遮蔽注册表视图,并按 `toolStep` 钉死步骤绑定;
|
|
3524
|
+
* - DSH 0.2.2–0.2.3-alpha.2(`setExecutor` 模式):从 `ctx.tools.definitions(agent, toolSet)` 实时读取;
|
|
3525
|
+
* - 测试替身未提供上述接口时回退到最近一次 `catalog`。
|
|
3305
3526
|
*/
|
|
3306
|
-
const resolveCatalog = (agent,
|
|
3527
|
+
const resolveCatalog = (agent, stepOrToolSet) => {
|
|
3528
|
+
if (rootRegistry !== void 0) try {
|
|
3529
|
+
const scopeObj = typeof agent === "object" && agent !== null ? agent : void 0;
|
|
3530
|
+
const defs = rootRegistry.bindings(scopeObj, stepOrToolSet);
|
|
3531
|
+
if (Array.isArray(defs) && defs.length > 0) {
|
|
3532
|
+
const entries = defs.map(toCatalogEntry).filter((entry) => entry !== void 0);
|
|
3533
|
+
if (entries.length > 0) return entries;
|
|
3534
|
+
}
|
|
3535
|
+
} catch {}
|
|
3307
3536
|
if (agent !== void 0 && typeof tools.definitions === "function") try {
|
|
3308
|
-
const defs = tools.definitions(agent,
|
|
3537
|
+
const defs = tools.definitions(agent, stepOrToolSet);
|
|
3309
3538
|
if (Array.isArray(defs) && defs.length > 0) {
|
|
3310
3539
|
const entries = defs.map(toCatalogEntry).filter((entry) => entry !== void 0);
|
|
3311
3540
|
if (entries.length > 0) return entries;
|
|
@@ -3398,11 +3627,32 @@ function apply(ctx, config = {}) {
|
|
|
3398
3627
|
};
|
|
3399
3628
|
let batch;
|
|
3400
3629
|
try {
|
|
3401
|
-
|
|
3630
|
+
if (rootRegistry !== void 0 && typeof context.waterfall === "function" && typeof tools.checkGuards === "function") {
|
|
3631
|
+
const mod = rootPipelineModule ?? await loadToolsPipeline(ctx);
|
|
3632
|
+
if (mod !== void 0) {
|
|
3633
|
+
rootPipelineModule = mod;
|
|
3634
|
+
if (rootPipelineInstance === void 0) {
|
|
3635
|
+
const registry = rootRegistry;
|
|
3636
|
+
rootPipelineInstance = new mod.ToolExecutionPipeline(ctx, { get: (calledName, scope, toolStep) => registry.binding(calledName, typeof scope === "object" && scope !== null ? scope : void 0, toolStep) });
|
|
3637
|
+
}
|
|
3638
|
+
const step = request.toolStep ?? request.toolSet;
|
|
3639
|
+
batch = await mod.executeToolBatch({
|
|
3640
|
+
calls: [call],
|
|
3641
|
+
signal: request.signal,
|
|
3642
|
+
...request.agent === void 0 ? {} : { agent: request.agent },
|
|
3643
|
+
...step === void 0 ? {} : { toolStep: step }
|
|
3644
|
+
}, rootPipelineInstance);
|
|
3645
|
+
} else batch = await tools.execute({
|
|
3646
|
+
calls: [call],
|
|
3647
|
+
signal: request.signal,
|
|
3648
|
+
...request.agent === void 0 ? {} : { agent: request.agent },
|
|
3649
|
+
...request.toolStep !== void 0 ? { toolStep: request.toolStep } : request.toolSet === void 0 ? {} : { toolSet: request.toolSet }
|
|
3650
|
+
});
|
|
3651
|
+
} else batch = await tools.execute({
|
|
3402
3652
|
calls: [call],
|
|
3403
3653
|
signal: request.signal,
|
|
3404
3654
|
...request.agent === void 0 ? {} : { agent: request.agent },
|
|
3405
|
-
...request.toolSet === void 0 ? {} : { toolSet: request.toolSet }
|
|
3655
|
+
...request.toolStep !== void 0 ? { toolStep: request.toolStep } : request.toolSet === void 0 ? {} : { toolSet: request.toolSet }
|
|
3406
3656
|
});
|
|
3407
3657
|
} catch (error) {
|
|
3408
3658
|
return { error: messageOf(error) };
|
|
@@ -3428,65 +3678,115 @@ function apply(ctx, config = {}) {
|
|
|
3428
3678
|
}
|
|
3429
3679
|
};
|
|
3430
3680
|
for (const definition of createDiscoveryDefinitions(rules, () => currentCatalogSnapshot() ?? catalog, () => debugRing)) tools.register(definition);
|
|
3431
|
-
|
|
3681
|
+
const transportDef = createTransportDefinition(host, rules);
|
|
3682
|
+
tools.register(transportDef);
|
|
3683
|
+
const sectionText = () => {
|
|
3684
|
+
const runtime = runtimeOf();
|
|
3685
|
+
return buildCodemodeSectionText({
|
|
3686
|
+
runToolName: rules.options.runToolName,
|
|
3687
|
+
metaTools: rules.options.metaTools,
|
|
3688
|
+
language: runtime?.language,
|
|
3689
|
+
programFormat: runtime?.programFormat,
|
|
3690
|
+
nativeToolsOnly: rules.options.nativeToolsOnly,
|
|
3691
|
+
nativeTools: rules.options.nativeTools
|
|
3692
|
+
});
|
|
3693
|
+
};
|
|
3694
|
+
const resetEnvironment = async (agent) => {
|
|
3695
|
+
const runtime = runtimeOf();
|
|
3696
|
+
if (runtime === void 0) throw new Error("codemode: no PTC runtime is mounted (ctx.ptcRuntime); the program transport is unavailable");
|
|
3697
|
+
if (!runtime.retainsState) throw new CodeResetFailedError("The PTC runtime does not retain an environment");
|
|
3698
|
+
try {
|
|
3699
|
+
await retention.reset(agent, () => {
|
|
3700
|
+
const inject = typeof agent === "object" && agent !== null ? agent.inject : void 0;
|
|
3701
|
+
if (typeof inject === "function") inject.call(agent, createUserMessage({
|
|
3702
|
+
content: [{
|
|
3703
|
+
type: "text",
|
|
3704
|
+
text: "Program environment reset; retained variables cleared. Completed tool effects remain."
|
|
3705
|
+
}],
|
|
3706
|
+
source: { kind: PLUGIN_MESSAGE_SOURCE_KIND }
|
|
3707
|
+
}));
|
|
3708
|
+
});
|
|
3709
|
+
} catch (error) {
|
|
3710
|
+
throw new CodeResetFailedError("Program environment reset failed: " + messageOf(error) + ". State may not be cleared; retry the host reset before running more code.");
|
|
3711
|
+
}
|
|
3712
|
+
};
|
|
3713
|
+
const recordDescribe = (decision) => {
|
|
3714
|
+
const hidden = summarizeHidden(decision.masked);
|
|
3715
|
+
debugRing.push({
|
|
3716
|
+
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3717
|
+
visible: decision.visible,
|
|
3718
|
+
hidden
|
|
3719
|
+
});
|
|
3720
|
+
while (debugRing.length > DEBUG_RING) debugRing.shift();
|
|
3721
|
+
const namespaces = hidden.namespaces.map((entry) => entry.namespace + "=" + String(entry.count)).join(", ");
|
|
3722
|
+
const line = "[codemode] masked " + String(hidden.total) + " non-standard tool(s)" + (namespaces === "" ? "" : " (" + namespaces + ")") + "; request tools: " + decision.visible.join(", ");
|
|
3723
|
+
if (!firstDescribeLogged) {
|
|
3724
|
+
firstDescribeLogged = true;
|
|
3725
|
+
log("info", line);
|
|
3726
|
+
} else log("debug", line);
|
|
3727
|
+
};
|
|
3728
|
+
if (typeof tools.setRoot === "function") {
|
|
3729
|
+
loadToolsPipeline(ctx).then((mod) => {
|
|
3730
|
+
if (mod !== void 0) rootPipelineModule = mod;
|
|
3731
|
+
});
|
|
3732
|
+
let probingSetRoot = false;
|
|
3733
|
+
rootRegistry = createCodemodeRootRegistry(rules, {
|
|
3734
|
+
view: (names, sourceView) => resolveCatalogView(sourceView, scopeKey, names),
|
|
3735
|
+
viewForName: (toolName, sourceView) => resolveNameView(sourceView, scopeKey, toolName),
|
|
3736
|
+
onCatalog: (definitions) => {
|
|
3737
|
+
catalog = definitions.map(toCatalogEntry).filter((entry) => entry !== void 0);
|
|
3738
|
+
},
|
|
3739
|
+
onDescribe: recordDescribe,
|
|
3740
|
+
isProbing: () => probingSetRoot,
|
|
3741
|
+
reset: resetEnvironment
|
|
3742
|
+
});
|
|
3743
|
+
probingSetRoot = true;
|
|
3744
|
+
try {
|
|
3745
|
+
tools.setRoot(rootRegistry);
|
|
3746
|
+
} finally {
|
|
3747
|
+
probingSetRoot = false;
|
|
3748
|
+
}
|
|
3749
|
+
const systemPrompt = context.systemPrompt ?? serviceOf("systemPrompt");
|
|
3750
|
+
const registerSection = typeof systemPrompt === "object" && systemPrompt !== null ? systemPrompt.section : void 0;
|
|
3751
|
+
if (rules.options.sdkSection && typeof registerSection === "function") registerSection.call(systemPrompt, {
|
|
3752
|
+
name: "tools:sdk",
|
|
3753
|
+
order: sectionOrderOf(ctx),
|
|
3754
|
+
interpolate: false,
|
|
3755
|
+
text: (assembleCtx) => {
|
|
3756
|
+
const step = assembleCtx?.toolStep;
|
|
3757
|
+
if (step !== void 0 && typeof step.declares === "function") return step.declares(transportDef) ? sectionText() : "";
|
|
3758
|
+
try {
|
|
3759
|
+
return tools.get(rules.options.runToolName, assembleCtx?.scope) === transportDef ? sectionText() : "";
|
|
3760
|
+
} catch {
|
|
3761
|
+
return "";
|
|
3762
|
+
}
|
|
3763
|
+
}
|
|
3764
|
+
});
|
|
3765
|
+
const scopeNote = scopeKey === void 0 ? "" : ", everything outside this preset scope";
|
|
3766
|
+
log("info", "[codemode] active (root registry): transport [" + rules.options.runToolName + "], discovery [" + rules.options.metaTools.join(", ") + "], hiding [" + rules.options.hiddenPrefixes.join(", ") + "]" + scopeNote);
|
|
3767
|
+
return;
|
|
3768
|
+
}
|
|
3432
3769
|
if (typeof tools.setExecutor !== "function") {
|
|
3433
|
-
log("warn", "[codemode] this DSH build has
|
|
3770
|
+
log("warn", "[codemode] this DSH build has neither ctx.tools.setRoot() nor ctx.tools.setExecutor(); Code Mode requires DSH 0.2.2 or later. Switch this session to the built-in ptc preset.");
|
|
3771
|
+
return;
|
|
3772
|
+
}
|
|
3773
|
+
const LegacyNativeToolExecutor = loadLegacyNativeToolExecutor(ctx);
|
|
3774
|
+
if (LegacyNativeToolExecutor === void 0) {
|
|
3775
|
+
log("warn", "[codemode] could not resolve @deepseek-ai/dsh-tool-executor-native for legacy ctx.tools.setExecutor(); switch this session to the built-in ptc preset.");
|
|
3434
3776
|
return;
|
|
3435
3777
|
}
|
|
3436
|
-
const delegate = new
|
|
3778
|
+
const delegate = new LegacyNativeToolExecutor(ctx);
|
|
3437
3779
|
const view = () => resolveCatalogView(tools, scopeKey, catalog.map((entry) => entry.name));
|
|
3438
3780
|
const executor = createCodemodeExecutor(ctx, rules, {
|
|
3439
3781
|
delegate,
|
|
3440
3782
|
view,
|
|
3441
3783
|
viewForName: (toolName) => resolveNameView(tools, scopeKey, toolName),
|
|
3442
|
-
sectionText
|
|
3443
|
-
const runtime = runtimeOf();
|
|
3444
|
-
return buildCodemodeSectionText({
|
|
3445
|
-
runToolName: rules.options.runToolName,
|
|
3446
|
-
metaTools: rules.options.metaTools,
|
|
3447
|
-
language: runtime?.language,
|
|
3448
|
-
programFormat: runtime?.programFormat,
|
|
3449
|
-
nativeToolsOnly: rules.options.nativeToolsOnly,
|
|
3450
|
-
nativeTools: rules.options.nativeTools
|
|
3451
|
-
});
|
|
3452
|
-
},
|
|
3784
|
+
sectionText,
|
|
3453
3785
|
onCatalog: (definitions) => {
|
|
3454
3786
|
catalog = definitions.map(toCatalogEntry).filter((entry) => entry !== void 0);
|
|
3455
3787
|
},
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
if (runtime === void 0) throw new Error("codemode: no PTC runtime is mounted (ctx.ptcRuntime); the program transport is unavailable");
|
|
3459
|
-
if (!runtime.retainsState) throw new CodeResetFailedError("The PTC runtime does not retain an environment");
|
|
3460
|
-
try {
|
|
3461
|
-
await retention.reset(agent, () => {
|
|
3462
|
-
const inject = typeof agent === "object" && agent !== null ? agent.inject : void 0;
|
|
3463
|
-
if (typeof inject === "function") inject.call(agent, createUserMessage({
|
|
3464
|
-
content: [{
|
|
3465
|
-
type: "text",
|
|
3466
|
-
text: "Program environment reset; retained variables cleared. Completed tool effects remain."
|
|
3467
|
-
}],
|
|
3468
|
-
source: { kind: PLUGIN_MESSAGE_SOURCE_KIND }
|
|
3469
|
-
}));
|
|
3470
|
-
});
|
|
3471
|
-
} catch (error) {
|
|
3472
|
-
throw new CodeResetFailedError("Program environment reset failed: " + messageOf(error) + ". State may not be cleared; retry the host reset before running more code.");
|
|
3473
|
-
}
|
|
3474
|
-
},
|
|
3475
|
-
onDescribe: (decision) => {
|
|
3476
|
-
const hidden = summarizeHidden(decision.masked);
|
|
3477
|
-
debugRing.push({
|
|
3478
|
-
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3479
|
-
visible: decision.visible,
|
|
3480
|
-
hidden
|
|
3481
|
-
});
|
|
3482
|
-
while (debugRing.length > DEBUG_RING) debugRing.shift();
|
|
3483
|
-
const namespaces = hidden.namespaces.map((entry) => entry.namespace + "=" + String(entry.count)).join(", ");
|
|
3484
|
-
const line = "[codemode] masked " + String(hidden.total) + " non-standard tool(s)" + (namespaces === "" ? "" : " (" + namespaces + ")") + "; request tools: " + decision.visible.join(", ");
|
|
3485
|
-
if (!firstDescribeLogged) {
|
|
3486
|
-
firstDescribeLogged = true;
|
|
3487
|
-
log("info", line);
|
|
3488
|
-
} else log("debug", line);
|
|
3489
|
-
}
|
|
3788
|
+
reset: resetEnvironment,
|
|
3789
|
+
onDescribe: recordDescribe
|
|
3490
3790
|
});
|
|
3491
3791
|
tools.setExecutor(executor);
|
|
3492
3792
|
const scopeNote = scopeKey === void 0 ? "" : ", everything outside this preset scope";
|