@git-stunts/git-cas 5.3.1 → 6.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/ADVANCED_GUIDE.md +1006 -0
- package/ARCHITECTURE.md +514 -0
- package/CHANGELOG.md +401 -4
- package/CODE_OF_CONDUCT.md +33 -0
- package/GUIDE.md +872 -0
- package/README.md +219 -325
- package/SECURITY.md +993 -0
- package/SUPPORT.md +54 -0
- package/UPGRADING.md +299 -0
- package/bin/actions.js +72 -20
- package/bin/agent/cli.js +51 -0
- package/bin/agent/commands/doctor.js +99 -0
- package/bin/agent/commands/index.js +1489 -0
- package/bin/agent/input.js +619 -0
- package/bin/agent/passphrase-source.js +123 -0
- package/bin/agent/protocol.js +193 -0
- package/bin/build-version.js +64 -0
- package/bin/credentials.js +425 -0
- package/bin/git-cas.js +604 -450
- package/bin/io.js +86 -0
- package/bin/passphrase-source.js +266 -0
- package/bin/restore-output-target.js +28 -0
- package/bin/ui/blocks/asset-card.js +109 -0
- package/bin/ui/blocks/health-dashboard.js +149 -0
- package/bin/ui/blocks/heatmap-block.js +67 -0
- package/bin/ui/blocks/merkle-explorer.js +163 -0
- package/bin/ui/blocks/operation-feed.js +176 -0
- package/bin/ui/blocks/wizard-block.js +168 -0
- package/bin/ui/components/short-sha.js +36 -0
- package/bin/ui/context.js +56 -1
- package/bin/ui/dashboard-cmds.js +1578 -13
- package/bin/ui/dashboard-view.js +612 -145
- package/bin/ui/dashboard.js +998 -214
- package/bin/ui/encryption-card.js +69 -26
- package/bin/ui/heatmap.js +26 -54
- package/bin/ui/history-timeline.js +51 -19
- package/bin/ui/manifest-view.js +115 -60
- package/bin/ui/merkle-dag.js +83 -0
- package/bin/ui/progress.js +15 -9
- package/bin/ui/repo-treemap.js +328 -0
- package/bin/ui/shaders/bak-sneppen.js +180 -0
- package/bin/ui/shaders/fractal-zoom.js +99 -0
- package/bin/ui/shaders/merkle-tree.js +142 -0
- package/bin/ui/shaders/organic-flow.js +96 -0
- package/bin/ui/shaders/phase-portrait.js +93 -0
- package/bin/ui/store-wizard.js +296 -0
- package/bin/ui/theme.js +155 -0
- package/bin/ui/vault-report.js +495 -0
- package/build-info.json +4 -0
- package/docs/API.md +2224 -0
- package/docs/ENCRYPTION_MODES.md +33 -0
- package/docs/EXTENDING.md +174 -0
- package/docs/STORE_RESTORE_PIPELINE.md +199 -0
- package/docs/THREAT_MODEL.md +269 -0
- package/docs/VAULT_INTERNALS.md +251 -0
- package/docs/WALKTHROUGH.md +1868 -0
- package/docs/demo.gif +0 -0
- package/docs/releases/v6.0.0.md +104 -0
- package/examples/README.md +260 -0
- package/index.d.ts +208 -65
- package/index.js +163 -54
- package/package.json +35 -6
- package/scripts/migrate-encryption.js +680 -0
- package/src/domain/bytes/ByteLayout.js +96 -0
- package/src/domain/encoding/base64.js +91 -0
- package/src/domain/encoding/hex.js +14 -0
- package/src/domain/encoding/utf8.js +123 -0
- package/src/domain/encryption/schemes.js +132 -0
- package/src/domain/errors/CannotRemoveLastRecipientError.js +10 -0
- package/src/domain/errors/CasError.d.ts +28 -0
- package/src/domain/errors/CasError.js +43 -6
- package/src/domain/errors/Codes.js +54 -0
- package/src/domain/errors/DekUnwrapFailedError.js +10 -0
- package/src/domain/errors/GitError.js +10 -0
- package/src/domain/errors/GitPlumbingInitializationError.js +10 -0
- package/src/domain/errors/IntegrityError.js +10 -0
- package/src/domain/errors/InvalidChunkingStrategyError.js +10 -0
- package/src/domain/errors/InvalidOidError.js +10 -0
- package/src/domain/errors/InvalidOptionsError.js +10 -0
- package/src/domain/errors/ManifestIntegrityError.js +10 -0
- package/src/domain/errors/ManifestNotFoundError.js +10 -0
- package/src/domain/errors/NoMatchingRecipientError.js +10 -0
- package/src/domain/errors/PersistenceCapabilityRequiredError.js +10 -0
- package/src/domain/errors/PortNotImplementedError.js +10 -0
- package/src/domain/errors/RecipientAlreadyExistsError.js +10 -0
- package/src/domain/errors/RecipientNotFoundError.js +10 -0
- package/src/domain/errors/RestoreTooLargeError.js +10 -0
- package/src/domain/errors/RotationNotSupportedError.js +10 -0
- package/src/domain/errors/createCasError.js +68 -0
- package/src/domain/errors/index.js +20 -0
- package/src/domain/helpers/buildKdfMetadata.js +4 -2
- package/src/domain/helpers/codecBytes.js +34 -0
- package/src/domain/helpers/gitRefErrors.js +84 -0
- package/src/domain/helpers/scryptMaxmem.js +22 -0
- package/src/domain/outcomes/RestoreFailure.js +15 -0
- package/src/domain/outcomes/RestoreOutcome.js +11 -0
- package/src/domain/outcomes/RestoreSuccess.js +34 -0
- package/src/domain/outcomes/StoreFailure.js +15 -0
- package/src/domain/outcomes/StoreOutcome.js +11 -0
- package/src/domain/outcomes/StoreSuccess.js +17 -0
- package/src/domain/schemas/ManifestSchema.d.ts +40 -9
- package/src/domain/schemas/ManifestSchema.js +67 -13
- package/src/domain/services/CasService.d.ts +123 -38
- package/src/domain/services/CasService.js +298 -834
- package/src/domain/services/ChunkRepository.js +230 -0
- package/src/domain/services/CompressionStreams.js +72 -0
- package/src/domain/services/ConvergentEncryption.js +128 -0
- package/src/domain/services/GitTreeBuilder.js +86 -0
- package/src/domain/services/IntegrityVerifier.js +199 -0
- package/src/domain/services/KeyResolver.js +49 -42
- package/src/domain/services/ManifestDiff.js +56 -0
- package/src/domain/services/ManifestRepository.js +286 -0
- package/src/domain/services/PrefetchWindow.js +48 -0
- package/src/domain/services/RecipientService.js +157 -0
- package/src/domain/services/RedactingObservability.js +169 -0
- package/src/domain/services/RestorePipeline.js +68 -0
- package/src/domain/services/StorePipeline.js +201 -0
- package/src/domain/services/VaultKeyVerifier.js +101 -0
- package/src/domain/services/VaultMetadataCodec.js +206 -0
- package/src/domain/services/VaultMutationRetryPolicy.js +105 -0
- package/src/domain/services/VaultPersistence.js +410 -0
- package/src/domain/services/VaultPrivacyIndex.js +191 -0
- package/src/domain/services/VaultService.js +749 -251
- package/src/domain/services/VaultStateCache.js +225 -0
- package/src/domain/services/VaultTreeCodec.js +121 -0
- package/src/domain/services/rotateVaultPassphrase.js +37 -20
- package/src/domain/strategies/Aad.js +39 -0
- package/src/domain/strategies/FramedRecordCodec.js +204 -0
- package/src/domain/strategies/RestoreCompressed.js +40 -0
- package/src/domain/strategies/RestoreConvergent.js +44 -0
- package/src/domain/strategies/RestoreFramed.js +55 -0
- package/src/domain/strategies/RestorePlain.js +37 -0
- package/src/domain/strategies/RestoreStrategy.js +35 -0
- package/src/domain/strategies/RestoreWhole.js +135 -0
- package/src/domain/strategies/StoreConvergent.js +28 -0
- package/src/domain/strategies/StoreFramed.js +39 -0
- package/src/domain/strategies/StorePlain.js +20 -0
- package/src/domain/strategies/StoreStrategy.js +61 -0
- package/src/domain/strategies/StoreWhole.js +34 -0
- package/src/domain/value-objects/Chunk.js +1 -2
- package/src/domain/value-objects/EncryptionMetadata.js +87 -0
- package/src/domain/value-objects/Manifest.d.ts +40 -4
- package/src/domain/value-objects/Manifest.js +61 -20
- package/src/domain/value-objects/Oid.js +45 -0
- package/src/domain/value-objects/Slug.js +124 -0
- package/src/domain/value-objects/StoreEncryptionConfig.js +114 -0
- package/src/helpers/aesGcmMeta.js +55 -0
- package/src/helpers/canonicalBase64.js +1 -0
- package/src/helpers/kdfPolicy.js +194 -0
- package/src/infrastructure/adapters/BunCryptoAdapter.js +124 -8
- package/src/infrastructure/adapters/FileIOHelper.js +178 -13
- package/src/infrastructure/adapters/GitPersistenceAdapter.js +235 -42
- package/src/infrastructure/adapters/GitPlumbingFactoryAdapter.js +62 -0
- package/src/infrastructure/adapters/GitRefAdapter.js +19 -6
- package/src/infrastructure/adapters/NodeCompressionAdapter.js +64 -0
- package/src/infrastructure/adapters/NodeCryptoAdapter.js +130 -10
- package/src/infrastructure/adapters/WebCryptoAdapter.js +187 -77
- package/src/infrastructure/chunkers/CdcChunker.js +53 -19
- package/src/infrastructure/chunkers/FixedChunker.js +15 -7
- package/src/infrastructure/chunkers/resolveChunker.js +3 -1
- package/src/infrastructure/codecs/CborCodec.js +3 -3
- package/src/infrastructure/codecs/JsonCodec.js +5 -5
- package/src/infrastructure/createGitPlumbing.js +22 -0
- package/src/package-version.js +1 -0
- package/src/ports/ChunkingPort.js +3 -3
- package/src/ports/CodecPort.js +4 -4
- package/src/ports/CompressionPort.js +57 -0
- package/src/ports/CryptoPort.js +138 -50
- package/src/ports/GitPersistencePort.js +32 -2
- package/src/ports/GitPlumbingFactoryPort.js +16 -0
- package/src/ports/GitRefPort.js +1 -1
- package/src/types/ambient.d.ts +10 -5
- package/test/CONVENTIONS.md +94 -0
- package/test/cycles/README.md +13 -0
package/bin/git-cas.js
CHANGED
|
@@ -1,53 +1,75 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { readFileSync } from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
4
6
|
import { program, Option } from 'commander';
|
|
5
|
-
import GitPlumbing, { ShellRunnerFactory } from '@git-stunts/plumbing';
|
|
6
7
|
import ContentAddressableStore, { EventEmitterObserver, CborCodec } from '../index.js';
|
|
7
8
|
import Manifest from '../src/domain/value-objects/Manifest.js';
|
|
9
|
+
import Slug from '../src/domain/value-objects/Slug.js';
|
|
10
|
+
import { createGitPlumbing } from '../src/infrastructure/createGitPlumbing.js';
|
|
8
11
|
import { createStoreProgress, createRestoreProgress } from './ui/progress.js';
|
|
9
12
|
import { renderEncryptionCard } from './ui/encryption-card.js';
|
|
10
13
|
import { renderHistoryTimeline } from './ui/history-timeline.js';
|
|
11
14
|
import { renderManifestView } from './ui/manifest-view.js';
|
|
12
15
|
import { renderHeatmap } from './ui/heatmap.js';
|
|
16
|
+
import { surfaceToString } from '@flyingrobots/bijou';
|
|
17
|
+
import {
|
|
18
|
+
buildVaultStats,
|
|
19
|
+
inspectVaultHealth,
|
|
20
|
+
renderVaultStats,
|
|
21
|
+
} from './ui/vault-report.js';
|
|
22
|
+
import { renderHealthDashboard } from './ui/blocks/health-dashboard.js';
|
|
23
|
+
import { getCliContext } from './ui/context.js';
|
|
13
24
|
import { runAction } from './actions.js';
|
|
25
|
+
import { runAgentCli } from './agent/cli.js';
|
|
26
|
+
import { flushStdioAndExit, installBrokenPipeHandlers } from './io.js';
|
|
14
27
|
import { filterEntries, formatTable, formatTabSeparated } from './ui/vault-list.js';
|
|
15
|
-
import { readPassphraseFile
|
|
28
|
+
import { readPassphraseFile } from './ui/passphrase-prompt.js';
|
|
29
|
+
import {
|
|
30
|
+
hasExplicitPassphraseSource,
|
|
31
|
+
resolvePassphrase,
|
|
32
|
+
warnInlinePassphraseArgs,
|
|
33
|
+
} from './passphrase-source.js';
|
|
34
|
+
import {
|
|
35
|
+
readKeyFile,
|
|
36
|
+
resolveCliEncryptionKey as resolveEncryptionKey,
|
|
37
|
+
validateCliCredentialSources as validateCredentialSources,
|
|
38
|
+
} from './credentials.js';
|
|
16
39
|
import { loadConfig, mergeConfig } from './config.js';
|
|
40
|
+
import { resolveRestoreOutputTarget } from './restore-output-target.js';
|
|
41
|
+
|
|
42
|
+
import { resolveVersionString } from './build-version.js';
|
|
43
|
+
|
|
44
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
45
|
+
const CLI_VERSION = resolveVersionString(
|
|
46
|
+
JSON.parse(readFileSync(path.resolve(__dirname, '../package.json'), 'utf8')).version,
|
|
47
|
+
);
|
|
17
48
|
|
|
18
49
|
const getJson = () => program.opts().json;
|
|
50
|
+
installBrokenPipeHandlers();
|
|
51
|
+
|
|
52
|
+
if (process.argv[2] === 'agent') {
|
|
53
|
+
await runAgentCli(process.argv.slice(3));
|
|
54
|
+
await flushStdioAndExit();
|
|
55
|
+
}
|
|
19
56
|
|
|
20
57
|
program
|
|
21
58
|
.name('git-cas')
|
|
22
59
|
.description('Content Addressable Storage backed by Git')
|
|
23
|
-
.version(
|
|
60
|
+
.version(CLI_VERSION)
|
|
24
61
|
.option('-q, --quiet', 'Suppress progress output')
|
|
25
62
|
.option('--json', 'Output results as JSON');
|
|
26
63
|
|
|
27
|
-
/**
|
|
28
|
-
* Read a 32-byte raw encryption key from a file.
|
|
29
|
-
*
|
|
30
|
-
* @param {string} keyFilePath
|
|
31
|
-
* @returns {Buffer}
|
|
32
|
-
*/
|
|
33
|
-
function readKeyFile(keyFilePath) {
|
|
34
|
-
const buf = readFileSync(keyFilePath);
|
|
35
|
-
if (buf.length !== 32) {
|
|
36
|
-
throw new Error(`Invalid key length: expected 32 bytes, got ${buf.length} (${keyFilePath})`);
|
|
37
|
-
}
|
|
38
|
-
return buf;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
64
|
/**
|
|
42
65
|
* Create a CAS instance for the given working directory.
|
|
43
66
|
*
|
|
44
67
|
* @param {string} cwd
|
|
45
68
|
* @param {Record<string, any>} [opts]
|
|
46
|
-
* @returns {ContentAddressableStore}
|
|
69
|
+
* @returns {Promise<ContentAddressableStore>}
|
|
47
70
|
*/
|
|
48
|
-
function createCas(cwd, opts = {}) {
|
|
49
|
-
const
|
|
50
|
-
const plumbing = new GitPlumbing({ runner, cwd });
|
|
71
|
+
async function createCas(cwd, opts = {}) {
|
|
72
|
+
const plumbing = await createGitPlumbing({ cwd });
|
|
51
73
|
/** @type {Record<string, any>} */
|
|
52
74
|
const casOpts = { plumbing, ...opts };
|
|
53
75
|
if (casOpts.codec === 'cbor') {
|
|
@@ -56,96 +78,6 @@ function createCas(cwd, opts = {}) {
|
|
|
56
78
|
return new ContentAddressableStore(casOpts);
|
|
57
79
|
}
|
|
58
80
|
|
|
59
|
-
/**
|
|
60
|
-
* Derive the encryption key from vault metadata + passphrase.
|
|
61
|
-
*
|
|
62
|
-
* @param {ContentAddressableStore} cas
|
|
63
|
-
* @param {import('../index.js').VaultMetadata} metadata
|
|
64
|
-
* @param {string} passphrase
|
|
65
|
-
* @returns {Promise<Buffer>}
|
|
66
|
-
*/
|
|
67
|
-
async function deriveVaultKey(cas, metadata, passphrase) {
|
|
68
|
-
if (!metadata.encryption?.kdf) {
|
|
69
|
-
throw new Error('Missing or malformed encryption metadata');
|
|
70
|
-
}
|
|
71
|
-
const { kdf } = metadata.encryption;
|
|
72
|
-
const { key } = await cas.deriveKey({
|
|
73
|
-
passphrase,
|
|
74
|
-
salt: Buffer.from(kdf.salt, 'base64'),
|
|
75
|
-
algorithm: /** @type {"pbkdf2" | "scrypt"} */ (kdf.algorithm),
|
|
76
|
-
iterations: kdf.iterations,
|
|
77
|
-
cost: kdf.cost,
|
|
78
|
-
blockSize: kdf.blockSize,
|
|
79
|
-
parallelization: kdf.parallelization,
|
|
80
|
-
});
|
|
81
|
-
return key;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Returns true when a non-interactive passphrase source exists (flag or env).
|
|
86
|
-
* Does NOT trigger prompts or consume stdin.
|
|
87
|
-
*
|
|
88
|
-
* @param {Record<string, any>} opts
|
|
89
|
-
* @returns {boolean}
|
|
90
|
-
*/
|
|
91
|
-
function hasPassphraseSource(opts) {
|
|
92
|
-
return Boolean(opts.vaultPassphraseFile || opts.vaultPassphrase || process.env.GIT_CAS_PASSPHRASE);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Resolve passphrase from (in priority order):
|
|
97
|
-
* 1. --vault-passphrase-file <path>
|
|
98
|
-
* 2. --vault-passphrase <pass>
|
|
99
|
-
* 3. GIT_CAS_PASSPHRASE env var
|
|
100
|
-
* 4. Interactive TTY prompt (if stdin is a TTY)
|
|
101
|
-
*
|
|
102
|
-
* @param {Record<string, any>} opts
|
|
103
|
-
* @param {{ confirm?: boolean }} [extra]
|
|
104
|
-
* @returns {Promise<string | undefined>}
|
|
105
|
-
*/
|
|
106
|
-
async function resolvePassphrase(opts, extra = {}) {
|
|
107
|
-
if (opts.vaultPassphraseFile) {
|
|
108
|
-
return await readPassphraseFile(opts.vaultPassphraseFile);
|
|
109
|
-
}
|
|
110
|
-
if (opts.vaultPassphrase) {
|
|
111
|
-
if (!opts.vaultPassphrase.trim()) { throw new Error('Passphrase must not be empty'); }
|
|
112
|
-
return opts.vaultPassphrase;
|
|
113
|
-
}
|
|
114
|
-
if (process.env.GIT_CAS_PASSPHRASE) {
|
|
115
|
-
if (!process.env.GIT_CAS_PASSPHRASE.trim()) { throw new Error('Passphrase must not be empty'); }
|
|
116
|
-
return process.env.GIT_CAS_PASSPHRASE;
|
|
117
|
-
}
|
|
118
|
-
if (process.stdin.isTTY) {
|
|
119
|
-
return await promptPassphrase({ confirm: extra.confirm || false });
|
|
120
|
-
}
|
|
121
|
-
return undefined;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Resolve encryption key from --key-file or --vault-passphrase / GIT_CAS_PASSPHRASE.
|
|
126
|
-
*
|
|
127
|
-
* @param {ContentAddressableStore} cas
|
|
128
|
-
* @param {Record<string, any>} opts
|
|
129
|
-
* @returns {Promise<Buffer | undefined>}
|
|
130
|
-
*/
|
|
131
|
-
async function resolveEncryptionKey(cas, opts) {
|
|
132
|
-
if (opts.keyFile) {
|
|
133
|
-
return readKeyFile(opts.keyFile);
|
|
134
|
-
}
|
|
135
|
-
const metadata = await cas.getVaultMetadata();
|
|
136
|
-
if (!metadata?.encryption) {
|
|
137
|
-
if (hasPassphraseSource(opts)) {
|
|
138
|
-
process.stderr.write('warning: passphrase ignored (vault is not encrypted)\n');
|
|
139
|
-
}
|
|
140
|
-
return undefined;
|
|
141
|
-
}
|
|
142
|
-
const passphrase = await resolvePassphrase(opts);
|
|
143
|
-
if (!passphrase) {
|
|
144
|
-
return undefined;
|
|
145
|
-
}
|
|
146
|
-
return deriveVaultKey(cas, metadata, passphrase);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
81
|
/**
|
|
150
82
|
* Validate --slug / --oid flags (exactly one required).
|
|
151
83
|
*
|
|
@@ -158,6 +90,17 @@ function validateRestoreFlags(opts) {
|
|
|
158
90
|
if (!opts.slug && !opts.oid) {
|
|
159
91
|
throw new Error('Provide --slug <slug> or --oid <tree-oid>');
|
|
160
92
|
}
|
|
93
|
+
if (opts.slug) {
|
|
94
|
+
Slug.validate(opts.slug);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @param {string} slug
|
|
100
|
+
* @returns {string}
|
|
101
|
+
*/
|
|
102
|
+
function normalizeSlug(slug) {
|
|
103
|
+
return Slug.from(slug).toString();
|
|
161
104
|
}
|
|
162
105
|
|
|
163
106
|
// ---------------------------------------------------------------------------
|
|
@@ -168,8 +111,9 @@ function validateRestoreFlags(opts) {
|
|
|
168
111
|
* @typedef {Object} StoreFileOpts
|
|
169
112
|
* @property {string} filePath - Path to the file to store.
|
|
170
113
|
* @property {string} slug - Asset slug identifier.
|
|
171
|
-
* @property {
|
|
172
|
-
* @property {
|
|
114
|
+
* @property {Uint8Array} [encryptionKey] - 32-byte AES-256-GCM key.
|
|
115
|
+
* @property {Uint8Array} [vaultEncryptionKey] - Vault key derived from a vault passphrase source.
|
|
116
|
+
* @property {Array<{ label: string, key: Uint8Array }>} [recipients] - Envelope recipients.
|
|
173
117
|
*/
|
|
174
118
|
|
|
175
119
|
/**
|
|
@@ -182,12 +126,17 @@ function validateRestoreFlags(opts) {
|
|
|
182
126
|
*/
|
|
183
127
|
async function buildStoreOpts(cas, file, opts) {
|
|
184
128
|
/** @type {StoreFileOpts} */
|
|
185
|
-
const storeOpts = { filePath: file, slug: opts.slug };
|
|
129
|
+
const storeOpts = { filePath: file, slug: Slug.from(opts.slug).toString() };
|
|
186
130
|
if (opts.recipient) {
|
|
187
131
|
storeOpts.recipients = opts.recipient;
|
|
188
132
|
} else {
|
|
189
133
|
const encryptionKey = await resolveEncryptionKey(cas, opts);
|
|
190
|
-
if (encryptionKey) {
|
|
134
|
+
if (encryptionKey) {
|
|
135
|
+
storeOpts.encryptionKey = encryptionKey;
|
|
136
|
+
if (!opts.keyFile) {
|
|
137
|
+
storeOpts.vaultEncryptionKey = encryptionKey;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
191
140
|
}
|
|
192
141
|
return storeOpts;
|
|
193
142
|
}
|
|
@@ -197,8 +146,8 @@ async function buildStoreOpts(cas, file, opts) {
|
|
|
197
146
|
* Format: label:keyfile
|
|
198
147
|
*
|
|
199
148
|
* @param {string} value
|
|
200
|
-
* @param {Array<{ label: string, key:
|
|
201
|
-
* @returns {Array<{ label: string, key:
|
|
149
|
+
* @param {Array<{ label: string, key: Uint8Array }>} [previous]
|
|
150
|
+
* @returns {Array<{ label: string, key: Uint8Array }>}
|
|
202
151
|
*/
|
|
203
152
|
function parseRecipient(value, previous) {
|
|
204
153
|
const sep = value.indexOf(':');
|
|
@@ -218,12 +167,21 @@ function parseRecipient(value, previous) {
|
|
|
218
167
|
|
|
219
168
|
/** @param {string} v */
|
|
220
169
|
const parseIntFlag = (v) => {
|
|
221
|
-
if (!/^-?\d+$/.test(v)) {
|
|
170
|
+
if (!/^-?\d+$/.test(v)) {
|
|
171
|
+
throw new Error(`Expected an integer, got "${v}"`);
|
|
172
|
+
}
|
|
222
173
|
const n = Number(v);
|
|
223
|
-
if (!Number.isSafeInteger(n)) {
|
|
174
|
+
if (!Number.isSafeInteger(n)) {
|
|
175
|
+
throw new Error(`Expected a safe integer, got "${v}"`);
|
|
176
|
+
}
|
|
224
177
|
return n;
|
|
225
178
|
};
|
|
226
179
|
|
|
180
|
+
/** @param {boolean} json */
|
|
181
|
+
function shouldSuppressProgress(json) {
|
|
182
|
+
return Boolean(program.opts().quiet || json);
|
|
183
|
+
}
|
|
184
|
+
|
|
227
185
|
program
|
|
228
186
|
.command('store <file>')
|
|
229
187
|
.description('Store a file into Git CAS')
|
|
@@ -232,8 +190,19 @@ program
|
|
|
232
190
|
.option('--recipient <label:keyfile>', 'Envelope recipient (repeatable)', parseRecipient)
|
|
233
191
|
.option('--tree', 'Also create a Git tree and print its OID')
|
|
234
192
|
.option('--force', 'Overwrite existing vault entry')
|
|
235
|
-
.option(
|
|
193
|
+
.option(
|
|
194
|
+
'--vault-passphrase <pass>',
|
|
195
|
+
'Vault-level passphrase for encryption (warns; prefer --vault-passphrase-file -, GIT_CAS_PASSPHRASE, or --os-keychain-target)'
|
|
196
|
+
)
|
|
236
197
|
.option('--vault-passphrase-file <path>', 'Read vault passphrase from file (use - for stdin)')
|
|
198
|
+
.option(
|
|
199
|
+
'--os-keychain-target <target>',
|
|
200
|
+
'Read vault passphrase from OS keychain target via @git-stunts/vault'
|
|
201
|
+
)
|
|
202
|
+
.option(
|
|
203
|
+
'--os-keychain-account <account>',
|
|
204
|
+
'OS keychain account namespace for --os-keychain-target (default: git-cas)'
|
|
205
|
+
)
|
|
237
206
|
.option('--gzip', 'Enable gzip compression')
|
|
238
207
|
.addOption(new Option('--strategy <type>', 'Chunking strategy').choices(['fixed', 'cdc']))
|
|
239
208
|
.option('--chunk-size <n>', 'Chunk size in bytes', parseIntFlag)
|
|
@@ -244,37 +213,54 @@ program
|
|
|
244
213
|
.option('--max-chunk-size <n>', 'CDC maximum chunk size', parseIntFlag)
|
|
245
214
|
.option('--merkle-threshold <n>', 'Chunk count threshold for Merkle sub-manifests', parseIntFlag)
|
|
246
215
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
247
|
-
.action(
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
216
|
+
.action(
|
|
217
|
+
runAction(async (/** @type {string} */ file, /** @type {Record<string, any>} */ opts) => {
|
|
218
|
+
warnInlinePassphraseArgs(opts);
|
|
219
|
+
validateCredentialSources(opts);
|
|
220
|
+
if (opts.recipient && (opts.keyFile || hasExplicitPassphraseSource(opts))) {
|
|
221
|
+
throw new Error(
|
|
222
|
+
'Provide --key-file or a vault passphrase source (--vault-passphrase, --vault-passphrase-file, --os-keychain-target, GIT_CAS_PASSPHRASE), or --recipient — not both'
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
if (opts.force && !opts.tree) {
|
|
226
|
+
throw new Error('--force requires --tree');
|
|
227
|
+
}
|
|
228
|
+
const json = program.opts().json;
|
|
229
|
+
const quiet = shouldSuppressProgress(json);
|
|
230
|
+
const observer = new EventEmitterObserver();
|
|
231
|
+
|
|
232
|
+
const config = loadConfig(opts.cwd);
|
|
233
|
+
const { casConfig, storeExtras } = mergeConfig(opts, config);
|
|
234
|
+
const cas = await createCas(opts.cwd, { observability: observer, ...casConfig });
|
|
235
|
+
|
|
236
|
+
const storeOpts = await buildStoreOpts(cas, file, opts);
|
|
237
|
+
Object.assign(storeOpts, storeExtras);
|
|
238
|
+
const progress = createStoreProgress({ filePath: file, chunkSize: cas.chunkSize, quiet });
|
|
239
|
+
progress.attach(observer);
|
|
240
|
+
let manifest;
|
|
241
|
+
try {
|
|
242
|
+
manifest = await cas.storeFile(storeOpts);
|
|
243
|
+
} finally {
|
|
244
|
+
progress.detach();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (opts.tree) {
|
|
248
|
+
const treeOid = await cas.createTree({ manifest });
|
|
249
|
+
await cas.addToVault({
|
|
250
|
+
slug: storeOpts.slug,
|
|
251
|
+
treeOid,
|
|
252
|
+
force: !!opts.force,
|
|
253
|
+
...(storeOpts.vaultEncryptionKey ? { encryptionKey: storeOpts.vaultEncryptionKey } : {}),
|
|
254
|
+
});
|
|
255
|
+
process.stdout.write(json ? `${JSON.stringify({ treeOid })}\n` : `${treeOid}\n`);
|
|
256
|
+
} else {
|
|
257
|
+
const output = json
|
|
258
|
+
? JSON.stringify({ manifest: manifest.toJSON() })
|
|
259
|
+
: JSON.stringify(manifest.toJSON(), null, 2);
|
|
260
|
+
process.stdout.write(`${output}\n`);
|
|
261
|
+
}
|
|
262
|
+
}, getJson)
|
|
263
|
+
);
|
|
278
264
|
|
|
279
265
|
// ---------------------------------------------------------------------------
|
|
280
266
|
// tree
|
|
@@ -284,18 +270,20 @@ program
|
|
|
284
270
|
.description('Create a Git tree from a manifest')
|
|
285
271
|
.requiredOption('--manifest <path>', 'Path to manifest JSON file')
|
|
286
272
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
287
|
-
.action(
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
273
|
+
.action(
|
|
274
|
+
runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
275
|
+
const cas = await createCas(opts.cwd);
|
|
276
|
+
const raw = readFileSync(opts.manifest, 'utf8');
|
|
277
|
+
const manifest = new Manifest(JSON.parse(raw));
|
|
278
|
+
const treeOid = await cas.createTree({ manifest });
|
|
279
|
+
const json = program.opts().json;
|
|
280
|
+
if (json) {
|
|
281
|
+
process.stdout.write(`${JSON.stringify({ treeOid })}\n`);
|
|
282
|
+
} else {
|
|
283
|
+
process.stdout.write(`${treeOid}\n`);
|
|
284
|
+
}
|
|
285
|
+
}, getJson)
|
|
286
|
+
);
|
|
299
287
|
|
|
300
288
|
// ---------------------------------------------------------------------------
|
|
301
289
|
// inspect
|
|
@@ -307,23 +295,25 @@ program
|
|
|
307
295
|
.option('--oid <tree-oid>', 'Direct tree OID')
|
|
308
296
|
.option('--heatmap', 'Show chunk heatmap visualization')
|
|
309
297
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
310
|
-
.action(
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
process.stdout.
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
298
|
+
.action(
|
|
299
|
+
runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
300
|
+
validateRestoreFlags(opts);
|
|
301
|
+
const cas = await createCas(opts.cwd);
|
|
302
|
+
const treeOid = opts.oid || (await cas.resolveVaultEntry({ slug: opts.slug }));
|
|
303
|
+
const manifest = await cas.readManifest({ treeOid });
|
|
304
|
+
const json = program.opts().json;
|
|
305
|
+
|
|
306
|
+
if (json) {
|
|
307
|
+
process.stdout.write(`${JSON.stringify(manifest.toJSON())}\n`);
|
|
308
|
+
} else if (opts.heatmap) {
|
|
309
|
+
process.stdout.write(renderHeatmap({ manifest: manifest.toJSON() }));
|
|
310
|
+
} else if (process.stdout.isTTY) {
|
|
311
|
+
process.stdout.write(renderManifestView({ manifest: manifest.toJSON() }));
|
|
312
|
+
} else {
|
|
313
|
+
process.stdout.write(`${JSON.stringify(manifest.toJSON(), null, 2)}\n`);
|
|
314
|
+
}
|
|
315
|
+
}, getJson)
|
|
316
|
+
);
|
|
327
317
|
|
|
328
318
|
// ---------------------------------------------------------------------------
|
|
329
319
|
// restore
|
|
@@ -335,51 +325,77 @@ program
|
|
|
335
325
|
.option('--slug <slug>', 'Resolve tree OID from vault slug')
|
|
336
326
|
.option('--oid <tree-oid>', 'Direct tree OID')
|
|
337
327
|
.option('--key-file <path>', 'Path to 32-byte raw encryption key file')
|
|
338
|
-
.option(
|
|
328
|
+
.option(
|
|
329
|
+
'--vault-passphrase <pass>',
|
|
330
|
+
'Vault-level passphrase for decryption (warns; prefer --vault-passphrase-file -, GIT_CAS_PASSPHRASE, or --os-keychain-target)'
|
|
331
|
+
)
|
|
339
332
|
.option('--vault-passphrase-file <path>', 'Read vault passphrase from file (use - for stdin)')
|
|
333
|
+
.option(
|
|
334
|
+
'--os-keychain-target <target>',
|
|
335
|
+
'Read vault passphrase from OS keychain target via @git-stunts/vault'
|
|
336
|
+
)
|
|
337
|
+
.option(
|
|
338
|
+
'--os-keychain-account <account>',
|
|
339
|
+
'OS keychain account namespace for --os-keychain-target (default: git-cas)'
|
|
340
|
+
)
|
|
340
341
|
.option('--concurrency <n>', 'Parallel chunk I/O operations', parseIntFlag)
|
|
341
|
-
.option(
|
|
342
|
+
.option(
|
|
343
|
+
'--max-restore-buffer <n>',
|
|
344
|
+
'Max bytes for buffered encrypted/compressed restore',
|
|
345
|
+
parseIntFlag
|
|
346
|
+
)
|
|
342
347
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
343
|
-
.action(
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
348
|
+
.action(
|
|
349
|
+
runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
350
|
+
warnInlinePassphraseArgs(opts);
|
|
351
|
+
validateCredentialSources(opts);
|
|
352
|
+
validateRestoreFlags(opts);
|
|
353
|
+
const quiet = program.opts().quiet || program.opts().json;
|
|
354
|
+
const observer = new EventEmitterObserver();
|
|
355
|
+
|
|
356
|
+
const config = loadConfig(opts.cwd);
|
|
357
|
+
/** @type {Record<string, any>} */
|
|
358
|
+
const casConfig = {};
|
|
359
|
+
const concurrency = opts.concurrency ?? config.concurrency;
|
|
360
|
+
const maxRestoreBufferSize = opts.maxRestoreBuffer ?? config.maxRestoreBufferSize;
|
|
361
|
+
if (concurrency !== undefined) {
|
|
362
|
+
casConfig.concurrency = concurrency;
|
|
363
|
+
}
|
|
364
|
+
if (maxRestoreBufferSize !== undefined) {
|
|
365
|
+
casConfig.maxRestoreBufferSize = maxRestoreBufferSize;
|
|
366
|
+
}
|
|
361
367
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
manifest,
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
368
|
+
const cas = await createCas(opts.cwd, { observability: observer, ...casConfig });
|
|
369
|
+
const treeOid = opts.oid || (await cas.resolveVaultEntry({ slug: opts.slug }));
|
|
370
|
+
const manifest = await cas.readManifest({ treeOid });
|
|
371
|
+
|
|
372
|
+
const encryptionKey = await resolveEncryptionKey(cas, opts);
|
|
373
|
+
|
|
374
|
+
const progress = createRestoreProgress({
|
|
375
|
+
totalChunks: manifest.chunks.length,
|
|
376
|
+
quiet,
|
|
377
|
+
});
|
|
378
|
+
progress.attach(observer);
|
|
379
|
+
let bytesWritten;
|
|
380
|
+
const restoreTarget = resolveRestoreOutputTarget(opts.out);
|
|
381
|
+
try {
|
|
382
|
+
({ bytesWritten } = await cas.restoreFile({
|
|
383
|
+
manifest,
|
|
384
|
+
...(encryptionKey ? { encryptionKey } : {}),
|
|
385
|
+
outputPath: restoreTarget.outputPath,
|
|
386
|
+
baseDirectory: restoreTarget.baseDirectory,
|
|
387
|
+
}));
|
|
388
|
+
} finally {
|
|
389
|
+
progress.detach();
|
|
390
|
+
}
|
|
391
|
+
const json = program.opts().json;
|
|
392
|
+
if (json) {
|
|
393
|
+
process.stdout.write(`${JSON.stringify({ bytesWritten })}\n`);
|
|
394
|
+
} else {
|
|
395
|
+
process.stdout.write(`${bytesWritten}\n`);
|
|
396
|
+
}
|
|
397
|
+
}, getJson)
|
|
398
|
+
);
|
|
383
399
|
|
|
384
400
|
// ---------------------------------------------------------------------------
|
|
385
401
|
// verify
|
|
@@ -390,54 +406,121 @@ program
|
|
|
390
406
|
.option('--slug <slug>', 'Resolve tree OID from vault slug')
|
|
391
407
|
.option('--oid <tree-oid>', 'Direct tree OID')
|
|
392
408
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
393
|
-
.action(
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
+
.action(
|
|
410
|
+
runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
411
|
+
validateRestoreFlags(opts);
|
|
412
|
+
const cas = await createCas(opts.cwd);
|
|
413
|
+
const treeOid = opts.oid || (await cas.resolveVaultEntry({ slug: opts.slug }));
|
|
414
|
+
const manifest = await cas.readManifest({ treeOid });
|
|
415
|
+
const ok = await cas.verifyIntegrity(manifest);
|
|
416
|
+
const json = program.opts().json;
|
|
417
|
+
if (json) {
|
|
418
|
+
process.stdout.write(
|
|
419
|
+
`${JSON.stringify({ ok, slug: manifest.slug, chunks: manifest.chunks.length })}\n`
|
|
420
|
+
);
|
|
421
|
+
} else {
|
|
422
|
+
process.stdout.write(ok ? 'ok\n' : `fail: ${manifest.slug}\n`);
|
|
423
|
+
}
|
|
424
|
+
if (!ok) {
|
|
425
|
+
process.exitCode = 1;
|
|
426
|
+
}
|
|
427
|
+
}, getJson)
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
// ---------------------------------------------------------------------------
|
|
431
|
+
// doctor
|
|
432
|
+
// ---------------------------------------------------------------------------
|
|
433
|
+
program
|
|
434
|
+
.command('doctor')
|
|
435
|
+
.description('Inspect vault health and surface integrity issues')
|
|
436
|
+
.option('--cwd <dir>', 'Git working directory', '.')
|
|
437
|
+
.option('--key-file <path>', 'Read raw 32-byte vault encryption key from file')
|
|
438
|
+
.option(
|
|
439
|
+
'--vault-passphrase <pass>',
|
|
440
|
+
'Vault-level passphrase for privacy vault diagnostics (warns; prefer --vault-passphrase-file -, GIT_CAS_PASSPHRASE, or --os-keychain-target)'
|
|
441
|
+
)
|
|
442
|
+
.option('--vault-passphrase-file <path>', 'Read vault passphrase from file (use - for stdin)')
|
|
443
|
+
.option(
|
|
444
|
+
'--os-keychain-target <target>',
|
|
445
|
+
'Read vault passphrase from OS keychain target via @git-stunts/vault'
|
|
446
|
+
)
|
|
447
|
+
.option(
|
|
448
|
+
'--os-keychain-account <account>',
|
|
449
|
+
'OS keychain account namespace for --os-keychain-target (default: git-cas)'
|
|
450
|
+
)
|
|
451
|
+
.action(
|
|
452
|
+
runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
453
|
+
warnInlinePassphraseArgs(opts);
|
|
454
|
+
validateCredentialSources(opts);
|
|
455
|
+
const cas = await createCas(opts.cwd);
|
|
456
|
+
const encryptionKey = await resolveEncryptionKey(cas, opts);
|
|
457
|
+
const report = await inspectVaultHealth(cas, { encryptionKey });
|
|
458
|
+
const json = program.opts().json;
|
|
459
|
+
|
|
460
|
+
if (json) {
|
|
461
|
+
process.stdout.write(`${JSON.stringify(report)}\n`);
|
|
462
|
+
} else {
|
|
463
|
+
const ctx = getCliContext();
|
|
464
|
+
process.stdout.write(`${renderHealthDashboard(report, ctx)}\n`);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
if (report.status !== 'ok') {
|
|
468
|
+
process.exitCode = 1;
|
|
469
|
+
}
|
|
470
|
+
}, getJson)
|
|
471
|
+
);
|
|
409
472
|
|
|
410
473
|
// ---------------------------------------------------------------------------
|
|
411
474
|
// vault init
|
|
412
475
|
// ---------------------------------------------------------------------------
|
|
413
|
-
const vault = program
|
|
414
|
-
.command('vault')
|
|
415
|
-
.description('Manage the CAS vault');
|
|
476
|
+
const vault = program.command('vault').description('Manage the CAS vault');
|
|
416
477
|
|
|
417
478
|
vault
|
|
418
479
|
.command('init')
|
|
419
480
|
.description('Initialize the vault')
|
|
420
|
-
.option(
|
|
481
|
+
.option(
|
|
482
|
+
'--vault-passphrase <pass>',
|
|
483
|
+
'Passphrase for vault-level encryption (warns; prefer --vault-passphrase-file -, GIT_CAS_PASSPHRASE, or --os-keychain-target)'
|
|
484
|
+
)
|
|
421
485
|
.option('--vault-passphrase-file <path>', 'Read vault passphrase from file (use - for stdin)')
|
|
422
|
-
.
|
|
486
|
+
.option(
|
|
487
|
+
'--os-keychain-target <target>',
|
|
488
|
+
'Read vault passphrase from OS keychain target via @git-stunts/vault'
|
|
489
|
+
)
|
|
490
|
+
.option(
|
|
491
|
+
'--os-keychain-account <account>',
|
|
492
|
+
'OS keychain account namespace for --os-keychain-target (default: git-cas)'
|
|
493
|
+
)
|
|
494
|
+
.addOption(new Option('--algorithm <alg>', 'KDF algorithm').choices(['pbkdf2', 'scrypt']))
|
|
423
495
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
424
|
-
.action(
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
initOpts
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
496
|
+
.action(
|
|
497
|
+
runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
498
|
+
warnInlinePassphraseArgs(opts);
|
|
499
|
+
validateCredentialSources(opts);
|
|
500
|
+
const cas = await createCas(opts.cwd);
|
|
501
|
+
/** @type {{ passphrase?: string, kdfOptions?: { algorithm: 'pbkdf2' | 'scrypt' } }} */
|
|
502
|
+
const initOpts = {};
|
|
503
|
+
const passphrase = await resolvePassphrase(opts, { confirm: true });
|
|
504
|
+
if (!passphrase && opts.algorithm !== undefined) {
|
|
505
|
+
throw new Error(
|
|
506
|
+
'Provide --vault-passphrase, --vault-passphrase-file, or --os-keychain-target when using --algorithm'
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
if (passphrase) {
|
|
510
|
+
initOpts.passphrase = passphrase;
|
|
511
|
+
initOpts.kdfOptions = {
|
|
512
|
+
algorithm: /** @type {'pbkdf2' | 'scrypt'} */ (opts.algorithm || 'pbkdf2'),
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
const { commitOid } = await cas.initVault(initOpts);
|
|
516
|
+
const json = program.opts().json;
|
|
517
|
+
if (json) {
|
|
518
|
+
process.stdout.write(`${JSON.stringify({ commitOid })}\n`);
|
|
519
|
+
} else {
|
|
520
|
+
process.stdout.write(`${commitOid}\n`);
|
|
521
|
+
}
|
|
522
|
+
}, getJson)
|
|
523
|
+
);
|
|
441
524
|
|
|
442
525
|
// ---------------------------------------------------------------------------
|
|
443
526
|
// vault list
|
|
@@ -447,19 +530,49 @@ vault
|
|
|
447
530
|
.description('List vault entries')
|
|
448
531
|
.option('--filter <pattern>', 'Filter entries by glob pattern')
|
|
449
532
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
450
|
-
.action(
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
process.stdout.
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
533
|
+
.action(
|
|
534
|
+
runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
535
|
+
const cas = await createCas(opts.cwd);
|
|
536
|
+
const all = await cas.listVault();
|
|
537
|
+
const entries = filterEntries(all, opts.filter);
|
|
538
|
+
const json = program.opts().json;
|
|
539
|
+
if (json) {
|
|
540
|
+
process.stdout.write(`${JSON.stringify(entries)}\n`);
|
|
541
|
+
} else if (process.stdout.isTTY) {
|
|
542
|
+
process.stdout.write(formatTable(entries));
|
|
543
|
+
} else {
|
|
544
|
+
process.stdout.write(formatTabSeparated(entries));
|
|
545
|
+
}
|
|
546
|
+
}, getJson)
|
|
547
|
+
);
|
|
548
|
+
|
|
549
|
+
// ---------------------------------------------------------------------------
|
|
550
|
+
// vault stats
|
|
551
|
+
// ---------------------------------------------------------------------------
|
|
552
|
+
vault
|
|
553
|
+
.command('stats')
|
|
554
|
+
.description('Summarize vault size, dedupe, and encryption coverage')
|
|
555
|
+
.option('--filter <pattern>', 'Filter entries by glob pattern')
|
|
556
|
+
.option('--cwd <dir>', 'Git working directory', '.')
|
|
557
|
+
.action(
|
|
558
|
+
runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
559
|
+
const cas = await createCas(opts.cwd);
|
|
560
|
+
const all = await cas.listVault();
|
|
561
|
+
const entries = filterEntries(all, opts.filter);
|
|
562
|
+
const records = [];
|
|
563
|
+
for (const entry of entries) {
|
|
564
|
+
const manifest = await cas.readManifest({ treeOid: entry.treeOid });
|
|
565
|
+
records.push({ ...entry, manifest });
|
|
566
|
+
}
|
|
567
|
+
const stats = buildVaultStats(records);
|
|
568
|
+
const json = program.opts().json;
|
|
569
|
+
if (json) {
|
|
570
|
+
process.stdout.write(`${JSON.stringify(stats)}\n`);
|
|
571
|
+
} else {
|
|
572
|
+
process.stdout.write(renderVaultStats(stats));
|
|
573
|
+
}
|
|
574
|
+
}, getJson)
|
|
575
|
+
);
|
|
463
576
|
|
|
464
577
|
// ---------------------------------------------------------------------------
|
|
465
578
|
// vault remove
|
|
@@ -468,16 +581,19 @@ vault
|
|
|
468
581
|
.command('remove <slug>')
|
|
469
582
|
.description('Remove an entry from the vault')
|
|
470
583
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
471
|
-
.action(
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
584
|
+
.action(
|
|
585
|
+
runAction(async (/** @type {string} */ slug, /** @type {Record<string, any>} */ opts) => {
|
|
586
|
+
const cas = await createCas(opts.cwd);
|
|
587
|
+
const vaultSlug = normalizeSlug(slug);
|
|
588
|
+
const { commitOid, removedTreeOid } = await cas.removeFromVault({ slug: vaultSlug });
|
|
589
|
+
const json = program.opts().json;
|
|
590
|
+
if (json) {
|
|
591
|
+
process.stdout.write(`${JSON.stringify({ commitOid, removedTreeOid })}\n`);
|
|
592
|
+
} else {
|
|
593
|
+
process.stdout.write(`${removedTreeOid}\n`);
|
|
594
|
+
}
|
|
595
|
+
}, getJson)
|
|
596
|
+
);
|
|
481
597
|
|
|
482
598
|
// ---------------------------------------------------------------------------
|
|
483
599
|
// vault info
|
|
@@ -487,29 +603,32 @@ vault
|
|
|
487
603
|
.description('Show info for a vault entry')
|
|
488
604
|
.option('--encryption', 'Show vault encryption details')
|
|
489
605
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
490
|
-
.action(
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
const
|
|
499
|
-
if (
|
|
500
|
-
|
|
606
|
+
.action(
|
|
607
|
+
runAction(async (/** @type {string} */ slug, /** @type {Record<string, any>} */ opts) => {
|
|
608
|
+
const cas = await createCas(opts.cwd);
|
|
609
|
+
const vaultSlug = normalizeSlug(slug);
|
|
610
|
+
const treeOid = await cas.resolveVaultEntry({ slug: vaultSlug });
|
|
611
|
+
const json = program.opts().json;
|
|
612
|
+
if (json) {
|
|
613
|
+
/** @type {Record<string, any>} */
|
|
614
|
+
const result = { slug: vaultSlug, treeOid };
|
|
615
|
+
if (opts.encryption) {
|
|
616
|
+
const metadata = await cas.getVaultMetadata();
|
|
617
|
+
if (metadata?.encryption) {
|
|
618
|
+
result.encryption = metadata.encryption;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
622
|
+
} else {
|
|
623
|
+
process.stdout.write(`slug\t${vaultSlug}\n`);
|
|
624
|
+
process.stdout.write(`tree\t${treeOid}\n`);
|
|
625
|
+
if (opts.encryption) {
|
|
626
|
+
const metadata = await cas.getVaultMetadata();
|
|
627
|
+
process.stdout.write(`\n${surfaceToString(renderEncryptionCard({ metadata }), getCliContext().style)}\n`);
|
|
501
628
|
}
|
|
502
629
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
process.stdout.write(`slug\t${slug}\n`);
|
|
506
|
-
process.stdout.write(`tree\t${treeOid}\n`);
|
|
507
|
-
if (opts.encryption) {
|
|
508
|
-
const metadata = await cas.getVaultMetadata();
|
|
509
|
-
process.stdout.write(`\n${renderEncryptionCard({ metadata })}\n`);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
}, getJson));
|
|
630
|
+
}, getJson)
|
|
631
|
+
);
|
|
513
632
|
|
|
514
633
|
// ---------------------------------------------------------------------------
|
|
515
634
|
// vault history
|
|
@@ -520,34 +639,35 @@ vault
|
|
|
520
639
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
521
640
|
.option('-n, --max-count <n>', 'Limit number of commits')
|
|
522
641
|
.option('--pretty', 'Render as color-coded timeline')
|
|
523
|
-
.action(
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
642
|
+
.action(
|
|
643
|
+
runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
644
|
+
const plumbing = await createGitPlumbing({ cwd: opts.cwd || '.' });
|
|
645
|
+
const args = ['log', '--oneline', ContentAddressableStore.VAULT_REF];
|
|
646
|
+
if (opts.maxCount) {
|
|
647
|
+
const n = parseInt(opts.maxCount, 10);
|
|
648
|
+
if (Number.isNaN(n) || n <= 0) {
|
|
649
|
+
throw new Error('--max-count must be a positive integer');
|
|
650
|
+
}
|
|
651
|
+
args.push(`-${n}`);
|
|
652
|
+
}
|
|
653
|
+
const output = await plumbing.execute({ args });
|
|
654
|
+
const json = program.opts().json;
|
|
655
|
+
if (json) {
|
|
656
|
+
const history = output
|
|
657
|
+
.split('\n')
|
|
658
|
+
.filter(Boolean)
|
|
659
|
+
.map((/** @type {string} */ line) => {
|
|
660
|
+
const [commitOid, ...messageParts] = line.trim().split(/\s+/);
|
|
661
|
+
return { commitOid, message: messageParts.join(' ') };
|
|
662
|
+
});
|
|
663
|
+
process.stdout.write(`${JSON.stringify(history)}\n`);
|
|
664
|
+
} else if (opts.pretty && process.stdout.isTTY) {
|
|
665
|
+
process.stdout.write(`${renderHistoryTimeline(output)}\n`);
|
|
666
|
+
} else {
|
|
667
|
+
process.stdout.write(`${output}\n`);
|
|
668
|
+
}
|
|
669
|
+
}, getJson)
|
|
670
|
+
);
|
|
551
671
|
|
|
552
672
|
// ---------------------------------------------------------------------------
|
|
553
673
|
// vault rotate
|
|
@@ -568,58 +688,80 @@ async function resolveRotatePassphrases(opts) {
|
|
|
568
688
|
const newPassphrase = opts.newPassphraseFile
|
|
569
689
|
? await readPassphraseFile(opts.newPassphraseFile)
|
|
570
690
|
: opts.newPassphrase;
|
|
571
|
-
if (!oldPassphrase
|
|
572
|
-
|
|
691
|
+
if (!oldPassphrase || !oldPassphrase.trim()) {
|
|
692
|
+
throw new Error('Old passphrase required (--old-passphrase or --old-passphrase-file)');
|
|
693
|
+
}
|
|
694
|
+
if (!newPassphrase || !newPassphrase.trim()) {
|
|
695
|
+
throw new Error('New passphrase required (--new-passphrase or --new-passphrase-file)');
|
|
696
|
+
}
|
|
573
697
|
return { oldPassphrase, newPassphrase };
|
|
574
698
|
}
|
|
575
699
|
|
|
576
700
|
vault
|
|
577
701
|
.command('rotate')
|
|
578
702
|
.description('Rotate vault-level encryption passphrase')
|
|
579
|
-
.option('--old-passphrase <pass>', 'Current vault passphrase')
|
|
580
|
-
.option('--new-passphrase <pass>', 'New vault passphrase')
|
|
703
|
+
.option('--old-passphrase <pass>', 'Current vault passphrase (warns; prefer --old-passphrase-file -)')
|
|
704
|
+
.option('--new-passphrase <pass>', 'New vault passphrase (warns; prefer --new-passphrase-file -)')
|
|
581
705
|
.option('--old-passphrase-file <path>', 'Read old passphrase from file (- for stdin)')
|
|
582
706
|
.option('--new-passphrase-file <path>', 'Read new passphrase from file (- for stdin)')
|
|
583
707
|
.addOption(new Option('--algorithm <alg>', 'KDF algorithm').choices(['pbkdf2', 'scrypt']))
|
|
584
708
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
585
|
-
.action(
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
oldPassphrase,
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
const json = program.opts().json;
|
|
598
|
-
if (json) {
|
|
599
|
-
process.stdout.write(`${JSON.stringify({ commitOid, rotatedSlugs, skippedSlugs })}\n`);
|
|
600
|
-
} else {
|
|
601
|
-
process.stdout.write(`${commitOid}\n`);
|
|
602
|
-
if (rotatedSlugs.length) {
|
|
603
|
-
process.stderr.write(`rotated: ${rotatedSlugs.join(', ')}\n`);
|
|
604
|
-
}
|
|
605
|
-
if (skippedSlugs.length) {
|
|
606
|
-
process.stderr.write(`skipped: ${skippedSlugs.join(', ')}\n`);
|
|
709
|
+
.action(
|
|
710
|
+
runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
711
|
+
warnInlinePassphraseArgs(opts);
|
|
712
|
+
const { oldPassphrase, newPassphrase } = await resolveRotatePassphrases(opts);
|
|
713
|
+
const cas = await createCas(opts.cwd);
|
|
714
|
+
/** @type {{ oldPassphrase: string, newPassphrase: string, kdfOptions?: { algorithm: 'pbkdf2' | 'scrypt' } }} */
|
|
715
|
+
const rotateOpts = {
|
|
716
|
+
oldPassphrase,
|
|
717
|
+
newPassphrase,
|
|
718
|
+
};
|
|
719
|
+
if (opts.algorithm) {
|
|
720
|
+
rotateOpts.kdfOptions = { algorithm: /** @type {'pbkdf2' | 'scrypt'} */ (opts.algorithm) };
|
|
607
721
|
}
|
|
608
|
-
|
|
609
|
-
|
|
722
|
+
const { commitOid, rotatedSlugs, skippedSlugs } = await cas.rotateVaultPassphrase(rotateOpts);
|
|
723
|
+
const json = program.opts().json;
|
|
724
|
+
if (json) {
|
|
725
|
+
process.stdout.write(`${JSON.stringify({ commitOid, rotatedSlugs, skippedSlugs })}\n`);
|
|
726
|
+
} else {
|
|
727
|
+
process.stdout.write(`${commitOid}\n`);
|
|
728
|
+
if (rotatedSlugs.length) {
|
|
729
|
+
process.stderr.write(`rotated: ${rotatedSlugs.join(', ')}\n`);
|
|
730
|
+
}
|
|
731
|
+
if (skippedSlugs.length) {
|
|
732
|
+
process.stderr.write(`skipped: ${skippedSlugs.join(', ')}\n`);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}, getJson)
|
|
736
|
+
);
|
|
610
737
|
|
|
611
738
|
// ---------------------------------------------------------------------------
|
|
612
739
|
// vault dashboard
|
|
613
740
|
// ---------------------------------------------------------------------------
|
|
614
741
|
vault
|
|
615
742
|
.command('dashboard')
|
|
616
|
-
.description('Interactive
|
|
743
|
+
.description('Interactive CAS explorer')
|
|
617
744
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
618
|
-
.
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
745
|
+
.option(
|
|
746
|
+
'--ref <gitRef>',
|
|
747
|
+
'Inspect a git ref that points to a CAS tree, CAS index blob, or commit with a manifest hint'
|
|
748
|
+
)
|
|
749
|
+
.option('--oid <treeOid>', 'Inspect a direct CAS tree OID')
|
|
750
|
+
.action(
|
|
751
|
+
runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
752
|
+
if (opts.ref && opts.oid) {
|
|
753
|
+
throw new Error('Choose either --ref or --oid, not both');
|
|
754
|
+
}
|
|
755
|
+
const cas = await createCas(opts.cwd);
|
|
756
|
+
const { launchDashboard } = await import('./ui/dashboard.js');
|
|
757
|
+
const source = opts.ref
|
|
758
|
+
? { type: 'ref', ref: opts.ref }
|
|
759
|
+
: opts.oid
|
|
760
|
+
? { type: 'oid', treeOid: opts.oid }
|
|
761
|
+
: { type: 'vault' };
|
|
762
|
+
await launchDashboard(cas, { cwd: path.resolve(opts.cwd), source });
|
|
763
|
+
}, getJson)
|
|
764
|
+
);
|
|
623
765
|
|
|
624
766
|
// ---------------------------------------------------------------------------
|
|
625
767
|
// rotate
|
|
@@ -633,43 +775,47 @@ program
|
|
|
633
775
|
.requiredOption('--new-key-file <path>', 'Path to new 32-byte key file')
|
|
634
776
|
.option('--label <label>', 'Rotate only the named recipient')
|
|
635
777
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
636
|
-
.action(
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
778
|
+
.action(
|
|
779
|
+
runAction(async (/** @type {Record<string, any>} */ opts) => {
|
|
780
|
+
validateRestoreFlags(opts);
|
|
781
|
+
const cas = await createCas(opts.cwd);
|
|
782
|
+
const treeOid = opts.oid || (await cas.resolveVaultEntry({ slug: opts.slug }));
|
|
783
|
+
const manifest = await cas.readManifest({ treeOid });
|
|
784
|
+
|
|
785
|
+
const oldKey = readKeyFile(opts.oldKeyFile);
|
|
786
|
+
const newKey = readKeyFile(opts.newKeyFile);
|
|
787
|
+
|
|
788
|
+
/** @type {{ manifest: Manifest, oldKey: Uint8Array, newKey: Uint8Array, label?: string }} */
|
|
789
|
+
const rotateOpts = { manifest, oldKey, newKey };
|
|
790
|
+
if (opts.label) {
|
|
791
|
+
rotateOpts.label = opts.label;
|
|
792
|
+
}
|
|
651
793
|
|
|
652
|
-
|
|
653
|
-
const
|
|
654
|
-
|
|
655
|
-
if (
|
|
656
|
-
|
|
794
|
+
const updated = await cas.rotateKey(rotateOpts);
|
|
795
|
+
const json = program.opts().json;
|
|
796
|
+
|
|
797
|
+
if (opts.slug) {
|
|
798
|
+
const newTreeOid = await cas.createTree({ manifest: updated });
|
|
799
|
+
await cas.addToVault({ slug: normalizeSlug(opts.slug), treeOid: newTreeOid, force: true });
|
|
800
|
+
if (json) {
|
|
801
|
+
process.stdout.write(
|
|
802
|
+
`${JSON.stringify({ treeOid: newTreeOid, keyVersion: updated.encryption?.keyVersion })}\n`
|
|
803
|
+
);
|
|
804
|
+
} else {
|
|
805
|
+
process.stdout.write(`${newTreeOid}\n`);
|
|
806
|
+
}
|
|
807
|
+
} else if (json) {
|
|
808
|
+
process.stdout.write(`${JSON.stringify(updated.toJSON())}\n`);
|
|
657
809
|
} else {
|
|
658
|
-
process.stdout.write(`${
|
|
810
|
+
process.stdout.write(`${JSON.stringify(updated.toJSON(), null, 2)}\n`);
|
|
659
811
|
}
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
} else {
|
|
663
|
-
process.stdout.write(`${JSON.stringify(updated.toJSON(), null, 2)}\n`);
|
|
664
|
-
}
|
|
665
|
-
}, getJson));
|
|
812
|
+
}, getJson)
|
|
813
|
+
);
|
|
666
814
|
|
|
667
815
|
// ---------------------------------------------------------------------------
|
|
668
816
|
// recipient add / remove / list
|
|
669
817
|
// ---------------------------------------------------------------------------
|
|
670
|
-
const recipient = program
|
|
671
|
-
.command('recipient')
|
|
672
|
-
.description('Manage envelope encryption recipients');
|
|
818
|
+
const recipient = program.command('recipient').description('Manage envelope encryption recipients');
|
|
673
819
|
|
|
674
820
|
recipient
|
|
675
821
|
.command('add <slug>')
|
|
@@ -678,78 +824,86 @@ recipient
|
|
|
678
824
|
.requiredOption('--key-file <path>', 'Path to 32-byte key file for the new recipient')
|
|
679
825
|
.requiredOption('--existing-key-file <path>', 'Path to key file of an existing recipient')
|
|
680
826
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
681
|
-
.action(
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
827
|
+
.action(
|
|
828
|
+
runAction(async (/** @type {string} */ slug, /** @type {Record<string, any>} */ opts) => {
|
|
829
|
+
const cas = await createCas(opts.cwd);
|
|
830
|
+
const vaultSlug = normalizeSlug(slug);
|
|
831
|
+
const treeOid = await cas.resolveVaultEntry({ slug: vaultSlug });
|
|
832
|
+
const manifest = await cas.readManifest({ treeOid });
|
|
833
|
+
|
|
834
|
+
const existingKey = readKeyFile(opts.existingKeyFile);
|
|
835
|
+
const newRecipientKey = readKeyFile(opts.keyFile);
|
|
836
|
+
|
|
837
|
+
const updated = await cas.addRecipient({
|
|
838
|
+
manifest,
|
|
839
|
+
existingKey,
|
|
840
|
+
newRecipientKey,
|
|
841
|
+
label: opts.label,
|
|
842
|
+
});
|
|
843
|
+
|
|
844
|
+
const newTreeOid = await cas.createTree({ manifest: updated });
|
|
845
|
+
await cas.addToVault({ slug: vaultSlug, treeOid: newTreeOid, force: true });
|
|
846
|
+
|
|
847
|
+
const json = program.opts().json;
|
|
848
|
+
if (json) {
|
|
849
|
+
process.stdout.write(`${JSON.stringify({ treeOid: newTreeOid })}\n`);
|
|
850
|
+
} else {
|
|
851
|
+
process.stdout.write(`${newTreeOid}\n`);
|
|
852
|
+
}
|
|
853
|
+
}, getJson)
|
|
854
|
+
);
|
|
706
855
|
|
|
707
856
|
recipient
|
|
708
857
|
.command('remove <slug>')
|
|
709
858
|
.description('Remove a recipient from an envelope-encrypted asset')
|
|
710
859
|
.requiredOption('--label <label>', 'Label of the recipient to remove')
|
|
711
860
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
712
|
-
.action(
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
861
|
+
.action(
|
|
862
|
+
runAction(async (/** @type {string} */ slug, /** @type {Record<string, any>} */ opts) => {
|
|
863
|
+
const cas = await createCas(opts.cwd);
|
|
864
|
+
const vaultSlug = normalizeSlug(slug);
|
|
865
|
+
const treeOid = await cas.resolveVaultEntry({ slug: vaultSlug });
|
|
866
|
+
const manifest = await cas.readManifest({ treeOid });
|
|
716
867
|
|
|
717
|
-
|
|
868
|
+
const updated = await cas.removeRecipient({ manifest, label: opts.label });
|
|
718
869
|
|
|
719
|
-
|
|
720
|
-
|
|
870
|
+
const newTreeOid = await cas.createTree({ manifest: updated });
|
|
871
|
+
await cas.addToVault({ slug: vaultSlug, treeOid: newTreeOid, force: true });
|
|
721
872
|
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
873
|
+
const json = program.opts().json;
|
|
874
|
+
if (json) {
|
|
875
|
+
process.stdout.write(`${JSON.stringify({ treeOid: newTreeOid })}\n`);
|
|
876
|
+
} else {
|
|
877
|
+
process.stdout.write(`${newTreeOid}\n`);
|
|
878
|
+
}
|
|
879
|
+
}, getJson)
|
|
880
|
+
);
|
|
729
881
|
|
|
730
882
|
recipient
|
|
731
883
|
.command('list <slug>')
|
|
732
884
|
.description('List recipients of an envelope-encrypted asset')
|
|
733
885
|
.option('--cwd <dir>', 'Git working directory', '.')
|
|
734
|
-
.action(
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
886
|
+
.action(
|
|
887
|
+
runAction(async (/** @type {string} */ slug, /** @type {Record<string, any>} */ opts) => {
|
|
888
|
+
const cas = await createCas(opts.cwd);
|
|
889
|
+
const vaultSlug = normalizeSlug(slug);
|
|
890
|
+
const treeOid = await cas.resolveVaultEntry({ slug: vaultSlug });
|
|
891
|
+
const manifest = await cas.readManifest({ treeOid });
|
|
892
|
+
|
|
893
|
+
const labels = await cas.listRecipients(manifest);
|
|
894
|
+
const json = program.opts().json;
|
|
895
|
+
if (json) {
|
|
896
|
+
process.stdout.write(`${JSON.stringify(labels)}\n`);
|
|
897
|
+
} else {
|
|
898
|
+
for (const label of labels) {
|
|
899
|
+
process.stdout.write(`${label}\n`);
|
|
900
|
+
}
|
|
746
901
|
}
|
|
747
|
-
}
|
|
748
|
-
|
|
902
|
+
}, getJson)
|
|
903
|
+
);
|
|
749
904
|
|
|
750
905
|
await program.parseAsync();
|
|
751
906
|
|
|
752
907
|
// Flush stdout/stderr before exiting — spawned git child processes leave
|
|
753
908
|
// libuv handles that prevent natural exit in containerized environments.
|
|
754
|
-
|
|
755
|
-
process.stdout.write('', () => process.stderr.write('', () => process.exit(code)));
|
|
909
|
+
await flushStdioAndExit();
|