@dragonflymcp/plugin 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (666) hide show
  1. package/.claude-plugin/plugin.json +26 -0
  2. package/LICENSE +21 -0
  3. package/README.md +126 -0
  4. package/dist/core/annotations.d.ts +71 -0
  5. package/dist/core/annotations.d.ts.map +1 -0
  6. package/dist/core/annotations.js +61 -0
  7. package/dist/core/annotations.js.map +1 -0
  8. package/dist/core/config.d.ts +66 -0
  9. package/dist/core/config.d.ts.map +1 -0
  10. package/dist/core/config.js +131 -0
  11. package/dist/core/config.js.map +1 -0
  12. package/dist/core/dispatcher.d.ts +77 -0
  13. package/dist/core/dispatcher.d.ts.map +1 -0
  14. package/dist/core/dispatcher.js +132 -0
  15. package/dist/core/dispatcher.js.map +1 -0
  16. package/dist/core/server.d.ts +24 -0
  17. package/dist/core/server.d.ts.map +1 -0
  18. package/dist/core/server.js +41 -0
  19. package/dist/core/server.js.map +1 -0
  20. package/dist/core/store.d.ts +91 -0
  21. package/dist/core/store.d.ts.map +1 -0
  22. package/dist/core/store.js +157 -0
  23. package/dist/core/store.js.map +1 -0
  24. package/dist/core/types.d.ts +128 -0
  25. package/dist/core/types.d.ts.map +1 -0
  26. package/dist/core/types.js +5 -0
  27. package/dist/core/types.js.map +1 -0
  28. package/dist/index.d.ts +22 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +81 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/test-utils/store-harness.d.ts +41 -0
  33. package/dist/test-utils/store-harness.d.ts.map +1 -0
  34. package/dist/test-utils/store-harness.js +61 -0
  35. package/dist/test-utils/store-harness.js.map +1 -0
  36. package/dist/tools/analytics/aggregators.d.ts +18 -0
  37. package/dist/tools/analytics/aggregators.d.ts.map +1 -0
  38. package/dist/tools/analytics/aggregators.js +260 -0
  39. package/dist/tools/analytics/aggregators.js.map +1 -0
  40. package/dist/tools/analytics/aggregators.test.d.ts +2 -0
  41. package/dist/tools/analytics/aggregators.test.d.ts.map +1 -0
  42. package/dist/tools/analytics/aggregators.test.js +177 -0
  43. package/dist/tools/analytics/aggregators.test.js.map +1 -0
  44. package/dist/tools/analytics/drift.d.ts +15 -0
  45. package/dist/tools/analytics/drift.d.ts.map +1 -0
  46. package/dist/tools/analytics/drift.js +135 -0
  47. package/dist/tools/analytics/drift.js.map +1 -0
  48. package/dist/tools/analytics/drift.test.d.ts +2 -0
  49. package/dist/tools/analytics/drift.test.d.ts.map +1 -0
  50. package/dist/tools/analytics/drift.test.js +99 -0
  51. package/dist/tools/analytics/drift.test.js.map +1 -0
  52. package/dist/tools/analytics/index.d.ts +10 -0
  53. package/dist/tools/analytics/index.d.ts.map +1 -0
  54. package/dist/tools/analytics/index.js +192 -0
  55. package/dist/tools/analytics/index.js.map +1 -0
  56. package/dist/tools/analytics/learner.d.ts +29 -0
  57. package/dist/tools/analytics/learner.d.ts.map +1 -0
  58. package/dist/tools/analytics/learner.js +135 -0
  59. package/dist/tools/analytics/learner.js.map +1 -0
  60. package/dist/tools/analytics/learner.test.d.ts +2 -0
  61. package/dist/tools/analytics/learner.test.d.ts.map +1 -0
  62. package/dist/tools/analytics/learner.test.js +118 -0
  63. package/dist/tools/analytics/learner.test.js.map +1 -0
  64. package/dist/tools/analytics/observe.d.ts +22 -0
  65. package/dist/tools/analytics/observe.d.ts.map +1 -0
  66. package/dist/tools/analytics/observe.js +143 -0
  67. package/dist/tools/analytics/observe.js.map +1 -0
  68. package/dist/tools/analytics/observe.test.d.ts +2 -0
  69. package/dist/tools/analytics/observe.test.d.ts.map +1 -0
  70. package/dist/tools/analytics/observe.test.js +95 -0
  71. package/dist/tools/analytics/observe.test.js.map +1 -0
  72. package/dist/tools/analytics/store.d.ts +29 -0
  73. package/dist/tools/analytics/store.d.ts.map +1 -0
  74. package/dist/tools/analytics/store.js +192 -0
  75. package/dist/tools/analytics/store.js.map +1 -0
  76. package/dist/tools/analytics/types.d.ts +290 -0
  77. package/dist/tools/analytics/types.d.ts.map +1 -0
  78. package/dist/tools/analytics/types.js +7 -0
  79. package/dist/tools/analytics/types.js.map +1 -0
  80. package/dist/tools/ast/index.d.ts +8 -0
  81. package/dist/tools/ast/index.d.ts.map +1 -0
  82. package/dist/tools/ast/index.js +242 -0
  83. package/dist/tools/ast/index.js.map +1 -0
  84. package/dist/tools/ast/indexer.d.ts +41 -0
  85. package/dist/tools/ast/indexer.d.ts.map +1 -0
  86. package/dist/tools/ast/indexer.js +617 -0
  87. package/dist/tools/ast/indexer.js.map +1 -0
  88. package/dist/tools/ast/store.d.ts +87 -0
  89. package/dist/tools/ast/store.d.ts.map +1 -0
  90. package/dist/tools/ast/store.js +280 -0
  91. package/dist/tools/ast/store.js.map +1 -0
  92. package/dist/tools/ast/store.test.d.ts +6 -0
  93. package/dist/tools/ast/store.test.d.ts.map +1 -0
  94. package/dist/tools/ast/store.test.js +257 -0
  95. package/dist/tools/ast/store.test.js.map +1 -0
  96. package/dist/tools/bridge/bridge.d.ts +37 -0
  97. package/dist/tools/bridge/bridge.d.ts.map +1 -0
  98. package/dist/tools/bridge/bridge.js +82 -0
  99. package/dist/tools/bridge/bridge.js.map +1 -0
  100. package/dist/tools/bridge/bridge.test.d.ts +2 -0
  101. package/dist/tools/bridge/bridge.test.d.ts.map +1 -0
  102. package/dist/tools/bridge/bridge.test.js +119 -0
  103. package/dist/tools/bridge/bridge.test.js.map +1 -0
  104. package/dist/tools/bridge/index.d.ts +8 -0
  105. package/dist/tools/bridge/index.d.ts.map +1 -0
  106. package/dist/tools/bridge/index.js +153 -0
  107. package/dist/tools/bridge/index.js.map +1 -0
  108. package/dist/tools/bridge/store.d.ts +45 -0
  109. package/dist/tools/bridge/store.d.ts.map +1 -0
  110. package/dist/tools/bridge/store.js +307 -0
  111. package/dist/tools/bridge/store.js.map +1 -0
  112. package/dist/tools/bridge/store.test.d.ts +2 -0
  113. package/dist/tools/bridge/store.test.d.ts.map +1 -0
  114. package/dist/tools/bridge/store.test.js +180 -0
  115. package/dist/tools/bridge/store.test.js.map +1 -0
  116. package/dist/tools/bridge/types.d.ts +44 -0
  117. package/dist/tools/bridge/types.d.ts.map +1 -0
  118. package/dist/tools/bridge/types.js +6 -0
  119. package/dist/tools/bridge/types.js.map +1 -0
  120. package/dist/tools/evolve/algorithm.d.ts +33 -0
  121. package/dist/tools/evolve/algorithm.d.ts.map +1 -0
  122. package/dist/tools/evolve/algorithm.js +64 -0
  123. package/dist/tools/evolve/algorithm.js.map +1 -0
  124. package/dist/tools/evolve/algorithm.test.d.ts +6 -0
  125. package/dist/tools/evolve/algorithm.test.d.ts.map +1 -0
  126. package/dist/tools/evolve/algorithm.test.js +138 -0
  127. package/dist/tools/evolve/algorithm.test.js.map +1 -0
  128. package/dist/tools/evolve/index.d.ts +11 -0
  129. package/dist/tools/evolve/index.d.ts.map +1 -0
  130. package/dist/tools/evolve/index.js +300 -0
  131. package/dist/tools/evolve/index.js.map +1 -0
  132. package/dist/tools/evolve/store.d.ts +27 -0
  133. package/dist/tools/evolve/store.d.ts.map +1 -0
  134. package/dist/tools/evolve/store.js +147 -0
  135. package/dist/tools/evolve/store.js.map +1 -0
  136. package/dist/tools/evolve/store.test.d.ts +6 -0
  137. package/dist/tools/evolve/store.test.d.ts.map +1 -0
  138. package/dist/tools/evolve/store.test.js +162 -0
  139. package/dist/tools/evolve/store.test.js.map +1 -0
  140. package/dist/tools/evolve/types.d.ts +38 -0
  141. package/dist/tools/evolve/types.d.ts.map +1 -0
  142. package/dist/tools/evolve/types.js +6 -0
  143. package/dist/tools/evolve/types.js.map +1 -0
  144. package/dist/tools/framework/content-loader.d.ts +45 -0
  145. package/dist/tools/framework/content-loader.d.ts.map +1 -0
  146. package/dist/tools/framework/content-loader.js +258 -0
  147. package/dist/tools/framework/content-loader.js.map +1 -0
  148. package/dist/tools/framework/content-loader.test.d.ts +5 -0
  149. package/dist/tools/framework/content-loader.test.d.ts.map +1 -0
  150. package/dist/tools/framework/content-loader.test.js +262 -0
  151. package/dist/tools/framework/content-loader.test.js.map +1 -0
  152. package/dist/tools/framework/index.d.ts +30 -0
  153. package/dist/tools/framework/index.d.ts.map +1 -0
  154. package/dist/tools/framework/index.js +517 -0
  155. package/dist/tools/framework/index.js.map +1 -0
  156. package/dist/tools/framework/session.d.ts +85 -0
  157. package/dist/tools/framework/session.d.ts.map +1 -0
  158. package/dist/tools/framework/session.js +311 -0
  159. package/dist/tools/framework/session.js.map +1 -0
  160. package/dist/tools/framework/session.test.d.ts +5 -0
  161. package/dist/tools/framework/session.test.d.ts.map +1 -0
  162. package/dist/tools/framework/session.test.js +291 -0
  163. package/dist/tools/framework/session.test.js.map +1 -0
  164. package/dist/tools/framework/sync-evaluator.d.ts +41 -0
  165. package/dist/tools/framework/sync-evaluator.d.ts.map +1 -0
  166. package/dist/tools/framework/sync-evaluator.js +298 -0
  167. package/dist/tools/framework/sync-evaluator.js.map +1 -0
  168. package/dist/tools/framework/sync-evaluator.test.d.ts +5 -0
  169. package/dist/tools/framework/sync-evaluator.test.d.ts.map +1 -0
  170. package/dist/tools/framework/sync-evaluator.test.js +288 -0
  171. package/dist/tools/framework/sync-evaluator.test.js.map +1 -0
  172. package/dist/tools/framework/types.d.ts +279 -0
  173. package/dist/tools/framework/types.d.ts.map +1 -0
  174. package/dist/tools/framework/types.js +6 -0
  175. package/dist/tools/framework/types.js.map +1 -0
  176. package/dist/tools/framework/workflow-intelligence.d.ts +55 -0
  177. package/dist/tools/framework/workflow-intelligence.d.ts.map +1 -0
  178. package/dist/tools/framework/workflow-intelligence.js +199 -0
  179. package/dist/tools/framework/workflow-intelligence.js.map +1 -0
  180. package/dist/tools/framework/workflow-intelligence.test.d.ts +6 -0
  181. package/dist/tools/framework/workflow-intelligence.test.d.ts.map +1 -0
  182. package/dist/tools/framework/workflow-intelligence.test.js +257 -0
  183. package/dist/tools/framework/workflow-intelligence.test.js.map +1 -0
  184. package/dist/tools/framework/workflow-planner.d.ts +10 -0
  185. package/dist/tools/framework/workflow-planner.d.ts.map +1 -0
  186. package/dist/tools/framework/workflow-planner.js +214 -0
  187. package/dist/tools/framework/workflow-planner.js.map +1 -0
  188. package/dist/tools/framework/workflow-planner.test.d.ts +5 -0
  189. package/dist/tools/framework/workflow-planner.test.d.ts.map +1 -0
  190. package/dist/tools/framework/workflow-planner.test.js +137 -0
  191. package/dist/tools/framework/workflow-planner.test.js.map +1 -0
  192. package/dist/tools/knowledge/bridge.d.ts +34 -0
  193. package/dist/tools/knowledge/bridge.d.ts.map +1 -0
  194. package/dist/tools/knowledge/bridge.js +249 -0
  195. package/dist/tools/knowledge/bridge.js.map +1 -0
  196. package/dist/tools/knowledge/bridge.test.d.ts +5 -0
  197. package/dist/tools/knowledge/bridge.test.d.ts.map +1 -0
  198. package/dist/tools/knowledge/bridge.test.js +221 -0
  199. package/dist/tools/knowledge/bridge.test.js.map +1 -0
  200. package/dist/tools/knowledge/extractor.d.ts +22 -0
  201. package/dist/tools/knowledge/extractor.d.ts.map +1 -0
  202. package/dist/tools/knowledge/extractor.js +154 -0
  203. package/dist/tools/knowledge/extractor.js.map +1 -0
  204. package/dist/tools/knowledge/index.d.ts +12 -0
  205. package/dist/tools/knowledge/index.d.ts.map +1 -0
  206. package/dist/tools/knowledge/index.js +505 -0
  207. package/dist/tools/knowledge/index.js.map +1 -0
  208. package/dist/tools/knowledge/retrieval.d.ts +28 -0
  209. package/dist/tools/knowledge/retrieval.d.ts.map +1 -0
  210. package/dist/tools/knowledge/retrieval.js +164 -0
  211. package/dist/tools/knowledge/retrieval.js.map +1 -0
  212. package/dist/tools/knowledge/store.d.ts +96 -0
  213. package/dist/tools/knowledge/store.d.ts.map +1 -0
  214. package/dist/tools/knowledge/store.js +562 -0
  215. package/dist/tools/knowledge/store.js.map +1 -0
  216. package/dist/tools/knowledge/store.test.d.ts +6 -0
  217. package/dist/tools/knowledge/store.test.d.ts.map +1 -0
  218. package/dist/tools/knowledge/store.test.js +385 -0
  219. package/dist/tools/knowledge/store.test.js.map +1 -0
  220. package/dist/tools/knowledge/types.d.ts +168 -0
  221. package/dist/tools/knowledge/types.d.ts.map +1 -0
  222. package/dist/tools/knowledge/types.js +6 -0
  223. package/dist/tools/knowledge/types.js.map +1 -0
  224. package/dist/tools/memory/evolution.d.ts +31 -0
  225. package/dist/tools/memory/evolution.d.ts.map +1 -0
  226. package/dist/tools/memory/evolution.js +130 -0
  227. package/dist/tools/memory/evolution.js.map +1 -0
  228. package/dist/tools/memory/index.d.ts +11 -0
  229. package/dist/tools/memory/index.d.ts.map +1 -0
  230. package/dist/tools/memory/index.js +239 -0
  231. package/dist/tools/memory/index.js.map +1 -0
  232. package/dist/tools/memory/store.d.ts +75 -0
  233. package/dist/tools/memory/store.d.ts.map +1 -0
  234. package/dist/tools/memory/store.js +398 -0
  235. package/dist/tools/memory/store.js.map +1 -0
  236. package/dist/tools/memory/store.test.d.ts +6 -0
  237. package/dist/tools/memory/store.test.d.ts.map +1 -0
  238. package/dist/tools/memory/store.test.js +429 -0
  239. package/dist/tools/memory/store.test.js.map +1 -0
  240. package/dist/tools/memory/types.d.ts +171 -0
  241. package/dist/tools/memory/types.d.ts.map +1 -0
  242. package/dist/tools/memory/types.js +6 -0
  243. package/dist/tools/memory/types.js.map +1 -0
  244. package/dist/tools/pipeline/composer.d.ts +29 -0
  245. package/dist/tools/pipeline/composer.d.ts.map +1 -0
  246. package/dist/tools/pipeline/composer.js +225 -0
  247. package/dist/tools/pipeline/composer.js.map +1 -0
  248. package/dist/tools/pipeline/composer.test.d.ts +2 -0
  249. package/dist/tools/pipeline/composer.test.d.ts.map +1 -0
  250. package/dist/tools/pipeline/composer.test.js +162 -0
  251. package/dist/tools/pipeline/composer.test.js.map +1 -0
  252. package/dist/tools/pipeline/index.d.ts +8 -0
  253. package/dist/tools/pipeline/index.d.ts.map +1 -0
  254. package/dist/tools/pipeline/index.js +102 -0
  255. package/dist/tools/pipeline/index.js.map +1 -0
  256. package/dist/tools/pipeline/planner.d.ts +10 -0
  257. package/dist/tools/pipeline/planner.d.ts.map +1 -0
  258. package/dist/tools/pipeline/planner.js +147 -0
  259. package/dist/tools/pipeline/planner.js.map +1 -0
  260. package/dist/tools/pipeline/planner.test.d.ts +2 -0
  261. package/dist/tools/pipeline/planner.test.d.ts.map +1 -0
  262. package/dist/tools/pipeline/planner.test.js +96 -0
  263. package/dist/tools/pipeline/planner.test.js.map +1 -0
  264. package/dist/tools/pipeline/preconditions.d.ts +14 -0
  265. package/dist/tools/pipeline/preconditions.d.ts.map +1 -0
  266. package/dist/tools/pipeline/preconditions.js +65 -0
  267. package/dist/tools/pipeline/preconditions.js.map +1 -0
  268. package/dist/tools/pipeline/preconditions.test.d.ts +2 -0
  269. package/dist/tools/pipeline/preconditions.test.d.ts.map +1 -0
  270. package/dist/tools/pipeline/preconditions.test.js +74 -0
  271. package/dist/tools/pipeline/preconditions.test.js.map +1 -0
  272. package/dist/tools/pipeline/types.d.ts +105 -0
  273. package/dist/tools/pipeline/types.d.ts.map +1 -0
  274. package/dist/tools/pipeline/types.js +6 -0
  275. package/dist/tools/pipeline/types.js.map +1 -0
  276. package/dist/tools/repair/index.d.ts +8 -0
  277. package/dist/tools/repair/index.d.ts.map +1 -0
  278. package/dist/tools/repair/index.js +384 -0
  279. package/dist/tools/repair/index.js.map +1 -0
  280. package/dist/tools/repair/repairer.d.ts +67 -0
  281. package/dist/tools/repair/repairer.d.ts.map +1 -0
  282. package/dist/tools/repair/repairer.js +257 -0
  283. package/dist/tools/repair/repairer.js.map +1 -0
  284. package/dist/tools/repair/repairer.test.d.ts +6 -0
  285. package/dist/tools/repair/repairer.test.d.ts.map +1 -0
  286. package/dist/tools/repair/repairer.test.js +159 -0
  287. package/dist/tools/repair/repairer.test.js.map +1 -0
  288. package/dist/tools/semantic/chunker.d.ts +23 -0
  289. package/dist/tools/semantic/chunker.d.ts.map +1 -0
  290. package/dist/tools/semantic/chunker.js +244 -0
  291. package/dist/tools/semantic/chunker.js.map +1 -0
  292. package/dist/tools/semantic/embedder.d.ts +16 -0
  293. package/dist/tools/semantic/embedder.d.ts.map +1 -0
  294. package/dist/tools/semantic/embedder.js +88 -0
  295. package/dist/tools/semantic/embedder.js.map +1 -0
  296. package/dist/tools/semantic/index.d.ts +8 -0
  297. package/dist/tools/semantic/index.d.ts.map +1 -0
  298. package/dist/tools/semantic/index.js +144 -0
  299. package/dist/tools/semantic/index.js.map +1 -0
  300. package/dist/tools/semantic/store.d.ts +31 -0
  301. package/dist/tools/semantic/store.d.ts.map +1 -0
  302. package/dist/tools/semantic/store.js +168 -0
  303. package/dist/tools/semantic/store.js.map +1 -0
  304. package/dist/tools/semantic/store.test.d.ts +6 -0
  305. package/dist/tools/semantic/store.test.d.ts.map +1 -0
  306. package/dist/tools/semantic/store.test.js +240 -0
  307. package/dist/tools/semantic/store.test.js.map +1 -0
  308. package/dist/tools/spec/generator.d.ts +32 -0
  309. package/dist/tools/spec/generator.d.ts.map +1 -0
  310. package/dist/tools/spec/generator.js +278 -0
  311. package/dist/tools/spec/generator.js.map +1 -0
  312. package/dist/tools/spec/generator.test.d.ts +6 -0
  313. package/dist/tools/spec/generator.test.d.ts.map +1 -0
  314. package/dist/tools/spec/generator.test.js +208 -0
  315. package/dist/tools/spec/generator.test.js.map +1 -0
  316. package/dist/tools/spec/index.d.ts +11 -0
  317. package/dist/tools/spec/index.d.ts.map +1 -0
  318. package/dist/tools/spec/index.js +426 -0
  319. package/dist/tools/spec/index.js.map +1 -0
  320. package/dist/tools/spec/store.d.ts +24 -0
  321. package/dist/tools/spec/store.d.ts.map +1 -0
  322. package/dist/tools/spec/store.js +104 -0
  323. package/dist/tools/spec/store.js.map +1 -0
  324. package/dist/tools/spec/store.test.d.ts +6 -0
  325. package/dist/tools/spec/store.test.d.ts.map +1 -0
  326. package/dist/tools/spec/store.test.js +173 -0
  327. package/dist/tools/spec/store.test.js.map +1 -0
  328. package/dist/tools/spec/types.d.ts +61 -0
  329. package/dist/tools/spec/types.d.ts.map +1 -0
  330. package/dist/tools/spec/types.js +6 -0
  331. package/dist/tools/spec/types.js.map +1 -0
  332. package/dist/tools/state/index.d.ts +11 -0
  333. package/dist/tools/state/index.d.ts.map +1 -0
  334. package/dist/tools/state/index.js +386 -0
  335. package/dist/tools/state/index.js.map +1 -0
  336. package/dist/tools/state/migrate.d.ts +39 -0
  337. package/dist/tools/state/migrate.d.ts.map +1 -0
  338. package/dist/tools/state/migrate.js +242 -0
  339. package/dist/tools/state/migrate.js.map +1 -0
  340. package/dist/tools/state/migrate.test.d.ts +2 -0
  341. package/dist/tools/state/migrate.test.d.ts.map +1 -0
  342. package/dist/tools/state/migrate.test.js +265 -0
  343. package/dist/tools/state/migrate.test.js.map +1 -0
  344. package/dist/tools/state/store.d.ts +107 -0
  345. package/dist/tools/state/store.d.ts.map +1 -0
  346. package/dist/tools/state/store.js +365 -0
  347. package/dist/tools/state/store.js.map +1 -0
  348. package/dist/tools/state/store.test.d.ts +5 -0
  349. package/dist/tools/state/store.test.d.ts.map +1 -0
  350. package/dist/tools/state/store.test.js +293 -0
  351. package/dist/tools/state/store.test.js.map +1 -0
  352. package/dist/tools/state/types.d.ts +90 -0
  353. package/dist/tools/state/types.d.ts.map +1 -0
  354. package/dist/tools/state/types.js +6 -0
  355. package/dist/tools/state/types.js.map +1 -0
  356. package/dist/tools/testing/analyzer.d.ts +44 -0
  357. package/dist/tools/testing/analyzer.d.ts.map +1 -0
  358. package/dist/tools/testing/analyzer.js +280 -0
  359. package/dist/tools/testing/analyzer.js.map +1 -0
  360. package/dist/tools/testing/generator.d.ts +57 -0
  361. package/dist/tools/testing/generator.d.ts.map +1 -0
  362. package/dist/tools/testing/generator.js +478 -0
  363. package/dist/tools/testing/generator.js.map +1 -0
  364. package/dist/tools/testing/generator.test.d.ts +6 -0
  365. package/dist/tools/testing/generator.test.d.ts.map +1 -0
  366. package/dist/tools/testing/generator.test.js +285 -0
  367. package/dist/tools/testing/generator.test.js.map +1 -0
  368. package/dist/tools/testing/index.d.ts +8 -0
  369. package/dist/tools/testing/index.d.ts.map +1 -0
  370. package/dist/tools/testing/index.js +373 -0
  371. package/dist/tools/testing/index.js.map +1 -0
  372. package/dist/utils/embedder.d.ts +7 -0
  373. package/dist/utils/embedder.d.ts.map +1 -0
  374. package/dist/utils/embedder.js +13 -0
  375. package/dist/utils/embedder.js.map +1 -0
  376. package/dist/utils/execution.d.ts +68 -0
  377. package/dist/utils/execution.d.ts.map +1 -0
  378. package/dist/utils/execution.js +467 -0
  379. package/dist/utils/execution.js.map +1 -0
  380. package/dist/utils/graph.d.ts +26 -0
  381. package/dist/utils/graph.d.ts.map +1 -0
  382. package/dist/utils/graph.js +32 -0
  383. package/dist/utils/graph.js.map +1 -0
  384. package/dist/utils/guards.d.ts +32 -0
  385. package/dist/utils/guards.d.ts.map +1 -0
  386. package/dist/utils/guards.js +40 -0
  387. package/dist/utils/guards.js.map +1 -0
  388. package/dist/utils/ids.d.ts +5 -0
  389. package/dist/utils/ids.d.ts.map +1 -0
  390. package/dist/utils/ids.js +7 -0
  391. package/dist/utils/ids.js.map +1 -0
  392. package/dist/utils/languages.d.ts +34 -0
  393. package/dist/utils/languages.d.ts.map +1 -0
  394. package/dist/utils/languages.js +153 -0
  395. package/dist/utils/languages.js.map +1 -0
  396. package/dist/utils/lazy.d.ts +17 -0
  397. package/dist/utils/lazy.d.ts.map +1 -0
  398. package/dist/utils/lazy.js +35 -0
  399. package/dist/utils/lazy.js.map +1 -0
  400. package/dist/utils/project.d.ts +41 -0
  401. package/dist/utils/project.d.ts.map +1 -0
  402. package/dist/utils/project.js +82 -0
  403. package/dist/utils/project.js.map +1 -0
  404. package/dist/utils/responses.d.ts +27 -0
  405. package/dist/utils/responses.d.ts.map +1 -0
  406. package/dist/utils/responses.js +72 -0
  407. package/dist/utils/responses.js.map +1 -0
  408. package/dist/utils/vectors.d.ts +33 -0
  409. package/dist/utils/vectors.d.ts.map +1 -0
  410. package/dist/utils/vectors.js +80 -0
  411. package/dist/utils/vectors.js.map +1 -0
  412. package/dist/utils/vectors.test.d.ts +6 -0
  413. package/dist/utils/vectors.test.d.ts.map +1 -0
  414. package/dist/utils/vectors.test.js +96 -0
  415. package/dist/utils/vectors.test.js.map +1 -0
  416. package/package.json +69 -0
  417. package/scripts/init.js +142 -0
  418. package/templates/CLAUDE.md.template +96 -0
  419. package/templates/agents/architecture-concept.md +237 -0
  420. package/templates/agents/checkpoint-concept.md +218 -0
  421. package/templates/agents/code-analysis-concept.md +171 -0
  422. package/templates/agents/compete-control.md +44 -0
  423. package/templates/agents/compete-evaluator.md +87 -0
  424. package/templates/agents/compete-treatment.md +55 -0
  425. package/templates/agents/context-concept.md +254 -0
  426. package/templates/agents/debate-advocate.md +127 -0
  427. package/templates/agents/debate-critic.md +119 -0
  428. package/templates/agents/debate-synthesis.md +160 -0
  429. package/templates/agents/documentation-concept.md +294 -0
  430. package/templates/agents/implementation-concept.md +165 -0
  431. package/templates/agents/quality-concept.md +299 -0
  432. package/templates/agents/research-concept.md +169 -0
  433. package/templates/agents/security-concept.md +255 -0
  434. package/templates/agents/story-concept.md +207 -0
  435. package/templates/agents/verification-concept.md +456 -0
  436. package/templates/agents/version-concept.md +163 -0
  437. package/templates/anchors/directory.anchor.yaml.template +53 -0
  438. package/templates/anchors/rules.anchor.yaml.template +70 -0
  439. package/templates/anchors/safety.anchor.yaml.template +96 -0
  440. package/templates/claude-md-managed.template +105 -0
  441. package/templates/commands/cache.md.template +439 -0
  442. package/templates/commands/checkpoint.md.template +121 -0
  443. package/templates/commands/classify.md.template +138 -0
  444. package/templates/commands/compete.md.template +90 -0
  445. package/templates/commands/costs.md.template +111 -0
  446. package/templates/commands/estimate.md.template +196 -0
  447. package/templates/commands/explore.md.template +186 -0
  448. package/templates/commands/feature.md.template +216 -0
  449. package/templates/commands/forget.md.template +104 -0
  450. package/templates/commands/global-recall.md.template +250 -0
  451. package/templates/commands/global-remember.md.template +187 -0
  452. package/templates/commands/health.md.template +107 -0
  453. package/templates/commands/help.md.template +253 -0
  454. package/templates/commands/observe.md.template +211 -0
  455. package/templates/commands/pr-review.md.template +164 -0
  456. package/templates/commands/predict-cost.md.template +251 -0
  457. package/templates/commands/profile.md.template +142 -0
  458. package/templates/commands/reasoning.md.template +228 -0
  459. package/templates/commands/recall.md.template +197 -0
  460. package/templates/commands/remember.md.template +148 -0
  461. package/templates/commands/replay.md.template +449 -0
  462. package/templates/commands/restore.md.template +87 -0
  463. package/templates/commands/retrospective.md.template +47 -0
  464. package/templates/commands/slo.md.template +286 -0
  465. package/templates/commands/spec.md.template +164 -0
  466. package/templates/commands/status.md.template +53 -0
  467. package/templates/commands/sync.md.template +321 -0
  468. package/templates/commands/task.md.template +86 -0
  469. package/templates/commands/trace.md.template +86 -0
  470. package/templates/commands/visualize.md.template +216 -0
  471. package/templates/commands/workflow.md.template +375 -0
  472. package/templates/concepts/README.md +329 -0
  473. package/templates/concepts/architecture.md.template +74 -0
  474. package/templates/concepts/code-analysis.md.template +186 -0
  475. package/templates/concepts/context-compactor.md.template +393 -0
  476. package/templates/concepts/context.md.template +62 -0
  477. package/templates/concepts/documentation.md.template +452 -0
  478. package/templates/concepts/estimator.md.template +214 -0
  479. package/templates/concepts/exploration.md.template +257 -0
  480. package/templates/concepts/global-memory.md.template +222 -0
  481. package/templates/concepts/implementation.md.template +62 -0
  482. package/templates/concepts/pr-review.md.template +277 -0
  483. package/templates/concepts/project-profile.md.template +358 -0
  484. package/templates/concepts/quality.md.template +63 -0
  485. package/templates/concepts/react-fallback.md.template +286 -0
  486. package/templates/concepts/research.md.template +221 -0
  487. package/templates/concepts/retrospective.md.template +93 -0
  488. package/templates/concepts/security.md.template +442 -0
  489. package/templates/concepts/slo.md.template +274 -0
  490. package/templates/concepts/spec.md.template +71 -0
  491. package/templates/concepts/story.md.template +50 -0
  492. package/templates/concepts/tool-router.md.template +289 -0
  493. package/templates/concepts/verification-synthesizer.md.template +279 -0
  494. package/templates/concepts/version.md.template +61 -0
  495. package/templates/config.yaml.template +347 -0
  496. package/templates/examples/README.md +77 -0
  497. package/templates/examples/architecture/api-design.yaml.template +286 -0
  498. package/templates/examples/architecture/oauth-authentication.yaml.template +305 -0
  499. package/templates/health/status.yaml.template +120 -0
  500. package/templates/hooks/concept-complete.sh.template +45 -0
  501. package/templates/hooks/lib/common.sh.template +160 -0
  502. package/templates/hooks/post-commit.sh.template +37 -0
  503. package/templates/hooks/post-concept-action.template +39 -0
  504. package/templates/hooks/post-tool-structure-check.sh.template +138 -0
  505. package/templates/hooks/post-tool-use.sh.template +51 -0
  506. package/templates/hooks/pre-compact.sh.template +48 -0
  507. package/templates/hooks/pre-tool-grounding.template +148 -0
  508. package/templates/hooks/session-exit-checkpoint.sh.template +35 -0
  509. package/templates/hooks/session-start.sh.template +67 -0
  510. package/templates/hooks/statusline.sh.template +148 -0
  511. package/templates/hooks/stop.sh.template +45 -0
  512. package/templates/hooks/subagent-stop.sh.template +40 -0
  513. package/templates/hooks/sync-blocked.sh.template +45 -0
  514. package/templates/hooks/timeout.sh.template +48 -0
  515. package/templates/hooks/user-prompt-submit.sh.template +68 -0
  516. package/templates/koan/README.md +58 -0
  517. package/templates/memory/index.yaml.template +48 -0
  518. package/templates/memory/procedural/debugging.yaml.template +24 -0
  519. package/templates/memory/procedural/workflows.yaml.template +22 -0
  520. package/templates/memory/semantic/architecture.yaml.template +21 -0
  521. package/templates/memory/semantic/conventions.yaml.template +18 -0
  522. package/templates/memory/semantic/patterns.yaml.template +21 -0
  523. package/templates/memory/semantic/preferences.yaml.template +18 -0
  524. package/templates/prompts/architecture.yaml.template +349 -0
  525. package/templates/prompts/context.yaml.template +384 -0
  526. package/templates/prompts/implementation.yaml.template +365 -0
  527. package/templates/prompts/planning.yaml.template +303 -0
  528. package/templates/prompts/quality.yaml.template +345 -0
  529. package/templates/prompts/retrospective.yaml.template +231 -0
  530. package/templates/prompts/slo.yaml.template +360 -0
  531. package/templates/prompts/story.yaml.template +236 -0
  532. package/templates/prompts/tree-of-thoughts.yaml.template +299 -0
  533. package/templates/prompts/verification.yaml.template +286 -0
  534. package/templates/prompts/version.yaml.template +279 -0
  535. package/templates/schemas/agent-schema.json +98 -0
  536. package/templates/schemas/architecture.schema.json +69 -0
  537. package/templates/schemas/config-schema.json +165 -0
  538. package/templates/schemas/implementation.schema.json +75 -0
  539. package/templates/schemas/planning.schema.json +243 -0
  540. package/templates/schemas/provenance.schema.json +111 -0
  541. package/templates/schemas/retrospective.schema.json +174 -0
  542. package/templates/schemas/review.schema.json +284 -0
  543. package/templates/schemas/slo.schema.json +443 -0
  544. package/templates/schemas/story.schema.json +68 -0
  545. package/templates/schemas/sync-schema.json +196 -0
  546. package/templates/schemas/task.schema.json +127 -0
  547. package/templates/schemas/tree-of-thoughts.schema.json +175 -0
  548. package/templates/schemas/verification.schema.json +106 -0
  549. package/templates/settings.full.json.template +135 -0
  550. package/templates/settings.minimal.json.template +68 -0
  551. package/templates/settings.standard.json.template +135 -0
  552. package/templates/skills/acceptance-criteria-generation.md.template +330 -0
  553. package/templates/skills/accessibility-checking.md.template +341 -0
  554. package/templates/skills/api-design-patterns.md.template +395 -0
  555. package/templates/skills/batch-processing.md.template +605 -0
  556. package/templates/skills/branch-strategy.md.template +362 -0
  557. package/templates/skills/changelog-generation.md.template +403 -0
  558. package/templates/skills/code-coverage-analysis.md.template +362 -0
  559. package/templates/skills/code-style-enforcement.md.template +294 -0
  560. package/templates/skills/code-template-patterns.md.template +419 -0
  561. package/templates/skills/concept-development.md.template +159 -0
  562. package/templates/skills/context-prioritization.md.template +306 -0
  563. package/templates/skills/cost-optimization.md.template +482 -0
  564. package/templates/skills/cross-project-knowledge.md.template +316 -0
  565. package/templates/skills/dependency-impact-analysis.md.template +263 -0
  566. package/templates/skills/documentation-generation.md.template +409 -0
  567. package/templates/skills/effort-estimation.md.template +350 -0
  568. package/templates/skills/error-classification.md.template +709 -0
  569. package/templates/skills/error-messages.md.template +339 -0
  570. package/templates/skills/ide-diagnostics.md.template +480 -0
  571. package/templates/skills/incremental-loading.md.template +574 -0
  572. package/templates/skills/output-caching.md.template +524 -0
  573. package/templates/skills/performance-estimation.md.template +325 -0
  574. package/templates/skills/performance-testing-patterns.md.template +341 -0
  575. package/templates/skills/phase2-optimizations-summary.md.template +458 -0
  576. package/templates/skills/progressive-disclosure-pattern.md.template +190 -0
  577. package/templates/skills/project-structure.md.template +372 -0
  578. package/templates/skills/provenance-analysis.md.template +609 -0
  579. package/templates/skills/react-executor.md.template +366 -0
  580. package/templates/skills/refactoring-patterns.md.template +422 -0
  581. package/templates/skills/release-management.md.template +373 -0
  582. package/templates/skills/requirement-prioritization.md.template +357 -0
  583. package/templates/skills/schema-validation.md.template +321 -0
  584. package/templates/skills/security-design-patterns.md.template +692 -0
  585. package/templates/skills/security-vulnerability-scanning.md.template +663 -0
  586. package/templates/skills/semantic-memory.md.template +266 -0
  587. package/templates/skills/semantic-versioning.md.template +371 -0
  588. package/templates/skills/smart-retry.md.template +676 -0
  589. package/templates/skills/smart-summarization.md.template +358 -0
  590. package/templates/skills/story-decomposition.md.template +278 -0
  591. package/templates/skills/synchronization-patterns.md.template +303 -0
  592. package/templates/skills/test-generation-strategy.md.template +247 -0
  593. package/templates/skills/workflow-replay.md.template +478 -0
  594. package/templates/skills/wysiwid-principles.md.template +364 -0
  595. package/templates/skills-manifest.yaml.template +526 -0
  596. package/templates/stubs/agents/architecture-concept.md +20 -0
  597. package/templates/stubs/agents/checkpoint-concept.md +19 -0
  598. package/templates/stubs/agents/code-analysis-concept.md +36 -0
  599. package/templates/stubs/agents/context-concept.md +37 -0
  600. package/templates/stubs/agents/debate-advocate.md +12 -0
  601. package/templates/stubs/agents/debate-critic.md +12 -0
  602. package/templates/stubs/agents/debate-synthesis.md +12 -0
  603. package/templates/stubs/agents/documentation-concept.md +39 -0
  604. package/templates/stubs/agents/implementation-concept.md +41 -0
  605. package/templates/stubs/agents/quality-concept.md +41 -0
  606. package/templates/stubs/agents/research-concept.md +35 -0
  607. package/templates/stubs/agents/security-concept.md +40 -0
  608. package/templates/stubs/agents/spec-concept.md +35 -0
  609. package/templates/stubs/agents/story-concept.md +36 -0
  610. package/templates/stubs/agents/verification-concept.md +39 -0
  611. package/templates/stubs/agents/version-concept.md +37 -0
  612. package/templates/stubs/commands/cache.md.template +2 -0
  613. package/templates/stubs/commands/checkpoint.md.template +2 -0
  614. package/templates/stubs/commands/classify.md.template +2 -0
  615. package/templates/stubs/commands/compete.md.template +2 -0
  616. package/templates/stubs/commands/costs.md.template +2 -0
  617. package/templates/stubs/commands/estimate.md.template +2 -0
  618. package/templates/stubs/commands/explore.md.template +2 -0
  619. package/templates/stubs/commands/feature.md.template +2 -0
  620. package/templates/stubs/commands/forget.md.template +2 -0
  621. package/templates/stubs/commands/global-recall.md.template +2 -0
  622. package/templates/stubs/commands/global-remember.md.template +2 -0
  623. package/templates/stubs/commands/health.md.template +2 -0
  624. package/templates/stubs/commands/help.md.template +2 -0
  625. package/templates/stubs/commands/observe.md.template +2 -0
  626. package/templates/stubs/commands/pr-review.md.template +2 -0
  627. package/templates/stubs/commands/predict-cost.md.template +2 -0
  628. package/templates/stubs/commands/profile.md.template +2 -0
  629. package/templates/stubs/commands/reasoning.md.template +2 -0
  630. package/templates/stubs/commands/recall.md.template +2 -0
  631. package/templates/stubs/commands/remember.md.template +2 -0
  632. package/templates/stubs/commands/replay.md.template +2 -0
  633. package/templates/stubs/commands/restore.md.template +2 -0
  634. package/templates/stubs/commands/retrospective.md.template +2 -0
  635. package/templates/stubs/commands/slo.md.template +2 -0
  636. package/templates/stubs/commands/spec.md.template +2 -0
  637. package/templates/stubs/commands/sync.md.template +2 -0
  638. package/templates/stubs/commands/task.md.template +2 -0
  639. package/templates/stubs/commands/trace.md.template +2 -0
  640. package/templates/stubs/commands/visualize.md.template +2 -0
  641. package/templates/stubs/commands/workflow.md.template +2 -0
  642. package/templates/synchronizations/archive/adaptive-learning.yaml.template +595 -0
  643. package/templates/synchronizations/archive/code-understanding-flow.yaml.template +533 -0
  644. package/templates/synchronizations/archive/collaboration-flow.yaml.template +521 -0
  645. package/templates/synchronizations/archive/context-folding.yaml.template +353 -0
  646. package/templates/synchronizations/archive/dead-letter-queue.yaml.template +530 -0
  647. package/templates/synchronizations/archive/documentation-flow.yaml.template +560 -0
  648. package/templates/synchronizations/archive/error-recovery-flow.yaml.template +1031 -0
  649. package/templates/synchronizations/archive/execution-loop.yaml.template +336 -0
  650. package/templates/synchronizations/archive/exploration-flow.yaml.template +369 -0
  651. package/templates/synchronizations/archive/feature-development.yaml.template +2145 -0
  652. package/templates/synchronizations/archive/learning-loop.yaml.template +657 -0
  653. package/templates/synchronizations/archive/multi-verify.yaml.template +346 -0
  654. package/templates/synchronizations/archive/planning-flow.yaml.template +312 -0
  655. package/templates/synchronizations/archive/retrospective-flow.yaml.template +277 -0
  656. package/templates/synchronizations/archive/security-flow.yaml.template +477 -0
  657. package/templates/synchronizations/archive/slo-monitoring.yaml.template +209 -0
  658. package/templates/synchronizations/archive/task-routing.yaml.template +489 -0
  659. package/templates/synchronizations/archive/test-driven.yaml.template +291 -0
  660. package/templates/synchronizations/archive/tool-routing.yaml.template +326 -0
  661. package/templates/synchronizations/archive/verification-flow.yaml.template +407 -0
  662. package/templates/synchronizations/error-policy.yaml.template +188 -0
  663. package/templates/synchronizations/main.sync.template +319 -0
  664. package/templates/synchronizations/slo-registry.yaml.template +229 -0
  665. package/templates/tasks/task.yaml.template +67 -0
  666. package/templates/zen-profile.yaml.template +14 -0
