@cluesmith/codev 3.3.2 → 3.3.3

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 (157) hide show
  1. package/dashboard-dist/assets/{index-D3XaKpZW.js → index-CUIjS_Vb.js} +41 -41
  2. package/dashboard-dist/assets/index-CUIjS_Vb.js.map +1 -0
  3. package/dashboard-dist/assets/index-DnYLy5C_.css +32 -0
  4. package/dashboard-dist/index.html +2 -2
  5. package/dist/agent-farm/commands/inbox.d.ts.map +1 -1
  6. package/dist/agent-farm/commands/inbox.js +67 -10
  7. package/dist/agent-farm/commands/inbox.js.map +1 -1
  8. package/dist/agent-farm/commands/interrupt.d.ts +4 -1
  9. package/dist/agent-farm/commands/interrupt.d.ts.map +1 -1
  10. package/dist/agent-farm/commands/interrupt.js +6 -3
  11. package/dist/agent-farm/commands/interrupt.js.map +1 -1
  12. package/dist/agent-farm/commands/reset.d.ts +4 -1
  13. package/dist/agent-farm/commands/reset.d.ts.map +1 -1
  14. package/dist/agent-farm/commands/reset.js +6 -3
  15. package/dist/agent-farm/commands/reset.js.map +1 -1
  16. package/dist/agent-farm/commands/send.d.ts +28 -0
  17. package/dist/agent-farm/commands/send.d.ts.map +1 -1
  18. package/dist/agent-farm/commands/send.js +64 -6
  19. package/dist/agent-farm/commands/send.js.map +1 -1
  20. package/dist/agent-farm/db/index.d.ts +3 -1
  21. package/dist/agent-farm/db/index.d.ts.map +1 -1
  22. package/dist/agent-farm/db/index.js +8 -443
  23. package/dist/agent-farm/db/index.js.map +1 -1
  24. package/dist/agent-farm/db/mailbox.d.ts +47 -7
  25. package/dist/agent-farm/db/mailbox.d.ts.map +1 -1
  26. package/dist/agent-farm/db/mailbox.js +56 -12
  27. package/dist/agent-farm/db/mailbox.js.map +1 -1
  28. package/dist/agent-farm/db/migrations.d.ts +57 -0
  29. package/dist/agent-farm/db/migrations.d.ts.map +1 -0
  30. package/dist/agent-farm/db/migrations.js +530 -0
  31. package/dist/agent-farm/db/migrations.js.map +1 -0
  32. package/dist/agent-farm/db/schema.d.ts +1 -1
  33. package/dist/agent-farm/db/schema.d.ts.map +1 -1
  34. package/dist/agent-farm/db/schema.js +1 -0
  35. package/dist/agent-farm/db/schema.js.map +1 -1
  36. package/dist/agent-farm/db/types.d.ts +22 -0
  37. package/dist/agent-farm/db/types.d.ts.map +1 -1
  38. package/dist/agent-farm/db/types.js.map +1 -1
  39. package/dist/agent-farm/lib/tunnel-client.d.ts.map +1 -1
  40. package/dist/agent-farm/lib/tunnel-client.js +43 -14
  41. package/dist/agent-farm/lib/tunnel-client.js.map +1 -1
  42. package/dist/agent-farm/servers/cron-delivery.d.ts +7 -1
  43. package/dist/agent-farm/servers/cron-delivery.d.ts.map +1 -1
  44. package/dist/agent-farm/servers/cron-delivery.js +2 -1
  45. package/dist/agent-farm/servers/cron-delivery.js.map +1 -1
  46. package/dist/agent-farm/servers/gate-profiles.d.ts +21 -0
  47. package/dist/agent-farm/servers/gate-profiles.d.ts.map +1 -1
  48. package/dist/agent-farm/servers/gate-profiles.js +36 -4
  49. package/dist/agent-farm/servers/gate-profiles.js.map +1 -1
  50. package/dist/agent-farm/servers/mailbox-delivery.d.ts +83 -8
  51. package/dist/agent-farm/servers/mailbox-delivery.d.ts.map +1 -1
  52. package/dist/agent-farm/servers/mailbox-delivery.js +102 -26
  53. package/dist/agent-farm/servers/mailbox-delivery.js.map +1 -1
  54. package/dist/agent-farm/servers/mailbox-wiring.d.ts +48 -15
  55. package/dist/agent-farm/servers/mailbox-wiring.d.ts.map +1 -1
  56. package/dist/agent-farm/servers/mailbox-wiring.js +116 -22
  57. package/dist/agent-farm/servers/mailbox-wiring.js.map +1 -1
  58. package/dist/agent-farm/servers/render-gate.d.ts +24 -1
  59. package/dist/agent-farm/servers/render-gate.d.ts.map +1 -1
  60. package/dist/agent-farm/servers/render-gate.js +50 -12
  61. package/dist/agent-farm/servers/render-gate.js.map +1 -1
  62. package/dist/agent-farm/servers/tower-cron.d.ts.map +1 -1
  63. package/dist/agent-farm/servers/tower-cron.js +3 -2
  64. package/dist/agent-farm/servers/tower-cron.js.map +1 -1
  65. package/dist/agent-farm/servers/tower-instances.d.ts.map +1 -1
  66. package/dist/agent-farm/servers/tower-instances.js +11 -3
  67. package/dist/agent-farm/servers/tower-instances.js.map +1 -1
  68. package/dist/agent-farm/servers/tower-routes.d.ts +32 -0
  69. package/dist/agent-farm/servers/tower-routes.d.ts.map +1 -1
  70. package/dist/agent-farm/servers/tower-routes.js +133 -13
  71. package/dist/agent-farm/servers/tower-routes.js.map +1 -1
  72. package/dist/agent-farm/servers/tower-server.js +15 -2
  73. package/dist/agent-farm/servers/tower-server.js.map +1 -1
  74. package/dist/agent-farm/servers/tower-terminals.d.ts +21 -0
  75. package/dist/agent-farm/servers/tower-terminals.d.ts.map +1 -1
  76. package/dist/agent-farm/servers/tower-terminals.js +53 -5
  77. package/dist/agent-farm/servers/tower-terminals.js.map +1 -1
  78. package/dist/agent-farm/servers/tower-utils.d.ts +35 -0
  79. package/dist/agent-farm/servers/tower-utils.d.ts.map +1 -1
  80. package/dist/agent-farm/servers/tower-utils.js +39 -0
  81. package/dist/agent-farm/servers/tower-utils.js.map +1 -1
  82. package/dist/agent-farm/servers/tower-websocket.d.ts.map +1 -1
  83. package/dist/agent-farm/servers/tower-websocket.js +8 -1
  84. package/dist/agent-farm/servers/tower-websocket.js.map +1 -1
  85. package/dist/agent-farm/utils/message-format.d.ts +78 -2
  86. package/dist/agent-farm/utils/message-format.d.ts.map +1 -1
  87. package/dist/agent-farm/utils/message-format.js +102 -5
  88. package/dist/agent-farm/utils/message-format.js.map +1 -1
  89. package/dist/cli.d.ts.map +1 -1
  90. package/dist/cli.js +3 -1
  91. package/dist/cli.js.map +1 -1
  92. package/dist/commands/doctor.js +2 -2
  93. package/dist/commands/generate-image.d.ts +20 -1
  94. package/dist/commands/generate-image.d.ts.map +1 -1
  95. package/dist/commands/generate-image.js +188 -1
  96. package/dist/commands/generate-image.js.map +1 -1
  97. package/dist/commands/porch/prompts.d.ts.map +1 -1
  98. package/dist/commands/porch/prompts.js +18 -2
  99. package/dist/commands/porch/prompts.js.map +1 -1
  100. package/dist/lib/forge-contracts.d.ts +66 -5
  101. package/dist/lib/forge-contracts.d.ts.map +1 -1
  102. package/dist/lib/forge-contracts.js.map +1 -1
  103. package/dist/lib/forge.d.ts +1 -1
  104. package/dist/lib/forge.d.ts.map +1 -1
  105. package/dist/lib/forge.js +33 -11
  106. package/dist/lib/forge.js.map +1 -1
  107. package/dist/terminal/pty-manager.d.ts +10 -1
  108. package/dist/terminal/pty-manager.d.ts.map +1 -1
  109. package/dist/terminal/pty-manager.js +38 -9
  110. package/dist/terminal/pty-manager.js.map +1 -1
  111. package/dist/terminal/pty-session.d.ts +52 -4
  112. package/dist/terminal/pty-session.d.ts.map +1 -1
  113. package/dist/terminal/pty-session.js +157 -18
  114. package/dist/terminal/pty-session.js.map +1 -1
  115. package/dist/terminal/shellper-client.d.ts +73 -0
  116. package/dist/terminal/shellper-client.d.ts.map +1 -1
  117. package/dist/terminal/shellper-client.js +151 -0
  118. package/dist/terminal/shellper-client.js.map +1 -1
  119. package/dist/terminal/shellper-main.js +20 -3
  120. package/dist/terminal/shellper-main.js.map +1 -1
  121. package/dist/terminal/shellper-process.d.ts +2 -0
  122. package/dist/terminal/shellper-process.d.ts.map +1 -1
  123. package/dist/terminal/shellper-process.js +17 -1
  124. package/dist/terminal/shellper-process.js.map +1 -1
  125. package/dist/terminal/shellper-protocol.d.ts +28 -0
  126. package/dist/terminal/shellper-protocol.d.ts.map +1 -1
  127. package/dist/terminal/shellper-protocol.js.map +1 -1
  128. package/package.json +4 -4
  129. package/scripts/forge/gitea/_lib.sh +214 -0
  130. package/scripts/forge/gitea/issue-comment.sh +8 -1
  131. package/scripts/forge/gitea/issue-view.sh +95 -4
  132. package/scripts/forge/gitea/pr-create.sh +155 -0
  133. package/scripts/forge/gitea/pr-exists.sh +32 -4
  134. package/scripts/forge/gitea/pr-list.sh +40 -31
  135. package/scripts/forge/gitea/pr-view.sh +65 -4
  136. package/scripts/forge/gitea/recently-merged.sh +91 -21
  137. package/scripts/forge/gitea/user-identity.sh +30 -1
  138. package/scripts/forge/github/issue-view.sh +5 -2
  139. package/scripts/forge/github/pr-create.sh +47 -0
  140. package/scripts/forge/github/pr-search.sh +3 -1
  141. package/scripts/forge/gitlab/issue-view.sh +24 -4
  142. package/scripts/forge/gitlab/pr-create.sh +53 -0
  143. package/scripts/forge/gitlab/pr-search.sh +3 -1
  144. package/scripts/forge/linear/issue-view.sh +13 -2
  145. package/skeleton/.claude/skills/generate-image/SKILL.md +22 -1
  146. package/skeleton/.codex/skills/generate-image/SKILL.md +22 -1
  147. package/skeleton/protocols/air/prompts/pr.md +6 -1
  148. package/skeleton/protocols/aspir/prompts/review.md +6 -1
  149. package/skeleton/protocols/bugfix/prompts/pr.md +6 -1
  150. package/skeleton/protocols/bugfix/protocol.md +2 -1
  151. package/skeleton/protocols/maintain/prompts/review.md +6 -1
  152. package/skeleton/protocols/pir/prompts/review.md +10 -7
  153. package/skeleton/protocols/spir/prompts/review.md +6 -1
  154. package/skeleton/resources/commands/agent-farm.md +1 -1
  155. package/templates/tower.html +16 -1
  156. package/dashboard-dist/assets/index-BZRTEMtH.css +0 -32
  157. package/dashboard-dist/assets/index-D3XaKpZW.js.map +0 -1
