@open-mercato/cezar 0.15.0 → 0.15.1

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.
Files changed (212) hide show
  1. package/dist/automations/github-poller.d.ts +8 -1
  2. package/dist/automations/github-poller.js +78 -13
  3. package/dist/automations/github-poller.js.map +1 -1
  4. package/dist/automations/pr-head.js +15 -1
  5. package/dist/automations/pr-head.js.map +1 -1
  6. package/dist/automations/prompts.js +2 -2
  7. package/dist/automations/types.d.ts +10 -0
  8. package/dist/automations/types.js +12 -1
  9. package/dist/automations/types.js.map +1 -1
  10. package/dist/config.d.ts +1 -0
  11. package/dist/config.js +6 -0
  12. package/dist/config.js.map +1 -1
  13. package/dist/contract/automations.d.ts +31 -1
  14. package/dist/contract/index.d.ts +1 -0
  15. package/dist/contract/index.js +161 -17
  16. package/dist/contract/projects.d.ts +46 -0
  17. package/dist/contract/runs.d.ts +15 -0
  18. package/dist/contract/skills.d.ts +1 -0
  19. package/dist/contract/telemetry.d.ts +124 -0
  20. package/dist/contract/workspace.d.ts +3 -0
  21. package/dist/core/cursor-agent-runner.d.ts +11 -0
  22. package/dist/core/cursor-agent-runner.js +48 -4
  23. package/dist/core/cursor-agent-runner.js.map +1 -1
  24. package/dist/core/disclaim-spawn.d.ts +10 -0
  25. package/dist/core/disclaim-spawn.js +105 -8
  26. package/dist/core/disclaim-spawn.js.map +1 -1
  27. package/dist/git-diff-base.js +26 -19
  28. package/dist/git-diff-base.js.map +1 -1
  29. package/dist/git-remotes.d.ts +43 -0
  30. package/dist/git-remotes.js +127 -0
  31. package/dist/git-remotes.js.map +1 -0
  32. package/dist/git-worktree.d.ts +43 -19
  33. package/dist/git-worktree.js +138 -54
  34. package/dist/git-worktree.js.map +1 -1
  35. package/dist/index.js +46 -6
  36. package/dist/index.js.map +1 -1
  37. package/dist/runs/auto-name.d.ts +17 -0
  38. package/dist/runs/auto-name.js +47 -2
  39. package/dist/runs/auto-name.js.map +1 -1
  40. package/dist/runs/event-history.d.ts +10 -2
  41. package/dist/runs/event-history.js +290 -120
  42. package/dist/runs/event-history.js.map +1 -1
  43. package/dist/runs/retention.js +1 -1
  44. package/dist/runs/retention.js.map +1 -1
  45. package/dist/runs/store.d.ts +16 -3
  46. package/dist/runs/store.js +89 -10
  47. package/dist/runs/store.js.map +1 -1
  48. package/dist/server/checkout.d.ts +4 -0
  49. package/dist/server/checkout.js +9 -5
  50. package/dist/server/checkout.js.map +1 -1
  51. package/dist/server/create-project.d.ts +77 -0
  52. package/dist/server/create-project.js +342 -0
  53. package/dist/server/create-project.js.map +1 -0
  54. package/dist/server/forge/github.d.ts +2 -0
  55. package/dist/server/forge/github.js +32 -10
  56. package/dist/server/forge/github.js.map +1 -1
  57. package/dist/server/forge/index.d.ts +1 -12
  58. package/dist/server/forge/index.js +7 -29
  59. package/dist/server/forge/index.js.map +1 -1
  60. package/dist/server/forge/types.d.ts +2 -0
  61. package/dist/server/git-changes.d.ts +15 -0
  62. package/dist/server/git-changes.js +51 -1
  63. package/dist/server/git-changes.js.map +1 -1
  64. package/dist/server/git.d.ts +3 -2
  65. package/dist/server/git.js +4 -3
  66. package/dist/server/git.js.map +1 -1
  67. package/dist/server/project-context.js +1 -1
  68. package/dist/server/project-context.js.map +1 -1
  69. package/dist/server/server.d.ts +609 -302
  70. package/dist/server/server.js +191 -12
  71. package/dist/server/server.js.map +1 -1
  72. package/dist/server/star-count.d.ts +27 -11
  73. package/dist/server/star-count.js +57 -28
  74. package/dist/server/star-count.js.map +1 -1
  75. package/dist/telemetry-cli.d.ts +10 -0
  76. package/dist/telemetry-cli.js +54 -0
  77. package/dist/telemetry-cli.js.map +1 -0
  78. package/dist/telemetry-service.json +1 -0
  79. package/dist/telemetry.d.ts +79 -0
  80. package/dist/telemetry.js +453 -0
  81. package/dist/telemetry.js.map +1 -0
  82. package/dist/workflows/run.d.ts +28 -0
  83. package/dist/workflows/run.js +111 -16
  84. package/dist/workflows/run.js.map +1 -1
  85. package/dist/workspace/config.d.ts +10 -0
  86. package/dist/workspace/config.js +16 -0
  87. package/dist/workspace/config.js.map +1 -1
  88. package/dist/workspace/projects-cli.js +3 -0
  89. package/dist/workspace/projects-cli.js.map +1 -1
  90. package/package.json +3 -3
  91. package/scripts/mock-claude.mjs +32 -17
  92. package/scripts/stamp-telemetry-service.mjs +20 -0
  93. package/web/dist/assets/agent-task-pickers-mJzYn0UB.js +1 -0
  94. package/web/dist/assets/{alert-dialog-CF_-dmQ1.js → alert-dialog-Dd1WPOaz.js} +1 -1
  95. package/web/dist/assets/arrow-left-fsST4JqT.js +1 -0
  96. package/web/dist/assets/{automation-format-D1nqk0ID.js → automation-format-BTIFWfjt.js} +1 -1
  97. package/web/dist/assets/automations-route-DJjhwqug.js +1 -0
  98. package/web/dist/assets/button-BNnH7COh.js +100 -0
  99. package/web/dist/assets/{centered-state-T0J7VmBb.js → centered-state-sEYB3bgq.js} +1 -1
  100. package/web/dist/assets/check-DA37PQLT.js +1 -0
  101. package/web/dist/assets/chevron-left-zbXV2Qbu.js +1 -0
  102. package/web/dist/assets/chevron-right-Beu1pd6H.js +1 -0
  103. package/web/dist/assets/{collapsible-RD4hkew7.js → collapsible-MuXfYnM8.js} +1 -1
  104. package/web/dist/assets/commit-list-Bps23fvP.js +1 -0
  105. package/web/dist/assets/compare-variants-CQskdfDW.js +1 -0
  106. package/web/dist/assets/composer-DKWLJeo9.js +18 -0
  107. package/web/dist/assets/dashboard-BCNe_6p7.js +44 -0
  108. package/web/dist/assets/diff-CrLUECGW.js +3 -0
  109. package/web/dist/assets/{diff-stat-CFoeFye2.js → diff-stat-SpfygteL.js} +1 -1
  110. package/web/dist/assets/diff-view-DP4Gw3QJ.js +13 -0
  111. package/web/dist/assets/{download-BFQEsJRY.js → download-CBwSbmy_.js} +1 -1
  112. package/web/dist/assets/dropdown-menu-CxPGHgWX.js +1 -0
  113. package/web/dist/assets/ellipsis-BmusVE8U.js +1 -0
  114. package/web/dist/assets/{file-Df5WtpM_.js → file-DkvcUwxT.js} +1 -1
  115. package/web/dist/assets/file-preview-DxFusXAO.js +2 -0
  116. package/web/dist/assets/file-text-DBeC0yKb.js +1 -0
  117. package/web/dist/assets/file-tree-BTJZXRkM.js +1 -0
  118. package/web/dist/assets/{git-commit-horizontal-DawNm4qg.js → git-commit-horizontal-BM9_nEW7.js} +1 -1
  119. package/web/dist/assets/git-toolbar-DXyPCDkQ.js +1 -0
  120. package/web/dist/assets/github-G5fU4gJd.js +1 -0
  121. package/web/dist/assets/index-BN3w52uE.js +21 -0
  122. package/web/dist/assets/index-CAvSSpvF.css +2 -0
  123. package/web/dist/assets/{markdown-Bmfy_1Ll.js → markdown-BpZ4p95p.js} +1 -1
  124. package/web/dist/assets/{markdown-B_O1ys3h.js → markdown-C5F95Rt-.js} +1 -1
  125. package/web/dist/assets/{message-square-BOO9s3qX.js → message-square-BFQln9c4.js} +1 -1
  126. package/web/dist/assets/{pill-bO5OcHuK.js → pill-BcIQGDbn.js} +1 -1
  127. package/web/dist/assets/project-router-CWMOKp_H.js +3 -0
  128. package/web/dist/assets/reference-chip-B7lU_Pyh.js +1 -0
  129. package/web/dist/assets/reference-overflow-ClRRXWez.js +1 -0
  130. package/web/dist/assets/{refresh-cw-BaFyjVUz.js → refresh-cw-BBEYC6z2.js} +1 -1
  131. package/web/dist/assets/repo-git-CgxxZ7cO.js +1 -0
  132. package/web/dist/assets/{run-diff-GZbNs8fA.js → run-diff-BTB7nBeD.js} +1 -1
  133. package/web/dist/assets/run-header-BPNBEaOy.js +1 -0
  134. package/web/dist/assets/{image-preview-4SVDrBvn.js → scroll-within-DRt7mAnQ.js} +1 -1
  135. package/web/dist/assets/{search-x-bpAfQtVY.js → search-x-6BavY3mg.js} +1 -1
  136. package/web/dist/assets/sheet-D9PeyyRZ.js +1 -0
  137. package/web/dist/assets/skills-SIMzpL0l.js +1 -0
  138. package/web/dist/assets/square-DsFAQaY9.js +1 -0
  139. package/web/dist/assets/tab-link-DEUSZU49.js +1 -0
  140. package/web/dist/assets/{tag-DLwUkUsN.js → tag-DvCVnA6I.js} +1 -1
  141. package/web/dist/assets/task-changes-D-aajoMU.js +1 -0
  142. package/web/dist/assets/task-commits-BYD1GVkS.js +1 -0
  143. package/web/dist/assets/task-composer-7bdNNMP_.js +12 -0
  144. package/web/dist/assets/task-files-BfIOz-eN.js +1 -0
  145. package/web/dist/assets/task-graph-B5-5_IPh.js +1 -0
  146. package/web/dist/assets/task-notes-CfkTBgo8.js +1 -0
  147. package/web/dist/assets/task-thread-eEkjTDxr.js +10 -0
  148. package/web/dist/assets/{terminal-CwrL1hAi.js → terminal-xRHwWarr.js} +1 -1
  149. package/web/dist/assets/textarea-rKUFh5lI.js +1 -0
  150. package/web/dist/assets/thread-loading-DLlbK51g.js +1 -0
  151. package/web/dist/assets/{token-metrics-C149OWmd.js → token-metrics-BcPjL36-.js} +1 -1
  152. package/web/dist/assets/tooltip-BVqBAGNb.js +1 -0
  153. package/web/dist/assets/tracker-2DfMzsIE.js +4 -0
  154. package/web/dist/assets/triangle-alert-CP3Xp0FU.js +1 -0
  155. package/web/dist/assets/upload-bwO_2kok.js +1 -0
  156. package/web/dist/assets/use-automations-PceYR6ss.js +5 -0
  157. package/web/dist/assets/use-now-BAKdIYLG.js +1 -0
  158. package/web/dist/assets/use-submit-shortcut-BA4NVpJl.js +1 -0
  159. package/web/dist/assets/workflow-graph-HopaWPea.js +13 -0
  160. package/web/dist/assets/x-HaVPcg_B.js +1 -0
  161. package/web/dist/index.html +28 -31
  162. package/web/dist/assets/agent-task-pickers-C3ydGatB.js +0 -1
  163. package/web/dist/assets/arrow-left-BxBdc5DC.js +0 -1
  164. package/web/dist/assets/automations-route-BsflncpV.js +0 -1
  165. package/web/dist/assets/button-CjSjKnkd.js +0 -100
  166. package/web/dist/assets/check-DAAMuI4o.js +0 -1
  167. package/web/dist/assets/chevron-left-CvcqxpQZ.js +0 -1
  168. package/web/dist/assets/chevron-right-DKiL3NWw.js +0 -1
  169. package/web/dist/assets/commit-list-BJac2uO6.js +0 -1
  170. package/web/dist/assets/compare-variants-CfqICvRy.js +0 -1
  171. package/web/dist/assets/composer-DZx3cwQW.js +0 -18
  172. package/web/dist/assets/dashboard-CpCDiZdE.js +0 -44
  173. package/web/dist/assets/diff-LG2cl0PE.js +0 -3
  174. package/web/dist/assets/diff-controls-QgdH-r3F.js +0 -1
  175. package/web/dist/assets/diff-view-BVwSaBb2.js +0 -13
  176. package/web/dist/assets/dropdown-menu-DkEK7m00.js +0 -1
  177. package/web/dist/assets/editable-title-CJSWyCcL.js +0 -1
  178. package/web/dist/assets/ellipsis-vertical-CB0adfr7.js +0 -1
  179. package/web/dist/assets/external-link-DPKRidDg.js +0 -1
  180. package/web/dist/assets/eye-CEHQ0c-s.js +0 -1
  181. package/web/dist/assets/file-preview-kYsqZiLU.js +0 -2
  182. package/web/dist/assets/file-text-m0tZu8sU.js +0 -1
  183. package/web/dist/assets/git-merge-B7oVXcKc.js +0 -1
  184. package/web/dist/assets/git-toolbar-B0K4Q5Zv.js +0 -1
  185. package/web/dist/assets/github-C4WaHPni.js +0 -1
  186. package/web/dist/assets/index-CiQrbvAq.js +0 -21
  187. package/web/dist/assets/index-WWaEax-B.css +0 -2
  188. package/web/dist/assets/pencil-CCR9uUZ1.js +0 -1
  189. package/web/dist/assets/reference-chip-Bx_mG9QG.js +0 -1
  190. package/web/dist/assets/repo-git-Mn3_jrGP.js +0 -1
  191. package/web/dist/assets/run-header-i1D5Lvfs.js +0 -1
  192. package/web/dist/assets/sheet-DCdZVHFk.js +0 -1
  193. package/web/dist/assets/skills-Dea5ynJK.js +0 -1
  194. package/web/dist/assets/tab-link-BVItTl_Y.js +0 -1
  195. package/web/dist/assets/task-changes-xNbBM7FO.js +0 -1
  196. package/web/dist/assets/task-commits-BYozE_X3.js +0 -1
  197. package/web/dist/assets/task-composer-Brx0sa7_.js +0 -12
  198. package/web/dist/assets/task-files-MAPO-efK.js +0 -1
  199. package/web/dist/assets/task-graph-BSLCUr1E.js +0 -1
  200. package/web/dist/assets/task-thread-CRVmwchQ.js +0 -9
  201. package/web/dist/assets/textarea-Bb0_Hz53.js +0 -1
  202. package/web/dist/assets/thread-loading-Bo6IOu3Y.js +0 -1
  203. package/web/dist/assets/toaster-Hj_czp_o.js +0 -3
  204. package/web/dist/assets/tooltip--PYfu68E.js +0 -1
  205. package/web/dist/assets/tracker-DM5WtYD0.js +0 -4
  206. package/web/dist/assets/trash-2-EdjdGvEo.js +0 -1
  207. package/web/dist/assets/triangle-alert-DpH3QFz6.js +0 -1
  208. package/web/dist/assets/use-automations-XKvBTPM-.js +0 -5
  209. package/web/dist/assets/use-now-CrM50BFB.js +0 -1
  210. package/web/dist/assets/use-submit-shortcut-BJ10ZshV.js +0 -1
  211. package/web/dist/assets/workflow-graph-Y2Pr7ubb.js +0 -13
  212. package/web/dist/assets/x-BkwTUDpG.js +0 -1
