@hearsay-tools/squawk 0.18.0-dev.6646 → 0.18.0-dev.6703

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 (255) hide show
  1. package/dist/agent-config/seed.js +1 -6
  2. package/dist/agent-config/seed.js.map +1 -1
  3. package/dist/autosave-git.js +3 -4
  4. package/dist/autosave-git.js.map +1 -1
  5. package/dist/ci-wait/controller.d.ts +37 -37
  6. package/dist/ci-wait/tool-catalog.js +1 -1
  7. package/dist/ci-wait/tool-catalog.js.map +1 -1
  8. package/dist/contract/attention.d.ts +8 -0
  9. package/dist/contract/index.js +14 -0
  10. package/dist/contract/runs.d.ts +15 -0
  11. package/dist/core/backend-detect.js +2 -1
  12. package/dist/core/backend-detect.js.map +1 -1
  13. package/dist/core/codex-hook-mapper.js +2 -1
  14. package/dist/core/codex-hook-mapper.js.map +1 -1
  15. package/dist/core/codex-ui-mapper.js +2 -2
  16. package/dist/core/codex-ui-mapper.js.map +1 -1
  17. package/dist/core/cursor-print-runner.js +2 -1
  18. package/dist/core/cursor-print-runner.js.map +1 -1
  19. package/dist/core/omp-runner.js +4 -5
  20. package/dist/core/omp-runner.js.map +1 -1
  21. package/dist/core/omp-subagent-rows.js +2 -1
  22. package/dist/core/omp-subagent-rows.js.map +1 -1
  23. package/dist/core/opencode-ui-mapper.js +2 -2
  24. package/dist/core/opencode-ui-mapper.js.map +1 -1
  25. package/dist/core/own-lookup.d.ts +5 -0
  26. package/dist/core/own-lookup.js +8 -0
  27. package/dist/core/own-lookup.js.map +1 -0
  28. package/dist/data-gitignore.js +2 -2
  29. package/dist/data-gitignore.js.map +1 -1
  30. package/dist/delegation/cli.js +2 -2
  31. package/dist/delegation/cli.js.map +1 -1
  32. package/dist/delegation/context.js +7 -11
  33. package/dist/delegation/context.js.map +1 -1
  34. package/dist/delegation/conversations.d.ts +4 -2
  35. package/dist/delegation/park-notice.d.ts +5 -1
  36. package/dist/delegation/park-notice.js +7 -0
  37. package/dist/delegation/park-notice.js.map +1 -1
  38. package/dist/delegation/results.js +2 -2
  39. package/dist/delegation/results.js.map +1 -1
  40. package/dist/delegation/routes.d.ts +11 -11
  41. package/dist/delegation/scratch-cleanup.js +6 -3
  42. package/dist/delegation/scratch-cleanup.js.map +1 -1
  43. package/dist/delegation/service.js +2 -4
  44. package/dist/delegation/service.js.map +1 -1
  45. package/dist/delegation/transport.d.ts +77 -77
  46. package/dist/git-command.d.ts +29 -0
  47. package/dist/git-command.js +27 -1
  48. package/dist/git-command.js.map +1 -1
  49. package/dist/git-worktree-lock-helper.d.ts +2 -0
  50. package/dist/git-worktree-lock-helper.js +12 -14
  51. package/dist/git-worktree-lock-helper.js.map +1 -1
  52. package/dist/git-worktree-lock.js +3 -10
  53. package/dist/git-worktree-lock.js.map +1 -1
  54. package/dist/home/command.js +1 -1
  55. package/dist/home/command.js.map +1 -1
  56. package/dist/jobs/cli.js +4 -2
  57. package/dist/jobs/cli.js.map +1 -1
  58. package/dist/jobs/job.d.ts +7 -0
  59. package/dist/jobs/job.js +32 -3
  60. package/dist/jobs/job.js.map +1 -1
  61. package/dist/project-migration/containment.js +2 -4
  62. package/dist/project-migration/containment.js.map +1 -1
  63. package/dist/project-migration/plan.js +2 -4
  64. package/dist/project-migration/plan.js.map +1 -1
  65. package/dist/release/publication.js +2 -2
  66. package/dist/release/publication.js.map +1 -1
  67. package/dist/runs/agent-tmpdir.d.ts +3 -2
  68. package/dist/runs/agent-tmpdir.js +11 -4
  69. package/dist/runs/agent-tmpdir.js.map +1 -1
  70. package/dist/runs/automation-runs.js +4 -3
  71. package/dist/runs/automation-runs.js.map +1 -1
  72. package/dist/runs/conversation-members.js +3 -2
  73. package/dist/runs/conversation-members.js.map +1 -1
  74. package/dist/runs/guarded-json-sql.d.ts +8 -0
  75. package/dist/runs/guarded-json-sql.js +11 -0
  76. package/dist/runs/guarded-json-sql.js.map +1 -0
  77. package/dist/runs/run-database-peer-page.js +3 -4
  78. package/dist/runs/run-database-peer-page.js.map +1 -1
  79. package/dist/runs/run-database-version.d.ts +1 -1
  80. package/dist/runs/run-database-version.js +2 -1
  81. package/dist/runs/run-database-version.js.map +1 -1
  82. package/dist/runs/run-database.js +5 -4
  83. package/dist/runs/run-database.js.map +1 -1
  84. package/dist/runs/run-exits.d.ts +15 -6
  85. package/dist/runs/run-exits.js +13 -4
  86. package/dist/runs/run-exits.js.map +1 -1
  87. package/dist/runs/run-index.js +1 -2
  88. package/dist/runs/run-index.js.map +1 -1
  89. package/dist/runs/store.d.ts +11 -5
  90. package/dist/runs/store.js +21 -20
  91. package/dist/runs/store.js.map +1 -1
  92. package/dist/serve-boot.d.ts +1 -2
  93. package/dist/serve-command.js +25 -15
  94. package/dist/serve-command.js.map +1 -1
  95. package/dist/serve-stop.d.ts +41 -0
  96. package/dist/serve-stop.js +42 -0
  97. package/dist/serve-stop.js.map +1 -0
  98. package/dist/server/activity-routes.d.ts +23 -23
  99. package/dist/server/checkout.d.ts +1 -1
  100. package/dist/server/checkout.js +5 -5
  101. package/dist/server/checkout.js.map +1 -1
  102. package/dist/server/create-project.js +9 -10
  103. package/dist/server/create-project.js.map +1 -1
  104. package/dist/server/forge/draft-pr.js +17 -13
  105. package/dist/server/forge/draft-pr.js.map +1 -1
  106. package/dist/server/git.js +2 -4
  107. package/dist/server/git.js.map +1 -1
  108. package/dist/server/health-cache.d.ts +39 -0
  109. package/dist/server/health-cache.js +66 -0
  110. package/dist/server/health-cache.js.map +1 -0
  111. package/dist/server/repo-pull.js +3 -7
  112. package/dist/server/repo-pull.js.map +1 -1
  113. package/dist/server/server.d.ts +368 -341
  114. package/dist/server/server.js +39 -98
  115. package/dist/server/server.js.map +1 -1
  116. package/dist/server/workspace-live-routes.d.ts +6 -6
  117. package/dist/server-install/platforms/macosx-migration.js +1 -1
  118. package/dist/server-install/platforms/macosx-migration.js.map +1 -1
  119. package/dist/server-install/platforms/ubuntu-vps-migration.js +1 -1
  120. package/dist/server-install/platforms/ubuntu-vps-migration.js.map +1 -1
  121. package/dist/skills-remote.js +8 -12
  122. package/dist/skills-remote.js.map +1 -1
  123. package/dist/task-branch-head.js +2 -4
  124. package/dist/task-branch-head.js.map +1 -1
  125. package/dist/task-cli/discovery.js +2 -4
  126. package/dist/task-cli/discovery.js.map +1 -1
  127. package/dist/ui-state.d.ts +7 -6
  128. package/dist/ui-state.js +31 -6
  129. package/dist/ui-state.js.map +1 -1
  130. package/dist/workflows/continuation-admission.d.ts +2 -1
  131. package/dist/workflows/run/attachment-writer.d.ts +5 -4
  132. package/dist/workflows/run/attachment-writer.js +9 -7
  133. package/dist/workflows/run/attachment-writer.js.map +1 -1
  134. package/dist/workflows/run/compose.d.ts +4 -1
  135. package/dist/workflows/run/compose.js +14 -10
  136. package/dist/workflows/run/compose.js.map +1 -1
  137. package/dist/workflows/run/continuation-acceptance.d.ts +4 -1
  138. package/dist/workflows/run/continuation-acceptance.js +4 -1
  139. package/dist/workflows/run/continuation-acceptance.js.map +1 -1
  140. package/dist/workflows/run/family-reconciler.d.ts +4 -0
  141. package/dist/workflows/run/family-reconciler.js +4 -0
  142. package/dist/workflows/run/family-reconciler.js.map +1 -1
  143. package/dist/workflows/run/inbox-claims.d.ts +2 -0
  144. package/dist/workflows/run/inbox-claims.js +2 -0
  145. package/dist/workflows/run/inbox-claims.js.map +1 -1
  146. package/dist/workflows/run/maintenance-claims.d.ts +2 -0
  147. package/dist/workflows/run/maintenance-claims.js +2 -0
  148. package/dist/workflows/run/maintenance-claims.js.map +1 -1
  149. package/dist/workflows/run/memory-guard.d.ts +6 -6
  150. package/dist/workflows/run/memory-guard.js +8 -8
  151. package/dist/workflows/run/memory-guard.js.map +1 -1
  152. package/dist/workflows/run/prompts.js +1 -1
  153. package/dist/workflows/run/prompts.js.map +1 -1
  154. package/dist/workflows/run/queued-input.d.ts +12 -10
  155. package/dist/workflows/run/queued-input.js +17 -16
  156. package/dist/workflows/run/queued-input.js.map +1 -1
  157. package/dist/workflows/run/run-line.d.ts +5 -4
  158. package/dist/workflows/run/run-line.js +11 -6
  159. package/dist/workflows/run/run-line.js.map +1 -1
  160. package/dist/workflows/run/run-memory.d.ts +52 -0
  161. package/dist/workflows/run/run-memory.js +58 -0
  162. package/dist/workflows/run/run-memory.js.map +1 -0
  163. package/dist/workflows/run/run-settlement.d.ts +21 -4
  164. package/dist/workflows/run/run-settlement.js +60 -22
  165. package/dist/workflows/run/run-settlement.js.map +1 -1
  166. package/dist/workflows/run/session-events.d.ts +2 -0
  167. package/dist/workflows/run/session-events.js +2 -2
  168. package/dist/workflows/run/session-events.js.map +1 -1
  169. package/dist/workflows/run/step-loop.js +1 -1
  170. package/dist/workflows/run/step-loop.js.map +1 -1
  171. package/dist/workflows/run/turn-bookkeeping.d.ts +5 -5
  172. package/dist/workflows/run/turn-bookkeeping.js +7 -7
  173. package/dist/workflows/run/turn-bookkeeping.js.map +1 -1
  174. package/dist/workflows/run/turn-settler.d.ts +3 -0
  175. package/dist/workflows/run/turn-settler.js +7 -3
  176. package/dist/workflows/run/turn-settler.js.map +1 -1
  177. package/dist/workflows/run/wait-engine.d.ts +2 -1
  178. package/dist/workflows/run/wait-registry.d.ts +1 -0
  179. package/dist/workflows/run/wait-registry.js +1 -0
  180. package/dist/workflows/run/wait-registry.js.map +1 -1
  181. package/dist/workflows/run/wake-retries.d.ts +10 -6
  182. package/dist/workflows/run/wake-retries.js +14 -10
  183. package/dist/workflows/run/wake-retries.js.map +1 -1
  184. package/dist/workflows/run/worker-executions.d.ts +11 -2
  185. package/dist/workflows/run/worker-executions.js +15 -6
  186. package/dist/workflows/run/worker-executions.js.map +1 -1
  187. package/dist/workflows/run/worker-orphans.js +2 -0
  188. package/dist/workflows/run/worker-orphans.js.map +1 -1
  189. package/dist/workflows/run/worker-questions.d.ts +3 -2
  190. package/dist/workflows/run/worker-questions.js +6 -5
  191. package/dist/workflows/run/worker-questions.js.map +1 -1
  192. package/dist/workflows/run/worktree-autosave.d.ts +2 -1
  193. package/dist/workflows/run/worktree-autosave.js +2 -1
  194. package/dist/workflows/run/worktree-autosave.js.map +1 -1
  195. package/dist/workflows/run-states.js +3 -3
  196. package/dist/workflows/run-states.js.map +1 -1
  197. package/dist/workflows/run.d.ts +2 -0
  198. package/dist/workflows/run.js +12 -3
  199. package/dist/workflows/run.js.map +1 -1
  200. package/dist/workspace/projects.d.ts +2 -0
  201. package/dist/workspace/projects.js +3 -4
  202. package/dist/workspace/projects.js.map +1 -1
  203. package/dist/worktree-manifest.js +2 -4
  204. package/dist/worktree-manifest.js.map +1 -1
  205. package/package.json +4 -4
  206. package/scripts/measure-transcript-facts-health.mjs +13 -6
  207. package/scripts/mock-ask-answer.mjs +19 -0
  208. package/scripts/mock-codex-app-server.mjs +16 -4
  209. package/scripts/mock-opencode-questions.mjs +89 -0
  210. package/scripts/mock-opencode-serve.mjs +6 -72
  211. package/web/dist/assets/activity-motion-DhLXb8Pt.js +2 -0
  212. package/web/dist/assets/{activity-route--Qj4NT9h.js → activity-route-CpwAMYLn.js} +1 -1
  213. package/web/dist/assets/{agent-accounts-BxpWcFS3.js → agent-accounts-Bc0LJ4SB.js} +1 -1
  214. package/web/dist/assets/attention-BF8NA1XM.js +1 -0
  215. package/web/dist/assets/{commit-diff-panel-DOgakNKv.js → commit-diff-panel-B1KZl0GP.js} +1 -1
  216. package/web/dist/assets/{diff-MoyKcT8Q.js → diff-Ci-qd1lU.js} +2 -2
  217. package/web/dist/assets/{diff-view-BFQcOCEf.js → diff-view-CWZElKoD.js} +1 -1
  218. package/web/dist/assets/{file-preview-BancpZHA.js → file-preview-CoWRr13R.js} +1 -1
  219. package/web/dist/assets/{git-toolbar-ClMasBRM.js → git-toolbar-BYIni94R.js} +1 -1
  220. package/web/dist/assets/{github-BVZ01nJq.js → github-CAPNq5vY.js} +1 -1
  221. package/web/dist/assets/{global-activity-route-DTgywy--.js → global-activity-route-DLEwsMA7.js} +1 -1
  222. package/web/dist/assets/index-CpwAOct4.js +17 -0
  223. package/web/dist/assets/{preview-pane-connected-B5PCWA9a.js → preview-pane-connected-CGw_9VuF.js} +2 -2
  224. package/web/dist/assets/{project-router-CiB1O_5A.js → project-router-oKsNlPN6.js} +1 -1
  225. package/web/dist/assets/{project-scope-context-CSPQyWoO.js → project-scope-context-BBVJVcJp.js} +1 -1
  226. package/web/dist/assets/{prompt-template-menu-VwBcsbqE.js → prompt-template-menu-BZTz2mIG.js} +1 -1
  227. package/web/dist/assets/queries-Be8VyHam.js +1 -0
  228. package/web/dist/assets/{reference-chip-DT-_ninM.js → reference-chip-Ht4xX9-k.js} +1 -1
  229. package/web/dist/assets/{repo-git-7KuJaDRk.js → repo-git-CzVLCWig.js} +1 -1
  230. package/web/dist/assets/{report-reader-CgY75QM2.js → report-reader-iTBkUgg-.js} +1 -1
  231. package/web/dist/assets/reports-BJF1Cl3C.js +1 -0
  232. package/web/dist/assets/run-header-BxB6gyt1.js +2 -0
  233. package/web/dist/assets/{skills-Dnrta_-m.js → skills-DvgHKWgK.js} +1 -1
  234. package/web/dist/assets/{tab-link-BPBiho7-.js → tab-link-Buy1fRFO.js} +1 -1
  235. package/web/dist/assets/{task-changes-C6sDd3Le.js → task-changes-CStxhLFG.js} +1 -1
  236. package/web/dist/assets/{task-commits-CQHxnFJ5.js → task-commits-DhpOAdOf.js} +1 -1
  237. package/web/dist/assets/{task-files-DK8Demuc.js → task-files-COmKUUfN.js} +1 -1
  238. package/web/dist/assets/{task-github-item-DgmmFFtN.js → task-github-item-BNLeAz58.js} +1 -1
  239. package/web/dist/assets/{task-thread-Dg9VWJq6.js → task-thread-DjSFvEQe.js} +6 -6
  240. package/web/dist/assets/{thread-state-DIMUAyFk.js → thread-state-B5tTsVNm.js} +1 -1
  241. package/web/dist/assets/use-desktop-BPWIJ0Kw.js +1 -0
  242. package/web/dist/assets/{use-hand-to-agent-state-D-yaVRRx.js → use-hand-to-agent-state-Ce6QW2j_.js} +1 -1
  243. package/web/dist/assets/{useInfiniteQuery-Q8eFXz-L.js → useInfiniteQuery-Yn58_Fkn.js} +1 -1
  244. package/web/dist/assets/useQuery-C1xFF0nd.js +1 -0
  245. package/web/dist/assets/{workflows-W_uriBcj.js → workflows-CN8uKYnY.js} +1 -1
  246. package/web/dist/assets/{ws-B-tB133E.js → ws-DbXGHAke.js} +1 -1
  247. package/web/dist/index.html +12 -12
  248. package/web/dist/assets/activity-motion-CEnf2rDh.js +0 -2
  249. package/web/dist/assets/attention-BDa7opY9.js +0 -1
  250. package/web/dist/assets/index-CsOa03VW.js +0 -17
  251. package/web/dist/assets/queries-pj368bmB.js +0 -1
  252. package/web/dist/assets/reports-CxTUchWh.js +0 -1
  253. package/web/dist/assets/run-header-BcX23gw7.js +0 -2
  254. package/web/dist/assets/use-desktop-Bq_Qh5ur.js +0 -1
  255. package/web/dist/assets/useQuery-BoLjCS2U.js +0 -1
