@defrex/autobuild 1.6.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.
- package/README.md +1 -1
- package/SPEC.md +107 -10
- package/docs/agent-runtimes.md +1 -1
- package/docs/architecture.md +62 -22
- package/docs/configuration-overview.md +10 -0
- package/docs/configuration.md +285 -5
- package/docs/forges.md +1 -0
- package/docs/operator-api.md +19 -8
- package/docs/operator-surfaces.md +6 -3
- package/docs/plugin-authoring.md +44 -6
- package/docs/remote-store-protocol.md +19 -6
- package/docs/restacking.md +12 -7
- package/docs/ticket-sources.md +34 -6
- package/docs/tickets.md +6 -0
- package/docs/workspaces.md +1 -1
- package/package.json +3 -3
- package/packages/core/src/cli/attention.ts +1 -0
- package/packages/core/src/cli/binary-direct.ts +1 -0
- package/packages/core/src/cli/dispatch-frontend.ts +10 -14
- package/packages/core/src/cli/dispatch-preflight.ts +1 -0
- package/packages/core/src/cli/dispatch-repository-feed.ts +145 -109
- package/packages/core/src/cli/dispatch.ts +9 -3
- package/packages/core/src/cli/help.ts +11 -4
- package/packages/core/src/cli/init-validation.ts +14 -1
- package/packages/core/src/cli/repository-status.ts +37 -2
- package/packages/core/src/cli/status.ts +8 -0
- package/packages/core/src/cli/ticket.ts +22 -4
- package/packages/core/src/cli/watch.ts +2 -0
- package/packages/core/src/config/live.ts +4 -0
- package/packages/core/src/config/profiles.ts +96 -0
- package/packages/core/src/config/ready-assignee.ts +43 -11
- package/packages/core/src/config/roles.ts +33 -10
- package/packages/core/src/config/schema.ts +166 -24
- package/packages/core/src/events/compatibility.ts +3 -1
- package/packages/core/src/events/forge-degradation-policy.ts +16 -2
- package/packages/core/src/events/payloads.ts +8 -0
- package/packages/core/src/events/policy.ts +1 -0
- package/packages/core/src/events/repository.ts +17 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +73 -124
- package/packages/core/src/kernel/build-creation.ts +29 -0
- package/packages/core/src/kernel/forge-health.ts +47 -0
- package/packages/core/src/kernel/guarded-forge.ts +76 -18
- package/packages/core/src/kernel/node-parent.ts +2 -0
- package/packages/core/src/kernel/read-facts.ts +9 -1
- package/packages/core/src/kernel/reducer.ts +18 -1
- package/packages/core/src/kernel/ticket-preparation.ts +4 -1
- package/packages/core/src/operator/protocol.ts +10 -0
- package/packages/core/src/operator/query.ts +1 -1
- package/packages/core/src/operator/registry.ts +25 -5
- package/packages/core/src/operator/sandbox-host.ts +3 -0
- package/packages/core/src/operator/tickets.ts +15 -3
- package/packages/core/src/plugin-sdk/index.ts +4 -0
- package/packages/core/src/ports/forge/create.ts +6 -0
- package/packages/core/src/ports/forge/github-transport.ts +40 -3
- package/packages/core/src/ports/forge/github.ts +12 -1
- package/packages/core/src/ports/forge/workspace-ancestry.ts +60 -0
- package/packages/core/src/ports/forge-failure.ts +31 -2
- package/packages/core/src/ports/runner/routing.ts +66 -5
- package/packages/core/src/ports/tickets/assignees.ts +54 -0
- package/packages/core/src/ports/tickets/contract.ts +164 -4
- package/packages/core/src/ports/tickets/create.ts +17 -3
- package/packages/core/src/ports/tickets/github-fake.ts +18 -2
- package/packages/core/src/ports/tickets/github.ts +247 -29
- package/packages/core/src/ports/tickets/hosted-index.ts +1 -0
- package/packages/core/src/ports/tickets/operations.ts +6 -1
- package/packages/core/src/ports/tickets/tree.ts +12 -2
- package/packages/core/src/ports/tickets/update.ts +6 -2
- package/packages/core/src/ports/types.ts +33 -3
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +9 -0
- package/packages/core/src/processes/build-child.ts +28 -7
- package/packages/core/src/processes/build-execution-state.ts +4 -1
- package/packages/core/src/processes/build-runner.ts +15 -1
- package/packages/core/src/processes/dispatcher.ts +98 -18
- package/packages/core/src/processes/harvest-child.ts +4 -0
- package/packages/core/src/processes/harvest-runner.ts +5 -0
- package/packages/core/src/processes/repo-view.ts +2 -0
- package/packages/core/src/scenarios/harness.ts +15 -1
- package/packages/core/src/store/reducer-value-shapes.json +3119 -2926
- package/packages/core/src/store/remote/client.ts +21 -8
- package/packages/core/src/store/remote/index.ts +4 -0
- package/packages/core/src/store/remote/protocol.ts +7 -0
- package/packages/core/src/store/remote/released-clients.json +11 -0
- package/packages/core/src/store/remote/released-reducer-values/1.7.0.json +27366 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +2 -0
- package/packages/core/src/store/repo-state-events.ts +1 -0
- package/packages/core/src/store/types.ts +11 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +84 -58
- package/packages/core/src/testing/index.ts +2 -0
- package/packages/core/src/testing/reduced-read-budget.ts +72 -9
- package/skills/guide/SKILL.md +116 -21
- package/skills/guide/references/operator-api.md +19 -8
- package/skills/guide/references/plugin-authoring.md +44 -6
- package/skills/guide/references/remote-store-protocol.md +19 -6
- package/skills/guide/references/restacking.md +12 -7
- package/skills/operate/SKILL.md +29 -3
- package/skills/tickets/SKILL.md +18 -2
- 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
|
|
@@ -459,6 +459,8 @@ export function summarizeEvent(event: AbEvent | RepositoryEvent, state: BuildSta
|
|
|
459
459
|
return `Account credentials recovered: ${JSON.stringify(event.payload.name)}`
|
|
460
460
|
case 'dispatcher.forge-recovered':
|
|
461
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`
|
|
462
464
|
case 'dispatcher.kernel-git-unavailable':
|
|
463
465
|
return `Kernel Git unavailable (${event.payload.executable}): ${singleLine(event.payload.detail)}`
|
|
464
466
|
case 'dispatcher.kernel-git-recovered':
|
|
@@ -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`
|
|
3
|
-
* with `readyAssignee = true`
|
|
4
|
-
*
|
|
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
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
|
70
|
-
*
|
|
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
|
|
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'> &
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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, `${
|
|
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
|
-
`${
|
|
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 ?? {}),
|