@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
@@ -23,6 +23,7 @@ import { fileURLToPath } from 'node:url';
23
23
  import { Hono } from 'hono';
24
24
  import { serve } from '@hono/node-server';
25
25
  import { bodyLimit } from 'hono/body-limit';
26
+ import { HTTPException } from 'hono/http-exception';
26
27
  import { streamSSE } from 'hono/streaming';
27
28
  import { jsonZodValidator, multipartZodValidator, paramZodValidator, queryZodValidator } from './validators.js';
28
29
  import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
@@ -59,7 +60,7 @@ import { StarCountReader } from './star-count.js';
59
60
  import { getTeamSkillsCached, refreshTeamSkills, waitForTeamSkills } from '../skills-remote.js';
60
61
  import { appendHandoffHeartbeat, handoffProgressExcerpt, readHandoff } from '../handoff.js';
61
62
  import { markStarted, onTodosChanged, readTodos, removeTodo, todoTaskText } from '../todos.js';
62
- import { HistoryCursorError, deriveRunContextEvents, readEventsAfterLiveCursor, readRunHistoryPage, validateLiveCursor, } from '../runs/event-history.js';
63
+ import { HistoryCursorError, deriveRunContextEvents, readEventsAfterLiveCursor, readRunHistoryPage, streamRunEvents, validateLiveCursor, } from '../runs/event-history.js';
63
64
  import { readRunIndexFromDisk } from '../runs/run-index.js';
64
65
  import { isV2WireEventType } from '../runs/ui-event-sink.js';
65
66
  import { onRunDeleted, onRunEvent } from './sse-subscriptions.js';
@@ -69,7 +70,7 @@ import { toPastedContent } from '../workflows/run.js';
69
70
  import { removeWorktree, worktreeDiff, worktreeDiffStat, worktreeSizeBytes } from '../git-worktree.js';
70
71
  import { isReclaimable, reclaimWorktrees } from '../runs/retention.js';
71
72
  import { getBranches, getCommit, getDiff, getLog, getRepoInfo, getStatus } from './git.js';
72
- import { collectChanges, collectCommitChanges, collectRunCommits, commitAll, createOrSwitchBranch, imageMimeType, isOsOpenableImage, listRepoPaths, pushCurrentBranch, readWorktreePath, repoIndexContains, } from './git-changes.js';
73
+ import { collectChanges, collectCommitChanges, collectRunCommits, commitAll, createOrSwitchBranch, imageMimeType, isOsOpenableImage, listRepoPaths, pushCurrentBranch, worktreeGitStatus, readWorktreePath, repoIndexContains, } from './git-changes.js';
73
74
  import { gatedSkillsRepos, loadConfig, resolveWorktreeRetention } from '../config.js';
74
75
  import { findConfigFile } from '../agent-config/catalog.js';
75
76
  import { readConfigFile, statConfigPath, writeConfigFile } from '../agent-config/files.js';
@@ -85,6 +86,8 @@ import { withEnvPrefix } from '../core/shell-env.js';
85
86
  import { allocateProjectSlug, clearProjectProbeCache, listProjects, normalizeProjectTags, probeProjectStatus, registerProject, removeProject, shouldRegisterProject, } from '../workspace/projects.js';
86
87
  import { mergeWriteWorkspaceUiState, readWorkspaceUiState } from '../workspace/ui-state.js';
87
88
  import { checkoutRepo } from './checkout.js';
89
+ import { createProjectInputSchema } from '../contract/index.js';
90
+ import { createProject, listGithubOwners } from './create-project.js';
88
91
  import { ProjectContextError, ProjectContexts } from './project-context.js';
89
92
  import { reviewGateEnabled } from '../runs/review-gate.js';
90
93
  import { readUiState, uiStatePath } from '../ui-state.js';
@@ -98,6 +101,8 @@ import { ensureLaunchKey } from './launch-key.js';
98
101
  import { openInTerminal } from './open-in-terminal.js';
99
102
  import { agentCliRunner, detectOpenTargets, openFileInDefaultApp, openInApp, withResolvedClaudeBin, } from './open-in-app.js';
100
103
  import { createDraftPr } from './pr.js';
