Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesPull RequestsActionsSecurityInsightsSettings
✨ AI
More
claude/adoring-hopper-5x74bqclaude/affectionate-feynman-ykrf1hclaude/architecture-audit-design-wxprenclaude/build-status-update-3MXsfclaude/charming-meitner-mllb5rclaude/compare-gate-gluecron-s4mFQclaude/confident-faraday-tikcwbclaude/continue-work-XMTlIclaude/crontech-gluecron-deploy-7MIECclaude/crontech-platform-setup-SeKfwclaude/design-2026claude/ecstatic-ptolemy-jMdigclaude/enhance-github-integration-QNHdGclaude/fix-aa-loop-issue-PonMQclaude/fix-actions-and-processclaude/fix-desktop-errors-XqoW8claude/fix-red-workflowsclaude/fix-website-access-6FKJNclaude/gatetest-integration-hardeningclaude/github-audit-improvements-bDFr9claude/gluecron-launch-status-FoMRlclaude/hopeful-lamport-olfCTclaude/issue-to-pr-and-protectionsclaude/jolly-heisenberg-2sg1Qclaude/launch-preparation-QmTb6claude/new-session-xk1l7claude/plan-platform-architecture-kkN4yclaude/platform-analysis-roadmap-1nUGLclaude/platform-launch-assessment-8dWV8claude/polish-platform-release-AeDrUclaude/resume-previous-work-KzyLwclaude/review-crontech-handoff-qYEVqclaude/review-project-completeness-lHhS2claude/review-readme-docs-ulqPKclaude/serene-edison-rj87weclaude/setup-multi-repo-dev-BCwNQclaude/ship-fixes-and-tests-Jvz1cclaude/site-audit-competitive-pctlwgclaude/site-migration-vercel-XstpKclaude/standalone-product-repos-XHFTDcopilot/feat-smart-empty-states-keyboard-first-enhancementcopilot/feat-smart-morning-digest-review-context-restorecopilot/fix-and-process-workflowscopilot/update-ai-powered-code-reviewfeat/debt-mapfeat/push-policy-codeowners-hardeningfeat/smart-digest-contextfeat/stage-impactfeat/t1-secret-migrationfeat/u-polishfeat/w-self-hostfeat/w2-claude-configfix/agent-journey-orphan-sweepfix/audit-sweep-2026-07-26gatetest/auto-fix-1776586424172gatetest/auto-fix-1776586534814gatetest/auto-fix-1776590685143gatetest/auto-fix-1776590808199mainops/redeploy-retriggerstyle/dxt-cta-themeworktree-agent-a3377aad30d55da26worktree-agent-a7ef607b7ee1d6c74
first-repo-scaffold.ts7.6 KB · 245 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/**
 * Seed a brand-new repository so it arrives working rather than empty.
 *
 * `POST /new` already calls bootstrapRepository(), which creates the DB side —
 * gate settings, branch protection, labels, a welcome issue. But it creates no
 * git content, so a new user landed on an empty repository: no commit, no
 * README, no workflow, and therefore no CI run to be green. Everything the
 * product does on push had nothing to act on, and the first thing a new user
 * saw was an empty-state page telling them to go and configure something.
 *
 * This writes an initial commit containing:
 *
 *   README.md                     what the repo is, and what the platform
 *                                 already did to it
 *   .gluecron/workflows/ci.yml    a workflow that runs on push and passes
 *
 * ...then calls the same syncAndEnqueuePushWorkflows() the git post-receive
 * hook calls. That matters: these files are written through the git plumbing
 * API rather than an actual push, so the post-receive hook never fires and
 * the workflow would otherwise sit undiscovered on disk. Calling the shared
 * seam means scaffolded repos take exactly the same path as pushed ones.
 *
 * Best-effort throughout. A repository that exists but has no README is a
 * cosmetic disappointment; a failed repo creation is a broken product. So
 * every step is caught and reported, never thrown.
 */

export interface ScaffoldResult {
  readmeCommitted: boolean;
  workflowCommitted: boolean;
  /** Workflows discovered and upserted by the shared sync seam. */
  workflowsSynced: number;
  /** CI runs enqueued — this is what makes the repo show a green check. */
  runsEnqueued: number;
  /** Code files embedded, so semantic search works from the first minute. */
  filesIndexed: number;
  errors: string[];
}

/** The CI workflow every new repo starts with. Deliberately trivial and
 *  dependency-free so it passes on a bare runner: the point is to prove the
 *  pipeline works end to end, not to guess the user's stack. */
function ciWorkflow(repoName: string): string {
  return `name: CI

on:
  - push

jobs:
  verify:
    runs-on: ubuntu-latest
    steps:
      - name: Say hello
        run: echo "CI is running for ${repoName}"
      - name: Check the workspace exists
        run: ls -a
`;
}

function readme(owner: string, repoName: string): string {
  return `# ${repoName}

Created on Gluecron. This repository was set up for you — nothing here needed
configuring.

## What is already switched on

- **Branch protection** on the default branch
- **Secret + security scanning** on every push
- **AI review** on every pull request
- **CI** — see \`.gluecron/workflows/ci.yml\`, which ran when this commit landed

## Next

Push some code:

\`\`\`bash
git clone https://gluecron.com/${owner}/${repoName}.git
cd ${repoName}
# ...
git push
\`\`\`

Every push is scanned, reviewed and gated automatically.
`;
}