@@ -21,7 +21,7 @@
21
21
  * that is still `held`.
22
22
  */
23
23
  import type Database from 'better-sqlite3';
24
- import type { DbMailbox, MailboxReason } from './types.js';
24
+ import type { DbMailbox, MailboxGateDetail, MailboxReason } from './types.js';
25
25
  /**
26
26
  * Fields a caller supplies to persist a new held row. The repository fills in the
27
27
  * id, `held` status, `escalated=0`, and the timestamps.
@@ -126,13 +126,32 @@ export declare function heldSummaryForWorkspace(db: Database.Database, workspace
126
126
  */
127
127
  export declare function markDelivered(db: Database.Database, id: string, now?: number): boolean;
128
128
  /**
129
- * Refresh the why-held `reason` on a still-held row (informational — the value
130
- * `afx inbox` shows and the send response reports). Only touches `held` rows, so
131
- * it can never relabel or resurrect a terminal row. Returns true if a held row was
132
- * updated. The delivery pass calls this so a held row's reason tracks the current
133
- * gate verdict (e.g. `busy` → `no-live-pty` when the terminal dies).
129
+ * Refresh the why-held verdict — `reason` AND its gate `detail` — on a still-held row
130
+ * (informational: the values `afx inbox`, the send response, the escalation broadcast and the
131
+ * owner starvation notice report). Only touches `held` rows, so it can never relabel or
132
+ * resurrect a terminal row. Returns true if a held row was updated. The delivery pass calls
133
+ * this so a held row's verdict tracks the current gate verdict (e.g. `busy` → `no-live-pty`
134
+ * when the terminal dies).
135
+ *
136
+ * ONE statement, not two (Issue #1482): the pair is a single verdict, and writing it in two
137
+ * updates would leave a window — and a second `updated_at` bump — where a reader could see a
138
+ * new reason beside the previous reason's detail. Callers that hold for a NON-gate cause pass
139
+ * `detail: null` so a stale detail can never outlive the verdict that produced it.
140
+ *
141
+ * `updated_at` therefore keeps meaning "when this row's verdict last MOVED", and that is
142
+ * enforced HERE, by the `(reason IS NOT ? OR detail IS NOT ?)` predicate — not merely by the
143
+ * callers that happen to check first. The delivery pass does guard before calling (see
144
+ * `mailbox-delivery.ts`), but a guard living only at the call site is one new caller away from
145
+ * silently breaking the starvation notice, which reads elapsed time off `updated_at` to say how
146
+ * long a composer has been occupied. `IS NOT` rather than `<>` because both columns are
147
+ * nullable and SQL's `<>` is not null-safe: `NULL <> NULL` is NULL, not false, so a
148
+ * `null`→`null` no-op would slip through the predicate and bump the timestamp anyway.
149
+ *
150
+ * Returns true only when a held row's verdict actually moved. A repeat of the same pair, a
151
+ * terminal row, and an unknown id are all `false` — callers wanting "does this row exist"
152
+ * should ask {@link getById}, not this.
134
153
  */
