openmatrix 0.2.5 → 0.2.6

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.
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare const debugCommand: Command;
@@ -0,0 +1,116 @@
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
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.debugCommand = void 0;
37
+ // src/cli/commands/debug.ts
38
+ const commander_1 = require("commander");
39
+ const fs = __importStar(require("fs"));
40
+ const debug_manager_js_1 = require("../../orchestrator/debug-manager.js");
41
+ exports.debugCommand = new commander_1.Command('debug')
42
+ .description('系统化调试 - 诊断并修复问题')
43
+ .argument('[description]', '问题描述')
44
+ .option('--task <taskId>', '调试指定的失败任务')
45
+ .option('--diagnose-only', '仅诊断,不执行修复')
46
+ .option('--json', '输出 JSON 格式')
47
+ .option('--list', '列出最近的调试会话')
48
+ .action(async (description, options) => {
49
+ const basePath = process.cwd();
50
+ const omPath = `${basePath}/.openmatrix`;
51
+ // 初始化 .openmatrix 目录(如果不存在)
52
+ if (!fs.existsSync(omPath)) {
53
+ console.log('❌ .openmatrix 目录不存在,请先运行: openmatrix start --init-only');
54
+ return;
55
+ }
56
+ const debugManager = new debug_manager_js_1.DebugManager(omPath);
57
+ // 列出最近的调试会话
58
+ if (options.list) {
59
+ const sessions = debugManager.listRecent();
60
+ if (sessions.length === 0) {
61
+ console.log('📋 没有调试记录');
62
+ return;
63
+ }
64
+ console.log('📋 最近的调试会话:\n');
65
+ sessions.forEach(s => {
66
+ console.log(` ${s.id} ${s.status} ${s.description}`);
67
+ console.log(` ${s.createdAt}`);
68
+ });
69
+ return;
70
+ }
71
+ // 如果没有描述也没有任务 ID,提示用户
72
+ if (!description && !options.task) {
73
+ console.log('🔍 系统化调试 - 诊断并修复问题\n');
74
+ console.log('用法:');
75
+ console.log(' openmatrix debug <问题描述> 描述问题开始调试');
76
+ console.log(' openmatrix debug --task TASK-XXX 调试指定失败任务');
77
+ console.log(' openmatrix debug --diagnose-only 仅诊断不修复');
78
+ console.log(' openmatrix debug --list 列出最近调试记录');
79
+ console.log(' openmatrix debug --json 输出 JSON 格式\n');
80
+ console.log('示例:');
81
+ console.log(' openmatrix debug "API 返回 500 错误"');
82
+ console.log(' openmatrix debug --task TASK-003');
83
+ console.log(' openmatrix debug "测试失败" --diagnose-only');
84
+ return;
85
+ }
86
+ // 初始化调试会话
87
+ const result = await debugManager.initialize({
88
+ description,
89
+ taskId: options.task,
90
+ diagnoseOnly: options.diagnoseOnly
91
+ });
92
+ if (options.json) {
93
+ console.log(JSON.stringify(result, null, 2));
94
+ return;
95
+ }
96
+ // 展示诊断信息
97
+ console.log('\n🔍 调试会话已初始化');
98
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
99
+ console.log(`会话 ID: ${result.sessionId}`);
100
+ console.log(`状态: ${result.status}`);
101
+ console.log(`问题类型: ${result.problemType}`);
102
+ console.log(`问题描述: ${result.report.description}`);
103
+ if (result.report.relatedTaskId) {
104
+ console.log(`关联任务: ${result.report.relatedTaskId}`);
105
+ }
106
+ if (result.report.errorInfo?.message) {
107
+ console.log(`错误信息: ${result.report.errorInfo.message}`);
108
+ }
109
+ if (result.report.relatedFiles && result.report.relatedFiles.length > 0) {
110
+ console.log(`相关文件: ${result.report.relatedFiles.join(', ')}`);
111
+ }
112
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
113
+ console.log('\n💡 下一步:');
114
+ console.log(' 使用 /om:debug 进入系统化调试流程');
115
+ console.log(' 或使用 openmatrix debug --list 查看所有调试记录');
116
+ });
package/dist/cli/index.js CHANGED
@@ -51,6 +51,7 @@ const check_gitignore_js_1 = require("./commands/check-gitignore.js");
51
51
  const analyze_js_1 = require("./commands/analyze.js");
52
52
  const brainstorm_js_1 = require("./commands/brainstorm.js");
53
53
  const research_js_1 = require("./commands/research.js");
54
+ const debug_js_1 = require("./commands/debug.js");
54
55
  const complete_js_1 = require("./commands/complete.js");
55
56
  const step_js_1 = require("./commands/step.js");
56
57
  // 读取 package.json 版本
@@ -85,5 +86,6 @@ program.addCommand(check_gitignore_js_1.checkGitignoreCommand);
85
86
  program.addCommand(analyze_js_1.analyzeCommand);
86
87
  program.addCommand(brainstorm_js_1.brainstormCommand);
87
88
  program.addCommand(research_js_1.researchCommand);
89
+ program.addCommand(debug_js_1.debugCommand);
88
90
  // 默认帮助
89
91
  program.parse();
