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