@git-stunts/git-cas 6.0.0 → 6.1.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.
@@ -1,14 +1,19 @@
1
1
  /**
2
2
  * Interactive store wizard — guided flow for storing a file into git-cas.
3
3
  *
4
- * State machine with steps: filePath → slug → encryption → compression → chunking → confirm.
4
+ * State machine with steps: filePath → slug → encryption → passphrase → compression → chunking → confirm.
5
5
  * Renders within the TUI overlay system using the TEA architecture.
6
6
  * Delegates generic step handling and rendering to WizardBlock.
7
7
  */
8
8
 
9
9
  import {
10
- handleSelectKey, handleTextKey, handleToggleKey,
11
- renderFieldLine, renderSelectList, renderTextInput, renderToggle,
10
+ handleSelectKey,
11
+ handleTextKey,
12
+ handleToggleKey,
13
+ renderFieldLine,
14
+ renderSelectList,
15
+ renderTextInput,
16
+ renderToggle,
12
17
  renderWizardPanel,
13
18
  } from './blocks/wizard-block.js';
14
19
  import { themeText } from './theme.js';
@@ -19,7 +24,7 @@ import { themeText } from './theme.js';
19
24
  */
20
25
 
21
26
  /**
22
- * @typedef {'filePath' | 'slug' | 'encryption' | 'compression' | 'chunking' | 'confirm' | 'storing' | 'done' | 'error'} WizardStep
27
+ * @typedef {'filePath' | 'slug' | 'encryption' | 'passphrase' | 'compression' | 'chunking' | 'confirm' | 'storing' | 'done' | 'error'} WizardStep
23
28
  */
24
29
 
25
30
  /**
@@ -31,14 +36,14 @@ import { themeText } from './theme.js';
31
36
  * @property {string} passphrase
32
37
  * @property {boolean} passphraseVisible
33
38
  * @property {boolean} compression
34
- * @property {'whole' | 'fixed' | 'cdc'} chunking
39
+ * @property {'fixed' | 'cdc'} chunking
35
40
  * @property {number} selectIndex
36
41
  * @property {string | null} error
37
42
  * @property {string | null} resultSlug
38
43
  */
39
44
 
40
45
  const ENCRYPTION_OPTIONS = ['none', 'passphrase', 'convergent'];
41
- const CHUNKING_OPTIONS = ['whole', 'fixed', 'cdc'];
46
+ const CHUNKING_OPTIONS = ['fixed', 'cdc'];
42
47
 
43
48
  /**
44
49
  * Create a fresh wizard state.
@@ -82,7 +87,12 @@ function handleFilePathKey(state, key) {
82
87
  function handleSlugKey(state, key) {
83
88
  const result = handleTextKey(state.slug, key);
84
89
  if (result.confirmed) {
85
- return { ...state, slug: result.value, step: 'encryption', selectIndex: ENCRYPTION_OPTIONS.indexOf(state.encryption) };
90
+ return {
91
+ ...state,
92
+ slug: result.value,
93
+ step: 'encryption',
94
+ selectIndex: ENCRYPTION_OPTIONS.indexOf(state.encryption),
95
+ };
86
96
  }
87
97
  return { ...state, slug: result.value };
88
98
  }
@@ -95,12 +105,28 @@ function handleSlugKey(state, key) {
95
105
  function handleEncryptionKey(state, key) {
96
106
  const result = handleSelectKey(state.selectIndex, ENCRYPTION_OPTIONS.length, key);
97
107
  if (result.confirmed) {
98
- const encryption = /** @type {'none' | 'passphrase' | 'convergent'} */ (ENCRYPTION_OPTIONS[result.selectIndex]);
99
- return { ...state, encryption, selectIndex: 0, step: 'compression' };
108
+ const encryption = /** @type {'none' | 'passphrase' | 'convergent'} */ (
109
+ ENCRYPTION_OPTIONS[result.selectIndex]
110
+ );
111
+ const step = encryption === 'none' ? 'compression' : 'passphrase';
112
+ return { ...state, encryption, passphrase: '', selectIndex: 0, step };
100
113
  }
101
114
  return { ...state, selectIndex: result.selectIndex };
102
115
  }
103
116
 
