@defrex/autobuild 1.10.0 → 1.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +745 -69
  3. package/bin/ab-dispatch-generation.ts +3 -1
  4. package/docs/accounts.md +2 -1
  5. package/docs/answering-blocked-builds.md +20 -0
  6. package/docs/architecture.md +165 -29
  7. package/docs/build-store.md +10 -7
  8. package/docs/cli.md +33 -1
  9. package/docs/configuration-overview.md +4 -1
  10. package/docs/configuration.md +381 -29
  11. package/docs/dispatcher.md +64 -4
  12. package/docs/forges.md +7 -0
  13. package/docs/integration-tree.md +2 -2
  14. package/docs/operating.md +4 -2
  15. package/docs/operator-api.md +134 -6
  16. package/docs/operator-surfaces.md +85 -0
  17. package/docs/optimization-nodes.md +69 -11
  18. package/docs/plugin-authoring.md +37 -1
  19. package/docs/remote-store-protocol.md +94 -13
  20. package/docs/remote-ticket-protocol.md +40 -0
  21. package/docs/restacking.md +20 -4
  22. package/docs/setup.md +14 -2
  23. package/docs/ticket-dependencies.md +10 -3
  24. package/docs/ticket-sources.md +24 -2
  25. package/docs/tickets.md +7 -1
  26. package/docs/troubleshooting.md +8 -0
  27. package/docs/verification.md +4 -3
  28. package/docs/workspaces.md +3 -0
  29. package/package.json +9 -5
  30. package/packages/core/src/cli/accounts.ts +7 -2
  31. package/packages/core/src/cli/attention.ts +3 -1
  32. package/packages/core/src/cli/binary-direct.ts +2 -0
  33. package/packages/core/src/cli/binary-lifecycle.ts +2 -1
  34. package/packages/core/src/cli/build-control.ts +79 -1
  35. package/packages/core/src/cli/context.ts +4 -0
  36. package/packages/core/src/cli/dashboard/facts.ts +49 -53
  37. package/packages/core/src/cli/dashboard/header.ts +111 -0
  38. package/packages/core/src/cli/dashboard/model.ts +31 -39
  39. package/packages/core/src/cli/dashboard/objective-row.ts +46 -14
  40. package/packages/core/src/cli/dashboard/poll.ts +179 -76
  41. package/packages/core/src/cli/dashboard/render.ts +159 -230
  42. package/packages/core/src/cli/dashboard/row-text.ts +538 -0
  43. package/packages/core/src/cli/dashboard/timeline.ts +288 -0
  44. package/packages/core/src/cli/dashboard/vocabulary.ts +188 -0
  45. package/packages/core/src/cli/dispatch-args.ts +44 -1
  46. package/packages/core/src/cli/dispatch-frontend.ts +40 -40
  47. package/packages/core/src/cli/dispatch-launch-stop.ts +18 -0
  48. package/packages/core/src/cli/dispatch-launcher.ts +20 -7
  49. package/packages/core/src/cli/dispatch-web.ts +155 -0
  50. package/packages/core/src/cli/dispatch.ts +202 -38
  51. package/packages/core/src/cli/help.ts +87 -3
  52. package/packages/core/src/cli/init-validation.ts +3 -3
  53. package/packages/core/src/cli/main.ts +70 -6
  54. package/packages/core/src/cli/mcp.ts +35 -3
  55. package/packages/core/src/cli/objective.ts +1 -1
  56. package/packages/core/src/cli/operator-preference.ts +57 -0
  57. package/packages/core/src/cli/repo-lease.ts +2 -0
  58. package/packages/core/src/cli/repo-state.ts +56 -6
  59. package/packages/core/src/cli/repository-status.ts +105 -49
  60. package/packages/core/src/cli/status.ts +82 -1
  61. package/packages/core/src/cli/terminal-restore.ts +32 -7
  62. package/packages/core/src/cli/ticket.ts +98 -36
  63. package/packages/core/src/cli/wait.ts +14 -6
  64. package/packages/core/src/cli/watch.ts +20 -4
  65. package/packages/core/src/cli/web.ts +139 -0
  66. package/packages/core/src/config/live.ts +99 -14
  67. package/packages/core/src/config/load.ts +61 -20
  68. package/packages/core/src/config/local.ts +212 -0
  69. package/packages/core/src/config/pipeline-source.ts +2 -0
  70. package/packages/core/src/config/reference.ts +18 -0
  71. package/packages/core/src/config/schema.ts +45 -10
  72. package/packages/core/src/events/catalog.ts +4 -0
  73. package/packages/core/src/events/payloads.ts +97 -0
  74. package/packages/core/src/events/policy.ts +10 -0
  75. package/packages/core/src/events/repository.ts +46 -3
  76. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +381 -30
  77. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/017d8dd5bb6dd80b.json.gz +0 -0
  78. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/178e12f1759b7552.json.gz +0 -0
  79. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/4932c70a2af97faf.json.gz +0 -0
  80. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/536085773daf6b58.json.gz +0 -0
  81. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/6bd6275061aaffa5.json.gz +0 -0
  82. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/89625654b02e9ac1.json.gz +0 -0
  83. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a98af134be2da8a9.json.gz +0 -0
  84. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/d5d5ccca80a893d8.json.gz +0 -0
  85. package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/f8155387eb5f375c.json.gz +0 -0
  86. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3c27f918b194e3b3.json +465 -0
  87. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/46196d8f0076496a.json +97 -0
  88. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/79f0e0f4ccd43ba2.json +455 -0
  89. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/859c09edac738823.json +1086 -0
  90. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a283c1f3462b1cc1.json +81 -0
  91. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a6e570fb126991ff.json +36 -0
  92. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a8acf22c968b6e3d.json +81 -0
  93. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/ba7b85895bf6698e.json +1153 -0
  94. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/fc66408cde0b6b04.json +637 -0
  95. package/packages/core/src/kernel/build-roster.ts +230 -0
  96. package/packages/core/src/kernel/dispatch-capacity.ts +4 -2
  97. package/packages/core/src/kernel/dispatch-status.ts +139 -0
  98. package/packages/core/src/kernel/engine.ts +43 -5
  99. package/packages/core/src/kernel/execution-intervals.ts +61 -0
  100. package/packages/core/src/kernel/generators/optimization-log.ts +101 -0
  101. package/packages/core/src/kernel/generators/repository-journals.ts +13 -0
  102. package/packages/core/src/kernel/leaf-restack-base.ts +33 -7
  103. package/packages/core/src/kernel/leaf-restack-state.ts +82 -3
  104. package/packages/core/src/kernel/log-index.ts +19 -0
  105. package/packages/core/src/kernel/optimization-admission.ts +244 -3
  106. package/packages/core/src/kernel/optimization.ts +183 -4
  107. package/packages/core/src/kernel/phase-failures.ts +121 -0
  108. package/packages/core/src/kernel/published-branch-head.ts +60 -0
  109. package/packages/core/src/kernel/read-facts.ts +15 -13
  110. package/packages/core/src/kernel/reducer-registry.ts +27 -8
  111. package/packages/core/src/kernel/reducer-revisions.ts +27 -0
  112. package/packages/core/src/kernel/reducer.ts +63 -4
  113. package/packages/core/src/kernel/rollup.ts +61 -0
  114. package/packages/core/src/kernel/setup-streak.ts +38 -0
  115. package/packages/core/src/kernel/step-durations.ts +257 -0
  116. package/packages/core/src/kernel/target-observation.ts +6 -1
  117. package/packages/core/src/kernel/target-rewrite-recovery.ts +116 -0
  118. package/packages/core/src/kernel/verify-diff-base.ts +5 -0
  119. package/packages/core/src/kernel/verify-stages.ts +13 -3
  120. package/packages/core/src/ontology.ts +5 -0
  121. package/packages/core/src/operator/agent-context-serve.ts +631 -0
  122. package/packages/core/src/operator/annotations.ts +75 -5
  123. package/packages/core/src/operator/attention.ts +470 -0
  124. package/packages/core/src/operator/canonical-skills.ts +35 -0
  125. package/packages/core/src/operator/cli-equivalents.ts +270 -0
  126. package/packages/core/src/operator/context-prompts.ts +61 -0
  127. package/packages/core/src/operator/index.ts +49 -1
  128. package/packages/core/src/operator/landings.ts +28 -19
  129. package/packages/core/src/operator/optimization.ts +7 -0
  130. package/packages/core/src/operator/protocol.ts +3 -0
  131. package/packages/core/src/operator/query.ts +129 -74
  132. package/packages/core/src/operator/read-view.ts +5 -2
  133. package/packages/core/src/operator/registry.ts +406 -46
  134. package/packages/core/src/operator/requests.ts +20 -18
  135. package/packages/core/src/operator/sandbox-host.ts +107 -11
  136. package/packages/core/src/operator/sandbox-resolver.ts +253 -0
  137. package/packages/core/src/operator/sandbox.ts +778 -82
  138. package/packages/core/src/operator/ticket-asset-list.ts +77 -0
  139. package/packages/core/src/operator/ticket-assets.ts +167 -0
  140. package/packages/core/src/operator/tickets.ts +33 -2
  141. package/packages/core/src/plugin-sdk/index.ts +22 -0
  142. package/packages/core/src/plugins/manifest.ts +1 -1
  143. package/packages/core/src/ports/forge/fake.ts +92 -1
  144. package/packages/core/src/ports/forge/git-blob.ts +15 -0
  145. package/packages/core/src/ports/forge/github.ts +82 -0
  146. package/packages/core/src/ports/forge/local-git.ts +61 -1
  147. package/packages/core/src/ports/forge-failure.ts +24 -0
  148. package/packages/core/src/ports/runner/antigravity-test.fixture.ts +149 -0
  149. package/packages/core/src/ports/runner/claude-test.fixture.ts +71 -0
  150. package/packages/core/src/ports/runner/codex-test.fixture.ts +63 -0
  151. package/packages/core/src/ports/tickets/contract.ts +71 -0
  152. package/packages/core/src/ports/tickets/fake.ts +11 -0
  153. package/packages/core/src/ports/tickets/file.ts +18 -0
  154. package/packages/core/src/ports/tickets/github-fake.ts +136 -4
  155. package/packages/core/src/ports/tickets/github.ts +387 -30
  156. package/packages/core/src/ports/tickets/hosted-index.ts +10 -0
  157. package/packages/core/src/ports/tickets/linear.ts +130 -0
  158. package/packages/core/src/ports/tickets/priority.ts +9 -0
  159. package/packages/core/src/ports/tickets/remote-protocol.ts +34 -0
  160. package/packages/core/src/ports/tickets/remote.ts +70 -6
  161. package/packages/core/src/ports/tickets/search.ts +139 -0
  162. package/packages/core/src/ports/types.ts +104 -2
  163. package/packages/core/src/ports/workspace/builtin-capabilities.ts +9 -0
  164. package/packages/core/src/ports/workspace/create.ts +15 -1
  165. package/packages/core/src/ports/workspace/fake.ts +340 -12
  166. package/packages/core/src/ports/workspace/git-worktree.ts +833 -42
  167. package/packages/core/src/ports/workspace/operator-sandbox.ts +129 -12
  168. package/packages/core/src/ports/workspace/process-group.ts +48 -0
  169. package/packages/core/src/ports/workspace/vercel-sandbox.ts +1260 -123
  170. package/packages/core/src/processes/agent-context-assemble.ts +576 -0
  171. package/packages/core/src/processes/agent-context.ts +469 -0
  172. package/packages/core/src/processes/build-runner.ts +387 -236
  173. package/packages/core/src/processes/dispatcher.ts +211 -55
  174. package/packages/core/src/processes/execution-no-progress.ts +4 -0
  175. package/packages/core/src/processes/optimization-activity.ts +120 -0
  176. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  177. package/packages/core/src/processes/repo-view.ts +78 -2
  178. package/packages/core/src/processes/sandbox-state.ts +53 -6
  179. package/packages/core/src/processes/tick-publication.ts +2 -0
  180. package/packages/core/src/processes/workspace-preparation.ts +76 -0
  181. package/packages/core/src/scenarios/harness.ts +0 -5
  182. package/packages/core/src/store/account-redaction.ts +1 -0
  183. package/packages/core/src/store/adapter.ts +52 -1
  184. package/packages/core/src/store/agent-context.ts +432 -0
  185. package/packages/core/src/store/build-feed.ts +291 -0
  186. package/packages/core/src/store/build-scope.ts +19 -1
  187. package/packages/core/src/store/contract.ts +911 -14
  188. package/packages/core/src/store/digest.ts +19 -6
  189. package/packages/core/src/store/histogram.ts +113 -0
  190. package/packages/core/src/store/local/schema.ts +62 -0
  191. package/packages/core/src/store/local/store.ts +628 -22
  192. package/packages/core/src/store/local/ticket-asset-heads.ts +23 -0
  193. package/packages/core/src/store/memory.ts +461 -69
  194. package/packages/core/src/store/open-builds.ts +19 -0
  195. package/packages/core/src/store/phase-session.ts +32 -4
  196. package/packages/core/src/store/reduced-reads.ts +14 -4
  197. package/packages/core/src/store/reducer-value-shapes.json +7027 -5751
  198. package/packages/core/src/store/reducer-values.ts +6 -1
  199. package/packages/core/src/store/remote/client.ts +208 -2
  200. package/packages/core/src/store/remote/compatibility.ts +1 -1
  201. package/packages/core/src/store/remote/index.ts +33 -0
  202. package/packages/core/src/store/remote/protocol.ts +69 -0
  203. package/packages/core/src/store/remote/released-clients.json +22 -0
  204. package/packages/core/src/store/remote/released-reducer-values/1.11.0.json +35680 -0
  205. package/packages/core/src/store/remote/released-reducer-values/1.11.1.json +35718 -0
  206. package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
  207. package/packages/core/src/store/retention.ts +23 -1
  208. package/packages/core/src/store/rollups.ts +337 -0
  209. package/packages/core/src/store/session-handle.ts +20 -2
  210. package/packages/core/src/store/snapshots.ts +10 -0
  211. package/packages/core/src/store/types.ts +108 -9
  212. package/packages/core/src/testing/dispatch-journals.ts +117 -0
  213. package/packages/core/src/testing/dispatch-read-budget.ts +1092 -2
  214. package/packages/core/src/testing/git-config-isolation.ts +7 -5
  215. package/packages/core/src/testing/index.ts +27 -0
  216. package/packages/core/src/testing/memory-operator-sandbox.ts +346 -0
  217. package/packages/core/src/testing/reduced-read-budget.ts +1873 -98
  218. package/packages/core/src/web/analytics-source.ts +303 -0
  219. package/packages/core/src/web/assets/Atkinson-OFL.txt +93 -0
  220. package/packages/core/src/web/assets/AtkinsonHyperlegibleNext.latin.woff2 +0 -0
  221. package/packages/core/src/web/assets/JetBrains-OFL.txt +93 -0
  222. package/packages/core/src/web/assets/JetBrainsMono.latin.woff2 +0 -0
  223. package/packages/core/src/web/assets/app.css +1 -0
  224. package/packages/core/src/web/assets/app.js +9 -0
  225. package/packages/core/src/web/assets/manifest.json +31 -0
  226. package/packages/core/src/web/assets/theme.js +1 -0
  227. package/packages/core/src/web/bounded.ts +31 -0
  228. package/packages/core/src/web/http.ts +315 -0
  229. package/packages/core/src/web/hub.ts +160 -0
  230. package/packages/core/src/web/options.ts +38 -0
  231. package/packages/core/src/web/overview-source.ts +322 -0
  232. package/packages/core/src/web/page.ts +56 -0
  233. package/packages/core/src/web/protocol.ts +151 -0
  234. package/packages/core/src/web/read-only.ts +23 -0
  235. package/packages/core/src/web/repository-source.ts +39 -0
  236. package/packages/core/src/web/server.ts +97 -0
  237. package/skills/code-review/SKILL.md +10 -2
  238. package/skills/guide/SKILL.md +376 -54
  239. package/skills/guide/references/accounts.md +2 -1
  240. package/skills/guide/references/integration-tree.md +2 -2
  241. package/skills/guide/references/operator-api.md +134 -6
  242. package/skills/guide/references/optimization-nodes.md +69 -11
  243. package/skills/guide/references/plugin-authoring.md +37 -1
  244. package/skills/guide/references/remote-store-protocol.md +94 -13
  245. package/skills/guide/references/remote-ticket-protocol.md +40 -0
  246. package/skills/guide/references/restacking.md +20 -4
  247. package/skills/guide/references/setup.md +14 -2
  248. package/skills/guide/references/ticket-dependencies.md +10 -3
  249. package/skills/implement/SKILL.md +23 -4
  250. package/skills/operate/SKILL.md +134 -32
  251. package/skills/plan/SKILL.md +10 -4
  252. package/skills/plan-review/SKILL.md +9 -2
  253. package/skills/spec/SKILL.md +34 -8
  254. package/skills/tickets/SKILL.md +51 -5
  255. package/templates/hosted-service/package.json +2 -2
