@defrex/autobuild 1.16.0 → 1.18.0

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 (97) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +132 -9
  3. package/docs/answering-blocked-builds.md +34 -1
  4. package/docs/architecture.md +42 -3
  5. package/docs/configuration.md +44 -7
  6. package/docs/dispatcher-hosting.md +5 -3
  7. package/docs/operator-api.md +29 -6
  8. package/docs/plugin-authoring.md +30 -1
  9. package/docs/remote-store-protocol.md +13 -3
  10. package/docs/remote-ticket-protocol.md +37 -2
  11. package/docs/restacking.md +46 -1
  12. package/docs/setup.md +24 -9
  13. package/docs/ticket-sources.md +28 -1
  14. package/docs/troubleshooting.md +54 -2
  15. package/docs/workspaces.md +3 -1
  16. package/package.json +4 -4
  17. package/packages/core/src/cli/accounts.ts +3 -0
  18. package/packages/core/src/cli/binary-direct.ts +14 -1
  19. package/packages/core/src/cli/binary.ts +10 -7
  20. package/packages/core/src/cli/dashboard/refresh.ts +8 -0
  21. package/packages/core/src/cli/dispatch.ts +503 -334
  22. package/packages/core/src/cli/secrets.ts +2 -0
  23. package/packages/core/src/config/schema.ts +17 -3
  24. package/packages/core/src/events/payloads.ts +8 -5
  25. package/packages/core/src/events/repository.ts +37 -1
  26. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/d41044cb2e54809c.json +194 -0
  27. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/e0f89f52e48cbf62.json +197 -0
  28. package/packages/core/src/kernel/engine.ts +118 -0
  29. package/packages/core/src/kernel/reconcile-restack.ts +72 -9
  30. package/packages/core/src/kernel/reducer-revisions.ts +5 -0
  31. package/packages/core/src/kernel/repository-read-facts.ts +9 -2
  32. package/packages/core/src/kernel/ticket-preparation.ts +10 -0
  33. package/packages/core/src/kernel/tracked-dirt.ts +173 -0
  34. package/packages/core/src/ontology.ts +1 -0
  35. package/packages/core/src/operator/index.ts +10 -0
  36. package/packages/core/src/operator/merged-builds.ts +51 -0
  37. package/packages/core/src/operator/registry.ts +254 -110
  38. package/packages/core/src/operator/repo-argument.ts +43 -0
  39. package/packages/core/src/operator/tickets.ts +139 -25
  40. package/packages/core/src/plugin-sdk/index.ts +4 -0
  41. package/packages/core/src/plugins/manifest.ts +1 -1
  42. package/packages/core/src/ports/tickets/completion.ts +71 -0
  43. package/packages/core/src/ports/tickets/contract.ts +73 -0
  44. package/packages/core/src/ports/tickets/github-fake.ts +8 -0
  45. package/packages/core/src/ports/tickets/github-issues.ts +1 -0
  46. package/packages/core/src/ports/tickets/github.ts +18 -6
  47. package/packages/core/src/ports/tickets/grants.ts +2 -0
  48. package/packages/core/src/ports/tickets/hosted-index.ts +8 -0
  49. package/packages/core/src/ports/tickets/linear.ts +18 -2
  50. package/packages/core/src/ports/tickets/remote-protocol.ts +37 -8
  51. package/packages/core/src/ports/tickets/remote.ts +43 -3
  52. package/packages/core/src/ports/tickets/tree.ts +11 -1
  53. package/packages/core/src/ports/types.ts +47 -4
  54. package/packages/core/src/ports/workspace/vercel-command-diagnostics.ts +144 -0
  55. package/packages/core/src/ports/workspace/vercel-sandbox.ts +649 -160
  56. package/packages/core/src/processes/build-child.ts +15 -1
  57. package/packages/core/src/processes/build-runner.ts +349 -20
  58. package/packages/core/src/processes/dispatcher.ts +880 -283
  59. package/packages/core/src/processes/harvest-child.ts +21 -1
  60. package/packages/core/src/processes/harvest-runner.ts +82 -35
  61. package/packages/core/src/processes/pass-stages.ts +32 -6
  62. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  63. package/packages/core/src/processes/provisioning-progress.ts +23 -0
  64. package/packages/core/src/processes/repo-view.ts +25 -4
  65. package/packages/core/src/processes/workspace-preparation.ts +1 -0
  66. package/packages/core/src/store/adapter.ts +34 -5
  67. package/packages/core/src/store/build-feed.ts +148 -22
  68. package/packages/core/src/store/build-scope.ts +12 -3
  69. package/packages/core/src/store/caller-attribution.ts +170 -0
  70. package/packages/core/src/store/contract.ts +1038 -165
  71. package/packages/core/src/store/local/schema.ts +12 -1
  72. package/packages/core/src/store/local/store.ts +260 -25
  73. package/packages/core/src/store/memory.ts +156 -9
  74. package/packages/core/src/store/phase-session.ts +23 -3
  75. package/packages/core/src/store/reducer-value-shapes.json +8196 -8118
  76. package/packages/core/src/store/remote/client.ts +90 -11
  77. package/packages/core/src/store/remote/credentials.ts +2 -0
  78. package/packages/core/src/store/remote/index.ts +31 -5
  79. package/packages/core/src/store/remote/protocol.ts +45 -8
  80. package/packages/core/src/store/remote/released-clients.json +22 -0
  81. package/packages/core/src/store/remote/released-reducer-values/1.17.0.json +36367 -0
  82. package/packages/core/src/store/remote/released-reducer-values/1.18.0.json +36436 -0
  83. package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
  84. package/packages/core/src/store/session-handle.ts +12 -3
  85. package/packages/core/src/store/types.ts +48 -3
  86. package/packages/core/src/testing/dispatch-read-budget.ts +143 -16
  87. package/packages/core/src/testing/index.ts +2 -0
  88. package/packages/core/src/testing/reduced-read-budget.ts +420 -6
  89. package/skills/guide/SKILL.md +67 -13
  90. package/skills/guide/references/operator-api.md +29 -6
  91. package/skills/guide/references/plugin-authoring.md +30 -1
  92. package/skills/guide/references/remote-store-protocol.md +13 -3
  93. package/skills/guide/references/remote-ticket-protocol.md +37 -2
  94. package/skills/guide/references/restacking.md +46 -1
  95. package/skills/guide/references/setup.md +24 -9
  96. package/skills/operate/SKILL.md +42 -4
  97. package/templates/hosted-service/package.json +2 -2
