@hanzo/dev 4.1.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,18 @@
1
1
  /**
2
- * A repository's files at one revision, from the platform's native git.
2
+ * A repository's files at one revision, and its outbound mirror targets,
3
+ * from the platform's native git.
3
4
  *
4
- * GET /v1/git/repos/{name}/tree?ref=&path= one directory, dirs first
5
- * GET /v1/git/repos/{name}/blob?ref=&path= one file; binary is base64,
6
- * past 1 MiB it is truncated with no content
5
+ * GET /v1/git/repos/{name}/tree?ref=&path= one directory, dirs first
6
+ * GET /v1/git/repos/{name}/blob?ref=&path= one file; binary is base64,
7
+ * past 1 MiB it is truncated with no content
8
+ * GET /v1/git/repos/{name}/targets outbound mirror targets
9
+ * POST /v1/git/repos/{name}/targets attach outbound GitHub mirror + initial sync push
10
+ * POST /v1/git/repos/{name}/link link an existing GitHub repo
7
11
  *
8
12
  * A run pushes its branch to the forge, not here, so a run's files are read
9
13
  * through the run (changes.ts); these read a codebase as the platform holds it.
10
14
  */
15
+ import { type At } from '../address.ts';
11
16
  import { type Target } from './call.ts';
12
17
  export interface Entry {
13
18
  name: string;
@@ -23,6 +28,29 @@ export interface Blob {
23
28
  truncated: boolean;
24
29
  size: number;
25
30
  }
31
+ /** An outbound mirror target attached to a Hanzo Git repository. */
32
+ export interface GitTarget {
33
+ id: string;
34
+ repo: string;
35
+ host: string;
36
+ url: string;
37
+ createdAt: string;
38
+ }
39
+ /**
40
+ * Parse a GitHub repository reference in any form GitHub hands out (`onGitHub`),
41
+ * or in `owner/repo` shorthand (e.g. `hanzoai/dev`).
42
+ */
43
+ export declare function parseGitHubRepo(input: string): At | null;
44
+ export declare function gitTarget(raw: unknown): GitTarget | null;
45
+ /** List outbound mirror targets for a Hanzo Git repository. */
46
+ export declare function listGitTargets(t: Target, name: string, signal?: AbortSignal): Promise<GitTarget[]>;
47
+ /**
48
+ * Attach an outbound GitHub mirror target to a Hanzo Git repository,
49
+ * which also triggers an initial sync push.
50
+ */
51
+ export declare function attachGitHubMirror(t: Target, name: string, url: string): Promise<GitTarget>;
52
+ /** Link an existing GitHub repository to a Hanzo Git repository. */
53
+ export declare function linkGitHubRepo(t: Target, name: string, source: string): Promise<void>;
26
54
  export declare function tree(t: Target, repo: string, ref: string, path?: string): Promise<Entry[]>;
27
55
  /** A tree answer's entries. A run's branch on the forge answers in the same shape. */
28
56
  export declare function entries(raw: unknown): Entry[];
@@ -1,15 +1,85 @@
1
1
  /**
2
- * A repository's files at one revision, from the platform's native git.
2
+ * A repository's files at one revision, and its outbound mirror targets,
3
+ * from the platform's native git.
3
4
  *
4
- * GET /v1/git/repos/{name}/tree?ref=&path= one directory, dirs first
5
- * GET /v1/git/repos/{name}/blob?ref=&path= one file; binary is base64,
6
- * past 1 MiB it is truncated with no content
5
+ * GET /v1/git/repos/{name}/tree?ref=&path= one directory, dirs first
6
+ * GET /v1/git/repos/{name}/blob?ref=&path= one file; binary is base64,
7
+ * past 1 MiB it is truncated with no content
8
+ * GET /v1/git/repos/{name}/targets outbound mirror targets
9
+ * POST /v1/git/repos/{name}/targets attach outbound GitHub mirror + initial sync push
10
+ * POST /v1/git/repos/{name}/link link an existing GitHub repo
7
11
  *
8
12
  * A run pushes its branch to the forge, not here, so a run's files are read
9
13
  * through the run (changes.ts); these read a codebase as the platform holds it.
10
14
  */
15
+ import { ADDRESS, clone, onGitHub } from '../address.js';
11
16
  import { call, query, seg } from './call.js';
12
17
  const str = (v) => (typeof v === 'string' ? v : '');
18
+ const obj = (v) => (v && typeof v === 'object' ? v : {});
19
+ /** GitHub owner/name shorthand segment. */
20
+ const GH_SEG = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
21
+ /**
22
+ * Parse a GitHub repository reference in any form GitHub hands out (`onGitHub`),
23
+ * or in `owner/repo` shorthand (e.g. `hanzoai/dev`).
24
+ */
25
+ export function parseGitHubRepo(input) {
26
+ const s = input.trim();
27
+ if (!s)
28
+ return null;
29
+ const full = onGitHub(s);
30
+ if (full)
31
+ return full;
32
+ const cleaned = s.replace(/\/+$/, '').replace(/\.git$/i, '');
33
+ const parts = cleaned.split('/');
34
+ if (parts.length !== 2)
35
+ return null;
36
+ const [owner, name] = parts;
37
+ return owner && name && GH_SEG.test(owner) && GH_SEG.test(name) ? { owner, name } : null;
38
+ }
39
+ export function gitTarget(raw) {
40
+ const o = obj(raw);
41
+ const url = str(o.url);
42
+ if (!url)
43
+ return null;
44
+ return {
45
+ id: str(o.id),
46
+ repo: str(o.repo),
47
+ host: str(o.host),
48
+ url,
49
+ createdAt: str(o.createdAt),
50
+ };
51
+ }
52
+ /** List outbound mirror targets for a Hanzo Git repository. */
53
+ export async function listGitTargets(t, name, signal) {
54
+ const raw = await call(t, 'GET', `/v1/git/repos/${seg(name)}/targets`, undefined, { signal });
55
+ const rows = Array.isArray(raw) ? raw : Array.isArray(obj(raw).data) ? obj(raw).data : [];
56
+ return rows.map(gitTarget).filter((x) => x !== null);
57
+ }
58
+ /**
59
+ * Attach an outbound GitHub mirror target to a Hanzo Git repository,
60
+ * which also triggers an initial sync push.
61
+ */
62
+ export async function attachGitHubMirror(t, name, url) {
63
+ const at = parseGitHubRepo(url);
64
+ if (!at)
65
+ throw new Error(ADDRESS);
66
+ const cloneUrl = clone(at);
67
+ const raw = await call(t, 'POST', `/v1/git/repos/${seg(name)}/targets`, { url: cloneUrl });
68
+ return (gitTarget(raw) ?? {
69
+ id: '',
70
+ repo: name,
71
+ host: 'github.com',
72
+ url: cloneUrl,
73
+ createdAt: '',
74
+ });
75
+ }
76
+ /** Link an existing GitHub repository to a Hanzo Git repository. */
77
+ export async function linkGitHubRepo(t, name, source) {
78
+ const at = parseGitHubRepo(source);
79
+ if (!at)
80
+ throw new Error(ADDRESS);
81
+ await call(t, 'POST', `/v1/git/repos/${seg(name)}/link`, { source: clone(at) });
82
+ }
13
83
  export async function tree(t, repo, ref, path = '') {
14
84
  return entries(await call(t, 'GET', `/v1/git/repos/${seg(repo)}/tree${query({ ref, path })}`));
15
85
  }
@@ -1,4 +1,6 @@
1
1
  import { type Target } from './call.ts';
2
+ import { attachGitHubMirror, linkGitHubRepo, listGitTargets, parseGitHubRepo, type GitTarget } from './git.ts';
3
+ export { attachGitHubMirror, linkGitHubRepo, listGitTargets, parseGitHubRepo, type GitTarget };
2
4
  export interface Repo {
3
5
  owner: string;
4
6
  name: string;
@@ -174,3 +176,55 @@ export interface Synced {
174
176
  * never duplicates, and the App's webhook keeps them live afterwards.
175
177
  */
176
178
  export declare function syncIssues(t: Target, repo?: string): Promise<Synced>;
179
+ /** A repository created or forked on GitHub through the platform. */
180
+ export interface CreatedRepo {
181
+ full_name: string;
182
+ html_url: string;
183
+ clone_url: string;
184
+ default_branch: string;
185
+ private: boolean;
186
+ existing: boolean;
187
+ }
188
+ export interface CreateRepoInput {
189
+ name: string;
190
+ description?: string;
191
+ private?: boolean;
192
+ org?: string;
193
+ linkRepo?: string;
194
+ }
195
+ export interface ForkRepoInput {
196
+ /** `owner/repo`, GitHub URL, or bare repo name. */
197
+ repo: string;
198
+ org?: string;
199
+ name?: string;
200
+ }
201
+ /**
202
+ * Create a GitHub repository via `POST /v1/provider/github/repos`.
203
+ * When `linkRepo` is provided, the platform also links and syncs that Hanzo Git repo to it.
204
+ * May throw `Refusal` with status 412 or 409 when personal GitHub user OAuth is required.
205
+ */
206
+ export declare function createGitHubRepo(t: Target, input: CreateRepoInput): Promise<CreatedRepo>;
207
+ /**
208
+ * Fork a GitHub repository via `POST /v1/provider/github/fork`.
209
+ * Accepts `owner/repo`, a full GitHub URL (normalized to `owner/repo`), or a bare repo name.
210
+ * May throw `Refusal` with status 412 or 409 when personal GitHub user OAuth is required.
211
+ */
212
+ export declare function forkGitHubRepo(t: Target, input: ForkRepoInput): Promise<CreatedRepo>;
213
+ /**
214
+ * True when creating or forking a GitHub repository failed because the user's
215
+ * personal GitHub account requires user OAuth authorization (HTTP 412 or 409).
216
+ */
217
+ export declare function isGitHubUserOAuthRequired(err: unknown): boolean;
218
+ /** Resolved GitHub identity for a project backed directly by GitHub or via an outbound mirror target. */
219
+ export interface GitHubRepoBadgeInfo {
220
+ owner: string;
221
+ name: string;
222
+ fullName: string;
223
+ htmlUrl: string;
224
+ source: 'repo' | 'target' | 'link';
225
+ }
226
+ /**
227
+ * Resolve a project's GitHub repository from its primary clone URL or outbound mirror targets.
228
+ * Returns null if the project is Hanzo Git only and not yet synced to GitHub.
229
+ */
230
+ export declare function githubRepoFrom(repoUrl: string, targets?: readonly GitTarget[]): GitHubRepoBadgeInfo | null;
@@ -21,9 +21,12 @@
21
21
  * and that page completes it (`complete`, and `landed` in ../back.ts).
22
22
  */
23
23
  import { phrase } from '@hanzo/i18n';
24
- import { call, query, seg } from './call.js';
24
+ import { onGitHub } from '../address.js';
25
+ import { call, query, Refusal, seg } from './call.js';
25
26
  import { codebases } from './codebases.js';
27
+ import { attachGitHubMirror, linkGitHubRepo, listGitTargets, parseGitHubRepo } from './git.js';
26
28
  import { links } from './links.js';
29
+ export { attachGitHubMirror, linkGitHubRepo, listGitTargets, parseGitHubRepo };
27
30
  const str = (v) => (typeof v === 'string' ? v : '');
28
31
  const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : 0);
29
32
  const obj = (v) => v && typeof v === 'object' ? v : {};
@@ -269,3 +272,102 @@ export async function syncIssues(t, repo = '') {
269
272
  truncated: raw.truncated === true,
270
273
  };
271
274
  }
275
+ function createdRepo(raw) {
276
+ const r = obj(raw);
277
+ const full = str(r.full_name);
278
+ const html = str(r.html_url) || (full ? `https://github.com/${full}` : '');
279
+ const cloneUrl = str(r.clone_url) || (full ? `https://github.com/${full}.git` : '');
280
+ return {
281
+ full_name: full,
282
+ html_url: html,
283
+ clone_url: cloneUrl,
284
+ default_branch: str(r.default_branch) || 'main',
285
+ private: r.private === true,
286
+ existing: r.existing === true,
287
+ };
288
+ }
289
+ /**
290
+ * Create a GitHub repository via `POST /v1/provider/github/repos`.
291
+ * When `linkRepo` is provided, the platform also links and syncs that Hanzo Git repo to it.
292
+ * May throw `Refusal` with status 412 or 409 when personal GitHub user OAuth is required.
293
+ */
294
+ export async function createGitHubRepo(t, input) {
295
+ const name = input.name.trim();
296
+ if (!name)
297
+ throw new Error(phrase('Enter a repository name'));
298
+ const body = { name };
299
+ const desc = input.description?.trim();
300
+ if (desc)
301
+ body.description = desc;
302
+ if (input.private !== undefined)
303
+ body.private = input.private;
304
+ const org = input.org?.trim();
305
+ if (org)
306
+ body.org = org;
307
+ const linkRepo = input.linkRepo?.trim();
308
+ if (linkRepo)
309
+ body.linkRepo = linkRepo;
310
+ return createdRepo(await call(t, 'POST', '/v1/provider/github/repos', body));
311
+ }
312
+ /**
313
+ * Fork a GitHub repository via `POST /v1/provider/github/fork`.
314
+ * Accepts `owner/repo`, a full GitHub URL (normalized to `owner/repo`), or a bare repo name.
315
+ * May throw `Refusal` with status 412 or 409 when personal GitHub user OAuth is required.
316
+ */
317
+ export async function forkGitHubRepo(t, input) {
318
+ const rawRepo = input.repo.trim();
319
+ if (!rawRepo)
320
+ throw new Error(phrase('Enter a GitHub repository to fork (owner/repo)'));
321
+ const parsed = onGitHub(rawRepo);
322
+ const repo = parsed ? `${parsed.owner}/${parsed.name}` : rawRepo.replace(/^\/+|\/+$/g, '').replace(/\.git$/i, '');
323
+ const body = { repo };
324
+ const org = input.org?.trim();
325
+ if (org)
326
+ body.org = org;
327
+ const name = input.name?.trim();
328
+ if (name)
329
+ body.name = name;
330
+ return createdRepo(await call(t, 'POST', '/v1/provider/github/fork', body));
331
+ }
332
+ /**
333
+ * True when creating or forking a GitHub repository failed because the user's
334
+ * personal GitHub account requires user OAuth authorization (HTTP 412 or 409).
335
+ */
336
+ export function isGitHubUserOAuthRequired(err) {
337
+ if (err instanceof Refusal)
338
+ return err.status === 412 || err.status === 409;
339
+ if (err && typeof err === 'object' && 'status' in err) {
340
+ const status = err.status;
341
+ return status === 412 || status === 409;
342
+ }
343
+ return false;
344
+ }
345
+ /**
346
+ * Resolve a project's GitHub repository from its primary clone URL or outbound mirror targets.
347
+ * Returns null if the project is Hanzo Git only and not yet synced to GitHub.
348
+ */
349
+ export function githubRepoFrom(repoUrl, targets) {
350
+ const direct = repoUrl ? onGitHub(repoUrl) : null;
351
+ if (direct) {
352
+ return {
353
+ owner: direct.owner,
354
+ name: direct.name,
355
+ fullName: `${direct.owner}/${direct.name}`,
356
+ htmlUrl: `https://github.com/${direct.owner}/${direct.name}`,
357
+ source: 'repo',
358
+ };
359
+ }
360
+ for (const t of targets ?? []) {
361
+ const at = parseGitHubRepo(t.url);
362
+ if (at) {
363
+ return {
364
+ owner: at.owner,
365
+ name: at.name,
366
+ fullName: `${at.owner}/${at.name}`,
367
+ htmlUrl: `https://github.com/${at.owner}/${at.name}`,
368
+ source: 'target',
369
+ };
370
+ }
371
+ }
372
+ return null;
373
+ }
@@ -17,7 +17,7 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
17
17
  import { SizableText, useMedia, XStack, YStack } from '@hanzo/gui';
18
18
  import { phrase } from '@hanzo/i18n';
19
19
  import { useI18n } from '@hanzo/i18n/react';
20
- import { ArrowRight, Check, ChevronDown, CircleCheck, CircleDot, CircleSlash, Copy, ExternalLink, FolderGit2, GitBranch, Github, GitPullRequest, LayoutTemplate, MoreHorizontal, RefreshCw, Search, SlidersHorizontal, Trash2, X, } from '@hanzogui/lucide-icons-2';
20
+ import { ArrowRight, Check, ChevronDown, CircleCheck, CircleDot, CircleSlash, Copy, ExternalLink, FolderGit2, GitBranch, GitFork, Github, GitPullRequest, LayoutTemplate, MoreHorizontal, Plus, RefreshCw, Search, SlidersHorizontal, Trash2, X, } from '@hanzogui/lucide-icons-2';
21
21
  import { Button, Dialog, DialogContent, DialogTitle, DropdownMenu, Input, Skeleton, toast } from '@hanzo/ui';
22
22
  import { useEffect, useMemo, useState } from 'react';
23
23
  import { copy as toClipboard } from './clipboard.js';
@@ -25,7 +25,7 @@ import { RING, RING_INSET } from './pane.js';
25
25
  import { ago } from './ago.js';
26
26
  import { codebases, remove as removeRepo } from './api/codebases.js';
27
27
  import { unlink as removeLink } from './api/links.js';
28
- import { remove as removeProject } from './api/projects.js';
28
+ import { remove as removeProject, name as repoName } from './api/projects.js';
29
29
  import { Scheduled } from './scheduled.js';
30
30
  import { boards, everything, sources, UNREAD } from './api/work.js';
31
31
  import { boardKey, pinRepo, readPending, writePending } from './choice.js';
@@ -35,9 +35,10 @@ import { useHost, useTarget } from './host.js';
35
35
  import { path } from './route.js';
36
36
  import { Customize } from './customize/index.js';
37
37
  import { Sync } from './sync.js';
38
- import { changed, connect, connection, disconnect as unlink, grants, heard, installations, linked, syncIssues } from './api/github.js';
38
+ import { changed, connect, connection, disconnect as unlink, githubRepoFrom, grants, heard, installations, linked, listGitTargets, syncIssues, } from './api/github.js';
39
39
  import { disconnect } from './api/provider.js';
40
40
  import { here, useBack } from './back.js';
41
+ import { GitHubBadge, GitHubReposModal, SyncToGitHubDialog } from './github-sync.js';
41
42
  import { Out } from './out.js';
42
43
  import { ask, assemble, attach, closes, facets, handle, home, keyOf, matches, pickProjects, place } from './merge.js';
43
44
  import { removal, stopped } from './removal.js';
@@ -146,11 +147,52 @@ function Projects() {
146
147
  const to = safePage * PAGE + slice.length;
147
148
  const none = !list.loading && !list.error && list.value.length === 0 && pending.length === 0;
148
149
  const open = (c) => host.go(path({ kind: 'repo', org: c.org || host.org || '', name: c.name }));
149
- const link = () => host.go(path({ kind: 'screen', screen: 'sync' }));
150
+ const [githubModal, setGitHubModal] = useState({ open: false, tab: 'browse' });
151
+ const openGitHubModal = (tab = 'browse') => setGitHubModal({ open: true, tab });
152
+ const link = () => openGitHubModal('browse');
150
153
  const template = () => host.go(path({ kind: 'screen', screen: 'templates' }));
154
+ // Outbound GitHub mirror targets for visible repositories, plus optimistic sync state.
155
+ const [syncTarget, setSyncTarget] = useState(null);
156
+ const [syncedMap, setSyncedMap] = useState({});
157
+ const [rowTargets, setRowTargets] = useState({});
158
+ const visibleNames = slice.filter((c) => !syncing.has(c.name)).map((c) => c.name);
159
+ const visibleKey = visibleNames.join('\n');
160
+ useEffect(() => {
161
+ if (!signed || !visibleKey)
162
+ return;
163
+ let stop = false;
164
+ const names = visibleKey.split('\n');
165
+ void Promise.all(names.map(async (n) => [n, await listGitTargets(target, n).catch(() => [])])).then((entries) => {
166
+ if (stop)
167
+ return;
168
+ setRowTargets((prev) => ({ ...prev, ...Object.fromEntries(entries) }));
169
+ });
170
+ return () => {
171
+ stop = true;
172
+ };
173
+ }, [signed, target, visibleKey, landed]);
151
174
  // What each repository is tied to on Hanzo — the links into it, GitHub's names
152
175
  // for the copies it made, the projects built from it — read for Remove alone.
153
176
  const made = useRead(signed ? () => sources(target) : null, NONE, [target, signed, landed]);
177
+ const githubFor = (c) => {
178
+ if (syncedMap[c.name])
179
+ return syncedMap[c.name];
180
+ const directOrTarget = githubRepoFrom(c.clone, rowTargets[c.name]);
181
+ if (directOrTarget)
182
+ return directOrTarget;
183
+ const inbound = made.value.linked.find((l) => l.forge.toLowerCase() === c.name.toLowerCase());
184
+ if (inbound && inbound.owner && inbound.name) {
185
+ return {
186
+ owner: inbound.owner,
187
+ name: inbound.name,
188
+ fullName: `${inbound.owner}/${inbound.name}`,
189
+ htmlUrl: `https://github.com/${inbound.owner}/${inbound.name}`,
190
+ source: 'link',
191
+ };
192
+ }
193
+ const site = made.value.sites.find((s) => s.slug.toLowerCase() === c.name.toLowerCase() || (s.repo && repoName(s.repo).toLowerCase() === c.name.toLowerCase()));
194
+ return site?.repo ? githubRepoFrom(site.repo) : null;
195
+ };
154
196
  const [confirming, setConfirming] = useState(null);
155
197
  const [removing, setRemoving] = useState(false);
156
198
  const [said, setSaid] = useState('');
@@ -195,15 +237,35 @@ function Projects() {
195
237
  };
196
238
  return (_jsxs(YStack, { flex: 1, minH: 0, overflow: "scroll", px: "$6", py: "$6", "$max-md": { px: '$4' }, children: [_jsxs(YStack, { width: "100%", maxW: 1040, mx: "auto", gap: "$4", children: [_jsxs(XStack, { justify: "space-between", items: "flex-start", gap: "$4", flexWrap: "wrap", children: [_jsxs(YStack, { gap: "$1", flex: 1, minW: 240, children: [_jsx(SizableText, { render: "h1", size: "$6", fontWeight: "500", color: "$ink", children: t('Projects') }), _jsx(SizableText, { size: "$2", color: "$soft", children: host.org
197
239
  ? t('{org}’s projects and linked GitHub repositories. Open one to work on it.', { org: host.org })
198
- : t('Projects and linked GitHub repositories. Open one to work on it.') })] }), signed ? (_jsxs(XStack, { gap: "$2", items: "center", flexWrap: "wrap", children: [_jsxs(Button, { size: "sm", variant: "outline", onPress: template, children: [_jsx(LayoutTemplate, { size: 14 }), t('Create from template')] }), _jsxs(Button, { size: "sm", variant: none ? 'outline' : 'primary', borderColor: none ? 'var(--border-strong)' : undefined, onPress: link, children: [_jsx(Github, { size: 14 }), t('Link a GitHub repo')] })] })) : null] }), signed ? _jsx(GitHubLink, { onSync: link }) : null, said ? (_jsx(SizableText, { size: "$2", color: saidError ? 'var(--state-error)' : '$soft', role: "status", children: said })) : null, list.error ? (_jsxs(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$4", bg: "$panel", px: "$5", py: "$8", gap: "$3", items: "center", children: [_jsx(SizableText, { size: "$2", color: "var(--state-error)", text: "center", children: list.error.message }), _jsx(Button, { size: "sm", variant: "outline", onPress: list.reload, children: t('Try again') })] })) : !signed ? (_jsxs(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$4", bg: "$panel", px: "$5", py: "$8", gap: "$3", items: "center", children: [_jsx(SizableText, { size: "$2", color: "$soft", text: "center", children: t("Sign in to see this organization's projects.") }), _jsx(Button, { size: "sm", variant: "primary", onPress: () => host.signIn?.(), children: t('Sign in') })] })) : list.loading && list.value.length === 0 && pending.length === 0 ? (_jsxs(YStack, { gap: "$3", "aria-busy": true, children: [_jsx(Note, { children: t('Loading projects…') }), _jsx(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$3", bg: "$panel", overflow: "hidden", children: [0, 1, 2, 3].map((i) => (_jsxs(XStack, { items: "center", gap: "$3", px: "$3", py: "$3", borderTopWidth: i ? 1 : 0, borderColor: "$borderColor", children: [_jsx(Skeleton, { layout: "block", width: 18, height: 18, rounded: "$2", shrink: 0 }), _jsxs(YStack, { flex: 1, gap: "$1.5", children: [_jsx(Skeleton, { layout: "block", width: "38%", height: 14, rounded: "$2" }), _jsx(Skeleton, { layout: "block", width: "56%", height: 12, rounded: "$2" })] }), _jsx(Skeleton, { layout: "block", width: 64, height: 12, rounded: "$2", shrink: 0 })] }, i))) })] })) : none ? (_jsxs(YStack, { gap: "$4", children: [_jsx(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$4", bg: "$panel", px: "$5", py: "$6", gap: "$1.5", items: "center", children: _jsx(SizableText, { size: "$2", color: "$soft", text: "center", maxW: 460, children: t('No projects yet. A project is a repository: link one from GitHub, or start one from a template.') }) }), _jsxs(XStack, { gap: "$3", flexWrap: "wrap", children: [_jsx(Choice, { label: t('Link a GitHub repo'), icon: _jsx(Github, { size: 20 }), says: t('Mirror repositories you already have. They stay in step with GitHub, and their issues can come too.'), onPress: link }), _jsx(Choice, { label: t('Create from template'), icon: _jsx(LayoutTemplate, { size: 20 }), says: t('Start from a finished product — a site, an app, a store — and make it yours.'), onPress: template })] })] })) : (_jsxs(_Fragment, { children: [_jsxs(XStack, { gap: "$2", items: "center", children: [_jsx(YStack, { flex: 1, "$max-md": { display: 'none' } }), _jsx(YStack, { width: 320, minW: 0, shrink: 1, "$max-md": { width: 'auto', flex: 1 }, children: _jsx(Input, { value: q, onChangeText: setQ, placeholder: t('Find a project…'), "aria-label": t('Find a project'), startAdornment: _jsx(Search, { size: 14, color: "$soft", "aria-hidden": true }), endAdornment: q ? (_jsx(XStack, { render: "button", "aria-label": t('Clear search'), onPress: () => setQ(''), minW: 24, minH: 24, items: "center", justify: "center", focusVisibleStyle: RING, children: _jsx(X, { size: 13, color: "$soft" }) })) : undefined, onKeyDown: (e) => {
240
+ : t('Projects and linked GitHub repositories. Open one to work on it.') })] }), signed ? (_jsxs(XStack, { gap: "$2", items: "center", flexWrap: "wrap", children: [_jsxs(Button, { size: "sm", variant: "outline", onPress: template, children: [_jsx(LayoutTemplate, { size: 14 }), t('Create from template')] }), _jsxs(Button, { size: "sm", variant: none ? 'outline' : 'primary', borderColor: none ? 'var(--border-strong)' : undefined, onPress: link, children: [_jsx(Github, { size: 14 }), t('Link a GitHub repo')] })] })) : null] }), signed ? (_jsx(GitHubLink, { onSync: () => openGitHubModal('browse'), onCreate: () => openGitHubModal('create'), onFork: () => openGitHubModal('fork') })) : null, said ? (_jsx(SizableText, { size: "$2", color: saidError ? 'var(--state-error)' : '$soft', role: "status", children: said })) : null, list.error ? (_jsxs(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$4", bg: "$panel", px: "$5", py: "$8", gap: "$3", items: "center", children: [_jsx(SizableText, { size: "$2", color: "var(--state-error)", text: "center", children: list.error.message }), _jsx(Button, { size: "sm", variant: "outline", onPress: list.reload, children: t('Try again') })] })) : !signed ? (_jsxs(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$4", bg: "$panel", px: "$5", py: "$8", gap: "$3", items: "center", children: [_jsx(SizableText, { size: "$2", color: "$soft", text: "center", children: t("Sign in to see this organization's projects.") }), _jsx(Button, { size: "sm", variant: "primary", onPress: () => host.signIn?.(), children: t('Sign in') })] })) : list.loading && list.value.length === 0 && pending.length === 0 ? (_jsxs(YStack, { gap: "$3", "aria-busy": true, children: [_jsx(Note, { children: t('Loading projects…') }), _jsx(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$3", bg: "$panel", overflow: "hidden", children: [0, 1, 2, 3].map((i) => (_jsxs(XStack, { items: "center", gap: "$3", px: "$3", py: "$3", borderTopWidth: i ? 1 : 0, borderColor: "$borderColor", children: [_jsx(Skeleton, { layout: "block", width: 18, height: 18, rounded: "$2", shrink: 0 }), _jsxs(YStack, { flex: 1, gap: "$1.5", children: [_jsx(Skeleton, { layout: "block", width: "38%", height: 14, rounded: "$2" }), _jsx(Skeleton, { layout: "block", width: "56%", height: 12, rounded: "$2" })] }), _jsx(Skeleton, { layout: "block", width: 64, height: 12, rounded: "$2", shrink: 0 })] }, i))) })] })) : none ? (_jsxs(YStack, { gap: "$4", children: [_jsx(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$4", bg: "$panel", px: "$5", py: "$6", gap: "$1.5", items: "center", children: _jsx(SizableText, { size: "$2", color: "$soft", text: "center", maxW: 460, children: t('No projects yet. A project is a repository: link one from GitHub, or start one from a template.') }) }), _jsxs(XStack, { gap: "$3", flexWrap: "wrap", children: [_jsx(Choice, { label: t('Link a GitHub repo'), icon: _jsx(Github, { size: 20 }), says: t('Mirror repositories you already have. They stay in step with GitHub, and their issues can come too.'), onPress: link }), _jsx(Choice, { label: t('Create from template'), icon: _jsx(LayoutTemplate, { size: 20 }), says: t('Start from a finished product — a site, an app, a store — and make it yours.'), onPress: template })] })] })) : (_jsxs(_Fragment, { children: [_jsxs(XStack, { gap: "$2", items: "center", children: [_jsx(YStack, { flex: 1, "$max-md": { display: 'none' } }), _jsx(YStack, { width: 320, minW: 0, shrink: 1, "$max-md": { width: 'auto', flex: 1 }, children: _jsx(Input, { value: q, onChangeText: setQ, placeholder: t('Find a project…'), "aria-label": t('Find a project'), startAdornment: _jsx(Search, { size: 14, color: "$soft", "aria-hidden": true }), endAdornment: q ? (_jsx(XStack, { render: "button", "aria-label": t('Clear search'), onPress: () => setQ(''), minW: 24, minH: 24, items: "center", justify: "center", focusVisibleStyle: RING, children: _jsx(X, { size: 13, color: "$soft" }) })) : undefined, onKeyDown: (e) => {
199
241
  if (e.key === 'Escape' && q)
200
242
  setQ('');
201
- } }) })] }), shown.length === 0 ? (_jsxs(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$4", bg: "$panel", px: "$5", py: "$7", gap: "$3", items: "center", children: [_jsx(Note, { children: t('Nothing matches.') }), _jsx(Button, { size: "sm", variant: "outline", onPress: () => setQ(''), children: t('Clear search') })] })) : (_jsxs(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$3", overflow: "hidden", children: [_jsxs(XStack, { px: "$3", py: "$2", gap: "$3", items: "center", bg: "$panel", children: [_jsxs(XStack, { flex: 1, minW: 0, render: "button", "aria-label": t('Sort by name'), items: "center", gap: "$1", onPress: () => setSort('name'), children: [_jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, children: t('Name') }), sort === 'name' ? _jsx(ChevronDown, { size: 12 }) : null] }), _jsx(SizableText, { size: "$1", color: "$soft", width: 120, "$max-md": { display: 'none' }, children: t('Branch') }), _jsxs(XStack, { render: "button", "aria-label": t('Sort by last updated'), items: "center", justify: "flex-end", gap: "$1", width: 120, shrink: 0, "$max-md": { width: 84 }, onPress: () => setSort('updated'), children: [_jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, children: t('Updated') }), sort === 'updated' ? _jsx(ChevronDown, { size: 12 }) : null] }), _jsx(YStack, { width: 32, shrink: 0 })] }), slice.map((c) => {
243
+ } }) })] }), shown.length === 0 ? (_jsxs(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$4", bg: "$panel", px: "$5", py: "$7", gap: "$3", items: "center", children: [_jsx(Note, { children: t('Nothing matches.') }), _jsx(Button, { size: "sm", variant: "outline", onPress: () => setQ(''), children: t('Clear search') })] })) : (_jsxs(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$3", overflow: "hidden", children: [_jsxs(XStack, { px: "$3", py: "$2", gap: "$3", items: "center", bg: "$panel", children: [_jsxs(XStack, { flex: 1, minW: 0, render: "button", "aria-label": t('Sort by name'), items: "center", gap: "$1", onPress: () => setSort('name'), children: [_jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, children: t('Name') }), sort === 'name' ? _jsx(ChevronDown, { size: 12 }) : null] }), _jsx(SizableText, { size: "$1", color: "$soft", width: 120, "$max-md": { display: 'none' }, children: t('Branch') }), _jsxs(XStack, { render: "button", "aria-label": t('Sort by last updated'), items: "center", justify: "flex-end", gap: "$1", width: 120, shrink: 0, "$max-md": { width: 84 }, onPress: () => setSort('updated'), children: [_jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, children: t('Updated') }), sort === 'updated' ? _jsx(ChevronDown, { size: 12 }) : null] }), _jsx(SizableText, { size: "$1", color: "$soft", width: 180, shrink: 0, text: "end", "$max-md": { display: 'none' }, children: "GitHub" }), _jsx(YStack, { width: 32, shrink: 0 })] }), slice.map((c) => {
202
244
  const key = `${c.org}/${c.name}`;
203
245
  const named = `${c.org ? `${c.org}/` : ''}${c.name}`;
204
246
  const r = plan(c);
205
- return (_jsx(YStack, { borderTopWidth: 1, borderColor: "$borderColor", children: _jsxs(XStack, { items: "center", gap: "$3", paddingInlineEnd: "$3", hoverStyle: { bg: '$hover' }, children: [_jsxs(XStack, { render: "button", "aria-label": t('Open {repo}', { repo: named }), onPress: () => open(c), "$platform-web": { textAlign: 'start' }, flex: 1, minW: 0, items: "center", gap: "$3", paddingInlineStart: "$3", py: "$2.5", minH: 44, focusVisibleStyle: RING_INSET, children: [_jsx(XStack, { shrink: 0, children: _jsx(FolderGit2, { size: 15, color: "$soft", "aria-hidden": true }) }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsxs(XStack, { minW: 0, maxW: "100%", overflow: "hidden", items: "baseline", self: "flex-start", 'data-i18n-ltr': '', children: [c.org ? (_jsx(SizableText, { size: "$2", color: "$soft", numberOfLines: 1, shrink: 100, minW: 0, children: `${c.org}/` })) : null, _jsx(SizableText, { size: "$2", color: "$ink", fontWeight: "500", numberOfLines: 1, shrink: 1, minW: 0, children: c.name })] }), c.description ? (_jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, children: c.description })) : null] }), _jsxs(XStack, { width: 120, items: "center", gap: "$1.5", minW: 0, "$max-md": { display: 'none' }, children: [_jsx(GitBranch, { size: 12, color: "$soft" }), _jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, children: c.branch })] }), _jsx(SizableText, { size: "$1", color: "$soft", width: 120, shrink: 0, "$max-md": { width: 84 }, text: "end", numberOfLines: 1, children: syncing.has(c.name) ? t('Syncing…') : ago(c.updated) })] }), _jsx(XStack, { width: 32, shrink: 0, justify: "center", children: _jsx(DropdownMenu, { trigger: _jsx(XStack, { render: "button", "aria-label": t('Actions for {repo}', { repo: named }), disabled: removing, width: 32, height: 32, items: "center", justify: "center", focusVisibleStyle: RING, children: _jsx(MoreHorizontal, { size: 16, color: "$soft" }) }), items: [
247
+ const gh = githubFor(c);
248
+ return (_jsx(YStack, { borderTopWidth: 1, borderColor: "$borderColor", children: _jsxs(XStack, { items: "center", gap: "$3", paddingInlineEnd: "$3", hoverStyle: { bg: '$hover' }, children: [_jsxs(XStack, { render: "button", "aria-label": t('Open {repo}', { repo: named }), onPress: () => open(c), "$platform-web": { textAlign: 'start' }, flex: 1, minW: 0, items: "center", gap: "$3", paddingInlineStart: "$3", py: "$2.5", minH: 44, focusVisibleStyle: RING_INSET, children: [_jsx(XStack, { shrink: 0, children: _jsx(FolderGit2, { size: 15, color: "$soft", "aria-hidden": true }) }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsxs(XStack, { minW: 0, maxW: "100%", overflow: "hidden", items: "baseline", self: "flex-start", 'data-i18n-ltr': '', children: [c.org ? (_jsx(SizableText, { size: "$2", color: "$soft", numberOfLines: 1, shrink: 100, minW: 0, children: `${c.org}/` })) : null, _jsx(SizableText, { size: "$2", color: "$ink", fontWeight: "500", numberOfLines: 1, shrink: 1, minW: 0, children: c.name })] }), c.description ? (_jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, children: c.description })) : null, gh ? (_jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, display: "none", "$max-md": { display: 'flex' }, children: `GitHub · ${gh.fullName}` })) : null] }), _jsxs(XStack, { width: 120, items: "center", gap: "$1.5", minW: 0, "$max-md": { display: 'none' }, children: [_jsx(GitBranch, { size: 12, color: "$soft" }), _jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, children: c.branch })] }), _jsx(SizableText, { size: "$1", color: "$soft", width: 120, shrink: 0, "$max-md": { width: 84 }, text: "end", numberOfLines: 1, children: syncing.has(c.name) ? t('Syncing…') : ago(c.updated) })] }), _jsx(XStack, { width: 180, justify: "flex-end", items: "center", gap: "$2", shrink: 0, "$max-md": { display: 'none' }, children: gh ? (_jsx(GitHubBadge, { fullName: gh.fullName, htmlUrl: gh.htmlUrl, compact: true })) : !syncing.has(c.name) ? (_jsxs(Button, { size: "sm", variant: "outline", "data-slot": "row-sync-github", "aria-label": t('Sync {repo} to GitHub', { repo: c.name }), onPress: () => setSyncTarget(c), children: [_jsx(Github, { size: 13 }), t('Sync to GitHub')] })) : null }), _jsx(XStack, { width: 32, shrink: 0, justify: "center", children: _jsx(DropdownMenu, { trigger: _jsx(XStack, { render: "button", "aria-label": t('Actions for {repo}', { repo: named }), disabled: removing, width: 32, height: 32, items: "center", justify: "center", focusVisibleStyle: RING, children: _jsx(MoreHorizontal, { size: 16, color: "$soft" }) }), items: [
206
249
  { key: 'open', label: t('Open workspace'), icon: _jsx(ArrowRight, { size: 14 }), onSelect: () => open(c) },
250
+ ...(gh
251
+ ? [
252
+ {
253
+ key: 'open-github',
254
+ label: t('Open {repo} on GitHub', { repo: gh.fullName }),
255
+ icon: _jsx(ExternalLink, { size: 14 }),
256
+ onSelect: () => host.open(gh.htmlUrl),
257
+ },
258
+ ]
259
+ : !syncing.has(c.name)
260
+ ? [
261
+ {
262
+ key: 'sync-github',
263
+ label: t('Sync to GitHub'),
264
+ icon: _jsx(Github, { size: 14 }),
265
+ onSelect: () => setSyncTarget(c),
266
+ },
267
+ ]
268
+ : []),
207
269
  { key: 'copy', label: t('Copy repository'), icon: _jsx(Copy, { size: 14 }), onSelect: () => copyRepo(named) },
208
270
  ...(r
209
271
  ? [
@@ -215,7 +277,14 @@ function Projects() {
215
277
  }), _jsxs(XStack, { px: "$3", py: "$2", justify: "space-between", items: "center", gap: "$2", flexWrap: "wrap", borderTopWidth: 1, borderColor: "$borderColor", children: [_jsx(SizableText, { size: "$1", color: "$soft", fontVariant: ['tabular-nums'], children: t('Showing {from}–{to} of {total}', { from, to, total: shown.length }) }), _jsxs(XStack, { gap: "$3", items: "center", children: [_jsx(XStack, { render: "button", "aria-label": t('Previous page'), disabled: safePage === 0, onPress: () => setPage(safePage - 1), children: _jsx(SizableText, { size: "$1", color: safePage === 0 ? '$soft' : '$ink', children: t('Prev') }) }), _jsx(SizableText, { size: "$1", color: "$soft", fontVariant: ['tabular-nums'], children: `${safePage + 1} / ${pages}` }), _jsx(XStack, { render: "button", "aria-label": t('Next page'), disabled: safePage >= pages - 1, onPress: () => setPage(safePage + 1), children: _jsx(SizableText, { size: "$1", color: safePage >= pages - 1 ? '$soft' : '$ink', children: t('Next') }) })] })] })] }))] }))] }), _jsx(Confirm, { open: confirming !== null, onOpenChange: (o) => !o && !removing && setConfirming(null), title: confirming ? t('Remove {repo}?', { repo: confirming.repo }) : t('Remove project?'), says: confirming?.says ?? '', act: t('Remove'), run: async () => {
216
278
  if (confirming)
217
279
  await remove(confirming);
218
- } })] }));
280
+ } }), _jsx(GitHubReposModal, { open: githubModal.open, initialTab: githubModal.tab, onOpenChange: (o) => setGitHubModal((prev) => ({ ...prev, open: o })), onChanged: () => {
281
+ list.reload();
282
+ made.reload();
283
+ setLanded((n) => n + 1);
284
+ } }), syncTarget ? (_jsx(SyncToGitHubDialog, { open: true, onOpenChange: (o) => !o && setSyncTarget(null), repoName: syncTarget.name, defaultName: syncTarget.name, defaultDescription: syncTarget.description, onSynced: (info) => {
285
+ setSyncedMap((prev) => ({ ...prev, [syncTarget.name]: info }));
286
+ setLanded((n) => n + 1);
287
+ } })) : null] }));
219
288
  }
