opencode-orchestrator 1.0.76 → 1.2.1

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 (118) hide show
  1. package/README.md +46 -47
  2. package/dist/agents/prompts/01_philosophy/execution_assurance.d.ts +1 -0
  3. package/dist/agents/prompts/01_philosophy/index.d.ts +5 -0
  4. package/dist/agents/prompts/01_philosophy/metadata.d.ts +19 -0
  5. package/dist/agents/prompts/02_discovery/agents/discovery_commander.d.ts +5 -0
  6. package/dist/agents/prompts/02_discovery/agents/discovery_planner.d.ts +5 -0
  7. package/dist/agents/prompts/02_discovery/agents/index.d.ts +2 -0
  8. package/dist/agents/prompts/02_discovery/discovery_core.d.ts +8 -0
  9. package/dist/agents/prompts/02_discovery/index.d.ts +6 -0
  10. package/dist/agents/prompts/03_planning/agents/index.d.ts +3 -0
  11. package/dist/agents/prompts/03_planning/agents/planning_commander.d.ts +5 -0
  12. package/dist/agents/prompts/03_planning/index.d.ts +11 -0
  13. package/dist/agents/prompts/03_planning/planning_core.d.ts +8 -0
  14. package/dist/agents/prompts/04_execution/agents/execution_commander.d.ts +5 -0
  15. package/dist/agents/prompts/04_execution/agents/execution_worker.d.ts +5 -0
  16. package/dist/agents/prompts/04_execution/agents/index.d.ts +2 -0
  17. package/dist/agents/prompts/04_execution/execution_core.d.ts +8 -0
  18. package/dist/agents/prompts/04_execution/execution_error_handling.d.ts +5 -0
  19. package/dist/agents/prompts/04_execution/index.d.ts +12 -0
  20. package/dist/agents/prompts/05_verification/agents/index.d.ts +2 -0
  21. package/dist/agents/prompts/05_verification/agents/verification_commander.d.ts +5 -0
  22. package/dist/agents/prompts/05_verification/index.d.ts +11 -0
  23. package/dist/agents/prompts/05_verification/verification_build.d.ts +5 -0
  24. package/dist/agents/prompts/05_verification/verification_core.d.ts +8 -0
  25. package/dist/agents/prompts/05_verification/verification_test.d.ts +5 -0
  26. package/dist/agents/prompts/06_mission/agents/index.d.ts +1 -0
  27. package/dist/agents/prompts/06_mission/agents/mission_commander.d.ts +5 -0
  28. package/dist/agents/prompts/06_mission/index.d.ts +7 -0
  29. package/dist/agents/prompts/06_mission/mission_core.d.ts +8 -0
  30. package/dist/agents/prompts/06_mission/mission_lifecycle.d.ts +5 -0
  31. package/dist/agents/prompts/07_agents/commander/commander_mandate.d.ts +5 -0
  32. package/dist/agents/prompts/07_agents/commander/index.d.ts +5 -0
  33. package/dist/agents/prompts/07_agents/planner/index.d.ts +4 -0
  34. package/dist/agents/prompts/07_agents/planner/planner_mandate.d.ts +5 -0
  35. package/dist/agents/prompts/07_agents/reviewer/index.d.ts +4 -0
  36. package/dist/agents/prompts/07_agents/reviewer/reviewer_mandate.d.ts +5 -0
  37. package/dist/agents/prompts/07_agents/worker/index.d.ts +4 -0
  38. package/dist/agents/prompts/07_agents/worker/worker_mandate.d.ts +5 -0
  39. package/dist/agents/prompts/08_tools/agents/index.d.ts +2 -0
  40. package/dist/agents/prompts/08_tools/index.d.ts +8 -0
  41. package/dist/agents/prompts/08_tools/tools_code_editing.d.ts +5 -0
  42. package/dist/agents/prompts/08_tools/tools_core.d.ts +8 -0
  43. package/dist/agents/prompts/08_tools/tools_testing.d.ts +5 -0
  44. package/dist/agents/prompts/index.d.ts +26 -14
  45. package/dist/core/agents/interfaces/session-pool.interface.d.ts +4 -0
  46. package/dist/core/agents/session-pool.d.ts +4 -0
  47. package/dist/core/loop/mission-loop.d.ts +8 -0
  48. package/dist/core/loop/todo-manager.d.ts +8 -4
  49. package/dist/core/todo/todo-manager.d.ts +36 -0
  50. package/dist/hooks/index.d.ts +1 -1
  51. package/dist/hooks/registry.d.ts +9 -6
  52. package/dist/hooks/types.d.ts +7 -0
  53. package/dist/index.js +1869 -1440
  54. package/package.json +1 -1
  55. package/dist/agents/prompts/discovery/index.d.ts +0 -3
  56. package/dist/agents/prompts/execution/index.d.ts +0 -9
  57. package/dist/agents/prompts/mission/index.d.ts +0 -4
  58. package/dist/agents/prompts/philosophy/execution-assurance.d.ts +0 -2
  59. package/dist/agents/prompts/philosophy/index.d.ts +0 -4
  60. package/dist/agents/prompts/planning/index.d.ts +0 -8
  61. package/dist/agents/prompts/roles/commander/index.d.ts +0 -4
  62. package/dist/agents/prompts/roles/planner/index.d.ts +0 -3
  63. package/dist/agents/prompts/roles/reviewer/index.d.ts +0 -3
  64. package/dist/agents/prompts/roles/worker/index.d.ts +0 -3
  65. package/dist/agents/prompts/tools/index.d.ts +0 -5
  66. package/dist/agents/prompts/verification/index.d.ts +0 -7
  67. /package/dist/agents/prompts/{philosophy/anti-hallucination.d.ts → 01_philosophy/anti_hallucination.d.ts} +0 -0
  68. /package/dist/agents/prompts/{philosophy → 01_philosophy}/core.d.ts +0 -0
  69. /package/dist/agents/prompts/{philosophy → 01_philosophy}/modularity.d.ts +0 -0
  70. /package/dist/agents/prompts/{discovery/environment.d.ts → 02_discovery/discovery_environment.d.ts} +0 -0
  71. /package/dist/agents/prompts/{discovery/skills.d.ts → 02_discovery/discovery_skills.d.ts} +0 -0
  72. /package/dist/agents/prompts/{discovery/workspace.d.ts → 02_discovery/discovery_workspace.d.ts} +0 -0
  73. /package/dist/agents/prompts/{planning/planner-todo.d.ts → 03_planning/agents/planning_planner.d.ts} +0 -0
  74. /package/dist/agents/prompts/{planning/reviewer-todo-update.d.ts → 03_planning/agents/planning_reviewer.d.ts} +0 -0
  75. /package/dist/agents/prompts/{planning/decomposition.d.ts → 03_planning/planning_decomposition.d.ts} +0 -0
  76. /package/dist/agents/prompts/{planning/file-planning.d.ts → 03_planning/planning_file_planning.d.ts} +0 -0
  77. /package/dist/agents/prompts/{execution/parallel.d.ts → 03_planning/planning_parallel.d.ts} +0 -0
  78. /package/dist/agents/prompts/{planning/research.d.ts → 03_planning/planning_research.d.ts} +0 -0
  79. /package/dist/agents/prompts/{planning/todo-format.d.ts → 03_planning/planning_todo_format.d.ts} +0 -0
  80. /package/dist/agents/prompts/{planning/todo-rules.d.ts → 03_planning/planning_todo_rules.d.ts} +0 -0
  81. /package/dist/agents/prompts/{planning/todo-sync.d.ts → 03_planning/planning_todo_sync.d.ts} +0 -0
  82. /package/dist/agents/prompts/{execution/delegation.d.ts → 04_execution/execution_delegation.d.ts} +0 -0
  83. /package/dist/agents/prompts/{execution/file-assignment.d.ts → 04_execution/execution_file_assignment.d.ts} +0 -0
  84. /package/dist/agents/prompts/{execution/hyper-parallel.d.ts → 04_execution/execution_hyper_parallel.d.ts} +0 -0
  85. /package/dist/agents/prompts/{execution/isolation.d.ts → 04_execution/execution_isolation.d.ts} +0 -0
  86. /package/dist/agents/prompts/{execution/quality.d.ts → 04_execution/execution_quality.d.ts} +0 -0
  87. /package/dist/agents/prompts/{execution/strategy.d.ts → 04_execution/execution_strategy.d.ts} +0 -0
  88. /package/dist/agents/prompts/{execution/tdd.d.ts → 04_execution/execution_tdd.d.ts} +0 -0
  89. /package/dist/agents/prompts/{execution/workflow.d.ts → 04_execution/execution_workflow.d.ts} +0 -0
  90. /package/dist/agents/prompts/{verification/reviewer-process.d.ts → 05_verification/agents/verification_reviewer.d.ts} +0 -0
  91. /package/dist/agents/prompts/{verification/async-monitoring.d.ts → 05_verification/verification_async_monitoring.d.ts} +0 -0
  92. /package/dist/agents/prompts/{verification/evidence.d.ts → 05_verification/verification_evidence.d.ts} +0 -0
  93. /package/dist/agents/prompts/{verification/integration.d.ts → 05_verification/verification_integration.d.ts} +0 -0
  94. /package/dist/agents/prompts/{verification/process.d.ts → 05_verification/verification_strategy.d.ts} +0 -0
  95. /package/dist/agents/prompts/{verification/sync-check.d.ts → 05_verification/verification_sync_check.d.ts} +0 -0
  96. /package/dist/agents/prompts/{verification/sync-handling.d.ts → 05_verification/verification_sync_handling.d.ts} +0 -0
  97. /package/dist/agents/prompts/{mission/completion-conditions.d.ts → 06_mission/mission_completion_conditions.d.ts} +0 -0
  98. /package/dist/agents/prompts/{mission/loop-continuation.d.ts → 06_mission/mission_loop_continuation.d.ts} +0 -0
  99. /package/dist/agents/prompts/{mission/recovery.d.ts → 06_mission/mission_recovery.d.ts} +0 -0
  100. /package/dist/agents/prompts/{mission/status-tracking.d.ts → 06_mission/mission_status_tracking.d.ts} +0 -0
  101. /package/dist/agents/prompts/{roles/commander/forbidden.d.ts → 07_agents/commander/commander_forbidden.d.ts} +0 -0
  102. /package/dist/agents/prompts/{roles/commander/identity.d.ts → 07_agents/commander/commander_identity.d.ts} +0 -0
  103. /package/dist/agents/prompts/{roles/commander/required.d.ts → 07_agents/commander/commander_required.d.ts} +0 -0
  104. /package/dist/agents/prompts/{roles/commander/role.d.ts → 07_agents/commander/commander_role.d.ts} +0 -0
  105. /package/dist/agents/prompts/{roles/planner/forbidden.d.ts → 07_agents/planner/planner_forbidden.d.ts} +0 -0
  106. /package/dist/agents/prompts/{roles/planner/identity.d.ts → 07_agents/planner/planner_identity.d.ts} +0 -0
  107. /package/dist/agents/prompts/{roles/planner/required.d.ts → 07_agents/planner/planner_required.d.ts} +0 -0
  108. /package/dist/agents/prompts/{roles/reviewer/forbidden.d.ts → 07_agents/reviewer/reviewer_forbidden.d.ts} +0 -0
  109. /package/dist/agents/prompts/{roles/reviewer/identity.d.ts → 07_agents/reviewer/reviewer_identity.d.ts} +0 -0
  110. /package/dist/agents/prompts/{roles/reviewer/required.d.ts → 07_agents/reviewer/reviewer_required.d.ts} +0 -0
  111. /package/dist/agents/prompts/{roles/worker/forbidden.d.ts → 07_agents/worker/worker_forbidden.d.ts} +0 -0
  112. /package/dist/agents/prompts/{roles/worker/identity.d.ts → 07_agents/worker/worker_identity.d.ts} +0 -0
  113. /package/dist/agents/prompts/{roles/worker/required.d.ts → 07_agents/worker/worker_required.d.ts} +0 -0
  114. /package/dist/agents/prompts/{tools/reviewer-lsp.d.ts → 08_tools/agents/tools_reviewer.d.ts} +0 -0
  115. /package/dist/agents/prompts/{tools/worker-lsp.d.ts → 08_tools/agents/tools_worker.d.ts} +0 -0
  116. /package/dist/agents/prompts/{tools/ast.d.ts → 08_tools/tools_ast.d.ts} +0 -0
  117. /package/dist/agents/prompts/{tools/lsp.d.ts → 08_tools/tools_lsp.d.ts} +0 -0
  118. /package/dist/agents/prompts/{tools/search.d.ts → 08_tools/tools_search.d.ts} +0 -0
package/dist/index.js CHANGED
@@ -2397,43 +2397,12 @@ var init_shared = __esm({
2397
2397
  }
2398
2398
  });
2399
2399
 
2400
- // src/agents/prompts/philosophy/core.ts
2401
- var CORE_PHILOSOPHY;
2402
- var init_core2 = __esm({
2403
- "src/agents/prompts/philosophy/core.ts"() {
2404
- "use strict";
2405
- init_constants();
2406
- init_shared();
2407
- CORE_PHILOSOPHY = `${PROMPT_TAGS.CORE_PHILOSOPHY.open}
2408
- ## Core Philosophy: ${PHILOSOPHY_TAGLINE}
2409
-
2410
- > ${PHILOSOPHY_QUOTE}
2411
-
2412
- | Phase | Action | Key Behavior |
2413
- |:-----:|:-------|:-------------|
2414
- | [EXPLORE] **${PHILOSOPHY_PHASES.EXPLORE}** | Scan unknown territory | Detect environment, never assume |
2415
- | [LEARN] **${PHILOSOPHY_PHASES.LEARN}** | Document discoveries | Record patterns for future use |
2416
- | [ADAPT] **${PHILOSOPHY_PHASES.ADAPT}** | Adjust to findings | Match project's style and context |
2417
- | [ACT] **${PHILOSOPHY_PHASES.ACT}** | Execute with confidence | Build, test, verify, conclude |
2418
-
2419
- **${PHILOSOPHY_LEARN_PRINCIPLE}**
2420
-
2421
- ### Agent Focus:
2422
- - [COMMANDER] **${AGENT_NAMES.COMMANDER}**: All phases (orchestrate the full cycle)
2423
- - [PLANNER] **${AGENT_NAMES.PLANNER}**: ${PHILOSOPHY_PHASES.EXPLORE} \u2192 ${PHILOSOPHY_PHASES.LEARN} (research and document)
2424
- - [WORKER] **${AGENT_NAMES.WORKER}**: ${PHILOSOPHY_PHASES.ADAPT} \u2192 ${PHILOSOPHY_PHASES.ACT} (implement with fit)
2425
- - [REVIEWER] **${AGENT_NAMES.REVIEWER}**: ${PHILOSOPHY_PHASES.EXPLORE} \u2192 ${PHILOSOPHY_PHASES.LEARN} \u2192 ${PHILOSOPHY_PHASES.ACT} (verify with evidence)
2426
- ${PROMPT_TAGS.CORE_PHILOSOPHY.close}`;
2427
- }
2428
- });
2429
-
2430
- // src/agents/prompts/philosophy/execution-assurance.ts
2400
+ // src/agents/prompts/01_philosophy/execution_assurance.ts
2431
2401
  var EXECUTION_ASSURANCE;
2432
2402
  var init_execution_assurance = __esm({
2433
- "src/agents/prompts/philosophy/execution-assurance.ts"() {
2403
+ "src/agents/prompts/01_philosophy/execution_assurance.ts"() {
2434
2404
  "use strict";
2435
2405
  init_shared();
2436
- init_shared();
2437
2406
  EXECUTION_ASSURANCE = wrapTag(PROMPT_TAGS.EXECUTION_ASSURANCE, `
2438
2407
  ## L0-L7 Execution Assurance Levels
2439
2408
 
@@ -2454,10 +2423,10 @@ var init_execution_assurance = __esm({
2454
2423
  }
2455
2424
  });
2456
2425
 
2457
- // src/agents/prompts/philosophy/anti-hallucination.ts
2426
+ // src/agents/prompts/01_philosophy/anti_hallucination.ts
2458
2427
  var ANTI_HALLUCINATION_CORE;
2459
2428
  var init_anti_hallucination = __esm({
2460
- "src/agents/prompts/philosophy/anti-hallucination.ts"() {
2429
+ "src/agents/prompts/01_philosophy/anti_hallucination.ts"() {
2461
2430
  "use strict";
2462
2431
  init_shared();
2463
2432
  ANTI_HALLUCINATION_CORE = `${PROMPT_TAGS.ANTI_HALLUCINATION.open}
@@ -2512,10 +2481,40 @@ ${PROMPT_TAGS.ANTI_HALLUCINATION.close}`;
2512
2481
  }
2513
2482
  });
2514
2483
 
2515
- // src/agents/prompts/philosophy/modularity.ts
2484
+ // src/agents/prompts/01_philosophy/core.ts
2485
+ var CORE_PHILOSOPHY;
2486
+ var init_core2 = __esm({
2487
+ "src/agents/prompts/01_philosophy/core.ts"() {
2488
+ "use strict";
2489
+ init_constants();
2490
+ init_shared();
2491
+ CORE_PHILOSOPHY = `${PROMPT_TAGS.CORE_PHILOSOPHY.open}
2492
+ ## Core Philosophy: ${PHILOSOPHY_TAGLINE}
2493
+
2494
+ > ${PHILOSOPHY_QUOTE}
2495
+
2496
+ | Phase | Action | Key Behavior |
2497
+ |:-----:|:-------|:-------------|
2498
+ | [EXPLORE] **${PHILOSOPHY_PHASES.EXPLORE}** | Scan unknown territory | Detect environment, never assume |
2499
+ | [LEARN] **${PHILOSOPHY_PHASES.LEARN}** | Document discoveries | Record patterns for future use |
2500
+ | [ADAPT] **${PHILOSOPHY_PHASES.ADAPT}** | Adjust to findings | Match project's style and context |
2501
+ | [ACT] **${PHILOSOPHY_PHASES.ACT}** | Execute with confidence | Build, test, verify, conclude |
2502
+
2503
+ **${PHILOSOPHY_LEARN_PRINCIPLE}**
2504
+
2505
+ ### Agent Focus:
2506
+ - [COMMANDER] **${AGENT_NAMES.COMMANDER}**: All phases (orchestrate the full cycle)
2507
+ - [PLANNER] **${AGENT_NAMES.PLANNER}**: ${PHILOSOPHY_PHASES.EXPLORE} \u2192 ${PHILOSOPHY_PHASES.LEARN} (research and document)
2508
+ - [WORKER] **${AGENT_NAMES.WORKER}**: ${PHILOSOPHY_PHASES.ADAPT} \u2192 ${PHILOSOPHY_PHASES.ACT} (implement with fit)
2509
+ - [REVIEWER] **${AGENT_NAMES.REVIEWER}**: ${PHILOSOPHY_PHASES.EXPLORE} \u2192 ${PHILOSOPHY_PHASES.LEARN} \u2192 ${PHILOSOPHY_PHASES.ACT} (verify with evidence)
2510
+ ${PROMPT_TAGS.CORE_PHILOSOPHY.close}`;
2511
+ }
2512
+ });
2513
+
2514
+ // src/agents/prompts/01_philosophy/modularity.ts
2516
2515
  var MODULARITY_ENFORCEMENT;
2517
2516
  var init_modularity = __esm({
2518
- "src/agents/prompts/philosophy/modularity.ts"() {
2517
+ "src/agents/prompts/01_philosophy/modularity.ts"() {
2519
2518
  "use strict";
2520
2519
  init_shared();
2521
2520
  MODULARITY_ENFORCEMENT = `${PROMPT_TAGS.QUALITY_CHECKLIST.open}
@@ -2547,585 +2546,399 @@ ${PROMPT_TAGS.QUALITY_CHECKLIST.close}`;
2547
2546
  }
2548
2547
  });
2549
2548
 
2550
- // src/agents/prompts/philosophy/index.ts
2549
+ // src/agents/prompts/01_philosophy/metadata.ts
2550
+ var init_metadata = __esm({
2551
+ "src/agents/prompts/01_philosophy/metadata.ts"() {
2552
+ "use strict";
2553
+ }
2554
+ });
2555
+
2556
+ // src/agents/prompts/01_philosophy/index.ts
2551
2557
  var init_philosophy2 = __esm({
2552
- "src/agents/prompts/philosophy/index.ts"() {
2558
+ "src/agents/prompts/01_philosophy/index.ts"() {
2553
2559
  "use strict";
2554
- init_core2();
2555
2560
  init_execution_assurance();
2556
2561
  init_anti_hallucination();
2562
+ init_core2();
2557
2563
  init_modularity();
2564
+ init_metadata();
2558
2565
  }
2559
2566
  });
2560
2567
 
2561
- // src/agents/prompts/mission/completion-conditions.ts
2562
- var COMPLETION_CONDITIONS;
2563
- var init_completion_conditions = __esm({
2564
- "src/agents/prompts/mission/completion-conditions.ts"() {
2568
+ // src/agents/prompts/02_discovery/discovery_workspace.ts
2569
+ var SHARED_WORKSPACE;
2570
+ var init_discovery_workspace = __esm({
2571
+ "src/agents/prompts/02_discovery/discovery_workspace.ts"() {
2565
2572
  "use strict";
2566
2573
  init_shared();
2567
- COMPLETION_CONDITIONS = `
2568
- ## \u26A0\uFE0F MISSION COMPLETION PROTOCOL
2569
-
2570
- > **IMPORTANT**: You (Commander) conclude the mission ONLY when every hierarchical task is verified.
2571
- > You must rely on ${AGENT_NAMES.REVIEWER} for the final quality gate.
2574
+ SHARED_WORKSPACE = `${PROMPT_TAGS.SHARED_WORKSPACE.open}
2575
+ ${PATHS.OPENCODE}/ - Shared Context Directory (Real-time State)
2572
2576
 
2573
- ### When to Conclude
2577
+ \`\`\`
2578
+ ${PATHS.OPENCODE}/
2579
+ \u251C\u2500\u2500 ${PATHS.TODO.split("/").pop()} - Master task list (single source of truth)
2580
+ \u251C\u2500\u2500 ${PATHS.CONTEXT.split("/").pop()} - Project context summary (<150 lines)
2581
+ \u251C\u2500\u2500 ${PATHS.WORK_LOG.split("/").pop()} - REAL-TIME work status (ALL agents read/write)
2582
+ \u2502 # - Active sessions & assigned files
2583
+ \u2502 # - Unit test completion records
2584
+ \u2502 # - Pending integration items
2585
+ \u251C\u2500\u2500 ${PATHS.UNIT_TESTS.split("/").pop()}/ - Unit test records (preserved after deletion)
2586
+ \u2502 \u2514\u2500\u2500 [timestamp]-[file].md # Test content, results, deleted test code
2587
+ \u251C\u2500\u2500 ${PATHS.SYNC_ISSUES.split("/").pop()} - File sync issues (Reviewer writes)
2588
+ \u251C\u2500\u2500 ${PATHS.INTEGRATION_STATUS.split("/").pop()} - Integration test results & sync status
2589
+ \u251C\u2500\u2500 ${PATHS.DOCS.split("/").pop()}/ - Cached documentation
2590
+ \u2514\u2500\u2500 ${PATHS.ARCHIVE.split("/").pop()}/ - Old context
2591
+ \`\`\`
2574
2592
 
2575
- Finalize only when ALL of the following are true:
2576
- - \u2705 **Hierarchical Completeness**: Every milestone, task, and sub-task in ${PATHS.TODO} is marked [x].
2577
- - \u2705 **Verified Outcome**: You have received confirmation from ${AGENT_NAMES.REVIEWER} that all tests and builds pass.
2578
- - \u2705 **Zero Regression**: No unresolved issues in ${PATHS.SYNC_ISSUES}.
2579
2593
 
2580
- ### Final Verification Workflow
2581
2594
 
2582
- 1. **Unit Reviews**: As Workers complete Grade 3 sub-tasks, delegate to ${AGENT_NAMES.REVIEWER} for individual file/module verification.
2583
- 2. **Integration Pass**: Once all segments are done, delegate a final "${VERIFICATION_SIGNALS.FINAL_PASS}" task to ${AGENT_NAMES.REVIEWER}.
2584
- 3. **Execution Gate**: The Reviewer MUST run the full build and E2E test suite.
2585
- 4. **Correction**: If Reviewer reports failure, address it immediately. Do not claim completion.
2595
+ ## ID Formats (no digit limit):
2596
+ - Session: ${ID_PREFIX.SESSION}N (e.g., ${ID_PREFIX.SESSION}1, ${ID_PREFIX.SESSION}42)
2597
+ - Sync Issue: ${ID_PREFIX.SYNC_ISSUE}N (e.g., ${ID_PREFIX.SYNC_ISSUE}1, ${ID_PREFIX.SYNC_ISSUE}100)
2598
+ - Unit Test: ${ID_PREFIX.UNIT_TEST}N (e.g., ${ID_PREFIX.UNIT_TEST}1, ${ID_PREFIX.UNIT_TEST}50)
2586
2599
 
2587
- ### Autonomous Loop Enforcement
2588
- - THE SYSTEM MONITOR: An autonomous process monitors ${PATHS.TODO} and ${PATHS.CONTEXT}.
2589
- - FORCED RESTART: If you attempt to stop while \`[ ]\` remain, the system will automatically inject a continuation prompt and increment the loop counter.
2590
- - RESOLUTION: You are only "released" when the system verifies 100% check-off of the hierarchical plan.
2600
+ ## Status Values:
2601
+ - Action: ${WORK_STATUS.ACTION.CREATE} | ${WORK_STATUS.ACTION.MODIFY} | ${WORK_STATUS.ACTION.DELETE} | ${WORK_STATUS.ACTION.FIX}
2602
+ - Status: ${WORK_STATUS.STATUS.PENDING} | ${WORK_STATUS.STATUS.IN_PROGRESS} | ${WORK_STATUS.STATUS.DONE}
2603
+ - Test: ${WORK_STATUS.TEST_RESULT.PASS} | ${WORK_STATUS.TEST_RESULT.FAIL}
2591
2604
 
2592
- ### DO NOT
2593
- - \u274C Declare mission success based on partial output.
2594
- - \u274C Stop if any Grade 1, 2, or 3 items are still \`[ ]\`.
2595
- - \u274C Skip the final integration build/test pass.
2596
- `;
2597
- }
2598
- });
2605
+ ## ${PATHS.WORK_LOG} FORMAT:
2606
+ \`\`\`markdown
2607
+ # Work Log
2599
2608
 
2600
- // src/agents/prompts/mission/loop-continuation.ts
2601
- var COMMANDER_LOOP_CONTINUATION;
2602
- var init_loop_continuation = __esm({
2603
- "src/agents/prompts/mission/loop-continuation.ts"() {
2604
- "use strict";
2605
- init_shared();
2606
- COMMANDER_LOOP_CONTINUATION = `${PROMPT_TAGS.LOOP_CONTINUATION.open}
2607
- ## LOOP CONTINUATION PROTOCOL
2609
+ ## Active Sessions
2610
+ - [ ] ${ID_PREFIX.SESSION}1 (${AGENT_NAMES.WORKER}): \`src/auth/login.ts\` - ${WORK_STATUS.STATUS.IN_PROGRESS}
2611
+ - [x] ${ID_PREFIX.SESSION}2 (${AGENT_NAMES.WORKER}): \`src/utils/hash.ts\` - ${WORK_STATUS.SESSION.COMPLETED}
2608
2612
 
2609
- At the START of each loop iteration, ${AGENT_NAMES.COMMANDER} MUST read shared state:
2613
+ ## Completed Units (Ready for Integration)
2614
+ | File | Session | Unit Test | Timestamp |
2615
+ |------|---------|-----------|-----------|
2616
+ | src/utils/hash.ts | ${ID_PREFIX.SESSION}2 | ${WORK_STATUS.TEST_RESULT.PASS} | 2026-01-18T09:00:00 |
2610
2617
 
2611
- ### Step 1: Read Status Summary
2612
- \`\`\`bash
2613
- cat ${PATHS.STATUS} 2>/dev/null || echo "No status yet"
2614
- cat ${PATHS.TODO}
2615
- cat ${PATHS.SYNC_ISSUES} 2>/dev/null || echo "No sync issues"
2618
+ ## Pending Integration
2619
+ - src/utils/hash.ts
2616
2620
  \`\`\`
2617
2621
 
2618
- ---
2619
-
2620
- ## Decision Matrix
2621
-
2622
- | ${PATHS.TODO} Status | ${PATHS.SYNC_ISSUES} | Action |
2623
- |--------|--------|--------|
2624
- | Incomplete items | Any | Continue work |
2625
- | All [x] | Issues exist | Fix sync issues |
2626
- | All [x] | Empty | Conclude mission |
2627
-
2628
- ### When All Work Complete
2629
- When ALL TODO items are [x] and NO sync issues:
2630
- \u2192 Ensure a final "${VERIFICATION_SIGNALS.FINAL_PASS}" task was performed by ${AGENT_NAMES.REVIEWER}
2631
- \u2192 If all checks pass, you may conclude the mission
2632
- \u2192 If any check fails, address issues and repeat verification
2633
-
2634
- ${PROMPT_TAGS.LOOP_CONTINUATION.close}
2622
+ ## PATH NOTES:
2623
+ - File paths use forward slash '/' in examples
2624
+ - On Windows, paths may use backslash '\\\\'
2625
+ - Use path.normalize() or similar when comparing paths programmatically
2635
2626
 
2627
+ RULES:
2628
+ - ALL agents MUST read ${PATHS.WORK_LOG} before starting
2629
+ - ${AGENT_NAMES.WORKER} updates ${PATHS.WORK_LOG} when starting/completing file work
2630
+ - ${AGENT_NAMES.REVIEWER} monitors ${PATHS.WORK_LOG} for completed units
2631
+ - ${AGENT_NAMES.COMMANDER} reads ${PATHS.WORK_LOG} in each loop iteration
2632
+ - ${PATHS.SYNC_ISSUES} = ${AGENT_NAMES.REVIEWER} writes issues for next iteration
2633
+ ${PROMPT_TAGS.SHARED_WORKSPACE.close}
2636
2634
  `;
2637
2635
  }
2638
2636
  });
2639
2637
 
