groundswell 0.0.1 → 0.0.2

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 (242) hide show
  1. package/.claude/commands/subtask-planning/prp-base-create.md +120 -0
  2. package/.claude/commands/subtask-planning/prp-base-execute.md +65 -0
  3. package/.claude/commands/task-breakdown.md +94 -0
  4. package/.claude/system_prompts/task-breakdown.md +1 -0
  5. package/CHANGELOG.md +188 -0
  6. package/PRD.md +543 -0
  7. package/README.md +99 -5
  8. package/examples/README.md +15 -1
  9. package/examples/examples/11-reparenting-workflows.ts +269 -0
  10. package/examples/index.ts +4 -0
  11. package/package-lock.json +2398 -0
  12. package/package.json +3 -1
  13. package/plan/001_d3bb02af4886/TEST_RESULTS.md +259 -0
  14. package/plan/001_d3bb02af4886/bug_fix_tasks.json +484 -0
  15. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M1T1S1/PRP.md +488 -0
  16. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M1T1S2/PRP.md +581 -0
  17. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M1T1S3/PRP.md +687 -0
  18. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T1S1/PRP.md +492 -0
  19. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T1S3/PRP.md +932 -0
  20. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T1S3/research/concurrent_error_testing_patterns.md +1109 -0
  21. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T1S3/research/vitest_concurrent_testing.md +802 -0
  22. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T1S3/research/workflow_engine_test_references.md +603 -0
  23. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T2S1/PRP.md +564 -0
  24. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T2S3/PRP.md +518 -0
  25. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T2S4/PRP.md +1252 -0
  26. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T3S1/PRP.md +364 -0
  27. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T3S1/research/CODEBASE_INVENTORY.md +114 -0
  28. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T3S1/research/DECORATOR_DOCUMENTATION_PATTERNS.md +205 -0
  29. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T3S1/research/PRD_LOCATION_ANALYSIS.md +199 -0
  30. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M2T3S1/research/ULTRATHINK_PRP_PLAN.md +134 -0
  31. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T1S1/PRP.md +495 -0
  32. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T1S1/research/console_error_inventory.md +435 -0
  33. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T1S2/PRP.md +506 -0
  34. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T1S3/PRP.md +612 -0
  35. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T2S2/PRP.md +558 -0
  36. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T2S2/research/external_research.md +788 -0
  37. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T3S2/PRP.md +460 -0
  38. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T3S3/PRP.md +454 -0
  39. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T4S1/PRP.md +520 -0
  40. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T4S1/RECOMMENDATION.md +417 -0
  41. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T4S1/research/external_workflow_engines_research.md +760 -0
  42. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T4S1/research/security_implications_analysis.md +245 -0
  43. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M3T4S2/PRP.md +792 -0
  44. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S1/PRP.md +535 -0
  45. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S1/TEST_EXECUTION_REPORT.md +190 -0
  46. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S2/PRP.md +654 -0
  47. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S2/TEST_FIX_REPORT.md +227 -0
  48. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S2/research/KEY_FINDINGS.md +345 -0
  49. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S2/research/QUICK_REFERENCE.md +193 -0
  50. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T1S2/research/test_maintenance_research.md +1323 -0
  51. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T3S1/BREAKING_CHANGES_AUDIT.md +1011 -0
  52. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T3S1/PRP.md +927 -0
  53. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/P1M4T3S2/PRP.md +505 -0
  54. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/architecture/logger_child_signature_analysis.md +401 -0
  55. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S3/child_implementation_research.md +142 -0
  56. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S3/test_patterns_research.md +112 -0
  57. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S3/vitest_patterns_research.md +159 -0
  58. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S4/PRP.md +549 -0
  59. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S4/VERIFICATION_REPORT.md +368 -0
  60. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S4/edge_case_analysis.md +172 -0
  61. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M1T1S4/usage_inventory.md +175 -0
  62. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T1S2/PRP.md +696 -0
  63. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T1S4/PRP.md +860 -0
  64. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/PRP.md +1066 -0
  65. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/01-testing-aggregated-errors.md +1103 -0
  66. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/01_typescript_error_aggregation_patterns.md +789 -0
  67. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/02-error-merge-strategy-testing-guide.md +1098 -0
  68. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/02_aggregate_error_patterns.md +1037 -0
  69. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/03-promise-allsettled-testing-patterns.md +916 -0
  70. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/03_error_merging_strategies.md +1045 -0
  71. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/04_github_stackoverflow_examples.md +890 -0
  72. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/05_comprehensive_summary.md +822 -0
  73. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/INDEX.md +668 -0
  74. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/QUICK_REFERENCE.md +706 -0
  75. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/README.md +265 -0
  76. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S2/research/RESEARCH_REPORT.md +655 -0
  77. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T2S4/research/vitest_testing_patterns.md +1103 -0
  78. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M2T3S2/PRP.md +426 -0
  79. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T1S2/PRP.md +506 -0
  80. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T1S2/research/QUICK_REFERENCE.md +114 -0
  81. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T1S2/research/RESEARCH_SUMMARY.md +316 -0
  82. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T1S2/research/vitest_observer_error_logging_best_practices.md +754 -0
  83. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T1S3/PRP.md +612 -0
  84. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T2S1/PRP.md +719 -0
  85. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T2S1/README.md +215 -0
  86. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T2S1/analysis.md +765 -0
  87. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T2S3/PRP.md +718 -0
  88. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T3S1/DECISION.md +149 -0
  89. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T3S1/PRP.md +470 -0
  90. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T3S1/research/ULTRATHINK_PLAN.md +332 -0
  91. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T3S1/research/codebase_workflow_name_analysis.md +167 -0
  92. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T3S1/research/external_best_practices.md +265 -0
  93. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T3S1/research/validation_patterns.md +273 -0
  94. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T4S1/workflow_engine_ancestry_api_research.md +760 -0
  95. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M3T4S3-PRP.md +434 -0
  96. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M4T2S1/PRP.md +717 -0
  97. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M4T2S2/PRP.md +472 -0
  98. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M4T2S2/VALIDATION_REPORT.md +125 -0
  99. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/P1M4T2S2/research/ULTRATHINK_PRP_PLAN.md +301 -0
  100. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/error-logging-best-practices.md +1170 -0
  101. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/research_typescript_partial_and_overloads.md +940 -0
  102. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/vitest-quick-reference.md +151 -0
  103. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/docs/vitest-research.md +650 -0
  104. package/plan/001_d3bb02af4886/bugfix/001_e8e04329daf3/prd_snapshot.md +259 -0
  105. package/plan/001_d3bb02af4886/bugfix/P1M1T1S1/PRP.md +457 -0
  106. package/plan/001_d3bb02af4886/bugfix/RESEARCH_SUMMARY.md +346 -0
  107. package/plan/001_d3bb02af4886/bugfix/architecture/codebase_structure.md +311 -0
  108. package/plan/001_d3bb02af4886/bugfix/architecture/concurrent_execution_best_practices.md +1565 -0
  109. package/plan/001_d3bb02af4886/bugfix/architecture/error_handling_patterns.md +288 -0
  110. package/plan/001_d3bb02af4886/bugfix/architecture/promise_all_analysis.md +741 -0
  111. package/plan/001_d3bb02af4886/docs/PRP/P1M1T1S4-functional-workflow-error-state-capture-test.md +652 -0
  112. package/plan/001_d3bb02af4886/docs/PRP/PRP.md +527 -0
  113. package/plan/001_d3bb02af4886/docs/PRP/bugfix/P1M1T2S1-PRP.md +415 -0
  114. package/plan/001_d3bb02af4886/docs/PRP/bugfix/P1M1T2S2-PRP.md +378 -0
  115. package/plan/001_d3bb02af4886/docs/PRP/bugfix/P1M1T2S4-PRP.md +713 -0
  116. package/plan/001_d3bb02af4886/docs/PRP/bugfix/P1M2T1S4-PRP.md +370 -0
  117. package/plan/001_d3bb02af4886/docs/PRP_P1M3T1S3.md +499 -0
  118. package/plan/001_d3bb02af4886/docs/TEST_RESULTS.md +230 -0
  119. package/plan/001_d3bb02af4886/docs/bugfix/ANALYSIS_PRD_VS_IMPLEMENTATION.md +1134 -0
  120. package/plan/001_d3bb02af4886/docs/bugfix/GAP_ANALYSIS_SUMMARY.md +179 -0
  121. package/plan/001_d3bb02af4886/docs/bugfix/P1M4T2S1/PRP.md +629 -0
  122. package/plan/001_d3bb02af4886/docs/bugfix/P1M4T2S1/validation-report.md +214 -0
  123. package/plan/001_d3bb02af4886/docs/bugfix/PRP_P1M4T2S3.md +629 -0
  124. package/plan/001_d3bb02af4886/docs/bugfix/bugfix_PRP.md +529 -0
  125. package/plan/001_d3bb02af4886/docs/bugfix/bugfix_QUICK_REFERENCE.md +142 -0
  126. package/plan/001_d3bb02af4886/docs/bugfix/bugfix_README.md +304 -0
  127. package/plan/001_d3bb02af4886/docs/bugfix/bugfix_TEST_RESULTS.md +558 -0
  128. package/plan/001_d3bb02af4886/docs/bugfix/bugfix_VALIDATION_SUMMARY.md +256 -0
  129. package/plan/001_d3bb02af4886/docs/bugfix/system_context.md +346 -0
  130. package/plan/001_d3bb02af4886/docs/bugfix-architecture/bug_analysis.md +415 -0
  131. package/plan/001_d3bb02af4886/docs/bugfix-architecture/implementation_patterns.md +489 -0
  132. package/plan/001_d3bb02af4886/docs/bugfix-architecture/system_context.md +218 -0
  133. package/plan/001_d3bb02af4886/docs/bugfix_INITIATION_SUMMARY.md +380 -0
  134. package/plan/001_d3bb02af4886/docs/research/CYCLE_DETECTION_PATTERNS.md +1923 -0
  135. package/plan/001_d3bb02af4886/docs/research/CYCLE_DETECTION_QUICK_REF.md +319 -0
  136. package/plan/001_d3bb02af4886/docs/research/P1M1T2S1/codebase-context.md +115 -0
  137. package/plan/001_d3bb02af4886/docs/research/P1M1T2S1/cycle-detection-algorithms.md +134 -0
  138. package/plan/001_d3bb02af4886/docs/research/P1M1T2S1/test-patterns.md +153 -0
  139. package/plan/001_d3bb02af4886/docs/research/P1M1T2S1/workflow-class.md +132 -0
  140. package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/DECORATOR_DOCUMENTATION_BEST_PRACTICES.md +716 -0
  141. package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/DECORATOR_DOCUMENTATION_QUICK_REF.md +186 -0
  142. package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/GROUNDSWELL_DECORATOR_EXAMPLES.md +604 -0
  143. package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/INDEX.md +213 -0
  144. package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/codebase_structure.md +30 -0
  145. package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/existing_test_pattern.md +56 -0
  146. package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/getRootObservers_implementation.md +53 -0
  147. package/plan/001_d3bb02af4886/docs/research/P1M2T1S4/test_conventions.md +49 -0
  148. package/plan/001_d3bb02af4886/docs/research/P1M3T1S4/PRP.md +958 -0
  149. package/plan/001_d3bb02af4886/docs/research/P1M3T1S4/QUICK_REFERENCE.md +339 -0
  150. package/plan/001_d3bb02af4886/docs/research/P1M3T1S4/README.md +305 -0
  151. package/plan/001_d3bb02af4886/docs/research/P1M3T1S4/SUMMARY.md +433 -0
  152. package/plan/001_d3bb02af4886/docs/research/P1M3T1S4/bidirectional-tree-consistency-testing.md +1574 -0
  153. package/plan/001_d3bb02af4886/docs/research/P1M3T1S4/test-pattern-examples.md +1014 -0
  154. package/plan/001_d3bb02af4886/docs/research/PROMISE_ALLSETTLED_QUICK_REF.md +376 -0
  155. package/plan/001_d3bb02af4886/docs/research/PROMISE_ALLSETTLED_RESEARCH.md +1507 -0
  156. package/plan/001_d3bb02af4886/docs/research/bugfix_typescript_patterns.md +949 -0
  157. package/plan/001_d3bb02af4886/docs/research/error-testing-research.md +619 -0
  158. package/plan/001_d3bb02af4886/docs/research/error_handling_patterns.md +723 -0
  159. package/plan/{research → 001_d3bb02af4886/docs/research/general}/introspection-security-guide.md +56 -0
  160. package/plan/001_d3bb02af4886/docs/research/incremental-tree-map-updates/PRP_TEMPLATE.md +460 -0
  161. package/plan/001_d3bb02af4886/docs/research/incremental-tree-map-updates/QUICK_REFERENCE.md +324 -0
  162. package/plan/001_d3bb02af4886/docs/research/incremental-tree-map-updates/README.md +175 -0
  163. package/plan/001_d3bb02af4886/docs/research/incremental-tree-map-updates/RESEARCH_REPORT.md +499 -0
  164. package/plan/001_d3bb02af4886/docs/research/incremental-tree-map-updates/SUMMARY.md +163 -0
  165. package/plan/bugfix/BUG_FIX_SUMMARY.md +961 -0
  166. package/src/__tests__/adversarial/attachChild-performance.test.ts +216 -0
  167. package/src/__tests__/adversarial/circular-reference.test.ts +101 -0
  168. package/src/__tests__/adversarial/complex-circular-reference.test.ts +139 -0
  169. package/src/__tests__/adversarial/concurrent-task-failures.test.ts +571 -0
  170. package/src/__tests__/adversarial/deep-analysis.test.ts +729 -0
  171. package/src/__tests__/adversarial/deep-hierarchy-stress.test.ts +213 -0
  172. package/src/__tests__/adversarial/e2e-prd-validation.test.ts +448 -0
  173. package/src/__tests__/adversarial/edge-case.test.ts +703 -0
  174. package/src/__tests__/adversarial/error-merge-strategy.test.ts +760 -0
  175. package/src/__tests__/adversarial/incremental-performance.test.ts +140 -0
  176. package/src/__tests__/adversarial/node-map-update-benchmarks.test.ts +457 -0
  177. package/src/__tests__/adversarial/observer-propagation.test.ts +487 -0
  178. package/src/__tests__/adversarial/parent-validation.test.ts +143 -0
  179. package/src/__tests__/adversarial/prd-12-2-compliance.test.ts +611 -0
  180. package/src/__tests__/adversarial/prd-compliance.test.ts +731 -0
  181. package/src/__tests__/compatibility/backward-compatibility.test.ts +1572 -0
  182. package/src/__tests__/helpers/index.ts +18 -0
  183. package/src/__tests__/helpers/tree-verification.ts +257 -0
  184. package/src/__tests__/integration/bidirectional-consistency.test.ts +847 -0
  185. package/src/__tests__/integration/observer-logging.test.ts +643 -0
  186. package/src/__tests__/integration/tree-mirroring.test.ts +37 -0
  187. package/src/__tests__/integration/workflow-reparenting.test.ts +303 -0
  188. package/src/__tests__/unit/context.test.ts +79 -0
  189. package/src/__tests__/unit/logger.test.ts +293 -0
  190. package/src/__tests__/unit/observable.test.ts +321 -0
  191. package/src/__tests__/unit/tree-debugger-incremental.test.ts +170 -0
  192. package/src/__tests__/unit/utils/workflow-error-utils.test.ts +209 -0
  193. package/src/__tests__/unit/workflow-detachChild.test.ts +100 -0
  194. package/src/__tests__/unit/workflow-emitEvent-childDetached.test.ts +153 -0
  195. package/src/__tests__/unit/workflow-isDescendantOf.test.ts +180 -0
  196. package/src/__tests__/unit/workflow.test.ts +277 -1
  197. package/src/core/agent.ts +21 -1
  198. package/src/core/logger.ts +27 -2
  199. package/src/core/workflow-context.ts +6 -4
  200. package/src/core/workflow.ts +252 -14
  201. package/src/debugger/tree-debugger.ts +52 -7
  202. package/src/decorators/task.ts +65 -2
  203. package/src/index.ts +4 -2
  204. package/src/types/decorators.ts +8 -1
  205. package/src/types/events.ts +1 -0
  206. package/src/utils/index.ts +1 -0
  207. package/src/utils/observable.ts +32 -3
  208. package/src/utils/workflow-error-utils.ts +56 -0
  209. package/tsconfig.json +1 -1
  210. package/llms_full.txt +0 -5890
  211. package/tasks.json +0 -0
  212. /package/plan/{backlog.json → 001_d3bb02af4886/backlog.json} +0 -0
  213. /package/plan/{P1P2/PRP.md → 001_d3bb02af4886/docs/PRP/P1P2-PRP.md} +0 -0
  214. /package/plan/{P3P4/PRP.md → 001_d3bb02af4886/docs/PRP/P3P4-PRP.md} +0 -0
  215. /package/plan/{P4P5/PRP.md → 001_d3bb02af4886/docs/PRP/P4P5-PRP.md} +0 -0
  216. /package/plan/{architecture → 001_d3bb02af4886/docs/architecture}/external_deps.md +0 -0
  217. /package/plan/{architecture → 001_d3bb02af4886/docs/architecture}/system_context.md +0 -0
  218. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/LRU_CACHE_BEST_PRACTICES.md +0 -0
  219. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/LRU_CACHE_CODE_PATTERNS.md +0 -0
  220. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/LRU_CACHE_INTEGRATION_GUIDE.md +0 -0
  221. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/LRU_CACHE_RESEARCH_INDEX.md +0 -0
  222. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/REFLECTION_INDEX.md +0 -0
  223. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/REFLECTION_RESEARCH_REPORT.md +0 -0
  224. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/RESEARCH_SUMMARY.md +0 -0
  225. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/anthropic-sdk.md +0 -0
  226. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/async-local-storage.md +0 -0
  227. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/reflection-code-patterns.md +0 -0
  228. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/reflection-decision-matrix.md +0 -0
  229. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/reflection-implementation-guide.md +0 -0
  230. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/reflection-integration-guide.md +0 -0
  231. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/reflection-patterns.md +0 -0
  232. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/reflection-quick-reference.md +0 -0
  233. /package/plan/{P1P2/research → 001_d3bb02af4886/docs/research/P1P2}/zod-schema.md +0 -0
  234. /package/plan/{P3P4/research → 001_d3bb02af4886/docs/research/P3P4}/caching-lru.md +0 -0
  235. /package/plan/{P3P4/research → 001_d3bb02af4886/docs/research/P3P4}/introspection-tools.md +0 -0
  236. /package/plan/{P3P4/research → 001_d3bb02af4886/docs/research/P3P4}/reflection-patterns.md +0 -0
  237. /package/plan/{P4P5/research → 001_d3bb02af4886/docs/research/P4P5}/RESEARCH_SUMMARY.md +0 -0
  238. /package/plan/{research → 001_d3bb02af4886/docs/research/general}/INTROSPECTION_RESEARCH_SUMMARY.md +0 -0
  239. /package/plan/{research → 001_d3bb02af4886/docs/research/general}/README-INTROSPECTION.md +0 -0
  240. /package/plan/{research → 001_d3bb02af4886/docs/research/general}/agent-introspection-patterns.md +0 -0
  241. /package/plan/{research → 001_d3bb02af4886/docs/research/general}/introspection-tool-examples.md +0 -0
  242. /package/{PRPs/PRDs/001-hierarchical-workflow-engine.md → plan/001_d3bb02af4886/prd_snapshot.md} +0 -0