104
+ import { DEFAULT_TELEMETRY_URL, TELEMETRY_POLICY_VERSION, deviceSid, loadTelemetryConsent, reportError, setTelemetryConsent, telemetryBlockedBy, track, } from '../telemetry.js';
105
+ import { setTelemetryConsentInputSchema, telemetryErrorInputSchema, telemetryEventInputSchema, telemetryPageInputSchema, } from '../contract/index.js';
101
106
  import { ProviderRuntimeAuthObserver } from './provider-auth-runtime.js';
102
107
  import { providerForActiveRun, providerForExistingRun, providersRequiredByWorkflow, unavailableProviderMessage, } from './provider-action-gate.js';
103
108
  import { ASSET_CACHE_CONTROL, SHELL_CACHE_CONTROL, BUILD_HINT_HTML, assetContentType, isSafeAssetFilename, resolveGetRequest, } from './static-ui.js';
@@ -516,6 +521,10 @@ const patchRunSchema = z.object({
516
521
  title: z.string().trim().min(1).max(300).optional(),
517
522
  task: z.string().trim().min(1).max(100_000).optional(),
518
523
  });
524
+ // `POST /runs/:id/pr`: `draft` defaults to true — a bodyless POST still opens the draft PR every
525
+ // caller got before the flag existed (the review gate's Draft PR); the run header's Create PR asks
526
+ // for a ready-for-review one with `draft: false`.
527
+ const createPrSchema = z.object({ draft: z.boolean().optional() });
519
528
  // Session commit (redesign R5 — §"Git/session API additions").
