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,633 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnswerContractId,
|
|
3
|
+
CapabilityGapId,
|
|
4
|
+
CommitmentMode,
|
|
5
|
+
StructuredCheckId,
|
|
6
|
+
TaskFamily,
|
|
7
|
+
} from "../routing/planning.js";
|
|
8
|
+
import type { PlanningEvidenceRecord, PlanningEvidenceType } from "./planning-evidence.js";
|
|
9
|
+
|
|
10
|
+
export type FinalAnswerField =
|
|
11
|
+
| "clear_commitment"
|
|
12
|
+
| "comparison_tradeoffs"
|
|
13
|
+
| "constructed_output"
|
|
14
|
+
| "state_update_confirmation"
|
|
15
|
+
| "clarifying_question"
|
|
16
|
+
| "symbol_verification_disclosure"
|
|
17
|
+
| "framework_or_checklist"
|
|
18
|
+
| "freshness_disclosure"
|
|
19
|
+
| "data_gap_disclosure"
|
|
20
|
+
| "risk_downside"
|
|
21
|
+
| "source_coverage";
|
|
22
|
+
|
|
23
|
+
export type FrameworkFallbackMode =
|
|
24
|
+
| "not_allowed"
|
|
25
|
+
| "diagnostic_until_parity"
|
|
26
|
+
| "active_after_parity";
|
|
27
|
+
|
|
28
|
+
export type ParityMigrationStatus =
|
|
29
|
+
| "legacy_active"
|
|
30
|
+
| "observe_only"
|
|
31
|
+
| "dual_run"
|
|
32
|
+
| "replacement_active"
|
|
33
|
+
| "legacy_removed";
|
|
34
|
+
|
|
35
|
+
export interface CommitmentModeContract {
|
|
36
|
+
mode: CommitmentMode;
|
|
37
|
+
requiredFinalFields: FinalAnswerField[];
|
|
38
|
+
requiresConcreteCommitment: boolean;
|
|
39
|
+
description: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface AnswerContractDefinition {
|
|
43
|
+
id: AnswerContractId;
|
|
44
|
+
taskFamily: TaskFamily;
|
|
45
|
+
commitmentMode: CommitmentMode;
|
|
46
|
+
implemented: boolean;
|
|
47
|
+
requiredEvidenceTypes: PlanningEvidenceType[];
|
|
48
|
+
requiredFinalFields: FinalAnswerField[];
|
|
49
|
+
requiresFreshness: boolean;
|
|
50
|
+
requiresDataGapDisclosure: boolean;
|
|
51
|
+
requiresRiskDownside: boolean;
|
|
52
|
+
requiresSourceCoverage: boolean;
|
|
53
|
+
requiresConcreteCommitment: boolean;
|
|
54
|
+
capabilityGapIds: CapabilityGapId[];
|
|
55
|
+
frameworkFallback: FrameworkFallbackMode;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface FinalAnswerMetadata {
|
|
59
|
+
commitmentMode: CommitmentMode;
|
|
60
|
+
finalFields: FinalAnswerField[];
|
|
61
|
+
freshness?: {
|
|
62
|
+
asOfDate?: string;
|
|
63
|
+
marketStatus?: string;
|
|
64
|
+
lastTradingDay?: string;
|
|
65
|
+
};
|
|
66
|
+
sourceCoverage?: {
|
|
67
|
+
sources: string[];
|
|
68
|
+
sampleSize?: number;
|
|
69
|
+
};
|
|
70
|
+
disclosedProviderStatuses?: string[];
|
|
71
|
+
disclosedCapabilityGapIds?: CapabilityGapId[];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface StructuredCheckResult {
|
|
75
|
+
checkId: StructuredCheckId;
|
|
76
|
+
passed: boolean;
|
|
77
|
+
observedOnly: true;
|
|
78
|
+
failureReason?: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface RetryEligibilityTrace {
|
|
82
|
+
eligible: boolean;
|
|
83
|
+
activeRetryAllowed: false;
|
|
84
|
+
reasons: string[];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface StructuredCheckTrace {
|
|
88
|
+
mode: "observe_only";
|
|
89
|
+
answerContractId: AnswerContractId;
|
|
90
|
+
results: StructuredCheckResult[];
|
|
91
|
+
failures: StructuredCheckResult[];
|
|
92
|
+
retryEligibility: RetryEligibilityTrace;
|
|
93
|
+
activeRetryAllowed: false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface FrameworkFallbackEligibility {
|
|
97
|
+
eligible: boolean;
|
|
98
|
+
active: boolean;
|
|
99
|
+
mode: "not_applicable" | "diagnostic_only" | "active";
|
|
100
|
+
reason: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface StructuredCheckInput {
|
|
104
|
+
contract: AnswerContractDefinition;
|
|
105
|
+
evidenceRecords: PlanningEvidenceRecord[];
|
|
106
|
+
finalAnswerMetadata: FinalAnswerMetadata;
|
|
107
|
+
structuredCheckIds?: StructuredCheckId[];
|
|
108
|
+
answerText?: string;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface FrameworkFallbackInput {
|
|
112
|
+
contract: AnswerContractDefinition;
|
|
113
|
+
evidenceRecords: PlanningEvidenceRecord[];
|
|
114
|
+
parityStatus: ParityMigrationStatus;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export const COMMITMENT_MODE_CONTRACTS: Record<CommitmentMode, CommitmentModeContract> = {
|
|
118
|
+
decision: {
|
|
119
|
+
mode: "decision",
|
|
120
|
+
requiredFinalFields: ["clear_commitment", "risk_downside"],
|
|
121
|
+
requiresConcreteCommitment: true,
|
|
122
|
+
description: "Make a clear call with major risks and conditions.",
|
|
123
|
+
},
|
|
124
|
+
compare_tradeoffs: {
|
|
125
|
+
mode: "compare_tradeoffs",
|
|
126
|
+
requiredFinalFields: ["comparison_tradeoffs", "risk_downside"],
|
|
127
|
+
requiresConcreteCommitment: false,
|
|
128
|
+
description: "Compare options without converting the task into construction unless requested.",
|
|
129
|
+
},
|
|
130
|
+
framework: {
|
|
131
|
+
mode: "framework",
|
|
132
|
+
requiredFinalFields: ["framework_or_checklist"],
|
|
133
|
+
requiresConcreteCommitment: false,
|
|
134
|
+
description: "Give a useful framework or checklist without inventing current facts.",
|
|
135
|
+
},
|
|
136
|
+
construct: {
|
|
137
|
+
mode: "construct",
|
|
138
|
+
requiredFinalFields: ["constructed_output", "risk_downside"],
|
|
139
|
+
requiresConcreteCommitment: true,
|
|
140
|
+
description: "Construct the requested allocation, screen, or plan.",
|
|
141
|
+
},
|
|
142
|
+
update_state: {
|
|
143
|
+
mode: "update_state",
|
|
144
|
+
requiredFinalFields: ["state_update_confirmation"],
|
|
145
|
+
requiresConcreteCommitment: false,
|
|
146
|
+
description: "Confirm the state change and preserve relevant context.",
|
|
147
|
+
},
|
|
148
|
+
clarify: {
|
|
149
|
+
mode: "clarify",
|
|
150
|
+
requiredFinalFields: ["clarifying_question"],
|
|
151
|
+
requiresConcreteCommitment: false,
|
|
152
|
+
description: "Ask only for the missing information required to proceed.",
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export const ANSWER_CONTRACT_REGISTRY: Record<AnswerContractId, AnswerContractDefinition> = {
|
|
157
|
+
single_asset_decision: {
|
|
158
|
+
id: "single_asset_decision",
|
|
159
|
+
taskFamily: "single_asset_decision",
|
|
160
|
+
commitmentMode: "decision",
|
|
161
|
+
implemented: true,
|
|
162
|
+
requiredEvidenceTypes: [],
|
|
163
|
+
requiredFinalFields: ["clear_commitment", "risk_downside", "freshness_disclosure", "data_gap_disclosure"],
|
|
164
|
+
requiresFreshness: true,
|
|
165
|
+
requiresDataGapDisclosure: true,
|
|
166
|
+
requiresRiskDownside: true,
|
|
167
|
+
requiresSourceCoverage: false,
|
|
168
|
+
requiresConcreteCommitment: true,
|
|
169
|
+
capabilityGapIds: [],
|
|
170
|
+
frameworkFallback: "not_allowed",
|
|
171
|
+
},
|
|
172
|
+
asset_compare_tradeoff: {
|
|
173
|
+
id: "asset_compare_tradeoff",
|
|
174
|
+
taskFamily: "asset_compare",
|
|
175
|
+
commitmentMode: "compare_tradeoffs",
|
|
176
|
+
implemented: true,
|
|
177
|
+
requiredEvidenceTypes: [],
|
|
178
|
+
requiredFinalFields: ["comparison_tradeoffs", "risk_downside", "data_gap_disclosure", "source_coverage"],
|
|
179
|
+
requiresFreshness: false,
|
|
180
|
+
requiresDataGapDisclosure: true,
|
|
181
|
+
requiresRiskDownside: true,
|
|
182
|
+
requiresSourceCoverage: true,
|
|
183
|
+
requiresConcreteCommitment: false,
|
|
184
|
+
capabilityGapIds: ["etf_holdings_overlap"],
|
|
185
|
+
frameworkFallback: "not_allowed",
|
|
186
|
+
},
|
|
187
|
+
portfolio_build: placeholderContract("portfolio_build", "portfolio_build", "construct", ["constructed_output"]),
|
|
188
|
+
portfolio_review: {
|
|
189
|
+
id: "portfolio_review",
|
|
190
|
+
taskFamily: "portfolio_review",
|
|
191
|
+
commitmentMode: "decision",
|
|
192
|
+
implemented: true,
|
|
193
|
+
requiredEvidenceTypes: [],
|
|
194
|
+
requiredFinalFields: [
|
|
195
|
+
"clear_commitment",
|
|
196
|
+
"risk_downside",
|
|
197
|
+
"framework_or_checklist",
|
|
198
|
+
"data_gap_disclosure",
|
|
199
|
+
"source_coverage",
|
|
200
|
+
],
|
|
201
|
+
requiresFreshness: false,
|
|
202
|
+
requiresDataGapDisclosure: true,
|
|
203
|
+
requiresRiskDownside: true,
|
|
204
|
+
requiresSourceCoverage: true,
|
|
205
|
+
requiresConcreteCommitment: true,
|
|
206
|
+
capabilityGapIds: [],
|
|
207
|
+
frameworkFallback: "not_allowed",
|
|
208
|
+
},
|
|
209
|
+
macro_allocation_review: {
|
|
210
|
+
id: "macro_allocation_review",
|
|
211
|
+
taskFamily: "macro_allocation_review",
|
|
212
|
+
commitmentMode: "decision",
|
|
213
|
+
implemented: true,
|
|
214
|
+
requiredEvidenceTypes: ["market_status"],
|
|
215
|
+
requiredFinalFields: [
|
|
216
|
+
"clear_commitment",
|
|
217
|
+
"risk_downside",
|
|
218
|
+
"framework_or_checklist",
|
|
219
|
+
"freshness_disclosure",
|
|
220
|
+
"data_gap_disclosure",
|
|
221
|
+
"source_coverage",
|
|
222
|
+
],
|
|
223
|
+
requiresFreshness: true,
|
|
224
|
+
requiresDataGapDisclosure: true,
|
|
225
|
+
requiresRiskDownside: true,
|
|
226
|
+
requiresSourceCoverage: true,
|
|
227
|
+
requiresConcreteCommitment: true,
|
|
228
|
+
capabilityGapIds: ["market_calendar", "forward_rate_probabilities"],
|
|
229
|
+
frameworkFallback: "not_allowed",
|
|
230
|
+
},
|
|
231
|
+
options_strategy: {
|
|
232
|
+
id: "options_strategy",
|
|
233
|
+
taskFamily: "options_strategy",
|
|
234
|
+
commitmentMode: "decision",
|
|
235
|
+
implemented: true,
|
|
236
|
+
requiredEvidenceTypes: [],
|
|
237
|
+
requiredFinalFields: [
|
|
238
|
+
"clear_commitment",
|
|
239
|
+
"risk_downside",
|
|
240
|
+
"freshness_disclosure",
|
|
241
|
+
"data_gap_disclosure",
|
|
242
|
+
"source_coverage",
|
|
243
|
+
],
|
|
244
|
+
requiresFreshness: true,
|
|
245
|
+
requiresDataGapDisclosure: true,
|
|
246
|
+
requiresRiskDownside: true,
|
|
247
|
+
requiresSourceCoverage: true,
|
|
248
|
+
requiresConcreteCommitment: true,
|
|
249
|
+
capabilityGapIds: [],
|
|
250
|
+
frameworkFallback: "not_allowed",
|
|
251
|
+
},
|
|
252
|
+
backtest_review: {
|
|
253
|
+
id: "backtest_review",
|
|
254
|
+
taskFamily: "backtest_review",
|
|
255
|
+
commitmentMode: "framework",
|
|
256
|
+
implemented: true,
|
|
257
|
+
requiredEvidenceTypes: [],
|
|
258
|
+
requiredFinalFields: ["framework_or_checklist", "risk_downside", "data_gap_disclosure", "source_coverage"],
|
|
259
|
+
requiresFreshness: false,
|
|
260
|
+
requiresDataGapDisclosure: true,
|
|
261
|
+
requiresRiskDownside: true,
|
|
262
|
+
requiresSourceCoverage: true,
|
|
263
|
+
requiresConcreteCommitment: false,
|
|
264
|
+
capabilityGapIds: [],
|
|
265
|
+
frameworkFallback: "not_allowed",
|
|
266
|
+
},
|
|
267
|
+
stateful_tracking_update: {
|
|
268
|
+
id: "stateful_tracking_update",
|
|
269
|
+
taskFamily: "stateful_tracking_update",
|
|
270
|
+
commitmentMode: "update_state",
|
|
271
|
+
implemented: true,
|
|
272
|
+
requiredEvidenceTypes: [],
|
|
273
|
+
requiredFinalFields: ["state_update_confirmation", "data_gap_disclosure"],
|
|
274
|
+
requiresFreshness: false,
|
|
275
|
+
requiresDataGapDisclosure: true,
|
|
276
|
+
requiresRiskDownside: false,
|
|
277
|
+
requiresSourceCoverage: false,
|
|
278
|
+
requiresConcreteCommitment: false,
|
|
279
|
+
capabilityGapIds: [],
|
|
280
|
+
frameworkFallback: "not_allowed",
|
|
281
|
+
},
|
|
282
|
+
current_event_explanation: {
|
|
283
|
+
id: "current_event_explanation",
|
|
284
|
+
taskFamily: "current_event_explanation",
|
|
285
|
+
commitmentMode: "framework",
|
|
286
|
+
implemented: true,
|
|
287
|
+
requiredEvidenceTypes: ["market_status"],
|
|
288
|
+
requiredFinalFields: ["framework_or_checklist", "freshness_disclosure", "source_coverage", "data_gap_disclosure"],
|
|
289
|
+
requiresFreshness: true,
|
|
290
|
+
requiresDataGapDisclosure: true,
|
|
291
|
+
requiresRiskDownside: false,
|
|
292
|
+
requiresSourceCoverage: true,
|
|
293
|
+
requiresConcreteCommitment: false,
|
|
294
|
+
capabilityGapIds: ["market_calendar"],
|
|
295
|
+
frameworkFallback: "not_allowed",
|
|
296
|
+
},
|
|
297
|
+
ticker_disambiguation: {
|
|
298
|
+
id: "ticker_disambiguation",
|
|
299
|
+
taskFamily: "ticker_disambiguation",
|
|
300
|
+
commitmentMode: "framework",
|
|
301
|
+
implemented: true,
|
|
302
|
+
requiredEvidenceTypes: ["ticker_disambiguation"],
|
|
303
|
+
requiredFinalFields: [
|
|
304
|
+
"symbol_verification_disclosure",
|
|
305
|
+
"framework_or_checklist",
|
|
306
|
+
"data_gap_disclosure",
|
|
307
|
+
"risk_downside",
|
|
308
|
+
],
|
|
309
|
+
requiresFreshness: false,
|
|
310
|
+
requiresDataGapDisclosure: true,
|
|
311
|
+
requiresRiskDownside: true,
|
|
312
|
+
requiresSourceCoverage: false,
|
|
313
|
+
requiresConcreteCommitment: false,
|
|
314
|
+
capabilityGapIds: ["earnings_event_risk"],
|
|
315
|
+
frameworkFallback: "diagnostic_until_parity",
|
|
316
|
+
},
|
|
317
|
+
sentiment_snapshot: {
|
|
318
|
+
id: "sentiment_snapshot",
|
|
319
|
+
taskFamily: "sentiment_snapshot",
|
|
320
|
+
commitmentMode: "framework",
|
|
321
|
+
implemented: true,
|
|
322
|
+
requiredEvidenceTypes: [],
|
|
323
|
+
requiredFinalFields: ["source_coverage", "data_gap_disclosure"],
|
|
324
|
+
requiresFreshness: false,
|
|
325
|
+
requiresDataGapDisclosure: true,
|
|
326
|
+
requiresRiskDownside: false,
|
|
327
|
+
requiresSourceCoverage: true,
|
|
328
|
+
requiresConcreteCommitment: false,
|
|
329
|
+
capabilityGapIds: ["sentiment_sample_depth"],
|
|
330
|
+
frameworkFallback: "not_allowed",
|
|
331
|
+
},
|
|
332
|
+
filing_thesis_review: {
|
|
333
|
+
id: "filing_thesis_review",
|
|
334
|
+
taskFamily: "filing_thesis_review",
|
|
335
|
+
commitmentMode: "framework",
|
|
336
|
+
implemented: true,
|
|
337
|
+
requiredEvidenceTypes: [],
|
|
338
|
+
requiredFinalFields: ["source_coverage", "data_gap_disclosure", "framework_or_checklist"],
|
|
339
|
+
requiresFreshness: false,
|
|
340
|
+
requiresDataGapDisclosure: true,
|
|
341
|
+
requiresRiskDownside: false,
|
|
342
|
+
requiresSourceCoverage: true,
|
|
343
|
+
requiresConcreteCommitment: false,
|
|
344
|
+
capabilityGapIds: [],
|
|
345
|
+
frameworkFallback: "not_allowed",
|
|
346
|
+
},
|
|
347
|
+
retail_tradeoff_framework: {
|
|
348
|
+
id: "retail_tradeoff_framework",
|
|
349
|
+
taskFamily: "retail_finance_tradeoff",
|
|
350
|
+
commitmentMode: "framework",
|
|
351
|
+
implemented: true,
|
|
352
|
+
requiredEvidenceTypes: [],
|
|
353
|
+
requiredFinalFields: ["comparison_tradeoffs", "data_gap_disclosure", "framework_or_checklist"],
|
|
354
|
+
requiresFreshness: false,
|
|
355
|
+
requiresDataGapDisclosure: true,
|
|
356
|
+
requiresRiskDownside: false,
|
|
357
|
+
requiresSourceCoverage: false,
|
|
358
|
+
requiresConcreteCommitment: false,
|
|
359
|
+
capabilityGapIds: ["brokerage_comparison", "cash_yield_products", "fund_tax_efficiency"],
|
|
360
|
+
frameworkFallback: "not_allowed",
|
|
361
|
+
},
|
|
362
|
+
concept_explainer: {
|
|
363
|
+
id: "concept_explainer",
|
|
364
|
+
taskFamily: "concept_explainer",
|
|
365
|
+
commitmentMode: "framework",
|
|
366
|
+
implemented: true,
|
|
367
|
+
requiredEvidenceTypes: [],
|
|
368
|
+
requiredFinalFields: ["framework_or_checklist"],
|
|
369
|
+
requiresFreshness: false,
|
|
370
|
+
requiresDataGapDisclosure: false,
|
|
371
|
+
requiresRiskDownside: false,
|
|
372
|
+
requiresSourceCoverage: false,
|
|
373
|
+
requiresConcreteCommitment: false,
|
|
374
|
+
capabilityGapIds: [],
|
|
375
|
+
frameworkFallback: "not_allowed",
|
|
376
|
+
},
|
|
377
|
+
general_fallback: placeholderContract("general_fallback", "general_fallback", "framework", ["data_gap_disclosure"]),
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
export function runStructuredChecks(input: StructuredCheckInput): StructuredCheckTrace {
|
|
381
|
+
const requestedChecks = new Set(input.structuredCheckIds ?? []);
|
|
382
|
+
const results: StructuredCheckResult[] = [
|
|
383
|
+
checkRequiredEvidence(input.contract, input.evidenceRecords),
|
|
384
|
+
checkFreshness(input.contract, input.finalAnswerMetadata),
|
|
385
|
+
checkDataGapDisclosure(input.contract, input.evidenceRecords, input.finalAnswerMetadata),
|
|
386
|
+
checkCommitmentMode(input.contract, input.finalAnswerMetadata),
|
|
387
|
+
checkSourceCoverage(input.contract, input.finalAnswerMetadata),
|
|
388
|
+
checkCapabilityGapDisclosure(input.contract, input.evidenceRecords, input.finalAnswerMetadata),
|
|
389
|
+
...semanticChecks(requestedChecks, input.answerText),
|
|
390
|
+
];
|
|
391
|
+
const failures = results.filter((result) => !result.passed);
|
|
392
|
+
const retryReasons = failures.map((failure) => `${failure.checkId}: ${failure.failureReason ?? "failed"}`);
|
|
393
|
+
|
|
394
|
+
return {
|
|
395
|
+
mode: "observe_only",
|
|
396
|
+
answerContractId: input.contract.id,
|
|
397
|
+
results,
|
|
398
|
+
failures,
|
|
399
|
+
retryEligibility: {
|
|
400
|
+
eligible: failures.length > 0,
|
|
401
|
+
activeRetryAllowed: false,
|
|
402
|
+
reasons: retryReasons,
|
|
403
|
+
},
|
|
404
|
+
activeRetryAllowed: false,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function semanticChecks(
|
|
409
|
+
requestedChecks: ReadonlySet<StructuredCheckId>,
|
|
410
|
+
answerText: string | undefined,
|
|
411
|
+
): StructuredCheckResult[] {
|
|
412
|
+
const checks: StructuredCheckResult[] = [];
|
|
413
|
+
if (requestedChecks.has("assumption_disclosed")) {
|
|
414
|
+
checks.push(checkAnswerText(
|
|
415
|
+
"assumption_disclosed",
|
|
416
|
+
answerText,
|
|
417
|
+
/\b(?:assuming|assumption|assuming that|if your|based on your stated|given your stated)\b/i,
|
|
418
|
+
"Explicit assumption disclosure is missing.",
|
|
419
|
+
));
|
|
420
|
+
}
|
|
421
|
+
if (requestedChecks.has("tax_caveat_present")) {
|
|
422
|
+
checks.push(checkAnswerText(
|
|
423
|
+
"tax_caveat_present",
|
|
424
|
+
answerText,
|
|
425
|
+
/\b(?:tax|taxable|after[-\s]?tax|capital gains?|ordinary income|qualified dividend|tax advisor|jurisdiction|account type)\b/i,
|
|
426
|
+
"Tax/account caveat is missing.",
|
|
427
|
+
));
|
|
428
|
+
}
|
|
429
|
+
if (requestedChecks.has("target_bands_present")) {
|
|
430
|
+
checks.push(checkAnswerText(
|
|
431
|
+
"target_bands_present",
|
|
432
|
+
answerText,
|
|
433
|
+
/\b(?:target bands?|bands?|range|threshold|drift|5\s*%|percentage points?)\b/i,
|
|
434
|
+
"Target band, range, or rebalance threshold guidance is missing.",
|
|
435
|
+
));
|
|
436
|
+
}
|
|
437
|
+
if (requestedChecks.has("when_not_ideal_present")) {
|
|
438
|
+
checks.push(checkAnswerText(
|
|
439
|
+
"when_not_ideal_present",
|
|
440
|
+
answerText,
|
|
441
|
+
/\b(?:not ideal|avoid|bad fit|poor fit|when this fails|where it fails|doesn'?t work|not suitable|watch out)\b/i,
|
|
442
|
+
"When-not-ideal or unsuitability guidance is missing.",
|
|
443
|
+
));
|
|
444
|
+
}
|
|
445
|
+
return checks;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function checkAnswerText(
|
|
449
|
+
checkId: StructuredCheckId,
|
|
450
|
+
answerText: string | undefined,
|
|
451
|
+
pattern: RegExp,
|
|
452
|
+
failureReason: string,
|
|
453
|
+
): StructuredCheckResult {
|
|
454
|
+
const passed = typeof answerText === "string" && pattern.test(answerText);
|
|
455
|
+
return structuredResult(
|
|
456
|
+
checkId,
|
|
457
|
+
passed,
|
|
458
|
+
passed ? undefined : failureReason,
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export function evaluateFrameworkFallbackEligibility(
|
|
463
|
+
input: FrameworkFallbackInput,
|
|
464
|
+
): FrameworkFallbackEligibility {
|
|
465
|
+
if (input.contract.frameworkFallback === "not_allowed") {
|
|
466
|
+
return {
|
|
467
|
+
eligible: false,
|
|
468
|
+
active: false,
|
|
469
|
+
mode: "not_applicable",
|
|
470
|
+
reason: "Contract does not allow framework fallback.",
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const hasUnresolvedSymbol = input.evidenceRecords.some((record) =>
|
|
475
|
+
record.evidenceType === "ticker_disambiguation" &&
|
|
476
|
+
(record.caveats.length > 0 || record.entityScope.symbols === undefined || record.entityScope.symbols.length === 0),
|
|
477
|
+
);
|
|
478
|
+
if (!hasUnresolvedSymbol) {
|
|
479
|
+
return {
|
|
480
|
+
eligible: false,
|
|
481
|
+
active: false,
|
|
482
|
+
mode: "not_applicable",
|
|
483
|
+
reason: "No unresolved selected-slice evidence gap was observed.",
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const parityAllowsActive =
|
|
488
|
+
input.parityStatus === "replacement_active" || input.parityStatus === "legacy_removed";
|
|
489
|
+
return {
|
|
490
|
+
eligible: true,
|
|
491
|
+
active: parityAllowsActive,
|
|
492
|
+
mode: parityAllowsActive ? "active" : "diagnostic_only",
|
|
493
|
+
reason: parityAllowsActive
|
|
494
|
+
? "Selected-slice parity permits active framework fallback."
|
|
495
|
+
: "Selected-slice fallback is recorded diagnostically until parity passes.",
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function placeholderContract(
|
|
500
|
+
id: AnswerContractId,
|
|
501
|
+
taskFamily: TaskFamily,
|
|
502
|
+
commitmentMode: CommitmentMode,
|
|
503
|
+
requiredFinalFields: FinalAnswerField[],
|
|
504
|
+
): AnswerContractDefinition {
|
|
505
|
+
return {
|
|
506
|
+
id,
|
|
507
|
+
taskFamily,
|
|
508
|
+
commitmentMode,
|
|
509
|
+
implemented: false,
|
|
510
|
+
requiredEvidenceTypes: [],
|
|
511
|
+
requiredFinalFields,
|
|
512
|
+
requiresFreshness: false,
|
|
513
|
+
requiresDataGapDisclosure: requiredFinalFields.includes("data_gap_disclosure"),
|
|
514
|
+
requiresRiskDownside: requiredFinalFields.includes("risk_downside"),
|
|
515
|
+
requiresSourceCoverage: requiredFinalFields.includes("source_coverage"),
|
|
516
|
+
requiresConcreteCommitment: COMMITMENT_MODE_CONTRACTS[commitmentMode].requiresConcreteCommitment,
|
|
517
|
+
capabilityGapIds: [],
|
|
518
|
+
frameworkFallback: "not_allowed",
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function checkRequiredEvidence(
|
|
523
|
+
contract: AnswerContractDefinition,
|
|
524
|
+
evidenceRecords: PlanningEvidenceRecord[],
|
|
525
|
+
): StructuredCheckResult {
|
|
526
|
+
const evidenceTypes = new Set(evidenceRecords.map((record) => record.evidenceType));
|
|
527
|
+
const missing = contract.requiredEvidenceTypes.filter((type) => !evidenceTypes.has(type));
|
|
528
|
+
return structuredResult(
|
|
529
|
+
"required_evidence_present",
|
|
530
|
+
missing.length === 0,
|
|
531
|
+
missing.length > 0 ? `Missing evidence types: ${missing.join(", ")}` : undefined,
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function checkFreshness(
|
|
536
|
+
contract: AnswerContractDefinition,
|
|
537
|
+
metadata: FinalAnswerMetadata,
|
|
538
|
+
): StructuredCheckResult {
|
|
539
|
+
if (!contract.requiresFreshness) return structuredResult("freshness_disclosed", true);
|
|
540
|
+
const present = metadata.finalFields.includes("freshness_disclosure") && metadata.freshness !== undefined;
|
|
541
|
+
return structuredResult(
|
|
542
|
+
"freshness_disclosed",
|
|
543
|
+
present,
|
|
544
|
+
present ? undefined : "Freshness metadata or freshness disclosure field is missing.",
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function checkDataGapDisclosure(
|
|
549
|
+
contract: AnswerContractDefinition,
|
|
550
|
+
evidenceRecords: PlanningEvidenceRecord[],
|
|
551
|
+
metadata: FinalAnswerMetadata,
|
|
552
|
+
): StructuredCheckResult {
|
|
553
|
+
if (!contract.requiresDataGapDisclosure) return structuredResult("data_gap_disclosed", true);
|
|
554
|
+
const evidenceHasGaps = evidenceRecords.some((record) => record.gaps.length > 0);
|
|
555
|
+
const fieldPresent = metadata.finalFields.includes("data_gap_disclosure");
|
|
556
|
+
const disclosedProvider = (metadata.disclosedProviderStatuses?.length ?? 0) > 0;
|
|
557
|
+
const disclosedCapability = (metadata.disclosedCapabilityGapIds?.length ?? 0) > 0;
|
|
558
|
+
const passed = fieldPresent && (!evidenceHasGaps || disclosedProvider || disclosedCapability);
|
|
559
|
+
return structuredResult(
|
|
560
|
+
"data_gap_disclosed",
|
|
561
|
+
passed,
|
|
562
|
+
passed ? undefined : "Data-gap disclosure metadata does not cover observed evidence gaps.",
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function checkCommitmentMode(
|
|
567
|
+
contract: AnswerContractDefinition,
|
|
568
|
+
metadata: FinalAnswerMetadata,
|
|
569
|
+
): StructuredCheckResult {
|
|
570
|
+
const modeContract = COMMITMENT_MODE_CONTRACTS[contract.commitmentMode];
|
|
571
|
+
const fields = new Set(metadata.finalFields);
|
|
572
|
+
const requiredFieldsPresent = modeContract.requiredFinalFields.every((field) => fields.has(field));
|
|
573
|
+
const passed =
|
|
574
|
+
metadata.commitmentMode === contract.commitmentMode &&
|
|
575
|
+
requiredFieldsPresent &&
|
|
576
|
+
(!contract.requiresConcreteCommitment || fields.has("clear_commitment"));
|
|
577
|
+
return structuredResult(
|
|
578
|
+
"commitment_mode_respected",
|
|
579
|
+
passed,
|
|
580
|
+
passed ? undefined : `Expected ${contract.commitmentMode} metadata and fields: ${modeContract.requiredFinalFields.join(", ")}`,
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
function checkSourceCoverage(
|
|
585
|
+
contract: AnswerContractDefinition,
|
|
586
|
+
metadata: FinalAnswerMetadata,
|
|
587
|
+
): StructuredCheckResult {
|
|
588
|
+
if (!contract.requiresSourceCoverage) return structuredResult("source_coverage_disclosed", true);
|
|
589
|
+
const present =
|
|
590
|
+
metadata.finalFields.includes("source_coverage") &&
|
|
591
|
+
metadata.sourceCoverage !== undefined &&
|
|
592
|
+
metadata.sourceCoverage.sources.length > 0;
|
|
593
|
+
return structuredResult(
|
|
594
|
+
"source_coverage_disclosed",
|
|
595
|
+
present,
|
|
596
|
+
present ? undefined : "Source-coverage metadata is missing.",
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
function checkCapabilityGapDisclosure(
|
|
601
|
+
contract: AnswerContractDefinition,
|
|
602
|
+
evidenceRecords: PlanningEvidenceRecord[],
|
|
603
|
+
metadata: FinalAnswerMetadata,
|
|
604
|
+
): StructuredCheckResult {
|
|
605
|
+
const required = new Set<CapabilityGapId>(contract.capabilityGapIds);
|
|
606
|
+
for (const record of evidenceRecords) {
|
|
607
|
+
for (const gap of record.gaps) {
|
|
608
|
+
if (gap.capabilityGapId) required.add(gap.capabilityGapId);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
if (required.size === 0) return structuredResult("capability_gap_disclosure", true);
|
|
612
|
+
|
|
613
|
+
const disclosed = new Set(metadata.disclosedCapabilityGapIds ?? []);
|
|
614
|
+
const missing = [...required].filter((gapId) => !disclosed.has(gapId));
|
|
615
|
+
return structuredResult(
|
|
616
|
+
"capability_gap_disclosure",
|
|
617
|
+
missing.length === 0,
|
|
618
|
+
missing.length > 0 ? `Missing capability-gap disclosures: ${missing.join(", ")}` : undefined,
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
function structuredResult(
|
|
623
|
+
checkId: StructuredCheckId,
|
|
624
|
+
passed: boolean,
|
|
625
|
+
failureReason?: string,
|
|
626
|
+
): StructuredCheckResult {
|
|
627
|
+
return {
|
|
628
|
+
checkId,
|
|
629
|
+
passed,
|
|
630
|
+
observedOnly: true,
|
|
631
|
+
failureReason,
|
|
632
|
+
};
|
|
633
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { PolicyCardId, TaskFamily } from "../routing/planning.js";
|
|
2
|
+
|
|
3
|
+
export type ArtifactContractId =
|
|
4
|
+
| "concept_example_table"
|
|
5
|
+
| "portfolio_exposure_map"
|
|
6
|
+
| "rebalance_action_plan"
|
|
7
|
+
| "source_coverage_table";
|
|
8
|
+
|
|
9
|
+
export interface ArtifactContractDefinition {
|
|
10
|
+
id: ArtifactContractId;
|
|
11
|
+
taskFamilies: TaskFamily[];
|
|
12
|
+
description: string;
|
|
13
|
+
status: "trace_only";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const ARTIFACT_CONTRACT_REGISTRY: Record<ArtifactContractId, ArtifactContractDefinition> = {
|
|
17
|
+
concept_example_table: {
|
|
18
|
+
id: "concept_example_table",
|
|
19
|
+
taskFamilies: ["concept_explainer"],
|
|
20
|
+
description: "Compact examples, cross-checks, or comparison rows for educational answers.",
|
|
21
|
+
status: "trace_only",
|
|
22
|
+
},
|
|
23
|
+
portfolio_exposure_map: {
|
|
24
|
+
id: "portfolio_exposure_map",
|
|
25
|
+
taskFamilies: ["portfolio_review"],
|
|
26
|
+
description: "Structural exposure map for portfolio review and rebalance prompts.",
|
|
27
|
+
status: "trace_only",
|
|
28
|
+
},
|
|
29
|
+
rebalance_action_plan: {
|
|
30
|
+
id: "rebalance_action_plan",
|
|
31
|
+
taskFamilies: ["portfolio_review"],
|
|
32
|
+
description: "Staged rebalance action plan with target ranges and execution caveats.",
|
|
33
|
+
status: "trace_only",
|
|
34
|
+
},
|
|
35
|
+
source_coverage_table: {
|
|
36
|
+
id: "source_coverage_table",
|
|
37
|
+
taskFamilies: ["sentiment_snapshot", "filing_thesis_review", "current_event_explanation"],
|
|
38
|
+
description: "Source and provider-gap coverage table for source-heavy answers.",
|
|
39
|
+
status: "trace_only",
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export function artifactContractIdsForPlanning(input: {
|
|
44
|
+
taskFamily: TaskFamily;
|
|
45
|
+
policyCardId: PolicyCardId;
|
|
46
|
+
}): ArtifactContractId[] {
|
|
47
|
+
if (
|
|
48
|
+
input.policyCardId === "concept_options_education" ||
|
|
49
|
+
input.policyCardId === "concept_inflation_cash_education" ||
|
|
50
|
+
input.policyCardId === "concept_valuation_metric_education"
|
|
51
|
+
) {
|
|
52
|
+
return ["concept_example_table"];
|
|
53
|
+
}
|
|
54
|
+
if (input.policyCardId === "portfolio_rebalance_review") {
|
|
55
|
+
return ["portfolio_exposure_map", "rebalance_action_plan"];
|
|
56
|
+
}
|
|
57
|
+
if (
|
|
58
|
+
input.taskFamily === "sentiment_snapshot" ||
|
|
59
|
+
input.taskFamily === "filing_thesis_review" ||
|
|
60
|
+
input.taskFamily === "current_event_explanation"
|
|
61
|
+
) {
|
|
62
|
+
return ["source_coverage_table"];
|
|
63
|
+
}
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function validateArtifactContractRegistry(): string[] {
|
|
68
|
+
const errors: string[] = [];
|
|
69
|
+
for (const [id, contract] of Object.entries(ARTIFACT_CONTRACT_REGISTRY)) {
|
|
70
|
+
if (contract.id !== id) errors.push(`${id} key must match contract id`);
|
|
71
|
+
if (contract.status !== "trace_only") errors.push(`${id} must remain trace-only in V1`);
|
|
72
|
+
if (contract.taskFamilies.length === 0) errors.push(`${id} must declare at least one task family`);
|
|
73
|
+
if (!contract.description.trim()) errors.push(`${id} must include a description`);
|
|
74
|
+
}
|
|
75
|
+
return errors;
|
|
76
|
+
}
|