135
- export declare function setHeldReason(db: Database.Database, id: string, reason: MailboxReason | null, now?: number): boolean;
154
+ export declare function setHeldVerdict(db: Database.Database, id: string, reason: MailboxReason | null, detail: MailboxGateDetail | null, now?: number): boolean;
136
155
  /**
137
156
  * Flag a still-held row as escalated — **visibility only, NEVER affects delivery**. The
138
157
  * drainer's escalation pass calls this when a row crosses the escalation age, then emits
@@ -141,6 +160,20 @@ export declare function setHeldReason(db: Database.Database, id: string, reason:
141
160
  * row is untouched. Returns true if it flipped.
142
161
  */
143
162
  export declare function markEscalated(db: Database.Database, id: string, now?: number): boolean;
163
+ /**
164
+ * Flag an already-DELIVERED row as escalated (Issue #1584) — visibility only, and the
165
+ * counterpart to {@link markEscalated} for the one case that flags a row *after* it has left
166
+ * the held set: a delivery whose write completed but whose echo never confirmed.
167
+ *
168
+ * A separate function rather than a relaxed guard on {@link markEscalated}, because that one's
169
+ * held-only contract is what makes the drainer's escalation pass safe to call blindly. Here the
170
+ * ordering is the point: the row is marked `delivered` FIRST (that commit is what makes the
171
+ * write un-repeatable even across a crash), so by the time the verdict is known the held-only
172
+ * guard would silently no-op and the flag would be lost.
173
+ *
174
+ * Delivered-only and idempotent (the `escalated = 0` guard). Returns true if it flipped.
175
+ */
176
+ export declare function markEscalatedDelivered(db: Database.Database, id: string, now?: number): boolean;
144
177
  /**
145
178
  * Supersede-key prefix for architect starvation notices (Spec 1313 round 3, change 3). A
146
179
  * notice row carries `${NOTICE_SUPERSEDE_PREFIX}<starving-agent>` so (a) one pending notice
@@ -163,6 +196,13 @@ export interface StarvingAgent {
163
196
  count: number;
164
197
  /** Representative why-held reason (held rows for one agent share the gate's verdict). */
