@cleocode/core 2026.6.13 → 2026.6.15

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 (485) hide show
  1. package/dist/admin/ops.d.ts +4 -0
  2. package/dist/admin/ops.d.ts.map +1 -1
  3. package/dist/check/index.d.ts +12 -0
  4. package/dist/check/index.d.ts.map +1 -0
  5. package/dist/check/index.js +12 -0
  6. package/dist/check/index.js.map +1 -0
  7. package/dist/check/pr-gate.d.ts +183 -0
  8. package/dist/check/pr-gate.d.ts.map +1 -0
  9. package/dist/check/pr-gate.js +348 -0
  10. package/dist/check/pr-gate.js.map +1 -0
  11. package/dist/conduit/delivery-router.d.ts +134 -0
  12. package/dist/conduit/delivery-router.d.ts.map +1 -0
  13. package/dist/conduit/delivery-router.js +0 -0
  14. package/dist/conduit/delivery-router.js.map +1 -0
  15. package/dist/conduit/index.d.ts +5 -2
  16. package/dist/conduit/index.d.ts.map +1 -1
  17. package/dist/conduit/index.js +5 -2
  18. package/dist/conduit/index.js.map +1 -1
  19. package/dist/conduit/local-tui-adapter.d.ts +89 -0
  20. package/dist/conduit/local-tui-adapter.d.ts.map +1 -0
  21. package/dist/conduit/local-tui-adapter.js +225 -0
  22. package/dist/conduit/local-tui-adapter.js.map +1 -0
  23. package/dist/config/config-repair.d.ts +70 -0
  24. package/dist/config/config-repair.d.ts.map +1 -0
  25. package/dist/config/config-repair.js +248 -0
  26. package/dist/config/config-repair.js.map +1 -0
  27. package/dist/config/registry.d.ts +54 -0
  28. package/dist/config/registry.d.ts.map +1 -1
  29. package/dist/config/registry.js +92 -0
  30. package/dist/config/registry.js.map +1 -1
  31. package/dist/config.d.ts.map +1 -1
  32. package/dist/config.js +11 -10
  33. package/dist/config.js.map +1 -1
  34. package/dist/deriver/queue-manager.d.ts +30 -2
  35. package/dist/deriver/queue-manager.d.ts.map +1 -1
  36. package/dist/deriver/queue-manager.js +54 -9
  37. package/dist/deriver/queue-manager.js.map +1 -1
  38. package/dist/dispatch/config-domain-handler.d.ts +125 -0
  39. package/dist/dispatch/config-domain-handler.d.ts.map +1 -0
  40. package/dist/dispatch/config-domain-handler.js +160 -0
  41. package/dist/dispatch/config-domain-handler.js.map +1 -0
  42. package/dist/dispatch/contracts/input-contracts.d.ts.map +1 -1
  43. package/dist/dispatch/contracts/input-contracts.js +19 -1
  44. package/dist/dispatch/contracts/input-contracts.js.map +1 -1
  45. package/dist/docs/export-document.js +3721 -696
  46. package/dist/docs/export-document.js.map +3 -3
  47. package/dist/gateway-client/client.d.ts +123 -0
  48. package/dist/gateway-client/client.d.ts.map +1 -0
  49. package/dist/gateway-client/client.js +93 -0
  50. package/dist/gateway-client/client.js.map +1 -0
  51. package/dist/gateway-client/generated/client/client.gen.d.ts +3 -0
  52. package/dist/gateway-client/generated/client/client.gen.d.ts.map +1 -0
  53. package/dist/gateway-client/generated/client/client.gen.js +217 -0
  54. package/dist/gateway-client/generated/client/client.gen.js.map +1 -0
  55. package/dist/gateway-client/generated/client/index.d.ts +11 -0
  56. package/dist/gateway-client/generated/client/index.d.ts.map +1 -0
  57. package/dist/gateway-client/generated/client/index.js +7 -0
  58. package/dist/gateway-client/generated/client/index.js.map +1 -0
  59. package/dist/gateway-client/generated/client/types.gen.d.ts +121 -0
  60. package/dist/gateway-client/generated/client/types.gen.d.ts.map +1 -0
  61. package/dist/gateway-client/generated/client/types.gen.js +3 -0
  62. package/dist/gateway-client/generated/client/types.gen.js.map +1 -0
  63. package/dist/gateway-client/generated/client/utils.gen.d.ts +38 -0
  64. package/dist/gateway-client/generated/client/utils.gen.d.ts.map +1 -0
  65. package/dist/gateway-client/generated/client/utils.gen.js +229 -0
  66. package/dist/gateway-client/generated/client/utils.gen.js.map +1 -0
  67. package/dist/gateway-client/generated/client.gen.d.ts +13 -0
  68. package/dist/gateway-client/generated/client.gen.d.ts.map +1 -0
  69. package/dist/gateway-client/generated/client.gen.js +4 -0
  70. package/dist/gateway-client/generated/client.gen.js.map +1 -0
  71. package/dist/gateway-client/generated/core/auth.gen.d.ts +26 -0
  72. package/dist/gateway-client/generated/core/auth.gen.d.ts.map +1 -0
  73. package/dist/gateway-client/generated/core/auth.gen.js +15 -0
  74. package/dist/gateway-client/generated/core/auth.gen.js.map +1 -0
  75. package/dist/gateway-client/generated/core/bodySerializer.gen.d.ts +26 -0
  76. package/dist/gateway-client/generated/core/bodySerializer.gen.d.ts.map +1 -0
  77. package/dist/gateway-client/generated/core/bodySerializer.gen.js +58 -0
  78. package/dist/gateway-client/generated/core/bodySerializer.gen.js.map +1 -0
  79. package/dist/gateway-client/generated/core/params.gen.d.ts +44 -0
  80. package/dist/gateway-client/generated/core/params.gen.d.ts.map +1 -0
  81. package/dist/gateway-client/generated/core/params.gen.js +101 -0
  82. package/dist/gateway-client/generated/core/params.gen.js.map +1 -0
  83. package/dist/gateway-client/generated/core/pathSerializer.gen.d.ts +34 -0
  84. package/dist/gateway-client/generated/core/pathSerializer.gen.d.ts.map +1 -0
  85. package/dist/gateway-client/generated/core/pathSerializer.gen.js +107 -0
  86. package/dist/gateway-client/generated/core/pathSerializer.gen.js.map +1 -0
  87. package/dist/gateway-client/generated/core/queryKeySerializer.gen.d.ts +19 -0
  88. package/dist/gateway-client/generated/core/queryKeySerializer.gen.d.ts.map +1 -0
  89. package/dist/gateway-client/generated/core/queryKeySerializer.gen.js +93 -0
  90. package/dist/gateway-client/generated/core/queryKeySerializer.gen.js.map +1 -0
  91. package/dist/gateway-client/generated/core/serverSentEvents.gen.d.ts +72 -0
  92. package/dist/gateway-client/generated/core/serverSentEvents.gen.d.ts.map +1 -0
  93. package/dist/gateway-client/generated/core/serverSentEvents.gen.js +133 -0
  94. package/dist/gateway-client/generated/core/serverSentEvents.gen.js.map +1 -0
  95. package/dist/gateway-client/generated/core/types.gen.d.ts +84 -0
  96. package/dist/gateway-client/generated/core/types.gen.d.ts.map +1 -0
  97. package/dist/gateway-client/generated/core/types.gen.js +3 -0
  98. package/dist/gateway-client/generated/core/types.gen.js.map +1 -0
  99. package/dist/gateway-client/generated/core/utils.gen.d.ts +20 -0
  100. package/dist/gateway-client/generated/core/utils.gen.d.ts.map +1 -0
  101. package/dist/gateway-client/generated/core/utils.gen.js +88 -0
  102. package/dist/gateway-client/generated/core/utils.gen.js.map +1 -0
  103. package/dist/gateway-client/generated/index.d.ts +3 -0
  104. package/dist/gateway-client/generated/index.d.ts.map +1 -0
  105. package/dist/gateway-client/generated/index.js +3 -0
  106. package/dist/gateway-client/generated/index.js.map +1 -0
  107. package/dist/gateway-client/generated/namespaces.gen.d.ts +512 -0
  108. package/dist/gateway-client/generated/namespaces.gen.d.ts.map +1 -0
  109. package/dist/gateway-client/generated/namespaces.gen.js +521 -0
  110. package/dist/gateway-client/generated/namespaces.gen.js.map +1 -0
  111. package/dist/gateway-client/generated/sdk.gen.d.ts +1780 -0
  112. package/dist/gateway-client/generated/sdk.gen.d.ts.map +1 -0
  113. package/dist/gateway-client/generated/sdk.gen.js +3811 -0
  114. package/dist/gateway-client/generated/sdk.gen.js.map +1 -0
  115. package/dist/gateway-client/generated/types.gen.d.ts +14681 -0
  116. package/dist/gateway-client/generated/types.gen.d.ts.map +1 -0
  117. package/dist/gateway-client/generated/types.gen.js +3 -0
  118. package/dist/gateway-client/generated/types.gen.js.map +1 -0
  119. package/dist/gateway-client/index.d.ts +27 -0
  120. package/dist/gateway-client/index.d.ts.map +1 -0
  121. package/dist/gateway-client/index.js +25 -0
  122. package/dist/gateway-client/index.js.map +1 -0
  123. package/dist/gc/cleanup.d.ts +23 -8
  124. package/dist/gc/cleanup.d.ts.map +1 -1
  125. package/dist/gc/cleanup.js +287 -22
  126. package/dist/gc/cleanup.js.map +1 -1
  127. package/dist/index.d.ts +10 -0
  128. package/dist/index.d.ts.map +1 -1
  129. package/dist/index.js +20 -0
  130. package/dist/index.js.map +1 -1
  131. package/dist/init.d.ts.map +1 -1
  132. package/dist/init.js +28 -0
  133. package/dist/init.js.map +1 -1
  134. package/dist/internal.d.ts +10 -1
  135. package/dist/internal.d.ts.map +1 -1
  136. package/dist/internal.js +18 -1
  137. package/dist/internal.js.map +1 -1
  138. package/dist/llm/catalog-model-resolver.d.ts +19 -0
  139. package/dist/llm/catalog-model-resolver.d.ts.map +1 -1
  140. package/dist/llm/catalog-model-resolver.js +36 -0
  141. package/dist/llm/catalog-model-resolver.js.map +1 -1
  142. package/dist/llm/catalog-resolver.d.ts +112 -0
  143. package/dist/llm/catalog-resolver.d.ts.map +1 -0
  144. package/dist/llm/catalog-resolver.js +207 -0
  145. package/dist/llm/catalog-resolver.js.map +1 -0
  146. package/dist/llm/catalog-seeder.d.ts +96 -0
  147. package/dist/llm/catalog-seeder.d.ts.map +1 -0
  148. package/dist/llm/catalog-seeder.js +189 -0
  149. package/dist/llm/catalog-seeder.js.map +1 -0
  150. package/dist/llm/cli-ops.d.ts +16 -0
  151. package/dist/llm/cli-ops.d.ts.map +1 -1
  152. package/dist/llm/cli-ops.js +37 -10
  153. package/dist/llm/cli-ops.js.map +1 -1
  154. package/dist/llm/complexity-classifier.d.ts +208 -0
  155. package/dist/llm/complexity-classifier.d.ts.map +1 -0
  156. package/dist/llm/complexity-classifier.js +359 -0
  157. package/dist/llm/complexity-classifier.js.map +1 -0
  158. package/dist/llm/credential-pool.d.ts +2 -0
  159. package/dist/llm/credential-pool.d.ts.map +1 -1
  160. package/dist/llm/credential-pool.js +5 -2
  161. package/dist/llm/credential-pool.js.map +1 -1
  162. package/dist/llm/credentials-store.d.ts +10 -14
  163. package/dist/llm/credentials-store.d.ts.map +1 -1
  164. package/dist/llm/credentials-store.js.map +1 -1
  165. package/dist/llm/cross-provider-selector.d.ts +249 -0
  166. package/dist/llm/cross-provider-selector.d.ts.map +1 -0
  167. package/dist/llm/cross-provider-selector.js +572 -0
  168. package/dist/llm/cross-provider-selector.js.map +1 -0
  169. package/dist/llm/entity-ops.d.ts +299 -0
  170. package/dist/llm/entity-ops.d.ts.map +1 -0
  171. package/dist/llm/entity-ops.js +441 -0
  172. package/dist/llm/entity-ops.js.map +1 -0
  173. package/dist/llm/index.d.ts +17 -0
  174. package/dist/llm/index.d.ts.map +1 -1
  175. package/dist/llm/index.js +9 -0
  176. package/dist/llm/index.js.map +1 -1
  177. package/dist/llm/llm-queue-admit.d.ts +118 -0
  178. package/dist/llm/llm-queue-admit.d.ts.map +1 -0
  179. package/dist/llm/llm-queue-admit.js +275 -0
  180. package/dist/llm/llm-queue-admit.js.map +1 -0
  181. package/dist/llm/local-model-fit.d.ts +260 -0
  182. package/dist/llm/local-model-fit.d.ts.map +1 -0
  183. package/dist/llm/local-model-fit.js +563 -0
  184. package/dist/llm/local-model-fit.js.map +1 -0
  185. package/dist/llm/oauth/device-code.d.ts.map +1 -1
  186. package/dist/llm/oauth/device-code.js +2 -8
  187. package/dist/llm/oauth/device-code.js.map +1 -1
  188. package/dist/llm/oauth/google-pkce.d.ts.map +1 -1
  189. package/dist/llm/oauth/google-pkce.js +2 -18
  190. package/dist/llm/oauth/google-pkce.js.map +1 -1
  191. package/dist/llm/oauth/pkce.d.ts +70 -0
  192. package/dist/llm/oauth/pkce.d.ts.map +1 -1
  193. package/dist/llm/oauth/pkce.js +106 -29
  194. package/dist/llm/oauth/pkce.js.map +1 -1
  195. package/dist/llm/onboarding/front-door.d.ts +146 -0
  196. package/dist/llm/onboarding/front-door.d.ts.map +1 -0
  197. package/dist/llm/onboarding/front-door.js +153 -0
  198. package/dist/llm/onboarding/front-door.js.map +1 -0
  199. package/dist/llm/onboarding/login-engine.d.ts +175 -0
  200. package/dist/llm/onboarding/login-engine.d.ts.map +1 -0
  201. package/dist/llm/onboarding/login-engine.js +286 -0
  202. package/dist/llm/onboarding/login-engine.js.map +1 -0
  203. package/dist/llm/pi/pi-gondolin-env.d.ts +23 -0
  204. package/dist/llm/pi/pi-gondolin-env.d.ts.map +1 -1
  205. package/dist/llm/pi/pi-gondolin-env.js +2 -2
  206. package/dist/llm/pi/pi-gondolin-env.js.map +1 -1
  207. package/dist/llm/plugin-facade.js +4612 -1042
  208. package/dist/llm/plugin-facade.js.map +3 -3
  209. package/dist/llm/provider-registry/builtin/anthropic.d.ts.map +1 -1
  210. package/dist/llm/provider-registry/builtin/anthropic.js +23 -10
  211. package/dist/llm/provider-registry/builtin/anthropic.js.map +1 -1
  212. package/dist/llm/provider-registry/builtin/ollama.d.ts +18 -0
  213. package/dist/llm/provider-registry/builtin/ollama.d.ts.map +1 -1
  214. package/dist/llm/provider-registry/builtin/ollama.js +20 -2
  215. package/dist/llm/provider-registry/builtin/ollama.js.map +1 -1
  216. package/dist/llm/provider-registry/provider-alias.d.ts +62 -0
  217. package/dist/llm/provider-registry/provider-alias.d.ts.map +1 -0
  218. package/dist/llm/provider-registry/provider-alias.js +85 -0
  219. package/dist/llm/provider-registry/provider-alias.js.map +1 -0
  220. package/dist/llm/provider-registry/provider-defs.d.ts +45 -0
  221. package/dist/llm/provider-registry/provider-defs.d.ts.map +1 -0
  222. package/dist/llm/provider-registry/provider-defs.js +145 -0
  223. package/dist/llm/provider-registry/provider-defs.js.map +1 -0
  224. package/dist/llm/provider-registry/provider-seed.d.ts +78 -0
  225. package/dist/llm/provider-registry/provider-seed.d.ts.map +1 -0
  226. package/dist/llm/provider-registry/provider-seed.js +113 -0
  227. package/dist/llm/provider-registry/provider-seed.js.map +1 -0
  228. package/dist/llm/role-executor.d.ts.map +1 -1
  229. package/dist/llm/role-executor.js +36 -0
  230. package/dist/llm/role-executor.js.map +1 -1
  231. package/dist/llm/role-resolver.d.ts.map +1 -1
  232. package/dist/llm/role-resolver.js +52 -10
  233. package/dist/llm/role-resolver.js.map +1 -1
  234. package/dist/llm/system-resolver.d.ts.map +1 -1
  235. package/dist/llm/system-resolver.js +73 -22
  236. package/dist/llm/system-resolver.js.map +1 -1
  237. package/dist/llm/transports/codex-responses.d.ts +111 -88
  238. package/dist/llm/transports/codex-responses.d.ts.map +1 -1
  239. package/dist/llm/transports/codex-responses.js +456 -258
  240. package/dist/llm/transports/codex-responses.js.map +1 -1
  241. package/dist/memory/learnings.d.ts +4 -0
  242. package/dist/memory/learnings.d.ts.map +1 -1
  243. package/dist/memory/patterns.d.ts +4 -0
  244. package/dist/memory/patterns.d.ts.map +1 -1
  245. package/dist/metrics/index.d.ts +2 -0
  246. package/dist/metrics/index.d.ts.map +1 -1
  247. package/dist/metrics/index.js +1 -0
  248. package/dist/metrics/index.js.map +1 -1
  249. package/dist/orchestration/spawn.d.ts +89 -0
  250. package/dist/orchestration/spawn.d.ts.map +1 -1
  251. package/dist/orchestration/spawn.js +68 -0
  252. package/dist/orchestration/spawn.js.map +1 -1
  253. package/dist/playbooks/cantbook-profile.d.ts +96 -0
  254. package/dist/playbooks/cantbook-profile.d.ts.map +1 -0
  255. package/dist/playbooks/cantbook-profile.js +97 -0
  256. package/dist/playbooks/cantbook-profile.js.map +1 -0
  257. package/dist/playbooks/guarded-deterministic-runner.d.ts +153 -0
  258. package/dist/playbooks/guarded-deterministic-runner.d.ts.map +1 -0
  259. package/dist/playbooks/guarded-deterministic-runner.js +155 -0
  260. package/dist/playbooks/guarded-deterministic-runner.js.map +1 -0
  261. package/dist/playbooks/index.d.ts +2 -0
  262. package/dist/playbooks/index.d.ts.map +1 -1
  263. package/dist/playbooks/index.js +10 -0
  264. package/dist/playbooks/index.js.map +1 -1
  265. package/dist/playbooks/pi-runner-wiring.d.ts +75 -0
  266. package/dist/playbooks/pi-runner-wiring.d.ts.map +1 -0
  267. package/dist/playbooks/pi-runner-wiring.js +82 -0
  268. package/dist/playbooks/pi-runner-wiring.js.map +1 -0
  269. package/dist/release/index.d.ts +2 -2
  270. package/dist/release/index.d.ts.map +1 -1
  271. package/dist/release/index.js +1 -1
  272. package/dist/release/index.js.map +1 -1
  273. package/dist/release/reconcile.d.ts +97 -0
  274. package/dist/release/reconcile.d.ts.map +1 -1
  275. package/dist/release/reconcile.js +412 -5
  276. package/dist/release/reconcile.js.map +1 -1
  277. package/dist/resources/backend.d.ts +155 -0
  278. package/dist/resources/backend.d.ts.map +1 -0
  279. package/dist/resources/backend.js +23 -0
  280. package/dist/resources/backend.js.map +1 -0
  281. package/dist/resources/linux-backend.d.ts +167 -0
  282. package/dist/resources/linux-backend.d.ts.map +1 -0
  283. package/dist/resources/linux-backend.js +259 -0
  284. package/dist/resources/linux-backend.js.map +1 -0
  285. package/dist/resources/monitor.d.ts +230 -0
  286. package/dist/resources/monitor.d.ts.map +1 -0
  287. package/dist/resources/monitor.js +255 -0
  288. package/dist/resources/monitor.js.map +1 -0
  289. package/dist/resources/spawn-wrapper.d.ts +265 -0
  290. package/dist/resources/spawn-wrapper.d.ts.map +1 -0
  291. package/dist/resources/spawn-wrapper.js +304 -0
  292. package/dist/resources/spawn-wrapper.js.map +1 -0
  293. package/dist/runtime/openapi/generate-openapi.d.ts +211 -0
  294. package/dist/runtime/openapi/generate-openapi.d.ts.map +1 -0
  295. package/dist/runtime/openapi/generate-openapi.js +300 -0
  296. package/dist/runtime/openapi/generate-openapi.js.map +1 -0
  297. package/dist/runtime/openapi/index.d.ts +16 -0
  298. package/dist/runtime/openapi/index.d.ts.map +1 -0
  299. package/dist/runtime/openapi/index.js +16 -0
  300. package/dist/runtime/openapi/index.js.map +1 -0
  301. package/dist/selfimprove/budget.d.ts +11 -2
  302. package/dist/selfimprove/budget.d.ts.map +1 -1
  303. package/dist/selfimprove/budget.js +11 -2
  304. package/dist/selfimprove/budget.js.map +1 -1
  305. package/dist/selfimprove/fix-gen.d.ts +229 -0
  306. package/dist/selfimprove/fix-gen.d.ts.map +1 -0
  307. package/dist/selfimprove/fix-gen.js +266 -0
  308. package/dist/selfimprove/fix-gen.js.map +1 -0
  309. package/dist/selfimprove/run-loop.d.ts +44 -4
  310. package/dist/selfimprove/run-loop.d.ts.map +1 -1
  311. package/dist/selfimprove/run-loop.js +73 -6
  312. package/dist/selfimprove/run-loop.js.map +1 -1
  313. package/dist/selfimprove/scenarios/dhq-replay-find/golden.json +32 -0
  314. package/dist/selfimprove/scenarios/dhq-replay-find/scenario.json +18 -0
  315. package/dist/sentient/cross-project-hygiene.d.ts +11 -2
  316. package/dist/sentient/cross-project-hygiene.d.ts.map +1 -1
  317. package/dist/sentient/cross-project-hygiene.js +73 -10
  318. package/dist/sentient/cross-project-hygiene.js.map +1 -1
  319. package/dist/sentient/daemon.d.ts.map +1 -1
  320. package/dist/sentient/daemon.js +7 -2
  321. package/dist/sentient/daemon.js.map +1 -1
  322. package/dist/sentient/worktree-dispatch.d.ts.map +1 -1
  323. package/dist/sentient/worktree-dispatch.js +8 -1
  324. package/dist/sentient/worktree-dispatch.js.map +1 -1
  325. package/dist/setup/config-json-merge.d.ts.map +1 -1
  326. package/dist/setup/config-json-merge.js +14 -0
  327. package/dist/setup/config-json-merge.js.map +1 -1
  328. package/dist/setup/index.d.ts +23 -11
  329. package/dist/setup/index.d.ts.map +1 -1
  330. package/dist/setup/index.js +25 -12
  331. package/dist/setup/index.js.map +1 -1
  332. package/dist/setup/sections/llm.d.ts +28 -1
  333. package/dist/setup/sections/llm.d.ts.map +1 -1
  334. package/dist/setup/sections/llm.js +27 -6
  335. package/dist/setup/sections/llm.js.map +1 -1
  336. package/dist/setup/sections/models-roles.d.ts +40 -0
  337. package/dist/setup/sections/models-roles.d.ts.map +1 -0
  338. package/dist/setup/sections/models-roles.js +219 -0
  339. package/dist/setup/sections/models-roles.js.map +1 -0
  340. package/dist/setup/wizard.d.ts +19 -1
  341. package/dist/setup/wizard.d.ts.map +1 -1
  342. package/dist/setup/wizard.js.map +1 -1
  343. package/dist/spawn/branch-lock.d.ts.map +1 -1
  344. package/dist/spawn/branch-lock.js +7 -1
  345. package/dist/spawn/branch-lock.js.map +1 -1
  346. package/dist/store/attachment-repair.d.ts +110 -0
  347. package/dist/store/attachment-repair.d.ts.map +1 -0
  348. package/dist/store/attachment-repair.js +326 -0
  349. package/dist/store/attachment-repair.js.map +1 -0
  350. package/dist/store/attachment-store.d.ts.map +1 -1
  351. package/dist/store/attachment-store.js +24 -7
  352. package/dist/store/attachment-store.js.map +1 -1
  353. package/dist/store/schedule-schema.d.ts +195 -0
  354. package/dist/store/schedule-schema.d.ts.map +1 -0
  355. package/dist/store/schedule-schema.js +84 -0
  356. package/dist/store/schedule-schema.js.map +1 -0
  357. package/dist/store/schedule-store.d.ts +144 -0
  358. package/dist/store/schedule-store.d.ts.map +1 -0
  359. package/dist/store/schedule-store.js +162 -0
  360. package/dist/store/schedule-store.js.map +1 -0
  361. package/dist/store/schema/attachments.d.ts +1 -1
  362. package/dist/store/schema/cleo-global/index.d.ts +3 -0
  363. package/dist/store/schema/cleo-global/index.d.ts.map +1 -1
  364. package/dist/store/schema/cleo-global/index.js +5 -0
  365. package/dist/store/schema/cleo-global/index.js.map +1 -1
  366. package/dist/store/schema/cleo-global/models-catalog.d.ts +359 -0
  367. package/dist/store/schema/cleo-global/models-catalog.d.ts.map +1 -0
  368. package/dist/store/schema/cleo-global/models-catalog.js +114 -0
  369. package/dist/store/schema/cleo-global/models-catalog.js.map +1 -0
  370. package/dist/store/schema/cleo-global/providers.d.ts +279 -0
  371. package/dist/store/schema/cleo-global/providers.d.ts.map +1 -0
  372. package/dist/store/schema/cleo-global/providers.js +94 -0
  373. package/dist/store/schema/cleo-global/providers.js.map +1 -0
  374. package/dist/store/schema/cleo-global/services.d.ts +493 -0
  375. package/dist/store/schema/cleo-global/services.d.ts.map +1 -0
  376. package/dist/store/schema/cleo-global/services.js +200 -0
  377. package/dist/store/schema/cleo-global/services.js.map +1 -0
  378. package/dist/store/schema/cleo-project/docs.d.ts +1 -1
  379. package/dist/store/schema/cleo-project/provenance-rest.d.ts +1 -1
  380. package/dist/store/schema/cleo-shared/brain.d.ts +2 -2
  381. package/dist/store/schema/memory-schema.d.ts +182 -2
  382. package/dist/store/schema/memory-schema.d.ts.map +1 -1
  383. package/dist/store/schema/memory-schema.js +111 -2
  384. package/dist/store/schema/memory-schema.js.map +1 -1
  385. package/dist/store/schema/provenance/releases.d.ts +1 -1
  386. package/dist/store/service-connections-accessor.d.ts +313 -0
  387. package/dist/store/service-connections-accessor.d.ts.map +1 -0
  388. package/dist/store/service-connections-accessor.js +464 -0
  389. package/dist/store/service-connections-accessor.js.map +1 -0
  390. package/dist/store/service-host-matcher.d.ts +70 -0
  391. package/dist/store/service-host-matcher.d.ts.map +1 -0
  392. package/dist/store/service-host-matcher.js +127 -0
  393. package/dist/store/service-host-matcher.js.map +1 -0
  394. package/dist/store/service-injection.d.ts +152 -0
  395. package/dist/store/service-injection.d.ts.map +1 -0
  396. package/dist/store/service-injection.js +225 -0
  397. package/dist/store/service-injection.js.map +1 -0
  398. package/dist/store/service-oauth.d.ts +287 -0
  399. package/dist/store/service-oauth.d.ts.map +1 -0
  400. package/dist/store/service-oauth.js +524 -0
  401. package/dist/store/service-oauth.js.map +1 -0
  402. package/dist/store/service-trust-gate.d.ts +164 -0
  403. package/dist/store/service-trust-gate.d.ts.map +1 -0
  404. package/dist/store/service-trust-gate.js +122 -0
  405. package/dist/store/service-trust-gate.js.map +1 -0
  406. package/dist/store/validation-schemas.d.ts +4 -4
  407. package/dist/tasks/agent-lifecycle-lane.d.ts +175 -0
  408. package/dist/tasks/agent-lifecycle-lane.d.ts.map +1 -0
  409. package/dist/tasks/agent-lifecycle-lane.js +176 -0
  410. package/dist/tasks/agent-lifecycle-lane.js.map +1 -0
  411. package/dist/tasks/complete.d.ts +17 -0
  412. package/dist/tasks/complete.d.ts.map +1 -1
  413. package/dist/tasks/complete.js +53 -10
  414. package/dist/tasks/complete.js.map +1 -1
  415. package/dist/tasks/depends-waiver-audit.d.ts +52 -0
  416. package/dist/tasks/depends-waiver-audit.d.ts.map +1 -0
  417. package/dist/tasks/depends-waiver-audit.js +36 -0
  418. package/dist/tasks/depends-waiver-audit.js.map +1 -0
  419. package/dist/tasks/engine-wrap.d.ts +36 -2
  420. package/dist/tasks/engine-wrap.d.ts.map +1 -1
  421. package/dist/tasks/engine-wrap.js +44 -2
  422. package/dist/tasks/engine-wrap.js.map +1 -1
  423. package/dist/tasks/evidence.d.ts +34 -2
  424. package/dist/tasks/evidence.d.ts.map +1 -1
  425. package/dist/tasks/evidence.js +293 -35
  426. package/dist/tasks/evidence.js.map +1 -1
  427. package/dist/tasks/index.d.ts +1 -0
  428. package/dist/tasks/index.d.ts.map +1 -1
  429. package/dist/tasks/index.js +1 -0
  430. package/dist/tasks/index.js.map +1 -1
  431. package/dist/tasks/ops.d.ts +3 -0
  432. package/dist/tasks/ops.d.ts.map +1 -1
  433. package/dist/tasks/task-ops.d.ts +1 -1
  434. package/dist/tasks/task-ops.d.ts.map +1 -1
  435. package/dist/tasks/task-ops.js +3 -1
  436. package/dist/tasks/task-ops.js.map +1 -1
  437. package/dist/tasks/task-reparent.d.ts +90 -0
  438. package/dist/tasks/task-reparent.d.ts.map +1 -1
  439. package/dist/tasks/task-reparent.js +171 -0
  440. package/dist/tasks/task-reparent.js.map +1 -1
  441. package/dist/tools/builtin-agent-tools.d.ts.map +1 -1
  442. package/dist/tools/builtin-agent-tools.js +41 -0
  443. package/dist/tools/builtin-agent-tools.js.map +1 -1
  444. package/dist/tools/exec-code-agent-tool.d.ts +179 -0
  445. package/dist/tools/exec-code-agent-tool.d.ts.map +1 -0
  446. package/dist/tools/exec-code-agent-tool.js +239 -0
  447. package/dist/tools/exec-code-agent-tool.js.map +1 -0
  448. package/dist/tools/index.d.ts +6 -0
  449. package/dist/tools/index.d.ts.map +1 -1
  450. package/dist/tools/index.js +15 -0
  451. package/dist/tools/index.js.map +1 -1
  452. package/dist/tools/mcp-agent-tool.d.ts +189 -0
  453. package/dist/tools/mcp-agent-tool.d.ts.map +1 -0
  454. package/dist/tools/mcp-agent-tool.js +243 -0
  455. package/dist/tools/mcp-agent-tool.js.map +1 -0
  456. package/dist/tools/media-agent-tools.d.ts +105 -0
  457. package/dist/tools/media-agent-tools.d.ts.map +1 -0
  458. package/dist/tools/media-agent-tools.js +255 -0
  459. package/dist/tools/media-agent-tools.js.map +1 -0
  460. package/dist/tools/memory-agent-tools.d.ts +99 -0
  461. package/dist/tools/memory-agent-tools.d.ts.map +1 -0
  462. package/dist/tools/memory-agent-tools.js +190 -0
  463. package/dist/tools/memory-agent-tools.js.map +1 -0
  464. package/dist/tools/schedule-agent-tools.d.ts +151 -0
  465. package/dist/tools/schedule-agent-tools.d.ts.map +1 -0
  466. package/dist/tools/schedule-agent-tools.js +238 -0
  467. package/dist/tools/schedule-agent-tools.js.map +1 -0
  468. package/dist/tools/skill-agent-tool.d.ts +108 -0
  469. package/dist/tools/skill-agent-tool.d.ts.map +1 -0
  470. package/dist/tools/skill-agent-tool.js +135 -0
  471. package/dist/tools/skill-agent-tool.js.map +1 -0
  472. package/dist/validation/engine-ops.d.ts.map +1 -1
  473. package/dist/validation/engine-ops.js +17 -1
  474. package/dist/validation/engine-ops.js.map +1 -1
  475. package/dist/verification/verify-tools.d.ts.map +1 -1
  476. package/dist/verification/verify-tools.js +5 -6
  477. package/dist/verification/verify-tools.js.map +1 -1
  478. package/migrations/drizzle-brain/20260610000001_t10405-bitemporal-network-columns/migration.sql +71 -0
  479. package/migrations/drizzle-cleo-global/20260609000000_t11937-service-vault/migration.sql +93 -0
  480. package/migrations/drizzle-cleo-global/20260609010000_t11733-models-catalog/migration.sql +65 -0
  481. package/migrations/drizzle-cleo-global/20260609020000_t11703-providers/migration.sql +52 -0
  482. package/migrations/drizzle-cleo-global/20260610000000_t11962-schedules/migration.sql +48 -0
  483. package/migrations/drizzle-cleo-project/20260610000000_t11962-schedules/migration.sql +48 -0
  484. package/package.json +33 -13
  485. package/templates/workflows/release-prepare.yml.tmpl +48 -2
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Fix-generation stage for the self-improvement loop (T11889 · T11975).
3
+ *
4
+ * This is the missing autonomous link the v1 loop explicitly stubbed out
5
+ * ("NO autonomous fix-gen in v1", see {@link "./run-loop.js"}): given a detected
6
+ * regression (an open `selfimprove_dhq` + its envelope-diff) plus minimal repo
7
+ * context, it asks the LLM to PROPOSE a unified-diff patch and writes that patch
8
+ * to the path the draft-PR egress ({@link "./draft-pr.js".openDraftPr}) already
9
+ * `existsSync`-checks: `<cwd>/selfimprove-<scenario>.patch`. Once the patch is on
10
+ * disk the existing egress guard opens ONE DRAFT PR — closing the
11
+ * DHQ → fix → draft-PR pipeline end-to-end.
12
+ *
13
+ * ## Hard safety posture (unchanged from v1 — P5 spec §B.7)
14
+ *
15
+ * - **LLM ONLY via the E9 chokepoint.** The real generator
16
+ * ({@link createLlmFixGenerator}) resolves its model strictly through
17
+ * {@link "../llm/system-resolver.js".resolveLLMForSystem} → {@link ModelRunner}
18
+ * (Gate-13). It constructs NO raw provider client, reads NO `*_API_KEY` env,
19
+ * and hardcodes no model id — the resolver/registry is the SSoT. The
20
+ * plaintext token is materialized only at the wire boundary (E10).
21
+ * - **Draft-PR-ONLY, never auto-merge.** This module produces a PATCH FILE only;
22
+ * the egress that consumes it always opens a `--draft` PR against a feature
23
+ * branch (never `main`). This module performs NO git/gh action.
24
+ * - **Graceful degrade, never a rogue mutation.** Every failure (no credential,
25
+ * LLM error, empty / non-unified-diff output) returns a typed
26
+ * {@link FixGenResult} of kind `'skipped'` and writes NO patch file — so the
27
+ * existing egress guard (`existsSync` on the patch path) simply skips the PR.
28
+ * This function NEVER throws.
29
+ * - **Injectable seam.** The LLM dependency is the {@link FixGenerator} port;
30
+ * unit tests inject a deterministic fake that returns a canned patch, so NO
31
+ * real LLM is reached in tests.
32
+ *
33
+ * CORE-first: this engine lives in `core` and owns the `FixGenerator` port TYPE.
34
+ * Import-time side-effect-free.
35
+ *
36
+ * @module @cleocode/core/selfimprove/fix-gen
37
+ * @epic T11889
38
+ * @task T11975
39
+ */
40
+ import type { Logger } from 'pino';
41
+ import type { DiffEntry } from './envelope-diff.js';
42
+ /**
43
+ * The structured request handed to a {@link FixGenerator}. Carries only what the
44
+ * generator needs to draft a patch: the DHQ identity, the scenario, the
45
+ * regression diff, and a minimal slice of repo context.
46
+ */
47
+ export interface FixGenRequest {
48
+ /** The stable `'DHQ-###'` handle of the open regression. */
49
+ readonly dhqId: string;
50
+ /** The scenario whose replay diverged from the golden. */
51
+ readonly scenario: string;
52
+ /** The idempotency hash tying this request to ONE open DHQ row. */
53
+ readonly questionHash: string;
54
+ /** The structured regression entries (the evidence) from the envelope diff. */
55
+ readonly regressions: readonly DiffEntry[];
56
+ /**
57
+ * Minimal repo context the generator may use to ground the patch (e.g. the
58
+ * project root, a short description). Kept small on purpose — the loop does NOT
59
+ * stuff the whole repo into the prompt.
60
+ */
61
+ readonly repoContext: FixGenRepoContext;
62
+ }
63
+ /** Minimal repo context grounding a fix-generation request. */
64
+ export interface FixGenRepoContext {
65
+ /** Absolute project root the patch is generated against. */
66
+ readonly projectRoot: string;
67
+ /** Optional one-line summary of what the scenario exercises. */
68
+ readonly summary?: string;
69
+ }
70
+ /** A generated patch, or an explicit "no usable patch" signal. */
71
+ export type FixGenOutput = {
72
+ /** The generator produced a candidate unified-diff patch. */
73
+ readonly kind: 'patch';
74
+ /** The raw unified-diff text (validated by {@link generateFixPatch}). */
75
+ readonly diff: string;
76
+ /** The model id that produced it (for audit). */
77
+ readonly model: string;
78
+ } | {
79
+ /** The generator produced no usable patch (degrade — never an error throw). */
80
+ readonly kind: 'none';
81
+ /** Machine-stable reason for the absence. */
82
+ readonly reason: string;
83
+ };
84
+ /**
85
+ * The injectable fix-generation port (the LLM seam).
86
+ *
87
+ * The real implementation ({@link createLlmFixGenerator}) drives the E9 chokepoint;
88
+ * tests inject a deterministic fake returning a canned patch. A `FixGenerator`
89
+ * MUST NOT throw — it encodes "no patch" as `{ kind: 'none', reason }`.
90
+ */
91
+ export interface FixGenerator {
92
+ /**
93
+ * Propose a unified-diff patch for one regression.
94
+ *
95
+ * @param request - The structured {@link FixGenRequest}.
96
+ * @returns A {@link FixGenOutput} — a candidate patch or an explicit "none".
97
+ */
98
+ propose(request: FixGenRequest): Promise<FixGenOutput>;
99
+ }
100
+ /** The terminal outcome of {@link generateFixPatch}. */
101
+ export type FixGenResult = {
102
+ /** A validated patch was written to {@link FixGenResultWritten.patchPath}. */
103
+ readonly kind: 'written';
104
+ /** Absolute path the patch was written to. */
105
+ readonly patchPath: string;
106
+ /** Byte length of the written patch. */
107
+ readonly bytes: number;
108
+ /** The model id that produced the patch. */
109
+ readonly model: string;
110
+ } | {
111
+ /** No patch was written; the egress guard will skip the PR. */
112
+ readonly kind: 'skipped';
113
+ /** Machine-stable reason recorded on the DHQ evidence. */
114
+ readonly reason: string;
115
+ };
116
+ /**
117
+ * Options for {@link generateFixPatch}.
118
+ */
119
+ export interface GenerateFixPatchOptions {
120
+ /** The structured fix-generation request. */
121
+ readonly request: FixGenRequest;
122
+ /** The injected generator (real LLM impl or a test fake). */
123
+ readonly generator: FixGenerator;
124
+ /**
125
+ * Working directory the patch path is resolved against — MUST match the `cwd`
126
+ * the downstream {@link "./draft-pr.js".openDraftPr} uses, so the file it writes
127
+ * is the file the egress finds.
128
+ */
129
+ readonly cwd?: string;
130
+ /** Injectable logger (defaults to the module logger). */
131
+ readonly logger?: Logger;
132
+ }
133
+ /**
134
+ * Compute the patch path the draft-PR egress expects for a scenario:
135
+ * `<cwd>/selfimprove-<scenario>.patch`. The scenario is sanitized to a safe file
136
+ * stem so a hostile scenario name cannot escape the cwd.
137
+ *
138
+ * @param scenario - The scenario name.
139
+ * @param cwd - The working directory to resolve against (defaults to `process.cwd`).
140
+ * @returns The absolute patch path.
141
+ */
142
+ export declare function fixPatchPath(scenario: string, cwd?: string): string;
143
+ /**
144
+ * Is `text` a plausible unified diff?
145
+ *
146
+ * A real `git apply`-able patch always carries at least one of the canonical
147
+ * unified-diff markers ({@link UNIFIED_DIFF_MARKERS}). An LLM that returns prose,
148
+ * an apology, or an empty string fails this guard, so the loop degrades to "no
149
+ * patch" rather than writing junk the egress would then fail to `git apply`.
150
+ *
151
+ * This is a cheap structural sniff, NOT a full parse — the authoritative
152
+ * applicability check is `git apply` inside the egress (which fails the PR cut on
153
+ * a bad patch, never `main`).
154
+ *
155
+ * @param text - Candidate patch text.
156
+ * @returns `true` when the text looks like a unified diff.
157
+ */
158
+ export declare function looksLikeUnifiedDiff(text: string): boolean;
159
+ /**
160
+ * Build the system + user prompt the real generator sends to the LLM. Pure
161
+ * (no IO) so it is unit-testable in isolation. The prompt is deliberately strict:
162
+ * "respond with ONLY a unified diff" — anything else fails
163
+ * {@link looksLikeUnifiedDiff} downstream and degrades to "no patch".
164
+ *
165
+ * @param request - The fix-generation request.
166
+ * @returns The `{ system, user }` prompt pair.
167
+ */
168
+ export declare function buildFixGenPrompt(request: FixGenRequest): {
169
+ system: string;
170
+ user: string;
171
+ };
172
+ /**
173
+ * Run the fix-generation stage: ask the injected {@link FixGenerator} for a patch,
174
+ * validate it as a unified diff, and write it to the egress-expected patch path.
175
+ *
176
+ * This function NEVER throws and NEVER mutates anything but the single patch file.
177
+ * On ANY degrade path — generator returns `'none'`, the generator throws, or the
178
+ * returned text is not a unified diff — it writes NO file and returns
179
+ * `{ kind: 'skipped', reason }`, so the downstream `existsSync` egress guard
180
+ * simply skips the PR. The caller records the `reason` on the DHQ evidence.
181
+ *
182
+ * @param opts - See {@link GenerateFixPatchOptions}.
183
+ * @returns A {@link FixGenResult}.
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * const res = await generateFixPatch({
188
+ * request: { dhqId: 'DHQ-abcd1234', scenario, questionHash, regressions, repoContext },
189
+ * generator: createLlmFixGenerator(),
190
+ * cwd: projectRoot,
191
+ * });
192
+ * if (res.kind === 'written') { // openDraftPr will now find selfimprove-<scenario>.patch }
193
+ * ```
194
+ */
195
+ export declare function generateFixPatch(opts: GenerateFixPatchOptions): Promise<FixGenResult>;
196
+ /**
197
+ * Construct the REAL fix generator — the one that drives the E9 LLM chokepoint.
198
+ *
199
+ * Resolution funnels through {@link resolveLLMForSystem}(`'task-executor'`) →
200
+ * {@link ModelRunner.build} → `session.send` (ONE non-streaming completion).
201
+ * It constructs NO raw provider client, reads NO API-key env, and hardcodes no
202
+ * model id (Gate-13). The plaintext credential is materialized ONLY at the
203
+ * `ModelRunner` wire boundary (E10) via the sealed handle. When no credential is
204
+ * reachable it returns `{ kind: 'none' }` — the loop degrades to "no patch", no
205
+ * PR. This function constructs nothing at call time (lazy dynamic imports keep the
206
+ * module import-time side-effect-free + the E9 deps off the hot import path).
207
+ *
208
+ * @param opts - Optional project root threaded into the resolver.
209
+ * @returns A {@link FixGenerator} backed by the E9 chokepoint.
210
+ *
211
+ * @example
212
+ * ```ts
213
+ * const gen = createLlmFixGenerator({ projectRoot });
214
+ * const out = await gen.propose(request); // resolves model via E9, never raw client
215
+ * ```
216
+ */
217
+ export declare function createLlmFixGenerator(opts?: {
218
+ projectRoot?: string;
219
+ }): FixGenerator;
220
+ /**
221
+ * Strip a single surrounding markdown code fence (```diff … ```), if present, so a
222
+ * model that wraps its diff still yields an applyable patch. A bare diff passes
223
+ * through untouched.
224
+ *
225
+ * @param text - Candidate patch text (already trimmed).
226
+ * @returns The fence-stripped text.
227
+ */
228
+ export declare function stripCodeFences(text: string): string;
229
+ //# sourceMappingURL=fix-gen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix-gen.d.ts","sourceRoot":"","sources":["../../src/selfimprove/fix-gen.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAKH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAYpD;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,4DAA4D;IAC5D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,0DAA0D;IAC1D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,mEAAmE;IACnE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,+EAA+E;IAC/E,QAAQ,CAAC,WAAW,EAAE,SAAS,SAAS,EAAE,CAAC;IAC3C;;;;OAIG;IACH,QAAQ,CAAC,WAAW,EAAE,iB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SAAS,EAAE,YAAY,CAAC;IACjC;;;;OAIG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,yDAAyD;IACzD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAGnE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAG1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,aAAa,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAsB1F;AAcD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,uBAAuB,GAAG,OAAO,CAAC,YAAY,CAAC,CAuC3F;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,YAAY,CA+DvF;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIpD"}
@@ -0,0 +1,266 @@
1
+ /**
2
+ * Fix-generation stage for the self-improvement loop (T11889 · T11975).
3
+ *
4
+ * This is the missing autonomous link the v1 loop explicitly stubbed out
5
+ * ("NO autonomous fix-gen in v1", see {@link "./run-loop.js"}): given a detected
6
+ * regression (an open `selfimprove_dhq` + its envelope-diff) plus minimal repo
7
+ * context, it asks the LLM to PROPOSE a unified-diff patch and writes that patch
8
+ * to the path the draft-PR egress ({@link "./draft-pr.js".openDraftPr}) already
9
+ * `existsSync`-checks: `<cwd>/selfimprove-<scenario>.patch`. Once the patch is on
10
+ * disk the existing egress guard opens ONE DRAFT PR — closing the
11
+ * DHQ → fix → draft-PR pipeline end-to-end.
12
+ *
13
+ * ## Hard safety posture (unchanged from v1 — P5 spec §B.7)
14
+ *
15
+ * - **LLM ONLY via the E9 chokepoint.** The real generator
16
+ * ({@link createLlmFixGenerator}) resolves its model strictly through
17
+ * {@link "../llm/system-resolver.js".resolveLLMForSystem} → {@link ModelRunner}
18
+ * (Gate-13). It constructs NO raw provider client, reads NO `*_API_KEY` env,
19
+ * and hardcodes no model id — the resolver/registry is the SSoT. The
20
+ * plaintext token is materialized only at the wire boundary (E10).
21
+ * - **Draft-PR-ONLY, never auto-merge.** This module produces a PATCH FILE only;
22
+ * the egress that consumes it always opens a `--draft` PR against a feature
23
+ * branch (never `main`). This module performs NO git/gh action.
24
+ * - **Graceful degrade, never a rogue mutation.** Every failure (no credential,
25
+ * LLM error, empty / non-unified-diff output) returns a typed
26
+ * {@link FixGenResult} of kind `'skipped'` and writes NO patch file — so the
27
+ * existing egress guard (`existsSync` on the patch path) simply skips the PR.
28
+ * This function NEVER throws.
29
+ * - **Injectable seam.** The LLM dependency is the {@link FixGenerator} port;
30
+ * unit tests inject a deterministic fake that returns a canned patch, so NO
31
+ * real LLM is reached in tests.
32
+ *
33
+ * CORE-first: this engine lives in `core` and owns the `FixGenerator` port TYPE.
34
+ * Import-time side-effect-free.
35
+ *
36
+ * @module @cleocode/core/selfimprove/fix-gen
37
+ * @epic T11889
38
+ * @task T11975
39
+ */
40
+ import { writeFileSync } from 'node:fs';
41
+ import { resolve as resolvePath } from 'node:path';
42
+ import { cwd as processCwd } from 'node:process';
43
+ /**
44
+ * The E9 system-of-use label the fix-generator resolves its model under. Maps to
45
+ * the `judgement` role (see `SYSTEM_ROLE_MAP`) — the closest standing role for
46
+ * "reason about a regression and propose a code change".
47
+ */
48
+ const FIXGEN_SYSTEM = 'task-executor';
49
+ /** A leading marker every unified-diff hunk header / file header carries. */
50
+ const UNIFIED_DIFF_MARKERS = ['diff --git ', '--- ', '+++ ', '@@ '];
51
+ /**
52
+ * Compute the patch path the draft-PR egress expects for a scenario:
53
+ * `<cwd>/selfimprove-<scenario>.patch`. The scenario is sanitized to a safe file
54
+ * stem so a hostile scenario name cannot escape the cwd.
55
+ *
56
+ * @param scenario - The scenario name.
57
+ * @param cwd - The working directory to resolve against (defaults to `process.cwd`).
58
+ * @returns The absolute patch path.
59
+ */
60
+ export function fixPatchPath(scenario, cwd) {
61
+ const safeScenario = scenario.replace(/[^a-z0-9-]/gi, '-');
62
+ return resolvePath(cwd ?? processCwd(), `selfimprove-${safeScenario}.patch`);
63
+ }
64
+ /**
65
+ * Is `text` a plausible unified diff?
66
+ *
67
+ * A real `git apply`-able patch always carries at least one of the canonical
68
+ * unified-diff markers ({@link UNIFIED_DIFF_MARKERS}). An LLM that returns prose,
69
+ * an apology, or an empty string fails this guard, so the loop degrades to "no
70
+ * patch" rather than writing junk the egress would then fail to `git apply`.
71
+ *
72
+ * This is a cheap structural sniff, NOT a full parse — the authoritative
73
+ * applicability check is `git apply` inside the egress (which fails the PR cut on
74
+ * a bad patch, never `main`).
75
+ *
76
+ * @param text - Candidate patch text.
77
+ * @returns `true` when the text looks like a unified diff.
78
+ */
79
+ export function looksLikeUnifiedDiff(text) {
80
+ if (text.trim().length === 0)
81
+ return false;
82
+ return UNIFIED_DIFF_MARKERS.some((marker) => text.includes(marker));
83
+ }
84
+ /**
85
+ * Build the system + user prompt the real generator sends to the LLM. Pure
86
+ * (no IO) so it is unit-testable in isolation. The prompt is deliberately strict:
87
+ * "respond with ONLY a unified diff" — anything else fails
88
+ * {@link looksLikeUnifiedDiff} downstream and degrades to "no patch".
89
+ *
90
+ * @param request - The fix-generation request.
91
+ * @returns The `{ system, user }` prompt pair.
92
+ */
93
+ export function buildFixGenPrompt(request) {
94
+ const system = 'You are an autonomous software-maintenance agent. You are given a detected ' +
95
+ 'regression in a TypeScript monorepo (a divergence between a replayed scenario ' +
96
+ 'and its golden expected output). Produce a MINIMAL fix as a single unified diff ' +
97
+ '(`git diff` format, with `diff --git`, `---`, `+++`, and `@@` hunk headers). ' +
98
+ 'Respond with ONLY the unified diff and NOTHING else — no prose, no code fences, ' +
99
+ 'no explanation. If you cannot propose a safe fix, respond with the single token ' +
100
+ 'NO_PATCH.';
101
+ const lines = request.regressions.map((r) => `- op ${r.opCoord} (#${r.opIndex}) at path \`${r.path}\`: ` +
102
+ `actual=${JSON.stringify(r.actual)} expected=${JSON.stringify(r.expected)}`);
103
+ const user = `Regression ${request.dhqId} in scenario \`${request.scenario}\` ` +
104
+ `(${request.regressions.length} diverging path(s)).\n` +
105
+ (request.repoContext.summary ? `Scenario summary: ${request.repoContext.summary}\n` : '') +
106
+ `Project root: ${request.repoContext.projectRoot}\n\n` +
107
+ `Diverging paths:\n${lines.join('\n')}\n\n` +
108
+ 'Produce the unified diff that resolves these divergences.';
109
+ return { system, user };
110
+ }
111
+ /**
112
+ * Lazily-resolved module logger (import-time side-effect-free).
113
+ */
114
+ let cachedLogger;
115
+ async function getModuleLogger() {
116
+ if (cachedLogger === undefined) {
117
+ const { getLogger } = await import('../logger.js');
118
+ cachedLogger = getLogger('selfimprove-fix-gen');
119
+ }
120
+ return cachedLogger;
121
+ }
122
+ /**
123
+ * Run the fix-generation stage: ask the injected {@link FixGenerator} for a patch,
124
+ * validate it as a unified diff, and write it to the egress-expected patch path.
125
+ *
126
+ * This function NEVER throws and NEVER mutates anything but the single patch file.
127
+ * On ANY degrade path — generator returns `'none'`, the generator throws, or the
128
+ * returned text is not a unified diff — it writes NO file and returns
129
+ * `{ kind: 'skipped', reason }`, so the downstream `existsSync` egress guard
130
+ * simply skips the PR. The caller records the `reason` on the DHQ evidence.
131
+ *
132
+ * @param opts - See {@link GenerateFixPatchOptions}.
133
+ * @returns A {@link FixGenResult}.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * const res = await generateFixPatch({
138
+ * request: { dhqId: 'DHQ-abcd1234', scenario, questionHash, regressions, repoContext },
139
+ * generator: createLlmFixGenerator(),
140
+ * cwd: projectRoot,
141
+ * });
142
+ * if (res.kind === 'written') { // openDraftPr will now find selfimprove-<scenario>.patch }
143
+ * ```
144
+ */
145
+ export async function generateFixPatch(opts) {
146
+ const logger = opts.logger ?? (await getModuleLogger());
147
+ const { request, generator } = opts;
148
+ const patchPath = fixPatchPath(request.scenario, opts.cwd);
149
+ let output;
150
+ try {
151
+ output = await generator.propose(request);
152
+ }
153
+ catch (err) {
154
+ const reason = `fixgen-threw:${err instanceof Error ? err.message : String(err)}`;
155
+ logger.warn({ dhqId: request.dhqId, scenario: request.scenario, reason }, 'fix-gen degraded');
156
+ return { kind: 'skipped', reason };
157
+ }
158
+ if (output.kind === 'none') {
159
+ logger.info({ dhqId: request.dhqId, scenario: request.scenario, reason: output.reason }, 'fix-gen produced no patch (graceful skip — no PR)');
160
+ return { kind: 'skipped', reason: `fixgen-none:${output.reason}` };
161
+ }
162
+ if (!looksLikeUnifiedDiff(output.diff)) {
163
+ logger.warn({ dhqId: request.dhqId, scenario: request.scenario }, 'fix-gen output is not a unified diff (graceful skip — no PR)');
164
+ return { kind: 'skipped', reason: 'fixgen-not-a-diff' };
165
+ }
166
+ // Normalize a trailing newline so `git apply` accepts the hunk.
167
+ const diff = output.diff.endsWith('\n') ? output.diff : `${output.diff}\n`;
168
+ writeFileSync(patchPath, diff, 'utf8');
169
+ const bytes = Buffer.byteLength(diff, 'utf8');
170
+ logger.info({ dhqId: request.dhqId, scenario: request.scenario, patchPath, bytes, model: output.model }, 'fix-gen wrote candidate patch — egress will open a DRAFT PR');
171
+ return { kind: 'written', patchPath, bytes, model: output.model };
172
+ }
173
+ /**
174
+ * Construct the REAL fix generator — the one that drives the E9 LLM chokepoint.
175
+ *
176
+ * Resolution funnels through {@link resolveLLMForSystem}(`'task-executor'`) →
177
+ * {@link ModelRunner.build} → `session.send` (ONE non-streaming completion).
178
+ * It constructs NO raw provider client, reads NO API-key env, and hardcodes no
179
+ * model id (Gate-13). The plaintext credential is materialized ONLY at the
180
+ * `ModelRunner` wire boundary (E10) via the sealed handle. When no credential is
181
+ * reachable it returns `{ kind: 'none' }` — the loop degrades to "no patch", no
182
+ * PR. This function constructs nothing at call time (lazy dynamic imports keep the
183
+ * module import-time side-effect-free + the E9 deps off the hot import path).
184
+ *
185
+ * @param opts - Optional project root threaded into the resolver.
186
+ * @returns A {@link FixGenerator} backed by the E9 chokepoint.
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * const gen = createLlmFixGenerator({ projectRoot });
191
+ * const out = await gen.propose(request); // resolves model via E9, never raw client
192
+ * ```
193
+ */
194
+ export function createLlmFixGenerator(opts = {}) {
195
+ return {
196
+ async propose(request) {
197
+ const logger = await getModuleLogger();
198
+ // Lazy imports: keep E9 deps off the module import path + side-effect-free.
199
+ const { resolveLLMForSystem } = await import('../llm/system-resolver.js');
200
+ const { ModelRunner } = await import('../llm/model-runner.js');
201
+ // 1. E9 resolution chokepoint. Never throws (resolver contract).
202
+ const projectRoot = opts.projectRoot ?? request.repoContext.projectRoot;
203
+ const resolved = await resolveLLMForSystem(FIXGEN_SYSTEM, { projectRoot });
204
+ if (!resolved.sealedCredential && resolved.authType !== 'aws_sdk') {
205
+ return { kind: 'none', reason: 'no-credential-resolved' };
206
+ }
207
+ // 2. Materialize the plaintext ONLY at the wire boundary (E10), build a
208
+ // clean descriptor, and construct the transport inside ModelRunner.
209
+ const apiKey = resolved.sealedCredential
210
+ ? (await resolved.sealedCredential.fetch()).value
211
+ : null;
212
+ const built = await ModelRunner.build({
213
+ provider: resolved.provider,
214
+ model: resolved.model,
215
+ credential: resolved.credential
216
+ ? {
217
+ provider: resolved.credential.provider,
218
+ apiKey,
219
+ source: resolved.credential.source,
220
+ authType: resolved.credential.authType,
221
+ }
222
+ : null,
223
+ source: resolved.source,
224
+ ...(resolved.credentialLabel !== undefined
225
+ ? { credentialLabel: resolved.credentialLabel }
226
+ : {}),
227
+ apiMode: resolved.apiMode,
228
+ baseUrl: resolved.baseUrl,
229
+ authType: resolved.authType,
230
+ ...(resolved.capabilities !== undefined ? { capabilities: resolved.capabilities } : {}),
231
+ });
232
+ // 3. ONE non-streaming completion. The system prompt is threaded onto the
233
+ // request via `systemSuffix` (ConcreteSession maps it to
234
+ // `TransportRequest.system`); the user turn carries the regression detail.
235
+ const { system, user } = buildFixGenPrompt(request);
236
+ try {
237
+ const response = await built.session.send([{ role: 'user', content: user }], {
238
+ systemSuffix: system,
239
+ });
240
+ const text = (response.content ?? '').trim();
241
+ if (text.length === 0 || text === 'NO_PATCH') {
242
+ return { kind: 'none', reason: 'model-declined' };
243
+ }
244
+ return { kind: 'patch', diff: stripCodeFences(text), model: response.model };
245
+ }
246
+ catch (err) {
247
+ logger.warn({ system: FIXGEN_SYSTEM, err: err instanceof Error ? err.message : String(err) }, 'fix-gen LLM call failed — degrading to no-patch');
248
+ return { kind: 'none', reason: 'llm-call-failed' };
249
+ }
250
+ },
251
+ };
252
+ }
253
+ /**
254
+ * Strip a single surrounding markdown code fence (```diff … ```), if present, so a
255
+ * model that wraps its diff still yields an applyable patch. A bare diff passes
256
+ * through untouched.
257
+ *
258
+ * @param text - Candidate patch text (already trimmed).
259
+ * @returns The fence-stripped text.
260
+ */
261
+ export function stripCodeFences(text) {
262
+ const fence = /^```[a-z]*\n([\s\S]*?)\n```$/i;
263
+ const m = text.match(fence);
264
+ return m?.[1] !== undefined ? m[1].trim() : text;
265
+ }
266
+ //# sourceMappingURL=fix-gen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix-gen.js","sourceRoot":"","sources":["../../src/selfimprove/fix-gen.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,GAAG,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAIjD;;;;GAIG;AACH,MAAM,aAAa,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AI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;oBAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;gBACpD,CAAC;gBACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;YAC/E,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,CAAC,IAAI,CACT,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAChF,iDAAiD,CAClD,CAAC;gBACF,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC;YACrD,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,KAAK,GAAG,+BAA+B,CAAC;IAC9C,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC5B,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACnD,CAAC"}
@@ -17,8 +17,15 @@
17
17
  * 4. on a regression, **emit ONE DHQ** row via the leased
