conatus 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1059) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +189 -0
  3. package/dist/adapter-layer.d.ts +67 -0
  4. package/dist/adapter-layer.d.ts.map +1 -0
  5. package/dist/adapter-layer.js +50 -0
  6. package/dist/adapter-layer.js.map +1 -0
  7. package/dist/adapters/a2a-adapter.d.ts +49 -0
  8. package/dist/adapters/a2a-adapter.d.ts.map +1 -0
  9. package/dist/adapters/a2a-adapter.js +211 -0
  10. package/dist/adapters/a2a-adapter.js.map +1 -0
  11. package/dist/adapters/a2a-client.d.ts +28 -0
  12. package/dist/adapters/a2a-client.d.ts.map +1 -0
  13. package/dist/adapters/a2a-client.js +178 -0
  14. package/dist/adapters/a2a-client.js.map +1 -0
  15. package/dist/adapters/browser-use-cli.d.ts +19 -0
  16. package/dist/adapters/browser-use-cli.d.ts.map +1 -0
  17. package/dist/adapters/browser-use-cli.js +112 -0
  18. package/dist/adapters/browser-use-cli.js.map +1 -0
  19. package/dist/adapters/claude-api.d.ts +10 -0
  20. package/dist/adapters/claude-api.d.ts.map +1 -0
  21. package/dist/adapters/claude-api.js +63 -0
  22. package/dist/adapters/claude-api.js.map +1 -0
  23. package/dist/adapters/claude-code-cli.d.ts +14 -0
  24. package/dist/adapters/claude-code-cli.d.ts.map +1 -0
  25. package/dist/adapters/claude-code-cli.js +99 -0
  26. package/dist/adapters/claude-code-cli.js.map +1 -0
  27. package/dist/adapters/file-existence-datasource.d.ts +16 -0
  28. package/dist/adapters/file-existence-datasource.d.ts.map +1 -0
  29. package/dist/adapters/file-existence-datasource.js +71 -0
  30. package/dist/adapters/file-existence-datasource.js.map +1 -0
  31. package/dist/adapters/github-issue-datasource.d.ts +45 -0
  32. package/dist/adapters/github-issue-datasource.d.ts.map +1 -0
  33. package/dist/adapters/github-issue-datasource.js +329 -0
  34. package/dist/adapters/github-issue-datasource.js.map +1 -0
  35. package/dist/adapters/github-issue.d.ts +87 -0
  36. package/dist/adapters/github-issue.d.ts.map +1 -0
  37. package/dist/adapters/github-issue.js +497 -0
  38. package/dist/adapters/github-issue.js.map +1 -0
  39. package/dist/adapters/openai-codex.d.ts +26 -0
  40. package/dist/adapters/openai-codex.d.ts.map +1 -0
  41. package/dist/adapters/openai-codex.js +112 -0
  42. package/dist/adapters/openai-codex.js.map +1 -0
  43. package/dist/adapters/shell-datasource.d.ts +36 -0
  44. package/dist/adapters/shell-datasource.d.ts.map +1 -0
  45. package/dist/adapters/shell-datasource.js +138 -0
  46. package/dist/adapters/shell-datasource.js.map +1 -0
  47. package/dist/capability-detector.d.ts +124 -0
  48. package/dist/capability-detector.d.ts.map +1 -0
  49. package/dist/capability-detector.js +576 -0
  50. package/dist/capability-detector.js.map +1 -0
  51. package/dist/character-config.d.ts +34 -0
  52. package/dist/character-config.d.ts.map +1 -0
  53. package/dist/character-config.js +53 -0
  54. package/dist/character-config.js.map +1 -0
  55. package/dist/cli/cli-logger.d.ts +3 -0
  56. package/dist/cli/cli-logger.d.ts.map +1 -0
  57. package/dist/cli/cli-logger.js +12 -0
  58. package/dist/cli/cli-logger.js.map +1 -0
  59. package/dist/cli/commands/config.d.ts +12 -0
  60. package/dist/cli/commands/config.d.ts.map +1 -0
  61. package/dist/cli/commands/config.js +345 -0
  62. package/dist/cli/commands/config.js.map +1 -0
  63. package/dist/cli/commands/daemon.d.ts +6 -0
  64. package/dist/cli/commands/daemon.d.ts.map +1 -0
  65. package/dist/cli/commands/daemon.js +99 -0
  66. package/dist/cli/commands/daemon.js.map +1 -0
  67. package/dist/cli/commands/goal-raw.d.ts +7 -0
  68. package/dist/cli/commands/goal-raw.d.ts.map +1 -0
  69. package/dist/cli/commands/goal-raw.js +93 -0
  70. package/dist/cli/commands/goal-raw.js.map +1 -0
  71. package/dist/cli/commands/goal-utils.d.ts +41 -0
  72. package/dist/cli/commands/goal-utils.d.ts.map +1 -0
  73. package/dist/cli/commands/goal-utils.js +184 -0
  74. package/dist/cli/commands/goal-utils.js.map +1 -0
  75. package/dist/cli/commands/goal.d.ts +22 -0
  76. package/dist/cli/commands/goal.d.ts.map +1 -0
  77. package/dist/cli/commands/goal.js +382 -0
  78. package/dist/cli/commands/goal.js.map +1 -0
  79. package/dist/cli/commands/plugin.d.ts +9 -0
  80. package/dist/cli/commands/plugin.d.ts.map +1 -0
  81. package/dist/cli/commands/plugin.js +336 -0
  82. package/dist/cli/commands/plugin.js.map +1 -0
  83. package/dist/cli/commands/report.d.ts +3 -0
  84. package/dist/cli/commands/report.d.ts.map +1 -0
  85. package/dist/cli/commands/report.js +29 -0
  86. package/dist/cli/commands/report.js.map +1 -0
  87. package/dist/cli/commands/run.d.ts +10 -0
  88. package/dist/cli/commands/run.d.ts.map +1 -0
  89. package/dist/cli/commands/run.js +159 -0
  90. package/dist/cli/commands/run.js.map +1 -0
  91. package/dist/cli/commands/suggest.d.ts +7 -0
  92. package/dist/cli/commands/suggest.d.ts.map +1 -0
  93. package/dist/cli/commands/suggest.js +466 -0
  94. package/dist/cli/commands/suggest.js.map +1 -0
  95. package/dist/cli/ensure-api-key.d.ts +14 -0
  96. package/dist/cli/ensure-api-key.d.ts.map +1 -0
  97. package/dist/cli/ensure-api-key.js +28 -0
  98. package/dist/cli/ensure-api-key.js.map +1 -0
  99. package/dist/cli/setup.d.ts +18 -0
  100. package/dist/cli/setup.d.ts.map +1 -0
  101. package/dist/cli/setup.js +147 -0
  102. package/dist/cli/setup.js.map +1 -0
  103. package/dist/cli/utils.d.ts +9 -0
  104. package/dist/cli/utils.d.ts.map +1 -0
  105. package/dist/cli/utils.js +113 -0
  106. package/dist/cli/utils.js.map +1 -0
  107. package/dist/cli-runner.d.ts +32 -0
  108. package/dist/cli-runner.d.ts.map +1 -0
  109. package/dist/cli-runner.js +467 -0
  110. package/dist/cli-runner.js.map +1 -0
  111. package/dist/codex-llm-client.d.ts +47 -0
  112. package/dist/codex-llm-client.d.ts.map +1 -0
  113. package/dist/codex-llm-client.js +193 -0
  114. package/dist/codex-llm-client.js.map +1 -0
  115. package/dist/context-provider.d.ts +16 -0
  116. package/dist/context-provider.d.ts.map +1 -0
  117. package/dist/context-provider.js +107 -0
  118. package/dist/context-provider.js.map +1 -0
  119. package/dist/context-providers/workspace-context.d.ts +8 -0
  120. package/dist/context-providers/workspace-context.d.ts.map +1 -0
  121. package/dist/context-providers/workspace-context.js +217 -0
  122. package/dist/context-providers/workspace-context.js.map +1 -0
  123. package/dist/core/suggest/repo-context.d.ts +8 -0
  124. package/dist/core/suggest/repo-context.d.ts.map +1 -0
  125. package/dist/core/suggest/repo-context.js +154 -0
  126. package/dist/core/suggest/repo-context.js.map +1 -0
  127. package/dist/core-loop.d.ts +63 -0
  128. package/dist/core-loop.d.ts.map +1 -0
  129. package/dist/core-loop.js +521 -0
  130. package/dist/core-loop.js.map +1 -0
  131. package/dist/cross-goal-portfolio.d.ts +153 -0
  132. package/dist/cross-goal-portfolio.d.ts.map +1 -0
  133. package/dist/cross-goal-portfolio.js +790 -0
  134. package/dist/cross-goal-portfolio.js.map +1 -0
  135. package/dist/curiosity-engine.d.ts +177 -0
  136. package/dist/curiosity-engine.d.ts.map +1 -0
  137. package/dist/curiosity-engine.js +736 -0
  138. package/dist/curiosity-engine.js.map +1 -0
  139. package/dist/daemon-runner.d.ts +109 -0
  140. package/dist/daemon-runner.d.ts.map +1 -0
  141. package/dist/daemon-runner.js +389 -0
  142. package/dist/daemon-runner.js.map +1 -0
  143. package/dist/data-source-adapter.d.ts +42 -0
  144. package/dist/data-source-adapter.d.ts.map +1 -0
  145. package/dist/data-source-adapter.js +223 -0
  146. package/dist/data-source-adapter.js.map +1 -0
  147. package/dist/drive/drive-scorer.d.ts +96 -0
  148. package/dist/drive/drive-scorer.d.ts.map +1 -0
  149. package/dist/drive/drive-scorer.js +240 -0
  150. package/dist/drive/drive-scorer.js.map +1 -0
  151. package/dist/drive/drive-system.d.ts +99 -0
  152. package/dist/drive/drive-system.d.ts.map +1 -0
  153. package/dist/drive/drive-system.js +344 -0
  154. package/dist/drive/drive-system.js.map +1 -0
  155. package/dist/drive/gap-calculator.d.ts +80 -0
  156. package/dist/drive/gap-calculator.d.ts.map +1 -0
  157. package/dist/drive/gap-calculator.js +219 -0
  158. package/dist/drive/gap-calculator.js.map +1 -0
  159. package/dist/drive/reward-log.d.ts +51 -0
  160. package/dist/drive/reward-log.d.ts.map +1 -0
  161. package/dist/drive/reward-log.js +48 -0
  162. package/dist/drive/reward-log.js.map +1 -0
  163. package/dist/drive/satisficing-helpers.d.ts +28 -0
  164. package/dist/drive/satisficing-helpers.d.ts.map +1 -0
  165. package/dist/drive/satisficing-helpers.js +111 -0
  166. package/dist/drive/satisficing-helpers.js.map +1 -0
  167. package/dist/drive/satisficing-judge.d.ts +140 -0
  168. package/dist/drive/satisficing-judge.d.ts.map +1 -0
  169. package/dist/drive/satisficing-judge.js +432 -0
  170. package/dist/drive/satisficing-judge.js.map +1 -0
  171. package/dist/drive/satisficing-propagation.d.ts +30 -0
  172. package/dist/drive/satisficing-propagation.d.ts.map +1 -0
  173. package/dist/drive/satisficing-propagation.js +196 -0
  174. package/dist/drive/satisficing-propagation.js.map +1 -0
  175. package/dist/drive/stall-detector.d.ts +113 -0
  176. package/dist/drive/stall-detector.d.ts.map +1 -0
  177. package/dist/drive/stall-detector.js +378 -0
  178. package/dist/drive/stall-detector.js.map +1 -0
  179. package/dist/drive-scorer.d.ts +96 -0
  180. package/dist/drive-scorer.d.ts.map +1 -0
  181. package/dist/drive-scorer.js +235 -0
  182. package/dist/drive-scorer.js.map +1 -0
  183. package/dist/drive-system.d.ts +92 -0
  184. package/dist/drive-system.d.ts.map +1 -0
  185. package/dist/drive-system.js +325 -0
  186. package/dist/drive-system.js.map +1 -0
  187. package/dist/embedding-client.d.ts +49 -0
  188. package/dist/embedding-client.d.ts.map +1 -0
  189. package/dist/embedding-client.js +141 -0
  190. package/dist/embedding-client.js.map +1 -0
  191. package/dist/ethics-gate.d.ts +70 -0
  192. package/dist/ethics-gate.d.ts.map +1 -0
  193. package/dist/ethics-gate.js +567 -0
  194. package/dist/ethics-gate.js.map +1 -0
  195. package/dist/event-server.d.ts +23 -0
  196. package/dist/event-server.d.ts.map +1 -0
  197. package/dist/event-server.js +69 -0
  198. package/dist/event-server.js.map +1 -0
  199. package/dist/execution/adapter-layer.d.ts +88 -0
  200. package/dist/execution/adapter-layer.d.ts.map +1 -0
  201. package/dist/execution/adapter-layer.js +123 -0
  202. package/dist/execution/adapter-layer.js.map +1 -0
  203. package/dist/execution/checkpoint-manager.d.ts +49 -0
  204. package/dist/execution/checkpoint-manager.d.ts.map +1 -0
  205. package/dist/execution/checkpoint-manager.js +143 -0
  206. package/dist/execution/checkpoint-manager.js.map +1 -0
  207. package/dist/execution/context-budget.d.ts +35 -0
  208. package/dist/execution/context-budget.d.ts.map +1 -0
  209. package/dist/execution/context-budget.js +73 -0
  210. package/dist/execution/context-budget.js.map +1 -0
  211. package/dist/execution/dimension-selector.d.ts +22 -0
  212. package/dist/execution/dimension-selector.d.ts.map +1 -0
  213. package/dist/execution/dimension-selector.js +57 -0
  214. package/dist/execution/dimension-selector.js.map +1 -0
  215. package/dist/execution/impact-analyzer.d.ts +24 -0
  216. package/dist/execution/impact-analyzer.d.ts.map +1 -0
  217. package/dist/execution/impact-analyzer.js +88 -0
  218. package/dist/execution/impact-analyzer.js.map +1 -0
  219. package/dist/execution/parallel-executor.d.ts +35 -0
  220. package/dist/execution/parallel-executor.d.ts.map +1 -0
  221. package/dist/execution/parallel-executor.js +162 -0
  222. package/dist/execution/parallel-executor.js.map +1 -0
  223. package/dist/execution/pipeline-executor.d.ts +54 -0
  224. package/dist/execution/pipeline-executor.d.ts.map +1 -0
  225. package/dist/execution/pipeline-executor.js +250 -0
  226. package/dist/execution/pipeline-executor.js.map +1 -0
  227. package/dist/execution/reflection-generator.d.ts +24 -0
  228. package/dist/execution/reflection-generator.d.ts.map +1 -0
  229. package/dist/execution/reflection-generator.js +143 -0
  230. package/dist/execution/reflection-generator.js.map +1 -0
  231. package/dist/execution/result-reconciler.d.ts +23 -0
  232. package/dist/execution/result-reconciler.d.ts.map +1 -0
  233. package/dist/execution/result-reconciler.js +109 -0
  234. package/dist/execution/result-reconciler.js.map +1 -0
  235. package/dist/execution/session-manager.d.ts +182 -0
  236. package/dist/execution/session-manager.d.ts.map +1 -0
  237. package/dist/execution/session-manager.js +506 -0
  238. package/dist/execution/session-manager.js.map +1 -0
  239. package/dist/execution/task-approval-check.d.ts +9 -0
  240. package/dist/execution/task-approval-check.d.ts.map +1 -0
  241. package/dist/execution/task-approval-check.js +14 -0
  242. package/dist/execution/task-approval-check.js.map +1 -0
  243. package/dist/execution/task-approval.d.ts +37 -0
  244. package/dist/execution/task-approval.d.ts.map +1 -0
  245. package/dist/execution/task-approval.js +147 -0
  246. package/dist/execution/task-approval.js.map +1 -0
  247. package/dist/execution/task-execution-types.d.ts +14 -0
  248. package/dist/execution/task-execution-types.d.ts.map +1 -0
  249. package/dist/execution/task-execution-types.js +2 -0
  250. package/dist/execution/task-execution-types.js.map +1 -0
  251. package/dist/execution/task-executor.d.ts +30 -0
  252. package/dist/execution/task-executor.d.ts.map +1 -0
  253. package/dist/execution/task-executor.js +196 -0
  254. package/dist/execution/task-executor.js.map +1 -0
  255. package/dist/execution/task-generation.d.ts +154 -0
  256. package/dist/execution/task-generation.d.ts.map +1 -0
  257. package/dist/execution/task-generation.js +406 -0
  258. package/dist/execution/task-generation.js.map +1 -0
  259. package/dist/execution/task-health-check.d.ts +38 -0
  260. package/dist/execution/task-health-check.d.ts.map +1 -0
  261. package/dist/execution/task-health-check.js +66 -0
  262. package/dist/execution/task-health-check.js.map +1 -0
  263. package/dist/execution/task-lifecycle.d.ts +122 -0
  264. package/dist/execution/task-lifecycle.d.ts.map +1 -0
  265. package/dist/execution/task-lifecycle.js +303 -0
  266. package/dist/execution/task-lifecycle.js.map +1 -0
  267. package/dist/execution/task-pipeline-cycle.d.ts +45 -0
  268. package/dist/execution/task-pipeline-cycle.d.ts.map +1 -0
  269. package/dist/execution/task-pipeline-cycle.js +134 -0
  270. package/dist/execution/task-pipeline-cycle.js.map +1 -0
  271. package/dist/execution/task-prompt-builder.d.ts +9 -0
  272. package/dist/execution/task-prompt-builder.d.ts.map +1 -0
  273. package/dist/execution/task-prompt-builder.js +165 -0
  274. package/dist/execution/task-prompt-builder.js.map +1 -0
  275. package/dist/execution/task-verifier.d.ts +112 -0
  276. package/dist/execution/task-verifier.d.ts.map +1 -0
  277. package/dist/execution/task-verifier.js +782 -0
  278. package/dist/execution/task-verifier.js.map +1 -0
  279. package/dist/gap-calculator.d.ts +80 -0
  280. package/dist/gap-calculator.d.ts.map +1 -0
  281. package/dist/gap-calculator.js +218 -0
  282. package/dist/gap-calculator.js.map +1 -0
  283. package/dist/goal/goal-decomposer.d.ts +30 -0
  284. package/dist/goal/goal-decomposer.d.ts.map +1 -0
  285. package/dist/goal/goal-decomposer.js +167 -0
  286. package/dist/goal/goal-decomposer.js.map +1 -0
  287. package/dist/goal/goal-dependency-graph.d.ts +119 -0
  288. package/dist/goal/goal-dependency-graph.d.ts.map +1 -0
  289. package/dist/goal/goal-dependency-graph.js +322 -0
  290. package/dist/goal/goal-dependency-graph.js.map +1 -0
  291. package/dist/goal/goal-negotiator.d.ts +66 -0
  292. package/dist/goal/goal-negotiator.d.ts.map +1 -0
  293. package/dist/goal/goal-negotiator.js +260 -0
  294. package/dist/goal/goal-negotiator.js.map +1 -0
  295. package/dist/goal/goal-suggest.d.ts +85 -0
  296. package/dist/goal/goal-suggest.d.ts.map +1 -0
  297. package/dist/goal/goal-suggest.js +178 -0
  298. package/dist/goal/goal-suggest.js.map +1 -0
  299. package/dist/goal/goal-tree-manager.d.ts +71 -0
  300. package/dist/goal/goal-tree-manager.d.ts.map +1 -0
  301. package/dist/goal/goal-tree-manager.js +580 -0
  302. package/dist/goal/goal-tree-manager.js.map +1 -0
  303. package/dist/goal/goal-tree-pruner.d.ts +25 -0
  304. package/dist/goal/goal-tree-pruner.d.ts.map +1 -0
  305. package/dist/goal/goal-tree-pruner.js +93 -0
  306. package/dist/goal/goal-tree-pruner.js.map +1 -0
  307. package/dist/goal/goal-tree-quality.d.ts +22 -0
  308. package/dist/goal/goal-tree-quality.d.ts.map +1 -0
  309. package/dist/goal/goal-tree-quality.js +183 -0
  310. package/dist/goal/goal-tree-quality.js.map +1 -0
  311. package/dist/goal/goal-validation.d.ts +20 -0
  312. package/dist/goal/goal-validation.d.ts.map +1 -0
  313. package/dist/goal/goal-validation.js +93 -0
  314. package/dist/goal/goal-validation.js.map +1 -0
  315. package/dist/goal/negotiator-context.d.ts +13 -0
  316. package/dist/goal/negotiator-context.d.ts.map +1 -0
  317. package/dist/goal/negotiator-context.js +119 -0
  318. package/dist/goal/negotiator-context.js.map +1 -0
  319. package/dist/goal/negotiator-prompts.d.ts +31 -0
  320. package/dist/goal/negotiator-prompts.d.ts.map +1 -0
  321. package/dist/goal/negotiator-prompts.js +65 -0
  322. package/dist/goal/negotiator-prompts.js.map +1 -0
  323. package/dist/goal/negotiator-steps.d.ts +59 -0
  324. package/dist/goal/negotiator-steps.d.ts.map +1 -0
  325. package/dist/goal/negotiator-steps.js +269 -0
  326. package/dist/goal/negotiator-steps.js.map +1 -0
  327. package/dist/goal/state-aggregator.d.ts +89 -0
  328. package/dist/goal/state-aggregator.d.ts.map +1 -0
  329. package/dist/goal/state-aggregator.js +292 -0
  330. package/dist/goal/state-aggregator.js.map +1 -0
  331. package/dist/goal/tree-loop-orchestrator.d.ts +79 -0
  332. package/dist/goal/tree-loop-orchestrator.d.ts.map +1 -0
  333. package/dist/goal/tree-loop-orchestrator.js +230 -0
  334. package/dist/goal/tree-loop-orchestrator.js.map +1 -0
  335. package/dist/goal-dependency-graph.d.ts +112 -0
  336. package/dist/goal-dependency-graph.d.ts.map +1 -0
  337. package/dist/goal-dependency-graph.js +291 -0
  338. package/dist/goal-dependency-graph.js.map +1 -0
  339. package/dist/goal-negotiator.d.ts +109 -0
  340. package/dist/goal-negotiator.d.ts.map +1 -0
  341. package/dist/goal-negotiator.js +1044 -0
  342. package/dist/goal-negotiator.js.map +1 -0
  343. package/dist/goal-tree-manager.d.ts +120 -0
  344. package/dist/goal-tree-manager.d.ts.map +1 -0
  345. package/dist/goal-tree-manager.js +954 -0
  346. package/dist/goal-tree-manager.js.map +1 -0
  347. package/dist/guardrail-runner.d.ts +29 -0
  348. package/dist/guardrail-runner.d.ts.map +1 -0
  349. package/dist/guardrail-runner.js +81 -0
  350. package/dist/guardrail-runner.js.map +1 -0
  351. package/dist/index.d.ts +95 -0
  352. package/dist/index.d.ts.map +1 -0
  353. package/dist/index.js +75 -0
  354. package/dist/index.js.map +1 -0
  355. package/dist/knowledge/drive-score-adapter.d.ts +39 -0
  356. package/dist/knowledge/drive-score-adapter.d.ts.map +1 -0
  357. package/dist/knowledge/drive-score-adapter.js +32 -0
  358. package/dist/knowledge/drive-score-adapter.js.map +1 -0
  359. package/dist/knowledge/embedding-client.d.ts +49 -0
  360. package/dist/knowledge/embedding-client.d.ts.map +1 -0
  361. package/dist/knowledge/embedding-client.js +141 -0
  362. package/dist/knowledge/embedding-client.js.map +1 -0
  363. package/dist/knowledge/knowledge-decisions.d.ts +41 -0
  364. package/dist/knowledge/knowledge-decisions.d.ts.map +1 -0
  365. package/dist/knowledge/knowledge-decisions.js +191 -0
  366. package/dist/knowledge/knowledge-decisions.js.map +1 -0
  367. package/dist/knowledge/knowledge-graph.d.ts +74 -0
  368. package/dist/knowledge/knowledge-graph.d.ts.map +1 -0
  369. package/dist/knowledge/knowledge-graph.js +207 -0
  370. package/dist/knowledge/knowledge-graph.js.map +1 -0
  371. package/dist/knowledge/knowledge-manager.d.ts +138 -0
  372. package/dist/knowledge/knowledge-manager.d.ts.map +1 -0
  373. package/dist/knowledge/knowledge-manager.js +497 -0
  374. package/dist/knowledge/knowledge-manager.js.map +1 -0
  375. package/dist/knowledge/knowledge-revalidation.d.ts +27 -0
  376. package/dist/knowledge/knowledge-revalidation.d.ts.map +1 -0
  377. package/dist/knowledge/knowledge-revalidation.js +130 -0
  378. package/dist/knowledge/knowledge-revalidation.js.map +1 -0
  379. package/dist/knowledge/knowledge-search.d.ts +49 -0
  380. package/dist/knowledge/knowledge-search.d.ts.map +1 -0
  381. package/dist/knowledge/knowledge-search.js +108 -0
  382. package/dist/knowledge/knowledge-search.js.map +1 -0
  383. package/dist/knowledge/knowledge-transfer-prompts.d.ts +45 -0
  384. package/dist/knowledge/knowledge-transfer-prompts.d.ts.map +1 -0
  385. package/dist/knowledge/knowledge-transfer-prompts.js +72 -0
  386. package/dist/knowledge/knowledge-transfer-prompts.js.map +1 -0
  387. package/dist/knowledge/knowledge-transfer.d.ts +148 -0
  388. package/dist/knowledge/knowledge-transfer.d.ts.map +1 -0
  389. package/dist/knowledge/knowledge-transfer.js +718 -0
  390. package/dist/knowledge/knowledge-transfer.js.map +1 -0
  391. package/dist/knowledge/learning-cross-goal.d.ts +19 -0
  392. package/dist/knowledge/learning-cross-goal.d.ts.map +1 -0
  393. package/dist/knowledge/learning-cross-goal.js +173 -0
  394. package/dist/knowledge/learning-cross-goal.js.map +1 -0
  395. package/dist/knowledge/learning-feedback.d.ts +26 -0
  396. package/dist/knowledge/learning-feedback.d.ts.map +1 -0
  397. package/dist/knowledge/learning-feedback.js +183 -0
  398. package/dist/knowledge/learning-feedback.js.map +1 -0
  399. package/dist/knowledge/learning-pipeline-prompts.d.ts +134 -0
  400. package/dist/knowledge/learning-pipeline-prompts.d.ts.map +1 -0
  401. package/dist/knowledge/learning-pipeline-prompts.js +103 -0
  402. package/dist/knowledge/learning-pipeline-prompts.js.map +1 -0
  403. package/dist/knowledge/learning-pipeline.d.ts +108 -0
  404. package/dist/knowledge/learning-pipeline.d.ts.map +1 -0
  405. package/dist/knowledge/learning-pipeline.js +467 -0
  406. package/dist/knowledge/learning-pipeline.js.map +1 -0
  407. package/dist/knowledge/memory-compression.d.ts +44 -0
  408. package/dist/knowledge/memory-compression.d.ts.map +1 -0
  409. package/dist/knowledge/memory-compression.js +289 -0
  410. package/dist/knowledge/memory-compression.js.map +1 -0
  411. package/dist/knowledge/memory-distill.d.ts +31 -0
  412. package/dist/knowledge/memory-distill.d.ts.map +1 -0
  413. package/dist/knowledge/memory-distill.js +170 -0
  414. package/dist/knowledge/memory-distill.js.map +1 -0
  415. package/dist/knowledge/memory-index.d.ts +11 -0
  416. package/dist/knowledge/memory-index.d.ts.map +1 -0
  417. package/dist/knowledge/memory-index.js +134 -0
  418. package/dist/knowledge/memory-index.js.map +1 -0
  419. package/dist/knowledge/memory-lifecycle.d.ts +172 -0
  420. package/dist/knowledge/memory-lifecycle.d.ts.map +1 -0
  421. package/dist/knowledge/memory-lifecycle.js +398 -0
  422. package/dist/knowledge/memory-lifecycle.js.map +1 -0
  423. package/dist/knowledge/memory-persistence.d.ts +30 -0
  424. package/dist/knowledge/memory-persistence.d.ts.map +1 -0
  425. package/dist/knowledge/memory-persistence.js +120 -0
  426. package/dist/knowledge/memory-persistence.js.map +1 -0
  427. package/dist/knowledge/memory-phases.d.ts +14 -0
  428. package/dist/knowledge/memory-phases.d.ts.map +1 -0
  429. package/dist/knowledge/memory-phases.js +14 -0
  430. package/dist/knowledge/memory-phases.js.map +1 -0
  431. package/dist/knowledge/memory-query.d.ts +4 -0
  432. package/dist/knowledge/memory-query.d.ts.map +1 -0
  433. package/dist/knowledge/memory-query.js +64 -0
  434. package/dist/knowledge/memory-query.js.map +1 -0
  435. package/dist/knowledge/memory-selection.d.ts +80 -0
  436. package/dist/knowledge/memory-selection.d.ts.map +1 -0
  437. package/dist/knowledge/memory-selection.js +356 -0
  438. package/dist/knowledge/memory-selection.js.map +1 -0
  439. package/dist/knowledge/memory-stats.d.ts +7 -0
  440. package/dist/knowledge/memory-stats.d.ts.map +1 -0
  441. package/dist/knowledge/memory-stats.js +162 -0
  442. package/dist/knowledge/memory-stats.js.map +1 -0
  443. package/dist/knowledge/memory-tier.d.ts +47 -0
  444. package/dist/knowledge/memory-tier.d.ts.map +1 -0
  445. package/dist/knowledge/memory-tier.js +212 -0
  446. package/dist/knowledge/memory-tier.js.map +1 -0
  447. package/dist/knowledge/transfer-trust.d.ts +40 -0
  448. package/dist/knowledge/transfer-trust.d.ts.map +1 -0
  449. package/dist/knowledge/transfer-trust.js +137 -0
  450. package/dist/knowledge/transfer-trust.js.map +1 -0
  451. package/dist/knowledge/vector-index.d.ts +65 -0
  452. package/dist/knowledge/vector-index.d.ts.map +1 -0
  453. package/dist/knowledge/vector-index.js +153 -0
  454. package/dist/knowledge/vector-index.js.map +1 -0
  455. package/dist/knowledge-graph.d.ts +70 -0
  456. package/dist/knowledge-graph.d.ts.map +1 -0
  457. package/dist/knowledge-graph.js +194 -0
  458. package/dist/knowledge-graph.js.map +1 -0
  459. package/dist/knowledge-manager.d.ts +110 -0
  460. package/dist/knowledge-manager.d.ts.map +1 -0
  461. package/dist/knowledge-manager.js +544 -0
  462. package/dist/knowledge-manager.js.map +1 -0
  463. package/dist/knowledge-transfer.d.ts +101 -0
  464. package/dist/knowledge-transfer.d.ts.map +1 -0
  465. package/dist/knowledge-transfer.js +484 -0
  466. package/dist/knowledge-transfer.js.map +1 -0
  467. package/dist/learning-pipeline.d.ts +107 -0
  468. package/dist/learning-pipeline.d.ts.map +1 -0
  469. package/dist/learning-pipeline.js +840 -0
  470. package/dist/learning-pipeline.js.map +1 -0
  471. package/dist/llm/base-llm-client.d.ts +20 -0
  472. package/dist/llm/base-llm-client.d.ts.map +1 -0
  473. package/dist/llm/base-llm-client.js +48 -0
  474. package/dist/llm/base-llm-client.js.map +1 -0
  475. package/dist/llm/codex-llm-client.d.ts +41 -0
  476. package/dist/llm/codex-llm-client.d.ts.map +1 -0
  477. package/dist/llm/codex-llm-client.js +188 -0
  478. package/dist/llm/codex-llm-client.js.map +1 -0
  479. package/dist/llm/llm-client.d.ts +54 -0
  480. package/dist/llm/llm-client.d.ts.map +1 -0
  481. package/dist/llm/llm-client.js +148 -0
  482. package/dist/llm/llm-client.js.map +1 -0
  483. package/dist/llm/ollama-client.d.ts +24 -0
  484. package/dist/llm/ollama-client.d.ts.map +1 -0
  485. package/dist/llm/ollama-client.js +94 -0
  486. package/dist/llm/ollama-client.js.map +1 -0
  487. package/dist/llm/openai-client.d.ts +34 -0
  488. package/dist/llm/openai-client.d.ts.map +1 -0
  489. package/dist/llm/openai-client.js +140 -0
  490. package/dist/llm/openai-client.js.map +1 -0
  491. package/dist/llm/provider-config.d.ts +55 -0
  492. package/dist/llm/provider-config.d.ts.map +1 -0
  493. package/dist/llm/provider-config.js +136 -0
  494. package/dist/llm/provider-config.js.map +1 -0
  495. package/dist/llm/provider-factory.d.ts +25 -0
  496. package/dist/llm/provider-factory.d.ts.map +1 -0
  497. package/dist/llm/provider-factory.js +111 -0
  498. package/dist/llm/provider-factory.js.map +1 -0
  499. package/dist/llm-client.d.ts +65 -0
  500. package/dist/llm-client.d.ts.map +1 -0
  501. package/dist/llm-client.js +151 -0
  502. package/dist/llm-client.js.map +1 -0
  503. package/dist/logger.d.ts +30 -0
  504. package/dist/logger.d.ts.map +1 -0
  505. package/dist/logger.js +121 -0
  506. package/dist/logger.js.map +1 -0
  507. package/dist/loop/core-loop-capability.d.ts +19 -0
  508. package/dist/loop/core-loop-capability.d.ts.map +1 -0
  509. package/dist/loop/core-loop-capability.js +107 -0
  510. package/dist/loop/core-loop-capability.js.map +1 -0
  511. package/dist/loop/core-loop-learning.d.ts +34 -0
  512. package/dist/loop/core-loop-learning.d.ts.map +1 -0
  513. package/dist/loop/core-loop-learning.js +78 -0
  514. package/dist/loop/core-loop-learning.js.map +1 -0
  515. package/dist/loop/core-loop-phases-b.d.ts +25 -0
  516. package/dist/loop/core-loop-phases-b.d.ts.map +1 -0
  517. package/dist/loop/core-loop-phases-b.js +510 -0
  518. package/dist/loop/core-loop-phases-b.js.map +1 -0
  519. package/dist/loop/core-loop-phases.d.ts +40 -0
  520. package/dist/loop/core-loop-phases.d.ts.map +1 -0
  521. package/dist/loop/core-loop-phases.js +228 -0
  522. package/dist/loop/core-loop-phases.js.map +1 -0
  523. package/dist/loop/core-loop-types.d.ts +202 -0
  524. package/dist/loop/core-loop-types.d.ts.map +1 -0
  525. package/dist/loop/core-loop-types.js +38 -0
  526. package/dist/loop/core-loop-types.js.map +1 -0
  527. package/dist/loop/tree-loop-runner.d.ts +24 -0
  528. package/dist/loop/tree-loop-runner.d.ts.map +1 -0
  529. package/dist/loop/tree-loop-runner.js +116 -0
  530. package/dist/loop/tree-loop-runner.js.map +1 -0
  531. package/dist/memory-lifecycle.d.ts +244 -0
  532. package/dist/memory-lifecycle.d.ts.map +1 -0
  533. package/dist/memory-lifecycle.js +1328 -0
  534. package/dist/memory-lifecycle.js.map +1 -0
  535. package/dist/notification-dispatcher.d.ts +36 -0
  536. package/dist/notification-dispatcher.d.ts.map +1 -0
  537. package/dist/notification-dispatcher.js +363 -0
  538. package/dist/notification-dispatcher.js.map +1 -0
  539. package/dist/observation/capability-dependencies.d.ts +45 -0
  540. package/dist/observation/capability-dependencies.d.ts.map +1 -0
  541. package/dist/observation/capability-dependencies.js +208 -0
  542. package/dist/observation/capability-dependencies.js.map +1 -0
  543. package/dist/observation/capability-detector.d.ts +72 -0
  544. package/dist/observation/capability-detector.d.ts.map +1 -0
  545. package/dist/observation/capability-detector.js +372 -0
  546. package/dist/observation/capability-detector.js.map +1 -0
  547. package/dist/observation/capability-registry.d.ts +48 -0
  548. package/dist/observation/capability-registry.d.ts.map +1 -0
  549. package/dist/observation/capability-registry.js +131 -0
  550. package/dist/observation/capability-registry.js.map +1 -0
  551. package/dist/observation/context-provider.d.ts +39 -0
  552. package/dist/observation/context-provider.d.ts.map +1 -0
  553. package/dist/observation/context-provider.js +177 -0
  554. package/dist/observation/context-provider.js.map +1 -0
  555. package/dist/observation/data-source-adapter.d.ts +42 -0
  556. package/dist/observation/data-source-adapter.d.ts.map +1 -0
  557. package/dist/observation/data-source-adapter.js +227 -0
  558. package/dist/observation/data-source-adapter.js.map +1 -0
  559. package/dist/observation/observation-apply.d.ts +18 -0
  560. package/dist/observation/observation-apply.d.ts.map +1 -0
  561. package/dist/observation/observation-apply.js +138 -0
  562. package/dist/observation/observation-apply.js.map +1 -0
  563. package/dist/observation/observation-datasource.d.ts +21 -0
  564. package/dist/observation/observation-datasource.d.ts.map +1 -0
  565. package/dist/observation/observation-datasource.js +96 -0
  566. package/dist/observation/observation-datasource.js.map +1 -0
  567. package/dist/observation/observation-engine.d.ts +156 -0
  568. package/dist/observation/observation-engine.d.ts.map +1 -0
  569. package/dist/observation/observation-engine.js +359 -0
  570. package/dist/observation/observation-engine.js.map +1 -0
  571. package/dist/observation/observation-helpers.d.ts +112 -0
  572. package/dist/observation/observation-helpers.d.ts.map +1 -0
  573. package/dist/observation/observation-helpers.js +173 -0
  574. package/dist/observation/observation-helpers.js.map +1 -0
  575. package/dist/observation/observation-llm.d.ts +46 -0
  576. package/dist/observation/observation-llm.d.ts.map +1 -0
  577. package/dist/observation/observation-llm.js +220 -0
  578. package/dist/observation/observation-llm.js.map +1 -0
  579. package/dist/observation/observation-task.d.ts +29 -0
  580. package/dist/observation/observation-task.d.ts.map +1 -0
  581. package/dist/observation/observation-task.js +51 -0
  582. package/dist/observation/observation-task.js.map +1 -0
  583. package/dist/observation/workspace-context.d.ts +8 -0
  584. package/dist/observation/workspace-context.d.ts.map +1 -0
  585. package/dist/observation/workspace-context.js +229 -0
  586. package/dist/observation/workspace-context.js.map +1 -0
  587. package/dist/observation-engine.d.ts +218 -0
  588. package/dist/observation-engine.d.ts.map +1 -0
  589. package/dist/observation-engine.js +711 -0
  590. package/dist/observation-engine.js.map +1 -0
  591. package/dist/ollama-client.d.ts +30 -0
  592. package/dist/ollama-client.d.ts.map +1 -0
  593. package/dist/ollama-client.js +112 -0
  594. package/dist/ollama-client.js.map +1 -0
  595. package/dist/openai-client.d.ts +40 -0
  596. package/dist/openai-client.d.ts.map +1 -0
  597. package/dist/openai-client.js +155 -0
  598. package/dist/openai-client.js.map +1 -0
  599. package/dist/pid-manager.d.ts +18 -0
  600. package/dist/pid-manager.d.ts.map +1 -0
  601. package/dist/pid-manager.js +64 -0
  602. package/dist/pid-manager.js.map +1 -0
  603. package/dist/portfolio-manager.d.ts +147 -0
  604. package/dist/portfolio-manager.d.ts.map +1 -0
  605. package/dist/portfolio-manager.js +371 -0
  606. package/dist/portfolio-manager.js.map +1 -0
  607. package/dist/portfolio-rebalance.d.ts +75 -0
  608. package/dist/portfolio-rebalance.d.ts.map +1 -0
  609. package/dist/portfolio-rebalance.js +254 -0
  610. package/dist/portfolio-rebalance.js.map +1 -0
  611. package/dist/prompt/context-assembler.d.ts +70 -0
  612. package/dist/prompt/context-assembler.d.ts.map +1 -0
  613. package/dist/prompt/context-assembler.js +346 -0
  614. package/dist/prompt/context-assembler.js.map +1 -0
  615. package/dist/prompt/formatters.d.ts +49 -0
  616. package/dist/prompt/formatters.d.ts.map +1 -0
  617. package/dist/prompt/formatters.js +136 -0
  618. package/dist/prompt/formatters.js.map +1 -0
  619. package/dist/prompt/gateway.d.ts +30 -0
  620. package/dist/prompt/gateway.d.ts.map +1 -0
  621. package/dist/prompt/gateway.js +43 -0
  622. package/dist/prompt/gateway.js.map +1 -0
  623. package/dist/prompt/index.d.ts +12 -0
  624. package/dist/prompt/index.d.ts.map +1 -0
  625. package/dist/prompt/index.js +9 -0
  626. package/dist/prompt/index.js.map +1 -0
  627. package/dist/prompt/purposes/capability.d.ts +64 -0
  628. package/dist/prompt/purposes/capability.d.ts.map +1 -0
  629. package/dist/prompt/purposes/capability.js +38 -0
  630. package/dist/prompt/purposes/capability.js.map +1 -0
  631. package/dist/prompt/purposes/checkpoint.d.ts +22 -0
  632. package/dist/prompt/purposes/checkpoint.d.ts.map +1 -0
  633. package/dist/prompt/purposes/checkpoint.js +17 -0
  634. package/dist/prompt/purposes/checkpoint.js.map +1 -0
  635. package/dist/prompt/purposes/curiosity.d.ts +41 -0
  636. package/dist/prompt/purposes/curiosity.d.ts.map +1 -0
  637. package/dist/prompt/purposes/curiosity.js +20 -0
  638. package/dist/prompt/purposes/curiosity.js.map +1 -0
  639. package/dist/prompt/purposes/dependency.d.ts +34 -0
  640. package/dist/prompt/purposes/dependency.d.ts.map +1 -0
  641. package/dist/prompt/purposes/dependency.js +21 -0
  642. package/dist/prompt/purposes/dependency.js.map +1 -0
  643. package/dist/prompt/purposes/ethics.d.ts +47 -0
  644. package/dist/prompt/purposes/ethics.d.ts.map +1 -0
  645. package/dist/prompt/purposes/ethics.js +89 -0
  646. package/dist/prompt/purposes/ethics.js.map +1 -0
  647. package/dist/prompt/purposes/final-migration.d.ts +15 -0
  648. package/dist/prompt/purposes/final-migration.d.ts.map +1 -0
  649. package/dist/prompt/purposes/final-migration.js +15 -0
  650. package/dist/prompt/purposes/final-migration.js.map +1 -0
  651. package/dist/prompt/purposes/goal-decomposition.d.ts +46 -0
  652. package/dist/prompt/purposes/goal-decomposition.d.ts.map +1 -0
  653. package/dist/prompt/purposes/goal-decomposition.js +20 -0
  654. package/dist/prompt/purposes/goal-decomposition.js.map +1 -0
  655. package/dist/prompt/purposes/goal-quality.d.ts +61 -0
  656. package/dist/prompt/purposes/goal-quality.d.ts.map +1 -0
  657. package/dist/prompt/purposes/goal-quality.js +37 -0
  658. package/dist/prompt/purposes/goal-quality.js.map +1 -0
  659. package/dist/prompt/purposes/index.d.ts +29 -0
  660. package/dist/prompt/purposes/index.d.ts.map +1 -0
  661. package/dist/prompt/purposes/index.js +320 -0
  662. package/dist/prompt/purposes/index.js.map +1 -0
  663. package/dist/prompt/purposes/knowledge-transfer.d.ts +81 -0
  664. package/dist/prompt/purposes/knowledge-transfer.d.ts.map +1 -0
  665. package/dist/prompt/purposes/knowledge-transfer.js +33 -0
  666. package/dist/prompt/purposes/knowledge-transfer.js.map +1 -0
  667. package/dist/prompt/purposes/knowledge.d.ts +88 -0
  668. package/dist/prompt/purposes/knowledge.d.ts.map +1 -0
  669. package/dist/prompt/purposes/knowledge.js +59 -0
  670. package/dist/prompt/purposes/knowledge.js.map +1 -0
  671. package/dist/prompt/purposes/learning.d.ts +70 -0
  672. package/dist/prompt/purposes/learning.d.ts.map +1 -0
  673. package/dist/prompt/purposes/learning.js +32 -0
  674. package/dist/prompt/purposes/learning.js.map +1 -0
  675. package/dist/prompt/purposes/memory-distill.d.ts +75 -0
  676. package/dist/prompt/purposes/memory-distill.d.ts.map +1 -0
  677. package/dist/prompt/purposes/memory-distill.js +27 -0
  678. package/dist/prompt/purposes/memory-distill.js.map +1 -0
  679. package/dist/prompt/purposes/observation.d.ts +25 -0
  680. package/dist/prompt/purposes/observation.d.ts.map +1 -0
  681. package/dist/prompt/purposes/observation.js +17 -0
  682. package/dist/prompt/purposes/observation.js.map +1 -0
  683. package/dist/prompt/purposes/strategy-template.d.ts +57 -0
  684. package/dist/prompt/purposes/strategy-template.d.ts.map +1 -0
  685. package/dist/prompt/purposes/strategy-template.js +31 -0
  686. package/dist/prompt/purposes/strategy-template.js.map +1 -0
  687. package/dist/prompt/purposes/strategy.d.ts +41 -0
  688. package/dist/prompt/purposes/strategy.d.ts.map +1 -0
  689. package/dist/prompt/purposes/strategy.js +19 -0
  690. package/dist/prompt/purposes/strategy.js.map +1 -0
  691. package/dist/prompt/purposes/task-generation.d.ts +26 -0
  692. package/dist/prompt/purposes/task-generation.d.ts.map +1 -0
  693. package/dist/prompt/purposes/task-generation.js +22 -0
  694. package/dist/prompt/purposes/task-generation.js.map +1 -0
  695. package/dist/prompt/purposes/verification.d.ts +25 -0
  696. package/dist/prompt/purposes/verification.d.ts.map +1 -0
  697. package/dist/prompt/purposes/verification.js +17 -0
  698. package/dist/prompt/purposes/verification.js.map +1 -0
  699. package/dist/prompt/slot-definitions 2.d.ts +33 -0
  700. package/dist/prompt/slot-definitions 2.d.ts.map +1 -0
  701. package/dist/prompt/slot-definitions 2.js +332 -0
  702. package/dist/prompt/slot-definitions 2.js.map +1 -0
  703. package/dist/prompt/slot-definitions.d.ts +33 -0
  704. package/dist/prompt/slot-definitions.d.ts.map +1 -0
  705. package/dist/prompt/slot-definitions.js +383 -0
  706. package/dist/prompt/slot-definitions.js.map +1 -0
  707. package/dist/provider-config.d.ts +43 -0
  708. package/dist/provider-config.d.ts.map +1 -0
  709. package/dist/provider-config.js +131 -0
  710. package/dist/provider-config.js.map +1 -0
  711. package/dist/provider-factory.d.ts +23 -0
  712. package/dist/provider-factory.d.ts.map +1 -0
  713. package/dist/provider-factory.js +83 -0
  714. package/dist/provider-factory.js.map +1 -0
  715. package/dist/reporting-engine.d.ts +58 -0
  716. package/dist/reporting-engine.d.ts.map +1 -0
  717. package/dist/reporting-engine.js +592 -0
  718. package/dist/reporting-engine.js.map +1 -0
  719. package/dist/runtime/daemon-runner.d.ts +147 -0
  720. package/dist/runtime/daemon-runner.d.ts.map +1 -0
  721. package/dist/runtime/daemon-runner.js +549 -0
  722. package/dist/runtime/daemon-runner.js.map +1 -0
  723. package/dist/runtime/event-server.d.ts +50 -0
  724. package/dist/runtime/event-server.d.ts.map +1 -0
  725. package/dist/runtime/event-server.js +192 -0
  726. package/dist/runtime/event-server.js.map +1 -0
  727. package/dist/runtime/logger.d.ts +57 -0
  728. package/dist/runtime/logger.d.ts.map +1 -0
  729. package/dist/runtime/logger.js +254 -0
  730. package/dist/runtime/logger.js.map +1 -0
  731. package/dist/runtime/notification-dispatcher.d.ts +49 -0
  732. package/dist/runtime/notification-dispatcher.d.ts.map +1 -0
  733. package/dist/runtime/notification-dispatcher.js +444 -0
  734. package/dist/runtime/notification-dispatcher.js.map +1 -0
  735. package/dist/runtime/notifier-registry.d.ts +26 -0
  736. package/dist/runtime/notifier-registry.d.ts.map +1 -0
  737. package/dist/runtime/notifier-registry.js +36 -0
  738. package/dist/runtime/notifier-registry.js.map +1 -0
  739. package/dist/runtime/pid-manager.d.ts +18 -0
  740. package/dist/runtime/pid-manager.d.ts.map +1 -0
  741. package/dist/runtime/pid-manager.js +61 -0
  742. package/dist/runtime/pid-manager.js.map +1 -0
  743. package/dist/runtime/plugin-loader.d.ts +78 -0
  744. package/dist/runtime/plugin-loader.d.ts.map +1 -0
  745. package/dist/runtime/plugin-loader.js +349 -0
  746. package/dist/runtime/plugin-loader.js.map +1 -0
  747. package/dist/satisficing-judge.d.ts +113 -0
  748. package/dist/satisficing-judge.d.ts.map +1 -0
  749. package/dist/satisficing-judge.js +592 -0
  750. package/dist/satisficing-judge.js.map +1 -0
  751. package/dist/session-manager.d.ts +159 -0
  752. package/dist/session-manager.d.ts.map +1 -0
  753. package/dist/session-manager.js +458 -0
  754. package/dist/session-manager.js.map +1 -0
  755. package/dist/stall-detector.d.ts +100 -0
  756. package/dist/stall-detector.d.ts.map +1 -0
  757. package/dist/stall-detector.js +306 -0
  758. package/dist/stall-detector.js.map +1 -0
  759. package/dist/state-aggregator.d.ts +89 -0
  760. package/dist/state-aggregator.d.ts.map +1 -0
  761. package/dist/state-aggregator.js +290 -0
  762. package/dist/state-aggregator.js.map +1 -0
  763. package/dist/state-manager.d.ts +121 -0
  764. package/dist/state-manager.d.ts.map +1 -0
  765. package/dist/state-manager.js +547 -0
  766. package/dist/state-manager.js.map +1 -0
  767. package/dist/strategy/cross-goal-portfolio.d.ts +118 -0
  768. package/dist/strategy/cross-goal-portfolio.d.ts.map +1 -0
  769. package/dist/strategy/cross-goal-portfolio.js +431 -0
  770. package/dist/strategy/cross-goal-portfolio.js.map +1 -0
  771. package/dist/strategy/portfolio-allocation.d.ts +36 -0
  772. package/dist/strategy/portfolio-allocation.d.ts.map +1 -0
  773. package/dist/strategy/portfolio-allocation.js +215 -0
  774. package/dist/strategy/portfolio-allocation.js.map +1 -0
  775. package/dist/strategy/portfolio-momentum.d.ts +11 -0
  776. package/dist/strategy/portfolio-momentum.d.ts.map +1 -0
  777. package/dist/strategy/portfolio-momentum.js +64 -0
  778. package/dist/strategy/portfolio-momentum.js.map +1 -0
  779. package/dist/strategy/portfolio-scheduling.d.ts +25 -0
  780. package/dist/strategy/portfolio-scheduling.d.ts.map +1 -0
  781. package/dist/strategy/portfolio-scheduling.js +133 -0
  782. package/dist/strategy/portfolio-scheduling.js.map +1 -0
  783. package/dist/strategy/strategy-helpers.d.ts +109 -0
  784. package/dist/strategy/strategy-helpers.d.ts.map +1 -0
  785. package/dist/strategy/strategy-helpers.js +125 -0
  786. package/dist/strategy/strategy-helpers.js.map +1 -0
  787. package/dist/strategy/strategy-manager-base.d.ts +95 -0
  788. package/dist/strategy/strategy-manager-base.d.ts.map +1 -0
  789. package/dist/strategy/strategy-manager-base.js +363 -0
  790. package/dist/strategy/strategy-manager-base.js.map +1 -0
  791. package/dist/strategy/strategy-manager.d.ts +65 -0
  792. package/dist/strategy/strategy-manager.d.ts.map +1 -0
  793. package/dist/strategy/strategy-manager.js +226 -0
  794. package/dist/strategy/strategy-manager.js.map +1 -0
  795. package/dist/strategy/strategy-template-registry.d.ts +84 -0
  796. package/dist/strategy/strategy-template-registry.d.ts.map +1 -0
  797. package/dist/strategy/strategy-template-registry.js +350 -0
  798. package/dist/strategy/strategy-template-registry.js.map +1 -0
  799. package/dist/strategy-manager.d.ts +128 -0
  800. package/dist/strategy-manager.d.ts.map +1 -0
  801. package/dist/strategy-manager.js +579 -0
  802. package/dist/strategy-manager.js.map +1 -0
  803. package/dist/strategy-template-registry.d.ts +80 -0
  804. package/dist/strategy-template-registry.d.ts.map +1 -0
  805. package/dist/strategy-template-registry.js +320 -0
  806. package/dist/strategy-template-registry.js.map +1 -0
  807. package/dist/task-lifecycle.d.ts +167 -0
  808. package/dist/task-lifecycle.d.ts.map +1 -0
  809. package/dist/task-lifecycle.js +1161 -0
  810. package/dist/task-lifecycle.js.map +1 -0
  811. package/dist/traits/character-config.d.ts +34 -0
  812. package/dist/traits/character-config.d.ts.map +1 -0
  813. package/dist/traits/character-config.js +53 -0
  814. package/dist/traits/character-config.js.map +1 -0
  815. package/dist/traits/curiosity-engine.d.ts +185 -0
  816. package/dist/traits/curiosity-engine.d.ts.map +1 -0
  817. package/dist/traits/curiosity-engine.js +530 -0
  818. package/dist/traits/curiosity-engine.js.map +1 -0
  819. package/dist/traits/curiosity-proposals.d.ts +38 -0
  820. package/dist/traits/curiosity-proposals.d.ts.map +1 -0
  821. package/dist/traits/curiosity-proposals.js +259 -0
  822. package/dist/traits/curiosity-proposals.js.map +1 -0
  823. package/dist/traits/curiosity-transfer.d.ts +27 -0
  824. package/dist/traits/curiosity-transfer.d.ts.map +1 -0
  825. package/dist/traits/curiosity-transfer.js +50 -0
  826. package/dist/traits/curiosity-transfer.js.map +1 -0
  827. package/dist/traits/ethics-gate.d.ts +72 -0
  828. package/dist/traits/ethics-gate.d.ts.map +1 -0
  829. package/dist/traits/ethics-gate.js +591 -0
  830. package/dist/traits/ethics-gate.js.map +1 -0
  831. package/dist/traits/trust-manager.d.ts +90 -0
  832. package/dist/traits/trust-manager.d.ts.map +1 -0
  833. package/dist/traits/trust-manager.js +276 -0
  834. package/dist/traits/trust-manager.js.map +1 -0
  835. package/dist/tree-loop-orchestrator.d.ts +79 -0
  836. package/dist/tree-loop-orchestrator.d.ts.map +1 -0
  837. package/dist/tree-loop-orchestrator.js +225 -0
  838. package/dist/tree-loop-orchestrator.js.map +1 -0
  839. package/dist/trust-manager.d.ts +67 -0
  840. package/dist/trust-manager.d.ts.map +1 -0
  841. package/dist/trust-manager.js +201 -0
  842. package/dist/trust-manager.js.map +1 -0
  843. package/dist/tui/actions.d.ts +38 -0
  844. package/dist/tui/actions.d.ts.map +1 -0
  845. package/dist/tui/actions.js +229 -0
  846. package/dist/tui/actions.js.map +1 -0
  847. package/dist/tui/app.d.ts +24 -0
  848. package/dist/tui/app.d.ts.map +1 -0
  849. package/dist/tui/app.js +159 -0
  850. package/dist/tui/app.js.map +1 -0
  851. package/dist/tui/approval-overlay.d.ts +8 -0
  852. package/dist/tui/approval-overlay.d.ts.map +1 -0
  853. package/dist/tui/approval-overlay.js +20 -0
  854. package/dist/tui/approval-overlay.js.map +1 -0
  855. package/dist/tui/chat.d.ts +15 -0
  856. package/dist/tui/chat.d.ts.map +1 -0
  857. package/dist/tui/chat.js +196 -0
  858. package/dist/tui/chat.js.map +1 -0
  859. package/dist/tui/dashboard.d.ts +9 -0
  860. package/dist/tui/dashboard.d.ts.map +1 -0
  861. package/dist/tui/dashboard.js +69 -0
  862. package/dist/tui/dashboard.js.map +1 -0
  863. package/dist/tui/entry.d.ts +3 -0
  864. package/dist/tui/entry.d.ts.map +1 -0
  865. package/dist/tui/entry.js +222 -0
  866. package/dist/tui/entry.js.map +1 -0
  867. package/dist/tui/fuzzy.d.ts +22 -0
  868. package/dist/tui/fuzzy.d.ts.map +1 -0
  869. package/dist/tui/fuzzy.js +66 -0
  870. package/dist/tui/fuzzy.js.map +1 -0
  871. package/dist/tui/help-overlay.d.ts +6 -0
  872. package/dist/tui/help-overlay.d.ts.map +1 -0
  873. package/dist/tui/help-overlay.js +12 -0
  874. package/dist/tui/help-overlay.js.map +1 -0
  875. package/dist/tui/intent-recognizer.d.ts +19 -0
  876. package/dist/tui/intent-recognizer.d.ts.map +1 -0
  877. package/dist/tui/intent-recognizer.js +125 -0
  878. package/dist/tui/intent-recognizer.js.map +1 -0
  879. package/dist/tui/markdown-renderer.d.ts +37 -0
  880. package/dist/tui/markdown-renderer.d.ts.map +1 -0
  881. package/dist/tui/markdown-renderer.js +220 -0
  882. package/dist/tui/markdown-renderer.js.map +1 -0
  883. package/dist/tui/report-view.d.ts +6 -0
  884. package/dist/tui/report-view.d.ts.map +1 -0
  885. package/dist/tui/report-view.js +79 -0
  886. package/dist/tui/report-view.js.map +1 -0
  887. package/dist/tui/use-loop.d.ts +54 -0
  888. package/dist/tui/use-loop.d.ts.map +1 -0
  889. package/dist/tui/use-loop.js +185 -0
  890. package/dist/tui/use-loop.js.map +1 -0
  891. package/dist/types/a2a.d.ts +972 -0
  892. package/dist/types/a2a.d.ts.map +1 -0
  893. package/dist/types/a2a.js +130 -0
  894. package/dist/types/a2a.js.map +1 -0
  895. package/dist/types/capability.d.ts +292 -0
  896. package/dist/types/capability.d.ts.map +1 -0
  897. package/dist/types/capability.js +53 -0
  898. package/dist/types/capability.js.map +1 -0
  899. package/dist/types/character.d.ts +20 -0
  900. package/dist/types/character.d.ts.map +1 -0
  901. package/dist/types/character.js +10 -0
  902. package/dist/types/character.js.map +1 -0
  903. package/dist/types/checkpoint.d.ts +109 -0
  904. package/dist/types/checkpoint.d.ts.map +1 -0
  905. package/dist/types/checkpoint.js +27 -0
  906. package/dist/types/checkpoint.js.map +1 -0
  907. package/dist/types/core.d.ts +175 -0
  908. package/dist/types/core.d.ts.map +1 -0
  909. package/dist/types/core.js +154 -0
  910. package/dist/types/core.js.map +1 -0
  911. package/dist/types/cross-portfolio.d.ts +378 -0
  912. package/dist/types/cross-portfolio.d.ts.map +1 -0
  913. package/dist/types/cross-portfolio.js +155 -0
  914. package/dist/types/cross-portfolio.js.map +1 -0
  915. package/dist/types/curiosity.d.ts +443 -0
  916. package/dist/types/curiosity.d.ts.map +1 -0
  917. package/dist/types/curiosity.js +86 -0
  918. package/dist/types/curiosity.js.map +1 -0
  919. package/dist/types/daemon.d.ts +111 -0
  920. package/dist/types/daemon.d.ts.map +1 -0
  921. package/dist/types/daemon.js +37 -0
  922. package/dist/types/daemon.js.map +1 -0
  923. package/dist/types/data-source.d.ts +311 -0
  924. package/dist/types/data-source.d.ts.map +1 -0
  925. package/dist/types/data-source.js +53 -0
  926. package/dist/types/data-source.js.map +1 -0
  927. package/dist/types/dependency.d.ts +108 -0
  928. package/dist/types/dependency.d.ts.map +1 -0
  929. package/dist/types/dependency.js +21 -0
  930. package/dist/types/dependency.js.map +1 -0
  931. package/dist/types/drive.d.ts +194 -0
  932. package/dist/types/drive.d.ts.map +1 -0
  933. package/dist/types/drive.js +77 -0
  934. package/dist/types/drive.js.map +1 -0
  935. package/dist/types/embedding.d.ts +59 -0
  936. package/dist/types/embedding.d.ts.map +1 -0
  937. package/dist/types/embedding.js +22 -0
  938. package/dist/types/embedding.js.map +1 -0
  939. package/dist/types/ethics.d.ts +169 -0
  940. package/dist/types/ethics.d.ts.map +1 -0
  941. package/dist/types/ethics.js +47 -0
  942. package/dist/types/ethics.js.map +1 -0
  943. package/dist/types/gap.d.ts +146 -0
  944. package/dist/types/gap.d.ts.map +1 -0
  945. package/dist/types/gap.js +41 -0
  946. package/dist/types/gap.js.map +1 -0
  947. package/dist/types/goal-tree.d.ts +180 -0
  948. package/dist/types/goal-tree.d.ts.map +1 -0
  949. package/dist/types/goal-tree.js +73 -0
  950. package/dist/types/goal-tree.js.map +1 -0
  951. package/dist/types/goal.d.ts +1233 -0
  952. package/dist/types/goal.d.ts.map +1 -0
  953. package/dist/types/goal.js +119 -0
  954. package/dist/types/goal.js.map +1 -0
  955. package/dist/types/guardrail.d.ts +104 -0
  956. package/dist/types/guardrail.d.ts.map +1 -0
  957. package/dist/types/guardrail.js +34 -0
  958. package/dist/types/guardrail.js.map +1 -0
  959. package/dist/types/index.d.ts +31 -0
  960. package/dist/types/index.d.ts.map +1 -0
  961. package/dist/types/index.js +31 -0
  962. package/dist/types/index.js.map +1 -0
  963. package/dist/types/knowledge.d.ts +402 -0
  964. package/dist/types/knowledge.d.ts.map +1 -0
  965. package/dist/types/knowledge.js +116 -0
  966. package/dist/types/knowledge.js.map +1 -0
  967. package/dist/types/learning.d.ts +292 -0
  968. package/dist/types/learning.d.ts.map +1 -0
  969. package/dist/types/learning.js +120 -0
  970. package/dist/types/learning.js.map +1 -0
  971. package/dist/types/memory-lifecycle.d.ts +617 -0
  972. package/dist/types/memory-lifecycle.d.ts.map +1 -0
  973. package/dist/types/memory-lifecycle.js +159 -0
  974. package/dist/types/memory-lifecycle.js.map +1 -0
  975. package/dist/types/negotiation.d.ts +450 -0
  976. package/dist/types/negotiation.d.ts.map +1 -0
  977. package/dist/types/negotiation.js +84 -0
  978. package/dist/types/negotiation.js.map +1 -0
  979. package/dist/types/notification.d.ts +879 -0
  980. package/dist/types/notification.d.ts.map +1 -0
  981. package/dist/types/notification.js +75 -0
  982. package/dist/types/notification.js.map +1 -0
  983. package/dist/types/pipeline.d.ts +191 -0
  984. package/dist/types/pipeline.d.ts.map +1 -0
  985. package/dist/types/pipeline.js +62 -0
  986. package/dist/types/pipeline.js.map +1 -0
  987. package/dist/types/plugin.d.ts +335 -0
  988. package/dist/types/plugin.d.ts.map +1 -0
  989. package/dist/types/plugin.js +61 -0
  990. package/dist/types/plugin.js.map +1 -0
  991. package/dist/types/portfolio.d.ts +146 -0
  992. package/dist/types/portfolio.d.ts.map +1 -0
  993. package/dist/types/portfolio.js +55 -0
  994. package/dist/types/portfolio.js.map +1 -0
  995. package/dist/types/reflection.d.ts +34 -0
  996. package/dist/types/reflection.d.ts.map +1 -0
  997. package/dist/types/reflection.js +14 -0
  998. package/dist/types/reflection.js.map +1 -0
  999. package/dist/types/report.d.ts +205 -0
  1000. package/dist/types/report.d.ts.map +1 -0
  1001. package/dist/types/report.js +59 -0
  1002. package/dist/types/report.js.map +1 -0
  1003. package/dist/types/satisficing.d.ts +130 -0
  1004. package/dist/types/satisficing.d.ts.map +1 -0
  1005. package/dist/types/satisficing.js +54 -0
  1006. package/dist/types/satisficing.js.map +1 -0
  1007. package/dist/types/session.d.ts +95 -0
  1008. package/dist/types/session.d.ts.map +1 -0
  1009. package/dist/types/session.js +36 -0
  1010. package/dist/types/session.js.map +1 -0
  1011. package/dist/types/stall.d.ts +68 -0
  1012. package/dist/types/stall.d.ts.map +1 -0
  1013. package/dist/types/stall.js +28 -0
  1014. package/dist/types/stall.js.map +1 -0
  1015. package/dist/types/state.d.ts +245 -0
  1016. package/dist/types/state.d.ts.map +1 -0
  1017. package/dist/types/state.js +36 -0
  1018. package/dist/types/state.js.map +1 -0
  1019. package/dist/types/strategy.d.ts +541 -0
  1020. package/dist/types/strategy.d.ts.map +1 -0
  1021. package/dist/types/strategy.js +55 -0
  1022. package/dist/types/strategy.js.map +1 -0
  1023. package/dist/types/suggest.d.ts +92 -0
  1024. package/dist/types/suggest.d.ts.map +1 -0
  1025. package/dist/types/suggest.js +15 -0
  1026. package/dist/types/suggest.js.map +1 -0
  1027. package/dist/types/task-group.d.ts +231 -0
  1028. package/dist/types/task-group.d.ts.map +1 -0
  1029. package/dist/types/task-group.js +14 -0
  1030. package/dist/types/task-group.js.map +1 -0
  1031. package/dist/types/task.d.ts +258 -0
  1032. package/dist/types/task.d.ts.map +1 -0
  1033. package/dist/types/task.js +66 -0
  1034. package/dist/types/task.js.map +1 -0
  1035. package/dist/types/trust.d.ts +126 -0
  1036. package/dist/types/trust.d.ts.map +1 -0
  1037. package/dist/types/trust.js +38 -0
  1038. package/dist/types/trust.js.map +1 -0
  1039. package/dist/utils/errors.d.ts +17 -0
  1040. package/dist/utils/errors.d.ts.map +1 -0
  1041. package/dist/utils/errors.js +34 -0
  1042. package/dist/utils/errors.js.map +1 -0
  1043. package/dist/utils/json-io.d.ts +28 -0
  1044. package/dist/utils/json-io.d.ts.map +1 -0
  1045. package/dist/utils/json-io.js +71 -0
  1046. package/dist/utils/json-io.js.map +1 -0
  1047. package/dist/utils/paths.d.ts +14 -0
  1048. package/dist/utils/paths.d.ts.map +1 -0
  1049. package/dist/utils/paths.js +38 -0
  1050. package/dist/utils/paths.js.map +1 -0
  1051. package/dist/utils/sleep.d.ts +2 -0
  1052. package/dist/utils/sleep.d.ts.map +1 -0
  1053. package/dist/utils/sleep.js +4 -0
  1054. package/dist/utils/sleep.js.map +1 -0
  1055. package/dist/vector-index.d.ts +39 -0
  1056. package/dist/vector-index.d.ts.map +1 -0
  1057. package/dist/vector-index.js +111 -0
  1058. package/dist/vector-index.js.map +1 -0
  1059. package/package.json +78 -0
