opencandle 0.11.1 → 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 (653) hide show
  1. package/README.md +20 -24
  2. package/dist/analysts/contracts.js +0 -1
  3. package/dist/analysts/orchestrator.js +0 -1
  4. package/dist/cli-main.js +13 -7
  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.js +0 -1
  9. package/dist/doctor/cli-command.js +2 -1
  10. package/dist/doctor/render.js +0 -1
  11. package/dist/doctor/report.js +40 -11
  12. package/dist/gui/server/ask-user-bridge.d.ts +19 -0
  13. package/dist/gui/server/ask-user-bridge.js +55 -0
  14. package/dist/gui/server/automation-heartbeat.d.ts +25 -0
  15. package/dist/gui/server/automation-heartbeat.js +61 -0
  16. package/dist/gui/server/background-quotes.d.ts +39 -0
  17. package/dist/gui/server/background-quotes.js +71 -0
  18. package/dist/gui/server/chat-event-adapter.d.ts +16 -0
  19. package/dist/gui/server/chat-event-adapter.js +263 -0
  20. package/dist/gui/server/gui-session-manager.d.ts +2 -0
  21. package/dist/gui/server/gui-session-manager.js +4 -0
  22. package/dist/gui/server/http-routes.d.ts +69 -0
  23. package/dist/gui/server/http-routes.js +1008 -0
  24. package/dist/gui/server/invoke-tool.d.ts +47 -0
  25. package/dist/gui/server/invoke-tool.js +373 -0
  26. package/dist/gui/server/live-chat-event-adapter.d.ts +19 -0
  27. package/dist/gui/server/live-chat-event-adapter.js +206 -0
  28. package/dist/gui/server/local-session-coordinator.d.ts +26 -0
  29. package/dist/gui/server/local-session-coordinator.js +53 -0
  30. package/dist/gui/server/market-state-api.d.ts +138 -0
  31. package/dist/gui/server/market-state-api.js +355 -0
  32. package/dist/gui/server/model-setup.d.ts +64 -0
  33. package/dist/gui/server/model-setup.js +150 -0
  34. package/dist/gui/server/private-api-access.d.ts +6 -0
  35. package/dist/gui/server/private-api-access.js +53 -0
  36. package/dist/gui/server/projector.d.ts +49 -0
  37. package/dist/gui/server/projector.js +296 -0
  38. package/dist/gui/server/prompt-observation.d.ts +8 -0
  39. package/dist/gui/server/prompt-observation.js +43 -0
  40. package/dist/gui/server/quote-snapshot-store.d.ts +14 -0
  41. package/dist/gui/server/quote-snapshot-store.js +49 -0
  42. package/dist/gui/server/server.d.ts +1 -0
  43. package/dist/gui/server/server.js +259 -0
  44. package/dist/gui/server/session-actions.d.ts +60 -0
  45. package/dist/gui/server/session-actions.js +218 -0
  46. package/dist/gui/server/session-entry-wait.d.ts +27 -0
  47. package/dist/gui/server/session-entry-wait.js +129 -0
  48. package/dist/gui/server/session-list.d.ts +2 -0
  49. package/dist/gui/server/session-list.js +11 -0
  50. package/dist/gui/server/shutdown.d.ts +10 -0
  51. package/dist/gui/server/shutdown.js +29 -0
  52. package/dist/gui/server/tool-invoke-ack.d.ts +17 -0
  53. package/dist/gui/server/tool-invoke-ack.js +26 -0
  54. package/dist/gui/server/tool-metadata.d.ts +93 -0
  55. package/dist/gui/server/tool-metadata.js +148 -0
  56. package/dist/gui/server/websocket.d.ts +9 -0
  57. package/dist/gui/server/websocket.js +124 -0
  58. package/dist/gui/server/writer-lock.d.ts +1 -0
  59. package/dist/gui/server/writer-lock.js +1 -0
  60. package/dist/gui/server/ws-hub.d.ts +50 -0
  61. package/dist/gui/server/ws-hub.js +284 -0
  62. package/dist/gui/shared/chat-events.d.ts +174 -0
  63. package/dist/gui/shared/chat-events.js +13 -0
  64. package/dist/gui/shared/event-reducer.d.ts +3 -0
  65. package/dist/gui/shared/event-reducer.js +187 -0
  66. package/dist/index.js +0 -1
  67. package/dist/infra/cache.js +0 -1
  68. package/dist/infra/freshness.js +0 -1
  69. package/dist/infra/http-client.js +1 -2
  70. package/dist/infra/index.js +0 -1
  71. package/dist/infra/market-calendar.js +0 -1
  72. package/dist/infra/native-dependencies.js +0 -1
  73. package/dist/infra/node-version.js +0 -1
  74. package/dist/infra/open-url.js +0 -1
  75. package/dist/infra/opencandle-paths.js +0 -1
  76. package/dist/infra/rate-limiter.js +0 -1
  77. package/dist/market-state/alert-conditions.js +0 -1
  78. package/dist/market-state/alert-runner.d.ts +1 -0
  79. package/dist/market-state/alert-runner.js +5 -4
  80. package/dist/market-state/daily-report.js +0 -1
  81. package/dist/market-state/local-automation-service.js +0 -1
  82. package/dist/market-state/notification-delivery.js +0 -1
  83. package/dist/market-state/resolve-for-mutation.js +0 -1
  84. package/dist/market-state/resolve.js +0 -1
  85. package/dist/market-state/service.d.ts +26 -21
  86. package/dist/market-state/service.js +175 -36
  87. package/dist/market-state/summaries.js +1 -13
  88. package/dist/memory/index.js +0 -1
  89. package/dist/memory/manager.js +0 -1
  90. package/dist/memory/preference-extractor.js +0 -1
  91. package/dist/memory/retrieval.js +0 -1
  92. package/dist/memory/sqlite.js +60 -11
  93. package/dist/memory/storage.js +0 -1
  94. package/dist/memory/tool-defaults.js +0 -1
  95. package/dist/memory/types.js +0 -1
  96. package/dist/monitor.js +0 -1
  97. package/dist/onboarding/connect.js +0 -1
  98. package/dist/onboarding/credential-interceptor.js +0 -1
  99. package/dist/onboarding/degradation-accumulator.js +0 -1
  100. package/dist/onboarding/prompt-user.d.ts +1 -1
  101. package/dist/onboarding/prompt-user.js +0 -1
  102. package/dist/onboarding/provider-status.js +0 -1
  103. package/dist/onboarding/providers.js +0 -1
  104. package/dist/onboarding/state.js +0 -1
  105. package/dist/onboarding/tool-helpers.js +0 -1
  106. package/dist/onboarding/tool-tags.js +0 -1
  107. package/dist/onboarding/validate-model-key.d.ts +17 -0
  108. package/dist/onboarding/validate-model-key.js +54 -0
  109. package/dist/onboarding/validation.js +0 -1
  110. package/dist/pi/opencandle-extension.js +2 -2
  111. package/dist/pi/session-action-dedupe.js +0 -1
  112. package/dist/pi/session-storage.js +0 -1
  113. package/dist/pi/session-writer-lock.js +0 -1
  114. package/dist/pi/session.js +0 -1
  115. package/dist/pi/setup.d.ts +2 -0
  116. package/dist/pi/setup.js +10 -3
  117. package/dist/pi/tool-adapter.js +0 -1
  118. package/dist/pi/tui-session-coordinator.js +0 -1
  119. package/dist/prompts/context-builder.js +1 -2
  120. package/dist/prompts/disclaimer.js +0 -1
  121. package/dist/prompts/policy-cards.js +0 -1
  122. package/dist/prompts/sections.js +0 -1
  123. package/dist/prompts/symbol-preflight.js +0 -1
  124. package/dist/prompts/workflow-prompts.js +0 -1
  125. package/dist/providers/alpha-vantage.js +2 -3
  126. package/dist/providers/coingecko.js +0 -1
  127. package/dist/providers/errors.js +0 -1
  128. package/dist/providers/exa-search.js +11 -10
  129. package/dist/providers/external-tool-command.js +0 -1
  130. package/dist/providers/external-tool-error.js +0 -1
  131. package/dist/providers/fear-greed.js +0 -1
  132. package/dist/providers/finnhub.js +0 -1
  133. package/dist/providers/fred.js +0 -1
  134. package/dist/providers/index.js +0 -1
  135. package/dist/providers/polymarket.js +0 -1
  136. package/dist/providers/provider-credential-error.js +0 -1
  137. package/dist/providers/reddit-cli.js +0 -1
  138. package/dist/providers/reddit.js +0 -1
  139. package/dist/providers/sec-edgar.js +0 -1
  140. package/dist/providers/tradingview.js +1 -2
  141. package/dist/providers/twitter-cli.js +0 -1
  142. package/dist/providers/twitter.js +0 -1
  143. package/dist/providers/web-search.js +15 -12
  144. package/dist/providers/with-fallback.js +0 -1
  145. package/dist/providers/wrap-provider.js +0 -1
  146. package/dist/providers/yahoo-finance.js +67 -4
  147. package/dist/routing/classify-intent.js +0 -1
  148. package/dist/routing/defaults.js +0 -1
  149. package/dist/routing/entity-extractor.js +2 -3
  150. package/dist/routing/fund-symbols.js +0 -1
  151. package/dist/routing/horizon.js +0 -1
  152. package/dist/routing/index.js +0 -1
  153. package/dist/routing/legacy-rule-router.js +0 -1
  154. package/dist/routing/planning.js +0 -1
  155. package/dist/routing/route-manifest.js +0 -1
  156. package/dist/routing/router-llm-client.d.ts +2 -2
  157. package/dist/routing/router-llm-client.js +0 -1
  158. package/dist/routing/router-prompt.js +0 -1
  159. package/dist/routing/router-types.js +0 -1
  160. package/dist/routing/router.js +1 -2
  161. package/dist/routing/slot-resolver.js +0 -1
  162. package/dist/routing/symbol-disambiguator.js +0 -1
  163. package/dist/routing/turn-context.js +0 -1
  164. package/dist/routing/types.js +0 -1
  165. package/dist/runtime/answer-contracts.js +0 -1
  166. package/dist/runtime/artifact-contracts.js +0 -1
  167. package/dist/runtime/evidence.js +0 -1
  168. package/dist/runtime/numeric-claims.js +0 -1
  169. package/dist/runtime/planning-evidence.js +0 -1
  170. package/dist/runtime/prompt-step.js +0 -1
  171. package/dist/runtime/provider-tracker.js +0 -1
  172. package/dist/runtime/run-context.js +0 -1
  173. package/dist/runtime/session-coordinator.js +0 -1
  174. package/dist/runtime/session-title.js +0 -1
  175. package/dist/runtime/tool-defaults-wrapper.js +0 -1
  176. package/dist/runtime/validation.js +0 -1
  177. package/dist/runtime/workflow-events.js +0 -1
  178. package/dist/runtime/workflow-runner.d.ts +1 -0
  179. package/dist/runtime/workflow-runner.js +8 -3
  180. package/dist/runtime/workflow-types.js +0 -1
  181. package/dist/sentiment/adapters/finnhub.js +0 -1
  182. package/dist/sentiment/adapters/reddit.js +0 -1
  183. package/dist/sentiment/adapters/twitter.js +0 -1
  184. package/dist/sentiment/adapters/web.js +0 -1
  185. package/dist/sentiment/index.js +4 -2
  186. package/dist/sentiment/insights.js +0 -1
  187. package/dist/sentiment/keywords.js +0 -1
  188. package/dist/sentiment/pipeline.js +0 -1
  189. package/dist/sentiment/scorer.js +0 -1
  190. package/dist/sentiment/store.js +0 -1
  191. package/dist/sentiment/trends.js +0 -1
  192. package/dist/sentiment/types.js +0 -1
  193. package/dist/system-prompt.js +0 -1
  194. package/dist/tool-kit.js +0 -1
  195. package/dist/tools/fundamentals/company-overview.d.ts +1 -1
  196. package/dist/tools/fundamentals/company-overview.js +2 -1
  197. package/dist/tools/fundamentals/comps.js +6 -4
  198. package/dist/tools/fundamentals/dcf.js +0 -1
  199. package/dist/tools/fundamentals/earnings.d.ts +1 -1
  200. package/dist/tools/fundamentals/earnings.js +2 -1
  201. package/dist/tools/fundamentals/financials.js +2 -1
  202. package/dist/tools/fundamentals/sec-filings.js +0 -1
  203. package/dist/tools/index.d.ts +116 -2
  204. package/dist/tools/index.js +0 -1
  205. package/dist/tools/interaction/ask-user.js +11 -1
  206. package/dist/tools/macro/event-probabilities.js +0 -1
  207. package/dist/tools/macro/fear-greed.d.ts +1 -1
  208. package/dist/tools/macro/fear-greed.js +0 -1
  209. package/dist/tools/macro/fred-data.d.ts +1 -1
  210. package/dist/tools/macro/fred-data.js +2 -1
  211. package/dist/tools/market/crypto-history.js +0 -1
  212. package/dist/tools/market/crypto-price.d.ts +2 -2
  213. package/dist/tools/market/crypto-price.js +0 -1
  214. package/dist/tools/market/screen-stocks.js +0 -1
  215. package/dist/tools/market/search-ticker.js +1 -2
  216. package/dist/tools/market/stock-history.js +0 -1
  217. package/dist/tools/market/stock-quote.d.ts +2 -2
  218. package/dist/tools/market/stock-quote.js +0 -1
  219. package/dist/tools/options/greeks.js +0 -1
  220. package/dist/tools/options/option-chain.d.ts +2 -2
  221. package/dist/tools/options/option-chain.js +0 -1
  222. package/dist/tools/portfolio/alerts.d.ts +2 -1
  223. package/dist/tools/portfolio/alerts.js +228 -2
  224. package/dist/tools/portfolio/correlation.js +23 -5
  225. package/dist/tools/portfolio/daily-report.js +0 -1
  226. package/dist/tools/portfolio/holdings-overlap.js +0 -1
  227. package/dist/tools/portfolio/notifications.js +0 -1
  228. package/dist/tools/portfolio/risk-analysis.d.ts +1 -1
  229. package/dist/tools/portfolio/risk-analysis.js +0 -1
  230. package/dist/tools/portfolio/tracker.d.ts +3 -1
  231. package/dist/tools/portfolio/tracker.js +57 -10
  232. package/dist/tools/portfolio/watchlist.d.ts +3 -6
  233. package/dist/tools/portfolio/watchlist.js +101 -110
  234. package/dist/tools/sentiment/insight-format.js +0 -1
  235. package/dist/tools/sentiment/query-match.js +0 -1
  236. package/dist/tools/sentiment/reddit-sentiment.js +0 -1
  237. package/dist/tools/sentiment/sentiment-summary.js +8 -4
  238. package/dist/tools/sentiment/sentiment-trend.d.ts +5 -1
  239. package/dist/tools/sentiment/sentiment-trend.js +6 -2
  240. package/dist/tools/sentiment/twitter-sentiment.js +0 -1
  241. package/dist/tools/sentiment/untrusted-text.js +0 -1
  242. package/dist/tools/sentiment/web-search.d.ts +1 -1
  243. package/dist/tools/sentiment/web-search.js +0 -1
  244. package/dist/tools/sentiment/web-sentiment.js +0 -1
  245. package/dist/tools/technical/backtest.js +0 -1
  246. package/dist/tools/technical/indicators.js +0 -1
  247. package/dist/types/fundamentals.js +0 -1
  248. package/dist/types/index.js +0 -1
  249. package/dist/types/macro.js +0 -1
  250. package/dist/types/market.d.ts +6 -0
  251. package/dist/types/market.js +0 -1
  252. package/dist/types/options.js +0 -1
  253. package/dist/types/portfolio.js +0 -1
  254. package/dist/types/prediction-markets.js +0 -1
  255. package/dist/types/sentiment.js +0 -1
  256. package/dist/workflows/compare-assets.js +0 -1
  257. package/dist/workflows/index.js +0 -1
  258. package/dist/workflows/options-screener.js +0 -1
  259. package/dist/workflows/portfolio-builder.js +0 -1
  260. package/gui/web/dist/assets/CatalogOverlay-CAc7e3Pf.js +1 -0
  261. package/gui/web/dist/assets/index-BOEKd9wT.css +2 -0
  262. package/gui/web/dist/assets/index-C-H05cQ2.js +65 -0
  263. package/gui/web/dist/index.html +2 -2
  264. package/package.json +11 -12
  265. package/dist/analysts/contracts.js.map +0 -1
  266. package/dist/analysts/orchestrator.js.map +0 -1
  267. package/dist/cli-main.js.map +0 -1
  268. package/dist/cli.js.map +0 -1
  269. package/dist/config.js.map +0 -1
  270. package/dist/doctor/cli-command.js.map +0 -1
  271. package/dist/doctor/render.js.map +0 -1
  272. package/dist/doctor/report.js.map +0 -1
  273. package/dist/index.js.map +0 -1
  274. package/dist/infra/cache.js.map +0 -1
  275. package/dist/infra/freshness.js.map +0 -1
  276. package/dist/infra/http-client.js.map +0 -1
  277. package/dist/infra/index.js.map +0 -1
  278. package/dist/infra/market-calendar.js.map +0 -1
  279. package/dist/infra/native-dependencies.js.map +0 -1
  280. package/dist/infra/node-version.js.map +0 -1
  281. package/dist/infra/open-url.js.map +0 -1
  282. package/dist/infra/opencandle-paths.js.map +0 -1
  283. package/dist/infra/rate-limiter.js.map +0 -1
  284. package/dist/market-state/alert-conditions.js.map +0 -1
  285. package/dist/market-state/alert-runner.js.map +0 -1
  286. package/dist/market-state/daily-report.js.map +0 -1
  287. package/dist/market-state/local-automation-service.js.map +0 -1
  288. package/dist/market-state/notification-delivery.js.map +0 -1
  289. package/dist/market-state/resolve-for-mutation.js.map +0 -1
  290. package/dist/market-state/resolve.js.map +0 -1
  291. package/dist/market-state/service.js.map +0 -1
  292. package/dist/market-state/summaries.js.map +0 -1
  293. package/dist/memory/index.js.map +0 -1
  294. package/dist/memory/manager.js.map +0 -1
  295. package/dist/memory/preference-extractor.js.map +0 -1
  296. package/dist/memory/retrieval.js.map +0 -1
  297. package/dist/memory/sqlite.js.map +0 -1
  298. package/dist/memory/storage.js.map +0 -1
  299. package/dist/memory/tool-defaults.js.map +0 -1
  300. package/dist/memory/types.js.map +0 -1
  301. package/dist/monitor.js.map +0 -1
  302. package/dist/onboarding/connect.js.map +0 -1
  303. package/dist/onboarding/credential-interceptor.js.map +0 -1
  304. package/dist/onboarding/degradation-accumulator.js.map +0 -1
  305. package/dist/onboarding/prompt-user.js.map +0 -1
  306. package/dist/onboarding/provider-status.js.map +0 -1
  307. package/dist/onboarding/providers.js.map +0 -1
  308. package/dist/onboarding/state.js.map +0 -1
  309. package/dist/onboarding/tool-helpers.js.map +0 -1
  310. package/dist/onboarding/tool-tags.js.map +0 -1
  311. package/dist/onboarding/validation.js.map +0 -1
  312. package/dist/pi/opencandle-extension.js.map +0 -1
  313. package/dist/pi/session-action-dedupe.js.map +0 -1
  314. package/dist/pi/session-storage.js.map +0 -1
  315. package/dist/pi/session-writer-lock.js.map +0 -1
  316. package/dist/pi/session.js.map +0 -1
  317. package/dist/pi/setup.js.map +0 -1
  318. package/dist/pi/tool-adapter.js.map +0 -1
  319. package/dist/pi/tui-session-coordinator.js.map +0 -1
  320. package/dist/prompts/context-builder.js.map +0 -1
  321. package/dist/prompts/disclaimer.js.map +0 -1
  322. package/dist/prompts/policy-cards.js.map +0 -1
  323. package/dist/prompts/sections.js.map +0 -1
  324. package/dist/prompts/symbol-preflight.js.map +0 -1
  325. package/dist/prompts/workflow-prompts.js.map +0 -1
  326. package/dist/providers/alpha-vantage.js.map +0 -1
  327. package/dist/providers/coingecko.js.map +0 -1
  328. package/dist/providers/errors.js.map +0 -1
  329. package/dist/providers/exa-search.js.map +0 -1
  330. package/dist/providers/external-tool-command.js.map +0 -1
  331. package/dist/providers/external-tool-error.js.map +0 -1
  332. package/dist/providers/fear-greed.js.map +0 -1
  333. package/dist/providers/finnhub.js.map +0 -1
  334. package/dist/providers/fred.js.map +0 -1
  335. package/dist/providers/index.js.map +0 -1
  336. package/dist/providers/polymarket.js.map +0 -1
  337. package/dist/providers/provider-credential-error.js.map +0 -1
  338. package/dist/providers/reddit-cli.js.map +0 -1
  339. package/dist/providers/reddit.js.map +0 -1
  340. package/dist/providers/sec-edgar.js.map +0 -1
  341. package/dist/providers/tradingview.js.map +0 -1
  342. package/dist/providers/twitter-cli.js.map +0 -1
  343. package/dist/providers/twitter.js.map +0 -1
  344. package/dist/providers/web-search.js.map +0 -1
  345. package/dist/providers/with-fallback.js.map +0 -1
  346. package/dist/providers/wrap-provider.js.map +0 -1
  347. package/dist/providers/yahoo-finance.js.map +0 -1
  348. package/dist/routing/classify-intent.js.map +0 -1
  349. package/dist/routing/defaults.js.map +0 -1
  350. package/dist/routing/entity-extractor.js.map +0 -1
  351. package/dist/routing/fund-symbols.js.map +0 -1
  352. package/dist/routing/horizon.js.map +0 -1
  353. package/dist/routing/index.js.map +0 -1
  354. package/dist/routing/legacy-rule-router.js.map +0 -1
  355. package/dist/routing/planning.js.map +0 -1
  356. package/dist/routing/route-manifest.js.map +0 -1
  357. package/dist/routing/router-llm-client.js.map +0 -1
  358. package/dist/routing/router-prompt.js.map +0 -1
  359. package/dist/routing/router-types.js.map +0 -1
  360. package/dist/routing/router.js.map +0 -1
  361. package/dist/routing/slot-resolver.js.map +0 -1
  362. package/dist/routing/symbol-disambiguator.js.map +0 -1
  363. package/dist/routing/turn-context.js.map +0 -1
  364. package/dist/routing/types.js.map +0 -1
  365. package/dist/runtime/answer-contracts.js.map +0 -1
  366. package/dist/runtime/artifact-contracts.js.map +0 -1
  367. package/dist/runtime/evidence.js.map +0 -1
  368. package/dist/runtime/numeric-claims.js.map +0 -1
  369. package/dist/runtime/planning-evidence.js.map +0 -1
  370. package/dist/runtime/prompt-step.js.map +0 -1
  371. package/dist/runtime/provider-tracker.js.map +0 -1
  372. package/dist/runtime/run-context.js.map +0 -1
  373. package/dist/runtime/session-coordinator.js.map +0 -1
  374. package/dist/runtime/session-title.js.map +0 -1
  375. package/dist/runtime/tool-defaults-wrapper.js.map +0 -1
  376. package/dist/runtime/validation.js.map +0 -1
  377. package/dist/runtime/workflow-events.js.map +0 -1
  378. package/dist/runtime/workflow-runner.js.map +0 -1
  379. package/dist/runtime/workflow-types.js.map +0 -1
  380. package/dist/sentiment/adapters/finnhub.js.map +0 -1
  381. package/dist/sentiment/adapters/reddit.js.map +0 -1
  382. package/dist/sentiment/adapters/twitter.js.map +0 -1
  383. package/dist/sentiment/adapters/web.js.map +0 -1
  384. package/dist/sentiment/index.js.map +0 -1
  385. package/dist/sentiment/insights.js.map +0 -1
  386. package/dist/sentiment/keywords.js.map +0 -1
  387. package/dist/sentiment/pipeline.js.map +0 -1
  388. package/dist/sentiment/scorer.js.map +0 -1
  389. package/dist/sentiment/store.js.map +0 -1
  390. package/dist/sentiment/trends.js.map +0 -1
  391. package/dist/sentiment/types.js.map +0 -1
  392. package/dist/system-prompt.js.map +0 -1
  393. package/dist/tool-kit.js.map +0 -1
  394. package/dist/tools/fundamentals/company-overview.js.map +0 -1
  395. package/dist/tools/fundamentals/comps.js.map +0 -1
  396. package/dist/tools/fundamentals/dcf.js.map +0 -1
  397. package/dist/tools/fundamentals/earnings.js.map +0 -1
  398. package/dist/tools/fundamentals/financials.js.map +0 -1
  399. package/dist/tools/fundamentals/sec-filings.js.map +0 -1
  400. package/dist/tools/index.js.map +0 -1
  401. package/dist/tools/interaction/ask-user.js.map +0 -1
  402. package/dist/tools/macro/event-probabilities.js.map +0 -1
  403. package/dist/tools/macro/fear-greed.js.map +0 -1
  404. package/dist/tools/macro/fred-data.js.map +0 -1
  405. package/dist/tools/market/crypto-history.js.map +0 -1
  406. package/dist/tools/market/crypto-price.js.map +0 -1
  407. package/dist/tools/market/screen-stocks.js.map +0 -1
  408. package/dist/tools/market/search-ticker.js.map +0 -1
  409. package/dist/tools/market/stock-history.js.map +0 -1
  410. package/dist/tools/market/stock-quote.js.map +0 -1
  411. package/dist/tools/options/greeks.js.map +0 -1
  412. package/dist/tools/options/option-chain.js.map +0 -1
  413. package/dist/tools/portfolio/alerts.js.map +0 -1
  414. package/dist/tools/portfolio/correlation.js.map +0 -1
  415. package/dist/tools/portfolio/daily-report.js.map +0 -1
  416. package/dist/tools/portfolio/holdings-overlap.js.map +0 -1
  417. package/dist/tools/portfolio/notifications.js.map +0 -1
  418. package/dist/tools/portfolio/risk-analysis.js.map +0 -1
  419. package/dist/tools/portfolio/tracker.js.map +0 -1
  420. package/dist/tools/portfolio/watchlist.js.map +0 -1
  421. package/dist/tools/sentiment/insight-format.js.map +0 -1
  422. package/dist/tools/sentiment/query-match.js.map +0 -1
  423. package/dist/tools/sentiment/reddit-sentiment.js.map +0 -1
  424. package/dist/tools/sentiment/sentiment-summary.js.map +0 -1
  425. package/dist/tools/sentiment/sentiment-trend.js.map +0 -1
  426. package/dist/tools/sentiment/twitter-sentiment.js.map +0 -1
  427. package/dist/tools/sentiment/untrusted-text.js.map +0 -1
  428. package/dist/tools/sentiment/web-search.js.map +0 -1
  429. package/dist/tools/sentiment/web-sentiment.js.map +0 -1
  430. package/dist/tools/technical/backtest.js.map +0 -1
  431. package/dist/tools/technical/indicators.js.map +0 -1
  432. package/dist/types/fundamentals.js.map +0 -1
  433. package/dist/types/index.js.map +0 -1
  434. package/dist/types/macro.js.map +0 -1
  435. package/dist/types/market.js.map +0 -1
  436. package/dist/types/options.js.map +0 -1
  437. package/dist/types/portfolio.js.map +0 -1
  438. package/dist/types/prediction-markets.js.map +0 -1
  439. package/dist/types/sentiment.js.map +0 -1
  440. package/dist/workflows/compare-assets.js.map +0 -1
  441. package/dist/workflows/index.js.map +0 -1
  442. package/dist/workflows/options-screener.js.map +0 -1
  443. package/dist/workflows/portfolio-builder.js.map +0 -1
  444. package/gui/server/ask-user-bridge.ts +0 -89
  445. package/gui/server/automation-heartbeat.ts +0 -97
  446. package/gui/server/background-quotes.ts +0 -127
  447. package/gui/server/chat-event-adapter.ts +0 -294
  448. package/gui/server/gui-session-manager.ts +0 -5
  449. package/gui/server/http-routes.ts +0 -1201
  450. package/gui/server/invoke-tool.ts +0 -490
  451. package/gui/server/live-chat-event-adapter.ts +0 -243
  452. package/gui/server/local-session-coordinator.ts +0 -97
  453. package/gui/server/market-state-api.ts +0 -331
  454. package/gui/server/model-setup.ts +0 -254
  455. package/gui/server/package.json +0 -5
  456. package/gui/server/private-api-access.ts +0 -62
  457. package/gui/server/projector.ts +0 -392
  458. package/gui/server/prompt-observation.ts +0 -58
  459. package/gui/server/quote-snapshot-store.ts +0 -50
  460. package/gui/server/server.ts +0 -289
  461. package/gui/server/session-actions.ts +0 -323
  462. package/gui/server/session-entry-wait.ts +0 -179
  463. package/gui/server/shutdown.ts +0 -47
  464. package/gui/server/tool-invoke-ack.ts +0 -49
  465. package/gui/server/tool-metadata.ts +0 -167
  466. package/gui/server/websocket.ts +0 -138
  467. package/gui/server/writer-lock.ts +0 -1
  468. package/gui/server/ws-hub.ts +0 -403
  469. package/gui/shared/chat-events.ts +0 -165
  470. package/gui/shared/event-reducer.ts +0 -220
  471. package/gui/web/dist/assets/CatalogOverlay-DZ1niyQm.js +0 -1
  472. package/gui/web/dist/assets/index-D4F9AJnn.css +0 -2
  473. package/gui/web/dist/assets/index-DtqMMBTr.js +0 -65
  474. package/src/analysts/contracts.ts +0 -176
  475. package/src/analysts/orchestrator.ts +0 -244
  476. package/src/cli-main.ts +0 -510
  477. package/src/cli.ts +0 -17
  478. package/src/config.ts +0 -272
  479. package/src/doctor/cli-command.ts +0 -83
  480. package/src/doctor/render.ts +0 -37
  481. package/src/doctor/report.ts +0 -638
  482. package/src/index.ts +0 -5
  483. package/src/infra/cache.ts +0 -127
  484. package/src/infra/freshness.ts +0 -165
  485. package/src/infra/http-client.ts +0 -134
  486. package/src/infra/index.ts +0 -14
  487. package/src/infra/market-calendar.ts +0 -193
  488. package/src/infra/native-dependencies.ts +0 -84
  489. package/src/infra/node-version.ts +0 -23
  490. package/src/infra/open-url.ts +0 -28
  491. package/src/infra/opencandle-paths.ts +0 -53
  492. package/src/infra/rate-limiter.ts +0 -77
  493. package/src/market-state/alert-conditions.ts +0 -82
  494. package/src/market-state/alert-runner.ts +0 -863
  495. package/src/market-state/daily-report.ts +0 -237
  496. package/src/market-state/local-automation-service.ts +0 -162
  497. package/src/market-state/notification-delivery.ts +0 -158
  498. package/src/market-state/resolve-for-mutation.ts +0 -24
  499. package/src/market-state/resolve.ts +0 -112
  500. package/src/market-state/service.ts +0 -2208
  501. package/src/market-state/summaries.ts +0 -75
  502. package/src/memory/index.ts +0 -10
  503. package/src/memory/manager.ts +0 -190
  504. package/src/memory/preference-extractor.ts +0 -106
  505. package/src/memory/retrieval.ts +0 -71
  506. package/src/memory/sqlite.ts +0 -577
  507. package/src/memory/storage.ts +0 -195
  508. package/src/memory/tool-defaults.ts +0 -108
  509. package/src/memory/types.ts +0 -71
  510. package/src/monitor.ts +0 -123
  511. package/src/onboarding/connect.ts +0 -177
  512. package/src/onboarding/credential-interceptor.ts +0 -122
  513. package/src/onboarding/degradation-accumulator.ts +0 -77
  514. package/src/onboarding/prompt-user.ts +0 -85
  515. package/src/onboarding/provider-status.ts +0 -382
  516. package/src/onboarding/providers.ts +0 -442
  517. package/src/onboarding/state.ts +0 -216
  518. package/src/onboarding/tool-helpers.ts +0 -104
  519. package/src/onboarding/tool-tags.ts +0 -244
  520. package/src/onboarding/validation.ts +0 -152
  521. package/src/pi/opencandle-extension.ts +0 -1294
  522. package/src/pi/session-action-dedupe.ts +0 -155
  523. package/src/pi/session-storage.ts +0 -5
  524. package/src/pi/session-writer-lock.ts +0 -426
  525. package/src/pi/session.ts +0 -84
  526. package/src/pi/setup.ts +0 -399
  527. package/src/pi/tool-adapter.ts +0 -49
  528. package/src/pi/tui-session-coordinator.ts +0 -351
  529. package/src/prompts/context-builder.ts +0 -326
  530. package/src/prompts/disclaimer.ts +0 -9
  531. package/src/prompts/policy-cards.ts +0 -228
  532. package/src/prompts/sections.ts +0 -46
  533. package/src/prompts/symbol-preflight.ts +0 -80
  534. package/src/prompts/workflow-prompts.ts +0 -504
  535. package/src/providers/alpha-vantage.ts +0 -340
  536. package/src/providers/coingecko.ts +0 -95
  537. package/src/providers/errors.ts +0 -9
  538. package/src/providers/exa-search.ts +0 -375
  539. package/src/providers/external-tool-command.ts +0 -164
  540. package/src/providers/external-tool-error.ts +0 -20
  541. package/src/providers/fear-greed.ts +0 -45
  542. package/src/providers/finnhub.ts +0 -125
  543. package/src/providers/fred.ts +0 -83
  544. package/src/providers/index.ts +0 -17
  545. package/src/providers/polymarket.ts +0 -214
  546. package/src/providers/provider-credential-error.ts +0 -23
  547. package/src/providers/reddit-cli.ts +0 -286
  548. package/src/providers/reddit.ts +0 -106
  549. package/src/providers/sec-edgar.ts +0 -326
  550. package/src/providers/tradingview.ts +0 -399
  551. package/src/providers/twitter-cli.ts +0 -202
  552. package/src/providers/twitter.ts +0 -102
  553. package/src/providers/web-search.ts +0 -303
  554. package/src/providers/with-fallback.ts +0 -42
  555. package/src/providers/wrap-provider.ts +0 -105
  556. package/src/providers/yahoo-finance.ts +0 -984
  557. package/src/routing/classify-intent.ts +0 -380
  558. package/src/routing/defaults.ts +0 -29
  559. package/src/routing/entity-extractor.ts +0 -557
  560. package/src/routing/fund-symbols.ts +0 -58
  561. package/src/routing/horizon.ts +0 -7
  562. package/src/routing/index.ts +0 -70
  563. package/src/routing/legacy-rule-router.ts +0 -13
  564. package/src/routing/planning.ts +0 -829
  565. package/src/routing/route-manifest.ts +0 -308
  566. package/src/routing/router-llm-client.ts +0 -64
  567. package/src/routing/router-prompt.ts +0 -159
  568. package/src/routing/router-types.ts +0 -84
  569. package/src/routing/router.ts +0 -1332
  570. package/src/routing/slot-resolver.ts +0 -213
  571. package/src/routing/symbol-disambiguator.ts +0 -72
  572. package/src/routing/turn-context.ts +0 -108
  573. package/src/routing/types.ts +0 -77
  574. package/src/runtime/answer-contracts.ts +0 -693
  575. package/src/runtime/artifact-contracts.ts +0 -77
  576. package/src/runtime/evidence.ts +0 -78
  577. package/src/runtime/numeric-claims.ts +0 -108
  578. package/src/runtime/planning-evidence.ts +0 -597
  579. package/src/runtime/prompt-step.ts +0 -185
  580. package/src/runtime/provider-tracker.ts +0 -40
  581. package/src/runtime/run-context.ts +0 -32
  582. package/src/runtime/session-coordinator.ts +0 -1037
  583. package/src/runtime/session-title.ts +0 -60
  584. package/src/runtime/tool-defaults-wrapper.ts +0 -43
  585. package/src/runtime/validation.ts +0 -211
  586. package/src/runtime/workflow-events.ts +0 -77
  587. package/src/runtime/workflow-runner.ts +0 -182
  588. package/src/runtime/workflow-types.ts +0 -105
  589. package/src/sentiment/adapters/finnhub.ts +0 -49
  590. package/src/sentiment/adapters/reddit.ts +0 -65
  591. package/src/sentiment/adapters/twitter.ts +0 -36
  592. package/src/sentiment/adapters/web.ts +0 -44
  593. package/src/sentiment/index.ts +0 -49
  594. package/src/sentiment/insights.ts +0 -269
  595. package/src/sentiment/keywords.ts +0 -31
  596. package/src/sentiment/pipeline.ts +0 -91
  597. package/src/sentiment/scorer.ts +0 -89
  598. package/src/sentiment/store.ts +0 -260
  599. package/src/sentiment/trends.ts +0 -96
  600. package/src/sentiment/types.ts +0 -112
  601. package/src/system-prompt.ts +0 -115
  602. package/src/tool-kit.ts +0 -69
  603. package/src/tools/AGENTS.md +0 -36
  604. package/src/tools/fundamentals/company-overview.ts +0 -64
  605. package/src/tools/fundamentals/comps.ts +0 -180
  606. package/src/tools/fundamentals/dcf.ts +0 -447
  607. package/src/tools/fundamentals/earnings.ts +0 -57
  608. package/src/tools/fundamentals/financials.ts +0 -63
  609. package/src/tools/fundamentals/sec-filings.ts +0 -105
  610. package/src/tools/index.ts +0 -104
  611. package/src/tools/interaction/ask-user.ts +0 -93
  612. package/src/tools/macro/event-probabilities.ts +0 -141
  613. package/src/tools/macro/fear-greed.ts +0 -41
  614. package/src/tools/macro/fred-data.ts +0 -92
  615. package/src/tools/market/crypto-history.ts +0 -72
  616. package/src/tools/market/crypto-price.ts +0 -65
  617. package/src/tools/market/screen-stocks.ts +0 -290
  618. package/src/tools/market/search-ticker.ts +0 -254
  619. package/src/tools/market/stock-history.ts +0 -104
  620. package/src/tools/market/stock-quote.ts +0 -73
  621. package/src/tools/options/greeks.ts +0 -81
  622. package/src/tools/options/option-chain.ts +0 -134
  623. package/src/tools/portfolio/alerts.ts +0 -457
  624. package/src/tools/portfolio/correlation.ts +0 -189
  625. package/src/tools/portfolio/daily-report.ts +0 -107
  626. package/src/tools/portfolio/holdings-overlap.ts +0 -139
  627. package/src/tools/portfolio/notifications.ts +0 -45
  628. package/src/tools/portfolio/risk-analysis.ts +0 -173
  629. package/src/tools/portfolio/tracker.ts +0 -308
  630. package/src/tools/portfolio/watchlist.ts +0 -288
  631. package/src/tools/sentiment/insight-format.ts +0 -50
  632. package/src/tools/sentiment/query-match.ts +0 -117
  633. package/src/tools/sentiment/reddit-sentiment.ts +0 -403
  634. package/src/tools/sentiment/sentiment-summary.ts +0 -383
  635. package/src/tools/sentiment/sentiment-trend.ts +0 -75
  636. package/src/tools/sentiment/twitter-sentiment.ts +0 -287
  637. package/src/tools/sentiment/untrusted-text.ts +0 -21
  638. package/src/tools/sentiment/web-search.ts +0 -186
  639. package/src/tools/sentiment/web-sentiment.ts +0 -96
  640. package/src/tools/technical/backtest.ts +0 -336
  641. package/src/tools/technical/indicators.ts +0 -281
  642. package/src/types/fundamentals.ts +0 -47
  643. package/src/types/index.ts +0 -26
  644. package/src/types/macro.ts +0 -27
  645. package/src/types/market.ts +0 -46
  646. package/src/types/options.ts +0 -53
  647. package/src/types/portfolio.ts +0 -83
  648. package/src/types/prediction-markets.ts +0 -13
  649. package/src/types/sentiment.ts +0 -129
  650. package/src/workflows/compare-assets.ts +0 -89
  651. package/src/workflows/index.ts +0 -3
  652. package/src/workflows/options-screener.ts +0 -125
  653. package/src/workflows/portfolio-builder.ts +0 -63
