@defrex/autobuild 1.5.0 → 1.7.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 (126) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +192 -24
  3. package/docs/agent-runtimes.md +1 -1
  4. package/docs/answering-blocked-builds.md +7 -4
  5. package/docs/architecture.md +100 -32
  6. package/docs/configuration-overview.md +10 -0
  7. package/docs/configuration.md +340 -10
  8. package/docs/dispatcher.md +2 -2
  9. package/docs/forges.md +1 -0
  10. package/docs/glossary.md +1 -1
  11. package/docs/operating.md +1 -1
  12. package/docs/operator-api.md +33 -10
  13. package/docs/operator-surfaces.md +6 -3
  14. package/docs/plugin-authoring.md +48 -6
  15. package/docs/remote-store-protocol.md +33 -10
  16. package/docs/restacking.md +16 -7
  17. package/docs/ticket-sources.md +34 -6
  18. package/docs/tickets.md +7 -1
  19. package/docs/troubleshooting.md +1 -1
  20. package/docs/workspaces.md +1 -1
  21. package/package.json +3 -3
  22. package/packages/core/src/cli/attention.ts +3 -0
  23. package/packages/core/src/cli/binary-direct.ts +1 -0
  24. package/packages/core/src/cli/dashboard/model.ts +14 -4
  25. package/packages/core/src/cli/dashboard/poll.ts +14 -0
  26. package/packages/core/src/cli/dashboard/render.ts +3 -0
  27. package/packages/core/src/cli/dispatch-frontend.ts +10 -14
  28. package/packages/core/src/cli/dispatch-preflight.ts +5 -1
  29. package/packages/core/src/cli/dispatch-repository-feed.ts +145 -109
  30. package/packages/core/src/cli/dispatch-tickets.ts +47 -0
  31. package/packages/core/src/cli/dispatch-upgrade-controller.ts +3 -0
  32. package/packages/core/src/cli/dispatch.ts +377 -101
  33. package/packages/core/src/cli/help.ts +15 -6
  34. package/packages/core/src/cli/init-validation.ts +14 -1
  35. package/packages/core/src/cli/repo-lease.ts +225 -0
  36. package/packages/core/src/cli/repository-status.ts +40 -3
  37. package/packages/core/src/cli/status.ts +21 -13
  38. package/packages/core/src/cli/ticket.ts +22 -4
  39. package/packages/core/src/cli/wait.ts +4 -1
  40. package/packages/core/src/cli/watch.ts +17 -4
  41. package/packages/core/src/config/live.ts +4 -0
  42. package/packages/core/src/config/profiles.ts +96 -0
  43. package/packages/core/src/config/ready-assignee.ts +43 -11
  44. package/packages/core/src/config/roles.ts +33 -10
  45. package/packages/core/src/config/schema.ts +204 -26
  46. package/packages/core/src/events/catalog.ts +2 -0
  47. package/packages/core/src/events/compatibility.ts +3 -1
  48. package/packages/core/src/events/forge-degradation-policy.ts +16 -2
  49. package/packages/core/src/events/payloads.ts +23 -0
  50. package/packages/core/src/events/policy.ts +3 -0
  51. package/packages/core/src/events/repository.ts +19 -0
  52. package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +267 -352
  53. package/packages/core/src/kernel/build-creation.ts +29 -0
  54. package/packages/core/src/kernel/dispatch-capacity.ts +134 -30
  55. package/packages/core/src/kernel/engine.ts +13 -6
  56. package/packages/core/src/kernel/forge-health.ts +47 -0
  57. package/packages/core/src/kernel/generators/build-log.ts +9 -0
  58. package/packages/core/src/kernel/guarded-forge.ts +76 -18
  59. package/packages/core/src/kernel/incremental-fixtures.ts +1 -0
  60. package/packages/core/src/kernel/janitor-failure.ts +85 -5
  61. package/packages/core/src/kernel/leaf-restack-state.ts +4 -2
  62. package/packages/core/src/kernel/log-index.ts +1 -1
  63. package/packages/core/src/kernel/node-landing.ts +2 -1
  64. package/packages/core/src/kernel/node-parent.ts +2 -0
  65. package/packages/core/src/kernel/read-facts.ts +9 -1
  66. package/packages/core/src/kernel/reducer-registry.ts +6 -1
  67. package/packages/core/src/kernel/reducer.ts +75 -4
  68. package/packages/core/src/kernel/ticket-preparation.ts +15 -8
  69. package/packages/core/src/operator/protocol.ts +10 -0
  70. package/packages/core/src/operator/query.ts +16 -13
  71. package/packages/core/src/operator/registry.ts +25 -5
  72. package/packages/core/src/operator/sandbox-host.ts +3 -0
  73. package/packages/core/src/operator/tickets.ts +15 -3
  74. package/packages/core/src/plugin-sdk/index.ts +4 -0
  75. package/packages/core/src/ports/forge/create.ts +6 -0
  76. package/packages/core/src/ports/forge/github-transport.ts +40 -3
  77. package/packages/core/src/ports/forge/github.ts +12 -1
  78. package/packages/core/src/ports/forge/workspace-ancestry.ts +60 -0
  79. package/packages/core/src/ports/forge-failure.ts +31 -2
  80. package/packages/core/src/ports/runner/routing.ts +66 -5
  81. package/packages/core/src/ports/tickets/assignees.ts +54 -0
  82. package/packages/core/src/ports/tickets/contract.ts +164 -4
  83. package/packages/core/src/ports/tickets/create.ts +35 -7
  84. package/packages/core/src/ports/tickets/github-fake.ts +18 -2
  85. package/packages/core/src/ports/tickets/github.ts +247 -29
  86. package/packages/core/src/ports/tickets/hosted-index.ts +1 -0
  87. package/packages/core/src/ports/tickets/operations.ts +6 -1
  88. package/packages/core/src/ports/tickets/tree.ts +12 -2
  89. package/packages/core/src/ports/tickets/update.ts +6 -2
  90. package/packages/core/src/ports/types.ts +37 -3
  91. package/packages/core/src/ports/workspace/commit-preservation.ts +28 -12
  92. package/packages/core/src/ports/workspace/git-worktree.ts +3 -1
  93. package/packages/core/src/ports/workspace/harvest-execution.ts +4 -2
  94. package/packages/core/src/ports/workspace/vercel-sandbox.ts +12 -0
  95. package/packages/core/src/processes/build-child.ts +28 -7
  96. package/packages/core/src/processes/build-execution-state.ts +4 -1
  97. package/packages/core/src/processes/build-runner.ts +17 -2
  98. package/packages/core/src/processes/dispatcher.ts +329 -59
  99. package/packages/core/src/processes/execution-no-progress.ts +2 -0
  100. package/packages/core/src/processes/harvest-child.ts +8 -2
  101. package/packages/core/src/processes/harvest-execution-state.ts +104 -0
  102. package/packages/core/src/processes/harvest-runner.ts +251 -17
  103. package/packages/core/src/processes/repo-view.ts +2 -0
  104. package/packages/core/src/scenarios/harness.ts +160 -36
  105. package/packages/core/src/store/reduced-reads.ts +10 -0
  106. package/packages/core/src/store/reducer-value-shapes.json +3339 -2898
  107. package/packages/core/src/store/remote/client.ts +21 -8
  108. package/packages/core/src/store/remote/index.ts +4 -0
  109. package/packages/core/src/store/remote/protocol.ts +7 -0
  110. package/packages/core/src/store/remote/released-clients.json +22 -0
  111. package/packages/core/src/store/remote/released-reducer-values/1.6.0.json +27173 -0
  112. package/packages/core/src/store/remote/released-reducer-values/1.7.0.json +27366 -0
  113. package/packages/core/src/store/remote/released-reducer-values/index.ts +4 -0
  114. package/packages/core/src/store/repo-state-events.ts +1 -0
  115. package/packages/core/src/store/types.ts +11 -0
  116. package/packages/core/src/testing/dispatch-read-budget.ts +84 -58
  117. package/packages/core/src/testing/index.ts +2 -0
  118. package/packages/core/src/testing/reduced-read-budget.ts +411 -11
  119. package/skills/guide/SKILL.md +166 -35
  120. package/skills/guide/references/operator-api.md +33 -10
  121. package/skills/guide/references/plugin-authoring.md +48 -6
  122. package/skills/guide/references/remote-store-protocol.md +33 -10
  123. package/skills/guide/references/restacking.md +16 -7
  124. package/skills/operate/SKILL.md +79 -14
  125. package/skills/tickets/SKILL.md +22 -4
  126. package/templates/hosted-service/package.json +2 -2