18
18
  * {@link "./dhq-adapter.js".DhqAdapter} (UPSERT under
19
19
  * `withWriterLease('project','bulk',…)`) — ONLY when `execute` is set;
20
+ * 4b. **generate a fix** ({@link "./fix-gen.js".generateFixPatch}, T11975) — ONLY
21
+ * when `execute` AND `CLEO_PI_RUNNER_ENABLED=1`. Drives the LLM strictly via
22
+ * the E9 chokepoint to produce a unified-diff patch at the path the egress
23
+ * expects (`<cwd>/selfimprove-<scenario>.patch`). Degrades gracefully (no
24
+ * patch ⇒ the egress guard skips the PR); the outcome is recorded back onto
25
+ * the DHQ row. NEVER throws a rogue mutation, NEVER auto-merges;
20
26
  * 5. **open ONE DRAFT PR** ({@link "./draft-pr.js".openDraftPr}, dry-run unless
21
- * `execute`) and record its URL back on the DHQ row.
27
+ * `execute`) and record its URL back on the DHQ row — fires only when the
28
+ * fix-gen stage wrote a patch file (the existing `existsSync` egress guard).
22
29
  *
23
30
  * Self-dogfooding guardrails (NON-NEGOTIABLE, P5 spec §B.7):
24
31
  * - **Default OFF.** Mutation + egress require `opts.execute === true`. Without
