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.tsBlame94 lines · 2 contributors
fc1817aClaude1import { mkdir } from "fs/promises";
2import app from "./app";
3import { config } from "./lib/config";
eafe8c6Claude4import { startWorker } from "./lib/workflow-runner";
2b821b7Claude5import { startAutopilot } from "./lib/autopilot";
988380aClaude6import { ensureDemoContent } from "./lib/demo-seed";
52ad8b1Claude7import { ensureDemoActivity } from "./lib/demo-activity-seed";
2d985e5Claude8import { ensureEnvSiteAdmin } from "./lib/admin-bootstrap";
96942a6Test User9import { maybeSelfBootstrap } from "./lib/self-bootstrap";
f764c07Claude10import { notifySystemdReady } from "./lib/systemd-notify";
509c376Claude11import { loadConfigIntoEnv } from "./lib/system-config";
fc1817aClaude12
13// Ensure repos directory exists
14await mkdir(config.gitReposPath, { recursive: true });
15
509c376Claude16// /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.
23try {
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
96942a6Test User33// 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.
38void maybeSelfBootstrap().catch((err) => {
39 console.warn(`[self-bootstrap] swallowed: ${(err as Error).message}`);
40});
41
eafe8c6Claude42// Start the Actions-equivalent workflow worker (Block C1). Polls
43// workflow_runs for queued rows and executes them sequentially.
44startWorker();
45
2b821b7Claude46// Autopilot: periodic mirror sync, merge-queue progress, weekly digests,
47// advisory rescans. No-op when AUTOPILOT_DISABLED=1.
48startAutopilot();
49
2d985e5Claude50// 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.
a28cedeClaude53void ensureEnvSiteAdmin().catch((err) => {
54 console.warn(
55 "[admin-bootstrap] ensureEnvSiteAdmin failed:",
56 err instanceof Error ? err.message : err
57 );
58});
2d985e5Claude59
988380aClaude60// Opt-in demo content seed on boot (DEMO_SEED_ON_BOOT=1). Idempotent, never
52ad8b1Claude61// 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.
988380aClaude64if (process.env.DEMO_SEED_ON_BOOT === "1") {
52ad8b1Claude65 void (async () => {
66 try {
67 await ensureDemoContent();
68 await ensureDemoActivity();
69 } catch {
70 /* never throw out of boot */
71 }
72 })();
988380aClaude73}
74
fc1817aClaude75console.log(`
76 gluecron v0.1.0
77 ──────────────────────
78 http://localhost:${config.port}
79 repos: ${config.gitReposPath}
80`);
81
f764c07Claude82// BLOCK N2 — tell systemd we're ready. No-op when NOTIFY_SOCKET is unset
83// (dev / non-systemd hosts). Fire-and-forget; never throws.
a28cedeClaude84void notifySystemdReady().catch((err) => {
85 console.warn(
86 "[systemd] notifySystemdReady failed:",
87 err instanceof Error ? err.message : err
88 );
89});
f764c07Claude90
fc1817aClaude91export default {
92 port: config.port,
93 fetch: app.fetch,
94};