@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
|
@@ -2,12 +2,24 @@ import { validateTicketAssetInput } from '../../store/ticket-assets'
|
|
|
2
2
|
import { mkdir, readdir, readFile, rename, rm, rmdir, stat, writeFile } from 'node:fs/promises'
|
|
3
3
|
import { dirname, join, resolve } from 'node:path'
|
|
4
4
|
import { z } from 'zod'
|
|
5
|
-
import type {
|
|
5
|
+
import type { TicketRef } from '../../ontology'
|
|
6
|
+
import { resolveTicketRef, type TicketMigrations } from '../../kernel/ticket-migrations'
|
|
7
|
+
import type { IssueLink, Ticket, TicketSource, TicketAssetStore } from '../types'
|
|
8
|
+
import {
|
|
9
|
+
holdsState,
|
|
10
|
+
LIFECYCLE_ROLES,
|
|
11
|
+
type LifecycleRole,
|
|
12
|
+
roleState,
|
|
13
|
+
stateRolesIn,
|
|
14
|
+
type TicketLifecycle,
|
|
15
|
+
} from './lifecycle'
|
|
6
16
|
import { projectTicketTree } from './tree'
|
|
7
17
|
import { FileTicketSource } from './file'
|
|
8
18
|
import { parseTicketFile, serializeTicketFile } from './file-codec'
|
|
9
19
|
import { validateFileTicketId } from './requested-id'
|
|
10
20
|
import { normalizeStateName } from './states'
|
|
21
|
+
import { TicketIssueLinksUnsupported } from './issue-links'
|
|
22
|
+
import { TicketPriorityUnsupported } from './priority'
|
|
11
23
|
import { encodePortableAsset, decodePortableAsset, type PortableAsset } from './portable-assets'
|
|
12
24
|
|
|
13
25
|
export const MANIFEST = '.ab-migration.json'
|
|
@@ -18,6 +30,14 @@ const manifestSchema = z.strictObject({
|
|
|
18
30
|
source: z.string().regex(/^[a-z][a-z0-9-]*(?::[\s\S]*)?$/),
|
|
19
31
|
keys: z.record(z.string(), z.string().min(1)),
|
|
20
32
|
states: z.record(z.string(), z.string()),
|
|
33
|
+
/** State directory → the lifecycle roles its state held in the exporting
|
|
34
|
+
* source. Import lands a role-holding state in the destination's state for
|
|
35
|
+
* the same role, whatever either source calls it. */
|
|
36
|
+
roles: z.record(z.string(), z.array(z.enum(LIFECYCLE_ROLES))).optional(),
|
|
37
|
+
/** When an import first saved this identity and its creation keys; every
|
|
38
|
+
* later keyed create from the input happens after it. Export never writes
|
|
39
|
+
* it, so export bytes stay unchanged. */
|
|
40
|
+
reservedAt: z.string().datetime().optional(),
|
|
21
41
|
})
|
|
22
42
|
export type Manifest = z.infer<typeof manifestSchema>
|
|
23
43
|
export async function readMigrationManifest(dir: string): Promise<Manifest> {
|
|
@@ -81,7 +101,13 @@ async function inventory(source: TicketSource, signal?: AbortSignal): Promise<Ti
|
|
|
81
101
|
}
|
|
82
102
|
return tickets
|
|
83
103
|
}
|
|
84
|
-
|
|
104
|
+
/** Map state names one to one. Names in `merge` (role-mapped states) may
|
|
105
|
+
* share a target with each other, never with a name-mapped state. */
|
|
106
|
+
function uniqueStateMap(
|
|
107
|
+
names: string[],
|
|
108
|
+
map: (name: string) => string,
|
|
109
|
+
merge: ReadonlySet<string> = new Set(),
|
|
110
|
+
): Record<string, string> {
|
|
85
111
|
const result: Record<string, string> = Object.create(null)
|
|
86
112
|
const groups = new Map<string, string[]>()
|
|
87
113
|
for (const name of new Set(names)) {
|
|
@@ -89,7 +115,9 @@ function uniqueStateMap(names: string[], map: (name: string) => string): Record<
|
|
|
89
115
|
result[name] = target
|
|
90
116
|
groups.set(target, [...(groups.get(target) ?? []), name])
|
|
91
117
|
}
|
|
92
|
-
const collisions = [...groups].filter(
|
|
118
|
+
const collisions = [...groups].filter(
|
|
119
|
+
([, originals]) => originals.length > 1 && !originals.every((name) => merge.has(name)),
|
|
120
|
+
)
|
|
93
121
|
if (collisions.length)
|
|
94
122
|
throw new Error(
|
|
95
123
|
`state collisions: ${collisions.map(([target, originals]) => `${originals.join(', ')} → ${target}`).join('; ')}`,
|
|
@@ -123,6 +151,16 @@ export interface MigrationOptions {
|
|
|
123
151
|
assets?: TicketAssetStore
|
|
124
152
|
signal?: AbortSignal
|
|
125
153
|
print?: (line: string) => void
|
|
154
|
+
/** The configured source's lifecycle: the source on export (recorded as
|
|
155
|
+
* manifest roles), the destination on import (where those roles land). */
|
|
156
|
+
lifecycle?: TicketLifecycle
|
|
157
|
+
/** Import only tickets in these input states (`--states`). */
|
|
158
|
+
states?: string[]
|
|
159
|
+
/** Unfinished builds' ticket and target refs, consulted only with
|
|
160
|
+
* `states`: a selection may not leave one of their tickets behind. */
|
|
161
|
+
inFlight?: { build: string; ticket: TicketRef }[]
|
|
162
|
+
/** Recorded continuity, to resolve `inFlight` refs into the export. */
|
|
163
|
+
migrations?: TicketMigrations
|
|
126
164
|
}
|
|
127
165
|
/** Publish a complete portable tracker only after every source read succeeds. */
|
|
128
166
|
export async function exportTickets(opts: MigrationOptions): Promise<void> {
|
|
@@ -167,10 +205,24 @@ export async function exportTickets(opts: MigrationOptions): Promise<void> {
|
|
|
167
205
|
keys: Object.create(null),
|
|
168
206
|
states,
|
|
169
207
|
}
|
|
208
|
+
if (opts.lifecycle) {
|
|
209
|
+
const roles: Record<string, LifecycleRole[]> = Object.create(null)
|
|
210
|
+
for (const [name, directory] of Object.entries(states)) {
|
|
211
|
+
const held = stateRolesIn(opts.lifecycle, name)
|
|
212
|
+
if (held.length) roles[directory] = held
|
|
213
|
+
}
|
|
214
|
+
if (Object.keys(roles).length) manifest.roles = roles
|
|
215
|
+
}
|
|
170
216
|
const records = []
|
|
171
217
|
for (const ticket of tickets) {
|
|
172
218
|
check()
|
|
173
219
|
validateFileTicketId(ticket.ref.id)
|
|
220
|
+
if (ticket.comments === undefined && opts.source.readComments) {
|
|
221
|
+
const comments = await opts.source.readComments(ticket.ref.id)
|
|
222
|
+
check()
|
|
223
|
+
if (comments === null) throw new Error(`ticket disappeared: ${ticket.ref.id}`)
|
|
224
|
+
ticket.comments = comments
|
|
225
|
+
}
|
|
174
226
|
const key = ticket.creationKey ?? `migration:${identity}:${ticket.ref.id}`
|
|
175
227
|
manifest.keys[ticket.ref.id] = key
|
|
176
228
|
records.push({
|
|
@@ -184,6 +236,8 @@ export async function exportTickets(opts: MigrationOptions): Promise<void> {
|
|
|
184
236
|
title: ticket.title,
|
|
185
237
|
labels: ticket.labels,
|
|
186
238
|
blockedBy: ticket.blockedBy,
|
|
239
|
+
issueLinks: ticket.issueLinks,
|
|
240
|
+
...(ticket.priority === 'urgent' ? { priority: ticket.priority } : {}),
|
|
187
241
|
idempotencyKey: key,
|
|
188
242
|
...(ticket.comments !== undefined ? { comments: ticket.comments } : {}),
|
|
189
243
|
attachments: await currentAssets(
|
|
@@ -232,28 +286,147 @@ function matchState(name: string, existing: string[]): string | undefined {
|
|
|
232
286
|
if (matches.length > 1) throw new Error(`ambiguous target state ${name}: ${matches.join(', ')}`)
|
|
233
287
|
return matches[0]
|
|
234
288
|
}
|
|
289
|
+
interface Selection {
|
|
290
|
+
tickets: Ticket[]
|
|
291
|
+
/** Input state directories the import creates at the destination. */
|
|
292
|
+
states: string[]
|
|
293
|
+
/** Each selected ticket's blockers, less those left behind as done. */
|
|
294
|
+
blockers: Map<string, string[]>
|
|
295
|
+
}
|
|
296
|
+
/** Resolve `--states` to input directories and keep their tickets. A blocker
|
|
297
|
+
* on a left-out done ticket is dropped as resolved; every other reference to a
|
|
298
|
+
* left-out ticket, and every unfinished build on one, is a problem. */
|
|
299
|
+
function selectTickets(
|
|
300
|
+
opts: MigrationOptions,
|
|
301
|
+
all: Ticket[],
|
|
302
|
+
inputStates: string[],
|
|
303
|
+
manifest: Manifest,
|
|
304
|
+
problems: string[],
|
|
305
|
+
): Selection {
|
|
306
|
+
const ids = new Set(all.map((ticket) => ticket.ref.id))
|
|
307
|
+
let chosen = new Set(inputStates)
|
|
308
|
+
if (opts.states) {
|
|
309
|
+
chosen = new Set()
|
|
310
|
+
const originals = Object.entries(manifest.states)
|
|
311
|
+
for (const name of opts.states) {
|
|
312
|
+
const folded = inputStates.filter((state) => state.toLowerCase() === name.toLowerCase())
|
|
313
|
+
const named = [
|
|
314
|
+
...new Set(
|
|
315
|
+
originals
|
|
316
|
+
.filter(([original]) => original.toLowerCase() === name.toLowerCase())
|
|
317
|
+
.map(([, directory]) => directory)
|
|
318
|
+
.filter((directory) => inputStates.includes(directory)),
|
|
319
|
+
),
|
|
320
|
+
]
|
|
321
|
+
const directory =
|
|
322
|
+
inputStates.find((state) => state === name) ??
|
|
323
|
+
(folded.length === 1 ? folded[0] : undefined) ??
|
|
324
|
+
(named.length === 1 ? named[0] : undefined)
|
|
325
|
+
if (directory === undefined)
|
|
326
|
+
problems.push(
|
|
327
|
+
`--states names unknown state "${name}"; the export holds: ${inputStates.join(', ') || 'none'}`,
|
|
328
|
+
)
|
|
329
|
+
else chosen.add(directory)
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const done = (state: string) =>
|
|
333
|
+
manifest.roles
|
|
334
|
+
? (manifest.roles[state]?.includes('done') ?? false)
|
|
335
|
+
: holdsState(state, opts.lifecycle?.done ?? 'done')
|
|
336
|
+
const stateOf = new Map(all.map((ticket) => [ticket.ref.id, ticket.state!]))
|
|
337
|
+
const excluded = (id: string) => ids.has(id) && !chosen.has(stateOf.get(id)!)
|
|
338
|
+
const tickets = all.filter((ticket) => chosen.has(ticket.state!))
|
|
339
|
+
const blockers = new Map<string, string[]>()
|
|
340
|
+
for (const ticket of tickets) {
|
|
341
|
+
const kept: string[] = []
|
|
342
|
+
for (const blocker of ticket.blockedBy ?? []) {
|
|
343
|
+
if (!ids.has(blocker) || blocker === ticket.ref.id)
|
|
344
|
+
throw new Error(`invalid blocker ${ticket.ref.id} → ${blocker}`)
|
|
345
|
+
if (!excluded(blocker)) kept.push(blocker)
|
|
346
|
+
else if (!done(stateOf.get(blocker)!))
|
|
347
|
+
problems.push(`${ticket.ref.id} is blocked by ${blocker}, which --states excludes`)
|
|
348
|
+
}
|
|
349
|
+
blockers.set(ticket.ref.id, kept)
|
|
350
|
+
if (ticket.target !== undefined && excluded(ticket.target))
|
|
351
|
+
problems.push(`${ticket.ref.id} targets ${ticket.target}, which --states excludes`)
|
|
352
|
+
if (migrationSource(manifest) === 'github')
|
|
353
|
+
for (const link of ticket.issueLinks ?? [])
|
|
354
|
+
if (excluded(String(link.issue)))
|
|
355
|
+
problems.push(`${ticket.ref.id} links issue #${link.issue}, which --states excludes`)
|
|
356
|
+
}
|
|
357
|
+
if (opts.states) {
|
|
358
|
+
const from = migrationSource(manifest)
|
|
359
|
+
for (const { build, ticket } of opts.inFlight ?? []) {
|
|
360
|
+
let ref: TicketRef
|
|
361
|
+
try {
|
|
362
|
+
ref = resolveTicketRef(opts.migrations ?? { migrations: [] }, ticket, from, build)
|
|
363
|
+
} catch {
|
|
364
|
+
// Refs outside this export's namespace do not belong to it.
|
|
365
|
+
continue
|
|
366
|
+
}
|
|
367
|
+
if (excluded(ref.id))
|
|
368
|
+
problems.push(`build ${build} is unfinished for ticket ${ref.id}, which --states excludes`)
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return { tickets, states: inputStates.filter((state) => chosen.has(state)), blockers }
|
|
372
|
+
}
|
|
373
|
+
/** Land each input state: a role-holding state in the destination's state for
|
|
374
|
+
* its primary role, any other by name. */
|
|
375
|
+
function planStates(
|
|
376
|
+
inputStates: string[],
|
|
377
|
+
manifest: Manifest,
|
|
378
|
+
lifecycle: TicketLifecycle | undefined,
|
|
379
|
+
existing: string[],
|
|
380
|
+
problems: string[],
|
|
381
|
+
): Record<string, string> {
|
|
382
|
+
const merged = new Set<string>()
|
|
383
|
+
const byRole = (name: string): string | undefined => {
|
|
384
|
+
const held = manifest.roles?.[name]
|
|
385
|
+
if (!lifecycle || !held?.length) return undefined
|
|
386
|
+
const role = LIFECYCLE_ROLES.find((candidate) => held.includes(candidate))!
|
|
387
|
+
const target = roleState(lifecycle, role)
|
|
388
|
+
if (target === undefined) {
|
|
389
|
+
problems.push(
|
|
390
|
+
`state ${name} holds the ${role} role, but the destination has no ${role} state; configure [tickets].${role}State`,
|
|
391
|
+
)
|
|
392
|
+
return undefined
|
|
393
|
+
}
|
|
394
|
+
merged.add(name)
|
|
395
|
+
return matchState(target, existing) ?? target
|
|
396
|
+
}
|
|
397
|
+
return uniqueStateMap(
|
|
398
|
+
inputStates,
|
|
399
|
+
(name) =>
|
|
400
|
+
byRole(name) ??
|
|
401
|
+
matchState(name, existing) ??
|
|
402
|
+
matchState(normalizeStateName(name), existing) ??
|
|
403
|
+
normalizeStateName(name),
|
|
404
|
+
merged,
|
|
405
|
+
)
|
|
406
|
+
}
|
|
407
|
+
/** Issue links rewritten through the mapping. Only an export from GitHub
|
|
408
|
+
* names this repository's tickets by issue number. */
|
|
409
|
+
function mappedIssueLinks(
|
|
410
|
+
links: IssueLink[] | undefined,
|
|
411
|
+
ids: ReadonlySet<string>,
|
|
412
|
+
mapping: Record<string, string>,
|
|
413
|
+
): IssueLink[] {
|
|
414
|
+
return (links ?? []).map((link) => {
|
|
415
|
+
const mapped = ids.has(String(link.issue)) ? mapping[String(link.issue)] : undefined
|
|
416
|
+
return mapped !== undefined && /^[1-9][0-9]*$/.test(mapped)
|
|
417
|
+
? { ...link, issue: Number(mapped) }
|
|
418
|
+
: link
|
|
419
|
+
})
|
|
420
|
+
}
|
|
235
421
|
/** Resume through creation keys, never through content similarity or mapping files. */
|
|
236
422
|
export async function importTickets(opts: MigrationOptions): Promise<MigrationResult> {
|
|
237
423
|
const policy = opts.source.requestedIds
|
|
238
|
-
if (!policy || !opts.source.listStates || !opts.source.addState)
|
|
424
|
+
if ((!policy && !opts.source.allocatesIds) || !opts.source.listStates || !opts.source.addState)
|
|
239
425
|
throw new Error(`ticket source ${opts.source.name} does not support import`)
|
|
240
426
|
const dir = resolve(opts.dir)
|
|
241
427
|
const input = new FileTicketSource({ dir })
|
|
242
|
-
const
|
|
243
|
-
projectTicketTree(
|
|
244
|
-
if (
|
|
245
|
-
!opts.source.integrationTree &&
|
|
246
|
-
tickets.some((t) => t.kind === 'node' || t.target !== undefined)
|
|
247
|
-
)
|
|
248
|
-
throw new Error('target source cannot preserve kind/target metadata')
|
|
249
|
-
const bundles = new Map<string, PortableAsset[]>()
|
|
250
|
-
for (const ticket of tickets) {
|
|
251
|
-
const path = join(dir, ticket.state!, `${ticket.ref.id}.md`)
|
|
252
|
-
bundles.set(
|
|
253
|
-
ticket.ref.id,
|
|
254
|
-
parseTicketFile(path, await readFile(path, 'utf8')).front.attachments ?? [],
|
|
255
|
-
)
|
|
256
|
-
}
|
|
428
|
+
const all = await inventory(input)
|
|
429
|
+
projectTicketTree(all, 'import')
|
|
257
430
|
let manifest: Manifest
|
|
258
431
|
try {
|
|
259
432
|
manifest = manifestSchema.parse(JSON.parse(await readFile(join(dir, MANIFEST), 'utf8')))
|
|
@@ -267,12 +440,38 @@ export async function importTickets(opts: MigrationOptions): Promise<MigrationRe
|
|
|
267
440
|
states: {},
|
|
268
441
|
}
|
|
269
442
|
}
|
|
270
|
-
|
|
443
|
+
// Only actual input directories participate; virtual lifecycle defaults are harmless empty states.
|
|
444
|
+
const directories: string[] = []
|
|
445
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
446
|
+
if (
|
|
447
|
+
!entry.name.startsWith('.') &&
|
|
448
|
+
(entry.isDirectory() ||
|
|
449
|
+
(entry.isSymbolicLink() && (await stat(join(dir, entry.name))).isDirectory()))
|
|
450
|
+
)
|
|
451
|
+
directories.push(entry.name)
|
|
452
|
+
}
|
|
453
|
+
const problems: string[] = []
|
|
454
|
+
const selection = selectTickets(opts, all, directories, manifest, problems)
|
|
455
|
+
const { tickets } = selection
|
|
456
|
+
if (
|
|
457
|
+
!opts.source.integrationTree &&
|
|
458
|
+
tickets.some((t) => t.kind === 'node' || t.target !== undefined)
|
|
459
|
+
)
|
|
460
|
+
throw new Error('target source cannot preserve kind/target metadata')
|
|
461
|
+
if (!opts.source.issueLinks && tickets.some((t) => t.issueLinks?.length))
|
|
462
|
+
throw new TicketIssueLinksUnsupported(opts.source.name)
|
|
463
|
+
if (!opts.source.priority && tickets.some((t) => t.priority === 'urgent'))
|
|
464
|
+
throw new TicketPriorityUnsupported(opts.source.name)
|
|
465
|
+
const bundles = new Map<string, PortableAsset[]>()
|
|
466
|
+
for (const ticket of tickets) {
|
|
467
|
+
const path = join(dir, ticket.state!, `${ticket.ref.id}.md`)
|
|
468
|
+
bundles.set(
|
|
469
|
+
ticket.ref.id,
|
|
470
|
+
parseTicketFile(path, await readFile(path, 'utf8')).front.attachments ?? [],
|
|
471
|
+
)
|
|
472
|
+
}
|
|
271
473
|
const keys = new Set<string>()
|
|
272
474
|
for (const ticket of tickets) {
|
|
273
|
-
for (const blocker of ticket.blockedBy ?? [])
|
|
274
|
-
if (!sourceIds.has(blocker) || blocker === ticket.ref.id)
|
|
275
|
-
throw new Error(`invalid blocker ${ticket.ref.id} → ${blocker}`)
|
|
276
475
|
const key =
|
|
277
476
|
ticket.creationKey ??
|
|
278
477
|
manifest.keys[ticket.ref.id] ??
|
|
@@ -281,7 +480,9 @@ export async function importTickets(opts: MigrationOptions): Promise<MigrationRe
|
|
|
281
480
|
keys.add(key)
|
|
282
481
|
manifest.keys[ticket.ref.id] = key
|
|
283
482
|
}
|
|
284
|
-
|
|
483
|
+
// A source that allocates every id adopts committed creates inside `create`,
|
|
484
|
+
// so only a requested-id policy needs the destination scanned for keys.
|
|
485
|
+
const target = policy ? await inventory(opts.source) : []
|
|
285
486
|
const byKey = new Map<string, Ticket>()
|
|
286
487
|
for (const ticket of target)
|
|
287
488
|
if (ticket.creationKey) {
|
|
@@ -290,47 +491,45 @@ export async function importTickets(opts: MigrationOptions): Promise<MigrationRe
|
|
|
290
491
|
byKey.set(ticket.creationKey, ticket)
|
|
291
492
|
}
|
|
292
493
|
const existingStates = (await opts.source.listStates()).map((state) => state.name)
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
(
|
|
299
|
-
|
|
494
|
+
const states = planStates(selection.states, manifest, opts.lifecycle, existingStates, problems)
|
|
495
|
+
if (!policy && !opts.source.readComments && tickets.some((t) => (t.comments?.length ?? 0) > 0))
|
|
496
|
+
problems.push(`target ${opts.source.name} cannot read comment history`)
|
|
497
|
+
if (opts.source.importProblems)
|
|
498
|
+
problems.push(
|
|
499
|
+
...(await opts.source.importProblems({
|
|
500
|
+
states: [...new Set(Object.values(states))],
|
|
501
|
+
labels: [...new Set(tickets.flatMap((ticket) => ticket.labels))],
|
|
502
|
+
creationKeys: [...keys],
|
|
503
|
+
})),
|
|
300
504
|
)
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const states = uniqueStateMap(
|
|
304
|
-
inputStates,
|
|
305
|
-
(name) =>
|
|
306
|
-
matchState(name, existingStates) ??
|
|
307
|
-
matchState(normalizeStateName(name), existingStates) ??
|
|
308
|
-
normalizeStateName(name),
|
|
309
|
-
)
|
|
505
|
+
if (problems.length)
|
|
506
|
+
throw new Error(`import refused (no target changes):\n${[...new Set(problems)].join('\n')}`)
|
|
310
507
|
const planned = new Map<string, string>()
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
if (
|
|
322
|
-
|
|
323
|
-
|
|
508
|
+
if (policy) {
|
|
509
|
+
const occupied = target.map((ticket) => ticket.ref.id)
|
|
510
|
+
const clashes: string[] = []
|
|
511
|
+
for (const ticket of tickets) {
|
|
512
|
+
const adopted = byKey.get(manifest.keys[ticket.ref.id]!)
|
|
513
|
+
if (adopted) {
|
|
514
|
+
planned.set(ticket.ref.id, adopted.ref.id)
|
|
515
|
+
continue
|
|
516
|
+
}
|
|
517
|
+
const kept = policy.preserve(ticket.ref.id)
|
|
518
|
+
if (kept !== undefined) {
|
|
519
|
+
if (occupied.includes(kept)) clashes.push(`${ticket.ref.id} → ${kept}`)
|
|
520
|
+
planned.set(ticket.ref.id, kept)
|
|
521
|
+
occupied.push(kept)
|
|
522
|
+
}
|
|
324
523
|
}
|
|
524
|
+
if (clashes.length)
|
|
525
|
+
throw new Error(`ticket id clashes (no target changes):\n${clashes.join('\n')}`)
|
|
526
|
+
for (const ticket of tickets)
|
|
527
|
+
if (!planned.has(ticket.ref.id)) {
|
|
528
|
+
const id = policy.allocate(occupied)
|
|
529
|
+
planned.set(ticket.ref.id, id)
|
|
530
|
+
occupied.push(id)
|
|
531
|
+
}
|
|
325
532
|
}
|
|
326
|
-
if (clashes.length)
|
|
327
|
-
throw new Error(`ticket id clashes (no target changes):\n${clashes.join('\n')}`)
|
|
328
|
-
for (const ticket of tickets)
|
|
329
|
-
if (!planned.has(ticket.ref.id)) {
|
|
330
|
-
const id = policy.allocate(occupied)
|
|
331
|
-
planned.set(ticket.ref.id, id)
|
|
332
|
-
occupied.push(id)
|
|
333
|
-
}
|
|
334
533
|
const assets = opts.assets ?? opts.source.assets
|
|
335
534
|
if ([...bundles.values()].some((value) => value.length) && !assets)
|
|
336
535
|
throw new Error('target has no attachment capability')
|
|
@@ -344,13 +543,20 @@ export async function importTickets(opts: MigrationOptions): Promise<MigrationRe
|
|
|
344
543
|
if ((ticket.comments?.length ?? 0) > 0 && adopted && adopted.comments === undefined)
|
|
345
544
|
throw new Error(`target cannot read comment history: ${adopted.ref.id}`)
|
|
346
545
|
}
|
|
347
|
-
// Persist identities before the first target write, including for ordinary
|
|
546
|
+
// Persist identities before the first target write, including for ordinary
|
|
547
|
+
// layouts. The first save's time is the keys' reservation time, and a retry
|
|
548
|
+
// reads it back unchanged.
|
|
549
|
+
manifest.reservedAt ??= new Date().toISOString()
|
|
348
550
|
await atomicJson(join(dir, MANIFEST), manifest)
|
|
349
551
|
const mapping: Record<string, string> = Object.create(null)
|
|
350
552
|
const mappingPath = join(dir, IMPORT_MAP)
|
|
351
553
|
const saveMap = () =>
|
|
352
554
|
atomicJson(mappingPath, { version: 1, identity: manifest.identity, states, tickets: mapping })
|
|
353
555
|
await saveMap()
|
|
556
|
+
// Links between the exported issues wait for their targets' new numbers.
|
|
557
|
+
const linkIds = migrationSource(manifest) === 'github' ? new Set(all.map((t) => t.ref.id)) : null
|
|
558
|
+
const createLinks = (ticket: Ticket) =>
|
|
559
|
+
(ticket.issueLinks ?? []).filter((link) => !linkIds?.has(String(link.issue)))
|
|
354
560
|
try {
|
|
355
561
|
for (const state of new Set(Object.values(states)))
|
|
356
562
|
if (!existingStates.includes(state)) {
|
|
@@ -370,6 +576,7 @@ export async function importTickets(opts: MigrationOptions): Promise<MigrationRe
|
|
|
370
576
|
for (const [from, to] of Object.entries(states)) opts.print?.(`state ${from} → ${to}`)
|
|
371
577
|
for (const ticket of tickets) {
|
|
372
578
|
const key = manifest.keys[ticket.ref.id]!
|
|
579
|
+
const links = createLinks(ticket)
|
|
373
580
|
const result =
|
|
374
581
|
byKey.get(key) ??
|
|
375
582
|
(await opts.source.create(
|
|
@@ -378,11 +585,16 @@ export async function importTickets(opts: MigrationOptions): Promise<MigrationRe
|
|
|
378
585
|
body: ticket.body,
|
|
379
586
|
labels: ticket.labels,
|
|
380
587
|
...(opts.source.integrationTree ? { kind: ticket.kind ?? 'work' } : {}),
|
|
588
|
+
...(opts.source.issueLinks && links.length ? { issueLinks: links } : {}),
|
|
589
|
+
...(opts.source.priority && ticket.priority === 'urgent'
|
|
590
|
+
? { priority: ticket.priority }
|
|
591
|
+
: {}),
|
|
381
592
|
},
|
|
382
593
|
{
|
|
383
594
|
state: states[ticket.state!]!,
|
|
384
595
|
idempotencyKey: key,
|
|
385
|
-
|
|
596
|
+
idempotencyKeyReservedAt: manifest.reservedAt,
|
|
597
|
+
...(policy ? { requestedId: planned.get(ticket.ref.id)! } : {}),
|
|
386
598
|
},
|
|
387
599
|
))
|
|
388
600
|
mapping[ticket.ref.id] = result.ref.id
|
|
@@ -399,15 +611,25 @@ export async function importTickets(opts: MigrationOptions): Promise<MigrationRe
|
|
|
399
611
|
target: ticket.target === undefined ? null : mapping[ticket.target]!,
|
|
400
612
|
})
|
|
401
613
|
}
|
|
614
|
+
if (linkIds)
|
|
615
|
+
for (const ticket of tickets) {
|
|
616
|
+
const links = mappedIssueLinks(ticket.issueLinks, linkIds, mapping)
|
|
617
|
+
if (JSON.stringify(links) !== JSON.stringify(createLinks(ticket)))
|
|
618
|
+
await opts.source.update(mapping[ticket.ref.id]!, { issueLinks: links })
|
|
619
|
+
}
|
|
402
620
|
for (const ticket of tickets) {
|
|
403
621
|
const id = mapping[ticket.ref.id]!
|
|
404
|
-
for (const blocker of ticket.
|
|
622
|
+
for (const blocker of selection.blockers.get(ticket.ref.id) ?? [])
|
|
405
623
|
await opts.source.addBlocker(id, mapping[blocker]!)
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
624
|
+
// An explicit history read where the source has one, so `get` stays
|
|
625
|
+
// comment-free on recurring paths.
|
|
626
|
+
const history = opts.source.readComments
|
|
627
|
+
? await opts.source.readComments(id)
|
|
628
|
+
: await opts.source.get(id).then((fresh) => (fresh === null ? null : fresh.comments))
|
|
629
|
+
if (history === null) throw new Error(`target disappeared: ${id}`)
|
|
630
|
+
if ((ticket.comments?.length ?? 0) && history === undefined)
|
|
409
631
|
throw new Error(`target cannot read comment history: ${id}`)
|
|
410
|
-
const bodies = new Set(
|
|
632
|
+
const bodies = new Set(history?.map((comment) => comment.body))
|
|
411
633
|
for (const comment of ticket.comments ?? [])
|
|
412
634
|
if (!bodies.has(comment.body)) {
|
|
413
635
|
await opts.source.comment(id, comment.body)
|