520
529
  const gitCommitSchema = z.object({
521
530
  message: z.string().trim().min(1, 'must not be empty').max(5_000),
@@ -1036,6 +1045,19 @@ export function createApp(deps) {
1036
1045
  contexts.onStoreCreated((store) => providerRuntimeAuth.watch(store));
1037
1046
  contexts.onContextBuilt((ctx) => providerRuntimeAuth.watch(ctx.store));
1038
1047
  const app = new Hono();
1048
+ // Hono's default 500, plus an error report (a no-op until the user opted in).
1049
+ app.onError((err, c) => {
1050
+ if (err instanceof HTTPException)
1051
+ return err.getResponse();
1052
+ console.error(err);
1053
+ reportError(err, {
1054
+ source: 'server',
1055
+ 'http.method': c.req.method,
1056
+ 'http.route': c.req.routePath,
1057
+ 'http.project_scoped': c.req.path.startsWith('/api/v1/p/'),
1058
+ }, { code: 'http_handler_failed', sid: deviceSid(c.req.header('x-cezar-sid')) });
1059
+ return c.text('Internal Server Error', 500);
1060
+ });
1039
1061
  // Reject oversized request bodies before they reach any handler (#429). GETs
1040
1062
  // and SSE carry no body, so this only ever gates the mutating routes.
1041
1063
  app.use('*', bodyLimit({ maxSize: GLOBAL_BODY_LIMIT }));
@@ -2180,6 +2202,8 @@ export function createApp(deps) {
2180
2202
  const registered = await registerFolder(parsed.data.root, 'local');
2181
2203
  if (registered.status !== 200)
2182
2204
  return c.json(registered.body, registered.status);
2205
+ // Only a genuinely new project: a re-add answers 409 above and is not an event.
2206
+ track('project_added', { label: 'local' }, { sid: deviceSid(c.req.header('x-cezar-sid')) });
2183
2207
  return c.json(registered.body, 200);
2184
2208
  })
2185
2209
  .delete('/projects/:projectId', async (c) => {
@@ -2363,6 +2387,48 @@ export function createApp(deps) {
2363
2387
  const error = 'error' in body && body.error ? body.error : 'could not register the checkout';
2364
2388
  return c.json({ error: `${error} (the clone is at ${result.target})` }, registered.status);
2365
2389
  }
2390
+ // The checkout dialog only clones GitHub repositories (`checkoutSchema`).
2391
+ track('project_added', { label: 'github' }, { sid: deviceSid(c.req.header('x-cezar-sid')) });
2392
+ return c.json(registered.body, 200);
2393
+ })
2394
+ // ---- new project (spec 2026-09-29-create-new-project) ------------------
2395
+ // "Add project → New project": a fresh git repo at `<projectsDir>/<name>`,
2396
+ // optionally backed by a new PRIVATE GitHub repository (never public — the
2397
+ // body has no visibility field to set), optionally generated from a
2398
+ // template. Same progress stream, same `registerFolder` commit, same
2399
+ // `{ error, reason }` degradation as the clone route above.
2400
+ .get('/projects/github-owners', async (c) => c.json(await listGithubOwners(deps.projectCommandRunner)))
2401
+ .post('/projects/create', jsonZodValidator(() => createProjectInputSchema, { message: 'project name must be a valid GitHub repository name — letters, digits, ".", "-" and "_" only, no spaces' }), async (c) => {
2402
+ if (capabilities().singleProject) {
2403
+ return c.json(singleProjectRefusal('adding projects'), 409);
2404
+ }
2405
+ const { name, github, checkoutId } = c.req.valid('json');
2406
+ const result = await createProject({
2407
+ name,
2408
+ github,
2409
+ checkoutId,
2410
+ projectsDir: expandTilde(await workspaceProjectsDir()),
2411
+ onProgress: (event) => workspaceEvents.emit('checkout-progress', event),
2412
+ signal: c.req.raw.signal,
2413
+ ...(deps.projectCommandRunner ? { run: deps.projectCommandRunner } : {}),
2414
+ });
2415
+ const sid = deviceSid(c.req.header('x-cezar-sid'));
2416
+ if (!result.ok) {
2417
+ // The stage, never the error text: that can carry paths and repository names.
2418
+ track('project_create_failed', { label: result.stage }, { sid });
2419
+ return c.json('reason' in result ? { error: result.error, reason: result.reason } : { error: result.error }, result.status);
2420
+ }
2421
+ // GitHub-backed projects register as `checkout` (they have an origin the
2422
+ // clone flow would also produce); a local-only repo is `local`.
2423
+ const registered = await registerFolder(result.target, result.slug ? 'checkout' : 'local');
2424
+ if (registered.status !== 200) {
2425
+ const { body } = registered;
2426
+ const error = 'error' in body && body.error ? body.error : 'could not register the new project';
2427
+ track('project_create_failed', { label: 'register' }, { sid });
2428
+ return c.json({ error: `${error} (the project is at ${result.target})` }, registered.status);
2429
+ }
2430
+ // `new_local` / `new_github` / `new_template`, beside the folder and clone flows' labels.
2431
+ track('project_added', { label: `new_${result.kind}` }, { sid });
2366
2432
  return c.json(registered.body, 200);
2367
2433
  });
2368
2434
  // Register an existing folder (multi-project spec, "Add project" — the
@@ -3741,7 +3807,13 @@ export function createApp(deps) {
3741
3807
  .get('/runs', (c) => c.json(c.get('project').store.listRuns().map(withUsage)))
3742
3808
  // Registered before the `/:id/...` routes so "archive-finished" and "read-all"
3743
3809
  // never match as a run id.
3744
- .post('/runs/archive-finished', (c) => c.json({ archived: c.get('project').store.archiveFinished() }))
3810
+ .post('/runs/archive-finished', (c) => {
3811
+ const archived = c.get('project').store.archiveFinished();
3812
+ // One event for the sweep, `value` = how many it archived (summed on the dashboard).
3813
+ if (archived > 0)
3814
+ track('task_archived', { label: 'bulk', value: archived }, { sid: deviceSid(c.req.header('x-cezar-sid')) });
3815
+ return c.json({ archived });
3816
+ })
3745
3817
  // The read-receipt sweep (#unread-done-items) — the mark-read twin of the archive
3746
3818
  // sweep above, and under the same registration-order guard.
3747
3819
  .post('/runs/read-all', (c) => c.json({ read: c.get('project').store.markAllRead() }))
@@ -3758,6 +3830,9 @@ export function createApp(deps) {
3758
3830
  const run = store.setArchived(id, parsed.data.archived !== false);
3759
3831
  if (run && retiresQuestion)
3760
3832
  manager.notifyQuestionRetired?.(id);
3833
+ // Labelled with the task's outcome: which results get kept, which get put away.
3834
+ if (run)
3835
+ track(parsed.data.archived !== false ? 'task_archived' : 'task_unarchived', { label: run.status }, { sid: deviceSid(c.req.header('x-cezar-sid')) });
3761
3836
  return run ? c.json(run) : c.json({ error: 'not found' }, 404);
3762
3837
  })
3763
3838
  // Pin one task to the top of this project's list, or unpin it (#935). The archive route's
@@ -3766,7 +3841,10 @@ export function createApp(deps) {
3766
3841
  // event and no new response shape.
3767
3842
  .post('/runs/:id/pin', jsonZodValidator(pinSchema, { absent: ({}) }), (c) => {
3768
3843
  const { store } = c.get('project');
3769
- const run = store.setPinned(c.req.param('id'), c.req.valid('json').pinned !== false);
3844
+ const pinned = c.req.valid('json').pinned !== false;
3845
+ const run = store.setPinned(c.req.param('id'), pinned);
3846
+ if (run)
3847
+ track(pinned ? 'task_pinned' : 'task_unpinned', { label: run.status }, { sid: deviceSid(c.req.header('x-cezar-sid')) });
3770
3848
  return run ? c.json(run) : c.json({ error: 'not found' }, 404);
3771
3849
  })
3772
3850
  // The per-task off switch for that resume (the workspace setting is Settings → Resources).
@@ -3857,6 +3935,7 @@ export function createApp(deps) {
3857
3935
  // CEZ_TODOS_FILE alike (RunManager.agentEnv).
3858
3936
  generateFollowups: capabilities().followups ? parsed.data.generateFollowups : false,
3859
3937
  ...(parsed.data.dispatch && capabilities().dispatch ? { dispatchIntent: parsed.data.dispatch } : {}),
3938
+ deviceSid: deviceSid(c.req.header('x-cezar-sid')),
3860
3939
  };
3861
3940
  if (variants > 1) {
3862
3941
  const runs = manager.startVariants(workflow, input, variants);
@@ -4145,6 +4224,7 @@ export function createApp(deps) {
4145
4224
  if (!opened) {
4146
4225
  return c.json({ error: 'no terminal emulator found', command: fallback }, 409);
4147
4226
  }
4227
+ track('open_in', { label: 'resume_in_terminal' }, { sid: deviceSid(c.req.header('x-cezar-sid')) });
4148
4228
  return c.json({ opened: true, command });
4149
4229
  })
4150
4230
  // Open a run's worktree (or the repo root) in the chosen local app.
@@ -4163,6 +4243,9 @@ export function createApp(deps) {
4163
4243
  // injection guard, this just validates the shape.
4164
4244
  const parsedBody = { data: c.req.valid('json') };
4165
4245
  const { target, path: relPath } = parsedBody.data;
4246
+ // Telemetry counts an `open_in` only once it opened: `target` is free client text until
4247
+ // `openApp`/`agentCliRunner` matched it, and labels must stay a closed set.
4248
+ const trackOpened = (label) => track('open_in', { label }, { sid: deviceSid(c.req.header('x-cezar-sid')) });
4166
4249
  const dir = run.worktreePath && existsSync(run.worktreePath) ? run.worktreePath : repoRoot;
4167
4250
  // Diff pane "open in OS default app" (#365): one worktree file, opened with the platform's
4168
4251
  // default handler for its type — not a directory in the file manager (that's `finder`
@@ -4203,6 +4286,7 @@ export function createApp(deps) {
4203
4286
  const opened = await openFile(filePath);
4204
4287
  if (!opened)
4205
4288
  return c.json({ error: `could not open ${result.path}`, path: filePath }, 409);
4289
+ trackOpened('default');
4206
4290
  return c.json({ opened: true, path: filePath });
4207
4291
  }
4208
4292
  // Coding-agent CLI handoff (#cli-handoff, #402): open a terminal in the worktree that resumes
@@ -4249,11 +4333,13 @@ export function createApp(deps) {
4249
4333
  if (!opened) {
4250
4334
  return c.json({ error: 'no terminal emulator found', command: fallback }, 409);
4251
4335
  }
4336
+ trackOpened(`cli:${cliRunner}`);
4252
4337
  return c.json({ opened: true, path: dir, command });
4253
4338
  }
4254
4339
  const opened = await openApp(target, dir);
4255
4340
  if (!opened)
4256
4341
  return c.json({ error: `could not open ${target}`, path: dir }, 409);
4342
+ trackOpened(target);
4257
4343
  return c.json({ opened: true, path: dir });
4258
4344
  })
4259
4345
  // Handoff journal (spec 007): the per-task handoff.md as markdown. 404 only
@@ -4462,13 +4548,29 @@ export function createApp(deps) {
4462
4548
  remote: result.remote,
4463
4549
  upstreamSet: result.upstreamSet,
4464
4550
  });
4551
+ })
4552
+ // What the worktree holds that has not left it, and what its base has that it lacks — drives
4553
+ // the header's one git button (Commit and push, Push, Update branch). Read-only.
4554
+ .get('/runs/:id/git/status', async (c) => {
4555
+ const { store } = c.get('project');
4556
+ const run = store.getRun(c.req.param('id'));
4557
+ if (!run)
4558
+ return c.json({ error: 'not found' }, 404);
4559
+ const worktree = worktreeOf(run);
4560
+ if (!worktree)
4561
+ return c.json({ error: NO_WORKTREE }, 409);
4562
+ const result = await worktreeGitStatus(worktree, run.baseBranch);
4563
+ if (!result.ok)
4564
+ return c.json({ error: result.error }, 409);
4565
+ return c.json({ uncommitted: result.uncommitted, unpushed: result.unpushed, behind: result.behind });
4465
4566
  })