2640
- // src/agents/prompts/mission/status-tracking.ts
2641
- var MISSION_STATUS_FORMAT;
2642
- var init_status_tracking = __esm({
2643
- "src/agents/prompts/mission/status-tracking.ts"() {
2638
+ // src/agents/prompts/02_discovery/discovery_core.ts
2639
+ var init_discovery_core = __esm({
2640
+ "src/agents/prompts/02_discovery/discovery_core.ts"() {
2644
2641
  "use strict";
2645
- init_shared();
2646
- MISSION_STATUS_FORMAT = `
2647
- # Mission Status
2648
-
2649
- ## Progress
2650
- - ${PATHS.TODO}: [N]/[Total] ([X]%)
2651
- - Issues: [N] unresolved
2652
- - ${AGENT_NAMES.WORKER}s: [N] active
2653
- - Verification Strategy: [High-level plan from ${AGENT_NAMES.REVIEWER}]
2654
- - Execution Status: ${WORK_STATUS.E2E_STATUS.NOT_STARTED} | ${WORK_STATUS.E2E_STATUS.RUNNING} | ${WORK_STATUS.E2E_STATUS.PASS} | ${WORK_STATUS.E2E_STATUS.FAIL}
2655
-
2656
- ## Current Phase
2657
- [Phase Name]
2658
- `;
2659
2642
  }
2660
2643
  });
2661
2644
 
2662
- // src/agents/prompts/mission/recovery.ts
2663
- var COMMANDER_RECOVERY;
2664
- var init_recovery3 = __esm({
2665
- "src/agents/prompts/mission/recovery.ts"() {
2645
+ // src/agents/prompts/02_discovery/discovery_environment.ts
2646
+ var ENVIRONMENT_DISCOVERY;
2647
+ var init_discovery_environment = __esm({
2648
+ "src/agents/prompts/02_discovery/discovery_environment.ts"() {
2666
2649
  "use strict";
2667
2650
  init_shared();
2668
- COMMANDER_RECOVERY = `${PROMPT_TAGS.RECOVERY.open}
2669
- ## RECOVERY: Agent Failure Handling
2670
-
2671
- When any agent fails, times out, or gets stuck:
2651
+ ENVIRONMENT_DISCOVERY = `${PROMPT_TAGS.ENVIRONMENT_DISCOVERY.open}
2652
+ **MANDATORY FIRST STEP** - Before any planning or coding:
2672
2653
 
2673
- ### Level 1: ${RECOVERY_LEVEL.DECOMPOSE}
2674
- - Task is too big \u2192 Split into smaller units (< ${LIMITS.TASK_TIME_LIMIT_MIN} min each)
2654
+ ## \u26A1 Direct Discovery (Efficient)
2655
+ Read the project directly - this is faster and cheaper than delegating to parallel scouts:
2656
+ 1. **Read** project structure, config files, and documentation directly.
2657
+ 2. **Document** all findings to \`${PATHS.CONTEXT}\`.
2658
+ 3. **Verify** findings against existing codebase.
2675
2659
 
2676
- - Delegate smaller pieces to fresh agents
2677
- - For repetitive changes, use ${TOOL_NAMES.SED_REPLACE} or shell tools
2660
+ [NOTE]: Direct reading saves tokens and avoids parallel wait overhead.
2678
2661
 
2679
- ### Level 2: ${RECOVERY_LEVEL.RE_PLAN}
2680
- If decomposition still fails:
2681
- - Step back and re-analyze the problem
2682
- - Write ${PATHS.OPENCODE}/escalation.md with analysis
2683
- - Call ${AGENT_NAMES.PLANNER} to create new strategy
2684
- - Try different approach
2662
+ ## 1. Project Structure Discovery
2663
+ Explore the project root to understand its organization:
2664
+ \`\`\`bash
2665
+ ls -la # Root contents
2666
+ find . -maxdepth 2 -type d | head -${LIMITS.DEFAULT_SCAN_LIMIT} # Directory structure
2667
+ find . -maxdepth 1 -type f # Root files
2668
+ \`\`\`
2685
2669
 
2686
- ### Level 3: ${RECOVERY_LEVEL.ASK_USER}
2687
- If re-planning fails or requires human judgment:
2688
- - Clearly explain the situation and what was tried
2689
- - Present 2-3 options with pros/cons
2690
- - Ask user for direction
2691
- - Proceed based on user input
2692
2670
 
2693
- ### Decision Guide
2694
- | Situation | Action |
2695
- |-----------|--------|
2696
- | Task too big | Level 1: ${RECOVERY_LEVEL.DECOMPOSE} |
2697
- | Wrong approach | Level 2: ${RECOVERY_LEVEL.RE_PLAN} |
2698
- | Ambiguous requirements | Level 3: ${RECOVERY_LEVEL.ASK_USER} |
2699
- | Critical decision needed | Level 3: ${RECOVERY_LEVEL.ASK_USER} |
2700
- | All attempts failed | Level 3: ${RECOVERY_LEVEL.ASK_USER} |
2671
+ **Look for patterns, NOT specific files:**
2672
+ - Source directories (src/, lib/, app/, pkg/, internal/, cmd/)
2673
+ - Test directories (tests/, test/, spec/, __tests__/, *_test/)
2674
+ - Build artifacts (dist/, build/, target/, out/, bin/)
2675
+ - Documentation (docs/, doc/, README*, CONTRIBUTING*, CHANGELOG*)
2676
+ - Configuration (hidden files, *.config.*, *.json, *.yaml, *.toml)
2701
2677
 
2702
- PRINCIPLE: ${RECOVERY_PRINCIPLE}
2703
- ${PROMPT_TAGS.RECOVERY.close}`;
2704
- }
2705
- });
2678
+ ## 2. Environment Detection (Adaptive)
2679
+ **DO NOT assume technology stack. DETECT it:**
2706
2680
 
2707
- // src/agents/prompts/mission/index.ts
2708
- var init_mission2 = __esm({
2709
- "src/agents/prompts/mission/index.ts"() {
2710
- "use strict";
2711
- init_completion_conditions();
2712
- init_loop_continuation();
2713
- init_status_tracking();
2714
- init_recovery3();
2715
- }
2716
- });
2681
+ | Indicator Files | Likely Environment |
2682
+ |----------------|-------------------|
2683
+ | package.json, tsconfig.json | Node.js / TypeScript |
2684
+ | Cargo.toml, Cargo.lock | Rust |
2685
+ | go.mod, go.sum | Go |
2686
+ | requirements.txt, pyproject.toml, setup.py | Python |
2687
+ | pom.xml, build.gradle | Java / JVM |
2688
+ | Gemfile, *.rb | Ruby |
2689
+ | composer.json | PHP |
2690
+ | CMakeLists.txt, Makefile | C/C++ |
2691
+ | *.csproj, *.sln | .NET / C# |
2692
+ | pubspec.yaml | Dart / Flutter |
2717
2693
 
2718
- // src/agents/prompts/verification/process.ts
2719
- var VERIFICATION_REQUIREMENTS;
2720
- var init_process = __esm({
2721
- "src/agents/prompts/verification/process.ts"() {
2722
- "use strict";
2723
- init_shared();
2724
- VERIFICATION_REQUIREMENTS = `${PROMPT_TAGS.VERIFICATION.open}
2725
- VERIFICATION CHECKLIST
2726
-
2727
- ## Code Verification
2728
- - [ ] lsp_diagnostics clean (no errors/warnings)
2729
- - [ ] Build passes (use project's build command from ${PATHS.CONTEXT})
2730
- - [ ] Tests pass (use project's test command from ${PATHS.CONTEXT})
2731
- - [ ] No untyped variables (language-appropriate)
2732
- - [ ] No debug logging left (console.log, print, etc.)
2733
-
2734
- ## Documentation Verification
2735
- - [ ] Implementation matches ${PATHS.DOCS}/
2736
- - [ ] API usage matches official docs
2737
- - [ ] Version compatibility confirmed
2694
+ **For each detected config file, read it to find:**
2695
+ - Build commands
2696
+ - Test commands
2697
+ - Entry points
2698
+ - Dependencies
2738
2699
 
2739
- ## Security Verification
2740
- - [ ] No hardcoded secrets/passwords/API keys
2741
- - [ ] Input validation present
2742
- - [ ] Error messages don't leak sensitive info
2700
+ ## 3. Infrastructure Detection
2701
+ \`\`\`bash
2702
+ # Container/orchestration
2703
+ ls Dockerfile* docker-compose* 2>/dev/null
2704
+ ls kubernetes/ k8s/ helm/ 2>/dev/null
2743
2705
 
2744
- ONLY mark complete after ALL checks pass!
2745
- ${PROMPT_TAGS.VERIFICATION.close}
2746
- `;
2747
- }
2748
- });
2706
+ # CI/CD
2707
+ ls .github/workflows/ .gitlab-ci.yml .circleci/ Jenkinsfile 2>/dev/null
2749
2708
 
2750
- // src/agents/prompts/verification/integration.ts
2751
- var REVIEWER_INTEGRATION_TESTING;
2752
- var init_integration = __esm({
2753
- "src/agents/prompts/verification/integration.ts"() {
2754
- "use strict";
2755
- init_shared();
2756
- REVIEWER_INTEGRATION_TESTING = `${PROMPT_TAGS.INTEGRATION_TESTING.open}
2757
- ## INTEGRATION TESTING (Full System)
2709
+ # Cloud/IaC
2710
+ ls terraform/ cloudformation/ pulumi/ 2>/dev/null
2711
+ ls serverless.yml sam.yaml 2>/dev/null
2712
+ \`\`\`
2758
2713
 
2759
- ### Scope
2760
- ${AGENT_NAMES.REVIEWER} handles ALL integration levels:
2761
- - **Module Level**: Cross-file imports, shared types, interface contracts.
2762
- - **System Level**: Multi-module interactions, comprehensive E2E verification.
2763
- - **Environment**: Build systems, runtime configurations, deployment readiness.
2714
+ ## 4. Existing Context Check
2715
+ \`\`\`bash
2716
+ ls -la ${PATHS.OPENCODE}/ 2>/dev/null || echo "No existing context"
2717
+ \`\`\`
2718
+ - If ${PATHS.OPENCODE}/ exists \u2192 ASK user to continue or start fresh
2719
+ - If not \u2192 Create fresh context
2764
2720
 
2765
- ### Verification Mandate
2766
- As the **Final Quality Gate**, you are responsible for ensuring the system works as a cohesive whole.
2721
+ ## 5. Context Summary (SAVE TO ${PATHS.CONTEXT})
2722
+ \`\`\`markdown
2723
+ # Project Context
2767
2724
 
2768
- ### Integration Workflow
2725
+ ## Environment
2726
+ - Language: [DETECTED from files]
2727
+ - Runtime: [DETECTED version if available]
2728
+ - Build: [DETECTED build command]
2729
+ - Test: [DETECTED test command]
2730
+ - Package Manager: [DETECTED from lockfiles]
2769
2731
 
2770
- #### Step 1: Check Dependencies
2771
- - Verify all imports work across the entire project.
2772
- - Ensure shared types are consistent and exported correctly.
2732
+ ## Project Type
2733
+ - [ ] Library/Package
2734
+ - [ ] Application (CLI/Web/Mobile/Desktop)
2735
+ - [ ] Microservice
2736
+ - [ ] Monorepo
2737
+ - [ ] Other: [describe]
2773
2738
 
2774
- #### Step 2: System Build & Test
2775
- - Run the full project build command (e.g., \`npm run build\`).
2776
- - Execute the complete test suite including E2E tests.
2739
+ ## Infrastructure
2740
+ - Container: [None / Docker / Podman]
2741
+ - Orchestration: [None / K8s / Docker Compose]
2742
+ - CI/CD: [DETECTED from config files]
2743
+ - Cloud: [DETECTED or None]
2777
2744
 
2778
- #### Step 3: Record Sync Issues
2779
- If any regressions or integration failures are found, document them in ${PATHS.SYNC_ISSUES} for immediate resolution.
2745
+ ## Structure
2746
+ - Source: [DETECTED path]
2747
+ - Tests: [DETECTED path]
2748
+ - Docs: [DETECTED path]
2749
+ - Entry: [DETECTED main file]
2780
2750
 
2781
- ### Final Verification Gate
2782
- When instructed by ${AGENT_NAMES.COMMANDER} for a "${VERIFICATION_SIGNALS.FINAL_PASS}":
2783
- 1. Check the ENTIRE hierarchical TODO tree.
2784
- 2. Ensure every task has evidence of success.
2785
- 3. Mark high-level Tasks/Milestones as [x] only after comprehensive proof.
2751
+ ## Conventions (OBSERVE from existing code)
2752
+ - Naming: [camelCase / snake_case / PascalCase]
2753
+ - Imports: [relative / absolute / aliases]
2754
+ - Error handling: [exceptions / Result type / error codes]
2755
+ - Testing: [unit / integration / e2e patterns]
2786
2756
 
2787
- ### After Verification
2788
- 1. Mark [x] for reviewed items in TODO.
2789
- 2. Provide a definitive "PASSED" or "FAILED" status to ${AGENT_NAMES.COMMANDER}.
2757
+ ## Notes
2758
+ - [Any unique patterns or requirements observed]
2759
+ \`\`\`
2790
2760
 
2791
- ${PROMPT_TAGS.INTEGRATION_TESTING.close}`;
2761
+ ## CRITICAL RULES:
2762
+ 1. NEVER assume - always VERIFY by reading files
2763
+ 2. ADAPT to what you find, don't force expectations
2764
+ 3. If uncertain, ASK the user for clarification
2765
+ 4. Document EVERYTHING you discover
2766
+ ${PROMPT_TAGS.ENVIRONMENT_DISCOVERY.close}`;
2792
2767
  }
2793
2768
  });
2794
2769
 
2795
- // src/agents/prompts/verification/sync-check.ts
2796
- var REVIEWER_SYNC_VERIFICATION;
2797
- var init_sync_check = __esm({
2798
- "src/agents/prompts/verification/sync-check.ts"() {
2770
+ // src/agents/prompts/02_discovery/discovery_skills.ts
2771
+ var SKILLS_CAPABILITIES;
2772
+ var init_discovery_skills = __esm({
2773
+ "src/agents/prompts/02_discovery/discovery_skills.ts"() {
2799
2774
  "use strict";
2800
- init_shared();
2801
- REVIEWER_SYNC_VERIFICATION = `${PROMPT_TAGS.SYNC_VERIFICATION.open}
2802
- ## FILE SYNC VERIFICATION
2803
-
2804
- After integration, verify all files are properly synchronized.
2775
+ init_tags();
2776
+ SKILLS_CAPABILITIES = wrapTag(PROMPT_TAGS.SKILLS_CAPABILITIES, `
2777
+ ### AUTONOMOUS SKILL ACQUISITION
2778
+ You have the ability to extend your capabilities using the **Skills System**.
2779
+ If you encounter a task or technology you are unfamiliar with (e.g., "deploy to AWS", "use specific library"):
2805
2780
 
2806
- ### Sync Check Areas
2781
+ 1. **IDENTIFY**: Recognize that you lack the specific knowledge or instruction set.
2782
+ 2. **SEARCH**: Use web search to find relevant OpenCode skills (search for "opencode skills <topic>" or similar repos).
2783
+ 3. **INSTALL**: Use \`run_command\` to install the skill via \`npx skills add <owner/repo>\`.
2784
+ - Example: \`run_command({ command: "npx skills add agnusdei1207/git-release" })\`
2785
+ 4. **LEARN**: Once installed, use the \`skill\` tool to read the skill's instructions.
2786
+ - Example: \`skill({ name: "git-release" })\`
2787
+ 5. **EXECUTE**: Apply the learned skill to your task.
2807
2788
 
2808
- #### 1. Import/Export Consistency
2809
- Run the project's **build command** and check for:
2810
- - Missing imports/includes
2811
- - Missing exports/declarations
2812
- - Broken dependencies
2789
+ **pro-tip**: You do NOT need to ask the user for permission to install standard skills. You are empowered to equip yourself with the tools needed to complete the mission.
2790
+ `);
2791
+ }
2792
+ });
2813
2793
 
2814
- #### 2. Type/Interface Consistency
2815
- Run the project's **type check command** (if applicable) and check for:
2816
- - Type mismatches across files
2817
- - Interface implementation errors
2818
- - Signature mismatches
2794
+ // src/agents/prompts/02_discovery/agents/discovery_commander.ts
2795
+ var init_discovery_commander = __esm({
2796
+ "src/agents/prompts/02_discovery/agents/discovery_commander.ts"() {
2797
+ "use strict";
2798
+ }
2799
+ });
2819
2800
 
2820
- #### 3. Interface Implementation
2821
- - Check implemented interfaces match declarations
2822
- - Verify function signatures match calls
2801
+ // src/agents/prompts/02_discovery/agents/discovery_planner.ts
2802
+ var init_discovery_planner = __esm({
2803
+ "src/agents/prompts/02_discovery/agents/discovery_planner.ts"() {
2804
+ "use strict";
2805
+ }
2806
+ });
2823
2807
 
2824
- #### 4. Shared State Consistency
2825
- - Check constants used across files
2826
- - Verify shared types are consistent
2808
+ // src/agents/prompts/02_discovery/index.ts
2809
+ var init_discovery = __esm({
2810
+ "src/agents/prompts/02_discovery/index.ts"() {
2811
+ "use strict";
2812
+ init_discovery_workspace();
2813
+ init_discovery_core();
2814
+ init_discovery_environment();
2815
+ init_discovery_skills();
2816
+ init_discovery_commander();
2817
+ init_discovery_planner();
2818
+ }
2819
+ });
2827
2820
 
2828
- ---
2821
+ // src/agents/prompts/03_planning/planning_decomposition.ts
2822
+ var TASK_DECOMPOSITION;
2823
+ var init_planning_decomposition = __esm({
2824
+ "src/agents/prompts/03_planning/planning_decomposition.ts"() {
2825
+ "use strict";
2826
+ init_shared();
2827
+ TASK_DECOMPOSITION = wrapTag(PROMPT_TAGS.DECOMPOSITION_RULES, `
2828
+ ## Task Decomposition Rules
2829
2829
 
2830
- ## ISSUE MANAGEMENT RULES (CRITICAL)
2830
+ When a task is too large or complex:
2831
+ 1. **Break it down** into atomic steps (max 1 file or 1 logical unit per step).
2832
+ 2. **Update TODO**: Replace the large task with subtasks T[N.1], T[N.2], etc.
2833
+ 3. **Verify Atomic Success**: Each subtask must be verifiable independently (L2+).
2831
2834
 
2832
- ### ${PATHS.SYNC_ISSUES} Contains UNRESOLVED ONLY
2833
- - **Delete resolved issues immediately** (keep file clean)
2834
- - **Keep only unresolved** (only what ${AGENT_NAMES.COMMANDER} needs to read)
2835
- - **Summarize if too long** (archive old issues)
2835
+ If stuck:
2836
+ - Do not retry the same failing action more than twice.
2837
+ - Decompose the problem into smaller investigation steps.
2838
+ - Create a specific "Research" task to find the root cause.`);
2839
+ }
2840
+ });
2836
2841
 
2837
- ### Issue Format (Minimal)
2838
- \`\`\`markdown
2839
- # Sync Issues (Unresolved Only)
2842
+ // src/agents/prompts/03_planning/planning_parallel.ts
2843
+ var COMMANDER_PARALLEL;
2844
+ var init_planning_parallel = __esm({
2845
+ "src/agents/prompts/03_planning/planning_parallel.ts"() {
2846
+ "use strict";
2847
+ init_shared();
2848
+ COMMANDER_PARALLEL = `${PROMPT_TAGS.PARALLEL_EXECUTION.open}
2849
+ YOUR 3 SUPERPOWERS - USE AGGRESSIVELY:
2840
2850
 
2841
- ## ${ID_PREFIX.SYNC_ISSUE}N
2842
- - Severity: ${WORK_STATUS.SEVERITY.HIGH}
2843
- - Files: src/file1.ts \u2194 src/file2.ts
2844
- - Problem: [concise description]
2845
- - Fix: [specific solution]
2846
- - Status: ${WORK_STATUS.STATUS.PENDING}
2851
+ 1. PARALLEL AGENTS
2852
+ \`\`\`
2853
+ ${TOOL_NAMES.DELEGATE_TASK}({ ${PARALLEL_PARAMS.AGENT}: "${AGENT_NAMES.PLANNER}", ${PARALLEL_PARAMS.PROMPT}: "Research X", ${PARALLEL_PARAMS.BACKGROUND}: true })
2854
+ ${TOOL_NAMES.DELEGATE_TASK}({ ${PARALLEL_PARAMS.AGENT}: "${AGENT_NAMES.PLANNER}", ${PARALLEL_PARAMS.PROMPT}: "Research Y", ${PARALLEL_PARAMS.BACKGROUND}: true })
2855
+ // 2x faster!
2847
2856
  \`\`\`
2848
2857
 
2849
- ### After Fix Verification
2850
- When re-verifying after fixes:
2851
- 1. Check if issue is resolved
2852
- 2. If resolved: **DELETE the issue from ${PATHS.SYNC_ISSUES}**
2853
- 3. If not resolved: Update issue status, add notes
2854
- 4. Keep file minimal
2855
-
2856
- ---
2857
-
2858
- ### Loop Continuation
2859
- If sync issues exist:
2860
- 1. Write ONLY unresolved issues to ${PATHS.SYNC_ISSUES}
2861
- 2. Delete resolved issues from file
2862
- 3. Update ${PATHS.WORK_LOG} with required rework
2863
- 4. Report status to ${AGENT_NAMES.COMMANDER}
2864
-
2865
- ### CRITICAL:
2866
- - Always check sync AFTER integration tests
2867
- - DELETE resolved issues immediately
2868
- - Keep ${PATHS.SYNC_ISSUES} as short as possible
2869
- - Ensure ${AGENT_NAMES.COMMANDER} only sees what needs fixing
2858
+ 2. BACKGROUND COMMANDS
2859
+ \`\`\`
2860
+ ${TOOL_NAMES.RUN_BACKGROUND}({ command: "npm run build" })
2861
+ // ...continue other work...
2862
+ ${TOOL_NAMES.CHECK_BACKGROUND}({ ${PARALLEL_PARAMS.TASK_ID}: "xxx" })
2863
+ \`\`\`
2870
2864
 
2871
- ${PROMPT_TAGS.SYNC_VERIFICATION.close}`;
2865
+ 3. SESSION RESUME
2866
+ \`\`\`
2867
+ ${TOOL_NAMES.DELEGATE_TASK}({ ${PARALLEL_PARAMS.PROMPT}: "Continue work", ${PARALLEL_PARAMS.RESUME}: "session_abc" })
2868
+ \`\`\`
2869
+ ${PROMPT_TAGS.PARALLEL_EXECUTION.close}`;
2872
2870
  }
2873
2871
  });
2874
2872
 
2875
- // src/agents/prompts/verification/sync-handling.ts
2876
- var COMMANDER_SYNC_HANDLING;
2877
- var init_sync_handling = __esm({
2878
- "src/agents/prompts/verification/sync-handling.ts"() {
2873
+ // src/agents/prompts/03_planning/planning_todo_sync.ts
2874
+ var PLANNER_TODO_SYNC;
2875
+ var init_planning_todo_sync = __esm({
2876
+ "src/agents/prompts/03_planning/planning_todo_sync.ts"() {
2879
2877
  "use strict";
2880
2878
  init_shared();
2881
- COMMANDER_SYNC_HANDLING = `${PROMPT_TAGS.SYNC_ISSUE_HANDLING.open}
2882
- ## SYNC ISSUE HANDLING
2879
+ PLANNER_TODO_SYNC = `${PROMPT_TAGS.TODO_SYNC.open}
2880
+ ## TODO SYNC & DOCUMENT MAINTENANCE
2883
2881
 
2884
- When ${AGENT_NAMES.REVIEWER} reports sync issues, YOU must direct fixes.
2882
+ When ${AGENT_NAMES.COMMANDER} detects sync issues, you update TODO and maintain docs.
2885
2883
 
2886
- ### Step 1: Read Sync Issues
2884
+ ### Step 1: Read Current State
2887
2885
  \`\`\`bash
2888
- cat ${PATHS.SYNC_ISSUES}
2886
+ cat ${PATHS.STATUS} # Current progress %
2887
+ cat ${PATHS.SYNC_ISSUES} # Unresolved issues
2888
+ cat ${PATHS.TODO} # Task list
2889
2889
  \`\`\`
2890
2890
 
2891
- ### Step 2: Analyze Each Issue
2892
- For each ${ID_PREFIX.SYNC_ISSUE}N issue:
2893
- - Which files are involved?
2894
- - What's the root cause?
2895
- - What's the fix?
2896
-
2897
- ### Step 3: Instruct Planner
2898
- Delegate to ${AGENT_NAMES.PLANNER} with SPECIFIC instructions:
2899
-
2900
- \`\`\`
2901
- ${TOOL_NAMES.DELEGATE_TASK}(
2902
- task: "Update TODO for sync fix ${ID_PREFIX.SYNC_ISSUE}1",
2903
- agent: ${AGENT_NAMES.PLANNER},
2904
- instructions: "
2905
- Read ${PATHS.SYNC_ISSUES} for ${ID_PREFIX.SYNC_ISSUE}1.
2906
- Add FIX tasks for: src/auth/login.ts, src/api/users.ts.
2907
- Issue: Import mismatch - login.ts exports 'login' but users.ts imports 'authenticate'.
2908
- Fix: Update users.ts to import 'login' instead of 'authenticate'.
2909
- Update ${PATHS.WORK_LOG} file status.
2910
- "
2911
- )
2912
- \`\`\`
2913
-
2914
- ### Step 4: Instruct ${AGENT_NAMES.WORKER}s
2915
- After ${AGENT_NAMES.PLANNER} updates ${PATHS.TODO}, delegate fixes:
2916
-
2917
- \`\`\`
2918
- ${TOOL_NAMES.DELEGATE_TASK}(
2919
- task: "Fix ${ID_PREFIX.SYNC_ISSUE}1 in src/api/users.ts",
2920
- agent: ${AGENT_NAMES.WORKER},
2921
- file: "src/api/users.ts",
2922
- instructions: "
2923
- Read ${PATHS.SYNC_ISSUES} ${ID_PREFIX.SYNC_ISSUE}1.
2924
- Read ${PATHS.WORK_LOG} for context.
2925
- Fix: Change 'import { authenticate }' to 'import { login }'.
2926
- Run isolated test.
2927
- Update ${PATHS.WORK_LOG}.
2928
- ",
2929
- background: true
2930
- )
2931
- \`\`\`
2932
-
2933
- ### Step 5: Invoke ${AGENT_NAMES.REVIEWER} Again
2934
- After all fix ${AGENT_NAMES.WORKER}s complete:
2935
-
2936
- \`\`\`
2937
- ${TOOL_NAMES.DELEGATE_TASK}(
2938
- task: "Re-verify after ${ID_PREFIX.SYNC_ISSUE}1 fixes",
2939
- agent: ${AGENT_NAMES.REVIEWER},
2940
- instructions: "
2941
- Verify ${ID_PREFIX.SYNC_ISSUE}1 is resolved.
2942
- Run integration tests.
2943
- Clear resolved issues from ${PATHS.SYNC_ISSUES}.
2944
- Update ${PATHS.INTEGRATION_STATUS}.
2945
- "
2946
- )
2947
- \`\`\`
2948
-
2949
- ### Communication Flow
2950
- \`\`\`
2951
- ${AGENT_NAMES.COMMANDER}: "${AGENT_NAMES.PLANNER}, sync issue found. Update TODO"
2952
- \u2193
2953
- ${AGENT_NAMES.PLANNER}: (Add FIX task to ${PATHS.TODO}, update ${PATHS.WORK_LOG})
2954
- \u2193
2955
- ${AGENT_NAMES.COMMANDER}: "${AGENT_NAMES.WORKER}, fix this file like this" (Multiple ${AGENT_NAMES.WORKER}s in parallel)
2956
- \u2193
2957
- ${AGENT_NAMES.WORKER}s: (Fix each file + unit test + update ${PATHS.WORK_LOG})
2958
- \u2193
2959
- ${AGENT_NAMES.COMMANDER}: "${AGENT_NAMES.REVIEWER}, verify again"
2960
- \u2193
2961
- ${AGENT_NAMES.REVIEWER}: (Integration test + sync check + clear ${PATHS.SYNC_ISSUES})
2962
- \`\`\`
2963
-
2964
- ### CRITICAL:
2965
- - ALWAYS read ${PATHS.SYNC_ISSUES} at loop start
2966
- - NEVER skip Planner when fixing - TODO must be updated
2967
- - ALWAYS include specific instructions in ${TOOL_NAMES.DELEGATE_TASK}
2968
- - Workers need: file path + issue ID + exact fix instructions
2969
- ${PROMPT_TAGS.SYNC_ISSUE_HANDLING.close}`;
2970
- }
2971
- });
2972
-
2973
- // src/agents/prompts/verification/evidence.ts
2974
- var EVIDENCE_FORMAT;
2975
- var init_evidence = __esm({
2976
- "src/agents/prompts/verification/evidence.ts"() {
2977
- "use strict";
2978
- init_shared();
2979
- EVIDENCE_FORMAT = `${PROMPT_TAGS.OUTPUT_FORMAT.open}
2980
- VERIFICATION: T[N]
2981
-
2982
- ## Pass Example:
2983
- PASS
2984
- Evidence:
2985
- - lsp_diagnostics: clean
2986
- - build: pass
2987
- - tests: 15 passed
2988
- - docs match: .opencode/docs/api.md
2989
-
2990
- ## Fail Example:
2991
- FAIL
2992
- Issue: Tests failing - 2 failed, 13 passed
2993
- Fix: Check src/api.ts line 45, missing null check
2994
- Action: ${AGENT_NAMES.WORKER} to fix, then re-verify
2995
- ${PROMPT_TAGS.OUTPUT_FORMAT.close}`;
2996
- }
2997
- });
2998
-
2999
- // src/agents/prompts/verification/async-monitoring.ts
3000
- var REVIEWER_ASYNC_MONITORING;
3001
- var init_async_monitoring = __esm({
3002
- "src/agents/prompts/verification/async-monitoring.ts"() {
3003
- "use strict";
3004
- init_shared();
3005
- REVIEWER_ASYNC_MONITORING = `${PROMPT_TAGS.ASYNC_MONITORING.open}
3006
- ## ASYNC PARALLEL WORK MONITORING
3007
-
3008
- You monitor ${AGENT_NAMES.WORKER} sessions running in PARALLEL.
3009
- Do NOT block - check status asynchronously and wait for completion.
3010
-
3011
- ### Monitoring Loop
3012
- 1. Read ${PATHS.WORK_LOG} to check active sessions:
3013
- \`\`\`bash
3014
- cat ${PATHS.WORK_LOG}
3015
- \`\`\`
3016
-
3017
- 2. Identify completed units (marked [x] in Active Sessions)
3018
-
3019
- 3. For each completed unit:
3020
- - Verify unit test record exists in ${PATHS.UNIT_TESTS}/
3021
- - Check isolated test file was deleted
3022
- - Verify implementation quality
3023
-
3024
- 4. Wait for ALL parallel workers to complete before integration test
3025
-
3026
- ### Status Check Pattern
3027
- \`\`\`markdown
3028
- ## Current Status Check
3029
- - Total active workers: [N]
3030
- - Completed units: [list]
3031
- - Still running: [list]
3032
- - Ready for integration: [YES/NO]
3033
- \`\`\`
3034
-
3035
- ### Non-Blocking Wait Strategy
3036
- 1. If workers still running:
3037
- - Report current status
3038
- - DO NOT block or wait indefinitely
3039
- - Schedule next check (${AGENT_NAMES.COMMANDER} will re-invoke)
3040
-
3041
- 2. If all workers complete:
3042
- - Proceed to integration testing
3043
- - Update ${PATHS.INTEGRATION_STATUS}
3044
-
3045
- ### ${PATHS.WORK_LOG.split("/").pop()} Interpretation
2891
+ ### Step 2: Add Fix Tasks
2892
+ Add NEW subtasks for sync fixes:
3046
2893
  \`\`\`markdown
3047
- # Reading ${PATHS.WORK_LOG.split("/").pop()}:
3048
- - [ ] = Still in progress, DO NOT verify yet
3049
- - [x] = Unit complete, READY for verification
3050
- \`\`\`
3051
-
3052
- ### CRITICAL:
3053
- - NEVER verify a file before worker marks [x]
3054
- - NEVER block waiting for workers
3055
- - Always update ${PATHS.WORK_LOG} with your monitoring status
3056
-
3057
- ${PROMPT_TAGS.ASYNC_MONITORING.close}`;
3058
- }
3059
- });
3060
-
3061
- // src/agents/prompts/verification/reviewer-process.ts
3062
- var REVIEWER_VERIFICATION;
3063
- var init_reviewer_process = __esm({
3064
- "src/agents/prompts/verification/reviewer-process.ts"() {
3065
- "use strict";
3066
- init_shared();
3067
- REVIEWER_VERIFICATION = `${PROMPT_TAGS.VERIFICATION_PROCESS.open}
3068
- **ADAPTIVE VERIFICATION PROCESS**
3069
-
3070
-
3071
- ## Step 1: Read Project Context
3072
- \`\`\`bash
3073
- cat ${PATHS.CONTEXT} # Get build/test commands
2894
+ ### T3: Sync Fixes | parallel-group:3
2895
+ - [ ] S3.1: ${WORK_STATUS.ACTION.FIX} \`src/auth/login.ts\` | issue:${ID_PREFIX.SYNC_ISSUE}1
2896
+ - [ ] S3.2: ${WORK_STATUS.ACTION.FIX} \`src/api/users.ts\` | issue:${ID_PREFIX.SYNC_ISSUE}1
3074
2897
  \`\`\`
3075
- - Identify the BUILD command for this project
3076
- - Identify the TEST command for this project
3077
- - Note any project-specific verification requirements
3078
2898
 
3079
- ## Step 2: Static Analysis
3080
- ${TOOL_NAMES.LSP_DIAGNOSTICS} - Must show NO errors or warnings
2899
+ ---
3081
2900
 
3082
- ## Step 3: Build Verification
3083
- - Run the project's BUILD command (from ${PATHS.CONTEXT})
3084
- - Must pass without errors
3085
- - Watch for deprecation warnings
2901
+ ## \u{1F4CB} DOCUMENT MAINTENANCE RULES
3086
2902
 
3087
- ## Step 4: Test Verification
3088
- - Run the project's TEST command (from ${PATHS.CONTEXT})
3089
- - ALL tests must pass
3090
- - New code MUST have corresponding tests
2903
+ ### Keep ${PATHS.OPENCODE}/ Minimal:
2904
+ | File | Rule |
2905
+ |------|------|
2906
+ | ${PATHS.STATUS} | Overwrite each loop (no history) |
2907
+ | ${PATHS.TODO} | Keep only uncompleted tasks |
2908
+ | ${PATHS.SYNC_ISSUES} | Delete resolved issues immediately |
2909
+ | ${PATHS.WORK_LOG} | Archive completed, keep active only |
3091
2910
 
3092
- ## Step 5: Documentation Compliance
3093
- - Compare implementation with ${PATHS.DOCS}/
3094
- - API usage must match official documentation
3095
- - Check for breaking changes
2911
+ ### Summarize & Clean:
2912
+ - **Completed tasks**: Move to archive or delete
2913
+ - **Resolved issues**: DELETE from ${PATHS.SYNC_ISSUES.split("/").pop()}
2914
+ - **Old status**: Overwrite with current (no append)
2915
+ - **Long descriptions**: Summarize to 1-2 lines
3096
2916
 
3097
- ## Step 6: Pattern Verification
3098
- - Does the code follow EXISTING patterns in codebase?
3099
- - Naming conventions consistent?
3100
- - Error handling consistent?
2917
+ ### What to DELETE:
2918
+ - Resolved sync issues
2919
+ - Completed TODO items (mark [x] first, then remove in next cycle)
2920
+ - Old status updates
2921
+ - Verbose explanations
3101
2922
 
3102
- ## Step 7: Mark Complete (ONLY after ALL pass)
3103
- In ${PATHS.TODO}:
3104
- - [x] T1: [task] | verified | evidence: [build/test results]
2923
+ ### What to KEEP:
2924
+ - Active/pending tasks
2925
+ - Unresolved issues
2926
+ - Current phase info
2927
+ - Blockers
3105
2928
 
3106
- **CRITICAL**: NEVER mark [x] without running ACTUAL verification commands!
3107
- ${PROMPT_TAGS.VERIFICATION_PROCESS.close}`;
3108
- }
3109
- });
2929
+ ### CRITICAL:
2930
+ - ${AGENT_NAMES.COMMANDER} should NOT see old/resolved content
2931
+ - Only current state matters
3110
2932
 
3111
- // src/agents/prompts/verification/index.ts
3112
- var init_verification2 = __esm({
3113
- "src/agents/prompts/verification/index.ts"() {
3114
- "use strict";
3115
- init_process();
3116
- init_integration();
3117
- init_sync_check();
3118
- init_sync_handling();
3119
- init_evidence();
3120
- init_async_monitoring();
3121
- init_reviewer_process();
2933
+ - Less context = faster decisions
2934
+ ${PROMPT_TAGS.TODO_SYNC.close}`;
3122
2935
  }
3123
2936
  });
3124
2937
 
3125
- // src/agents/prompts/planning/todo-format.ts
2938
+ // src/agents/prompts/03_planning/planning_todo_format.ts
3126
2939
  var COMMANDER_TODO_FORMAT;
3127
- var init_todo_format = __esm({
3128
- "src/agents/prompts/planning/todo-format.ts"() {
2940
+ var init_planning_todo_format = __esm({
2941
+ "src/agents/prompts/03_planning/planning_todo_format.ts"() {
3129
2942
  "use strict";
3130
2943
  init_shared();
3131
2944
  COMMANDER_TODO_FORMAT = `${PROMPT_TAGS.TODO_FORMAT.open}
@@ -3171,10 +2984,17 @@ ${PROMPT_TAGS.TODO_FORMAT.close}`;
3171
2984
  }
3172
2985
  });
3173
2986
 
3174
- // src/agents/prompts/planning/todo-rules.ts
2987
+ // src/agents/prompts/03_planning/planning_core.ts
2988
+ var init_planning_core = __esm({
2989
+ "src/agents/prompts/03_planning/planning_core.ts"() {
2990
+ "use strict";
2991
+ }
2992
+ });
2993
+
2994
+ // src/agents/prompts/03_planning/planning_todo_rules.ts
3175
2995
  var TODO_RULES;
3176
- var init_todo_rules = __esm({
3177
- "src/agents/prompts/planning/todo-rules.ts"() {
2996
+ var init_planning_todo_rules = __esm({
2997
+ "src/agents/prompts/03_planning/planning_todo_rules.ts"() {
3178
2998
  "use strict";
3179
2999
  init_shared();
3180
3000
  TODO_RULES = `${PROMPT_TAGS.TODO_RULES.open}
@@ -3236,20 +3056,87 @@ ${PROMPT_TAGS.TODO_RULES.close}`;
3236
3056
  }
3237
3057
  });
3238
3058
 
3239
- // src/agents/prompts/planning/file-planning.ts
3240
- var PLANNER_FILE_PLANNING;
3241
- var init_file_planning = __esm({
3242
- "src/agents/prompts/planning/file-planning.ts"() {
3059
+ // src/agents/prompts/03_planning/planning_research.ts
3060
+ var PLANNER_RESEARCH;
3061
+ var init_planning_research = __esm({
3062
+ "src/agents/prompts/03_planning/planning_research.ts"() {
3243
3063
  "use strict";
3244
3064
  init_shared();
3245
- PLANNER_FILE_PLANNING = `${PROMPT_TAGS.FILE_LEVEL_PLANNING.open}
3246
- ## FILE-LEVEL PLANNING (MANDATORY)
3247
-
3248
- Before any work begins, you MUST identify ALL files:
3065
+ PLANNER_RESEARCH = `${PROMPT_TAGS.RESEARCH_WORKFLOW.open}
3066
+ \u{1F52C} ADAPTIVE RESEARCH WORKFLOW
3249
3067
 
3250
- ### Step 1: Analyze Requirements
3251
- - What needs to be built/changed?
3252
- - What existing files are affected?
3068
+ ## Available Research Tools
3069
+ | Tool | Usage | Purpose |
3070
+ |------|-------|---------|
3071
+ | ${TOOL_NAMES.WEBSEARCH} | websearch({ query: "..." }) | Search web for docs, tutorials |
3072
+ | ${TOOL_NAMES.WEBFETCH} | webfetch({ url: "..." }) | Fetch full content from URL |
3073
+ | ${TOOL_NAMES.CODESEARCH} | codesearch({ query: "..." }) | Search GitHub for examples |
3074
+ | ${TOOL_NAMES.CACHE_DOCS} | cache_docs({ url, topic }) | Save docs to ${PATHS.DOCS}/ |
3075
+
3076
+ ## Step 1: Identify What to Research
3077
+ - What technology/library/API is needed?
3078
+ - What version is the project using? (check ${PATHS.CONTEXT})
3079
+ - What specific syntax/pattern is unclear?
3080
+
3081
+ ## Step 2: Prioritize Sources (in order)
3082
+ 1. **Project's own docs** - Check ${PATHS.DOCS}/ first
3083
+ 2. **Official documentation** - [framework].dev, docs.[library].com
3084
+ 3. **GitHub repo** - README, examples, source code
3085
+ 4. **Package registry** - npm, PyPI, crates.io
3086
+ 5. **Community** - Stack Overflow, Discord (lowest priority)
3087
+
3088
+ ## Step 3: Search Strategy
3089
+ \`\`\`
3090
+ ${TOOL_NAMES.WEBSEARCH} "[topic] official documentation [detected version]"
3091
+ ${TOOL_NAMES.WEBSEARCH} "[topic] [language] example"
3092
+ ${TOOL_NAMES.WEBFETCH} "[result URL from search]"
3093
+ ${TOOL_NAMES.CACHE_DOCS} "{ url, topic }"
3094
+ \`\`\`
3095
+
3096
+ ## Step 4: Validate & Extract
3097
+ - Is this the CORRECT version for this project?
3098
+ - Extract EXACT syntax (never paraphrase)
3099
+ - Note any version-specific differences
3100
+
3101
+ ## Step 5: Cache Research
3102
+ Save to ${PATHS.DOCS}/[topic].md:
3103
+
3104
+ \`\`\`markdown
3105
+ # Research: [topic]
3106
+ Date: [timestamp]
3107
+ Source: [official URL]
3108
+ Confidence: ${WORK_STATUS.CONFIDENCE.HIGH}/${WORK_STATUS.CONFIDENCE.MEDIUM}/${WORK_STATUS.CONFIDENCE.LOW}
3109
+ Version: [detected version from project]
3110
+
3111
+ ## Context
3112
+ Why this is needed: [brief explanation]
3113
+
3114
+ ## Exact Syntax
3115
+ \`\`\`[detected language]
3116
+ [code from official docs - VERBATIM]
3117
+ \`\`\`
3118
+
3119
+ ## Usage Notes
3120
+ - [any gotchas or important details]
3121
+ \`\`\`
3122
+ ${PROMPT_TAGS.RESEARCH_WORKFLOW.close}`;
3123
+ }
3124
+ });
3125
+
3126
+ // src/agents/prompts/03_planning/planning_file_planning.ts
3127
+ var PLANNER_FILE_PLANNING;
3128
+ var init_planning_file_planning = __esm({
3129
+ "src/agents/prompts/03_planning/planning_file_planning.ts"() {
3130
+ "use strict";
3131
+ init_shared();
3132
+ PLANNER_FILE_PLANNING = `${PROMPT_TAGS.FILE_LEVEL_PLANNING.open}
3133
+ ## FILE-LEVEL PLANNING (MANDATORY)
3134
+
3135
+ Before any work begins, you MUST identify ALL files:
3136
+
3137
+ ### Step 1: Analyze Requirements
3138
+ - What needs to be built/changed?
3139
+ - What existing files are affected?
3253
3140
 
3254
3141
  ### Step 2: Create File Manifest
3255
3142
  Write to ${PATHS.TODO}:
@@ -3316,96 +3203,79 @@ ${PROMPT_TAGS.FILE_LEVEL_PLANNING.close}`;
3316
3203
  }
3317
3204
  });
3318
3205
 
3319
- // src/agents/prompts/planning/decomposition.ts
3320
- var TASK_DECOMPOSITION;
3321
- var init_decomposition = __esm({
3322
- "src/agents/prompts/planning/decomposition.ts"() {
3206
+ // src/agents/prompts/03_planning/agents/planning_commander.ts
3207
+ var init_planning_commander = __esm({
3208
+ "src/agents/prompts/03_planning/agents/planning_commander.ts"() {
3323
3209
  "use strict";
3324
- init_shared();
3325
- TASK_DECOMPOSITION = wrapTag(PROMPT_TAGS.DECOMPOSITION_RULES, `
3326
- ## Task Decomposition Rules
3327
-
3328
- When a task is too large or complex:
3329
- 1. **Break it down** into atomic steps (max 1 file or 1 logical unit per step).
3330
- 2. **Update TODO**: Replace the large task with subtasks T[N.1], T[N.2], etc.
3331
- 3. **Verify Atomic Success**: Each subtask must be verifiable independently (L2+).
3332
-
3333
- If stuck:
3334
- - Do not retry the same failing action more than twice.
3335
- - Decompose the problem into smaller investigation steps.
3336
- - Create a specific "Research" task to find the root cause.`);
3337
3210
  }
3338
3211
  });
3339
3212
 
3340
- // src/agents/prompts/planning/todo-sync.ts
3341
- var PLANNER_TODO_SYNC;
3342
- var init_todo_sync = __esm({
3343
- "src/agents/prompts/planning/todo-sync.ts"() {
3213
+ // src/agents/prompts/03_planning/agents/planning_planner.ts
3214
+ var PLANNER_TODO_FORMAT;
3215
+ var init_planning_planner = __esm({
3216
+ "src/agents/prompts/03_planning/agents/planning_planner.ts"() {
3344
3217
  "use strict";
3345
3218
  init_shared();
3346
- PLANNER_TODO_SYNC = `${PROMPT_TAGS.TODO_SYNC.open}
3347
- ## TODO SYNC & DOCUMENT MAINTENANCE
3219
+ PLANNER_TODO_FORMAT = `${PROMPT_TAGS.PLANNING_FORMAT.open}
3220
+ OUTPUT TO: ${PATHS.TODO}
3348
3221
 
3349
- When ${AGENT_NAMES.COMMANDER} detects sync issues, you update TODO and maintain docs.
3222
+ ## Hierarchical Task Decomposition
3223
+ Break down the complex request into as many levels as needed to achieve atomic work units.
3224
+ Each level must be clearly indented and uniquely numbered.
3350
3225
 
3351
- ### Step 1: Read Current State
3352
- \`\`\`bash
3353
- cat ${PATHS.STATUS} # Current progress %
3354
- cat ${PATHS.SYNC_ISSUES} # Unresolved issues
3355
- cat ${PATHS.TODO} # Task list
3356
- \`\`\`
3226
+ ### Level N - Parent Task/Epic/Story
3227
+ - Represents a high-level goal or a logical grouping of work.
3228
+ - Status: ${WORK_STATUS.TODO_STATUS.PENDING} | [dependencies]
3229
+ - **COMPLETION RULE**: Satisfied only when ALL child tasks are marked as [x].
3357
3230
 
3358
- ### Step 2: Add Fix Tasks
3359
- Add NEW subtasks for sync fixes:
3360
- \`\`\`markdown
3361
- ### T3: Sync Fixes | parallel-group:3
3362
- - [ ] S3.1: ${WORK_STATUS.ACTION.FIX} \`src/auth/login.ts\` | issue:${ID_PREFIX.SYNC_ISSUE}1
3363
- - [ ] S3.2: ${WORK_STATUS.ACTION.FIX} \`src/api/users.ts\` | issue:${ID_PREFIX.SYNC_ISSUE}1
3364
- \`\`\`
3231
+ ### Level N+1 - Actionable Subtasks
3232
+ - Represents specific, atomic actions (15-60 min).
3233
+ - Format: \`- [ ] ID: [description] | agent:[Name] | [metadata]\`
3234
+ - Metadata options: \`depends:[ID]\`, \`file:[path]\`, \`size:[XS/S/M/L]\`
3365
3235
 
3366
- ---
3236
+ ## Template Example
3237
+ \`\`\`markdown
3238
+ # Mission: [goal]
3367
3239
 
3368
- ## \u{1F4CB} DOCUMENT MAINTENANCE RULES
3240
+ ## Project Context
3241
+ ...
3369
3242
 
3370
- ### Keep ${PATHS.OPENCODE}/ Minimal:
3371
- | File | Rule |
3372
- |------|------|
3373
- | ${PATHS.STATUS} | Overwrite each loop (no history) |
3374
- | ${PATHS.TODO} | Keep only uncompleted tasks |
3375
- | ${PATHS.SYNC_ISSUES} | Delete resolved issues immediately |
3376
- | ${PATHS.WORK_LOG} | Archive completed, keep active only |
3243
+ ## G1: [The Goal] | status: ${WORK_STATUS.TODO_STATUS.PENDING}
3244
+ ### P1.1: [Feature Project] | agent:${AGENT_NAMES.PLANNER}
3245
+ - [ ] T1.1.1: [Atomic Research] | size:S
3246
+ - [ ] T1.1.2: [Detailed Design] | size:M
3377
3247
 
3378
- ### Summarize & Clean:
3379
- - **Completed tasks**: Move to archive or delete
3380
- - **Resolved issues**: DELETE from ${PATHS.SYNC_ISSUES.split("/").pop()}
3381
- - **Old status**: Overwrite with current (no append)
3382
- - **Long descriptions**: Summarize to 1-2 lines
3248
+ ### P1.2: [Implementation Block] | agent:${AGENT_NAMES.WORKER} | depends:P1.1
3249
+ #### P1.2.1: [Sub-module A]
3250
+ - [ ] T1.2.1.1: [Draft code] | file:src/a.ts | size:M
3251
+ - [ ] T1.2.1.2: [Tests for A] | file:tests/a.test.ts | size:S
3383
3252
 
3384
- ### What to DELETE:
3385
- - Resolved sync issues
3386
- - Completed TODO items (mark [x] first, then remove in next cycle)
3387
- - Old status updates
3388
- - Verbose explanations
3253
+ #### P1.2.2: [Sub-module B] | depends:P1.2.1
3254
+ - [ ] T1.2.2.1: [Draft code] | file:src/b.ts | size:M
3255
+ - [ ] T1.2.2.2: [Tests for B] | file:tests/b.test.ts | size:S
3389
3256
 
3390
- ### What to KEEP:
3391
- - Active/pending tasks
3392
- - Unresolved issues
3393
- - Current phase info
3394
- - Blockers
3257
+ ### P1.3: [Final Quality Pass] | agent:${AGENT_NAMES.REVIEWER} | depends:P1.2
3258
+ - [ ] T1.3.1: [Visual E2E] | size:M
3259
+ - [ ] T1.3.2: [Release Build] | size:S
3260
+ \`\`\`
3395
3261
 
3396
- ### CRITICAL:
3397
- - ${AGENT_NAMES.COMMANDER} should NOT see old/resolved content
3398
- - Only current state matters
3262
+ ## Planning Rules
3263
+ - **No Limit on Depth**: If a task is too big for one person or session, break it down further.
3264
+ - **Atomic Execution**: Only the leaf nodes (the innermost tasks with checkboxes) are directly executed.
3265
+ - **Parent Propagation**: When you find all children of a parent header are checked, update the parent status to ${WORK_STATUS.TODO_STATUS.COMPLETE}.
3266
+ - **Max Parallelism**: Identify tasks that don't depend on each other and mark them as such to allow multiple Workers to run in parallel.
3267
+ - Size: ${WORK_STATUS.TASK_SIZE.XS}(<5min), ${WORK_STATUS.TASK_SIZE.S}(5-15min), ${WORK_STATUS.TASK_SIZE.M}(15-30min), ${WORK_STATUS.TASK_SIZE.L}(30-60min)
3268
+ - If any task is L or larger, it MUST be broken into subtasks.
3399
3269
 
3400
- - Less context = faster decisions
3401
- ${PROMPT_TAGS.TODO_SYNC.close}`;
3270
+ ALL items MUST start with [ ] (unchecked) unless already finished.
3271
+ ${PROMPT_TAGS.PLANNING_FORMAT.close}`;
3402
3272
  }
3403
3273
  });
3404
3274
 
3405
- // src/agents/prompts/planning/reviewer-todo-update.ts
3275
+ // src/agents/prompts/03_planning/agents/planning_reviewer.ts
3406
3276
  var REVIEWER_TODO_UPDATE;
3407
- var init_reviewer_todo_update = __esm({
3408
- "src/agents/prompts/planning/reviewer-todo-update.ts"() {
3277
+ var init_planning_reviewer = __esm({
3278
+ "src/agents/prompts/03_planning/agents/planning_reviewer.ts"() {
3409
3279
  "use strict";
3410
3280
  init_shared();
3411
3281
  REVIEWER_TODO_UPDATE = `${PROMPT_TAGS.TODO_MANAGEMENT.open}
@@ -3452,185 +3322,83 @@ ${PROMPT_TAGS.TODO_MANAGEMENT.close}`;
3452
3322
  }
3453
3323
  });
3454
3324
 
3455
- // src/agents/prompts/planning/research.ts
3456
- var PLANNER_RESEARCH;
3457
- var init_research = __esm({
3458
- "src/agents/prompts/planning/research.ts"() {
3325
+ // src/agents/prompts/03_planning/index.ts
3326
+ var init_planning = __esm({
3327
+ "src/agents/prompts/03_planning/index.ts"() {
3459
3328
  "use strict";
3460
- init_shared();
3461
- PLANNER_RESEARCH = `${PROMPT_TAGS.RESEARCH_WORKFLOW.open}
3462
- \u{1F52C} ADAPTIVE RESEARCH WORKFLOW
3463
-
3464
- ## Available Research Tools
3465
- | Tool | Usage | Purpose |
3466
- |------|-------|---------|
3467
- | ${TOOL_NAMES.WEBSEARCH} | websearch({ query: "..." }) | Search web for docs, tutorials |
3468
- | ${TOOL_NAMES.WEBFETCH} | webfetch({ url: "..." }) | Fetch full content from URL |
3469
- | ${TOOL_NAMES.CODESEARCH} | codesearch({ query: "..." }) | Search GitHub for examples |
3470
- | ${TOOL_NAMES.CACHE_DOCS} | cache_docs({ url, topic }) | Save docs to ${PATHS.DOCS}/ |
3329
+ init_planning_decomposition();
3330
+ init_planning_parallel();
3331
+ init_planning_todo_sync();
3332
+ init_planning_todo_format();
3333
+ init_planning_core();
3334
+ init_planning_todo_rules();
3335
+ init_planning_research();
3336
+ init_planning_file_planning();
3337
+ init_planning_commander();
3338
+ init_planning_planner();
3339
+ init_planning_reviewer();
3340
+ }
3341
+ });
3471
3342
 
3472
- ## Step 1: Identify What to Research
3473
- - What technology/library/API is needed?
3474
- - What version is the project using? (check ${PATHS.CONTEXT})
3475
- - What specific syntax/pattern is unclear?
3343
+ // src/agents/prompts/04_execution/execution_quality.ts
3344
+ var WORKER_QUALITY;
3345
+ var init_execution_quality = __esm({
3346
+ "src/agents/prompts/04_execution/execution_quality.ts"() {
3347
+ "use strict";
3348
+ init_shared();
3349
+ WORKER_QUALITY = `${PROMPT_TAGS.QUALITY_CHECKLIST.open}
3350
+ \u{1F4CB} QUALITY CHECKLIST (Adaptive)
3476
3351
 
3477
- ## Step 2: Prioritize Sources (in order)
3478
- 1. **Project's own docs** - Check ${PATHS.DOCS}/ first
3479
- 2. **Official documentation** - [framework].dev, docs.[library].com
3480
- 3. **GitHub repo** - README, examples, source code
3481
- 4. **Package registry** - npm, PyPI, crates.io
3482
- 5. **Community** - Stack Overflow, Discord (lowest priority)
3352
+ Before reporting complete, verify against PROJECT-SPECIFIC standards:
3483
3353
 
3484
- ## Step 3: Search Strategy
3485
- \`\`\`
3486
- ${TOOL_NAMES.WEBSEARCH} "[topic] official documentation [detected version]"
3487
- ${TOOL_NAMES.WEBSEARCH} "[topic] [language] example"
3488
- ${TOOL_NAMES.WEBFETCH} "[result URL from search]"
3489
- ${TOOL_NAMES.CACHE_DOCS} "{ url, topic }"
3490
- \`\`\`
3354
+ ## 1. Static Analysis
3355
+ - lsp_diagnostics shows NO errors
3356
+ - Follow linting rules discovered in project (if any)
3491
3357
 
3492
- ## Step 4: Validate & Extract
3493
- - Is this the CORRECT version for this project?
3494
- - Extract EXACT syntax (never paraphrase)
3495
- - Note any version-specific differences
3358
+ ## 2. Build Verification
3359
+ - Run the BUILD command from ${PATHS.CONTEXT}
3360
+ - Must complete without errors
3496
3361
 
3497
- ## Step 5: Cache Research
3498
- Save to ${PATHS.DOCS}/[topic].md:
3362
+ ## 3. Test Verification
3363
+ - Tests written for new/changed code
3364
+ - Run the TEST command from ${PATHS.CONTEXT}
3365
+ - All tests must pass
3499
3366
 
3500
- \`\`\`markdown
3501
- # Research: [topic]
3502
- Date: [timestamp]
3503
- Source: [official URL]
3504
- Confidence: ${WORK_STATUS.CONFIDENCE.HIGH}/${WORK_STATUS.CONFIDENCE.MEDIUM}/${WORK_STATUS.CONFIDENCE.LOW}
3505
- Version: [detected version from project]
3367
+ ## 4. Code Quality (OBSERVE existing patterns)
3368
+ - Match naming conventions found in codebase
3369
+ - Match error handling patterns found in codebase
3370
+ - No debug logging left (console.log, print, logger.debug, etc.)
3371
+ - No hardcoded values that should be config
3506
3372
 
3507
- ## Context
3508
- Why this is needed: [brief explanation]
3373
+ ## 5. Documentation Compliance
3374
+ - Implementation matches ${PATHS.DOCS}/ patterns
3375
+ - API usage matches official documentation
3509
3376
 
3510
- ## Exact Syntax
3511
- \`\`\`[detected language]
3512
- [code from official docs - VERBATIM]
3377
+ ## OUTPUT FORMAT:
3513
3378
  \`\`\`
3514
-
3515
- ## Usage Notes
3516
- - [any gotchas or important details]
3379
+ TASK: T[N]
3380
+ CHANGED: [files] ([lines])
3381
+ BUILD: [command used] \u2192 [result]
3382
+ TEST: [command used] \u2192 [result]
3383
+ PATTERNS_FOLLOWED: [list observed conventions]
3384
+ DOCS_USED: ${PATHS.DOCS}/[file]
3385
+ Ready for ${AGENT_NAMES.REVIEWER} verification
3517
3386
  \`\`\`
3518
- ${PROMPT_TAGS.RESEARCH_WORKFLOW.close}`;
3387
+ ${PROMPT_TAGS.QUALITY_CHECKLIST.close}`;
3519
3388
  }
3520
3389
  });
3521
3390
 
3522
- // src/agents/prompts/planning/planner-todo.ts
3523
- var PLANNER_TODO_FORMAT;
3524
- var init_planner_todo = __esm({
3525
- "src/agents/prompts/planning/planner-todo.ts"() {
3391
+ // src/agents/prompts/04_execution/execution_error_handling.ts
3392
+ var init_execution_error_handling = __esm({
3393
+ "src/agents/prompts/04_execution/execution_error_handling.ts"() {
3526
3394
  "use strict";
3527
- init_shared();
3528
- PLANNER_TODO_FORMAT = `${PROMPT_TAGS.PLANNING_FORMAT.open}
3529
- OUTPUT TO: ${PATHS.TODO}
3530
-
3531
- ## Hierarchical Task Decomposition
3532
- Break down the complex request into as many levels as needed to achieve atomic work units.
3533
- Each level must be clearly indented and uniquely numbered.
3534
-
3535
- ### Level N - Parent Task/Epic/Story
3536
- - Represents a high-level goal or a logical grouping of work.
3537
- - Status: ${WORK_STATUS.TODO_STATUS.PENDING} | [dependencies]
3538
- - **COMPLETION RULE**: Satisfied only when ALL child tasks are marked as [x].
3539
-
3540
- ### Level N+1 - Actionable Subtasks
3541
- - Represents specific, atomic actions (15-60 min).
3542
- - Format: \`- [ ] ID: [description] | agent:[Name] | [metadata]\`
3543
- - Metadata options: \`depends:[ID]\`, \`file:[path]\`, \`size:[XS/S/M/L]\`
3544
-
3545
- ## Template Example
3546
- \`\`\`markdown
3547
- # Mission: [goal]
3548
-
3549
- ## Project Context
3550
- ...
3551
-
3552
- ## G1: [The Goal] | status: ${WORK_STATUS.TODO_STATUS.PENDING}
3553
- ### P1.1: [Feature Project] | agent:${AGENT_NAMES.PLANNER}
3554
- - [ ] T1.1.1: [Atomic Research] | size:S
3555
- - [ ] T1.1.2: [Detailed Design] | size:M
3556
-
3557
- ### P1.2: [Implementation Block] | agent:${AGENT_NAMES.WORKER} | depends:P1.1
3558
- #### P1.2.1: [Sub-module A]
3559
- - [ ] T1.2.1.1: [Draft code] | file:src/a.ts | size:M
3560
- - [ ] T1.2.1.2: [Tests for A] | file:tests/a.test.ts | size:S
3561
-
3562
- #### P1.2.2: [Sub-module B] | depends:P1.2.1
3563
- - [ ] T1.2.2.1: [Draft code] | file:src/b.ts | size:M
3564
- - [ ] T1.2.2.2: [Tests for B] | file:tests/b.test.ts | size:S
3565
-
3566
- ### P1.3: [Final Quality Pass] | agent:${AGENT_NAMES.REVIEWER} | depends:P1.2
3567
- - [ ] T1.3.1: [Visual E2E] | size:M
3568
- - [ ] T1.3.2: [Release Build] | size:S
3569
- \`\`\`
3570
-
3571
- ## Planning Rules
3572
- - **No Limit on Depth**: If a task is too big for one person or session, break it down further.
3573
- - **Atomic Execution**: Only the leaf nodes (the innermost tasks with checkboxes) are directly executed.
3574
- - **Parent Propagation**: When you find all children of a parent header are checked, update the parent status to ${WORK_STATUS.TODO_STATUS.COMPLETE}.
3575
- - **Max Parallelism**: Identify tasks that don't depend on each other and mark them as such to allow multiple Workers to run in parallel.
3576
- - Size: ${WORK_STATUS.TASK_SIZE.XS}(<5min), ${WORK_STATUS.TASK_SIZE.S}(5-15min), ${WORK_STATUS.TASK_SIZE.M}(15-30min), ${WORK_STATUS.TASK_SIZE.L}(30-60min)
3577
- - If any task is L or larger, it MUST be broken into subtasks.
3578
-
3579
- ALL items MUST start with [ ] (unchecked) unless already finished.
3580
- ${PROMPT_TAGS.PLANNING_FORMAT.close}`;
3581
- }
3582
- });
3583
-
3584
- // src/agents/prompts/planning/index.ts
3585
- var init_planning = __esm({
3586
- "src/agents/prompts/planning/index.ts"() {
3587
- "use strict";
3588
- init_todo_format();
3589
- init_todo_rules();
3590
- init_file_planning();
3591
- init_decomposition();
3592
- init_todo_sync();
3593
- init_reviewer_todo_update();
3594
- init_research();
3595
- init_planner_todo();
3596
- }
3597
- });
3598
-
3599
- // src/agents/prompts/execution/parallel.ts
3600
- var COMMANDER_PARALLEL;
3601
- var init_parallel4 = __esm({
3602
- "src/agents/prompts/execution/parallel.ts"() {
3603
- "use strict";
3604
- init_shared();
3605
- COMMANDER_PARALLEL = `${PROMPT_TAGS.PARALLEL_EXECUTION.open}
3606
- YOUR 3 SUPERPOWERS - USE AGGRESSIVELY:
3607
-
3608
- 1. PARALLEL AGENTS
3609
- \`\`\`
3610
- ${TOOL_NAMES.DELEGATE_TASK}({ ${PARALLEL_PARAMS.AGENT}: "${AGENT_NAMES.PLANNER}", ${PARALLEL_PARAMS.PROMPT}: "Research X", ${PARALLEL_PARAMS.BACKGROUND}: true })
3611
- ${TOOL_NAMES.DELEGATE_TASK}({ ${PARALLEL_PARAMS.AGENT}: "${AGENT_NAMES.PLANNER}", ${PARALLEL_PARAMS.PROMPT}: "Research Y", ${PARALLEL_PARAMS.BACKGROUND}: true })
3612
- // 2x faster!
3613
- \`\`\`
3614
-
3615
- 2. BACKGROUND COMMANDS
3616
- \`\`\`
3617
- ${TOOL_NAMES.RUN_BACKGROUND}({ command: "npm run build" })
3618
- // ...continue other work...
3619
- ${TOOL_NAMES.CHECK_BACKGROUND}({ ${PARALLEL_PARAMS.TASK_ID}: "xxx" })
3620
- \`\`\`
3621
-
3622
- 3. SESSION RESUME
3623
- \`\`\`
3624
- ${TOOL_NAMES.DELEGATE_TASK}({ ${PARALLEL_PARAMS.PROMPT}: "Continue work", ${PARALLEL_PARAMS.RESUME}: "session_abc" })
3625
- \`\`\`
3626
- ${PROMPT_TAGS.PARALLEL_EXECUTION.close}`;
3627
3395
  }
3628
3396
  });
3629
3397
 
3630
- // src/agents/prompts/execution/delegation.ts
3398
+ // src/agents/prompts/04_execution/execution_delegation.ts
3631
3399
  var DELEGATION_RULES;
3632
- var init_delegation = __esm({
3633
- "src/agents/prompts/execution/delegation.ts"() {
3400
+ var init_execution_delegation = __esm({
3401
+ "src/agents/prompts/04_execution/execution_delegation.ts"() {
3634
3402
  "use strict";
3635
3403
  init_shared();
3636
3404
  DELEGATION_RULES = `${PROMPT_TAGS.AGENTS.open}
@@ -3644,10 +3412,10 @@ ${PROMPT_TAGS.AGENTS.close}`;
3644
3412
  }
3645
3413
  });
3646
3414
 
3647
- // src/agents/prompts/execution/file-assignment.ts
3415
+ // src/agents/prompts/04_execution/execution_file_assignment.ts
3648
3416
  var WORKER_FILE_ASSIGNMENT;
3649
- var init_file_assignment = __esm({
3650
- "src/agents/prompts/execution/file-assignment.ts"() {
3417
+ var init_execution_file_assignment = __esm({
3418
+ "src/agents/prompts/04_execution/execution_file_assignment.ts"() {
3651
3419
  "use strict";
3652
3420
  init_shared();
3653
3421
  WORKER_FILE_ASSIGNMENT = `${PROMPT_TAGS.FILE_ASSIGNMENT.open}
@@ -3730,10 +3498,10 @@ ${PROMPT_TAGS.FILE_ASSIGNMENT.close}`;
3730
3498
  }
3731
3499
  });
3732
3500
 
3733
- // src/agents/prompts/execution/workflow.ts
3501
+ // src/agents/prompts/04_execution/execution_workflow.ts
3734
3502
  var WORKER_WORKFLOW;
3735
- var init_workflow = __esm({
3736
- "src/agents/prompts/execution/workflow.ts"() {
3503
+ var init_execution_workflow = __esm({
3504
+ "src/agents/prompts/04_execution/execution_workflow.ts"() {
3737
3505
  "use strict";
3738
3506
  init_shared();
3739
3507
  WORKER_WORKFLOW = `${PROMPT_TAGS.WORKFLOW.open}
@@ -3777,28 +3545,64 @@ ${PROMPT_TAGS.WORKFLOW.close}`;
3777
3545
  }
3778
3546
  });
3779
3547
 
3780
- // src/agents/prompts/execution/hyper-parallel.ts
3781
- var HYPER_PARALLEL_ENFORCEMENT;
3782
- var init_hyper_parallel = __esm({
3783
- "src/agents/prompts/execution/hyper-parallel.ts"() {
3548
+ // src/agents/prompts/04_execution/execution_core.ts
3549
+ var init_execution_core = __esm({
3550
+ "src/agents/prompts/04_execution/execution_core.ts"() {
3551
+ "use strict";
3552
+ }
3553
+ });
3554
+
3555
+ // src/agents/prompts/04_execution/execution_strategy.ts
3556
+ var COMMANDER_EXECUTION;
3557
+ var init_execution_strategy = __esm({
3558
+ "src/agents/prompts/04_execution/execution_strategy.ts"() {
3784
3559
  "use strict";
3785
3560
  init_shared();
3786
- HYPER_PARALLEL_ENFORCEMENT = `${PROMPT_TAGS.QUALITY_CHECKLIST.open}
3787
- \u{1F680} HYPER-PARALLEL COGNITIVE ARCHITECTURE (HPFA)
3561
+ COMMANDER_EXECUTION = `${PROMPT_TAGS.EXECUTION_STRATEGY.open}
3562
+ ## ${PHASES.PHASE_0.ID}: ${PHASES.PHASE_0.NAME} (Direct Discovery)
3563
+ ${PHASE_0_DIRECT_DISCOVERY}
3788
3564
 
3789
- To achieve maximum velocity, you MUST leverage these advanced parallel execution patterns:
3565
+ ## ${PHASES.PHASE_1.ID}: ${PHASES.PHASE_1.NAME} (Mandatory - Never Skip!)
3566
+ **THINK FIRST**: As ${AGENT_NAMES.COMMANDER}, think about ORCHESTRATION and synthesis before action.
3790
3567
 
3791
- ${HPFA_RULES}
3568
+ ${PHASE_1_THINK_ANALYSIS}
3792
3569
 
3793
- [CRITICAL]: Sequential execution when parallel is possible is a mission failure.
3794
- ${PROMPT_TAGS.QUALITY_CHECKLIST.close}`;
3570
+ **ANTI-PATTERNS**: Sequential execution when parallel is possible. Doing work yourself instead of delegating. Starting without clear decomposition or intellectual synthesis.
3571
+
3572
+ ## ${PHASES.PHASE_2.ID}: ${PHASES.PHASE_2.NAME}
3573
+ | Type | Signal | Approach |
3574
+ |------|--------|----------|
3575
+ | ${WORK_STATUS.TRIAGE.TYPE.SIMPLE} | ${WORK_STATUS.TRIAGE.SIGNAL.ONE_FILE} | ${WORK_STATUS.TRIAGE.APPROACH.DIRECT} |
3576
+ | ${WORK_STATUS.TRIAGE.TYPE.MEDIUM} | ${WORK_STATUS.TRIAGE.SIGNAL.MULTI_FILE} | ${WORK_STATUS.TRIAGE.APPROACH.PLAN_EXECUTE_VERIFY} |
3577
+ | ${WORK_STATUS.TRIAGE.TYPE.COMPLEX} | ${WORK_STATUS.TRIAGE.SIGNAL.LARGE_SCOPE} | ${WORK_STATUS.TRIAGE.APPROACH.RESEARCH_PLAN_PARALLEL} |
3578
+
3579
+ ## ${PHASES.PHASE_3.ID}: ${PHASES.PHASE_3.NAME} (for ${WORK_STATUS.TRIAGE.TYPE.MEDIUM}/${WORK_STATUS.TRIAGE.TYPE.COMPLEX})
3580
+ ${AGENT_NAMES.PLANNER} creates ${PATHS.TODO} with parallel groups
3581
+
3582
+ ## ${PHASES.PHASE_4.ID}: ${PHASES.PHASE_4.NAME}
3583
+ 1. LAUNCH all independent tasks simultaneously (background=true)
3584
+ 2. MONITOR with ${TOOL_NAMES.LIST_TASKS}
3585
+ 3. COLLECT results with ${TOOL_NAMES.GET_TASK_RESULT}
3586
+ 4. CONTINUE with dependent tasks
3587
+ 5. REPEAT until all [ ] become [x]
3588
+
3589
+ ## ${PHASES.PHASE_5.ID}: ${PHASES.PHASE_5.NAME}
3590
+ ${PHASE_5_MSVP}
3591
+
3592
+ ## ${PHASES.PHASE_6.ID}: ${PHASES.PHASE_6.NAME}
3593
+ When ALL work is complete:
3594
+ 1. Verify ALL TODO items in ${PATHS.TODO} are marked [x].
3595
+ 2. Delegate a final "${VERIFICATION_SIGNALS.FINAL_PASS}" task to ${AGENT_NAMES.REVIEWER}.
3596
+ 3. Conclude the mission ONLY after ${AGENT_NAMES.REVIEWER} confirms zero regressions and all tests pass.
3597
+ 4. If failures are reported, address them immediately and repeat verification.
3598
+ ${PROMPT_TAGS.EXECUTION_STRATEGY.close}`;
3795
3599
  }
3796
3600
  });
3797
3601
 
3798
- // src/agents/prompts/execution/tdd.ts
3602
+ // src/agents/prompts/04_execution/execution_tdd.ts
3799
3603
  var WORKER_TDD_WORKFLOW;
3800
- var init_tdd = __esm({
3801
- "src/agents/prompts/execution/tdd.ts"() {
3604
+ var init_execution_tdd = __esm({
3605
+ "src/agents/prompts/04_execution/execution_tdd.ts"() {
3802
3606
  "use strict";
3803
3607
  init_shared();
3804
3608
  WORKER_TDD_WORKFLOW = `${PROMPT_TAGS.TDD_WORKFLOW.open}
@@ -3875,10 +3679,10 @@ ${PROMPT_TAGS.TDD_WORKFLOW.close}`;
3875
3679
  }
3876
3680
  });
3877
3681
 
3878
- // src/agents/prompts/execution/isolation.ts
3682
+ // src/agents/prompts/04_execution/execution_isolation.ts
3879
3683
  var WORKER_ISOLATION_TESTING;
3880
- var init_isolation = __esm({
3881
- "src/agents/prompts/execution/isolation.ts"() {
3684
+ var init_execution_isolation = __esm({
3685
+ "src/agents/prompts/04_execution/execution_isolation.ts"() {
3882
3686
  "use strict";
3883
3687
  init_shared();
3884
3688
  WORKER_ISOLATION_TESTING = `${PROMPT_TAGS.ISOLATION_TESTING.open}
@@ -3968,474 +3772,709 @@ ${PROMPT_TAGS.ISOLATION_TESTING.close}`;
3968
3772
  }
3969
3773
  });
3970
3774
 
3971
- // src/agents/prompts/execution/strategy.ts
3972
- var COMMANDER_EXECUTION;
3973
- var init_strategy = __esm({
3974
- "src/agents/prompts/execution/strategy.ts"() {
3775
+ // src/agents/prompts/04_execution/execution_hyper_parallel.ts
3776
+ var HYPER_PARALLEL_ENFORCEMENT;
3777
+ var init_execution_hyper_parallel = __esm({
3778
+ "src/agents/prompts/04_execution/execution_hyper_parallel.ts"() {
3975
3779
  "use strict";
3976
3780
  init_shared();
3977
- COMMANDER_EXECUTION = `${PROMPT_TAGS.EXECUTION_STRATEGY.open}
3978
- ## ${PHASES.PHASE_0.ID}: ${PHASES.PHASE_0.NAME} (Direct Discovery)
3979
- ${PHASE_0_DIRECT_DISCOVERY}
3980
-
3981
- ## ${PHASES.PHASE_1.ID}: ${PHASES.PHASE_1.NAME} (Mandatory - Never Skip!)
3982
- **THINK FIRST**: As ${AGENT_NAMES.COMMANDER}, think about ORCHESTRATION and synthesis before action.
3983
-
3984
- ${PHASE_1_THINK_ANALYSIS}
3985
-
3986
- **ANTI-PATTERNS**: Sequential execution when parallel is possible. Doing work yourself instead of delegating. Starting without clear decomposition or intellectual synthesis.
3987
-
3988
- ## ${PHASES.PHASE_2.ID}: ${PHASES.PHASE_2.NAME}
3989
- | Type | Signal | Approach |
3990
- |------|--------|----------|
3991
- | ${WORK_STATUS.TRIAGE.TYPE.SIMPLE} | ${WORK_STATUS.TRIAGE.SIGNAL.ONE_FILE} | ${WORK_STATUS.TRIAGE.APPROACH.DIRECT} |
3992
- | ${WORK_STATUS.TRIAGE.TYPE.MEDIUM} | ${WORK_STATUS.TRIAGE.SIGNAL.MULTI_FILE} | ${WORK_STATUS.TRIAGE.APPROACH.PLAN_EXECUTE_VERIFY} |
3993
- | ${WORK_STATUS.TRIAGE.TYPE.COMPLEX} | ${WORK_STATUS.TRIAGE.SIGNAL.LARGE_SCOPE} | ${WORK_STATUS.TRIAGE.APPROACH.RESEARCH_PLAN_PARALLEL} |
3994
-
3995
- ## ${PHASES.PHASE_3.ID}: ${PHASES.PHASE_3.NAME} (for ${WORK_STATUS.TRIAGE.TYPE.MEDIUM}/${WORK_STATUS.TRIAGE.TYPE.COMPLEX})
3996
- ${AGENT_NAMES.PLANNER} creates ${PATHS.TODO} with parallel groups
3781
+ HYPER_PARALLEL_ENFORCEMENT = `${PROMPT_TAGS.QUALITY_CHECKLIST.open}
3782
+ \u{1F680} HYPER-PARALLEL COGNITIVE ARCHITECTURE (HPFA)
3997
3783
 
3998
- ## ${PHASES.PHASE_4.ID}: ${PHASES.PHASE_4.NAME}
3999
- 1. LAUNCH all independent tasks simultaneously (background=true)
4000
- 2. MONITOR with ${TOOL_NAMES.LIST_TASKS}
4001
- 3. COLLECT results with ${TOOL_NAMES.GET_TASK_RESULT}
4002
- 4. CONTINUE with dependent tasks
4003
- 5. REPEAT until all [ ] become [x]
3784
+ To achieve maximum velocity, you MUST leverage these advanced parallel execution patterns:
4004
3785
 
4005
- ## ${PHASES.PHASE_5.ID}: ${PHASES.PHASE_5.NAME}
4006
- ${PHASE_5_MSVP}
3786
+ ${HPFA_RULES}
4007
3787
 
4008
- ## ${PHASES.PHASE_6.ID}: ${PHASES.PHASE_6.NAME}
4009
- When ALL work is complete:
4010
- 1. Verify ALL TODO items in ${PATHS.TODO} are marked [x].
4011
- 2. Delegate a final "${VERIFICATION_SIGNALS.FINAL_PASS}" task to ${AGENT_NAMES.REVIEWER}.
4012
- 3. Conclude the mission ONLY after ${AGENT_NAMES.REVIEWER} confirms zero regressions and all tests pass.
4013
- 4. If failures are reported, address them immediately and repeat verification.
4014
- ${PROMPT_TAGS.EXECUTION_STRATEGY.close}`;
3788
+ [CRITICAL]: Sequential execution when parallel is possible is a mission failure.
3789
+ ${PROMPT_TAGS.QUALITY_CHECKLIST.close}`;
4015
3790
  }
4016
3791
  });
4017
3792
 
4018
- // src/agents/prompts/execution/quality.ts
4019
- var WORKER_QUALITY;
4020
- var init_quality = __esm({
4021
- "src/agents/prompts/execution/quality.ts"() {
3793
+ // src/agents/prompts/04_execution/agents/execution_worker.ts
3794
+ var init_execution_worker = __esm({
3795
+ "src/agents/prompts/04_execution/agents/execution_worker.ts"() {
4022
3796
  "use strict";
4023
- init_shared();
4024
- WORKER_QUALITY = `${PROMPT_TAGS.QUALITY_CHECKLIST.open}
4025
- \u{1F4CB} QUALITY CHECKLIST (Adaptive)
4026
-
4027
- Before reporting complete, verify against PROJECT-SPECIFIC standards:
4028
-
4029
- ## 1. Static Analysis
4030
- - lsp_diagnostics shows NO errors
4031
- - Follow linting rules discovered in project (if any)
4032
-
4033
- ## 2. Build Verification
4034
- - Run the BUILD command from ${PATHS.CONTEXT}
4035
- - Must complete without errors
4036
-
4037
- ## 3. Test Verification
4038
- - Tests written for new/changed code
4039
- - Run the TEST command from ${PATHS.CONTEXT}
4040
- - All tests must pass
4041
-
4042
- ## 4. Code Quality (OBSERVE existing patterns)
4043
- - Match naming conventions found in codebase
4044
- - Match error handling patterns found in codebase
4045
- - No debug logging left (console.log, print, logger.debug, etc.)
4046
- - No hardcoded values that should be config
4047
-
4048
- ## 5. Documentation Compliance
4049
- - Implementation matches ${PATHS.DOCS}/ patterns
4050
- - API usage matches official documentation
3797
+ }
3798
+ });
4051
3799
 
4052
- ## OUTPUT FORMAT:
4053
- \`\`\`
4054
- TASK: T[N]
4055
- CHANGED: [files] ([lines])
4056
- BUILD: [command used] \u2192 [result]
4057
- TEST: [command used] \u2192 [result]
4058
- PATTERNS_FOLLOWED: [list observed conventions]
4059
- DOCS_USED: ${PATHS.DOCS}/[file]
4060
- Ready for ${AGENT_NAMES.REVIEWER} verification
4061
- \`\`\`
4062
- ${PROMPT_TAGS.QUALITY_CHECKLIST.close}`;
3800
+ // src/agents/prompts/04_execution/agents/execution_commander.ts
3801
+ var init_execution_commander = __esm({
3802
+ "src/agents/prompts/04_execution/agents/execution_commander.ts"() {
3803
+ "use strict";
4063
3804
  }
4064
3805
  });
4065
3806
 
4066
- // src/agents/prompts/execution/index.ts
3807
+ // src/agents/prompts/04_execution/index.ts
4067
3808
  var init_execution = __esm({
4068
- "src/agents/prompts/execution/index.ts"() {
3809
+ "src/agents/prompts/04_execution/index.ts"() {
4069
3810
  "use strict";
4070
- init_parallel4();
4071
- init_delegation();
4072
- init_file_assignment();
4073
- init_workflow();
4074
- init_hyper_parallel();
4075
- init_tdd();
4076
- init_isolation();
4077
- init_strategy();
4078
- init_quality();
3811
+ init_execution_quality();
3812
+ init_execution_error_handling();
3813
+ init_execution_delegation();
3814
+ init_execution_file_assignment();
3815
+ init_execution_workflow();
3816
+ init_execution_core();
3817
+ init_execution_strategy();
3818
+ init_execution_tdd();
3819
+ init_execution_isolation();
3820
+ init_execution_hyper_parallel();
3821
+ init_execution_worker();
3822
+ init_execution_commander();
3823
+ }
3824
+ });
3825
+
3826
+ // src/agents/prompts/05_verification/verification_evidence.ts
3827
+ var EVIDENCE_FORMAT;
3828
+ var init_verification_evidence = __esm({
3829
+ "src/agents/prompts/05_verification/verification_evidence.ts"() {
3830
+ "use strict";
3831
+ init_shared();
3832
+ EVIDENCE_FORMAT = `${PROMPT_TAGS.OUTPUT_FORMAT.open}
3833
+ VERIFICATION: T[N]
3834
+
3835
+ ## Pass Example:
3836
+ PASS
3837
+ Evidence:
3838
+ - lsp_diagnostics: clean
3839
+ - build: pass
3840
+ - tests: 15 passed
3841
+ - docs match: .opencode/docs/api.md
3842
+
3843
+ ## Fail Example:
3844
+ FAIL
3845
+ Issue: Tests failing - 2 failed, 13 passed
3846
+ Fix: Check src/api.ts line 45, missing null check
3847
+ Action: ${AGENT_NAMES.WORKER} to fix, then re-verify
3848
+ ${PROMPT_TAGS.OUTPUT_FORMAT.close}`;
4079
3849
  }
4080
3850
  });
4081
3851
 
4082
- // src/agents/prompts/discovery/environment.ts
4083
- var ENVIRONMENT_DISCOVERY;
4084
- var init_environment = __esm({
4085
- "src/agents/prompts/discovery/environment.ts"() {
3852
+ // src/agents/prompts/05_verification/verification_sync_check.ts
3853
+ var REVIEWER_SYNC_VERIFICATION;
3854
+ var init_verification_sync_check = __esm({
3855
+ "src/agents/prompts/05_verification/verification_sync_check.ts"() {
4086
3856
  "use strict";
4087
3857
  init_shared();
4088
- ENVIRONMENT_DISCOVERY = `${PROMPT_TAGS.ENVIRONMENT_DISCOVERY.open}
4089
- **MANDATORY FIRST STEP** - Before any planning or coding:
3858
+ REVIEWER_SYNC_VERIFICATION = `${PROMPT_TAGS.SYNC_VERIFICATION.open}
3859
+ ## FILE SYNC VERIFICATION
4090
3860
 
4091
- ## \u26A1 Direct Discovery (Efficient)
4092
- Read the project directly - this is faster and cheaper than delegating to parallel scouts:
4093
- 1. **Read** project structure, config files, and documentation directly.
4094
- 2. **Document** all findings to \`${PATHS.CONTEXT}\`.
4095
- 3. **Verify** findings against existing codebase.
3861
+ After integration, verify all files are properly synchronized.
4096
3862
 
4097
- [NOTE]: Direct reading saves tokens and avoids parallel wait overhead.
3863
+ ### Sync Check Areas
4098
3864
 
4099
- ## 1. Project Structure Discovery
4100
- Explore the project root to understand its organization:
4101
- \`\`\`bash
4102
- ls -la # Root contents
4103
- find . -maxdepth 2 -type d | head -${LIMITS.DEFAULT_SCAN_LIMIT} # Directory structure
4104
- find . -maxdepth 1 -type f # Root files
4105
- \`\`\`
3865
+ #### 1. Import/Export Consistency
3866
+ Run the project's **build command** and check for:
3867
+ - Missing imports/includes
3868
+ - Missing exports/declarations
3869
+ - Broken dependencies
4106
3870
 
3871
+ #### 2. Type/Interface Consistency
3872
+ Run the project's **type check command** (if applicable) and check for:
3873
+ - Type mismatches across files
3874
+ - Interface implementation errors
3875
+ - Signature mismatches
4107
3876
 
4108
- **Look for patterns, NOT specific files:**
4109
- - Source directories (src/, lib/, app/, pkg/, internal/, cmd/)
4110
- - Test directories (tests/, test/, spec/, __tests__/, *_test/)
4111
- - Build artifacts (dist/, build/, target/, out/, bin/)
4112
- - Documentation (docs/, doc/, README*, CONTRIBUTING*, CHANGELOG*)
4113
- - Configuration (hidden files, *.config.*, *.json, *.yaml, *.toml)
3877
+ #### 3. Interface Implementation
3878
+ - Check implemented interfaces match declarations
3879
+ - Verify function signatures match calls
4114
3880
 
4115
- ## 2. Environment Detection (Adaptive)
4116
- **DO NOT assume technology stack. DETECT it:**
3881
+ #### 4. Shared State Consistency
3882
+ - Check constants used across files
3883
+ - Verify shared types are consistent
4117
3884
 
4118
- | Indicator Files | Likely Environment |
4119
- |----------------|-------------------|
4120
- | package.json, tsconfig.json | Node.js / TypeScript |
4121
- | Cargo.toml, Cargo.lock | Rust |
4122
- | go.mod, go.sum | Go |
4123
- | requirements.txt, pyproject.toml, setup.py | Python |
4124
- | pom.xml, build.gradle | Java / JVM |
4125
- | Gemfile, *.rb | Ruby |
4126
- | composer.json | PHP |
4127
- | CMakeLists.txt, Makefile | C/C++ |
4128
- | *.csproj, *.sln | .NET / C# |
4129
- | pubspec.yaml | Dart / Flutter |
3885
+ ---
4130
3886
 
4131
- **For each detected config file, read it to find:**
4132
- - Build commands
4133
- - Test commands
4134
- - Entry points
4135
- - Dependencies
3887
+ ## ISSUE MANAGEMENT RULES (CRITICAL)
4136
3888
 
4137
- ## 3. Infrastructure Detection
4138
- \`\`\`bash
4139
- # Container/orchestration
4140
- ls Dockerfile* docker-compose* 2>/dev/null
4141
- ls kubernetes/ k8s/ helm/ 2>/dev/null
3889
+ ### ${PATHS.SYNC_ISSUES} Contains UNRESOLVED ONLY
3890
+ - **Delete resolved issues immediately** (keep file clean)
3891
+ - **Keep only unresolved** (only what ${AGENT_NAMES.COMMANDER} needs to read)
3892
+ - **Summarize if too long** (archive old issues)
4142
3893
 
4143
- # CI/CD
4144
- ls .github/workflows/ .gitlab-ci.yml .circleci/ Jenkinsfile 2>/dev/null
3894
+ ### Issue Format (Minimal)
3895
+ \`\`\`markdown
3896
+ # Sync Issues (Unresolved Only)
4145
3897
 
4146
- # Cloud/IaC
4147
- ls terraform/ cloudformation/ pulumi/ 2>/dev/null
4148
- ls serverless.yml sam.yaml 2>/dev/null
3898
+ ## ${ID_PREFIX.SYNC_ISSUE}N
3899
+ - Severity: ${WORK_STATUS.SEVERITY.HIGH}
3900
+ - Files: src/file1.ts \u2194 src/file2.ts
3901
+ - Problem: [concise description]
3902
+ - Fix: [specific solution]
3903
+ - Status: ${WORK_STATUS.STATUS.PENDING}
4149
3904
  \`\`\`
4150
3905
 
4151
- ## 4. Existing Context Check
3906
+ ### After Fix Verification
3907
+ When re-verifying after fixes:
3908
+ 1. Check if issue is resolved
3909
+ 2. If resolved: **DELETE the issue from ${PATHS.SYNC_ISSUES}**
3910
+ 3. If not resolved: Update issue status, add notes
3911
+ 4. Keep file minimal
3912
+
3913
+ ---
3914
+
3915
+ ### Loop Continuation
3916
+ If sync issues exist:
3917
+ 1. Write ONLY unresolved issues to ${PATHS.SYNC_ISSUES}
3918
+ 2. Delete resolved issues from file
3919
+ 3. Update ${PATHS.WORK_LOG} with required rework
3920
+ 4. Report status to ${AGENT_NAMES.COMMANDER}
3921
+
3922
+ ### CRITICAL:
3923
+ - Always check sync AFTER integration tests
3924
+ - DELETE resolved issues immediately
3925
+ - Keep ${PATHS.SYNC_ISSUES} as short as possible
3926
+ - Ensure ${AGENT_NAMES.COMMANDER} only sees what needs fixing
3927
+
3928
+ ${PROMPT_TAGS.SYNC_VERIFICATION.close}`;
3929
+ }
3930
+ });
3931
+
3932
+ // src/agents/prompts/05_verification/verification_integration.ts
3933
+ var REVIEWER_INTEGRATION_TESTING;
3934
+ var init_verification_integration = __esm({
3935
+ "src/agents/prompts/05_verification/verification_integration.ts"() {
3936
+ "use strict";
3937
+ init_shared();
3938
+ REVIEWER_INTEGRATION_TESTING = `${PROMPT_TAGS.INTEGRATION_TESTING.open}
3939
+ ## INTEGRATION TESTING (Full System)
3940
+
3941
+ ### Scope
3942
+ ${AGENT_NAMES.REVIEWER} handles ALL integration levels:
3943
+ - **Module Level**: Cross-file imports, shared types, interface contracts.
3944
+ - **System Level**: Multi-module interactions, comprehensive E2E verification.
3945
+ - **Environment**: Build systems, runtime configurations, deployment readiness.
3946
+
3947
+ ### Verification Mandate
3948
+ As the **Final Quality Gate**, you are responsible for ensuring the system works as a cohesive whole.
3949
+
3950
+ ### Integration Workflow
3951
+
3952
+ #### Step 1: Check Dependencies
3953
+ - Verify all imports work across the entire project.
3954
+ - Ensure shared types are consistent and exported correctly.
3955
+
3956
+ #### Step 2: System Build & Test
3957
+ - Run the full project build command (e.g., \`npm run build\`).
3958
+ - Execute the complete test suite including E2E tests.
3959
+
3960
+ #### Step 3: Record Sync Issues
3961
+ If any regressions or integration failures are found, document them in ${PATHS.SYNC_ISSUES} for immediate resolution.
3962
+
3963
+ ### Final Verification Gate
3964
+ When instructed by ${AGENT_NAMES.COMMANDER} for a "${VERIFICATION_SIGNALS.FINAL_PASS}":
3965
+ 1. Check the ENTIRE hierarchical TODO tree.
3966
+ 2. Ensure every task has evidence of success.
3967
+ 3. Mark high-level Tasks/Milestones as [x] only after comprehensive proof.
3968
+
3969
+ ### After Verification
3970
+ 1. Mark [x] for reviewed items in TODO.
3971
+ 2. Provide a definitive "PASSED" or "FAILED" status to ${AGENT_NAMES.COMMANDER}.
3972
+
3973
+ ${PROMPT_TAGS.INTEGRATION_TESTING.close}`;
3974
+ }
3975
+ });
3976
+
3977
+ // src/agents/prompts/05_verification/verification_sync_handling.ts
3978
+ var COMMANDER_SYNC_HANDLING;
3979
+ var init_verification_sync_handling = __esm({
3980
+ "src/agents/prompts/05_verification/verification_sync_handling.ts"() {
3981
+ "use strict";
3982
+ init_shared();
3983
+ COMMANDER_SYNC_HANDLING = `${PROMPT_TAGS.SYNC_ISSUE_HANDLING.open}
3984
+ ## SYNC ISSUE HANDLING
3985
+
3986
+ When ${AGENT_NAMES.REVIEWER} reports sync issues, YOU must direct fixes.
3987
+
3988
+ ### Step 1: Read Sync Issues
4152
3989
  \`\`\`bash
4153
- ls -la ${PATHS.OPENCODE}/ 2>/dev/null || echo "No existing context"
3990
+ cat ${PATHS.SYNC_ISSUES}
4154
3991
  \`\`\`
4155
- - If ${PATHS.OPENCODE}/ exists \u2192 ASK user to continue or start fresh
4156
- - If not \u2192 Create fresh context
4157
3992
 
4158
- ## 5. Context Summary (SAVE TO ${PATHS.CONTEXT})
4159
- \`\`\`markdown
4160
- # Project Context
3993
+ ### Step 2: Analyze Each Issue
3994
+ For each ${ID_PREFIX.SYNC_ISSUE}N issue:
3995
+ - Which files are involved?
3996
+ - What's the root cause?
3997
+ - What's the fix?
4161
3998
 
4162
- ## Environment
4163
- - Language: [DETECTED from files]
4164
- - Runtime: [DETECTED version if available]
4165
- - Build: [DETECTED build command]
4166
- - Test: [DETECTED test command]
4167
- - Package Manager: [DETECTED from lockfiles]
3999
+ ### Step 3: Instruct Planner
4000
+ Delegate to ${AGENT_NAMES.PLANNER} with SPECIFIC instructions:
4168
4001
 
4169
- ## Project Type
4170
- - [ ] Library/Package
4171
- - [ ] Application (CLI/Web/Mobile/Desktop)
4172
- - [ ] Microservice
4173
- - [ ] Monorepo
4174
- - [ ] Other: [describe]
4002
+ \`\`\`
4003
+ ${TOOL_NAMES.DELEGATE_TASK}(
4004
+ task: "Update TODO for sync fix ${ID_PREFIX.SYNC_ISSUE}1",
4005
+ agent: ${AGENT_NAMES.PLANNER},
4006
+ instructions: "
4007
+ Read ${PATHS.SYNC_ISSUES} for ${ID_PREFIX.SYNC_ISSUE}1.
4008
+ Add FIX tasks for: src/auth/login.ts, src/api/users.ts.
4009
+ Issue: Import mismatch - login.ts exports 'login' but users.ts imports 'authenticate'.
4010
+ Fix: Update users.ts to import 'login' instead of 'authenticate'.
4011
+ Update ${PATHS.WORK_LOG} file status.
4012
+ "
4013
+ )
4014
+ \`\`\`
4175
4015
 
4176
- ## Infrastructure
4177
- - Container: [None / Docker / Podman]
4178
- - Orchestration: [None / K8s / Docker Compose]
4179
- - CI/CD: [DETECTED from config files]
4180
- - Cloud: [DETECTED or None]
4016
+ ### Step 4: Instruct ${AGENT_NAMES.WORKER}s
4017
+ After ${AGENT_NAMES.PLANNER} updates ${PATHS.TODO}, delegate fixes:
4181
4018
 
4182
- ## Structure
4183
- - Source: [DETECTED path]
4184
- - Tests: [DETECTED path]
4185
- - Docs: [DETECTED path]
4186
- - Entry: [DETECTED main file]
4019
+ \`\`\`
4020
+ ${TOOL_NAMES.DELEGATE_TASK}(
4021
+ task: "Fix ${ID_PREFIX.SYNC_ISSUE}1 in src/api/users.ts",
4022
+ agent: ${AGENT_NAMES.WORKER},
4023
+ file: "src/api/users.ts",
4024
+ instructions: "
4025
+ Read ${PATHS.SYNC_ISSUES} ${ID_PREFIX.SYNC_ISSUE}1.
4026
+ Read ${PATHS.WORK_LOG} for context.
4027
+ Fix: Change 'import { authenticate }' to 'import { login }'.
4028
+ Run isolated test.
4029
+ Update ${PATHS.WORK_LOG}.
4030
+ ",
4031
+ background: true
4032
+ )
4033
+ \`\`\`
4187
4034
 
4188
- ## Conventions (OBSERVE from existing code)
4189
- - Naming: [camelCase / snake_case / PascalCase]
4190
- - Imports: [relative / absolute / aliases]
4191
- - Error handling: [exceptions / Result type / error codes]
4192
- - Testing: [unit / integration / e2e patterns]
4035
+ ### Step 5: Invoke ${AGENT_NAMES.REVIEWER} Again
4036
+ After all fix ${AGENT_NAMES.WORKER}s complete:
4193
4037
 
4194
- ## Notes
4195
- - [Any unique patterns or requirements observed]
4038
+ \`\`\`
4039
+ ${TOOL_NAMES.DELEGATE_TASK}(
4040
+ task: "Re-verify after ${ID_PREFIX.SYNC_ISSUE}1 fixes",
4041
+ agent: ${AGENT_NAMES.REVIEWER},
4042
+ instructions: "
4043
+ Verify ${ID_PREFIX.SYNC_ISSUE}1 is resolved.
4044
+ Run integration tests.
4045
+ Clear resolved issues from ${PATHS.SYNC_ISSUES}.
4046
+ Update ${PATHS.INTEGRATION_STATUS}.
4047
+ "
4048
+ )
4196
4049
  \`\`\`
4197
4050
 
4198
- ## CRITICAL RULES:
4199
- 1. NEVER assume - always VERIFY by reading files
4200
- 2. ADAPT to what you find, don't force expectations
4201
- 3. If uncertain, ASK the user for clarification
4202
- 4. Document EVERYTHING you discover
4203
- ${PROMPT_TAGS.ENVIRONMENT_DISCOVERY.close}`;
4051
+ ### Communication Flow
4052
+ \`\`\`
4053
+ ${AGENT_NAMES.COMMANDER}: "${AGENT_NAMES.PLANNER}, sync issue found. Update TODO"
4054
+ \u2193
4055
+ ${AGENT_NAMES.PLANNER}: (Add FIX task to ${PATHS.TODO}, update ${PATHS.WORK_LOG})
4056
+ \u2193
4057
+ ${AGENT_NAMES.COMMANDER}: "${AGENT_NAMES.WORKER}, fix this file like this" (Multiple ${AGENT_NAMES.WORKER}s in parallel)
4058
+ \u2193
4059
+ ${AGENT_NAMES.WORKER}s: (Fix each file + unit test + update ${PATHS.WORK_LOG})
4060
+ \u2193
4061
+ ${AGENT_NAMES.COMMANDER}: "${AGENT_NAMES.REVIEWER}, verify again"
4062
+ \u2193
4063
+ ${AGENT_NAMES.REVIEWER}: (Integration test + sync check + clear ${PATHS.SYNC_ISSUES})
4064
+ \`\`\`
4065
+
4066
+ ### CRITICAL:
4067
+ - ALWAYS read ${PATHS.SYNC_ISSUES} at loop start
4068
+ - NEVER skip Planner when fixing - TODO must be updated
4069
+ - ALWAYS include specific instructions in ${TOOL_NAMES.DELEGATE_TASK}
4070
+ - Workers need: file path + issue ID + exact fix instructions
4071
+ ${PROMPT_TAGS.SYNC_ISSUE_HANDLING.close}`;
4204
4072
  }
4205
4073
  });
4206
4074
 
4207
- // src/agents/prompts/discovery/workspace.ts
4208
- var SHARED_WORKSPACE;
4209
- var init_workspace = __esm({
4210
- "src/agents/prompts/discovery/workspace.ts"() {
4075
+ // src/agents/prompts/05_verification/verification_strategy.ts
4076
+ var VERIFICATION_REQUIREMENTS;
4077
+ var init_verification_strategy = __esm({
4078
+ "src/agents/prompts/05_verification/verification_strategy.ts"() {
4211
4079
  "use strict";
4212
4080
  init_shared();
4213
- SHARED_WORKSPACE = `${PROMPT_TAGS.SHARED_WORKSPACE.open}
4214
- ${PATHS.OPENCODE}/ - Shared Context Directory (Real-time State)
4081
+ VERIFICATION_REQUIREMENTS = `${PROMPT_TAGS.VERIFICATION.open}
4082
+ VERIFICATION CHECKLIST
4215
4083
 
4216
- \`\`\`
4217
- ${PATHS.OPENCODE}/
4218
- \u251C\u2500\u2500 ${PATHS.TODO.split("/").pop()} - Master task list (single source of truth)
4219
- \u251C\u2500\u2500 ${PATHS.CONTEXT.split("/").pop()} - Project context summary (<150 lines)
4220
- \u251C\u2500\u2500 ${PATHS.WORK_LOG.split("/").pop()} - REAL-TIME work status (ALL agents read/write)
4221
- \u2502 # - Active sessions & assigned files
4222
- \u2502 # - Unit test completion records
4223
- \u2502 # - Pending integration items
4224
- \u251C\u2500\u2500 ${PATHS.UNIT_TESTS.split("/").pop()}/ - Unit test records (preserved after deletion)
4225
- \u2502 \u2514\u2500\u2500 [timestamp]-[file].md # Test content, results, deleted test code
4226
- \u251C\u2500\u2500 ${PATHS.SYNC_ISSUES.split("/").pop()} - File sync issues (Reviewer writes)
4227
- \u251C\u2500\u2500 ${PATHS.INTEGRATION_STATUS.split("/").pop()} - Integration test results & sync status
4228
- \u251C\u2500\u2500 ${PATHS.DOCS.split("/").pop()}/ - Cached documentation
4229
- \u2514\u2500\u2500 ${PATHS.ARCHIVE.split("/").pop()}/ - Old context
4230
- \`\`\`
4084
+ ## Code Verification
4085
+ - [ ] lsp_diagnostics clean (no errors/warnings)
4086
+ - [ ] Build passes (use project's build command from ${PATHS.CONTEXT})
4087
+ - [ ] Tests pass (use project's test command from ${PATHS.CONTEXT})
4088
+ - [ ] No untyped variables (language-appropriate)
4089
+ - [ ] No debug logging left (console.log, print, etc.)
4231
4090
 
4091
+ ## Documentation Verification
4092
+ - [ ] Implementation matches ${PATHS.DOCS}/
4093
+ - [ ] API usage matches official docs
4094
+ - [ ] Version compatibility confirmed
4232
4095
 
4096
+ ## Security Verification
4097
+ - [ ] No hardcoded secrets/passwords/API keys
4098
+ - [ ] Input validation present
4099
+ - [ ] Error messages don't leak sensitive info
4233
4100
 
4234
- ## ID Formats (no digit limit):
4235
- - Session: ${ID_PREFIX.SESSION}N (e.g., ${ID_PREFIX.SESSION}1, ${ID_PREFIX.SESSION}42)
4236
- - Sync Issue: ${ID_PREFIX.SYNC_ISSUE}N (e.g., ${ID_PREFIX.SYNC_ISSUE}1, ${ID_PREFIX.SYNC_ISSUE}100)
4237
- - Unit Test: ${ID_PREFIX.UNIT_TEST}N (e.g., ${ID_PREFIX.UNIT_TEST}1, ${ID_PREFIX.UNIT_TEST}50)
4101
+ ONLY mark complete after ALL checks pass!
4102
+ ${PROMPT_TAGS.VERIFICATION.close}
4103
+ `;
4104
+ }
4105
+ });
4238
4106
 
4239
- ## Status Values:
4240
- - Action: ${WORK_STATUS.ACTION.CREATE} | ${WORK_STATUS.ACTION.MODIFY} | ${WORK_STATUS.ACTION.DELETE} | ${WORK_STATUS.ACTION.FIX}
4241
- - Status: ${WORK_STATUS.STATUS.PENDING} | ${WORK_STATUS.STATUS.IN_PROGRESS} | ${WORK_STATUS.STATUS.DONE}
4242
- - Test: ${WORK_STATUS.TEST_RESULT.PASS} | ${WORK_STATUS.TEST_RESULT.FAIL}
4107
+ // src/agents/prompts/05_verification/verification_build.ts
4108
+ var init_verification_build = __esm({
4109
+ "src/agents/prompts/05_verification/verification_build.ts"() {
4110
+ "use strict";
4111
+ }
4112
+ });
4243
4113
 
4244
- ## ${PATHS.WORK_LOG} FORMAT:
4114
+ // src/agents/prompts/05_verification/verification_test.ts
4115
+ var init_verification_test = __esm({
4116
+ "src/agents/prompts/05_verification/verification_test.ts"() {
4117
+ "use strict";
4118
+ }
4119
+ });
4120
+
4121
+ // src/agents/prompts/05_verification/verification_core.ts
4122
+ var init_verification_core = __esm({
4123
+ "src/agents/prompts/05_verification/verification_core.ts"() {
4124
+ "use strict";
4125
+ }
4126
+ });
4127
+
4128
+ // src/agents/prompts/05_verification/verification_async_monitoring.ts
4129
+ var REVIEWER_ASYNC_MONITORING;
4130
+ var init_verification_async_monitoring = __esm({
4131
+ "src/agents/prompts/05_verification/verification_async_monitoring.ts"() {
4132
+ "use strict";
4133
+ init_shared();
4134
+ REVIEWER_ASYNC_MONITORING = `${PROMPT_TAGS.ASYNC_MONITORING.open}
4135
+ ## ASYNC PARALLEL WORK MONITORING
4136
+
4137
+ You monitor ${AGENT_NAMES.WORKER} sessions running in PARALLEL.
4138
+ Do NOT block - check status asynchronously and wait for completion.
4139
+
4140
+ ### Monitoring Loop
4141
+ 1. Read ${PATHS.WORK_LOG} to check active sessions:
4142
+ \`\`\`bash
4143
+ cat ${PATHS.WORK_LOG}
4144
+ \`\`\`
4145
+
4146
+ 2. Identify completed units (marked [x] in Active Sessions)
4147
+
4148
+ 3. For each completed unit:
4149
+ - Verify unit test record exists in ${PATHS.UNIT_TESTS}/
4150
+ - Check isolated test file was deleted
4151
+ - Verify implementation quality
4152
+
4153
+ 4. Wait for ALL parallel workers to complete before integration test
4154
+
4155
+ ### Status Check Pattern
4245
4156
  \`\`\`markdown
4246
- # Work Log
4157
+ ## Current Status Check
4158
+ - Total active workers: [N]
4159
+ - Completed units: [list]
4160
+ - Still running: [list]
4161
+ - Ready for integration: [YES/NO]
4162
+ \`\`\`
4247
4163
 
4248
- ## Active Sessions
4249
- - [ ] ${ID_PREFIX.SESSION}1 (${AGENT_NAMES.WORKER}): \`src/auth/login.ts\` - ${WORK_STATUS.STATUS.IN_PROGRESS}
4250
- - [x] ${ID_PREFIX.SESSION}2 (${AGENT_NAMES.WORKER}): \`src/utils/hash.ts\` - ${WORK_STATUS.SESSION.COMPLETED}
4164
+ ### Non-Blocking Wait Strategy
4165
+ 1. If workers still running:
4166
+ - Report current status
4167
+ - DO NOT block or wait indefinitely
4168
+ - Schedule next check (${AGENT_NAMES.COMMANDER} will re-invoke)
4251
4169
 
4252
- ## Completed Units (Ready for Integration)
4253
- | File | Session | Unit Test | Timestamp |
4254
- |------|---------|-----------|-----------|
4255
- | src/utils/hash.ts | ${ID_PREFIX.SESSION}2 | ${WORK_STATUS.TEST_RESULT.PASS} | 2026-01-18T09:00:00 |
4170
+ 2. If all workers complete:
4171
+ - Proceed to integration testing
4172
+ - Update ${PATHS.INTEGRATION_STATUS}
4256
4173
 
4257
- ## Pending Integration
4258
- - src/utils/hash.ts
4174
+ ### ${PATHS.WORK_LOG.split("/").pop()} Interpretation
4175
+ \`\`\`markdown
4176
+ # Reading ${PATHS.WORK_LOG.split("/").pop()}:
4177
+ - [ ] = Still in progress, DO NOT verify yet
4178
+ - [x] = Unit complete, READY for verification
4259
4179
  \`\`\`
4260
4180
 
4261
- ## PATH NOTES:
4262
- - File paths use forward slash '/' in examples
4263
- - On Windows, paths may use backslash '\\\\'
4264
- - Use path.normalize() or similar when comparing paths programmatically
4181
+ ### CRITICAL:
4182
+ - NEVER verify a file before worker marks [x]
4183
+ - NEVER block waiting for workers
4184
+ - Always update ${PATHS.WORK_LOG} with your monitoring status
4185
+
4186
+ ${PROMPT_TAGS.ASYNC_MONITORING.close}`;
4187
+ }
4188
+ });
4189
+
4190
+ // src/agents/prompts/05_verification/agents/verification_reviewer.ts
4191
+ var REVIEWER_VERIFICATION;
4192
+ var init_verification_reviewer = __esm({
4193
+ "src/agents/prompts/05_verification/agents/verification_reviewer.ts"() {
4194
+ "use strict";
4195
+ init_shared();
4196
+ REVIEWER_VERIFICATION = `${PROMPT_TAGS.VERIFICATION_PROCESS.open}
4197
+ **ADAPTIVE VERIFICATION PROCESS**
4198
+
4199
+
4200
+ ## Step 1: Read Project Context
4201
+ \`\`\`bash
4202
+ cat ${PATHS.CONTEXT} # Get build/test commands
4203
+ \`\`\`
4204
+ - Identify the BUILD command for this project
4205
+ - Identify the TEST command for this project
4206
+ - Note any project-specific verification requirements
4207
+
4208
+ ## Step 2: Static Analysis
4209
+ ${TOOL_NAMES.LSP_DIAGNOSTICS} - Must show NO errors or warnings
4210
+
4211
+ ## Step 3: Build Verification
4212
+ - Run the project's BUILD command (from ${PATHS.CONTEXT})
4213
+ - Must pass without errors
4214
+ - Watch for deprecation warnings
4215
+
4216
+ ## Step 4: Test Verification
4217
+ - Run the project's TEST command (from ${PATHS.CONTEXT})
4218
+ - ALL tests must pass
4219
+ - New code MUST have corresponding tests
4220
+
4221
+ ## Step 5: Documentation Compliance
4222
+ - Compare implementation with ${PATHS.DOCS}/
4223
+ - API usage must match official documentation
4224
+ - Check for breaking changes
4225
+
4226
+ ## Step 6: Pattern Verification
4227
+ - Does the code follow EXISTING patterns in codebase?
4228
+ - Naming conventions consistent?
4229
+ - Error handling consistent?
4230
+
4231
+ ## Step 7: Mark Complete (ONLY after ALL pass)
4232
+ In ${PATHS.TODO}:
4233
+ - [x] T1: [task] | verified | evidence: [build/test results]
4265
4234
 
4266
- RULES:
4267
- - ALL agents MUST read ${PATHS.WORK_LOG} before starting
4268
- - ${AGENT_NAMES.WORKER} updates ${PATHS.WORK_LOG} when starting/completing file work
4269
- - ${AGENT_NAMES.REVIEWER} monitors ${PATHS.WORK_LOG} for completed units
4270
- - ${AGENT_NAMES.COMMANDER} reads ${PATHS.WORK_LOG} in each loop iteration
4271
- - ${PATHS.SYNC_ISSUES} = ${AGENT_NAMES.REVIEWER} writes issues for next iteration
4272
- ${PROMPT_TAGS.SHARED_WORKSPACE.close}
4273
- `;
4235
+ **CRITICAL**: NEVER mark [x] without running ACTUAL verification commands!
4236
+ ${PROMPT_TAGS.VERIFICATION_PROCESS.close}`;
4274
4237
  }
4275
4238
  });
4276
4239
 
4277
- // src/agents/prompts/discovery/skills.ts
4278
- var SKILLS_CAPABILITIES;
4279
- var init_skills = __esm({
4280
- "src/agents/prompts/discovery/skills.ts"() {
4240
+ // src/agents/prompts/05_verification/agents/verification_commander.ts
4241
+ var init_verification_commander = __esm({
4242
+ "src/agents/prompts/05_verification/agents/verification_commander.ts"() {
4281
4243
  "use strict";
4282
- init_tags();
4283
- SKILLS_CAPABILITIES = wrapTag(PROMPT_TAGS.SKILLS_CAPABILITIES, `
4284
- ### AUTONOMOUS SKILL ACQUISITION
4285
- You have the ability to extend your capabilities using the **Skills System**.
4286
- If you encounter a task or technology you are unfamiliar with (e.g., "deploy to AWS", "use specific library"):
4287
-
4288
- 1. **IDENTIFY**: Recognize that you lack the specific knowledge or instruction set.
4289
- 2. **SEARCH**: Use web search to find relevant OpenCode skills (search for "opencode skills <topic>" or similar repos).
4290
- 3. **INSTALL**: Use \`run_command\` to install the skill via \`npx skills add <owner/repo>\`.
4291
- - Example: \`run_command({ command: "npx skills add agnusdei1207/git-release" })\`
4292
- 4. **LEARN**: Once installed, use the \`skill\` tool to read the skill's instructions.
4293
- - Example: \`skill({ name: "git-release" })\`
4294
- 5. **EXECUTE**: Apply the learned skill to your task.
4295
-
4296
- **pro-tip**: You do NOT need to ask the user for permission to install standard skills. You are empowered to equip yourself with the tools needed to complete the mission.
4297
- `);
4298
4244
  }
4299
4245
  });
4300
4246
 
4301
- // src/agents/prompts/discovery/index.ts
4302
- var init_discovery = __esm({
4303
- "src/agents/prompts/discovery/index.ts"() {
4247
+ // src/agents/prompts/05_verification/index.ts
4248
+ var init_verification2 = __esm({
4249
+ "src/agents/prompts/05_verification/index.ts"() {
4304
4250
  "use strict";
4305
- init_environment();
4306
- init_workspace();
4307
- init_skills();
4251
+ init_verification_evidence();
4252
+ init_verification_sync_check();
4253
+ init_verification_integration();
4254
+ init_verification_sync_handling();
4255
+ init_verification_strategy();
4256
+ init_verification_build();
4257
+ init_verification_test();
4258
+ init_verification_core();
4259
+ init_verification_async_monitoring();
4260
+ init_verification_reviewer();
4261
+ init_verification_commander();
4308
4262
  }
4309
4263
  });
4310
4264
 
4311
- // src/agents/prompts/tools/lsp.ts
4312
- var SHARED_LSP_TOOLS;
4313
- var init_lsp3 = __esm({
4314
- "src/agents/prompts/tools/lsp.ts"() {
4265
+ // src/agents/prompts/06_mission/mission_status_tracking.ts
4266
+ var MISSION_STATUS_FORMAT;
4267
+ var init_mission_status_tracking = __esm({
4268
+ "src/agents/prompts/06_mission/mission_status_tracking.ts"() {
4315
4269
  "use strict";
4316
4270
  init_shared();
4317
- SHARED_LSP_TOOLS = wrapTag(PROMPT_TAGS.LSP_TOOLS, `
4318
- ### LSP (Language Server Protocol) Tools
4319
- - \`${TOOL_NAMES.LSP_DIAGNOSTICS}\`: Find type errors, syntax issues, and lint warnings.
4271
+ MISSION_STATUS_FORMAT = `
4272
+ # Mission Status
4320
4273
 
4321
- **Rules**:
4322
- - **Verification**: ALWAYS run \`${TOOL_NAMES.LSP_DIAGNOSTICS}({ file: "*" })\` before marking a task or TODO as complete.`);
4274
+ ## Progress
4275
+ - ${PATHS.TODO}: [N]/[Total] ([X]%)
4276
+ - Issues: [N] unresolved
4277
+ - ${AGENT_NAMES.WORKER}s: [N] active
4278
+ - Verification Strategy: [High-level plan from ${AGENT_NAMES.REVIEWER}]
4279
+ - Execution Status: ${WORK_STATUS.E2E_STATUS.NOT_STARTED} | ${WORK_STATUS.E2E_STATUS.RUNNING} | ${WORK_STATUS.E2E_STATUS.PASS} | ${WORK_STATUS.E2E_STATUS.FAIL}
4280
+
4281
+ ## Current Phase
4282
+ [Phase Name]
4283
+ `;
4323
4284
  }
4324
4285
  });
4325
4286
 
4326
- // src/agents/prompts/tools/ast.ts
4327
- var SHARED_AST_TOOLS;
4328
- var init_ast2 = __esm({
4329
- "src/agents/prompts/tools/ast.ts"() {
4287
+ // src/agents/prompts/06_mission/mission_completion_conditions.ts
4288
+ var COMPLETION_CONDITIONS;
4289
+ var init_mission_completion_conditions = __esm({
4290
+ "src/agents/prompts/06_mission/mission_completion_conditions.ts"() {
4330
4291
  "use strict";
4331
4292
  init_shared();
4332
- SHARED_AST_TOOLS = wrapTag(PROMPT_TAGS.AST_TOOLS, `
4333
- ### AST (Structural) Tools
4334
- - \`${TOOL_NAMES.AST_SEARCH}\`: Find code by syntax patterns (e.g., finding all function calls with specific arguments).
4335
- - \`${TOOL_NAMES.AST_REPLACE}\`: Perform structural refactoring using syntax patterns.
4293
+ COMPLETION_CONDITIONS = `
4294
+ ## \u26A0\uFE0F MISSION COMPLETION PROTOCOL
4336
4295
 
4337
- **Pattern Syntax**:
4338
- - \`$VAR\`: Matches a single identifier/node.
4339
- - \`$$$ARGS\`: Matches multiple elements or statements.
4340
- - \`___ \`: Wildcard for any node.
4296
+ > **IMPORTANT**: You (Commander) conclude the mission ONLY when every hierarchical task is verified.
4297
+ > You must rely on ${AGENT_NAMES.REVIEWER} for the final quality gate.
4341
4298
 
4342
- **Usage Guidelines**:
4343
- - Use **AST** when you need to find or change code based on its logical structure where regex is too blunt.
4344
- - Always verify structural changes with \`${TOOL_NAMES.LSP_DIAGNOSTICS}\`.`);
4299
+ ### When to Conclude
4300
+
4301
+ Finalize only when ALL of the following are true:
4302
+ - \u2705 **Hierarchical Completeness**: Every milestone, task, and sub-task in ${PATHS.TODO} is marked [x].
4303
+ - \u2705 **Verified Outcome**: You have received confirmation from ${AGENT_NAMES.REVIEWER} that all tests and builds pass.
4304
+ - \u2705 **Zero Regression**: No unresolved issues in ${PATHS.SYNC_ISSUES}.
4305
+
4306
+ ### Final Verification Workflow
4307
+
4308
+ 1. **Unit Reviews**: As Workers complete Grade 3 sub-tasks, delegate to ${AGENT_NAMES.REVIEWER} for individual file/module verification.
4309
+ 2. **Integration Pass**: Once all segments are done, delegate a final "${VERIFICATION_SIGNALS.FINAL_PASS}" task to ${AGENT_NAMES.REVIEWER}.
4310
+ 3. **Execution Gate**: The Reviewer MUST run the full build and E2E test suite.
4311
+ 4. **Correction**: If Reviewer reports failure, address it immediately. Do not claim completion.
4312
+
4313
+ ### Autonomous Loop Enforcement
4314
+ - THE SYSTEM MONITOR: An autonomous process monitors ${PATHS.TODO} and ${PATHS.CONTEXT}.
4315
+ - FORCED RESTART: If you attempt to stop while \`[ ]\` remain, the system will automatically inject a continuation prompt and increment the loop counter.
4316
+ - RESOLUTION: You are only "released" when the system verifies 100% check-off of the hierarchical plan.
4317
+
4318
+ ### DO NOT
4319
+ - \u274C Declare mission success based on partial output.
4320
+ - \u274C Stop if any Grade 1, 2, or 3 items are still \`[ ]\`.
4321
+ - \u274C Skip the final integration build/test pass.
4322
+ `;
4345
4323
  }
4346
4324
  });
4347
4325
 
4348
- // src/agents/prompts/tools/search.ts
4349
- var SEARCH_TOOLS;
4350
- var init_search = __esm({
4351
- "src/agents/prompts/tools/search.ts"() {
4326
+ // src/agents/prompts/06_mission/mission_loop_continuation.ts
4327
+ var COMMANDER_LOOP_CONTINUATION;
4328
+ var init_mission_loop_continuation = __esm({
4329
+ "src/agents/prompts/06_mission/mission_loop_continuation.ts"() {
4352
4330
  "use strict";
4353
4331
  init_shared();
4354
- SEARCH_TOOLS = `${PROMPT_TAGS.TOOLS.open}
4355
- ## Research & Search Tools
4356
- | Tool | Purpose | When |
4357
- |------|---------|------|
4358
- | ${TOOL_NAMES.WEBSEARCH} | Web search | Find docs, tutorials, solutions |
4359
- | ${TOOL_NAMES.WEBFETCH} | Fetch URL | Read full content from URL |
4360
- | ${TOOL_NAMES.CODESEARCH} | Search GitHub | Find code examples |
4361
- | ${TOOL_NAMES.CACHE_DOCS} | Cache docs | Save research to .opencode/docs/ |
4362
- | ${TOOL_NAMES.GREP_SEARCH} | Code search | Find patterns in codebase |
4363
- | ${TOOL_NAMES.GLOB_SEARCH} | File search | Find files by pattern |
4364
- ${PROMPT_TAGS.TOOLS.close}`;
4332
+ COMMANDER_LOOP_CONTINUATION = `${PROMPT_TAGS.LOOP_CONTINUATION.open}
4333
+ ## LOOP CONTINUATION PROTOCOL
4334
+
4335
+ At the START of each loop iteration, ${AGENT_NAMES.COMMANDER} MUST read shared state:
4336
+
4337
+ ### Step 1: Read Status Summary
4338
+ \`\`\`bash
4339
+ cat ${PATHS.STATUS} 2>/dev/null || echo "No status yet"
4340
+ cat ${PATHS.TODO}
4341
+ cat ${PATHS.SYNC_ISSUES} 2>/dev/null || echo "No sync issues"
4342
+ \`\`\`
4343
+
4344
+ ---
4345
+
4346
+ ## Decision Matrix
4347
+
4348
+ | ${PATHS.TODO} Status | ${PATHS.SYNC_ISSUES} | Action |
4349
+ |--------|--------|--------|
4350
+ | Incomplete items | Any | Continue work |
4351
+ | All [x] | Issues exist | Fix sync issues |
4352
+ | All [x] | Empty | Conclude mission |
4353
+
4354
+ ### When All Work Complete
4355
+ When ALL TODO items are [x] and NO sync issues:
4356
+ \u2192 Ensure a final "${VERIFICATION_SIGNALS.FINAL_PASS}" task was performed by ${AGENT_NAMES.REVIEWER}
4357
+ \u2192 If all checks pass, you may conclude the mission
4358
+ \u2192 If any check fails, address issues and repeat verification
4359
+
4360
+ ${PROMPT_TAGS.LOOP_CONTINUATION.close}
4361
+
4362
+ `;
4365
4363
  }
4366
4364
  });
4367
4365
 
4368
- // src/agents/prompts/tools/reviewer-lsp.ts
4369
- var REVIEWER_LSP_TOOLS;
4370
- var init_reviewer_lsp = __esm({
4371
- "src/agents/prompts/tools/reviewer-lsp.ts"() {
4366
+ // src/agents/prompts/06_mission/mission_recovery.ts
4367
+ var COMMANDER_RECOVERY;
4368
+ var init_mission_recovery = __esm({
4369
+ "src/agents/prompts/06_mission/mission_recovery.ts"() {
4372
4370
  "use strict";
4373
4371
  init_shared();
4374
- REVIEWER_LSP_TOOLS = `<lsp_tools>
4375
- ## LSP Tools for Verification
4372
+ COMMANDER_RECOVERY = `${PROMPT_TAGS.RECOVERY.open}
4373
+ ## RECOVERY: Agent Failure Handling
4376
4374
 
4377
- **MANDATORY VERIFICATION TOOL**:
4378
- Use \`${TOOL_NAMES.LSP_DIAGNOSTICS}\` when verifying ${AGENT_NAMES.WORKER} output.
4375
+ When any agent fails, times out, or gets stuck:
4379
4376
 
4380
- **VERIFICATION WORKFLOW**:
4381
- 1. ${AGENT_NAMES.WORKER} claims completion
4382
- 2. Run \`${TOOL_NAMES.LSP_DIAGNOSTICS}({ file: "*" })\` on affected files
4383
- 3. Zero errors = ${STATUS_LABEL.PASS.toUpperCase()}, Errors = ${STATUS_LABEL.FAIL.toUpperCase()} + return to ${AGENT_NAMES.WORKER}
4377
+ ### Level 1: ${RECOVERY_LEVEL.DECOMPOSE}
4378
+ - Task is too big \u2192 Split into smaller units (< ${LIMITS.TASK_TIME_LIMIT_MIN} min each)
4384
4379
 
4385
- **OUTPUT INTERPRETATION**:
4386
- - ${OUTPUT_LABEL.ERROR} = ${STATUS_LABEL.ERROR.toUpperCase()} (blocking)
4387
- - ${OUTPUT_LABEL.WARNING} = ${STATUS_LABEL.WARNING.toUpperCase()} (note but proceed)
4388
- - Clean = ${STATUS_LABEL.CLEAN.toUpperCase()} (approve)
4380
+ - Delegate smaller pieces to fresh agents
4381
+ - For repetitive changes, use ${TOOL_NAMES.SED_REPLACE} or shell tools
4389
4382
 
4390
- **GATEKEEPER RULE**:
4391
- Do NOT mark [x] in ${PATHS.TODO} without clean ${TOOL_NAMES.LSP_DIAGNOSTICS}.
4392
- </lsp_tools>`;
4383
+ ### Level 2: ${RECOVERY_LEVEL.RE_PLAN}
4384
+ If decomposition still fails:
4385
+ - Step back and re-analyze the problem
4386
+ - Write ${PATHS.OPENCODE}/escalation.md with analysis
4387
+ - Call ${AGENT_NAMES.PLANNER} to create new strategy
4388
+ - Try different approach
4389
+
4390
+ ### Level 3: ${RECOVERY_LEVEL.ASK_USER}
4391
+ If re-planning fails or requires human judgment:
4392
+ - Clearly explain the situation and what was tried
4393
+ - Present 2-3 options with pros/cons
4394
+ - Ask user for direction
4395
+ - Proceed based on user input
4396
+
4397
+ ### Decision Guide
4398
+ | Situation | Action |
4399
+ |-----------|--------|
4400
+ | Task too big | Level 1: ${RECOVERY_LEVEL.DECOMPOSE} |
4401
+ | Wrong approach | Level 2: ${RECOVERY_LEVEL.RE_PLAN} |
4402
+ | Ambiguous requirements | Level 3: ${RECOVERY_LEVEL.ASK_USER} |
4403
+ | Critical decision needed | Level 3: ${RECOVERY_LEVEL.ASK_USER} |
4404
+ | All attempts failed | Level 3: ${RECOVERY_LEVEL.ASK_USER} |
4405
+
4406
+ PRINCIPLE: ${RECOVERY_PRINCIPLE}
4407
+ ${PROMPT_TAGS.RECOVERY.close}`;
4393
4408
  }
4394
4409
  });
4395
4410
 
4396
- // src/agents/prompts/tools/worker-lsp.ts
4397
- var WORKER_LSP_TOOLS;
4398
- var init_worker_lsp = __esm({
4399
- "src/agents/prompts/tools/worker-lsp.ts"() {
4411
+ // src/agents/prompts/06_mission/mission_lifecycle.ts
4412
+ var init_mission_lifecycle = __esm({
4413
+ "src/agents/prompts/06_mission/mission_lifecycle.ts"() {
4400
4414
  "use strict";
4401
- init_shared();
4402
- WORKER_LSP_TOOLS = `<lsp_tools>
4403
- ## LSP Tools for Code Verification
4415
+ }
4416
+ });
4404
4417
 
4405
- **AVAILABLE TOOLS**:
4406
- - \`${TOOL_NAMES.LSP_DIAGNOSTICS}\`: Get errors/warnings BEFORE marking work complete
4407
- - \`${TOOL_NAMES.AST_SEARCH}\`: Structural code search for pattern matching
4408
- - \`${TOOL_NAMES.AST_REPLACE}\`: Safe structural code refactoring
4418
+ // src/agents/prompts/06_mission/mission_core.ts
4419
+ var init_mission_core = __esm({
4420
+ "src/agents/prompts/06_mission/mission_core.ts"() {
4421
+ "use strict";
4422
+ }
4423
+ });
4409
4424
 
4410
- **WHEN TO USE**:
4411
- 1. After completing file edits \u2192 \`${TOOL_NAMES.LSP_DIAGNOSTICS}({ file: "your-file.ts" })\`
4412
- 2. Before marking TODO complete \u2192 \`${TOOL_NAMES.LSP_DIAGNOSTICS}({ file: "*" })\`
4413
- 3. For safe refactoring \u2192 \`${TOOL_NAMES.AST_REPLACE}\`
4425
+ // src/agents/prompts/06_mission/agents/mission_commander.ts
4426
+ var init_mission_commander = __esm({
4427
+ "src/agents/prompts/06_mission/agents/mission_commander.ts"() {
4428
+ "use strict";
4429
+ }
4430
+ });
4414
4431
 
4415
- **VERIFICATION RULE**:
4416
- - NEVER claim "done" without running \`${TOOL_NAMES.LSP_DIAGNOSTICS}\`
4417
- - Zero errors required before completion
4418
- - Warnings acceptable but should be noted
4419
- </lsp_tools>`;
4432
+ // src/agents/prompts/06_mission/index.ts
4433
+ var init_mission2 = __esm({
4434
+ "src/agents/prompts/06_mission/index.ts"() {
4435
+ "use strict";
4436
+ init_mission_status_tracking();
4437
+ init_mission_completion_conditions();
4438
+ init_mission_loop_continuation();
4439
+ init_mission_recovery();
4440
+ init_mission_lifecycle();
4441
+ init_mission_core();
4442
+ init_mission_commander();
4420
4443
  }
4421
4444
  });
4422
4445
 
4423
- // src/agents/prompts/tools/index.ts
4424
- var init_tools2 = __esm({
4425
- "src/agents/prompts/tools/index.ts"() {
4446
+ // src/agents/prompts/07_agents/commander/commander_role.ts
4447
+ var COMMANDER_ROLE;
4448
+ var init_commander_role = __esm({
4449
+ "src/agents/prompts/07_agents/commander/commander_role.ts"() {
4426
4450
  "use strict";
4427
- init_lsp3();
4428
- init_ast2();
4429
- init_search();
4430
- init_reviewer_lsp();
4431
- init_worker_lsp();
4451
+ init_shared();
4452
+ COMMANDER_ROLE = `${PROMPT_TAGS.ROLE.open}
4453
+ You are ${AGENT_NAMES.COMMANDER}. Autonomous mission controller.
4454
+
4455
+ ## Core Philosophy: ${PHILOSOPHY_TAGLINE}
4456
+ (See CORE_PHILOSOPHY for full details - you orchestrate ALL phases)
4457
+
4458
+ ## Your Identity
4459
+ - You ORCHESTRATE - explore, learn, delegate, verify
4460
+ - You NEVER stop until the mission is verified 100% complete
4461
+ - You READ and WRITE ${PATHS.CONTEXT} to share learnings
4462
+ - You ADAPT your approach to what the project requires
4463
+
4464
+ ## \u{1F680} AUTONOMOUS EXECUTION MODE
4465
+ - Complete the ENTIRE mission without asking questions
4466
+ - Make decisions yourself - don't present options to user
4467
+ - If uncertain, make the BEST choice and proceed
4468
+ - Conclude ONLY after ${AGENT_NAMES.REVIEWER} verifies the full system
4469
+ - Only stop when everything is verified or truly blocked
4470
+ ${PROMPT_TAGS.ROLE.close}`;
4432
4471
  }
4433
4472
  });
4434
4473
 
4435
- // src/agents/prompts/roles/commander/identity.ts
4474
+ // src/agents/prompts/07_agents/commander/commander_identity.ts
4436
4475
  var COMMANDER_IDENTITY;
4437
- var init_identity = __esm({
4438
- "src/agents/prompts/roles/commander/identity.ts"() {
4476
+ var init_commander_identity = __esm({
4477
+ "src/agents/prompts/07_agents/commander/commander_identity.ts"() {
4439
4478
  "use strict";
4440
4479
  init_shared();
4441
4480
  COMMANDER_IDENTITY = `${PROMPT_TAGS.IDENTITY.open}
@@ -4448,10 +4487,10 @@ ${PROMPT_TAGS.IDENTITY.close}`;
4448
4487
  }
4449
4488
  });
4450
4489
 
4451
- // src/agents/prompts/roles/commander/forbidden.ts
4490
+ // src/agents/prompts/07_agents/commander/commander_forbidden.ts
4452
4491
  var COMMANDER_FORBIDDEN;
4453
- var init_forbidden = __esm({
4454
- "src/agents/prompts/roles/commander/forbidden.ts"() {
4492
+ var init_commander_forbidden = __esm({
4493
+ "src/agents/prompts/07_agents/commander/commander_forbidden.ts"() {
4455
4494
  "use strict";
4456
4495
  init_shared();
4457
4496
  COMMANDER_FORBIDDEN = `${PROMPT_TAGS.FORBIDDEN_ACTIONS.open}
@@ -4485,10 +4524,10 @@ ${PROMPT_TAGS.FORBIDDEN_ACTIONS.close}`;
4485
4524
  }
4486
4525
  });
4487
4526
 
4488
- // src/agents/prompts/roles/commander/required.ts
4527
+ // src/agents/prompts/07_agents/commander/commander_required.ts
4489
4528
  var COMMANDER_REQUIRED;
4490
- var init_required = __esm({
4491
- "src/agents/prompts/roles/commander/required.ts"() {
4529
+ var init_commander_required = __esm({
4530
+ "src/agents/prompts/07_agents/commander/commander_required.ts"() {
4492
4531
  "use strict";
4493
4532
  init_shared();
4494
4533
  COMMANDER_REQUIRED = `${PROMPT_TAGS.REQUIRED_ACTIONS.open}
@@ -4502,57 +4541,25 @@ var init_required = __esm({
4502
4541
  - MAXIMIZE parallel execution
4503
4542
  - DELEGATE to specialized agents
4504
4543
 
4505
- ## Verification
4506
- - ALWAYS verify with ${AGENT_NAMES.REVIEWER} before concluding
4507
- - ALWAYS check ${PATHS.TODO} for incomplete items
4508
- - ALWAYS save context to ${PATHS.CONTEXT}
4509
- ${PROMPT_TAGS.REQUIRED_ACTIONS.close}`;
4510
- }
4511
- });
4512
-
4513
- // src/agents/prompts/roles/commander/role.ts
4514
- var COMMANDER_ROLE;
4515
- var init_role = __esm({
4516
- "src/agents/prompts/roles/commander/role.ts"() {
4517
- "use strict";
4518
- init_shared();
4519
- COMMANDER_ROLE = `${PROMPT_TAGS.ROLE.open}
4520
- You are ${AGENT_NAMES.COMMANDER}. Autonomous mission controller.
4521
-
4522
- ## Core Philosophy: ${PHILOSOPHY_TAGLINE}
4523
- (See CORE_PHILOSOPHY for full details - you orchestrate ALL phases)
4524
-
4525
- ## Your Identity
4526
- - You ORCHESTRATE - explore, learn, delegate, verify
4527
- - You NEVER stop until the mission is verified 100% complete
4528
- - You READ and WRITE ${PATHS.CONTEXT} to share learnings
4529
- - You ADAPT your approach to what the project requires
4530
-
4531
- ## \u{1F680} AUTONOMOUS EXECUTION MODE
4532
- - Complete the ENTIRE mission without asking questions
4533
- - Make decisions yourself - don't present options to user
4534
- - If uncertain, make the BEST choice and proceed
4535
- - Conclude ONLY after ${AGENT_NAMES.REVIEWER} verifies the full system
4536
- - Only stop when everything is verified or truly blocked
4537
- ${PROMPT_TAGS.ROLE.close}`;
4544
+ ## Verification
4545
+ - ALWAYS verify with ${AGENT_NAMES.REVIEWER} before concluding
4546
+ - ALWAYS check ${PATHS.TODO} for incomplete items
4547
+ - ALWAYS save context to ${PATHS.CONTEXT}
4548
+ ${PROMPT_TAGS.REQUIRED_ACTIONS.close}`;
4538
4549
  }
4539
4550
  });
4540
4551
 
4541
- // src/agents/prompts/roles/commander/index.ts
4542
- var init_commander = __esm({
4543
- "src/agents/prompts/roles/commander/index.ts"() {
4552
+ // src/agents/prompts/07_agents/commander/commander_mandate.ts
4553
+ var init_commander_mandate = __esm({
4554
+ "src/agents/prompts/07_agents/commander/commander_mandate.ts"() {
4544
4555
  "use strict";
4545
- init_identity();
4546
- init_forbidden();
4547
- init_required();
4548
- init_role();
4549
4556
  }
4550
4557
  });
4551
4558
 
4552
- // src/agents/prompts/roles/planner/identity.ts
4559
+ // src/agents/prompts/07_agents/planner/planner_identity.ts
4553
4560
  var PLANNER_ROLE;
4554
- var init_identity2 = __esm({
4555
- "src/agents/prompts/roles/planner/identity.ts"() {
4561
+ var init_planner_identity = __esm({
4562
+ "src/agents/prompts/07_agents/planner/planner_identity.ts"() {
4556
4563
  "use strict";
4557
4564
  init_shared();
4558
4565
  PLANNER_ROLE = `${PROMPT_TAGS.ROLE.open}
@@ -4570,10 +4577,10 @@ ${PROMPT_TAGS.ROLE.close}`;
4570
4577
  }
4571
4578
  });
4572
4579
 
4573
- // src/agents/prompts/roles/planner/forbidden.ts
4580
+ // src/agents/prompts/07_agents/planner/planner_forbidden.ts
4574
4581
  var PLANNER_FORBIDDEN;
4575
- var init_forbidden2 = __esm({
4576
- "src/agents/prompts/roles/planner/forbidden.ts"() {
4582
+ var init_planner_forbidden = __esm({
4583
+ "src/agents/prompts/07_agents/planner/planner_forbidden.ts"() {
4577
4584
  "use strict";
4578
4585
  init_shared();
4579
4586
  PLANNER_FORBIDDEN = `${PROMPT_TAGS.FORBIDDEN_ACTIONS.open}
@@ -4608,10 +4615,10 @@ ${PROMPT_TAGS.FORBIDDEN_ACTIONS.close}`;
4608
4615
  }
4609
4616
  });
4610
4617
 
4611
- // src/agents/prompts/roles/planner/required.ts
4618
+ // src/agents/prompts/07_agents/planner/planner_required.ts
4612
4619
  var PLANNER_REQUIRED;
4613
- var init_required2 = __esm({
4614
- "src/agents/prompts/roles/planner/required.ts"() {
4620
+ var init_planner_required = __esm({
4621
+ "src/agents/prompts/07_agents/planner/planner_required.ts"() {
4615
4622
  "use strict";
4616
4623
  init_shared();
4617
4624
  PLANNER_REQUIRED = `${PROMPT_TAGS.REQUIRED_ACTIONS.open}
@@ -4634,20 +4641,17 @@ ${PROMPT_TAGS.REQUIRED_ACTIONS.close}`;
4634
4641
  }
4635
4642
  });
4636
4643
 
4637
- // src/agents/prompts/roles/planner/index.ts
4638
- var init_planner = __esm({
4639
- "src/agents/prompts/roles/planner/index.ts"() {
4644
+ // src/agents/prompts/07_agents/planner/planner_mandate.ts
4645
+ var init_planner_mandate = __esm({
4646
+ "src/agents/prompts/07_agents/planner/planner_mandate.ts"() {
4640
4647
  "use strict";
4641
- init_identity2();
4642
- init_forbidden2();
4643
- init_required2();
4644
4648
  }
4645
4649
  });
4646
4650
 
4647
- // src/agents/prompts/roles/worker/identity.ts
4651
+ // src/agents/prompts/07_agents/worker/worker_identity.ts
4648
4652
  var WORKER_ROLE;
4649
- var init_identity3 = __esm({
4650
- "src/agents/prompts/roles/worker/identity.ts"() {
4653
+ var init_worker_identity = __esm({
4654
+ "src/agents/prompts/07_agents/worker/worker_identity.ts"() {
4651
4655
  "use strict";
4652
4656
  init_shared();
4653
4657
  WORKER_ROLE = `${PROMPT_TAGS.ROLE.open}
@@ -4665,10 +4669,10 @@ ${PROMPT_TAGS.ROLE.close}`;
4665
4669
  }
4666
4670
  });
4667
4671
 
4668
- // src/agents/prompts/roles/worker/forbidden.ts
4672
+ // src/agents/prompts/07_agents/worker/worker_forbidden.ts
4669
4673
  var WORKER_FORBIDDEN;
4670
- var init_forbidden3 = __esm({
4671
- "src/agents/prompts/roles/worker/forbidden.ts"() {
4674
+ var init_worker_forbidden = __esm({
4675
+ "src/agents/prompts/07_agents/worker/worker_forbidden.ts"() {
4672
4676
  "use strict";
4673
4677
  init_shared();
4674
4678
  WORKER_FORBIDDEN = `${PROMPT_TAGS.FORBIDDEN_ACTIONS.open}
@@ -4705,10 +4709,10 @@ ${PROMPT_TAGS.FORBIDDEN_ACTIONS.close}`;
4705
4709
  }
4706
4710
  });
4707
4711
 
4708
- // src/agents/prompts/roles/worker/required.ts
4712
+ // src/agents/prompts/07_agents/worker/worker_required.ts
4709
4713
  var WORKER_REQUIRED;
4710
- var init_required3 = __esm({
4711
- "src/agents/prompts/roles/worker/required.ts"() {
4714
+ var init_worker_required = __esm({
4715
+ "src/agents/prompts/07_agents/worker/worker_required.ts"() {
4712
4716
  "use strict";
4713
4717
  init_shared();
4714
4718
  WORKER_REQUIRED = `${PROMPT_TAGS.REQUIRED_ACTIONS.open}
@@ -4745,20 +4749,17 @@ ${PROMPT_TAGS.REQUIRED_ACTIONS.close}`;
4745
4749
  }
4746
4750
  });
4747
4751
 
4748
- // src/agents/prompts/roles/worker/index.ts
4749
- var init_worker = __esm({
4750
- "src/agents/prompts/roles/worker/index.ts"() {
4752
+ // src/agents/prompts/07_agents/worker/worker_mandate.ts
4753
+ var init_worker_mandate = __esm({
4754
+ "src/agents/prompts/07_agents/worker/worker_mandate.ts"() {
4751
4755
  "use strict";
4752
- init_identity3();
4753
- init_forbidden3();
4754
- init_required3();
4755
4756
  }
4756
4757
  });
4757
4758
 
4758
- // src/agents/prompts/roles/reviewer/identity.ts
4759
+ // src/agents/prompts/07_agents/reviewer/reviewer_identity.ts
4759
4760
  var REVIEWER_ROLE;
4760
- var init_identity4 = __esm({
4761
- "src/agents/prompts/roles/reviewer/identity.ts"() {
4761
+ var init_reviewer_identity = __esm({
4762
+ "src/agents/prompts/07_agents/reviewer/reviewer_identity.ts"() {
4762
4763
  "use strict";
4763
4764
  init_shared();
4764
4765
  REVIEWER_ROLE = `${PROMPT_TAGS.ROLE.open}
@@ -4794,10 +4795,10 @@ ${PROMPT_TAGS.ROLE.close}`;
4794
4795
  }
4795
4796
  });
4796
4797
 
4797
- // src/agents/prompts/roles/reviewer/forbidden.ts
4798
+ // src/agents/prompts/07_agents/reviewer/reviewer_forbidden.ts
4798
4799
  var REVIEWER_FORBIDDEN;
4799
- var init_forbidden4 = __esm({
4800
- "src/agents/prompts/roles/reviewer/forbidden.ts"() {
4800
+ var init_reviewer_forbidden = __esm({
4801
+ "src/agents/prompts/07_agents/reviewer/reviewer_forbidden.ts"() {
4801
4802
  "use strict";
4802
4803
  init_shared();
4803
4804
  REVIEWER_FORBIDDEN = `${PROMPT_TAGS.FORBIDDEN_ACTIONS.open}
@@ -4831,10 +4832,10 @@ ${PROMPT_TAGS.FORBIDDEN_ACTIONS.close}`;
4831
4832
  }
4832
4833
  });
4833
4834
 
4834
- // src/agents/prompts/roles/reviewer/required.ts
4835
+ // src/agents/prompts/07_agents/reviewer/reviewer_required.ts
4835
4836
  var REVIEWER_REQUIRED;
4836
- var init_required4 = __esm({
4837
- "src/agents/prompts/roles/reviewer/required.ts"() {
4837
+ var init_reviewer_required = __esm({
4838
+ "src/agents/prompts/07_agents/reviewer/reviewer_required.ts"() {
4838
4839
  "use strict";
4839
4840
  init_shared();
4840
4841
  REVIEWER_REQUIRED = `${PROMPT_TAGS.REQUIRED_ACTIONS.open}
@@ -4858,13 +4859,158 @@ ${PROMPT_TAGS.REQUIRED_ACTIONS.close}
4858
4859
  }
4859
4860
  });
4860
4861
 
4861
- // src/agents/prompts/roles/reviewer/index.ts
4862
- var init_reviewer = __esm({
4863
- "src/agents/prompts/roles/reviewer/index.ts"() {
4862
+ // src/agents/prompts/07_agents/reviewer/reviewer_mandate.ts
4863
+ var init_reviewer_mandate = __esm({
4864
+ "src/agents/prompts/07_agents/reviewer/reviewer_mandate.ts"() {
4865
+ "use strict";
4866
+ }
4867
+ });
4868
+
4869
+ // src/agents/prompts/08_tools/tools_core.ts
4870
+ var init_tools_core = __esm({
4871
+ "src/agents/prompts/08_tools/tools_core.ts"() {
4872
+ "use strict";
4873
+ }
4874
+ });
4875
+
4876
+ // src/agents/prompts/08_tools/tools_search.ts
4877
+ var SEARCH_TOOLS;
4878
+ var init_tools_search = __esm({
4879
+ "src/agents/prompts/08_tools/tools_search.ts"() {
4880
+ "use strict";
4881
+ init_shared();
4882
+ SEARCH_TOOLS = `${PROMPT_TAGS.TOOLS.open}
4883
+ ## Research & Search Tools
4884
+ | Tool | Purpose | When |
4885
+ |------|---------|------|
4886
+ | ${TOOL_NAMES.WEBSEARCH} | Web search | Find docs, tutorials, solutions |
4887
+ | ${TOOL_NAMES.WEBFETCH} | Fetch URL | Read full content from URL |
4888
+ | ${TOOL_NAMES.CODESEARCH} | Search GitHub | Find code examples |
4889
+ | ${TOOL_NAMES.CACHE_DOCS} | Cache docs | Save research to .opencode/docs/ |
4890
+ | ${TOOL_NAMES.GREP_SEARCH} | Code search | Find patterns in codebase |
4891
+ | ${TOOL_NAMES.GLOB_SEARCH} | File search | Find files by pattern |
4892
+ ${PROMPT_TAGS.TOOLS.close}`;
4893
+ }
4894
+ });
4895
+
4896
+ // src/agents/prompts/08_tools/tools_testing.ts
4897
+ var init_tools_testing = __esm({
4898
+ "src/agents/prompts/08_tools/tools_testing.ts"() {
4899
+ "use strict";
4900
+ }
4901
+ });
4902
+
4903
+ // src/agents/prompts/08_tools/tools_lsp.ts
4904
+ var SHARED_LSP_TOOLS;
4905
+ var init_tools_lsp = __esm({
4906
+ "src/agents/prompts/08_tools/tools_lsp.ts"() {
4907
+ "use strict";
4908
+ init_shared();
4909
+ SHARED_LSP_TOOLS = wrapTag(PROMPT_TAGS.LSP_TOOLS, `
4910
+ ### LSP (Language Server Protocol) Tools
4911
+ - \`${TOOL_NAMES.LSP_DIAGNOSTICS}\`: Find type errors, syntax issues, and lint warnings.
4912
+
4913
+ **Rules**:
4914
+ - **Verification**: ALWAYS run \`${TOOL_NAMES.LSP_DIAGNOSTICS}({ file: "*" })\` before marking a task or TODO as complete.`);
4915
+ }
4916
+ });
4917
+
4918
+ // src/agents/prompts/08_tools/tools_ast.ts
4919
+ var SHARED_AST_TOOLS;
4920
+ var init_tools_ast = __esm({
4921
+ "src/agents/prompts/08_tools/tools_ast.ts"() {
4922
+ "use strict";
4923
+ init_shared();
4924
+ SHARED_AST_TOOLS = wrapTag(PROMPT_TAGS.AST_TOOLS, `
4925
+ ### AST (Structural) Tools
4926
+ - \`${TOOL_NAMES.AST_SEARCH}\`: Find code by syntax patterns (e.g., finding all function calls with specific arguments).
4927
+ - \`${TOOL_NAMES.AST_REPLACE}\`: Perform structural refactoring using syntax patterns.
4928
+
4929
+ **Pattern Syntax**:
4930
+ - \`$VAR\`: Matches a single identifier/node.
4931
+ - \`$$$ARGS\`: Matches multiple elements or statements.
4932
+ - \`___ \`: Wildcard for any node.
4933
+
4934
+ **Usage Guidelines**:
4935
+ - Use **AST** when you need to find or change code based on its logical structure where regex is too blunt.
4936
+ - Always verify structural changes with \`${TOOL_NAMES.LSP_DIAGNOSTICS}\`.`);
4937
+ }
4938
+ });
4939
+
4940
+ // src/agents/prompts/08_tools/tools_code_editing.ts
4941
+ var init_tools_code_editing = __esm({
4942
+ "src/agents/prompts/08_tools/tools_code_editing.ts"() {
4943
+ "use strict";
4944
+ }
4945
+ });
4946
+
4947
+ // src/agents/prompts/08_tools/agents/tools_reviewer.ts
4948
+ var REVIEWER_LSP_TOOLS;
4949
+ var init_tools_reviewer = __esm({
4950
+ "src/agents/prompts/08_tools/agents/tools_reviewer.ts"() {
4951
+ "use strict";
4952
+ init_shared();
4953
+ REVIEWER_LSP_TOOLS = `<lsp_tools>
4954
+ ## LSP Tools for Verification
4955
+
4956
+ **MANDATORY VERIFICATION TOOL**:
4957
+ Use \`${TOOL_NAMES.LSP_DIAGNOSTICS}\` when verifying ${AGENT_NAMES.WORKER} output.
4958
+
4959
+ **VERIFICATION WORKFLOW**:
4960
+ 1. ${AGENT_NAMES.WORKER} claims completion
4961
+ 2. Run \`${TOOL_NAMES.LSP_DIAGNOSTICS}({ file: "*" })\` on affected files
4962
+ 3. Zero errors = ${STATUS_LABEL.PASS.toUpperCase()}, Errors = ${STATUS_LABEL.FAIL.toUpperCase()} + return to ${AGENT_NAMES.WORKER}
4963
+
4964
+ **OUTPUT INTERPRETATION**:
4965
+ - ${OUTPUT_LABEL.ERROR} = ${STATUS_LABEL.ERROR.toUpperCase()} (blocking)
4966
+ - ${OUTPUT_LABEL.WARNING} = ${STATUS_LABEL.WARNING.toUpperCase()} (note but proceed)
4967
+ - Clean = ${STATUS_LABEL.CLEAN.toUpperCase()} (approve)
4968
+
4969
+ **GATEKEEPER RULE**:
4970
+ Do NOT mark [x] in ${PATHS.TODO} without clean ${TOOL_NAMES.LSP_DIAGNOSTICS}.
4971
+ </lsp_tools>`;
4972
+ }
4973
+ });
4974
+
4975
+ // src/agents/prompts/08_tools/agents/tools_worker.ts
4976
+ var WORKER_LSP_TOOLS;
4977
+ var init_tools_worker = __esm({
4978
+ "src/agents/prompts/08_tools/agents/tools_worker.ts"() {
4979
+ "use strict";
4980
+ init_shared();
4981
+ WORKER_LSP_TOOLS = `<lsp_tools>
4982
+ ## LSP Tools for Code Verification
4983
+
4984
+ **AVAILABLE TOOLS**:
4985
+ - \`${TOOL_NAMES.LSP_DIAGNOSTICS}\`: Get errors/warnings BEFORE marking work complete
4986
+ - \`${TOOL_NAMES.AST_SEARCH}\`: Structural code search for pattern matching
4987
+ - \`${TOOL_NAMES.AST_REPLACE}\`: Safe structural code refactoring
4988
+
4989
+ **WHEN TO USE**:
4990
+ 1. After completing file edits \u2192 \`${TOOL_NAMES.LSP_DIAGNOSTICS}({ file: "your-file.ts" })\`
4991
+ 2. Before marking TODO complete \u2192 \`${TOOL_NAMES.LSP_DIAGNOSTICS}({ file: "*" })\`
4992
+ 3. For safe refactoring \u2192 \`${TOOL_NAMES.AST_REPLACE}\`
4993
+
4994
+ **VERIFICATION RULE**:
4995
+ - NEVER claim "done" without running \`${TOOL_NAMES.LSP_DIAGNOSTICS}\`
4996
+ - Zero errors required before completion
4997
+ - Warnings acceptable but should be noted
4998
+ </lsp_tools>`;
4999
+ }
5000
+ });
5001
+
5002
+ // src/agents/prompts/08_tools/index.ts
5003
+ var init_tools2 = __esm({
5004
+ "src/agents/prompts/08_tools/index.ts"() {
4864
5005
  "use strict";
4865
- init_identity4();
4866
- init_forbidden4();
4867
- init_required4();
5006
+ init_tools_core();
5007
+ init_tools_search();
5008
+ init_tools_testing();
5009
+ init_tools_lsp();
5010
+ init_tools_ast();
5011
+ init_tools_code_editing();
5012
+ init_tools_reviewer();
5013
+ init_tools_worker();
4868
5014
  }
4869
5015
  });
4870
5016
 
@@ -4873,16 +5019,30 @@ var init_prompts2 = __esm({
4873
5019
  "src/agents/prompts/index.ts"() {
4874
5020
  "use strict";
4875
5021
  init_philosophy2();
4876
- init_mission2();
4877
- init_verification2();
5022
+ init_shared();
5023
+ init_discovery();
4878
5024
  init_planning();
4879
5025
  init_execution();
4880
- init_discovery();
5026
+ init_verification2();
5027
+ init_mission2();
5028
+ init_commander_role();
5029
+ init_commander_identity();
5030
+ init_commander_forbidden();
5031
+ init_commander_required();
5032
+ init_commander_mandate();
5033
+ init_planner_identity();
5034
+ init_planner_forbidden();
5035
+ init_planner_required();
5036
+ init_planner_mandate();
5037
+ init_worker_identity();
5038
+ init_worker_forbidden();
5039
+ init_worker_required();
5040
+ init_worker_mandate();
5041
+ init_reviewer_identity();
5042
+ init_reviewer_forbidden();
5043
+ init_reviewer_required();
5044
+ init_reviewer_mandate();
4881
5045
  init_tools2();
4882
- init_commander();
4883
- init_planner();
4884
- init_worker();
4885
- init_reviewer();
4886
5046
  }
4887
5047
  });
4888
5048
 
@@ -4892,7 +5052,7 @@ __export(commander_exports, {
4892
5052
  commander: () => commander
4893
5053
  });
4894
5054
  var systemPrompt, commander;
4895
- var init_commander2 = __esm({
5055
+ var init_commander = __esm({
4896
5056
  "src/agents/commander.ts"() {
4897
5057
  "use strict";
4898
5058
  init_constants();
@@ -5794,15 +5954,15 @@ function mergeDefs(...defs) {
5794
5954
  function cloneDef(schema) {
5795
5955
  return mergeDefs(schema._zod.def);
5796
5956
  }
5797
- function getElementAtPath(obj, path9) {
5798
- if (!path9)
5957
+ function getElementAtPath(obj, path10) {
5958
+ if (!path10)
5799
5959
  return obj;
5800
- return path9.reduce((acc, key) => acc?.[key], obj);
5960
+ return path10.reduce((acc, key) => acc?.[key], obj);
5801
5961
  }
5802
5962
  function promiseAllObject(promisesObj) {
5803
5963
  const keys = Object.keys(promisesObj);
5804
- const promises = keys.map((key) => promisesObj[key]);
5805
- return Promise.all(promises).then((results) => {
5964
+ const promises2 = keys.map((key) => promisesObj[key]);
5965
+ return Promise.all(promises2).then((results) => {
5806
5966
  const resolvedObj = {};
5807
5967
  for (let i = 0; i < keys.length; i++) {
5808
5968
  resolvedObj[keys[i]] = results[i];
@@ -6158,11 +6318,11 @@ function aborted(x, startIndex = 0) {
6158
6318
  }
6159
6319
  return false;
6160
6320
  }
6161
- function prefixIssues(path9, issues) {
6321
+ function prefixIssues(path10, issues) {
6162
6322
  return issues.map((iss) => {
6163
6323
  var _a;
6164
6324
  (_a = iss).path ?? (_a.path = []);
6165
- iss.path.unshift(path9);
6325
+ iss.path.unshift(path10);
6166
6326
  return iss;
6167
6327
  });
6168
6328
  }
@@ -6330,7 +6490,7 @@ function treeifyError(error45, _mapper) {
6330
6490
  return issue2.message;
6331
6491
  };
6332
6492
  const result = { errors: [] };
6333
- const processError = (error46, path9 = []) => {
6493
+ const processError = (error46, path10 = []) => {
6334
6494
  var _a, _b;
6335
6495
  for (const issue2 of error46.issues) {
6336
6496
  if (issue2.code === "invalid_union" && issue2.errors.length) {
@@ -6340,7 +6500,7 @@ function treeifyError(error45, _mapper) {
6340
6500
  } else if (issue2.code === "invalid_element") {
6341
6501
  processError({ issues: issue2.issues }, issue2.path);
6342
6502
  } else {
6343
- const fullpath = [...path9, ...issue2.path];
6503
+ const fullpath = [...path10, ...issue2.path];
6344
6504
  if (fullpath.length === 0) {
6345
6505
  result.errors.push(mapper(issue2));
6346
6506
  continue;
@@ -6372,8 +6532,8 @@ function treeifyError(error45, _mapper) {
6372
6532
  }
6373
6533
  function toDotPath(_path) {
6374
6534
  const segs = [];
6375
- const path9 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
6376
- for (const seg of path9) {
6535
+ const path10 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
6536
+ for (const seg of path10) {
6377
6537
  if (typeof seg === "number")
6378
6538
  segs.push(`[${seg}]`);
6379
6539
  else if (typeof seg === "symbol")
@@ -17487,7 +17647,7 @@ tool.schema = external_exports;
17487
17647
 
17488
17648
  // src/agents/definitions.ts
17489
17649
  init_constants();
17490
- init_commander2();
17650
+ init_commander();
17491
17651
 
17492
17652
  // src/agents/subagents/planner.ts
17493
17653
  init_constants();
@@ -18398,10 +18558,11 @@ var ConcurrencyController = class {
18398
18558
  const streak = (this.successStreak.get(key) ?? 0) + 1;
18399
18559
  this.successStreak.set(key, streak);
18400
18560
  this.failureCount.set(key, 0);
18401
- if (streak % 5 === 0) {
18561
+ if (streak >= 3) {
18402
18562
  const currentLimit = this.getConcurrencyLimit(key);
18403
18563
  if (currentLimit < PARALLEL_TASK.MAX_CONCURRENCY) {
18404
18564
  this.setLimit(key, currentLimit + 1);
18565
+ this.successStreak.set(key, 0);
18405
18566
  log(`[concurrency] Auto-scaling UP for ${key}: ${currentLimit + 1}`);
18406
18567
  }
18407
18568
  }
@@ -18414,6 +18575,7 @@ var ConcurrencyController = class {
18414
18575
  const minLimit = 1;
18415
18576
  if (currentLimit > minLimit) {
18416
18577
  this.setLimit(key, currentLimit - 1);
18578
+ this.failureCount.set(key, 0);
18417
18579
  log(`[concurrency] Auto-scaling DOWN for ${key}: ${currentLimit - 1} (due to ${failures} failures)`);
18418
18580
  }
18419
18581
  }
@@ -20077,6 +20239,7 @@ var SessionPool = class _SessionPool {
20077
20239
  await this.deleteSession(oldest.id);
20078
20240
  }
20079
20241
  }
20242
+ await this.resetSession(sessionId);
20080
20243
  session.inUse = false;
20081
20244
  log(`[SessionPool] Released session ${sessionId.slice(0, 8)}... to pool`);
20082
20245
  }
@@ -20153,6 +20316,22 @@ var SessionPool = class _SessionPool {
20153
20316
  // =========================================================================
20154
20317
  // Private Methods
20155
20318
  // =========================================================================
20319
+ /**
20320
+ * Reset/Compact a session to clear context for next reuse.
20321
+ */
20322
+ async resetSession(sessionId) {
20323
+ const session = this.sessionsById.get(sessionId);
20324
+ if (!session) return;
20325
+ log(`[SessionPool] Resetting session ${sessionId.slice(0, 8)}...`);
20326
+ try {
20327
+ await this.client.session.compact?.({ path: { id: sessionId } });
20328
+ session.lastResetAt = /* @__PURE__ */ new Date();
20329
+ session.health = "healthy";
20330
+ } catch (error45) {
20331
+ log(`[SessionPool] Failed to reset session ${sessionId.slice(0, 8)}: ${error45}`);
20332
+ session.health = "degraded";
20333
+ }
20334
+ }
20156
20335
  getPoolKey(agentName) {
20157
20336
  return agentName;
20158
20337
  }
@@ -20180,7 +20359,9 @@ var SessionPool = class _SessionPool {
20180
20359
  createdAt: /* @__PURE__ */ new Date(),
20181
20360
  lastUsedAt: /* @__PURE__ */ new Date(),
20182
20361
  reuseCount: 0,
20183
- inUse: true
20362
+ inUse: true,
20363
+ health: "healthy",
20364
+ lastResetAt: /* @__PURE__ */ new Date()
20184
20365
  };
20185
20366
  const poolKey = this.getPoolKey(agentName);
20186
20367
  const agentPool = this.pool.get(poolKey) || [];
@@ -20250,33 +20431,122 @@ var TerminalMonitor = class _TerminalMonitor {
20250
20431
  // src/core/agents/manager.ts
20251
20432
  init_core2();
20252
20433
 
20253
- // src/core/loop/todo-manager.ts
20434
+ // src/core/todo/todo-manager.ts
20254
20435
  init_shared();
20255
- import { readFileSync, writeFileSync, existsSync as existsSync3 } from "node:fs";
20256
- import { join as join5 } from "node:path";
20436
+ import * as fs5 from "node:fs";
20437
+ import * as path5 from "node:path";
20438
+ import * as crypto2 from "node:crypto";
20257
20439
  var TodoManager = class _TodoManager {
20258
- static instance;
20440
+ static _instance;
20259
20441
  directory = "";
20442
+ todoPath = "";
20443
+ versionPath = "";
20444
+ historyPath = "";
20445
+ updateMutex = Promise.resolve();
20260
20446
  constructor() {
20261
20447
  }
20262
- static getInstance() {
20263
- if (!_TodoManager.instance) {
20264
- _TodoManager.instance = new _TodoManager();
20448
+ static getInstance(directory) {
20449
+ if (!_TodoManager._instance) {
20450
+ _TodoManager._instance = new _TodoManager();
20451
+ }
20452
+ if (directory) {
20453
+ _TodoManager._instance.setDirectory(directory);
20265
20454
  }
20266
- return _TodoManager.instance;
20455
+ return _TodoManager._instance;
20267
20456
  }
20268
20457
  setDirectory(dir) {
20269
20458
  this.directory = dir;
20459
+ this.todoPath = path5.join(this.directory, PATHS.TODO);
20460
+ this.versionPath = path5.join(this.directory, ".opencode/todo.version.json");
20461
+ this.historyPath = path5.join(this.directory, ".opencode/archive/todo_history.jsonl");
20462
+ const archiveDir = path5.dirname(this.historyPath);
20463
+ if (!fs5.existsSync(archiveDir)) {
20464
+ fs5.mkdirSync(archiveDir, { recursive: true });
20465
+ }
20466
+ }
20467
+ async readWithVersion() {
20468
+ if (!this.directory) throw new Error("Directory not set");
20469
+ try {
20470
+ const content = fs5.existsSync(this.todoPath) ? await fs5.promises.readFile(this.todoPath, "utf-8") : "";
20471
+ let versionInfo = {
20472
+ version: 0,
20473
+ timestamp: Date.now(),
20474
+ author: "system"
20475
+ };
20476
+ if (fs5.existsSync(this.versionPath)) {
20477
+ try {
20478
+ const data = await fs5.promises.readFile(this.versionPath, "utf-8");
20479
+ versionInfo = JSON.parse(data);
20480
+ } catch (e) {
20481
+ log(`[TodoManager] Failed to parse version file: ${e}`);
20482
+ }
20483
+ }
20484
+ return { content, version: versionInfo };
20485
+ } catch (error45) {
20486
+ log(`[TodoManager] Error reading TODO: ${error45}`);
20487
+ return { content: "", version: { version: 0, timestamp: Date.now(), author: "system" } };
20488
+ }
20270
20489
  }
20271
20490
  /**
20272
- * Update a specific TODO item by its text content
20491
+ * Update TODO with both MVCC (for logical consistency) and Mutex (for atomicity)
20273
20492
  */
20274
- updateItem(searchText, newStatus) {
20275
- const todoPath = join5(this.directory, PATHS.TODO);
20276
- if (!existsSync3(todoPath)) return false;
20277
- try {
20278
- const content = readFileSync(todoPath, "utf-8");
20279
- const lines = content.split("\n");
20493
+ async update(expectedVersion, updater, author) {
20494
+ return new Promise((resolve2, reject) => {
20495
+ this.updateMutex = this.updateMutex.then(async () => {
20496
+ try {
20497
+ const result = await this._internalUpdate(expectedVersion, updater, author);
20498
+ resolve2(result);
20499
+ } catch (e) {
20500
+ reject(e);
20501
+ }
20502
+ }).catch((e) => {
20503
+ log(`[TodoManager] Mutex error: ${e}`);
20504
+ });
20505
+ });
20506
+ }
20507
+ async _internalUpdate(expectedVersion, updater, author) {
20508
+ const MAX_RETRIES2 = 3;
20509
+ const RETRY_DELAY = 50;
20510
+ for (let attempt = 0; attempt < MAX_RETRIES2; attempt++) {
20511
+ try {
20512
+ const current = await this.readWithVersion();
20513
+ if (current.version.version !== expectedVersion) {
20514
+ log(`[TodoManager] Conflict: expected v${expectedVersion}, found v${current.version.version}`);
20515
+ return {
20516
+ success: false,
20517
+ currentVersion: current.version.version,
20518
+ conflict: true
20519
+ };
20520
+ }
20521
+ const newContent = updater(current.content);
20522
+ const newVersion = current.version.version + 1;
20523
+ const tmpPath = `${this.todoPath}.tmp.${Date.now()}.${Math.random().toString(36).slice(2)}`;
20524
+ await fs5.promises.writeFile(tmpPath, newContent, "utf-8");
20525
+ await fs5.promises.writeFile(
20526
+ this.versionPath,
20527
+ JSON.stringify({
20528
+ version: newVersion,
20529
+ timestamp: Date.now(),
20530
+ author
20531
+ }),
20532
+ "utf-8"
20533
+ );
20534
+ await fs5.promises.rename(tmpPath, this.todoPath);
20535
+ this.logChange(newVersion, newContent, author).catch(() => {
20536
+ });
20537
+ log(`[TodoManager] Updated TODO to v${newVersion} by ${author}`);
20538
+ return { success: true, currentVersion: newVersion };
20539
+ } catch (error45) {
20540
+ if (attempt === MAX_RETRIES2 - 1) throw error45;
20541
+ await new Promise((r) => setTimeout(r, RETRY_DELAY));
20542
+ }
20543
+ }
20544
+ throw new Error("Failed to update TODO");
20545
+ }
20546
+ async updateItem(searchText, newStatus, author = "system") {
20547
+ let retries = 5;
20548
+ while (retries-- > 0) {
20549
+ const data = await this.readWithVersion();
20280
20550
  const statusMap = {
20281
20551
  [TODO_CONSTANTS.STATUS.PENDING]: TODO_CONSTANTS.MARKERS.PENDING,
20282
20552
  [TODO_CONSTANTS.STATUS.COMPLETED]: TODO_CONSTANTS.MARKERS.COMPLETED,
@@ -20284,57 +20554,63 @@ var TodoManager = class _TodoManager {
20284
20554
  [TODO_CONSTANTS.STATUS.FAILED]: TODO_CONSTANTS.MARKERS.FAILED
20285
20555
  };
20286
20556
  const marker = statusMap[newStatus] || TODO_CONSTANTS.MARKERS.PENDING;
20287
- let updated = false;
20288
- const newLines = lines.map((line) => {
20289
- if (line.includes(searchText) && (line.includes(TODO_CONSTANTS.MARKERS.PENDING) || line.includes(TODO_CONSTANTS.MARKERS.PROGRESS) || line.includes(TODO_CONSTANTS.MARKERS.COMPLETED) || line.includes(TODO_CONSTANTS.MARKERS.FAILED))) {
20290
- updated = true;
20291
- return line.replace(/\[[ x\/\-]\]/, marker);
20292
- }
20293
- return line;
20294
- });
20295
- if (updated) {
20296
- writeFileSync(todoPath, newLines.join("\n"), "utf-8");
20297
- log(`[TodoManager] Updated item: "${searchText}" -> ${newStatus}`);
20298
- return true;
20299
- }
20300
- return false;
20301
- } catch (error45) {
20302
- log(`[TodoManager] Error updating TODO: ${error45}`);
20303
- return false;
20557
+ const result = await this.update(data.version.version, (content) => {
20558
+ const lines = content.split("\n");
20559
+ let updated = false;
20560
+ const newLines = lines.map((line) => {
20561
+ if (line.includes(searchText) && /\[[ x\/\-]\]/.test(line)) {
20562
+ updated = true;
20563
+ return line.replace(/\[[ x\/\-]\]/, marker);
20564
+ }
20565
+ return line;
20566
+ });
20567
+ return updated ? newLines.join("\n") : content;
20568
+ }, author);
20569
+ if (result.success) return true;
20570
+ if (!result.conflict) return false;
20571
+ await new Promise((r) => setTimeout(r, 50));
20304
20572
  }
20573
+ return false;
20305
20574
  }
20306
- /**
20307
- * Add a new sub-task under a parent task
20308
- */
20309
- addSubTask(parentText, subTaskText) {
20310
- const todoPath = join5(this.directory, PATHS.TODO);
20311
- if (!existsSync3(todoPath)) return false;
20312
- try {
20313
- const content = readFileSync(todoPath, "utf-8");
20314
- const lines = content.split("\n");
20315
- let parentIndex = -1;
20316
- let parentIndent = "";
20317
- for (let i = 0; i < lines.length; i++) {
20318
- if (lines[i].includes(parentText)) {
20319
- parentIndex = i;
20320
- const match = lines[i].match(/^(\s*)/);
20321
- parentIndent = match ? match[1] : "";
20322
- break;
20323
- }
20324
- }
20325
- if (parentIndex !== -1) {
20326
- const subTaskIndent = parentIndent + " ";
20327
- const newLine = `${subTaskIndent}- ${TODO_CONSTANTS.MARKERS.PENDING} ${subTaskText}`;
20328
- lines.splice(parentIndex + 1, 0, newLine);
20329
- writeFileSync(todoPath, lines.join("\n"), "utf-8");
20330
- log(`[TodoManager] Added sub-task: "${subTaskText}" under "${parentText}"`);
20331
- return true;
20332
- }
20333
- return false;
20334
- } catch (error45) {
20335
- log(`[TodoManager] Error adding sub-task: ${error45}`);
20336
- return false;
20575
+ async addSubTask(parentText, subTaskText, author = "system") {
20576
+ let retries = 5;
20577
+ while (retries-- > 0) {
20578
+ const data = await this.readWithVersion();
20579
+ const result = await this.update(data.version.version, (content) => {
20580
+ const lines = content.split("\n");
20581
+ let parentIndex = -1;
20582
+ let parentIndent = "";
20583
+ for (let i = 0; i < lines.length; i++) {
20584
+ if (lines[i].includes(parentText)) {
20585
+ parentIndex = i;
20586
+ const match = lines[i].match(/^(\s*)/);
20587
+ parentIndent = match ? match[1] : "";
20588
+ break;
20589
+ }
20590
+ }
20591
+ if (parentIndex !== -1) {
20592
+ const subTaskIndent = parentIndent + " ";
20593
+ const newLine = `${subTaskIndent}- ${TODO_CONSTANTS.MARKERS.PENDING} ${subTaskText}`;
20594
+ lines.splice(parentIndex + 1, 0, newLine);
20595
+ return lines.join("\n");
20596
+ }
20597
+ return content;
20598
+ }, author);
20599
+ if (result.success) return true;
20600
+ if (!result.conflict) return false;
20601
+ await new Promise((r) => setTimeout(r, 50));
20337
20602
  }
20603
+ return false;
20604
+ }
20605
+ async logChange(version2, content, author) {
20606
+ const entry = {
20607
+ version: version2,
20608
+ timestamp: Date.now(),
20609
+ author,
20610
+ contentHash: crypto2.createHash("sha256").update(content).digest("hex"),
20611
+ size: content.length
20612
+ };
20613
+ await fs5.promises.appendFile(this.historyPath, JSON.stringify(entry) + "\n", "utf-8");
20338
20614
  }
20339
20615
  };
20340
20616
 
@@ -21093,11 +21369,11 @@ var createUpdateTodoTool = () => tool({
21093
21369
  const manager = TodoManager.getInstance();
21094
21370
  if (args.action === "update") {
21095
21371
  if (!args.status) return `${OUTPUT_LABEL.ERROR} 'status' is required for update action.`;
21096
- const success2 = manager.updateItem(args.task, args.status);
21372
+ const success2 = await manager.updateItem(args.task, args.status);
21097
21373
  return success2 ? `${OUTPUT_LABEL.DONE} Updated task status: "${args.task}" -> ${args.status}` : `${OUTPUT_LABEL.ERROR} Task not found: "${args.task}"`;
21098
21374
  } else {
21099
21375
  if (!args.subtask) return `${OUTPUT_LABEL.ERROR} 'subtask' is required for add action.`;
21100
- const success2 = manager.addSubTask(args.task, args.subtask);
21376
+ const success2 = await manager.addSubTask(args.task, args.subtask);
21101
21377
  return success2 ? `${OUTPUT_LABEL.DONE} Added sub-task: "${args.subtask}" under "${args.task}"` : `${OUTPUT_LABEL.ERROR} Parent task not found: "${args.task}"`;
21102
21378
  }
21103
21379
  }
@@ -21168,15 +21444,15 @@ var METADATA_FILE = PATHS.DOC_METADATA;
21168
21444
  var DEFAULT_TTL_MS = CACHE.DEFAULT_TTL_MS;
21169
21445
 
21170
21446
  // src/core/cache/operations.ts
21171
- import * as fs6 from "node:fs/promises";
21172
- import * as path5 from "node:path";
21447
+ import * as fs7 from "node:fs/promises";
21448
+ import * as path6 from "node:path";
21173
21449
 
21174
21450
  // src/core/cache/utils.ts
21175
- import * as fs5 from "node:fs/promises";
21451
+ import * as fs6 from "node:fs/promises";
21176
21452
  import { existsSync as existsSync4 } from "node:fs";
21177
21453
  async function ensureCacheDir() {
21178
21454
  if (!existsSync4(CACHE_DIR)) {
21179
- await fs5.mkdir(CACHE_DIR, { recursive: true });
21455
+ await fs6.mkdir(CACHE_DIR, { recursive: true });
21180
21456
  }
21181
21457
  }
21182
21458
  function urlToFilename(url2) {
@@ -21191,7 +21467,7 @@ function urlToFilename(url2) {
21191
21467
  }
21192
21468
  async function readMetadata() {
21193
21469
  try {
21194
- const content = await fs5.readFile(METADATA_FILE, "utf-8");
21470
+ const content = await fs6.readFile(METADATA_FILE, "utf-8");
21195
21471
  return JSON.parse(content);
21196
21472
  } catch {
21197
21473
  return { documents: {}, lastUpdated: (/* @__PURE__ */ new Date()).toISOString() };
@@ -21200,7 +21476,7 @@ async function readMetadata() {
21200
21476
  async function writeMetadata(metadata) {
21201
21477
  await ensureCacheDir();
21202
21478
  metadata.lastUpdated = (/* @__PURE__ */ new Date()).toISOString();
21203
- await fs5.writeFile(METADATA_FILE, JSON.stringify(metadata, null, 2));
21479
+ await fs6.writeFile(METADATA_FILE, JSON.stringify(metadata, null, 2));
21204
21480
  }
21205
21481
 
21206
21482
  // src/core/cache/operations.ts
@@ -21214,8 +21490,8 @@ async function get2(url2) {
21214
21490
  return null;
21215
21491
  }
21216
21492
  try {
21217
- const filepath = path5.join(CACHE_DIR, filename);
21218
- const content = await fs6.readFile(filepath, "utf-8");
21493
+ const filepath = path6.join(CACHE_DIR, filename);
21494
+ const content = await fs7.readFile(filepath, "utf-8");
21219
21495
  return { ...entry, content };
21220
21496
  } catch {
21221
21497
  return null;
@@ -21226,8 +21502,8 @@ async function getByFilename(filename) {
21226
21502
  const entry = metadata.documents[filename];
21227
21503
  if (!entry) return null;
21228
21504
  try {
21229
- const filepath = path5.join(CACHE_DIR, filename);
21230
- const content = await fs6.readFile(filepath, "utf-8");
21505
+ const filepath = path6.join(CACHE_DIR, filename);
21506
+ const content = await fs7.readFile(filepath, "utf-8");
21231
21507
  return { ...entry, content };
21232
21508
  } catch {
21233
21509
  return null;
@@ -21236,7 +21512,7 @@ async function getByFilename(filename) {
21236
21512
  async function set2(url2, content, title, ttlMs = DEFAULT_TTL_MS) {
21237
21513
  await ensureCacheDir();
21238
21514
  const filename = urlToFilename(url2);
21239
- const filepath = path5.join(CACHE_DIR, filename);
21515
+ const filepath = path6.join(CACHE_DIR, filename);
21240
21516
  const now = /* @__PURE__ */ new Date();
21241
21517
  const header = `# ${title}
21242
21518
 
@@ -21247,7 +21523,7 @@ async function set2(url2, content, title, ttlMs = DEFAULT_TTL_MS) {
21247
21523
 
21248
21524
  `;
21249
21525
  const fullContent = header + content;
21250
- await fs6.writeFile(filepath, fullContent);
21526
+ await fs7.writeFile(filepath, fullContent);
21251
21527
  const metadata = await readMetadata();
21252
21528
  metadata.documents[filename] = {
21253
21529
  url: url2,
@@ -21261,9 +21537,9 @@ async function set2(url2, content, title, ttlMs = DEFAULT_TTL_MS) {
21261
21537
  }
21262
21538
  async function remove(url2) {
21263
21539
  const filename = urlToFilename(url2);
21264
- const filepath = path5.join(CACHE_DIR, filename);
21540
+ const filepath = path6.join(CACHE_DIR, filename);
21265
21541
  try {
21266
- await fs6.unlink(filepath);
21542
+ await fs7.unlink(filepath);
21267
21543
  const metadata = await readMetadata();
21268
21544
  delete metadata.documents[filename];
21269
21545
  await writeMetadata(metadata);
@@ -21285,9 +21561,9 @@ async function clear3() {
21285
21561
  const metadata = await readMetadata();
21286
21562
  const count = Object.keys(metadata.documents).length;
21287
21563
  for (const filename of Object.keys(metadata.documents)) {
21288
- const filepath = path5.join(CACHE_DIR, filename);
21564
+ const filepath = path6.join(CACHE_DIR, filename);
21289
21565
  try {
21290
- await fs6.unlink(filepath);
21566
+ await fs7.unlink(filepath);
21291
21567
  } catch {
21292
21568
  }
21293
21569
  }
@@ -21948,8 +22224,8 @@ ${r.content}
21948
22224
  });
21949
22225
 
21950
22226
  // src/tools/lsp/diagnostics-cache.ts
21951
- import fs7 from "fs/promises";
21952
- import path6 from "path";
22227
+ import fs8 from "fs/promises";
22228
+ import path7 from "path";
21953
22229
  var DiagnosticsCache = class {
21954
22230
  cache = /* @__PURE__ */ new Map();
21955
22231
  defaultTTL = 3e4;
@@ -21992,10 +22268,10 @@ var DiagnosticsCache = class {
21992
22268
  }
21993
22269
  async getFilesMtime(directory, file2) {
21994
22270
  if (file2 && file2 !== "*") {
21995
- const stats3 = await fs7.stat(path6.join(directory, file2));
22271
+ const stats3 = await fs8.stat(path7.join(directory, file2));
21996
22272
  return stats3.mtimeMs;
21997
22273
  }
21998
- const stats2 = await fs7.stat(directory);
22274
+ const stats2 = await fs8.stat(directory);
21999
22275
  return stats2.mtimeMs;
22000
22276
  }
22001
22277
  };
@@ -22068,20 +22344,76 @@ var HookRegistry = class _HookRegistry {
22068
22344
  }
22069
22345
  return _HookRegistry.instance;
22070
22346
  }
22071
- registerPreTool(hook) {
22072
- this.preToolHooks.push(hook);
22347
+ registerPreTool(hook, metadata) {
22348
+ this.preToolHooks.push({ hook, metadata: this.prepareMetadata(hook.name, metadata) });
22349
+ this.sortHooks(this.preToolHooks);
22350
+ }
22351
+ registerPostTool(hook, metadata) {
22352
+ this.postToolHooks.push({ hook, metadata: this.prepareMetadata(hook.name, metadata) });
22353
+ this.sortHooks(this.postToolHooks);
22073
22354
  }
22074
- registerPostTool(hook) {
22075
- this.postToolHooks.push(hook);
22355
+ registerChat(hook, metadata) {
22356
+ this.chatHooks.push({ hook, metadata: this.prepareMetadata(hook.name, metadata) });
22357
+ this.sortHooks(this.chatHooks);
22076
22358
  }
22077
- registerChat(hook) {
22078
- this.chatHooks.push(hook);
22359
+ registerDone(hook, metadata) {
22360
+ this.doneHooks.push({ hook, metadata: this.prepareMetadata(hook.name, metadata) });
22361
+ this.sortHooks(this.doneHooks);
22362
+ }
22363
+ prepareMetadata(name, metadata) {
22364
+ return {
22365
+ name: metadata?.name || name,
22366
+ priority: metadata?.priority ?? 50,
22367
+ phase: metadata?.phase || "normal",
22368
+ dependencies: metadata?.dependencies || [],
22369
+ errorHandling: metadata?.errorHandling || "continue"
22370
+ };
22079
22371
  }
22080
- registerDone(hook) {
22081
- this.doneHooks.push(hook);
22372
+ sortHooks(registrations) {
22373
+ registrations.sort((a, b) => {
22374
+ const phaseOrder = { early: 0, normal: 1, late: 2 };
22375
+ const phaseA = phaseOrder[a.metadata.phase || "normal"];
22376
+ const phaseB = phaseOrder[b.metadata.phase || "normal"];
22377
+ if (phaseA !== phaseB) return phaseA - phaseB;
22378
+ return a.metadata.priority - b.metadata.priority;
22379
+ });
22380
+ try {
22381
+ const sorted = this.topologicalSort(registrations);
22382
+ registrations.length = 0;
22383
+ registrations.push(...sorted);
22384
+ } catch (e) {
22385
+ log(`[HookRegistry] Dependency sort failed: ${e}`);
22386
+ throw e;
22387
+ }
22388
+ }
22389
+ topologicalSort(registrations) {
22390
+ const sorted = [];
22391
+ const visited = /* @__PURE__ */ new Set();
22392
+ const visiting = /* @__PURE__ */ new Set();
22393
+ const nameToReg = new Map(registrations.map((r) => [r.metadata.name, r]));
22394
+ const visit = (name) => {
22395
+ if (visiting.has(name)) {
22396
+ throw new Error(`Circular dependency detected in hooks: ${name}`);
22397
+ }
22398
+ if (visited.has(name)) return;
22399
+ visiting.add(name);
22400
+ const reg = nameToReg.get(name);
22401
+ if (reg) {
22402
+ for (const dep of reg.metadata.dependencies || []) {
22403
+ visit(dep);
22404
+ }
22405
+ }
22406
+ visiting.delete(name);
22407
+ visited.add(name);
22408
+ if (reg) sorted.push(reg);
22409
+ };
22410
+ for (const reg of registrations) {
22411
+ visit(reg.metadata.name);
22412
+ }
22413
+ return sorted;
22082
22414
  }
22083
22415
  async executePreTool(ctx, tool2, args) {
22084
- for (const hook of this.preToolHooks) {
22416
+ for (const { hook, metadata } of this.preToolHooks) {
22085
22417
  try {
22086
22418
  const result = await hook.execute(ctx, tool2, args);
22087
22419
  if (result.action === HOOK_ACTIONS.BLOCK) return result;
@@ -22089,26 +22421,28 @@ var HookRegistry = class _HookRegistry {
22089
22421
  args = result.modifiedArgs;
22090
22422
  }
22091
22423
  } catch (e) {
22092
- log(`[HookRegistry] Error in PreTool hook ${hook.name}`, e);
22424
+ log(`[HookRegistry] Error in PreTool hook ${metadata.name}`, e);
22425
+ if (metadata.errorHandling === "stop") throw e;
22093
22426
  }
22094
22427
  }
22095
22428
  return { action: HOOK_ACTIONS.ALLOW, modifiedArgs: args };
22096
22429
  }
22097
22430
  async executePostTool(ctx, tool2, input, output) {
22098
- for (const hook of this.postToolHooks) {
22431
+ for (const { hook, metadata } of this.postToolHooks) {
22099
22432
  try {
22100
22433
  const result = await hook.execute(ctx, tool2, input, output);
22101
22434
  if (result?.output) {
22102
22435
  output.output = result.output;
22103
22436
  }
22104
22437
  } catch (e) {
22105
- log(`[HookRegistry] Error in PostTool hook ${hook.name}`, e);
22438
+ log(`[HookRegistry] Error in PostTool hook ${metadata.name}`, e);
22439
+ if (metadata.errorHandling === "stop") throw e;
22106
22440
  }
22107
22441
  }
22108
22442
  }
22109
22443
  async executeChat(ctx, message) {
22110
22444
  let currentMessage = message;
22111
- for (const hook of this.chatHooks) {
22445
+ for (const { hook, metadata } of this.chatHooks) {
22112
22446
  try {
22113
22447
  const result = await hook.execute(ctx, currentMessage);
22114
22448
  if (result.action === HOOK_ACTIONS.INTERCEPT) {
@@ -22118,13 +22452,14 @@ var HookRegistry = class _HookRegistry {
22118
22452
  currentMessage = result.modifiedMessage;
22119
22453
  }
22120
22454
  } catch (e) {
22121
- log(`[HookRegistry] Error in Chat hook ${hook.name}`, e);
22455
+ log(`[HookRegistry] Error in Chat hook ${metadata.name}`, e);
22456
+ if (metadata.errorHandling === "stop") throw e;
22122
22457
  }
22123
22458
  }
22124
22459
  return { action: HOOK_ACTIONS.PROCESS, modifiedMessage: currentMessage };
22125
22460
  }
22126
22461
  async executeDone(ctx, finalText) {
22127
- for (const hook of this.doneHooks) {
22462
+ for (const { hook, metadata } of this.doneHooks) {
22128
22463
  try {
22129
22464
  const result = await hook.execute(ctx, finalText);
22130
22465
  if (result.action === HOOK_ACTIONS.STOP) {
@@ -22134,7 +22469,8 @@ var HookRegistry = class _HookRegistry {
22134
22469
  return result;
22135
22470
  }
22136
22471
  } catch (e) {
22137
- log(`[HookRegistry] Error in Done hook ${hook.name}`, e);
22472
+ log(`[HookRegistry] Error in Done hook ${metadata.name}`, e);
22473
+ if (metadata.errorHandling === "stop") throw e;
22138
22474
  }
22139
22475
  }
22140
22476
  return { action: HOOK_ACTIONS.CONTINUE };
@@ -22262,7 +22598,7 @@ function checkOutputSanity(text) {
22262
22598
  init_shared();
22263
22599
 
22264
22600
  // src/core/loop/mission-loop.ts
22265
- import { existsSync as existsSync5, readFileSync as readFileSync2, writeFileSync as writeFileSync2, unlinkSync, mkdirSync } from "node:fs";
22601
+ import { existsSync as existsSync5, readFileSync, writeFileSync, unlinkSync, mkdirSync as mkdirSync2 } from "node:fs";
22266
22602
  import { join as join7 } from "node:path";
22267
22603
  init_shared();
22268
22604
 
@@ -22316,8 +22652,11 @@ var CONTINUE_INSTRUCTION = `<auto_continue>
22316
22652
  <rules>
22317
22653
  1. DO NOT stop - mission is incomplete
22318
22654
  2. DO NOT wait for user input
22319
- 3. If previous action failed, try different approach
22320
- 4. Check your hierarchical todo list - complete ALL pending items
22655
+ 3. **PROACTIVE THINKING MANDATORY**: If background tasks are running, use the time to:
22656
+ - Run \`check_background_task\` to audit logs and ensure no deadlocks.
22657
+ - speculatively plan the next steps or prepare necessary code templates.
22658
+ - execute independent sub-tasks from the TODO list.
22659
+ 4. If previous action failed, try different approach
22321
22660
  5. Breakdown abstract tasks into Grade 3 sub-tasks before execution
22322
22661
  </rules>
22323
22662
 
@@ -22349,7 +22688,7 @@ function readLoopState(directory) {
22349
22688
  return null;
22350
22689
  }
22351
22690
  try {
22352
- const content = readFileSync2(filePath, "utf-8");
22691
+ const content = readFileSync(filePath, "utf-8");
22353
22692
  return JSON.parse(content);
22354
22693
  } catch (error45) {
22355
22694
  log(`[${MISSION_CONTROL.LOG_SOURCE}] Failed to read state: ${error45}`);
@@ -22361,9 +22700,9 @@ function writeLoopState(directory, state2) {
22361
22700
  const dirPath = join7(directory, PATHS.OPENCODE);
22362
22701
  try {
22363
22702
  if (!existsSync5(dirPath)) {
22364
- mkdirSync(dirPath, { recursive: true });
22703
+ mkdirSync2(dirPath, { recursive: true });
22365
22704
  }
22366
- writeFileSync2(filePath, JSON.stringify(state2, null, 2), "utf-8");
22705
+ writeFileSync(filePath, JSON.stringify(state2, null, 2), "utf-8");
22367
22706
  return true;
22368
22707
  } catch (error45) {
22369
22708
  log(`[${MISSION_CONTROL.LOG_SOURCE}] Failed to write state: ${error45}`);
@@ -22443,6 +22782,18 @@ ${state2.prompt}
22443
22782
  **NOW**: Continue executing!
22444
22783
  </mission_loop>`;
22445
22784
  }
22785
+ var STAGNATION_INTERVENTION = `
22786
+ <system_intervention type="stagnation_detected">
22787
+ \u26A0\uFE0F **\uACBD\uACE0: \uC9C4\uD589 \uC815\uCCB4 \uAC10\uC9C0 (STAGNATION DETECTED)**
22788
+ \uCD5C\uADFC \uC5EC\uB7EC \uD134 \uB3D9\uC548 \uC2E4\uC9C8\uC801\uC778 \uC9C4\uC804\uC774 \uAC10\uC9C0\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4. \uB2E8\uC21C "\uBAA8\uB2C8\uD130\uB9C1"\uC774\uB098 \uAC19\uC740 \uD589\uB3D9\uC744 \uBC18\uBCF5\uD558\uB294 \uAC83\uC740 \uAE08\uC9C0\uB429\uB2C8\uB2E4.
22789
+
22790
+ **\uC790\uC728\uC801 \uC9C4\uB2E8 \uBC0F \uD574\uACB0 \uC9C0\uCE68:**
22791
+ 1. **\uC2E4\uC2DC\uAC04 \uB85C\uADF8 \uD655\uC778**: \`check_background_task\` \uB610\uB294 \`read_file\`\uC744 \uC0AC\uC6A9\uD558\uC5EC \uC9C4\uD589 \uC911\uC778 \uC791\uC5C5\uC758 \uCD9C\uB825 \uB85C\uADF8\uB97C \uC9C1\uC811 \uD655\uC778\uD558\uC2ED\uC2DC\uC624.
22792
+ 2. **\uD504\uB85C\uC138\uC2A4 \uC0DD\uC874 \uC9C4\uB2E8**: \uC791\uC5C5\uC774 \uC880\uBE44 \uC0C1\uD0DC\uC774\uAC70\uB098 \uBA48\uCD98 \uAC83 \uAC19\uB2E4\uBA74 \uACFC\uAC10\uD558\uAC8C \`kill\`\uD558\uACE0 \uB2E8\uACC4\uB97C \uC138\uBD84\uD654\uD558\uC5EC \uB2E4\uC2DC \uC2E4\uD589\uD558\uC2ED\uC2DC\uC624.
22793
+ 3. **\uC804\uB7B5 \uC804\uD658**: \uB3D9\uC77C\uD55C \uC811\uADFC \uBC29\uC2DD\uC774 \uC2E4\uD328\uD558\uACE0 \uC788\uB2E4\uBA74, \uB2E4\uB978 \uB3C4\uAD6C\uB098 \uBC29\uBC95\uC744 \uC0AC\uC6A9\uD558\uC5EC \uBAA9\uD45C\uC5D0 \uB3C4\uB2EC\uD558\uC2ED\uC2DC\uC624.
22794
+
22795
+ **\uC9C0\uAE08 \uBC14\uB85C \uB2A5\uB3D9\uC801\uC73C\uB85C \uAC1C\uC785\uD558\uC2ED\uC2DC\uC624. \uB300\uAE30\uD558\uC9C0 \uB9C8\uC2ED\uC2DC\uC624.**
22796
+ </system_intervention>`;
22446
22797
 
22447
22798
  // src/core/orchestrator/session-manager.ts
22448
22799
  function ensureSessionInitialized(sessions, sessionID, directory) {
@@ -22659,7 +23010,7 @@ function formatElapsedTime(startMs, endMs = Date.now()) {
22659
23010
 
22660
23011
  // src/core/loop/verification.ts
22661
23012
  init_shared();
22662
- import { existsSync as existsSync6, readFileSync as readFileSync3 } from "node:fs";
23013
+ import { existsSync as existsSync6, readFileSync as readFileSync2 } from "node:fs";
22663
23014
  import { join as join8 } from "node:path";
22664
23015
  var CHECKLIST_FILE = CHECKLIST.FILE;
22665
23016
  function parseChecklistLine(line, currentCategory) {
@@ -22730,7 +23081,7 @@ function readChecklist(directory) {
22730
23081
  return [];
22731
23082
  }
22732
23083
  try {
22733
- const content = readFileSync3(filePath, "utf-8");
23084
+ const content = readFileSync2(filePath, "utf-8");
22734
23085
  return parseChecklist(content);
22735
23086
  } catch (error45) {
22736
23087
  log(`[checklist] Failed to read checklist: ${error45}`);
@@ -22827,7 +23178,7 @@ function verifyMissionCompletion(directory) {
22827
23178
  const todoPath = join8(directory, PATHS.TODO);
22828
23179
  if (existsSync6(todoPath)) {
22829
23180
  try {
22830
- const content = readFileSync3(todoPath, "utf-8");
23181
+ const content = readFileSync2(todoPath, "utf-8");
22831
23182
  const incompleteCount = countMatches(content, TODO_INCOMPLETE_PATTERN);
22832
23183
  const completeCount = countMatches(content, TODO_COMPLETE_PATTERN);
22833
23184
  const total = incompleteCount + completeCount;
@@ -22852,7 +23203,7 @@ function verifyMissionCompletion(directory) {
22852
23203
  const syncPath = join8(directory, PATHS.SYNC_ISSUES);
22853
23204
  if (existsSync6(syncPath)) {
22854
23205
  try {
22855
- const content = readFileSync3(syncPath, "utf-8");
23206
+ const content = readFileSync2(syncPath, "utf-8");
22856
23207
  result.syncIssuesEmpty = !hasRealSyncIssues(content);
22857
23208
  if (!result.syncIssuesEmpty) {
22858
23209
  const issueLines = content.split("\n").filter(
@@ -22991,10 +23342,10 @@ async function resolveCommandPath(key, commandName) {
22991
23342
  const currentPending = pending.get(key);
22992
23343
  if (currentPending) return currentPending;
22993
23344
  const promise2 = (async () => {
22994
- const path9 = await findCommand(commandName);
22995
- cache[key] = path9;
23345
+ const path10 = await findCommand(commandName);
23346
+ cache[key] = path10;
22996
23347
  pending.delete(key);
22997
- return path9;
23348
+ return path10;
22998
23349
  })();
22999
23350
  pending.set(key, promise2);
23000
23351
  return promise2;
@@ -23003,21 +23354,21 @@ async function resolveCommandPath(key, commandName) {
23003
23354
  // src/core/notification/os-notify/notifier.ts
23004
23355
  var execAsync2 = promisify2(exec2);
23005
23356
  async function notifyDarwin(title, message) {
23006
- const path9 = await resolveCommandPath(
23357
+ const path10 = await resolveCommandPath(
23007
23358
  NOTIFICATION_COMMAND_KEYS.OSASCRIPT,
23008
23359
  NOTIFICATION_COMMANDS.OSASCRIPT
23009
23360
  );
23010
- if (!path9) return;
23361
+ if (!path10) return;
23011
23362
  const escT = title.replace(/"/g, '\\"');
23012
23363
  const escM = message.replace(/"/g, '\\"');
23013
- await execAsync2(`${path9} -e 'display notification "${escM}" with title "${escT}" sound name "Glass"'`);
23364
+ await execAsync2(`${path10} -e 'display notification "${escM}" with title "${escT}" sound name "Glass"'`);
23014
23365
  }
23015
23366
  async function notifyLinux(title, message) {
23016
- const path9 = await resolveCommandPath(
23367
+ const path10 = await resolveCommandPath(
23017
23368
  NOTIFICATION_COMMAND_KEYS.NOTIFY_SEND,
23018
23369
  NOTIFICATION_COMMANDS.NOTIFY_SEND
23019
23370
  );
23020
- if (path9) await execAsync2(`${path9} "${title}" "${message}" 2>/dev/null`);
23371
+ if (path10) await execAsync2(`${path10} "${title}" "${message}" 2>/dev/null`);
23021
23372
  }
23022
23373
  async function notifyWindows(title, message) {
23023
23374
  const ps = await resolveCommandPath(
@@ -23064,11 +23415,11 @@ init_os();
23064
23415
  async function playDarwin(soundPath) {
23065
23416
  if (!soundPath) return;
23066
23417
  try {
23067
- const path9 = await resolveCommandPath(
23418
+ const path10 = await resolveCommandPath(
23068
23419
  NOTIFICATION_COMMAND_KEYS.AFPLAY,
23069
23420
  NOTIFICATION_COMMANDS.AFPLAY
23070
23421
  );
23071
- if (path9) exec3(`"${path9}" "${soundPath}"`);
23422
+ if (path10) exec3(`"${path10}" "${soundPath}"`);
23072
23423
  } catch (err) {
23073
23424
  log(`[session-notify] Error playing sound (Darwin): ${err}`);
23074
23425
  }
@@ -23187,13 +23538,27 @@ var MissionControlHook = class {
23187
23538
  if (verification.passed) {
23188
23539
  return this.handleMissionComplete(directory, verification);
23189
23540
  }
23190
- log(`[${MISSION_CONTROL.LOG_SOURCE}] Work remains - forcing autonomous continuation`, {
23191
- todo: verification.todoProgress,
23192
- checklist: verification.checklistProgress
23193
- });
23541
+ const loopState = readLoopState(directory);
23542
+ let isStagnant = false;
23543
+ if (loopState && loopState.active && loopState.sessionID === sessionID) {
23544
+ const currentProgress = verification.todoProgress;
23545
+ if (loopState.lastProgress === currentProgress) {
23546
+ loopState.stagnationCount = (loopState.stagnationCount || 0) + 1;
23547
+ if (loopState.stagnationCount >= 2) {
23548
+ isStagnant = true;
23549
+ }
23550
+ } else {
23551
+ loopState.stagnationCount = 0;
23552
+ }
23553
+ loopState.lastProgress = currentProgress;
23554
+ writeLoopState(directory, loopState);
23555
+ }
23194
23556
  const failurePrompt = verification.checklistProgress !== "0/0" ? buildVerificationFailurePrompt(verification) : buildTodoIncompletePrompt(verification);
23195
23557
  const continuation = this.buildContinuationResponse(session, sessionID);
23196
23558
  const prompts = [failurePrompt];
23559
+ if (isStagnant) {
23560
+ prompts.push(STAGNATION_INTERVENTION);
23561
+ }
23197
23562
  if (continuation.action === HOOK_ACTIONS.INJECT) {
23198
23563
  prompts.push(...continuation.prompts);
23199
23564
  }
@@ -24043,26 +24408,93 @@ function initializeHooks() {
24043
24408
  const userActivity = new UserActivityHook();
24044
24409
  const memoryGate = new MemoryGateHook();
24045
24410
  const metricsHook = new MetricsHook();
24046
- registry2.registerChat(userActivity);
24047
- registry2.registerChat(missionControl);
24048
- registry2.registerPostTool(sanityCheck);
24049
- registry2.registerPostTool(secretScanner);
24050
- registry2.registerPostTool(agentUI);
24051
- registry2.registerPostTool(resourceControl);
24052
- registry2.registerPostTool(memoryGate);
24053
- registry2.registerPostTool(metricsHook);
24054
- registry2.registerPreTool(roleGuard);
24055
- registry2.registerPreTool(metricsHook);
24056
- registry2.registerDone(sanityCheck);
24057
- registry2.registerDone(missionControl);
24058
- registry2.registerDone(resourceControl);
24059
- registry2.registerDone(memoryGate);
24060
- registry2.registerDone(metricsHook);
24411
+ registry2.registerChat(userActivity, {
24412
+ name: "user-activity",
24413
+ priority: 10,
24414
+ phase: "early"
24415
+ });
24416
+ registry2.registerChat(missionControl, {
24417
+ name: "mission-control",
24418
+ priority: 20,
24419
+ phase: "early",
24420
+ dependencies: ["user-activity"],
24421
+ errorHandling: "stop"
24422
+ });
24423
+ registry2.registerPreTool(roleGuard, {
24424
+ name: "role-guard",
24425
+ priority: 10,
24426
+ phase: "early",
24427
+ errorHandling: "stop"
24428
+ });
24429
+ registry2.registerPreTool(metricsHook, {
24430
+ name: "metrics-pre",
24431
+ priority: 90,
24432
+ phase: "late"
24433
+ });
24434
+ registry2.registerPostTool(sanityCheck, {
24435
+ name: "sanity-check",
24436
+ priority: 10,
24437
+ phase: "early",
24438
+ errorHandling: "stop"
24439
+ });
24440
+ registry2.registerPostTool(secretScanner, {
24441
+ name: "secret-scanner",
24442
+ priority: 20,
24443
+ phase: "early",
24444
+ dependencies: ["sanity-check"],
24445
+ errorHandling: "stop"
24446
+ });
24447
+ registry2.registerPostTool(agentUI, {
24448
+ name: "agent-ui",
24449
+ priority: 40,
24450
+ phase: "normal"
24451
+ });
24452
+ registry2.registerPostTool(resourceControl, {
24453
+ name: "resource-control",
24454
+ priority: 50,
24455
+ phase: "normal"
24456
+ });
24457
+ registry2.registerPostTool(memoryGate, {
24458
+ name: "memory-gate",
24459
+ priority: 60,
24460
+ phase: "normal"
24461
+ });
24462
+ registry2.registerPostTool(metricsHook, {
24463
+ name: "metrics-post",
24464
+ priority: 90,
24465
+ phase: "late",
24466
+ dependencies: ["metrics-pre"]
24467
+ });
24468
+ registry2.registerDone(sanityCheck, {
24469
+ name: "sanity-check",
24470
+ priority: 10,
24471
+ phase: "early"
24472
+ });
24473
+ registry2.registerDone(missionControl, {
24474
+ name: "mission-control",
24475
+ priority: 20,
24476
+ phase: "early"
24477
+ });
24478
+ registry2.registerDone(resourceControl, {
24479
+ name: "resource-control",
24480
+ priority: 50,
24481
+ phase: "normal"
24482
+ });
24483
+ registry2.registerDone(memoryGate, {
24484
+ name: "memory-gate",
24485
+ priority: 60,
24486
+ phase: "normal"
24487
+ });
24488
+ registry2.registerDone(metricsHook, {
24489
+ name: "metrics-done",
24490
+ priority: 90,
24491
+ phase: "late"
24492
+ });
24061
24493
  }
24062
24494
 
24063
24495
  // src/core/plugins/plugin-manager.ts
24064
- import * as fs8 from "fs/promises";
24065
- import * as path7 from "path";
24496
+ import * as fs9 from "fs/promises";
24497
+ import * as path8 from "path";
24066
24498
  init_shared();
24067
24499
  var PluginManager = class _PluginManager {
24068
24500
  static instance;
@@ -24086,13 +24518,13 @@ var PluginManager = class _PluginManager {
24086
24518
  */
24087
24519
  async loadPlugins() {
24088
24520
  if (!this.directory) return;
24089
- const pluginsDir = path7.join(this.directory, PATHS.PLUGINS);
24521
+ const pluginsDir = path8.join(this.directory, PATHS.PLUGINS);
24090
24522
  try {
24091
- await fs8.mkdir(pluginsDir, { recursive: true });
24092
- const files = await fs8.readdir(pluginsDir);
24523
+ await fs9.mkdir(pluginsDir, { recursive: true });
24524
+ const files = await fs9.readdir(pluginsDir);
24093
24525
  for (const file2 of files) {
24094
24526
  if (file2.endsWith(".js") || file2.endsWith(".mjs")) {
24095
- await this.loadPlugin(path7.join(pluginsDir, file2));
24527
+ await this.loadPlugin(path8.join(pluginsDir, file2));
24096
24528
  }
24097
24529
  }
24098
24530
  } catch (error45) {
@@ -24201,17 +24633,17 @@ function createChatMessageHandler(ctx) {
24201
24633
  init_shared();
24202
24634
 
24203
24635
  // src/utils/compatibility/claude.ts
24204
- import fs9 from "fs";
24205
- import path8 from "path";
24636
+ import fs10 from "fs";
24637
+ import path9 from "path";
24206
24638
  function findClaudeRules(startDir = process.cwd()) {
24207
24639
  try {
24208
24640
  let currentDir = startDir;
24209
- const root = path8.parse(startDir).root;
24641
+ const root = path9.parse(startDir).root;
24210
24642
  while (true) {
24211
- const claudeMdPath = path8.join(currentDir, "CLAUDE.md");
24212
- if (fs9.existsSync(claudeMdPath)) {
24643
+ const claudeMdPath = path9.join(currentDir, "CLAUDE.md");
24644
+ if (fs10.existsSync(claudeMdPath)) {
24213
24645
  try {
24214
- const content = fs9.readFileSync(claudeMdPath, "utf-8");
24646
+ const content = fs10.readFileSync(claudeMdPath, "utf-8");
24215
24647
  log(`[compatibility] Loaded CLAUDE.md from ${claudeMdPath}`);
24216
24648
  return formatRules("CLAUDE.md", content);
24217
24649
  } catch (e) {
@@ -24219,11 +24651,11 @@ function findClaudeRules(startDir = process.cwd()) {
24219
24651
  }
24220
24652
  }
24221
24653
  if (currentDir === root) break;
24222
- currentDir = path8.dirname(currentDir);
24654
+ currentDir = path9.dirname(currentDir);
24223
24655
  }
24224
- const copilotPath = path8.join(startDir, ".github", "copilot-instructions.md");
24225
- if (fs9.existsSync(copilotPath)) {
24226
- return formatRules("Copilot Instructions", fs9.readFileSync(copilotPath, "utf-8"));
24656
+ const copilotPath = path9.join(startDir, ".github", "copilot-instructions.md");
24657
+ if (fs10.existsSync(copilotPath)) {
24658
+ return formatRules("Copilot Instructions", fs10.readFileSync(copilotPath, "utf-8"));
24227
24659
  }
24228
24660
  return null;
24229
24661
  } catch (error45) {
@@ -24352,22 +24784,6 @@ function hasRunningBackgroundTasks2(parentSessionID) {
24352
24784
  return false;
24353
24785
  }
24354
24786
  }
24355
- async function showCountdownToast2(client, seconds, iteration, maxIterations) {
24356
- try {
24357
- const tuiClient2 = client;
24358
- if (tuiClient2.tui?.showToast) {
24359
- await tuiClient2.tui.showToast({
24360
- body: {
24361
- title: "\u{1F504} Mission Loop",
24362
- message: `Continuing in ${seconds}s... (iteration ${iteration}/${maxIterations})`,
24363
- variant: TOAST_VARIANTS.WARNING,
24364
- duration: TOAST_DURATION.EXTRA_SHORT
24365
- }
24366
- });
24367
- }
24368
- } catch {
24369
- }
24370
- }
24371
24787
  async function showCompletedToast(client, state2) {
24372
24788
  try {
24373
24789
  const tuiClient2 = client;
@@ -24384,7 +24800,7 @@ async function showCompletedToast(client, state2) {
24384
24800
  } catch {
24385
24801
  }
24386
24802
  }
24387
- async function injectContinuation2(client, directory, sessionID, loopState) {
24803
+ async function injectContinuation2(client, directory, sessionID, loopState, customPrompt) {
24388
24804
  const handlerState = getState4(sessionID);
24389
24805
  if (handlerState.isAborting) return;
24390
24806
  if (hasRunningBackgroundTasks2(sessionID)) return;
@@ -24395,7 +24811,12 @@ async function injectContinuation2(client, directory, sessionID, loopState) {
24395
24811
  return;
24396
24812
  }
24397
24813
  const summary = buildVerificationSummary(verification);
24398
- const prompt = generateMissionContinuationPrompt(loopState, summary);
24814
+ let prompt = generateMissionContinuationPrompt(loopState, summary);
24815
+ if (customPrompt) {
24816
+ prompt = `${customPrompt}
24817
+
24818
+ ${prompt}`;
24819
+ }
24399
24820
  try {
24400
24821
  client.session.prompt({
24401
24822
  path: { id: sessionID },
@@ -24456,19 +24877,27 @@ async function handleMissionIdle(client, directory, sessionID, mainSessionID) {
24456
24877
  await handleMissionComplete(client, directory, loopState);
24457
24878
  return;
24458
24879
  }
24459
- log(`[${MISSION_CONTROL.LOG_SOURCE}-handler] Work remains for ${sessionID}, continuing...`, {
24460
- todo: verification.todoProgress,
24461
- checklist: verification.checklistProgress
24462
- });
24463
- if (loopState.iteration >= loopState.maxIterations) {
24464
- log(`[${MISSION_CONTROL.LOG_SOURCE}-handler] Max iterations (${loopState.maxIterations}) reached but verification failed. Forced continuation enabled.`);
24880
+ const currentProgress = verification.todoProgress;
24881
+ let isStagnant = false;
24882
+ if (loopState.lastProgress === currentProgress) {
24883
+ loopState.stagnationCount = (loopState.stagnationCount || 0) + 1;
24884
+ if (loopState.stagnationCount >= 2) {
24885
+ isStagnant = true;
24886
+ log(`[${MISSION_CONTROL.LOG_SOURCE}-handler] Stagnation detected for ${sessionID} (${currentProgress}). Intervention ready.`);
24887
+ }
24888
+ } else {
24889
+ loopState.stagnationCount = 0;
24465
24890
  }
24891
+ loopState.lastProgress = currentProgress;
24466
24892
  const newState = incrementIteration(directory);
24467
24893
  if (!newState) return;
24468
- await showCountdownToast2(client, MISSION_CONTROL.DEFAULT_COUNTDOWN_SECONDS, newState.iteration, newState.maxIterations);
24894
+ newState.lastProgress = currentProgress;
24895
+ newState.stagnationCount = loopState.stagnationCount;
24896
+ writeLoopState(directory, newState);
24897
+ const countdownMsg = isStagnant ? "Stagnation Detected! Intervening..." : `Continuing in ${MISSION_CONTROL.DEFAULT_COUNTDOWN_SECONDS}s... (iteration ${newState.iteration}/${newState.maxIterations})`;
24469
24898
  handlerState.countdownTimer = setTimeout(async () => {
24470
24899
  cancelCountdown2(sessionID);
24471
- await injectContinuation2(client, directory, sessionID, newState);
24900
+ await injectContinuation2(client, directory, sessionID, newState, isStagnant ? STAGNATION_INTERVENTION : void 0);
24472
24901
  }, MISSION_CONTROL.DEFAULT_COUNTDOWN_SECONDS * 1e3);
24473
24902
  }
24474
24903
  function handleUserMessage2(sessionID) {
@@ -24761,7 +25190,7 @@ function createSystemTransformHandler(ctx) {
24761
25190
  }
24762
25191
  const systemAdditions = [];
24763
25192
  if (isActiveLoop && loopState) {
24764
- const { commander: commander2 } = await Promise.resolve().then(() => (init_commander2(), commander_exports));
25193
+ const { commander: commander2 } = await Promise.resolve().then(() => (init_commander(), commander_exports));
24765
25194
  systemAdditions.push(commander2.systemPrompt);
24766
25195
  systemAdditions.push(buildMissionLoopSystemPrompt(loopState.iteration, loopState.maxIterations));
24767
25196
  }