@@ -1,447 +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 { getFinancials, getOverview } from "../../providers/alpha-vantage.js";
5
- import { ProviderCredentialError } from "../../providers/provider-credential-error.js";
6
- import { wrapProvider } from "../../providers/wrap-provider.js";
7
- import { getQuote, getYahooFinancials } from "../../providers/yahoo-finance.js";
8
- import type { ProviderResult } from "../../runtime/evidence.js";
9
- import type { FinancialStatement } from "../../types/fundamentals.js";
10
-
11
- export interface DCFResult {
12
- intrinsicValue: number;
13
- enterpriseValue: number;
14
- terminalValue: number;
15
- netDebt: number;
16
- projectedCashFlows: Array<{ year: number; fcf: number; presentValue: number }>;
17
- assumptions: {
18
- fcf: number;
19
- growthRate: number;
20
- discountRate: number;
21
- terminalGrowth: number;
22
- years: number;
23
- };
24
- sensitivityTable: Array<{ growthRate: number; discountRate: number; intrinsicValue: number }>;
25
- warnings: string[];
26
- }
27
-
28
- export interface DCFParams {
29
- freeCashFlow: number;
30
- growthRate: number;
31
- discountRate: number;
32
- terminalGrowth: number;
33
- years: number;
34
- netDebt: number;
35
- sharesOutstanding: number;
36
- }
37
-
38
- export function computeDCF(params: DCFParams): DCFResult {
39
- const {
40
- freeCashFlow,
41
- growthRate,
42
- discountRate,
43
- terminalGrowth,
44
- years,
45
- netDebt,
46
- sharesOutstanding,
47
- } = params;
48
-
49
- // Gordon Growth requires discount > terminal growth; a non-positive spread
50
- // divides by zero or flips the terminal value's sign.
51
- if (discountRate <= terminalGrowth) {
52
- throw new Error(
53
- `Gordon Growth constraint violated: terminal growth (${(terminalGrowth * 100).toFixed(1)}%) must be below the discount rate (${(discountRate * 100).toFixed(1)}%).`,
54
- );
55
- }
56
-
57
- // Project future cash flows (mid-year convention: discount at year-0.5)
58
- const projectedCashFlows: Array<{ year: number; fcf: number; presentValue: number }> = [];
59
- for (let y = 1; y <= years; y++) {
60
- const fcf = freeCashFlow * (1 + growthRate) ** y;
61
- const pv = fcf / (1 + discountRate) ** (y - 0.5); // mid-year convention
62
- projectedCashFlows.push({ year: y, fcf, presentValue: pv });
63
- }
64
-
65
- // Terminal value (Gordon Growth Model), discounted at full year (end of projection)
66
- const finalFCF = freeCashFlow * (1 + growthRate) ** years;
67
- const terminalValue = (finalFCF * (1 + terminalGrowth)) / (discountRate - terminalGrowth);
68
- const pvTerminal = terminalValue / (1 + discountRate) ** years;
69
-
70
- // Enterprise value
71
- const sumPVs = projectedCashFlows.reduce((s, cf) => s + cf.presentValue, 0);
72
- const enterpriseValue = sumPVs + pvTerminal;
73
-
74
- // Equity value → per share
75
- const equityValue = enterpriseValue - netDebt;
76
- const intrinsicValue = equityValue / sharesOutstanding;
77
-
78
- // Sensitivity table: vary growth ±2% and discount ±2%
79
- const sensitivityTable: Array<{
80
- growthRate: number;
81
- discountRate: number;
82
- intrinsicValue: number;
83
- }> = [];
84
- for (let gDelta = -0.02; gDelta <= 0.02; gDelta += 0.01) {
85
- for (let dDelta = -0.02; dDelta <= 0.02; dDelta += 0.01) {
86
- const g = growthRate + gDelta;
87
- const d = discountRate + dDelta;
88
- if (d <= terminalGrowth || d <= 0 || g < 0) continue;
89
- const sensResult = computeDCFSimple(
90
- freeCashFlow,
91
- g,
92
- d,
93
- terminalGrowth,
94
- years,
95
- netDebt,
96
- sharesOutstanding,
97
- );
98
- sensitivityTable.push({ growthRate: g, discountRate: d, intrinsicValue: sensResult });
99
- }
100
- }
101
-
102
- // Validation warnings (inspired by Anthropic financial plugins + Dexter)
103
- const warnings: string[] = [];
104
- const tvPctOfEV = pvTerminal / enterpriseValue;
105
- if (tvPctOfEV > 0.85) {
106
- warnings.push(
107
- `Terminal value is ${(tvPctOfEV * 100).toFixed(0)}% of enterprise value (typical: 40-80%). The valuation is heavily dependent on terminal assumptions.`,
108
- );
109
- }
110
- const spreadPct = discountRate - terminalGrowth;
111
- if (spreadPct < 0.02) {
112
- warnings.push(
113
- `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.`,
114
- );
115
- }
116
- if (discountRate < 0.05 || discountRate > 0.2) {
117
- warnings.push(
118
- `Discount rate of ${(discountRate * 100).toFixed(1)}% is outside typical WACC range (5-20%).`,
119
- );
120
- }
121
- if (growthRate > 0.2) {
122
- warnings.push(
123
- `Growth rate of ${(growthRate * 100).toFixed(1)}% exceeds 20%. High growth is difficult to sustain — consider a multi-stage model.`,
124
- );
125
- }
126
-
127
- return {
128
- intrinsicValue,
129
- enterpriseValue,
130
- terminalValue,
131
- netDebt,
132
- projectedCashFlows,
133
- assumptions: {
134
- fcf: freeCashFlow,
135
- growthRate,
136
- discountRate,
137
- terminalGrowth,
138
- years,
139
- },
140
- sensitivityTable,
141
- warnings,
142
- };
143
- }
144
-
145
- function computeDCFSimple(
146
- fcf: number,
147
- g: number,
148
- d: number,
149
- tg: number,
150
- years: number,
151
- debt: number,
152
- shares: number,
153
- ): number {
154
- let sumPV = 0;
155
- for (let y = 1; y <= years; y++) {
156
- sumPV += (fcf * (1 + g) ** y) / (1 + d) ** (y - 0.5); // mid-year convention
157
- }
158
- const finalFCF = fcf * (1 + g) ** years;
159
- const tv = (finalFCF * (1 + tg)) / (d - tg);
160
- const pvTV = tv / (1 + d) ** years;
161
- return (sumPV + pvTV - debt) / shares;
162
- }
163
-
164
- export function computeNetDebt(f: FinancialStatement): number | null {
165
- if (f.totalDebt != null && f.cashAndEquivalents != null) {
166
- return f.totalDebt - f.cashAndEquivalents;
167
- }
168
- return null;
169
- }
170
-
171
- async function optionalAlphaVantage<T>(
172
- apiKey: string | undefined,
173
- fn: (apiKey: string) => Promise<T>,
174
- ): Promise<ProviderResult<T>> {
175
- if (!apiKey) {
176
- return {
177
- status: "unavailable",
178
- reason: "Alpha Vantage API key not configured",
179
- provider: "alphavantage",
180
- };
181
- }
182
- try {
183
- return await wrapProvider("alphavantage", () => fn(apiKey));
184
- } catch (error) {
185
- if (error instanceof ProviderCredentialError) {
186
- return {
187
- status: "unavailable",
188
- reason: `Alpha Vantage credential ${error.reason}`,
189
- provider: "alphavantage",
190
- };
191
- }
192
- throw error;
193
- }
194
- }
195
-
196
- const params = Type.Object({
197
- symbol: Type.String({ description: "Stock ticker symbol (e.g. AAPL, MSFT)" }),
198
- growth_rate: Type.Optional(
199
- Type.Number({
200
- description:
201
- "Annual FCF growth rate as decimal (e.g. 0.10 for 10%). If omitted, estimated from historical data.",
202
- }),
203
- ),
204
- discount_rate: Type.Optional(
205
- Type.Number({ description: "Discount rate / WACC as decimal (default: 0.10 for 10%)" }),
206
- ),
207
- terminal_growth: Type.Optional(
208
- Type.Number({ description: "Terminal growth rate as decimal (default: 0.03 for 3%)" }),
209
- ),
210
- projection_years: Type.Optional(
211
- Type.Number({ description: "Years to project forward (default: 5)" }),
212
- ),
213
- });
214
-
215
- export const dcfTool: AgentTool<typeof params> = {
216
- name: "compute_dcf",
217
- label: "DCF Valuation",
218
- description:
219
- "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.",
220
- parameters: params,
221
- async execute(_toolCallId, args) {
222
- const symbol = args.symbol.toUpperCase();
223
- const config = getConfig();
224
- const alphaVantageApiKey = config.alphaVantageApiKey;
225
-
226
- const [alphaVantageFinancialsResult, quoteResult] = await Promise.all([
227
- optionalAlphaVantage(alphaVantageApiKey, (apiKey) => getFinancials(symbol, apiKey)),
228
- wrapProvider("yahoo", () => getQuote(symbol)),
229
- ]);
230
-
231
- const missing: string[] = [];
232
- if (quoteResult.status === "unavailable") missing.push(`stock quote (${quoteResult.reason})`);
233
-
234
- if (quoteResult.status === "unavailable") {
235
- return {
236
- content: [
237
- {
238
- type: "text",
239
- text: `⚠ DCF valuation unavailable for ${symbol}. Missing: ${missing.join(", ")}. Both financials and current price are required.`,
240
- },
241
- ],
242
- details: null,
243
- };
244
- }
245
-
246
- const quote = quoteResult.data;
247
- if (quote.price <= 0) {
248
- return {
249
- content: [
250
- {
251
- type: "text",
252
- text: `⚠ DCF valuation unavailable for ${symbol}. Missing: current stock price. DCF output requires a real current quote price.`,
253
- },
254
- ],
255
- details: null,
256
- };
257
- }
258
-
259
- let financialsSource = "Alpha Vantage";
260
- let financials: FinancialStatement[];
261
- if (alphaVantageFinancialsResult.status === "ok" && !alphaVantageFinancialsResult.stale) {
262
- financials = alphaVantageFinancialsResult.data;
263
- } else {
264
- const alphaVantageReason =
265
- alphaVantageFinancialsResult.status === "ok"
266
- ? `stale cached financial statements${
267
- alphaVantageFinancialsResult.timestamp
268
- ? ` from ${alphaVantageFinancialsResult.timestamp}`
269
- : ""
270
- }`
271
- : alphaVantageFinancialsResult.reason;
272
- const yahooFinancialsResult = await wrapProvider("yahoo", () => getYahooFinancials(symbol));
273
- if (yahooFinancialsResult.status === "unavailable") {
274
- return {
275
- content: [
276
- {
277
- type: "text",
278
- text: `⚠ DCF valuation unavailable for ${symbol}. Missing: financial statements (Alpha Vantage: ${alphaVantageReason}; Yahoo Finance: ${yahooFinancialsResult.reason}). Both financials and current price are required.`,
279
- },
280
- ],
281
- details: null,
282
- };
283
- }
284
- if (yahooFinancialsResult.stale) {
285
- const cachedAt = yahooFinancialsResult.timestamp
286
- ? ` from ${yahooFinancialsResult.timestamp}`
287
- : "";
288
- return {
289
- content: [
290
- {
291
- type: "text",
292
- text: `⚠ DCF valuation unavailable for ${symbol}. Yahoo Finance returned stale cached financial statements${cachedAt} after Alpha Vantage could not provide fresh financial statements (${alphaVantageReason}). DCF output requires fresh financial statements and a current price.`,
293
- },
294
- ],
295
- details: null,
296
- };
297
- }
298
- financials = yahooFinancialsResult.data;
299
- financialsSource = "Yahoo Finance";
300
- }
301
-
302
- const latestFCF = financials[0]?.freeCashFlow ?? 0;
303
- if (latestFCF <= 0) {
304
- return {
305
- content: [
306
- {
307
- type: "text",
308
- text: `${symbol} has negative or zero free cash flow ($${latestFCF.toLocaleString()}). DCF is not meaningful for companies without positive FCF.`,
309
- },
310
- ],
311
- details: null,
312
- };
313
- }
314
-
315
- // Estimate growth from historical FCF if not provided
316
- let growthRate = args.growth_rate ?? 0.1;
317
- if (!args.growth_rate && financials.length >= 2) {
318
- const olderFCF = financials[1]?.freeCashFlow;
319
- if (olderFCF && olderFCF > 0) {
320
- growthRate = Math.max(0.02, Math.min(0.25, (latestFCF - olderFCF) / olderFCF));
321
- }
322
- }
323
-
324
- const discountRate = args.discount_rate ?? 0.1;
325
- const terminalGrowth = args.terminal_growth ?? 0.03;
326
- if (discountRate <= terminalGrowth) {
327
- return {
328
- content: [
329
- {
330
- type: "text",
331
- 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.`,
332
- },
333
- ],
334
- details: null,
335
- };
336
- }
337
-
338
- const years = args.projection_years ?? 5;
339
- // Prefer an actual reported share count, then derive from market cap
340
- // only when needed. Never substitute a placeholder share count.
341
- const statementSharesOutstanding = financials[0]?.sharesOutstanding;
342
- let marketCap = quote.marketCap > 0 ? quote.marketCap : 0;
343
- let sharesOutstanding =
344
- statementSharesOutstanding && statementSharesOutstanding > 0 ? statementSharesOutstanding : 0;
345
- if (sharesOutstanding <= 0 && marketCap <= 0) {
346
- const overviewResult = await optionalAlphaVantage(alphaVantageApiKey, (apiKey) =>
347
- getOverview(symbol, apiKey),
348
- );
349
- if (overviewResult.status === "ok" && overviewResult.data.marketCap > 0) {
350
- marketCap = overviewResult.data.marketCap;
351
- }
352
- }
353
- if (sharesOutstanding <= 0 && quote.price > 0 && marketCap > 0) {
354
- sharesOutstanding = marketCap / quote.price;
355
- }
356
- if (sharesOutstanding <= 0) {
357
- return {
358
- content: [
359
- {
360
- type: "text",
361
- text: `⚠ Cannot compute a per-share DCF for ${symbol}: shares outstanding are unavailable from financial statements and 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.`,
362
- },
363
- ],
364
- details: null,
365
- };
366
- }
367
- // Signed on purpose: net cash (negative net debt) adds to equity value.
368
- // Omit the adjustment if debt/cash fields are missing; assets minus
369
- // liabilities is book equity, not a net-cash proxy.
370
- const computedNetDebt = financials[0] ? computeNetDebt(financials[0]) : null;
371
- const netDebt = computedNetDebt ?? 0;
372
-
373
- const result = computeDCF({
374
- freeCashFlow: latestFCF,
375
- growthRate,
376
- discountRate,
377
- terminalGrowth,
378
- years,
379
- netDebt,
380
- sharesOutstanding,
381
- });
382
- if (computedNetDebt == null) {
383
- result.warnings.push(
384
- "Net debt adjustment omitted because total debt and cash equivalents were unavailable.",
385
- );
386
- }
387
-
388
- const marginOfSafety = (result.intrinsicValue - quote.price) / result.intrinsicValue;
389
- const upside = (result.intrinsicValue - quote.price) / quote.price;
390
-
391
- const lines = [
392
- `**${symbol} DCF Valuation**`,
393
- ``,
394
- `Current Price: $${quote.price.toFixed(2)}`,
395
- `Intrinsic Value: $${result.intrinsicValue.toFixed(2)}`,
396
- `Margin of Safety: ${(marginOfSafety * 100).toFixed(1)}%`,
397
- `Upside/Downside: ${upside >= 0 ? "+" : ""}${(upside * 100).toFixed(1)}%`,
398
- ``,
399
- `**Assumptions**`,
400
- `Financial statements source: ${financialsSource}`,
401
- `Free Cash Flow: $${(latestFCF / 1e9).toFixed(2)}B`,
402
- `Growth Rate: ${(growthRate * 100).toFixed(1)}%`,
403
- `Discount Rate (WACC): ${(discountRate * 100).toFixed(1)}%`,
404
- `Terminal Growth: ${(terminalGrowth * 100).toFixed(1)}%`,
405
- `Projection: ${years} years`,
406
- ``,
407
- `**Projected Cash Flows**`,
408
- ...result.projectedCashFlows.map(
409
- (cf) =>
410
- ` Year ${cf.year}: FCF $${(cf.fcf / 1e9).toFixed(2)}B → PV $${(cf.presentValue / 1e9).toFixed(2)}B`,
411
- ),
412
- ` Terminal Value: $${(result.terminalValue / 1e9).toFixed(2)}B`,
413
- ` Enterprise Value: $${(result.enterpriseValue / 1e9).toFixed(2)}B`,
414
- ``,
415
- `**Sensitivity Table** (Intrinsic Value at different Growth/Discount rates)`,
416
- ...formatSensitivityTable(result.sensitivityTable),
417
- ...(result.warnings.length > 0
418
- ? ["", "**Warnings**", ...result.warnings.map((warning) => `- ${warning}`)]
419
- : []),
420
- ];
421
-
422
- return {
423
- content: [{ type: "text", text: lines.join("\n") }],
424
- details: { ...result, currentPrice: quote.price, marginOfSafety, upside },
425
- };
426
- },
427
- };
428
-
429
- function formatSensitivityTable(
430
- table: Array<{ growthRate: number; discountRate: number; intrinsicValue: number }>,
431
- ): string[] {
432
- if (table.length === 0) return [" (insufficient data for sensitivity table)"];
433
-
434
- const discountRates = [...new Set(table.map((e) => e.discountRate))].sort((a, b) => a - b);
435
- const growthRates = [...new Set(table.map((e) => e.growthRate))].sort((a, b) => a - b);
436
-
437
- const header = ` ${"Growth↓/WACC→".padEnd(14)} ${discountRates.map((d) => `${(d * 100).toFixed(0)}%`.padStart(8)).join("")}`;
438
- const rows = growthRates.map((g) => {
439
- const cells = discountRates.map((d) => {
440
- const entry = table.find((e) => e.growthRate === g && e.discountRate === d);
441
- return entry ? `$${entry.intrinsicValue.toFixed(0)}`.padStart(8) : "N/A".padStart(8);
442
- });
443
- return ` ${`${(g * 100).toFixed(0)}%`.padEnd(14)} ${cells.join("")}`;
444
- });
445
-
446
- return [header, ...rows];
447
- }
@@ -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
- };
@@ -1,63 +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 } from "../../providers/alpha-vantage.js";
6
- import { wrapProvider } from "../../providers/wrap-provider.js";
7
- import type { FinancialStatement } 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 financialsTool: AgentTool<
14
- typeof params,
15
- FinancialStatement[] | { credentialRequired: unknown }
16
- > = {
17
- name: "get_financials",
18
- label: "Financial Statements",
19
- description:
20
- "Get annual income statement data: revenue, gross profit, operating income, net income, and EPS. 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
- getFinancials(args.symbol.toUpperCase(), apiKey),
27
- );
28
- if (result.status === "unavailable") {
29
- return {
30
- content: [
31
- {
32
- type: "text",
33
- text: `⚠ Financial statements unavailable for ${args.symbol.toUpperCase()} (${result.reason}). Analysis will proceed without financials.`,
34
- },
35
- ],
36
- details: [],
37
- };
38
- }
39
- const statements = result.data;
40
- if (statements.length === 0) {
41
- return {
42
- content: [{ type: "text", text: `No financial data found for ${args.symbol}` }],
43
- details: [],
44
- };
45
- }
46
-
47
- const header = `${args.symbol.toUpperCase()} — Annual Income Statement (${statements.length} years)`;
48
- const rows = statements.map(
49
- (s) =>
50
- `${s.fiscalDate} | Rev: $${fmt(s.revenue)} | GP: $${fmt(s.grossProfit)} | OpInc: $${fmt(s.operatingIncome)} | Net: $${fmt(s.netIncome)}`,
51
- );
52
-
53
- const text = [header, ...rows].join("\n");
54
- return { content: [{ type: "text", text }], details: statements };
55
- });
56
- },
57
- };
58
-
59
- function fmt(n: number): string {
60
- if (n >= 1e9) return `${(n / 1e9).toFixed(2)}B`;
61
- if (n >= 1e6) return `${(n / 1e6).toFixed(2)}M`;
62
- return n.toLocaleString();
63
- }
@@ -1,105 +0,0 @@
1
- import type { AgentTool } from "@earendil-works/pi-agent-core";
2
- import { Type } from "@sinclair/typebox";
3
- import { searchFilings } from "../../providers/sec-edgar.js";
4
- import { wrapProvider } from "../../providers/wrap-provider.js";
5
- import { renderUntrustedText, untrustedContentHeader } from "../sentiment/untrusted-text.js";
6
-
7
- const params = Type.Object({
8
- symbol: Type.String({ description: "Stock ticker symbol (e.g. AAPL, MSFT, TSLA)" }),
9
- form_types: Type.Optional(
10
- Type.Array(Type.String(), {
11
- description:
12
- "Filing types to search: 10-K (annual), 10-Q (quarterly), 8-K (material events). Default: all three.",
13
- }),
14
- ),
15
- limit: Type.Optional(
16
- Type.Number({ description: "Maximum number of filings to return (default: 10)" }),
17
- ),
18
- include_snippets: Type.Optional(
19
- Type.Boolean({
20
- description:
21
- "Include short filing-text evidence snippets for risk/MD&A/litigation themes. Default: true.",
22
- }),
23
- ),
24
- });
25
-
26
- export const secFilingsTool: AgentTool<typeof params> = {
27
- name: "get_sec_filings",
28
- label: "SEC Filings",
29
- description:
30
- "Search SEC EDGAR for company filings (10-K annual reports, 10-Q quarterly reports, 8-K material events). Returns filing dates, types, and direct links to the documents. Free API, no key required.",
31
- parameters: params,
32
- async execute(_toolCallId, args) {
33
- const symbol = args.symbol.toUpperCase();
34
- const formTypes = args.form_types ?? ["10-K", "10-Q", "8-K"];
35
- const limit = args.limit ?? 10;
36
- const includeSnippets = args.include_snippets ?? true;
37
-
38
- const result = await wrapProvider("sec-edgar", () =>
39
- searchFilings(symbol, formTypes, limit, { includeSnippets, snippetLimitPerFiling: 2 }),
40
- );
41
- if (result.status === "unavailable") {
42
- return {
43
- content: [
44
- { type: "text", text: `⚠ SEC filings unavailable for ${symbol} (${result.reason}).` },
45
- ],
46
- details: null,
47
- };
48
- }
49
- const filings = result.data;
50
-
51
- if (filings.length === 0) {
52
- return {
53
- content: [
54
- {
55
- type: "text",
56
- text: `No SEC filings found for ${symbol}. Verify the ticker is a US-listed company.`,
57
- },
58
- ],
59
- details: null,
60
- };
61
- }
62
-
63
- const lines = [
64
- `**${symbol} SEC Filings** (${filings.length} found)`,
65
- ``,
66
- ...filings.map(
67
- (f) =>
68
- ` ${f.formType.padEnd(6)} | Filed: ${f.filedDate} | Period: ${f.periodOfReport || "N/A"} | ${f.entityName}`,
69
- ),
70
- ``,
71
- `Links:`,
72
- ...filings.map((f) => ` ${f.formType} (${f.filedDate}): ${f.url}`),
73
- ``,
74
- `Primary documents:`,
75
- ...filings.flatMap((f) => [
76
- ` ${f.formType} (${f.filedDate}): ${f.primaryDocumentUrl ?? "N/A"}`,
77
- ...(f.items?.length ? [` 8-K items: ${f.items.join(", ")}`] : []),
78
- ]),
79
- ...(includeSnippets
80
- ? [
81
- ``,
82
- `Evidence snippets (short excerpts; review source filing for full context):`,
83
- untrustedContentHeader("SEC filing snippets"),
84
- ...filings.flatMap((f) =>
85
- f.evidenceWarning
86
- ? [` ${f.formType} ${f.filedDate}: ${f.evidenceWarning}`]
87
- : f.evidenceSnippets?.length
88
- ? f.evidenceSnippets.map(
89
- (snippet) =>
90
- ` ${f.formType} ${f.filedDate}: ${renderUntrustedText(snippet, 500)}`,
91
- )
92
- : [
93
- ` ${f.formType} ${f.filedDate}: No keyword snippet found in fetched primary document.`,
94
- ],
95
- ),
96
- ]
97
- : []),
98
- ];
99
-
100
- return {
101
- content: [{ type: "text", text: lines.join("\n") }],
102
- details: { symbol, filings },
103
- };
104
- },
105
- };