220
289
  /** One of the two ways in, as a card you press. */
221
290
  function Choice({ label, icon, says, onPress }) {
@@ -235,7 +304,7 @@ function Choice({ label, icon, says, onPress }) {
235
304
  * A change made here, in Settings or in the Hanzo app's Quick setup is said on
236
305
  * the window (api/github.ts `changed`), and this line reads it again.
237
306
  */
238
- function GitHubLink({ onSync }) {
307
+ function GitHubLink({ onSync, onCreate, onFork, }) {
239
308
  const host = useHost();
240
309
  const target = useTarget();
241
310
  const { t } = useI18n();
@@ -290,7 +359,7 @@ function GitHubLink({ onSync }) {
290
359
  ? own
291
360
  ? t('Disconnect your GitHub from Hanzo?')
292
361
  : t('Disconnect @{login}? Hanzo’s GitHub App is removed from it too, unless another organization uses it.', { login: c.login })
293
- : note || (c.connected ? t('Choose repositories to mirror; each stays in step with GitHub.') : t('One step on GitHub, then pick the repositories to sync.')) })] }), c.connected && asking ? (_jsxs(XStack, { gap: "$2", children: [_jsx(Button, { size: "sm", variant: "outline", disabled: busy, onPress: () => setAsking(false), children: t('Cancel') }), _jsx(Button, { size: "sm", variant: "primary", disabled: busy, onPress: () => void drop(), children: busy ? t('Disconnecting…') : t('Confirm disconnect') })] })) : c.connected ? (_jsxs(XStack, { gap: "$2", children: [_jsxs(Button, { size: "sm", variant: "outline", onPress: onSync, children: [_jsx(RefreshCw, { size: 14 }), t('Sync repositories')] }), leave ? (_jsx(Button, { size: "sm", variant: "outline", disabled: busy, onPress: () => setAsking(true), children: t('Disconnect') })) : null] })) : (_jsxs(Button, { size: "sm", variant: "primary", disabled: busy, onPress: () => void link(), children: [_jsx(Github, { size: 14 }), busy ? t('Opening GitHub…') : t('Connect GitHub')] }))] }));
362
+ : note || (c.connected ? t('Choose repositories to mirror; each stays in step with GitHub.') : t('One step on GitHub, then pick the repositories to sync.')) })] }), c.connected && asking ? (_jsxs(XStack, { gap: "$2", children: [_jsx(Button, { size: "sm", variant: "outline", disabled: busy, onPress: () => setAsking(false), children: t('Cancel') }), _jsx(Button, { size: "sm", variant: "primary", disabled: busy, onPress: () => void drop(), children: busy ? t('Disconnecting…') : t('Confirm disconnect') })] })) : c.connected ? (_jsxs(XStack, { gap: "$2", flexWrap: "wrap", children: [_jsxs(Button, { size: "sm", variant: "outline", onPress: onSync, children: [_jsx(RefreshCw, { size: 14 }), t('Sync repositories')] }), onCreate ? (_jsxs(Button, { size: "sm", variant: "outline", onPress: onCreate, children: [_jsx(Plus, { size: 14 }), t('Create new repo')] })) : null, onFork ? (_jsxs(Button, { size: "sm", variant: "outline", onPress: onFork, children: [_jsx(GitFork, { size: 14 }), t('Fork repo')] })) : null, leave ? (_jsx(Button, { size: "sm", variant: "outline", disabled: busy, onPress: () => setAsking(true), children: t('Disconnect') })) : null] })) : (_jsxs(Button, { size: "sm", variant: "primary", disabled: busy, onPress: () => void link(), children: [_jsx(Github, { size: 14 }), busy ? t('Opening GitHub…') : t('Connect GitHub')] }))] }));
294
363
  }
