/ examples / js / planning / task-planning.ts
task-planning.ts
 1  /**
 2   * Planning System Example
 3   * Demonstrates plans, steps, and todo lists
 4   */
 5  
 6  import { Plan, PlanStep, TodoList, TodoItem, PlanStorage, createPlan, createTodoList } from 'praisonai';
 7  
 8  async function main() {
 9    // Create a project plan
10    console.log('=== Project Plan ===');
11    const plan = createPlan({ 
12      name: 'Build AI Agent',
13      description: 'Create a fully functional AI agent'
14    });
15  
16    plan.addStep(new PlanStep({ description: 'Design agent architecture' }));
17    plan.addStep(new PlanStep({ description: 'Implement core functionality' }));
18    plan.addStep(new PlanStep({ description: 'Add tool support' }));
19    plan.addStep(new PlanStep({ description: 'Write tests' }));
20    plan.addStep(new PlanStep({ description: 'Deploy to production' }));
21  
22    console.log('Plan:', plan.name);
23    console.log('Steps:', plan.steps.length);
24  
25    // Execute steps
26    plan.start();
27    plan.steps[0].start();
28    plan.steps[0].complete();
29    plan.steps[1].start();
30    plan.steps[1].complete();
31  
32    const progress = plan.getProgress();
33    console.log(`Progress: ${progress.completed}/${progress.total} (${progress.percentage}%)`);
34  
35    // Create todo list
36    console.log('\n=== Todo List ===');
37    const todos = createTodoList('Sprint Tasks');
38  
39    todos.add(new TodoItem({ content: 'Review PR #123', priority: 'high' }));
40    todos.add(new TodoItem({ content: 'Fix bug in router', priority: 'high' }));
41    todos.add(new TodoItem({ content: 'Update documentation', priority: 'medium' }));
42    todos.add(new TodoItem({ content: 'Refactor tests', priority: 'low' }));
43  
44    console.log('Total items:', todos.items.length);
45    console.log('High priority:', todos.getByPriority('high').length);
46  
47    // Complete some items
48    todos.items[0].complete();
49    todos.items[1].start();
50  
51    console.log('Pending:', todos.getPending().length);
52    console.log('Completed:', todos.getCompleted().length);
53  
54    const todoProgress = todos.getProgress();
55    console.log(`Progress: ${todoProgress.completed}/${todoProgress.total} (${todoProgress.percentage}%)`);
56  
57    // Use storage
58    console.log('\n=== Plan Storage ===');
59    const storage = new PlanStorage();
60    storage.savePlan(plan);
61    storage.saveTodoList(todos);
62  
63    console.log('Saved plans:', storage.listPlans().length);
64    console.log('Saved todo lists:', storage.listTodoLists().length);
65  
66    // Retrieve
67    const retrieved = storage.getPlan(plan.id);
68    console.log('Retrieved plan:', retrieved?.name);
69  }
70  
71  main().catch(console.error);