Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
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.

index.tsBlame100 lines · 2 contributors
fc1817aClaude1import { mkdir } from "fs/promises";
2import app from "./app";
3import { config } from "./lib/config";
eafe8c6Claude4import { startWorker } from "./lib/workflow-runner";
8405c43Claude5import { startWebhookDeliveryWorker } from "./lib/webhook-delivery";
2b821b7Claude6import { startAutopilot } from "./lib/autopilot";
988380aClaude7import { ensureDemoContent } from "./lib/demo-seed";
52ad8b1Claude8import { ensureDemoActivity } from "./lib/demo-activity-seed";
2d985e5Claude9import { ensureEnvSiteAdmin } from "./lib/admin-bootstrap";
96942a6Test User10import { maybeSelfBootstrap } from "./lib/self-bootstrap";
f764c07Claude11import { notifySystemdReady } from "./lib/systemd-notify";
509c376Claude12import { loadConfigIntoEnv } from "./lib/system-config";
fc1817aClaude13
14// Ensure repos directory exists
15await mkdir(config.gitReposPath, { recursive: true });
16
509c376Claude17// /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.
24try {
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
96942a6Test User34// 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.
39void maybeSelfBootstrap().catch((err) => {
40 console.warn(`[self-bootstrap] swallowed: ${(err as Error).message}`);
41});
42
eafe8c6Claude43// Start the Actions-equivalent workflow worker (Block C1). Polls
44// workflow_runs for queued rows and executes them sequentially.
45startWorker();
46
8405c43Claude47// 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.
50startWebhookDeliveryWorker();
51
2b821b7Claude52// Autopilot: periodic mirror sync, merge-queue progress, weekly digests,
53// advisory rescans. No-op when AUTOPILOT_DISABLED=1.
54startAutopilot();
55
2d985e5Claude56// 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.
a28cedeClaude59void ensureEnvSiteAdmin().catch((err) => {
60 console.warn(
61 "[admin-bootstrap] ensureEnvSiteAdmin failed:",
62 err instanceof Error ? err.message : err
63 );
64});
2d985e5Claude65
988380aClaude66// Opt-in demo content seed on boot (DEMO_SEED_ON_BOOT=1). Idempotent, never
52ad8b1Claude67// 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.
988380aClaude70if (process.env.DEMO_SEED_ON_BOOT === "1") {
52ad8b1Claude71 void (async () => {
72 try {
73 await ensureDemoContent();
74 await ensureDemoActivity();
75 } catch {
76 /* never throw out of boot */
77 }
78 })();
988380aClaude79}
80
fc1817aClaude81console.log(`
82 gluecron v0.1.0
83 ──────────────────────
84 http://localhost:${config.port}
85 repos: ${config.gitReposPath}
86`);
87
f764c07Claude88// BLOCK N2 — tell systemd we're ready. No-op when NOTIFY_SOCKET is unset
89// (dev / non-systemd hosts). Fire-and-forget; never throws.
a28cedeClaude90void notifySystemdReady().catch((err) => {
91 console.warn(
92 "[systemd] notifySystemdReady failed:",
93 err instanceof Error ? err.message : err
94 );
95});
f764c07Claude96
fc1817aClaude97export default {
98 port: config.port,
99 fetch: app.fetch,
100};