@ai-setting/roy-agent-core 1.5.17-beta.1 → 1.5.22
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/dist/env/index.js +20 -8
- package/dist/env/log-trace/index.js +1 -1
- package/dist/env/prompt/index.js +1 -1
- package/dist/env/workflow/engine/index.js +1 -1
- package/dist/env/workflow/index.js +2 -2
- package/dist/index.js +6 -7
- package/dist/shared/@ai-setting/{roy-agent-core-xq8hhqb8.js → roy-agent-core-4wjywp3c.js} +4 -2
- package/dist/shared/@ai-setting/roy-agent-core-8jxva565.js +19 -0
- package/dist/shared/@ai-setting/roy-agent-core-avq1x4t7.js +84 -0
- package/dist/shared/@ai-setting/{roy-agent-core-gq20wsgv.js → roy-agent-core-ffb9fq4v.js} +23 -2
- package/dist/shared/@ai-setting/{roy-agent-core-93zfb3r1.js → roy-agent-core-mrcxzpbg.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-rhmtwnw1.js → roy-agent-core-pw7cv1px.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-gbqcyegm.js → roy-agent-core-rccptwv0.js} +512 -673
- package/dist/shared/@ai-setting/{roy-agent-core-wrcy0h6z.js → roy-agent-core-ty94k28r.js} +1 -1
- package/package.json +8 -29
- package/dist/config/index.d.ts +0 -1250
- package/dist/env/agent/index.d.ts +0 -2279
- package/dist/env/commands/index.d.ts +0 -1131
- package/dist/env/debug/formatters/index.d.ts +0 -236
- package/dist/env/debug/index.d.ts +0 -1652
- package/dist/env/hook/index.d.ts +0 -279
- package/dist/env/index.d.ts +0 -3481
- package/dist/env/llm/index.d.ts +0 -1760
- package/dist/env/log-trace/index.d.ts +0 -1574
- package/dist/env/mcp/index.d.ts +0 -1331
- package/dist/env/mcp/tool/index.d.ts +0 -183
- package/dist/env/memory/built-in/index.d.ts +0 -232
- package/dist/env/memory/index.d.ts +0 -1799
- package/dist/env/memory/plugin/index.d.ts +0 -747
- package/dist/env/prompt/index.d.ts +0 -1164
- package/dist/env/session/index.d.ts +0 -1908
- package/dist/env/session/storage/index.d.ts +0 -564
- package/dist/env/skill/index.d.ts +0 -1266
- package/dist/env/skill/tool/index.d.ts +0 -193
- package/dist/env/task/delegate/index.d.ts +0 -1612
- package/dist/env/task/events/index.d.ts +0 -171
- package/dist/env/task/hooks/index.d.ts +0 -624
- package/dist/env/task/index.d.ts +0 -1553
- package/dist/env/task/plugins/index.d.ts +0 -466
- package/dist/env/task/storage/index.d.ts +0 -241
- package/dist/env/task/tools/index.d.ts +0 -1485
- package/dist/env/task/tools/operation/index.d.ts +0 -1484
- package/dist/env/tool/built-in/index.d.ts +0 -218
- package/dist/env/tool/index.d.ts +0 -1396
- package/dist/env/workflow/decorators/index.d.ts +0 -2161
- package/dist/env/workflow/engine/index.d.ts +0 -3453
- package/dist/env/workflow/index.d.ts +0 -3546
- package/dist/env/workflow/nodes/index.d.ts +0 -2092
- package/dist/env/workflow/service/index.d.ts +0 -227
- package/dist/env/workflow/storage/index.d.ts +0 -165
- package/dist/env/workflow/tools/index.d.ts +0 -416
- package/dist/env/workflow/types/index.d.ts +0 -2255
- package/dist/env/workflow/utils/index.d.ts +0 -2031
- package/dist/index.d.ts +0 -7858
|
@@ -1,747 +0,0 @@
|
|
|
1
|
-
import { ModelMessage } from "ai";
|
|
2
|
-
/**
|
|
3
|
-
* MemoryPlugin configuration
|
|
4
|
-
*/
|
|
5
|
-
interface MemoryPluginConfig {
|
|
6
|
-
/** Enable memory plugin */
|
|
7
|
-
enabled?: boolean;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Memory task types
|
|
11
|
-
*/
|
|
12
|
-
type MemoryTaskType = "extract_memory";
|
|
13
|
-
/**
|
|
14
|
-
* Memory task
|
|
15
|
-
*/
|
|
16
|
-
interface MemoryTask {
|
|
17
|
-
id: string;
|
|
18
|
-
type: MemoryTaskType;
|
|
19
|
-
payload: unknown;
|
|
20
|
-
timestamp: number;
|
|
21
|
-
priority: number;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Extract memory payload
|
|
25
|
-
*/
|
|
26
|
-
interface ExtractMemoryPayload {
|
|
27
|
-
messages: ModelMessage[];
|
|
28
|
-
sessionId?: string;
|
|
29
|
-
/** Hook context for Memory Agent */
|
|
30
|
-
ctx?: MemoryHookContext;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* SessionMessage 接口
|
|
34
|
-
*/
|
|
35
|
-
interface SessionMessage {
|
|
36
|
-
/** 消息角色 */
|
|
37
|
-
role: "user" | "assistant" | "system" | "tool";
|
|
38
|
-
/** 消息内容 */
|
|
39
|
-
content: string | Array<{
|
|
40
|
-
type: string;
|
|
41
|
-
[key: string]: unknown;
|
|
42
|
-
}>;
|
|
43
|
-
/** 工具调用 ID(仅 tool 角色) */
|
|
44
|
-
toolCallId?: string;
|
|
45
|
-
/** 工具名称(仅 tool 角色) */
|
|
46
|
-
toolName?: string;
|
|
47
|
-
/** 时间戳 */
|
|
48
|
-
timestamp?: number;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Hook context data for agent:after.react
|
|
52
|
-
*/
|
|
53
|
-
interface MemoryHookContext {
|
|
54
|
-
/** Current messages for memory extraction */
|
|
55
|
-
messages: ModelMessage[];
|
|
56
|
-
/** Current session ID */
|
|
57
|
-
sessionId?: string;
|
|
58
|
-
/** Project summaries (populated by project agent) */
|
|
59
|
-
projectSummaries?: unknown[];
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* MemoryManager 配置
|
|
63
|
-
*/
|
|
64
|
-
interface MemoryManagerConfig {
|
|
65
|
-
/** 回调:当需要提取记忆时调用 */
|
|
66
|
-
onExtractMemory?: (payload: ExtractMemoryPayload) => Promise<void>;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* MemoryManager V3 - Simplified
|
|
70
|
-
*
|
|
71
|
-
* 简化的后台异步内存处理,只负责任务队列
|
|
72
|
-
*/
|
|
73
|
-
declare class MemoryManager {
|
|
74
|
-
/** 队列最大容量,防止内存溢出 */
|
|
75
|
-
private static readonly MAX_QUEUE_SIZE;
|
|
76
|
-
private queue;
|
|
77
|
-
private processing;
|
|
78
|
-
private shuttingDown;
|
|
79
|
-
private config;
|
|
80
|
-
private processingPromise;
|
|
81
|
-
private resolveProcessing;
|
|
82
|
-
constructor(config?: MemoryManagerConfig);
|
|
83
|
-
/**
|
|
84
|
-
* 更新配置
|
|
85
|
-
*/
|
|
86
|
-
updateConfig(config: Partial<MemoryManagerConfig>): void;
|
|
87
|
-
/**
|
|
88
|
-
* 入队(非阻塞)
|
|
89
|
-
*/
|
|
90
|
-
enqueue(task: Omit<MemoryTask, "id">): void;
|
|
91
|
-
/**
|
|
92
|
-
* 启动处理循环
|
|
93
|
-
*/
|
|
94
|
-
private startProcessingLoop;
|
|
95
|
-
/**
|
|
96
|
-
* 检查是否有待处理任务
|
|
97
|
-
*/
|
|
98
|
-
hasPendingTasks(): boolean;
|
|
99
|
-
/**
|
|
100
|
-
* 等待处理完成
|
|
101
|
-
*/
|
|
102
|
-
waitForCompletion(): Promise<void>;
|
|
103
|
-
/**
|
|
104
|
-
* 准备关闭
|
|
105
|
-
*/
|
|
106
|
-
prepareShutdown(): void;
|
|
107
|
-
/**
|
|
108
|
-
* 释放资源
|
|
109
|
-
*/
|
|
110
|
-
dispose(): Promise<void>;
|
|
111
|
-
/**
|
|
112
|
-
* 处理单个任务
|
|
113
|
-
*/
|
|
114
|
-
private processTask;
|
|
115
|
-
/**
|
|
116
|
-
* 处理记忆提取
|
|
117
|
-
*/
|
|
118
|
-
private handleExtractMemory;
|
|
119
|
-
}
|
|
120
|
-
import { ModelMessage as ModelMessage2 } from "ai";
|
|
121
|
-
import { z, ZodType, ZodError } from "zod";
|
|
122
|
-
/**
|
|
123
|
-
* 沙箱配置
|
|
124
|
-
*/
|
|
125
|
-
interface SandboxConfig {
|
|
126
|
-
/** 是否启用沙箱 */
|
|
127
|
-
enabled: boolean;
|
|
128
|
-
/** 沙箱类型 */
|
|
129
|
-
type: "native" | "docker";
|
|
130
|
-
/** 动作过滤 */
|
|
131
|
-
actionFilter?: {
|
|
132
|
-
/** 包含的动作 */
|
|
133
|
-
include?: string[];
|
|
134
|
-
/** 排除的动作 */
|
|
135
|
-
exclude?: string[];
|
|
136
|
-
};
|
|
137
|
-
/** 文件系统限制 */
|
|
138
|
-
filesystem?: {
|
|
139
|
-
/** 允许读取 */
|
|
140
|
-
allowRead?: string[];
|
|
141
|
-
/** 禁止读取 */
|
|
142
|
-
denyRead?: string[];
|
|
143
|
-
/** 允许写入 */
|
|
144
|
-
allowWrite?: string[];
|
|
145
|
-
/** 禁止写入 */
|
|
146
|
-
denyWrite?: string[];
|
|
147
|
-
};
|
|
148
|
-
/** 网络限制 */
|
|
149
|
-
network?: {
|
|
150
|
-
/** 允许的域名 */
|
|
151
|
-
allowedDomains?: string[];
|
|
152
|
-
/** 禁止的域名 */
|
|
153
|
-
deniedDomains?: string[];
|
|
154
|
-
};
|
|
155
|
-
/** Docker 配置 */
|
|
156
|
-
docker?: {
|
|
157
|
-
/** 镜像 */
|
|
158
|
-
image?: string;
|
|
159
|
-
/** 网络模式 */
|
|
160
|
-
networkMode?: "bridge" | "host" | "none";
|
|
161
|
-
/** 卷挂载 */
|
|
162
|
-
volumes?: Record<string, string>;
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* 工具执行上下文
|
|
167
|
-
*/
|
|
168
|
-
interface ToolContext {
|
|
169
|
-
/** 工作目录 */
|
|
170
|
-
workdir?: string;
|
|
171
|
-
/** 用户 ID */
|
|
172
|
-
user_id?: string;
|
|
173
|
-
/** 会话 ID */
|
|
174
|
-
session_id?: string;
|
|
175
|
-
/** 消息 ID */
|
|
176
|
-
message_id?: string;
|
|
177
|
-
/** 中断信号 */
|
|
178
|
-
abort?: AbortSignal;
|
|
179
|
-
/** 额外元数据 */
|
|
180
|
-
metadata?: Record<string, unknown>;
|
|
181
|
-
/** 沙箱配置 */
|
|
182
|
-
sandbox?: SandboxConfig;
|
|
183
|
-
/** 沙箱 Provider */
|
|
184
|
-
sandboxProvider?: unknown | null;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* 工具结果元数据
|
|
188
|
-
*/
|
|
189
|
-
interface ToolResultMetadata {
|
|
190
|
-
/** 执行时间(毫秒) */
|
|
191
|
-
execution_time_ms: number;
|
|
192
|
-
/** 输出大小(字节) */
|
|
193
|
-
output_size?: number;
|
|
194
|
-
/** 标准输出 */
|
|
195
|
-
stdout?: string;
|
|
196
|
-
/** 标准错误 */
|
|
197
|
-
stderr?: string;
|
|
198
|
-
/** 退出码 */
|
|
199
|
-
exit_code?: number;
|
|
200
|
-
/** Token 使用量 */
|
|
201
|
-
usage?: {
|
|
202
|
-
inputTokens: number;
|
|
203
|
-
outputTokens: number;
|
|
204
|
-
totalTokens?: number;
|
|
205
|
-
};
|
|
206
|
-
/** 额外元数据 */
|
|
207
|
-
[key: string]: unknown;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* 工具执行结果
|
|
211
|
-
*/
|
|
212
|
-
interface ToolResult {
|
|
213
|
-
/** 是否成功 */
|
|
214
|
-
success: boolean;
|
|
215
|
-
/** 输出内容 */
|
|
216
|
-
output: string | Record<string, unknown>;
|
|
217
|
-
/** 错误信息 */
|
|
218
|
-
error?: string;
|
|
219
|
-
/** 结果元数据 */
|
|
220
|
-
metadata?: ToolResultMetadata;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* 工具元数据
|
|
224
|
-
*/
|
|
225
|
-
interface ToolMetadata {
|
|
226
|
-
/** 分类 */
|
|
227
|
-
category?: string;
|
|
228
|
-
/** 标签 */
|
|
229
|
-
tags?: string[];
|
|
230
|
-
/** 版本 */
|
|
231
|
-
version?: string;
|
|
232
|
-
/** 作者 */
|
|
233
|
-
author?: string;
|
|
234
|
-
/** 是否实验性 */
|
|
235
|
-
experimental?: boolean;
|
|
236
|
-
/** MCP 工具信息(MCP adapter 使用) */
|
|
237
|
-
mcpTool?: {
|
|
238
|
-
originalName: string;
|
|
239
|
-
originalDescription: string;
|
|
240
|
-
inputSchema?: unknown;
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* 工具沙箱配置
|
|
245
|
-
*/
|
|
246
|
-
interface ToolSandboxConfig {
|
|
247
|
-
/** 是否启用沙箱 */
|
|
248
|
-
enabled: boolean;
|
|
249
|
-
/** 沙箱配置 */
|
|
250
|
-
config?: Partial<SandboxConfig>;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* 工具权限配置
|
|
254
|
-
*/
|
|
255
|
-
interface ToolPermissionConfig {
|
|
256
|
-
/** 是否需要用户确认 */
|
|
257
|
-
requireConfirmation?: boolean;
|
|
258
|
-
/** 权限级别 */
|
|
259
|
-
level?: "safe" | "dangerous" | "critical";
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* 工具信息
|
|
263
|
-
*/
|
|
264
|
-
interface ToolInfo<Parameters extends ZodType = ZodType> {
|
|
265
|
-
/** 工具名称 */
|
|
266
|
-
name: string;
|
|
267
|
-
/** 工具描述 */
|
|
268
|
-
description: string;
|
|
269
|
-
/** 参数 Schema */
|
|
270
|
-
parameters: Parameters;
|
|
271
|
-
/** 初始化函数(可选) */
|
|
272
|
-
init?: (ctx?: ToolContext) => Promise<void>;
|
|
273
|
-
/** 执行函数 */
|
|
274
|
-
execute: (args: z.infer<Parameters>, ctx: ToolContext) => Promise<ToolResult>;
|
|
275
|
-
/** 参数验证错误格式化(可选) */
|
|
276
|
-
formatValidationError?: (error: ZodError) => string;
|
|
277
|
-
/** 沙箱配置 */
|
|
278
|
-
sandbox?: ToolSandboxConfig;
|
|
279
|
-
/** 权限配置 */
|
|
280
|
-
permission?: ToolPermissionConfig;
|
|
281
|
-
/** 工具元数据 */
|
|
282
|
-
metadata?: ToolMetadata;
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* 工具类型别名
|
|
286
|
-
*/
|
|
287
|
-
type Tool = ToolInfo;
|
|
288
|
-
type AbortSignalType = AbortSignal;
|
|
289
|
-
interface ProjectSummary {
|
|
290
|
-
projectPath: string;
|
|
291
|
-
projectName: string;
|
|
292
|
-
lastUpdated: number;
|
|
293
|
-
summary: string;
|
|
294
|
-
shortSummary: string;
|
|
295
|
-
draftCount: number;
|
|
296
|
-
memoryMdPath: string;
|
|
297
|
-
draftsDir: string;
|
|
298
|
-
detailsDir: string;
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Agent 执行上下文
|
|
302
|
-
*/
|
|
303
|
-
interface AgentContext {
|
|
304
|
-
/** 会话 ID */
|
|
305
|
-
sessionId?: string;
|
|
306
|
-
/** 消息 ID */
|
|
307
|
-
messageId?: string;
|
|
308
|
-
/** 中断信号 */
|
|
309
|
-
abort?: AbortSignalType;
|
|
310
|
-
/** 额外的上下文信息(会添加到 system prompt) */
|
|
311
|
-
additionInfo?: string;
|
|
312
|
-
/** 元数据 */
|
|
313
|
-
metadata?: Record<string, unknown>;
|
|
314
|
-
/** Agent 类型(用于选择 Behavior Spec) */
|
|
315
|
-
agentType?: string;
|
|
316
|
-
/** 使用的模型 */
|
|
317
|
-
model?: string;
|
|
318
|
-
/** 允许的工具列表(上下文级别,会覆盖 agent 配置) */
|
|
319
|
-
allowedTools?: string[];
|
|
320
|
-
/** 拒绝的工具列表(上下文级别,会覆盖 agent 配置) */
|
|
321
|
-
deniedTools?: string[];
|
|
322
|
-
/** 是否过滤 history 中的 tool 消息(上下文级别,会覆盖 agent 配置) */
|
|
323
|
-
filterHistory?: boolean;
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* 工具调用(内部使用)
|
|
327
|
-
*/
|
|
328
|
-
interface ToolCall2 {
|
|
329
|
-
/** 调用 ID */
|
|
330
|
-
id: string;
|
|
331
|
-
/** 工具名称 */
|
|
332
|
-
name: string;
|
|
333
|
-
/** 调用参数 */
|
|
334
|
-
arguments: Record<string, unknown>;
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* 工具调用结果
|
|
338
|
-
*/
|
|
339
|
-
interface ToolCallResult {
|
|
340
|
-
/** 调用 ID */
|
|
341
|
-
id: string;
|
|
342
|
-
/** 工具名称 */
|
|
343
|
-
name: string;
|
|
344
|
-
/** 调用结果 */
|
|
345
|
-
result: ToolResult;
|
|
346
|
-
/** 是否成功 */
|
|
347
|
-
success: boolean;
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Hook 点枚举(带 component 前缀)
|
|
351
|
-
*/
|
|
352
|
-
type HookPoint = "agent:before.start" | "agent:before.llm" | "agent:after.llm" | "agent:before.tool" | "agent:after.tool" | "agent:on.iteration" | "agent:on.threshold" | "agent:after.complete" | "agent:on.error" | "agent:after.react" | "on.error";
|
|
353
|
-
/**
|
|
354
|
-
* Hook 上下文(Agent 特有版本)
|
|
355
|
-
*
|
|
356
|
-
* 注意:这是 AgentComponent 使用的 HookContext 扩展版本
|
|
357
|
-
* 包含 iteration, maxIterations, messages 等 Agent 特有字段
|
|
358
|
-
*/
|
|
359
|
-
interface HookContext2 {
|
|
360
|
-
/** 当前 LLM 输出(after.llm hook 可用) */
|
|
361
|
-
llmOutput?: AgentLLMOutput;
|
|
362
|
-
/** 当前工具调用(before.tool/after.tool hook 可用) */
|
|
363
|
-
currentToolCall?: ToolCall2;
|
|
364
|
-
/** 工具执行结果(after.tool hook 可用) */
|
|
365
|
-
toolResult?: ToolCallResult;
|
|
366
|
-
/** 阈值信息(on.threshold hook 可用) */
|
|
367
|
-
threshold?: {
|
|
368
|
-
type: "tokens" | "turns" | "iterations" | "custom";
|
|
369
|
-
value: number;
|
|
370
|
-
limit?: number;
|
|
371
|
-
};
|
|
372
|
-
/** 当前错误(on.error hook 可用) */
|
|
373
|
-
error?: Error;
|
|
374
|
-
/** 当前 Agent 实例 */
|
|
375
|
-
agent: AgentInstance;
|
|
376
|
-
/** 当前迭代次数(可修改) */
|
|
377
|
-
iteration: number;
|
|
378
|
-
/** 最大迭代次数限制(before.llm hook 可用) */
|
|
379
|
-
maxIterations: number;
|
|
380
|
-
/** 消息列表(可直接修改) */
|
|
381
|
-
messages: ModelMessage2[];
|
|
382
|
-
/** 可用工具列表(可直接修改) */
|
|
383
|
-
tools: Tool[];
|
|
384
|
-
/** 当前 system prompt(可直接修改) */
|
|
385
|
-
systemPrompt: string;
|
|
386
|
-
/** 额外的上下文信息(可直接修改) */
|
|
387
|
-
additionInfo?: string;
|
|
388
|
-
/** 执行上下文(可直接修改属性) */
|
|
389
|
-
context: AgentContext;
|
|
390
|
-
/** 是否已停止 */
|
|
391
|
-
_stopped?: boolean;
|
|
392
|
-
/** 停止原因 */
|
|
393
|
-
_stopReason?: string;
|
|
394
|
-
/** 待执行的干预动作 */
|
|
395
|
-
_pendingAction?: {
|
|
396
|
-
type: HookActionType2;
|
|
397
|
-
payload?: unknown;
|
|
398
|
-
};
|
|
399
|
-
/** 错误列表 */
|
|
400
|
-
_errors?: Array<{
|
|
401
|
-
plugin: string;
|
|
402
|
-
error: string;
|
|
403
|
-
}>;
|
|
404
|
-
/** Project Memory Agent 生成的摘要列表(由 Project Agent 写入,Global Agent 读取) */
|
|
405
|
-
projectSummaries?: ProjectSummary[];
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* Hook 干预动作
|
|
409
|
-
*/
|
|
410
|
-
type HookActionType2 = "stop" | "retry" | "compress" | "extract_memory" | "inject_message" | "skip_tool";
|
|
411
|
-
/**
|
|
412
|
-
* Hook 返回结果
|
|
413
|
-
*/
|
|
414
|
-
interface HookResult2 {
|
|
415
|
-
/** 是否继续执行(false = 停止 Agent) */
|
|
416
|
-
continue: boolean;
|
|
417
|
-
/** 干预动作(可选) */
|
|
418
|
-
action?: {
|
|
419
|
-
type: HookActionType2;
|
|
420
|
-
payload?: unknown;
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
/**
|
|
424
|
-
* Plugin 定义
|
|
425
|
-
*/
|
|
426
|
-
interface Plugin {
|
|
427
|
-
/** Plugin 唯一名称 */
|
|
428
|
-
name: string;
|
|
429
|
-
/** Plugin 版本 */
|
|
430
|
-
version: string;
|
|
431
|
-
/** Plugin 描述 */
|
|
432
|
-
description?: string;
|
|
433
|
-
/** 订阅的 Hook 点及优先级 */
|
|
434
|
-
hooks: Array<{
|
|
435
|
-
point: HookPoint;
|
|
436
|
-
/** 优先级,默认 0,数字越大越先执行 */
|
|
437
|
-
priority?: number;
|
|
438
|
-
}>;
|
|
439
|
-
/** 执行函数 */
|
|
440
|
-
execute: (ctx: HookContext2) => HookResult2 | Promise<HookResult2>;
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* Agent 类型
|
|
444
|
-
*/
|
|
445
|
-
type AgentType = "primary" | "sub" | "summary";
|
|
446
|
-
/**
|
|
447
|
-
* Agent 状态
|
|
448
|
-
*/
|
|
449
|
-
type AgentStatus = "idle" | "running" | "paused" | "stopped" | "error";
|
|
450
|
-
/**
|
|
451
|
-
* Agent 实例配置
|
|
452
|
-
*/
|
|
453
|
-
interface AgentInstanceConfig {
|
|
454
|
-
/** Agent 类型 */
|
|
455
|
-
type: AgentType;
|
|
456
|
-
/** Agent 名称 */
|
|
457
|
-
name?: string;
|
|
458
|
-
/** System Prompt */
|
|
459
|
-
systemPrompt?: string;
|
|
460
|
-
/** Behavior Spec ID */
|
|
461
|
-
behaviorSpecId?: string;
|
|
462
|
-
/** 使用的模型 */
|
|
463
|
-
model?: string;
|
|
464
|
-
/** 最大迭代次数 */
|
|
465
|
-
maxIterations?: number;
|
|
466
|
-
/** 最大错误重试次数 */
|
|
467
|
-
maxErrorRetries?: number;
|
|
468
|
-
/** 死循环检测阈值 */
|
|
469
|
-
doomLoopThreshold?: number;
|
|
470
|
-
/** 允许的工具列表 */
|
|
471
|
-
allowedTools?: string[];
|
|
472
|
-
/** 拒绝的工具列表 */
|
|
473
|
-
deniedTools?: string[];
|
|
474
|
-
/** 工具超时(毫秒) */
|
|
475
|
-
toolTimeout?: number;
|
|
476
|
-
/** 工具重试次数 */
|
|
477
|
-
toolRetries?: number;
|
|
478
|
-
/** 是否过滤 history 中的 tool 消息(默认过滤,避免上下文过长) */
|
|
479
|
-
filterHistory?: boolean;
|
|
480
|
-
}
|
|
481
|
-
/**
|
|
482
|
-
* Agent 实例
|
|
483
|
-
*/
|
|
484
|
-
interface AgentInstance {
|
|
485
|
-
/** Agent 名称 */
|
|
486
|
-
name: string;
|
|
487
|
-
/** Agent 配置 */
|
|
488
|
-
config: Required<AgentInstanceConfig>;
|
|
489
|
-
/** 当前状态 */
|
|
490
|
-
status: AgentStatus;
|
|
491
|
-
/** 注册的 Plugins */
|
|
492
|
-
plugins: Map<string, Plugin>;
|
|
493
|
-
}
|
|
494
|
-
/**
|
|
495
|
-
* Agent 内部使用的 LLM 输出
|
|
496
|
-
* 独立定义以避免与 LLMOutput 的类型冲突
|
|
497
|
-
*/
|
|
498
|
-
interface AgentLLMOutput {
|
|
499
|
-
/** 生成的内容 */
|
|
500
|
-
content: string;
|
|
501
|
-
/** 完成原因 */
|
|
502
|
-
finishReason: "stop" | "length" | "content-filter" | "tool-calls" | "function-call";
|
|
503
|
-
/** 工具调用(兼容格式) */
|
|
504
|
-
toolCalls?: Array<{
|
|
505
|
-
id: string;
|
|
506
|
-
function?: {
|
|
507
|
-
name: string;
|
|
508
|
-
arguments: string;
|
|
509
|
-
};
|
|
510
|
-
name?: string;
|
|
511
|
-
arguments?: string;
|
|
512
|
-
}>;
|
|
513
|
-
/** Usage 信息 */
|
|
514
|
-
usage?: {
|
|
515
|
-
promptTokens: number;
|
|
516
|
-
completionTokens: number;
|
|
517
|
-
totalTokens: number;
|
|
518
|
-
};
|
|
519
|
-
/** 生成模型 */
|
|
520
|
-
model?: string;
|
|
521
|
-
/** 推理内容(思考过程) */
|
|
522
|
-
reasoning?: string;
|
|
523
|
-
}
|
|
524
|
-
/**
|
|
525
|
-
* MemoryPlugin - Simplified
|
|
526
|
-
*
|
|
527
|
-
* 简化的记忆插件,不再自动处理。
|
|
528
|
-
*
|
|
529
|
-
* 用户应该使用 `roy memory recall --extract` 命令来手动触发记忆提取。
|
|
530
|
-
*
|
|
531
|
-
* 保留此插件是为了:
|
|
532
|
-
* 1. 保持 API 兼容性
|
|
533
|
-
* 2. 未来可以扩展为可选的自动触发
|
|
534
|
-
*/
|
|
535
|
-
declare class MemoryPlugin {
|
|
536
|
-
private config;
|
|
537
|
-
private disposed;
|
|
538
|
-
private initialized;
|
|
539
|
-
/** 项目 memory 基础目录 */
|
|
540
|
-
private projectBaseDir;
|
|
541
|
-
/** 全局 memory 基础目录 */
|
|
542
|
-
private globalBaseDir;
|
|
543
|
-
/** 当前工作目录(用于推断项目路径) */
|
|
544
|
-
private workDir;
|
|
545
|
-
/** AgentComponent 引用(延迟获取) */
|
|
546
|
-
private agentComponent;
|
|
547
|
-
constructor(baseDir: string, config?: MemoryPluginConfig);
|
|
548
|
-
/**
|
|
549
|
-
* Plugin 名称
|
|
550
|
-
*/
|
|
551
|
-
get name(): string;
|
|
552
|
-
/**
|
|
553
|
-
* 订阅的 Hook 点
|
|
554
|
-
*/
|
|
555
|
-
get hookPoint(): "agent:after.react";
|
|
556
|
-
/**
|
|
557
|
-
* 优先级
|
|
558
|
-
*/
|
|
559
|
-
get priority(): number;
|
|
560
|
-
/**
|
|
561
|
-
* 描述
|
|
562
|
-
*/
|
|
563
|
-
get description(): string;
|
|
564
|
-
/**
|
|
565
|
-
* 获取 Hook 定义
|
|
566
|
-
*/
|
|
567
|
-
get hooks(): unknown;
|
|
568
|
-
/**
|
|
569
|
-
* 初始化
|
|
570
|
-
*/
|
|
571
|
-
initialize(): Promise<void>;
|
|
572
|
-
/**
|
|
573
|
-
* 执行 Hook
|
|
574
|
-
*
|
|
575
|
-
* 简化为空操作。用户应该使用 `roy memory recall --extract` 命令。
|
|
576
|
-
*/
|
|
577
|
-
execute(ctx: HookContext2): Promise<void>;
|
|
578
|
-
/**
|
|
579
|
-
* 准备关闭
|
|
580
|
-
*/
|
|
581
|
-
prepareShutdown(): void;
|
|
582
|
-
/**
|
|
583
|
-
* 检查是否有待处理任务
|
|
584
|
-
*/
|
|
585
|
-
hasPendingTasks(): boolean;
|
|
586
|
-
/**
|
|
587
|
-
* 等待处理完成
|
|
588
|
-
*/
|
|
589
|
-
waitForCompletion(): Promise<void>;
|
|
590
|
-
/**
|
|
591
|
-
* 释放资源
|
|
592
|
-
*/
|
|
593
|
-
dispose(): Promise<void>;
|
|
594
|
-
/**
|
|
595
|
-
* 获取项目 base dir
|
|
596
|
-
*/
|
|
597
|
-
getProjectBaseDir(): string;
|
|
598
|
-
/**
|
|
599
|
-
* 获取全局 base dir
|
|
600
|
-
*/
|
|
601
|
-
getGlobalBaseDir(): string;
|
|
602
|
-
}
|
|
603
|
-
/**
|
|
604
|
-
* 创建 MemoryPlugin 实例
|
|
605
|
-
*/
|
|
606
|
-
declare function createMemoryPlugin(baseDir: string, config?: MemoryPluginConfig): MemoryPlugin;
|
|
607
|
-
/**
|
|
608
|
-
* Memory 来源类型
|
|
609
|
-
* - project: 项目级记忆
|
|
610
|
-
* - global: 全局记忆
|
|
611
|
-
*/
|
|
612
|
-
type MemorySource = "project" | "global";
|
|
613
|
-
/**
|
|
614
|
-
* Memory 路径配置
|
|
615
|
-
*/
|
|
616
|
-
interface MemoryPath {
|
|
617
|
-
/** 来源类型 */
|
|
618
|
-
type: MemorySource;
|
|
619
|
-
/** 绝对路径 */
|
|
620
|
-
path: string;
|
|
621
|
-
}
|
|
622
|
-
/**
|
|
623
|
-
* 读取记忆文件
|
|
624
|
-
*
|
|
625
|
-
* @param memoryPaths - 记忆路径列表
|
|
626
|
-
* @returns 记忆内容
|
|
627
|
-
*/
|
|
628
|
-
declare function recallMemory(memoryPaths: MemoryPath[]): Promise<string>;
|
|
629
|
-
import { ModelMessage as ModelMessage3 } from "ai";
|
|
630
|
-
/**
|
|
631
|
-
* Memory 作用域类型
|
|
632
|
-
*/
|
|
633
|
-
type MemoryScope = "project" | "global";
|
|
634
|
-
/**
|
|
635
|
-
* 项目摘要信息
|
|
636
|
-
*/
|
|
637
|
-
interface ProjectSummary2 {
|
|
638
|
-
/** 项目根目录路径 */
|
|
639
|
-
projectPath: string;
|
|
640
|
-
/** 项目名称 */
|
|
641
|
-
projectName: string;
|
|
642
|
-
/** 最后更新时间戳 */
|
|
643
|
-
lastUpdated: number;
|
|
644
|
-
/** 项目 memory.md 摘要(一段话) */
|
|
645
|
-
summary: string;
|
|
646
|
-
/** 简短摘要(几个词) */
|
|
647
|
-
shortSummary: string;
|
|
648
|
-
/** 项目 memory.md 路径 */
|
|
649
|
-
memoryMdPath: string;
|
|
650
|
-
}
|
|
651
|
-
/**
|
|
652
|
-
* Memory Agent 输入
|
|
653
|
-
*/
|
|
654
|
-
interface MemoryAgentInput {
|
|
655
|
-
/** 作用域 */
|
|
656
|
-
scope: MemoryScope;
|
|
657
|
-
/** 基础目录(project: .roy/memory, global: ~/.config/roy-agent/memory) */
|
|
658
|
-
baseDir: string;
|
|
659
|
-
/** 当前 memory.md 内容 */
|
|
660
|
-
currentMemoryMd: string;
|
|
661
|
-
/** 当前对话消息 */
|
|
662
|
-
messages: ModelMessage3[];
|
|
663
|
-
/** 项目摘要列表(仅 global scope 使用) */
|
|
664
|
-
projectSummaries?: ProjectSummary2[];
|
|
665
|
-
}
|
|
666
|
-
/**
|
|
667
|
-
* Memory Agent 输出结果
|
|
668
|
-
*/
|
|
669
|
-
interface MemoryAgentResult {
|
|
670
|
-
/** 作用域 */
|
|
671
|
-
scope: MemoryScope;
|
|
672
|
-
/** 新的 memory.md 内容(全文) */
|
|
673
|
-
memoryMdContent: string;
|
|
674
|
-
/** 项目摘要(仅 project scope 输出) */
|
|
675
|
-
projectSummary?: ProjectSummary2;
|
|
676
|
-
/** 是否有更新 */
|
|
677
|
-
hasUpdates: boolean;
|
|
678
|
-
}
|
|
679
|
-
/**
|
|
680
|
-
* Memory Agent 配置
|
|
681
|
-
*/
|
|
682
|
-
interface MemoryAgentConfig {
|
|
683
|
-
/** Agent 名称 */
|
|
684
|
-
name: string;
|
|
685
|
-
/** System prompt */
|
|
686
|
-
systemPrompt: string;
|
|
687
|
-
/** 最大迭代次数 */
|
|
688
|
-
maxIterations: number;
|
|
689
|
-
}
|
|
690
|
-
/**
|
|
691
|
-
* Project Memory Agent System Prompt
|
|
692
|
-
*/
|
|
693
|
-
declare const PROJECT_MEMORY_AGENT_PROMPT = "你是项目级 Memory Agent,负责整理和更新当前项目的记忆。\n\n## 你的职责\n\n1. **信息收集**:在提取记忆前,先收集项目上下文信息\n2. **从对话中提取记忆**:分析 messages,提取与项目相关的知识、决策、解决方案\n3. **生成 memory.md**:更新项目记忆索引\n\n## 信息收集步骤(重要!)\n\n在提取记忆之前,请先使用可用工具收集项目上下文:\n\n1. **阅读项目 README**:了解项目概述、功能、使用方法\n - 路径示例:README.md, README.zh-CN.md, docs/README.md\n\n2. **检查设计文档**:了解项目架构和设计决策\n - 路径示例:docs/design.md, docs/ARCHITECTURE.md, docs/superpowers/specs/*.md\n\n3. **查看代码实现**:了解关键模块和实现细节\n - 路径示例:src/**/*.ts, packages/*/src/**/*.ts\n\n4. **回顾现有 memory**:了解已有的项目记忆\n - 路径:当前目录下的 .roy/memory/memory.md\n\n## 输入信息\n\n- 当前项目的 memory.md 内容\n- 当前对话消息\n\n## 输出要求\n\n请以 JSON 格式输出结果,包含以下字段:\n- memoryMdContent: 新的 memory.md 内容\n- projectSummary: 项目摘要(包含 summary, shortSummary 等)\n- hasUpdates: 是否有更新\n\n## 记忆组织原则\n\n- 优先记录具体、可操作的记忆(代码位置、配置项、命令)\n- 避免过于抽象或通用的描述\n- 记录设计决策及其理由";
|
|
694
|
-
/**
|
|
695
|
-
* Global Memory Agent System Prompt
|
|
696
|
-
*/
|
|
697
|
-
declare const GLOBAL_MEMORY_AGENT_PROMPT = "你是全局 Memory Agent,负责整理跨项目的通用记忆。\n\n## 你的职责\n\n1. **聚合项目摘要**:分析 projectSummaries,提取共性知识\n2. **维护全局记忆**:更新全局 memory.md\n3. **维护项目索引**:在 memory.md 中维护项目列表\n4. **提取共性经验**:将项目经验提炼为通用最佳实践\n\n## 输入信息\n\n- 全局 memory.md 内容\n- 当前对话消息\n- 项目摘要列表(projectSummaries)\n\n## 输出要求\n\n请以 JSON 格式输出结果,包含以下字段:\n- memoryMdContent: 新的 memory.md 内容\n- hasUpdates: 是否有更新\n\n## 记忆组织原则\n\n- 关注跨项目共性(工作流、规范、偏好)\n- 项目索引只记录摘要和路径,不复制内容\n- 用户个人偏好(饮食、工作习惯)优先记录";
|
|
698
|
-
/**
|
|
699
|
-
* 创建 Memory Agent 配置
|
|
700
|
-
*/
|
|
701
|
-
declare function createMemoryAgent(scope: MemoryScope): MemoryAgentConfig;
|
|
702
|
-
/**
|
|
703
|
-
* 格式化 Memory Agent 输入为字符串
|
|
704
|
-
*/
|
|
705
|
-
declare function formatMemoryInput(input: MemoryAgentInput): string;
|
|
706
|
-
/**
|
|
707
|
-
* 解析 Memory Agent 输出
|
|
708
|
-
*/
|
|
709
|
-
declare function parseMemoryAgentOutput(output: string, scope: MemoryScope): MemoryAgentResult;
|
|
710
|
-
/**
|
|
711
|
-
* 创建默认的 MemoryAgentResult
|
|
712
|
-
*/
|
|
713
|
-
declare function createEmptyResult(scope: MemoryScope): MemoryAgentResult;
|
|
714
|
-
/**
|
|
715
|
-
* 构建 Project Memory Agent 输入
|
|
716
|
-
*/
|
|
717
|
-
declare function buildProjectInput(params: {
|
|
718
|
-
projectPath: string;
|
|
719
|
-
currentMemoryMd: string;
|
|
720
|
-
messages: ModelMessage3[];
|
|
721
|
-
}): Promise<MemoryAgentInput>;
|
|
722
|
-
/**
|
|
723
|
-
* 构建 Global Memory Agent 输入
|
|
724
|
-
*/
|
|
725
|
-
declare function buildGlobalInput(params: {
|
|
726
|
-
baseDir: string;
|
|
727
|
-
currentMemoryMd: string;
|
|
728
|
-
messages: ModelMessage3[];
|
|
729
|
-
projectSummaries?: ProjectSummary2[];
|
|
730
|
-
}): MemoryAgentInput;
|
|
731
|
-
/**
|
|
732
|
-
* 应用 Memory Agent 结果到文件系统
|
|
733
|
-
*
|
|
734
|
-
* @param result MemoryAgent 结果
|
|
735
|
-
* @param baseDir 基础目录
|
|
736
|
-
*/
|
|
737
|
-
declare function applyMemoryResult(result: MemoryAgentResult, baseDir: string): Promise<void>;
|
|
738
|
-
/**
|
|
739
|
-
* 生成项目摘要
|
|
740
|
-
*/
|
|
741
|
-
declare function generateProjectSummary(params: {
|
|
742
|
-
projectPath: string;
|
|
743
|
-
projectName: string;
|
|
744
|
-
memoryMdContent: string;
|
|
745
|
-
memoryMdPath: string;
|
|
746
|
-
}): ProjectSummary2;
|
|
747
|
-
export { recallMemory, parseMemoryAgentOutput, generateProjectSummary, formatMemoryInput, createMemoryPlugin, createMemoryAgent, createEmptyResult, buildProjectInput, buildGlobalInput, applyMemoryResult, SessionMessage, ProjectSummary2 as ProjectSummary, PROJECT_MEMORY_AGENT_PROMPT, MemoryTaskType, MemoryTask, MemoryScope, MemoryPluginConfig, MemoryPlugin, MemoryManager, MemoryHookContext, MemoryAgentResult, MemoryAgentInput, MemoryAgentConfig, GLOBAL_MEMORY_AGENT_PROMPT, ExtractMemoryPayload };
|