@downcity/plugins 1.0.60 → 1.0.61
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/bin/BuiltinPlugins.d.ts +15 -0
- package/bin/BuiltinPlugins.d.ts.map +1 -1
- package/bin/BuiltinPlugins.js +7 -1
- package/bin/BuiltinPlugins.js.map +1 -1
- package/bin/index.d.ts +6 -0
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +3 -0
- package/bin/index.js.map +1 -1
- package/bin/memory/Action.d.ts +15 -10
- package/bin/memory/Action.d.ts.map +1 -1
- package/bin/memory/Action.js +233 -16
- package/bin/memory/Action.js.map +1 -1
- package/bin/memory/MemoryPlugin.d.ts +10 -4
- package/bin/memory/MemoryPlugin.d.ts.map +1 -1
- package/bin/memory/MemoryPlugin.js +79 -37
- package/bin/memory/MemoryPlugin.js.map +1 -1
- package/bin/memory/runtime/Search.d.ts +1 -1
- package/bin/memory/runtime/Search.d.ts.map +1 -1
- package/bin/memory/runtime/Search.js +11 -7
- package/bin/memory/runtime/Search.js.map +1 -1
- package/bin/memory/runtime/Store.d.ts +8 -23
- package/bin/memory/runtime/Store.d.ts.map +1 -1
- package/bin/memory/runtime/Store.js +28 -43
- package/bin/memory/runtime/Store.js.map +1 -1
- package/bin/memory/runtime/SystemProvider.d.ts +4 -8
- package/bin/memory/runtime/SystemProvider.d.ts.map +1 -1
- package/bin/memory/runtime/SystemProvider.js +55 -62
- package/bin/memory/runtime/SystemProvider.js.map +1 -1
- package/bin/memory/runtime/Writer.d.ts +48 -10
- package/bin/memory/runtime/Writer.d.ts.map +1 -1
- package/bin/memory/runtime/Writer.js +197 -60
- package/bin/memory/runtime/Writer.js.map +1 -1
- package/bin/memory/types/Memory.d.ts +222 -33
- package/bin/memory/types/Memory.d.ts.map +1 -1
- package/bin/memory/types/Memory.js +4 -3
- package/bin/memory/types/Memory.js.map +1 -1
- package/bin/shell/ShellPlugin.d.ts +2 -1
- package/bin/shell/ShellPlugin.d.ts.map +1 -1
- package/bin/shell/ShellPlugin.js +3 -3
- package/bin/shell/ShellPlugin.js.map +1 -1
- package/bin/shell/ShellRuntimeTypes.d.ts +7 -2
- package/bin/shell/ShellRuntimeTypes.d.ts.map +1 -1
- package/bin/shell/runtime/ShellActionRuntime.d.ts.map +1 -1
- package/bin/shell/runtime/ShellActionRuntime.js +6 -6
- package/bin/shell/runtime/ShellActionRuntime.js.map +1 -1
- package/bin/shell/runtime/ShellActionRuntimeSupport.d.ts +14 -5
- package/bin/shell/runtime/ShellActionRuntimeSupport.d.ts.map +1 -1
- package/bin/shell/runtime/ShellActionRuntimeSupport.js +58 -22
- package/bin/shell/runtime/ShellActionRuntimeSupport.js.map +1 -1
- package/bin/shell/runtime/ShellProcessEvents.js +3 -3
- package/bin/shell/runtime/ShellProcessEvents.js.map +1 -1
- package/bin/shell/types/ShellPluginOptions.d.ts +95 -0
- package/bin/shell/types/ShellPluginOptions.d.ts.map +1 -0
- package/bin/shell/types/ShellPluginOptions.js +10 -0
- package/bin/shell/types/ShellPluginOptions.js.map +1 -0
- package/bin/task/Scheduler.d.ts +8 -0
- package/bin/task/Scheduler.d.ts.map +1 -1
- package/bin/task/Scheduler.js +7 -9
- package/bin/task/Scheduler.js.map +1 -1
- package/bin/task/TaskPlugin.d.ts +18 -1
- package/bin/task/TaskPlugin.d.ts.map +1 -1
- package/bin/task/TaskPlugin.js +23 -1
- package/bin/task/TaskPlugin.js.map +1 -1
- package/bin/task/types/TaskPluginOptions.d.ts +22 -0
- package/bin/task/types/TaskPluginOptions.d.ts.map +1 -0
- package/bin/task/types/TaskPluginOptions.js +9 -0
- package/bin/task/types/TaskPluginOptions.js.map +1 -0
- package/package.json +2 -2
- package/src/BuiltinPlugins.ts +27 -1
- package/src/index.ts +35 -0
- package/src/memory/Action.ts +292 -25
- package/src/memory/MemoryPlugin.ts +82 -40
- package/src/memory/runtime/Search.ts +16 -9
- package/src/memory/runtime/Store.ts +52 -49
- package/src/memory/runtime/SystemProvider.ts +55 -69
- package/src/memory/runtime/Writer.ts +262 -81
- package/src/memory/types/Memory.ts +296 -35
- package/src/shell/ShellPlugin.ts +4 -3
- package/src/shell/ShellRuntimeTypes.ts +7 -2
- package/src/shell/runtime/ShellActionRuntime.ts +18 -9
- package/src/shell/runtime/ShellActionRuntimeSupport.ts +106 -21
- package/src/shell/runtime/ShellProcessEvents.ts +3 -3
- package/src/shell/types/ShellPluginOptions.ts +112 -0
- package/src/task/Scheduler.ts +15 -9
- package/src/task/TaskPlugin.ts +27 -1
- package/src/task/types/TaskPluginOptions.ts +22 -0
- package/bin/memory/runtime/Flush.d.ts +0 -15
- package/bin/memory/runtime/Flush.d.ts.map +0 -1
- package/bin/memory/runtime/Flush.js +0 -63
- package/bin/memory/runtime/Flush.js.map +0 -1
- package/src/memory/runtime/Flush.ts +0 -83
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Memory
|
|
2
|
+
* Memory Plugin 类型定义。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
5
|
+
* - MemoryPlugin 对 agent 暴露“记忆能力”,内部使用 LLM Wiki 方式组织知识。
|
|
6
|
+
* - `wiki` 是整理后的知识层,`source` 是原始证据层,`working` 是会话局部层。
|
|
7
|
+
* - LLM 能力只通过 constructor 注入,plugin 自身不绑定具体模型或服务。
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
import type { JsonValue } from "@downcity/agent/internal/types/common/Json.js";
|
|
@@ -11,16 +12,169 @@ import type { JsonValue } from "@downcity/agent/internal/types/common/Json.js";
|
|
|
11
12
|
/**
|
|
12
13
|
* 记忆来源类型。
|
|
13
14
|
*/
|
|
14
|
-
export type MemorySourceType = "
|
|
15
|
+
export type MemorySourceType = "wiki" | "source" | "working";
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* 查询模式。
|
|
18
19
|
*
|
|
19
20
|
* 说明(中文)
|
|
20
|
-
* - 当前实现直接扫描 Markdown
|
|
21
|
+
* - 当前实现直接扫描 Markdown 文件,不引入向量库或外部索引服务。
|
|
21
22
|
*/
|
|
22
23
|
export type MemorySearchMode = "scan";
|
|
23
24
|
|
|
25
|
+
/**
|
|
26
|
+
* MemoryPlugin constructor 参数。
|
|
27
|
+
*/
|
|
28
|
+
export interface MemoryPluginOptions {
|
|
29
|
+
/**
|
|
30
|
+
* 把 session 或长文本 source 提炼为 wiki page 的函数。
|
|
31
|
+
*
|
|
32
|
+
* 说明(中文):未传时 `digest` action 会做确定性落盘,不会调用模型。
|
|
33
|
+
*/
|
|
34
|
+
digest?: MemoryDigestHandler;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 基于新证据修订某个 wiki page 的函数。
|
|
38
|
+
*
|
|
39
|
+
* 说明(中文):未传时 `remember`/`revise` 会追加写入,不做 LLM 重写。
|
|
40
|
+
*/
|
|
41
|
+
revise?: MemoryReviseHandler;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* digest handler。
|
|
46
|
+
*/
|
|
47
|
+
export type MemoryDigestHandler = (
|
|
48
|
+
input: MemoryDigestHandlerInput,
|
|
49
|
+
) => Promise<MemoryDigestHandlerOutput | string>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* revise handler。
|
|
53
|
+
*/
|
|
54
|
+
export type MemoryReviseHandler = (
|
|
55
|
+
input: MemoryReviseHandlerInput,
|
|
56
|
+
) => Promise<MemoryReviseHandlerOutput | string>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* digest handler 输入。
|
|
60
|
+
*/
|
|
61
|
+
export interface MemoryDigestHandlerInput {
|
|
62
|
+
/**
|
|
63
|
+
* 当前项目根目录。
|
|
64
|
+
*/
|
|
65
|
+
rootPath: string;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 需要提炼的原始文本。
|
|
69
|
+
*/
|
|
70
|
+
sourceText: string;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 原始文本来源路径(相对项目根目录)。
|
|
74
|
+
*/
|
|
75
|
+
sourcePath: string;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 触发 digest 的 session id。
|
|
79
|
+
*/
|
|
80
|
+
sessionId?: string;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 当前 wiki index 内容,方便模型决定更新哪些页面。
|
|
84
|
+
*/
|
|
85
|
+
wikiIndex: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* digest handler 输出。
|
|
90
|
+
*/
|
|
91
|
+
export interface MemoryDigestHandlerOutput {
|
|
92
|
+
/**
|
|
93
|
+
* 本次 digest 生成或更新的 wiki page。
|
|
94
|
+
*/
|
|
95
|
+
pages: MemoryWikiPageDraft[];
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 给调用方看的简短摘要。
|
|
99
|
+
*/
|
|
100
|
+
summary?: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* revise handler 输入。
|
|
105
|
+
*/
|
|
106
|
+
export interface MemoryReviseHandlerInput {
|
|
107
|
+
/**
|
|
108
|
+
* 当前项目根目录。
|
|
109
|
+
*/
|
|
110
|
+
rootPath: string;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 要修订的 wiki page 路径(相对项目根目录)。
|
|
114
|
+
*/
|
|
115
|
+
path: string;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 当前 page 内容;文件不存在时为空字符串。
|
|
119
|
+
*/
|
|
120
|
+
currentContent: string;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 修订指令。
|
|
124
|
+
*/
|
|
125
|
+
instruction: string;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 新证据或需要合入的内容。
|
|
129
|
+
*/
|
|
130
|
+
evidence: string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* revise handler 输出。
|
|
135
|
+
*/
|
|
136
|
+
export interface MemoryReviseHandlerOutput {
|
|
137
|
+
/**
|
|
138
|
+
* 修订后的 wiki page 路径;未传时沿用输入 path。
|
|
139
|
+
*/
|
|
140
|
+
path?: string;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 修订后的完整 Markdown 内容。
|
|
144
|
+
*/
|
|
145
|
+
content: string;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 给调用方看的简短摘要。
|
|
149
|
+
*/
|
|
150
|
+
summary?: string;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 待写入 wiki 的页面草稿。
|
|
155
|
+
*/
|
|
156
|
+
export interface MemoryWikiPageDraft {
|
|
157
|
+
/**
|
|
158
|
+
* 目标路径;可传 `.downcity/memory/wiki/foo.md` 或 `foo.md`。
|
|
159
|
+
*/
|
|
160
|
+
path?: string;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 页面标题。
|
|
164
|
+
*/
|
|
165
|
+
title?: string;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* 完整 Markdown 内容。
|
|
169
|
+
*/
|
|
170
|
+
content: string;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 页面标签。
|
|
174
|
+
*/
|
|
175
|
+
tags?: string[];
|
|
176
|
+
}
|
|
177
|
+
|
|
24
178
|
/**
|
|
25
179
|
* 单条记忆检索结果。
|
|
26
180
|
*/
|
|
@@ -29,28 +183,34 @@ export interface MemorySearchResultItem {
|
|
|
29
183
|
* 片段来源路径(相对项目根目录)。
|
|
30
184
|
*/
|
|
31
185
|
path: string;
|
|
186
|
+
|
|
32
187
|
/**
|
|
33
188
|
* 片段起始行号(1-based)。
|
|
34
189
|
*/
|
|
35
190
|
startLine: number;
|
|
191
|
+
|
|
36
192
|
/**
|
|
37
193
|
* 片段结束行号(1-based)。
|
|
38
194
|
*/
|
|
39
195
|
endLine: number;
|
|
196
|
+
|
|
40
197
|
/**
|
|
41
198
|
* 归一化分数(0~1,越高越相关)。
|
|
42
199
|
*/
|
|
43
200
|
score: number;
|
|
201
|
+
|
|
44
202
|
/**
|
|
45
203
|
* 返回给模型/用户的片段文本(已按预算裁剪)。
|
|
46
204
|
*/
|
|
47
205
|
snippet: string;
|
|
206
|
+
|
|
48
207
|
/**
|
|
49
|
-
*
|
|
208
|
+
* 记忆来源分类。
|
|
50
209
|
*/
|
|
51
210
|
source: MemorySourceType;
|
|
211
|
+
|
|
52
212
|
/**
|
|
53
|
-
* 引用标记(例如:`.downcity/memory/
|
|
213
|
+
* 引用标记(例如:`.downcity/memory/wiki/plugin-system.md#L12-L20`)。
|
|
54
214
|
*/
|
|
55
215
|
citation: string;
|
|
56
216
|
}
|
|
@@ -63,14 +223,21 @@ export interface MemorySearchPayload {
|
|
|
63
223
|
* 查询语句。
|
|
64
224
|
*/
|
|
65
225
|
query: string;
|
|
226
|
+
|
|
66
227
|
/**
|
|
67
228
|
* 可选返回条数上限,未传使用内置默认值。
|
|
68
229
|
*/
|
|
69
230
|
maxResults?: number;
|
|
231
|
+
|
|
70
232
|
/**
|
|
71
233
|
* 可选分数阈值,未传使用内置默认值。
|
|
72
234
|
*/
|
|
73
235
|
minScore?: number;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* 是否检索原始 source 层;默认只检索 wiki 层和 working 层。
|
|
239
|
+
*/
|
|
240
|
+
includeSources?: boolean;
|
|
74
241
|
}
|
|
75
242
|
|
|
76
243
|
/**
|
|
@@ -81,18 +248,22 @@ export interface MemorySearchResponse {
|
|
|
81
248
|
* 返回结果集合。
|
|
82
249
|
*/
|
|
83
250
|
results: MemorySearchResultItem[];
|
|
251
|
+
|
|
84
252
|
/**
|
|
85
253
|
* 当前检索模式。
|
|
86
254
|
*/
|
|
87
255
|
mode: MemorySearchMode;
|
|
256
|
+
|
|
88
257
|
/**
|
|
89
258
|
* 当前后端标识。
|
|
90
259
|
*/
|
|
91
260
|
backend: "builtin";
|
|
261
|
+
|
|
92
262
|
/**
|
|
93
263
|
* 错误原因文本(失败场景)。
|
|
94
264
|
*/
|
|
95
265
|
error?: string;
|
|
266
|
+
|
|
96
267
|
/**
|
|
97
268
|
* 建议动作(失败场景)。
|
|
98
269
|
*/
|
|
@@ -102,15 +273,17 @@ export interface MemorySearchResponse {
|
|
|
102
273
|
/**
|
|
103
274
|
* 读取记忆片段请求。
|
|
104
275
|
*/
|
|
105
|
-
export interface
|
|
276
|
+
export interface MemoryReadPayload {
|
|
106
277
|
/**
|
|
107
278
|
* 相对项目根目录的目标路径。
|
|
108
279
|
*/
|
|
109
280
|
path: string;
|
|
281
|
+
|
|
110
282
|
/**
|
|
111
283
|
* 可选起始行(1-based)。
|
|
112
284
|
*/
|
|
113
285
|
from?: number;
|
|
286
|
+
|
|
114
287
|
/**
|
|
115
288
|
* 可选读取行数。
|
|
116
289
|
*/
|
|
@@ -120,15 +293,17 @@ export interface MemoryGetPayload {
|
|
|
120
293
|
/**
|
|
121
294
|
* 读取记忆片段响应。
|
|
122
295
|
*/
|
|
123
|
-
export interface
|
|
296
|
+
export interface MemoryReadResponse {
|
|
124
297
|
/**
|
|
125
298
|
* 目标路径(回显)。
|
|
126
299
|
*/
|
|
127
300
|
path: string;
|
|
301
|
+
|
|
128
302
|
/**
|
|
129
303
|
* 读取内容;文件缺失时为空字符串。
|
|
130
304
|
*/
|
|
131
305
|
text: string;
|
|
306
|
+
|
|
132
307
|
/**
|
|
133
308
|
* 文件不存在时为 true。
|
|
134
309
|
*/
|
|
@@ -136,49 +311,69 @@ export interface MemoryGetResponse {
|
|
|
136
311
|
}
|
|
137
312
|
|
|
138
313
|
/**
|
|
139
|
-
*
|
|
314
|
+
* remember 请求。
|
|
140
315
|
*/
|
|
141
|
-
export interface
|
|
316
|
+
export interface MemoryRememberPayload {
|
|
142
317
|
/**
|
|
143
|
-
*
|
|
318
|
+
* 需要记住的内容。
|
|
144
319
|
*/
|
|
145
320
|
content: string;
|
|
321
|
+
|
|
146
322
|
/**
|
|
147
|
-
*
|
|
323
|
+
* 可选主题,用于决定默认 wiki page 路径。
|
|
148
324
|
*/
|
|
149
|
-
|
|
325
|
+
topic?: string;
|
|
326
|
+
|
|
150
327
|
/**
|
|
151
|
-
*
|
|
328
|
+
* 可选目标 wiki page 路径。
|
|
152
329
|
*/
|
|
153
|
-
|
|
330
|
+
path?: string;
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* 可选来源说明。
|
|
334
|
+
*/
|
|
335
|
+
source?: string;
|
|
154
336
|
}
|
|
155
337
|
|
|
156
338
|
/**
|
|
157
|
-
*
|
|
339
|
+
* remember 响应。
|
|
158
340
|
*/
|
|
159
|
-
export interface
|
|
341
|
+
export interface MemoryRememberResponse {
|
|
160
342
|
/**
|
|
161
|
-
*
|
|
343
|
+
* 原始 source 归档路径。
|
|
162
344
|
*/
|
|
163
|
-
|
|
345
|
+
sourcePath: string;
|
|
346
|
+
|
|
164
347
|
/**
|
|
165
|
-
*
|
|
348
|
+
* 写入或更新的 wiki page 路径。
|
|
166
349
|
*/
|
|
167
|
-
|
|
350
|
+
wikiPath: string;
|
|
351
|
+
|
|
168
352
|
/**
|
|
169
|
-
*
|
|
353
|
+
* 当前写入策略。
|
|
354
|
+
*/
|
|
355
|
+
mode: "appended" | "revised";
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* 写入内容字符数。
|
|
170
359
|
*/
|
|
171
360
|
writtenChars: number;
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* 可选摘要。
|
|
364
|
+
*/
|
|
365
|
+
summary?: string;
|
|
172
366
|
}
|
|
173
367
|
|
|
174
368
|
/**
|
|
175
|
-
*
|
|
369
|
+
* digest 请求。
|
|
176
370
|
*/
|
|
177
|
-
export interface
|
|
371
|
+
export interface MemoryDigestPayload {
|
|
178
372
|
/**
|
|
179
|
-
*
|
|
373
|
+
* 目标 session id。
|
|
180
374
|
*/
|
|
181
375
|
sessionId: string;
|
|
376
|
+
|
|
182
377
|
/**
|
|
183
378
|
* 可选最大提取消息条数。
|
|
184
379
|
*/
|
|
@@ -186,21 +381,78 @@ export interface MemoryFlushPayload {
|
|
|
186
381
|
}
|
|
187
382
|
|
|
188
383
|
/**
|
|
189
|
-
*
|
|
384
|
+
* digest 响应。
|
|
190
385
|
*/
|
|
191
|
-
export interface
|
|
386
|
+
export interface MemoryDigestResponse {
|
|
192
387
|
/**
|
|
193
|
-
*
|
|
388
|
+
* 原始 session source 归档路径。
|
|
194
389
|
*/
|
|
195
|
-
|
|
390
|
+
sourcePath: string;
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* 写入或更新的 wiki page 路径集合。
|
|
394
|
+
*/
|
|
395
|
+
wikiPaths: string[];
|
|
396
|
+
|
|
196
397
|
/**
|
|
197
|
-
* 参与
|
|
398
|
+
* 参与 digest 的消息条数。
|
|
198
399
|
*/
|
|
199
400
|
messageCount: number;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* 当前 digest 模式。
|
|
404
|
+
*/
|
|
405
|
+
mode: "archived" | "digested";
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* 可选摘要。
|
|
409
|
+
*/
|
|
410
|
+
summary?: string;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* revise 请求。
|
|
415
|
+
*/
|
|
416
|
+
export interface MemoryRevisePayload {
|
|
417
|
+
/**
|
|
418
|
+
* 要修订的 wiki page 路径。
|
|
419
|
+
*/
|
|
420
|
+
path: string;
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* 修订指令。
|
|
424
|
+
*/
|
|
425
|
+
instruction: string;
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* 新证据或需要合入的内容。
|
|
429
|
+
*/
|
|
430
|
+
evidence?: string;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* revise 响应。
|
|
435
|
+
*/
|
|
436
|
+
export interface MemoryReviseResponse {
|
|
437
|
+
/**
|
|
438
|
+
* 实际写入的 wiki page 路径。
|
|
439
|
+
*/
|
|
440
|
+
path: string;
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* 当前 revise 模式。
|
|
444
|
+
*/
|
|
445
|
+
mode: "appended" | "revised";
|
|
446
|
+
|
|
200
447
|
/**
|
|
201
448
|
* 写入内容字符数。
|
|
202
449
|
*/
|
|
203
450
|
writtenChars: number;
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* 可选摘要。
|
|
454
|
+
*/
|
|
455
|
+
summary?: string;
|
|
204
456
|
}
|
|
205
457
|
|
|
206
458
|
/**
|
|
@@ -211,10 +463,12 @@ export interface MemorySourceStat {
|
|
|
211
463
|
* 来源分类。
|
|
212
464
|
*/
|
|
213
465
|
source: MemorySourceType;
|
|
466
|
+
|
|
214
467
|
/**
|
|
215
468
|
* 文件数量。
|
|
216
469
|
*/
|
|
217
470
|
files: number;
|
|
471
|
+
|
|
218
472
|
/**
|
|
219
473
|
* 片段数量。
|
|
220
474
|
*/
|
|
@@ -229,18 +483,22 @@ export interface MemoryStatusResponse {
|
|
|
229
483
|
* 后端标识。
|
|
230
484
|
*/
|
|
231
485
|
backend: "builtin";
|
|
486
|
+
|
|
232
487
|
/**
|
|
233
488
|
* 当前检索模式。
|
|
234
489
|
*/
|
|
235
490
|
mode: MemorySearchMode;
|
|
491
|
+
|
|
236
492
|
/**
|
|
237
493
|
* 文件总数。
|
|
238
494
|
*/
|
|
239
495
|
files: number;
|
|
496
|
+
|
|
240
497
|
/**
|
|
241
498
|
* chunk 总数。
|
|
242
499
|
*/
|
|
243
500
|
chunks: number;
|
|
501
|
+
|
|
244
502
|
/**
|
|
245
503
|
* 按来源统计。
|
|
246
504
|
*/
|
|
@@ -248,17 +506,19 @@ export interface MemoryStatusResponse {
|
|
|
248
506
|
}
|
|
249
507
|
|
|
250
508
|
/**
|
|
251
|
-
* Memory service
|
|
509
|
+
* Memory service 内置默认配置。
|
|
252
510
|
*/
|
|
253
511
|
export interface MemoryDefaults {
|
|
254
512
|
/**
|
|
255
513
|
* 检索默认返回条数。
|
|
256
514
|
*/
|
|
257
515
|
maxResults: number;
|
|
516
|
+
|
|
258
517
|
/**
|
|
259
518
|
* 检索默认最小分数。
|
|
260
519
|
*/
|
|
261
520
|
minScore: number;
|
|
521
|
+
|
|
262
522
|
/**
|
|
263
523
|
* 注入预算(字符)。
|
|
264
524
|
*/
|
|
@@ -270,7 +530,8 @@ export interface MemoryDefaults {
|
|
|
270
530
|
*/
|
|
271
531
|
export type MemoryActionPayload =
|
|
272
532
|
| MemorySearchPayload
|
|
273
|
-
|
|
|
274
|
-
|
|
|
275
|
-
|
|
|
533
|
+
| MemoryReadPayload
|
|
534
|
+
| MemoryRememberPayload
|
|
535
|
+
| MemoryDigestPayload
|
|
536
|
+
| MemoryRevisePayload
|
|
276
537
|
| Record<string, JsonValue>;
|
package/src/shell/ShellPlugin.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
ShellPluginState,
|
|
15
15
|
ShellSessionRuntimeState,
|
|
16
16
|
} from "@/shell/ShellRuntimeTypes.js";
|
|
17
|
+
import type { ShellPluginOptions } from "@/shell/types/ShellPluginOptions.js";
|
|
17
18
|
import type {
|
|
18
19
|
ShellCloseRequest,
|
|
19
20
|
ShellExecRequest,
|
|
@@ -60,9 +61,9 @@ export class ShellPlugin extends BasePlugin {
|
|
|
60
61
|
*/
|
|
61
62
|
public readonly sessions: Map<string, ShellSessionRuntimeState>;
|
|
62
63
|
|
|
63
|
-
constructor() {
|
|
64
|
+
constructor(options: ShellPluginOptions = {}) {
|
|
64
65
|
super();
|
|
65
|
-
this.state = createShellPluginState();
|
|
66
|
+
this.state = createShellPluginState(options);
|
|
66
67
|
this.sessions = this.state.sessions;
|
|
67
68
|
this.actions = {
|
|
68
69
|
exec: {
|
|
@@ -121,7 +122,7 @@ export class ShellPlugin extends BasePlugin {
|
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
this.state.sessions.clear();
|
|
124
|
-
this.state.
|
|
125
|
+
this.state.context = null;
|
|
125
126
|
},
|
|
126
127
|
};
|
|
127
128
|
}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import type { ChildProcessWithoutNullStreams } from "node:child_process";
|
|
11
11
|
import type { AgentContext } from "@downcity/agent/internal/types/runtime/agent/AgentContext.js";
|
|
12
12
|
import type { ShellSessionSnapshot } from "@downcity/agent/internal/executor/tools/shell/types/ShellPlugin.js";
|
|
13
|
+
import type { ResolvedShellPluginOptions } from "@/shell/types/ShellPluginOptions.js";
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* 单个 shell wait 调用挂起时注册的 waiter。
|
|
@@ -79,16 +80,20 @@ export type ShellSessionRuntimeState = {
|
|
|
79
80
|
* `ShellPlugin` 实例级状态。
|
|
80
81
|
*/
|
|
81
82
|
export type ShellPluginState = {
|
|
83
|
+
/**
|
|
84
|
+
* 当前 shell plugin 归一化后的运行参数。
|
|
85
|
+
*/
|
|
86
|
+
options: ResolvedShellPluginOptions;
|
|
82
87
|
/**
|
|
83
88
|
* 当前实例持有的全部 in-memory shell session。
|
|
84
89
|
*/
|
|
85
90
|
sessions: Map<string, ShellSessionRuntimeState>;
|
|
86
91
|
/**
|
|
87
|
-
*
|
|
92
|
+
* 当前实例最近一次启动时绑定的 agent context。
|
|
88
93
|
*
|
|
89
94
|
* 关键点(中文)
|
|
90
95
|
* - 仅用于 shell 自动通知 chat 的回调路径。
|
|
91
96
|
* - 这是实例字段,不再是模块级全局变量。
|
|
92
97
|
*/
|
|
93
|
-
|
|
98
|
+
context: AgentContext | null;
|
|
94
99
|
};
|
|
@@ -31,12 +31,9 @@ import { getShellDir, getShellOutputPath, getShellSnapshotPath } from "./Paths.j
|
|
|
31
31
|
import {
|
|
32
32
|
buildActionResponse,
|
|
33
33
|
buildShellEnv,
|
|
34
|
-
|
|
34
|
+
clampWaitMsWithOptions,
|
|
35
35
|
createOutputChunk,
|
|
36
36
|
createShellPluginState,
|
|
37
|
-
DEFAULT_EXEC_TIMEOUT_MS,
|
|
38
|
-
DEFAULT_INLINE_WAIT_MS,
|
|
39
|
-
DEFAULT_WAIT_TIMEOUT_MS,
|
|
40
37
|
ensureCapacity,
|
|
41
38
|
isInMemorySession,
|
|
42
39
|
isTerminalStatus,
|
|
@@ -65,7 +62,7 @@ export function bindShellRuntime(
|
|
|
65
62
|
state: ShellPluginState,
|
|
66
63
|
context: AgentContext,
|
|
67
64
|
): void {
|
|
68
|
-
state.
|
|
65
|
+
state.context = context;
|
|
69
66
|
}
|
|
70
67
|
|
|
71
68
|
/**
|
|
@@ -189,7 +186,11 @@ export async function startShellSession(
|
|
|
189
186
|
attachShellProcessEventHandlers({ state, session });
|
|
190
187
|
await persistSnapshot(session);
|
|
191
188
|
|
|
192
|
-
const inlineWaitMs =
|
|
189
|
+
const inlineWaitMs = clampWaitMsWithOptions(
|
|
190
|
+
state.options,
|
|
191
|
+
request.inlineWaitMs,
|
|
192
|
+
state.options.defaultInlineWaitMs,
|
|
193
|
+
);
|
|
193
194
|
await waitShellSession(state, context, {
|
|
194
195
|
shellId,
|
|
195
196
|
afterVersion: 1,
|
|
@@ -351,7 +352,11 @@ export async function waitShellSession(
|
|
|
351
352
|
};
|
|
352
353
|
const timer = setTimeout(() => {
|
|
353
354
|
finish();
|
|
354
|
-
},
|
|
355
|
+
}, clampWaitMsWithOptions(
|
|
356
|
+
state.options,
|
|
357
|
+
request.timeoutMs,
|
|
358
|
+
state.options.defaultWaitTimeoutMs,
|
|
359
|
+
));
|
|
355
360
|
waiter = {
|
|
356
361
|
resolve: finish,
|
|
357
362
|
timer,
|
|
@@ -445,13 +450,17 @@ export async function execShellCommand(
|
|
|
445
450
|
context: AgentContext,
|
|
446
451
|
request: ShellExecRequest,
|
|
447
452
|
): Promise<ShellActionResponse> {
|
|
448
|
-
const timeoutMs =
|
|
453
|
+
const timeoutMs = clampWaitMsWithOptions(
|
|
454
|
+
state.options,
|
|
455
|
+
request.timeoutMs,
|
|
456
|
+
state.options.defaultExecTimeoutMs,
|
|
457
|
+
);
|
|
449
458
|
const started = await startShellSession(state, context, {
|
|
450
459
|
cmd: request.cmd,
|
|
451
460
|
...(request.cwd ? { cwd: request.cwd } : {}),
|
|
452
461
|
...(request.shell ? { shell: request.shell } : {}),
|
|
453
462
|
login: request.login,
|
|
454
|
-
inlineWaitMs: Math.min(
|
|
463
|
+
inlineWaitMs: Math.min(state.options.defaultInlineWaitMs, timeoutMs),
|
|
455
464
|
maxOutputTokens: request.maxOutputTokens,
|
|
456
465
|
autoNotifyOnExit: false,
|
|
457
466
|
});
|