dsh-plugin-tool-management 0.21.1 → 0.21.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/CHANGELOG.md +111 -1
  2. package/README.md +43 -7
  3. package/README_EN.md +41 -7
  4. package/docs/{update.md → UPDATE.md} +38 -36
  5. package/docs/images/1-EN.png +0 -0
  6. package/docs/images/1.png +0 -0
  7. package/docs/images/2-EN.png +0 -0
  8. package/docs/images/2.png +0 -0
  9. package/docs/images/3-EN.png +0 -0
  10. package/docs/images/3.png +0 -0
  11. package/docs/images/4-EN.png +0 -0
  12. package/docs/images/4.png +0 -0
  13. package/docs/images/5-EN.png +0 -0
  14. package/docs/images/5.png +0 -0
  15. package/docs/images/6-EN.png +0 -0
  16. package/docs/images/6.png +0 -0
  17. package/docs/images/7-EN.png +0 -0
  18. package/docs/images/7.png +0 -0
  19. package/docs/images/8-EN.png +0 -0
  20. package/docs/images/8.png +0 -0
  21. package/lib/approval-policy.js +2 -2
  22. package/lib/audit-log.js +1 -1
  23. package/lib/boot/reconcile.js +157 -0
  24. package/lib/client.js +6668 -3145
  25. package/lib/compat/capability-specs.js +13 -17
  26. package/lib/compat/host-contracts.js +2 -0
  27. package/lib/compat/host-probe.js +35 -38
  28. package/lib/compat/host-roots.js +86 -15
  29. package/lib/compat/patch-dialect.js +14 -1
  30. package/lib/compat/preset-reach.js +75 -102
  31. package/lib/compat/probe.js +86 -131
  32. package/lib/compat/runtime-notes.js +1 -1
  33. package/lib/context-inject-contract.js +6 -5
  34. package/lib/context-inject-frame.js +124 -73
  35. package/lib/context-inject-select.js +66 -12
  36. package/lib/context-inject-surface.js +52 -4
  37. package/lib/context-inject.js +176 -39
  38. package/lib/desktop-cookie-prune.js +95 -0
  39. package/lib/diagnostics.js +79 -0
  40. package/lib/exports/transcript.js +4 -4
  41. package/lib/host-names.js +6 -6
  42. package/lib/http-api.js +73 -48
  43. package/lib/http-fence.js +44 -9
  44. package/lib/hub.js +12 -13
  45. package/lib/imports/parsers.js +25 -21
  46. package/lib/imports/unzip.js +48 -0
  47. package/lib/imports/upload.js +13 -37
  48. package/lib/index.js +3026 -279
  49. package/lib/mcp/disabled-tools.js +97 -0
  50. package/lib/mcp/loader-token.js +4 -4
  51. package/lib/mcp/manager.js +636 -226
  52. package/lib/mcp/override-blocks.js +1 -1
  53. package/lib/mcp/patch-yaml.js +42 -31
  54. package/lib/mcp/restart-marker.js +110 -0
  55. package/lib/mcp/secret-guard.js +6 -6
  56. package/lib/mcp/state-section.js +190 -60
  57. package/lib/mcp/tool-visibility.js +364 -73
  58. package/lib/memories/archive-engine.js +67 -42
  59. package/lib/memories/archive.js +23 -3
  60. package/lib/memories/constants.js +40 -127
  61. package/lib/memories/discovery.js +41 -12
  62. package/lib/memories/index-io.js +238 -33
  63. package/lib/memories/projection.js +36 -20
  64. package/lib/memories/prompt-layer.js +38 -0
  65. package/lib/memories/search.js +86 -0
  66. package/lib/memories/service.js +350 -111
  67. package/lib/memories/snapshot.js +83 -36
  68. package/lib/op-registry.js +73 -15
  69. package/lib/ops/candidates.js +14 -5
  70. package/lib/ops/compat.js +56 -13
  71. package/lib/ops/ctx.js +1 -1
  72. package/lib/ops/memory.js +89 -20
  73. package/lib/ops/prompts.js +57 -13
  74. package/lib/ops/quick-prompts.js +25 -2
  75. package/lib/ops/scene-records.js +29 -23
  76. package/lib/ops/scene-sync.js +30 -10
  77. package/lib/ops/scope.js +1094 -0
  78. package/lib/ops/sessions.js +15 -11
  79. package/lib/ops/snapshot.js +65 -29
  80. package/lib/ops/state-doctor.js +40 -5
  81. package/lib/ops/trash-retention.js +2 -1
  82. package/lib/ops/trash.js +6 -6
  83. package/lib/paths.js +50 -3
  84. package/lib/prompts/preset-id.js +5 -1
  85. package/lib/prompts/project-instructions.js +162 -0
  86. package/lib/prompts/quick-service.js +6 -4
  87. package/lib/prompts/service.js +30 -18
  88. package/lib/request-gate.js +32 -29
  89. package/lib/scene-linkage.js +17 -4
  90. package/lib/scene-prompt-sync.js +11 -10
  91. package/lib/scene-settings.js +1 -0
  92. package/lib/scenes/candidates.js +17 -11
  93. package/lib/scope/intent-store.js +106 -0
  94. package/lib/scope/intent.js +376 -0
  95. package/lib/scope/resolve.js +190 -0
  96. package/lib/scope/scope-overrides.js +894 -0
  97. package/lib/scope/store.js +263 -0
  98. package/lib/scope/workspace-key.js +64 -0
  99. package/lib/sessions/archive-schemas.js +9 -0
  100. package/lib/sessions/bridge.js +42 -56
  101. package/lib/sessions/history.js +9 -9
  102. package/lib/sessions/workspace.js +21 -23
  103. package/lib/settings-sidecars.js +51 -24
  104. package/lib/sidebar-settings.js +1 -0
  105. package/lib/skills/catalog.js +207 -35
  106. package/lib/skills/core-util.js +5 -0
  107. package/lib/skills/core.js +36 -23
  108. package/lib/skills/frontmatter.js +144 -11
  109. package/lib/skills/homes.js +2 -0
  110. package/lib/skills/import-pipeline.js +8 -1
  111. package/lib/skills/manager-state.js +30 -6
  112. package/lib/skills/official.js +14 -11
  113. package/lib/skills/readonly-discovery.js +1 -0
  114. package/lib/skills/service.js +157 -31
  115. package/lib/skills/skill-roots.js +25 -7
  116. package/lib/skills/skill-trash.js +14 -3
  117. package/lib/skills/system-trash.js +3 -1
  118. package/lib/skills/upload-pipeline.js +19 -3
  119. package/lib/slash-settings.js +1 -0
  120. package/lib/stale-write.js +82 -0
  121. package/lib/subagents/catalog.js +52 -18
  122. package/lib/subagents/child-preset.js +7 -10
  123. package/lib/subagents/persona-parse.js +35 -13
  124. package/lib/subagents/persona-write.js +12 -8
  125. package/lib/subagents/run-provider.js +13 -15
  126. package/lib/subagents/service.js +16 -14
  127. package/lib/subagents/tool-filter.js +1 -1
  128. package/lib/subagents/tools.js +113 -41
  129. package/lib/token-config.js +34 -14
  130. package/lib/tool-table-switch.js +142 -49
  131. package/lib/tools/deps.js +172 -6
  132. package/lib/tools/mcp.js +231 -54
  133. package/lib/tools/memory.js +139 -39
  134. package/lib/tools/prompt.js +81 -17
  135. package/lib/tools/remove.js +52 -26
  136. package/lib/tools/scene.js +139 -42
  137. package/lib/tools/skills.js +211 -51
  138. package/lib/tools/subagent.js +63 -32
  139. package/lib/tools/table.js +63 -25
  140. package/lib/trash-id.js +3 -2
  141. package/lib/trash-retention.js +7 -7
  142. package/lib/update-check.js +222 -0
  143. package/package.json +18 -15
