opencandle 0.11.1 → 0.13.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 (678) hide show
  1. package/README.md +50 -186
  2. package/dist/analysts/contracts.js +0 -1
  3. package/dist/analysts/orchestrator.js +0 -1
  4. package/dist/cli-main.js +22 -15
  5. package/dist/cli-options.d.ts +4 -0
  6. package/dist/cli-options.js +33 -0
  7. package/dist/cli.js +8 -3
  8. package/dist/config.d.ts +4 -0
  9. package/dist/config.js +1 -1
  10. package/dist/doctor/cli-command.js +9 -5
  11. package/dist/doctor/render.js +0 -1
  12. package/dist/doctor/report.js +53 -11
  13. package/dist/gui/server/ask-user-bridge.d.ts +19 -0
  14. package/dist/gui/server/ask-user-bridge.js +55 -0
  15. package/dist/gui/server/automation-heartbeat.d.ts +25 -0
  16. package/dist/gui/server/automation-heartbeat.js +61 -0
  17. package/dist/gui/server/background-quotes.d.ts +39 -0
  18. package/dist/gui/server/background-quotes.js +71 -0
  19. package/dist/gui/server/chat-event-adapter.d.ts +16 -0
  20. package/dist/gui/server/chat-event-adapter.js +388 -0
  21. package/dist/gui/server/gui-session-manager.d.ts +2 -0
  22. package/dist/gui/server/gui-session-manager.js +4 -0
  23. package/dist/gui/server/history-snapshot-store.d.ts +8 -0
  24. package/dist/gui/server/history-snapshot-store.js +43 -0
  25. package/dist/gui/server/http-routes.d.ts +71 -0
  26. package/dist/gui/server/http-routes.js +1033 -0
  27. package/dist/gui/server/invoke-tool.d.ts +47 -0
  28. package/dist/gui/server/invoke-tool.js +373 -0
  29. package/dist/gui/server/live-chat-event-adapter.d.ts +21 -0
  30. package/dist/gui/server/live-chat-event-adapter.js +224 -0
  31. package/dist/gui/server/local-session-coordinator.d.ts +26 -0
  32. package/dist/gui/server/local-session-coordinator.js +53 -0
  33. package/dist/gui/server/market-indices-api.d.ts +21 -0
  34. package/dist/gui/server/market-indices-api.js +26 -0
  35. package/dist/gui/server/market-indices-snapshot-store.d.ts +12 -0
  36. package/dist/gui/server/market-indices-snapshot-store.js +56 -0
  37. package/dist/gui/server/market-state-api.d.ts +250 -0
  38. package/dist/gui/server/market-state-api.js +597 -0
  39. package/dist/gui/server/model-setup.d.ts +55 -0
  40. package/dist/gui/server/model-setup.js +154 -0
  41. package/dist/gui/server/private-api-access.d.ts +6 -0
  42. package/dist/gui/server/private-api-access.js +53 -0
  43. package/dist/gui/server/projector.d.ts +49 -0
  44. package/dist/gui/server/projector.js +296 -0
  45. package/dist/gui/server/prompt-observation.d.ts +8 -0
  46. package/dist/gui/server/prompt-observation.js +43 -0
  47. package/dist/gui/server/quote-snapshot-store.d.ts +14 -0
  48. package/dist/gui/server/quote-snapshot-store.js +49 -0
  49. package/dist/gui/server/server.d.ts +1 -0
  50. package/dist/gui/server/server.js +262 -0
  51. package/dist/gui/server/session-actions.d.ts +60 -0
  52. package/dist/gui/server/session-actions.js +218 -0
  53. package/dist/gui/server/session-entry-wait.d.ts +27 -0
  54. package/dist/gui/server/session-entry-wait.js +129 -0
  55. package/dist/gui/server/session-list.d.ts +2 -0
  56. package/dist/gui/server/session-list.js +11 -0
  57. package/dist/gui/server/shutdown.d.ts +10 -0
  58. package/dist/gui/server/shutdown.js +29 -0
  59. package/dist/gui/server/tool-invoke-ack.d.ts +17 -0
  60. package/dist/gui/server/tool-invoke-ack.js +26 -0
  61. package/dist/gui/server/tool-metadata.d.ts +93 -0
  62. package/dist/gui/server/tool-metadata.js +148 -0
  63. package/dist/gui/server/websocket.d.ts +9 -0
  64. package/dist/gui/server/websocket.js +124 -0
  65. package/dist/gui/server/writer-lock.d.ts +1 -0
  66. package/dist/gui/server/writer-lock.js +1 -0
  67. package/dist/gui/server/ws-hub.d.ts +50 -0
  68. package/dist/gui/server/ws-hub.js +284 -0
  69. package/dist/gui/shared/chat-events.d.ts +174 -0
  70. package/dist/gui/shared/chat-events.js +13 -0
  71. package/dist/gui/shared/event-reducer.d.ts +3 -0
  72. package/dist/gui/shared/event-reducer.js +187 -0
  73. package/dist/index.js +0 -1
  74. package/dist/infra/cache.d.ts +4 -0
  75. package/dist/infra/cache.js +4 -1
  76. package/dist/infra/freshness.js +0 -1
  77. package/dist/infra/http-client.js +1 -2
  78. package/dist/infra/index.js +0 -1
  79. package/dist/infra/lse-byte-budget.d.ts +10 -0
  80. package/dist/infra/lse-byte-budget.js +47 -0
  81. package/dist/infra/market-calendar.js +0 -1
  82. package/dist/infra/native-dependencies.js +0 -1
  83. package/dist/infra/node-version.js +0 -1
  84. package/dist/infra/open-url.js +0 -1
  85. package/dist/infra/opencandle-paths.js +0 -1
  86. package/dist/infra/rate-limiter.js +1 -1
  87. package/dist/market-state/alert-conditions.js +0 -1
  88. package/dist/market-state/alert-runner.d.ts +1 -0
  89. package/dist/market-state/alert-runner.js +5 -4
  90. package/dist/market-state/daily-report.js +0 -1
  91. package/dist/market-state/local-automation-service.js +0 -1
  92. package/dist/market-state/notification-delivery.js +0 -1
  93. package/dist/market-state/resolve-for-mutation.js +0 -1
  94. package/dist/market-state/resolve.js +0 -1
  95. package/dist/market-state/service.d.ts +26 -21
  96. package/dist/market-state/service.js +175 -36
  97. package/dist/market-state/summaries.js +1 -13
  98. package/dist/memory/index.js +0 -1
  99. package/dist/memory/manager.js +0 -1
  100. package/dist/memory/preference-extractor.js +0 -1
  101. package/dist/memory/retrieval.js +0 -1
  102. package/dist/memory/sqlite.js +60 -11
  103. package/dist/memory/storage.js +0 -1
  104. package/dist/memory/tool-defaults.js +0 -1
  105. package/dist/memory/types.js +0 -1
  106. package/dist/monitor.js +0 -1
  107. package/dist/onboarding/connect.js +0 -1
  108. package/dist/onboarding/credential-interceptor.js +0 -1
  109. package/dist/onboarding/degradation-accumulator.js +0 -1
  110. package/dist/onboarding/prompt-user.d.ts +1 -1
  111. package/dist/onboarding/prompt-user.js +0 -1
  112. package/dist/onboarding/provider-status.js +0 -1
  113. package/dist/onboarding/providers.d.ts +16 -1
  114. package/dist/onboarding/providers.js +20 -1
  115. package/dist/onboarding/state.js +0 -1
  116. package/dist/onboarding/tool-helpers.js +0 -1
  117. package/dist/onboarding/tool-tags.js +0 -1
  118. package/dist/onboarding/validate-model-key.d.ts +17 -0
  119. package/dist/onboarding/validate-model-key.js +86 -0
  120. package/dist/onboarding/validation.js +8 -1
  121. package/dist/pi/opencandle-extension.d.ts +2 -1
  122. package/dist/pi/opencandle-extension.js +4 -4
  123. package/dist/pi/session-action-dedupe.js +0 -1
  124. package/dist/pi/session-storage.js +0 -1
  125. package/dist/pi/session-writer-lock.js +0 -1
  126. package/dist/pi/session.d.ts +2 -3
  127. package/dist/pi/session.js +7 -6
  128. package/dist/pi/setup.d.ts +4 -2
  129. package/dist/pi/setup.js +60 -61
  130. package/dist/pi/tool-adapter.js +0 -1
  131. package/dist/pi/tui-session-coordinator.js +0 -1
  132. package/dist/prompts/context-builder.js +1 -2
  133. package/dist/prompts/disclaimer.js +0 -1
  134. package/dist/prompts/policy-cards.js +0 -1
  135. package/dist/prompts/sections.js +0 -1
  136. package/dist/prompts/symbol-preflight.js +0 -1
  137. package/dist/prompts/workflow-prompts.js +16 -15
  138. package/dist/providers/alpha-vantage.js +2 -3
  139. package/dist/providers/coingecko.js +0 -1
  140. package/dist/providers/errors.js +0 -1
  141. package/dist/providers/exa-search.js +11 -10
  142. package/dist/providers/external-tool-command.js +0 -1
  143. package/dist/providers/external-tool-error.js +0 -1
  144. package/dist/providers/fear-greed.js +0 -1
  145. package/dist/providers/finnhub.js +0 -1
  146. package/dist/providers/fred.js +0 -1
  147. package/dist/providers/index.d.ts +1 -0
  148. package/dist/providers/index.js +1 -1
  149. package/dist/providers/lse.d.ts +35 -0
  150. package/dist/providers/lse.js +284 -0
  151. package/dist/providers/polymarket.js +22 -6
  152. package/dist/providers/provider-credential-error.js +0 -1
  153. package/dist/providers/reddit-cli.js +0 -1
  154. package/dist/providers/reddit.js +0 -1
  155. package/dist/providers/sec-edgar.js +0 -1
  156. package/dist/providers/tradingview.js +1 -2
  157. package/dist/providers/twitter-cli.js +0 -1
  158. package/dist/providers/twitter.js +0 -1
  159. package/dist/providers/web-search.js +15 -12
  160. package/dist/providers/with-fallback.js +0 -1
  161. package/dist/providers/wrap-provider.js +1 -1
  162. package/dist/providers/yahoo-finance.js +68 -4
  163. package/dist/routing/classify-intent.js +0 -1
  164. package/dist/routing/defaults.js +0 -1
  165. package/dist/routing/entity-extractor.js +2 -3
  166. package/dist/routing/fund-symbols.js +0 -1
  167. package/dist/routing/horizon.js +0 -1
  168. package/dist/routing/index.js +0 -1
  169. package/dist/routing/legacy-rule-router.js +0 -1
  170. package/dist/routing/planning.js +0 -1
  171. package/dist/routing/route-manifest.js +1 -1
  172. package/dist/routing/router-llm-client.d.ts +2 -2
  173. package/dist/routing/router-llm-client.js +0 -1
  174. package/dist/routing/router-prompt.js +0 -1
  175. package/dist/routing/router-types.js +0 -1
  176. package/dist/routing/router.js +9 -3
  177. package/dist/routing/slot-resolver.js +0 -1
  178. package/dist/routing/symbol-disambiguator.js +0 -1
  179. package/dist/routing/turn-context.js +0 -1
  180. package/dist/routing/types.js +0 -1
  181. package/dist/runtime/answer-contracts.js +0 -1
  182. package/dist/runtime/artifact-contracts.js +0 -1
  183. package/dist/runtime/evidence.d.ts +1 -0
  184. package/dist/runtime/evidence.js +1 -2
  185. package/dist/runtime/numeric-claims.js +0 -1
  186. package/dist/runtime/planning-evidence.js +0 -1
  187. package/dist/runtime/prompt-step.js +0 -1
  188. package/dist/runtime/provider-tracker.js +0 -1
  189. package/dist/runtime/run-context.js +0 -1
  190. package/dist/runtime/session-coordinator.d.ts +2 -2
  191. package/dist/runtime/session-coordinator.js +2 -3
  192. package/dist/runtime/session-title.js +0 -1
  193. package/dist/runtime/tool-defaults-wrapper.js +0 -1
  194. package/dist/runtime/validation.js +0 -1
  195. package/dist/runtime/workflow-events.js +0 -1
  196. package/dist/runtime/workflow-runner.d.ts +1 -0
  197. package/dist/runtime/workflow-runner.js +8 -3
  198. package/dist/runtime/workflow-types.js +0 -1
  199. package/dist/sentiment/adapters/finnhub.js +0 -1
  200. package/dist/sentiment/adapters/reddit.js +0 -1
  201. package/dist/sentiment/adapters/twitter.js +0 -1
  202. package/dist/sentiment/adapters/web.js +0 -1
  203. package/dist/sentiment/index.js +4 -2
  204. package/dist/sentiment/insights.js +0 -1
  205. package/dist/sentiment/keywords.js +0 -1
  206. package/dist/sentiment/pipeline.js +0 -1
  207. package/dist/sentiment/scorer.js +0 -1
  208. package/dist/sentiment/store.js +0 -1
  209. package/dist/sentiment/trends.js +0 -1
  210. package/dist/sentiment/types.js +0 -1
  211. package/dist/system-prompt.js +0 -1
  212. package/dist/tool-kit.js +0 -1
  213. package/dist/tools/fundamentals/company-overview.d.ts +1 -1
  214. package/dist/tools/fundamentals/company-overview.js +2 -1
  215. package/dist/tools/fundamentals/comps.js +6 -4
  216. package/dist/tools/fundamentals/dcf.js +37 -9
  217. package/dist/tools/fundamentals/earnings.d.ts +1 -1
  218. package/dist/tools/fundamentals/earnings.js +2 -1
  219. package/dist/tools/fundamentals/financials.js +88 -9
  220. package/dist/tools/fundamentals/sec-filings.js +0 -1
  221. package/dist/tools/index.d.ts +121 -2
  222. package/dist/tools/index.js +3 -1
  223. package/dist/tools/interaction/ask-user.js +11 -1
  224. package/dist/tools/macro/event-probabilities.js +0 -1
  225. package/dist/tools/macro/fear-greed.d.ts +1 -1
  226. package/dist/tools/macro/fear-greed.js +0 -1
  227. package/dist/tools/macro/fred-data.d.ts +1 -1
  228. package/dist/tools/macro/fred-data.js +2 -1
  229. package/dist/tools/market/crypto-history.js +0 -1
  230. package/dist/tools/market/crypto-price.d.ts +2 -2
  231. package/dist/tools/market/crypto-price.js +0 -1
  232. package/dist/tools/market/price-comparison.d.ts +30 -0
  233. package/dist/tools/market/price-comparison.js +202 -0
  234. package/dist/tools/market/screen-stocks.js +0 -1
  235. package/dist/tools/market/search-ticker.js +1 -2
  236. package/dist/tools/market/stock-history.d.ts +18 -3
  237. package/dist/tools/market/stock-history.js +132 -18
  238. package/dist/tools/market/stock-quote.d.ts +2 -2
  239. package/dist/tools/market/stock-quote.js +0 -1
  240. package/dist/tools/options/greeks.js +0 -1
  241. package/dist/tools/options/option-chain.d.ts +2 -2
  242. package/dist/tools/options/option-chain.js +0 -1
  243. package/dist/tools/portfolio/alerts.d.ts +2 -1
  244. package/dist/tools/portfolio/alerts.js +228 -2
  245. package/dist/tools/portfolio/correlation.d.ts +1 -1
  246. package/dist/tools/portfolio/correlation.js +23 -5
  247. package/dist/tools/portfolio/daily-report.js +0 -1
  248. package/dist/tools/portfolio/holdings-overlap.js +0 -1
  249. package/dist/tools/portfolio/notifications.js +0 -1
  250. package/dist/tools/portfolio/risk-analysis.d.ts +2 -2
  251. package/dist/tools/portfolio/risk-analysis.js +0 -1
  252. package/dist/tools/portfolio/tracker.d.ts +3 -1
  253. package/dist/tools/portfolio/tracker.js +57 -10
  254. package/dist/tools/portfolio/watchlist.d.ts +3 -6
  255. package/dist/tools/portfolio/watchlist.js +101 -110
  256. package/dist/tools/sentiment/insight-format.js +0 -1
  257. package/dist/tools/sentiment/query-match.js +0 -1
  258. package/dist/tools/sentiment/reddit-sentiment.js +0 -1
  259. package/dist/tools/sentiment/sentiment-summary.js +8 -4
  260. package/dist/tools/sentiment/sentiment-trend.d.ts +5 -1
  261. package/dist/tools/sentiment/sentiment-trend.js +6 -2
  262. package/dist/tools/sentiment/twitter-sentiment.js +0 -1
  263. package/dist/tools/sentiment/untrusted-text.js +0 -1
  264. package/dist/tools/sentiment/web-search.d.ts +1 -1
  265. package/dist/tools/sentiment/web-search.js +0 -1
  266. package/dist/tools/sentiment/web-sentiment.js +0 -1
  267. package/dist/tools/technical/backtest.js +0 -1
  268. package/dist/tools/technical/indicators.js +0 -1
  269. package/dist/types/fundamentals.js +0 -1
  270. package/dist/types/index.js +0 -1
  271. package/dist/types/macro.js +0 -1
  272. package/dist/types/market.d.ts +8 -0
  273. package/dist/types/market.js +0 -1
  274. package/dist/types/options.js +0 -1
  275. package/dist/types/portfolio.js +0 -1
  276. package/dist/types/prediction-markets.js +0 -1
  277. package/dist/types/sentiment.js +0 -1
  278. package/dist/workflows/compare-assets.js +0 -1
  279. package/dist/workflows/index.js +0 -1
  280. package/dist/workflows/options-screener.js +0 -1
  281. package/dist/workflows/portfolio-builder.js +0 -1
  282. package/gui/web/dist/assets/CatalogOverlay-Cy8Fq0fn.js +1 -0
  283. package/gui/web/dist/assets/allocation-donut-DgBRIKCk.js +52 -0
  284. package/gui/web/dist/assets/index-DIlFyIOO.js +66 -0
  285. package/gui/web/dist/assets/index-DS4jESOB.css +2 -0
  286. package/gui/web/dist/assets/market-chart-DammaCjH.js +1 -0
  287. package/gui/web/dist/assets/utils-CnADgYgh.js +1 -0
  288. package/gui/web/dist/index.html +3 -2
  289. package/package.json +23 -26
  290. package/dist/analysts/contracts.js.map +0 -1
  291. package/dist/analysts/orchestrator.js.map +0 -1
  292. package/dist/cli-main.js.map +0 -1
  293. package/dist/cli.js.map +0 -1
  294. package/dist/config.js.map +0 -1
  295. package/dist/doctor/cli-command.js.map +0 -1
  296. package/dist/doctor/render.js.map +0 -1
  297. package/dist/doctor/report.js.map +0 -1
  298. package/dist/index.js.map +0 -1
  299. package/dist/infra/cache.js.map +0 -1
  300. package/dist/infra/freshness.js.map +0 -1
  301. package/dist/infra/http-client.js.map +0 -1
  302. package/dist/infra/index.js.map +0 -1
  303. package/dist/infra/market-calendar.js.map +0 -1
  304. package/dist/infra/native-dependencies.js.map +0 -1
  305. package/dist/infra/node-version.js.map +0 -1
  306. package/dist/infra/open-url.js.map +0 -1
  307. package/dist/infra/opencandle-paths.js.map +0 -1
  308. package/dist/infra/rate-limiter.js.map +0 -1
  309. package/dist/market-state/alert-conditions.js.map +0 -1
  310. package/dist/market-state/alert-runner.js.map +0 -1
  311. package/dist/market-state/daily-report.js.map +0 -1
  312. package/dist/market-state/local-automation-service.js.map +0 -1
  313. package/dist/market-state/notification-delivery.js.map +0 -1
  314. package/dist/market-state/resolve-for-mutation.js.map +0 -1
  315. package/dist/market-state/resolve.js.map +0 -1
  316. package/dist/market-state/service.js.map +0 -1
  317. package/dist/market-state/summaries.js.map +0 -1
  318. package/dist/memory/index.js.map +0 -1
  319. package/dist/memory/manager.js.map +0 -1
  320. package/dist/memory/preference-extractor.js.map +0 -1
  321. package/dist/memory/retrieval.js.map +0 -1
  322. package/dist/memory/sqlite.js.map +0 -1
  323. package/dist/memory/storage.js.map +0 -1
  324. package/dist/memory/tool-defaults.js.map +0 -1
  325. package/dist/memory/types.js.map +0 -1
  326. package/dist/monitor.js.map +0 -1
  327. package/dist/onboarding/connect.js.map +0 -1
  328. package/dist/onboarding/credential-interceptor.js.map +0 -1
  329. package/dist/onboarding/degradation-accumulator.js.map +0 -1
  330. package/dist/onboarding/prompt-user.js.map +0 -1
  331. package/dist/onboarding/provider-status.js.map +0 -1
  332. package/dist/onboarding/providers.js.map +0 -1
  333. package/dist/onboarding/state.js.map +0 -1
  334. package/dist/onboarding/tool-helpers.js.map +0 -1
  335. package/dist/onboarding/tool-tags.js.map +0 -1
  336. package/dist/onboarding/validation.js.map +0 -1
  337. package/dist/pi/opencandle-extension.js.map +0 -1
  338. package/dist/pi/session-action-dedupe.js.map +0 -1
  339. package/dist/pi/session-storage.js.map +0 -1
  340. package/dist/pi/session-writer-lock.js.map +0 -1
  341. package/dist/pi/session.js.map +0 -1
  342. package/dist/pi/setup.js.map +0 -1
  343. package/dist/pi/tool-adapter.js.map +0 -1
  344. package/dist/pi/tui-session-coordinator.js.map +0 -1
  345. package/dist/prompts/context-builder.js.map +0 -1
  346. package/dist/prompts/disclaimer.js.map +0 -1
  347. package/dist/prompts/policy-cards.js.map +0 -1
  348. package/dist/prompts/sections.js.map +0 -1
  349. package/dist/prompts/symbol-preflight.js.map +0 -1
  350. package/dist/prompts/workflow-prompts.js.map +0 -1
  351. package/dist/providers/alpha-vantage.js.map +0 -1
  352. package/dist/providers/coingecko.js.map +0 -1
  353. package/dist/providers/errors.js.map +0 -1
  354. package/dist/providers/exa-search.js.map +0 -1
  355. package/dist/providers/external-tool-command.js.map +0 -1
  356. package/dist/providers/external-tool-error.js.map +0 -1
  357. package/dist/providers/fear-greed.js.map +0 -1
  358. package/dist/providers/finnhub.js.map +0 -1
  359. package/dist/providers/fred.js.map +0 -1
  360. package/dist/providers/index.js.map +0 -1
  361. package/dist/providers/polymarket.js.map +0 -1
  362. package/dist/providers/provider-credential-error.js.map +0 -1
  363. package/dist/providers/reddit-cli.js.map +0 -1
  364. package/dist/providers/reddit.js.map +0 -1
  365. package/dist/providers/sec-edgar.js.map +0 -1
  366. package/dist/providers/tradingview.js.map +0 -1
  367. package/dist/providers/twitter-cli.js.map +0 -1
  368. package/dist/providers/twitter.js.map +0 -1
  369. package/dist/providers/web-search.js.map +0 -1
  370. package/dist/providers/with-fallback.js.map +0 -1
  371. package/dist/providers/wrap-provider.js.map +0 -1
  372. package/dist/providers/yahoo-finance.js.map +0 -1
  373. package/dist/routing/classify-intent.js.map +0 -1
  374. package/dist/routing/defaults.js.map +0 -1
  375. package/dist/routing/entity-extractor.js.map +0 -1
  376. package/dist/routing/fund-symbols.js.map +0 -1
  377. package/dist/routing/horizon.js.map +0 -1
  378. package/dist/routing/index.js.map +0 -1
  379. package/dist/routing/legacy-rule-router.js.map +0 -1
  380. package/dist/routing/planning.js.map +0 -1
  381. package/dist/routing/route-manifest.js.map +0 -1
  382. package/dist/routing/router-llm-client.js.map +0 -1
  383. package/dist/routing/router-prompt.js.map +0 -1
  384. package/dist/routing/router-types.js.map +0 -1
  385. package/dist/routing/router.js.map +0 -1
  386. package/dist/routing/slot-resolver.js.map +0 -1
  387. package/dist/routing/symbol-disambiguator.js.map +0 -1
  388. package/dist/routing/turn-context.js.map +0 -1
  389. package/dist/routing/types.js.map +0 -1
  390. package/dist/runtime/answer-contracts.js.map +0 -1
  391. package/dist/runtime/artifact-contracts.js.map +0 -1
  392. package/dist/runtime/evidence.js.map +0 -1
  393. package/dist/runtime/numeric-claims.js.map +0 -1
  394. package/dist/runtime/planning-evidence.js.map +0 -1
  395. package/dist/runtime/prompt-step.js.map +0 -1
  396. package/dist/runtime/provider-tracker.js.map +0 -1
  397. package/dist/runtime/run-context.js.map +0 -1
  398. package/dist/runtime/session-coordinator.js.map +0 -1
  399. package/dist/runtime/session-title.js.map +0 -1
  400. package/dist/runtime/tool-defaults-wrapper.js.map +0 -1
  401. package/dist/runtime/validation.js.map +0 -1
  402. package/dist/runtime/workflow-events.js.map +0 -1
  403. package/dist/runtime/workflow-runner.js.map +0 -1
  404. package/dist/runtime/workflow-types.js.map +0 -1
  405. package/dist/sentiment/adapters/finnhub.js.map +0 -1
  406. package/dist/sentiment/adapters/reddit.js.map +0 -1
  407. package/dist/sentiment/adapters/twitter.js.map +0 -1
  408. package/dist/sentiment/adapters/web.js.map +0 -1
  409. package/dist/sentiment/index.js.map +0 -1
  410. package/dist/sentiment/insights.js.map +0 -1
  411. package/dist/sentiment/keywords.js.map +0 -1
  412. package/dist/sentiment/pipeline.js.map +0 -1
  413. package/dist/sentiment/scorer.js.map +0 -1
  414. package/dist/sentiment/store.js.map +0 -1
  415. package/dist/sentiment/trends.js.map +0 -1
  416. package/dist/sentiment/types.js.map +0 -1
  417. package/dist/system-prompt.js.map +0 -1
  418. package/dist/tool-kit.js.map +0 -1
  419. package/dist/tools/fundamentals/company-overview.js.map +0 -1
  420. package/dist/tools/fundamentals/comps.js.map +0 -1
  421. package/dist/tools/fundamentals/dcf.js.map +0 -1
  422. package/dist/tools/fundamentals/earnings.js.map +0 -1
  423. package/dist/tools/fundamentals/financials.js.map +0 -1
  424. package/dist/tools/fundamentals/sec-filings.js.map +0 -1
  425. package/dist/tools/index.js.map +0 -1
  426. package/dist/tools/interaction/ask-user.js.map +0 -1
  427. package/dist/tools/macro/event-probabilities.js.map +0 -1
  428. package/dist/tools/macro/fear-greed.js.map +0 -1
  429. package/dist/tools/macro/fred-data.js.map +0 -1
  430. package/dist/tools/market/crypto-history.js.map +0 -1
  431. package/dist/tools/market/crypto-price.js.map +0 -1
  432. package/dist/tools/market/screen-stocks.js.map +0 -1
  433. package/dist/tools/market/search-ticker.js.map +0 -1
  434. package/dist/tools/market/stock-history.js.map +0 -1
  435. package/dist/tools/market/stock-quote.js.map +0 -1
  436. package/dist/tools/options/greeks.js.map +0 -1
  437. package/dist/tools/options/option-chain.js.map +0 -1
  438. package/dist/tools/portfolio/alerts.js.map +0 -1
  439. package/dist/tools/portfolio/correlation.js.map +0 -1
  440. package/dist/tools/portfolio/daily-report.js.map +0 -1
  441. package/dist/tools/portfolio/holdings-overlap.js.map +0 -1
  442. package/dist/tools/portfolio/notifications.js.map +0 -1
  443. package/dist/tools/portfolio/risk-analysis.js.map +0 -1
  444. package/dist/tools/portfolio/tracker.js.map +0 -1
  445. package/dist/tools/portfolio/watchlist.js.map +0 -1
  446. package/dist/tools/sentiment/insight-format.js.map +0 -1
  447. package/dist/tools/sentiment/query-match.js.map +0 -1
  448. package/dist/tools/sentiment/reddit-sentiment.js.map +0 -1
  449. package/dist/tools/sentiment/sentiment-summary.js.map +0 -1
  450. package/dist/tools/sentiment/sentiment-trend.js.map +0 -1
  451. package/dist/tools/sentiment/twitter-sentiment.js.map +0 -1
  452. package/dist/tools/sentiment/untrusted-text.js.map +0 -1
  453. package/dist/tools/sentiment/web-search.js.map +0 -1
  454. package/dist/tools/sentiment/web-sentiment.js.map +0 -1
  455. package/dist/tools/technical/backtest.js.map +0 -1
  456. package/dist/tools/technical/indicators.js.map +0 -1
  457. package/dist/types/fundamentals.js.map +0 -1
  458. package/dist/types/index.js.map +0 -1
  459. package/dist/types/macro.js.map +0 -1
  460. package/dist/types/market.js.map +0 -1
  461. package/dist/types/options.js.map +0 -1
  462. package/dist/types/portfolio.js.map +0 -1
  463. package/dist/types/prediction-markets.js.map +0 -1
  464. package/dist/types/sentiment.js.map +0 -1
  465. package/dist/workflows/compare-assets.js.map +0 -1
  466. package/dist/workflows/index.js.map +0 -1
  467. package/dist/workflows/options-screener.js.map +0 -1
  468. package/dist/workflows/portfolio-builder.js.map +0 -1
  469. package/gui/server/ask-user-bridge.ts +0 -89
  470. package/gui/server/automation-heartbeat.ts +0 -97
  471. package/gui/server/background-quotes.ts +0 -127
  472. package/gui/server/chat-event-adapter.ts +0 -294
  473. package/gui/server/gui-session-manager.ts +0 -5
  474. package/gui/server/http-routes.ts +0 -1201
  475. package/gui/server/invoke-tool.ts +0 -490
  476. package/gui/server/live-chat-event-adapter.ts +0 -243
  477. package/gui/server/local-session-coordinator.ts +0 -97
  478. package/gui/server/market-state-api.ts +0 -331
  479. package/gui/server/model-setup.ts +0 -254
  480. package/gui/server/package.json +0 -5
  481. package/gui/server/private-api-access.ts +0 -62
  482. package/gui/server/projector.ts +0 -392
  483. package/gui/server/prompt-observation.ts +0 -58
  484. package/gui/server/quote-snapshot-store.ts +0 -50
  485. package/gui/server/server.ts +0 -289
  486. package/gui/server/session-actions.ts +0 -323
  487. package/gui/server/session-entry-wait.ts +0 -179
  488. package/gui/server/shutdown.ts +0 -47
  489. package/gui/server/tool-invoke-ack.ts +0 -49
  490. package/gui/server/tool-metadata.ts +0 -167
  491. package/gui/server/websocket.ts +0 -138
  492. package/gui/server/writer-lock.ts +0 -1
  493. package/gui/server/ws-hub.ts +0 -403
  494. package/gui/shared/chat-events.ts +0 -165
  495. package/gui/shared/event-reducer.ts +0 -220
  496. package/gui/web/dist/assets/CatalogOverlay-DZ1niyQm.js +0 -1
  497. package/gui/web/dist/assets/index-D4F9AJnn.css +0 -2
  498. package/gui/web/dist/assets/index-DtqMMBTr.js +0 -65
  499. package/src/analysts/contracts.ts +0 -176
  500. package/src/analysts/orchestrator.ts +0 -244
  501. package/src/cli-main.ts +0 -510
  502. package/src/cli.ts +0 -17
  503. package/src/config.ts +0 -272
  504. package/src/doctor/cli-command.ts +0 -83
  505. package/src/doctor/render.ts +0 -37
  506. package/src/doctor/report.ts +0 -638
  507. package/src/index.ts +0 -5
  508. package/src/infra/cache.ts +0 -127
  509. package/src/infra/freshness.ts +0 -165
  510. package/src/infra/http-client.ts +0 -134
  511. package/src/infra/index.ts +0 -14
  512. package/src/infra/market-calendar.ts +0 -193
  513. package/src/infra/native-dependencies.ts +0 -84
  514. package/src/infra/node-version.ts +0 -23
  515. package/src/infra/open-url.ts +0 -28
  516. package/src/infra/opencandle-paths.ts +0 -53
  517. package/src/infra/rate-limiter.ts +0 -77
  518. package/src/market-state/alert-conditions.ts +0 -82
  519. package/src/market-state/alert-runner.ts +0 -863
  520. package/src/market-state/daily-report.ts +0 -237
  521. package/src/market-state/local-automation-service.ts +0 -162
  522. package/src/market-state/notification-delivery.ts +0 -158
  523. package/src/market-state/resolve-for-mutation.ts +0 -24
  524. package/src/market-state/resolve.ts +0 -112
  525. package/src/market-state/service.ts +0 -2208
  526. package/src/market-state/summaries.ts +0 -75
  527. package/src/memory/index.ts +0 -10
  528. package/src/memory/manager.ts +0 -190
  529. package/src/memory/preference-extractor.ts +0 -106
  530. package/src/memory/retrieval.ts +0 -71
  531. package/src/memory/sqlite.ts +0 -577
  532. package/src/memory/storage.ts +0 -195
  533. package/src/memory/tool-defaults.ts +0 -108
  534. package/src/memory/types.ts +0 -71
  535. package/src/monitor.ts +0 -123
  536. package/src/onboarding/connect.ts +0 -177
  537. package/src/onboarding/credential-interceptor.ts +0 -122
  538. package/src/onboarding/degradation-accumulator.ts +0 -77
  539. package/src/onboarding/prompt-user.ts +0 -85
  540. package/src/onboarding/provider-status.ts +0 -382
  541. package/src/onboarding/providers.ts +0 -442
  542. package/src/onboarding/state.ts +0 -216
  543. package/src/onboarding/tool-helpers.ts +0 -104
  544. package/src/onboarding/tool-tags.ts +0 -244
  545. package/src/onboarding/validation.ts +0 -152
  546. package/src/pi/opencandle-extension.ts +0 -1294
  547. package/src/pi/session-action-dedupe.ts +0 -155
  548. package/src/pi/session-storage.ts +0 -5
  549. package/src/pi/session-writer-lock.ts +0 -426
  550. package/src/pi/session.ts +0 -84
  551. package/src/pi/setup.ts +0 -399
  552. package/src/pi/tool-adapter.ts +0 -49
  553. package/src/pi/tui-session-coordinator.ts +0 -351
  554. package/src/prompts/context-builder.ts +0 -326
  555. package/src/prompts/disclaimer.ts +0 -9
  556. package/src/prompts/policy-cards.ts +0 -228
  557. package/src/prompts/sections.ts +0 -46
  558. package/src/prompts/symbol-preflight.ts +0 -80
  559. package/src/prompts/workflow-prompts.ts +0 -504
  560. package/src/providers/alpha-vantage.ts +0 -340
  561. package/src/providers/coingecko.ts +0 -95
  562. package/src/providers/errors.ts +0 -9
  563. package/src/providers/exa-search.ts +0 -375
  564. package/src/providers/external-tool-command.ts +0 -164
  565. package/src/providers/external-tool-error.ts +0 -20
  566. package/src/providers/fear-greed.ts +0 -45
  567. package/src/providers/finnhub.ts +0 -125
  568. package/src/providers/fred.ts +0 -83
  569. package/src/providers/index.ts +0 -17
  570. package/src/providers/polymarket.ts +0 -214
  571. package/src/providers/provider-credential-error.ts +0 -23
  572. package/src/providers/reddit-cli.ts +0 -286
  573. package/src/providers/reddit.ts +0 -106
  574. package/src/providers/sec-edgar.ts +0 -326
  575. package/src/providers/tradingview.ts +0 -399
  576. package/src/providers/twitter-cli.ts +0 -202
  577. package/src/providers/twitter.ts +0 -102
  578. package/src/providers/web-search.ts +0 -303
  579. package/src/providers/with-fallback.ts +0 -42
  580. package/src/providers/wrap-provider.ts +0 -105
  581. package/src/providers/yahoo-finance.ts +0 -984
  582. package/src/routing/classify-intent.ts +0 -380
  583. package/src/routing/defaults.ts +0 -29
  584. package/src/routing/entity-extractor.ts +0 -557
  585. package/src/routing/fund-symbols.ts +0 -58
  586. package/src/routing/horizon.ts +0 -7
  587. package/src/routing/index.ts +0 -70
  588. package/src/routing/legacy-rule-router.ts +0 -13
  589. package/src/routing/planning.ts +0 -829
  590. package/src/routing/route-manifest.ts +0 -308
  591. package/src/routing/router-llm-client.ts +0 -64
  592. package/src/routing/router-prompt.ts +0 -159
  593. package/src/routing/router-types.ts +0 -84
  594. package/src/routing/router.ts +0 -1332
  595. package/src/routing/slot-resolver.ts +0 -213
  596. package/src/routing/symbol-disambiguator.ts +0 -72
  597. package/src/routing/turn-context.ts +0 -108
  598. package/src/routing/types.ts +0 -77
  599. package/src/runtime/answer-contracts.ts +0 -693
  600. package/src/runtime/artifact-contracts.ts +0 -77
  601. package/src/runtime/evidence.ts +0 -78
  602. package/src/runtime/numeric-claims.ts +0 -108
  603. package/src/runtime/planning-evidence.ts +0 -597
  604. package/src/runtime/prompt-step.ts +0 -185
  605. package/src/runtime/provider-tracker.ts +0 -40
  606. package/src/runtime/run-context.ts +0 -32
  607. package/src/runtime/session-coordinator.ts +0 -1037
  608. package/src/runtime/session-title.ts +0 -60
  609. package/src/runtime/tool-defaults-wrapper.ts +0 -43
  610. package/src/runtime/validation.ts +0 -211
  611. package/src/runtime/workflow-events.ts +0 -77
  612. package/src/runtime/workflow-runner.ts +0 -182
  613. package/src/runtime/workflow-types.ts +0 -105
  614. package/src/sentiment/adapters/finnhub.ts +0 -49
  615. package/src/sentiment/adapters/reddit.ts +0 -65
  616. package/src/sentiment/adapters/twitter.ts +0 -36
  617. package/src/sentiment/adapters/web.ts +0 -44
  618. package/src/sentiment/index.ts +0 -49
  619. package/src/sentiment/insights.ts +0 -269
  620. package/src/sentiment/keywords.ts +0 -31
  621. package/src/sentiment/pipeline.ts +0 -91
  622. package/src/sentiment/scorer.ts +0 -89
  623. package/src/sentiment/store.ts +0 -260
  624. package/src/sentiment/trends.ts +0 -96
  625. package/src/sentiment/types.ts +0 -112
  626. package/src/system-prompt.ts +0 -115
  627. package/src/tool-kit.ts +0 -69
  628. package/src/tools/AGENTS.md +0 -36
  629. package/src/tools/fundamentals/company-overview.ts +0 -64
  630. package/src/tools/fundamentals/comps.ts +0 -180
  631. package/src/tools/fundamentals/dcf.ts +0 -447
  632. package/src/tools/fundamentals/earnings.ts +0 -57
  633. package/src/tools/fundamentals/financials.ts +0 -63
  634. package/src/tools/fundamentals/sec-filings.ts +0 -105
  635. package/src/tools/index.ts +0 -104
  636. package/src/tools/interaction/ask-user.ts +0 -93
  637. package/src/tools/macro/event-probabilities.ts +0 -141
  638. package/src/tools/macro/fear-greed.ts +0 -41
  639. package/src/tools/macro/fred-data.ts +0 -92
  640. package/src/tools/market/crypto-history.ts +0 -72
  641. package/src/tools/market/crypto-price.ts +0 -65
  642. package/src/tools/market/screen-stocks.ts +0 -290
  643. package/src/tools/market/search-ticker.ts +0 -254
  644. package/src/tools/market/stock-history.ts +0 -104
  645. package/src/tools/market/stock-quote.ts +0 -73
  646. package/src/tools/options/greeks.ts +0 -81
  647. package/src/tools/options/option-chain.ts +0 -134
  648. package/src/tools/portfolio/alerts.ts +0 -457
  649. package/src/tools/portfolio/correlation.ts +0 -189
  650. package/src/tools/portfolio/daily-report.ts +0 -107
  651. package/src/tools/portfolio/holdings-overlap.ts +0 -139
  652. package/src/tools/portfolio/notifications.ts +0 -45
  653. package/src/tools/portfolio/risk-analysis.ts +0 -173
  654. package/src/tools/portfolio/tracker.ts +0 -308
  655. package/src/tools/portfolio/watchlist.ts +0 -288
  656. package/src/tools/sentiment/insight-format.ts +0 -50
  657. package/src/tools/sentiment/query-match.ts +0 -117
  658. package/src/tools/sentiment/reddit-sentiment.ts +0 -403
  659. package/src/tools/sentiment/sentiment-summary.ts +0 -383
  660. package/src/tools/sentiment/sentiment-trend.ts +0 -75
  661. package/src/tools/sentiment/twitter-sentiment.ts +0 -287
  662. package/src/tools/sentiment/untrusted-text.ts +0 -21
  663. package/src/tools/sentiment/web-search.ts +0 -186
  664. package/src/tools/sentiment/web-sentiment.ts +0 -96
  665. package/src/tools/technical/backtest.ts +0 -336
  666. package/src/tools/technical/indicators.ts +0 -281
  667. package/src/types/fundamentals.ts +0 -47
  668. package/src/types/index.ts +0 -26
  669. package/src/types/macro.ts +0 -27
  670. package/src/types/market.ts +0 -46
  671. package/src/types/options.ts +0 -53
  672. package/src/types/portfolio.ts +0 -83
  673. package/src/types/prediction-markets.ts +0 -13
  674. package/src/types/sentiment.ts +0 -129
  675. package/src/workflows/compare-assets.ts +0 -89
  676. package/src/workflows/index.ts +0 -3
  677. package/src/workflows/options-screener.ts +0 -125
  678. package/src/workflows/portfolio-builder.ts +0 -63
