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"; |
| 5ca514a | 10 | import { ensureMarketplaceSeed } from "./lib/agent-marketplace-seed"; |
| 96942a6 | 11 | import { maybeSelfBootstrap } from "./lib/self-bootstrap"; |
| f764c07 | 12 | import { notifySystemdReady } from "./lib/systemd-notify"; |
| 509c376 | 13 | import { loadConfigIntoEnv } from "./lib/system-config"; |
| 60323c5 | 14 | import { startSshServer } from "./lib/ssh-server"; |
| fc1817a | 15 | |
| 16 | // Ensure repos directory exists | |
| 17 | await mkdir(config.gitReposPath, { recursive: true }); | |
| 18 | ||
| 509c376 | 19 | // /admin/integrations boot hook — pull saved integration secrets out of the |
| 20 | // system_config table and into process.env BEFORE anything else reads them. | |
| 21 | // This is the magic that lets the existing synchronous config getters | |
| 22 | // (config.anthropicApiKey, config.resendApiKey, …) transparently pick up | |
| 23 | // values an admin saved through the UI, with no restart needed. If the DB | |
| 24 | // is unreachable at boot, env vars stay as the fallback — never blocks | |
| 25 | // startup. | |
| 26 | try { | |
| 27 | const n = await loadConfigIntoEnv(); | |
| 28 | if (n > 0) console.log(`[system-config] loaded ${n} key(s) from DB into env`); | |
| 29 | } catch (err) { | |
| 30 | console.warn( | |
| 31 | "[system-config] boot load failed (env vars remain authoritative):", | |
| 32 | err instanceof Error ? err.message : err | |
| 33 | ); | |
| 34 | } | |
| 35 | ||
| 96942a6 | 36 | // Self-bootstrap: if Gluecron's own canonical repo (`ccantynz/Gluecron.com.git` |
| 37 | // by default) doesn't exist on disk yet, initialize it from the GitHub mirror | |
| 38 | // and install the post-receive hook. This is the platform's self-healing path | |
| 39 | // — once it runs successfully on a host, future deploys flow through Gluecron | |
| 40 | // itself with no external CI tooling. Fire-and-forget; never blocks startup. | |
| 41 | void maybeSelfBootstrap().catch((err) => { | |
| 42 | console.warn(`[self-bootstrap] swallowed: ${(err as Error).message}`); | |
| 43 | }); | |
| 44 | ||
| 60323c5 | 45 | // SSH git server (Block SSH-1). Listens for git-over-SSH on SSH_PORT |
| 46 | // (default 2222). Authenticates by public key from the `ssh_keys` table. | |
| 47 | // Set SSH_PORT=0 to disable. Set SSH_HOST_KEY to a persistent PEM key | |
| 48 | // in production to avoid "host key changed" warnings on restart. | |
| 49 | startSshServer(); | |
| 50 | ||
| eafe8c6 | 51 | // Start the Actions-equivalent workflow worker (Block C1). Polls |
| 52 | // workflow_runs for queued rows and executes them sequentially. | |
| 53 | startWorker(); | |
| 54 | ||
| 8405c43 | 55 | // Reliable webhook delivery worker (migration 0056). Polls |
| 56 | // webhook_deliveries for pending rows whose next_attempt_at <= now() and | |
| 57 | // retries with exponential backoff before dead-lettering. | |
| 58 | startWebhookDeliveryWorker(); | |
| 59 | ||
| 2b821b7 | 60 | // Autopilot: periodic mirror sync, merge-queue progress, weekly digests, |
| 61 | // advisory rescans. No-op when AUTOPILOT_DISABLED=1. | |
| 62 | startAutopilot(); | |
| 63 | ||
| 2d985e5 | 64 | // Site-admin bootstrap from env (SITE_ADMIN_USERNAME). Idempotent — if the |
| 65 | // user exists, they get a row in site_admins; if not, logged and retried | |
| 66 | // on next boot. Background-fired so a slow DB doesn't block startup. | |
| a28cede | 67 | void ensureEnvSiteAdmin().catch((err) => { |
| 68 | console.warn( | |
| 69 | "[admin-bootstrap] ensureEnvSiteAdmin failed:", | |
| 70 | err instanceof Error ? err.message : err | |
| 71 | ); | |
| 72 | }); | |
| 2d985e5 | 73 | |
| 5ca514a | 74 | // Agent marketplace seed. Idempotent — inserts the 4 canonical example |
| 75 | // listings only if they don't already exist. Background-fired with a small | |
| 76 | // delay so the admin-bootstrap path lands first (the seed lists the | |
| 77 | // publisher as the bootstrap admin). | |
| 78 | void (async () => { | |
| 79 | try { | |
| 80 | await new Promise((r) => setTimeout(r, 1500)); | |
| 81 | await ensureMarketplaceSeed(); | |
| 82 | } catch (err) { | |
| 83 | console.warn( | |
| 84 | "[agent-marketplace-seed] failed:", | |
| 85 | err instanceof Error ? err.message : err | |
| 86 | ); | |
| 87 | } | |
| 88 | })(); | |
| 89 | ||
| 988380a | 90 | // Opt-in demo content seed on boot (DEMO_SEED_ON_BOOT=1). Idempotent, never |
| 52ad8b1 | 91 | // throws — safe to run on every start. Block L3 layers extra activity (more |
| 92 | // issues, an open + merged PR on todo-api, AI-review comment, auto-merge | |
| 93 | // audit row) so the live /demo page has content out of the box. | |
| 988380a | 94 | if (process.env.DEMO_SEED_ON_BOOT === "1") { |
| 52ad8b1 | 95 | void (async () => { |
| 96 | try { | |
| 97 | await ensureDemoContent(); | |
| 98 | await ensureDemoActivity(); | |
| 99 | } catch { | |
| 100 | /* never throw out of boot */ | |
| 101 | } | |
| 102 | })(); | |
| 988380a | 103 | } |
| 104 | ||
| fc1817a | 105 | console.log(` |
| 106 | gluecron v0.1.0 | |
| 107 | ────────────────────── | |
| 108 | http://localhost:${config.port} | |
| 109 | repos: ${config.gitReposPath} | |
| 110 | `); | |
| 111 | ||
| f764c07 | 112 | // BLOCK N2 — tell systemd we're ready. No-op when NOTIFY_SOCKET is unset |
| 113 | // (dev / non-systemd hosts). Fire-and-forget; never throws. | |
| a28cede | 114 | void notifySystemdReady().catch((err) => { |
| 115 | console.warn( | |
| 116 | "[systemd] notifySystemdReady failed:", | |
| 117 | err instanceof Error ? err.message : err | |
| 118 | ); | |
| 119 | }); | |
| f764c07 | 120 | |
| fc1817a | 121 | export default { |
| 122 | port: config.port, | |
| 123 | fetch: app.fetch, | |
| 124 | }; |