@jakobm/peacekeeper 0.22.0 → 0.23.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 CHANGED
@@ -86,7 +86,7 @@ peacekeeper generate-github-setup \
86
86
 
87
87
  Repeat `--repository` to configure any number of repositories in one script.
88
88
  At generation time the command reads and validates each repository's
89
- `peacekeeper.config.json` from its GitHub default branch, then embeds that
89
+ `peacekeeper.config.yaml` from its GitHub default branch, then embeds that
90
90
  repository's `git.releaseRequiredChecks` in the output. A repository without the
91
91
  file uses Peacekeeper's bundled defaults; an invalid file or unreadable repository
92
92
  stops generation. The command writes this configuration snapshot to stdout, so it
@@ -137,7 +137,7 @@ Include these entries in the caller's `package.json`, alongside its other script
137
137
 
138
138
  Run `npm install` from the project root and commit the resulting `package-lock.json`. npm adds `node_modules/.bin` to the `PATH` of package scripts, so package scripts can call `peacekeeper` by name.
139
139
 
140
- ### 2. `peacekeeper.config.json`
140
+ ### 2. `peacekeeper.config.yaml`
141
141
 
142
142
  Place this file at the caller's Git root. Every field, including nested fields,
143
143
  is required. Unknown fields and invalid values are rejected. If no file exists,
@@ -147,10 +147,14 @@ recording or reusing a test receipt.
147
147
 
148
148
  Run `peacekeeper update-config` to create the file or recursively fill missing
149
149
  fields from the defaults. Existing values, including empty arrays, are preserved.
150
- Review newly inserted values. Invalid JSON, unknown fields, or invalid existing
150
+ Comments in an existing YAML file are preserved. Review newly inserted values.
151
+ Invalid YAML, unknown fields, or invalid existing
151
152
  values cause failure without changing the file. Repeating the command on a
152
153
  complete valid file leaves it unchanged.
153
154
 
155
+ The former `peacekeeper.config.json` filename is not accepted. Rename and convert
156
+ it before upgrading so Peacekeeper cannot silently fall back to defaults.
157
+
154
158
  All CLI commands validate configuration before executing, except help,
155
159
  `check-project --explain`, and `update-config`. Checkpoint hooks instead validate
156
160
  the event worktree configuration when the event requires instructions or a check.
@@ -160,31 +164,31 @@ therefore require `peacekeeper update-config` before ordinary commands can run.
160
164
 
161
165
  Complete example:
162
166
 
163
- ```json
164
- {
165
- "publishesToNpm": false,
166
- "git": {
167
- "remote": "origin",
168
- "defaultBranch": "main",
169
- "branchPrefix": "codex/",
170
- "requiredApprover": "OWNER",
171
- "checkpointPushRemotes": ["origin"],
172
- "releaseMergeMethod": "merge",
173
- "releaseRequiredChecks": ["test"],
174
- "releaseTestWorkflow": "test.yml"
175
- },
176
- "tests": {
177
- "commands": ["eslint .", "node --test"],
178
- "receiptMaxAgeMinutes": 60,
179
- "npmTestUsesRunner": true
180
- },
181
- "loggingDirectory": "tmp/logs",
182
- "loggingEnabled": true,
183
- "projectChecks": {
184
- "testWorkflow": "test.yml",
185
- "requiredJobs": ["test"]
186
- }
187
- }
167
+ ```yaml
168
+ publishesToNpm: false
169
+ git:
170
+ remote: origin
171
+ defaultBranch: main
172
+ branchPrefix: codex/
173
+ requiredApprover: OWNER
174
+ checkpointPushRemotes:
175
+ - origin
176
+ releaseMergeMethod: merge
177
+ releaseRequiredChecks:
178
+ - test
179
+ releaseTestWorkflow: test.yml
180
+ tests:
181
+ commands:
182
+ - eslint .
183
+ - node --test
184
+ receiptMaxAgeMinutes: 60
185
+ npmTestUsesRunner: true
186
+ loggingDirectory: tmp/logs
187
+ loggingEnabled: true
188
+ projectChecks:
189
+ testWorkflow: test.yml
190
+ requiredJobs:
191
+ - test
188
192
  ```
189
193
 
190
194
  `git.remote` and `git.defaultBranch` identify the branch used for checkpointing and cleanup. `git.branchPrefix` names new task branches. `git.requiredApprover` names the personal GitHub repository owner who must approve other users' PRs and may bypass only the approval ruleset from a PR. Set it explicitly after `update-config`; its bundled default is `null`. The root project must contain `.github/CODEOWNERS` with the single non-comment rule `* @OWNER`, matching this value. `run-tests` always runs the local `check-project` validation first, even when reusing a test receipt. Explicit `check-project` invocations in `tests.commands` are rejected as redundant. The configured commands are complete shell commands, run in order from the caller's Git root; install any executables they use. The test runner stops on the first failure and records a receipt only after every command succeeds. `receiptMaxAgeMinutes` controls how long a receipt can be reused. Set `npmTestUsesRunner` to `true` only when the caller's `npm test` script invokes `peacekeeper run-tests`; this makes the rerun hint `npm test -- --force`. Otherwise the hint uses the explicit package path. `loggingDirectory` stores hook invocation logs relative to the primary Git worktree's root.
@@ -195,13 +199,13 @@ Checkpoint hook failures write the cause to stderr and exit with code 2 instead
195
199
 
196
200
  To publish checkpoint branches automatically, set `git.checkpointPushRemotes` (fragment):
197
201
 
198
- ```json
199
- {
200
- "remote": "origin",
201
- "defaultBranch": "main",
202
- "branchPrefix": "codex/",
203
- "checkpointPushRemotes": ["origin", "backup"]
204
- }
202
+ ```yaml
203
+ remote: origin
204
+ defaultBranch: main
205
+ branchPrefix: codex/
206
+ checkpointPushRemotes:
207
+ - origin
208
+ - backup
205
209
  ```