@@ -0,0 +1,77 @@
1
+ import { type GithubOwnersResponse } from '../contract/index.js';
2
+ import { type CheckoutProgressEvent } from './checkout.ts';
3
+ export type CommandResult = {
4
+ ok: true;
5
+ stdout: string;
6
+ } | {
7
+ ok: false;
8
+ error: string;
9
+ notFound?: boolean;
10
+ };
11
+ /** Run one command (never through a shell). Injected so tests can drive the
12
+ * flow without `gh`, a network, or a git identity. `onLine` receives
13
+ * progress/stderr lines as they arrive. */
14
+ export type CommandRunner = (cmd: 'git' | 'gh', args: string[], opts: {
15
+ cwd: string;
16
+ onLine?: (line: string) => void;
17
+ signal?: AbortSignal | undefined;
18
+ }) => Promise<CommandResult>;
19
+ export declare const spawnCommandRunner: CommandRunner;
20
+ /**
21
+ * `CEZ_DRY_RUN=1` — real `git` (it is local and required anyway), fake `gh`.
22
+ * The fake clone writes only inside the directory the caller created, as a real
23
+ * (`git init`) repo: the `git config --local` that follows must find THIS repo,
24
+ * never walk up past a bare `.git` folder into an enclosing one. `git push`
25
+ * would need a real remote, so it is faked like `gh`.
26
+ */
27
+ export declare const dryRunCommandRunner: CommandRunner;
28
+ /**
29
+ * Where creation stopped — `project_create_failed`'s telemetry label, so a closed set (the route
30
+ * adds `register` for a project that was created but could not be registered). Never the error
31
+ * text: that can carry paths and repository names.
32
+ */
33
+ export type CreateProjectFailureStage = 'invalid_input' | 'checkout_root' | 'folder_exists' | 'gh_missing' | 'cancelled' | 'git_init' | 'github_create' | 'template_clone';
34
+ export type CreateProjectFailure = {
35
+ ok: false;
36
+ status: 400 | 409 | 500;
37
+ error: string;
38
+ stage: CreateProjectFailureStage;
39
+ } | {
40
+ ok: false;
41
+ status: 503;
42
+ error: string;
43
+ reason: string;
44
+ stage: CreateProjectFailureStage;
45
+ };
46
+ /** `kind` — what was created: a local-only repo, an empty GitHub-backed one, or one from a
47
+ * template. `project_added`'s label (`new_<kind>`). */
48
+ export type CreateProjectResult = {
49
+ ok: true;
50
+ target: string;
51
+ name: string;
52
+ slug?: string;
53
+ kind: 'local' | 'github' | 'template';
54
+ } | CreateProjectFailure;
55
+ export interface CreateProjectOptions {
56
+ /** Project name — both the folder name and, with `github`, the repo name. */
57
+ name: string;
58
+ /** Present ⇒ also create a PRIVATE GitHub repository under `owner`. */
59
+ github?: {
60
+ owner: string;
61
+ template?: string | undefined;
62
+ } | undefined;
63
+ /** The checkout root, ALREADY `~`-expanded by the caller. */
64
+ projectsDir: string;
65
+ onProgress: (event: CheckoutProgressEvent) => void;
66
+ checkoutId?: string | undefined;
67
+ signal?: AbortSignal | undefined;
68
+ /** Test seam; defaults to spawning real commands (or the dry-run fake). */
69
+ run?: CommandRunner;
70
+ /** Test seam for the template wait. */
71
+ sleep?: (ms: number) => Promise<void>;
72
+ }
73
+ export declare function createProject(opts: CreateProjectOptions): Promise<CreateProjectResult>;
74
+ /** `GET /api/v1/projects/github-owners` — who a new repository may belong to:
75
+ * the signed-in user first, then their organisations, each with its avatar
76
+ * (and an org's description) for the dialog's owner cards. */
77
+ export declare function listGithubOwners(run?: CommandRunner): Promise<GithubOwnersResponse>;
@@ -0,0 +1,342 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { mkdir, writeFile } from 'node:fs/promises';
3
+ import { join, resolve } from 'node:path';
4
+ import { GITHUB_REPO_NAME_PATTERN } from '../contract/index.js';
5
+ import { GH_CREDENTIAL_HELPER_CONFIG, cleanupCheckout, isValidCheckoutName, parseRepoRef } from './checkout.js';
6
+ /**
7
+ * `POST /api/v1/projects/create` — the "Add project → New project" flow
8
+ * (spec 2026-09-29-create-new-project).
9
+ *
10
+ * Three shapes, one target rule (`<projectsDir>/<name>`, shared with the clone
11
+ * flow in `checkout.ts`, including its ownership-token `mkdir` and its guarded
12
+ * cleanup):
13
+ *
14
+ * 1. **Local only** — `git init -b main` plus an empty initial commit, so the
15
+ * new project has a base commit a task worktree can branch from.
16
+ * 2. **GitHub, empty** — the same local repo, then `gh repo create <owner>/<name>
17
+ * --private`, an HTTPS `origin`, and a plain `git push`.
18
+ * 3. **GitHub, from a template** — `gh repo create <owner>/<name> --private
19
+ * --template <tmpl>`, wait for GitHub to finish generating it, then clone
20
+ * its HTTPS URL.
21
+ *
22
+ * Both GitHub paths persist the `gh` credential helper a clone gets (#968), so
23
+ * a task worktree's later raw `git push` authenticates the same way.
24
+ *
25
+ * The repository is ALWAYS private: `--private` is a constant here, not a
26
+ * parameter, and nothing in the request can reach it. Visibility is one click
27
+ * on GitHub afterwards; an accidental public repo is not undoable.
28
+ *
29
+ * A GitHub repository is never deleted by cezar. If a later step fails after
30
+ * `gh repo create` succeeded, the local folder is cleaned up exactly like a
31
+ * failed clone, and the error says the remote repo exists — deleting it would
32
+ * need the `delete_repo` scope and is not something to do on a network error.
33
+ */
34
+ const COMMAND_TIMEOUT_MS = 10 * 60_000;
35
+ const ERROR_TAIL_LINES = 6;
36
+ /** How long to wait for GitHub to generate a repo from a template before
37
+ * cloning anyway. Generation is asynchronous and usually takes a few seconds. */
38
+ const TEMPLATE_WAIT_ATTEMPTS = 15;
39
+ const TEMPLATE_WAIT_MS = 2_000;
40
+ /** The one initial branch name for a new local repo. */
41
+ const INITIAL_BRANCH = 'main';
42
+ export const spawnCommandRunner = (cmd, args, opts) => new Promise((resolvePromise) => {
43
+ const child = spawn(cmd, args, {
44
+ cwd: opts.cwd,
45
+ stdio: ['ignore', 'pipe', 'pipe'],
46
+ timeout: COMMAND_TIMEOUT_MS,
47
+ // Non-interactive on purpose: a prompt nobody can see would pin the request.
48
+ env: { ...process.env, GH_PROMPT_DISABLED: '1', GIT_TERMINAL_PROMPT: '0' },
49
+ });
50
+ const tail = [];
51
+ let stdout = '';
52
+ let settled = false;
53
+ const finish = (result) => {
54
+ if (settled)
55
+ return;
56
+ settled = true;
57
+ resolvePromise(result);
58
+ };
59
+ const onAbort = () => {
60
+ child.kill('SIGTERM');
61
+ finish({ ok: false, error: 'project creation cancelled' });
62
+ };
63
+ opts.signal?.addEventListener('abort', onAbort, { once: true });
64
+ let pending = '';
65
+ child.stderr?.setEncoding('utf8');
66
+ child.stderr?.on('data', (chunk) => {
67
+ pending += chunk;
68
+ const parts = pending.split(/\r\n|\r|\n/);
69
+ pending = parts.pop() ?? '';
70
+ for (const part of parts) {
71
+ const line = part.trim();
72
+ if (line === '')
73
+ continue;
74
+ tail.push(line);
75
+ if (tail.length > ERROR_TAIL_LINES)
76
+ tail.shift();
77
+ opts.onLine?.(line);
78
+ }
79
+ });
80
+ child.stdout?.setEncoding('utf8');
81
+ child.stdout?.on('data', (chunk) => {
82
+ stdout += chunk;
83
+ });
84
+ child.on('error', (err) => {
85
+ opts.signal?.removeEventListener('abort', onAbort);
86
+ finish({ ok: false, error: err.message, notFound: err.code === 'ENOENT' });
87
+ });
88
+ child.on('close', (code) => {
89
+ opts.signal?.removeEventListener('abort', onAbort);
90
+ if (code === 0)
91
+ return finish({ ok: true, stdout });
92
+ const detail = [...tail, pending.trim(), stdout.trim()].filter((s) => s !== '').slice(-ERROR_TAIL_LINES).join('\n');
93
+ finish({ ok: false, error: detail === '' ? `${cmd} ${args[0] ?? ''} exited with code ${code}` : detail });
94
+ });
95
+ });
96
+ /**
97
+ * `CEZ_DRY_RUN=1` — real `git` (it is local and required anyway), fake `gh`.
98
+ * The fake clone writes only inside the directory the caller created, as a real
99
+ * (`git init`) repo: the `git config --local` that follows must find THIS repo,
100
+ * never walk up past a bare `.git` folder into an enclosing one. `git push`
101
+ * would need a real remote, so it is faked like `gh`.
102
+ */
103
+ export const dryRunCommandRunner = async (cmd, args, opts) => {
104
+ if (cmd === 'git' && args[0] === 'push') {
105
+ opts.onLine?.(`(CEZ_DRY_RUN=1) git ${args.join(' ')}`);
106
+ return { ok: true, stdout: '' };
107
+ }
108
+ if (cmd === 'git') {
109
+ // An empty commit needs an identity; a dry run must not depend on the
110
+ // host's git config, so it lends one for that single call.
111
+ const withIdentity = args[0] === 'commit' ? ['-c', 'user.name=cezar dry run', '-c', 'user.email=dry-run@cezar.invalid', ...args] : args;
112
+ return spawnCommandRunner(cmd, withIdentity, opts);
113
+ }
114
+ opts.onLine?.(`(CEZ_DRY_RUN=1) gh ${args.join(' ')}`);
115
+ if (args[0] === 'repo' && args[1] === 'clone') {
116
+ const dir = args[3] ?? opts.cwd;
117
+ const init = await spawnCommandRunner('git', ['init', '-b', INITIAL_BRANCH], { ...opts, cwd: dir });
118
+ if (!init.ok)
119
+ return init;
120
+ await writeFile(join(dir, 'README.md'), `# ${args[2] ?? 'repo'}\n\n(CEZ_DRY_RUN=1 fake template clone)\n`, 'utf8');
121
+ }
122
+ if (args[0] === 'api')
123
+ return { ok: true, stdout: '1\n' };
124
+ return { ok: true, stdout: '' };
125
+ };
126
+ const OWNER_SEGMENT = /^[A-Za-z0-9][A-Za-z0-9-]*$/;
127
+ const GH_MISSING = 'gh CLI not found — install it and run `gh auth login`';
128
+ export async function createProject(opts) {
129
+ const name = opts.name.trim();
130
+ // GitHub's repository-name rules, even for a local-only project: the name is
131
+ // the folder AND (now or later) the repo, and GitHub would silently rewrite
132
+ // anything else — `my project` becomes `my-project` there but not on disk.
133
+ if (!GITHUB_REPO_NAME_PATTERN.test(name) || !isValidCheckoutName(name)) {
134
+ return {
135
+ ok: false,
136
+ status: 400,
137
+ stage: 'invalid_input',
138
+ error: `not a valid project name: ${name.slice(0, 200)} — use letters, digits, ".", "-" and "_" only, no spaces`,
139
+ };
140
+ }
141
+ let slug;
142
+ let template;
143
+ if (opts.github) {
144
+ const owner = opts.github.owner.trim();
145
+ if (owner.length > 64 || !OWNER_SEGMENT.test(owner)) {
146
+ return { ok: false, status: 400, stage: 'invalid_input', error: `not a valid GitHub owner: ${owner.slice(0, 200)}` };
147
+ }
148
+ slug = `${owner}/${name}`;
149
+ const rawTemplate = opts.github.template?.trim() ?? '';
150
+ if (rawTemplate !== '') {
151
+ const ref = parseRepoRef(rawTemplate);
152
+ if (!ref)
153
+ return { ok: false, status: 400, stage: 'invalid_input', error: `not a GitHub template repository: ${rawTemplate.slice(0, 200)}` };
154
+ template = ref.slug;
155
+ }
156
+ }
157
+ if (!opts.projectsDir.startsWith('/')) {
158
+ return { ok: false, status: 500, stage: 'checkout_root', error: `checkout root is not an absolute path: ${opts.projectsDir}` };
159
+ }
160
+ const root = resolve(opts.projectsDir);
161
+ const target = join(root, name);
162
+ try {
163
+ await mkdir(root, { recursive: true });
164
+ }
165
+ catch (err) {
166
+ return { ok: false, status: 500, stage: 'checkout_root', error: `checkout root is not writable: ${errText(err)}` };
167
+ }
168
+ // The ownership token, exactly as in checkout.ts: non-recursive, so it
169
+ // succeeds only when WE created the directory — which is what licenses the
170
+ // cleanup below.
171
+ try {
172
+ await mkdir(target);
173
+ }
174
+ catch (err) {
175
+ if (err.code === 'EEXIST') {
176
+ return { ok: false, status: 409, stage: 'folder_exists', error: `folder already exists: ${target}` };
177
+ }
178
+ return { ok: false, status: 500, stage: 'checkout_root', error: `could not create ${target}: ${errText(err)}` };
179
+ }
180
+ const emit = (event) => opts.onProgress({ ...event, name, ...(opts.checkoutId ? { checkoutId: opts.checkoutId } : {}) });
181
+ const say = (line) => emit({ phase: 'cloning', line });
182
+ const run = opts.run ?? (process.env.CEZ_DRY_RUN === '1' ? dryRunCommandRunner : spawnCommandRunner);
183
+ const exec = async (cmd, args) => {
184
+ try {
185
+ return await run(cmd, args, { cwd: target, onLine: say, signal: opts.signal });
186
+ }
187
+ catch (err) {
188
+ return { ok: false, error: errText(err) };
189
+ }
190
+ };
191
+ /** PR #968: route this repo's github.com HTTPS credentials through `gh`, as `checkout.ts` does. */
192
+ const persistCredentialHelper = async () => {
193
+ for (const args of GH_CREDENTIAL_HELPER_CONFIG) {
194
+ const result = await exec('git', ['config', '--local', ...args]);
195
+ if (!result.ok)
196
+ return { ok: false, error: `could not configure GitHub credentials: ${result.error}` };
197
+ }
198
+ return { ok: true, stdout: '' };
199
+ };
200
+ /** Clean up the local folder and answer with a failure. */
201
+ const fail = async (outcome, remoteCreated, step) => {
202
+ await cleanupCheckout(root, target);
203
+ if (outcome.notFound) {
204
+ emit({ phase: 'error', error: GH_MISSING });
205
+ return { ok: false, status: 503, error: GH_MISSING, reason: GH_MISSING, stage: 'gh_missing' };
206
+ }
207
+ const error = remoteCreated && slug ? `${outcome.error}\n(the private repository ${slug} was created on GitHub)` : outcome.error;
208
+ emit({ phase: 'error', error });
209
+ return { ok: false, status: 500, error, stage: opts.signal?.aborted ? 'cancelled' : step };
210
+ };
211
+ if (slug && template) {
212
+ say(`Creating private repository ${slug} from ${template}…`);
213
+ const created = await exec('gh', ['repo', 'create', slug, '--private', '--template', template]);
214
+ if (!created.ok)
215
+ return fail(created, false, 'github_create');
216
+ // Template generation is asynchronous on GitHub: an immediate clone can
217
+ // land an empty repo. Wait until the first commit is visible.
218
+ const sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
219
+ for (let attempt = 0; attempt < TEMPLATE_WAIT_ATTEMPTS; attempt++) {
220
+ if (opts.signal?.aborted)
221
+ return fail({ error: 'project creation cancelled' }, true, 'cancelled');
222
+ const probe = await exec('gh', ['api', `repos/${slug}/commits?per_page=1`, '--jq', 'length']);
223
+ if (probe.ok && Number.parseInt(probe.stdout.trim(), 10) > 0)
224
+ break;
225
+ if (attempt === 0)
226
+ say('Waiting for GitHub to generate the repository…');
227
+ await sleep(TEMPLATE_WAIT_MS);
228
+ }
229
+ const cloned = await exec('gh', ['repo', 'clone', remoteUrl(slug), target, '--', '--progress']);
230
+ if (!cloned.ok)
231
+ return fail(cloned, true, 'template_clone');
232
+ const helper = await persistCredentialHelper();
233
+ if (!helper.ok)
234
+ return fail(helper, true, 'template_clone');
235
+ emit({ phase: 'done' });
236
+ return { ok: true, target, name, slug, kind: 'template' };
237
+ }
238
+ say('Initializing a git repository…');
239
+ const init = await exec('git', ['init', '-b', INITIAL_BRANCH]);
240
+ if (!init.ok)
241
+ return fail(init, false, 'git_init');
242
+ // An empty commit gives the project a base commit to branch task worktrees
243
+ // from, without writing any file the user did not ask for.
244
+ const commit = await exec('git', ['commit', '--allow-empty', '-m', 'Initial commit']);
245
+ if (!commit.ok) {
246
+ // Most likely no git identity. A local-only project is still a fine git
247
+ // repo without it; a GitHub push is not possible, so say why.
248
+ say(`No initial commit: ${commit.error.split('\n')[0] ?? commit.error}`);
249
+ }
250
+ if (slug) {
251
+ say(`Creating private repository ${slug}…`);
252
+ const created = await exec('gh', ['repo', 'create', slug, '--private']);
253
+ if (!created.ok)
254
+ return fail(created, false, 'github_create');
255
+ // HTTPS remote + gh credential helper, exactly as a clone gets (#968); the
256
+ // push then goes through plain git, proving the setup a task push relies on.
257
+ const remote = await exec('git', ['remote', 'add', 'origin', remoteUrl(slug)]);
258
+ if (!remote.ok)
259
+ return fail(remote, true, 'github_create');
260
+ const helper = await persistCredentialHelper();
261
+ if (!helper.ok)
262
+ return fail(helper, true, 'github_create');
263
+ if (commit.ok) {
264
+ say(`Pushing ${INITIAL_BRANCH} to ${slug}…`);
265
+ const pushed = await exec('git', ['push', '-u', 'origin', INITIAL_BRANCH]);
266
+ if (!pushed.ok)
267
+ return fail(pushed, true, 'github_create');
268
+ }
269
+ }
270
+ emit({ phase: 'done' });
271
+ return { ok: true, target, name, ...(slug ? { slug } : {}), kind: slug ? 'github' : 'local' };
272
+ }
273
+ /** `GET /api/v1/projects/github-owners` — who a new repository may belong to:
274
+ * the signed-in user first, then their organisations, each with its avatar
275
+ * (and an org's description) for the dialog's owner cards. */
276
+ export async function listGithubOwners(run) {
277
+ if (!run && process.env.CEZ_DRY_RUN === '1') {
278
+ return {
279
+ available: true,
280
+ owners: [
281
+ { login: 'dry-run-user', personal: true },
282
+ { login: 'dry-run-org', personal: false, description: 'CEZ_DRY_RUN=1 fake organisation' },
283
+ ],
284
+ };
285
+ }
286
+ const exec = run ?? spawnCommandRunner;
287
+ const cwd = process.cwd();
288
+ const [user, orgs] = await Promise.all([
289
+ exec('gh', ['api', 'user', '--jq', '[.login, .avatar_url // ""] | @tsv'], { cwd }).catch((err) => ({
290
+ ok: false,
291
+ error: errText(err),
292
+ })),
293
+ exec('gh', ['api', 'user/orgs', '--paginate', '--jq', '.[] | [.login, .avatar_url // "", .description // ""] | @tsv'], {
294
+ cwd,
295
+ }).catch((err) => ({ ok: false, error: errText(err) })),
296
+ ]);
297
+ if (!user.ok) {
298
+ if ('notFound' in user && user.notFound)
299
+ return { available: false, reason: GH_MISSING };
300
+ return { available: false, reason: `gh is not authenticated — run \`gh auth login\` (${user.error.split('\n')[0] ?? ''})` };
301
+ }
302
+ const me = parseOwnerLine(user.stdout.split('\n')[0] ?? '', true);
303
+ if (!me)
304
+ return { available: false, reason: 'gh returned no GitHub login' };
305
+ // An org listing failure (e.g. a token without read:org) still leaves the
306
+ // personal account — degrade to that rather than hide GitHub entirely.
307
+ const orgOwners = new Map();
308
+ if (orgs.ok) {
309
+ for (const line of orgs.stdout.split('\n')) {
310
+ const org = parseOwnerLine(line, false);
311
+ if (org && org.login !== me.login)
312
+ orgOwners.set(org.login, org);
313
+ }
314
+ }
315
+ const sorted = [...orgOwners.values()].sort((a, b) => a.login.localeCompare(b.login));
316
+ return { available: true, owners: [me, ...sorted] };
317
+ }
318
+ /** One `login<TAB>avatar[<TAB>description]` line from `gh --jq … | @tsv`.
319
+ * Only https avatars are passed on — the cockpit renders them as `<img src>`. */
320
+ function parseOwnerLine(line, personal) {
321
+ const [login = '', avatar = '', ...rest] = line.split('\t');
322
+ const trimmed = login.trim();
323
+ if (!OWNER_SEGMENT.test(trimmed))
324
+ return null;
325
+ // `@tsv` escapes tabs/newlines inside a field as `\t`/`\n`; fold them to spaces.
326
+ const description = rest.join(' ').replace(/\\[tnr]/g, ' ').replace(/\s+/g, ' ').trim();
327
+ return {
328
+ login: trimmed,
329
+ personal,
330
+ ...(avatar.trim().startsWith('https://') ? { avatarUrl: avatar.trim() } : {}),
331
+ ...(description !== '' ? { description: description.slice(0, 200) } : {}),
332
+ };
333
+ }
334
+ /** The HTTPS remote, never the bare slug: `gh` would pick SSH from its own config, and an SSH key
335
+ * is what an organisation's SAML policy may reject (#968, `RepoRef.cloneUrl`). */
336
+ function remoteUrl(slug) {
337
+ return `https://github.com/${slug}.git`;
338
+ }
339
+ function errText(err) {
340
+ return err instanceof Error ? err.message : String(err);
341
+ }
342
+ //# sourceMappingURL=create-project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-project.js","sourceRoot":"","sources":["../../src/server/create-project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,wBAAwB,EAA+C,MAAM,8BAA8B,CAAC;AACrH,OAAO,EAAE,2BAA2B,EAAE,eAAe,EAAE,mBAAmB,EAAE,YAAY,EAA8B,MAAM,eAAe,CAAC;AAE5I;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,MAAM,kBAAkB,GAAG,EAAE,GAAG,MAAM,CAAC;AACvC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B;kFACkF;AAClF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AAiB;IACrD,MAAM,CAAC,KAAK,GAAG,EAAE,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5D,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IAC9C,iFAAiF;IACjF,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACxF,OAAO;QACL,KAAK,EAAE,OAAO;QACd,QAAQ;QACR,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7E,GAAG,CAAC,WAAW,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1E,CAAC;AACJ,CAAC;AAED;mFACmF;AACnF,SAAS,SAAS,CAAC,IAAY;IAC7B,OAAO,sBAAsB,IAAI,MAAM,CAAC;AAC1C,CAAC;AAED,SAAS,OAAO,CAAC,GAAY;IAC3B,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC"}
@@ -571,6 +571,8 @@ export declare function fetchGithubRefStatus(repoRoot: string, input: {
571
571
  */
572
572
  export declare function fetchGithubComments(repoRoot: string, kind: 'issue' | 'pr', number: number, refresh?: boolean): Promise<ForgeCommentsData>;
573
573
  export declare function createDraftPr(input: DraftPrInput): Promise<DraftPrOutcome>;
574
+ /** `gh pr create` target: `--repo <base repo>`, head owner-qualified when pushed to a fork. */
575
+ export declare function prRepoArgs(worktree: string, baseRemote: string, pushRemote: string, branch: string): Promise<string[]>;
574
576
  /**
575
577
  * PR body from the handoff journal: the "## Goal" section (task text as
576
578
  * fallback) + the first ~10 lines of "## Progress log" (newest first) +
@@ -2,7 +2,8 @@ import { execFile } from 'node:child_process';
2
2
  import { promisify } from 'node:util';
3
3
  import { z } from 'zod';
4
4
  import { REFERENCE_STATUS_MAX } from '../../contract/index.js';
5
- import { autosaveCommit } from '../../git-worktree.js';
5
+ import { autosaveCommit, taskRemotes } from '../../git-worktree.js';
6
+ import { parseRemote, splitRemoteRef } from '../../git-remotes.js';
6
7
  /**
7
8
  * The GitHub forge driver — all `gh`-CLI logic in one place, moved here from
8
9
  * `src/server/github.ts` (tab listing) and `src/server/pr.ts` (draft PRs)
@@ -2253,9 +2254,9 @@ function mockGithubComments(kind) {
2253
2254
  };
2254
2255
  }
2255
2256
  // ---- draft-PR creation (review gate, spec 009) ------------------------------
2256
- // Final autosave-commit → `git push -u origin cez/<id8>` → `gh pr create
2257
- // --draft`, all executed in the task worktree (gh picks the repo up from the
2258
- // worktree's remote). Every failure maps to a one-line human error — the GUI
2257
+ // Final autosave-commit → `git push -u <push remote> cez/<id8>` → `gh pr create
2258
+ // --draft --repo <base repo>`, all executed in the task worktree. Every failure
2259
+ // maps to a one-line human error — the GUI
2259
2260
  // shows it as a toast plus the manual `git merge <branch>` fallback. Never throws.
2260
2261
  const PR_URL_RE = /https:\/\/github\.com\/[^/\s]+\/[^/\s]+\/pull\/\d+/;
2261
2262
  const PUSH_TIMEOUT_MS = 60_000;
@@ -2287,22 +2288,24 @@ export async function createDraftPr(input) {
2287
2288
  if (process.env.CEZ_DRY_RUN === '1') {
2288
2289
  return { ok: true, url: 'https://github.com/open-mercato/demo/pull/777', dryRun: true };
2289
2290
  }
2290
- const remote = await execTool(['remote', 'get-url', 'origin'], worktree, 'git');
2291
- if (!remote.ok || !remote.stdout.trim()) {
2291
+ // Push to the push remote, open the PR on the base remote the task forked from (#1383).
2292
+ const remotes = await taskRemotes(worktree);
2293
+ if (!remotes.push || !remotes.base) {
2292
2294
  return { ok: false, error: 'no git remote — add one (git remote add origin <url>) or merge the branch locally' };
2293
2295
  }
2294
- const push = await execTool(['push', '-u', 'origin', branch], worktree, 'git', PUSH_TIMEOUT_MS);
2296
+ const push = await execTool(['push', '-u', remotes.push, branch], worktree, 'git', PUSH_TIMEOUT_MS);
2295
2297
  if (!push.ok) {
2296
2298
  return { ok: false, error: `git push failed — ${tail(push.stderr) || 'unknown error'}` };
2297
2299
  }
2298
2300
  const body = buildPrBody(input.handoffText, run.task);
2299
2301
  // Target the branch the worktree forked from (config `baseBranch`) — without
2300
2302
  // --base, gh aims at the repo default (main) even when work started on
2301
- // develop. `origin/x` normalizes to `x`; a raw sha (detached-HEAD fork
2303
+ // develop. `<remote>/x` normalizes to `x`; a raw sha (detached-HEAD fork
2302
2304
  // point) can't be a PR base, so gh falls back to the default branch.
2303
- const prBase = run.baseBranch?.replace(/^origin\//, '');
2305
+ const prBase = run.baseBranch ? splitRemoteRef(run.baseBranch, remotes.names).branch : undefined;
2304
2306
  const baseArgs = prBase && !/^[0-9a-f]{7,40}$/i.test(prBase) ? ['--base', prBase] : [];
2305
- const pr = await execTool(['pr', 'create', '--draft', '--head', branch, ...baseArgs, '--title', run.title, '--body', body], worktree, 'gh', PUSH_TIMEOUT_MS);
2307
+ const repoArgs = await prRepoArgs(worktree, remotes.base, remotes.push, branch);
2308
+ const pr = await execTool(['pr', 'create', ...(input.draft === false ? [] : ['--draft']), ...repoArgs, ...baseArgs, '--title', run.title, '--body', body], worktree, 'gh', PUSH_TIMEOUT_MS);
2306
2309
  if (!pr.ok) {
2307
2310
  if (pr.notFound) {
2308
2311
  return { ok: false, error: 'gh not found — install the GitHub CLI and run `gh auth login`, or merge the branch locally' };
@@ -2317,6 +2320,25 @@ export async function createDraftPr(input) {
2317
2320
  }
2318
2321
  return { ok: true, url: match[0], dryRun: false };
2319
2322
  }
2323
+ /** `gh pr create` target: `--repo <base repo>`, head owner-qualified when pushed to a fork. */
2324
+ export async function prRepoArgs(worktree, baseRemote, pushRemote, branch) {
2325
+ const url = async (name) => {
2326
+ const res = await execTool(['remote', 'get-url', name], worktree, 'git');
2327
+ return res.ok ? parseRemote(res.stdout.trim()) : null;
2328
+ };
2329
+ const target = await url(baseRemote);
2330
+ if (!target)
2331
+ return ['--head', branch];
2332
+ const repoArgs = ['--repo', `${target.host}/${target.owner}/${target.repo}`];
2333
+ if (pushRemote === baseRemote)
2334
+ return [...repoArgs, '--head', branch];
2335
+ const source = await url(pushRemote);
2336
+ const sameRepo = source &&
2337
+ source.host === target.host &&
2338
+ source.owner.toLowerCase() === target.owner.toLowerCase() &&
2339
+ source.repo.toLowerCase() === target.repo.toLowerCase();
2340
+ return [...repoArgs, '--head', source && !sameRepo ? `${source.owner}:${branch}` : branch];
2341
+ }
2320
2342
  /**
2321
2343
  * PR body from the handoff journal: the "## Goal" section (task text as
2322
2344
  * fallback) + the first ~10 lines of "## Progress log" (newest first) +