@defrex/autobuild 1.7.0 → 1.8.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 (116) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +316 -47
  3. package/docs/answering-blocked-builds.md +44 -3
  4. package/docs/architecture.md +62 -7
  5. package/docs/cli.md +1 -0
  6. package/docs/configuration-overview.md +1 -1
  7. package/docs/configuration.md +49 -9
  8. package/docs/dispatcher.md +1 -1
  9. package/docs/integration-overview.md +2 -2
  10. package/docs/integration-tree.md +7 -4
  11. package/docs/merge-policy.md +78 -6
  12. package/docs/migration-1.0.md +4 -2
  13. package/docs/operating.md +3 -2
  14. package/docs/operator-api.md +26 -5
  15. package/docs/operator-surfaces.md +10 -0
  16. package/docs/plugin-authoring.md +1 -1
  17. package/docs/remote-store-protocol.md +9 -1
  18. package/docs/restacking.md +23 -4
  19. package/docs/ticket-dependencies.md +9 -4
  20. package/docs/tickets.md +1 -1
  21. package/docs/troubleshooting.md +1 -1
  22. package/package.json +3 -3
  23. package/packages/core/src/cli/attention.ts +1 -0
  24. package/packages/core/src/cli/build-control.ts +65 -7
  25. package/packages/core/src/cli/context.ts +55 -14
  26. package/packages/core/src/cli/dashboard/actions.ts +13 -4
  27. package/packages/core/src/cli/dashboard/landing-display.ts +32 -8
  28. package/packages/core/src/cli/dashboard/model.ts +61 -8
  29. package/packages/core/src/cli/dashboard/render.ts +28 -3
  30. package/packages/core/src/cli/dashboard/tree.ts +9 -1
  31. package/packages/core/src/cli/help.ts +69 -7
  32. package/packages/core/src/cli/landings.ts +1 -1
  33. package/packages/core/src/cli/main.ts +60 -9
  34. package/packages/core/src/cli/publication-settlement.ts +10 -0
  35. package/packages/core/src/cli/status.ts +178 -12
  36. package/packages/core/src/cli/terminals.ts +197 -4
  37. package/packages/core/src/cli/wait.ts +1 -0
  38. package/packages/core/src/cli/watch.ts +71 -0
  39. package/packages/core/src/config/landing.ts +12 -0
  40. package/packages/core/src/config/path-selectors.ts +68 -0
  41. package/packages/core/src/config/schema.ts +40 -58
  42. package/packages/core/src/events/catalog.ts +17 -3
  43. package/packages/core/src/events/compatibility.ts +2 -1
  44. package/packages/core/src/events/head-paths-limits.ts +25 -0
  45. package/packages/core/src/events/payloads.ts +315 -20
  46. package/packages/core/src/events/policy.ts +21 -0
  47. package/packages/core/src/events/repository.ts +30 -1
  48. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +247 -6
  49. package/packages/core/src/kernel/consent-revocation.ts +72 -0
  50. package/packages/core/src/kernel/dispatch-capacity.ts +19 -8
  51. package/packages/core/src/kernel/engine.ts +48 -8
  52. package/packages/core/src/kernel/head-paths-state.ts +63 -0
  53. package/packages/core/src/kernel/head-paths.ts +401 -0
  54. package/packages/core/src/kernel/landing-policy-identity.ts +20 -0
  55. package/packages/core/src/kernel/landing-policy.ts +55 -2
  56. package/packages/core/src/kernel/landing-readiness.ts +104 -9
  57. package/packages/core/src/kernel/landing-state.ts +44 -4
  58. package/packages/core/src/kernel/leaf-restack-base.ts +34 -0
  59. package/packages/core/src/kernel/leaf-restack-state.ts +22 -2
  60. package/packages/core/src/kernel/log-index.ts +27 -1
  61. package/packages/core/src/kernel/node-polling.ts +13 -3
  62. package/packages/core/src/kernel/node-restack-state.ts +8 -1
  63. package/packages/core/src/kernel/node-restack-transaction.ts +45 -0
  64. package/packages/core/src/kernel/read-deferrals.ts +3 -1
  65. package/packages/core/src/kernel/read-facts.ts +28 -1
  66. package/packages/core/src/kernel/reducer-registry.ts +22 -1
  67. package/packages/core/src/kernel/reducer.ts +316 -17
  68. package/packages/core/src/kernel/target-observation.ts +2 -5
  69. package/packages/core/src/kernel/terminal-guard.ts +52 -3
  70. package/packages/core/src/kernel/ticket-handbacks.ts +40 -0
  71. package/packages/core/src/kernel/ticket-preparation.ts +12 -1
  72. package/packages/core/src/kernel/ticket-wait.ts +345 -0
  73. package/packages/core/src/kernel/verify-applicability.ts +9 -19
  74. package/packages/core/src/ontology.ts +1 -0
  75. package/packages/core/src/operator/annotations.ts +6 -0
  76. package/packages/core/src/operator/index.ts +3 -0
  77. package/packages/core/src/operator/protocol.ts +15 -2
  78. package/packages/core/src/operator/registry.ts +97 -5
  79. package/packages/core/src/operator/repository-events.ts +67 -0
  80. package/packages/core/src/ports/tickets/fake.ts +5 -0
  81. package/packages/core/src/ports/types.ts +3 -2
  82. package/packages/core/src/processes/build-execution-state.ts +30 -1
  83. package/packages/core/src/processes/build-runner.ts +150 -18
  84. package/packages/core/src/processes/dispatcher.ts +739 -97
  85. package/packages/core/src/processes/execution-no-progress.ts +22 -2
  86. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  87. package/packages/core/src/processes/publication-state.ts +6 -1
  88. package/packages/core/src/store/digest.ts +41 -2
  89. package/packages/core/src/store/reduced-reads.ts +4 -1
  90. package/packages/core/src/store/reducer-value-shapes.json +10108 -8432
  91. package/packages/core/src/store/remote/client.ts +28 -2
  92. package/packages/core/src/store/remote/protocol.ts +11 -1
  93. package/packages/core/src/store/remote/released-clients.json +22 -0
  94. package/packages/core/src/store/remote/released-reducer-values/1.8.0.json +29043 -0
  95. package/packages/core/src/store/remote/released-reducer-values/index.ts +2 -0
  96. package/packages/core/src/store/repo-state-events.ts +2 -0
  97. package/packages/core/src/store/types.ts +16 -0
  98. package/packages/core/src/testing/reduced-read-budget.ts +347 -0
  99. package/skills/code-review/SKILL.md +8 -0
  100. package/skills/finalize/SKILL.md +4 -0
  101. package/skills/guide/SKILL.md +125 -26
  102. package/skills/guide/references/integration-tree.md +7 -4
  103. package/skills/guide/references/merge-policy.md +78 -6
  104. package/skills/guide/references/migration-1.0.md +4 -2
  105. package/skills/guide/references/operator-api.md +26 -5
  106. package/skills/guide/references/plugin-authoring.md +1 -1
  107. package/skills/guide/references/remote-store-protocol.md +9 -1
  108. package/skills/guide/references/restacking.md +23 -4
  109. package/skills/guide/references/ticket-dependencies.md +9 -4
  110. package/skills/implement/SKILL.md +15 -1
  111. package/skills/operate/SKILL.md +104 -13
  112. package/skills/plan/SKILL.md +17 -2
  113. package/skills/plan-review/SKILL.md +8 -0
  114. package/skills/reconcile/SKILL.md +21 -5
  115. package/skills/tickets/SKILL.md +5 -4
  116. package/templates/hosted-service/package.json +2 -2