@@ -0,0 +1,2145 @@
1
+ # Feature Development Workflow Synchronizations
2
+ # This file defines the complete workflow from story to deployment
3
+ #
4
+ # WYSIWID Principle: This YAML IS the workflow logic
5
+ # Read this file to understand exactly what happens and when
6
+
7
+ version: "1.0.0"
8
+
9
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
10
+ # SLO Templates (YAML Anchors for reuse)
11
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
12
+ # Use *SLO_NAME to reference these templates in rules
13
+
14
+ slo_templates:
15
+ # Architecture design with Opus (deep reasoning)
16
+ architecture: &SLO_ARCHITECTURE
17
+ expected_duration_ms: 15000
18
+ max_duration_ms: 90000
19
+ expected_cost_usd: 0.015
20
+ max_cost_usd: 0.050
21
+ expected_context_tokens: 1500
22
+ success_rate_target: 0.95
23
+ on_timeout:
24
+ action: "retry"
25
+ max_retries: 1
26
+ backoff_ms: 2000
27
+ on_exhausted: "escalate"
28
+ on_cost_exceeded:
29
+ action: "alert"
30
+ continue: true
31
+
32
+ # Verification passes (Sonnet reasoning)
33
+ verification: &SLO_VERIFICATION
34
+ expected_duration_ms: 12000
35
+ max_duration_ms: 60000
36
+ expected_cost_usd: 0.003
37
+ max_cost_usd: 0.015
38
+ expected_context_tokens: 2500
39
+ success_rate_target: 0.95
40
+ on_timeout:
41
+ action: "skip"
42
+ fallback: "Proceed without verification"
43
+
44
+ # Implementation generation (Sonnet)
45
+ implementation: &SLO_IMPLEMENTATION
46
+ expected_duration_ms: 3000
47
+ max_duration_ms: 30000
48
+ expected_cost_usd: 0.000175
49
+ max_cost_usd: 0.001
50
+ expected_context_tokens: 1000
51
+ success_rate_target: 0.90
52
+ on_timeout:
53
+ action: "retry"
54
+ max_retries: 1
55
+ backoff_ms: 1000
56
+ on_exhausted: "escalate"
57
+
58
+ # Quality review/test (Sonnet)
59
+ quality: &SLO_QUALITY
60
+ expected_duration_ms: 2500
61
+ max_duration_ms: 20000
62
+ expected_cost_usd: 0.000175
63
+ max_cost_usd: 0.001
64
+ expected_context_tokens: 800
65
+ success_rate_target: 0.95
66
+ on_timeout:
67
+ action: "retry"
68
+ max_retries: 1
69
+ backoff_ms: 1000
70
+ on_exhausted: "escalate"
71
+
72
+ # Quick operations (commit, context inject, etc.)
73
+ quick: &SLO_QUICK
74
+ expected_duration_ms: 1000
75
+ max_duration_ms: 10000
76
+ expected_cost_usd: 0.000175
77
+ max_cost_usd: 0.0005
78
+ expected_context_tokens: 300
79
+ success_rate_target: 0.99
80
+ on_timeout:
81
+ action: "retry"
82
+ max_retries: 2
83
+ backoff_ms: 500
84
+ on_exhausted: "escalate"
85
+
86
+ # Context operations (compression, snapshot)
87
+ context: &SLO_CONTEXT
88
+ expected_duration_ms: 1500
89
+ max_duration_ms: 10000
90
+ expected_cost_usd: 0.000175
91
+ max_cost_usd: 0.0005
92
+ expected_context_tokens: 500
93
+ success_rate_target: 0.99
94
+ on_timeout:
95
+ action: "escalate"
96
+
97
+ # MCP-based code analysis
98
+ mcp_analysis: &SLO_MCP_ANALYSIS
99
+ expected_duration_ms: 2000
100
+ max_duration_ms: 10000
101
+ expected_cost_usd: 0.0002
102
+ max_cost_usd: 0.001
103
+ expected_context_tokens: 500
104
+ success_rate_target: 0.90
105
+ on_timeout:
106
+ action: "skip"
107
+ fallback: "Proceed without code analysis"
108
+
109
+ # Zero-cost operations (inject context, set flag)
110
+ zero_cost: &SLO_ZERO_COST
111
+ expected_duration_ms: 100
112
+ max_duration_ms: 500
113
+ expected_cost_usd: 0.0
114
+ max_cost_usd: 0.0
115
+ expected_context_tokens: 200
116
+ on_timeout:
117
+ action: "skip"
118
+ fallback: "Proceed without context"
119
+
120
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
121
+ # MCP Server SLO Templates
122
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
123
+
124
+ # Test Generator MCP operations
125
+ test_generation: &SLO_TEST_GENERATION
126
+ expected_duration_ms: 5000
127
+ max_duration_ms: 30000
128
+ expected_cost_usd: 0.0005
129
+ max_cost_usd: 0.002
130
+ expected_context_tokens: 800
131
+ success_rate_target: 0.90
132
+ on_timeout:
133
+ action: "skip"
134
+ fallback: "Proceed without auto-generated tests"
135
+ set_flag: "test_generation.skipped = true"
136
+ on_mcp_unavailable:
137
+ action: "skip"
138
+ fallback: "MCP server unavailable - manual test creation needed"
139
+
140
+ # Execution Loop MCP operations (self-repair)
141
+ execution_loop: &SLO_EXECUTION_LOOP
142
+ expected_duration_ms: 15000
143
+ max_duration_ms: 120000 # 2 minutes for iterative repair
144
+ expected_cost_usd: 0.001
145
+ max_cost_usd: 0.005
146
+ expected_context_tokens: 1500
147
+ success_rate_target: 0.85
148
+ on_timeout:
149
+ action: "escalate"
150
+ message: "Self-repair loop exceeded timeout - manual intervention needed"
151
+ on_mcp_unavailable:
152
+ action: "fallback"
153
+ fallback_rule: "quality-tests-failed" # Use legacy manual fix path
154
+
155
+ # Coverage Analysis MCP operations
156
+ coverage_analysis: &SLO_COVERAGE_ANALYSIS
157
+ expected_duration_ms: 3000
158
+ max_duration_ms: 20000
159
+ expected_cost_usd: 0.0002
160
+ max_cost_usd: 0.001
161
+ expected_context_tokens: 500
162
+ success_rate_target: 0.95
163
+ on_timeout:
164
+ action: "skip"
165
+ fallback: "Proceed without coverage analysis"
166
+
167
+ # Global SLO defaults (fallback when no template specified)
168
+ slo_defaults:
169
+ expected_duration_ms: 5000
170
+ max_duration_ms: 60000
171
+ expected_cost_usd: 0.002
172
+ max_cost_usd: 0.02
173
+ expected_context_tokens: 1500
174
+ success_rate_target: 0.95
175
+ on_timeout:
176
+ action: "retry"
177
+ max_retries: 1
178
+ backoff_ms: 2000
179
+ on_exhausted: "escalate"
180
+ on_cost_exceeded:
181
+ action: "alert"
182
+ continue: true
183
+
184
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
185
+ # Global Defaults - Applied to all rules unless overridden
186
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
187
+ defaults:
188
+ timeout_seconds: 120 # 2 minutes default timeout
189
+ max_retries: 2 # Retry twice before failing
190
+ retry_backoff_ms: 2000 # 2 second backoff between retries
191
+ on_timeout: "escalate" # escalate | skip | retry | fail
192
+ on_error: "retry" # retry | skip | fail | escalate
193
+
194
+ synchronizations:
195
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
196
+ # Phase 0: Story Clarification (Optional - Human-in-the-Loop)
197
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
198
+
199
+ - id: "story-ambiguous-clarify"
200
+ description: "Ask user for clarification when story is ambiguous"
201
+ when:
202
+ concept: "story"
203
+ action: "create"
204
+ status: "completed"
205
+ where:
206
+ query: "story.clarity == 'ambiguous' OR story.confidence < 0.7"
207
+ then:
208
+ - action: "ask_user"
209
+ questions:
210
+ - question: "Story '${story.description}' is ambiguous. What's the primary goal?"
211
+ header: "Clarification"
212
+ multiSelect: false
213
+ options:
214
+ - label: "New feature"
215
+ description: "Add new functionality to the system"
216
+ - label: "Bug fix"
217
+ description: "Fix existing broken behavior"
218
+ - label: "Performance optimization"
219
+ description: "Improve speed, memory, or efficiency"
220
+ - label: "Refactoring"
221
+ description: "Improve code structure without changing behavior"
222
+ - label: "Technical debt"
223
+ description: "Address architectural or code quality issues"
224
+
225
+ - question: "What's the urgency/priority?"
226
+ header: "Priority"
227
+ multiSelect: false
228
+ options:
229
+ - label: "Critical (today)"
230
+ description: "Blocking work or production issue"
231
+ - label: "High (this week)"
232
+ description: "Important but not blocking"
233
+ - label: "Medium (this sprint)"
234
+ description: "Should be done but flexible timing"
235
+ - label: "Low (backlog)"
236
+ description: "Nice to have, no rush"
237
+
238
+ on_answer:
239
+ # Update story with clarifications
240
+ - concept: "story"
241
+ action: "update"
242
+ model: "sonnet"
243
+ inputs:
244
+ story_id: "${story.id}"
245
+ goal_type: "${answer.primary_goal}"
246
+ priority: "${answer.urgency}"
247
+ clarity: "clarified"
248
+
249
+ provenance:
250
+ flow_id: "${flow.id}"
251
+ reason: "Ambiguous story requires user clarification"
252
+ decision_point: true
253
+ user_interaction: "ask_user_question"
254
+ category: "core"
255
+
256
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
257
+ # Phase 1A: Story → Code Analysis + Security (PARALLEL)
258
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
259
+ #
260
+ # PARALLEL EXECUTION: Both run simultaneously after story
261
+ # - Code Analysis: Gather codebase context via MCP
262
+ # - Security Threat Modeling: STRIDE analysis
263
+ #
264
+ # Benefits: ~30% faster than sequential, no cost increase
265
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
266
+
267
+ - id: "story-to-code-analysis"
268
+ description: "When story is ready, gather codebase context before architecture"
269
+ when:
270
+ concept: "story"
271
+ action: "create"
272
+ status: "completed"
273
+ where:
274
+ query: "story.status == 'ready' AND story.acceptance_criteria.length > 0"
275
+ then:
276
+ - concept: "code-analysis"
277
+ action: "context"
278
+ model: "sonnet"
279
+ mcp_tools:
280
+ # Find existing patterns related to this feature
281
+ - tool: "ast-index.find_symbol"
282
+ input: "${story.technical_keywords}"
283
+ output_to: "existing_patterns"
284
+
285
+ # Find semantically similar implementations
286
+ - tool: "semantic-rag.semantic_search"
287
+ input: "${story.description}"
288
+ limit: 5
289
+ output_to: "similar_implementations"
290
+
291
+ # Get file symbols for key files
292
+ - tool: "ast-index.get_file_symbols"
293
+ input: "${similar_implementations[0].file}"
294
+ output_to: "reference_structure"
295
+
296
+ inputs:
297
+ story_id: "${story.id}"
298
+ description: "${story.description}"
299
+ keywords: "${story.technical_keywords}"
300
+
301
+ outputs:
302
+ target: "koan/context/analysis-${story.id}.yaml"
303
+
304
+ # MCP-specific error handling for code analysis
305
+ error_handling:
306
+ mcp_connection_failed:
307
+ type: "transient"
308
+ action: "retry"
309
+ max_retries: 2
310
+ backoff_ms: 1000
311
+ on_exhausted:
312
+ action: "skip"
313
+ set_flag: "code_analysis.skipped = true"
314
+ reason: "MCP servers unavailable - proceeding without code analysis"
315
+
316
+ mcp_tool_not_found:
317
+ type: "permanent"
318
+ action: "skip"
319
+ set_flag: "code_analysis.skipped = true"
320
+ fallback: "story-to-arch" # Use legacy path without MCP
321
+ reason: "Required MCP tool not installed"
322
+
323
+ mcp_rate_limited:
324
+ type: "transient"
325
+ action: "retry"
326
+ backoff_ms: 5000 # Longer backoff for rate limits
327
+ max_retries: 3
328
+ on_exhausted:
329
+ action: "skip"
330
+ set_flag: "code_analysis.skipped = true"
331
+
332
+ mcp_response_error:
333
+ type: "transient"
334
+ action: "retry"
335
+ max_retries: 1
336
+ on_exhausted:
337
+ action: "skip"
338
+ set_flag: "code_analysis.skipped = true"
339
+
340
+ slo_expectations:
341
+ expected_duration_ms: 2000 # 2 seconds (fast MCP calls)
342
+ max_duration_ms: 10000 # 10 seconds timeout
343
+ expected_cost_usd: 0.0002 # Sonnet + MCP overhead
344
+ max_cost_usd: 0.001 # Alert if exceeds
345
+ expected_context_tokens: 500 # Minimal context
346
+ max_context_tokens: 2000 # Warning threshold
347
+ success_rate_target: 0.90 # 90% analysis succeeds
348
+
349
+ on_timeout:
350
+ action: "skip" # Don't block - architecture can proceed without
351
+ fallback: "architecture.design without context"
352
+ set_flag: "code_analysis.skipped = true"
353
+
354
+ provenance:
355
+ flow_id: "${flow.id}"
356
+ reason: "Gathering codebase context to inform architecture decisions"
357
+ category: "intelligence"
358
+
359
+ # Parallel: Security threat modeling (runs alongside code-analysis)
360
+ - id: "story-to-security-threat"
361
+ description: "PARALLEL with code-analysis: Perform security threat modeling"
362
+ when:
363
+ concept: "story"
364
+ action: "create"
365
+ status: "completed"
366
+ where:
367
+ query: "story.status == 'ready' AND story.acceptance_criteria.length > 0"
368
+ then:
369
+ - concept: "security"
370
+ action: "threat_model"
371
+ model: "sonnet"
372
+ parallel: true # ← ENABLES PARALLEL EXECUTION with code-analysis
373
+ inputs:
374
+ story_id: "${story.id}"
375
+ description: "${story.description}"
376
+ acceptance_criteria: "${story.acceptance_criteria}"
377
+ analysis_type: "STRIDE"
378
+
379
+ slo_expectations:
380
+ expected_duration_ms: 3000 # 3 seconds
381
+ max_duration_ms: 15000 # 15 second timeout
382
+ expected_cost_usd: 0.002
383
+ max_cost_usd: 0.005
384
+ success_rate_target: 0.95
385
+
386
+ provenance:
387
+ flow_id: "${flow.id}"
388
+ reason: "Security threat modeling (parallel with code analysis)"
389
+ parallel_with: "story-to-code-analysis"
390
+ category: "intelligence"
391
+
392
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
393
+ # Phase 1B: Global Learnings → Architecture Context
394
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
395
+ #
396
+ # AUTOMATIC: Inject relevant global learnings into architecture inputs
397
+ # This ensures cross-project patterns inform design decisions
398
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
399
+
400
+ - id: "global-learnings-to-arch-context"
401
+ description: "Automatically inject global learnings into architecture design"
402
+ when:
403
+ concept: "architecture"
404
+ action: "design"
405
+ status: "starting"
406
+ where:
407
+ query: "context.global_learnings != null AND context.global_learnings.length > 0"
408
+ then:
409
+ - action: "inject_context"
410
+ target: "architecture.design"
411
+ context_type: "global_patterns"
412
+ content:
413
+ patterns: "${context.global_learnings.filter(l => l.category == 'patterns')}"
414
+ failure_lessons: "${context.global_learnings.filter(l => l.category == 'learnings')}"
415
+ relevance_scores: "${context.global_learnings.map(l => l.relevance_score)}"
416
+
417
+ slo_expectations:
418
+ expected_duration_ms: 100
419
+ max_duration_ms: 500
420
+ expected_cost_usd: 0.0
421
+ max_cost_usd: 0.0
422
+ expected_context_tokens: 200
423
+ on_timeout:
424
+ action: "skip"
425
+ fallback: "Proceed without global learnings"
426
+
427
+ provenance:
428
+ flow_id: "${flow.id}"
429
+ reason: "Injecting relevant global learnings to inform architecture decisions"
430
+ category: "intelligence"
431
+
432
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
433
+ # MEMORY INTEGRATION: Auto-Remember Architecture Decisions
434
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
435
+ #
436
+ # AUTOMATIC: Store architecture decisions in semantic memory
437
+ # These decisions become available for future feature workflows
438
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
439
+
440
+ - id: "arch-decisions-to-memory"
441
+ description: "Auto-remember architecture decisions after design completes"
442
+ when:
443
+ concept: "architecture"
444
+ action: "design"
445
+ status: "completed"
446
+ where:
447
+ query: "architecture.decisions != null AND architecture.decisions.length > 0"
448
+ then:
449
+ - action: "store_memory"
450
+ target: "koan/memory/semantic/architecture.yaml"
451
+ content:
452
+ id: "mem-arch-${architecture.id}-${timestamp}"
453
+ type: "auto_captured"
454
+ category: "architecture"
455
+ content: "${architecture.approach}: ${architecture.decisions.map(d => d.description).join('; ')}"
456
+ confidence: 0.7
457
+ source: "Auto-captured from architecture ${architecture.id}"
458
+ tags: "${architecture.technologies || []}"
459
+ story_id: "${story.id}"
460
+ created_at: "${timestamp}"
461
+ related_files: "${architecture.affected_files || []}"
462
+
463
+ slo_expectations:
464
+ expected_duration_ms: 50
465
+ max_duration_ms: 200
466
+ expected_cost_usd: 0.0
467
+ max_cost_usd: 0.0
468
+ on_timeout:
469
+ action: "skip"
470
+ fallback: "Memory storage skipped - decisions not persisted"
471
+ on_failure:
472
+ action: "log"
473
+ continue: true
474
+
475
+ provenance:
476
+ flow_id: "${flow.id}"
477
+ reason: "Auto-remembering architecture decisions for future workflows"
478
+ category: "memory"
479
+
480
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
481
+ # Phase 1C: Code Analysis + Security → Architecture
482
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
483
+ #
484
+ # WAIT for BOTH parallel steps before architecture
485
+
486
+ - id: "code-analysis-to-arch"
487
+ description: "When code analysis complete, design architecture with context"
488
+ when:
489
+ concept: "code-analysis"
490
+ action: "context"
491
+ status: "completed"
492
+ then:
493
+ - concept: "architecture"
494
+ action: "design"
495
+ model: "opus" # Deepest reasoning for complex trade-offs
496
+ inputs:
497
+ story_id: "${story.id}"
498
+ requirements: "${story.description}"
499
+ acceptance_criteria: "${story.acceptance_criteria}"
500
+ # Code analysis context
501
+ existing_patterns: "${code_analysis.existing_patterns}"
502
+ similar_implementations: "${code_analysis.similar_implementations}"
503
+ reference_structure: "${code_analysis.reference_structure}"
504
+ # Security context from parallel threat modeling
505
+ security_threats: "${security.threat_model.threats}"
506
+ security_requirements: "${security.threat_model.requirements}"
507
+
508
+ slo_expectations:
509
+ expected_duration_ms: 15000 # 15 seconds typical with Opus
510
+ max_duration_ms: 90000 # 90 seconds timeout for deep reasoning
511
+ expected_cost_usd: 0.015 # Opus with Phase 2 optimizations
512
+ max_cost_usd: 0.050 # Alert if exceeds
513
+ expected_context_tokens: 1500 # Slightly higher with code context
514
+ max_context_tokens: 10000 # Warning threshold
515
+ success_rate_target: 0.95 # 95% of architecture designs succeed
516
+
517
+ on_timeout:
518
+ action: "retry"
519
+ max_retries: 1
520
+ backoff_ms: 2000
521
+ on_exhausted: "escalate"
522
+
523
+ on_cost_exceeded:
524
+ action: "alert"
525
+ continue: true # Don't block workflow
526
+
527
+ on_context_exceeded:
528
+ action: "alert"
529
+ investigate: true # Create investigation task
530
+
531
+ provenance:
532
+ flow_id: "${flow.id}"
533
+ reason: "Code analysis complete, designing architecture with codebase context"
534
+ category: "core"
535
+
536
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
537
+ # Phase 1 (Legacy): Story → Architecture (Fallback)
538
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
539
+ # Used when code-analysis is skipped or fails
540
+
541
+ - id: "story-to-arch"
542
+ description: "Fallback: design architecture without code analysis"
543
+ when:
544
+ concept: "story"
545
+ action: "create"
546
+ status: "completed"
547
+ where:
548
+ # Only triggers if code-analysis was skipped (no MCP servers available)
549
+ query: "story.status == 'ready' AND story.acceptance_criteria.length > 0 AND code_analysis.skipped == true"
550
+ then:
551
+ - concept: "architecture"
552
+ action: "design"
553
+ model: "opus" # Deepest reasoning for complex trade-offs
554
+ inputs:
555
+ story_id: "${story.id}"
556
+ requirements: "${story.description}"
557
+ acceptance_criteria: "${story.acceptance_criteria}"
558
+
559
+ # SLO Expectations for architecture.design
560
+ slo_expectations:
561
+ expected_duration_ms: 15000 # 15 seconds typical with Opus
562
+ max_duration_ms: 90000 # 90 seconds timeout for deep reasoning
563
+ expected_cost_usd: 0.015 # Opus with Phase 2 optimizations
564
+ max_cost_usd: 0.050 # Alert if exceeds
565
+ expected_context_tokens: 1100 # With incremental loading
566
+ max_context_tokens: 10000 # Warning threshold
567
+ success_rate_target: 0.95 # 95% of architecture designs succeed
568
+
569
+ on_timeout:
570
+ action: "retry"
571
+ max_retries: 1
572
+ backoff_ms: 2000
573
+ on_exhausted: "escalate"
574
+
575
+ on_cost_exceeded:
576
+ action: "alert"
577
+ continue: true # Don't block workflow
578
+
579
+ on_context_exceeded:
580
+ action: "alert"
581
+ investigate: true # Create investigation task
582
+
583
+ provenance:
584
+ flow_id: "${flow.id}"
585
+ reason: "Story validated and ready for technical design"
586
+ category: "core"
587
+
588
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
589
+ # Phase 2A: Architecture → Verification (Always Run)
590
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
591
+ #
592
+ # Multi-pass verification runs on EVERY feature for quality assurance.
593
+ # Research shows 39.7% accuracy improvement with this approach.
594
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
595
+
596
+ - id: "arch-to-verify"
597
+ description: "Run multi-pass verification on architecture before implementation"
598
+ when:
599
+ concept: "architecture"
600
+ action: "design"
601
+ status: "completed"
602
+ where:
603
+ query: "architecture.decisions.length > 0"
604
+ then:
605
+ - concept: "verification"
606
+ action: "verify_architecture"
607
+ model: "sonnet"
608
+ inputs:
609
+ story: "${story}"
610
+ architecture: "${architecture}"
611
+ verification_pass: 1
612
+ total_passes: 2
613
+
614
+ slo_expectations:
615
+ expected_duration_ms: 12000
616
+ max_duration_ms: 60000
617
+ expected_cost_usd: 0.003
618
+ max_cost_usd: 0.015
619
+ expected_context_tokens: 2500
620
+ success_rate_target: 0.95
621
+ on_timeout:
622
+ action: "skip"
623
+ fallback: "Proceed to implementation without verification"
624
+
625
+ provenance:
626
+ flow_id: "${flow.id}"
627
+ reason: "Multi-pass verification of architecture design"
628
+ category: "validation"
629
+
630
+ # Second verification pass
631
+ - id: "arch-verify-pass-2"
632
+ description: "Second verification pass with previous findings"
633
+ when:
634
+ concept: "verification"
635
+ action: "verify_architecture"
636
+ status: "completed"
637
+ where:
638
+ query: "verification.pass == 1 AND verification.target.concept == 'architecture'"
639
+ then:
640
+ - concept: "verification"
641
+ action: "verify_architecture"
642
+ model: "sonnet"
643
+ inputs:
644
+ story: "${story}"
645
+ architecture: "${architecture}"
646
+ verification_pass: 2
647
+ total_passes: 2
648
+ previous_reviews:
649
+ - reviewer: "${verification.reviewer}"
650
+ summary: "${verification.summary}"
651
+
652
+ slo_expectations:
653
+ expected_duration_ms: 12000
654
+ max_duration_ms: 60000
655
+ expected_cost_usd: 0.003
656
+ max_cost_usd: 0.015
657
+ expected_context_tokens: 2800
658
+ success_rate_target: 0.95
659
+
660
+ provenance:
661
+ flow_id: "${flow.id}"
662
+ reason: "Second verification pass with prior findings"
663
+ category: "validation"
664
+
665
+ # Verification consensus
666
+ - id: "arch-verify-consensus"
667
+ description: "Aggregate verification passes and decide"
668
+ when:
669
+ concept: "verification"
670
+ action: "verify_architecture"
671
+ status: "completed"
672
+ where:
673
+ query: "verification.pass == 2 AND verification.target.concept == 'architecture'"
674
+ then:
675
+ - concept: "verification"
676
+ action: "consensus"
677
+ model: "sonnet"
678
+ inputs:
679
+ verifications: "${all_verification_passes}"
680
+
681
+ slo_expectations:
682
+ expected_duration_ms: 3000
683
+ max_duration_ms: 20000
684
+ expected_cost_usd: 0.000175
685
+ max_cost_usd: 0.001
686
+ expected_context_tokens: 1200
687
+ success_rate_target: 0.99
688
+
689
+ provenance:
690
+ flow_id: "${flow.id}"
691
+ reason: "Aggregate verification findings"
692
+ category: "validation"
693
+
694
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
695
+ # Phase 2B: Verification → Implementation
696
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
697
+
698
+ - id: "verify-approved-to-impl"
699
+ description: "When verification approves, proceed to implementation"
700
+ when:
701
+ concept: "verification"
702
+ action: "consensus"
703
+ status: "completed"
704
+ where:
705
+ query: "verification.recommendation == 'approve' OR verification.recommendation == 'approve_with_notes'"
706
+ then:
707
+ - concept: "implementation"
708
+ action: "generate"
709
+ model: "sonnet"
710
+ inputs:
711
+ architecture_id: "${architecture.id}"
712
+ story_id: "${story.id}"
713
+ technical_spec: "${architecture.technical_spec}"
714
+ patterns: "${architecture.patterns}"
715
+ verification_notes: "${verification.aggregated_issues}"
716
+
717
+ slo_expectations:
718
+ expected_duration_ms: 3000
719
+ max_duration_ms: 30000
720
+ expected_cost_usd: 0.000175
721
+ max_cost_usd: 0.001
722
+ expected_context_tokens: 1000
723
+ success_rate_target: 0.90
724
+ on_timeout:
725
+ action: "retry"
726
+ max_retries: 1
727
+ backoff_ms: 1000
728
+ on_exhausted: "escalate"
729
+
730
+ provenance:
731
+ flow_id: "${flow.id}"
732
+ reason: "Verification approved, proceeding to implementation"
733
+ category: "core"
734
+
735
+ - id: "verify-blocked-to-revise"
736
+ description: "When verification blocks, revise architecture"
737
+ when:
738
+ concept: "verification"
739
+ action: "consensus"
740
+ status: "completed"
741
+ where:
742
+ query: "verification.recommendation == 'block' OR verification.recommendation == 'revise'"
743
+ then:
744
+ - concept: "architecture"
745
+ action: "revise"
746
+ model: "opus" # Deep reasoning for revision
747
+ inputs:
748
+ original_architecture: "${architecture}"
749
+ verification_issues: "${verification.aggregated_issues}"
750
+ recommendation: "${verification.rationale}"
751
+
752
+ slo_expectations:
753
+ expected_duration_ms: 20000
754
+ max_duration_ms: 90000
755
+ expected_cost_usd: 0.015
756
+ max_cost_usd: 0.050
757
+ expected_context_tokens: 3500
758
+ success_rate_target: 0.90
759
+
760
+ provenance:
761
+ flow_id: "${flow.id}"
762
+ reason: "Verification blocked - revising architecture"
763
+ category: "recovery"
764
+
765
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
766
+ # Phase 2 (Legacy): Architecture → Implementation (Fallback)
767
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
768
+ # Only used when verification is skipped or times out
769
+
770
+ - id: "arch-to-impl"
771
+ description: "Fallback: implement without verification (when verification skipped)"
772
+ when:
773
+ concept: "architecture"
774
+ action: "design"
775
+ status: "completed"
776
+ where:
777
+ # Only triggers if verification was skipped
778
+ query: "architecture.decisions.length > 0 AND verification.skipped == true"
779
+ then:
780
+ - concept: "implementation"
781
+ action: "generate"
782
+ model: "sonnet"
783
+ inputs:
784
+ architecture_id: "${architecture.id}"
785
+ story_id: "${story.id}"
786
+ technical_spec: "${architecture.technical_spec}"
787
+ patterns: "${architecture.patterns}"
788
+
789
+ # SLO Expectations for implementation.generate
790
+ slo_expectations:
791
+ expected_duration_ms: 3000 # 3 seconds typical
792
+ max_duration_ms: 30000 # 30 seconds timeout
793
+ expected_cost_usd: 0.000175 # Sonnet with pattern-based generation
794
+ max_cost_usd: 0.001 # Alert if exceeds
795
+ expected_context_tokens: 1000 # Moderate context usage
796
+ max_context_tokens: 5000 # Warning threshold
797
+ success_rate_target: 0.90 # 90% implementation success
798
+
799
+ on_timeout:
800
+ action: "retry"
801
+ max_retries: 1
802
+ backoff_ms: 1000
803
+ on_exhausted: "escalate"
804
+
805
+ on_cost_exceeded:
806
+ action: "alert"
807
+ continue: true
808
+
809
+ on_context_exceeded:
810
+ action: "alert"
811
+ investigate: true
812
+
813
+ provenance:
814
+ flow_id: "${flow.id}"
815
+ reason: "Architecture approved, risk acceptable, specs clear"
816
+ category: "core"
817
+
818
+ - id: "arch-high-risk-approval"
819
+ description: "When architecture has high risk, ask user how to proceed"
820
+ when:
821
+ concept: "architecture"
822
+ action: "design"
823
+ status: "completed"
824
+ where:
825
+ query: "architecture.estimated_risk == 'high'"
826
+ then:
827
+ # NEW: Ask user for decision (human-in-the-loop)
828
+ - action: "ask_user"
829
+ questions:
830
+ - question: "Architecture has HIGH RISK. Review koan/architecture/${architecture.id}.yaml - How should we proceed?"
831
+ header: "Risk Decision"
832
+ multiSelect: false
833
+ options:
834
+ - label: "Approve and implement"
835
+ description: "I reviewed the architecture. Risk is acceptable - proceed with implementation."
836
+ - label: "Revise for lower risk"
837
+ description: "Find an alternative approach with medium or low risk."
838
+ - label: "Cancel this feature"
839
+ description: "Don't implement. Risk is too high for this project."
840
+
841
+ # Handle user's decision
842
+ on_answer:
843
+ "Approve and implement":
844
+ - concept: "implementation"
845
+ action: "generate"
846
+ model: "sonnet"
847
+ inputs:
848
+ architecture_id: "${architecture.id}"
849
+ story_id: "${story.id}"
850
+ user_approval: "approved_high_risk"
851
+
852
+ "Revise for lower risk":
853
+ - concept: "architecture"
854
+ action: "revise"
855
+ model: "sonnet"
856
+ inputs:
857
+ original_architecture_id: "${architecture.id}"
858
+ story_id: "${story.id}"
859
+ constraint: "Design alternative approach with medium or low risk. Avoid: ${architecture.risks}"
860
+
861
+ "Cancel this feature":
862
+ - concept: "story"
863
+ action: "cancel"
864
+ model: "sonnet"
865
+ inputs:
866
+ story_id: "${story.id}"
867
+ reason: "User cancelled due to high-risk architecture"
868
+
869
+ provenance:
870
+ flow_id: "${flow.id}"
871
+ reason: "High risk requires human approval before proceeding"
872
+ decision_point: true
873
+ user_interaction: "ask_user_question"
874
+ category: "core"
875
+
876
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
877
+ # Phase 2.7: Implementation → Auto Test Generation (MCP)
878
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
879
+ #
880
+ # AUTOMATIC: Use test-generator MCP to create tests for new code
881
+ # - Generates unit tests for all new/modified functions
882
+ # - Suggests integration tests for API changes
883
+ # - Runs BEFORE manual quality checks
884
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
885
+
886
+ - id: "impl-to-test-generation"
887
+ description: "Auto-generate tests for new implementation using test-generator MCP"
888
+ when:
889
+ concept: "implementation"
890
+ action: "generate"
891
+ status: "completed"
892
+ where:
893
+ query: "implementation.status == 'completed' AND implementation.files_changed.length > 0"
894
+ then:
895
+ - concept: "quality"
896
+ action: "generate_tests"
897
+ model: "sonnet"
898
+ parallel: true # Runs alongside code review
899
+ mcp_tools:
900
+ # Generate unit tests for each changed file
901
+ - tool: "test-generator.generate_unit_tests"
902
+ input:
903
+ sourceFiles: "${implementation.files_changed}"
904
+ language: "${implementation.language || 'typescript'}"
905
+ framework: "${project.test_framework || 'vitest'}"
906
+ coverageTarget: 80
907
+ output_to: "generated_tests"
908
+
909
+ # Suggest additional tests based on code analysis
910
+ - tool: "test-generator.suggest_tests"
911
+ input:
912
+ files: "${implementation.files_changed}"
913
+ language: "${implementation.language || 'typescript'}"
914
+ output_to: "test_suggestions"
915
+
916
+ # Find any files that now lack tests
917
+ - tool: "test-generator.find_untested_files"
918
+ input:
919
+ sourceGlob: "src/**/*.{ts,tsx,js,jsx}"
920
+ testGlob: "**/*.{test,spec}.{ts,tsx,js,jsx}"
921
+ output_to: "untested_files"
922
+
923
+ inputs:
924
+ implementation_id: "${implementation.id}"
925
+ story_id: "${story.id}"
926
+ files_changed: "${implementation.files_changed}"
927
+
928
+ outputs:
929
+ target: "koan/tests/test-gen-${implementation.id}.yaml"
930
+
931
+ # MCP-specific error handling
932
+ error_handling:
933
+ mcp_connection_failed:
934
+ type: "transient"
935
+ action: "retry"
936
+ max_retries: 2
937
+ backoff_ms: 1000
938
+ on_exhausted:
939
+ action: "skip"
940
+ set_flag: "test_generation.skipped = true"
941
+ reason: "Test generator MCP unavailable - manual test creation needed"
942
+
943
+ mcp_tool_not_found:
944
+ type: "permanent"
945
+ action: "skip"
946
+ set_flag: "test_generation.skipped = true"
947
+ reason: "test-generator MCP server not installed"
948
+
949
+ slo_expectations:
950
+ <<: *SLO_TEST_GENERATION
951
+
952
+ provenance:
953
+ flow_id: "${flow.id}"
954
+ reason: "Auto-generating tests for new implementation"
955
+ category: "automation"
956
+ mcp_server: "test-generator"
957
+
958
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
959
+ # Phase 3: Implementation → Quality (PARALLEL)
960
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
961
+ #
962
+ # KEY OPTIMIZATION: Both quality checks run simultaneously
963
+ # - 50% faster execution (2min vs 4min)
964
+ # - Same cost (both actions run anyway)
965
+ # - Safe parallelization (independent checks)
966
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
967
+
968
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
969
+ # Phase 2.5: Exploration → Quality Context
970
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
971
+ #
972
+ # AUTOMATIC: When exploration was performed, inject rationale into quality review
973
+ # This helps reviewers understand why certain approaches were selected
974
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
975
+
976
+ - id: "exploration-to-quality-context"
977
+ description: "Inject exploration rationale into quality review for informed review"
978
+ when:
979
+ concept: "quality"
980
+ action: "review"
981
+ status: "starting"
982
+ where:
983
+ query: "exploration.selected_path != null"
984
+ then:
985
+ - action: "inject_context"
986
+ target: "quality.review"
987
+ context_type: "exploration_rationale"
988
+ content:
989
+ selected_approach: "${exploration.selected_path.name}"
990
+ selection_criteria: "${exploration.selected_path.criteria}"
991
+ rejected_alternatives: "${exploration.rejected_paths_summary}"
992
+ confidence_level: "${exploration.confidence}"
993
+ trade_offs: "${exploration.selected_path.trade_offs}"
994
+
995
+ slo_expectations:
996
+ expected_duration_ms: 100
997
+ max_duration_ms: 500
998
+ expected_cost_usd: 0.0
999
+ max_cost_usd: 0.0
1000
+ expected_context_tokens: 300
1001
+ on_timeout:
1002
+ action: "skip"
1003
+ fallback: "Proceed without exploration context"
1004
+
1005
+ provenance:
1006
+ flow_id: "${flow.id}"
1007
+ reason: "Injecting exploration rationale to inform quality review"
1008
+ category: "intelligence"
1009
+
1010
+ - id: "impl-to-quality-review"
1011
+ description: "When implementation complete, review code quality"
1012
+ when:
1013
+ concept: "implementation"
1014
+ action: "generate"
1015
+ status: "completed"
1016
+ where:
1017
+ query: "implementation.status == 'completed' AND implementation.blockers.length == 0"
1018
+ then:
1019
+ - concept: "quality"
1020
+ action: "review"
1021
+ model: "sonnet"
1022
+ parallel: true # ← ENABLES PARALLEL EXECUTION
1023
+ inputs:
1024
+ implementation_id: "${implementation.id}"
1025
+ files: "${implementation.files_changed}"
1026
+ patterns: "${architecture.patterns}"
1027
+ # NEW: Include exploration context if available
1028
+ exploration_rationale: "${exploration.selected_path || null}"
1029
+
1030
+ # SLO Expectations for quality.review
1031
+ slo_expectations:
1032
+ expected_duration_ms: 2500 # 2.5 seconds typical
1033
+ max_duration_ms: 20000 # 20 seconds timeout
1034
+ expected_cost_usd: 0.000175 # Sonnet pattern-based review
1035
+ max_cost_usd: 0.001 # Alert if exceeds
1036
+ expected_context_tokens: 800 # Code + patterns
1037
+ max_context_tokens: 3000 # Warning threshold
1038
+ success_rate_target: 0.95 # 95% reviews complete successfully
1039
+
1040
+ on_timeout:
1041
+ action: "retry"
1042
+ max_retries: 1
1043
+ backoff_ms: 1000
1044
+ on_exhausted: "escalate"
1045
+
1046
+ on_cost_exceeded:
1047
+ action: "alert"
1048
+ continue: true
1049
+
1050
+ on_context_exceeded:
1051
+ action: "alert"
1052
+ investigate: true
1053
+
1054
+ provenance:
1055
+ flow_id: "${flow.id}"
1056
+ reason: "Implementation complete, code review required"
1057
+ category: "core"
1058
+
1059
+ - id: "impl-to-quality-test"
1060
+ description: "When implementation complete, run tests"
1061
+ when:
1062
+ concept: "implementation"
1063
+ action: "generate"
1064
+ status: "completed"
1065
+ where:
1066
+ query: "implementation.status == 'completed' AND implementation.test_files.length > 0"
1067
+ then:
1068
+ - concept: "quality"
1069
+ action: "test"
1070
+ model: "sonnet"
1071
+ parallel: true # ← RUNS SIMULTANEOUSLY WITH REVIEW
1072
+ inputs:
1073
+ implementation_id: "${implementation.id}"
1074
+ test_paths: "${implementation.test_files}"
1075
+ story_id: "${story.id}"
1076
+
1077
+ # SLO Expectations for quality.test
1078
+ slo_expectations:
1079
+ expected_duration_ms: 2500 # 2.5 seconds typical
1080
+ max_duration_ms: 20000 # 20 seconds timeout
1081
+ expected_cost_usd: 0.000175 # Sonnet test execution
1082
+ max_cost_usd: 0.001 # Alert if exceeds
1083
+ expected_context_tokens: 800 # Test code + context
1084
+ max_context_tokens: 3000 # Warning threshold
1085
+ success_rate_target: 0.95 # 95% test runs succeed
1086
+
1087
+ on_timeout:
1088
+ action: "retry"
1089
+ max_retries: 1
1090
+ backoff_ms: 1000
1091
+ on_exhausted: "escalate"
1092
+
1093
+ on_cost_exceeded:
1094
+ action: "alert"
1095
+ continue: true
1096
+
1097
+ on_context_exceeded:
1098
+ action: "alert"
1099
+ investigate: true
1100
+
1101
+ provenance:
1102
+ flow_id: "${flow.id}"
1103
+ reason: "Implementation complete with tests, execute test suite"
1104
+ category: "core"
1105
+
1106
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1107
+ # Phase 3.5: Coverage Analysis (MCP-Powered)
1108
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1109
+ #
1110
+ # AUTOMATIC: After tests pass, analyze coverage and suggest improvements
1111
+ # Uses test-generator MCP for coverage analysis
1112
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1113
+
1114
+ - id: "quality-test-passed-to-coverage"
1115
+ description: "After tests pass, analyze coverage using test-generator MCP"
1116
+ when:
1117
+ concept: "quality"
1118
+ action: "test"
1119
+ status: "completed"
1120
+ where:
1121
+ query: "test.status == 'passed' AND test.failed == 0"
1122
+ then:
1123
+ - concept: "quality"
1124
+ action: "analyze_coverage"
1125
+ model: "sonnet"
1126
+ mcp_tools:
1127
+ # Analyze coverage from test run
1128
+ - tool: "test-generator.analyze_coverage"
1129
+ input:
1130
+ coverageDir: "${project.coverage_dir || 'coverage/'}"
1131
+ output_to: "coverage_report"
1132
+
1133
+ # Find any files still without tests
1134
+ - tool: "test-generator.find_untested_files"
1135
+ input:
1136
+ sourceGlob: "src/**/*.{ts,tsx,js,jsx}"
1137
+ testGlob: "**/*.{test,spec}.{ts,tsx,js,jsx}"
1138
+ output_to: "untested_files"
1139
+
1140
+ inputs:
1141
+ implementation_id: "${implementation.id}"
1142
+ test_results: "${test.results}"
1143
+
1144
+ outputs:
1145
+ target: "koan/coverage/coverage-${implementation.id}.yaml"
1146
+
1147
+ # MCP-specific error handling
1148
+ error_handling:
1149
+ mcp_connection_failed:
1150
+ type: "transient"
1151
+ action: "skip"
1152
+ set_flag: "coverage_analysis.skipped = true"
1153
+ reason: "Coverage analysis MCP unavailable - proceeding without"
1154
+
1155
+ mcp_tool_not_found:
1156
+ type: "permanent"
1157
+ action: "skip"
1158
+ set_flag: "coverage_analysis.skipped = true"
1159
+
1160
+ slo_expectations:
1161
+ <<: *SLO_COVERAGE_ANALYSIS
1162
+
1163
+ provenance:
1164
+ flow_id: "${flow.id}"
1165
+ reason: "Analyzing coverage after successful tests"
1166
+ category: "intelligence"
1167
+ mcp_server: "test-generator"
1168
+
1169
+ # If coverage is below target, suggest generating more tests
1170
+ - id: "coverage-below-target-suggest"
1171
+ description: "When coverage below target, suggest additional tests"
1172
+ when:
1173
+ concept: "quality"
1174
+ action: "analyze_coverage"
1175
+ status: "completed"
1176
+ where:
1177
+ query: "coverage_report.overall < (project.coverage_target || 80)"
1178
+ then:
1179
+ - action: "ask_user"
1180
+ questions:
1181
+ - question: "Coverage at ${coverage_report.overall}% (target: ${project.coverage_target || 80}%). Generate more tests?"
1182
+ header: "Coverage Gap"
1183
+ multiSelect: false
1184
+ options:
1185
+ - label: "Generate additional tests (Recommended)"
1186
+ description: "Auto-generate tests for low-coverage files"
1187
+ - label: "Proceed anyway"
1188
+ description: "Accept current coverage and continue to commit"
1189
+ - label: "Show coverage details"
1190
+ description: "Display detailed coverage report first"
1191
+
1192
+ on_answer:
1193
+ "Generate additional tests (Recommended)":
1194
+ - concept: "quality"
1195
+ action: "generate_tests"
1196
+ model: "sonnet"
1197
+ mcp_tools:
1198
+ - tool: "test-generator.generate_unit_tests"
1199
+ input:
1200
+ sourceFiles: "${coverage_report.low_coverage_files}"
1201
+ language: "${implementation.language || 'typescript'}"
1202
+ framework: "${project.test_framework || 'vitest'}"
1203
+ coverageTarget: "${project.coverage_target || 80}"
1204
+ inputs:
1205
+ focus: "low_coverage"
1206
+ files: "${coverage_report.low_coverage_files}"
1207
+
1208
+ "Proceed anyway":
1209
+ - action: "set_flag"
1210
+ flag: "coverage.accepted_below_target"
1211
+ value: true
1212
+ # Workflow continues to version
1213
+
1214
+ "Show coverage details":
1215
+ - action: "display"
1216
+ content:
1217
+ title: "Coverage Report"
1218
+ overall: "${coverage_report.overall}%"
1219
+ breakdown: "${coverage_report.breakdown}"
1220
+ low_files: "${coverage_report.low_coverage_files}"
1221
+ suggestions: "${coverage_report.recommendations}"
1222
+
1223
+ provenance:
1224
+ flow_id: "${flow.id}"
1225
+ reason: "Coverage below target - user decision required"
1226
+ decision_point: true
1227
+ user_interaction: "ask_user_question"
1228
+ category: "quality"
1229
+
1230
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1231
+ # Phase 4: Quality → Version (Sequential)
1232
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1233
+ #
1234
+ # WAITS for BOTH parallel quality checks to complete
1235
+ # Uses depends_on to prevent race condition
1236
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1237
+
1238
+ - id: "quality-to-version"
1239
+ description: "When quality approved and tests pass, commit changes"
1240
+ when:
1241
+ concept: "quality"
1242
+ action: "review|test" # Triggered after EITHER completes
1243
+ status: "completed"
1244
+
1245
+ # RACE CONDITION FIX: Wait for both parallel tasks before triggering
1246
+ depends_on:
1247
+ required:
1248
+ - id: "impl-to-quality-review"
1249
+ status: "completed"
1250
+ timeout_ms: 30000
1251
+ - id: "impl-to-quality-test"
1252
+ status: "completed|skipped" # Test may be skipped if no test files
1253
+ timeout_ms: 30000
1254
+ on_dependency_timeout:
1255
+ action: "wait" # Keep waiting, don't proceed prematurely
1256
+ max_wait_ms: 60000
1257
+ on_max_wait:
1258
+ action: "escalate"
1259
+ message: "Quality checks timed out - manual intervention needed"
1260
+
1261
+ where:
1262
+ # This query ensures BOTH checks passed AND no blockers exist
1263
+ query: "review.status == 'approved' AND test.status == 'passed' AND test.failed == 0 AND implementation.blockers.length == 0"
1264
+ then:
1265
+ - concept: "version"
1266
+ action: "commit"
1267
+ model: "sonnet"
1268
+ inputs:
1269
+ implementation_id: "${implementation.id}"
1270
+ story_id: "${story.id}"
1271
+ flow_id: "${flow.id}"
1272
+ files: "${implementation.files_changed}"
1273
+
1274
+ # SLO Expectations for version.commit
1275
+ slo_expectations:
1276
+ expected_duration_ms: 1000 # 1 second typical
1277
+ max_duration_ms: 5000 # 5 seconds timeout
1278
+ expected_cost_usd: 0.000175 # Sonnet commit message generation
1279
+ max_cost_usd: 0.0005 # Alert if exceeds
1280
+ expected_context_tokens: 300 # Minimal context (files + summary)
1281
+ max_context_tokens: 1000 # Warning threshold
1282
+ success_rate_target: 0.99 # 99% commits succeed
1283
+
1284
+ on_timeout:
1285
+ action: "retry"
1286
+ max_retries: 2
1287
+ backoff_ms: 500
1288
+ on_exhausted: "escalate"
1289
+
1290
+ on_cost_exceeded:
1291
+ action: "alert"
1292
+ continue: true
1293
+
1294
+ on_context_exceeded:
1295
+ action: "alert"
1296
+ investigate: true
1297
+
1298
+ provenance:
1299
+ flow_id: "${flow.id}"
1300
+ reason: "Quality approved, all tests passed, ready for version control"
1301
+ category: "core"
1302
+
1303
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1304
+ # Phase 4B: Version → Story Completion (Auto-Transition)
1305
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1306
+ #
1307
+ # AUTOMATIC: When workflow commits successfully, mark the
1308
+ # story as "completed". This prevents stories from staying
1309
+ # stuck at "ready" status after their implementation ships.
1310
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1311
+
1312
+ - id: "version-to-story-complete"
1313
+ description: "Auto-complete story when workflow commits successfully"
1314
+ when:
1315
+ concept: "version"
1316
+ action: "commit"
1317
+ status: "completed"
1318
+ where:
1319
+ query: "story.status == 'ready' AND flow.status == 'completed'"
1320
+ then:
1321
+ - concept: "story"
1322
+ action: "update_status"
1323
+ model: "sonnet"
1324
+ inputs:
1325
+ story_id: "${story.id}"
1326
+ new_status: "completed"
1327
+ reason: "Workflow completed - implementation committed"
1328
+
1329
+ slo_expectations:
1330
+ <<: *SLO_QUICK
1331
+
1332
+ provenance:
1333
+ flow_id: "${flow.id}"
1334
+ reason: "Auto-completing story after successful workflow commit"
1335
+ category: "lifecycle"
1336
+
1337
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1338
+ # Error Recovery: Quality → Implementation (Rework)
1339
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1340
+
1341
+ - id: "quality-needs-changes"
1342
+ description: "When quality review finds issues, refactor implementation"
1343
+ when:
1344
+ concept: "quality"
1345
+ action: "review"
1346
+ status: "completed"
1347
+ where:
1348
+ query: "review.status == 'needs_changes'"
1349
+ then:
1350
+ - concept: "implementation"
1351
+ action: "refactor"
1352
+ model: "sonnet"
1353
+ inputs:
1354
+ implementation_id: "${implementation.id}"
1355
+ issues: "${review.issues}"
1356
+ suggestions: "${review.suggestions}"
1357
+ provenance:
1358
+ flow_id: "${flow.id}"
1359
+ reason: "Code review identified issues requiring refactoring"
1360
+ category: "recovery"
1361
+
1362
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1363
+ # MCP-Powered Self-Repair (execution-loop)
1364
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1365
+ #
1366
+ # When tests fail, use execution-loop MCP for automatic repair:
1367
+ # 1. Diagnose failure with self_debug
1368
+ # 2. Apply fix with iterative_refine
1369
+ # 3. Re-run tests with run_tests_with_repair
1370
+ # 4. Loop until passing or max iterations
1371
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1372
+
1373
+ - id: "quality-tests-failed-self-repair"
1374
+ description: "When tests fail, use execution-loop MCP to auto-repair"
1375
+ when:
1376
+ concept: "quality"
1377
+ action: "test"
1378
+ status: "completed"
1379
+ where:
1380
+ # Only trigger if tests failed AND we haven't exceeded repair attempts
1381
+ query: "test.status == 'failed' AND test.failed > 0 AND (repair_attempts || 0) < 3"
1382
+ then:
1383
+ - concept: "quality"
1384
+ action: "self_repair"
1385
+ model: "sonnet"
1386
+ mcp_tools:
1387
+ # First: Diagnose the failure
1388
+ - tool: "execution-loop.self_debug"
1389
+ input:
1390
+ code: "${implementation.files_changed}"
1391
+ error: "${test.failures[0].message}"
1392
+ language: "${implementation.language || 'typescript'}"
1393
+ contextFiles: "${test.failures[0].file}"
1394
+ output_to: "diagnosis"
1395
+
1396
+ # Second: Run tests with automatic repair
1397
+ - tool: "execution-loop.run_tests_with_repair"
1398
+ input:
1399
+ testCommand: "${project.test_command || 'npm test'}"
1400
+ cwd: "${project.root}"
1401
+ targetFiles: "${implementation.files_changed}"
1402
+ maxRetries: 3
1403
+ output_to: "repair_result"
1404
+
1405
+ inputs:
1406
+ implementation_id: "${implementation.id}"
1407
+ failing_tests: "${test.failures}"
1408
+ test_output: "${test.results}"
1409
+ repair_attempt: "${(repair_attempts || 0) + 1}"
1410
+
1411
+ outputs:
1412
+ target: "koan/repairs/repair-${implementation.id}-${repair_attempts || 1}.yaml"
1413
+
1414
+ # Track repair attempts to prevent infinite loops
1415
+ state_updates:
1416
+ - key: "repair_attempts"
1417
+ value: "${(repair_attempts || 0) + 1}"
1418
+
1419
+ # MCP-specific error handling
1420
+ error_handling:
1421
+ mcp_connection_failed:
1422
+ type: "transient"
1423
+ action: "retry"
1424
+ max_retries: 1
1425
+ backoff_ms: 2000
1426
+ on_exhausted:
1427
+ action: "fallback"
1428
+ fallback_rule: "quality-tests-failed-manual"
1429
+
1430
+ mcp_tool_not_found:
1431
+ type: "permanent"
1432
+ action: "fallback"
1433
+ fallback_rule: "quality-tests-failed-manual"
1434
+
1435
+ slo_expectations:
1436
+ <<: *SLO_EXECUTION_LOOP
1437
+
1438
+ provenance:
1439
+ flow_id: "${flow.id}"
1440
+ reason: "Test failures - attempting automatic repair via execution-loop MCP"
1441
+ category: "automation"
1442
+ mcp_server: "execution-loop"
1443
+
1444
+ # Fallback: Manual fix when MCP unavailable or max retries exceeded
1445
+ - id: "quality-tests-failed-manual"
1446
+ description: "Fallback: Manual implementation fix when self-repair unavailable"
1447
+ when:
1448
+ concept: "quality"
1449
+ action: "test"
1450
+ status: "completed"
1451
+ where:
1452
+ # Triggers if: MCP unavailable OR max repair attempts exceeded
1453
+ query: "(test.status == 'failed' AND test.failed > 0 AND execution_loop.unavailable == true) OR (repair_attempts >= 3)"
1454
+ then:
1455
+ - concept: "implementation"
1456
+ action: "fix"
1457
+ model: "sonnet"
1458
+ inputs:
1459
+ implementation_id: "${implementation.id}"
1460
+ failing_tests: "${test.failures}"
1461
+ test_output: "${test.results}"
1462
+ repair_history: "${repair_attempts > 0 ? 'Previous auto-repair attempts failed' : null}"
1463
+
1464
+ slo_expectations:
1465
+ <<: *SLO_IMPLEMENTATION
1466
+
1467
+ provenance:
1468
+ flow_id: "${flow.id}"
1469
+ reason: "Test failures require manual implementation fixes (auto-repair unavailable or exhausted)"
1470
+ category: "recovery"
1471
+
1472
+ # After successful self-repair, re-run quality checks
1473
+ - id: "self-repair-success-to-quality"
1474
+ description: "After successful self-repair, re-run full quality checks"
1475
+ when:
1476
+ concept: "quality"
1477
+ action: "self_repair"
1478
+ status: "completed"
1479
+ where:
1480
+ query: "repair_result.success == true AND repair_result.tests_passing == true"
1481
+ then:
1482
+ - concept: "quality"
1483
+ action: "test"
1484
+ model: "sonnet"
1485
+ inputs:
1486
+ implementation_id: "${implementation.id}"
1487
+ test_paths: "${implementation.test_files}"
1488
+ story_id: "${story.id}"
1489
+ after_repair: true
1490
+
1491
+ # Reset repair counter on success
1492
+ state_updates:
1493
+ - key: "repair_attempts"
1494
+ value: 0
1495
+
1496
+ slo_expectations:
1497
+ <<: *SLO_QUALITY
1498
+
1499
+ provenance:
1500
+ flow_id: "${flow.id}"
1501
+ reason: "Self-repair succeeded - re-running quality checks to verify"
1502
+ category: "validation"
1503
+
1504
+ # If self-repair fails, escalate to user
1505
+ - id: "self-repair-failed-escalate"
1506
+ description: "When self-repair fails after max attempts, ask user"
1507
+ when:
1508
+ concept: "quality"
1509
+ action: "self_repair"
1510
+ status: "completed"
1511
+ where:
1512
+ query: "repair_result.success == false OR repair_attempts >= 3"
1513
+ then:
1514
+ - action: "ask_user"
1515
+ questions:
1516
+ - question: "Auto-repair failed after ${repair_attempts} attempts. Test failures: ${test.failures.length}. How to proceed?"
1517
+ header: "Repair Failed"
1518
+ multiSelect: false
1519
+ options:
1520
+ - label: "Show me the errors"
1521
+ description: "Display full error details so I can fix manually"
1522
+ - label: "Try different approach"
1523
+ description: "Revert changes and try a different implementation strategy"
1524
+ - label: "Skip tests for now"
1525
+ description: "Proceed without passing tests (not recommended)"
1526
+
1527
+ on_answer:
1528
+ "Show me the errors":
1529
+ - action: "display"
1530
+ content:
1531
+ title: "Test Failures"
1532
+ failures: "${test.failures}"
1533
+ repair_attempts: "${repair_history}"
1534
+ suggested_fixes: "${diagnosis.suggestions}"
1535
+
1536
+ "Try different approach":
1537
+ - concept: "implementation"
1538
+ action: "revise"
1539
+ model: "sonnet"
1540
+ inputs:
1541
+ original_implementation: "${implementation}"
1542
+ failure_reason: "${test.failures}"
1543
+ constraint: "Try a different approach - previous implementation had unfixable test failures"
1544
+
1545
+ "Skip tests for now":
1546
+ - action: "set_flag"
1547
+ flag: "tests.skipped"
1548
+ value: true
1549
+ - concept: "version"
1550
+ action: "commit"
1551
+ model: "sonnet"
1552
+ inputs:
1553
+ implementation_id: "${implementation.id}"
1554
+ story_id: "${story.id}"
1555
+ warning: "TESTS SKIPPED - User chose to proceed without passing tests"
1556
+
1557
+ provenance:
1558
+ flow_id: "${flow.id}"
1559
+ reason: "Auto-repair exhausted - user intervention required"
1560
+ decision_point: true
1561
+ user_interaction: "ask_user_question"
1562
+ category: "recovery"
1563
+
1564
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1565
+ # Automatic Checkpoints (Phase 4)
1566
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1567
+ #
1568
+ # Automatic state preservation at key points:
1569
+ # 1. On every git commit (ties to version history)
1570
+ # 2. Before context compression (safety net at 70%)
1571
+ # 3. On workflow/feature completion (milestone marker)
1572
+ # 4. On session exit (via hook)
1573
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1574
+
1575
+ # Trigger 1: Auto-checkpoint on git commit
1576
+ - id: "commit-auto-checkpoint"
1577
+ description: "Create checkpoint automatically on every git commit"
1578
+ when:
1579
+ event: "git.commit"
1580
+ status: "completed"
1581
+ then:
1582
+ - concept: "checkpoint"
1583
+ action: "create"
1584
+ model: "haiku" # Fast, lightweight
1585
+ inputs:
1586
+ name: "commit-${commit.short_hash}"
1587
+ type: "commit"
1588
+ commit_hash: "${commit.hash}"
1589
+ commit_message: "${commit.message}"
1590
+ files_changed: "${commit.files}"
1591
+ include:
1592
+ - "active_task"
1593
+ - "recent_decisions"
1594
+ - "conversation_summary"
1595
+ lightweight: true # Don't include full conversation
1596
+
1597
+ outputs:
1598
+ target: "koan/session-state/checkpoint-commit-${commit.short_hash}.yaml"
1599
+
1600
+ slo_expectations:
1601
+ expected_duration_ms: 500
1602
+ max_duration_ms: 3000
1603
+ expected_cost_usd: 0.00005 # Haiku is very cheap
1604
+ max_cost_usd: 0.0002
1605
+ success_rate_target: 0.99
1606
+
1607
+ provenance:
1608
+ reason: "Auto-checkpoint on commit for version-aligned restoration"
1609
+ category: "checkpoint"
1610
+ automatic: true
1611
+
1612
+ # Trigger 2: Auto-checkpoint before context compression
1613
+ - id: "pre-compression-checkpoint"
1614
+ description: "Create checkpoint before context compression at 70%"
1615
+ when:
1616
+ concept: "*"
1617
+ action: "*"
1618
+ status: "completed"
1619
+ where:
1620
+ query: "context.usage_percent >= 70 AND context.usage_percent < 75 AND checkpoint.last_at_percent < 70"
1621
+ then:
1622
+ - concept: "checkpoint"
1623
+ action: "create"
1624
+ model: "haiku"
1625
+ inputs:
1626
+ name: "pre-compress-${timestamp}"
1627
+ type: "safety"
1628
+ reason: "Context at 70% - saving state before compression"
1629
+ include:
1630
+ - "active_task"
1631
+ - "all_decisions"
1632
+ - "conversation_highlights"
1633
+ - "pending_work"
1634
+ lightweight: false # Full checkpoint before potential loss
1635
+
1636
+ outputs:
1637
+ target: "koan/session-state/checkpoint-pre-compress-${timestamp}.yaml"
1638
+
1639
+ state_updates:
1640
+ - key: "checkpoint.last_at_percent"
1641
+ value: "${context.usage_percent}"
1642
+
1643
+ slo_expectations:
1644
+ expected_duration_ms: 1000
1645
+ max_duration_ms: 5000
1646
+ expected_cost_usd: 0.0001
1647
+ max_cost_usd: 0.0005
1648
+ success_rate_target: 0.99
1649
+
1650
+ provenance:
1651
+ reason: "Safety checkpoint before context compression"
1652
+ category: "checkpoint"
1653
+ automatic: true
1654
+
1655
+ # Trigger 3: Auto-checkpoint on workflow/feature completion
1656
+ - id: "workflow-complete-checkpoint"
1657
+ description: "Create checkpoint when workflow completes successfully"
1658
+ when:
1659
+ concept: "version"
1660
+ action: "commit"
1661
+ status: "completed"
1662
+ where:
1663
+ query: "flow.status == 'completed'"
1664
+ then:
1665
+ - concept: "checkpoint"
1666
+ action: "create"
1667
+ model: "haiku"
1668
+ inputs:
1669
+ name: "feature-${story.id}"
1670
+ type: "milestone"
1671
+ story_id: "${story.id}"
1672
+ story_title: "${story.title}"
1673
+ flow_id: "${flow.id}"
1674
+ include:
1675
+ - "story_summary"
1676
+ - "architecture_decisions"
1677
+ - "implementation_summary"
1678
+ - "quality_results"
1679
+ - "total_cost"
1680
+ milestone: true
1681
+
1682
+ outputs:
1683
+ target: "koan/session-state/checkpoint-feature-${story.id}.yaml"
1684
+
1685
+ slo_expectations:
1686
+ expected_duration_ms: 800
1687
+ max_duration_ms: 4000
1688
+ expected_cost_usd: 0.00008
1689
+ max_cost_usd: 0.0003
1690
+ success_rate_target: 0.99
1691
+
1692
+ provenance:
1693
+ flow_id: "${flow.id}"
1694
+ reason: "Feature milestone checkpoint - workflow completed successfully"
1695
+ category: "checkpoint"
1696
+ automatic: true
1697
+ milestone: true
1698
+
1699
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1700
+ # MEMORY INTEGRATION: Auto-Remember Workflow Summary
1701
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1702
+ #
1703
+ # AUTOMATIC: Store workflow summary in semantic memory
1704
+ # Captures feature approach, key files, and patterns for future reference
1705
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1706
+
1707
+ - id: "workflow-complete-memory"
1708
+ description: "Auto-remember workflow summary after successful completion"
1709
+ when:
1710
+ concept: "version"
1711
+ action: "commit"
1712
+ status: "completed"
1713
+ where:
1714
+ query: "flow.status == 'completed'"
1715
+ then:
1716
+ - action: "store_memory"
1717
+ target: "koan/memory/semantic/patterns.yaml"
1718
+ content:
1719
+ id: "mem-workflow-${story.id}-${timestamp}"
1720
+ type: "workflow_completion"
1721
+ category: "patterns"
1722
+ content: "Feature '${story.title}' implemented using ${architecture.approach}. Key files: ${implementation.files_changed.slice(0, 5).join(', ')}"
1723
+ confidence: 0.6
1724
+ source: "Auto-captured from workflow ${flow.id}"
1725
+ tags:
1726
+ - "workflow"
1727
+ - "${story.title.split(' ')[0].toLowerCase()}"
1728
+ story_id: "${story.id}"
1729
+ architecture_id: "${architecture.id}"
1730
+ implementation_id: "${implementation.id}"
1731
+ created_at: "${timestamp}"
1732
+ metrics:
1733
+ files_changed: "${implementation.files_changed.length}"
1734
+ total_cost: "${flow.total_cost}"
1735
+ duration_minutes: "${flow.duration_minutes}"
1736
+
1737
+ slo_expectations:
1738
+ expected_duration_ms: 50
1739
+ max_duration_ms: 200
1740
+ expected_cost_usd: 0.0
1741
+ max_cost_usd: 0.0
1742
+ on_timeout:
1743
+ action: "skip"
1744
+ fallback: "Memory storage skipped - workflow summary not persisted"
1745
+ on_failure:
1746
+ action: "log"
1747
+ continue: true
1748
+
1749
+ provenance:
1750
+ flow_id: "${flow.id}"
1751
+ reason: "Auto-remembering workflow summary for future reference"
1752
+ category: "memory"
1753
+ automatic: true
1754
+
1755
+ # Trigger 4: Session exit checkpoint (via hook)
1756
+ # Note: This is implemented as a Claude Code hook, not a sync rule
1757
+ # See: .claude/settings.local.json → hooks.Stop
1758
+ #
1759
+ # Hook implementation:
1760
+ # {
1761
+ # "hooks": {
1762
+ # "Stop": [{
1763
+ # "type": "command",
1764
+ # "command": "claude -p 'Create a checkpoint for session end. Name: session-exit-$(date +%Y%m%d-%H%M%S). Include: active tasks, uncommitted work, conversation summary, next steps.' --output koan/session-state/"
1765
+ # }]
1766
+ # }
1767
+ # }
1768
+
1769
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1770
+ # Context Management (Automatic - Phase 3)
1771
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1772
+ #
1773
+ # Automatically manages context window to prevent overflow
1774
+ # - 75% threshold: Smart compression of earlier steps
1775
+ # - 90% threshold: Full snapshot and context reset
1776
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1777
+
1778
+ - id: "context-compression"
1779
+ description: "At 75% context usage, compress earlier workflow steps"
1780
+ when:
1781
+ concept: "*" # After any concept completes
1782
+ action: "*"
1783
+ status: "completed"
1784
+ where:
1785
+ query: "context.usage_percent >= 75 AND context.usage_percent < 90"
1786
+ then:
1787
+ - concept: "context"
1788
+ action: "compress"
1789
+ model: "sonnet"
1790
+ inputs:
1791
+ threshold: "75%"
1792
+ strategy: "smart_compression"
1793
+ compress_range: "steps_1_to_current_minus_3" # Keep last 3 steps in full detail
1794
+ target_reduction: "80%"
1795
+
1796
+ # SLO Expectations for context.compress
1797
+ slo_expectations:
1798
+ expected_duration_ms: 1500 # 1.5 seconds typical
1799
+ max_duration_ms: 10000 # 10 seconds timeout
1800
+ expected_cost_usd: 0.000175 # Sonnet compression
1801
+ max_cost_usd: 0.0005 # Alert if exceeds
1802
+ expected_context_tokens: 500 # Analyzing existing context
1803
+ max_context_tokens: 2000 # Warning threshold
1804
+ success_rate_target: 0.99 # 99% compression succeeds
1805
+
1806
+ on_timeout:
1807
+ action: "escalate" # Compression failure is serious
1808
+
1809
+ on_cost_exceeded:
1810
+ action: "alert"
1811
+ continue: true
1812
+
1813
+ on_context_exceeded:
1814
+ action: "alert"
1815
+ investigate: true
1816
+
1817
+ provenance:
1818
+ flow_id: "${flow.id}"
1819
+ reason: "Context at 75% - compressing earlier steps to maintain performance"
1820
+ category: "context-management"
1821
+
1822
+ - id: "context-snapshot"
1823
+ description: "At 90% context usage, create snapshot and reset"
1824
+ when:
1825
+ concept: "*"
1826
+ action: "*"
1827
+ status: "completed"
1828
+ where:
1829
+ query: "context.usage_percent >= 90"
1830
+ then:
1831
+ - concept: "context"
1832
+ action: "snapshot"
1833
+ model: "sonnet"
1834
+ inputs:
1835
+ threshold: "90%"
1836
+ strategy: "full_snapshot"
1837
+ snapshot_location: "koan/session-state/snapshot-${timestamp}.yaml"
1838
+ reset_to: "5K_summary"
1839
+
1840
+ # SLO Expectations for context.snapshot
1841
+ slo_expectations:
1842
+ expected_duration_ms: 1500 # 1.5 seconds typical
1843
+ max_duration_ms: 10000 # 10 seconds timeout
1844
+ expected_cost_usd: 0.000175 # Sonnet snapshot creation
1845
+ max_cost_usd: 0.0005 # Alert if exceeds
1846
+ expected_context_tokens: 500 # Minimal (writing snapshot)
1847
+ max_context_tokens: 2000 # Warning threshold
1848
+ success_rate_target: 0.99 # 99% snapshots succeed
1849
+
1850
+ on_timeout:
1851
+ action: "escalate" # Snapshot failure is critical
1852
+
1853
+ on_cost_exceeded:
1854
+ action: "alert"
1855
+ continue: true
1856
+
1857
+ on_context_exceeded:
1858
+ action: "alert"
1859
+ investigate: true
1860
+
1861
+ provenance:
1862
+ flow_id: "${flow.id}"
1863
+ reason: "Context critical at 90% - creating snapshot and resetting"
1864
+ category: "context-management"
1865
+
1866
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1867
+ # Budget Management (Human-in-the-Loop)
1868
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1869
+
1870
+ - id: "cost-budget-approval"
1871
+ description: "Ask user when workflow cost exceeds configured budget"
1872
+ when:
1873
+ concept: "*"
1874
+ action: "*"
1875
+ status: "completed"
1876
+ where:
1877
+ query: "flow.total_cost > config.cost_budget AND flow.budget_approval_requested == false"
1878
+ then:
1879
+ - action: "ask_user"
1880
+ questions:
1881
+ - question: "Workflow cost $${flow.total_cost} exceeds budget $${config.cost_budget}. Continue?"
1882
+ header: "Budget Exceeded"
1883
+ multiSelect: false
1884
+ options:
1885
+ - label: "Continue anyway"
1886
+ description: "The extra cost is acceptable for this feature"
1887
+ - label: "Optimize and retry"
1888
+ description: "Try to reduce cost (may impact quality)"
1889
+ - label: "Cancel workflow"
1890
+ description: "Stop now to avoid more costs"
1891
+
1892
+ on_answer:
1893
+ "Continue anyway":
1894
+ - action: "set_flag"
1895
+ flag: "flow.budget_approval_requested"
1896
+ value: true
1897
+ # Workflow continues normally
1898
+
1899
+ "Optimize and retry":
1900
+ - concept: "context"
1901
+ action: "optimize"
1902
+ model: "sonnet"
1903
+ inputs:
1904
+ target: "reduce_cost"
1905
+ budget_remaining: "${config.cost_budget - flow.total_cost}"
1906
+
1907
+ "Cancel workflow":
1908
+ - concept: "story"
1909
+ action: "cancel"
1910
+ model: "sonnet"
1911
+ inputs:
1912
+ story_id: "${story.id}"
1913
+ reason: "User cancelled due to budget exceeded ($${flow.total_cost} > $${config.cost_budget})"
1914
+
1915
+ provenance:
1916
+ flow_id: "${flow.id}"
1917
+ reason: "Cost budget exceeded - user approval required"
1918
+ decision_point: true
1919
+ user_interaction: "ask_user_question"
1920
+ category: "core"
1921
+
1922
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1923
+ # State Validation Rules
1924
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1925
+ #
1926
+ # These rules validate that required state exists before
1927
+ # allowing workflow to proceed. Prevents silent failures
1928
+ # from missing prerequisites.
1929
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1930
+
1931
+ - id: "validate-koan-directories"
1932
+ description: "Ensure koan directories exist before workflow starts"
1933
+ when:
1934
+ event: "workflow.start"
1935
+ then:
1936
+ - action: "validate_state"
1937
+ checks:
1938
+ - type: "directory_exists"
1939
+ path: "koan/stories"
1940
+ on_missing: "create"
1941
+ - type: "directory_exists"
1942
+ path: "koan/architecture"
1943
+ on_missing: "create"
1944
+ - type: "directory_exists"
1945
+ path: "koan/implementations"
1946
+ on_missing: "create"
1947
+ - type: "directory_exists"
1948
+ path: "koan/reviews"
1949
+ on_missing: "create"
1950
+ - type: "directory_exists"
1951
+ path: "koan/provenance/actions"
1952
+ on_missing: "create"
1953
+ - type: "directory_exists"
1954
+ path: "koan/flows"
1955
+ on_missing: "create"
1956
+ provenance:
1957
+ reason: "Ensuring required koan directories exist"
1958
+ category: "validation"
1959
+
1960
+ - id: "validate-story-before-arch"
1961
+ description: "Ensure story state file exists before architecture"
1962
+ when:
1963
+ concept: "architecture"
1964
+ action: "design"
1965
+ status: "starting"
1966
+ where:
1967
+ query: "story.id != null"
1968
+ then:
1969
+ - action: "validate_state"
1970
+ checks:
1971
+ - type: "file_exists"
1972
+ path: "koan/stories/story-${story.id}.yaml"
1973
+ on_missing: "block"
1974
+ error_message: "Story state file not found. Run story.create first."
1975
+ - type: "field_not_empty"
1976
+ file: "koan/stories/story-${story.id}.yaml"
1977
+ field: "acceptance_criteria"
1978
+ on_empty: "warn"
1979
+ warning_message: "Story has no acceptance criteria. Architecture may be incomplete."
1980
+ provenance:
1981
+ reason: "Validating story prerequisites before architecture"
1982
+ category: "validation"
1983
+
1984
+ - id: "validate-arch-before-impl"
1985
+ description: "Ensure architecture state file exists before implementation"
1986
+ when:
1987
+ concept: "implementation"
1988
+ action: "generate"
1989
+ status: "starting"
1990
+ where:
1991
+ query: "architecture.id != null"
1992
+ then:
1993
+ - action: "validate_state"
1994
+ checks:
1995
+ - type: "file_exists"
1996
+ path: "koan/architecture/arch-${architecture.id}.yaml"
1997
+ on_missing: "block"
1998
+ error_message: "Architecture state file not found. Run architecture.design first."
1999
+ - type: "field_not_empty"
2000
+ file: "koan/architecture/arch-${architecture.id}.yaml"
2001
+ field: "decisions"
2002
+ on_empty: "block"
2003
+ error_message: "Architecture has no decisions. Cannot proceed with implementation."
2004
+ provenance:
2005
+ reason: "Validating architecture prerequisites before implementation"
2006
+ category: "validation"
2007
+
2008
+ - id: "validate-impl-before-quality"
2009
+ description: "Ensure implementation state exists before quality review"
2010
+ when:
2011
+ concept: "quality"
2012
+ action: "review|test"
2013
+ status: "starting"
2014
+ where:
2015
+ query: "implementation.id != null"
2016
+ then:
2017
+ - action: "validate_state"
2018
+ checks:
2019
+ - type: "file_exists"
2020
+ path: "koan/implementations/impl-${implementation.id}.yaml"
2021
+ on_missing: "block"
2022
+ error_message: "Implementation state file not found. Run implementation.generate first."
2023
+ - type: "field_not_empty"
2024
+ file: "koan/implementations/impl-${implementation.id}.yaml"
2025
+ field: "files_changed"
2026
+ on_empty: "block"
2027
+ error_message: "Implementation has no files changed. Nothing to review."
2028
+ provenance:
2029
+ reason: "Validating implementation prerequisites before quality review"
2030
+ category: "validation"
2031
+
2032
+ - id: "validate-quality-before-version"
2033
+ description: "Ensure quality checks passed before versioning"
2034
+ when:
2035
+ concept: "version"
2036
+ action: "commit"
2037
+ status: "starting"
2038
+ then:
2039
+ - action: "validate_state"
2040
+ checks:
2041
+ - type: "file_exists"
2042
+ path: "koan/reviews/review-${implementation.id}.yaml"
2043
+ on_missing: "block"
2044
+ error_message: "No quality review found. Run quality.review first."
2045
+ - type: "field_equals"
2046
+ file: "koan/reviews/review-${implementation.id}.yaml"
2047
+ field: "status"
2048
+ value: "approved"
2049
+ on_mismatch: "block"
2050
+ error_message: "Quality review not approved. Fix issues before committing."
2051
+ provenance:
2052
+ reason: "Validating quality approval before version commit"
2053
+ category: "validation"
2054
+
2055
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
2056
+ # Workflow Summary
2057
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
2058
+ #
2059
+ # Happy Path (with MCP Integration):
2060
+ # Story → Code Analysis → Architecture → Verification → Implementation → Test Gen → Quality → Coverage → Version
2061
+ # [MCP: ast-index, (2-pass) [MCP: test-gen] [PARALLEL] [MCP: test-gen]
2062
+ # semantic-rag] ↓ ↓
2063
+ # [block/revise] [auto-generated tests]
2064
+ # ↓ ↓
2065
+ # Architecture Revision ┌─────────────────────────┐
2066
+ # │ On test failure: │
2067
+ # │ MCP: execution-loop │
2068
+ # │ → self_debug │
2069
+ # │ → run_tests_with_repair │
2070
+ # │ → iterate until passing │
2071
+ # └─────────────────────────┘
2072
+ #
2073
+ # MCP Server Integration:
2074
+ # 1. ast-index + semantic-rag (Code Analysis Phase):
2075
+ # - find_symbol: Locate existing patterns
2076
+ # - semantic_search: Find similar implementations
2077
+ # - get_file_symbols: Understand structure
2078
+ #
2079
+ # 2. test-generator (After Implementation):
2080
+ # - generate_unit_tests: Auto-create tests for new code
2081
+ # - suggest_tests: Recommend integration tests
2082
+ # - find_untested_files: Identify coverage gaps
2083
+ # - analyze_coverage: Measure test coverage
2084
+ #
2085
+ # 3. execution-loop (On Test Failure):
2086
+ # - self_debug: Diagnose failure root cause
2087
+ # - run_tests_with_repair: Auto-fix and re-run
2088
+ # - iterative_refine: Multiple improvement passes
2089
+ # - Max 3 attempts before escalating to user
2090
+ #
2091
+ # Human-in-the-Loop Decision Points (WYSIWID):
2092
+ # - Ambiguous story (Phase 0) → Ask user for goal type + priority
2093
+ # - High risk architecture → Ask user: approve, revise, or cancel
2094
+ # - Coverage below target → Ask user: generate more tests, proceed, or view details
2095
+ # - Self-repair failed → Ask user: show errors, try different approach, or skip tests
2096
+ # - Cost budget exceeded → Ask user: continue, optimize, or cancel
2097
+ #
2098
+ # Verification Flow:
2099
+ # - Pass 1: Independent review of architecture
2100
+ # - Pass 2: Review with Pass 1 findings
2101
+ # - Consensus: Aggregate → approve/approve_with_notes/block/revise
2102
+ # - 39.7% accuracy improvement (research-backed)
2103
+ #
2104
+ # Error Paths:
2105
+ # - Verification blocks → Revise architecture with Opus
2106
+ # - High risk architecture → Human approval required
2107
+ # - Quality needs changes → Refactor
2108
+ # - Tests failed → MCP self-repair (up to 3 attempts) → Human if exhausted
2109
+ # - Coverage below target → User decision to generate more or proceed
2110
+ # - Budget exceeded → Human decision required
2111
+ #
2112
+ # Performance:
2113
+ # - With MCP: ~15-20 minutes (reduced by auto-test-gen and self-repair)
2114
+ # - Without MCP: ~25-30 minutes (manual test creation and debugging)
2115
+ # - Self-repair saves: ~5-10 minutes per failure cycle
2116
+ #
2117
+ # Cost (with MCP Integration):
2118
+ # - Story (Sonnet): $0.000175 (<1%)
2119
+ # - Code Analysis (MCP): $0.0002 (<1%) ← ast-index + semantic-rag
2120
+ # - Architecture (Opus): $0.015 (60%) ← Opus for deepest reasoning
2121
+ # - Verification 2x (Sonnet): $0.006175 (25%) ← 2 passes + consensus
2122
+ # - Test Generation (MCP): $0.0005 (2%) ← test-generator
2123
+ # - Implementation (Sonnet): $0.000175 (<1%)
2124
+ # - Quality 2x (Sonnet): $0.000350 (1%) ← Same cost parallel or sequential
2125
+ # - Self-Repair (MCP): $0.001 (4%) ← execution-loop (if needed)
2126
+ # - Coverage Analysis (MCP): $0.0002 (<1%) ← test-generator
2127
+ # - Version (Sonnet): $0.000175 (<1%)
2128
+ # - Total: $0.025 per feature (with MCP)
2129
+ #
2130
+ # MCP Graceful Degradation:
2131
+ # - All MCP integrations have fallback paths
2132
+ # - If MCP unavailable, workflow continues without that feature
2133
+ # - No hard dependency on MCP servers
2134
+ #
2135
+ # ROI:
2136
+ # - 39.7% accuracy improvement from verification
2137
+ # - ~50% reduction in manual test writing via auto-generation
2138
+ # - ~70% reduction in debugging time via self-repair
2139
+ # - +$0.003 per feature for MCP integration
2140
+ #
2141
+ # Phase 4 Enhancements (MCP Integration):
2142
+ # - Auto Test Generation: Tests created automatically after implementation
2143
+ # - Self-Repair Loop: Automatic debugging and fixing of test failures
2144
+ # - Coverage Analysis: Automatic coverage tracking and gap identification
2145
+ # - All MCP tools have graceful fallback to manual workflows