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.tsBlame124 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";
5ca514aClaude10import { ensureMarketplaceSeed } from "./lib/agent-marketplace-seed";
96942a6Test User11import { maybeSelfBootstrap } from "./lib/self-bootstrap";
f764c07Claude12import { notifySystemdReady } from "./lib/systemd-notify";
509c376Claude13import { loadConfigIntoEnv } from "./lib/system-config";
60323c5Claude14import { startSshServer } from "./lib/ssh-server";
fc1817aClaude15
16// Ensure repos directory exists
17await mkdir(config.gitReposPath, { recursive: true });
18
509c376Claude19// /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.
26try {
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
96942a6Test User36// 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.
41void maybeSelfBootstrap().catch((err) => {
42 console.warn(`[self-bootstrap] swallowed: ${(err as Error).message}`);
43});
44
60323c5Claude45// 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.
49startSshServer();
50
eafe8c6Claude51// Start the Actions-equivalent workflow worker (Block C1). Polls
52// workflow_runs for queued rows and executes them sequentially.
53startWorker();
54
8405c43Claude55// 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.
58startWebhookDeliveryWorker();
59
2b821b7Claude60// Autopilot: periodic mirror sync, merge-queue progress, weekly digests,
61// advisory rescans. No-op when AUTOPILOT_DISABLED=1.
62startAutopilot();
63
2d985e5Claude64// 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.
a28cedeClaude67void ensureEnvSiteAdmin().catch((err) => {
68 console.warn(
69 "[admin-bootstrap] ensureEnvSiteAdmin failed:",
70 err instanceof Error ? err.message : err
71 );
72});
2d985e5Claude73
5ca514aClaude74// 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).
78void (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
988380aClaude90// Opt-in demo content seed on boot (DEMO_SEED_ON_BOOT=1). Idempotent, never
52ad8b1Claude91// 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.
988380aClaude94if (process.env.DEMO_SEED_ON_BOOT === "1") {
52ad8b1Claude95 void (async () => {
96 try {
97 await ensureDemoContent();
98 await ensureDemoActivity();
99 } catch {
100 /* never throw out of boot */
101 }
102 })();
988380aClaude103}
104
fc1817aClaude105console.log(`
106 gluecron v0.1.0
107 ──────────────────────
108 http://localhost:${config.port}
109 repos: ${config.gitReposPath}
110`);
111
f764c07Claude112// BLOCK N2 — tell systemd we're ready. No-op when NOTIFY_SOCKET is unset
113// (dev / non-systemd hosts). Fire-and-forget; never throws.
a28cedeClaude114void notifySystemdReady().catch((err) => {
115 console.warn(
116 "[systemd] notifySystemdReady failed:",
117 err instanceof Error ? err.message : err
118 );
119});
f764c07Claude120
fc1817aClaude121export default {
122 port: config.port,
123 fetch: app.fetch,
124};