@@ -110,6 +110,7 @@ import { worktreeDiff, worktreeSizeBytes } from '../git-worktree.js';
110
110
  import { releaseThenRemoveWorktree } from '../git-worktree-release.js';
111
111
  import { isReclaimable, reclaimWorktree, reclaimWorktrees, selectReclaimableWorktrees } from '../runs/retention.js';
112
112
  import { getBranches, getCommit, getDiff, getLogWithParents, getRepoInfo, getStatus, getTracking } from './git.js';
113
+ import { createHealthCache, HEALTH_TTL_MS } from './health-cache.js';
113
114
  import { createGithubBranchForge } from './repo-branch-forge.js';
114
115
  import { attributeLog, classifyInputFor, deleteBranches, forgetRepoBranches, readRepoBranchCounts, readRepoBranches } from './repo-branches.js';
115
116
  import { claimRepoGitMutation, localPullBranches, pullRepoCheckout } from './repo-pull.js';
@@ -133,7 +134,7 @@ import { mergeWriteWorkspaceUiState, readWorkspaceUiState } from '../workspace/u
133
134
  import { checkoutRepo } from './checkout.js';
134
135
  import { createProject, listGithubOwners } from './create-project.js';
135
136
  import { createWorkspaceRunFeed } from './workspace-run-feed.js';
