@defrex/autobuild 1.10.0 → 1.11.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 +738 -68
- package/bin/ab-dispatch-generation.ts +3 -1
- package/docs/accounts.md +2 -1
- package/docs/answering-blocked-builds.md +20 -0
- package/docs/architecture.md +155 -25
- package/docs/build-store.md +10 -7
- package/docs/cli.md +33 -1
- package/docs/configuration-overview.md +4 -1
- package/docs/configuration.md +381 -29
- package/docs/dispatcher.md +63 -4
- package/docs/forges.md +7 -0
- package/docs/integration-tree.md +2 -2
- package/docs/operating.md +4 -2
- package/docs/operator-api.md +134 -6
- package/docs/operator-surfaces.md +85 -0
- package/docs/optimization-nodes.md +69 -11
- package/docs/plugin-authoring.md +37 -1
- package/docs/remote-store-protocol.md +94 -13
- package/docs/remote-ticket-protocol.md +40 -0
- package/docs/restacking.md +20 -4
- package/docs/setup.md +14 -2
- package/docs/ticket-dependencies.md +10 -3
- package/docs/ticket-sources.md +24 -2
- package/docs/tickets.md +7 -1
- package/docs/troubleshooting.md +8 -0
- package/docs/verification.md +4 -3
- package/docs/workspaces.md +3 -0
- package/package.json +9 -5
- package/packages/core/src/cli/accounts.ts +7 -2
- package/packages/core/src/cli/attention.ts +3 -1
- package/packages/core/src/cli/binary-direct.ts +2 -0
- package/packages/core/src/cli/binary-lifecycle.ts +2 -1
- package/packages/core/src/cli/build-control.ts +79 -1
- package/packages/core/src/cli/context.ts +4 -0
- package/packages/core/src/cli/dashboard/facts.ts +49 -53
- package/packages/core/src/cli/dashboard/header.ts +101 -0
- package/packages/core/src/cli/dashboard/model.ts +31 -39
- package/packages/core/src/cli/dashboard/objective-row.ts +46 -14
- package/packages/core/src/cli/dashboard/poll.ts +178 -76
- package/packages/core/src/cli/dashboard/render.ts +129 -230
- package/packages/core/src/cli/dashboard/row-text.ts +538 -0
- package/packages/core/src/cli/dashboard/timeline.ts +288 -0
- package/packages/core/src/cli/dashboard/vocabulary.ts +188 -0
- package/packages/core/src/cli/dispatch-args.ts +44 -1
- package/packages/core/src/cli/dispatch-frontend.ts +29 -38
- package/packages/core/src/cli/dispatch-launch-stop.ts +18 -0
- package/packages/core/src/cli/dispatch-launcher.ts +20 -7
- package/packages/core/src/cli/dispatch-web.ts +155 -0
- package/packages/core/src/cli/dispatch.ts +200 -34
- package/packages/core/src/cli/help.ts +87 -3
- package/packages/core/src/cli/init-validation.ts +3 -3
- package/packages/core/src/cli/main.ts +70 -6
- package/packages/core/src/cli/mcp.ts +35 -3
- package/packages/core/src/cli/objective.ts +1 -1
- package/packages/core/src/cli/operator-preference.ts +57 -0
- package/packages/core/src/cli/repo-lease.ts +2 -0
- package/packages/core/src/cli/repo-state.ts +56 -6
- package/packages/core/src/cli/repository-status.ts +97 -43
- package/packages/core/src/cli/status.ts +82 -1
- package/packages/core/src/cli/terminal-restore.ts +32 -7
- package/packages/core/src/cli/ticket.ts +98 -36
- package/packages/core/src/cli/wait.ts +14 -6
- package/packages/core/src/cli/watch.ts +20 -4
- package/packages/core/src/cli/web.ts +139 -0
- package/packages/core/src/config/live.ts +99 -14
- package/packages/core/src/config/load.ts +61 -20
- package/packages/core/src/config/local.ts +212 -0
- package/packages/core/src/config/pipeline-source.ts +2 -0
- package/packages/core/src/config/reference.ts +18 -0
- package/packages/core/src/config/schema.ts +45 -10
- package/packages/core/src/events/catalog.ts +4 -0
- package/packages/core/src/events/payloads.ts +97 -0
- package/packages/core/src/events/policy.ts +10 -0
- package/packages/core/src/events/repository.ts +46 -3
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +316 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/017d8dd5bb6dd80b.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/178e12f1759b7552.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/4932c70a2af97faf.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/536085773daf6b58.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/6bd6275061aaffa5.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/89625654b02e9ac1.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/a98af134be2da8a9.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/d5d5ccca80a893d8.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-corpora/f8155387eb5f375c.json.gz +0 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3c27f918b194e3b3.json +465 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/79f0e0f4ccd43ba2.json +455 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/859c09edac738823.json +1086 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a283c1f3462b1cc1.json +81 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a6e570fb126991ff.json +36 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a8acf22c968b6e3d.json +81 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/ba7b85895bf6698e.json +1153 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/fc66408cde0b6b04.json +637 -0
- package/packages/core/src/kernel/build-roster.ts +230 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +4 -2
- package/packages/core/src/kernel/engine.ts +43 -5
- package/packages/core/src/kernel/execution-intervals.ts +61 -0
- package/packages/core/src/kernel/generators/optimization-log.ts +101 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +13 -0
- package/packages/core/src/kernel/leaf-restack-base.ts +33 -7
- package/packages/core/src/kernel/leaf-restack-state.ts +82 -3
- package/packages/core/src/kernel/log-index.ts +19 -0
- package/packages/core/src/kernel/optimization-admission.ts +244 -3
- package/packages/core/src/kernel/optimization.ts +183 -4
- package/packages/core/src/kernel/phase-failures.ts +121 -0
- package/packages/core/src/kernel/published-branch-head.ts +60 -0
- package/packages/core/src/kernel/reducer-registry.ts +27 -8
- package/packages/core/src/kernel/reducer-revisions.ts +25 -0
- package/packages/core/src/kernel/reducer.ts +63 -4
- package/packages/core/src/kernel/rollup.ts +61 -0
- package/packages/core/src/kernel/setup-streak.ts +38 -0
- package/packages/core/src/kernel/step-durations.ts +257 -0
- package/packages/core/src/kernel/target-observation.ts +6 -1
- package/packages/core/src/kernel/target-rewrite-recovery.ts +116 -0
- package/packages/core/src/kernel/verify-diff-base.ts +5 -0
- package/packages/core/src/kernel/verify-stages.ts +13 -3
- package/packages/core/src/ontology.ts +5 -0
- package/packages/core/src/operator/agent-context-serve.ts +631 -0
- package/packages/core/src/operator/annotations.ts +75 -5
- package/packages/core/src/operator/attention.ts +470 -0
- package/packages/core/src/operator/canonical-skills.ts +35 -0
- package/packages/core/src/operator/cli-equivalents.ts +270 -0
- package/packages/core/src/operator/context-prompts.ts +61 -0
- package/packages/core/src/operator/index.ts +49 -1
- package/packages/core/src/operator/landings.ts +28 -19
- package/packages/core/src/operator/optimization.ts +7 -0
- package/packages/core/src/operator/protocol.ts +3 -0
- package/packages/core/src/operator/query.ts +122 -72
- package/packages/core/src/operator/read-view.ts +5 -2
- package/packages/core/src/operator/registry.ts +406 -46
- package/packages/core/src/operator/requests.ts +20 -18
- package/packages/core/src/operator/sandbox-host.ts +107 -11
- package/packages/core/src/operator/sandbox-resolver.ts +253 -0
- package/packages/core/src/operator/sandbox.ts +778 -82
- package/packages/core/src/operator/ticket-asset-list.ts +77 -0
- package/packages/core/src/operator/ticket-assets.ts +167 -0
- package/packages/core/src/operator/tickets.ts +33 -2
- package/packages/core/src/plugin-sdk/index.ts +22 -0
- package/packages/core/src/plugins/manifest.ts +1 -1
- package/packages/core/src/ports/forge/fake.ts +92 -1
- package/packages/core/src/ports/forge/git-blob.ts +15 -0
- package/packages/core/src/ports/forge/github.ts +82 -0
- package/packages/core/src/ports/forge/local-git.ts +61 -1
- package/packages/core/src/ports/forge-failure.ts +24 -0
- package/packages/core/src/ports/runner/antigravity-test.fixture.ts +149 -0
- package/packages/core/src/ports/runner/claude-test.fixture.ts +71 -0
- package/packages/core/src/ports/runner/codex-test.fixture.ts +63 -0
- package/packages/core/src/ports/tickets/contract.ts +71 -0
- package/packages/core/src/ports/tickets/fake.ts +11 -0
- package/packages/core/src/ports/tickets/file.ts +18 -0
- package/packages/core/src/ports/tickets/github-fake.ts +136 -4
- package/packages/core/src/ports/tickets/github.ts +387 -30
- package/packages/core/src/ports/tickets/hosted-index.ts +10 -0
- package/packages/core/src/ports/tickets/linear.ts +130 -0
- package/packages/core/src/ports/tickets/priority.ts +9 -0
- package/packages/core/src/ports/tickets/remote-protocol.ts +34 -0
- package/packages/core/src/ports/tickets/remote.ts +70 -6
- package/packages/core/src/ports/tickets/search.ts +139 -0
- package/packages/core/src/ports/types.ts +104 -2
- package/packages/core/src/ports/workspace/builtin-capabilities.ts +9 -0
- package/packages/core/src/ports/workspace/create.ts +15 -1
- package/packages/core/src/ports/workspace/fake.ts +340 -12
- package/packages/core/src/ports/workspace/git-worktree.ts +833 -42
- package/packages/core/src/ports/workspace/operator-sandbox.ts +129 -12
- package/packages/core/src/ports/workspace/process-group.ts +48 -0
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +1260 -123
- package/packages/core/src/processes/agent-context-assemble.ts +576 -0
- package/packages/core/src/processes/agent-context.ts +469 -0
- package/packages/core/src/processes/build-runner.ts +387 -236
- package/packages/core/src/processes/dispatcher.ts +211 -55
- package/packages/core/src/processes/execution-no-progress.ts +4 -0
- package/packages/core/src/processes/optimization-activity.ts +120 -0
- package/packages/core/src/processes/phase-failure-budget.ts +1 -0
- package/packages/core/src/processes/repo-view.ts +78 -2
- package/packages/core/src/processes/sandbox-state.ts +53 -6
- package/packages/core/src/processes/tick-publication.ts +2 -0
- package/packages/core/src/processes/workspace-preparation.ts +76 -0
- package/packages/core/src/scenarios/harness.ts +0 -5
- package/packages/core/src/store/account-redaction.ts +1 -0
- package/packages/core/src/store/adapter.ts +52 -1
- package/packages/core/src/store/agent-context.ts +432 -0
- package/packages/core/src/store/build-feed.ts +291 -0
- package/packages/core/src/store/build-scope.ts +19 -1
- package/packages/core/src/store/contract.ts +911 -14
- package/packages/core/src/store/digest.ts +19 -6
- package/packages/core/src/store/histogram.ts +113 -0
- package/packages/core/src/store/local/schema.ts +62 -0
- package/packages/core/src/store/local/store.ts +628 -22
- package/packages/core/src/store/local/ticket-asset-heads.ts +23 -0
- package/packages/core/src/store/memory.ts +461 -69
- package/packages/core/src/store/open-builds.ts +19 -0
- package/packages/core/src/store/phase-session.ts +32 -4
- package/packages/core/src/store/reduced-reads.ts +14 -4
- package/packages/core/src/store/reducer-value-shapes.json +6987 -5749
- package/packages/core/src/store/reducer-values.ts +6 -1
- package/packages/core/src/store/remote/client.ts +208 -2
- package/packages/core/src/store/remote/compatibility.ts +1 -1
- package/packages/core/src/store/remote/index.ts +33 -0
- package/packages/core/src/store/remote/protocol.ts +69 -0
- package/packages/core/src/store/remote/released-clients.json +11 -0
- package/packages/core/src/store/remote/released-reducer-values/1.11.0.json +35680 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +18 -16
- package/packages/core/src/store/retention.ts +23 -1
- package/packages/core/src/store/rollups.ts +337 -0
- package/packages/core/src/store/session-handle.ts +20 -2
- package/packages/core/src/store/snapshots.ts +10 -0
- package/packages/core/src/store/types.ts +108 -9
- package/packages/core/src/testing/dispatch-read-budget.ts +1092 -2
- package/packages/core/src/testing/git-config-isolation.ts +7 -5
- package/packages/core/src/testing/index.ts +27 -0
- package/packages/core/src/testing/memory-operator-sandbox.ts +346 -0
- package/packages/core/src/testing/reduced-read-budget.ts +1873 -98
- package/packages/core/src/web/analytics-source.ts +303 -0
- package/packages/core/src/web/assets/Atkinson-OFL.txt +93 -0
- package/packages/core/src/web/assets/AtkinsonHyperlegibleNext.latin.woff2 +0 -0
- package/packages/core/src/web/assets/JetBrains-OFL.txt +93 -0
- package/packages/core/src/web/assets/JetBrainsMono.latin.woff2 +0 -0
- package/packages/core/src/web/assets/app.css +1 -0
- package/packages/core/src/web/assets/app.js +9 -0
- package/packages/core/src/web/assets/manifest.json +31 -0
- package/packages/core/src/web/assets/theme.js +1 -0
- package/packages/core/src/web/bounded.ts +31 -0
- package/packages/core/src/web/http.ts +315 -0
- package/packages/core/src/web/hub.ts +160 -0
- package/packages/core/src/web/options.ts +38 -0
- package/packages/core/src/web/overview-source.ts +322 -0
- package/packages/core/src/web/page.ts +56 -0
- package/packages/core/src/web/protocol.ts +151 -0
- package/packages/core/src/web/read-only.ts +23 -0
- package/packages/core/src/web/repository-source.ts +35 -0
- package/packages/core/src/web/server.ts +97 -0
- package/skills/code-review/SKILL.md +10 -2
- package/skills/guide/SKILL.md +366 -52
- package/skills/guide/references/accounts.md +2 -1
- package/skills/guide/references/integration-tree.md +2 -2
- package/skills/guide/references/operator-api.md +134 -6
- package/skills/guide/references/optimization-nodes.md +69 -11
- package/skills/guide/references/plugin-authoring.md +37 -1
- package/skills/guide/references/remote-store-protocol.md +94 -13
- package/skills/guide/references/remote-ticket-protocol.md +40 -0
- package/skills/guide/references/restacking.md +20 -4
- package/skills/guide/references/setup.md +14 -2
- package/skills/guide/references/ticket-dependencies.md +10 -3
- package/skills/implement/SKILL.md +23 -4
- package/skills/operate/SKILL.md +134 -32
- package/skills/plan/SKILL.md +10 -4
- package/skills/plan-review/SKILL.md +9 -2
- package/skills/spec/SKILL.md +34 -8
- package/skills/tickets/SKILL.md +51 -5
- package/templates/hosted-service/package.json +2 -2
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ticket-asset helpers the operator surface and the CLI share: the id
|
|
3
|
+
* assets are keyed by, the listing projection `ab ticket show --json` and
|
|
4
|
+
* `tickets.get` both print, and the active-build notice. A leaf module, so
|
|
5
|
+
* `operator/tickets.ts` and `operator/ticket-assets.ts` can both import it.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { parseIssueId } from '../ports/tickets/github-issues'
|
|
9
|
+
import type { TicketSource } from '../ports/types'
|
|
10
|
+
import { readBuildFacts } from '../store/reduced-reads'
|
|
11
|
+
import { composeTicketAssets, type TicketAssetSummary } from '../store/ticket-assets'
|
|
12
|
+
import type { BuildStore } from '../store/types'
|
|
13
|
+
|
|
14
|
+
/** One current ticket asset as `ab ticket show --json` and `tickets.get` list it. */
|
|
15
|
+
export interface OperatorTicketAsset {
|
|
16
|
+
kind: string
|
|
17
|
+
name: string
|
|
18
|
+
revision: number
|
|
19
|
+
size: number
|
|
20
|
+
layout: TicketAssetSummary['layout']
|
|
21
|
+
fileCount: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The id ticket assets are keyed by. GitHub accepts `123` and `#123` for one
|
|
25
|
+
* issue, and the dispatcher reads assets by `ref.id`, so both spellings key by
|
|
26
|
+
* the issue number. Other sources key by the id as given. */
|
|
27
|
+
export function assetTicketId(source: string, id: string): string {
|
|
28
|
+
if (source !== 'github') return id
|
|
29
|
+
const number = parseIssueId(id)
|
|
30
|
+
return number === null ? id : String(number)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function projectTicketAssets(summaries: TicketAssetSummary[]): OperatorTicketAsset[] {
|
|
34
|
+
return summaries.map(({ kind, name, revision, size, layout, fileCount }) => ({
|
|
35
|
+
kind,
|
|
36
|
+
name,
|
|
37
|
+
revision,
|
|
38
|
+
size,
|
|
39
|
+
layout,
|
|
40
|
+
fileCount,
|
|
41
|
+
}))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The ticket's current assets. One current-mode listing: bounded by the
|
|
45
|
+
* ticket's asset names, never by retained history or other tickets. */
|
|
46
|
+
export async function listOperatorTicketAssets(
|
|
47
|
+
store: BuildStore,
|
|
48
|
+
source: TicketSource,
|
|
49
|
+
repo: string,
|
|
50
|
+
id: string,
|
|
51
|
+
): Promise<OperatorTicketAsset[]> {
|
|
52
|
+
return projectTicketAssets(
|
|
53
|
+
await composeTicketAssets(source, store).listTicketAssets(repo, assetTicketId(source.name, id)),
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Slugs of this repo's non-terminal builds for the ticket. A build freezes its
|
|
58
|
+
* ticket assets at the claim (SPEC §6.3), so a change to them does not reach
|
|
59
|
+
* it. One build listing, then one saved reduced read per build of this ticket;
|
|
60
|
+
* never a log read. The notice is advisory: a failed lookup yields none. */
|
|
61
|
+
export async function activeTicketBuilds(
|
|
62
|
+
store: BuildStore,
|
|
63
|
+
repo: string,
|
|
64
|
+
id: string,
|
|
65
|
+
): Promise<string[]> {
|
|
66
|
+
try {
|
|
67
|
+
const active: string[] = []
|
|
68
|
+
for (const record of await store.listBuildsForRepo(repo)) {
|
|
69
|
+
if (record.ticket?.id !== id) continue
|
|
70
|
+
const { status } = (await readBuildFacts(store, record.slug)).value.state
|
|
71
|
+
if (status !== 'done' && status !== 'aborted') active.push(record.slug)
|
|
72
|
+
}
|
|
73
|
+
return active
|
|
74
|
+
} catch {
|
|
75
|
+
return []
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ticket assets for the operator surface (SPEC §7.1, §8.8): the service half
|
|
3
|
+
* of the `tickets.asset.*` tools. Same pieces and order as `ab ticket attach`,
|
|
4
|
+
* `ab ticket asset get` and `ab ticket asset rm`: the source is asked first,
|
|
5
|
+
* so an unknown ticket stores nothing; the shared validator runs before any
|
|
6
|
+
* write; the note follows the store write, so it never points at nothing.
|
|
7
|
+
* Bytes cross the wire as base64.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { ticketAssetNote } from '../cli/ticket-assets'
|
|
11
|
+
import { TicketOperationError, requireTicket } from '../ports/tickets/operations'
|
|
12
|
+
import type { TicketSource } from '../ports/types'
|
|
13
|
+
import {
|
|
14
|
+
composeTicketAssets,
|
|
15
|
+
validateTicketAssetInput,
|
|
16
|
+
type TicketAssetInput,
|
|
17
|
+
type TicketAssetLayout,
|
|
18
|
+
type TicketAssetMeta,
|
|
19
|
+
} from '../store/ticket-assets'
|
|
20
|
+
import type { TicketAssetStore } from '../ports/types'
|
|
21
|
+
import type { BuildStore } from '../store/types'
|
|
22
|
+
import { activeTicketBuilds, assetTicketId } from './ticket-asset-list'
|
|
23
|
+
import { openOperatorTickets, type OperatorTicketBackend } from './tickets'
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
activeTicketBuilds,
|
|
27
|
+
assetTicketId,
|
|
28
|
+
listOperatorTicketAssets,
|
|
29
|
+
projectTicketAssets,
|
|
30
|
+
type OperatorTicketAsset,
|
|
31
|
+
} from './ticket-asset-list'
|
|
32
|
+
|
|
33
|
+
/** One asset entry on the wire: a file with its exact bytes, or a directory. */
|
|
34
|
+
export type OperatorTicketAssetEntry =
|
|
35
|
+
| { type: 'file'; path: string; contentBase64: string }
|
|
36
|
+
| { type: 'dir'; path: string }
|
|
37
|
+
|
|
38
|
+
interface OperatorTicketAssetTarget {
|
|
39
|
+
store: BuildStore
|
|
40
|
+
repo: string
|
|
41
|
+
backend: OperatorTicketBackend
|
|
42
|
+
id: string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function openTicketAssets(opts: OperatorTicketAssetTarget): Promise<{
|
|
46
|
+
source: TicketSource
|
|
47
|
+
assets: TicketAssetStore
|
|
48
|
+
key: string
|
|
49
|
+
hosted: boolean
|
|
50
|
+
}> {
|
|
51
|
+
const { context, source } = await openOperatorTickets(opts)
|
|
52
|
+
if (source.name === 'hosted' && !source.assets)
|
|
53
|
+
throw new TicketOperationError('refusal', 'hosted ticket source has no asset capability')
|
|
54
|
+
return {
|
|
55
|
+
source,
|
|
56
|
+
assets: composeTicketAssets(source, opts.store),
|
|
57
|
+
key: assetTicketId(source.name, opts.id),
|
|
58
|
+
hosted: source.name === 'hosted' || context.tickets.source === 'hosted',
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Leave the note; a failure is reported, never thrown, because the store
|
|
63
|
+
* change already happened and retrying would change it again. */
|
|
64
|
+
async function leaveNote(source: TicketSource, id: string, note: string): Promise<string | null> {
|
|
65
|
+
try {
|
|
66
|
+
await source.comment(id, note)
|
|
67
|
+
return null
|
|
68
|
+
} catch (error) {
|
|
69
|
+
return `the note on ${source.name}:${id} failed: ${error instanceof Error ? error.message : String(error)}`
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function attachOperatorTicketAsset(
|
|
74
|
+
opts: OperatorTicketAssetTarget & {
|
|
75
|
+
kind: string
|
|
76
|
+
name: string
|
|
77
|
+
layout: TicketAssetLayout
|
|
78
|
+
entries: OperatorTicketAssetEntry[]
|
|
79
|
+
},
|
|
80
|
+
): Promise<{
|
|
81
|
+
asset: TicketAssetMeta
|
|
82
|
+
replaced: boolean
|
|
83
|
+
activeBuilds: string[]
|
|
84
|
+
noteError?: string
|
|
85
|
+
}> {
|
|
86
|
+
const { source, assets, key, hosted } = await openTicketAssets(opts)
|
|
87
|
+
await requireTicket(source, key)
|
|
88
|
+
const input: TicketAssetInput = {
|
|
89
|
+
kind: opts.kind,
|
|
90
|
+
name: opts.name,
|
|
91
|
+
layout: opts.layout,
|
|
92
|
+
entries: opts.entries.map((entry) =>
|
|
93
|
+
entry.type === 'file'
|
|
94
|
+
? {
|
|
95
|
+
type: 'file',
|
|
96
|
+
path: entry.path,
|
|
97
|
+
content: new Uint8Array(Buffer.from(entry.contentBase64, 'base64')),
|
|
98
|
+
}
|
|
99
|
+
: { type: 'dir', path: entry.path },
|
|
100
|
+
),
|
|
101
|
+
}
|
|
102
|
+
validateTicketAssetInput(input, await assets.ticketAssetLimits(opts.repo))
|
|
103
|
+
const replaced = (await assets.listTicketAssets(opts.repo, key)).some(
|
|
104
|
+
(asset) => asset.kind === input.kind && asset.name === input.name,
|
|
105
|
+
)
|
|
106
|
+
const asset = await assets.putTicketAsset(opts.repo, key, input)
|
|
107
|
+
const activeBuilds = await activeTicketBuilds(opts.store, opts.repo, key)
|
|
108
|
+
const noteError = await leaveNote(
|
|
109
|
+
source,
|
|
110
|
+
key,
|
|
111
|
+
ticketAssetNote(replaced ? 'replaced' : 'attached', asset, 'ab', hosted),
|
|
112
|
+
)
|
|
113
|
+
return { asset, replaced, activeBuilds, ...(noteError !== null ? { noteError } : {}) }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export async function getOperatorTicketAsset(
|
|
117
|
+
opts: OperatorTicketAssetTarget & { kind: string; name: string; rev?: number },
|
|
118
|
+
): Promise<{
|
|
119
|
+
asset: TicketAssetMeta
|
|
120
|
+
entries: (
|
|
121
|
+
| { type: 'file'; path: string; size: number; contentBase64: string }
|
|
122
|
+
| {
|
|
123
|
+
type: 'dir'
|
|
124
|
+
path: string
|
|
125
|
+
}
|
|
126
|
+
)[]
|
|
127
|
+
}> {
|
|
128
|
+
const { assets, key } = await openTicketAssets(opts)
|
|
129
|
+
const found = await assets.getTicketAsset(opts.repo, key, opts.kind, opts.name, opts.rev)
|
|
130
|
+
if (found === null) {
|
|
131
|
+
const revision = opts.rev === undefined ? '' : ` revision ${opts.rev}`
|
|
132
|
+
throw new TicketOperationError(
|
|
133
|
+
'not-found',
|
|
134
|
+
`ticket ${key} has no asset ${opts.kind}/${opts.name}${revision}` +
|
|
135
|
+
(opts.rev === undefined ? ' (it may have been removed — pass rev)' : ''),
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
asset: found.meta,
|
|
140
|
+
entries: found.entries.map((entry) =>
|
|
141
|
+
entry.type === 'file'
|
|
142
|
+
? {
|
|
143
|
+
type: 'file',
|
|
144
|
+
path: entry.path,
|
|
145
|
+
size: entry.content.byteLength,
|
|
146
|
+
contentBase64: Buffer.from(entry.content).toString('base64'),
|
|
147
|
+
}
|
|
148
|
+
: { type: 'dir', path: entry.path },
|
|
149
|
+
),
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export async function removeOperatorTicketAsset(
|
|
154
|
+
opts: OperatorTicketAssetTarget & { kind: string; name: string },
|
|
155
|
+
): Promise<{ removed: TicketAssetMeta; activeBuilds: string[]; noteError?: string }> {
|
|
156
|
+
const { source, assets, key, hosted } = await openTicketAssets(opts)
|
|
157
|
+
await requireTicket(source, key)
|
|
158
|
+
const removed = await assets.removeTicketAsset(opts.repo, key, opts.kind, opts.name)
|
|
159
|
+
if (removed === null)
|
|
160
|
+
throw new TicketOperationError(
|
|
161
|
+
'not-found',
|
|
162
|
+
`ticket ${key} has no current asset ${opts.kind}/${opts.name} to remove`,
|
|
163
|
+
)
|
|
164
|
+
const activeBuilds = await activeTicketBuilds(opts.store, opts.repo, key)
|
|
165
|
+
const noteError = await leaveNote(source, key, ticketAssetNote('removed', removed, 'ab', hosted))
|
|
166
|
+
return { removed, activeBuilds, ...(noteError !== null ? { noteError } : {}) }
|
|
167
|
+
}
|
|
@@ -8,7 +8,8 @@ import { normalizeIssueLinks, type IssueLinkInput } from '../ports/tickets/issue
|
|
|
8
8
|
import { urgentFirst } from '../ports/tickets/priority'
|
|
9
9
|
import { creationAssignees } from '../ports/tickets/assignees'
|
|
10
10
|
import { creationLabels } from '../ports/tickets/labels'
|
|
11
|
-
import type { IssueLink } from '../ports/types'
|
|
11
|
+
import type { IssueLink, TicketSearchPage } from '../ports/types'
|
|
12
|
+
import { searchTickets } from '../ports/tickets/search'
|
|
12
13
|
import { projectTicketTree, compatibleTicketSource } from '../ports/tickets/tree'
|
|
13
14
|
import { readBuildFacts } from '../store/reduced-reads'
|
|
14
15
|
import { samplePinnedAssets, preparePinnedAssets } from '../store/ticket-assets'
|
|
@@ -34,6 +35,7 @@ import type {
|
|
|
34
35
|
import type { BuildStore } from '../store/types'
|
|
35
36
|
import { ticketLifecycle, type TicketMoveRole } from '../ports/tickets/lifecycle'
|
|
36
37
|
import { effectiveConfig } from './query'
|
|
38
|
+
import { listOperatorTicketAssets, type OperatorTicketAsset } from './ticket-asset-list'
|
|
37
39
|
|
|
38
40
|
export interface OperatorTicketContext {
|
|
39
41
|
repo: string
|
|
@@ -82,6 +84,10 @@ export interface OperatorTicketDetail {
|
|
|
82
84
|
build: OperatorTicketBuild | null
|
|
83
85
|
}
|
|
84
86
|
|
|
87
|
+
/** `tickets.get` and the ticket detail route: the detail plus the ticket's
|
|
88
|
+
* current assets, listed as `ab ticket show --json` lists them. */
|
|
89
|
+
export type OperatorTicketView = OperatorTicketDetail & { assets: OperatorTicketAsset[] }
|
|
90
|
+
|
|
85
91
|
function contextFor(config: Config, repo: string): OperatorTicketContext {
|
|
86
92
|
const tickets = config.tickets
|
|
87
93
|
return {
|
|
@@ -129,6 +135,29 @@ export function operatorControlTickets(opts: {
|
|
|
129
135
|
}
|
|
130
136
|
}
|
|
131
137
|
|
|
138
|
+
/** Text search over the configured source in every state unless `state` is
|
|
139
|
+
* given. A source without search refuses with `TicketSearchUnsupported`
|
|
140
|
+
* before any ticket read; nothing falls back to a listing. */
|
|
141
|
+
export async function searchOperatorTickets(opts: {
|
|
142
|
+
store: BuildStore
|
|
143
|
+
repo: string
|
|
144
|
+
backend: OperatorTicketBackend
|
|
145
|
+
query: string
|
|
146
|
+
state?: string
|
|
147
|
+
labels?: string[]
|
|
148
|
+
limit?: number
|
|
149
|
+
cursor?: string
|
|
150
|
+
}): Promise<TicketSearchPage> {
|
|
151
|
+
const { source } = await openOperatorTickets(opts)
|
|
152
|
+
return searchTickets(source, {
|
|
153
|
+
text: opts.query,
|
|
154
|
+
...(opts.state !== undefined ? { state: opts.state } : {}),
|
|
155
|
+
...(opts.labels !== undefined ? { labels: opts.labels } : {}),
|
|
156
|
+
...(opts.limit !== undefined ? { limit: opts.limit } : {}),
|
|
157
|
+
...(opts.cursor !== undefined ? { cursor: opts.cursor } : {}),
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
132
161
|
export async function listOperatorTickets(opts: {
|
|
133
162
|
store: BuildStore
|
|
134
163
|
repo: string
|
|
@@ -241,7 +270,7 @@ export async function getOperatorTicket(opts: {
|
|
|
241
270
|
repo: string
|
|
242
271
|
backend: OperatorTicketBackend
|
|
243
272
|
id: string
|
|
244
|
-
}): Promise<
|
|
273
|
+
}): Promise<OperatorTicketView> {
|
|
245
274
|
const { source, context } = await openOperatorTickets(opts)
|
|
246
275
|
const ticket = await requireTicket(source, opts.id)
|
|
247
276
|
const blockers = await source.dependencyStates(ticket.blockedBy ?? [])
|
|
@@ -255,6 +284,8 @@ export async function getOperatorTicket(opts: {
|
|
|
255
284
|
source,
|
|
256
285
|
context.tickets.source,
|
|
257
286
|
),
|
|
287
|
+
// Keyed by the id as given, as `ab ticket show` keys it.
|
|
288
|
+
assets: await listOperatorTicketAssets(opts.store, source, opts.repo, opts.id),
|
|
258
289
|
}
|
|
259
290
|
}
|
|
260
291
|
|
|
@@ -168,6 +168,7 @@ export {
|
|
|
168
168
|
withoutUnsupportedPriority,
|
|
169
169
|
urgentFirst,
|
|
170
170
|
} from '../ports/tickets/priority'
|
|
171
|
+
export { TicketSearchCursorInvalid, TicketSearchUnsupported } from '../ports/tickets/search'
|
|
171
172
|
export {
|
|
172
173
|
TicketAssigneesUnsupported,
|
|
173
174
|
refuseUnsupportedAssignees,
|
|
@@ -183,9 +184,11 @@ export {
|
|
|
183
184
|
ArchiveConflictError,
|
|
184
185
|
ForgeFailure,
|
|
185
186
|
ForgeRejection,
|
|
187
|
+
ForgeTreeUnlistable,
|
|
186
188
|
isArchiveConflict,
|
|
187
189
|
isForgeFailure,
|
|
188
190
|
isForgeRejection,
|
|
191
|
+
isForgeTreeUnlistable,
|
|
189
192
|
} from '../ports/forge-failure'
|
|
190
193
|
export type {
|
|
191
194
|
ForgeFailureDetails,
|
|
@@ -276,5 +279,24 @@ export type {
|
|
|
276
279
|
ReducerValueStorage,
|
|
277
280
|
ValueCacheRow,
|
|
278
281
|
} from '../store/reducer-values'
|
|
282
|
+
export {
|
|
283
|
+
KeyedMutex,
|
|
284
|
+
ROLLUP_LEASE_MS,
|
|
285
|
+
ROLLUP_LEASE_WAIT_MS,
|
|
286
|
+
ROLLUP_RENEW_BATCH,
|
|
287
|
+
RollupLeaseLostError,
|
|
288
|
+
RollupLeaseTimeoutError,
|
|
289
|
+
readRollupValue,
|
|
290
|
+
resolveRollupValue,
|
|
291
|
+
rollupEntry,
|
|
292
|
+
} from '../store/rollups'
|
|
293
|
+
export type {
|
|
294
|
+
ResolvedRollup,
|
|
295
|
+
RollupAdvance,
|
|
296
|
+
RollupReads,
|
|
297
|
+
RollupRow,
|
|
298
|
+
RollupStorage,
|
|
299
|
+
} from '../store/rollups'
|
|
300
|
+
export type { ReducerValueScope, RollupScope } from '../store/snapshots'
|
|
279
301
|
|
|
280
302
|
export { resumeAgent } from '../ports/runner/native-session'
|
|
@@ -15,7 +15,7 @@ import type {
|
|
|
15
15
|
} from '../ports/workspace/provider-capabilities'
|
|
16
16
|
|
|
17
17
|
/** Version of the in-process plugin contract exposed by `@defrex/autobuild/plugin-sdk`. */
|
|
18
|
-
export const PLUGIN_API_VERSION = '1.
|
|
18
|
+
export const PLUGIN_API_VERSION = '1.11.0' as const
|
|
19
19
|
|
|
20
20
|
/** Context supplied when a registered adapter or contract fixture is selected. */
|
|
21
21
|
export interface PluginFactoryContext<Config = Record<string, unknown>> {
|
|
@@ -6,7 +6,9 @@ import {
|
|
|
6
6
|
withIssueKeywords,
|
|
7
7
|
} from '../../kernel/issue-keywords'
|
|
8
8
|
import { ForgeMergeQueueRejection, type BuildLandingOptions } from '../types'
|
|
9
|
-
import { ArchiveConflictError, ForgeRejection } from '../forge-failure'
|
|
9
|
+
import { ArchiveConflictError, ForgeRejection, ForgeTreeUnlistable } from '../forge-failure'
|
|
10
|
+
import { createHash } from 'node:crypto'
|
|
11
|
+
import { gitBlobOid } from './git-blob'
|
|
10
12
|
import { findSummaryMarker } from './summary-marker'
|
|
11
13
|
/**
|
|
12
14
|
* FakeForge (SPEC §3.2): in-memory Forge for seam tests. Gate existence and
|
|
@@ -27,6 +29,7 @@ import type {
|
|
|
27
29
|
PrAttachmentReclaimRequest,
|
|
28
30
|
PrAttachmentUploadRequest,
|
|
29
31
|
Forge,
|
|
32
|
+
ForgeTreeEntry,
|
|
30
33
|
IssueLink,
|
|
31
34
|
PrRef,
|
|
32
35
|
PrState,
|
|
@@ -102,6 +105,63 @@ export type MergeSha = string | ((number: number) => string)
|
|
|
102
105
|
|
|
103
106
|
type FakeGateState = MergeGatePresence | AutoMergeDeferralReason
|
|
104
107
|
|
|
108
|
+
/** A seeded tree file: content, a symlink target, or a submodule commit. */
|
|
109
|
+
export type FakeTreeFile = string | Uint8Array | { symlink: string } | { submodule: string }
|
|
110
|
+
|
|
111
|
+
/** Synthesize a commit's recursive tree listing from `files`: blob entries
|
|
112
|
+
* with real git blob ids and sizes, plus directory entries whose ids are
|
|
113
|
+
* deterministic over their children (a child change changes every ancestor). */
|
|
114
|
+
export function fakeTree(files: Record<string, FakeTreeFile>): {
|
|
115
|
+
entries: ForgeTreeEntry[]
|
|
116
|
+
blobs: Map<string, Uint8Array>
|
|
117
|
+
} {
|
|
118
|
+
const encoder = new TextEncoder()
|
|
119
|
+
const entries = new Map<string, ForgeTreeEntry>()
|
|
120
|
+
const blobs = new Map<string, Uint8Array>()
|
|
121
|
+
for (const [path, file] of Object.entries(files)) {
|
|
122
|
+
if (typeof file === 'object' && 'submodule' in file) {
|
|
123
|
+
entries.set(path, { path, mode: '160000', type: 'commit', oid: file.submodule })
|
|
124
|
+
continue
|
|
125
|
+
}
|
|
126
|
+
const symlink = typeof file === 'object' && 'symlink' in file
|
|
127
|
+
const bytes =
|
|
128
|
+
typeof file === 'string'
|
|
129
|
+
? encoder.encode(file)
|
|
130
|
+
: symlink
|
|
131
|
+
? encoder.encode(file.symlink)
|
|
132
|
+
: (file as Uint8Array)
|
|
133
|
+
const oid = gitBlobOid(bytes)
|
|
134
|
+
blobs.set(oid, bytes)
|
|
135
|
+
entries.set(path, {
|
|
136
|
+
path,
|
|
137
|
+
mode: symlink ? '120000' : '100644',
|
|
138
|
+
type: 'blob',
|
|
139
|
+
oid,
|
|
140
|
+
size: bytes.byteLength,
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
const dirs = new Set<string>()
|
|
144
|
+
for (const path of entries.keys()) {
|
|
145
|
+
const parts = path.split('/')
|
|
146
|
+
for (let i = 1; i < parts.length; i++) dirs.add(parts.slice(0, i).join('/'))
|
|
147
|
+
}
|
|
148
|
+
// Deepest first, so each directory hashes its already-identified children.
|
|
149
|
+
for (const dir of [...dirs].sort((a, b) => b.split('/').length - a.split('/').length)) {
|
|
150
|
+
const children = [...entries.values()]
|
|
151
|
+
.filter(
|
|
152
|
+
(entry) =>
|
|
153
|
+
entry.path.startsWith(`${dir}/`) && !entry.path.slice(dir.length + 1).includes('/'),
|
|
154
|
+
)
|
|
155
|
+
.map((entry) => `${entry.mode} ${entry.path} ${entry.oid}`)
|
|
156
|
+
.sort()
|
|
157
|
+
const oid = createHash('sha1')
|
|
158
|
+
.update(`tree\0${children.join('\n')}`)
|
|
159
|
+
.digest('hex')
|
|
160
|
+
entries.set(dir, { path: dir, mode: '040000', type: 'tree', oid })
|
|
161
|
+
}
|
|
162
|
+
return { entries: [...entries.values()].sort((a, b) => (a.path < b.path ? -1 : 1)), blobs }
|
|
163
|
+
}
|
|
164
|
+
|
|
105
165
|
export class FakeForge implements Forge {
|
|
106
166
|
readiness: ForgeReadinessCheck[] = readinessChecks(
|
|
107
167
|
'pass',
|
|
@@ -216,6 +276,14 @@ export class FakeForge implements Forge {
|
|
|
216
276
|
readonly files = new Map<string, string>()
|
|
217
277
|
readonly commitMessages = new Map<string, string>()
|
|
218
278
|
readonly buildSlugs = new Map<number, string>()
|
|
279
|
+
/** Seedable tree reads: listings by commit (unseeded commits list empty),
|
|
280
|
+
* blob bytes by id, and commits whose listing throws `ForgeTreeUnlistable`
|
|
281
|
+
* naming a directory. */
|
|
282
|
+
readonly trees = new Map<string, ForgeTreeEntry[]>()
|
|
283
|
+
readonly blobs = new Map<string, Uint8Array>()
|
|
284
|
+
readonly unlistable = new Map<string, string>()
|
|
285
|
+
readonly treeReads: string[] = []
|
|
286
|
+
readonly blobReads: string[] = []
|
|
219
287
|
|
|
220
288
|
/** Journals — public so tests assert directly on call order and args. */
|
|
221
289
|
readonly pushes: PushRecord[] = []
|
|
@@ -666,6 +734,29 @@ export class FakeForge implements Forge {
|
|
|
666
734
|
return this.remoteBranches.has(branch)
|
|
667
735
|
}
|
|
668
736
|
|
|
737
|
+
/** Seed `commit`'s tree from `files` (see `fakeTree`). */
|
|
738
|
+
seedTree(commit: string, files: Record<string, FakeTreeFile>): ForgeTreeEntry[] {
|
|
739
|
+
const { entries, blobs } = fakeTree(files)
|
|
740
|
+
this.trees.set(commit, entries)
|
|
741
|
+
for (const [oid, bytes] of blobs) this.blobs.set(oid, bytes)
|
|
742
|
+
return entries
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
async readTree(commit: string): Promise<ForgeTreeEntry[]> {
|
|
746
|
+
this.treeReads.push(commit)
|
|
747
|
+
const directory = this.unlistable.get(commit)
|
|
748
|
+
if (directory !== undefined) throw new ForgeTreeUnlistable(directory)
|
|
749
|
+
// An unseeded commit is a repository with no agent context.
|
|
750
|
+
return structuredClone(this.trees.get(commit) ?? [])
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
async readBlob(oid: string): Promise<Uint8Array> {
|
|
754
|
+
this.blobReads.push(oid)
|
|
755
|
+
const bytes = this.blobs.get(oid)
|
|
756
|
+
if (bytes === undefined) throw new Error(`FakeForge: unknown blob ${oid}`)
|
|
757
|
+
return new Uint8Array(bytes)
|
|
758
|
+
}
|
|
759
|
+
|
|
669
760
|
async readFile(path: string, ref?: string): Promise<string> {
|
|
670
761
|
const key = `${ref ?? 'default'}\0${path}`
|
|
671
762
|
const content = this.files.get(key)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
|
|
3
|
+
/** Git's object id for a blob holding `bytes`: the hash of `blob <n>\0` plus
|
|
4
|
+
* the bytes. SHA-1 for 40-hex ids, SHA-256 for 64-hex object-format ids. */
|
|
5
|
+
export function gitBlobOid(bytes: Uint8Array, format: 'sha1' | 'sha256' = 'sha1'): string {
|
|
6
|
+
const hash = createHash(format)
|
|
7
|
+
hash.update(`blob ${bytes.byteLength}\0`)
|
|
8
|
+
hash.update(bytes)
|
|
9
|
+
return hash.digest('hex')
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** True when `bytes` are exactly the blob `oid` names. */
|
|
13
|
+
export function matchesGitBlobOid(oid: string, bytes: Uint8Array): boolean {
|
|
14
|
+
return gitBlobOid(bytes, oid.length === 64 ? 'sha256' : 'sha1') === oid
|
|
15
|
+
}
|
|
@@ -3,9 +3,11 @@ import { AsyncLocalStorage } from 'node:async_hooks'
|
|
|
3
3
|
import {
|
|
4
4
|
classifyGitNetworkFailure,
|
|
5
5
|
ForgeFailure,
|
|
6
|
+
ForgeTreeUnlistable,
|
|
6
7
|
isForgeFailure,
|
|
7
8
|
type ForgeRequestObserver,
|
|
8
9
|
} from '../forge-failure'
|
|
10
|
+
import { matchesGitBlobOid } from './git-blob'
|
|
9
11
|
import {
|
|
10
12
|
forgeRequestContext,
|
|
11
13
|
forgeRequestExhausted,
|
|
@@ -26,6 +28,7 @@ import {
|
|
|
26
28
|
ForgeRejection,
|
|
27
29
|
NoCommitsBetweenBranchesError,
|
|
28
30
|
type BuildLandingOptions,
|
|
31
|
+
type ForgeTreeEntry,
|
|
29
32
|
} from '../types'
|
|
30
33
|
import { findSummaryMarker } from './summary-marker'
|
|
31
34
|
import {
|
|
@@ -327,6 +330,21 @@ const restBranchHead = z
|
|
|
327
330
|
.object({ commit: z.object({ sha: z.string().min(1) }).passthrough() })
|
|
328
331
|
.passthrough()
|
|
329
332
|
|
|
333
|
+
const gitCommitTree = z.object({ tree: z.object({ sha: z.string().min(1) }) })
|
|
334
|
+
const gitTreeListing = z.object({
|
|
335
|
+
truncated: z.boolean(),
|
|
336
|
+
tree: z.array(
|
|
337
|
+
z.object({
|
|
338
|
+
path: z.string().min(1),
|
|
339
|
+
mode: z.enum(['100644', '100755', '040000', '120000', '160000']),
|
|
340
|
+
type: z.enum(['blob', 'tree', 'commit']),
|
|
341
|
+
sha: z.string().min(1),
|
|
342
|
+
size: z.number().int().nonnegative().optional(),
|
|
343
|
+
}),
|
|
344
|
+
),
|
|
345
|
+
})
|
|
346
|
+
const gitBlobContent = z.object({ content: z.string(), encoding: z.literal('base64') })
|
|
347
|
+
|
|
330
348
|
const restRulesetRules = z.array(
|
|
331
349
|
z
|
|
332
350
|
.object({
|
|
@@ -2734,6 +2752,70 @@ export class GitHubForge implements Forge {
|
|
|
2734
2752
|
}
|
|
2735
2753
|
}
|
|
2736
2754
|
|
|
2755
|
+
/** Complete recursive tree of `commit` (Git Trees API). A truncated
|
|
2756
|
+
* recursive listing is completed one subtree at a time, as GitHub
|
|
2757
|
+
* documents; only a directory with too many direct entries to list at all
|
|
2758
|
+
* throws `ForgeTreeUnlistable`. */
|
|
2759
|
+
async readTree(commit: string): Promise<ForgeTreeEntry[]> {
|
|
2760
|
+
const { owner, name } = await this.requireCoordinates()
|
|
2761
|
+
const base = `repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/git`
|
|
2762
|
+
const listing = (sha: string, recursive: boolean) =>
|
|
2763
|
+
this.getJson(
|
|
2764
|
+
gitTreeListing,
|
|
2765
|
+
`${base}/trees/${encodeURIComponent(sha)}`,
|
|
2766
|
+
'git tree',
|
|
2767
|
+
recursive ? { query: { recursive: '1' } } : undefined,
|
|
2768
|
+
)
|
|
2769
|
+
const entries = (
|
|
2770
|
+
prefix: string,
|
|
2771
|
+
tree: z.infer<typeof gitTreeListing>['tree'],
|
|
2772
|
+
): ForgeTreeEntry[] =>
|
|
2773
|
+
tree.map((entry) => ({
|
|
2774
|
+
path: prefix === '' ? entry.path : `${prefix}/${entry.path}`,
|
|
2775
|
+
mode: entry.mode,
|
|
2776
|
+
type: entry.type,
|
|
2777
|
+
oid: entry.sha,
|
|
2778
|
+
...(entry.size !== undefined ? { size: entry.size } : {}),
|
|
2779
|
+
}))
|
|
2780
|
+
const walk = async (prefix: string, sha: string): Promise<ForgeTreeEntry[]> => {
|
|
2781
|
+
const direct = await listing(sha, false)
|
|
2782
|
+
if (direct.truncated) throw new ForgeTreeUnlistable(prefix)
|
|
2783
|
+
const out = entries(prefix, direct.tree)
|
|
2784
|
+
for (const child of out.filter((entry) => entry.type === 'tree')) {
|
|
2785
|
+
const below = await listing(child.oid, true)
|
|
2786
|
+
out.push(
|
|
2787
|
+
...(below.truncated
|
|
2788
|
+
? await walk(child.path, child.oid)
|
|
2789
|
+
: entries(child.path, below.tree)),
|
|
2790
|
+
)
|
|
2791
|
+
}
|
|
2792
|
+
return out
|
|
2793
|
+
}
|
|
2794
|
+
const root = (
|
|
2795
|
+
await this.getJson(
|
|
2796
|
+
gitCommitTree,
|
|
2797
|
+
`${base}/commits/${encodeURIComponent(commit)}`,
|
|
2798
|
+
'git commit',
|
|
2799
|
+
)
|
|
2800
|
+
).tree.sha
|
|
2801
|
+
const recursive = await listing(root, true)
|
|
2802
|
+
return recursive.truncated ? walk('', root) : entries('', recursive.tree)
|
|
2803
|
+
}
|
|
2804
|
+
|
|
2805
|
+
/** Exact bytes of blob `oid` (Git Blobs API), verified against the id. */
|
|
2806
|
+
async readBlob(oid: string): Promise<Uint8Array> {
|
|
2807
|
+
const { owner, name } = await this.requireCoordinates()
|
|
2808
|
+
const blob = await this.getJson(
|
|
2809
|
+
gitBlobContent,
|
|
2810
|
+
`repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/git/blobs/${encodeURIComponent(oid)}`,
|
|
2811
|
+
'git blob',
|
|
2812
|
+
)
|
|
2813
|
+
const bytes = new Uint8Array(Buffer.from(blob.content.replace(/\s+/g, ''), 'base64'))
|
|
2814
|
+
if (!matchesGitBlobOid(oid, bytes))
|
|
2815
|
+
throw new Error(`GitHub blob ${oid} returned content that does not match its id`)
|
|
2816
|
+
return bytes
|
|
2817
|
+
}
|
|
2818
|
+
|
|
2737
2819
|
/** Raw file bytes from the repository. Ref omitted → the repository's
|
|
2738
2820
|
* default branch. Throws (including 404) when the path does not exist. */
|
|
2739
2821
|
async readFile(path: string, ref?: string): Promise<string> {
|