295
364
  /** The menus' words, marked (`phrase`) and drawn through `t`; GitHub and Hanzo are names, drawn as given. */
296
365
  const KINDS = { all: phrase('Issues and pull requests'), issue: phrase('Issues'), pr: phrase('Pull requests') };
@@ -0,0 +1,70 @@
1
+ import { type CreatedRepo, type GitHubRepoBadgeInfo } from './api/github.ts';
2
+ /**
3
+ * Crisp monochrome GitHub badge/link (`owner/repo ↗`) with optional sync status.
4
+ */
5
+ export declare function GitHubBadge({ fullName, htmlUrl, syncedLabel, compact, }: {
6
+ fullName: string;
7
+ htmlUrl: string;
8
+ syncedLabel?: string;
9
+ compact?: boolean;
10
+ }): import("react").JSX.Element;
11
+ /**
12
+ * 1-click user OAuth fallback callout shown when creating/forking under a
13
+ * personal GitHub account returns HTTP 412 or 409.
14
+ */
15
+ export declare function GitHubOAuthCallout({ message, label, }: {
16
+ message?: string;
17
+ label?: string;
18
+ }): import("react").JSX.Element;
19
+ /**
20
+ * Form to create a new GitHub repository (`POST /v1/provider/github/repos`).
21
+ * Handles 412/409 personal account OAuth requirement with a 1-click CTA.
22
+ */
23
+ export declare function CreateGitHubRepoForm({ defaultName, defaultDescription, linkRepo, orgs, submitLabel, oauthLabel, onCreated, onCancel, }: {
24
+ defaultName?: string;
25
+ defaultDescription?: string;
26
+ /** Hanzo Git repo slug to link and push immediately after creation. */
27
+ linkRepo?: string;
28
+ orgs?: string[];
29
+ submitLabel?: string;
30
+ oauthLabel?: string;
31
+ onCreated: (repo: CreatedRepo) => void | Promise<void>;
32
+ onCancel?: () => void;
33
+ }): import("react").JSX.Element;
34
+ /**
35
+ * Form to fork a GitHub repository (`POST /v1/provider/github/fork`).
36
+ * Supports `owner/repo`, GitHub URLs, and bare repository names.
37
+ */
38
+ export declare function ForkGitHubRepoForm({ orgs, submitLabel, onForked, onCancel, }: {
39
+ orgs?: string[];
40
+ submitLabel?: string;
41
+ onForked: (repo: CreatedRepo) => void | Promise<void>;
42
+ onCancel?: () => void;
43
+ }): import("react").JSX.Element;
44
+ /**
45
+ * Dialog to sync a Hanzo Git project to GitHub:
46
+ * - Create & sync a new GitHub repository (`POST /v1/provider/github/repos` with `linkRepo`), OR
47
+ * - Link an existing GitHub repository URL (`POST /v1/git/repos/:name/targets`).
48
+ */
49
+ export declare function SyncToGitHubDialog({ open, onOpenChange, repoName, defaultName, defaultDescription, onSynced, }: {
50
+ open: boolean;
51
+ onOpenChange: (open: boolean) => void;
52
+ repoName: string;
53
+ defaultName?: string;
54
+ defaultDescription?: string;
55
+ onSynced: (info: GitHubRepoBadgeInfo) => void;
56
+ }): import("react").JSX.Element;
57
+ /**
58
+ * Modal/drawer experience for "Link a GitHub repo" / "Sync repositories" on `/dev/projects`:
59
+ * - When connected with 0 repositories, presents first-class "Create a new GitHub repository"
60
+ * and "Fork a GitHub repository" actions instead of a dead-end empty state.
61
+ * - When repositories are listed, provides instant search, 1-click "Import & edit in /dev",
62
+ * and clean access to "Create new repo" and "Fork repo".
63
+ * - Responsive from 390px mobile to 1440px desktop with zero overlap.
64
+ */
65
+ export declare function GitHubReposModal({ open, onOpenChange, initialTab, onChanged, }: {
66
+ open: boolean;
67
+ onOpenChange: (open: boolean) => void;
68
+ initialTab?: 'browse' | 'create' | 'fork';
69
+ onChanged?: () => void;
70
+ }): import("react").JSX.Element;
@@ -0,0 +1,435 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * GitHub repository creation, public `owner/repo` forking, outbound mirror sync,
4
+ * and repository import modal for `/dev`.
5
+ *
6
+ * Follows the monochrome design system (`@hanzo/gui`, `@hanzo/ui`, `@hanzo/i18n`)
7
+ * and works cleanly from mobile (`390px`) to desktop (`1440px`).
8
+ */
9
+ import { SizableText, XStack, YStack } from '@hanzo/gui';
10
+ import { useI18n } from '@hanzo/i18n/react';
11
+ import { ArrowRight, ArrowUpRight, GitBranch, GitFork, Github, Globe, Link2, Lock, Plus, Search, X, } from '@hanzogui/lucide-icons-2';
12
+ import { Button, Dialog, DialogContent, DialogDescription, DialogTitle, Input, Skeleton, toast } from '@hanzo/ui';
13
+ import { useEffect, useId, useMemo, useState } from 'react';
14
+ import { here } from './back.js';
15
+ import { told } from './api/call.js';
16
+ import { codebases } from './api/codebases.js';
17
+ import { attachGitHubMirror, bring, connect, connection, createGitHubRepo, forkGitHubRepo, installations, isGitHubUserOAuthRequired, parseGitHubRepo, repos as listGitHubRepos, } from './api/github.js';
18
+ import { links } from './api/links.js';
19
+ import { authorize, read as readProvider } from './api/provider.js';
20
+ import { pinHub, readPending, writePending } from './choice.js';
21
+ import { useRead } from './data.js';
22
+ import { useHost, useTarget } from './host.js';
23
+ import { Out } from './out.js';
24
+ import { RING } from './pane.js';
25
+ import { path } from './route.js';
26
+ const EMPTY_REPOS = { repos: [], next: '', total: 0, unread: [], connected: false };
27
+ /**
28
+ * Crisp monochrome GitHub badge/link (`owner/repo ↗`) with optional sync status.
29
+ */
30
+ export function GitHubBadge({ fullName, htmlUrl, syncedLabel, compact = false, }) {
31
+ const { t } = useI18n();
32
+ return (_jsx(XStack, { "data-slot": "github-badge", "data-repo": fullName, items: "center", rounded: 999, borderWidth: 1, borderColor: "$borderColor", bg: "$panel", px: "$2", py: "$0.5", minH: 26, minW: 0, shrink: 1, maxW: compact ? 180 : 240, "$max-md": { maxW: compact ? 132 : 180 }, hoverStyle: { bg: '$hover' }, children: _jsx(Out, { href: htmlUrl, label: t('Open {repo} on GitHub', { repo: fullName }), children: _jsxs(XStack, { items: "center", gap: "$1.5", minW: 0, maxW: "100%", 'data-i18n-ltr': '', children: [_jsx(Github, { size: 12, color: "$ink", "aria-hidden": true }), _jsx(SizableText, { size: "$1", color: "$ink", fontWeight: "500", numberOfLines: 1, minW: 0, shrink: 1, children: fullName }), syncedLabel && !compact ? (_jsx(SizableText, { size: "$1", color: "$soft", shrink: 0, "$max-md": { display: 'none' }, children: `· ${syncedLabel}` })) : null, _jsx(ArrowUpRight, { size: 11, color: "$soft", "aria-hidden": true })] }) }) }));
33
+ }
34
+ /**
35
+ * 1-click user OAuth fallback callout shown when creating/forking under a
36
+ * personal GitHub account returns HTTP 412 or 409.
37
+ */
38
+ export function GitHubOAuthCallout({ message, label, }) {
39
+ const host = useHost();
40
+ const target = useTarget();
41
+ const { t } = useI18n();
42
+ const [busy, setBusy] = useState(false);
43
+ const [err, setErr] = useState('');
44
+ const authorizeUser = async () => {
45
+ setBusy(true);
46
+ setErr('');
47
+ try {
48
+ const url = await connect(target, here());
49
+ host.open(url);
50
+ }
51
+ catch (e) {
52
+ setErr(told(e, t));
53
+ setBusy(false);
54
+ }
55
+ };
56
+ return (_jsxs(YStack, { "data-slot": "github-oauth-fallback", role: "alert", gap: "$2", px: "$3", py: "$2.5", rounded: "$3", borderWidth: 1, borderColor: "var(--border-strong)", bg: "$panel", children: [_jsx(SizableText, { size: "$2", color: "$ink", children: message || t('Authorize your personal GitHub account to create or fork repositories.') }), err ? (_jsx(SizableText, { size: "$1", color: "var(--state-error)", children: err })) : null, _jsx(XStack, { children: _jsxs(Button, { size: "sm", variant: "primary", "data-slot": "github-oauth-cta", "aria-label": label || t('Authorize GitHub account'), disabled: busy, onPress: () => void authorizeUser(), children: [_jsx(Github, { size: 14 }), busy ? t('Opening GitHub…') : label || t('Authorize GitHub account')] }) })] }));
57
+ }
58
+ /**
59
+ * Segmented toggle pill button used for tabs and visibility switches.
60
+ */
61
+ function SegmentButton({ active, label, icon, role, onPress, disabled = false, dataSlot, }) {
62
+ return (_jsxs(XStack, { render: "button", "data-slot": dataSlot, role: role, "aria-selected": role === 'tab' ? active : undefined, "aria-pressed": role !== 'tab' ? active : undefined, "aria-label": label, disabled: disabled, onPress: onPress, items: "center", justify: "center", gap: "$1.5", px: "$3", py: "$1.5", minH: 36, rounded: "$3", borderWidth: 1, borderColor: active ? '$ink' : '$borderColor', bg: active ? '$ink' : '$panel', cursor: disabled ? 'default' : 'pointer', opacity: disabled ? 0.6 : 1, focusVisibleStyle: RING, children: [icon, _jsx(SizableText, { size: "$2", fontWeight: active ? '500' : '400', color: active ? '$background' : '$ink', numberOfLines: 1, children: label })] }));
63
+ }
64
+ /**
65
+ * Form to create a new GitHub repository (`POST /v1/provider/github/repos`).
66
+ * Handles 412/409 personal account OAuth requirement with a 1-click CTA.
67
+ */
68
+ export function CreateGitHubRepoForm({ defaultName = '', defaultDescription = '', linkRepo, orgs = [], submitLabel, oauthLabel, onCreated, onCancel, }) {
69
+ const target = useTarget();
70
+ const { t } = useI18n();
71
+ const id = useId();
72
+ const [name, setName] = useState(defaultName);
73
+ const [description, setDescription] = useState(defaultDescription);
74
+ const [isPrivate, setIsPrivate] = useState(true);
75
+ const [org, setOrg] = useState('');
76
+ const [busy, setBusy] = useState(false);
77
+ const [error, setError] = useState('');
78
+ const [needsOAuth, setNeedsOAuth] = useState(false);
79
+ useEffect(() => {
80
+ setName(defaultName);
81
+ setDescription(defaultDescription);
82
+ setError('');
83
+ setNeedsOAuth(false);
84
+ }, [defaultName, defaultDescription, linkRepo]);
85
+ const submit = async () => {
86
+ const trimmed = name.trim();
87
+ if (!trimmed) {
88
+ setError(t('Enter a repository name.'));
89
+ return;
90
+ }
91
+ setBusy(true);
92
+ setError('');
93
+ setNeedsOAuth(false);
94
+ try {
95
+ const created = await createGitHubRepo(target, {
96
+ name: trimmed,
97
+ description: description.trim() || undefined,
98
+ private: isPrivate,
99
+ org: org || undefined,
100
+ linkRepo,
101
+ });
102
+ await onCreated(created);
103
+ }
104
+ catch (e) {
105
+ if (isGitHubUserOAuthRequired(e)) {
106
+ setNeedsOAuth(true);
107
+ setError(told(e, t));
108
+ }
109
+ else {
110
+ setError(told(e, t));
111
+ }
112
+ }
113
+ finally {
114
+ setBusy(false);
115
+ }
116
+ };
117
+ return (_jsxs(YStack, { "data-slot": "create-github-repo-form", gap: "$3", children: [_jsxs(YStack, { gap: "$1.5", children: [_jsx(SizableText, { render: "label", size: "$2", color: "$soft", htmlFor: `${id}-name`, children: t('Repository name') }), _jsx(Input, { id: `${id}-name`, value: name, onChangeText: setName, placeholder: "my-project", "aria-label": t('Repository name'), disabled: busy, onKeyDown: (e) => {
118
+ if (e.key === 'Enter')
119
+ void submit();
120
+ } })] }), _jsxs(YStack, { gap: "$1.5", children: [_jsx(SizableText, { render: "label", size: "$2", color: "$soft", htmlFor: `${id}-desc`, children: t('Description') }), _jsx(Input, { id: `${id}-desc`, value: description, onChangeText: setDescription, placeholder: t('Short description (optional)'), "aria-label": t('Description'), disabled: busy, onKeyDown: (e) => {
121
+ if (e.key === 'Enter')
122
+ void submit();
123
+ } })] }), _jsxs(YStack, { gap: "$1.5", children: [_jsx(SizableText, { size: "$2", color: "$soft", children: t('Visibility') }), _jsxs(XStack, { gap: "$2", flexWrap: "wrap", role: "group", "aria-label": t('Visibility'), children: [_jsx(SegmentButton, { dataSlot: "visibility-private", active: isPrivate, label: t('Private'), icon: _jsx(Lock, { size: 13, color: isPrivate ? '$background' : '$ink' }), disabled: busy, onPress: () => setIsPrivate(true) }), _jsx(SegmentButton, { dataSlot: "visibility-public", active: !isPrivate, label: t('Public'), icon: _jsx(Globe, { size: 13, color: !isPrivate ? '$background' : '$ink' }), disabled: busy, onPress: () => setIsPrivate(false) })] })] }), orgs.length > 0 ? (_jsxs(YStack, { gap: "$1.5", children: [_jsx(SizableText, { size: "$2", color: "$soft", children: t('Owner') }), _jsxs(XStack, { gap: "$1.5", flexWrap: "wrap", role: "group", "aria-label": t('Owner'), children: [_jsx(SegmentButton, { active: org === '', label: t('Personal account'), disabled: busy, onPress: () => setOrg('') }), orgs.map((o) => (_jsx(SegmentButton, { active: org === o, label: o, disabled: busy, onPress: () => setOrg(o) }, o)))] })] })) : null, needsOAuth ? (_jsx(GitHubOAuthCallout, { message: error || t('Your personal GitHub account needs authorization before creating repositories.'), label: oauthLabel })) : error ? (_jsx(SizableText, { size: "$2", color: "var(--state-error)", role: "alert", children: error })) : null, _jsxs(XStack, { gap: "$2", justify: "flex-end", flexWrap: "wrap", children: [onCancel ? (_jsx(Button, { size: "sm", variant: "outline", disabled: busy, onPress: onCancel, children: t('Cancel') })) : null, _jsxs(Button, { size: "sm", variant: "primary", "data-slot": "create-github-repo-submit", disabled: busy || !name.trim(), onPress: () => void submit(), children: [_jsx(Plus, { size: 14 }), busy ? t('Creating…') : submitLabel || t('Create repository')] })] })] }));
124
+ }
125
+ /**
126
+ * Form to fork a GitHub repository (`POST /v1/provider/github/fork`).
127
+ * Supports `owner/repo`, GitHub URLs, and bare repository names.
128
+ */
129
+ export function ForkGitHubRepoForm({ orgs = [], submitLabel, onForked, onCancel, }) {
130
+ const target = useTarget();
131
+ const { t } = useI18n();
132
+ const id = useId();
133
+ const [repo, setRepo] = useState('');
134
+ const [name, setName] = useState('');
135
+ const [org, setOrg] = useState('');
136
+ const [busy, setBusy] = useState(false);
137
+ const [error, setError] = useState('');
138
+ const [needsOAuth, setNeedsOAuth] = useState(false);
139
+ const submit = async () => {
140
+ const trimmed = repo.trim();
141
+ if (!trimmed) {
142
+ setError(t('Enter a repository to fork, such as owner/repo.'));
143
+ return;
144
+ }
145
+ setBusy(true);
146
+ setError('');
147
+ setNeedsOAuth(false);
148
+ try {
149
+ const forked = await forkGitHubRepo(target, {
150
+ repo: trimmed,
151
+ org: org || undefined,
152
+ name: name.trim() || undefined,
153
+ });
154
+ await onForked(forked);
155
+ }
156
+ catch (e) {
157
+ if (isGitHubUserOAuthRequired(e)) {
158
+ setNeedsOAuth(true);
159
+ setError(told(e, t));
160
+ }
161
+ else {
162
+ setError(told(e, t));
163
+ }
164
+ }
165
+ finally {
166
+ setBusy(false);
167
+ }
168
+ };
169
+ return (_jsxs(YStack, { "data-slot": "fork-github-repo-form", gap: "$3", children: [_jsxs(YStack, { gap: "$1.5", children: [_jsx(SizableText, { render: "label", size: "$2", color: "$soft", htmlFor: `${id}-repo`, children: t('Repository to fork') }), _jsx(Input, { id: `${id}-repo`, value: repo, onChangeText: setRepo, placeholder: "owner/repo", "aria-label": t('Repository to fork'), disabled: busy, onKeyDown: (e) => {
170
+ if (e.key === 'Enter')
171
+ void submit();
172
+ } }), _jsx(SizableText, { size: "$1", color: "$soft", children: t('Enter any public GitHub repository (e.g. hanzoai/ui) or paste its URL.') })] }), _jsxs(YStack, { gap: "$1.5", children: [_jsx(SizableText, { render: "label", size: "$2", color: "$soft", htmlFor: `${id}-rename`, children: t('New repository name (optional)') }), _jsx(Input, { id: `${id}-rename`, value: name, onChangeText: setName, placeholder: t('Keep original name'), "aria-label": t('New repository name (optional)'), disabled: busy, onKeyDown: (e) => {
173
+ if (e.key === 'Enter')
174
+ void submit();
175
+ } })] }), orgs.length > 0 ? (_jsxs(YStack, { gap: "$1.5", children: [_jsx(SizableText, { size: "$2", color: "$soft", children: t('Fork into') }), _jsxs(XStack, { gap: "$1.5", flexWrap: "wrap", role: "group", "aria-label": t('Fork into'), children: [_jsx(SegmentButton, { active: org === '', label: t('Personal account'), disabled: busy, onPress: () => setOrg('') }), orgs.map((o) => (_jsx(SegmentButton, { active: org === o, label: o, disabled: busy, onPress: () => setOrg(o) }, o)))] })] })) : null, needsOAuth ? (_jsx(GitHubOAuthCallout, { message: error || t('Authorize your personal GitHub account to fork repositories into it.') })) : error ? (_jsx(SizableText, { size: "$2", color: "var(--state-error)", role: "alert", children: error })) : null, _jsxs(XStack, { gap: "$2", justify: "flex-end", flexWrap: "wrap", children: [onCancel ? (_jsx(Button, { size: "sm", variant: "outline", disabled: busy, onPress: onCancel, children: t('Cancel') })) : null, _jsxs(Button, { size: "sm", variant: "primary", "data-slot": "fork-github-repo-submit", disabled: busy || !repo.trim(), onPress: () => void submit(), children: [_jsx(GitFork, { size: 14 }), busy ? t('Forking…') : submitLabel || t('Fork & edit in /dev')] })] })] }));
176
+ }
177
+ /**
178
+ * Dialog to sync a Hanzo Git project to GitHub:
179
+ * - Create & sync a new GitHub repository (`POST /v1/provider/github/repos` with `linkRepo`), OR
180
+ * - Link an existing GitHub repository URL (`POST /v1/git/repos/:name/targets`).
181
+ */
182
+ export function SyncToGitHubDialog({ open, onOpenChange, repoName, defaultName, defaultDescription = '', onSynced, }) {
183
+ const target = useTarget();
184
+ const { t } = useI18n();
185
+ const id = useId();
186
+ const [mode, setMode] = useState('create');
187
+ const [existingUrl, setExistingUrl] = useState('');
188
+ const [busy, setBusy] = useState(false);
189
+ const [error, setError] = useState('');
190
+ const [needsOAuth, setNeedsOAuth] = useState(false);
191
+ const installed = useRead(open ? () => installations(target).catch(() => []) : null, [], [target, open]);
192
+ const orgLogins = useMemo(() => installed.value.filter((i) => i.connected && i.type.toLowerCase() === 'organization').map((i) => i.login), [installed.value]);
193
+ useEffect(() => {
194
+ if (!open)
195
+ return;
196
+ setMode('create');
197
+ setExistingUrl('');
198
+ setError('');
199
+ setNeedsOAuth(false);
200
+ }, [open, repoName]);
201
+ const attachExisting = async () => {
202
+ const at = parseGitHubRepo(existingUrl);
203
+ if (!at) {
204
+ setError(t('Enter a GitHub repository URL or owner/repo (e.g. https://github.com/owner/repo).'));
205
+ return;
206
+ }
207
+ setBusy(true);
208
+ setError('');
209
+ setNeedsOAuth(false);
210
+ try {
211
+ await attachGitHubMirror(target, repoName, existingUrl);
212
+ const fullName = `${at.owner}/${at.name}`;
213
+ const htmlUrl = `https://github.com/${fullName}`;
214
+ toast.success(t('Syncing {repo} to GitHub ({target})', { repo: repoName, target: fullName }));
215
+ onSynced({ owner: at.owner, name: at.name, fullName, htmlUrl, source: 'target' });
216
+ onOpenChange(false);
217
+ }
218
+ catch (e) {
219
+ if (isGitHubUserOAuthRequired(e)) {
220
+ setNeedsOAuth(true);
221
+ setError(told(e, t));
222
+ }
223
+ else {
224
+ setError(told(e, t));
225
+ }
226
+ }
227
+ finally {
228
+ setBusy(false);
229
+ }
230
+ };
231
+ return (_jsx(Dialog, { open: open, onOpenChange: (o) => !busy && onOpenChange(o), children: _jsxs(DialogContent, { "data-slot": "sync-to-github-dialog", width: "100%", maxW: 480, maxH: "85vh", overflow: "scroll", gap: "$3", children: [_jsx(DialogTitle, { children: t('Sync to GitHub') }), _jsx(DialogDescription, { children: t('Push {repo} to a new or existing GitHub repository and keep commits synced.', { repo: repoName }) }), _jsxs(XStack, { role: "tablist", "aria-label": t('Sync method'), gap: "$2", flexWrap: "wrap", children: [_jsx(SegmentButton, { role: "tab", dataSlot: "sync-tab-create", active: mode === 'create', label: t('Create new repo'), icon: _jsx(Plus, { size: 13, color: mode === 'create' ? '$background' : '$ink' }), disabled: busy, onPress: () => {
232
+ setMode('create');
233
+ setError('');
234
+ setNeedsOAuth(false);
235
+ } }), _jsx(SegmentButton, { role: "tab", dataSlot: "sync-tab-link", active: mode === 'link', label: t('Link existing repo'), icon: _jsx(Link2, { size: 13, color: mode === 'link' ? '$background' : '$ink' }), disabled: busy, onPress: () => {
236
+ setMode('link');
237
+ setError('');
238
+ setNeedsOAuth(false);
239
+ } })] }), mode === 'create' ? (_jsx(CreateGitHubRepoForm, { defaultName: defaultName || repoName, defaultDescription: defaultDescription, linkRepo: repoName, orgs: orgLogins, submitLabel: t('Create & sync to GitHub'), oauthLabel: t('Authorize GitHub to create repos'), onCancel: () => onOpenChange(false), onCreated: (created) => {
240
+ const parts = created.full_name.split('/');
241
+ const owner = parts[0] ?? '';
242
+ const name = parts[1] ?? created.full_name;
243
+ toast.success(t('Synced to {repo} on GitHub', { repo: created.full_name }));
244
+ onSynced({
245
+ owner,
246
+ name,
247
+ fullName: created.full_name,
248
+ htmlUrl: created.html_url || `https://github.com/${created.full_name}`,
249
+ source: 'target',
250
+ });
251
+ onOpenChange(false);
252
+ } })) : (_jsxs(YStack, { "data-slot": "link-existing-github-form", gap: "$3", children: [_jsxs(YStack, { gap: "$1.5", children: [_jsx(SizableText, { render: "label", size: "$2", color: "$soft", htmlFor: `${id}-url`, children: t('GitHub repository') }), _jsx(Input, { id: `${id}-url`, value: existingUrl, onChangeText: setExistingUrl, placeholder: "https://github.com/owner/repo", "aria-label": t('GitHub repository URL'), disabled: busy, onKeyDown: (e) => {
253
+ if (e.key === 'Enter')
254
+ void attachExisting();
255
+ } }), _jsx(SizableText, { size: "$1", color: "$soft", children: t('Attaches an outbound mirror target and triggers an initial sync push.') })] }), needsOAuth ? (_jsx(GitHubOAuthCallout, { message: error || t('Authorize your GitHub account to push to this repository.') })) : error ? (_jsx(SizableText, { size: "$2", color: "var(--state-error)", role: "alert", children: error })) : null, _jsxs(XStack, { gap: "$2", justify: "flex-end", flexWrap: "wrap", children: [_jsx(Button, { size: "sm", variant: "outline", disabled: busy, onPress: () => onOpenChange(false), children: t('Cancel') }), _jsxs(Button, { size: "sm", variant: "primary", "data-slot": "link-existing-github-submit", disabled: busy || !existingUrl.trim(), onPress: () => void attachExisting(), children: [_jsx(Link2, { size: 14 }), busy ? t('Syncing…') : t('Link & sync to GitHub')] })] })] }))] }) }));
256
+ }
257
+ /**
258
+ * Modal/drawer experience for "Link a GitHub repo" / "Sync repositories" on `/dev/projects`:
259
+ * - When connected with 0 repositories, presents first-class "Create a new GitHub repository"
260
+ * and "Fork a GitHub repository" actions instead of a dead-end empty state.
261
+ * - When repositories are listed, provides instant search, 1-click "Import & edit in /dev",
262
+ * and clean access to "Create new repo" and "Fork repo".
263
+ * - Responsive from 390px mobile to 1440px desktop with zero overlap.
264
+ */
265
+ export function GitHubReposModal({ open, onOpenChange, initialTab = 'browse', onChanged, }) {
266
+ const host = useHost();
267
+ const target = useTarget();
268
+ const { t } = useI18n();
269
+ const signed = Boolean(host.person);
270
+ const [tab, setTab] = useState(initialTab);
271
+ const [q, setQ] = useState('');
272
+ const [importing, setImporting] = useState('');
273
+ const [connecting, setConnecting] = useState(false);
274
+ const [error, setError] = useState('');
275
+ const [needsOAuth, setNeedsOAuth] = useState(false);
276
+ useEffect(() => {
277
+ if (!open)
278
+ return;
279
+ setTab(initialTab);
280
+ setQ('');
281
+ setError('');
282
+ setNeedsOAuth(false);
283
+ setImporting('');
284
+ }, [open, initialTab]);
285
+ const me = useRead(open && signed ? () => connection(target).catch(() => null) : null, null, [target, open, signed]);
286
+ const providerConn = useRead(open && signed ? () => readProvider(target, 'github').catch(() => null) : null, null, [target, open, signed]);
287
+ const installed = useRead(open && signed ? () => installations(target).catch(() => []) : null, [], [target, open, signed]);
288
+ const repoPage = useRead(open && signed ? () => listGitHubRepos(target, { limit: 100 }) : null, EMPTY_REPOS, [target, open, signed]);
289
+ const held = useRead(open && signed ? () => codebases(target).catch(() => []) : null, [], [target, open, signed]);
290
+ const syncedLinks = useRead(open && signed ? () => links(target).catch(() => []) : null, [], [target, open, signed]);
291
+ const isConnected = Boolean(me.value?.connected ||
292
+ providerConn.value?.connected ||
293
+ repoPage.value.connected ||
294
+ installed.value.some((i) => i.connected));
295
+ const login = me.value?.login ||
296
+ providerConn.value?.account ||
297
+ installed.value.find((i) => i.connected)?.login ||
298
+ '';
299
+ const orgLogins = useMemo(() => installed.value.filter((i) => i.connected && i.type.toLowerCase() === 'organization').map((i) => i.login), [installed.value]);
300
+ const loading = me.loading || repoPage.loading;
301
+ const heldNames = useMemo(() => new Set(held.value.map((c) => c.name.toLowerCase())), [held.value]);
302
+ const linkedMap = useMemo(() => new Map(syncedLinks.value.map((l) => [`${l.owner}/${l.name}`.toLowerCase(), l])), [syncedLinks.value]);
303
+ const needle = q.trim().toLowerCase();
304
+ const filteredRepos = useMemo(() => repoPage.value.repos.filter((r) => !needle || r.full_name.toLowerCase().includes(needle) || r.name.toLowerCase().includes(needle) || r.owner.toLowerCase().includes(needle)), [repoPage.value.repos, needle]);
305
+ const startConnect = async () => {
306
+ setConnecting(true);
307
+ setError('');
308
+ try {
309
+ host.open(await connect(target, here()));
310
+ }
311
+ catch (e) {
312
+ setError(told(e, t));
313
+ setConnecting(false);
314
+ }
315
+ };
316
+ const installApp = async () => {
317
+ setConnecting(true);
318
+ setError('');
319
+ try {
320
+ host.open(await authorize(target, 'github', here()));
321
+ }
322
+ catch (e) {
323
+ setError(told(e, t));
324
+ setConnecting(false);
325
+ }
326
+ };
327
+ const openCreatedOrForked = async (created, verb) => {
328
+ const [owner = '', name = created.full_name] = created.full_name.split('/');
329
+ try {
330
+ const queued = await bring(target, [created.full_name]);
331
+ const codebaseName = queued.codebases[created.full_name.toLowerCase()] || name;
332
+ const nextPending = [
333
+ ...readPending(host.org).filter((p) => p.fullName.toLowerCase() !== created.full_name.toLowerCase()),
334
+ { fullName: created.full_name, name: codebaseName },
335
+ ];
336
+ writePending(host.org, nextPending);
337
+ }
338
+ catch {
339
+ // Personal OAuth repos can still be edited directly via github.com/owner/repo even without an org mirror.
340
+ }
341
+ pinHub(host.org, {
342
+ owner,
343
+ name,
344
+ private: created.private,
345
+ branch: created.default_branch || 'main',
346
+ });
347
+ toast.success(verb === 'created'
348
+ ? t('Created {repo} on GitHub — opening in Dev', { repo: created.full_name })
349
+ : t('Forked {repo} to GitHub — opening in Dev', { repo: created.full_name }));
350
+ onChanged?.();
351
+ onOpenChange(false);
352
+ host.go('');
353
+ };
354
+ const importAndEdit = async (r) => {
355
+ const existingLink = linkedMap.get(r.full_name.toLowerCase());
356
+ const forgeName = existingLink?.forge || r.codebase || r.name;
357
+ if (heldNames.has(forgeName.toLowerCase())) {
358
+ onOpenChange(false);
359
+ host.go(path({ kind: 'repo', org: host.org || '', name: forgeName }));
360
+ return;
361
+ }
362
+ setImporting(r.full_name);
363
+ setError('');
364
+ setNeedsOAuth(false);
365
+ try {
366
+ const queued = await bring(target, [r.full_name]);
367
+ const codebaseName = queued.codebases[r.full_name.toLowerCase()] || r.codebase || r.name;
368
+ const nextPending = [
369
+ ...readPending(host.org).filter((p) => p.fullName.toLowerCase() !== r.full_name.toLowerCase()),
370
+ { fullName: r.full_name, name: codebaseName },
371
+ ];
372
+ writePending(host.org, nextPending);
373
+ pinHub(host.org, {
374
+ owner: r.owner,
375
+ name: r.name,
376
+ private: r.private,
377
+ branch: r.default_branch || 'main',
378
+ });
379
+ toast.success(t('Importing {repo} — opening in Dev', { repo: r.full_name }));
380
+ onChanged?.();
381
+ onOpenChange(false);
382
+ host.go('');
383
+ }
384
+ catch (e) {
385
+ if (isGitHubUserOAuthRequired(e)) {
386
+ // When user has personal GitHub connected, they can still work directly on github.com/owner/repo.
387
+ if (me.value?.connected) {
388
+ pinHub(host.org, {
389
+ owner: r.owner,
390
+ name: r.name,
391
+ private: r.private,
392
+ branch: r.default_branch || 'main',
393
+ });
394
+ toast.success(t('Opened {repo} in Dev', { repo: r.full_name }));
395
+ onOpenChange(false);
396
+ host.go('');
397
+ return;
398
+ }
399
+ setNeedsOAuth(true);
400
+ setError(told(e, t));
401
+ }
402
+ else {
403
+ setError(told(e, t));
404
+ }
405
+ }
406
+ finally {
407
+ setImporting('');
408
+ }
409
+ };
410
+ return (_jsx(Dialog, { open: open, onOpenChange: (o) => !importing && onOpenChange(o), children: _jsxs(DialogContent, { "data-slot": "github-repos-modal", width: "100%", maxW: 540, maxH: "85vh", overflow: "scroll", gap: "$3", children: [_jsx(XStack, { items: "center", justify: "space-between", gap: "$2", flexWrap: "wrap", children: _jsxs(YStack, { gap: "$0.5", flex: 1, minW: 0, children: [_jsx(DialogTitle, { children: t('GitHub repositories') }), isConnected && login ? (_jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, children: t('Connected as @{login}', { login }) })) : null] }) }), !signed ? (_jsxs(YStack, { gap: "$3", items: "center", py: "$4", children: [_jsx(SizableText, { size: "$2", color: "$soft", text: "center", children: t('Sign in to connect GitHub and work on repositories in Dev.') }), _jsx(Button, { size: "sm", variant: "primary", onPress: () => host.signIn?.(), children: t('Sign in') })] })) : !isConnected && !loading ? (_jsxs(YStack, { "data-slot": "github-not-connected", gap: "$3", py: "$2", children: [_jsx(SizableText, { size: "$2", color: "$soft", children: t('Connect your GitHub account to import, create, or fork repositories right from Dev.') }), error ? (_jsx(SizableText, { size: "$2", color: "var(--state-error)", role: "alert", children: error })) : null, _jsxs(XStack, { gap: "$2", flexWrap: "wrap", children: [_jsxs(Button, { size: "sm", variant: "primary", disabled: connecting, onPress: () => void startConnect(), children: [_jsx(Github, { size: 14 }), connecting ? t('Opening GitHub…') : t('Connect GitHub')] }), host.admin ? (_jsx(Button, { size: "sm", variant: "outline", disabled: connecting, onPress: () => void installApp(), children: t('Install on organization') })) : null] })] })) : (_jsxs(_Fragment, { children: [_jsxs(XStack, { role: "tablist", "aria-label": t('GitHub actions'), gap: "$2", flexWrap: "wrap", children: [_jsx(SegmentButton, { role: "tab", dataSlot: "github-tab-browse", active: tab === 'browse', label: repoPage.value.repos.length > 0
411
+ ? t('Repositories ({n})', { n: repoPage.value.total || repoPage.value.repos.length })
412
+ : t('Repositories'), icon: _jsx(Github, { size: 13, color: tab === 'browse' ? '$background' : '$ink' }), onPress: () => {
413
+ setTab('browse');
414
+ setError('');
415
+ setNeedsOAuth(false);
416
+ } }), _jsx(SegmentButton, { role: "tab", dataSlot: "github-tab-create", active: tab === 'create', label: t('Create new repo'), icon: _jsx(Plus, { size: 13, color: tab === 'create' ? '$background' : '$ink' }), onPress: () => {
417
+ setTab('create');
418
+ setError('');
419
+ setNeedsOAuth(false);
420
+ } }), _jsx(SegmentButton, { role: "tab", dataSlot: "github-tab-fork", active: tab === 'fork', label: t('Fork repo'), icon: _jsx(GitFork, { size: 13, color: tab === 'fork' ? '$background' : '$ink' }), onPress: () => {
421
+ setTab('fork');
422
+ setError('');
423
+ setNeedsOAuth(false);
424
+ } })] }), tab === 'browse' ? (loading && repoPage.value.repos.length === 0 ? (_jsxs(YStack, { gap: "$2", "aria-busy": true, py: "$2", children: [_jsx(SizableText, { size: "$2", color: "$soft", children: t('Reading your GitHub repositories…') }), _jsx(Skeleton, { layout: "block", height: 40, rounded: "$3" }), _jsx(Skeleton, { layout: "block", height: 40, rounded: "$3" }), _jsx(Skeleton, { layout: "block", height: 40, rounded: "$3" })] })) : repoPage.error && repoPage.value.repos.length === 0 ? (_jsxs(YStack, { gap: "$3", py: "$2", children: [_jsx(SizableText, { size: "$2", color: "var(--state-error)", role: "alert", children: told(repoPage.error, t) }), _jsxs(XStack, { gap: "$2", flexWrap: "wrap", children: [_jsx(Button, { size: "sm", variant: "outline", onPress: repoPage.reload, children: t('Try again') }), _jsxs(Button, { size: "sm", variant: "primary", onPress: () => setTab('create'), children: [_jsx(Plus, { size: 14 }), t('Create a new GitHub repository')] }), _jsxs(Button, { size: "sm", variant: "outline", onPress: () => setTab('fork'), children: [_jsx(GitFork, { size: 14 }), t('Fork a GitHub repository')] })] })] })) : repoPage.value.repos.length === 0 ? (_jsxs(YStack, { "data-slot": "github-empty-state", gap: "$3", py: "$2", children: [_jsxs(YStack, { gap: "$1", children: [_jsx(SizableText, { size: "$3", fontWeight: "500", color: "$ink", children: t('No repositories on GitHub yet') }), _jsx(SizableText, { size: "$2", color: "$soft", children: login
425
+ ? t('Your GitHub account (@{login}) has 0 repositories right now. Create a new repository or fork any public owner/repo to start editing in Dev.', { login })
426
+ : t('Your connected GitHub account has 0 repositories right now. Create a new repository or fork any public owner/repo to start editing in Dev.') })] }), _jsxs(XStack, { gap: "$2.5", flexWrap: "wrap", children: [_jsxs(YStack, { render: "button", "data-slot": "empty-create-github-repo", "aria-label": t('Create a new GitHub repository'), onPress: () => setTab('create'), flex: 1, flexBasis: 200, minW: 0, gap: "$1.5", p: "$3.5", rounded: "$4", borderWidth: 1, borderColor: "$borderColor", bg: "$panel", items: "flex-start", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, "$platform-web": { textAlign: 'start' }, children: [_jsx(Plus, { size: 18, color: "$ink" }), _jsx(SizableText, { size: "$3", fontWeight: "500", color: "$ink", children: t('Create a new GitHub repository') }), _jsx(SizableText, { size: "$1", color: "$soft", children: t('Name, description, and visibility — created on GitHub and opened in Dev.') })] }), _jsxs(YStack, { render: "button", "data-slot": "empty-fork-github-repo", "aria-label": t('Fork a GitHub repository'), onPress: () => setTab('fork'), flex: 1, flexBasis: 200, minW: 0, gap: "$1.5", p: "$3.5", rounded: "$4", borderWidth: 1, borderColor: "$borderColor", bg: "$panel", items: "flex-start", hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, "$platform-web": { textAlign: 'start' }, children: [_jsx(GitFork, { size: 18, color: "$ink" }), _jsx(SizableText, { size: "$3", fontWeight: "500", color: "$ink", children: t('Fork a GitHub repository') }), _jsx(SizableText, { size: "$1", color: "$soft", children: t('Fork any public owner/repo to your GitHub and edit it in Dev.') })] })] }), host.admin ? (_jsx(XStack, { children: _jsx(Button, { size: "sm", variant: "ghost", disabled: connecting, onPress: () => void installApp(), children: t('Grant access to more repositories on GitHub') }) })) : null] })) : (_jsxs(YStack, { "data-slot": "github-repo-list", gap: "$2.5", children: [_jsx(Input, { value: q, onChangeText: setQ, placeholder: t('Search repositories…'), "aria-label": t('Search repositories'), startAdornment: _jsx(Search, { size: 14, color: "$soft", "aria-hidden": true }), endAdornment: q ? (_jsx(XStack, { render: "button", "aria-label": t('Clear search'), onPress: () => setQ(''), minW: 24, minH: 24, items: "center", justify: "center", focusVisibleStyle: RING, children: _jsx(X, { size: 13, color: "$soft" }) })) : undefined }), needsOAuth ? (_jsx(GitHubOAuthCallout, { message: error })) : error ? (_jsx(SizableText, { size: "$2", color: "var(--state-error)", role: "alert", children: error })) : null, _jsx(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$3", maxH: 320, overflow: "scroll", children: filteredRepos.length === 0 ? (_jsxs(YStack, { p: "$4", gap: "$2", items: "center", children: [_jsx(SizableText, { size: "$2", color: "$soft", children: t('Nothing matches.') }), _jsx(Button, { size: "sm", variant: "outline", onPress: () => setQ(''), children: t('Clear search') })] })) : (filteredRepos.map((r, i) => {
427
+ const existingLink = linkedMap.get(r.full_name.toLowerCase());
428
+ const forgeName = existingLink?.forge || r.codebase || r.name;
429
+ const onForge = heldNames.has(forgeName.toLowerCase());
430
+ const isBusy = importing === r.full_name;
431
+ return (_jsxs(XStack, { items: "center", gap: "$2.5", px: "$3", py: "$2.5", minH: 48, borderTopWidth: i ? 1 : 0, borderColor: "$borderColor", hoverStyle: { bg: '$hover' }, flexWrap: "wrap", children: [_jsxs(XStack, { items: "center", gap: "$2", flex: 1, minW: 160, children: [r.private ? _jsx(Lock, { size: 14, color: "$soft", "aria-hidden": true }) : _jsx(Globe, { size: 14, color: "$soft", "aria-hidden": true }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(SizableText, { size: "$2", color: "$ink", fontWeight: "500", numberOfLines: 1, 'data-i18n-ltr': '', children: r.full_name }), r.default_branch ? (_jsxs(XStack, { items: "center", gap: "$1", children: [_jsx(GitBranch, { size: 10, color: "$soft", "aria-hidden": true }), _jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, children: r.default_branch })] })) : null] })] }), _jsxs(Button, { size: "sm", variant: onForge ? 'outline' : 'primary', "data-slot": "import-edit-repo", "aria-label": onForge
432
+ ? t('Open {repo} in /dev', { repo: r.full_name })
433
+ : t('Import & edit {repo} in /dev', { repo: r.full_name }), disabled: Boolean(importing), onPress: () => void importAndEdit(r), shrink: 0, children: [isBusy ? t('Importing…') : onForge ? t('Open in /dev') : t('Import & edit in /dev'), !isBusy ? _jsx(ArrowRight, { size: 13 }) : null] })] }, r.full_name));
434
+ })) })] }))) : tab === 'create' ? (_jsx(CreateGitHubRepoForm, { orgs: orgLogins, submitLabel: t('Create & edit in /dev'), onCreated: (r) => openCreatedOrForked(r, 'created'), onCancel: () => setTab('browse') })) : (_jsx(ForkGitHubRepoForm, { orgs: orgLogins, submitLabel: t('Fork & edit in /dev'), onForked: (r) => openCreatedOrForked(r, 'forked'), onCancel: () => setTab('browse') }))] }))] }) }));
435
+ }
@@ -44,7 +44,7 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
44
44
  */
