dsh-plugin-agent-memory 0.1.4 → 0.1.6

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/README.md CHANGED
@@ -7,6 +7,10 @@ It adds an **expert selector** to the left of the composer. An *expert* is one a
7
7
  in the Hub; that agent's long-term memories are recalled for each user message and appended to the
8
8
  step as an `<agent-memory>` block, so the model sees them without any tool call.
9
9
 
10
+ The rest of the agent's team assets are available as read-only tools: `am_knowledge_resources`
11
+ (lists wiki and code-graph resources), `am_knowledge_call` (gets a resource's tool list, then runs
12
+ `explore` / `search` / `callers` / `impact` / `read_page` …), `am_skill_search` and `am_skill_read`.
13
+
10
14
  ## Requirements
11
15
 
12
16
  - DSH `>=0.2.2-rc.5` (the plugin declares `dsh.bundle` and a Web client half).
@@ -44,6 +48,8 @@ Open the plugin's settings page (or the panel's gear button) and set:
44
48
  | `writeMemory` | Write each turn's user message back to the expert's memory (default off) |
45
49
  | `topK` | Max memories per recall (1–10, default 4) |
46
50
  | `timeoutMs` | Per-request timeout (default 6000) |
51
+ | `kernelUrl` | Kernel API base for wiki / code-graph / skills (default: Hub host on port 8420) |
52
+ | `tools` | Register the four read-only asset tools (default on) |
47
53
  | `debug` | Append diagnostics to `~/.dsh/agent-memory-debug.log` (default off, 256 KiB cap) |
48
54
 
49
55
  With no `hubUrl` or `userKey` the plugin stays idle: the selector is hidden and nothing is sent.
package/client.js CHANGED
@@ -283,7 +283,7 @@ window.__ModuleLoader__.load({
283
283
  .catch((failure) => setError(String(failure.message ?? failure)));
284
284
  }, [sessionId]);
285
285
 
286
- const label = selection ? `专家:${selection.agentName}` : '选择专家';
286
+ const label = selection ? `专家:${selection.agentName}` : '请选择专家';
287
287
  const healthColor =
288
288
  health.state === 'ok' ? '#2e7d32' : health.state === 'bad' ? '#c0392b' : 'rgba(128,128,128,0.85)';
289
289
 
@@ -302,17 +302,32 @@ window.__ModuleLoader__.load({
302
302
  }
303
303
  },
304
304
  },
305
- h('span', {
306
- style: {
307
- width: '6px',
308
- height: '6px',
309
- borderRadius: '50%',
310
- flex: '0 0 auto',
311
- background: selection
312
- ? 'var(--dsw-alias-accent, #247bbf)'
313
- : 'var(--dsw-alias-border-subtle, rgba(128,128,128,0.5))',
305
+ h(
306
+ 'svg',
307
+ {
308
+ width: 13,
309
+ height: 13,
310
+ viewBox: '0 0 16 16',
311
+ 'aria-hidden': true,
312
+ style: {
313
+ flex: '0 0 auto',
314
+ color: selection
315
+ ? 'var(--dsw-alias-accent, #247bbf)'
316
+ : 'var(--dsw-alias-text-secondary, currentColor)',
317
+ },
314
318
  },
315
- }),
319
+ h('path', {
320
+ d: 'M6.6 3.6 9.4 3.1 M4.9 6.3 7.3 9.2 M10.9 5.2 9.1 9.1',
321
+ stroke: 'currentColor',
322
+ strokeWidth: 1.1,
323
+ strokeLinecap: 'round',
324
+ fill: 'none',
325
+ opacity: 0.75,
326
+ }),
327
+ h('circle', { cx: 4.6, cy: 5, r: 2, fill: 'currentColor' }),
328
+ h('circle', { cx: 11.6, cy: 4.2, r: 1.6, fill: 'currentColor', opacity: 0.8 }),
329
+ h('circle', { cx: 8.2, cy: 11, r: 2.2, fill: 'currentColor', opacity: 0.95 }),
330
+ ),
316
331
  h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, label),
317
332
  );
318
333
 
package/docs/DETAIL.md CHANGED
@@ -5,8 +5,9 @@
5
5
  ## 用法
6
6
 
