dsh-plugin-tool-management 0.21.1 → 0.21.2
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 +73 -0
- package/README.md +42 -6
- package/README_EN.md +40 -6
- package/docs/images/1-EN.png +0 -0
- package/docs/images/1.png +0 -0
- package/docs/images/2-EN.png +0 -0
- package/docs/images/2.png +0 -0
- package/docs/images/3-EN.png +0 -0
- package/docs/images/3.png +0 -0
- package/docs/images/4-EN.png +0 -0
- package/docs/images/4.png +0 -0
- package/docs/images/5-EN.png +0 -0
- package/docs/images/5.png +0 -0
- package/docs/images/6-EN.png +0 -0
- package/docs/images/6.png +0 -0
- package/docs/images/7-EN.png +0 -0
- package/docs/images/7.png +0 -0
- package/docs/images/8-EN.png +0 -0
- package/docs/images/8.png +0 -0
- package/docs/update.md +37 -36
- package/lib/boot/reconcile.js +157 -0
- package/lib/client.js +6658 -3146
- package/lib/compat/patch-dialect.js +14 -1
- package/lib/compat/probe.js +25 -21
- package/lib/context-inject-frame.js +27 -36
- package/lib/context-inject-select.js +59 -4
- package/lib/context-inject-surface.js +49 -3
- package/lib/context-inject.js +144 -21
- package/lib/diagnostics.js +77 -0
- package/lib/http-api.js +39 -23
- package/lib/http-fence.js +40 -5
- package/lib/imports/unzip.js +48 -0
- package/lib/imports/upload.js +8 -36
- package/lib/index.js +2906 -166
- package/lib/mcp/disabled-tools.js +96 -0
- package/lib/mcp/manager.js +559 -128
- package/lib/mcp/restart-marker.js +110 -0
- package/lib/mcp/state-section.js +132 -43
- package/lib/mcp/tool-visibility.js +348 -56
- package/lib/memories/archive-engine.js +39 -14
- package/lib/memories/discovery.js +30 -10
- package/lib/memories/index-io.js +217 -18
- package/lib/memories/projection.js +20 -3
- package/lib/memories/prompt-layer.js +37 -0
- package/lib/memories/search.js +86 -0
- package/lib/memories/service.js +327 -91
- package/lib/memories/snapshot.js +49 -10
- package/lib/op-registry.js +46 -4
- package/lib/ops/candidates.js +11 -3
- package/lib/ops/compat.js +46 -4
- package/lib/ops/memory.js +78 -9
- package/lib/ops/prompts.js +49 -5
- package/lib/ops/quick-prompts.js +24 -2
- package/lib/ops/scene-records.js +7 -0
- package/lib/ops/scene-sync.js +23 -4
- package/lib/ops/scope.js +1093 -0
- package/lib/ops/sessions.js +5 -2
- package/lib/ops/snapshot.js +55 -20
- package/lib/ops/state-doctor.js +39 -4
- package/lib/paths.js +50 -3
- package/lib/prompts/preset-id.js +4 -0
- package/lib/prompts/project-instructions.js +162 -0
- package/lib/prompts/quick-service.js +5 -4
- package/lib/prompts/service.js +20 -9
- package/lib/request-gate.js +6 -4
- package/lib/scene-linkage.js +12 -0
- package/lib/scene-prompt-sync.js +1 -1
- package/lib/scenes/candidates.js +8 -1
- package/lib/scope/intent-store.js +105 -0
- package/lib/scope/intent.js +376 -0
- package/lib/scope/resolve.js +190 -0
- package/lib/scope/scope-overrides.js +894 -0
- package/lib/scope/store.js +262 -0
- package/lib/scope/workspace-key.js +64 -0
- package/lib/sessions/history.js +3 -2
- package/lib/settings-sidecars.js +50 -24
- package/lib/skills/catalog.js +206 -33
- package/lib/skills/core.js +1 -1
- package/lib/skills/frontmatter.js +121 -0
- package/lib/skills/service.js +145 -20
- package/lib/stale-write.js +74 -0
- package/lib/subagents/catalog.js +47 -13
- package/lib/subagents/persona-parse.js +26 -5
- package/lib/subagents/persona-write.js +11 -7
- package/lib/subagents/service.js +3 -2
- package/lib/subagents/tools.js +78 -8
- package/lib/token-config.js +25 -5
- package/lib/tool-table-switch.js +141 -49
- package/lib/tools/deps.js +151 -5
- package/lib/tools/mcp.js +189 -39
- package/lib/tools/memory.js +103 -18
- package/lib/tools/prompt.js +61 -9
- package/lib/tools/remove.js +46 -21
- package/lib/tools/scene.js +120 -26
- package/lib/tools/skills.js +191 -30
- package/lib/tools/subagent.js +52 -20
- package/lib/tools/table.js +48 -11
- package/lib/trash-retention.js +3 -2
- package/lib/update-check.js +218 -0
- package/package.json +16 -14
package/lib/tools/skills.js
CHANGED
|
@@ -5,28 +5,44 @@
|
|
|
5
5
|
// (先读一次 `skill-state`)。改的分支走新加的 `skill-update` op,它只认本插件可写的两个根
|
|
6
6
|
// (hub = 导入落点 / dsh = 新建默认落点,2026-10-15 裁定)里的胜出者。
|
|
7
7
|
import { toKebab } from '../skills/core.js';
|
|
8
|
-
import { locateSkillRoot, text } from './deps.js';
|
|
8
|
+
import { effectiveScope, globalActionNote, isolationOffNote, locateSkillRoot, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, sessionScopeOf, text } from './deps.js';
|
|
9
9
|
export function buildSkillTools(deps) {
|
|
10
10
|
const { defineTool, register } = deps;
|
|
11
11
|
// Skill-facing tools: list, toggle, create. create is gated by the
|
|
12
12
|
// tools/pre-execute hook below (the model must ask before writing files).
|
|
13
13
|
register(defineTool({
|
|
14
14
|
name: 'skill_manager_list',
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
description: 'List skills with enabled state, effective/shadowed status and source file path. The "Current skills" reminder carries callable skills and summaries only; use this for entries that are off, for
|
|
15
|
+
// 关于「官方 `skill` 工具挂载时这条读能力由谁提供」:两处都不写了(2026-10-21 审查 P2)。
|
|
16
|
+
// 原先把它放在 `skill_manager_read` 的描述里,但那条工具在官方工具挂载时会被
|
|
17
|
+
// `CARRIER_DUPLICATES` 直接隐藏 —— 能看到那句话的 agent,条件必然不成立;条件成立的
|
|
18
|
+
// agent,看不到那句话。这条描述里再写一遍同样是白付 token。工具被隐藏本身就是最准确的信号。
|
|
19
|
+
description: 'List skills with enabled state, effective/shadowed status and source file path. The "Current skills" reminder carries callable skills and summaries only; use this for entries that are off, for source paths, and to see which source wins a name collision — a copy marked "shadowed-by:<root>" stays inactive even if enabled, "preferred" marks the winner. Defaults to enabled only; all=true for every entry.',
|
|
20
20
|
parameters: {
|
|
21
21
|
all: { type: 'boolean', description: 'Include disabled and shadowed entries (default false).' },
|
|
22
22
|
},
|
|
23
23
|
output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
|
|
24
24
|
async execute(args, exec) {
|
|
25
25
|
const showAll = Boolean(args && args.all === true);
|
|
26
|
-
|
|
26
|
+
// 会话层(0.21.2,计划 §8.2「skill_manager_list 按会话过滤」):
|
|
27
|
+
// · `sessionId` 让 op 只按**本会话的 cwd** 推导项目技能根(不给 = 全部活动会话的并集,
|
|
28
|
+
// 两个对话看到同一份清单);
|
|
29
|
+
// · `overrides` 是本会话的逐条开关,标出"全局开着、本会话关掉"的那几条。
|
|
30
|
+
const scoped = sessionScopeOf(deps, exec && exec.agent);
|
|
31
|
+
const r = await deps.skillsOps['skill-state'](scoped === null ? {} : { sessionId: scoped.sessionId });
|
|
27
32
|
if (!r || r.ok === false)
|
|
28
33
|
throw new Error((r && r.error) || 'skill-state failed');
|
|
29
34
|
const data = r.data || {};
|
|
35
|
+
const overrides = scoped?.scope?.skills;
|
|
36
|
+
const flagOf = (domain, key) => {
|
|
37
|
+
if (deps.sessionFlagOf === undefined || key === '')
|
|
38
|
+
return undefined;
|
|
39
|
+
try {
|
|
40
|
+
return deps.sessionFlagOf(exec && exec.agent, domain, key);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
30
46
|
// 同名(canonical = declaredName || name)跨根重复时只有**一份**生效,排序规则是
|
|
31
47
|
// 「同名首选 > 来源优先级 rank」,**与启用状态无关**(core 的 groupLoadableSkillsByName)。
|
|
32
48
|
// 于是「启用被覆盖的那份」是静默无效的:工具会回 OK,技能却依然不可用 —— 用户实测
|
|
@@ -39,24 +55,49 @@ export function buildSkillTools(deps) {
|
|
|
39
55
|
const rows = [];
|
|
40
56
|
const counts = new Map();
|
|
41
57
|
for (const root of data.roots || []) {
|
|
58
|
+
// 来源级停用 = 上层闸:里面的单条技能一条都加载不了。0.21.2 起这一格也有会话层
|
|
59
|
+
// (skillSources):场景勾中的来源为开、没勾的为关;拨开一个来源时写侧会把它按
|
|
60
|
+
// 租约跑起来(来源关着时技能级 enable 会被 core 吞掉)。
|
|
61
|
+
const rootKey = String(root.key || '');
|
|
62
|
+
const srcFlag = flagOf('skillSources', rootKey);
|
|
63
|
+
// 没有会话层时落到**全局意图**(`globalOn`,0.21.2),不是运行态(`enabled`):
|
|
64
|
+
// 租约期间两者不同,读运行态会把"只为几个对话开着"报成"全局开着"。
|
|
65
|
+
const rootEnabled = typeof srcFlag === 'boolean' ? srcFlag
|
|
66
|
+
: (typeof root.globalOn === 'boolean' ? root.globalOn : root.enabled !== false);
|
|
67
|
+
const rootLeases = typeof root.leaseCount === 'number' ? root.leaseCount : 0;
|
|
42
68
|
for (const skill of root.skills || []) {
|
|
43
69
|
const key = String(skill.declaredName || skill.name || '');
|
|
44
70
|
counts.set(key, (counts.get(key) || 0) + 1);
|
|
45
71
|
// `enabled` 只写在「胜出者」上(core 的 markWinners);影子副本与不可加载的技能
|
|
46
72
|
// 没有这个字段。原先直接读 skill.enabled,这些技能一律被报成 disabled ——
|
|
47
73
|
// 这里改用与界面同口径的兜底推导(client 的 isSkillEnabled)。
|
|
48
|
-
const
|
|
74
|
+
const globalEnabled = skill.enabled !== undefined
|
|
49
75
|
? skill.enabled === true
|
|
50
76
|
: (skill.invocationPolicyValid && skill.modelInvocable && skill.userInvocable && skill.managerEnabled !== false);
|
|
77
|
+
// 会话层:四层并值优先,键与档案 / 注入段逐字一致(`<rootKey>/<声明名>`)。
|
|
78
|
+
const over = key === '' ? undefined : flagOf('skills', rootKey + '/' + key);
|
|
79
|
+
// 这一层没说话时落到**全局意图**(`globalOn`),不是运行态:租约期间两者不同,
|
|
80
|
+
// 读运行态会把"别的对话临时开着"报成"全局开着"(与上面来源那一格同一条)。
|
|
81
|
+
const skillGlobal = typeof skill.globalOn === 'boolean' ? skill.globalOn : globalEnabled;
|
|
82
|
+
const enabled = rootEnabled && (typeof over === 'boolean' ? over : skillGlobal);
|
|
51
83
|
// 带标签的 `k: v` 串(2026-10-14 对抗性审查 P1-1):此前是无列头的 pipe 串,两个标记
|
|
52
84
|
// (`shadowed by <root>` / `preferred`)还会挤在同一格里、都没有标签 —— 模型得猜哪段
|
|
53
85
|
// 是字段、哪段是标记,以及 `preferred` 到底是什么(它此前**全仓没有定义**)。
|
|
54
86
|
// 与 `mcp_manager_list` 的 `server:` / `level:` / `user-hint:` 同款。
|
|
87
|
+
// 会话层:「本会话关掉 / 开启」必须与「全局停用 / 启用」分开说 —— 前者换个对话就回来了。
|
|
88
|
+
const state = root.intent === 'blocked'
|
|
89
|
+
? 'source-stopped-machine-wide (overrides every conversation; ' + (rootLeases > 0 ? rootLeases + ' conversation(s) still wanted it' : 'no conversation is using it') + ')'
|
|
90
|
+
: !rootEnabled
|
|
91
|
+
? 'source-off (the whole source folder is disabled' + (rootLeases > 0 ? '; kept running by ' + rootLeases + ' conversation(s)' : '') + ')'
|
|
92
|
+
: typeof over === 'boolean'
|
|
93
|
+
? (enabled ? 'enabled-in-this-conversation (global: ' + (globalEnabled ? 'enabled' : 'disabled') + ')'
|
|
94
|
+
: 'off-here (global: ' + (globalEnabled ? 'enabled' : 'disabled') + ')')
|
|
95
|
+
: (enabled ? 'enabled' : 'disabled');
|
|
55
96
|
rows.push({
|
|
56
97
|
root: String(root.key || ''),
|
|
57
98
|
enabled,
|
|
58
99
|
text: 'skill:' + (skill.name || skill.declaredName || '') + ' | root:' + (root.key || '') +
|
|
59
|
-
' | ' +
|
|
100
|
+
' | ' + state +
|
|
60
101
|
(skill.shadowedBy && skill.shadowedBy.root ? ' | shadowed-by:' + skill.shadowedBy.root : '') +
|
|
61
102
|
(skill.preferred === true ? ' | preferred' : '') +
|
|
62
103
|
(skill.path ? ' | path:' + skill.path : ''),
|
|
@@ -65,11 +106,19 @@ export function buildSkillTools(deps) {
|
|
|
65
106
|
}
|
|
66
107
|
const dupGroups = [...counts.values()].filter((n) => n > 1).length;
|
|
67
108
|
const shown = showAll ? rows : rows.filter((row) => row.enabled);
|
|
109
|
+
// 会话层(0.21.2):项目技能根按**本会话的 cwd** 推导,所以这份清单可能只是这个对话
|
|
110
|
+
// 看得到的那些。不说清的话,模型会拿它回答"本机装了哪些技能"。
|
|
111
|
+
const sessionNote = scoped === null
|
|
112
|
+
? ''
|
|
113
|
+
: ' (this scope\'s view: project roots come from its own cwd' +
|
|
114
|
+
(scoped.scope?.scene === undefined ? '' : ', scene "' + scoped.scope.scene + '"') +
|
|
115
|
+
(overrides === undefined ? '' : ', ' + Object.keys(overrides).length + ' switch(es) overridden here') + ')';
|
|
68
116
|
const header = 'Skills: ' + (showAll
|
|
69
117
|
? rows.length + ' entries'
|
|
70
118
|
: shown.length + ' enabled of ' + rows.length + ' entries') +
|
|
71
119
|
(dupGroups ? ' · ' + dupGroups + ' duplicated names' : '') +
|
|
72
|
-
(showAll || shown.length === rows.length ? '' : ' (pass all=true to include disabled and shadowed entries)') +
|
|
120
|
+
(showAll || shown.length === rows.length ? '' : ' (pass all=true to include disabled and shadowed entries)') +
|
|
121
|
+
sessionNote + '\n';
|
|
73
122
|
// 注入边界:预设没挂 dsh-tool-skill(如极简)时官方技能目录不在,本插件的
|
|
74
123
|
// 「技能目录」注入域会在开关打开时兜底(见上面的注入通道);两者都没有时模型看到的
|
|
75
124
|
// 只是这份名单 —— 说清边界,别让它以为上下文里已经有技能正文(正文用路径读)。
|
|
@@ -84,7 +133,7 @@ export function buildSkillTools(deps) {
|
|
|
84
133
|
// 已在上面标出胜出者),再走 `skill-detail` 读那一份 —— 读到的永远是目录列出来的那一份。
|
|
85
134
|
register(defineTool({
|
|
86
135
|
name: 'skill_manager_read',
|
|
87
|
-
description: 'Read one skill\'s full SKILL.md body by name
|
|
136
|
+
description: 'Read one skill\'s full SKILL.md body by name (the reminder has names and summaries only). Also lists the other files in that skill folder (references/, scripts/), which the body often points at. Resolves name collisions the same way, so you get the copy actually in effect; pass root only to inspect a specific (e.g. shadowed) source.',
|
|
88
137
|
parameters: {
|
|
89
138
|
name: { type: 'string', required: true, description: 'Skill name, exactly as it appears in the catalog (kebab-case).' },
|
|
90
139
|
root: { type: 'string', description: 'Source root key (dsh/hub/agents/codex/claude, a project key, or a custom one). Default: the winning copy of this name.' },
|
|
@@ -95,7 +144,11 @@ export function buildSkillTools(deps) {
|
|
|
95
144
|
if (!wanted)
|
|
96
145
|
throw new Error('name is required');
|
|
97
146
|
const rootWanted = String((args && args.root) || '').trim();
|
|
98
|
-
|
|
147
|
+
// 会话层(0.21.2):项目技能根按本会话的 cwd 推导 —— 与 skill_manager_list 同一份口径,
|
|
148
|
+
// 否则「列表里有、读不到」(两个对话的 cwd 不同时项目技能各有一份)。
|
|
149
|
+
const scoped = sessionScopeOf(deps, exec && exec.agent);
|
|
150
|
+
const overrides = scoped?.scope?.skills;
|
|
151
|
+
const state = await deps.skillsOps['skill-state'](scoped === null ? {} : { sessionId: scoped.sessionId });
|
|
99
152
|
if (!state || state.ok === false)
|
|
100
153
|
throw new Error((state && state.error) || 'skill-state failed');
|
|
101
154
|
const data = state.data || {};
|
|
@@ -115,9 +168,14 @@ export function buildSkillTools(deps) {
|
|
|
115
168
|
shadowedBy: skill.shadowedBy && skill.shadowedBy.root ? String(skill.shadowedBy.root) : '',
|
|
116
169
|
preferred: skill.preferred === true,
|
|
117
170
|
// 与 skill_manager_list 同一套启停推导(影子副本没有 enabled 字段)。
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
171
|
+
// 会话层(0.21.2):覆盖优先 —— 否则「列表里说关着、读出来说 enabled」两处打架。
|
|
172
|
+
enabled: (() => {
|
|
173
|
+
const g = skill.enabled !== undefined
|
|
174
|
+
? skill.enabled === true
|
|
175
|
+
: (skill.invocationPolicyValid && skill.modelInvocable && skill.userInvocable && skill.managerEnabled !== false);
|
|
176
|
+
const o = overrides?.[String(root.key || '') + '/' + String(skill.declaredName || skill.name || '')];
|
|
177
|
+
return typeof o === 'boolean' ? o : g;
|
|
178
|
+
})(),
|
|
121
179
|
});
|
|
122
180
|
}
|
|
123
181
|
}
|
|
@@ -145,6 +203,11 @@ export function buildSkillTools(deps) {
|
|
|
145
203
|
marks.push('preferred copy');
|
|
146
204
|
if (!picked.enabled)
|
|
147
205
|
marks.push('disabled');
|
|
206
|
+
// 会话层(0.21.2):本会话关掉的技能照样读得到正文(读 ≠ 生效),但必须说清 ——
|
|
207
|
+
// 不说的话模型会以为自己已经掌握了它、下一轮却看不到它。
|
|
208
|
+
const overHere = scoped?.scope?.skills?.[picked.rootKey + '/' + wanted];
|
|
209
|
+
if (overHere === false)
|
|
210
|
+
marks.push('switched off here only — the global setting is unchanged');
|
|
148
211
|
const dup = hits.filter((hit) => !hit.shadowedBy).length > 1
|
|
149
212
|
? hits.filter((hit) => !hit.shadowedBy).map((hit) => hit.rootKey).filter((k) => k !== picked.rootKey)
|
|
150
213
|
: [];
|
|
@@ -184,18 +247,32 @@ export function buildSkillTools(deps) {
|
|
|
184
247
|
// 会把"忘了给"静默当成"停用"。
|
|
185
248
|
enabled: { type: 'boolean', description: 'true to enable, false to disable. Required unless you only pass `prefer`.' },
|
|
186
249
|
source: { type: 'string', description: 'A source root key to switch as a whole (dsh/hub/agents/codex/claude or a project key).' },
|
|
187
|
-
root: { type: 'string', description: 'Source root
|
|
250
|
+
root: { type: 'string', description: 'Source root the skill lives in (with `name`). Default: whichever source holds it. Required with `prefer`.' },
|
|
188
251
|
// 同名首选来源(2026-10-15 注入文本审查)。此前这条工具的回执写着
|
|
189
252
|
// "or make this root the preferred copy **in the panel**" —— 明明一个布尔能解决,
|
|
190
253
|
// 却把用户推去界面点。而 `skill-prefer` / `skill-unprefer` 两个 op 早就在(面板在用)。
|
|
191
254
|
// 代价为零:本工具在出厂默认名单里就是关着的,加参数不进默认上下文。
|
|
192
|
-
prefer: { type: 'boolean', description: 'true = the copy in `root` wins this name\'s collision; false = drop the recorded choice. Needs `name`
|
|
255
|
+
prefer: { type: 'boolean', description: 'true = the copy in `root` wins this name\'s collision; false = drop the recorded choice. Needs `name` + explicit `root`; omit = leave it.' },
|
|
256
|
+
// 决策 10(2026-10-19):默认只改**这个对话**。写全局要显式说明。
|
|
257
|
+
// 0.21.2:`source` 也有会话版本了(拨开时来源按租约跑起来 —— 来源关着时技能级
|
|
258
|
+
// 开关会被 core 吞掉,所以那一步在回执里如实交代)。
|
|
259
|
+
scope: { type: 'string', enum: ['session', 'global'], description: scopeSessionDesc('turning a source or skill on may run that source as a lease, invisible outside that scope (isolation on only). global = every conversation (the state file).') },
|
|
193
260
|
},
|
|
194
261
|
output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
|
|
195
|
-
async execute(args) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
262
|
+
async execute(args, exec) {
|
|
263
|
+
if (args && args.enabled !== undefined && typeof args.enabled !== 'boolean') {
|
|
264
|
+
throw new Error('enabled must be true or false (omit it to only change the preferred copy)');
|
|
265
|
+
}
|
|
266
|
+
// 场景锁冻结的是**全局**写入(决策 11):本会话的逐条开关写的是侧车,与锁无关 ——
|
|
267
|
+
// 与面板的 `scopeWriteLocked()` 同一口径。只有真会改全局状态的那几条才过守卫。
|
|
268
|
+
// 全局粒度一律走全局:那一档没有会话层,写的就是状态文件 —— 所以要过场景锁。
|
|
269
|
+
const sessionWrite = Boolean(args && args.enabled !== undefined && effectiveScope(deps, args) === 'session' &&
|
|
270
|
+
!String(args.source || '').trim() && args.prefer === undefined);
|
|
271
|
+
if (!sessionWrite) {
|
|
272
|
+
const blocked = await deps.lockedSceneGuard();
|
|
273
|
+
if (blocked)
|
|
274
|
+
throw new Error(blocked);
|
|
275
|
+
}
|
|
199
276
|
const name = String((args && args.name) || '').trim();
|
|
200
277
|
const source = String((args && args.source) || '').trim();
|
|
201
278
|
// `prefer` 的三态与它自己的前置条件(2026-10-15):省略 = 不碰首选表;
|
|
@@ -213,6 +290,16 @@ export function buildSkillTools(deps) {
|
|
|
213
290
|
throw new Error('missing argument: name (one skill) or source (a whole source folder)');
|
|
214
291
|
if (preferGiven && !name)
|
|
215
292
|
throw new Error('missing argument: prefer needs name');
|
|
293
|
+
// 会话层(0.21.2):首选来源是**全局**的一张表,没有会话版本。`scope` 省略时默认是
|
|
294
|
+
// session(见参数说明),所以这里必须要求显式 `scope="global"` —— 否则一次「本会话
|
|
295
|
+
// 切个技能」会静默改掉全局的同名胜负。
|
|
296
|
+
const scopeArg = String((args && args.scope) || '');
|
|
297
|
+
// 全局粒度下 prefer 就是全局设置,不必再要一句显式的 scope="global"。
|
|
298
|
+
const isolationOff = !sessionLayerOn(deps);
|
|
299
|
+
if (preferGiven && !isolationOff && scopeArg !== 'global') {
|
|
300
|
+
throw new Error('prefer is a global setting (which copy wins a name collision is the same in every conversation), so it needs scope="global" explicitly. '
|
|
301
|
+
+ 'Drop prefer to switch only this scope, or pass scope="global" to change the global choice.');
|
|
302
|
+
}
|
|
216
303
|
if (preferGiven && String((args && args.root) || '').trim() === '') {
|
|
217
304
|
throw new Error('prefer needs root: name the copy that should win this collision (dsh / hub / agents / codex / claude or a project key)');
|
|
218
305
|
}
|
|
@@ -221,28 +308,72 @@ export function buildSkillTools(deps) {
|
|
|
221
308
|
throw new Error('missing argument: enabled must be true or false (pass prefer if you only want to change which copy wins the collision)');
|
|
222
309
|
}
|
|
223
310
|
if (source) {
|
|
311
|
+
if (args.root !== undefined)
|
|
312
|
+
throw new Error('source is already a source-level key; do not pass root with it');
|
|
313
|
+
// 会话层(0.21.2):来源这一格有会话版本了(`skillSources`)。拨开时 op 侧会把它
|
|
314
|
+
// 在**全局**启用(来源关着时技能级 enable 会被 core 吞掉);拨关只影响本会话的
|
|
315
|
+
// 「看不看得到」,别的对话与全局状态都不动。
|
|
316
|
+
if (effectiveScope(deps, args) === 'session') {
|
|
317
|
+
if (!deps.sessionScopeSet)
|
|
318
|
+
throw new Error('per-conversation switches are unavailable in this host: pass scope="global" to change it for every conversation');
|
|
319
|
+
const sc = await deps.sessionScopeSet(exec && exec.agent, 'skillSources', source, args.enabled === true);
|
|
320
|
+
if (!sc || sc.ok === false)
|
|
321
|
+
throw new Error((sc && sc.error) || 'failed to switch this source here');
|
|
322
|
+
const warnings = sc.warnings !== undefined && sc.warnings.length > 0 ? '\n' + sc.warnings.join('\n') : '';
|
|
323
|
+
return 'OK: source ' + source + ' now ' + (args.enabled ? 'enabled' : 'disabled') + scopeOnlyNote() +
|
|
324
|
+
(sc.cleared === true ? ' (that matches what this scope would see anyway, so the override was removed)' : '') + warnings +
|
|
325
|
+
(warnings === '' ? '\nThe global source switch is unchanged; other conversations keep theirs.' : '') +
|
|
326
|
+
' Pass scope="global" to change it for every conversation.';
|
|
327
|
+
}
|
|
328
|
+
// 全局来源开关 = **意图**(0.21.2):off 之后仍被会话认领的来源保持启用(租约),
|
|
329
|
+
// 只是别的会话看不到它下面的技能。直接改来源状态会让这次会话级开启串到所有会话 ——
|
|
330
|
+
// 与 MCP 那条是同一个修法。
|
|
331
|
+
if (deps.scopeIntentSet) {
|
|
332
|
+
const value = args.enabled === true ? 'on' : 'off';
|
|
333
|
+
const r = await deps.scopeIntentSet('skillSources', [source], value);
|
|
334
|
+
if (!r || r.ok === false)
|
|
335
|
+
throw new Error((r && r.error) || 'skill source toggle failed');
|
|
336
|
+
const syncErr = r.sceneSyncError ? String(r.sceneSyncError) : null;
|
|
337
|
+
const warnings = r.warnings !== undefined && r.warnings.length > 0 ? '\n' + r.warnings.join('\n') : '';
|
|
338
|
+
return 'OK: source ' + source + ' now ' + (value === 'on'
|
|
339
|
+
? 'enabled for every conversation'
|
|
340
|
+
: 'disabled globally (conversations still using it keep it enabled until none does)') + warnings +
|
|
341
|
+
(syncErr ? '\nWARN: the current scene archive was not synced (' + syncErr + ')' : '') +
|
|
342
|
+
'\nnote: a whole source folder is global (every conversation); omit scope to switch it here only.' + isolationOffNote(deps);
|
|
343
|
+
}
|
|
224
344
|
// 来源级启停:登记表里 `skill-source-enable` / `skill-source-disable` 都是
|
|
225
345
|
// `{ serviceWrite, frozen, syncsArchive }`,所以守卫已过、档案也要同步
|
|
226
346
|
// —— 同步的入参是 `{ root }`(来源级没有独立字段,档案靠"来源下有没有被勾的技能"反推)。
|
|
227
|
-
if (args.root !== undefined)
|
|
228
|
-
throw new Error('source is already a source-level key; do not pass root with it');
|
|
229
347
|
const op = args.enabled ? 'skill-source-enable' : 'skill-source-disable';
|
|
230
348
|
const r = await deps.skillsOps[op]({ root: source });
|
|
231
349
|
if (!r || r.ok === false)
|
|
232
350
|
throw new Error((r && r.error) || 'skill source toggle failed');
|
|
233
351
|
const syncErr = await deps.syncSwitchToScene(op, { root: source, enabled: args.enabled === true });
|
|
234
352
|
return 'OK: source ' + source + ' now ' + (args.enabled ? 'enabled' : 'disabled') +
|
|
235
|
-
(syncErr ? '\nWARN: the current scene archive was not synced (' + syncErr + ')' : '')
|
|
353
|
+
(syncErr ? '\nWARN: the current scene archive was not synced (' + syncErr + ')' : '') +
|
|
354
|
+
'\nnote: a whole source folder is global (every conversation); omit scope to switch it here only.' + isolationOffNote(deps);
|
|
236
355
|
}
|
|
237
356
|
// 不给 root 就在全部来源里找(2026-10-15 smoke-test P0-1):`skill_manager_save` 的落点
|
|
238
357
|
// 是 hub(`tool-management/skills/`),而这里的默认值原本是 dsh —— 「建完就启用」这条
|
|
239
358
|
// 最自然的链路必然报「技能不存在」。默认值改哪一边都不对(面板是显式传 root 的,
|
|
240
359
|
// 两边都依赖各自的默认),所以判定放到工具侧:按名字找**胜出的那一份**。
|
|
360
|
+
/** 会话覆盖键用的声明名(与目录名可以不同;0.21.2)。 */
|
|
361
|
+
let canonicalName = name;
|
|
241
362
|
const resolveRoot = async () => {
|
|
242
363
|
const explicit = String((args && args.root) || '').trim();
|
|
364
|
+
const found = await locateSkillRoot(deps.skillsOps, name);
|
|
365
|
+
// 声明名按**指定来源那一份**取;没指定就用胜出副本的。找不到就退回传入名,
|
|
366
|
+
// 由后面的全局 op 报"技能不存在"(会话写入不该在这里编一个结论)。
|
|
367
|
+
const match = explicit !== ''
|
|
368
|
+
? found.matches.filter((m) => m.root === explicit)[0]
|
|
369
|
+
: undefined;
|
|
370
|
+
// 指定来源时只认**那个来源**里的声明名;找不到就退回传入名(不能拿别的来源的同名
|
|
371
|
+
// 副本去拼键 —— 那会写出一条 root 与声明名对不上的覆盖)。
|
|
372
|
+
canonicalName = explicit !== ''
|
|
373
|
+
? (match && match.canonical) || name
|
|
374
|
+
: found.canonical || name;
|
|
243
375
|
if (explicit !== '')
|
|
244
376
|
return explicit;
|
|
245
|
-
const found = await locateSkillRoot(deps.skillsOps, name);
|
|
246
377
|
if (found.root)
|
|
247
378
|
return found.root;
|
|
248
379
|
// 探得到、就是没这个技能:当场把"查过哪些来源"说清楚。否则模型收到 op 那句不带
|
|
@@ -265,12 +396,35 @@ export function buildSkillTools(deps) {
|
|
|
265
396
|
throw new Error((p && p.error) || 'failed to set the collision winner');
|
|
266
397
|
// `skill-prefer` 会在"记下了但不会生效"时回 ok:true + warning(首选指向**停用**的来源,
|
|
267
398
|
// 而同名首选会挡住其他副本 → 两份都不生效)。原样转出去,否则模型以为已经生效。
|
|
399
|
+
// 首选来源是**全局**的一张表(同名胜负对所有对话都一样),会话层没有对应键 ——
|
|
400
|
+
// 与 enable 同一次调用时也要说清,否则"本会话切了个技能"会连带改掉全局的胜负。
|
|
268
401
|
out.push((prefer
|
|
269
402
|
? 'OK: ' + root + '/' + String(p.name || args.name) + ' is now the preferred copy of that name'
|
|
270
403
|
: 'OK: cleared the preferred copy of ' + String(p.name || args.name)) +
|
|
271
|
-
(p.warning ? '\nWARN: ' + String(p.warning) : '')
|
|
404
|
+
(p.warning ? '\nWARN: ' + String(p.warning) : '') +
|
|
405
|
+
'\nnote: which copy wins a name collision is a global setting (it has no per-conversation version).');
|
|
272
406
|
}
|
|
273
407
|
if (args.enabled !== undefined) {
|
|
408
|
+
// 决策 10(2026-10-19):默认写**本会话**(别的对话不受影响),`scope: "global"` 才改状态文件。
|
|
409
|
+
// 会话层只改"列不列"(决策:会话层不碰启停本身),所以它不需要冻结守卫与场景档案同步 ——
|
|
410
|
+
// 那两样保护的是全局状态。
|
|
411
|
+
if (effectiveScope(deps, args) === 'session') {
|
|
412
|
+
if (!deps.sessionScopeSet)
|
|
413
|
+
throw new Error('per-conversation switches are unavailable in this host: pass scope="global" to change it for every conversation');
|
|
414
|
+
// 键用**声明名**:目录名与 frontmatter 名字不同时,面板 / 注入段 / 模型列表都按
|
|
415
|
+
// 声明名读写;拿目录名写进去,覆盖永远读不到("点了没反应")。
|
|
416
|
+
const sc = await deps.sessionScopeSet(exec && exec.agent, 'skills', root + '/' + canonicalName, args.enabled === true);
|
|
417
|
+
if (!sc || sc.ok === false)
|
|
418
|
+
throw new Error((sc && sc.error) || 'failed to switch this skill here');
|
|
419
|
+
// 拨开时 op 侧可能顺手在全局把它的**来源**启用(来源关着时技能级开关会被 core 吞掉),
|
|
420
|
+
// 那一步的影响由 `warnings` 如实带出来;没动全局时才说"全局设置未变"。
|
|
421
|
+
const warnings = sc.warnings !== undefined && sc.warnings.length > 0 ? '\n' + sc.warnings.join('\n') : '';
|
|
422
|
+
out.push('OK: ' + args.name + ' now ' + (args.enabled ? 'enabled' : 'disabled') + scopeOnlyNote() +
|
|
423
|
+
(sc.cleared === true ? ' (that matches what this scope would see anyway, so the override was removed)' : '') + warnings +
|
|
424
|
+
(warnings === '' ? '\nThe global setting is unchanged; other conversations keep theirs.' : '') +
|
|
425
|
+
' Pass scope="global" to change it for every conversation.');
|
|
426
|
+
return out.join('\n');
|
|
427
|
+
}
|
|
274
428
|
const op = args.enabled ? 'skill-enable' : 'skill-disable';
|
|
275
429
|
const r = await deps.skillsOps[op]({ name: args.name, root });
|
|
276
430
|
if (!r || r.ok === false)
|
|
@@ -304,7 +458,7 @@ export function buildSkillTools(deps) {
|
|
|
304
458
|
? ' — BUT this copy is shadowed by the same-name skill in "' + shadowedBy + '", so it stays inactive: enable that copy instead, or make it win with prefer=true and root="' + shadowedBy + '"'
|
|
305
459
|
: '';
|
|
306
460
|
const sceneWarn = syncErr ? '\nWARN: the current scene archive was not synced (' + syncErr + ')' : '';
|
|
307
|
-
out.push('OK: ' + args.name + ' now ' + (args.enabled ? 'enabled' : 'disabled') + warn + sceneWarn);
|
|
461
|
+
out.push('OK: ' + args.name + ' now ' + (args.enabled ? 'enabled' : 'disabled') + warn + sceneWarn + isolationOffNote(deps));
|
|
308
462
|
}
|
|
309
463
|
return out.join('\n');
|
|
310
464
|
},
|
|
@@ -331,12 +485,16 @@ export function buildSkillTools(deps) {
|
|
|
331
485
|
name: { type: 'string', required: true, description: 'Skill name; normalized to kebab-case (≤128 chars, [a-z0-9-]).' },
|
|
332
486
|
description: { type: 'string', description: 'A concise routing description (≤500 chars). Required when creating; omit = keep.' },
|
|
333
487
|
body: { type: 'string', description: 'Markdown instructions (≤256 KiB). Required when creating; omit = keep.' },
|
|
488
|
+
// 0.21.2:技能 / 人设 / 场景 / MCP 服务器是**机器级**对象,没有「本会话的一份」。
|
|
489
|
+
// 这个参数只为一件事:模型以为自己在改会话时,当场纠回来(见 deps.ts 的 requireGlobalScope)。
|
|
490
|
+
scope: { type: 'string', enum: ['session', 'global'], description: scopeGlobalOnlyDesc('a skill file is machine-wide', 'switch it here instead of editing it') },
|
|
334
491
|
},
|
|
335
492
|
output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
|
|
336
|
-
async execute(args) {
|
|
493
|
+
async execute(args, exec) {
|
|
337
494
|
const blocked = await deps.lockedSceneGuard();
|
|
338
495
|
if (blocked)
|
|
339
496
|
throw new Error(blocked);
|
|
497
|
+
requireGlobalScope(args, 'skills', !sessionLayerOn(deps));
|
|
340
498
|
const wanted = String((args && args.name) || '').trim();
|
|
341
499
|
if (!wanted)
|
|
342
500
|
throw new Error('missing argument: name');
|
|
@@ -379,7 +537,9 @@ export function buildSkillTools(deps) {
|
|
|
379
537
|
const enableHint = deps.toolVisible('skill_manager_switch')
|
|
380
538
|
? ' (created disabled; use skill_manager_switch to enable it)'
|
|
381
539
|
: ' (created disabled; the user has to enable it first)';
|
|
382
|
-
|
|
540
|
+
// 会话层(0.21.2):技能文件是**机器级**的,本会话的开关只决定这里看不看得到它。
|
|
541
|
+
return 'Created DSH skill ' + (data.name || kebab) + ' at ' + (data.path || '(unknown)') + enableHint +
|
|
542
|
+
globalActionNote(deps, exec && exec.agent, 'skills', 'skill');
|
|
383
543
|
}
|
|
384
544
|
// 改的分支:省略 = 保持。两个可改字段一个都没给就拒 —— op 会按"保持原样"重写一次文件
|
|
385
545
|
// 并刷新时间戳,模型以为改了点什么,其实只是把同一份内容又写了一遍。
|
|
@@ -394,7 +554,8 @@ export function buildSkillTools(deps) {
|
|
|
394
554
|
if (!r || r.ok === false)
|
|
395
555
|
throw new Error((r && r.error) || 'skill update failed');
|
|
396
556
|
const data = r.data || {};
|
|
397
|
-
return 'Updated DSH skill ' + (data.name || kebab) + ' at ' + (data.path || '(unknown)') + ' (changed ' + touched.join(', ') + ')'
|
|
557
|
+
return 'Updated DSH skill ' + (data.name || kebab) + ' at ' + (data.path || '(unknown)') + ' (changed ' + touched.join(', ') + ')' +
|
|
558
|
+
globalActionNote(deps, exec && exec.agent, 'skills', 'skill');
|
|
398
559
|
},
|
|
399
560
|
}));
|
|
400
561
|
}
|
package/lib/tools/subagent.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// 两个工具**各自** try/catch:一个注册失败不该把另一个也带走,而且失败必须说得出
|
|
7
7
|
// 「是哪一个没注册上」——只打一行日志时,模型侧只会「查无此工具」、界面毫无痕迹。
|
|
8
8
|
import { defineSubagentManagerListTool, defineSubagentManagerRunTool } from '../subagents/tools.js';
|
|
9
|
-
import { text } from './deps.js';
|
|
9
|
+
import { effectiveScope, globalActionNote, isolationOffNote, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, text } from './deps.js';
|
|
10
10
|
/**
|
|
11
11
|
* 高频高级字段:`subagent_manager_save` 与 op 之间原样透传的那几个(省略 = 不出现 = op 侧保持)。
|
|
12
12
|
*
|
|
@@ -42,6 +42,8 @@ export function buildSubagentTools(deps) {
|
|
|
42
42
|
sceneLists: deps.sceneLists,
|
|
43
43
|
// 与其余发现型工具同口径:压制型预设下不注入时,人设目录不在模型上下文里,
|
|
44
44
|
// 只有工具可用。挂上边界提示,模型才不会把「看不到人设」当成「没有人设」。
|
|
45
|
+
flagFor: deps.subagentFlagFor,
|
|
46
|
+
overridesFor: deps.subagentOverridesFor,
|
|
45
47
|
noticeFor: (exec) => deps.reachNoticeForAgent(deps.presetRoster(), exec && exec.agent && exec.agent.ctx, deps.injectNoticeOptions()),
|
|
46
48
|
})));
|
|
47
49
|
}
|
|
@@ -59,7 +61,7 @@ export function buildSubagentTools(deps) {
|
|
|
59
61
|
// 谈不上委派;0.19.0 测「允许追问」时才被暴露出来,因为那条通道同样要过这一步)。
|
|
60
62
|
// `Object.create` 保持同一条原型链:`ops` 仍是审计过的那份,`list` / `runSerial` 回真实服务。
|
|
61
63
|
// 与 index.ts 造这个包装层时用的是同一个写法(那边注释写的是「原型链回真实服务,其余读法一字不动」)。
|
|
62
|
-
register(defineTool(defineSubagentManagerRunTool(Object.assign(Object.create(deps.subagentService), { sceneLists: deps.sceneLists, toolFilterFor: deps.toolFilterFor }))));
|
|
64
|
+
register(defineTool(defineSubagentManagerRunTool(Object.assign(Object.create(deps.subagentService), { sceneLists: deps.sceneLists, toolFilterFor: deps.toolFilterFor, flagFor: deps.subagentFlagFor }))));
|
|
63
65
|
}
|
|
64
66
|
catch (e) {
|
|
65
67
|
recordFailure('subagent_manager_run', e);
|
|
@@ -81,14 +83,37 @@ export function buildSubagentTools(deps) {
|
|
|
81
83
|
description: 'Enable or disable one persona. Only enabled personas appear in the "Current subagents" catalog and can be given work. Reversible. Only when the user asks or approves.',
|
|
82
84
|
parameters: {
|
|
83
85
|
name: { type: 'string', required: true, description: 'Persona name.' },
|
|
84
|
-
enabled: { type: 'boolean', required: true, description: 'true = enable, false = disable
|
|
86
|
+
enabled: { type: 'boolean', required: true, description: 'true = enable, false = disable.' },
|
|
87
|
+
// 决策 10(2026-10-19):默认只改**这个对话**。写全局要显式说明。
|
|
88
|
+
scope: { type: 'string', enum: ['session', 'global'], description: scopeSessionDesc('global = every conversation (the persona state file).') },
|
|
85
89
|
},
|
|
86
90
|
output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
|
|
87
|
-
async execute(args) {
|
|
88
|
-
const blocked = await deps.lockedSceneGuard();
|
|
89
|
-
if (blocked)
|
|
90
|
-
throw new Error(blocked);
|
|
91
|
+
async execute(args, exec) {
|
|
91
92
|
const name = String((args && args.name) || '').trim();
|
|
93
|
+
// 省略 `enabled` 时不能静默当成 false —— 默认写的是**本会话**,一次猜错就是
|
|
94
|
+
// 这个对话里的人设凭空消失(全局那条倒是没动,更难查)。
|
|
95
|
+
if (typeof (args && args.enabled) !== 'boolean')
|
|
96
|
+
throw new Error('missing argument: enabled must be true or false');
|
|
97
|
+
// 场景锁冻结的是**全局**写入(决策 11):会话覆盖写侧车,与锁无关。
|
|
98
|
+
// 全局粒度下一律走全局:那一档没有会话层,写的就是状态文件。
|
|
99
|
+
const sessionOnly = effectiveScope(deps, args) === 'session';
|
|
100
|
+
if (!sessionOnly) {
|
|
101
|
+
const blocked = await deps.lockedSceneGuard();
|
|
102
|
+
if (blocked)
|
|
103
|
+
throw new Error(blocked);
|
|
104
|
+
}
|
|
105
|
+
// 决策 10:默认写**本会话**(别的对话不受影响),`scope: "global"` 才改状态文件。
|
|
106
|
+
// 会话层只改"列不列、调不调得动",不碰启停本身 —— 所以不需要场景档案同步。
|
|
107
|
+
if (sessionOnly) {
|
|
108
|
+
if (!deps.sessionScopeSet)
|
|
109
|
+
throw new Error('per-conversation switches are unavailable in this host: pass scope="global" to change it for every conversation');
|
|
110
|
+
const sc = await deps.sessionScopeSet(exec && exec.agent, 'subagents', name, args.enabled === true);
|
|
111
|
+
if (!sc || sc.ok === false)
|
|
112
|
+
throw new Error((sc && sc.error) || 'failed to switch this persona here');
|
|
113
|
+
return 'OK: persona ' + name + ' ' + (args.enabled === true ? 'enabled' : 'disabled') + scopeOnlyNote() +
|
|
114
|
+
(sc.cleared === true ? ' (that matches the global setting, so the per-conversation override was removed)' : '') +
|
|
115
|
+
'. The global setting is unchanged; other conversations keep theirs. Pass scope="global" to change it for every conversation.';
|
|
116
|
+
}
|
|
92
117
|
const r = await ops()['subagent-toggle']({ name, enabled: args.enabled === true });
|
|
93
118
|
if (!r || r.ok === false)
|
|
94
119
|
throw new Error((r && r.error) || 'failed to toggle the persona');
|
|
@@ -96,7 +121,7 @@ export function buildSubagentTools(deps) {
|
|
|
96
121
|
// 直接调 service op,绕过了那一层包装,所以这里自己叫一声)。
|
|
97
122
|
const syncErr = await deps.syncSwitchToScene('subagent-toggle', { name, enabled: args.enabled === true });
|
|
98
123
|
return 'OK: persona ' + name + ' ' + (args.enabled === true ? 'enabled' : 'disabled') +
|
|
99
|
-
(syncErr ? '\nWARN: the current scene archive was not synced (' + syncErr + ')' : '');
|
|
124
|
+
(syncErr ? '\nWARN: the current scene archive was not synced (' + syncErr + ')' : '') + isolationOffNote(deps);
|
|
100
125
|
},
|
|
101
126
|
}));
|
|
102
127
|
}
|
|
@@ -117,23 +142,27 @@ export function buildSubagentTools(deps) {
|
|
|
117
142
|
// 落点路径(`at ~/.dsh/tool-management/subagents/<name>.md`)删掉(2026-10-15 注入文本
|
|
118
143
|
// 审查):模型不按路径行动,这条工具也没有"给我路径"的用法(要读正文有 `list` +
|
|
119
144
|
// 宿主的文件工具,而人设正文本来就是给它自己当系统提示词用的)。
|
|
120
|
-
description: 'Create a persona, or update the one
|
|
145
|
+
description: 'Create a persona, or update the one with this name — the receipt says which; omitted fields keep their values. Write `body` as who this is and how it judges its own work, not steps or paths (those belong to the task); put hard output requirements in `output`, one per line. Also settable: `model` (\'\' = inherit), `continuable`, `tools`/`toolsDeny` ([] = clear) — other routing/limit fields aren\'t. Blocked while the active scene is locked. Only on the user\'s instruction.',
|
|
121
146
|
parameters: {
|
|
122
147
|
name: { type: 'string', required: true, description: 'Persona name (= file name); ≤64 chars, one path segment — no / \\ or < > : " | ? *, no leading dot, no reserved device name, no trailing dot or space.' },
|
|
123
|
-
description: { type: 'string', description: 'One-line routing description
|
|
124
|
-
body: { type: 'string', description: 'Markdown role definition. Required when creating
|
|
125
|
-
output: { type: 'string', description: 'Output contract, one requirement per line. Empty string clears it
|
|
126
|
-
nextName: { type: 'string', description: 'New name (rename); re-points scene
|
|
127
|
-
model: { type: 'string', description: "Model id for this persona's runs. '' = inherit the main session's model
|
|
128
|
-
continuable: { type: 'boolean', description: 'true = this persona may be followed up (runs in the background and returns an agent id); false = one-shot.
|
|
129
|
-
tools: { type: 'array', items: { type: 'string' }, description: 'Tool allowlist — the subagent keeps only these tools. [] = clear
|
|
130
|
-
toolsDeny: { type: 'array', items: { type: 'string' }, description: 'Tool denylist — removed from the subagent; wins over the allowlist. [] = clear
|
|
148
|
+
description: { type: 'string', description: 'One-line routing description (what the delegation catalog shows). Required when creating.' },
|
|
149
|
+
body: { type: 'string', description: 'Markdown role definition. Required when creating.' },
|
|
150
|
+
output: { type: 'string', description: 'Output contract, one requirement per line. Empty string clears it.' },
|
|
151
|
+
nextName: { type: 'string', description: 'New name (rename); re-points scene bindings. Refused if the name is taken.' },
|
|
152
|
+
model: { type: 'string', description: "Model id for this persona's runs. '' = inherit the main session's model." },
|
|
153
|
+
continuable: { type: 'boolean', description: 'true = this persona may be followed up (runs in the background and returns an agent id); false = one-shot.' },
|
|
154
|
+
tools: { type: 'array', items: { type: 'string' }, description: 'Tool allowlist — the subagent keeps only these tools. [] = clear.' },
|
|
155
|
+
toolsDeny: { type: 'array', items: { type: 'string' }, description: 'Tool denylist — removed from the subagent; wins over the allowlist. [] = clear.' },
|
|
156
|
+
// 0.21.2:人设是**机器级**文件,没有「本会话的一份」。这个参数只为一件事:
|
|
157
|
+
// 模型以为自己在改会话时,当场纠回来(见 deps.ts 的 requireGlobalScope)。
|
|
158
|
+
scope: { type: 'string', enum: ['session', 'global'], description: scopeGlobalOnlyDesc('a persona file is machine-wide', 'switch it here instead of editing it') },
|
|
131
159
|
},
|
|
132
160
|
output: { schema: { type: 'string' }, render: (_a, v) => text(String(v)) },
|
|
133
|
-
async execute(args) {
|
|
161
|
+
async execute(args, exec) {
|
|
134
162
|
const blocked = await deps.lockedSceneGuard();
|
|
135
163
|
if (blocked)
|
|
136
164
|
throw new Error(blocked);
|
|
165
|
+
requireGlobalScope(args, 'personas', !sessionLayerOn(deps));
|
|
137
166
|
const name = String((args && args.name) || '').trim();
|
|
138
167
|
// 高级字段的形状校验:填错会在 op 侧**静默**(`serializePersona` 对非数组 `tools`
|
|
139
168
|
// 是"当空处理",等于把用户原有的名单清掉)。在这里先挡一句。
|
|
@@ -167,7 +196,9 @@ export function buildSubagentTools(deps) {
|
|
|
167
196
|
const enableHint = deps.toolVisible('subagent_manager_switch')
|
|
168
197
|
? ' (created disabled; use subagent_manager_switch to enable it before delegating)'
|
|
169
198
|
: ' (created disabled; the user has to enable it before you can delegate)';
|
|
170
|
-
|
|
199
|
+
// 会话层(0.21.2):人设文件是**机器级**的,本会话的开关只决定这里看不看得到它。
|
|
200
|
+
return 'OK: persona ' + String(r.name || name) + ' created' + enableHint +
|
|
201
|
+
globalActionNote(deps, exec && exec.agent, 'subagents', 'persona');
|
|
171
202
|
}
|
|
172
203
|
const keep = current.persona || {};
|
|
173
204
|
// 省略 = 保持(读回现值),给了 = 覆盖。高级字段走同一套 —— 不在工具侧合并,
|
|
@@ -202,7 +233,8 @@ export function buildSubagentTools(deps) {
|
|
|
202
233
|
if (!r || r.ok === false)
|
|
203
234
|
throw new Error((r && r.error) || 'failed to update the persona');
|
|
204
235
|
return 'OK: persona ' + String(r.name || name) + ' updated (changed ' + touched.join(', ') + ')' +
|
|
205
|
-
(r.renamedFrom ? ' — was named "' + r.renamedFrom + '"; the scene-archive binding was renamed too' : '')
|
|
236
|
+
(r.renamedFrom ? ' — was named "' + r.renamedFrom + '"; the scene-archive binding was renamed too' : '') +
|
|
237
|
+
globalActionNote(deps, exec && exec.agent, 'subagents', 'persona');
|
|
206
238
|
},
|
|
207
239
|
}));
|
|
208
240
|
}
|