45
45
  import { SizableText, useMedia, XStack, YStack } from '@hanzo/gui';
46
46
  import { useI18n } from '@hanzo/i18n/react';
47
- import { AlertCircle, Check, Clock, ExternalLink, Globe, MousePointerClick, PanelLeft, RefreshCcw, Search, Share2, Square, Upload, } from '@hanzogui/lucide-icons-2';
47
+ import { AlertCircle, Check, Clock, ExternalLink, Github, Globe, MousePointerClick, PanelLeft, RefreshCcw, Search, Share2, Square, Upload, } from '@hanzogui/lucide-icons-2';
48
48
  import { Attachments, CHAT, Console, DEVICES, Feedback, FileTabs, FileTree, PageSelect, PreviewFrame, ProjectChip, VIEWS, Views, Workspace, fold, } from '@hanzo/ui/agents';
49
49
  import { Composer, Message } from '@hanzo/ui/chat';
50
50
  import { Button, Dialog, DialogContent, DialogTitle, Input, Skeleton, toast } from '@hanzo/ui';
@@ -57,7 +57,8 @@ import { RING } from './pane.js';
57
57
  import { read as pushed } from './api/changes.js';
58
58
  import { codebases, one } from './api/codebases.js';
59
59
  import { start, steer as steerCoding } from './api/coding.js';