4466
4567
  // Draft PR from the review gate (spec 009): final autosave → push →
4467
4568
  // `gh pr create --draft`; on success the run completes as done with the PR
4468
4569
  // badge. Failures come back as 409 with a `manual` merge command the GUI
4469
4570
  // shows next to the toast. CEZ_DRY_RUN=1 fakes the URL (no push, no gh).
4470
- .post('/runs/:id/pr', async (c) => {
4571
+ .post('/runs/:id/pr', jsonZodValidator(createPrSchema, { absent: ({}) }), async (c) => {
4471
4572
  const { root: repoRoot, dataDir, store, manager } = c.get('project');
4573
+ const draft = c.req.valid('json').draft ?? true;
4472
4574
  const id = c.req.param('id');
4473
4575
  const run = store.getRun(id);
4474
4576
  if (!run)
@@ -4490,6 +4592,7 @@ export function createApp(deps) {
4490
4592
  repoRoot,
4491
4593
  run,
4492
4594
  handoffText: readHandoff(dataDir, id),
4595
+ draft,
4493
4596
  });
4494
4597
  if (!outcome.ok) {
4495
4598
  return c.json({ error: outcome.error, manual: `git merge ${run.branch}` }, 409);
@@ -4507,7 +4610,7 @@ export function createApp(deps) {
4507
4610
  });
4508
4611
  store.appendEvent(id, {
4509
4612
  type: 'note',
4510
- message: `draft PR created: ${outcome.url}${outcome.dryRun ? ' (dry run — no real PR)' : ''}`,
4613
+ message: `${draft ? 'draft PR' : 'PR'} created: ${outcome.url}${outcome.dryRun ? ' (dry run — no real PR)' : ''}`,
4511
4614
  });
4512
4615
  return c.json({ url: outcome.url, dryRun: outcome.dryRun }, 201);
4513
4616
  })
@@ -4543,7 +4646,10 @@ export function createApp(deps) {
4543
4646
  // The run's `refs/cezar/pr/<n>` goes with the last run that needed it (Phase 3).
4544
4647
  if (deleted && run.prHead)
4545
4648
  await manager.sweepPrHeadRefs();
4546
- return deleted ? c.json({ deleted: true }) : c.json({ error: 'not found' }, 404);
4649
+ if (!deleted)
4650
+ return c.json({ error: 'not found' }, 404);
4651
+ track('task_deleted', { label: run.status }, { sid: deviceSid(c.req.header('x-cezar-sid')) });
4652
+ return c.json({ deleted: true });
4547
4653
  });
