dual-brain 0.2.30 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (312) hide show
  1. package/.dual-brain/docs/claude-code-extension-points.md +32 -0
  2. package/.dual-brain/docs/data-tools-capabilities.md +181 -0
  3. package/.dual-brain/docs/ecosystem-tools.md +91 -0
  4. package/.dual-brain/docs/panel-handoff.md +124 -0
  5. package/.dual-brain/docs/ruflo-analysis.md +48 -0
  6. package/bin/dual-brain.mjs +56 -56
  7. package/dist/mcp-server/index.d.ts +27 -0
  8. package/dist/mcp-server/index.js +359 -0
  9. package/dist/mcp-server/index.js.map +1 -0
  10. package/dist/src/agent-protocol.d.ts +163 -0
  11. package/dist/src/agent-protocol.js +368 -0
  12. package/dist/src/agent-protocol.js.map +1 -0
  13. package/dist/src/agents/registry.d.ts +52 -0
  14. package/dist/src/agents/registry.js +393 -0
  15. package/dist/src/agents/registry.js.map +1 -0
  16. package/dist/src/awareness.d.ts +93 -0
  17. package/dist/src/awareness.js +406 -0
  18. package/dist/src/awareness.js.map +1 -0
  19. package/dist/src/brief.d.ts +48 -0
  20. package/dist/src/brief.js +179 -0
  21. package/dist/src/brief.js.map +1 -0
  22. package/dist/src/calibration.d.ts +32 -0
  23. package/dist/src/calibration.js +133 -0
  24. package/dist/src/calibration.js.map +1 -0
  25. package/dist/src/checkpoint.d.ts +33 -0
  26. package/dist/src/checkpoint.js +99 -0
  27. package/dist/src/checkpoint.js.map +1 -0
  28. package/dist/src/ci-triage.d.ts +33 -0
  29. package/dist/src/ci-triage.js +193 -0
  30. package/dist/src/ci-triage.js.map +1 -0
  31. package/dist/src/cognitive-loop.d.ts +56 -0
  32. package/dist/src/cognitive-loop.js +495 -0
  33. package/dist/src/cognitive-loop.js.map +1 -0
  34. package/dist/src/collaboration.d.ts +147 -0
  35. package/dist/src/collaboration.js +438 -0
  36. package/dist/src/collaboration.js.map +1 -0
  37. package/dist/src/context-intel.d.ts +47 -0
  38. package/dist/src/context-intel.js +156 -0
  39. package/dist/src/context-intel.js.map +1 -0
  40. package/dist/src/context.d.ts +53 -0
  41. package/dist/src/context.js +332 -0
  42. package/dist/src/context.js.map +1 -0
  43. package/dist/src/continuity.d.ts +89 -0
  44. package/dist/src/continuity.js +230 -0
  45. package/dist/src/continuity.js.map +1 -0
  46. package/dist/src/cost-tracker.d.ts +47 -0
  47. package/dist/src/cost-tracker.js +170 -0
  48. package/dist/src/cost-tracker.js.map +1 -0
  49. package/dist/src/debrief.d.ts +53 -0
  50. package/dist/src/debrief.js +222 -0
  51. package/dist/src/debrief.js.map +1 -0
  52. package/dist/src/decide.d.ts +96 -0
  53. package/dist/src/decide.js +744 -0
  54. package/dist/src/decide.js.map +1 -0
  55. package/dist/src/decompose.d.ts +39 -0
  56. package/dist/src/decompose.js +218 -0
  57. package/dist/src/decompose.js.map +1 -0
  58. package/dist/src/detect.d.ts +91 -0
  59. package/dist/src/detect.js +544 -0
  60. package/dist/src/detect.js.map +1 -0
  61. package/dist/src/dispatch.d.ts +154 -0
  62. package/dist/src/dispatch.js +1306 -0
  63. package/dist/src/dispatch.js.map +1 -0
  64. package/dist/src/doctor.d.ts +421 -0
  65. package/dist/src/doctor.js +1689 -0
  66. package/dist/src/doctor.js.map +1 -0
  67. package/dist/src/engine.d.ts +70 -0
  68. package/dist/src/engine.js +155 -0
  69. package/dist/src/engine.js.map +1 -0
  70. package/dist/src/envelope.d.ts +36 -0
  71. package/dist/src/envelope.js +80 -0
  72. package/dist/src/envelope.js.map +1 -0
  73. package/dist/src/failure-memory.d.ts +55 -0
  74. package/dist/src/failure-memory.js +175 -0
  75. package/dist/src/failure-memory.js.map +1 -0
  76. package/dist/src/fx.d.ts +87 -0
  77. package/dist/src/fx.js +272 -0
  78. package/dist/src/fx.js.map +1 -0
  79. package/dist/src/governance.d.ts +93 -0
  80. package/dist/src/governance.js +261 -0
  81. package/dist/src/governance.js.map +1 -0
  82. package/dist/src/handoff.d.ts +11 -0
  83. package/dist/src/handoff.js +90 -0
  84. package/dist/src/handoff.js.map +1 -0
  85. package/dist/src/head-protocol.d.ts +76 -0
  86. package/dist/src/head-protocol.js +109 -0
  87. package/dist/src/head-protocol.js.map +1 -0
  88. package/dist/src/head.d.ts +222 -0
  89. package/dist/src/head.js +765 -0
  90. package/dist/src/head.js.map +1 -0
  91. package/dist/src/health.d.ts +132 -0
  92. package/dist/src/health.js +435 -0
  93. package/dist/src/health.js.map +1 -0
  94. package/dist/src/inbox.d.ts +70 -0
  95. package/dist/src/inbox.js +218 -0
  96. package/dist/src/inbox.js.map +1 -0
  97. package/dist/src/index.d.ts +33 -0
  98. package/dist/src/index.js +38 -0
  99. package/dist/src/index.js.map +1 -0
  100. package/dist/src/install-hooks.d.ts +13 -0
  101. package/dist/src/install-hooks.js +88 -0
  102. package/dist/src/install-hooks.js.map +1 -0
  103. package/dist/src/integrity.d.ts +59 -0
  104. package/dist/src/integrity.js +206 -0
  105. package/dist/src/integrity.js.map +1 -0
  106. package/dist/src/intelligence.d.ts +104 -0
  107. package/dist/src/intelligence.js +391 -0
  108. package/dist/src/intelligence.js.map +1 -0
  109. package/dist/src/ledger.d.ts +54 -0
  110. package/dist/src/ledger.js +179 -0
  111. package/dist/src/ledger.js.map +1 -0
  112. package/dist/src/living-docs.d.ts +14 -0
  113. package/dist/src/living-docs.js +197 -0
  114. package/dist/src/living-docs.js.map +1 -0
  115. package/dist/src/memory-tiers.d.ts +37 -0
  116. package/dist/src/memory-tiers.js +160 -0
  117. package/dist/src/memory-tiers.js.map +1 -0
  118. package/dist/src/model-profiles.d.ts +65 -0
  119. package/dist/src/model-profiles.js +568 -0
  120. package/dist/src/model-profiles.js.map +1 -0
  121. package/dist/src/models.d.ts +58 -0
  122. package/dist/src/models.js +327 -0
  123. package/dist/src/models.js.map +1 -0
  124. package/dist/src/narrative.d.ts +54 -0
  125. package/dist/src/narrative.js +163 -0
  126. package/dist/src/narrative.js.map +1 -0
  127. package/dist/src/nextstep.d.ts +16 -0
  128. package/dist/src/nextstep.js +103 -0
  129. package/dist/src/nextstep.js.map +1 -0
  130. package/dist/src/observer.d.ts +18 -0
  131. package/dist/src/observer.js +251 -0
  132. package/dist/src/observer.js.map +1 -0
  133. package/dist/src/outcome.d.ts +110 -0
  134. package/dist/src/outcome.js +377 -0
  135. package/dist/src/outcome.js.map +1 -0
  136. package/dist/src/pipeline.d.ts +167 -0
  137. package/dist/src/pipeline.js +1503 -0
  138. package/dist/src/pipeline.js.map +1 -0
  139. package/dist/src/playbook.d.ts +59 -0
  140. package/dist/src/playbook.js +238 -0
  141. package/dist/src/playbook.js.map +1 -0
  142. package/dist/src/pr-agent.d.ts +97 -0
  143. package/dist/src/pr-agent.js +195 -0
  144. package/dist/src/pr-agent.js.map +1 -0
  145. package/dist/src/predictive.d.ts +57 -0
  146. package/dist/src/predictive.js +230 -0
  147. package/dist/src/predictive.js.map +1 -0
  148. package/dist/src/profile.d.ts +294 -0
  149. package/dist/src/profile.js +1347 -0
  150. package/dist/src/profile.js.map +1 -0
  151. package/dist/src/prompt-audit.d.ts +22 -0
  152. package/dist/src/prompt-audit.js +194 -0
  153. package/dist/src/prompt-audit.js.map +1 -0
  154. package/dist/src/prompt-intel.d.ts +12 -0
  155. package/dist/src/prompt-intel.js +321 -0
  156. package/dist/src/prompt-intel.js.map +1 -0
  157. package/dist/src/provider-context.d.ts +121 -0
  158. package/dist/src/provider-context.js +222 -0
  159. package/dist/src/provider-context.js.map +1 -0
  160. package/dist/src/provider-manager.d.ts +92 -0
  161. package/dist/src/provider-manager.js +428 -0
  162. package/dist/src/provider-manager.js.map +1 -0
  163. package/dist/src/receipt.d.ts +87 -0
  164. package/dist/src/receipt.js +326 -0
  165. package/dist/src/receipt.js.map +1 -0
  166. package/dist/src/recommendations.d.ts +13 -0
  167. package/dist/src/recommendations.js +291 -0
  168. package/dist/src/recommendations.js.map +1 -0
  169. package/dist/src/redact.d.ts +15 -0
  170. package/dist/src/redact.js +129 -0
  171. package/dist/src/redact.js.map +1 -0
  172. package/dist/src/replit.d.ts +397 -0
  173. package/dist/src/replit.js +1160 -0
  174. package/dist/src/replit.js.map +1 -0
  175. package/dist/src/repo.d.ts +149 -0
  176. package/dist/src/repo.js +416 -0
  177. package/dist/src/repo.js.map +1 -0
  178. package/dist/src/revert.d.ts +30 -0
  179. package/dist/src/revert.js +166 -0
  180. package/dist/src/revert.js.map +1 -0
  181. package/dist/src/room.d.ts +102 -0
  182. package/dist/src/room.js +212 -0
  183. package/dist/src/room.js.map +1 -0
  184. package/dist/src/routing-advisor.d.ts +57 -0
  185. package/dist/src/routing-advisor.js +221 -0
  186. package/dist/src/routing-advisor.js.map +1 -0
  187. package/dist/src/self-correct.d.ts +40 -0
  188. package/dist/src/self-correct.js +137 -0
  189. package/dist/src/self-correct.js.map +1 -0
  190. package/dist/src/session-lock.d.ts +35 -0
  191. package/dist/src/session-lock.js +134 -0
  192. package/dist/src/session-lock.js.map +1 -0
  193. package/dist/src/session.d.ts +267 -0
  194. package/dist/src/session.js +1660 -0
  195. package/dist/src/session.js.map +1 -0
  196. package/dist/src/settings-tui.d.ts +5 -0
  197. package/dist/src/settings-tui.js +422 -0
  198. package/dist/src/settings-tui.js.map +1 -0
  199. package/dist/src/setup-flow.d.ts +63 -0
  200. package/dist/src/setup-flow.js +233 -0
  201. package/dist/src/setup-flow.js.map +1 -0
  202. package/dist/src/signal.d.ts +19 -0
  203. package/dist/src/signal.js +122 -0
  204. package/dist/src/signal.js.map +1 -0
  205. package/dist/src/simmer.d.ts +85 -0
  206. package/dist/src/simmer.js +224 -0
  207. package/dist/src/simmer.js.map +1 -0
  208. package/dist/src/state-export.d.ts +129 -0
  209. package/dist/src/state-export.js +233 -0
  210. package/dist/src/state-export.js.map +1 -0
  211. package/dist/src/strategy.d.ts +54 -0
  212. package/dist/src/strategy.js +95 -0
  213. package/dist/src/strategy.js.map +1 -0
  214. package/dist/src/subscription.d.ts +40 -0
  215. package/dist/src/subscription.js +189 -0
  216. package/dist/src/subscription.js.map +1 -0
  217. package/dist/src/templates.d.ts +208 -0
  218. package/dist/src/templates.js +238 -0
  219. package/dist/src/templates.js.map +1 -0
  220. package/dist/src/test.d.ts +9 -0
  221. package/dist/src/test.js +1173 -0
  222. package/dist/src/test.js.map +1 -0
  223. package/dist/src/think-engine.d.ts +67 -0
  224. package/dist/src/think-engine.js +412 -0
  225. package/dist/src/think-engine.js.map +1 -0
  226. package/dist/src/tui.d.ts +71 -0
  227. package/dist/src/tui.js +242 -0
  228. package/dist/src/tui.js.map +1 -0
  229. package/dist/src/types.d.ts +177 -0
  230. package/dist/src/types.js +6 -0
  231. package/dist/src/types.js.map +1 -0
  232. package/dist/src/update-check.d.ts +7 -0
  233. package/dist/src/update-check.js +36 -0
  234. package/dist/src/update-check.js.map +1 -0
  235. package/dist/src/wave-planner.d.ts +30 -0
  236. package/dist/src/wave-planner.js +281 -0
  237. package/dist/src/wave-planner.js.map +1 -0
  238. package/hooks/head-guard.sh +41 -0
  239. package/hooks/precompact.mjs +3 -3
  240. package/hooks/session-end.mjs +3 -3
  241. package/hooks/task-classifier.mjs +328 -0
  242. package/hooks/vibe-router.mjs +387 -0
  243. package/install.mjs +2 -2
  244. package/package.json +29 -153
  245. package/src/agents/registry.mjs +0 -405
  246. package/src/awareness.mjs +0 -425
  247. package/src/brief.mjs +0 -266
  248. package/src/calibration.mjs +0 -148
  249. package/src/checkpoint.mjs +0 -109
  250. package/src/ci-triage.mjs +0 -191
  251. package/src/cognitive-loop.mjs +0 -562
  252. package/src/collaboration.mjs +0 -545
  253. package/src/context-intel.mjs +0 -158
  254. package/src/context.mjs +0 -389
  255. package/src/continuity.mjs +0 -298
  256. package/src/cost-tracker.mjs +0 -184
  257. package/src/debrief.mjs +0 -228
  258. package/src/decide.mjs +0 -1099
  259. package/src/decompose.mjs +0 -331
  260. package/src/detect.mjs +0 -702
  261. package/src/dispatch.mjs +0 -1447
  262. package/src/doctor.mjs +0 -1607
  263. package/src/envelope.mjs +0 -139
  264. package/src/failure-memory.mjs +0 -178
  265. package/src/fx.mjs +0 -276
  266. package/src/governance.mjs +0 -279
  267. package/src/handoff.mjs +0 -87
  268. package/src/head-protocol.mjs +0 -128
  269. package/src/head.mjs +0 -952
  270. package/src/health.mjs +0 -528
  271. package/src/inbox.mjs +0 -195
  272. package/src/index.mjs +0 -44
  273. package/src/install-hooks.mjs +0 -100
  274. package/src/integrity.mjs +0 -245
  275. package/src/intelligence.mjs +0 -447
  276. package/src/ledger.mjs +0 -196
  277. package/src/living-docs.mjs +0 -210
  278. package/src/memory-tiers.mjs +0 -193
  279. package/src/models.mjs +0 -363
  280. package/src/narrative.mjs +0 -169
  281. package/src/nextstep.mjs +0 -100
  282. package/src/observer.mjs +0 -241
  283. package/src/outcome.mjs +0 -400
  284. package/src/pipeline.mjs +0 -1711
  285. package/src/playbook.mjs +0 -257
  286. package/src/pr-agent.mjs +0 -214
  287. package/src/predictive.mjs +0 -250
  288. package/src/profile.mjs +0 -1411
  289. package/src/prompt-audit.mjs +0 -231
  290. package/src/prompt-intel.mjs +0 -325
  291. package/src/provider-context.mjs +0 -257
  292. package/src/receipt.mjs +0 -344
  293. package/src/recommendations.mjs +0 -296
  294. package/src/redact.mjs +0 -192
  295. package/src/replit.mjs +0 -1210
  296. package/src/repo.mjs +0 -445
  297. package/src/revert.mjs +0 -149
  298. package/src/routing-advisor.mjs +0 -204
  299. package/src/self-correct.mjs +0 -147
  300. package/src/session-lock.mjs +0 -160
  301. package/src/session.mjs +0 -1655
  302. package/src/settings-tui.mjs +0 -373
  303. package/src/setup-flow.mjs +0 -223
  304. package/src/signal.mjs +0 -115
  305. package/src/simmer.mjs +0 -241
  306. package/src/strategy.mjs +0 -235
  307. package/src/subscription.mjs +0 -212
  308. package/src/templates.mjs +0 -260
  309. package/src/think-engine.mjs +0 -428
  310. package/src/tui.mjs +0 -276
  311. package/src/update-check.mjs +0 -35
  312. package/src/wave-planner.mjs +0 -294
