Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesPull RequestsActionsSecurityInsightsSettings
✨ AI
More
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.tsBlame76 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";
fc1817aClaude11
12// Ensure repos directory exists
13await mkdir(config.gitReposPath, { recursive: true });
14
96942a6Test User15// Self-bootstrap: if Gluecron's own canonical repo (`ccantynz/Gluecron.com.git`
16// by default) doesn't exist on disk yet, initialize it from the GitHub mirror
17// and install the post-receive hook. This is the platform's self-healing path
18// — once it runs successfully on a host, future deploys flow through Gluecron
19// itself with no external CI tooling. Fire-and-forget; never blocks startup.
20void maybeSelfBootstrap().catch((err) => {
21 console.warn(`[self-bootstrap] swallowed: ${(err as Error).message}`);
22});
23
eafe8c6Claude24// Start the Actions-equivalent workflow worker (Block C1). Polls
25// workflow_runs for queued rows and executes them sequentially.
26startWorker();
27
2b821b7Claude28// Autopilot: periodic mirror sync, merge-queue progress, weekly digests,
29// advisory rescans. No-op when AUTOPILOT_DISABLED=1.
30startAutopilot();
31
2d985e5Claude32// Site-admin bootstrap from env (SITE_ADMIN_USERNAME). Idempotent — if the
33// user exists, they get a row in site_admins; if not, logged and retried
34// on next boot. Background-fired so a slow DB doesn't block startup.
a28cedeClaude35void ensureEnvSiteAdmin().catch((err) => {
36 console.warn(
37 "[admin-bootstrap] ensureEnvSiteAdmin failed:",
38 err instanceof Error ? err.message : err
39 );
40});
2d985e5Claude41
988380aClaude42// Opt-in demo content seed on boot (DEMO_SEED_ON_BOOT=1). Idempotent, never
52ad8b1Claude43// throws — safe to run on every start. Block L3 layers extra activity (more
44// issues, an open + merged PR on todo-api, AI-review comment, auto-merge
45// audit row) so the live /demo page has content out of the box.
988380aClaude46if (process.env.DEMO_SEED_ON_BOOT === "1") {
52ad8b1Claude47 void (async () => {
48 try {
49 await ensureDemoContent();
50 await ensureDemoActivity();
51 } catch {
52 /* never throw out of boot */
53 }
54 })();
988380aClaude55}
56
fc1817aClaude57console.log(`
58 gluecron v0.1.0
59 ──────────────────────
60 http://localhost:${config.port}
61 repos: ${config.gitReposPath}
62`);
63
f764c07Claude64// BLOCK N2 — tell systemd we're ready. No-op when NOTIFY_SOCKET is unset
65// (dev / non-systemd hosts). Fire-and-forget; never throws.
a28cedeClaude66void notifySystemdReady().catch((err) => {
67 console.warn(
68 "[systemd] notifySystemdReady failed:",
69 err instanceof Error ? err.message : err
70 );
71});
f764c07Claude72
fc1817aClaude73export default {
74 port: config.port,
75 fetch: app.fetch,
76};