@@ -0,0 +1,23 @@
1
+ export interface DebugContext {
2
+ state?: Record<string, unknown>;
3
+ task?: Record<string, unknown>;
4
+ logs?: string;
5
+ errorStack?: string;
6
+ projectFiles?: string[];
7
+ envInfo?: Record<string, unknown>;
8
+ configFiles?: string[];
9
+ cliLogs?: string;
10
+ systemState?: Record<string, unknown>;
11
+ }
12
+ /**
13
+ * 根据问题类型收集上下文信息
14
+ */
15
+ export declare class ContextCollector {
16
+ private basePath;
17
+ constructor(basePath: string);
18
+ collectForTaskFailure(taskId: string): Promise<DebugContext>;
19
+ collectForProjectBug(): Promise<DebugContext>;
20
+ collectForEnvironment(): Promise<DebugContext>;
21
+ collectForSystemBug(): Promise<DebugContext>;
22
+ private scanFiles;
23
+ }
@@ -0,0 +1,168 @@
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
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ContextCollector = void 0;
37
+ // src/orchestrator/context-collector.ts
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ /**
41
+ * 根据问题类型收集上下文信息
42
+ */
43
+ class ContextCollector {
44
+ basePath;
45
+ constructor(basePath) {
46
+ this.basePath = basePath;
47
+ }
48
+ async collectForTaskFailure(taskId) {
49
+ const context = {};
50
+ // 读取全局状态
51
+ const statePath = path.join(this.basePath, 'state.json');
52
+ if (fs.existsSync(statePath)) {
53
+ try {
54
+ context.state = JSON.parse(fs.readFileSync(statePath, 'utf-8'));
55
+ }
56
+ catch { /* ignore */ }
57
+ }
58
+ // 读取任务文件
59
+ const taskPath = path.join(this.basePath, 'tasks', `${taskId}.json`);
60
+ if (fs.existsSync(taskPath)) {
61
+ try {
62
+ context.task = JSON.parse(fs.readFileSync(taskPath, 'utf-8'));
63
+ }
64
+ catch { /* ignore */ }
65
+ }
66
+ // 读取日志
67
+ const logPath = path.join(this.basePath, 'logs');
68
+ if (fs.existsSync(logPath)) {
69
+ try {
70
+ const files = fs.readdirSync(logPath);
71
+ const logs = files
72
+ .filter(f => f.endsWith('.log') || f.includes(taskId))
73
+ .map(f => fs.readFileSync(path.join(logPath, f), 'utf-8'))
74
+ .join('\n---\n');
75
+ if (logs)
76
+ context.logs = logs;
77
+ }
78
+ catch { /* ignore */ }
79
+ }
80
+ return context;
81
+ }
82
+ async collectForProjectBug() {
83
+ const context = {};
84
+ // 扫描项目关键文件
85
+ const projectRoot = path.resolve(this.basePath, '..');
86
+ const scanDirs = ['src', 'lib', 'app', 'server', 'api', 'controllers', 'routes'];
87
+ const projectFiles = [];
88
+ for (const dir of scanDirs) {
89
+ const fullPath = path.join(projectRoot, dir);
90
+ if (fs.existsSync(fullPath)) {
91
+ const files = this.scanFiles(fullPath, ['.ts', '.js', '.tsx', '.jsx'], 2);
92
+ projectFiles.push(...files);
93
+ }
94
+ }
95
+ if (projectFiles.length > 0) {
96
+ context.projectFiles = projectFiles.slice(0, 50);
97
+ }
98
+ return context;
99
+ }
100
+ async collectForEnvironment() {
101
+ const context = {};
102
+ // 收集环境信息
103
+ const envInfo = {
104
+ nodeVersion: process.version,
105
+ platform: process.platform,
106
+ cwd: process.cwd(),
107
+ envVars: Object.keys(process.env).slice(0, 20)
108
+ };
109
+ context.envInfo = envInfo;
110
+ // 扫描配置文件
111
+ const projectRoot = path.resolve(this.basePath, '..');
112
+ const configFiles = [
113
+ 'package.json',
114
+ 'tsconfig.json',
115
+ '.env',
116
+ '.env.local',
117
+ 'config.json',
118
+ 'webpack.config.js',
119
+ 'vite.config.ts',
120
+ '.openmatrix/state.json'
121
+ ];
122
+ const found = [];
123
+ for (const file of configFiles) {
124
+ const fullPath = path.join(projectRoot, file);
125
+ if (fs.existsSync(fullPath)) {
126
+ found.push(file);
127
+ }
128
+ }
129
+ if (found.length > 0) {
130
+ context.configFiles = found;
131
+ }
132
+ return context;
133
+ }
134
+ async collectForSystemBug() {
135
+ const context = {};
136
+ // 读取系统状态
137
+ const statePath = path.join(this.basePath, 'state.json');
138
+ if (fs.existsSync(statePath)) {
139
+ try {
140
+ context.systemState = JSON.parse(fs.readFileSync(statePath, 'utf-8'));
141
+ }
142
+ catch { /* ignore */ }
143
+ }
144
+ return context;
145
+ }
146
+ scanFiles(dir, extensions, maxDepth, currentDepth = 0) {
147
+ if (currentDepth > maxDepth)
148
+ return [];
149
+ const results = [];
150
+ try {
151
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
152
+ for (const entry of entries) {
153
+ const fullPath = path.join(dir, entry.name);
154
+ if (entry.isDirectory()) {
155
+ if (!entry.name.startsWith('.') && entry.name !== 'node_modules') {
156
+ results.push(...this.scanFiles(fullPath, extensions, maxDepth, currentDepth + 1));
157
+ }
158
+ }
159
+ else if (extensions.some(ext => entry.name.endsWith(ext))) {
160
+ results.push(fullPath.replace(process.cwd() + path.sep, ''));
161
+ }
162
+ }
163
+ }
164
+ catch { /* ignore */ }
165
+ return results;
166
+ }
167
+ }
168
+ exports.ContextCollector = ContextCollector;
@@ -0,0 +1,52 @@
1
+ import type { DebugSession, DiagnosisReport, ProblemType } from '../types/index.js';
2
+ export interface DebugConfig {
3
+ description?: string;
4
+ taskId?: string;
5
+ diagnoseOnly?: boolean;
6
+ }
7
+ export interface DebugInitResult {
8
+ sessionId: string;
9
+ status: string;
10
+ problemType: ProblemType;
11
+ report: Partial<DiagnosisReport>;
12
+ }
13
+ /**
14
+ * 调试管理器 - 协调整个调试流程
15
+ */
16
+ export declare class DebugManager {
17
+ private omPath;
18
+ private detector;
19
+ private collector;
20
+ private reporter;
21
+ constructor(omPath: string);
22
+ /**
23
+ * 初始化调试会话
24
+ */
25
+ initialize(config: DebugConfig): Promise<DebugInitResult>;
26
+ /**
27
+ * 获取会话
28
+ */
29
+ getSession(sessionId: string): DebugSession | null;
30
+ /**
31
+ * 更新会话
32
+ */
33
+ updateSession(sessionId: string, updates: Partial<DebugSession>): void;
34
+ /**
35
+ * 完成会话
36
+ */
37
+ completeSession(sessionId: string): Promise<string | null>;
38
+ /**
39
+ * 列出最近的调试会话
40
+ */
41
+ listRecent(): {
42
+ id: string;
43
+ status: string;
44
+ description: string;
45
+ createdAt: string;
46
+ }[];
47
+ private collectContext;
48
+ private getTaskError;
49
+ private saveSession;
50
+ private getSessionPath;
51
+ private generateSessionId;
52
+ }
@@ -0,0 +1,214 @@
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
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.DebugManager = void 0;
37
+ // src/orchestrator/debug-manager.ts
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ const problem_detector_js_1 = require("./problem-detector.js");
41
+ const context_collector_js_1 = require("./context-collector.js");
42
+ const debug_reporter_js_1 = require("./debug-reporter.js");
43
+ /**
44
+ * 调试管理器 - 协调整个调试流程
45
+ */
46
+ class DebugManager {
47
+ omPath;
48
+ detector;
49
+ collector;
50
+ reporter;
51
+ constructor(omPath) {
52
+ this.omPath = omPath;
53
+ this.detector = new problem_detector_js_1.ProblemDetector();
54
+ this.collector = new context_collector_js_1.ContextCollector(omPath);
55
+ this.reporter = new debug_reporter_js_1.DebugReporter(omPath);
56
+ }
57
+ /**
58
+ * 初始化调试会话
59
+ */
60
+ async initialize(config) {
61
+ // 如果有任务 ID,尝试读取任务信息
62
+ let taskError = null;
63
+ if (config.taskId) {
64
+ taskError = await this.getTaskError(config.taskId);
65
+ }
66
+ // 判断问题类型
67
+ const problemType = await this.detector.detect({
68
+ description: config.description,
69
+ taskId: config.taskId,
70
+ taskError
71
+ });
72
+ // 收集上下文
73
+ const context = await this.collectContext(problemType, config);
74
+ // 创建会话
75
+ const sessionId = this.generateSessionId();
76
+ const session = {
77
+ id: sessionId,
78
+ status: config.diagnoseOnly ? 'initialized' : 'diagnosing',
79
+ report: {
80
+ id: sessionId,
81
+ problemType,
82
+ trigger: config.taskId ? 'auto' : 'explicit',
83
+ description: config.description || `调试任务 ${config.taskId}`,
84
+ relatedTaskId: config.taskId,
85
+ errorInfo: taskError ? {
86
+ message: taskError,
87
+ timestamp: new Date().toISOString()
88
+ } : undefined,
89
+ relatedFiles: context.projectFiles || [],
90
+ rootCause: '', // 由 Skill 阶段 Agent 填充
91
+ impactScope: [],
92
+ suggestedFix: '', // 由 Skill 阶段 Agent 填充
93
+ diagnosedAt: new Date().toISOString()
94
+ },
95
+ retryCount: 0,
96
+ createdAt: new Date().toISOString(),
97
+ updatedAt: new Date().toISOString()
98
+ };
99
+ // 持久化会话
100
+ this.saveSession(session);
101
+ return {
102
+ sessionId,
103
+ status: session.status,
104
+ problemType,
105
+ report: {
106
+ description: session.report.description,
107
+ relatedTaskId: session.report.relatedTaskId,
108
+ relatedFiles: session.report.relatedFiles,
109
+ errorInfo: session.report.errorInfo
110
+ }
111
+ };
112
+ }
113
+ /**
114
+ * 获取会话
115
+ */
116
+ getSession(sessionId) {
117
+ const sessionPath = this.getSessionPath(sessionId);
118
+ if (!fs.existsSync(sessionPath))
119
+ return null;
120
+ try {
121
+ return JSON.parse(fs.readFileSync(sessionPath, 'utf-8'));
122
+ }
123
+ catch {
124
+ return null;
125
+ }
126
+ }
127
+ /**
128
+ * 更新会话
129
+ */
130
+ updateSession(sessionId, updates) {
131
+ const session = this.getSession(sessionId);
132
+ if (!session)
133
+ return;
134
+ Object.assign(session, updates, { updatedAt: new Date().toISOString() });
135
+ this.saveSession(session);
136
+ }
137
+ /**
138
+ * 完成会话
139
+ */
140
+ async completeSession(sessionId) {
141
+ const session = this.getSession(sessionId);
142
+ if (!session)
143
+ return null;
144
+ session.status = 'completed';
145
+ session.completedAt = new Date().toISOString();
146
+ this.saveSession(session);
147
+ return await this.reporter.generateReport(session);
148
+ }
149
+ /**
150
+ * 列出最近的调试会话
151
+ */
152
+ listRecent() {
153
+ const debugDir = path.join(this.omPath, 'debug');
154
+ if (!fs.existsSync(debugDir))
155
+ return [];
156
+ const files = fs.readdirSync(debugDir)
157
+ .filter(f => f.endsWith('.json') && f.startsWith('DEBUG-'))
158
+ .sort()
159
+ .reverse()
160
+ .slice(0, 10);
161
+ return files.map(f => {
162
+ const session = JSON.parse(fs.readFileSync(path.join(debugDir, f), 'utf-8'));
163
+ return {
164
+ id: session.id,
165
+ status: session.status,
166
+ description: session.report.description,
167
+ createdAt: session.createdAt
168
+ };
169
+ });
170
+ }
171
+ async collectContext(problemType, config) {
172
+ switch (problemType) {
173
+ case 'task_failure':
174
+ return config.taskId ? await this.collector.collectForTaskFailure(config.taskId) : {};
175
+ case 'project_bug':
176
+ return await this.collector.collectForProjectBug();
177
+ case 'environment':
178
+ return await this.collector.collectForEnvironment();
179
+ case 'system_bug':
180
+ return await this.collector.collectForSystemBug();
181
+ default:
182
+ return {};
183
+ }
184
+ }
185
+ async getTaskError(taskId) {
186
+ const taskPath = path.join(this.omPath, 'tasks', `${taskId}.json`);
187
+ if (!fs.existsSync(taskPath))
188
+ return null;
189
+ try {
190
+ const task = JSON.parse(fs.readFileSync(taskPath, 'utf-8'));
191
+ return task.error || null;
192
+ }
193
+ catch {
194
+ return null;
195
+ }
196
+ }
197
+ saveSession(session) {
198
+ const debugDir = path.join(this.omPath, 'debug');
199
+ if (!fs.existsSync(debugDir)) {
200
+ fs.mkdirSync(debugDir, { recursive: true });
201
+ }
202
+ const sessionPath = this.getSessionPath(session.id);
203
+ fs.writeFileSync(sessionPath, JSON.stringify(session, null, 2), 'utf-8');
204
+ }
205
+ getSessionPath(sessionId) {
206
+ return path.join(this.omPath, 'debug', `${sessionId}.json`);
207
+ }
208
+ generateSessionId() {
209
+ const timestamp = Date.now().toString(36).toUpperCase();
210
+ const random = Math.random().toString(36).substring(2, 5).toUpperCase();
211
+ return `DEBUG-${timestamp}${random}`;
212
+ }
213
+ }
214
+ exports.DebugManager = DebugManager;
@@ -0,0 +1,25 @@
1
+ import type { DebugSession } from '../types/index.js';
2
+ /**
3
+ * 生成和保存诊断报告
4
+ */
5
+ export declare class DebugReporter {
6
+ private debugDir;
7
+ constructor(basePath: string);
8
+ /**
9
+ * 生成诊断报告文件
10
+ */
11
+ generateReport(session: DebugSession): Promise<string>;
12
+ /**
13
+ * 格式化报告内容为 Markdown
14
+ */
15
+ private formatReport;
16
+ /**
17
+ * 列出所有诊断报告
18
+ */
19
+ listReports(): {
20
+ id: string;
21
+ path: string;
22
+ createdAt: string;
23
+ }[];
24
+ private ensureDir;
25
+ }
@@ -0,0 +1,167 @@
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
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.DebugReporter = void 0;
37
+ // src/orchestrator/debug-reporter.ts
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ /**
41
+ * 生成和保存诊断报告
42
+ */
43
+ class DebugReporter {
44
+ debugDir;
45
+ constructor(basePath) {
46
+ this.debugDir = path.join(basePath, 'debug');
47
+ this.ensureDir();
48
+ }
49
+ /**
50
+ * 生成诊断报告文件
51
+ */
52
+ async generateReport(session) {
53
+ const report = session.report;
54
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
55
+ const fileName = `${report.id}-report-${timestamp}.md`;
56
+ const filePath = path.join(this.debugDir, fileName);
57
+ const content = this.formatReport(session);
58
+ fs.writeFileSync(filePath, content, 'utf-8');
59
+ return filePath;
60
+ }
61
+ /**
62
+ * 格式化报告内容为 Markdown
63
+ */
64
+ formatReport(session) {
65
+ const { report, fixResult, verifyResult } = session;
66
+ let md = `# Debug Report\n\n`;
67
+ md += `**会话 ID**: ${session.id}\n`;
68
+ md += `**日期**: ${session.createdAt}\n`;
69
+ md += `**状态**: ${session.status}\n`;
70
+ if (session.completedAt) {
71
+ md += `**完成时间**: ${session.completedAt}\n`;
72
+ }
73
+ md += `\n---\n\n`;
74
+ // 问题描述
75
+ md += `## 问题描述\n\n${report.description}\n\n`;
76
+ // 问题类型
77
+ md += `## 问题类型\n\n\`${report.problemType}\`\n\n`;
78
+ if (report.relatedTaskId) {
79
+ md += `**关联任务**: ${report.relatedTaskId}\n\n`;
80
+ }
81
+ // 诊断结果
82
+ md += `## 诊断结果\n\n`;
83
+ md += `### 根因\n\n${report.rootCause}\n\n`;
84
+ if (report.errorInfo) {
85
+ md += `### 错误信息\n\n`;
86
+ md += `\`\`\`\n${report.errorInfo.message}\n\`\`\`\n\n`;
87
+ if (report.errorInfo.stack) {
88
+ md += `### 错误栈\n\n\`\`\`\n${report.errorInfo.stack}\n\`\`\`\n\n`;
89
+ }
90
+ }
91
+ // 影响范围
92
+ if (report.impactScope.length > 0) {
93
+ md += `### 影响范围\n\n`;
94
+ report.impactScope.forEach((item) => { md += `- ${item}\n`; });
95
+ md += `\n`;
96
+ }
97
+ // 相关文件
98
+ if (report.relatedFiles && report.relatedFiles.length > 0) {
99
+ md += `### 相关文件\n\n`;
100
+ report.relatedFiles.forEach((file) => { md += `- \`${file}\`\n`; });
101
+ md += `\n`;
102
+ }
103
+ // 修复建议
104
+ md += `## 修复建议\n\n${report.suggestedFix}\n\n`;
105
+ // 修复操作
106
+ if (fixResult) {
107
+ md += `## 修复操作\n\n`;
108
+ if (fixResult.success) {
109
+ md += `✅ 修复成功\n\n`;
110
+ }
111
+ else {
112
+ md += `❌ 修复未完全生效\n\n`;
113
+ }
114
+ if (fixResult.modifiedFiles.length > 0) {
115
+ md += `### 修改文件\n\n`;
116
+ fixResult.modifiedFiles.forEach((file) => { md += `- \`${file}\`\n`; });
117
+ md += `\n`;
118
+ }
119
+ if (fixResult.operations.length > 0) {
120
+ md += `### 执行操作\n\n`;
121
+ fixResult.operations.forEach((op) => { md += `- ${op}\n`; });
122
+ md += `\n`;
123
+ }
124
+ }
125
+ // 验证结果
126
+ if (verifyResult) {
127
+ md += `## 验证结果\n\n`;
128
+ if (verifyResult.passed) {
129
+ md += `✅ 验证通过\n\n`;
130
+ }
131
+ else {
132
+ md += `❌ 验证未通过\n\n`;
133
+ }
134
+ md += `${verifyResult.details}\n\n`;
135
+ }
136
+ // 重试信息
137
+ if (session.retryCount > 0) {
138
+ md += `## 重试信息\n\n已尝试 ${session.retryCount} 次修复\n\n`;
139
+ if (session.retryCount >= 3) {
140
+ md += `⚠️ **已尝试 3 次以上修复,建议暂停并质疑架构**\n\n`;
141
+ }
142
+ }
143
+ return md;
144
+ }
145
+ /**
146
+ * 列出所有诊断报告
147
+ */
148
+ listReports() {
149
+ if (!fs.existsSync(this.debugDir))
150
+ return [];
151
+ const files = fs.readdirSync(this.debugDir)
152
+ .filter(f => f.endsWith('-report.md') || f.includes('-report-'))
153
+ .sort()
154
+ .reverse();
155
+ return files.map(f => ({
156
+ id: f.split('-')[0],
157
+ path: path.join(this.debugDir, f),
158
+ createdAt: f
159
+ }));
160
+ }
161
+ ensureDir() {
162
+ if (!fs.existsSync(this.debugDir)) {
163
+ fs.mkdirSync(this.debugDir, { recursive: true });
164
+ }
165
+ }
166
+ }
167
+ exports.DebugReporter = DebugReporter;
@@ -0,0 +1,15 @@
1
+ import type { ProblemType } from '../types/index.js';
2
+ export interface ProblemDetectionConfig {
3
+ description?: string;
4
+ taskId?: string;
5
+ taskError?: string | null;
6
+ }
7
+ /**
8
+ * 判断问题类型的检测器
9
+ */
10
+ export declare class ProblemDetector {
11
+ /**
12
+ * 根据配置判断问题类型
13
+ */
14
+ detect(config: ProblemDetectionConfig): Promise<ProblemType>;
15
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProblemDetector = void 0;
4
+ /**
5
+ * 判断问题类型的检测器
6
+ */
7
+ class ProblemDetector {
8
+ /**
9
+ * 根据配置判断问题类型
10
+ */
11
+ async detect(config) {
12
+ // 有任务 ID 且任务失败
13
+ if (config.taskId && config.taskError) {
14
+ return 'task_failure';
15
+ }
16
+ // 根据描述判断
17
+ if (config.description) {
18
+ const desc = config.description.toLowerCase();
19
+ // 环境相关关键词
20
+ const envKeywords = [
21
+ '依赖', '安装', '环境', '配置', 'npm install', 'node_modules',
22
+ 'env', 'environment', 'dependency', 'install', 'config',
23
+ 'path', '版本', 'version', '权限', 'permission'
24
+ ];
25
+ // 项目代码相关关键词
26
+ const projectKeywords = [
27
+ '接口', 'api', '函数', 'function', '返回', 'response',
28
+ '数据', 'data', '逻辑', 'logic', '页面', 'page',
29
+ '组件', 'component', '样式', 'style', '渲染', 'render'
30
+ ];
31
+ // 系统/OpenMatrix 相关关键词
32
+ const systemKeywords = [
33
+ 'openmatrix', 'cli', '命令', 'command', '状态', 'state',
34
+ '任务', 'task', '编排', 'orchestrat', 'agent', '技能', 'skill'
35
+ ];
36
+ const hasEnvKeyword = envKeywords.some(kw => desc.includes(kw));
37
+ const hasProjectKeyword = projectKeywords.some(kw => desc.includes(kw));
38
+ const hasSystemKeyword = systemKeywords.some(kw => desc.includes(kw));
39
+ // 优先级:环境 > 项目 > 系统
40
+ if (hasEnvKeyword)
41
+ return 'environment';
42
+ if (hasProjectKeyword)
43
+ return 'project_bug';
44
+ if (hasSystemKeyword)
45
+ return 'system_bug';
46
+ }
47
+ // 默认:系统 bug
48
+ return 'system_bug';
49
+ }
50
+ }
51
+ exports.ProblemDetector = ProblemDetector;
@@ -267,3 +267,47 @@ export interface ResearchSession {
267
267
  createdAt: string;
268
268
  completedAt?: string;
269
269
  }
270
+ /** 问题类型 */
271
+ export type ProblemType = 'task_failure' | 'project_bug' | 'system_bug' | 'environment';
272
+ /** 诊断报告 */
273
+ export interface DiagnosisReport {
274
+ id: string;
275
+ problemType: ProblemType;
276
+ trigger: 'explicit' | 'auto';
277
+ description: string;
278
+ errorInfo?: {
279
+ message: string;
280
+ stack?: string;
281
+ timestamp: string;
282
+ };
283
+ relatedTaskId?: string;
284
+ relatedFiles?: string[];
285
+ rootCause: string;
286
+ impactScope: string[];
287
+ suggestedFix: string;
288
+ diagnosedAt: string;
289
+ diagnosisDuration?: number;
290
+ }
291
+ /** 调试会话状态 */
292
+ export type DebugStatus = 'initialized' | 'diagnosing' | 'awaiting_fix' | 'fixing' | 'verifying' | 'completed' | 'cancelled';
293
+ /** 调试会话 */
294
+ export interface DebugSession {
295
+ id: string;
296
+ status: DebugStatus;
297
+ report: DiagnosisReport;
298
+ fixDecision?: 'approve' | 'skip' | 'manual';
299
+ fixResult?: {
300
+ success: boolean;
301
+ operations: string[];
302
+ modifiedFiles: string[];
303
+ output: string;
304
+ };
305
+ verifyResult?: {
306
+ passed: boolean;
307
+ details: string;
308
+ };
309
+ retryCount: number;
310
+ createdAt: string;
311
+ updatedAt: string;
312
+ completedAt?: string;
313
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openmatrix",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
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",
@@ -0,0 +1,425 @@
1
+ ---
2
+ name: om:debug
3
+ description: 系统化调试 - 遇到任何 bug、测试失败或异常行为时使用,在提出修复方案之前执行
4
+ priority: high
5
+ ---
6
+
7
+ <NO-OTHER-SKILLS>
8
+ **绝对禁止**调用以下技能:
9
+ - ❌ superpowers:systematic-debugging → 你已经在 om:debug 中了
10
+ - ❌ superpowers:* → 全部被 OpenMatrix 替代
11
+ - ❌ gsd:* → 全部被 OpenMatrix 替代
12
+ - ❌ 任何其他任务编排相关的技能
13
+
14
+ **诊断和修复阶段只能使用 Agent 工具** — 直接调用 Agent,不通过任何中间层。
15
+ </NO-OTHER-SKILLS>
16
+
17
+ <MANDATORY-EXECUTION-ORDER>
18
+ ## 执行顺序 - 必须严格按此顺序,不得跳过
19
+
20
+ ```
21
+ Step 1: 接收问题描述(参数、指定任务、或询问用户)
22
+ Step 2: 调用 CLI: openmatrix debug 初始化会话
23
+ Step 3: 第一阶段:根因调查(Explore Agent)
24
+ Step 4: 第二阶段:模式分析(Explore Agent)
25
+ Step 5: 展示诊断报告 + 修复建议
26
+ Step 6: AskUserQuestion 确认修复策略
27
+ Step 7: 第四阶段:实施修复(Agent)
28
+ Step 8: 验证修复结果
29
+ Step 9: 写入 Debug Report 并展示
30
+ ```
31
+
32
+ **铁律:不做根因调查,不许提修复方案**
33
+ </MANDATORY-EXECUTION-ORDER>
34
+
35
+ <objective>
36
+ 系统化调试 - 通过四阶段流程诊断和修复问题。不依赖任务流程,可独立使用。
37
+ </objective>
38
+
39
+ <process>
40
+
41
+ ## Step 1: 接收问题
42
+
43
+ **检查 `$ARGUMENTS`:**
44
+
45
+ | 参数 | 处理方式 |
46
+ |------|---------|
47
+ | `--task TASK-XXX` | 读取指定失败任务 |
48
+ | `<问题描述>` | 直接使用描述 |
49
+ | 空 | 询问用户问题描述 |
50
+
51
+ **如果是空参数,询问:**
52
+
53
+ AskUserQuestion: `header: "问题描述"`, `multiSelect: false`
54
+ **question:** 请描述你遇到的问题
55
+
56
+ | label | description |
57
+ |-------|-------------|
58
+ | 描述问题 | 输入自由文本描述 |
59
+ | 选择失败任务 | 从当前失败任务中选择 |
60
+ | 取消 | 退出调试模式 |
61
+
62
+ **如果有失败任务(检查 .openmatrix/state.json):**
63
+ ```bash
64
+ cat .openmatrix/state.json 2>/dev/null | grep -o '"failed":[0-9]*'
65
+ ```
66
+ 如果 `statistics.failed > 0`,读取 `.openmatrix/tasks/` 目录找到 failed 任务并展示。
67
+
68
+ ## Step 2: 调用 CLI 初始化
69
+
70
+ **带任务 ID:**
71
+ ```bash
72
+ openmatrix debug --task TASK-XXX --json
73
+ ```
74
+
75
+ **带描述:**
76
+ ```bash
77
+ openmatrix debug "问题描述" --json
78
+ ```
79
+
80
+ CLI 返回:
81
+ ```json
82
+ {
83
+ "sessionId": "DEBUG-xxx",
84
+ "status": "diagnosing",
85
+ "problemType": "task_failure",
86
+ "report": {
87
+ "description": "...",
88
+ "relatedTaskId": "TASK-003",
89
+ "relatedFiles": ["src/xxx.ts"]
90
+ }
91
+ }
92
+ ```
93
+
94
+ 从返回结果中读取 `sessionId`,后续步骤使用此 ID。
95
+
96
+ ## Step 3: 第一阶段 - 根因调查
97
+
98
+ **调用 Explore Agent:**
99
+
100
+ ```typescript
101
+ Agent({
102
+ subagent_type: "Explore",
103
+ description: "根因调查 - 第一阶段",
104
+ prompt: `你是调试专家。正在进行系统化调试的第一阶段:根因调查。
105
+
106
+ **铁律:在找到根因之前,不要提出任何修复方案。**
107
+
108
+ ## 问题信息
109
+ - 问题类型: ${problemType}
110
+ - 问题描述: ${description}
111
+ ${relatedTaskId ? `- 关联任务: ${relatedTaskId}` : ''}
112
+
113
+ ## 任务
114
+ 1. 仔细阅读所有错误信息(不要跳过任何警告或错误)
115
+ 2. 收集相关文件和日志
116
+ 3. 检查近期代码变更(git diff、最近提交)
117
+ 4. 如果有多个组件,追踪数据流,找到断裂点
118
+ 5. 定位问题根源
119
+
120
+ ## 输出格式
121
+ 请按以下格式输出:
122
+
123
+ ### 错误信息
124
+ - 错误类型: ...
125
+ - 错误位置: 文件:行号
126
+ - 错误详情: ...
127
+
128
+ ### 复现步骤
129
+ 1. ...
130
+
131
+ ### 近期变更
132
+ - 提交1: 描述
133
+ - 提交2: 描述
134
+
135
+ ### 根因分析
136
+ [详细描述问题根源]
137
+
138
+ ### 影响范围
139
+ - 文件1
140
+ - 文件2
141
+
142
+ ## 禁止行为
143
+ ❌ 提出修复方案
144
+ ❌ 修改任何文件
145
+ ❌ 做出未经证实的假设`,
146
+ run_in_background: false
147
+ })
148
+ ```
149
+
150
+ ## Step 4: 第二阶段 - 模式分析
151
+
152
+ **调用 Explore Agent:**
153
+
154
+ ```typescript
155
+ Agent({
156
+ subagent_type: "Explore",
157
+ description: "模式分析 - 第二阶段",
158
+ prompt: `继续进行系统化调试的第二阶段:模式分析。
159
+
160
+ ## 第一阶段发现
161
+
162
+ ${第一阶段根因调查的完整输出}
163
+
164
+ ## 任务
165
+ 1. 在代码库中找到类似的、正常工作的代码
166
+ 2. 对比正常代码和异常代码的差异
167
+ 3. 列出所有差异点(无论多小)
168
+ 4. 理解功能依赖关系和隐含假设
169
+
170
+ ## 输出格式
171
+
172
+ ### 正常示例
173
+ - 文件: path:line
174
+ - 说明: 为什么这段代码能正常工作
175
+
176
+ ### 差异点
177
+ 1. 差异1: 正常代码 vs 异常代码
178
+ 2. 差异2: ...
179
+
180
+ ### 依赖关系
181
+ - 需要哪些前置条件
182
+ - 有哪些隐含假设`,
183
+ run_in_background: false
184
+ })
185
+ ```
186
+
187
+ ## Step 5: 展示诊断报告
188
+
189
+ **第一阶段和第二阶段完成后,展示诊断报告:**
190
+
191
+ ```
192
+ 🔍 诊断报告
193
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
194
+
195
+ 问题类型: xxx
196
+
197
+ 根因分析
198
+ [来自第一阶段调查的根因描述]
199
+
200
+ 正常示例
201
+ 文件: path:line
202
+ 说明: ...
203
+
204
+ 差异点
205
+ 1. ...
206
+ 2. ...
207
+
208
+ 影响范围
209
+ - 文件1
210
+ - 文件2
211
+
212
+ 修复建议
213
+ [基于差异分析的具体修复建议]
214
+
215
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
216
+ ```
217
+
218
+ ## Step 6: 确认修复策略
219
+
220
+ AskUserQuestion: `header: "修复策略"`, `multiSelect: false`
221
+ **question:** 诊断完成,选择修复策略?
222
+
223
+ | label | description |
224
+ |-------|-------------|
225
+ | 自动修复 (推荐) | 调用 Agent 执行修复 |
226
+ | 手动修复 | 仅展示建议,用户自行修复 |
227
+ | 跳过 | 不修复,仅记录诊断报告 |
228
+ | 继续深入 | 根因不够清晰,继续调查 |
229
+
230
+ **用户选择 "继续深入"** → 回到 Step 3,带着新信息重新调查。
231
+
232
+ ## Step 7: 实施修复
233
+
234
+ **如果用户选择自动修复:**
235
+
236
+ **修复前安全检查(必须执行):**
237
+ ```bash
238
+ git status --porcelain
239
+ git log --oneline -5
240
+ ```
241
+
242
+ ```typescript
243
+ Agent({
244
+ subagent_type: "general-purpose",
245
+ description: "实施 bug 修复",
246
+ prompt: `根据诊断报告执行修复。
247
+
248
+ ## 铁律
249
+ 1. 只实施单一修复(不要做额外改动)
250
+ 2. 每次只改一个变量
251
+ 3. 不在诊断不清的情况下盲目尝试
252
+ 4. 不做"顺便"的重构
253
+
254
+ ## 诊断报告
255
+ ${诊断报告全文}
256
+
257
+ ## 修复建议
258
+ ${suggestedFix}
259
+
260
+ ## 任务
261
+ 1. 根据修复建议实施修改
262
+ 2. 确保修改范围最小化
263
+ 3. 完成后输出修改了哪些文件和具体改动
264
+
265
+ ## 禁止行为
266
+ ❌ 修改与修复无关的文件
267
+ ❌ 进行额外的重构
268
+ ❌ 同时修复多个问题`,
269
+ run_in_background: false
270
+ })
271
+ ```
272
+
273
+ **Agent 完成后:**
274
+ 1. 检查 Git 状态
275
+ 2. 提交修复(如果文件有变更)
276
+ 3. 进入 Step 8 验证
277
+
278
+ ## Step 8: 验证修复
279
+
280
+ **根据问题类型选择验证方式:**
281
+
282
+ | 问题类型 | 验证方式 |
283
+ |---------|---------|
284
+ | task_failure | 重新运行失败任务或相关测试 |
285
+ | project_bug | 运行相关测试或构建 |
286
+ | system_bug | 验证 CLI 功能 |
287
+ | environment | 检查依赖安装状态 |
288
+
289
+ **任务失败:**
290
+ ```bash
291
+ # 运行相关测试
292
+ npm test -- --run 2>&1 | tail -20
293
+ ```
294
+
295
+ **项目 bug:**
296
+ ```bash
297
+ npm run build 2>&1 | tail -10
298
+ ```
299
+
300
+ **环境:**
301
+ ```bash
302
+ npm ls --depth=0 2>&1 | tail -20
303
+ ```
304
+
305
+ **验证结果判断:**
306
+ - 测试全通过 / 构建成功 → 验证通过
307
+ - 仍有失败 / 构建失败 → 验证未通过
308
+
309
+ AskUserQuestion: `header: "验证结果"`, `multiSelect: false`
310
+ **question:** 修复验证通过了吗?
311
+
312
+ | label | description |
313
+ |-------|-------------|
314
+ | 通过 | 修复成功,记录报告 |
315
+ | 未通过 | 修复未生效,重新分析 |
316
+ | 部分通过 | 部分修复,继续诊断 |
317
+
318
+ **如果验证未通过:**
319
+ - 重试计数 +1
320
+ - **< 3 次** → 回到 Step 3(带着新信息重新分析)
321
+ - **>= 3 次** → 输出"已尝试 3 次以上修复,建议暂停并质疑架构",进入 Step 9
322
+
323
+ ## Step 9: 写入 Debug Report
324
+
325
+ 完成调试会话:
326
+ ```bash
327
+ openmatrix debug --list
328
+ ```
329
+
330
+ **生成诊断报告文件(在界面输出):**
331
+
332
+ ```markdown
333
+ # Debug Report
334
+
335
+ **会话 ID**: ${sessionId}
336
+ **日期**: ${timestamp}
337
+ **状态**: ${status}
338
+
339
+ ## 问题描述
340
+ ${description}
341
+
342
+ ## 问题类型
343
+ ${problemType}
344
+
345
+ ## 诊断结果
346
+ ### 根因
347
+ ${rootCause}
348
+
349
+ ### 影响范围
350
+ ${impactScope}
351
+
352
+ ## 修复操作
353
+ ${operations}
354
+
355
+ ## 验证结果
356
+ ${verifyResult}
357
+
358
+ ## 经验教训
359
+ ${lessons}
360
+ ```
361
+
362
+ **Git 提交修复(如果有文件变更):**
363
+ ```bash
364
+ git status --porcelain
365
+ # 如果有未提交文件:
366
+ git add -A && git commit -m "$(cat <<'EOF'
367
+ fix: 修复 bug - 问题描述
368
+
369
+ 根因: ...
370
+ 修复: ...
371
+
372
+ 影响范围: ...
373
+ 文件改动: ...
374
+
375
+ Co-Authored-By: OpenMatrix https://github.com/bigfish1913/openmatrix
376
+ EOF
377
+ )"
378
+ ```
379
+
380
+ </process>
381
+
382
+ <arguments>
383
+ $ARGUMENTS
384
+ </arguments>
385
+
386
+ <examples>
387
+ /om:debug # 交互式调试
388
+ /om:debug --task TASK-003 # 调试指定失败任务
389
+ /om:debug "API 返回 500 错误" # 带问题描述调试
390
+ </examples>
391
+
392
+ <notes>
393
+ ## 四阶段流程
394
+
395
+ ```
396
+ Step 1: 接收问题
397
+
398
+ Step 2: CLI 初始化会话
399
+
400
+ Step 3: 第一阶段 - 根因调查(只读)
401
+
402
+ Step 4: 第二阶段 - 模式分析(只读)
403
+
404
+ Step 5: 展示诊断报告 + 修复建议
405
+
406
+ Step 6: AskUserQuestion 确认修复策略
407
+
408
+ Step 7: 第三/四阶段 - 实施修复
409
+
410
+ Step 8: 验证修复结果
411
+
412
+ Step 9: 写入 Debug Report
413
+ ```
414
+
415
+ ## 铁律
416
+
417
+ **不做根因调查,不许提修复方案**
418
+
419
+ ## 红线
420
+
421
+ - 3 次修复失败 → 暂停,质疑架构
422
+ - 不修改未关联的文件
423
+ - 单一修复原则
424
+ - 修复前必须有验证方法
425
+ </notes>
package/skills/om.md CHANGED
@@ -82,6 +82,7 @@ OpenMatrix 默认入口 — 用户无需记忆命令,直接描述任务即可
82
82
  /om:status - View status
83
83
  /om:meeting - Handle blockers
84
84
  /om:report - Generate report
85
+ /om:debug - Systematic debugging (bug/error investigation)
85
86
  ```
86
87
  </process>
87
88
 
@@ -99,5 +100,5 @@ $ARGUMENTS
99
100
 
100
101
  <notes>
101
102
  `/om` is shorthand for the OpenMatrix workflow. Same skill set as `openmatrix`, shorter invocation.
102
- Available commands: `/om:brainstorm`, `/om:start`, `/om:auto`, `/om:status`, `/om:meeting`, `/om:report`, `/om:resume`, `/om:retry`, `/om:research`, `/om:approve`, `/om:check`
103
+ Available commands: `/om:brainstorm`, `/om:start`, `/om:auto`, `/om:status`, `/om:meeting`, `/om:report`, `/om:resume`, `/om:retry`, `/om:research`, `/om:approve`, `/om:check`, `/om:debug`
103
104
  </notes>