opencandle 0.3.0 → 0.5.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.
- package/LICENSE +1 -1
- package/README.md +106 -14
- package/assets/logo.svg +187 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +40 -3
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +25 -0
- package/dist/config.js +72 -0
- package/dist/config.js.map +1 -1
- package/dist/infra/browser.d.ts +11 -3
- package/dist/infra/browser.js +2 -1
- package/dist/infra/browser.js.map +1 -1
- package/dist/infra/native-dependencies.d.ts +1 -0
- package/dist/infra/native-dependencies.js +10 -0
- package/dist/infra/native-dependencies.js.map +1 -0
- package/dist/infra/node-version.d.ts +2 -0
- package/dist/infra/node-version.js +23 -0
- package/dist/infra/node-version.js.map +1 -0
- package/dist/infra/rate-limiter.d.ts +4 -0
- package/dist/infra/rate-limiter.js +5 -1
- package/dist/infra/rate-limiter.js.map +1 -1
- package/dist/memory/index.d.ts +2 -0
- package/dist/memory/index.js +1 -0
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/manager.d.ts +9 -0
- package/dist/memory/manager.js +28 -11
- package/dist/memory/manager.js.map +1 -1
- package/dist/memory/sqlite.js +42 -4
- package/dist/memory/sqlite.js.map +1 -1
- package/dist/memory/storage.d.ts +7 -0
- package/dist/memory/storage.js +3 -3
- package/dist/memory/storage.js.map +1 -1
- package/dist/memory/tool-defaults.d.ts +8 -0
- package/dist/memory/tool-defaults.js +59 -0
- package/dist/memory/tool-defaults.js.map +1 -0
- package/dist/memory/types.js +4 -0
- package/dist/memory/types.js.map +1 -1
- package/dist/onboarding/connect.d.ts +13 -1
- package/dist/onboarding/connect.js +21 -10
- package/dist/onboarding/connect.js.map +1 -1
- package/dist/onboarding/prompt-user.d.ts +1 -1
- package/dist/onboarding/providers.d.ts +7 -0
- package/dist/onboarding/providers.js +6 -3
- package/dist/onboarding/providers.js.map +1 -1
- package/dist/onboarding/tool-helpers.d.ts +1 -1
- package/dist/pi/opencandle-extension.d.ts +7 -1
- package/dist/pi/opencandle-extension.js +391 -21
- package/dist/pi/opencandle-extension.js.map +1 -1
- package/dist/pi/session-storage.d.ts +2 -0
- package/dist/pi/session-storage.js +5 -0
- package/dist/pi/session-storage.js.map +1 -0
- package/dist/pi/session.d.ts +4 -1
- package/dist/pi/session.js +25 -3
- package/dist/pi/session.js.map +1 -1
- package/dist/pi/setup.d.ts +1 -1
- package/dist/pi/setup.js +11 -1
- package/dist/pi/setup.js.map +1 -1
- package/dist/pi/tool-adapter.d.ts +2 -2
- package/dist/pi/tool-adapter.js +14 -1
- package/dist/pi/tool-adapter.js.map +1 -1
- package/dist/prompts/context-builder.d.ts +40 -3
- package/dist/prompts/context-builder.js +140 -19
- package/dist/prompts/context-builder.js.map +1 -1
- package/dist/prompts/disclaimer.d.ts +6 -0
- package/dist/prompts/disclaimer.js +9 -0
- package/dist/prompts/disclaimer.js.map +1 -0
- package/dist/prompts/policy-cards.d.ts +13 -0
- package/dist/prompts/policy-cards.js +197 -0
- package/dist/prompts/policy-cards.js.map +1 -0
- package/dist/prompts/sections.js +3 -3
- package/dist/prompts/sections.js.map +1 -1
- package/dist/prompts/workflow-prompts.d.ts +8 -0
- package/dist/prompts/workflow-prompts.js +208 -22
- package/dist/prompts/workflow-prompts.js.map +1 -1
- package/dist/providers/alpha-vantage.js +23 -1
- package/dist/providers/alpha-vantage.js.map +1 -1
- package/dist/providers/sec-edgar.d.ts +8 -1
- package/dist/providers/sec-edgar.js +172 -5
- package/dist/providers/sec-edgar.js.map +1 -1
- package/dist/providers/yahoo-finance.d.ts +2 -0
- package/dist/providers/yahoo-finance.js +203 -35
- package/dist/providers/yahoo-finance.js.map +1 -1
- package/dist/routing/classify-intent.d.ts +3 -0
- package/dist/routing/classify-intent.js +82 -3
- package/dist/routing/classify-intent.js.map +1 -1
- package/dist/routing/defaults.js +4 -4
- package/dist/routing/defaults.js.map +1 -1
- package/dist/routing/entity-extractor.d.ts +1 -0
- package/dist/routing/entity-extractor.js +158 -12
- package/dist/routing/entity-extractor.js.map +1 -1
- package/dist/routing/index.d.ts +10 -0
- package/dist/routing/index.js +7 -0
- package/dist/routing/index.js.map +1 -1
- package/dist/routing/legacy-rule-router.d.ts +9 -0
- package/dist/routing/legacy-rule-router.js +12 -0
- package/dist/routing/legacy-rule-router.js.map +1 -0
- package/dist/routing/planning.d.ts +54 -0
- package/dist/routing/planning.js +531 -0
- package/dist/routing/planning.js.map +1 -0
- package/dist/routing/route-manifest.d.ts +35 -0
- package/dist/routing/route-manifest.js +221 -0
- package/dist/routing/route-manifest.js.map +1 -0
- package/dist/routing/router-llm-client.d.ts +11 -0
- package/dist/routing/router-llm-client.js +42 -0
- package/dist/routing/router-llm-client.js.map +1 -0
- package/dist/routing/router-prompt.d.ts +2 -0
- package/dist/routing/router-prompt.js +141 -0
- package/dist/routing/router-prompt.js.map +1 -0
- package/dist/routing/router-types.d.ts +71 -0
- package/dist/routing/router-types.js +2 -0
- package/dist/routing/router-types.js.map +1 -0
- package/dist/routing/router.d.ts +11 -0
- package/dist/routing/router.js +638 -0
- package/dist/routing/router.js.map +1 -0
- package/dist/routing/slot-resolver.js +46 -6
- package/dist/routing/slot-resolver.js.map +1 -1
- package/dist/routing/turn-context.d.ts +44 -0
- package/dist/routing/turn-context.js +45 -0
- package/dist/routing/turn-context.js.map +1 -0
- package/dist/routing/types.d.ts +13 -1
- package/dist/runtime/answer-contracts.d.ts +82 -0
- package/dist/runtime/answer-contracts.js +414 -0
- package/dist/runtime/answer-contracts.js.map +1 -0
- package/dist/runtime/artifact-contracts.d.ts +14 -0
- package/dist/runtime/artifact-contracts.js +57 -0
- package/dist/runtime/artifact-contracts.js.map +1 -0
- package/dist/runtime/planning-evidence.d.ts +99 -0
- package/dist/runtime/planning-evidence.js +445 -0
- package/dist/runtime/planning-evidence.js.map +1 -0
- package/dist/runtime/session-coordinator.d.ts +81 -3
- package/dist/runtime/session-coordinator.js +201 -17
- package/dist/runtime/session-coordinator.js.map +1 -1
- package/dist/runtime/tool-defaults-wrapper.d.ts +3 -0
- package/dist/runtime/tool-defaults-wrapper.js +25 -0
- package/dist/runtime/tool-defaults-wrapper.js.map +1 -0
- package/dist/sentiment/store.js +5 -0
- package/dist/sentiment/store.js.map +1 -1
- package/dist/system-prompt.js +23 -12
- package/dist/system-prompt.js.map +1 -1
- package/dist/tool-kit.d.ts +4 -4
- package/dist/tools/fundamentals/company-overview.d.ts +1 -1
- package/dist/tools/fundamentals/company-overview.js +1 -1
- package/dist/tools/fundamentals/company-overview.js.map +1 -1
- package/dist/tools/fundamentals/comps.d.ts +1 -1
- package/dist/tools/fundamentals/comps.js +1 -1
- package/dist/tools/fundamentals/comps.js.map +1 -1
- package/dist/tools/fundamentals/dcf.d.ts +1 -1
- package/dist/tools/fundamentals/dcf.js +1 -1
- package/dist/tools/fundamentals/dcf.js.map +1 -1
- package/dist/tools/fundamentals/earnings.d.ts +1 -1
- package/dist/tools/fundamentals/earnings.js +1 -1
- package/dist/tools/fundamentals/earnings.js.map +1 -1
- package/dist/tools/fundamentals/financials.d.ts +1 -1
- package/dist/tools/fundamentals/financials.js +1 -1
- package/dist/tools/fundamentals/financials.js.map +1 -1
- package/dist/tools/fundamentals/sec-filings.d.ts +2 -1
- package/dist/tools/fundamentals/sec-filings.js +19 -2
- package/dist/tools/fundamentals/sec-filings.js.map +1 -1
- package/dist/tools/index.d.ts +29 -1
- package/dist/tools/index.js +30 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/interaction/ask-user.d.ts +1 -1
- package/dist/tools/interaction/twitter-login.d.ts +1 -1
- package/dist/tools/macro/fear-greed.d.ts +1 -1
- package/dist/tools/macro/fear-greed.js +1 -1
- package/dist/tools/macro/fear-greed.js.map +1 -1
- package/dist/tools/macro/fred-data.d.ts +1 -1
- package/dist/tools/macro/fred-data.js +29 -5
- package/dist/tools/macro/fred-data.js.map +1 -1
- package/dist/tools/market/crypto-history.d.ts +1 -1
- package/dist/tools/market/crypto-history.js +18 -2
- package/dist/tools/market/crypto-history.js.map +1 -1
- package/dist/tools/market/crypto-price.d.ts +1 -1
- package/dist/tools/market/crypto-price.js +1 -1
- package/dist/tools/market/crypto-price.js.map +1 -1
- package/dist/tools/market/search-ticker.d.ts +1 -1
- package/dist/tools/market/search-ticker.js +1 -1
- package/dist/tools/market/search-ticker.js.map +1 -1
- package/dist/tools/market/stock-history.d.ts +1 -1
- package/dist/tools/market/stock-history.js +1 -1
- package/dist/tools/market/stock-history.js.map +1 -1
- package/dist/tools/market/stock-quote.d.ts +1 -1
- package/dist/tools/market/stock-quote.js +1 -1
- package/dist/tools/market/stock-quote.js.map +1 -1
- package/dist/tools/options/greeks.js +0 -1
- package/dist/tools/options/greeks.js.map +1 -1
- package/dist/tools/options/option-chain.d.ts +1 -1
- package/dist/tools/options/option-chain.js +13 -5
- package/dist/tools/options/option-chain.js.map +1 -1
- package/dist/tools/portfolio/correlation.d.ts +1 -1
- package/dist/tools/portfolio/correlation.js +1 -1
- package/dist/tools/portfolio/correlation.js.map +1 -1
- package/dist/tools/portfolio/holdings-overlap.d.ts +8 -0
- package/dist/tools/portfolio/holdings-overlap.js +105 -0
- package/dist/tools/portfolio/holdings-overlap.js.map +1 -0
- package/dist/tools/portfolio/predictions.d.ts +1 -1
- package/dist/tools/portfolio/predictions.js +1 -1
- package/dist/tools/portfolio/predictions.js.map +1 -1
- package/dist/tools/portfolio/risk-analysis.d.ts +1 -1
- package/dist/tools/portfolio/risk-analysis.js +1 -1
- package/dist/tools/portfolio/risk-analysis.js.map +1 -1
- package/dist/tools/portfolio/tracker.d.ts +1 -1
- package/dist/tools/portfolio/tracker.js +1 -1
- package/dist/tools/portfolio/tracker.js.map +1 -1
- package/dist/tools/portfolio/watchlist.d.ts +1 -1
- package/dist/tools/portfolio/watchlist.js +12 -4
- package/dist/tools/portfolio/watchlist.js.map +1 -1
- package/dist/tools/sentiment/reddit-sentiment.d.ts +1 -1
- package/dist/tools/sentiment/reddit-sentiment.js +1 -1
- package/dist/tools/sentiment/reddit-sentiment.js.map +1 -1
- package/dist/tools/sentiment/sentiment-summary.d.ts +1 -1
- package/dist/tools/sentiment/sentiment-summary.js +57 -2
- package/dist/tools/sentiment/sentiment-summary.js.map +1 -1
- package/dist/tools/sentiment/sentiment-trend.d.ts +1 -1
- package/dist/tools/sentiment/twitter-sentiment.d.ts +1 -1
- package/dist/tools/sentiment/twitter-sentiment.js +1 -1
- package/dist/tools/sentiment/twitter-sentiment.js.map +1 -1
- package/dist/tools/sentiment/web-search.d.ts +1 -1
- package/dist/tools/sentiment/web-search.js +32 -3
- package/dist/tools/sentiment/web-search.js.map +1 -1
- package/dist/tools/sentiment/web-sentiment.d.ts +1 -1
- package/dist/tools/sentiment/web-sentiment.js +1 -1
- package/dist/tools/sentiment/web-sentiment.js.map +1 -1
- package/dist/tools/technical/backtest.d.ts +3 -3
- package/dist/tools/technical/backtest.js +41 -27
- package/dist/tools/technical/backtest.js.map +1 -1
- package/dist/tools/technical/indicators.d.ts +1 -1
- package/dist/tools/technical/indicators.js +8 -4
- package/dist/tools/technical/indicators.js.map +1 -1
- package/dist/types/options.d.ts +10 -0
- package/dist/types/portfolio.d.ts +27 -0
- package/dist/workflows/compare-assets.js +38 -2
- package/dist/workflows/compare-assets.js.map +1 -1
- package/dist/workflows/options-screener.js +94 -8
- package/dist/workflows/options-screener.js.map +1 -1
- package/dist/workflows/portfolio-builder.js +9 -5
- package/dist/workflows/portfolio-builder.js.map +1 -1
- package/gui/server/ask-user-bridge.ts +82 -0
- package/gui/server/background-quotes.ts +31 -0
- package/gui/server/chat-event-adapter.ts +142 -0
- package/gui/server/gui-session-manager.ts +5 -0
- package/gui/server/invoke-tool.ts +89 -0
- package/gui/server/live-chat-event-adapter.ts +181 -0
- package/gui/server/model-setup.ts +100 -0
- package/gui/server/package.json +5 -0
- package/gui/server/projector.ts +254 -0
- package/gui/server/prompt-observation.ts +61 -0
- package/gui/server/server.ts +703 -0
- package/gui/server/session-actions.ts +31 -0
- package/gui/server/session-entry-wait.ts +81 -0
- package/gui/server/tool-metadata.ts +88 -0
- package/gui/server/websocket.ts +128 -0
- package/gui/server/writer-lock.ts +118 -0
- package/gui/shared/chat-events.ts +118 -0
- package/gui/shared/event-reducer.ts +186 -0
- package/gui/web/dist/assets/CatalogOverlay-Bmp6Knu7.js +1 -0
- package/gui/web/dist/assets/index-Bxt9QpLX.css +1 -0
- package/gui/web/dist/assets/index-CZ9DHZYy.js +67 -0
- package/gui/web/dist/assets/logo-CWpt6Y2a.svg +187 -0
- package/gui/web/dist/index.html +17 -0
- package/package.json +50 -18
- package/src/analysts/contracts.ts +189 -0
- package/src/analysts/orchestrator.ts +300 -0
- package/src/cli.ts +206 -0
- package/src/config.ts +245 -0
- package/src/index.ts +5 -0
- package/src/infra/browser.ts +111 -0
- package/src/infra/cache.ts +103 -0
- package/src/infra/http-client.ts +68 -0
- package/src/infra/index.ts +18 -0
- package/src/infra/native-dependencies.ts +12 -0
- package/src/infra/node-version.ts +24 -0
- package/src/infra/open-url.ts +28 -0
- package/src/infra/opencandle-paths.ts +64 -0
- package/src/infra/rate-limiter.ts +73 -0
- package/src/memory/index.ts +10 -0
- package/src/memory/manager.ts +192 -0
- package/src/memory/preference-extractor.ts +106 -0
- package/src/memory/retrieval.ts +70 -0
- package/src/memory/sqlite.ts +172 -0
- package/src/memory/storage.ts +205 -0
- package/src/memory/tool-defaults.ts +87 -0
- package/src/memory/types.ts +71 -0
- package/src/onboarding/connect.ts +184 -0
- package/src/onboarding/credential-interceptor.ts +134 -0
- package/src/onboarding/degradation-accumulator.ts +79 -0
- package/src/onboarding/prompt-user.ts +85 -0
- package/src/onboarding/providers.ts +315 -0
- package/src/onboarding/state.ts +218 -0
- package/src/onboarding/tool-helpers.ts +111 -0
- package/src/onboarding/tool-tags.ts +201 -0
- package/src/onboarding/validation.ts +158 -0
- package/src/pi/opencandle-extension.ts +955 -0
- package/src/pi/session-storage.ts +5 -0
- package/src/pi/session.ts +81 -0
- package/src/pi/setup.ts +381 -0
- package/src/pi/tool-adapter.ts +36 -0
- package/src/prompts/context-builder.ts +315 -0
- package/src/prompts/disclaimer.ts +9 -0
- package/src/prompts/policy-cards.ts +220 -0
- package/src/prompts/sections.ts +46 -0
- package/src/prompts/workflow-prompts.ts +433 -0
- package/src/providers/alpha-vantage.ts +315 -0
- package/src/providers/coingecko.ts +96 -0
- package/src/providers/exa-search.ts +373 -0
- package/src/providers/fear-greed.ts +45 -0
- package/src/providers/finnhub.ts +124 -0
- package/src/providers/fred.ts +83 -0
- package/src/providers/index.ts +9 -0
- package/src/providers/provider-credential-error.ts +23 -0
- package/src/providers/reddit.ts +151 -0
- package/src/providers/sec-edgar.ts +312 -0
- package/src/providers/twitter.ts +173 -0
- package/src/providers/web-search.ts +293 -0
- package/src/providers/with-fallback.ts +41 -0
- package/src/providers/wrap-provider.ts +64 -0
- package/src/providers/yahoo-finance.ts +534 -0
- package/src/routing/classify-intent.ts +285 -0
- package/src/routing/defaults.ts +29 -0
- package/src/routing/entity-extractor.ts +291 -0
- package/src/routing/index.ts +70 -0
- package/src/routing/legacy-rule-router.ts +13 -0
- package/src/routing/planning.ts +732 -0
- package/src/routing/route-manifest.ts +287 -0
- package/src/routing/router-llm-client.ts +51 -0
- package/src/routing/router-prompt.ts +163 -0
- package/src/routing/router-types.ts +87 -0
- package/src/routing/router.ts +712 -0
- package/src/routing/slot-resolver.ts +190 -0
- package/src/routing/turn-context.ts +111 -0
- package/src/routing/types.ts +75 -0
- package/src/runtime/answer-contracts.ts +633 -0
- package/src/runtime/artifact-contracts.ts +76 -0
- package/src/runtime/evidence.ts +77 -0
- package/src/runtime/planning-evidence.ts +591 -0
- package/src/runtime/prompt-step.ts +75 -0
- package/src/runtime/provider-tracker.ts +40 -0
- package/src/runtime/run-context.ts +22 -0
- package/src/runtime/session-coordinator.ts +472 -0
- package/src/runtime/tool-defaults-wrapper.ts +35 -0
- package/src/runtime/validation.ts +214 -0
- package/src/runtime/workflow-events.ts +75 -0
- package/src/runtime/workflow-runner.ts +188 -0
- package/src/runtime/workflow-types.ts +102 -0
- package/src/sentiment/adapters/finnhub.ts +44 -0
- package/src/sentiment/adapters/reddit.ts +65 -0
- package/src/sentiment/adapters/twitter.ts +36 -0
- package/src/sentiment/adapters/web.ts +44 -0
- package/src/sentiment/index.ts +58 -0
- package/src/sentiment/keywords.ts +9 -0
- package/src/sentiment/pipeline.ts +68 -0
- package/src/sentiment/scorer.ts +78 -0
- package/src/sentiment/store.ts +260 -0
- package/src/sentiment/trends.ts +90 -0
- package/src/sentiment/types.ts +108 -0
- package/src/system-prompt.ts +118 -0
- package/src/tool-kit.ts +68 -0
- package/src/tools/AGENTS.md +36 -0
- package/src/tools/fundamentals/company-overview.ts +54 -0
- package/src/tools/fundamentals/comps.ts +156 -0
- package/src/tools/fundamentals/dcf.ts +267 -0
- package/src/tools/fundamentals/earnings.ts +47 -0
- package/src/tools/fundamentals/financials.ts +54 -0
- package/src/tools/fundamentals/sec-filings.ts +84 -0
- package/src/tools/index.ts +91 -0
- package/src/tools/interaction/ask-user.ts +81 -0
- package/src/tools/interaction/twitter-login.ts +93 -0
- package/src/tools/macro/fear-greed.ts +41 -0
- package/src/tools/macro/fred-data.ts +80 -0
- package/src/tools/market/crypto-history.ts +67 -0
- package/src/tools/market/crypto-price.ts +53 -0
- package/src/tools/market/search-ticker.ts +53 -0
- package/src/tools/market/stock-history.ts +79 -0
- package/src/tools/market/stock-quote.ts +64 -0
- package/src/tools/options/greeks.ts +81 -0
- package/src/tools/options/option-chain.ts +96 -0
- package/src/tools/portfolio/correlation.ts +162 -0
- package/src/tools/portfolio/holdings-overlap.ts +123 -0
- package/src/tools/portfolio/predictions.ts +253 -0
- package/src/tools/portfolio/risk-analysis.ts +134 -0
- package/src/tools/portfolio/tracker.ts +147 -0
- package/src/tools/portfolio/watchlist.ts +159 -0
- package/src/tools/sentiment/reddit-sentiment.ts +164 -0
- package/src/tools/sentiment/sentiment-summary.ts +316 -0
- package/src/tools/sentiment/sentiment-trend.ts +58 -0
- package/src/tools/sentiment/twitter-sentiment.ts +96 -0
- package/src/tools/sentiment/web-search.ts +183 -0
- package/src/tools/sentiment/web-sentiment.ts +76 -0
- package/src/tools/technical/backtest.ts +267 -0
- package/src/tools/technical/indicators.ts +256 -0
- package/src/types/fundamentals.ts +46 -0
- package/src/types/index.ts +20 -0
- package/src/types/macro.ts +27 -0
- package/src/types/market.ts +43 -0
- package/src/types/options.ts +52 -0
- package/src/types/portfolio.ts +73 -0
- package/src/types/sentiment.ts +70 -0
- package/src/workflows/compare-assets.ts +75 -0
- package/src/workflows/index.ts +4 -0
- package/src/workflows/options-screener.ts +127 -0
- package/src/workflows/portfolio-builder.ts +56 -0
- package/src/workflows/types.ts +4 -0
- package/dist/runtime/index.d.ts +0 -16
- package/dist/runtime/index.js +0 -10
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/provider-ids.d.ts +0 -14
- package/dist/runtime/provider-ids.js +0 -14
- package/dist/runtime/provider-ids.js.map +0 -1
|
@@ -0,0 +1,732 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RouterDiagnostic,
|
|
3
|
+
RouterInputContext,
|
|
4
|
+
RouterOutput,
|
|
5
|
+
RouterRouteKind,
|
|
6
|
+
ToolBundleName,
|
|
7
|
+
} from "./router-types.js";
|
|
8
|
+
import type { WorkflowType } from "./types.js";
|
|
9
|
+
import {
|
|
10
|
+
artifactContractIdsForPlanning,
|
|
11
|
+
type ArtifactContractId,
|
|
12
|
+
} from "../runtime/artifact-contracts.js";
|
|
13
|
+
|
|
14
|
+
export const PLANNING_VERSION = "planning-v1" as const;
|
|
15
|
+
|
|
16
|
+
export type TaskFamily =
|
|
17
|
+
| "single_asset_decision"
|
|
18
|
+
| "asset_compare"
|
|
19
|
+
| "portfolio_build"
|
|
20
|
+
| "portfolio_review"
|
|
21
|
+
| "macro_allocation_review"
|
|
22
|
+
| "options_strategy"
|
|
23
|
+
| "current_event_explanation"
|
|
24
|
+
| "ticker_disambiguation"
|
|
25
|
+
| "filing_thesis_review"
|
|
26
|
+
| "sentiment_snapshot"
|
|
27
|
+
| "concept_explainer"
|
|
28
|
+
| "retail_finance_tradeoff"
|
|
29
|
+
| "stateful_tracking_update"
|
|
30
|
+
| "backtest_review"
|
|
31
|
+
| "general_fallback";
|
|
32
|
+
|
|
33
|
+
export type CommitmentMode =
|
|
34
|
+
| "decision"
|
|
35
|
+
| "compare_tradeoffs"
|
|
36
|
+
| "framework"
|
|
37
|
+
| "construct"
|
|
38
|
+
| "update_state"
|
|
39
|
+
| "clarify";
|
|
40
|
+
|
|
41
|
+
export type PolicyCardId =
|
|
42
|
+
| "single_asset_decision"
|
|
43
|
+
| "asset_compare"
|
|
44
|
+
| "portfolio_build"
|
|
45
|
+
| "portfolio_review"
|
|
46
|
+
| "portfolio_rebalance_review"
|
|
47
|
+
| "macro_allocation_review"
|
|
48
|
+
| "options_strategy"
|
|
49
|
+
| "current_event_explanation"
|
|
50
|
+
| "ticker_disambiguation"
|
|
51
|
+
| "sentiment_snapshot"
|
|
52
|
+
| "filing_thesis_review"
|
|
53
|
+
| "retail_finance_tradeoff"
|
|
54
|
+
| "concept_explainer"
|
|
55
|
+
| "concept_options_education"
|
|
56
|
+
| "concept_inflation_cash_education"
|
|
57
|
+
| "concept_valuation_metric_education"
|
|
58
|
+
| "backtest_review"
|
|
59
|
+
| "stateful_tracking_update"
|
|
60
|
+
| "general_fallback";
|
|
61
|
+
|
|
62
|
+
export type EvidencePlanId =
|
|
63
|
+
| "market_status"
|
|
64
|
+
| "ticker_disambiguation"
|
|
65
|
+
| "placeholder_single_asset_decision"
|
|
66
|
+
| "placeholder_asset_compare"
|
|
67
|
+
| "placeholder_portfolio_build"
|
|
68
|
+
| "placeholder_portfolio_review"
|
|
69
|
+
| "placeholder_options_strategy"
|
|
70
|
+
| "placeholder_current_event_explanation"
|
|
71
|
+
| "placeholder_sentiment_snapshot"
|
|
72
|
+
| "placeholder_filing_thesis_review"
|
|
73
|
+
| "placeholder_retail_finance_tradeoff"
|
|
74
|
+
| "placeholder_concept_explainer"
|
|
75
|
+
| "placeholder_backtest_review"
|
|
76
|
+
| "placeholder_stateful_tracking_update"
|
|
77
|
+
| "placeholder_general_fallback";
|
|
78
|
+
|
|
79
|
+
export type AnswerContractId =
|
|
80
|
+
| "single_asset_decision"
|
|
81
|
+
| "asset_compare_tradeoff"
|
|
82
|
+
| "portfolio_build"
|
|
83
|
+
| "portfolio_review"
|
|
84
|
+
| "macro_allocation_review"
|
|
85
|
+
| "options_strategy"
|
|
86
|
+
| "current_event_explanation"
|
|
87
|
+
| "ticker_disambiguation"
|
|
88
|
+
| "sentiment_snapshot"
|
|
89
|
+
| "filing_thesis_review"
|
|
90
|
+
| "retail_tradeoff_framework"
|
|
91
|
+
| "concept_explainer"
|
|
92
|
+
| "backtest_review"
|
|
93
|
+
| "stateful_tracking_update"
|
|
94
|
+
| "general_fallback";
|
|
95
|
+
|
|
96
|
+
export type StructuredCheckId =
|
|
97
|
+
| "required_evidence_present"
|
|
98
|
+
| "freshness_disclosed"
|
|
99
|
+
| "data_gap_disclosed"
|
|
100
|
+
| "commitment_mode_respected"
|
|
101
|
+
| "source_coverage_disclosed"
|
|
102
|
+
| "capability_gap_disclosure"
|
|
103
|
+
| "assumption_disclosed"
|
|
104
|
+
| "tax_caveat_present"
|
|
105
|
+
| "target_bands_present"
|
|
106
|
+
| "when_not_ideal_present";
|
|
107
|
+
|
|
108
|
+
export type CapabilityGapId =
|
|
109
|
+
| "market_calendar"
|
|
110
|
+
| "etf_holdings_overlap"
|
|
111
|
+
| "brokerage_comparison"
|
|
112
|
+
| "cash_yield_products"
|
|
113
|
+
| "earnings_event_risk"
|
|
114
|
+
| "fund_tax_efficiency"
|
|
115
|
+
| "forward_rate_probabilities"
|
|
116
|
+
| "sentiment_sample_depth";
|
|
117
|
+
|
|
118
|
+
export interface CapabilityGapDefinition {
|
|
119
|
+
id: CapabilityGapId;
|
|
120
|
+
label: string;
|
|
121
|
+
description: string;
|
|
122
|
+
v1Status: "classified_gap";
|
|
123
|
+
specialistCompetitive: boolean;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const CAPABILITY_GAP_REGISTRY: Record<CapabilityGapId, CapabilityGapDefinition> = {
|
|
127
|
+
market_calendar: {
|
|
128
|
+
id: "market_calendar",
|
|
129
|
+
label: "Market calendar",
|
|
130
|
+
description: "Exchange holiday and session-state data beyond deterministic weekday/known-holiday grounding.",
|
|
131
|
+
v1Status: "classified_gap",
|
|
132
|
+
specialistCompetitive: false,
|
|
133
|
+
},
|
|
134
|
+
etf_holdings_overlap: {
|
|
135
|
+
id: "etf_holdings_overlap",
|
|
136
|
+
label: "ETF holdings overlap",
|
|
137
|
+
description: "Exact fund holding overlap, weights, and issuer-level exposure calculations.",
|
|
138
|
+
v1Status: "classified_gap",
|
|
139
|
+
specialistCompetitive: false,
|
|
140
|
+
},
|
|
141
|
+
brokerage_comparison: {
|
|
142
|
+
id: "brokerage_comparison",
|
|
143
|
+
label: "Brokerage comparison",
|
|
144
|
+
description: "Live brokerage fees, platform features, account support, and execution-quality comparison data.",
|
|
145
|
+
v1Status: "classified_gap",
|
|
146
|
+
specialistCompetitive: false,
|
|
147
|
+
},
|
|
148
|
+
cash_yield_products: {
|
|
149
|
+
id: "cash_yield_products",
|
|
150
|
+
label: "Cash-yield products",
|
|
151
|
+
description: "Live HYSA, money-market, CD, T-bill, and sweep-rate comparison data.",
|
|
152
|
+
v1Status: "classified_gap",
|
|
153
|
+
specialistCompetitive: false,
|
|
154
|
+
},
|
|
155
|
+
earnings_event_risk: {
|
|
156
|
+
id: "earnings_event_risk",
|
|
157
|
+
label: "Earnings-event risk",
|
|
158
|
+
description: "Upcoming earnings timing, transcript, implied move, and event-specific risk coverage.",
|
|
159
|
+
v1Status: "classified_gap",
|
|
160
|
+
specialistCompetitive: false,
|
|
161
|
+
},
|
|
162
|
+
fund_tax_efficiency: {
|
|
163
|
+
id: "fund_tax_efficiency",
|
|
164
|
+
label: "Fund tax efficiency",
|
|
165
|
+
description: "Distribution, turnover, asset-location, and after-tax fund comparison data.",
|
|
166
|
+
v1Status: "classified_gap",
|
|
167
|
+
specialistCompetitive: false,
|
|
168
|
+
},
|
|
169
|
+
forward_rate_probabilities: {
|
|
170
|
+
id: "forward_rate_probabilities",
|
|
171
|
+
label: "Forward-rate probabilities",
|
|
172
|
+
description: "Forward policy-rate probability and curve-derived expectation data.",
|
|
173
|
+
v1Status: "classified_gap",
|
|
174
|
+
specialistCompetitive: false,
|
|
175
|
+
},
|
|
176
|
+
sentiment_sample_depth: {
|
|
177
|
+
id: "sentiment_sample_depth",
|
|
178
|
+
label: "Sentiment sample depth",
|
|
179
|
+
description: "Coverage, sample-size, source-depth, and low-volume confidence metadata for sentiment evidence.",
|
|
180
|
+
v1Status: "classified_gap",
|
|
181
|
+
specialistCompetitive: false,
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export type PlanningBehaviorMode = "observe_only" | "dual_run" | "replacement_active";
|
|
186
|
+
|
|
187
|
+
export interface PlanningSelection {
|
|
188
|
+
taskFamily: TaskFamily;
|
|
189
|
+
commitmentMode: CommitmentMode;
|
|
190
|
+
policyCardId: PolicyCardId;
|
|
191
|
+
evidencePlanId: EvidencePlanId;
|
|
192
|
+
answerContractId: AnswerContractId;
|
|
193
|
+
structuredCheckIds: StructuredCheckId[];
|
|
194
|
+
capabilityGapIds: CapabilityGapId[];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export interface PlanningEnvelope extends PlanningSelection {
|
|
198
|
+
version: typeof PLANNING_VERSION;
|
|
199
|
+
behaviorMode: PlanningBehaviorMode;
|
|
200
|
+
workspacePlaceholderIds: string[];
|
|
201
|
+
artifactPlaceholderIds: string[];
|
|
202
|
+
artifactContractIds?: ArtifactContractId[];
|
|
203
|
+
diagnostics: RouterDiagnostic[];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export interface PlanningBuildOptions {
|
|
207
|
+
migrationStatuses?: Partial<Record<TaskFamily, PlanningBehaviorMode>>;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
interface PlanningManifestEntry extends PlanningSelection {
|
|
211
|
+
routeKinds: RouterRouteKind[];
|
|
212
|
+
workflows: Array<Exclude<WorkflowType, "unclassified"> | undefined>;
|
|
213
|
+
compatibleToolBundles: ToolBundleName[];
|
|
214
|
+
migrated: boolean;
|
|
215
|
+
migrationStatus?: PlanningBehaviorMode;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export const PLANNING_MANIFEST: Record<TaskFamily, PlanningManifestEntry> = {
|
|
219
|
+
single_asset_decision: {
|
|
220
|
+
routeKinds: ["agent_task"],
|
|
221
|
+
workflows: ["single_asset_analysis", "general_finance_qa", undefined],
|
|
222
|
+
taskFamily: "single_asset_decision",
|
|
223
|
+
commitmentMode: "decision",
|
|
224
|
+
policyCardId: "single_asset_decision",
|
|
225
|
+
evidencePlanId: "placeholder_single_asset_decision",
|
|
226
|
+
answerContractId: "single_asset_decision",
|
|
227
|
+
structuredCheckIds: ["required_evidence_present", "freshness_disclosed", "data_gap_disclosed"],
|
|
228
|
+
capabilityGapIds: [],
|
|
229
|
+
compatibleToolBundles: ["core_market", "options", "sentiment", "sec", "clarification"],
|
|
230
|
+
migrated: false,
|
|
231
|
+
migrationStatus: "replacement_active",
|
|
232
|
+
},
|
|
233
|
+
asset_compare: {
|
|
234
|
+
routeKinds: ["workflow_dispatch", "agent_task"],
|
|
235
|
+
workflows: ["compare_assets"],
|
|
236
|
+
taskFamily: "asset_compare",
|
|
237
|
+
commitmentMode: "compare_tradeoffs",
|
|
238
|
+
policyCardId: "asset_compare",
|
|
239
|
+
evidencePlanId: "placeholder_asset_compare",
|
|
240
|
+
answerContractId: "asset_compare_tradeoff",
|
|
241
|
+
structuredCheckIds: ["required_evidence_present", "data_gap_disclosed", "capability_gap_disclosure"],
|
|
242
|
+
capabilityGapIds: ["etf_holdings_overlap"],
|
|
243
|
+
compatibleToolBundles: ["core_market", "macro", "sentiment", "clarification"],
|
|
244
|
+
migrated: false,
|
|
245
|
+
migrationStatus: "replacement_active",
|
|
246
|
+
},
|
|
247
|
+
portfolio_build: {
|
|
248
|
+
routeKinds: ["workflow_dispatch"],
|
|
249
|
+
workflows: ["portfolio_builder"],
|
|
250
|
+
taskFamily: "portfolio_build",
|
|
251
|
+
commitmentMode: "construct",
|
|
252
|
+
policyCardId: "portfolio_build",
|
|
253
|
+
evidencePlanId: "placeholder_portfolio_build",
|
|
254
|
+
answerContractId: "portfolio_build",
|
|
255
|
+
structuredCheckIds: ["required_evidence_present", "commitment_mode_respected"],
|
|
256
|
+
capabilityGapIds: [],
|
|
257
|
+
compatibleToolBundles: ["core_market", "macro", "sentiment", "clarification"],
|
|
258
|
+
migrated: false,
|
|
259
|
+
},
|
|
260
|
+
portfolio_review: {
|
|
261
|
+
routeKinds: ["agent_task", "workflow_dispatch"],
|
|
262
|
+
workflows: ["general_finance_qa", "portfolio_builder"],
|
|
263
|
+
taskFamily: "portfolio_review",
|
|
264
|
+
commitmentMode: "decision",
|
|
265
|
+
policyCardId: "portfolio_review",
|
|
266
|
+
evidencePlanId: "placeholder_portfolio_review",
|
|
267
|
+
answerContractId: "portfolio_review",
|
|
268
|
+
structuredCheckIds: ["required_evidence_present", "data_gap_disclosed", "commitment_mode_respected"],
|
|
269
|
+
capabilityGapIds: [],
|
|
270
|
+
compatibleToolBundles: ["core_market", "macro", "sentiment", "clarification"],
|
|
271
|
+
migrated: false,
|
|
272
|
+
migrationStatus: "replacement_active",
|
|
273
|
+
},
|
|
274
|
+
options_strategy: {
|
|
275
|
+
routeKinds: ["workflow_dispatch", "agent_task"],
|
|
276
|
+
workflows: ["options_screener", "general_finance_qa"],
|
|
277
|
+
taskFamily: "options_strategy",
|
|
278
|
+
commitmentMode: "decision",
|
|
279
|
+
policyCardId: "options_strategy",
|
|
280
|
+
evidencePlanId: "placeholder_options_strategy",
|
|
281
|
+
answerContractId: "options_strategy",
|
|
282
|
+
structuredCheckIds: ["required_evidence_present", "freshness_disclosed"],
|
|
283
|
+
capabilityGapIds: [],
|
|
284
|
+
compatibleToolBundles: ["core_market", "options", "sentiment", "clarification"],
|
|
285
|
+
migrated: false,
|
|
286
|
+
migrationStatus: "replacement_active",
|
|
287
|
+
},
|
|
288
|
+
current_event_explanation: {
|
|
289
|
+
routeKinds: ["agent_task"],
|
|
290
|
+
workflows: ["general_finance_qa", "single_asset_analysis", undefined],
|
|
291
|
+
taskFamily: "current_event_explanation",
|
|
292
|
+
commitmentMode: "framework",
|
|
293
|
+
policyCardId: "current_event_explanation",
|
|
294
|
+
evidencePlanId: "market_status",
|
|
295
|
+
answerContractId: "current_event_explanation",
|
|
296
|
+
structuredCheckIds: ["required_evidence_present", "freshness_disclosed", "data_gap_disclosed"],
|
|
297
|
+
capabilityGapIds: ["market_calendar"],
|
|
298
|
+
compatibleToolBundles: ["core_market", "macro", "sentiment", "sec", "clarification"],
|
|
299
|
+
migrated: false,
|
|
300
|
+
migrationStatus: "replacement_active",
|
|
301
|
+
},
|
|
302
|
+
ticker_disambiguation: {
|
|
303
|
+
routeKinds: ["agent_task"],
|
|
304
|
+
workflows: ["general_finance_qa", "single_asset_analysis", undefined],
|
|
305
|
+
taskFamily: "ticker_disambiguation",
|
|
306
|
+
commitmentMode: "framework",
|
|
307
|
+
policyCardId: "ticker_disambiguation",
|
|
308
|
+
evidencePlanId: "ticker_disambiguation",
|
|
309
|
+
answerContractId: "ticker_disambiguation",
|
|
310
|
+
structuredCheckIds: ["required_evidence_present", "data_gap_disclosed"],
|
|
311
|
+
capabilityGapIds: ["earnings_event_risk"],
|
|
312
|
+
compatibleToolBundles: ["core_market", "clarification"],
|
|
313
|
+
migrated: true,
|
|
314
|
+
},
|
|
315
|
+
filing_thesis_review: {
|
|
316
|
+
routeKinds: ["agent_task"],
|
|
317
|
+
workflows: ["general_finance_qa", "single_asset_analysis"],
|
|
318
|
+
taskFamily: "filing_thesis_review",
|
|
319
|
+
commitmentMode: "framework",
|
|
320
|
+
policyCardId: "filing_thesis_review",
|
|
321
|
+
evidencePlanId: "placeholder_filing_thesis_review",
|
|
322
|
+
answerContractId: "filing_thesis_review",
|
|
323
|
+
structuredCheckIds: ["required_evidence_present", "data_gap_disclosed"],
|
|
324
|
+
capabilityGapIds: [],
|
|
325
|
+
compatibleToolBundles: ["core_market", "sec"],
|
|
326
|
+
migrated: false,
|
|
327
|
+
migrationStatus: "replacement_active",
|
|
328
|
+
},
|
|
329
|
+
sentiment_snapshot: {
|
|
330
|
+
routeKinds: ["agent_task"],
|
|
331
|
+
workflows: ["general_finance_qa", "single_asset_analysis"],
|
|
332
|
+
taskFamily: "sentiment_snapshot",
|
|
333
|
+
commitmentMode: "framework",
|
|
334
|
+
policyCardId: "sentiment_snapshot",
|
|
335
|
+
evidencePlanId: "placeholder_sentiment_snapshot",
|
|
336
|
+
answerContractId: "sentiment_snapshot",
|
|
337
|
+
structuredCheckIds: ["required_evidence_present", "source_coverage_disclosed", "data_gap_disclosed"],
|
|
338
|
+
capabilityGapIds: ["sentiment_sample_depth"],
|
|
339
|
+
compatibleToolBundles: ["core_market", "sentiment"],
|
|
340
|
+
migrated: false,
|
|
341
|
+
migrationStatus: "replacement_active",
|
|
342
|
+
},
|
|
343
|
+
concept_explainer: {
|
|
344
|
+
routeKinds: ["agent_task"],
|
|
345
|
+
workflows: ["general_finance_qa", undefined],
|
|
346
|
+
taskFamily: "concept_explainer",
|
|
347
|
+
commitmentMode: "framework",
|
|
348
|
+
policyCardId: "concept_explainer",
|
|
349
|
+
evidencePlanId: "placeholder_concept_explainer",
|
|
350
|
+
answerContractId: "concept_explainer",
|
|
351
|
+
structuredCheckIds: ["commitment_mode_respected"],
|
|
352
|
+
capabilityGapIds: [],
|
|
353
|
+
compatibleToolBundles: [],
|
|
354
|
+
migrated: false,
|
|
355
|
+
migrationStatus: "replacement_active",
|
|
356
|
+
},
|
|
357
|
+
retail_finance_tradeoff: {
|
|
358
|
+
routeKinds: ["agent_task"],
|
|
359
|
+
workflows: ["general_finance_qa", undefined],
|
|
360
|
+
taskFamily: "retail_finance_tradeoff",
|
|
361
|
+
commitmentMode: "framework",
|
|
362
|
+
policyCardId: "retail_finance_tradeoff",
|
|
363
|
+
evidencePlanId: "placeholder_retail_finance_tradeoff",
|
|
364
|
+
answerContractId: "retail_tradeoff_framework",
|
|
365
|
+
structuredCheckIds: ["data_gap_disclosed", "capability_gap_disclosure"],
|
|
366
|
+
capabilityGapIds: ["brokerage_comparison", "cash_yield_products", "fund_tax_efficiency"],
|
|
367
|
+
compatibleToolBundles: [],
|
|
368
|
+
migrated: false,
|
|
369
|
+
migrationStatus: "replacement_active",
|
|
370
|
+
},
|
|
371
|
+
stateful_tracking_update: {
|
|
372
|
+
routeKinds: ["agent_task"],
|
|
373
|
+
workflows: ["watchlist_or_tracking"],
|
|
374
|
+
taskFamily: "stateful_tracking_update",
|
|
375
|
+
commitmentMode: "update_state",
|
|
376
|
+
policyCardId: "stateful_tracking_update",
|
|
377
|
+
evidencePlanId: "placeholder_stateful_tracking_update",
|
|
378
|
+
answerContractId: "stateful_tracking_update",
|
|
379
|
+
structuredCheckIds: ["commitment_mode_respected"],
|
|
380
|
+
capabilityGapIds: [],
|
|
381
|
+
compatibleToolBundles: ["core_market", "clarification"],
|
|
382
|
+
migrated: false,
|
|
383
|
+
migrationStatus: "replacement_active",
|
|
384
|
+
},
|
|
385
|
+
backtest_review: {
|
|
386
|
+
routeKinds: ["agent_task"],
|
|
387
|
+
workflows: ["general_finance_qa", "single_asset_analysis"],
|
|
388
|
+
taskFamily: "backtest_review",
|
|
389
|
+
commitmentMode: "framework",
|
|
390
|
+
policyCardId: "backtest_review",
|
|
391
|
+
evidencePlanId: "placeholder_backtest_review",
|
|
392
|
+
answerContractId: "backtest_review",
|
|
393
|
+
structuredCheckIds: ["required_evidence_present", "data_gap_disclosed", "source_coverage_disclosed"],
|
|
394
|
+
capabilityGapIds: [],
|
|
395
|
+
compatibleToolBundles: ["core_market", "options", "sentiment", "sec", "clarification"],
|
|
396
|
+
migrated: false,
|
|
397
|
+
migrationStatus: "replacement_active",
|
|
398
|
+
},
|
|
399
|
+
macro_allocation_review: {
|
|
400
|
+
routeKinds: ["agent_task"],
|
|
401
|
+
workflows: ["general_finance_qa"],
|
|
402
|
+
taskFamily: "macro_allocation_review",
|
|
403
|
+
commitmentMode: "decision",
|
|
404
|
+
policyCardId: "macro_allocation_review",
|
|
405
|
+
evidencePlanId: "market_status",
|
|
406
|
+
answerContractId: "macro_allocation_review",
|
|
407
|
+
structuredCheckIds: ["required_evidence_present", "freshness_disclosed", "data_gap_disclosed"],
|
|
408
|
+
capabilityGapIds: ["market_calendar", "forward_rate_probabilities"],
|
|
409
|
+
compatibleToolBundles: ["core_market", "macro", "sentiment", "clarification"],
|
|
410
|
+
migrated: false,
|
|
411
|
+
migrationStatus: "replacement_active",
|
|
412
|
+
},
|
|
413
|
+
general_fallback: {
|
|
414
|
+
routeKinds: ["agent_task", "clarification", "pass_through"],
|
|
415
|
+
workflows: [undefined, "general_finance_qa"],
|
|
416
|
+
taskFamily: "general_fallback",
|
|
417
|
+
commitmentMode: "framework",
|
|
418
|
+
policyCardId: "general_fallback",
|
|
419
|
+
evidencePlanId: "placeholder_general_fallback",
|
|
420
|
+
answerContractId: "general_fallback",
|
|
421
|
+
structuredCheckIds: ["data_gap_disclosed"],
|
|
422
|
+
capabilityGapIds: [],
|
|
423
|
+
compatibleToolBundles: ["core_market", "clarification"],
|
|
424
|
+
migrated: false,
|
|
425
|
+
},
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
export function buildPlanningEnvelope(
|
|
429
|
+
input: RouterInputContext,
|
|
430
|
+
output: RouterOutput,
|
|
431
|
+
options: PlanningBuildOptions = {},
|
|
432
|
+
): PlanningEnvelope {
|
|
433
|
+
const proposed = defaultPlanningSelection(input, output);
|
|
434
|
+
const { selection, diagnostics } = validatePlanningSelection(output, proposed);
|
|
435
|
+
const manifestEntry = PLANNING_MANIFEST[selection.taskFamily];
|
|
436
|
+
const behaviorMode: PlanningBehaviorMode = options.migrationStatuses?.[selection.taskFamily] ??
|
|
437
|
+
manifestEntry.migrationStatus ??
|
|
438
|
+
(manifestEntry.migrated
|
|
439
|
+
? "replacement_active"
|
|
440
|
+
: "observe_only");
|
|
441
|
+
|
|
442
|
+
return {
|
|
443
|
+
version: PLANNING_VERSION,
|
|
444
|
+
...selection,
|
|
445
|
+
behaviorMode,
|
|
446
|
+
workspacePlaceholderIds: [],
|
|
447
|
+
artifactPlaceholderIds: [],
|
|
448
|
+
artifactContractIds: artifactContractIdsForPlanning(selection),
|
|
449
|
+
diagnostics: [
|
|
450
|
+
...diagnostics,
|
|
451
|
+
...(output.diagnostics.length > 0
|
|
452
|
+
? [{
|
|
453
|
+
code: "planning_after_router_corrections",
|
|
454
|
+
message: "planning selected after router diagnostics were applied",
|
|
455
|
+
}]
|
|
456
|
+
: []),
|
|
457
|
+
...(behaviorMode === "observe_only"
|
|
458
|
+
? [{
|
|
459
|
+
code: "planning_observe_only",
|
|
460
|
+
message: "planning metadata is recorded without changing active prompt, route, workflow, tools, or answer behavior",
|
|
461
|
+
}]
|
|
462
|
+
: []),
|
|
463
|
+
],
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export function validatePlanningSelection(
|
|
468
|
+
output: RouterOutput,
|
|
469
|
+
proposed: PlanningSelection,
|
|
470
|
+
): { selection: PlanningSelection; diagnostics: RouterDiagnostic[] } {
|
|
471
|
+
const manifestEntry = PLANNING_MANIFEST[proposed.taskFamily];
|
|
472
|
+
if (isAllowedForOutput(manifestEntry, output)) {
|
|
473
|
+
return { selection: proposed, diagnostics: [] };
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
const fallback = defaultTaskFamilyForOutput(output, "");
|
|
477
|
+
return {
|
|
478
|
+
selection: selectionForTaskFamily(fallback),
|
|
479
|
+
diagnostics: [{
|
|
480
|
+
code: "planning_task_family_corrected",
|
|
481
|
+
message: `${proposed.taskFamily} is not supported for ${output.routeKind}${output.workflow ? `/${output.workflow}` : ""}; using ${fallback}`,
|
|
482
|
+
}],
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function defaultPlanningSelection(
|
|
487
|
+
input: RouterInputContext,
|
|
488
|
+
output: RouterOutput,
|
|
489
|
+
): PlanningSelection {
|
|
490
|
+
const selection = selectionForTaskFamily(defaultTaskFamilyForOutput(output, input.text));
|
|
491
|
+
return refinePlanningSelectionForPrompt(selection, input.text);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
function selectionForTaskFamily(taskFamily: TaskFamily): PlanningSelection {
|
|
495
|
+
const entry = PLANNING_MANIFEST[taskFamily];
|
|
496
|
+
return {
|
|
497
|
+
taskFamily: entry.taskFamily,
|
|
498
|
+
commitmentMode: entry.commitmentMode,
|
|
499
|
+
policyCardId: entry.policyCardId,
|
|
500
|
+
evidencePlanId: entry.evidencePlanId,
|
|
501
|
+
answerContractId: entry.answerContractId,
|
|
502
|
+
structuredCheckIds: [...entry.structuredCheckIds],
|
|
503
|
+
capabilityGapIds: [...entry.capabilityGapIds],
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function defaultTaskFamilyForOutput(output: RouterOutput, text: string): TaskFamily {
|
|
508
|
+
const lower = text.toLowerCase();
|
|
509
|
+
if (output.routeKind === "clarification") return "general_fallback";
|
|
510
|
+
if (output.routeKind === "pass_through") return "general_fallback";
|
|
511
|
+
if (output.workflow === "portfolio_builder" && isExistingRetirementAllocationReviewPrompt(lower)) {
|
|
512
|
+
return "portfolio_review";
|
|
513
|
+
}
|
|
514
|
+
if (output.workflow === "portfolio_builder") return "portfolio_build";
|
|
515
|
+
if (output.workflow === "options_screener") return "options_strategy";
|
|
516
|
+
if (output.workflow === "compare_assets") return "asset_compare";
|
|
517
|
+
if (output.workflow === "watchlist_or_tracking") return "stateful_tracking_update";
|
|
518
|
+
|
|
519
|
+
if (output.entities.symbols.length === 0 && isNoToolConceptEducationPrompt(lower)) {
|
|
520
|
+
return "concept_explainer";
|
|
521
|
+
}
|
|
522
|
+
if (isTickerDisambiguationPrompt(lower)) {
|
|
523
|
+
return "ticker_disambiguation";
|
|
524
|
+
}
|
|
525
|
+
if (isOptionsStrategyPrompt(lower)) return "options_strategy";
|
|
526
|
+
if (/\bbacktest(?:ing|ed)?\b/.test(lower)) {
|
|
527
|
+
return "backtest_review";
|
|
528
|
+
}
|
|
529
|
+
if (/\b(?:macro|inflation|fed|rates?|duration|recession)\b/.test(lower)) {
|
|
530
|
+
return "macro_allocation_review";
|
|
531
|
+
}
|
|
532
|
+
if (/\b(?:sentiment|mood|reddit|twitter|x\/twitter)\b/.test(lower)) {
|
|
533
|
+
return "sentiment_snapshot";
|
|
534
|
+
}
|
|
535
|
+
if (isPortfolioRebalancePrompt(lower) || isAddToExistingHoldingsPrompt(lower, output.entities.symbols.length)) {
|
|
536
|
+
return "portfolio_review";
|
|
537
|
+
}
|
|
538
|
+
if (/\b(?:today|right now|this morning|after close|moved|catalyst)\b/.test(lower)) {
|
|
539
|
+
return "current_event_explanation";
|
|
540
|
+
}
|
|
541
|
+
if (/\b(?:filing|10-k|10-q|8-k|sec)\b/.test(lower)) {
|
|
542
|
+
return "filing_thesis_review";
|
|
543
|
+
}
|
|
544
|
+
if (/\b(?:brokerage|hysa|money-market|t-bills?|cds?|mortgage|taxable account)\b/.test(lower)) {
|
|
545
|
+
return "retail_finance_tradeoff";
|
|
546
|
+
}
|
|
547
|
+
if (/\b(?:btc|bitcoin|crypto)\b/.test(lower) && /\b(?:allocation|range|position\s+size|sizing|drawdown)\b/.test(lower)) {
|
|
548
|
+
return "retail_finance_tradeoff";
|
|
549
|
+
}
|
|
550
|
+
if (/\b(?:60\/40|portfolio|allocation)\b/.test(lower) && /\b(?:evaluate|evaluation|review|risk|prospects)\b/.test(lower)) {
|
|
551
|
+
return "portfolio_review";
|
|
552
|
+
}
|
|
553
|
+
if (output.entities.symbols.length === 1 && /\b(?:analyze|buy|sell|wait|avoid|recommendation|attractive)\b/.test(lower)) {
|
|
554
|
+
return "single_asset_decision";
|
|
555
|
+
}
|
|
556
|
+
if (output.workflow === "single_asset_analysis") return "single_asset_decision";
|
|
557
|
+
if (/\b(?:explain|what is|what does|how to|define)\b/.test(lower) && output.entities.symbols.length === 0) {
|
|
558
|
+
return "concept_explainer";
|
|
559
|
+
}
|
|
560
|
+
return "general_fallback";
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function refinePlanningSelectionForPrompt(
|
|
564
|
+
selection: PlanningSelection,
|
|
565
|
+
text: string,
|
|
566
|
+
): PlanningSelection {
|
|
567
|
+
const lower = text.toLowerCase();
|
|
568
|
+
|
|
569
|
+
if (selection.taskFamily === "concept_explainer") {
|
|
570
|
+
if (isOptionsEducationPrompt(lower)) {
|
|
571
|
+
return {
|
|
572
|
+
...selection,
|
|
573
|
+
policyCardId: "concept_options_education",
|
|
574
|
+
structuredCheckIds: mergeStructuredChecks(selection.structuredCheckIds, [
|
|
575
|
+
"tax_caveat_present",
|
|
576
|
+
"when_not_ideal_present",
|
|
577
|
+
]),
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
if (isInflationCashEducationPrompt(lower)) {
|
|
581
|
+
return {
|
|
582
|
+
...selection,
|
|
583
|
+
policyCardId: "concept_inflation_cash_education",
|
|
584
|
+
structuredCheckIds: mergeStructuredChecks(selection.structuredCheckIds, ["tax_caveat_present"]),
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
if (isValuationMetricEducationPrompt(lower)) {
|
|
588
|
+
return {
|
|
589
|
+
...selection,
|
|
590
|
+
policyCardId: "concept_valuation_metric_education",
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
if (
|
|
596
|
+
selection.taskFamily === "portfolio_review" &&
|
|
597
|
+
(isPortfolioRebalancePrompt(lower) || isAddToExistingHoldingsPrompt(lower, 2)) &&
|
|
598
|
+
!isExistingRetirementAllocationReviewPrompt(lower)
|
|
599
|
+
) {
|
|
600
|
+
return {
|
|
601
|
+
...selection,
|
|
602
|
+
policyCardId: "portfolio_rebalance_review",
|
|
603
|
+
structuredCheckIds: mergeStructuredChecks(selection.structuredCheckIds, [
|
|
604
|
+
"assumption_disclosed",
|
|
605
|
+
"target_bands_present",
|
|
606
|
+
]),
|
|
607
|
+
capabilityGapIds: mergeCapabilityGaps(selection.capabilityGapIds, ["etf_holdings_overlap"]),
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
if (
|
|
612
|
+
selection.taskFamily === "retail_finance_tradeoff" &&
|
|
613
|
+
/\b(?:where should|hysa|money-market|t-bills?|cds?|mortgage|versus|vs\.?|or)\b/.test(lower)
|
|
614
|
+
) {
|
|
615
|
+
return {
|
|
616
|
+
...selection,
|
|
617
|
+
commitmentMode: "compare_tradeoffs",
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
if (
|
|
622
|
+
selection.taskFamily === "retail_finance_tradeoff" &&
|
|
623
|
+
/\b(?:btc|bitcoin|crypto)\b/.test(lower) &&
|
|
624
|
+
/\b(?:allocation|range|position\s+size|sizing|drawdown)\b/.test(lower)
|
|
625
|
+
) {
|
|
626
|
+
return {
|
|
627
|
+
...selection,
|
|
628
|
+
commitmentMode: "decision",
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
if (
|
|
633
|
+
selection.taskFamily === "ticker_disambiguation" &&
|
|
634
|
+
/\b(?:earnings|trim|hedge|hold|event[-\s]?risk|position\s+size)\b/.test(lower)
|
|
635
|
+
) {
|
|
636
|
+
return {
|
|
637
|
+
...selection,
|
|
638
|
+
commitmentMode: "decision",
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
if (
|
|
643
|
+
selection.taskFamily === "macro_allocation_review" &&
|
|
644
|
+
/\b(?:sentiment|mood|reddit|twitter|x\/twitter)\b/.test(lower)
|
|
645
|
+
) {
|
|
646
|
+
return {
|
|
647
|
+
...selection,
|
|
648
|
+
commitmentMode: "framework",
|
|
649
|
+
capabilityGapIds: mergeCapabilityGaps(selection.capabilityGapIds, ["sentiment_sample_depth"]),
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
return selection;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
function isNoToolConceptEducationPrompt(lower: string): boolean {
|
|
657
|
+
if (!/\b(?:explain|what\s+is|what\s+are|what\s+does|how\s+does|how\s+do|how\s+to|define)\b/.test(lower)) {
|
|
658
|
+
return false;
|
|
659
|
+
}
|
|
660
|
+
return isOptionsEducationPrompt(lower) ||
|
|
661
|
+
isInflationCashEducationPrompt(lower) ||
|
|
662
|
+
isValuationMetricEducationPrompt(lower);
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
function isOptionsEducationPrompt(lower: string): boolean {
|
|
666
|
+
return /\b(?:covered\s+calls?|protective\s+puts?|options?|option\s+premium|assignment\s+risk|strike|expiration|delta|theta|greeks?)\b/.test(lower);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
function isOptionsStrategyPrompt(lower: string): boolean {
|
|
670
|
+
return /\b(?:covered\s+calls?|protective\s+puts?|sell(?:ing)?\s+calls?|sell(?:ing)?\s+puts?|options?\s+income|option\s+strategy|hedge|collar)\b/.test(lower) &&
|
|
671
|
+
/\b(?:own|have|shares?|position|cost\s+basis|good\s+idea|make\s+sense|income|premium|strike|expiration|assignment|stable|flat|protect|hedge|sell)\b/.test(lower);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
function isTickerDisambiguationPrompt(lower: string): boolean {
|
|
675
|
+
if (/\b(?:ticker|symbol|formerly|old ticker)\b/.test(lower)) return true;
|
|
676
|
+
return /\b(?:earnings are|earnings tonight)\b/.test(lower) &&
|
|
677
|
+
/\b(?:trim|hedge|hold|event[-\s]?risk|position\s+size)\b/.test(lower) &&
|
|
678
|
+
!/\b(?:covered\s+calls?|protective\s+puts?|sell(?:ing)?\s+calls?|sell(?:ing)?\s+puts?|option\s+chain|strike|expiration|premium)\b/.test(lower);
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
function isInflationCashEducationPrompt(lower: string): boolean {
|
|
682
|
+
return /\b(?:inflation|purchasing\s+power|real\s+returns?|cash\s+savings?|cash\s+drag|tips|short(?:er)?[-\s]?duration)\b/.test(lower) &&
|
|
683
|
+
/\b(?:cash|savings?|purchasing\s+power|real\s+returns?|bonds?|tips|protect|protection|affect)\b/.test(lower);
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
function isValuationMetricEducationPrompt(lower: string): boolean {
|
|
687
|
+
return /\b(?:p\/e|pe\s+ratio|price[-\s]?to[-\s]?earnings|ev\/ebitda|p\/s|price[-\s]?to[-\s]?sales|valuation\s+metric|trailing|forward\s+earnings|normalized\s+earnings|cyclically\s+adjusted)\b/.test(lower);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
function isPortfolioRebalancePrompt(lower: string): boolean {
|
|
691
|
+
return /\b(?:portfolio|allocation|holdings?|sleeves?|ira|etfs?|funds?|s&p\s*500|index|equity|bonds?|cash)\b/.test(lower) &&
|
|
692
|
+
/\b(?:rebalance|diversify|diversifying|concentration|overweight|underweight|target\s+bands?|drift|reduce\s+concentration|adjust|adjustment|more\s+aggressive|higher\s+growth|too\s+risky|riskier|worried|crash|protect|protection|missing\s+out\s+on\s+growth)\b/.test(lower);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
function isAddToExistingHoldingsPrompt(lower: string, symbolCount: number): boolean {
|
|
696
|
+
return symbolCount >= 2 &&
|
|
697
|
+
/\b(?:already\s+own|already\s+hold|current(?:ly)?\s+own|existing\s+(?:holdings?|portfolio|position)|my\s+portfolio)\b/.test(lower) &&
|
|
698
|
+
/\b(?:add(?:ing)?|buy(?:ing)?|make\s+sense|fit|long[-\s]?term|growth)\b/.test(lower);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
function isExistingRetirementAllocationReviewPrompt(lower: string): boolean {
|
|
702
|
+
return /\b(?:401k|401\(k\)|target[-\s]?date|tdf)\b/.test(lower) &&
|
|
703
|
+
/\b(?:mostly|current(?:ly)?|already|have|holding|invested|allocation)\b/.test(lower) &&
|
|
704
|
+
/\b(?:review|solid|worried|inflation|diversify|boost returns?|other options?|without taking crazy risks?|risk)\b/.test(lower);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
function mergeCapabilityGaps(
|
|
708
|
+
primary: readonly CapabilityGapId[],
|
|
709
|
+
secondary: readonly CapabilityGapId[],
|
|
710
|
+
): CapabilityGapId[] {
|
|
711
|
+
const merged: CapabilityGapId[] = [];
|
|
712
|
+
for (const gap of [...primary, ...secondary]) {
|
|
713
|
+
if (!merged.includes(gap)) merged.push(gap);
|
|
714
|
+
}
|
|
715
|
+
return merged;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
function mergeStructuredChecks(
|
|
719
|
+
primary: readonly StructuredCheckId[],
|
|
720
|
+
secondary: readonly StructuredCheckId[],
|
|
721
|
+
): StructuredCheckId[] {
|
|
722
|
+
const merged: StructuredCheckId[] = [];
|
|
723
|
+
for (const check of [...primary, ...secondary]) {
|
|
724
|
+
if (!merged.includes(check)) merged.push(check);
|
|
725
|
+
}
|
|
726
|
+
return merged;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
function isAllowedForOutput(entry: PlanningManifestEntry, output: RouterOutput): boolean {
|
|
730
|
+
if (!entry.routeKinds.includes(output.routeKind)) return false;
|
|
731
|
+
return entry.workflows.includes(output.workflow);
|
|
732
|
+
}
|