openmatrix 0.1.0

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.
Files changed (85) hide show
  1. package/README.md +512 -0
  2. package/dist/agents/agent-runner.d.ts +152 -0
  3. package/dist/agents/agent-runner.js +656 -0
  4. package/dist/agents/base-agent.d.ts +46 -0
  5. package/dist/agents/base-agent.js +17 -0
  6. package/dist/agents/impl/coder-agent.d.ts +17 -0
  7. package/dist/agents/impl/coder-agent.js +96 -0
  8. package/dist/agents/impl/executor-agent.d.ts +32 -0
  9. package/dist/agents/impl/executor-agent.js +168 -0
  10. package/dist/agents/impl/index.d.ts +6 -0
  11. package/dist/agents/impl/index.js +17 -0
  12. package/dist/agents/impl/planner-agent.d.ts +24 -0
  13. package/dist/agents/impl/planner-agent.js +126 -0
  14. package/dist/agents/impl/researcher-agent.d.ts +17 -0
  15. package/dist/agents/impl/researcher-agent.js +133 -0
  16. package/dist/agents/impl/reviewer-agent.d.ts +17 -0
  17. package/dist/agents/impl/reviewer-agent.js +120 -0
  18. package/dist/agents/impl/tester-agent.d.ts +17 -0
  19. package/dist/agents/impl/tester-agent.js +110 -0
  20. package/dist/cli/commands/approve.d.ts +2 -0
  21. package/dist/cli/commands/approve.js +87 -0
  22. package/dist/cli/commands/meeting.d.ts +2 -0
  23. package/dist/cli/commands/meeting.js +245 -0
  24. package/dist/cli/commands/report.d.ts +2 -0
  25. package/dist/cli/commands/report.js +202 -0
  26. package/dist/cli/commands/resume.d.ts +2 -0
  27. package/dist/cli/commands/resume.js +104 -0
  28. package/dist/cli/commands/retry.d.ts +2 -0
  29. package/dist/cli/commands/retry.js +79 -0
  30. package/dist/cli/commands/start.d.ts +2 -0
  31. package/dist/cli/commands/start.js +252 -0
  32. package/dist/cli/commands/status.d.ts +2 -0
  33. package/dist/cli/commands/status.js +226 -0
  34. package/dist/cli/index.d.ts +2 -0
  35. package/dist/cli/index.js +26 -0
  36. package/dist/index.d.ts +2 -0
  37. package/dist/index.js +9 -0
  38. package/dist/orchestrator/ai-reviewer.d.ts +50 -0
  39. package/dist/orchestrator/ai-reviewer.js +326 -0
  40. package/dist/orchestrator/approval-manager.d.ts +62 -0
  41. package/dist/orchestrator/approval-manager.js +160 -0
  42. package/dist/orchestrator/executor.d.ts +114 -0
  43. package/dist/orchestrator/executor.js +325 -0
  44. package/dist/orchestrator/full-test-runner.d.ts +122 -0
  45. package/dist/orchestrator/full-test-runner.js +335 -0
  46. package/dist/orchestrator/git-commit-manager.d.ts +75 -0
  47. package/dist/orchestrator/git-commit-manager.js +248 -0
  48. package/dist/orchestrator/interactive-question-generator.d.ts +90 -0
  49. package/dist/orchestrator/interactive-question-generator.js +312 -0
  50. package/dist/orchestrator/meeting-manager.d.ts +85 -0
  51. package/dist/orchestrator/meeting-manager.js +222 -0
  52. package/dist/orchestrator/phase-executor.d.ts +198 -0
  53. package/dist/orchestrator/phase-executor.js +796 -0
  54. package/dist/orchestrator/question-generator.d.ts +22 -0
  55. package/dist/orchestrator/question-generator.js +102 -0
  56. package/dist/orchestrator/retry-manager.d.ts +41 -0
  57. package/dist/orchestrator/retry-manager.js +83 -0
  58. package/dist/orchestrator/scheduler.d.ts +62 -0
  59. package/dist/orchestrator/scheduler.js +148 -0
  60. package/dist/orchestrator/state-machine.d.ts +53 -0
  61. package/dist/orchestrator/state-machine.js +124 -0
  62. package/dist/orchestrator/task-parser.d.ts +7 -0
  63. package/dist/orchestrator/task-parser.js +63 -0
  64. package/dist/orchestrator/task-planner.d.ts +71 -0
  65. package/dist/orchestrator/task-planner.js +316 -0
  66. package/dist/storage/file-store.d.ts +12 -0
  67. package/dist/storage/file-store.js +80 -0
  68. package/dist/storage/state-manager.d.ts +31 -0
  69. package/dist/storage/state-manager.js +202 -0
  70. package/dist/types/index.d.ts +193 -0
  71. package/dist/types/index.js +30 -0
  72. package/dist/utils/logger.d.ts +41 -0
  73. package/dist/utils/logger.js +166 -0
  74. package/dist/utils/progress-reporter.d.ts +116 -0
  75. package/dist/utils/progress-reporter.js +287 -0
  76. package/package.json +50 -0
  77. package/scripts/build-check.js +19 -0
  78. package/scripts/install-skills.js +51 -0
  79. package/skills/approve.md +253 -0
  80. package/skills/meeting.md +346 -0
  81. package/skills/report.md +100 -0
  82. package/skills/resume.md +68 -0
  83. package/skills/retry.md +61 -0
  84. package/skills/start.md +449 -0
  85. package/skills/status.md +46 -0