@@ -1,15 +1,14 @@
1
- // 记忆(rules)域的 model 工具(2026-09-19 从 index.ts 的注册区抽出;2026-09-23 改名合并、
2
- // 同日把场景能力分出去):memory_manager_list / _read / _switch / _save。
1
+ // 记忆(rules)域的 model 工具:memory_manager_list / _read / _search / _switch / _save。
3
2
  //
4
- // 为什么族名在 0.14.0 里绕了一圈回到 `memory_manager_`:中途改成 `scene_memory_manager_`
5
- // 是为了跟注入段名(`scene-memory-manager-catalog`)对齐,但那个名字描述的是**域**,
3
+ // 为什么族名是 `memory_manager_` 而不是 `scene_memory_manager_`:后者是为了跟注入段名
4
+ // (`scene-memory-manager-catalog`)对齐才改的,但那个名字描述的是**域**,
6
5
  // 而这个族操作的全是记忆。加场景能力时这个错配就现形了 —— 场景是另一个对象(容器,
7
6
  // 进入时切换 mcp / 技能 / 人设),硬塞进 `save` 会让 `description` 变成双义参数(给
8
7
  // `memory` 时是记忆描述、给 `scene` 时是场景描述),门禁也得按参数分叉(记忆写入有开关
9
8
  // 可放行,场景写入是改运行时环境、不该有那条路)。所以拆成两族:这里管记忆内容,
10
9
  // `scene_manager_*`(tools/scene.ts)管场景本身。
11
10
  //
12
- // 场景清单也不挂在这条 list 的尾巴上(同日第四轮裁定:「记忆就管记忆,场景就管场景」)——
11
+ // 场景清单也不挂在这条 list 的尾巴上(「记忆就管记忆,场景就管场景」)——
13
12
  // 它在 `scene_manager_list`,理由记在 tools/scene.ts 头部,别当"少写了一段"再加回来。
14
13
  //
15
14
  // 为什么 write + update 并成 save:两者的判定(同名 = 改、无同名 = 建)本来就只有
@@ -17,22 +16,24 @@
17
16
  // 模型必须自己先查一次再决定调哪条,而它手里的清单可能已经过期。合并后由工具侧兜住。
18
17
  //
19
18
  // 活动场景的记忆正文会自动注入上下文(无需调用工具读取);这里的工具用于查询/编辑规则
20
- // 本身。memory_manager_save 受 tools/pre-execute 审批门禁(D2)。
19
+ // 本身。memory_manager_save 受 tools/pre-execute 审批门禁。
21
20
  // 路径锚点:$DSH_HOME/tool-management/memories/<场景>/…(场景 `global` = 界面「全局」)。