4548
4654
  // ---- chained family: in-task drafts (project-scoped) ----------------------
4549
4655
  /**
@@ -4751,6 +4857,8 @@ export function createApp(deps) {
4751
4857
  const opened = await openApp(target, root);
4752
4858
  if (!opened)
4753
4859
  return c.json({ error: `could not open ${target}`, path: root }, 409);
4860
+ // After the allowlist and the open: a closed label set (see the run route above).
4861
+ track('open_in', { label: `project:${target}` }, { sid: deviceSid(c.req.header('x-cezar-sid')) });
4754
4862
  return c.json({ opened: true, path: root });
4755
4863
  });
4756
4864
  // Agent screenshots and user attachments — what the run manager persisted out of tool
@@ -4977,9 +5085,11 @@ export function createApp(deps) {
4977
5085
  });
4978
5086
  const replay = query.cursor
4979
5087
  ? await readEventsAfterLiveCursor(eventsPath, query.cursor)
4980
- : { events: store.readEvents(id), boundarySeq: 0 };
5088
+ : { events: streamRunEvents(eventsPath), boundarySeq: 0 };
4981
5089
  maxSeq = Math.max(maxSeq, replay.boundarySeq);
4982
- for (const event of replay.events) {
5090
+ for await (const event of replay.events) {
5091
+ if (stream.aborted)
5092
+ break;
4983
5093
  if (event.seq <= maxSeq)
4984
5094
  continue;
4985
5095
  await writeEvent(event);
@@ -5600,7 +5710,7 @@ export function createApp(deps) {
5600
5710
  // ---- chained family: repo / git (project-scoped) ----
5601
5711
  const repoRoutes = new Hono()
5602
5712
  .get('/repo', async (c) => {
5603
- const { root: repoRoot } = c.get('project');
5713
+ const { root: repoRoot, store } = c.get('project');
5604
5714
  const info = await getRepoInfo(repoRoot);
5605
5715
  if (!info)
5606
5716
  return c.json({
@@ -5610,10 +5720,12 @@ export function createApp(deps) {
5610
5720
  branches: [],
5611
5721
  baseBranch: null,
5612
5722
  });
5723
+ // Task branches are never a base: hide the named ones (no `cez/` prefix) by record.
5724
+ const taskBranches = new Set(store.listRuns().flatMap((r) => (r.branch ? [r.branch] : [])));
5613
5725
  const [status, log, branches, config] = await Promise.all([
5614
5726
  getStatus(info.root),
5615
5727
  getLog(info.root),
5616
- getBranches(info.root),
5728
+ getBranches(info.root, taskBranches),
5617
5729
  loadConfig(repoRoot),
5618
5730
  ]);
5619
5731
  return c.json({
@@ -5804,6 +5916,7 @@ export function createApp(deps) {
5804
5916
  baseBranch: config.baseBranch ?? null,
5805
5917
  defaultRunner: config.defaultRunner,
5806
5918
  systemPrompt: config.systemPrompt ?? null,
5919
+ branchNaming: config.branchNaming ?? null,
5807
5920
  // Native defaults seed each runner independently. A Cezar preset remains
5808
5921
  // selectable unless the operator opts into the fixed-model policy.
5809
5922
  // An explicit auto override (#906) answers `''` for that runner — the one
@@ -5873,6 +5986,15 @@ export function createApp(deps) {
5873
5986
  raw.systemPrompt = parsed.data.systemPrompt;
5874
5987
  }
5875
5988
  }
5989
+ if (parsed.data.branchNaming !== undefined) {
5990
+ // Same clearing rule as systemPrompt: an emptied textarea means `cez/<id8>` again.
5991
+ if (parsed.data.branchNaming === null || parsed.data.branchNaming === '') {
5992
+ delete raw.branchNaming;
5993
+ }
5994
+ else {
5995
+ raw.branchNaming = parsed.data.branchNaming;
5996
+ }
5997
+ }
5876
5998
  if (parsed.data.maxParallel !== undefined)
5877
5999
  raw.maxParallel = parsed.data.maxParallel;
5878
6000
  if (parsed.data.worktreeRetention !== undefined) {
@@ -5963,6 +6085,8 @@ export function createApp(deps) {
5963
6085
  baseBranch: z.string().trim().min(1).max(200).nullable().optional(),
5964
6086
  defaultRunner: z.enum(RUNNER_IDS).optional(),
5965
6087
  systemPrompt: z.string().trim().max(20_000, 'must be at most 20000 characters').nullable().optional(),
6088
+ // Branch naming instructions (spec 2026-10-11-branch-naming-instructions); null/'' clears.
6089
+ branchNaming: z.string().trim().max(4_000, 'must be at most 4000 characters').nullable().optional(),
5966
6090
  defaultModels: z
5967
6091
  .object({
5968
6092
  claude: modelPresetSchema,
@@ -6282,6 +6406,60 @@ export function createApp(deps) {
6282
6406
  }
6283
6407
  });
6284
6408
  deps.onDispose?.(() => { offDashboardRegistry(); dashboard.dispose(); });
6409
+ // The server's half of a cockpit error: is the bundle that page runs still the one being
6410
+ // served? A page kept open across a rebuild or self-update asks for chunks that no longer
6411
+ // exist — the stale-shell failure a WebKit "Importing a module script failed" usually is.
6412
+ const servedBuildContext = (entry) => {
6413
+ const ctx = { 'server.version': version };
6414
+ if (typeof entry !== 'string' || !isSafeAssetFilename(entry))
6415
+ return ctx;
6416
+ try {
6417
+ ctx['build.entry_served'] = readFileSync(join(distDir, 'index.html'), 'utf8').includes(`/assets/${entry}`);
6418
+ ctx['build.entry_exists'] = existsSync(join(distDir, 'assets', entry));
6419
+ }
6420
+ catch {
6421
+ ctx['build.entry_served'] = false; // no web/dist at all
6422
+ }
6423
+ return ctx;
6424
+ };
6425
+ // Cockpit telemetry (opt-in, docs/telemetry.md). The telemetry worker sends no CORS headers, so
6426
+ // the browser reports through here; the relays answer 204 whether or not the user opted in, and
6427
+ // only a closed set of page names is forwarded.
6428
+ const telemetryConsentBody = (consent) => ({
6429
+ consent,
6430
+ policyVersion: TELEMETRY_POLICY_VERSION,
6431
+ blockedBy: telemetryBlockedBy(),
6432
+ endpoint: (process.env.CEZ_TELEMETRY_URL || DEFAULT_TELEMETRY_URL).replace(/\/+$/, ''),
6433
+ });
6434
+ const telemetryRoutes = new Hono()
6435
+ .get('/telemetry/consent', async (c) => c.json(telemetryConsentBody(await loadTelemetryConsent())))
6436
+ .put('/telemetry/consent', jsonZodValidator(setTelemetryConsentInputSchema, { message: 'consent must be granted or denied' }), async (c) => {
6437
+ const consent = await setTelemetryConsent(c.req.valid('json').consent);
6438
+ return c.json(telemetryConsentBody(consent));
6439
+ })
6440
+ .post('/telemetry/page', jsonZodValidator(telemetryPageInputSchema, { message: 'invalid route' }), (c) => {
6441
+ track('page_viewed', { label: c.req.valid('json').route }, { sid: deviceSid(c.req.header('x-cezar-sid')) });
6442
+ return c.body(null, 204);
6443
+ })
6444
+ .post('/telemetry/event', jsonZodValidator(telemetryEventInputSchema, { message: 'invalid event' }), (c) => {
6445
+ const { event, label } = c.req.valid('json');
6446
+ track(event, { label }, { sid: deviceSid(c.req.header('x-cezar-sid')) });
6447
+ return c.body(null, 204);
6448
+ })
6449
+ .use('/telemetry/error', bodyLimit({ maxSize: 32 * 1024 }))
6450
+ .post('/telemetry/error', jsonZodValidator(telemetryErrorInputSchema, { message: 'invalid error report' }), (c) => {
6451
+ const body = c.req.valid('json');
6452
+ const err = new Error(body.message);
6453
+ err.name = body.type;
6454
+ err.stack = body.stack;
6455
+ reportError(err, {
6456
+ ...body.context,
6457
+ source: 'cockpit',
6458
+ handler: body.handler,
6459
+ ...servedBuildContext(body.context?.['build.entry']),
6460
+ }, { code: body.code, fingerprint: body.fingerprint, sid: deviceSid(c.req.header('x-cezar-sid')) });
6461
+ return c.body(null, 204);
6462
+ });
6285
6463
  // Workspace-level families answer for the whole workspace, so they are single-mount: never a
6286
6464
  // project-scoped spelling, which would be a second surface to protect with no consumer.
6287
6465
  const workspaceV1 = new Hono()
@@ -6299,7 +6477,8 @@ export function createApp(deps) {
6299
6477
  .route('/', automationChecksRoutes)
6300
6478
  .route('/', runsIndexRoutes)
6301
6479
  .route('/', dashboardRoutes(dashboard, () => ({ tokens: capabilities().tokenUsageMetrics, cost: capabilities().costMetrics }), () => capabilities().automations))
6302
- .route('/', workspaceEventsRoutes);
6480
+ .route('/', workspaceEventsRoutes)
6481
+ .route('/', telemetryRoutes);
6303
6482
  // ---- mount ---------------------------------------------------------------
6304
6483
  // Scoped first, then the unscoped alias bound to the boot project. The paths are disjoint (no
6305
6484
  // route starts with `/p/`), so order between the two never decides a match — but the SPA