dsh-plugin-tool-management 0.21.2 → 0.21.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/CHANGELOG.md +62 -1
- package/README.md +3 -5
- package/README_EN.md +3 -3
- package/docs/{update.md → UPDATE.md} +35 -33
- package/lib/approval-policy.js +2 -2
- package/lib/audit-log.js +1 -1
- package/lib/boot/reconcile.js +3 -3
- package/lib/client.js +469 -171
- package/lib/compat/capability-specs.js +13 -17
- package/lib/compat/host-contracts.js +2 -0
- package/lib/compat/host-probe.js +35 -38
- package/lib/compat/host-roots.js +86 -15
- package/lib/compat/preset-reach.js +75 -102
- package/lib/compat/probe.js +68 -117
- package/lib/compat/runtime-notes.js +1 -1
- package/lib/context-inject-contract.js +6 -5
- package/lib/context-inject-frame.js +113 -53
- package/lib/context-inject-select.js +13 -14
- package/lib/context-inject-surface.js +5 -3
- package/lib/context-inject.js +58 -44
- package/lib/desktop-cookie-prune.js +95 -0
- package/lib/diagnostics.js +3 -1
- package/lib/exports/transcript.js +4 -4
- package/lib/host-names.js +6 -6
- package/lib/http-api.js +35 -26
- package/lib/http-fence.js +6 -6
- package/lib/hub.js +12 -13
- package/lib/imports/parsers.js +25 -21
- package/lib/imports/upload.js +5 -1
- package/lib/index.js +274 -243
- package/lib/mcp/disabled-tools.js +1 -0
- package/lib/mcp/loader-token.js +4 -4
- package/lib/mcp/manager.js +93 -114
- package/lib/mcp/override-blocks.js +1 -1
- package/lib/mcp/patch-yaml.js +42 -31
- package/lib/mcp/restart-marker.js +1 -1
- package/lib/mcp/secret-guard.js +6 -6
- package/lib/mcp/state-section.js +110 -69
- package/lib/mcp/tool-visibility.js +21 -22
- package/lib/memories/archive-engine.js +29 -29
- package/lib/memories/archive.js +23 -3
- package/lib/memories/constants.js +40 -127
- package/lib/memories/discovery.js +11 -2
- package/lib/memories/index-io.js +26 -20
- package/lib/memories/projection.js +18 -19
- package/lib/memories/prompt-layer.js +3 -2
- package/lib/memories/service.js +41 -38
- package/lib/memories/snapshot.js +37 -29
- package/lib/op-registry.js +38 -18
- package/lib/ops/candidates.js +3 -2
- package/lib/ops/compat.js +10 -9
- package/lib/ops/ctx.js +1 -1
- package/lib/ops/memory.js +18 -18
- package/lib/ops/prompts.js +8 -8
- package/lib/ops/quick-prompts.js +1 -0
- package/lib/ops/scene-records.js +23 -24
- package/lib/ops/scene-sync.js +8 -7
- package/lib/ops/scope.js +144 -40
- package/lib/ops/sessions.js +10 -9
- package/lib/ops/snapshot.js +10 -9
- package/lib/ops/state-doctor.js +6 -6
- package/lib/ops/trash-retention.js +2 -1
- package/lib/ops/trash.js +6 -6
- package/lib/prompts/preset-id.js +1 -1
- package/lib/prompts/project-instructions.js +3 -3
- package/lib/prompts/quick-service.js +1 -0
- package/lib/prompts/service.js +13 -12
- package/lib/request-gate.js +26 -25
- package/lib/scene-linkage.js +6 -5
- package/lib/scene-prompt-sync.js +10 -9
- package/lib/scene-settings.js +1 -0
- package/lib/scenes/candidates.js +9 -10
- package/lib/scope/intent-store.js +1 -0
- package/lib/scope/intent.js +16 -15
- package/lib/scope/resolve.js +6 -6
- package/lib/scope/scope-overrides.js +17 -17
- package/lib/scope/store.js +1 -0
- package/lib/sessions/archive-schemas.js +9 -0
- package/lib/sessions/bridge.js +42 -56
- package/lib/sessions/history.js +6 -7
- package/lib/sessions/workspace.js +21 -23
- package/lib/settings-sidecars.js +1 -0
- package/lib/sidebar-settings.js +1 -0
- package/lib/skills/catalog.js +9 -10
- package/lib/skills/core-util.js +5 -0
- package/lib/skills/core.js +35 -22
- package/lib/skills/frontmatter.js +26 -14
- package/lib/skills/homes.js +2 -0
- package/lib/skills/import-pipeline.js +8 -1
- package/lib/skills/manager-state.js +30 -6
- package/lib/skills/official.js +14 -11
- package/lib/skills/readonly-discovery.js +1 -0
- package/lib/skills/service.js +19 -18
- package/lib/skills/skill-roots.js +25 -7
- package/lib/skills/skill-trash.js +14 -3
- package/lib/skills/system-trash.js +3 -1
- package/lib/skills/upload-pipeline.js +19 -3
- package/lib/slash-settings.js +1 -0
- package/lib/stale-write.js +9 -1
- package/lib/subagents/catalog.js +5 -5
- package/lib/subagents/child-preset.js +7 -10
- package/lib/subagents/persona-parse.js +9 -8
- package/lib/subagents/persona-write.js +1 -1
- package/lib/subagents/run-provider.js +13 -15
- package/lib/subagents/service.js +13 -12
- package/lib/subagents/tool-filter.js +1 -1
- package/lib/subagents/tools.js +41 -39
- package/lib/token-config.js +9 -9
- package/lib/tool-table-switch.js +3 -2
- package/lib/tools/deps.js +33 -13
- package/lib/tools/mcp.js +63 -36
- package/lib/tools/memory.js +51 -36
- package/lib/tools/prompt.js +32 -20
- package/lib/tools/remove.js +12 -11
- package/lib/tools/scene.js +39 -36
- package/lib/tools/skills.js +44 -45
- package/lib/tools/subagent.js +21 -22
- package/lib/tools/table.js +21 -20
- package/lib/trash-id.js +3 -2
- package/lib/trash-retention.js +4 -5
- package/lib/update-check.js +5 -1
- package/package.json +4 -3
package/lib/tools/prompt.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
// AGENTS.md 预设域的 model
|
|
1
|
+
// AGENTS.md 预设域的 model 工具(从 index.ts 的注册区抽出):
|
|
2
2
|
// prompt_manager_list / prompt_manager_apply。
|
|
3
3
|
//
|
|
4
4
|
// 模型可查、可切;**不能造** —— 预设正文是用户自己写的一份长文(`AGENTS.md`),
|
|
5
5
|
// 模型没有创建入口,要新建只能由用户在面板里写。
|
|
6
6
|
//
|
|
7
|
-
// 删除在 `tools/remove.ts` 的 `prompt_manager_remove
|
|
7
|
+
// 删除在 `tools/remove.ts` 的 `prompt_manager_remove`(加)。此前这里写的是
|
|
8
8
|
// 「不能造 / **不能删** —— 避免模型乱删用户预设」,那条理由针对的是**不可恢复**的删除:
|
|
9
9
|
// 预设正文是用户手写的、删了就得重写。回收站把它的前提消掉了 —— 五条 `*_manager_remove`
|
|
10
10
|
// 一律「进回收站、可恢复、需用户指令、过场景冻结守卫」,永久删除仍只留在面板。
|
|
@@ -13,12 +13,13 @@ import { join } from 'node:path';
|
|
|
13
13
|
import { normalizePresetDescription } from '../prompts/service.js';
|
|
14
14
|
import { hasPromptOverride } from '../scope/scope-overrides.js';
|
|
15
15
|
import { sessionScopeOf, text } from './deps.js';
|
|
16
|
+
/** 注册提示词域的 model 工具(列表 / 读取 / 应用)。 */
|
|
16
17
|
export function buildPromptTools(deps) {
|
|
17
18
|
const { defineTool, register } = deps;
|
|
18
19
|
register(defineTool({
|
|
19
20
|
name: 'prompt_manager_list',
|
|
20
21
|
// 那句 `(that reminder is absent when the preset carries the official instructions line)`
|
|
21
|
-
//
|
|
22
|
+
// 删掉:模型**观测不到**"official instructions line"这个条件
|
|
22
23
|
// 拿它做不了任何决定 —— reminder 在不在,它抬头就能看见,不必由描述来预告。
|
|
23
24
|
description: 'List AGENTS.md presets (id, description, active state, file path); read that file for a body. The one in effect is in the "Current prompt" reminder. Defaults to the one in effect; all=true for the whole library.',
|
|
24
25
|
parameters: {
|
|
@@ -31,7 +32,7 @@ export function buildPromptTools(deps) {
|
|
|
31
32
|
if (!r || r.ok === false)
|
|
32
33
|
throw new Error((r && r.error) || 'failed to read the AGENTS.md presets');
|
|
33
34
|
const all = r.presets || [];
|
|
34
|
-
// 默认只列「这份 AGENTS.md
|
|
35
|
+
// 默认只列「这份 AGENTS.md 来自哪个预设」。
|
|
35
36
|
// 判定分两级:`active`(场景驱动时 = 场景绑的那份;否则 = 内容逐字节相同)优先,
|
|
36
37
|
// 否则看服务层记下的「最近一次应用」—— 用户手改过全局文件时,第二级仍能给出答案,
|
|
37
38
|
// 不必退化成全列(那会白烧上下文)。
|
|
@@ -41,11 +42,11 @@ export function buildPromptTools(deps) {
|
|
|
41
42
|
// 三列各有用途:
|
|
42
43
|
// · 路径 —— 「名单 → 全文」的闭环。预设正文既不进提示词、也没有读取工具,给出文件
|
|
43
44
|
// 路径让模型用宿主的文件工具读,比再造一个 read 工具省一条常驻 schema。
|
|
44
|
-
// · 描述 ——
|
|
45
|
+
// · 描述 —— 模型要能在预设之间做选择,而 id 本身不说明用途。描述在
|
|
45
46
|
// 这里按 `DEFAULT_PRESET_DESC_MAX_LENGTH` 压行截断(与 MCP 备注同一条口径),
|
|
46
47
|
// 因为它从这一版起是**常驻成本**而不是"只给使用者看"。
|
|
47
48
|
// · mark —— `activeVia` 必须打出来:`fileApplied` 但场景绑着别的,说明文件里那份
|
|
48
|
-
//
|
|
49
|
+
// 已经**不生效**了。原先这里会错报成 [active](那正是被修掉的那句假话)。
|
|
49
50
|
const summary = shown.map((p) => {
|
|
50
51
|
const mark = p.active
|
|
51
52
|
? (p.activeVia === 'scene' ? ' [active via scene]' : ' [active via file]')
|
|
@@ -55,7 +56,7 @@ export function buildPromptTools(deps) {
|
|
|
55
56
|
const desc = normalizePresetDescription(p.description);
|
|
56
57
|
return p.id + mark + ' | ' + (desc || '(no description)') + ' | ' + join(deps.promptsDir, p.id, 'AGENTS.md');
|
|
57
58
|
});
|
|
58
|
-
//
|
|
59
|
+
// 会话层:提示词**不进**会话域 —— 预设写的是全局基线 ~/.dsh/AGENTS.md,
|
|
59
60
|
// 宿主每轮只读一份。会话能改的是生效场景,而场景绑哪个预设是场景自己的事。
|
|
60
61
|
// 这句只在模型真会读错时才值钱:它会拿这份清单回答「本会话现在用哪份提示词」,
|
|
61
62
|
// 而本会话钉住场景时,答案来自那个场景的绑定,不是这份 active 标记。
|
|
@@ -79,7 +80,7 @@ export function buildPromptTools(deps) {
|
|
|
79
80
|
name: 'prompt_manager_apply',
|
|
80
81
|
description: 'Apply one AGENTS.md preset by id; effective next turn. When a scene drives the baseline this does not refuse — it rebinds that scene, so tell the user which one. A locked scene blocks the call. apply=false cancels instead: AGENTS.md goes back to what it was before this run of applies (removed if there was none), which a scene-driven baseline refuses — rebind the scene instead. Only on the user\'s instruction.',
|
|
81
82
|
parameters: {
|
|
82
|
-
// `id` 从 required
|
|
83
|
+
// `id` 从 required 摘掉:描述一直写着 "Ignored when
|
|
83
84
|
// apply=false",schema 却把它标成必填 —— 模型照描述「取消不用给 id」操作,先被 schema
|
|
84
85
|
// 拒掉(missing required property "id"),只能编一个 dummy id 才过得去。条件必填由
|
|
85
86
|
// execute 里那句守卫表达,与 `skill_manager_switch` 的 enabled / prefer 同一形状。
|
|
@@ -91,11 +92,11 @@ export function buildPromptTools(deps) {
|
|
|
91
92
|
const blocked = await deps.lockedSceneGuard();
|
|
92
93
|
if (blocked)
|
|
93
94
|
throw new Error(blocked);
|
|
94
|
-
//
|
|
95
|
+
// 会话层:提示词永远全局。本会话钉了场景时,这里改的是**那个场景**
|
|
95
96
|
// 的绑定(`applyPresetGuarded` 的 viaScene 分支)—— 别的对话只要没钉同一个场景就不受影响,
|
|
96
97
|
// 但这不是「本会话的提示词」,回执必须按那条路说清。
|
|
97
|
-
//
|
|
98
|
-
// `requireGlobalScope`
|
|
98
|
+
// 提示词**不进**会话域,所以这里没有 scope 参数,也**不做**
|
|
99
|
+
// `requireGlobalScope` 守卫:守卫读 `args.scope`,而参数表里
|
|
99
100
|
// 没有这个字段 —— 模型按 schema 不可能传它,守卫只在「模型自己编了一个未声明参数」时
|
|
100
101
|
// 才触发,等于靠运气。留着这行还让 deps.ts 的清单以为这条被守住了。
|
|
101
102
|
// 提示词确实只有全局一层,参数表已经把这件事说完了。
|
|
@@ -104,7 +105,7 @@ export function buildPromptTools(deps) {
|
|
|
104
105
|
if (args.apply === false) {
|
|
105
106
|
// 取消方向:`agentsmd-unapply` 自带两条护栏(场景驱动时拒绝、没有链起点时给确定
|
|
106
107
|
// 错误码),原样透传。回执要说清恢复成哪种 —— 起点没有文件时是**删文件**,
|
|
107
|
-
// 不说的话用户以为 AGENTS.md
|
|
108
|
+
// 不说的话用户以为 AGENTS.md 还在(界面弹窗报的就是这两种)。
|
|
108
109
|
const r = await deps.unapplyPreset();
|
|
109
110
|
if (!r.ok)
|
|
110
111
|
throw new Error(r.error || 'failed to cancel the application');
|
|
@@ -122,18 +123,29 @@ export function buildPromptTools(deps) {
|
|
|
122
123
|
// 场景驱动时写的是「场景绑定」,回执必须说清改的是哪个场景 —— 只说「已应用到
|
|
123
124
|
// AGENTS.md」会让模型对用户谎报(用户不知道自己的场景绑定被换掉了)。
|
|
124
125
|
if (r.viaScene) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
126
|
+
// `scene` 是场景名(`scene_manager_*` 认的那个),`label` 是界面显示名 ——
|
|
127
|
+
// 只报 label 时模型会把「全局」当场景名转述,而那个名字其实是 `global`。
|
|
128
|
+
const target = String(r.scene || '');
|
|
129
|
+
const shown = target + (r.label && String(r.label) !== target ? ' (' + String(r.label) + ')' : '');
|
|
130
|
+
// 会话层两种情形必须分开说:`applyPresetGuarded` 走的是**全局** driver,
|
|
131
|
+
// 永远只改机器级那个场景的绑定,而本作用域可能钉着**另一个**场景。
|
|
132
|
+
// 只报「绑定换成了 X」时,agent 会把它转述成「这个对话的提示词换了」——
|
|
133
|
+
// 而这里一个字都没变(原先那句只在两个名字相同时才出,恰好是最不需要它的情形)。
|
|
134
|
+
const scopeNote = pinned === undefined
|
|
135
|
+
? ''
|
|
136
|
+
: pinned === target
|
|
137
|
+
? '\nnote: that is the scene pinned here, so this scope follows it.'
|
|
138
|
+
: '\nnote: this scope pins scene "' + pinned + '", so what it gets here is unchanged — this call rebound the machine-wide scene "' + shown + '". '
|
|
139
|
+
+ (deps.toolVisibleFor('scene_manager_save', exec && exec.agent)
|
|
140
|
+
? 'To change the binding that applies here, save scene "' + pinned + '" with that preset (scene_manager_save).'
|
|
141
|
+
: 'To change the binding that applies here, the user has to rebind scene "' + pinned + '" in the panel.');
|
|
142
|
+
return 'OK: preset ' + id + ' is now the prompt binding of scene "' + shown + '" and the scene was re-synced (effective next turn; ~/.dsh/AGENTS.md now carries that scene\'s binding).' + scopeNote;
|
|
131
143
|
}
|
|
132
144
|
// 生效时机与宿主行为对齐(index.ts 提示词服务一节考证过):dsh-agent-instructions
|
|
133
145
|
// 每个 pre-step 都 stat 比对版本,写文件即下一轮重读 —— 不是"下个会话"。说错了
|
|
134
146
|
// 模型会劝用户重开会话,而其实下一句话就已经在新基线下跑。
|
|
135
147
|
return 'OK: preset ' + id + ' applied to ~/.dsh/AGENTS.md — effective next turn' + (r.backedUp ? ' (previous backed up to __last-applied__)' : '') +
|
|
136
|
-
//
|
|
148
|
+
// 成功分支也要带尾注:`applyPresetGuarded` 走的是**全局**
|
|
137
149
|
// driver,本会话钉着的场景/会话级覆盖都不在其中 —— 不带的话,模型会照回执说
|
|
138
150
|
// 「提示词已换」,而用户在这个对话里看到的是原来那份。
|
|
139
151
|
promptScopeTail(scoped?.scope);
|
|
@@ -141,7 +153,7 @@ export function buildPromptTools(deps) {
|
|
|
141
153
|
}));
|
|
142
154
|
}
|
|
143
155
|
/**
|
|
144
|
-
*
|
|
156
|
+
* 提示词回执的会话尾注(三路:会话覆盖 / 钉住场景 / 无覆盖)。
|
|
145
157
|
*
|
|
146
158
|
* 提示词**不进**会话域:预设写的是全局基线 `~/.dsh/AGENTS.md`,宿主每轮只读一份。
|
|
147
159
|
* 但**生效来源**按会话走 —— 本会话可能钉了场景(`scene-preset`),也可能带会话级
|
package/lib/tools/remove.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// 删除 / 回收站族的 model
|
|
1
|
+
// 删除 / 回收站族的 model 工具:五个域各一条 `*_manager_remove`。
|
|
2
2
|
//
|
|
3
3
|
// 为什么单开一族:此前模型**只能停用、不能删除** —— "把这条过时的记忆删掉"这类要求手里
|
|
4
4
|
// 没有出口,模型会去调 `*_switch(enabled:false)` 然后回一句"已停用",用户以为删了。面板上
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
//
|
|
7
7
|
// 三条纪律:
|
|
8
8
|
// · **删除一律进回收站**(可恢复),与面板同一条路 —— 回执如实说"可恢复"。
|
|
9
|
-
// · **不做 purge
|
|
9
|
+
// · **不做 purge**(永久删除):低频且不可恢复,用户要求"使用频率低的可以不要,
|
|
10
10
|
// 太多功能反而冗余" —— 清空回收站留给面板。
|
|
11
11
|
// · `list` 是只读(不进场景冻结守卫,与 `trash-preview` 只读口径一致);`trash` /
|
|
12
12
|
// `restore` 是写,过 `lockedSceneGuard()`。
|
|
@@ -25,7 +25,7 @@ const ACTION_DESC = 'trash = delete the item named by `id`; restore = put back a
|
|
|
25
25
|
/** 删除只有全局一份(会话层没有可删的东西),四个域同一句话。 */
|
|
26
26
|
const REMOVE_SCOPE_DESC = scopeGlobalOnlyDesc('one machine-wide copy', 'switch it off here instead');
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* 场景的变体:`REMOVE_SCOPE_DESC` 让模型「在本会话里把它关掉」,
|
|
29
29
|
* 而场景根本没有「关掉」这个动作 —— `scene_manager_switch` 只有 enter / exit。照抄那一句
|
|
30
30
|
* 会让模型去找一个不存在的开关,或者干脆回一句「做不到」。
|
|
31
31
|
*/
|
|
@@ -36,7 +36,7 @@ const REMOVE_SCOPE_DESC_SCENE = scopeGlobalOnlyDesc('the scene record and archiv
|
|
|
36
36
|
* · 提示词预设 → `id`(预设的 id 就是它的名字)
|
|
37
37
|
* 记忆还会把投影对象放在 `rule.id` 上,作为第三顺位兜底。
|
|
38
38
|
*
|
|
39
|
-
* 还要解一层 `data
|
|
39
|
+
* 还要解一层 `data`(漏掉的那半):技能的 op 表外面包了
|
|
40
40
|
* `wrap`(`skills/service.ts:239` —— `{ ok: true, data: result }`),名字在 `r.data.name`,
|
|
41
41
|
* 不在 `r.name` 上。其余四个域的 op 是扁平返回。两边都要看,否则技能域的回执仍会退回 trashId。
|
|
42
42
|
*/
|
|
@@ -57,8 +57,8 @@ function restoredName(r) {
|
|
|
57
57
|
/**
|
|
58
58
|
* 一条删除工具的 execute:三个动词的分派与回执。
|
|
59
59
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
60
|
+
* 会话层:删除是**全局**动作 —— 技能正文、人设 `.md`、场景档案、MCP 补丁
|
|
61
|
+
* 提示词预设都只有一份,没有「本会话的副本」,所以这一格的口径就是「全局动作」。
|
|
62
62
|
* 所以这里不写会话层,只在**这个对话真有该域覆盖**时补一句尾注:
|
|
63
63
|
* 删完之后那条会话覆盖还在(读时忽略,对账才清),不说明的话用户会以为它跟着没了。
|
|
64
64
|
*/
|
|
@@ -77,9 +77,9 @@ async function runRemove(deps, cfg, args, agent) {
|
|
|
77
77
|
const blocked = await deps.lockedSceneGuard();
|
|
78
78
|
if (blocked)
|
|
79
79
|
throw new Error(blocked);
|
|
80
|
-
//
|
|
81
|
-
// 当场纠回来。省略 / "global"
|
|
82
|
-
//
|
|
80
|
+
// 会话层:`scope: "session"` 是模型**以为**自己能删本会话那一份时的错误
|
|
81
|
+
// 当场纠回来。省略 / "global" 照旧走全局。五条删除都是全局动作 ——
|
|
82
|
+
// 连提示词那一族也一样(提示词根本不进会话域,更没有「本会话的预设」可删)。
|
|
83
83
|
requireGlobalScope(args, cfg.noun + 's', !sessionLayerOn(deps));
|
|
84
84
|
const id = String((args && args.id) || '').trim();
|
|
85
85
|
if (id === '')
|
|
@@ -91,13 +91,14 @@ async function runRemove(deps, cfg, args, agent) {
|
|
|
91
91
|
return 'OK: ' + cfg.label + ' "' + id + '" moved to the trash (recoverable; permanent deletion lives in the panel trash)' +
|
|
92
92
|
(cfg.domain === undefined ? '' : globalActionNote(deps, agent, cfg.domain, cfg.label));
|
|
93
93
|
}
|
|
94
|
-
// 恢复的回执要说**恢复成了什么**,而不是回收站条目 id
|
|
94
|
+
// 恢复的回执要说**恢复成了什么**,而不是回收站条目 id:
|
|
95
95
|
// `id` 是 `action=list` 给的那一串(记忆 `mv…`、技能 `<时间戳>-<uuid>`),模型看到它
|
|
96
96
|
// 认不出恢复了哪一条;退号恢复时最终落盘的名字还与回收站里的原名不同,更要说准。
|
|
97
97
|
const name = restoredName(r) || id;
|
|
98
98
|
return 'OK: restored ' + cfg.label + ' "' + name + '" from the trash' +
|
|
99
99
|
(name === id ? '' : ' (trash entry ' + id + ')');
|
|
100
100
|
}
|
|
101
|
+
/** 注册删除类工具:技能 / 人设 / 场景三种对象各一个动词。 */
|
|
101
102
|
export function buildRemoveTools(deps) {
|
|
102
103
|
const { defineTool, register } = deps;
|
|
103
104
|
const mem = deps.memoryOps;
|
|
@@ -118,7 +119,7 @@ export function buildRemoveTools(deps) {
|
|
|
118
119
|
};
|
|
119
120
|
const skillCfg = {
|
|
120
121
|
noun: 'skill', label: 'skill', domain: 'skills',
|
|
121
|
-
// 与 `skill_manager_switch`
|
|
122
|
+
// 与 `skill_manager_switch` 同一条:不给 root 就按名字在全部来源里
|
|
122
123
|
// 找胜出的那一份。默认值原本是 dsh,而 `skill_manager_save` 落 hub —— 「建完就删」
|
|
123
124
|
// 必然报「技能不存在」。删一个真的不存在的技能时退回 dsh,交给 op 报它自己的错。
|
|
124
125
|
trash: async (a) => {
|
package/lib/tools/scene.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// 场景域的 model
|
|
1
|
+
// 场景域的 model 工具(从记忆族分出来;同日补上 `_switch` 与 `_list`):
|
|
2
2
|
// `scene_manager_list` → `_switch` → `_save`。**注册顺序就是兼容页「模型工具表」的显示顺序**
|
|
3
3
|
// (`tools/table.ts` 刻意不定义第二份排序),这一族按其余四族同形的排法排:先查、再拨开关、
|
|
4
4
|
// 最后写定义 —— 场景族补上这两条时是照"先建后切"的语义顺序注册的,成了五族里唯一的例外。
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
// 预算)。合成一条工具会让 `description` 变成双义参数、门禁按参数分叉,而这两件事的失败
|
|
9
9
|
// 形状都是静默的。
|
|
10
10
|
//
|
|
11
|
-
// 为什么有 `scene_manager_list
|
|
11
|
+
// 为什么有 `scene_manager_list`:
|
|
12
12
|
// 场景清单此前挂在 `memory_manager_list` 的输出末尾(它最初解释的是"这条记忆为什么没被注入",
|
|
13
|
-
//
|
|
13
|
+
// 后来把档案也并了进去,为的是不加新工具、不加新 op)。省下那 106 tok/轮的代价是
|
|
14
14
|
// **引用方向反了** —— 场景族两条工具都要模型去调记忆族的工具看现状,而工具表可以单独关掉
|
|
15
15
|
// `memory_manager_list`(`tools/table.ts`),关掉后 `_switch` 描述里那句"照抄它打印的场景名"
|
|
16
16
|
// 就悬空了。六个注入域里也只有场景没有自己的 list。
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
// 写侧为什么是两条、而不是一条带 `action` 的:
|
|
21
21
|
// · `_save` 只写**定义**(场景记录 + 档案),不改变现在;
|
|
22
22
|
// · `_switch` 改的是**现在**(进入 = 六处开关一起动 + 收窄注入 + 改写 AGENTS.md)。
|
|
23
|
-
//
|
|
23
|
+
// 危险度差一档,回执要说的事也完全不同。当初把「启用与进入」整个留在界面,
|
|
24
24
|
// 理由是"那是改运行时环境的动作";补上 `_switch` 的取舍记在 CHANGELOG 里 —— 要点是
|
|
25
25
|
// **场景段的动作句仍然不加回来**:「上下文注入只给现在是什么」是同一天定下的原则,
|
|
26
26
|
// 不因为多了一条工具就破例(工具描述本来就是写"什么时候该用它"的地方)。
|
|
27
|
-
import { effectiveScope, isolationOffNote, requireGlobalScope, scopeGlobalOnlyDesc, scopeSessionDesc, sessionLayerOn, sessionScopeOf, text, toolNameList } from './deps.js';
|
|
27
|
+
import { effectiveScope, globalUnchangedNote, isolationOffNote, requireGlobalScope, scopeGlobalOnlyDesc, scopeOnlyNote, scopeSessionDesc, sessionLayerOn, sessionScopeOf, text, toolNameList } from './deps.js';
|
|
28
28
|
import { FACTORY_TOOL_TABLE_PRESET } from './table.js';
|
|
29
29
|
/** 档案里由模型设置的段(`memories` 段在 P5 已废弃,不再是档案的一部分)。
|
|
30
|
-
* `mcpNotes
|
|
30
|
+
* `mcpNotes`与其余三段同族:整段替换、段缺席 = 不碰这一域。 */
|
|
31
31
|
const ARCHIVE_SECTIONS = ['mcp', 'mcpNotes', 'skills', 'subagents'];
|
|
32
32
|
/** 段里的名单:数组段是名字列表,`mcp` 段是 serverName → `'*'` | 工具名数组。段缺席 = 空。 */
|
|
33
33
|
function segmentNames(value) {
|
|
@@ -79,16 +79,16 @@ function archiveText(archive) {
|
|
|
79
79
|
const notes = keys(archive.mcpNotes);
|
|
80
80
|
if (notes.length)
|
|
81
81
|
parts.push('notes ' + toolNameList(notes));
|
|
82
|
-
//
|
|
82
|
+
// 模型工具表方案(档案里有这一栏):进入时换的是**模型自己能用什么**,不报就是
|
|
83
83
|
// 让它事后发现自己少了工具却说不出原因。只给方案名 —— 关停名单不在档案里,硬算要多读一次
|
|
84
84
|
// 方案清单,而真正需要条数的时机是切换之后(那条回执有)。没绑就不冒这一格(与备注同口径)。
|
|
85
85
|
const tt = toolTableLabel(archive.toolTablePreset);
|
|
86
86
|
if (tt)
|
|
87
87
|
parts.push('tool-table preset "' + tt + '"');
|
|
88
|
-
//
|
|
88
|
+
// 快捷提示词绑定:进了这个场景会动到 `/` 菜单里哪些条目,不报就只能靠猜。
|
|
89
89
|
// 空表是"进入后全部停用",与"没绑"(这一域不碰)是两句相反的话,不能压成一个 "0 条"。
|
|
90
90
|
//
|
|
91
|
-
// 印 **id
|
|
91
|
+
// 印 **id 而不是条数**:`scene_manager_save.quickPrompts` 的描述让模型
|
|
92
92
|
// "copy them from a scene binding in the listing" —— 而此前这里只印「N 条」,清单里根本
|
|
93
93
|
// 没有 id 可抄,那句是一条**指不到的死路**(模型照做只会白跑一趟,然后去问用户)。
|
|
94
94
|
// 与 `skills` / `subagents` 两段同款(那两段本来就是 `toolNameList` 印名字)。
|
|
@@ -129,12 +129,12 @@ function segmentDiff(key, beforeValue, afterValue) {
|
|
|
129
129
|
* 探测不到 / 什么都没做(`unchanged`)就不占行:那两种情况下文件确实没变,
|
|
130
130
|
* 说一句"没变"只是噪音。
|
|
131
131
|
*
|
|
132
|
-
* `baselineError
|
|
132
|
+
* `baselineError`:切进去了**但退不回来** —— 场景提示词已写进 AGENTS.md
|
|
133
133
|
* 而"进场景之前那份基线"没能落盘。此前这一支在客户端有(45-scenes.js 的
|
|
134
134
|
* `scenes.agents.note.baselineLost`)、工具回执里没有,于是模型侧唯一能看到的版本是
|
|
135
135
|
* "切成功了"。它比 `error` 更该说:文件已经改了,只是没有退路。
|
|
136
136
|
*
|
|
137
|
-
* `snapshotMissing
|
|
137
|
+
* `snapshotMissing`:**模式快照丢了**,退出场景只能落盘模式位、运行时
|
|
138
138
|
* (MCP / 技能 / 人设 / 工具表)回不来。客户端有计划卡上的同款文案
|
|
139
139
|
* (`scenes.exit.noSnapshot`),工具回执此前同样没有 —— 模型只能看到"已退出"。
|
|
140
140
|
*/
|
|
@@ -159,6 +159,7 @@ function agentsMdNote(sync, action) {
|
|
|
159
159
|
}
|
|
160
160
|
return notes.join('');
|
|
161
161
|
}
|
|
162
|
+
/** 注册场景域的 model 工具(列表 / 进入 / 保存 / 删除)。 */
|
|
162
163
|
export function buildSceneTools(deps) {
|
|
163
164
|
const { defineTool, register } = deps;
|
|
164
165
|
register(defineTool({
|
|
@@ -173,7 +174,7 @@ export function buildSceneTools(deps) {
|
|
|
173
174
|
parameters: {},
|
|
174
175
|
output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
|
|
175
176
|
async execute(_args, exec) {
|
|
176
|
-
//
|
|
177
|
+
// 会话层(`scene_manager_list` 标注本会话与全局默认):
|
|
177
178
|
// 列表里的 on/off 是**全局**的启用集合;本会话进入的场景是另一件事(只改这个对话
|
|
178
179
|
// 看到什么)。两者都不说清,模型会把「全局进入的是 A」读成「这个对话看到的也是 A」。
|
|
179
180
|
const scoped = sessionScopeOf(deps, exec && exec.agent);
|
|
@@ -210,7 +211,7 @@ export function buildSceneTools(deps) {
|
|
|
210
211
|
// 模型会把"启用着"读成"现在就是它" —— 而记忆与提示词只按**进入**的那一个注入。
|
|
211
212
|
if (entered !== null && name === entered)
|
|
212
213
|
state.push('entered');
|
|
213
|
-
//
|
|
214
|
+
// 本会话进入的那个场景:与 `entered` 是两个不同的东西 —— 前者只改
|
|
214
215
|
// 这个对话看到什么,后者真的切了运行时。同一个名字两个标,不冲突。
|
|
215
216
|
if (pinned !== undefined && name === pinned)
|
|
216
217
|
state.push('entered-in-this-conversation');
|
|
@@ -227,8 +228,8 @@ export function buildSceneTools(deps) {
|
|
|
227
228
|
bits.push('archive: ' + (archives === null ? 'unreadable (does not mean absent)' : archiveText(archives[name])));
|
|
228
229
|
return bits.join(' · ');
|
|
229
230
|
});
|
|
230
|
-
//
|
|
231
|
-
// `entered`
|
|
231
|
+
// 会话层:这一层进入的场景只改这一层的视图,不切运行时 —— 这一行必须与
|
|
232
|
+
// `entered` 分开报。退出场景之后这一层不回全局,而是回到创建时的样子。
|
|
232
233
|
const sessionLine = pinned !== undefined
|
|
233
234
|
? '\nthe view here is scene "' + pinned + '" (its own view: the machine-wide runtime was not switched and AGENTS.md was not written).'
|
|
234
235
|
: (detachedHere
|
|
@@ -249,10 +250,10 @@ export function buildSceneTools(deps) {
|
|
|
249
250
|
parameters: {
|
|
250
251
|
action: { type: 'string', required: true, enum: ['enter', 'exit'], description: 'enter = switch to the scene named in `scene`; exit = leave the current one (no scene needed).' },
|
|
251
252
|
scene: { type: 'string', description: 'Scene name (one path segment), required for enter — the exact name, not the display label.' },
|
|
252
|
-
//
|
|
253
|
-
//
|
|
253
|
+
// 默认只改**这个对话看到什么**,不切运行时、不写 AGENTS.md。
|
|
254
|
+
// 进入时可能让场景勾中的 MCP 服务器 / 技能来源按租约临时运行(连接与来源启用是
|
|
254
255
|
// 进程级的);那一步只在回执里出现,别在参数里长篇解释。
|
|
255
|
-
scope: { type: 'string', enum: ['session', 'global'], description: scopeSessionDesc('the scene is entered for that scope only: no runtime switch, AGENTS.md untouched (
|
|
256
|
+
scope: { type: 'string', enum: ['session', 'global'], description: scopeSessionDesc('the scene is entered for that scope only: no runtime switch, AGENTS.md untouched (its MCP servers may keep running for this scope). global = the machine-wide current scene: switches the runtime and applies the bound prompt to AGENTS.md.') },
|
|
256
257
|
},
|
|
257
258
|
output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
|
|
258
259
|
async execute(args, exec) {
|
|
@@ -263,7 +264,7 @@ export function buildSceneTools(deps) {
|
|
|
263
264
|
// 刻意**不过** `lockedSceneGuard()`:场景**自身**的启停不在冻结清单里(冻结的是五个
|
|
264
265
|
// 域的内容)。锁定中的场景正被进入时不能退出 —— 那条守卫在 `scene-mode-set` 的包装里
|
|
265
266
|
// (index.ts),它以 ok:false 返回,下面如实抛出去。
|
|
266
|
-
//
|
|
267
|
+
// 会话层进出场景**不切全局运行时** ——
|
|
267
268
|
// 不调 `scene-mode-set`、不调 `rules-set-active`、不写 AGENTS.md。它把场景作为本会话的
|
|
268
269
|
// 一层记下来:档案里勾了的在其生效集合内、没勾的在本会话关掉,记忆 / 场景段 / 目录按那个
|
|
269
270
|
// 场景投影。两个例外要如实说:进入时会把场景勾中的 MCP 服务器 / 技能来源在**全局**拉起
|
|
@@ -286,10 +287,10 @@ export function buildSceneTools(deps) {
|
|
|
286
287
|
throw new Error((sc && sc.error) || 'failed to switch the scene here');
|
|
287
288
|
const warnings = sc.warnings !== undefined && sc.warnings.length > 0 ? '\n' + sc.warnings.join('\n') : '';
|
|
288
289
|
return action === 'enter'
|
|
289
|
-
? 'OK: scene "' + wanted + '" is now entered
|
|
290
|
-
'. The machine-wide runtime did not switch and AGENTS.md was not written
|
|
290
|
+
? 'OK: scene "' + wanted + '" is now entered' + scopeOnlyNote(deps) + ' (its own view)' +
|
|
291
|
+
'. The machine-wide runtime did not switch and AGENTS.md was not written. ' + globalUnchangedNote(deps) + warnings +
|
|
291
292
|
' Pass scope="global" to enter it for real.'
|
|
292
|
-
: 'OK:
|
|
293
|
+
: 'OK: left the scene' + scopeOnlyNote(deps) + ' — back to how it looked when it was created (its own view). The runtime was not touched. ' + globalUnchangedNote(deps);
|
|
293
294
|
}
|
|
294
295
|
let scene = '';
|
|
295
296
|
if (action === 'enter') {
|
|
@@ -360,7 +361,7 @@ export function buildSceneTools(deps) {
|
|
|
360
361
|
// 而"退出时快照丢了"这件事只有模式引擎知道(见 archive-engine.ts 的 scene-mode-set)。
|
|
361
362
|
// 进 / 退两个方向都报 —— 进场景时它说的是"你即将进入一个退不出来的场景"。
|
|
362
363
|
const snapshotMissing = mode && mode.exit && mode.exit.snapshotMissing === true;
|
|
363
|
-
//
|
|
364
|
+
// 会话层:全局切了场景,但**本会话**若钉着别的场景,这里看到的东西不会变。
|
|
364
365
|
// 不点这一句,模型会以为「切了场景 = 我这边也切了」,然后拿错误的场景解释上下文。
|
|
365
366
|
const pinned = sessionScopeOf(deps, exec && exec.agent)?.scope?.scene;
|
|
366
367
|
const pinnedNote = pinned === undefined
|
|
@@ -378,25 +379,27 @@ export function buildSceneTools(deps) {
|
|
|
378
379
|
register(defineTool({
|
|
379
380
|
name: 'scene_manager_save',
|
|
380
381
|
// 「写入指引」保留("写成指令而不是备注"—— 这是场景说明质量的杠杆),但不再声称
|
|
381
|
-
// "注入后模型会被要求照办"
|
|
382
|
+
// "注入后模型会被要求照办":定稿把场景段的授权语删了(注入只陈述现状),
|
|
382
383
|
// 参数说明与注入侧各说各话时,模型信的那份是错的。改为如实说明去向。
|
|
383
|
-
|
|
384
|
+
// 描述不再逐项列举档案里有哪些段(参数表本身就是那张清单,模型读参数时两处都在手上):
|
|
385
|
+
// 这里只留参数表**答不了**的三件事 —— 场景是什么、整段替换的语义、保存不等于进入。
|
|
386
|
+
description: 'Save a scene — a named bundle the user enters: entering switches on exactly what its archive lists and everything else off. Creates it if absent. Omitted fields keep their values; an archive section you give replaces that section whole (include what should stay — the receipt reports what got displaced). Saving does not enter it. Only on the user\'s instruction.',
|
|
384
387
|
parameters: {
|
|
385
388
|
scene: { type: 'string', required: true, description: 'Scene name (one path segment, ≤64 chars, no / \\ or < > : " | ? *, not `_shared`). Created if absent.' },
|
|
386
389
|
label: { type: 'string', description: 'Display name for this scene.' },
|
|
387
390
|
description: { type: 'string', description: 'What this scene is for — write an instruction, not a note; it shows beside the scene name while the scene is on.' },
|
|
388
391
|
// 与下面 `mcp` / `skills` / `subagents` 同一句式("X = 一个都不"):
|
|
389
|
-
// 界面
|
|
392
|
+
// 界面 补了「无」这个选项,工具侧的空串语义要跟着说清,否则模型只知道
|
|
390
393
|
// 「省略 = 保持」,不知道还有一条「解绑」的路。
|
|
391
394
|
prompt: { type: 'string', description: 'Prompt preset id to bind; while this scene is on it is the global baseline. \'\' = bind none (this scene leaves AGENTS.md alone).' },
|
|
392
|
-
//
|
|
393
|
-
//
|
|
395
|
+
// 模型工具表方案绑定:界面早就能绑、档案里一直有这一栏,`_list` / `_switch` 也读它,
|
|
396
|
+
// 唯独 `_save` 写不了。'' = 解绑只能走
|
|
394
397
|
// `rules-update-scene` —— `scene-archive-save` 对载荷里**不带的栏**一律保留现值
|
|
395
398
|
// (archive-engine 的「不带 ≠ 解绑」),所以解绑与设置分成两条路,见 execute 的 ②。
|
|
396
399
|
// 哨兵 `factory-default` 与界面下拉同值(tools/table.ts 的 FACTORY_TOOL_TABLE_PRESET);
|
|
397
400
|
// 不存在的方案名由引擎按 stale 丢弃并在进入时报告,op 不硬拒(与悬空绑定同口径)。
|
|
398
401
|
toolTablePreset: { type: 'string', description: "Model tool-table scheme to bind while this scene is on. '' = unbind; 'factory-default' = the factory default; otherwise a saved scheme name. An unknown name is dropped and reported." },
|
|
399
|
-
//
|
|
402
|
+
// 快捷提示词绑定。段语义与上面三个档案段相反:**空数组是合法值**
|
|
400
403
|
// (进入后全部停用),不是"清除这一段"。本工具不提供解绑(界面可解)—— 与
|
|
401
404
|
// mcp / skills / subagents 三段没有解绑参数同一条口径。id 从场景清单里别的场景的
|
|
402
405
|
// 绑定、或用户口述里来;不存在的 id 被引擎丢弃并在回执报出来。
|
|
@@ -409,7 +412,7 @@ export function buildSceneTools(deps) {
|
|
|
409
412
|
additionalProperties: true,
|
|
410
413
|
description: "Archive: serverName -> '*' (whole server) or a list of tool names to leave on. {} = switch none on.",
|
|
411
414
|
},
|
|
412
|
-
// 场景级 MCP
|
|
415
|
+
// 场景级 MCP 备注覆盖:进入这个场景时用这份盖掉全局备注,退出时还原。
|
|
413
416
|
// 与 mcp 段同一句式(省略 = 保持;{} = 一个都不覆盖)—— 界面存档编辑器早就能改,
|
|
414
417
|
// `_list` 也显示它,`_save` 此前不接这一段。
|
|
415
418
|
mcpNotes: {
|
|
@@ -419,7 +422,7 @@ export function buildSceneTools(deps) {
|
|
|
419
422
|
},
|
|
420
423
|
skills: { type: 'array', items: { type: 'string' }, description: 'Archive: skill keys `<root>/<name>` to switch on. [] = switch none on.' },
|
|
421
424
|
subagents: { type: 'array', items: { type: 'string' }, description: 'Archive: persona names to switch on. [] = switch none on.' },
|
|
422
|
-
//
|
|
425
|
+
// 场景记录与档案是**机器级**的,没有「本会话的一份」。这个参数只为一件事:
|
|
423
426
|
// 模型以为自己在改会话时,当场纠回来(见 deps.ts 的 requireGlobalScope)。
|
|
424
427
|
scope: { type: 'string', enum: ['session', 'global'], description: scopeGlobalOnlyDesc('the scene record and archive are machine-wide', 'entering a scene for one conversation is a switch action') },
|
|
425
428
|
},
|
|
@@ -506,7 +509,7 @@ export function buildSceneTools(deps) {
|
|
|
506
509
|
// ③ 档案 read-modify-write:段(mcp / mcpNotes / skills / subagents)与两个绑定栏的
|
|
507
510
|
// 「设置」方向合并成一份,只经 `scene-archive-save` 一条路落盘。
|
|
508
511
|
// **必须 read-modify-write**:`scene-archive-save` 是**整份替换**,只把模型给的段
|
|
509
|
-
// 传过去,没给的段会被静默清掉 —— 与
|
|
512
|
+
// 传过去,没给的段会被静默清掉 —— 与 `subagent_manager_save` 省略字段被
|
|
510
513
|
// 清空同一形状,只是这次清掉的是"这个场景进入时要开哪些东西"。
|
|
511
514
|
// 注意段语义:**段不存在 = 不限制(全部照常)**,段存在但为空 = 全部停用。所以模型给
|
|
512
515
|
// `mcp: {}` 得到的是"全不勾",不是"清除该段" —— 后者只能靠不给。
|
|
@@ -582,16 +585,16 @@ export function buildSceneTools(deps) {
|
|
|
582
585
|
// 点名 scene_manager_switch 的那句按可见性分叉(它在出厂默认名单里就是关着的):
|
|
583
586
|
// 部分启用(开 save 不开 switch)时指向一条模型没有的工具,只会让它白跑一趟 ——
|
|
584
587
|
// 与 mcp/skill 的 listHint 同一条纪律。
|
|
585
|
-
const enterHint = deps.
|
|
588
|
+
const enterHint = deps.toolVisibleFor('scene_manager_switch', exec && exec.agent)
|
|
586
589
|
? 'To take effect, enter it with scene_manager_switch.'
|
|
587
590
|
: 'To take effect, the user has to enter this scene manually (scene_manager_switch is not available in this session).';
|
|
588
|
-
//
|
|
591
|
+
// 会话层:场景记录与档案是**机器级**的(一份索引 + 一份档案),本会话能改的
|
|
589
592
|
// 只有「这个对话用哪个场景」。不说清的话,模型会把「存好了」读成「只在这个对话里生效」。
|
|
590
593
|
const pinned = sessionScopeOf(deps, exec && exec.agent)?.scope?.scene;
|
|
591
594
|
const globalNote = pinned === undefined
|
|
592
595
|
? ''
|
|
593
|
-
: '\nnote: scenes are global (one record and one archive for the whole machine).
|
|
594
|
-
' (currently "' + pinned + '");
|
|
596
|
+
: '\nnote: scenes are global (one record and one archive for the whole machine). The pin here only decides which scene this scope uses' +
|
|
597
|
+
' (currently "' + pinned + '"); ' + globalUnchangedNote(deps);
|
|
595
598
|
return 'OK: scene "' + scene + '"' + parts.join('; ') + warnTail + clearWarn + globalNote +
|
|
596
599
|
(collapsed
|
|
597
600
|
? '\nnote: every scene was enabled until now (the historical all-enabled default); this call narrowed the enabled set to one scene, and the new one is not it — the user should confirm the enabled state.'
|