22
- import { text } from './deps.js';
21
+ import { GLOBAL_SCENE, SHARED_GROUP } from '../memories/constants.js';
22
+ import { effectiveScope, globalActionNote, globalUnchangedNote, isolationOffNote, scopeOnlyNote, scopeSessionDesc, sessionScopeOf, text } from './deps.js';
23
+ /** 注册记忆域的 model 工具(列表 / 读取 / 检索 / 切换 / 保存)。 */
23
24
  export function buildMemoryTools(deps) {
24
25
  const { defineTool, register } = deps;
25
26
  register(defineTool({
26
27
  name: 'memory_manager_list',
27
28
  // 末尾**不点名** `scene_manager_list`:场景一族在出厂默认里就是关着的,指向一条模型没有的
28
- // 工具只会让它去猜名字(用户 2026-09-23 把默认名单扩到十五条时去掉的这句)。
29
- description: 'List memories (id, scene, enabled, form flat|bundle, description) plus the scene injection currently follows. What is injected each turn is in the "Current memories" reminder; use this for ids and for entries that are off. Pass a `scene` to filter by scene; all=true lists everything.',
29
+ // 工具只会让它去猜名字(用户 把默认名单扩到十五条时去掉的这句)。
30
+ description: 'List memories (id, scene, enabled, form flat|bundle, description) plus the scene the injection follows. What is injected each turn is in the "Current memories" reminder; use this for ids and for entries that are off. Pass `scene` to filter; all=true lists everything.',
30
31
  parameters: {
31
- // 参数名与其余五个域同词(2026-10-14 对抗性审查 P1-3):同一个概念在工具面只该有一个名字,
32
+ // 参数名与其余五个域同词:同一个概念在工具面只该有一个名字
32
33
  // 而 `scene` 是它在 `scene_manager_*`、`<scene>/<name>` 与注入段标题里的叫法。
33
34
  // op 的内部契约字段仍是 `group`(`rules-list` 与界面侧调用方都读它),所以 execute 里
34
35
  // 显式映射一次 —— 改 op 的字段名要动界面,那不是这一条能顺手做的事。
35
- scene: { type: 'string', description: 'Optional scene filter.' },
36
+ scene: { type: 'string', description: 'Optional scene filter; `global` is the always-on scene.' },
36
37
  all: { type: 'boolean', description: 'Include memories that are off, in an inactive scene, or shadowed (default false).' },
37
38
  },
38
39
  output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
@@ -42,13 +43,27 @@ export function buildMemoryTools(deps) {
42
43
  const opArgs = {};
43
44
  if (args && args.scene !== undefined)
44
45
  opArgs.group = args.scene;
46
+ // 会话层(`memory_manager_list` 只列本会话场景):带上 sessionId,
47
+ // op 就按本会话钉住的场景与逐条开关投影 —— 「会注入」这一栏与模型真实看到的一致。
48
+ // 取不到会话 = 不给,op 退回全局口径(不报错)。
49
+ const scoped = sessionScopeOf(deps, exec && exec.agent);
50
+ if (scoped !== null)
51
+ opArgs.sessionId = scoped.sessionId;
45
52
  const r = await deps.rulesOps['rules-list'](opArgs);
46
53
  if (!r || r.ok === false)
47
54
  throw new Error((r && r.error) || 'failed to read memories');
48
55
  // 「会注入」的判定与记忆段同源(renderSceneMemory):global 场景恒常注入,其余场景要
49
56
  // 在 index.active 里,再叠加单条 enabled 与同名 bundle 的 shadowed。默认只列这些,
50
- // 全列一次会把没启用的条目也算进上下文(用户裁定 2026-09-16,与技能列表同口径)。
51
- const sceneOn = (group) => group === 'global' ||
57
+ // 全列一次会把没启用的条目也算进上下文(与技能列表同口径)。
58
+ //
59
+ // **两个**保留桶恒常注入,不是一个:`global`(界面「全局」)之外还有 `_shared`
60
+ // (公共基线)。注入侧 `resolveActiveScenes` 无条件把两者都放进 active
61
+ // (见 memories/projection.ts),这里只认 `global` 就会把 `_shared` 标成
62
+ // "scene off" 并默认藏起来 —— 而它每轮都在上下文里。模型照这份名单回答
63
+ // 「没有这条记忆」,实际它正躺在自己眼前。`activeScene` 永远报不到 `_shared`
64
+ // (`enabledSceneOf` 只回非保留场景),所以只能在这一层显式认。
65
+ const alwaysInjects = (group) => group === GLOBAL_SCENE || group === SHARED_GROUP;
66
+ const sceneOn = (group) => alwaysInjects(group) ||
52
67
  (group !== '' && (r.activeMode === 'all' || String(r.activeScene || '') === group));
53
68
  const stateOf = (x) => {
54
69
  if (x.shadowed === true)
@@ -62,7 +77,7 @@ export function buildMemoryTools(deps) {
62
77
  const rows = (r.rules || []).map((x) => ({ x, ...stateOf(x) }));
63
78
  const shown = showAll ? rows : rows.filter((row) => row.injects);
64
79
  const lines = shown.map(({ x, label }) => ('- ' + x.id + ' [' + (x.group || 'no scene') + '] ' + label +
65
- // 形态与附件(2026-10-15):此前不报,模型分不清哪条是 bundle、更不知道它带了几个附件
80
+ // 形态与附件:此前不报,模型分不清哪条是 bundle、更不知道它带了几个附件
66
81
  // (`rules-list` 早就把 `form` 与 bundle 的附件摘要给了出来,只是这里没渲染)。
67
82
  (x.form === 'bundle'
68
83
  ? ' · bundle' + (x.attach && x.attach.count ? ' (' + x.attach.count + ' attachment(s))' : '')
@@ -70,15 +85,26 @@ export function buildMemoryTools(deps) {
70
85
  (x.description ? ' — ' + x.description : '')));
71
86
  // 注入按哪个场景走 —— 上面那句「场景未启用」只有配上它才可解读:少了这一行,
72
87
  // 模型看到一片"未启用"会以为是条目自己的问题。(场景本身的清单在 `scene_manager_list`,
73
- // 2026-09-23 拆过去了;这里只留"记忆按哪一集注入",因为那是记忆域自己的现状。)
74
88
  const scope = r.activeMode === 'all'
75
89
  ? 'every scene (historical default, not narrowed)'
76
90
  : (r.activeScene ? '"' + String(r.activeScene) + '"' : 'no scene is on');
91
+ // 会话层:本会话钉了场景 / 改了个别开关时,上面那行报的是**本会话**的投影
92
+ // 与全局可能不同。不说清的话,模型会拿这份名单去回答"全局现在是什么" —— 那是错的答案。
93
+ // 粒度决定这句话的主语:工作区粒度下那一格是同工作区共享的,"本对话"是假话。
94
+ const viewNoun = deps.scopeMode?.() === 'workspace' ? 'this workspace' : 'this conversation';
95
+ const sessionNote = scoped === null || scoped.scope === undefined
96
+ ? ''
97
+ : '\nthis is ' + viewNoun + "'s view" +
98
+ (scoped.scope.scene !== undefined ? ' — scene pinned to "' + scoped.scope.scene + '"; the machine-wide scene may differ' : '') +
99
+ (scoped.scope.memory !== undefined ? '; ' + Object.keys(scoped.scope.memory).length + ' switch(es) applied here' : '');
100
+ // `_shared` 只在真有这类条目时点名:没有就不付这几个字,而有了不说的话,
101
+ // 上面那句「只列会注入的」会让人以为名单里全是 global + 当前场景。
102
+ const sharedHere = rows.some(({ x }) => String(x.group || '') === SHARED_GROUP);
77
103
  const header = 'memories: ' + (showAll
78
104
  ? rows.length + ' total'
79
105
  : shown.length + ' injecting / ' + rows.length + ' total' +
80
106
  (shown.length === rows.length ? '' : ' (pass all=true for all)')) +
81
- '\ninjects from: ' + scope + ' + global (global always injects)\n';
107
+ '\ninjects from: ' + scope + ' + global' + (sharedHere ? ' + _shared' : '') + ' (always on)' + sessionNote + '\n';
82
108
  // 注入边界:压制型预设(persona complete / 关闭运行时上下文)下本插件默认不注入,
83
109
  // 此时列出的记忆**不在**模型上下文里。必须说出来,否则模型会假设自己已经看到正文。
84
110
  const notice = await deps.reachNoticeForAgent(deps.presetRoster(), exec && exec.agent && exec.agent.ctx, deps.injectNoticeOptions());
@@ -87,21 +113,21 @@ export function buildMemoryTools(deps) {
87
113
  }));
88
114
  register(defineTool({
89
115
  name: 'memory_manager_read',
90
- // "dropped by the byte budget" 改成"left out of it"(2026-10-15 注入文本审查):byte budget
116
+ // "dropped by the byte budget" 改成"left out of it":byte budget
91
117
  // 是本插件内部术语,模型没有这个概念 —— 它只知道"这条在不在我上下文里"。说内部机制
92
118
  // 等于让它去猜一个它观测不到的量。
93
- description: 'Read the full body of one memory, plus its form (flat|bundle) and the names of its attachments. Only for ones not already in your context (disabled, in an inactive scene, or left out of it). Attachment contents are not returned — read those with your file tools.',
119
+ description: 'Read one memory\'s full body, its form (flat|bundle) and its attachment names. Only for ones not already in your context (disabled, in an inactive scene, or left out). Attachment contents are not returned — use your file tools.',
94
120
  parameters: {
95
121
  memory: { type: 'string', required: true, description: 'Memory id like <scene>/<name>.' },
96
122
  },
97
123
  output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
98
- async execute(args) {
124
+ async execute(args, exec) {
99
125
  // op 的字段名是 `id`,不改 op:这里显式转换(键名对模型是 `<场景>/<名字>`,对 op 是 `id`)。
100
126
  const r = await deps.rulesOps['rules-read']({ id: String((args && args.memory) || '') });
101
127
  if (!r || r.ok === false)
102
128
  throw new Error((r && r.error) || 'failed to read memories');
103
129
  const rule = r.rule || {};
104
- // 形态与附件名(2026-10-15):op 一直把 `attachments` 给了出来,这里此前**整个丢掉**,
130
+ // 形态与附件名:op 一直把 `attachments` 给了出来,这里此前**整个丢掉**,
105
131
  // 于是模型连"这条记忆是 bundle、带了 3 个附件"都看不到。只给名字不给内容 ——
106
132
  // 附件可能是图片或大 md,全文塞回来会吃光这一轮的上下文(与注入段附件行同口径)。
107
133
  const attach = Array.isArray(rule.attachments) ? rule.attachments : [];
@@ -109,16 +135,58 @@ export function buildMemoryTools(deps) {
109
135
  const attLine = attach.length
110
136
  ? '\nattachments (' + attach.length + '): ' + attach.map((a) => String((a && a.name) || a)).join(', ')
111
137
  : '';
112
- return '# ' + rule.id + ' (' + form + ')' + attLine + '\n\n' + (rule.body || '');
138
+ // 会话层:这条记忆在本会话是关着的(或不在本会话钉住的场景里)时,读得到
139
+ // 正文 ≠ 它会进上下文。不说清的话,模型会以为自己已经掌握了它、下一轮却看不到。
140
+ const scoped = sessionScopeOf(deps, exec && exec.agent);
141
+ const over = scoped?.scope?.memory?.[String(rule.id)];
142
+ const offHere = over === false
143
+ ? '\n(switched off here only — the body above is not injected here; the global setting is unchanged) '
144
+ : '';
145
+ return '# ' + rule.id + ' (' + form + ')' + attLine + '\n\n' + (rule.body || '') + offHere;
146
+ },
147
+ }));
148
+ register(defineTool({
149
+ name: 'memory_manager_search',
150
+ // 为什么单独一条而不是给 list 加 `query`:list 是"清单"(每条都要占一行输出),
151
+ // 搜索是"找一条"(片段 + 排序)。混在一起时,搜不到就等于清单为空 —— 模型分不清
152
+ // "没有这条记忆"和"这个词没匹配上"。默认在工具表里**关着**(见 tools/table.ts):
153
+ // 它是按需检索,不是每轮都该付 schema 成本的能力。
154
+ description: 'Search memories by words in id, scene, description, tags or body. Returns ids plus a short snippet; read the memory itself for the full body. All words must match (case-insensitive).',
155
+ parameters: {
156
+ query: { type: 'string', required: true, description: 'Words to look for; every word must match somewhere in the memory.' },
157
+ limit: { type: 'number', description: 'Max hits (default 20, max 100).' },
158
+ },
159
+ output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
160
+ async execute(args, exec) {
161
+ const query = String((args && args.query) || '').trim();
162
+ if (query === '')
163
+ throw new Error('missing argument: query');
164
+ const opArgs = { query };
165
+ if (args && args.limit !== undefined)
166
+ opArgs.limit = args.limit;
167
+ // 与 list 同一条会话投影:`enabled` 报的是**这里**的生效值,不是全局。
168
+ const scoped = sessionScopeOf(deps, exec && exec.agent);
169
+ if (scoped !== null)
170
+ opArgs.sessionId = scoped.sessionId;
171
+ const r = await deps.rulesOps['rules-search'](opArgs);
172
+ if (!r || r.ok === false)
173
+ throw new Error((r && r.error) || 'failed to search memories');
174
+ const hits = Array.isArray(r.hits) ? r.hits : [];
175
+ if (!hits.length)
176
+ return 'no memories match "' + query + '"';
177
+ const lines = hits.map((h) => '- ' + h.id + ' [' + (h.scene || 'no scene') + ']' +
178
+ (h.enabled === false ? ' (off here)' : '') +
179
+ (h.snippet ? ' — ' + h.snippet : ''));
180
+ return 'memories matching "' + query + '": ' + hits.length + '\n' + lines.join('\n');
113
181
  },
114
182
  }));
115
183
  register(defineTool({
116
184
  name: 'memory_manager_switch',
117
- // 为什么叫 `_switch` 而不是 `_set_enabled`(2026-09-23 用户裁定):六个域里"拨一个开关"
185
+ // 为什么叫 `_switch` 而不是 `_set_enabled`:六个域里"拨一个开关"
118
186
  // 是同一件事,名字该同形 —— `mcp_manager_switch` 早就是这个名字,`_set_enabled` 只剩
119
187
  // 记忆 / 技能 / 人设三族在叫。**参数保留 `enabled` 布尔**:这里没有 `restart` 那第三个
120
188
  // 动词,`action: 'on' | 'off'` 只会在 `true`/`false` 之上多一层映射、多付一段 schema。
121
- // 旧名不注册别名(同 0.14.0 的口径:注册就进工具表、就要付 token);用户的旧设置由
189
+ // 旧名不注册别名(同一口径:注册就进工具表、就要付 token);用户的旧设置由
122
190
  // `tools/table.ts` 的 `LEGACY_TOOL_NAME_MAP` 翻译。
123
191
  //
124
192
  // 为什么单独一个工具:注入实况里「这个域注入了几次 / 模型调了几次」都看得到,但模型此前
@@ -127,23 +195,44 @@ export function buildMemoryTools(deps) {
127
195
  // 三个写侧工具共用一句 consent(`Only when the user asks or approves.` / `Only on the
128
196
  // user's instruction.`):这些动的都是"以后每一轮都会带上"的东西,模型不该顺手做。
129
197
  // 描述同时按"省 token"重写了一遍 —— 这几段文字每次请求都要发出去,废话是常驻成本。
130
- // 后半句"freeing the byte budget"删掉(2026-10-15 注入文本审查):byte budget 是本插件
198
+ // 后半句"freeing the byte budget"删掉:byte budget 是本插件
131
199
  // 内部术语,模型据此做不了任何判断 —— "不再被注入"已经是它需要的全部因果。
132
200
  description: 'Enable or disable one memory. Disabled memories stop being injected. Reversible. Only when the user asks or approves.',
133
201
  parameters: {
134
202
  memory: { type: 'string', required: true, description: 'Memory id like <scene>/<name>.' },
135
- enabled: { type: 'boolean', required: true, description: 'true = enable, false = disable; omission is refused.' },
203
+ enabled: { type: 'boolean', required: true, description: 'true = enable, false = disable.' },
204
+ // 默认只改**这个对话**。写全局要显式说明。
205
+ scope: { type: 'string', enum: ['session', 'global'], description: scopeSessionDesc('global = every conversation.') },
136
206
  },
137
207
  output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
138
- async execute(args) {
139
- const blocked = await deps.lockedSceneGuard();
140
- if (blocked)
141
- throw new Error(blocked);
208
+ async execute(args, exec) {
142
209
  const memory = String((args && args.memory) || '');
143
210
  // `enabled` 必须是布尔:`rules-toggle` 缺了它直接拒(ops/memory.ts),但那是给用户看的
144
211
  // 中文 op 错;这里先挡一句说清"这条工具要什么"。
145
212
  if (typeof (args && args.enabled) !== 'boolean')
146
213
  throw new Error('missing argument: enabled must be true or false');
214
+ // 场景锁冻结的是**全局**写入:会话覆盖写的是侧车,与锁无关 ——
215
+ // 与面板的 `scopeWriteLocked()` 同一口径。只有全局那条路才过守卫。
216
+ // 全局粒度下 `effectiveScope` 一律返回 global:那一档没有会话层,写的就是索引本身。
217
+ const scope = effectiveScope(deps, args);
218
+ const sessionOnly = scope === 'session';
219
+ if (!sessionOnly) {
220
+ const blocked = await deps.lockedSceneGuard();
221
+ if (blocked)
222
+ throw new Error(blocked);
223
+ }
224
+ // 默认写**本会话**(别的对话不受影响),`scope: "global"` 才改索引。
225
+ // 会话层只改"注入不注入",不碰索引里那条记录 —— 所以不需要场景档案同步。
226
+ if (sessionOnly) {
227
+ if (!deps.sessionScopeSet)
228
+ throw new Error('per-conversation switches are unavailable in this host: pass scope="global" to change it for every conversation');
229
+ const sc = await deps.sessionScopeSet(exec && exec.agent, 'memory', memory, args.enabled === true);
230
+ if (!sc || sc.ok === false)
231
+ throw new Error((sc && sc.error) || 'failed to switch this memory here');
232
+ return 'OK: ' + memory + ' now ' + (args.enabled ? 'enabled' : 'disabled') + scopeOnlyNote(deps) +
233
+ (sc.cleared === true ? ' (that matches what this scope would see anyway, so the override was removed)' : '') +
234
+ '. ' + globalUnchangedNote(deps) + ' Pass scope="global" to change it for every conversation.';
235
+ }
147
236
  const r = await deps.rulesOps['rules-toggle']({ id: memory, enabled: args.enabled });
148
237
  if (!r || r.ok === false)
149
238
  throw new Error((r && r.error) || 'failed to switch this memory');
@@ -163,34 +252,34 @@ export function buildMemoryTools(deps) {
163
252
  catch {
164
253
  sceneNote = '';
165
254
  }
166
- return 'OK: memory ' + String(rule.id || memory) + ' ' + (rule.enabled === false ? 'disabled' : 'enabled') + sceneNote;
255
+ return 'OK: memory ' + String(rule.id || memory) + ' ' + (rule.enabled === false ? 'disabled' : 'enabled') + sceneNote + isolationOffNote(deps);
167
256
  },
168
257
  }));
169
258
  register(defineTool({
170
259
  name: 'memory_manager_save',
171
- // 「能推导的别记」「先查重」这两句是 0.13.0 加的:记忆是唯一直接吃注入预算的域
260
+ // 「能推导的别记」「先查重」这两句必须有:记忆是唯一直接吃注入预算的域
172
261
  // (场景段 128 KiB),而模型很乐意把「这个项目用 pnpm」记一条 —— 那看一眼 `package.json`
173
262
  // 就知道,记下来却永久占着每一轮请求。合并 write/update 后这两句更要留:upsert 降低了
174
263
  // "再记一条"的摩擦,而摩擦正是这里唯一拦得住它的东西。
175
- description: 'Create a memory, or update the one that already has this id — the receipt says which happened. Memories cost context on EVERY later request, so record only what cannot be re-derived from code, config or git, and check the list for one that already says this — update that instead of adding a near-duplicate. Blocked while the active scene is locked. Only on the user\'s instruction.',
264
+ description: 'Create a memory, or update the one with this id — the receipt says which. Memories cost context on every later request: record only what cannot be re-derived from code, config or git, and update an existing one rather than adding a near-duplicate. Blocked while the active scene is locked. Only on the user\'s instruction.',
176
265
  parameters: {
177
266
  memory: { type: 'string', required: true, description: 'Memory id like <scene>/<name> — copy it from the list. `global` is the always-on scene.' },
178
267
  description: { type: 'string', description: 'One-sentence description (<=500 chars). Required when creating. Empty string = drop it and re-derive from the body; omit = keep.' },
179
268
  body: { type: 'string', description: 'Markdown body (<=256 KiB). Required when creating. Omit to keep the current body.' },
180
- // 不再承诺「旧文件进回收站」(2026-10-14 对抗性审查 P0-3):bundle 记忆改名走的是
269
+ // 不再承诺「旧文件进回收站」:bundle 记忆改名走的是
181
270
  // 「只重写正文、目录不动」那条路,一个字都不进回收站 —— 对 bundle 说进回收站是假话。
182
271
  // 与上一轮 P1-1 同口径:**只说可逆,不说实现细节**。
183
272
  nextName: { type: 'string', description: 'New memory name (= file name); omit to keep it.' },
184
273
  },
185
274
  output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
186
- async execute(args) {
275
+ async execute(args, exec) {
187
276
  const blocked = await deps.lockedSceneGuard();
188
277
  if (blocked)
189
278
  throw new Error(blocked);
190
279
  const memory = String((args && args.memory) || '').trim();
191
280
  // 拆成 `<场景>/<名字>`:要求两段都非空。**不做"没有斜杠就落 global"的兜底** —— 那会把
192
281
  // 一次拼错的 id 变成一条"每轮都注入"的全局记忆,而清单上看起来完全正常。
193
- // 清单里打印的就是 `<场景>/<名字>`,照抄比拼装准(§2 规则一)。
282
+ // 清单里打印的就是 `<场景>/<名字>`,照抄比拼装准。
194
283
  const slash = memory.indexOf('/');
195
284
  if (slash <= 0 || slash === memory.length - 1) {
196
285
  throw new Error('memory must be <scene>/<name> (copy that from the listing; the always-on scene is written global/<name>): ' + (memory || '(empty)'));
@@ -262,17 +351,28 @@ export function buildMemoryTools(deps) {
262
351
  const warn = dup.length
263
352
  ? `\nnote: ${dup.length} existing memories have a similar name or description (${dup.join(', ')}) — if it is the same thing, update that one instead of keeping two.`
264
353
  : '';
265
- // 回执必须同时说清**两个**条件(2026-10-15 smoke-test P1-3):新建的记忆在 op 层是
354
+ // 回执必须同时说清**两个**条件:新建的记忆在 op 层是
266
355
  // `enabled: false`(ops/memory.ts 的 rulesCreate),而原先这句只提场景 —— 读起来像
267
356
  // "场景一开它就自动生效",模型据此以为已经生效,实际还差一次开关。与 skill_manager_save
268
357
  // 的 enableHint 同一形状:点名的工具在出厂默认名单里是关着的,关着就改说"用户开启后"。
358
+ // 「会不会注入」按**本会话**的投影判:会话钉了别的场景时,这条记忆落进的
359
+ // 那个场景在这个对话里根本没开着 —— 照全局口径回一句"打开就能用"是错的答案。
360
+ const scoped = sessionScopeOf(deps, exec && exec.agent);
361
+ const effScene = scoped?.scope?.scene;
362
+ const activeNow = effScene === undefined ? all.activeScene : effScene;
363
+ const activeMode = effScene === undefined ? all.activeMode : 'custom';
269
364
  const sceneActive = group === 'global' ||
270
- (group !== '' && (all.activeMode === 'all' || String(all.activeScene || '') === group));
365
+ (group !== '' && (activeMode === 'all' || String(activeNow || '') === group));
271
366
  const sceneTail = sceneActive ? '' : ', and turn scene "' + group + '" on';
272
- const enableHint = deps.toolVisible('memory_manager_switch')
367
+ // 判据按 **agent**:工具表是每个作用域一份,本作用域把它关掉(或人设 toolsDeny 砍掉)
368
+ // 之后,点名它就是让模型白跑一趟 —— 与 mcp/skill 的 listHint 同一条。
369
+ const enableHint = deps.toolVisibleFor('memory_manager_switch', exec && exec.agent)
273
370
  ? ' (created disabled — turn it on first with memory_manager_switch' + sceneTail + ')'
274
371
  : ' (created disabled — the user has to turn it on first' + sceneTail + ')';
275
- return 'OK: created ' + r.rule.id + enableHint + warn;
372
+ // 会话层:这条记忆写的是**磁盘上的那一份**(所有对话共用),本会话的开关只决定
373
+ // "这里看不看得到"。模型据此回一句"记下了"时,用户很容易读成"只在这个对话里"。
374
+ return 'OK: created ' + r.rule.id + enableHint + warn +
375
+ globalActionNote(deps, exec && exec.agent, 'memory', 'memory');
276
376
  },
277
377
  }));
278
378
  }
@@ -1,25 +1,27 @@
1
- // AGENTS.md 预设域的 model 工具(2026-09-19 从 index.ts 的注册区抽出):
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`(2026-10-15 加)。此前这里写的是
7
+ // 删除在 `tools/remove.ts` 的 `prompt_manager_remove`(加)。此前这里写的是
8
8
  // 「不能造 / **不能删** —— 避免模型乱删用户预设」,那条理由针对的是**不可恢复**的删除:
9
9
  // 预设正文是用户手写的、删了就得重写。回收站把它的前提消掉了 —— 五条 `*_manager_remove`
10
10
  // 一律「进回收站、可恢复、需用户指令、过场景冻结守卫」,永久删除仍只留在面板。
11
11
  // 换句话说:**能删的是可恢复的那一步,不可逆的那一步照旧不给模型。**
12
12
  import { join } from 'node:path';
13
13
  import { normalizePresetDescription } from '../prompts/service.js';
14
- import { text } from './deps.js';
14
+ import { hasPromptOverride } from '../scope/scope-overrides.js';
15
+ import { sessionScopeOf, text } from './deps.js';
16
+ /** 注册提示词域的 model 工具(列表 / 读取 / 应用)。 */
15
17
  export function buildPromptTools(deps) {
16
18
  const { defineTool, register } = deps;
17
19
  register(defineTool({
18
20
  name: 'prompt_manager_list',
19
21
  // 那句 `(that reminder is absent when the preset carries the official instructions line)`
20
- // 删掉(2026-10-15 注入文本审查):模型**观测不到**"official instructions line"这个条件,
22
+ // 删掉:模型**观测不到**"official instructions line"这个条件
21
23
  // 拿它做不了任何决定 —— reminder 在不在,它抬头就能看见,不必由描述来预告。
22
- description: 'List AGENTS.md presets (id, description, active state, file path); read that file for a preset body. The one in effect is in the "Current prompt" reminder, whose "Instructions from:" line names the file. Defaults to the one in effect; all=true for the whole library.',
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.',
23
25
  parameters: {
24
26
  all: { type: 'boolean', description: 'Include inactive presets (default false).' },
25
27
  },
@@ -30,7 +32,7 @@ export function buildPromptTools(deps) {
30
32
  if (!r || r.ok === false)
31
33
  throw new Error((r && r.error) || 'failed to read the AGENTS.md presets');
32
34
  const all = r.presets || [];
33
- // 默认只列「这份 AGENTS.md 来自哪个预设」(用户裁定 2026-09-16)。
35
+ // 默认只列「这份 AGENTS.md 来自哪个预设」。
34
36
  // 判定分两级:`active`(场景驱动时 = 场景绑的那份;否则 = 内容逐字节相同)优先,
35
37
  // 否则看服务层记下的「最近一次应用」—— 用户手改过全局文件时,第二级仍能给出答案,
36
38
  // 不必退化成全列(那会白烧上下文)。
@@ -40,11 +42,11 @@ export function buildPromptTools(deps) {
40
42
  // 三列各有用途:
41
43
  // · 路径 —— 「名单 → 全文」的闭环。预设正文既不进提示词、也没有读取工具,给出文件
42
44
  // 路径让模型用宿主的文件工具读,比再造一个 read 工具省一条常驻 schema。
43
- // · 描述 —— 0.14.0 加的。模型要能在预设之间做选择,而 id 本身不说明用途。描述在
45
+ // · 描述 —— 模型要能在预设之间做选择,而 id 本身不说明用途。描述在
44
46
  // 这里按 `DEFAULT_PRESET_DESC_MAX_LENGTH` 压行截断(与 MCP 备注同一条口径),
45
47
  // 因为它从这一版起是**常驻成本**而不是"只给使用者看"。
46
48
  // · mark —— `activeVia` 必须打出来:`fileApplied` 但场景绑着别的,说明文件里那份
47
- // 已经**不生效**了。0.14.0 之前这里会错报成 [active](那正是被修掉的那句假话)。
49
+ // 已经**不生效**了。原先这里会错报成 [active](那正是被修掉的那句假话)。
48
50
  const summary = shown.map((p) => {
49
51
  const mark = p.active
50
52
  ? (p.activeVia === 'scene' ? ' [active via scene]' : ' [active via file]')
@@ -54,12 +56,20 @@ export function buildPromptTools(deps) {
54
56
  const desc = normalizePresetDescription(p.description);
55
57
  return p.id + mark + ' | ' + (desc || '(no description)') + ' | ' + join(deps.promptsDir, p.id, 'AGENTS.md');
56
58
  });
59
+ // 会话层:提示词**不进**会话域 —— 预设写的是全局基线 ~/.dsh/AGENTS.md,
60
+ // 宿主每轮只读一份。会话能改的是生效场景,而场景绑哪个预设是场景自己的事。
61
+ // 这句只在模型真会读错时才值钱:它会拿这份清单回答「本会话现在用哪份提示词」,
62
+ // 而本会话钉住场景时,答案来自那个场景的绑定,不是这份 active 标记。
63
+ const pinned = sessionScopeOf(deps, exec && exec.agent)?.scope?.scene;
64
+ const sessionLine = pinned === undefined
65
+ ? '\n(prompts are global: this scope has no preset of its own)'
66
+ : '\n(prompts are global; this scope pins scene "' + pinned + '", so the preset in effect here is that scene\'s binding — not necessarily the [active] one below)';
57
67
  const header = 'AGENTS.md presets: ' + (showAll
58
68
  ? all.length + ' in the library'
59
69
  : fallback.length
60
70
  ? fallback.length + (active.length ? ' active' : ' last applied') + ' of ' + all.length +
61
71
  (fallback.length === all.length ? '' : ' (pass all=true for the whole library)')
62
- : '0 active of ' + all.length + ' (pass all=true for the whole library)') + '\n';
72
+ : '0 active of ' + all.length + ' (pass all=true for the whole library)') + sessionLine + '\n';
63
73
  // 同上:AGENTS.md 由官方 dsh-agent-instructions 行承载(极简没挂这一行),
64
74
  // 这一行不在时文件内容不会进上下文。
65
75
  const notice = await deps.reachNoticeForAgent(deps.presetRoster(), exec && exec.agent && exec.agent.ctx, deps.injectNoticeOptions());
@@ -68,9 +78,9 @@ export function buildPromptTools(deps) {
68
78
  }));
69
79
  register(defineTool({
70
80
  name: 'prompt_manager_apply',
71
- description: 'Apply one AGENTS.md preset by id; effective next turn. If a scene drives the baseline this does NOT refuse — it rebinds that scene to the preset and re-syncs it, so tell the user which scene was rebound. A locked scene blocks the call. Pass apply=false to cancel instead — AGENTS.md goes back to what it was before the run of applies (the file is removed if there was none to begin with); a scene driving the baseline refuses that, rebind the scene instead. Only on the user\'s instruction.',
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.',
72
82
  parameters: {
73
- // `id` 从 required 摘掉(2026-10-15 smoke-test P1-5):描述一直写着 "Ignored when
83
+ // `id` 从 required 摘掉:描述一直写着 "Ignored when
74
84
  // apply=false",schema 却把它标成必填 —— 模型照描述「取消不用给 id」操作,先被 schema
75
85
  // 拒掉(missing required property "id"),只能编一个 dummy id 才过得去。条件必填由
76
86
  // execute 里那句守卫表达,与 `skill_manager_switch` 的 enabled / prefer 同一形状。
@@ -78,20 +88,31 @@ export function buildPromptTools(deps) {
78
88
  apply: { type: 'boolean', description: 'Omit or true = apply the preset in `id`; false = cancel — undo the run of applies (no `id` needed).' },
79
89
  },
80
90
  output: { schema: { type: 'string' }, render: (_a, v) => text(v) },
81
- async execute(args) {
91
+ async execute(args, exec) {
82
92
  const blocked = await deps.lockedSceneGuard();
83
93
  if (blocked)
84
94
  throw new Error(blocked);
95
+ // 会话层:提示词永远全局。本会话钉了场景时,这里改的是**那个场景**
96
+ // 的绑定(`applyPresetGuarded` 的 viaScene 分支)—— 别的对话只要没钉同一个场景就不受影响,
97
+ // 但这不是「本会话的提示词」,回执必须按那条路说清。
98
+ // 提示词**不进**会话域,所以这里没有 scope 参数,也**不做**
99
+ // `requireGlobalScope` 守卫:守卫读 `args.scope`,而参数表里
100
+ // 没有这个字段 —— 模型按 schema 不可能传它,守卫只在「模型自己编了一个未声明参数」时
101
+ // 才触发,等于靠运气。留着这行还让 deps.ts 的清单以为这条被守住了。
102
+ // 提示词确实只有全局一层,参数表已经把这件事说完了。
103
+ const scoped = sessionScopeOf(deps, exec && exec.agent);
104
+ const pinned = scoped?.scope?.scene;
85
105
  if (args.apply === false) {
86
106
  // 取消方向:`agentsmd-unapply` 自带两条护栏(场景驱动时拒绝、没有链起点时给确定
87
107
  // 错误码),原样透传。回执要说清恢复成哪种 —— 起点没有文件时是**删文件**,
88
- // 不说的话用户以为 AGENTS.md 还在(0.19.1 界面弹窗报的就是这两种)。
108
+ // 不说的话用户以为 AGENTS.md 还在(界面弹窗报的就是这两种)。
89
109
  const r = await deps.unapplyPreset();
90
110
  if (!r.ok)
91
111
  throw new Error(r.error || 'failed to cancel the application');
92
- return r.removed === true
112
+ return (r.removed === true
93
113
  ? 'OK: application cancelled — ~/.dsh/AGENTS.md did not exist before the run started, so the file was removed (effective next turn).'
94
- : 'OK: application cancelled — ~/.dsh/AGENTS.md is back to what it was before the run started (effective next turn).';
114
+ : 'OK: application cancelled — ~/.dsh/AGENTS.md is back to what it was before the run started (effective next turn).') +
115
+ promptScopeTail(scoped?.scope);
95
116
  }
96
117
  const id = String((args && args.id) || '').trim();
97
118
  if (id === '')
@@ -102,12 +123,55 @@ export function buildPromptTools(deps) {
102
123
  // 场景驱动时写的是「场景绑定」,回执必须说清改的是哪个场景 —— 只说「已应用到
103
124
  // AGENTS.md」会让模型对用户谎报(用户不知道自己的场景绑定被换掉了)。
104
125
  if (r.viaScene) {
105
- return 'OK: preset ' + id + ' is now the prompt binding of scene "' + (r.scene || '') + '" and the scene was re-synced (effective next turn; ~/.dsh/AGENTS.md now carries that scene\'s binding).';
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;
106
143
  }
107
144
  // 生效时机与宿主行为对齐(index.ts 提示词服务一节考证过):dsh-agent-instructions
108
145
  // 每个 pre-step 都 stat 比对版本,写文件即下一轮重读 —— 不是"下个会话"。说错了
109
146
  // 模型会劝用户重开会话,而其实下一句话就已经在新基线下跑。
110
- return 'OK: preset ' + id + ' applied to ~/.dsh/AGENTS.md — effective next turn' + (r.backedUp ? ' (previous backed up to __last-applied__)' : '');
147
+ return 'OK: preset ' + id + ' applied to ~/.dsh/AGENTS.md — effective next turn' + (r.backedUp ? ' (previous backed up to __last-applied__)' : '') +
148
+ // 成功分支也要带尾注:`applyPresetGuarded` 走的是**全局**
149
+ // driver,本会话钉着的场景/会话级覆盖都不在其中 —— 不带的话,模型会照回执说
150
+ // 「提示词已换」,而用户在这个对话里看到的是原来那份。
151
+ promptScopeTail(scoped?.scope);
111
152
  },
112
153
  }));
113
154
  }
155
+ /**
156
+ * 提示词回执的会话尾注(三路:会话覆盖 / 钉住场景 / 无覆盖)。
157
+ *
158
+ * 提示词**不进**会话域:预设写的是全局基线 `~/.dsh/AGENTS.md`,宿主每轮只读一份。
159
+ * 但**生效来源**按会话走 —— 本会话可能钉了场景(`scene-preset`),也可能带会话级
160
+ * 提示词覆盖(`session-preset` / `session-content`),两者都排在 `global-file` 之上。
161
+ * 不说清的话,模型会回一句「提示词已换」,而用户在自己的对话里看到的是别的。
162
+ *
163
+ * 为什么必须三路:`prompt_manager_apply` 走的是**全局** driver(`applyPresetGuarded`),
164
+ * 会话钉的场景不在其中。「全局没有场景 + 本会话钉了场景」是日常形态,而这条路此前
165
+ * 只在 `apply=false` 分支带了尾注,成功分支漏了 —— 用户按回执去验证,必然发现没变。
166
+ */
167
+ function promptScopeTail(scope) {
168
+ if (scope === undefined)
169
+ return '';
170
+ if (hasPromptOverride(scope)) {
171
+ return '\nnote: prompts are global — this changed the machine-wide baseline. This scope carries its own prompt override, so what it gets here stays the same until that override is cleared.';
172
+ }
173
+ const pinned = scope.scene;
174
+ if (pinned === undefined)
175
+ return '';
176
+ return '\nnote: prompts are global — this changed the machine-wide baseline. This scope pins scene "' + pinned + '", so what it actually gets is that scene\'s binding.';
177
+ }