code-foundry 1.14.0 → 1.15.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.
@@ -0,0 +1,56 @@
1
+ name: Attest verified build artifacts
2
+ description: Generate checksums and signed provenance for explicitly selected build outputs.
3
+ inputs:
4
+ artifacts:
5
+ description: 'JSON array of nonempty regular artifact files relative to the workspace.'
6
+ required: true
7
+ outputs:
8
+ manifest-path:
9
+ description: Path to the generated SHA-256 JSON manifest.
10
+ value: ${{ steps.manifest.outputs.manifest-path }}
11
+ bundle-path:
12
+ description: Path to the signed provenance bundle.
13
+ value: ${{ steps.attest.outputs.bundle-path }}
14
+ attestation-url:
15
+ description: URL of the published attestation.
16
+ value: ${{ steps.attest.outputs.attestation-url }}
17
+ runs:
18
+ using: composite
19
+ steps:
20
+ - name: Select and hash build outputs
21
+ id: manifest
22
+ shell: bash
23
+ env:
24
+ ARTIFACTS: ${{ inputs.artifacts }}
25
+ run: |
26
+ set -euo pipefail
27
+ [[ "$GITHUB_EVENT_NAME" != pull_request && "$GITHUB_EVENT_NAME" != pull_request_target ]]
28
+ node --input-type=module <<'NODE'
29
+ import { appendFileSync, mkdtempSync, writeFileSync } from 'node:fs'
30
+ import { join, resolve } from 'node:path'
31
+ import { pathToFileURL } from 'node:url'
32
+ const helper = pathToFileURL(resolve(process.env.GITHUB_ACTION_PATH, '../../../src/commands/release-integrity.mjs'))
33
+ const { assetManifest } = await import(helper.href)
34
+ const files = JSON.parse(process.env.ARTIFACTS)
35
+ if (!Array.isArray(files) || files.some(file => typeof file !== 'string')) throw new Error('artifacts must be a JSON string array')
36
+ const manifest = assetManifest(process.env.GITHUB_WORKSPACE, files)
37
+ const directory = mkdtempSync(join(process.env.RUNNER_TEMP, 'foundry-attestation-'))
38
+ const manifestPath = join(directory, 'manifest.json')
39
+ const sumsPath = join(directory, 'SHA256SUMS')
40
+ writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + '\n')
41
+ writeFileSync(sumsPath, manifest.checksums)
42
+ appendFileSync(process.env.GITHUB_OUTPUT, `manifest-path=${manifestPath}\nchecksums-path=${sumsPath}\n`)
43
+ NODE
44
+ - name: Sign build provenance
45
+ id: attest
46
+ uses: actions/attest-build-provenance@977bb373ede98d70efdf65b84cb5f73e068dcc2a # v3
47
+ with:
48
+ subject-checksums: ${{ steps.manifest.outputs.checksums-path }}
49
+ - name: Verify artifacts were not changed during signing
50
+ shell: bash
51
+ env:
52
+ CHECKSUMS_PATH: ${{ steps.manifest.outputs.checksums-path }}
53
+ run: |
54
+ set -euo pipefail
55
+ cd "$GITHUB_WORKSPACE"
56
+ sha256sum --check "$CHECKSUMS_PATH"
@@ -0,0 +1,63 @@
1
+ name: Code Foundry Release Integrity
2
+ on:
3
+ workflow_call:
4
+ inputs:
5
+ runtime-ref:
6
+ description: Exact Code Foundry tag or SHA containing the verifier.
7
+ required: true
8
+ type: string
9
+ tag:
10
+ description: Exact published release tag in the caller repository.
11
+ required: true
12
+ type: string
13
+ expected-sha:
14
+ description: Optional full expected source commit SHA.
15
+ required: false
16
+ type: string
17
+ default: ''
18
+ outputs:
19
+ source-sha:
20
+ description: Verified immutable tag commit.
21
+ value: ${{ jobs.verify.outputs.source-sha }}
22
+ permissions:
23
+ contents: read
24
+ attestations: read
25
+ jobs:
26
+ verify:
27
+ if: vars.CI_BILLING_PAUSED != 'true'
28
+ runs-on: ubuntu-latest
29
+ timeout-minutes: 10
30
+ outputs:
31
+ source-sha: ${{ steps.verify.outputs.source-sha }}
32
+ steps:
33
+ - name: Validate runtime pin
34
+ env:
35
+ RUNTIME_REF: ${{ inputs.runtime-ref }}
36
+ run: '[[ "$RUNTIME_REF" =~ ^(v[0-9]+\.[0-9]+\.[0-9]+|[0-9a-fA-F]{40})$ ]]'
37
+ - name: Checkout verifier, not release-owned executable code
38
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
39
+ with:
40
+ repository: 0xPlayerOne/code-foundry
41
+ ref: ${{ inputs.runtime-ref }}
42
+ persist-credentials: false
43
+ sparse-checkout: src/commands
44
+ - name: Verify immutable release and signed attestation
45
+ id: verify
46
+ env:
47
+ GH_TOKEN: ${{ github.token }}
48
+ RELEASE_TAG: ${{ inputs.tag }}
49
+ EXPECTED_SHA: ${{ inputs.expected-sha }}
50
+ run: |
51
+ set -euo pipefail
52
+ args=(release --repo "$GITHUB_REPOSITORY" --tag "$RELEASE_TAG")
53
+ if [ -n "$EXPECTED_SHA" ]; then args+=(--expected-sha "$EXPECTED_SHA"); fi
54
+ node src/commands/release-integrity.mjs "${args[@]}" > "$RUNNER_TEMP/release-integrity.json"
55
+ node -e 'const fs = require("node:fs"); const r = JSON.parse(fs.readFileSync(process.env.RUNNER_TEMP + "/release-integrity.json")); fs.appendFileSync(process.env.GITHUB_OUTPUT, "source-sha=" + r.sourceSha + "\n")'
56
+ - name: Preserve verification evidence
57
+ if: always() && steps.verify.outcome != 'skipped'
58
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
59
+ with:
60
+ name: release-integrity-${{ github.run_id }}-${{ github.run_attempt }}
61
+ path: ${{ runner.temp }}/release-integrity.json
62
+ if-no-files-found: error
63
+ retention-days: 30
@@ -0,0 +1,22 @@
1
+ name: Verify Code Foundry Release Integrity
2
+ on:
3
+ release:
4
+ types: [published]
5
+ workflow_dispatch:
6
+ inputs:
7
+ tag:
8
+ description: Published immutable release tag to verify.
9
+ required: true
10
+ type: string
11
+ permissions:
12
+ contents: read
13
+ attestations: read
14
+ jobs:
15
+ verify:
16
+ # Enable only after an administrator enables immutable releases. This is a
17
+ # post-publication verifier, not a substitute for the GitHub repository setting.
18
+ if: vars.CI_BILLING_PAUSED != 'true' && (vars.REQUIRE_IMMUTABLE_RELEASES == 'true' || github.event_name == 'workflow_dispatch')
19
+ uses: ./.github/workflows/release-integrity.yml
20
+ with:
21
+ runtime-ref: ${{ github.sha }}
22
+ tag: ${{ github.event.release.tag_name || inputs.tag }}
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.15.0](https://github.com/0xPlayerOne/code-foundry/compare/v1.14.0...v1.15.0) (2026-09-09)
4
+
5
+
6
+ ### Features
7
+
8
+ * **releases:** verify immutable releases and attest selected build artifacts ([#537](https://github.com/0xPlayerOne/code-foundry/issues/537)) ([099aa57](https://github.com/0xPlayerOne/code-foundry/commit/099aa577227ab067a9a554e4cfc286aa2f5eb38e))
9
+
3
10
  ## [1.14.0](https://github.com/0xPlayerOne/code-foundry/compare/v1.13.0...v1.14.0) (2026-09-09)
4
11
 
5
12
 
package/README.md CHANGED
@@ -127,7 +127,8 @@ first. Either way, Release Please creates a GitHub release after the version
127
127
  PR is merged. npm publication is opt-in through `npm_publish: true` and
128
128
  supports npm trusted publishing or an `NPM_TOKEN` fallback.
129
129
 
130
- Read [Release management](docs/RELEASES.md) and
130
+ Read [Release management](docs/RELEASES.md),
131
+ [Release integrity and build provenance](docs/release-integrity.md), and
131
132
  [Publishing packages](docs/PUBLISHING.md) before enabling automated
132
133
  publishing. They are intentionally written with placeholders so they can be
133
134
  copied into other repositories.
package/docs/README.md CHANGED
@@ -10,6 +10,7 @@ its own names, environments, and deployment details.
10
10
  - [Configuration reference](CONFIGURATION.md)
11
11
  - [Workflow and CI conventions](WORKFLOWS.md)
12
12
  - [Release management](RELEASES.md)
13
+ - [Release integrity and build provenance](release-integrity.md)
13
14
  - [Publishing packages](PUBLISHING.md)
14
15
  - [Caching and remote caching](CACHING.md)
15
16
  - [Performance budgets and baselines](PERFORMANCE.md)
@@ -0,0 +1,140 @@
1
+ # Release integrity and build provenance
2
+
3
+ Code Foundry now provides a read-only immutable-setting preflight, cryptographic
4
+ release/asset verification, and an optional build-provenance action. These are
5
+ separate guarantees: a checksum identifies bytes, an attestation identifies their
6
+ origin, and GitHub's immutable-release setting prevents replacement after publish.
7
+
8
+ ## Enable immutable releases explicitly
9
+
10
+ An administrator must enable **Settings → General → Releases → Enable release
11
+ immutability**. This applies only to future releases. Existing mutable releases
12
+ are not retroactively frozen, and this implementation does not change the setting.
13
+ After enabling it, set the repository variable `REQUIRE_IMMUTABLE_RELEASES=true`
14
+ to activate Code Foundry's post-publication verification caller. Manual dispatch
15
+ can verify an explicitly selected tag without the variable. Billing pause is
16
+ honored by both workflows. A skipped workflow is not verification evidence.
17
+
18
+ Publish all assets to a draft release **before** publishing it. Do not attach or
19
+ replace assets after an immutable release is published. The existing Release
20
+ Please/npm workflow is not rewritten by this change; repositories adding release
21
+ assets must review their attachment ordering before enabling immutability.
22
+
23
+ A release workflow can run this preflight before publication:
24
+
25
+ ```sh
26
+ npx code-foundry release-integrity settings --repo owner/repository
27
+ ```
28
+
29
+ The setting endpoint needs an authenticated identity with repository
30
+ Administration **read** permission. Do not grant Administration write for this
31
+ check. The ordinary Actions token may be unable to read it. Inaccessible,
32
+ unsupported, malformed, or disabled settings fail as unverified; a 404 is not
33
+ silently interpreted as proof that a setting is absent. No setting writes exist
34
+ in the verifier.
35
+
36
+ ## Verify published releases and local assets
37
+
38
+ ```sh
39
+ npx code-foundry release-integrity release \
40
+ --repo owner/repository --tag v1.2.3 \
41
+ --expected-sha FULL_40_CHARACTER_COMMIT_SHA \
42
+ --asset dist/package.tgz
43
+ ```
44
+
45
+ `--expected-sha` and repeatable `--asset` are optional. Verification requires the
46
+ exact published tag to be immutable, invokes `gh release verify` for signed
47
+ release-attestation validation, resolves lightweight/annotated tags to a commit,
48
+ and optionally checks that commit against the expected source. Each local asset
49
+ is checked with `gh release verify-asset`, and hashed before/after verification to
50
+ reject replacement during the check. GitHub-generated source archives are not
51
+ supported release assets for this command; verify uploaded binaries/packages.
52
+ The GitHub CLI must support these subcommands; an older CLI fails rather than
53
+ falling back to a metadata-only claim. The verifier targets github.com explicitly.
54
+
55
+ JSON is emitted on stdout with a nonzero exit status on failure. No credential or
56
+ raw failed API response is included in the report. Selected assets must be
57
+ nonempty regular files inside the repository, without symlink components.
58
+
59
+ `sync` installs an opt-in release-event caller in
60
+ `.github/workflows/release-integrity.yml`; set `REQUIRE_IMMUTABLE_RELEASES=true`
61
+ to enable it. To call the reusable workflow directly, pin both references to the
62
+ same reviewed tag or commit:
63
+
64
+ ```yaml
65
+ permissions:
66
+ contents: read
67
+ attestations: read
68
+ jobs:
69
+ verify-release:
70
+ uses: 0xPlayerOne/code-foundry/.github/workflows/release-integrity.yml@REVIEWED_REF
71
+ with:
72
+ runtime-ref: REVIEWED_REF
73
+ tag: v1.2.3
74
+ expected-sha: FULL_40_CHARACTER_COMMIT_SHA
75
+ ```
76
+
77
+ `runtime-ref`, `tag`, and optional `expected-sha` are the workflow inputs. The job
78
+ checks out only the selected verifier, not executable code from the release under
79
+ test, needs `contents: read` and `attestations: read`, preserves evidence, and
80
+ exposes the verified `source-sha`. Downstream publication or consumer steps should
81
+ explicitly `needs` this job when verification is their gate. Code Foundry's own
82
+ release-event caller verifies **after publication**; it cannot prevent a release
83
+ that has already been published. Actual immutability comes from the repository
84
+ setting.
85
+
86
+ ## Optional build provenance
87
+
88
+ In the same trusted job that builds the artifacts, grant `contents: read`,
89
+ `id-token: write`, and `attestations: write`, then call:
90
+
91
+ ```yaml
92
+ - name: Attest built package
93
+ # Replace REVIEWED_SHA with the reviewed Code Foundry commit.
94
+ uses: 0xPlayerOne/code-foundry/.github/actions/attest-artifact@REVIEWED_SHA
95
+ id: provenance
96
+ with:
97
+ artifacts: '["dist/package.tgz"]'
98
+ ```
99
+
100
+ The action hashes only the explicitly selected files, generates a checksum
101
+ manifest, signs those digests with the commit-pinned official GitHub provenance
102
+ action, and checks the files have not changed during signing. Its outputs provide
103
+ the manifest, signed bundle, and attestation URL. Persist the manifest and bundle
104
+ alongside build evidence; attach release assets before publishing an immutable
105
+ release. The action refuses PR event contexts. Repository-owned build scripts
106
+ must still be trusted: signing attacker-controlled downloaded bytes does not
107
+ prove that this job built them. Do not place attestation into an unrelated job
108
+ that merely downloads and re-labels artifacts from another build.
109
+
110
+ Artifact attestations require GitHub support for the repository/account. Never
111
+ silently skip a required attestation because the account lacks that capability.
112
+ Consumers should use `gh attestation verify` with the expected source repository
113
+ and trusted signer workflow as appropriate; digest equality alone is insufficient.
114
+ This action covers local file artifacts, not registry image publishing. npm
115
+ trusted publishing remains available through the existing release workflow; this
116
+ change does not replace or require an npm token.
117
+
118
+ Generate a local unsigned manifest without GitHub/network access with:
119
+
120
+ ```sh
121
+ npx code-foundry release-integrity manifest --asset dist/package.tgz
122
+ ```
123
+
124
+ That command makes no provenance or authenticity claim.
125
+
126
+ ## Validation and references
127
+
128
+ Run `node --test test/release-integrity.test.mjs`. Tests cover exact command
129
+ contracts, signature-verifier invocation, tag identity, asset replacement/path
130
+ safety, settings uncertainty, sync-installed caller wiring, and pinned/read-only
131
+ workflow structure using CLI fixtures. Real signing and release verification
132
+ require a supported authenticated GitHub environment and must be exercised there
133
+ before rollout.
134
+
135
+ - https://docs.github.com/en/code-security/concepts/supply-chain-security/immutable-releases
136
+ - https://docs.github.com/en/code-security/how-tos/secure-your-supply-chain/secure-your-dependencies/verify-release-integrity
137
+ - https://cli.github.com/manual/gh_release_verify
138
+ - https://cli.github.com/manual/gh_release_verify-asset
139
+ - https://docs.github.com/en/rest/repos/repos#get-immutable-releases-settings
140
+ - https://docs.github.com/actions/security-for-github-actions/using-artifact-attestations/using-artifact-attestations-to-establish-provenance-for-builds
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code-foundry",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "description": "A fast, language-aware repository factory for agent-ready workflows, testing, security, and release automation.",
5
5
  "homepage": "https://github.com/0xPlayerOne/code-foundry#readme",
6
6
  "bugs": {
package/src/cli.mjs CHANGED
@@ -7,7 +7,7 @@ import { fileURLToPath } from 'node:url'
7
7
 
8
8
  const packageRoot = resolve(fileURLToPath(new URL('..', import.meta.url)))
9
9
 
10
- /** @typedef {{ target: string, root: string, dryRun: boolean, force: boolean, github: boolean, createPr: boolean, exclude: string[], base: string, head: string, tag: string, workflow: string, mode: string, version: string, releaseSubcommand?: string, fleetSubcommand?: string, ciSubcommand?: 'pause'|'resume'|'status' }} Options */
10
+ /** @typedef {{ target: string, root: string, dryRun: boolean, force: boolean, github: boolean, createPr: boolean, exclude: string[], base: string, head: string, tag: string, workflow: string, mode: string, version: string, repository: string, expectedSha: string, assets: string[], rootProvided: boolean, releaseSubcommand?: string, fleetSubcommand?: string, integritySubcommand?: 'settings'|'release'|'manifest', ciSubcommand?: 'pause'|'resume'|'status' }} Options */
11
11
  /** @typedef {{ command: string, options: Options }} ParsedArgs */
12
12
 
13
13
  const usage = `code-foundry — initialize and maintain agent-ready repositories
@@ -21,6 +21,9 @@ Usage:
21
21
  npx code-foundry ci pause|resume|status [--target PATH]
22
22
  npx code-foundry release reconcile [--github] [--base BRANCH] [--head BRANCH]
23
23
  npx code-foundry release hook --tag TAG --workflow WORKFLOW
24
+ npx code-foundry release-integrity settings --repo OWNER/REPO
25
+ npx code-foundry release-integrity release --repo OWNER/REPO --tag TAG
26
+ npx code-foundry release-integrity manifest --asset PATH [--root PATH]
24
27
  npx code-foundry fleet status [--root PATH]
25
28
  npx code-foundry fleet upgrade [--root PATH] [--dry-run] [--create-pr]
26
29
 
@@ -38,6 +41,9 @@ Options:
38
41
  --tag TAG Published release tag for a post-release hook
39
42
  --workflow FILE Workflow to dispatch for a post-release hook
40
43
  --mode MODE auto, workflow-dispatch, release-event, or disabled
44
+ --repo OWNER/REPO GitHub repository for release-integrity commands
45
+ --expected-sha SHA Expected source commit for release-integrity verification
46
+ --asset PATH Selected release-integrity artifact (repeatable)
41
47
  --root PATH Fleet root containing repositories (default: current directory)
42
48
  --create-pr Create isolated upgrade branches and pull requests
43
49
  --version TAG Runtime tag to report in fleet upgrade branches
@@ -71,6 +77,10 @@ function parseArgs(argv) {
71
77
  workflow: '',
72
78
  mode: 'auto',
73
79
  version: `v${readPackageVersion(packageRoot)}`,
80
+ repository: '',
81
+ expectedSha: '',
82
+ assets: [],
83
+ rootProvided: false,
74
84
  }
75
85
 
76
86
  if (command === 'release') {
@@ -80,6 +90,13 @@ function parseArgs(argv) {
80
90
  `unknown release command: ${subcommand ?? '(missing)'}; use release reconcile, release hook, release validate-prs, or release recovery-plan`
81
91
  )
82
92
  options.releaseSubcommand = subcommand
93
+ } else if (command === 'release-integrity') {
94
+ const subcommand = argv.shift() ?? ''
95
+ if (!['settings', 'release', 'manifest'].includes(subcommand))
96
+ fail(
97
+ `unknown release-integrity command: ${subcommand || '(missing)'}; use release-integrity settings, release, or manifest`
98
+ )
99
+ options.integritySubcommand = /** @type {'settings'|'release'|'manifest'} */ (subcommand)
83
100
  } else if (command === 'fleet') {
84
101
  const subcommand = argv.shift() ?? ''
85
102
  if (subcommand !== 'status' && subcommand !== 'upgrade')
@@ -110,12 +127,26 @@ function parseArgs(argv) {
110
127
  else if (arg === '--base') options.base = argv.shift() ?? fail('--base requires a branch')
111
128
  else if (arg === '--head') options.head = argv.shift() ?? fail('--head requires a branch')
112
129
  else if (arg === '--tag') options.tag = argv.shift() ?? fail('--tag requires a tag')
113
- else if (arg === '--workflow')
130
+ else if (arg === '--repo') {
131
+ if (command !== 'release-integrity')
132
+ fail('--repo is only supported by release-integrity commands')
133
+ options.repository = argv.shift() ?? fail('--repo requires OWNER/REPO')
134
+ } else if (arg === '--expected-sha') {
135
+ if (command !== 'release-integrity')
136
+ fail('--expected-sha is only supported by release-integrity commands')
137
+ options.expectedSha = argv.shift() ?? fail('--expected-sha requires a commit SHA')
138
+ } else if (arg === '--asset') {
139
+ if (command !== 'release-integrity')
140
+ fail('--asset is only supported by release-integrity commands')
141
+ options.assets.push(argv.shift() ?? fail('--asset requires a path'))
142
+ } else if (arg === '--workflow')
114
143
  options.workflow = argv.shift() ?? fail('--workflow requires a workflow')
115
144
  else if (arg === '--mode')
116
145
  options.mode = argv.shift() ?? fail('--mode requires a delivery mode')
117
- else if (arg === '--root') options.root = argv.shift() ?? fail('--root requires a path')
118
- else if (arg === '--create-pr') options.createPr = true
146
+ else if (arg === '--root') {
147
+ options.root = argv.shift() ?? fail('--root requires a path')
148
+ options.rootProvided = true
149
+ } else if (arg === '--create-pr') options.createPr = true
119
150
  else if (arg === '--version') options.version = argv.shift() ?? fail('--version requires a tag')
120
151
  else if (arg === '--exclude')
121
152
  options.exclude.push(argv.shift() ?? fail('--exclude requires a name'))
@@ -177,6 +208,32 @@ async function main() {
177
208
  } catch (error) {
178
209
  fail(error instanceof Error ? error.message : String(error))
179
210
  }
211
+ } else if (command === 'release-integrity') {
212
+ try {
213
+ const { integrityCommand } = await import('./commands/release-integrity.mjs')
214
+ const integrityArgs = /** @type {string[]} */ ([options.integritySubcommand])
215
+ if (options.repository) integrityArgs.push('--repo', options.repository)
216
+ if (options.tag) integrityArgs.push('--tag', options.tag)
217
+ if (options.expectedSha) integrityArgs.push('--expected-sha', options.expectedSha)
218
+ if (options.rootProvided || options.integritySubcommand !== 'settings')
219
+ integrityArgs.push('--root', options.root)
220
+ for (const asset of options.assets) integrityArgs.push('--asset', asset)
221
+ console.log(JSON.stringify(integrityCommand(integrityArgs), null, 2))
222
+ } catch (error) {
223
+ console.log(
224
+ JSON.stringify(
225
+ {
226
+ schemaVersion: 1,
227
+ kind: 'code-foundry-release-integrity',
228
+ status: 'failed',
229
+ reason: error instanceof Error ? error.message : String(error),
230
+ },
231
+ null,
232
+ 2
233
+ )
234
+ )
235
+ process.exitCode = 1
236
+ }
180
237
  } else if (command === 'fleet') {
181
238
  try {
182
239
  const { discoverRepositories, upgradeFleet } = await import('./commands/fleet.mjs')
@@ -0,0 +1,254 @@
1
+ #!/usr/bin/env node
2
+ // @ts-check
3
+
4
+ import { createHash } from 'node:crypto'
5
+ import { lstatSync, readFileSync, realpathSync } from 'node:fs'
6
+ import { basename, isAbsolute, relative, resolve, sep } from 'node:path'
7
+ import { spawnSync } from 'node:child_process'
8
+ import { pathToFileURL } from 'node:url'
9
+
10
+ /** @typedef {(argv: string[]) => {status: number|null, stdout: string}} Runner */
11
+
12
+ /** @type {Runner} */
13
+ export function runGh(argv) {
14
+ const result = spawnSync('gh', argv, {
15
+ encoding: 'utf8',
16
+ timeout: 120000,
17
+ maxBuffer: 8 * 1024 * 1024,
18
+ env: { ...process.env, GH_PROMPT_DISABLED: '1', GH_HOST: 'github.com' },
19
+ })
20
+ if (result.error) throw new Error(`GitHub CLI unavailable: ${result.error.name}`)
21
+ return { status: result.status, stdout: result.stdout ?? '' }
22
+ }
23
+
24
+ /** @param {string} repository */
25
+ function validateRepository(repository) {
26
+ if (
27
+ !/^[\w.-]+\/[\w.-]+$/.test(repository) ||
28
+ repository.split('/').some((part) => ['.', '..'].includes(part))
29
+ )
30
+ throw new Error('repository must be an owner/name on github.com')
31
+ }
32
+
33
+ /** @param {string} tag */
34
+ function validateTag(tag) {
35
+ const hasInvalidCharacter = tag
36
+ ? [...tag].some((character) => {
37
+ const codePoint = character.codePointAt(0)
38
+ return (
39
+ (codePoint !== undefined && (codePoint <= 0x20 || codePoint === 0x7f)) ||
40
+ '~^:?*[\\'.includes(character)
41
+ )
42
+ })
43
+ : false
44
+ if (
45
+ !tag ||
46
+ tag.startsWith('-') ||
47
+ hasInvalidCharacter ||
48
+ tag.includes('..') ||
49
+ tag.includes('@{')
50
+ )
51
+ throw new Error('Invalid release tag')
52
+ }
53
+
54
+ /** @param {Runner} run @param {string[]} argv */
55
+ function json(run, argv) {
56
+ const result = run(argv)
57
+ if (result.status !== 0)
58
+ throw new Error(
59
+ `GitHub verification command failed (${result.status ?? 'signal'}); state is unverified`
60
+ )
61
+ try {
62
+ return JSON.parse(result.stdout)
63
+ } catch {
64
+ throw new Error('GitHub verification returned invalid JSON; state is unverified')
65
+ }
66
+ }
67
+
68
+ /** @param {Runner} run @param {string} endpoint */
69
+ function api(run, endpoint) {
70
+ return json(run, ['api', '--hostname', 'github.com', endpoint])
71
+ }
72
+
73
+ /** Read only. A permissions failure is unknown, never evidence of disabled settings.
74
+ * @param {string} repository @param {Runner} [run]
75
+ */
76
+ export function verifyImmutableSetting(repository, run = runGh) {
77
+ validateRepository(repository)
78
+ const result = api(run, `repos/${repository}/immutable-releases`)
79
+ if (result?.enabled !== true) throw new Error('Release immutability is not confirmed enabled')
80
+ return {
81
+ schemaVersion: 1,
82
+ kind: 'code-foundry-release-integrity',
83
+ status: 'passed',
84
+ repository,
85
+ check: 'immutable-setting',
86
+ enforcedByOwner: result.enforced_by_owner === true,
87
+ }
88
+ }
89
+
90
+ /** @param {string} root @param {string} file */
91
+ export function assetDigest(root, file) {
92
+ if (!file || isAbsolute(file)) throw new Error('Asset paths must be repository-relative')
93
+ const base = realpathSync(root)
94
+ const path = resolve(base, file)
95
+ const rel = relative(base, path)
96
+ if (!rel || rel === '..' || rel.startsWith(`..${sep}`))
97
+ throw new Error('Asset path escapes repository')
98
+ let current = base
99
+ for (const part of rel.split(sep)) {
100
+ current = resolve(current, part)
101
+ if (lstatSync(current).isSymbolicLink()) throw new Error('Release assets must not be symlinks')
102
+ }
103
+ if (!lstatSync(path).isFile()) throw new Error('Release asset must be a regular file')
104
+ const content = readFileSync(path)
105
+ if (!content.length) throw new Error('Release asset is empty')
106
+ return {
107
+ file: rel.split(sep).join('/'),
108
+ name: basename(path),
109
+ bytes: content.length,
110
+ digest: `sha256:${createHash('sha256').update(content).digest('hex')}`,
111
+ path,
112
+ }
113
+ }
114
+
115
+ /** @param {string} root @param {string[]} files */
116
+ export function assetManifest(root, files) {
117
+ if (!files.length) throw new Error('At least one artifact is required')
118
+ const assets = files.map((file) => assetDigest(root, file))
119
+ if (new Set(assets.map((asset) => asset.file)).size !== assets.length)
120
+ throw new Error('Duplicate artifact')
121
+ if (assets.some((asset) => /[\r\n\\]/.test(asset.file)))
122
+ throw new Error('Unsupported checksum filename')
123
+ return {
124
+ schemaVersion: 1,
125
+ kind: 'code-foundry-asset-manifest',
126
+ assets: assets.map(({ path: _path, ...asset }) => asset),
127
+ checksums: assets.map((asset) => `${asset.digest.slice(7)} ${asset.file}\n`).join(''),
128
+ }
129
+ }
130
+
131
+ /** @param {Runner} run @param {string} repository @param {string} tag */
132
+ function tagCommit(run, repository, tag) {
133
+ let object = api(run, `repos/${repository}/git/ref/tags/${encodeURIComponent(tag)}`).object
134
+ for (let depth = 0; object?.type === 'tag' && depth < 8; depth += 1) {
135
+ if (!/^[0-9a-f]{40}$/i.test(object.sha ?? '')) throw new Error('Malformed annotated tag')
136
+ object = api(run, `repos/${repository}/git/tags/${object.sha}`).object
137
+ }
138
+ if (object?.type !== 'commit' || !/^[0-9a-f]{40}$/i.test(object.sha ?? ''))
139
+ throw new Error('Release tag does not resolve to a commit')
140
+ return object.sha
141
+ }
142
+
143
+ /** GitHub CLI performs signature/attestation verification, not merely a metadata check.
144
+ * @param {{repository: string, tag: string, root?: string, assets?: string[], expectedSha?: string}} options
145
+ * @param {Runner} [run]
146
+ */
147
+ export function verifyRelease(options, run = runGh) {
148
+ const { repository, tag } = options
149
+ validateRepository(repository)
150
+ validateTag(tag)
151
+ if (options.expectedSha && !/^[0-9a-f]{40}$/i.test(options.expectedSha))
152
+ throw new Error('expected-sha must be a full commit SHA')
153
+ const release = api(run, `repos/${repository}/releases/tags/${encodeURIComponent(tag)}`)
154
+ if (release?.immutable !== true || release.draft !== false || release.tag_name !== tag)
155
+ throw new Error('Expected a published immutable release with the exact requested tag')
156
+ json(run, ['release', 'verify', tag, '--repo', repository, '--format', 'json'])
157
+ const sourceSha = tagCommit(run, repository, tag)
158
+ if (options.expectedSha && options.expectedSha.toLowerCase() !== sourceSha.toLowerCase())
159
+ throw new Error('Release tag does not match the expected source SHA')
160
+ const assets = []
161
+ for (const file of options.assets ?? []) {
162
+ const asset = assetDigest(options.root ?? process.cwd(), file)
163
+ json(run, [
164
+ 'release',
165
+ 'verify-asset',
166
+ tag,
167
+ asset.path,
168
+ '--repo',
169
+ repository,
170
+ '--format',
171
+ 'json',
172
+ ])
173
+ // Rehash after signature verification so a replaced local file is not reported verified.
174
+ if (assetDigest(options.root ?? process.cwd(), file).digest !== asset.digest)
175
+ throw new Error('Local release asset changed during verification')
176
+ assets.push({ file: asset.file, bytes: asset.bytes, digest: asset.digest, status: 'verified' })
177
+ }
178
+ return {
179
+ schemaVersion: 1,
180
+ kind: 'code-foundry-release-integrity',
181
+ status: 'passed',
182
+ check: 'release-attestation',
183
+ repository,
184
+ tag,
185
+ sourceSha,
186
+ immutable: true,
187
+ assets,
188
+ }
189
+ }
190
+
191
+ /** @param {string[]} argv @param {Runner} [run] */
192
+ export function integrityCommand(argv, run = runGh) {
193
+ const [command, ...args] = argv
194
+ /** @type {Record<string, string>} */
195
+ const values = {}
196
+ const assets = []
197
+ while (args.length) {
198
+ const key = args.shift()
199
+ if (!key || !['--repo', '--tag', '--root', '--asset', '--expected-sha'].includes(key))
200
+ throw new Error(`Unknown argument: ${key}`)
201
+ const value = args.shift()
202
+ if (!value || value.startsWith('--')) throw new Error(`Missing value for ${key}`)
203
+ if (key === '--asset') assets.push(value)
204
+ else {
205
+ if (Object.hasOwn(values, key)) throw new Error(`Duplicate ${key}`)
206
+ values[key] = value
207
+ }
208
+ }
209
+ const allowed =
210
+ command === 'settings'
211
+ ? ['--repo']
212
+ : command === 'manifest'
213
+ ? ['--root']
214
+ : ['--repo', '--tag', '--root', '--expected-sha']
215
+ if (
216
+ Object.keys(values).some((key) => !allowed.includes(key)) ||
217
+ (command === 'settings' && assets.length)
218
+ )
219
+ throw new Error('An argument is not supported by this integrity command')
220
+ if (command === 'settings') return verifyImmutableSetting(values['--repo'] ?? '', run)
221
+ if (command === 'manifest') return assetManifest(values['--root'] ?? process.cwd(), assets)
222
+ if (command === 'release')
223
+ return verifyRelease(
224
+ {
225
+ repository: values['--repo'] ?? '',
226
+ tag: values['--tag'] ?? '',
227
+ root: values['--root'],
228
+ expectedSha: values['--expected-sha'],
229
+ assets,
230
+ },
231
+ run
232
+ )
233
+ throw new Error('Use release-integrity settings, release, or manifest')
234
+ }
235
+
236
+ if (process.argv[1] && pathToFileURL(resolve(process.argv[1])).href === import.meta.url) {
237
+ try {
238
+ console.log(JSON.stringify(integrityCommand(process.argv.slice(2)), null, 2))
239
+ } catch (error) {
240
+ console.log(
241
+ JSON.stringify(
242
+ {
243
+ schemaVersion: 1,
244
+ kind: 'code-foundry-release-integrity',
245
+ status: 'failed',
246
+ reason: error instanceof Error ? error.message : String(error),
247
+ },
248
+ null,
249
+ 2
250
+ )
251
+ )
252
+ process.exitCode = 1
253
+ }
254
+ }
@@ -48,6 +48,7 @@ const standardFiles = [
48
48
  '.github/workflows/draft-pr.yml',
49
49
  '.github/workflows/release-pr.yml',
50
50
  '.github/workflows/release.yml',
51
+ '.github/workflows/release-integrity.yml',
51
52
  '.github/workflows/opencode-security.yml',
52
53
  ]
53
54
 
@@ -492,6 +493,7 @@ function shouldInclude(file, languages, features, config) {
492
493
  // without a configuration change. The detect job keeps the scan off unless
493
494
  // the configuration or the variable enables it and the API key exists.
494
495
  if (file === '.github/workflows/opencode-security.yml') return true
496
+ if (file === '.github/workflows/release-integrity.yml') return true
495
497
  const workflow = file.match(/^\.github\/workflows\/([^/]+)\.yml$/)?.[1]
496
498
  if (workflow === 'draft-control' || workflow === 'draft-enforcement') {
497
499
  return (