/**
 * Injectable dependencies.
 *
 * Deliberately mirrors the pattern in push-workflow-sync.ts. Both of these
 * modules are imported by dozens of unrelated test files, so a
 * `mock.module()` on either leaks a global mock across the entire test run —
 * mocking them from this file's tests broke six tests in
 * push-workflow-sync.test.ts, which is precisely what that file's header
 * comment warns about.
 */
export interface ScaffoldDeps {
  createOrUpdateFileOnBranch: (input: {
    owner: string;
    name: string;
    branch: string;
    filePath: string;
    bytes: Uint8Array;
    message: string;
    authorName: string;
    authorEmail: string;
  }) => Promise<
    { commitSha: string; blobSha: string; parentSha: string | null } | { error: string }
  >;
  syncAndEnqueuePushWorkflows: (opts: {
    owner: string;
    repo: string;
    repositoryId: string;
    branch: string;
    commitSha: string;
    triggeredBy?: string | null;
  }) => Promise<{ synced: number; enqueued: number; errors: string[] }>;
}

async function realDeps(): Promise<ScaffoldDeps> {
  const { createOrUpdateFileOnBranch } = await import("../git/repository");
  const { syncAndEnqueuePushWorkflows } = await import("./push-workflow-sync");
  return {
    createOrUpdateFileOnBranch: createOrUpdateFileOnBranch as ScaffoldDeps["createOrUpdateFileOnBranch"],
    syncAndEnqueuePushWorkflows,
  };
}

export async function scaffoldFirstRepo(
  opts: {
    owner: string;
    repoName: string;
    repositoryId: string;
    defaultBranch: string;
    authorName: string;
    authorEmail: string;
    userId: string;
  },
  injected?: ScaffoldDeps
): Promise<ScaffoldResult> {
  const result: ScaffoldResult = {
    readmeCommitted: false,
    workflowCommitted: false,
    workflowsSynced: 0,
    runsEnqueued: 0,
    filesIndexed: 0,
    errors: [],
  };

  const deps = injected ?? (await realDeps());
  const { createOrUpdateFileOnBranch } = deps;
  const enc = new TextEncoder();
  let headSha: string | null = null;

  const write = async (filePath: string, body: string, message: string) => {
    const res = await createOrUpdateFileOnBranch({
      owner: opts.owner,
      name: opts.repoName,
      branch: opts.defaultBranch,
      filePath,
      bytes: enc.encode(body),
      message,
      authorName: opts.authorName,
      authorEmail: opts.authorEmail,
    });
    if ("error" in res) throw new Error(`${filePath}: ${res.error}`);
    return res.commitSha;
  };

  try {
    headSha = await write(
      "README.md",
      readme(opts.owner, opts.repoName),
      "Add README"
    );
    result.readmeCommitted = true;
  } catch (err) {
    result.errors.push(
      `readme: ${err instanceof Error ? err.message : String(err)}`
    );
  }

  try {
    headSha = await write(
      ".gluecron/workflows/ci.yml",
      ciWorkflow(opts.repoName),
      "Add CI workflow"
    );
    result.workflowCommitted = true;
  } catch (err) {
    result.errors.push(
      `workflow: ${err instanceof Error ? err.message : String(err)}`
    );
  }

  // Discover + enqueue via the SAME seam post-receive uses. Without this the
  // workflow file exists on disk but no `workflows` row and no run are ever
  // created, because writing through the plumbing API does not fire the git
  // hook — the repo would look configured and do nothing.
  if (result.workflowCommitted && headSha) {
    try {
      const sync = await deps.syncAndEnqueuePushWorkflows({
        owner: opts.owner,
        repo: opts.repoName,
        repositoryId: opts.repositoryId,
        branch: opts.defaultBranch,
        commitSha: headSha,
        triggeredBy: opts.userId,
      });
      result.workflowsSynced = sync.synced ?? 0;
      result.runsEnqueued = sync.enqueued ?? 0;
    } catch (err) {
      result.errors.push(
        `sync: ${err instanceof Error ? err.message : String(err)}`
      );
    }
  }

  // Semantic index. Same reason the workflow sync is here: indexChangedFiles()
  // runs only from the git post-receive hook, and these files were written
  // through the plumbing API. Without this the repo's semantic search, repo
  // chat and "ask this repo" return nothing — and an empty index is
  // indistinguishable from "no matches", so nobody notices.
  if (headSha) {
    try {
      const { indexExistingRepo } = await import("./index-existing-repo");
      const idx = await indexExistingRepo({
        repositoryId: opts.repositoryId,
        owner: opts.owner,
        repoName: opts.repoName,
        ref: opts.defaultBranch,
        commitSha: headSha,
      });
      result.filesIndexed = idx.indexed;
      if (idx.error) result.errors.push(`index: ${idx.error}`);
    } catch (err) {
      result.errors.push(
        `index: ${err instanceof Error ? err.message : String(err)}`
      );
    }
  }

  return result;
}