@hearsay-tools/squawk 0.18.0-pr3437.6046 → 0.18.0-pr3437.6101

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 (172) hide show
  1. package/dist/artifacts/store.js +1 -1
  2. package/dist/artifacts/store.js.map +1 -1
  3. package/dist/automations/enabled.d.ts +2 -0
  4. package/dist/automations/enabled.js +6 -0
  5. package/dist/automations/enabled.js.map +1 -0
  6. package/dist/automations/store.js +1 -1
  7. package/dist/automations/store.js.map +1 -1
  8. package/dist/autosave-commit.d.ts +52 -0
  9. package/dist/autosave-commit.js +378 -0
  10. package/dist/autosave-commit.js.map +1 -0
  11. package/dist/ci-wait/controller.d.ts +38 -47
  12. package/dist/ci-wait/controller.js +2 -15
  13. package/dist/ci-wait/controller.js.map +1 -1
  14. package/dist/ci-wait/errors.d.ts +9 -0
  15. package/dist/ci-wait/errors.js +14 -0
  16. package/dist/ci-wait/errors.js.map +1 -1
  17. package/dist/ci-wait/resource-pool.d.ts +17 -0
  18. package/dist/ci-wait/resource-pool.js +51 -0
  19. package/dist/ci-wait/resource-pool.js.map +1 -0
  20. package/dist/ci-wait/resources.d.ts +5 -8
  21. package/dist/ci-wait/resources.js +8 -42
  22. package/dist/ci-wait/resources.js.map +1 -1
  23. package/dist/ci-wait/tool-catalog.js +2 -1
  24. package/dist/ci-wait/tool-catalog.js.map +1 -1
  25. package/dist/config.js +1 -1
  26. package/dist/config.js.map +1 -1
  27. package/dist/core/cursor-print-runner.js +2 -2
  28. package/dist/core/cursor-print-runner.js.map +1 -1
  29. package/dist/core/process-stat.d.ts +36 -0
  30. package/dist/core/process-stat.js +101 -0
  31. package/dist/core/process-stat.js.map +1 -0
  32. package/dist/delegation/process-liveness.d.ts +2 -10
  33. package/dist/delegation/process-liveness.js +3 -42
  34. package/dist/delegation/process-liveness.js.map +1 -1
  35. package/dist/delegation/routes.d.ts +11 -11
  36. package/dist/delegation/transport.d.ts +13 -13
  37. package/dist/detached-process.d.ts +2 -23
  38. package/dist/detached-process.js +2 -61
  39. package/dist/detached-process.js.map +1 -1
  40. package/dist/git-worktree.d.ts +0 -52
  41. package/dist/git-worktree.js +2 -374
  42. package/dist/git-worktree.js.map +1 -1
  43. package/dist/headless-run.js +2 -1
  44. package/dist/headless-run.js.map +1 -1
  45. package/dist/home/leases.js +1 -1
  46. package/dist/home/leases.js.map +1 -1
  47. package/dist/home/migrate.js +1 -1
  48. package/dist/home/migrate.js.map +1 -1
  49. package/dist/home/migration-accounts.js +1 -1
  50. package/dist/home/migration-accounts.js.map +1 -1
  51. package/dist/home/migration-claim.js +1 -1
  52. package/dist/home/migration-claim.js.map +1 -1
  53. package/dist/home/private-files.js +1 -1
  54. package/dist/home/private-files.js.map +1 -1
  55. package/dist/home/process-identity.js +1 -1
  56. package/dist/home/process-identity.js.map +1 -1
  57. package/dist/home/recovery.d.ts +0 -1
  58. package/dist/home/recovery.js +0 -1
  59. package/dist/home/recovery.js.map +1 -1
  60. package/dist/home/write-lock.js +1 -1
  61. package/dist/home/write-lock.js.map +1 -1
  62. package/dist/project-fence.d.ts +63 -0
  63. package/dist/project-fence.js +146 -0
  64. package/dist/project-fence.js.map +1 -0
  65. package/dist/project-migration/live.js +1 -1
  66. package/dist/project-migration/live.js.map +1 -1
  67. package/dist/runs/live-tasks.d.ts +10 -0
  68. package/dist/runs/live-tasks.js +33 -0
  69. package/dist/runs/live-tasks.js.map +1 -0
  70. package/dist/runs/webhook.d.ts +1 -3
  71. package/dist/runs/webhook.js +2 -10
  72. package/dist/runs/webhook.js.map +1 -1
  73. package/dist/serve-command.js +3 -2
  74. package/dist/serve-command.js.map +1 -1
  75. package/dist/server/capabilities.js +2 -1
  76. package/dist/server/capabilities.js.map +1 -1
  77. package/dist/server/cockpit-ownership.d.ts +2 -59
  78. package/dist/server/cockpit-ownership.js +4 -143
  79. package/dist/server/cockpit-ownership.js.map +1 -1
  80. package/dist/server/forge/draft-pr.js +1 -1
  81. package/dist/server/forge/draft-pr.js.map +1 -1
  82. package/dist/server/home-recovery-routes.js +2 -1
  83. package/dist/server/home-recovery-routes.js.map +1 -1
  84. package/dist/server/live-routes.d.ts +6 -6
  85. package/dist/server/project-context.d.ts +5 -11
  86. package/dist/server/project-context.js +1 -32
  87. package/dist/server/project-context.js.map +1 -1
  88. package/dist/server/reports-api.d.ts +2 -2
  89. package/dist/server/server.d.ts +1752 -1752
  90. package/dist/ui-state.js +1 -1
  91. package/dist/ui-state.js.map +1 -1
  92. package/dist/voice/routes.d.ts +19 -19
  93. package/dist/workflows/run/compose.d.ts +2 -2
  94. package/dist/workflows/run/continuation-session.d.ts +1 -1
  95. package/dist/workflows/run/input-delivery.d.ts +1 -1
  96. package/dist/workflows/run/input-delivery.js +3 -4
  97. package/dist/workflows/run/input-delivery.js.map +1 -1
  98. package/dist/workflows/run/launch-context.js +3 -3
  99. package/dist/workflows/run/launch-context.js.map +1 -1
  100. package/dist/workflows/run/run-settlement.d.ts +1 -1
  101. package/dist/workflows/run/run-settlement.js.map +1 -1
  102. package/dist/workflows/run/session-events.js +1 -1
  103. package/dist/workflows/run/session-events.js.map +1 -1
  104. package/dist/workflows/run/squawk-tools.d.ts +2 -2
  105. package/dist/workflows/run/worktree-autosave.d.ts +1 -1
  106. package/dist/workflows/run/worktree-autosave.js +1 -1
  107. package/dist/workflows/run/worktree-autosave.js.map +1 -1
  108. package/dist/workflows/run.d.ts +2 -0
  109. package/dist/workflows/run.js +1 -2
  110. package/dist/workflows/run.js.map +1 -1
  111. package/dist/workspace/registry-entry.d.ts +4 -0
  112. package/dist/workspace/registry-entry.js +11 -0
  113. package/dist/workspace/registry-entry.js.map +1 -0
  114. package/package.json +4 -4
  115. package/scripts/benchmark-family-reconcile.ts +2 -1
  116. package/scripts/benchmark-run-store.ts +2 -1
  117. package/scripts/benchmark-stuck-destroys.ts +2 -1
  118. package/scripts/benchmark-workspace-events.ts +2 -1
  119. package/scripts/measure-transcript-facts-health.mjs +2 -1
  120. package/scripts/mock-lifecycle.d.mts +2 -0
  121. package/scripts/mock-lifecycle.mjs +5 -1
  122. package/web/dist/assets/{activity-motion-Dld5ms7x.js → activity-motion-DKwwsRr3.js} +1 -1
  123. package/web/dist/assets/activity-route-DIPqGSX9.js +1 -0
  124. package/web/dist/assets/agent-accounts-BNlpWTOY.js +18 -0
  125. package/web/dist/assets/commit-diff-panel-V_1QPI6-.js +1 -0
  126. package/web/dist/assets/diff-CeZUO8N3.js +3 -0
  127. package/web/dist/assets/{diff-view-DcvEkA3I.js → diff-view-t7aBbbYR.js} +4 -4
  128. package/web/dist/assets/file-preview-DePQ7br9.js +2 -0
  129. package/web/dist/assets/git-toolbar-wuy8ssaR.js +1 -0
  130. package/web/dist/assets/github-BnmHJIdi.js +1 -0
  131. package/web/dist/assets/global-activity-route-WbzruEHL.js +1 -0
  132. package/web/dist/assets/index-DOC5F0jG.js +17 -0
  133. package/web/dist/assets/index-U_ryo80X.css +1 -0
  134. package/web/dist/assets/preview-pane-connected-DA-o4lox.js +3 -0
  135. package/web/dist/assets/prompt-template-menu-D4-inlE4.js +1 -0
  136. package/web/dist/assets/reference-chip-Drpbf-MP.js +1 -0
  137. package/web/dist/assets/repo-git-CPAzGsXP.js +1 -0
  138. package/web/dist/assets/report-reader-258jGuDd.js +1 -0
  139. package/web/dist/assets/reports-Bi62-scJ.js +1 -0
  140. package/web/dist/assets/{run-header-BDtR-uVy.js → run-header-CtB7SQZX.js} +2 -2
  141. package/web/dist/assets/skills-DgMECGzl.js +1 -0
  142. package/web/dist/assets/{task-changes-NqJ_-tod.js → task-changes-Cl5qY22F.js} +1 -1
  143. package/web/dist/assets/task-commits-BeWKWgm7.js +1 -0
  144. package/web/dist/assets/task-files-CetL9fpi.js +1 -0
  145. package/web/dist/assets/task-github-item-CPMpjXAi.js +1 -0
  146. package/web/dist/assets/{task-thread-DkF28KyV.js → task-thread-HhiSFO55.js} +7 -7
  147. package/web/dist/assets/{thread-state-C8XI1WNf.js → thread-state-CiNCxsdq.js} +1 -1
  148. package/web/dist/assets/use-hand-to-agent-state-07Nw6AlG.js +1 -0
  149. package/web/dist/assets/workflows-D1sS-h0j.js +7 -0
  150. package/web/dist/index.html +6 -6
  151. package/web/dist/assets/activity-route-CNZPeNfz.js +0 -1
  152. package/web/dist/assets/agent-accounts-B-Gpf8IN.js +0 -18
  153. package/web/dist/assets/commit-diff-panel-NClCG68F.js +0 -1
  154. package/web/dist/assets/control-locations-B88tMDqg.js +0 -1
  155. package/web/dist/assets/diff-nIehE-T6.js +0 -3
  156. package/web/dist/assets/file-preview-D5OEhi_p.js +0 -2
  157. package/web/dist/assets/git-toolbar-6nOTPb_C.js +0 -1
  158. package/web/dist/assets/github-kqE3kY6l.js +0 -1
  159. package/web/dist/assets/github-sidebar-model-DkUAF09l.js +0 -1
  160. package/web/dist/assets/global-activity-route-BExanylS.js +0 -1
  161. package/web/dist/assets/index-9YmaiQ1k.css +0 -1
  162. package/web/dist/assets/index-DBNT3CYH.js +0 -17
  163. package/web/dist/assets/preview-pane-connected-BN0BWrKD.js +0 -3
  164. package/web/dist/assets/repo-git-CPEbNCTy.js +0 -1
  165. package/web/dist/assets/report-reader-Ltc8JdIV.js +0 -1
  166. package/web/dist/assets/reports-DHuR8gwU.js +0 -1
  167. package/web/dist/assets/skills-DTowIB5z.js +0 -1
  168. package/web/dist/assets/task-commits-BbhrfhCT.js +0 -1
  169. package/web/dist/assets/task-files-n29-eIMD.js +0 -1
  170. package/web/dist/assets/task-github-item-BwS8ltjs.js +0 -1
  171. package/web/dist/assets/use-hand-to-agent-state-CY43kvaa.js +0 -1
  172. package/web/dist/assets/workflows-CWFMDlCn.js +0 -7