117
+ /**
118
+ * @param {StoreWizardState} state
119
+ * @param {string} key
120
+ * @returns {StoreWizardState}
121
+ */
122
+ function handlePassphraseKey(state, key) {
123
+ const result = handleTextKey(state.passphrase, key);
124
+ if (result.confirmed) {
125
+ return { ...state, passphrase: result.value, step: 'compression' };
126
+ }
127
+ return { ...state, passphrase: result.value };
128
+ }
129
+
104
130
  /**
105
131
  * @param {StoreWizardState} state
106
132
  * @param {string} key
@@ -109,7 +135,12 @@ function handleEncryptionKey(state, key) {
109
135
  function handleCompressionKey(state, key) {
110
136
  const result = handleToggleKey(state.compression, key);
111
137
  if (result.confirmed) {
112
- return { ...state, compression: result.value, step: 'chunking', selectIndex: CHUNKING_OPTIONS.indexOf(state.chunking) };
138
+ return {
139
+ ...state,
140
+ compression: result.value,
141
+ step: 'chunking',
142
+ selectIndex: CHUNKING_OPTIONS.indexOf(state.chunking),
143
+ };
113
144
  }
114
145
  return { ...state, compression: result.value };
115
146
  }
@@ -122,7 +153,7 @@ function handleCompressionKey(state, key) {
122
153
  function handleChunkingKey(state, key) {
123
154
  const result = handleSelectKey(state.selectIndex, CHUNKING_OPTIONS.length, key);
124
155
  if (result.confirmed) {
125
- const chunking = /** @type {'whole' | 'fixed' | 'cdc'} */ (CHUNKING_OPTIONS[result.selectIndex]);
156
+ const chunking = /** @type {'fixed' | 'cdc'} */ (CHUNKING_OPTIONS[result.selectIndex]);
126
157
  return { ...state, chunking, step: 'confirm' };
127
158
  }
128
159
  return { ...state, selectIndex: result.selectIndex };