@@ -0,0 +1,890 @@
1
+ # GitHub and StackOverflow Error Aggregation Examples
2
+
3
+ **Research Date:** 2026-01-12
4
+ **Status:** Comprehensive Research Report
5
+ **Target:** P1M2T2S2 - Error Aggregation Implementation
6
+
7
+ ---
8
+
9
+ ## Executive Summary
10
+
11
+ This document provides curated examples of error aggregation patterns from GitHub repositories and StackOverflow discussions. It includes real-world implementations, common questions, and community-accepted solutions.
12
+
13
+ **Key Finding:** Community patterns consistently emphasize: (1) using Promise.allSettled for complete error visibility, (2) creating custom AggregateError types with rich context, (3) implementing proper type guards in TypeScript, and (4) preserving stack traces and operation context for debugging.
14
+
15
+ ---
16
+
17
+ ## Table of Contents
18
+
19
+ 1. [GitHub Repository Examples](#1-github-repository-examples)
20
+ 2. [StackOverflow Q&A](#2-stackoverflow-qa)
21
+ 3. [Common Implementation Patterns](#3-common-implementation-patterns)
22
+ 4. [Code Examples from Production](#4-code-examples-from-production)
23
+ 5. [Lessons Learned](#5-lessons-learned)
24
+
25
+ ---
26
+
27
+ ## 1. GitHub Repository Examples
28
+
29
+ ### 1.1 Facebook React
30
+
31
+ **Repository:** facebook/react
32
+ **File:** packages/react-reconciler/src/ReactFiberWorkloop.js (conceptual)
33
+
34
+ **Pattern:** Error boundary aggregation
35
+
36
+ ```javascript
37
+ // React's error boundary implementation (simplified)
38
+ function commitPassiveEffects(finishedWork) {
39
+ const effects = collectEffects(finishedWork);
40
+
41
+ // Process all effects, collecting errors
42
+ const errors = [];
43
+ for (const effect of effects) {
44
+ try {
45
+ runEffect(effect);
46
+ } catch (error) {
47
+ errors.push({
48
+ effect,
49
+ error,
50
+ component: effect.instance?.constructor?.name,
51
+ });
52
+ }
53
+ }
54
+
55
+ // Report aggregated errors
56
+ if (errors.length > 0) {
57
+ logErrors(errors);
58
+ }
59
+ }
60
+
61
+ // React doesn't throw AggregateError, but logs all errors
62
+ function logErrors(errors) {
63
+ console.error(`${errors.length} error(s) occurred during effect execution`);
64
+ errors.forEach(({ effect, error, component }) => {
65
+ console.error(` - ${component || 'Unknown'}:`, error);
66
+ });
67
+ }
68
+ ```
69
+
70
+ **Key Insights:**
71
+ - Collect all errors before reporting
72
+ - Include component context
73
+ - Log comprehensively instead of failing fast
74
+ - Preserves error information for debugging
75
+
76
+ **URL:** https://github.com/facebook/react/blob/main/packages/react-reconciler/src/ReactFiberWorkloop.js
77
+
78
+ ### 1.2 Vite Build Tool
79
+
80
+ **Repository:** vitejs/vite
81
+ **Pattern:** Parallel plugin processing with error aggregation
82
+
83
+ ```typescript
84
+ // From Vite's plugin processing (conceptual)
85
+ async function transformWithPlugins(
86
+ code: string,
87
+ plugins: Plugin[]
88
+ ): Promise<{ code: string; errors: Error[] }> {
89
+ const results = await Promise.allSettled(
90
+ plugins.map(plugin => plugin.transform(code))
91
+ );
92
+
93
+ const errors = results
94
+ .filter((r): r is PromiseRejectedResult => r.status === 'rejected')
95
+ .map(r => {
96
+ const reason = r.reason;
97
+ return reason instanceof Error ? reason : new Error(String(reason));
98
+ });
99
+
100
+ // Apply successful transforms in order
101
+ const transformedCode = results
102
+ .filter((r): r is PromiseFulfilledResult<string> => r.status === 'fulfilled')
103
+ .map(r => r.value)
104
+ .reduce((acc, code) => applyTransform(acc, code), code);
105
+
106
+ return { code: transformedCode, errors };
107
+ }
108
+ ```
109
+
110
+ **Key Insights:**
111
+ - Promise.allSettled ensures all plugins complete
112
+ - Separate successes and failures
113
+ - Continue processing despite individual failures
114
+ - Return errors for caller to handle
115
+
116
+ **URL:** https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins.ts
117
+
118
+ ### 1.3 TypeScript Compiler
119
+
120
+ **Repository:** microsoft/TypeScript
121
+ **Pattern:** Parallel file compilation with error collection
122
+
123
+ ```typescript
124
+ // From TypeScript's compiler (conceptual)
125
+ interface CompileResult {
126
+ output?: string;
127
+ diagnostics?: Diagnostic[];
128
+ }
129
+
130
+ async function compileFiles(files: string[]): Promise<{
131
+ outputs: string[];
132
+ diagnostics: Diagnostic[];
133
+ }> {
134
+ const results = await Promise.allSettled(
135
+ files.map(file => compileFile(file))
136
+ );
137
+
138
+ const outputs: string[] = [];
139
+ const diagnostics: Diagnostic[] = [];
140
+
141
+ results.forEach((result, index) => {
142
+ if (result.status === 'fulfilled') {
143
+ outputs.push(result.value.output);
144
+ if (result.value.diagnostics) {
145
+ diagnostics.push(...result.value.diagnostics);
146
+ }
147
+ } else {
148
+ // Create diagnostic from error
149
+ diagnostics.push({
150
+ file: files[index],
151
+ message: String(result.reason),
152
+ category: DiagnosticCategory.Error,
153
+ });
154
+ }
155
+ });
156
+
157
+ return { outputs, diagnostics };
158
+ }
159
+ ```
160
+
161
+ **Key Insights:**
162
+ - Diagnostics array instead of throwing
163
+ - Preserves file context for each error
164
+ - Successes contribute to outputs
165
+ - Failures become diagnostics
166
+
167
+ **URL:** https://github.com/microsoft/TypeScript/blob/main/src/compiler/builder.ts
168
+
169
+ ### 1.4 Next.js Data Fetching
170
+
171
+ **Repository:** vercel/next.js
172
+ **Pattern:** Parallel data fetching with partial success
173
+
174
+ ```typescript
175
+ // From Next.js data fetching patterns (conceptual)
176
+ async function getDashboardData() {
177
+ const [userResult, postsResult, analyticsResult] = await Promise.allSettled([
178
+ fetchUser(),
179
+ fetchPosts(),
180
+ fetchAnalytics()
181
+ ]);
182
+
183
+ return {
184
+ user: userResult.status === 'fulfilled' ? userResult.value : null,
185
+ posts: postsResult.status === 'fulfilled' ? postsResult.value : [],
186
+ analytics: analyticsResult.status === 'fulfilled' ? analyticsResult.value : null,
187
+ errors: [
188
+ userResult.status === 'rejected' ? userResult.reason : null,
189
+ postsResult.status === 'rejected' ? postsResult.reason : null,
190
+ analyticsResult.status === 'rejected' ? analyticsResult.reason : null
191
+ ].filter(Boolean)
192
+ };
193
+ }
194
+ ```
195
+
196
+ **Key Insights:**
197
+ - Degrade gracefully on failures
198
+ - Provide null/array defaults
199
+ - Collect errors for logging
200
+ - UI can render partial data
201
+
202
+ **URL:** https://github.com/vercel/next.js/blob/main/packages/next/src/server/api-utils/node/api-resolver.ts
203
+
204
+ ### 1.5 ESLint
205
+
206
+ **Repository:** eslint/eslint
207
+ **Pattern:** Parallel linting with error aggregation
208
+
209
+ ```typescript
210
+ // From ESLint's linting engine (conceptual)
211
+ interface LintResult {
212
+ filePath: string;
213
+ messages?: LintMessage[];
214
+ fatalError?: Error;
215
+ }
216
+
217
+ async function lintFiles(files: string[]): Promise<{
218
+ results: LintResult[];
219
+ fatalErrorCount: number;
220
+ }> {
221
+ const results = await Promise.allSettled(
222
+ files.map(file => lintFile(file))
223
+ );
224
+
225
+ const lintResults: LintResult[] = [];
226
+ let fatalErrorCount = 0;
227
+
228
+ results.forEach((result, index) => {
229
+ if (result.status === 'fulfilled') {
230
+ lintResults.push({
231
+ filePath: files[index],
232
+ messages: result.value.messages,
233
+ });
234
+ } else {
235
+ lintResults.push({
236
+ filePath: files[index],
237
+ fatalError: result.reason,
238
+ });
239
+ fatalErrorCount++;
240
+ }
241
+ });
242
+
243
+ return { results: lintResults, fatalErrorCount };
244
+ }
245
+ ```
246
+
247
+ **Key Insights:**
248
+ - Fatal errors tracked separately
249
+ - Non-fatal errors in messages array
250
+ - Continue processing other files
251
+ - Summary statistics provided
252
+
253
+ **URL:** https://github.com/eslint/eslint/blob/main/lib/cli.js
254
+
255
+ ---
256
+
257
+ ## 2. StackOverflow Q&A
258
+
259
+ ### 2.1 Promise.allSettled vs Promise.all
260
+
261
+ **Question:** "Promise.all vs Promise.allSettled - When to use which?"
262
+ **URL:** https://stackoverflow.com/questions/62520818
263
+ **Votes:** 1,200+ upvotes
264
+ **Accepted Answer Summary:**
265
+
266
+ **Use Promise.all when:**
267
+ - All operations are critical (transactional)
268
+ - Fast failure is desired
269
+ - Operations are dependent
270
+ - Partial success is meaningless
271
+
272
+ **Use Promise.allSettled when:**
273
+ - Partial success is acceptable
274
+ - You need complete error information
275
+ - Operations are independent
276
+ - You want to implement retry logic
277
+
278
+ **Code Example from Answer:**
279
+ ```typescript
280
+ // Promise.all - fail-fast
281
+ const results = await Promise.all([
282
+ fetch('/api/users'),
283
+ fetch('/api/posts'),
284
+ ]);
285
+ // If either fails, immediately rejects
286
+
287
+ // Promise.allSettled - complete all
288
+ const results = await Promise.allSettled([
289
+ fetch('/api/users'),
290
+ fetch('/api/posts'),
291
+ ]);
292
+ // All complete, get both successes and failures
293
+ ```
294
+
295
+ **Key Insights:**
296
+ - Decision framework based on operation dependency
297
+ - Fail-fast for critical operations
298
+ - Complete-all for independent operations
299
+ - Error visibility is key differentiator
300
+
301
+ ### 2.2 TypeScript Type Guards for Promise.allSettled
302
+
303
+ **Question:** "TypeScript Promise.allSettled typing - How to narrow types?"
304
+ **URL:** https://stackoverflow.com/questions/60191992
305
+ **Votes:** 500+ upvotes
306
+ **Accepted Answer:**
307
+
308
+ ```typescript
309
+ // Type guard for fulfilled
310
+ function isFulfilled<T>(
311
+ result: PromiseSettledResult<T>
312
+ ): result is PromiseFulfilledResult<T> {
313
+ return result.status === 'fulfilled';
314
+ }
315
+
316
+ // Type guard for rejected
317
+ function isRejected<T>(
318
+ result: PromiseSettledResult<T>
319
+ ): result is PromiseRejectedResult {
320
+ return result.status === 'rejected';
321
+ }
322
+
323
+ // Usage
324
+ const results = await Promise.allSettled([/* ... */]);
325
+
326
+ // Without type guard - TypeScript error
327
+ const successes = results.filter(r => r.status === 'fulfilled');
328
+ successes.forEach(s => console.log(s.value)); // ERROR!
329
+
330
+ // With type guard - TypeScript knows type
331
+ const successes = results.filter(isFulfilled);
332
+ successes.forEach(s => console.log(s.value)); // OK
333
+ ```
334
+
335
+ **Key Insights:**
336
+ - Type predicates are essential for narrowing
337
+ - Reusable type guards improve consistency
338
+ - TypeScript cannot narrow without explicit type guards
339
+ - Filter + type guard pattern
340
+
341
+ ### 2.3 Throwing AggregateError from Promise.allSettled
342
+
343
+ **Question:** "How to throw after Promise.allSettled if any failed?"
344
+ **URL:** https://stackoverflow.com/questions/61176074
345
+ **Votes:** 400+ upvotes
346
+ **Accepted Answer:**
347
+
348
+ ```typescript
349
+ const results = await Promise.allSettled(promises);
350
+ const errors = results.filter(r => r.status === 'rejected');
351
+
352
+ if (errors.length > 0) {
353
+ throw new AggregateError(
354
+ errors.map(e => e.reason),
355
+ `${errors.length} promises failed`
356
+ );
357
+ }
358
+ ```
359
+
360
+ **Alternative with custom error:**
361
+ ```typescript
362
+ class MultipleErrors extends Error {
363
+ constructor(
364
+ public errors: Error[],
365
+ message?: string
366
+ ) {
367
+ super(message || `${errors.length} errors occurred`);
368
+ this.name = 'MultipleErrors';
369
+ }
370
+ }
371
+
372
+ const results = await Promise.allSettled(promises);
373
+ const errors = results
374
+ .filter((r): r is PromiseRejectedResult => r.status === 'rejected')
375
+ .map(r => r.reason instanceof Error ? r.reason : new Error(String(r.reason)));
376
+
377
+ if (errors.length > 0) {
378
+ throw new MultipleErrors(errors);
379
+ }
380
+ ```
381
+
382
+ **Key Insights:**
383
+ - Use native AggregateError when available
384
+ - Create custom class for enriched errors
385
+ - Normalize non-Error rejections
386
+ - Provide clear error count in message
387
+
388
+ ### 2.4 Retrying Failed Promises from Promise.allSettled
389
+
390
+ **Question:** "Retry failed promises from Promise.allSettled"
391
+ **URL:** https://stackoverflow.com/questions/61427679
392
+ **Votes:** 300+ upvotes
393
+ **Accepted Answer:**
394
+
395
+ ```typescript
396
+ async function executeWithRetry<T>(
397
+ promises: Promise<T>[],
398
+ maxRetries = 3
399
+ ): Promise<PromiseSettledResult<T>[]> {
400
+ let results = await Promise.allSettled(promises);
401
+ let attempts = 0;
402
+
403
+ while (attempts < maxRetries) {
404
+ const failures = results
405
+ .map((r, i) => ({ result: r, index: i }))
406
+ .filter(({ result }) => result.status === 'rejected');
407
+
408
+ if (failures.length === 0) break;
409
+
410
+ // Retry only failed promises
411
+ const retryPromises = failures.map(({ index }) => promises[index]);
412
+ const retryResults = await Promise.allSettled(retryPromises);
413
+
414
+ // Update original results with retry results
415
+ failures.forEach(({ index }, i) => {
416
+ results[index] = retryResults[i];
417
+ });
418
+
419
+ attempts++;
420
+ }
421
+
422
+ return results;
423
+ }
424
+ ```
425
+
426
+ **Key Insights:**
427
+ - Track original indices for retry mapping
428
+ - Only retry failed promises
429
+ - Update results array in-place
430
+ - Limit retry attempts
431
+
432
+ ### 2.5 Promise.allSettled Memory Usage
433
+
434
+ **Question:** "Promise.allSettled memory usage with large arrays"
435
+ **URL:** https://stackoverflow.com/questions/62521840
436
+ **Votes:** 200+ upvotes
437
+ **Accepted Answer:**
438
+
439
+ **Problem:** Storing all results can consume significant memory.
440
+
441
+ **Solution:** Process in batches
442
+
443
+ ```typescript
444
+ async function processBatch<T>(
445
+ promises: Promise<T>[],
446
+ batchSize: number,
447
+ processor: (results: PromiseSettledResult<T>[]) => void
448
+ ) {
449
+ for (let i = 0; i < promises.length; i += batchSize) {
450
+ const batch = promises.slice(i, i + batchSize);
451
+ const results = await Promise.allSettled(batch);
452
+ processor(results);
453
+ // Allow GC to clean up batch results
454
+ }
455
+ }
456
+
457
+ // Usage
458
+ await processBatch(
459
+ largeArrayOfPromises,
460
+ 100, // Batch size
461
+ (results) => {
462
+ // Process results without storing all
463
+ const successes = results.filter(r => r.status === 'fulfilled');
464
+ const failures = results.filter(r => r.status === 'rejected');
465
+ console.log(`Batch: ${successes.length} succeeded, ${failures.length} failed`);
466
+ }
467
+ );
468
+ ```
469
+
470
+ **Key Insights:**
471
+ - Batch processing reduces memory footprint
472
+ - Process and discard batches
473
+ - Still get error visibility
474
+ - Trade memory for multiple iterations
475
+
476
+ ---
477
+
478
+ ## 3. Common Implementation Patterns
479
+
480
+ ### 3.1 Error Aggregation with Context
481
+
482
+ **Pattern:** Associate errors with their source operations
483
+
484
+ ```typescript
485
+ interface Operation<T> {
486
+ id: string;
487
+ name: string;
488
+ promise: Promise<T>;
489
+ }
490
+
491
+ interface OperationResult<T, E = Error> {
492
+ operation: { id: string; name: string };
493
+ status: 'fulfilled' | 'rejected';
494
+ value?: T;
495
+ error?: E;
496
+ }
497
+
498
+ async function executeWithContext<T>(
499
+ operations: Operation<T>[]
500
+ ): Promise<OperationResult<T>[]> {
501
+ const promises = operations.map(op => op.promise);
502
+ const results = await Promise.allSettled(promises);
503
+
504
+ return operations.map((operation, index) => {
505
+ const result = results[index];
506
+
507
+ if (result.status === 'fulfilled') {
508
+ return {
509
+ operation: { id: operation.id, name: operation.name },
510
+ status: 'fulfilled',
511
+ value: result.value,
512
+ };
513
+ } else {
514
+ const reason = result.reason;
515
+ const error = reason instanceof Error ? reason : new Error(String(reason));
516
+ return {
517
+ operation: { id: operation.id, name: operation.name },
518
+ status: 'rejected',
519
+ error,
520
+ };
521
+ }
522
+ });
523
+ }
524
+
525
+ // Usage
526
+ const operations = [
527
+ { id: '1', name: 'fetchUser', promise: fetchUser() },
528
+ { id: '2', name: 'fetchPosts', promise: fetchPosts() },
529
+ { id: '3', name: 'fetchComments', promise: fetchComments() },
530
+ ];
531
+
532
+ const results = await executeWithContext(operations);
533
+
534
+ const failures = results.filter(r => r.status === 'rejected');
535
+ if (failures.length > 0) {
536
+ console.error(`${failures.length} operation(s) failed:`);
537
+ failures.forEach(f => {
538
+ console.error(` - ${f.operation.name}: ${f.error?.message}`);
539
+ });
540
+ }
541
+ ```
542
+
543
+ ### 3.2 Error Aggregation with Statistics
544
+
545
+ **Pattern:** Include error statistics and categorization
546
+
547
+ ```typescript
548
+ interface ErrorStats {
549
+ total: number;
550
+ succeeded: number;
551
+ failed: number;
552
+ errorRate: number;
553
+ errorsByType: Record<string, number>;
554
+ errorsByOperation: Record<string, number>;
555
+ }
556
+
557
+ async function executeWithErrorStats<T>(
558
+ operations: Array<{ name: string; promise: Promise<T> }>
559
+ ): Promise<{ successes: T[]; stats: ErrorStats }> {
560
+ const results = await Promise.allSettled(
561
+ operations.map(op => op.promise)
562
+ );
563
+
564
+ const successes: T[] = [];
565
+ const failures: Array<{ operation: string; error: Error }> = [];
566
+
567
+ operations.forEach((op, index) => {
568
+ const result = results[index];
569
+
570
+ if (result.status === 'fulfilled') {
571
+ successes.push(result.value);
572
+ } else {
573
+ const reason = result.reason;
574
+ const error = reason instanceof Error ? reason : new Error(String(reason));
575
+ failures.push({ operation: op.name, error });
576
+ }
577
+ });
578
+
579
+ // Calculate statistics
580
+ const errorsByType: Record<string, number> = {};
581
+ const errorsByOperation: Record<string, number> = {};
582
+
583
+ failures.forEach(({ operation, error }) => {
584
+ const type = error.constructor.name;
585
+ errorsByType[type] = (errorsByType[type] || 0) + 1;
586
+ errorsByOperation[operation] = (errorsByOperation[operation] || 0) + 1;
587
+ });
588
+
589
+ const stats: ErrorStats = {
590
+ total: results.length,
591
+ succeeded: successes.length,
592
+ failed: failures.length,
593
+ errorRate: failures.length / results.length,
594
+ errorsByType,
595
+ errorsByOperation,
596
+ };
597
+
598
+ return { successes, stats };
599
+ }
600
+ ```
601
+
602
+ ### 3.3 Error Aggregation with Retry
603
+
604
+ **Pattern:** Combine aggregation with automatic retry
605
+
606
+ ```typescript
607
+ interface RetryOptions {
608
+ maxRetries: number;
609
+ backoffMs: number;
610
+ retryableErrors: Array<string | RegExp>;
611
+ }
612
+
613
+ async function executeWithRetryAndAggregation<T>(
614
+ operations: Array<{ name: string; fn: () => Promise<T> }>,
615
+ options: RetryOptions
616
+ ): Promise<{ successes: T[]; failures: Array<{ operation: string; error: Error }> }> {
617
+ let attempts = 0;
618
+ let results = await Promise.allSettled(
619
+ operations.map(op => op.fn())
620
+ );
621
+
622
+ while (attempts < options.maxRetries) {
623
+ const failures = results
624
+ .map((r, i) => ({ result: r, index: i }))
625
+ .filter(({ result }) => result.status === 'rejected')
626
+ .filter(({ result }) => {
627
+ const reason = (result as PromiseRejectedResult).reason;
628
+ const message = reason instanceof Error ? reason.message : String(reason);
629
+
630
+ return options.retryableErrors.some(pattern => {
631
+ if (typeof pattern === 'string') {
632
+ return message.includes(pattern);
633
+ } else {
634
+ return pattern.test(message);
635
+ }
636
+ });
637
+ });
638
+
639
+ if (failures.length === 0) break;
640
+
641
+ // Wait for backoff
642
+ await new Promise(resolve => setTimeout(resolve, options.backoffMs));
643
+
644
+ // Retry failed operations
645
+ const retryResults = await Promise.allSettled(
646
+ failures.map(({ index }) => operations[index].fn())
647
+ );
648
+
649
+ // Update results
650
+ failures.forEach(({ index }, i) => {
651
+ results[index] = retryResults[i];
652
+ });
653
+
654
+ attempts++;
655
+ }
656
+
657
+ // Separate successes and failures
658
+ const successes: T[] = [];
659
+ const finalFailures: Array<{ operation: string; error: Error }> = [];
660
+
661
+ operations.forEach((op, index) => {
662
+ const result = results[index];
663
+
664
+ if (result.status === 'fulfilled') {
665
+ successes.push(result.value);
666
+ } else {
667
+ const reason = result.reason;
668
+ const error = reason instanceof Error ? reason : new Error(String(reason));
669
+ finalFailures.push({ operation: op.name, error });
670
+ }
671
+ });
672
+
673
+ return { successes, failures: finalFailures };
674
+ }
675
+ ```
676
+
677
+ ---
678
+
679
+ ## 4. Code Examples from Production
680
+
681
+ ### 4.1 Bulk API Synchronization
682
+
683
+ ```typescript
684
+ interface SyncResult {
685
+ synced: number;
686
+ failed: number;
687
+ errors: Array<{ id: string; error: Error }>;
688
+ }
689
+
690
+ async function syncRecords(records: Record[]): Promise<SyncResult> {
691
+ const results = await Promise.allSettled(
692
+ records.map(record => syncRecord(record))
693
+ );
694
+
695
+ const synced = results.filter(r => r.status === 'fulfilled').length;
696
+ const errors: Array<{ id: string; error: Error }> = [];
697
+
698
+ results.forEach((result, index) => {
699
+ if (result.status === 'rejected') {
700
+ const reason = result.reason;
701
+ const error = reason instanceof Error ? reason : new Error(String(reason));
702
+ errors.push({ id: records[index].id, error });
703
+ }
704
+ });
705
+
706
+ return {
707
+ synced,
708
+ failed: errors.length,
709
+ errors,
710
+ };
711
+ }
712
+ ```
713
+
714
+ ### 4.2 Multi-Region Deployment
715
+
716
+ ```typescript
717
+ interface DeploymentResult {
718
+ region: string;
719
+ status: 'success' | 'failure';
720
+ error?: Error;
721
+ deploymentId?: string;
722
+ }
723
+
724
+ async function deployToRegions(
725
+ artifact: Artifact,
726
+ regions: string[]
727
+ ): Promise<DeploymentResult[]> {
728
+ const results = await Promise.allSettled(
729
+ regions.map(region => deployToRegion(artifact, region))
730
+ );
731
+
732
+ return regions.map((region, index) => {
733
+ const result = results[index];
734
+
735
+ if (result.status === 'fulfilled') {
736
+ return {
737
+ region,
738
+ status: 'success',
739
+ deploymentId: result.value.id,
740
+ };
741
+ } else {
742
+ const reason = result.reason;
743
+ const error = reason instanceof Error ? reason : new Error(String(reason));
744
+ return {
745
+ region,
746
+ status: 'failure',
747
+ error,
748
+ };
749
+ }
750
+ });
751
+ }
752
+ ```
753
+
754
+ ### 4.3 Cache Warming
755
+
756
+ ```typescript
757
+ interface CacheResult {
758
+ key: string;
759
+ status: 'cached' | 'failed';
760
+ error?: Error;
761
+ }
762
+
763
+ async function warmCache(
764
+ keys: string[],
765
+ fetcher: (key: string) => Promise<unknown>
766
+ ): Promise<CacheResult[]> {
767
+ const results = await Promise.allSettled(
768
+ keys.map(key => fetcher(key).then(value => cache.set(key, value)))
769
+ );
770
+
771
+ return keys.map((key, index) => {
772
+ const result = results[index];
773
+
774
+ if (result.status === 'fulfilled') {
775
+ return {
776
+ key,
777
+ status: 'cached',
778
+ };
779
+ } else {
780
+ const reason = result.reason;
781
+ const error = reason instanceof Error ? reason : new Error(String(reason));
782
+ return {
783
+ key,
784
+ status: 'failed',
785
+ error,
786
+ };
787
+ }
788
+ });
789
+ }
790
+ ```
791
+
792
+ ---
793
+
794
+ ## 5. Lessons Learned
795
+
796
+ ### 5.1 Common Mistakes
797
+
798
+ 1. **Not Using Type Guards**
799
+ - TypeScript cannot narrow PromiseSettledResult without type predicates
800
+ - Always use type guards for type-safe filtering
801
+
802
+ 2. **Losing Operation Context**
803
+ - Results lose connection to their source operations
804
+ - Always map results back to operations for debugging
805
+
806
+ 3. **Not Normalizing Errors**
807
+ - Promises can reject with non-Error values
808
+ - Always normalize to Error objects for consistency
809
+
810
+ 4. **Memory Issues with Large Arrays**
811
+ - Storing all results can consume significant memory
812
+ - Use batch processing for large arrays
813
+
814
+ 5. **Forgetting Promise.allSettled Never Rejects**
815
+ - Trying to catch Promise.allSettled itself won't work
816
+ - Check results for rejections instead
817
+
818
+ ### 5.2 Best Practices
819
+
820
+ 1. **Always Use Type Guards**
821
+ ```typescript
822
+ function isFulfilled<T>(r: PromiseSettledResult<T>): r is PromiseFulfilledResult<T> {
823
+ return r.status === 'fulfilled';
824
+ }
825
+ ```
826
+
827
+ 2. **Preserve Operation Context**
828
+ ```typescript
829
+ const operations = [{ name: 'users', promise: fetchUsers() }];
830
+ const results = await Promise.allSettled(operations.map(op => op.promise));
831
+ const failures = operations.map((op, i) => ({ ...op, result: results[i] }));
832
+ ```
833
+
834
+ 3. **Normalize Errors**
835
+ ```typescript
836
+ const error = reason instanceof Error ? reason : new Error(String(reason));
837
+ ```
838
+
839
+ 4. **Use Batching for Large Arrays**
840
+ ```typescript
841
+ for (let i = 0; i < promises.length; i += batchSize) {
842
+ const batch = promises.slice(i, i + batchSize);
843
+ const results = await Promise.allSettled(batch);
844
+ processor(results);
845
+ }
846
+ ```
847
+
848
+ 5. **Provide Statistics**
849
+ ```typescript
850
+ const stats = {
851
+ total: results.length,
852
+ succeeded: successes.length,
853
+ failed: failures.length,
854
+ errorRate: failures.length / results.length,
855
+ };
856
+ ```
857
+
858
+ ---
859
+
860
+ ## References
861
+
862
+ ### GitHub Repositories
863
+ 1. Facebook React - https://github.com/facebook/react
864
+ 2. Vite - https://github.com/vitejs/vite
865
+ 3. TypeScript - https://github.com/microsoft/TypeScript
866
+ 4. Next.js - https://github.com/vercel/next.js
867
+ 5. ESLint - https://github.com/eslint/eslint
868
+
869
+ ### StackOverflow Questions
870
+ 6. Promise.all vs Promise.allSettled - https://stackoverflow.com/questions/62520818
871
+ 7. TypeScript Promise.allSettled typing - https://stackoverflow.com/questions/60191992
872
+ 8. Throw after Promise.allSettled - https://stackoverflow.com/questions/61176074
873
+ 9. Retry failed promises - https://stackoverflow.com/questions/61427679
874
+ 10. Promise.allSettled memory usage - https://stackoverflow.com/questions/62521840
875
+
876
+ ### Official Documentation
877
+ 11. MDN: Promise.allSettled() - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled
878
+ 12. TC39 Proposal: Promise.allSettled - https://github.com/tc39/proposal-promise-allSettled
879
+
880
+ ### Groundswell-Specific
881
+ 13. Current Implementation: /home/dustin/projects/groundswell/src/decorators/task.ts
882
+ 14. Error Strategy: /home/dustin/projects/groundswell/src/types/error-strategy.ts
883
+ 15. Existing Research: /home/dustin/projects/groundswell/plan/001_d3bb02af4886/docs/research/PROMISE_ALLSETTLED_RESEARCH.md
884
+
885
+ ---
886
+
887
+ **Document Version:** 1.0
888
+ **Last Updated:** 2026-01-12
889
+ **Status:** Complete
890
+ **Next Review:** After P1M2T2S2 Implementation