7
7
  1. 在对话框工具行左侧点「选择专家」,展开后点右上角「设置」,直接填 `Hub 地址`、`实例 ID`、`Userkey` 并点「检测连接」;保存后写入本 profile 的 `cordis.patch.yml`(也可以手改该行)。
8
- 2. 「设置」旁边的「返回列表」回到团队 / agent 列表,先选团队,再选 agent;选中的专家记录在当前会话上。
8
+ 2. 「设置」旁边的「返回列表」回到团队 / agent 列表,先选团队,再选 agent;选中的专家记录在当前会话上。未选择时按钮显示「请选择专家」,且不注入任何记忆——需要默认专家时把 `defaultAgentId` 填上即可。
9
9
  3. 每轮对话开始时,Host 半侧会用该 agent 的记忆块做检索(L3 / L2 / L1 / L0 依次尝试),把命中的记忆以 `<agent-memory>` 段落追加到该 step 的消息里,模型因此能看到专家的长期记忆。
10
+ 4. 同一份团队资产还能按需取用:插件注册了 4 个只读工具 —— `am_knowledge_resources`(列出 wiki / code-graph 资源)、`am_knowledge_call`(先取该资源的工具清单,再执行 explore / search / callers / impact / read_page 等)、`am_skill_search`(检索技能)、`am_skill_read`(读技能正文)。工具默认绑定当前会话选中的专家所在团队。
10
11
 
11
12
  ## 配置项
12
13
 
@@ -20,6 +21,8 @@
20
21
  | `writeMemory` | 打开后每轮结束时把该轮用户消息写回专家记忆块(插件默认关闭,本实例安装配置里已开启) |
21
22
  | `topK` | 每层最多取回的记忆条数(1–10) |
22
23
  | `timeoutMs` | 单次 Hub 请求超时 |
24
+ | `kernelUrl` | 内核 API 地址(知识库 / code-graph / 技能),默认按 Hub 主机名 + `8420` 推断;显式填写更稳妥 |
25
+ | `tools` | 是否注册上述 4 个资产工具(默认开) |
23
26
  | `debug` | 是否写诊断日志(默认关) |
24
27
 
25
28
  Host 半侧导出了 `z.object` 形式的 `Config`(`userKey` 标了 `role('secret')`),因此插件详情页也能看到同名字段的表单;字段保存走框架的 `configEditor`,写入后提示重启插件以重建内存状态。