136
- import { readProjectUiState, readUiState, writeProjectUiState } from '../ui-state.js';
137
+ import { mergeWriteProjectUiState, readUiState } from '../ui-state.js';
137
138
  import { agentHomePaths, expandTilde } from '../paths.js';
138
139
  import { isLoopbackHostHeader, normalizeHostname, resolveCapabilities } from './capabilities.js';
139
140
  import { browseDirectory, isInsideBrowseRoot, isLexicallyInsideBrowseRoot, resolveBrowseRoot } from './fs-browse.js';
@@ -678,11 +679,9 @@ export function createApp(deps) {
678
679
  .then((changed) => {
679
680
  if (!changed)
680
681
  return;
681
- // Probe is settled; finish any cold snapshot, then refresh both transports separately.
682
- void (async () => {
683
- await healthInFlight?.catch(() => { });
684
- await refreshHealth();
685
- })().catch(() => { });
682
+ // Probe is settled; publish the new checks to both transports. Only availability changed:
683
+ // re-reading Git would spawn processes on this loop (hearsay-tools/squawk#3355).
684
+ void healthCache.patch((payload) => ({ ...payload, checks: backendChecks })).catch(() => { });
686
685
  });
687
686
  }
688
687
  return backendChecks;
@@ -730,69 +729,24 @@ export function createApp(deps) {
730
729
  bootProject: workspace.bootProject,
731
730
  };