@@ -0,0 +1,378 @@
1
+ import { logPrefix } from './home/display.js';
2
+ import { fallbackProjectWriteError } from './project-paths.js';
3
+ import { autosaveGit } from './autosave-git.js';
4
+ import { realpathSync } from 'node:fs';
5
+ import { readFile, stat } from 'node:fs/promises';
6
+ import { join, resolve } from 'node:path';
7
+ /**
8
+ * Leftover merge-conflict markers, anchored at line start as git writes them.
9
+ * All three must appear *in order*: a bare `=======` line is ordinary Markdown
10
+ * (a setext heading underline), and any of the three alone — or the pair
11
+ * `<<<<<<<`/`>>>>>>>` in either order — occurs legitimately in checked-in
12
+ * patch fixtures and in docs that demonstrate conflict markers. Requiring the
13
+ * full ordered triple is what separates a real conflict from a file that
14
+ * merely talks about one.
15
+ */
16
+ const CONFLICT_START = /^<{7}(?:\s|$)/;
17
+ const CONFLICT_MID = /^={7}(?:\s|$)/;
18
+ const CONFLICT_END = /^>{7}(?:\s|$)/;
19
+ /**
20
+ * Largest file the marker scan will read. Autosave runs as often as every 90 s,
21
+ * and decoding a large tracked file into a JS string each time is a real memory
22
+ * cost for a check that only ever looks at a few marker lines. Oversized files
23
+ * are skipped, which fails *open* — consistent with the rest of this guard,
24
+ * where a false negative costs noise and a false positive costs the recovery
25
+ * point.
26
+ */
27
+ const MARKER_SCAN_MAX_BYTES = 2_000_000;
28
+ /** Does this file carry a complete, ordered conflict hunk? */
29
+ function hasConflictMarkers(text) {
30
+ let want = 0; // 0: `<<<<<<<`, 1: `=======`, 2: `>>>>>>>`
31
+ for (const line of text.split('\n')) {
32
+ if (want === 0) {
33
+ if (CONFLICT_START.test(line))
34
+ want = 1;
35
+ }
36
+ else if (want === 1) {
37
+ if (CONFLICT_MID.test(line))
38
+ want = 2;
39
+ }
40
+ else if (CONFLICT_END.test(line)) {
41
+ return true;
42
+ }
43
+ }
44
+ return false;
45
+ }
46
+ /** Serialize all autosave entry points, including periodic/final flush overlap. */
47
+ const autosaves = new Map();
48
+ /** HEAD's symbolic ref, `null` on a detached HEAD, `undefined` when the read failed. */
49
+ async function readAutosaveHead(dir, git) {
50
+ // Exit 1 under -q is a detached HEAD; anything else is a failed read.
51
+ const ref = await git(dir, ['symbolic-ref', '-q', 'HEAD']);
52
+ if (!ref.ok && ref.code !== 1)
53
+ return undefined;
54
+ return ref.ok ? ref.stdout.trim() : null;
55
+ }
56
+ function autosaveBranchName(head) {
57
+ return head?.startsWith('refs/heads/') ? head.slice('refs/heads/'.length) : head;
58
+ }
59
+ function reportAutosave(onOutcome, outcome) {
60
+ try {
61
+ onOutcome?.(outcome);
62
+ }
63
+ catch { /* Reporting must not change what the save did. */ }
64
+ }
65
+ // HEAD is not the task branch: the work stays uncommitted, reported with the paths status saw.
66
+ function skipAutosave(head, status, onOutcome) {
67
+ reportAutosave(onOutcome, { result: 'skipped', branch: autosaveBranchName(head), changedPaths: status.split('\n').filter(Boolean).length });
68
+ return 'skipped';
69
+ }
70
+ /** A resolved merge, cherry-pick or revert the agent has not concluded: `git commit`
71
+ * would conclude it under `cezar autosave`. The agent concludes it with its own
72
+ * message; the next flush picks the work up (hearsay-tools/cezarion#1004). Asked of
73
+ * Git, not looked up as files: only MERGE_HEAD is always a file. CHERRY_PICK_HEAD and
74
+ * REVERT_HEAD are root refs in the ref backend, which a reftable repository keeps in
75
+ * its reftable stack, so a file check would miss them there. */
76
+ async function pendingAutosaveOperation(dir, reason, git) {
77
+ for (const pending of ['MERGE_HEAD', 'CHERRY_PICK_HEAD', 'REVERT_HEAD']) {
78
+ const found = await git(dir, ['rev-parse', '--verify', '-q', pending]);
79
+ if (found.ok) {
80
+ console.warn(`${logPrefix()} skipping ${reason} autosave in ${dir}: ${pending} is set, the operation is not concluded`);
81
+ return 'refused';
82
+ }
83
+ if (found.code !== 1)
84
+ return 'failed';
85
+ }
86
+ return null;
87
+ }
88
+ /** Commit as the CURRENT git user, so the branch's commits (and any PR opened from it) are
89
+ * attributed to the real author and pass CLA / attribution checks. The old hardcoded
90
+ * `cezar <cezar@local>` identity made every autosave look like a non-GitHub user. Fall back to
91
+ * that identity ONLY when the machine has no git identity configured — otherwise `git commit`
92
+ * would fail and the autosave (the run's recovery point) would be lost. */
93
+ async function autosaveIdentityArgs(dir, git) {
94
+ const name = await git(dir, ['config', 'user.name']);
95
+ if (!name.ok && name.code !== 1)
96
+ return 'failed';
97
+ const email = await git(dir, ['config', 'user.email']);
98
+ if (!email.ok && email.code !== 1)
99
+ return 'failed';
100
+ return (name.ok && name.stdout.trim() && email.ok && email.stdout.trim())
101
+ ? [] : ['-c', 'user.name=cezar', '-c', 'user.email=cezar@local'];
102
+ }
103
+ async function commitAutosaveOnHead(dir, identityArgs, message, branch, onOutcome, git) {
104
+ const commit = await git(dir, [...identityArgs, 'commit', '--no-verify', '-m', message]);
105
+ if (!commit.ok)
106
+ return 'failed';
107
+ if (onOutcome) {
108
+ // The commit already landed: a failed read loses the sha, never the report.
109
+ const sha = await git(dir, ['rev-parse', '--short', 'HEAD']);
110
+ reportAutosave(onOutcome, { result: 'committed', sha: (sha.ok && sha.stdout.trim()) || null, branch });
111
+ }
112
+ return 'committed';
113
+ }
114
+ /** The task branch is written by compare-and-swap, never through HEAD: the agent can
115
+ * check another branch out after the `symbolic-ref` check in `readAutosaveHead`, and `git commit`
116
+ * resolves HEAD again at its own start, so the save landed on the agent's branch
117
+ * (review on hearsay-tools/cezarion#1111). `update-ref <ref> <new> <old>` moves the
118
+ * branch only while it still points at the tip read here (an unborn one: while it
119
+ * still does not exist); a moved branch fails the save and the next flush retries.
120
+ * Unlike the porcelain this runs no prepare-commit-msg or post-commit hook
121
+ * (`--no-verify` already skipped pre-commit and commit-msg), and the reflog entry
122
+ * reads `cezar autosave (<reason>)` without the `commit: ` prefix. commit-tree
123
+ * stopped reading commit.gpgSign in Git 2.9 (its release notes tell scripts to read
124
+ * it and pass -S), so it is read here: a user who signs every commit still does. */
125
+ async function writeAutosaveCommit(dir, taskBranch, identityArgs, message, git) {
126
+ const ref = `refs/heads/${taskBranch}`;
127
+ const tip = await git(dir, ['rev-parse', '--verify', '-q', ref]);
128
+ if (!tip.ok && tip.code !== 1)
129
+ return 'failed';
130
+ const parent = tip.ok ? tip.stdout.trim() : '';
131
+ const written = await git(dir, ['write-tree']);
132
+ const tree = written.stdout.trim();
133
+ if (!written.ok || !tree)
134
+ return 'failed';
135
+ if (parent) {
136
+ // Dirty when status looked, identical once staged: nothing to save.
137
+ const parentTree = await git(dir, ['rev-parse', '--verify', '-q', `${parent}^{tree}`]);
138
+ if (!parentTree.ok)
139
+ return 'failed';
140
+ if (parentTree.stdout.trim() === tree)
141
+ return 'nothing-to-do';
142
+ }
143
+ const sign = await git(dir, ['config', '--type=bool', 'commit.gpgsign']);
144
+ if (!sign.ok && sign.code !== 1)
145
+ return 'failed';
146
+ const created = await git(dir, [
147
+ ...identityArgs,
148
+ 'commit-tree',
149
+ ...(sign.ok && sign.stdout.trim() === 'true' ? ['-S'] : []),
150
+ tree,
151
+ ...(parent ? ['-p', parent] : []),
152
+ '-m',
153
+ message,
154
+ ]);
155
+ const sha = created.stdout.trim();
156
+ if (!created.ok || !sha)
157
+ return 'failed';
158
+ return { sha, parent };
159
+ }
160
+ async function publishAutosaveCommit(dir, taskBranch, sha, parent, message, status, onOutcome, reason, git) {
161
+ const ref = `refs/heads/${taskBranch}`;
162
+ // The save is not atomic against the agent's own Git commands. It guarantees that no
163
+ // ref other than refs/heads/<taskBranch> moves, and that no merge, cherry-pick or
164
+ // revert Git has recorded as pending (its MERGE_HEAD, CHERRY_PICK_HEAD or REVERT_HEAD
165
+ // written) by this recheck is committed: the check before `add -A` cannot see one that
166
+ // starts after it, and the save would record that operation's content without its
167
+ // ancestry (review round 4 on hearsay-tools/cezarion#1004). An operation that starts
168
+ // after `write-tree` cannot be in this tree; one recorded before it is still pending
169
+ // here, unless the agent also concluded it, which moved the branch and fails the
170
+ // compare-and-swap, or aborted it within those few commands, whose content the save
171
+ // then still records. A Git command still running during the save is not excluded:
172
+ // `git merge` publishes the merged index before it writes MERGE_HEAD, so a save in
173
+ // between records that content single-parent, as `git add -A && git commit` always
174
+ // did (review round 5 reproduced the same result on main). The save also commits only
175
+ // when HEAD names the task branch at both of its reads, before `add -A` and here after
176
+ // `write-tree`, so a checkout between them skips it (review round 2 on
177
+ // hearsay-tools/cezarion#1111). A checkout away and back again between the reads is not
178
+ // excluded, nor is one still running, which writes the new index and working tree
179
+ // before it moves HEAD, so a save in between commits the other branch's files onto the
180
+ // task branch, as `git add -A && git commit` on main does. A refusal or a skip here
181
+ // leaves what `add -A` staged in the index, as every failure after it does.
182
+ const moved = await readAutosaveHead(dir, git);
183
+ if (moved === undefined)
184
+ return 'failed';
185
+ if (moved !== ref)
186
+ return skipAutosave(moved, status, onOutcome);
187
+ const late = await pendingAutosaveOperation(dir, reason, git);
188
+ if (late)
189
+ return late;
190
+ if (!(await git(dir, ['update-ref', '-m', message, ref, sha, parent])).ok)
191
+ return 'failed';
192
+ if (onOutcome) {
193
+ // The commit already landed: a failed read loses the sha, never the report.
194
+ const short = await git(dir, ['rev-parse', '--short', sha]);
195
+ reportAutosave(onOutcome, { result: 'committed', sha: (short.ok && short.stdout.trim()) || null, branch: taskBranch });
196
+ }
197
+ return 'committed';
198
+ }
199
+ /**
200
+ * Stage and commit everything in the worktree as a "cezar autosave" commit
201
+ * (janitor pattern) — the agent's progress is recoverable from the `cez/<id8>`
202
+ * branch history. Quietly a no-op when nothing changed. With `taskBranch`, a
203
+ * worktree whose HEAD the agent moved to another branch (or detached) is left
204
+ * uncommitted instead: an autosave commit there lands in the agent's own PR
205
+ * history (hearsay-tools/cezarion#1004).
206
+ *
207
+ * The message carries `reason` so the opt-in periodic timer and the always-on
208
+ * flushes are distinguishable in `git log`; the `cezar autosave` prefix is kept
209
+ * so existing log greps still match.
210
+ *
211
+ * Refuses to commit a worktree that is mid-merge or still carries conflict
212
+ * markers: the incident behind #471 was an autosave capturing a half-resolved
213
+ * merge, and a blind `git add -A` would do it again.
214
+ */
215
+ export async function autosaveCommit(dir, reason, options = {}) {
216
+ if (fallbackProjectWriteError(dir)) {
217
+ console.info(`${logPrefix()} Autosave skipped 1 read-only fallback worktree under .ai/squawk/.`);
218
+ return 'skipped';
219
+ }
220
+ let key = resolve(dir);
221
+ try {
222
+ key = realpathSync(dir);
223
+ }
224
+ catch { /* Missing/unreadable dir fails through Git. */ }
225
+ const previous = autosaves.get(key);
226
+ const task = (async () => {
227
+ if (previous)
228
+ await previous;
229
+ return save();
230
+ })();
231
+ autosaves.set(key, task);
232
+ try {
233
+ return await task;
234
+ }
235
+ finally {
236
+ if (autosaves.get(key) === task)
237
+ autosaves.delete(key);
238
+ }
239
+ async function save() {
240
+ const git = (cwd, args) => autosaveGit(cwd, args, options);
241
+ const status = await git(dir, ['status', '--porcelain']);
242
+ if (!status.ok)
243
+ return 'failed';
244
+ if (!status.stdout.trim())
245
+ return 'nothing-to-do';
246
+ const { taskBranch, onOutcome } = options;
247
+ let head = null;
248
+ if (taskBranch !== undefined || onOutcome) {
249
+ const read = await readAutosaveHead(dir, git);
250
+ if (read === undefined)
251
+ return 'failed';
252
+ head = read;
253
+ }
254
+ const branch = autosaveBranchName(head);
255
+ if (taskBranch !== undefined && head !== `refs/heads/${taskBranch}`)
256
+ return skipAutosave(head, status.stdout, onOutcome);
257
+ const unresolved = await unresolvedConflicts(dir, status.stdout);
258
+ if (unresolved) {
259
+ // Losing one recovery point beats poisoning the branch with a commit that
260
+ // does not build. For the periodic and turn-end flushes the next one picks
261
+ // the work up once the merge resolves; the pre-PR flush has no next one,
262
+ // which is why callers get `refused` rather than a bare `false`.
263
+ console.warn(`${logPrefix()} skipping ${reason} autosave in ${dir}: ${unresolved}`);
264
+ return 'refused';
265
+ }
266
+ if (taskBranch !== undefined) {
267
+ // Checked before staging too, so a pending operation's index stays as the agent left it.
268
+ const pending = await pendingAutosaveOperation(dir, reason, git);
269
+ if (pending)
270
+ return pending;
271
+ }
272
+ if (!(await git(dir, ['add', '-A'])).ok)
273
+ return 'failed';
274
+ const identityArgs = await autosaveIdentityArgs(dir, git);
275
+ if (identityArgs === 'failed')
276
+ return 'failed';
277
+ const message = `cezar autosave (${reason})`;
278
+ if (taskBranch === undefined) {
279
+ return commitAutosaveOnHead(dir, identityArgs, message, branch, onOutcome, git);
280
+ }
281
+ const written = await writeAutosaveCommit(dir, taskBranch, identityArgs, message, git);
282
+ if (written === 'failed' || written === 'nothing-to-do')
283
+ return written;
284
+ return publishAutosaveCommit(dir, taskBranch, written.sha, written.parent, message, status.stdout, onOutcome, reason, git);
285
+ }
286
+ }
287
+ /**
288
+ * Is the worktree mid-merge or still carrying conflict markers? Returns a
289
+ * human-readable reason, or `null` when it is safe to autosave.
290
+ *
291
+ * Two independent checks, because they catch different failures: porcelain `U`
292
+ * codes catch an *unresolved* merge, while the marker scan catches the worse
293
+ * case — someone ran `git add` on a file they had not finished resolving, which
294
+ * clears the `U` code but leaves `<<<<<<<` in the text.
295
+ */
296
+ async function unresolvedConflicts(dir, porcelain) {
297
+ const entries = porcelain.split('\n').filter(Boolean);
298
+ const unmerged = entries.filter((line) => {
299
+ const xy = line.slice(0, 2);
300
+ // Unmerged per `git status` docs: any side U, plus the AA / DD collisions.
301
+ return xy.includes('U') || xy === 'AA' || xy === 'DD';
302
+ });
303
+ const firstUnmerged = unmerged[0];
304
+ if (firstUnmerged) {
305
+ return `${unmerged.length} unmerged path(s), e.g. ${firstUnmerged.slice(3)}`;
306
+ }
307
+ // Deleted paths have no content to scan. Untracked (`??`) ones are skipped
308
+ // even though `git add -A` will commit them: a conflict always lands in a
309
+ // tracked file, whereas an untracked fixture or doc that legitimately
310
+ // contains marker-shaped lines would otherwise wedge every autosave. False
311
+ // negatives here cost noise; false positives would cost the recovery point.
312
+ const candidates = entries
313
+ .filter((line) => !line.startsWith('D ') && !line.startsWith(' D') && !line.startsWith('??'))
314
+ .map((line) => {
315
+ // A rename reads `old -> new`; the new path is what gets committed.
316
+ const raw = line.slice(3).trim();
317
+ const path = raw.includes(' -> ') ? (raw.split(' -> ')[1] ?? raw) : raw;
318
+ return unquotePath(path);
319
+ });
320
+ for (const path of candidates) {
321
+ // Read the working tree, not the index: this runs before `git add -A`, so
322
+ // the on-disk copy is what would be committed. Binary files decode to
323
+ // mojibake rather than throwing, but cannot match the anchored marker
324
+ // pattern; unreadable paths (races, symlinks) are skipped, not fatal.
325
+ let text;
326
+ try {
327
+ const full = join(dir, path);
328
+ if ((await stat(full)).size > MARKER_SCAN_MAX_BYTES)
329
+ continue;
330
+ text = await readFile(full, 'utf8');
331
+ }
332
+ catch {
333
+ continue;
334
+ }
335
+ if (hasConflictMarkers(text)) {
336
+ return `leftover conflict markers in ${path}`;
337
+ }
338
+ }
339
+ return null;
340
+ }
341
+ /**
342
+ * Undo `git status --porcelain` path quoting. Git quotes a path containing a
343
+ * space or a non-ASCII byte, escaping the latter as octal — `café.txt` reads
344
+ * back as `"caf\303\251.txt"`. Stripping the quotes alone leaves those escapes
345
+ * literal, so the file would not open and a real conflict in it would go
346
+ * unnoticed. Decoding the octal bytes as UTF-8 restores the actual name.
347
+ */
348
+ function unquotePath(path) {
349
+ if (!path.startsWith('"') || !path.endsWith('"'))
350
+ return path;
351
+ const inner = path.slice(1, -1);
352
+ const bytes = [];
353
+ for (let i = 0; i < inner.length; i += 1) {
354
+ if (inner[i] !== '\\') {
355
+ bytes.push(...Buffer.from(inner[i], 'utf8'));
356
+ continue;
357
+ }
358
+ const next = inner[i + 1];
359
+ if (next === undefined)
360
+ break;
361
+ const octal = inner.slice(i + 1, i + 4);
362
+ if (/^[0-7]{3}$/.test(octal)) {
363
+ bytes.push(parseInt(octal, 8));
364
+ i += 3;
365
+ continue;
366
+ }
367
+ // C-style single-character escapes git also emits.
368
+ const simple = { n: 10, t: 9, r: 13, '"': 34, '\\': 92 };
369
+ const escaped = simple[next];
370
+ if (escaped === undefined)
371
+ bytes.push(...Buffer.from(next, 'utf8'));
372
+ else
373
+ bytes.push(escaped);
374
+ i += 1;
375
+ }
376
+ return Buffer.from(bytes).toString('utf8');
377
+ }
378
+ //# sourceMappingURL=autosave-commit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autosave-commit.js","sourceRoot":"","sources":["../src/autosave-commit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OA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CAAC;YAC/B,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACX,CAAC;QACD,mDAAmD;QACnD,MAAM,MAAM,GAA2B,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;QACjF,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAC7B,IAAI,OAAO,KAAK,SAAS;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;;YAC/D,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzB,CAAC,IAAI,CAAC,CAAC;IACT,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC7C,CAAC"}
@@ -1,3 +1,4 @@
1
+ export { ToolsUnavailableError } from './errors.ts';
1
2
  import { type ScheduleTaskAnswer, type ScheduleTaskRequest, type ScheduledTasksAnswer, type ScheduledTasksRequest } from '../contract/index.js';