@@ -0,0 +1,22 @@
1
+ import type { ParsedTask } from '../types/index.js';
2
+ export interface Question {
3
+ id: string;
4
+ question: string;
5
+ type: 'single' | 'multiple' | 'text';
6
+ options?: QuestionOption[];
7
+ required: boolean;
8
+ }
9
+ export interface QuestionOption {
10
+ key: string;
11
+ label: string;
12
+ description?: string;
13
+ }
14
+ export declare class QuestionGenerator {
15
+ generate(parsedTask: ParsedTask): Question[];
16
+ private needsTechStackQuestion;
17
+ private createTechStackQuestion;
18
+ private createPriorityQuestion;
19
+ private createConstraintConfirmation;
20
+ private createDeliverableConfirmation;
21
+ private createTestQuestion;
22
+ }
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QuestionGenerator = void 0;
4
+ class QuestionGenerator {
5
+ generate(parsedTask) {
6
+ const questions = [];
7
+ // 1. 技术栈选择
8
+ if (this.needsTechStackQuestion(parsedTask)) {
9
+ questions.push(this.createTechStackQuestion());
10
+ }
11
+ // 2. 优先级确认
12
+ if (parsedTask.goals.length > 1) {
13
+ questions.push(this.createPriorityQuestion(parsedTask.goals));
14
+ }
15
+ // 3. 约束条件确认
16
+ if (parsedTask.constraints.length > 0) {
17
+ questions.push(this.createConstraintConfirmation(parsedTask.constraints));
18
+ }
19
+ // 4. 交付物确认
20
+ if (parsedTask.deliverables.length > 0) {
21
+ questions.push(this.createDeliverableConfirmation(parsedTask.deliverables));
22
+ }
23
+ // 5. 测试要求
24
+ questions.push(this.createTestQuestion());
25
+ return questions;
26
+ }
27
+ needsTechStackQuestion(task) {
28
+ // 如果任务描述中没有明确提到技术栈,则需要询问
29
+ const techKeywords = ['TypeScript', 'JavaScript', 'React', 'Vue', 'Node', 'Python'];
30
+ const content = task.rawContent.toLowerCase();
31
+ return !techKeywords.some(kw => content.includes(kw.toLowerCase()));
32
+ }
33
+ createTechStackQuestion() {
34
+ return {
35
+ id: 'tech_stack',
36
+ question: '请选择项目使用的主要技术栈?',
37
+ type: 'multiple',
38
+ required: true,
39
+ options: [
40
+ { key: 'typescript', label: 'TypeScript', description: '类型安全的 JavaScript 超集' },
41
+ { key: 'javascript', label: 'JavaScript', description: '标准 JavaScript' },
42
+ { key: 'react', label: 'React', description: 'React 前端框架' },
43
+ { key: 'vue', label: 'Vue', description: 'Vue 前端框架' },
44
+ { key: 'node', label: 'Node.js', description: 'Node.js 后端运行时' },
45
+ { key: 'python', label: 'Python', description: 'Python 语言' }
46
+ ]
47
+ };
48
+ }
49
+ createPriorityQuestion(goals) {
50
+ return {
51
+ id: 'priority',
52
+ question: '以下目标中,哪些是核心必须完成的?(可多选)',
53
+ type: 'multiple',
54
+ required: true,
55
+ options: goals.map((goal, index) => ({
56
+ key: `goal_${index}`,
57
+ label: goal
58
+ }))
59
+ };
60
+ }
61
+ createConstraintConfirmation(constraints) {
62
+ return {
63
+ id: 'constraints_confirm',
64
+ question: '请确认以下约束条件是否正确?',
65
+ type: 'single',
66
+ required: true,
67
+ options: [
68
+ { key: 'confirm', label: '确认正确', description: '所有约束条件都符合预期' },
69
+ { key: 'modify', label: '需要修改', description: '部分约束需要调整' },
70
+ { key: 'ignore', label: '忽略约束', description: '不遵循这些约束条件' }
71
+ ]
72
+ };
73
+ }
74
+ createDeliverableConfirmation(deliverables) {
75
+ return {
76
+ id: 'deliverables_confirm',
77
+ question: `需要生成以下 ${deliverables.length} 个交付物,是否确认?`,
78
+ type: 'single',
79
+ required: true,
80
+ options: [
81
+ { key: 'confirm', label: '确认', description: '生成所有列出的交付物' },
82
+ { key: 'partial', label: '部分生成', description: '只生成部分交付物' },
83
+ { key: 'custom', label: '自定义', description: '添加或删除某些交付物' }
84
+ ]
85
+ };
86
+ }
87
+ createTestQuestion() {
88
+ return {
89
+ id: 'test_requirement',
90
+ question: '测试覆盖率要求?',
91
+ type: 'single',
92
+ required: false,
93
+ options: [
94
+ { key: 'high', label: '高 (>80%)', description: '完整的单元测试和集成测试' },
95
+ { key: 'medium', label: '中 (50-80%)', description: '核心功能的测试' },
96
+ { key: 'low', label: '低 (<50%)', description: '仅关键路径测试' },
97
+ { key: 'none', label: '不需要', description: '不生成测试代码' }
98
+ ]
99
+ };
100
+ }
101
+ }
102
+ exports.QuestionGenerator = QuestionGenerator;
@@ -0,0 +1,41 @@
1
+ export interface RetryConfig {
2
+ maxRetries: number;
3
+ backoff: 'exponential' | 'linear' | 'fixed';
4
+ baseDelay: number;
5
+ }
6
+ export interface RetryItem {
7
+ taskId: string;
8
+ attempt: number;
9
+ nextRetryAt: number;
10
+ error: string;
11
+ }
12
+ export declare class RetryManager {
13
+ private queue;
14
+ private config;
15
+ constructor(config?: Partial<RetryConfig>);
16
+ /**
17
+ * Add a failed task to retry queue
18
+ */
19
+ addToQueue(taskId: string, error: string): void;
20
+ /**
21
+ * Get tasks ready for retry
22
+ */
23
+ getReadyTasks(): RetryItem[];
24
+ /**
25
+ * Remove a task from the queue
26
+ */
27
+ removeFromQueue(taskId: string): void;
28
+ /**
29
+ * Check if a task should be retried
30
+ */
31
+ shouldRetry(taskId: string): boolean;
32
+ /**
33
+ * Get queue status
34
+ */
35
+ getQueueStatus(): {
36
+ total: number;
37
+ ready: number;
38
+ pending: number;
39
+ };
40
+ private calculateDelay;
41
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RetryManager = void 0;
4
+ class RetryManager {
5
+ queue = [];
6
+ config;
7
+ constructor(config = {}) {
8
+ this.config = {
9
+ maxRetries: 3,
10
+ backoff: 'exponential',
11
+ baseDelay: 30000, // 30 seconds
12
+ ...config
13
+ };
14
+ }
15
+ /**
16
+ * Add a failed task to retry queue
17
+ */
18
+ addToQueue(taskId, error) {
19
+ const existing = this.queue.find(item => item.taskId === taskId);
20
+ if (existing) {
21
+ existing.attempt++;
22
+ existing.nextRetryAt = this.calculateDelay(existing.attempt);
23
+ existing.error = error;
24
+ }
25
+ else {
26
+ this.queue.push({
27
+ taskId,
28
+ attempt: 1,
29
+ nextRetryAt: Date.now() + this.calculateDelay(1),
30
+ error
31
+ });
32
+ }
33
+ }
34
+ /**
35
+ * Get tasks ready for retry
36
+ */
37
+ getReadyTasks() {
38
+ const now = Date.now();
39
+ return this.queue.filter(item => item.nextRetryAt <= now);
40
+ }
41
+ /**
42
+ * Remove a task from the queue
43
+ */
44
+ removeFromQueue(taskId) {
45
+ const index = this.queue.findIndex(item => item.taskId === taskId);
46
+ if (index !== -1) {
47
+ this.queue.splice(index, 1);
48
+ }
49
+ }
50
+ /**
51
+ * Check if a task should be retried
52
+ */
53
+ shouldRetry(taskId) {
54
+ const item = this.queue.find(item => item.taskId === taskId);
55
+ if (!item)
56
+ return false;
57
+ return item.attempt < this.config.maxRetries;
58
+ }
59
+ /**
60
+ * Get queue status
61
+ */
62
+ getQueueStatus() {
63
+ const now = Date.now();
64
+ return {
65
+ total: this.queue.length,
66
+ ready: this.getReadyTasks().length,
67
+ pending: this.queue.filter(item => item.nextRetryAt > now).length
68
+ };
69
+ }
70
+ calculateDelay(attempt) {
71
+ switch (this.config.backoff) {
72
+ case 'exponential':
73
+ return Math.min(this.config.baseDelay * Math.pow(2, attempt - 1), 300000 // Max 5 minutes
74
+ );
75
+ case 'linear':
76
+ return this.config.baseDelay * attempt;
77
+ case 'fixed':
78
+ default:
79
+ return this.config.baseDelay;
80
+ }
81
+ }
82
+ }
83
+ exports.RetryManager = RetryManager;
@@ -0,0 +1,62 @@
1
+ import type { Task, AgentType } from '../types/index.js';
2
+ import { StateManager } from '../storage/state-manager.js';
3
+ export interface SchedulerConfig {
4
+ maxConcurrentTasks: number;
5
+ taskTimeout: number;
6
+ }
7
+ export interface TaskAssignment {
8
+ taskId: string;
9
+ agentType: AgentType;
10
+ priority: number;
11
+ dependencies: string[];
12
+ }
13
+ export declare class Scheduler {
14
+ private stateManager;
15
+ private config;
16
+ private runningTasks;
17
+ constructor(stateManager: StateManager, config?: Partial<SchedulerConfig>);
18
+ /**
19
+ * 获取下一个可执行的任务
20
+ */
21
+ getNextTask(): Promise<Task | null>;
22
+ /**
23
+ * 检查任务是否可执行
24
+ */
25
+ private canExecute;
26
+ /**
27
+ * 获取优先级权重
28
+ */
29
+ private getPriorityWeight;
30
+ /**
31
+ * 标记任务开始执行
32
+ */
33
+ markTaskStarted(taskId: string): Promise<void>;
34
+ /**
35
+ * 标记任务完成
36
+ */
37
+ markTaskCompleted(taskId: string): Promise<void>;
38
+ /**
39
+ * 标记任务失败
40
+ */
41
+ markTaskFailed(taskId: string, error: string): Promise<void>;
42
+ /**
43
+ * 标记任务等待确认
44
+ */
45
+ markTaskWaiting(taskId: string): Promise<void>;
46
+ /**
47
+ * 标记任务阻塞(需要 Meeting)
48
+ */
49
+ markTaskBlocked(taskId: string, reason: string): Promise<void>;
50
+ /**
51
+ * 获取所有可并行执行的任务
52
+ */
53
+ getParallelTasks(): Promise<Task[]>;
54
+ /**
55
+ * 获取调度状态
56
+ */
57
+ getStatus(): {
58
+ running: number;
59
+ maxConcurrent: number;
60
+ runningTaskIds: string[];
61
+ };
62
+ }
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Scheduler = void 0;
4
+ class Scheduler {
5
+ stateManager;
6
+ config;
7
+ runningTasks = new Set();
8
+ constructor(stateManager, config) {
9
+ this.stateManager = stateManager;
10
+ this.config = {
11
+ maxConcurrentTasks: 3,
12
+ taskTimeout: 120000,
13
+ ...config
14
+ };
15
+ }
16
+ /**
17
+ * 获取下一个可执行的任务
18
+ */
19
+ async getNextTask() {
20
+ const tasks = await this.stateManager.listTasks();
21
+ // 筛选可执行任务
22
+ const executable = tasks.filter(task => this.canExecute(task, tasks));
23
+ if (executable.length === 0) {
24
+ return null;
25
+ }
26
+ // 按优先级排序
27
+ executable.sort((a, b) => this.getPriorityWeight(b.priority) - this.getPriorityWeight(a.priority));
28
+ return executable[0];
29
+ }
30
+ /**
31
+ * 检查任务是否可执行
32
+ */
33
+ canExecute(task, allTasks) {
34
+ // 1. 状态必须是 pending 或 retry_queue
35
+ if (task.status !== 'pending' && task.status !== 'retry_queue') {
36
+ return false;
37
+ }
38
+ // 2. 检查并发限制
39
+ if (this.runningTasks.size >= this.config.maxConcurrentTasks) {
40
+ return false;
41
+ }
42
+ // 3. 检查依赖是否完成
43
+ if (task.dependencies && task.dependencies.length > 0) {
44
+ for (const depId of task.dependencies) {
45
+ const depTask = allTasks.find(t => t.id === depId);
46
+ if (!depTask || depTask.status !== 'completed') {
47
+ return false;
48
+ }
49
+ }
50
+ }
51
+ return true;
52
+ }
53
+ /**
54
+ * 获取优先级权重
55
+ */
56
+ getPriorityWeight(priority) {
57
+ const weights = {
58
+ 'P0': 4,
59
+ 'P1': 3,
60
+ 'P2': 2,
61
+ 'P3': 1
62
+ };
63
+ return weights[priority] || 0;
64
+ }
65
+ /**
66
+ * 标记任务开始执行
67
+ */
68
+ async markTaskStarted(taskId) {
69
+ this.runningTasks.add(taskId);
70
+ await this.stateManager.updateTask(taskId, {
71
+ status: 'in_progress',
72
+ phases: {
73
+ develop: { status: 'in_progress', duration: null, startedAt: new Date().toISOString() },
74
+ verify: { status: 'pending', duration: null },
75
+ accept: { status: 'pending', duration: null }
76
+ }
77
+ });
78
+ }
79
+ /**
80
+ * 标记任务完成
81
+ */
82
+ async markTaskCompleted(taskId) {
83
+ this.runningTasks.delete(taskId);
84
+ const task = await this.stateManager.getTask(taskId);
85
+ if (task) {
86
+ await this.stateManager.updateTask(taskId, {
87
+ status: 'completed',
88
+ phases: {
89
+ ...task.phases,
90
+ accept: { status: 'completed', duration: 0, completedAt: new Date().toISOString() }
91
+ }
92
+ });
93
+ }
94
+ }
95
+ /**
96
+ * 标记任务失败
97
+ */
98
+ async markTaskFailed(taskId, error) {
99
+ this.runningTasks.delete(taskId);
100
+ await this.stateManager.updateTask(taskId, {
101
+ status: 'failed',
102
+ error,
103
+ retryCount: (await this.stateManager.getTask(taskId))?.retryCount || 0
104
+ });
105
+ }
106
+ /**
107
+ * 标记任务等待确认
108
+ */
109
+ async markTaskWaiting(taskId) {
110
+ await this.stateManager.updateTask(taskId, {
111
+ status: 'waiting'
112
+ });
113
+ }
114
+ /**
115
+ * 标记任务阻塞(需要 Meeting)
116
+ */
117
+ async markTaskBlocked(taskId, reason) {
118
+ this.runningTasks.delete(taskId);
119
+ await this.stateManager.updateTask(taskId, {
120
+ status: 'blocked',
121
+ error: reason
122
+ });
123
+ }
124
+ /**
125
+ * 获取所有可并行执行的任务
126
+ */
127
+ async getParallelTasks() {
128
+ const tasks = await this.stateManager.listTasks();
129
+ const available = [];
130
+ for (const task of tasks) {
131
+ if (this.canExecute(task, tasks) && available.length < this.config.maxConcurrentTasks) {
132
+ available.push(task);
133
+ }
134
+ }
135
+ return available;
136
+ }
137
+ /**
138
+ * 获取调度状态
139
+ */
140
+ getStatus() {
141
+ return {
142
+ running: this.runningTasks.size,
143
+ maxConcurrent: this.config.maxConcurrentTasks,
144
+ runningTaskIds: Array.from(this.runningTasks)
145
+ };
146
+ }
147
+ }
148
+ exports.Scheduler = Scheduler;
@@ -0,0 +1,53 @@
1
+ import type { Task, TaskStatus } from '../types/index.js';
2
+ /**
3
+ * 任务状态转换规则
4
+ *
5
+ * pending → scheduled → in_progress → verify → accept → completed
6
+ * │ │ │ │
7
+ * │ ▼ ▼ ▼
8
+ * │ blocked failed failed
9
+ * │ │ │ │
10
+ * │ ▼ └────────┘
11
+ * │ waiting │
12
+ * │ │ ▼
13
+ * └────────────┴──────────► retry_queue
14
+ */
15
+ export type TransitionEvent = 'schedule' | 'start' | 'develop_done' | 'verify_done' | 'accept_done' | 'need_verify' | 'need_accept' | 'block' | 'unblock' | 'wait' | 'resume' | 'fail' | 'retry' | 'cancel';
16
+ export interface TransitionResult {
17
+ success: boolean;
18
+ fromStatus: TaskStatus;
19
+ toStatus: TaskStatus;
20
+ event: TransitionEvent;
21
+ error?: string;
22
+ }
23
+ export interface StateTransition {
24
+ from: TaskStatus;
25
+ to: TaskStatus;
26
+ event: TransitionEvent;
27
+ condition?: (task: Task) => boolean;
28
+ }
29
+ export declare class StateMachine {
30
+ /**
31
+ * 尝试转换状态
32
+ */
33
+ transition(task: Task, event: TransitionEvent): TransitionResult;
34
+ /**
35
+ * 获取当前状态允许的转换
36
+ */
37
+ getAllowedTransitions(status: TaskStatus): {
38
+ event: TransitionEvent;
39
+ toStatus: TaskStatus;
40
+ }[];
41
+ /**
42
+ * 检查是否可以执行指定事件
43
+ */
44
+ canTransition(task: Task, event: TransitionEvent): boolean;
45
+ /**
46
+ * 获取状态描述
47
+ */
48
+ getStatusDescription(status: TaskStatus): string;
49
+ /**
50
+ * 获取事件描述
51
+ */
52
+ getEventDescription(event: TransitionEvent): string;
53
+ }
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StateMachine = void 0;
4
+ // 定义允许的状态转换
5
+ const TRANSITIONS = [
6
+ // pending → scheduled
7
+ { from: 'pending', to: 'scheduled', event: 'schedule' },
8
+ // scheduled → in_progress
9
+ { from: 'scheduled', to: 'in_progress', event: 'start' },
10
+ // in_progress → verify
11
+ { from: 'in_progress', to: 'verify', event: 'develop_done' },
12
+ // verify → accept
13
+ { from: 'verify', to: 'accept', event: 'verify_done' },
14
+ // accept → completed
15
+ { from: 'accept', to: 'completed', event: 'accept_done' },
16
+ // in_progress → blocked
17
+ { from: 'in_progress', to: 'blocked', event: 'block' },
18
+ // blocked → waiting (等待 Meeting)
19
+ { from: 'blocked', to: 'waiting', event: 'wait' },
20
+ // waiting → in_progress (Meeting 解决后)
21
+ { from: 'waiting', to: 'in_progress', event: 'resume' },
22
+ // any → failed
23
+ { from: 'in_progress', to: 'failed', event: 'fail' },
24
+ { from: 'verify', to: 'failed', event: 'fail' },
25
+ { from: 'accept', to: 'failed', event: 'fail' },
26
+ // failed → retry_queue
27
+ { from: 'failed', to: 'retry_queue', event: 'retry' },
28
+ // retry_queue → pending
29
+ { from: 'retry_queue', to: 'pending', event: 'retry' },
30
+ // any → pending (cancel and restart)
31
+ { from: 'scheduled', to: 'pending', event: 'cancel' },
32
+ { from: 'blocked', to: 'pending', event: 'cancel' },
33
+ ];
34
+ class StateMachine {
35
+ /**
36
+ * 尝试转换状态
37
+ */
38
+ transition(task, event) {
39
+ const fromStatus = task.status;
40
+ // 查找允许的转换
41
+ const allowedTransition = TRANSITIONS.find(t => t.from === fromStatus && t.event === event);
42
+ if (!allowedTransition) {
43
+ return {
44
+ success: false,
45
+ fromStatus,
46
+ toStatus: fromStatus,
47
+ event,
48
+ error: `不允许的转换: ${fromStatus} --[${event}]--> ?`
49
+ };
50
+ }
51
+ // 检查条件
52
+ if (allowedTransition.condition && !allowedTransition.condition(task)) {
53
+ return {
54
+ success: false,
55
+ fromStatus,
56
+ toStatus: fromStatus,
57
+ event,
58
+ error: '转换条件不满足'
59
+ };
60
+ }
61
+ return {
62
+ success: true,
63
+ fromStatus,
64
+ toStatus: allowedTransition.to,
65
+ event
66
+ };
67
+ }
68
+ /**
69
+ * 获取当前状态允许的转换
70
+ */
71
+ getAllowedTransitions(status) {
72
+ return TRANSITIONS
73
+ .filter(t => t.from === status)
74
+ .map(t => ({ event: t.event, toStatus: t.to }));
75
+ }
76
+ /**
77
+ * 检查是否可以执行指定事件
78
+ */
79
+ canTransition(task, event) {
80
+ const result = this.transition(task, event);
81
+ return result.success;
82
+ }
83
+ /**
84
+ * 获取状态描述
85
+ */
86
+ getStatusDescription(status) {
87
+ const descriptions = {
88
+ 'pending': '等待执行',
89
+ 'scheduled': '已调度,等待 Agent',
90
+ 'in_progress': '执行中',
91
+ 'blocked': '被阻塞',
92
+ 'waiting': '等待确认/Meeting',
93
+ 'verify': '验证中',
94
+ 'accept': '验收中',
95
+ 'completed': '已完成',
96
+ 'failed': '失败',
97
+ 'retry_queue': '重试队列'
98
+ };
99
+ return descriptions[status] || status;
100
+ }
101
+ /**
102
+ * 获取事件描述
103
+ */
104
+ getEventDescription(event) {
105
+ const descriptions = {
106
+ 'schedule': '调度任务',
107
+ 'start': '开始执行',
108
+ 'develop_done': '开发完成',
109
+ 'verify_done': '验证完成',
110
+ 'accept_done': '验收完成',
111
+ 'need_verify': '需要验证',
112
+ 'need_accept': '需要验收',
113
+ 'block': '阻塞任务',
114
+ 'unblock': '解除阻塞',
115
+ 'wait': '等待外部',
116
+ 'resume': '恢复执行',
117
+ 'fail': '标记失败',
118
+ 'retry': '重试任务',
119
+ 'cancel': '取消任务'
120
+ };
121
+ return descriptions[event] || event;
122
+ }
123
+ }
124
+ exports.StateMachine = StateMachine;
@@ -0,0 +1,7 @@
1
+ import type { ParsedTask } from '../types/index.js';
2
+ export declare class TaskParser {
3
+ parse(content: string): ParsedTask;
4
+ private extractTitle;
5
+ private extractDescription;
6
+ private extractSection;
7
+ }