732
731
  };
733
- // ---- server-side health cache (stale-while-revalidate) -------------------
734
- // The snapshot still reads git and workspace state. Agent-CLI availability
735
- // probes have their own nonblocking cache above. Paying that on the browser's FIRST `GET /api/health` is
736
- // exactly the few-seconds-blank the cockpit showed at load. So on the live
737
- // server the snapshot is computed at the server's OWN pace: both the GET and
738
- // the WS `health` topic serve the cached value immediately and revalidate
739
- // behind the response, and the cache is pre-warmed at boot so that first
740
- // request lands on a warm value instead of the cold compute.
741
- const HEALTH_TTL_MS = 5_000;
742
- // The staleness CEILING, which is a different job from the TTL above. The TTL
743
- // decides how often a revalidation is kicked off; on its own it bounds nothing,
744
- // because the revalidation is fire-and-forget. While a cockpit holds the
745
- // `health` topic the publisher's interval keeps the cache warm and the two are
746
- // the same number — but the normal state of a background `hsq serve` is NO
747
- // subscriber, and then nothing refreshes the cache at all: the next `GET
748
- // /api/health`, an hour later, would answer with the boot pre-warm's payload
749
- // and only the request AFTER it would see the truth. `repo.branch` going stale there is
750
- // literally #369, so past this age correctness beats the latency win and the
751
- // read waits for the compute. `refreshHealth` dedupes, so waiting costs one.
752
- const HEALTH_MAX_STALE_MS = 60_000;
753
- let healthCache;
754
- let healthInFlight;
755
- // Set while the topic has a subscriber; a change a refresh detects is pushed
756
- // here (a noop when nobody is listening).
732
+ // Stale-while-revalidate cache over the snapshot; see health-cache.ts.
733
+ // Set while the topic has a subscriber (a noop when nobody is listening).
757
734
  let publishHealth = () => { };