206
210
 
207
211
  Each name must identify a Git remote configured in the calling repository. Checkpoints push to exactly those remotes, creating the task branch if
@@ -333,7 +337,7 @@ test runner directly, avoiding recursion through `npm test`. The cleanup package
333
337
  scripts work the same way as in calling projects.
334
338
 
335
339
  When first adopting these hooks, make sure the primary checkout also contains
336
- `peacekeeper.config.json` before trusting them with `/hooks`: invocation logs
340
+ `peacekeeper.config.yaml` before trusting them with `/hooks`: invocation logs
337
341
  are stored there and session cleanup reads that checkout's configuration.
338
342
  The hook definitions can then be reviewed and trusted in Codex; committing them
339
343
  does not grant trust automatically.
@@ -342,7 +346,7 @@ does not grant trust automatically.
342
346
 
343
347
  Run `peacekeeper check-project` to check the local project configuration.
344
348
 
345
- Declare the mandatory boolean `publishesToNpm` in `peacekeeper.config.json`.
349
+ Declare the mandatory boolean `publishesToNpm` in `peacekeeper.config.yaml`.
346
350
  Its default is `false`; `update-config` inserts `false` without inferring intent
347
351
  from package metadata. Set it to `true` for packages published to npm (including
348
352
  restricted scoped packages). Peacekeeper itself sets it to `true`.
@@ -490,7 +494,7 @@ another run.
490
494
 
491
495
  Release verification uses GitHub's enforced branch policy instead of retaining
492
496
  artifacts of tested contents. Configure `git.releaseRequiredChecks` in the root
493
- `peacekeeper.config.json` with the exact CI job names required for a release
497
+ `peacekeeper.config.yaml` with the exact CI job names required for a release
494
498
  (for this repository: `["test", "Test package"]`). These checks must be mandatory
495
499
  with **Require branches to be up to date before merging** enabled. Classic branch
496
500
  protection may provide the base PR and check requirements. Active base rulesets
@@ -654,7 +658,7 @@ that needs manual cleanup.
654
658
 
655
659
  Other npm projects can use this command through a package script such as
656
660
  `"release": "peacekeeper release"`. The project must use a root package
657
- with a stable version, a `peacekeeper.config.json` with
661
+ with a stable version, a `peacekeeper.config.yaml` with
658
662
  `git.releaseRequiredChecks`, and the supported tag-triggered GitHub Actions
659
663
  publish job. Add `peacekeeper verify-release-protection` to a required PR
660
664
  test job and `peacekeeper verify-release` before publishing, with `GH_TOKEN`
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jakobm/peacekeeper",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "Shared repository test, Git worktree, and Codex hook commands",
5
5
  "license": "MIT",
6
6
  "author": "Jakob Mattsson",
@@ -2,6 +2,7 @@ import { execFileSync, spawn, spawnSync } from 'node:child_process';
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
+ import YAML from 'yaml';
5
6
  import projectConfigDefaults from './modules/configuration/project-config-defaults.json' with { type: 'json' };
