dsh-plugin-tool-management 0.21.6 → 0.21.8
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/CHANGELOG.md +23 -0
- package/docs/UPDATE.md +2 -0
- package/lib/client.js +233 -50
- package/lib/hub-lock.js +121 -0
- package/lib/index.js +93 -8
- package/lib/mcp/state-section.js +4 -1
- package/lib/op-registry.js +2 -0
- package/lib/ops/candidates.js +5 -4
- package/lib/ops/compat.js +2 -2
- package/lib/ops/scope.js +29 -0
- package/lib/scenes/candidates.js +4 -2
- package/lib/scope/intent-store.js +30 -1
- package/lib/scope/intent.js +18 -0
- package/lib/scope/store.js +29 -1
- package/lib/update-check.js +199 -20
- package/package.json +12 -12
package/lib/index.js
CHANGED
|
@@ -51,6 +51,7 @@ import { createCandidates } from './scenes/candidates.js';
|
|
|
51
51
|
// 「已知工具」归一化与「当前可用工具数」原本定义在本文件(导出仅为测试接缝),
|
|
52
52
|
export { normalizeKnownTools, countEnabledTools } from './mcp/manager.js';
|
|
53
53
|
import { hubBackupDir, hubPath, hubRoot, migrateHubLayoutSync, relocateEntries } from './hub.js';
|
|
54
|
+
import { createHubFileLock } from './hub-lock.js';
|
|
54
55
|
// 分域的 HTTP ops(从本文件 handlers 表抽出,依赖显式传参)。
|
|
55
56
|
import { buildCompatOps } from './ops/compat.js';
|
|
56
57
|
import { createUpdateChecker } from './update-check.js';
|
|
@@ -60,12 +61,12 @@ import { buildQuickPromptOps } from './ops/quick-prompts.js';
|
|
|
60
61
|
import { buildScopeOps } from './ops/scope.js';
|
|
61
62
|
import { buildSessionOps } from './ops/sessions.js';
|
|
62
63
|
import { buildTrashRetentionOps } from './ops/trash-retention.js';
|
|
63
|
-
// 会话作用域:侧车 scope-overrides.json +
|
|
64
|
+
// 会话作用域:侧车 scope-overrides.json / scope-intent.json + 作用域 op + 启动对账。
|
|
64
65
|
import { rememberSessionCwd, scopeKeyOfAgent, scopeKeyOfIdSync, sessionIdentityOf, sessionIdOf, sessionScopeIdOf } from './scope/resolve.js';
|
|
65
66
|
import { createScopeStore } from './scope/store.js';
|
|
66
67
|
import { isWorkspaceScopeKey, scopeKeyLabel } from './scope/workspace-key.js';
|
|
67
68
|
import { createIntentStore } from './scope/intent-store.js';
|
|
68
|
-
import { effectiveLayerOf, intentOf, isIntentDomain, planReconcile, resolveResource, scanSessionClaims, withIntent, } from './scope/intent.js';
|
|
69
|
+
import { effectiveLayerOf, intentOf, isIntentDomain, planReconcile, pruneIntentKeys, resolveResource, scanSessionClaims, withIntent, } from './scope/intent.js';
|
|
69
70
|
import { SCOPE_FLAG_DOMAINS, clampPromptBaseline, hasPromptOverride, mcpToolServerSegments, promptBaselineOf, promptOverrideOf, removeSceneInScope, renameSceneInScope, sessionScenePinOf, sessionToolTableHidden, setSceneToolTableInScope, withBaseline, } from './scope/scope-overrides.js';
|
|
70
71
|
import { promptBaselineDiffers } from './memories/prompt-layer.js';
|
|
71
72
|
// 回收站保留期:侧车 `hub/trash-retention.json` + 六类回收站的到期清扫。
|
|
@@ -226,9 +227,13 @@ export default {
|
|
|
226
227
|
const { CONFIG_TOKEN, CONFIG_TOKEN_FROM_FILE, TOKEN_DISABLED, TOKEN, tokenMatches, BOOT_ID, acceptedThisBoot, markAccepted, unmarkAccepted } = createAccessToken({ config });
|
|
227
228
|
const wait = (ms) => ctx.timeout(ms);
|
|
228
229
|
const message = (e) => String((e && e.message) || e);
|
|
230
|
+
// 两层串行:`writeChain` 管同一进程内的排队;`hubLock` 管 web / desktop 两个进程
|
|
231
|
+
// 共用同一个 `$DSH_HOME` 时的整份读-改-写。只保留前者会让后写的整份覆盖先写的
|
|
232
|
+
// (停用表丢掉一条 = 已停用的 MCP 工具重新可调用)。
|
|
233
|
+
const hubLock = createHubFileLock(hubPath());
|
|
229
234
|
let writeChain = Promise.resolve();
|
|
230
235
|
function withWriteLock(fn) {
|
|
231
|
-
const run = writeChain.then(() => fn
|
|
236
|
+
const run = writeChain.then(() => hubLock.run(fn), () => hubLock.run(fn));
|
|
232
237
|
writeChain = run.then(() => undefined, () => undefined);
|
|
233
238
|
return run;
|
|
234
239
|
}
|
|
@@ -3193,6 +3198,7 @@ export default {
|
|
|
3193
3198
|
let intent;
|
|
3194
3199
|
let patchRows;
|
|
3195
3200
|
let roots;
|
|
3201
|
+
let skillStateOk = false;
|
|
3196
3202
|
try {
|
|
3197
3203
|
intent = await intentStore.read(true);
|
|
3198
3204
|
const [rowsResult, skillResult] = await Promise.all([
|
|
@@ -3201,7 +3207,8 @@ export default {
|
|
|
3201
3207
|
]);
|
|
3202
3208
|
patchRows = rowsResult;
|
|
3203
3209
|
const st = skillResult;
|
|
3204
|
-
|
|
3210
|
+
skillStateOk = !!st && st.ok !== false;
|
|
3211
|
+
roots = skillStateOk ? ((st.data && st.data.roots) || []) : [];
|
|
3205
3212
|
}
|
|
3206
3213
|
catch {
|
|
3207
3214
|
return report;
|
|
@@ -3230,17 +3237,24 @@ export default {
|
|
|
3230
3237
|
// 把声明名传给 core 会得到「技能不存在: pdf-reader」(真机:重启后
|
|
3231
3238
|
// 租约里的技能拉不起来)。界面的启停 op 收的是 `sk.name`,与这里同一个口径。
|
|
3232
3239
|
const skillRows = [];
|
|
3240
|
+
// 影子副本不参与对账,但**算"这个键还在"**:它只是暂时被同名条目压住,
|
|
3241
|
+
// 压住它的那份删掉后还会回来,不能把它的意图当成"资源已删除"清掉。
|
|
3242
|
+
const knownSkillKeys = new Set();
|
|
3233
3243
|
for (const root of roots) {
|
|
3234
3244
|
const rootKey = String((root && root.key) || '');
|
|
3235
3245
|
if (rootKey === '')
|
|
3236
3246
|
continue;
|
|
3237
3247
|
for (const sk of ((root && root.skills) || [])) {
|
|
3238
|
-
if (!sk
|
|
3248
|
+
if (!sk)
|
|
3239
3249
|
continue;
|
|
3240
3250
|
const name = String(sk.declaredName || sk.name || '');
|
|
3241
3251
|
if (name === '')
|
|
3242
3252
|
continue;
|
|
3243
|
-
|
|
3253
|
+
const key = rootKey + '/' + name;
|
|
3254
|
+
knownSkillKeys.add(key);
|
|
3255
|
+
if (sk.shadowedBy)
|
|
3256
|
+
continue;
|
|
3257
|
+
skillRows.push({ key, root: rootKey, name: String(sk.name || name), running: sk.enabled === true });
|
|
3244
3258
|
}
|
|
3245
3259
|
}
|
|
3246
3260
|
const claims = await leaseClaimsOf(servers, sources, skillRows.map((row) => row.key)).catch(() => ({
|
|
@@ -3284,7 +3298,8 @@ export default {
|
|
|
3284
3298
|
explicitClaims: (claims.skillExplicit.get(row.key) || []).length,
|
|
3285
3299
|
traced: tracedOf('skills', row.key),
|
|
3286
3300
|
})), { adoptExternal: opts.adoptExternal === true });
|
|
3287
|
-
// ① 意图采纳(升级推断 /
|
|
3301
|
+
// ① 意图采纳(升级推断 / 外部改动)与清理(资源已不存在)一次落盘。
|
|
3302
|
+
// 写失败不拦运行态 —— 下一轮会再试。
|
|
3288
3303
|
const intentWrites = [];
|
|
3289
3304
|
for (const d of mcpDecisions)
|
|
3290
3305
|
if (d.intentNext !== undefined)
|
|
@@ -3295,12 +3310,26 @@ export default {
|
|
|
3295
3310
|
for (const d of skillDecisions)
|
|
3296
3311
|
if (d.intentNext !== undefined)
|
|
3297
3312
|
intentWrites.push({ domain: 'skills', key: d.key, state: d.intentNext });
|
|
3313
|
+
// 清单完整才清理:技能状态读失败时 `roots` 是空数组,拿它当"全部删除"会把用户
|
|
3314
|
+
// 所有技能意图一次清掉(与 `liveSessionIds` 读不到不剪枝同一条纪律)。
|
|
3315
|
+
//
|
|
3316
|
+
// MCP 这一轮**不剪**:`patchServerRows` 只覆盖两份 patch,loader 里临时挂载 / 手写
|
|
3317
|
+
// 配置的服务器不在其中;而 loader 清单读取失败时 `configuredServerStates` 会静默退回
|
|
3318
|
+
// patch-only。拿一份可能缺项的名册剪意图,会把仍在运行的服务器决定删掉。
|
|
3319
|
+
const pruneSources = skillStateOk ? new Set(sources) : null;
|
|
3320
|
+
const pruneSkills = skillStateOk ? knownSkillKeys : null;
|
|
3321
|
+
const pruneNeeded = (pruneSources !== null && Object.keys(intent.skillSources).some((key) => !pruneSources.has(key)))
|
|
3322
|
+
|| (pruneSkills !== null && Object.keys(intent.skills).some((key) => !pruneSkills.has(key)));
|
|
3298
3323
|
let finalIntent = intent;
|
|
3299
|
-
if (intentWrites.length > 0) {
|
|
3324
|
+
if (intentWrites.length > 0 || pruneNeeded) {
|
|
3300
3325
|
const res = await intentStore.mutate((current) => {
|
|
3301
3326
|
let next = current;
|
|
3302
3327
|
for (const write of intentWrites)
|
|
3303
3328
|
next = withIntent(next, write.domain, [write.key], write.state);
|
|
3329
|
+
if (pruneSources !== null)
|
|
3330
|
+
next = pruneIntentKeys(next, 'skillSources', pruneSources);
|
|
3331
|
+
if (pruneSkills !== null)
|
|
3332
|
+
next = pruneIntentKeys(next, 'skills', pruneSkills);
|
|
3304
3333
|
return next;
|
|
3305
3334
|
});
|
|
3306
3335
|
if (res.ok)
|
|
@@ -3818,6 +3847,59 @@ export default {
|
|
|
3818
3847
|
stateDir: hubPath(),
|
|
3819
3848
|
current: PKG_VERSION,
|
|
3820
3849
|
currentEngines: PKG_DSH_RANGE,
|
|
3850
|
+
// 下载源跟宿主走:`configuredRegistries` 是宿主安装器自己的配置源(第一源 + fallback),
|
|
3851
|
+
// `fastest()` 是宿主插件页用的双源测速。两个都软取 —— 服务没挂载或字段不在
|
|
3852
|
+
// 就返回 null,更新检查退回 npm 官方单源,不因为取不到宿主服务而失败。
|
|
3853
|
+
//
|
|
3854
|
+
// **先读 `configuredRegistries` 属性,不先调 `registries()`**:后者每次都会 spawn
|
|
3855
|
+
// `pnpm config get registry`(宿主默认 20 秒超时),而更新检查只等 2.5 秒 —— 冷启动时
|
|
3856
|
+
// 会把用户显式配置的私有源丢掉。属性里已经有显式源时不需要 pnpm 的 `resolved`;
|
|
3857
|
+
// 只有「没配置第一源、也没有 fallback」的 `.npmrc`-only 机器才回退去问宿主。
|
|
3858
|
+
registries: async () => {
|
|
3859
|
+
try {
|
|
3860
|
+
const manager = ctx.get('pluginManager');
|
|
3861
|
+
if (!manager)
|
|
3862
|
+
return null;
|
|
3863
|
+
const direct = manager.configuredRegistries;
|
|
3864
|
+
if (direct && typeof direct === 'object') {
|
|
3865
|
+
const fallback = Array.isArray(direct.fallbackRegistries)
|
|
3866
|
+
? direct.fallbackRegistries.filter((value) => typeof value === 'string' && value.trim() !== '')
|
|
3867
|
+
: [];
|
|
3868
|
+
const registry = typeof direct.registry === 'string' && direct.registry.trim() !== '' ? direct.registry : null;
|
|
3869
|
+
if (registry !== null || fallback.length > 0) {
|
|
3870
|
+
return { registry, fallbackRegistries: fallback, resolved: null };
|
|
3871
|
+
}
|
|
3872
|
+
}
|
|
3873
|
+
if (typeof manager.registries !== 'function')
|
|
3874
|
+
return null;
|
|
3875
|
+
const raw = await manager.registries();
|
|
3876
|
+
if (!raw || typeof raw !== 'object')
|
|
3877
|
+
return null;
|
|
3878
|
+
const fallback = Array.isArray(raw.fallbackRegistries)
|
|
3879
|
+
? raw.fallbackRegistries.filter((value) => typeof value === 'string' && value.trim() !== '')
|
|
3880
|
+
: [];
|
|
3881
|
+
return {
|
|
3882
|
+
registry: typeof raw.registry === 'string' && raw.registry.trim() !== '' ? raw.registry : null,
|
|
3883
|
+
fallbackRegistries: fallback,
|
|
3884
|
+
resolved: typeof raw.resolved === 'string' && raw.resolved.trim() !== '' ? raw.resolved : null,
|
|
3885
|
+
};
|
|
3886
|
+
}
|
|
3887
|
+
catch {
|
|
3888
|
+
return null;
|
|
3889
|
+
}
|
|
3890
|
+
},
|
|
3891
|
+
fastest: async () => {
|
|
3892
|
+
try {
|
|
3893
|
+
const probe = ctx.get('pluginRegistryProbe');
|
|
3894
|
+
if (!probe || typeof probe.fastest !== 'function')
|
|
3895
|
+
return null;
|
|
3896
|
+
const answer = await probe.fastest();
|
|
3897
|
+
return typeof answer === 'string' && answer.trim() !== '' ? answer : null;
|
|
3898
|
+
}
|
|
3899
|
+
catch {
|
|
3900
|
+
return null;
|
|
3901
|
+
}
|
|
3902
|
+
},
|
|
3821
3903
|
hostVersion: () => {
|
|
3822
3904
|
try {
|
|
3823
3905
|
const registry = history.getSessionsRegistry();
|
|
@@ -4041,6 +4123,9 @@ export default {
|
|
|
4041
4123
|
const res = await intentStore.mutate((current) => withIntent(current, domain, keys, state));
|
|
4042
4124
|
return res.ok ? null : res.error;
|
|
4043
4125
|
},
|
|
4126
|
+
// 作用域侧车损坏时的显式修复通道(scope-repair):隔离现场后按空表继续。
|
|
4127
|
+
repairScope: () => scopeStore.repair(),
|
|
4128
|
+
repairIntent: () => intentStore.repair(),
|
|
4044
4129
|
// 基线:会话**创建时**的冻结快照 —— 启动期与 agent/created 各调一次(`ensureBaselineFor`)。
|
|
4045
4130
|
captureBaseline: () => captureBaselineSnapshot(),
|
|
4046
4131
|
// 会话提示词:应用前读一次正文(校验存在性 + 拒绝空预设)
|
package/lib/mcp/state-section.js
CHANGED
|
@@ -207,6 +207,7 @@ sessionTools = { on: [], off: [] }) {
|
|
|
207
207
|
/** 创建 SWR 的 MCP 状态目录。计算失败时保留上一次的值,不把段清空。 */
|
|
208
208
|
export function createMcpStateCatalog(deps, opts = {}) {
|
|
209
209
|
const ttlMs = opts.ttlMs ?? 3000;
|
|
210
|
+
const emptyTtlMs = opts.emptyTtlMs ?? 60_000;
|
|
210
211
|
const now = opts.now ?? (() => Date.now());
|
|
211
212
|
// 缓存的是**行数据**而不是渲染结果(与技能 / 子智能体两个目录同一手法):清单只依赖磁盘,
|
|
212
213
|
// 而尾句要不要点名查询工具取决于**这个 agent 手里有没有它**。渲染是纯字符串操作,代价可忽略。
|
|
@@ -216,6 +217,8 @@ export function createMcpStateCatalog(deps, opts = {}) {
|
|
|
216
217
|
// 渲染缓存键 = (尾句前提, 本会话停用的服务器)。两者都影响正文,少一个就会让 A 的段
|
|
217
218
|
// 出现在 B 里(与技能 / 人设两个目录同一手法)。
|
|
218
219
|
let rendered = null;
|
|
220
|
+
/** 空清单按 `emptyTtlMs` 走,有行时仍按 `ttlMs`(判据见 `emptyTtlMs` 的注释)。 */
|
|
221
|
+
const ttlFor = () => (data !== null && data.length === 0 ? emptyTtlMs : ttlMs);
|
|
219
222
|
const recompute = async () => {
|
|
220
223
|
try {
|
|
221
224
|
const result = await deps.rows();
|
|
@@ -255,7 +258,7 @@ export function createMcpStateCatalog(deps, opts = {}) {
|
|
|
255
258
|
};
|
|
256
259
|
const graceMs = opts.graceMs ?? 60_000;
|
|
257
260
|
const text = (agent) => {
|
|
258
|
-
if (now() - loadedAt >
|
|
261
|
+
if (now() - loadedAt > ttlFor())
|
|
259
262
|
void revalidate();
|
|
260
263
|
if (data === null)
|
|
261
264
|
return '';
|
package/lib/op-registry.js
CHANGED
|
@@ -276,6 +276,8 @@ export const OP_REGISTRY = Object.freeze({
|
|
|
276
276
|
'scope-clear': { write: true },
|
|
277
277
|
// 锁开关自己不能被自己挡住,否则锁上了解不开(与 `rules-scene-lock` 同一条)。
|
|
278
278
|
'scope-lock': { write: true },
|
|
279
|
+
// 作用域侧车损坏后的显式修复:隔离现场、按空表继续。**不冻结** —— 场景锁着时也可能需要修。
|
|
280
|
+
'scope-repair': { write: true },
|
|
279
281
|
// 全局意图(`hub/scope-intent.json`):MCP 服务器 / 技能 / 技能来源三格的**全局开关**。
|
|
280
282
|
// 与 `mcpm-set-enabled` / `skill-source-enable` 同档:写全局定义、场景锁要冻结它。
|
|
281
283
|
// 会话层的 scope-set 仍不冻结(它只写租约,不改全局)。
|
package/lib/ops/candidates.js
CHANGED
|
@@ -15,12 +15,13 @@ export function buildCandidateOps(deps) {
|
|
|
15
15
|
...(await deps.presetToolCandidates()),
|
|
16
16
|
unavailable: deps.getToolFailures().map((f) => ({ ...f })),
|
|
17
17
|
}),
|
|
18
|
-
// model-candidates:宿主 LLM 目录里的 (provider, model)
|
|
18
|
+
// model-candidates:宿主 LLM 目录里的 (provider, model) 对(`listModels`,官方适配器带缓存)。
|
|
19
19
|
'model-candidates': async () => ({ ok: true, ...(await deps.modelCandidates()) }),
|
|
20
20
|
// model-reasoning:某个 (provider, model) 支持的思考强度档位(人设表单的「思考强度」下拉)。
|
|
21
|
-
// 为什么单独一个 op
|
|
22
|
-
// model-candidates
|
|
23
|
-
//
|
|
21
|
+
// 为什么单独一个 op:档位清单要逐个模型问 adapter(`llm.resolveModelInfo`,异步、
|
|
22
|
+
// 可能联网),代价随模型数量增长;而 model-candidates 读的是有缓存的官方目录。
|
|
23
|
+
// 捆在一次调用里会让"打开人设表单"多付这部分代价。这里只做参数归一与转发,
|
|
24
|
+
// 判定留给调用方(界面按 ok 分两态显示)。
|
|
24
25
|
'model-reasoning': async (args) => {
|
|
25
26
|
const provider = String((args && args.provider) || '').trim();
|
|
26
27
|
const model = String((args && args.model) || '').trim();
|
package/lib/ops/compat.js
CHANGED
|
@@ -443,14 +443,14 @@ export function buildCompatOps(deps) {
|
|
|
443
443
|
'update-status': async (args) => {
|
|
444
444
|
const checker = deps.updateChecker;
|
|
445
445
|
if (!checker) {
|
|
446
|
-
return { ok: true, status: 'unknown', current: null, host: null, newest: null, bestCompatible: null, command: null, checkedAt: null, fromCache: false, error: '更新检查未接线' };
|
|
446
|
+
return { ok: true, status: 'unknown', current: null, host: null, newest: null, bestCompatible: null, source: null, command: null, checkedAt: null, fromCache: false, error: '更新检查未接线' };
|
|
447
447
|
}
|
|
448
448
|
try {
|
|
449
449
|
// `ok` 刻意放在最后覆盖:op 本身成功,答案由 `status` 表达(含 `unknown`)。
|
|
450
450
|
return { ...(await checker.check(Boolean(args && args.refresh))), ok: true };
|
|
451
451
|
}
|
|
452
452
|
catch (e) {
|
|
453
|
-
return { ok: true, status: 'unknown', current: null, host: null, newest: null, bestCompatible: null, command: null, checkedAt: null, fromCache: false, error: deps.message(e) };
|
|
453
|
+
return { ok: true, status: 'unknown', current: null, host: null, newest: null, bestCompatible: null, source: null, command: null, checkedAt: null, fromCache: false, error: deps.message(e) };
|
|
454
454
|
}
|
|
455
455
|
},
|
|
456
456
|
};
|
package/lib/ops/scope.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// scope-sessions-list 只读:当前会话区里的未归档会话(下拉框的数据源,按工作区分组)
|
|
7
7
|
// scope-lock 写:锁 / 解锁某个会话的覆盖
|
|
8
8
|
// scope-intent-set 写:MCP 服务器 / 技能来源的全局意图(on / off / blocked)
|
|
9
|
+
// scope-repair 写:隔离损坏的 scope-overrides.json / scope-intent.json(显式修复)
|
|
9
10
|
//
|
|
10
11
|
// ## 为什么这几条都不标 frozen
|
|
11
12
|
//
|
|
@@ -1193,5 +1194,33 @@ export function buildScopeOps(deps) {
|
|
|
1193
1194
|
return { ok: false, error: '保存失败: ' + res.error };
|
|
1194
1195
|
return { ok: true, sessionId, locked };
|
|
1195
1196
|
},
|
|
1197
|
+
/**
|
|
1198
|
+
* 修复损坏的作用域侧车:只把解析不了的文件改名留存,不覆盖任何健康文件。
|
|
1199
|
+
*
|
|
1200
|
+
* 这是**显式**的破坏性动作:隔离后覆盖表/意图表按空表继续,下一次对账会把意图从
|
|
1201
|
+
* 运行态反推。界面必须先确认再调用;健康的文件返回 `null`,不做任何事。
|
|
1202
|
+
*/
|
|
1203
|
+
'scope-repair': async () => {
|
|
1204
|
+
const errors = [];
|
|
1205
|
+
let scopeQuarantined = null;
|
|
1206
|
+
let intentQuarantined = null;
|
|
1207
|
+
if (deps.repairScope) {
|
|
1208
|
+
const res = await deps.repairScope();
|
|
1209
|
+
if (res.ok)
|
|
1210
|
+
scopeQuarantined = res.quarantined;
|
|
1211
|
+
else
|
|
1212
|
+
errors.push('scope-overrides.json: ' + res.error);
|
|
1213
|
+
}
|
|
1214
|
+
if (deps.repairIntent) {
|
|
1215
|
+
const res = await deps.repairIntent();
|
|
1216
|
+
if (res.ok)
|
|
1217
|
+
intentQuarantined = res.quarantined;
|
|
1218
|
+
else
|
|
1219
|
+
errors.push('scope-intent.json: ' + res.error);
|
|
1220
|
+
}
|
|
1221
|
+
if (errors.length)
|
|
1222
|
+
return { ok: false, error: errors.join(';') };
|
|
1223
|
+
return { ok: true, scopeQuarantined, intentQuarantined };
|
|
1224
|
+
},
|
|
1196
1225
|
};
|
|
1197
1226
|
}
|
package/lib/scenes/candidates.js
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
// 直接读各自 service 的 op,无缓存;
|
|
9
9
|
// * **预设工具**(presetToolCandidates / presetToolNames)—— 每次枚举要为每个预设取一次
|
|
10
10
|
// 官方 `acquireScope` 租约 + 读一次 `tools.schemas()`,所以按 PRESET_ENUM_CACHE_MS 缓存;
|
|
11
|
-
// * **模型**(modelCandidates)——
|
|
11
|
+
// * **模型**(modelCandidates)—— 读宿主 LLM 目录(`listModels`)。官方 DeepSeek API-key
|
|
12
|
+
// 适配器把它实现为服务端模型列表(带缓存,过期后台刷新),不是纯本地读取。
|
|
12
13
|
//
|
|
13
14
|
// 依赖全部经 deps 显式传入。注意 \`toolKeyParts\` 留在 index.ts:场景档案引擎也在用它,
|
|
14
15
|
// 放进本文件会让两个域互相引用。
|
|
@@ -409,7 +410,8 @@ export function createCandidates(deps) {
|
|
|
409
410
|
}
|
|
410
411
|
/**
|
|
411
412
|
* 模型候选(人设的「模型」与「模型来源」两个下拉):宿主已注册的 provider + 各 provider
|
|
412
|
-
*
|
|
413
|
+
* 能宣告的模型。`listModels` 是官方契约,但**不是纯本地读取** —— 官方 DeepSeek API-key
|
|
414
|
+
* 适配器把它实现为服务端模型列表,自带缓存、过期后台刷新,首次访问会等一次加载。
|
|
413
415
|
* 拿不到就返回空列表,UI 退回手填(跨来源模型如 sensenova 的手工条目仍需手填兜底)。
|
|
414
416
|
*
|
|
415
417
|
* 两份投影、用途不同:
|
|
@@ -98,9 +98,38 @@ export function createIntentStore(deps) {
|
|
|
98
98
|
}
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
|
+
async function repair() {
|
|
102
|
+
return deps.withWriteLock(async () => {
|
|
103
|
+
let raw;
|
|
104
|
+
try {
|
|
105
|
+
raw = await readFile(file(), 'utf8');
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
if (e?.code === 'ENOENT')
|
|
109
|
+
return { ok: true, quarantined: null };
|
|
110
|
+
return { ok: false, error: deps.message(e) };
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
normalizeScopeIntent(JSON.parse(raw));
|
|
114
|
+
return { ok: true, quarantined: null };
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
const target = file() + '.corrupt-' + Date.now();
|
|
118
|
+
try {
|
|
119
|
+
await renameWithRetry(file(), target);
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
return { ok: false, error: deps.message(e) };
|
|
123
|
+
}
|
|
124
|
+
cache = null;
|
|
125
|
+
rev += 1;
|
|
126
|
+
return { ok: true, quarantined: target };
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
101
130
|
function invalidate() {
|
|
102
131
|
cache = null;
|
|
103
132
|
rev += 1;
|
|
104
133
|
}
|
|
105
|
-
return { read, snapshot, revision: () => rev, mutate, invalidate };
|
|
134
|
+
return { read, snapshot, revision: () => rev, mutate, repair, invalidate };
|
|
106
135
|
}
|
package/lib/scope/intent.js
CHANGED
|
@@ -92,6 +92,24 @@ export function withIntent(intent, domain, keys, state) {
|
|
|
92
92
|
}
|
|
93
93
|
return { ...intent, [domain]: map };
|
|
94
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* 只保留 `keep` 里的键(返回新对象,不改入参)。
|
|
97
|
+
*
|
|
98
|
+
* 资源被删除后它的意图要跟着消失:否则重新创建同名资源会继承旧的 off / blocked,
|
|
99
|
+
* 用户以为新资源默认能用,实际被一条已经无主的决定压着。调用方必须**先确认清单完整**:
|
|
100
|
+
* 清单读失败时传空集合会把所有意图清掉,那比不清理危险得多。
|
|
101
|
+
*/
|
|
102
|
+
export function pruneIntentKeys(intent, domain, keep) {
|
|
103
|
+
let changed = false;
|
|
104
|
+
const next = Object.create(null);
|
|
105
|
+
for (const [key, state] of Object.entries(intent[domain])) {
|
|
106
|
+
if (keep.has(key))
|
|
107
|
+
next[key] = state;
|
|
108
|
+
else
|
|
109
|
+
changed = true;
|
|
110
|
+
}
|
|
111
|
+
return changed ? { ...intent, [domain]: next } : intent;
|
|
112
|
+
}
|
|
95
113
|
/**
|
|
96
114
|
* 一台服务器 / 一个来源在某个会话里的可见性。`lower` 是会话的那三层
|
|
97
115
|
* (覆盖 → 场景层 → 基线)的并值,`undefined` = 三层都没话说。
|
package/lib/scope/store.js
CHANGED
|
@@ -235,10 +235,38 @@ export function createScopeStore(deps) {
|
|
|
235
235
|
}
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
|
+
async function repair() {
|
|
239
|
+
return deps.withWriteLock(async () => {
|
|
240
|
+
let raw;
|
|
241
|
+
try {
|
|
242
|
+
raw = await readFile(file(), 'utf8');
|
|
243
|
+
}
|
|
244
|
+
catch (e) {
|
|
245
|
+
if (e?.code === 'ENOENT')
|
|
246
|
+
return { ok: true, quarantined: null };
|
|
247
|
+
return { ok: false, error: deps.message(e) };
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
normalizeScopeOverrides(JSON.parse(raw));
|
|
251
|
+
return { ok: true, quarantined: null };
|
|
252
|
+
}
|
|
253
|
+
catch {
|
|
254
|
+
const target = file() + '.corrupt-' + Date.now();
|
|
255
|
+
try {
|
|
256
|
+
await renameWithRetry(file(), target);
|
|
257
|
+
}
|
|
258
|
+
catch (e) {
|
|
259
|
+
return { ok: false, error: deps.message(e) };
|
|
260
|
+
}
|
|
261
|
+
cache = null;
|
|
262
|
+
return { ok: true, quarantined: target };
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
238
266
|
function invalidate() {
|
|
239
267
|
cache = null;
|
|
240
268
|
}
|
|
241
|
-
return { read, readStrict, snapshot, mode, modeSync, scopeOf, scopeOfSync, switchMode, mutate, mutateAll, clearSession, pruneDeletedSessions, invalidate };
|
|
269
|
+
return { read, readStrict, snapshot, mode, modeSync, scopeOf, scopeOfSync, switchMode, mutate, mutateAll, clearSession, pruneDeletedSessions, repair, invalidate };
|
|
242
270
|
}
|
|
243
271
|
/**
|
|
244
272
|
* 剪枝的**纯函数**部分(导出给契约测试):留下 `live` 里有的会话。
|