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
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-sweepgatetest/auto-fix-1776586424172gatetest/auto-fix-1776586534814gatetest/auto-fix-1776590685143gatetest/auto-fix-1776590808199mainops/redeploy-retriggerstyle/dxt-cta-themeworktree-agent-a3377aad30d55da26worktree-agent-a7ef607b7ee1d6c74
ai-workspace.tsx16.1 KB · 544 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
/**
 * AI Copilot Workspace routes.
 *
 * GET  /:owner/:repo/issues/:number/workspace        — status page
 * POST /:owner/:repo/issues/:number/workspace/start  — start job
 */

import { Hono } from "hono";
import { eq, and } from "drizzle-orm";
import { db } from "../db";
import { issues, repositories, users } from "../db/schema";
import { Layout } from "../views/layout";
import { softAuth, requireAuth } from "../middleware/auth";
import { requireRepoAccess } from "../middleware/repo-access";
import type { AuthEnv } from "../middleware/auth";
import {
  startWorkspace,
  getWorkspaceJobForIssue,
  type WorkspaceJob,
  type WorkspaceStatus,
} from "../lib/ai-workspace";
import { isAiAvailable } from "../lib/ai-client";

export const workspaceRoutes = new Hono<AuthEnv>();

// ---------------------------------------------------------------------------
// Styles
// ---------------------------------------------------------------------------

const wsStyles = `
  .ws-hero {
    position: relative;
    margin: 4px 0 24px;
    padding: 28px 32px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
  }
  .ws-hero::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, #5b6ee8 30%, #5f8fa0 70%, transparent 100%);
    opacity: 0.7;
    pointer-events: none;
  }
  .ws-title {
    font-family: var(--font-display);
    font-size: clamp(22px, 3vw, 30px);
    font-weight: 700;
    letter-spacing: -0.022em;
    color: var(--text-strong);
    margin: 0 0 8px;
  }
  .ws-subtitle {
    font-size: 15px;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.5;
  }
  .ws-stepper {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin: 28px 0;
  }
  .ws-step {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px 0;
    border-left: 2px solid var(--border);
    padding-left: 20px;
    position: relative;
  }
  .ws-step:last-child {
    border-left: 2px solid transparent;
  }
  .ws-step-dot {
    position: absolute;
    left: -7px;
    top: 18px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--border);
    border: 2px solid var(--bg);
    flex-shrink: 0;
    transition: background 200ms;
  }
  .ws-step.is-done .ws-step-dot {
    background: #34d399;
  }
  .ws-step.is-active .ws-step-dot {
    background: #5b6ee8;
    box-shadow: 0 0 0 4px rgba(91,110,232,0.22);
    animation: ws-pulse 1.4s ease-in-out infinite;
  }
  .ws-step.is-failed .ws-step-dot {
    background: #f87171;
  }
  @keyframes ws-pulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(91,110,232,0.22); }
    50% { box-shadow: 0 0 0 7px rgba(91,110,232,0.10); }
  }
  .ws-step-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    line-height: 1.4;
    padding-top: 1px;
  }
  .ws-step.is-done .ws-step-label { color: #34d399; }
  .ws-step.is-active .ws-step-label { color: var(--text-strong); }
  .ws-step.is-failed .ws-step-label { color: #f87171; }
  .ws-step-desc {
    font-size: 12.5px;
    color: var(--text-muted);
    margin-top: 2px;
  }
  .ws-result {
    margin-top: 18px;
    padding: 16px 20px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.55;
  }
  .ws-result.is-done {
    background: rgba(52,211,153,0.08);
    border: 1px solid rgba(52,211,153,0.3);
    color: var(--text);
  }
  .ws-result.is-failed {
    background: rgba(248,113,113,0.08);
    border: 1px solid rgba(248,113,113,0.3);
    color: var(--text);
  }
  .ws-pr-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    padding: 9px 18px;
    border-radius: 8px;
    background: rgba(91,110,232,0.14);
    border: 1px solid rgba(91,110,232,0.35);
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
    font-size: 13.5px;
    transition: background 120ms;
  }
  .ws-pr-link:hover { background: rgba(91,110,232,0.22); text-decoration: none; }
  .ws-start-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 22px;
    border-radius: 8px;
    background: rgba(91,110,232,0.14);
    border: 1px solid rgba(91,110,232,0.35);
    color: var(--accent);
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: background 120ms;
  }
  .ws-start-btn:hover { background: rgba(91,110,232,0.22); }
  .ws-explain {
    margin-top: 18px;
    padding: 14px 18px;
    border-radius: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    font-size: 13.5px;
    color: var(--text-muted);
    line-height: 1.6;
  }
  .ws-explain ul {
    margin: 8px 0 0 18px;
    padding: 0;
  }
  .ws-explain li { margin: 4px 0; }
  .ws-back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
    text-decoration: none;
    margin-bottom: 18px;
  }
  .ws-back-link:hover { color: var(--text); text-decoration: none; }
  .ws-badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }
  .ws-badge-active {
    background: rgba(91,110,232,0.15);
    color: #a78bfa;
    border: 1px solid rgba(91,110,232,0.3);
  }
  .ws-badge-done {
    background: rgba(52,211,153,0.12);
    color: #34d399;
    border: 1px solid rgba(52,211,153,0.3);
  }
  .ws-badge-failed {
    background: rgba(248,113,113,0.12);
    color: #f87171;
    border: 1px solid rgba(248,113,113,0.3);
  }
`;