@@ -30,8 +37,12 @@
30
37
  * - **Budget caps** (in-code): `maxTokens` / `maxUsd` / `maxPrs = 1` /
31
38
  * `maxWorktrees = 1`, checked PRE-FLIGHT before each costed step. `MemoryMax=32G`
32
39
  * is an operational launch-wrapper, not an in-code cap.
33
- * - **NO autonomous fix-gen, NO auto-merge, NO end-user mode in v1.** The loop
34
- * surfaces regressions as DHQs + draft PRs; a human drives the fix.
40
+ * - **Fix-gen is GATED + DRAFT-PR-ONLY (T11975).** The autonomous fix-generation
41
+ * stage runs ONLY behind BOTH `execute` AND `CLEO_PI_RUNNER_ENABLED=1` (the
42
+ * same gates guarding the rest of the loop). It produces a candidate patch via
43
+ * the E9 LLM chokepoint and lets the EXISTING egress open a DRAFT PR — NEVER
44
+ * an auto-merge, NEVER an end-user mode, NEVER a `main` push. A failed or empty
45
+ * fix-gen degrades to "no patch" and the egress simply skips the PR.
35
46
  *
36
47
  * CORE-first: this engine lives in `core` and owns the `ReplayDispatch` port TYPE;
37
48
  * the cleo dispatch handler supplies the concrete adapter (dependency inversion —
@@ -45,8 +56,9 @@ import { type ExecutionEnvBackend } from '../llm/pi/resolve-execution-env.js';
45
56
  import { type ToolGuard } from '../tools/guard.js';
46
57
  import { type CircuitBreakerState, DEFAULT_BUDGET, type SelfImproveBudget } from './budget.js';
47
58
  import { type DhqAdapter } from './dhq-adapter.js';
48
- import { type DraftPrResult } from './draft-pr.js';
59
+ import { type CommandRunner, type DraftPrResult } from './draft-pr.js';
49
60
  import { type DiffEntry } from './envelope-diff.js';
61
+ import { type FixGenerator, type FixGenResult } from './fix-gen.js';
50
62
  import { type ReplayDispatch } from './replay.js';
51
63
  /** Options for {@link runSelfImprove}. */
52
64
  export interface RunSelfImproveOptions {
@@ -87,6 +99,27 @@ export interface RunSelfImproveOptions {
87
99
  readonly gateRedCheck?: () => Promise<boolean>;
88
100
  /** Test seam: inject a DHQ adapter (defaults to the real leased adapter). */
89
101
  readonly adapter?: DhqAdapter;
102
+ /**
103
+ * Test seam: inject the fix generator (the LLM dependency). Defaults to the real
104
+ * {@link "./fix-gen.js".createLlmFixGenerator} backed by the E9 chokepoint — unit
105
+ * tests inject a deterministic fake returning a canned patch so NO real LLM is
106
+ * reached. The fix-gen stage only runs when BOTH `execute` is set AND the
107
+ * Pi-runner gate (`CLEO_PI_RUNNER_ENABLED=1`) is on, unless `piRunnerEnabled` is
108
+ * supplied (test seam) to override the env read.
109
+ */
110
+ readonly fixGenerator?: FixGenerator;
111
+ /**
112
+ * Test seam: override the `CLEO_PI_RUNNER_ENABLED` env gate that arms fix-gen.
113
+ * Defaults to `process.env.CLEO_PI_RUNNER_ENABLED === '1'`. Supplied explicitly
114
+ * by tests so the deterministic fake runs without mutating process env.
115
+ */
116
+ readonly piRunnerEnabled?: boolean;
117
+ /**
118
+ * Test seam: inject the draft-PR egress command runner (captures the git/gh
119
+ * shell-out). Defaults to the real `execFileSync`-backed runner. Supplied by
120
+ * tests so the capstone proves the egress WITHOUT a real `gh`/`git` invocation.
121
+ */
122
+ readonly draftPrRun?: CommandRunner;
90
123
  /** Test seam: inject the guard backing the in-process fallback env. */
91
124
  readonly guard?: ToolGuard;
92
125
  /** Test seam: inject the run id (defaults to a timestamped id). */
@@ -120,6 +153,13 @@ export interface SelfImproveResult {
120
153
  readonly questionHash: string | null;
121
154
  /** The draft-PR egress result, or `null` when none fired (green / dry-run-no-egress). */
122
155
  readonly draftPr: DraftPrResult | null;
156
+ /**
157
+ * The fix-generation outcome (T11975), or `null` when the stage did not run
158
+ * (green run, dry-run, gate off, or breaker tripped before persist). `'written'`
159
+ * means a candidate patch was produced and the egress was armed; `'skipped'`
160
+ * means fix-gen degraded gracefully (no patch ⇒ no PR).
161
+ */
162
+ readonly fixGen: FixGenResult | null;
123
163
  /** The final circuit-breaker state. */
124
164
  readonly breaker: CircuitBreakerState;
125
165
  }
@@ -1 +1 @@
1
- {"version":3,"file":"run-loop.d.ts","sourceRoot":"","sources":["../../src/selfimprove/run-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAGH,OAAO,EAAE,KAAK,mBAAmB,EAAuB,MAAM,oCAAoC,CAAC;AAGnG,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAGL,KAAK,mBAAmB,EACxB,cAAc,EAEd,KAAK,iBAAiB,EACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,KAAK,aAAa,EAAe,MAAM,eAAe,CAAC;AAChE,OAAO,EAAuB,KAAK,SAAS,EAAiB,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,KAAK,cAAc,EAAkB,MAAM,aAAa,CAAC;AAGlE,0CAA0C;AAC1C,MAAM,WAAW,qBAAqB;IACpC,qEAAqE;IACrE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,oFAAoF;IACpF,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM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