@jakobm/peacekeeper 0.25.2 → 0.27.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.
Files changed (40) hide show
  1. package/README.md +464 -89
  2. package/dist/cmdabra.yaml +174 -110
  3. package/dist/package.json +6 -5
  4. package/dist/src/modules/cli/legacy-commands.js +37 -0
  5. package/dist/src/modules/cli/service.js +48 -39
  6. package/dist/src/modules/configuration/convention-rules.js +93 -0
  7. package/dist/src/modules/configuration/facade.js +1 -0
  8. package/dist/src/modules/configuration/project-config-defaults.json +5 -1
  9. package/dist/src/modules/configuration/project-config.js +28 -9
  10. package/dist/src/modules/configuration/update-config.js +16 -2
  11. package/dist/src/modules/dependencies.yaml +4 -4
  12. package/dist/src/modules/external.js +5 -0
  13. package/dist/src/modules/lifecycle/checkpoint-instructions.js +1 -1
  14. package/dist/src/modules/lifecycle/cleanup-ended-session.js +1 -1
  15. package/dist/src/modules/maintenance/cleanup-merged-branches.js +4 -4
  16. package/dist/src/modules/maintenance/initialize-codex-worktree.js +1 -1
  17. package/dist/src/modules/maintenance/remove-empty-directories.js +1 -1
  18. package/dist/src/modules/projects/check-project-requirements.txt +32 -31
  19. package/dist/src/modules/projects/check-project.js +16 -16
  20. package/dist/src/modules/projects/codex-setup-prefix.sh +2 -2
  21. package/dist/src/modules/projects/create-project-core.js +13 -28
  22. package/dist/src/modules/projects/generate-github-setup.js +16 -55
  23. package/dist/src/modules/projects/github-setup-prefix.sh +29 -2
  24. package/dist/src/modules/projects/github-setup-repository-template.sh +1 -40
  25. package/dist/src/modules/projects/github-setup-suffix-template.sh +7 -5
  26. package/dist/src/modules/projects/install-hooks.js +6 -5
  27. package/dist/src/modules/releases/configure-github.js +57 -0
  28. package/dist/src/modules/releases/facade.js +3 -2
  29. package/dist/src/modules/releases/github-configuration.js +166 -0
  30. package/dist/src/modules/releases/github-policy.js +45 -11
  31. package/dist/src/modules/releases/github-remote.js +230 -0
  32. package/dist/src/modules/testing/check-conventions.js +41 -0
  33. package/dist/src/modules/testing/check-test-receipt.js +17 -22
  34. package/dist/src/modules/testing/conventions.js +168 -0
  35. package/dist/src/modules/testing/facade.js +2 -1
  36. package/dist/src/modules/testing/receipt-state.js +27 -1
  37. package/dist/src/modules/testing/record-test-receipt.js +14 -13
  38. package/dist/src/modules/testing/run-tests.js +23 -14
  39. package/dist/src/modules/testing/types.js +1 -0
  40. package/package.json +6 -5
