aicodeman 0.2.8 → 0.3.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 (348) hide show
  1. package/README.md +91 -0
  2. package/dist/ai-idle-checker.d.ts.map +1 -1
  3. package/dist/ai-idle-checker.js +3 -2
  4. package/dist/ai-idle-checker.js.map +1 -1
  5. package/dist/ai-plan-checker.d.ts.map +1 -1
  6. package/dist/ai-plan-checker.js +3 -2
  7. package/dist/ai-plan-checker.js.map +1 -1
  8. package/dist/bash-tool-parser.d.ts +2 -3
  9. package/dist/bash-tool-parser.d.ts.map +1 -1
  10. package/dist/bash-tool-parser.js +14 -31
  11. package/dist/bash-tool-parser.js.map +1 -1
  12. package/dist/config/ai-defaults.d.ts +16 -0
  13. package/dist/config/ai-defaults.d.ts.map +1 -0
  14. package/dist/config/ai-defaults.js +16 -0
  15. package/dist/config/ai-defaults.js.map +1 -0
  16. package/dist/config/auth-config.d.ts +19 -0
  17. package/dist/config/auth-config.d.ts.map +1 -0
  18. package/dist/config/auth-config.js +28 -0
  19. package/dist/config/auth-config.js.map +1 -0
  20. package/dist/config/exec-timeout.d.ts +10 -0
  21. package/dist/config/exec-timeout.d.ts.map +1 -0
  22. package/dist/config/exec-timeout.js +10 -0
  23. package/dist/config/exec-timeout.js.map +1 -0
  24. package/dist/config/map-limits.d.ts +4 -0
  25. package/dist/config/map-limits.d.ts.map +1 -1
  26. package/dist/config/map-limits.js +7 -0
  27. package/dist/config/map-limits.js.map +1 -1
  28. package/dist/config/server-timing.d.ts +36 -0
  29. package/dist/config/server-timing.d.ts.map +1 -0
  30. package/dist/config/server-timing.js +51 -0
  31. package/dist/config/server-timing.js.map +1 -0
  32. package/dist/config/team-config.d.ts +16 -0
  33. package/dist/config/team-config.d.ts.map +1 -0
  34. package/dist/config/team-config.js +16 -0
  35. package/dist/config/team-config.js.map +1 -0
  36. package/dist/config/terminal-limits.d.ts +18 -0
  37. package/dist/config/terminal-limits.d.ts.map +1 -0
  38. package/dist/config/terminal-limits.js +18 -0
  39. package/dist/config/terminal-limits.js.map +1 -0
  40. package/dist/config/tunnel-config.d.ts +27 -0
  41. package/dist/config/tunnel-config.d.ts.map +1 -0
  42. package/dist/config/tunnel-config.js +36 -0
  43. package/dist/config/tunnel-config.js.map +1 -0
  44. package/dist/hooks-config.d.ts.map +1 -1
  45. package/dist/hooks-config.js +7 -6
  46. package/dist/hooks-config.js.map +1 -1
  47. package/dist/image-watcher.d.ts +4 -4
  48. package/dist/image-watcher.d.ts.map +1 -1
  49. package/dist/image-watcher.js +17 -30
  50. package/dist/image-watcher.js.map +1 -1
  51. package/dist/index.js +1 -2
  52. package/dist/index.js.map +1 -1
  53. package/dist/plan-orchestrator.d.ts +2 -24
  54. package/dist/plan-orchestrator.d.ts.map +1 -1
  55. package/dist/plan-orchestrator.js.map +1 -1
  56. package/dist/push-store.d.ts +1 -1
  57. package/dist/push-store.d.ts.map +1 -1
  58. package/dist/push-store.js +4 -12
  59. package/dist/push-store.js.map +1 -1
  60. package/dist/ralph-fix-plan-watcher.d.ts +91 -0
  61. package/dist/ralph-fix-plan-watcher.d.ts.map +1 -0
  62. package/dist/ralph-fix-plan-watcher.js +326 -0
  63. package/dist/ralph-fix-plan-watcher.js.map +1 -0
  64. package/dist/ralph-plan-tracker.d.ts +201 -0
  65. package/dist/ralph-plan-tracker.d.ts.map +1 -0
  66. package/dist/ralph-plan-tracker.js +325 -0
  67. package/dist/ralph-plan-tracker.js.map +1 -0
  68. package/dist/ralph-stall-detector.d.ts +84 -0
  69. package/dist/ralph-stall-detector.d.ts.map +1 -0
  70. package/dist/ralph-stall-detector.js +139 -0
  71. package/dist/ralph-stall-detector.js.map +1 -0
  72. package/dist/ralph-status-parser.d.ts +141 -0
  73. package/dist/ralph-status-parser.d.ts.map +1 -0
  74. package/dist/ralph-status-parser.js +478 -0
  75. package/dist/ralph-status-parser.js.map +1 -0
  76. package/dist/ralph-tracker.d.ts +194 -685
  77. package/dist/ralph-tracker.d.ts.map +1 -1
  78. package/dist/ralph-tracker.js +349 -1713
  79. package/dist/ralph-tracker.js.map +1 -1
  80. package/dist/respawn-adaptive-timing.d.ts +61 -0
  81. package/dist/respawn-adaptive-timing.d.ts.map +1 -0
  82. package/dist/respawn-adaptive-timing.js +105 -0
  83. package/dist/respawn-adaptive-timing.js.map +1 -0
  84. package/dist/respawn-controller.d.ts +14 -101
  85. package/dist/respawn-controller.d.ts.map +1 -1
  86. package/dist/respawn-controller.js +155 -594
  87. package/dist/respawn-controller.js.map +1 -1
  88. package/dist/respawn-health.d.ts +54 -0
  89. package/dist/respawn-health.d.ts.map +1 -0
  90. package/dist/respawn-health.js +183 -0
  91. package/dist/respawn-health.js.map +1 -0
  92. package/dist/respawn-metrics.d.ts +81 -0
  93. package/dist/respawn-metrics.d.ts.map +1 -0
  94. package/dist/respawn-metrics.js +198 -0
  95. package/dist/respawn-metrics.js.map +1 -0
  96. package/dist/respawn-patterns.d.ts +45 -0
  97. package/dist/respawn-patterns.d.ts.map +1 -0
  98. package/dist/respawn-patterns.js +125 -0
  99. package/dist/respawn-patterns.js.map +1 -0
  100. package/dist/session-auto-ops.d.ts +89 -0
  101. package/dist/session-auto-ops.d.ts.map +1 -0
  102. package/dist/session-auto-ops.js +224 -0
  103. package/dist/session-auto-ops.js.map +1 -0
  104. package/dist/session-cli-builder.d.ts +62 -0
  105. package/dist/session-cli-builder.d.ts.map +1 -0
  106. package/dist/session-cli-builder.js +121 -0
  107. package/dist/session-cli-builder.js.map +1 -0
  108. package/dist/session-task-cache.d.ts +52 -0
  109. package/dist/session-task-cache.d.ts.map +1 -0
  110. package/dist/session-task-cache.js +90 -0
  111. package/dist/session-task-cache.js.map +1 -0
  112. package/dist/session.d.ts +2 -33
  113. package/dist/session.d.ts.map +1 -1
  114. package/dist/session.js +58 -309
  115. package/dist/session.js.map +1 -1
  116. package/dist/state-store.d.ts +9 -2
  117. package/dist/state-store.d.ts.map +1 -1
  118. package/dist/state-store.js +112 -39
  119. package/dist/state-store.js.map +1 -1
  120. package/dist/subagent-watcher.d.ts +16 -9
  121. package/dist/subagent-watcher.d.ts.map +1 -1
  122. package/dist/subagent-watcher.js +126 -147
  123. package/dist/subagent-watcher.js.map +1 -1
  124. package/dist/team-watcher.d.ts +3 -0
  125. package/dist/team-watcher.d.ts.map +1 -1
  126. package/dist/team-watcher.js +54 -5
  127. package/dist/team-watcher.js.map +1 -1
  128. package/dist/tmux-manager.d.ts.map +1 -1
  129. package/dist/tmux-manager.js +1 -2
  130. package/dist/tmux-manager.js.map +1 -1
  131. package/dist/tunnel-manager.d.ts +26 -0
  132. package/dist/tunnel-manager.d.ts.map +1 -1
  133. package/dist/tunnel-manager.js +127 -7
  134. package/dist/tunnel-manager.js.map +1 -1
  135. package/dist/types/api.d.ts +93 -0
  136. package/dist/types/api.d.ts.map +1 -0
  137. package/dist/types/api.js +83 -0
  138. package/dist/types/api.js.map +1 -0
  139. package/dist/types/app-state.d.ts +100 -0
  140. package/dist/types/app-state.d.ts.map +1 -0
  141. package/dist/types/app-state.js +59 -0
  142. package/dist/types/app-state.js.map +1 -0
  143. package/dist/types/common.d.ts +70 -0
  144. package/dist/types/common.d.ts.map +1 -0
  145. package/dist/types/common.js +8 -0
  146. package/dist/types/common.js.map +1 -0
  147. package/dist/types/index.d.ts +18 -0
  148. package/dist/types/index.d.ts.map +1 -0
  149. package/dist/types/index.js +18 -0
  150. package/dist/types/index.js.map +1 -0
  151. package/dist/types/lifecycle.d.ts +17 -0
  152. package/dist/types/lifecycle.d.ts.map +1 -0
  153. package/dist/types/lifecycle.js +5 -0
  154. package/dist/types/lifecycle.js.map +1 -0
  155. package/dist/types/plan.d.ts +32 -0
  156. package/dist/types/plan.d.ts.map +1 -0
  157. package/dist/types/plan.js +5 -0
  158. package/dist/types/plan.js.map +1 -0
  159. package/dist/types/push.d.ts +23 -0
  160. package/dist/types/push.d.ts.map +1 -0
  161. package/dist/types/push.js +5 -0
  162. package/dist/types/push.js.map +1 -0
  163. package/dist/types/ralph.d.ts +241 -0
  164. package/dist/types/ralph.d.ts.map +1 -0
  165. package/dist/types/ralph.js +49 -0
  166. package/dist/types/ralph.js.map +1 -0
  167. package/dist/types/respawn.d.ts +250 -0
  168. package/dist/types/respawn.d.ts.map +1 -0
  169. package/dist/types/respawn.js +5 -0
  170. package/dist/types/respawn.js.map +1 -0
  171. package/dist/types/run-summary.d.ts +81 -0
  172. package/dist/types/run-summary.d.ts.map +1 -0
  173. package/dist/types/run-summary.js +22 -0
  174. package/dist/types/run-summary.js.map +1 -0
  175. package/dist/types/session.d.ts +130 -0
  176. package/dist/types/session.d.ts.map +1 -0
  177. package/dist/types/session.js +5 -0
  178. package/dist/types/session.js.map +1 -0
  179. package/dist/types/task.d.ts +58 -0
  180. package/dist/types/task.d.ts.map +1 -0
  181. package/dist/types/task.js +5 -0
  182. package/dist/types/task.js.map +1 -0
  183. package/dist/types/teams.d.ts +55 -0
  184. package/dist/types/teams.d.ts.map +1 -0
  185. package/dist/types/teams.js +5 -0
  186. package/dist/types/teams.js.map +1 -0
  187. package/dist/types/tools.d.ts +46 -0
  188. package/dist/types/tools.d.ts.map +1 -0
  189. package/dist/types/tools.js +5 -0
  190. package/dist/types/tools.js.map +1 -0
  191. package/dist/types.d.ts +1 -1138
  192. package/dist/types.d.ts.map +1 -1
  193. package/dist/types.js +1 -214
  194. package/dist/types.js.map +1 -1
  195. package/dist/utils/claude-cli-resolver.d.ts.map +1 -1
  196. package/dist/utils/claude-cli-resolver.js +1 -2
  197. package/dist/utils/claude-cli-resolver.js.map +1 -1
  198. package/dist/utils/debouncer.d.ts +111 -0
  199. package/dist/utils/debouncer.d.ts.map +1 -0
  200. package/dist/utils/debouncer.js +162 -0
  201. package/dist/utils/debouncer.js.map +1 -0
  202. package/dist/utils/index.d.ts +3 -2
  203. package/dist/utils/index.d.ts.map +1 -1
  204. package/dist/utils/index.js +3 -2
  205. package/dist/utils/index.js.map +1 -1
  206. package/dist/utils/opencode-cli-resolver.d.ts.map +1 -1
  207. package/dist/utils/opencode-cli-resolver.js +1 -2
  208. package/dist/utils/opencode-cli-resolver.js.map +1 -1
  209. package/dist/utils/string-similarity.d.ts +0 -57
  210. package/dist/utils/string-similarity.d.ts.map +1 -1
  211. package/dist/utils/string-similarity.js +3 -18
  212. package/dist/utils/string-similarity.js.map +1 -1
  213. package/dist/web/middleware/auth.d.ts +31 -0
  214. package/dist/web/middleware/auth.d.ts.map +1 -0
  215. package/dist/web/middleware/auth.js +154 -0
  216. package/dist/web/middleware/auth.js.map +1 -0
  217. package/dist/web/ports/auth-port.d.ts +18 -0
  218. package/dist/web/ports/auth-port.d.ts.map +1 -0
  219. package/dist/web/ports/auth-port.js +6 -0
  220. package/dist/web/ports/auth-port.js.map +1 -0
  221. package/dist/web/ports/config-port.d.ts +28 -0
  222. package/dist/web/ports/config-port.d.ts.map +1 -0
  223. package/dist/web/ports/config-port.js +6 -0
  224. package/dist/web/ports/config-port.js.map +1 -0
  225. package/dist/web/ports/event-port.d.ts +13 -0
  226. package/dist/web/ports/event-port.d.ts.map +1 -0
  227. package/dist/web/ports/event-port.js +6 -0
  228. package/dist/web/ports/event-port.js.map +1 -0
  229. package/dist/web/ports/index.d.ts +14 -0
  230. package/dist/web/ports/index.d.ts.map +1 -0
  231. package/dist/web/ports/index.js +9 -0
  232. package/dist/web/ports/index.js.map +1 -0
  233. package/dist/web/ports/infra-port.d.ts +36 -0
  234. package/dist/web/ports/infra-port.d.ts.map +1 -0
  235. package/dist/web/ports/infra-port.js +6 -0
  236. package/dist/web/ports/infra-port.js.map +1 -0
  237. package/dist/web/ports/respawn-port.d.ts +20 -0
  238. package/dist/web/ports/respawn-port.d.ts.map +1 -0
  239. package/dist/web/ports/respawn-port.js +6 -0
  240. package/dist/web/ports/respawn-port.js.map +1 -0
  241. package/dist/web/ports/session-port.d.ts +15 -0
  242. package/dist/web/ports/session-port.d.ts.map +1 -0
  243. package/dist/web/ports/session-port.js +6 -0
  244. package/dist/web/ports/session-port.js.map +1 -0
  245. package/dist/web/public/api-client.js +70 -0
  246. package/dist/web/public/api-client.js.br +0 -0
  247. package/dist/web/public/api-client.js.gz +0 -0
  248. package/dist/web/public/app.js +152 -236
  249. package/dist/web/public/app.js.br +0 -0
  250. package/dist/web/public/app.js.gz +0 -0
  251. package/dist/web/public/constants.js +238 -0
  252. package/dist/web/public/constants.js.br +0 -0
  253. package/dist/web/public/constants.js.gz +0 -0
  254. package/dist/web/public/index.html +11 -3
  255. package/dist/web/public/index.html.br +0 -0
  256. package/dist/web/public/index.html.gz +0 -0
  257. package/dist/web/public/keyboard-accessory.js +279 -0
  258. package/dist/web/public/keyboard-accessory.js.br +0 -0
  259. package/dist/web/public/keyboard-accessory.js.gz +0 -0
  260. package/dist/web/public/mobile-handlers.js +467 -0
  261. package/dist/web/public/mobile-handlers.js.br +0 -0
  262. package/dist/web/public/mobile-handlers.js.gz +0 -0
  263. package/dist/web/public/mobile.css.gz +0 -0
  264. package/dist/web/public/notification-manager.js +445 -0
  265. package/dist/web/public/notification-manager.js.br +0 -0
  266. package/dist/web/public/notification-manager.js.gz +0 -0
  267. package/dist/web/public/ralph-wizard.js +3 -3
  268. package/dist/web/public/ralph-wizard.js.br +0 -0
  269. package/dist/web/public/ralph-wizard.js.gz +0 -0
  270. package/dist/web/public/styles.css.gz +0 -0
  271. package/dist/web/public/subagent-windows.js +1115 -0
  272. package/dist/web/public/subagent-windows.js.br +0 -0
  273. package/dist/web/public/subagent-windows.js.gz +0 -0
  274. package/dist/web/public/sw.js.gz +0 -0
  275. package/dist/web/public/upload.html.gz +0 -0
  276. package/dist/web/public/vendor/xterm-addon-fit.min.js.gz +0 -0
  277. package/dist/web/public/vendor/xterm-addon-unicode11.min.js.gz +0 -0
  278. package/dist/web/public/vendor/xterm-addon-webgl.min.js.gz +0 -0
  279. package/dist/web/public/vendor/xterm.css.gz +0 -0
  280. package/dist/web/public/vendor/xterm.min.js.gz +0 -0
  281. package/dist/web/public/voice-input.js +858 -0
  282. package/dist/web/public/voice-input.js.br +0 -0
  283. package/dist/web/public/voice-input.js.gz +0 -0
  284. package/dist/web/route-helpers.d.ts +38 -0
  285. package/dist/web/route-helpers.d.ts.map +1 -0
  286. package/dist/web/route-helpers.js +143 -0
  287. package/dist/web/route-helpers.js.map +1 -0
  288. package/dist/web/routes/case-routes.d.ts +9 -0
  289. package/dist/web/routes/case-routes.d.ts.map +1 -0
  290. package/dist/web/routes/case-routes.js +419 -0
  291. package/dist/web/routes/case-routes.js.map +1 -0
  292. package/dist/web/routes/file-routes.d.ts +8 -0
  293. package/dist/web/routes/file-routes.d.ts.map +1 -0
  294. package/dist/web/routes/file-routes.js +337 -0
  295. package/dist/web/routes/file-routes.js.map +1 -0
  296. package/dist/web/routes/hook-event-routes.d.ts +9 -0
  297. package/dist/web/routes/hook-event-routes.d.ts.map +1 -0
  298. package/dist/web/routes/hook-event-routes.js +57 -0
  299. package/dist/web/routes/hook-event-routes.js.map +1 -0
  300. package/dist/web/routes/index.d.ts +16 -0
  301. package/dist/web/routes/index.d.ts.map +1 -0
  302. package/dist/web/routes/index.js +16 -0
  303. package/dist/web/routes/index.js.map +1 -0
  304. package/dist/web/routes/mux-routes.d.ts +8 -0
  305. package/dist/web/routes/mux-routes.d.ts.map +1 -0
  306. package/dist/web/routes/mux-routes.js +32 -0
  307. package/dist/web/routes/mux-routes.js.map +1 -0
  308. package/dist/web/routes/plan-routes.d.ts +9 -0
  309. package/dist/web/routes/plan-routes.d.ts.map +1 -0
  310. package/dist/web/routes/plan-routes.js +381 -0
  311. package/dist/web/routes/plan-routes.js.map +1 -0
  312. package/dist/web/routes/push-routes.d.ts +8 -0
  313. package/dist/web/routes/push-routes.d.ts.map +1 -0
  314. package/dist/web/routes/push-routes.js +49 -0
  315. package/dist/web/routes/push-routes.js.map +1 -0
  316. package/dist/web/routes/ralph-routes.d.ts +9 -0
  317. package/dist/web/routes/ralph-routes.d.ts.map +1 -0
  318. package/dist/web/routes/ralph-routes.js +475 -0
  319. package/dist/web/routes/ralph-routes.js.map +1 -0
  320. package/dist/web/routes/respawn-routes.d.ts +8 -0
  321. package/dist/web/routes/respawn-routes.d.ts.map +1 -0
  322. package/dist/web/routes/respawn-routes.js +260 -0
  323. package/dist/web/routes/respawn-routes.js.map +1 -0
  324. package/dist/web/routes/scheduled-routes.d.ts +8 -0
  325. package/dist/web/routes/scheduled-routes.d.ts.map +1 -0
  326. package/dist/web/routes/scheduled-routes.js +51 -0
  327. package/dist/web/routes/scheduled-routes.js.map +1 -0
  328. package/dist/web/routes/session-routes.d.ts +9 -0
  329. package/dist/web/routes/session-routes.d.ts.map +1 -0
  330. package/dist/web/routes/session-routes.js +729 -0
  331. package/dist/web/routes/session-routes.js.map +1 -0
  332. package/dist/web/routes/system-routes.d.ts +9 -0
  333. package/dist/web/routes/system-routes.d.ts.map +1 -0
  334. package/dist/web/routes/system-routes.js +678 -0
  335. package/dist/web/routes/system-routes.js.map +1 -0
  336. package/dist/web/routes/team-routes.d.ts +8 -0
  337. package/dist/web/routes/team-routes.d.ts.map +1 -0
  338. package/dist/web/routes/team-routes.js +14 -0
  339. package/dist/web/routes/team-routes.js.map +1 -0
  340. package/dist/web/schemas.d.ts +43 -3
  341. package/dist/web/schemas.d.ts.map +1 -1
  342. package/dist/web/schemas.js +6 -2
  343. package/dist/web/schemas.js.map +1 -1
  344. package/dist/web/server.d.ts +10 -9
  345. package/dist/web/server.d.ts.map +1 -1
  346. package/dist/web/server.js +342 -3829
  347. package/dist/web/server.js.map +1 -1
  348. package/package.json +1 -1
