dsh-plugin-tool-management 0.22.1 → 0.22.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.
@@ -1,5 +1,6 @@
1
1
  import { catalogInjectedAt, CONTINUABLE_MARK } from './service.js';
2
2
  import { subagentDepthOf } from '../context-inject.js';
3
+ import { CATALOG_CAP_DEFAULTS } from '../catalog-caps.js';
3
4
  import { filterBySceneBinding } from './tools.js';
4
5
  /**
5
6
  * 描述截断长度 —— 照抄官方技能目录的默认值
@@ -9,9 +10,9 @@ import { filterBySceneBinding } from './tools.js';
9
10
  * 而且这是官方旋钮的默认值,不是本插件拍脑袋定的数。日后 token 成本成为问题时,
10
11
  * 官方对应的旋钮是 `catalogDescriptionMaxLength`。
11
12
  */
12
- export const DEFAULT_CATALOG_DESCRIPTION_MAX_LENGTH = 500;
13
+ export const DEFAULT_CATALOG_DESCRIPTION_MAX_LENGTH = CATALOG_CAP_DEFAULTS.subagentsDescription;
13
14
  /** 段里最多列几个人设;超出部分只报数量,让模型自己去调 subagent_manager_list。 */
14
- export const DEFAULT_CATALOG_MAX_ENTRIES = 50;
15
+ export const DEFAULT_CATALOG_MAX_ENTRIES = CATALOG_CAP_DEFAULTS.subagents;
15
16
  /** 无描述时的占位,与 `subagent_manager_list` 工具的输出保持同一口径。 */
16
17
  const NO_DESCRIPTION = '(no description)';
17
18
  /**
@@ -59,10 +60,11 @@ export function renderSubagentCatalog(allowed, maxEntries = DEFAULT_CATALOG_MAX_
59
60
  // 「确认一遍」去调它(没列出来的就是当前不想要的)。与 MCP 状态段的
60
61
  // `(${N} more not listed.)` 同一句式,但这里多给一个出口——不给人设就真的找不回来了。
61
62
  if (hidden > 0) {
62
- // 与技能目录同一条纪律:点名一个被关掉的工具只会让模型去猜名字。数量照报。
63
+ // 与技能目录同一条纪律:点名一个被关掉的工具只会让模型去猜名字。数量照报,
64
+ // 再补一句可转告的事实 —— 工具是关着的、用户能开(折叠行只在真被截掉时出现)。
63
65
  out.push('', listToolVisible
64
66
  ? `(${hidden} more not listed — see them with \`subagent_manager_list\`.)`
65
- : `(${hidden} more not listed.)`);
67
+ : `(${hidden} more not listed — the listing tool is disabled in this session; ask the user to enable it.)`);
66
68
  }
67
69
  return out.join('\n');
68
70
  }
@@ -73,17 +75,19 @@ export function renderSubagentCatalog(allowed, maxEntries = DEFAULT_CATALOG_MAX_
73
75
  * 会让模型突然「忘记」有哪些人设。
74
76
  */
75
77
  export function createSubagentCatalog(deps, opts = {}) {
76
- const maxEntries = opts.maxEntries ?? DEFAULT_CATALOG_MAX_ENTRIES;
77
- const maxDescription = opts.maxDescription ?? DEFAULT_CATALOG_DESCRIPTION_MAX_LENGTH;
78
+ const maxEntriesDefault = DEFAULT_CATALOG_MAX_ENTRIES;
79
+ const maxDescriptionDefault = DEFAULT_CATALOG_DESCRIPTION_MAX_LENGTH;
78
80
  const ttlMs = opts.ttlMs ?? 1000;
79
81
  const now = opts.now ?? (() => Date.now());
82
+ /** 函数式上限求值(兼容页的设置每次渲染现取;静态值原样返回)。 */
83
+ const resolveCap = (value) => typeof value === 'function' ? value() : value;
80
84
  let docs = [];
81
85
  let globalSceneLists = [];
82
86
  /** 全局口径的可见集合(正在用的场景绑定 ∩ 全局启停)—— 每次重算从 docs 推一次。 */
83
87
  let globalAllowed = new Set();
84
88
  let loadedAt = Number.NEGATIVE_INFINITY;
85
89
  let inflight = null;
86
- // 渲染结果按**深度 + 尾句前提 + 会话层指纹**缓存:过滤只依赖这三样。
90
+ // 渲染结果按**深度 + 尾句前提 + 会话层指纹 + 两个上限**缓存:过滤与排版只依赖这四样。
87
91
  const rendered = new Map();
88
92
  const recompute = async () => {
89
93
  try {
@@ -132,11 +136,15 @@ export function createSubagentCatalog(deps, opts = {}) {
132
136
  void revalidate();
133
137
  const depth = subagentDepthOf(agent);
134
138
  const visible = deps.listToolVisible ? deps.listToolVisible(agent) : true;
139
+ // 上限每次渲染现取(设置有 TTL 缓存,这里只是转发);缺省回落厂值。
140
+ const maxEntries = resolveCap(opts.maxEntries) ?? maxEntriesDefault;
141
+ const maxDescription = resolveCap(opts.maxDescription) ?? maxDescriptionDefault;
135
142
  const hasLayer = deps.flagFor !== undefined && deps.flagFor(agent) !== undefined;
136
143
  // 有会话层但装配层没给指纹(老装配 / 测试)时不走渲染缓存:宁可多算一次。
137
144
  const cacheable = !hasLayer || deps.layerKeyFor !== undefined;
138
145
  const layerKey = deps.layerKeyFor ? deps.layerKeyFor(agent) : '';
139
- const key = layerKey + '\u0000' + depth + '|' + (visible ? '1' : '0');
146
+ // 缓存键必须带上两个上限:改了设置而键没变的话,渲染缓存会一直发旧文本。
147
+ const key = layerKey + '\u0000' + depth + '|' + (visible ? '1' : '0') + '\u0000' + maxEntries + '\u0000' + maxDescription;
140
148
  if (cacheable) {
141
149
  const cached = rendered.get(key);
142
150
  if (cached !== undefined)
@@ -143,8 +143,8 @@ export function createToolTableSwitch(deps) {
143
143
  // ——覆盖它等于把用户原来的选择彻底洗掉(没有取证通道)。
144
144
  if (toolTableStateValue === 'unknown')
145
145
  return { ok: false, error: toolTableRefuseMessage() };
146
- // 落盘在写锁里,落完**出了锁**再刷新(`withWriteLock` 是一条不可重入的链:锁里再调
147
- // 一次会等自己,直接卡死)。刷新是两处目录读,本来也不必占着写锁。
146
+ // 落盘在写锁里,落完**出了锁**再刷新:刷新是两处目录读,不必占着写锁拉长其它写者的
147
+ // 等待(锁可重入,但代价是重入方也一起变慢)。
148
148
  return deps.withWriteLock(async () => await writeToolTableSettingsLocked(next));
149
149
  }
150
150
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-tool-management",
3
- "version": "0.22.1",
3
+ "version": "0.22.3",
4
4
  "description": "一个设置面板,统一管理 MCP、技能、记忆、子智能体、提示词和归档会话;可自定义搭配场景,一个场景即可切换整个环境;Agent也能帮你操作这个插件。",
5
5
  "repository": {
6
6
  "type": "git",