@@ -5,6 +5,7 @@ import { createForge } from '../ports/forge/create'
5
5
  import { compatibleTicketSource, type TicketTreeEntry } from '../ports/tickets/tree'
6
6
  import { formatIssueLinks, parseIssueLinkList } from '../ports/tickets/issue-links'
7
7
  import { parsePriorityFlag, ticketPriority } from '../ports/tickets/priority'
8
+ import { creationAssignees, parseAssigneesFlag } from '../ports/tickets/assignees'
8
9
  import { parseIssueId, rejectedStateOf } from '../ports/tickets/github-issues'
9
10
  import { readBuildDigests, readBuildFacts } from '../store/reduced-reads'
10
11
  import type { TicketRef } from '../ontology'
@@ -106,6 +107,9 @@ export interface TicketCreateOpts extends TicketCommandOpts {
106
107
  issueLinks?: import('../ports/types').IssueLink[]
107
108
  /** Dispatch class; a source without priority support refuses `urgent`. */
108
109
  priority?: import('../ports/types').TicketPriority
110
+ /** Usernames or `me`; replaces the `[tickets].createAssignee` default, and
111
+ * an explicit [] creates an unassigned ticket. Sources without support refuse. */
112
+ assignees?: string[]
109
113
  }
110
114
 
111
115
  export interface TicketUpdateOpts extends TicketCommandOpts {
@@ -122,6 +126,8 @@ export interface TicketUpdateOpts extends TicketCommandOpts {
122
126
  issueLinks?: import('../ports/types').IssueLink[]
123
127
  /** `normal` removes urgency; a source without priority support refuses `urgent`. */
124
128
  priority?: import('../ports/types').TicketPriority
129
+ /** Complete assignee replacement (usernames or `me`). An explicit [] clears. */
130
+ assignees?: string[]
125
131
  }
126
132
 
127
133
  export interface TicketBlockerOpts extends TicketCommandOpts {
@@ -368,6 +374,7 @@ function ticketDetail(
368
374
  lines.push(` blocked by: ${blockers.join(', ')}`)
369
375
  }
370
376
  if (ticket.issueLinks?.length) lines.push(` issues: ${formatIssueLinks(ticket.issueLinks)}`)
377
+ if (ticket.assignees?.length) lines.push(` assignees: ${ticket.assignees.join(', ')}`)
371
378
  if (ticket.ref.url !== undefined) lines.push(` url: ${ticket.ref.url}`)
372
379
  if (assets.length > 0) lines.push(' assets:', ...assets.map(assetLine))
373
380
  lines.push(' body:')
@@ -386,7 +393,8 @@ function emitTicketJson(opts: TicketCommandOpts, ticket: Ticket): void {
386
393
  export async function abTicketCreate(opts: TicketCreateOpts): Promise<void> {
387
394
  // Read the complete body before constructing or calling a mutable source.
388
395
  const body = await readBody(opts.bodyFile)
389
- const { source } = await resolveTicketCommand(opts, 'create')
396
+ const { source, config } = await resolveTicketCommand(opts, 'create')
397
+ const assignees = creationAssignees(config.tickets, opts.assignees)
390
398
 
391
399
  const ticket = await createTicket(
392
400
  source,
@@ -399,6 +407,7 @@ export async function abTicketCreate(opts: TicketCreateOpts): Promise<void> {
399
407
  ...(opts.blockedBy !== undefined ? { blockedBy: opts.blockedBy } : {}),
400
408
  ...(opts.issueLinks !== undefined ? { issueLinks: opts.issueLinks } : {}),
401
409
  ...(opts.priority !== undefined ? { priority: opts.priority } : {}),
410
+ ...(assignees !== undefined ? { assignees } : {}),
402
411
  ...(opts.state !== undefined ? { state: opts.state } : {}),
403
412
  },
404
413
  {
@@ -418,8 +427,9 @@ export async function abTicketCreate(opts: TicketCreateOpts): Promise<void> {
418
427
  : ''
419
428
  const issues = ticket.issueLinks?.length ? ` — ${formatIssueLinks(ticket.issueLinks)}` : ''
420
429
  const urgent = ticket.priority === 'urgent' ? ' — urgent' : ''
430
+ const assigned = ticket.assignees?.length ? ` — assigned to ${ticket.assignees.join(', ')}` : ''
421
431
  opts.stdout(
422
- `ticket created: ${ticket.ref.source}:${ticket.ref.id} (${state})${urgent}${blockers}${issues}${url}`,
432
+ `ticket created: ${ticket.ref.source}:${ticket.ref.id} (${state})${urgent}${assigned}${blockers}${issues}${url}`,
423
433
  )
424
434
  }
425
435
 
@@ -434,6 +444,7 @@ export async function abTicketUpdate(opts: TicketUpdateOpts): Promise<void> {
434
444
  ...(opts.labels !== undefined ? { labels: [...opts.labels] } : {}),
435
445
  ...(opts.issueLinks !== undefined ? { issueLinks: [...opts.issueLinks] } : {}),
436
446
  ...(opts.priority !== undefined ? { priority: opts.priority } : {}),
447
+ ...(opts.assignees !== undefined ? { assignees: [...opts.assignees] } : {}),
437
448
  }
438
449
  const updated =
439
450
  patch.target === undefined
@@ -931,9 +942,9 @@ export async function abTicketStateCreate(opts: TicketStateCreateOpts): Promise<
931
942
  }
932
943
 
933
944
  const CREATE_USAGE =
934
- 'usage: ab ticket create <title> --body <file> [--state <state>] [--labels a,b] [--blocked-by id,id] [--issues N[:refs],...] [--priority urgent|normal] [--kind work|node] [--target <id> | --no-target] [--json] (§8.8)'
945
+ 'usage: ab ticket create <title> --body <file> [--state <state>] [--labels a,b] [--blocked-by id,id] [--issues N[:refs],...] [--priority urgent|normal] [--assignees a,b] [--kind work|node] [--target <id> | --no-target] [--json] (§8.8)'
935
946
  const UPDATE_USAGE =
936
- 'usage: ab ticket update <id> [--kind work|node] [--target <id> | --no-target] [--title <title>] [--body <file>] [--labels a,b] [--issues N[:refs],...] [--priority urgent|normal] [--expected-revision <opaque>] [--json] (§8.8)'
947
+ 'usage: ab ticket update <id> [--kind work|node] [--target <id> | --no-target] [--title <title>] [--body <file>] [--labels a,b] [--issues N[:refs],...] [--priority urgent|normal] [--assignees a,b] [--expected-revision <opaque>] [--json] (§8.8)'
937
948
  const BLOCK_USAGE =
938
949
  'usage: ab ticket block <id> <blocker-id[,blocker-id...]> [--expected-revision <opaque>] [--json] (§8.8)'
939
950
  const UNBLOCK_USAGE =
@@ -1065,6 +1076,7 @@ export async function abTicket(argv: string[], opts: TicketCliOpts): Promise<voi
1065
1076
  'blocked-by': 'value',
1066
1077
  issues: 'value',
1067
1078
  priority: 'value',
1079
+ assignees: 'value',
1068
1080
  json: 'boolean',
1069
1081
  },
1070
1082
  TICKET_USAGE,
@@ -1080,6 +1092,7 @@ export async function abTicket(argv: string[], opts: TicketCliOpts): Promise<voi
1080
1092
  const blockedBy = stringFlag(parsed, 'blocked-by')
1081
1093
  const issues = stringFlag(parsed, 'issues')
1082
1094
  const priority = stringFlag(parsed, 'priority')
1095
+ const assignees = stringFlag(parsed, 'assignees')
1083
1096
  await abTicketCreate({
1084
1097
  ...opts,
1085
1098
  ...metadataFlags(parsed),
@@ -1090,6 +1103,7 @@ export async function abTicket(argv: string[], opts: TicketCliOpts): Promise<voi
1090
1103
  ...(blockedBy !== undefined ? { blockedBy: commaList(blockedBy) } : {}),
1091
1104
  ...(issues !== undefined ? { issueLinks: parseIssueLinkList(issues) } : {}),
1092
1105
  ...(priority !== undefined ? { priority: parsePriorityFlag(priority) } : {}),
1106
+ ...(assignees !== undefined ? { assignees: parseAssigneesFlag(assignees) } : {}),
1093
1107
  json: parsed.flags.has('json'),
1094
1108
  })
1095
1109
  return
@@ -1114,6 +1128,7 @@ export async function abTicket(argv: string[], opts: TicketCliOpts): Promise<voi
1114
1128
  labels: 'value',
1115
1129
  issues: 'value',
1116
1130
  priority: 'value',
1131
+ assignees: 'value',
1117
1132
  'expected-revision': 'value',
1118
1133
  json: 'boolean',
1119
1134
  },
@@ -1126,6 +1141,7 @@ export async function abTicket(argv: string[], opts: TicketCliOpts): Promise<voi
1126
1141
  'labels',
1127
1142
  'issues',
1128
1143
  'priority',
1144
+ 'assignees',
1129
1145
  'kind',
1130
1146
  'target',
1131
1147
  'no-target',
@@ -1138,6 +1154,7 @@ export async function abTicket(argv: string[], opts: TicketCliOpts): Promise<voi
1138
1154
  const labels = stringFlag(parsed, 'labels')
1139
1155
  const issues = stringFlag(parsed, 'issues')
1140
1156
  const priority = stringFlag(parsed, 'priority')
1157
+ const assignees = stringFlag(parsed, 'assignees')
1141
1158
  if (bodyFile !== undefined && bodyFile.trim() === '') {
1142
1159
  throw new Error(TICKET_USAGE)
1143
1160
  }
@@ -1151,6 +1168,7 @@ export async function abTicket(argv: string[], opts: TicketCliOpts): Promise<voi
1151
1168
  ...(labels !== undefined ? { labels: commaList(labels) } : {}),
1152
1169
  ...(issues !== undefined ? { issueLinks: parseIssueLinkList(issues) } : {}),
1153
1170
  ...(priority !== undefined ? { priority: parsePriorityFlag(priority) } : {}),
1171
+ ...(assignees !== undefined ? { assignees: parseAssigneesFlag(assignees) } : {}),
1154
1172
  json: parsed.flags.has('json'),
1155
1173
  })
1156
1174
  return
@@ -465,6 +465,7 @@ export async function abWait(opts: AbWaitOpts): Promise<number> {
465
465
  condition === 'consent' ||
466
466
  (condition === 'attention' &&
467
467
  event.type !== 'phase.deferral-escalated' &&
468
+ event.type !== 'build.janitor-escalated' &&
468
469
  event.type !== 'escalation.raised')
469
470
  ? consentReady(seed, now())
470
471
  : null
@@ -472,7 +473,8 @@ export async function abWait(opts: AbWaitOpts): Promise<number> {
472
473
  consent ??
473
474
  (condition === 'attention' &&
474
475
  event.type !== 'escalation.raised' &&
475
- event.type !== 'phase.deferral-escalated'
476
+ event.type !== 'phase.deferral-escalated' &&
477
+ event.type !== 'build.janitor-escalated'
476
478
  ? mergeDecisionFromFacts(state, seed.deferral, now())
477
479
  : null)
478
480
  if (consent) deliveredAttention.add(consentIdentity(event.build, consent.position))
@@ -512,6 +514,7 @@ export async function abWait(opts: AbWaitOpts): Promise<number> {
512
514
  if (
513
515
  event.type === 'escalation.raised' ||
514
516
  event.type === 'phase.deferral-escalated' ||
517
+ event.type === 'build.janitor-escalated' ||
515
518
  event.type === 'integration.landed' ||
516
519
  event.type === 'integration.verification-failed' ||
517
520
  event.type === 'node.item-conflicted' ||
@@ -6,6 +6,7 @@ import { randomUUID } from 'node:crypto'
6
6
  import { OPERATOR_HEARTBEAT_MS, operatorIdentitySchema } from '../store/operator-presence'
7
7
  import { consentReady, consentIdentity, type ConsentReady } from './attention'
8
8
  import { formatReadinessFailure } from '../ports/forge/readiness'
9
+ import { abandonedPreparationDiagnostic } from '../kernel/ticket-preparation'
9
10
  import { readDispatchUpgrade, readBuildDigests } from '../store/reduced-reads'
10
11
  import { readBuildStreamSeed, readRepositoryAttention } from '../store/reduced-reads'
11
12
  import { buildStreamSeedReducer, type BuildStreamSeed } from '../kernel/read-facts'
@@ -112,6 +113,7 @@ const TERMINAL_STATUSES: readonly BuildStatus[] = ['done', 'aborted']
112
113
  export const BUILD_ATTENTION_EVENTS = [
113
114
  'target.rewritten',
114
115
  'build.janitor-failing',
116
+ 'build.janitor-escalated',
115
117
  'build.compatibility-deferred',
116
118
  'escalation.raised',
117
119
  'phase.deferral-escalated',
@@ -457,11 +459,14 @@ export function summarizeEvent(event: AbEvent | RepositoryEvent, state: BuildSta
457
459
  return `Account credentials recovered: ${JSON.stringify(event.payload.name)}`
458
460
  case 'dispatcher.forge-recovered':
459
461
  return `Forge recovered: ${event.payload.forge}`
462
+ case 'forge.credential-limited':
463
+ return `Forge request limited for ${event.payload.process} (${event.payload.credential}${event.payload.missingCredential ? `: ${singleLine(event.payload.missingCredential)}` : ''}); reset ${event.payload.resetAt}; dispatcher forge work continues`
460
464
  case 'dispatcher.kernel-git-unavailable':
461
465
  return `Kernel Git unavailable (${event.payload.executable}): ${singleLine(event.payload.detail)}`
462
466
  case 'dispatcher.kernel-git-recovered':
463
467
  return `Kernel Git recovered (${event.payload.executable})`
464
468
  case 'phase.deferral-escalated':
469
+ case 'build.janitor-escalated':
465
470
  case 'escalation.raised':
466
471
  return `${event.payload.id}: ${singleLine(event.payload.question)}`
467
472
  case 'build.compatibility-deferred':
@@ -520,13 +525,21 @@ export function summarizeEvent(event: AbEvent | RepositoryEvent, state: BuildSta
520
525
  return `dispatcher config rejected: ${singleLine(event.payload.error)}`
521
526
  case 'dispatcher.harvest-runner-failed':
522
527
  return `harvest runner failed: ${singleLine(event.payload.error)}`
523
- default: {
524
- const compact = singleLine(JSON.stringify(event.payload))
525
- return compact.length > SUMMARY_MAX ? `${compact.slice(0, SUMMARY_MAX - 1)}…` : compact
526
- }
528
+ case 'ticket-preparation.resolved':
529
+ if (event.payload.outcome === 'abandoned') {
530
+ return singleLine(abandonedPreparationDiagnostic(event.payload, event.payload.reason))
531
+ }
532
+ return summarizePayload(event.payload)
533
+ default:
534
+ return summarizePayload(event.payload)
527
535
  }
528
536
  }
529
537
 
538
+ function summarizePayload(payload: unknown): string {
539
+ const compact = singleLine(JSON.stringify(payload))
540
+ return compact.length > SUMMARY_MAX ? `${compact.slice(0, SUMMARY_MAX - 1)}…` : compact
541
+ }
542
+
530
543
  /** The human form: one line, timestamp first, no ANSI anywhere. */
531
544
  export function renderWatchLine(
532
545
  event: AbEvent | RepositoryEvent,
@@ -29,6 +29,7 @@ export const CONFIG_RELOAD_CLASSIFICATION = {
29
29
  verify: 'hot',
30
30
  finalize: 'hot',
31
31
  roles: 'hot',
32
+ profiles: 'hot',
32
33
  accounts: 'hot',
33
34
  policy: 'hot',
34
35
  orchestrator: 'restart',
@@ -37,6 +38,7 @@ export const CONFIG_RELOAD_CLASSIFICATION = {
37
38
  readyLabels: 'hot',
38
39
  readyState: 'hot',
39
40
  readyAssignee: 'hot',
41
+ createAssignee: 'hot',
40
42
  teamKey: 'restart',
41
43
  claimedState: 'restart',
42
44
  createState: 'restart',
@@ -217,6 +219,7 @@ export class LiveConfig {
217
219
  startup.roles,
218
220
  startup.policy.sessionBudgetSeconds,
219
221
  startup.accounts,
222
+ startup.profiles,
220
223
  ),
221
224
  revision: 0,
222
225
  }
@@ -299,6 +302,7 @@ export class LiveConfig {
299
302
  config.roles,
300
303
  config.policy.sessionBudgetSeconds,
301
304
  config.accounts,
305
+ config.profiles,
302
306
  )
303
307
  } catch (error) {
304
308
  const message = error instanceof Error ? error.message : String(error)
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Label-selected role profiles (SPEC §9).
3
+ *
4
+ * A `[profiles.<name>]` table names one ticket label and any number of role
5
+ * entries. A build whose ticket carries that label at claim records the
6
+ * profile on `build.created`; every later session of that build resolves its
7
+ * role through the profile's overlay of the CURRENT configuration.
8
+ *
9
+ * The overlay is a synthetic roles map: a profile entry's declared fields sit
10
+ * over `[roles.<role>]` (or over nothing when the repository does not declare
11
+ * the role), and the resolver then merges each field over `[roles.default]`
12
+ * exactly as it does for repository roles. An omitted field therefore falls
13
+ * back to `[roles.<role>]`, then `[roles.default]`; a declared `alternates`
14
+ * list, including `[]`, replaces the inherited list.
15
+ *
16
+ * Everything here is pure and in memory. Selection reads only the labels the
17
+ * ready scan already returned.
18
+ */
19
+ import { defineEntry } from '../open-map'
20
+ import { displayName } from './roles'
21
+ import type { RoleConfig } from './schema'
22
+
23
+ export interface ProfileConfig {
24
+ label: string
25
+ roles: Record<string, RoleConfig>
26
+ }
27
+
28
+ /** Labels match case-insensitively after trimming, as forge and Linear labels do. */
29
+ export function normalizeProfileLabel(label: string): string {
30
+ return label.trim().toLowerCase()
31
+ }
32
+
33
+ /**
34
+ * The repository roles with one profile's entries overlaid. Keys stay intact
35
+ * end to end (`__proto__` included), and only fields an entry actually
36
+ * declares replace the repository role's value.
37
+ */
38
+ export function profileRoles<T extends object>(
39
+ roles: Record<string, T>,
40
+ entries: Record<string, T>,
41
+ ): Record<string, T> {
42
+ const overlaid: Record<string, T> = Object.create(null)
43
+ for (const key of Object.keys(roles)) defineEntry(overlaid, key, roles[key]!)
44
+ for (const key of Object.keys(entries)) {
45
+ const base = (Object.hasOwn(roles, key) ? roles[key]! : {}) as T
46
+ const merged = Object.create(null) as T
47
+ for (const [field, value] of Object.entries(base))
48
+ if (value !== undefined) defineEntry(merged as Record<string, unknown>, field, value)
49
+ for (const [field, value] of Object.entries(entries[key]!))
50
+ if (value !== undefined) defineEntry(merged as Record<string, unknown>, field, value)
51
+ defineEntry(overlaid, key, merged)
52
+ }
53
+ return overlaid
54
+ }
55
+
56
+ export type ProfileSelection =
57
+ | { kind: 'none' }
58
+ | { kind: 'selected'; name: string }
59
+ | { kind: 'conflict'; matches: { name: string; label: string }[] }
60
+
61
+ /** Which configured profile a ticket's labels select. Two or more distinct
62
+ * profiles matching is a conflict: profiles never combine. */
63
+ export function selectProfile(
64
+ profiles: Record<string, { label: string }> | undefined,
65
+ labels: readonly string[] | undefined,
66
+ ): ProfileSelection {
67
+ if (profiles === undefined || labels === undefined || labels.length === 0) return { kind: 'none' }
68
+ const carried = new Set(labels.map(normalizeProfileLabel))
69
+ const matches: { name: string; label: string }[] = []
70
+ for (const name of Object.keys(profiles)) {
71
+ const label = profiles[name]!.label
72
+ if (normalizeProfileLabel(label).length === 0) continue
73
+ if (carried.has(normalizeProfileLabel(label))) matches.push({ name, label })
74
+ }
75
+ if (matches.length === 0) return { kind: 'none' }
76
+ if (matches.length === 1) return { kind: 'selected', name: matches[0]!.name }
77
+ matches.sort((left, right) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0))
78
+ return { kind: 'conflict', matches }
79
+ }
80
+
81
+ function andList(parts: readonly string[]): string {
82
+ if (parts.length <= 2) return parts.join(' and ')
83
+ return `${parts.slice(0, -1).join(', ')}, and ${parts[parts.length - 1]}`
84
+ }
85
+
86
+ /** The scan diagnostic for a ready ticket left unclaimed by conflicting labels. */
87
+ export function profileConflictDiagnostic(
88
+ ticketId: string,
89
+ matches: readonly { name: string; label: string }[],
90
+ ): string {
91
+ return (
92
+ `ticket ${ticketId}: labels ${andList(matches.map((m) => displayName(m.label)))} select ` +
93
+ `more than one profile (${matches.map((m) => displayName(m.name)).join(', ')}) — ` +
94
+ `remove all but one profile label to make it claimable`
95
+ )
96
+ }
@@ -1,7 +1,8 @@
1
1
  /**
2
- * `[tickets].readyAssignee` is a ticket-source capability. A source opts in
3
- * with `readyAssignee = true` on the constructed `TicketSource`; parse time
4
- * can only check the builtins, because plugins load after config parse, so the
2
+ * `[tickets].readyAssignee` and `[tickets].createAssignee` are ticket-source
3
+ * capabilities. A source opts in with `readyAssignee = true` (respectively
4
+ * `assignees = true`) on the constructed `TicketSource`; parse time can only
5
+ * check the builtins, because plugins load after config parse, so the
5
6
  * registry-aware seams (`createTicketSource` and `LiveConfig` reloads) enforce
6
7
  * the declaration for every source. The value forms below are the builtins'
7
8
  * own rules; a plugin source enforces its own.
@@ -30,18 +31,27 @@ export const LINEAR_READY_ASSIGNEE: ReadyAssigneeForm = {
30
31
  * placement, since older accounts predate the normalization rules; `ab init
31
32
  * --validate` proves the user can actually be assigned.
32
33
  */
33
- export const GITHUB_READY_ASSIGNEE: ReadyAssigneeForm = {
34
- accepts: (s) =>
35
- s === 'me' || (s.length <= 39 && /^[A-Za-z0-9][A-Za-z0-9-]*(?:_[A-Za-z0-9]{3,8})?$/.test(s)),
36
- message:
37
- '[tickets].readyAssignee must be "me" (the owner of the GitHub credential) or a GitHub username (e.g. "octocat", or a managed user\'s "mona_acme") for source = "github"',
34
+ export function githubAssigneeForm(key: 'readyAssignee' | 'createAssignee'): ReadyAssigneeForm {
35
+ return {
36
+ accepts: (s) =>
37
+ s === 'me' || (s.length <= 39 && /^[A-Za-z0-9][A-Za-z0-9-]*(?:_[A-Za-z0-9]{3,8})?$/.test(s)),
38
+ message: `[tickets].${key} must be "me" (the owner of the GitHub credential) or a GitHub username (e.g. "octocat", or a managed user's "mona_acme") for source = "github"`,
39
+ }
38
40
  }
39
41
 
42
+ export const GITHUB_READY_ASSIGNEE = githubAssigneeForm('readyAssignee')
43
+ export const GITHUB_CREATE_ASSIGNEE = githubAssigneeForm('createAssignee')
44
+
40
45
  export function readyAssigneeUnsupported(source: string, plugin?: string): string {
41
46
  const from = plugin !== undefined ? ` from plugin "${plugin}"` : ''
42
47
  return `[tickets].readyAssignee: ticket source "${source}"${from} cannot filter ready tickets by assignee — remove readyAssignee (selected source: "${source}")`
43
48
  }
44
49
 
50
+ export function createAssigneeUnsupported(source: string, plugin?: string): string {
51
+ const from = plugin !== undefined ? ` from plugin "${plugin}"` : ''
52
+ return `[tickets].createAssignee: ticket source "${source}"${from} cannot assign tickets — remove createAssignee (selected source: "${source}")`
53
+ }
54
+
45
55
  /** Refuse `readyAssignee` for a constructed source that does not declare it. */
46
56
  export function assertReadyAssigneeSupported(
47
57
  tickets: TicketsConfig,
@@ -52,6 +62,16 @@ export function assertReadyAssigneeSupported(
52
62
  throw new Error(readyAssigneeUnsupported(tickets.source, plugin))
53
63
  }
54
64
 
65
+ /** Refuse `createAssignee` for a constructed source that cannot store assignees. */
66
+ export function assertCreateAssigneeSupported(
67
+ tickets: TicketsConfig,
68
+ source: TicketSource,
69
+ plugin?: string,
70
+ ): void {
71
+ if (tickets.createAssignee !== undefined && source.assignees !== true)
72
+ throw new Error(createAssigneeUnsupported(tickets.source, plugin))
73
+ }
74
+
55
75
  /**
56
76
  * The reload check: synchronous and request-free, because `LiveConfig`
57
77
  * refreshes at the head of a dispatcher tick. It decides from what
@@ -64,10 +84,21 @@ export function assertReadyAssigneeAccepted(tickets: TicketsConfig, source: Tick
64
84
  if (refusal !== undefined) throw new Error(refusal)
65
85
  }
66
86
 
87
+ /** The `createAssignee` reload check, synchronous and request-free like
88
+ * `assertReadyAssigneeAccepted`. */
89
+ export function assertCreateAssigneeAccepted(tickets: TicketsConfig, source: TicketSource): void {
90
+ assertCreateAssigneeSupported(tickets, source)
91
+ if (tickets.createAssignee === undefined) return
92
+ const refusal = source.createAssigneeRefusal?.(tickets.createAssignee)
93
+ if (refusal !== undefined) throw new Error(refusal)
94
+ }
95
+
67
96
  /**
68
97
  * Dispatcher startup, before the loop: prepare whatever a later `"me"` needs,
69
- * whether or not `readyAssignee` is set, so no tick ever resolves it. A
70
- * preparation failure fails startup only when the configuration needs it.
98
+ * whether or not `readyAssignee` or `createAssignee` is set, so no tick ever
99
+ * resolves it (a harvest proposal filed under `createAssignee = "me"` reuses
100
+ * the prepared owner). A preparation failure fails startup only when the
101
+ * configuration needs it.
71
102
  */
72
103
  export async function prepareReadyAssigneeForDispatch(
73
104
  source: TicketSource,
@@ -77,10 +108,11 @@ export async function prepareReadyAssigneeForDispatch(
77
108
  try {
78
109
  await source.prepareReadyAssignee?.()
79
110
  } catch (error) {
80
- if (tickets.readyAssignee !== undefined) throw error
111
+ if (tickets.readyAssignee !== undefined || tickets.createAssignee !== undefined) throw error
81
112
  warn(
82
113
  `ticket source "${source.name}" could not prepare readyAssignee: ${error instanceof Error ? error.message : String(error)}`,
83
114
  )
84
115
  }
85
116
  assertReadyAssigneeAccepted(tickets, source)
117
+ assertCreateAssigneeAccepted(tickets, source)
86
118
  }
@@ -26,7 +26,8 @@ import { selectAccount, type SelectedAccount } from './accounts'
26
26
  * never requested on the other.
27
27
  */
28
28
  import { CORE_PHASES } from '../ontology'
29
- import type { Config } from './schema'
29
+ import { profileRoles } from './profiles'
30
+ import type { Config, RoleConfig } from './schema'
30
31
 
31
32
  // ── Vocabulary ───────────────────────────────────────────────────────────────
32
33
 
@@ -100,7 +101,8 @@ export interface RuntimeReferenceGroup {
100
101
  * bootstrap share one source of truth.
101
102
  */
102
103
  export function effectiveRuntimeReferences(
103
- config: Pick<Config, 'roles' | 'verify' | 'finalize'> & Partial<Pick<Config, 'accounts'>>,
104
+ config: Pick<Config, 'roles' | 'verify' | 'finalize'> &
105
+ Partial<Pick<Config, 'accounts' | 'profiles'>>,
104
106
  options: { includeUnusedAccounts?: boolean } = {},
105
107
  ): RuntimeReferenceGroup[] {
106
108
  const defaultSpec = config.roles.default ?? {}
@@ -130,12 +132,18 @@ export function effectiveRuntimeReferences(
130
132
  string,
131
133
  { references: Set<string>; models: Set<string>; usesRuntimeDefaultModel: boolean }
132
134
  >()
133
- const declaredSpec = (role: string, aliases: readonly string[] = []) => {
135
+ // MUST mirror the resolver's candidate walk (src/ports/runner/routing.ts).
136
+ // `selected` is the declared key that won, or undefined for the fallback.
137
+ const declaredSpec = (
138
+ roles: Record<string, RoleConfig>,
139
+ role: string,
140
+ aliases: readonly string[] = [],
141
+ ): { spec: RoleConfig; selected?: string } => {
134
142
  for (const key of [role, ...aliases]) {
135
- if (key === RESERVED_ROLE) return defaultSpec
136
- if (Object.hasOwn(config.roles, key)) return config.roles[key]!
143
+ if (key === RESERVED_ROLE) return { spec: defaultSpec }
144
+ if (Object.hasOwn(roles, key)) return { spec: roles[key]!, selected: key }
137
145
  }
138
- return defaultSpec
146
+ return { spec: defaultSpec }
139
147
  }
140
148
  const add = (
141
149
  runtime: string | undefined,
@@ -170,22 +178,37 @@ export function effectiveRuntimeReferences(
170
178
  grouped.set(runtime, group)
171
179
  }
172
180
 
173
- for (const route of routes) {
174
- const spec = declaredSpec(route.role, route.aliases)
181
+ const addRoute = (spec: RoleConfig, label: string) => {
175
182
  const runtime = spec.runtime ?? defaultSpec.runtime
176
183
  const model = spec.model ?? defaultSpec.model
177
- add(runtime, model, `${route.label} primary`, spec.account ?? defaultSpec.account)
184
+ add(runtime, model, `${label} primary`, spec.account ?? defaultSpec.account)
178
185
  const alternates = spec.alternates ?? defaultSpec.alternates ?? []
179
186
  alternates.forEach((alternate, index) => {
180
187
  add(
181
188
  alternate.runtime ?? runtime,
182
189
  alternate.model ?? model,
183
- `${route.label} alternate[${index}]`,
190
+ `${label} alternate[${index}]`,
184
191
  alternate.account ?? spec.account ?? defaultSpec.account,
185
192
  )
186
193
  })
187
194
  }
188
195
 
196
+ for (const route of routes)
197
+ addRoute(declaredSpec(config.roles, route.role, route.aliases).spec, route.label)
198
+
199
+ // A profile can select a runtime, model or account no repository route
200
+ // does. Only routes whose winning key is a profile entry add anything new.
201
+ const profiles = config.profiles ?? {}
202
+ for (const name of Object.keys(profiles)) {
203
+ const entries = profiles[name]!.roles
204
+ const overlaid = profileRoles(config.roles, entries)
205
+ for (const route of routes) {
206
+ const { spec, selected } = declaredSpec(overlaid, route.role, route.aliases)
207
+ if (selected === undefined || !Object.hasOwn(entries, selected)) continue
208
+ addRoute(spec, `profile ${displayName(name)} ${route.label}`)
209
+ }
210
+ }
211
+
189
212
  // Unused accounts still require their actual runtime for readiness.
190
213
  for (const [name, descriptor] of Object.entries(
191
214
  options.includeUnusedAccounts === false ? {} : (config.accounts ?? {}),