CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history
index.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| fc1817a | 1 | import { mkdir } from "fs/promises"; |
| 2 | import app from "./app"; | |
| 3 | import { config } from "./lib/config"; | |
| eafe8c6 | 4 | import { startWorker } from "./lib/workflow-runner"; |
| 8405c43 | 5 | import { startWebhookDeliveryWorker } from "./lib/webhook-delivery"; |
| 2b821b7 | 6 | import { startAutopilot } from "./lib/autopilot"; |
| 988380a | 7 | import { ensureDemoContent } from "./lib/demo-seed"; |
| 52ad8b1 | 8 | import { ensureDemoActivity } from "./lib/demo-activity-seed"; |
| 2d985e5 | 9 | import { ensureEnvSiteAdmin } from "./lib/admin-bootstrap"; |
| 96942a6 | 10 | import { maybeSelfBootstrap } from "./lib/self-bootstrap"; |
| f764c07 | 11 | import { notifySystemdReady } from "./lib/systemd-notify"; |
| 509c376 | 12 | import { loadConfigIntoEnv } from "./lib/system-config"; |
| fc1817a | 13 | |
| 14 | // Ensure repos directory exists | |
| 15 | await mkdir(config.gitReposPath, { recursive: true }); | |
| 16 | ||
| 509c376 | 17 | // /admin/integrations boot hook — pull saved integration secrets out of the |
| 18 | // system_config table and into process.env BEFORE anything else reads them. | |
| 19 | // This is the magic that lets the existing synchronous config getters | |
| 20 | // (config.anthropicApiKey, config.resendApiKey, …) transparently pick up | |
| 21 | // values an admin saved through the UI, with no restart needed. If the DB | |
| 22 | // is unreachable at boot, env vars stay as the fallback — never blocks | |
| 23 | // startup. | |
| 24 | try { | |
| 25 | const n = await loadConfigIntoEnv(); | |
| 26 | if (n > 0) console.log(`[system-config] loaded ${n} key(s) from DB into env`); | |
| 27 | } catch (err) { | |
| 28 | console.warn( | |
| 29 | "[system-config] boot load failed (env vars remain authoritative):", | |
| 30 | err instanceof Error ? err.message : err | |
| 31 | ); | |
| 32 | } | |
| 33 | ||
| 96942a6 | 34 | // Self-bootstrap: if Gluecron's own canonical repo (`ccantynz/Gluecron.com.git` |
| 35 | // by default) doesn't exist on disk yet, initialize it from the GitHub mirror | |
| 36 | // and install the post-receive hook. This is the platform's self-healing path | |
| 37 | // — once it runs successfully on a host, future deploys flow through Gluecron | |
| 38 | // itself with no external CI tooling. Fire-and-forget; never blocks startup. | |
| 39 | void maybeSelfBootstrap().catch((err) => { | |
| 40 | console.warn(`[self-bootstrap] swallowed: ${(err as Error).message}`); | |
| 41 | }); | |
| 42 | ||
| eafe8c6 | 43 | // Start the Actions-equivalent workflow worker (Block C1). Polls |
| 44 | // workflow_runs for queued rows and executes them sequentially. | |
| 45 | startWorker(); | |
| 46 | ||
| 8405c43 | 47 | // Reliable webhook delivery worker (migration 0056). Polls |
| 48 | // webhook_deliveries for pending rows whose next_attempt_at <= now() and | |
| 49 | // retries with exponential backoff before dead-lettering. | |
| 50 | startWebhookDeliveryWorker(); | |
| 51 | ||
| 2b821b7 | 52 | // Autopilot: periodic mirror sync, merge-queue progress, weekly digests, |
| 53 | // advisory rescans. No-op when AUTOPILOT_DISABLED=1. | |
| 54 | startAutopilot(); | |
| 55 | ||
| 2d985e5 | 56 | // Site-admin bootstrap from env (SITE_ADMIN_USERNAME). Idempotent — if the |
| 57 | // user exists, they get a row in site_admins; if not, logged and retried | |
| 58 | // on next boot. Background-fired so a slow DB doesn't block startup. | |
| a28cede | 59 | void ensureEnvSiteAdmin().catch((err) => { |
| 60 | console.warn( | |
| 61 | "[admin-bootstrap] ensureEnvSiteAdmin failed:", | |
| 62 | err instanceof Error ? err.message : err | |
| 63 | ); | |
| 64 | }); | |
| 2d985e5 | 65 | |
| 988380a | 66 | // Opt-in demo content seed on boot (DEMO_SEED_ON_BOOT=1). Idempotent, never |
| 52ad8b1 | 67 | // throws — safe to run on every start. Block L3 layers extra activity (more |
| 68 | // issues, an open + merged PR on todo-api, AI-review comment, auto-merge | |
| 69 | // audit row) so the live /demo page has content out of the box. | |
| 988380a | 70 | if (process.env.DEMO_SEED_ON_BOOT === "1") { |
| 52ad8b1 | 71 | void (async () => { |
| 72 | try { | |
| 73 | await ensureDemoContent(); | |
| 74 | await ensureDemoActivity(); | |
| 75 | } catch { | |
| 76 | /* never throw out of boot */ | |
| 77 | } | |
| 78 | })(); | |
| 988380a | 79 | } |
| 80 | ||
| fc1817a | 81 | console.log(` |
| 82 | gluecron v0.1.0 | |
| 83 | ────────────────────── | |
| 84 | http://localhost:${config.port} | |
| 85 | repos: ${config.gitReposPath} | |
| 86 | `); | |
| 87 | ||
| f764c07 | 88 | // BLOCK N2 — tell systemd we're ready. No-op when NOTIFY_SOCKET is unset |
| 89 | // (dev / non-systemd hosts). Fire-and-forget; never throws. | |
| a28cede | 90 | void notifySystemdReady().catch((err) => { |
| 91 | console.warn( | |
| 92 | "[systemd] notifySystemdReady failed:", | |
| 93 | err instanceof Error ? err.message : err | |
| 94 | ); | |
| 95 | }); | |
| f764c07 | 96 | |
| fc1817a | 97 | export default { |
| 98 | port: config.port, | |
| 99 | fetch: app.fetch, | |
| 100 | }; |