@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,190 @@
|
|
|
1
|
+
"""Private, portable input and human-action contracts for Lifecycle Capture."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
from datetime import date, timedelta
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any, Callable
|
|
8
|
+
from urllib.parse import urlsplit
|
|
9
|
+
|
|
10
|
+
KINDS = ("newsletter", "account", "trial", "waitlist", "lead_form")
|
|
11
|
+
ENTRY_TYPES = ("details", "materials", "webinar", "quiz", "waitlist", "account", "trial", "newsletter")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def read_object(path: Path) -> dict[str, Any]:
|
|
15
|
+
if not path.is_file():
|
|
16
|
+
return {}
|
|
17
|
+
try:
|
|
18
|
+
value = json.loads(path.read_text(encoding="utf-8"))
|
|
19
|
+
except (OSError, ValueError) as exc:
|
|
20
|
+
raise ValueError(f"{path.name} must contain valid JSON") from exc
|
|
21
|
+
if not isinstance(value, dict):
|
|
22
|
+
raise ValueError(f"{path.name} must contain an object")
|
|
23
|
+
return value
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _url(value: Any, label: str) -> str:
|
|
27
|
+
if not isinstance(value, str) or any(c.isspace() for c in value):
|
|
28
|
+
raise ValueError(f"{label} needs an https URL")
|
|
29
|
+
parsed = urlsplit(value)
|
|
30
|
+
if parsed.scheme != "https" or not parsed.hostname or parsed.username or parsed.password:
|
|
31
|
+
raise ValueError(f"{label} needs an https URL without credentials")
|
|
32
|
+
return value
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def validate_entry(value: Any, domain: str, normalize: Callable[[str], str]) -> dict[str, Any] | None:
|
|
36
|
+
if value is None:
|
|
37
|
+
return None
|
|
38
|
+
if not isinstance(value, dict):
|
|
39
|
+
raise ValueError(f"{domain}: selected/fallback must be an object or null")
|
|
40
|
+
out = dict(value)
|
|
41
|
+
for key in ("id", "comparable_offer", "reason", "stop_condition"):
|
|
42
|
+
if not isinstance(out.get(key), str) or not out[key].strip():
|
|
43
|
+
raise ValueError(f"{domain}: entry needs {key}")
|
|
44
|
+
source = _url(out.get("source_url"), f"{domain} source_url")
|
|
45
|
+
destination = _url(out.get("entry_url"), f"{domain} entry_url")
|
|
46
|
+
if normalize(urlsplit(source).hostname or "") != domain:
|
|
47
|
+
raise ValueError(f"{domain}: source_url must originate on the competitor's domain")
|
|
48
|
+
if normalize(urlsplit(destination).hostname or "") != domain:
|
|
49
|
+
if not isinstance(out.get("handoff_evidence"), str) or not out["handoff_evidence"].strip():
|
|
50
|
+
raise ValueError(f"{domain}: external form needs handoff_evidence for the linked or embedded destination")
|
|
51
|
+
if out.get("kind") not in KINDS or out.get("entry_type") not in ENTRY_TYPES:
|
|
52
|
+
raise ValueError(f"{domain}: invalid kind or entry_type")
|
|
53
|
+
for key in ("needs_phone", "needs_card"):
|
|
54
|
+
if key not in out or (out[key] is not None and not isinstance(out[key], bool)):
|
|
55
|
+
raise ValueError(f"{domain}: {key} must be true, false or null (unknown)")
|
|
56
|
+
fields = out.get("fields")
|
|
57
|
+
if not isinstance(fields, list) or any(not isinstance(f, dict) or not isinstance(f.get("name"), str)
|
|
58
|
+
or not isinstance(f.get("required"), bool) for f in fields):
|
|
59
|
+
raise ValueError(f"{domain}: fields needs named fields with boolean required")
|
|
60
|
+
instructions = out.get("instructions")
|
|
61
|
+
if not isinstance(instructions, list) or not instructions or any(not isinstance(i, str) or not i.strip() for i in instructions):
|
|
62
|
+
raise ValueError(f"{domain}: instructions must be a nonempty list")
|
|
63
|
+
evidence = out.get("evidence")
|
|
64
|
+
if not isinstance(evidence, list) or not evidence:
|
|
65
|
+
raise ValueError(f"{domain}: entry needs source evidence")
|
|
66
|
+
for proof in evidence:
|
|
67
|
+
if not isinstance(proof, dict) or not isinstance(proof.get("detail"), str) or not proof["detail"].strip():
|
|
68
|
+
raise ValueError(f"{domain}: evidence needs a detail")
|
|
69
|
+
_url(proof.get("url"), f"{domain} evidence URL")
|
|
70
|
+
try:
|
|
71
|
+
observed = date.fromisoformat(proof["observed_on"])
|
|
72
|
+
except (KeyError, TypeError, ValueError) as exc:
|
|
73
|
+
raise ValueError(f"{domain}: evidence needs observed_on YYYY-MM-DD") from exc
|
|
74
|
+
if observed > date.today():
|
|
75
|
+
raise ValueError(f"{domain}: evidence cannot be observed in the future")
|
|
76
|
+
return out
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def discovery(path: Path, domains: list[str], normalize: Callable[[str], str]) -> dict[str, dict[str, Any]]:
|
|
80
|
+
raw = read_object(path)
|
|
81
|
+
if not raw:
|
|
82
|
+
return {}
|
|
83
|
+
if raw.get("schema_version") != 1 or not isinstance(raw.get("competitors"), list):
|
|
84
|
+
raise ValueError("entry-points.json needs schema_version 1 and competitors")
|
|
85
|
+
result = {}
|
|
86
|
+
for value in raw["competitors"]:
|
|
87
|
+
if not isinstance(value, dict):
|
|
88
|
+
raise ValueError("entry-point competitor must be an object")
|
|
89
|
+
domain = normalize(str(value.get("domain") or ""))
|
|
90
|
+
if domain not in domains:
|
|
91
|
+
continue
|
|
92
|
+
if domain in result:
|
|
93
|
+
raise ValueError(f"duplicate entry-point competitor {domain}")
|
|
94
|
+
selected = validate_entry(value.get("selected"), domain, normalize)
|
|
95
|
+
fallback = validate_entry(value.get("fallback"), domain, normalize)
|
|
96
|
+
reason = value.get("skip_reason")
|
|
97
|
+
if selected is None and (not isinstance(reason, str) or not reason.strip()):
|
|
98
|
+
raise ValueError(f"{domain}: no selected entry needs a skip_reason")
|
|
99
|
+
if selected and fallback and selected["id"] == fallback["id"]:
|
|
100
|
+
raise ValueError(f"{domain}: selected and fallback need different ids")
|
|
101
|
+
result[domain] = {"selected": selected, "fallback": fallback, "skip_reason": reason,
|
|
102
|
+
"discovery_status": "reviewed"}
|
|
103
|
+
return result
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def subscription_entry(item: dict[str, Any], planned: dict[str, Any]) -> dict[str, Any]:
|
|
107
|
+
"""Bind a real subscription to the reviewed selected/fallback entry."""
|
|
108
|
+
candidates = [e for e in (planned.get("selected"), planned.get("fallback")) if e]
|
|
109
|
+
if not candidates: # Only pre-existing, already active legacy captures use this path.
|
|
110
|
+
if planned.get("legacy"):
|
|
111
|
+
return {}
|
|
112
|
+
raise ValueError(f"{item['domain']}: subscription needs a reviewed entry point")
|
|
113
|
+
matches = [e for e in candidates if e["entry_url"] == item.get("entry_url") and e["kind"] == item.get("kind")
|
|
114
|
+
and (not item.get("entry_id") or item["entry_id"] == e["id"])]
|
|
115
|
+
if len(matches) != 1:
|
|
116
|
+
raise ValueError(f"{item['domain']}: entry_url/kind must match the selected entry or recorded fallback")
|
|
117
|
+
entry = matches[0]
|
|
118
|
+
if entry["needs_phone"] is True or entry["needs_card"] is True:
|
|
119
|
+
raise ValueError(f"{item['domain']}: selected entry requires a phone or card")
|
|
120
|
+
if (entry["needs_phone"] is None or entry["needs_card"] is None) and item.get("requirements_verified") is not True:
|
|
121
|
+
raise ValueError(f"{item['domain']}: the assigned human must verify unknown phone/card requirements")
|
|
122
|
+
if planned.get("fallback") and entry["id"] == planned["fallback"]["id"] and not str(item.get("fallback_reason") or "").strip():
|
|
123
|
+
raise ValueError(f"{item['domain']}: fallback use needs fallback_reason")
|
|
124
|
+
return {"entry_id": entry["id"], "entry_type": entry["entry_type"], "source_url": entry["source_url"],
|
|
125
|
+
"fallback_reason": item.get("fallback_reason"), "requirements_verified": item.get("requirements_verified")}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def render_signups(plan: dict[str, Any]) -> str:
|
|
129
|
+
lines = ["# Lifecycle Capture: human signup actions", "", "Use only the planned address. Leave optional phone fields empty; stop before a required phone, a card, payment or CAPTCHA bypass.",
|
|
130
|
+
"Only the assigned human with verified access to the planned aliases and mailbox may register, confirm double opt-in and unsubscribe; report each result and its actual date in the chat. If nobody has that access, leave actions pending. Never reply to sales representatives.",
|
|
131
|
+
"", "This private list contains mailbox aliases. Keep it outside published research and decision packs.", ""]
|
|
132
|
+
for c in plan["competitors"]:
|
|
133
|
+
lines += [f"## {c['domain']}", "", f"Address: `{c['alias']}`", ""]
|
|
134
|
+
if c.get("discovery_status") != "reviewed" and not c.get("legacy"):
|
|
135
|
+
lines += ["Entry discovery is pending; there is no verified sign-up recommendation yet.", ""]
|
|
136
|
+
continue
|
|
137
|
+
if not c.get("selected"):
|
|
138
|
+
lines += ["Skip: " + str(c.get("skip_reason") or "no reviewed entry"), ""]
|
|
139
|
+
for label, entry in (("Selected", c.get("selected")), ("Fallback", c.get("fallback"))):
|
|
140
|
+
if not entry:
|
|
141
|
+
continue
|
|
142
|
+
phone = "unknown — verify before submitting" if entry["needs_phone"] is None else "required — unavailable" if entry["needs_phone"] else "not required"
|
|
143
|
+
card = "unknown — verify before submitting" if entry["needs_card"] is None else "required — unavailable" if entry["needs_card"] else "not required"
|
|
144
|
+
lines += [f"**{label}: {entry['entry_type']} ({entry['id']})**", "", f"Source: {entry['source_url']}",
|
|
145
|
+
f"Form: {entry['entry_url']}", f"Phone: {phone}. Card: {card}.",
|
|
146
|
+
"Fields: " + ", ".join(f["name"] + (" (required)" if f["required"] else " (optional)") for f in entry["fields"]),
|
|
147
|
+
"Reason: " + entry["reason"], "", *[f"- {step}" for step in entry["instructions"]],
|
|
148
|
+
"", "Stop condition: " + entry["stop_condition"], ""]
|
|
149
|
+
return "\n".join(lines)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def operator_actions(plan: dict[str, Any], subscriptions: list[dict[str, Any]], skipped: list[dict[str, Any]],
|
|
153
|
+
harvested_on: str | None, previous: dict[str, Any], harvested_domains: list[str] | None = None) -> dict[str, Any]:
|
|
154
|
+
if previous.get("capture_id") != plan["capture_id"]:
|
|
155
|
+
previous = {}
|
|
156
|
+
old = {a["id"]: a for a in previous.get("actions", []) if isinstance(a, dict) and "id" in a}
|
|
157
|
+
old_harvests = {a["id"]: a for a in previous.get("harvests", []) if isinstance(a, dict) and "id" in a}
|
|
158
|
+
by_domain = {s["domain"]: s for s in subscriptions}
|
|
159
|
+
skipped_domains = {s["domain"] for s in skipped}
|
|
160
|
+
actions, harvests = [], []
|
|
161
|
+
for c in plan["competitors"]:
|
|
162
|
+
d, s = c["domain"], by_domain.get(c["domain"])
|
|
163
|
+
if not s and c.get("discovery_status") != "reviewed" and not c.get("legacy"):
|
|
164
|
+
continue
|
|
165
|
+
discovery_skip = c.get("discovery_status") == "reviewed" and not c.get("selected") and bool(c.get("skip_reason"))
|
|
166
|
+
signup_id = d + ":signup"
|
|
167
|
+
actions.append({"id": signup_id, "domain": d, "kind": "signup",
|
|
168
|
+
"status": "completed" if s else "skipped" if d in skipped_domains or discovery_skip else "pending",
|
|
169
|
+
"due_on": old.get(signup_id, {}).get("due_on") or (date.today() + timedelta(days=1)).isoformat()})
|
|
170
|
+
if not s:
|
|
171
|
+
continue
|
|
172
|
+
subscribed = date.fromisoformat(s["subscribed_on"])
|
|
173
|
+
full_due = (subscribed + timedelta(days=14)).isoformat()
|
|
174
|
+
if s.get("confirmed") is not None:
|
|
175
|
+
actions.append({"id": d + ":confirm", "domain": d, "kind": "confirm",
|
|
176
|
+
"status": "completed" if s["confirmed"] else "skipped" if s.get("unsubscribed_on") else "pending",
|
|
177
|
+
"due_on": old.get(d + ":confirm", {}).get("due_on") or date.today().isoformat()})
|
|
178
|
+
actions.append({"id": d + ":unsubscribe", "domain": d, "kind": "unsubscribe",
|
|
179
|
+
"status": "completed" if s.get("unsubscribed_on") else "pending", "due_on": full_due,
|
|
180
|
+
"blocked_by": d + ":full"})
|
|
181
|
+
for kind, days in (("early", 3), ("full", 14)):
|
|
182
|
+
due = (subscribed + timedelta(days=days)).isoformat()
|
|
183
|
+
old_harvest = old_harvests.get(d + ":" + kind, {})
|
|
184
|
+
ended_early = s.get("unsubscribed_on") and s["unsubscribed_on"] < due
|
|
185
|
+
completed = (old_harvest.get("due_on") == due and old_harvest.get("status") == "completed") or (
|
|
186
|
+
harvested_on and harvested_on >= due and d in (harvested_domains or []))
|
|
187
|
+
status = "skipped" if ended_early else "completed" if completed else "pending"
|
|
188
|
+
harvests.append({"id": d + ":" + kind, "domain": d, "kind": kind, "due_on": due, "status": status})
|
|
189
|
+
return {"schema_version": 1, "section_id": "lifecycle_capture", "capture_id": plan["capture_id"],
|
|
190
|
+
"product_domain": plan.get("product_domain", ""), "actions": actions, "harvests": harvests}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Verify published research files; the caller owns the product's Git workflow."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import importlib.util
|
|
6
|
+
import sys
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Sequence
|
|
10
|
+
|
|
11
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
12
|
+
from egbe_artifacts import artifact_path
|
|
13
|
+
|
|
14
|
+
REPORT_PATH = Path(artifact_path("egbe-docs/research/market/full-report.md"))
|
|
15
|
+
DEFAULT_COMMIT_MESSAGE = "research: update market report"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ReportPersistenceError(RuntimeError):
|
|
19
|
+
"""A publication is missing or outside this research's public artifacts."""
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True)
|
|
23
|
+
class PersistenceResult:
|
|
24
|
+
commit_sha: str = ""
|
|
25
|
+
committed: bool = False
|
|
26
|
+
publication_mode: str = "local"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _artifact_io():
|
|
30
|
+
spec = importlib.util.spec_from_file_location("pmr_artifact_io", Path(__file__).with_name("research-artifact-io.py"))
|
|
31
|
+
module = importlib.util.module_from_spec(spec)
|
|
32
|
+
spec.loader.exec_module(module)
|
|
33
|
+
return module
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def persist_research_report(workspace: Path, *, commit_message: str = DEFAULT_COMMIT_MESSAGE,
|
|
37
|
+
extra_paths: Sequence[Path] = ()) -> PersistenceResult:
|
|
38
|
+
workspace = workspace.resolve()
|
|
39
|
+
lock = workspace / REPORT_PATH.parent / ".local" / "publication.lock"
|
|
40
|
+
if not lock.resolve().is_relative_to(workspace):
|
|
41
|
+
raise ReportPersistenceError("Research directory must stay inside the project")
|
|
42
|
+
with _artifact_io().publication_lock(workspace / REPORT_PATH):
|
|
43
|
+
return _persist_research_report(workspace, commit_message=commit_message, extra_paths=extra_paths)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _persist_research_report(workspace: Path, *, commit_message: str = DEFAULT_COMMIT_MESSAGE,
|
|
47
|
+
extra_paths: Sequence[Path] = ()) -> PersistenceResult:
|
|
48
|
+
# Preserve the receipt signature, not the old nested-repo workflow.
|
|
49
|
+
# Publication never commits/pushes unrelated product work.
|
|
50
|
+
workspace = workspace.resolve()
|
|
51
|
+
public_root = (workspace / REPORT_PATH.parent).resolve()
|
|
52
|
+
if not public_root.is_relative_to(workspace):
|
|
53
|
+
raise ReportPersistenceError("Research directory must stay inside the project")
|
|
54
|
+
for relative in (REPORT_PATH, *extra_paths):
|
|
55
|
+
relative = Path(relative)
|
|
56
|
+
target = (workspace / relative).resolve()
|
|
57
|
+
if (relative.is_absolute() or any(part in ("..", ".local", "work") for part in relative.parts)
|
|
58
|
+
or not target.is_relative_to(public_root)
|
|
59
|
+
or any(part in (".local", "work") for part in target.relative_to(public_root).parts)):
|
|
60
|
+
raise ReportPersistenceError(f"Not a public artifact of this research: {relative}")
|
|
61
|
+
if not target.is_file():
|
|
62
|
+
raise ReportPersistenceError(f"Research artifact does not exist: {relative}")
|
|
63
|
+
return PersistenceResult()
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"""Small filesystem boundary shared by research publishers (stdlib only).
|
|
2
|
+
|
|
3
|
+
python3 research-artifact-io.py --compact WS
|
|
4
|
+
|
|
5
|
+
compresses the provider caches of the sections whose readers accept it and
|
|
6
|
+
hard-links byte-identical content-addressed images; replays read both forms.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import sys as _artifact_sys
|
|
11
|
+
from pathlib import Path as _ArtifactPath
|
|
12
|
+
_artifact_sys.path.insert(0, str(_ArtifactPath(__file__).resolve().parent))
|
|
13
|
+
from egbe_artifacts import artifact_path as _artifact_path
|
|
14
|
+
|
|
15
|
+
import argparse
|
|
16
|
+
import fcntl
|
|
17
|
+
import gzip
|
|
18
|
+
import hashlib
|
|
19
|
+
import json
|
|
20
|
+
import os
|
|
21
|
+
import re
|
|
22
|
+
import shutil
|
|
23
|
+
import sys
|
|
24
|
+
import tempfile
|
|
25
|
+
import time
|
|
26
|
+
import zlib
|
|
27
|
+
from contextlib import contextmanager
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def write_atomic(path: Path, content: str) -> None:
|
|
32
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
33
|
+
name = None
|
|
34
|
+
try:
|
|
35
|
+
with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8", dir=path.parent,
|
|
36
|
+
prefix=f".{path.name}.", delete=False) as handle:
|
|
37
|
+
name = handle.name
|
|
38
|
+
handle.write(content)
|
|
39
|
+
handle.flush()
|
|
40
|
+
os.fsync(handle.fileno())
|
|
41
|
+
os.replace(name, path)
|
|
42
|
+
name = None
|
|
43
|
+
finally:
|
|
44
|
+
if name:
|
|
45
|
+
Path(name).unlink(missing_ok=True)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def write_json(path: Path, value: dict) -> None:
|
|
49
|
+
write_atomic(path, json.dumps(value, ensure_ascii=False, indent=2, sort_keys=True) + "\n")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def sha256(path: Path) -> str:
|
|
53
|
+
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def context_path(section_id: str) -> Path:
|
|
57
|
+
if not re.fullmatch(r"[a-z0-9_]+", section_id):
|
|
58
|
+
raise ValueError("Invalid research section id")
|
|
59
|
+
return Path(_artifact_path("egbe-docs/research/market/work")) / section_id / "input-context.json"
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def resolve_context(workspace: Path, *, context_file=None, context=None) -> dict:
|
|
63
|
+
"""Read only explicitly supplied context. Measurements may need none."""
|
|
64
|
+
if context_file is not None and context is not None:
|
|
65
|
+
raise ValueError("Supply context text or a context file, not both")
|
|
66
|
+
sources = {}
|
|
67
|
+
text = "" if context is None else str(context).strip()
|
|
68
|
+
if context_file is not None:
|
|
69
|
+
path = Path(context_file)
|
|
70
|
+
path = path if path.is_absolute() else workspace / path
|
|
71
|
+
raw = path.read_bytes()
|
|
72
|
+
text = raw.decode("utf-8").strip()
|
|
73
|
+
if not text:
|
|
74
|
+
raise ValueError("The supplied research context is empty")
|
|
75
|
+
resolved = path.resolve()
|
|
76
|
+
source = resolved.relative_to(workspace.resolve()).as_posix() if resolved.is_relative_to(workspace.resolve()) else str(resolved)
|
|
77
|
+
sources[source] = hashlib.sha256(raw).hexdigest()
|
|
78
|
+
return {"schema_version": 1, "text": text, "sources": sources}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def bind_context(workspace: Path, section_id: str, *, context_file=None, context=None) -> dict:
|
|
82
|
+
"""Freeze selected context before collection; never discover product files."""
|
|
83
|
+
with file_lock((workspace / context_path(section_id)).with_name(".context.lock"), timeout=1):
|
|
84
|
+
return _bind_context(workspace, section_id, context_file=context_file, context=context)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _bind_context(workspace: Path, section_id: str, *, context_file=None, context=None) -> dict:
|
|
88
|
+
path = workspace / context_path(section_id)
|
|
89
|
+
previous = json.loads(path.read_text()) if path.exists() else None
|
|
90
|
+
receipt_path = path.with_name("request.json")
|
|
91
|
+
if receipt_path.exists():
|
|
92
|
+
receipt = json.loads(receipt_path.read_text())
|
|
93
|
+
binding = receipt.get("research_context")
|
|
94
|
+
provenance_path = path.with_name("input-provenance.json")
|
|
95
|
+
if binding is None and provenance_path.exists():
|
|
96
|
+
binding = json.loads(provenance_path.read_text()).get("research_context")
|
|
97
|
+
if previous is None or binding != context_binding(workspace, section_id):
|
|
98
|
+
raise ValueError("Saved research input binding is missing or damaged; preserve evidence and inspect before resuming")
|
|
99
|
+
if previous is not None and context_file is None and context is None:
|
|
100
|
+
value = previous # continuation/clone uses the recorded input, not a fresh search
|
|
101
|
+
else:
|
|
102
|
+
value = resolve_context(workspace, context_file=context_file, context=context)
|
|
103
|
+
if not isinstance(value, dict) or value.get("schema_version") != 1 or not isinstance(value.get("text"), str) or not isinstance(value.get("sources"), dict):
|
|
104
|
+
raise ValueError("Invalid saved research context; retain it and inspect before continuing")
|
|
105
|
+
if previous is not None and previous != value:
|
|
106
|
+
raise ValueError("Research context changed; retain this study and use a new research ID for new work")
|
|
107
|
+
if previous is None:
|
|
108
|
+
write_json(path, value)
|
|
109
|
+
return value
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def context_binding(workspace: Path, section_id: str) -> dict:
|
|
113
|
+
relative = context_path(section_id)
|
|
114
|
+
return {"path": relative.as_posix(), "sha256": sha256(workspace / relative)}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def context_text(workspace: Path, section_id: str) -> str:
|
|
118
|
+
value = json.loads((workspace / context_path(section_id)).read_text())
|
|
119
|
+
if value.get("schema_version") != 1 or not isinstance(value.get("text"), str):
|
|
120
|
+
raise ValueError("Invalid research context snapshot")
|
|
121
|
+
return value["text"]
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def verify_context(workspace: Path, section_id: str, binding) -> dict:
|
|
125
|
+
if binding != context_binding(workspace, section_id):
|
|
126
|
+
raise ValueError("Research input snapshot does not match its receipt")
|
|
127
|
+
value = json.loads((workspace / context_path(section_id)).read_text())
|
|
128
|
+
if value.get("schema_version") != 1 or not isinstance(value.get("text"), str) or not isinstance(value.get("sources"), dict):
|
|
129
|
+
raise ValueError("Invalid research context snapshot")
|
|
130
|
+
for source, digest in value["sources"].items():
|
|
131
|
+
path = Path(source)
|
|
132
|
+
path = path if path.is_absolute() else workspace / path
|
|
133
|
+
if path.is_file() and sha256(path) != digest:
|
|
134
|
+
raise ValueError("Declared research input changed; saved evidence remains intact, review its applicability")
|
|
135
|
+
return value
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
@contextmanager
|
|
139
|
+
def file_lock(path: Path, timeout: float = 60):
|
|
140
|
+
"""A bounded process lock; callers must not nest the same lock."""
|
|
141
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
142
|
+
with path.open("a") as handle:
|
|
143
|
+
deadline = time.monotonic() + timeout
|
|
144
|
+
while True:
|
|
145
|
+
try:
|
|
146
|
+
fcntl.flock(handle, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
147
|
+
break
|
|
148
|
+
except BlockingIOError:
|
|
149
|
+
if time.monotonic() >= deadline:
|
|
150
|
+
raise TimeoutError(f"Research publication busy: {path}; retry without recollecting data")
|
|
151
|
+
time.sleep(0.05)
|
|
152
|
+
try:
|
|
153
|
+
yield
|
|
154
|
+
finally:
|
|
155
|
+
fcntl.flock(handle, fcntl.LOCK_UN)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def publication_lock(report: Path):
|
|
159
|
+
return file_lock(report.parent / ".local" / "publication.lock")
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
@contextmanager
|
|
163
|
+
def section_attempt(workspace: Path, section_id: str, *, context_file=None):
|
|
164
|
+
"""Invalidate old completion before work; the runner owns successful publication."""
|
|
165
|
+
root = workspace / _artifact_path("egbe-docs/research/market/work") / section_id
|
|
166
|
+
# A competing invocation must not invalidate the active runner's receipt.
|
|
167
|
+
with file_lock(root / ".run.lock", timeout=1):
|
|
168
|
+
bind_context(workspace, section_id, context_file=context_file)
|
|
169
|
+
state = {"schema_version": 1, "section_id": section_id, "status": "pending", "error": None,
|
|
170
|
+
"research_context": context_binding(workspace, section_id)}
|
|
171
|
+
write_json(root / "request.json", state)
|
|
172
|
+
try:
|
|
173
|
+
yield
|
|
174
|
+
except Exception:
|
|
175
|
+
# Keep cached responses/results for recovery. Never persist upstream
|
|
176
|
+
# exception text, which may contain request details or credentials.
|
|
177
|
+
write_json(root / "request.json", {
|
|
178
|
+
**state, "status": "failed",
|
|
179
|
+
"error": "Current attempt failed; retained files do not prove completion. Retry using the cache.",
|
|
180
|
+
})
|
|
181
|
+
raise
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
# Provider caches: an entry is addressed by its logical `<digest>.json` path
|
|
185
|
+
# and stored as `<digest>.json.gz` (an older plain file is read as well).
|
|
186
|
+
COMPRESSED_CACHE_SECTIONS = ("channel_footprint", "creative_patterns", "competitor_set")
|
|
187
|
+
_DIGEST_JSON = re.compile(r"[0-9a-f]{64}\.json")
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def cache_entry_path(path: Path) -> Path | None:
|
|
191
|
+
packed = path.with_name(path.name + ".gz")
|
|
192
|
+
return path if path.is_file() else packed if packed.is_file() else None
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def read_cache_entry(path: Path):
|
|
196
|
+
"""The entry, or None when absent; corrupt bytes raise (OSError/ValueError/EOFError)."""
|
|
197
|
+
actual = cache_entry_path(path)
|
|
198
|
+
if actual is None:
|
|
199
|
+
return None
|
|
200
|
+
data = actual.read_bytes()
|
|
201
|
+
try:
|
|
202
|
+
return json.loads(gzip.decompress(data) if actual != path else data)
|
|
203
|
+
except zlib.error as exc:
|
|
204
|
+
raise gzip.BadGzipFile("Invalid compressed cache entry") from exc
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def write_cache_entry(path: Path, entry) -> None:
|
|
208
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
209
|
+
packed = path.with_name(path.name + ".gz")
|
|
210
|
+
tmp = packed.with_name(packed.name + ".tmp")
|
|
211
|
+
tmp.write_bytes(gzip.compress(json.dumps(entry).encode("utf-8"), mtime=0))
|
|
212
|
+
tmp.replace(packed)
|
|
213
|
+
path.unlink(missing_ok=True)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def drop_cache_entry(path: Path) -> None:
|
|
217
|
+
path.unlink(missing_ok=True)
|
|
218
|
+
path.with_name(path.name + ".gz").unlink(missing_ok=True)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def cache_entries(directory: Path) -> list[Path]:
|
|
222
|
+
"""Logical entry paths under `directory`, in their former sorted order."""
|
|
223
|
+
found = {p for p in directory.rglob("*.json")} | {p.with_name(p.name[:-3]) for p in directory.rglob("*.json.gz")}
|
|
224
|
+
return sorted(found)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def link_or_copy(source: Path, target: Path) -> None:
|
|
228
|
+
"""Exact bytes stored once: a hard link on the same filesystem, a copy
|
|
229
|
+
otherwise; the target is replaced atomically."""
|
|
230
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
231
|
+
if target.exists() and os.path.samefile(source, target):
|
|
232
|
+
return
|
|
233
|
+
fd, tmp = tempfile.mkstemp(dir=target.parent, prefix=f".{target.name}.")
|
|
234
|
+
os.close(fd)
|
|
235
|
+
os.unlink(tmp)
|
|
236
|
+
try:
|
|
237
|
+
try:
|
|
238
|
+
os.link(source, tmp)
|
|
239
|
+
except OSError:
|
|
240
|
+
shutil.copyfile(source, tmp)
|
|
241
|
+
os.replace(tmp, target)
|
|
242
|
+
except BaseException:
|
|
243
|
+
Path(tmp).unlink(missing_ok=True)
|
|
244
|
+
raise
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def compact(workspace: Path) -> dict:
|
|
248
|
+
"""Compress cache entries in place (same JSON, gzip) and link identical
|
|
249
|
+
images named by their SHA-256; nothing is re-fetched or re-classified."""
|
|
250
|
+
runtime, report = workspace / _artifact_path("egbe-docs/research/market/work"), {"entries": 0, "json_bytes_saved": 0, "linked_images": 0, "image_bytes_saved": 0}
|
|
251
|
+
for section in COMPRESSED_CACHE_SECTIONS:
|
|
252
|
+
for path in sorted((runtime / section / "cache").rglob("*.json")):
|
|
253
|
+
if not _DIGEST_JSON.fullmatch(path.name) or "video" in path.relative_to(runtime).parts:
|
|
254
|
+
continue
|
|
255
|
+
before = path.stat().st_size
|
|
256
|
+
write_cache_entry(path, json.loads(path.read_bytes()))
|
|
257
|
+
report["entries"] += 1
|
|
258
|
+
report["json_bytes_saved"] += before - path.with_name(path.name + ".gz").stat().st_size
|
|
259
|
+
first: dict[str, Path] = {}
|
|
260
|
+
roots = [runtime / section / "cache" for section in COMPRESSED_CACHE_SECTIONS] + [workspace / _artifact_path("egbe-docs/research/market/assets")]
|
|
261
|
+
for root in roots:
|
|
262
|
+
for path in sorted(root.rglob("*")) if root.is_dir() else []:
|
|
263
|
+
stem = path.name.split(".", 1)[0]
|
|
264
|
+
if not path.is_file() or path.is_symlink() or not re.fullmatch(r"[0-9a-f]{64}", stem) or path.suffix.lower() not in (".png", ".jpg", ".jpeg", ".webp", ".gif"):
|
|
265
|
+
continue
|
|
266
|
+
if hashlib.sha256(path.read_bytes()).hexdigest() != stem:
|
|
267
|
+
continue
|
|
268
|
+
original = first.setdefault(stem, path)
|
|
269
|
+
if original != path and not os.path.samefile(original, path):
|
|
270
|
+
report["linked_images"] += 1
|
|
271
|
+
report["image_bytes_saved"] += path.stat().st_size
|
|
272
|
+
link_or_copy(original, path)
|
|
273
|
+
return report
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
if __name__ == "__main__":
|
|
277
|
+
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
278
|
+
parser.add_argument("--compact", type=Path, metavar="WS", required=True, help="Research workspace to compact")
|
|
279
|
+
args = parser.parse_args()
|
|
280
|
+
print(json.dumps(compact(args.compact.resolve()), indent=2))
|
|
281
|
+
sys.exit(0)
|