@@ -10,66 +10,22 @@
10
10
  * patterns are detected in the output stream, reducing overhead for
11
11
  * sessions not using autonomous loops.
12
12
  *
13
+ * Composed of four sub-modules:
14
+ * - RalphPlanTracker: Plan task management, checkpoints, versioning
15
+ * - RalphFixPlanWatcher: @fix_plan.md file watching and parsing
16
+ * - RalphStallDetector: Iteration stall detection
17
+ * - RalphStatusParser: RALPH_STATUS block parsing, circuit breaker
18
+ *
13
19
  * @module ralph-tracker
14
20
  */
15
21
  import { EventEmitter } from 'node:events';
16
22
  import { RalphTrackerState, RalphTodoItem, RalphStatusBlock, CircuitBreakerStatus, RalphTodoProgress, CompletionConfidence, PlanTaskStatus, TddPhase } from './types.js';
17
- /**
18
- * Enhanced plan task with verification criteria, dependencies, and execution tracking.
19
- * Supports TDD workflow, failure tracking, and plan versioning.
20
- */
21
- export interface EnhancedPlanTask {
22
- /** Unique identifier (e.g., "P0-001") */
23
- id: string;
24
- /** Task description */
25
- content: string;
26
- /** Criticality level */
27
- priority: 'P0' | 'P1' | 'P2' | null;
28
- /** How to verify completion */
29
- verificationCriteria?: string;
30
- /** Command to run for verification */
31
- testCommand?: string;
32
- /** IDs of tasks that must complete first */
33
- dependencies: string[];
34
- /** Current execution status */
35
- status: PlanTaskStatus;
36
- /** How many times attempted */
37
- attempts: number;
38
- /** Most recent failure reason */
39
- lastError?: string;
40
- /** Timestamp of completion */
41
- completedAt?: number;
42
- /** Plan version this belongs to */
43
- version: number;
44
- /** TDD phase category */
45
- tddPhase?: TddPhase;
46
- /** ID of paired test/impl task */
47
- pairedWith?: string;
48
- /** Estimated complexity */
49
- complexity?: 'low' | 'medium' | 'high';
50
- /** Checklist items for review tasks (tddPhase: 'review') */
51
- reviewChecklist?: string[];
52
- }
53
- /** Checkpoint review data */
54
- export interface CheckpointReview {
55
- iteration: number;
56
- timestamp: number;
57
- summary: {
58
- total: number;
59
- completed: number;
60
- failed: number;
61
- blocked: number;
62
- pending: number;
63
- inProgress: number;
64
- };
65
- stuckTasks: Array<{
66
- id: string;
67
- content: string;
68
- attempts: number;
69
- lastError?: string;
70
- }>;
71
- recommendations: string[];
72
- }
23
+ import { RalphPlanTracker } from './ralph-plan-tracker.js';
24
+ import type { EnhancedPlanTask, CheckpointReview } from './ralph-plan-tracker.js';
25
+ import { RalphFixPlanWatcher } from './ralph-fix-plan-watcher.js';
26
+ import { RalphStallDetector } from './ralph-stall-detector.js';
27
+ import { RalphStatusParser } from './ralph-status-parser.js';
28
+ export type { EnhancedPlanTask, CheckpointReview } from './ralph-plan-tracker.js';
73
29
  /**
74
30
  * Events emitted by RalphTracker
75
31
  * @event loopUpdate - Fired when loop state changes (active, iteration, completion phrase)
@@ -136,6 +92,13 @@ export interface RalphTrackerEvents {
136
92
  * - 2nd occurrence: Emits `completionDetected` event (actual completion)
137
93
  * - If loop already active: Emits immediately on first occurrence
138
94
  *
95
+ * ## Sub-modules
96
+ *
97
+ * - `planTracker` - Plan task management, checkpoints, versioning
98
+ * - `fixPlanWatcher` - @fix_plan.md file watching and parsing
99
+ * - `stallDetector` - Iteration stall detection
100
+ * - `statusParser` - RALPH_STATUS block parsing, circuit breaker
101
+ *
139
102
  * ## Events
140
103
  *
141
104
  * - `loopUpdate` - Loop state changed (status, iteration, phrase)
@@ -154,6 +117,14 @@ export interface RalphTrackerEvents {
154
117
  * ```
155
118
  */