@@ -1,4 +1,4 @@
1
- export default ({ external: { execFileSync, fs, path, projectConfigDefaults, runtime, YAML, } }) => {
1
+ export default ({ conventionRules, external: { execFileSync, fs, path, projectConfigDefaults, runtime, YAML, } }) => {
2
2
  const CONFIG_FILE = 'peacekeeper.config.yaml';
3
3
  const LEGACY_CONFIG_FILE = 'peacekeeper.config.json';
4
4
  function repositoryRoot(cwd = runtime.cwd()) {
@@ -13,7 +13,8 @@ export default ({ external: { execFileSync, fs, path, projectConfigDefaults, run
13
13
  git: { remote: true, defaultBranch: true, branchPrefix: true, requiredApprover: true,
14
14
  checkpointPushRemotes: true, releaseMergeMethod: true,
15
15
  releaseRequiredChecks: true, releaseTestWorkflow: true },
16
- tests: { commands: true, receiptMaxAgeMinutes: true, npmTestUsesRunner: true },
16
+ tests: { all: true, checkpoint: true, receiptMaxAgeMinutes: true, npmTestUsesRunner: true },
17
+ conventions: { rules: true },
17
18
  loggingDirectory: true,
18
19
  loggingEnabled: true,
19
20
  projectChecks: { testWorkflow: true, requiredJobs: true },
@@ -44,7 +45,13 @@ export default ({ external: { execFileSync, fs, path, projectConfigDefaults, run
44
45
  const errors = [];
45
46
  validateShape(config, CONFIG_SCHEMA, 'config', errors);
46
47
  if (errors.length)
47
- throw new Error(`${file}: ${errors.join('; ')}. Run peacekeeper update-config to add missing fields.`);
48
+ throw new Error(`${file}: ${errors.join('; ')}. Run peacekeeper project update-config to add missing fields.`);
49
+ try {
50
+ conventionRules.validate(config.conventions.rules);
51
+ }
52
+ catch (error) {
53
+ throw new Error(`${file}: ${error instanceof Error ? error.message : String(error)}`);
54
+ }
48
55
  if (typeof config.projectChecks.testWorkflow !== 'string' || !/^[A-Za-z0-9_-]+\.ya?ml$/u.test(config.projectChecks.testWorkflow)) {
49
56
  throw new Error(`${file}: projectChecks.testWorkflow must be a workflow filename`);
50
57
  }
@@ -84,9 +91,15 @@ export default ({ external: { execFileSync, fs, path, projectConfigDefaults, run
84
91
  throw new Error(`${file}: loggingEnabled must be a boolean`);
85
92
  }
86
93
  requireNonemptyString(config.loggingDirectory, 'loggingDirectory', file);
87
- if (!Array.isArray(config.tests.commands)
88
- || config.tests.commands.some((command) => typeof command !== 'string' || command.trim() === '')) {
89
- throw new Error(`${file}: tests.commands must be an array of command strings`);
94
+ for (const level of ['all', 'checkpoint']) {
95
+ if (!Array.isArray(config.tests[level])
96
+ || config.tests[level].some((command) => typeof command !== 'string' || command.trim() === '')) {
97
+ throw new Error(`${file}: tests.${level} must be an array of command strings`);
98
+ }
99
+ }
100
+ const missing = config.tests.checkpoint.filter(command => !config.tests.all.includes(command));
101
+ if (missing.length) {
102
+ throw new Error(`${file}: every command in tests.checkpoint must also appear in tests.all; missing: ${JSON.stringify(missing)}`);
90
103
  }
91
104
  if (!Number.isSafeInteger(config.tests.receiptMaxAgeMinutes)
92
105
  || config.tests.receiptMaxAgeMinutes < 1) {
@@ -110,10 +123,16 @@ export default ({ external: { execFileSync, fs, path, projectConfigDefaults, run
110
123
  return { root, ...config };
111
124
  }
112
125
  function requireTestCommands(root) {
113
- if (!projectConfig(root).tests.commands.length) {
114
- throw new Error('Configure tests.commands before running tests or using a test receipt.');
126
+ if (!projectConfig(root).tests.all.length) {
127
+ throw new Error('Configure tests.all before running tests or using a test receipt.');
115
128
  }
116
129
  }
117
- const api = { CONFIG_FILE, LEGACY_CONFIG_FILE, CONFIG_SCHEMA, validateConfig, projectConfig, repositoryRoot, requireTestCommands };
130
+ function codeownersError(contents, approver) {
131
+ const lines = typeof contents === 'string' ? contents.split(/\r?\n/u)
132
+ .map(line => line.trim()).filter(line => line && !line.startsWith('#')) : [];
133
+ return lines.length === 1 && lines[0] === `* @${approver}` ? undefined
134
+ : `.github/CODEOWNERS: use exactly one ownership rule, "* @${approver}", so only git.requiredApprover can satisfy required code-owner review.`;
135
+ }
136
+ const api = { CONFIG_FILE, LEGACY_CONFIG_FILE, CONFIG_SCHEMA, validateConfig, projectConfig, repositoryRoot, requireTestCommands, codeownersError };
118
137
  return api;
119
138
  };
@@ -37,10 +37,24 @@ export default ({ projectConfig, external: { fs, isDeepStrictEqual, output, path
37
37
  if (document.errors.length)
38
38
  throw new Error(`${file}: ${document.errors.map(error => error.message).join('; ')}`);
39
39
  const original = document.toJS();
40
- const updated = complete(original, defaults);
40
+ const migrated = complete(original, {});
41
+ const legacyCommands = migrated?.tests && Object.hasOwn(migrated.tests, 'commands');
42
+ if (legacyCommands) {
43
+ if (Object.hasOwn(migrated.tests, 'all')) {
44
+ throw new Error(`${file}: both tests.commands and tests.all exist; remove tests.commands after reviewing both lists.`);
45
+ }
46
+ migrated.tests = { ...migrated.tests, all: migrated.tests.commands };
47
+ delete migrated.tests.commands;
48
+ }
49
+ const updated = complete(migrated, defaults);
41
50
  validateConfig(updated, file);
42
51
  if (!exists || !isDeepStrictEqual(original, updated)) {
43
- addMissing(document, original, defaults);
52
+ if (legacyCommands) {
53
+ const tests = document.getIn(['tests'], true);
54
+ const commands = tests.items.find(pair => pair.key.value === 'commands');
55
+ commands.key.value = 'all';
56
+ }
57
+ addMissing(document, migrated, defaults);
44
58
  fs.writeFileSync(file, document.toString({ lineWidth: 0 }));
45
59
  output.log(`Updated ${file}. Review defaults before using project commands.`);
46
60
  }
@@ -8,9 +8,9 @@ allowed-modules:
8
8
  testing: [configuration, projects]
9
9
  allowed-external:
10
10
  cli: [cliConfigPath, runCli, runtime]
11
- configuration: [execFileSync, fs, isDeepStrictEqual, output, path, projectConfigDefaults, runtime, YAML]
11
+ configuration: [YAML, execFileSync, fs, hasMagic, isDeepStrictEqual, output, path, projectConfigDefaults, runtime]
12
12
  lifecycle: [buffer, clock, executablePath, fs, output, path, runtime, spawn, spawnSync]
13
13
  maintenance: [execFileSync, fs, output, path, runtime, spawnSync]
14
- projects: [buffer, fs, isDeepStrictEqual, modulesRoot, output, packageVersion, path, projectConfigDefaults, runtime, semver, spawnSync, structuredClone, TOML, url, YAML]
15
- releases: [assessReleaseSchema, clock, execFileSync, fs, modulesRoot, os, output, path, runtime, semver, spawnSync, structuredClone, url, YAML]
16
- testing: [clock, crypto, execFileSync, fs, modulesRoot, os, output, path, runtime, spawnSync]
14
+ projects: [TOML, YAML, buffer, fs, isDeepStrictEqual, modulesRoot, output, packageVersion, path, projectConfigDefaults, runtime, semver, spawnSync, structuredClone, url]
15
+ releases: [YAML, assessReleaseSchema, buffer, clock, execFileSync, fs, modulesRoot, os, output, packageVersion, path, projectConfigDefaults, runtime, semver, spawnSync, structuredClone, url]
16
+ testing: [YAML, clock, crypto, execFileSync, fs, globSync, hasMagic, modulesRoot, os, output, path, runtime, spawnSync, test]
@@ -4,6 +4,8 @@ import fs from 'node:fs';
4
4
  import os from 'node:os';
5
5
  import path from 'node:path';
6
6
  import { isDeepStrictEqual } from 'node:util';
7
+ import test from 'node:test';
8
+ import { globSync, hasMagic } from 'glob';
7
9
  import { fileURLToPath } from 'node:url';
8
10
  import TOML from '@iarna/toml';
9
11
  import semver from 'semver';
@@ -30,6 +32,8 @@ export default () => ({
30
32
  crypto,
31
33
  execFileSync,
32
34
  fs,
35
+ globSync,
36
+ hasMagic,
33
37
  isDeepStrictEqual,
34
38
  modulesRoot: moduleDirectory,
35
39
  os,
@@ -43,6 +47,7 @@ export default () => ({
43
47
  spawn,
44
48
  spawnSync,
45
49
  structuredClone,
50
+ test,
46
51
  TOML,
47
52
  url: URL,
48
53
  YAML,
@@ -10,7 +10,7 @@ export default () => {
10
10
  + `(${config.git.defaultBranch}), first create and switch to a descriptive task branch named with the ${config.git.branchPrefix} prefix. `
11
11
  + 'Write an English commit message with a concise, descriptive single-line subject and a body '
12
12
  + 'separated from it by a blank line. The English body should explain the change using between '
13
- + 'one and ten sentences. Run `npm exec --no -- peacekeeper checkpoint-codex-changes '
13
+ + 'one and ten sentences. Run `npm exec --no -- peacekeeper codex checkpoint '
14
14
  + '--subject "<subject>" --body "<body paragraph>"`; repeat `--body` for additional paragraphs when useful. '
15
15
  + 'The command stages all changes, so do not include unrelated changes. '
16
16
  + 'Push behavior follows the project configuration. Unless an explicit user instruction disables '
@@ -219,7 +219,7 @@ export default ({ configuration, logScriptInvocation: invocation, maintenance, e
219
219
  const logPath = loggingEnabled ? path.join(target.commonGitDirectory, 'cleanup-ended-session.log') : null;
220
220
  const logFile = loggingEnabled ? fs.openSync(logPath, 'a') : 'ignore';
221
221
  const payload = buffer.from(JSON.stringify(target)).toString('base64url');
222
- const child = spawn(runtime.execPath, [executablePath, 'cleanup-ended-session', '--worker', payload], {
222
+ const child = spawn(runtime.execPath, [executablePath, 'codex', 'session-end', '--worker', payload], {
223
223
  cwd: target.repositoryRoot,
224
224
  detached: true,
225
225
  stdio: ['ignore', logFile, logFile],
@@ -5,9 +5,9 @@
5
5
  *
6
6
  * Recommended usage:
7
7
  *
8
- * npm exec --no -- peacekeeper cleanup-merged-branches # Dry-run (default).
9
- * npm exec --no -- peacekeeper cleanup-merged-branches --dry-run # Explicit dry-run.
10
- * npm exec --no -- peacekeeper cleanup-merged-branches --execute # Apply the displayed cleanup.
8
+ * npm exec --no -- peacekeeper cleanup merged-branches # Dry-run (default).
9
+ * npm exec --no -- peacekeeper cleanup merged-branches --dry-run # Explicit dry-run.
10
+ * npm exec --no -- peacekeeper cleanup merged-branches --execute # Apply the displayed cleanup.
11
11
  *
12
12
  * Every run fetches the configured remote, including dry-runs, so the cleanup
13
13
  * plan uses current remote references. Dry-run does not remove anything,
@@ -252,7 +252,7 @@ export default ({ configuration, external: { execFileSync, fs, output, path, run
252
252
  if (!execute) {
253
253
  log('');
254
254
  log('To apply this cleanup, run:');
255
- log(' npm exec --no -- peacekeeper cleanup-merged-branches --execute');
255
+ log(' npm exec --no -- peacekeeper cleanup merged-branches --execute');
256
256
  }
257
257
  }
258
258
  function run({ execute = false } = {}) {
@@ -264,7 +264,7 @@ export default ({ configuration, external: { fs, output, path, runtime, spawnSyn
264
264
  const root = git(cwd, 'rev-parse', '--show-toplevel');
265
265
  const primaryRoot = primaryWorktree(root);
266
266
  if (samePath(root, primaryRoot)) {
267
- throw new Error('initialize-codex-worktree must run from a linked Git worktree');
267
+ throw new Error('codex init-worktree must run from a linked Git worktree');
268
268
  }
269
269
  const config = projectConfig(root);
270
270
  let state = readState(root);
@@ -89,7 +89,7 @@ export default ({ external: { execFileSync, fs, output, path, runtime, } }) => {
89
89
  log(`Would remove ${directory}`);
90
90
  log('');
91
91
  log('To remove these directories, run:');
92
- log(' npm exec --no -- peacekeeper remove-empty-directories --execute');
92
+ log(' npm exec --no -- peacekeeper cleanup empty-directories --execute');
93
93
  }
94
94
  function main({ execute = false } = {}) {
95
95
  try {
@@ -5,7 +5,7 @@ Purpose and scope
5
5
  lifecycle hooks, and runs reproducible PR checks. Published npm packages also
6
6
  verify a release before publishing the tested version.
7
7
 
8
- check-project reads local files at the Git root. It makes no network requests,
8
+ project check reads local files at the Git root. It makes no network requests,
9
9
  runs no project scripts, and changes no files. Failure exits with status 1.
10
10
  Independent failures are reported together. Missing or unreadable prerequisites
11
11
  can block dependent checks; the reported failures are not an exhaustive list
@@ -16,9 +16,10 @@ Project configuration
16
16
  package.json is required at the Git root. Without peacekeeper.config.yaml,
17
17
  bundled defaults apply. An existing configuration must declare every schema
18
18
  field, including nested fields; unknown fields and invalid values fail.
19
- Run peacekeeper update-config to create or complete it without overwriting
20
- existing values. Review inserted defaults. Empty tests.commands blocks tests
21
- and receipts. Help, --explain and update-config bypass completeness checking.
19
+ Run peacekeeper project update-config to create or complete it without overwriting
20
+ existing values. Migrate tests.commands to tests.all and add tests.checkpoint
21
+ as an empty list. Review inserted defaults. Empty tests.all blocks tests
22
+ and receipts. Help, --explain and project update-config bypass completeness checking.
22
23
 
23
24
  projectChecks.testWorkflow selects the PR workflow filename.
24
25
  projectChecks.requiredJobs selects required job names.
@@ -42,7 +43,7 @@ Project configuration
42
43
 
43
44
  git.requiredApprover must identify the personal GitHub account that owns the
44
45
  repository. Its bundled default is null so migrations must choose explicitly.
45
- check-project requires .github/CODEOWNERS to contain exactly one non-comment
46
+ project check requires .github/CODEOWNERS to contain exactly one non-comment
46
47
  rule matching that account:
47
48
  * @OWNER
48
49
  Additional ownership patterns or owners are rejected because GitHub accepts
@@ -102,7 +103,7 @@ Codex lifecycle hooks
102
103
  .codex/hooks.json must contain the current peacekeeper hooks exactly once
103
104
  for each lifecycle event, in their expected order, without group conditions.
104
105
  Unrelated hooks are allowed. Repair with:
105
- peacekeeper install-hooks
106
+ peacekeeper codex install-hooks
106
107
  Hook installation does not itself grant Codex trust.
107
108
 
108
109
  All GitHub Actions workflows
@@ -172,7 +173,7 @@ Required PR workflow and jobs
172
173
  GitHub check contexts and branch protection still need online verification.
173
174
 
174
175
  If any matrix leg fails or is cancelled, the dependent test gate is normally
175
- skipped, not failed. verify-release requires each configured release job to
176
+ skipped, not failed. release verify requires each configured release job to
176
177
  conclude success, so a skipped gate blocks publication (even if the overall
177
178
  workflow conclusion were success).
178
179
 
@@ -185,7 +186,7 @@ Required PR workflow and jobs
185
186
  names in that setting. Alternatively, use separate static required jobs for
186
187
  each platform and list all of them in git.releaseRequiredChecks. A gate using
187
188
  always() to fail explicitly on failed dependencies is not currently accepted
188
- by check-project's required-job condition rules.
189
+ by project check's required-job condition rules.
189
190
 
190
191
  Publication: publishesToNpm=true
191
192
  package.json version must be exact and stable (no prerelease). Commit a
@@ -199,13 +200,13 @@ Publication: publishesToNpm=true
199
200
  if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
200
201
  The publish job must not allow failure.
201
202
 
202
- In publish steps, run unconditional npm ci, then unconditional verify-release,
203
+ In publish steps, run unconditional npm ci, then unconditional release verify,
203
204
  then npm publish. Neither install nor verification may allow failure.
204
205
  Accepted direct verification commands:
205
- peacekeeper verify-release
206
- npm exec --no -- peacekeeper verify-release
207
- node dist/bin/peacekeeper.js verify-release
208
- node node_modules/@jakobm/peacekeeper/dist/bin/peacekeeper.js verify-release
206
+ peacekeeper release verify
207
+ npm exec --no -- peacekeeper release verify
208
+ node dist/bin/peacekeeper.js release verify
209
+ node node_modules/@jakobm/peacekeeper/dist/bin/peacekeeper.js release verify
209
210
  The node paths may also start with ./.
210
211
 
211
212
  Verification must receive these environment inputs, directly on the step or
@@ -218,9 +219,9 @@ Publication: publishesToNpm=true
218
219
  contents: write is also accepted. The same toolchain rules apply to publishing.
219
220
 
220
221
  Publication intent comes only from the mandatory boolean publishesToNpm.
221
- Its bundled default is false. update-config inserts false even if existing
222
+ Its bundled default is false. project update-config inserts false even if existing
222
223
  package metadata looks publishable; explicitly select true when migrating.
223
- A missing field in an existing configuration fails check-project.
224
+ A missing field in an existing configuration fails project check.
224
225
 
225
226
  With true, package.json private must be absent or false. Require a valid npm
226
227
  name, nonblank description and license, nonempty files list, and publishConfig
@@ -228,8 +229,8 @@ Publication: publishesToNpm=true
228
229
  scripts.prerelease must be exactly npm ci. npm runs it before scripts.release,
229
230
  so release starts with the dependency versions committed in the lockfile even
230
231
  when node_modules was installed before the latest pull. scripts.release must
231
- directly invoke peacekeeper release (also supported: npm exec --no --
232
- peacekeeper release or the local Node CLI forms). Run releases through
232
+ directly invoke peacekeeper release publish (also supported: npm exec --no --
233
+ peacekeeper release publish or the local Node CLI forms). Run releases through
233
234
  npm run release so npm does not bypass the prerelease installation.
234
235
  The selected PR workflow must declare an unconditional packaging check after
235
236
  npm ci: npm pack (optionally
@@ -241,19 +242,19 @@ Publication: publishesToNpm=true
241
242
  authentication needed by private dependencies to the npm ci step.
242
243
 
243
244
  With false, require private: true and reject publishConfig, files, npm
244
- publication/release scripts, verify-release steps and npm-publish actions.
245
+ publication/release scripts, release verify steps and npm-publish actions.
245
246
  Scan command lists and npm script aliases; arbitrary shell wrappers, reusable
246
247
  workflows and external scripts cannot be fully inspected. Remove dedicated
247
248
  publishing credentials and npm trusted-publisher registration separately.
248
249
  Internal packing, prepack/build scripts, main/exports/types/bin, deployment
249
250
  workflows, OIDC for other services, and dependency read authentication remain
250
251
  allowed. Workflow filenames and job names alone do not imply npm publication.
251
- Toolchain, hooks, PR checks and verify-release-protection still apply.
252
+ Toolchain, hooks, PR checks and release verify-protection still apply.
252
253
 
253
254
  Online release policy and GitHub token setup
254
- These are online installation requirements; check-project only verifies the
255
- local declarations above. Use verify-release-protection to check the branch
256
- policy and verify-release before publishing to check the release itself.
255
+ These are online installation requirements; project check only verifies the
256
+ local declarations above. Use release verify-protection to check the branch
257
+ policy and release verify before publishing to check the release itself.
257
258
 
258
259
  Enable "Automatically delete head branches" (delete_branch_on_merge=true) in
259
260
  the repository settings. The online release policy commands require it.
@@ -298,8 +299,8 @@ Online release policy and GitHub token setup
298
299
  Fork PRs do not receive repository secrets; do not expose this token by
299
300
  running fork code with pull_request_target.
300
301
 
301
- verify-release-protection uses GITHUB_BASE_REF, or git.defaultBranch outside
302
- PR CI. It can be run before tests in a required trusted PR job. verify-release
302
+ release verify-protection uses GITHUB_BASE_REF, or git.defaultBranch outside
303
+ PR CI. It can be run before tests in a required trusted PR job. release verify
303
304
  checks matching package/tag/lockfile versions, that the tagged commit belongs
304
305
  to the default branch and is the merge commit of a same-repository merged
305
306
  release/v<version> PR, and the latest selected PR workflow run and required
@@ -361,7 +362,7 @@ Complete npm trusted-publishing example with Volta
361
362
  env:
362
363
  GH_TOKEN: ${{ secrets.RELEASE_POLICY_TOKEN }}
363
364
  RELEASE_TAG: ${{ github.ref_name }}
364
- run: npm exec --no -- peacekeeper verify-release
365
+ run: npm exec --no -- peacekeeper release verify
365
366
  - run: npm publish
366
367
 
367
368
  Volta selects the pinned tools and its registry-url input configures npm's
@@ -375,7 +376,7 @@ Complete npm trusted-publishing example with Volta
375
376
  publishing does not authenticate dependency installation. Add any necessary
376
377
  build step before publication, keeping npm publish as its own direct step.
377
378
 
378
- check-project verifies supported local workflow structure, not the npm OIDC
379
+ project check verifies supported local workflow structure, not the npm OIDC
379
380
  minimum versions, trusted-publisher registration, package visibility, registry
380
381
  credentials, or actual publishing access. Verify those external settings too.
381
382
  Upstream references for provider-specific setup and changing prerequisites:
@@ -389,19 +390,19 @@ What a passing check does and does not establish
389
390
  installed dependency versions, or check Git remotes and ignored files.
390
391
  It cannot confirm actual GitHub branch protection, token/secret access,
391
392
  successful workflow runs, or npm trusted publisher configuration. Those need
392
- online verification; verify-release handles the release checks it supports.
393
+ online verification; release verify handles the release checks it supports.
393
394
 
394
395
  Using this check in the test chain
395
- run-tests always runs check-project as an implicit first step before
396
- tests.commands, including when a valid receipt skips the configured commands.
397
- Explicit check-project invocations in tests.commands are rejected as redundant
396
+ test run always runs project check as an implicit first step before
397
+ tests.all or tests.checkpoint, including when command receipts skip execution.
398
+ Explicit project check invocations in either test list are rejected as redundant
398
399
  because the runner always includes this step automatically. Supported direct
399
400
  peacekeeper, npm exec, npx and node CLI forms are checked, including commands
400
401
  separated by shell control operators. Failure stops the run and invalidates any
401
402
  existing receipt. This check remains entirely local.
402
403
 
403
404
  Default-branch GitHub policy chain
404
- The configured PR workflow must run verify-release-protection with step GH_TOKEN
405
+ The configured PR workflow must run release verify-protection with step GH_TOKEN
405
406
  after npm ci and before tests in at least one job in git.releaseRequiredChecks.
406
407
  Verification must be unconditional and must not allow failure. The existing
407
408
  required-job validation applies to that job and its dependencies.
@@ -18,7 +18,7 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
18
18
  }
19
19
  const testCommand = /^npm (?:test|run test(?::[\w-]+)?|pack --dry-run(?: --json)?)$/u;
20
20
  const installCommand = /^npm ci$/u;
21
- const verifyCommand = /^(?:peacekeeper|npm exec --no -- peacekeeper|node (?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?(?:dist\/)?bin\/peacekeeper\.js) verify-release$/u;
21
+ const verifyCommand = /^(?:peacekeeper|npm exec --no -- peacekeeper|node (?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?(?:dist\/)?bin\/peacekeeper\.js) (?:release verify|verify-release)$/u;
22
22
  function checkProject(cwd = runtime.cwd()) {
23
23
  const config = projectConfig(cwd);
24
24
  const root = config.root;
@@ -44,9 +44,11 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
44
44
  }
45
45
  };
46
46
  check('tests', () => {
47
- const projectCheck = /(?:^|&&|\|\||;|\n)\s*(?:peacekeeper|npm\s+exec\s+--no\s+--\s+peacekeeper|npx\s+--no-install\s+peacekeeper|node\s+(?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?bin\/peacekeeper\.js)\s+check-project(?=\s|$|;|&|\|)/u;
48
- for (const [index, command] of config.tests.commands.entries()) {
49
- requireThat(!projectCheck.test(command), `tests.commands[${index}]: remove check-project; it is redundant because Peacekeeper always includes it automatically before the configured test commands, even when reusing a test receipt.`);
47
+ const projectCheck = /(?:^|&&|\|\||;|\n)\s*(?:peacekeeper|npm\s+exec\s+--no\s+--\s+peacekeeper|npx\s+--no-install\s+peacekeeper|node\s+(?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?(?:dist\/)?bin\/peacekeeper\.js)\s+(?:project\s+check|check-project)(?=\s|$|;|&|\|)/u;
48
+ for (const level of ['all', 'checkpoint']) {
49
+ for (const [index, command] of config.tests[level].entries()) {
50
+ requireThat(!projectCheck.test(command), `tests.${level}[${index}]: remove project check; it is redundant because Peacekeeper always includes it automatically before the configured test commands, even when reusing a test receipt.`);
51
+ }
50
52
  }
51
53
  });
52
54
  check('package', () => {
@@ -60,10 +62,8 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
60
62
  if (typeof approver !== 'string')
61
63
  return;
62
64
  const file = '.github/CODEOWNERS';
63
- const lines = read(root, file, value => value.split(/\r?\n/u))
64
- .map(line => line.trim())
65
- .filter(line => line && !line.startsWith('#'));
66
- requireThat(isDeepStrictEqual(lines, [`* @${approver}`]), `${file}: use exactly one ownership rule, "* @${approver}", so only git.requiredApprover can satisfy required code-owner review.`);
65
+ const error = configuration.codeownersError(read(root, file, value => value), approver);
66
+ requireThat(!error, error || '');
67
67
  });
68
68
  const workflows = new Map();
69
69
  check('CI', () => {
@@ -170,14 +170,14 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
170
170
  requireThat(Object.keys(group).every(key => key === 'hooks'), '.codex/hooks.json: peacekeeper lifecycle hooks must not have group conditions.');
171
171
  return handlers;
172
172
  });
173
- requireThat(isDeepStrictEqual(owned(document.hooks?.[event] || []), owned(expected.hooks[event] || [])), `.codex/hooks.json: missing, duplicate or outdated ${event} lifecycle hooks; run peacekeeper install-hooks.`);
173
+ requireThat(isDeepStrictEqual(owned(document.hooks?.[event] || []), owned(expected.hooks[event] || [])), `.codex/hooks.json: missing, duplicate or outdated ${event} lifecycle hooks; run peacekeeper codex install-hooks.`);
174
174
  }
175
175
  });
176
176
  const published = config.publishesToNpm;
177
177
  check('publication', () => {
178
178
  const nonblank = value => typeof value === 'string' && value.trim().length > 0;
179
179
  const scripts = manifest.scripts || {};
180
- const releaseCommand = /^(?:peacekeeper|npm exec --no -- peacekeeper|node (?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?(?:dist\/)?bin\/peacekeeper\.js) release$/u;
180
+ const releaseCommand = /^(?:peacekeeper|npm exec --no -- peacekeeper|node (?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?(?:dist\/)?bin\/peacekeeper\.js) release(?: publish)?$/u;
181
181
  // Resolve npm script aliases without executing project code. Cycles stop here.
182
182
  function commands(command, seen = new Set()) {
183
183
  if (typeof command !== 'string')
@@ -201,7 +201,7 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
201
201
  && ['public', 'restricted'].includes(manifest.publishConfig?.access), 'package.json: publishConfig must declare registry https://registry.npmjs.org/ and access public or restricted.');
202
202
  requireThat(Array.isArray(manifest.files) && manifest.files.length > 0 && manifest.files.every(nonblank), 'package.json: published packages require a nonempty files list.');
203
203
  requireThat(typeof scripts.prerelease === 'string' && scripts.prerelease.trim() === 'npm ci', 'package.json: scripts.prerelease must be exactly npm ci so release uses the locked dependencies.');
204
- requireThat(typeof scripts.release === 'string' && releaseCommand.test(scripts.release.trim()), 'package.json: scripts.release must invoke peacekeeper release directly.');
204
+ requireThat(typeof scripts.release === 'string' && releaseCommand.test(scripts.release.trim()), 'package.json: scripts.release must invoke peacekeeper release publish directly.');
205
205
  const testWorkflow = workflows.get(config.projectChecks.testWorkflow);
206
206
  requireThat(testWorkflow && Object.values(testWorkflow.jobs).some((rawJob) => {
207
207
  const job = rawJob;
@@ -262,7 +262,7 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
262
262
  const steps = job.steps || [];
263
263
  const installed = steps.findIndex(step => directCommand(step, installCommand) && unconditional(step.if) && !step['continue-on-error']);
264
264
  const tested = steps.findIndex(step => directCommand(step, testCommand) && unconditional(step.if) && !step['continue-on-error']);
265
- const policy = steps.findIndex(step => directCommand(step, /^(?:peacekeeper|npm exec --no -- peacekeeper|node (?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?(?:dist\/)?bin\/peacekeeper\.js) verify-release-protection$/u)
265
+ const policy = steps.findIndex(step => directCommand(step, /^(?:peacekeeper|npm exec --no -- peacekeeper|node (?:\.\/)?(?:node_modules\/@jakobm\/peacekeeper\/)?(?:dist\/)?bin\/peacekeeper\.js) (?:release verify-protection|verify-release-protection)$/u)
266
266
  && unconditional(step.if) && !step['continue-on-error'] && step.env?.GH_TOKEN);
267
267
  if (policy > installed && installed >= 0 && policy < tested && config.git.releaseRequiredChecks.includes(job.name || id))
268
268
  policyJobs += 1;
@@ -277,7 +277,7 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
277
277
  checked.clear();
278
278
  requiredJob(...matching[0], true);
279
279
  }
280
- requireThat(policyJobs > 0, `${filename}: a job in git.releaseRequiredChecks must run unconditional verify-release-protection with GH_TOKEN after npm ci and before tests.`);
280
+ requireThat(policyJobs > 0, `${filename}: a job in git.releaseRequiredChecks must run unconditional release verify-protection with GH_TOKEN after npm ci and before tests.`);
281
281
  });
282
282
  if (published)
283
283
  check('publication', () => {
@@ -306,9 +306,9 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
306
306
  requireThat(publish >= 0 && unconditional(steps[publish].if) && !steps[publish]['continue-on-error'], `${publishing.path}: npm publish must be unconditional and must not allow failure.`);
307
307
  const publishEnvironment = { ...workflow.env, ...job.env, ...steps[publish]?.env };
308
308
  requireThat(!['NPM_TOKEN', 'NODE_AUTH_TOKEN'].some(key => Object.hasOwn(publishEnvironment, key)), `${publishing.path}: remove npm publishing tokens from the publish step; use OIDC. Scope private dependency read authentication to npm ci.`);
309
- requireThat(installed >= 0 && verify > installed && verify < publish && unconditional(steps[verify].if) && !steps[verify]['continue-on-error'], `${publishing.path}: run verify-release unconditionally before npm publish.`);
309
+ requireThat(installed >= 0 && verify > installed && verify < publish && unconditional(steps[verify].if) && !steps[verify]['continue-on-error'], `${publishing.path}: run release verify unconditionally before npm publish.`);
310
310
  const environment = { ...workflow.env, ...job.env, ...steps[verify]?.env };
311
- requireThat(environment.RELEASE_TAG === '${{ github.ref_name }}' && environment.GH_TOKEN, `${publishing.path}: verify-release needs RELEASE_TAG from github.ref_name and GH_TOKEN.`);
311
+ requireThat(environment.RELEASE_TAG === '${{ github.ref_name }}' && environment.GH_TOKEN, `${publishing.path}: release verify needs RELEASE_TAG from github.ref_name and GH_TOKEN.`);
312
312
  const permissions = job.permissions || workflow.permissions;
313
313
  requireThat(permissions && permissions['id-token'] === 'write' && ['read', 'write'].includes(permissions.contents), `${publishing.path}: declare contents: read and id-token: write for publishing.`);
314
314
  const selected = config.git.releaseTestWorkflow;
@@ -321,7 +321,7 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
321
321
  runtime.stdout.write(fs.readFileSync(path.join(modulesRoot, 'projects/check-project-requirements.txt'), 'utf8'));
322
322
  return;
323
323
  }
324
- output.log('Run peacekeeper check-project --explain for the complete expected project architecture and requirements.');
324
+ output.log('Run peacekeeper project check --explain for the complete expected project architecture and requirements.');
325
325
  const { errors, published } = checkProject();
326
326
  if (errors.length) {
327
327
  for (const error of errors)
@@ -19,7 +19,7 @@ npm --version
19
19
  npm ci
20
20
 
21
21
  # Initialize the linked worktree and safely synchronize the primary checkout.
22
- npm exec --no -- peacekeeper initialize-codex-worktree --sync-primary
23
- npm exec --no -- peacekeeper cleanup-merged-branches --execute
22
+ npm exec --no -- peacekeeper codex init-worktree --sync-primary
23
+ npm exec --no -- peacekeeper cleanup merged-branches --execute
24
24
 
25
25
  # Add custom project setup below
@@ -1,6 +1,5 @@
1
- export default ({ installHooks, releases, external: { fs, modulesRoot, packageVersion, path, projectConfigDefaults, runtime, spawnSync, url: Url, YAML, } }) => {
1
+ export default ({ installHooks, external: { fs, modulesRoot, packageVersion, path, projectConfigDefaults, runtime, spawnSync, url: Url, YAML, } }) => {
2
2
  const { planHooks } = installHooks;
3
- const { createGithubPolicy, githubSetupPlan } = releases;
4
3
  const TOOLCHAIN = Object.freeze({
5
4
  node: '22.14.0',
6
5
  npm: '11.21.0',
@@ -64,10 +63,10 @@ export default ({ installHooks, releases, external: { fs, modulesRoot, packageVe
64
63
  fs.writeFileSync(target, contents, { mode });
65
64
  }
66
65
  function workflow(published) {
67
- return `name: Test\n\non:\n pull_request:\n branches: [main]\n\npermissions:\n contents: read\n\njobs:\n test:\n runs-on: ubuntu-24.04\n steps:\n - uses: actions/checkout@v7\n - uses: volta-cli/action@v5\n - run: npm ci\n - name: Verify strict release policy\n env:\n GH_TOKEN: \${{ secrets.RELEASE_POLICY_TOKEN }}\n run: npm exec --no -- peacekeeper verify-release-protection\n - run: npm test\n${published ? `\n package:\n name: Test package\n runs-on: ubuntu-24.04\n steps:\n - uses: actions/checkout@v7\n - uses: volta-cli/action@v5\n - run: npm ci\n - run: npm run test:package\n` : ''}`;
66
+ return `name: Test\n\non:\n pull_request:\n branches: [main]\n\npermissions:\n contents: read\n\njobs:\n test:\n runs-on: ubuntu-24.04\n steps:\n - uses: actions/checkout@v7\n - uses: volta-cli/action@v5\n - run: npm ci\n - name: Verify strict release policy\n env:\n GH_TOKEN: \${{ secrets.RELEASE_POLICY_TOKEN }}\n run: npm exec --no -- peacekeeper release verify-protection\n - run: npm test\n${published ? `\n package:\n name: Test package\n runs-on: ubuntu-24.04\n steps:\n - uses: actions/checkout@v7\n - uses: volta-cli/action@v5\n - run: npm ci\n - run: npm run test:package\n` : ''}`;
68
67
  }
69
68
  function publishWorkflow() {
70
- return `name: Publish\n\non:\n push:\n tags: ['v*']\n\npermissions:\n contents: read\n\njobs:\n publish:\n name: Publish to npm\n runs-on: ubuntu-24.04\n permissions:\n contents: read\n actions: read\n pull-requests: read\n id-token: write\n steps:\n - uses: actions/checkout@v7\n - uses: volta-cli/action@v5\n with:\n registry-url: https://registry.npmjs.org\n - run: npm ci\n - name: Verify release\n env:\n GH_TOKEN: \${{ secrets.RELEASE_POLICY_TOKEN }}\n RELEASE_TAG: \${{ github.ref_name }}\n run: npm exec --no -- peacekeeper verify-release\n - run: npm publish\n`;
69
+ return `name: Publish\n\non:\n push:\n tags: ['v*']\n\npermissions:\n contents: read\n\njobs:\n publish:\n name: Publish to npm\n runs-on: ubuntu-24.04\n permissions:\n contents: read\n actions: read\n pull-requests: read\n id-token: write\n steps:\n - uses: actions/checkout@v7\n - uses: volta-cli/action@v5\n with:\n registry-url: https://registry.npmjs.org\n - run: npm ci\n - name: Verify release\n env:\n GH_TOKEN: \${{ secrets.RELEASE_POLICY_TOKEN }}\n RELEASE_TAG: \${{ github.ref_name }}\n run: npm exec --no -- peacekeeper release verify\n - run: npm publish\n`;
71
70
  }
72
71
  function renderTemplate(filename, replacements) {
73
72
  let template = fs.readFileSync(path.join(modulesRoot, `projects/${filename}`), 'utf8');
@@ -81,27 +80,13 @@ export default ({ installHooks, releases, external: { fs, modulesRoot, packageVe
81
80
  return template.trim();
82
81
  }
83
82
  function githubSetup(repositories) {
84
- const prefix = renderTemplate('github-setup-prefix.sh', {});
85
- const configured = repositories.map(({ owner, repositoryName, requiredChecks, requiredApprover = owner, defaultBranch = 'main' }) => {
86
- let plan;
87
- try {
88
- plan = githubSetupPlan(createGithubPolicy({ branch: defaultBranch,
89
- checks: requiredChecks, requiredApprover }));
90
- }
91
- catch (error) {
92
- throw new Error(`GitHub setup for ${owner}/${repositoryName}: ${error instanceof Error ? error.message : String(error)}`);
93
- }
94
- return renderTemplate('github-setup-repository-template.sh', {
95
- OWNER: shellSingleQuotedContent(owner),
96
- REPOSITORY_NAME: shellSingleQuotedContent(repositoryName),
97
- DEFAULT_BRANCH: shellSingleQuotedContent(plan.branchPath),
98
- REPOSITORY_PATCH_ARGUMENTS: plan.repositoryPatchArguments,
99
- BASE_RULESET: plan.baseRuleset,
100
- APPROVAL_RULESET: plan.approvalRuleset,
101
- REQUIRED_APPROVER: shellSingleQuotedContent(requiredApprover),
102
- REQUIRED_APPROVER_LOWER: shellSingleQuotedContent(requiredApprover.toLowerCase()),
103
- });
104
- });
83
+ const prefix = renderTemplate('github-setup-prefix.sh', { VERSION: shellSingleQuotedContent(packageVersion) });
84
+ const configured = repositories.map(({ owner, repositoryName, policyPr, sourceRef }) => renderTemplate('github-setup-repository-template.sh', {
85
+ REPOSITORY: shellSingleQuotedContent(`${owner}/${repositoryName}`),
86
+ PLAN_NAME: shellSingleQuotedContent(`${owner}--${repositoryName}.json`),
87
+ POLICY_PR: shellSingleQuotedContent(policyPr === undefined ? '' : String(policyPr)),
88
+ SOURCE_REF: shellSingleQuotedContent(sourceRef || ''),
89
+ }));
105
90
  const argumentsValue = repositories
106
91
  .map(({ owner, repositoryName }) => `--new-repo ${shellLiteral(`${owner}/${repositoryName}`)}`)
107
92
  .join(' ');
@@ -126,8 +111,8 @@ export default ({ installHooks, releases, external: { fs, modulesRoot, packageVe
126
111
  repository: { type: 'git', url: `git+${options.repository}` }, license: 'MIT',
127
112
  engines: { node: '>=20' }, volta: { node: TOOLCHAIN.node, npm: TOOLCHAIN.npm },
128
113
  main: './dist/index.js', types: './dist/index.d.ts', exports: { '.': { types: './dist/index.d.ts', import: './dist/index.js' } },
129
- scripts: { build: 'tsc -p tsconfig.json', prepare: 'npm run build', typecheck: 'tsc -p tsconfig.json --noEmit', test: 'peacekeeper run-tests', 'test:unit': 'node --test test/*.test.js',
130
- ...(options.published ? { 'test:package': 'node scripts/test-package.cjs', prerelease: 'npm ci', release: 'peacekeeper release' } : {}) },
114
+ scripts: { build: 'tsc -p tsconfig.json', prepare: 'npm run build', typecheck: 'tsc -p tsconfig.json --noEmit', test: 'peacekeeper test run', 'test:unit': 'node --test test/*.test.js',
115
+ ...(options.published ? { 'test:package': 'node scripts/test-package.cjs', prerelease: 'npm ci', release: 'peacekeeper release publish' } : {}) },
131
116
  devDependencies: { '@jakobm/peacekeeper': version, '@types/node': TOOLCHAIN.nodeTypes, typescript: TOOLCHAIN.typescript },
132
117
  ...(options.published ? { files: ['dist/'], publishConfig: { access: 'public', registry: 'https://registry.npmjs.org/' } } : {}),
133
118
  };
@@ -140,7 +125,7 @@ export default ({ installHooks, releases, external: { fs, modulesRoot, packageVe
140
125
  const defaults = JSON.parse(JSON.stringify(projectConfigDefaults));
141
126
  defaults.publishesToNpm = options.published;
142
127
  defaults.git.requiredApprover = options.owner;
143
- defaults.tests.commands = ['npm run typecheck', 'npm run build', 'npm run test:unit', ...(options.published ? ['npm run test:package'] : [])];
128
+ defaults.tests.all = ['npm run typecheck', 'npm run build', 'npm run test:unit', ...(options.published ? ['npm run test:package'] : [])];
144
129
  defaults.tests.npmTestUsesRunner = true;
145
130
  write(root, 'peacekeeper.config.yaml', YAML.stringify(defaults, { lineWidth: 0 }));
146
131
  write(root, '.codex/hooks.json', json(planHooks({}).document));