@@ -42,6 +42,13 @@ import { TicketAssigneesUnsupported } from '../ports/tickets/assignees'
42
42
  * every mutator, and — for constrained bindings — repository targeting.
43
43
  */
44
44
  import { z } from 'zod'
45
+ import { listOperatorMergedBuilds } from './merged-builds'
46
+ import {
47
+ hasRepositoryArgument,
48
+ missingRepoIssue,
49
+ REPOSITORY_ARGUMENT_MESSAGE,
50
+ repoArgumentIssue,
51
+ } from './repo-argument'
45
52
  import {
46
53
  controlBuild,
47
54
  BuildControlError,
@@ -51,8 +58,13 @@ import {
51
58
  import type { Via } from '../events/envelope'
52
59
  import { bulkControlRepository, BulkWalkError } from '../cli/bulk-control'
53
60
  import { systemClock, type BuildStore, type Clock } from '../store/types'
61
+ import { BuildFeedUnsupportedError, BuildFeedValidationError } from '../store/build-feed'
54
62
  import { TicketOperationError } from '../ports/tickets/operations'
55
63
  import { TicketSearchCursorInvalid, TicketSearchUnsupported } from '../ports/tickets/search'
64
+ import {
65
+ TICKET_COMPLETION_SCAN_LIMIT,
66
+ TicketCompletionRangeTooBroad,
67
+ } from '../ports/tickets/completion'
56
68
  import { controlTicketStart } from './ticket-start'
57
69
  import {
58
70
  attachOperatorTicketAsset,
@@ -256,16 +268,25 @@ function extendUnion(schema: z.ZodType, extra: z.ZodRawShape): z.ZodType {
256
268
  if (!Array.isArray(options) || options.length === 0) {
257
269
  throw new Error('extendUnion requires a union schema with options')
258
270
  }
259
- return z.union(options.map((option) => option.extend(extra)))
271
+ return z.union(
272
+ options.map((option) => option.extend(extra)),
273
+ { error: repoArgumentIssue },
274
+ )
275
+ }
276
+
277
+ /** A tool's top-level input: a strict object whose issues for an input
278
+ * carrying `repository` state the `repo` contract. */
279
+ function toolInput<Shape extends z.ZodRawShape>(shape: Shape) {
280
+ return z.strictObject(shape, { error: repoArgumentIssue })
260
281
  }
261
282
 
262
283
  // ── Shared input fields ──────────────────────────────────────────────────────
263
284
 
264
285
  const repoField = z
265
- .string()
286
+ .string({ error: missingRepoIssue })
266
287
  .min(1)
267
288
  .describe(
268
- 'Repository identity as the store keys it: the checkout’s normalized origin URL (e.g. "https://github.com/acme/widgets").',
289
+ 'Repository identity as the store keys it: the checkout’s normalized origin URL (e.g. "https://github.com/acme/widgets"). The argument is `repo`, never `repository`; a repository-scoped MCP endpoint binds the repository from its URL and takes no `repo`.',
269
290
  )
270
291
  const slugField = z.string().min(1).describe('Build slug identifying one build in the store.')
271
292
  const ticketIdField = z
@@ -273,22 +294,59 @@ const ticketIdField = z
273
294
  .min(1)
274
295
  .describe('Ticket id in the configured ticket source (e.g. "AUT-8").')
275
296
 
276
- const buildListInput = z.strictObject({
297
+ const MERGED_ONLY_FIELDS = ['since', 'until', 'limit', 'cursor'] as const
298
+
299
+ const buildListInput = toolInput({
277
300
  repo: repoField,
278
301
  scope: z
279
- .enum(['active', 'queued', 'all'])
302
+ .enum(['active', 'queued', 'all', 'merged'])
280
303
  .default('active')
281
304
  .describe(
282
- 'Which builds to include: "active" (running, paused, or blocked — the default), "queued", or "all".',
305
+ 'Which builds to include: "active" (running, paused, or blocked — the default), "queued", "all", or "merged" (most recently merged first, paged; the call for a "what shipped since T" digest — use "active" and "queued" for what lands next).',
306
+ ),
307
+ since: z
308
+ .string()
309
+ .optional()
310
+ .describe(
311
+ 'Scope "merged" only: an ISO-8601 instant with a zone; include builds merged at or after it.',
283
312
  ),
313
+ until: z
314
+ .string()
315
+ .optional()
316
+ .describe(
317
+ 'Scope "merged" only: an ISO-8601 instant with a zone; include builds merged before it (exclusive).',
318
+ ),
319
+ limit: z
320
+ .number()
321
+ .int()
322
+ .min(1)
323
+ .max(100)
324
+ .optional()
325
+ .describe('Scope "merged" only: page size, 1 to 100; default 25.'),
326
+ cursor: z
327
+ .string()
328
+ .min(1)
329
+ .optional()
330
+ .describe(
331
+ 'Scope "merged" only: the `next` value from the previous page, requested with the same since and until.',
332
+ ),
333
+ }).superRefine((value, ctx) => {
334
+ if (value.scope === 'merged') return
335
+ for (const field of MERGED_ONLY_FIELDS)
336
+ if (value[field] !== undefined)
337
+ ctx.addIssue({
338
+ code: 'custom',
339
+ path: [field],
340
+ message: 'since, until, limit and cursor apply only to scope "merged"',
341
+ })
284
342
  })
285
343
 
286
- const buildDetailInput = z.strictObject({ repo: repoField, slug: slugField })
344
+ const buildDetailInput = toolInput({ repo: repoField, slug: slugField })
287
345
 
288
- const ticketDetailInput = z.strictObject({ repo: repoField, id: ticketIdField })
346
+ const ticketDetailInput = toolInput({ repo: repoField, id: ticketIdField })
289
347
 
290
- const contextListInput = z.strictObject({ repo: repoField })
291
- const contextReadInput = z.strictObject({
348
+ const contextListInput = toolInput({ repo: repoField })
349
+ const contextReadInput = toolInput({
292
350
  repo: repoField,
293
351
  path: z
294
352
  .string()
@@ -347,7 +405,7 @@ const assetNameField = z
347
405
  .string()
348
406
  .min(1)
349
407
  .describe('Asset name, unique per kind on the ticket (e.g. "checkout-canvas").')
350
- const ticketAssetAttachInput = z.strictObject({
408
+ const ticketAssetAttachInput = toolInput({
351
409
  repo: repoField,
352
410
  id: ticketIdField,
353
411
  kind: assetKindField,
@@ -377,7 +435,7 @@ const ticketAssetAttachInput = z.strictObject({
377
435
  )
378
436
  .describe('The asset’s files and explicit directories.'),
379
437
  })
380
- const ticketAssetGetInput = z.strictObject({
438
+ const ticketAssetGetInput = toolInput({
381
439
  repo: repoField,
382
440
  id: ticketIdField,
383
441
  kind: assetKindField,
@@ -392,39 +450,37 @@ const ticketAssetGetInput = z.strictObject({
392
450
  'Exact revision to read. Omit for the latest; a removed asset is readable only by revision.',
393
451
  ),
394
452
  })
395
- const ticketAssetRemoveInput = z.strictObject({
453
+ const ticketAssetRemoveInput = toolInput({
396
454
  repo: repoField,
397
455
  id: ticketIdField,
398
456
  kind: assetKindField,
399
457
  name: assetNameField,
400
458
  })
401
459
 
402
- const objectiveReviseInput = z
403
- .strictObject({
404
- repo: repoField,
405
- slug: slugField,
406
- threshold: z.number().optional().describe('Stop when the node head reaches this value.'),
407
- epsilon: objectiveEpsilonSchema
408
- .optional()
409
- .describe('The smallest gain that counts: {absolute: n} or {relative: 0 < n < 1}.'),
410
- maxAttempts: z.number().int().min(1).optional(),
411
- maxHours: z.number().gt(0).optional(),
412
- plateau: z
413
- .number()
414
- .int()
415
- .min(1)
416
- .optional()
417
- .describe('Consecutive no-improvement or declined attempts that stop the node.'),
418
- stopMode: z.enum(['abort', 'drain']).optional(),
419
- concurrency: z.number().int().min(1).optional().describe('Attempts in flight.'),
420
- })
421
- .refine(
422
- ({ repo: _repo, slug: _slug, ...changes }) =>
423
- Object.values(changes).some((value) => value !== undefined),
424
- 'revise at least one field',
425
- )
460
+ const objectiveReviseInput = toolInput({
461
+ repo: repoField,
462
+ slug: slugField,
463
+ threshold: z.number().optional().describe('Stop when the node head reaches this value.'),
464
+ epsilon: objectiveEpsilonSchema
465
+ .optional()
466
+ .describe('The smallest gain that counts: {absolute: n} or {relative: 0 < n < 1}.'),
467
+ maxAttempts: z.number().int().min(1).optional(),
468
+ maxHours: z.number().gt(0).optional(),
469
+ plateau: z
470
+ .number()
471
+ .int()
472
+ .min(1)
473
+ .optional()
474
+ .describe('Consecutive no-improvement or declined attempts that stop the node.'),
475
+ stopMode: z.enum(['abort', 'drain']).optional(),
476
+ concurrency: z.number().int().min(1).optional().describe('Attempts in flight.'),
477
+ }).refine(
478
+ ({ repo: _repo, slug: _slug, ...changes }) =>
479
+ Object.values(changes).some((value) => value !== undefined),
480
+ 'revise at least one field',
481
+ )
426
482
 
427
- const objectiveStopInput = z.strictObject({
483
+ const objectiveStopInput = toolInput({
428
484
  repo: repoField,
429
485
  slug: slugField,
430
486
  mode: z
@@ -435,7 +491,7 @@ const objectiveStopInput = z.strictObject({
435
491
  ),
436
492
  })
437
493
 
438
- const objectiveSettleUnmeasuredInput = z.strictObject({
494
+ const objectiveSettleUnmeasuredInput = toolInput({
439
495
  repo: repoField,
440
496
  slug: slugField,
441
497
  attempt: z
@@ -448,7 +504,7 @@ const objectiveSettleUnmeasuredInput = z.strictObject({
448
504
  note: z.string().max(4000).optional().describe('A note recorded with the settlement.'),
449
505
  })
450
506
 
451
- const buildEventsInput = z.strictObject({
507
+ const buildEventsInput = toolInput({
452
508
  repo: repoField,
453
509
  slug: slugField,
454
510
  cursor: z
@@ -470,7 +526,7 @@ const buildEventsInput = z.strictObject({
470
526
  ),
471
527
  })
472
528
 
473
- const buildArtifactInput = z.strictObject({
529
+ const buildArtifactInput = toolInput({
474
530
  repo: repoField,
475
531
  slug: slugField,
476
532
  kind: z.string().min(1).describe('Artifact kind to download (e.g. "spec", "plan", "notes").'),
@@ -482,7 +538,7 @@ const buildArtifactInput = z.strictObject({
482
538
  .describe('Artifact revision to fetch; omit for the latest revision of the kind.'),
483
539
  })
484
540
 
485
- const buildControlInput = z.strictObject({
541
+ const buildControlInput = toolInput({
486
542
  head: z
487
543
  .string()
488
544
  .min(1)
@@ -526,7 +582,7 @@ const buildControlInput = z.strictObject({
526
582
  ),
527
583
  })
528
584
 
529
- const repositoryEventsInput = z.strictObject({
585
+ const repositoryEventsInput = toolInput({
530
586
  repo: repoField,
531
587
  cursor: z
532
588
  .number()
@@ -554,7 +610,7 @@ const repositoryEventsInput = z.strictObject({
554
610
  ),
555
611
  })
556
612
 
557
- const repositoryAttentionInput = z.strictObject({
613
+ const repositoryAttentionInput = toolInput({
558
614
  repo: repoField,
559
615
  cursor: z
560
616
  .number()
@@ -569,11 +625,15 @@ const repositoryAttentionInput = z.strictObject({
569
625
 
570
626
  const buildsAnswerInput = extendUnion(answerRequestSchema, { repo: repoField, slug: slugField })
571
627
 
572
- const buildsReopenInput = reopenRequestSchema.extend({ repo: repoField, slug: slugField })
628
+ const buildsReopenInput = toolInput({
629
+ ...reopenRequestSchema.shape,
630
+ repo: repoField,
631
+ slug: slugField,
632
+ })
573
633
 
574
- const repositoryStatusInput = z.strictObject({ repo: repoField })
634
+ const repositoryStatusInput = toolInput({ repo: repoField })
575
635
 
576
- const repositorySettingsInput = z.strictObject({
636
+ const repositorySettingsInput = toolInput({
577
637
  repo: repoField,
578
638
  setting: z.enum(['intake']).describe('"intake" gates whether new tickets may be claimed.'),
579
639
  enabled: z
@@ -582,7 +642,7 @@ const repositorySettingsInput = z.strictObject({
582
642
  .describe('Set the value explicitly; omit to toggle the current durable value.'),
583
643
  })
584
644
 
585
- const bulkControlInput = z.strictObject({
645
+ const bulkControlInput = toolInput({
586
646
  repo: repoField,
587
647
  action: z
588
648
  .enum(['pause', 'resume'])
@@ -591,40 +651,74 @@ const bulkControlInput = z.strictObject({
591
651
  ),
592
652
  })
593
653
 
594
- const harvestStatusInput = z.strictObject({ repo: repoField })
654
+ const harvestStatusInput = toolInput({ repo: repoField })
595
655
 
596
656
  const harvestControlInput = extendUnion(harvestControlRequestSchema, { repo: repoField })
597
657
 
598
- const ticketsListInput = z.strictObject({
658
+ /** The largest `tickets.list` page, and the page size used when paging or
659
+ * filter arguments arrive without `limit`. */
660
+ export const TICKETS_LIST_MAX_LIMIT = 200
661
+
662
+ const ticketsListInput = toolInput({
599
663
  repo: repoField,
600
664
  state: z
601
665
  .string()
602
666
  .min(1)
603
667
  .optional()
604
668
  .describe(
605
- 'Provider state to list; defaults to the effective triage state from the repository’s effective config.',
669
+ 'Provider state to list; defaults to the effective triage state from the repository’s effective config, or to the effective done state when `since` or `until` is given.',
606
670
  ),
607
671
  labels: z
608
672
  .array(z.string().min(1))
609
673
  .optional()
610
674
  .describe('Narrow the list to tickets carrying every named label.'),
675
+ excludeLabels: z
676
+ .array(z.string().min(1))
677
+ .optional()
678
+ .describe('Omit tickets carrying any named label; `total` counts after the exclusion.'),
679
+ since: z
680
+ .string()
681
+ .datetime({ offset: true })
682
+ .optional()
683
+ .describe(
684
+ `Inclusive lower bound on completion time (\`resolvedAt\`), ISO-8601 with offset. Tickets without a completion time never match; defaults \`state\` to done. A hosted range over more than ${TICKET_COMPLETION_SCAN_LIMIT} tickets is refused.`,
685
+ ),
686
+ until: z
687
+ .string()
688
+ .datetime({ offset: true })
689
+ .optional()
690
+ .describe(
691
+ 'Exclusive upper bound on completion time (`resolvedAt`), ISO-8601 with offset; defaults `state` to done.',
692
+ ),
693
+ summary: z
694
+ .boolean()
695
+ .optional()
696
+ .describe('Omit ticket bodies and comments, keeping every other field.'),
611
697
  limit: z
612
698
  .number()
613
699
  .int()
614
700
  .min(0)
615
- .max(200)
701
+ .max(TICKETS_LIST_MAX_LIMIT)
616
702
  .optional()
617
- .describe('Return at most this many tickets; `total` still counts every match.'),
703
+ .describe(
704
+ `Return at most this many tickets; \`total\` still counts every match. Defaults to ${TICKETS_LIST_MAX_LIMIT} when \`offset\`, \`order\`, \`since\`, \`until\` or \`excludeLabels\` is given.`,
705
+ ),
618
706
  offset: z.number().int().min(0).optional().describe('Skip this many tickets first.'),
619
707
  order: z
620
- .enum(['oldest', 'newest'])
708
+ .enum(['oldest', 'newest', 'completed'])
621
709
  .optional()
622
710
  .describe(
623
- 'Priority order, urgent then high then normal then low tickets, each in the source order (the default), or newest filed first regardless of priority.',
711
+ 'Priority order, urgent then high then normal then low tickets, each in the source order (the default); newest filed first regardless of priority; or most recently completed first, then tickets without a completion time newest filed first.',
624
712
  ),
625
- })
713
+ }).refine(
714
+ (input) =>
715
+ input.since === undefined ||
716
+ input.until === undefined ||
717
+ Date.parse(input.since) < Date.parse(input.until),
718
+ { message: '`since` must be earlier than `until`', path: ['until'] },
719
+ )
626
720
 
627
- const ticketsSearchInput = z.strictObject({
721
+ const ticketsSearchInput = toolInput({
628
722
  repo: repoField,
629
723
  query: z
630
724
  .string()
@@ -651,24 +745,27 @@ const ticketsSearchInput = z.strictObject({
651
745
  .describe('The `cursor` from the previous page of the same search.'),
652
746
  })
653
747
 
654
- const ticketsCreateInput = ticketCreateRequestSchema.extend({ repo: repoField })
655
-
656
- const ticketsUpdateInput = ticketUpdateRequestSchema
657
- .extend({ repo: repoField, id: ticketIdField })
658
- .refine(
659
- (value) =>
660
- value.title !== undefined ||
661
- value.body !== undefined ||
662
- value.labels !== undefined ||
663
- value.issueLinks !== undefined ||
664
- value.priority !== undefined ||
665
- value.assignees !== undefined ||
666
- value.kind !== undefined ||
667
- value.target !== undefined,
668
- 'update must name at least one field',
669
- )
748
+ const ticketsCreateInput = toolInput({ ...ticketCreateRequestSchema.shape, repo: repoField })
670
749
 
671
- const ticketsBlockersInput = ticketBlockerRequestSchema.extend({
750
+ const ticketsUpdateInput = toolInput({
751
+ ...ticketUpdateRequestSchema.shape,
752
+ repo: repoField,
753
+ id: ticketIdField,
754
+ }).refine(
755
+ (value) =>
756
+ value.title !== undefined ||
757
+ value.body !== undefined ||
758
+ value.labels !== undefined ||
759
+ value.issueLinks !== undefined ||
760
+ value.priority !== undefined ||
761
+ value.assignees !== undefined ||
762
+ value.kind !== undefined ||
763
+ value.target !== undefined,
764
+ 'update must name at least one field',
765
+ )
766
+
767
+ const ticketsBlockersInput = toolInput({
768
+ ...ticketBlockerRequestSchema.shape,
672
769
  repo: repoField,
673
770
  id: ticketIdField,
674
771
  blockerIds: z
@@ -679,7 +776,7 @@ const ticketsBlockersInput = ticketBlockerRequestSchema.extend({
679
776
  ),
680
777
  })
681
778
 
682
- const ticketsStartInput = z.strictObject({
779
+ const ticketsStartInput = toolInput({
683
780
  repo: repoField,
684
781
  id: ticketIdField,
685
782
  priority: z
@@ -694,23 +791,22 @@ const ticketsStartInput = z.strictObject({
694
791
  .describe('Cancel the pending start request for this ticket instead of requesting one.'),
695
792
  })
696
793
 
697
- const ticketsMoveInput = ticketMoveRequestShape
698
- .extend({
699
- repo: repoField,
700
- id: ticketIdField,
701
- state: z
702
- .string()
703
- .min(1)
704
- .optional()
705
- .describe(
706
- 'Provider state to move the ticket into; give this or `role`, not both. Destructive: moving a ticket into the repository’s configured ready state queues it for dispatch.',
707
- ),
708
- })
709
- .refine(exactlyOneMoveTarget, MOVE_TARGET_MESSAGE)
794
+ const ticketsMoveInput = toolInput({
795
+ ...ticketMoveRequestShape.shape,
796
+ repo: repoField,
797
+ id: ticketIdField,
798
+ state: z
799
+ .string()
800
+ .min(1)
801
+ .optional()
802
+ .describe(
803
+ 'Provider state to move the ticket into; give this or `role`, not both. Destructive: moving a ticket into the repository’s configured ready state queues it for dispatch.',
804
+ ),
805
+ }).refine(exactlyOneMoveTarget, MOVE_TARGET_MESSAGE)
710
806
 
711
- const notesReadInput = z.strictObject({ repo: repoField })
807
+ const notesReadInput = toolInput({ repo: repoField })
712
808
 
713
- const notesWriteInput = z.strictObject({
809
+ const notesWriteInput = toolInput({
714
810
  repo: repoField,
715
811
  document: z
716
812
  .string()
@@ -719,7 +815,7 @@ const notesWriteInput = z.strictObject({
719
815
  ),
720
816
  })
721
817
 
722
- const sandboxExecInput = z.strictObject({
818
+ const sandboxExecInput = toolInput({
723
819
  repo: repoField,
724
820
  command: z.string().min(1).describe('Shell command to run inside the operator sandbox.'),
725
821
  cwd: z
@@ -739,7 +835,7 @@ const sandboxExecInput = z.strictObject({
739
835
  ),
740
836
  })
741
837
 
742
- const sandboxStartInput = z.strictObject({
838
+ const sandboxStartInput = toolInput({
743
839
  repo: repoField,
744
840
  command: z
745
841
  .string()
@@ -753,7 +849,7 @@ const sandboxStartInput = z.strictObject({
753
849
  ),
754
850
  })
755
851
 
756
- const sandboxWaitInput = z.strictObject({
852
+ const sandboxWaitInput = toolInput({
757
853
  repo: repoField,
758
854
  commandId: z.string().min(1).describe('Command id returned by a previous sandbox.start.'),
759
855
  waitSeconds: z
@@ -766,7 +862,7 @@ const sandboxWaitInput = z.strictObject({
766
862
  ),
767
863
  })
768
864
 
769
- const sandboxReadFileInput = z.strictObject({
865
+ const sandboxReadFileInput = toolInput({
770
866
  repo: repoField,
771
867
  path: z
772
868
  .string()
@@ -774,7 +870,7 @@ const sandboxReadFileInput = z.strictObject({
774
870
  .describe('File path relative to the checkout. Absolute paths and ".." escapes are refused.'),
775
871
  })
776
872
 
777
- const sandboxWriteFileInput = z.strictObject({
873
+ const sandboxWriteFileInput = toolInput({
778
874
  repo: repoField,
779
875
  path: z
780
876
  .string()
@@ -787,13 +883,13 @@ const sandboxWriteFileInput = z.strictObject({
787
883
  .describe('How to decode `content`: "utf8" (default) or "base64".'),
788
884
  })
789
885
 
790
- const sandboxResetInput = z.strictObject({ repo: repoField })
791
- const sandboxOpenInput = z.strictObject({ repo: repoField })
792
- const sandboxStatusInput = z.strictObject({ repo: repoField })
793
- const sandboxCloseInput = z.strictObject({ repo: repoField })
794
- const sandboxRefreshInput = z.strictObject({ repo: repoField })
886
+ const sandboxResetInput = toolInput({ repo: repoField })
887
+ const sandboxOpenInput = toolInput({ repo: repoField })
888
+ const sandboxStatusInput = toolInput({ repo: repoField })
889
+ const sandboxCloseInput = toolInput({ repo: repoField })
890
+ const sandboxRefreshInput = toolInput({ repo: repoField })
795
891
 
796
- const sandboxPublishInput = z.strictObject({
892
+ const sandboxPublishInput = toolInput({
797
893
  repo: repoField,
798
894
  title: z.string().min(1).max(200).describe('Pull-request title, 1-200 characters.'),
799
895
  body: z
@@ -869,11 +965,20 @@ export const TOOLS: readonly ToolEntry[] = [
869
965
  ),
870
966
  defineTool(
871
967
  'builds.list',
872
- 'List one repository’s builds, newest first, with effective status derived from the build log.',
968
+ 'List one repository’s builds, newest first, with effective status derived from the build log; or, with scope "merged", the builds merged in a time window, most recently merged first, one page at a time.',
873
969
  buildListInput,
874
- 'JSON array of build summaries: slug, ticket ref, effective status, phase/round/attempt, PR number/url/state, updatedAt, lease health, durable-event progress, any ticket wait (`wait` with its state and tickets; `waitOnly` when the wait is the only open escalation), an optimization node’s objective progress (`objective`), and each nonterminal build’s slot state (`slot`: `{state: "held"}`, `{state: "requested", request, priority?: "urgent" | "high" | "low"}` or `{state: "none"}`; absent means unknown, never none).',
970
+ 'Scope "merged": {builds, next}, where each build is {slug, mergedAt, kind: "leaf" | "node", ticket?: {source, id, title?, url?}, pr?: {number, url}, target?: {build, ticket}} (`mergedAt` is when it merged, never a later cleanup; `target` is the node a child build targets), and `next` is a cursor to pass back with the same since and until, or null on the last page. Other scopes: a JSON array of build summaries: slug, ticket ref, effective status, phase/round/attempt, PR number/url/state, updatedAt, lease health, durable-event progress, any ticket wait (`wait` with its state and tickets; `waitOnly` when the wait is the only open escalation), an optimization node’s objective progress (`objective`), and each nonterminal build’s slot state (`slot`: `{state: "held"}`, `{state: "requested", request, priority?: "urgent" | "high" | "low"}` or `{state: "none"}`; absent means unknown, never none).',
875
971
  async (raw, ctx) => {
876
972
  const input = raw as z.infer<typeof buildListInput>
973
+ if (input.scope === 'merged')
974
+ return listOperatorMergedBuilds({
975
+ store: ctx.store,
976
+ repo: input.repo,
977
+ ...(input.since !== undefined ? { since: input.since } : {}),
978
+ ...(input.until !== undefined ? { until: input.until } : {}),
979
+ ...(input.limit !== undefined ? { limit: input.limit } : {}),
980
+ ...(input.cursor !== undefined ? { cursor: input.cursor } : {}),
981
+ })
877
982
  return listOperatorBuilds({
878
983
  store: ctx.store,
879
984
  repo: input.repo,
@@ -1136,8 +1241,8 @@ export const TOOLS: readonly ToolEntry[] = [
1136
1241
  defineTool(
1137
1242
  'repository.forge_clear',
1138
1243
  'Explicitly clear erroneous forge cooldown state with an audited reason; does not prove provider recovery.',
1139
- z.strictObject({
1140
- repo: z.string().min(1).describe('Exact repository identity.'),
1244
+ toolInput({
1245
+ repo: repoField,
1141
1246
  forge: z.string().trim().min(1).describe('Forge adapter name.'),
1142
1247
  reason: z.string().trim().min(1).describe('Reason for the operator override.'),
1143
1248
  }),
@@ -1273,7 +1378,7 @@ export const TOOLS: readonly ToolEntry[] = [
1273
1378
  defineTool(
1274
1379
  'tickets.states',
1275
1380
  'List all ticket states with ticket counts and optional purposes.',
1276
- z.strictObject({ repo: z.string().min(1) }),
1381
+ toolInput({ repo: repoField }),
1277
1382
  'Array of {name,tickets,about?}.',
1278
1383
  async (raw, ctx) => {
1279
1384
  const input = raw as { repo: string }
@@ -1287,7 +1392,7 @@ export const TOOLS: readonly ToolEntry[] = [
1287
1392
  defineTool(
1288
1393
  'tickets.state.create',
1289
1394
  'Create a custom ticket state with an optional one-line purpose. Hosted duplicates are refused.',
1290
- z.strictObject({ repo: z.string().min(1), name: z.string(), about: z.string().optional() }),
1395
+ toolInput({ repo: repoField, name: z.string(), about: z.string().optional() }),
1291
1396
  '{state: {name,tickets,about?},created}.',
1292
1397
  async (raw, ctx) => {
1293
1398
  const input = raw as { repo: string; name: string; about?: string }
@@ -1298,19 +1403,30 @@ export const TOOLS: readonly ToolEntry[] = [
1298
1403
  'tickets.list',
1299
1404
  'List the repository’s ticket grooming queue from the configured ticket source.',
1300
1405
  ticketsListInput,
1301
- '{states, tickets, diagnostics, criteria, triageState, readyState, doneState, total}: the queue listing (one page when `limit` is set), the effective lifecycle names, the criteria actually applied, and the match count before paging.',
1406
+ `{states, tickets, diagnostics, criteria, triageState, readyState, doneState, total}: the queue listing (one page when \`limit\`, \`offset\`, \`order\`, \`since\`, \`until\` or \`excludeLabels\` is set), the effective lifecycle names, the criteria actually applied (state, labels, excludeLabels, since, until), and the match count before paging. Tickets carry \`resolvedAt\` (completion time) when the source knows it and \`targetTitle\` beside \`target\`; \`summary\` omits \`body\` and \`comments\`. Hosted completion queries (\`since\`/\`until\`, \`order: "completed"\`, \`excludeLabels\`) examine at most ${TICKET_COMPLETION_SCAN_LIMIT} tickets of the state and range; broader ones refuse with \`completion-range-too-broad\` — narrow \`since\`/\`until\`.`,
1302
1407
  async (raw, ctx) => {
1303
1408
  const input = raw as z.infer<typeof ticketsListInput>
1409
+ const paged =
1410
+ input.limit !== undefined ||
1411
+ input.offset !== undefined ||
1412
+ input.order !== undefined ||
1413
+ input.since !== undefined ||
1414
+ input.until !== undefined ||
1415
+ input.excludeLabels !== undefined
1304
1416
  return listOperatorTickets({
1305
1417
  store: ctx.store,
1306
1418
  repo: input.repo,
1307
1419
  backend: ticketsOf(ctx),
1308
1420
  ...(input.state !== undefined ? { state: input.state } : {}),
1309
1421
  ...(input.labels !== undefined ? { labels: input.labels } : {}),
1310
- ...(input.limit !== undefined
1422
+ ...(input.excludeLabels !== undefined ? { excludeLabels: input.excludeLabels } : {}),
1423
+ ...(input.since !== undefined ? { since: input.since } : {}),
1424
+ ...(input.until !== undefined ? { until: input.until } : {}),
1425
+ ...(input.summary !== undefined ? { summary: input.summary } : {}),
1426
+ ...(paged
1311
1427
  ? {
1312
1428
  page: {
1313
- limit: input.limit,
1429
+ limit: input.limit ?? TICKETS_LIST_MAX_LIMIT,
1314
1430
  ...(input.offset !== undefined ? { offset: input.offset } : {}),
1315
1431
  ...(input.order !== undefined ? { order: input.order } : {}),
1316
1432
  },
@@ -1790,6 +1906,12 @@ function mapDomainError(error: unknown): RegistryError {
1790
1906
  error: error.message,
1791
1907
  code: 'search-unsupported',
1792
1908
  })
1909
+ if (error instanceof TicketCompletionRangeTooBroad)
1910
+ return new RegistryError('domain', error.message, {
1911
+ kind: 'refusal',
1912
+ error: error.message,
1913
+ code: 'completion-range-too-broad',
1914
+ })
1793
1915
  if (error instanceof TicketSearchCursorInvalid)
1794
1916
  return new RegistryError('domain', error.message, {
1795
1917
  kind: 'refusal',
@@ -1833,6 +1955,18 @@ function mapDomainError(error: unknown): RegistryError {
1833
1955
  ...(error.state !== undefined ? { state: error.state } : {}),
1834
1956
  })
1835
1957
  }
1958
+ if (error instanceof BuildFeedValidationError)
1959
+ return new RegistryError('domain', error.message, {
1960
+ kind: 'validation',
1961
+ error: error.message,
1962
+ code: 'invalid-page',
1963
+ })
1964
+ if (error instanceof BuildFeedUnsupportedError)
1965
+ return new RegistryError('domain', error.message, {
1966
+ kind: 'conflict',
1967
+ error: error.message,
1968
+ code: 'store-unsupported',
1969
+ })
1836
1970
  if (error instanceof OperatorQueryError) {
1837
1971
  return new RegistryError('domain', error.message, {
1838
1972
  kind: error.code === 'not-found' ? 'not-found' : 'conflict',
@@ -1882,6 +2016,16 @@ export function buildRegistry(options: RegistryOptions): OperatorToolRegistry {
1882
2016
  error: `unknown tool "${name}"`,
1883
2017
  })
1884
2018
  }
2019
+ // The repository argument's name is a contract every binding states the
2020
+ // same way, before any other validation.
2021
+ if (hasRepositoryArgument(input)) {
2022
+ const error = `invalid input for tool "${name}": ${REPOSITORY_ARGUMENT_MESSAGE}`
2023
+ throw new RegistryError('validation', error, {
2024
+ kind: 'validation',
2025
+ error,
2026
+ code: 'repo-argument',
2027
+ })
2028
+ }
1885
2029
  const parsed = entry.inputSchema.safeParse(input)
1886
2030
  if (!parsed.success) {
1887
2031
  throw new RegistryError(