@asd2233996/dsh-auto-context 0.0.0-stage → 1.15.0
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/LICENSE +21 -0
- package/README.en.md +113 -0
- package/README.md +250 -2
- package/cordis.patch.yml +23 -0
- package/docs/product-introduction.md +282 -0
- package/docs/structured-kb-notes.md +179 -0
- package/lib/actions.js +2758 -0
- package/lib/extract.js +1647 -0
- package/lib/graph.js +1628 -0
- package/lib/groups.js +307 -0
- package/lib/impl.js +170 -0
- package/lib/index.js +43 -0
- package/lib/kb-tools.js +384 -0
- package/lib/kb.js +254 -0
- package/lib/kg-archive.js +1042 -0
- package/lib/kg-store.js +1427 -0
- package/lib/recall.js +62 -0
- package/lib/scan.js +2537 -0
- package/lib/segments.js +660 -0
- package/lib/store.js +365 -0
- package/lib/util.js +64 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +87 -4
package/lib/recall.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* context-manager — 模型工具 `context_recall`。
|
|
3
|
+
*
|
|
4
|
+
* 用户把卡片从云端上下文中精简后,历史里只留下
|
|
5
|
+
* `<context-pruned card="u-123" title="…" tokens="…"/>` 占位。模型若判断当前
|
|
6
|
+
* 任务确实需要那段信息,可以调用本工具从**原始会话日志**取回完整原文——
|
|
7
|
+
* 数据从未删除,只是默认不发送。
|
|
8
|
+
*
|
|
9
|
+
* 工具实现复用 actions.recall():原始会话日志是唯一数据源(单一实现)。
|
|
10
|
+
* @module context-manager/recall
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
14
|
+
import { RECALL_TOOL_NAME } from './util.js'
|
|
15
|
+
|
|
16
|
+
/** 工具描述(模型可见,务必说明“按需取回、不要滥用”)。 */
|
|
17
|
+
const DESCRIPTION = [
|
|
18
|
+
'取回被用户从云端上下文中精简掉的历史原文。',
|
|
19
|
+
'当会话历史里出现 `<context-pruned card="…"/>` 占位标签时(card 是「阶段卡」id,如 g-u-12),说明该段历史被用户精简以降低上下文压力;',
|
|
20
|
+
'如果当前任务确实需要其中的信息(例如要复述、修改或核对被精简的代码、命令、工具输出或结论),',
|
|
21
|
+
'调用本工具并传入对应 cardIds,即可从原始会话日志中取回该阶段卡的完整原文(按段/角色标注)。',
|
|
22
|
+
'不传 cardIds 时列出当前所有已精简卡片(id、标题、大小);也可以传 query 按关键词搜索已精简/保留的卡片。',
|
|
23
|
+
'注意:取回的内容会重新占用上下文窗口,只在确有必要时调用,不要为了“补全上下文”而预先取回。',
|
|
24
|
+
].join('')
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 构造 context_recall 工具定义。
|
|
28
|
+
* @param {object} actions - lib/actions.js 的业务 API。
|
|
29
|
+
* @returns {object} 可传给 ctx.tools.register 的工具定义。
|
|
30
|
+
*/
|
|
31
|
+
export function createRecallTool(actions) {
|
|
32
|
+
return defineTool({
|
|
33
|
+
name: RECALL_TOOL_NAME,
|
|
34
|
+
description: DESCRIPTION,
|
|
35
|
+
parameters: {
|
|
36
|
+
query: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
description: '按关键词搜索上下文卡片(标题/简介/内容/id 匹配),不需要知道 card id;与 cardIds 二选一。',
|
|
39
|
+
},
|
|
40
|
+
cardIds: {
|
|
41
|
+
type: 'array',
|
|
42
|
+
items: { type: 'string' },
|
|
43
|
+
description: '要取回的阶段卡 id(来自历史中的 <context-pruned card="…"/> 占位,如 g-u-12)。留空则列出所有已精简卡片。',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
output: {
|
|
47
|
+
schema: { type: 'string' },
|
|
48
|
+
render(_args, value) {
|
|
49
|
+
return [{ type: 'text', text: String(value) }]
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
async execute(args, exec) {
|
|
53
|
+
const session = exec.agent?.session
|
|
54
|
+
if (session === undefined || session === null) {
|
|
55
|
+
throw new Error('context_recall 只能在一个会话内调用')
|
|
56
|
+
}
|
|
57
|
+
const cardIds = Array.isArray(args.cardIds) ? args.cardIds : undefined
|
|
58
|
+
const query = typeof args.query === 'string' ? args.query : undefined
|
|
59
|
+
return actions.recall(session.id, cardIds, query === undefined ? undefined : { query })
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
}
|