opencandle 0.11.0 → 0.12.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 (663) hide show
  1. package/README.md +25 -28
  2. package/dist/analysts/contracts.js +0 -1
  3. package/dist/analysts/orchestrator.d.ts +2 -0
  4. package/dist/analysts/orchestrator.js +19 -1
  5. package/dist/cli-main.js +13 -7
  6. package/dist/cli-options.d.ts +4 -0
  7. package/dist/cli-options.js +33 -0
  8. package/dist/cli.js +8 -3
  9. package/dist/config.js +0 -1
  10. package/dist/doctor/cli-command.js +2 -1
  11. package/dist/doctor/render.js +0 -1
  12. package/dist/doctor/report.js +41 -12
  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 +263 -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/http-routes.d.ts +69 -0
  24. package/dist/gui/server/http-routes.js +1008 -0
  25. package/dist/gui/server/invoke-tool.d.ts +47 -0
  26. package/dist/gui/server/invoke-tool.js +373 -0
  27. package/dist/gui/server/live-chat-event-adapter.d.ts +19 -0
  28. package/dist/gui/server/live-chat-event-adapter.js +206 -0
  29. package/dist/gui/server/local-session-coordinator.d.ts +26 -0
  30. package/dist/gui/server/local-session-coordinator.js +53 -0
  31. package/dist/gui/server/market-state-api.d.ts +138 -0
  32. package/dist/gui/server/market-state-api.js +355 -0
  33. package/dist/gui/server/model-setup.d.ts +64 -0
  34. package/dist/gui/server/model-setup.js +150 -0
  35. package/dist/gui/server/private-api-access.d.ts +6 -0
  36. package/dist/gui/server/private-api-access.js +53 -0
  37. package/dist/gui/server/projector.d.ts +49 -0
  38. package/dist/gui/server/projector.js +296 -0
  39. package/dist/gui/server/prompt-observation.d.ts +8 -0
  40. package/dist/gui/server/prompt-observation.js +43 -0
  41. package/dist/gui/server/quote-snapshot-store.d.ts +14 -0
  42. package/dist/gui/server/quote-snapshot-store.js +49 -0
  43. package/dist/gui/server/server.d.ts +1 -0
  44. package/dist/gui/server/server.js +259 -0
  45. package/dist/gui/server/session-actions.d.ts +60 -0
  46. package/dist/gui/server/session-actions.js +218 -0
  47. package/dist/gui/server/session-entry-wait.d.ts +27 -0
  48. package/dist/gui/server/session-entry-wait.js +129 -0
  49. package/dist/gui/server/session-list.d.ts +2 -0
  50. package/dist/gui/server/session-list.js +11 -0
  51. package/dist/gui/server/shutdown.d.ts +10 -0
  52. package/dist/gui/server/shutdown.js +29 -0
  53. package/dist/gui/server/tool-invoke-ack.d.ts +17 -0
  54. package/dist/gui/server/tool-invoke-ack.js +26 -0
  55. package/dist/gui/server/tool-metadata.d.ts +93 -0
  56. package/dist/gui/server/tool-metadata.js +148 -0
  57. package/dist/gui/server/websocket.d.ts +9 -0
  58. package/dist/gui/server/websocket.js +124 -0
  59. package/dist/gui/server/writer-lock.d.ts +1 -0
  60. package/dist/gui/server/writer-lock.js +1 -0
  61. package/dist/gui/server/ws-hub.d.ts +50 -0
  62. package/dist/gui/server/ws-hub.js +284 -0
  63. package/dist/gui/shared/chat-events.d.ts +174 -0
  64. package/dist/gui/shared/chat-events.js +13 -0
  65. package/dist/gui/shared/event-reducer.d.ts +3 -0
  66. package/dist/gui/shared/event-reducer.js +187 -0
  67. package/dist/index.js +0 -1
  68. package/dist/infra/cache.d.ts +6 -0
  69. package/dist/infra/cache.js +16 -7
  70. package/dist/infra/freshness.d.ts +21 -0
  71. package/dist/infra/freshness.js +118 -0
  72. package/dist/infra/http-client.js +1 -2
  73. package/dist/infra/index.js +0 -1
  74. package/dist/infra/market-calendar.d.ts +14 -0
  75. package/dist/infra/market-calendar.js +136 -0
  76. package/dist/infra/native-dependencies.js +0 -1
  77. package/dist/infra/node-version.js +0 -1
  78. package/dist/infra/open-url.js +0 -1
  79. package/dist/infra/opencandle-paths.js +0 -1
  80. package/dist/infra/rate-limiter.js +1 -1
  81. package/dist/market-state/alert-conditions.js +0 -1
  82. package/dist/market-state/alert-runner.d.ts +1 -0
  83. package/dist/market-state/alert-runner.js +5 -4
  84. package/dist/market-state/daily-report.js +0 -1
  85. package/dist/market-state/local-automation-service.js +0 -1
  86. package/dist/market-state/notification-delivery.js +0 -1
  87. package/dist/market-state/resolve-for-mutation.js +0 -1
  88. package/dist/market-state/resolve.js +0 -1
  89. package/dist/market-state/service.d.ts +26 -21
  90. package/dist/market-state/service.js +175 -36
  91. package/dist/market-state/summaries.d.ts +8 -0
  92. package/dist/market-state/summaries.js +58 -0
  93. package/dist/memory/index.js +0 -1
  94. package/dist/memory/manager.js +0 -1
  95. package/dist/memory/preference-extractor.js +0 -1
  96. package/dist/memory/retrieval.js +0 -1
  97. package/dist/memory/sqlite.js +60 -11
  98. package/dist/memory/storage.js +0 -1
  99. package/dist/memory/tool-defaults.js +0 -1
  100. package/dist/memory/types.js +0 -1
  101. package/dist/monitor.js +0 -1
  102. package/dist/onboarding/connect.js +0 -1
  103. package/dist/onboarding/credential-interceptor.js +0 -1
  104. package/dist/onboarding/degradation-accumulator.js +0 -1
  105. package/dist/onboarding/prompt-user.d.ts +1 -1
  106. package/dist/onboarding/prompt-user.js +0 -1
  107. package/dist/onboarding/provider-status.js +0 -1
  108. package/dist/onboarding/providers.d.ts +25 -1
  109. package/dist/onboarding/providers.js +26 -1
  110. package/dist/onboarding/state.js +0 -1
  111. package/dist/onboarding/tool-helpers.js +0 -1
  112. package/dist/onboarding/tool-tags.js +0 -1
  113. package/dist/onboarding/validate-model-key.d.ts +17 -0
  114. package/dist/onboarding/validate-model-key.js +54 -0
  115. package/dist/onboarding/validation.js +0 -1
  116. package/dist/pi/opencandle-extension.js +46 -7
  117. package/dist/pi/session-action-dedupe.js +0 -1
  118. package/dist/pi/session-storage.js +0 -1
  119. package/dist/pi/session-writer-lock.js +0 -1
  120. package/dist/pi/session.js +0 -1
  121. package/dist/pi/setup.d.ts +2 -0
  122. package/dist/pi/setup.js +10 -3
  123. package/dist/pi/tool-adapter.js +0 -1
  124. package/dist/pi/tui-session-coordinator.js +0 -1
  125. package/dist/prompts/context-builder.js +1 -2
  126. package/dist/prompts/disclaimer.js +0 -1
  127. package/dist/prompts/policy-cards.js +0 -1
  128. package/dist/prompts/sections.js +0 -1
  129. package/dist/prompts/symbol-preflight.js +0 -1
  130. package/dist/prompts/workflow-prompts.js +0 -1
  131. package/dist/providers/alpha-vantage.js +8 -3
  132. package/dist/providers/coingecko.js +1 -1
  133. package/dist/providers/errors.js +0 -1
  134. package/dist/providers/exa-search.js +11 -10
  135. package/dist/providers/external-tool-command.js +0 -1
  136. package/dist/providers/external-tool-error.js +0 -1
  137. package/dist/providers/fear-greed.js +0 -1
  138. package/dist/providers/finnhub.js +0 -1
  139. package/dist/providers/fred.js +0 -1
  140. package/dist/providers/index.js +0 -1
  141. package/dist/providers/polymarket.d.ts +2 -0
  142. package/dist/providers/polymarket.js +162 -0
  143. package/dist/providers/provider-credential-error.js +0 -1
  144. package/dist/providers/reddit-cli.js +0 -1
  145. package/dist/providers/reddit.js +0 -1
  146. package/dist/providers/sec-edgar.js +0 -1
  147. package/dist/providers/tradingview.js +1 -2
  148. package/dist/providers/twitter-cli.js +0 -1
  149. package/dist/providers/twitter.js +0 -1
  150. package/dist/providers/web-search.js +15 -12
  151. package/dist/providers/with-fallback.js +0 -1
  152. package/dist/providers/wrap-provider.js +5 -4
  153. package/dist/providers/yahoo-finance.d.ts +3 -0
  154. package/dist/providers/yahoo-finance.js +272 -13
  155. package/dist/routing/classify-intent.js +0 -1
  156. package/dist/routing/defaults.js +0 -1
  157. package/dist/routing/entity-extractor.js +18 -3
  158. package/dist/routing/fund-symbols.js +0 -1
  159. package/dist/routing/horizon.js +0 -1
  160. package/dist/routing/index.js +0 -1
  161. package/dist/routing/legacy-rule-router.js +0 -1
  162. package/dist/routing/planning.js +0 -1
  163. package/dist/routing/route-manifest.js +1 -2
  164. package/dist/routing/router-llm-client.d.ts +2 -2
  165. package/dist/routing/router-llm-client.js +18 -4
  166. package/dist/routing/router-prompt.js +0 -1
  167. package/dist/routing/router-types.js +0 -1
  168. package/dist/routing/router.d.ts +1 -1
  169. package/dist/routing/router.js +274 -6
  170. package/dist/routing/slot-resolver.d.ts +1 -0
  171. package/dist/routing/slot-resolver.js +1 -2
  172. package/dist/routing/symbol-disambiguator.js +0 -1
  173. package/dist/routing/turn-context.js +0 -1
  174. package/dist/routing/types.js +0 -1
  175. package/dist/runtime/answer-contracts.js +0 -1
  176. package/dist/runtime/artifact-contracts.js +0 -1
  177. package/dist/runtime/evidence.d.ts +1 -0
  178. package/dist/runtime/evidence.js +0 -1
  179. package/dist/runtime/numeric-claims.d.ts +23 -0
  180. package/dist/runtime/numeric-claims.js +99 -0
  181. package/dist/runtime/planning-evidence.js +1 -77
  182. package/dist/runtime/prompt-step.d.ts +10 -1
  183. package/dist/runtime/prompt-step.js +116 -3
  184. package/dist/runtime/provider-tracker.js +0 -1
  185. package/dist/runtime/run-context.js +0 -1
  186. package/dist/runtime/session-coordinator.d.ts +11 -1
  187. package/dist/runtime/session-coordinator.js +352 -50
  188. package/dist/runtime/session-title.js +0 -1
  189. package/dist/runtime/tool-defaults-wrapper.js +0 -1
  190. package/dist/runtime/validation.d.ts +3 -1
  191. package/dist/runtime/validation.js +0 -1
  192. package/dist/runtime/workflow-events.d.ts +1 -1
  193. package/dist/runtime/workflow-events.js +0 -1
  194. package/dist/runtime/workflow-runner.d.ts +1 -0
  195. package/dist/runtime/workflow-runner.js +8 -3
  196. package/dist/runtime/workflow-types.d.ts +3 -0
  197. package/dist/runtime/workflow-types.js +0 -1
  198. package/dist/sentiment/adapters/finnhub.js +0 -1
  199. package/dist/sentiment/adapters/reddit.js +0 -1
  200. package/dist/sentiment/adapters/twitter.js +0 -1
  201. package/dist/sentiment/adapters/web.js +0 -1
  202. package/dist/sentiment/index.js +4 -2
  203. package/dist/sentiment/insights.js +0 -1
  204. package/dist/sentiment/keywords.js +0 -1
  205. package/dist/sentiment/pipeline.js +0 -1
  206. package/dist/sentiment/scorer.js +0 -1
  207. package/dist/sentiment/store.js +0 -1
  208. package/dist/sentiment/trends.js +0 -1
  209. package/dist/sentiment/types.js +0 -1
  210. package/dist/system-prompt.js +0 -1
  211. package/dist/tool-kit.js +0 -1
  212. package/dist/tools/fundamentals/company-overview.d.ts +1 -1
  213. package/dist/tools/fundamentals/company-overview.js +2 -1
  214. package/dist/tools/fundamentals/comps.d.ts +1 -0
  215. package/dist/tools/fundamentals/comps.js +25 -12
  216. package/dist/tools/fundamentals/dcf.js +183 -113
  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 +2 -1
  220. package/dist/tools/fundamentals/sec-filings.js +0 -1
  221. package/dist/tools/index.d.ts +117 -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.d.ts +8 -0
  225. package/dist/tools/macro/event-probabilities.js +120 -0
  226. package/dist/tools/macro/fear-greed.d.ts +1 -1
  227. package/dist/tools/macro/fear-greed.js +0 -1
  228. package/dist/tools/macro/fred-data.d.ts +1 -1
  229. package/dist/tools/macro/fred-data.js +2 -1
  230. package/dist/tools/market/crypto-history.js +0 -1
  231. package/dist/tools/market/crypto-price.d.ts +4 -1
  232. package/dist/tools/market/crypto-price.js +10 -2
  233. package/dist/tools/market/screen-stocks.js +14 -4
  234. package/dist/tools/market/search-ticker.js +1 -2
  235. package/dist/tools/market/stock-history.js +0 -1
  236. package/dist/tools/market/stock-quote.d.ts +4 -1
  237. package/dist/tools/market/stock-quote.js +9 -5
  238. package/dist/tools/options/greeks.js +0 -1
  239. package/dist/tools/options/option-chain.d.ts +4 -1
  240. package/dist/tools/options/option-chain.js +12 -2
  241. package/dist/tools/portfolio/alerts.d.ts +2 -1
  242. package/dist/tools/portfolio/alerts.js +228 -2
  243. package/dist/tools/portfolio/correlation.js +23 -5
  244. package/dist/tools/portfolio/daily-report.js +0 -1
  245. package/dist/tools/portfolio/holdings-overlap.js +0 -1
  246. package/dist/tools/portfolio/notifications.js +0 -1
  247. package/dist/tools/portfolio/risk-analysis.d.ts +1 -1
  248. package/dist/tools/portfolio/risk-analysis.js +1 -2
  249. package/dist/tools/portfolio/tracker.d.ts +3 -1
  250. package/dist/tools/portfolio/tracker.js +57 -10
  251. package/dist/tools/portfolio/watchlist.d.ts +3 -6
  252. package/dist/tools/portfolio/watchlist.js +101 -110
  253. package/dist/tools/sentiment/insight-format.js +0 -1
  254. package/dist/tools/sentiment/query-match.js +0 -1
  255. package/dist/tools/sentiment/reddit-sentiment.js +0 -1
  256. package/dist/tools/sentiment/sentiment-summary.js +8 -4
  257. package/dist/tools/sentiment/sentiment-trend.d.ts +5 -1
  258. package/dist/tools/sentiment/sentiment-trend.js +6 -2
  259. package/dist/tools/sentiment/twitter-sentiment.js +0 -1
  260. package/dist/tools/sentiment/untrusted-text.js +0 -1
  261. package/dist/tools/sentiment/web-search.d.ts +1 -1
  262. package/dist/tools/sentiment/web-search.js +0 -1
  263. package/dist/tools/sentiment/web-sentiment.js +0 -1
  264. package/dist/tools/technical/backtest.js +0 -1
  265. package/dist/tools/technical/indicators.js +1 -2
  266. package/dist/types/fundamentals.d.ts +1 -0
  267. package/dist/types/fundamentals.js +0 -1
  268. package/dist/types/index.d.ts +1 -0
  269. package/dist/types/index.js +0 -1
  270. package/dist/types/macro.js +0 -1
  271. package/dist/types/market.d.ts +8 -0
  272. package/dist/types/market.js +0 -1
  273. package/dist/types/options.d.ts +1 -0
  274. package/dist/types/options.js +0 -1
  275. package/dist/types/portfolio.js +0 -1
  276. package/dist/types/prediction-markets.d.ts +13 -0
  277. package/dist/types/prediction-markets.js +1 -0
  278. package/dist/types/sentiment.js +0 -1
  279. package/dist/workflows/compare-assets.js +0 -1
  280. package/dist/workflows/index.js +0 -1
  281. package/dist/workflows/options-screener.js +0 -1
  282. package/dist/workflows/portfolio-builder.js +0 -1
  283. package/gui/web/dist/assets/CatalogOverlay-CAc7e3Pf.js +1 -0
  284. package/gui/web/dist/assets/index-BOEKd9wT.css +2 -0
  285. package/gui/web/dist/assets/index-C-H05cQ2.js +65 -0
  286. package/gui/web/dist/index.html +2 -2
  287. package/package.json +16 -22
  288. package/dist/analysts/contracts.js.map +0 -1
  289. package/dist/analysts/orchestrator.js.map +0 -1
  290. package/dist/cli-main.js.map +0 -1
  291. package/dist/cli.js.map +0 -1
  292. package/dist/config.js.map +0 -1
  293. package/dist/doctor/cli-command.js.map +0 -1
  294. package/dist/doctor/render.js.map +0 -1
  295. package/dist/doctor/report.js.map +0 -1
  296. package/dist/index.js.map +0 -1
  297. package/dist/infra/cache.js.map +0 -1
  298. package/dist/infra/http-client.js.map +0 -1
  299. package/dist/infra/index.js.map +0 -1
  300. package/dist/infra/native-dependencies.js.map +0 -1
  301. package/dist/infra/node-version.js.map +0 -1
  302. package/dist/infra/open-url.js.map +0 -1
  303. package/dist/infra/opencandle-paths.js.map +0 -1
  304. package/dist/infra/rate-limiter.js.map +0 -1
  305. package/dist/market-state/alert-conditions.js.map +0 -1
  306. package/dist/market-state/alert-runner.js.map +0 -1
  307. package/dist/market-state/daily-report.js.map +0 -1
  308. package/dist/market-state/local-automation-service.js.map +0 -1
  309. package/dist/market-state/notification-delivery.js.map +0 -1
  310. package/dist/market-state/resolve-for-mutation.js.map +0 -1
  311. package/dist/market-state/resolve.js.map +0 -1
  312. package/dist/market-state/service.js.map +0 -1
  313. package/dist/memory/index.js.map +0 -1
  314. package/dist/memory/manager.js.map +0 -1
  315. package/dist/memory/preference-extractor.js.map +0 -1
  316. package/dist/memory/retrieval.js.map +0 -1
  317. package/dist/memory/sqlite.js.map +0 -1
  318. package/dist/memory/storage.js.map +0 -1
  319. package/dist/memory/tool-defaults.js.map +0 -1
  320. package/dist/memory/types.js.map +0 -1
  321. package/dist/monitor.js.map +0 -1
  322. package/dist/onboarding/connect.js.map +0 -1
  323. package/dist/onboarding/credential-interceptor.js.map +0 -1
  324. package/dist/onboarding/degradation-accumulator.js.map +0 -1
  325. package/dist/onboarding/prompt-user.js.map +0 -1
  326. package/dist/onboarding/provider-status.js.map +0 -1
  327. package/dist/onboarding/providers.js.map +0 -1
  328. package/dist/onboarding/state.js.map +0 -1
  329. package/dist/onboarding/tool-helpers.js.map +0 -1
  330. package/dist/onboarding/tool-tags.js.map +0 -1
  331. package/dist/onboarding/validation.js.map +0 -1
  332. package/dist/pi/opencandle-extension.js.map +0 -1
  333. package/dist/pi/session-action-dedupe.js.map +0 -1
  334. package/dist/pi/session-storage.js.map +0 -1
  335. package/dist/pi/session-writer-lock.js.map +0 -1
  336. package/dist/pi/session.js.map +0 -1
  337. package/dist/pi/setup.js.map +0 -1
  338. package/dist/pi/tool-adapter.js.map +0 -1
  339. package/dist/pi/tui-session-coordinator.js.map +0 -1
  340. package/dist/prompts/context-builder.js.map +0 -1
  341. package/dist/prompts/disclaimer.js.map +0 -1
  342. package/dist/prompts/policy-cards.js.map +0 -1
  343. package/dist/prompts/sections.js.map +0 -1
  344. package/dist/prompts/symbol-preflight.js.map +0 -1
  345. package/dist/prompts/workflow-prompts.js.map +0 -1
  346. package/dist/providers/alpha-vantage.js.map +0 -1
  347. package/dist/providers/coingecko.js.map +0 -1
  348. package/dist/providers/errors.js.map +0 -1
  349. package/dist/providers/exa-search.js.map +0 -1
  350. package/dist/providers/external-tool-command.js.map +0 -1
  351. package/dist/providers/external-tool-error.js.map +0 -1
  352. package/dist/providers/fear-greed.js.map +0 -1
  353. package/dist/providers/finnhub.js.map +0 -1
  354. package/dist/providers/fred.js.map +0 -1
  355. package/dist/providers/index.js.map +0 -1
  356. package/dist/providers/provider-credential-error.js.map +0 -1
  357. package/dist/providers/reddit-cli.js.map +0 -1
  358. package/dist/providers/reddit.js.map +0 -1
  359. package/dist/providers/sec-edgar.js.map +0 -1
  360. package/dist/providers/tradingview.js.map +0 -1
  361. package/dist/providers/twitter-cli.js.map +0 -1
  362. package/dist/providers/twitter.js.map +0 -1
  363. package/dist/providers/web-search.js.map +0 -1
  364. package/dist/providers/with-fallback.js.map +0 -1
  365. package/dist/providers/wrap-provider.js.map +0 -1
  366. package/dist/providers/yahoo-finance.js.map +0 -1
  367. package/dist/routing/classify-intent.js.map +0 -1
  368. package/dist/routing/defaults.js.map +0 -1
  369. package/dist/routing/entity-extractor.js.map +0 -1
  370. package/dist/routing/fund-symbols.js.map +0 -1
  371. package/dist/routing/horizon.js.map +0 -1
  372. package/dist/routing/index.js.map +0 -1
  373. package/dist/routing/legacy-rule-router.js.map +0 -1
  374. package/dist/routing/planning.js.map +0 -1
  375. package/dist/routing/route-manifest.js.map +0 -1
  376. package/dist/routing/router-llm-client.js.map +0 -1
  377. package/dist/routing/router-prompt.js.map +0 -1
  378. package/dist/routing/router-types.js.map +0 -1
  379. package/dist/routing/router.js.map +0 -1
  380. package/dist/routing/slot-resolver.js.map +0 -1
  381. package/dist/routing/symbol-disambiguator.js.map +0 -1
  382. package/dist/routing/turn-context.js.map +0 -1
  383. package/dist/routing/types.js.map +0 -1
  384. package/dist/runtime/answer-contracts.js.map +0 -1
  385. package/dist/runtime/artifact-contracts.js.map +0 -1
  386. package/dist/runtime/evidence.js.map +0 -1
  387. package/dist/runtime/planning-evidence.js.map +0 -1
  388. package/dist/runtime/prompt-step.js.map +0 -1
  389. package/dist/runtime/provider-tracker.js.map +0 -1
  390. package/dist/runtime/run-context.js.map +0 -1
  391. package/dist/runtime/session-coordinator.js.map +0 -1
  392. package/dist/runtime/session-title.js.map +0 -1
  393. package/dist/runtime/tool-defaults-wrapper.js.map +0 -1
  394. package/dist/runtime/validation.js.map +0 -1
  395. package/dist/runtime/workflow-events.js.map +0 -1
  396. package/dist/runtime/workflow-runner.js.map +0 -1
  397. package/dist/runtime/workflow-types.js.map +0 -1
  398. package/dist/sentiment/adapters/finnhub.js.map +0 -1
  399. package/dist/sentiment/adapters/reddit.js.map +0 -1
  400. package/dist/sentiment/adapters/twitter.js.map +0 -1
  401. package/dist/sentiment/adapters/web.js.map +0 -1
  402. package/dist/sentiment/index.js.map +0 -1
  403. package/dist/sentiment/insights.js.map +0 -1
  404. package/dist/sentiment/keywords.js.map +0 -1
  405. package/dist/sentiment/pipeline.js.map +0 -1
  406. package/dist/sentiment/scorer.js.map +0 -1
  407. package/dist/sentiment/store.js.map +0 -1
  408. package/dist/sentiment/trends.js.map +0 -1
  409. package/dist/sentiment/types.js.map +0 -1
  410. package/dist/system-prompt.js.map +0 -1
  411. package/dist/tool-kit.js.map +0 -1
  412. package/dist/tools/fundamentals/company-overview.js.map +0 -1
  413. package/dist/tools/fundamentals/comps.js.map +0 -1
  414. package/dist/tools/fundamentals/dcf.js.map +0 -1
  415. package/dist/tools/fundamentals/earnings.js.map +0 -1
  416. package/dist/tools/fundamentals/financials.js.map +0 -1
  417. package/dist/tools/fundamentals/sec-filings.js.map +0 -1
  418. package/dist/tools/index.js.map +0 -1
  419. package/dist/tools/interaction/ask-user.js.map +0 -1
  420. package/dist/tools/macro/fear-greed.js.map +0 -1
  421. package/dist/tools/macro/fred-data.js.map +0 -1
  422. package/dist/tools/market/crypto-history.js.map +0 -1
  423. package/dist/tools/market/crypto-price.js.map +0 -1
  424. package/dist/tools/market/screen-stocks.js.map +0 -1
  425. package/dist/tools/market/search-ticker.js.map +0 -1
  426. package/dist/tools/market/stock-history.js.map +0 -1
  427. package/dist/tools/market/stock-quote.js.map +0 -1
  428. package/dist/tools/options/greeks.js.map +0 -1
  429. package/dist/tools/options/option-chain.js.map +0 -1
  430. package/dist/tools/portfolio/alerts.js.map +0 -1
  431. package/dist/tools/portfolio/correlation.js.map +0 -1
  432. package/dist/tools/portfolio/daily-report.js.map +0 -1
  433. package/dist/tools/portfolio/holdings-overlap.js.map +0 -1
  434. package/dist/tools/portfolio/notifications.js.map +0 -1
  435. package/dist/tools/portfolio/risk-analysis.js.map +0 -1
  436. package/dist/tools/portfolio/tracker.js.map +0 -1
  437. package/dist/tools/portfolio/watchlist.js.map +0 -1
  438. package/dist/tools/sentiment/insight-format.js.map +0 -1
  439. package/dist/tools/sentiment/query-match.js.map +0 -1
  440. package/dist/tools/sentiment/reddit-sentiment.js.map +0 -1
  441. package/dist/tools/sentiment/sentiment-summary.js.map +0 -1
  442. package/dist/tools/sentiment/sentiment-trend.js.map +0 -1
  443. package/dist/tools/sentiment/twitter-sentiment.js.map +0 -1
  444. package/dist/tools/sentiment/untrusted-text.js.map +0 -1
  445. package/dist/tools/sentiment/web-search.js.map +0 -1
  446. package/dist/tools/sentiment/web-sentiment.js.map +0 -1
  447. package/dist/tools/technical/backtest.js.map +0 -1
  448. package/dist/tools/technical/indicators.js.map +0 -1
  449. package/dist/types/fundamentals.js.map +0 -1
  450. package/dist/types/index.js.map +0 -1
  451. package/dist/types/macro.js.map +0 -1
  452. package/dist/types/market.js.map +0 -1
  453. package/dist/types/options.js.map +0 -1
  454. package/dist/types/portfolio.js.map +0 -1
  455. package/dist/types/sentiment.js.map +0 -1
  456. package/dist/workflows/compare-assets.js.map +0 -1
  457. package/dist/workflows/index.js.map +0 -1
  458. package/dist/workflows/options-screener.js.map +0 -1
  459. package/dist/workflows/portfolio-builder.js.map +0 -1
  460. package/gui/server/ask-user-bridge.ts +0 -89
  461. package/gui/server/automation-heartbeat.ts +0 -97
  462. package/gui/server/background-quotes.ts +0 -127
  463. package/gui/server/chat-event-adapter.ts +0 -210
  464. package/gui/server/chat-run-session.ts +0 -16
  465. package/gui/server/gui-session-manager.ts +0 -5
  466. package/gui/server/http-routes.ts +0 -953
  467. package/gui/server/invoke-tool.ts +0 -489
  468. package/gui/server/live-chat-event-adapter.ts +0 -208
  469. package/gui/server/local-session-coordinator.ts +0 -97
  470. package/gui/server/market-state-api.ts +0 -273
  471. package/gui/server/model-setup.ts +0 -254
  472. package/gui/server/package.json +0 -5
  473. package/gui/server/private-api-access.ts +0 -62
  474. package/gui/server/projector.ts +0 -263
  475. package/gui/server/prompt-observation.ts +0 -58
  476. package/gui/server/quote-snapshot-store.ts +0 -50
  477. package/gui/server/server.ts +0 -289
  478. package/gui/server/session-actions.ts +0 -331
  479. package/gui/server/session-entry-wait.ts +0 -160
  480. package/gui/server/shutdown.ts +0 -47
  481. package/gui/server/tool-invoke-ack.ts +0 -49
  482. package/gui/server/tool-metadata.ts +0 -167
  483. package/gui/server/websocket.ts +0 -138
  484. package/gui/server/writer-lock.ts +0 -1
  485. package/gui/server/ws-hub.ts +0 -391
  486. package/gui/shared/chat-events.ts +0 -156
  487. package/gui/shared/event-reducer.ts +0 -219
  488. package/gui/web/dist/assets/CatalogOverlay-ChRTKNlf.js +0 -1
  489. package/gui/web/dist/assets/index-BzyqyVnd.css +0 -2
  490. package/gui/web/dist/assets/index-DvMjkOP9.js +0 -65
  491. package/src/analysts/contracts.ts +0 -176
  492. package/src/analysts/orchestrator.ts +0 -224
  493. package/src/cli-main.ts +0 -510
  494. package/src/cli.ts +0 -17
  495. package/src/config.ts +0 -272
  496. package/src/doctor/cli-command.ts +0 -83
  497. package/src/doctor/render.ts +0 -37
  498. package/src/doctor/report.ts +0 -638
  499. package/src/index.ts +0 -5
  500. package/src/infra/cache.ts +0 -114
  501. package/src/infra/http-client.ts +0 -134
  502. package/src/infra/index.ts +0 -14
  503. package/src/infra/native-dependencies.ts +0 -84
  504. package/src/infra/node-version.ts +0 -23
  505. package/src/infra/open-url.ts +0 -28
  506. package/src/infra/opencandle-paths.ts +0 -53
  507. package/src/infra/rate-limiter.ts +0 -76
  508. package/src/market-state/alert-conditions.ts +0 -82
  509. package/src/market-state/alert-runner.ts +0 -863
  510. package/src/market-state/daily-report.ts +0 -237
  511. package/src/market-state/local-automation-service.ts +0 -162
  512. package/src/market-state/notification-delivery.ts +0 -158
  513. package/src/market-state/resolve-for-mutation.ts +0 -24
  514. package/src/market-state/resolve.ts +0 -112
  515. package/src/market-state/service.ts +0 -2208
  516. package/src/memory/index.ts +0 -10
  517. package/src/memory/manager.ts +0 -190
  518. package/src/memory/preference-extractor.ts +0 -106
  519. package/src/memory/retrieval.ts +0 -71
  520. package/src/memory/sqlite.ts +0 -577
  521. package/src/memory/storage.ts +0 -195
  522. package/src/memory/tool-defaults.ts +0 -108
  523. package/src/memory/types.ts +0 -71
  524. package/src/monitor.ts +0 -123
  525. package/src/onboarding/connect.ts +0 -177
  526. package/src/onboarding/credential-interceptor.ts +0 -122
  527. package/src/onboarding/degradation-accumulator.ts +0 -77
  528. package/src/onboarding/prompt-user.ts +0 -85
  529. package/src/onboarding/provider-status.ts +0 -382
  530. package/src/onboarding/providers.ts +0 -414
  531. package/src/onboarding/state.ts +0 -216
  532. package/src/onboarding/tool-helpers.ts +0 -104
  533. package/src/onboarding/tool-tags.ts +0 -244
  534. package/src/onboarding/validation.ts +0 -152
  535. package/src/pi/opencandle-extension.ts +0 -1244
  536. package/src/pi/session-action-dedupe.ts +0 -155
  537. package/src/pi/session-storage.ts +0 -5
  538. package/src/pi/session-writer-lock.ts +0 -426
  539. package/src/pi/session.ts +0 -84
  540. package/src/pi/setup.ts +0 -399
  541. package/src/pi/tool-adapter.ts +0 -49
  542. package/src/pi/tui-session-coordinator.ts +0 -351
  543. package/src/prompts/context-builder.ts +0 -326
  544. package/src/prompts/disclaimer.ts +0 -9
  545. package/src/prompts/policy-cards.ts +0 -228
  546. package/src/prompts/sections.ts +0 -46
  547. package/src/prompts/symbol-preflight.ts +0 -80
  548. package/src/prompts/workflow-prompts.ts +0 -504
  549. package/src/providers/alpha-vantage.ts +0 -334
  550. package/src/providers/coingecko.ts +0 -93
  551. package/src/providers/errors.ts +0 -9
  552. package/src/providers/exa-search.ts +0 -375
  553. package/src/providers/external-tool-command.ts +0 -164
  554. package/src/providers/external-tool-error.ts +0 -20
  555. package/src/providers/fear-greed.ts +0 -45
  556. package/src/providers/finnhub.ts +0 -125
  557. package/src/providers/fred.ts +0 -83
  558. package/src/providers/index.ts +0 -17
  559. package/src/providers/provider-credential-error.ts +0 -23
  560. package/src/providers/reddit-cli.ts +0 -286
  561. package/src/providers/reddit.ts +0 -106
  562. package/src/providers/sec-edgar.ts +0 -326
  563. package/src/providers/tradingview.ts +0 -399
  564. package/src/providers/twitter-cli.ts +0 -202
  565. package/src/providers/twitter.ts +0 -102
  566. package/src/providers/web-search.ts +0 -303
  567. package/src/providers/with-fallback.ts +0 -42
  568. package/src/providers/wrap-provider.ts +0 -103
  569. package/src/providers/yahoo-finance.ts +0 -672
  570. package/src/routing/classify-intent.ts +0 -380
  571. package/src/routing/defaults.ts +0 -29
  572. package/src/routing/entity-extractor.ts +0 -540
  573. package/src/routing/fund-symbols.ts +0 -58
  574. package/src/routing/horizon.ts +0 -7
  575. package/src/routing/index.ts +0 -70
  576. package/src/routing/legacy-rule-router.ts +0 -13
  577. package/src/routing/planning.ts +0 -829
  578. package/src/routing/route-manifest.ts +0 -308
  579. package/src/routing/router-llm-client.ts +0 -52
  580. package/src/routing/router-prompt.ts +0 -159
  581. package/src/routing/router-types.ts +0 -84
  582. package/src/routing/router.ts +0 -997
  583. package/src/routing/slot-resolver.ts +0 -213
  584. package/src/routing/symbol-disambiguator.ts +0 -72
  585. package/src/routing/turn-context.ts +0 -108
  586. package/src/routing/types.ts +0 -77
  587. package/src/runtime/answer-contracts.ts +0 -693
  588. package/src/runtime/artifact-contracts.ts +0 -77
  589. package/src/runtime/evidence.ts +0 -77
  590. package/src/runtime/planning-evidence.ts +0 -682
  591. package/src/runtime/prompt-step.ts +0 -60
  592. package/src/runtime/provider-tracker.ts +0 -40
  593. package/src/runtime/run-context.ts +0 -32
  594. package/src/runtime/session-coordinator.ts +0 -632
  595. package/src/runtime/session-title.ts +0 -60
  596. package/src/runtime/tool-defaults-wrapper.ts +0 -43
  597. package/src/runtime/validation.ts +0 -211
  598. package/src/runtime/workflow-events.ts +0 -75
  599. package/src/runtime/workflow-runner.ts +0 -182
  600. package/src/runtime/workflow-types.ts +0 -102
  601. package/src/sentiment/adapters/finnhub.ts +0 -49
  602. package/src/sentiment/adapters/reddit.ts +0 -65
  603. package/src/sentiment/adapters/twitter.ts +0 -36
  604. package/src/sentiment/adapters/web.ts +0 -44
  605. package/src/sentiment/index.ts +0 -49
  606. package/src/sentiment/insights.ts +0 -269
  607. package/src/sentiment/keywords.ts +0 -31
  608. package/src/sentiment/pipeline.ts +0 -91
  609. package/src/sentiment/scorer.ts +0 -89
  610. package/src/sentiment/store.ts +0 -260
  611. package/src/sentiment/trends.ts +0 -96
  612. package/src/sentiment/types.ts +0 -112
  613. package/src/system-prompt.ts +0 -115
  614. package/src/tool-kit.ts +0 -69
  615. package/src/tools/AGENTS.md +0 -36
  616. package/src/tools/fundamentals/company-overview.ts +0 -64
  617. package/src/tools/fundamentals/comps.ts +0 -169
  618. package/src/tools/fundamentals/dcf.ts +0 -367
  619. package/src/tools/fundamentals/earnings.ts +0 -57
  620. package/src/tools/fundamentals/financials.ts +0 -63
  621. package/src/tools/fundamentals/sec-filings.ts +0 -105
  622. package/src/tools/index.ts +0 -101
  623. package/src/tools/interaction/ask-user.ts +0 -93
  624. package/src/tools/macro/fear-greed.ts +0 -41
  625. package/src/tools/macro/fred-data.ts +0 -92
  626. package/src/tools/market/crypto-history.ts +0 -72
  627. package/src/tools/market/crypto-price.ts +0 -53
  628. package/src/tools/market/screen-stocks.ts +0 -279
  629. package/src/tools/market/search-ticker.ts +0 -254
  630. package/src/tools/market/stock-history.ts +0 -104
  631. package/src/tools/market/stock-quote.ts +0 -67
  632. package/src/tools/options/greeks.ts +0 -81
  633. package/src/tools/options/option-chain.ts +0 -120
  634. package/src/tools/portfolio/alerts.ts +0 -457
  635. package/src/tools/portfolio/correlation.ts +0 -189
  636. package/src/tools/portfolio/daily-report.ts +0 -107
  637. package/src/tools/portfolio/holdings-overlap.ts +0 -139
  638. package/src/tools/portfolio/notifications.ts +0 -45
  639. package/src/tools/portfolio/risk-analysis.ts +0 -173
  640. package/src/tools/portfolio/tracker.ts +0 -308
  641. package/src/tools/portfolio/watchlist.ts +0 -288
  642. package/src/tools/sentiment/insight-format.ts +0 -50
  643. package/src/tools/sentiment/query-match.ts +0 -117
  644. package/src/tools/sentiment/reddit-sentiment.ts +0 -403
  645. package/src/tools/sentiment/sentiment-summary.ts +0 -383
  646. package/src/tools/sentiment/sentiment-trend.ts +0 -75
  647. package/src/tools/sentiment/twitter-sentiment.ts +0 -287
  648. package/src/tools/sentiment/untrusted-text.ts +0 -21
  649. package/src/tools/sentiment/web-search.ts +0 -186
  650. package/src/tools/sentiment/web-sentiment.ts +0 -96
  651. package/src/tools/technical/backtest.ts +0 -336
  652. package/src/tools/technical/indicators.ts +0 -281
  653. package/src/types/fundamentals.ts +0 -46
  654. package/src/types/index.ts +0 -25
  655. package/src/types/macro.ts +0 -27
  656. package/src/types/market.ts +0 -44
  657. package/src/types/options.ts +0 -52
  658. package/src/types/portfolio.ts +0 -83
  659. package/src/types/sentiment.ts +0 -129
  660. package/src/workflows/compare-assets.ts +0 -89
  661. package/src/workflows/index.ts +0 -3
  662. package/src/workflows/options-screener.ts +0 -125
  663. package/src/workflows/portfolio-builder.ts +0 -63
