dsh-lean-router 0.0.0-stage → 0.2.3
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 +266 -0
- package/docs/changelog.md +269 -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/discovery.js +297 -0
- package/lib/toolface/executor.js +323 -0
- package/lib/toolface/index.js +242 -0
- package/lib/toolface/pool.js +160 -0
- package/lib/toolface/retention.js +187 -0
- package/lib/toolface/rules.js +395 -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 +145 -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-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
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
// dsh-lean-router · lib/lean/tool-concurrency.js —— 加料件 · glob/grep 只读并发标记(vendored 移植)
|
|
2
|
+
//
|
|
3
|
+
// 上游来源:D:\Agent Workspace\.scratch\upstream\flash-presets\lib\tool-concurrency.js
|
|
4
|
+
// (0.3.2,300 行;无第三方依赖)。逐段移植上游「run_code 优化 A」:给 glob/grep 在**已注册的
|
|
5
|
+
// 定义对象**上补 isConcurrencySafe 分类函数,让原生多调用真正并行(调度器只认 === true)。
|
|
6
|
+
// 上游机理与历史注释原文见该文件 L1-37(为什么必须补:dsh-tool-fs-search 未声明、registry
|
|
7
|
+
// 不允许同名覆盖、0.2.x tune-runtime 补丁路径已静默失效)。
|
|
8
|
+
//
|
|
9
|
+
// 与上游的适配:
|
|
10
|
+
// 1. TAG '[tool-concurrency]' → '[lean-concurrency]';Symbol.for 键空间改本包
|
|
11
|
+
// (dsh-lean-router.tool-concurrency[.hook]),避免与 flash 同装时互踩。
|
|
12
|
+
// 2. 关闭开关同时认 DSH_LEAN_ROUTER_CONCURRENCY=0(本包名)与
|
|
13
|
+
// DSH_FLASH_PRESETS_CONCURRENCY=0(上游兼容名)。
|
|
14
|
+
// 3. 增加默认导出插件对象(name 'lean-concurrency',inject ['tools','agents']),
|
|
15
|
+
// 上游此职责在 lib/core.js(flash-presets-core 行);本包单文件承载,可直接作为
|
|
16
|
+
// bundle 插件行 name 'dsh-lean-router/lean/tool-concurrency' 的解析目标。
|
|
17
|
+
// config 形状与 core.js 一致:{ toolConcurrency: { enabled?, tools?, sweepMs? } }。
|
|
18
|
+
// 4. markConcurrencySafe / unmarkConcurrencySafe / installToolConcurrency / __internals
|
|
19
|
+
// 导出面与上游一致,逻辑原样。
|
|
20
|
+
// 状态回调 onStatus 与版本号由挂载方传入(core.js 注入形状保留)。
|
|
21
|
+
|
|
22
|
+
const TAG = '[lean-concurrency]';
|
|
23
|
+
const MARK = Symbol.for('dsh-lean-router.tool-concurrency');
|
|
24
|
+
const HOOK = Symbol.for('dsh-lean-router.tool-concurrency.hook');
|
|
25
|
+
const DEFAULT_TARGETS = ['glob', 'grep'];
|
|
26
|
+
// 500ms:会话挂载到它第一轮的工具调用之间通常只有几秒,15s 的扫描会漏掉第一轮
|
|
27
|
+
// (上游 2026-11-06 实测注释)。
|
|
28
|
+
const DEFAULT_SWEEP_MS = 500;
|
|
29
|
+
const WARMUP_MS = 1200;
|
|
30
|
+
// 前 60 秒按 sweepMs 扫;之后退到 SLOW_SWEEP_MS 兜底(上游第四轮审计 P2-4)。
|
|
31
|
+
const FAST_WINDOW_MS = 60000;
|
|
32
|
+
const SLOW_SWEEP_MS = 5000;
|
|
33
|
+
// 只读工具的探测参数:只为确认「分类函数返回 true」,不会真的执行
|
|
34
|
+
const PROBE = { pattern: '*' };
|
|
35
|
+
|
|
36
|
+
function say(level, text) {
|
|
37
|
+
try { (level === 'error' ? console.error : console.info)(text); } catch (error) {}
|
|
38
|
+
}
|
|
39
|
+
function msgOf(error) {
|
|
40
|
+
return String((error && error.message) || error);
|
|
41
|
+
}
|
|
42
|
+
function serviceOf(ctx, name) {
|
|
43
|
+
try {
|
|
44
|
+
if (ctx[name] !== undefined) return ctx[name];
|
|
45
|
+
if (typeof ctx.get === 'function') return ctx.get(name);
|
|
46
|
+
} catch (error) {}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
function parseTargets(value) {
|
|
50
|
+
if (Array.isArray(value)) return value.filter((x) => typeof x === 'string' && x.length > 0);
|
|
51
|
+
if (typeof value === 'string') return value.split(',').map((x) => x.trim()).filter(Boolean);
|
|
52
|
+
return DEFAULT_TARGETS.slice();
|
|
53
|
+
}
|
|
54
|
+
function getDef(tools, name, scope) {
|
|
55
|
+
try { return scope === undefined ? tools.get(name) : tools.get(name, scope); } catch (error) { return undefined; }
|
|
56
|
+
}
|
|
57
|
+
function envOff() {
|
|
58
|
+
return process.env.DSH_LEAN_ROUTER_CONCURRENCY === '0' || process.env.DSH_FLASH_PRESETS_CONCURRENCY === '0';
|
|
59
|
+
}
|
|
60
|
+
function envReason() {
|
|
61
|
+
return process.env.DSH_LEAN_ROUTER_CONCURRENCY === '0' ? 'env:DSH_LEAN_ROUTER_CONCURRENCY=0' : 'env:DSH_FLASH_PRESETS_CONCURRENCY=0';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 在一个作用域里标记一批只读工具为并发安全(幂等)。
|
|
66
|
+
* @returns {{marked: string[], kept: string[], missing: string[], failed: string[]}}
|
|
67
|
+
*/
|
|
68
|
+
export function markConcurrencySafe(tools, targets, scope) {
|
|
69
|
+
const result = { marked: [], kept: [], missing: [], failed: [] };
|
|
70
|
+
if (tools === undefined || tools === null || typeof tools.get !== 'function') {
|
|
71
|
+
result.failed.push('tools 服务不可用');
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
for (const name of targets) {
|
|
75
|
+
const def = getDef(tools, name, scope);
|
|
76
|
+
if (def === undefined || def === null) { result.missing.push(name); continue; }
|
|
77
|
+
if (typeof def.isConcurrencySafe === 'function') { result.kept.push(name); continue; }
|
|
78
|
+
try {
|
|
79
|
+
def.isConcurrencySafe = () => true;
|
|
80
|
+
if (def.isConcurrencySafe(PROBE) !== true) { delete def.isConcurrencySafe; result.failed.push(name + '(探测未返回 true)'); continue; }
|
|
81
|
+
result.marked.push(name);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
result.failed.push(name + '(' + msgOf(error) + ')');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** 撤掉本模块打上的标记(只删我们加的那个函数;原生声明过的不在该列表里)。 */
|
|
90
|
+
export function unmarkConcurrencySafe(tools, names, scope) {
|
|
91
|
+
for (const name of Array.isArray(names) ? names : []) {
|
|
92
|
+
try {
|
|
93
|
+
const def = getDef(tools, name, scope);
|
|
94
|
+
if (def !== undefined && def !== null && typeof def.isConcurrencySafe === 'function') delete def.isConcurrencySafe;
|
|
95
|
+
} catch (error) {}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 在**决策点**上兜底:pipeline 取定义走 ctx.tools.executable(name, scope, toolSet),
|
|
101
|
+
* 包住它就能在调度器真正问「这个工具能不能并行」之前把标记补上——不依赖定时扫描。
|
|
102
|
+
* @returns 还原函数;不可用/已装过则返回 null
|
|
103
|
+
*/
|
|
104
|
+
function installExecutableHook(tools, targetSet, onMark) {
|
|
105
|
+
if (tools === null || tools === undefined || typeof tools.executable !== 'function') return null;
|
|
106
|
+
let previous = null;
|
|
107
|
+
try { previous = tools[HOOK]; } catch (error) { previous = null; }
|
|
108
|
+
if (previous !== null && previous !== undefined) return null;
|
|
109
|
+
const original = tools.executable;
|
|
110
|
+
const wrapped = function (name, scope, toolSet) {
|
|
111
|
+
const def = original.call(this, name, scope, toolSet);
|
|
112
|
+
try {
|
|
113
|
+
if (def !== null && def !== undefined && targetSet.has(name) && typeof def.isConcurrencySafe !== 'function') {
|
|
114
|
+
def.isConcurrencySafe = () => true;
|
|
115
|
+
if (typeof onMark === 'function') onMark(def, name);
|
|
116
|
+
}
|
|
117
|
+
} catch (error) {}
|
|
118
|
+
return def;
|
|
119
|
+
};
|
|
120
|
+
try {
|
|
121
|
+
Object.defineProperty(tools, HOOK, { value: { original, wrapped }, configurable: true });
|
|
122
|
+
tools.executable = wrapped;
|
|
123
|
+
} catch (error) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
return () => {
|
|
127
|
+
try {
|
|
128
|
+
if (tools.executable === wrapped) tools.executable = original;
|
|
129
|
+
delete tools[HOOK];
|
|
130
|
+
} catch (error) {}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** 「调度器会怎么判」:pipeline 只认 === true,这里照抄它的判据。 */
|
|
135
|
+
function witnessOf(tools, targets, scope) {
|
|
136
|
+
return targets
|
|
137
|
+
.map((name) => {
|
|
138
|
+
let verdict = 'n/a';
|
|
139
|
+
try {
|
|
140
|
+
const def = getDef(tools, name, scope);
|
|
141
|
+
if (def !== undefined && def !== null && typeof def.isConcurrencySafe === 'function') verdict = String(def.isConcurrencySafe(PROBE) === true);
|
|
142
|
+
} catch (error) { verdict = '?'; }
|
|
143
|
+
return name + '=' + verdict;
|
|
144
|
+
})
|
|
145
|
+
.join(' ');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* 等 tools/agents 就绪后标记:先全局,再按已挂载 agent;之后定时补新 agent。
|
|
150
|
+
* @param ctx - 插件上下文
|
|
151
|
+
* @param options - {enabled?: boolean, tools?: string[] | string, sweepMs?: number, version?: string, onStatus?: (s) => void}
|
|
152
|
+
*/
|
|
153
|
+
export function installToolConcurrency(ctx, options) {
|
|
154
|
+
const opts = options !== null && typeof options === 'object' ? options : {};
|
|
155
|
+
// 版本号与状态回调由挂载方传入:日志带版本,排障只认这一行。
|
|
156
|
+
const VERSION = typeof opts.version === 'string' && opts.version.length > 0 ? opts.version : '0.0.0';
|
|
157
|
+
const report = typeof opts.onStatus === 'function' ? opts.onStatus : () => {};
|
|
158
|
+
if (opts.enabled === false || envOff()) {
|
|
159
|
+
const why = envOff() ? envReason() : 'config:toolConcurrency.enabled=false';
|
|
160
|
+
say('info', TAG + ' v' + VERSION + ' 未启用|原因=' + why + '|(默认开启;去掉这条配置或环境变量即可恢复)');
|
|
161
|
+
report({ active: false, reason: why, witness: 'n/a', scopes: 0 });
|
|
162
|
+
return { installed: false, reason: why };
|
|
163
|
+
}
|
|
164
|
+
const targets = parseTargets(opts.tools);
|
|
165
|
+
const sweepMs = Number.isFinite(Number(opts.sweepMs)) && Number(opts.sweepMs) >= 1000 ? Math.floor(Number(opts.sweepMs)) : DEFAULT_SWEEP_MS;
|
|
166
|
+
const targetSet = new Set(targets);
|
|
167
|
+
// lazy:决策点勾子上「顺手」标上的定义(不在扫描列表里),卸载时也要撤
|
|
168
|
+
const state = { tools: null, marked: new Map(), loggedScopes: 0, loggedWitness: false, timers: new Set(), hook: null, lazy: new Set() };
|
|
169
|
+
|
|
170
|
+
/** 唯一一行自检日志:版本 / 目标 / 扫描间隔 / 调度器判据 / 作用域数。 */
|
|
171
|
+
const lineOf = () => {
|
|
172
|
+
const scopes = state.marked.size - (state.marked.has('__global__') ? 1 : 0);
|
|
173
|
+
return TAG + ' v' + VERSION + ' 生效|targets=' + targets.join(',') + '|sweep=' + sweepMs + 'ms|witness='
|
|
174
|
+
+ witnessOf(state.tools, targets, undefined) + '|scopes=' + scopes;
|
|
175
|
+
};
|
|
176
|
+
const scopesOf = () => state.marked.size - (state.marked.has('__global__') ? 1 : 0);
|
|
177
|
+
|
|
178
|
+
const remember = (key, names, scope) => {
|
|
179
|
+
if (names.length === 0) return;
|
|
180
|
+
const prev = state.marked.get(key);
|
|
181
|
+
state.marked.set(key, { scope, names: [...new Set([...(prev ? prev.names : []), ...names])] });
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/** 扫一遍:全局 + 每个已挂载 agent。返回本轮新增标记数。 */
|
|
185
|
+
const sweep = (child, quiet) => {
|
|
186
|
+
const tools = state.tools === null ? serviceOf(child, 'tools') : state.tools;
|
|
187
|
+
if (tools === undefined || tools === null || typeof tools.get !== 'function') return 0;
|
|
188
|
+
state.tools = tools;
|
|
189
|
+
if (state.hook === null) {
|
|
190
|
+
state.hook = installExecutableHook(tools, targetSet, (def, name) => { state.lazy.add({ def, name }); }) ?? null;
|
|
191
|
+
}
|
|
192
|
+
let added = 0;
|
|
193
|
+
const global = markConcurrencySafe(tools, targets);
|
|
194
|
+
if (global.marked.length > 0) { remember('__global__', global.marked, undefined); added += global.marked.length; }
|
|
195
|
+
const agents = serviceOf(child, 'agents');
|
|
196
|
+
let list = [];
|
|
197
|
+
if (agents !== undefined && agents !== null && typeof agents.list === 'function') {
|
|
198
|
+
try { list = agents.list(); } catch (error) { list = []; }
|
|
199
|
+
}
|
|
200
|
+
for (const agent of Array.isArray(list) ? list : []) {
|
|
201
|
+
const result = markConcurrencySafe(tools, targets, agent);
|
|
202
|
+
if (result.marked.length === 0) continue;
|
|
203
|
+
remember(String(agent.id ?? list.indexOf(agent)), result.marked, agent);
|
|
204
|
+
added += result.marked.length;
|
|
205
|
+
}
|
|
206
|
+
if (!quiet) {
|
|
207
|
+
const witness = witnessOf(tools, targets, undefined);
|
|
208
|
+
const active = witness.includes('=true');
|
|
209
|
+
const scopes = scopesOf();
|
|
210
|
+
report({ active, reason: active ? null : 'not-marked', witness, scopes });
|
|
211
|
+
if (active && !state.loggedWitness) {
|
|
212
|
+
state.loggedWitness = true;
|
|
213
|
+
state.loggedScopes = scopes;
|
|
214
|
+
say('info', lineOf());
|
|
215
|
+
} else if (scopes > state.loggedScopes) {
|
|
216
|
+
state.loggedScopes = scopes;
|
|
217
|
+
let total = 0;
|
|
218
|
+
for (const entry of state.marked.values()) total += entry.names.length;
|
|
219
|
+
say('info', TAG + ' 作用域 +' + scopes + '(共标 ' + total + ' 处)|witness=' + witness);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return added;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const pass = () => {
|
|
226
|
+
try { sweep(ctx, false); } catch (error) { say('error', TAG + ' 扫描失败(已忽略):' + msgOf(error)); }
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
try {
|
|
230
|
+
ctx.inject(['tools', 'agents'], (child) => {
|
|
231
|
+
const warmup = setTimeout(() => {
|
|
232
|
+
try {
|
|
233
|
+
sweep(child, false);
|
|
234
|
+
// 首次诊断始终打一行:要么「生效」,要么「未生效 + 原因」,不留静默态
|
|
235
|
+
if (!state.loggedWitness) {
|
|
236
|
+
const tools = state.tools;
|
|
237
|
+
const first = targets[0];
|
|
238
|
+
const def = tools === null || tools === undefined ? undefined : getDef(tools, first);
|
|
239
|
+
say('info', TAG + ' v' + VERSION + ' 未生效|原因='
|
|
240
|
+
+ (def === undefined ? '工具尚未注册(' + first + ' 不在本宿主的工具表里)' : '判据还不是 true')
|
|
241
|
+
+ '|会话挂载后会自动补标');
|
|
242
|
+
report({ active: false, reason: def === undefined ? 'tool-missing' : 'not-marked', witness: witnessOf(tools, targets, undefined), scopes: scopesOf() });
|
|
243
|
+
}
|
|
244
|
+
} catch (error) {}
|
|
245
|
+
}, WARMUP_MS);
|
|
246
|
+
// 自续期定时器:快扫 60s → 慢扫兜底。用 Set 记录存活句柄,卸载时统一清掉。
|
|
247
|
+
const fastUntil = Date.now() + FAST_WINDOW_MS;
|
|
248
|
+
let delayMs = sweepMs;
|
|
249
|
+
const chain = () => {
|
|
250
|
+
const handle = setTimeout(() => {
|
|
251
|
+
state.timers.delete(handle);
|
|
252
|
+
if (Date.now() > fastUntil) delayMs = Math.max(sweepMs, SLOW_SWEEP_MS);
|
|
253
|
+
try { sweep(child, false); } catch (error) {}
|
|
254
|
+
chain();
|
|
255
|
+
}, delayMs);
|
|
256
|
+
try { if (typeof handle.unref === 'function') handle.unref(); } catch (error) {}
|
|
257
|
+
state.timers.add(handle);
|
|
258
|
+
};
|
|
259
|
+
chain();
|
|
260
|
+
// 新会话挂载时立刻补标记(扫描只是兜底)
|
|
261
|
+
try {
|
|
262
|
+
child.on('agent/created', (payload) => {
|
|
263
|
+
try {
|
|
264
|
+
const agent = payload !== null && typeof payload === 'object' && payload.agent !== undefined ? payload.agent : payload;
|
|
265
|
+
const tools = state.tools === null ? serviceOf(child, 'tools') : state.tools;
|
|
266
|
+
if (tools === null || tools === undefined) return;
|
|
267
|
+
const result = markConcurrencySafe(tools, targets, agent);
|
|
268
|
+
const key = agent !== null && agent !== undefined && agent.id !== undefined ? String(agent.id) : 'agent-' + state.marked.size;
|
|
269
|
+
if (result.marked.length > 0) remember(key, result.marked, agent);
|
|
270
|
+
try { sweep(child, false); } catch (error) {}
|
|
271
|
+
} catch (error) {}
|
|
272
|
+
});
|
|
273
|
+
} catch (error) {}
|
|
274
|
+
try { if (typeof warmup.unref === 'function') warmup.unref(); } catch (error) {}
|
|
275
|
+
state.timers.add(warmup);
|
|
276
|
+
try { sweep(child, false); } catch (error) { say('error', TAG + ' 首扫失败(已忽略):' + msgOf(error)); }
|
|
277
|
+
});
|
|
278
|
+
} catch (error) {
|
|
279
|
+
try { pass(); } catch (error2) {}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
try {
|
|
283
|
+
if (typeof ctx.effect === 'function') {
|
|
284
|
+
ctx.effect(() => () => {
|
|
285
|
+
for (const timer of state.timers) { try { clearTimeout(timer); clearInterval(timer); } catch (error) {} }
|
|
286
|
+
state.timers.clear();
|
|
287
|
+
if (typeof state.hook === 'function') { try { state.hook(); } catch (error) {} }
|
|
288
|
+
for (const entry of state.lazy) { try { if (typeof entry.def.isConcurrencySafe === 'function') delete entry.def.isConcurrencySafe; } catch (error) {} }
|
|
289
|
+
if (state.tools !== null) {
|
|
290
|
+
for (const entry of state.marked.values()) unmarkConcurrencySafe(state.tools, entry.names, entry.scope);
|
|
291
|
+
}
|
|
292
|
+
}, 'lean-concurrency: markers');
|
|
293
|
+
}
|
|
294
|
+
} catch (error) {}
|
|
295
|
+
|
|
296
|
+
return { installed: true, targets, sweepMs };
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* 默认导出插件(上游 lib/core.js 职责并入本文件):可作 bundle 插件行
|
|
301
|
+
* name 'dsh-lean-router/lean/tool-concurrency' 的解析目标。
|
|
302
|
+
* config 形状(core.js 原样):{ toolConcurrency: { enabled?, tools?, sweepMs? } }。
|
|
303
|
+
*/
|
|
304
|
+
export default {
|
|
305
|
+
name: 'lean-concurrency',
|
|
306
|
+
inject: ['tools', 'agents'],
|
|
307
|
+
apply(ctx, config) {
|
|
308
|
+
const cfg = config !== null && typeof config === 'object' ? config : {};
|
|
309
|
+
const tc = cfg.toolConcurrency !== null && typeof cfg.toolConcurrency === 'object' ? cfg.toolConcurrency : {};
|
|
310
|
+
const result = installToolConcurrency(ctx, { ...tc });
|
|
311
|
+
try { console.info(TAG + ' 插件行挂载|installed=' + String(result !== null && result.installed === true)); } catch (error) {}
|
|
312
|
+
// cordis 契约(@deepseek-ai/cordis lib/index.js _execute):apply 的返回值会当作 effect 校验,
|
|
313
|
+
// 只接受 dispose 函数 / null / undefined / thenable;返回普通对象会 throw TypeError("Invalid effect"),
|
|
314
|
+
// 真宿主把插件标红「异常」,且同一 patch 里排在它之后的 preset 行不再注册(1.0.1 实测现象)。
|
|
315
|
+
return undefined;
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
export const __internals = { markConcurrencySafe, unmarkConcurrencySafe, parseTargets, witnessOf, envOff, TAG, PROBE, DEFAULT_TARGETS, DEFAULT_SWEEP_MS };
|