openmatrix 0.1.17 → 0.1.18

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 analyzeCommand: Command;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.analyzeCommand = void 0;
4
+ // src/cli/commands/analyze.ts
5
+ const commander_1 = require("commander");
6
+ const smart_question_analyzer_js_1 = require("../../orchestrator/smart-question-analyzer.js");
7
+ exports.analyzeCommand = new commander_1.Command('analyze')
8
+ .description('智能分析任务,推断配置,返回需要确认的问题列表')
9
+ .argument('[task]', '任务描述')
10
+ .option('--json', '输出 JSON 格式')
11
+ .action(async (task, options) => {
12
+ const analyzer = new smart_question_analyzer_js_1.SmartQuestionAnalyzer(process.cwd());
13
+ if (!task) {
14
+ if (options.json) {
15
+ console.log(JSON.stringify({
16
+ status: 'error',
17
+ message: '请提供任务描述'
18
+ }));
19
+ }
20
+ else {
21
+ console.log('❌ 请提供任务描述');
22
+ console.log(' 用法: openmatrix analyze "实现用户登录功能"');
23
+ }
24
+ return;
25
+ }
26
+ try {
27
+ const result = await analyzer.analyze(task);
28
+ if (options.json) {
29
+ // 输出 JSON 格式 (供 Skill 解析)
30
+ const output = result;
31
+ console.log(JSON.stringify(output, null, 2));
32
+ }
33
+ else {
34
+ // 输出人类可读格式
35
+ console.log('\n' + analyzer.generateSummary(result));
36
+ }
37
+ }
38
+ catch (error) {
39
+ if (options.json) {
40
+ console.log(JSON.stringify({
41
+ status: 'error',
42
+ message: error instanceof Error ? error.message : '分析失败'
43
+ }));
44
+ }
45
+ else {
46
+ console.log('❌ 分析失败:', error instanceof Error ? error.message : '未知错误');
47
+ }
48
+ }
49
+ });
package/dist/cli/index.js CHANGED
@@ -12,6 +12,7 @@ const meeting_js_1 = require("./commands/meeting.js");
12
12
  const auto_js_1 = require("./commands/auto.js");
13
13
  const install_skills_js_1 = require("./commands/install-skills.js");
14
14
  const check_js_1 = require("./commands/check.js");
15
+ const analyze_js_1 = require("./commands/analyze.js");
15
16
  const program = new commander_1.Command();
16
17
  program
17
18
  .name('openmatrix')
@@ -28,5 +29,6 @@ program.addCommand(meeting_js_1.meetingCommand);
28
29
  program.addCommand(auto_js_1.autoCommand);
29
30
  program.addCommand(install_skills_js_1.installSkillsCommand);
30
31
  program.addCommand(check_js_1.checkCommand);
32
+ program.addCommand(analyze_js_1.analyzeCommand);
31
33
  // 默认帮助
32
34
  program.parse();
@@ -39,6 +39,13 @@ export interface QuestionSession {
39
39
  status: 'pending' | 'in_progress' | 'completed';
40
40
  createdAt: string;
41
41
  completedAt?: string;
42
+ /** 推断值 (由 SmartQuestionAnalyzer 提供) */
43
+ inferences?: Map<string, {
44
+ answer: string | string[];
45
+ reason: string;
46
+ }>;
47
+ /** 已跳过的问题 (使用推断值) */
48
+ skippedQuestionIds?: string[];
42
49
  }
43
50
  /**
44
51
  * InteractiveQuestionGenerator - 交互式问题生成器
@@ -48,9 +55,40 @@ export interface QuestionSession {
48
55
  * 2. 优先级排序 - 按重要性顺序提问
49
56
  * 3. 条件分支 - 不同回答触发不同追问
50
57
  * 4. 交互友好 - 支持单步/批量回答
58
+ * 5. 智能推断 - 支持预设推断值,跳过不必要的问题
51
59
  */