758
- const refreshHealth = () => {
759
- // Dedupe: a GET's background revalidation and the topic's interval tick
760
- // share ONE repository/workspace compute rather than racing two.
761
- if (healthInFlight)
762
- return healthInFlight;
763
- healthInFlight = (async () => {
764
- try {
765
- const payload = await healthSnapshot();
766
- const body = JSON.stringify(payload);
767
- const changed = body !== healthCache?.body;
768
- healthCache = { at: Date.now(), payload, body };
769
- if (changed) {
770
- publishHealth(payload);
771
- workspaceEvents.emit('health', payload);
772
- } // only a real change reaches either transport
773
- return payload;
774
- }
775
- finally {
776
- healthInFlight = undefined;
777
- }
778
- })();
779
- return healthInFlight;
780
- };
735
+ const healthCache = createHealthCache({
736
+ snapshot: healthSnapshot,
737
+ publish: (payload) => {
738
+ publishHealth(payload);
739
+ workspaceEvents.emit('health', payload);
740
+ },
741
+ });
742
+ const refreshHealth = () => healthCache.refresh();
781
743
  // The read the GET and the topic snapshot share. On the live server (a hub is
782
- // injected) it answers from cache instantly and revalidates behind the
783
- // response; without a hub — a bare app in tests — there is no refresher
784
- // keeping a cache coherent, so it computes fresh, exactly as before.
744
+ // injected) it answers from cache; without a hub — a bare app in tests — there is
745
+ // no refresher keeping a cache coherent, so it computes fresh, exactly as before.
785
746
  const readHealth = async () => {
786
747
  if (!deps.socketHub)
787
748
  return healthSnapshot();
788
- if (!healthCache)
789
- return refreshHealth(); // first ever: nothing to serve yet
790
- const age = Date.now() - healthCache.at;
791
- if (age > HEALTH_MAX_STALE_MS)
792
- return refreshHealth(); // too old to serve — wait for the truth
793
- if (age > HEALTH_TTL_MS)
794
- void refreshHealth(); // stale: refresh, don't wait on it
795
- return { ...healthCache.payload, capabilities: capabilities() }; // per request, like the gates (ADR 0055)
749
+ return healthCache.read((payload) => ({ ...payload, capabilities: capabilities() })); // per request, like the gates (ADR 0055)
796
750
  };