@@ -284,6 +284,7 @@ const STATUS_COLOR: Record<DashboardBuild['status'] | DashboardHarvest['status']
284
284
  suspended: 'yellow',
285
285
  resuming: 'cyan',
286
286
  blocked: 'red',
287
+ waiting: 'yellow',
287
288
  aborting: 'red',
288
289
  cleaning: 'yellow',
289
290
  escalated: 'yellow',
@@ -474,6 +475,11 @@ function renderBuild(
474
475
  if (build.alert)
475
476
  for (const line of wrappedText(build.alert.text, Math.max(1, width - 4), ''))
476
477
  lines.push(paint(` ! ${line}`, build.alert.tone, color))
478
+ // A ticket wait is held work, not a blocker: one yellow line naming the
479
+ // tickets, never a red question preview.
480
+ if (build.wait)
481
+ for (const line of wrappedText(build.wait.text, Math.max(1, width - 4), ''))
482
+ lines.push(paint(` ! ${line}`, 'yellow', color))
477
483
  // Setup failures and blocker questions are dense-list previews. Their model
478
484
  // strings remain untouched; newline-aware wrapping and capping happen only
479
485
  // at this presentation seam.
@@ -894,6 +900,19 @@ function detailBody(
894
900
  body.push(...wrappedText(note, width, ' ').map((line) => paint(line, 'dim', color)))
895
901
  }
896
902
  }
