dsh-cohub 0.11.0 → 0.11.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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# dsh-cohub
|
|
2
2
|
|
|
3
|
-
> 本文对应 **v0.11.
|
|
3
|
+
> 本文对应 **v0.11.1**;完整变更历史见 [CHANGELOG.md](./CHANGELOG.md)。
|
|
4
4
|
|
|
5
5
|
DeepSeek Harness 版(对照 [OpenCode 版](../oh-my-opencode-cohub/)):中文智能体编排插件。
|
|
6
6
|
把「纯调度模式 + 13 个技能(12 个代理编排体系 + co-cordis 组合创作)+ 多模型共识 + 运行期调度韧性」移植到 DSH 原生能力之上。
|
|
@@ -9,7 +9,10 @@ DeepSeek Harness 版(对照 [OpenCode 版](../oh-my-opencode-cohub/)):中
|
|
|
9
9
|
|
|
10
10
|
### 1. 前置条件
|
|
11
11
|
|
|
12
|
-
宿主 DSH ≥ `0.2.0-rc.2
|
|
12
|
+
宿主 DSH ≥ `0.2.2-rc.1`(`@deepseek-ai/dsh-*` peer 依赖声明为 `^0.2.2-rc.1`,等价于 `>=0.2.2-rc.1 <0.3.0-0`;低于此版本时 npm 会因 peer 冲突拒绝安装,属预期行为)。不支持 DSH 0.1,以及 0.2.0 / 0.2.1 系列。
|
|
13
|
+
|
|
14
|
+
- 子代理读写硬隔离(per-child `agentPreset`)自 DSH `0.2.1` 起提供,已被上述下限涵盖,无需单独满足。
|
|
15
|
+
- `0.2.2-rc.1` 是 prerelease,版本走 npm dist-tag `next`(2026-11-04 发布);宿主自身要求 **Node ≥ 24.9.0**(`engines.node`),本地构建/运行前请先对齐 Node 版本。本包不单独声明 `engines.node`,Node 门槛以宿主为准。
|
|
13
16
|
|
|
14
17
|
### 2. 安装
|
|
15
18
|
|
|
@@ -84,7 +87,7 @@ cp presets/co-orchestrator/* ~/.dsh/.agent-presets/co-orchestrator/
|
|
|
84
87
|
> pwsh -File scripts/deploy-preset.ps1 -PresetName co-orchestrator
|
|
85
88
|
> ```
|
|
86
89
|
|
|
87
|
-
在 GUI 的 agent preset 选择器中切换。注意:**DSH 0.2.1 起支持 per-child `agentPreset`**(`SubagentStartRequest.agentPreset` 为一等字段,子代理经 `presets.mount()`
|
|
90
|
+
在 GUI 的 agent preset 选择器中切换。注意:**DSH 0.2.1 起支持 per-child `agentPreset`**(`SubagentStartRequest.agentPreset` 为一等字段,子代理经 `presets.mount()` 独立组装;本包 peer 要求的 `^0.2.2-rc.1` 已涵盖该能力),子代理不再继承父代理的 preset 组合与工具表——cohub 已用两个独立精简 preset(`cohub-subagent-readonly` / `cohub-subagent-write`)对子代理做**硬隔离**,故「绝不亲自操作文件」「只读代理不写文件」由工具面物理保证,不再只靠提示词。`toolFilter` 仍保留作为补充收窄手段(但它对子代理 own 层挂载的工具无效)。主代理侧「绝不亲自操作文件」继续由 co-orchestrator 技能在提示词层约束(与 OpenCode 原版一致)。
|
|
88
91
|
|
|
89
92
|
完整变更历史(含 v0.3.0–v0.8.2 全部条目)见 [CHANGELOG.md](./CHANGELOG.md)。
|
|
90
93
|
|
|
@@ -150,7 +153,7 @@ revision 做冲突栅栏),因此改完保存即生效,无需重启。
|
|
|
150
153
|
留空 = 不覆盖;可填档位见上文
|
|
151
154
|
[按代理配置推理强度](#按代理配置推理强度reasoningeffort)。
|
|
152
155
|
|
|
153
|
-
`npm run test:client`(`test/client-runtime-0.2.ts`,
|
|
156
|
+
`npm run test:client`(`test/client-runtime-0.2.ts`,120 条断言)覆盖该页的渲染契约与写回契约:
|
|
154
157
|
`value=""` 继承占位项、目录加载中/失败降级手填、已存值不可用时 disabled 回显、只读连接、
|
|
155
158
|
revision 冲突拒绝保存、只写显式配置的代理等。
|
|
156
159
|
|
|
@@ -276,14 +279,18 @@ skills:
|
|
|
276
279
|
|
|
277
280
|
## 兼容性
|
|
278
281
|
|
|
279
|
-
宿主版本要求见「快速开始 → 前置条件」。`@deepseek-ai/
|
|
280
|
-
|
|
282
|
+
宿主版本要求见「快速开始 → 前置条件」。`@deepseek-ai/dsh-*` peer 声明为 `^0.2.2-rc.1`;`@deepseek-ai/cordis`
|
|
283
|
+
peer `^4.0.1` / `schemastery` peer `^3.18.4` **保持不变**——这两个区间已覆盖宿主内置的 cordis 4.1.0 与
|
|
284
|
+
schemastery 3.19.0(非 prerelease,无 prerelease 元组匹配问题,故不需要随宿主一起抬)。
|
|
285
|
+
测试 devDependencies **精确固定** `4.1.0` / `3.19.0`(与宿主内置一致;`@deepseek-ai/dsh-*` 侧则精确固定
|
|
286
|
+
`0.2.2-rc.1`,与 peer 下限同版)——lock 解析到最新不代表宿主实测,以宿主为准:
|
|
281
287
|
|
|
282
288
|
- **0.1 的 settings namespace 机制已移除**:`installSettingsSection` / `settingsNamespace` 在
|
|
283
289
|
dsh-settings 0.2 已删除。本插件不再注册 `cohub` namespace,改为 Config 的三个动态字段标
|
|
284
290
|
`.volatile()`(见上节)。`settings.yaml` 的 `cohub.*` 段**不会被自动迁移**(旧 importer 是否
|
|
285
291
|
支持自定义 namespace 未证实,明确不触发),请通过设置页或 `cordis.patch.yml` 重新配置。
|
|
286
292
|
- **不兼容 DSH 0.1**:宿主版本要求见「快速开始 → 前置条件」(0.1 宿主上 npm 会拒绝 peer 冲突,属预期行为)。
|
|
293
|
+
同理,**0.2.0 / 0.2.1 及全部 `0.2.2-*` 早期 rc 也已不在支持范围**——peer 下限是 `0.2.2-rc.1`,低于它一律按 peer 冲突拒绝。
|
|
287
294
|
- **验证入口**:`npm run test:runtime`(`test/runtime-0.2.ts`,真实 schemastery/Volatile/defineTool
|
|
288
295
|
契约 + 真实 cordis 挂载,离线 stub 子代理)、`npm run test:host`(`test/host-integration.ts`,
|
|
289
296
|
真实 Loader + entry.update volatile 提交 + SettingsForms.describe 投影 + 真实 subagents 服务
|
|
@@ -292,6 +299,7 @@ skills:
|
|
|
292
299
|
(`test/types/runtime-0.2.ts`,strict 编译检查公共边界与真实 DSH 0.2 导出)。完整宿主链路
|
|
293
300
|
(真实 spawn/fork transport 的进程内实现、真实 LLM provider、preset 树真实挂载)由宿主集成验证覆盖,
|
|
294
301
|
单测不冒称完全覆盖。
|
|
302
|
+
- **continuable 子代理冷恢复后回到父 preset 全量工具**:`toolFilter` 不进 subagent descriptor,冷恢复(进程重启后接续)时子代理回到父 preset 的完整工具面。因此**工具隔离主要靠 `agentPreset` 承担**(`cohub-subagent-readonly` / `cohub-subagent-write`),不要把 `toolFilter` 当作安全边界。
|
|
295
303
|
|
|
296
304
|
### 环境契约持久化
|
|
297
305
|
|
|
@@ -421,7 +429,7 @@ presets/
|
|
|
421
429
|
cohub-subagent-write/ 子代理可写 preset(工具面硬隔离)
|
|
422
430
|
test/
|
|
423
431
|
unit.ts 基础集成
|
|
424
|
-
client-runtime-0.2.ts 设置页渲染 / 写回契约(
|
|
432
|
+
client-runtime-0.2.ts 设置页渲染 / 写回契约(120 条断言)
|
|
425
433
|
delegate-p1.ts P1 环境契约注入 + 重试 + 模型回退
|
|
426
434
|
stall-p3.ts 停滞检测
|
|
427
435
|
schedule-p3.ts 调度参数
|
package/lib/index.js
CHANGED
|
@@ -440,8 +440,8 @@ Orchestrator 禁止使用任何文件/代码操作工具(read、grep、glob、
|
|
|
440
440
|
|
|
441
441
|
**硬约束:配置类文件要标并发风险**(**仅写类子代理适用**;只读类不改文件,本条对它们无意义)——委派改动下列文件时,任务书必须写一句「该文件可能有并发写者(GUI 插件市场 / 其他插件会毫秒级回写),改完必须复查**全量 diff** 而不能只看目标行」,并要求按「并发写与 FS_STALE_VERSION」纪律处理:
|
|
442
442
|
- \`~/.dsh/profiles/*/package.json\`(插件市场回写)
|
|
443
|
-
- \`~/.dsh/profiles/*/cordis.patch.yml
|
|
444
|
-
- \`~/.dsh/.agent-presets
|
|
443
|
+
- \`~/.dsh/profiles/*/cordis.patch.yml\`(patch 层,插件市场与多个插件都可能毫秒级回写)
|
|
444
|
+
- \`~/.dsh/.agent-presets/**\`(目录式 preset 布局,cohub 自身会重装;新版宿主亦支持 \`dsh-agent-preset\` 声明行,动手前先确认该 preset 属于哪种形态)
|
|
445
445
|
- \`.dsh-market/**\`、\`settings.*\` 等状态文件
|
|
446
446
|
|
|
447
447
|
**时间预算纪律(硬性四条):**
|
|
@@ -1190,7 +1190,7 @@ Orchestrator 会在 prompt 中明确指定:
|
|
|
1190
1190
|
可用:read / glob / grep / edit / write / pwsh(构建、测试、git)。
|
|
1191
1191
|
主战场:
|
|
1192
1192
|
- 插件仓库源码(\`src/\`、\`cordis.patch.yml\`、\`package.json\` 的 \`dsh.bundle.patch\`)
|
|
1193
|
-
- 组合层:profile 的 \`cordis.patch.yml\`(在 bundle patch **之后**应用)、\`~/.dsh/.agent-presets/<id>/agent.cordis.yml\`
|
|
1193
|
+
- 组合层:profile 的 \`cordis.patch.yml\`(在 bundle patch **之后**应用)、\`~/.dsh/.agent-presets/<id>/agent.cordis.yml\`(目录式 preset 布局;新版宿主已改用 \`dsh-agent-preset\` 声明行,动手前先确认目标 preset 属于哪一种形态)
|
|
1194
1194
|
- 运行时产物:\`lib/\` —— **改完源码必须重建(如 \`bun run build\`),否则运行时加载的还是旧产物**
|
|
1195
1195
|
|
|
1196
1196
|
禁止:改动部署自带的 preset 安装目录(升级会覆盖它;要改行为就把组合复制成新 preset 再改副本);扩大范围去改与本任务无关的文件。
|
|
@@ -1881,7 +1881,7 @@ function bindTypertRemote(service, serviceKey, options = {}) {
|
|
|
1881
1881
|
const namespace = options.namespace ?? serviceKey;
|
|
1882
1882
|
validateName("namespace", namespace);
|
|
1883
1883
|
const ctx = Reflect.get(service, "ctx");
|
|
1884
|
-
if (ctx
|
|
1884
|
+
if (Context.is(ctx))
|
|
1885
1885
|
provideInvocationAccessor(ctx);
|
|
1886
1886
|
return Object.freeze({
|
|
1887
1887
|
service,
|
|
@@ -1906,23 +1906,47 @@ function provideInvocationAccessor(ctx) {
|
|
|
1906
1906
|
function Remote(methodExportOrOptions, context) {
|
|
1907
1907
|
if (typeof methodExportOrOptions === "string") {
|
|
1908
1908
|
validateName("Remote export name", methodExportOrOptions);
|
|
1909
|
-
return remoteDecorator({ kind: "direct" },
|
|
1910
|
-
}
|
|
1911
|
-
if (typeof methodExportOrOptions === "object") {
|
|
1912
|
-
if (remoteOptionMode(methodExportOrOptions) !== "stream" || Reflect.ownKeys(methodExportOrOptions).length !== 1)
|
|
1913
|
-
throw new TypeError('typert-protocol: Remote options must contain exactly mode: "stream"');
|
|
1914
|
-
return remoteDecorator({ kind: "direct" }, "stream");
|
|
1909
|
+
return remoteDecorator({ kind: "direct" }, { exportName: methodExportOrOptions });
|
|
1915
1910
|
}
|
|
1911
|
+
if (typeof methodExportOrOptions === "object")
|
|
1912
|
+
return remoteDecorator({ kind: "direct" }, markerOptions(methodExportOrOptions, REMOTE_OPTION_KEYS, 'Remote options require name, mode: "stream", or resources'));
|
|
1916
1913
|
if (context === undefined)
|
|
1917
1914
|
throw new TypeError("typert-protocol: Remote decorator context is missing");
|
|
1918
1915
|
addMarkerInitializer(context, { kind: "direct" });
|
|
1919
1916
|
}
|
|
1920
|
-
|
|
1921
|
-
|
|
1917
|
+
var REMOTE_OPTION_KEYS = new Set([
|
|
1918
|
+
"name",
|
|
1919
|
+
"mode",
|
|
1920
|
+
"resources"
|
|
1921
|
+
]);
|
|
1922
|
+
var REMOTE_SCOPE_OPTION_KEYS = new Set(["name", "resources"]);
|
|
1923
|
+
function markerOptions(options, accepted, requirement) {
|
|
1924
|
+
const keys = Reflect.ownKeys(options);
|
|
1925
|
+
if (keys.length === 0 || keys.some((key) => typeof key !== "string" || !accepted.has(key)) || Object.hasOwn(options, "mode") && options.mode !== "stream")
|
|
1926
|
+
throw new TypeError(`typert-protocol: ${requirement}`);
|
|
1927
|
+
const { mode, name, resources } = options;
|
|
1928
|
+
if (name !== undefined)
|
|
1929
|
+
validateName("Remote export name", name);
|
|
1930
|
+
return {
|
|
1931
|
+
...mode === undefined ? {} : { mode },
|
|
1932
|
+
...name === undefined ? {} : { exportName: name },
|
|
1933
|
+
...resources === undefined ? {} : { resources: resourceReaders(resources) }
|
|
1934
|
+
};
|
|
1922
1935
|
}
|
|
1923
|
-
function
|
|
1936
|
+
function resourceReaders(resources) {
|
|
1937
|
+
const readers = {};
|
|
1938
|
+
for (const [kind, reader] of Object.entries(resources)) {
|
|
1939
|
+
if (typeof reader !== "function")
|
|
1940
|
+
throw new TypeError(`typert-protocol: Remote resource reader "${kind}" must be a function`);
|
|
1941
|
+
readers[kind] = reader;
|
|
1942
|
+
}
|
|
1943
|
+
if (Object.keys(readers).length === 0)
|
|
1944
|
+
throw new TypeError("typert-protocol: Remote resources require at least one reader");
|
|
1945
|
+
return Object.freeze(readers);
|
|
1946
|
+
}
|
|
1947
|
+
function remoteDecorator(invocation, options = {}) {
|
|
1924
1948
|
return function(_method, context) {
|
|
1925
|
-
addMarkerInitializer(context, invocation,
|
|
1949
|
+
addMarkerInitializer(context, invocation, options);
|
|
1926
1950
|
};
|
|
1927
1951
|
}
|
|
1928
1952
|
function readRemoteMethodDescriptor(prototype) {
|
|
@@ -1940,7 +1964,7 @@ function readRemoteMethodDescriptor(prototype) {
|
|
|
1940
1964
|
throw new TypeError("typert-protocol: Remote method descriptor methods must be an array");
|
|
1941
1965
|
return descriptor;
|
|
1942
1966
|
}
|
|
1943
|
-
function addMarkerInitializer(context, invocation,
|
|
1967
|
+
function addMarkerInitializer(context, invocation, options = {}) {
|
|
1944
1968
|
if (context.private || context.static || typeof context.name !== "string")
|
|
1945
1969
|
throw new TypeError("typert-protocol: Remote decorators require a public instance method with a string name");
|
|
1946
1970
|
const method = context.name;
|
|
@@ -1948,20 +1972,21 @@ function addMarkerInitializer(context, invocation, mode, exportName) {
|
|
|
1948
1972
|
const prototype = Object.getPrototypeOf(this);
|
|
1949
1973
|
if (prototype === null)
|
|
1950
1974
|
throw new TypeError(`typert-protocol: cannot mark Remote method "${method}" on an object without a prototype`);
|
|
1951
|
-
mark(prototype, method, invocation,
|
|
1975
|
+
mark(prototype, method, invocation, options);
|
|
1952
1976
|
});
|
|
1953
1977
|
}
|
|
1954
|
-
function mark(prototype, method, invocation, mode, exportName) {
|
|
1978
|
+
function mark(prototype, method, invocation, { mode, exportName, resources }) {
|
|
1955
1979
|
const descriptor = readRemoteMethodDescriptor(prototype);
|
|
1956
1980
|
const marker = Object.freeze({
|
|
1957
1981
|
method,
|
|
1958
1982
|
...exportName === undefined || exportName === method ? {} : { exportName },
|
|
1959
1983
|
...mode === undefined ? {} : { mode },
|
|
1960
|
-
invocation: Object.freeze(invocation)
|
|
1984
|
+
invocation: Object.freeze(invocation),
|
|
1985
|
+
...resources === undefined ? {} : { resources }
|
|
1961
1986
|
});
|
|
1962
1987
|
const current = descriptor?.methods.find((candidate) => candidate.method === method);
|
|
1963
1988
|
if (current !== undefined) {
|
|
1964
|
-
if (current.exportName === marker.exportName && current.mode === marker.mode && sameInvocation(current.invocation, invocation))
|
|
1989
|
+
if (current.exportName === marker.exportName && current.mode === marker.mode && current.resources === marker.resources && sameInvocation(current.invocation, invocation))
|
|
1965
1990
|
return;
|
|
1966
1991
|
throw new Error(`typert-protocol: Remote method "${method}" has conflicting invocation markers`);
|
|
1967
1992
|
}
|
|
@@ -1986,6 +2011,593 @@ function validateName(subject, value) {
|
|
|
1986
2011
|
}
|
|
1987
2012
|
|
|
1988
2013
|
// node_modules/@deepseek-ai/dsh-util-values/lib/index.js
|
|
2014
|
+
var SIMPLE_ESCAPES = {
|
|
2015
|
+
'"': '"',
|
|
2016
|
+
"\\": "\\",
|
|
2017
|
+
"/": "/",
|
|
2018
|
+
b: "\b",
|
|
2019
|
+
f: "\f",
|
|
2020
|
+
n: `
|
|
2021
|
+
`,
|
|
2022
|
+
r: "\r",
|
|
2023
|
+
t: "\t"
|
|
2024
|
+
};
|
|
2025
|
+
var CONTENT_ESCAPE = /[\\\u0000-\u001f]/u;
|
|
2026
|
+
function isWhitespace(c) {
|
|
2027
|
+
return c === " " || c === `
|
|
2028
|
+
` || c === "\r" || c === "\t";
|
|
2029
|
+
}
|
|
2030
|
+
function isHex(c) {
|
|
2031
|
+
return c >= "0" && c <= "9" || c >= "a" && c <= "f" || c >= "A" && c <= "F";
|
|
2032
|
+
}
|
|
2033
|
+
var PartialArguments = class PartialArguments {
|
|
2034
|
+
static EMPTY = PartialArguments.fromObject({});
|
|
2035
|
+
static fromText(text) {
|
|
2036
|
+
const view = new PartialArguments;
|
|
2037
|
+
view.append(text);
|
|
2038
|
+
view.sealed = true;
|
|
2039
|
+
return view;
|
|
2040
|
+
}
|
|
2041
|
+
static fromObject(value) {
|
|
2042
|
+
const view = new PartialArguments;
|
|
2043
|
+
view.object = typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
2044
|
+
view.sealed = true;
|
|
2045
|
+
return view;
|
|
2046
|
+
}
|
|
2047
|
+
chunks = [];
|
|
2048
|
+
object;
|
|
2049
|
+
sealed = false;
|
|
2050
|
+
#ends = [];
|
|
2051
|
+
#size = 0;
|
|
2052
|
+
#consumed = 0;
|
|
2053
|
+
#mode = "root";
|
|
2054
|
+
#escape = false;
|
|
2055
|
+
#keyStart = 0;
|
|
2056
|
+
#keyEscaped = false;
|
|
2057
|
+
#key = "";
|
|
2058
|
+
#current = null;
|
|
2059
|
+
#nestedEnds = [];
|
|
2060
|
+
#nestedInString = false;
|
|
2061
|
+
#invalidAt;
|
|
2062
|
+
#invalidValue = false;
|
|
2063
|
+
#entries = /* @__PURE__ */ new Map;
|
|
2064
|
+
#order = [];
|
|
2065
|
+
#reads = /* @__PURE__ */ new Map;
|
|
2066
|
+
get isSealed() {
|
|
2067
|
+
return this.sealed;
|
|
2068
|
+
}
|
|
2069
|
+
get invalid() {
|
|
2070
|
+
this.scan();
|
|
2071
|
+
return this.#mode === "invalid" || this.#invalidValue;
|
|
2072
|
+
}
|
|
2073
|
+
append(fragment) {
|
|
2074
|
+
if (this.sealed)
|
|
2075
|
+
throw new Error("PartialArguments: cannot append to a sealed view");
|
|
2076
|
+
if (fragment.length === 0)
|
|
2077
|
+
return;
|
|
2078
|
+
this.chunks.push(fragment);
|
|
2079
|
+
this.#size += fragment.length;
|
|
2080
|
+
this.#ends.push(this.#size);
|
|
2081
|
+
}
|
|
2082
|
+
settle(text) {
|
|
2083
|
+
if (this.object !== undefined || text.length !== this.#size)
|
|
2084
|
+
return PartialArguments.fromText(text);
|
|
2085
|
+
let offset = 0;
|
|
2086
|
+
for (const chunk of this.chunks) {
|
|
2087
|
+
if (!text.startsWith(chunk, offset))
|
|
2088
|
+
return PartialArguments.fromText(text);
|
|
2089
|
+
offset += chunk.length;
|
|
2090
|
+
}
|
|
2091
|
+
this.chunks = text.length === 0 ? [] : [text];
|
|
2092
|
+
this.#ends = text.length === 0 ? [] : [text.length];
|
|
2093
|
+
this.sealed = true;
|
|
2094
|
+
return this;
|
|
2095
|
+
}
|
|
2096
|
+
refresh() {
|
|
2097
|
+
if (this.#reads.size === 0)
|
|
2098
|
+
return false;
|
|
2099
|
+
this.scan();
|
|
2100
|
+
let changed = false;
|
|
2101
|
+
let completions = false;
|
|
2102
|
+
for (const read of this.#reads.values()) {
|
|
2103
|
+
if (read.completion) {
|
|
2104
|
+
completions = true;
|
|
2105
|
+
continue;
|
|
2106
|
+
}
|
|
2107
|
+
changed = this.refreshRead(read) || changed;
|
|
2108
|
+
}
|
|
2109
|
+
if (completions) {
|
|
2110
|
+
for (const read of this.#reads.values())
|
|
2111
|
+
if (read.completion)
|
|
2112
|
+
changed = this.refreshRead(read) || changed;
|
|
2113
|
+
}
|
|
2114
|
+
if (this.sealed)
|
|
2115
|
+
this.#reads.clear();
|
|
2116
|
+
return changed;
|
|
2117
|
+
}
|
|
2118
|
+
refreshRead(read) {
|
|
2119
|
+
const now = read.answer();
|
|
2120
|
+
if (Object.is(now, read.last))
|
|
2121
|
+
return false;
|
|
2122
|
+
read.last = now;
|
|
2123
|
+
return true;
|
|
2124
|
+
}
|
|
2125
|
+
closed() {
|
|
2126
|
+
return this.remember("closed", "", () => this.closedNow());
|
|
2127
|
+
}
|
|
2128
|
+
keys() {
|
|
2129
|
+
return this.remember("keys", "", () => this.keysNow(), (keys) => keys.length);
|
|
2130
|
+
}
|
|
2131
|
+
has(key) {
|
|
2132
|
+
return this.remember("has", key, () => this.hasNow(key));
|
|
2133
|
+
}
|
|
2134
|
+
complete(key) {
|
|
2135
|
+
return this.remember("complete", key, () => this.completeNow(key));
|
|
2136
|
+
}
|
|
2137
|
+
stringLength(key, options) {
|
|
2138
|
+
const step = Math.max(1, Math.floor(options?.step ?? 1));
|
|
2139
|
+
const offset = options?.offset ?? 0;
|
|
2140
|
+
return this.remember(`length:${step}:${offset}`, key, () => this.lengthNow(key), (length) => length === undefined ? undefined : Math.ceil((length + offset) / step));
|
|
2141
|
+
}
|
|
2142
|
+
stringExceeds(key, maxLength) {
|
|
2143
|
+
const limit = Math.max(0, Math.floor(maxLength));
|
|
2144
|
+
return this.remember(`exceeds:${limit}`, key, () => (this.lengthNow(key, limit + 1) ?? 0) > limit);
|
|
2145
|
+
}
|
|
2146
|
+
text(key) {
|
|
2147
|
+
return this.remember("text", key, () => this.textNow(key));
|
|
2148
|
+
}
|
|
2149
|
+
textPrefix(key, maxLength) {
|
|
2150
|
+
const limit = Math.max(1, Math.floor(maxLength));
|
|
2151
|
+
return this.remember(`prefix:${limit}`, key, () => this.textPrefixNow(key, limit));
|
|
2152
|
+
}
|
|
2153
|
+
value(key) {
|
|
2154
|
+
return this.remember("value", key, () => this.valueNow(key));
|
|
2155
|
+
}
|
|
2156
|
+
remember(kind, key, read, comparison) {
|
|
2157
|
+
this.scan();
|
|
2158
|
+
const result = read();
|
|
2159
|
+
if (!this.sealed) {
|
|
2160
|
+
const id = `${kind}/${key}`;
|
|
2161
|
+
if (!this.#reads.has(id))
|
|
2162
|
+
this.#reads.set(id, {
|
|
2163
|
+
completion: kind === "complete",
|
|
2164
|
+
answer: comparison === undefined ? read : () => comparison(read()),
|
|
2165
|
+
last: comparison === undefined ? result : comparison(result)
|
|
2166
|
+
});
|
|
2167
|
+
}
|
|
2168
|
+
return result;
|
|
2169
|
+
}
|
|
2170
|
+
closedNow() {
|
|
2171
|
+
return this.sealed || this.#mode === "closed" || this.#mode === "invalid";
|
|
2172
|
+
}
|
|
2173
|
+
keysNow() {
|
|
2174
|
+
return this.object === undefined ? this.#order : Object.keys(this.object);
|
|
2175
|
+
}
|
|
2176
|
+
hasNow(key) {
|
|
2177
|
+
return this.object === undefined ? this.#entries.has(key) : Object.hasOwn(this.object, key);
|
|
2178
|
+
}
|
|
2179
|
+
completeNow(key) {
|
|
2180
|
+
if (this.object !== undefined)
|
|
2181
|
+
return Object.hasOwn(this.object, key);
|
|
2182
|
+
const entry = this.#entries.get(key);
|
|
2183
|
+
return entry !== undefined && entry.end >= 0 && (entry.kind === "string" ? entry.invalidAt === undefined : !entry.invalid);
|
|
2184
|
+
}
|
|
2185
|
+
lengthNow(key, limit = Number.POSITIVE_INFINITY) {
|
|
2186
|
+
if (this.object !== undefined) {
|
|
2187
|
+
const field = Object.hasOwn(this.object, key) ? this.object[key] : undefined;
|
|
2188
|
+
return typeof field === "string" ? field.length : undefined;
|
|
2189
|
+
}
|
|
2190
|
+
const entry = this.#entries.get(key);
|
|
2191
|
+
if (entry?.kind !== "string")
|
|
2192
|
+
return;
|
|
2193
|
+
if (entry.text !== undefined && entry.text.at === entry.end)
|
|
2194
|
+
return entry.text.length;
|
|
2195
|
+
const read = entry.length ??= {
|
|
2196
|
+
at: entry.start,
|
|
2197
|
+
length: 0,
|
|
2198
|
+
text: ""
|
|
2199
|
+
};
|
|
2200
|
+
this.readString(entry, read, limit, false);
|
|
2201
|
+
return read.length;
|
|
2202
|
+
}
|
|
2203
|
+
textNow(key) {
|
|
2204
|
+
if (this.object !== undefined) {
|
|
2205
|
+
const field = Object.hasOwn(this.object, key) ? this.object[key] : undefined;
|
|
2206
|
+
return typeof field === "string" ? field : undefined;
|
|
2207
|
+
}
|
|
2208
|
+
const entry = this.#entries.get(key);
|
|
2209
|
+
if (entry?.kind !== "string")
|
|
2210
|
+
return;
|
|
2211
|
+
if (entry.text === undefined && entry.end >= 0 && entry.needsDecoding && entry.invalidAt === undefined) {
|
|
2212
|
+
let text;
|
|
2213
|
+
try {
|
|
2214
|
+
text = JSON.parse(`"${this.slice(entry.start, entry.end)}"`);
|
|
2215
|
+
} catch (_error) {}
|
|
2216
|
+
if (text !== undefined)
|
|
2217
|
+
entry.text = {
|
|
2218
|
+
at: entry.end,
|
|
2219
|
+
length: text.length,
|
|
2220
|
+
text
|
|
2221
|
+
};
|
|
2222
|
+
}
|
|
2223
|
+
const read = entry.text ??= {
|
|
2224
|
+
at: entry.start,
|
|
2225
|
+
length: 0,
|
|
2226
|
+
text: ""
|
|
2227
|
+
};
|
|
2228
|
+
this.readString(entry, read, Number.POSITIVE_INFINITY, true);
|
|
2229
|
+
return read.text;
|
|
2230
|
+
}
|
|
2231
|
+
textPrefixNow(key, maxLength) {
|
|
2232
|
+
if (this.object !== undefined) {
|
|
2233
|
+
const field = Object.hasOwn(this.object, key) ? this.object[key] : undefined;
|
|
2234
|
+
return typeof field === "string" ? field.slice(0, maxLength) : undefined;
|
|
2235
|
+
}
|
|
2236
|
+
const entry = this.#entries.get(key);
|
|
2237
|
+
if (entry?.kind !== "string")
|
|
2238
|
+
return;
|
|
2239
|
+
const prefixes = entry.prefixes ??= /* @__PURE__ */ new Map;
|
|
2240
|
+
let read = prefixes.get(maxLength);
|
|
2241
|
+
if (read === undefined) {
|
|
2242
|
+
read = {
|
|
2243
|
+
at: entry.start,
|
|
2244
|
+
length: 0,
|
|
2245
|
+
text: ""
|
|
2246
|
+
};
|
|
2247
|
+
prefixes.set(maxLength, read);
|
|
2248
|
+
}
|
|
2249
|
+
this.readString(entry, read, maxLength, true);
|
|
2250
|
+
return read.text;
|
|
2251
|
+
}
|
|
2252
|
+
valueNow(key) {
|
|
2253
|
+
if (this.object !== undefined) {
|
|
2254
|
+
if (!Object.hasOwn(this.object, key))
|
|
2255
|
+
return;
|
|
2256
|
+
const field = this.object[key];
|
|
2257
|
+
return typeof field === "string" ? undefined : field;
|
|
2258
|
+
}
|
|
2259
|
+
const entry = this.#entries.get(key);
|
|
2260
|
+
if (entry?.kind !== "value" || entry.end < 0 || entry.invalid)
|
|
2261
|
+
return;
|
|
2262
|
+
if (entry.parsed === undefined)
|
|
2263
|
+
try {
|
|
2264
|
+
entry.parsed = JSON.parse(this.slice(entry.start, entry.end));
|
|
2265
|
+
} catch (_error) {
|
|
2266
|
+
entry.invalid = true;
|
|
2267
|
+
this.#invalidValue = true;
|
|
2268
|
+
}
|
|
2269
|
+
return entry.parsed;
|
|
2270
|
+
}
|
|
2271
|
+
chunkAt(at) {
|
|
2272
|
+
let low = 0;
|
|
2273
|
+
let high = this.#ends.length;
|
|
2274
|
+
while (low < high) {
|
|
2275
|
+
const mid = low + high >>> 1;
|
|
2276
|
+
if (this.#ends[mid] <= at)
|
|
2277
|
+
low = mid + 1;
|
|
2278
|
+
else
|
|
2279
|
+
high = mid;
|
|
2280
|
+
}
|
|
2281
|
+
return low;
|
|
2282
|
+
}
|
|
2283
|
+
slice(start, end) {
|
|
2284
|
+
if (start >= end)
|
|
2285
|
+
return "";
|
|
2286
|
+
const first = this.chunkAt(start);
|
|
2287
|
+
const last = this.chunkAt(end - 1);
|
|
2288
|
+
const base = first === 0 ? 0 : this.#ends[first - 1];
|
|
2289
|
+
if (first === last)
|
|
2290
|
+
return this.chunks[first].slice(start - base, end - base);
|
|
2291
|
+
const parts = [this.chunks[first].slice(start - base)];
|
|
2292
|
+
for (let i = first + 1;i < last; i++)
|
|
2293
|
+
parts.push(this.chunks[i]);
|
|
2294
|
+
parts.push(this.chunks[last].slice(0, end - this.#ends[last - 1]));
|
|
2295
|
+
return parts.join("");
|
|
2296
|
+
}
|
|
2297
|
+
readString(entry, read, limit, materialize) {
|
|
2298
|
+
const end = Math.min(entry.end < 0 ? this.#consumed : entry.end, entry.invalidAt ?? Number.POSITIVE_INFINITY, this.#invalidAt ?? Number.POSITIVE_INFINITY);
|
|
2299
|
+
if (!entry.needsDecoding) {
|
|
2300
|
+
const length = Math.min(end - read.at, limit - read.length);
|
|
2301
|
+
if (length <= 0)
|
|
2302
|
+
return;
|
|
2303
|
+
if (materialize)
|
|
2304
|
+
read.text += this.slice(read.at, read.at + length);
|
|
2305
|
+
read.at += length;
|
|
2306
|
+
read.length += length;
|
|
2307
|
+
return;
|
|
2308
|
+
}
|
|
2309
|
+
let chunkIndex = this.chunkAt(read.at);
|
|
2310
|
+
while (read.at < end && read.length < limit) {
|
|
2311
|
+
const base = chunkIndex === 0 ? 0 : this.#ends[chunkIndex - 1];
|
|
2312
|
+
const chunk = this.chunks[chunkIndex];
|
|
2313
|
+
const remaining = chunk.slice(read.at - base, Math.min(chunk.length, end - base));
|
|
2314
|
+
const boundary = remaining.search(CONTENT_ESCAPE);
|
|
2315
|
+
const length = Math.min(boundary < 0 ? remaining.length : boundary, limit - read.length);
|
|
2316
|
+
if (length > 0) {
|
|
2317
|
+
if (materialize)
|
|
2318
|
+
read.text += remaining.slice(0, length);
|
|
2319
|
+
read.at += length;
|
|
2320
|
+
read.length += length;
|
|
2321
|
+
if (read.at === base + chunk.length)
|
|
2322
|
+
chunkIndex++;
|
|
2323
|
+
continue;
|
|
2324
|
+
}
|
|
2325
|
+
const type = remaining.length > 1 ? remaining[1] : read.at + 1 < end ? this.chunks[chunkIndex + 1][0] : undefined;
|
|
2326
|
+
let decoded;
|
|
2327
|
+
let width = 2;
|
|
2328
|
+
if (remaining[0] === "\\" && type === undefined && entry.end < 0)
|
|
2329
|
+
return;
|
|
2330
|
+
if (remaining[0] === "\\" && type === "u") {
|
|
2331
|
+
const hex = this.slice(read.at + 2, Math.min(end, read.at + 6));
|
|
2332
|
+
let valid = true;
|
|
2333
|
+
for (let i = 0;i < hex.length; i++)
|
|
2334
|
+
if (!isHex(hex[i]))
|
|
2335
|
+
valid = false;
|
|
2336
|
+
if (valid) {
|
|
2337
|
+
if (hex.length < 4 && entry.end < 0)
|
|
2338
|
+
return;
|
|
2339
|
+
if (hex.length === 4)
|
|
2340
|
+
decoded = String.fromCharCode(Number.parseInt(hex, 16));
|
|
2341
|
+
}
|
|
2342
|
+
width = 6;
|
|
2343
|
+
} else if (remaining[0] === "\\" && type !== undefined)
|
|
2344
|
+
decoded = SIMPLE_ESCAPES[type];
|
|
2345
|
+
if (decoded === undefined) {
|
|
2346
|
+
entry.invalidAt = read.at;
|
|
2347
|
+
this.#invalidValue = true;
|
|
2348
|
+
return;
|
|
2349
|
+
}
|
|
2350
|
+
if (materialize)
|
|
2351
|
+
read.text += decoded;
|
|
2352
|
+
read.length++;
|
|
2353
|
+
read.at += width;
|
|
2354
|
+
while (chunkIndex < this.chunks.length && read.at >= this.#ends[chunkIndex])
|
|
2355
|
+
chunkIndex++;
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
scan() {
|
|
2359
|
+
if (this.object !== undefined || this.#consumed === this.#size)
|
|
2360
|
+
return;
|
|
2361
|
+
for (let i = this.chunkAt(this.#consumed);i < this.chunks.length && this.#invalidAt === undefined; i++) {
|
|
2362
|
+
const pending = this.chunks[i];
|
|
2363
|
+
const base = i === 0 ? 0 : this.#ends[i - 1];
|
|
2364
|
+
for (let index = this.#consumed - base;index < pending.length && this.#mode !== "invalid"; index++) {
|
|
2365
|
+
if (this.#mode === "string" || this.#mode === "nested" && this.#nestedInString) {
|
|
2366
|
+
const end = this.stringBoundary(pending, index);
|
|
2367
|
+
this.#consumed += end - index;
|
|
2368
|
+
index = end;
|
|
2369
|
+
if (index === pending.length)
|
|
2370
|
+
break;
|
|
2371
|
+
}
|
|
2372
|
+
this.step(pending[index], this.#consumed);
|
|
2373
|
+
this.#consumed++;
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
stringBoundary(fragment, start) {
|
|
2378
|
+
let at = start;
|
|
2379
|
+
while (true) {
|
|
2380
|
+
const quote = fragment.indexOf('"', at);
|
|
2381
|
+
const end = quote < 0 ? fragment.length : quote;
|
|
2382
|
+
if (this.#mode === "string") {
|
|
2383
|
+
const entry = this.#current;
|
|
2384
|
+
if (!entry.needsDecoding && CONTENT_ESCAPE.test(fragment.slice(at, end)))
|
|
2385
|
+
entry.needsDecoding = true;
|
|
2386
|
+
}
|
|
2387
|
+
let slashStart = end;
|
|
2388
|
+
while (slashStart > at && fragment[slashStart - 1] === "\\")
|
|
2389
|
+
slashStart--;
|
|
2390
|
+
const escaped = (end - slashStart) % 2 === 1 !== (slashStart === at && this.#escape);
|
|
2391
|
+
this.#escape = quote < 0 && escaped;
|
|
2392
|
+
if (quote < 0 || !escaped)
|
|
2393
|
+
return end;
|
|
2394
|
+
at = quote + 1;
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
step(c, at) {
|
|
2398
|
+
switch (this.#mode) {
|
|
2399
|
+
case "root":
|
|
2400
|
+
if (isWhitespace(c))
|
|
2401
|
+
return;
|
|
2402
|
+
if (c === "{") {
|
|
2403
|
+
this.#mode = "key-or-end";
|
|
2404
|
+
return;
|
|
2405
|
+
}
|
|
2406
|
+
this.fail();
|
|
2407
|
+
return;
|
|
2408
|
+
case "key-or-end":
|
|
2409
|
+
if (isWhitespace(c))
|
|
2410
|
+
return;
|
|
2411
|
+
if (c === "}") {
|
|
2412
|
+
this.#mode = "closed";
|
|
2413
|
+
return;
|
|
2414
|
+
}
|
|
2415
|
+
if (c === '"') {
|
|
2416
|
+
this.beginKey(at);
|
|
2417
|
+
return;
|
|
2418
|
+
}
|
|
2419
|
+
this.fail();
|
|
2420
|
+
return;
|
|
2421
|
+
case "key-only":
|
|
2422
|
+
if (isWhitespace(c))
|
|
2423
|
+
return;
|
|
2424
|
+
if (c === '"') {
|
|
2425
|
+
this.beginKey(at);
|
|
2426
|
+
return;
|
|
2427
|
+
}
|
|
2428
|
+
this.fail();
|
|
2429
|
+
return;
|
|
2430
|
+
case "key":
|
|
2431
|
+
this.stepKey(c, at);
|
|
2432
|
+
return;
|
|
2433
|
+
case "colon":
|
|
2434
|
+
if (isWhitespace(c))
|
|
2435
|
+
return;
|
|
2436
|
+
if (c === ":") {
|
|
2437
|
+
this.#mode = "value";
|
|
2438
|
+
return;
|
|
2439
|
+
}
|
|
2440
|
+
this.fail();
|
|
2441
|
+
return;
|
|
2442
|
+
case "value":
|
|
2443
|
+
this.beginValue(c, at);
|
|
2444
|
+
return;
|
|
2445
|
+
case "string": {
|
|
2446
|
+
const entry = this.#current;
|
|
2447
|
+
entry.end = at;
|
|
2448
|
+
this.#current = null;
|
|
2449
|
+
this.#mode = "comma-or-end";
|
|
2450
|
+
return;
|
|
2451
|
+
}
|
|
2452
|
+
case "scalar":
|
|
2453
|
+
this.stepScalar(c, at);
|
|
2454
|
+
return;
|
|
2455
|
+
case "nested":
|
|
2456
|
+
this.stepNested(c, at);
|
|
2457
|
+
return;
|
|
2458
|
+
case "comma-or-end":
|
|
2459
|
+
if (isWhitespace(c))
|
|
2460
|
+
return;
|
|
2461
|
+
if (c === ",") {
|
|
2462
|
+
this.#mode = "key-only";
|
|
2463
|
+
return;
|
|
2464
|
+
}
|
|
2465
|
+
if (c === "}") {
|
|
2466
|
+
this.#mode = "closed";
|
|
2467
|
+
return;
|
|
2468
|
+
}
|
|
2469
|
+
this.fail();
|
|
2470
|
+
return;
|
|
2471
|
+
case "closed":
|
|
2472
|
+
if (isWhitespace(c))
|
|
2473
|
+
return;
|
|
2474
|
+
this.fail();
|
|
2475
|
+
return;
|
|
2476
|
+
case "invalid":
|
|
2477
|
+
return;
|
|
2478
|
+
default:
|
|
2479
|
+
assertNever(this.#mode);
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
fail() {
|
|
2483
|
+
this.#invalidAt = this.#consumed;
|
|
2484
|
+
this.#mode = "invalid";
|
|
2485
|
+
this.#current = null;
|
|
2486
|
+
}
|
|
2487
|
+
beginKey(at) {
|
|
2488
|
+
this.#mode = "key";
|
|
2489
|
+
this.#keyStart = at + 1;
|
|
2490
|
+
this.#keyEscaped = false;
|
|
2491
|
+
this.#escape = false;
|
|
2492
|
+
}
|
|
2493
|
+
stepKey(c, at) {
|
|
2494
|
+
if (c < " ") {
|
|
2495
|
+
this.fail();
|
|
2496
|
+
return;
|
|
2497
|
+
}
|
|
2498
|
+
if (this.#escape) {
|
|
2499
|
+
this.#escape = false;
|
|
2500
|
+
return;
|
|
2501
|
+
}
|
|
2502
|
+
if (c === "\\") {
|
|
2503
|
+
this.#escape = true;
|
|
2504
|
+
this.#keyEscaped = true;
|
|
2505
|
+
return;
|
|
2506
|
+
}
|
|
2507
|
+
if (c !== '"')
|
|
2508
|
+
return;
|
|
2509
|
+
const raw = this.slice(this.#keyStart, at);
|
|
2510
|
+
if (this.#keyEscaped)
|
|
2511
|
+
try {
|
|
2512
|
+
this.#key = JSON.parse(`"${raw}"`);
|
|
2513
|
+
} catch (_error) {
|
|
2514
|
+
this.fail();
|
|
2515
|
+
return;
|
|
2516
|
+
}
|
|
2517
|
+
else
|
|
2518
|
+
this.#key = raw;
|
|
2519
|
+
this.#mode = "colon";
|
|
2520
|
+
}
|
|
2521
|
+
open(entry) {
|
|
2522
|
+
if (!this.#entries.has(this.#key))
|
|
2523
|
+
this.#order.push(this.#key);
|
|
2524
|
+
this.#entries.set(this.#key, entry);
|
|
2525
|
+
this.#current = entry;
|
|
2526
|
+
}
|
|
2527
|
+
beginValue(c, at) {
|
|
2528
|
+
if (isWhitespace(c))
|
|
2529
|
+
return;
|
|
2530
|
+
if (c === '"') {
|
|
2531
|
+
this.open({
|
|
2532
|
+
kind: "string",
|
|
2533
|
+
start: at + 1,
|
|
2534
|
+
end: -1,
|
|
2535
|
+
needsDecoding: false,
|
|
2536
|
+
invalidAt: undefined,
|
|
2537
|
+
length: undefined,
|
|
2538
|
+
text: undefined,
|
|
2539
|
+
prefixes: undefined
|
|
2540
|
+
});
|
|
2541
|
+
this.#escape = false;
|
|
2542
|
+
this.#mode = "string";
|
|
2543
|
+
return;
|
|
2544
|
+
}
|
|
2545
|
+
if (c === "}" || c === "," || c === ":" || c === "]") {
|
|
2546
|
+
this.fail();
|
|
2547
|
+
return;
|
|
2548
|
+
}
|
|
2549
|
+
this.open({
|
|
2550
|
+
kind: "value",
|
|
2551
|
+
start: at,
|
|
2552
|
+
end: -1,
|
|
2553
|
+
parsed: undefined,
|
|
2554
|
+
invalid: false
|
|
2555
|
+
});
|
|
2556
|
+
if (c === "{" || c === "[") {
|
|
2557
|
+
this.#mode = "nested";
|
|
2558
|
+
this.#nestedEnds = [c === "{" ? "}" : "]"];
|
|
2559
|
+
this.#nestedInString = false;
|
|
2560
|
+
this.#escape = false;
|
|
2561
|
+
return;
|
|
2562
|
+
}
|
|
2563
|
+
this.#mode = "scalar";
|
|
2564
|
+
}
|
|
2565
|
+
stepScalar(c, at) {
|
|
2566
|
+
if (c !== "," && c !== "}" && !isWhitespace(c))
|
|
2567
|
+
return;
|
|
2568
|
+
this.closeValue(at);
|
|
2569
|
+
this.#mode = c === "," ? "key-only" : c === "}" ? "closed" : "comma-or-end";
|
|
2570
|
+
}
|
|
2571
|
+
stepNested(c, at) {
|
|
2572
|
+
if (this.#nestedInString) {
|
|
2573
|
+
this.#nestedInString = false;
|
|
2574
|
+
return;
|
|
2575
|
+
}
|
|
2576
|
+
if (c === '"') {
|
|
2577
|
+
this.#nestedInString = true;
|
|
2578
|
+
return;
|
|
2579
|
+
}
|
|
2580
|
+
if (c === "{" || c === "[") {
|
|
2581
|
+
this.#nestedEnds.push(c === "{" ? "}" : "]");
|
|
2582
|
+
return;
|
|
2583
|
+
}
|
|
2584
|
+
if (c === "}" || c === "]") {
|
|
2585
|
+
if (this.#nestedEnds.pop() !== c) {
|
|
2586
|
+
this.fail();
|
|
2587
|
+
return;
|
|
2588
|
+
}
|
|
2589
|
+
if (this.#nestedEnds.length === 0) {
|
|
2590
|
+
this.closeValue(at + 1);
|
|
2591
|
+
this.#mode = "comma-or-end";
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
closeValue(end) {
|
|
2596
|
+
const entry = this.#current;
|
|
2597
|
+
entry.end = end;
|
|
2598
|
+
this.#current = null;
|
|
2599
|
+
}
|
|
2600
|
+
};
|
|
1989
2601
|
function assertNever(value, context) {
|
|
1990
2602
|
const rendered = JSON.stringify(value) ?? String(value);
|
|
1991
2603
|
throw new Error(`unreachable variant${context ? ` in ${context}` : ""}: ${rendered}`);
|
|
@@ -2031,7 +2643,7 @@ function deepFreeze(value) {
|
|
|
2031
2643
|
return value;
|
|
2032
2644
|
}
|
|
2033
2645
|
|
|
2034
|
-
// node_modules/@deepseek-ai/dsh-util-crypto/lib/index.js
|
|
2646
|
+
// node_modules/@deepseek-ai/dsh-llm/node_modules/@deepseek-ai/dsh-util-crypto/lib/index.js
|
|
2035
2647
|
function randomUUID() {
|
|
2036
2648
|
const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16));
|
|
2037
2649
|
const hex = Array.from(bytes, (byte, index) => {
|
|
@@ -2048,7 +2660,7 @@ function brandString(value) {
|
|
|
2048
2660
|
// node_modules/@deepseek-ai/dsh-llm/lib/index.js
|
|
2049
2661
|
import z from "@deepseek-ai/schemastery";
|
|
2050
2662
|
|
|
2051
|
-
// node_modules/@deepseek-ai/dsh-timeout/lib/index.js
|
|
2663
|
+
// node_modules/@deepseek-ai/dsh-llm/node_modules/@deepseek-ai/dsh-timeout/lib/index.js
|
|
2052
2664
|
var MAX_TIMER_DELAY_MS = 2147483647;
|
|
2053
2665
|
|
|
2054
2666
|
// node_modules/@deepseek-ai/dsh-llm/lib/index.js
|
|
@@ -2564,7 +3176,6 @@ var LlmRuntime = (() => {
|
|
|
2564
3176
|
super(ctx, "llm");
|
|
2565
3177
|
}
|
|
2566
3178
|
emitAdaptersUpdated() {
|
|
2567
|
-
let invariantFailure;
|
|
2568
3179
|
for (const listener of this.ctx.events.dispatch("emit", ["llm/adapters-updated"]))
|
|
2569
3180
|
try {
|
|
2570
3181
|
const returned = listener();
|
|
@@ -2573,14 +3184,8 @@ var LlmRuntime = (() => {
|
|
|
2573
3184
|
this.warnAdaptersListenerFailure(error);
|
|
2574
3185
|
});
|
|
2575
3186
|
} catch (error) {
|
|
2576
|
-
if (error?.code === "INVARIANT") {
|
|
2577
|
-
invariantFailure ??= error;
|
|
2578
|
-
continue;
|
|
2579
|
-
}
|
|
2580
3187
|
this.warnAdaptersListenerFailure(error);
|
|
2581
3188
|
}
|
|
2582
|
-
if (invariantFailure !== undefined)
|
|
2583
|
-
throw invariantFailure;
|
|
2584
3189
|
}
|
|
2585
3190
|
warnAdaptersListenerFailure(error) {
|
|
2586
3191
|
this.ctx.logger.warn("llm: an llm/adapters-updated listener failed");
|
|
@@ -2659,10 +3264,7 @@ var LlmRuntime = (() => {
|
|
|
2659
3264
|
throw new LlmError(`configurable provider "${entry.provider}" has an empty settingsPath segment`, "INVALID_DIRECTORY");
|
|
2660
3265
|
if (this.directory.has(entry.provider) && !own.has(entry.provider) || detached.some((seen) => seen.provider === entry.provider))
|
|
2661
3266
|
throw new LlmError(`configurable provider "${entry.provider}" is already declared`, "DUPLICATE_DIRECTORY");
|
|
2662
|
-
detached.push(
|
|
2663
|
-
...entry,
|
|
2664
|
-
settingsPath: [...entry.settingsPath]
|
|
2665
|
-
});
|
|
3267
|
+
detached.push(detachDirectoryEntry(entry));
|
|
2666
3268
|
}
|
|
2667
3269
|
for (const entry of held)
|
|
2668
3270
|
this.directory.delete(entry.provider);
|
|
@@ -2692,10 +3294,7 @@ var LlmRuntime = (() => {
|
|
|
2692
3294
|
return handle;
|
|
2693
3295
|
}
|
|
2694
3296
|
listConfigurableProviders() {
|
|
2695
|
-
return [...this.directory.values()].map(
|
|
2696
|
-
...entry,
|
|
2697
|
-
settingsPath: [...entry.settingsPath]
|
|
2698
|
-
}));
|
|
3297
|
+
return [...this.directory.values()].map(detachDirectoryEntry);
|
|
2699
3298
|
}
|
|
2700
3299
|
registerModelDiscovery(settingsNs, discover) {
|
|
2701
3300
|
const dispose = this.ctx.effect(function* () {
|
|
@@ -2749,6 +3348,9 @@ var LlmRuntime = (() => {
|
|
|
2749
3348
|
imageRequestPricing(provider, model) {
|
|
2750
3349
|
return this.adapters.get(provider)?.adapter.imageRequestPricing(provider, model);
|
|
2751
3350
|
}
|
|
3351
|
+
imageRequestTarget(provider, model, image) {
|
|
3352
|
+
return this.registration(provider).adapter.imageRequestTarget(provider, model, image);
|
|
3353
|
+
}
|
|
2752
3354
|
fileRequestText(ref) {
|
|
2753
3355
|
return fileHandleText(ref, this.fileReadPath(ref));
|
|
2754
3356
|
}
|
|
@@ -2763,12 +3365,17 @@ var LlmRuntime = (() => {
|
|
|
2763
3365
|
throw new LlmError(`adapter returned invalid or duplicate model metadata for provider "${provider}"`, "INVALID_CATALOG");
|
|
2764
3366
|
seen.add(model.id);
|
|
2765
3367
|
const inputModalities = this.detachedModalities(model.inputModalities);
|
|
3368
|
+
const badge = model.badge;
|
|
2766
3369
|
return {
|
|
2767
3370
|
provider: model.provider,
|
|
2768
3371
|
id: model.id,
|
|
2769
3372
|
name: model.name,
|
|
2770
3373
|
...model.description === undefined ? {} : { description: model.description },
|
|
2771
|
-
...inputModalities === undefined ? {} : { inputModalities }
|
|
3374
|
+
...inputModalities === undefined ? {} : { inputModalities },
|
|
3375
|
+
...badge === undefined ? {} : { badge: {
|
|
3376
|
+
text: typeof badge.text === "string" ? badge.text : { ...badge.text },
|
|
3377
|
+
tone: badge.tone
|
|
3378
|
+
} }
|
|
2772
3379
|
};
|
|
2773
3380
|
});
|
|
2774
3381
|
}
|
|
@@ -2869,16 +3476,25 @@ var LlmRuntime = (() => {
|
|
|
2869
3476
|
modelInfo: info
|
|
2870
3477
|
};
|
|
2871
3478
|
}
|
|
2872
|
-
async prepareCall(config, signal) {
|
|
2873
|
-
|
|
2874
|
-
const
|
|
2875
|
-
const
|
|
2876
|
-
const
|
|
3479
|
+
async prepareCall(config, signal, configure) {
|
|
3480
|
+
signal?.throwIfAborted();
|
|
3481
|
+
const { provider, model, ...controls } = config;
|
|
3482
|
+
const registration = this.registration(provider);
|
|
3483
|
+
const adapterCall = await registration.adapter.prepareCall(provider, model, signal);
|
|
3484
|
+
signal?.throwIfAborted();
|
|
3485
|
+
const modelInfo = this.normalizeModelInfo(registration, model, adapterCall.model);
|
|
3486
|
+
const proposed = configure === undefined ? config : {
|
|
3487
|
+
...configure(deepFreeze(structuredClone(controls)), deepFreeze(modelInfo)),
|
|
3488
|
+
provider,
|
|
3489
|
+
model
|
|
3490
|
+
};
|
|
3491
|
+
signal?.throwIfAborted();
|
|
3492
|
+
const resolved = this.resolveCallWithInfo(proposed, modelInfo);
|
|
2877
3493
|
const resolvedConfig = deepFreeze(structuredClone(resolved.config));
|
|
2878
3494
|
const context = resolved.context === undefined ? undefined : deepFreeze(structuredClone(resolved.context));
|
|
2879
3495
|
const adapterDefaults = deepFreeze({
|
|
2880
|
-
...
|
|
2881
|
-
...
|
|
3496
|
+
...proposed.reasoningEffort === undefined && resolvedConfig.reasoningEffort !== undefined ? { reasoningEffort: true } : {},
|
|
3497
|
+
...proposed.maxTokens === undefined && resolvedConfig.maxTokens !== undefined ? { maxTokens: true } : {}
|
|
2882
3498
|
});
|
|
2883
3499
|
let dispatched = false;
|
|
2884
3500
|
return Object.freeze({
|
|
@@ -3046,6 +3662,18 @@ function adapterFailureChunk(error, signal) {
|
|
|
3046
3662
|
}
|
|
3047
3663
|
};
|
|
3048
3664
|
}
|
|
3665
|
+
function detachDirectoryEntry(entry) {
|
|
3666
|
+
const { nativeAuth } = entry;
|
|
3667
|
+
return {
|
|
3668
|
+
...entry,
|
|
3669
|
+
settingsPath: [...entry.settingsPath],
|
|
3670
|
+
...entry.baseURLEnv === undefined ? {} : { baseURLEnv: [...entry.baseURLEnv] },
|
|
3671
|
+
...nativeAuth === undefined ? {} : { nativeAuth: {
|
|
3672
|
+
...nativeAuth,
|
|
3673
|
+
env: [...nativeAuth.env]
|
|
3674
|
+
} }
|
|
3675
|
+
};
|
|
3676
|
+
}
|
|
3049
3677
|
|
|
3050
3678
|
// src/todo-nudge.ts
|
|
3051
3679
|
var NUDGE_TEXT = "委派结果已返回:立刻 todo_write 回写对应项状态(整表覆盖,保留未动项),再继续下一步。";
|
|
@@ -3345,42 +3973,24 @@ async function startSubagentRunOnce(ctx, provider, spec) {
|
|
|
3345
3973
|
if (signal === undefined) {
|
|
3346
3974
|
ctx?.logger?.warn?.("[cohub] startSubagentRun 无可用 signal:子运行不可中止(父轮停止无法回收)");
|
|
3347
3975
|
}
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
provider,
|
|
3352
|
-
label: spec.label,
|
|
3353
|
-
request: {
|
|
3354
|
-
prompt,
|
|
3355
|
-
parent: spec.parent,
|
|
3356
|
-
...spec.agentPreset !== undefined ? { agentPreset: spec.agentPreset } : {},
|
|
3357
|
-
...spec.agentOptions !== undefined ? { agentOptions: spec.agentOptions } : {},
|
|
3358
|
-
...spec.toolFilter !== undefined ? { toolFilter: spec.toolFilter } : {}
|
|
3359
|
-
},
|
|
3360
|
-
...signal !== undefined ? { signal } : {},
|
|
3361
|
-
delivery: "caller"
|
|
3362
|
-
});
|
|
3363
|
-
applyChildToolFilterDirectly(ctx, receipt.childId, spec.toolFilter, spec.degradeNotes);
|
|
3364
|
-
return {
|
|
3365
|
-
id: receipt.childId,
|
|
3366
|
-
result: receipt.result,
|
|
3367
|
-
dispose: () => receipt.dispose()
|
|
3368
|
-
};
|
|
3369
|
-
}
|
|
3370
|
-
const run = await subagents.start(provider, {
|
|
3976
|
+
const prompt = spec.persona !== undefined ? [{ type: "text", text: spec.persona }, ...spec.prompt] : spec.prompt;
|
|
3977
|
+
const receipt = await subagents.startActivation({
|
|
3978
|
+
provider,
|
|
3371
3979
|
label: spec.label,
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
...signal !== undefined ? { signal } : {}
|
|
3980
|
+
request: {
|
|
3981
|
+
prompt,
|
|
3982
|
+
parent: spec.parent,
|
|
3983
|
+
...spec.agentPreset !== undefined ? { agentPreset: spec.agentPreset } : {},
|
|
3984
|
+
...spec.agentOptions !== undefined ? { agentOptions: spec.agentOptions } : {}
|
|
3985
|
+
},
|
|
3986
|
+
...signal !== undefined ? { signal } : {},
|
|
3987
|
+
delivery: "caller"
|
|
3379
3988
|
});
|
|
3989
|
+
applyChildToolFilterDirectly(ctx, receipt.childId, spec.toolFilter, spec.degradeNotes);
|
|
3380
3990
|
return {
|
|
3381
|
-
id:
|
|
3382
|
-
result:
|
|
3383
|
-
dispose: () =>
|
|
3991
|
+
id: receipt.childId,
|
|
3992
|
+
result: receipt.result,
|
|
3993
|
+
dispose: () => receipt.dispose()
|
|
3384
3994
|
};
|
|
3385
3995
|
}
|
|
3386
3996
|
function createEnvContract(config) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cohub",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "DeepSeek Harness 版 CoHub:中文智能体编排——用户可选 2 种工作模式(co-orchestrator 纯调度 / cohub-cordis 创造模式)+ 13 个专职代理技能 + 多模型共识;另由 cohub-subagent-readonly / cohub-subagent-write 两个支撑 preset 实现子代理读写硬隔离(共 4 个 preset)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -43,21 +43,22 @@
|
|
|
43
43
|
"typecheck:0.2": "bunx tsc --noEmit -p test/tsconfig.runtime-0.2.json",
|
|
44
44
|
"typecheck:src": "bunx tsc --noEmit -p tsconfig.typecheck.json",
|
|
45
45
|
"typecheck": "bun run typecheck:src && bun run typecheck:0.2",
|
|
46
|
+
"prepublish-check": "bun run scripts/prepublish-check.ts",
|
|
46
47
|
"prepublishOnly": "npm run build",
|
|
47
48
|
"build:client": "bun run scripts/build-client.js",
|
|
48
49
|
"audit": "node scripts/audit-session.mjs"
|
|
49
50
|
},
|
|
50
51
|
"peerDependencies": {
|
|
51
|
-
"@deepseek-ai/cordis": "^4.0
|
|
52
|
-
"@deepseek-ai/schemastery": "^3.
|
|
53
|
-
"@deepseek-ai/dsh-system-prompt": "^0.2.
|
|
54
|
-
"@deepseek-ai/dsh-skill": "^0.2.
|
|
55
|
-
"@deepseek-ai/dsh-tools": "^0.2.
|
|
56
|
-
"@deepseek-ai/dsh-home-paths": "^0.2.
|
|
57
|
-
"@deepseek-ai/dsh-subagent": "^0.2.
|
|
58
|
-
"@deepseek-ai/dsh-llm": "^0.2.
|
|
59
|
-
"@deepseek-ai/dsh-session-projection": "^0.2.
|
|
60
|
-
"@deepseek-ai/dsh-client-locale": "^0.2.
|
|
52
|
+
"@deepseek-ai/cordis": "^4.1.0",
|
|
53
|
+
"@deepseek-ai/schemastery": "^3.19.0",
|
|
54
|
+
"@deepseek-ai/dsh-system-prompt": "^0.2.2-rc.1",
|
|
55
|
+
"@deepseek-ai/dsh-skill": "^0.2.2-rc.1",
|
|
56
|
+
"@deepseek-ai/dsh-tools": "^0.2.2-rc.1",
|
|
57
|
+
"@deepseek-ai/dsh-home-paths": "^0.2.2-rc.1",
|
|
58
|
+
"@deepseek-ai/dsh-subagent": "^0.2.2-rc.1",
|
|
59
|
+
"@deepseek-ai/dsh-llm": "^0.2.2-rc.1",
|
|
60
|
+
"@deepseek-ai/dsh-session-projection": "^0.2.2-rc.1",
|
|
61
|
+
"@deepseek-ai/dsh-client-locale": "^0.2.2-rc.1"
|
|
61
62
|
},
|
|
62
63
|
"peerDependenciesMeta": {
|
|
63
64
|
"@deepseek-ai/cordis": {
|
|
@@ -77,20 +78,23 @@
|
|
|
77
78
|
}
|
|
78
79
|
},
|
|
79
80
|
"devDependencies": {
|
|
80
|
-
"@deepseek-ai/cordis": "4.0
|
|
81
|
-
"@deepseek-ai/schemastery": "3.
|
|
82
|
-
"@deepseek-ai/dsh-system-prompt": "0.2.
|
|
83
|
-
"@deepseek-ai/dsh-skill": "0.2.
|
|
84
|
-
"@deepseek-ai/dsh-tools": "0.2.
|
|
85
|
-
"@deepseek-ai/dsh-home-paths": "0.2.
|
|
86
|
-
"@deepseek-ai/dsh-subagent": "0.2.
|
|
87
|
-
"@deepseek-ai/dsh-settings": "0.2.
|
|
88
|
-
"@deepseek-ai/dsh-session-projection": "0.2.
|
|
89
|
-
"@deepseek-ai/dsh-app-boot": "0.2.
|
|
90
|
-
"@deepseek-ai/dsh-config-editor": "0.2.
|
|
91
|
-
"@deepseek-ai/
|
|
92
|
-
"@deepseek-ai/
|
|
93
|
-
"@deepseek-ai/cordis-plugin-
|
|
81
|
+
"@deepseek-ai/cordis": "4.1.0",
|
|
82
|
+
"@deepseek-ai/schemastery": "3.19.0",
|
|
83
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.2-rc.1",
|
|
84
|
+
"@deepseek-ai/dsh-skill": "0.2.2-rc.1",
|
|
85
|
+
"@deepseek-ai/dsh-tools": "0.2.2-rc.1",
|
|
86
|
+
"@deepseek-ai/dsh-home-paths": "0.2.2-rc.1",
|
|
87
|
+
"@deepseek-ai/dsh-subagent": "0.2.2-rc.1",
|
|
88
|
+
"@deepseek-ai/dsh-settings": "0.2.2-rc.1",
|
|
89
|
+
"@deepseek-ai/dsh-session-projection": "0.2.2-rc.1",
|
|
90
|
+
"@deepseek-ai/dsh-app-boot": "0.2.2-rc.1",
|
|
91
|
+
"@deepseek-ai/dsh-config-editor": "0.2.2-rc.1",
|
|
92
|
+
"@deepseek-ai/dsh-fs": "0.2.2-rc.1",
|
|
93
|
+
"@deepseek-ai/dsh-working-directory": "0.2.2-rc.1",
|
|
94
|
+
"@deepseek-ai/cordis-plugin-loader": "1.1.0",
|
|
95
|
+
"@deepseek-ai/cordis-plugin-include": "1.1.0",
|
|
96
|
+
"@deepseek-ai/cordis-plugin-group": "1.1.0",
|
|
97
|
+
"@deepseek-ai/cordis-plugin-timer": "1.2.0",
|
|
94
98
|
"@types/node": "^24.0.0"
|
|
95
99
|
},
|
|
96
100
|
"license": "MIT",
|
|
@@ -88,9 +88,6 @@
|
|
|
88
88
|
- id: tool-subagent-control
|
|
89
89
|
name: '@deepseek-ai/dsh-tool-subagent-control'
|
|
90
90
|
|
|
91
|
-
- id: tool-subagent-list-agents
|
|
92
|
-
name: '@deepseek-ai/dsh-tool-subagent-control/list-agents'
|
|
93
|
-
|
|
94
91
|
- id: tool-subagent
|
|
95
92
|
name: '@deepseek-ai/dsh-tool-subagent'
|
|
96
93
|
config:
|
|
@@ -208,9 +208,6 @@
|
|
|
208
208
|
- id: tool-subagent-control
|
|
209
209
|
name: '@deepseek-ai/dsh-tool-subagent-control'
|
|
210
210
|
|
|
211
|
-
- id: tool-subagent-list-agents
|
|
212
|
-
name: '@deepseek-ai/dsh-tool-subagent-control/list-agents'
|
|
213
|
-
|
|
214
211
|
- id: tool-subagent
|
|
215
212
|
name: '@deepseek-ai/dsh-tool-subagent'
|
|
216
213
|
config:
|
|
@@ -88,8 +88,8 @@ When a preset genuinely owns a service, wrap the provider **and every consumer t
|
|
|
88
88
|
isolate:
|
|
89
89
|
workflows: true
|
|
90
90
|
config:
|
|
91
|
-
- id: workflow-
|
|
92
|
-
name: '@deepseek-ai/dsh-workflow-
|
|
91
|
+
- id: workflow-ptc
|
|
92
|
+
name: '@deepseek-ai/dsh-workflow-ptc'
|
|
93
93
|
config:
|
|
94
94
|
provider: spawn
|
|
95
95
|
- id: tool-workflow
|