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,790 @@
1
+ import { scoreDeadline } from "./drive/drive-scorer.js";
2
+ import { CrossGoalPortfolioConfigSchema, } from "./types/cross-portfolio.js";
3
+ // ─── Helpers ───
4
+ function clamp(value, min, max) {
5
+ return Math.min(Math.max(value, min), max);
6
+ }
7
+ /**
8
+ * CrossGoalPortfolio manages resource allocation and priority across multiple
9
+ * active goals. It sits above individual PortfolioManager instances and answers
10
+ * the question: "given N active goals, how should overall resources be split?"
11
+ *
12
+ * Responsibilities:
13
+ * - Calculate per-goal priority scores from 4 factors
14
+ * - Allocate resource shares proportionally
15
+ * - Rebalance on 4 trigger types
16
+ * - Recommend strategy templates using vector similarity
17
+ *
18
+ * CrossGoalPortfolio does NOT manage strategies within a single goal —
19
+ * that remains the responsibility of PortfolioManager.
20
+ */
21
+ export class CrossGoalPortfolio {
22
+ stateManager;
23
+ goalDependencyGraph;
24
+ vectorIndex;
25
+ embeddingClient;
26
+ config;
27
+ /** goalId → cached GoalPriorityFactors from the last calculation */
28
+ lastPriorities = new Map();
29
+ constructor(stateManager, goalDependencyGraph, vectorIndex, embeddingClient, config) {
30
+ this.stateManager = stateManager;
31
+ this.goalDependencyGraph = goalDependencyGraph;
32
+ this.vectorIndex = vectorIndex;
33
+ this.embeddingClient = embeddingClient;
34
+ this.config = CrossGoalPortfolioConfigSchema.parse(config ?? {});
35
+ }
36
+ // ─── Priority Calculation ───
37
+ /**
38
+ * Calculate priority factors for each goal in the provided list.
39
+ *
40
+ * The 4 factors and their weights:
41
+ * w1=0.35 deadline_urgency — how soon the goal must be finished
42
+ * w2=0.25 gap_severity — worst-case normalized gap across dimensions
43
+ * w3=0.25 dependency_weight — how many goals depend on this one
44
+ * w4=0.15 user_priority — user-specified priority (1-5 → 0-1)
45
+ *
46
+ * After the weighted sum is computed, synergy/conflict edges from
47
+ * GoalDependencyGraph adjust the final score before clamping to [0,1].
48
+ *
49
+ * @param goalIds — IDs of goals to evaluate (missing goals are skipped)
50
+ * @returns GoalPriorityFactors[] sorted by computed_priority descending
51
+ */
52
+ calculateGoalPriorities(goalIds) {
53
+ if (goalIds.length === 0)
54
+ return [];
55
+ const totalGoals = goalIds.length;
56
+ const now = new Date();
57
+ const rawList = [];
58
+ for (const goalId of goalIds) {
59
+ const goal = this.stateManager.loadGoal(goalId);
60
+ if (!goal)
61
+ continue;
62
+ // deadline_urgency — use scoreDeadline with maxGap=1 as the
63
+ // normalized_weighted_gap input, then read the urgency value.
64
+ let deadlineUrgency = 0;
65
+ if (goal.deadline) {
66
+ const deadlineMs = new Date(goal.deadline).getTime();
67
+ const timeRemainingHours = (deadlineMs - now.getTime()) / (1000 * 60 * 60);
68
+ const result = scoreDeadline(1, timeRemainingHours);
69
+ // Normalize urgency to [0,1]. scoreDeadline with gap=1 means score == urgency.
70
+ // urgency >= 1 (at minimum). We normalise by capping at the urgency-at-zero cap.
71
+ // Use urgency directly but clamp to [0,1] after dividing by a reasonable max.
72
+ // default urgency_steepness=2, deadline_horizon=168h → urgencyAtZero = exp(2) ≈ 7.39
73
+ const urgencyAtZero = Math.exp(2); // exp(urgency_steepness)
74
+ deadlineUrgency = clamp(result.urgency / urgencyAtZero, 0, 1);
75
+ }
76
+ // gap_severity — max normalized_weighted_gap across all dimensions
77
+ // We approximate by treating each dimension's gap as proportional
78
+ // to how far it is from its threshold relative to a known scale.
79
+ // For simplicity (no GapCalculator instance injected), we derive a
80
+ // rough severity from the dimension values directly.
81
+ let gapSeverity = 0;
82
+ for (const dim of goal.dimensions) {
83
+ const dimGap = this._estimateDimensionGap(dim);
84
+ if (dimGap > gapSeverity) {
85
+ gapSeverity = dimGap;
86
+ }
87
+ }
88
+ gapSeverity = clamp(gapSeverity, 0, 1);
89
+ // dependency_weight — how many goals in the provided list depend on this goal
90
+ const graph = this.goalDependencyGraph.getGraph();
91
+ const dependentCount = graph.edges.filter((e) => e.from_goal_id === goalId &&
92
+ e.type === "prerequisite" &&
93
+ e.status === "active" &&
94
+ goalIds.includes(e.to_goal_id)).length;
95
+ const dependencyWeight = totalGoals > 1 ? dependentCount / (totalGoals - 1) : 0;
96
+ // user_priority — extract from goal constraints or metadata
97
+ // Assume format "priority:N" (N in 1-5) anywhere in constraints
98
+ let userPriority = 0.5; // default
99
+ for (const constraint of goal.constraints) {
100
+ const match = constraint.match(/\bpriority[:\s=]+(\d+)\b/i);
101
+ if (match) {
102
+ const level = parseInt(match[1], 10);
103
+ userPriority = clamp(level / 5, 0, 1);
104
+ break;
105
+ }
106
+ }
107
+ rawList.push({
108
+ goalId,
109
+ goal,
110
+ deadlineUrgency,
111
+ gapSeverity,
112
+ dependencyWeight: clamp(dependencyWeight, 0, 1),
113
+ userPriority,
114
+ });
115
+ }
116
+ if (rawList.length === 0)
117
+ return [];
118
+ // --- Step 2: compute weighted priority ---
119
+ const W1 = 0.35;
120
+ const W2 = 0.25;
121
+ const W3 = 0.25;
122
+ const W4 = 0.15;
123
+ const withBase = rawList.map((r) => {
124
+ const basePriority = W1 * r.deadlineUrgency +
125
+ W2 * r.gapSeverity +
126
+ W3 * r.dependencyWeight +
127
+ W4 * r.userPriority;
128
+ return { ...r, basePriority };
129
+ });
130
+ // --- Step 3: apply synergy / conflict adjustments ---
131
+ const synergyBonus = this.config.synergy_bonus / 2; // split the config bonus equally
132
+ const CONFLICT_PENALTY = 0.15;
133
+ const goalIdSet = new Set(rawList.map((r) => r.goalId));
134
+ // Build a lookup: goalId → index in withBase
135
+ const indexMap = new Map();
136
+ withBase.forEach((r, i) => indexMap.set(r.goalId, i));
137
+ // Adjust scores based on dependency edges between goals in the set
138
+ const adjustments = new Array(withBase.length).fill(0);
139
+ const graph = this.goalDependencyGraph.getGraph();
140
+ const seenPairs = new Set();
141
+ for (const edge of graph.edges) {
142
+ if (edge.status !== "active")
143
+ continue;
144
+ if (!goalIdSet.has(edge.from_goal_id) || !goalIdSet.has(edge.to_goal_id))
145
+ continue;
146
+ const pairKey = [edge.from_goal_id, edge.to_goal_id].sort().join("||");
147
+ if (edge.type === "synergy") {
148
+ if (!seenPairs.has(pairKey)) {
149
+ seenPairs.add(pairKey);
150
+ const idxA = indexMap.get(edge.from_goal_id);
151
+ const idxB = indexMap.get(edge.to_goal_id);
152
+ if (idxA !== undefined)
153
+ adjustments[idxA] += synergyBonus;
154
+ if (idxB !== undefined)
155
+ adjustments[idxB] += synergyBonus;
156
+ }
157
+ }
158
+ else if (edge.type === "conflict") {
159
+ if (!seenPairs.has(pairKey)) {
160
+ seenPairs.add(pairKey);
161
+ // Penalise the lower-priority goal
162
+ const idxA = indexMap.get(edge.from_goal_id);
163
+ const idxB = indexMap.get(edge.to_goal_id);
164
+ if (idxA !== undefined && idxB !== undefined) {
165
+ const scoreA = withBase[idxA].basePriority;
166
+ const scoreB = withBase[idxB].basePriority;
167
+ if (scoreA <= scoreB) {
168
+ adjustments[idxA] -= CONFLICT_PENALTY;
169
+ }
170
+ else {
171
+ adjustments[idxB] -= CONFLICT_PENALTY;
172
+ }
173
+ }
174
+ }
175
+ }
176
+ }
177
+ // --- Step 4: produce final factors ---
178
+ const result = withBase.map((r, i) => {
179
+ const computedPriority = clamp(r.basePriority + (adjustments[i] ?? 0), 0, 1);
180
+ return {
181
+ goal_id: r.goalId,
182
+ deadline_urgency: r.deadlineUrgency,
183
+ gap_severity: r.gapSeverity,
184
+ dependency_weight: r.dependencyWeight,
185
+ user_priority: r.userPriority,
186
+ computed_priority: computedPriority,
187
+ };
188
+ });
189
+ // Sort descending by computed_priority
190
+ result.sort((a, b) => b.computed_priority - a.computed_priority);
191
+ // Cache for rebalance
192
+ for (const f of result) {
193
+ this.lastPriorities.set(f.goal_id, f);
194
+ }
195
+ return result;
196
+ }
197
+ // ─── Resource Allocation ───
198
+ /**
199
+ * Allocate resource shares across goals based on their priority scores.
200
+ *
201
+ * Rules:
202
+ * 1. If goals > max_concurrent_goals, lowest priority goals get allocation=0
203
+ * and are labelled "waiting".
204
+ * 2. Active goals (up to max_concurrent_goals) share 1.0 proportionally to
205
+ * computed_priority, with a floor of min_goal_share.
206
+ * 3. Sum of active allocations = 1.0.
207
+ *
208
+ * @param priorities — output from calculateGoalPriorities
209
+ * @param strategy — optional AllocationStrategy (default: 'priority')
210
+ * @param momentumMap — goalId → MomentumInfo, required when strategy.type === 'momentum'
211
+ * @param depSchedule — DependencySchedule, required when strategy.type === 'dependency_aware'
212
+ * @returns CrossGoalAllocation[] in the same order as priorities
213
+ */
214
+ allocateResources(priorities, strategy, momentumMap, depSchedule) {
215
+ if (priorities.length === 0)
216
+ return [];
217
+ const { max_concurrent_goals, min_goal_share } = this.config;
218
+ // Split into active (top N) and waiting (rest), already sorted desc
219
+ const activeCount = Math.min(priorities.length, max_concurrent_goals);
220
+ const activePriorities = priorities.slice(0, activeCount);
221
+ const waitingPriorities = priorities.slice(activeCount);
222
+ // Build allocations for waiting goals (zero share)
223
+ const waitingAllocations = waitingPriorities.map((p) => ({
224
+ goal_id: p.goal_id,
225
+ priority: p.computed_priority,
226
+ resource_share: 0,
227
+ adjustment_reason: `waiting: exceeds max_concurrent_goals (${max_concurrent_goals})`,
228
+ }));
229
+ if (activePriorities.length === 0)
230
+ return waitingAllocations;
231
+ // Single goal gets everything
232
+ if (activePriorities.length === 1) {
233
+ return [
234
+ {
235
+ goal_id: activePriorities[0].goal_id,
236
+ priority: activePriorities[0].computed_priority,
237
+ resource_share: 1.0,
238
+ adjustment_reason: "sole active goal",
239
+ },
240
+ ...waitingAllocations,
241
+ ];
242
+ }
243
+ const n = activePriorities.length;
244
+ // --- Strategy-specific weight computation ---
245
+ const strategyType = strategy?.type ?? "priority";
246
+ let weights;
247
+ let strategyReason;
248
+ if (strategyType === "equal") {
249
+ weights = activePriorities.map(() => 1);
250
+ strategyReason = "equal allocation";
251
+ }
252
+ else if (strategyType === "momentum" && momentumMap && momentumMap.size > 0) {
253
+ const momentumWeight = strategy?.momentumWeight ?? 0.5;
254
+ // Blend priority and momentum velocity
255
+ weights = activePriorities.map((p) => {
256
+ const mom = momentumMap.get(p.goal_id);
257
+ const vel = mom ? Math.max(mom.velocity, 0) : 0;
258
+ return (1 - momentumWeight) * p.computed_priority + momentumWeight * vel;
259
+ });
260
+ strategyReason = "momentum-weighted";
261
+ }
262
+ else if (strategyType === "dependency_aware" && depSchedule) {
263
+ // Goals on critical path and unblocked goals get a boost
264
+ const criticalSet = new Set(depSchedule.criticalPath);
265
+ // Determine which goals are currently unblocked (in phase 0 or phase whose blockedBy are empty)
266
+ const unblockedGoals = new Set();
267
+ for (const phase of depSchedule.phases) {
268
+ if (phase.blockedBy.length === 0) {
269
+ for (const id of phase.goalIds)
270
+ unblockedGoals.add(id);
271
+ }
272
+ }
273
+ weights = activePriorities.map((p) => {
274
+ let w = p.computed_priority;
275
+ if (criticalSet.has(p.goal_id))
276
+ w *= 1.5;
277
+ if (unblockedGoals.has(p.goal_id))
278
+ w *= 1.2;
279
+ return w;
280
+ });
281
+ strategyReason = "dependency_aware";
282
+ }
283
+ else {
284
+ // Default: priority-proportional
285
+ weights = activePriorities.map((p) => p.computed_priority);
286
+ strategyReason = "priority";
287
+ }
288
+ // Proportional allocation with guaranteed min_goal_share floor.
289
+ //
290
+ // Algorithm:
291
+ // 1. Reserve min_goal_share for every active goal.
292
+ // 2. Distribute the remaining budget (1 - n * min_goal_share) proportionally
293
+ // by computed weight.
294
+ // 3. This guarantees every active goal has at least min_goal_share.
295
+ //
296
+ // Edge case: if n * min_goal_share >= 1 (too many goals for the floor to
297
+ // allow proportional distribution), fall back to equal distribution.
298
+ const reservedTotal = n * min_goal_share;
299
+ let finalShares;
300
+ if (reservedTotal >= 1) {
301
+ // No room for proportional top-up — give everyone an equal share
302
+ finalShares = activePriorities.map(() => 1 / n);
303
+ }
304
+ else {
305
+ const remainingBudget = 1 - reservedTotal;
306
+ const totalWeight = weights.reduce((sum, w) => sum + w, 0);
307
+ if (totalWeight === 0) {
308
+ // All zero — split remaining budget equally
309
+ finalShares = activePriorities.map(() => min_goal_share + remainingBudget / n);
310
+ }
311
+ else {
312
+ finalShares = weights.map((w) => min_goal_share + remainingBudget * (w / totalWeight));
313
+ }
314
+ }
315
+ // Track which goals received the floor for reason strings
316
+ const totalWeightForReason = weights.reduce((sum, w) => sum + w, 0);
317
+ const rawShares = totalWeightForReason === 0
318
+ ? activePriorities.map(() => 1 / n)
319
+ : weights.map((w) => w / totalWeightForReason);
320
+ const activeAllocations = activePriorities.map((p, i) => {
321
+ const share = finalShares[i];
322
+ const raw = rawShares[i];
323
+ let reason;
324
+ if (raw < min_goal_share) {
325
+ reason = `min_goal_share floor applied (raw=${raw.toFixed(3)}, strategy=${strategyReason})`;
326
+ }
327
+ else {
328
+ reason = `${strategyReason}: weight=${weights[i].toFixed(3)}`;
329
+ }
330
+ return {
331
+ goal_id: p.goal_id,
332
+ priority: p.computed_priority,
333
+ resource_share: share,
334
+ adjustment_reason: reason,
335
+ };
336
+ });
337
+ return [...activeAllocations, ...waitingAllocations];
338
+ }
339
+ // ─── Rebalancing ───
340
+ /**
341
+ * Recalculate priorities for all currently active goals and produce a new
342
+ * allocation plan.
343
+ *
344
+ * @param trigger — what caused this rebalance
345
+ * @param goalIds — explicit list of goal IDs to consider; if omitted, the
346
+ * IDs from the last calculateGoalPriorities call are used
347
+ */
348
+ rebalanceGoals(trigger, goalIds) {
349
+ const ids = goalIds ?? Array.from(this.lastPriorities.keys());
350
+ const priorities = this.calculateGoalPriorities(ids);
351
+ const allocations = this.allocateResources(priorities);
352
+ return {
353
+ timestamp: new Date().toISOString(),
354
+ allocations,
355
+ triggered_by: trigger,
356
+ };
357
+ }
358
+ // ─── Template Recommendation ───
359
+ /**
360
+ * Search the VectorIndex for strategy templates that match the given goal.
361
+ *
362
+ * Matching is based on:
363
+ * 1. Semantic similarity between the goal text and template hypothesis_pattern
364
+ * 2. domain_tags overlap (at least 1 tag in common with the goal's domain tags)
365
+ * 3. Final ranking: similarity × effectiveness_score (descending)
366
+ *
367
+ * The caller is responsible for having added StrategyTemplate objects to the
368
+ * VectorIndex with their `template_id` as the entry id and metadata shaped
369
+ * as StrategyTemplate fields.
370
+ *
371
+ * @param goalId — goal for which templates are requested
372
+ * @param vectorIndex — the index to search (typically the instance-level one,
373
+ * but callers may pass a different one for testing)
374
+ * @param limit — number of results to return (default 3)
375
+ */
376
+ async getRecommendedTemplates(goalId, vectorIndex, limit = 3) {
377
+ const goal = this.stateManager.loadGoal(goalId);
378
+ if (!goal)
379
+ return [];
380
+ // Build a query string from the goal
381
+ const queryText = [goal.title, goal.description, ...goal.constraints]
382
+ .filter(Boolean)
383
+ .join(" ");
384
+ if (!queryText.trim())
385
+ return [];
386
+ // Search index — retrieve more than `limit` so we can filter by domain_tags
387
+ const searchResults = await vectorIndex.search(queryText, limit * 5);
388
+ if (searchResults.length === 0)
389
+ return [];
390
+ // Derive goal domain tags from constraints (format "domain:tag") or title words
391
+ const goalDomainTags = this._extractDomainTags(goal);
392
+ // Filter and score
393
+ const scored = [];
394
+ for (const result of searchResults) {
395
+ const meta = result.metadata;
396
+ // Must have the required StrategyTemplate fields in metadata
397
+ if (typeof meta["template_id"] !== "string" ||
398
+ typeof meta["hypothesis_pattern"] !== "string" ||
399
+ !Array.isArray(meta["domain_tags"]) ||
400
+ typeof meta["effectiveness_score"] !== "number") {
401
+ continue;
402
+ }
403
+ const domainTags = meta["domain_tags"];
404
+ const effectivenessScore = meta["effectiveness_score"];
405
+ // Require at least 1 domain tag overlap — unless goal has no tags (then include all)
406
+ if (goalDomainTags.length > 0) {
407
+ const overlap = domainTags.filter((t) => goalDomainTags.includes(t)).length;
408
+ if (overlap < 1)
409
+ continue;
410
+ }
411
+ const template = {
412
+ template_id: meta["template_id"],
413
+ source_goal_id: typeof meta["source_goal_id"] === "string"
414
+ ? meta["source_goal_id"]
415
+ : "",
416
+ source_strategy_id: typeof meta["source_strategy_id"] === "string"
417
+ ? meta["source_strategy_id"]
418
+ : "",
419
+ hypothesis_pattern: meta["hypothesis_pattern"],
420
+ domain_tags: domainTags,
421
+ effectiveness_score: effectivenessScore,
422
+ applicable_dimensions: Array.isArray(meta["applicable_dimensions"])
423
+ ? meta["applicable_dimensions"]
424
+ : [],
425
+ embedding_id: typeof meta["embedding_id"] === "string"
426
+ ? meta["embedding_id"]
427
+ : null,
428
+ created_at: typeof meta["created_at"] === "string"
429
+ ? meta["created_at"]
430
+ : new Date().toISOString(),
431
+ };
432
+ const finalScore = result.similarity * effectivenessScore;
433
+ scored.push({ template, finalScore });
434
+ }
435
+ // Sort by finalScore descending and return top `limit`
436
+ scored.sort((a, b) => b.finalScore - a.finalScore);
437
+ return scored.slice(0, limit).map((s) => s.template);
438
+ }
439
+ // ─── Momentum ───
440
+ /**
441
+ * Calculate momentum for a single goal based on recent state snapshots.
442
+ *
443
+ * @param goalId — goal to evaluate
444
+ * @param snapshots — array of recent progress values (0-1), ordered oldest → newest
445
+ * (typically last 5 iterations). Minimum 2 values required.
446
+ * @returns MomentumInfo
447
+ */
448
+ calculateMomentum(goalId, snapshots) {
449
+ if (snapshots.length === 0) {
450
+ return { goalId, recentProgress: 0, velocity: 0, trend: "stalled" };
451
+ }
452
+ if (snapshots.length === 1) {
453
+ return { goalId, recentProgress: 0, velocity: 0, trend: "stalled" };
454
+ }
455
+ // recentProgress = total delta from first to last snapshot
456
+ const recentProgress = snapshots[snapshots.length - 1] - snapshots[0];
457
+ // velocity = smoothed average per-step delta (EMA-style: weight recent steps more)
458
+ const deltas = [];
459
+ for (let i = 1; i < snapshots.length; i++) {
460
+ deltas.push(snapshots[i] - snapshots[i - 1]);
461
+ }
462
+ // Simple smoothed velocity: weighted average where later deltas have higher weight
463
+ let weightedSum = 0;
464
+ let weightTotal = 0;
465
+ for (let i = 0; i < deltas.length; i++) {
466
+ const w = i + 1; // weight increases for more recent deltas
467
+ weightedSum += deltas[i] * w;
468
+ weightTotal += w;
469
+ }
470
+ const velocity = weightTotal > 0 ? weightedSum / weightTotal : 0;
471
+ // Trend detection:
472
+ // stalled: velocity ≈ 0 (< 0.005)
473
+ // accelerating: later half average > earlier half average
474
+ // decelerating: later half average < earlier half average (by ≥ threshold)
475
+ // steady: otherwise
476
+ let trend;
477
+ const STALL_THRESHOLD = 0.005;
478
+ if (Math.abs(velocity) < STALL_THRESHOLD) {
479
+ trend = "stalled";
480
+ }
481
+ else if (deltas.length >= 2) {
482
+ const mid = Math.floor(deltas.length / 2);
483
+ const earlyAvg = deltas.slice(0, mid).reduce((s, d) => s + d, 0) / mid;
484
+ const lateAvg = deltas.slice(mid).reduce((s, d) => s + d, 0) / (deltas.length - mid);
485
+ const ACCEL_THRESHOLD = 0.002;
486
+ if (lateAvg > earlyAvg + ACCEL_THRESHOLD) {
487
+ trend = "accelerating";
488
+ }
489
+ else if (lateAvg < earlyAvg - ACCEL_THRESHOLD) {
490
+ trend = "decelerating";
491
+ }
492
+ else {
493
+ trend = "steady";
494
+ }
495
+ }
496
+ else {
497
+ // Only 1 delta — classify by sign
498
+ trend = velocity > 0 ? "steady" : "stalled";
499
+ }
500
+ return { goalId, recentProgress, velocity, trend };
501
+ }
502
+ // ─── Dependency Scheduling ───
503
+ /**
504
+ * Build a phased dependency schedule for the given goals using the provided
505
+ * GoalDependencyGraph instance.
506
+ *
507
+ * The schedule uses topological sort to group goals into phases where all
508
+ * goals in a phase can run concurrently. Phase 0 contains goals with no
509
+ * prerequisites; subsequent phases contain goals whose prerequisites are
510
+ * all satisfied by earlier phases.
511
+ *
512
+ * The critical path is the longest chain of prerequisite edges through the
513
+ * DAG (measured in number of nodes).
514
+ *
515
+ * @param goalIds — IDs of goals to schedule
516
+ * @param graph — the GoalDependencyGraph instance to query
517
+ * @returns DependencySchedule
518
+ */
519
+ buildDependencySchedule(goalIds, graph) {
520
+ if (goalIds.length === 0) {
521
+ return { phases: [], criticalPath: [] };
522
+ }
523
+ const goalSet = new Set(goalIds);
524
+ // Build adjacency: prereqMap[child] = Set of parents that must complete first
525
+ const prereqMap = new Map();
526
+ for (const id of goalIds) {
527
+ prereqMap.set(id, new Set());
528
+ }
529
+ for (const id of goalIds) {
530
+ const blockers = graph.getBlockingGoals(id).filter((b) => goalSet.has(b));
531
+ for (const blocker of blockers) {
532
+ prereqMap.get(id).add(blocker);
533
+ }
534
+ }
535
+ // Kahn's algorithm for topological sort into phases
536
+ const phases = [];
537
+ const completed = new Set();
538
+ const remaining = new Set(goalIds);
539
+ let phaseIndex = 0;
540
+ while (remaining.size > 0) {
541
+ // Goals whose all prerequisites are completed
542
+ const readyGoals = [];
543
+ for (const id of remaining) {
544
+ const prereqs = prereqMap.get(id);
545
+ const allSatisfied = [...prereqs].every((p) => completed.has(p));
546
+ if (allSatisfied) {
547
+ readyGoals.push(id);
548
+ }
549
+ }
550
+ if (readyGoals.length === 0) {
551
+ // Cycle detected or unresolvable — put all remaining in one phase
552
+ const cycleGoals = [...remaining];
553
+ const blockedBy = cycleGoals.flatMap((id) => [...(prereqMap.get(id) ?? [])].filter((p) => !completed.has(p)));
554
+ phases.push({
555
+ phase: phaseIndex,
556
+ goalIds: cycleGoals,
557
+ blockedBy: [...new Set(blockedBy)],
558
+ });
559
+ break;
560
+ }
561
+ // Collect the set of blockers for this phase's goals
562
+ const phaseBlockedBy = readyGoals.flatMap((id) => [...(prereqMap.get(id) ?? [])]);
563
+ phases.push({
564
+ phase: phaseIndex,
565
+ goalIds: readyGoals,
566
+ blockedBy: [...new Set(phaseBlockedBy)],
567
+ });
568
+ for (const id of readyGoals) {
569
+ completed.add(id);
570
+ remaining.delete(id);
571
+ }
572
+ phaseIndex++;
573
+ }
574
+ // Critical path: longest chain of prerequisite edges (BFS/DFS from each node)
575
+ const criticalPath = this._computeCriticalPath(goalIds, prereqMap);
576
+ return { phases, criticalPath };
577
+ }
578
+ // ─── Stall Rebalancing ───
579
+ /**
580
+ * Detect stalled goals and redistribute their resources to progressing goals.
581
+ *
582
+ * A goal is considered stalled if its MomentumInfo.trend === 'stalled'.
583
+ * Resources from stalled goals are redistributed proportionally to
584
+ * non-stalled goals based on their velocity.
585
+ *
586
+ * @param currentAllocations — current CrossGoalAllocation array
587
+ * @param momentumMap — goalId → MomentumInfo
588
+ * @returns array of RebalanceActions taken (empty if no stalled goals)
589
+ */
590
+ rebalanceOnStall(currentAllocations, momentumMap) {
591
+ const actions = [];
592
+ if (currentAllocations.length === 0)
593
+ return actions;
594
+ const stalled = [];
595
+ const progressing = [];
596
+ for (const alloc of currentAllocations) {
597
+ const mom = momentumMap.get(alloc.goal_id);
598
+ if (!mom || mom.trend === "stalled") {
599
+ stalled.push(alloc);
600
+ }
601
+ else {
602
+ progressing.push(alloc);
603
+ }
604
+ }
605
+ if (stalled.length === 0)
606
+ return actions;
607
+ // Nothing to redistribute to
608
+ if (progressing.length === 0)
609
+ return actions;
610
+ // Calculate total share to redistribute
611
+ const redistributeTotal = stalled.reduce((s, a) => s + a.resource_share, 0);
612
+ // Compute target shares for progressing goals, weighted by velocity
613
+ const totalVelocity = progressing.reduce((s, a) => {
614
+ const mom = momentumMap.get(a.goal_id);
615
+ return s + Math.max(mom?.velocity ?? 0, 0);
616
+ }, 0);
617
+ for (const alloc of stalled) {
618
+ actions.push({
619
+ goalId: alloc.goal_id,
620
+ action: "reduce",
621
+ reason: "stalled: momentum velocity ≈ 0",
622
+ previousShare: alloc.resource_share,
623
+ newShare: 0,
624
+ });
625
+ }
626
+ for (const alloc of progressing) {
627
+ const mom = momentumMap.get(alloc.goal_id);
628
+ const vel = Math.max(mom?.velocity ?? 0, 0);
629
+ const bonus = totalVelocity > 0
630
+ ? redistributeTotal * (vel / totalVelocity)
631
+ : redistributeTotal / progressing.length;
632
+ const newShare = clamp(alloc.resource_share + bonus, 0, 1);
633
+ actions.push({
634
+ goalId: alloc.goal_id,
635
+ action: "increase",
636
+ reason: `received share from stalled goals (velocity=${vel.toFixed(4)})`,
637
+ previousShare: alloc.resource_share,
638
+ newShare,
639
+ });
640
+ }
641
+ return actions;
642
+ }
643
+ // ─── Private helpers ───
644
+ /**
645
+ * Compute the critical path (longest prerequisite chain) among the given goals.
646
+ * Returns the sequence of goalIds on the critical path.
647
+ */
648
+ _computeCriticalPath(goalIds, prereqMap) {
649
+ // dp[id] = longest path length ending at id (in nodes)
650
+ const dp = new Map();
651
+ const parent = new Map();
652
+ function longestFrom(id) {
653
+ const cached = dp.get(id);
654
+ if (cached !== undefined)
655
+ return cached;
656
+ const prereqs = prereqMap.get(id) ?? new Set();
657
+ if (prereqs.size === 0) {
658
+ dp.set(id, 1);
659
+ parent.set(id, null);
660
+ return 1;
661
+ }
662
+ let best = 0;
663
+ let bestParent = null;
664
+ for (const p of prereqs) {
665
+ const len = longestFrom(p);
666
+ if (len > best) {
667
+ best = len;
668
+ bestParent = p;
669
+ }
670
+ }
671
+ dp.set(id, best + 1);
672
+ parent.set(id, bestParent);
673
+ return best + 1;
674
+ }
675
+ // Compute for all goals
676
+ for (const id of goalIds) {
677
+ longestFrom(id);
678
+ }
679
+ // Find the goal with the highest dp value
680
+ let maxLen = 0;
681
+ let maxGoal = goalIds[0] ?? "";
682
+ for (const id of goalIds) {
683
+ const len = dp.get(id) ?? 0;
684
+ if (len > maxLen) {
685
+ maxLen = len;
686
+ maxGoal = id;
687
+ }
688
+ }
689
+ if (maxLen === 0)
690
+ return [];
691
+ // Reconstruct path by following parent pointers
692
+ const path = [];
693
+ let current = maxGoal;
694
+ while (current !== null) {
695
+ path.unshift(current);
696
+ current = parent.get(current) ?? null;
697
+ }
698
+ return path;
699
+ }
700
+ /**
701
+ * Produce a rough [0,1] severity for a single goal dimension.
702
+ *
703
+ * For numeric thresholds we compute gap / scale.
704
+ * For binary thresholds (present/match) we return 0 or 1.
705
+ * Returns 0 when the dimension is already satisfied.
706
+ */
707
+ _estimateDimensionGap(dim) {
708
+ const { current_value, threshold } = dim;
709
+ if (current_value === null)
710
+ return 1;
711
+ switch (threshold.type) {
712
+ case "min": {
713
+ if (typeof current_value !== "number")
714
+ return 0;
715
+ const gap = threshold.value - current_value;
716
+ if (gap <= 0)
717
+ return 0;
718
+ return threshold.value !== 0 ? clamp(gap / threshold.value, 0, 1) : 1;
719
+ }
720
+ case "max": {
721
+ if (typeof current_value !== "number")
722
+ return 0;
723
+ const gap = current_value - threshold.value;
724
+ if (gap <= 0)
725
+ return 0;
726
+ return threshold.value !== 0 ? clamp(gap / threshold.value, 0, 1) : 1;
727
+ }
728
+ case "range": {
729
+ if (typeof current_value !== "number")
730
+ return 0;
731
+ const span = threshold.high - threshold.low;
732
+ if (current_value < threshold.low) {
733
+ const gap = threshold.low - current_value;
734
+ return span > 0 ? clamp(gap / span, 0, 1) : 1;
735
+ }
736
+ if (current_value > threshold.high) {
737
+ const gap = current_value - threshold.high;
738
+ return span > 0 ? clamp(gap / span, 0, 1) : 1;
739
+ }
740
+ return 0;
741
+ }
742
+ case "present": {
743
+ return current_value ? 0 : 1;
744
+ }
745
+ case "match": {
746
+ return current_value === threshold.value ? 0 : 1;
747
+ }
748
+ default:
749
+ return 0;
750
+ }
751
+ }
752
+ /**
753
+ * Extract domain tags from a goal's constraints and title.
754
+ * Recognises constraints with format "domain:tagname" or "tag:tagname".
755
+ */
756
+ _extractDomainTags(goal) {
757
+ const tags = [];
758
+ for (const constraint of goal.constraints) {
759
+ const match = constraint.match(/^(?:domain|tag)[:\s]+(.+)$/i);
760
+ if (match) {
761
+ tags.push(match[1].trim().toLowerCase());
762
+ }
763
+ }
764
+ return tags;
765
+ }
766
+ // ─── Allocation Map ───
767
+ /**
768
+ * Get a goal_id → resource_share map for the given goal IDs.
769
+ *
770
+ * Recomputes allocations based on current goal states.
771
+ * Returns a Map suitable for use by PortfolioManager.selectNextStrategyAcrossGoals().
772
+ */
773
+ getAllocationMap(goalIds) {
774
+ const priorities = this.calculateGoalPriorities(goalIds);
775
+ const allocations = this.allocateResources(priorities);
776
+ const map = new Map();
777
+ for (const alloc of allocations) {
778
+ map.set(alloc.goal_id, alloc.resource_share);
779
+ }
780
+ // Fill in any goal IDs that were not computed (e.g. loadGoal returned null)
781
+ const equalShare = goalIds.length > 0 ? 1.0 / goalIds.length : 0;
782
+ for (const goalId of goalIds) {
783
+ if (!map.has(goalId)) {
784
+ map.set(goalId, equalShare);
785
+ }
786
+ }
787
+ return map;
788
+ }
789
+ }
790
+ //# sourceMappingURL=cross-goal-portfolio.js.map