797
751
  // ---- chained family: health (workspace-level) ----------------------------
798
752
  // Written as ONE chained expression rather than a loose `app.get(...)`
@@ -1624,6 +1578,12 @@ export function createApp(deps) {
1624
1578
  const registered = await registerFolder(parsed.data.root, 'local');
1625
1579
  if (registered.status !== 200)
1626
1580
  return c.json(registered.body, registered.status);
1581
+ if (registered.existing) {
1582
+ // 409 with the EXISTING entry (spec): the dialog treats it as "you already have this one"
1583
+ // and navigates there rather than dead-ending.
1584
+ const { project } = registered.body;
1585
+ return c.json({ project, error: `already registered as ${project.id}` }, 409);
1586
+ }
1627
1587
  return c.json(registered.body, 200);
1628
1588
  })
1629
1589
  .delete('/projects/:projectId', async (c) => {
@@ -1872,15 +1832,15 @@ export function createApp(deps) {
1872
1832
  // `{ error, reason }` degradation, mirroring the GitHub pane.
1873
1833
  return c.json('reason' in result ? { error: result.error, reason: result.reason } : { error: result.error }, result.status);
1874
1834
  }
1835
+ // An existing entry for the same root (its folder had been deleted) is a success too: the
1836
+ // project the user asked for is there (hearsay-tools/squawk#1086).
1875
1837
  const registered = await registerFolder(result.target, 'checkout');
1876
1838
  if (registered.status !== 200) {
1877
1839
  // The clone SUCCEEDED and its files are legitimately the user's, so this
1878
1840
  // path deliberately does NOT clean up — an unregisterable checkout is a
1879
1841
  // registry problem, not a reason to delete a repo we just fetched. Say
1880
1842
  // where it is so they can register it by hand.
1881
- const { body } = registered;
1882
- const error = 'error' in body && body.error ? body.error : 'could not register the checkout';
1883
- return c.json({ error: `${error} (the clone is at ${result.target})` }, registered.status);
1843
+ return c.json({ error: `${registered.body.error} (the clone is at ${result.target})` }, registered.status);
1884
1844
  }
1885
1845
  return c.json(registered.body, 200);
1886
1846
  })
