@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,956 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// install-crons — Install run-scoped cron jobs for an Instantly campaign run.
|
|
3
|
+
//
|
|
4
|
+
// Schedulers: OpenClaw cron (default) or explicit --scheduler cron on an always-on host.
|
|
5
|
+
// Each job is registered as an `agentTurn` payload that triggers an OpenClaw agent
|
|
6
|
+
// with a tightly-scoped message asking it to run exactly one script and report.
|
|
7
|
+
//
|
|
8
|
+
// Unix cron runs the bundled scripts directly without an agent turn.
|
|
9
|
+
//
|
|
10
|
+
// Usage:
|
|
11
|
+
// node install-crons.js --run-dir <path> --env-file <path> [--scheduler openclaw|cron] [--dry-run]
|
|
12
|
+
// [--deliver-channel <channel> --deliver-to <target> | --no-chat-delivery] [--agent <id>]
|
|
13
|
+
//
|
|
14
|
+
// OpenClaw agent: --agent <id> (must exist on the host), else the agent whose
|
|
15
|
+
// workspace holds --run-dir, else the host's default agent from
|
|
16
|
+
// `openclaw agents list --json`. Agent ids differ per host (e.g. "fina"), so
|
|
17
|
+
// the installer never assumes "main". A reinstall keeps the recorded agent.
|
|
18
|
+
//
|
|
19
|
+
// OpenClaw delivery: isolated cron sessions have no "last" chat route, so the
|
|
20
|
+
// installer requires an explicit target (flags, or notifications.deliver_channel
|
|
21
|
+
// / notifications.deliver_to in run-spec.json) or --no-chat-delivery.
|
|
22
|
+
//
|
|
23
|
+
// Send window (OpenClaw only): reply and monitor run only around the campaign's
|
|
24
|
+
// sending schedule (campaign.schedule in run-spec.json), in its timezone.
|
|
25
|
+
|
|
26
|
+
const fs = require("fs");
|
|
27
|
+
const path = require("path");
|
|
28
|
+
const { createHash, randomUUID } = require("crypto");
|
|
29
|
+
const os = require("os");
|
|
30
|
+
const { execFileSync } = require("child_process");
|
|
31
|
+
const {
|
|
32
|
+
readJson,
|
|
33
|
+
writeJson,
|
|
34
|
+
parseArgs,
|
|
35
|
+
isoNow,
|
|
36
|
+
readEnvFile,
|
|
37
|
+
ensureRunEnv,
|
|
38
|
+
getOsConfig,
|
|
39
|
+
} = require("./lib/helpers");
|
|
40
|
+
|
|
41
|
+
function shellQuote(value) {
|
|
42
|
+
return `'${String(value).replace(/'/g, `'\\''`)}'`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function hasBinary(name) {
|
|
46
|
+
try {
|
|
47
|
+
execFileSync("which", [name], {
|
|
48
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
49
|
+
timeout: 5000,
|
|
50
|
+
});
|
|
51
|
+
return true;
|
|
52
|
+
} catch {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// OpenClaw drops a final reply that is exactly this token instead of
|
|
58
|
+
// delivering it, so a quiet tick posts nothing to the owner's chat.
|
|
59
|
+
const SILENT_TOKEN = "NO_REPLY";
|
|
60
|
+
|
|
61
|
+
// 24/7 cadence used when the run spec has no usable sending schedule.
|
|
62
|
+
// Reply runs hourly at :05 so it never coincides with the monitor at :15.
|
|
63
|
+
const DEFAULT_SCHEDULES = { reply: "5 * * * *", monitor: "15 * * * *" };
|
|
64
|
+
const WINDOW_MARGIN_BEFORE_MINUTES = 60;
|
|
65
|
+
const WINDOW_MARGIN_AFTER_MINUTES = 120;
|
|
66
|
+
|
|
67
|
+
function parseClock(value) {
|
|
68
|
+
const match = /^(\d{1,2}):(\d{2})$/.exec(String(value || "").trim());
|
|
69
|
+
if (!match) return null;
|
|
70
|
+
const hours = Number(match[1]);
|
|
71
|
+
const minutes = Number(match[2]);
|
|
72
|
+
if (hours > 24 || minutes > 59 || (hours === 24 && minutes)) return null;
|
|
73
|
+
return hours * 60 + minutes;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Day keys are numeric 0=Sun..6=Sat (Instantly's own format) or weekday
|
|
77
|
+
// names. Any numeric key marks the map numeric, so a Tue-Fri map without
|
|
78
|
+
// "0"/"1" keys is not misread as a name map (which would mean every day).
|
|
79
|
+
function sendingDays(days) {
|
|
80
|
+
if (!days) return [0, 1, 2, 3, 4, 5, 6];
|
|
81
|
+
const names = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
|
82
|
+
const numeric = Object.keys(days).some((key) => /^[0-6]$/.test(key));
|
|
83
|
+
return names
|
|
84
|
+
.map((name, index) => (numeric ? days[String(index)] : days[name]) ? index : null)
|
|
85
|
+
.filter((index) => index != null);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function cronDayField(days) {
|
|
89
|
+
if (days.length === 7) return "*";
|
|
90
|
+
const parts = [];
|
|
91
|
+
for (let i = 0; i < days.length; i++) {
|
|
92
|
+
let j = i;
|
|
93
|
+
while (j + 1 < days.length && days[j + 1] === days[j] + 1) j++;
|
|
94
|
+
parts.push(j - i >= 2 ? `${days[i]}-${days[j]}` : days.slice(i, j + 1).join(","));
|
|
95
|
+
i = j;
|
|
96
|
+
}
|
|
97
|
+
return parts.join(",");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function validTimezone(tz) {
|
|
101
|
+
try {
|
|
102
|
+
new Intl.DateTimeFormat("en-US", { timeZone: tz });
|
|
103
|
+
return true;
|
|
104
|
+
} catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Derive reply/monitor cron expressions from campaign.schedule: same days,
|
|
110
|
+
// from one hour before the window opens until two hours after it closes, in
|
|
111
|
+
// the campaign's timezone. Anything unusable keeps the 24/7 cadence.
|
|
112
|
+
function deriveSendWindow(runSpec) {
|
|
113
|
+
const schedule = runSpec?.campaign?.schedule;
|
|
114
|
+
const fallback = (reason) => ({ applied: false, reason, timezone: "UTC", ...DEFAULT_SCHEDULES });
|
|
115
|
+
if (!schedule) return fallback("run spec has no campaign.schedule; keeping the 24/7 cadence");
|
|
116
|
+
const tz = schedule.timezone;
|
|
117
|
+
const from = parseClock(schedule.timing?.from);
|
|
118
|
+
const to = parseClock(schedule.timing?.to);
|
|
119
|
+
if (!tz || from == null || to == null) {
|
|
120
|
+
return fallback("campaign.schedule needs timezone and timing.from/to (HH:MM); keeping the 24/7 cadence");
|
|
121
|
+
}
|
|
122
|
+
if (!validTimezone(tz)) return fallback(`campaign.schedule.timezone "${tz}" is not a valid IANA zone; keeping the 24/7 cadence`);
|
|
123
|
+
if (to <= from) return fallback("sending windows that cross midnight are not supported; keeping the 24/7 cadence");
|
|
124
|
+
const days = sendingDays(schedule.days);
|
|
125
|
+
if (!days.length) return fallback("campaign.schedule.days has no sending day; keeping the 24/7 cadence");
|
|
126
|
+
const startHour = Math.max(0, Math.floor((from - WINDOW_MARGIN_BEFORE_MINUTES) / 60));
|
|
127
|
+
// Last hourly tick lands in the hour two hours after close (17:00 -> 19:xx).
|
|
128
|
+
const endHour = Math.min(23, Math.floor((to + WINDOW_MARGIN_AFTER_MINUTES) / 60));
|
|
129
|
+
const hours = startHour === endHour ? String(startHour) : `${startHour}-${endHour}`;
|
|
130
|
+
const dow = cronDayField(days);
|
|
131
|
+
return {
|
|
132
|
+
applied: true,
|
|
133
|
+
timezone: tz,
|
|
134
|
+
sending: { from: schedule.timing.from, to: schedule.timing.to, days },
|
|
135
|
+
margin_minutes: { before: WINDOW_MARGIN_BEFORE_MINUTES, after: WINDOW_MARGIN_AFTER_MINUTES },
|
|
136
|
+
hours,
|
|
137
|
+
days_of_week: dow,
|
|
138
|
+
reply: `5 ${hours} * * ${dow}`,
|
|
139
|
+
monitor: `15 ${hours} * * ${dow}`,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function stringOption(value) {
|
|
144
|
+
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Where OpenClaw delivers the agent's final reply for each job.
|
|
148
|
+
function resolveDelivery(args, runSpec) {
|
|
149
|
+
if (args["no-chat-delivery"]) {
|
|
150
|
+
return { mode: "none", source: "--no-chat-delivery", flags: ["--no-deliver"] };
|
|
151
|
+
}
|
|
152
|
+
const notifications = runSpec?.notifications || {};
|
|
153
|
+
const argChannel = stringOption(args["deliver-channel"]);
|
|
154
|
+
const argTo = stringOption(args["deliver-to"]);
|
|
155
|
+
const channel = argChannel || stringOption(notifications.deliver_channel);
|
|
156
|
+
const to = argTo || stringOption(notifications.deliver_to);
|
|
157
|
+
if (!channel || !to) {
|
|
158
|
+
return {
|
|
159
|
+
mode: "missing",
|
|
160
|
+
error:
|
|
161
|
+
"OpenClaw cron jobs need an explicit chat delivery target: isolated cron sessions have no " +
|
|
162
|
+
'"last" chat route, so reports and alerts would be silently dropped. Pass ' +
|
|
163
|
+
"--deliver-channel <channel> --deliver-to <target> (e.g. --deliver-channel slack " +
|
|
164
|
+
"--deliver-to channel:C0123456789), or set notifications.deliver_channel and " +
|
|
165
|
+
"notifications.deliver_to in run-spec.json, or pass --no-chat-delivery to run without chat reports." +
|
|
166
|
+
(channel || to ? ` Got only ${channel ? "a channel" : "a target"}; both are required.` : ""),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
mode: "announce",
|
|
171
|
+
channel,
|
|
172
|
+
to,
|
|
173
|
+
source: argChannel && argTo ? "args" : argChannel || argTo ? "args + run-spec notifications" : "run-spec notifications",
|
|
174
|
+
flags: ["--announce", "--channel", channel, "--to", to],
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function readOpenclawAgents() {
|
|
179
|
+
let out;
|
|
180
|
+
try {
|
|
181
|
+
out = execFileSync("openclaw", ["agents", "list", "--json"], {
|
|
182
|
+
encoding: "utf8",
|
|
183
|
+
timeout: 15000,
|
|
184
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
185
|
+
});
|
|
186
|
+
} catch (err) {
|
|
187
|
+
const detail = String(err.stderr || "").trim() || String(err.message);
|
|
188
|
+
throw new Error(`Cannot read OpenClaw agents (openclaw agents list --json): ${detail}`);
|
|
189
|
+
}
|
|
190
|
+
let parsed;
|
|
191
|
+
try { parsed = JSON.parse(out || "[]"); }
|
|
192
|
+
catch { throw new Error(`Unexpected output from openclaw agents list --json: ${String(out).slice(0, 200)}`); }
|
|
193
|
+
const agents = Array.isArray(parsed) ? parsed : Array.isArray(parsed?.agents) ? parsed.agents : null;
|
|
194
|
+
if (!agents) throw new Error(`Unexpected output from openclaw agents list --json: ${String(out).slice(0, 200)}`);
|
|
195
|
+
return agents.filter((a) => a && typeof a.id === "string" && a.id);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function realpathOr(p) {
|
|
199
|
+
try { return fs.realpathSync(p); } catch { return path.resolve(p); }
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function insideDir(child, parent) {
|
|
203
|
+
const rel = path.relative(parent, child);
|
|
204
|
+
return rel === "" || (!!rel && !rel.startsWith("..") && !path.isAbsolute(rel));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Which OpenClaw agent runs the jobs. A job for an agent the host does not
|
|
208
|
+
// have never runs, and one OpenClaw can hold several agents, so: --agent
|
|
209
|
+
// (must exist on the host), else the agent whose workspace holds the run
|
|
210
|
+
// directory, else the host's default (or only) agent. A reinstall without
|
|
211
|
+
// --agent never moves jobs recorded for another agent.
|
|
212
|
+
function resolveAgent(args, runDir, priorAgentId) {
|
|
213
|
+
if (args.agent === true) throw new Error("--agent needs an agent id");
|
|
214
|
+
const explicit = stringOption(args.agent);
|
|
215
|
+
let agents;
|
|
216
|
+
try { agents = readOpenclawAgents(); }
|
|
217
|
+
catch (err) {
|
|
218
|
+
if (!explicit) throw new Error(`${err.message}; pass --agent <id>`);
|
|
219
|
+
// A broken agents list must not block an operator who names the agent.
|
|
220
|
+
console.error(`WARNING: --agent ${explicit} not checked against the host's agents. ${err.message}`);
|
|
221
|
+
return { id: explicit, source: "--agent (unverified)" };
|
|
222
|
+
}
|
|
223
|
+
const ids = agents.map((a) => a.id);
|
|
224
|
+
if (explicit) {
|
|
225
|
+
if (!ids.includes(explicit)) {
|
|
226
|
+
throw new Error(`OpenClaw agent "${explicit}" is not on this host (agents: ${ids.join(", ") || "none"})`);
|
|
227
|
+
}
|
|
228
|
+
return { id: explicit, source: "--agent" };
|
|
229
|
+
}
|
|
230
|
+
const owners = agents
|
|
231
|
+
.filter((a) => typeof a.workspace === "string" && a.workspace)
|
|
232
|
+
.map((a) => ({ agent: a, real: realpathOr(a.workspace) }))
|
|
233
|
+
.filter((o) => insideDir(runDir, o.real))
|
|
234
|
+
.sort((a, b) => b.real.length - a.real.length)
|
|
235
|
+
.map((o) => o.agent);
|
|
236
|
+
let chosen;
|
|
237
|
+
if (owners.length) chosen = { id: owners[0].id, source: "run-dir workspace" };
|
|
238
|
+
else {
|
|
239
|
+
const fallback = agents.find((a) => a.isDefault === true) || (agents.length === 1 ? agents[0] : null);
|
|
240
|
+
if (!fallback) {
|
|
241
|
+
throw new Error(`No default OpenClaw agent on this host (agents: ${ids.join(", ") || "none"}); pass --agent <id>`);
|
|
242
|
+
}
|
|
243
|
+
chosen = { id: fallback.id, source: fallback.isDefault === true ? "openclaw default agent" : "only openclaw agent" };
|
|
244
|
+
}
|
|
245
|
+
if (priorAgentId && priorAgentId !== chosen.id) {
|
|
246
|
+
throw new Error(
|
|
247
|
+
`This run's jobs were installed for agent "${priorAgentId}", but it now resolves to "${chosen.id}" (${chosen.source}). ` +
|
|
248
|
+
`Pass --agent ${priorAgentId} to keep them there, or --agent ${chosen.id} to move them.`,
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
return chosen;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Unix cron runs in the host timezone and per-entry timezones are not
|
|
255
|
+
// portable, so the window applies to OpenClaw (which takes --tz) only.
|
|
256
|
+
function sendWindowFor(runSpec, scheduler) {
|
|
257
|
+
if (scheduler === "cron") {
|
|
258
|
+
return {
|
|
259
|
+
applied: false,
|
|
260
|
+
reason: "--scheduler cron runs in the host timezone (no portable per-entry timezone); keeping the 24/7 cadence",
|
|
261
|
+
timezone: "host",
|
|
262
|
+
...DEFAULT_SCHEDULES,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
return deriveSendWindow(runSpec);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function jobsForRun(runDir, envFile, runSpec, sendWindow, scheduler) {
|
|
269
|
+
const snapshotSchedule = runSpec.monitoring?.snapshot_schedule;
|
|
270
|
+
if (snapshotSchedule !== undefined &&
|
|
271
|
+
(typeof snapshotSchedule !== "string" || !/^[\d*,/\-]+(?: +[\d*,/\-]+){4}$/.test(snapshotSchedule)))
|
|
272
|
+
throw new Error("monitoring.snapshot_schedule must contain five numeric cron fields, without commands or newlines");
|
|
273
|
+
const base = path.dirname(path.resolve(__filename));
|
|
274
|
+
const replenishEnabled =
|
|
275
|
+
runSpec.lead_replenishment?.enabled === true;
|
|
276
|
+
const windowTz = sendWindow.timezone;
|
|
277
|
+
const fixedTz = scheduler === "cron" ? "host" : "UTC";
|
|
278
|
+
|
|
279
|
+
const jobs = [
|
|
280
|
+
{
|
|
281
|
+
key: "reply",
|
|
282
|
+
schedule: sendWindow.reply,
|
|
283
|
+
tz: windowTz,
|
|
284
|
+
timeout_seconds: 600,
|
|
285
|
+
script: "reply-worker.js",
|
|
286
|
+
intent:
|
|
287
|
+
"Collect new inbound replies for this run into reply-queue.json, then answer or route each pending one.",
|
|
288
|
+
agent_steps: [
|
|
289
|
+
"Before deciding how to respond, read the project's current email-outreach method and this run's plan/reply policy. Use the current task's authority and product facts, not a new policy from this schedule.",
|
|
290
|
+
"After the command, read reply-queue.json in the run directory and handle every item with status \"pending\" by references/reply-handling.md (read it first).",
|
|
291
|
+
"To send a reply you wrote: save the text to a file and run `node send-reply.js --run-dir <run dir> --env-file <env file> --email-id <id> --text-file <file>` from the scripts directory.",
|
|
292
|
+
"If a reply needs the owner, route it through the agreed channel with the original reply and your proposed response, then use `--mark owner_review`.",
|
|
293
|
+
"After reading a reply, record a confirmed refusal with `--mark opt_out`; this also checks stopping known campaigns. Use `--mark no_reply` only for other messages needing no response, such as an automatic reply. A keyword hint alone is not confirmation.",
|
|
294
|
+
"Handle one message at a time; never run two send-reply.js at once. An item still \"sending\" was interrupted mid-send: check its thread in Instantly, then run send-reply.js with `--mark sent` or `--mark pending`.",
|
|
295
|
+
],
|
|
296
|
+
report_rules: [
|
|
297
|
+
"- Report each reply you sent, routed to the owner, or marked, one line each. No new or pending replies is not news.",
|
|
298
|
+
],
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
key: "monitor",
|
|
302
|
+
schedule: sendWindow.monitor,
|
|
303
|
+
tz: windowTz,
|
|
304
|
+
timeout_seconds: 900,
|
|
305
|
+
script: "monitor-campaign.js",
|
|
306
|
+
intent:
|
|
307
|
+
"Fetch campaign-scoped observations and apply the configured operational protection thresholds. Missing required signals are not healthy results; inspect the returned pause/readback state.",
|
|
308
|
+
report_rules: [
|
|
309
|
+
'- The command logs to cron-monitor.log; read monitor-summary.json in the run directory. Report only the items in "alerts" whose "alert" is "new", and "pause_action" if present (a pause was attempted this run).',
|
|
310
|
+
'- If "pause_failed" is true, lead with it: pause is not confirmed. Inspect the provider state; a request response alone does not establish that sending stopped.',
|
|
311
|
+
'- Items with "alert": "repeat" were already reported (including gates the owner acknowledged by resuming the campaign): do not mention them again. "pause_skipped" (campaign already paused), "pause_suppressed" (acknowledged gates) and "protection.skipped_gates" are not news.',
|
|
312
|
+
],
|
|
313
|
+
},
|
|
314
|
+
];
|
|
315
|
+
|
|
316
|
+
if (replenishEnabled) {
|
|
317
|
+
jobs.push({
|
|
318
|
+
key: "replenish",
|
|
319
|
+
schedule: "45 */2 * * *",
|
|
320
|
+
tz: fixedTz,
|
|
321
|
+
timeout_seconds: 1800,
|
|
322
|
+
script: "replenish-leads.js",
|
|
323
|
+
intent:
|
|
324
|
+
"Source the next batch of leads from carry-over or OS Apollo when utilization >= threshold and cooldown has elapsed. Import into the campaign.",
|
|
325
|
+
report_rules: [
|
|
326
|
+
'- The command logs to cron-replenish.log; its result is the last JSON there. Report when leads were imported.',
|
|
327
|
+
'- If the result has "leads_rejected_names" > 0, that is news even when "skipped" is true: report the count and its "warning" text, and point the owner to "rejected_leads_file" (state/rejected-leads.json) in the run directory.',
|
|
328
|
+
'- Otherwise "skipped": true (cooldown, cap, nothing to source) is not news.',
|
|
329
|
+
],
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// A factual export is optional. It does not decide that a test is finished.
|
|
334
|
+
if (runSpec.monitoring?.snapshot_schedule) jobs.push({
|
|
335
|
+
key: "conclude",
|
|
336
|
+
schedule: runSpec.monitoring.snapshot_schedule,
|
|
337
|
+
tz: fixedTz,
|
|
338
|
+
timeout_seconds: 900,
|
|
339
|
+
script: "conclude-campaign.js",
|
|
340
|
+
intent: "Package the latest observed facts as conclusion.json; preserve source timestamps, nulls and partial coverage. This command does not assess the test or mark it complete.",
|
|
341
|
+
report_rules: [
|
|
342
|
+
'- Inspect collection errors and freshness. A newly packaged old snapshot is not new evidence; do not announce a business verdict from it.',
|
|
343
|
+
],
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
return jobs.map((job) => ({
|
|
347
|
+
...job,
|
|
348
|
+
schedule_basis: ["reply", "monitor"].includes(job.key) && sendWindow.applied ? "send-window" : "fixed",
|
|
349
|
+
base,
|
|
350
|
+
command: `cd ${shellQuote(base)} && node ${job.script} --run-dir ${shellQuote(runDir)} --env-file ${shellQuote(envFile)} >> ${shellQuote(path.join(runDir, `cron-${job.key}.log`))} 2>&1`,
|
|
351
|
+
}));
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function jobName(runKey, key) {
|
|
355
|
+
return `instantly-${runKey}-${key}`;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function buildAgentMessage(job, runKey, runDir) {
|
|
359
|
+
return [
|
|
360
|
+
`Scheduled cron job for instantly-campaign-launcher run "${runKey}".`,
|
|
361
|
+
"",
|
|
362
|
+
job.agent_steps ? "Execute this command first:" : "Execute this command, then report according to the rules below:",
|
|
363
|
+
"",
|
|
364
|
+
` ${job.command}`,
|
|
365
|
+
"",
|
|
366
|
+
`Intent: ${job.intent}`,
|
|
367
|
+
...(job.agent_steps ? ["", "Then:", ...job.agent_steps.map((s) => `- ${s}`)] : []),
|
|
368
|
+
"",
|
|
369
|
+
"Reporting rules:",
|
|
370
|
+
"- Do not start unrelated tasks. Do not modify files outside the run directory.",
|
|
371
|
+
job.agent_steps
|
|
372
|
+
? `- Keep reply drafts under ${runDir}/replies/; the scripts write their own state.`
|
|
373
|
+
: `- The script writes its own state under ${runDir}; you do not need to write anything else.`,
|
|
374
|
+
"- If the script exits non-zero, report the exit code and the last error line.",
|
|
375
|
+
...(job.report_rules || []),
|
|
376
|
+
`- Silent rule: when nothing needs the owner (no reply answered or routed, no new alert, no pause, no error), your final reply must be exactly ${SILENT_TOKEN} and nothing else; OpenClaw then delivers nothing. Otherwise send a short report of a few lines.`,
|
|
377
|
+
].join("\n");
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// ---------------------------------------------------------------------------
|
|
381
|
+
// OpenClaw cron path (canonical)
|
|
382
|
+
// ---------------------------------------------------------------------------
|
|
383
|
+
|
|
384
|
+
function listOpenclawJobs(strict = false) {
|
|
385
|
+
try {
|
|
386
|
+
const out = execFileSync("openclaw", ["cron", "list", "--json", "--all"], {
|
|
387
|
+
encoding: "utf8",
|
|
388
|
+
timeout: 15000,
|
|
389
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
390
|
+
});
|
|
391
|
+
const parsed = JSON.parse(out || "[]");
|
|
392
|
+
if (Array.isArray(parsed)) return parsed;
|
|
393
|
+
if (Array.isArray(parsed.jobs)) return parsed.jobs;
|
|
394
|
+
if (strict) throw new Error("Invalid OpenClaw job list; cannot verify removal");
|
|
395
|
+
return [];
|
|
396
|
+
} catch (err) {
|
|
397
|
+
if (strict) throw err;
|
|
398
|
+
return [];
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function jobTargetsRun(job, runDir) {
|
|
403
|
+
const message = job?.payload?.message;
|
|
404
|
+
if (typeof message !== "string") return false;
|
|
405
|
+
// Inspect the generated command, not the human-readable run key: different
|
|
406
|
+
// workspaces can use the same key and therefore the same scheduler job name.
|
|
407
|
+
const argument = ` --run-dir ${shellQuote(runDir)} --env-file `;
|
|
408
|
+
return message.split("\n").some(line => line.startsWith(" cd ") && line.includes(argument));
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function recordedJobIds(record, key, name) {
|
|
412
|
+
return new Set((record.jobs || [])
|
|
413
|
+
.filter(job => job.key === key || job.name === name)
|
|
414
|
+
.flatMap(job => job.ids || []).map(String));
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function findExistingJobs(allJobs, name, runDir, recordedIds = new Set()) {
|
|
418
|
+
return allJobs.filter(job =>
|
|
419
|
+
(job?.name === name || job?.id === name || recordedIds.has(String(job?.id))) &&
|
|
420
|
+
jobTargetsRun(job, runDir));
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function reconcileOpenclawJobs(runDir, runKey, jobs, record) {
|
|
424
|
+
const existing = listOpenclawJobs(true);
|
|
425
|
+
const recordedIds = new Set((record.jobs || []).flatMap(job => job.ids || []).map(String));
|
|
426
|
+
for (const job of existing) {
|
|
427
|
+
if (recordedIds.has(String(job.id)) && !jobTargetsRun(job, runDir)) {
|
|
428
|
+
throw new Error(`Cannot verify recorded OpenClaw job ${job.id} belongs to this exact run directory; preserve the receipt and reconcile it before reinstalling`);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
const names = new Set(["reply", "monitor", "replenish", "conclude"].map(key => jobName(runKey, key)));
|
|
432
|
+
const wantedNames = new Set(jobs.map(job => jobName(runKey, job.key)));
|
|
433
|
+
const wantedIds = new Set(jobs.flatMap(job => [...recordedJobIds(record, job.key, jobName(runKey, job.key))]));
|
|
434
|
+
const obsolete = job => jobTargetsRun(job, runDir) &&
|
|
435
|
+
(names.has(job.name) || recordedIds.has(String(job.id))) &&
|
|
436
|
+
!wantedNames.has(job.name) && !wantedIds.has(String(job.id));
|
|
437
|
+
const removed = [];
|
|
438
|
+
for (const job of existing.filter(obsolete)) {
|
|
439
|
+
if (!job.id) throw new Error(`Cannot safely remove OpenClaw job ${job.name} without its stable ID`);
|
|
440
|
+
execFileSync("openclaw", ["cron", "remove", String(job.id)], {timeout:15000, stdio:"pipe"});
|
|
441
|
+
removed.push(String(job.id));
|
|
442
|
+
}
|
|
443
|
+
if (listOpenclawJobs(true).some(job => removed.includes(String(job.id)) || obsolete(job))) {
|
|
444
|
+
throw new Error("OpenClaw reconciliation failed: omitted jobs remain; preserve the previous receipt and retry removal");
|
|
445
|
+
}
|
|
446
|
+
return removed;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
function openclawCronUpsert(job, runKey, runDir, delivery, agent, record) {
|
|
450
|
+
const name = jobName(runKey, job.key);
|
|
451
|
+
const message = buildAgentMessage(job, runKey, runDir);
|
|
452
|
+
const allJobs = listOpenclawJobs(true);
|
|
453
|
+
const existing = findExistingJobs(allJobs, name, runDir, recordedJobIds(record, job.key, name));
|
|
454
|
+
|
|
455
|
+
if (existing.length > 0) {
|
|
456
|
+
// Dedupe defensively: keep the first match, edit it, delete the rest.
|
|
457
|
+
// Without this, a previously-buggy state with multiple jobs of the same
|
|
458
|
+
// name would have all of them re-edited, leaving N copies firing.
|
|
459
|
+
const keep = existing[0];
|
|
460
|
+
const keepId = keep.id || keep.name;
|
|
461
|
+
execFileSync(
|
|
462
|
+
"openclaw",
|
|
463
|
+
[
|
|
464
|
+
"cron",
|
|
465
|
+
"edit",
|
|
466
|
+
String(keepId),
|
|
467
|
+
"--agent",
|
|
468
|
+
agent.id,
|
|
469
|
+
"--name",
|
|
470
|
+
name,
|
|
471
|
+
"--cron",
|
|
472
|
+
job.schedule,
|
|
473
|
+
"--tz",
|
|
474
|
+
job.tz,
|
|
475
|
+
"--session",
|
|
476
|
+
"isolated",
|
|
477
|
+
"--message",
|
|
478
|
+
message,
|
|
479
|
+
...delivery.flags,
|
|
480
|
+
"--enable",
|
|
481
|
+
"--timeout-seconds",
|
|
482
|
+
String(job.timeout_seconds),
|
|
483
|
+
],
|
|
484
|
+
{ stdio: ["ignore", "pipe", "pipe"], timeout: 15000 },
|
|
485
|
+
);
|
|
486
|
+
const removed = [];
|
|
487
|
+
for (const dup of existing.slice(1)) {
|
|
488
|
+
const dupId = dup.id || dup.name;
|
|
489
|
+
try {
|
|
490
|
+
execFileSync("openclaw", ["cron", "remove", String(dupId)], {
|
|
491
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
492
|
+
timeout: 15000,
|
|
493
|
+
});
|
|
494
|
+
removed.push(dupId);
|
|
495
|
+
} catch (err) {
|
|
496
|
+
console.error(
|
|
497
|
+
`WARNING: failed to remove duplicate cron ${dupId} for ${name}: ${err.message}`,
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return {
|
|
502
|
+
name,
|
|
503
|
+
action: removed.length ? "edited+deduped" : "edited",
|
|
504
|
+
ids: [keepId],
|
|
505
|
+
removed_duplicates: removed,
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
const out = execFileSync(
|
|
510
|
+
"openclaw",
|
|
511
|
+
[
|
|
512
|
+
"cron",
|
|
513
|
+
"add",
|
|
514
|
+
"--json",
|
|
515
|
+
"--agent",
|
|
516
|
+
agent.id,
|
|
517
|
+
"--name",
|
|
518
|
+
name,
|
|
519
|
+
"--cron",
|
|
520
|
+
job.schedule,
|
|
521
|
+
"--tz",
|
|
522
|
+
job.tz,
|
|
523
|
+
"--session",
|
|
524
|
+
"isolated",
|
|
525
|
+
"--message",
|
|
526
|
+
message,
|
|
527
|
+
...delivery.flags,
|
|
528
|
+
"--timeout-seconds",
|
|
529
|
+
String(job.timeout_seconds),
|
|
530
|
+
],
|
|
531
|
+
{ encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 15000 },
|
|
532
|
+
);
|
|
533
|
+
let id = null;
|
|
534
|
+
try {
|
|
535
|
+
const parsed = JSON.parse(out || "{}");
|
|
536
|
+
id = parsed.id || parsed.job_id || parsed.cron_id || null;
|
|
537
|
+
} catch {}
|
|
538
|
+
return { name, action: "added", ids: id ? [id] : [] };
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
function verifyOpenclawJobs(jobs, runKey, runDir) {
|
|
542
|
+
const allJobs = listOpenclawJobs(true);
|
|
543
|
+
const missing = [];
|
|
544
|
+
for (const job of jobs) {
|
|
545
|
+
const name = jobName(runKey, job.key);
|
|
546
|
+
if (findExistingJobs(allJobs, name, runDir).length !== 1) missing.push(name);
|
|
547
|
+
}
|
|
548
|
+
return { ok: missing.length === 0, missing };
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function installViaOpenclaw(runDir, envFile, runKey, jobs, delivery, agent) {
|
|
552
|
+
const record = readJson(path.join(runDir, "cron-install.json"), {});
|
|
553
|
+
const removed = reconcileOpenclawJobs(runDir, runKey, jobs, record);
|
|
554
|
+
const installed = [];
|
|
555
|
+
for (const job of jobs) {
|
|
556
|
+
const result = openclawCronUpsert(job, runKey, runDir, delivery, agent, record);
|
|
557
|
+
installed.push({
|
|
558
|
+
key: job.key,
|
|
559
|
+
name: result.name,
|
|
560
|
+
action: result.action,
|
|
561
|
+
ids: result.ids,
|
|
562
|
+
schedule: job.schedule,
|
|
563
|
+
tz: job.tz,
|
|
564
|
+
schedule_basis: job.schedule_basis,
|
|
565
|
+
timeout_seconds: job.timeout_seconds,
|
|
566
|
+
command: job.command,
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
const verification = verifyOpenclawJobs(jobs, runKey, runDir);
|
|
570
|
+
if (!verification.ok) {
|
|
571
|
+
throw new Error(
|
|
572
|
+
`OpenClaw cron verification failed. Missing or duplicate run jobs after install: ${verification.missing.join(", ")}`,
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
return { scheduler: "openclaw", agent, installed, removed, verification, delivery: publicDelivery(delivery) };
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function publicDelivery(delivery) {
|
|
579
|
+
if (!delivery) return undefined;
|
|
580
|
+
const { flags, error, ...rest } = delivery;
|
|
581
|
+
return { ...rest, openclaw_flags: flags || [] };
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// Unix cron is opt-in: it writes only this run's marked block and preserves
|
|
585
|
+
// unrelated entries. Jobs use the current Node executable, not cron's PATH.
|
|
586
|
+
function readCrontab() {
|
|
587
|
+
try {
|
|
588
|
+
return execFileSync("crontab", ["-l"], { encoding: "utf8", timeout: 15000 });
|
|
589
|
+
} catch (err) {
|
|
590
|
+
if (err.status === 1 && /no crontab for/i.test(String(err.stderr))) return "";
|
|
591
|
+
throw err;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
async function withCrontabLock(callback) {
|
|
596
|
+
const lock = process.env.EGBE_CRON_LOCK_DIR || path.join("/tmp", `egbe-instantly-crontab-${process.geteuid()}.lock`);
|
|
597
|
+
fs.mkdirSync(path.dirname(lock), {recursive:true, mode:0o700});
|
|
598
|
+
try { fs.mkdirSync(lock, {mode:0o700}); }
|
|
599
|
+
catch (err) {
|
|
600
|
+
if (err.code !== "EEXIST") throw err;
|
|
601
|
+
throw new Error(`Crontab installer lock exists: ${lock}. Retry after the installer ends; verify no installer is running before removing a stale lock.`);
|
|
602
|
+
}
|
|
603
|
+
try { return await callback(); }
|
|
604
|
+
finally { fs.rmSync(lock, {recursive:true, force:true}); }
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// A readable/writable crontab does not prove the daemon is executing jobs.
|
|
608
|
+
// Run a harmless, temporary Node probe through cron before claiming availability.
|
|
609
|
+
async function checkCronExecution(timeoutSeconds) {
|
|
610
|
+
const marker = `EGBE-INSTANTLY-PROBE-${randomUUID()}`;
|
|
611
|
+
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "egbe-cron-probe-"));
|
|
612
|
+
const script = path.join(directory, "probe.js");
|
|
613
|
+
const proof = path.join(directory, "executed");
|
|
614
|
+
fs.writeFileSync(script, `require("fs").writeFileSync(${JSON.stringify(proof)}, "executed");`, {mode:0o600});
|
|
615
|
+
const command = [process.execPath, script].map(shellQuote).join(" ") + " >/dev/null 2>&1";
|
|
616
|
+
if (/[\r\n]/.test(command)) {
|
|
617
|
+
fs.rmSync(directory, {recursive:true, force:true});
|
|
618
|
+
throw new Error("Cron probe paths must not contain newlines");
|
|
619
|
+
}
|
|
620
|
+
const entry = `* * * * * /bin/sh -c ${shellQuote(command)} # ${marker}`.replace(/%/g, "\\%");
|
|
621
|
+
try {
|
|
622
|
+
const prior = readCrontab();
|
|
623
|
+
execFileSync("crontab", ["-"], {input:prior + (prior && !prior.endsWith("\n") ? "\n" : "") + entry + "\n", encoding:"utf8", timeout:15000});
|
|
624
|
+
const deadline = Date.now() + timeoutSeconds * 1000;
|
|
625
|
+
while (!fs.existsSync(proof) && Date.now() < deadline) {
|
|
626
|
+
await new Promise(resolve => setTimeout(resolve, 200));
|
|
627
|
+
}
|
|
628
|
+
if (!fs.existsSync(proof)) throw new Error("Cron execution probe timed out: enable the cron daemon on an always-on host before launch");
|
|
629
|
+
return {execution_verified:true};
|
|
630
|
+
} finally {
|
|
631
|
+
// Read again so unrelated edits made during the probe are preserved.
|
|
632
|
+
try {
|
|
633
|
+
const current = readCrontab();
|
|
634
|
+
const updated = current.split("\n").filter(line => !line.includes(marker)).join("\n");
|
|
635
|
+
execFileSync("crontab", ["-"], {input:updated, encoding:"utf8", timeout:15000});
|
|
636
|
+
if (readCrontab().includes(marker)) throw new Error("Cron probe cleanup verification failed");
|
|
637
|
+
} finally { fs.rmSync(directory, {recursive:true, force:true}); }
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
function cronMarker(runDir) {
|
|
642
|
+
return "EGBE-INSTANTLY-" + createHash("sha256").update(runDir).digest("hex").slice(0,24);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function recordedCronMarker(runDir) {
|
|
646
|
+
const prior = readJson(path.join(runDir, "cron-install.json"), {});
|
|
647
|
+
const marker = prior.marker || cronMarker(runDir);
|
|
648
|
+
if (!/^EGBE-INSTANTLY-[0-9a-f]{24}$/.test(marker)) throw new Error("Invalid recorded cron marker");
|
|
649
|
+
return marker;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
function removeCronBlock(text, marker) {
|
|
653
|
+
return text.replace(new RegExp(`^# BEGIN ${marker}\\n[\\s\\S]*?^# END ${marker}(?:\\n|$)`, "gm"), "");
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
async function removeScheduledJobs(runDir, runKey, scheduler) {
|
|
657
|
+
if (scheduler === "cron") {
|
|
658
|
+
if (!hasBinary("crontab")) throw new Error("crontab is unavailable; cannot verify removal");
|
|
659
|
+
return withCrontabLock(() => {
|
|
660
|
+
const marker = recordedCronMarker(runDir);
|
|
661
|
+
const record = readJson(path.join(runDir, "cron-install.json"), {});
|
|
662
|
+
const entries = (record.jobs || []).map((job) => job.entry).filter(Boolean);
|
|
663
|
+
const remains = (text) => text.includes(marker) || entries.some((entry) => text.includes(entry));
|
|
664
|
+
const updated = removeCronBlock(readCrontab(), marker);
|
|
665
|
+
if (remains(updated)) throw new Error("Malformed cron block or recorded entries remain; repair before removal");
|
|
666
|
+
execFileSync("crontab", ["-"], {input:updated, encoding:"utf8", timeout:15000});
|
|
667
|
+
if (remains(readCrontab())) throw new Error("Cron removal verification failed");
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
if (!hasBinary("openclaw")) throw new Error("openclaw is unavailable; cannot verify removal");
|
|
671
|
+
const record = readJson(path.join(runDir, "cron-install.json"), {});
|
|
672
|
+
const names = new Set((record.jobs || []).map((job) => job.name));
|
|
673
|
+
const ids = new Set((record.jobs || []).flatMap((job) => job.ids || []).map(String));
|
|
674
|
+
const matches = (job) => (names.has(job.name) || ids.has(String(job.id))) && jobTargetsRun(job, runDir);
|
|
675
|
+
for (const key of ["reply", "monitor", "replenish", "conclude"]) names.add(jobName(runKey,key));
|
|
676
|
+
const existing = listOpenclawJobs(true);
|
|
677
|
+
if (existing.some(job => ids.has(String(job.id)) && !jobTargetsRun(job, runDir))) {
|
|
678
|
+
throw new Error("Cannot verify recorded OpenClaw job scope; preserve the receipt and reconcile it before removal");
|
|
679
|
+
}
|
|
680
|
+
for (const job of existing) {
|
|
681
|
+
if (matches(job)) execFileSync("openclaw", ["cron", "remove", String(job.id || job.name)], {timeout:15000, stdio:"pipe"});
|
|
682
|
+
}
|
|
683
|
+
if (listOpenclawJobs(true).some(matches)) throw new Error("OpenClaw removal verification failed");
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
async function installViaCron(runDir, envFile, runKey, jobs, timeoutSeconds) {
|
|
687
|
+
return withCrontabLock(async () => {
|
|
688
|
+
const marker = recordedCronMarker(runDir);
|
|
689
|
+
const start = `# BEGIN ${marker}`;
|
|
690
|
+
const end = `# END ${marker}`;
|
|
691
|
+
const runner = path.join(__dirname, "run-cron-job.js");
|
|
692
|
+
const installed = jobs.map((job) => {
|
|
693
|
+
const command = [process.execPath, runner, "--job", job.key,
|
|
694
|
+
"--run-dir", runDir, "--env-file", envFile,
|
|
695
|
+
"--timeout-seconds", String(job.timeout_seconds)].map(shellQuote).join(" ")
|
|
696
|
+
+ ` >> ${shellQuote(path.join(runDir, `cron-${job.key}.log`))} 2>&1`;
|
|
697
|
+
if (/[\r\n]/.test(command)) throw new Error("Cron paths must not contain newlines");
|
|
698
|
+
// Cron interprets % even inside shell quotes. Force a POSIX shell regardless
|
|
699
|
+
// of an existing user crontab's SHELL setting, then escape cron metacharacters.
|
|
700
|
+
const entry = `${job.schedule} /bin/sh -c ${shellQuote(command)} # ${marker}:${job.key}`.replace(/%/g, "\\%");
|
|
701
|
+
return {key:job.key, name:jobName(runKey, job.key), ids:[`${marker}:${job.key}`],
|
|
702
|
+
schedule:job.schedule, tz:job.tz, schedule_basis:job.schedule_basis,
|
|
703
|
+
timeout_seconds:job.timeout_seconds, command, entry};
|
|
704
|
+
});
|
|
705
|
+
const block = [start, ...installed.map((job) => job.entry), end].join("\n");
|
|
706
|
+
const prior = readCrontab();
|
|
707
|
+
const remaining = removeCronBlock(prior, marker);
|
|
708
|
+
const receipt = readJson(path.join(runDir, "cron-install.json"), {});
|
|
709
|
+
const recordedEntries = (receipt.jobs || []).map(job => job.entry).filter(Boolean);
|
|
710
|
+
if (remaining.includes(marker) || recordedEntries.some(entry => remaining.includes(entry))) {
|
|
711
|
+
throw new Error("Malformed run cron block or orphaned recorded entries; repair it before installing");
|
|
712
|
+
}
|
|
713
|
+
const execution = await checkCronExecution(timeoutSeconds);
|
|
714
|
+
const afterProbe = removeCronBlock(readCrontab(), marker);
|
|
715
|
+
if (afterProbe.includes(marker) || recordedEntries.some(entry => afterProbe.includes(entry))) {
|
|
716
|
+
throw new Error("Run cron block changed during execution probe; repair orphaned entries before installing");
|
|
717
|
+
}
|
|
718
|
+
const updated = afterProbe + (afterProbe && !afterProbe.endsWith("\n") ? "\n" : "") + block + "\n";
|
|
719
|
+
execFileSync("crontab", ["-"], {input:updated, encoding:"utf8", timeout:15000});
|
|
720
|
+
const verified = readCrontab();
|
|
721
|
+
if (!verified.split("\n").includes(start) || !verified.includes(block)) {
|
|
722
|
+
throw new Error("Unix cron verification failed: run block missing after install");
|
|
723
|
+
}
|
|
724
|
+
return {scheduler:"cron", timezone:"host", marker, installed,
|
|
725
|
+
verification:{ok:true, missing:[], ...execution}};
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// ---------------------------------------------------------------------------
|
|
730
|
+
// Manifest persistence
|
|
731
|
+
// ---------------------------------------------------------------------------
|
|
732
|
+
|
|
733
|
+
function persistCronJobsToManifest(runDir, result, manifest = readJson(path.join(runDir, "manifest.json"), null)) {
|
|
734
|
+
const manifestPath = path.join(runDir, "manifest.json");
|
|
735
|
+
if (!manifest) return;
|
|
736
|
+
manifest.cron_jobs = {
|
|
737
|
+
scheduler: result.scheduler,
|
|
738
|
+
installed_at: isoNow(),
|
|
739
|
+
jobs: (result.installed || []).map((j) => ({
|
|
740
|
+
key: j.key,
|
|
741
|
+
name: j.name,
|
|
742
|
+
ids: j.ids || [],
|
|
743
|
+
schedule: j.schedule,
|
|
744
|
+
...(j.tz ? { tz: j.tz } : {}),
|
|
745
|
+
})),
|
|
746
|
+
};
|
|
747
|
+
writeJson(manifestPath, manifest);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// ---------------------------------------------------------------------------
|
|
751
|
+
// Main
|
|
752
|
+
// ---------------------------------------------------------------------------
|
|
753
|
+
|
|
754
|
+
async function main() {
|
|
755
|
+
const args = parseArgs(process.argv);
|
|
756
|
+
const scheduler = args.scheduler || "openclaw";
|
|
757
|
+
if (!["openclaw", "cron"].includes(scheduler)) throw new Error("Use --scheduler openclaw or cron");
|
|
758
|
+
const timeoutSeconds = Number(args["scheduler-check-timeout-seconds"] || 75);
|
|
759
|
+
if (!Number.isInteger(timeoutSeconds) || timeoutSeconds < 65 || timeoutSeconds > 120) {
|
|
760
|
+
throw new Error("--scheduler-check-timeout-seconds must be an integer from 65 to 120 (cron needs a full minute plus startup margin)");
|
|
761
|
+
}
|
|
762
|
+
if (args["check-scheduler"]) {
|
|
763
|
+
const binary = scheduler === "cron" ? "crontab" : "openclaw";
|
|
764
|
+
if (!hasBinary(binary)) throw new Error(`${binary} is unavailable; choose a working scheduler before launch`);
|
|
765
|
+
if (scheduler === "cron") await withCrontabLock(() => checkCronExecution(timeoutSeconds));
|
|
766
|
+
else execFileSync("openclaw", ["cron", "list", "--json", "--all"], {timeout:15000, stdio:"pipe"});
|
|
767
|
+
console.log(JSON.stringify({scheduler, available:true}));
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
const runDir = args["run-dir"] ? fs.realpathSync(path.resolve(args["run-dir"])) : null;
|
|
771
|
+
if (!runDir) throw new Error("Missing --run-dir");
|
|
772
|
+
|
|
773
|
+
// Cover receipts as well as scheduler writes: concurrent install/remove or
|
|
774
|
+
// scheduler-switch requests for one run must not publish stale success.
|
|
775
|
+
const runLock = path.join(runDir, ".scheduler-install.lock");
|
|
776
|
+
try { fs.mkdirSync(runLock, {mode:0o700}); }
|
|
777
|
+
catch (err) {
|
|
778
|
+
if (err.code !== "EEXIST") throw err;
|
|
779
|
+
throw new Error(`Run scheduler installer lock exists: ${runLock}. Verify no installer is running before removing a stale lock.`);
|
|
780
|
+
}
|
|
781
|
+
try {
|
|
782
|
+
let manifest;
|
|
783
|
+
try { manifest = readJson(path.join(runDir, "manifest.json")); }
|
|
784
|
+
catch (err) {
|
|
785
|
+
if (!args.remove) throw err;
|
|
786
|
+
manifest = null; // Cleanup must remain available with a truncated manifest.
|
|
787
|
+
}
|
|
788
|
+
const prior = readJson(path.join(runDir, "cron-install.json"), {});
|
|
789
|
+
const runKey = (args.remove ? prior.run_key || manifest?.run_key : manifest?.run_key) || path.basename(runDir);
|
|
790
|
+
if (args.remove) {
|
|
791
|
+
if (args["dry-run"]) { console.log(JSON.stringify({planned_removal:scheduler, run_dir:runDir})); return; }
|
|
792
|
+
if (prior.installed && prior.scheduler !== scheduler) throw new Error("Select the recorded scheduler for removal");
|
|
793
|
+
await removeScheduledJobs(runDir, runKey, scheduler);
|
|
794
|
+
const result = {installed:false, scheduler, removed_at:isoNow(), jobs:[]};
|
|
795
|
+
writeJson(path.join(runDir, "cron-install.json"), result);
|
|
796
|
+
persistCronJobsToManifest(runDir, {scheduler, installed:[]}, manifest);
|
|
797
|
+
console.log(JSON.stringify(result));
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
if (!manifest?.campaign?.id) throw new Error("Run manifest missing campaign ID");
|
|
802
|
+
|
|
803
|
+
// Materialize OS creds from process.env into the run-scoped .env if needed.
|
|
804
|
+
// Cron jobs run with their own environment and only see what's in --env-file,
|
|
805
|
+
// so the run .env must contain OS_URL and OS_API_KEY.
|
|
806
|
+
const envInit = ensureRunEnv(runDir, args["env-file"]);
|
|
807
|
+
const envFile = fs.realpathSync(envInit.envFilePath);
|
|
808
|
+
const stat = fs.statSync(envFile);
|
|
809
|
+
if ((stat.mode & 0o077) !== 0) {
|
|
810
|
+
// ensureRunEnv enforces 0o600; this is defense in depth.
|
|
811
|
+
throw new Error(
|
|
812
|
+
`Env file permissions are too open. Run: chmod 600 ${envFile}`,
|
|
813
|
+
);
|
|
814
|
+
}
|
|
815
|
+
const env = readEnvFile(envFile);
|
|
816
|
+
const os = getOsConfig(env);
|
|
817
|
+
if (os.missing.length) {
|
|
818
|
+
throw new Error(
|
|
819
|
+
`Cannot install crons: ${os.missing.join(" and ")} not found in process.env or ${envFile}. ` +
|
|
820
|
+
`This skill talks to Instantly through the OS outreach capability; it does NOT use a personal Instantly API key. ` +
|
|
821
|
+
`Set OS_URL and OS_API_KEY at the container level, then re-run install-crons.js.`,
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
const runSpec = readJson(path.join(runDir, "run-spec.json"), {});
|
|
826
|
+
const sendWindow = sendWindowFor(runSpec, scheduler);
|
|
827
|
+
const jobs = jobsForRun(runDir, envFile, runSpec, sendWindow, scheduler);
|
|
828
|
+
const delivery = scheduler === "openclaw" ? resolveDelivery(args, runSpec) : null;
|
|
829
|
+
const openclawAvailable = hasBinary("openclaw");
|
|
830
|
+
const priorOpenclawAgent = prior?.installed === true && prior.scheduler === "openclaw" ? stringOption(prior.agent?.id) : null;
|
|
831
|
+
|
|
832
|
+
if (args["dry-run"]) {
|
|
833
|
+
const planned = scheduler === "cron" ? (hasBinary("crontab") ? "cron" : "none") : (openclawAvailable ? "openclaw" : "none");
|
|
834
|
+
let agent;
|
|
835
|
+
if (planned === "openclaw") {
|
|
836
|
+
try { agent = resolveAgent(args, runDir, priorOpenclawAgent); } catch (err) { agent = { error: err.message }; }
|
|
837
|
+
}
|
|
838
|
+
console.log(
|
|
839
|
+
JSON.stringify(
|
|
840
|
+
{
|
|
841
|
+
planned_scheduler: planned,
|
|
842
|
+
run_key: runKey,
|
|
843
|
+
run_dir: runDir,
|
|
844
|
+
env_file: envFile,
|
|
845
|
+
send_window: sendWindow,
|
|
846
|
+
...(agent ? { agent } : {}),
|
|
847
|
+
...(delivery ? { delivery: delivery.mode === "missing" ? { mode: "missing", error: delivery.error } : publicDelivery(delivery) } : {}),
|
|
848
|
+
jobs: jobs.map((j) => ({
|
|
849
|
+
key: j.key,
|
|
850
|
+
name: jobName(runKey, j.key),
|
|
851
|
+
schedule: j.schedule,
|
|
852
|
+
tz: j.tz,
|
|
853
|
+
command: j.command,
|
|
854
|
+
})),
|
|
855
|
+
},
|
|
856
|
+
null,
|
|
857
|
+
2,
|
|
858
|
+
),
|
|
859
|
+
);
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
const priorInstall = readJson(path.join(runDir, "cron-install.json"), null);
|
|
864
|
+
if (priorInstall?.installed === true && priorInstall.scheduler !== scheduler) {
|
|
865
|
+
throw new Error("Run --remove with the recorded scheduler before switching schedulers; preserve the previous install record until removal verifies");
|
|
866
|
+
}
|
|
867
|
+
let result;
|
|
868
|
+
if (scheduler === "cron") {
|
|
869
|
+
if (!hasBinary("crontab")) throw new Error("crontab is unavailable; configure an always-on scheduler before launch");
|
|
870
|
+
result = await installViaCron(runDir, envFile, runKey, jobs, timeoutSeconds);
|
|
871
|
+
} else if (openclawAvailable) {
|
|
872
|
+
// Fail before any scheduler write: a job without a route would run but
|
|
873
|
+
// its reports and alerts would never reach anyone.
|
|
874
|
+
if (delivery.mode === "missing") throw new Error(delivery.error);
|
|
875
|
+
const agent = resolveAgent(args, runDir, priorOpenclawAgent);
|
|
876
|
+
result = installViaOpenclaw(runDir, envFile, runKey, jobs, delivery, agent);
|
|
877
|
+
} else {
|
|
878
|
+
// The no-local-scheduler policy stands (non-zero exit so callers cannot
|
|
879
|
+
// mistake manual mode for done), but a launched campaign still needs
|
|
880
|
+
// monitoring — leave the operator a runbook: the exact commands and
|
|
881
|
+
// cadence to run by hand until the OpenClaw scheduler is available.
|
|
882
|
+
// All state lives under --run-dir, so a later install-crons.js rerun
|
|
883
|
+
// picks up cleanly and overwrites this file.
|
|
884
|
+
const manualJobs = jobs.map((j) => ({
|
|
885
|
+
key: j.key,
|
|
886
|
+
schedule: j.schedule,
|
|
887
|
+
tz: j.tz,
|
|
888
|
+
command: j.command,
|
|
889
|
+
}));
|
|
890
|
+
const cronInstallPath = path.join(runDir, "cron-install.json");
|
|
891
|
+
const prior = readJson(cronInstallPath, null);
|
|
892
|
+
if (prior?.installed === true) {
|
|
893
|
+
// A successful install already exists — its jobs are likely still
|
|
894
|
+
// firing. Do not clobber that record with installed:false just because
|
|
895
|
+
// this shell lacks the CLI.
|
|
896
|
+
throw new Error(
|
|
897
|
+
"openclaw CLI unavailable in this shell, but cron-install.json already records a " +
|
|
898
|
+
`successful install (scheduler: ${prior.scheduler}); jobs are likely still active. ` +
|
|
899
|
+
"Leaving the record untouched — re-run install-crons.js from a shell with openclaw " +
|
|
900
|
+
"on PATH to verify or update jobs.",
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
writeJson(cronInstallPath, {
|
|
904
|
+
installed: false,
|
|
905
|
+
scheduler: "none",
|
|
906
|
+
reason: "openclaw CLI unavailable",
|
|
907
|
+
run_key: runKey,
|
|
908
|
+
env_file: envFile,
|
|
909
|
+
manual_monitoring: manualJobs,
|
|
910
|
+
generated_at: isoNow(),
|
|
911
|
+
});
|
|
912
|
+
console.error(
|
|
913
|
+
"OpenClaw cron is unavailable. Manual monitoring fallback — run these " +
|
|
914
|
+
"by hand on the listed cadence, and re-run install-crons.js once the " +
|
|
915
|
+
"scheduler is back:",
|
|
916
|
+
);
|
|
917
|
+
for (const job of manualJobs) {
|
|
918
|
+
console.error(` [${job.schedule} ${job.tz}] ${job.key}: ${job.command}`);
|
|
919
|
+
}
|
|
920
|
+
throw new Error(
|
|
921
|
+
"OpenClaw cron is unavailable: install-crons.js requires the openclaw CLI. " +
|
|
922
|
+
"Use --scheduler cron on an always-on host for direct script scheduling. " +
|
|
923
|
+
"Manual commands were written to cron-install.json (manual_monitoring).",
|
|
924
|
+
);
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
result.installed = result.installed || [];
|
|
928
|
+
result.run_key = runKey;
|
|
929
|
+
result.env_file = envFile;
|
|
930
|
+
result.installed_at = isoNow();
|
|
931
|
+
result.installed_status = true;
|
|
932
|
+
|
|
933
|
+
writeJson(path.join(runDir, "cron-install.json"), {
|
|
934
|
+
installed: true,
|
|
935
|
+
installed_at: result.installed_at,
|
|
936
|
+
scheduler: result.scheduler,
|
|
937
|
+
env_file: envFile,
|
|
938
|
+
run_key: runKey,
|
|
939
|
+
jobs: result.installed,
|
|
940
|
+
send_window: sendWindow,
|
|
941
|
+
...(result.agent ? { agent: result.agent } : {}),
|
|
942
|
+
...(result.delivery ? { delivery: result.delivery } : {}),
|
|
943
|
+
...(result.marker ? { marker: result.marker } : {}),
|
|
944
|
+
...(result.verification ? { verification: result.verification } : {}),
|
|
945
|
+
});
|
|
946
|
+
|
|
947
|
+
persistCronJobsToManifest(runDir, result);
|
|
948
|
+
|
|
949
|
+
console.log(JSON.stringify(result, null, 2));
|
|
950
|
+
} finally { fs.rmSync(runLock, {recursive:true, force:true}); }
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
main().catch((err) => {
|
|
954
|
+
console.error(err.stack || err.message);
|
|
955
|
+
process.exit(1);
|
|
956
|
+
});
|