165
198
  reason: MailboxReason | null;
199
+ /**
200
+ * Representative gate detail beside {@link reason} (Issue #1482) — the same MAX() aggregate,
201
+ * for the same reason: an agent's held rows all carry the verdict of the last delivery pass.
202
+ * It is what lets the owner starvation notice distinguish "a human is at the composer" from
203
+ * "the classifier cannot verify this composer", which have different remedies.
204
+ */
205
+ detail: MailboxGateDetail | null;
166
206
  }
167
207
  /**
168
208
  * Per-agent view of currently-STARVING mail (Spec 1313 round 3, change 3): agents with at
@@ -1 +1 @@
1
- {"version":3,"file":"mailbox.d.ts","sourceRoot":"","sources":["../../../src/agent-farm/db/mailbox.ts"],"names":[],"mapp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,EAAE,QAAQ,CAAC,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,GAAE,MAAmB,GAAG,OAAO,CAO5F;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,MAAM,GACnB,MAAM,CAOR;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,YAAY,EACnB,GAAG,GAAE,MAAmB,GACvB,SAAS,CAQX;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,aAAa,EAAE,MAAM,EACrB,GAAG,GAAE,MAAmB,GACvB,MAAM,CAQR"}
@@ -24,11 +24,11 @@ import { randomUUID } from 'node:crypto';
24
24
  const INSERT_SQL = `
25
25
  INSERT INTO mailbox (
26
26
  id, workspace_path, to_agent, terminal_id, from_agent, from_workspace,
27
- body, formatted_message, no_enter, status, reason, supersede_key,
27
+ body, formatted_message, no_enter, status, reason, detail, supersede_key,
28
28
  escalated, not_before, created_at, updated_at, resolved_at
29
29
  ) VALUES (
30
30
  @id, @workspace_path, @to_agent, @terminal_id, @from_agent, @from_workspace,
31
- @body, @formatted_message, @no_enter, @status, @reason, @supersede_key,
31
+ @body, @formatted_message, @no_enter, @status, @reason, @detail, @supersede_key,
32
32
  @escalated, @not_before, @created_at, @updated_at, @resolved_at
33
33
  )
34
34
  `;
@@ -45,6 +45,10 @@ function buildRow(input, now) {
45
45
  no_enter: input.noEnter ? 1 : 0,
46
46
  status: 'held',
47
47
  reason: input.reason ?? null,
48
+ // A brand-new row has no gate verdict yet: the only reasons available at enqueue are the
49
+ // non-gate ones (`no-live-pty` from holdAndRespond), which never carry a detail. The first
50
+ // delivery pass sets it (Issue #1482).
51
+ detail: null,
48
52
  supersede_key: input.supersedeKey ?? null,
49
53
  escalated: 0,
50
54
  not_before: input.notBefore ?? null,
@@ -163,21 +167,41 @@ export function heldSummaryForWorkspace(db, workspacePath, now = Date.now()) {
163
167
  */
