openmatrix 0.1.54 → 0.1.55

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.
@@ -67,6 +67,12 @@ export declare class AgentRunner {
67
67
  * 构建完整的执行提示词
68
68
  */
69
69
  buildExecutionPrompt(task: Task): string;
70
+ /**
71
+ * 构建累积上下文 - 从已完成任务中提取共享信息
72
+ *
73
+ * 读取所有已完成任务的 context.md,为当前 Agent 提供前序 Agent 的决策和知识
74
+ */
75
+ private buildAccumulatedContext;
70
76
  /**
71
77
  * 构建阶段上下文
72
78
  */
@@ -1,6 +1,41 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.AgentRunner = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
4
39
  /**
5
40
  * AgentRunner - 使用 Subagent 执行任务
6
41
  *
@@ -101,6 +136,7 @@ class AgentRunner {
101
136
  buildExecutionPrompt(task) {
102
137
  const agentPrompt = this.buildAgentPrompt(task);
103
138
  const phaseContext = this.buildPhaseContext(task);
139
+ const accumulatedContext = this.buildAccumulatedContext(task);
104
140
  return `# 任务执行
105
141
 
106
142
  ## 任务信息
@@ -118,6 +154,8 @@ ${task.dependencies.length > 0
118
154
  ? task.dependencies.map(d => `- ${d}`).join('\n')
119
155
  : '无依赖'}
120
156
 
157
+ ${accumulatedContext}
158
+
121
159
  ---
122
160
 
123
161
  ${agentPrompt.context}
@@ -130,8 +168,47 @@ ${agentPrompt.instructions}
130
168
 
131
169
  1. 完成任务后,更新任务状态文件: \`.openmatrix/tasks/${task.id}/task.json\`
132
170
  2. 将执行结果写入: \`.openmatrix/tasks/${task.id}/artifacts/result.md\`
133
- 3. 如需审批,创建审批请求: \`.openmatrix/approvals/\` 目录
171
+ 3. 将上下文摘要写入: \`.openmatrix/tasks/${task.id}/context.md\` (供后续 Agent 读取)
172
+ 4. 如需审批,创建审批请求: \`.openmatrix/approvals/\` 目录
173
+ `;
174
+ }
175
+ /**
176
+ * 构建累积上下文 - 从已完成任务中提取共享信息
177
+ *
178
+ * 读取所有已完成任务的 context.md,为当前 Agent 提供前序 Agent 的决策和知识
179
+ */
180
+ buildAccumulatedContext(currentTask) {
181
+ const omPath = path.join(process.cwd(), '.openmatrix');
182
+ const tasksDir = path.join(omPath, 'tasks');
183
+ try {
184
+ if (!fs.existsSync(tasksDir))
185
+ return '';
186
+ const contextParts = [];
187
+ // 读取所有已完成任务的 context.md
188
+ const taskDirs = fs.readdirSync(tasksDir).filter(name => name.startsWith('TASK-'));
189
+ for (const taskId of taskDirs) {
190
+ const contextFile = path.join(tasksDir, taskId, 'context.md');
191
+ if (fs.existsSync(contextFile)) {
192
+ const content = fs.readFileSync(contextFile, 'utf-8').trim();
193
+ if (content) {
194
+ contextParts.push(`### ${taskId}\n${content}`);
195
+ }
196
+ }
197
+ }
198
+ if (contextParts.length === 0)
199
+ return '';
200
+ return `
201
+ ## 前序 Agent 共享上下文 (Agent Memory)
202
+
203
+ 以下是之前执行的 Agent 留下的上下文信息,包含它们的决策、发现和注意事项。
204
+ 你应该基于这些信息来工作,避免重复犯错或与已有决策冲突。
205
+
206
+ ${contextParts.join('\n\n')}
134
207
  `;
208
+ }
209
+ catch {
210
+ return '';
211
+ }
135
212
  }
136
213
  /**
137
214
  * 构建阶段上下文
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openmatrix",
3
- "version": "0.1.54",
3
+ "version": "0.1.55",
4
4
  "description": "AI Agent task orchestration system with Claude Code Skills integration",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/skills/auto.md CHANGED
@@ -157,9 +157,37 @@ Agent({
157
157
  ```
158
158
 
159
159
  每个 Agent 完成后:
160
- 1. 更新任务状态
161
- 2. **立即检查是否还有未完成任务** — 读取 `.openmatrix/state.json` 中的 statistics,如果 completed < totalTasks,继续执行下一个
162
- 3. Git 自动提交(**必须使用 HEREDOC 格式**):
160
+ 1. **保存 Agent 上下文** — 将执行结果摘要写入 `.openmatrix/tasks/TASK-XXX/context.md`,格式如下:
161
+
162
+ ```markdown
163
+ ## 任务: TASK-XXX 任务标题
164
+
165
+ ### 关键决策
166
+ - [做出的重要决策]
167
+
168
+ ### 创建/修改的文件
169
+ - `path/to/file1.ts` - 简述用途
170
+ - `path/to/file2.ts` - 简述用途
171
+
172
+ ### 重要发现
173
+ - [发现的问题、模式、注意事项]
174
+
175
+ ### 对后续任务的建议
176
+ - [下一个 Agent 应该注意什么]
177
+ ```
178
+
179
+ 2. 更新任务状态
180
+ 3. **立即检查是否还有未完成任务** — 读取 `.openmatrix/state.json` 中的 statistics,如果 completed < totalTasks,继续执行下一个
181
+ 4. Git 自动提交(**必须使用 HEREDOC 格式**):
182
+
183
+ **Agent 上下文共享机制 (Agent Memory):**
184
+
185
+ 每个 Agent 执行时会自动接收前序 Agent 的上下文信息(通过 `context.md` 文件)。
186
+ 这确保 Agent 之间共享知识、避免重复工作、保持决策一致性。
187
+
188
+ ```
189
+ Agent-1 完成 → 写入 context.md → Agent-2 读取 Agent-1 的上下文 → 写入 context.md → ...
190
+ ```
163
191
  ```bash
164
192
  git add -A && git commit -m "$(cat <<'EOF'
165
193
  feat: (TASK-XXX) 任务标题
package/skills/start.md CHANGED
@@ -200,10 +200,38 @@ Agent({
200
200
  ```
201
201
 
202
202
  每个 Agent 完成后:
203
- 1. 更新任务状态: `openmatrix complete <taskId>` 或更新 state
204
- 2. Git 自动提交(必须使用下方统一提交格式)
205
- 3. **立即检查是否还有未完成任务** — 读取 `.openmatrix/state.json` 中的 statistics,如果 completed < totalTasks,继续执行下一个
206
- 4. 检查审批点(auto 模式自动批准,其他模式按配置暂停)
203
+ 1. **保存 Agent 上下文** 将执行结果摘要写入 `.openmatrix/tasks/TASK-XXX/context.md`,格式如下:
204
+
205
+ ```markdown
206
+ ## 任务: TASK-XXX 任务标题
207
+
208
+ ### 关键决策
209
+ - [做出的重要决策]
210
+
211
+ ### 创建/修改的文件
212
+ - `path/to/file1.ts` - 简述用途
213
+ - `path/to/file2.ts` - 简述用途
214
+
215
+ ### 重要发现
216
+ - [发现的问题、模式、注意事项]
217
+
218
+ ### 对后续任务的建议
219
+ - [下一个 Agent 应该注意什么]
220
+ ```
221
+
222
+ 2. 更新任务状态: `openmatrix complete <taskId>` 或更新 state
223
+ 3. Git 自动提交(必须使用下方统一提交格式)
224
+ 4. **立即检查是否还有未完成任务** — 读取 `.openmatrix/state.json` 中的 statistics,如果 completed < totalTasks,继续执行下一个
225
+ 5. 检查审批点(auto 模式自动批准,其他模式按配置暂停)
226
+
227
+ **Agent 上下文共享机制 (Agent Memory):**
228
+
229
+ 每个 Agent 执行时会自动接收前序 Agent 的上下文信息(通过 `context.md` 文件)。
230
+ 这确保 Agent 之间共享知识、避免重复工作、保持决策一致性。
231
+
232
+ ```
233
+ Agent-1 完成 → 写入 context.md → Agent-2 读取 Agent-1 的上下文 → 写入 context.md → ...
234
+ ```
207
235
 
208
236
  **中断恢复:** 如果会话中断,再次执行 `/om:start` 时:
209
237
  1. 读取 `.openmatrix/state.json`