@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
@@ -14,13 +14,18 @@
14
14
  *
15
15
  * Cost (CLAUDE.md "Store read cost is a correctness property", applied to
16
16
  * GitHub budget): the source holds no BuildStore handle. Recurring reads
17
- * (the ready listing, candidates' blockers, reopen checks and parent issues,
18
- * dependency reads, `get`, the label registry, and `listTargeting`'s node,
19
- * sub-issue and child reads) are conditional through a durable validator
20
- * store, so an unchanged repository answers a tick with 304s. Counts are one
21
- * fresh, bounded GraphQL request per call and are never cached. Explicit
22
- * history reads (export snapshots and comment history), the keyed-create scan, the claim read and every
23
- * write store nothing.
17
+ * (the ready listing, each hydrated ticket's dependency list, reopen checks
18
+ * and parent issues, dependency reads, `get`, the label registry, and
19
+ * `listTargeting`'s node, sub-issue and child reads) are conditional through
20
+ * a durable validator store, so an unchanged repository answers a tick with
21
+ * 304s. Those reads never trust a zero dependency summary, which lags the
22
+ * edges by seconds; broad unremembered listings (`listAll`, non-ready
23
+ * `listReady`) and export do, so they can omit a blocker recorded seconds
24
+ * earlier, and never feed a claim. Counts are one fresh, bounded GraphQL
25
+ * request per call and are never cached. Explicit history reads (export
26
+ * snapshots and comment history), the keyed-create scan, the claim's issue
27
+ * and dependency reads (one each per claim attempt, plus a page per further
28
+ * 100 blockers) and every write store nothing.
24
29
  * A `readyAssignee` narrows the ready read itself
25
30
  * (its `assignee` query parameter); `"me"` costs one `GET /user` per
26
31
  * dispatcher start, sent by `prepareReadyAssignee` before the loop and never
@@ -34,6 +39,10 @@
34
39
  * `"me"` through the same memoized `GET /user`; a dispatcher prepared it at
35
40
  * startup, so a harvest proposal filed under `createAssignee = "me"` adds no
36
41
  * `GET /user` and an idle tick adds nothing.
42
+ * Each `search` page is one `GET /search/issues` on GitHub's separate search
43
+ * quota, sent fresh and storing nothing; hits come from that response alone.
44
+ * Confirmed primary search-quota exhaustion arms only a search cooldown;
45
+ * secondary or ambiguous rate limits arm the source cooldown like any request.
37
46
  */
38
47
  import { z } from 'zod'
39
48
  import {
@@ -51,13 +60,17 @@ import type {
51
60
  TicketCreateOptions,
52
61
  TicketCriteria,
53
62
  TicketDraft,
63
+ TicketClaimOptions,
54
64
  TicketListing,
65
+ TicketSearchHit,
66
+ TicketSearchPage,
67
+ TicketSearchQuery,
55
68
  TicketSource,
56
69
  TicketStateCount,
57
70
  TicketStateInfo,
58
71
  TicketUpdate,
59
72
  } from '../types'
60
- import { TicketSourceRateLimitError } from '../types'
73
+ import { TicketClaimBlockedError, TicketSourceRateLimitError } from '../types'
61
74
  import {
62
75
  type CreationIntent,
63
76
  effectiveLabels,
@@ -104,6 +117,7 @@ import { type GitHubValidatorStore, MemoryGitHubValidatorStore } from './github-
104
117
  import { normalizeIssueLinks } from './issue-links'
105
118
  import { holdsState, type TicketLifecycle } from './lifecycle'
106
119
  import { ticketRevision } from './revision'
120
+ import { searchTerms, TicketSearchCursorInvalid } from './search'
107
121
  import {
108
122
  matchStateNames,
109
123
  orderStates,
@@ -180,11 +194,16 @@ interface HydrateOptions {
180
194
  target?: string | null
181
195
  /** False for reads that never return a target (dependency states). */
182
196
  resolveTarget?: boolean
197
+ /** Trust a zero dependency summary instead of reading the list; only for
198
+ * broad listings that never feed a claim decision. */
199
+ trustEmptySummary?: boolean
183
200
  }
184
201
 
185
202
  interface Blockers {
186
203
  ids: string[]
187
204
  resolved: boolean
205
+ /** Ids that are foreign or not closed as completed. */
206
+ unresolved: string[]
188
207
  issues: GitHubIssue[]
189
208
  }
190
209
 
@@ -257,6 +276,166 @@ function assigneeLogins(issue: GitHubIssue): string[] {
257
276
  return (issue.assignees ?? []).map((assignee) => assignee.login)
258
277
  }
259
278
 
279
+ // ── Search ────────────────────────────────────────────────────────────────
280
+ //
281
+ // GitHub documentation this rests on:
282
+ // - https://docs.github.com/en/rest/search/search#search-issues-and-pull-requests
283
+ // (`q`, `sort`, `order`, `per_page`, `page`; at most 1,000 results per
284
+ // search; query text at most 256 characters, excluding qualifiers)
285
+ // - https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests
286
+ // (`repo:`, `is:issue`, `is:open`/`is:closed`, `reason:`, `label:`, `in:`)
287
+ // - https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax
288
+ // (case-insensitive; quoted terms are literal; `-` excludes)
289
+ // - https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api
290
+ // (the search quota is its own resource; secondary limits)
291
+
292
+ /** GitHub serves only the first 1,000 results of a search. */
293
+ export const SEARCH_RESULT_CAP = 1000
294
+ /** GitHub refuses query text longer than this, qualifiers excluded. */
295
+ export const SEARCH_TEXT_MAX = 256
296
+
297
+ /** The `q` of one GitHub issue search, and the fingerprint its cursors carry. */
298
+ export function githubSearchQuery(
299
+ repository: string,
300
+ lifecycle: TicketLifecycle,
301
+ query: Pick<TicketSearchQuery, 'text' | 'state' | 'labels'>,
302
+ ): { q: string; fingerprint: string } {
303
+ // Every term is quoted, so text that looks like search syntax (`repo:`,
304
+ // `OR`, a leading `-`) stays a literal word and never widens the scope.
305
+ const terms = searchTerms(query.text)
306
+ .map((term) => term.replaceAll('"', ''))
307
+ .filter((term) => term !== '')
308
+ if (terms.length === 0) throw new Error('github ticket search: the query has no searchable words')
309
+ const quoted = terms.map((term) => `"${term}"`).join(' ')
310
+ if (quoted.length > SEARCH_TEXT_MAX)
311
+ throw new Error(
312
+ `github ticket search: the query is ${quoted.length} characters once quoted; GitHub search allows at most ${SEARCH_TEXT_MAX}`,
313
+ )
314
+ const labels = query.labels ?? []
315
+ for (const label of labels) {
316
+ if (label.includes('"'))
317
+ throw new Error(`github ticket search: label "${label}" contains a double quote`)
318
+ // GitHub reads `label:"a,b"` as a OR b even when quoted, so a comma would
319
+ // widen the filter instead of naming one label.
320
+ if (label.includes(','))
321
+ throw new Error(`github ticket search: label "${label}" contains a comma`)
322
+ }
323
+ const state = searchStateQualifiers(lifecycle, query.state)
324
+ const q = [
325
+ `repo:${repository}`,
326
+ 'is:issue',
327
+ 'in:title,body',
328
+ ...state,
329
+ ...labels.map((label) => `label:"${label}"`),
330
+ quoted,
331
+ ].join(' ')
332
+ const key = JSON.stringify([terms, state, [...labels].map((l) => l.toLowerCase()).sort()])
333
+ return { q, fingerprint: fnv1a(key) }
334
+ }
335
+
336
+ /** Qualifiers that select a superset of the issues holding `state`, resolved
337
+ * as `listReady` resolves it; the caller filters hits to the exact state. */
338
+ function searchStateQualifiers(lifecycle: TicketLifecycle, state: string | undefined): string[] {
339
+ if (state === undefined) return []
340
+ if (state.includes('"'))
341
+ throw new Error(`github ticket search: state "${state}" contains a double quote`)
342
+ const rejected = rejectedStateOf(lifecycle)
343
+ // `is:closed` and not `reason:completed`: a legacy closure with no reason
344
+ // is done, and only the local filter can keep it.
345
+ if (holdsState(state, lifecycle.done)) return ['is:closed']
346
+ if (holdsState(state, rejected)) return ['is:closed', '-reason:completed']
347
+ if (holdsState(state, lifecycle.triage))
348
+ return [
349
+ 'is:open',
350
+ ...lifecycleNames(lifecycle)
351
+ .filter(
352
+ (name) =>
353
+ !holdsState(name, lifecycle.triage) &&
354
+ !holdsState(name, lifecycle.done) &&
355
+ !holdsState(name, rejected),
356
+ )
357
+ .map((name) => `-label:"${stateLabel(name)}"`),
358
+ ]
359
+ const name = lifecycleNames(lifecycle).find((known) => holdsState(known, state)) ?? state
360
+ return ['is:open', `label:"${stateLabel(name)}"`]
361
+ }
362
+
363
+ /** 32-bit FNV-1a as 8 hex digits. */
364
+ function fnv1a(text: string): string {
365
+ let hash = 0x811c9dc5
366
+ for (let i = 0; i < text.length; i++) {
367
+ hash ^= text.charCodeAt(i)
368
+ hash = Math.imul(hash, 0x01000193)
369
+ }
370
+ return (hash >>> 0).toString(16).padStart(8, '0')
371
+ }
372
+
373
+ export function encodeSearchCursor(offset: number, fingerprint: string): string {
374
+ return `${offset}.${fingerprint}`
375
+ }
376
+
377
+ /** The match offset a cursor names, or `TicketSearchCursorInvalid` for a
378
+ * cursor another search (or source) issued. */
379
+ export function decodeSearchCursor(cursor: string | undefined, fingerprint: string): number {
380
+ if (cursor === undefined) return 0
381
+ const match = /^(0|[1-9]\d*)\.([0-9a-f]{8})$/.exec(cursor)
382
+ const offset = match ? Number(match[1]) : NaN
383
+ if (!match || match[2] !== fingerprint || !(offset < SEARCH_RESULT_CAP))
384
+ throw new TicketSearchCursorInvalid('github', cursor)
385
+ return offset
386
+ }
387
+
388
+ /** One request's window starting exactly at `offset`: the largest page size
389
+ * up to `limit` that divides `offset` and stays within the first 1,000. */
390
+ export function searchWindow(offset: number, limit: number): { perPage: number; page: number } {
391
+ let perPage = Math.max(1, Math.min(limit, SEARCH_RESULT_CAP - offset))
392
+ while (offset % perPage !== 0) perPage--
393
+ return { perPage, page: offset / perPage + 1 }
394
+ }
395
+
396
+ /** GitHub's documented signs of a secondary rate limit. A secondary refusal
397
+ * can also carry `x-ratelimit-remaining: 0`, so this is checked first. */
398
+ function githubSecondaryLimitEvidence(error: GitHubApiError): boolean {
399
+ if (error.headers['retry-after'] !== undefined) return true
400
+ const body = (error.body ?? {}) as { message?: unknown; documentation_url?: unknown }
401
+ const secondary = /secondary rate limit|abuse detection/i
402
+ if (secondary.test(error.message)) return true
403
+ if (typeof body.message === 'string' && secondary.test(body.message)) return true
404
+ return (
405
+ typeof body.documentation_url === 'string' &&
406
+ body.documentation_url.includes('secondary-rate-limits')
407
+ )
408
+ }
409
+
410
+ /**
411
+ * Whether a refusal is confirmed exhaustion of GitHub's primary search quota
412
+ * (a resource separate from every other endpoint's), which may refuse only
413
+ * further searches. Secondary-limit evidence takes precedence over the
414
+ * exhaustion headers: GitHub documents that a secondary-limit response may
415
+ * also report `x-ratelimit-remaining: 0`
416
+ * (https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api#exceeding-the-rate-limit),
417
+ * and GitHub asks integrations to stop all requests on a secondary limit.
418
+ * Anything not confirmed here pauses the whole source.
419
+ */
420
+ export function githubSearchQuotaExhausted(error: unknown): boolean {
421
+ if (!(error instanceof GitHubApiError)) return false
422
+ if (error.status !== 403 && error.status !== 429) return false
423
+ if (githubSecondaryLimitEvidence(error)) return false
424
+ return (
425
+ error.headers['x-ratelimit-resource'] === 'search' &&
426
+ error.headers['x-ratelimit-remaining'] === '0' &&
427
+ error.headers['x-ratelimit-reset'] !== undefined
428
+ )
429
+ }
430
+
431
+ const githubSearchResponseSchema = z
432
+ .object({
433
+ total_count: z.number(),
434
+ incomplete_results: z.boolean().optional(),
435
+ items: z.array(z.unknown()),
436
+ })
437
+ .passthrough()
438
+
260
439
  export class GitHubTicketSource implements TicketSource {
261
440
  readonly name = 'github'
262
441
  readonly issueLinks = true
@@ -277,6 +456,9 @@ export class GitHubTicketSource implements TicketSource {
277
456
  /** A rate limit hit by the unassigned-ready report, kept apart from
278
457
  * `cooldown` so it never refuses the listing or claim reads. */
279
458
  private unassignedCooldownUntil?: number
459
+ /** Primary search-quota exhaustion, kept apart from `cooldown` so it
460
+ * refuses only searches. */
461
+ private searchCooldownUntil?: number
280
462
  /** Exact label name (lowercased) → the one registry write in progress. */
281
463
  private readonly pendingLabels = new Map<string, Promise<void>>()
282
464
  /** Labels this instance created or saw created, lowercased. */
@@ -333,6 +515,9 @@ export class GitHubTicketSource implements TicketSource {
333
515
  body?: unknown
334
516
  remember?: boolean
335
517
  missing?: boolean
518
+ /** A rate limit this predicate accepts is thrown without arming the
519
+ * source cooldown; the caller keeps its own (search's quota). */
520
+ localRateLimit?: (error: unknown) => boolean
336
521
  } = {},
337
522
  ): Promise<Response | null> {
338
523
  if (this.cooldown !== undefined) {
@@ -355,6 +540,11 @@ export class GitHubTicketSource implements TicketSource {
355
540
  try {
356
541
  response = await this.transport(method, path, request)
357
542
  } catch (error) {
543
+ if (opts.localRateLimit?.(error) === true) {
544
+ const resetAt = githubRateLimitUntil(error, this.now())
545
+ if (resetAt !== undefined)
546
+ throw new TicketSourceRateLimitError('github', Date.parse(resetAt))
547
+ }
358
548
  this.rateLimited(error)
359
549
  const status = statusOf(error)
360
550
  if (opts.missing && (status === 404 || status === 410)) return null
@@ -387,7 +577,12 @@ export class GitHubTicketSource implements TicketSource {
387
577
  operation: string,
388
578
  method: string,
389
579
  path: string,
390
- opts: { query?: Record<string, string>; body?: unknown; remember?: boolean } = {},
580
+ opts: {
581
+ query?: Record<string, string>
582
+ body?: unknown
583
+ remember?: boolean
584
+ localRateLimit?: (error: unknown) => boolean
585
+ } = {},
391
586
  ): Promise<Response> {
392
587
  return (await this.request(operation, method, path, opts)) as Response
393
588
  }
@@ -706,10 +901,21 @@ export class GitHubTicketSource implements TicketSource {
706
901
  }
707
902
  }
708
903
 
709
- private async blockers(issue: GitHubIssue, remember: boolean): Promise<Blockers> {
904
+ /**
905
+ * The issue's blockers from its dependency list. GitHub's dependency
906
+ * summary lags the edges by seconds, so a zero summary is trusted only
907
+ * when `trustEmptySummary` says the caller is a broad listing that never
908
+ * feeds a claim decision.
909
+ */
910
+ private async blockers(
911
+ issue: GitHubIssue,
912
+ remember: boolean,
913
+ trustEmptySummary = false,
914
+ ): Promise<Blockers> {
710
915
  const summary = issue.issue_dependencies_summary
711
916
  const total = summary?.total_blocked_by ?? summary?.blocked_by
712
- if (total === 0) return { ids: [], resolved: true, issues: [] }
917
+ if (total === 0 && trustEmptySummary)
918
+ return { ids: [], resolved: true, unresolved: [], issues: [] }
713
919
  const issues: GitHubIssue[] = []
714
920
  let page: string | undefined = '1'
715
921
  while (page !== undefined) {
@@ -724,14 +930,20 @@ export class GitHubTicketSource implements TicketSource {
724
930
  page = nextPage(response.link)
725
931
  }
726
932
  const ids: string[] = []
727
- let resolved = true
933
+ const unresolved: string[] = []
728
934
  for (const blocker of issues) {
729
935
  const repo = this.repositoryOf(blocker)
730
936
  const local = repo === undefined || repo.toLowerCase() === this.fullName.toLowerCase()
731
- ids.push(local ? String(blocker.number) : `${repo}#${blocker.number}`)
732
- if (!local || !isClosedCompleted(blocker)) resolved = false
937
+ const id = local ? String(blocker.number) : `${repo}#${blocker.number}`
938
+ ids.push(id)
939
+ if (!local || !isClosedCompleted(blocker)) unresolved.push(id)
940
+ }
941
+ return {
942
+ ids: [...new Set(ids)],
943
+ resolved: unresolved.length === 0,
944
+ unresolved: [...new Set(unresolved)],
945
+ issues,
733
946
  }
734
- return { ids: [...new Set(ids)], resolved, issues }
735
947
  }
736
948
 
737
949
  /** Whether `issue` is issue `number` of the configured repository. */
@@ -821,7 +1033,7 @@ export class GitHubTicketSource implements TicketSource {
821
1033
  }
822
1034
  }
823
1035
  }
824
- const blockers = await this.blockers(issue, opts.remember)
1036
+ const blockers = await this.blockers(issue, opts.remember, opts.trustEmptySummary)
825
1037
  const target = await this.targetOf(issue, opts)
826
1038
  return {
827
1039
  ticket: this.toTicket(current, state, blockers.ids, links.links, target),
@@ -869,6 +1081,84 @@ export class GitHubTicketSource implements TicketSource {
869
1081
  return (await this.hydrate(read.issue, { remember: true, ...etagOf(read) })).ticket
870
1082
  }
871
1083
 
1084
+ /**
1085
+ * One page of GitHub issue search: exactly one `GET /search/issues`, sent
1086
+ * fresh on GitHub's separate search quota, with every hit built from its
1087
+ * items (no read per hit, so hits carry no target, and a reopened issue's
1088
+ * stale label reports its label's state until a listing heals it). A state
1089
+ * filter queries a superset and keeps hits holding exactly that state, so a
1090
+ * page can be shorter than `limit` and still carry a cursor. Only the first
1091
+ * 1,000 matches are reachable. See the doc links above `SEARCH_RESULT_CAP`.
1092
+ */
1093
+ async search(query: TicketSearchQuery): Promise<TicketSearchPage> {
1094
+ const { q, fingerprint } = githubSearchQuery(this.fullName, this.lifecycle, query)
1095
+ const offset = decodeSearchCursor(query.cursor, fingerprint)
1096
+ if (this.searchCooldownUntil !== undefined) {
1097
+ if (this.now() < this.searchCooldownUntil)
1098
+ throw new TicketSourceRateLimitError('github', this.searchCooldownUntil)
1099
+ this.searchCooldownUntil = undefined
1100
+ }
1101
+ const { perPage, page } = searchWindow(offset, query.limit)
1102
+ let response: Response
1103
+ try {
1104
+ response = await this.must('search', 'GET', 'search/issues', {
1105
+ query: {
1106
+ q,
1107
+ sort: 'created',
1108
+ order: 'desc',
1109
+ per_page: String(perPage),
1110
+ page: String(page),
1111
+ },
1112
+ localRateLimit: githubSearchQuotaExhausted,
1113
+ })
1114
+ } catch (error) {
1115
+ // Not the source cooldown: confirmed search-quota exhaustion.
1116
+ if (error instanceof TicketSourceRateLimitError && error !== this.cooldown)
1117
+ this.searchCooldownUntil = error.resetAt
1118
+ throw error
1119
+ }
1120
+ const parsed = githubSearchResponseSchema.safeParse(response.json)
1121
+ if (!parsed.success)
1122
+ throw new Error(`github search: unexpected response shape — ${parsed.error.message}`)
1123
+ const { total_count: total, incomplete_results: incomplete, items } = parsed.data
1124
+ const tickets: TicketSearchHit[] = []
1125
+ const diagnostics: string[] = []
1126
+ for (const json of items) {
1127
+ const issue = this.parseIssue('search', json)
1128
+ if (!this.isLocalChild(issue)) continue
1129
+ const read = issueState(issue, this.lifecycle)
1130
+ if ('malformed' in read) {
1131
+ diagnostics.push(
1132
+ `github #${issue.number}: has ${read.malformed.length} state labels (${read.malformed.join(', ')}); a ticket holds one state — remove all but one`,
1133
+ )
1134
+ continue
1135
+ }
1136
+ if (query.state !== undefined && !holdsState(read.state, query.state)) continue
1137
+ tickets.push({
1138
+ id: String(issue.number),
1139
+ title: issue.title,
1140
+ state: read.state,
1141
+ labels: ticketLabelsOf(issue),
1142
+ kind: isNode(issue) ? 'node' : 'work',
1143
+ })
1144
+ }
1145
+ const next = offset + perPage
1146
+ const full = items.length === perPage
1147
+ if (full && next >= SEARCH_RESULT_CAP && total > SEARCH_RESULT_CAP)
1148
+ diagnostics.push(
1149
+ `GitHub search returns only the first ${SEARCH_RESULT_CAP} of ${total} matches; narrow the query`,
1150
+ )
1151
+ if (incomplete === true)
1152
+ diagnostics.push('GitHub search timed out and returned partial results for this page')
1153
+ return {
1154
+ tickets,
1155
+ ...(full && next < Math.min(total, SEARCH_RESULT_CAP)
1156
+ ? { cursor: encodeSearchCursor(next, fingerprint) }
1157
+ : {}),
1158
+ diagnostics,
1159
+ }
1160
+ }
1161
+
872
1162
  // ── Export and import ─────────────────────────────────────────────────────
873
1163
 
874
1164
  /** Comment history, oldest first, through GitHub's "List issue comments"
@@ -916,7 +1206,7 @@ export class GitHubTicketSource implements TicketSource {
916
1206
  const diagnostics: string[] = []
917
1207
  for (const issue of issues) {
918
1208
  opts.signal?.throwIfAborted()
919
- const hydrated = await this.hydrate(issue, { remember: false })
1209
+ const hydrated = await this.hydrate(issue, { remember: false, trustEmptySummary: true })
920
1210
  diagnostics.push(...hydrated.diagnostics)
921
1211
  if (!hydrated.listed && hydrated.diagnostics.length === 0)
922
1212
  diagnostics.push(`github #${issue.number}: has no readable state`)
@@ -974,6 +1264,7 @@ export class GitHubTicketSource implements TicketSource {
974
1264
  await this.listIssues('listAll', { state: 'all' }, false),
975
1265
  () => true,
976
1266
  false,
1267
+ true,
977
1268
  )
978
1269
  }
979
1270
 
@@ -1010,6 +1301,7 @@ export class GitHubTicketSource implements TicketSource {
1010
1301
  await listIssues('list', { state: 'all', ...labelQuery() }, false),
1011
1302
  () => true,
1012
1303
  false,
1304
+ true,
1013
1305
  )
1014
1306
  const wanted = criteria.state
1015
1307
  const holds = (ticket: Ticket) => holdsState(ticket.state, wanted)
@@ -1021,15 +1313,18 @@ export class GitHubTicketSource implements TicketSource {
1021
1313
  await listIssues('list', { state: 'closed', ...labelQuery() }, false),
1022
1314
  holds,
1023
1315
  false,
1316
+ true,
1024
1317
  )
1025
1318
  if (holdsState(wanted, this.lifecycle.triage))
1026
1319
  return this.listing(
1027
1320
  await listIssues('list', { state: 'open', ...labelQuery() }, false),
1028
1321
  holds,
1029
1322
  false,
1323
+ true,
1030
1324
  )
1031
1325
  // A label state: the ready listing is the recurring dispatcher read, so
1032
- // it alone is remembered, oldest first for a stable order.
1326
+ // it alone is remembered, oldest first for a stable order. It alone also
1327
+ // confirms a zero dependency summary, since it feeds claim decisions.
1033
1328
  const recurring = holdsState(wanted, this.lifecycle.ready)
1034
1329
  const listing = await this.listing(
1035
1330
  await listIssues(
@@ -1044,6 +1339,7 @@ export class GitHubTicketSource implements TicketSource {
1044
1339
  ),
1045
1340
  holds,
1046
1341
  recurring,
1342
+ !recurring,
1047
1343
  )
1048
1344
  if (!recurring || login === undefined) return listing
1049
1345
  return {
@@ -1120,10 +1416,11 @@ export class GitHubTicketSource implements TicketSource {
1120
1416
  issues: GitHubIssue[],
1121
1417
  keep: (ticket: Ticket) => boolean,
1122
1418
  remember: boolean,
1419
+ trustEmptySummary: boolean,
1123
1420
  ): Promise<TicketListing> {
1124
1421
  const parents = new Map(issues.map((issue) => [issue.number, issue]))
1125
1422
  const parentReads = new Map<number, Promise<GitHubIssue | null>>()
1126
- return this.collect(issues, keep, { remember, parents, parentReads })
1423
+ return this.collect(issues, keep, { remember, parents, parentReads, trustEmptySummary })
1127
1424
  }
1128
1425
 
1129
1426
  private async collect(
@@ -1222,11 +1519,14 @@ export class GitHubTicketSource implements TicketSource {
1222
1519
 
1223
1520
  /**
1224
1521
  * Claim-before-launch (SPEC §12): a fresh, unconditional read re-checks the
1225
- * issue is open, in the ready state and carries every ready label; then the
1226
- * ready label becomes the claimed one. The pair is not transactional, which
1227
- * the single-writer dispatcher (§12) makes acceptable.
1522
+ * issue is open, in the ready state and carries every ready label; then a
1523
+ * fresh, unconditional read of the dependency list refuses an unresolved
1524
+ * blocker the caller's dependency check did not evaluate, because GitHub's
1525
+ * dependency summary lags its edges. Only then does the ready label become
1526
+ * the claimed one. The pair is not transactional, which the single-writer
1527
+ * dispatcher (§12) makes acceptable.
1228
1528
  */
1229
- async claim(id: string): Promise<boolean> {
1529
+ async claim(id: string, opts: TicketClaimOptions = {}): Promise<boolean> {
1230
1530
  const number = parseIssueId(id)
1231
1531
  if (number === null) return false
1232
1532
  const read = await this.readIssue('claim', number, false)
@@ -1242,6 +1542,10 @@ export class GitHubTicketSource implements TicketSource {
1242
1542
  if (verdict === 'stale') await this.heal(issue)
1243
1543
  if (verdict !== 'fresh') return false
1244
1544
  }
1545
+ const blockers = await this.blockers(issue, false)
1546
+ const evaluated = new Set(opts.blockedBy ?? [])
1547
+ const added = blockers.unresolved.filter((blocker) => !evaluated.has(blocker))
1548
+ if (added.length > 0) throw new TicketClaimBlockedError(this.name, String(number), added)
1245
1549
  await this.ensureLabels('claim', [stateLabel(this.lifecycle.doing)])
1246
1550
  await this.patchIssue('claim', number, {
1247
1551
  labels: [
@@ -1373,8 +1677,12 @@ export class GitHubTicketSource implements TicketSource {
1373
1677
  if (adopted !== undefined) return this.adopt(adopted, blockedBy, assignees, labels)
1374
1678
  }
1375
1679
  // A closing create state opens the issue without a state label and
1376
- // closes it as a follow-up.
1377
- const initial = write.labels
1680
+ // closes it as a follow-up. A ready-bound create with blockers opens
1681
+ // staged in triage and moves to ready only after every blocker is
1682
+ // recorded, so no dispatcher can claim it unblocked.
1683
+ const initial = this.stagesCreate(state, blockedBy)
1684
+ ? write.labels.filter((name) => !isStateLabel(name))
1685
+ : write.labels
1378
1686
  await this.ensureLabels('create', initial)
1379
1687
  const intent: CreationIntent = {
1380
1688
  state,
@@ -1497,10 +1805,17 @@ export class GitHubTicketSource implements TicketSource {
1497
1805
  return this.fresh('create', issue.number)
1498
1806
  }
1499
1807
 
1808
+ /** Whether a create into `state` with `blockedBy` opens staged in triage:
1809
+ * the ready state is the one a dispatcher claims from. */
1810
+ private stagesCreate(state: string, blockedBy: readonly string[]): boolean {
1811
+ return blockedBy.length > 0 && holdsState(state, this.lifecycle.ready)
1812
+ }
1813
+
1500
1814
  /**
1501
1815
  * The create's follow-ups, shared by a first attempt and a recovery so both
1502
1816
  * run the same idempotent steps: the closure, any missing link labels, the
1503
- * blockers, then the marker rewritten to its plain (complete) form.
1817
+ * target, the blockers, a staged create's deferred ready state, then the
1818
+ * marker rewritten to its plain (complete) form.
1504
1819
  */
1505
1820
  private async finishCreate(
1506
1821
  issue: GitHubIssue,
@@ -1534,8 +1849,13 @@ export class GitHubTicketSource implements TicketSource {
1534
1849
  }
1535
1850
  if (intent.target !== undefined)
1536
1851
  await this.recordTarget(current, intent.target, adopting, key !== undefined)
1852
+ const staged = this.stagesCreate(intent.state, intent.blockedBy)
1537
1853
  if (intent.blockedBy.length > 0)
1538
- await this.recordBlockers(current, intent.blockedBy, adopting, key !== undefined)
1854
+ await this.recordBlockers(current, intent.blockedBy, adopting, key !== undefined, staged)
1855
+ // A recovery publishes only an issue still staged (open, no state label);
1856
+ // one a person has moved since is left alone.
1857
+ if (staged && current.state === 'open' && stateLabelsOf(current).length === 0)
1858
+ await this.publishStaged(current, intent.state, key !== undefined)
1539
1859
  if (key !== undefined) {
1540
1860
  const { body } = splitCreationMarker(current.body)
1541
1861
  await this.patchIssue('create', current.number, { body: encodeCreationMarker(body, key) })
@@ -1554,14 +1874,38 @@ export class GitHubTicketSource implements TicketSource {
1554
1874
  return data.repository?.issue?.timelineItems.totalCount ?? 0
1555
1875
  }
1556
1876
 
1877
+ /** Move a staged create into its intended ready state once every blocker
1878
+ * is recorded. A failure says the issue exists, with its blockers, and was
1879
+ * left in triage. */
1880
+ private async publishStaged(
1881
+ issue: GitHubIssue,
1882
+ state: string,
1883
+ retryableByKey: boolean,
1884
+ ): Promise<void> {
1885
+ try {
1886
+ await this.applyState('create', issue, state)
1887
+ } catch (error) {
1888
+ throw new Error(
1889
+ `github create: ticket "${issue.number}" ${retryableByKey ? 'already exists' : 'was created'} at ${issue.html_url} ` +
1890
+ `and every blocker was recorded, but it was left in ${this.lifecycle.triage} instead of ${state}. ` +
1891
+ (retryableByKey
1892
+ ? 'Retry with the same creation key; GitHub will adopt this ticket and finish only what is missing. '
1893
+ : `Do not rerun ticket creation; move it with \`ab ticket move ${issue.number} ${state}\`. `) +
1894
+ `Underlying failure: ${message(error)}`,
1895
+ { cause: error },
1896
+ )
1897
+ }
1898
+ }
1899
+
1557
1900
  /** Record blockers on a created issue. Every failure says the issue exists,
1558
1901
  * and which blockers were and were not recorded, so a retry adopts it
1559
- * rather than duplicating it. */
1902
+ * rather than duplicating it. A staged create says it was left in triage. */
1560
1903
  private async recordBlockers(
1561
1904
  issue: GitHubIssue,
1562
1905
  requested: string[],
1563
1906
  readExisting: boolean,
1564
1907
  retryableByKey: boolean,
1908
+ staged = false,
1565
1909
  ): Promise<void> {
1566
1910
  const recorded: string[] = []
1567
1911
  try {
@@ -1572,17 +1916,30 @@ export class GitHubTicketSource implements TicketSource {
1572
1916
  recorded.push(blocker)
1573
1917
  }
1574
1918
  } catch (error) {
1575
- if (error instanceof TicketSourceRateLimitError && recorded.length === 0 && !retryableByKey)
1919
+ // A staged create always says the issue exists: it is not where the
1920
+ // caller asked for it.
1921
+ if (
1922
+ error instanceof TicketSourceRateLimitError &&
1923
+ recorded.length === 0 &&
1924
+ !retryableByKey &&
1925
+ staged === false
1926
+ )
1576
1927
  throw error
1577
1928
  const unrecorded = requested.filter((id) => !recorded.includes(id))
1929
+ const ready = staged ? this.lifecycle.ready : undefined
1578
1930
  throw new Error(
1579
1931
  `github create: ticket "${issue.number}" ${retryableByKey ? 'already exists' : 'was created'} at ${issue.html_url}, ` +
1580
1932
  'but its blockers were not all recorded. ' +
1581
1933
  `Blockers recorded: ${blockerList(requested.filter((id) => recorded.includes(id)))}. ` +
1582
1934
  `Blockers not recorded: ${blockerList(unrecorded)}. ` +
1935
+ (ready !== undefined
1936
+ ? `It was left in ${this.lifecycle.triage} instead of ${ready} so no dispatcher claims it. `
1937
+ : '') +
1583
1938
  (retryableByKey
1584
1939
  ? 'Retry with the same creation key; GitHub will adopt this ticket and finish only what is missing. '
1585
- : 'Do not rerun ticket creation; repair the blockers on the existing ticket. ') +
1940
+ : ready !== undefined
1941
+ ? `Do not rerun ticket creation; repair the blockers on the existing ticket, then move it with \`ab ticket move ${issue.number} ${ready}\`. `
1942
+ : 'Do not rerun ticket creation; repair the blockers on the existing ticket. ') +
1586
1943
  `Underlying failure: ${message(error)}`,
1587
1944
  { cause: error },
1588
1945
  )
@@ -25,6 +25,9 @@ export {
25
25
  TICKET_PAGING_HEADER,
26
26
  TICKET_PAGING_CAPABILITY,
27
27
  ticketPageWireSchema,
28
+ TICKET_SEARCH_HEADER,
29
+ TICKET_SEARCH_CAPABILITY,
30
+ ticketSearchPageWireSchema,
28
31
  hostedTicketContextSchema,
29
32
  hostedTicketRequestSchemas,
30
33
  TICKET_REVISIONS_HEADER,
@@ -32,6 +35,13 @@ export {
32
35
  } from './remote-protocol'
33
36
  export type { HostedTicketContext, HostedTicketOperation } from './remote-protocol'
34
37
 
38
+ export {
39
+ searchTerms,
40
+ searchTickets,
41
+ TicketSearchCursorInvalid,
42
+ TicketSearchUnsupported,
43
+ } from './search'
44
+
35
45
  export {
36
46
  TicketRevisionConflict,
37
47
  TicketRevisionUnsupported,