@git-stunts/git-cas 5.2.1 → 5.2.4
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 +52 -0
- package/README.md +24 -0
- package/bin/actions.js +24 -7
- package/bin/git-cas.js +78 -30
- package/bin/ui/context.js +13 -0
- package/bin/ui/dashboard-cmds.js +14 -6
- package/bin/ui/dashboard-view.js +55 -6
- package/bin/ui/dashboard.js +109 -7
- package/bin/ui/encryption-card.js +2 -2
- package/bin/ui/heatmap.js +20 -2
- package/bin/ui/history-timeline.js +8 -6
- package/bin/ui/manifest-view.js +37 -8
- package/bin/ui/progress.js +60 -38
- package/index.d.ts +5 -1
- package/index.js +47 -215
- package/package.json +2 -1
- package/src/domain/helpers/buildKdfMetadata.js +18 -0
- package/src/domain/services/CasService.d.ts +1 -1
- package/src/domain/services/CasService.js +38 -213
- package/src/domain/services/KeyResolver.js +220 -0
- package/src/domain/services/Semaphore.js +2 -2
- package/src/domain/services/VaultService.js +49 -27
- package/src/domain/services/rotateVaultPassphrase.js +143 -0
- package/src/infrastructure/adapters/BunCryptoAdapter.js +38 -6
- package/src/infrastructure/adapters/EventEmitterObserver.js +19 -7
- package/src/infrastructure/adapters/FileIOHelper.js +64 -0
- package/src/infrastructure/adapters/GitPersistenceAdapter.js +21 -5
- package/src/infrastructure/adapters/GitRefAdapter.js +27 -5
- package/src/infrastructure/adapters/NodeCryptoAdapter.js +38 -7
- package/src/infrastructure/adapters/SilentObserver.js +15 -0
- package/src/infrastructure/adapters/StatsCollector.js +15 -1
- package/src/infrastructure/adapters/WebCryptoAdapter.js +68 -18
- package/src/infrastructure/adapters/createCryptoAdapter.js +25 -0
- package/src/infrastructure/chunkers/FixedChunker.js +5 -1
- package/src/infrastructure/chunkers/resolveChunker.js +45 -0
- package/src/infrastructure/codecs/CborCodec.js +11 -3
- package/src/infrastructure/codecs/JsonCodec.js +10 -2
- package/src/ports/CodecPort.js +3 -3
- package/src/ports/CryptoPort.js +56 -23
- package/src/ports/GitPersistencePort.js +4 -4
- package/src/ports/GitRefPort.js +10 -10
- package/src/types/ambient.d.ts +37 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,58 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [5.2.4] — Prism polish (2026-03-03)
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
- **`CryptoPortBase.sha256()` type** — `index.d.ts` declaration corrected from `string | Promise<string>` to `Promise<string>`, matching the async implementation since v5.2.3.
|
|
14
|
+
- **`keyLength` passthrough** — `KeyResolver.#resolveKeyFromPassphrase` and `deriveKekFromKdf` now forward `kdf.keyLength` to `deriveKey()`, fixing a latent bug for vaults configured with non-default key lengths.
|
|
15
|
+
- **Deno test compatibility** — `createCryptoAdapter.test.js` no longer crashes on Deno by guarding immutable `globalThis.Deno` restoration with try/catch and skipping Node-only tests on non-Node runtimes.
|
|
16
|
+
- **README wording** — "no public API changes" corrected to "no breaking API changes" in the v5.2.3 summary.
|
|
17
|
+
- **Barrel re-export description** — README and CHANGELOG now show the correct `export { default as X } from '...'` syntax.
|
|
18
|
+
- **Vestigial `lastchat.txt`** removed from `jsr.json` exclude list.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
- **`keyResolver` is now private** — `CasService.keyResolver` changed to `#keyResolver`, preventing external access to an internal implementation detail.
|
|
22
|
+
- **`VaultPassphraseRotator.js` → `rotateVaultPassphrase.js`** — renamed to follow camelCase convention for files that export a function (PascalCase is reserved for classes).
|
|
23
|
+
- **`resolveChunker` validation** — `chunkSize` now validated as a finite positive number before constructing `FixedChunker`; invalid values fall through to CasService default.
|
|
24
|
+
- **`@fileoverview` JSDoc** added to `FileIOHelper.js`, `createCryptoAdapter.js`, and `resolveChunker.js`.
|
|
25
|
+
- **`KeyResolver` design note** — class JSDoc now documents the direct `CryptoPort.deriveKey()` call (bypasses `CasService.deriveKey()`).
|
|
26
|
+
- **Long function signature wrapped** — `rotateVaultPassphrase()` export signature broken across multiple lines.
|
|
27
|
+
- **Test hardening** — salt assertion in `KeyResolver.resolveForStore`, `keyLength` round-trip test, `resolveChunker` edge-case tests, guarded `rmSync` teardown in `FileIOHelper.test.js`.
|
|
28
|
+
|
|
29
|
+
## [5.2.3] — Prism refactor (2026-03-03)
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
- **Async `sha256()` across all adapters** — `NodeCryptoAdapter.sha256()` now returns `Promise<string>` (was sync `string`), matching Bun and Web adapters. Fixes Liskov Substitution violation; all callers already `await`. `CryptoPort` JSDoc and `CasService.d.ts` updated to `Promise<string>`.
|
|
33
|
+
- **Extract `KeyResolver`** — ~170 lines of key resolution logic (`wrapDek`, `unwrapDek`, `resolveForDecryption`, `resolveForStore`, `resolveRecipients`, `resolveKeyForRecipients`, passphrase derivation, mutual-exclusion validation) extracted from `CasService` into `src/domain/services/KeyResolver.js`. CasService delegates via `this.keyResolver`. No public API changes. 24 new unit tests.
|
|
34
|
+
- **Move `createCryptoAdapter`** — runtime crypto detection moved from `index.js` to `src/infrastructure/adapters/createCryptoAdapter.js`; test helper now delegates instead of duplicating.
|
|
35
|
+
- **Factor out `resolveChunker`** — chunker factory resolution moved from `index.js` private method to `src/infrastructure/chunkers/resolveChunker.js`.
|
|
36
|
+
- **Move file I/O helpers** — `storeFile()` and `restoreFile()` moved from `index.js` to `src/infrastructure/adapters/FileIOHelper.js`; all `node:*` imports removed from facade.
|
|
37
|
+
- **Factor out `rotateVaultPassphrase`** — passphrase rotation orchestration (~100 lines with retry/backoff) moved from `index.js` to `src/domain/services/rotateVaultPassphrase.js`; `CasError` and `buildKdfMetadata` imports removed from facade.
|
|
38
|
+
- **Private `#config` field** — facade constructor stores options in a single private `#config` field instead of 10 public `this.fooConfig` properties.
|
|
39
|
+
- **Barrel re-exports** — 10 re-export-only modules (`NodeCryptoAdapter`, `Manifest`, `Chunk`, ports, observers, chunkers) converted to `export { default as X } from '...'` form, eliminating unnecessary local bindings.
|
|
40
|
+
- **Configurable retry** — `rotateVaultPassphrase()` now accepts optional `maxRetries` (default 3) and `retryBaseMs` (default 50) options for tuning optimistic-concurrency backoff.
|
|
41
|
+
- **Deterministic fuzz test** — envelope fuzz round-trip test now uses a seeded xorshift32 PRNG instead of `Math.random()`, making failures reproducible across runs.
|
|
42
|
+
- **DRY chunk verification** — extracted `_readAndVerifyChunk()` in `CasService`; both the buffered and streaming restore paths now delegate to the same single-chunk verification method.
|
|
43
|
+
- **DRY KDF metadata** — extracted `buildKdfMetadata()` helper (`src/domain/helpers/buildKdfMetadata.js`); `VaultService` and `ContentAddressableStore` both call it instead of duplicating the KDF object construction.
|
|
44
|
+
|
|
45
|
+
## [5.2.2] — JSDoc total coverage (2026-02-28)
|
|
46
|
+
|
|
47
|
+
### Added
|
|
48
|
+
- `tsconfig.checkjs.json` — strict `checkJs` configuration; `tsc --noEmit` passes with zero errors.
|
|
49
|
+
- `src/types/ambient.d.ts` — ambient type declarations for `@git-stunts/plumbing` and `bun` modules.
|
|
50
|
+
- `@types/node` dev dependency for typecheck support.
|
|
51
|
+
- JSDoc `@typedef` types: `EncryptionMeta`, `KdfParamSet`, `DeriveKeyParams` (CryptoPort); `VaultMetadata`, `VaultState`, `VaultEncryptionMeta` (VaultService).
|
|
52
|
+
|
|
53
|
+
### Changed
|
|
54
|
+
- Every exported and internal function, class method, and callback across all 32 source files now has complete JSDoc `@param`/`@returns` annotations.
|
|
55
|
+
- CryptoPort return types widened to `string | Promise<string>` (sha256), `Buffer | Uint8Array` (randomBytes), sync-or-async for encrypt/decrypt — accurately reflecting adapter implementations.
|
|
56
|
+
- Port `@param` names corrected to match underscore-prefixed abstract parameters (fixes TS8024).
|
|
57
|
+
- Observer adapter methods (`SilentObserver`, `EventEmitterObserver`, `StatsCollector`) fully typed.
|
|
58
|
+
- CLI files (`bin/`) comprehensively annotated with JSDoc types for all Commander callbacks and TUI render functions.
|
|
59
|
+
|
|
8
60
|
## [5.2.1] — Carousel polish (2026-02-28)
|
|
9
61
|
|
|
10
62
|
### Added
|
package/README.md
CHANGED
|
@@ -38,6 +38,30 @@ We use the object database.
|
|
|
38
38
|
|
|
39
39
|
<img src="./docs/demo.gif" alt="git-cas demo" />
|
|
40
40
|
|
|
41
|
+
## What's new in v5.2.4
|
|
42
|
+
|
|
43
|
+
**Code review polish — bug fixes, internal hardening, no breaking changes.**
|
|
44
|
+
|
|
45
|
+
- **`keyLength` passthrough fixed** — KDF derivation now correctly forwards `kdf.keyLength`, fixing a latent bug for vaults configured with non-default key lengths.
|
|
46
|
+
- **`sha256()` type declaration fixed** — `index.d.ts` corrected from `string | Promise<string>` to `Promise<string>`.
|
|
47
|
+
- **Deno CI fixed** — `createCryptoAdapter` tests no longer crash on Deno due to immutable global restoration.
|
|
48
|
+
- **`keyResolver` made private** — `CasService.#keyResolver` prevents external access to an internal detail.
|
|
49
|
+
- **`resolveChunker` validation** — `chunkSize` now validated as a finite positive number before constructing `FixedChunker`.
|
|
50
|
+
- **File rename** — `VaultPassphraseRotator.js` → `rotateVaultPassphrase.js` (camelCase for functions, PascalCase for classes).
|
|
51
|
+
|
|
52
|
+
See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
|
|
53
|
+
|
|
54
|
+
## What's new in v5.2.3
|
|
55
|
+
|
|
56
|
+
**Internal refactoring — no breaking API changes.** The facade, CasService, and crypto adapters were restructured for better separation of concerns:
|
|
57
|
+
|
|
58
|
+
- **Consistent async `sha256()`** — `NodeCryptoAdapter.sha256()` now returns `Promise<string>` like Bun and Web adapters, fixing a Liskov Substitution violation.
|
|
59
|
+
- **`KeyResolver` extracted** — ~170 lines of key resolution logic (DEK wrap/unwrap, passphrase derivation, envelope recipients) moved from CasService (1085 → 909 lines) into a dedicated `KeyResolver` service.
|
|
60
|
+
- **Facade decomposed** — `createCryptoAdapter`, `resolveChunker`, `FileIOHelper`, `rotateVaultPassphrase`, and `buildKdfMetadata` extracted from the monolithic `index.js` into focused modules.
|
|
61
|
+
- **Barrel re-exports** — 10 re-export-only modules converted to `export { default as X } from '...'` form.
|
|
62
|
+
|
|
63
|
+
See [CHANGELOG.md](./CHANGELOG.md) for the full list of changes.
|
|
64
|
+
|
|
41
65
|
## What's new in v5.2.1
|
|
42
66
|
|
|
43
67
|
Bug fix: `rotateVaultPassphrase` now honours `kdfOptions.algorithm` — previously the `--algorithm` flag was silently ignored, always reusing the old KDF algorithm. CLI flag tables in `docs/API.md` are now split per command with `--cwd` documented.
|
package/bin/actions.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
* CLI error handler — wraps command actions with structured error output.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
/** @typedef {{ code?: string, message?: string }} ErrorLike */
|
|
6
|
+
|
|
7
|
+
/** @type {Readonly<Record<string, string>>} */
|
|
5
8
|
const HINTS = {
|
|
6
9
|
MISSING_KEY: 'Provide --key-file or --vault-passphrase',
|
|
7
10
|
MANIFEST_NOT_FOUND: 'Verify the tree OID contains a manifest',
|
|
@@ -19,38 +22,52 @@ const HINTS = {
|
|
|
19
22
|
/**
|
|
20
23
|
* Format and write an error to stderr.
|
|
21
24
|
*
|
|
22
|
-
* @param {
|
|
25
|
+
* @param {ErrorLike} err
|
|
23
26
|
* @param {boolean} json - Whether to output JSON.
|
|
24
27
|
*/
|
|
25
28
|
function writeError(err, json) {
|
|
26
29
|
const message = err?.message ?? String(err);
|
|
27
30
|
const code = typeof err?.code === 'string' ? err.code : undefined;
|
|
28
31
|
if (json) {
|
|
32
|
+
/** @type {{ error: string, code?: string }} */
|
|
29
33
|
const obj = { error: message };
|
|
30
34
|
if (code) { obj.code = code; }
|
|
31
35
|
process.stderr.write(`${JSON.stringify(obj)}\n`);
|
|
32
36
|
} else {
|
|
33
37
|
const prefix = code ? `error [${code}]: ` : 'error: ';
|
|
34
38
|
process.stderr.write(`${prefix}${message}\n`);
|
|
35
|
-
const hint = code
|
|
39
|
+
const hint = getHint(code);
|
|
36
40
|
if (hint) {
|
|
37
41
|
process.stderr.write(`hint: ${hint}\n`);
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Look up a hint for the given error code, guarding against prototype keys.
|
|
48
|
+
*
|
|
49
|
+
* @param {string | undefined} code
|
|
50
|
+
* @returns {string | undefined}
|
|
51
|
+
*/
|
|
52
|
+
function getHint(code) {
|
|
53
|
+
if (code && Object.prototype.hasOwnProperty.call(HINTS, code)) {
|
|
54
|
+
return HINTS[code];
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
42
59
|
/**
|
|
43
60
|
* Wrap a command action with structured error handling.
|
|
44
61
|
*
|
|
45
|
-
* @param {
|
|
46
|
-
* @param {
|
|
47
|
-
* @returns {
|
|
62
|
+
* @param {(...args: any[]) => Promise<void>} fn - The async action function.
|
|
63
|
+
* @param {() => boolean} getJson - Lazy getter for --json flag value.
|
|
64
|
+
* @returns {(...args: any[]) => Promise<void>} Wrapped action.
|
|
48
65
|
*/
|
|
49
66
|
export function runAction(fn, getJson) {
|
|
50
|
-
return async (...args) => {
|
|
67
|
+
return async (/** @type {any[]} */ ...args) => {
|
|
51
68
|
try {
|
|
52
69
|
await fn(...args);
|
|
53
|
-
} catch (err) {
|
|
70
|
+
} catch (/** @type {any} */ err) {
|
|
54
71
|
writeError(err, getJson());
|
|
55
72
|
process.exitCode = 1;
|
|
56
73
|
}
|
package/bin/git-cas.js
CHANGED
|
@@ -18,35 +18,54 @@ const getJson = () => program.opts().json;
|
|
|
18
18
|
program
|
|
19
19
|
.name('git-cas')
|
|
20
20
|
.description('Content Addressable Storage backed by Git')
|
|
21
|
-
.version('5.2.
|
|
21
|
+
.version('5.2.2')
|
|
22
22
|
.option('-q, --quiet', 'Suppress progress output')
|
|
23
23
|
.option('--json', 'Output results as JSON');
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Read a 32-byte raw encryption key from a file.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} keyFilePath
|
|
29
|
+
* @returns {Buffer}
|
|
27
30
|
*/
|
|
28
31
|
function readKeyFile(keyFilePath) {
|
|
29
|
-
|
|
32
|
+
const buf = readFileSync(keyFilePath);
|
|
33
|
+
if (buf.length !== 32) {
|
|
34
|
+
throw new Error(`Invalid key length: expected 32 bytes, got ${buf.length} (${keyFilePath})`);
|
|
35
|
+
}
|
|
36
|
+
return buf;
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
/**
|
|
33
40
|
* Create a CAS instance for the given working directory with an optional observability adapter.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} cwd
|
|
43
|
+
* @param {{ observability?: import('../index.js').ObservabilityPort }} [opts]
|
|
44
|
+
* @returns {ContentAddressableStore}
|
|
34
45
|
*/
|
|
35
|
-
function createCas(cwd,
|
|
46
|
+
function createCas(cwd, opts = {}) {
|
|
36
47
|
const runner = ShellRunnerFactory.create();
|
|
37
48
|
const plumbing = new GitPlumbing({ runner, cwd });
|
|
38
|
-
return new ContentAddressableStore({ plumbing, observability });
|
|
49
|
+
return new ContentAddressableStore({ plumbing, observability: opts.observability });
|
|
39
50
|
}
|
|
40
51
|
|
|
41
52
|
/**
|
|
42
53
|
* Derive the encryption key from vault metadata + passphrase.
|
|
54
|
+
*
|
|
55
|
+
* @param {ContentAddressableStore} cas
|
|
56
|
+
* @param {import('../index.js').VaultMetadata} metadata
|
|
57
|
+
* @param {string} passphrase
|
|
58
|
+
* @returns {Promise<Buffer>}
|
|
43
59
|
*/
|
|
44
60
|
async function deriveVaultKey(cas, metadata, passphrase) {
|
|
61
|
+
if (!metadata.encryption?.kdf) {
|
|
62
|
+
throw new Error('Missing or malformed encryption metadata');
|
|
63
|
+
}
|
|
45
64
|
const { kdf } = metadata.encryption;
|
|
46
65
|
const { key } = await cas.deriveKey({
|
|
47
66
|
passphrase,
|
|
48
67
|
salt: Buffer.from(kdf.salt, 'base64'),
|
|
49
|
-
algorithm: kdf.algorithm,
|
|
68
|
+
algorithm: /** @type {"pbkdf2" | "scrypt"} */ (kdf.algorithm),
|
|
50
69
|
iterations: kdf.iterations,
|
|
51
70
|
cost: kdf.cost,
|
|
52
71
|
blockSize: kdf.blockSize,
|
|
@@ -57,6 +76,9 @@ async function deriveVaultKey(cas, metadata, passphrase) {
|
|
|
57
76
|
|
|
58
77
|
/**
|
|
59
78
|
* Resolve passphrase from --vault-passphrase flag or GIT_CAS_PASSPHRASE env var.
|
|
79
|
+
*
|
|
80
|
+
* @param {Record<string, any>} opts
|
|
81
|
+
* @returns {string | undefined}
|
|
60
82
|
*/
|
|
61
83
|
function resolvePassphrase(opts) {
|
|
62
84
|
return opts.vaultPassphrase ?? process.env.GIT_CAS_PASSPHRASE;
|
|
@@ -64,6 +86,10 @@ function resolvePassphrase(opts) {
|
|
|
64
86
|
|
|
65
87
|
/**
|
|
66
88
|
* Resolve encryption key from --key-file or --vault-passphrase / GIT_CAS_PASSPHRASE.
|
|
89
|
+
*
|
|
90
|
+
* @param {ContentAddressableStore} cas
|
|
91
|
+
* @param {Record<string, any>} opts
|
|
92
|
+
* @returns {Promise<Buffer | undefined>}
|
|
67
93
|
*/
|
|
68
94
|
async function resolveEncryptionKey(cas, opts) {
|
|
69
95
|
if (opts.keyFile) {
|
|
@@ -83,6 +109,8 @@ async function resolveEncryptionKey(cas, opts) {
|
|
|
83
109
|
|
|
84
110
|
/**
|
|
85
111
|
* Validate --slug / --oid flags (exactly one required).
|
|
112
|
+
*
|
|
113
|
+
* @param {Record<string, any>} opts
|
|
86
114
|
*/
|
|
87
115
|
function validateRestoreFlags(opts) {
|
|
88
116
|
if (opts.slug && opts.oid) {
|
|
@@ -96,10 +124,25 @@ function validateRestoreFlags(opts) {
|
|
|
96
124
|
// ---------------------------------------------------------------------------
|
|
97
125
|
// store
|
|
98
126
|
// ---------------------------------------------------------------------------
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @typedef {Object} StoreFileOpts
|
|
130
|
+
* @property {string} filePath - Path to the file to store.
|
|
131
|
+
* @property {string} slug - Asset slug identifier.
|
|
132
|
+
* @property {Buffer} [encryptionKey] - 32-byte AES-256-GCM key.
|
|
133
|
+
* @property {Array<{ label: string, key: Buffer }>} [recipients] - Envelope recipients.
|
|
134
|
+
*/
|
|
135
|
+
|
|
99
136
|
/**
|
|
100
137
|
* Build store options, resolving encryption key or recipients.
|
|
138
|
+
*
|
|
139
|
+
* @param {ContentAddressableStore} cas
|
|
140
|
+
* @param {string} file
|
|
141
|
+
* @param {Record<string, any>} opts
|
|
142
|
+
* @returns {Promise<StoreFileOpts>}
|
|
101
143
|
*/
|
|
102
144
|
async function buildStoreOpts(cas, file, opts) {
|
|
145
|
+
/** @type {StoreFileOpts} */
|
|
103
146
|
const storeOpts = { filePath: file, slug: opts.slug };
|
|
104
147
|
if (opts.recipient) {
|
|
105
148
|
storeOpts.recipients = opts.recipient;
|
|
@@ -113,6 +156,10 @@ async function buildStoreOpts(cas, file, opts) {
|
|
|
113
156
|
/**
|
|
114
157
|
* Parse a --recipient flag value into { label, key }.
|
|
115
158
|
* Format: label:keyfile
|
|
159
|
+
*
|
|
160
|
+
* @param {string} value
|
|
161
|
+
* @param {Array<{ label: string, key: Buffer }>} [previous]
|
|
162
|
+
* @returns {Array<{ label: string, key: Buffer }>}
|
|
116
163
|
*/
|
|
117
164
|
function parseRecipient(value, previous) {
|
|
118
165
|
const sep = value.indexOf(':');
|
|
@@ -140,7 +187,7 @@ program
|
|
|
140
187
|
.option('--force', 'Overwrite existing vault entry')
|
|
141
188
|
.option('--vault-passphrase <pass>', 'Vault-level passphrase for encryption (prefer GIT_CAS_PASSPHRASE env var)')
|
|
142
189
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
143
|
-
.action(runAction(async (file, opts) => {
|
|
190
|
+
.action(runAction(async (/** @type {string} */ file, /** @type {Record<string, any>} */ opts) => {
|
|
144
191
|
if (opts.recipient && (opts.keyFile || resolvePassphrase(opts))) {
|
|
145
192
|
throw new Error('Provide --key-file/--vault-passphrase or --recipient, not both');
|
|
146
193
|
}
|
|
@@ -176,7 +223,7 @@ program
|
|
|
176
223
|
.description('Create a Git tree from a manifest')
|
|
177
224
|
.requiredOption('--manifest <path>', 'Path to manifest JSON file')
|
|
178
225
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
179
|
-
.action(runAction(async (opts) => {
|
|
226
|
+
.action(runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
180
227
|
const cas = createCas(opts.cwd);
|
|
181
228
|
const raw = readFileSync(opts.manifest, 'utf8');
|
|
182
229
|
const manifest = new Manifest(JSON.parse(raw));
|
|
@@ -199,7 +246,7 @@ program
|
|
|
199
246
|
.option('--oid <tree-oid>', 'Direct tree OID')
|
|
200
247
|
.option('--heatmap', 'Show chunk heatmap visualization')
|
|
201
248
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
202
|
-
.action(runAction(async (opts) => {
|
|
249
|
+
.action(runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
203
250
|
validateRestoreFlags(opts);
|
|
204
251
|
const cas = createCas(opts.cwd);
|
|
205
252
|
const treeOid = opts.oid || await cas.resolveVaultEntry({ slug: opts.slug });
|
|
@@ -229,7 +276,7 @@ program
|
|
|
229
276
|
.option('--key-file <path>', 'Path to 32-byte raw encryption key file')
|
|
230
277
|
.option('--vault-passphrase <pass>', 'Vault-level passphrase for decryption (prefer GIT_CAS_PASSPHRASE env var)')
|
|
231
278
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
232
|
-
.action(runAction(async (opts) => {
|
|
279
|
+
.action(runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
233
280
|
validateRestoreFlags(opts);
|
|
234
281
|
const quiet = program.opts().quiet || program.opts().json;
|
|
235
282
|
const observer = new EventEmitterObserver();
|
|
@@ -237,11 +284,7 @@ program
|
|
|
237
284
|
const treeOid = opts.oid || await cas.resolveVaultEntry({ slug: opts.slug });
|
|
238
285
|
const manifest = await cas.readManifest({ treeOid });
|
|
239
286
|
|
|
240
|
-
const restoreOpts = { manifest };
|
|
241
287
|
const encryptionKey = await resolveEncryptionKey(cas, opts);
|
|
242
|
-
if (encryptionKey) {
|
|
243
|
-
restoreOpts.encryptionKey = encryptionKey;
|
|
244
|
-
}
|
|
245
288
|
|
|
246
289
|
const progress = createRestoreProgress({
|
|
247
290
|
totalChunks: manifest.chunks.length, quiet,
|
|
@@ -250,7 +293,8 @@ program
|
|
|
250
293
|
let bytesWritten;
|
|
251
294
|
try {
|
|
252
295
|
({ bytesWritten } = await cas.restoreFile({
|
|
253
|
-
|
|
296
|
+
manifest,
|
|
297
|
+
...(encryptionKey ? { encryptionKey } : {}),
|
|
254
298
|
outputPath: opts.out,
|
|
255
299
|
}));
|
|
256
300
|
} finally {
|
|
@@ -273,7 +317,7 @@ program
|
|
|
273
317
|
.option('--slug <slug>', 'Resolve tree OID from vault slug')
|
|
274
318
|
.option('--oid <tree-oid>', 'Direct tree OID')
|
|
275
319
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
276
|
-
.action(runAction(async (opts) => {
|
|
320
|
+
.action(runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
277
321
|
validateRestoreFlags(opts);
|
|
278
322
|
const cas = createCas(opts.cwd);
|
|
279
323
|
const treeOid = opts.oid || await cas.resolveVaultEntry({ slug: opts.slug });
|
|
@@ -303,13 +347,14 @@ vault
|
|
|
303
347
|
.option('--vault-passphrase <pass>', 'Passphrase for vault-level encryption (prefer GIT_CAS_PASSPHRASE env var)')
|
|
304
348
|
.option('--algorithm <alg>', 'KDF algorithm (pbkdf2 or scrypt)', 'pbkdf2')
|
|
305
349
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
306
|
-
.action(runAction(async (opts) => {
|
|
350
|
+
.action(runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
307
351
|
const cas = createCas(opts.cwd);
|
|
352
|
+
/** @type {{ passphrase?: string, kdfOptions?: { algorithm: 'pbkdf2' | 'scrypt' } }} */
|
|
308
353
|
const initOpts = {};
|
|
309
354
|
const passphrase = resolvePassphrase(opts);
|
|
310
355
|
if (passphrase) {
|
|
311
356
|
initOpts.passphrase = passphrase;
|
|
312
|
-
initOpts.kdfOptions = { algorithm: opts.algorithm };
|
|
357
|
+
initOpts.kdfOptions = { algorithm: /** @type {'pbkdf2' | 'scrypt'} */ (opts.algorithm) };
|
|
313
358
|
}
|
|
314
359
|
const { commitOid } = await cas.initVault(initOpts);
|
|
315
360
|
const json = program.opts().json;
|
|
@@ -328,7 +373,7 @@ vault
|
|
|
328
373
|
.description('List vault entries')
|
|
329
374
|
.option('--filter <pattern>', 'Filter entries by glob pattern')
|
|
330
375
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
331
|
-
.action(runAction(async (opts) => {
|
|
376
|
+
.action(runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
332
377
|
const cas = createCas(opts.cwd);
|
|
333
378
|
const all = await cas.listVault();
|
|
334
379
|
const entries = filterEntries(all, opts.filter);
|
|
@@ -349,7 +394,7 @@ vault
|
|
|
349
394
|
.command('remove <slug>')
|
|
350
395
|
.description('Remove an entry from the vault')
|
|
351
396
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
352
|
-
.action(runAction(async (slug, opts) => {
|
|
397
|
+
.action(runAction(async (/** @type {string} */ slug, /** @type {Record<string, any>} */ opts) => {
|
|
353
398
|
const cas = createCas(opts.cwd);
|
|
354
399
|
const { commitOid, removedTreeOid } = await cas.removeFromVault({ slug });
|
|
355
400
|
const json = program.opts().json;
|
|
@@ -368,11 +413,12 @@ vault
|
|
|
368
413
|
.description('Show info for a vault entry')
|
|
369
414
|
.option('--encryption', 'Show vault encryption details')
|
|
370
415
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
371
|
-
.action(runAction(async (slug, opts) => {
|
|
416
|
+
.action(runAction(async (/** @type {string} */ slug, /** @type {Record<string, any>} */ opts) => {
|
|
372
417
|
const cas = createCas(opts.cwd);
|
|
373
418
|
const treeOid = await cas.resolveVaultEntry({ slug });
|
|
374
419
|
const json = program.opts().json;
|
|
375
420
|
if (json) {
|
|
421
|
+
/** @type {Record<string, any>} */
|
|
376
422
|
const result = { slug, treeOid };
|
|
377
423
|
if (opts.encryption) {
|
|
378
424
|
const metadata = await cas.getVaultMetadata();
|
|
@@ -400,7 +446,7 @@ vault
|
|
|
400
446
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
401
447
|
.option('-n, --max-count <n>', 'Limit number of commits')
|
|
402
448
|
.option('--pretty', 'Render as color-coded timeline')
|
|
403
|
-
.action(runAction(async (opts) => {
|
|
449
|
+
.action(runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
404
450
|
const runner = ShellRunnerFactory.create();
|
|
405
451
|
const plumbing = new GitPlumbing({ runner, cwd: opts.cwd || '.' });
|
|
406
452
|
const args = ['log', '--oneline', ContentAddressableStore.VAULT_REF];
|
|
@@ -417,7 +463,7 @@ vault
|
|
|
417
463
|
const history = output
|
|
418
464
|
.split('\n')
|
|
419
465
|
.filter(Boolean)
|
|
420
|
-
.map((line) => {
|
|
466
|
+
.map((/** @type {string} */ line) => {
|
|
421
467
|
const [commitOid, ...messageParts] = line.trim().split(/\s+/);
|
|
422
468
|
return { commitOid, message: messageParts.join(' ') };
|
|
423
469
|
});
|
|
@@ -439,14 +485,15 @@ vault
|
|
|
439
485
|
.requiredOption('--new-passphrase <pass>', 'New vault passphrase')
|
|
440
486
|
.option('--algorithm <alg>', 'KDF algorithm (pbkdf2 or scrypt)')
|
|
441
487
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
442
|
-
.action(runAction(async (opts) => {
|
|
488
|
+
.action(runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
443
489
|
const cas = createCas(opts.cwd);
|
|
490
|
+
/** @type {{ oldPassphrase: string, newPassphrase: string, kdfOptions?: { algorithm: 'pbkdf2' | 'scrypt' } }} */
|
|
444
491
|
const rotateOpts = {
|
|
445
492
|
oldPassphrase: opts.oldPassphrase,
|
|
446
493
|
newPassphrase: opts.newPassphrase,
|
|
447
494
|
};
|
|
448
495
|
if (opts.algorithm) {
|
|
449
|
-
rotateOpts.kdfOptions = { algorithm: opts.algorithm };
|
|
496
|
+
rotateOpts.kdfOptions = { algorithm: /** @type {'pbkdf2' | 'scrypt'} */ (opts.algorithm) };
|
|
450
497
|
}
|
|
451
498
|
const { commitOid, rotatedSlugs, skippedSlugs } = await cas.rotateVaultPassphrase(rotateOpts);
|
|
452
499
|
const json = program.opts().json;
|
|
@@ -470,7 +517,7 @@ vault
|
|
|
470
517
|
.command('dashboard')
|
|
471
518
|
.description('Interactive vault explorer')
|
|
472
519
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
473
|
-
.action(runAction(async (opts) => {
|
|
520
|
+
.action(runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
474
521
|
const cas = createCas(opts.cwd);
|
|
475
522
|
const { launchDashboard } = await import('./ui/dashboard.js');
|
|
476
523
|
await launchDashboard(cas);
|
|
@@ -488,7 +535,7 @@ program
|
|
|
488
535
|
.requiredOption('--new-key-file <path>', 'Path to new 32-byte key file')
|
|
489
536
|
.option('--label <label>', 'Rotate only the named recipient')
|
|
490
537
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
491
|
-
.action(runAction(async (opts) => {
|
|
538
|
+
.action(runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
492
539
|
validateRestoreFlags(opts);
|
|
493
540
|
const cas = createCas(opts.cwd);
|
|
494
541
|
const treeOid = opts.oid || await cas.resolveVaultEntry({ slug: opts.slug });
|
|
@@ -497,6 +544,7 @@ program
|
|
|
497
544
|
const oldKey = readKeyFile(opts.oldKeyFile);
|
|
498
545
|
const newKey = readKeyFile(opts.newKeyFile);
|
|
499
546
|
|
|
547
|
+
/** @type {{ manifest: Manifest, oldKey: Buffer, newKey: Buffer, label?: string }} */
|
|
500
548
|
const rotateOpts = { manifest, oldKey, newKey };
|
|
501
549
|
if (opts.label) { rotateOpts.label = opts.label; }
|
|
502
550
|
|
|
@@ -507,7 +555,7 @@ program
|
|
|
507
555
|
const newTreeOid = await cas.createTree({ manifest: updated });
|
|
508
556
|
await cas.addToVault({ slug: opts.slug, treeOid: newTreeOid, force: true });
|
|
509
557
|
if (json) {
|
|
510
|
-
process.stdout.write(`${JSON.stringify({ treeOid: newTreeOid, keyVersion: updated.encryption
|
|
558
|
+
process.stdout.write(`${JSON.stringify({ treeOid: newTreeOid, keyVersion: updated.encryption?.keyVersion })}\n`);
|
|
511
559
|
} else {
|
|
512
560
|
process.stdout.write(`${newTreeOid}\n`);
|
|
513
561
|
}
|
|
@@ -532,7 +580,7 @@ recipient
|
|
|
532
580
|
.requiredOption('--key-file <path>', 'Path to 32-byte key file for the new recipient')
|
|
533
581
|
.requiredOption('--existing-key-file <path>', 'Path to key file of an existing recipient')
|
|
534
582
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
535
|
-
.action(runAction(async (slug, opts) => {
|
|
583
|
+
.action(runAction(async (/** @type {string} */ slug, /** @type {Record<string, any>} */ opts) => {
|
|
536
584
|
const cas = createCas(opts.cwd);
|
|
537
585
|
const treeOid = await cas.resolveVaultEntry({ slug });
|
|
538
586
|
const manifest = await cas.readManifest({ treeOid });
|
|
@@ -563,7 +611,7 @@ recipient
|
|
|
563
611
|
.description('Remove a recipient from an envelope-encrypted asset')
|
|
564
612
|
.requiredOption('--label <label>', 'Label of the recipient to remove')
|
|
565
613
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
566
|
-
.action(runAction(async (slug, opts) => {
|
|
614
|
+
.action(runAction(async (/** @type {string} */ slug, /** @type {Record<string, any>} */ opts) => {
|
|
567
615
|
const cas = createCas(opts.cwd);
|
|
568
616
|
const treeOid = await cas.resolveVaultEntry({ slug });
|
|
569
617
|
const manifest = await cas.readManifest({ treeOid });
|
|
@@ -585,7 +633,7 @@ recipient
|
|
|
585
633
|
.command('list <slug>')
|
|
586
634
|
.description('List recipients of an envelope-encrypted asset')
|
|
587
635
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
588
|
-
.action(runAction(async (slug, opts) => {
|
|
636
|
+
.action(runAction(async (/** @type {string} */ slug, /** @type {Record<string, any>} */ opts) => {
|
|
589
637
|
const cas = createCas(opts.cwd);
|
|
590
638
|
const treeOid = await cas.resolveVaultEntry({ slug });
|
|
591
639
|
const manifest = await cas.readManifest({ treeOid });
|
package/bin/ui/context.js
CHANGED
|
@@ -5,11 +5,14 @@
|
|
|
5
5
|
import { createBijou } from '@flyingrobots/bijou';
|
|
6
6
|
import { nodeRuntime, chalkStyle } from '@flyingrobots/bijou-node';
|
|
7
7
|
|
|
8
|
+
/** @type {import('@flyingrobots/bijou').BijouContext | null} */
|
|
8
9
|
let ctx = null;
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Returns a bijou context that writes to stderr instead of stdout.
|
|
12
13
|
* Stdout is reserved for structured output (OIDs, JSON).
|
|
14
|
+
*
|
|
15
|
+
* @returns {import('@flyingrobots/bijou').BijouContext}
|
|
13
16
|
*/
|
|
14
17
|
export function getCliContext() {
|
|
15
18
|
if (ctx) {
|
|
@@ -25,8 +28,12 @@ export function getCliContext() {
|
|
|
25
28
|
return ctx;
|
|
26
29
|
}
|
|
27
30
|
|
|
31
|
+
/**
|
|
32
|
+
* @returns {import('@flyingrobots/bijou').IOPort}
|
|
33
|
+
*/
|
|
28
34
|
function stderrIO() {
|
|
29
35
|
return {
|
|
36
|
+
/** @param {string} data */
|
|
30
37
|
write(data) {
|
|
31
38
|
process.stderr.write(data);
|
|
32
39
|
},
|
|
@@ -36,6 +43,7 @@ function stderrIO() {
|
|
|
36
43
|
rawInput() {
|
|
37
44
|
throw new Error('rawInput() not supported in CLI context');
|
|
38
45
|
},
|
|
46
|
+
/** @param {(cols: number, rows: number) => void} callback */
|
|
39
47
|
onResize(callback) {
|
|
40
48
|
const handler = () => {
|
|
41
49
|
callback(process.stderr.columns ?? 80, process.stderr.rows ?? 24);
|
|
@@ -43,12 +51,17 @@ function stderrIO() {
|
|
|
43
51
|
process.stderr.on('resize', handler);
|
|
44
52
|
return { dispose() { process.stderr.removeListener('resize', handler); } };
|
|
45
53
|
},
|
|
54
|
+
/**
|
|
55
|
+
* @param {() => void} callback
|
|
56
|
+
* @param {number} ms
|
|
57
|
+
*/
|
|
46
58
|
setInterval(callback, ms) {
|
|
47
59
|
const id = globalThis.setInterval(callback, ms);
|
|
48
60
|
return { dispose() { globalThis.clearInterval(id); } };
|
|
49
61
|
},
|
|
50
62
|
readFile() { throw new Error('readFile() not supported'); },
|
|
51
63
|
readDir() { throw new Error('readDir() not supported'); },
|
|
64
|
+
/** @param {string[]} segments */
|
|
52
65
|
joinPath(...segments) { return segments.join('/'); },
|
|
53
66
|
};
|
|
54
67
|
}
|
package/bin/ui/dashboard-cmds.js
CHANGED
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
* Async command factories for the vault dashboard.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
/** @typedef {import('../../index.js').default} ContentAddressableStore */
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* Load vault entries and metadata in parallel.
|
|
9
|
+
*
|
|
10
|
+
* @param {ContentAddressableStore} cas
|
|
7
11
|
*/
|
|
8
12
|
export function loadEntriesCmd(cas) {
|
|
9
13
|
return async () => {
|
|
@@ -12,23 +16,27 @@ export function loadEntriesCmd(cas) {
|
|
|
12
16
|
cas.listVault(),
|
|
13
17
|
cas.getVaultMetadata(),
|
|
14
18
|
]);
|
|
15
|
-
return { type: 'loaded-entries', entries, metadata };
|
|
16
|
-
} catch (err) {
|
|
17
|
-
return { type: 'load-error', source: 'entries', error: err.message };
|
|
19
|
+
return /** @type {const} */ ({ type: 'loaded-entries', entries, metadata });
|
|
20
|
+
} catch (/** @type {any} */ err) {
|
|
21
|
+
return /** @type {const} */ ({ type: 'load-error', source: 'entries', error: /** @type {Error} */ (err).message });
|
|
18
22
|
}
|
|
19
23
|
};
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
/**
|
|
23
27
|
* Load a single manifest by slug and tree OID.
|
|
28
|
+
*
|
|
29
|
+
* @param {ContentAddressableStore} cas
|
|
30
|
+
* @param {string} slug
|
|
31
|
+
* @param {string} treeOid
|
|
24
32
|
*/
|
|
25
33
|
export function loadManifestCmd(cas, slug, treeOid) {
|
|
26
34
|
return async () => {
|
|
27
35
|
try {
|
|
28
36
|
const manifest = await cas.readManifest({ treeOid });
|
|
29
|
-
return { type: 'loaded-manifest', slug, manifest };
|
|
30
|
-
} catch (err) {
|
|
31
|
-
return { type: 'load-error', source: 'manifest', slug, error: err.message };
|
|
37
|
+
return /** @type {const} */ ({ type: 'loaded-manifest', slug, manifest });
|
|
38
|
+
} catch (/** @type {any} */ err) {
|
|
39
|
+
return /** @type {const} */ ({ type: 'load-error', source: 'manifest', slug, error: /** @type {Error} */ (err).message });
|
|
32
40
|
}
|
|
33
41
|
};
|
|
34
42
|
}
|