dsh-lean-router 0.0.0-stage → 0.2.4
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/LICENSE +21 -0
- package/NOTICE.md +23 -0
- package/README.en.md +73 -0
- package/README.md +72 -2
- package/cordis.patch.yml +870 -0
- package/docs/adr/0001-token-ledger-durable-usage.md +11 -0
- package/docs/agents/domain.md +38 -0
- package/docs/agents/issue-tracker.md +44 -0
- package/docs/agents/release.md +24 -0
- package/docs/agents/triage-labels.md +13 -0
- package/docs/agents/verification.md +32 -0
- package/docs/architecture.en.md +67 -0
- package/docs/architecture.md +66 -0
- package/docs/changelog.en.md +279 -0
- package/docs/changelog.md +282 -0
- package/docs/configuration.en.md +57 -0
- package/docs/configuration.md +57 -0
- package/docs/install.en.md +60 -0
- package/docs/install.md +60 -0
- package/docs/quickstart.en.md +75 -0
- package/docs/quickstart.md +75 -0
- package/docs/release-checklist.en.md +82 -0
- package/docs/release-checklist.md +131 -0
- package/docs//345/244/215/346/240/270-/345/205/263/346/217/222/344/273/266/346/270/205/345/215/225.md +108 -0
- package/docs//345/267/245/345/205/267/351/201/256/350/224/275-/346/216/245/347/272/277/350/257/264/346/230/216.md +140 -0
- package/docs//350/267/257/347/224/261-/350/256/276/350/256/241/350/257/264/346/230/216.md +104 -0
- package/lib/bands.js +149 -0
- package/lib/index.js +12 -0
- package/lib/lean/compaction.js +119 -0
- package/lib/lean/delivery-gate.js +312 -0
- package/lib/lean/disabled.js +61 -0
- package/lib/lean/history-budget.js +301 -0
- package/lib/lean/history-downgrade.js +345 -0
- package/lib/lean/index.js +19 -0
- package/lib/lean/output-slim.js +271 -0
- package/lib/lean/persona-text.js +111 -0
- package/lib/lean/plan-mode.js +31 -0
- package/lib/lean/pruner.js +75 -0
- package/lib/lean/tool-concurrency.js +319 -0
- package/lib/lean/usage-ledger.js +442 -0
- package/lib/router.js +287 -0
- package/lib/token-ledger/index.js +147 -0
- package/lib/token-ledger/live.js +193 -0
- package/lib/toolface/desc-slim.js +140 -0
- package/lib/toolface/discovery.js +297 -0
- package/lib/toolface/executor.js +333 -0
- package/lib/toolface/index.js +250 -0
- package/lib/toolface/pool.js +160 -0
- package/lib/toolface/retention.js +187 -0
- package/lib/toolface/rules.js +435 -0
- package/lib/toolface/scope.js +188 -0
- package/lib/toolface/transport.js +335 -0
- package/package.json +65 -4
- package/presets/base/frag-lean.patch.yml +459 -0
- package/presets/base/frag-preset.patch.yml +274 -0
- package/presets/base/frag-router.patch.yml +17 -0
- package/presets/base/frag-toolface.patch.yml +73 -0
- package/presets/base/lean-router.patch.yml +44 -0
- package/scripts/build-bundle.mjs +45 -0
- package/scripts/doctor.mjs +35 -0
- package/scripts/install-profile.mjs +113 -0
- package/scripts/install.mjs +20 -0
- package/scripts/integrate-preset.mjs +107 -0
- package/scripts/release.mjs +146 -0
- package/scripts/verify.mjs +8 -0
- package/test/build.test.mjs +7 -0
- package/test/history-budget.test.mjs +210 -0
- package/test/history-downgrade.test.mjs +379 -0
- package/test/integration-preset.test.mjs +59 -0
- package/test/lean-compaction.test.mjs +47 -0
- package/test/lean-concurrency.test.mjs +117 -0
- package/test/lean-delivery-gate.test.mjs +75 -0
- package/test/lean-frag.test.mjs +132 -0
- package/test/lean-modules.test.mjs +112 -0
- package/test/lean-pruner.test.mjs +42 -0
- package/test/output-slim.test.mjs +212 -0
- package/test/package.test.mjs +20 -0
- package/test/patch-yaml.test.mjs +45 -0
- package/test/plugin-entry.test.mjs +26 -0
- package/test/router-bands.test.mjs +98 -0
- package/test/router.test.mjs +215 -0
- package/test/token-ledger-live.test.mjs +351 -0
- package/test/token-ledger.test.mjs +264 -0
- package/test/toolface-desc-slim.test.mjs +255 -0
- package/test/toolface-executor.test.mjs +302 -0
- package/test/toolface-mask.test.mjs +258 -0
- package/test/toolface-rules.test.mjs +177 -0
- package/test/toolface-runtime.test.mjs +466 -0
- package/test/toolface-wiring.test.mjs +272 -0
- package/test/usage-ledger-inject.test.mjs +50 -0
- package/test/usage-ledger.test.mjs +399 -0
package/lib/bands.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// dsh-lean-router - 思考链路由三带配置表(票 05)
|
|
2
|
+
// 思想来源(只移植结论,不搬代码):上游 routing-suite 实测 —— DeepSeek persona 轴
|
|
3
|
+
// 非连续、分相变,量化为稳定带:spec(先读后改)/ react(直接产出)/ weak(模型自分类);
|
|
4
|
+
// mixed 0.2-0.49 是转换陷阱,永不自动选中。V4.1 Flash 为阈值型:neutral + classify
|
|
5
|
+
// few-shot + 三锚(回顾/收敛/反跑题)为实测最优(路由 96%、单任务完成 100%)。
|
|
6
|
+
// 本表只交「persona 变体文本常量 + 工具面宽窄标记」;persona suffix 拼接由 master 集成,
|
|
7
|
+
// 工具面裁剪归票 04。本模块零外部依赖,纯 node 可测。
|
|
8
|
+
|
|
9
|
+
/** 三个实测稳定行为带(自动分类只会落在其中之一;'auto' 仅作显式指令值,表示回退自动路由)。 */
|
|
10
|
+
export const BAND_IDS = ["spec", "react", "weak"];
|
|
11
|
+
|
|
12
|
+
/** 显式 [router] 指令里合法的 band 值(含 auto:清除显式覆盖,回退自动分类)。 */
|
|
13
|
+
export const DIRECTIVE_BAND_IDS = [...BAND_IDS, "auto"];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 近场引导固定文本基调:每带一段、内容恒定(缓存友好)——
|
|
17
|
+
* 同一带内每轮请求渲染同一文本,dynamic context 判定相等即零写入。
|
|
18
|
+
*/
|
|
19
|
+
const GUIDE_TAIL =
|
|
20
|
+
"Recall what you have already done in this session and continue from there; do not repeat completed steps. Converge on the deliverable; do not expand scope. Return to the task at hand whenever you notice drift.";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 三带配置表。
|
|
24
|
+
* - personaText: 该带的 persona 变体文本常量(英文;由 master 拼进 persona suffix)。
|
|
25
|
+
* - toolsWide: 工具面宽窄标记(true=写向宽面,false=读向窄面)。裁剪实现归票 04。
|
|
26
|
+
* - guideText: 近场引导固定文本(dynamic context 通道,见 lib/router.js)。
|
|
27
|
+
*/
|
|
28
|
+
export const BANDS = {
|
|
29
|
+
spec: {
|
|
30
|
+
id: "spec",
|
|
31
|
+
label: "inspect-and-plan",
|
|
32
|
+
toolsWide: false,
|
|
33
|
+
personaText:
|
|
34
|
+
"Approach each task as an inspector: read before changing. Collect context, locate the exact cause, plan the smallest safe change, then apply and verify. " +
|
|
35
|
+
GUIDE_TAIL,
|
|
36
|
+
guideText:
|
|
37
|
+
"Near-field guide (inspect-and-plan): you are working a fix/inspection task. Read and locate before changing; state the plan when your information is complete, then apply the smallest safe change and verify it. " +
|
|
38
|
+
GUIDE_TAIL,
|
|
39
|
+
},
|
|
40
|
+
react: {
|
|
41
|
+
id: "react",
|
|
42
|
+
label: "hands-on-production",
|
|
43
|
+
toolsWide: true,
|
|
44
|
+
personaText:
|
|
45
|
+
"Approach each task as a builder: produce working increments now. Read only what the next increment needs, make it real, and verify by running it. " +
|
|
46
|
+
GUIDE_TAIL,
|
|
47
|
+
guideText:
|
|
48
|
+
"Near-field guide (hands-on production): you are working a build task. Produce the next working increment now; verify by running it before claiming progress. " +
|
|
49
|
+
GUIDE_TAIL,
|
|
50
|
+
},
|
|
51
|
+
weak: {
|
|
52
|
+
id: "weak",
|
|
53
|
+
label: "model-routed",
|
|
54
|
+
toolsWide: false,
|
|
55
|
+
// weak 带是唯一内路由窗口(实测:模型不能自路由,weak persona + few-shot
|
|
56
|
+
// classify 指令是仅有解;区分度 +2.3..+3.3,lean 不翻转)。
|
|
57
|
+
personaText:
|
|
58
|
+
"You are a generalist. For each new task, first classify it before acting: (build) create something new end-to-end; (fix) diagnose and repair something broken. Adopt the matching style: build -> hands-on production; fix -> inspect-and-plan. " +
|
|
59
|
+
GUIDE_TAIL,
|
|
60
|
+
guideText:
|
|
61
|
+
"Near-field guide (self-routed): classify the current user message before acting - build (create something new) or fix (diagnose and repair) - then follow the matching style for the rest of this turn. " +
|
|
62
|
+
GUIDE_TAIL,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** 任务回显前缀:引导文本里携带显式 task 文本时使用(上游实测:模型每轮看清在为什么事工作)。 */
|
|
67
|
+
export const TASK_ECHO_PREFIX = "Task: ";
|
|
68
|
+
|
|
69
|
+
/** build(react 带)关键词计数词表 —— 自写词表,非上游代码。 */
|
|
70
|
+
export const REACT_HINT_RE =
|
|
71
|
+
/(开发|创建|写一个|写个|生成|做一个|做个|搭建|实现|新增|上线|落地|游戏|网页|网站|构建|脚本|工具|应用|从零|新项目|build|create|develop|generate|implement|new project|scaffold|bootstrap)/gi;
|
|
72
|
+
|
|
73
|
+
/** fix(spec 带)关键词计数词表 —— 自写词表,非上游代码。 */
|
|
74
|
+
export const SPEC_HINT_RE =
|
|
75
|
+
/(修复|修一下|调试|排查|报错|出错|崩溃|异常|故障|审查|复核|重构|维护|优化|兼容|迁移|升级|为什么|bug|fix|debug|refactor|maintain|broken|error|investigate|regression|regress)/gi;
|
|
76
|
+
|
|
77
|
+
function countHits(regex, text) {
|
|
78
|
+
return [...text.matchAll(regex)].length;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 分类的可解释版本(供 /band 展示"最近一次分类结果与依据"):
|
|
83
|
+
* 返回带号 + 两路命中数 + 命中的词样例(去重,最多 3 个)。
|
|
84
|
+
* @param {string} text 用户消息全文
|
|
85
|
+
* @returns {{band: "spec"|"react"|"weak", reactHits: number, specHits: number, signals: string[]}}
|
|
86
|
+
*/
|
|
87
|
+
export function explainClassification(text) {
|
|
88
|
+
if (typeof text !== "string" || text.length === 0) return { band: "weak", reactHits: 0, specHits: 0, signals: [] };
|
|
89
|
+
const reactWords = [...text.matchAll(REACT_HINT_RE)].map((m) => m[0]);
|
|
90
|
+
const specWords = [...text.matchAll(SPEC_HINT_RE)].map((m) => m[0]);
|
|
91
|
+
const reactHits = reactWords.length;
|
|
92
|
+
const specHits = specWords.length;
|
|
93
|
+
const band = reactHits > specHits ? "react" : specHits > reactHits ? "spec" : "weak";
|
|
94
|
+
const signals = [...new Set([...reactWords, ...specWords])].slice(0, 3);
|
|
95
|
+
return { band, reactHits, specHits, signals };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 按首条真实用户消息分类任务带(思想移植、实现重写):
|
|
100
|
+
* build 类证据占优 -> react;fix 类证据占优 -> spec;平票或无匹配 -> weak
|
|
101
|
+
* (weak 是实测最优的内路由模式:模型按 few-shot 指令自分类)。
|
|
102
|
+
* @param {string} text 用户消息全文
|
|
103
|
+
* @returns {"spec"|"react"|"weak"}
|
|
104
|
+
*/
|
|
105
|
+
export function classifyTask(text) {
|
|
106
|
+
return explainClassification(text).band;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** 架构型词(深度任务启发):命中或长文本视为复杂任务(深度引导变体)。 */
|
|
110
|
+
const COMPLEX_HINT_RE =
|
|
111
|
+
/(重构|架构|全面|详细|设计|系统|优化|分析|survey|overview|architecture|refactor|comprehensive|detailed|design|system|optimize|analyze)/i;
|
|
112
|
+
|
|
113
|
+
/** 简单任务给快收敛引导;复杂任务给深度引导(深度自适应,实测 depth +12% 且更快收敛)。 */
|
|
114
|
+
export function isComplexTask(text) {
|
|
115
|
+
return typeof text === "string" && (text.length > 120 || COMPLEX_HINT_RE.test(text));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 解析用户消息里的显式路由指令:`[router] band=<spec|react|weak|auto>[ task=<...>]`
|
|
120
|
+
* - 显式指令优先于关键词分类(人在回路)。
|
|
121
|
+
* - band=auto 表示清除显式覆盖、回退自动分类。
|
|
122
|
+
* - task 为可选任务回显文本,捕获到行尾。
|
|
123
|
+
* @param {string} text 用户消息全文
|
|
124
|
+
* @returns {{ band: string, task?: string } | null} 无指令时返回 null
|
|
125
|
+
*/
|
|
126
|
+
export function parseRouterDirective(text) {
|
|
127
|
+
if (typeof text !== "string") return null;
|
|
128
|
+
const match = /\[router\][ \t]*band[ \t]*=[ \t]*(spec|react|weak|auto)(?:[ \t]+task[ \t]*=[ \t]*(.+))?/i.exec(text);
|
|
129
|
+
if (match === null) return null;
|
|
130
|
+
const out = { band: match[1].toLowerCase() };
|
|
131
|
+
if (match[2] !== undefined) {
|
|
132
|
+
const task = match[2].trim();
|
|
133
|
+
if (task.length > 0) out.task = task;
|
|
134
|
+
}
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 勤勉自检固定文本(每 N 轮注入一次;含轮次号使文本轮间稳定、轮到才变化)。
|
|
140
|
+
* @param {number} turn 当前轮次(>= 1)
|
|
141
|
+
* @returns {string}
|
|
142
|
+
*/
|
|
143
|
+
export function diligenceReminder(turn) {
|
|
144
|
+
return (
|
|
145
|
+
"Diligence self-check (turn " +
|
|
146
|
+
turn +
|
|
147
|
+
"): before your next action, confirm you still hold the deliverable, the remaining steps, and the freshest evidence; re-derive whichever is unclear from this session, then continue with full attention. Do not repeat completed steps."
|
|
148
|
+
);
|
|
149
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// dsh-lean-router - cordis 插件入口(包根)
|
|
2
|
+
//
|
|
3
|
+
// 2.0.0:技能子系统(31 技能、每轮门控打分、审计落盘、技能面板 UI 与客户端 bundle)已整体移除,
|
|
4
|
+
// 这里不再注册任何东西,只保留一个可被加载的合法插件形状:
|
|
5
|
+
// - inject 必须是服务名数组(cordis 的 Inject 只有数组或「服务名 → 拦截配置」映射两种形状;
|
|
6
|
+
// 写成 { required, optional } 会被当成两个服务名,宿主行永远 PENDING)。
|
|
7
|
+
// - apply 必须返回 undefined(返回普通对象会触发 cordis 的 Invalid effect)。
|
|
8
|
+
// 真正的功能挂在 lib/router.js(路由 + /band)、lib/lean/*(省 token)、lib/toolface/*(工具遮蔽)。
|
|
9
|
+
export const name = "lean-router";
|
|
10
|
+
export const inject = [];
|
|
11
|
+
|
|
12
|
+
export function apply() {}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// dsh-lean-router · lib/lean/compaction.js —— 机制 1 · 轮次压缩(参数 + 宿主判定公式镜像)
|
|
2
|
+
//
|
|
3
|
+
// 口径来源(lean 口径照抄 flash 实测,约束台账 v1 第 2 条):
|
|
4
|
+
// 上游 D:\Agent Workspace\.scratch\upstream\flash-presets\presets\flash-lean-ptc-v3.patch.yml
|
|
5
|
+
// L121-133(balance 档 L79-94 同值):thresholdRatio 0.25 / retainTokens 20000 /
|
|
6
|
+
// compactionRetries 1 / auto true;机理注释(0.8 默认在 1M 窗口 = 800k 才触发、109 次运行
|
|
7
|
+
// 0 次触发、压缩是有损摘要)同见 docs/技术文档-省token四机制.md L26-68。
|
|
8
|
+
// 判定公式镜像宿主(0.2.2-rc.5 实装,供 config 预检使用):
|
|
9
|
+
// D:\Deepseek Harness\resources\app.asar\dsh\node_modules\@deepseek-ai\dsh-compaction-basic\lib\index.js
|
|
10
|
+
// L15(默认 thresholdRatio 0.8)、L17(默认 retainRatio 0.16)、L63(headroomTokens 默认 65536)、
|
|
11
|
+
// L124-147 resolveCompactSpec(thresholdTokens = floor(min(cw × ratio, pressureBudget));
|
|
12
|
+
// retainTokens = retainTokens ?? floor(messageBudget × retainRatio);retain >= threshold → 抛错)、
|
|
13
|
+
// L155-157(retainRatio 必须 < thresholdRatio)、L192(retainRatio 与 retainTokens 互斥)。
|
|
14
|
+
// 零依赖:纯函数,任何环境可独立加载。
|
|
15
|
+
//
|
|
16
|
+
// 注意:本模块只做参数口径与预检,不做压缩执行——执行由宿主 @deepseek-ai/dsh-compaction-basic
|
|
17
|
+
// 按 frag-lean.patch.yml 里 compaction 组的 config 完成。
|
|
18
|
+
|
|
19
|
+
/** flash lean 实测口径的压缩配置(frag-lean.patch.yml compaction-basic 行的数据源)。 */
|
|
20
|
+
export const LEAN_COMPACTION_CONFIG = Object.freeze({
|
|
21
|
+
thresholdRatio: 0.25,
|
|
22
|
+
retainTokens: 20000,
|
|
23
|
+
compactionRetries: 1,
|
|
24
|
+
auto: true,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/** 宿主默认值(镜像 dsh-compaction-basic L15/L17/L63)。 */
|
|
28
|
+
export const HOST_DEFAULTS = Object.freeze({
|
|
29
|
+
thresholdRatio: 0.8,
|
|
30
|
+
retainRatio: 0.16,
|
|
31
|
+
headroomTokens: 65536,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const POLICY_KEYS = new Set([
|
|
35
|
+
'thresholdRatio', 'headroomTokens', 'retainRatio', 'retainTokens',
|
|
36
|
+
'summarizationProvider', 'summarizationModel', 'maxTokens', 'compactionRetries', 'maxOverflowRetries',
|
|
37
|
+
]);
|
|
38
|
+
// 顶层完整键集(镜像宿主 BASIC_COMPACT_CONFIG_KEYS L31-35:多 auto 与 modelPolicies 两键)。
|
|
39
|
+
const TOP_LEVEL_KEYS = new Set([...POLICY_KEYS, 'auto', 'modelPolicies']);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 镜像宿主 resolveCompactSpec(dsh-compaction-basic L124-147):把一条路由策略
|
|
43
|
+
* 按模型容量换算成具体 token 预算,并在 retain >= threshold 时抛配置错误。
|
|
44
|
+
* @param policy 含 thresholdRatio/retainTokens|retainRatio/headroomTokens 的策略对象
|
|
45
|
+
* @param contextWindow 该路由声明的上下文窗口(正整数)
|
|
46
|
+
* @param reservedCompletionTokens 单次请求预留的输出 token(非负)
|
|
47
|
+
* @returns deep-frozen 的 {thresholdTokens, retainTokens, ...}
|
|
48
|
+
*/
|
|
49
|
+
export function resolveCompactSpec(policy, contextWindow, reservedCompletionTokens) {
|
|
50
|
+
if (!Number.isInteger(contextWindow) || contextWindow <= 0) {
|
|
51
|
+
throw new Error('compaction-basic: contextWindow must be a positive integer');
|
|
52
|
+
}
|
|
53
|
+
if (!Number.isInteger(reservedCompletionTokens) || reservedCompletionTokens < 0) {
|
|
54
|
+
throw new Error('compaction-basic: reservedCompletionTokens must be a non-negative integer');
|
|
55
|
+
}
|
|
56
|
+
const messageBudgetTokens = contextWindow - reservedCompletionTokens;
|
|
57
|
+
if (messageBudgetTokens <= 0) {
|
|
58
|
+
throw new Error('compaction-basic: message budget exhausted; raise the adapter contextWindow');
|
|
59
|
+
}
|
|
60
|
+
const headroomTokens = policy.headroomTokens ?? HOST_DEFAULTS.headroomTokens;
|
|
61
|
+
const pressureBudgetTokens = messageBudgetTokens - headroomTokens;
|
|
62
|
+
if (pressureBudgetTokens <= 0) {
|
|
63
|
+
throw new Error('compaction-basic: pressure budget exhausted; reduce maxTokens or headroomTokens');
|
|
64
|
+
}
|
|
65
|
+
const thresholdRatio = policy.thresholdRatio ?? HOST_DEFAULTS.thresholdRatio;
|
|
66
|
+
const thresholdTokens = Math.floor(Math.min(contextWindow * thresholdRatio, pressureBudgetTokens));
|
|
67
|
+
const retainTokens = policy.retainTokens ?? Math.floor(messageBudgetTokens * (policy.retainRatio ?? HOST_DEFAULTS.retainRatio));
|
|
68
|
+
if (retainTokens >= thresholdTokens) {
|
|
69
|
+
throw new Error('compaction-basic: retainTokens (' + retainTokens + ') must be less than threshold tokens ' + thresholdTokens);
|
|
70
|
+
}
|
|
71
|
+
return Object.freeze({
|
|
72
|
+
contextWindow,
|
|
73
|
+
thresholdRatio,
|
|
74
|
+
thresholdTokens,
|
|
75
|
+
retainTokens,
|
|
76
|
+
headroomTokens,
|
|
77
|
+
pressureBudgetTokens,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 镜像宿主 load 期校验(validatePolicy/validateRatioRetention L155-225):键集、
|
|
83
|
+
* 比例区间、互斥、整数性。合法返回 true,非法抛 Error。
|
|
84
|
+
*/
|
|
85
|
+
export function validateCompactionConfig(config) {
|
|
86
|
+
for (const key of Object.keys(config)) {
|
|
87
|
+
if (!TOP_LEVEL_KEYS.has(key)) throw new Error('BasicCompactionConfig: unknown key "' + key + '"');
|
|
88
|
+
}
|
|
89
|
+
const ratio = config.thresholdRatio;
|
|
90
|
+
if (ratio !== undefined && (typeof ratio !== 'number' || !Number.isFinite(ratio) || ratio <= 0 || ratio > 1)) {
|
|
91
|
+
throw new Error('BasicCompactionConfig.thresholdRatio must be a number in (0, 1]');
|
|
92
|
+
}
|
|
93
|
+
const retainRatio = config.retainRatio;
|
|
94
|
+
const retainTokens = config.retainTokens;
|
|
95
|
+
if (retainRatio !== undefined && retainTokens !== undefined) {
|
|
96
|
+
throw new Error('BasicCompactionConfig: retainRatio and retainTokens are mutually exclusive');
|
|
97
|
+
}
|
|
98
|
+
if (retainRatio !== undefined) {
|
|
99
|
+
if (typeof retainRatio !== 'number' || !Number.isFinite(retainRatio) || retainRatio <= 0 || retainRatio > 1) {
|
|
100
|
+
throw new Error('BasicCompactionConfig.retainRatio must be a number in (0, 1]');
|
|
101
|
+
}
|
|
102
|
+
if (retainRatio >= (ratio ?? HOST_DEFAULTS.thresholdRatio)) {
|
|
103
|
+
throw new Error('BasicCompactionConfig: retainRatio must be less than the resolved thresholdRatio');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (retainTokens !== undefined) assertNonNegativeInteger('retainTokens', retainTokens);
|
|
107
|
+
if (config.compactionRetries !== undefined) assertNonNegativeInteger('compactionRetries', config.compactionRetries);
|
|
108
|
+
if (config.maxOverflowRetries !== undefined) assertNonNegativeInteger('maxOverflowRetries', config.maxOverflowRetries);
|
|
109
|
+
if (config.auto !== undefined && typeof config.auto !== 'boolean') {
|
|
110
|
+
throw new Error('BasicCompactionConfig: auto must be a boolean');
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function assertNonNegativeInteger(name, value) {
|
|
116
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
117
|
+
throw new Error('BasicCompactionConfig.' + name + ' must be a non-negative integer');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
// dsh-lean-router · lib/lean/delivery-gate.js —— 加料件 · 交付门(vendored 移植)
|
|
2
|
+
//
|
|
3
|
+
// 上游来源:D:\Agent Workspace\.scratch\upstream\flash-presets\lib\delivery-gate.js(0.3.2,282 行)
|
|
4
|
+
// 逐段移植上游「交付门」机制:工作区有验收脚本(verify.ps1/verify.sh)时,回合收尾自动跑一次;
|
|
5
|
+
// 不通过就把失败清单 + 尾部输出 steer 回灌,同一会话最多 maxRounds 次;关着时一个字都不注入。
|
|
6
|
+
// 上游机理注释原文见该文件 L1-13(为什么需要它:三臂实测「要求写清楚」到位但缺「不达标不许结束」)。
|
|
7
|
+
//
|
|
8
|
+
// 与上游的适配(约束台账 v1 第 4 条:缺宿主依赖处动态 import + 显式降级,不得顶层静态 import):
|
|
9
|
+
// 1. 顶层静态 import { createUserMessage } from '@deepseek-ai/dsh-llm' → 在 steer 调用点
|
|
10
|
+
// 动态 import;宿主缺该包(纯 node/无宿主)时显式降级:脚本照跑、回灌跳过并记日志,不崩溃。
|
|
11
|
+
// 2. zod Config schema → 手写 validateDeliveryGateConfig(同 maybeResolve 语义:缺省值 +
|
|
12
|
+
// 类型检查 + scripts 空数组回落默认),零第三方依赖。
|
|
13
|
+
// 3. name 由 'delivery-gate' 改为 'lean-delivery-gate',避免与本包外若同装的
|
|
14
|
+
// dsh-flash-presets/delivery-gate 服务同名冲突。
|
|
15
|
+
// 4. 其余逻辑(runScript 的 exit+排空+清进程组、cwd 解析、会话状态、MIN_GAP_MS、
|
|
16
|
+
// section provider 关闭态返回空串)保持上游原样。
|
|
17
|
+
// 环境变量:DSH_DELIVERY_GATE=0 强制关;=1 在 config.enabled 缺省时强制开(上游 L53-59 语义)。
|
|
18
|
+
// 默认 enabled: false(上游 L25-27:插件卡不带路由配置时 schema 默认值是唯一防线)。
|
|
19
|
+
import { spawn } from 'node:child_process';
|
|
20
|
+
import { existsSync, statSync } from 'node:fs';
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
|
|
23
|
+
export const name = 'lean-delivery-gate';
|
|
24
|
+
export const inject = ['systemPrompt'];
|
|
25
|
+
|
|
26
|
+
/** Windows 先找 verify.ps1,*nix 先找 verify.sh(上游 L38-42)。 */
|
|
27
|
+
function defaultScripts() {
|
|
28
|
+
return process.platform === 'win32' ? ['verify.ps1', 'verify.sh'] : ['verify.sh', 'verify.ps1'];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 手写校验(替代上游 zod Config):合法返回归一化配置,非法抛 Error。 */
|
|
32
|
+
export function validateDeliveryGateConfig(config) {
|
|
33
|
+
const c = config ?? {};
|
|
34
|
+
const keys = ['enabled', 'scripts', 'maxRounds', 'timeoutMs', 'tailChars'];
|
|
35
|
+
for (const key of Object.keys(c)) {
|
|
36
|
+
if (!keys.includes(key)) throw new Error('DeliveryGateConfig: unknown key "' + key + '"');
|
|
37
|
+
}
|
|
38
|
+
if (c.enabled !== undefined && typeof c.enabled !== 'boolean') throw new Error('DeliveryGateConfig: enabled must be a boolean');
|
|
39
|
+
if (c.scripts !== undefined) {
|
|
40
|
+
if (!Array.isArray(c.scripts) || c.scripts.some((s) => typeof s !== 'string' || s.length === 0)) {
|
|
41
|
+
throw new Error('DeliveryGateConfig: scripts must be an array of non-empty strings');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
for (const key of ['maxRounds', 'timeoutMs', 'tailChars']) {
|
|
45
|
+
if (c[key] !== undefined && (!Number.isInteger(c[key]) || c[key] <= 0)) {
|
|
46
|
+
throw new Error('DeliveryGateConfig: ' + key + ' must be a positive integer');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return maybeResolve(c);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const TAG = '[lean-delivery-gate]';
|
|
53
|
+
const SESSION_CAP = 200;
|
|
54
|
+
// 两次自动验收的最小间隔:turn-stopping 会在回合内的步与步之间也触发(上游 L47)
|
|
55
|
+
const MIN_GAP_MS = 15000;
|
|
56
|
+
|
|
57
|
+
function log(message) {
|
|
58
|
+
try { console.info(TAG + ' ' + message); } catch (error) {}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function isOff(config) {
|
|
62
|
+
const env = process.env.DSH_DELIVERY_GATE;
|
|
63
|
+
if (env === '0') return true;
|
|
64
|
+
// 文档写「或临时设 DSH_DELIVERY_GATE=1」:设 1 视为开(上游 L53-59 语义,含 0.3.1 修复)。
|
|
65
|
+
if (env === '1') return false;
|
|
66
|
+
return config.enabled !== true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function findScript(cwd, names) {
|
|
70
|
+
if (typeof cwd !== 'string' || cwd.length === 0) return null;
|
|
71
|
+
for (const candidate of names) {
|
|
72
|
+
const file = path.resolve(cwd, candidate);
|
|
73
|
+
try { if (statSync(file).isFile()) return file; } catch (error) {}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 一次验收:拿退出码 + 尾部输出。不抛,失败也当数据(上游 L70-164 原样移植)。
|
|
79
|
+
// 三个坑(上游 2026-11-17 审计注释):
|
|
80
|
+
// 1. 只听 close 会被后台孙进程挂死 —— 改成听 exit + 排空宽限。
|
|
81
|
+
// 2. 只 kill bash 杀不掉孙进程 —— detached 起独立进程组,超时/取消时 kill(-pid)。
|
|
82
|
+
// 3. 输出无上限 —— 结果只用尾部 tailChars,这里按 128 KB 环形保留。
|
|
83
|
+
function runScript(file, cwd, timeoutMs, signal) {
|
|
84
|
+
return new Promise((resolve) => {
|
|
85
|
+
const win = process.platform === 'win32';
|
|
86
|
+
const startedAt = Date.now();
|
|
87
|
+
const CAP = 128 * 1024;
|
|
88
|
+
const keep = (cur, buf) => {
|
|
89
|
+
const next = cur + String(buf);
|
|
90
|
+
return next.length > CAP ? next.slice(-CAP) : next;
|
|
91
|
+
};
|
|
92
|
+
let stdout = '';
|
|
93
|
+
let stderr = '';
|
|
94
|
+
let timedOut = false;
|
|
95
|
+
let aborted = false;
|
|
96
|
+
let child;
|
|
97
|
+
let done = false;
|
|
98
|
+
let timer;
|
|
99
|
+
// 收尾一律清一次进程组(上游第二轮审计 P2-9):正常退出时它留下的后台进程会一直挂着。
|
|
100
|
+
// Windows 没有进程组,用 taskkill /T。
|
|
101
|
+
const cleanup = () => {
|
|
102
|
+
if (child === undefined || child === null) return;
|
|
103
|
+
const pid = child.pid;
|
|
104
|
+
if (typeof pid !== 'number' || pid <= 0) return;
|
|
105
|
+
try {
|
|
106
|
+
if (win) spawn('taskkill', ['/T', '/F', '/PID', String(pid)], { windowsHide: true, stdio: 'ignore' });
|
|
107
|
+
else process.kill(-pid, 'SIGTERM');
|
|
108
|
+
} catch (error) {}
|
|
109
|
+
};
|
|
110
|
+
const finish = (code) => {
|
|
111
|
+
if (done) return;
|
|
112
|
+
done = true;
|
|
113
|
+
cleanup();
|
|
114
|
+
if (timer !== undefined) clearTimeout(timer);
|
|
115
|
+
if (signal !== undefined && typeof signal.removeEventListener === 'function') {
|
|
116
|
+
try { signal.removeEventListener('abort', onAbort); } catch (error) {}
|
|
117
|
+
}
|
|
118
|
+
const seconds = Math.round((Date.now() - startedAt) / 100) / 10;
|
|
119
|
+
resolve({
|
|
120
|
+
ok: code === 0 && timedOut !== true && aborted !== true,
|
|
121
|
+
code,
|
|
122
|
+
out: (stdout + stderr).trim(),
|
|
123
|
+
seconds,
|
|
124
|
+
timedOut: timedOut || aborted,
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
const killTree = () => {
|
|
128
|
+
if (child === undefined || child === null) return;
|
|
129
|
+
try {
|
|
130
|
+
// detached 起的子进程自成进程组:负 pid 一次性带走 bash 和它的孙进程
|
|
131
|
+
if (!win && typeof child.pid === 'number' && child.pid > 0) process.kill(-child.pid, 'SIGKILL');
|
|
132
|
+
else child.kill('SIGKILL');
|
|
133
|
+
} catch (error) {
|
|
134
|
+
try { child.kill('SIGKILL'); } catch (error2) {}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const onAbort = () => { aborted = true; killTree(); };
|
|
138
|
+
// 按扩展名选解释器(上游第二轮审计 P2-5):Windows 一律 pwsh -File 遇 verify.sh 必失败。
|
|
139
|
+
const ext = path.extname(file).toLowerCase();
|
|
140
|
+
const argv = ext === '.ps1'
|
|
141
|
+
? ['pwsh', ['-NoProfile', '-NonInteractive', '-File', file]]
|
|
142
|
+
: [win ? 'bash' : '/bin/bash', [file]]; // Windows 走 Git Bash;没有就 ENOENT,按跳过处理
|
|
143
|
+
try {
|
|
144
|
+
child = spawn(argv[0], argv[1], { cwd, windowsHide: true, detached: !win });
|
|
145
|
+
} catch (error) {
|
|
146
|
+
resolve({ ok: true, skipped: true, code: null, out: 'spawn failed: ' + String(error && error.message), seconds: 0, timedOut: false });
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
timer = setTimeout(() => { timedOut = true; killTree(); }, timeoutMs);
|
|
150
|
+
if (signal !== undefined && typeof signal.addEventListener === 'function') {
|
|
151
|
+
if (signal.aborted === true) { aborted = true; killTree(); }
|
|
152
|
+
else signal.addEventListener('abort', onAbort, { once: true });
|
|
153
|
+
}
|
|
154
|
+
child.stdout.on('data', (buf) => { stdout = keep(stdout, buf); });
|
|
155
|
+
child.stderr.on('data', (buf) => { stderr = keep(stderr, buf); });
|
|
156
|
+
child.on('error', (error) => {
|
|
157
|
+
// 解释器不存在(Windows 没有 Git Bash / 没有 pwsh)不算验收失败:跳过,别把用户堵在回合里
|
|
158
|
+
if (error !== null && error !== undefined && error.code === 'ENOENT') {
|
|
159
|
+
done = true;
|
|
160
|
+
if (timer !== undefined) clearTimeout(timer);
|
|
161
|
+
resolve({ ok: true, skipped: true, code: null, out: argv[0] + ' not found (ENOENT) - acceptance skipped', seconds: 0, timedOut: false });
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
stderr = keep(stderr, String(error && error.message));
|
|
165
|
+
finish(null);
|
|
166
|
+
});
|
|
167
|
+
// exit 先到:给 stdio 一点排空时间再收尾,避免丢尾部输出(close 也可能先到)
|
|
168
|
+
child.on('exit', (code) => { setTimeout(() => finish(code), 200); });
|
|
169
|
+
child.on('close', (code) => { finish(code); });
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// 不要回落到 process.cwd():那是宿主进程的启动目录,不是本会话的工作区(上游 L166-181)。
|
|
174
|
+
function cwdOf(agent, session) {
|
|
175
|
+
const fromBox = (box) => {
|
|
176
|
+
if (box === undefined || box === null || typeof box !== 'object') return null;
|
|
177
|
+
for (const field of ['cwd', 'dir', 'workspace', 'workdir']) {
|
|
178
|
+
if (typeof box[field] === 'string' && existsSync(box[field])) return box[field];
|
|
179
|
+
}
|
|
180
|
+
for (const field of ['meta', 'metadata', 'header', 'info']) {
|
|
181
|
+
const nested = box[field];
|
|
182
|
+
if (nested !== undefined && nested !== null && typeof nested === 'object' && typeof nested.cwd === 'string' && existsSync(nested.cwd)) return nested.cwd;
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
};
|
|
186
|
+
// 拿不到就返回 null,由调用方跳过验收(宁可少跑一次,也不要在错误目录里跑别人的 verify.sh)。
|
|
187
|
+
return fromBox(session) ?? (agent !== undefined && agent !== null ? fromBox(agent.session) : null);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function maybeResolve(config) {
|
|
191
|
+
const base = { enabled: false, scripts: defaultScripts(), maxRounds: 2, timeoutMs: 900000, tailChars: 1200 };
|
|
192
|
+
const merged = { ...base, ...(config || {}) };
|
|
193
|
+
if (Array.isArray(merged.scripts) && merged.scripts.length === 0) merged.scripts = base.scripts;
|
|
194
|
+
return merged;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function sessionKey(agent) {
|
|
198
|
+
const direct = agent && agent.session && (agent.session.id || agent.session.sessionId);
|
|
199
|
+
if (typeof direct === 'string' && direct.length > 0) return direct;
|
|
200
|
+
const fallback = agent && (agent.id || agent.agentId);
|
|
201
|
+
return typeof fallback === 'string' && fallback.length > 0 ? fallback : 'default';
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async function resolveCwd(ctx, exec) {
|
|
205
|
+
try {
|
|
206
|
+
const service = typeof ctx.get === 'function' ? ctx.get('workingDirectory') : undefined;
|
|
207
|
+
if (service !== undefined && typeof service.ensure === 'function') {
|
|
208
|
+
const dir = await service.ensure(exec.agent, exec.signal);
|
|
209
|
+
if (typeof dir === 'string' && dir.length > 0) return dir;
|
|
210
|
+
}
|
|
211
|
+
} catch (error) {}
|
|
212
|
+
return cwdOf(exec.agent, exec.agent && exec.agent.session);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* 动态加载 @deepseek-ai/dsh-llm 的 createUserMessage(适配 1)。
|
|
217
|
+
* 缺包时返回 null,调用方显式降级:脚本照跑、回灌跳过、记日志,不崩溃。
|
|
218
|
+
*/
|
|
219
|
+
async function loadCreateUserMessage() {
|
|
220
|
+
try {
|
|
221
|
+
const mod = await import('@deepseek-ai/dsh-llm');
|
|
222
|
+
if (mod && typeof mod.createUserMessage === 'function') return mod.createUserMessage;
|
|
223
|
+
return null;
|
|
224
|
+
} catch (error) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export function apply(ctx, config) {
|
|
230
|
+
const resolved = maybeResolve(config);
|
|
231
|
+
const state = new Map();
|
|
232
|
+
|
|
233
|
+
const remember = (key, value) => {
|
|
234
|
+
if (state.size > SESSION_CAP) state.delete(state.keys().next().value);
|
|
235
|
+
state.set(key, value);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// 关着的时候一个字都不注入(上游 L217-229):空 section 在装配时会被丢掉。
|
|
239
|
+
const sectionText = [
|
|
240
|
+
'DELIVERY GATE: this workspace has an acceptance script; the harness runs it when a turn stops and sends you pass/fail plus the tail of its output.',
|
|
241
|
+
'If the harness reports that acceptance failed, do not deliver: fix the failure and let it run again; only then answer.',
|
|
242
|
+
].join(' ');
|
|
243
|
+
ctx.systemPrompt.section({
|
|
244
|
+
name: 'lean-delivery-gate',
|
|
245
|
+
order: 42,
|
|
246
|
+
text: () => (isOff(resolved) ? '' : sectionText),
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
ctx.effect(() => ctx.on('agent/turn-stopping', async (payload) => {
|
|
250
|
+
if (isOff(resolved)) return;
|
|
251
|
+
const agent = payload && payload.agent;
|
|
252
|
+
if (agent === undefined || agent === null) return;
|
|
253
|
+
if (payload.signal !== undefined && payload.signal.aborted === true) return;
|
|
254
|
+
// 与主插件一致:优先问 workingDirectory 服务(生产环境 session.cwd 常为 undefined)
|
|
255
|
+
const cwd = await resolveCwd(ctx, { agent, signal: payload.signal });
|
|
256
|
+
if (cwd === null || cwd === undefined) return; // 拿不到工作区就跳过,不在错误目录里跑脚本
|
|
257
|
+
const script = findScript(cwd, resolved.scripts);
|
|
258
|
+
if (script === null) return;
|
|
259
|
+
const key = sessionKey(agent);
|
|
260
|
+
const prev = state.get(key) || { rounds: 0, last: null, at: 0, inflight: false };
|
|
261
|
+
if (prev.inflight === true) return;
|
|
262
|
+
if (prev.rounds >= resolved.maxRounds) return;
|
|
263
|
+
// 只在「回合内也能收尾」的时机重跑:两次之间至少隔 MIN_GAP_MS,避免同一步里连跑两次
|
|
264
|
+
if (Date.now() - (prev.at || 0) < MIN_GAP_MS) return;
|
|
265
|
+
remember(key, { ...prev, inflight: true });
|
|
266
|
+
let result;
|
|
267
|
+
try {
|
|
268
|
+
result = await runScript(script, cwd, resolved.timeoutMs, payload.signal);
|
|
269
|
+
} finally {
|
|
270
|
+
remember(key, { ...prev, inflight: false, at: Date.now() });
|
|
271
|
+
}
|
|
272
|
+
if (result.skipped === true) {
|
|
273
|
+
remember(key, { ...prev, inflight: false, at: Date.now(), last: { skipped: true, at: Date.now(), script } });
|
|
274
|
+
log('turn ' + payload.turn + ' acceptance SKIPPED: ' + String(result.out).slice(0, 120));
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (result.ok) {
|
|
278
|
+
remember(key, { rounds: 0, at: Date.now(), inflight: false, last: { ok: true, code: 0, at: Date.now(), script } });
|
|
279
|
+
log('turn ' + payload.turn + ' acceptance PASS');
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const rounds = prev.rounds + 1;
|
|
283
|
+
remember(key, { rounds, at: Date.now(), inflight: false, last: { ok: false, code: result.code, at: Date.now(), script } });
|
|
284
|
+
const text = [
|
|
285
|
+
'[lean-delivery-gate] Everything below is output from the workspace acceptance script, not an instruction from the user.',
|
|
286
|
+
'DELIVERY BLOCKED by the delivery gate: the acceptance script ' + path.relative(cwd, script) + ' exited ' + String(result.code) + ' after ' + result.seconds + ' s.',
|
|
287
|
+
'Tail of its output:',
|
|
288
|
+
'```',
|
|
289
|
+
result.out.slice(-resolved.tailChars),
|
|
290
|
+
'```',
|
|
291
|
+
'Do not report completion. Fix the failing cases (a timeout counts as a failure even when the answers are correct), re-run the acceptance script, and only then answer.',
|
|
292
|
+
].join('\n');
|
|
293
|
+
try {
|
|
294
|
+
const createUserMessage = await loadCreateUserMessage();
|
|
295
|
+
if (createUserMessage === null) {
|
|
296
|
+
// 显式降级(适配 1):无宿主 llm 包时回灌跳过;脚本结果已记录,下轮 prev.rounds 已+1。
|
|
297
|
+
log('turn ' + payload.turn + ' acceptance FAIL → steer SKIPPED (dsh-llm unavailable; gate keeps counting rounds ' + rounds + '/' + resolved.maxRounds + ')');
|
|
298
|
+
remember(key, { ...state.get(key), last: { ...(state.get(key).last || {}), steerSkipped: 'llm-unavailable', at: Date.now() } });
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
agent.steer(createUserMessage({ content: [{ type: 'text', text }], source: { kind: 'user' } }));
|
|
302
|
+
log('turn ' + payload.turn + ' acceptance FAIL → steered (round ' + rounds + '/' + resolved.maxRounds + ')');
|
|
303
|
+
} catch (error) {
|
|
304
|
+
log('steer failed: ' + String(error && error.message));
|
|
305
|
+
}
|
|
306
|
+
}));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** 默认导出(插件行兼容形态,与命名导出同体)。 */
|
|
310
|
+
export default { name, inject, apply };
|
|
311
|
+
|
|
312
|
+
export const __internals = { defaultScripts, isOff, findScript, maybeResolve, sessionKey, cwdOf, runScript, MIN_GAP_MS, TAG };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// dsh-lean-router · lib/lean/disabled.js —— 机制 3 · 关 6 插件(清单数据)
|
|
2
|
+
//
|
|
3
|
+
// 逐行照抄上游(vendored,约束台账 v1 第 2 条):
|
|
4
|
+
// D:\Agent Workspace\.scratch\upstream\flash-presets\presets\flash-lean-ptc-v3.patch.yml
|
|
5
|
+
// L155-168(tool-subagent-codex / tool-subagent-claude-code)、
|
|
6
|
+
// L169-182(workflow-ptc / tool-workflow / tool-ralph)、
|
|
7
|
+
// L200-202(tool-plugin-manager)。
|
|
8
|
+
// 这些行属于 frag-lean.patch.yml 里 delegation 组与预设顶层;disabled: true 的插件不加载,
|
|
9
|
+
// 其工具 schema 不进系统提示(docs/技术文档-省token四机制.md L119-140)。
|
|
10
|
+
// 与 codemode 遮蔽面(native+code_run)的逐项复核结论:docs/复核-关插件清单.md。
|
|
11
|
+
// 零依赖数据模块。
|
|
12
|
+
//
|
|
13
|
+
// 顺序与 id 与上游一致;config 原值保留(maxDepth: provider-managed 为上游原文字面量)。
|
|
14
|
+
|
|
15
|
+
/** 上游 lean v3 关闭的 6 个插件 id(顺序同上游)。 */
|
|
16
|
+
export const DISABLED_PLUGIN_IDS = Object.freeze([
|
|
17
|
+
'tool-subagent-codex',
|
|
18
|
+
'tool-subagent-claude-code',
|
|
19
|
+
'workflow-ptc',
|
|
20
|
+
'tool-workflow',
|
|
21
|
+
'tool-ralph',
|
|
22
|
+
'tool-plugin-manager',
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
/** 6 行 disabled 行数据(id/name/disabled/config 与上游预设行逐字段一致)。 */
|
|
26
|
+
export const DISABLED_PLUGIN_ROWS = Object.freeze([
|
|
27
|
+
Object.freeze({
|
|
28
|
+
id: 'tool-subagent-codex',
|
|
29
|
+
name: '@deepseek-ai/dsh-tool-subagent',
|
|
30
|
+
disabled: true,
|
|
31
|
+
config: Object.freeze({ provider: 'codex', toolName: 'subagent_codex', maxDepth: 'provider-managed' }),
|
|
32
|
+
}),
|
|
33
|
+
Object.freeze({
|
|
34
|
+
id: 'tool-subagent-claude-code',
|
|
35
|
+
name: '@deepseek-ai/dsh-tool-subagent',
|
|
36
|
+
disabled: true,
|
|
37
|
+
config: Object.freeze({ provider: 'claude-code', toolName: 'subagent_claude_code', maxDepth: 'provider-managed' }),
|
|
38
|
+
}),
|
|
39
|
+
Object.freeze({
|
|
40
|
+
id: 'workflow-ptc',
|
|
41
|
+
name: '@deepseek-ai/dsh-workflow-ptc',
|
|
42
|
+
disabled: true,
|
|
43
|
+
config: Object.freeze({ provider: 'spawn' }),
|
|
44
|
+
}),
|
|
45
|
+
Object.freeze({
|
|
46
|
+
id: 'tool-workflow',
|
|
47
|
+
name: '@deepseek-ai/dsh-tool-workflow',
|
|
48
|
+
disabled: true,
|
|
49
|
+
}),
|
|
50
|
+
Object.freeze({
|
|
51
|
+
id: 'tool-ralph',
|
|
52
|
+
name: '@deepseek-ai/dsh-tool-ralph',
|
|
53
|
+
disabled: true,
|
|
54
|
+
config: Object.freeze({ subagentProvider: 'spawn', maxRounds: 64 }),
|
|
55
|
+
}),
|
|
56
|
+
Object.freeze({
|
|
57
|
+
id: 'tool-plugin-manager',
|
|
58
|
+
name: '@deepseek-ai/dsh-plugin-manager/tools',
|
|
59
|
+
disabled: true,
|
|
60
|
+
}),
|
|
61
|
+
]);
|