@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
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { normalizeTicket } from './tree'
|
|
2
2
|
import { hostedRequestedIds } from './requested-id'
|
|
3
3
|
import { TicketRevisionConflict } from './revision'
|
|
4
|
+
import { TicketIssueLinksUnsupported } from './issue-links'
|
|
5
|
+
import { TicketPriorityUnsupported } from './priority'
|
|
6
|
+
import { ticketLifecycle } from './lifecycle'
|
|
7
|
+
import type { TicketsConfig } from '../../config/schema'
|
|
4
8
|
import type {
|
|
5
9
|
DependencyState,
|
|
6
10
|
Ticket,
|
|
@@ -23,12 +27,24 @@ import {
|
|
|
23
27
|
type HostedTicketPolicy,
|
|
24
28
|
TICKET_COMMENTS_HEADER,
|
|
25
29
|
TICKET_COMMENTS_CAPABILITY,
|
|
30
|
+
TICKET_ISSUE_LINKS_HEADER,
|
|
31
|
+
TICKET_ISSUE_LINKS_CAPABILITY,
|
|
32
|
+
TICKET_PRIORITY_HEADER,
|
|
33
|
+
TICKET_PRIORITY_CAPABILITY,
|
|
34
|
+
TICKET_DEPENDENCY_STATE_HEADER,
|
|
35
|
+
TICKET_DEPENDENCY_STATE_CAPABILITY,
|
|
36
|
+
TICKET_POLICY_ROLES_HEADER,
|
|
37
|
+
TICKET_POLICY_ROLES_CAPABILITY,
|
|
38
|
+
TICKET_TARGETING_HEADER,
|
|
39
|
+
TICKET_TARGETING_CAPABILITY,
|
|
40
|
+
TICKET_TARGETING_PROBE_NODE,
|
|
26
41
|
dependencyStatesWireSchema,
|
|
27
42
|
type HostedTicketContext,
|
|
28
43
|
successWireSchema,
|
|
29
44
|
ticketListingWireSchema,
|
|
30
45
|
ticketWireSchema,
|
|
31
46
|
ticketStatesWireSchema,
|
|
47
|
+
ticketStateCountsWireSchema,
|
|
32
48
|
ticketStateCreateWireSchema,
|
|
33
49
|
} from './remote-protocol'
|
|
34
50
|
import {
|
|
@@ -49,16 +65,48 @@ export interface HostedTicketSourceOptions extends HostedTicketContext {
|
|
|
49
65
|
fetchFn?: HostedTicketFetch
|
|
50
66
|
}
|
|
51
67
|
|
|
52
|
-
/**
|
|
68
|
+
/** The project ticket policy a hosted `[tickets]` table publishes. The backlog
|
|
69
|
+
* and rejected roles appear only when configured, so a policy without them is
|
|
70
|
+
* exactly what services predating the roles accept. */
|
|
71
|
+
export function hostedTicketPolicy(tickets: TicketsConfig): HostedTicketPolicy {
|
|
72
|
+
if (tickets.teamKey === undefined) throw new Error('[tickets].source = "hosted" requires teamKey')
|
|
73
|
+
const lifecycle = ticketLifecycle(tickets)
|
|
74
|
+
return {
|
|
75
|
+
version: 1,
|
|
76
|
+
tickets: {
|
|
77
|
+
source: 'hosted',
|
|
78
|
+
teamKey: tickets.teamKey,
|
|
79
|
+
readyState: lifecycle.ready,
|
|
80
|
+
triageState: lifecycle.triage,
|
|
81
|
+
claimedState: lifecycle.doing,
|
|
82
|
+
doneState: lifecycle.done,
|
|
83
|
+
createState: lifecycle.create,
|
|
84
|
+
proposalState: lifecycle.proposal,
|
|
85
|
+
...(tickets.readyLabels !== undefined ? { readyLabels: tickets.readyLabels } : {}),
|
|
86
|
+
...(lifecycle.backlog !== undefined ? { backlogState: lifecycle.backlog } : {}),
|
|
87
|
+
...(lifecycle.rejected !== undefined ? { rejectedState: lifecycle.rejected } : {}),
|
|
88
|
+
},
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Full TicketSource client for a hosted Autobuild service. Targeted listing
|
|
93
|
+
* is declared only after a response from the service has carried the
|
|
94
|
+
* targeting echo; product code obtains the source through `createTicketSource`,
|
|
95
|
+
* which settles that decision before returning it. */
|
|
53
96
|
export class HostedTicketSource implements TicketSource {
|
|
54
97
|
readonly name = 'hosted'
|
|
55
98
|
readonly integrationTree = true
|
|
99
|
+
readonly issueLinks = true
|
|
100
|
+
readonly priority = true
|
|
56
101
|
readonly requestedIds: ReturnType<typeof hostedRequestedIds>
|
|
57
102
|
readonly assets: import('../types').TicketAssetStore
|
|
58
103
|
private readonly base: string
|
|
59
104
|
private readonly token: string
|
|
60
105
|
private readonly fetchFn: HostedTicketFetch
|
|
61
106
|
private readonly context: HostedTicketContext
|
|
107
|
+
/** Unknown until a response settles it; see `noteTargeting`. */
|
|
108
|
+
private targetingSupport: boolean | undefined
|
|
109
|
+
private readonly targeted = (nodeId: string) => this.targetedListing(nodeId)
|
|
62
110
|
|
|
63
111
|
constructor(options: HostedTicketSourceOptions) {
|
|
64
112
|
this.requestedIds = hostedRequestedIds(options.teamKey)
|
|
@@ -86,18 +134,44 @@ export class HostedTicketSource implements TicketSource {
|
|
|
86
134
|
}
|
|
87
135
|
|
|
88
136
|
async synchronizePolicy(policy: HostedTicketPolicy): Promise<void> {
|
|
89
|
-
|
|
137
|
+
const parsed = hostedTicketPolicySchema.parse(policy)
|
|
138
|
+
const namesRoles =
|
|
139
|
+
parsed.tickets.backlogState !== undefined || parsed.tickets.rejectedState !== undefined
|
|
140
|
+
await this.request('policy', parsed, successWireSchema, { policyRoles: namesRoles })
|
|
90
141
|
}
|
|
91
142
|
|
|
92
|
-
|
|
93
|
-
|
|
143
|
+
/** Present only once the service has positively advertised `list-targeting`;
|
|
144
|
+
* while support is unknown or refused, observation keeps the exhaustive path. */
|
|
145
|
+
get listTargeting(): TicketSource['listTargeting'] {
|
|
146
|
+
return this.targetingSupport === true ? this.targeted : undefined
|
|
94
147
|
}
|
|
95
148
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
149
|
+
/** Settles targeted-listing support before any observation runs: free when a
|
|
150
|
+
* response already settled it, otherwise one `list-targeting` probe for a
|
|
151
|
+
* node id that can never exist. Throws when the answer is inconclusive. */
|
|
152
|
+
async negotiateTargeting(): Promise<boolean> {
|
|
153
|
+
if (this.targetingSupport !== undefined) return this.targetingSupport
|
|
154
|
+
const response = await this.send('list-targeting', { nodeId: TICKET_TARGETING_PROBE_NODE })
|
|
155
|
+
if (this.targetingSupport === undefined && (response.status === 404 || response.status === 400))
|
|
156
|
+
this.targetingSupport = false
|
|
157
|
+
await response.body?.cancel()
|
|
158
|
+
if (this.targetingSupport === undefined)
|
|
159
|
+
throw new Error(
|
|
160
|
+
`could not negotiate targeted listing with the ticket service (HTTP ${response.status})`,
|
|
161
|
+
)
|
|
162
|
+
return this.targetingSupport
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Any response carrying the echo declares support; an ok response without
|
|
166
|
+
* it comes from a service predating `list-targeting`. A non-ok response
|
|
167
|
+
* without it (a gateway page, say) proves nothing. */
|
|
168
|
+
private noteTargeting(response: Response): void {
|
|
169
|
+
if (response.headers.get(TICKET_TARGETING_HEADER) === TICKET_TARGETING_CAPABILITY)
|
|
170
|
+
this.targetingSupport = true
|
|
171
|
+
else if (response.ok) this.targetingSupport = false
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private async send(operation: string, input: unknown): Promise<Response> {
|
|
101
175
|
const response = await this.fetchFn(`${this.base}/tickets/${operation}`, {
|
|
102
176
|
method: 'POST',
|
|
103
177
|
headers: {
|
|
@@ -106,12 +180,55 @@ export class HostedTicketSource implements TicketSource {
|
|
|
106
180
|
[TICKET_COMMENTS_HEADER]: TICKET_COMMENTS_CAPABILITY,
|
|
107
181
|
authorization: `Bearer ${this.token}`,
|
|
108
182
|
[TICKET_REVISIONS_HEADER]: TICKET_REVISIONS_CAPABILITY,
|
|
183
|
+
[TICKET_ISSUE_LINKS_HEADER]: TICKET_ISSUE_LINKS_CAPABILITY,
|
|
184
|
+
[TICKET_PRIORITY_HEADER]: TICKET_PRIORITY_CAPABILITY,
|
|
185
|
+
[TICKET_DEPENDENCY_STATE_HEADER]: TICKET_DEPENDENCY_STATE_CAPABILITY,
|
|
186
|
+
[TICKET_POLICY_ROLES_HEADER]: TICKET_POLICY_ROLES_CAPABILITY,
|
|
187
|
+
[TICKET_TARGETING_HEADER]: TICKET_TARGETING_CAPABILITY,
|
|
109
188
|
[AUTOBUILD_VERSION_HEADER]: AUTOBUILD_VERSION,
|
|
110
189
|
[REMOTE_STORE_PROTOCOL_VERSION_HEADER]: REMOTE_STORE_PROTOCOL_VERSION,
|
|
111
190
|
},
|
|
112
191
|
body: JSON.stringify({ context: this.context, input }),
|
|
113
192
|
})
|
|
193
|
+
this.noteTargeting(response)
|
|
194
|
+
return response
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
private project(ticket: Ticket): Ticket {
|
|
198
|
+
return normalizeTicket({ ...ticket, ref: { ...ticket.ref, source: this.name } })
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
private async request<T>(
|
|
202
|
+
operation: string,
|
|
203
|
+
input: unknown,
|
|
204
|
+
schema: { parse(value: unknown): T },
|
|
205
|
+
names: { issueLinks?: boolean; priority?: boolean; policyRoles?: boolean } = {},
|
|
206
|
+
): Promise<T> {
|
|
207
|
+
const response = await this.send(operation, input)
|
|
114
208
|
if (!response.ok) {
|
|
209
|
+
// A service predating targeted listing has no such route (or refuses it
|
|
210
|
+
// with a strict schema) and never echoes the capability header. The read
|
|
211
|
+
// fails closed; the next observation takes the negotiated exhaustive path.
|
|
212
|
+
if (
|
|
213
|
+
operation === 'list-targeting' &&
|
|
214
|
+
(response.status === 404 || response.status === 400) &&
|
|
215
|
+
response.headers.get(TICKET_TARGETING_HEADER) !== TICKET_TARGETING_CAPABILITY
|
|
216
|
+
) {
|
|
217
|
+
this.targetingSupport = false
|
|
218
|
+
throw new Error(
|
|
219
|
+
'ticket service predates targeted listing (list-targeting); upgrade the service',
|
|
220
|
+
)
|
|
221
|
+
}
|
|
222
|
+
// A service predating the roles refuses them with its strict policy schema
|
|
223
|
+
// and never echoes the capability header.
|
|
224
|
+
if (
|
|
225
|
+
names.policyRoles &&
|
|
226
|
+
response.status === 400 &&
|
|
227
|
+
response.headers.get(TICKET_POLICY_ROLES_HEADER) !== TICKET_POLICY_ROLES_CAPABILITY
|
|
228
|
+
)
|
|
229
|
+
throw new Error(
|
|
230
|
+
'ticket service predates backlog/rejected roles in ticket policy; upgrade the service or unset [tickets].backlogState and rejectedState',
|
|
231
|
+
)
|
|
115
232
|
let message = `ticket service responded ${response.status}`
|
|
116
233
|
try {
|
|
117
234
|
const body = (await response.json()) as Record<string, unknown>
|
|
@@ -122,9 +239,33 @@ export class HostedTicketSource implements TicketSource {
|
|
|
122
239
|
typeof body.id === 'string'
|
|
123
240
|
)
|
|
124
241
|
throw new TicketRevisionConflict(body.id, body.expectedRevision, body.currentRevision)
|
|
242
|
+
if (body.code === 'issue-links-unsupported')
|
|
243
|
+
throw new TicketIssueLinksUnsupported(this.name)
|
|
244
|
+
if (body.code === 'priority-unsupported') throw new TicketPriorityUnsupported(this.name)
|
|
125
245
|
message = errorBodySchema.parse(body).error
|
|
246
|
+
// A server predating issue links or priority refuses the unknown key with
|
|
247
|
+
// its strict request schema and never echoes the capability header.
|
|
248
|
+
if (
|
|
249
|
+
names.issueLinks &&
|
|
250
|
+
response.status === 400 &&
|
|
251
|
+
response.headers.get(TICKET_ISSUE_LINKS_HEADER) !== TICKET_ISSUE_LINKS_CAPABILITY &&
|
|
252
|
+
message.includes('issueLinks')
|
|
253
|
+
)
|
|
254
|
+
throw new TicketIssueLinksUnsupported(this.name)
|
|
255
|
+
if (
|
|
256
|
+
names.priority &&
|
|
257
|
+
response.status === 400 &&
|
|
258
|
+
response.headers.get(TICKET_PRIORITY_HEADER) !== TICKET_PRIORITY_CAPABILITY &&
|
|
259
|
+
message.includes('priority')
|
|
260
|
+
)
|
|
261
|
+
throw new TicketPriorityUnsupported(this.name)
|
|
126
262
|
} catch (error) {
|
|
127
|
-
if (
|
|
263
|
+
if (
|
|
264
|
+
error instanceof TicketRevisionConflict ||
|
|
265
|
+
error instanceof TicketIssueLinksUnsupported ||
|
|
266
|
+
error instanceof TicketPriorityUnsupported
|
|
267
|
+
)
|
|
268
|
+
throw error
|
|
128
269
|
// Keep the status-only safe fallback for non-protocol responses.
|
|
129
270
|
}
|
|
130
271
|
if (response.status === 401 || response.status === 403) throw new AuthError(message)
|
|
@@ -145,14 +286,25 @@ export class HostedTicketSource implements TicketSource {
|
|
|
145
286
|
return { ...listing, tickets: listing.tickets.map((ticket) => this.project(ticket)) }
|
|
146
287
|
}
|
|
147
288
|
|
|
289
|
+
/** The exhaustive listing: non-recurring callers, and integration
|
|
290
|
+
* observation against a service that negotiated no targeted listing. */
|
|
148
291
|
listAll(): Promise<TicketListing> {
|
|
149
292
|
return this.listReady({})
|
|
150
293
|
}
|
|
151
294
|
|
|
295
|
+
private async targetedListing(nodeId: string): Promise<TicketListing> {
|
|
296
|
+
const listing = await this.request('list-targeting', { nodeId }, ticketListingWireSchema)
|
|
297
|
+
return { ...listing, tickets: listing.tickets.map((ticket) => this.project(ticket)) }
|
|
298
|
+
}
|
|
299
|
+
|
|
152
300
|
async listStates() {
|
|
153
301
|
return this.request('states', {}, ticketStatesWireSchema)
|
|
154
302
|
}
|
|
155
303
|
|
|
304
|
+
async countStates(names: readonly string[]) {
|
|
305
|
+
return this.request('state-counts', { names: [...names] }, ticketStateCountsWireSchema)
|
|
306
|
+
}
|
|
307
|
+
|
|
156
308
|
async addState(name: string, opts: { about?: string } = {}) {
|
|
157
309
|
return this.request('add-state', { name, ...opts }, ticketStateCreateWireSchema)
|
|
158
310
|
}
|
|
@@ -174,8 +326,18 @@ export class HostedTicketSource implements TicketSource {
|
|
|
174
326
|
await this.request('transition', { id, state }, successWireSchema)
|
|
175
327
|
}
|
|
176
328
|
|
|
329
|
+
// Normal is the default, so a plain create never names priority and keeps
|
|
330
|
+
// working against a service predating it.
|
|
177
331
|
async create(draft: TicketDraft, options: TicketCreateOptions = {}): Promise<Ticket> {
|
|
178
|
-
|
|
332
|
+
const { priority, ...rest } = draft
|
|
333
|
+
const write = priority === 'urgent' ? { ...rest, priority } : rest
|
|
334
|
+
const { idempotencyKeyReservedAt: _reservedAt, ...wireOptions } = options
|
|
335
|
+
return this.project(
|
|
336
|
+
await this.request('create', { draft: write, options: wireOptions }, ticketWireSchema, {
|
|
337
|
+
issueLinks: write.issueLinks !== undefined,
|
|
338
|
+
priority: priority === 'urgent',
|
|
339
|
+
}),
|
|
340
|
+
)
|
|
179
341
|
}
|
|
180
342
|
|
|
181
343
|
async mutateIfRevision(
|
|
@@ -183,11 +345,24 @@ export class HostedTicketSource implements TicketSource {
|
|
|
183
345
|
expectedRevision: string,
|
|
184
346
|
mutation: TicketMutation,
|
|
185
347
|
): Promise<void> {
|
|
186
|
-
await this.request(
|
|
348
|
+
await this.request(
|
|
349
|
+
'mutate-if-revision',
|
|
350
|
+
{ id, expectedRevision, mutation },
|
|
351
|
+
successWireSchema,
|
|
352
|
+
mutation.kind === 'update'
|
|
353
|
+
? {
|
|
354
|
+
issueLinks: mutation.patch.issueLinks !== undefined,
|
|
355
|
+
priority: mutation.patch.priority !== undefined,
|
|
356
|
+
}
|
|
357
|
+
: {},
|
|
358
|
+
)
|
|
187
359
|
}
|
|
188
360
|
|
|
189
361
|
async update(id: string, patch: TicketUpdate): Promise<void> {
|
|
190
|
-
await this.request('update', { id, patch }, successWireSchema
|
|
362
|
+
await this.request('update', { id, patch }, successWireSchema, {
|
|
363
|
+
issueLinks: patch.issueLinks !== undefined,
|
|
364
|
+
priority: patch.priority !== undefined,
|
|
365
|
+
})
|
|
191
366
|
}
|
|
192
367
|
|
|
193
368
|
async addBlocker(id: string, blockerId: string): Promise<void> {
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto'
|
|
2
2
|
import type { Ticket, TicketMutation, TicketSource } from '../types'
|
|
3
|
+
import { normalizeIssueLinks } from './issue-links'
|
|
3
4
|
|
|
4
5
|
/** Content versions intentionally return to the same value after an exact revert. */
|
|
5
6
|
export function ticketRevision(
|
|
6
|
-
ticket: Pick<
|
|
7
|
+
ticket: Pick<
|
|
8
|
+
Ticket,
|
|
9
|
+
| 'title'
|
|
10
|
+
| 'body'
|
|
11
|
+
| 'labels'
|
|
12
|
+
| 'state'
|
|
13
|
+
| 'blockedBy'
|
|
14
|
+
| 'kind'
|
|
15
|
+
| 'target'
|
|
16
|
+
| 'issueLinks'
|
|
17
|
+
| 'priority'
|
|
18
|
+
> & {
|
|
7
19
|
comments?: Ticket['comments']
|
|
8
20
|
attachments?: unknown
|
|
9
21
|
},
|
|
10
22
|
): string {
|
|
23
|
+
const issueLinks = normalizeIssueLinks(ticket.issueLinks ?? [])
|
|
11
24
|
return createHash('sha256')
|
|
12
25
|
.update(
|
|
13
26
|
JSON.stringify([
|
|
@@ -21,6 +34,14 @@ export function ticketRevision(
|
|
|
21
34
|
...(ticket.comments !== undefined || ticket.attachments !== undefined
|
|
22
35
|
? [ticket.comments ?? null, ticket.attachments ?? null]
|
|
23
36
|
: []),
|
|
37
|
+
// Appended only when nonempty so revisions of tickets without links,
|
|
38
|
+
// in every source, stay exactly what they were before links existed.
|
|
39
|
+
...(issueLinks.length > 0
|
|
40
|
+
? [['issueLinks', issueLinks.map((link) => [link.issue, link.intent])]]
|
|
41
|
+
: []),
|
|
42
|
+
// Appended only when urgent, for the same reason: normal tickets keep
|
|
43
|
+
// the revisions they had before priority existed.
|
|
44
|
+
...(ticket.priority === 'urgent' ? [['priority', 'urgent']] : []),
|
|
24
45
|
]),
|
|
25
46
|
)
|
|
26
47
|
.digest('hex')
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { TicketSource, TicketStateCount } from '../types'
|
|
2
|
+
|
|
1
3
|
/** Shared state rules; configured names are deliberately not create-validated. */
|
|
2
4
|
export const STATE_NAME_RULE =
|
|
3
5
|
'a state name is one to forty characters of lowercase letters, digits, and hyphens, starting with a letter'
|
|
@@ -43,6 +45,47 @@ export function resolveState(
|
|
|
43
45
|
)
|
|
44
46
|
}
|
|
45
47
|
|
|
48
|
+
/** Ticket count of the named state using `resolveState`'s matching (exact,
|
|
49
|
+
* else one case-insensitive match); zero or ambiguous matches are unknown. */
|
|
50
|
+
export function triageStateCount(
|
|
51
|
+
states: readonly TicketStateCount[],
|
|
52
|
+
name: string,
|
|
53
|
+
): number | undefined {
|
|
54
|
+
const exact = states.find((state) => state.name === name)
|
|
55
|
+
if (exact !== undefined) return exact.tickets
|
|
56
|
+
const matches = states.filter((state) => state.name.toLowerCase() === name.toLowerCase())
|
|
57
|
+
return matches.length === 1 ? matches[0]?.tickets : undefined
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** One bounded display count for the named state: a single
|
|
61
|
+
* `countStates([name])` request, never a listing. Undefined when the source
|
|
62
|
+
* has no bounded counts or the name does not resolve uniquely; rejects when
|
|
63
|
+
* the read fails, so callers can keep their last good value. */
|
|
64
|
+
export async function boundedStateCount(
|
|
65
|
+
source: Pick<TicketSource, 'countStates'>,
|
|
66
|
+
name: string,
|
|
67
|
+
): Promise<number | undefined> {
|
|
68
|
+
if (source.countStates === undefined) return undefined
|
|
69
|
+
return triageStateCount(await source.countStates([name]), name)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Canonical names for requested states using `resolveState`'s matching
|
|
73
|
+
* (exact, else one case-insensitive match); unmatched or ambiguous names are
|
|
74
|
+
* dropped, duplicates collapse, and request order is kept. */
|
|
75
|
+
export function matchStateNames(names: readonly string[], existing: readonly string[]): string[] {
|
|
76
|
+
const matched: string[] = []
|
|
77
|
+
for (const name of names) {
|
|
78
|
+
let canonical: string | undefined
|
|
79
|
+
if (existing.includes(name)) canonical = name
|
|
80
|
+
else {
|
|
81
|
+
const matches = existing.filter((state) => state.toLowerCase() === name.toLowerCase())
|
|
82
|
+
if (matches.length === 1) canonical = matches[0]
|
|
83
|
+
}
|
|
84
|
+
if (canonical !== undefined && !matched.includes(canonical)) matched.push(canonical)
|
|
85
|
+
}
|
|
86
|
+
return matched
|
|
87
|
+
}
|
|
88
|
+
|
|
46
89
|
/** Portable directory vocabulary, without guessing lifecycle roles. */
|
|
47
90
|
export function normalizeStateName(name: string): string {
|
|
48
91
|
if (/^[a-z][a-z0-9-]{0,39}$/.test(name)) return name
|
|
@@ -1,22 +1,42 @@
|
|
|
1
1
|
import type { Ticket, TicketDraft, TicketSource, TicketUpdate } from '../types'
|
|
2
|
+
import { checkTicketRevision } from './revision'
|
|
3
|
+
import { validateTicketUpdate } from './update'
|
|
4
|
+
import { refuseUnsupportedIssueLinks } from './issue-links'
|
|
5
|
+
import { refuseUnsupportedPriority, withoutUnsupportedPriority } from './priority'
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
|
|
7
|
+
/** Sources without a capability cannot present that capability's fields. */
|
|
8
|
+
export function normalizeTicket(
|
|
9
|
+
ticket: Ticket,
|
|
10
|
+
supported = true,
|
|
11
|
+
issueLinks = true,
|
|
12
|
+
priority = true,
|
|
13
|
+
): Ticket {
|
|
14
|
+
const { target, issueLinks: links, priority: urgency, ...rest } = ticket
|
|
5
15
|
return {
|
|
6
16
|
...rest,
|
|
7
17
|
kind: supported ? (ticket.kind ?? 'work') : 'work',
|
|
8
18
|
...(supported && target !== undefined ? { target } : {}),
|
|
19
|
+
...(issueLinks && links !== undefined ? { issueLinks: links } : {}),
|
|
20
|
+
// Normal is the absence of the field, so strict wire schemas never see it.
|
|
21
|
+
...(priority && urgency === 'urgent' ? { priority: urgency } : {}),
|
|
9
22
|
}
|
|
10
23
|
}
|
|
11
24
|
|
|
25
|
+
/** Apply the source's own capabilities to a ticket it returned. */
|
|
26
|
+
export function normalizeSourceTicket(source: TicketSource, ticket: Ticket): Ticket {
|
|
27
|
+
return normalizeTicket(ticket, !!source.integrationTree, !!source.issueLinks, !!source.priority)
|
|
28
|
+
}
|
|
29
|
+
|
|
12
30
|
export function refuseUnsupportedMetadata(
|
|
13
31
|
source: TicketSource,
|
|
14
32
|
patch: TicketDraft | TicketUpdate,
|
|
15
33
|
): void {
|
|
16
34
|
if (!source.integrationTree && (patch.kind !== undefined || patch.target !== undefined))
|
|
17
35
|
throw new Error(
|
|
18
|
-
`${source.name} ticket source does not support kind/target writes; use a source with integrationTree support (file, Linear or hosted)`,
|
|
36
|
+
`${source.name} ticket source does not support kind/target writes; use a source with integrationTree support (file, Linear, GitHub or hosted)`,
|
|
19
37
|
)
|
|
38
|
+
refuseUnsupportedIssueLinks(source, patch)
|
|
39
|
+
refuseUnsupportedPriority(source, patch)
|
|
20
40
|
}
|
|
21
41
|
|
|
22
42
|
/** Validate before any part of a mixed patch is written. Canonical refs close alias cycles. */
|
|
@@ -66,6 +86,13 @@ export async function validateTicketTree(
|
|
|
66
86
|
return canonical
|
|
67
87
|
}
|
|
68
88
|
|
|
89
|
+
/** Strip a `normal` no-op for a source without priority, after validating the
|
|
90
|
+
* patch it named so a stripped value is never an unchecked one. */
|
|
91
|
+
function writablePatch(source: TicketSource, patch: TicketUpdate): TicketUpdate {
|
|
92
|
+
if (source.priority || patch.priority === undefined) return patch
|
|
93
|
+
return withoutUnsupportedPriority(source, validateTicketUpdate(patch))
|
|
94
|
+
}
|
|
95
|
+
|
|
69
96
|
/** Forward through an empty facade so frozen source properties do not constrain
|
|
70
97
|
* proxy results. Methods and accessors still receive the original source. */
|
|
71
98
|
export function compatibleTicketSource(source: TicketSource): TicketSource {
|
|
@@ -77,27 +104,36 @@ export function compatibleTicketSource(source: TicketSource): TicketSource {
|
|
|
77
104
|
if (property === 'get')
|
|
78
105
|
return async (id: string) => {
|
|
79
106
|
const ticket = await target.get(id)
|
|
80
|
-
return ticket ?
|
|
107
|
+
return ticket ? normalizeSourceTicket(target, ticket) : null
|
|
81
108
|
}
|
|
82
|
-
if (
|
|
109
|
+
if (
|
|
110
|
+
property === 'listReady' ||
|
|
111
|
+
property === 'listAll' ||
|
|
112
|
+
property === 'listPage' ||
|
|
113
|
+
property === 'listTargeting'
|
|
114
|
+
)
|
|
83
115
|
return async (...args: unknown[]) => {
|
|
84
116
|
const listing = await value.apply(target, args)
|
|
85
117
|
return {
|
|
86
118
|
...listing,
|
|
87
|
-
tickets: listing.tickets.map((ticket: Ticket) =>
|
|
88
|
-
normalizeTicket(ticket, !!target.integrationTree),
|
|
89
|
-
),
|
|
119
|
+
tickets: listing.tickets.map((ticket: Ticket) => normalizeSourceTicket(target, ticket)),
|
|
90
120
|
}
|
|
91
121
|
}
|
|
92
122
|
if (property === 'create')
|
|
93
123
|
return async (draft: TicketDraft, ...args: unknown[]) => {
|
|
94
124
|
refuseUnsupportedMetadata(target, draft)
|
|
95
|
-
return
|
|
125
|
+
return normalizeSourceTicket(
|
|
126
|
+
target,
|
|
127
|
+
await value.call(target, withoutUnsupportedPriority(target, draft), ...args),
|
|
128
|
+
)
|
|
96
129
|
}
|
|
97
130
|
if (property === 'update')
|
|
98
131
|
return async (id: string, patch: TicketUpdate) => {
|
|
99
132
|
refuseUnsupportedMetadata(target, patch)
|
|
100
|
-
|
|
133
|
+
const write = writablePatch(target, patch)
|
|
134
|
+
// A normal-only patch on a source without priority changes nothing.
|
|
135
|
+
if (write !== patch && Object.keys(write).length === 0) return
|
|
136
|
+
return target.update(id, write)
|
|
101
137
|
}
|
|
102
138
|
if (property === 'mutateIfRevision')
|
|
103
139
|
return async (
|
|
@@ -105,8 +141,18 @@ export function compatibleTicketSource(source: TicketSource): TicketSource {
|
|
|
105
141
|
revision: string,
|
|
106
142
|
mutation: Parameters<NonNullable<TicketSource['mutateIfRevision']>>[2],
|
|
107
143
|
) => {
|
|
108
|
-
if (mutation.kind
|
|
109
|
-
|
|
144
|
+
if (mutation.kind !== 'update') return value.call(target, id, revision, mutation)
|
|
145
|
+
refuseUnsupportedMetadata(target, mutation.patch)
|
|
146
|
+
const patch = writablePatch(target, mutation.patch)
|
|
147
|
+
if (patch !== mutation.patch && Object.keys(patch).length === 0) {
|
|
148
|
+
// Nothing to write, but a stale revision is still refused.
|
|
149
|
+
if (!revision.trim()) throw new Error('expected revision must be nonblank')
|
|
150
|
+
const current = await target.get(id)
|
|
151
|
+
if (!current) throw new Error(`${target.name} ticket source: unknown ticket "${id}"`)
|
|
152
|
+
checkTicketRevision(current, revision)
|
|
153
|
+
return
|
|
154
|
+
}
|
|
155
|
+
return value.call(target, id, revision, { kind: 'update', patch })
|
|
110
156
|
}
|
|
111
157
|
return value.bind(target)
|
|
112
158
|
},
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod'
|
|
2
2
|
import { expandIssues } from '../../zod-issues'
|
|
3
3
|
import type { TicketUpdate } from '../types'
|
|
4
|
+
import { issueLinksInputSchema, normalizeIssueLinks } from './issue-links'
|
|
5
|
+
import { ticketPrioritySchema } from './priority'
|
|
4
6
|
|
|
5
7
|
const ticketUpdateSchema = z
|
|
6
8
|
.strictObject({
|
|
@@ -19,6 +21,8 @@ const ticketUpdateSchema = z
|
|
|
19
21
|
.refine((value) => value.trim().length > 0, 'body must not be blank')
|
|
20
22
|
.optional(),
|
|
21
23
|
labels: z.array(z.string()).optional(),
|
|
24
|
+
issueLinks: issueLinksInputSchema.optional(),
|
|
25
|
+
priority: ticketPrioritySchema.optional(),
|
|
22
26
|
})
|
|
23
27
|
.refine(
|
|
24
28
|
(patch) =>
|
|
@@ -26,8 +30,10 @@ const ticketUpdateSchema = z
|
|
|
26
30
|
patch.body !== undefined ||
|
|
27
31
|
patch.labels !== undefined ||
|
|
28
32
|
patch.kind !== undefined ||
|
|
29
|
-
patch.target !== undefined
|
|
30
|
-
|
|
33
|
+
patch.target !== undefined ||
|
|
34
|
+
patch.issueLinks !== undefined ||
|
|
35
|
+
patch.priority !== undefined,
|
|
36
|
+
'update must name at least one of title, body, labels, issue links, priority, kind, or target',
|
|
31
37
|
)
|
|
32
38
|
|
|
33
39
|
/** Render ticket-update issues while retaining nested union branch detail. */
|
|
@@ -60,5 +66,9 @@ export function validateTicketUpdate(patch: TicketUpdate): TicketUpdate {
|
|
|
60
66
|
...(result.data.title !== undefined ? { title: result.data.title } : {}),
|
|
61
67
|
...(result.data.body !== undefined ? { body: result.data.body } : {}),
|
|
62
68
|
...(result.data.labels !== undefined ? { labels: [...result.data.labels] } : {}),
|
|
69
|
+
...(result.data.issueLinks !== undefined
|
|
70
|
+
? { issueLinks: normalizeIssueLinks(result.data.issueLinks) }
|
|
71
|
+
: {}),
|
|
72
|
+
...(result.data.priority !== undefined ? { priority: result.data.priority } : {}),
|
|
63
73
|
}
|
|
64
74
|
}
|