// ---------------------------------------------------------------------------
// Step definitions
// ---------------------------------------------------------------------------

const STEPS: Array<{ key: WorkspaceStatus; label: string; desc: string }> = [
  { key: "planning",       label: "Planning",       desc: "Reading the issue, exploring the codebase, generating a plan" },
  { key: "implementing",   label: "Implementing",   desc: "Creating a branch and applying file changes" },
  { key: "opening_pr",     label: "Opening PR",     desc: "Pushing the branch and opening a draft pull request" },
  { key: "done",           label: "Done",           desc: "PR is open and ready for review" },
];

const STATUS_ORDER: Record<WorkspaceStatus, number> = {
  pending: -1,
  planning: 0,
  implementing: 1,
  opening_pr: 2,
  done: 3,
  failed: -2,
};

function stepClass(stepStatus: WorkspaceStatus, currentStatus: WorkspaceStatus): string {
  if (currentStatus === "failed") {
    // All steps pending or last attempted step shows as failed — just show neutral
    return "";
  }
  const stepOrder = STATUS_ORDER[stepStatus];
  const curOrder = STATUS_ORDER[currentStatus];
  if (stepOrder < curOrder) return "is-done";
  if (stepOrder === curOrder) return "is-active";
  return "";
}

// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------

async function resolveIssueAndRepo(
  ownerName: string,
  repoName: string,
  issueNum: number
) {
  const [ownerRow] = await db
    .select({ id: users.id })
    .from(users)
    .where(eq(users.username, ownerName))
    .limit(1);
  if (!ownerRow) return null;

  const [repoRow] = await db
    .select({ id: repositories.id, name: repositories.name, isPrivate: repositories.isPrivate })
    .from(repositories)
    .where(and(eq(repositories.ownerId, ownerRow.id), eq(repositories.name, repoName)))
    .limit(1);
  if (!repoRow) return null;

  const [issueRow] = await db
    .select({ id: issues.id, number: issues.number, title: issues.title, state: issues.state })
    .from(issues)
    .where(and(eq(issues.repositoryId, repoRow.id), eq(issues.number, issueNum)))
    .limit(1);
  if (!issueRow) return null;

  return { owner: ownerRow, repo: repoRow, issue: issueRow };
}

// ---------------------------------------------------------------------------
// WorkspaceStatusPage JSX component
// ---------------------------------------------------------------------------