@@ -31,6 +34,8 @@ Host 半侧导出了 `z.object` 形式的 `Config`(`userKey` 标了 `role('sec
31
34
  - 只允许选中自己的 agent(`owner_user_id` 必须等于当前 user key 的用户);他人 agent 的选择请求返回 403 `NOT_YOUR_AGENT`,因为记忆块读写都会被 Hub 拒绝。
32
35
  - 写回时会丢掉运行期注入的噪声文本(子 agent 完成通知、审批策略变更通知、计划任务消息、技能注入),否则这些模板文字会污染记忆。
33
36
  - Hub 没有可用的按条删除路由(`chat-memory/clear` 恒返回 `BLOCK_NOT_FOUND`),写错的记忆只能在记忆管理界面清理。
34
- - 团队与 agent 列表缓存 5 分钟。
37
+ - 团队与 agent 列表有缓存,默认 10 秒(`refreshMs`),选择器按同一间隔自动刷新。
38
+ - 资产工具只读:知识库 / code-graph 走知识服务的 `tools/list` + `tools/call`,技能走内核 `/v3/skill/*`;user key 只在 Host 里加进请求头,不进 prompt、不进浏览器。
39
+ - code-graph 是分支快照,需要某段代码此刻的精确内容时应读工作区源码;插件在工具描述里也这样要求模型。
35
40
  - 插件自带 `GET /plugins/agent-memory/health`(回连 Hub 校验 userkey 并汇总团队 / agent 数)与 `POST /plugins/agent-memory/config`(保存设置);两条路由都只接受回环地址来源的浏览器请求,跨站请求返回 403。
36
41
  - 诊断日志写入 `~/.dsh/agent-memory-debug.log`(单个文件上限 256 KB),需 `debug: true` 才开启。
package/index.js CHANGED
@@ -44,6 +44,11 @@ export const Config = z.object({
44
44
  .step(1000)
45
45
  .default(DEFAULT_REFRESH_MS)
46
46
  .description('团队/agent 列表缓存与选择器自动刷新的间隔(毫秒,默认 10 秒)'),
47
+ kernelUrl: z
48
+ .string()
49
+ .default('')
50
+ .description('内核 API 地址(知识库 / code-graph / 技能),例如 http://memhub.example.com:8420;留空则按 Hub 主机名 + 8420 推断'),
51
+ tools: z.boolean().default(true).description('向模型提供知识库 / code-graph / 技能三类只读工具'),
47
52
  debug: z.boolean().default(false).description('把召回/写回诊断写入 ~/.dsh/agent-memory-debug.log'),
48
53
  });
49
54
 
@@ -99,10 +104,15 @@ function normalizeConfig(config) {
99
104
  topK: Number.isFinite(value.topK) ? Math.max(1, Math.min(10, value.topK)) : 4,
100
105
  timeoutMs: Number.isFinite(value.timeoutMs) ? Math.max(1000, value.timeoutMs) : 6000,
101
106
  refreshMs: Number.isFinite(value.refreshMs) ? Math.max(3000, Math.min(600000, value.refreshMs)) : DEFAULT_REFRESH_MS,
107
+ kernelUrl: typeof value.kernelUrl === 'string' ? value.kernelUrl.trim().replace(/\/+$/, '') : '',
108
+ tools: value.tools !== false,
102
109
  debug: value.debug === true,
103
110
  };
104
111
  }
105
112
 
113
+ /** `ctx.tools` is a hard dependency: property access without this declaration throws at activation. */
114
+ export const inject = ['tools'];
115
+
106
116
  export function apply(ctx, config) {
107
117
  const settings = normalizeConfig(config);
108
118
  // A published bundle ships no Hub address or key, so an unconfigured install must still
@@ -123,6 +133,7 @@ export function apply(ctx, config) {
123
133
  identity: null,
124
134
  selections: new Map(),
125
135
  blocks: new Map(),
136
+ assets: new Map(),
126
137
  lastInjection: new Map(),
127
138
  lastUser: new Map(),
128
139
  };
@@ -272,6 +283,148 @@ export function apply(ctx, config) {
272
283
  return lines.join('\n');
273
284
  }
274
285
 
286
+ /** Kernel base: explicit config wins, otherwise the Hub host on the kernel port (8420). */
287
+ function kernelBase() {
288
+ if (settings.kernelUrl !== '') return settings.kernelUrl;
289
+ try {
290
+ const hub = new URL(settings.hubUrl);
291
+ return `${hub.protocol}//${hub.hostname}:8420`;
292
+ } catch {
293
+ return '';
294
+ }
295
+ }
296
+
297
+ async function kernel(path, body) {
298
+ const base = kernelBase();
299
+ if (base === '') throw new Error('内核地址未配置:请在插件设置里填 kernelUrl');
300
+ if (settings.userKey === '') throw new Error('Memory Hub userkey 未配置:请在插件设置里填 userKey');
301
+ const response = await fetch(`${base}${path}`, {
302
+ method: 'POST',
303
+ headers: { ...headers, Authorization: `Bearer ${settings.userKey}` },
304
+ body: JSON.stringify(body ?? {}),
305
+ signal: AbortSignal.timeout(settings.timeoutMs * 2),
306
+ });
307
+ const payload = await response.json().catch(() => null);
308
+ if (payload === null || typeof payload !== 'object') throw new Error(`kernel ${path}: unreadable response`);
309
+ if (payload.code !== 0) throw new Error(`kernel ${path}: ${payload.message ?? `code ${payload.code}`}`);
310
+ return payload.data ?? {};
311
+ }
312
+
313
+ /** The knowledge service routes tenants by `x-tdai-service-id` only; the user key stays here. */
314
+ async function knowledgeService(serviceUrl, path, body) {
315
+ const response = await fetch(`${String(serviceUrl).replace(/\/+$/, '')}${path}`, {
316
+ method: 'POST',
317
+ headers: { 'x-tdai-service-id': settings.instanceId, 'Content-Type': 'application/json' },
318
+ body: JSON.stringify(body ?? {}),
319
+ signal: AbortSignal.timeout(settings.timeoutMs * 3),
320
+ });
321
+ const payload = await response.json().catch(() => null);
322
+ if (payload === null || typeof payload !== 'object') throw new Error(`knowledge ${path}: unreadable response`);
323
+ if (payload.code !== undefined && payload.code !== 0) {
324
+ throw new Error(`knowledge ${path}: ${payload.message ?? `code ${payload.code}`}`);
325
+ }
326
+ return payload.data ?? {};
327
+ }
328
+
329
+ async function knowledgeResources(teamId) {
330
+ const key = `knowledge:${teamId}`;
331
+ const cached = state.assets.get(key);
332
+ if (cached !== undefined && Date.now() - cached.at < settings.refreshMs * 6) return cached.items;
333
+ const data = await kernel('/v3/knowledge/list', { team_id: teamId, pagination: { limit: 200 } });
334
+ const items = (Array.isArray(data.items) ? data.items : []).filter(
335
+ (item) =>
336
+ item &&
337
+ typeof item.knowledge_id === 'string' &&
338
+ typeof item.service_url === 'string' &&
339
+ item.service_url !== '',
340
+ );
341
+ state.assets.set(key, { at: Date.now(), items });
342
+ return items;
343
+ }
344
+
345
+ async function skillSearch(teamId, query, topK) {
346
+ const data = await kernel('/v3/skill/search', {
347
+ team_id: teamId,
348
+ query,
349
+ top_k: Math.max(1, Math.min(50, topK)),
350
+ mode: 'hybrid',
351
+ });
352
+ return Array.isArray(data.items) ? data.items : [];
353
+ }
354
+
355
+ async function skillGet(teamId, skillId) {
356
+ return kernel('/v3/skill/get', { team_id: teamId, skill_id: skillId, include_content: true });
357
+ }
358
+
359
+ /** Tools run under the session's selected expert; without one they fall back to the first team. */
360
+ async function toolScope(exec) {
361
+ const sessionId = String(exec?.agent?.id ?? '');
362
+ const selection = sessionId === '' ? null : await selectionFor(sessionId);
363
+ if (selection !== null) return selection;
364
+ const known = await teams();
365
+ const first = known[0];
366
+ if (first === undefined) throw new Error('当前 userkey 下没有可见团队');
367
+ return { teamId: first.team_id, teamName: first.name, agentId: settings.defaultAgentId, agentName: '' };
368
+ }
369
+
370
+ const TOOL_TEXT_LIMIT = 12000;
371
+
372
+ function clip(text) {
373
+ return text.length > TOOL_TEXT_LIMIT
374
+ ? `${text.slice(0, TOOL_TEXT_LIMIT)}\n…(已截断,原文 ${text.length} 字符)`
375
+ : text;
376
+ }
377
+
378
+ function knowledgeListText(selection, items, options = {}) {
379
+ const kind = options.kind === 'wiki' || options.kind === 'code-graph' ? options.kind : '';
380
+ const needle = String(options.filter ?? '').trim().toLowerCase();
381
+ let picked = items;
382
+ if (kind === 'wiki') picked = picked.filter((item) => item.type !== 'code-graph');
383
+ if (kind === 'code-graph') picked = picked.filter((item) => item.type === 'code-graph');
384
+ if (needle !== '') {
385
+ picked = picked.filter((item) => `${item.name} ${item.repo_url ?? ''}`.toLowerCase().includes(needle));
386
+ }
387
+ if (picked.length === 0) {
388
+ return `团队「${selection.teamName}」没有匹配的知识资源(kind=${kind || '全部'} filter=${needle || '无'})。`;
389
+ }
390
+ const wikis = picked.filter((item) => item.type !== 'code-graph');
391
+ const graphs = picked.filter((item) => item.type === 'code-graph');
392
+ const lines = [`团队「${selection.teamName}」的知识资源(用 am_knowledge_call 读取):`];
393
+ if (wikis.length > 0) {
394
+ lines.push('wiki:');
395
+ for (const item of wikis) {
396
+ const about =
397
+ typeof item.summary === 'string' && item.summary !== ''
398
+ ? ` — ${item.summary.replace(/\s+/g, ' ').slice(0, 160)}`
399
+ : '';
400
+ lines.push(`- ${item.knowledge_id} ${item.name}${about}`);
401
+ }
402
+ }
403
+ if (graphs.length > 0) {
404
+ // The team can hold dozens of repositories; show a slice and let the model filter.
405
+ const shown = needle === '' ? graphs.slice(0, 20) : graphs;
406
+ lines.push(`code-graph(${graphs.length} 个仓库;repo 与当前工作区一致时才值得查):`);
407
+ for (const item of shown) {
408
+ lines.push(`- ${item.knowledge_id} ${item.name} (${item.branch ?? 'main'}) ${item.repo_url ?? ''}`.trim());
409
+ }
410
+ if (shown.length < graphs.length) {
411
+ lines.push(`…另有 ${graphs.length - shown.length} 个仓库未列出,传 filter 按仓库名过滤。`);
412
+ }
413
+ }
414
+ return lines.join('\n');
415
+ }
416
+
417
+ function toolsListText(resource, data) {
418
+ const tools = Array.isArray(data.tools) ? data.tools : [];
419
+ if (tools.length === 0) return `资源「${resource.name}」(${resource.type})没有可用工具。`;
420
+ const lines = [`资源「${resource.name}」(${resource.type})的可用工具:`];
421
+ for (const tool of tools) {
422
+ lines.push(`- ${tool.name}: ${String(tool.description ?? '').replace(/\s+/g, ' ').slice(0, 200)}`);
423
+ if (tool.params !== undefined) lines.push(` params: ${JSON.stringify(tool.params)}`);
424
+ }
425
+ return lines.join('\n');
426
+ }
427
+
275
428
  ctx.effect(() => {
276
429
  const listener = async function (payload, next) {
277
430
  debug({ at: 'pre-step-enter', agent: String(payload?.agent?.id ?? '') });
@@ -357,6 +510,160 @@ export function apply(ctx, config) {
357
510
  return () => off();
358
511
  }, 'agent-memory: memory write-back');
359
512
 
513
+ /**
514
+ * Read-only asset tools. Knowledge (wiki / code-graph) goes through the knowledge
515
+ * service's own `tools/list` + `tools/call` protocol, so new server-side tools appear
516
+ * without a plugin release; skills go through the kernel skill API.
517
+ */
518
+ ctx.effect(() => {
519
+ if (settings.tools !== true || !configured) return () => {};
520
+ const tools = ctx.tools;
521
+ if (tools === undefined || typeof tools.register !== 'function') {
522
+ ctx.logger?.warn?.('[agent-memory] tools service unavailable; asset tools not registered');
523
+ return () => {};
524
+ }
525
+ const textOutput = { schema: { type: 'string' }, render: (_args, text) => [{ type: 'text', text }] };
526
+ const disposers = [];
527
+ disposers.push(
528
+ tools.register({
529
+ name: 'am_knowledge_resources',
530
+ description:
531
+ '列出当前团队 agent-memory 的知识资源:code-graph(仓库的预建代码索引:符号/调用图/结构)与 wiki(工程设计文档)。code-graph 的 repo 与你当前工作区一致时才值得查;wiki 与工作区无关,按 about 判断相关性。拿到 id 后用 am_knowledge_call 读取。',
532
+ parameters: {
533
+ type: 'object',
534
+ properties: {
535
+ kind: { type: 'string', enum: ['wiki', 'code-graph'], description: '只看某一类资源;省略则两类都列。' },
536
+ filter: { type: 'string', description: '按资源名或仓库地址做子串过滤,例如 minmetals-ui。' },
537
+ },
538
+ additionalProperties: false,
539
+ },
540
+ output: textOutput,
541
+ isConcurrencySafe: () => true,
542
+ async execute(args, exec) {
543
+ const scope = await toolScope(exec);
544
+ const items = await knowledgeResources(scope.teamId);
545
+ return knowledgeListText(scope, items, args ?? {});
546
+ },
547
+ }),
548
+ );
549
+ disposers.push(
550
+ tools.register({
551
+ name: 'am_knowledge_call',
552
+ description:
553
+ '调用 agent-memory 知识资源上的工具。省略 tool 时返回该资源可用的工具清单(含参数);给出 tool 时执行它。code-graph 适合跨文件结构、调用链、影响面、定位实现等问题(explore/search/callers/callees/impact/node/files);wiki 适合设计意图、背景、团队约定等问题(search/read_page/list_pages)。索引是分支快照,需要某段代码此刻的精确内容时请读工作区源码。',
554
+ parameters: {
555
+ type: 'object',
556
+ properties: {
557
+ knowledge_id: { type: 'string', description: '资源 id,来自 am_knowledge_resources(如 cg-xxx / wiki-xxx)。' },
558
+ tool: { type: 'string', description: '工具名,必须与工具清单里的 name 完全一致;省略则只返回清单。' },
559
+ params: { type: 'object', description: '工具参数对象,无参传 {}。' },
560
+ },
561
+ required: ['knowledge_id'],
562
+ additionalProperties: false,
563
+ },
564
+ output: textOutput,
565
+ isConcurrencySafe: () => true,
566
+ async execute(args, exec) {
567
+ const scope = await toolScope(exec);
568
+ const knowledgeId = String(args.knowledge_id ?? '').trim();
569
+ if (knowledgeId === '') throw new Error('knowledge_id 不能为空');
570
+ const items = await knowledgeResources(scope.teamId);
571
+ const resource = items.find((item) => item.knowledge_id === knowledgeId);
572
+ if (resource === undefined) {
573
+ throw new Error(`未知的 knowledge_id:${knowledgeId}(先用 am_knowledge_resources 查看)`);
574
+ }
575
+ const serviceUrl = String(resource.service_url ?? '');
576
+ if (serviceUrl === '') throw new Error('该资源没有 service_url,无法调用');
577
+ const tool = typeof args.tool === 'string' ? args.tool.trim() : '';
578
+ if (tool === '') {
579
+ const data = await knowledgeService(serviceUrl, '/tools/list', { knowledge_id: knowledgeId });
580
+ return clip(toolsListText(resource, data));
581
+ }
582
+ const data = await knowledgeService(serviceUrl, '/tools/call', {
583
+ knowledge_id: knowledgeId,
584
+ tool_name: tool,
585
+ params: args.params ?? {},
586
+ });
587
+ if (typeof data.text === 'string') return clip(data.text);
588
+ return clip(JSON.stringify(data, null, 2));
589
+ },
590
+ }),
591
+ );
592
+ disposers.push(
593
+ tools.register({
594
+ name: 'am_skill_search',
595
+ description:
596
+ '在团队的 agent-memory 技能库(skill)里检索可复用技能,返回 skill_id、名称与描述。命中后用 am_skill_read 读取正文并按其步骤执行。',
597
+ parameters: {
598
+ type: 'object',
599
+ properties: {
600
+ query: { type: 'string', description: '检索关键词,例如 code review、单元测试、发布流程。' },
601
+ top_k: { type: 'number', description: '返回条数,1-20,默认 5。' },
602
+ },
603
+ required: ['query'],
604
+ additionalProperties: false,
605
+ },
606
+ output: textOutput,
607
+ isConcurrencySafe: () => true,
608
+ async execute(args, exec) {
609
+ const query = String(args.query ?? '').trim();
610
+ if (query === '') throw new Error('query 不能为空');
611
+ const topK = Number.isFinite(args.top_k) ? args.top_k : 5;
612
+ const scope = await toolScope(exec);
613
+ const hits = await skillSearch(scope.teamId, query, topK);
614
+ if (hits.length === 0) return `团队「${scope.teamName}」的技能库里没有匹配「${query}」的技能。`;
615
+ return hits
616
+ .map(
617
+ (hit, index) =>
618
+ `${index + 1}. ${hit.name} (id=${hit.skill_id}, v${hit.version ?? '?'})\n ${String(hit.description ?? '').replace(/\s+/g, ' ')}`,
619
+ )
620
+ .join('\n');
621
+ },
622
+ }),
623
+ );
624
+ disposers.push(
625
+ tools.register({
626
+ name: 'am_skill_read',
627
+ description:
628
+ '读取 agent-memory 技能库里某个 skill 的完整正文(Markdown,含 frontmatter 说明与执行步骤)。参数可传 skill_id(skl-...)或技能名。',
629
+ parameters: {
630
+ type: 'object',
631
+ properties: {
632
+ skill: { type: 'string', description: 'skill_id(skl-...)或技能名,例如 code-review。' },
633
+ },
634
+ required: ['skill'],
635
+ additionalProperties: false,
636
+ },
637
+ output: textOutput,
638
+ isConcurrencySafe: () => true,
639
+ async execute(args, exec) {
640
+ let skillId = String(args.skill ?? '').trim();
641
+ if (skillId === '') throw new Error('skill 不能为空');
642
+ const scope = await toolScope(exec);
643
+ if (!skillId.startsWith('skl-')) {
644
+ const hits = await skillSearch(scope.teamId, skillId, 10);
645
+ const match = hits.find((hit) => hit.name === skillId) ?? hits[0];
646
+ if (match === undefined) throw new Error(`团队「${scope.teamName}」的技能库里没有匹配「${skillId}」的技能`);
647
+ skillId = String(match.skill_id);
648
+ }
649
+ const data = await skillGet(scope.teamId, skillId);
650
+ const content = typeof data.content === 'string' ? data.content : '';
651
+ if (content === '') return `技能 ${data.name ?? skillId} 没有正文内容。`;
652
+ return clip(`# 技能 ${data.name ?? skillId}(id=${skillId} v${data.version ?? '?'})\n\n${content}`);
653
+ },
654
+ }),
655
+ );
656
+ return () => {
657
+ for (const dispose of disposers) {
658
+ try {
659
+ dispose();
660
+ } catch {
661
+ /* unregistering is best effort */
662
+ }
663
+ }
664
+ };
665
+ }, 'agent-memory: asset tools');
666
+
360
667
  const webServer = ctx.get('webServer');
361
668
  if (webServer === undefined) {
362
669
  ctx.logger?.warn?.('[agent-memory] webServer service unavailable; the composer selector stays hidden');
@@ -466,6 +773,8 @@ export function apply(ctx, config) {
466
773
  writeMemory: settings.writeMemory,
467
774
  topK: settings.topK,
468
775
  refreshMs: settings.refreshMs,
776
+ kernelUrl: kernelBase(),
777
+ tools: settings.tools,
469
778
  debug: settings.debug,
470
779
  },
471
780
  });
@@ -556,9 +865,8 @@ export function apply(ctx, config) {
556
865
  if (typeof body.userKey === 'string' && body.userKey.trim() !== '') {
557
866
  patch.userKey = body.userKey.trim();
558
867
  }
559
- if (typeof body.defaultAgentId === 'string' && body.defaultAgentId.trim() !== '') {
560
- patch.defaultAgentId = body.defaultAgentId.trim();
561
- }
868
+ // An empty string clears the default expert, so the composer starts at 「请选择专家」.
869
+ if (typeof body.defaultAgentId === 'string') patch.defaultAgentId = body.defaultAgentId.trim();
562
870
  if (typeof body.injectMemory === 'boolean') patch.injectMemory = body.injectMemory;
563
871
  if (typeof body.writeMemory === 'boolean') patch.writeMemory = body.writeMemory;
564
872
  if (Number.isFinite(body.topK)) patch.topK = Math.max(1, Math.min(10, body.topK));
@@ -567,6 +875,8 @@ export function apply(ctx, config) {
567
875
  patch.refreshMs = Math.max(3000, Math.min(600000, body.refreshMs));
568
876
  }
569
877
  if (typeof body.debug === 'boolean') patch.debug = body.debug;
878
+ if (typeof body.kernelUrl === 'string') patch.kernelUrl = body.kernelUrl.trim().replace(/\/+$/, '');
879
+ if (typeof body.tools === 'boolean') patch.tools = body.tools;
570
880
  if (Object.keys(patch).length === 0) {
571
881
  reply(response, 400, { error: 'no editable field in request' });
572
882
  return;
@@ -726,4 +1036,5 @@ export function apply(ctx, config) {
726
1036
  }),
727
1037
  'agent-memory: preview route',
728
1038
  );
1039
+
729
1040
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "dsh-plugin-agent-memory",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
- "description": "Tencent agent-memory integration: pick a team agent as an expert at the composer and its long-term memories are recalled into each turn.",
5
+ "description": "Tencent agent-memory integration: pick a team agent as an expert at the composer, recall its memories into each turn, and expose its wiki, code-graph and skill assets as tools.",
6
6
  "license": "MIT",
7
7
  "keywords": [
8
8
  "dsh-plugin",