@ai-setting/roy-agent-core 1.4.13 → 1.4.14
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/packages/core/src/config/index.js +32 -0
- package/dist/packages/core/src/env/agent/index.js +24 -0
- package/dist/packages/core/src/env/commands/index.js +14 -0
- package/dist/packages/core/src/env/debug/formatters/index.js +11 -0
- package/dist/packages/core/src/env/debug/index.js +26 -0
- package/dist/packages/core/src/env/hook/index.js +29 -0
- package/dist/packages/core/src/env/index.js +81 -0
- package/dist/packages/core/src/env/llm/index.js +40 -0
- package/dist/packages/core/src/env/log-trace/index.js +83 -0
- package/dist/packages/core/src/env/mcp/index.js +39 -0
- package/dist/packages/core/src/env/mcp/tool/index.js +14 -0
- package/dist/packages/core/src/env/memory/built-in/index.js +11 -0
- package/dist/packages/core/src/env/memory/index.js +56 -0
- package/dist/packages/core/src/env/memory/plugin/index.js +36 -0
- package/dist/packages/core/src/env/prompt/index.js +20 -0
- package/dist/packages/core/src/env/session/index.js +25 -0
- package/dist/packages/core/src/env/session/storage/index.js +18 -0
- package/dist/packages/core/src/env/skill/index.js +34 -0
- package/dist/packages/core/src/env/skill/tool/index.js +9 -0
- package/dist/packages/core/src/env/task/delegate/index.js +18 -0
- package/dist/packages/core/src/env/task/hooks/index.js +7 -0
- package/dist/packages/core/src/env/task/index.js +30 -0
- package/dist/packages/core/src/env/task/plugins/index.js +23 -0
- package/dist/packages/core/src/env/task/storage/index.js +14 -0
- package/dist/packages/core/src/env/task/tools/index.js +17 -0
- package/dist/packages/core/src/env/task/tools/operation/index.js +15 -0
- package/dist/{shared/chunk-1d4rwms4.js → packages/core/src/env/tool/built-in/index.js} +4 -4
- package/dist/packages/core/src/env/tool/index.js +39 -0
- package/dist/packages/core/src/env/workflow/decorators/index.js +27 -0
- package/dist/packages/core/src/env/workflow/engine/index.js +28 -0
- package/dist/packages/core/src/env/workflow/index.js +132 -0
- package/dist/packages/core/src/env/workflow/nodes/index.js +19 -0
- package/dist/packages/core/src/env/workflow/service/index.js +13 -0
- package/dist/packages/core/src/env/workflow/storage/index.js +27 -0
- package/dist/packages/core/src/env/workflow/tools/index.js +159 -0
- package/dist/packages/core/src/env/workflow/types/index.js +94 -0
- package/dist/packages/core/src/env/workflow/utils/index.js +637 -0
- package/dist/packages/core/src/index.js +398 -0
- package/dist/shared/@ai-setting/roy-agent-core-04fm8177.js +393 -0
- package/dist/shared/@ai-setting/roy-agent-core-04qgbjbe.js +172 -0
- package/dist/shared/@ai-setting/roy-agent-core-084qqd7t.js +11 -0
- package/dist/shared/@ai-setting/roy-agent-core-0gekht4e.js +1130 -0
- package/dist/shared/@ai-setting/roy-agent-core-0hdry23r.js +419 -0
- package/dist/shared/{chunk-ze20rksg.js → @ai-setting/roy-agent-core-0sgn3de4.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-12x57kf1.js +286 -0
- package/dist/shared/@ai-setting/roy-agent-core-1f3xrrm6.js +393 -0
- package/dist/shared/{chunk-q9j99fsm.js → @ai-setting/roy-agent-core-1k28kg7h.js} +6 -6
- package/dist/shared/{chunk-2b5kbhx3.js → @ai-setting/roy-agent-core-1z1zv5g8.js} +9 -117
- package/dist/shared/@ai-setting/roy-agent-core-2hqxnaf3.js +851 -0
- package/dist/shared/@ai-setting/roy-agent-core-3dfq8awb.js +587 -0
- package/dist/shared/@ai-setting/roy-agent-core-3takar0s.js +93 -0
- package/dist/shared/@ai-setting/roy-agent-core-3tnb2005.js +117 -0
- package/dist/shared/@ai-setting/roy-agent-core-4vmcvkav.js +14 -0
- package/dist/shared/{chunk-25x2pdtp.js → @ai-setting/roy-agent-core-4ws8atva.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-5fbp24se.js +603 -0
- package/dist/shared/@ai-setting/roy-agent-core-5my94ywp.js +66 -0
- package/dist/shared/{chunk-rncy3rtd.js → @ai-setting/roy-agent-core-6j0zcmwk.js} +128 -1122
- package/dist/shared/@ai-setting/roy-agent-core-6w4pmxc7.js +266 -0
- package/dist/shared/{chunk-yqmx37vm.js → @ai-setting/roy-agent-core-7vrk3add.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-8dvbn7tw.js +64 -0
- package/dist/shared/@ai-setting/roy-agent-core-8mbmrwzs.js +171 -0
- package/dist/shared/@ai-setting/roy-agent-core-8wzz66qe.js +620 -0
- package/dist/shared/@ai-setting/roy-agent-core-9ykq91jc.js +762 -0
- package/dist/shared/@ai-setting/roy-agent-core-dde19zke.js +1305 -0
- package/dist/shared/@ai-setting/roy-agent-core-f7g67gce.js +913 -0
- package/dist/shared/@ai-setting/roy-agent-core-fq5mtxsy.js +341 -0
- package/dist/shared/@ai-setting/roy-agent-core-fvd9g6k8.js +1205 -0
- package/dist/shared/@ai-setting/roy-agent-core-gv1hrn3x.js +378 -0
- package/dist/shared/@ai-setting/roy-agent-core-gy0wp5h7.js +213 -0
- package/dist/shared/{chunk-mf5xqbdh.js → @ai-setting/roy-agent-core-hyza1gm7.js} +3 -2
- package/dist/shared/{chunk-1qwabsm0.js → @ai-setting/roy-agent-core-j8zx62zr.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-jb2exr0d.js +442 -0
- package/dist/shared/@ai-setting/roy-agent-core-jv3b7v9w.js +57 -0
- package/dist/shared/@ai-setting/roy-agent-core-k1rxf9ya.js +513 -0
- package/dist/shared/@ai-setting/roy-agent-core-kydc9nwb.js +60 -0
- package/dist/shared/@ai-setting/roy-agent-core-m2x48hw6.js +97 -0
- package/dist/shared/@ai-setting/roy-agent-core-m6y668cc.js +377 -0
- package/dist/shared/{chunk-1aakcfp1.js → @ai-setting/roy-agent-core-nczzf0ms.js} +3 -3
- package/dist/shared/@ai-setting/roy-agent-core-nfj6knp5.js +36 -0
- package/dist/shared/@ai-setting/roy-agent-core-ntrp979d.js +204 -0
- package/dist/shared/@ai-setting/roy-agent-core-pd7g8z5v.js +1387 -0
- package/dist/shared/@ai-setting/roy-agent-core-pzk1syce.js +14 -0
- package/dist/shared/@ai-setting/roy-agent-core-q50tg9m2.js +862 -0
- package/dist/shared/{chunk-9qzt1v1p.js → @ai-setting/roy-agent-core-qg9tcaph.js} +3 -2
- package/dist/shared/{chunk-91bas8w5.js → @ai-setting/roy-agent-core-qhyerewk.js} +5 -5
- package/dist/shared/{chunk-1pf5mfgd.js → @ai-setting/roy-agent-core-qxybm159.js} +3 -3
- package/dist/shared/{chunk-g6j5n3gv.js → @ai-setting/roy-agent-core-rh9dpkpw.js} +10 -10
- package/dist/shared/{chunk-0q6s9wm6.js → @ai-setting/roy-agent-core-rr9p1g43.js} +7 -51
- package/dist/shared/@ai-setting/roy-agent-core-sbzvpfn7.js +284 -0
- package/dist/shared/@ai-setting/roy-agent-core-t22nqt4d.js +788 -0
- package/dist/shared/{chunk-t1rh6jtm.js → @ai-setting/roy-agent-core-tkr5ynkh.js} +8 -13
- package/dist/shared/@ai-setting/roy-agent-core-v4aabsf0.js +303 -0
- package/dist/shared/@ai-setting/roy-agent-core-w75rafhy.js +202 -0
- package/dist/shared/@ai-setting/roy-agent-core-w76hqkmg.js +584 -0
- package/dist/shared/@ai-setting/roy-agent-core-yfbgwes2.js +408 -0
- package/dist/shared/{chunk-a9qmy3sc.js → @ai-setting/roy-agent-core-yn761yve.js} +7 -4
- package/dist/shared/@ai-setting/roy-agent-core-yrzmn4m1.js +492 -0
- package/dist/shared/@ai-setting/roy-agent-core-yt8wdh2w.js +206 -0
- package/package.json +8 -7
- package/dist/index.d.ts +0 -7825
- package/dist/index.js +0 -16551
- package/dist/shared/chunk-hs7tbmje.js +0 -24
- /package/dist/shared/{chunk-wbkh7wat.js → @ai-setting/roy-agent-core-fs0mn2jk.js} +0 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createLogger,
|
|
3
|
+
init_logger
|
|
4
|
+
} from "./roy-agent-core-yn761yve.js";
|
|
5
|
+
import {
|
|
6
|
+
__require
|
|
7
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
8
|
+
|
|
9
|
+
// packages/core/src/env/memory/plugin/memory-manager.ts
|
|
10
|
+
init_logger();
|
|
11
|
+
var logger = createLogger("MemoryManagerV3");
|
|
12
|
+
function generateTaskId() {
|
|
13
|
+
return `task_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
class MemoryManager {
|
|
17
|
+
static MAX_QUEUE_SIZE = 100;
|
|
18
|
+
queue = [];
|
|
19
|
+
processing = false;
|
|
20
|
+
shuttingDown = false;
|
|
21
|
+
config;
|
|
22
|
+
processingPromise = null;
|
|
23
|
+
resolveProcessing = null;
|
|
24
|
+
constructor(config = {}) {
|
|
25
|
+
this.config = config;
|
|
26
|
+
}
|
|
27
|
+
updateConfig(config) {
|
|
28
|
+
this.config = { ...this.config, ...config };
|
|
29
|
+
}
|
|
30
|
+
enqueue(task) {
|
|
31
|
+
if (this.shuttingDown) {
|
|
32
|
+
logger.debug("MemoryManager is shutting down, ignoring new task");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const fullTask = {
|
|
36
|
+
...task,
|
|
37
|
+
id: generateTaskId()
|
|
38
|
+
};
|
|
39
|
+
if (this.queue.length >= MemoryManager.MAX_QUEUE_SIZE) {
|
|
40
|
+
const dropped = this.queue.shift();
|
|
41
|
+
logger.warn(`Queue full (${MemoryManager.MAX_QUEUE_SIZE}), dropping oldest task: ${dropped?.id}`);
|
|
42
|
+
}
|
|
43
|
+
this.queue.push(fullTask);
|
|
44
|
+
logger.debug(`Task enqueued: ${task.type}, queue size: ${this.queue.length}`);
|
|
45
|
+
if (!this.processing) {
|
|
46
|
+
this.startProcessingLoop();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
startProcessingLoop() {
|
|
50
|
+
const runLoop = async () => {
|
|
51
|
+
while (this.queue.length > 0 && !this.shuttingDown) {
|
|
52
|
+
const task = this.queue.shift();
|
|
53
|
+
try {
|
|
54
|
+
await this.processTask(task);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
logger.error(`Task ${task.id} failed:`, error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
this.processing = false;
|
|
60
|
+
if (this.resolveProcessing) {
|
|
61
|
+
this.resolveProcessing();
|
|
62
|
+
this.resolveProcessing = null;
|
|
63
|
+
this.processingPromise = null;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
this.processing = true;
|
|
67
|
+
this.processingPromise = new Promise((resolve) => {
|
|
68
|
+
this.resolveProcessing = resolve;
|
|
69
|
+
});
|
|
70
|
+
setImmediate(() => {
|
|
71
|
+
runLoop().catch((error) => {
|
|
72
|
+
logger.error("Processing loop error:", error);
|
|
73
|
+
this.processing = false;
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
hasPendingTasks() {
|
|
78
|
+
return this.queue.length > 0 || this.processing;
|
|
79
|
+
}
|
|
80
|
+
async waitForCompletion() {
|
|
81
|
+
if (this.queue.length === 0 && !this.processing) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (this.processingPromise) {
|
|
85
|
+
await this.processingPromise;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
prepareShutdown() {
|
|
89
|
+
this.shuttingDown = true;
|
|
90
|
+
logger.info("MemoryManager preparing for shutdown");
|
|
91
|
+
}
|
|
92
|
+
async dispose() {
|
|
93
|
+
await this.waitForCompletion();
|
|
94
|
+
this.queue = [];
|
|
95
|
+
logger.info("MemoryManager disposed");
|
|
96
|
+
}
|
|
97
|
+
async processTask(task) {
|
|
98
|
+
logger.debug(`Processing task: ${task.type}`);
|
|
99
|
+
switch (task.type) {
|
|
100
|
+
case "extract_memory":
|
|
101
|
+
await this.handleExtractMemory(task.payload);
|
|
102
|
+
break;
|
|
103
|
+
default:
|
|
104
|
+
logger.warn(`Unknown task type: ${task.type}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async handleExtractMemory(payload) {
|
|
108
|
+
const messageCount = payload.messages?.length || 0;
|
|
109
|
+
logger.info(`Extracting memory from ${messageCount} messages`);
|
|
110
|
+
if (this.config.onExtractMemory) {
|
|
111
|
+
try {
|
|
112
|
+
await this.config.onExtractMemory(payload);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
logger.error("Memory extraction failed", { error });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// packages/core/src/env/memory/plugin/types.ts
|
|
120
|
+
var DEFAULT_MEMORY_PLUGIN_CONFIG = {
|
|
121
|
+
enabled: true
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// packages/core/src/env/memory/plugin/memory-plugin.ts
|
|
125
|
+
init_logger();
|
|
126
|
+
import path from "path";
|
|
127
|
+
import os from "os";
|
|
128
|
+
var logger2 = createLogger("MemoryPlugin");
|
|
129
|
+
|
|
130
|
+
class MemoryPlugin {
|
|
131
|
+
config;
|
|
132
|
+
disposed = false;
|
|
133
|
+
initialized = false;
|
|
134
|
+
projectBaseDir = "";
|
|
135
|
+
globalBaseDir = "";
|
|
136
|
+
workDir = "";
|
|
137
|
+
agentComponent = null;
|
|
138
|
+
constructor(baseDir, config = {}) {
|
|
139
|
+
this.config = { ...DEFAULT_MEMORY_PLUGIN_CONFIG, ...config };
|
|
140
|
+
this.workDir = baseDir;
|
|
141
|
+
this.projectBaseDir = path.join(baseDir, ".roy", "memory");
|
|
142
|
+
this.globalBaseDir = path.join(os.homedir(), ".config", "roy-agent", "memory");
|
|
143
|
+
logger2.info("MemoryPlugin (simplified) created", { baseDir, config: this.config });
|
|
144
|
+
}
|
|
145
|
+
get name() {
|
|
146
|
+
return "MemoryPlugin";
|
|
147
|
+
}
|
|
148
|
+
get hookPoint() {
|
|
149
|
+
return "agent:after.react";
|
|
150
|
+
}
|
|
151
|
+
get priority() {
|
|
152
|
+
return 50;
|
|
153
|
+
}
|
|
154
|
+
get description() {
|
|
155
|
+
return "Memory management plugin. Use 'roy memory recall --extract' to extract memories.";
|
|
156
|
+
}
|
|
157
|
+
get hooks() {
|
|
158
|
+
return [
|
|
159
|
+
{
|
|
160
|
+
point: this.hookPoint,
|
|
161
|
+
priority: this.priority
|
|
162
|
+
}
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
async initialize() {
|
|
166
|
+
if (this.initialized) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
this.initialized = true;
|
|
170
|
+
logger2.info("MemoryPlugin (simplified) initialized");
|
|
171
|
+
}
|
|
172
|
+
async execute(ctx) {
|
|
173
|
+
if (this.disposed || !this.config.enabled || !this.initialized) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
logger2.debug("MemoryPlugin hook executed. Use 'roy memory recall --extract' for memory extraction.");
|
|
177
|
+
}
|
|
178
|
+
prepareShutdown() {}
|
|
179
|
+
hasPendingTasks() {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
async waitForCompletion() {}
|
|
183
|
+
async dispose() {
|
|
184
|
+
if (this.disposed) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
this.disposed = true;
|
|
188
|
+
logger2.info("MemoryPlugin (simplified) disposed");
|
|
189
|
+
}
|
|
190
|
+
getProjectBaseDir() {
|
|
191
|
+
return this.projectBaseDir;
|
|
192
|
+
}
|
|
193
|
+
getGlobalBaseDir() {
|
|
194
|
+
return this.globalBaseDir;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function createMemoryPlugin(baseDir, config) {
|
|
198
|
+
return new MemoryPlugin(baseDir, config);
|
|
199
|
+
}
|
|
200
|
+
// packages/core/src/env/memory/plugin/recall-memory.ts
|
|
201
|
+
import fs from "fs/promises";
|
|
202
|
+
import path2 from "path";
|
|
203
|
+
async function recallMemory(memoryPaths) {
|
|
204
|
+
const results = [];
|
|
205
|
+
for (const memoryPath of memoryPaths) {
|
|
206
|
+
const scope = memoryPath.type;
|
|
207
|
+
const baseDir = memoryPath.path;
|
|
208
|
+
try {
|
|
209
|
+
const memoryFile = path2.join(baseDir, "memory.md");
|
|
210
|
+
try {
|
|
211
|
+
const content = await fs.readFile(memoryFile, "utf-8");
|
|
212
|
+
if (content.trim()) {
|
|
213
|
+
results.push(`## [${scope}] memory.md
|
|
214
|
+
${content}`);
|
|
215
|
+
}
|
|
216
|
+
} catch {}
|
|
217
|
+
} catch (error) {
|
|
218
|
+
console.error(`Error processing memory path ${baseDir}:`, error);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (results.length === 0) {
|
|
222
|
+
return "(No memory files found)";
|
|
223
|
+
}
|
|
224
|
+
return results.join(`
|
|
225
|
+
|
|
226
|
+
`);
|
|
227
|
+
}
|
|
228
|
+
// packages/core/src/env/memory/plugin/memory-agent.ts
|
|
229
|
+
var PROJECT_MEMORY_AGENT_PROMPT = `你是项目级 Memory Agent,负责整理和更新当前项目的记忆。
|
|
230
|
+
|
|
231
|
+
## 你的职责
|
|
232
|
+
|
|
233
|
+
1. **信息收集**:在提取记忆前,先收集项目上下文信息
|
|
234
|
+
2. **从对话中提取记忆**:分析 messages,提取与项目相关的知识、决策、解决方案
|
|
235
|
+
3. **生成 memory.md**:更新项目记忆索引
|
|
236
|
+
|
|
237
|
+
## 信息收集步骤(重要!)
|
|
238
|
+
|
|
239
|
+
在提取记忆之前,请先使用可用工具收集项目上下文:
|
|
240
|
+
|
|
241
|
+
1. **阅读项目 README**:了解项目概述、功能、使用方法
|
|
242
|
+
- 路径示例:README.md, README.zh-CN.md, docs/README.md
|
|
243
|
+
|
|
244
|
+
2. **检查设计文档**:了解项目架构和设计决策
|
|
245
|
+
- 路径示例:docs/design.md, docs/ARCHITECTURE.md, docs/superpowers/specs/*.md
|
|
246
|
+
|
|
247
|
+
3. **查看代码实现**:了解关键模块和实现细节
|
|
248
|
+
- 路径示例:src/**/*.ts, packages/*/src/**/*.ts
|
|
249
|
+
|
|
250
|
+
4. **回顾现有 memory**:了解已有的项目记忆
|
|
251
|
+
- 路径:当前目录下的 .roy/memory/memory.md
|
|
252
|
+
|
|
253
|
+
## 输入信息
|
|
254
|
+
|
|
255
|
+
- 当前项目的 memory.md 内容
|
|
256
|
+
- 当前对话消息
|
|
257
|
+
|
|
258
|
+
## 输出要求
|
|
259
|
+
|
|
260
|
+
请以 JSON 格式输出结果,包含以下字段:
|
|
261
|
+
- memoryMdContent: 新的 memory.md 内容
|
|
262
|
+
- projectSummary: 项目摘要(包含 summary, shortSummary 等)
|
|
263
|
+
- hasUpdates: 是否有更新
|
|
264
|
+
|
|
265
|
+
## 记忆组织原则
|
|
266
|
+
|
|
267
|
+
- 优先记录具体、可操作的记忆(代码位置、配置项、命令)
|
|
268
|
+
- 避免过于抽象或通用的描述
|
|
269
|
+
- 记录设计决策及其理由`;
|
|
270
|
+
var GLOBAL_MEMORY_AGENT_PROMPT = `你是全局 Memory Agent,负责整理跨项目的通用记忆。
|
|
271
|
+
|
|
272
|
+
## 你的职责
|
|
273
|
+
|
|
274
|
+
1. **聚合项目摘要**:分析 projectSummaries,提取共性知识
|
|
275
|
+
2. **维护全局记忆**:更新全局 memory.md
|
|
276
|
+
3. **维护项目索引**:在 memory.md 中维护项目列表
|
|
277
|
+
4. **提取共性经验**:将项目经验提炼为通用最佳实践
|
|
278
|
+
|
|
279
|
+
## 输入信息
|
|
280
|
+
|
|
281
|
+
- 全局 memory.md 内容
|
|
282
|
+
- 当前对话消息
|
|
283
|
+
- 项目摘要列表(projectSummaries)
|
|
284
|
+
|
|
285
|
+
## 输出要求
|
|
286
|
+
|
|
287
|
+
请以 JSON 格式输出结果,包含以下字段:
|
|
288
|
+
- memoryMdContent: 新的 memory.md 内容
|
|
289
|
+
- hasUpdates: 是否有更新
|
|
290
|
+
|
|
291
|
+
## 记忆组织原则
|
|
292
|
+
|
|
293
|
+
- 关注跨项目共性(工作流、规范、偏好)
|
|
294
|
+
- 项目索引只记录摘要和路径,不复制内容
|
|
295
|
+
- 用户个人偏好(饮食、工作习惯)优先记录`;
|
|
296
|
+
function createMemoryAgent(scope) {
|
|
297
|
+
const name = `memory-agent-${scope}-${Date.now()}`;
|
|
298
|
+
const systemPrompt = scope === "project" ? PROJECT_MEMORY_AGENT_PROMPT : GLOBAL_MEMORY_AGENT_PROMPT;
|
|
299
|
+
return {
|
|
300
|
+
name,
|
|
301
|
+
systemPrompt,
|
|
302
|
+
maxIterations: 5
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function formatMemoryInput(input) {
|
|
306
|
+
const lines = [];
|
|
307
|
+
lines.push(`# Memory Agent Input (${input.scope} scope)
|
|
308
|
+
`);
|
|
309
|
+
lines.push("## Current memory.md");
|
|
310
|
+
lines.push(input.currentMemoryMd || "_No existing memory_");
|
|
311
|
+
lines.push("");
|
|
312
|
+
lines.push("## Recent Messages");
|
|
313
|
+
if (input.messages.length === 0) {
|
|
314
|
+
lines.push("_No messages_");
|
|
315
|
+
} else {
|
|
316
|
+
for (const msg of input.messages.slice(-10)) {
|
|
317
|
+
const content = typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content);
|
|
318
|
+
lines.push(`**${msg.role}**: ${content.substring(0, 500)}`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
lines.push("");
|
|
322
|
+
if (input.scope === "global" && input.projectSummaries && input.projectSummaries.length > 0) {
|
|
323
|
+
lines.push("## Project Summaries");
|
|
324
|
+
for (const ps of input.projectSummaries) {
|
|
325
|
+
lines.push(`### ${ps.projectName}`);
|
|
326
|
+
lines.push(`Path: ${ps.projectPath}`);
|
|
327
|
+
lines.push(`Last Updated: ${new Date(ps.lastUpdated).toLocaleString()}`);
|
|
328
|
+
lines.push(`Summary: ${ps.summary}`);
|
|
329
|
+
lines.push(`Memory: ${ps.memoryMdPath}`);
|
|
330
|
+
lines.push("---");
|
|
331
|
+
}
|
|
332
|
+
lines.push("");
|
|
333
|
+
}
|
|
334
|
+
lines.push("## Task");
|
|
335
|
+
lines.push("请分析以上信息,更新记忆并以 JSON 格式输出结果。");
|
|
336
|
+
return lines.join(`
|
|
337
|
+
`);
|
|
338
|
+
}
|
|
339
|
+
function parseMemoryAgentOutput(output, scope) {
|
|
340
|
+
let jsonStr = output;
|
|
341
|
+
const jsonMatch = output.match(/```json\s*([\s\S]*?)\s*```/) || output.match(/```\s*([\s\S]*?)\s*```/) || output.match(/(\{[\s\S]*\})/);
|
|
342
|
+
if (jsonMatch) {
|
|
343
|
+
jsonStr = jsonMatch[1] || jsonMatch[0];
|
|
344
|
+
}
|
|
345
|
+
try {
|
|
346
|
+
const parsed = JSON.parse(jsonStr);
|
|
347
|
+
return {
|
|
348
|
+
scope,
|
|
349
|
+
memoryMdContent: parsed.memoryMdContent || "",
|
|
350
|
+
projectSummary: parsed.projectSummary,
|
|
351
|
+
hasUpdates: parsed.hasUpdates ?? false
|
|
352
|
+
};
|
|
353
|
+
} catch {
|
|
354
|
+
return {
|
|
355
|
+
scope,
|
|
356
|
+
memoryMdContent: output,
|
|
357
|
+
hasUpdates: false
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function createEmptyResult(scope) {
|
|
362
|
+
return {
|
|
363
|
+
scope,
|
|
364
|
+
memoryMdContent: "",
|
|
365
|
+
hasUpdates: false
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
async function buildProjectInput(params) {
|
|
369
|
+
const baseDir = params.projectPath + "/.roy/memory";
|
|
370
|
+
return {
|
|
371
|
+
scope: "project",
|
|
372
|
+
baseDir,
|
|
373
|
+
currentMemoryMd: params.currentMemoryMd,
|
|
374
|
+
messages: params.messages
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
function buildGlobalInput(params) {
|
|
378
|
+
return {
|
|
379
|
+
scope: "global",
|
|
380
|
+
baseDir: params.baseDir,
|
|
381
|
+
currentMemoryMd: params.currentMemoryMd,
|
|
382
|
+
messages: params.messages,
|
|
383
|
+
projectSummaries: params.projectSummaries
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
async function applyMemoryResult(result, baseDir) {
|
|
387
|
+
const fs2 = await import("fs/promises");
|
|
388
|
+
const path3 = await import("path");
|
|
389
|
+
const memoryMdPath = path3.join(baseDir, "memory.md");
|
|
390
|
+
await fs2.mkdir(path3.dirname(memoryMdPath), { recursive: true });
|
|
391
|
+
await fs2.writeFile(memoryMdPath, result.memoryMdContent, "utf-8");
|
|
392
|
+
}
|
|
393
|
+
function generateProjectSummary(params) {
|
|
394
|
+
const paragraphs = params.memoryMdContent.split(/\n\n+/);
|
|
395
|
+
const firstParagraph = paragraphs[0] || "";
|
|
396
|
+
const summary = firstParagraph.replace(/^#+\s*/g, "").trim() || "No summary available";
|
|
397
|
+
const firstSentence = summary.split(/[.!?]/)[0] || summary;
|
|
398
|
+
const shortSummary = firstSentence.substring(0, 50) + (firstSentence.length > 50 ? "..." : "");
|
|
399
|
+
return {
|
|
400
|
+
projectPath: params.projectPath,
|
|
401
|
+
projectName: params.projectName,
|
|
402
|
+
lastUpdated: Date.now(),
|
|
403
|
+
summary,
|
|
404
|
+
shortSummary,
|
|
405
|
+
memoryMdPath: params.memoryMdPath
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
export { MemoryManager, MemoryPlugin, createMemoryPlugin, recallMemory, PROJECT_MEMORY_AGENT_PROMPT, GLOBAL_MEMORY_AGENT_PROMPT, createMemoryAgent, formatMemoryInput, parseMemoryAgentOutput, createEmptyResult, buildProjectInput, buildGlobalInput, applyMemoryResult, generateProjectSummary };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getTracerProvider,
|
|
3
3
|
init_tracer_provider
|
|
4
|
-
} from "./
|
|
4
|
+
} from "./roy-agent-core-1k28kg7h.js";
|
|
5
5
|
import {
|
|
6
6
|
__esm,
|
|
7
7
|
__require
|
|
8
|
-
} from "./
|
|
8
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
9
9
|
|
|
10
|
-
// src/env/log-trace/logger.ts
|
|
10
|
+
// packages/core/src/env/log-trace/logger.ts
|
|
11
11
|
import { appendFileSync, existsSync, mkdirSync } from "fs";
|
|
12
12
|
import { join } from "path";
|
|
13
13
|
function simplifyFilePath(fullPath) {
|
|
@@ -141,6 +141,9 @@ function getMaxOutput() {
|
|
|
141
141
|
function setLogDirOverride(dir) {
|
|
142
142
|
logDirOverride = dir;
|
|
143
143
|
}
|
|
144
|
+
function getLogDirOverride() {
|
|
145
|
+
return logDirOverride;
|
|
146
|
+
}
|
|
144
147
|
|
|
145
148
|
class Logger {
|
|
146
149
|
prefix;
|
|
@@ -293,4 +296,4 @@ var init_logger = __esm(() => {
|
|
|
293
296
|
loggerCache = new Map;
|
|
294
297
|
});
|
|
295
298
|
|
|
296
|
-
export { simplifyFilePath, isQuietMode, setQuietMode, setConfigComponent, getLogLevel, getLogDir, getMaxOutput, setLogDirOverride, createLogger, getLogLevels, init_logger };
|
|
299
|
+
export { simplifyFilePath, isQuietMode, setQuietMode, setConfigComponent, getLogLevel, getLogFile, getLogDir, getMaxOutput, setLogDirOverride, getLogDirOverride, createLogger, getLogLevels, init_logger };
|