@@ -4,11 +4,15 @@
4
4
  * MCP annotations are per-tool hints, never per-argument, so a tool whose
5
5
  * action set *may* destroy work carries `destructiveHint: true` for the whole
6
6
  * tool, and each destructive action value is additionally named in the input
7
- * field's description so a model still sees the per-value risk. Exactly four
8
- * tools may destroy work: `builds.control` (abort, discard),
9
- * `builds.answer` (revise-spec), `builds.reopen` (a spec revision, and it
10
- * revokes merge consent), and `tickets.move` (a move into the configured
11
- * ready state).
7
+ * field's description so a model still sees the per-value risk. The tools
8
+ * that may destroy work:
9
+ * - `optimization.stop` (abort aborts running attempts; a stop is final),
10
+ * - `builds.control` (abort, discard),
11
+ * - `builds.answer` (revise-spec),
12
+ * - `builds.reopen` (a spec revision, and it revokes merge consent),
13
+ * - `tickets.move` (a move into the configured ready state),
14
+ * - `tickets.asset.remove` (drops an asset from the ticket's current assets),
15
+ * - `sandbox.reset` and `sandbox.publish`.
12
16
  *
13
17
  * The registry entries and the contract suite both read this table, so a
14
18
  * change to any tool's risk class is a one-line visible diff this suite
@@ -129,6 +133,12 @@ export const OPERATOR_TOOL_ANNOTATIONS = {
129
133
  idempotentHint: true,
130
134
  approval: 'never',
131
135
  },
136
+ 'repository.attention': {
137
+ readOnlyHint: true,
138
+ destructiveHint: false,
139
+ idempotentHint: true,
140
+ approval: 'never',
141
+ },
132
142
  'repository.settings': {
133
143
  readOnlyHint: false,
134
144
  destructiveHint: false,
@@ -171,6 +181,12 @@ export const OPERATOR_TOOL_ANNOTATIONS = {
171
181
  idempotentHint: true,
172
182
  approval: 'never',
173
183
  },
184
+ 'tickets.search': {
185
+ readOnlyHint: true,
186
+ destructiveHint: false,
187
+ idempotentHint: true,
188
+ approval: 'never',
189
+ },
174
190
  'tickets.get': {
175
191
  readOnlyHint: true,
176
192
  destructiveHint: false,
@@ -213,6 +229,24 @@ export const OPERATOR_TOOL_ANNOTATIONS = {
213
229
  idempotentHint: true,
214
230
  approval: 'default',
215
231
  },
232
+ 'tickets.asset.attach': {
233
+ readOnlyHint: false,
234
+ destructiveHint: false,
235
+ idempotentHint: false,
236
+ approval: 'default',
237
+ },
238
+ 'tickets.asset.get': {
239
+ readOnlyHint: true,
240
+ destructiveHint: false,
241
+ idempotentHint: true,
242
+ approval: 'never',
243
+ },
244
+ 'tickets.asset.remove': {
245
+ readOnlyHint: false,
246
+ destructiveHint: true,
247
+ idempotentHint: false,
248
+ approval: 'default',
249
+ },
216
250
  'notes.read': {
217
251
  readOnlyHint: true,
218
252
  destructiveHint: false,
@@ -225,6 +259,30 @@ export const OPERATOR_TOOL_ANNOTATIONS = {
225
259
  idempotentHint: false,
226
260
  approval: 'default',
227
261
  },
262
+ 'sandbox.open': {
263
+ readOnlyHint: false,
264
+ destructiveHint: false,
265
+ idempotentHint: true,
266
+ approval: 'default',
267
+ },
268
+ 'sandbox.status': {
269
+ readOnlyHint: true,
270
+ destructiveHint: false,
271
+ idempotentHint: true,
272
+ approval: 'never',
273
+ },
274
+ 'sandbox.close': {
275
+ readOnlyHint: false,
276
+ destructiveHint: false,
277
+ idempotentHint: true,
278
+ approval: 'default',
279
+ },
280
+ 'sandbox.refresh': {
281
+ readOnlyHint: false,
282
+ destructiveHint: false,
283
+ idempotentHint: true,
284
+ approval: 'default',
285
+ },
228
286
  'sandbox.exec': {
229
287
  readOnlyHint: false,
230
288
  destructiveHint: false,
@@ -267,6 +325,18 @@ export const OPERATOR_TOOL_ANNOTATIONS = {
267
325
  idempotentHint: false,
268
326
  approval: 'default',
269
327
  },
328
+ 'context.list': {
329
+ readOnlyHint: true,
330
+ destructiveHint: false,
331
+ idempotentHint: true,
332
+ approval: 'never',
333
+ },
334
+ 'context.read': {
335
+ readOnlyHint: true,
336
+ destructiveHint: false,
337
+ idempotentHint: true,
338
+ approval: 'never',
339
+ },
270
340
  } as const satisfies Record<string, ToolAnnotationsTableEntry>
271
341
 
272
342
  export type OperatorToolName = keyof typeof OPERATOR_TOOL_ANNOTATIONS
@@ -0,0 +1,470 @@
1
+ /**
2
+ * The operator attention digest (`repository.attention`): one read of
3
+ * everything that currently waits on the operator for a repository, for a
4
+ * connected agent that cannot hold `ab watch --operator` open.
5
+ *
6
+ * The digest composes the services the dedicated tools already run — the
7
+ * open escalations `builds.get` reports, the consent queue `merges.list`
8
+ * returns, the attention page `repository.events` serves and the
9
+ * `repository.status` projection — so each section matches its dedicated tool
10
+ * by construction. It adds only a closed `resolve` list per item: the
11
+ * registry tool call that acts on it.
12
+ *
13
+ * Read cost per call is bounded: one `repository.status` pass, one open-build
14
+ * view pass (one facts read per open, nonterminal build; settled builds are
15
+ * never listed), and one repository journal page of at most 256 rows after
16
+ * the cursor. Nothing grows with log length or settled history, and the call
17
+ * reads zero event rows when nothing changed since the cursor.
18
+ */
19
+ import { isDiverged } from '../cli/build-progress'
20
+ import { summarizeFrom, type BuildSummary } from '../cli/status'
21
+ import type { RepositoryStatus } from '../cli/repository-status'
22
+ import type { ConsentQueueEntry } from '../cli/dashboard/tree'
23
+ import type { RepositoryEvent } from '../events/repository'
24
+ import { integrationFailed, missingIntegrationFailures } from '../kernel/integration-state'
25
+ import type { BuildState, OpenEscalation } from '../kernel/reducer'
26
+ import type { TicketRef } from '../ontology'
27
+ import type { BuildStore } from '../store/types'
28
+ import type { OperatorToolName } from './annotations'
29
+ import { consentEntryFromView } from './landings'
30
+ import { getRepositoryStatus } from './query'
31
+ import { withOperatorView } from './read-view'
32
+ import { readRepositoryAttentionPage } from './repository-events'
33
+
34
+ /** A tool call that resolves an attention item. `input` is partial: it names
35
+ * the repository and the subject (slug, ticket id, action, head…); the agent
36
+ * supplies the rest (an answer's text, a ticket's title). `by: 'human'` marks a
37
+ * condition no agent call fixes: the named tool is the read that supplies the
38
+ * evidence to report to a human. */
39
+ export interface Resolution {
40
+ tool: OperatorToolName
41
+ input: Record<string, unknown>
42
+ by: 'operator' | 'human'
43
+ note?: string
44
+ }
45
+
46
+ export interface AttentionEscalationItem {
47
+ slug: string
48
+ ticket?: TicketRef
49
+ status: BuildSummary['status']
50
+ phase?: BuildSummary['phase']
51
+ round?: number
52
+ escalations: OpenEscalation[]
53
+ resolve: Resolution[]
54
+ }
55
+
56
+ export interface AttentionMergeItem {
57
+ slug: string
58
+ pr: { number: number; url: string } | null
59
+ entry: ConsentQueueEntry
60
+ resolve: Resolution[]
61
+ }
62
+
63
+ export interface AttentionEventItem {
64
+ event: RepositoryEvent
65
+ resolve: Resolution[]
66
+ }
67
+
68
+ export type AttentionWaitingReason = 'paused' | 'stalled' | 'verification-failed' | 'ci-failing'
69
+
70
+ export interface AttentionWaitingItem {
71
+ slug: string
72
+ ticket?: TicketRef
73
+ reason: AttentionWaitingReason
74
+ detail: unknown
75
+ resolve: Resolution[]
76
+ }
77
+
78
+ export type DispatcherAttentionKind = 'no-holder' | 'upgrade-failed' | 'rollback' | 'forge-cooldown'
79
+
80
+ export interface DispatcherAttentionItem {
81
+ kind: DispatcherAttentionKind
82
+ detail: string
83
+ /** The `repository.status` fragment the item came from. */
84
+ source: unknown
85
+ resolve: Resolution[]
86
+ }
87
+
88
+ export interface OperatorAttention {
89
+ repo: string
90
+ generatedAt: string
91
+ escalations: AttentionEscalationItem[]
92
+ merges: AttentionMergeItem[]
93
+ events: { items: AttentionEventItem[]; cursor: number; hasMore: boolean }
94
+ waiting: AttentionWaitingItem[]
95
+ dispatcher: DispatcherAttentionItem[]
96
+ }
97
+
98
+ const REPAIR_NOTE = 'file a repair child targeting this node'
99
+
100
+ const reportToHuman = (repo: string, note: string): Resolution[] => [
101
+ { tool: 'repository.status', input: { repo }, by: 'human', note },
102
+ ]
103
+
104
+ const FORGE_CLEAR_NOTE =
105
+ 'only when the cooldown is erroneous; otherwise it lifts on its own at resetAt'
106
+
107
+ /** Human-only repository attention: the agent reports it, never fixes it. */
108
+ const HUMAN_EVENT_NOTES = {
109
+ 'dispatcher.config-rejected': 'the dispatcher rejected a configuration change',
110
+ 'dispatcher.runtime-rolled-back': 'the dispatcher rolled back to its previous runtime',
111
+ 'dispatcher.upgrade-failed': 'a dispatcher upgrade failed',
112
+ 'dispatcher.kernel-git-unavailable': 'the dispatcher cannot run kernel git operations',
113
+ 'dispatcher.forge-readiness-failed': 'the dispatcher’s forge readiness check failed',
114
+ 'dispatcher.config-reloaded': 'a configuration change needs a dispatcher restart',
115
+ 'dispatcher.run-stopped': 'a dispatcher run stopped abnormally',
116
+ 'hook.failing': 'a configured hook is failing',
117
+ 'hook.recovered': 'a configured hook recovered',
118
+ 'hook.skipped': 'a configured hook skipped deliveries',
119
+ 'account.credentials-unavailable': 'a runner account’s credentials are unavailable',
120
+ 'forge.credential-limited': 'a forge credential outside the dispatcher is rate limited',
121
+ } as const satisfies Partial<Record<RepositoryEvent['type'], string>>
122
+
123
+ /** The note an attention type that no branch names resolves with. */
124
+ export const UNMAPPED_EVENT_NOTE = 'report this repository attention to the maintainer'
125
+
126
+ /** The tool calls that resolve one repository attention event. */
127
+ export function repositoryEventResolution(event: RepositoryEvent, repo: string): Resolution[] {
128
+ switch (event.type) {
129
+ case 'ticket.handed-back':
130
+ return [
131
+ {
132
+ tool: 'tickets.move',
133
+ input: { repo, id: event.payload.ticket.id },
134
+ by: 'operator',
135
+ note: 'decide where the handed-back ticket goes next',
136
+ },
137
+ ]
138
+ case 'ticket-preparation.resolved':
139
+ return [
140
+ {
141
+ tool: 'tickets.move',
142
+ input: { repo, id: event.payload.ticket.id },
143
+ by: 'operator',
144
+ note: 'ticket preparation was abandoned; decide where the ticket goes next',
145
+ },
146
+ ]
147
+ case 'ticket.start-settled':
148
+ return event.payload.slug !== undefined
149
+ ? [
150
+ {
151
+ tool: 'builds.get',
152
+ input: { repo, slug: event.payload.slug },
153
+ by: 'operator',
154
+ },
155
+ ]
156
+ : [
157
+ {
158
+ tool: 'tickets.start',
159
+ input: { repo, id: event.payload.ticket.id },
160
+ by: 'operator',
161
+ note: 'the start request settled without a build; fix the cause, then request again',
162
+ },
163
+ ]
164
+ case 'harvest.escalated':
165
+ case 'harvest.recovery-exhausted':
166
+ return [
167
+ { tool: 'harvest.status', input: { repo }, by: 'operator' },
168
+ { tool: 'harvest.control', input: { repo }, by: 'operator' },
169
+ ]
170
+ case 'dispatcher.forge-degraded':
171
+ return [
172
+ {
173
+ tool: 'repository.forge_clear',
174
+ input: { repo, forge: event.payload.forge },
175
+ by: 'operator',
176
+ note: FORGE_CLEAR_NOTE,
177
+ },
178
+ ]
179
+ case 'dispatcher.config-rejected':
180
+ case 'dispatcher.runtime-rolled-back':
181
+ case 'dispatcher.upgrade-failed':
182
+ case 'dispatcher.kernel-git-unavailable':
183
+ case 'dispatcher.forge-readiness-failed':
184
+ case 'dispatcher.config-reloaded':
185
+ case 'dispatcher.run-stopped':
186
+ case 'hook.failing':
187
+ case 'hook.recovered':
188
+ case 'hook.skipped':
189
+ case 'account.credentials-unavailable':
190
+ case 'forge.credential-limited':
191
+ return reportToHuman(repo, `${HUMAN_EVENT_NOTES[event.type]}; report it to the maintainer`)
192
+ default:
193
+ return reportToHuman(repo, UNMAPPED_EVENT_NOTE)
194
+ }
195
+ }
196
+
197
+ /** Why one open build waits on operator action. Every reason is checked on
198
+ * its own; no status — `blocked` included — short-circuits another. An open
199
+ * escalation is never a reason here: the escalations section reports it. */
200
+ export function waitingReasons(input: {
201
+ repo: string
202
+ slug: string
203
+ ticket?: TicketRef
204
+ summary: BuildSummary
205
+ state: BuildState
206
+ now: Date
207
+ }): AttentionWaitingItem[] {
208
+ const { repo, slug, summary, state } = input
209
+ const subject = {
210
+ slug,
211
+ ...(input.ticket !== undefined ? { ticket: input.ticket } : {}),
212
+ }
213
+ const items: AttentionWaitingItem[] = []
214
+ if (summary.status === 'paused')
215
+ items.push({
216
+ ...subject,
217
+ reason: 'paused',
218
+ detail: { phase: summary.phase ?? null },
219
+ resolve: [
220
+ {
221
+ tool: 'builds.control',
222
+ input: { repo, slug, action: 'resume' },
223
+ by: 'operator',
224
+ note: 'a build with open escalations needs them answered first',
225
+ },
226
+ ],
227
+ })
228
+ if (isDiverged(summary.progress, input.now))
229
+ items.push({
230
+ ...subject,
231
+ reason: 'stalled',
232
+ detail: {
233
+ lastEventAt: summary.progress.lastEventAt,
234
+ heartbeatAt: summary.progress.heartbeatAt,
235
+ },
236
+ resolve: [
237
+ {
238
+ tool: 'builds.control',
239
+ input: { repo, slug, action: 'pause' },
240
+ by: 'operator',
241
+ note: 'inspect builds.events first; aborting needs the human’s consent',
242
+ },
243
+ {
244
+ tool: 'builds.control',
245
+ input: { repo, slug, action: 'resume' },
246
+ by: 'operator',
247
+ },
248
+ ],
249
+ })
250
+ if (state.kind === 'node' && integrationFailed(state)) {
251
+ const cycle = state.integration!.cycle!
252
+ const failure =
253
+ state.integration?.failures?.find((entry) => entry.id === cycle.id) ??
254
+ missingIntegrationFailures(state, slug)[0]
255
+ items.push({
256
+ ...subject,
257
+ reason: 'verification-failed',
258
+ detail: {
259
+ cycle: cycle.id,
260
+ head: failure?.head ?? cycle.head,
261
+ parent: failure?.parent ?? cycle.parent,
262
+ steps: failure?.steps ?? [],
263
+ guidance: failure?.guidance ?? `${REPAIR_NOTE}: ${slug}`,
264
+ },
265
+ resolve: [
266
+ {
267
+ tool: 'tickets.create',
268
+ input: {
269
+ repo,
270
+ kind: 'work',
271
+ ...(input.ticket !== undefined ? { target: input.ticket.id } : {}),
272
+ },
273
+ by: 'operator',
274
+ note: REPAIR_NOTE,
275
+ },
276
+ {
277
+ tool: 'builds.answer',
278
+ input: { repo, slug },
279
+ by: 'operator',
280
+ note: 'or revise the node spec',
281
+ },
282
+ ],
283
+ })
284
+ }
285
+ if (summary.ciFailure !== undefined)
286
+ items.push({
287
+ ...subject,
288
+ reason: 'ci-failing',
289
+ detail: summary.ciFailure.text,
290
+ resolve: [
291
+ {
292
+ tool: 'builds.reopen',
293
+ input: { repo, slug },
294
+ by: 'operator',
295
+ note: 're-run CI on the forge if the failure looks flaky or external; reopen with feedback if the change broke it',
296
+ },
297
+ ],
298
+ })
299
+ return items
300
+ }
301
+
302
+ /** The dispatcher conditions in a `repository.status` projection that wait on
303
+ * the operator, in a fixed kind order. */
304
+ export function dispatcherAttention(
305
+ status: RepositoryStatus,
306
+ now: Date,
307
+ ): DispatcherAttentionItem[] {
308
+ const repo = status.repo
309
+ const items: DispatcherAttentionItem[] = []
310
+ const dispatcher = status.dispatcher
311
+ if (dispatcher.state !== 'held') {
312
+ const run = (dispatcher.expiredHolder ?? dispatcher.latestRun)?.run ?? null
313
+ items.push({
314
+ kind: 'no-holder',
315
+ detail: `dispatcher ${dispatcher.state}; latest run ${run ?? 'none'}`,
316
+ source: {
317
+ state: dispatcher.state,
318
+ run,
319
+ stop: dispatcher.latestStoppedRun?.stop ?? null,
320
+ },
321
+ resolve: reportToHuman(repo, 'no dispatcher holds this repository; report it'),
322
+ })
323
+ }
324
+ for (const entry of [status.upgradeStatus.current, status.upgradeStatus.previous]) {
325
+ if (entry?.outcome?.type !== 'dispatcher.upgrade-failed' || entry.superseded) continue
326
+ items.push({
327
+ kind: 'upgrade-failed',
328
+ detail: `run ${entry.run}: upgrade to ${entry.outcome.payload.target.key} failed: ${entry.outcome.payload.reason}`,
329
+ source: entry,
330
+ resolve: reportToHuman(repo, 'a dispatcher upgrade failed; report it'),
331
+ })
332
+ }
333
+ if (status.rollbackHold !== undefined)
334
+ items.push({
335
+ kind: 'rollback',
336
+ detail: `held runtime ${status.rollbackHold.payload.failed.version}; target ${status.rollbackHold.payload.target.key}`,
337
+ source: status.rollbackHold,
338
+ resolve: reportToHuman(repo, 'the dispatcher rolled back and holds the failed target'),
339
+ })
340
+ const degradation = status.forgeDegradation
341
+ if (
342
+ status.forgeRateLimit?.paused === true &&
343
+ degradation !== undefined &&
344
+ Date.parse(degradation.resetAt) > now.getTime()
345
+ )
346
+ items.push({
347
+ kind: 'forge-cooldown',
348
+ detail: `forge ${degradation.forge} paused until ${degradation.resetAt}: ${degradation.message}`,
349
+ source: {
350
+ forgeRateLimit: status.forgeRateLimit,
351
+ forgeDegradation: degradation,
352
+ },
353
+ resolve: [
354
+ {
355
+ tool: 'repository.forge_clear',
356
+ input: { repo, forge: degradation.forge },
357
+ by: 'operator',
358
+ note: FORGE_CLEAR_NOTE,
359
+ },
360
+ ],
361
+ })
362
+ return items
363
+ }
364
+
365
+ const bySlug = (a: { slug: string }, b: { slug: string }) => a.slug.localeCompare(b.slug)
366
+
367
+ /** Everything waiting on the operator for `repo`. An omitted cursor returns no
368
+ * events and a baseline cursor beside the current-state sections; an expired
369
+ * one fails with the `cursor-too-old` conflict `repository.events` raises. */
370
+ export async function getOperatorAttention(opts: {
371
+ store: BuildStore
372
+ repo: string
373
+ cursor?: number
374
+ now: Date
375
+ }): Promise<OperatorAttention> {
376
+ const { store, repo, now } = opts
377
+ // Never nest these: a view pass awaiting another pass on the same
378
+ // repository deadlocks behind itself.
379
+ const [status, builds] = await Promise.all([
380
+ getRepositoryStatus(store, repo, now),
381
+ withOperatorView(store, repo, 'builds', async (view) => {
382
+ const escalations: AttentionEscalationItem[] = []
383
+ const merges: AttentionMergeItem[] = []
384
+ const waiting: AttentionWaitingItem[] = []
385
+ for (const { record, digest } of await view.listOpenBuilds(repo)) {
386
+ if (record.repo !== repo || digest.terminal !== undefined) continue
387
+ const facts = await view.buildFacts(record.slug)
388
+ const state = facts.state
389
+ const summary = summarizeFrom(record, state, now)
390
+ const ticket = record.ticket
391
+ if (state.openEscalations.length > 0 && summary.waitOnly !== true)
392
+ escalations.push({
393
+ slug: record.slug,
394
+ ...(ticket !== undefined ? { ticket } : {}),
395
+ status: summary.status,
396
+ ...(summary.phase !== undefined ? { phase: summary.phase } : {}),
397
+ ...(summary.round !== undefined ? { round: summary.round } : {}),
398
+ escalations: state.openEscalations,
399
+ resolve: [
400
+ {
401
+ tool: 'builds.answer',
402
+ input: { repo, slug: record.slug },
403
+ by: 'operator',
404
+ },
405
+ ],
406
+ })
407
+ const entry = await consentEntryFromView(view, record, facts)
408
+ if (entry !== null)
409
+ merges.push({
410
+ slug: record.slug,
411
+ pr: summary.pr ? { number: summary.pr.number, url: summary.pr.url } : null,
412
+ entry,
413
+ resolve: [
414
+ {
415
+ tool: 'builds.control',
416
+ input: {
417
+ repo,
418
+ slug: record.slug,
419
+ action: 'merge',
420
+ head: entry.currentHead,
421
+ },
422
+ by: 'operator',
423
+ ...(entry.reason === 'held' ? { note: 'merging releases the hold' } : {}),
424
+ },
425
+ {
426
+ tool: 'builds.control',
427
+ input: { repo, slug: record.slug, action: 'hold' },
428
+ by: 'operator',
429
+ },
430
+ ],
431
+ })
432
+ waiting.push(
433
+ ...waitingReasons({
434
+ repo,
435
+ slug: record.slug,
436
+ ...(ticket !== undefined ? { ticket } : {}),
437
+ summary,
438
+ state,
439
+ now,
440
+ }),
441
+ )
442
+ }
443
+ return {
444
+ escalations: escalations.sort(bySlug),
445
+ merges: merges.sort(bySlug),
446
+ waiting: waiting.sort(bySlug),
447
+ }
448
+ }),
449
+ ])
450
+ const page = await readRepositoryAttentionPage(store, repo, {
451
+ ...(opts.cursor !== undefined ? { cursor: opts.cursor } : {}),
452
+ filter: 'attention',
453
+ })
454
+ return {
455
+ repo,
456
+ generatedAt: now.toISOString(),
457
+ escalations: builds.escalations,
458
+ merges: builds.merges,
459
+ events: {
460
+ items: page.events.map((event) => ({
461
+ event,
462
+ resolve: repositoryEventResolution(event, repo),
463
+ })),
464
+ cursor: page.cursor,
465
+ hasMore: page.hasMore,
466
+ },
467
+ waiting: builds.waiting,
468
+ dispatcher: dispatcherAttention(status, now),
469
+ }
470
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The canonical skills bundled with the serving Autobuild, in install form —
3
+ * what `ab init` would vendor. The context tools serve them when a
4
+ * repository has no captured agent context.
5
+ *
6
+ * `cli/init` is imported dynamically so the registry's static import graph
7
+ * never pulls its filesystem code into a bundle that does not call it. The
8
+ * result is memoized per process; a failure is not, so a later call retries.
9
+ */
10
+ import { AUTOBUILD_VERSION } from '../store/remote/version'
11
+ import type { CanonicalSkillBundle } from './agent-context-serve'
12
+
13
+ let bundle: Promise<CanonicalSkillBundle> | undefined
14
+
15
+ export function defaultCanonicalSkills(): Promise<CanonicalSkillBundle> {
16
+ if (bundle === undefined) {
17
+ const attempt = (async () => {
18
+ const { defaultDistRoot, readDistSkills } = await import('../cli/init')
19
+ const root = defaultDistRoot()
20
+ try {
21
+ return { version: AUTOBUILD_VERSION, skills: await readDistSkills(root) }
22
+ } catch (error) {
23
+ throw new Error(
24
+ `canonical skills unavailable at ${root}/skills: ${error instanceof Error ? error.message : String(error)}`,
25
+ { cause: error },
26
+ )
27
+ }
28
+ })()
29
+ bundle = attempt
30
+ void attempt.catch(() => {
31
+ if (bundle === attempt) bundle = undefined
32
+ })
33
+ }
34
+ return bundle
35
+ }