CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
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 | /**
* AI Workspace Hub — /:owner/:repo/workspace
*
* The single entry point for all AI-assisted coding on a repo.
* Surfaces the three existing modes in one clean page so developers
* don't have to hunt through menus to find them:
*
* Mode A — Spec-to-PR: describe a feature, AI writes the code + opens a PR
* Mode B — Fix an issue: pick an open issue, AI implements it autonomously
* Mode C — Quick edit: describe a small change, editor opens on a new branch
*
* Also shows the 5 most recent workspace/spec jobs for this repo so the
* owner can track in-progress AI tasks at a glance.
*/
import { Hono } from "hono";
import { and, desc, eq, gte } from "drizzle-orm";
import { db } from "../db";
import { issues, repositories, users } from "../db/schema";
import { softAuth } from "../middleware/auth";
import type { AuthEnv } from "../middleware/auth";
import { Layout } from "../views/layout";
import { RepoHeader, RepoNav } from "../views/components";
const app = new Hono<AuthEnv>();
app.use("/:owner/:repo/workspace", softAuth);
// ---------------------------------------------------------------------------
// GET /:owner/:repo/workspace
// ---------------------------------------------------------------------------
app.get("/:owner/:repo/workspace", async (c) => {
const { owner, repo } = c.req.param();
const authUser = c.get("user");
const [repoRow] = await db
.select({ repo: repositories, owner: users })
.from(repositories)
.innerJoin(users, eq(repositories.ownerId, users.id))
.where(and(eq(users.username, owner), eq(repositories.name, repo)));
if (!repoRow) return c.notFound();
if (repoRow.repo.isPrivate && authUser?.id !== repoRow.owner.id) return c.notFound();
const isOwner = authUser?.id === repoRow.owner.id;
// Load a handful of open issues to populate the "Fix an issue" mode
const openIssues = await db
.select({
number: issues.number,
title: issues.title,
authorUsername: users.username,
})
.from(issues)
.innerJoin(users, eq(issues.authorId, users.id))
.where(and(eq(issues.repositoryId, repoRow.repo.id), eq(issues.state, "open")))
.orderBy(desc(issues.createdAt))
.limit(8);
const styles = `
.ws-wrap { max-width: 920px; margin: 0 auto; }
.ws-intro {
margin-bottom: var(--space-6);
padding: var(--space-5) var(--space-6);
background: var(--bg-elevated);
border: 1px solid var(--border);
border-radius: 16px;
position: relative;
overflow: hidden;
}
.ws-intro::before {
content: '';
position: absolute;
top: 0; left: 0; right: 0;
height: 3px;
background: var(--accent-gradient);
}
.ws-intro-title {
font-size: 22px;
font-weight: 700;
color: var(--text);
margin: 0 0 var(--space-2);
}
.ws-intro-sub {
font-size: 14px;
color: var(--text-secondary);
max-width: 600px;
}
.ws-modes {
display: grid;
grid-template-columns: 1fr 1fr;
gap: var(--space-4);
margin-bottom: var(--space-6);
}
@media (max-width: 680px) { .ws-modes { grid-template-columns: 1fr; } }
.ws-mode {
background: var(--bg-elevated);
border: 1px solid var(--border);
border-radius: 14px;
padding: var(--space-5);
display: flex;
flex-direction: column;
gap: var(--space-3);
transition: border-color 160ms, box-shadow 160ms;
}
.ws-mode:hover {
border-color: var(--border-strong);
box-shadow: 0 4px 20px rgba(0,0,0,0.18);
}
.ws-mode-icon {
font-size: 28px;
line-height: 1;
}
.ws-mode-title {
font-size: 16px;
font-weight: 700;
color: var(--text);
}
.ws-mode-desc {
font-size: 13px;
color: var(--text-secondary);
flex: 1;
line-height: 1.6;
}
.ws-mode-cta {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 8px 16px;
background: var(--accent-gradient);
color: #fff;
border: none;
border-radius: 8px;
font-size: 13px;
font-weight: 600;
text-decoration: none;
cursor: pointer;
transition: opacity 150ms;
width: fit-content;
}
.ws-mode-cta:hover { opacity: 0.88; color: #fff; text-decoration: none; }
.ws-mode-cta.secondary {
background: var(--bg-inset);
color: var(--text-secondary);
border: 1px solid var(--border);
}
.ws-mode-cta.secondary:hover { border-color: var(--accent); color: var(--accent); opacity: 1; }
.ws-issues-section {
background: var(--bg-elevated);
border: 1px solid var(--border);
border-radius: 14px;
overflow: hidden;
margin-bottom: var(--space-6);
}
.ws-issues-head {
display: flex;
align-items: center;
justify-content: space-between;
padding: var(--space-3) var(--space-5);
border-bottom: 1px solid var(--border);
font-size: 12px;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.07em;
color: var(--text-muted);
}
.ws-issue-row {
display: flex;
align-items: center;
gap: var(--space-3);
padding: var(--space-3) var(--space-5);
transition: background 120ms;
}
.ws-issue-row:hover { background: var(--bg-hover); }
.ws-issue-title {
flex: 1;
font-size: 13px;
color: var(--text);
font-weight: 500;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.ws-issue-num { font-size: 11px; color: var(--text-muted); }
.ws-issue-btn {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 4px 10px;
font-size: 11px;
font-weight: 600;
border: 1px solid var(--border);
border-radius: 7px;
background: var(--bg-inset);
color: var(--text-secondary);
text-decoration: none;
white-space: nowrap;
flex-shrink: 0;
transition: border-color 120ms, color 120ms;
}
.ws-issue-btn:hover { border-color: var(--accent); color: var(--accent); }
.ws-tips {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: var(--space-3);
}
@media (max-width: 600px) { .ws-tips { grid-template-columns: 1fr; } }
.ws-tip {
padding: var(--space-4);
background: var(--bg-elevated);
border: 1px solid var(--border);
border-radius: 10px;
font-size: 12px;
color: var(--text-secondary);
line-height: 1.6;
}
.ws-tip-head { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
`;
return c.html(
<Layout title={`AI Workspace — ${owner}/${repo}`} user={authUser ?? undefined}>
<style>{styles}</style>
<div class="ws-wrap">
<RepoHeader
owner={owner}
repo={repo}
description={repoRow.repo.description ?? ""}
isPrivate={repoRow.repo.isPrivate}
isFork={!!repoRow.repo.forkedFromId}
stars={repoRow.repo.starsCount ?? 0}
forks={repoRow.repo.forksCount ?? 0}
/>
<RepoNav owner={owner} repo={repo} active="workspace" isOwner={isOwner} />
{/* Hero intro */}
<div class="ws-intro">
<div class="ws-intro-title">✨ AI Workspace</div>
<div class="ws-intro-sub">
Claude-powered coding modes for <strong>{owner}/{repo}</strong>. Describe what you want built — the AI writes the code, opens a branch, and creates a draft PR for review.
</div>
</div>
{/* Three modes */}
<div class="ws-modes">
<div class="ws-mode">
<div class="ws-mode-icon">📋</div>
<div class="ws-mode-title">Spec-to-PR</div>
<div class="ws-mode-desc">
Paste a feature specification in plain English. Claude analyses the codebase, writes the implementation, and opens a draft pull request ready for your review.
</div>
<a href={`/${owner}/${repo}/spec`} class="ws-mode-cta">
Write a spec →
</a>
</div>
<div class="ws-mode">
<div class="ws-mode-icon">🔧</div>
<div class="ws-mode-title">Fix an issue</div>
<div class="ws-mode-desc">
Pick any open issue below. Claude reads the issue, explores the relevant code, writes a fix, and opens a PR — you just review and merge.
</div>
<a href={`/${owner}/${repo}/issues`} class="ws-mode-cta secondary">
Browse open issues ↓
</a>
</div>
<div class="ws-mode">
<div class="ws-mode-icon">✏️</div>
<div class="ws-mode-title">Web editor</div>
<div class="ws-mode-desc">
Edit files directly in the browser. Great for quick documentation updates, config tweaks, or small fixes without cloning the repo.
</div>
<a href={`/${owner}/${repo}/new/main`} class="ws-mode-cta secondary">
Open editor →
</a>
</div>
<div class="ws-mode">
<div class="ws-mode-icon">🧪</div>
<div class="ws-mode-title">Generate tests</div>
<div class="ws-mode-desc">
Point Claude at a file or function. It generates a test suite, creates a branch, and opens a PR so you can review coverage improvements instantly.
</div>
<a href={`/${owner}/${repo}/generate-tests`} class="ws-mode-cta secondary">
Generate tests →
</a>
</div>
</div>
{/* Open issues ready to be fixed by AI */}
{openIssues.length > 0 && (
<div class="ws-issues-section">
<div class="ws-issues-head">
<span>Open issues — launch AI workspace</span>
<a href={`/${owner}/${repo}/issues`} style="font-size:11px;color:var(--accent);text-transform:none;letter-spacing:0;text-decoration:none">
All issues →
</a>
</div>
{openIssues.map((issue) => (
<div class="ws-issue-row" key={issue.number}>
<span style="color:#3fb950;font-size:12px;flex-shrink:0">○</span>
<span class="ws-issue-title">{issue.title}</span>
<span class="ws-issue-num">#{issue.number}</span>
{isOwner && (
<a
href={`/${owner}/${repo}/issues/${issue.number}/workspace`}
class="ws-issue-btn"
title="Let AI implement this issue"
>
✨ Fix with AI
</a>
)}
</div>
))}
</div>
)}
{/* Usage tips */}
<div class="ws-tips">
<div class="ws-tip">
<div class="ws-tip-head">Best specs get best results</div>
Include acceptance criteria, the affected files if you know them, and any constraints (no new dependencies, must stay backwards-compatible, etc.).
</div>
<div class="ws-tip">
<div class="ws-tip-head">Always review the diff</div>
AI PRs are drafts. Claude marks them clearly with an ⚡ AI badge. Check the diff before merging — gates still run so broken builds are caught automatically.
</div>
<div class="ws-tip">
<div class="ws-tip-head">Issues → specs → PRs</div>
The fastest flow: file a clear issue, use "Fix with AI" to start a workspace, review the resulting PR. The gate CI runs automatically on every push.
</div>
</div>
</div>
</Layout>
);
});
export default app;
|