oneie 1.2.1 → 1.2.3

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,717 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Task Orchestration System
5
+ * Manages tasks within stories and coordinates agent assignments
6
+ */
7
+
8
+ import fs from 'fs-extra';
9
+ import path from 'path';
10
+ import yaml from 'js-yaml';
11
+ import chalk from 'chalk';
12
+ import inquirer from 'inquirer';
13
+
14
+ export class TaskSystem {
15
+ constructor(projectPath = process.cwd()) {
16
+ this.projectPath = projectPath;
17
+ this.oneDir = path.join(projectPath, '.one');
18
+ this.missionsDir = path.join(this.oneDir, 'missions');
19
+ this.agentsDir = path.join(projectPath, '.claude', 'agents');
20
+
21
+ // Agent registry from your existing system
22
+ this.agents = {
23
+ // Command structure agents
24
+ 'Mission Commander': { file: 'mission-commander.md', specialty: 'strategic planning, mission creation' },
25
+ 'Story Teller': { file: 'story-teller.md', specialty: 'story creation, narrative development' },
26
+ 'Task Master': { file: 'task-master.md', specialty: 'task execution, agent coordination' },
27
+
28
+ // Engineering team
29
+ 'Engineering Director': { file: 'engineering-director.md', specialty: 'technical leadership, architecture' },
30
+ 'Engineering Architect': { file: 'engineering-architect.md', specialty: 'system design, technical architecture' },
31
+ 'Engineering Developer': { file: 'engineering-developer.md', specialty: 'implementation, coding' },
32
+ 'Engineering Quality Assurance': { file: 'engineering-quality-assurance.md', specialty: 'testing, validation' },
33
+ 'Engineering Product Manager': { file: 'engineering-product-manager.md', specialty: 'product management, requirements' },
34
+ 'Engineering User Experience': { file: 'engineering-user-experience.md', specialty: 'UX design, user interface' },
35
+
36
+ // Marketing team
37
+ 'Marketing Director': { file: 'marketing-director.md', specialty: 'marketing strategy, campaigns' },
38
+ 'Marketing Viral Growth': { file: 'marketing-viral-growth.md', specialty: 'viral marketing, growth hacking' },
39
+ 'Marketing Brand Identity': { file: 'marketing-brand-identity.md', specialty: 'branding, identity design' },
40
+ 'Marketing Content Hooks': { file: 'marketing-content-hooks.md', specialty: 'content strategy, engagement' },
41
+ 'Marketing Lead Capture': { file: 'marketing-lead-capture.md', specialty: 'lead generation, conversion' },
42
+
43
+ // Content team
44
+ 'Content Team Manager': { file: 'content-team-manager.md', specialty: 'content management, strategy' },
45
+ 'Content Calendar Planner': { file: 'content-calendar-planner.md', specialty: 'content planning, scheduling' },
46
+ 'Content Playbook Writer': { file: 'content-playbook-writer.md', specialty: 'playbook creation, documentation' },
47
+
48
+ // Research team
49
+ 'Research Team Manager': { file: 'research-team-manager.md', specialty: 'research coordination, analysis' },
50
+ 'Research Foundation Analyst': { file: 'research-foundation-analyst.md', specialty: 'foundation research, market analysis' },
51
+ 'Research Market Analyst': { file: 'research-market-analyst.md', specialty: 'market research, competitive analysis' },
52
+
53
+ // Service team
54
+ 'Service Team Manager': { file: 'service-team-manager.md', specialty: 'customer service, success management' },
55
+ 'Service Success Manager': { file: 'service-success-manager.md', specialty: 'customer success, retention' },
56
+ 'Service Advocacy Manager': { file: 'service-advocacy-manager.md', specialty: 'customer advocacy, support' },
57
+
58
+ // Crypto team
59
+ 'Crypto Team Manager': { file: 'crypto-team-manager.md', specialty: 'crypto strategy, blockchain' },
60
+ 'Crypto Token Analyst': { file: 'crypto-token-analyst.md', specialty: 'token analysis, crypto markets' },
61
+ 'Crypto Market Researcher': { file: 'crypto-market-researcher.md', specialty: 'crypto market research' }
62
+ };
63
+ }
64
+
65
+ async createTask(storyId, taskName, options = {}) {
66
+ console.log(chalk.blue('\\nšŸ“‹ Creating new task...'));
67
+
68
+ // Step 1: Get story and validate it exists
69
+ const { story, missionId } = await this.getStoryWithMission(storyId);
70
+ if (!story) {
71
+ throw new Error(`Story not found: ${storyId}`);
72
+ }
73
+
74
+ // Step 2: Generate task template with AI suggestions
75
+ const taskTemplate = await this.generateTaskTemplate(taskName, story, options);
76
+
77
+ // Step 3: Human-AI collaboration on task design
78
+ const task = await this.collaborativelyDesignTask(taskTemplate, options);
79
+
80
+ // Step 4: Create task file and assign to story
81
+ await this.initializeTask(missionId, storyId, task);
82
+
83
+ console.log(chalk.green(`\\nāœ… Task "${task.name}" created successfully!`));
84
+ console.log(chalk.cyan(`šŸ“‹ Task ID: ${task.id}`));
85
+ console.log(chalk.cyan(`šŸ¤– Assigned agents: ${task.agents.join(', ')}`));
86
+
87
+ return task;
88
+ }
89
+
90
+ async generateTaskTemplate(taskName, story, options = {}) {
91
+ console.log(chalk.gray('🧠 Generating task template...'));
92
+
93
+ const template = {
94
+ name: taskName,
95
+ id: this.generateTaskId(taskName),
96
+ storyId: story.id,
97
+ description: `Task: ${taskName}`,
98
+ suggestedAgents: this.suggestTaskAgents(taskName, story),
99
+ estimatedDuration: this.estimateTaskDuration(taskName, story),
100
+ priority: this.assessTaskPriority(taskName, story),
101
+ dependencies: this.identifyTaskDependencies(taskName, story),
102
+ acceptanceCriteria: this.generateAcceptanceCriteria(taskName, story),
103
+ techContext: this.extractTechContext(taskName, story)
104
+ };
105
+
106
+ return template;
107
+ }
108
+
109
+ generateTaskId(taskName) {
110
+ const hash = this.hashString(taskName).substring(0, 8);
111
+ return `task-${hash}`;
112
+ }
113
+
114
+ hashString(str) {
115
+ let hash = 0;
116
+ for (let i = 0; i < str.length; i++) {
117
+ const char = str.charCodeAt(i);
118
+ hash = ((hash << 5) - hash) + char;
119
+ hash = hash & hash;
120
+ }
121
+ return Math.abs(hash).toString(16);
122
+ }
123
+
124
+ suggestTaskAgents(taskName, story) {
125
+ const agents = new Set();
126
+ const taskLower = taskName.toLowerCase();
127
+ const storyObjective = story.objective?.toLowerCase() || '';
128
+
129
+ // Always include Task Master for coordination
130
+ agents.add('Task Master');
131
+
132
+ // Technical implementation tasks
133
+ if (taskLower.includes('implement') || taskLower.includes('code') || taskLower.includes('develop')) {
134
+ agents.add('Engineering Developer');
135
+ agents.add('Engineering Director');
136
+ }
137
+
138
+ // Architecture and design tasks
139
+ if (taskLower.includes('design') || taskLower.includes('architecture') || taskLower.includes('structure')) {
140
+ agents.add('Engineering Architect');
141
+ if (taskLower.includes('ui') || taskLower.includes('user')) {
142
+ agents.add('Engineering User Experience');
143
+ }
144
+ }
145
+
146
+ // Testing and quality tasks
147
+ if (taskLower.includes('test') || taskLower.includes('quality') || taskLower.includes('validation')) {
148
+ agents.add('Engineering Quality Assurance');
149
+ }
150
+
151
+ // Marketing and content tasks
152
+ if (taskLower.includes('marketing') || taskLower.includes('campaign') || taskLower.includes('growth')) {
153
+ agents.add('Marketing Director');
154
+ if (taskLower.includes('viral') || taskLower.includes('growth')) {
155
+ agents.add('Marketing Viral Growth');
156
+ }
157
+ if (taskLower.includes('brand') || taskLower.includes('identity')) {
158
+ agents.add('Marketing Brand Identity');
159
+ }
160
+ }
161
+
162
+ // Content creation tasks
163
+ if (taskLower.includes('content') || taskLower.includes('write') || taskLower.includes('documentation')) {
164
+ agents.add('Content Team Manager');
165
+ if (taskLower.includes('playbook') || taskLower.includes('guide')) {
166
+ agents.add('Content Playbook Writer');
167
+ }
168
+ }
169
+
170
+ // Research tasks
171
+ if (taskLower.includes('research') || taskLower.includes('analysis') || taskLower.includes('investigate')) {
172
+ agents.add('Research Team Manager');
173
+ if (taskLower.includes('market') || taskLower.includes('competitive')) {
174
+ agents.add('Research Market Analyst');
175
+ }
176
+ }
177
+
178
+ // Crypto tasks
179
+ if (taskLower.includes('crypto') || taskLower.includes('token') || taskLower.includes('blockchain')) {
180
+ agents.add('Crypto Team Manager');
181
+ if (taskLower.includes('token') || taskLower.includes('analysis')) {
182
+ agents.add('Crypto Token Analyst');
183
+ }
184
+ }
185
+
186
+ // Service tasks
187
+ if (taskLower.includes('service') || taskLower.includes('customer') || taskLower.includes('support')) {
188
+ agents.add('Service Team Manager');
189
+ if (taskLower.includes('success') || taskLower.includes('retention')) {
190
+ agents.add('Service Success Manager');
191
+ }
192
+ }
193
+
194
+ // Include story agents that are relevant
195
+ const relevantStoryAgents = story.agents?.filter(agent => {
196
+ const agentLower = agent.toLowerCase();
197
+
198
+ // Match agent specialty to task type
199
+ if (taskLower.includes('implement') && agentLower.includes('developer')) return true;
200
+ if (taskLower.includes('design') && agentLower.includes('architect')) return true;
201
+ if (taskLower.includes('test') && agentLower.includes('quality')) return true;
202
+ if (taskLower.includes('marketing') && agentLower.includes('marketing')) return true;
203
+
204
+ return false;
205
+ }) || [];
206
+
207
+ relevantStoryAgents.forEach(agent => agents.add(agent));
208
+
209
+ // Ensure minimum agent assignment
210
+ if (agents.size < 2) {
211
+ agents.add('Engineering Director');
212
+ agents.add('Story Teller');
213
+ }
214
+
215
+ return Array.from(agents);
216
+ }
217
+
218
+ estimateTaskDuration(taskName, story) {
219
+ let baseHours = 4; // Default task duration
220
+
221
+ const taskLower = taskName.toLowerCase();
222
+ const complexityKeywords = ['complex', 'integration', 'architecture', 'migration', 'refactor'];
223
+ const simpleKeywords = ['fix', 'update', 'small', 'minor', 'simple', 'quick'];
224
+
225
+ // Adjust based on task complexity
226
+ if (complexityKeywords.some(keyword => taskLower.includes(keyword))) {
227
+ baseHours *= 2;
228
+ } else if (simpleKeywords.some(keyword => taskLower.includes(keyword))) {
229
+ baseHours /= 2;
230
+ }
231
+
232
+ // Adjust based on task type
233
+ if (taskLower.includes('research') || taskLower.includes('analysis')) {
234
+ baseHours += 2;
235
+ }
236
+
237
+ if (taskLower.includes('implement') || taskLower.includes('develop')) {
238
+ baseHours += 4;
239
+ }
240
+
241
+ baseHours = Math.max(1, baseHours); // Minimum 1 hour
242
+
243
+ if (baseHours <= 4) {
244
+ return `${baseHours} hours`;
245
+ } else if (baseHours <= 8) {
246
+ return `${Math.ceil(baseHours)} hours (1 day)`;
247
+ } else {
248
+ return `${Math.ceil(baseHours/8)} days`;
249
+ }
250
+ }
251
+
252
+ assessTaskPriority(taskName, story) {
253
+ const taskLower = taskName.toLowerCase();
254
+
255
+ // Inherit story priority as baseline
256
+ let basePriority = story.priority || 'medium';
257
+
258
+ // High priority indicators
259
+ const highPriorityKeywords = ['critical', 'urgent', 'blocker', 'security', 'bug', 'fix', 'error'];
260
+ if (highPriorityKeywords.some(keyword => taskLower.includes(keyword))) {
261
+ return 'high';
262
+ }
263
+
264
+ // Low priority indicators
265
+ const lowPriorityKeywords = ['nice-to-have', 'enhancement', 'optional', 'future', 'cleanup'];
266
+ if (lowPriorityKeywords.some(keyword => taskLower.includes(keyword))) {
267
+ return 'low';
268
+ }
269
+
270
+ return basePriority;
271
+ }
272
+
273
+ identifyTaskDependencies(taskName, story) {
274
+ const dependencies = [];
275
+ const taskLower = taskName.toLowerCase();
276
+
277
+ // Common dependency patterns
278
+ if (taskLower.includes('test') && !taskLower.includes('plan')) {
279
+ dependencies.push('Implementation completed');
280
+ }
281
+
282
+ if (taskLower.includes('deploy') || taskLower.includes('release')) {
283
+ dependencies.push('Testing completed');
284
+ dependencies.push('Code review approved');
285
+ }
286
+
287
+ if (taskLower.includes('integration')) {
288
+ dependencies.push('Individual components completed');
289
+ }
290
+
291
+ return dependencies;
292
+ }
293
+
294
+ generateAcceptanceCriteria(taskName, story) {
295
+ const criteria = [];
296
+ const taskLower = taskName.toLowerCase();
297
+
298
+ // Common acceptance criteria patterns
299
+ if (taskLower.includes('implement') || taskLower.includes('develop')) {
300
+ criteria.push('Code is implemented according to specifications');
301
+ criteria.push('Code passes all existing tests');
302
+ criteria.push('Code follows project coding standards');
303
+ criteria.push('Implementation is documented');
304
+ }
305
+
306
+ if (taskLower.includes('test')) {
307
+ criteria.push('Test cases cover all requirements');
308
+ criteria.push('All tests pass successfully');
309
+ criteria.push('Test coverage meets project standards');
310
+ }
311
+
312
+ if (taskLower.includes('design')) {
313
+ criteria.push('Design meets user requirements');
314
+ criteria.push('Design is reviewed and approved');
315
+ criteria.push('Design specifications are documented');
316
+ }
317
+
318
+ if (taskLower.includes('research')) {
319
+ criteria.push('Research findings are documented');
320
+ criteria.push('Recommendations are provided');
321
+ criteria.push('Results are peer-reviewed');
322
+ }
323
+
324
+ // Default criteria if none match
325
+ if (criteria.length === 0) {
326
+ criteria.push('Task objectives are met');
327
+ criteria.push('Deliverables are completed');
328
+ criteria.push('Quality standards are maintained');
329
+ }
330
+
331
+ return criteria;
332
+ }
333
+
334
+ extractTechContext(taskName, story) {
335
+ // Get mission context to understand tech stack
336
+ const context = {
337
+ frameworks: [],
338
+ languages: [],
339
+ tools: [],
340
+ patterns: []
341
+ };
342
+
343
+ const taskLower = taskName.toLowerCase();
344
+
345
+ // Common framework patterns
346
+ if (taskLower.includes('react') || story.objective?.includes('React')) {
347
+ context.frameworks.push('React');
348
+ context.languages.push('JavaScript');
349
+ }
350
+
351
+ if (taskLower.includes('node') || taskLower.includes('express')) {
352
+ context.frameworks.push('Node.js');
353
+ context.languages.push('JavaScript');
354
+ }
355
+
356
+ if (taskLower.includes('api') || taskLower.includes('endpoint')) {
357
+ context.patterns.push('REST API');
358
+ }
359
+
360
+ if (taskLower.includes('database') || taskLower.includes('data')) {
361
+ context.patterns.push('Database Integration');
362
+ }
363
+
364
+ return context;
365
+ }
366
+
367
+ async collaborativelyDesignTask(template, options) {
368
+ console.log(chalk.blue('\\nšŸ¤ Collaborative task design...'));
369
+
370
+ // Show AI analysis
371
+ console.log(chalk.cyan('\\nšŸ¤– AI Analysis:'));
372
+ console.log(` Task: ${template.name}`);
373
+ console.log(` Estimated duration: ${template.estimatedDuration}`);
374
+ console.log(` Priority: ${template.priority}`);
375
+ console.log(` Suggested agents: ${template.suggestedAgents.join(', ')}`);
376
+ console.log(` Dependencies: ${template.dependencies.join(', ') || 'None'}`);
377
+
378
+ if (options.interactive !== false) {
379
+ // Get human input
380
+ const answers = await inquirer.prompt([
381
+ {
382
+ type: 'input',
383
+ name: 'name',
384
+ message: 'Task name:',
385
+ default: template.name
386
+ },
387
+ {
388
+ type: 'editor',
389
+ name: 'description',
390
+ message: 'Task description:',
391
+ default: `# ${template.name}\\n\\n[Describe what this task will accomplish and how it contributes to the story]`
392
+ },
393
+ {
394
+ type: 'checkbox',
395
+ name: 'agents',
396
+ message: 'Select agents for this task:',
397
+ choices: template.suggestedAgents,
398
+ default: template.suggestedAgents.slice(0, 3)
399
+ },
400
+ {
401
+ type: 'list',
402
+ name: 'priority',
403
+ message: 'Task priority:',
404
+ choices: ['high', 'medium', 'low'],
405
+ default: template.priority
406
+ },
407
+ {
408
+ type: 'input',
409
+ name: 'duration',
410
+ message: 'Expected duration:',
411
+ default: template.estimatedDuration
412
+ }
413
+ ]);
414
+
415
+ // Merge human input with AI suggestions
416
+ Object.assign(template, answers);
417
+ template.acceptanceCriteria = template.acceptanceCriteria; // Keep AI suggestions
418
+ } else {
419
+ // Non-interactive mode
420
+ template.agents = template.suggestedAgents.slice(0, 3);
421
+ template.duration = template.estimatedDuration;
422
+ template.description = `# ${template.name}\\n\\nAI-generated task: ${template.name.toLowerCase()}.`;
423
+ }
424
+
425
+ console.log(chalk.green('āœ… Task design complete'));
426
+ return template;
427
+ }
428
+
429
+ async initializeTask(missionId, storyId, task) {
430
+ console.log(chalk.gray('šŸ“ Creating task structure...'));
431
+
432
+ const storyDir = path.join(this.missionsDir, missionId, 'stories');
433
+ const tasksDir = path.join(storyDir, 'tasks');
434
+
435
+ // Ensure tasks directory exists
436
+ await fs.ensureDir(tasksDir);
437
+
438
+ // Create task data
439
+ const taskData = {
440
+ name: task.name,
441
+ id: task.id,
442
+ storyId: storyId,
443
+ missionId: missionId,
444
+ description: task.description,
445
+ status: 'pending',
446
+ priority: task.priority,
447
+ created: new Date().toISOString(),
448
+ agents: task.agents,
449
+ duration: task.duration,
450
+ dependencies: task.dependencies,
451
+ acceptanceCriteria: task.acceptanceCriteria,
452
+ techContext: task.techContext,
453
+ progress: {
454
+ started: null,
455
+ completed: null,
456
+ notes: []
457
+ }
458
+ };
459
+
460
+ // Save task file
461
+ await fs.writeFile(
462
+ path.join(tasksDir, `${task.id}.yaml`),
463
+ yaml.dump(taskData, { indent: 2 })
464
+ );
465
+
466
+ // Update story with new task
467
+ await this.addTaskToStory(missionId, storyId, task.id, task.name);
468
+
469
+ // Create task README
470
+ const readmeContent = `# ${task.name}
471
+
472
+ ${task.description || `Task: ${task.name}`}
473
+
474
+ ## Acceptance Criteria
475
+ ${task.acceptanceCriteria.map(criteria => `- [ ] ${criteria}`).join('\\n')}
476
+
477
+ ## Agents
478
+ ${task.agents.map(agent => `- ${agent}`).join('\\n')}
479
+
480
+ ## Details
481
+ - Priority: ${task.priority}
482
+ - Duration: ${task.duration}
483
+ - Status: ${taskData.status}
484
+ - Created: ${taskData.created}
485
+
486
+ ## Dependencies
487
+ ${task.dependencies.length > 0 ? task.dependencies.map(dep => `- ${dep}`).join('\\n') : 'None'}
488
+
489
+ ## Tech Context
490
+ - Frameworks: ${task.techContext.frameworks.join(', ') || 'None'}
491
+ - Languages: ${task.techContext.languages.join(', ') || 'None'}
492
+ - Patterns: ${task.techContext.patterns.join(', ') || 'None'}
493
+
494
+ ## Progress Notes
495
+ _Task progress and notes will be tracked here_
496
+ `;
497
+
498
+ await fs.writeFile(path.join(tasksDir, `${task.id}.md`), readmeContent);
499
+
500
+ return taskData;
501
+ }
502
+
503
+ async addTaskToStory(missionId, storyId, taskId, taskName) {
504
+ const storyPath = path.join(this.missionsDir, missionId, 'stories', `${storyId}.yaml`);
505
+
506
+ if (await fs.pathExists(storyPath)) {
507
+ const story = yaml.load(await fs.readFile(storyPath, 'utf8'));
508
+
509
+ // Add task to story if not already there
510
+ const taskExists = story.tasks.some(task =>
511
+ (typeof task === 'string' && task === taskName) ||
512
+ (typeof task === 'object' && (task.id === taskId || task.name === taskName))
513
+ );
514
+
515
+ if (!taskExists) {
516
+ story.tasks.push({
517
+ name: taskName,
518
+ id: taskId,
519
+ status: 'pending',
520
+ created: new Date().toISOString()
521
+ });
522
+
523
+ await fs.writeFile(storyPath, yaml.dump(story, { indent: 2 }));
524
+ }
525
+ }
526
+ }
527
+
528
+ async listTasks(storyId = null, missionId = null) {
529
+ const tasks = [];
530
+
531
+ if (storyId && missionId) {
532
+ // List tasks for specific story
533
+ const tasksDir = path.join(this.missionsDir, missionId, 'stories', 'tasks');
534
+
535
+ if (await fs.pathExists(tasksDir)) {
536
+ const taskFiles = await fs.readdir(tasksDir);
537
+
538
+ for (const file of taskFiles) {
539
+ if (file.endsWith('.yaml')) {
540
+ const taskPath = path.join(tasksDir, file);
541
+ const taskData = yaml.load(await fs.readFile(taskPath, 'utf8'));
542
+ if (taskData.storyId === storyId) {
543
+ tasks.push(taskData);
544
+ }
545
+ }
546
+ }
547
+ }
548
+ } else {
549
+ // List all tasks across all missions/stories
550
+ if (await fs.pathExists(this.missionsDir)) {
551
+ const missionDirs = await fs.readdir(this.missionsDir);
552
+
553
+ for (const missionDir of missionDirs) {
554
+ const storiesDir = path.join(this.missionsDir, missionDir, 'stories');
555
+
556
+ if (await fs.pathExists(storiesDir)) {
557
+ const storyItems = await fs.readdir(storiesDir);
558
+
559
+ for (const item of storyItems) {
560
+ if (item === 'tasks') {
561
+ const tasksDir = path.join(storiesDir, 'tasks');
562
+ const taskFiles = await fs.readdir(tasksDir);
563
+
564
+ for (const file of taskFiles) {
565
+ if (file.endsWith('.yaml')) {
566
+ const taskPath = path.join(tasksDir, file);
567
+ const taskData = yaml.load(await fs.readFile(taskPath, 'utf8'));
568
+ tasks.push(taskData);
569
+ }
570
+ }
571
+ }
572
+ }
573
+ }
574
+ }
575
+ }
576
+ }
577
+
578
+ return tasks.sort((a, b) => new Date(b.created) - new Date(a.created));
579
+ }
580
+
581
+ async getTask(taskId, storyId = null, missionId = null) {
582
+ if (storyId && missionId) {
583
+ // Look in specific story
584
+ const taskPath = path.join(this.missionsDir, missionId, 'stories', 'tasks', `${taskId}.yaml`);
585
+ if (await fs.pathExists(taskPath)) {
586
+ return yaml.load(await fs.readFile(taskPath, 'utf8'));
587
+ }
588
+ } else {
589
+ // Search across all tasks
590
+ const tasks = await this.listTasks();
591
+ return tasks.find(task => task.id === taskId);
592
+ }
593
+
594
+ return null;
595
+ }
596
+
597
+ async updateTaskStatus(taskId, status, notes = null) {
598
+ const task = await this.getTask(taskId);
599
+ if (!task) {
600
+ throw new Error(`Task not found: ${taskId}`);
601
+ }
602
+
603
+ task.status = status;
604
+ task.updated = new Date().toISOString();
605
+
606
+ // Update progress tracking
607
+ if (status === 'active' && !task.progress.started) {
608
+ task.progress.started = new Date().toISOString();
609
+ } else if (status === 'completed') {
610
+ task.progress.completed = new Date().toISOString();
611
+ }
612
+
613
+ if (notes) {
614
+ task.progress.notes.push({
615
+ timestamp: new Date().toISOString(),
616
+ note: notes
617
+ });
618
+ }
619
+
620
+ // Find and update the task file
621
+ const taskPath = await this.findTaskPath(taskId);
622
+
623
+ if (taskPath && await fs.pathExists(taskPath)) {
624
+ await fs.writeFile(taskPath, yaml.dump(task, { indent: 2 }));
625
+ return task;
626
+ }
627
+
628
+ throw new Error(`Could not update task file: ${taskId}`);
629
+ }
630
+
631
+ async findTaskPath(taskId) {
632
+ const tasks = await this.listTasks();
633
+ const task = tasks.find(t => t.id === taskId);
634
+ if (task) {
635
+ return path.join(this.missionsDir, task.missionId, 'stories', 'tasks', `${taskId}.yaml`);
636
+ }
637
+ return null;
638
+ }
639
+
640
+ async assignTaskToAgent(taskId, agentName) {
641
+ const task = await this.getTask(taskId);
642
+ if (!task) {
643
+ throw new Error(`Task not found: ${taskId}`);
644
+ }
645
+
646
+ if (!this.agents[agentName]) {
647
+ throw new Error(`Agent not found: ${agentName}`);
648
+ }
649
+
650
+ // Add agent if not already assigned
651
+ if (!task.agents.includes(agentName)) {
652
+ task.agents.push(agentName);
653
+ task.updated = new Date().toISOString();
654
+
655
+ task.progress.notes.push({
656
+ timestamp: new Date().toISOString(),
657
+ note: `Agent assigned: ${agentName}`
658
+ });
659
+
660
+ // Update task file
661
+ const taskPath = await this.findTaskPath(taskId);
662
+ if (taskPath) {
663
+ await fs.writeFile(taskPath, yaml.dump(task, { indent: 2 }));
664
+ }
665
+ }
666
+
667
+ return task;
668
+ }
669
+
670
+ async getStoryWithMission(storyId) {
671
+ // Search across all missions to find the story and its mission
672
+ if (await fs.pathExists(this.missionsDir)) {
673
+ const missionDirs = await fs.readdir(this.missionsDir);
674
+
675
+ for (const missionDir of missionDirs) {
676
+ const storiesDir = path.join(this.missionsDir, missionDir, 'stories');
677
+
678
+ if (await fs.pathExists(storiesDir)) {
679
+ const storyPath = path.join(storiesDir, `${storyId}.yaml`);
680
+
681
+ if (await fs.pathExists(storyPath)) {
682
+ const story = yaml.load(await fs.readFile(storyPath, 'utf8'));
683
+ return { story, missionId: missionDir };
684
+ }
685
+ }
686
+ }
687
+ }
688
+
689
+ return { story: null, missionId: null };
690
+ }
691
+ }
692
+
693
+ // CLI interface functions
694
+ export async function createTask(storyId, taskName, options = {}) {
695
+ const taskSystem = new TaskSystem();
696
+ return await taskSystem.createTask(storyId, taskName, options);
697
+ }
698
+
699
+ export async function listTasks(storyId = null, missionId = null) {
700
+ const taskSystem = new TaskSystem();
701
+ return await taskSystem.listTasks(storyId, missionId);
702
+ }
703
+
704
+ export async function getTask(taskId, storyId = null, missionId = null) {
705
+ const taskSystem = new TaskSystem();
706
+ return await taskSystem.getTask(taskId, storyId, missionId);
707
+ }
708
+
709
+ export async function updateTaskStatus(taskId, status, notes = null) {
710
+ const taskSystem = new TaskSystem();
711
+ return await taskSystem.updateTaskStatus(taskId, status, notes);
712
+ }
713
+
714
+ export async function assignTaskToAgent(taskId, agentName) {
715
+ const taskSystem = new TaskSystem();
716
+ return await taskSystem.assignTaskToAgent(taskId, agentName);
717
+ }