@@ -1928,25 +1888,16 @@ export function createApp(deps) {
1928
1888
  }
1929
1889
  // GitHub-backed projects register as `checkout` (they have an origin the
1930
1890
  // clone flow would also produce); a local-only repo is `local`.
1891
+ // A new entry, or the existing one for the same root — what creating a registered project
1892
+ // whose folder had been deleted produces. Both are a success.
1931
1893
  const registered = await registerFolder(result.target, result.slug ? 'checkout' : 'local');
1932
- // A new entry (200), or the existing one for the same root (409 "already registered") — what
1933
- // creating a registered project whose folder had been deleted produces. The user asked for
1934
- // that project and it is there, so both are a success. (An if/else chain, not a helper:
1935
- // only narrowing `registered` keeps the error bodies out of the route's 200 type.)
1936
- let project;
1937
- if (registered.status === 200)
1938
- project = registered.body.project;
1939
- else if (registered.status === 409 && 'project' in registered.body)
1940
- project = registered.body.project;
1941
- else {
1894
+ if (registered.status !== 200) {
1942
1895
  // As with a clone: the repository is the user's now, so it stays — and a GitHub warning
1943
1896
  // rides along, since its finishing commands are the only record of what is left to do.
1944
- const { body } = registered;
1945
- const error = 'error' in body && body.error ? body.error : 'could not register the new project';
1946
1897
  const warning = result.warning ? `\n${result.warning}` : '';
1947
- return c.json({ error: `${error} (the project is at ${result.target})${warning}` }, registered.status);
1898
+ return c.json({ error: `${registered.body.error} (the project is at ${result.target})${warning}` }, registered.status);
1948
1899
  }
1949
- const body = { project, ...(result.warning ? { warning: result.warning } : {}) };
1900
+ const body = { project: registered.body.project, ...(result.warning ? { warning: result.warning } : {}) };
1950
1901
  return c.json(body, 200);
1951
1902
  });