52
60
  export declare class InteractiveQuestionGenerator {
53
61
  private session;
62
+ /** 推断值 */
63
+ private inferences;
64
+ /** 需要跳过的问题 ID */
65
+ private skippedQuestionIds;
66
+ /**
67
+ * 设置推断值 (来自 SmartQuestionAnalyzer)
68
+ */
69
+ setInferences(inferences: Map<string, {
70
+ answer: string | string[];
71
+ reason: string;
72
+ }>): void;
73
+ /**
74
+ * 获取推断值
75
+ */
76
+ getInference(questionId: string): {
77
+ answer: string | string[];
78
+ reason: string;
79
+ } | undefined;
80
+ /**
81
+ * 检查问题是否被跳过 (使用推断值)
82
+ */
83
+ isQuestionSkipped(questionId: string): boolean;
84
+ /**
85
+ * 获取所有跳过的问题及其推断值
86
+ */
87
+ getSkippedQuestions(): Array<{
88
+ questionId: string;
89
+ answer: string | string[];
90
+ reason: string;
91
+ }>;
54
92
  /**
55
93
  * 开始新的问答会话
56
94
  */
@@ -9,22 +9,80 @@ exports.InteractiveQuestionGenerator = void 0;
9
9
  * 2. 优先级排序 - 按重要性顺序提问
10
10
  * 3. 条件分支 - 不同回答触发不同追问
11
11
  * 4. 交互友好 - 支持单步/批量回答
12
+ * 5. 智能推断 - 支持预设推断值,跳过不必要的问题
12
13
  */
13
14
  class InteractiveQuestionGenerator {
14
15
  session = null;
16
+ /** 推断值 */
17
+ inferences = new Map();
18
+ /** 需要跳过的问题 ID */
19
+ skippedQuestionIds = new Set();
20
+ /**
21
+ * 设置推断值 (来自 SmartQuestionAnalyzer)
22
+ */
23
+ setInferences(inferences) {
24
+ this.inferences = inferences;
25
+ // 高置信度的推断值可以跳过问题
26
+ for (const [questionId] of inferences) {
27
+ this.skippedQuestionIds.add(questionId);
28
+ }
29
+ }
30
+ /**
31
+ * 获取推断值
32
+ */
33
+ getInference(questionId) {
34
+ return this.inferences.get(questionId);
35
+ }
36
+ /**
37
+ * 检查问题是否被跳过 (使用推断值)
38
+ */
39
+ isQuestionSkipped(questionId) {
40
+ return this.skippedQuestionIds.has(questionId);
41
+ }
42
+ /**
43
+ * 获取所有跳过的问题及其推断值
44
+ */
45
+ getSkippedQuestions() {
46
+ const result = [];
47
+ for (const questionId of this.skippedQuestionIds) {
48
+ const inference = this.inferences.get(questionId);
49
+ if (inference) {
50
+ result.push({ questionId, ...inference });
51
+ }
52
+ }
53
+ return result;
54
+ }
15
55
  /**
16
56
  * 开始新的问答会话
17
57
  */
18
58
  startSession(parsedTask) {
19
- const baseQuestions = this.generateBaseQuestions(parsedTask);
59
+ const allQuestions = this.generateBaseQuestions(parsedTask);
60
+ // 过滤掉已跳过的问题 (使用推断值)
61
+ const questionsToAsk = allQuestions.filter(q => !this.skippedQuestionIds.has(q.id));
62
+ // 为跳过的问题创建答案
63
+ const skippedAnswers = [];
64
+ for (const question of allQuestions) {
65
+ if (this.skippedQuestionIds.has(question.id)) {
66
+ const inference = this.inferences.get(question.id);
67
+ if (inference) {
68
+ const answer = {
69
+ questionId: question.id,
70
+ selectedKeys: Array.isArray(inference.answer) ? inference.answer : [inference.answer]
71
+ };
72
+ skippedAnswers.push(answer);
73
+ }
74
+ }
75
+ }
20
76
  this.session = {
21
77
  sessionId: `qs-${Date.now().toString(36)}`,
22
78
  taskId: parsedTask.title,
23
- questions: baseQuestions.sort((a, b) => a.priority - b.priority),
24
- answers: [],
79
+ questions: questionsToAsk.sort((a, b) => a.priority - b.priority),
80
+ answers: skippedAnswers, // 预填充跳过问题的答案
25
81
  currentQuestionIndex: 0,
26
82
  status: 'in_progress',
27
- createdAt: new Date().toISOString()
83
+ createdAt: new Date().toISOString(),
84
+ inferences: this.inferences,
85
+ skippedQuestionIds: Array.from(this.skippedQuestionIds)
28
86
  };
29
87
  return this.session;
30
88
  }
@@ -0,0 +1,82 @@
1
+ import type { ParsedTask } from '../types/index.js';
2
+ /**
3
+ * 问题推断结果
4
+ */
5
+ export interface QuestionInference {
6
+ questionId: string;
7
+ inferredAnswer?: string | string[];
8
+ confidence: 'high' | 'medium' | 'low';
9
+ reason: string;
10
+ }
11
+ /**
12
+ * 项目上下文
13
+ */
14
+ export interface ProjectContext {
15
+ projectType: 'typescript' | 'javascript' | 'python' | 'go' | 'rust' | 'java' | 'unknown';
16
+ frameworks: string[];
17
+ hasFrontend: boolean;
18
+ hasBackend: boolean;
19
+ hasTests: boolean;
20
+ packageManager: 'npm' | 'yarn' | 'pnpm' | 'pip' | 'go-mod' | 'cargo' | 'unknown';
21
+ dependencies: Record<string, string>;
22
+ }
23
+ /**
24
+ * 分析结果
25
+ */
26
+ export interface AnalysisResult {
27
+ inferences: QuestionInference[];
28
+ questionsToAsk: string[];
29
+ skippedQuestions: string[];
30
+ projectContext: ProjectContext;
31
+ }
32
+ /**
33
+ * SmartQuestionAnalyzer - 智能问答分析器
34
+ *
35
+ * 根据任务描述和项目上下文智能推断问题答案,减少不必要的问答
36
+ *
37
+ * 使用方式:
38
+ * 1. 分析项目文件获取上下文
39
+ * 2. 根据任务关键词推断答案
40
+ * 3. 返回需要提问的问题列表
41
+ */
42
+ export declare class SmartQuestionAnalyzer {
43
+ private projectRoot;
44
+ private cachedContext;
45
+ constructor(projectRoot?: string);
46
+ /**
47
+ * 分析任务,返回推断结果
48
+ */
49
+ analyze(taskDescription: string, parsedTask?: ParsedTask): Promise<AnalysisResult>;
50
+ /**
51
+ * 获取项目上下文
52
+ */
53
+ getProjectContext(): Promise<ProjectContext>;
54
+ /**
55
+ * 推断问题答案
56
+ */
57
+ private inferAnswers;
58
+ /**
59
+ * 推断质量级别
60
+ */
61
+ private inferQualityLevel;
62
+ /**
63
+ * 推断技术栈
64
+ */
65
+ private inferTechStack;
66
+ /**
67
+ * 推断文档级别
68
+ */
69
+ private inferDocLevel;
70
+ /**
71
+ * 推断 E2E 测试
72
+ */
73
+ private inferE2ETest;
74
+ /**
75
+ * 推断执行模式
76
+ */
77
+ private inferExecutionMode;
78
+ /**
79
+ * 生成推断摘要
80
+ */
81
+ generateSummary(result: AnalysisResult): string;
82
+ }
@@ -0,0 +1,412 @@
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.SmartQuestionAnalyzer = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ /**
40
+ * SmartQuestionAnalyzer - 智能问答分析器
41
+ *
42
+ * 根据任务描述和项目上下文智能推断问题答案,减少不必要的问答
43
+ *
44
+ * 使用方式:
45
+ * 1. 分析项目文件获取上下文
46
+ * 2. 根据任务关键词推断答案
47
+ * 3. 返回需要提问的问题列表
48
+ */
49
+ class SmartQuestionAnalyzer {
50
+ projectRoot;
51
+ cachedContext = null;
52
+ constructor(projectRoot = process.cwd()) {
53
+ this.projectRoot = projectRoot;
54
+ }
55
+ /**
56
+ * 分析任务,返回推断结果
57
+ */
58
+ async analyze(taskDescription, parsedTask) {
59
+ // 1. 获取项目上下文
60
+ const projectContext = await this.getProjectContext();
61
+ // 2. 执行推断
62
+ const inferences = this.inferAnswers(taskDescription, projectContext);
63
+ // 3. 筛选需要提问的问题
64
+ const questionsToAsk = inferences
65
+ .filter(i => i.confidence === 'low' || !i.inferredAnswer)
66
+ .map(i => i.questionId);
67
+ const skippedQuestions = inferences
68
+ .filter(i => i.confidence !== 'low' && i.inferredAnswer)
69
+ .map(i => i.questionId);
70
+ return {
71
+ inferences,
72
+ questionsToAsk,
73
+ skippedQuestions,
74
+ projectContext
75
+ };
76
+ }
77
+ /**
78
+ * 获取项目上下文
79
+ */
80
+ async getProjectContext() {
81
+ if (this.cachedContext) {
82
+ return this.cachedContext;
83
+ }
84
+ const context = {
85
+ projectType: 'unknown',
86
+ frameworks: [],
87
+ hasFrontend: false,
88
+ hasBackend: false,
89
+ hasTests: false,
90
+ packageManager: 'unknown',
91
+ dependencies: {}
92
+ };
93
+ // 检测项目类型和依赖
94
+ const packageJsonPath = path.join(this.projectRoot, 'package.json');
95
+ if (fs.existsSync(packageJsonPath)) {
96
+ try {
97
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
98
+ context.packageManager = 'npm';
99
+ context.dependencies = {
100
+ ...packageJson.dependencies,
101
+ ...packageJson.devDependencies
102
+ };
103
+ // 检测 TypeScript
104
+ if (context.dependencies['typescript'] || fs.existsSync(path.join(this.projectRoot, 'tsconfig.json'))) {
105
+ context.projectType = 'typescript';
106
+ }
107
+ else {
108
+ context.projectType = 'javascript';
109
+ }
110
+ // 检测框架
111
+ const frameworkDeps = {
112
+ 'react': 'React',
113
+ 'vue': 'Vue',
114
+ 'svelte': 'Svelte',
115
+ 'angular': 'Angular',
116
+ 'next': 'Next.js',
117
+ 'nuxt': 'Nuxt.js',
118
+ 'express': 'Express',
119
+ 'fastify': 'Fastify',
120
+ 'nestjs': 'NestJS',
121
+ 'koa': 'Koa',
122
+ 'electron': 'Electron'
123
+ };
124
+ for (const [dep, name] of Object.entries(frameworkDeps)) {
125
+ if (context.dependencies[dep]) {
126
+ context.frameworks.push(name);
127
+ }
128
+ }
129
+ // 检测前端/后端
130
+ context.hasFrontend = ['react', 'vue', 'svelte', 'angular', 'next', 'nuxt', 'electron']
131
+ .some(dep => context.dependencies[dep]);
132
+ context.hasBackend = ['express', 'fastify', 'nestjs', 'koa']
133
+ .some(dep => context.dependencies[dep]);
134
+ // 检测测试
135
+ context.hasTests = ['vitest', 'jest', 'mocha', 'pytest', 'testing']
136
+ .some(dep => context.dependencies[dep]) ||
137
+ fs.existsSync(path.join(this.projectRoot, 'tests')) ||
138
+ fs.existsSync(path.join(this.projectRoot, 'test'));
139
+ }
140
+ catch {
141
+ // 忽略解析错误
142
+ }
143
+ }
144
+ // 检测 Python 项目
145
+ if (fs.existsSync(path.join(this.projectRoot, 'requirements.txt')) ||
146
+ fs.existsSync(path.join(this.projectRoot, 'pyproject.toml'))) {
147
+ context.projectType = 'python';
148
+ context.packageManager = 'pip';
149
+ }
150
+ // 检测 Go 项目
151
+ if (fs.existsSync(path.join(this.projectRoot, 'go.mod'))) {
152
+ context.projectType = 'go';
153
+ context.packageManager = 'go-mod';
154
+ }
155
+ // 检测 Rust 项目
156
+ if (fs.existsSync(path.join(this.projectRoot, 'Cargo.toml'))) {
157
+ context.projectType = 'rust';
158
+ context.packageManager = 'cargo';
159
+ }
160
+ this.cachedContext = context;
161
+ return context;
162
+ }
163
+ /**
164
+ * 推断问题答案
165
+ */
166
+ inferAnswers(taskDescription, context) {
167
+ const inferences = [];
168
+ const desc = taskDescription.toLowerCase();
169
+ // 1. 推断质量级别
170
+ inferences.push(this.inferQualityLevel(desc, context));
171
+ // 2. 推断技术栈
172
+ inferences.push(this.inferTechStack(desc, context));
173
+ // 3. 推断文档级别
174
+ inferences.push(this.inferDocLevel(desc, context));
175
+ // 4. 推断 E2E 测试
176
+ inferences.push(this.inferE2ETest(desc, context));
177
+ // 5. 推断执行模式
178
+ inferences.push(this.inferExecutionMode(desc, context));
179
+ return inferences;
180
+ }
181
+ /**
182
+ * 推断质量级别
183
+ */
184
+ inferQualityLevel(desc, context) {
185
+ const inference = {
186
+ questionId: 'quality_level',
187
+ confidence: 'low',
188
+ reason: ''
189
+ };
190
+ // Bug 修复 -> balanced
191
+ if (/(fix|bug|修复|hotfix|patch|问题)/i.test(desc)) {
192
+ inference.inferredAnswer = 'balanced';
193
+ inference.confidence = 'high';
194
+ inference.reason = '任务涉及 Bug 修复';
195
+ return inference;
196
+ }
197
+ // 原型/POC -> fast
198
+ if (/(prototype|poc|demo|快速|原型|示例|sample)/i.test(desc)) {
199
+ inference.inferredAnswer = 'fast';
200
+ inference.confidence = 'high';
201
+ inference.reason = '任务涉及原型或演示';
202
+ return inference;
203
+ }
204
+ // 测试相关 -> strict
205
+ if (/(test|测试|单元|unit|coverage|覆盖率)/i.test(desc)) {
206
+ inference.inferredAnswer = 'strict';
207
+ inference.confidence = 'high';
208
+ inference.reason = '任务涉及测试';
209
+ return inference;
210
+ }
211
+ // 新功能/生产代码 -> strict
212
+ if (/(implement|add|新功能|实现|开发|feature|生产)/i.test(desc)) {
213
+ inference.inferredAnswer = 'strict';
214
+ inference.confidence = 'medium';
215
+ inference.reason = '任务涉及新功能开发';
216
+ return inference;
217
+ }
218
+ // 重构 -> balanced
219
+ if (/(refactor|优化|重构|improve)/i.test(desc)) {
220
+ inference.inferredAnswer = 'balanced';
221
+ inference.confidence = 'medium';
222
+ inference.reason = '任务涉及代码重构';
223
+ return inference;
224
+ }
225
+ inference.reason = '无法确定任务类型';
226
+ return inference;
227
+ }
228
+ /**
229
+ * 推断技术栈
230
+ */
231
+ inferTechStack(desc, context) {
232
+ const inference = {
233
+ questionId: 'tech_stack',
234
+ confidence: 'low',
235
+ reason: ''
236
+ };
237
+ const detected = [];
238
+ // 从项目上下文检测
239
+ if (context.projectType === 'typescript') {
240
+ detected.push('typescript');
241
+ }
242
+ else if (context.projectType === 'python') {
243
+ detected.push('python');
244
+ }
245
+ else if (context.projectType === 'go') {
246
+ detected.push('go');
247
+ }
248
+ else if (context.projectType === 'rust') {
249
+ detected.push('rust');
250
+ }
251
+ // 从任务描述检测
252
+ const techKeywords = {
253
+ 'typescript': ['typescript', 'ts', 'tsx'],
254
+ 'javascript': ['javascript', 'js', 'jsx'],
255
+ 'react': ['react', 'reactjs'],
256
+ 'vue': ['vue', 'vuejs', 'vue3'],
257
+ 'node': ['node', 'nodejs', 'express', 'koa'],
258
+ 'python': ['python', 'py', 'django', 'flask', 'fastapi'],
259
+ 'go': ['golang', 'go'],
260
+ 'rust': ['rust', 'cargo']
261
+ };
262
+ for (const [tech, keywords] of Object.entries(techKeywords)) {
263
+ if (keywords.some(kw => desc.includes(kw))) {
264
+ if (!detected.includes(tech)) {
265
+ detected.push(tech);
266
+ }
267
+ }
268
+ }
269
+ // 从项目框架检测
270
+ for (const framework of context.frameworks) {
271
+ const normalized = framework.toLowerCase();
272
+ if (!detected.includes(normalized)) {
273
+ detected.push(normalized);
274
+ }
275
+ }
276
+ if (detected.length > 0) {
277
+ inference.inferredAnswer = detected;
278
+ inference.confidence = context.projectType !== 'unknown' ? 'high' : 'medium';
279
+ inference.reason = `检测到技术栈: ${detected.join(', ')}`;
280
+ }
281
+ else {
282
+ inference.reason = '无法检测技术栈';
283
+ }
284
+ return inference;
285
+ }
286
+ /**
287
+ * 推断文档级别
288
+ */
289
+ inferDocLevel(desc, context) {
290
+ const inference = {
291
+ questionId: 'doc_level',
292
+ confidence: 'low',
293
+ reason: ''
294
+ };
295
+ // Bug 修复 -> 无需文档
296
+ if (/(fix|bug|修复|hotfix)/i.test(desc)) {
297
+ inference.inferredAnswer = 'none';
298
+ inference.confidence = 'high';
299
+ inference.reason = 'Bug 修复通常不需要文档';
300
+ return inference;
301
+ }
302
+ // 重构 -> 最小文档
303
+ if (/(refactor|优化|重构)/i.test(desc)) {
304
+ inference.inferredAnswer = 'minimal';
305
+ inference.confidence = 'medium';
306
+ inference.reason = '重构任务通常需要最小文档';
307
+ return inference;
308
+ }
309
+ // API/模块/库 -> 完整文档
310
+ if (/(api|module|library|组件|库|sdk)/i.test(desc)) {
311
+ inference.inferredAnswer = 'full';
312
+ inference.confidence = 'medium';
313
+ inference.reason = 'API/模块开发需要完整文档';
314
+ return inference;
315
+ }
316
+ // 新功能 -> 基础文档
317
+ if (/(implement|add|新功能|实现|开发|feature)/i.test(desc)) {
318
+ inference.inferredAnswer = 'basic';
319
+ inference.confidence = 'medium';
320
+ inference.reason = '新功能开发需要基础文档';
321
+ return inference;
322
+ }
323
+ inference.reason = '无法确定文档需求';
324
+ return inference;
325
+ }
326
+ /**
327
+ * 推断 E2E 测试
328
+ */
329
+ inferE2ETest(desc, context) {
330
+ const inference = {
331
+ questionId: 'e2e_test',
332
+ confidence: 'low',
333
+ reason: ''
334
+ };
335
+ // CLI/后端 -> 不需要 E2E
336
+ if (/(cli|api|backend|后端|命令行)/i.test(desc) && !context.hasFrontend) {
337
+ inference.inferredAnswer = 'false';
338
+ inference.confidence = 'high';
339
+ inference.reason = 'CLI/后端任务不需要 E2E 测试';
340
+ return inference;
341
+ }
342
+ // 前端页面 -> 询问
343
+ if (context.hasFrontend || /(page|ui|前端|界面|web)/i.test(desc)) {
344
+ inference.confidence = 'low';
345
+ inference.reason = '前端任务可能需要 E2E 测试,需要用户确认';
346
+ return inference;
347
+ }
348
+ // 默认不需要
349
+ inference.inferredAnswer = 'false';
350
+ inference.confidence = 'medium';
351
+ inference.reason = '默认不需要 E2E 测试';
352
+ return inference;
353
+ }
354
+ /**
355
+ * 推断执行模式
356
+ */
357
+ inferExecutionMode(desc, context) {
358
+ const inference = {
359
+ questionId: 'execution_mode',
360
+ confidence: 'low',
361
+ reason: ''
362
+ };
363
+ // 快速原型 -> 全自动
364
+ if (/(prototype|poc|demo|快速|原型)/i.test(desc)) {
365
+ inference.inferredAnswer = 'auto';
366
+ inference.confidence = 'medium';
367
+ inference.reason = '原型任务适合全自动执行';
368
+ return inference;
369
+ }
370
+ // 简单修复 -> 全自动
371
+ if (/(fix|bug|修复|hotfix)/i.test(desc) && desc.length < 100) {
372
+ inference.inferredAnswer = 'auto';
373
+ inference.confidence = 'medium';
374
+ inference.reason = '简单 Bug 修复适合全自动执行';
375
+ return inference;
376
+ }
377
+ // 新功能 -> 每阶段确认
378
+ if (/(implement|add|新功能|实现|开发)/i.test(desc)) {
379
+ inference.inferredAnswer = 'phase';
380
+ inference.confidence = 'medium';
381
+ inference.reason = '新功能开发适合每阶段确认';
382
+ return inference;
383
+ }
384
+ inference.reason = '无法确定执行模式';
385
+ return inference;
386
+ }
387
+ /**
388
+ * 生成推断摘要
389
+ */
390
+ generateSummary(result) {
391
+ const lines = ['📊 AI 推断结果:\n'];
392
+ for (const inference of result.inferences) {
393
+ const icon = inference.confidence === 'high' ? '✅' :
394
+ inference.confidence === 'medium' ? '🤔' : '❓';
395
+ const answer = Array.isArray(inference.inferredAnswer)
396
+ ? inference.inferredAnswer.join(', ')
397
+ : inference.inferredAnswer || '待确认';
398
+ lines.push(`${icon} ${inference.questionId}: ${answer}`);
399
+ if (inference.reason) {
400
+ lines.push(` └─ ${inference.reason}`);
401
+ }
402
+ }
403
+ if (result.questionsToAsk.length > 0) {
404
+ lines.push(`\n❓ 需要确认的问题: ${result.questionsToAsk.join(', ')}`);
405
+ }
406
+ else {
407
+ lines.push('\n✅ 所有问题已推断,无需额外确认');
408
+ }
409
+ return lines.join('\n');
410
+ }
411
+ }
412
+ exports.SmartQuestionAnalyzer = SmartQuestionAnalyzer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openmatrix",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
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/start.md CHANGED
@@ -8,7 +8,7 @@ description: 启动新的任务执行周期
8
8
  </NO-OTHER-SKILLS>
9
9
 
10
10
  <objective>
11
- 解析任务文档,通过交互式问答澄清需求(3-7个问题,支持多轮追问),确认后启动执行。
11
+ 解析任务文档,通过智能分析自动推断配置,仅对不确定的问题进行交互式问答,确认后启动执行。
12
12
  </objective>
13
13
 
14
14
  <process>
@@ -39,13 +39,48 @@ description: 启动新的任务执行周期
39
39
  - 如果 `$ARGUMENTS` 是任务描述 → 直接使用
40
40
  - 如果无参数 → **使用 AskUserQuestion 询问用户要执行的任务**
41
41
 
42
- 5. **⚠️ 交互式问答 (必须执行)**
42
+ 5. **🔍 智能分析 (新流程)**
43
43
 
44
- **重要**: 除非用户明确指定 `--skip-questions` 或提供了 `--quality` 等选项,否则必须执行交互式问答。
44
+ **首先调用 CLI 进行智能分析:**
45
+ ```bash
46
+ openmatrix analyze --json
47
+ ```
48
+
49
+ 这会返回分析结果:
50
+ ```json
51
+ {
52
+ "inferences": [
53
+ { "questionId": "quality_level", "inferredAnswer": "strict", "confidence": "high", "reason": "任务涉及新功能开发" },
54
+ { "questionId": "tech_stack", "inferredAnswer": ["typescript", "react"], "confidence": "high", "reason": "检测到技术栈: TypeScript, React" },
55
+ { "questionId": "doc_level", "inferredAnswer": "basic", "confidence": "medium", "reason": "新功能开发需要基础文档" }
56
+ ],
57
+ "questionsToAsk": ["e2e_test"],
58
+ "skippedQuestions": ["quality_level", "tech_stack", "doc_level"],
59
+ "projectContext": { "projectType": "typescript", "frameworks": ["React"], "hasFrontend": true }
60
+ }
61
+ ```
62
+
63
+ **展示推断摘要:**
64
+ ```
65
+ 🔍 AI 正在分析任务...
66
+
67
+ 📊 推断结果:
68
+ ✅ 质量级别: strict (任务涉及新功能开发)
69
+ ✅ 技术栈: TypeScript, React (检测到技术栈)
70
+ ✅ 文档级别: 基础文档 (新功能开发需要基础文档)
71
+
72
+ ❓ 需要确认的问题: E2E测试
73
+ ```
74
+
75
+ 6. **⚠️ 交互式问答 (仅针对不确定的问题)**
76
+
77
+ **重要改进**: 现在只对 AI 无法推断或置信度低的问题进行问答。
78
+
79
+ **如果 `questionsToAsk` 为空**: 直接使用推断值,跳过问答。
45
80
 
46
- 使用 `AskUserQuestion` 工具,逐个提出以下问题:
81
+ **如果有需要确认的问题**: 使用 `AskUserQuestion` 逐个提问。
47
82
 
48
- **问题 0: 质量级别 (最重要,第一个问)**
83
+ **问题 0: 质量级别** (仅当 questionsToAsk 包含 "quality_level" 时询问)
49
84
  ```typescript
50
85
  AskUserQuestion({
51
86
  questions: [{
@@ -116,7 +151,7 @@ description: 启动新的任务执行周期
116
151
  })
117
152
  ```
118
153
 
119
- **问题 1: 任务目标**
154
+ **问题 1: 任务目标** (仅当 questionsToAsk 包含 "objective" 时询问)
120
155
  ```typescript
121
156
  AskUserQuestion({
122
157
  questions: [{
@@ -133,7 +168,7 @@ description: 启动新的任务执行周期
133
168
  })
134
169
  ```
135
170
 
136
- **问题 2: 技术栈** (根据任务内容动态生成)
171
+ **问题 2: 技术栈** (仅当 questionsToAsk 包含 "tech_stack" 时询问,否则使用项目检测值)
137
172
  ```typescript
138
173
  AskUserQuestion({
139
174
  questions: [{
@@ -150,7 +185,7 @@ description: 启动新的任务执行周期
150
185
  })
151
186
  ```
152
187
 
153
- **问题 3: 文档要求**
188
+ **问题 3: 文档要求** (仅当 questionsToAsk 包含 "doc_level" 时询问)
154
189
  ```typescript
155
190
  AskUserQuestion({
156
191
  questions: [{