164
168
  export function markDelivered(db, id, now = Date.now()) {
165
169
  const info = db
166
- .prepare("UPDATE mailbox SET status = 'delivered', reason = NULL, updated_at = ?, resolved_at = ? WHERE id = ? AND status = 'held'")
170
+ .prepare("UPDATE mailbox SET status = 'delivered', reason = NULL, detail = NULL, updated_at = ?, resolved_at = ? WHERE id = ? AND status = 'held'")
167
171
  .run(now, now, id);
168
172
  return info.changes > 0;
169
173
  }
170
174
  /**
171
- * Refresh the why-held `reason` on a still-held row (informational — the value
172
- * `afx inbox` shows and the send response reports). Only touches `held` rows, so
173
- * it can never relabel or resurrect a terminal row. Returns true if a held row was
174
- * updated. The delivery pass calls this so a held row's reason tracks the current
175
- * gate verdict (e.g. `busy` → `no-live-pty` when the terminal dies).
175
+ * Refresh the why-held verdict — `reason` AND its gate `detail` — on a still-held row
176
+ * (informational: the values `afx inbox`, the send response, the escalation broadcast and the
177
+ * owner starvation notice report). Only touches `held` rows, so it can never relabel or
178
+ * resurrect a terminal row. Returns true if a held row was updated. The delivery pass calls
179
+ * this so a held row's verdict tracks the current gate verdict (e.g. `busy` → `no-live-pty`
180
+ * when the terminal dies).
181
+ *
182
+ * ONE statement, not two (Issue #1482): the pair is a single verdict, and writing it in two
183
+ * updates would leave a window — and a second `updated_at` bump — where a reader could see a
184
+ * new reason beside the previous reason's detail. Callers that hold for a NON-gate cause pass
185
+ * `detail: null` so a stale detail can never outlive the verdict that produced it.
186
+ *
187
+ * `updated_at` therefore keeps meaning "when this row's verdict last MOVED", and that is
188
+ * enforced HERE, by the `(reason IS NOT ? OR detail IS NOT ?)` predicate — not merely by the
189
+ * callers that happen to check first. The delivery pass does guard before calling (see
190
+ * `mailbox-delivery.ts`), but a guard living only at the call site is one new caller away from
191
+ * silently breaking the starvation notice, which reads elapsed time off `updated_at` to say how
192
+ * long a composer has been occupied. `IS NOT` rather than `<>` because both columns are
193
+ * nullable and SQL's `<>` is not null-safe: `NULL <> NULL` is NULL, not false, so a
194
+ * `null`→`null` no-op would slip through the predicate and bump the timestamp anyway.
195
+ *
196
+ * Returns true only when a held row's verdict actually moved. A repeat of the same pair, a
197
+ * terminal row, and an unknown id are all `false` — callers wanting "does this row exist"
198
+ * should ask {@link getById}, not this.
176
199
  */