60
- import { blob, tree } from './api/git.js';
60
+ import { blob, listGitTargets, tree } from './api/git.js';
61
+ import { githubRepoFrom } from './api/github.js';
61
62
  import { limits as readLimits } from './api/models.js';
62
63
  import { declare } from './api/platform.js';
63
64
  import { address, deployments, name as repoName, ours, templates } from './api/projects.js';
@@ -67,6 +68,7 @@ import { decode, followed, outcome, pull, said, scrub, who } from './api/turn.js
67
68
  import { verdict as record } from './api/verdict.js';
68
69
  import { useKept, useProjects, useRead, useRun } from './data.js';
69
70
  import { Merge } from './git.js';
71
+ import { GitHubBadge, SyncToGitHubDialog } from './github-sync.js';
70
72
  import { Gutter } from './gutter.js';
71
73
  import { useHost, useTarget } from './host.js';
72
74
  import { cacheBustUrl, previewRevision, resolvePreviewSource } from './preview-url.js';
@@ -321,6 +323,14 @@ export function Project({ at }) {
321
323
  // Files and Code: native git, at the branch the open run pushed (or the project's own).
322
324
  const repo = named ? named.name : project?.repo ? repoName(project.repo) : '';
323
325
  const ref = run.record?.branch || home;
326
+ // Outbound GitHub mirror targets: shows a GitHub badge when synced, or "Sync to GitHub" when Hanzo Git only.
327
+ const gitTargets = useRead(signed && repo ? () => listGitTargets(target, repo).catch(() => []) : null, [], [target, signed, repo]);
328
+ const [syncDialogOpen, setSyncDialogOpen] = useState(false);
329
+ const [syncedGitHub, setSyncedGitHub] = useState(null);
330
+ useEffect(() => {
331
+ setSyncedGitHub(null);
332
+ }, [repo]);
333
+ const githubInfo = useMemo(() => syncedGitHub ?? githubRepoFrom(project?.repo || clone || '', gitTargets.value), [syncedGitHub, project?.repo, clone, gitTargets.value]);
324
334
  const [files, setFiles] = useState([]);
325
335
  const [file, setFile] = useState(null);
326
336
  useEffect(() => {
@@ -566,7 +576,7 @@ export function Project({ at }) {
566
576
  // So below md they take a row of their own under the bar, in whichever pane
567
577
  // shows (one pane at a time there, so one row).
568
578
  const row = wide ? null : (_jsx(XStack, { "data-slot": "views-row", justify: "center", px: "$3", pb: "$2", shrink: 0, minW: 0, overflowX: "auto", "$platform-web": { scrollbarWidth: 'none' }, children: views }));
569
- return (_jsxs(_Fragment, { children: [_jsxs(Workspace, { start: _jsxs(XStack, { items: "center", gap: "$2", minW: 0, shrink: 1, children: [_jsx(XStack, { render: "button", "aria-label": t('All sessions'), ...{ title: t('All sessions') }, onPress: () => host.go(''), p: "$1", "$max-md": { minW: 40, minH: 40, items: 'center', justify: 'center' }, shrink: 0, children: _jsx(HanzoMark, { size: 20 }) }), _jsx(ProjectChip, { name: title, onPress: () => setSwitcher(true) }), _jsx(XStack, { render: "button", "aria-label": t('History'), ...{ title: t('History') }, onPress: () => setHistory(true), p: "$1.5", "$max-md": { minW: 40, minH: 40, items: 'center', justify: 'center' }, rounded: "$3", shrink: 0, hoverStyle: { bg: '$hover' }, children: _jsx(Clock, { size: 16 }) }), _jsx(XStack, { render: "button", "aria-label": shut ? t('Show the chat') : t('Hide the chat'), ...{ title: shut ? t('Show the chat') : t('Hide the chat') }, "aria-pressed": !shut, onClick: () => (cramped ? setAsked(!asked) : setCollapsed(!collapsed)), minW: 32, minH: 32, items: "center", justify: "center", rounded: "$3", shrink: 0, hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, "$max-md": { display: 'none' }, children: _jsx(PanelLeft, { size: 16 }) })] }), middle: wide ? views : undefined, end: _jsxs(XStack, { "data-slot": "project-header-actions", items: "center", gap: "$2", shrink: 0, style: { paddingInlineEnd: 'var(--hanzo-shell-top-right-inset, 0px)' }, children: [_jsx(XStack, { display: "none", $md: { display: 'flex' }, shrink: 0, children: _jsxs(Button, { variant: "outline", size: "sm", onPress: () => void share(), children: [_jsx(Share2, { size: 14 }), " ", t('Share')] }) }), _jsxs(Button, { size: "sm", variant: "primary", "aria-label": t('Publish'), disabled: !clone || !slug, onPress: () => setPublish({ repo: clone, title, ref, name: slug, project: slug, preview: project?.live || undefined }), shrink: 0, children: [_jsx(Upload, { size: 14 }), _jsx(SizableText, { size: "$2", color: "inherit", "$max-md": { display: 'none' }, children: t('Publish') })] })] }), chat: _jsxs(_Fragment, { children: [row, chat] }), dock: _jsx(Console, { lines: lines, height: dock, onHeight: setDock, onClear: () => setPageLines([]), status: run.status || end.status || undefined, label: t('Console') }), collapsed: shut, pane: pane, width: across, onLayout: (e) => setRoom(e.nativeEvent.layout.width), children: [row, preview, body] }), _jsx(Dialog, { open: history, onOpenChange: setHistory, children: _jsxs(DialogContent, { maxW: 480, children: [_jsx(DialogTitle, { children: t('Sessions on {title}', { title }) }), _jsx(YStack, { gap: "$1", children: runs.value.length === 0 ? (_jsx(SizableText, { size: "$2", color: "$soft", children: t('No sessions yet.') })) : (runs.value.map((r) => {
579
+ return (_jsxs(_Fragment, { children: [_jsxs(Workspace, { start: _jsxs(XStack, { items: "center", gap: "$2", minW: 0, shrink: 1, children: [_jsx(XStack, { render: "button", "aria-label": t('All sessions'), ...{ title: t('All sessions') }, onPress: () => host.go(''), p: "$1", "$max-md": { minW: 40, minH: 40, items: 'center', justify: 'center' }, shrink: 0, children: _jsx(HanzoMark, { size: 20 }) }), _jsx(ProjectChip, { name: title, onPress: () => setSwitcher(true) }), _jsx(XStack, { render: "button", "aria-label": t('History'), ...{ title: t('History') }, onPress: () => setHistory(true), p: "$1.5", "$max-md": { minW: 40, minH: 40, items: 'center', justify: 'center' }, rounded: "$3", shrink: 0, hoverStyle: { bg: '$hover' }, children: _jsx(Clock, { size: 16 }) }), _jsx(XStack, { render: "button", "aria-label": shut ? t('Show the chat') : t('Hide the chat'), ...{ title: shut ? t('Show the chat') : t('Hide the chat') }, "aria-pressed": !shut, onClick: () => (cramped ? setAsked(!asked) : setCollapsed(!collapsed)), minW: 32, minH: 32, items: "center", justify: "center", rounded: "$3", shrink: 0, hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, "$max-md": { display: 'none' }, children: _jsx(PanelLeft, { size: 16 }) })] }), middle: wide ? views : undefined, end: _jsxs(XStack, { "data-slot": "project-header-actions", items: "center", gap: "$2", shrink: 0, style: { paddingInlineEnd: 'var(--hanzo-shell-top-right-inset, 0px)' }, children: [githubInfo ? (_jsx(GitHubBadge, { fullName: githubInfo.fullName, htmlUrl: githubInfo.htmlUrl, syncedLabel: t('Synced'), compact: true })) : repo ? (_jsxs(Button, { variant: "outline", size: "sm", "data-slot": "project-sync-github", "aria-label": t('Sync to GitHub'), ...{ title: t('Sync to GitHub') }, onPress: () => setSyncDialogOpen(true), shrink: 0, children: [_jsx(Github, { size: 14 }), _jsx(SizableText, { size: "$2", color: "inherit", "$max-md": { display: 'none' }, children: t('Sync to GitHub') })] })) : null, _jsx(XStack, { display: "none", $md: { display: 'flex' }, shrink: 0, children: _jsxs(Button, { variant: "outline", size: "sm", onPress: () => void share(), children: [_jsx(Share2, { size: 14 }), " ", t('Share')] }) }), _jsxs(Button, { size: "sm", variant: "primary", "aria-label": t('Publish'), disabled: !clone || !slug, onPress: () => setPublish({ repo: clone, title, ref, name: slug, project: slug, preview: project?.live || undefined }), shrink: 0, children: [_jsx(Upload, { size: 14 }), _jsx(SizableText, { size: "$2", color: "inherit", "$max-md": { display: 'none' }, children: t('Publish') })] })] }), chat: _jsxs(_Fragment, { children: [row, chat] }), dock: _jsx(Console, { lines: lines, height: dock, onHeight: setDock, onClear: () => setPageLines([]), status: run.status || end.status || undefined, label: t('Console') }), collapsed: shut, pane: pane, width: across, onLayout: (e) => setRoom(e.nativeEvent.layout.width), children: [row, preview, body] }), _jsx(Dialog, { open: history, onOpenChange: setHistory, children: _jsxs(DialogContent, { maxW: 480, children: [_jsx(DialogTitle, { children: t('Sessions on {title}', { title }) }), _jsx(YStack, { gap: "$1", children: runs.value.length === 0 ? (_jsx(SizableText, { size: "$2", color: "$soft", children: t('No sessions yet.') })) : (runs.value.map((r) => {
570
580
  const active = r.id === current;
571
581
  return (_jsxs(XStack, { render: "button", "aria-current": active ? 'true' : undefined, onPress: () => {
572
582
  setChosen(r.id);
@@ -587,5 +597,8 @@ export function Project({ at }) {
587
597
  setSwitcher(false);
588
598
  setSwitchQ('');
589
599
  host.go(path({ kind: 'screen', screen: 'projects' }));
590
- }, children: t('All projects') })] }) }), _jsx(Publish, { source: publish, onClose: () => setPublish(null), onLive: fresh })] }));
600
+ }, children: t('All projects') })] }) }), _jsx(Publish, { source: publish, onClose: () => setPublish(null), onLive: fresh }), repo ? (_jsx(SyncToGitHubDialog, { open: syncDialogOpen, onOpenChange: setSyncDialogOpen, repoName: repo, defaultName: slug || repo, defaultDescription: forge.value?.description || '', onSynced: (info) => {
601
+ setSyncedGitHub(info);
602
+ gitTargets.reload();
603
+ } })) : null] }));
591
604
  }
@@ -15,8 +15,8 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
15
15
  */
16
16
  import { SizableText, XStack, YStack } from '@hanzo/gui';
17
17
  import { useI18n } from '@hanzo/i18n/react';
18
- import { Check, ChevronLeft, ChevronRight, Plus, X } from '@hanzogui/lucide-icons-2';
19
- import { Button, Input } from '@hanzo/ui';
18
+ import { Check, ChevronLeft, ChevronRight, GitFork, Plus, X } from '@hanzogui/lucide-icons-2';
19
+ import { Button, Input, toast } from '@hanzo/ui';
20
20
  import { useEffect, useMemo, useState } from 'react';
21
21
  import { here, useBack } from './back.js';
22
22
  import { Refusal } from './api/call.js';
@@ -24,6 +24,7 @@ import { accounts, added, bring, grants } from './api/github.js';
24
24
  import { authorize } from './api/provider.js';
25
25
  import { pinHub, readPending, writePending } from './choice.js';
26
26
  import { useRead } from './data.js';
27
+ import { CreateGitHubRepoForm, ForkGitHubRepoForm } from './github-sync.js';
27
28
  import { useHost, useTarget } from './host.js';
28
29
  import { path } from './route.js';
29
30
  const EMPTY = { repos: [], unread: [] };
@@ -115,6 +116,26 @@ export function Sync() {
115
116
  const back = () => {
116
117
  host.go(path({ kind: 'screen', screen: 'projects' }));
117
118
  };
119
+ const openCreatedOrForked = async (created, verb) => {
120
+ const [repoOwner = '', repoName = created.full_name] = created.full_name.split('/');
121
+ try {
122
+ const queued = await bring(target, [created.full_name]);
123
+ const codebaseName = queued.codebases[created.full_name.toLowerCase()] || repoName;
124
+ const next = [
125
+ ...readPending(host.org).filter((p) => p.fullName.toLowerCase() !== created.full_name.toLowerCase()),
126
+ { fullName: created.full_name, name: codebaseName },
127
+ ];
128
+ writePending(host.org, next);
129
+ }
130
+ catch {
131
+ /* direct GitHub editing via pinHub still works */
132
+ }
133
+ pinHub(host.org, { owner: repoOwner, name: repoName, private: created.private, branch: created.default_branch || 'main' });
134
+ toast.success(verb === 'created'
135
+ ? t('Created {repo} on GitHub — opening in Dev', { repo: created.full_name })
136
+ : t('Forked {repo} to GitHub — opening in Dev', { repo: created.full_name }));
137
+ host.go('');
138
+ };
118
139
  useEffect(() => {
119
140
  if (!syncing)
120
141
  return;
@@ -143,11 +164,13 @@ export function Sync() {
143
164
  : t('Nothing matches.') })) : (shownOrgs.map((a) => (_jsxs(XStack, { render: "button", "aria-label": a.blocked ? t('{name} needs an organization admin', { name: a.name }) : t('Open {name}', { name: a.name }), disabled: a.blocked, items: "center", gap: "$2", py: "$2", borderTopWidth: 1, borderColor: "$borderColor", onPress: () => {
144
165
  setOwner(a.name);
145
166
  setQ('');
146
- }, children: [_jsx(SizableText, { flex: 1, size: "$2", color: a.blocked ? '$soft' : '$ink', numberOfLines: 1, children: a.name }), a.blocked ? (_jsx(SizableText, { size: "$1", color: "$soft", children: t('Needs organization admin') })) : (_jsx(ChevronRight, { size: 14, 'data-i18n-mirror': '' }))] }, a.name)))), _jsxs(XStack, { render: "button", "aria-label": t('Add organization'), items: "center", gap: "$2", py: "$2", onPress: () => void addOrg(), disabled: !signed, children: [_jsx(Plus, { size: 14 }), _jsx(SizableText, { size: "$2", color: "$ink", children: t('Add organization') })] })] })] })) : null, step === 'pick' && owner ? (_jsxs(_Fragment, { children: [_jsxs(YStack, { gap: "$1", items: "center", children: [_jsx(SizableText, { size: "$5", color: "$ink", children: t('Select repositories') }), _jsx(SizableText, { size: "$2", color: "$soft", text: "center", children: t('Choose repositories to bring into {place}', { place: dest }) })] }), _jsxs(Panel, { children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(XStack, { render: "button", "aria-label": t('All organizations'), onPress: () => setOwner(''), children: _jsx(ChevronLeft, { size: 16, 'data-i18n-mirror': '' }) }), _jsx(SizableText, { flex: 1, size: "$2", color: "$ink", numberOfLines: 1, children: owner })] }), _jsx(Input, { value: q, onChangeText: setQ, placeholder: t('Search repositories'), "aria-label": t('Search repositories') }), _jsxs(XStack, { justify: "space-between", items: "center", children: [_jsx(SizableText, { size: "$1", color: "$soft", children: ofOwner.length === 1 ? t('1 repository') : t('{n} repositories', { n: ofOwner.length }) }), _jsx(XStack, { render: "button", "aria-label": t('Select all'), onPress: selectShown, disabled: shownRepos.length === 0, children: _jsx(SizableText, { size: "$1", color: "$ink", children: t('Select all') }) })] }), shownRepos.length === 0 ? (_jsx(Soft, { children: t('Nothing matches.') })) : (shownRepos.map((r) => (_jsx(RepoRow, { repo: r, on: picked.includes(r.fullName), onPress: () => toggle(r.fullName) }, r.fullName)))), _jsxs(XStack, { render: "button", "aria-label": t('Grant more repositories'), items: "center", gap: "$2", py: "$2", onPress: () => void addOrg(), children: [_jsx(Plus, { size: 14 }), _jsx(SizableText, { size: "$2", color: "$ink", children: t('Add repositories') })] })] })] })) : null, step === 'access' ? (_jsxs(_Fragment, { children: [_jsxs(YStack, { gap: "$1", items: "center", children: [_jsx(SizableText, { size: "$5", color: "$ink", children: t('Repository access') }), _jsx(SizableText, { size: "$2", color: "$soft", text: "center", children: t('Review who can read these repositories') })] }), _jsxs(XStack, { gap: "$2", items: "center", children: [_jsxs(XStack, { flex: 1, items: "center", gap: "$2", px: "$3", py: "$2", rounded: "$3", borderWidth: 1, borderColor: "$borderColor", children: [_jsx(XStack, { render: "button", "aria-label": t('Clear the selection'), onPress: () => { setPicked([]); setStep('pick'); }, children: _jsx(X, { size: 12 }) }), _jsx(SizableText, { flex: 1, size: "$2", color: "$ink", numberOfLines: 1, children: more ? t('{name}, +{n} more', { name: lead, n: more }) : lead })] }), _jsx(Button, { size: "sm", variant: "outline", onPress: () => setStep('pick'), children: t('Edit') })] }), _jsxs(XStack, { justify: "space-between", gap: "$4", children: [_jsxs(YStack, { gap: "$1", children: [_jsx(SizableText, { size: "$1", color: "$soft", children: t('Who gets access') }), _jsx(SizableText, { size: "$2", color: "$ink", children: t('{name} · You', { name: host.person?.name || host.person?.email || t('You') }) })] }), _jsxs(YStack, { gap: "$1", items: "flex-end", children: [_jsx(SizableText, { size: "$1", color: "$soft", children: t('Role') }), _jsx(SizableText, { size: "$2", color: "$ink", children: host.admin ? t('Repository admin') : t('Member') })] })] }), _jsx(SizableText, { size: "$2", color: "$soft", text: "center", children: t('Anyone with access to {place}', { place: dest }) })] })) : null, error ? _jsx(Soft, { children: error }) : null, unbound && step === 'access' ? (_jsxs(Button, { width: "100%", variant: "outline", onPress: () => void addOrg(), children: [_jsx(Plus, { size: 14 }), t('Add organization')] })) : null, step === 'pick' ? (_jsx(Button, { width: "100%", disabled: !owner || picked.length === 0, onPress: () => setStep('access'), children: t('Continue') })) : (_jsxs(YStack, { gap: "$3", items: "center", width: "100%", children: [_jsx(Button, { width: "100%", disabled: busy || syncing || picked.length === 0, onPress: () => void send(), children: syncing || busy
167
+ }, children: [_jsx(SizableText, { flex: 1, size: "$2", color: a.blocked ? '$soft' : '$ink', numberOfLines: 1, children: a.name }), a.blocked ? (_jsx(SizableText, { size: "$1", color: "$soft", children: t('Needs organization admin') })) : (_jsx(ChevronRight, { size: 14, 'data-i18n-mirror': '' }))] }, a.name)))), _jsxs(XStack, { render: "button", "aria-label": t('Add organization'), items: "center", gap: "$2", py: "$2", onPress: () => void addOrg(), disabled: !signed, children: [_jsx(Plus, { size: 14 }), _jsx(SizableText, { size: "$2", color: "$ink", children: t('Add organization') })] })] })] })) : null, step === 'pick' && owner ? (_jsxs(_Fragment, { children: [_jsxs(YStack, { gap: "$1", items: "center", children: [_jsx(SizableText, { size: "$5", color: "$ink", children: t('Select repositories') }), _jsx(SizableText, { size: "$2", color: "$soft", text: "center", children: t('Choose repositories to bring into {place}', { place: dest }) })] }), _jsxs(Panel, { children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(XStack, { render: "button", "aria-label": t('All organizations'), onPress: () => setOwner(''), children: _jsx(ChevronLeft, { size: 16, 'data-i18n-mirror': '' }) }), _jsx(SizableText, { flex: 1, size: "$2", color: "$ink", numberOfLines: 1, children: owner })] }), _jsx(Input, { value: q, onChangeText: setQ, placeholder: t('Search repositories'), "aria-label": t('Search repositories') }), _jsxs(XStack, { justify: "space-between", items: "center", children: [_jsx(SizableText, { size: "$1", color: "$soft", children: ofOwner.length === 1 ? t('1 repository') : t('{n} repositories', { n: ofOwner.length }) }), _jsx(XStack, { render: "button", "aria-label": t('Select all'), onPress: selectShown, disabled: shownRepos.length === 0, children: _jsx(SizableText, { size: "$1", color: "$ink", children: t('Select all') }) })] }), shownRepos.length === 0 ? (_jsxs(YStack, { gap: "$2.5", py: "$1", children: [_jsx(Soft, { children: ofOwner.length === 0
168
+ ? t('No repositories found under {owner} yet. Create a new repository or fork an existing one.', { owner })
169
+ : t('Nothing matches.') }), ofOwner.length === 0 ? (_jsxs(XStack, { gap: "$2", flexWrap: "wrap", children: [_jsxs(Button, { size: "sm", variant: "primary", onPress: () => setStep('create'), children: [_jsx(Plus, { size: 14 }), t('Create a new GitHub repository')] }), _jsxs(Button, { size: "sm", variant: "outline", onPress: () => setStep('fork'), children: [_jsx(GitFork, { size: 14 }), t('Fork a GitHub repository')] })] })) : null] })) : (shownRepos.map((r) => (_jsx(RepoRow, { repo: r, on: picked.includes(r.fullName), onPress: () => toggle(r.fullName) }, r.fullName)))), _jsxs(XStack, { render: "button", "aria-label": t('Grant more repositories'), items: "center", gap: "$2", py: "$2", onPress: () => void addOrg(), children: [_jsx(Plus, { size: 14 }), _jsx(SizableText, { size: "$2", color: "$ink", children: t('Add repositories') })] })] })] })) : null, step === 'access' ? (_jsxs(_Fragment, { children: [_jsxs(YStack, { gap: "$1", items: "center", children: [_jsx(SizableText, { size: "$5", color: "$ink", children: t('Repository access') }), _jsx(SizableText, { size: "$2", color: "$soft", text: "center", children: t('Review who can read these repositories') })] }), _jsxs(XStack, { gap: "$2", items: "center", children: [_jsxs(XStack, { flex: 1, items: "center", gap: "$2", px: "$3", py: "$2", rounded: "$3", borderWidth: 1, borderColor: "$borderColor", children: [_jsx(XStack, { render: "button", "aria-label": t('Clear the selection'), onPress: () => { setPicked([]); setStep('pick'); }, children: _jsx(X, { size: 12 }) }), _jsx(SizableText, { flex: 1, size: "$2", color: "$ink", numberOfLines: 1, children: more ? t('{name}, +{n} more', { name: lead, n: more }) : lead })] }), _jsx(Button, { size: "sm", variant: "outline", onPress: () => setStep('pick'), children: t('Edit') })] }), _jsxs(XStack, { justify: "space-between", gap: "$4", children: [_jsxs(YStack, { gap: "$1", children: [_jsx(SizableText, { size: "$1", color: "$soft", children: t('Who gets access') }), _jsx(SizableText, { size: "$2", color: "$ink", children: t('{name} · You', { name: host.person?.name || host.person?.email || t('You') }) })] }), _jsxs(YStack, { gap: "$1", items: "flex-end", children: [_jsx(SizableText, { size: "$1", color: "$soft", children: t('Role') }), _jsx(SizableText, { size: "$2", color: "$ink", children: host.admin ? t('Repository admin') : t('Member') })] })] }), _jsx(SizableText, { size: "$2", color: "$soft", text: "center", children: t('Anyone with access to {place}', { place: dest }) })] })) : null, step === 'create' ? (_jsxs(_Fragment, { children: [_jsxs(YStack, { gap: "$1", items: "center", children: [_jsx(SizableText, { size: "$5", color: "$ink", children: t('Create a new GitHub repository') }), _jsx(SizableText, { size: "$2", color: "$soft", text: "center", children: t('Create a repository on GitHub and open it in Dev.') })] }), _jsx(CreateGitHubRepoForm, { orgs: orgs.filter((a) => !a.blocked).map((a) => a.name), submitLabel: t('Create & edit in /dev'), onCancel: () => setStep('pick'), onCreated: (r) => openCreatedOrForked(r, 'created') })] })) : null, step === 'fork' ? (_jsxs(_Fragment, { children: [_jsxs(YStack, { gap: "$1", items: "center", children: [_jsx(SizableText, { size: "$5", color: "$ink", children: t('Fork a GitHub repository') }), _jsx(SizableText, { size: "$2", color: "$soft", text: "center", children: t('Fork any public owner/repo to your GitHub and edit it in Dev.') })] }), _jsx(ForkGitHubRepoForm, { orgs: orgs.filter((a) => !a.blocked).map((a) => a.name), submitLabel: t('Fork & edit in /dev'), onCancel: () => setStep('pick'), onForked: (r) => openCreatedOrForked(r, 'forked') })] })) : null, error ? _jsx(Soft, { children: error }) : null, unbound && step === 'access' ? (_jsxs(Button, { width: "100%", variant: "outline", onPress: () => void addOrg(), children: [_jsx(Plus, { size: 14 }), t('Add organization')] })) : null, step === 'pick' ? (_jsxs(YStack, { gap: "$2.5", width: "100%", children: [_jsx(Button, { width: "100%", disabled: !owner || picked.length === 0, onPress: () => setStep('access'), children: t('Continue') }), signed ? (_jsxs(XStack, { gap: "$2", flexWrap: "wrap", justify: "center", children: [_jsxs(Button, { size: "sm", variant: "outline", onPress: () => setStep('create'), children: [_jsx(Plus, { size: 14 }), t('Create new repo')] }), _jsxs(Button, { size: "sm", variant: "outline", onPress: () => setStep('fork'), children: [_jsx(GitFork, { size: 14 }), t('Fork repo')] })] })) : null] })) : step === 'access' ? (_jsxs(YStack, { gap: "$3", items: "center", width: "100%", children: [_jsx(Button, { width: "100%", disabled: busy || syncing || picked.length === 0, onPress: () => void send(), children: syncing || busy
147
170
  ? t('Syncing…')
148
171
  : picked.length === 1
149
172
  ? t('Sync 1 repository to {place}', { place: dest })
150
- : t('Sync {n} repositories to {place}', { n: picked.length, place: dest }) }), syncing ? null : (_jsx(XStack, { render: "button", "aria-label": t('Sync later'), onPress: back, children: _jsx(SizableText, { size: "$2", color: "$soft", children: t('Sync later') }) }))] })), !signed ? (_jsx(Button, { width: "100%", onPress: () => host.signIn?.(), children: t('Sign in') })) : null] })] })] }));
173
+ : t('Sync {n} repositories to {place}', { n: picked.length, place: dest }) }), syncing ? null : (_jsx(XStack, { render: "button", "aria-label": t('Sync later'), onPress: back, children: _jsx(SizableText, { size: "$2", color: "$soft", children: t('Sync later') }) }))] })) : null, !signed ? (_jsx(Button, { width: "100%", onPress: () => host.signIn?.(), children: t('Sign in') })) : null] })] })] }));
151
174
  }
152
175
  function Step({ label, done, current }) {
153
176
  return (_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(YStack, { width: 14, height: 14, rounded: 999, borderWidth: 1, items: "center", justify: "center", children: done ? _jsx(Check, { size: 10, color: "white" }) : null }), _jsx(SizableText, { size: "$1", color: current || done ? '$ink' : '$soft', children: label })] }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/dev",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "description": "The unified Hanzo Dev & Builder library (Dev core threads/composer/runtime + Builder workspace, sessions, routes, plans, and host providers).",
5
5
  "license": "MIT",
6
6
  "repository": {