2
3
  import { type SquawkAskAnswer, type SquawkAskRequest, type SquawkCancelWaitAnswer, type SquawkCancelWaitRequest, type SquawkDoneAnswer, type SquawkDoneRequest, type SquawkWaitAnswer, type SquawkWaitRequestInput, type Wait, type WaitVia } from '../contract/index.js';
3
4
  import { type PreviewStopRequest, type PreviewStopResult, type PreviewServeRequest, type PreviewServeResult } from '../contract/index.js';
@@ -43,15 +44,6 @@ export type CiToolSession = {
43
44
  env: Record<string, string>;
44
45
  revoke(): void;
45
46
  };
46
- /**
47
- * hearsay-tools/cezarion#2397: every agent session needs the lifecycle tools, so a controller that
48
- * cannot start fails the launch with this error. Its message names the cause and the fix.
49
- */
50
- export declare class ToolsUnavailableError extends Error {
51
- readonly detail: string;
52
- readonly directory: string | undefined;
53
- constructor(detail: string, directory: string | undefined);
54
- }
55
47
  /** Separate from the cockpit and delegation APIs. No TCP listener or durable credentials. */
56
48
  export declare class CiToolController {
57
49
  private readonly server;
@@ -288,11 +280,12 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
288
280
  "/api/v1/tools/ask": {
289
281
  $post: {
290
282
  output: {
291
- code: 'capability_revoked';
283
+ ok: false;
284
+ code: 'unavailable';
292
285
  message: string;
293
286
  };
294
287
  outputFormat: "json";
295
- status: 401;
288
+ status: import("hono/utils/http-status").ContentfulStatusCode;
296
289
  input: {
297
290
  json: {
298
291
  questions: {
@@ -310,12 +303,11 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
310
303
  };
311
304
  } | {
312
305
  output: {
313
- ok: false;
314
- code: 'unavailable';
306
+ code: 'capability_revoked';
315
307
  message: string;
316
308
  };
317
309
  outputFormat: "json";
318
- status: import("hono/utils/http-status").ContentfulStatusCode;
310
+ status: 401;
319
311
  input: {
320
312
  json: {
321
313
  questions: {
@@ -383,11 +375,12 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
383
375
  "/api/v1/tools/cancel-wait": {
384
376
  $post: {
385
377
  output: {
386
- code: 'capability_revoked';
378
+ cancelled: false;
379
+ code: 'unavailable';
387
380
  message: string;
388
381
  };
389
382
  outputFormat: "json";
390
- status: 401;
383
+ status: import("hono/utils/http-status").ContentfulStatusCode;
391
384
  input: {
392
385
  json: {
393
386
  wait_id: string;
@@ -395,12 +388,11 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
395
388
  };
396
389
  } | {
397
390
  output: {
398
- cancelled: false;
399
- code: 'unavailable';
391
+ code: 'capability_revoked';
400
392
  message: string;
401
393
  };
402
394
  outputFormat: "json";
403
- status: import("hono/utils/http-status").ContentfulStatusCode;
395
+ status: 401;
404
396
  input: {
405
397
  json: {
406
398
  wait_id: string;
@@ -448,11 +440,12 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
448
440
  "/api/v1/tools/done": {
449
441
  $post: {
450
442
  output: {
451
- code: 'capability_revoked';
443
+ ok: false;
444
+ code: 'unavailable';
452
445
  message: string;
453
446
  };
454
447
  outputFormat: "json";
455
- status: 401;
448
+ status: import("hono/utils/http-status").ContentfulStatusCode;
456
449
  input: {
457
450
  json: {
458
451
  summary?: string | undefined;
@@ -460,12 +453,11 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
460
453
  };
461
454
  } | {
462
455
  output: {
463
- ok: false;
464
- code: 'unavailable';
456
+ code: 'capability_revoked';
465
457
  message: string;
466
458
  };
467
459
  outputFormat: "json";
468
- status: import("hono/utils/http-status").ContentfulStatusCode;
460
+ status: 401;
469
461
  input: {
470
462
  json: {
471
463
  summary?: string | undefined;
@@ -533,11 +525,13 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
533
525
  "/api/v1/tools/preview-stop": {
534
526
  $post: {
535
527
  output: {
536
- code: 'capability_revoked';
528
+ ok: boolean;
529
+ code: "adopted" | "approval_required" | "headless" | "invalid_input" | "not_registered" | "port_held" | "port_in_use" | "preview_disabled" | "restarted" | "stopped" | "unavailable" | "worktree_missing";
537
530
  message: string;
531
+ hint: string;
538
532
  };
539
533
  outputFormat: "json";
540
- status: 401;
534
+ status: import("hono/utils/http-status").ContentfulStatusCode;
541
535
  input: {
542
536
  json: {
543
537
  port: number;
@@ -546,13 +540,11 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
546
540
  };
547
541
  } | {
548
542
  output: {
549
- ok: boolean;
550
- code: "adopted" | "approval_required" | "headless" | "invalid_input" | "not_registered" | "port_held" | "port_in_use" | "preview_disabled" | "restarted" | "stopped" | "unavailable" | "worktree_missing";
543
+ code: 'capability_revoked';
551
544
  message: string;
552
- hint: string;
553
545
  };
554
546
  outputFormat: "json";
555
- status: import("hono/utils/http-status").ContentfulStatusCode;
547
+ status: 401;
556
548
  input: {
557
549
  json: {
558
550
  port: number;
@@ -565,11 +557,13 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
565
557
  "/api/v1/tools/preview-serve": {
566
558
  $post: {
567
559
  output: {
568
- code: 'capability_revoked';
560
+ ok: boolean;
561
+ code: "cezar_port" | "cwd_outside_worktree" | "headless" | "invalid_input" | "port_held" | "preview_disabled" | "registered" | "replaced" | "too_many" | "unavailable" | "worktree_missing";
569
562
  message: string;
563
+ hint: string;
570
564
  };
571
565
  outputFormat: "json";
572
- status: 401;
566
+ status: import("hono/utils/http-status").ContentfulStatusCode;
573
567
  input: {
574
568
  json: {
575
569
  command: string;
@@ -581,13 +575,11 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
581
575
  };
582
576
  } | {
583
577
  output: {
584
- ok: boolean;
585
- code: "cezar_port" | "cwd_outside_worktree" | "headless" | "invalid_input" | "port_held" | "preview_disabled" | "registered" | "replaced" | "too_many" | "unavailable" | "worktree_missing";
578
+ code: 'capability_revoked';
586
579
  message: string;
587
- hint: string;
588
580
  };
589
581
  outputFormat: "json";
590
- status: import("hono/utils/http-status").ContentfulStatusCode;
582
+ status: 401;
591
583
  input: {
592
584
  json: {
593
585
  command: string;
@@ -603,11 +595,12 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
603
595
  "/api/v1/tools/schedule-task": {
604
596
  $post: {
605
597
  output: {
606
- code: 'capability_revoked';
598
+ ok: false;
599
+ code: import('../contract/index.js').ScheduledTaskRefusalCode;
607
600
  message: string;
608
601
  };
609
602
  outputFormat: "json";
610
- status: 401;
603
+ status: import("hono/utils/http-status").ContentfulStatusCode;
611
604
  input: {
612
605
  json: {
613
606
  at?: string | undefined;
@@ -624,12 +617,11 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
624
617
  };
625
618
  } | {
626
619
  output: {
627
- ok: false;
628
- code: import('../contract/index.js').ScheduledTaskRefusalCode;
620
+ code: 'capability_revoked';
629
621
  message: string;
630
622
  };
631
623
  outputFormat: "json";
632
- status: import("hono/utils/http-status").ContentfulStatusCode;
624
+ status: 401;
633
625
  input: {
634
626
  json: {
635
627
  at?: string | undefined;
@@ -684,11 +676,12 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
684
676
  "/api/v1/tools/scheduled-tasks": {
685
677
  $post: {
686
678
  output: {
687
- code: 'capability_revoked';
679
+ ok: false;
680
+ code: import('../contract/index.js').ScheduledTaskRefusalCode;
688
681
  message: string;
689
682
  };
690
683
  outputFormat: "json";
691
- status: 401;
684
+ status: import("hono/utils/http-status").ContentfulStatusCode;
692
685
  input: {
693
686
  json: {
694
687
  at?: string | undefined;
@@ -721,12 +714,11 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
721
714
  };
722
715
  } | {
723
716
  output: {
724
- ok: false;
725
- code: import('../contract/index.js').ScheduledTaskRefusalCode;
717
+ code: 'capability_revoked';
726
718
  message: string;
727
719
  };
728
720
  outputFormat: "json";
729
- status: import("hono/utils/http-status").ContentfulStatusCode;
721
+ status: 401;
730
722
  input: {
731
723
  json: {
732
724
  at?: string | undefined;
@@ -821,4 +813,3 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
821
813
  };
822
814
  }, "/", "/api/v1/tools/scheduled-tasks">;
823
815
  export type CiToolApp = ReturnType<typeof ciToolRoutes>;
824
- export {};