1952
1903
  /** Hosted containment for a path that may not exist yet: lexical for the
@@ -1973,7 +1924,8 @@ export function createApp(deps) {
1973
1924
  * The register-a-folder half of `POST /api/projects`, factored out so the
1974
1925
  * checkout route (step 4.3) commits its fresh clone through the SAME guards
1975
1926
  * and the same `project-added` emission rather than a second copy of them.
1976
- * Returns the status + body for the caller to answer with.
1927
+ * A root the registry already holds is a success with `existing: true`; each
1928
+ * route decides how to answer it.
1977
1929
  */
1978
1930
  const registerFolder = async (spelled, source) => {
1979
1931
  // `~` is expanded for the same reason `/api/fs/browse` expands it: the
@@ -2066,18 +2018,11 @@ export function createApp(deps) {
2066
2018
  body: { error: err instanceof Error ? err.message : String(err) },
2067
2019
  };
2068
2020
  }
2069
- if (known) {
2070
- // 409 with the EXISTING entry (spec): the dialog treats it as "you
2071
- // already have this one" and navigates there rather than dead-ending.
2072
- return {
2073
- status: 409,
2074
- body: { project, error: `already registered as ${project.id}` },
2075
- };
2076
- }
2077
2021
  // Only a genuinely new project is an event — a re-add is a no-op for every
2078
2022
  // open cockpit's sidebar.
2079
- workspaceEvents.emit('project-added', { project });
2080
- return { status: 200, body: { project } };
2023
+ if (!known)
2024
+ workspaceEvents.emit('project-added', { project });
2025
+ return { status: 200, body: { project }, existing: known };
2081
2026
  };
2082
2027
  // Deregister a project (multi-project spec, step 4.4 — Settings → Projects,
2083
2028
  // the per-row "Remove"). READ THIS BEFORE TOUCHING THE HANDLER: the ONLY
@@ -2290,20 +2235,16 @@ export function createApp(deps) {
2290
2235
  // On `use`, not inline on the route — see the workspace ui-state PUT above.
2291
2236
  .use('/ui-state', bodyLimit({ maxSize: UI_STATE_BODY_LIMIT }))
2292
2237
  .put('/ui-state', jsonZodValidator(uiStateBody), async (c) => {
2293
- const { root: repoRoot, dataDir } = c.get('project');
2294
2238
  // `.passthrough()` keeps unknown prefs, but a
2295
2239
  // single request may not stuff an unbounded key set (#429) — the shared
2296
2240
  // schema+cap half of both ui-state routes lives in `uiStateBody`.
2297
- const parsed = { data: c.req.valid('json') };
2298
- const merged = { ...(await readProjectUiState(repoRoot)), ...parsed.data };
2241
+ const patch = c.req.valid('json');
2299
2242
  try {
2300
- await mkdir(dataDir, { recursive: true });
2301
- await writeProjectUiState(repoRoot, merged);
2243
+ return c.json(await mergeWriteProjectUiState(c.get('project').root, (current) => ({ ...current, ...patch })));
2302
2244
  }
2303
2245
  catch (err) {
2304
2246
  return c.json({ error: err instanceof Error ? err.message : String(err) }, 500);
2305
2247
  }
2306
- return c.json(merged);
2307
2248
  });
2308
2249
  // ---- chained family: workflows (project-scoped) --------------------------
2309
2250
  // One chained expression, mounted by `createApp` into BOTH the legacy `api`