903
+ if (build.wait !== undefined) {
904
+ body.push('', paint('Waiting', 'bold', color))
905
+ body.push(
906
+ ...wrapDisplay(build.wait.text, width, ' ').map((line) => paint(line, 'yellow', color)),
907
+ )
908
+ body.push(...wrappedText(`since ${build.wait.since}`, width, ' '))
909
+ for (const note of [
910
+ 'r answers the wait and ends it early',
911
+ `CLI only: ab answer ${build.slug} [text]`,
912
+ ]) {
913
+ body.push(...wrappedText(note, width, ' ').map((line) => paint(line, 'dim', color)))
914
+ }
915
+ }
897
916
  body.push('', paint('Sessions', 'bold', color))
898
917
  const sessions = build.sessions ?? []
899
918
  let sessionFocus: number | undefined
@@ -1453,7 +1472,13 @@ export function resumePanel(
1453
1472
  // frame did not grant — which is what makes every `fieldWidth` below at
1454
1473
  // least 1 without a clamp.
1455
1474
  if (width <= 0) return []
1456
- const questions = model.builds.find((candidate) => candidate.slug === prompt.slug)?.blockers ?? []
1475
+ const build = model.builds.find((candidate) => candidate.slug === prompt.slug)
1476
+ // Answering a waiting build answers its wait's question, shown in the wait's
1477
+ // yellow beside any red blockers.
1478
+ const questions: Array<{ text: string; tone: 'red' | 'yellow' }> = [
1479
+ ...(build?.blockers ?? []).map((text) => ({ text, tone: 'red' as const })),
1480
+ ...(build?.wait ? [{ text: build.wait.question, tone: 'yellow' as const }] : []),
1481
+ ]
1457
1482
 
1458
1483
  const title = truncate(
1459
1484
  paint(paint(`Resume ${displayText(prompt.slug)}`, 'cyan', color), 'bold', color),
@@ -1467,10 +1492,10 @@ export function resumePanel(
1467
1492
  // notice accounts for.
1468
1493
  const questionRows: string[] = []
1469
1494
  for (const question of questions) {
1470
- const wrapped = wrapDisplay(question, width - 4)
1495
+ const wrapped = wrapDisplay(question.text, width - 4)
1471
1496
  for (const [index, line] of wrapped.entries()) {
1472
1497
  questionRows.push(
1473
- truncate(paint(`${index === 0 ? ' ! ' : ' '}${line}`, 'red', color), width),
1498
+ truncate(paint(`${index === 0 ? ' ! ' : ' '}${line}`, question.tone, color), width),
1474
1499
  )
1475
1500
  }
1476
1501
  }
@@ -7,7 +7,7 @@ import {
7
7
  integrationCycleVerified,
8
8
  } from '../../kernel/integration-state'
9
9
  import { mergeVocabulary } from './landing-display'
10
- import { awaitsConsent, landingReady } from '../../kernel/landing-readiness'
10
+ import { awaitsConsent, currentCandidateHead, landingReady } from '../../kernel/landing-readiness'
11
11
 
12
12
  export const treeVocabulary = {
13
13
  root: 'root',
@@ -17,6 +17,8 @@ export const treeVocabulary = {
17
17
  landing: mergeVocabulary.label,
18
18
  restack: 'restack',
19
19
  consent: 'consent',
20
+ head: 'head',
21
+ consentedAt: 'consented at',
20
22
  queue: 'queue',
21
23
  work: 'work',
22
24
  integrationKind: 'integration',
@@ -90,6 +92,12 @@ export function projectTree(
90
92
  : {}),
91
93
  ready: landingReady(state, restack),
92
94
  consent: awaitsConsent(state, restack),
95
+ /** The live candidate head: what `ab merge --head` must name. */
96
+ currentHead: currentCandidateHead(state) ?? null,
97
+ /** The candidate head consent was given at while merge consent is
98
+ * recorded; null without consent and for legacy consent. */
99
+ consentedHead:
100
+ state.landing?.command?.kind === 'land' ? (state.landing.command.head ?? null) : null,
93
101
  reason: awaitsConsent(state, restack)
94
102
  ? state.landing?.command?.kind === 'hold'
95
103
  ? ('held' as const)
@@ -320,7 +320,8 @@ These fields describe intent; dispatch and merge behavior are unchanged.`,
320
320
  summary: 'List ready merges awaiting consent.',
321
321
  detail: page([
322
322
  'Usage: ab merges [--json] [--store <ref>]',
323
- 'Shows ready consent and held merges with effective target, branch, verification and node children.',
323
+ 'Shows ready consent and held merges with effective target, branch, verification, node children,',
324
+ 'the current candidate head and any consented head.',
324
325
  'Use ab merge <slug> to consent or ab hold <slug> to withdraw consent. Merge rechecks readiness.',
325
326
  'Source ancestry is available separately through ab ticket tree or MCP tickets.tree.',
326
327
  ]),
@@ -338,6 +339,10 @@ These fields describe intent; dispatch and merge behavior are unchanged.`,
338
339
  'shows every status and subsumes --queued. --json emits the projection as a',
339
340
  'bare JSON value, and --store overrides the BuildStore path or URL.',
340
341
  '',
342
+ 'A build parked on a ticket wait lists as waiting, with the tickets after its',
343
+ 'phase. --json keeps the reducer status (blocked) and adds wait with its state',
344
+ 'and tickets.',
345
+ '',
341
346
  'This command is read-only and requires no session identity for operator use.',
342
347
  'Inside a phase, a complete ambient tuple retains its build scope, so the',
343
348
  'repository-wide list is denied; malformed or partial identity is rejected.',
@@ -408,7 +413,7 @@ These fields describe intent; dispatch and merge behavior are unchanged.`,
408
413
  'Default filter — actionable attention only. Builds: escalation.raised, phase.deferral-escalated, integration.landed,',
409
414
  'integration.verification-failed (failed node verification), build.janitor-failing, build.janitor-escalated,',
410
415
  'build.compatibility-deferred, node.item-conflicted, target.rewritten, conflicted restack.replayed,',
411
- 'derived build.consent-ready and',
416
+ 'landing.consent-revoked (protected merge consent revoked by a reconcile), derived build.consent-ready and',
412
417
  'build.merge-decision (a current actionable merge-gate deferral or unsafe forge outcome).',
413
418
  'Consent and held ready merges use only build.consent-ready, once per readiness episode.',
414
419
  'Unready or stale consent candidates stay silent; one merge gate decision per build/PR.',
@@ -416,11 +421,16 @@ These fields describe intent; dispatch and merge behavior are unchanged.`,
416
421
  'dispatcher.kernel-git-unavailable, forge.credential-limited, dispatcher.config-reloaded with restartRequired,',
417
422
  'abnormal dispatcher.run-stopped,',
418
423
  'abandoned ticket-preparation.resolved (claim confirmed or unconfirmed; ticket unchanged),',
424
+ 'ticket.handed-back (a claimed or ready ticket returned other than as completion: abort,',
425
+ 'spec-bounce, preparation-failed, pr-closed or discard; emitted once after the move),',
419
426
  'and dispatcher.lost. dispatcher.ticket-source-persistent reports degradation past',
420
427
  'resetAt after a tick started at or after reset completes or fails while still degraded,',
421
428
  'or 15 minutes without a reset; dispatcher.tick-failure-persistent reports',
422
429
  'five minutes of continuous tick failure outside source grace or cooldown. Each episode',
423
430
  'reports once; recovery ends it. Cooldown failures do not start the tick-failure clock.',
431
+ 'Ticket waits are routine, not attention: wait.entered, wait.ended and the escalation.answered',
432
+ "that ends a wait stay out of the default. Follow them with --event 'wait.*' --event escalation.answered.",
433
+ 'A wait-unresolvable escalation (a waited ticket was rejected or deleted) is ordinary attention.',
424
434
  '--event replaces defaults with exactly matching catalog events (or dispatcher.lost).',
425
435
  'Routine failures, finalize and terminal outcomes require explicit --event globs.',
426
436
  'Derived records carry observation instead of event, with observedAt and PR/reason',
@@ -665,13 +675,27 @@ These fields describe intent; dispatch and merge behavior are unchanged.`,
665
675
  summary: 'Request that a non-terminal build abort and be cleaned up.',
666
676
  detail: page([
667
677
  'Usage:',
668
- ' ab abort <slug> [--store <ref>]',
678
+ ' ab abort <slug> [--to triage|ready] [--reason <text>] [--store <ref>]',
669
679
  '',
670
680
  'Durably request that a queued, running, paused, or blocked build abort. The live',
671
681
  'agent turn is cancelled promptly; dispatcher cleanup closes any unmerged PR,',
672
682
  'removes the workspace and local/remote branches, labels the ticket',
673
- 'autobuild:aborted, and returns it to triage. Cleanup is asynchronous and retry-safe.',
674
- '--store overrides the BuildStore path or URL. This command is sessionless; a phase',
683
+ 'autobuild:aborted, and hands the ticket back. Cleanup is asynchronous and retry-safe.',
684
+ '',
685
+ ' --to <role> Where the ticket goes: triage (default) or ready. ready moves it',
686
+ ' straight to the configured ready state with its blockedBy list',
687
+ ' unchanged, so it redispatches once its blockers merge; no second',
688
+ ' move is needed. A ticket that no longer conforms to the spec',
689
+ ' standard falls back to triage, and the comment lists what is missing.',
690
+ ' --reason <text> Recorded on the request (1-2000 characters) and quoted in the',
691
+ ' hand-back comment.',
692
+ ' --store <ref> Override the BuildStore path or URL.',
693
+ '',
694
+ 'The ticket moves once, inside cleanup. After the move is committed the dispatcher',
695
+ 'appends one ticket.handed-back repository event (in the default ab watch filter).',
696
+ 'Act on that event, not on build.aborted: moving the ticket after it is safe, and no',
697
+ 'later dispatcher write overrides it. Repeating the same abort is a no-op; a',
698
+ 'different destination or reason is refused. This command is sessionless; a phase',
675
699
  'may not control its own build.',
676
700
  ]),
677
701
  },
@@ -692,10 +716,20 @@ These fields describe intent; dispatch and merge behavior are unchanged.`,
692
716
  audience: 'human' as const,
693
717
  summary: name === 'hold' ? 'Hold a merge and withdraw consent.' : 'Consent to a ready merge.',
694
718
  detail: page([
695
- `Usage: ab ${name} <slug> [--store <ref>]`,
719
+ name === 'hold'
720
+ ? 'Usage: ab hold <slug> [--store <ref>]'
721
+ : 'Usage: ab merge <slug> [--head <sha>] [--store <ref>]',
696
722
  '',
697
- 'Merge consent survives restacks and verification; hold persists until merge.',
723
+ 'Merge consent survives clean restacks and verification; hold persists until merge.',
724
+ 'Consent given under a [[merge]] rule with paths or within is revoked when a reconcile',
725
+ 'edits a file the rule protects (landing.consent-revoked); the build needs fresh consent.',
698
726
  'These sessionless controls never bypass merge gates.',
727
+ ...(name === 'merge'
728
+ ? [
729
+ '--head refuses, recording nothing, unless <sha> (full or ≥7-character prefix)',
730
+ "is the build's current candidate head; consent still survives later clean restacks.",
731
+ ]
732
+ : []),
699
733
  ]),
700
734
  })),
701
735
  {
@@ -844,6 +878,34 @@ These fields describe intent; dispatch and merge behavior are unchanged.`,
844
878
  'terminal command. Every phase ends with exactly one terminal command (D5).',
845
879
  ]),
846
880
  },
881
+ {
882
+ name: 'wait-on',
883
+ audience: 'ai',
884
+ summary: 'Park the build on other tickets without holding a slot.',
885
+ detail: page([
886
+ 'Usage:',
887
+ ' ab wait-on <ticket-id>... --reason <text>',
888
+ '',
889
+ 'Declare that this build cannot proceed until the named tickets complete.',
890
+ 'This is a terminal command: it records the request and ends the session.',
891
+ 'The dispatcher checks the ids against the ticket source. Accepted, they are',
892
+ "added to the build's ticket as blockers and the build waits without holding",
893
+ 'a capacity slot, keeping its branch and workspace. Refused (an unknown id,',
894
+ "the build's own ticket, or an already completed ticket), nothing is written",
895
+ 'and this phase re-runs with the reason as guidance. The dispatcher ends an',
896
+ 'accepted wait on its first tick after every named ticket completes; a',
897
+ 'rejected or deleted ticket raises an ordinary escalation instead, and an',
898
+ "operator may end the wait early with 'ab answer'.",
899
+ "When the wait ends the build first restacks onto its target's current head",
900
+ 'if the target moved, so the resumed phase sees the merged blockers (a',
901
+ 'conflicting restack is reconciled first); the phase then resumes with',
902
+ 'guidance naming what it waited on. In implement the command requires a',
903
+ "clean worktree and first publishes the build's commits; a failed push",
904
+ 'writes nothing. A build holds one wait at a time: while another',
905
+ "session's wait is pending or open, this command is refused and writes",
906
+ 'nothing. Every phase ends with exactly one terminal command (D5).',
907
+ ]),
908
+ },
847
909
  {
848
910
  name: 'harvest',
849
911
  audience: 'ai',
@@ -12,7 +12,7 @@ export async function abLandings(opts: StatusOpts): Promise<void> {
12
12
  else
13
13
  for (const entry of entries)
14
14
  opts.stdout(
15
- `${entry.slug} → ${entry.target.ticket?.id ?? entry.target.branch ?? treeVocabulary.root} · ${entry.branch ?? 'unknown branch'} · ${entry.reason} · ${treeVocabulary.verify} ${entry.verification.results.map((r) => `${r.step}:${r.outcome}`).join(', ') || 'no steps'}${entry.kind === 'node' ? ` · ${treeVocabulary.children} ${entry.children?.length ?? 'unknown'} (${entry.completeness})` : ''}`,
15
+ `${entry.slug} → ${entry.target.ticket?.id ?? entry.target.branch ?? treeVocabulary.root} · ${entry.branch ?? 'unknown branch'} · ${entry.reason} · ${treeVocabulary.verify} ${entry.verification.results.map((r) => `${r.step}:${r.outcome}`).join(', ') || 'no steps'}${entry.kind === 'node' ? ` · ${treeVocabulary.children} ${entry.children?.length ?? 'unknown'} (${entry.completeness})` : ''} · ${treeVocabulary.head} ${entry.currentHead ?? 'unknown'}${entry.consentedHead ? ` · ${treeVocabulary.consentedAt} ${entry.consentedHead}` : ''}`,
16
16
  )
17
17
  })
18
18
  }
@@ -9,7 +9,7 @@ import { withSessionlessStore } from './store-opening'
9
9
  import { abLandings } from './landings'
10
10
  import { readBuildFacts } from '../store/reduced-reads'
11
11
  import { preparePinnedAssets } from '../store/ticket-assets'
12
- import type { PinnedAsset } from '../events/payloads'
12
+ import { abortDestinationSchema, type PinnedAsset } from '../events/payloads'
13
13
  import { abConnect, abDisconnect } from './connect'
14
14
  /**
15
15
  * `ab` — the only channel between agents and the store, and the enforcement
@@ -33,7 +33,12 @@ import { spawnExec, type Exec } from '../ports/workspace/git-worktree'
33
33
  import type { IdSource } from '../ids'
34
34
  import { artifactDownload, artifactDownloadStream, artifactGet, artifactPut } from './artifact'
35
35
  import { multiFlag, parseArgs, stringFlag, type ParsedArgs } from './args'
36
- import { abBuildControl, type BuildControlAction, type BuildControlResult } from './build-control'
36
+ import {
37
+ abBuildControl,
38
+ parseConsentHead,
39
+ type BuildControlAction,
40
+ type BuildControlResult,
41
+ } from './build-control'
37
42
  import {
38
43
  abBulkControl,
39
44
  bulkControlLines,
@@ -63,7 +68,7 @@ import { abWatch, WATCH_USAGE } from './watch'
63
68
  import { abWait, WAIT_USAGE } from './wait'
64
69
  import { abMcp, AB_MCP_USAGE } from './mcp'
65
70
  import type { StoreOpener } from './store-opening'
66
- import { done, escalate, verdict } from './terminals'
71
+ import { done, escalate, verdict, waitOn } from './terminals'
67
72
  import { abTicket, lazyTicketSource, openTicketSource } from './ticket'
68
73
  import { checkUpgradeCompatibility, type CompatibilityFetch } from './upgrade-compatibility'
69
74
  import { abUpgrade, type ResolveConflict } from './upgrade'
@@ -278,6 +283,8 @@ export function buildControlConfirmation(result: BuildControlResult): string {
278
283
  'auto-merge-on': 'auto-merge requested',
279
284
  'auto-merge-off': 'auto-merge cancelled',
280
285
  }
286
+ if (result.event.type === 'build.abort-requested')
287
+ return `build ${result.slug}: abort requested; ticket returns to ${result.event.payload.to ?? 'triage'}`
281
288
  return `build ${result.slug}: ${outcome[result.command]}`
282
289
  }
283
290
  case 'answered': {
@@ -1154,13 +1161,24 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
1154
1161
  }
1155
1162
 
1156
1163
  case 'abort': {
1157
- const usage = 'usage: ab abort <slug> [--store <ref>]'
1158
- const parsed = parseArgs(rest, { store: 'value' }, usage)
1164
+ const usage = 'usage: ab abort <slug> [--to triage|ready] [--reason <text>] [--store <ref>]'
1165
+ const parsed = parseArgs(rest, { store: 'value', to: 'value', reason: 'value' }, usage)
1159
1166
  if (parsed.positionals.length !== 1) throw new Error(usage)
1167
+ const to = stringFlag(parsed, 'to')
1168
+ const destination = abortDestinationSchema.safeParse(to)
1169
+ if (to !== undefined && !destination.success)
1170
+ throw new Error(
1171
+ `--to must be one of: ${abortDestinationSchema.options.join(', ')} — ${usage}`,
1172
+ )
1173
+ const reason = stringFlag(parsed, 'reason')
1160
1174
  await runBuildControl(
1161
1175
  deps,
1162
1176
  parsed.positionals[0]!,
1163
- { kind: 'abort' },
1177
+ {
1178
+ kind: 'abort',
1179
+ ...(destination.success ? { to: destination.data } : {}),
1180
+ ...(reason !== undefined ? { reason } : {}),
1181
+ },
1164
1182
  stringFlag(parsed, 'store'),
1165
1183
  )
1166
1184
  return 0
@@ -1192,13 +1210,29 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
1192
1210
  case 'merge':
1193
1211
  case 'land': {
1194
1212
  if (command === 'land') stderr('ab land is deprecated; use ab merge')
1195
- const usage = `usage: ab ${command} <slug> [--store <ref>]`
1196
- const parsed = parseArgs(rest, { store: 'value' }, usage)
1213
+ if (command === 'hold') {
1214
+ const usage = 'usage: ab hold <slug> [--store <ref>]'
1215
+ const parsed = parseArgs(rest, { store: 'value' }, usage)
1216
+ if (parsed.positionals.length !== 1) throw new Error(usage)
1217
+ await runBuildControl(
1218
+ deps,
1219
+ parsed.positionals[0]!,
1220
+ { kind: 'hold' },
1221
+ stringFlag(parsed, 'store'),
1222
+ )
1223
+ return 0
1224
+ }
1225
+ const usage = `usage: ab ${command} <slug> [--head <sha>] [--store <ref>]`
1226
+ const parsed = parseArgs(rest, { store: 'value', head: 'value' }, usage)
1197
1227
  if (parsed.positionals.length !== 1) throw new Error(usage)
1228
+ const headFlag = stringFlag(parsed, 'head')
1229
+ const head = headFlag === undefined ? undefined : parseConsentHead(headFlag)
1230
+ if (headFlag !== undefined && head === undefined)
1231
+ throw new Error(`--head must be a nonblank commit SHA — ${usage}`)
1198
1232
  await runBuildControl(
1199
1233
  deps,
1200
1234
  parsed.positionals[0]!,
1201
- { kind: command === 'merge' ? 'land' : command },
1235
+ head === undefined ? { kind: 'land' } : { kind: 'land', head },
1202
1236
  stringFlag(parsed, 'store'),
1203
1237
  )
1204
1238
  return 0
@@ -1656,6 +1690,23 @@ async function dispatch(argv: string[], deps: SessionlessCliDeps): Promise<numbe
1656
1690
  return 0
1657
1691
  }
1658
1692
 
1693
+ case 'wait-on': {
1694
+ const usage = 'usage: ab wait-on <ticket-id>... --reason <text>'
1695
+ const parsed = parseArgs(rest, { reason: 'value' }, usage)
1696
+ if (parsed.positionals.length === 0) throw new Error(usage)
1697
+ const reason = stringFlag(parsed, 'reason')
1698
+ if (reason === undefined) throw new Error("'ab wait-on' requires --reason <text>")
1699
+ const session = requireSession(command, deps)
1700
+ const event = await waitOn(session, { tickets: parsed.positionals, reason })
1701
+ stdout(
1702
+ `wait requested on ${event.payload.tickets.join(', ')} (${event.payload.id}); ` +
1703
+ 'this session is complete. The dispatcher checks the tickets: if it accepts, the ' +
1704
+ 'build waits without a slot; if it refuses, this phase re-runs with the reason in ' +
1705
+ 'its guidance.',
1706
+ )
1707
+ return 0
1708
+ }
1709
+
1659
1710
  default: {
1660
1711
  stderr(`unknown command "${command}"\n\n${renderTopLevelHelp()}`)
1661
1712
  return 1
@@ -395,6 +395,16 @@ export async function settlePendingPublication(
395
395
  })
396
396
  return
397
397
  }
398
+ if (request.payload.operation === 'wait') {
399
+ // The wait's declaration follows its request; the dispatcher enters the
400
+ // wait only after this completion fact.
401
+ await deps.store.append(slug, {
402
+ actor: DISPATCHER,
403
+ type: 'wait.published',
404
+ payload: { id: request.payload.id, sha: request.payload.sha },
405
+ })
406
+ return
407
+ }
398
408
 
399
409
  const description = await deps.store.getArtifact(
400
410
  slug,