@@ -1,36 +0,0 @@
1
- # TOOLS
2
-
3
- Market analysis tools organized by financial domain. Tools fetch data from `src/providers/`, return structured results for LLM synthesis.
4
-
5
- ## STRUCTURE
6
- ```
7
- src/tools/
8
- ├── fundamentals/ # Earnings, financials, DCF, comps, SEC filings
9
- ├── technical/ # Indicators (SMA, RSI, MACD), backtesting
10
- ├── options/ # Options chains, Greeks computation
11
- ├── macro/ # FRED economic data, fear & greed index
12
- ├── sentiment/ # Reddit sentiment, news sentiment
13
- ├── portfolio/ # Tracker, risk analysis, watchlist, correlation
14
- ├── market/ # Stock quotes, history, crypto, ticker search
15
- └── index.ts # getAllTools() registry — add new tools here
16
- ```
17
-
18
- ## LOOKUP
19
- | Domain | Location |
20
- |--------|----------|
21
- | P/E, EPS, balance sheets, DCF | `fundamentals/` |
22
- | RSI, MACD, SMA, backtest | `technical/` |
23
- | Put/call ratio, IV, Greeks | `options/` |
24
- | GDP, inflation, Fed rates | `macro/` |
25
- | Reddit buzz, news | `sentiment/` |
26
- | Positions, Sharpe, VaR, watchlist | `portfolio/` |
27
- | Quotes, OHLCV, crypto, search | `market/` |
28
-
29
- ## ADDING A TOOL
30
- 1. Create `src/tools/<domain>/my-tool.ts` with Typebox params + `AgentTool` export.
31
- 2. Register in `src/tools/index.ts` (`getAllTools()` array).
32
- 3. Add test in `tests/unit/tools/` with fixture-based fetch mocking.
33
-
34
- ## ANTI-PATTERNS
35
- - Never hardcode mock data in tools; call providers.
36
- - Tools return structured data. The LLM analyzes it, not the tool.
@@ -1,64 +0,0 @@
1
- import type { AgentTool } from "@earendil-works/pi-agent-core";
2
- import { Type } from "@sinclair/typebox";
3
- import { getConfig } from "../../config.js";
4
- import { withCredentialCheck } from "../../onboarding/tool-helpers.js";
5
- import { getOverview } from "../../providers/alpha-vantage.js";
6
- import { wrapProvider } from "../../providers/wrap-provider.js";
7
- import type { CompanyOverview } from "../../types/fundamentals.js";
8
-
9
- const params = Type.Object({
10
- symbol: Type.String({ description: "Stock ticker symbol (e.g. AAPL, MSFT)" }),
11
- });
12
-
13
- export const companyOverviewTool: AgentTool<
14
- typeof params,
15
- CompanyOverview | { credentialRequired: unknown }
16
- > = {
17
- name: "get_company_overview",
18
- label: "Company Overview",
19
- description:
20
- "Get company fundamentals: P/E ratio, EPS, market cap, sector, dividend yield, profit margin, beta, and description. Requires Alpha Vantage.",
21
- parameters: params,
22
- async execute(_toolCallId, args) {
23
- return withCredentialCheck("alpha_vantage", async () => {
24
- const apiKey = getConfig().alphaVantageApiKey!;
25
- const result = await wrapProvider("alphavantage", () =>
26
- getOverview(args.symbol.toUpperCase(), apiKey),
27
- );
28
- if (result.status === "unavailable") {
29
- return {
30
- content: [
31
- {
32
- type: "text",
33
- text: `⚠ Company overview unavailable for ${args.symbol.toUpperCase()} (${result.reason}). Analysis will proceed without fundamentals.`,
34
- },
35
- ],
36
- details: null as any,
37
- };
38
- }
39
- const ov = result.data;
40
- const text = [
41
- `**${ov.name}** (${ov.symbol}) — ${ov.exchange}`,
42
- `Sector: ${ov.sector} | Industry: ${ov.industry}`,
43
- `Market Cap: $${formatLargeNumber(ov.marketCap)} | P/E: ${ov.pe ?? "N/A"} | Fwd P/E: ${ov.forwardPe ?? "N/A"}`,
44
- `EPS: $${ov.eps ?? "N/A"} | Div Yield: ${ov.dividendYield ? `${(ov.dividendYield * 100).toFixed(2)}%` : "N/A"}`,
45
- `Beta: ${ov.beta ?? "N/A"} | Profit Margin: ${ov.profitMargin ? `${(ov.profitMargin * 100).toFixed(1)}%` : "N/A"}`,
46
- `52W: $${ov.week52Low.toFixed(2)} - $${ov.week52High.toFixed(2)}`,
47
- ``,
48
- `${ov.description.slice(0, 300)}${ov.description.length > 300 ? "..." : ""}`,
49
- ].join("\n");
50
-
51
- const prefix = result.stale
52
- ? `⚠ Using cached fundamentals from ${result.timestamp} (Alpha Vantage rate limited)\n`
53
- : "";
54
- return { content: [{ type: "text", text: prefix + text }], details: ov };
55
- });
56
- },
57
- };
58
-
59
- function formatLargeNumber(n: number): string {
60
- if (n >= 1e12) return `${(n / 1e12).toFixed(2)}T`;
61
- if (n >= 1e9) return `${(n / 1e9).toFixed(2)}B`;
62
- if (n >= 1e6) return `${(n / 1e6).toFixed(2)}M`;
63
- return n.toLocaleString();
64
- }
@@ -1,169 +0,0 @@
1
- import type { AgentTool } from "@earendil-works/pi-agent-core";
2
- import { Type } from "@sinclair/typebox";
3
- import { getConfig } from "../../config.js";
4
- import { withCredentialCheck } from "../../onboarding/tool-helpers.js";
5
- import { getOverview } from "../../providers/alpha-vantage.js";
6
- import { wrapProvider } from "../../providers/wrap-provider.js";
7
- import type { CompanyOverview } from "../../types/fundamentals.js";
8
-
9
- export interface CompsMetric {
10
- metric: string;
11
- values: Record<string, number | null>;
12
- median: number | null;
13
- p25: number | null;
14
- p75: number | null;
15
- best: string;
16
- worst: string;
17
- }
18
-
19
- export interface CompsResult {
20
- companies: CompanyOverview[];
21
- metrics: CompsMetric[];
22
- unavailableSymbols: string[];
23
- }
24
-
25
- type MetricDef = {
26
- name: string;
27
- extract: (c: CompanyOverview) => number | null;
28
- lowerIsBetter: boolean;
29
- };
30
-
31
- const METRIC_DEFS: MetricDef[] = [
32
- { name: "P/E", extract: (c) => c.pe, lowerIsBetter: true },
33
- { name: "Forward P/E", extract: (c) => c.forwardPe, lowerIsBetter: true },
34
- { name: "EPS", extract: (c) => c.eps, lowerIsBetter: false },
35
- { name: "Profit Margin", extract: (c) => c.profitMargin, lowerIsBetter: false },
36
- { name: "Revenue Growth", extract: (c) => c.revenueGrowth, lowerIsBetter: false },
37
- { name: "Dividend Yield", extract: (c) => c.dividendYield, lowerIsBetter: false },
38
- { name: "Beta", extract: (c) => c.beta, lowerIsBetter: true },
39
- ];
40
-
41
- export function computeComps(companies: CompanyOverview[]): CompsResult {
42
- const metrics: CompsMetric[] = METRIC_DEFS.map((def) => {
43
- const values: Record<string, number | null> = {};
44
- for (const c of companies) {
45
- values[c.symbol] = def.extract(c);
46
- }
47
-
48
- const nonNull = Object.entries(values)
49
- .filter(([, v]) => v != null)
50
- .map(([sym, v]) => ({ sym, v: v! }));
51
-
52
- const sorted = [...nonNull].sort((a, b) => a.v - b.v);
53
- const sortedVals = sorted.map((s) => s.v);
54
- const median = computeMedian(sortedVals);
55
- const p25 = computePercentile(sortedVals, 0.25);
56
- const p75 = computePercentile(sortedVals, 0.75);
57
-
58
- const best = def.lowerIsBetter
59
- ? (sorted[0]?.sym ?? "")
60
- : (sorted[sorted.length - 1]?.sym ?? "");
61
- const worst = def.lowerIsBetter
62
- ? (sorted[sorted.length - 1]?.sym ?? "")
63
- : (sorted[0]?.sym ?? "");
64
-
65
- return { metric: def.name, values, median, p25, p75, best, worst };
66
- });
67
-
68
- return { companies, metrics, unavailableSymbols: [] };
69
- }
70
-
71
- function computeMedian(sorted: number[]): number | null {
72
- if (sorted.length === 0) return null;
73
- const mid = Math.floor(sorted.length / 2);
74
- return sorted.length % 2 === 0 ? (sorted[mid - 1] + sorted[mid]) / 2 : sorted[mid];
75
- }
76
-
77
- function computePercentile(sorted: number[], p: number): number | null {
78
- if (sorted.length === 0) return null;
79
- if (sorted.length === 1) return sorted[0];
80
- const idx = p * (sorted.length - 1);
81
- const lower = Math.floor(idx);
82
- const upper = Math.ceil(idx);
83
- if (lower === upper) return sorted[lower];
84
- return sorted[lower] + (sorted[upper] - sorted[lower]) * (idx - lower);
85
- }
86
-
87
- const params = Type.Object({
88
- symbols: Type.Array(Type.String(), {
89
- description: "Array of 2-6 ticker symbols to compare (e.g. ['AAPL','MSFT','GOOGL'])",
90
- minItems: 2,
91
- maxItems: 6,
92
- }),
93
- });
94
-
95
- export const compsTool: AgentTool<typeof params> = {
96
- name: "compare_companies",
97
- label: "Comparable Company Analysis",
98
- description:
99
- "Compare 2-6 companies side-by-side on key valuation and financial metrics: P/E, Forward P/E, EPS, Profit Margin, Revenue Growth, Dividend Yield, Beta. Identifies the cheapest and most expensive on each metric.",
100
- parameters: params,
101
- async execute(_toolCallId, args) {
102
- return withCredentialCheck("alpha_vantage", async () => {
103
- const config = getConfig();
104
- const symbols = args.symbols.map((s) => s.toUpperCase());
105
-
106
- const results = await Promise.all(
107
- symbols.map(async (s) => ({
108
- symbol: s,
109
- result: await wrapProvider("alphavantage", () =>
110
- getOverview(s, config.alphaVantageApiKey!),
111
- ),
112
- })),
113
- );
114
-
115
- const companies: CompanyOverview[] = [];
116
- const unavailableSymbols: string[] = [];
117
-
118
- for (const { symbol: sym, result: r } of results) {
119
- if (r.status === "ok") {
120
- companies.push(r.data);
121
- } else {
122
- unavailableSymbols.push(sym);
123
- }
124
- }
125
-
126
- if (companies.length === 0) {
127
- return {
128
- content: [
129
- {
130
- type: "text",
131
- text: `⚠ Company fundamentals unavailable for all symbols: ${symbols.join(", ")}. Alpha Vantage may be rate limited.`,
132
- },
133
- ],
134
- details: null as any,
135
- };
136
- }
137
-
138
- const result = computeComps(companies);
139
- result.unavailableSymbols = unavailableSymbols;
140
-
141
- const availableSymbols = companies.map((company) => company.symbol);
142
- const header = `**Comparable Company Analysis**: ${availableSymbols.join(" vs ")}`;
143
- const rows = result.metrics.map((m) => {
144
- const vals = availableSymbols.map((s) => {
145
- const v = m.values[s];
146
- if (v == null) return "N/A".padStart(10);
147
- if (Math.abs(v) < 1) return `${(v * 100).toFixed(1)}%`.padStart(10);
148
- return v.toFixed(2).padStart(10);
149
- });
150
- const medStr =
151
- m.median != null
152
- ? Math.abs(m.median) < 1
153
- ? `${(m.median * 100).toFixed(1)}%`
154
- : m.median.toFixed(2)
155
- : "N/A";
156
- return ` ${m.metric.padEnd(16)} ${vals.join("")} Med: ${medStr} Best: ${m.best}`;
157
- });
158
-
159
- const symHeader = ` ${"Metric".padEnd(16)} ${availableSymbols.map((s) => s.padStart(10)).join("")}`;
160
- const noteLines =
161
- unavailableSymbols.length > 0
162
- ? ["", `Unavailable fundamentals: ${unavailableSymbols.join(", ")}`]
163
- : [];
164
- const text = [header, "", symHeader, ...rows, ...noteLines].join("\n");
165
-
166
- return { content: [{ type: "text", text }], details: result };
167
- });
168
- },
169
- };
@@ -1,367 +0,0 @@
1
- import type { AgentTool } from "@earendil-works/pi-agent-core";
2
- import { Type } from "@sinclair/typebox";
3
- import { getConfig } from "../../config.js";
4
- import { withCredentialCheck } from "../../onboarding/tool-helpers.js";
5
- import { getFinancials, getOverview } from "../../providers/alpha-vantage.js";
6
- import { wrapProvider } from "../../providers/wrap-provider.js";
7
- import { getQuote } from "../../providers/yahoo-finance.js";
8
- import type { FinancialStatement } from "../../types/fundamentals.js";
9
-
10
- export interface DCFResult {
11
- intrinsicValue: number;
12
- enterpriseValue: number;
13
- terminalValue: number;
14
- netDebt: number;
15
- projectedCashFlows: Array<{ year: number; fcf: number; presentValue: number }>;
16
- assumptions: {
17
- fcf: number;
18
- growthRate: number;
19
- discountRate: number;
20
- terminalGrowth: number;
21
- years: number;
22
- };
23
- sensitivityTable: Array<{ growthRate: number; discountRate: number; intrinsicValue: number }>;
24
- warnings: string[];
25
- }
26
-
27
- export interface DCFParams {
28
- freeCashFlow: number;
29
- growthRate: number;
30
- discountRate: number;
31
- terminalGrowth: number;
32
- years: number;
33
- netDebt: number;
34
- sharesOutstanding: number;
35
- }
36
-
37
- export function computeDCF(params: DCFParams): DCFResult {
38
- const {
39
- freeCashFlow,
40
- growthRate,
41
- discountRate,
42
- terminalGrowth,
43
- years,
44
- netDebt,
45
- sharesOutstanding,
46
- } = params;
47
-
48
- // Gordon Growth requires discount > terminal growth; a non-positive spread
49
- // divides by zero or flips the terminal value's sign.
50
- if (discountRate <= terminalGrowth) {
51
- throw new Error(
52
- `Gordon Growth constraint violated: terminal growth (${(terminalGrowth * 100).toFixed(1)}%) must be below the discount rate (${(discountRate * 100).toFixed(1)}%).`,
53
- );
54
- }
55
-
56
- // Project future cash flows (mid-year convention: discount at year-0.5)
57
- const projectedCashFlows: Array<{ year: number; fcf: number; presentValue: number }> = [];
58
- for (let y = 1; y <= years; y++) {
59
- const fcf = freeCashFlow * (1 + growthRate) ** y;
60
- const pv = fcf / (1 + discountRate) ** (y - 0.5); // mid-year convention
61
- projectedCashFlows.push({ year: y, fcf, presentValue: pv });
62
- }
63
-
64
- // Terminal value (Gordon Growth Model), discounted at full year (end of projection)
65
- const finalFCF = freeCashFlow * (1 + growthRate) ** years;
66
- const terminalValue = (finalFCF * (1 + terminalGrowth)) / (discountRate - terminalGrowth);
67
- const pvTerminal = terminalValue / (1 + discountRate) ** years;
68
-
69
- // Enterprise value
70
- const sumPVs = projectedCashFlows.reduce((s, cf) => s + cf.presentValue, 0);
71
- const enterpriseValue = sumPVs + pvTerminal;
72
-
73
- // Equity value → per share
74
- const equityValue = enterpriseValue - netDebt;
75
- const intrinsicValue = equityValue / sharesOutstanding;
76
-
77
- // Sensitivity table: vary growth ±2% and discount ±2%
78
- const sensitivityTable: Array<{
79
- growthRate: number;
80
- discountRate: number;
81
- intrinsicValue: number;
82
- }> = [];
83
- for (let gDelta = -0.02; gDelta <= 0.02; gDelta += 0.01) {
84
- for (let dDelta = -0.02; dDelta <= 0.02; dDelta += 0.01) {
85
- const g = growthRate + gDelta;
86
- const d = discountRate + dDelta;
87
- if (d <= terminalGrowth || d <= 0 || g < 0) continue;
88
- const sensResult = computeDCFSimple(
89
- freeCashFlow,
90
- g,
91
- d,
92
- terminalGrowth,
93
- years,
94
- netDebt,
95
- sharesOutstanding,
96
- );
97
- sensitivityTable.push({ growthRate: g, discountRate: d, intrinsicValue: sensResult });
98
- }
99
- }
100
-
101
- // Validation warnings (inspired by Anthropic financial plugins + Dexter)
102
- const warnings: string[] = [];
103
- const tvPctOfEV = pvTerminal / enterpriseValue;
104
- if (tvPctOfEV > 0.85) {
105
- warnings.push(
106
- `Terminal value is ${(tvPctOfEV * 100).toFixed(0)}% of enterprise value (typical: 40-80%). The valuation is heavily dependent on terminal assumptions.`,
107
- );
108
- }
109
- const spreadPct = discountRate - terminalGrowth;
110
- if (spreadPct < 0.02) {
111
- warnings.push(
112
- `Terminal growth (${(terminalGrowth * 100).toFixed(1)}%) is very close to discount rate (${(discountRate * 100).toFixed(1)}%). Small changes in assumptions will produce large swings in value.`,
113
- );
114
- }
115
- if (discountRate < 0.05 || discountRate > 0.2) {
116
- warnings.push(
117
- `Discount rate of ${(discountRate * 100).toFixed(1)}% is outside typical WACC range (5-20%).`,
118
- );
119
- }
120
- if (growthRate > 0.2) {
121
- warnings.push(
122
- `Growth rate of ${(growthRate * 100).toFixed(1)}% exceeds 20%. High growth is difficult to sustain — consider a multi-stage model.`,
123
- );
124
- }
125
-
126
- return {
127
- intrinsicValue,
128
- enterpriseValue,
129
- terminalValue,
130
- netDebt,
131
- projectedCashFlows,
132
- assumptions: {
133
- fcf: freeCashFlow,
134
- growthRate,
135
- discountRate,
136
- terminalGrowth,
137
- years,
138
- },
139
- sensitivityTable,
140
- warnings,
141
- };
142
- }
143
-
144
- function computeDCFSimple(
145
- fcf: number,
146
- g: number,
147
- d: number,
148
- tg: number,
149
- years: number,
150
- debt: number,
151
- shares: number,
152
- ): number {
153
- let sumPV = 0;
154
- for (let y = 1; y <= years; y++) {
155
- sumPV += (fcf * (1 + g) ** y) / (1 + d) ** (y - 0.5); // mid-year convention
156
- }
157
- const finalFCF = fcf * (1 + g) ** years;
158
- const tv = (finalFCF * (1 + tg)) / (d - tg);
159
- const pvTV = tv / (1 + d) ** years;
160
- return (sumPV + pvTV - debt) / shares;
161
- }
162
-
163
- export function computeNetDebt(f: FinancialStatement): number | null {
164
- if (f.totalDebt != null && f.cashAndEquivalents != null) {
165
- return f.totalDebt - f.cashAndEquivalents;
166
- }
167
- return null;
168
- }
169
-
170
- const params = Type.Object({
171
- symbol: Type.String({ description: "Stock ticker symbol (e.g. AAPL, MSFT)" }),
172
- growth_rate: Type.Optional(
173
- Type.Number({
174
- description:
175
- "Annual FCF growth rate as decimal (e.g. 0.10 for 10%). If omitted, estimated from historical data.",
176
- }),
177
- ),
178
- discount_rate: Type.Optional(
179
- Type.Number({ description: "Discount rate / WACC as decimal (default: 0.10 for 10%)" }),
180
- ),
181
- terminal_growth: Type.Optional(
182
- Type.Number({ description: "Terminal growth rate as decimal (default: 0.03 for 3%)" }),
183
- ),
184
- projection_years: Type.Optional(
185
- Type.Number({ description: "Years to project forward (default: 5)" }),
186
- ),
187
- });
188
-
189
- export const dcfTool: AgentTool<typeof params> = {
190
- name: "compute_dcf",
191
- label: "DCF Valuation",
192
- description:
193
- "Compute a Discounted Cash Flow (DCF) intrinsic value estimate for a stock. Uses free cash flow, growth projections, and a discount rate to estimate what the stock is worth. Returns intrinsic value per share, margin of safety vs current price, and a sensitivity table.",
194
- parameters: params,
195
- async execute(_toolCallId, args) {
196
- return withCredentialCheck("alpha_vantage", async () => {
197
- const symbol = args.symbol.toUpperCase();
198
- const config = getConfig();
199
-
200
- const [overviewResult, financialsResult, quoteResult] = await Promise.all([
201
- wrapProvider("alphavantage", () => getOverview(symbol, config.alphaVantageApiKey!)),
202
- wrapProvider("alphavantage", () => getFinancials(symbol, config.alphaVantageApiKey!)),
203
- wrapProvider("yahoo", () => getQuote(symbol)),
204
- ]);
205
-
206
- const missing: string[] = [];
207
- if (overviewResult.status === "unavailable")
208
- missing.push(`company overview (${overviewResult.reason})`);
209
- if (financialsResult.status === "unavailable")
210
- missing.push(`financial statements (${financialsResult.reason})`);
211
- if (quoteResult.status === "unavailable") missing.push(`stock quote (${quoteResult.reason})`);
212
-
213
- if (financialsResult.status === "unavailable" || quoteResult.status === "unavailable") {
214
- return {
215
- content: [
216
- {
217
- type: "text",
218
- text: `⚠ DCF valuation unavailable for ${symbol}. Missing: ${missing.join(", ")}. Both financials and current price are required.`,
219
- },
220
- ],
221
- details: null,
222
- };
223
- }
224
-
225
- const overview = overviewResult.status === "ok" ? overviewResult.data : null;
226
- const financials = financialsResult.data;
227
- const quote = quoteResult.data;
228
-
229
- const latestFCF = financials[0]?.freeCashFlow ?? 0;
230
- if (latestFCF <= 0) {
231
- return {
232
- content: [
233
- {
234
- type: "text",
235
- text: `${symbol} has negative or zero free cash flow ($${latestFCF.toLocaleString()}). DCF is not meaningful for companies without positive FCF.`,
236
- },
237
- ],
238
- details: null,
239
- };
240
- }
241
-
242
- // Estimate growth from historical FCF if not provided
243
- let growthRate = args.growth_rate ?? 0.1;
244
- if (!args.growth_rate && financials.length >= 2) {
245
- const olderFCF = financials[1]?.freeCashFlow;
246
- if (olderFCF && olderFCF > 0) {
247
- growthRate = Math.max(0.02, Math.min(0.25, (latestFCF - olderFCF) / olderFCF));
248
- }
249
- }
250
-
251
- const discountRate = args.discount_rate ?? 0.1;
252
- const terminalGrowth = args.terminal_growth ?? 0.03;
253
- if (discountRate <= terminalGrowth) {
254
- return {
255
- content: [
256
- {
257
- type: "text",
258
- text: `⚠ Invalid DCF assumptions for ${symbol}: terminal growth (${(terminalGrowth * 100).toFixed(1)}%) must be below the discount rate (${(discountRate * 100).toFixed(1)}%) for the Gordon Growth terminal value to be meaningful. Lower terminal_growth or raise discount_rate.`,
259
- },
260
- ],
261
- details: null,
262
- };
263
- }
264
-
265
- const years = args.projection_years ?? 5;
266
- // Prefer the overview market cap; fall back to the quote's market cap.
267
- // Never substitute a placeholder share count — a fabricated
268
- // per-share value is worse than an honest refusal.
269
- const marketCap =
270
- overview?.marketCap && overview.marketCap > 0
271
- ? overview.marketCap
272
- : quote.marketCap > 0
273
- ? quote.marketCap
274
- : 0;
275
- if (quote.price <= 0 || marketCap <= 0) {
276
- return {
277
- content: [
278
- {
279
- type: "text",
280
- text: `⚠ Cannot compute a per-share DCF for ${symbol}: shares outstanding cannot be derived because ${quote.price <= 0 ? "the current quote price is unavailable" : "market capitalization is unavailable from the overview and quote providers"}. Per-share intrinsic value requires a real share count.`,
281
- },
282
- ],
283
- details: null,
284
- };
285
- }
286
- const sharesOutstanding = marketCap / quote.price;
287
- // Signed on purpose: net cash (negative net debt) adds to equity value.
288
- // Omit the adjustment if debt/cash fields are missing; assets minus
289
- // liabilities is book equity, not a net-cash proxy.
290
- const computedNetDebt = financials[0] ? computeNetDebt(financials[0]) : null;
291
- const netDebt = computedNetDebt ?? 0;
292
-
293
- const result = computeDCF({
294
- freeCashFlow: latestFCF,
295
- growthRate,
296
- discountRate,
297
- terminalGrowth,
298
- years,
299
- netDebt,
300
- sharesOutstanding,
301
- });
302
- if (computedNetDebt == null) {
303
- result.warnings.push(
304
- "Net debt adjustment omitted because total debt and cash equivalents were unavailable.",
305
- );
306
- }
307
-
308
- const marginOfSafety = (result.intrinsicValue - quote.price) / result.intrinsicValue;
309
- const upside = (result.intrinsicValue - quote.price) / quote.price;
310
-
311
- const lines = [
312
- `**${symbol} DCF Valuation**`,
313
- ``,
314
- `Current Price: $${quote.price.toFixed(2)}`,
315
- `Intrinsic Value: $${result.intrinsicValue.toFixed(2)}`,
316
- `Margin of Safety: ${(marginOfSafety * 100).toFixed(1)}%`,
317
- `Upside/Downside: ${upside >= 0 ? "+" : ""}${(upside * 100).toFixed(1)}%`,
318
- ``,
319
- `**Assumptions**`,
320
- `Free Cash Flow: $${(latestFCF / 1e9).toFixed(2)}B`,
321
- `Growth Rate: ${(growthRate * 100).toFixed(1)}%`,
322
- `Discount Rate (WACC): ${(discountRate * 100).toFixed(1)}%`,
323
- `Terminal Growth: ${(terminalGrowth * 100).toFixed(1)}%`,
324
- `Projection: ${years} years`,
325
- ``,
326
- `**Projected Cash Flows**`,
327
- ...result.projectedCashFlows.map(
328
- (cf) =>
329
- ` Year ${cf.year}: FCF $${(cf.fcf / 1e9).toFixed(2)}B → PV $${(cf.presentValue / 1e9).toFixed(2)}B`,
330
- ),
331
- ` Terminal Value: $${(result.terminalValue / 1e9).toFixed(2)}B`,
332
- ` Enterprise Value: $${(result.enterpriseValue / 1e9).toFixed(2)}B`,
333
- ``,
334
- `**Sensitivity Table** (Intrinsic Value at different Growth/Discount rates)`,
335
- ...formatSensitivityTable(result.sensitivityTable),
336
- ...(result.warnings.length > 0
337
- ? ["", "**Warnings**", ...result.warnings.map((warning) => `- ${warning}`)]
338
- : []),
339
- ];
340
-
341
- return {
342
- content: [{ type: "text", text: lines.join("\n") }],
343
- details: { ...result, currentPrice: quote.price, marginOfSafety, upside },
344
- };
345
- });
346
- },
347
- };
348
-
349
- function formatSensitivityTable(
350
- table: Array<{ growthRate: number; discountRate: number; intrinsicValue: number }>,
351
- ): string[] {
352
- if (table.length === 0) return [" (insufficient data for sensitivity table)"];
353
-
354
- const discountRates = [...new Set(table.map((e) => e.discountRate))].sort((a, b) => a - b);
355
- const growthRates = [...new Set(table.map((e) => e.growthRate))].sort((a, b) => a - b);
356
-
357
- const header = ` ${"Growth↓/WACC→".padEnd(14)} ${discountRates.map((d) => `${(d * 100).toFixed(0)}%`.padStart(8)).join("")}`;
358
- const rows = growthRates.map((g) => {
359
- const cells = discountRates.map((d) => {
360
- const entry = table.find((e) => e.growthRate === g && e.discountRate === d);
361
- return entry ? `$${entry.intrinsicValue.toFixed(0)}`.padStart(8) : "N/A".padStart(8);
362
- });
363
- return ` ${`${(g * 100).toFixed(0)}%`.padEnd(14)} ${cells.join("")}`;
364
- });
365
-
366
- return [header, ...rows];
367
- }
@@ -1,57 +0,0 @@
1
- import type { AgentTool } from "@earendil-works/pi-agent-core";
2
- import { Type } from "@sinclair/typebox";
3
- import { getConfig } from "../../config.js";
4
- import { withCredentialCheck } from "../../onboarding/tool-helpers.js";
5
- import { getEarnings } from "../../providers/alpha-vantage.js";
6
- import { wrapProvider } from "../../providers/wrap-provider.js";
7
- import type { EarningsData } from "../../types/fundamentals.js";
8
-
9
- const params = Type.Object({
10
- symbol: Type.String({ description: "Stock ticker symbol (e.g. AAPL, MSFT)" }),
11
- });
12
-
13
- export const earningsTool: AgentTool<
14
- typeof params,
15
- EarningsData | { credentialRequired: unknown }
16
- > = {
17
- name: "get_earnings",
18
- label: "Earnings History",
19
- description:
20
- "Get quarterly earnings: reported EPS, estimated EPS, and surprise percentage for the last 8 quarters. Requires Alpha Vantage.",
21
- parameters: params,
22
- async execute(_toolCallId, args) {
23
- return withCredentialCheck("alpha_vantage", async () => {
24
- const apiKey = getConfig().alphaVantageApiKey!;
25
- const result = await wrapProvider("alphavantage", () =>
26
- getEarnings(args.symbol.toUpperCase(), apiKey),
27
- );
28
- if (result.status === "unavailable") {
29
- return {
30
- content: [
31
- {
32
- type: "text",
33
- text: `⚠ Earnings data unavailable for ${args.symbol.toUpperCase()} (${result.reason}). Analysis will proceed without earnings history.`,
34
- },
35
- ],
36
- details: null as any,
37
- };
38
- }
39
- const earnings = result.data;
40
- if (earnings.quarterly.length === 0) {
41
- return {
42
- content: [{ type: "text", text: `No earnings data found for ${args.symbol}` }],
43
- details: earnings,
44
- };
45
- }
46
-
47
- const header = `${args.symbol.toUpperCase()} — Quarterly Earnings (last ${earnings.quarterly.length} quarters)`;
48
- const rows = earnings.quarterly.map((q) => {
49
- const sign = q.surprisePercent >= 0 ? "+" : "";
50
- return `${q.date} | Reported: $${q.reportedEPS.toFixed(2)} | Est: $${q.estimatedEPS.toFixed(2)} | Surprise: ${sign}${q.surprisePercent.toFixed(1)}%`;
51
- });
52
-
53
- const text = [header, ...rows].join("\n");
54
- return { content: [{ type: "text", text }], details: earnings };
55
- });
56
- },
57
- };