156
119
  export declare class RalphTracker extends EventEmitter {
120
+ /** Plan task management sub-module */
121
+ readonly planTracker: RalphPlanTracker;
122
+ /** @fix_plan.md file watcher sub-module */
123
+ readonly fixPlanWatcher: RalphFixPlanWatcher;
124
+ /** Iteration stall detector sub-module */
125
+ readonly stallDetector: RalphStallDetector;
126
+ /** RALPH_STATUS block parser and circuit breaker sub-module */
127
+ readonly statusParser: RalphStatusParser;
157
128
  /** Current state of the detected loop */
158
129
  private _loopState;
159
130
  /** Map of todo items by ID for O(1) lookup */
@@ -167,14 +138,10 @@ export declare class RalphTracker extends EventEmitter {
167
138
  private _completionPhraseCount;
168
139
  /** Timestamp of last cleanup check for throttling */
169
140
  private _lastCleanupTime;
170
- /** Debounce timer for todoUpdate events */
171
- private _todoUpdateTimer;
172
- /** Debounce timer for loopUpdate events */
173
- private _loopUpdateTimer;
174
- /** Flag indicating pending todoUpdate emission */
175
- private _todoUpdatePending;
176
- /** Flag indicating pending loopUpdate emission */
177
- private _loopUpdatePending;
141
+ /** Debouncer for todoUpdate events */
142
+ private _todoDeb;
143
+ /** Debouncer for loopUpdate events */
144
+ private _loopDeb;
178
145
  /** When true, prevents auto-enable on pattern detection */
179
146
  private _autoEnableDisabled;
180
147
  /** Maps task numbers from "✔ Task #N" format to their content for status updates */
@@ -187,59 +154,6 @@ export declare class RalphTracker extends EventEmitter {
187
154
  private _partialPromiseBuffer;
188
155
  /** Maximum size of partial promise buffer */
189
156
  private static readonly MAX_PARTIAL_PROMISE_SIZE;
190
- /** Circuit breaker state tracking */
191
- private _circuitBreaker;
192
- /** Buffer for RALPH_STATUS block lines */
193
- private _statusBlockBuffer;
194
- /** Flag indicating we're inside a RALPH_STATUS block */
195
- private _inStatusBlock;
196
- /** Last parsed RALPH_STATUS block */
197
- private _lastStatusBlock;
198
- /** Count of completion indicators detected (for dual-condition exit) */
199
- private _completionIndicators;
200
- /** Whether dual-condition exit gate has been met */
201
- private _exitGateMet;
202
- /** Cumulative files modified across all iterations */
203
- private _totalFilesModified;
204
- /** Cumulative tasks completed across all iterations */
205
- private _totalTasksCompleted;
206
- /** Working directory for @fix_plan.md watching */
207
- private _workingDir;
208
- /** File watcher for @fix_plan.md */
209
- private _fixPlanWatcher;
210
- /** Error handler for FSWatcher (stored for cleanup to prevent memory leak) */
211
- private _fixPlanWatcherErrorHandler;
212
- /** Debounce timer for file change events */
213
- private _fixPlanReloadTimer;
214
- /** Path to the @fix_plan.md file being watched */
215
- private _fixPlanPath;
216
- /**
217
- * When @fix_plan.md is active, treat it as the source of truth for todo status.
218
- * This prevents output-based detection from overriding file-based status.
219
- */
220
- private get isFileAuthoritative();
221
- /** Current version of the plan (incremented on changes) */
222
- private _planVersion;
223
- /** History of plan versions for rollback support */
224
- private _planHistory;
225
- /** Enhanced plan tasks with execution tracking */
226
- private _planTasks;
227
- /** Checkpoint intervals (iterations at which to trigger review) */
228
- private _checkpointIterations;
229
- /** Last checkpoint iteration */
230
- private _lastCheckpointIteration;
231
- /** Timestamp when iteration count last changed */
232
- private _lastIterationChangeTime;
233
- /** Last observed iteration count for stall detection */
234
- private _lastObservedIteration;
235
- /** Timer for iteration stall detection */
236
- private _iterationStallTimer;
237
- /** Iteration stall warning threshold (ms) - default 10 minutes */
238
- private _iterationStallWarningMs;
239
- /** Iteration stall critical threshold (ms) - default 20 minutes */
240
- private _iterationStallCriticalMs;
241
- /** Whether stall warning has been emitted */
242
- private _iterationStallWarned;
243
157
  /** Alternate completion phrases (P1-003: multi-phrase support) - Set for O(1) lookup */
244
158
  private _alternateCompletionPhrases;
245
159
  /** History of todo completion times (ms) for averaging */
@@ -250,595 +164,393 @@ export declare class RalphTracker extends EventEmitter {
250
164
  private _todosStartedAt;
251
165
  /** Map of todo ID to timestamp when it started (for duration tracking) */
252
166
  private _todoStartTimes;
167
+ /** Last calculated completion confidence */
168
+ private _lastCompletionConfidence;
169
+ /** Confidence threshold for triggering completion (0-100) */
170
+ private static readonly COMPLETION_CONFIDENCE_THRESHOLD;
253
171
  /**
254
172
  * Creates a new RalphTracker instance.
255
173
  * Starts in disabled state until Ralph patterns are detected.
256
174
  */
257
175
  constructor();
258
176
  /**
259
- * Add an alternate completion phrase (P1-003: multi-phrase support).
260
- * Multiple phrases can trigger completion (useful for complex workflows).
261
- * @param phrase - Additional phrase that can trigger completion
177
+ * Forward all sub-module events through RalphTracker
178
+ * so external consumers don't need to know about the split.
262
179
  */
263
- addAlternateCompletionPhrase(phrase: string): void;
180
+ private _wireSubModuleEvents;
264
181
  /**
265
- * Remove an alternate completion phrase.
266
- * @param phrase - Phrase to remove
182
+ * Initialize plan tasks from generated plan items.
267
183
  */
268
- removeAlternateCompletionPhrase(phrase: string): void;
184
+ initializePlanTasks(items: Array<{
185
+ id?: string;
186
+ content: string;
187
+ priority?: 'P0' | 'P1' | 'P2' | null;
188
+ verificationCriteria?: string;
189
+ testCommand?: string;
190
+ dependencies?: string[];
191
+ tddPhase?: TddPhase;
192
+ pairedWith?: string;
193
+ complexity?: 'low' | 'medium' | 'high';
194
+ }>): void;
269
195
  /**
270
- * Check if a phrase matches any valid completion phrase (primary or alternate).
271
- * @param phrase - Phrase to check
272
- * @returns True if phrase matches any valid completion phrase
196
+ * Update a specific plan task's status, attempts, or error.
273
197
  */
274
- isValidCompletionPhrase(phrase: string): boolean;
198
+ updatePlanTask(taskId: string, update: {
199
+ status?: PlanTaskStatus;
200
+ error?: string;
201
+ incrementAttempts?: boolean;
202
+ }): {
203
+ success: boolean;
204
+ task?: EnhancedPlanTask;
205
+ error?: string;
206
+ };
275
207
  /**
276
- * Find which completion phrase (primary or alternate) matches the given phrase.
277
- * @param phrase - Phrase to check
278
- * @returns The matched canonical phrase, or null if no match
208
+ * Add a new task to the plan.
279
209
  */
280
- private findMatchingCompletionPhrase;
210
+ addPlanTask(task: {
211
+ content: string;
212
+ priority?: 'P0' | 'P1' | 'P2';
213
+ verificationCriteria?: string;
214
+ dependencies?: string[];
215
+ insertAfter?: string;
216
+ }): {
217
+ task: EnhancedPlanTask;
218
+ };
281
219
  /**
282
- * Prevent auto-enable from pattern detection.
283
- * Use this when the user has explicitly disabled the Ralph tracker.
220
+ * Get all plan tasks.
284
221
  */
285
- disableAutoEnable(): void;
222
+ getPlanTasks(): EnhancedPlanTask[];
286
223
  /**
287
- * Allow auto-enable from pattern detection.
224
+ * Generate a checkpoint review.
288
225
  */
289
- enableAutoEnable(): void;
226
+ generateCheckpointReview(): CheckpointReview;
290
227
  /**
291
- * Whether auto-enable is disabled.
228
+ * Get plan version history.
292
229
  */
293
- get autoEnableDisabled(): boolean;
230
+ getPlanHistory(): Array<{
231
+ version: number;
232
+ timestamp: number;
233
+ summary: string;
234
+ stats: {
235
+ total: number;
236
+ completed: number;
237
+ failed: number;
238
+ };
239
+ }>;
240
+ /**
241
+ * Rollback to a previous plan version.
242
+ */
243
+ rollbackToVersion(version: number): {
244
+ success: boolean;
245
+ plan?: EnhancedPlanTask[];
246
+ error?: string;
247
+ };
248
+ /**
249
+ * Check if checkpoint review is due.
250
+ */
251
+ isCheckpointDue(): boolean;
252
+ /**
253
+ * Get current plan version.
254
+ */
255
+ get planVersion(): number;
294
256
  /**
295
257
  * Set the working directory and start watching @fix_plan.md.
296
- * Automatically loads existing @fix_plan.md if present.
297
258
  * @param workingDir - The session's working directory
298
259
  */
299
260
  setWorkingDir(workingDir: string): void;
300
261
  /**
301
262
  * Load @fix_plan.md from disk if it exists.
302
- * Called on initialization and when file changes are detected.
303
263
  */
304
264
  loadFixPlanFromDisk(): Promise<number>;
305
265
  /**
306
- * Start watching @fix_plan.md for changes.
307
- * Reloads todos when the file is modified.
266
+ * Stop watching @fix_plan.md.
308
267
  */
309
- private startWatchingFixPlan;
268
+ stopWatchingFixPlan(): void;
310
269
  /**
311
- * Handle @fix_plan.md file change with debouncing.
270
+ * When @fix_plan.md is active, treat it as the source of truth for todo status.
312
271
  */
313
- private handleFixPlanChange;
272
+ get isFileAuthoritative(): boolean;
314
273
  /**
315
- * Stop watching @fix_plan.md.
274
+ * Generate @fix_plan.md content from current todos.
316
275
  */
317
- stopWatchingFixPlan(): void;
276
+ generateFixPlanMarkdown(): string;
277
+ /**
278
+ * Parse @fix_plan.md content and import todos.
279
+ * Replaces current todos with imported ones.
280
+ *
281
+ * @param content - Markdown content from @fix_plan.md
282
+ * @returns Number of todos imported
283
+ */
284
+ importFixPlanMarkdown(content: string): number;
285
+ /**
286
+ * Start iteration stall detection timer.
287
+ */
288
+ startIterationStallDetection(): void;
289
+ /**
290
+ * Stop iteration stall detection timer.
291
+ */
292
+ stopIterationStallDetection(): void;
293
+ /**
294
+ * Get iteration stall metrics for monitoring.
295
+ */
296
+ getIterationStallMetrics(): {
297
+ lastIterationChangeTime: number;
298
+ stallDurationMs: number;
299
+ warningThresholdMs: number;
300
+ criticalThresholdMs: number;
301
+ isWarned: boolean;
302
+ currentIteration: number;
303
+ };
304
+ /**
305
+ * Configure iteration stall thresholds.
306
+ */
307
+ configureIterationStallThresholds(warningMs: number, criticalMs: number): void;
308
+ /**
309
+ * Manually reset circuit breaker to CLOSED state.
310
+ * @fires circuitBreakerUpdate
311
+ */
312
+ resetCircuitBreaker(): void;
313
+ /**
314
+ * Get current circuit breaker status.
315
+ */
316
+ get circuitBreakerStatus(): CircuitBreakerStatus;
317
+ /**
318
+ * Get last parsed RALPH_STATUS block.
319
+ */
320
+ get lastStatusBlock(): RalphStatusBlock | null;
321
+ /**
322
+ * Get cumulative stats from status blocks.
323
+ */
324
+ get cumulativeStats(): {
325
+ filesModified: number;
326
+ tasksCompleted: number;
327
+ completionIndicators: number;
328
+ };
329
+ /**
330
+ * Whether dual-condition exit gate has been met.
331
+ */
332
+ get exitGateMet(): boolean;
333
+ /**
334
+ * Add an alternate completion phrase (P1-003: multi-phrase support).
335
+ */
336
+ addAlternateCompletionPhrase(phrase: string): void;
337
+ /**
338
+ * Remove an alternate completion phrase.
339
+ */
340
+ removeAlternateCompletionPhrase(phrase: string): void;
341
+ /**
342
+ * Check if a phrase matches any valid completion phrase (primary or alternate).
343
+ */
344
+ isValidCompletionPhrase(phrase: string): boolean;
345
+ /**
346
+ * Find which completion phrase (primary or alternate) matches the given phrase.
347
+ */
348
+ private findMatchingCompletionPhrase;
349
+ /**
350
+ * Prevent auto-enable from pattern detection.
351
+ */
352
+ disableAutoEnable(): void;
353
+ /**
354
+ * Allow auto-enable from pattern detection.
355
+ */
356
+ enableAutoEnable(): void;
357
+ /**
358
+ * Whether auto-enable is disabled.
359
+ */
360
+ get autoEnableDisabled(): boolean;
318
361
  /**
319
362
  * Whether the tracker is enabled and actively monitoring output.
320
- * Disabled by default; auto-enables when Ralph patterns detected.
321
- * @returns True if tracker is processing terminal data
322
363
  */
323
364
  get enabled(): boolean;
324
365
  /**
325
366
  * Enable the tracker to start monitoring terminal output.
326
- * Called automatically when Ralph patterns are detected.
327
- * Emits 'enabled' event when transitioning from disabled state.
328
367
  * @fires enabled
329
368
  * @fires loopUpdate
330
369
  */
331
370
  enable(): void;
332
371
  /**
333
372
  * Disable the tracker to stop monitoring terminal output.
334
- * Terminal data will be ignored until re-enabled.
335
373
  * @fires loopUpdate
336
374
  */
337
375
  disable(): void;
338
376
  /**
339
377
  * Soft reset - clears state but keeps enabled status.
340
- * Use when a new task/loop starts within the same session.
341
- *
342
- * Clears:
343
- * - All todo items
344
- * - Completion phrase tracking
345
- * - Loop state (active, iterations)
346
- * - Line buffer
347
- *
348
- * Preserves:
349
- * - Enabled status
350
- *
351
378
  * @fires loopUpdate
352
379
  * @fires todoUpdate
353
380
  */
354
381
  reset(): void;
355
382
  /**
356
383
  * Full reset - clears all state including enabled status.
357
- * Use when session is closed or completely cleared.
358
- * Returns tracker to initial disabled state.
359
384
  * @fires loopUpdate
360
385
  * @fires todoUpdate
361
386
  */
362
387
  fullReset(): void;
363
388
  /**
364
389
  * Clear all debounce timers.
365
- * Called during reset/fullReset to prevent stale emissions.
366
390
  */
367
391
  private clearDebounceTimers;
368
392
  /**
369
393
  * Emit todoUpdate event with debouncing.
370
- * Batches rapid consecutive calls to reduce UI jitter.
371
- * The event fires after EVENT_DEBOUNCE_MS of inactivity.
372
394
  */
373
395
  private emitTodoUpdateDebounced;
374
396
  /**
375
397
  * Emit loopUpdate event with debouncing.
376
- * Batches rapid consecutive calls to reduce UI jitter.
377
- * The event fires after EVENT_DEBOUNCE_MS of inactivity.
378
398
  */
379
399
  private emitLoopUpdateDebounced;
380
400
  /**
381
401
  * Flush all pending debounced events immediately.
382
- * Useful for testing or when immediate state sync is needed.
383
402
  */
384
403
  flushPendingEvents(): void;
385
404
  /**
386
405
  * Get a copy of the current loop state.
387
- * @returns Shallow copy of loop state (safe to modify)
388
- */
389
- /**
390
- * Start iteration stall detection timer.
391
- * Should be called when the loop becomes active.
392
- */
393
- startIterationStallDetection(): void;
394
- /**
395
- * Stop iteration stall detection timer.
396
- */
397
- stopIterationStallDetection(): void;
398
- /**
399
- * Check for iteration stall and emit appropriate events.
400
- */
401
- private checkIterationStall;
402
- /**
403
- * Get iteration stall metrics for monitoring.
404
406
  */
405
- getIterationStallMetrics(): {
406
- lastIterationChangeTime: number;
407
- stallDurationMs: number;
408
- warningThresholdMs: number;
409
- criticalThresholdMs: number;
410
- isWarned: boolean;
411
- currentIteration: number;
412
- };
413
- /**
414
- * Configure iteration stall thresholds.
415
- * @param warningMs - Warning threshold in milliseconds
416
- * @param criticalMs - Critical threshold in milliseconds
417
- */
418
- configureIterationStallThresholds(warningMs: number, criticalMs: number): void;
419
407
  get loopState(): RalphTrackerState;
420
- /** Last calculated completion confidence */
421
- private _lastCompletionConfidence;
422
- /** Confidence threshold for triggering completion (0-100) */
423
- private static readonly COMPLETION_CONFIDENCE_THRESHOLD;
424
408
  /**
425
409
  * Calculate confidence score for a potential completion signal.
426
- *
427
- * Scoring weights:
428
- * - Promise tag with proper format: +30
429
- * - Matches expected phrase: +25
430
- * - All todos complete: +20
431
- * - EXIT_SIGNAL: true: +15
432
- * - Multiple completion indicators (>=2): +10
433
- * - Context appropriate (not in prompt/explanation): +10
434
- * - Loop was explicitly active: +10
435
- *
436
- * @param phrase - The detected phrase to evaluate
437
- * @param context - Optional surrounding context for the phrase
438
- * @returns CompletionConfidence assessment
439
410
  */
440
411
  calculateCompletionConfidence(phrase: string, context?: string): CompletionConfidence;
441
412
  /**
442
413
  * Get all tracked todo items as an array.
443
- * @returns Array of todo items (copy, safe to modify)
444
414
  */
445
415
  get todos(): RalphTodoItem[];
446
416
  /**
447
417
  * Process raw terminal data to detect inner loop patterns.
448
- *
449
- * This is the main entry point for parsing output. Call this with each
450
- * chunk of data from the PTY. The tracker will:
451
- *
452
- * 1. Strip ANSI escape codes
453
- * 2. Auto-enable if disabled and Ralph patterns detected
454
- * 3. Buffer data and process complete lines
455
- * 4. Detect loop status, todos, and completion phrases
456
- * 5. Periodically clean up expired todos
457
- *
458
- * @param data - Raw terminal data (may include ANSI codes)
459
- * @fires loopUpdate - When loop state changes
460
- * @fires todoUpdate - When todos are detected or updated
461
- * @fires completionDetected - When completion phrase found
462
- * @fires enabled - When tracker auto-enables
463
418
  */
464
419
  processTerminalData(data: string): void;
465
420
  /**
466
421
  * Process pre-stripped terminal data (ANSI codes already removed).
467
- * Use this when the caller has already stripped ANSI to avoid redundant regex work.
468
422
  */
469
423
  processCleanData(cleanData: string): void;
470
424
  /**
471
425
  * Check if data contains patterns that should auto-enable the tracker.
472
- *
473
- * The tracker auto-enables when any of these patterns are detected:
474
- * - `/ralph-loop:ralph-loop` command
475
- * - `<promise>PHRASE</promise>` completion tags
476
- * - TodoWrite tool usage indicators
477
- * - Iteration patterns (`Iteration 5/50`, `[5/50]`)
478
- * - Todo checkboxes (`- [ ]`, `- [x]`)
479
- * - Todo indicator icons (`☐`, `◐`, `☒`)
480
- * - Loop start messages (`Loop started at`)
481
- * - All tasks complete announcements
482
- * - Task completion signals
483
- *
484
- * @param data - ANSI-cleaned terminal data
485
- * @returns True if any Ralph-related pattern is detected
486
426
  */
487
427
  private shouldAutoEnable;
488
428
  /**
489
429
  * Process a single line of terminal output.
490
- * Runs all detection methods in sequence.
491
- * @param line - Single line of ANSI-cleaned terminal output
492
430
  */
493
431
  private processLine;
494
432
  /**
495
433
  * Detect "all tasks complete" messages.
496
- *
497
- * When a valid "all complete" message is detected:
498
- * 1. Marks all tracked todos as completed
499
- * 2. Emits completion event if a completion phrase is set
500
- *
501
- * Validation criteria:
502
- * - Line must match ALL_COMPLETE_PATTERN
503
- * - Line must be reasonably short (<100 chars) to avoid matching commentary
504
- * - Must not look like prompt text (no "output:" or `<promise>`)
505
- * - Must have at least one tracked todo
506
- * - If count is mentioned, should roughly match tracked todo count
507
- *
508
- * @param line - Single line to check
509
- * @fires todoUpdate - If any todos marked complete
510
- * @fires completionDetected - If completion phrase was set
511
- * @fires loopUpdate - If loop state changes
512
434
  */
513
435
  private detectAllTasksComplete;
514
436
  /**
515
- * Detect individual task completion signals
516
- * e.g., "Task 8 is done", "marked as completed"
517
- *
518
- * NOTE: This is intentionally conservative to avoid jitter.
519
- * Only marks a todo complete if we can match it by task number.
437
+ * Detect individual task completion signals.
520
438
  */
521
439
  private detectTaskCompletion;
522
440
  /**
523
441
  * Check for multi-line patterns that might span line boundaries.
524
- * Completion phrases can be split across PTY chunks.
525
- *
526
- * Handles cross-chunk promise tags by:
527
- * 1. Checking combined buffer + new data for complete tags
528
- * 2. Detecting partial tags at end of chunk and buffering
529
- * 3. Clearing buffer when complete tag found or buffer gets stale
530
- *
531
- * @param data - The full data chunk (may contain multiple lines)
532
442
  */
533
443
  private checkMultiLinePatterns;
534
444
  /**
535
445
  * Detect completion phrases in a line.
536
- *
537
- * Handles two formats:
538
- * 1. Tagged: `<promise>PHRASE</promise>` - Processed via handleCompletionPhrase
539
- * 2. Bare: Just `PHRASE` - Only if we already know the expected phrase
540
- *
541
- * Bare phrase detection avoids false positives by requiring:
542
- * - The phrase was previously seen in tagged form
543
- * - Line is standalone or ends with the phrase
544
- * - Line doesn't look like prompt context
545
- *
546
- * @param line - Single line to check
547
446
  */
548
447
  private detectCompletionPhrase;
549
448
  /**
550
449
  * Handle a bare completion phrase (without XML tags).
551
- *
552
- * Only fires completion if:
553
- * 1. The phrase was previously seen in tagged form (from prompt)
554
- * 2. This is the first bare occurrence (prevents double-firing)
555
- *
556
- * When triggered:
557
- * - Marks all todos as complete
558
- * - Emits completionDetected event
559
- * - Sets loop to inactive
560
- *
561
- * @param phrase - The completion phrase text
562
- * @fires todoUpdate - If any todos marked complete
563
- * @fires completionDetected - When completion triggered
564
- * @fires loopUpdate - When loop state changes
565
450
  */
566
451
  private handleBareCompletionPhrase;
567
452
  /**
568
- * Handle a detected completion phrase
569
- *
570
- * Uses occurrence-based detection combined with confidence scoring
571
- * to distinguish prompt from actual completion:
572
- * - 1st occurrence: Store as expected phrase (likely in prompt)
573
- * - 2nd occurrence OR high confidence: Emit completionDetected (actual completion)
574
- * - If loop already active: Emit immediately (explicit loop start)
453
+ * Handle a detected completion phrase.
575
454
  */
576
455
  private handleCompletionPhrase;
577
456
  /**
578
457
  * Check if two phrases match with fuzzy tolerance.
579
- * Handles variations in:
580
- * - Case (COMPLETE vs Complete)
581
- * - Whitespace (TASK_DONE vs TASK DONE)
582
- * - Separators (TASK_DONE vs TASK-DONE)
583
- * - Minor typos with Levenshtein distance (COMPLET vs COMPLETE)
584
- *
585
- * @param phrase1 - First phrase to compare
586
- * @param phrase2 - Second phrase to compare
587
- * @param maxDistance - Maximum edit distance for fuzzy match (default: 2)
588
- * @returns True if phrases are fuzzy-equal
589
458
  */
590
459
  private isFuzzyPhraseMatch;
591
460
  /**
592
461
  * Validate a completion phrase and emit warnings if it's risky.
593
- *
594
- * P1-002: Configurable false positive prevention
595
- *
596
- * Checks for:
597
- * - Common/generic phrases (DONE, COMPLETE, etc.)
598
- * - Short phrases (< MIN_RECOMMENDED_PHRASE_LENGTH)
599
- * - Numeric-only phrases
600
- *
601
- * @param phrase - The completion phrase to validate
602
- * @fires phraseValidationWarning - When a risky phrase is detected
603
462
  */
604
463
  private validateCompletionPhrase;
605
464
  /**
606
465
  * Activate the loop if not already active.
607
- *
608
- * Sets loop state to active and initializes counters.
609
- * No-op if loop is already active.
610
- *
611
- * @returns True if loop was activated, false if already active
612
- * @fires loopUpdate - When loop state changes
613
466
  */
614
467
  private activateLoopIfNeeded;
615
468
  /**
616
469
  * Detect loop start and status indicators.
617
- *
618
- * Patterns detected:
619
- * - Ralph loop start commands (`/ralph-loop:ralph-loop`)
620
- * - Loop start messages (`Loop started at`, `Starting Ralph loop`)
621
- * - Max iterations setting (`max-iterations 50`)
622
- * - Iteration progress (`Iteration 5/50`, `[5/50]`)
623
- * - Elapsed time (`Elapsed: 2.5 hours`)
624
- * - Cycle count (`cycle #5`, `respawn cycle #3`)
625
- * - TodoWrite tool usage
626
- *
627
- * @param line - Single line to check
628
- * @fires loopUpdate - When any loop state changes
629
470
  */
630
471
  private detectLoopStatus;
631
472
  /**
632
473
  * Detect todo items in various formats from Claude Code output.
633
- *
634
- * Supported formats:
635
- * - Format 1: Checkbox markdown (`- [ ] Task`, `- [x] Task`)
636
- * - Format 2: Indicator icons (`Todo: ☐ Task`, `Todo: ✓ Task`)
637
- * - Format 3: Status in parentheses (`- Task (pending)`)
638
- * - Format 4: Native TodoWrite (`☐ Task`, `☒ Task`, `◐ Task`)
639
- *
640
- * Uses quick pre-check to skip lines that can't contain todos.
641
- * Excludes tool invocations and Claude commentary patterns.
642
- *
643
- * @param line - Single line to check
644
- * @fires todoUpdate - When any todos are detected or updated
645
474
  */
646
475
  private detectTodoItems;
647
476
  /**
648
477
  * Convert a todo icon character to its corresponding status.
649
- *
650
- * Icon mappings:
651
- * - Completed: `✓`, `✅`, `☒`, `◉`, `●`
652
- * - In Progress: `◐`, `⏳`, `⌛`, `🔄`
653
- * - Pending: `☐`, `○`, and anything else (default)
654
- *
655
- * @param icon - Single character icon
656
- * @returns Corresponding RalphTodoStatus
657
478
  */
658
479
  private iconToStatus;
659
480
  /**
660
481
  * Parse priority from todo content.
661
- * P1-008: Enhanced keyword-based priority inference.
662
- *
663
- * Priority levels:
664
- * - P0 (Critical): Explicit P0, "critical", "blocker", "urgent", "security", "crash", "broken"
665
- * - P1 (High): Explicit P1, "important", "high priority", "bug", "fix", "error", "fail"
666
- * - P2 (Medium): Explicit P2, "nice to have", "low priority", "refactor", "cleanup", "improve"
667
- *
668
- * @param content - Todo content text
669
- * @returns Parsed priority level or null
670
482
  */
671
483
  private parsePriority;
672
484
  /**
673
485
  * Add a new todo item or update an existing one.
674
- *
675
- * Behavior:
676
- * - Content is cleaned (ANSI removed, whitespace collapsed)
677
- * - Content under 5 chars is skipped
678
- * - ID is generated from normalized content (stable hash)
679
- * - Priority is parsed from content (P0/P1/P2, Critical, High Priority, etc.)
680
- * - Existing item: Updates status and timestamp
681
- * - New item: Adds to map, evicts oldest if at MAX_TODOS_PER_SESSION
682
- *
683
- * @param content - Raw todo content text
684
- * @param status - Status to set
685
486
  */
686
487
  private upsertTodo;
687
488
  /**
688
489
  * Normalize todo content for consistent matching.
689
- *
690
- * Normalization steps:
691
- * 1. Collapse multiple whitespace to single space
692
- * 2. Remove special characters (keep alphanumeric + basic punctuation)
693
- * 3. Trim whitespace
694
- * 4. Convert to lowercase
695
- *
696
- * This prevents duplicate todos from terminal rendering artifacts.
697
- *
698
- * @param content - Raw todo content
699
- * @returns Normalized lowercase string
700
490
  */
701
491
  private normalizeTodoContent;
702
492
  /**
703
493
  * Calculate similarity between two strings.
704
- *
705
- * P1-007: Uses a hybrid approach combining:
706
- * 1. Levenshtein-based similarity for edit-distance tolerance
707
- * 2. Bigram (Dice coefficient) for reordering tolerance
708
- * Returns the maximum of both methods.
709
- *
710
- * @param str1 - First string (will be normalized)
711
- * @param str2 - Second string (will be normalized)
712
- * @returns Similarity score from 0.0 (no similarity) to 1.0 (identical)
713
494
  */
714
495
  private calculateSimilarity;
715
496
  /**
716
497
  * Calculate bigram (Dice coefficient) similarity.
717
- * Good for detecting near-duplicates with word reordering.
718
- *
719
- * @param norm1 - First normalized string
720
- * @param norm2 - Second normalized string
721
- * @returns Similarity score from 0.0 to 1.0
722
498
  */
723
499
  private calculateBigramSimilarity;
724
500
  /**
725
501
  * Find an existing todo that is similar to the given content.
726
- * Returns the most similar todo if similarity >= threshold.
727
- *
728
- * Deduplication is intentionally conservative:
729
- * - Short strings (< 30 chars): require 95% similarity (nearly identical)
730
- * - Medium strings (30-60 chars): require 90% similarity
731
- * - Longer strings: use default 85% threshold
732
- *
733
- * This prevents over-aggressive deduplication of brief, numbered items
734
- * like "Task 1", "Task 2" while still catching true duplicates.
735
- *
736
- * @param content - New todo content to check against existing todos
737
- * @returns Similar todo item if found, undefined otherwise
738
502
  */
739
503
  private findSimilarTodo;
740
504
  /**
741
505
  * Estimate complexity of a todo based on content keywords.
742
- * Used for duration estimation.
743
- *
744
- * @param content - Todo content text
745
- * @returns Complexity category
746
506
  */
747
507
  private estimateComplexity;
748
508
  /**
749
509
  * Get estimated duration for a complexity level (ms).
750
- * Based on historical patterns from similar tasks.
751
- *
752
- * @param complexity - Complexity category
753
- * @returns Estimated duration in milliseconds
754
510
  */
755
511
  private getEstimatedDuration;
756
512
  /**
757
513
  * Get average completion time from historical data.
758
- * @returns Average time in ms, or null if no data
759
514
  */
760
515
  private getAverageCompletionTime;
761
516
  /**
762
517
  * Record a todo completion for progress tracking.
763
- * @param todoId - ID of the completed todo
764
518
  */
765
519
  private recordTodoCompletion;
766
520
  /**
767
521
  * Start tracking a todo for duration estimation.
768
- * @param todoId - ID of the todo being started
769
522
  */
770
523
  private startTrackingTodo;
771
524
  /**
772
525
  * Get progress estimation for the todo list.
773
- * P1-009: Provides completion percentage, estimated remaining time,
774
- * and projected completion timestamp.
775
- *
776
- * @returns Progress estimation object
777
526
  */
778
527
  getTodoProgress(): RalphTodoProgress;
779
- /**
780
- * Generate a stable ID from todo content using djb2 hash.
781
- *
782
- * Uses the djb2 hash algorithm for good distribution across strings.
783
- * Content is normalized first to prevent duplicates from terminal artifacts.
784
- *
785
- * @param content - Todo content text
786
- * @returns Stable ID in format `todo-{hash}` (base36 encoded)
787
- */
788
528
  /**
789
529
  * Generate a stable ID from todo content using content hashing.
790
- *
791
- * P1-007: Uses centralized todoContentHash utility for consistency
792
- * with deduplication logic.
793
- *
794
- * @param content - Todo content text
795
- * @returns Unique ID string prefixed with "todo-"
796
530
  */
797
531
  private generateTodoId;
798
532
  /**
799
533
  * Find the todo item with the oldest detectedAt timestamp.
800
- * Used for LRU eviction when at MAX_TODOS_PER_SESSION limit.
801
- * @returns Oldest todo item, or undefined if map is empty
802
534
  */
803
535
  private findOldestTodo;
804
536
  /**
805
537
  * Conditionally run cleanup, throttled to CLEANUP_THROTTLE_MS.
806
- * Prevents cleanup from running on every data chunk (performance).
807
538
  */
808
539
  private maybeCleanupExpiredTodos;
809
540
  /**
810
541
  * Remove todo items older than TODO_EXPIRY_MS.
811
- * Emits todoUpdate if any items were removed.
812
- * @fires todoUpdate - When expired items are removed
813
542
  */
814
543
  private cleanupExpiredTodos;
815
544
  /**
816
545
  * Programmatically start a loop (external API).
817
- *
818
- * Use when starting a loop from outside terminal detection,
819
- * such as from a user action or API call.
820
- *
821
- * Automatically enables the tracker if not already enabled.
822
- *
823
- * @param completionPhrase - Optional phrase that signals completion
824
- * @param maxIterations - Optional maximum iteration count
825
- * @fires enabled - If tracker was disabled
826
- * @fires loopUpdate - When loop state changes
827
546
  */
828
547
  startLoop(completionPhrase?: string, maxIterations?: number): void;
829
548
  /**
830
549
  * Update the maximum iteration count (external API).
831
- *
832
- * @param maxIterations - New max iterations, or null to remove limit
833
- * @fires loopUpdate - When loop state changes
834
550
  */
835
551
  setMaxIterations(maxIterations: number | null): void;
836
552
  /**
837
- * Configure the tracker from external state (e.g. ralph plugin config).
838
- * Only updates fields that are provided, leaving others unchanged.
839
- *
840
- * @param config - Partial configuration to apply
841
- * @fires loopUpdate - When loop state changes
553
+ * Configure the tracker from external state.
842
554
  */
843
555
  configure(config: {
844
556
  enabled?: boolean;
@@ -847,36 +559,18 @@ export declare class RalphTracker extends EventEmitter {
847
559
  }): void;
848
560
  /**
849
561
  * Programmatically stop the loop (external API).
850
- *
851
- * Sets loop to inactive. Does not disable the tracker
852
- * or clear todos - use reset() or clear() for that.
853
- *
854
- * @fires loopUpdate - When loop state changes
855
562
  */
856
563
  stopLoop(): void;
857
564
  /**
858
565
  * Enforce size limit on _taskNumberToContent map.
859
- * Removes lowest task numbers (oldest tasks) when limit exceeded.
860
566
  */
861
567
  private enforceTaskMappingLimit;
862
568
  /**
863
569
  * Clear all state and disable the tracker.
864
- *
865
- * Use when the session is cleared or closed.
866
- * Resets everything to initial disabled state.
867
- *
868
- * @fires loopUpdate - With initial state
869
- * @fires todoUpdate - With empty array
870
570
  */
871
571
  clear(): void;
872
572
  /**
873
573
  * Get aggregated statistics about tracked todos.
874
- *
875
- * @returns Object with counts by status:
876
- * - total: Total number of tracked todos
877
- * - pending: Todos not yet started
878
- * - inProgress: Todos currently in progress
879
- * - completed: Finished todos
880
574
  */
881
575
  getTodoStats(): {
882
576
  total: number;
@@ -886,195 +580,10 @@ export declare class RalphTracker extends EventEmitter {
886
580
  };
887
581
  /**
888
582
  * Restore tracker state from persisted data.
889
- *
890
- * Use after loading state from StateStore. Handles backwards
891
- * compatibility by defaulting missing `enabled` flag to false.
892
- *
893
- * Note: Does not emit events (caller should handle if needed).
894
- *
895
- * @param loopState - Persisted loop state object
896
- * @param todos - Persisted todo items array
897
583
  */
898
584
  restoreState(loopState: RalphTrackerState, todos: RalphTodoItem[]): void;
899
- /**
900
- * Process a line for RALPH_STATUS block detection.
901
- * Buffers lines between ---RALPH_STATUS--- and ---END_RALPH_STATUS---
902
- * then parses the complete block.
903
- *
904
- * @param line - Single line to process (already trimmed)
905
- * @fires statusBlockDetected - When a complete block is parsed
906
- */
907
- private processStatusBlockLine;
908
- /**
909
- * Parse buffered RALPH_STATUS block lines into structured data.
910
- *
911
- * P1-004: Enhanced with schema validation and error recovery
912
- *
913
- * @param lines - Array of lines between block markers
914
- * @fires statusBlockDetected - When parsing succeeds
915
- */
916
- private parseStatusBlock;
917
- /**
918
- * Handle a parsed RALPH_STATUS block.
919
- * Updates circuit breaker, checks exit conditions.
920
- *
921
- * @param block - Parsed status block
922
- * @fires statusBlockDetected - With the block data
923
- * @fires circuitBreakerUpdate - If state changes
924
- * @fires exitGateMet - If dual-condition exit triggered
925
- */
926
- private handleStatusBlock;
927
- /**
928
- * Update circuit breaker state based on iteration results.
929
- *
930
- * @param hasProgress - Whether this iteration made progress
931
- * @param testsStatus - Current test status
932
- * @param status - Overall status from RALPH_STATUS
933
- * @fires circuitBreakerUpdate - If state changes
934
- */
935
- private updateCircuitBreaker;
936
- /**
937
- * Manually reset circuit breaker to CLOSED state.
938
- * Use when user acknowledges the issue is resolved.
939
- *
940
- * @fires circuitBreakerUpdate
941
- */
942
- resetCircuitBreaker(): void;
943
- /**
944
- * Get current circuit breaker status.
945
- */
946
- get circuitBreakerStatus(): CircuitBreakerStatus;
947
- /**
948
- * Get last parsed RALPH_STATUS block.
949
- */
950
- get lastStatusBlock(): RalphStatusBlock | null;
951
- /**
952
- * Get cumulative stats from status blocks.
953
- */
954
- get cumulativeStats(): {
955
- filesModified: number;
956
- tasksCompleted: number;
957
- completionIndicators: number;
958
- };
959
- /**
960
- * Whether dual-condition exit gate has been met.
961
- */
962
- get exitGateMet(): boolean;
963
- /**
964
- * Check line for completion indicators (natural language patterns).
965
- * Used for dual-condition exit gate.
966
- *
967
- * @param line - Line to check
968
- */
969
- private detectCompletionIndicators;
970
- /**
971
- * Generate @fix_plan.md content from current todos.
972
- * Groups todos by priority and status.
973
- *
974
- * @returns Markdown content for @fix_plan.md
975
- */
976
- generateFixPlanMarkdown(): string;
977
- /**
978
- * Parse @fix_plan.md content and import todos.
979
- * Replaces current todos with imported ones.
980
- *
981
- * @param content - Markdown content from @fix_plan.md
982
- * @returns Number of todos imported
983
- */
984
- importFixPlanMarkdown(content: string): number;
985
- /**
986
- * Initialize plan tasks from generated plan items.
987
- * Called when wizard generates a new plan.
988
- */
989
- initializePlanTasks(items: Array<{
990
- id?: string;
991
- content: string;
992
- priority?: 'P0' | 'P1' | 'P2' | null;
993
- verificationCriteria?: string;
994
- testCommand?: string;
995
- dependencies?: string[];
996
- tddPhase?: TddPhase;
997
- pairedWith?: string;
998
- complexity?: 'low' | 'medium' | 'high';
999
- }>): void;
1000
- /**
1001
- * Update a specific plan task's status, attempts, or error.
1002
- */
1003
- updatePlanTask(taskId: string, update: {
1004
- status?: PlanTaskStatus;
1005
- error?: string;
1006
- incrementAttempts?: boolean;
1007
- }): {
1008
- success: boolean;
1009
- task?: EnhancedPlanTask;
1010
- error?: string;
1011
- };
1012
- /**
1013
- * Unblock tasks that were waiting on a completed dependency.
1014
- */
1015
- private _unblockDependentTasks;
1016
- /**
1017
- * Check if current iteration is a checkpoint and emit review if so.
1018
- */
1019
- private _checkForCheckpoint;
1020
- /**
1021
- * Generate a checkpoint review summarizing plan progress and stuck tasks.
1022
- */
1023
- generateCheckpointReview(): CheckpointReview;
1024
- /**
1025
- * Save current plan state to history.
1026
- */
1027
- private _savePlanToHistory;
1028
- /**
1029
- * Get plan version history.
1030
- */
1031
- getPlanHistory(): Array<{
1032
- version: number;
1033
- timestamp: number;
1034
- summary: string;
1035
- stats: {
1036
- total: number;
1037
- completed: number;
1038
- failed: number;
1039
- };
1040
- }>;
1041
- /**
1042
- * Rollback to a previous plan version.
1043
- */
1044
- rollbackToVersion(version: number): {
1045
- success: boolean;
1046
- plan?: EnhancedPlanTask[];
1047
- error?: string;
1048
- };
1049
- /**
1050
- * Add a new task to the plan (for runtime adaptation).
1051
- */
1052
- addPlanTask(task: {
1053
- content: string;
1054
- priority?: 'P0' | 'P1' | 'P2';
1055
- verificationCriteria?: string;
1056
- dependencies?: string[];
1057
- insertAfter?: string;
1058
- }): {
1059
- task: EnhancedPlanTask;
1060
- };
1061
- /**
1062
- * Get all plan tasks.
1063
- */
1064
- getPlanTasks(): EnhancedPlanTask[];
1065
- /**
1066
- * Get current plan version.
1067
- */
1068
- get planVersion(): number;
1069
- /**
1070
- * Check if checkpoint review is due for current iteration.
1071
- */
1072
- isCheckpointDue(): boolean;
1073
585
  /**
1074
586
  * Clean up all resources and release memory.
1075
- *
1076
- * Call this when the session is being destroyed to prevent memory leaks.
1077
- * Stops file watchers, clears all timers, data, and removes event listeners.
1078
587
  */
1079
588
  destroy(): void;
1080
589
  }