@ehven/git-release-guardrails 0.0.0-stage → 1.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0
4
+
5
+ - Portable guards for retirement planning, remote identity and deployment source checks.
6
+ - Read-only local and live preview, verified Git backups, and restoration into a new bare repository.
7
+ - Explicit retirement bound to a reviewed live plan ID, with exact ref leases, local compare-and-swap and journal recovery.
8
+ - Node and CLI entrypoints with TypeScript declarations and zero npm runtime dependencies.
9
+
10
+ The package follows [Semantic Versioning](https://semver.org/). Preview and
11
+ prerelease artifacts may change before publication. Re-run preview after
12
+ upgrading, and preserve the original package version and verified backup until
13
+ any open recovery operation has been resolved.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ehventerprise LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,562 @@
1
- # Temporary Holding Version
1
+ # @ehven/git-release-guardrails
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Portable guards for retiring integrated Git branches and checking deployment
4
+ source identity. MIT licensed; zero npm runtime dependencies.
5
+
6
+ ## Install and preview
7
+
8
+ ```sh
9
+ npm install --save-dev @ehven/git-release-guardrails
10
+ npm exec -- ehven-git-release-guardrails --help
11
+ ```
12
+
13
+ Start with a [retirement configuration](#retirement-cli-and-configuration) for
14
+ the repository. Run `preview` and inspect the result before requesting live
15
+ validation. Use `apply` only with the reviewed plan ID from `preview --live`.
16
+
17
+ The Node package is ESM and requires Node 24.19.0 or later in the Node 24 line.
18
+ The CLI and Node subpath are supported on Linux and macOS with Git 2.56.1 or
19
+ later and a local filesystem with the documented POSIX protections. The release
20
+ tests exercise Linux with Node 24.19.0 and macOS 26 ARM64 with Node 24.22.3,
21
+ using Git 2.56.1.
22
+ The portable entrypoint does not require Git.
23
+
24
+ Use [GitHub Issues](https://github.com/ehven-consultants-npm-products/ehven-git-release-guardrails/issues)
25
+ for reproducible bugs. Report suspected vulnerabilities privately as described
26
+ in [SECURITY.md](https://github.com/ehven-consultants-npm-products/ehven-git-release-guardrails/blob/main/SECURITY.md).
27
+
28
+ ## Portable API
29
+
30
+ The intended ESM entrypoint exports `planRetirements`,
31
+ `assertDeploymentSource`, `GitReleaseGuardError`, `DEFAULT_TEMPORARY_PREFIXES`,
32
+ `normalizeRemoteUrl` and `assertRemoteDestinations`. Adjacent TypeScript declarations describe the API.
33
+ Importing this entrypoint requires no Git executable, credentials, network,
34
+ filesystem access, Cloudflare account, Wrangler or pnpm. No process environment
35
+ is consulted by these guards.
36
+
37
+ ### planRetirements(options)
38
+
39
+ Returns a Promise for a complete retirement plan, or rejects the entire plan.
40
+ The function does not execute Git or change refs. Its snapshots and ancestry
41
+ resolver must come from a trusted caller. It does not prove that arbitrary
42
+ supplied commit IDs exist or that a review actually occurred.
43
+
44
+ | Option | Contract |
45
+ | --- | --- |
46
+ | `repository` | Bounded nonempty consumer-owned repository identity. Use a canonical, credential-free value. Review matching uses exact string equality. |
47
+ | `permanent` | One to 100 distinct permanent short branch names. All corresponding remote heads must exist and identify the same target commit. |
48
+ | `remote`, `local` | Plain objects mapping short branch names to full commit IDs; null-prototype data objects are supported. At most 10,000 entries in each map. No accessor properties. |
49
+ | `isAncestor(head, target)` | Required trusted resolver returning a boolean or Promise of a boolean. `true` means ancestry was established; `false` means it was not. A thrown/rejected error stops the plan. Bound transport time and cancellation in the resolver. |
50
+ | `objectFormat` | `sha1` by default; explicitly select `sha256` for that object format. Mixed formats, abbreviated IDs, uppercase IDs and all-zero IDs are rejected. |
51
+ | `temporaryPrefixes` | Distinct literal prefixes ending in `/`. Default: `docs/`, `feat/`, `fix/`, `refactor/`, `chore/`. Nested branch names are supported. This is data, not a regex or callback. |
52
+ | `reviewedHeads` | Optional array of at most 10,000 structured review records, described below. Defaults to an empty array. Explicit `null` is invalid. |
53
+
54
+ Unrecognized fields fail rather than silently changing behavior. Names and
55
+ identity text are bounded to 1,024 characters. Branches must be supported short
56
+ Git branch names without whitespace, controls, option prefixes, traversal-like
57
+ components or Git-reserved sequences. This contract is intentionally narrower
58
+ than accepting every possible ref name.
59
+
60
+ Each squash-review record contains exactly:
61
+
62
+ ```js
63
+ {
64
+ repository: 'example.test/team/project',
65
+ branch: 'fix/reviewed-change',
66
+ head: reviewedTemporaryCommit,
67
+ target: acceptedIntegrationCommit,
68
+ evidence: 'review-record/42'
69
+ }
70
+ ```
71
+
72
+ All five fields are required. `evidence` is nonempty text up to 2,048 characters,
73
+ not an executable callback or a URL the package fetches. Duplicate records for
74
+ the same repository/branch/head/target are rejected as ambiguous. A review for
75
+ another repository, branch, head or target cannot authorize retirement. An older
76
+ review may remain in the array but grants no authority to a different tuple.
77
+
78
+ A review is an assertion supplied by a trusted integrator. The package neither
79
+ authenticates the reviewer nor independently verifies equivalent changes. A
80
+ reviewed head is never permission to overwrite a divergent permanent branch.
81
+
82
+ The returned data has this shape:
83
+
84
+ ```js
85
+ {
86
+ repository, objectFormat, target,
87
+ remote: [{ branch, sha, basis: 'ancestry' }],
88
+ local: [{ branch, sha, basis: 'reviewed-head', evidence }],
89
+ align: ['local-permanent-branch-needing-alignment']
90
+ }
91
+ ```
92
+
93
+ Each temporary entry has its actual proof basis. Arrays are sorted by JavaScript
94
+ string order, independently of input property order and system locale. Missing
95
+ local permanent branches appear in `align`; existing local permanent branches
96
+ with unique history stop the plan. Unknown nonpermanent branches stop the plan,
97
+ even when they point to the target. Plan inputs are copied and validated before
98
+ the first ancestry callback; the original inputs are not mutated.
99
+
100
+ This is a snapshot plan. Use the [live CLI preview](#live-retirement-preview)
101
+ to obtain an execution plan ID. Apply re-inspects relevant live state,
102
+ destinations, worktrees and review evidence before changing refs. Remote and
103
+ local changes commit in separate transactions.
104
+
105
+ ### assertDeploymentSource(options)
106
+
107
+ Checks an explicit allowed target, full commit ID, clean source and local/CI
108
+ branch identity. Returns `{ target, sha }`; it performs no deployment.
109
+
110
+ - `targets`: one to 100 distinct allowed short branch names.
111
+ - `target`: one of those names.
112
+ - `sha`: full nonzero lowercase ID in `objectFormat` (`sha1` by default).
113
+ - `status`: exactly `''`, representing clean porcelain output. Include
114
+ untracked files when collecting actual Git status in a caller.
115
+ - `localBranch`: a short branch name; use `''` for detached CI only.
116
+ - `ci`: optional `{ branch, sha }` from a trusted caller. Its commit must match
117
+ `sha`. An attached local branch must agree with the CI branch. A detached
118
+ checkout requires matching CI metadata.
119
+
120
+ Plain metadata can be fabricated by a caller. Passing this guard does not prove
121
+ remote branch state, successful CI, human approval, the identity of build output
122
+ or the revision currently live. The guard works with a caller-owned deploy
123
+ command, including a site-owned Cloudflare wrapper.
124
+
125
+ ### Errors
126
+
127
+ All guard failures use `GitReleaseGuardError` with a stable `code`:
128
+
129
+ | Code | Meaning |
130
+ | --- | --- |
131
+ | `ERR_INPUT` | Missing, malformed, unsupported, oversized or ambiguous input. |
132
+ | `ERR_PERMANENT_ALIGNMENT` | Remote permanent branches are missing or divergent. |
133
+ | `ERR_UNKNOWN_BRANCH` | A nonpermanent branch is outside the configured temporary prefixes. |
134
+ | `ERR_LOCAL_UNMERGED` | A local permanent branch has unique history. |
135
+ | `ERR_UNREVIEWED_WORK` | A temporary head lacks ancestry or an exact applicable review. |
136
+ | `ERR_ANCESTRY_CHECK` | Ancestry inspection failed or returned a nonboolean. |
137
+ | `ERR_DEPLOYMENT_TARGET` | The selected target is not allowed. |
138
+ | `ERR_DIRTY_SOURCE` | Clean source was not established. |
139
+ | `ERR_CI_IDENTITY` | Supplied CI identity conflicts with checkout identity. |
140
+ | `ERR_DEPLOYMENT_SOURCE` | The branch does not match the target. |
141
+
142
+ Messages omit input values. An ancestry failure preserves the original exception
143
+ as `cause` for trusted debugging; do not blindly log that cause when it may
144
+ contain transport or credential details. Review references and repository IDs
145
+ in returned plans remain consumer-controlled data.
146
+
147
+ ## Migration from the local candidate
148
+
149
+ - Add explicit `repository` to planner input.
150
+ - Replace the old `knownHeads: { branch: sha }` map with `reviewedHeads` records.
151
+ Re-review old squash exceptions against the exact accepted target; do not
152
+ mechanically stamp historical entries with the current target.
153
+ - The old `knownHeads` option is intentionally rejected.
154
+ - Use configured literal prefixes when the default temporary naming convention
155
+ does not fit. Unknown work continues to stop the plan.
156
+ - Expect proof metadata and stable sorted arrays in returned plans.
157
+ - Supply exact empty porcelain status for deployment checks. Attached local/CI
158
+ conflicts are rejected; trusted detached CI remains supported.
159
+ - Install the package normally and redirect all imports and retirement commands
160
+ to the installed version. Keep any provider-specific deployment invocation
161
+ in the consumer and import `assertDeploymentSource` there. Remove the old
162
+ candidate after verifying the replacement on an isolated copy.
163
+
164
+ ## Remote endpoint guard
165
+
166
+ `assertRemoteDestinations({ expectedRemoteUrls, fetchUrls, pushUrls })` checks the
167
+ effective fetch and push endpoints independently. Supply one to eight deliberately
168
+ approved HTTPS/SSH URLs; the configured effective fetch and push must each contain
169
+ exactly one approved endpoint. Multiple actual destinations are refused.
170
+
171
+ `normalizeRemoteUrl(url)` canonicalizes equivalent syntax: hostname case, default
172
+ ports, and `git@host:path` versus `ssh://git@host/path`. It does not equate HTTPS
173
+ with SSH, remove `.git`, fold path case or assume different paths serve the same
174
+ repository. Declare each reviewed transport endpoint explicitly. Credential-bearing
175
+ HTTPS, SSH passwords, query/fragment URLs, ambiguous encoded paths and local/custom
176
+ transports are rejected without echoing their contents.
177
+
178
+ The consumer owns the relationship between its opaque repository identity, review
179
+ records and approved endpoint list. URL matching does not authenticate a server,
180
+ resolve SSH host aliases or verify who controls a hostname.
181
+
182
+ ## Optional Node inspection entrypoint
183
+
184
+ ```js
185
+ import { inspectRetirements } from '@ehven/git-release-guardrails/node';
186
+
187
+ const inspection = await inspectRetirements({
188
+ cwd: '/absolute/path/to/repository-root',
189
+ repository: 'example.test/team/project',
190
+ expectedRemoteUrls: [
191
+ 'https://example.test/team/project.git',
192
+ 'git@example.test:team/project.git',
193
+ ],
194
+ remote: 'origin',
195
+ integrationBranch: 'main',
196
+ permanent: ['main', 'preview', 'live'],
197
+ reviewedHeads: [],
198
+ });
199
+ ```
200
+
201
+ This explicitly selected API requires Git. The root portable entrypoint does
202
+ not import it. Use the supported Node, Git and platform versions listed above.
203
+
204
+ The inspector runs from a real repository root with an attached integration
205
+ branch and clean tracked/untracked source. It requires full local history, no
206
+ replacement refs/grafts/promisor state, and exactly one working tree. Linked,
207
+ detached, locked or prunable extra worktrees are refused for now. Preserve that
208
+ work; the inspector never removes worktrees. Executable content-filter configuration
209
+ is refused before status inspection, even if the current files do not use it.
210
+
211
+ Effective URLs are read through Git, including `insteadOf`/`pushInsteadOf`
212
+ rewrites. Require one complete branch fetch refspec such as
213
+ `+refs/heads/*:refs/remotes/origin/*`; filtered/negative/additional refspecs are
214
+ refused. Mirror, implicit push-refspec and follow-tags configuration is also
215
+ refused. Remote names use a conservative ASCII form, up to 64 characters.
216
+
217
+ Local and remote-tracking heads must align as required by the planner. The
218
+ inspector repeats source/ref/worktree/transport reads and refuses observed
219
+ changes during inspection. This is not an atomic lock or execution permit;
220
+ apply revalidates live state under its own controls.
221
+
222
+ The result includes `source`, `transport`, `worktrees` and `plan`, plus:
223
+
224
+ ```js
225
+ {
226
+ inspectionOnly: true,
227
+ remoteFreshness: 'unverified-local-cache',
228
+ networkAccess: false,
229
+ refMutations: false
230
+ }
231
+ ```
232
+
233
+ No fetch, remote query, push, pruning, deployment or ref update is performed.
234
+ Remote-tracking data may be stale. Refreshing it safely is a separate future
235
+ step provided by the opt-in live preview below.
236
+
237
+ Git commands use no shell, noninteractive input, optional locks disabled and
238
+ network protocols/lazy object fetching disabled. Filesystem-monitor hooks are
239
+ disabled; subprocess credentials and repository/environment overrides are not
240
+ forwarded. Git configuration locations are retained so actual endpoint rewrites
241
+ are visible. Use a trusted local repository, Git executable and configuration:
242
+ this is not a sandbox for arbitrary Git installations or filesystem mounts.
243
+
244
+ `timeoutMs` bounds the Git inspection phase and each command (default 10,000;
245
+ allowed 1..30,000). An optional `AbortSignal` cancels it. `maxOutputBytes` bounds
246
+ combined stdout/stderr per command (default 4 MiB; allowed 1 KiB..16 MiB). UTF-8
247
+ output is required. Command output and credential-bearing URLs are not copied
248
+ into errors. Native filesystem lookups are not cancelled by this Git-process
249
+ deadline; use trusted local filesystem locations.
250
+
251
+ Additional stable error codes include `ERR_REMOTE_URL`, `ERR_REMOTE_DESTINATION`,
252
+ `ERR_REPOSITORY_PATH`, `ERR_REPOSITORY_ROOT`, `ERR_SHALLOW_HISTORY`,
253
+ `ERR_REPLACED_HISTORY`, `ERR_PARTIAL_HISTORY`, `ERR_EXTERNAL_FILTER`,
254
+ `ERR_FETCH_REFSPEC`, `ERR_PUSH_CONFIGURATION`, `ERR_SOURCE_BRANCH`,
255
+ `ERR_SOURCE_ALIGNMENT`, `ERR_DETACHED_SOURCE`, `ERR_SYMBOLIC_REF`,
256
+ `ERR_WORKTREE`, `ERR_INSPECTION_CHANGED`, `ERR_INSPECTION_FS`, `ERR_GIT_PARSE`,
257
+ `ERR_GIT_START`, `ERR_GIT_COMMAND`, `ERR_GIT_ENCODING`, `ERR_GIT_OUTPUT_LIMIT`,
258
+ `ERR_GIT_TIMEOUT` and `ERR_ABORTED`. Inspect and preserve source on any refusal;
259
+ do not bypass it with forced cleanup.
260
+
261
+ ## Development verification
262
+
263
+ `npm test` runs portable contract tests plus disposable local Git-history fixtures.
264
+ Fixtures cover ancestral and squashed work, changed target, alternate branches
265
+ and both SHA-1/SHA-256 histories. Live preview tests use disposable remotes.
266
+ Synthetic fixtures are not a second real consumer or a full security assessment.
267
+
268
+ ## Retirement CLI and configuration
269
+
270
+ The installed executable is `ehven-git-release-guardrails`. It supports preview,
271
+ backup, verification, restoration, apply and recovery. Preview uses cached refs
272
+ by default. Pass `--live` for a read-only comparison with the approved remote.
273
+
274
+ ```sh
275
+ ehven-git-release-guardrails --help
276
+ ehven-git-release-guardrails --version
277
+ ehven-git-release-guardrails preview --config ../retirement.json --cwd /path/to/repository
278
+ ehven-git-release-guardrails preview --config ../retirement.json --cwd /path/to/repository --json
279
+ ```
280
+
281
+ Supply a deliberate schemaVersion 1 JSON file:
282
+
283
+ ```json
284
+ {
285
+ "schemaVersion": 1,
286
+ "repository": "example.test/team/project",
287
+ "expectedRemoteUrls": ["https://example.test/team/project.git"],
288
+ "remote": "origin",
289
+ "integrationBranch": "main",
290
+ "permanent": ["main"],
291
+ "temporaryPrefixes": ["docs/", "feat/", "fix/", "refactor/", "chore/"],
292
+ "reviewedHeads": [],
293
+ "timeoutMs": 10000,
294
+ "maxOutputBytes": 4194304
295
+ }
296
+ ```
297
+
298
+ The integration branch must be permanent. A single permanent branch is supported;
299
+ multiple permanent remote branches must all identify the same accepted commit.
300
+ Remote, temporary prefixes, reviews and inspection limits use the defaults and
301
+ contracts described above. Unknown fields, duplicate JSON keys (including escaped
302
+ aliases), invalid reviews and unsupported schema versions are refused. Store
303
+ only credential-free endpoints and deliberately approved review records.
304
+
305
+ Both paths resolve from the invocation directory. `--cwd` defaults to that
306
+ directory; the config file's directory does not change the selected repository.
307
+ Keep an external config outside the working tree, or commit/ignore it deliberately
308
+ so the source passes clean-state inspection. The CLI never writes a config file.
309
+
310
+ Configuration is UTF-8 JSON data only, at most 1 MiB and 32 nesting levels. No
311
+ modules, shell commands, environment interpolation or automatic config discovery
312
+ are supported. The loader requires a regular file and refuses a symlink at the
313
+ final path component, directories and FIFOs. It checks observed file metadata
314
+ before/after reading. Parent directories/filesystems and concurrent writers must
315
+ be trusted; these checks are not a filesystem sandbox or an atomic path lock.
316
+ Platforms without the required file-open protections are refused. Native file
317
+ operations are not covered by the Git-process deadline.
318
+
319
+ `readRetirementConfig(file, { signal? })` is also exported from the optional Node
320
+ entrypoint. It returns inspection options without `cwd` or `signal`; supply those
321
+ explicitly to `inspectRetirements`. It never runs Git. Review commit formats are
322
+ checked internally for consistency and then against the actual repository during
323
+ inspection. Cancellation is checked before and between file reads.
324
+
325
+ With `--json`, success is one JSON object on stdout:
326
+
327
+ ```js
328
+ { schemaVersion: 1, ok: true, command: 'preview', result: inspection }
329
+ ```
330
+
331
+ Refusals leave stdout empty and write one JSON object on stderr:
332
+
333
+ ```js
334
+ { schemaVersion: 1, ok: false, error: { code, message } }
335
+ ```
336
+
337
+ Exit codes: 0 for success/help/version, 1 for a refused or failed command,
338
+ 2 for unsupported/repeated/missing CLI arguments, 130 for handled SIGINT and
339
+ 143 for handled SIGTERM. Help/version do not require Git or a config. Unknown
340
+ commands and unrecognized flags are refused. Human output
341
+ lists temporary branches and proof bases, plus permanent alignment candidates.
342
+ Returned repository data may be sensitive; choose where to retain CLI output.
343
+
344
+ Configuration adds `ERR_CONFIG_FILE`, `ERR_CONFIG_JSON`, `ERR_CONFIG_SCHEMA`,
345
+ `ERR_CONFIG_LIMIT`, `ERR_CONFIG_CHANGED`; the CLI adds `ERR_CLI_USAGE` and
346
+ `ERR_CLI_FAILURE`. Raw parser/subprocess input is not echoed in refusal messages.
347
+ On POSIX, cancellation/deadlines terminate the subprocess group owned by each
348
+ command, including helpers sharing its output pipes. This is not a control for
349
+ arbitrary daemonized processes. Current executable verification remains Linux.
350
+
351
+ ## Live retirement preview
352
+
353
+ ```sh
354
+ ehven-git-release-guardrails preview --config ../retirement.json --cwd /path/to/repository --live --json
355
+ ```
356
+
357
+ Use the package's local preview first. Live mode applies the same source,
358
+ worktree, review, refspec and endpoint checks. It runs read-only `git ls-remote`
359
+ against each distinct effective fetch and push endpoint, then rechecks the local
360
+ snapshot. Each endpoint must advertise exactly the branch names and commit IDs
361
+ in the local remote-tracking cache. New, missing and moved heads stop the preview.
362
+ No tags are compared. A push endpoint must support read access for this check.
363
+
364
+ A success reports `remoteFreshness: 'matched-live-advertisement'` and an
365
+ `observation` with its completion timestamp, the branch count for each endpoint
366
+ and the number of distinct endpoints queried. This is a point-in-time comparison
367
+ of visible advertisements. Server permissions or hidden-ref policy can limit
368
+ visibility. Endpoints are read separately and may change during or after the
369
+ check. A matching advertisement does not prove push access or authorize a
370
+ mutation. An executor must obtain its own fresh state and atomic checks.
371
+
372
+ Live mode supports explicit HTTPS and direct OpenSSH with simple ASCII host and
373
+ repository path syntax. For SSH, use the same URL form in the allowlist and Git
374
+ configuration. SCP-style relative paths and `ssh://` absolute paths are distinct.
375
+ SSH requires established host trust and a default identity or local agent. The
376
+ query uses batch mode without SSH config aliases, forwarding or host-key updates.
377
+ HTTPS uses verified TLS and disables redirects. Both transports run with isolated
378
+ Git configuration, so query-time URL rewrites and credential helpers are bypassed.
379
+
380
+ For an authenticated HTTPS repository, load a complete `Basic ...` or `Bearer
381
+ ...` authorization value into an environment variable through your secret
382
+ manager or CI configuration. Pass its name with `--https-auth-env` and the
383
+ matching approved URL with `--https-auth-endpoint`. Never put the header value in
384
+ command arguments or the JSON configuration. Only the child querying that exact
385
+ HTTPS endpoint receives the header. The Node API accepts `httpsAuthorization:
386
+ { endpoint, value }` on `validateLiveRetirement(options)` from the Node subpath.
387
+ Both interfaces use the same source policy and bounded Git deadline.
388
+
389
+ A stale preview reports added, missing and moved counts. Inspect and refresh
390
+ tracking refs using your normal Git workflow before trying again. This command
391
+ does not fetch objects, prune tracking refs, push, or delete branches.
392
+
393
+ ## Verified local backups and fresh bare recovery
394
+
395
+ ```sh
396
+ ehven-git-release-guardrails backup --config ../retirement.json --cwd /path/to/repository --directory /private/backups/new-snapshot --json
397
+ ehven-git-release-guardrails verify-backup --directory /private/backups/new-snapshot --json
398
+ ehven-git-release-guardrails restore-backup --directory /private/backups/new-snapshot --destination /private/recovery/new.git --json
399
+ ```
400
+
401
+ The optional Node entrypoint exports the matching functions:
402
+
403
+ ```js
404
+ const backup = await createRetirementBackup({
405
+ inspection: { ...config, cwd: '/path/to/repository' },
406
+ directory: '/private/backups/new-snapshot',
407
+ });
408
+ await verifyRetirementBackup({ directory: backup.directory });
409
+ const recovery = await restoreRetirementBackup({
410
+ directory: backup.directory,
411
+ destination: '/private/recovery/new.git',
412
+ });
413
+ ```
414
+
415
+ Import these functions from `@ehven/git-release-guardrails/node`. Creation requires
416
+ an eligible retirement inspection, including clean/full history and the current
417
+ worktree, endpoint, ancestry/review and alignment gates. It repeats inspection and
418
+ all-ref snapshots after proving restoration. These are local-cache checks, with
419
+ no live remote proof and no original ref mutation.
420
+
421
+ Creation requires a new directory outside the source working tree and Git common
422
+ directory. Its parent must already exist. Broken refs and incomplete reachable
423
+ history prevent backup creation. It writes a self-contained
424
+ `repository.bundle`, then records `manifest.json` only after an actual isolated
425
+ bare clone, exact refs/object-format/HEAD comparison and `git fsck --full --strict`
426
+ succeed. The complete fsynced manifest is published exclusively with a hard link;
427
+ no existing manifest is replaced. Supported filesystem hard links are required.
428
+ The two final files are private (requested mode 0600, directory 0700), subject to
429
+ a possibly stricter caller umask. Temporary proof repositories are removed.
430
+
431
+ The bundle contains objects reachable from all recorded refs and HEAD, including
432
+ annotated tags and reviewed squash heads. The manifest records full ref names,
433
+ object IDs, symbolic aliases and their immediate targets, original attached branch, object format, byte count
434
+ and SHA256 digest. Both SHA-1 and SHA-256 repositories are covered by executable
435
+ fixtures. Ref/object-format/HEAD preservation was verified after removing the
436
+ original fixture repository.
437
+
438
+ This is **Git history recovery**, with a deliberately bounded scope:
439
+
440
+ - It excludes working files, index state, repository configuration, credentials,
441
+ hooks, reflogs and unreachable objects. Git LFS content and submodule working
442
+ repositories are not fetched or backed up; committed pointer/gitlink objects
443
+ remain Git objects in the bundle. Preserve those external assets separately.
444
+ - Recovery creates a new **bare repository** outside existing Git working trees
445
+ and metadata directories. It does not check out a working
446
+ tree, configure the original remote, reconnect worktrees or change an existing
447
+ repository. Inspect recovered history before separately cloning/using it.
448
+ - A backup can contain private historical data. Restrict its storage and access.
449
+ Digests detect mismatched bytes; they do not authenticate an unknown author or
450
+ protect against someone replacing both manifest and bundle consistently.
451
+
452
+ Verification repeats isolated restoration and fsck; a matching digest alone is
453
+ insufficient. Incremental bundles with prerequisites, filtered/unknown bundle
454
+ capabilities, extra/missing advertised refs, malformed manifests, duplicate JSON
455
+ keys, changed inputs and invalid packs are refused. Manifest/header input is
456
+ bounded to 4 MiB; at most 10,000 refs and 100 symbolic aliases are supported.
457
+
458
+ Restoration first stages the exact regular-file bytes it verifies into a private
459
+ temporary directory. Git clones only that staged file, with global/system Git
460
+ configuration disabled, empty templates and network protocols disabled except
461
+ local file access for this specific clone. It removes the clone's temporary
462
+ transport configuration, restores recorded aliases/HEAD, and verifies the result.
463
+ Configured URL rewrites and templates cannot redirect this recovery clone.
464
+ Original backup files and source refs are left unchanged.
465
+
466
+ `timeoutMs` is 1..30,000 milliseconds (default 30,000) for the complete Git backup,
467
+ verify or restore operation. Native filesystem calls are not preempted; cancellation
468
+ is checked between reads/writes/commands. `maxBackupBytes` is 1 KiB..1 GiB (default
469
+ 256 MiB). Creation/copying stream bundle data rather than buffering the whole
470
+ pack; Git's internal memory use is not bounded by this byte limit. The CLI exposes
471
+ `--timeout-ms` and `--max-backup-bytes` on these three commands. These are separate
472
+ from the source inspection's per-command output limits.
473
+
474
+ A refusal/interruption can leave the new backup directory incomplete, or leave a
475
+ new partial recovery repository. Preserve it for inspection. Retry only with a
476
+ new destination; existing paths are never overwritten or automatically removed.
477
+ A very late interruption may leave a complete backup; run `verify-backup` before
478
+ relying on it. Manifest presence is not a substitute for verification. This is
479
+ not a power-loss durability certification. Apply adds its own retirement journal.
480
+
481
+ Paths, parent filesystems/writers, the installed Git executable and source Git
482
+ configuration must be trusted. Final input symlinks, directories/FIFOs used as
483
+ files, and a symlinked backup input directory are refused. Parent symlinks are
484
+ resolved deliberately, not sandboxed. Observed source/input changes are refused;
485
+ checks do not lock out arbitrary concurrent writers or detect every transient
486
+ change. Apply revalidates live refs against the approved plan.
487
+
488
+ Backup and recovery require the documented POSIX protections and are tested
489
+ on Linux and macOS. Uncertain
490
+ worktree metadata, including separate-Git-dir layouts whose worktree listing
491
+ conflicts with the supplied source root, remains refused by inspection.
492
+
493
+ Backup results include `verified: true`, `repository`, `objectFormat`, `refCount`,
494
+ `bundleSha256`, `bundleBytes`, absolute `directory`, `networkAccess: false` and
495
+ `sourceRefMutations: false`; restore additionally returns absolute `destination`.
496
+ CLI JSON uses the same success/error envelope as preview with its actual command
497
+ name. Stable additional errors are `ERR_BACKUP_PLATFORM`, `ERR_BACKUP_PATH`,
498
+ `ERR_BACKUP_DESTINATION`, `ERR_BACKUP_FILE`, `ERR_BACKUP_LIMIT`,
499
+ `ERR_BACKUP_CHANGED`, `ERR_BACKUP_REFS`, `ERR_BACKUP_MANIFEST`,
500
+ `ERR_BACKUP_BUNDLE`, `ERR_BACKUP_INTEGRITY`, `ERR_BACKUP_RESTORE` and
501
+ `ERR_BACKUP_IO`, alongside existing input/Git/cancellation codes.
502
+
503
+ ## Apply a reviewed plan
504
+
505
+ 1. Run live preview from the target repository. Confirm the retirement list,
506
+ proof basis, destination, and permanent branches. Save the printed plan ID.
507
+ 2. Run apply with that exact ID and a new private backup directory outside the
508
+ repository. Use the same source, configuration, and authentication options.
509
+ 3. Keep the backup and journal. On failure, inspect the source and remote before
510
+ continuing the saved operation. Use the same ID and directory with recover.
511
+
512
+ ```sh
513
+ ehven-git-release-guardrails preview --live --config /private/retirement-config.json --json
514
+ ehven-git-release-guardrails apply --config /private/retirement-config.json --expect-plan REVIEWED_ID --directory /private/backups/new-operation --json
515
+ ehven-git-release-guardrails recover --config /private/retirement-config.json --expect-plan REVIEWED_ID --directory /private/backups/new-operation --json
516
+ ```
517
+
518
+ `applyRetirement` and `recoverRetirement` accept
519
+ `{ inspection, expectedPlanId, directory, signal?, timeoutMs?, maxBackupBytes? }`
520
+ from the Node subpath. `inspection` uses the same inputs as live preview, with
521
+ any authorization supplied separately from the JSON configuration. The plan
522
+ ID commits to the observed source root, Git endpoint settings, permanent
523
+ branch set, exact branch heads and reviewed deletion plan. Fetch and push
524
+ must resolve to the same effective endpoint for execution.
525
+
526
+ Apply creates a private verified backup and fsyncs an immutable
527
+ `retirement.json` journal before the first mutation. Remote deletions are a
528
+ single atomic push with one exact lease per retired ref. The server must
529
+ advertise atomic push support. The package caps each operation at 64 remote
530
+ deletions and bounds push argument size. The local ref transaction verifies
531
+ original IDs, aligns eligible permanent branches, and removes reviewed local
532
+ heads and matching tracking refs. It checks the source again while Git holds
533
+ the prepared ref locks. No unrelated ref pruning is performed.
534
+
535
+ Exclusive apply and recovery commands use `ehven-retirement.lock` in the
536
+ repository's Git common directory. Do not run other Git writers or worktree
537
+ operations against the same checkout during execution. A hard process death
538
+ can leave this lock behind. Inspect its recorded process and directory before
539
+ removing it, and remove it only after confirming no process owns the operation.
540
+ Keep the bundle and journal available for either path.
541
+
542
+ Recovery re-verifies the saved bundle and reads both actual Git states. If
543
+ both sides still match the approved original state, recovery can retry the
544
+ exact leased push. If remote completion is already visible, recovery proceeds
545
+ only with the original local ref transaction. A completed operation can be
546
+ verified again. Any other ref state requires investigation and retains the
547
+ backup. Reconcile unexpected state manually and review a new plan. Recovery
548
+ does not restore old refs over concurrent work.
549
+
550
+ The remote and local transactions commit separately. Git leases guard
551
+ the remote refs being deleted. A standard push does not lock unchanged
552
+ permanent branches, and server-side visibility policies affect advertisements.
553
+ Keep permanent-branch writers coordinated during apply. Rechecks detect
554
+ observed divergence, including divergence after a write, but cannot undo or
555
+ rule out changes between observations. A host crash can leave a ref store
556
+ partly updated. Recovery stops on a mixed state and keeps the verified backup.
557
+ No automatic rollback is performed.
558
+
559
+ Success includes the reviewed plan ID, backup path and verified counts of
560
+ remote deletions, local deletions and local alignments. An empty plan succeeds
561
+ with zero changes and no new backup directory. SSH and HTTPS use the same
562
+ restricted transport settings as live preview.
package/SECURITY.md ADDED
@@ -0,0 +1,11 @@
1
+ # Security
2
+
3
+ Report a suspected vulnerability privately to [security@ehven.com](mailto:security@ehven.com).
4
+ Include the package version, affected command or API, runtime and Git versions,
5
+ expected and actual behavior, and reproduction steps in a disposable repository.
6
+ Redact credentials and private refs. Share a backup only after agreeing on a
7
+ secure transfer method.
8
+
9
+ For suspected unsafe retirement behavior, stop using the affected command and
10
+ preserve the verified backup and operation journal. Ordinary defects can be
11
+ reported in [GitHub Issues](https://github.com/ehven-consultants-npm-products/ehven-git-release-guardrails/issues).