@defrex/autobuild 1.4.1 → 1.5.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 +440 -95
- package/bin/ab-dispatch-kernel.ts +1 -0
- package/docs/accounts.md +9 -0
- package/docs/agent-runtimes.md +1 -0
- package/docs/answering-blocked-builds.md +2 -1
- package/docs/architecture.md +290 -130
- package/docs/assets/headline-wide.png +0 -0
- package/docs/build-store.md +33 -3
- package/docs/cli.md +2 -1
- package/docs/configuration-overview.md +9 -0
- package/docs/configuration.md +166 -101
- package/docs/dispatcher-hosting.md +19 -3
- package/docs/dispatcher.md +9 -4
- package/docs/integration-overview.md +2 -2
- package/docs/integration-tree.md +91 -28
- package/docs/merge-policy.md +28 -9
- package/docs/operator-api.md +43 -18
- package/docs/operator-surfaces.md +1 -1
- package/docs/plugin-authoring.md +85 -8
- package/docs/remote-store-protocol.md +25 -7
- package/docs/remote-ticket-protocol.md +126 -12
- package/docs/restacking.md +20 -6
- package/docs/seams.md +2 -2
- package/docs/setup.md +19 -13
- package/docs/spec-standard.md +2 -1
- package/docs/ticket-dependencies.md +26 -8
- package/docs/ticket-migration.md +70 -7
- package/docs/ticket-sources.md +82 -5
- package/docs/tickets.md +34 -2
- package/docs/troubleshooting.md +2 -2
- package/docs/verification.md +5 -5
- package/docs/website.md +8 -0
- package/docs/workspaces.md +1 -1
- package/package.json +5 -4
- package/packages/core/src/accounts/hosted-readiness.ts +21 -0
- package/packages/core/src/cli/attention.ts +1 -0
- package/packages/core/src/cli/build-control.ts +36 -12
- package/packages/core/src/cli/connect.ts +9 -18
- package/packages/core/src/cli/context.ts +44 -0
- package/packages/core/src/cli/dashboard/configuration.ts +11 -0
- package/packages/core/src/cli/dashboard/model.ts +40 -10
- package/packages/core/src/cli/dashboard/queue.ts +21 -0
- package/packages/core/src/cli/dashboard/render.ts +40 -22
- package/packages/core/src/cli/dispatch-frontend.ts +63 -30
- package/packages/core/src/cli/dispatch-mode.ts +35 -16
- package/packages/core/src/cli/dispatch-repository-feed.ts +40 -11
- package/packages/core/src/cli/dispatch.ts +154 -47
- package/packages/core/src/cli/help.ts +59 -22
- package/packages/core/src/cli/init-hosted-accounts.ts +54 -0
- package/packages/core/src/cli/init-readiness-remote.ts +16 -3
- package/packages/core/src/cli/init-validation.ts +144 -42
- package/packages/core/src/cli/issue-links.ts +67 -0
- package/packages/core/src/cli/main.ts +32 -15
- package/packages/core/src/cli/pr-summary-publication.ts +38 -7
- package/packages/core/src/cli/publication-settlement.ts +36 -24
- package/packages/core/src/cli/repository-status.ts +201 -49
- package/packages/core/src/cli/status.ts +41 -3
- package/packages/core/src/cli/terminals.ts +37 -2
- package/packages/core/src/cli/ticket-editor.ts +20 -6
- package/packages/core/src/cli/ticket.ts +264 -46
- package/packages/core/src/cli/triage-count-sampler.ts +59 -0
- package/packages/core/src/cli/watch.ts +4 -0
- package/packages/core/src/config/live.ts +45 -4
- package/packages/core/src/config/load.ts +9 -0
- package/packages/core/src/config/pipeline-source.ts +6 -2
- package/packages/core/src/config/ready-assignee.ts +86 -0
- package/packages/core/src/config/schema.ts +164 -36
- package/packages/core/src/distribution-packaging.ts +1 -1
- package/packages/core/src/events/catalog.ts +5 -0
- package/packages/core/src/events/compatibility.ts +2 -1
- package/packages/core/src/events/payloads.ts +70 -0
- package/packages/core/src/events/policy.ts +8 -0
- package/packages/core/src/events/repository.ts +91 -28
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +41 -0
- package/packages/core/src/kernel/build-identity.ts +12 -0
- package/packages/core/src/kernel/change-presence.ts +139 -6
- package/packages/core/src/kernel/dispatch-capacity.ts +80 -14
- package/packages/core/src/kernel/dispatch-status.ts +10 -1
- package/packages/core/src/kernel/dispatch-upgrade.ts +104 -5
- package/packages/core/src/kernel/engine.ts +4 -2
- package/packages/core/src/kernel/finalize-pr-rejection.ts +95 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +15 -1
- package/packages/core/src/kernel/harvest.ts +4 -1
- package/packages/core/src/kernel/integration-completeness.ts +104 -17
- package/packages/core/src/kernel/integration-landing.ts +17 -0
- package/packages/core/src/kernel/integration-state.ts +17 -0
- package/packages/core/src/kernel/issue-keywords.ts +202 -0
- package/packages/core/src/kernel/janitor-failure.ts +11 -0
- package/packages/core/src/kernel/kernel-git.ts +87 -0
- package/packages/core/src/kernel/landing-readiness.ts +25 -17
- package/packages/core/src/kernel/log-index.ts +1 -1
- package/packages/core/src/kernel/node-issue-links.ts +142 -0
- package/packages/core/src/kernel/node-parent.ts +6 -0
- package/packages/core/src/kernel/node-restack-transaction.ts +2 -0
- package/packages/core/src/kernel/pr-summary.ts +24 -0
- package/packages/core/src/kernel/read-deferrals.ts +75 -12
- package/packages/core/src/kernel/read-facts.ts +32 -1
- package/packages/core/src/kernel/reconcile-restack.ts +1 -1
- package/packages/core/src/kernel/reducer-registry.ts +31 -1
- package/packages/core/src/kernel/reducer.ts +90 -2
- package/packages/core/src/kernel/ticket-preparation.ts +12 -0
- package/packages/core/src/kernel/verify-budget.ts +43 -0
- package/packages/core/src/operator/index.ts +3 -1
- package/packages/core/src/operator/presentation.ts +3 -0
- package/packages/core/src/operator/protocol.ts +38 -2
- package/packages/core/src/operator/query.ts +66 -29
- package/packages/core/src/operator/registry.ts +47 -26
- package/packages/core/src/operator/tickets.ts +77 -10
- package/packages/core/src/plugin-sdk/index.ts +13 -0
- package/packages/core/src/plugins/manifest.ts +1 -1
- package/packages/core/src/plugins/registry.ts +1 -0
- package/packages/core/src/ports/forge/contract.ts +69 -0
- package/packages/core/src/ports/forge/create.ts +5 -0
- package/packages/core/src/ports/forge/fake.ts +184 -3
- package/packages/core/src/ports/forge/git-rewrite.ts +4 -2
- package/packages/core/src/ports/forge/github.ts +175 -38
- package/packages/core/src/ports/forge/local-git.ts +14 -0
- package/packages/core/src/ports/forge/readiness.ts +10 -0
- package/packages/core/src/ports/forge-failure.ts +43 -0
- package/packages/core/src/ports/runner/claude.ts +7 -1
- package/packages/core/src/ports/runner/codex.ts +7 -2
- package/packages/core/src/ports/runner/native-cli-fixture.ts +2 -1
- package/packages/core/src/ports/runner/pi.ts +7 -1
- package/packages/core/src/ports/runner/runtime.ts +3 -0
- package/packages/core/src/ports/runner/start-prompt.ts +37 -0
- package/packages/core/src/ports/tickets/contract.ts +320 -7
- package/packages/core/src/ports/tickets/create.ts +72 -17
- package/packages/core/src/ports/tickets/fake.ts +18 -0
- package/packages/core/src/ports/tickets/file-codec.ts +20 -0
- package/packages/core/src/ports/tickets/file.ts +43 -1
- package/packages/core/src/ports/tickets/github-fake.ts +1123 -0
- package/packages/core/src/ports/tickets/github-issues.ts +431 -0
- package/packages/core/src/ports/tickets/github-validators.ts +194 -0
- package/packages/core/src/ports/tickets/github.ts +2029 -0
- package/packages/core/src/ports/tickets/hosted-index.ts +34 -3
- package/packages/core/src/ports/tickets/issue-links.ts +86 -0
- package/packages/core/src/ports/tickets/lifecycle.ts +60 -4
- package/packages/core/src/ports/tickets/linear.ts +66 -6
- package/packages/core/src/ports/tickets/migration.ts +290 -68
- package/packages/core/src/ports/tickets/operations.ts +98 -12
- package/packages/core/src/ports/tickets/priority.ts +55 -0
- package/packages/core/src/ports/tickets/remote-protocol.ts +195 -29
- package/packages/core/src/ports/tickets/remote.ts +188 -13
- package/packages/core/src/ports/tickets/revision.ts +22 -1
- package/packages/core/src/ports/tickets/states.ts +43 -0
- package/packages/core/src/ports/tickets/tree.ts +58 -12
- package/packages/core/src/ports/tickets/update.ts +12 -2
- package/packages/core/src/ports/types.ts +194 -11
- package/packages/core/src/ports/workspace/commit-preservation.ts +135 -13
- package/packages/core/src/ports/workspace/git-worktree.ts +3 -1
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +132 -27
- package/packages/core/src/processes/build-runner.ts +99 -21
- package/packages/core/src/processes/dispatcher.ts +1080 -533
- package/packages/core/src/processes/execution-no-progress.ts +5 -0
- package/packages/core/src/processes/harvest-runner.ts +17 -8
- package/packages/core/src/processes/harvest.ts +5 -8
- package/packages/core/src/processes/tick-publication.ts +12 -2
- package/packages/core/src/processes/ticket-scan-schedule.ts +78 -0
- package/packages/core/src/processes/workspace-preservation.ts +37 -2
- package/packages/core/src/runtime-identity.ts +10 -2
- package/packages/core/src/scenarios/harness.ts +4 -0
- package/packages/core/src/store/adapter.ts +7 -1
- package/packages/core/src/store/contract.ts +83 -2
- package/packages/core/src/store/digest.ts +32 -1
- package/packages/core/src/store/reducer-value-shapes.json +4187 -3391
- package/packages/core/src/store/remote/protocol.ts +2 -0
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.5.0.json +26924 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +2 -0
- package/packages/core/src/store/repo-state-events.ts +2 -0
- package/packages/core/src/store/types.ts +5 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +729 -123
- package/packages/core/src/testing/index.ts +18 -1
- package/packages/core/src/testing/presence-history.ts +79 -0
- package/packages/core/src/testing/reduced-read-budget.ts +1197 -31
- package/packages/core/src/testing/upgrade-generations.ts +77 -0
- package/skills/code-review/SKILL.md +4 -3
- package/skills/finalize/SKILL.md +18 -2
- package/skills/guide/SKILL.md +382 -139
- package/skills/guide/references/accounts.md +9 -0
- package/skills/guide/references/integration-tree.md +91 -28
- package/skills/guide/references/merge-policy.md +28 -9
- package/skills/guide/references/operator-api.md +43 -18
- package/skills/guide/references/plugin-authoring.md +85 -8
- package/skills/guide/references/remote-store-protocol.md +25 -7
- package/skills/guide/references/remote-ticket-protocol.md +126 -12
- package/skills/guide/references/restacking.md +20 -6
- package/skills/guide/references/setup.md +19 -13
- package/skills/guide/references/spec-standard.md +2 -1
- package/skills/guide/references/ticket-dependencies.md +26 -8
- package/skills/guide/references/ticket-migration.md +70 -7
- package/skills/harvest-review/SKILL.md +4 -3
- package/skills/implement/SKILL.md +20 -1
- package/skills/operate/SKILL.md +103 -28
- package/skills/plan/SKILL.md +1 -1
- package/skills/reconcile/SKILL.md +5 -4
- package/skills/spec/SKILL.md +15 -2
- package/skills/tickets/SKILL.md +114 -37
- package/templates/autobuild.toml +5 -0
- package/templates/hosted-service/package.json +2 -2
|
@@ -16,9 +16,19 @@ import type { PluginFactoryContext } from '../../plugins/manifest'
|
|
|
16
16
|
import type { TicketSource } from '../types'
|
|
17
17
|
import { DEFAULT_TICKETS_DIR, FileTicketSource } from './file'
|
|
18
18
|
import { LinearTicketSource } from './linear'
|
|
19
|
-
import {
|
|
19
|
+
import { GitHubTicketSource } from './github'
|
|
20
|
+
import { FileGitHubValidatorStore } from './github-validators'
|
|
21
|
+
import {
|
|
22
|
+
createGitHubFetchTransport,
|
|
23
|
+
githubTokenSource,
|
|
24
|
+
resolveGitHubToken,
|
|
25
|
+
} from '../forge/github-transport'
|
|
26
|
+
import { parseRepoCoordinates } from '../forge/github'
|
|
27
|
+
import { normalizeGitRemoteUrl } from '../../kernel/origin'
|
|
28
|
+
import { HostedTicketSource, hostedTicketPolicy } from './remote'
|
|
20
29
|
import { ticketLifecycle } from './lifecycle'
|
|
21
30
|
import { normalizeServiceURL } from '../../connection'
|
|
31
|
+
import { assertReadyAssigneeSupported } from '../../config/ready-assignee'
|
|
22
32
|
|
|
23
33
|
function reason(error: unknown): string {
|
|
24
34
|
return error instanceof Error ? error.message : String(error)
|
|
@@ -87,22 +97,11 @@ async function rawTicketSource(
|
|
|
87
97
|
})
|
|
88
98
|
// Delegated sessions may read policy, but never redefine project authority.
|
|
89
99
|
if (!ticketSession && !env.AB_HARVEST && !env.AB_PHASE) {
|
|
90
|
-
|
|
91
|
-
await source.synchronizePolicy({
|
|
92
|
-
version: 1,
|
|
93
|
-
tickets: {
|
|
94
|
-
source: 'hosted',
|
|
95
|
-
teamKey: config.teamKey,
|
|
96
|
-
readyState: lifecycle.ready,
|
|
97
|
-
triageState: lifecycle.triage,
|
|
98
|
-
claimedState: lifecycle.doing,
|
|
99
|
-
doneState: lifecycle.done,
|
|
100
|
-
createState: lifecycle.create,
|
|
101
|
-
proposalState: lifecycle.proposal,
|
|
102
|
-
...(config.readyLabels !== undefined ? { readyLabels: config.readyLabels } : {}),
|
|
103
|
-
},
|
|
104
|
-
})
|
|
100
|
+
await source.synchronizePolicy(hostedTicketPolicy(config))
|
|
105
101
|
}
|
|
102
|
+
// The source leaves with a settled targeting decision, so no observation
|
|
103
|
+
// pass ever runs on undecided support; the policy sync usually settled it.
|
|
104
|
+
await source.negotiateTargeting()
|
|
106
105
|
return source
|
|
107
106
|
}
|
|
108
107
|
|
|
@@ -130,6 +129,42 @@ async function rawTicketSource(
|
|
|
130
129
|
})
|
|
131
130
|
}
|
|
132
131
|
|
|
132
|
+
if (config.source === 'github') {
|
|
133
|
+
const origin = env.AB_REPOSITORY?.trim() || (await resolveRepoOrigin(targetRepo, spawnExec))
|
|
134
|
+
if (origin === undefined || origin === '')
|
|
135
|
+
throw new Error(
|
|
136
|
+
'[tickets].source = "github" needs the repository\'s origin remote on github.com; set the checkout\'s origin or export AB_REPOSITORY',
|
|
137
|
+
)
|
|
138
|
+
const coordinates = githubCoordinates(origin)
|
|
139
|
+
if (coordinates === null)
|
|
140
|
+
throw new Error(
|
|
141
|
+
`[tickets].source = "github" needs an origin on github.com; origin is ${origin}`,
|
|
142
|
+
)
|
|
143
|
+
return new GitHubTicketSource({
|
|
144
|
+
transport: createGitHubFetchTransport({ token: githubTokenSource(env) }),
|
|
145
|
+
repository: coordinates,
|
|
146
|
+
lifecycle: ticketLifecycle(config),
|
|
147
|
+
readyLabels: config.readyLabels ?? ['autobuild'],
|
|
148
|
+
...(localStateRoot !== undefined
|
|
149
|
+
? {
|
|
150
|
+
validators: new FileGitHubValidatorStore(
|
|
151
|
+
resolve(
|
|
152
|
+
localStateRoot,
|
|
153
|
+
'github-tickets',
|
|
154
|
+
coordinates.owner,
|
|
155
|
+
coordinates.name,
|
|
156
|
+
'validators',
|
|
157
|
+
),
|
|
158
|
+
),
|
|
159
|
+
}
|
|
160
|
+
: {}),
|
|
161
|
+
credentialMiss: async () => {
|
|
162
|
+
const credential = await resolveGitHubToken(env)
|
|
163
|
+
return 'reason' in credential ? credential.reason : undefined
|
|
164
|
+
},
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
|
|
133
168
|
if (config.source === 'file') {
|
|
134
169
|
return new FileTicketSource({
|
|
135
170
|
dir:
|
|
@@ -182,5 +217,25 @@ async function rawTicketSource(
|
|
|
182
217
|
export async function createTicketSource(
|
|
183
218
|
...args: Parameters<typeof rawTicketSource>
|
|
184
219
|
): Promise<TicketSource> {
|
|
185
|
-
|
|
220
|
+
const [config, , , , plugins] = args
|
|
221
|
+
const source = await rawTicketSource(...args)
|
|
222
|
+
// Plugins load after config parse, so the capability is checked here, on
|
|
223
|
+
// the constructed source, rather than in the schema.
|
|
224
|
+
const owner = plugins?.ticketSources.get(config.source)?.owner
|
|
225
|
+
assertReadyAssigneeSupported(config, source, owner?.kind === 'plugin' ? owner.name : undefined)
|
|
226
|
+
return compatibleTicketSource(source)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Owner and name of a github.com origin: an `owner/name` slug, or a URL or
|
|
230
|
+
* SSH spelling whose host is github.com. Anything else is null. */
|
|
231
|
+
export function githubCoordinates(origin: string): { owner: string; name: string } | null {
|
|
232
|
+
const normalized = normalizeGitRemoteUrl(origin)
|
|
233
|
+
let host: string | undefined
|
|
234
|
+
try {
|
|
235
|
+
host = new URL(normalized).hostname
|
|
236
|
+
} catch {
|
|
237
|
+
host = undefined
|
|
238
|
+
}
|
|
239
|
+
if (host !== undefined && host !== '' && host.toLowerCase() !== 'github.com') return null
|
|
240
|
+
return parseRepoCoordinates(normalized)
|
|
186
241
|
}
|
|
@@ -18,6 +18,7 @@ import type {
|
|
|
18
18
|
TicketMutation,
|
|
19
19
|
} from '../types'
|
|
20
20
|
import { validateTicketUpdate } from './update'
|
|
21
|
+
import { normalizeIssueLinks } from './issue-links'
|
|
21
22
|
|
|
22
23
|
function cloneTicket(ticket: Ticket, doneState: string): Ticket {
|
|
23
24
|
return {
|
|
@@ -32,6 +33,10 @@ function cloneTicket(ticket: Ticket, doneState: string): Ticket {
|
|
|
32
33
|
resolved: ticket.state === doneState,
|
|
33
34
|
labels: [...ticket.labels],
|
|
34
35
|
...(ticket.blockedBy !== undefined ? { blockedBy: [...ticket.blockedBy] } : {}),
|
|
36
|
+
...(ticket.issueLinks?.length
|
|
37
|
+
? { issueLinks: ticket.issueLinks.map((link) => ({ ...link })) }
|
|
38
|
+
: {}),
|
|
39
|
+
...(ticket.priority === 'urgent' ? { priority: 'urgent' as const } : {}),
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
42
|
|
|
@@ -39,6 +44,8 @@ export class FakeTicketSource implements TicketSource {
|
|
|
39
44
|
readonly requestedIds = fileRequestedIds
|
|
40
45
|
readonly name = 'fake'
|
|
41
46
|
readonly integrationTree = true
|
|
47
|
+
readonly issueLinks = true
|
|
48
|
+
readonly priority = true
|
|
42
49
|
|
|
43
50
|
async listAll(): Promise<TicketListing> {
|
|
44
51
|
return {
|
|
@@ -173,6 +180,8 @@ export class FakeTicketSource implements TicketSource {
|
|
|
173
180
|
...(draft.blockedBy !== undefined && draft.blockedBy.length > 0
|
|
174
181
|
? { blockedBy: [...draft.blockedBy] }
|
|
175
182
|
: {}),
|
|
183
|
+
...(draft.issueLinks?.length ? { issueLinks: normalizeIssueLinks(draft.issueLinks) } : {}),
|
|
184
|
+
...(draft.priority === 'urgent' ? { priority: 'urgent' as const } : {}),
|
|
176
185
|
}
|
|
177
186
|
this.tickets.set(id, ticket)
|
|
178
187
|
if (opts.idempotencyKey !== undefined) {
|
|
@@ -221,6 +230,10 @@ export class FakeTicketSource implements TicketSource {
|
|
|
221
230
|
}
|
|
222
231
|
if (validated.body !== undefined) ticket.body = validated.body
|
|
223
232
|
if (validated.labels !== undefined) ticket.labels = [...validated.labels]
|
|
233
|
+
if (validated.issueLinks?.length) ticket.issueLinks = validated.issueLinks
|
|
234
|
+
else if (validated.issueLinks !== undefined) delete ticket.issueLinks
|
|
235
|
+
if (validated.priority === 'urgent') ticket.priority = 'urgent'
|
|
236
|
+
else if (validated.priority !== undefined) delete ticket.priority
|
|
224
237
|
|
|
225
238
|
this.updates.push({ id, patch: cloneUpdate(validated) })
|
|
226
239
|
}
|
|
@@ -256,6 +269,7 @@ export class FakeTicketSource implements TicketSource {
|
|
|
256
269
|
id,
|
|
257
270
|
exists: true,
|
|
258
271
|
resolved: ticket.state === this.doneState,
|
|
272
|
+
state: ticket.state,
|
|
259
273
|
blockedBy: [...(ticket.blockedBy ?? [])],
|
|
260
274
|
}
|
|
261
275
|
})
|
|
@@ -277,5 +291,9 @@ function cloneUpdate(patch: TicketUpdate): TicketUpdate {
|
|
|
277
291
|
...(patch.title !== undefined ? { title: patch.title } : {}),
|
|
278
292
|
...(patch.body !== undefined ? { body: patch.body } : {}),
|
|
279
293
|
...(patch.labels !== undefined ? { labels: [...patch.labels] } : {}),
|
|
294
|
+
...(patch.issueLinks !== undefined
|
|
295
|
+
? { issueLinks: patch.issueLinks.map((link) => ({ ...link })) }
|
|
296
|
+
: {}),
|
|
297
|
+
...(patch.priority !== undefined ? { priority: patch.priority } : {}),
|
|
280
298
|
}
|
|
281
299
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { portableAssetSchema } from './portable-assets'
|
|
2
2
|
import { parse as parseToml, stringify as stringifyToml } from 'smol-toml'
|
|
3
3
|
import { z } from 'zod'
|
|
4
|
+
import { refineUniqueIssues } from './issue-links'
|
|
4
5
|
|
|
5
6
|
const frontmatterSchema = z.strictObject({
|
|
6
7
|
kind: z.enum(['work', 'node']).optional(),
|
|
@@ -31,6 +32,20 @@ const frontmatterSchema = z.strictObject({
|
|
|
31
32
|
/** Source-local blocker ids (§13). Absent ≡ no dependencies, which keeps
|
|
32
33
|
* every pre-existing ticket file valid. */
|
|
33
34
|
blockedBy: z.array(z.string()).optional(),
|
|
35
|
+
/** Forge issues the ticket addresses, always with an explicit intent.
|
|
36
|
+
* Absent ≡ none, which keeps every pre-existing ticket file valid. */
|
|
37
|
+
issueLinks: z
|
|
38
|
+
.array(
|
|
39
|
+
z.strictObject({
|
|
40
|
+
issue: z.number().int().positive().max(Number.MAX_SAFE_INTEGER),
|
|
41
|
+
intent: z.enum(['closes', 'refs']),
|
|
42
|
+
}),
|
|
43
|
+
)
|
|
44
|
+
.superRefine(refineUniqueIssues)
|
|
45
|
+
.optional(),
|
|
46
|
+
/** Dispatch class. Absent ≡ normal; a hand-written `normal` is tolerated and
|
|
47
|
+
* dropped on the next write. */
|
|
48
|
+
priority: z.enum(['urgent', 'normal']).optional(),
|
|
34
49
|
/** Stable external-create adoption key. It travels with the ticket across
|
|
35
50
|
* state-directory moves, so retries find it in any lifecycle state. */
|
|
36
51
|
idempotencyKey: z.string().min(1).optional(),
|
|
@@ -87,6 +102,11 @@ export function serializeTicketFile(front: Frontmatter, body: string): string {
|
|
|
87
102
|
if (front.blockedBy !== undefined && front.blockedBy.length > 0) {
|
|
88
103
|
data.blockedBy = front.blockedBy
|
|
89
104
|
}
|
|
105
|
+
if (front.issueLinks !== undefined && front.issueLinks.length > 0) {
|
|
106
|
+
data.issueLinks = front.issueLinks
|
|
107
|
+
}
|
|
108
|
+
// Only urgent is written, so normal tickets round-trip byte-identically.
|
|
109
|
+
if (front.priority === 'urgent') data.priority = front.priority
|
|
90
110
|
if (front.idempotencyKey !== undefined) {
|
|
91
111
|
data.idempotencyKey = front.idempotencyKey
|
|
92
112
|
}
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
validateStatePurpose,
|
|
31
31
|
orderStates,
|
|
32
32
|
resolveState,
|
|
33
|
+
matchStateNames,
|
|
33
34
|
} from './states'
|
|
34
35
|
import { readdirSync, statSync } from 'node:fs'
|
|
35
36
|
import { mkdir, readdir, readFile, rename, stat, writeFile } from 'node:fs/promises'
|
|
@@ -50,11 +51,13 @@ import type {
|
|
|
50
51
|
TicketDraft,
|
|
51
52
|
TicketListing,
|
|
52
53
|
TicketSource,
|
|
54
|
+
TicketStateCount,
|
|
53
55
|
TicketStateInfo,
|
|
54
56
|
TicketUpdate,
|
|
55
57
|
TicketMutation,
|
|
56
58
|
} from '../types'
|
|
57
59
|
import { validateTicketUpdate } from './update'
|
|
60
|
+
import { normalizeIssueLinks } from './issue-links'
|
|
58
61
|
|
|
59
62
|
/** Repo-relative fallback when no selected local-state root is supplied. */
|
|
60
63
|
export const DEFAULT_TICKETS_DIR = '.autobuild/tickets'
|
|
@@ -95,6 +98,8 @@ interface Located {
|
|
|
95
98
|
export class FileTicketSource implements TicketSource {
|
|
96
99
|
readonly name = 'file'
|
|
97
100
|
readonly integrationTree = true
|
|
101
|
+
readonly issueLinks = true
|
|
102
|
+
readonly priority = true
|
|
98
103
|
readonly requestedIds = fileRequestedIds
|
|
99
104
|
readonly assets: FileTicketAssets
|
|
100
105
|
|
|
@@ -239,7 +244,7 @@ export class FileTicketSource implements TicketSource {
|
|
|
239
244
|
// otherwise-idempotent transition to the current state.
|
|
240
245
|
await this.loadAt(found)
|
|
241
246
|
// Idempotent by construction — the dispatcher retries transitions after a
|
|
242
|
-
// crash (file.test.ts explains the window). rename(2) would no-op here
|
|
247
|
+
// crash (file.integration.test.ts explains the window). rename(2) would no-op here
|
|
243
248
|
// anyway, but resting idempotency on that POSIX subtlety would make it a
|
|
244
249
|
// property of the syscall rather than of this adapter.
|
|
245
250
|
if (found.state === target) return
|
|
@@ -291,6 +296,8 @@ export class FileTicketSource implements TicketSource {
|
|
|
291
296
|
...(draft.blockedBy !== undefined && draft.blockedBy.length > 0
|
|
292
297
|
? { blockedBy: [...draft.blockedBy] }
|
|
293
298
|
: {}),
|
|
299
|
+
...(draft.issueLinks?.length ? { issueLinks: normalizeIssueLinks(draft.issueLinks) } : {}),
|
|
300
|
+
...(draft.priority === 'urgent' ? { priority: 'urgent' as const } : {}),
|
|
294
301
|
...(opts.idempotencyKey !== undefined ? { idempotencyKey: opts.idempotencyKey } : {}),
|
|
295
302
|
}
|
|
296
303
|
if (taken.has(front.id)) throw new Error(`requested ticket id already occupied: ${front.id}`)
|
|
@@ -329,6 +336,8 @@ export class FileTicketSource implements TicketSource {
|
|
|
329
336
|
else if (canonicalTarget !== undefined) front.target = canonicalTarget
|
|
330
337
|
if (patch.title !== undefined) front.title = patch.title
|
|
331
338
|
if (patch.labels !== undefined) front.labels = patch.labels
|
|
339
|
+
setIssueLinks(front, patch.issueLinks)
|
|
340
|
+
setPriority(front, patch.priority)
|
|
332
341
|
if (patch.body !== undefined) body = patch.body
|
|
333
342
|
} else if (mutation.kind === 'blockers') {
|
|
334
343
|
const blockers = new Set(front.blockedBy ?? [])
|
|
@@ -354,6 +363,8 @@ export class FileTicketSource implements TicketSource {
|
|
|
354
363
|
...(validated.labels !== undefined ? { labels: [...validated.labels] } : {}),
|
|
355
364
|
}
|
|
356
365
|
if (canonicalTarget === null) delete front.target
|
|
366
|
+
setIssueLinks(front, validated.issueLinks)
|
|
367
|
+
setPriority(front, validated.priority)
|
|
357
368
|
await this.rewriteAt(loaded.found, front, validated.body ?? loaded.body)
|
|
358
369
|
}
|
|
359
370
|
|
|
@@ -430,6 +441,7 @@ export class FileTicketSource implements TicketSource {
|
|
|
430
441
|
id,
|
|
431
442
|
exists: true,
|
|
432
443
|
resolved: found.state === this.doneState,
|
|
444
|
+
state: found.state,
|
|
433
445
|
blockedBy: [...(loaded.front.blockedBy ?? [])],
|
|
434
446
|
})
|
|
435
447
|
}
|
|
@@ -444,6 +456,18 @@ export class FileTicketSource implements TicketSource {
|
|
|
444
456
|
return infos
|
|
445
457
|
}
|
|
446
458
|
|
|
459
|
+
/**
|
|
460
|
+
* Per-state counts from each matched state's directory listing, never a
|
|
461
|
+
* ticket parse. The listing still grows with that state's ticket files.
|
|
462
|
+
*/
|
|
463
|
+
async countStates(names: readonly string[]): Promise<TicketStateCount[]> {
|
|
464
|
+
const counts: TicketStateCount[] = []
|
|
465
|
+
for (const name of matchStateNames(names, await this.states())) {
|
|
466
|
+
counts.push({ name, tickets: (await this.readMarkdown(join(this.dir, name))).length })
|
|
467
|
+
}
|
|
468
|
+
return counts
|
|
469
|
+
}
|
|
470
|
+
|
|
447
471
|
async addState(
|
|
448
472
|
name: string,
|
|
449
473
|
opts: { about?: string } = {},
|
|
@@ -665,6 +689,8 @@ export class FileTicketSource implements TicketSource {
|
|
|
665
689
|
labels: front.labels,
|
|
666
690
|
state,
|
|
667
691
|
blockedBy: front.blockedBy,
|
|
692
|
+
issueLinks: front.issueLinks,
|
|
693
|
+
priority: front.priority,
|
|
668
694
|
...(front.comments !== undefined ? { comments: front.comments } : {}),
|
|
669
695
|
...(front.attachments !== undefined ? { attachments: front.attachments } : {}),
|
|
670
696
|
}),
|
|
@@ -679,10 +705,26 @@ export class FileTicketSource implements TicketSource {
|
|
|
679
705
|
...(front.blockedBy !== undefined && front.blockedBy.length > 0
|
|
680
706
|
? { blockedBy: [...front.blockedBy] }
|
|
681
707
|
: {}),
|
|
708
|
+
...(front.issueLinks?.length ? { issueLinks: normalizeIssueLinks(front.issueLinks) } : {}),
|
|
709
|
+
...(front.priority === 'urgent' ? { priority: 'urgent' as const } : {}),
|
|
682
710
|
}
|
|
683
711
|
}
|
|
684
712
|
}
|
|
685
713
|
|
|
714
|
+
/** A named set replaces the stored one; an empty set removes the key. */
|
|
715
|
+
function setIssueLinks(front: Frontmatter, links: TicketUpdate['issueLinks']): void {
|
|
716
|
+
if (links === undefined) return
|
|
717
|
+
if (links.length > 0) front.issueLinks = normalizeIssueLinks(links)
|
|
718
|
+
else delete front.issueLinks
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/** Urgent sets the key; normal removes it. */
|
|
722
|
+
function setPriority(front: Frontmatter, priority: TicketUpdate['priority']): void {
|
|
723
|
+
if (priority === undefined) return
|
|
724
|
+
if (priority === 'urgent') front.priority = priority
|
|
725
|
+
else delete front.priority
|
|
726
|
+
}
|
|
727
|
+
|
|
686
728
|
function duplicateError(id: string, paths: string[]): Error {
|
|
687
729
|
return new Error(
|
|
688
730
|
`file ticket source: ticket "${id}" exists in more than one state directory: ` +
|