@egbe-ai/opencode 0.0.0-stage → 0.1.8
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 +4 -0
- package/README.md +124 -2
- package/index.js +5 -0
- package/package.json +55 -4
- package/plugin.js +230 -0
- package/session-log.js +315 -0
- package/skills/.egbe-catalog/manifest.json +1 -0
- package/skills/egbe-os-analytics/SKILL.md +499 -0
- package/skills/egbe-os-analytics/canonical-events.v1.json +256 -0
- package/skills/egbe-os-analytics/references/session-funnel.md +130 -0
- package/skills/egbe-os-analytics/references/workflows/activation-tracking.md +147 -0
- package/skills/egbe-os-analytics/references/workflows/landing-click-tracking.md +209 -0
- package/skills/egbe-os-analytics/references/workflows/payment-lifecycle-tracking.md +122 -0
- package/skills/egbe-os-analytics/references/workflows/product-funnel-tracking.md +77 -0
- package/skills/egbe-os-analytics/references/workflows/signup-lifecycle-tracking.md +208 -0
- package/skills/egbe-os-analytics/scripts/umami_funnel.py +927 -0
- package/skills/egbe-os-apollo-lead-finder/SKILL.md +135 -0
- package/skills/egbe-os-apollo-lead-finder/references/operations.md +240 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/enrich.js +6 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/enrich.sh +4 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/find-leads.js +6 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/find-leads.sh +4 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/lib/apollo-client.js +343 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/lib/connection-identity.js +17 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/lib/helpers.js +127 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/lib/places-filters.js +217 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/lib/sourcing.js +153 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/places-leads.js +653 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/places-leads.sh +4 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/search.js +6 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/search.sh +4 -0
- package/skills/egbe-os-campaign-landing-page/SKILL.md +95 -0
- package/skills/egbe-os-campaign-landing-page/agents/openai.yaml +4 -0
- package/skills/egbe-os-campaign-landing-page/references/leads-calendar-and-tracking.md +66 -0
- package/skills/egbe-os-campaign-landing-page/references/os-wiring.md +58 -0
- package/skills/egbe-os-campaign-landing-page/references/qa.md +40 -0
- package/skills/egbe-os-campaign-landing-page/references/routing.md +32 -0
- package/skills/egbe-os-db/SKILL.md +174 -0
- package/skills/egbe-os-deploy/SKILL.md +412 -0
- package/skills/egbe-os-design/SKILL.md +182 -0
- package/skills/egbe-os-design-landing-page/SKILL.md +117 -0
- package/skills/egbe-os-design-landing-page/agents/openai.yaml +4 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/.dockerignore +11 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/AGENTS.md +31 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/Dockerfile +21 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/eslint.config.mjs +18 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/next.config.ts +11 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/package.json +36 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/postcss.config.mjs +7 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/public/.gitkeep +1 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/sentry.edge.config.ts +13 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/sentry.server.config.ts +13 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/app/global-error.tsx +19 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/app/globals.css +22 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/app/layout.tsx +21 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/app/page.tsx +3 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/app/privacy/page.tsx +28 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/components/egbe-analytics.tsx +39 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/instrumentation-client.ts +15 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/instrumentation.ts +13 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/lib/egbe-observability.generated.ts +20 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/lib/utils.ts +6 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/tsconfig.json +34 -0
- package/skills/egbe-os-design-landing-page/references/application-preparation.md +44 -0
- package/skills/egbe-os-design-landing-page/references/page-inputs.md +22 -0
- package/skills/egbe-os-destination-readiness/SKILL.md +132 -0
- package/skills/egbe-os-destination-readiness/references/checks.md +130 -0
- package/skills/egbe-os-destination-readiness/references/network-requirements.md +34 -0
- package/skills/egbe-os-destination-readiness/references/report.md +116 -0
- package/skills/egbe-os-domains/SKILL.md +189 -0
- package/skills/egbe-os-errors/SKILL.md +259 -0
- package/skills/egbe-os-git/SKILL.md +275 -0
- package/skills/egbe-os-git/references/issues.md +33 -0
- package/skills/egbe-os-google-ads/SKILL.md +163 -0
- package/skills/egbe-os-google-ads/references/artifacts.md +133 -0
- package/skills/egbe-os-google-ads/references/campaigns.md +157 -0
- package/skills/egbe-os-google-ads/references/conversions.md +153 -0
- package/skills/egbe-os-google-ads/references/delivery.md +128 -0
- package/skills/egbe-os-google-ads/references/keyword-ideas.md +40 -0
- package/skills/egbe-os-google-ads/references/reporting.md +105 -0
- package/skills/egbe-os-google-ads/references/search-assets.md +219 -0
- package/skills/egbe-os-google-ads/references/server-conversions.md +119 -0
- package/skills/egbe-os-google-auth/SKILL.md +285 -0
- package/skills/egbe-os-google-auth/agents/openai.yaml +4 -0
- package/skills/egbe-os-gtm-knowledge/SKILL.md +151 -0
- package/skills/egbe-os-images/SKILL.md +163 -0
- package/skills/egbe-os-images/references/stock-images.md +21 -0
- package/skills/egbe-os-instantly-campaign-launcher/SKILL.md +127 -0
- package/skills/egbe-os-instantly-campaign-launcher/references/instantly-ops.md +260 -0
- package/skills/egbe-os-instantly-campaign-launcher/references/observation-and-scheduling.md +188 -0
- package/skills/egbe-os-instantly-campaign-launcher/references/reply-handling.md +116 -0
- package/skills/egbe-os-instantly-campaign-launcher/references/run-spec-template.json +65 -0
- package/skills/egbe-os-instantly-campaign-launcher/references/run-state.md +145 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/conclude-campaign.js +158 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/install-crons.js +956 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/launch-campaign.js +2008 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/campaign-metrics.js +124 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/confirmed-opt-outs.js +208 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/connection-identity.js +17 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/create-once.js +23 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/gtm-identity.js +125 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/helpers.js +545 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/html-body.js +266 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/instantly-client.js +328 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/outreach-db.js +370 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/recipient-exclusion/index.js +86 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/replenish-test-harness.js +53 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/reply-queue.js +67 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/run-config.js +103 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/sender-selection.js +105 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/monitor-campaign.js +607 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/outreach-report.js +147 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/replenish-leads.js +619 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/reply-worker.js +258 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/run-cron-job.js +32 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/send-reply.js +260 -0
- package/skills/egbe-os-linkedin-ads/SKILL.md +114 -0
- package/skills/egbe-os-linkedin-ads/references/destination-requirements.md +30 -0
- package/skills/egbe-os-linkedin-ads/references/runtime/api-reference.md +154 -0
- package/skills/egbe-os-linkedin-ads/references/runtime/artifacts.md +63 -0
- package/skills/egbe-os-linkedin-ads/references/workflows/build-paused.md +44 -0
- package/skills/egbe-os-linkedin-ads/references/workflows/conversions.md +88 -0
- package/skills/egbe-os-linkedin-ads/references/workflows/launch-and-pause.md +49 -0
- package/skills/egbe-os-linkedin-ads/references/workflows/monitoring.md +35 -0
- package/skills/egbe-os-linkedin-ads/references/workflows/readiness.md +63 -0
- package/skills/egbe-os-linkedin-ads/references/workflows/targeting-and-creative.md +52 -0
- package/skills/egbe-os-llm/SKILL.md +160 -0
- package/skills/egbe-os-mail/SKILL.md +180 -0
- package/skills/egbe-os-me/SKILL.md +119 -0
- package/skills/egbe-os-meta-ads/SKILL.md +114 -0
- package/skills/egbe-os-meta-ads/references/creative/creative-specs.md +15 -0
- package/skills/egbe-os-meta-ads/references/creative/talking-head.md +35 -0
- package/skills/egbe-os-meta-ads/references/destination-requirements.md +30 -0
- package/skills/egbe-os-meta-ads/references/runtime/api-reference.md +436 -0
- package/skills/egbe-os-meta-ads/references/runtime/artifacts.md +51 -0
- package/skills/egbe-os-meta-ads/references/runtime/insights-reference.md +187 -0
- package/skills/egbe-os-meta-ads/references/runtime/pixel-install.md +196 -0
- package/skills/egbe-os-meta-ads/references/runtime/shared-analytics-attribution.md +16 -0
- package/skills/egbe-os-meta-ads/references/workflows/build-paused.md +36 -0
- package/skills/egbe-os-meta-ads/references/workflows/launch-ready.md +16 -0
- package/skills/egbe-os-meta-ads/references/workflows/launch.md +23 -0
- package/skills/egbe-os-meta-ads/references/workflows/monitoring.md +72 -0
- package/skills/egbe-os-meta-ads/references/workflows/pause.md +17 -0
- package/skills/egbe-os-meta-ads/references/workflows/recovery.md +23 -0
- package/skills/egbe-os-meta-ads/scripts/check-pixel.py +229 -0
- package/skills/egbe-os-meta-ads/scripts/validate-meta-artifacts.py +187 -0
- package/skills/egbe-os-notifications/SKILL.md +78 -0
- package/skills/egbe-os-openai-ads/SKILL.md +149 -0
- package/skills/egbe-os-openai-ads/references/creative/chat-card.md +51 -0
- package/skills/egbe-os-openai-ads/references/destination-requirements.md +29 -0
- package/skills/egbe-os-openai-ads/references/runtime/api-reference.md +219 -0
- package/skills/egbe-os-openai-ads/references/runtime/artifacts.md +169 -0
- package/skills/egbe-os-openai-ads/references/workflows/build-paused.md +40 -0
- package/skills/egbe-os-openai-ads/references/workflows/conversions.md +40 -0
- package/skills/egbe-os-openai-ads/references/workflows/creative-assembly.md +24 -0
- package/skills/egbe-os-openai-ads/references/workflows/launch.md +27 -0
- package/skills/egbe-os-openai-ads/references/workflows/monitoring.md +54 -0
- package/skills/egbe-os-openai-ads/references/workflows/pause.md +22 -0
- package/skills/egbe-os-openai-ads/references/workflows/readiness.md +37 -0
- package/skills/egbe-os-openai-ads/references/workflows/tracking.md +32 -0
- package/skills/egbe-os-openai-ads/scripts/validate-openai-artifacts.py +271 -0
- package/skills/egbe-os-organic-trend-watch/SKILL.md +139 -0
- package/skills/egbe-os-organic-trend-watch/agents/openai.yaml +4 -0
- package/skills/egbe-os-organic-trend-watch/references/analysis-and-adaptation.md +54 -0
- package/skills/egbe-os-organic-trend-watch/references/collection-and-analysis.md +117 -0
- package/skills/egbe-os-organic-trend-watch/references/output-contract.md +133 -0
- package/skills/egbe-os-organic-trend-watch/references/provider-contract.md +169 -0
- package/skills/egbe-os-organic-trend-watch/references/runtime-contract.md +204 -0
- package/skills/egbe-os-organic-trend-watch/references/visual-analysis-prompt.md +17 -0
- package/skills/egbe-os-organic-trend-watch/scripts/_analysis.py +612 -0
- package/skills/egbe-os-organic-trend-watch/scripts/_contract.py +1133 -0
- package/skills/egbe-os-organic-trend-watch/scripts/_provider_inputs.py +165 -0
- package/skills/egbe-os-organic-trend-watch/scripts/analyze-visual-evidence.py +315 -0
- package/skills/egbe-os-organic-trend-watch/scripts/build-provider-inputs.py +88 -0
- package/skills/egbe-os-organic-trend-watch/scripts/connection_identity.py +22 -0
- package/skills/egbe-os-organic-trend-watch/scripts/egbe_artifacts.py +24 -0
- package/skills/egbe-os-organic-trend-watch/scripts/finalize-receipt.py +106 -0
- package/skills/egbe-os-organic-trend-watch/scripts/normalize-videos.py +647 -0
- package/skills/egbe-os-organic-trend-watch/scripts/prepare-visual-evidence.py +324 -0
- package/skills/egbe-os-organic-trend-watch/scripts/render-result.py +30 -0
- package/skills/egbe-os-organic-trend-watch/scripts/run-apify.py +723 -0
- package/skills/egbe-os-organic-trend-watch/scripts/run-state.py +192 -0
- package/skills/egbe-os-organic-trend-watch/scripts/validate-context.py +27 -0
- package/skills/egbe-os-organic-trend-watch/scripts/validate-runtime.py +137 -0
- package/skills/egbe-os-payments/SKILL.md +215 -0
- package/skills/egbe-os-payments/agents/openai.yaml +4 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/.egbe/scaffolds/billing-nextjs-subscription.v1.json +5 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/AGENTS.append.md +13 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/db/migrations/1000_egbe_billing.sql +66 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/package.fragment.json +12 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/scripts/billing-sync.mjs +162 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/app/account/billing/error.tsx +11 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/app/account/billing/loading.tsx +8 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/app/account/billing/page.tsx +121 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/app/api/billing/checkout/route.ts +102 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/app/api/billing/portal/route.ts +54 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/app/api/billing/status/route.ts +22 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/app/api/payments/webhook/route.ts +65 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/components/egbe-billing/plan-badge.tsx +16 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/billing-sync.test.mjs +58 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/catalog.ts +82 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/checkout-payload.ts +47 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/foundation-contract.test.mjs +59 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/lifecycle.d.ts +16 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/lifecycle.mjs +82 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/lifecycle.test.mjs +94 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/os-client.ts +96 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/plans.json +17 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/repository.ts +325 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/signature.d.ts +6 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/signature.mjs +22 -0
- package/skills/egbe-os-payments/references/contracts/plan-catalog.md +46 -0
- package/skills/egbe-os-payments/references/security/durable-verification.md +64 -0
- package/skills/egbe-os-payments/references/security/server-integration.md +26 -0
- package/skills/egbe-os-payments/references/security/webhook-and-entitlements.md +152 -0
- package/skills/egbe-os-payments/references/ux/billing-experience.md +47 -0
- package/skills/egbe-os-payments/references/workflows/account-billing.md +64 -0
- package/skills/egbe-os-payments/references/workflows/discounts-and-promotion-codes.md +265 -0
- package/skills/egbe-os-payments/references/workflows/one-time-purchase.md +75 -0
- package/skills/egbe-os-payments/references/workflows/product-checkout.md +355 -0
- package/skills/egbe-os-payments/references/workflows/subscription-lifecycle.md +55 -0
- package/skills/egbe-os-playbook/SKILL.md +79 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/channels/email-outreach.md +91 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/channels/google-search.md +40 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/channels/linkedin.md +24 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/channels/meta.md +23 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/channels/openai.md +15 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/channels/reddit.md +56 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/choose-test.md +73 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/evaluate.md +91 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/market.md +96 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/run-test.md +111 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition.md +56 -0
- package/skills/egbe-os-playbook/playbooks/product/business-loop.md +141 -0
- package/skills/egbe-os-playbook/playbooks/product/collaboration.md +26 -0
- package/skills/egbe-os-playbook/playbooks/product/deliver.md +75 -0
- package/skills/egbe-os-playbook/playbooks/product/diagnose.md +80 -0
- package/skills/egbe-os-playbook/playbooks/product/evaluate.md +67 -0
- package/skills/egbe-os-playbook/playbooks/product/experience.md +132 -0
- package/skills/egbe-os-playbook/playbooks/product/loop-examples.md +67 -0
- package/skills/egbe-os-playbook/playbooks/product/offer.md +65 -0
- package/skills/egbe-os-playbook/playbooks/product/value.md +91 -0
- package/skills/egbe-os-playbook/playbooks/product.md +67 -0
- package/skills/egbe-os-playbook/references/catalog.md +127 -0
- package/skills/egbe-os-playbook/references/changes.md +167 -0
- package/skills/egbe-os-playbook/scripts/playbook-changes.py +6 -0
- package/skills/egbe-os-playbook/scripts/playbook_changes/__init__.py +1 -0
- package/skills/egbe-os-playbook/scripts/playbook_changes/cli.py +57 -0
- package/skills/egbe-os-playbook/scripts/playbook_changes/operations.py +137 -0
- package/skills/egbe-os-playbook/scripts/playbook_changes/protocol.py +132 -0
- package/skills/egbe-os-playbook/scripts/playbook_changes/storage.py +180 -0
- package/skills/egbe-os-playbook/scripts/playbook_changes/transport.py +113 -0
- package/skills/egbe-os-product-auth/SKILL.md +151 -0
- package/skills/egbe-os-product-auth/agents/openai.yaml +4 -0
- package/skills/egbe-os-product-auth/assets/db/README.md +102 -0
- package/skills/egbe-os-product-auth/assets/db/create-validation-session.mjs +223 -0
- package/skills/egbe-os-product-auth/assets/db/migrate.mjs +64 -0
- package/skills/egbe-os-product-auth/assets/db/migrations/0001_auth.sql +33 -0
- package/skills/egbe-os-product-auth/assets/db/migrations/0002_auth_identities.sql +16 -0
- package/skills/egbe-os-product-auth/assets/scaffolds/product-auth-database/AGENTS.append.md +17 -0
- package/skills/egbe-os-product-auth/assets/scaffolds/product-auth-database/package.fragment.json +10 -0
- package/skills/egbe-os-product-auth/assets/scaffolds/product-nextjs-postgres/AGENTS.append.md +9 -0
- package/skills/egbe-os-product-auth/assets/scaffolds/product-nextjs-postgres/package.fragment.json +13 -0
- package/skills/egbe-os-product-auth/assets/scaffolds/product-nextjs-postgres/src/lib/egbe-product/db.ts +31 -0
- package/skills/egbe-os-product-auth/assets/scaffolds/product-nextjs-postgres/src/lib/egbe-product/identity.ts +94 -0
- package/skills/egbe-os-product-auth/assets/scaffolds/product-nextjs-postgres/src/lib/egbe-product/index.ts +3 -0
- package/skills/egbe-os-product-auth/assets/scaffolds/product-nextjs-postgres/src/lib/egbe-product/session.ts +91 -0
- package/skills/egbe-os-product-auth/references/contracts/live-auth-interface.md +108 -0
- package/skills/egbe-os-product-auth/references/frameworks/nextjs.md +34 -0
- package/skills/egbe-os-product-auth/references/security/session-and-credentials.md +73 -0
- package/skills/egbe-os-product-auth/references/ux/auth-experience.md +58 -0
- package/skills/egbe-os-product-auth/references/workflows/account-recovery.md +22 -0
- package/skills/egbe-os-product-auth/references/workflows/build-auth.md +212 -0
- package/skills/egbe-os-product-auth/references/workflows/google.md +34 -0
- package/skills/egbe-os-product-auth/references/workflows/passwordless-email.md +65 -0
- package/skills/egbe-os-product-build/SKILL.md +111 -0
- package/skills/egbe-os-product-build/agents/openai.yaml +4 -0
- package/skills/egbe-os-product-build/references/capabilities.md +25 -0
- package/skills/egbe-os-product-build/references/engineering.md +72 -0
- package/skills/egbe-os-product-build/references/execution.md +55 -0
- package/skills/egbe-os-product-build/references/foundations.md +93 -0
- package/skills/egbe-os-product-build/references/interface-quality.md +32 -0
- package/skills/egbe-os-product-build/references/workflows/private-review-handoff.md +86 -0
- package/skills/egbe-os-product-build/scripts/scaffold.py +296 -0
- package/skills/egbe-os-product-demo-video/SKILL.md +118 -0
- package/skills/egbe-os-product-demo-video/references/recording.md +32 -0
- package/skills/egbe-os-product-market-research/SKILL.md +159 -0
- package/skills/egbe-os-product-market-research/agents/openai.yaml +4 -0
- package/skills/egbe-os-product-market-research/references/catalog.v1.json +177 -0
- package/skills/egbe-os-product-market-research/references/config/channel-footprint-sources.v1.json +99 -0
- package/skills/egbe-os-product-market-research/references/config/creative-taxonomy.v1.json +367 -0
- package/skills/egbe-os-product-market-research/references/contracts/creative-video.md +75 -0
- package/skills/egbe-os-product-market-research/references/contracts/funnel-teardown.md +235 -0
- package/skills/egbe-os-product-market-research/references/contracts/geography-comparison.md +71 -0
- package/skills/egbe-os-product-market-research/references/contracts/lifecycle-capture.md +119 -0
- package/skills/egbe-os-product-market-research/references/contracts/research-artifacts.md +520 -0
- package/skills/egbe-os-product-market-research/references/contracts/walk-mechanics.v2.json +18 -0
- package/skills/egbe-os-product-market-research/references/prompts/acquisition-channels.md +137 -0
- package/skills/egbe-os-product-market-research/references/prompts/acquisition-channels.user.md +4 -0
- package/skills/egbe-os-product-market-research/references/prompts/competitive-landscape.md +118 -0
- package/skills/egbe-os-product-market-research/references/prompts/competitive-landscape.user.md +4 -0
- package/skills/egbe-os-product-market-research/references/prompts/demand-validation.md +154 -0
- package/skills/egbe-os-product-market-research/references/prompts/demand-validation.user.md +4 -0
- package/skills/egbe-os-product-market-research/references/prompts/market-size-and-dynamics.md +100 -0
- package/skills/egbe-os-product-market-research/references/prompts/market-size-and-dynamics.user.md +4 -0
- package/skills/egbe-os-product-market-research/references/prompts/pricing-and-monetization.md +126 -0
- package/skills/egbe-os-product-market-research/references/prompts/pricing-and-monetization.user.md +4 -0
- package/skills/egbe-os-product-market-research/references/prompts/target-audience.md +98 -0
- package/skills/egbe-os-product-market-research/references/prompts/target-audience.user.md +4 -0
- package/skills/egbe-os-product-market-research/references/prompts/unit-economics.md +217 -0
- package/skills/egbe-os-product-market-research/references/prompts/unit-economics.user.md +4 -0
- package/skills/egbe-os-product-market-research/references/prompts/value-proposition.md +113 -0
- package/skills/egbe-os-product-market-research/references/prompts/value-proposition.user.md +4 -0
- package/skills/egbe-os-product-market-research/references/workflows/acquisition-channels.md +27 -0
- package/skills/egbe-os-product-market-research/references/workflows/channel-footprint.md +163 -0
- package/skills/egbe-os-product-market-research/references/workflows/community-demand.md +100 -0
- package/skills/egbe-os-product-market-research/references/workflows/competitive-landscape.md +27 -0
- package/skills/egbe-os-product-market-research/references/workflows/competitor-ads.md +82 -0
- package/skills/egbe-os-product-market-research/references/workflows/competitor-set.md +300 -0
- package/skills/egbe-os-product-market-research/references/workflows/creative-patterns.md +228 -0
- package/skills/egbe-os-product-market-research/references/workflows/demand-validation.md +27 -0
- package/skills/egbe-os-product-market-research/references/workflows/fleet-prior.md +80 -0
- package/skills/egbe-os-product-market-research/references/workflows/funnel-teardown.md +184 -0
- package/skills/egbe-os-product-market-research/references/workflows/geography-comparison.md +84 -0
- package/skills/egbe-os-product-market-research/references/workflows/keyword-economics.md +122 -0
- package/skills/egbe-os-product-market-research/references/workflows/lifecycle-capture.md +218 -0
- package/skills/egbe-os-product-market-research/references/workflows/local-research.md +55 -0
- package/skills/egbe-os-product-market-research/references/workflows/market-size-and-dynamics.md +27 -0
- package/skills/egbe-os-product-market-research/references/workflows/preview.md +175 -0
- package/skills/egbe-os-product-market-research/references/workflows/pricing-and-monetization.md +27 -0
- package/skills/egbe-os-product-market-research/references/workflows/recommendations.md +35 -0
- package/skills/egbe-os-product-market-research/references/workflows/review-mining.md +76 -0
- package/skills/egbe-os-product-market-research/references/workflows/target-audience.md +27 -0
- package/skills/egbe-os-product-market-research/references/workflows/tiktok-reels-market-trends.md +46 -0
- package/skills/egbe-os-product-market-research/references/workflows/unit-economics.md +27 -0
- package/skills/egbe-os-product-market-research/references/workflows/value-proposition.md +27 -0
- package/skills/egbe-os-product-market-research/scripts/build-organic-trend-context.py +167 -0
- package/skills/egbe-os-product-market-research/scripts/build-preview-context.py +91 -0
- package/skills/egbe-os-product-market-research/scripts/build-research-query.py +225 -0
- package/skills/egbe-os-product-market-research/scripts/channel-footprint-model.py +294 -0
- package/skills/egbe-os-product-market-research/scripts/connection_identity.py +22 -0
- package/skills/egbe-os-product-market-research/scripts/creative-model.py +364 -0
- package/skills/egbe-os-product-market-research/scripts/creative-selection.py +113 -0
- package/skills/egbe-os-product-market-research/scripts/creative-semantics.py +365 -0
- package/skills/egbe-os-product-market-research/scripts/creative-video.py +542 -0
- package/skills/egbe-os-product-market-research/scripts/egbe_artifacts.py +24 -0
- package/skills/egbe-os-product-market-research/scripts/finalize-organic-trend-watch.py +304 -0
- package/skills/egbe-os-product-market-research/scripts/funnel-email-review.py +97 -0
- package/skills/egbe-os-product-market-research/scripts/funnel-model.py +966 -0
- package/skills/egbe-os-product-market-research/scripts/funnel_features.py +50 -0
- package/skills/egbe-os-product-market-research/scripts/geography-comparison-contract.py +172 -0
- package/skills/egbe-os-product-market-research/scripts/geography-comparison.py +169 -0
- package/skills/egbe-os-product-market-research/scripts/keyword-forecast.py +61 -0
- package/skills/egbe-os-product-market-research/scripts/keyword-locale-publication.py +136 -0
- package/skills/egbe-os-product-market-research/scripts/lifecycle-start.py +190 -0
- package/skills/egbe-os-product-market-research/scripts/persist-research-report.py +63 -0
- package/skills/egbe-os-product-market-research/scripts/research-artifact-io.py +281 -0
- package/skills/egbe-os-product-market-research/scripts/research-evidence.py +496 -0
- package/skills/egbe-os-product-market-research/scripts/research-policy.py +33 -0
- package/skills/egbe-os-product-market-research/scripts/research-section-runtime.py +343 -0
- package/skills/egbe-os-product-market-research/scripts/research-section-workflow.py +288 -0
- package/skills/egbe-os-product-market-research/scripts/research_integrity.py +122 -0
- package/skills/egbe-os-product-market-research/scripts/review-research-completion.py +306 -0
- package/skills/egbe-os-product-market-research/scripts/run-acquisition-channels.py +72 -0
- package/skills/egbe-os-product-market-research/scripts/run-channel-footprint.py +2258 -0
- package/skills/egbe-os-product-market-research/scripts/run-community-demand.py +1603 -0
- package/skills/egbe-os-product-market-research/scripts/run-competitive-landscape.py +66 -0
- package/skills/egbe-os-product-market-research/scripts/run-competitor-ads.py +1156 -0
- package/skills/egbe-os-product-market-research/scripts/run-competitor-set.py +2514 -0
- package/skills/egbe-os-product-market-research/scripts/run-creative-patterns.py +2042 -0
- package/skills/egbe-os-product-market-research/scripts/run-demand-validation.py +72 -0
- package/skills/egbe-os-product-market-research/scripts/run-fleet-prior.py +652 -0
- package/skills/egbe-os-product-market-research/scripts/run-funnel-teardown.py +493 -0
- package/skills/egbe-os-product-market-research/scripts/run-keyword-economics.py +1443 -0
- package/skills/egbe-os-product-market-research/scripts/run-lifecycle-capture.py +1543 -0
- package/skills/egbe-os-product-market-research/scripts/run-market-size-and-dynamics.py +66 -0
- package/skills/egbe-os-product-market-research/scripts/run-os-research.py +311 -0
- package/skills/egbe-os-product-market-research/scripts/run-pricing-and-monetization.py +71 -0
- package/skills/egbe-os-product-market-research/scripts/run-review-mining.py +1051 -0
- package/skills/egbe-os-product-market-research/scripts/run-target-audience.py +66 -0
- package/skills/egbe-os-product-market-research/scripts/run-unit-economics.py +71 -0
- package/skills/egbe-os-product-market-research/scripts/run-value-proposition.py +67 -0
- package/skills/egbe-os-product-market-research/scripts/upsert-markdown-section.py +156 -0
- package/skills/egbe-os-product-market-research/scripts/walk-funnels.py +249 -0
- package/skills/egbe-os-product-market-research/scripts/write-preview.py +710 -0
- package/skills/egbe-os-product-market-research/scripts/write-recommendations.py +272 -0
- package/skills/egbe-os-product-report/SKILL.md +150 -0
- package/skills/egbe-os-product-report/references/artifacts.md +84 -0
- package/skills/egbe-os-product-report/references/brief.md +34 -0
- package/skills/egbe-os-product-report/references/daily.md +76 -0
- package/skills/egbe-os-product-report/references/sources.md +68 -0
- package/skills/egbe-os-product-routines/SKILL.md +166 -0
- package/skills/egbe-os-product-routines/references/catalog.md +22 -0
- package/skills/egbe-os-product-routines/references/continuation-check.md +41 -0
- package/skills/egbe-os-product-routines/references/product-reporting.md +163 -0
- package/skills/egbe-os-product-routines/references/run-preset.md +32 -0
- package/skills/egbe-os-quickstart/scripts/egbe-curl.py +357 -0
- package/skills/egbe-os-quiz-funnel/SKILL.md +152 -0
- package/skills/egbe-os-quiz-funnel/agents/openai.yaml +4 -0
- package/skills/egbe-os-quiz-funnel/assets/engine/quiz-engine.d.mts +224 -0
- package/skills/egbe-os-quiz-funnel/assets/engine/quiz-engine.mjs +652 -0
- package/skills/egbe-os-quiz-funnel/assets/engine/quiz-engine.test.mjs +764 -0
- package/skills/egbe-os-quiz-funnel/assets/engine/quiz-history.d.mts +31 -0
- package/skills/egbe-os-quiz-funnel/assets/engine/quiz-history.mjs +87 -0
- package/skills/egbe-os-quiz-funnel/assets/engine/quiz-history.test.mjs +265 -0
- package/skills/egbe-os-quiz-funnel/assets/engine/quiz-reference.test.mjs +254 -0
- package/skills/egbe-os-quiz-funnel/assets/examples/egbe-docs/product/quizzes/books-checkup/QUIZ.md +195 -0
- package/skills/egbe-os-quiz-funnel/assets/examples/egbe-docs/product/quizzes/books-checkup/quiz.json +421 -0
- package/skills/egbe-os-quiz-funnel/assets/examples/egbe-docs/product/quizzes/books-checkup/quiz.public.json +369 -0
- package/skills/egbe-os-quiz-funnel/assets/examples/egbe-docs/product/quizzes/books-checkup/validation.json +21 -0
- package/skills/egbe-os-quiz-funnel/assets/reference/index.html +26 -0
- package/skills/egbe-os-quiz-funnel/assets/reference/quiz-bootstrap.js +31 -0
- package/skills/egbe-os-quiz-funnel/assets/reference/quiz-early-actions.mjs +11 -0
- package/skills/egbe-os-quiz-funnel/assets/reference/quiz-first-screen.mjs +32 -0
- package/skills/egbe-os-quiz-funnel/assets/reference/quiz-page.mjs +480 -0
- package/skills/egbe-os-quiz-funnel/assets/reference/quiz.css +264 -0
- package/skills/egbe-os-quiz-funnel/references/competitor-teardown.md +159 -0
- package/skills/egbe-os-quiz-funnel/references/conversion-handoff.md +156 -0
- package/skills/egbe-os-quiz-funnel/references/implementation.md +207 -0
- package/skills/egbe-os-quiz-funnel/references/inputs.md +37 -0
- package/skills/egbe-os-quiz-funnel/references/measurement.md +122 -0
- package/skills/egbe-os-quiz-funnel/references/spec-contract.md +335 -0
- package/skills/egbe-os-quiz-funnel/references/verification.md +101 -0
- package/skills/egbe-os-quiz-funnel/references/walk-mechanics.v2.json +18 -0
- package/skills/egbe-os-quiz-funnel/scripts/compile-quiz-spec.py +1869 -0
- package/skills/egbe-os-quiz-funnel/scripts/prepare-research-identity.py +66 -0
- package/skills/egbe-os-reddit-ads/SKILL.md +121 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/bold-statement/schema.json +41 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/bold-statement/template.html +106 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/data-proof/schema.json +61 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/data-proof/template.html +151 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/honest-breakdown/schema.json +91 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/honest-breakdown/template.html +185 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/question-hook/schema.json +51 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/question-hook/template.html +121 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/reddit-post-style/schema.json +87 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/reddit-post-style/template.html +212 -0
- package/skills/egbe-os-reddit-ads/references/creative/html-to-png-pipeline.md +123 -0
- package/skills/egbe-os-reddit-ads/references/creative/static-banner-qa.md +12 -0
- package/skills/egbe-os-reddit-ads/references/creative/static-banner-system.md +16 -0
- package/skills/egbe-os-reddit-ads/references/destination-requirements.md +36 -0
- package/skills/egbe-os-reddit-ads/references/runtime/api-reference.md +435 -0
- package/skills/egbe-os-reddit-ads/references/runtime/artifacts.md +57 -0
- package/skills/egbe-os-reddit-ads/references/runtime/monitoring.md +64 -0
- package/skills/egbe-os-reddit-ads/references/runtime/pixel-and-tracking.md +49 -0
- package/skills/egbe-os-reddit-ads/references/runtime/policies.md +19 -0
- package/skills/egbe-os-reddit-ads/references/runtime/shared-analytics-attribution.md +14 -0
- package/skills/egbe-os-reddit-ads/references/workflows/build-paused.md +35 -0
- package/skills/egbe-os-reddit-ads/references/workflows/launch-ready.md +19 -0
- package/skills/egbe-os-reddit-ads/references/workflows/launch.md +32 -0
- package/skills/egbe-os-reddit-ads/references/workflows/readiness.md +9 -0
- package/skills/egbe-os-reddit-ads/scripts/capture-ad.sh +178 -0
- package/skills/egbe-os-reddit-ads/scripts/validate-reddit-artifacts.py +187 -0
- package/skills/egbe-os-report-ui/SKILL.md +133 -0
- package/skills/egbe-os-report-ui/assets/egbe-wordmark.svg +9 -0
- package/skills/egbe-os-report-ui/assets/examples/components.html +417 -0
- package/skills/egbe-os-report-ui/assets/examples/editorial.html +209 -0
- package/skills/egbe-os-report-ui/assets/scaffold.html +179 -0
- package/skills/egbe-os-report-ui/references/components.md +209 -0
- package/skills/egbe-os-research/SKILL.md +125 -0
- package/skills/egbe-os-saas-unit-economics/SKILL.md +188 -0
- package/skills/egbe-os-scrape/SKILL.md +160 -0
- package/skills/egbe-os-search/SKILL.md +182 -0
- package/skills/egbe-os-search/references/google-places.md +81 -0
- package/skills/egbe-os-support/SKILL.md +149 -0
- package/skills/egbe-os-telemetry/SKILL.md +344 -0
- package/skills/egbe-os-telemetry/references/harnesses/claude-code.md +97 -0
- package/skills/egbe-os-telemetry/references/harnesses/codex.md +22 -0
- package/skills/egbe-os-telemetry/references/harnesses/hermes.md +39 -0
- package/skills/egbe-os-telemetry/references/harnesses/openclaw.md +139 -0
- package/skills/egbe-os-telemetry/references/harnesses/opencode.md +28 -0
- package/skills/egbe-os-tools/SKILL.md +180 -0
- package/skills/egbe-os-tools/references/theona.md +26 -0
- package/skills/egbe-os-wallet/SKILL.md +181 -0
- package/skills/egbe-setup/EGBE.md +484 -0
- package/skills/egbe-setup/SKILL.md +116 -0
- package/skills/egbe-setup/references/project.md +80 -0
- package/state.js +37 -0
- package/update.js +361 -0
|
@@ -0,0 +1,710 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Render one founder research Preview and its compact chat summary."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import sys as _artifact_sys
|
|
7
|
+
from pathlib import Path as _ArtifactPath
|
|
8
|
+
_artifact_sys.path.insert(0, str(_ArtifactPath(__file__).resolve().parent))
|
|
9
|
+
from egbe_artifacts import artifact_path as _artifact_path
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
from urllib.parse import urlsplit
|
|
13
|
+
import hashlib
|
|
14
|
+
import json
|
|
15
|
+
import os
|
|
16
|
+
import re
|
|
17
|
+
import tempfile
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Any, Iterable
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
DEFAULT_CONTEXT = Path(_artifact_path("egbe-docs/research/market/work/preview-context.json"))
|
|
23
|
+
DEFAULT_SYNTHESIS = Path(_artifact_path("egbe-docs/research/market/preview-synthesis.json"))
|
|
24
|
+
DEFAULT_FULL_REPORT = Path(_artifact_path("egbe-docs/research/market/full-report.md"))
|
|
25
|
+
DEFAULT_PREVIEW = Path(_artifact_path("egbe-docs/research/market/preview.md"))
|
|
26
|
+
DEFAULT_SUMMARY = Path(_artifact_path("egbe-docs/research/market/summary.md"))
|
|
27
|
+
DEFAULT_RECEIPT = Path(_artifact_path("egbe-docs/research/market/preview-render.json"))
|
|
28
|
+
|
|
29
|
+
PREVIEW_TITLE = "Market Research: Findings and Recommendations"
|
|
30
|
+
FULL_REPORT_TITLE = "Market Research Report"
|
|
31
|
+
MAX_PREVIEW_WORDS = 750
|
|
32
|
+
MAX_SUMMARY_VISIBLE_CHARS = 600
|
|
33
|
+
CONTEXT_STATUSES = frozenset(
|
|
34
|
+
{"pending", "completed", "partial", "no_data", "could_not_complete", "not_selected"}
|
|
35
|
+
)
|
|
36
|
+
COVERAGE_LABEL_KEYS = frozenset({"partial", "no_data"})
|
|
37
|
+
LABEL_KEYS = frozenset(
|
|
38
|
+
{
|
|
39
|
+
"bottom_line",
|
|
40
|
+
"what_matters",
|
|
41
|
+
"what_this_means",
|
|
42
|
+
"what_remains_open",
|
|
43
|
+
"research_coverage",
|
|
44
|
+
"researched",
|
|
45
|
+
"not_included",
|
|
46
|
+
"could_not_complete",
|
|
47
|
+
"full_report",
|
|
48
|
+
"recommended_direction",
|
|
49
|
+
"biggest_open_question",
|
|
50
|
+
"based_on",
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
_STRUCTURAL_MARKDOWN = re.compile(
|
|
54
|
+
r"(?:^\s{0,3}(?:#{1,6}|>|[-+*]|\d+[.)])\s)|"
|
|
55
|
+
r"(?:!?\[[^\]]*\]\([^)]*\)|```|`|\*\*|__|~~|<[^>]+>)"
|
|
56
|
+
)
|
|
57
|
+
_CJK = re.compile(
|
|
58
|
+
r"[\u3400-\u4dbf\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af]"
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class PreviewInputError(ValueError):
|
|
63
|
+
pass
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class _DuplicateJsonKeyError(ValueError):
|
|
67
|
+
pass
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _unique_json_object(pairs: list[tuple[str, Any]]) -> dict[str, Any]:
|
|
71
|
+
value: dict[str, Any] = {}
|
|
72
|
+
for key, item in pairs:
|
|
73
|
+
if key in value:
|
|
74
|
+
raise _DuplicateJsonKeyError(f"duplicate JSON key {key!r}")
|
|
75
|
+
value[key] = item
|
|
76
|
+
return value
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _read_json_object(path: Path, *, label: str) -> dict[str, Any]:
|
|
80
|
+
try:
|
|
81
|
+
value = json.loads(
|
|
82
|
+
path.read_text(encoding="utf-8"),
|
|
83
|
+
object_pairs_hook=_unique_json_object,
|
|
84
|
+
)
|
|
85
|
+
except OSError as exc:
|
|
86
|
+
raise PreviewInputError(f"cannot read {label} {path}: {exc}") from exc
|
|
87
|
+
except (json.JSONDecodeError, UnicodeDecodeError) as exc:
|
|
88
|
+
raise PreviewInputError(f"{label} must be valid UTF-8 JSON") from exc
|
|
89
|
+
except _DuplicateJsonKeyError as exc:
|
|
90
|
+
raise PreviewInputError(f"{label} contains {exc}") from exc
|
|
91
|
+
if not isinstance(value, dict):
|
|
92
|
+
raise PreviewInputError(f"{label} must be a JSON object")
|
|
93
|
+
return value
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _file_sha256(path: Path) -> str:
|
|
97
|
+
digest = hashlib.sha256()
|
|
98
|
+
with path.open("rb") as handle:
|
|
99
|
+
for chunk in iter(lambda: handle.read(64 * 1024), b""):
|
|
100
|
+
digest.update(chunk)
|
|
101
|
+
return digest.hexdigest()
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _validate_context(value: dict[str, Any]) -> dict[str, str]:
|
|
105
|
+
expected_fields = {
|
|
106
|
+
"schema_version",
|
|
107
|
+
"selection_id",
|
|
108
|
+
"source_revision",
|
|
109
|
+
"selected_option_ids",
|
|
110
|
+
"sections",
|
|
111
|
+
}
|
|
112
|
+
if set(value) != expected_fields or value.get("schema_version") != 1:
|
|
113
|
+
raise PreviewInputError(
|
|
114
|
+
"Preview context must use the exact schema_version 1 contract"
|
|
115
|
+
)
|
|
116
|
+
for key in ("selection_id", "source_revision"):
|
|
117
|
+
if not isinstance(value.get(key), str) or not value[key].strip():
|
|
118
|
+
raise PreviewInputError(
|
|
119
|
+
f"Preview context {key} must be a non-empty string"
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
raw_sections = value.get("sections")
|
|
123
|
+
if not isinstance(raw_sections, list) or not raw_sections:
|
|
124
|
+
raise PreviewInputError("Preview context sections must be a non-empty list")
|
|
125
|
+
outcomes: dict[str, str] = {}
|
|
126
|
+
for raw in raw_sections:
|
|
127
|
+
required = {"id", "label", "status"}
|
|
128
|
+
optional = {"coverage", "closed_by_caller"}
|
|
129
|
+
if not isinstance(raw, dict) or not required <= set(raw) <= required | optional:
|
|
130
|
+
raise PreviewInputError(
|
|
131
|
+
"Preview context section entries require id, label, and status; "
|
|
132
|
+
"only coverage and closed_by_caller are optional"
|
|
133
|
+
)
|
|
134
|
+
option_id = raw.get("id")
|
|
135
|
+
label = raw.get("label")
|
|
136
|
+
status = raw.get("status")
|
|
137
|
+
if not isinstance(option_id, str) or not option_id.strip():
|
|
138
|
+
raise PreviewInputError("Preview context contains an invalid section id")
|
|
139
|
+
_plain_text(label, field=f"sections.{option_id}.label", maximum=120)
|
|
140
|
+
if option_id in outcomes:
|
|
141
|
+
raise PreviewInputError(f"Preview context repeats section {option_id!r}")
|
|
142
|
+
if status not in CONTEXT_STATUSES:
|
|
143
|
+
raise PreviewInputError(
|
|
144
|
+
f"Preview context has invalid status for {option_id!r}"
|
|
145
|
+
)
|
|
146
|
+
if "closed_by_caller" in raw and (
|
|
147
|
+
raw["closed_by_caller"] is not True or status != "could_not_complete"
|
|
148
|
+
):
|
|
149
|
+
raise PreviewInputError("Caller closure requires could_not_complete status")
|
|
150
|
+
if "coverage" in raw and (
|
|
151
|
+
not isinstance(raw["coverage"], dict)
|
|
152
|
+
or status not in {"completed", "partial", "no_data"}
|
|
153
|
+
or raw["coverage"].get("status") != {"completed": "complete"}.get(status, status)
|
|
154
|
+
):
|
|
155
|
+
raise PreviewInputError("Preview context coverage must match section status")
|
|
156
|
+
if status == "pending":
|
|
157
|
+
raise PreviewInputError(
|
|
158
|
+
"Preview cannot render while selected research is still pending"
|
|
159
|
+
)
|
|
160
|
+
outcomes[option_id] = status
|
|
161
|
+
|
|
162
|
+
expected_selected = [
|
|
163
|
+
option_id for option_id, status in outcomes.items() if status != "not_selected"
|
|
164
|
+
]
|
|
165
|
+
if value.get("selected_option_ids") != expected_selected or not expected_selected:
|
|
166
|
+
raise PreviewInputError(
|
|
167
|
+
"Preview context selected IDs do not match section outcomes"
|
|
168
|
+
)
|
|
169
|
+
return outcomes
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _plain_text(value: Any, *, field: str, maximum: int) -> str:
|
|
173
|
+
if not isinstance(value, str):
|
|
174
|
+
raise PreviewInputError(f"{field} must be a string")
|
|
175
|
+
normalized = " ".join(value.split())
|
|
176
|
+
if not normalized:
|
|
177
|
+
raise PreviewInputError(f"{field} must not be empty")
|
|
178
|
+
if len(normalized) > maximum:
|
|
179
|
+
raise PreviewInputError(f"{field} must be at most {maximum} characters")
|
|
180
|
+
if _STRUCTURAL_MARKDOWN.search(normalized):
|
|
181
|
+
raise PreviewInputError(
|
|
182
|
+
f"{field} must be plain text without Markdown structure"
|
|
183
|
+
)
|
|
184
|
+
return normalized
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def _source_ids(
|
|
188
|
+
value: Any,
|
|
189
|
+
*,
|
|
190
|
+
field: str,
|
|
191
|
+
evidence_ids: set[str],
|
|
192
|
+
allow_empty: bool,
|
|
193
|
+
) -> list[str]:
|
|
194
|
+
if not isinstance(value, list) or any(not isinstance(item, str) for item in value):
|
|
195
|
+
raise PreviewInputError(f"{field} must be a list of section IDs")
|
|
196
|
+
if len(value) != len(set(value)):
|
|
197
|
+
raise PreviewInputError(f"{field} must not repeat section IDs")
|
|
198
|
+
if not value and not allow_empty:
|
|
199
|
+
raise PreviewInputError(f"{field} must reference usable research evidence")
|
|
200
|
+
unsupported = [item for item in value if item not in evidence_ids]
|
|
201
|
+
if unsupported:
|
|
202
|
+
raise PreviewInputError(
|
|
203
|
+
f"{field} references research without usable evidence: "
|
|
204
|
+
+ ", ".join(unsupported)
|
|
205
|
+
)
|
|
206
|
+
return list(value)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def _validate_synthesis(
|
|
210
|
+
value: dict[str, Any],
|
|
211
|
+
*,
|
|
212
|
+
known_ids: list[str],
|
|
213
|
+
evidence_ids: set[str],
|
|
214
|
+
coverage_statuses: set[str],
|
|
215
|
+
) -> dict[str, Any]:
|
|
216
|
+
expected_fields = {
|
|
217
|
+
"schema_version",
|
|
218
|
+
"labels",
|
|
219
|
+
"section_labels",
|
|
220
|
+
"bottom_line",
|
|
221
|
+
"findings",
|
|
222
|
+
"product_implications",
|
|
223
|
+
"open_questions",
|
|
224
|
+
}
|
|
225
|
+
if set(value) != expected_fields or value.get("schema_version") != 1:
|
|
226
|
+
raise PreviewInputError(
|
|
227
|
+
"Preview synthesis must use the exact schema_version 1 contract"
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
raw_labels = value.get("labels")
|
|
231
|
+
required_labels = LABEL_KEYS | (coverage_statuses & COVERAGE_LABEL_KEYS)
|
|
232
|
+
if (
|
|
233
|
+
not isinstance(raw_labels, dict)
|
|
234
|
+
or not required_labels <= set(raw_labels) <= LABEL_KEYS | COVERAGE_LABEL_KEYS
|
|
235
|
+
):
|
|
236
|
+
raise PreviewInputError(
|
|
237
|
+
"Preview synthesis labels do not match the required contract"
|
|
238
|
+
)
|
|
239
|
+
labels = {
|
|
240
|
+
key: _plain_text(raw_labels[key], field=f"labels.{key}", maximum=80)
|
|
241
|
+
for key in sorted(raw_labels)
|
|
242
|
+
}
|
|
243
|
+
if len(set(labels.values())) != len(labels):
|
|
244
|
+
raise PreviewInputError("Preview synthesis labels must be distinct")
|
|
245
|
+
|
|
246
|
+
raw_section_labels = value.get("section_labels")
|
|
247
|
+
if not isinstance(raw_section_labels, dict) or set(raw_section_labels) != set(
|
|
248
|
+
known_ids
|
|
249
|
+
):
|
|
250
|
+
raise PreviewInputError(
|
|
251
|
+
"Preview synthesis section_labels must contain every runtime section ID"
|
|
252
|
+
)
|
|
253
|
+
section_labels = {
|
|
254
|
+
option_id: _plain_text(
|
|
255
|
+
raw_section_labels[option_id],
|
|
256
|
+
field=f"section_labels.{option_id}",
|
|
257
|
+
maximum=120,
|
|
258
|
+
)
|
|
259
|
+
for option_id in known_ids
|
|
260
|
+
}
|
|
261
|
+
if len(set(section_labels.values())) != len(section_labels):
|
|
262
|
+
raise PreviewInputError("Preview synthesis section_labels must be distinct")
|
|
263
|
+
|
|
264
|
+
raw_bottom = value.get("bottom_line")
|
|
265
|
+
bottom_fields = {
|
|
266
|
+
"summary",
|
|
267
|
+
"detail",
|
|
268
|
+
"source_section_ids",
|
|
269
|
+
"confidence_note",
|
|
270
|
+
}
|
|
271
|
+
if not isinstance(raw_bottom, dict) or set(raw_bottom) != bottom_fields:
|
|
272
|
+
raise PreviewInputError(
|
|
273
|
+
"Preview synthesis bottom_line does not match the required contract"
|
|
274
|
+
)
|
|
275
|
+
bottom_line = {
|
|
276
|
+
"summary": _plain_text(
|
|
277
|
+
raw_bottom.get("summary"),
|
|
278
|
+
field="bottom_line.summary",
|
|
279
|
+
maximum=240,
|
|
280
|
+
),
|
|
281
|
+
"detail": _plain_text(
|
|
282
|
+
raw_bottom.get("detail"),
|
|
283
|
+
field="bottom_line.detail",
|
|
284
|
+
maximum=900,
|
|
285
|
+
),
|
|
286
|
+
"source_section_ids": _source_ids(
|
|
287
|
+
raw_bottom.get("source_section_ids"),
|
|
288
|
+
field="bottom_line.source_section_ids",
|
|
289
|
+
evidence_ids=evidence_ids,
|
|
290
|
+
allow_empty=not evidence_ids,
|
|
291
|
+
),
|
|
292
|
+
"confidence_note": _plain_text(
|
|
293
|
+
raw_bottom.get("confidence_note"),
|
|
294
|
+
field="bottom_line.confidence_note",
|
|
295
|
+
maximum=240,
|
|
296
|
+
),
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
raw_findings = value.get("findings")
|
|
300
|
+
if not isinstance(raw_findings, list) or len(raw_findings) > 5:
|
|
301
|
+
raise PreviewInputError(
|
|
302
|
+
"Preview synthesis findings must contain at most five items"
|
|
303
|
+
)
|
|
304
|
+
finding_fields = {
|
|
305
|
+
"title",
|
|
306
|
+
"finding",
|
|
307
|
+
"why_it_matters",
|
|
308
|
+
"source_section_ids",
|
|
309
|
+
"limitation",
|
|
310
|
+
}
|
|
311
|
+
findings: list[dict[str, Any]] = []
|
|
312
|
+
for index, raw in enumerate(raw_findings):
|
|
313
|
+
if not isinstance(raw, dict) or set(raw) != finding_fields:
|
|
314
|
+
raise PreviewInputError(
|
|
315
|
+
f"findings[{index}] does not match the required contract"
|
|
316
|
+
)
|
|
317
|
+
findings.append(
|
|
318
|
+
{
|
|
319
|
+
"title": _plain_text(
|
|
320
|
+
raw.get("title"),
|
|
321
|
+
field=f"findings[{index}].title",
|
|
322
|
+
maximum=100,
|
|
323
|
+
),
|
|
324
|
+
"finding": _plain_text(
|
|
325
|
+
raw.get("finding"),
|
|
326
|
+
field=f"findings[{index}].finding",
|
|
327
|
+
maximum=500,
|
|
328
|
+
),
|
|
329
|
+
"why_it_matters": _plain_text(
|
|
330
|
+
raw.get("why_it_matters"),
|
|
331
|
+
field=f"findings[{index}].why_it_matters",
|
|
332
|
+
maximum=400,
|
|
333
|
+
),
|
|
334
|
+
"source_section_ids": _source_ids(
|
|
335
|
+
raw.get("source_section_ids"),
|
|
336
|
+
field=f"findings[{index}].source_section_ids",
|
|
337
|
+
evidence_ids=evidence_ids,
|
|
338
|
+
allow_empty=False,
|
|
339
|
+
),
|
|
340
|
+
"limitation": _plain_text(
|
|
341
|
+
raw.get("limitation"),
|
|
342
|
+
field=f"findings[{index}].limitation",
|
|
343
|
+
maximum=240,
|
|
344
|
+
),
|
|
345
|
+
}
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
raw_implications = value.get("product_implications")
|
|
349
|
+
if not isinstance(raw_implications, list) or len(raw_implications) > 4:
|
|
350
|
+
raise PreviewInputError(
|
|
351
|
+
"Preview synthesis product_implications must contain at most four items"
|
|
352
|
+
)
|
|
353
|
+
implication_fields = {
|
|
354
|
+
"title",
|
|
355
|
+
"direction",
|
|
356
|
+
"rationale",
|
|
357
|
+
"source_section_ids",
|
|
358
|
+
"reconsider_if",
|
|
359
|
+
}
|
|
360
|
+
implications: list[dict[str, Any]] = []
|
|
361
|
+
for index, raw in enumerate(raw_implications):
|
|
362
|
+
if not isinstance(raw, dict) or set(raw) != implication_fields:
|
|
363
|
+
raise PreviewInputError(
|
|
364
|
+
f"product_implications[{index}] does not match the required contract"
|
|
365
|
+
)
|
|
366
|
+
implications.append(
|
|
367
|
+
{
|
|
368
|
+
"title": _plain_text(
|
|
369
|
+
raw.get("title"),
|
|
370
|
+
field=f"product_implications[{index}].title",
|
|
371
|
+
maximum=100,
|
|
372
|
+
),
|
|
373
|
+
"direction": _plain_text(
|
|
374
|
+
raw.get("direction"),
|
|
375
|
+
field=f"product_implications[{index}].direction",
|
|
376
|
+
maximum=360,
|
|
377
|
+
),
|
|
378
|
+
"rationale": _plain_text(
|
|
379
|
+
raw.get("rationale"),
|
|
380
|
+
field=f"product_implications[{index}].rationale",
|
|
381
|
+
maximum=500,
|
|
382
|
+
),
|
|
383
|
+
"source_section_ids": _source_ids(
|
|
384
|
+
raw.get("source_section_ids"),
|
|
385
|
+
field=f"product_implications[{index}].source_section_ids",
|
|
386
|
+
evidence_ids=evidence_ids,
|
|
387
|
+
allow_empty=False,
|
|
388
|
+
),
|
|
389
|
+
"reconsider_if": _plain_text(
|
|
390
|
+
raw.get("reconsider_if"),
|
|
391
|
+
field=f"product_implications[{index}].reconsider_if",
|
|
392
|
+
maximum=300,
|
|
393
|
+
),
|
|
394
|
+
}
|
|
395
|
+
)
|
|
396
|
+
|
|
397
|
+
raw_questions = value.get("open_questions")
|
|
398
|
+
if not isinstance(raw_questions, list) or not 1 <= len(raw_questions) <= 4:
|
|
399
|
+
raise PreviewInputError(
|
|
400
|
+
"Preview synthesis open_questions must contain 1-4 items"
|
|
401
|
+
)
|
|
402
|
+
questions: list[dict[str, str]] = []
|
|
403
|
+
for index, raw in enumerate(raw_questions):
|
|
404
|
+
if not isinstance(raw, dict) or set(raw) != {"question", "why_it_matters"}:
|
|
405
|
+
raise PreviewInputError(
|
|
406
|
+
f"open_questions[{index}] does not match the required contract"
|
|
407
|
+
)
|
|
408
|
+
questions.append(
|
|
409
|
+
{
|
|
410
|
+
"question": _plain_text(
|
|
411
|
+
raw.get("question"),
|
|
412
|
+
field=f"open_questions[{index}].question",
|
|
413
|
+
maximum=300,
|
|
414
|
+
),
|
|
415
|
+
"why_it_matters": _plain_text(
|
|
416
|
+
raw.get("why_it_matters"),
|
|
417
|
+
field=f"open_questions[{index}].why_it_matters",
|
|
418
|
+
maximum=300,
|
|
419
|
+
),
|
|
420
|
+
}
|
|
421
|
+
)
|
|
422
|
+
|
|
423
|
+
if not evidence_ids and (findings or implications):
|
|
424
|
+
raise PreviewInputError(
|
|
425
|
+
"Research with no usable evidence cannot produce findings or "
|
|
426
|
+
"product implications"
|
|
427
|
+
)
|
|
428
|
+
return {
|
|
429
|
+
"schema_version": 1,
|
|
430
|
+
"labels": labels,
|
|
431
|
+
"section_labels": section_labels,
|
|
432
|
+
"bottom_line": bottom_line,
|
|
433
|
+
"findings": findings,
|
|
434
|
+
"product_implications": implications,
|
|
435
|
+
"open_questions": questions,
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
def _evidence_line(
|
|
440
|
+
synthesis: dict[str, Any],
|
|
441
|
+
source_ids: Iterable[str],
|
|
442
|
+
trailing_note: str,
|
|
443
|
+
) -> str:
|
|
444
|
+
rendered_sources = ", ".join(
|
|
445
|
+
synthesis["section_labels"][item] for item in source_ids
|
|
446
|
+
)
|
|
447
|
+
return f"_{synthesis['labels']['based_on']}: {rendered_sources}. {trailing_note}_"
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
def _render_preview(
|
|
451
|
+
synthesis: dict[str, Any],
|
|
452
|
+
outcomes: dict[str, str],
|
|
453
|
+
*,
|
|
454
|
+
full_report_url: str,
|
|
455
|
+
) -> str:
|
|
456
|
+
labels = synthesis["labels"]
|
|
457
|
+
bottom = synthesis["bottom_line"]
|
|
458
|
+
bottom_evidence = (
|
|
459
|
+
_evidence_line(
|
|
460
|
+
synthesis,
|
|
461
|
+
bottom["source_section_ids"],
|
|
462
|
+
bottom["confidence_note"],
|
|
463
|
+
)
|
|
464
|
+
if bottom["source_section_ids"]
|
|
465
|
+
else f"_{bottom['confidence_note']}_"
|
|
466
|
+
)
|
|
467
|
+
blocks = [
|
|
468
|
+
f"# {PREVIEW_TITLE}",
|
|
469
|
+
f"## {labels['bottom_line']}\n\n**{bottom['summary']}**\n\n"
|
|
470
|
+
f"{bottom['detail']}\n\n{bottom_evidence}",
|
|
471
|
+
]
|
|
472
|
+
|
|
473
|
+
if synthesis["findings"]:
|
|
474
|
+
finding_blocks = [
|
|
475
|
+
f"### {item['title']}\n\n{item['finding']}\n\n"
|
|
476
|
+
f"{item['why_it_matters']}\n\n"
|
|
477
|
+
f"{_evidence_line(synthesis, item['source_section_ids'], item['limitation'])}"
|
|
478
|
+
for item in synthesis["findings"]
|
|
479
|
+
]
|
|
480
|
+
blocks.append(
|
|
481
|
+
f"## {labels['what_matters']}\n\n" + "\n\n".join(finding_blocks)
|
|
482
|
+
)
|
|
483
|
+
|
|
484
|
+
if synthesis["product_implications"]:
|
|
485
|
+
implication_blocks = [
|
|
486
|
+
f"### {item['title']}\n\n{item['direction']}\n\n"
|
|
487
|
+
f"{item['rationale']}\n\n"
|
|
488
|
+
f"{_evidence_line(synthesis, item['source_section_ids'], item['reconsider_if'])}"
|
|
489
|
+
for item in synthesis["product_implications"]
|
|
490
|
+
]
|
|
491
|
+
blocks.append(
|
|
492
|
+
f"## {labels['what_this_means']}\n\n"
|
|
493
|
+
+ "\n\n".join(implication_blocks)
|
|
494
|
+
)
|
|
495
|
+
|
|
496
|
+
question_bullets = "\n".join(
|
|
497
|
+
f"- **{item['question']}** {item['why_it_matters']}"
|
|
498
|
+
for item in synthesis["open_questions"]
|
|
499
|
+
)
|
|
500
|
+
blocks.append(f"## {labels['what_remains_open']}\n\n{question_bullets}")
|
|
501
|
+
|
|
502
|
+
coverage_lines = []
|
|
503
|
+
for status, label_key in (
|
|
504
|
+
("completed", "researched"),
|
|
505
|
+
("partial", "partial"),
|
|
506
|
+
("no_data", "no_data"),
|
|
507
|
+
("not_selected", "not_included"),
|
|
508
|
+
("could_not_complete", "could_not_complete"),
|
|
509
|
+
):
|
|
510
|
+
values = [
|
|
511
|
+
synthesis["section_labels"][option_id]
|
|
512
|
+
for option_id, outcome in outcomes.items()
|
|
513
|
+
if outcome == status
|
|
514
|
+
]
|
|
515
|
+
if values:
|
|
516
|
+
coverage_lines.append(f"- **{labels[label_key]}:** {', '.join(values)}")
|
|
517
|
+
coverage_lines.append(f"[{labels['full_report']}]({full_report_url})")
|
|
518
|
+
blocks.append(
|
|
519
|
+
f"## {labels['research_coverage']}\n\n" + "\n".join(coverage_lines)
|
|
520
|
+
)
|
|
521
|
+
return "\n\n".join(blocks) + "\n"
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
def _render_summary(synthesis: dict[str, Any]) -> str:
|
|
525
|
+
labels = synthesis["labels"]
|
|
526
|
+
parts = [
|
|
527
|
+
f"**{labels['bottom_line']}**\n\n{synthesis['bottom_line']['summary']}"
|
|
528
|
+
]
|
|
529
|
+
implications = synthesis["product_implications"][:2]
|
|
530
|
+
if implications:
|
|
531
|
+
bullets = "\n".join(f"- {item['direction']}" for item in implications)
|
|
532
|
+
parts.append(f"**{labels['recommended_direction']}**\n\n{bullets}")
|
|
533
|
+
parts.append(
|
|
534
|
+
f"**{labels['biggest_open_question']}**\n\n"
|
|
535
|
+
f"{synthesis['open_questions'][0]['question']}"
|
|
536
|
+
)
|
|
537
|
+
return "\n\n".join(parts) + "\n"
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
def _word_count(value: str) -> int:
|
|
541
|
+
cjk = _CJK.findall(value)
|
|
542
|
+
without_cjk = _CJK.sub(" ", value)
|
|
543
|
+
words = re.findall(r"\b[\w’'-]+\b", without_cjk, flags=re.UNICODE)
|
|
544
|
+
return len(words) + len(cjk)
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
def _visible_markdown_chars(value: str) -> int:
|
|
548
|
+
visible = re.sub(r"!?\[([^\]]*)\]\([^)]*\)", r"\1", value)
|
|
549
|
+
visible = re.sub(r"(?m)^\s{0,3}(?:#{1,6}|[-+*>])\s*", "", visible)
|
|
550
|
+
visible = visible.replace("**", "").replace("__", "").replace("`", "")
|
|
551
|
+
visible = re.sub(r"\s+", " ", visible).strip()
|
|
552
|
+
return len(visible)
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
def build_preview_documents(
|
|
556
|
+
context: dict[str, Any],
|
|
557
|
+
synthesis: dict[str, Any],
|
|
558
|
+
*,
|
|
559
|
+
full_report_url: str,
|
|
560
|
+
) -> tuple[str, str]:
|
|
561
|
+
outcomes = _validate_context(context)
|
|
562
|
+
known_ids = list(outcomes)
|
|
563
|
+
evidence_ids = {
|
|
564
|
+
section["id"] for section in context["sections"]
|
|
565
|
+
if _has_usable_evidence(section)
|
|
566
|
+
}
|
|
567
|
+
normalized = _validate_synthesis(
|
|
568
|
+
synthesis,
|
|
569
|
+
known_ids=known_ids,
|
|
570
|
+
evidence_ids=evidence_ids,
|
|
571
|
+
coverage_statuses=set(outcomes.values()),
|
|
572
|
+
)
|
|
573
|
+
preview = _render_preview(
|
|
574
|
+
normalized,
|
|
575
|
+
outcomes,
|
|
576
|
+
full_report_url=full_report_url,
|
|
577
|
+
)
|
|
578
|
+
summary = _render_summary(normalized)
|
|
579
|
+
if _word_count(preview) > MAX_PREVIEW_WORDS:
|
|
580
|
+
raise PreviewInputError(
|
|
581
|
+
f"Preview must be at most {MAX_PREVIEW_WORDS} words or CJK reading units"
|
|
582
|
+
)
|
|
583
|
+
if _visible_markdown_chars(summary) > MAX_SUMMARY_VISIBLE_CHARS:
|
|
584
|
+
raise PreviewInputError(
|
|
585
|
+
"Founder chat summary must be at most "
|
|
586
|
+
f"{MAX_SUMMARY_VISIBLE_CHARS} visible characters"
|
|
587
|
+
)
|
|
588
|
+
return preview, summary
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
def _has_usable_evidence(section: dict[str, Any]) -> bool:
|
|
592
|
+
if section["status"] == "completed":
|
|
593
|
+
return True
|
|
594
|
+
if section["status"] != "partial":
|
|
595
|
+
return False
|
|
596
|
+
# A failed source plus an empty successful source is still a partial run,
|
|
597
|
+
# but neither an empty nor an unanalyzed collection can support findings.
|
|
598
|
+
coverage = section.get("coverage", {})
|
|
599
|
+
collected = coverage.get("collected_count")
|
|
600
|
+
analyzed = coverage.get("analyzed_count")
|
|
601
|
+
return type(collected) is int and type(analyzed) is int and 0 < analyzed <= collected
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
def _atomic_write(path: Path, value: str, *, mode: int = 0o644) -> None:
|
|
605
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
606
|
+
temporary_path: Path | None = None
|
|
607
|
+
try:
|
|
608
|
+
with tempfile.NamedTemporaryFile(
|
|
609
|
+
mode="w",
|
|
610
|
+
encoding="utf-8",
|
|
611
|
+
newline="\n",
|
|
612
|
+
dir=path.parent,
|
|
613
|
+
prefix=f".{path.name}.",
|
|
614
|
+
suffix=".tmp",
|
|
615
|
+
delete=False,
|
|
616
|
+
) as handle:
|
|
617
|
+
handle.write(value)
|
|
618
|
+
handle.flush()
|
|
619
|
+
os.fsync(handle.fileno())
|
|
620
|
+
temporary_path = Path(handle.name)
|
|
621
|
+
os.chmod(temporary_path, mode)
|
|
622
|
+
os.replace(temporary_path, path)
|
|
623
|
+
temporary_path = None
|
|
624
|
+
finally:
|
|
625
|
+
if temporary_path is not None:
|
|
626
|
+
temporary_path.unlink(missing_ok=True)
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
def _ensure_full_report(path: Path) -> None:
|
|
630
|
+
if path.exists():
|
|
631
|
+
return
|
|
632
|
+
_atomic_write(path, f"# {FULL_REPORT_TITLE}\n")
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
def write_preview_documents(
|
|
636
|
+
*,
|
|
637
|
+
context_path: Path,
|
|
638
|
+
synthesis_path: Path,
|
|
639
|
+
full_report_path: Path,
|
|
640
|
+
preview_path: Path,
|
|
641
|
+
summary_path: Path,
|
|
642
|
+
receipt_path: Path,
|
|
643
|
+
local_report_link: str = "full-report.md",
|
|
644
|
+
) -> tuple[str, str, dict[str, Any]]:
|
|
645
|
+
context = _read_json_object(context_path, label="Preview context")
|
|
646
|
+
synthesis = _read_json_object(synthesis_path, label="Preview synthesis")
|
|
647
|
+
parsed = urlsplit(local_report_link)
|
|
648
|
+
if (not local_report_link or any(c.isspace() or c in "()\\<>" for c in local_report_link)
|
|
649
|
+
or parsed.username or parsed.password or local_report_link.startswith(("/", "."))
|
|
650
|
+
or ".." in parsed.path.split("/")
|
|
651
|
+
or (parsed.scheme and (parsed.scheme not in {"http", "https"} or not parsed.netloc))
|
|
652
|
+
or (not parsed.scheme and parsed.netloc)):
|
|
653
|
+
raise PreviewInputError("Use a safe relative report link or HTTP(S) URL")
|
|
654
|
+
full_report_url = local_report_link
|
|
655
|
+
_ensure_full_report(full_report_path)
|
|
656
|
+
preview, summary = build_preview_documents(
|
|
657
|
+
context,
|
|
658
|
+
synthesis,
|
|
659
|
+
full_report_url=full_report_url,
|
|
660
|
+
)
|
|
661
|
+
_atomic_write(preview_path, preview)
|
|
662
|
+
_atomic_write(summary_path, summary)
|
|
663
|
+
receipt = {
|
|
664
|
+
"schema_version": 1,
|
|
665
|
+
"context_sha256": _file_sha256(context_path),
|
|
666
|
+
"synthesis_sha256": _file_sha256(synthesis_path),
|
|
667
|
+
"full_report_sha256": _file_sha256(full_report_path),
|
|
668
|
+
"preview_sha256": _file_sha256(preview_path),
|
|
669
|
+
"summary_sha256": _file_sha256(summary_path),
|
|
670
|
+
"full_report_url": full_report_url,
|
|
671
|
+
"publication_mode": "local",
|
|
672
|
+
}
|
|
673
|
+
_atomic_write(
|
|
674
|
+
receipt_path,
|
|
675
|
+
json.dumps(receipt, ensure_ascii=False, indent=2, sort_keys=True) + "\n",
|
|
676
|
+
)
|
|
677
|
+
return preview, summary, receipt
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
def _parser() -> argparse.ArgumentParser:
|
|
681
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
682
|
+
parser.add_argument("--context", type=Path, default=DEFAULT_CONTEXT)
|
|
683
|
+
parser.add_argument("--input", type=Path, default=DEFAULT_SYNTHESIS)
|
|
684
|
+
parser.add_argument("--full-report", type=Path, default=DEFAULT_FULL_REPORT)
|
|
685
|
+
parser.add_argument("--preview", type=Path, default=DEFAULT_PREVIEW)
|
|
686
|
+
parser.add_argument("--summary", type=Path, default=DEFAULT_SUMMARY)
|
|
687
|
+
parser.add_argument("--receipt", type=Path, default=DEFAULT_RECEIPT)
|
|
688
|
+
parser.add_argument("--local-report-link", default="full-report.md", help="Report link (default: full-report.md); no instance required")
|
|
689
|
+
return parser
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
def main() -> int:
|
|
693
|
+
args = _parser().parse_args()
|
|
694
|
+
try:
|
|
695
|
+
write_preview_documents(
|
|
696
|
+
context_path=args.context,
|
|
697
|
+
synthesis_path=args.input,
|
|
698
|
+
full_report_path=args.full_report,
|
|
699
|
+
preview_path=args.preview,
|
|
700
|
+
summary_path=args.summary,
|
|
701
|
+
receipt_path=args.receipt,
|
|
702
|
+
local_report_link=args.local_report_link,
|
|
703
|
+
)
|
|
704
|
+
except (OSError, PreviewInputError, RuntimeError, UnicodeError) as exc:
|
|
705
|
+
raise SystemExit(str(exc)) from exc
|
|
706
|
+
return 0
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
if __name__ == "__main__":
|
|
710
|
+
raise SystemExit(main())
|