function WorkspaceStatusPage({
  owner,
  repoName,
  issue,
  job,
  user,
}: {
  owner: string;
  repoName: string;
  issue: { number: number; title: string };
  job: WorkspaceJob | undefined;
  user: { username: string } | null | undefined;
}) {
  const isActive =
    job &&
    ["pending", "planning", "implementing", "opening_pr"].includes(job.status);
  const isDone = job?.status === "done";
  const isFailed = job?.status === "failed";
  const hasJob = !!job;

  const issueUrl = `/${owner}/${repoName}/issues/${issue.number}`;
  const prUrl = isDone && job.prNumber
    ? `/${owner}/${repoName}/pulls/${job.prNumber}`
    : null;
  const branchUrl = job?.branchName
    ? `/${owner}/${repoName}/tree/${job.branchName}`
    : null;

  return (
    <Layout title={`AI Workspace — #${issue.number}`} user={user as any}>
      {isActive && (
        <meta http-equiv="refresh" content="3" />
      )}
      <style dangerouslySetInnerHTML={{ __html: wsStyles }} />
      <div style="max-width:800px;margin:0 auto;padding:24px 16px">
        <a href={issueUrl} class="ws-back-link">
          &larr; #{issue.number}: {issue.title}
        </a>

        <div class="ws-hero">
          <h1 class="ws-title">
            AI Copilot Workspace
            {isActive && (
              <span class="ws-badge ws-badge-active" style="margin-left:12px;vertical-align:middle">
                Running
              </span>
            )}
            {isDone && (
              <span class="ws-badge ws-badge-done" style="margin-left:12px;vertical-align:middle">
                Done
              </span>
            )}
            {isFailed && (
              <span class="ws-badge ws-badge-failed" style="margin-left:12px;vertical-align:middle">
                Failed
              </span>
            )}
          </h1>
          <p class="ws-subtitle">
            Autonomous issue-to-PR agent — reads the issue, explores the codebase,
            proposes a plan, then opens a draft pull request.
          </p>
        </div>

        {/* If no job, show Start button */}
        {!hasJob && (
          <div>
            <form method="post" action={`/${owner}/${repoName}/issues/${issue.number}/workspace/start`}>
              <button type="submit" class="ws-start-btn">
                Start Workspace
              </button>
            </form>
            <div class="ws-explain">
              <strong>What Gluecron will do:</strong>
              <ul>
                <li>Read issue #{issue.number} and recent comments to understand the task</li>
                <li>Explore the codebase — file tree + most relevant files (Claude-selected)</li>
                <li>Generate an implementation plan and post it as an issue comment</li>
                <li>Create a branch, implement the changes file-by-file</li>
                <li>Open a draft PR linked to this issue</li>
              </ul>
              <p style="margin:12px 0 0">
                This usually takes 60–180 seconds depending on codebase size.
                The page auto-refreshes while running.
              </p>
            </div>
          </div>
        )}

        {/* Stepper — shown when a job exists */}
        {hasJob && (
          <div>
            <div class="ws-stepper">
              {STEPS.map((step) => {
                const cls = isFailed
                  ? ""
                  : stepClass(step.key, job!.status);
                return (
                  <div class={`ws-step ${cls}`}>
                    <div class="ws-step-dot" />
                    <div>
                      <div class="ws-step-label">{step.label}</div>
                      <div class="ws-step-desc">{step.desc}</div>
                    </div>
                  </div>
                );
              })}
            </div>

            {/* Done state */}
            {isDone && prUrl && (
              <div class="ws-result is-done">
                <strong>Workspace complete!</strong> A draft PR has been opened.
                <br />
                {job.planComment && (
                  <p style="margin-top:8px;font-size:13px;color:var(--text-muted)">
                    An implementation plan was posted as a comment on the issue.
                  </p>
                )}
                <a href={prUrl} class="ws-pr-link">
                  View Draft PR #{job.prNumber}
                </a>
                {branchUrl && (
                  <>
                    {" "}
                    <a href={branchUrl} class="ws-pr-link" style="margin-left:8px">
                      Browse Branch
                    </a>
                  </>
                )}
              </div>
            )}

            {/* Failed state */}
            {isFailed && (
              <div class="ws-result is-failed">
                <strong>Workspace failed.</strong>
                {job.errorMessage && (
                  <p style="margin:8px 0 0;font-family:var(--font-mono);font-size:12px;word-break:break-all">
                    {job.errorMessage}
                  </p>
                )}
                <form
                  method="post"
                  action={`/${owner}/${repoName}/issues/${issue.number}/workspace/start`}
                  style="margin-top:14px"
                >
                  <button type="submit" class="ws-start-btn">
                    Retry Workspace
                  </button>
                </form>
              </div>
            )}

            {/* Active state hint */}
            {isActive && (
              <p style="font-size:13px;color:var(--text-muted);margin-top:12px">
                This page refreshes every 3 seconds. You can leave and come back.
              </p>
            )}
          </div>
        )}
      </div>
    </Layout>
  );
}

// ---------------------------------------------------------------------------
// GET /:owner/:repo/issues/:number/workspace
// ---------------------------------------------------------------------------

workspaceRoutes.get(
  "/:owner/:repo/issues/:number/workspace",
  softAuth,
  requireAuth,
  requireRepoAccess("read"),
  async (c) => {
    const { owner, repo } = c.req.param();
    const issueNum = parseInt(c.req.param("number"), 10);
    const user = c.get("user");

    const resolved = await resolveIssueAndRepo(owner, repo, issueNum);
    if (!resolved) {
      return c.html(
        <Layout title="Not Found" user={user}>
          <div style="padding:40px;text-align:center;color:var(--text-muted)">Issue not found.</div>
        </Layout>,
        404
      );
    }

    const job = getWorkspaceJobForIssue(resolved.issue.id);

    return c.html(
      <WorkspaceStatusPage
        owner={owner}
        repoName={repo}
        issue={{ number: resolved.issue.number, title: resolved.issue.title }}
        job={job}
        user={user}
      />
    );
  }
);

// ---------------------------------------------------------------------------
// POST /:owner/:repo/issues/:number/workspace/start
// ---------------------------------------------------------------------------

workspaceRoutes.post(
  "/:owner/:repo/issues/:number/workspace/start",
  softAuth,
  requireAuth,
  requireRepoAccess("write"),
  async (c) => {
    const { owner, repo } = c.req.param();
    const issueNum = parseInt(c.req.param("number"), 10);
    const user = c.get("user")!;

    if (!isAiAvailable()) {
      return c.html(
        <Layout title="AI unavailable" user={user}>
          <div style="padding:40px;text-align:center;color:var(--text-muted)">
            ANTHROPIC_API_KEY is not configured. AI Workspace requires the AI features to be enabled.
          </div>
        </Layout>,
        503
      );
    }

    const resolved = await resolveIssueAndRepo(owner, repo, issueNum);
    if (!resolved) {
      return c.html(
        <Layout title="Not Found" user={user}>
          <div style="padding:40px;text-align:center;color:var(--text-muted)">Issue not found.</div>
        </Layout>,
        404
      );
    }

    await startWorkspace(
      resolved.issue.id,
      resolved.issue.number,
      resolved.repo.id,
      owner,
      repo,
      user.id
    );

    return c.redirect(`/${owner}/${repo}/issues/${issueNum}/workspace`);
  }
);

export default workspaceRoutes;