6
7
  import createProjectConfig from './modules/configuration/project-config.js';
7
8
  import createLifecycle from './modules/lifecycle/interface.js';
@@ -28,7 +29,7 @@ const output = console;
28
29
  function dependencyFreeLifecycleContainer() {
29
30
  const runtime = process;
30
31
  const projectConfig = createProjectConfig({
31
- external: { execFileSync, fs, path, projectConfigDefaults, runtime },
32
+ external: { execFileSync, fs, path, projectConfigDefaults, runtime, YAML },
32
33
  });
33
34
  const configuration = Object.freeze({
34
35
  projectConfig: projectConfig.projectConfig,
@@ -1,5 +1,6 @@
1
- export default ({ external: { execFileSync, fs, path, projectConfigDefaults, runtime, } }) => {
2
- const CONFIG_FILE = 'peacekeeper.config.json';
1
+ export default ({ external: { execFileSync, fs, path, projectConfigDefaults, runtime, YAML, } }) => {
2
+ const CONFIG_FILE = 'peacekeeper.config.yaml';
3
+ const LEGACY_CONFIG_FILE = 'peacekeeper.config.json';
3
4
  function repositoryRoot(cwd = runtime.cwd()) {
4
5
  return execFileSync('git', ['rev-parse', '--show-toplevel'], {
5
6
  cwd,
@@ -98,8 +99,12 @@ export default ({ external: { execFileSync, fs, path, projectConfigDefaults, run
98
99
  function projectConfig(cwd = runtime.cwd()) {
99
100
  const root = repositoryRoot(cwd);
100
101
  const file = path.join(root, CONFIG_FILE);
102
+ const legacyFile = path.join(root, LEGACY_CONFIG_FILE);
103
+ if (!fs.existsSync(file) && fs.existsSync(legacyFile)) {
104
+ throw new Error(`${legacyFile}: rename this legacy JSON configuration to ${CONFIG_FILE} and convert it to YAML.`);
105
+ }
101
106
  const config = fs.existsSync(file)
102
- ? JSON.parse(fs.readFileSync(file, 'utf8'))
107
+ ? YAML.parse(fs.readFileSync(file, 'utf8'))
103
108
  : JSON.parse(JSON.stringify(projectConfigDefaults));
104
109
  validateConfig(config, file);
105
110
  return { root, ...config };
@@ -109,6 +114,6 @@ export default ({ external: { execFileSync, fs, path, projectConfigDefaults, run
109
114
  throw new Error('Configure tests.commands before running tests or using a test receipt.');
110
115
  }
111
116
  }
112
- const api = { CONFIG_FILE, CONFIG_SCHEMA, validateConfig, projectConfig, repositoryRoot, requireTestCommands };
117
+ const api = { CONFIG_FILE, LEGACY_CONFIG_FILE, CONFIG_SCHEMA, validateConfig, projectConfig, repositoryRoot, requireTestCommands };
113
118
  return api;
114
119
  };
@@ -1,5 +1,5 @@
1
- export default ({ projectConfig, external: { fs, isDeepStrictEqual, output, path, projectConfigDefaults, runtime, } }) => {
2
- const { CONFIG_FILE, repositoryRoot, validateConfig } = projectConfig;
1
+ export default ({ projectConfig, external: { fs, isDeepStrictEqual, output, path, projectConfigDefaults, runtime, YAML, } }) => {
2
+ const { CONFIG_FILE, LEGACY_CONFIG_FILE, repositoryRoot, validateConfig } = projectConfig;
3
3
  function complete(value, defaults) {
4
4
  if (value === null || typeof value !== 'object' || Array.isArray(value))
5
5
  return value;
@@ -13,16 +13,35 @@ export default ({ projectConfig, external: { fs, isDeepStrictEqual, output, path
13
13
  }
14
14
  return result;
15
15
  }
16
+ function addMissing(document, value, defaults, keys = []) {
17
+ for (const [key, fallback] of Object.entries(defaults)) {
18
+ const childKeys = [...keys, key];
19
+ if (!Object.hasOwn(value, key))
20
+ document.setIn(childKeys, JSON.parse(JSON.stringify(fallback)));
21
+ else if (fallback !== null && typeof fallback === 'object' && !Array.isArray(fallback)) {
22
+ addMissing(document, value[key], fallback, childKeys);
23
+ }
24
+ }
25
+ }
16
26
  function updateConfig(cwd = runtime.cwd()) {
17
- const file = path.join(repositoryRoot(cwd), CONFIG_FILE);
27
+ const root = repositoryRoot(cwd);
28
+ const file = path.join(root, CONFIG_FILE);
29
+ const legacyFile = path.join(root, LEGACY_CONFIG_FILE);
30
+ if (!fs.existsSync(file) && fs.existsSync(legacyFile)) {
31
+ throw new Error(`${legacyFile}: rename this legacy JSON configuration to ${CONFIG_FILE} and convert it to YAML.`);
32
+ }
18
33
  const defaults = projectConfigDefaults;
19
34
  validateConfig(defaults, 'bundled defaults');
20
35
  const exists = fs.existsSync(file);
21
- const original = exists ? JSON.parse(fs.readFileSync(file, 'utf8')) : {};
36
+ const document = exists ? YAML.parseDocument(fs.readFileSync(file, 'utf8')) : new YAML.Document({});
37
+ if (document.errors.length)
38
+ throw new Error(`${file}: ${document.errors.map(error => error.message).join('; ')}`);
39
+ const original = document.toJS();
22
40
  const updated = complete(original, defaults);
23
41
  validateConfig(updated, file);
24
42
  if (!exists || !isDeepStrictEqual(original, updated)) {
25
- fs.writeFileSync(file, `${JSON.stringify(updated, null, 2)}\n`);
43
+ addMissing(document, original, defaults);
44
+ fs.writeFileSync(file, document.toString({ lineWidth: 0 }));
26
45
  output.log(`Updated ${file}. Review defaults before using project commands.`);
27
46
  }
28
47
  else
@@ -8,7 +8,7 @@ allowed-modules:
8
8
  testing: [configuration, projects]
9
9
  allowed-external:
10
10
  cli: [cliConfigPath, runCli]
11
- configuration: [execFileSync, fs, isDeepStrictEqual, output, path, projectConfigDefaults, runtime]
11
+ configuration: [execFileSync, fs, isDeepStrictEqual, output, path, projectConfigDefaults, runtime, YAML]
12
12
  lifecycle: [buffer, clock, executablePath, fs, output, path, runtime, spawn, spawnSync]
13
13
  maintenance: [execFileSync, fs, output, path, runtime, spawnSync]
14
14
  projects: [buffer, fs, isDeepStrictEqual, modulesRoot, output, packageVersion, path, projectConfigDefaults, runtime, semver, spawnSync, TOML, url, YAML]
@@ -13,7 +13,7 @@ Purpose and scope
13
13
  --explain prints this entire document without loading or checking a project.
14
14
 
15
15
  Project configuration
16
- package.json is required at the Git root. Without peacekeeper.config.json,
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
19
  Run peacekeeper update-config to create or complete it without overwriting
@@ -56,7 +56,7 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
56
56
  });
57
57
  check('GitHub policy', () => {
58
58
  const approver = config.git.requiredApprover;
59
- requireThat(typeof approver === 'string', 'peacekeeper.config.json: set git.requiredApprover to the personal GitHub repository owner.');
59
+ requireThat(typeof approver === 'string', 'peacekeeper.config.yaml: set git.requiredApprover to the personal GitHub repository owner.');
60
60
  if (typeof approver !== 'string')
61
61
  return;
62
62
  const file = '.github/CODEOWNERS';
@@ -231,7 +231,7 @@ export default ({ configuration, installHooks, releases, external: { fs, isDeepS
231
231
  check('CI', () => {
232
232
  const workflow = workflows.get(filename);
233
233
  if (!workflow) {
234
- requireThat(false, `${filename}: configured PR workflow is missing (selected by projectChecks.testWorkflow). Set projectChecks.testWorkflow${published ? ' and git.releaseTestWorkflow to the same existing file' : ' to an existing file'} in peacekeeper.config.json. PR checks are blocked until it can be read.`);
234
+ requireThat(false, `${filename}: configured PR workflow is missing (selected by projectChecks.testWorkflow). Set projectChecks.testWorkflow${published ? ' and git.releaseTestWorkflow to the same existing file' : ' to an existing file'} in peacekeeper.config.yaml. PR checks are blocked until it can be read.`);
235
235
  return;
236
236
  }
237
237
  const jobs = workflow.jobs;
@@ -1,4 +1,4 @@
1
- export default ({ installHooks, releases, external: { fs, modulesRoot, packageVersion, path, projectConfigDefaults, runtime, spawnSync, url: Url, } }) => {
1
+ export default ({ installHooks, releases, external: { fs, modulesRoot, packageVersion, path, projectConfigDefaults, runtime, spawnSync, url: Url, YAML, } }) => {
2
2
  const { planHooks } = installHooks;
3
3
  const { createGithubPolicy, githubSetupPlan } = releases;
4
4
  const TOOLCHAIN = Object.freeze({
@@ -142,7 +142,7 @@ export default ({ installHooks, releases, external: { fs, modulesRoot, packageVe
142
142
  defaults.git.requiredApprover = options.owner;
143
143
  defaults.tests.commands = ['npm run typecheck', 'npm run build', 'npm run test:unit', ...(options.published ? ['npm run test:package'] : [])];
144
144
  defaults.tests.npmTestUsesRunner = true;
145
- write(root, 'peacekeeper.config.json', json(defaults));
145
+ write(root, 'peacekeeper.config.yaml', YAML.stringify(defaults, { lineWidth: 0 }));
146
146
  write(root, '.codex/hooks.json', json(planHooks({}).document));
147
147
  const prefix = fs.readFileSync(path.join(modulesRoot, 'projects/codex-setup-prefix.sh'), 'utf8');
148
148
  write(root, '.codex/environments/environment.toml', `version = 1\nname = ${JSON.stringify(options.repositoryName)}\n\n[setup]\nscript = '''\n${prefix}'''\n`);
@@ -1,4 +1,4 @@
1
- export default ({ configuration, createProjectCore, external: { buffer: Buffer, projectConfigDefaults, runtime, spawnSync, } }) => {
1
+ export default ({ configuration, createProjectCore, external: { buffer: Buffer, projectConfigDefaults, runtime, spawnSync, YAML, } }) => {
2
2
  const { validateConfig } = configuration;
3
3
  const { githubSetup, repositoryIdentity } = createProjectCore;
4
4
  function api(endpoint, missingAllowed = false) {
@@ -25,24 +25,28 @@ export default ({ configuration, createProjectCore, external: { buffer: Buffer,
25
25
  if (typeof metadata?.default_branch !== 'string' || !metadata.default_branch) {
26
26
  throw new Error(`GitHub did not return a default branch for ${slug}.`);
27
27
  }
28
- const endpoint = `repos/${slug}/contents/peacekeeper.config.json?ref=${encodeURIComponent(metadata.default_branch)}`;
28
+ const endpoint = `repos/${slug}/contents/peacekeeper.config.yaml?ref=${encodeURIComponent(metadata.default_branch)}`;
29
29
  const file = api(endpoint, true);
30
30
  let config;
31
31
  if (file === undefined) {
32
+ const legacyEndpoint = `repos/${slug}/contents/peacekeeper.config.json?ref=${encodeURIComponent(metadata.default_branch)}`;
33
+ if (api(legacyEndpoint, true) !== undefined) {
34
+ throw new Error(`${slug}/peacekeeper.config.json: rename this legacy JSON configuration to peacekeeper.config.yaml and convert it to YAML.`);
35
+ }
32
36
  config = structuredClone(projectConfigDefaults);
33
37
  }
34
38
  else {
35
39
  if (file.type !== 'file' || file.encoding !== 'base64' || typeof file.content !== 'string') {
36
- throw new Error(`${slug}/peacekeeper.config.json: GitHub returned invalid file contents.`);
40
+ throw new Error(`${slug}/peacekeeper.config.yaml: GitHub returned invalid file contents.`);
37
41
  }
38
42
  try {
39
- config = JSON.parse(Buffer.from(file.content, 'base64').toString('utf8'));
43
+ config = YAML.parse(Buffer.from(file.content, 'base64').toString('utf8'));
40
44
  }
41
45
  catch (error) {
42
- throw new Error(`${slug}/peacekeeper.config.json: ${error instanceof Error ? error.message : String(error)}`);
46
+ throw new Error(`${slug}/peacekeeper.config.yaml: ${error instanceof Error ? error.message : String(error)}`);
43
47
  }
44
48
  }
45
- validateConfig(config, `${slug}/peacekeeper.config.json`);
49
+ validateConfig(config, `${slug}/peacekeeper.config.yaml`);
46
50
  return { ...identity, requiredChecks: config.git.releaseRequiredChecks,
47
51
  requiredApprover: config.git.requiredApprover || identity.owner,
48
52
  defaultBranch: metadata.default_branch };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jakobm/peacekeeper",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "Shared repository test, Git worktree, and Codex hook commands",
5
5
  "license": "MIT",
6
6
  "author": "Jakob Mattsson",