@@ -1,308 +0,0 @@
1
- import type { MemoryCategory } from "../memory/types.js";
2
- import type { RouterOutput, RouterRoute, RouterRouteKind, ToolBundleName } from "./router-types.js";
3
- import type { ExtractedEntities, WorkflowType } from "./types.js";
4
-
5
- export const ROUTE_KINDS: readonly RouterRouteKind[] = [
6
- "workflow_dispatch",
7
- "agent_task",
8
- "clarification",
9
- "pass_through",
10
- ];
11
-
12
- export const TOOL_BUNDLE_TOOLS: Record<ToolBundleName, readonly string[]> = {
13
- core_market: [
14
- "search_ticker",
15
- "get_stock_quote",
16
- "get_stock_history",
17
- "screen_stocks",
18
- "get_crypto_price",
19
- "get_crypto_history",
20
- "get_company_overview",
21
- "get_financials",
22
- "get_earnings",
23
- "compare_companies",
24
- "compute_dcf",
25
- "get_technical_indicators",
26
- "backtest_strategy",
27
- "analyze_risk",
28
- "analyze_correlation",
29
- "analyze_holdings_overlap",
30
- "track_portfolio",
31
- "manage_watchlist",
32
- "manage_alerts",
33
- "daily_watchlist_report",
34
- "manage_notifications",
35
- "search_web",
36
- ],
37
- options: ["get_option_chain", "get_stock_quote", "search_ticker", "search_web"],
38
- macro: ["get_economic_data", "get_event_probabilities", "get_fear_greed", "search_web"],
39
- sentiment: [
40
- "get_reddit_sentiment",
41
- "get_twitter_sentiment",
42
- "get_web_sentiment",
43
- "get_sentiment_trend",
44
- "get_sentiment_summary",
45
- "get_fear_greed",
46
- "search_web",
47
- ],
48
- sec: ["get_sec_filings", "get_company_overview", "search_web"],
49
- clarification: ["ask_user"],
50
- };
51
-
52
- export type PromptPlaybookId =
53
- | "workflow_dispatch"
54
- | "agent_task"
55
- | "clarification"
56
- | "pass_through";
57
-
58
- interface RouteCapability {
59
- routeKind: RouterRouteKind;
60
- legacyRoute: RouterRoute;
61
- promptPlaybook: PromptPlaybookId;
62
- toolBundles: ToolBundleName[];
63
- memoryScopes: MemoryCategory[];
64
- allowWorkflow: boolean;
65
- }
66
-
67
- interface WorkflowCapability {
68
- workflow: Exclude<WorkflowType, "unclassified">;
69
- dispatchable: boolean;
70
- requiredSlots: string[];
71
- toolBundles: ToolBundleName[];
72
- memoryScopes: MemoryCategory[];
73
- promptPlaybook: PromptPlaybookId;
74
- }
75
-
76
- export const ROUTE_CAPABILITY_MANIFEST: Record<RouterRouteKind, RouteCapability> = {
77
- workflow_dispatch: {
78
- routeKind: "workflow_dispatch",
79
- legacyRoute: "workflow",
80
- promptPlaybook: "workflow_dispatch",
81
- toolBundles: ["core_market"],
82
- memoryScopes: ["investor_profile", "workflow_history"],
83
- allowWorkflow: true,
84
- },
85
- agent_task: {
86
- routeKind: "agent_task",
87
- legacyRoute: "fallback",
88
- promptPlaybook: "agent_task",
89
- toolBundles: ["core_market"],
90
- memoryScopes: ["investor_profile", "workflow_history"],
91
- allowWorkflow: false,
92
- },
93
- clarification: {
94
- routeKind: "clarification",
95
- legacyRoute: "fallback",
96
- promptPlaybook: "clarification",
97
- toolBundles: ["clarification"],
98
- memoryScopes: ["investor_profile", "workflow_history"],
99
- allowWorkflow: true,
100
- },
101
- pass_through: {
102
- routeKind: "pass_through",
103
- legacyRoute: "fallback",
104
- promptPlaybook: "pass_through",
105
- toolBundles: [],
106
- memoryScopes: [],
107
- allowWorkflow: false,
108
- },
109
- };
110
-
111
- export const WORKFLOW_CAPABILITY_MANIFEST: Record<
112
- Exclude<WorkflowType, "unclassified">,
113
- WorkflowCapability
114
- > = {
115
- portfolio_builder: {
116
- workflow: "portfolio_builder",
117
- dispatchable: true,
118
- requiredSlots: ["budget"],
119
- toolBundles: ["core_market", "macro", "sentiment", "clarification"],
120
- memoryScopes: ["investor_profile", "interaction_feedback", "workflow_history"],
121
- promptPlaybook: "workflow_dispatch",
122
- },
123
- options_screener: {
124
- workflow: "options_screener",
125
- dispatchable: true,
126
- requiredSlots: ["symbol"],
127
- toolBundles: ["core_market", "options", "sentiment", "clarification"],
128
- memoryScopes: ["investor_profile", "interaction_feedback", "workflow_history"],
129
- promptPlaybook: "workflow_dispatch",
130
- },
131
- compare_assets: {
132
- workflow: "compare_assets",
133
- dispatchable: true,
134
- requiredSlots: ["symbols"],
135
- toolBundles: ["core_market", "macro", "sentiment", "clarification"],
136
- memoryScopes: ["investor_profile", "workflow_history"],
137
- promptPlaybook: "workflow_dispatch",
138
- },
139
- single_asset_analysis: {
140
- workflow: "single_asset_analysis",
141
- dispatchable: false,
142
- requiredSlots: ["symbol"],
143
- toolBundles: ["core_market", "options", "sentiment", "sec", "clarification"],
144
- memoryScopes: ["investor_profile", "workflow_history"],
145
- promptPlaybook: "agent_task",
146
- },
147
- watchlist_or_tracking: {
148
- workflow: "watchlist_or_tracking",
149
- dispatchable: false,
150
- requiredSlots: [],
151
- toolBundles: ["core_market", "clarification"],
152
- memoryScopes: ["investor_profile", "workflow_history"],
153
- promptPlaybook: "agent_task",
154
- },
155
- general_finance_qa: {
156
- workflow: "general_finance_qa",
157
- dispatchable: false,
158
- requiredSlots: [],
159
- toolBundles: ["core_market", "macro", "sentiment", "sec", "clarification"],
160
- memoryScopes: ["investor_profile", "workflow_history"],
161
- promptPlaybook: "agent_task",
162
- },
163
- };
164
-
165
- export function isRouteKind(value: string): value is RouterRouteKind {
166
- return ROUTE_KINDS.includes(value as RouterRouteKind);
167
- }
168
-
169
- export function isToolBundleName(value: string): value is ToolBundleName {
170
- return Object.hasOwn(TOOL_BUNDLE_TOOLS, value);
171
- }
172
-
173
- export function legacyRouteForRouteKind(routeKind: RouterRouteKind): RouterRoute {
174
- return ROUTE_CAPABILITY_MANIFEST[routeKind].legacyRoute;
175
- }
176
-
177
- export function isDispatchableWorkflow(
178
- workflow: Exclude<WorkflowType, "unclassified"> | undefined,
179
- ): boolean {
180
- if (!workflow) return false;
181
- return WORKFLOW_CAPABILITY_MANIFEST[workflow]?.dispatchable === true;
182
- }
183
-
184
- export function routeKindFromLegacyRoute(
185
- route: RouterRoute,
186
- missingRequired: readonly string[] = [],
187
- ): RouterRouteKind {
188
- if (missingRequired.length > 0) return "clarification";
189
- return route === "workflow" ? "workflow_dispatch" : "agent_task";
190
- }
191
-
192
- export function workflowRequiredSlots(
193
- workflow: Exclude<WorkflowType, "unclassified"> | undefined,
194
- ): string[] {
195
- if (!workflow) return [];
196
- return WORKFLOW_CAPABILITY_MANIFEST[workflow]?.requiredSlots ?? [];
197
- }
198
-
199
- export function computeMissingRequiredSlots(
200
- workflow: Exclude<WorkflowType, "unclassified"> | undefined,
201
- entities: ExtractedEntities,
202
- slots: RouterOutput["slots"] = {},
203
- existingMissing: readonly string[] = [],
204
- ): string[] {
205
- const missing = new Set<string>();
206
- const existing = new Set(existingMissing);
207
- for (const slot of workflowRequiredSlots(workflow)) {
208
- if (slot === "budget" && entities.budget === undefined && !slotHasValue(slots.budget)) {
209
- missing.add("budget");
210
- }
211
- if (slot === "symbol" && entities.symbols.length === 0 && !slotHasValue(slots.symbol)) {
212
- missing.add("symbol");
213
- }
214
- if (
215
- slot === "symbols" &&
216
- entities.symbols.length < 2 &&
217
- !slotHasSymbolListValue(slots.symbols, 2)
218
- ) {
219
- missing.add("symbols");
220
- }
221
- existing.delete(slot);
222
- }
223
- for (const slot of existing) {
224
- if (!slotHasValue(slots[slot])) missing.add(slot);
225
- }
226
- return Array.from(missing);
227
- }
228
-
229
- function slotHasValue(slot: RouterOutput["slots"][string] | undefined): boolean {
230
- if (!slot) return false;
231
- if (Array.isArray(slot.value)) return slot.value.length > 0;
232
- return slot.value !== undefined && slot.value !== null && slot.value !== "";
233
- }
234
-
235
- function slotHasSymbolListValue(
236
- slot: RouterOutput["slots"][string] | undefined,
237
- minLength: number,
238
- ): boolean {
239
- if (!slot) return false;
240
- if (Array.isArray(slot.value))
241
- return slot.value.filter((value) => typeof value === "string").length >= minLength;
242
- return false;
243
- }
244
-
245
- export function selectToolBundles(
246
- output: Pick<RouterOutput, "routeKind" | "workflow" | "entities">,
247
- ): ToolBundleName[] {
248
- if (output.routeKind === "pass_through") return [];
249
- if (output.routeKind === "clarification") return ["clarification"];
250
-
251
- const bundles = new Set<ToolBundleName>();
252
- const routeBundles = ROUTE_CAPABILITY_MANIFEST[output.routeKind]?.toolBundles ?? [];
253
- for (const bundle of routeBundles) {
254
- bundles.add(bundle);
255
- }
256
-
257
- if (output.workflow) {
258
- const workflow = WORKFLOW_CAPABILITY_MANIFEST[output.workflow];
259
- if (workflow) {
260
- for (const bundle of workflow.toolBundles) {
261
- bundles.add(bundle);
262
- }
263
- }
264
- }
265
-
266
- const metrics = output.entities.compareMetrics ?? [];
267
- const horizon = output.entities.timeHorizon ?? "";
268
- if (
269
- metrics.includes("macro_hedge") ||
270
- metrics.includes("interest_rates") ||
271
- /\b(?:macro|rate|inflation)\b/i.test(horizon)
272
- ) {
273
- bundles.add("macro");
274
- }
275
-
276
- if (output.entities.symbols.length > 0) {
277
- bundles.add("core_market");
278
- }
279
- if (output.entities.optionStrategy) {
280
- bundles.add("options");
281
- }
282
-
283
- return Array.from(bundles);
284
- }
285
-
286
- export function activeToolsForBundles(
287
- bundles: readonly ToolBundleName[],
288
- availableToolNames?: readonly string[],
289
- ): string[] {
290
- const selected = new Set<string>();
291
- for (const bundle of bundles) {
292
- for (const tool of TOOL_BUNDLE_TOOLS[bundle] ?? []) {
293
- selected.add(tool);
294
- }
295
- }
296
-
297
- if (!availableToolNames) return Array.from(selected);
298
- const available = new Set(availableToolNames);
299
- return Array.from(selected).filter((tool) => available.has(tool));
300
- }
301
-
302
- export function memoryScopesForRoute(
303
- routeKind: RouterRouteKind,
304
- workflow?: Exclude<WorkflowType, "unclassified">,
305
- ): MemoryCategory[] {
306
- if (workflow) return WORKFLOW_CAPABILITY_MANIFEST[workflow]?.memoryScopes ?? [];
307
- return ROUTE_CAPABILITY_MANIFEST[routeKind]?.memoryScopes ?? [];
308
- }
@@ -1,64 +0,0 @@
1
- import type { Model } from "@earendil-works/pi-ai";
2
- import { completeSimple } from "@earendil-works/pi-ai/compat";
3
- import type { RouterLlmClient } from "./router-types.js";
4
-
5
- type CompleteSimpleResponse = Awaited<ReturnType<typeof completeSimple>>;
6
-
7
- /**
8
- * Build a router LLM client backed by pi-ai's `completeSimple`. The client
9
- * is intentionally thin: prompt in, raw text out. Schema validation and
10
- * retry logic live in `router.ts`.
11
- *
12
- * Zero tools are passed — the router operates on text alone. Temperature
13
- * is pinned low for structured-output stability.
14
- */
15
- export function createPiAiRouterClient(
16
- model: Model<"anthropic-messages"> | Model<any>,
17
- ): RouterLlmClient {
18
- return {
19
- async complete(prompt: string): Promise<string> {
20
- const request = {
21
- messages: [
22
- {
23
- role: "user" as const,
24
- content: prompt,
25
- timestamp: Date.now(),
26
- },
27
- ],
28
- // Explicitly no tools — spec requirement.
29
- tools: [],
30
- };
31
- const options = {
32
- temperature: 0,
33
- maxTokens: 2000,
34
- reasoning: "minimal" as const,
35
- };
36
- let response: CompleteSimpleResponse;
37
- try {
38
- response = await completeSimple(model, request, options);
39
- } catch (error) {
40
- if (!isUnsupportedTemperatureError(error)) throw error;
41
- const { temperature: _temperature, ...retryOptions } = options;
42
- response = await completeSimple(model, request, retryOptions);
43
- }
44
-
45
- if (response.stopReason === "error" || response.stopReason === "aborted") {
46
- throw new Error(`router LLM call failed: ${response.errorMessage ?? response.stopReason}`);
47
- }
48
-
49
- const text = response.content
50
- .filter((c): c is { type: "text"; text: string } => c.type === "text")
51
- .map((c) => c.text)
52
- .join("");
53
- if (!text) {
54
- throw new Error("router LLM call returned no text content");
55
- }
56
- return text;
57
- },
58
- };
59
- }
60
-
61
- function isUnsupportedTemperatureError(error: unknown): boolean {
62
- const message = error instanceof Error ? error.message : String(error);
63
- return /unsupported parameter/i.test(message) && /temperature/i.test(message);
64
- }
@@ -1,159 +0,0 @@
1
- import { ROUTE_CAPABILITY_MANIFEST, WORKFLOW_CAPABILITY_MANIFEST } from "./route-manifest.js";
2
- import type { RouterInputContext } from "./router-types.js";
3
-
4
- /**
5
- * Privacy note — priorTurns rendering:
6
- * Conversational text rendered into the router prompt via `priorTurns` is NOT
7
- * filtered by `src/memory/types.ts::NEVER_TRUST_FROM_MEMORY` (which governs
8
- * structured market-sensitive memory keys such as `stock_price` and
9
- * `target_price`). A future `/forget` command is the designated scrubbing
10
- * primitive for removing or masking matching entries from the session branch
11
- * so they no longer reach the router. See
12
- * `openspec/changes/router-context-and-observability/` for the follow-up.
13
- */
14
-
15
- function renderCatalog(): string {
16
- const descriptions: Record<string, string> = {
17
- portfolio_builder: "user asks to build/allocate a portfolio, invest a budget across positions",
18
- options_screener: "user asks for options trades / calls / puts on a specific ticker",
19
- compare_assets: "user asks to compare two or more symbols (vs / versus / which is better)",
20
- single_asset_analysis:
21
- "user asks for a full analysis / deep dive / 'is X attractive' on ONE symbol",
22
- watchlist_or_tracking: "user manages or asks about their saved watchlist or tracked positions",
23
- general_finance_qa:
24
- "definitional / conceptual questions plus broad market structure, sector, industry, monetary policy, and emerging markets research",
25
- };
26
-
27
- return Object.values(WORKFLOW_CAPABILITY_MANIFEST)
28
- .map((w) => {
29
- const required =
30
- w.requiredSlots.length > 0 ? ` [required: ${w.requiredSlots.join(", ")}]` : "";
31
- const mode = w.dispatchable ? "dispatchable workflow" : "agent-task workflow label";
32
- return `- "${w.workflow}" (${mode}): ${descriptions[w.workflow]}${required}`;
33
- })
34
- .join("\n");
35
- }
36
-
37
- function renderRouteKinds(): string {
38
- return Object.values(ROUTE_CAPABILITY_MANIFEST)
39
- .map((route) => `- "${route.routeKind}" -> legacy route "${route.legacyRoute}"`)
40
- .join("\n");
41
- }
42
-
43
- function renderProfile(profile: Record<string, unknown>): string {
44
- const entries = Object.entries(profile);
45
- if (entries.length === 0) return "(empty)";
46
- return entries.map(([k, v]) => `- ${k}: ${JSON.stringify(v)}`).join("\n");
47
- }
48
-
49
- function renderPriorTurns(turns: Array<{ role: "user" | "assistant"; text: string }>): string {
50
- if (turns.length === 0) return "(none)";
51
- return turns.map((t) => `[${t.role}] ${t.text.replace(/\n+/g, " ").slice(0, 400)}`).join("\n");
52
- }
53
-
54
- function renderRecentRuns(
55
- runs: Array<{
56
- workflowType: string;
57
- turnType: string;
58
- resolvedSlots?: Record<string, unknown>;
59
- createdAt: string;
60
- }>,
61
- ): string {
62
- if (runs.length === 0) return "(none)";
63
- return runs
64
- .map(
65
- (r) =>
66
- `- ${r.createdAt} ${r.turnType}/${r.workflowType} ${r.resolvedSlots ? JSON.stringify(r.resolvedSlots) : ""}`,
67
- )
68
- .join("\n");
69
- }
70
-
71
- const SCHEMA_SPEC = `You MUST respond with a SINGLE JSON object and nothing else (no markdown fences, no prose outside the JSON). The object MUST conform to this TypeScript interface exactly:
72
-
73
- interface RouterOutput {
74
- routeKind: "workflow_dispatch" | "agent_task" | "clarification" | "pass_through";
75
- route: "workflow" | "fallback";
76
- workflow?: "portfolio_builder" | "options_screener" | "compare_assets" | "single_asset_analysis" | "watchlist_or_tracking" | "general_finance_qa";
77
- entities: {
78
- symbols: string[]; // UPPERCASE tickers the user mentioned or implied
79
- budget?: number; // dollar amount if user stated one
80
- maxPremium?: number;
81
- timeHorizon?: string; // e.g. "6mo", "1y_plus", "short", "long"
82
- riskProfile?: string; // "conservative" | "balanced" | "aggressive"
83
- direction?: "bullish" | "bearish";
84
- dteHint?: string;
85
- optionStrategy?: "covered_call" | "protective_put"; // set when user explicitly asks for a known option strategy
86
- heldSymbol?: string; // for covered calls/protective puts: ticker the user owns/holds
87
- catalystSymbols?: string[]; // tickers mentioned as event/catalyst context, not the option-chain underlying
88
- costBasis?: number; // per-share basis when user says "cost basis is $X"
89
- shareQuantity?: number; // number of shares owned when stated, e.g. "200 shares"
90
- compareMetrics?: string[]; // optional compare focus tags, e.g. "sentiment", "macro_hedge"
91
- };
92
- slots: Record<string, {
93
- value: unknown;
94
- source: "user" | "preference" | "default" | "prior_context" | "memory";
95
- confidence: "high" | "medium" | "low";
96
- }>;
97
- preference_updates: Array<{
98
- key: string; // e.g. "risk_profile", "time_horizon", "asset_scope", "options_liquidity"
99
- value: string;
100
- confidence: "high" | "medium" | "low";
101
- source: "inferred";
102
- }>;
103
- missing_required: string[]; // required slot names the turn/profile/defaults did not fill
104
- tool_bundles: Array<"core_market" | "options" | "macro" | "sentiment" | "sec" | "clarification">;
105
- diagnostics: Array<{ code: string; message: string }>;
106
- reasoning: string; // one or two short sentences; used for debugging only
107
- }`;
108
-
109
- const ROUTING_RULES = `Routing rules:
110
- - Choose routeKind = "workflow_dispatch" ONLY when the turn clearly matches a dispatchable workflow (portfolio_builder, options_screener, or compare_assets) AND required slots are filled from the turn, trusted prior context, or profile snapshot.
111
- - For single_asset_analysis, watchlist_or_tracking, and general_finance_qa, set routeKind = "agent_task" even when you set the workflow label. These are workflow labels for prompt/tool policy, not structured workflow dispatch.
112
- - Choose routeKind = "agent_task" for in-scope finance work that should be answered by the main agent, including simple data fetches like "AAPL quote" and open-ended questions like "entry levels on ASTS for 6 months".
113
- - Choose routeKind = "clarification" when required slots are missing (e.g. options workflow needs a symbol, portfolio needs a budget). List specific slot names in missing_required. The main agent will use ask_user to collect them.
114
- - Choose routeKind = "pass_through" when the request is outside OpenCandle's finance task surface.
115
- - Set legacy route = "workflow" only for routeKind = "workflow_dispatch"; otherwise set legacy route = "fallback".
116
- - DO NOT invent a "direct_tool" route. Tool execution belongs to the main agent.
117
- - For covered call prompts, distinguish the owned underlying from catalyst tickers. Put the owned symbol first in symbols, set heldSymbol to the owned symbol, put event/context tickers in catalystSymbols, set workflow="options_screener", and preserve costBasis if stated.
118
- - For protective put prompts, treat the owned/held ticker as the option-chain underlying, set optionStrategy="protective_put", direction="bearish", and preserve shareQuantity if stated. This is a hedge on an existing long share position, not a bullish call screen.
119
- - Source attribution rules (per-slot source field):
120
- - source = "user": the value came from THIS turn's text.
121
- - source = "preference": the value came from profileSnapshot (not this turn).
122
- - source = "default": a sensible default was applied (workflow fallback).
123
- - source = "prior_context": the value came from prior conversation turns.
124
- - source = "memory": the value came from retrieved non-profile memory.
125
- - Preference updates:
126
- - Emit preference_updates ONLY for stable user-dispositions stated (or very strongly implied) in the current turn. E.g. "I'm aggressive" → risk_profile=aggressive, high.
127
- - Do NOT emit preference_updates that merely echo profileSnapshot.
128
- - Only confidence="high" updates will be persisted; medium/low are logged but dropped.
129
- - You have NO tools. Do not request tool execution. Classify on text alone.`;
130
-
131
- export function buildRouterPrompt(input: RouterInputContext): string {
132
- return `You are OpenCandle's routing agent. Your job is to classify the user's turn into one of the known workflows (or fallback), extract entities + per-slot provenance, and surface any stable preferences the user expressed. Your output feeds the main analyst agent — it does NOT go to the user.
133
-
134
- ROUTE KINDS:
135
- ${renderRouteKinds()}
136
-
137
- WORKFLOW CATALOG:
138
- ${renderCatalog()}
139
-
140
- ${SCHEMA_SPEC}
141
-
142
- ${ROUTING_RULES}
143
-
144
- --- CONTEXT ---
145
-
146
- Profile snapshot (persisted preferences from prior sessions):
147
- ${renderProfile(input.profileSnapshot)}
148
-
149
- Recent workflow runs (most recent last):
150
- ${renderRecentRuns(input.recentWorkflowRuns)}
151
-
152
- Prior conversation turns (most recent last):
153
- ${renderPriorTurns(input.priorTurns)}
154
-
155
- --- CURRENT TURN ---
156
- ${input.text}
157
-
158
- Respond with the JSON object. Nothing else.`;
159
- }
@@ -1,84 +0,0 @@
1
- import type { ExtractedEntities, SlotSource, WorkflowType } from "./types.js";
2
-
3
- export type RouterRoute = "workflow" | "fallback";
4
- export type RouterRouteKind = "workflow_dispatch" | "agent_task" | "clarification" | "pass_through";
5
-
6
- export type ToolBundleName =
7
- | "core_market"
8
- | "options"
9
- | "macro"
10
- | "sentiment"
11
- | "sec"
12
- | "clarification";
13
-
14
- export type RouterConfidence = "high" | "medium" | "low";
15
-
16
- export interface RouterSlot {
17
- value: unknown;
18
- source: SlotSource;
19
- confidence: RouterConfidence;
20
- }
21
-
22
- export interface RouterPreferenceUpdate {
23
- key: string;
24
- value: string;
25
- confidence: RouterConfidence;
26
- source: "inferred";
27
- }
28
-
29
- export interface RouterDiagnostic {
30
- code: string;
31
- message: string;
32
- details?: Record<string, unknown>;
33
- }
34
-
35
- /**
36
- * Structured output from the LLM router. Mirrors existing types
37
- * (`ClassificationResult`, `ExtractedEntities`, `SlotSource`) so downstream
38
- * consumers can branch without a new vocabulary.
39
- *
40
- * `workflow` is only meaningful when `route === "workflow"`. For `fallback`
41
- * routes, `workflow_type` at the storage layer is the sentinel `"fallback"`.
42
- */
43
- export interface RouterOutput {
44
- routeKind: RouterRouteKind;
45
- route: RouterRoute;
46
- workflow?: Exclude<WorkflowType, "unclassified">;
47
- entities: ExtractedEntities;
48
- slots: Record<string, RouterSlot>;
49
- preference_updates: RouterPreferenceUpdate[];
50
- missing_required: string[];
51
- tool_bundles: ToolBundleName[];
52
- diagnostics: RouterDiagnostic[];
53
- reasoning: string;
54
- }
55
-
56
- /** Context passed into the router on each turn. */
57
- export interface RouterInputContext {
58
- /** Raw user text from `pi.on("input")`. */
59
- text: string;
60
- /** Last 5 user/assistant turns (most recent last). */
61
- priorTurns: Array<{ role: "user" | "assistant"; text: string }>;
62
- /** Current investor_profile snapshot retrieved from preferences storage. */
63
- profileSnapshot: Record<string, unknown>;
64
- /** Last 3 workflow_runs, compact summaries. */
65
- recentWorkflowRuns: Array<{
66
- workflowType: string;
67
- turnType: string;
68
- resolvedSlots?: Record<string, unknown>;
69
- createdAt: string;
70
- }>;
71
- }
72
-
73
- /**
74
- * Abstract LLM client used by the router. Injected by callers so unit tests
75
- * can supply a deterministic mock. The real implementation (see
76
- * `src/routing/router-llm-client.ts`) wraps pi-ai's `completeSimple`.
77
- */
78
- export interface RouterLlmClient {
79
- /**
80
- * Run a single prompt → text completion. Router parses the returned text
81
- * as JSON; the client is not responsible for structured-output parsing.
82
- */
83
- complete(prompt: string): Promise<string>;
84
- }