@@ -0,0 +1,32 @@
1
+ interface AnalysisResult {
2
+ specificity: number;
3
+ signals: {
4
+ hasFileRefs: boolean;
5
+ hasTechTerms: boolean;
6
+ hasExactInstructions: boolean;
7
+ isVague: boolean;
8
+ wordCount: number;
9
+ };
10
+ }
11
+ export declare function analyzeInput(input: string | null | undefined): AnalysisResult;
12
+ export declare function detectCorrection(input: string | null | undefined): boolean;
13
+ export interface Calibration {
14
+ specificity?: number;
15
+ corrections?: number;
16
+ autonomy?: number;
17
+ interactions?: number;
18
+ lastUpdated?: string;
19
+ }
20
+ export declare function updateCalibration(calibration: Calibration, input: string, correction?: boolean): Calibration;
21
+ interface Adaptation {
22
+ clarifyBeforeActing: boolean;
23
+ explainReasoning: boolean;
24
+ suggestNextSteps: boolean;
25
+ askForApproval: boolean;
26
+ autoExecute: boolean;
27
+ responseStyle: 'terse' | 'normal' | 'detailed';
28
+ userLevel: 'advanced' | 'intermediate' | 'beginner';
29
+ }
30
+ export declare function getAdaptation(calibration: Calibration): Adaptation;
31
+ export declare function formatCalibration(calibration: Calibration): string;
32
+ export {};
@@ -0,0 +1,133 @@
1
+ // User calibration module — tracks specificity, corrections, and autonomy signals
2
+ // to adapt dual-brain behavior to any user from vague vibe-coder to precise expert.
3
+ const FILE_REF_RE = /(?:src\/|\.mjs|\.tsx?|\.jsx?|\.json|\.ya?ml|\.sh|line\s+\d+|\bL\d+\b)/i;
4
+ const TECH_TERM_RE = /\b(?:regex|middleware|api|endpoint|refactor|migration|schema|auth(?:entication)?|jwt|token|hook|dispatch|pipeline|module|function|class|interface|type|import|export|async|await|promise|callback|handler|router|controller|service|repository|factory|singleton|decorator|mixin|proxy|guard|interceptor|serializer|validator|transformer|adapter|facade|strategy|observer|subscriber|emitter|stream|buffer|cache|queue|worker|thread|mutex|semaphore|socket|websocket|http|grpc|graphql|rest|orm|sql|nosql|index|query|transaction|migration|seed|fixture|mock|stub|spy|assertion|coverage|lint|typecheck|bundle|compile|transpile|minify|tree.shake|dead.code|chunk|lazy.load|ssr|csr|hydrat)\b/i;
5
+ const VAGUE_RE = /\b(?:idk|just|make\s+it|fix\s+it|whatever|vibes?|better|nicer|faster|cleaner|improve|help|do\s+it|yeah|sure|ok|okay|hmm|uh|er|um)\b/i;
6
+ const AUTONOMY_HIGH_RE = /\b(?:just\s+do\s+it|go(?:\s+ahead)?|build\s+it|ship\s+it|run\s+it|execute|do\s+it|proceed|continue|carry\s+on|handle\s+it|take\s+care|make\s+it\s+happen|yolo)\b/i;
7
+ const QUESTION_RE = /\?|^(?:how|what|why|when|where|which|should|can|could|would|is|are|do|does|did|will|won't|don't)\b/i;
8
+ const CORRECTION_RE = /^(?:no[,.]?|not\s|wrong|stop|don't|that'?s?\s+not|i\s+said|i\s+meant)\b|(?:\binstead\b|\brather\b|\bactually\b)/i;
9
+ export function analyzeInput(input) {
10
+ const text = (input || '').trim();
11
+ const words = text.split(/\s+/).filter(Boolean);
12
+ const wordCount = words.length;
13
+ const hasFileRefs = FILE_REF_RE.test(text);
14
+ const hasTechTerms = TECH_TERM_RE.test(text);
15
+ const hasExactInstructions = /\b(?:step\s+\d|first[,\s]|then[,\s]|finally[,\s]|specifically|exactly|must|should\s+(?:use|call|return|handle)|(?:use|call|return|throw|emit|dispatch)\s+\w)/i.test(text);
16
+ const isVague = VAGUE_RE.test(text.toLowerCase()) || wordCount <= 3;
17
+ let specificity;
18
+ if (hasFileRefs || /\bline\s*\d+\b|\bL\d+\b/i.test(text) || (hasTechTerms && hasExactInstructions)) {
19
+ specificity = 5;
20
+ }
21
+ else if (hasTechTerms && wordCount >= 6) {
22
+ specificity = 4;
23
+ }
24
+ else if (!isVague && wordCount >= 8) {
25
+ specificity = 3;
26
+ }
27
+ else if (wordCount >= 4 && !isVague) {
28
+ specificity = 2;
29
+ }
30
+ else {
31
+ specificity = 1;
32
+ }
33
+ return {
34
+ specificity,
35
+ signals: {
36
+ hasFileRefs,
37
+ hasTechTerms,
38
+ hasExactInstructions,
39
+ isVague,
40
+ wordCount
41
+ }
42
+ };
43
+ }
44
+ export function detectCorrection(input) {
45
+ return CORRECTION_RE.test((input || '').trim());
46
+ }
47
+ function clamp(value, min = 1, max = 5) {
48
+ return Math.min(max, Math.max(min, value));
49
+ }
50
+ function round1(value) {
51
+ return Math.round(value * 10) / 10;
52
+ }
53
+ function detectAutonomySignal(input) {
54
+ const text = (input || '').trim();
55
+ if (AUTONOMY_HIGH_RE.test(text))
56
+ return 5;
57
+ if (QUESTION_RE.test(text))
58
+ return 2;
59
+ return null;
60
+ }
61
+ export function updateCalibration(calibration, input, correction = false) {
62
+ const { specificity: newSpec } = analyzeInput(input);
63
+ const autonomySignal = detectAutonomySignal(input);
64
+ const prev = {
65
+ specificity: calibration.specificity ?? 3,
66
+ corrections: calibration.corrections ?? 3,
67
+ autonomy: calibration.autonomy ?? 3,
68
+ interactions: calibration.interactions ?? 0
69
+ };
70
+ const specificity = round1(clamp(prev.specificity * 0.7 + newSpec * 0.3));
71
+ const corrections = round1(clamp(correction ? prev.corrections - 0.3 : prev.corrections + 0.1));
72
+ let autonomy = prev.autonomy;
73
+ if (autonomySignal !== null) {
74
+ autonomy = round1(clamp(prev.autonomy * 0.7 + autonomySignal * 0.3));
75
+ }
76
+ return {
77
+ specificity,
78
+ corrections,
79
+ autonomy,
80
+ interactions: prev.interactions + 1,
81
+ lastUpdated: new Date().toISOString()
82
+ };
83
+ }
84
+ export function getAdaptation(calibration) {
85
+ const s = calibration.specificity ?? 3;
86
+ const c = calibration.corrections ?? 3;
87
+ const a = calibration.autonomy ?? 3;
88
+ const clarifyBeforeActing = s < 2.5 || c > 3;
89
+ const explainReasoning = a < 3;
90
+ const suggestNextSteps = a < 4;
91
+ const askForApproval = c < 2.5;
92
+ const autoExecute = a > 4 && c > 3.5;
93
+ let responseStyle;
94
+ const combined = (s + c + a) / 3;
95
+ if (combined >= 4) {
96
+ responseStyle = 'terse';
97
+ }
98
+ else if (combined >= 2.5) {
99
+ responseStyle = 'normal';
100
+ }
101
+ else {
102
+ responseStyle = 'detailed';
103
+ }
104
+ let userLevel;
105
+ if (s >= 4) {
106
+ userLevel = 'advanced';
107
+ }
108
+ else if (s >= 2.5) {
109
+ userLevel = 'intermediate';
110
+ }
111
+ else {
112
+ userLevel = 'beginner';
113
+ }
114
+ return {
115
+ clarifyBeforeActing,
116
+ explainReasoning,
117
+ suggestNextSteps,
118
+ askForApproval,
119
+ autoExecute,
120
+ responseStyle,
121
+ userLevel
122
+ };
123
+ }
124
+ export function formatCalibration(calibration) {
125
+ const { userLevel, responseStyle } = getAdaptation(calibration);
126
+ const s = calibration.specificity ?? 3;
127
+ const c = calibration.corrections ?? 3;
128
+ const a = calibration.autonomy ?? 3;
129
+ const autonomyLabel = a >= 4 ? 'high autonomy' : a >= 2.5 ? 'normal autonomy' : 'low autonomy';
130
+ const trustLabel = c >= 4 ? 'high trust' : c >= 2.5 ? 'good trust' : 'low trust';
131
+ return `User: ${userLevel} · ${autonomyLabel} · ${trustLabel}\n (specificity: ${s}, corrections: ${c}, autonomy: ${a})`;
132
+ }
133
+ //# sourceMappingURL=calibration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calibration.js","sourceRoot":"","sources":["../../src/calibration.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,oFAAoF;AAEpF,MAAM,WAAW,GAAG,wEAAwE,CAAC;AAC7F,MAAM,YAAY,GAAG,oqBAAoqB,CAAC;AAC1rB,MAAM,QAAQ,GAAG,sIAAsI,CAAC;AACxJ,MAAM,gBAAgB,GAAG,mKAAmK,CAAC;AAC7L,MAAM,WAAW,GAAG,qGAAqG,CAAC;AAC1H,MAAM,aAAa,GAAG,kHAAkH,CAAC;AAazI,MAAM,UAAU,YAAY,CAAC,KAAgC;IAC3D,MAAM,IAAI,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAClC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,SAAS,GAAG,KAA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5
+ timestamp: string;
6
+ }
7
+ interface CheckpointEntry {
8
+ id: string;
9
+ label: string;
10
+ timestamp: string;
11
+ type: string;
12
+ tag?: string;
13
+ status: string;
14
+ }
15
+ /**
16
+ * Check if checkpoint capability is available.
17
+ */
18
+ export declare function hasCheckpoints(): boolean;
19
+ /**
20
+ * Create a checkpoint before a risky operation.
21
+ */
22
+ export declare function createCheckpoint(label: string, opts?: {
23
+ cwd?: string;
24
+ }): CheckpointResult;
25
+ /**
26
+ * List recent checkpoints (most recent first, up to 20).
27
+ */
28
+ export declare function listCheckpoints(cwd?: string): CheckpointEntry[];
29
+ /**
30
+ * Get the most recent checkpoint.
31
+ */
32
+ export declare function getLastCheckpoint(cwd?: string): CheckpointEntry | null;
33
+ export {};
@@ -0,0 +1,99 @@
1
+ // checkpoint.ts — Checkpoint wrapper for dual-brain execution safety.
2
+ // Wraps Replit's native checkpoint system with a git-based fallback.
3
+ // Exports: hasCheckpoints, createCheckpoint, listCheckpoints, getLastCheckpoint
4
+ import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'node:fs';
5
+ import { join } from 'node:path';
6
+ import { execSync } from 'node:child_process';
7
+ /**
8
+ * Check if checkpoint capability is available.
9
+ */
10
+ export function hasCheckpoints() {
11
+ try {
12
+ // Check for Replit checkpoint binary
13
+ if (existsSync('/usr/local/bin/replit-checkpoint'))
14
+ return true;
15
+ execSync('which replit-checkpoint', { stdio: 'pipe', timeout: 2000 });
16
+ return true;
17
+ }
18
+ catch {
19
+ return false;
20
+ }
21
+ }
22
+ /**
23
+ * Create a checkpoint before a risky operation.
24
+ */
25
+ export function createCheckpoint(label, opts = {}) {
26
+ const cwd = opts.cwd || process.cwd();
27
+ const timestamp = new Date().toISOString();
28
+ const id = `cp-${Date.now()}`;
29
+ // Try Replit checkpoint first
30
+ if (hasCheckpoints()) {
31
+ try {
32
+ execSync('replit-checkpoint create', { cwd, stdio: 'pipe', timeout: 10000 });
33
+ _logCheckpoint({ id, label, timestamp, type: 'replit', status: 'created' }, cwd);
34
+ return { success: true, id, label, timestamp };
35
+ }
36
+ catch {
37
+ // Fall through to git-based checkpoint
38
+ }
39
+ }
40
+ // Fallback: git stash + tag
41
+ try {
42
+ // Stash any uncommitted changes
43
+ const status = execSync('git status --porcelain', { cwd, encoding: 'utf8', timeout: 5000 }).trim();
44
+ if (status) {
45
+ execSync(`git stash push -m "dual-brain-checkpoint: ${label}"`, { cwd, stdio: 'pipe', timeout: 10000 });
46
+ execSync('git stash pop', { cwd, stdio: 'pipe', timeout: 10000 });
47
+ }
48
+ // Create a lightweight tag
49
+ const safeLabel = label.replace(/[^a-zA-Z0-9-_]/g, '-').slice(0, 50);
50
+ const tagName = `db-checkpoint/${safeLabel}-${Date.now()}`;
51
+ execSync(`git tag "${tagName}"`, { cwd, stdio: 'pipe', timeout: 5000 });
52
+ _logCheckpoint({ id, label, timestamp, type: 'git-tag', tag: tagName, status: 'created' }, cwd);
53
+ return { success: true, id, label, timestamp };
54
+ }
55
+ catch {
56
+ _logCheckpoint({ id, label, timestamp, type: 'failed', status: 'failed' }, cwd);
57
+ return { success: false, id: null, label, timestamp };
58
+ }
59
+ }
60
+ /**
61
+ * List recent checkpoints (most recent first, up to 20).
62
+ */
63
+ export function listCheckpoints(cwd) {
64
+ const logPath = join(cwd || process.cwd(), '.dual-brain', 'checkpoints.jsonl');
65
+ if (!existsSync(logPath))
66
+ return [];
67
+ try {
68
+ return readFileSync(logPath, 'utf8')
69
+ .trim()
70
+ .split('\n')
71
+ .filter(Boolean)
72
+ .map(line => JSON.parse(line))
73
+ .reverse()
74
+ .slice(0, 20);
75
+ }
76
+ catch {
77
+ return [];
78
+ }
79
+ }
80
+ /**
81
+ * Get the most recent checkpoint.
82
+ */
83
+ export function getLastCheckpoint(cwd) {
84
+ const checkpoints = listCheckpoints(cwd);
85
+ return checkpoints[0] || null;
86
+ }
87
+ // ─── Internal helpers ─────────────────────────────────────────────────────────
88
+ function _logCheckpoint(entry, cwd) {
89
+ const dir = join(cwd || process.cwd(), '.dual-brain');
90
+ mkdirSync(dir, { recursive: true });
91
+ const logPath = join(dir, 'checkpoints.jsonl');
92
+ const line = JSON.stringify(entry) + '\n';
93
+ try {
94
+ const existing = existsSync(logPath) ? readFileSync(logPath, 'utf8') : '';
95
+ writeFileSync(logPath, existing + line);
96
+ }
97
+ catch { /* non-fatal */ }
98
+ }
99
+ //# sourceMappingURL=checkpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkpoint.js","sourceRoot":"","sources":["../../src/checkpoint.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,qEAAqE;AACrE,gFAAgF;AAEhF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAkB9C;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,IAAI,CAAC;QACH,qCAAqC;QACrC,IAAI,UAAU,CAAC,kCAAkC,CAAC;YAAE,OAAO,IAAI,CAAC;QAChE,QAAQ,CAAC,yBAAyB,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QACtE,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa,EAAE,OAAyB,EAAE;IACzE,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACtC,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC3C,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;IAE9B,8BAA8B;IAC9B,IAAI,cAAc,EAAE,EAAE,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AW,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAChC,CAAC;AAED,iFAAiF;AAEjF,SAAS,cAAc,CAAC,KAAsB,EAAE,GAAW;IACzD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,CAAC,CAAC;IACtD,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACpC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;IAC/C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IAC1C,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1E,aAAa,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC,CAAC;IAC1C,CAAC;IAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Detect CI system in use.
3
+ * @param {string} [cwd]
4
+ * @returns {{ systems: string[], primary: string|null }}
5
+ */
6
+ export declare function detectCI(cwd?: string): {
7
+ systems: string[];
8
+ primary: string | null;
9
+ };
10
+ /**
11
+ * Get recent CI run status using gh CLI.
12
+ * @param {string} [cwd]
13
+ * @returns {{ available: boolean, runs: object[], hasFailures: boolean, lastRun: object|null }}
14
+ */
15
+ export declare function getCIStatus(cwd?: string): {
16
+ available: boolean;
17
+ runs: unknown[];
18
+ hasFailures: boolean;
19
+ lastRun: unknown;
20
+ };
21
+ /**
22
+ * Get failed CI run logs and classify the failure.
23
+ * @param {string|number} runId
24
+ * @param {string} [cwd]
25
+ * @returns {object}
26
+ */
27
+ export declare function triageFailure(runId: string | number, cwd?: string): Record<string, unknown>;
28
+ /**
29
+ * Full CI triage: detect CI, fetch status, classify failures, map to files.
30
+ * @param {string} [cwd]
31
+ * @returns {object}
32
+ */
33
+ export declare function fullTriage(cwd?: string): Record<string, unknown>;
@@ -0,0 +1,193 @@
1
+ import { execSync } from 'node:child_process';
2
+ import { existsSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ /**
5
+ * Detect CI system in use.
6
+ * @param {string} [cwd]
7
+ * @returns {{ systems: string[], primary: string|null }}
8
+ */
9
+ export function detectCI(cwd) {
10
+ const root = cwd || process.cwd();
11
+ const systems = [];
12
+ if (existsSync(join(root, '.github/workflows')))
13
+ systems.push('github-actions');
14
+ if (existsSync(join(root, '.circleci')))
15
+ systems.push('circleci');
16
+ if (existsSync(join(root, '.gitlab-ci.yml')))
17
+ systems.push('gitlab-ci');
18
+ if (existsSync(join(root, 'Jenkinsfile')))
19
+ systems.push('jenkins');
20
+ if (existsSync(join(root, '.travis.yml')))
21
+ systems.push('travis');
22
+ if (existsSync(join(root, 'vercel.json')) || existsSync(join(root, '.vercel')))
23
+ systems.push('vercel');
24
+ if (existsSync(join(root, 'netlify.toml')))
25
+ systems.push('netlify');
26
+ return { systems, primary: systems[0] || null };
27
+ }
28
+ /**
29
+ * Get recent CI run status using gh CLI.
30
+ * @param {string} [cwd]
31
+ * @returns {{ available: boolean, runs: object[], hasFailures: boolean, lastRun: object|null }}
32
+ */
33
+ export function getCIStatus(cwd) {
34
+ try {
35
+ const json = execSync('gh run list --limit 5 --json databaseId,name,status,conclusion,headBranch,createdAt', { cwd, encoding: 'utf8', timeout: 10000 });
36
+ const runs = JSON.parse(json);
37
+ return {
38
+ available: true,
39
+ runs: runs.map((r) => ({
40
+ id: r.databaseId,
41
+ name: r.name,
42
+ status: r.status,
43
+ conclusion: r.conclusion,
44
+ branch: r.headBranch,
45
+ createdAt: r.createdAt,
46
+ })),
47
+ hasFailures: runs.some((r) => r.conclusion === 'failure'),
48
+ lastRun: runs[0] || null,
49
+ };
50
+ }
51
+ catch {
52
+ return { available: false, runs: [], hasFailures: false, lastRun: null };
53
+ }
54
+ }
55
+ /**
56
+ * Get failed CI run logs and classify the failure.
57
+ * @param {string|number} runId
58
+ * @param {string} [cwd]
59
+ * @returns {object}
60
+ */
61
+ export function triageFailure(runId, cwd) {
62
+ try {
63
+ const logs = execSync(`gh run view ${runId} --log-failed 2>/dev/null | tail -100`, {
64
+ cwd, encoding: 'utf8', timeout: 15000,
65
+ });
66
+ const classification = classifyFailure(logs);
67
+ const fileHints = extractFileHints(logs, cwd);
68
+ return {
69
+ success: true,
70
+ runId,
71
+ logs: logs.slice(-3000), // last 3000 chars
72
+ classification,
73
+ fileHints,
74
+ suggestedAction: getSuggestedAction(classification),
75
+ };
76
+ }
77
+ catch (err) {
78
+ const msg = err instanceof Error ? err.message : String(err);
79
+ return { success: false, runId, error: msg };
80
+ }
81
+ }
82
+ /**
83
+ * Classify a CI failure from log output.
84
+ * @param {string} logs
85
+ * @returns {{ type: string, confidence: string }}
86
+ */
87
+ function classifyFailure(logs) {
88
+ const lower = logs.toLowerCase();
89
+ if (lower.includes('syntaxerror') || lower.includes('parse error'))
90
+ return { type: 'syntax', confidence: 'high' };
91
+ if (lower.includes('typeerror') || lower.includes('type error'))
92
+ return { type: 'type-error', confidence: 'high' };
93
+ if (lower.includes('referenceerror'))
94
+ return { type: 'reference-error', confidence: 'high' };
95
+ if (lower.includes('test fail') || lower.includes('tests failed') || lower.includes('assertion'))
96
+ return { type: 'test-failure', confidence: 'high' };
97
+ if (lower.includes('enoent') || lower.includes('no such file'))
98
+ return { type: 'missing-file', confidence: 'high' };
99
+ if (lower.includes('permission denied') || lower.includes('eacces'))
100
+ return { type: 'permissions', confidence: 'high' };
101
+ if (lower.includes('timeout') || lower.includes('timed out'))
102
+ return { type: 'timeout', confidence: 'medium' };
103
+ if (lower.includes('out of memory') || lower.includes('heap'))
104
+ return { type: 'oom', confidence: 'medium' };
105
+ if (lower.includes('npm err') || lower.includes('yarn error') || lower.includes('dependency'))
106
+ return { type: 'dependency', confidence: 'medium' };
107
+ if (lower.includes('lint') || lower.includes('eslint'))
108
+ return { type: 'lint', confidence: 'high' };
109
+ if (lower.includes('build fail'))
110
+ return { type: 'build', confidence: 'medium' };
111
+ if (lower.includes('docker') || lower.includes('container'))
112
+ return { type: 'container', confidence: 'medium' };
113
+ return { type: 'unknown', confidence: 'low' };
114
+ }
115
+ /**
116
+ * Extract local file paths referenced in CI logs.
117
+ * @param {string} logs
118
+ * @param {string} [cwd]
119
+ * @returns {string[]}
120
+ */
121
+ function extractFileHints(logs, cwd) {
122
+ const files = new Set();
123
+ const root = cwd || process.cwd();
124
+ const patterns = [
125
+ /(?:at\s+)?([a-zA-Z0-9_./\\-]+\.[a-zA-Z]+):(\d+)/g,
126
+ /(?:in\s+)?([a-zA-Z0-9_./\\-]+\.[a-zA-Z]+)\((\d+)\)/g,
127
+ /Error in ([a-zA-Z0-9_./\\-]+\.[a-zA-Z]+)/g,
128
+ ];
129
+ for (const pattern of patterns) {
130
+ for (const match of logs.matchAll(pattern)) {
131
+ const file = match[1];
132
+ if (file && !file.includes('node_modules') && existsSync(join(root, file))) {
133
+ files.add(file);
134
+ }
135
+ }
136
+ }
137
+ return [...files];
138
+ }
139
+ /**
140
+ * Get a human-readable suggested action for a failure classification.
141
+ * @param {{ type: string }} classification
142
+ * @returns {string}
143
+ */
144
+ function getSuggestedAction(classification) {
145
+ const actions = {
146
+ 'syntax': 'Fix syntax error in the identified file',
147
+ 'type-error': 'Check type annotations and function signatures',
148
+ 'reference-error': 'Check for undefined variables or missing imports',
149
+ 'test-failure': 'Run tests locally and fix failing assertions',
150
+ 'missing-file': 'Check if a required file was deleted or not committed',
151
+ 'permissions': 'Check file permissions and access rights',
152
+ 'timeout': 'Investigate slow operations or increase timeout',
153
+ 'oom': 'Check for memory leaks or reduce batch size',
154
+ 'dependency': 'Run npm install and check for version conflicts',
155
+ 'lint': 'Run linter locally and fix violations',
156
+ 'build': 'Check build configuration and dependencies',
157
+ 'container': 'Check Dockerfile and container configuration',
158
+ 'unknown': 'Review full CI logs for error details',
159
+ };
160
+ return actions[classification.type] || actions.unknown;
161
+ }
162
+ /**
163
+ * Full CI triage: detect CI, fetch status, classify failures, map to files.
164
+ * @param {string} [cwd]
165
+ * @returns {object}
166
+ */
167
+ export function fullTriage(cwd) {
168
+ const ci = detectCI(cwd);
169
+ if (!ci.primary)
170
+ return { available: false, reason: 'no-ci-detected' };
171
+ const status = getCIStatus(cwd);
172
+ if (!status.available)
173
+ return { available: false, reason: 'gh-cli-unavailable' };
174
+ if (!status.hasFailures)
175
+ return { available: true, healthy: true, message: 'All CI runs passing' };
176
+ const failedRuns = status.runs.filter((r) => r.conclusion === 'failure');
177
+ const triages = failedRuns.slice(0, 3).map((r) => triageFailure(r.id, cwd));
178
+ return {
179
+ available: true,
180
+ healthy: false,
181
+ failedRuns: failedRuns.length,
182
+ triages,
183
+ topIssue: triages[0]?.classification || null,
184
+ };
185
+ }
186
+ // ─── CLI (direct invocation) ──────────────────────────────────────────────────
187
+ const isMain = process.argv[1]?.endsWith('ci-triage.ts') || process.argv[1]?.endsWith('ci-triage.js');
188
+ if (isMain) {
189
+ const cwd = process.argv[2] || process.cwd();
190
+ const result = fullTriage(cwd);
191
+ process.stdout.write(JSON.stringify(result, null, 2) + '\n');
192
+ }
193
+ //# sourceMappingURL=ci-triage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ci-triage.js","sourceRoot":"","sources":["../../src/ci-triage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAgB,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAY;IACnC,MAAM,IAAI,GAAG,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAClC,MAAM,OAAO,GAAG,EAAE,C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CAAC,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC;AACtG,IAAI,MAAM,EAAE,CAAC;IACX,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAC7C,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;IAC/B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AAC/D,CAAC"}
@@ -0,0 +1,56 @@
1
+ interface LoopAction {
2
+ type: string;
3
+ mode?: string;
4
+ }
5
+ interface LoopResult {
6
+ phase: string;
7
+ action: LoopAction;
8
+ rationale?: string;
9
+ shouldAskUser?: boolean;
10
+ surfaceNoticings?: unknown[];
11
+ plan: unknown | null;
12
+ nextDispatch: unknown | null;
13
+ mode?: {
14
+ primary: string;
15
+ confidence: number;
16
+ };
17
+ estimatedCost?: number;
18
+ suggestion?: unknown;
19
+ waveSummary?: unknown;
20
+ replanned?: boolean;
21
+ gateCondition?: string;
22
+ }
23
+ interface LoopContext {
24
+ files?: string[];
25
+ recentFiles?: string[];
26
+ priorFailures?: unknown[];
27
+ uncommittedFiles?: string[];
28
+ _detectedIntent?: string | null;
29
+ _immersionContext?: string;
30
+ _inboxBrief?: string;
31
+ _crystallizedIdeas?: string[];
32
+ _updateNotice?: string;
33
+ priorDebriefs?: unknown[];
34
+ [key: string]: unknown;
35
+ }
36
+ /**
37
+ * Entry point: process a user message through the full cognitive loop.
38
+ * Returns a LoopResult that tells the caller exactly what to do next.
39
+ */
40
+ export declare function enter(userMessage: string, context?: LoopContext): LoopResult;
41
+ /**
42
+ * Called after a wave completes. Processes debriefs and determines next action.
43
+ */
44
+ export declare function advance(rawResults: string[], completedWaveId: string, context?: LoopContext): LoopResult;
45
+ export declare function getActivePlan(): unknown;
46
+ export declare function getLoopStatus(): {
47
+ hasActivePlan: boolean;
48
+ completedWaves: number;
49
+ totalWaves: number;
50
+ replans: number;
51
+ totalDispatches: number;
52
+ debriefCount: number;
53
+ };
54
+ export declare function resetLoop(): void;
55
+ export declare function shutdown(): void;
56
+ export {};