177
- export function setHeldReason(db, id, reason, now = Date.now()) {
200
+ export function setHeldVerdict(db, id, reason, detail, now = Date.now()) {
178
201
  const info = db
179
- .prepare("UPDATE mailbox SET reason = ?, updated_at = ? WHERE id = ? AND status = 'held'")
180
- .run(reason, now, id);
202
+ .prepare("UPDATE mailbox SET reason = ?, detail = ?, updated_at = ? " +
203
+ "WHERE id = ? AND status = 'held' AND (reason IS NOT ? OR detail IS NOT ?)")
204
+ .run(reason, detail, now, id, reason, detail);
181
205
  return info.changes > 0;
182
206
  }
183
207
  /**
@@ -193,6 +217,25 @@ export function markEscalated(db, id, now = Date.now()) {
193
217
  .run(now, id);
194
218
  return info.changes > 0;
195
219
  }
220
+ /**
221
+ * Flag an already-DELIVERED row as escalated (Issue #1584) — visibility only, and the
222
+ * counterpart to {@link markEscalated} for the one case that flags a row *after* it has left
223
+ * the held set: a delivery whose write completed but whose echo never confirmed.
224
+ *
225
+ * A separate function rather than a relaxed guard on {@link markEscalated}, because that one's
226
+ * held-only contract is what makes the drainer's escalation pass safe to call blindly. Here the
227
+ * ordering is the point: the row is marked `delivered` FIRST (that commit is what makes the
228
+ * write un-repeatable even across a crash), so by the time the verdict is known the held-only
229
+ * guard would silently no-op and the flag would be lost.
230
+ *
231
+ * Delivered-only and idempotent (the `escalated = 0` guard). Returns true if it flipped.
232
+ */
233
+ export function markEscalatedDelivered(db, id, now = Date.now()) {
234
+ const info = db
235
+ .prepare("UPDATE mailbox SET escalated = 1, updated_at = ? WHERE id = ? AND status = 'delivered' AND escalated = 0")
236
+ .run(now, id);
237
+ return info.changes > 0;
238
+ }
196
239
  /**
197
240
  * Supersede-key prefix for architect starvation notices (Spec 1313 round 3, change 3). A
198
241
  * notice row carries `${NOTICE_SUPERSEDE_PREFIX}<starving-agent>` so (a) one pending notice
@@ -217,7 +260,8 @@ export function findStarvingAgents(db, now = Date.now()) {
217
260
  .prepare(`SELECT workspace_path AS workspacePath, to_agent AS toAgent,
218
261
  MIN(${ESCALATION_START_SQL}) AS stuckSince,
219
262
  COUNT(*) AS count,
220
- MAX(reason) AS reason
263
+ MAX(reason) AS reason,
264
+ MAX(detail) AS detail
221
265
  FROM mailbox
222
266
  WHERE status = 'held'
223
267
  AND (not_before IS NULL OR not_before <= ?)
@@ -1 +1 @@
1
- {"version":3,"file":"mailbox.js","sourceRoot":"","sources":["../../../src/agent-farm/db/mailbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAiCzC,MAAM,UAAU,GAAG;;;;;;;;;;CAUlB,CAAC;AAEF,SAAS,QAAQ,CAAC,KAAmB,EAAE,GAAW;IAChD,OAAO;QACL,EAAE,EAAE,UAAU,EAAE;QAChB,cAAc,EAAE,KAAK,CAAC,aAAa;QACnC,QAAQ,EAAE,KAAK,CAAC,OAAO;QACvB,WAAW,EAAE,KAAK,CAAC,UAAU,IAAI,IAAI;QACrC,UAAU,EAAE,KAAK,CAAC,SAAS,IAAI,IAAI;QACnC,cAAc,EAAE,KAAK,CAAC,aAAa,IAAI,IAAI;QAC3C,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,iBAAiB,EAAE,KAAK,CAAC,gBAAgB;QACzC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/B,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,IAAI;QAC5B,aAAa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AM,GAAG,GAAG,EAAE;SACX,OAAO,CACN,sGAAsG,CACvG;SACA,GAAG,CAAC,aAAa,EAAE,YAAY,CAAkB,CAAC;IACrD,OAAO,GAAG,CAAC,CAAC,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CACvB,EAAqB,EACrB,aAAqB,EACrB,YAAoB,EACpB,KAAmB,EACnB,MAAc,IAAI,CAAC,GAAG,EAAE;IAExB,MAAM,GAAG,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE;QAC9B,EAAE,CAAC,OAAO,CACR,8IAA8I,CAC/I,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC;QAC7C,OAAO,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,EAAE,GAAG,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAC3B,EAAqB,EACrB,aAAqB,EACrB,MAAc,IAAI,CAAC,GAAG,EAAE;IAExB,MAAM,MAAM,GAAG,GAAG,GAAG,aAAa,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IACzD,MAAM,IAAI,GAAG,EAAE;SACZ,OAAO,CACN,4FAA4F,CAC7F;SACA,GAAG,CAAC,MAAM,CAAC,CAAC;IACf,OAAO,IAAI,CAAC,OAAO,CAAC;AACtB,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * global.db forward-only migrations (Issue #1476).
3
+ *
4
+ * The migration sequence used to live inline inside the private
5
+ * `ensureGlobalDatabase()` path in `db/index.ts`, so migration tests could only
6
+ * drive hand-maintained *replicas* of it. This module is the single source of
7
+ * truth both production init and the tests call:
8
+ *
9
+ * - `ensureGlobalDatabase()` calls `runGlobalMigrations(db)` on an existing
10
+ * database (fresh installs get the final shape from GLOBAL_SCHEMA and stamp
11
+ * every marker up to `GLOBAL_CURRENT_VERSION` instead).
12
+ * - `__tests__/spec-1313-migration.test.ts` builds a database at a historical
13
+ * version and calls the very same function, so the SQL under test is the SQL
14
+ * that ships.
15
+ *
16
+ * The runner takes an explicit `db` handle (matching `db/mailbox.ts` /
17
+ * `db/consolidate.ts`) — it never opens a connection, reads a singleton, or sets
18
+ * pragmas. Every step is idempotent and gated on its `_migrations` marker, so
19
+ * calling it repeatedly on the same handle is a no-op. Migrations are
20
+ * forward-only by project convention; there is no reverse SQL.
21
+ */
22
+ import type Database from 'better-sqlite3';
23
+ /** Current migration version — bump when adding new migrations. */
24
+ export declare const GLOBAL_CURRENT_VERSION = 18;
25
+ export interface GlobalMigrationOptions {
26
+ /**
27
+ * Sink for per-migration progress lines. Defaults to `console.log`, which is
28
+ * what the production open path wants; tests pass a collector (or a no-op) to
29
+ * keep output clean and to assert which steps actually ran.
30
+ */
31
+ log?: (message: string) => void;
32
+ /**
33
+ * Directory holding shellper sockets, whose files migration v8 renames.
34
+ * Defaults to `~/.codev/run` — the production location. Tests point it at a
35
+ * temp directory so driving the real runner never touches a developer's live
36
+ * sockets.
37
+ */
38
+ runDir?: string;
39
+ }
40
+ /**
41
+ * Run every outstanding global.db migration against `db`.
42
+ *
43
+ * Safe to call on any existing database that reached its recorded version through
44
+ * migrations: each step checks its own `_migrations` marker first, so applied steps
45
+ * are skipped and the call converges on the `GLOBAL_CURRENT_VERSION` shape.
46
+ *
47
+ * NOT for a fresh database. A GLOBAL_SCHEMA-shaped database with no markers would run
48
+ * v5 against the long-renamed `terminal_sessions.project_path` — which is why
49
+ * `ensureGlobalDatabase()` stamps every marker on the fresh path instead of running
50
+ * the chain. That shape is rejected at entry with a named error rather than an opaque
51
+ * mid-chain SQLite failure.
52
+ *
53
+ * @throws if the database carries the post-v9 `workspace_path` shape without the v9
54
+ * marker to match (a fresh schema that never walked the chain).
55
+ */
56
+ export declare function runGlobalMigrations(db: Database.Database, options?: GlobalMigrationOptions): void;
57
+ //# sourceMappingURL=migrations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../../src/agent-farm/db/migrations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAK3C,mEAAmE;AACnE,eAAO,MAAM,sBAAsB,KAAK,CAAC;AAEzC,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CACjC,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACrB,OAAO,GAAE,sBAA2B,GACnC,IAAI,CAufN"}