@@ -148,6 +179,7 @@ const stepHandlers = {
148
179
  filePath: handleFilePathKey,
149
180
  slug: handleSlugKey,
150
181
  encryption: handleEncryptionKey,
182
+ passphrase: handlePassphraseKey,
151
183
  compression: handleCompressionKey,
152
184
  chunking: handleChunkingKey,
153
185
  confirm: handleConfirmKey,
@@ -182,19 +214,49 @@ function deriveSlug(filePath) {
182
214
  return dotIndex > 0 ? name.slice(0, dotIndex) : name;
183
215
  }
184
216
 
217
+ const ENCRYPTED_STEP_ORDER = Object.freeze([
218
+ 'filePath',
219
+ 'slug',
220
+ 'encryption',
221
+ 'passphrase',
222
+ 'compression',
223
+ 'chunking',
224
+ 'confirm',
225
+ ]);
226
+ const PLAIN_STEP_ORDER = Object.freeze([
227
+ 'filePath',
228
+ 'slug',
229
+ 'encryption',
230
+ 'compression',
231
+ 'chunking',
232
+ 'confirm',
233
+ ]);
234
+
185
235
  /** @type {Record<string, string>} */
186
- const STEP_LABELS = {
187
- filePath: '1/6 File',
188
- slug: '2/6 Slug',
189
- encryption: '3/6 Encryption',
190
- compression: '4/6 Compression',
191
- chunking: '5/6 Chunking',
192
- confirm: '6/6 Confirm',
236
+ const STEP_NAMES = {
237
+ filePath: 'File',
238
+ slug: 'Slug',
239
+ encryption: 'Encryption',
240
+ passphrase: 'Passphrase',
241
+ compression: 'Compression',
242
+ chunking: 'Chunking',
243
+ confirm: 'Confirm',
193
244
  storing: 'Storing...',
194
245
  done: 'Done',
195
246
  error: 'Error',
196
247
  };
197
248
 
249
+ /**
250
+ * @param {StoreWizardState} state
251
+ * @returns {string}
252
+ */
253
+ function stepLabel(state) {
254
+ const name = STEP_NAMES[state.step] ?? state.step;
255
+ const order = state.encryption === 'none' ? PLAIN_STEP_ORDER : ENCRYPTED_STEP_ORDER;
256
+ const index = order.indexOf(state.step);
257
+ return index === -1 ? name : `${index + 1}/${order.length} ${name}`;
258
+ }
259
+
198
260
  /**
199
261
  * Render the wizard overlay surface.
200
262
  *
@@ -204,7 +266,7 @@ const STEP_LABELS = {
204
266
  */
205
267
  export function renderWizardSurface(state, opts) {
206
268
  return renderWizardPanel({
207
- title: `Store [${STEP_LABELS[state.step] ?? state.step}]`,
269
+ title: `Store [${stepLabel(state)}]`,
208
270
  body: renderWizardBody(state, opts.ctx),
209
271
  screenWidth: opts.width,
210
272
  screenHeight: opts.height,
@@ -259,6 +321,14 @@ function renderStepBody(state, ctx) {
259
321
  '',
260
322
  themeText(ctx, 'j/k to move, enter to select.', { tone: 'subdued' }),
261
323
  ],
324
+ passphrase: () => [
325
+ themeText(ctx, 'Encryption passphrase:', { tone: 'accent' }),
326
+ renderTextInput(
327
+ state.passphraseVisible ? state.passphrase : '*'.repeat(state.passphrase.length)
328
+ ),
329
+ '',
330
+ themeText(ctx, 'Type the passphrase, then press enter.', { tone: 'subdued' }),
331
+ ],
262
332
  compression: () => [
263
333
  themeText(ctx, 'Compression (gzip):', { tone: 'accent' }),
264
334
  renderToggle(state.compression, ctx),
@@ -288,6 +358,7 @@ function renderConfirmBody(state, ctx) {
288
358
  renderFieldLine(ctx, 'File:', state.filePath),
289
359
  renderFieldLine(ctx, 'Slug:', state.slug),
290
360
  renderFieldLine(ctx, 'Encryption:', state.encryption),
361
+ renderFieldLine(ctx, 'Passphrase:', state.encryption === 'none' ? 'none' : 'set'),
291
362
  renderFieldLine(ctx, 'Compression:', state.compression ? 'gzip' : 'none'),
292
363
  renderFieldLine(ctx, 'Chunking:', state.chunking),
293
364
  '',
package/build-info.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "sha": "3a3cd3e",
3
- "timestamp": "2026-05-09T06:59:46.782Z"
2
+ "sha": "65eda79",
3
+ "timestamp": "2026-07-11T22:16:25.638Z"
4
4
  }
package/docs/API.md CHANGED
@@ -15,13 +15,14 @@ should treat restored data, chunker output, codec output, and keys as
15
15
  ## Table of Contents
16
16
 
17
17
  1. [ContentAddressableStore](#contentaddressablestore)
18
- 2. [Vault](#vault)
19
- 3. [CasService](#casservice)
20
- 4. [Events](#events)
21
- 5. [Value Objects](#value-objects)
22
- 6. [Ports](#ports)
23
- 7. [Codecs](#codecs)
24
- 8. [Error Codes](#error-codes)
18
+ 2. [Root Sets](#root-sets)
19
+ 3. [Vault](#vault)
20
+ 4. [CasService](#casservice)
21
+ 5. [Events](#events)
22
+ 6. [Value Objects](#value-objects)
23
+ 7. [Ports](#ports)
24
+ 8. [Codecs](#codecs)
25
+ 9. [Error Codes](#error-codes)
25
26
 
26
27
  ## ContentAddressableStore
27
28
 
@@ -172,7 +173,19 @@ const vaultService = await cas.getVaultService();
172
173
  #### store
173
174
 
174
175
  ```javascript
175
- await cas.store({ source, slug, filename, encryptionKey, passphrase, encryption, kdfOptions, compression, recipients, merkleThreshold });
176
+ await cas.store({
177
+ source,
178
+ slug,
179
+ filename,
180
+ encryptionKey,
181
+ passphrase,
182
+ encryption,
183
+ kdfOptions,
184
+ compression,
185
+ chunking,
186
+ recipients,
187
+ merkleThreshold,
188
+ });
176
189
  ```
177
190
 
178
191
  Stores content from an async iterable source.
@@ -190,6 +203,7 @@ Stores content from an async iterable source.
190
203
  - `encryption.convergent` (optional): `boolean` - Explicit convergent opt-in/opt-out when `encryption.scheme` is omitted
191
204
  - `kdfOptions` (optional): `Object` - KDF options when using `passphrase` (`{ algorithm, iterations, cost, ... }`). New passphrase stores default to PBKDF2 `600000` iterations or scrypt `N=131072`, and out-of-policy values fail with `KDF_POLICY_VIOLATION`
192
205
  - `compression` (optional): `{ algorithm: 'gzip' }` - Enable compression before encryption/chunking
206
+ - `chunking` (optional): `{ strategy: 'fixed' | 'cdc', chunkSize?, targetChunkSize?, minChunkSize?, maxChunkSize?, normalized? }` - Per-operation chunking override. It affects only this store call; the facade's default chunker is unchanged
193
207
  - `recipients` (optional): `Array<{ label: string, key: Uint8Array }>` - Envelope recipients for multi-recipient encryption (mutually exclusive with `encryptionKey`/`passphrase`)
194
208
  - `merkleThreshold` (optional): `number` - Per-operation chunk count threshold used when this manifest is later published with `createTree()`
195
209
 
@@ -232,6 +246,7 @@ await cas.storeFile({
232
246
  encryption,
233
247
  kdfOptions,
234
248
  compression,
249
+ chunking,
235
250
  recipients,
236
251
  merkleThreshold,
237
252
  });
@@ -252,6 +267,7 @@ Convenience method that opens a file and stores it.
252
267
  - `encryption.convergent` (optional): `boolean` - Explicit convergent opt-in/opt-out when `encryption.scheme` is omitted
253
268
  - `kdfOptions` (optional): `Object` - KDF options when using `passphrase`. New passphrase stores default to PBKDF2 `600000` iterations or scrypt `N=131072`, and out-of-policy values fail with `KDF_POLICY_VIOLATION`
254
269
  - `compression` (optional): `{ algorithm: 'gzip' }` - Enable compression
270
+ - `chunking` (optional): `{ strategy: 'fixed' | 'cdc', chunkSize?, targetChunkSize?, minChunkSize?, maxChunkSize?, normalized? }` - Per-operation chunking override. It affects only this file store; the facade's default chunker is unchanged
255
271
  - `recipients` (optional): `Array<{ label: string, key: Uint8Array }>` - Envelope recipients for multi-recipient encryption (mutually exclusive with `encryptionKey`/`passphrase`)
256
272
  - `merkleThreshold` (optional): `number` - Per-operation chunk count threshold used when this manifest is later published with `createTree()`
257
273
 
@@ -266,6 +282,7 @@ const manifest = await cas.storeFile({
266
282
  filePath: '/path/to/file.txt',
267
283
  slug: 'my-asset',
268
284
  encryptionKey: key,
285
+ chunking: { strategy: 'cdc' },
269
286
  });
270
287
  ```
271
288
 
@@ -888,6 +905,170 @@ Returns the configured chunk size in bytes.
888
905
  console.log(cas.chunkSize); // 262144
889
906
  ```
890
907
 
908
+ ## Root Sets
909
+
910
+ Root sets retain a mutable current set of Git blobs or trees. They are intended
911
+ for caches, indexes, checkpoints, and other derived state that must survive Git
912
+ garbage collection while live but should become collectible after eviction.
913
+
914
+ | Surface | Git state after write | History policy | Removal behavior | Typical use |
915
+ | --- | --- | --- | --- | --- |
916
+ | `createTree()` / plumbing | orphaned unless another ref reaches it | none | already prune-eligible after Git's grace period | immediate composition |
917
+ | Root set | anchored while present | current generation only | becomes orphaned when no other ref reaches it | cache and derived state |
918
+ | Vault | anchored | commit history retained | old generations remain reachable through vault history | durable named assets |
919
+
920
+ The `pinned` and `evictable` entry values are application retention policy.
921
+ Both are Git-anchored while present in a root set. `pinned` does not create a
922
+ pack `.keep` file and does not make an object immune to explicit ref deletion.
923
+
924
+ ### Storage Structure
925
+
926
+ ```text
927
+ refs/cas/rootsets/warp/state-cache -> parentless commit -> tree
928
+ |-- .rootset.json
929
+ |-- root-00000000 -> tree/blob
930
+ `-- root-00000001 -> tree/blob
931
+ ```
932
+
933
+ Every generation commit is parentless by default. Updating the ref therefore
934
+ releases the previous generation instead of retaining it as history. OIDs in
935
+ `.rootset.json` are descriptive; the Git tree entries are what make targets
936
+ reachable.
937
+
938
+ ### Open A Root Set
939
+
940
+ ```javascript
941
+ const rootSet = await cas.rootSets.open({
942
+ ref: 'refs/cas/rootsets/warp/state-cache',
943
+ });
944
+ ```
945
+
946
+ Root-set refs must be below `refs/cas/rootsets/`. Invalid or unsafe ref names
947
+ fail with `ROOT_SET_REF_INVALID`.
948
+
949
+ ### put
950
+
951
+ ```javascript
952
+ await rootSet.put({
953
+ name: snapshotId,
954
+ oid: payloadTreeOid,
955
+ type: 'tree',
956
+ retention: 'evictable',
957
+ });
958
+ ```
959
+
960
+ Adds or replaces one named entry. `type` must be `blob` or `tree` and must
961
+ match the actual Git object type. `retention` defaults to `pinned` and may be
962
+ `pinned` or `evictable`.
963
+
964
+ The target is checked before metadata is written. Missing targets fail with
965
+ `ROOT_SET_TARGET_MISSING`; type mismatches fail with
966
+ `ROOT_SET_TARGET_TYPE_MISMATCH`.
967
+
968
+ ### list And contains
969
+
970
+ ```javascript
971
+ const entries = await rootSet.list();
972
+ const retained = await rootSet.contains(snapshotId);
973
+ ```
974
+
975
+ `list()` returns canonical name-sorted entries. `contains(name)` checks the
976
+ current snapshot.
977
+
978
+ ### remove
979
+
980
+ ```javascript
981
+ const { removed } = await rootSet.remove({ name: snapshotId });
982
+ ```
983
+
984
+ Removes one entry. When no other ref reaches its target, that target becomes
985
+ orphaned and follows normal Git expiration and pruning rules. Removal is a
986
+ no-op when the name is absent.
987
+
988
+ ### replace
989
+
990
+ ```javascript
991
+ await rootSet.replace({
992
+ expectedHeadOid: (await rootSet.read()).headOid,
993
+ entries: liveSnapshots.map(({ id, payloadRef }) => ({
994
+ name: id,
995
+ oid: payloadRef,
996
+ type: 'tree',
997
+ retention: 'evictable',
998
+ })),
999
+ });
1000
+ ```
1001
+
1002
+ Atomically replaces the current set. This is the preferred integration for an
1003
+ application that already has an authoritative live-entry index. Pass
1004
+ `expectedHeadOid` (including `null` for a set that must not exist yet) when the
1005
+ replacement was derived from a particular generation. A stale expectation
1006
+ fails with `ROOT_SET_CONFLICT` instead of overwriting newer state.
1007
+
1008
+ ### mutate
1009
+
1010
+ ```javascript
1011
+ const { headOid } = await rootSet.read();
1012
+ await rootSet.mutate(
1013
+ (entries) => entries.filter((entry) => shouldKeep(entry)),
1014
+ { expectedHeadOid: headOid },
1015
+ );
1016
+ ```
1017
+
1018
+ Runs a compare-and-swap read/modify/write operation. The callback receives a
1019
+ frozen snapshot and returns the next iterable of entries. Without
1020
+ `expectedHeadOid`, conflicts are retried against a fresh snapshot. With an
1021
+ expected head, the callback is guarded to that generation and any stale read
1022
+ or write conflict is returned to the caller without retrying.
1023
+
1024
+ ### doctor
1025
+
1026
+ ```javascript
1027
+ const report = await rootSet.doctor();
1028
+ ```
1029
+
1030
+ Returns a non-mutating report with:
1031
+
1032
+ - `healthy`, `ref`, `headOid`, `treeOid`, and `entryCount`
1033
+ - `policyCounts` for `pinned` and `evictable`
1034
+ - `reachabilityCounts` for `anchored`, `missing`, `unknown`, `orphaned`, and
1035
+ `volatile`
1036
+ - per-target existence and actual Git object type
1037
+ - stable issue codes for missing or mismatched targets
1038
+
1039
+ Current members are `anchored`. `orphaned` and `volatile` describe objects
1040
+ outside the current root set and are reported as zero by a single-set doctor;
1041
+ repository-wide classification remains a Git maintenance concern.
1042
+
1043
+ ### repair
1044
+
1045
+ ```javascript
1046
+ await rootSet.repair({ entries: authoritativeLiveEntries });
1047
+ ```
1048
+
1049
+ Replaces a missing or malformed root-set head from an authoritative entry
1050
+ list, without trusting the current metadata. Repair can only adopt objects that
1051
+ still exist. Run repair before destructive cleanup:
1052
+
1053
+ 1. Read the application's authoritative live OIDs.
1054
+ 2. Call `doctor()` and compare the application index with `list()`.
1055
+ 3. Call `repair({ entries })` to anchor every known-live object.
1056
+ 4. Re-run `doctor()` and require `healthy: true`.
1057
+ 5. Only then run a Git prune dry-run or garbage collection.
1058
+
1059
+ ### Direct Services
1060
+
1061
+ `RootSet` and `RootSetRegistry` are exported from the package root. Normal
1062
+ callers should use `cas.rootSets.open(...)`; `getRootSetRegistry()` exposes the
1063
+ shared registry for advanced composition.
1064
+
1065
+ Custom persistence implementations that support root sets must implement
1066
+ `readObjectType(oid)`, and custom ref adapters must implement
1067
+ `resolveParents(commitOid)`. The default Git adapters use `git cat-file -t`
1068
+ and `git rev-list --parents` so missing targets, repository read failures, and
1069
+ parentful heads remain distinct doctor findings. Existing store, restore, and
1070
+ vault paths do not call these methods.
1071
+
891
1072
  ## Vault
892
1073
 
893
1074
  The vault provides GC-safe storage by maintaining a single Git ref (`refs/cas/vault`) pointing to a commit chain. The commit's tree indexes all stored assets by slug. This prevents `git gc` from garbage-collecting stored data.
@@ -1231,14 +1412,14 @@ git cas rotate --slug demo/hello \
1231
1412
 
1232
1413
  #### `git cas vault rotate` flags
1233
1414
 
1234
- | Flag | Description |
1235
- | ----------------------------- | ------------------------------------------------------- |
1236
- | `--old-passphrase <pass>` | Current inline passphrase (warns; prefer file) |
1237
- | `--new-passphrase <pass>` | New inline passphrase (warns; prefer file) |
1238
- | `--old-passphrase-file <path>` | Read current passphrase from file (`-` for stdin) |
1239
- | `--new-passphrase-file <path>` | Read new passphrase from file (`-` for stdin) |
1240
- | `--algorithm <alg>` | KDF algorithm for new passphrase (`pbkdf2` or `scrypt`) |
1241
- | `--cwd <dir>` | Git working directory (default: `.`) |
1415
+ | Flag | Description |
1416
+ | ------------------------------ | ------------------------------------------------------- |
1417
+ | `--old-passphrase <pass>` | Current inline passphrase (warns; prefer file) |
1418
+ | `--new-passphrase <pass>` | New inline passphrase (warns; prefer file) |
1419
+ | `--old-passphrase-file <path>` | Read current passphrase from file (`-` for stdin) |
1420
+ | `--new-passphrase-file <path>` | Read new passphrase from file (`-` for stdin) |
1421
+ | `--algorithm <alg>` | KDF algorithm for new passphrase (`pbkdf2` or `scrypt`) |
1422
+ | `--cwd <dir>` | Git working directory (default: `.`) |
1242
1423
 
1243
1424
  ### Vault History
1244
1425
 
@@ -1264,7 +1445,21 @@ Core domain service implementing CAS operations. Usually accessed via ContentAdd
1264
1445
  ### Constructor
1265
1446
 
1266
1447
  ```javascript
1267
- new CasService({ persistence, codec, crypto, observability, chunkSize, merkleThreshold, concurrency, chunker, compressionAdapter, maxRestoreBufferSize, maxBlobSize, formatVersion, legacyMode });
1448
+ new CasService({
1449
+ persistence,
1450
+ codec,
1451
+ crypto,
1452
+ observability,
1453
+ chunkSize,
1454
+ merkleThreshold,
1455
+ concurrency,
1456
+ chunker,
1457
+ compressionAdapter,
1458
+ maxRestoreBufferSize,
1459
+ maxBlobSize,
1460
+ formatVersion,
1461
+ legacyMode,
1462
+ });
1268
1463
  ```
1269
1464
 
1270
1465
  **Parameters:**
@@ -1319,7 +1514,7 @@ const service = new CasService({
1319
1514
 
1320
1515
  All methods from ContentAddressableStore delegate to CasService. See ContentAddressableStore documentation above for:
1321
1516
 
1322
- - `store({ source, slug, filename, encryptionKey, passphrase, encryption, kdfOptions, compression, recipients })`
1517
+ - `store({ source, slug, filename, encryptionKey, passphrase, encryption, kdfOptions, compression, chunker, recipients })`
1323
1518
  - `restore({ manifest, encryptionKey, passphrase })`
1324
1519
  - `restoreStream({ manifest, encryptionKey, passphrase })`
1325
1520
  - `createTree({ manifest })`
@@ -1721,6 +1916,19 @@ Reads a Git tree object.
1721
1916
 
1722
1917
  **Returns:** `Promise<Array<{ mode: string, type: string, oid: string, name: string }>>`
1723
1918
 
1919
+ ##### readObjectType
1920
+
1921
+ ```javascript
1922
+ await port.readObjectType(oid);
1923
+ ```
1924
+
1925
+ Reads an object's Git type without materializing its content. Root sets use
1926
+ this capability to reject missing targets and type mismatches before changing
1927
+ a ref.
1928
+
1929
+ **Returns:** `Promise<string>` - Git object type such as `blob`, `tree`, or
1930
+ `commit`
1931
+
1724
1932
  **Example Implementation:**
1725
1933
 
1726
1934
  ```javascript
@@ -1744,6 +1952,10 @@ class CustomGitAdapter {
1744
1952
  async readTree(treeOid) {
1745
1953
  // Implementation
1746
1954
  }
1955
+
1956
+ async readObjectType(oid) {
1957
+ // Implementation
1958
+ }
1747
1959
  }
1748
1960
  ```
1749
1961
 
@@ -2107,39 +2319,49 @@ new CasError({ message, code, meta, documentationUrl });
2107
2319
 
2108
2320
  ### Error Codes
2109
2321
 
2110
- | Code | Description | Thrown By |
2111
- | ------------------------------------- | -------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
2112
- | `INVALID_KEY_TYPE` | Encryption key must be a Uint8Array | `encrypt()`, `decrypt()`, `store()`, `restore()` |
2113
- | `INVALID_KEY_LENGTH` | Encryption key must be exactly 32 bytes | `encrypt()`, `decrypt()`, `store()`, `restore()` |
2114
- | `MISSING_KEY` | Encryption key required to restore encrypted content but none was provided | `restore()` |
2115
- | `INTEGRITY_ERROR` | Chunk digest verification failed or decryption authentication failed | `restore()`, `verifyIntegrity()`, `decrypt()` |
2116
- | `PERSISTENCE_CAPABILITY_REQUIRED` | Buffered restore mode requires `readBlobStream()` so `maxRestoreBufferSize` can be enforced with memory-safe reads | `restore()`, `restoreStream()` |
2117
- | `DECRYPTION_BUFFER_EXCEEDED` | Web Crypto whole-object decrypt exceeded the configured buffer limit | `createDecryptionStream()` via Web Crypto restore paths |
2118
- | `KDF_POLICY_VIOLATION` | KDF parameters fell outside the accepted policy window | `store()`, `restore()`, `initVault()`, `rotateVaultPassphrase()`, `readState()` |
2119
- | `STREAM_ERROR` | Stream error occurred during store operation | `store()` |
2120
- | `STORE_ERROR` | Chunk write failed during store after dispatch | `store()` |
2121
- | `MANIFEST_NOT_FOUND` | No manifest entry found in the Git tree | `readManifest()`, `inspectAsset()`, `collectReferencedChunks()` |
2122
- | `GIT_ERROR` | Underlying Git plumbing command failed | `readManifest()`, `inspectAsset()`, `collectReferencedChunks()` |
2123
- | `GIT_REF_NOT_FOUND` | Git ref lookup found no ref; vault reads normalize this to empty state | `GitRefAdapter`, `VaultPersistence` |
2124
- | `INVALID_OPTIONS` | Mutually exclusive options provided or unsupported option value | `store()`, `restore()` |
2125
- | `INVALID_SLUG` | Slug fails validation (empty, control chars, `..` segments, etc.) | `addToVault()` |
2126
- | `VAULT_ENTRY_NOT_FOUND` | Slug does not exist in vault | `removeFromVault()`, `resolveVaultEntry()` |
2127
- | `VAULT_ENTRY_EXISTS` | Slug already exists (use `force` to overwrite) | `addToVault()` |
2128
- | `VAULT_CONFLICT` | Concurrent vault update detected (CAS failure after retries) | `addToVault()`, `removeFromVault()`, `initVault()`, `rotateVaultPassphrase()` |
2129
- | `VAULT_REF_MISSING` | Vault ref is absent during diagnostics | `git cas doctor` |
2130
- | `VAULT_REF_UPDATE_FAILED` | Vault ref update failed for a non-CAS reason | `addToVault()`, `removeFromVault()`, `initVault()`, `rotateVaultPassphrase()` |
2131
- | `VAULT_HEAD_INVALID` | Vault ref exists but cannot be resolved to a readable commit tree | `readState()`, `getVaultMetadata()`, `git cas doctor` |
2132
- | `VAULT_METADATA_INVALID` | `.vault.json` malformed, unknown version, unsupported cipher, or missing required fields | `readState()`, `rotateVaultPassphrase()`, `git cas doctor` |
2133
- | `VAULT_PRIVACY_INDEX_INVALID` | Privacy index metadata, payload, or raw HMAC tree coverage is invalid | `readState()`, `listVault()`, `resolveVaultEntry()`, `git cas doctor` |
2134
- | `VAULT_PRIVACY_INDEX_MISSING` | Privacy mode is enabled but `.privacy-index` is missing | `readState()`, `listVault()`, `git cas doctor` |
2135
- | `VAULT_PRIVACY_KEY_REQUIRED` | Privacy mode requires a vault encryption key for state reads | `readState()`, `listVault()`, `resolveVaultEntry()` |
2136
- | `VAULT_ENCRYPTION_ALREADY_CONFIGURED` | Cannot reconfigure encryption without key rotation | `initVault()` |
2137
- | `NO_MATCHING_RECIPIENT` | No recipient entry matches the provided KEK | `restore()`, `rotateKey()` |
2138
- | `DEK_UNWRAP_FAILED` | Failed to unwrap DEK with the provided KEK | `addRecipient()`, `rotateKey()` |
2139
- | `RECIPIENT_NOT_FOUND` | Recipient label not found in manifest | `removeRecipient()`, `rotateKey()` |
2140
- | `RECIPIENT_ALREADY_EXISTS` | Recipient label already exists | `addRecipient()` |
2141
- | `CANNOT_REMOVE_LAST_RECIPIENT` | Cannot remove the last recipient | `removeRecipient()` |
2142
- | `ROTATION_NOT_SUPPORTED` | Key rotation requires envelope encryption (recipients) | `rotateKey()` |
2322
+ | Code | Description | Thrown By |
2323
+ | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------- |
2324
+ | `INVALID_KEY_TYPE` | Encryption key must be a Uint8Array | `encrypt()`, `decrypt()`, `store()`, `restore()` |
2325
+ | `INVALID_KEY_LENGTH` | Encryption key must be exactly 32 bytes | `encrypt()`, `decrypt()`, `store()`, `restore()` |
2326
+ | `MISSING_KEY` | Encryption key required to restore encrypted content but none was provided | `restore()` |
2327
+ | `INTEGRITY_ERROR` | Chunk digest verification failed or decryption authentication failed | `restore()`, `verifyIntegrity()`, `decrypt()` |
2328
+ | `PERSISTENCE_CAPABILITY_REQUIRED` | Buffered restore mode requires `readBlobStream()` so `maxRestoreBufferSize` can be enforced with memory-safe reads | `restore()`, `restoreStream()` |
2329
+ | `DECRYPTION_BUFFER_EXCEEDED` | Web Crypto whole-object decrypt exceeded the configured buffer limit | `createDecryptionStream()` via Web Crypto restore paths |
2330
+ | `KDF_POLICY_VIOLATION` | KDF parameters fell outside the accepted policy window | `store()`, `restore()`, `initVault()`, `rotateVaultPassphrase()`, `readState()` |
2331
+ | `STREAM_ERROR` | Stream error occurred during store operation | `store()` |
2332
+ | `STORE_ERROR` | Chunk write failed during store after dispatch | `store()` |
2333
+ | `MANIFEST_NOT_FOUND` | No manifest entry found in the Git tree | `readManifest()`, `inspectAsset()`, `collectReferencedChunks()` |
2334
+ | `GIT_ERROR` | Underlying Git plumbing command failed | `readManifest()`, `inspectAsset()`, `collectReferencedChunks()` |
2335
+ | `GIT_REF_NOT_FOUND` | Git ref lookup found no ref; vault reads normalize this to empty state | `GitRefAdapter`, `VaultPersistence` |
2336
+ | `INVALID_OPTIONS` | Mutually exclusive options provided or unsupported option value | `store()`, `restore()` |
2337
+ | `INVALID_SLUG` | Slug fails validation (empty, control chars, `..` segments, etc.) | `addToVault()` |
2338
+ | `ROOT_SET_REF_INVALID` | Ref is outside `refs/cas/rootsets/*` or is not a safe Git ref | `rootSets.open()` |
2339
+ | `ROOT_SET_ENTRY_INVALID` | Entry name, OID, type, retention, or duplicate-name validation failed | `put()`, `replace()`, `mutate()`, `repair()` |
2340
+ | `ROOT_SET_TARGET_MISSING` | A requested target OID does not exist | `put()`, `replace()`, `mutate()`, `repair()` |
2341
+ | `ROOT_SET_TARGET_UNREADABLE` | Git could not inspect a target, but did not prove that it was missing | Root-set mutation and doctor |
2342
+ | `ROOT_SET_TARGET_TYPE_MISMATCH` | Declared blob/tree type does not match the Git object | `put()`, `replace()`, `mutate()`, `repair()` |
2343
+ | `ROOT_SET_CONFLICT` | Concurrent root-set update exhausted bounded compare-and-swap retries | Root-set mutations and repair |
2344
+ | `ROOT_SET_HEAD_INVALID` | Root-set ref cannot resolve to a readable commit tree | `read()`, `list()`, `doctor()` |
2345
+ | `ROOT_SET_METADATA_INVALID` | `.rootset.json` is malformed, non-canonical, or belongs to another ref | `read()`, `list()`, `doctor()` |
2346
+ | `ROOT_SET_TREE_INVALID` | Metadata and the Git tree's actual reachability edges disagree | `read()`, `list()`, `doctor()` |
2347
+ | `ROOT_SET_REF_UPDATE_FAILED` | Root-set ref update failed for a non-conflict reason | Root-set mutations and repair |
2348
+ | `VAULT_ENTRY_NOT_FOUND` | Slug does not exist in vault | `removeFromVault()`, `resolveVaultEntry()` |
2349
+ | `VAULT_ENTRY_EXISTS` | Slug already exists (use `force` to overwrite) | `addToVault()` |
2350
+ | `VAULT_CONFLICT` | Concurrent vault update detected (CAS failure after retries) | `addToVault()`, `removeFromVault()`, `initVault()`, `rotateVaultPassphrase()` |
2351
+ | `VAULT_REF_MISSING` | Vault ref is absent during diagnostics | `git cas doctor` |
2352
+ | `VAULT_REF_UPDATE_FAILED` | Vault ref update failed for a non-CAS reason | `addToVault()`, `removeFromVault()`, `initVault()`, `rotateVaultPassphrase()` |
2353
+ | `VAULT_HEAD_INVALID` | Vault ref exists but cannot be resolved to a readable commit tree | `readState()`, `getVaultMetadata()`, `git cas doctor` |
2354
+ | `VAULT_METADATA_INVALID` | `.vault.json` malformed, unknown version, unsupported cipher, or missing required fields | `readState()`, `rotateVaultPassphrase()`, `git cas doctor` |
2355
+ | `VAULT_PRIVACY_INDEX_INVALID` | Privacy index metadata, payload, or raw HMAC tree coverage is invalid | `readState()`, `listVault()`, `resolveVaultEntry()`, `git cas doctor` |
2356
+ | `VAULT_PRIVACY_INDEX_MISSING` | Privacy mode is enabled but `.privacy-index` is missing | `readState()`, `listVault()`, `git cas doctor` |
2357
+ | `VAULT_PRIVACY_KEY_REQUIRED` | Privacy mode requires a vault encryption key for state reads | `readState()`, `listVault()`, `resolveVaultEntry()` |
2358
+ | `VAULT_ENCRYPTION_ALREADY_CONFIGURED` | Cannot reconfigure encryption without key rotation | `initVault()` |
2359
+ | `NO_MATCHING_RECIPIENT` | No recipient entry matches the provided KEK | `restore()`, `rotateKey()` |
2360
+ | `DEK_UNWRAP_FAILED` | Failed to unwrap DEK with the provided KEK | `addRecipient()`, `rotateKey()` |
2361
+ | `RECIPIENT_NOT_FOUND` | Recipient label not found in manifest | `removeRecipient()`, `rotateKey()` |
2362
+ | `RECIPIENT_ALREADY_EXISTS` | Recipient label already exists | `addRecipient()` |
2363
+ | `CANNOT_REMOVE_LAST_RECIPIENT` | Cannot remove the last recipient | `removeRecipient()` |
2364
+ | `ROTATION_NOT_SUPPORTED` | Key rotation requires envelope encryption (recipients) | `rotateKey()` |
2143
2365
 
2144
2366
  ### Error Handling
2145
2367