@@ -0,0 +1,954 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { z } from "zod";
3
+ import { GoalSchema } from "./types/goal.js";
4
+ import { ConcretenessScoreSchema, DecompositionQualityMetricsSchema } from "./types/goal-tree.js";
5
+ // ─── LLM Response Schemas ───
6
+ const SpecificityResponseSchema = z.object({
7
+ specificity_score: z.number().min(0).max(1),
8
+ reasoning: z.string(),
9
+ });
10
+ const SubgoalItemSchema = z.object({
11
+ hypothesis: z.string(),
12
+ dimensions: z
13
+ .array(z.object({
14
+ name: z.string(),
15
+ label: z.string(),
16
+ threshold_type: z.enum(["min", "max", "range", "present", "match"]),
17
+ threshold_value: z.union([z.number(), z.string(), z.boolean(), z.null()]).nullable(),
18
+ observation_method_hint: z.string().optional().default(""),
19
+ }))
20
+ .default([]),
21
+ constraints: z.array(z.string()).default([]),
22
+ expected_specificity: z.number().min(0).max(1).optional(),
23
+ });
24
+ const SubgoalsResponseSchema = z.array(SubgoalItemSchema);
25
+ const CoverageResponseSchema = z.object({
26
+ covers_parent: z.boolean(),
27
+ missing_dimensions: z.array(z.string()).default([]),
28
+ reasoning: z.string(),
29
+ });
30
+ const RestructureSuggestionSchema = z.object({
31
+ action: z.enum(["move", "merge", "split", "reorder"]),
32
+ goal_ids: z.array(z.string()),
33
+ reasoning: z.string(),
34
+ });
35
+ const RestructureResponseSchema = z.array(RestructureSuggestionSchema);
36
+ const ConcretenessLLMResponseSchema = z.object({
37
+ hasQuantitativeThreshold: z.boolean(),
38
+ hasObservableOutcome: z.boolean(),
39
+ hasTimebound: z.boolean(),
40
+ hasClearScope: z.boolean(),
41
+ reason: z.string(),
42
+ });
43
+ const QualityEvaluationResponseSchema = z.object({
44
+ coverage: z.number().min(0).max(1),
45
+ overlap: z.number().min(0).max(1),
46
+ actionability: z.number().min(0).max(1),
47
+ reasoning: z.string(),
48
+ });
49
+ // ─── Prompt Builders ───
50
+ function buildSpecificityPrompt(goal) {
51
+ const dimNames = goal.dimensions.map((d) => d.name).join(", ");
52
+ const constraintLines = goal.constraints.length > 0
53
+ ? `\nConstraints: ${goal.constraints.join(", ")}`
54
+ : "";
55
+ return `Evaluate the specificity of this goal. A high specificity score (>= 0.7) means the goal is already a single, atomic task with no meaningful sub-components that could be worked on independently. A low score (< 0.7) means it has multiple distinct aspects that should be broken down into separate subgoals.
56
+
57
+ Goal title: ${goal.title}
58
+ Goal description: ${goal.description}
59
+ Dimensions: ${dimNames || "(none defined)"}${constraintLines}
60
+ Current decomposition depth: ${goal.decomposition_depth}
61
+
62
+ Output JSON:
63
+ {
64
+ "specificity_score": <number 0.0 to 1.0>,
65
+ "reasoning": "<brief explanation>"
66
+ }
67
+
68
+ Return ONLY the JSON object, no other text.`;
69
+ }
70
+ function buildSubgoalPrompt(goal, depth, maxDepth, maxChildren) {
71
+ const constraintLines = goal.constraints.length > 0
72
+ ? `Constraints:\n${goal.constraints.map((c) => `- ${c}`).join("\n")}`
73
+ : "Constraints: none";
74
+ const dimLines = goal.dimensions.length > 0
75
+ ? `Existing dimensions:\n${goal.dimensions.map((d) => `- ${d.name}: ${d.label}`).join("\n")}`
76
+ : "Existing dimensions: none";
77
+ return `Decompose this goal into ${maxChildren} or fewer concrete subgoals. Each subgoal should address a distinct aspect of the parent goal and be more specific.
78
+
79
+ Parent goal: ${goal.title}
80
+ Description: ${goal.description}
81
+ ${dimLines}
82
+ ${constraintLines}
83
+ Current depth: ${depth} (max allowed depth: ${maxDepth})
84
+ Remaining decomposition levels: ${maxDepth - depth}
85
+
86
+ For each subgoal, provide:
87
+ - hypothesis: what this subgoal achieves (1-2 sentences)
88
+ - dimensions: array of measurable dimensions with fields:
89
+ - name: string (snake_case identifier)
90
+ - label: string (human-readable)
91
+ - threshold_type: MUST be one of "min" | "max" | "range" | "present" | "match" (no other values allowed)
92
+ - threshold_value: number or string or boolean or null
93
+ - observation_method_hint: string (optional)
94
+ - constraints: array of constraints specific to this subgoal
95
+ - expected_specificity: estimated specificity score after decomposition (0.0-1.0)
96
+
97
+ Output JSON array of subgoal objects. Maximum ${maxChildren} items.
98
+ Return ONLY a JSON array, no other text.`;
99
+ }
100
+ function buildCoveragePrompt(parent, children) {
101
+ const parentDims = parent.dimensions.map((d) => d.name).join(", ");
102
+ const childSummaries = children
103
+ .map((c, i) => ` ${i + 1}. "${c.title}": dimensions=[${c.dimensions.map((d) => d.name).join(", ")}]`)
104
+ .join("\n");
105
+ return `Do these subgoals collectively cover all dimensions of the parent goal?
106
+
107
+ Parent goal: ${parent.title}
108
+ Parent dimensions: ${parentDims || "(none)"}
109
+
110
+ Subgoals:
111
+ ${childSummaries}
112
+
113
+ Output JSON:
114
+ {
115
+ "covers_parent": <true|false>,
116
+ "missing_dimensions": ["<dim1>", ...],
117
+ "reasoning": "<brief explanation>"
118
+ }
119
+
120
+ Return ONLY the JSON object, no other text.`;
121
+ }
122
+ function buildConcretenessPrompt(description) {
123
+ return `Evaluate the concreteness of this goal description on four dimensions.
124
+
125
+ Goal description: "${description}"
126
+
127
+ Answer each question:
128
+ 1. hasQuantitativeThreshold: Does the goal specify quantitative/measurable success criteria or thresholds? (e.g., "achieve 80% coverage", "response time < 200ms")
129
+ 2. hasObservableOutcome: Does the goal describe an observable, verifiable outcome? (e.g., "a working API endpoint", "passing CI build")
130
+ 3. hasTimebound: Does the goal have a time constraint or deadline? (e.g., "by end of sprint", "within 2 weeks")
131
+ 4. hasClearScope: Does the goal have a clearly defined scope with no ambiguity about what is included or excluded?
132
+
133
+ Output JSON:
134
+ {
135
+ "hasQuantitativeThreshold": <true|false>,
136
+ "hasObservableOutcome": <true|false>,
137
+ "hasTimebound": <true|false>,
138
+ "hasClearScope": <true|false>,
139
+ "reason": "<brief explanation covering all four dimensions>"
140
+ }
141
+
142
+ Return ONLY the JSON object, no other text.`;
143
+ }
144
+ function buildQualityEvaluationPrompt(parentDescription, subgoalDescriptions) {
145
+ const subgoalList = subgoalDescriptions
146
+ .map((desc, i) => ` ${i + 1}. "${desc}"`)
147
+ .join("\n");
148
+ return `Evaluate the quality of this goal decomposition.
149
+
150
+ Parent goal: "${parentDescription}"
151
+
152
+ Subgoals:
153
+ ${subgoalList}
154
+
155
+ Evaluate:
156
+ 1. coverage (0.0-1.0): How well do the subgoals collectively cover all aspects of the parent goal? 1.0 = complete coverage, 0.0 = no coverage.
157
+ 2. overlap (0.0-1.0): How much redundancy/overlap exists between subgoals? 0.0 = no overlap (ideal), 1.0 = all subgoals are identical.
158
+ 3. actionability (0.0-1.0): Average concreteness/actionability of the subgoals. 1.0 = all are immediately actionable, 0.0 = all are too abstract.
159
+
160
+ Output JSON:
161
+ {
162
+ "coverage": <number 0.0 to 1.0>,
163
+ "overlap": <number 0.0 to 1.0>,
164
+ "actionability": <number 0.0 to 1.0>,
165
+ "reasoning": "<brief explanation>"
166
+ }
167
+
168
+ Return ONLY the JSON object, no other text.`;
169
+ }
170
+ function buildRestructurePrompt(rootId, treeState, goals) {
171
+ const goalSummaries = goals
172
+ .map((g) => ` - id="${g.id}" title="${g.title}" depth=${g.decomposition_depth} status=${g.status}`)
173
+ .join("\n");
174
+ return `Suggest restructuring actions for this goal tree to improve efficiency.
175
+
176
+ Root goal ID: ${rootId}
177
+ Total nodes: ${treeState.total_nodes}
178
+ Max depth reached: ${treeState.max_depth_reached}
179
+ Active loops: ${treeState.active_loops.length}
180
+ Pruned nodes: ${treeState.pruned_nodes.length}
181
+
182
+ Goals in tree:
183
+ ${goalSummaries}
184
+
185
+ Suggest restructuring actions. Each action should specify:
186
+ - action: "move" | "merge" | "split" | "reorder"
187
+ - goal_ids: array of goal IDs involved
188
+ - reasoning: why this restructuring would help
189
+
190
+ Output JSON array. Return empty array [] if no restructuring needed.
191
+ Return ONLY a JSON array, no other text.`;
192
+ }
193
+ // ─── Helper: Build a Goal from subgoal spec ───
194
+ function buildGoalFromSubgoalSpec(spec, parentId, parentDepth, now) {
195
+ const id = randomUUID();
196
+ const dims = spec.dimensions.map((d) => ({
197
+ name: d.name,
198
+ label: d.label,
199
+ current_value: null,
200
+ threshold: {
201
+ type: d.threshold_type,
202
+ value: d.threshold_value ?? null,
203
+ },
204
+ confidence: 0.5,
205
+ observation_method: {
206
+ type: "manual",
207
+ source: "decomposition",
208
+ schedule: null,
209
+ endpoint: null,
210
+ confidence_tier: "self_report",
211
+ },
212
+ last_updated: now,
213
+ history: [],
214
+ weight: 1.0,
215
+ uncertainty_weight: null,
216
+ state_integrity: "ok",
217
+ dimension_mapping: null,
218
+ }));
219
+ return GoalSchema.parse({
220
+ id,
221
+ parent_id: parentId,
222
+ node_type: "subgoal",
223
+ title: spec.hypothesis.slice(0, 200),
224
+ description: spec.hypothesis,
225
+ status: "active",
226
+ dimensions: dims,
227
+ gap_aggregation: "max",
228
+ dimension_mapping: null,
229
+ constraints: spec.constraints,
230
+ children_ids: [],
231
+ target_date: null,
232
+ origin: "decomposition",
233
+ pace_snapshot: null,
234
+ deadline: null,
235
+ confidence_flag: null,
236
+ user_override: false,
237
+ feasibility_note: null,
238
+ uncertainty_weight: 1.0,
239
+ decomposition_depth: parentDepth + 1,
240
+ specificity_score: spec.expected_specificity ?? null,
241
+ loop_status: "idle",
242
+ created_at: now,
243
+ updated_at: now,
244
+ });
245
+ }
246
+ export class GoalTreeManager {
247
+ stateManager;
248
+ llmClient;
249
+ ethicsGate;
250
+ goalDependencyGraph;
251
+ goalNegotiator;
252
+ concretenesThreshold;
253
+ maxDepth;
254
+ pruneHistory = new Map();
255
+ constructor(stateManager, llmClient, ethicsGate, goalDependencyGraph, goalNegotiator, options) {
256
+ this.stateManager = stateManager;
257
+ this.llmClient = llmClient;
258
+ this.ethicsGate = ethicsGate;
259
+ this.goalDependencyGraph = goalDependencyGraph;
260
+ this.goalNegotiator = goalNegotiator;
261
+ // null means concreteness auto-stop is disabled (backward compatible)
262
+ this.concretenesThreshold = options?.concretenesThreshold ?? null;
263
+ this.maxDepth = options?.maxDepth ?? 5;
264
+ }
265
+ // ─── Concreteness Scoring ───
266
+ /**
267
+ * Scores the concreteness of a goal description on four dimensions using an LLM.
268
+ * Score = weighted average of 4 boolean dimensions (each 0.25).
269
+ * Falls back to zero score on LLM/parse failures.
270
+ */
271
+ async scoreConcreteness(description) {
272
+ if (!description || description.trim() === "") {
273
+ return ConcretenessScoreSchema.parse({
274
+ score: 0,
275
+ dimensions: {
276
+ hasQuantitativeThreshold: false,
277
+ hasObservableOutcome: false,
278
+ hasTimebound: false,
279
+ hasClearScope: false,
280
+ },
281
+ reason: "Empty description provided",
282
+ });
283
+ }
284
+ const prompt = buildConcretenessPrompt(description);
285
+ try {
286
+ const response = await this.llmClient.sendMessage([{ role: "user", content: prompt }], { temperature: 0 });
287
+ const parsed = this.llmClient.parseJSON(response.content, ConcretenessLLMResponseSchema);
288
+ const dims = {
289
+ hasQuantitativeThreshold: parsed.hasQuantitativeThreshold,
290
+ hasObservableOutcome: parsed.hasObservableOutcome,
291
+ hasTimebound: parsed.hasTimebound,
292
+ hasClearScope: parsed.hasClearScope,
293
+ };
294
+ const trueCount = Object.values(dims).filter(Boolean).length;
295
+ const score = trueCount * 0.25;
296
+ return ConcretenessScoreSchema.parse({
297
+ score,
298
+ dimensions: dims,
299
+ reason: parsed.reason,
300
+ });
301
+ }
302
+ catch {
303
+ return ConcretenessScoreSchema.parse({
304
+ score: 0,
305
+ dimensions: {
306
+ hasQuantitativeThreshold: false,
307
+ hasObservableOutcome: false,
308
+ hasTimebound: false,
309
+ hasClearScope: false,
310
+ },
311
+ reason: "LLM evaluation failed, defaulting to zero score",
312
+ });
313
+ }
314
+ }
315
+ // ─── Decomposition Quality ───
316
+ /**
317
+ * Evaluates the quality of a decomposition using an LLM.
318
+ * Measures coverage, overlap, actionability, and computes depthEfficiency.
319
+ * Logs a warning when quality is poor (coverage < 0.5 or overlap > 0.7).
320
+ */
321
+ async evaluateDecompositionQuality(parentDescription, subgoalDescriptions) {
322
+ if (subgoalDescriptions.length === 0) {
323
+ const metrics = DecompositionQualityMetricsSchema.parse({
324
+ coverage: 0,
325
+ overlap: 0,
326
+ actionability: 0,
327
+ depthEfficiency: 1,
328
+ });
329
+ console.warn("GoalTreeManager.evaluateDecompositionQuality: no subgoals provided — coverage=0");
330
+ return metrics;
331
+ }
332
+ const prompt = buildQualityEvaluationPrompt(parentDescription, subgoalDescriptions);
333
+ let coverage = 0;
334
+ let overlap = 0;
335
+ let actionability = 0;
336
+ try {
337
+ const response = await this.llmClient.sendMessage([{ role: "user", content: prompt }], { temperature: 0 });
338
+ const parsed = this.llmClient.parseJSON(response.content, QualityEvaluationResponseSchema);
339
+ coverage = parsed.coverage;
340
+ overlap = parsed.overlap;
341
+ actionability = parsed.actionability;
342
+ }
343
+ catch {
344
+ // On failure return conservative metrics
345
+ coverage = 0;
346
+ overlap = 0;
347
+ actionability = 0;
348
+ }
349
+ const depthEfficiency = Math.max(0, Math.min(1, 1 - overlap * 0.5));
350
+ const metrics = DecompositionQualityMetricsSchema.parse({
351
+ coverage,
352
+ overlap,
353
+ actionability,
354
+ depthEfficiency,
355
+ });
356
+ if (coverage < 0.5 || overlap > 0.7) {
357
+ console.warn(`GoalTreeManager.evaluateDecompositionQuality: poor quality detected — coverage=${coverage.toFixed(2)}, overlap=${overlap.toFixed(2)}`);
358
+ }
359
+ return metrics;
360
+ }
361
+ // ─── Specificity Evaluation ───
362
+ /**
363
+ * Evaluates the specificity of a goal using an LLM.
364
+ * Returns a score between 0 (very abstract) and 1 (very concrete).
365
+ * Falls back to 0.5 on parse failures.
366
+ */
367
+ async evaluateSpecificity(goal) {
368
+ const prompt = buildSpecificityPrompt(goal);
369
+ try {
370
+ const response = await this.llmClient.sendMessage([{ role: "user", content: prompt }], { temperature: 0 });
371
+ const parsed = this.llmClient.parseJSON(response.content, SpecificityResponseSchema);
372
+ return { score: parsed.specificity_score, reasoning: parsed.reasoning };
373
+ }
374
+ catch {
375
+ // Conservative fallback: treat as needing decomposition
376
+ return { score: 0.5, reasoning: "LLM evaluation failed, defaulting to 0.5" };
377
+ }
378
+ }
379
+ // ─── Core Decomposition ───
380
+ /**
381
+ * Recursively decomposes a goal into subgoals until each subgoal either:
382
+ * (a) has specificity_score >= config.min_specificity → leaf node
383
+ * (b) has decomposition_depth >= config.max_depth → forced leaf
384
+ * (c) concreteness score >= concretenesThreshold (auto-stop)
385
+ * (d) current depth >= maxDepth (depth guard)
386
+ *
387
+ * Options override instance-level defaults when provided.
388
+ * Returns a DecompositionResult for the top-level call.
389
+ */
390
+ async decomposeGoal(goalId, config, options) {
391
+ const goal = this.stateManager.loadGoal(goalId);
392
+ if (!goal) {
393
+ throw new Error(`GoalTreeManager.decomposeGoal: goal "${goalId}" not found`);
394
+ }
395
+ const effectiveConcretenesThreshold = options?.concretenesThreshold ?? this.concretenesThreshold;
396
+ const effectiveMaxDepth = options?.maxDepth ?? this.maxDepth;
397
+ // Auto-stop: check concreteness before decomposing (only when threshold is explicitly set)
398
+ if (effectiveConcretenesThreshold !== null) {
399
+ const concretenessResult = await this.scoreConcreteness(goal.description);
400
+ if (concretenessResult.score >= effectiveConcretenesThreshold) {
401
+ const now = new Date().toISOString();
402
+ const leafGoal = {
403
+ ...goal,
404
+ node_type: "leaf",
405
+ specificity_score: concretenessResult.score,
406
+ updated_at: now,
407
+ };
408
+ this.stateManager.saveGoal(leafGoal);
409
+ return {
410
+ parent_id: goal.id,
411
+ children: [],
412
+ depth: goal.decomposition_depth,
413
+ specificity_scores: { [goal.id]: concretenessResult.score },
414
+ reasoning: `Auto-stop: concreteness score ${concretenessResult.score.toFixed(2)} >= threshold ${effectiveConcretenesThreshold}. ${concretenessResult.reason}`,
415
+ };
416
+ }
417
+ }
418
+ return this._decomposeGoalInternal(goal, config, 0, effectiveMaxDepth);
419
+ }
420
+ async _decomposeGoalInternal(goal, config, retryCount, depthLimit) {
421
+ const now = new Date().toISOString();
422
+ const effectiveMaxDepth = depthLimit ?? config.max_depth;
423
+ // Step 1: Evaluate specificity
424
+ const { score: specificityScore, reasoning } = await this.evaluateSpecificity(goal);
425
+ // Update goal with specificity score
426
+ const updatedGoal = {
427
+ ...goal,
428
+ specificity_score: specificityScore,
429
+ updated_at: now,
430
+ };
431
+ // Step 2: Determine if this is a leaf node
432
+ const isLeaf = (goal.decomposition_depth > 0 && specificityScore >= config.min_specificity) ||
433
+ goal.decomposition_depth >= effectiveMaxDepth;
434
+ if (isLeaf) {
435
+ // Mark as leaf node
436
+ const leafGoal = {
437
+ ...updatedGoal,
438
+ node_type: "leaf",
439
+ updated_at: now,
440
+ };
441
+ this.stateManager.saveGoal(leafGoal);
442
+ return {
443
+ parent_id: goal.id,
444
+ children: [],
445
+ depth: goal.decomposition_depth,
446
+ specificity_scores: { [goal.id]: specificityScore },
447
+ reasoning: specificityScore >= config.min_specificity
448
+ ? `Goal is specific enough (score=${specificityScore.toFixed(2)}): ${reasoning}`
449
+ : `Max depth ${effectiveMaxDepth} reached, forced leaf`,
450
+ };
451
+ }
452
+ // Step 3: Generate subgoals via LLM
453
+ const maxChildren = 5;
454
+ const subgoalPrompt = buildSubgoalPrompt(updatedGoal, goal.decomposition_depth, effectiveMaxDepth, maxChildren);
455
+ let subgoalSpecs = [];
456
+ try {
457
+ const subgoalResponse = await this.llmClient.sendMessage([{ role: "user", content: subgoalPrompt }], { temperature: 0 });
458
+ // Sanitize threshold_type values before schema validation —
459
+ // LLMs sometimes return "exact", "scale", "qualitative" etc.
460
+ const THRESHOLD_TYPE_MAP = {
461
+ exact: "match",
462
+ scale: "min",
463
+ qualitative: "min",
464
+ boolean: "present",
465
+ percentage: "min",
466
+ count: "min",
467
+ };
468
+ const VALID_TYPES = new Set(["min", "max", "range", "present", "match"]);
469
+ const rawContent = subgoalResponse.content;
470
+ const sanitized = rawContent.replace(/"threshold_type"\s*:\s*"([^"]+)"/g, (_match, val) => {
471
+ if (VALID_TYPES.has(val))
472
+ return `"threshold_type": "${val}"`;
473
+ const mapped = THRESHOLD_TYPE_MAP[val] ?? "min";
474
+ return `"threshold_type": "${mapped}"`;
475
+ });
476
+ const parsed = this.llmClient.parseJSON(sanitized, SubgoalsResponseSchema);
477
+ subgoalSpecs = parsed.map((sg) => ({
478
+ ...sg,
479
+ dimensions: (sg.dimensions ?? []).map((d) => ({
480
+ ...d,
481
+ observation_method_hint: d.observation_method_hint ?? "",
482
+ })),
483
+ constraints: sg.constraints ?? [],
484
+ }));
485
+ // Clamp to max_children_per_node
486
+ subgoalSpecs = subgoalSpecs.slice(0, maxChildren);
487
+ }
488
+ catch (err) {
489
+ // If subgoal generation fails, treat as leaf — but log the error for diagnostics
490
+ console.error(`[GoalTreeManager] Subgoal generation failed for "${goal.id}":`, err instanceof Error ? err.message : String(err));
491
+ const leafGoal = {
492
+ ...updatedGoal,
493
+ node_type: "leaf",
494
+ updated_at: now,
495
+ };
496
+ this.stateManager.saveGoal(leafGoal);
497
+ return {
498
+ parent_id: goal.id,
499
+ children: [],
500
+ depth: goal.decomposition_depth,
501
+ specificity_scores: { [goal.id]: specificityScore },
502
+ reasoning: `Subgoal generation failed: ${err instanceof Error ? err.message : String(err)}`,
503
+ };
504
+ }
505
+ // Handle empty decomposition
506
+ if (subgoalSpecs.length === 0) {
507
+ const leafGoal = {
508
+ ...updatedGoal,
509
+ node_type: "leaf",
510
+ updated_at: now,
511
+ };
512
+ this.stateManager.saveGoal(leafGoal);
513
+ return {
514
+ parent_id: goal.id,
515
+ children: [],
516
+ depth: goal.decomposition_depth,
517
+ specificity_scores: { [goal.id]: specificityScore },
518
+ reasoning: "LLM returned empty subgoal list, treating as leaf",
519
+ };
520
+ }
521
+ // Step 4: Build child Goal objects
522
+ const childGoals = subgoalSpecs.map((spec) => buildGoalFromSubgoalSpec(spec, goal.id, goal.decomposition_depth, now));
523
+ // Step 5: Build the provisional decomposition result for validation
524
+ const provisionalResult = {
525
+ parent_id: goal.id,
526
+ children: childGoals,
527
+ depth: goal.decomposition_depth,
528
+ specificity_scores: { [goal.id]: specificityScore },
529
+ reasoning,
530
+ };
531
+ // Step 6: Validate decomposition (retry up to 2 times)
532
+ const isValid = await this.validateDecomposition(provisionalResult);
533
+ if (!isValid && retryCount < 2) {
534
+ // Retry decomposition
535
+ return this._decomposeGoalInternal(goal, config, retryCount + 1, depthLimit);
536
+ }
537
+ // Step 7: Save parent goal (updated specificity_score, node_type stays as-is for non-leaf)
538
+ this.stateManager.saveGoal(updatedGoal);
539
+ // Step 8: Save each child goal and update parent's children_ids
540
+ const childIds = [];
541
+ for (const child of childGoals) {
542
+ this.stateManager.saveGoal(child);
543
+ childIds.push(child.id);
544
+ // Register parent->child dependency in GoalDependencyGraph
545
+ try {
546
+ this.goalDependencyGraph.addEdge({
547
+ from_goal_id: goal.id,
548
+ to_goal_id: child.id,
549
+ type: "parent_child", // type extended in 14A
550
+ status: "active",
551
+ condition: null,
552
+ affected_dimensions: child.dimensions.map((d) => d.name),
553
+ mitigation: null,
554
+ detection_confidence: 1.0,
555
+ reasoning: `Parent-child relationship from goal decomposition`,
556
+ });
557
+ }
558
+ catch {
559
+ // Dependency graph may not support parent_child type — skip silently
560
+ }
561
+ }
562
+ // Update parent goal's children_ids
563
+ const parentWithChildren = {
564
+ ...updatedGoal,
565
+ children_ids: [...updatedGoal.children_ids, ...childIds],
566
+ updated_at: now,
567
+ };
568
+ this.stateManager.saveGoal(parentWithChildren);
569
+ // Step 9: Collect specificity scores for result
570
+ const specificityScores = {
571
+ [goal.id]: specificityScore,
572
+ };
573
+ // Step 10: Recursively decompose each child
574
+ for (const child of childGoals) {
575
+ const childResult = await this._decomposeGoalInternal(child, config, 0, depthLimit);
576
+ // Merge child specificity scores
577
+ Object.assign(specificityScores, childResult.specificity_scores);
578
+ // Merge children into child's record
579
+ if (childResult.children.length > 0) {
580
+ const reloadedChild = this.stateManager.loadGoal(child.id);
581
+ if (reloadedChild) {
582
+ // child was saved with updated children_ids from recursive call
583
+ void reloadedChild; // already persisted by recursive call
584
+ }
585
+ }
586
+ }
587
+ return {
588
+ parent_id: goal.id,
589
+ children: childGoals,
590
+ depth: goal.decomposition_depth,
591
+ specificity_scores: specificityScores,
592
+ reasoning,
593
+ };
594
+ }
595
+ // ─── Validation ───
596
+ /**
597
+ * Validates a decomposition result by checking:
598
+ * 1. Coverage: subgoals cover all parent dimensions (LLM)
599
+ * 2. Cycle detection: no circular dependencies introduced
600
+ *
601
+ * Returns true only if both checks pass.
602
+ */
603
+ async validateDecomposition(result) {
604
+ const parent = this.stateManager.loadGoal(result.parent_id);
605
+ if (!parent)
606
+ return false;
607
+ const children = result.children;
608
+ // Check 1: Coverage validation via LLM
609
+ if (children.length > 0) {
610
+ const coveragePrompt = buildCoveragePrompt(parent, children);
611
+ try {
612
+ const coverageResponse = await this.llmClient.sendMessage([{ role: "user", content: coveragePrompt }], { temperature: 0 });
613
+ const coverage = this.llmClient.parseJSON(coverageResponse.content, CoverageResponseSchema);
614
+ if (!coverage.covers_parent) {
615
+ return false;
616
+ }
617
+ }
618
+ catch {
619
+ // On parse failure, allow decomposition to proceed
620
+ }
621
+ }
622
+ // Check 2: Cycle detection
623
+ for (const child of children) {
624
+ const wouldCycle = this.goalDependencyGraph.detectCycle(result.parent_id, child.id);
625
+ if (wouldCycle) {
626
+ return false;
627
+ }
628
+ }
629
+ return true;
630
+ }
631
+ // ─── Pruning ───
632
+ /**
633
+ * Prunes a goal and all its descendants by setting status = "cancelled".
634
+ * Removes the goal from its parent's children_ids.
635
+ * Returns a PruneDecision.
636
+ */
637
+ pruneGoal(goalId, reason) {
638
+ const goal = this.stateManager.loadGoal(goalId);
639
+ if (!goal) {
640
+ throw new Error(`GoalTreeManager.pruneGoal: goal "${goalId}" not found`);
641
+ }
642
+ const now = new Date().toISOString();
643
+ // Cancel the goal and all descendants
644
+ this._cancelGoalAndDescendants(goal, now);
645
+ // Remove from parent's children_ids
646
+ if (goal.parent_id) {
647
+ const parent = this.stateManager.loadGoal(goal.parent_id);
648
+ if (parent) {
649
+ const updatedParent = {
650
+ ...parent,
651
+ children_ids: parent.children_ids.filter((id) => id !== goalId),
652
+ updated_at: now,
653
+ };
654
+ this.stateManager.saveGoal(updatedParent);
655
+ }
656
+ }
657
+ return {
658
+ goal_id: goalId,
659
+ reason,
660
+ replacement_id: null,
661
+ };
662
+ }
663
+ /**
664
+ * Prunes a subgoal with a free-form reason string for tracking.
665
+ * Records a PruneRecord in the history for the parent goal tree.
666
+ * The parentGoalId is the root goal whose history you want to track.
667
+ */
668
+ pruneSubgoal(subgoalId, reason, parentGoalId) {
669
+ const goal = this.stateManager.loadGoal(subgoalId);
670
+ if (!goal) {
671
+ throw new Error(`GoalTreeManager.pruneSubgoal: goal "${subgoalId}" not found`);
672
+ }
673
+ const now = new Date().toISOString();
674
+ // Cancel the goal and all descendants
675
+ this._cancelGoalAndDescendants(goal, now);
676
+ // Remove from parent's children_ids
677
+ if (goal.parent_id) {
678
+ const parent = this.stateManager.loadGoal(goal.parent_id);
679
+ if (parent) {
680
+ const updatedParent = {
681
+ ...parent,
682
+ children_ids: parent.children_ids.filter((id) => id !== subgoalId),
683
+ updated_at: now,
684
+ };
685
+ this.stateManager.saveGoal(updatedParent);
686
+ }
687
+ }
688
+ // Record prune history keyed by parentGoalId or the goal's own parent_id
689
+ const trackingKey = parentGoalId ?? goal.parent_id ?? subgoalId;
690
+ const record = { subgoalId, reason, timestamp: now };
691
+ const existing = this.pruneHistory.get(trackingKey) ?? [];
692
+ this.pruneHistory.set(trackingKey, [...existing, record]);
693
+ return {
694
+ goal_id: subgoalId,
695
+ reason: "user_requested",
696
+ replacement_id: null,
697
+ };
698
+ }
699
+ /**
700
+ * Returns the prune history for a given goal tree root ID.
701
+ * Returns an empty array if no prunes have been recorded.
702
+ */
703
+ getPruneHistory(goalId) {
704
+ return this.pruneHistory.get(goalId) ?? [];
705
+ }
706
+ _cancelGoalAndDescendants(goal, now) {
707
+ // Recursively cancel all children first
708
+ for (const childId of goal.children_ids) {
709
+ const child = this.stateManager.loadGoal(childId);
710
+ if (child) {
711
+ this._cancelGoalAndDescendants(child, now);
712
+ }
713
+ }
714
+ // Cancel this goal
715
+ const cancelled = {
716
+ ...goal,
717
+ status: "cancelled",
718
+ updated_at: now,
719
+ };
720
+ this.stateManager.saveGoal(cancelled);
721
+ }
722
+ // ─── Dynamic Subgoal Addition ───
723
+ /**
724
+ * Adds a new subgoal to a parent goal.
725
+ * - Validates the parent exists
726
+ * - Saves the new goal with parent_id set
727
+ * - Adds child ID to parent's children_ids
728
+ * - Registers the dependency in GoalDependencyGraph
729
+ * Returns the saved goal.
730
+ */
731
+ addSubgoal(parentId, goal) {
732
+ const parent = this.stateManager.loadGoal(parentId);
733
+ if (!parent) {
734
+ throw new Error(`GoalTreeManager.addSubgoal: parent goal "${parentId}" not found`);
735
+ }
736
+ const now = new Date().toISOString();
737
+ // Ensure parent_id is set on the new goal
738
+ const goalWithParent = GoalSchema.parse({
739
+ ...goal,
740
+ parent_id: parentId,
741
+ updated_at: now,
742
+ });
743
+ // Save the new goal
744
+ this.stateManager.saveGoal(goalWithParent);
745
+ // Update parent's children_ids
746
+ const updatedParent = {
747
+ ...parent,
748
+ children_ids: [...parent.children_ids, goalWithParent.id],
749
+ updated_at: now,
750
+ };
751
+ this.stateManager.saveGoal(updatedParent);
752
+ // Register dependency
753
+ try {
754
+ this.goalDependencyGraph.addEdge({
755
+ from_goal_id: parentId,
756
+ to_goal_id: goalWithParent.id,
757
+ type: "parent_child",
758
+ status: "active",
759
+ condition: null,
760
+ affected_dimensions: goalWithParent.dimensions.map((d) => d.name),
761
+ mitigation: null,
762
+ detection_confidence: 1.0,
763
+ reasoning: `Parent-child relationship (dynamic subgoal addition)`,
764
+ });
765
+ }
766
+ catch {
767
+ // Dependency graph may not support parent_child type — skip silently
768
+ }
769
+ return goalWithParent;
770
+ }
771
+ // ─── Tree Restructure ───
772
+ /**
773
+ * Asks an LLM for restructuring suggestions on the current tree rooted at goalId,
774
+ * then applies them. Currently supports identifying merge/move candidates.
775
+ *
776
+ * After restructuring, evaluates quality of the new structure. If quality
777
+ * metrics do not show improvement (overall score degraded), reverts changes
778
+ * by restoring the snapshot taken before restructuring.
779
+ *
780
+ * Returns the quality metrics of the final (kept) structure.
781
+ */
782
+ async restructureTree(goalId) {
783
+ const allGoalIdsBefore = this._collectAllDescendantIds(goalId);
784
+ allGoalIdsBefore.unshift(goalId);
785
+ const qualityEnabled = this.concretenesThreshold !== null;
786
+ // Snapshot state before restructuring (needed for quality-based revert)
787
+ const snapshot = new Map();
788
+ if (qualityEnabled) {
789
+ for (const id of allGoalIdsBefore) {
790
+ const g = this.stateManager.loadGoal(id);
791
+ if (g)
792
+ snapshot.set(id, g);
793
+ }
794
+ }
795
+ // Evaluate quality before restructuring (only when concreteness feature is enabled)
796
+ const rootGoalBefore = this.stateManager.loadGoal(goalId);
797
+ let qualityBefore = null;
798
+ if (qualityEnabled) {
799
+ const beforeSubgoalDescs = allGoalIdsBefore
800
+ .slice(1)
801
+ .map((id) => snapshot.get(id)?.description ?? "")
802
+ .filter(Boolean);
803
+ qualityBefore =
804
+ beforeSubgoalDescs.length > 0 && rootGoalBefore
805
+ ? await this.evaluateDecompositionQuality(rootGoalBefore.description, beforeSubgoalDescs)
806
+ : null;
807
+ }
808
+ const treeState = this.getTreeState(goalId);
809
+ const goals = [];
810
+ for (const id of allGoalIdsBefore) {
811
+ const g = this.stateManager.loadGoal(id);
812
+ if (g)
813
+ goals.push(g);
814
+ }
815
+ const prompt = buildRestructurePrompt(goalId, treeState, goals);
816
+ let restructuringApplied = false;
817
+ try {
818
+ const response = await this.llmClient.sendMessage([{ role: "user", content: prompt }], { temperature: 0 });
819
+ const suggestions = this.llmClient.parseJSON(response.content, RestructureResponseSchema);
820
+ const now = new Date().toISOString();
821
+ for (const suggestion of suggestions) {
822
+ if (suggestion.action === "merge" && suggestion.goal_ids.length >= 2) {
823
+ // Merge: cancel all but first goal in the list
824
+ const [keepId, ...mergeIds] = suggestion.goal_ids;
825
+ if (keepId) {
826
+ for (const mergeId of mergeIds) {
827
+ const mergeGoal = this.stateManager.loadGoal(mergeId);
828
+ if (mergeGoal && mergeGoal.status !== "cancelled") {
829
+ this._cancelGoalAndDescendants(mergeGoal, now);
830
+ restructuringApplied = true;
831
+ // Remove from parent
832
+ if (mergeGoal.parent_id) {
833
+ const parent = this.stateManager.loadGoal(mergeGoal.parent_id);
834
+ if (parent) {
835
+ const updatedParent = {
836
+ ...parent,
837
+ children_ids: parent.children_ids.filter((id) => id !== mergeId),
838
+ updated_at: now,
839
+ };
840
+ this.stateManager.saveGoal(updatedParent);
841
+ }
842
+ }
843
+ }
844
+ }
845
+ }
846
+ }
847
+ // Other actions (move, split, reorder) are logged but not fully automated in MVP
848
+ }
849
+ }
850
+ catch {
851
+ // Restructure is best-effort; silently ignore errors
852
+ }
853
+ // Quality evaluation after restructuring (only when concreteness feature is enabled)
854
+ if (!qualityEnabled || !restructuringApplied || !rootGoalBefore) {
855
+ // When quality evaluation is not enabled, return undefined
856
+ // to maintain backward compatibility with pre-M7 void return
857
+ return qualityEnabled ? qualityBefore : undefined;
858
+ }
859
+ const allGoalIdsAfter = this._collectAllDescendantIds(goalId);
860
+ allGoalIdsAfter.unshift(goalId);
861
+ const afterSubgoalDescs = allGoalIdsAfter
862
+ .slice(1)
863
+ .map((id) => {
864
+ const g = this.stateManager.loadGoal(id);
865
+ return g?.description ?? "";
866
+ })
867
+ .filter(Boolean);
868
+ const qualityAfter = afterSubgoalDescs.length > 0
869
+ ? await this.evaluateDecompositionQuality(rootGoalBefore.description, afterSubgoalDescs)
870
+ : DecompositionQualityMetricsSchema.parse({
871
+ coverage: 0,
872
+ overlap: 0,
873
+ actionability: 0,
874
+ depthEfficiency: 1,
875
+ });
876
+ // Compute an overall score: higher coverage + lower overlap + higher actionability is better
877
+ const scoreBefore = qualityBefore
878
+ ? qualityBefore.coverage * 0.4 +
879
+ (1 - qualityBefore.overlap) * 0.3 +
880
+ qualityBefore.actionability * 0.3
881
+ : 0;
882
+ const scoreAfter = qualityAfter.coverage * 0.4 +
883
+ (1 - qualityAfter.overlap) * 0.3 +
884
+ qualityAfter.actionability * 0.3;
885
+ if (scoreAfter < scoreBefore) {
886
+ // Revert: restore all goals from snapshot
887
+ for (const [, savedGoal] of snapshot) {
888
+ this.stateManager.saveGoal(savedGoal);
889
+ }
890
+ return qualityBefore;
891
+ }
892
+ return qualityAfter;
893
+ }
894
+ // ─── Tree State ───
895
+ /**
896
+ * Computes the current GoalTreeState for the tree rooted at rootId.
897
+ * Traverses all descendants recursively.
898
+ */
899
+ getTreeState(rootId) {
900
+ const root = this.stateManager.loadGoal(rootId);
901
+ if (!root) {
902
+ return {
903
+ root_id: rootId,
904
+ total_nodes: 0,
905
+ max_depth_reached: 0,
906
+ active_loops: [],
907
+ pruned_nodes: [],
908
+ };
909
+ }
910
+ let totalNodes = 0;
911
+ let maxDepthReached = 0;
912
+ const activeLoops = [];
913
+ const prunedNodes = [];
914
+ const visit = (goal) => {
915
+ totalNodes++;
916
+ if (goal.decomposition_depth > maxDepthReached) {
917
+ maxDepthReached = goal.decomposition_depth;
918
+ }
919
+ if (goal.loop_status === "running") {
920
+ activeLoops.push(goal.id);
921
+ }
922
+ if (goal.status === "cancelled") {
923
+ prunedNodes.push(goal.id);
924
+ }
925
+ for (const childId of goal.children_ids) {
926
+ const child = this.stateManager.loadGoal(childId);
927
+ if (child) {
928
+ visit(child);
929
+ }
930
+ }
931
+ };
932
+ visit(root);
933
+ return {
934
+ root_id: rootId,
935
+ total_nodes: totalNodes,
936
+ max_depth_reached: maxDepthReached,
937
+ active_loops: activeLoops,
938
+ pruned_nodes: prunedNodes,
939
+ };
940
+ }
941
+ // ─── Private Helpers ───
942
+ _collectAllDescendantIds(goalId) {
943
+ const goal = this.stateManager.loadGoal(goalId);
944
+ if (!goal)
945
+ return [];
946
+ const result = [];
947
+ for (const childId of goal.children_ids) {
948
+ result.push(childId);
949
+ result.push(...this._collectAllDescendantIds(childId));
950
+ }
951
+ return result;
952
+ }
953
+ }
954
+ //# sourceMappingURL=goal-tree-manager.js.map