@git-stunts/git-cas 5.3.2 → 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.
Files changed (173) hide show
  1. package/ADVANCED_GUIDE.md +1006 -0
  2. package/ARCHITECTURE.md +514 -0
  3. package/CHANGELOG.md +393 -5
  4. package/CODE_OF_CONDUCT.md +33 -0
  5. package/GUIDE.md +872 -0
  6. package/README.md +219 -325
  7. package/SECURITY.md +993 -0
  8. package/SUPPORT.md +54 -0
  9. package/UPGRADING.md +299 -0
  10. package/bin/actions.js +70 -21
  11. package/bin/agent/cli.js +51 -0
  12. package/bin/agent/commands/doctor.js +99 -0
  13. package/bin/agent/commands/index.js +1489 -0
  14. package/bin/agent/input.js +619 -0
  15. package/bin/agent/passphrase-source.js +123 -0
  16. package/bin/agent/protocol.js +193 -0
  17. package/bin/build-version.js +64 -0
  18. package/bin/credentials.js +425 -0
  19. package/bin/git-cas.js +595 -449
  20. package/bin/passphrase-source.js +266 -0
  21. package/bin/restore-output-target.js +28 -0
  22. package/bin/ui/blocks/asset-card.js +109 -0
  23. package/bin/ui/blocks/health-dashboard.js +149 -0
  24. package/bin/ui/blocks/heatmap-block.js +67 -0
  25. package/bin/ui/blocks/merkle-explorer.js +163 -0
  26. package/bin/ui/blocks/operation-feed.js +176 -0
  27. package/bin/ui/blocks/wizard-block.js +168 -0
  28. package/bin/ui/components/short-sha.js +36 -0
  29. package/bin/ui/context.js +56 -1
  30. package/bin/ui/dashboard-cmds.js +1578 -13
  31. package/bin/ui/dashboard-view.js +612 -145
  32. package/bin/ui/dashboard.js +998 -214
  33. package/bin/ui/encryption-card.js +69 -26
  34. package/bin/ui/heatmap.js +26 -54
  35. package/bin/ui/history-timeline.js +51 -19
  36. package/bin/ui/manifest-view.js +115 -60
  37. package/bin/ui/merkle-dag.js +83 -0
  38. package/bin/ui/progress.js +15 -9
  39. package/bin/ui/repo-treemap.js +328 -0
  40. package/bin/ui/shaders/bak-sneppen.js +180 -0
  41. package/bin/ui/shaders/fractal-zoom.js +99 -0
  42. package/bin/ui/shaders/merkle-tree.js +142 -0
  43. package/bin/ui/shaders/organic-flow.js +96 -0
  44. package/bin/ui/shaders/phase-portrait.js +93 -0
  45. package/bin/ui/store-wizard.js +296 -0
  46. package/bin/ui/theme.js +155 -0
  47. package/bin/ui/vault-report.js +495 -0
  48. package/build-info.json +4 -0
  49. package/docs/API.md +2224 -0
  50. package/docs/ENCRYPTION_MODES.md +33 -0
  51. package/docs/EXTENDING.md +174 -0
  52. package/docs/STORE_RESTORE_PIPELINE.md +199 -0
  53. package/docs/THREAT_MODEL.md +269 -0
  54. package/docs/VAULT_INTERNALS.md +251 -0
  55. package/docs/WALKTHROUGH.md +1868 -0
  56. package/docs/demo.gif +0 -0
  57. package/docs/releases/v6.0.0.md +104 -0
  58. package/examples/README.md +260 -0
  59. package/index.d.ts +208 -65
  60. package/index.js +163 -54
  61. package/package.json +35 -6
  62. package/scripts/migrate-encryption.js +680 -0
  63. package/src/domain/bytes/ByteLayout.js +96 -0
  64. package/src/domain/encoding/base64.js +91 -0
  65. package/src/domain/encoding/hex.js +14 -0
  66. package/src/domain/encoding/utf8.js +123 -0
  67. package/src/domain/encryption/schemes.js +132 -0
  68. package/src/domain/errors/CannotRemoveLastRecipientError.js +10 -0
  69. package/src/domain/errors/CasError.d.ts +28 -0
  70. package/src/domain/errors/CasError.js +43 -6
  71. package/src/domain/errors/Codes.js +54 -0
  72. package/src/domain/errors/DekUnwrapFailedError.js +10 -0
  73. package/src/domain/errors/GitError.js +10 -0
  74. package/src/domain/errors/GitPlumbingInitializationError.js +10 -0
  75. package/src/domain/errors/IntegrityError.js +10 -0
  76. package/src/domain/errors/InvalidChunkingStrategyError.js +10 -0
  77. package/src/domain/errors/InvalidOidError.js +10 -0
  78. package/src/domain/errors/InvalidOptionsError.js +10 -0
  79. package/src/domain/errors/ManifestIntegrityError.js +10 -0
  80. package/src/domain/errors/ManifestNotFoundError.js +10 -0
  81. package/src/domain/errors/NoMatchingRecipientError.js +10 -0
  82. package/src/domain/errors/PersistenceCapabilityRequiredError.js +10 -0
  83. package/src/domain/errors/PortNotImplementedError.js +10 -0
  84. package/src/domain/errors/RecipientAlreadyExistsError.js +10 -0
  85. package/src/domain/errors/RecipientNotFoundError.js +10 -0
  86. package/src/domain/errors/RestoreTooLargeError.js +10 -0
  87. package/src/domain/errors/RotationNotSupportedError.js +10 -0
  88. package/src/domain/errors/createCasError.js +68 -0
  89. package/src/domain/errors/index.js +20 -0
  90. package/src/domain/helpers/buildKdfMetadata.js +4 -2
  91. package/src/domain/helpers/codecBytes.js +34 -0
  92. package/src/domain/helpers/gitRefErrors.js +84 -0
  93. package/src/domain/helpers/scryptMaxmem.js +22 -0
  94. package/src/domain/outcomes/RestoreFailure.js +15 -0
  95. package/src/domain/outcomes/RestoreOutcome.js +11 -0
  96. package/src/domain/outcomes/RestoreSuccess.js +34 -0
  97. package/src/domain/outcomes/StoreFailure.js +15 -0
  98. package/src/domain/outcomes/StoreOutcome.js +11 -0
  99. package/src/domain/outcomes/StoreSuccess.js +17 -0
  100. package/src/domain/schemas/ManifestSchema.d.ts +40 -9
  101. package/src/domain/schemas/ManifestSchema.js +67 -13
  102. package/src/domain/services/CasService.d.ts +123 -38
  103. package/src/domain/services/CasService.js +298 -834
  104. package/src/domain/services/ChunkRepository.js +230 -0
  105. package/src/domain/services/CompressionStreams.js +72 -0
  106. package/src/domain/services/ConvergentEncryption.js +128 -0
  107. package/src/domain/services/GitTreeBuilder.js +86 -0
  108. package/src/domain/services/IntegrityVerifier.js +199 -0
  109. package/src/domain/services/KeyResolver.js +49 -42
  110. package/src/domain/services/ManifestDiff.js +56 -0
  111. package/src/domain/services/ManifestRepository.js +286 -0
  112. package/src/domain/services/PrefetchWindow.js +48 -0
  113. package/src/domain/services/RecipientService.js +157 -0
  114. package/src/domain/services/RedactingObservability.js +169 -0
  115. package/src/domain/services/RestorePipeline.js +68 -0
  116. package/src/domain/services/StorePipeline.js +201 -0
  117. package/src/domain/services/VaultKeyVerifier.js +101 -0
  118. package/src/domain/services/VaultMetadataCodec.js +206 -0
  119. package/src/domain/services/VaultMutationRetryPolicy.js +105 -0
  120. package/src/domain/services/VaultPersistence.js +410 -0
  121. package/src/domain/services/VaultPrivacyIndex.js +191 -0
  122. package/src/domain/services/VaultService.js +749 -251
  123. package/src/domain/services/VaultStateCache.js +225 -0
  124. package/src/domain/services/VaultTreeCodec.js +121 -0
  125. package/src/domain/services/rotateVaultPassphrase.js +37 -20
  126. package/src/domain/strategies/Aad.js +39 -0
  127. package/src/domain/strategies/FramedRecordCodec.js +204 -0
  128. package/src/domain/strategies/RestoreCompressed.js +40 -0
  129. package/src/domain/strategies/RestoreConvergent.js +44 -0
  130. package/src/domain/strategies/RestoreFramed.js +55 -0
  131. package/src/domain/strategies/RestorePlain.js +37 -0
  132. package/src/domain/strategies/RestoreStrategy.js +35 -0
  133. package/src/domain/strategies/RestoreWhole.js +135 -0
  134. package/src/domain/strategies/StoreConvergent.js +28 -0
  135. package/src/domain/strategies/StoreFramed.js +39 -0
  136. package/src/domain/strategies/StorePlain.js +20 -0
  137. package/src/domain/strategies/StoreStrategy.js +61 -0
  138. package/src/domain/strategies/StoreWhole.js +34 -0
  139. package/src/domain/value-objects/Chunk.js +1 -2
  140. package/src/domain/value-objects/EncryptionMetadata.js +87 -0
  141. package/src/domain/value-objects/Manifest.d.ts +40 -4
  142. package/src/domain/value-objects/Manifest.js +61 -20
  143. package/src/domain/value-objects/Oid.js +45 -0
  144. package/src/domain/value-objects/Slug.js +124 -0
  145. package/src/domain/value-objects/StoreEncryptionConfig.js +114 -0
  146. package/src/helpers/aesGcmMeta.js +55 -0
  147. package/src/helpers/canonicalBase64.js +1 -0
  148. package/src/helpers/kdfPolicy.js +194 -0
  149. package/src/infrastructure/adapters/BunCryptoAdapter.js +124 -8
  150. package/src/infrastructure/adapters/FileIOHelper.js +178 -13
  151. package/src/infrastructure/adapters/GitPersistenceAdapter.js +235 -42
  152. package/src/infrastructure/adapters/GitPlumbingFactoryAdapter.js +62 -0
  153. package/src/infrastructure/adapters/GitRefAdapter.js +19 -6
  154. package/src/infrastructure/adapters/NodeCompressionAdapter.js +64 -0
  155. package/src/infrastructure/adapters/NodeCryptoAdapter.js +130 -10
  156. package/src/infrastructure/adapters/WebCryptoAdapter.js +187 -77
  157. package/src/infrastructure/chunkers/CdcChunker.js +53 -19
  158. package/src/infrastructure/chunkers/FixedChunker.js +15 -7
  159. package/src/infrastructure/chunkers/resolveChunker.js +3 -1
  160. package/src/infrastructure/codecs/CborCodec.js +3 -3
  161. package/src/infrastructure/codecs/JsonCodec.js +5 -5
  162. package/src/infrastructure/createGitPlumbing.js +22 -0
  163. package/src/package-version.js +1 -0
  164. package/src/ports/ChunkingPort.js +3 -3
  165. package/src/ports/CodecPort.js +4 -4
  166. package/src/ports/CompressionPort.js +57 -0
  167. package/src/ports/CryptoPort.js +138 -50
  168. package/src/ports/GitPersistencePort.js +32 -2
  169. package/src/ports/GitPlumbingFactoryPort.js +16 -0
  170. package/src/ports/GitRefPort.js +1 -1
  171. package/src/types/ambient.d.ts +10 -5
  172. package/test/CONVENTIONS.md +94 -0
  173. package/test/cycles/README.md +13 -0
@@ -16,6 +16,7 @@
16
16
  */
17
17
 
18
18
  import ChunkingPort from '../../ports/ChunkingPort.js';
19
+ import { copyBytes, normalizeByteChunk } from '../../domain/bytes/ByteLayout.js';
19
20
 
20
21
  // ---------------------------------------------------------------------------
21
22
  // Buzhash byte-table (256 entries, deterministic)
@@ -73,11 +74,15 @@ const WINDOW_MASK = WINDOW_SIZE - 1; // 63, for fast modulo
73
74
  * @property {Uint8Array} win - Sliding window ring buffer.
74
75
  * @property {number} winPos - Current write position in `win`.
75
76
  * @property {number} hashFed - Bytes fed since last reset.
76
- * @property {Buffer} chunkBuf - Pre-allocated chunk output buffer.
77
+ * @property {Uint8Array} chunkBuf - Pre-allocated chunk output buffer.
77
78
  * @property {number} chunkLen - Bytes written to chunkBuf so far.
78
79
  * @property {number} minSize - Minimum chunk size.
79
80
  * @property {number} maxSize - Maximum chunk size.
80
- * @property {number} mask - Boundary detection mask.
81
+ * @property {number} mask - Boundary detection mask (single-mask mode).
82
+ * @property {number} hardMask - Stricter mask for below-target (normalized mode).
83
+ * @property {number} easyMask - Looser mask for above-target (normalized mode).
84
+ * @property {number} targetSize - Target chunk size (normalized mode).
85
+ * @property {boolean} normalized - Whether dual-mask normalization is active.
81
86
  */
82
87
 
83
88
  /**
@@ -101,7 +106,7 @@ function resetState(st) {
101
106
  * Uses a simplified hash update (no outgoing-byte removal).
102
107
  *
103
108
  * @param {ChunkState} st
104
- * @param {Buffer} buf - Source buffer being processed.
109
+ * @param {Uint8Array} buf - Source bytes being processed.
105
110
  * @param {number} srcPos - Current read offset in `buf`.
106
111
  * @returns {number} Updated srcPos.
107
112
  */
@@ -129,7 +134,7 @@ function fillWindow(st, buf, srcPos) {
129
134
  * Bulk-copies bytes into the chunk buffer while updating the hash.
130
135
  *
131
136
  * @param {ChunkState} st
132
- * @param {Buffer} buf
137
+ * @param {Uint8Array} buf
133
138
  * @param {number} srcPos
134
139
  * @returns {number} Updated srcPos.
135
140
  */
@@ -140,8 +145,13 @@ function feedPreMin(st, buf, srcPos) {
140
145
  const end = srcPos + n;
141
146
  const table = BUZ_TABLE;
142
147
 
143
- // Bulk-copy into chunk buffer
144
- buf.copy(st.chunkBuf, st.chunkLen, srcPos, end);
148
+ copyBytes({
149
+ source: buf,
150
+ target: st.chunkBuf,
151
+ targetOffset: st.chunkLen,
152
+ sourceStart: srcPos,
153
+ sourceEnd: end,
154
+ });
145
155
 
146
156
  // Feed bytes into rolling hash (window is full)
147
157
  while (srcPos < end) {
@@ -159,12 +169,12 @@ function feedPreMin(st, buf, srcPos) {
159
169
  * Phase 3 — scan for a content-defined boundary in [minSize, maxSize).
160
170
  *
161
171
  * @param {ChunkState} st
162
- * @param {Buffer} buf
172
+ * @param {Uint8Array} buf
163
173
  * @param {number} srcPos
164
174
  * @returns {{ srcPos: number, found: boolean }}
165
175
  */
166
176
  function scanBoundary(st, buf, srcPos) {
167
- const { mask, maxSize } = st;
177
+ const { maxSize, normalized, hardMask, easyMask, targetSize, mask } = st;
168
178
  const table = BUZ_TABLE;
169
179
  const limit = buf.length < (srcPos + maxSize - st.chunkLen)
170
180
  ? buf.length
@@ -183,7 +193,8 @@ function scanBoundary(st, buf, srcPos) {
183
193
  chunkBuf[cl++] = byte;
184
194
  srcPos++;
185
195
 
186
- if ((h & mask) === 0) {
196
+ const m = normalized ? (cl < targetSize ? hardMask : easyMask) : mask;
197
+ if ((h & m) === 0) {
187
198
  st.hash = h;
188
199
  st.winPos = wp;
189
200
  st.chunkLen = cl;
@@ -204,11 +215,11 @@ function scanBoundary(st, buf, srcPos) {
204
215
  * was found within this buffer).
205
216
  *
206
217
  * @param {ChunkState} st
207
- * @param {Buffer} buf
208
- * @returns {Buffer[]} Completed chunks ready to yield.
218
+ * @param {Uint8Array} buf
219
+ * @returns {Uint8Array[]} Completed chunks ready to yield.
209
220
  */
210
221
  function processBuf(st, buf) {
211
- /** @type {Buffer[]} */
222
+ /** @type {Uint8Array[]} */
212
223
  const completed = [];
213
224
  let srcPos = 0;
214
225
 
@@ -229,7 +240,7 @@ function processBuf(st, buf) {
229
240
  srcPos = result.srcPos;
230
241
 
231
242
  if (result.found || st.chunkLen >= st.maxSize) {
232
- completed.push(Buffer.from(st.chunkBuf.subarray(0, st.chunkLen)));
243
+ completed.push(new Uint8Array(st.chunkBuf.subarray(0, st.chunkLen)));
233
244
  resetState(st);
234
245
  }
235
246
  }
@@ -246,17 +257,26 @@ function processBuf(st, buf) {
246
257
  * @property {number} [minChunkSize=65536] - Minimum chunk size in bytes (64 KiB).
247
258
  * @property {number} [maxChunkSize=1048576] - Maximum chunk size in bytes (1 MiB).
248
259
  * @property {number} [targetChunkSize=262144] - Target (average) chunk size in bytes (256 KiB).
260
+ * @property {boolean} [normalized=true] - Enable FastCDC dual-mask normalization.
249
261
  */
250
262
 
251
263
  /**
252
264
  * CDC chunker that uses a Buzhash rolling hash to find content-defined
253
265
  * chunk boundaries within an async byte stream.
266
+ *
267
+ * When `normalized` is true (the default), a dual-mask strategy is used:
268
+ * a stricter mask below the target size and a looser mask above it. This
269
+ * concentrates the chunk size distribution around the target, improving
270
+ * deduplication efficiency.
254
271
  */
255
272
  export default class CdcChunker extends ChunkingPort {
256
273
  /** @type {number} */ #minChunkSize;
257
274
  /** @type {number} */ #maxChunkSize;
258
275
  /** @type {number} */ #targetChunkSize;
259
276
  /** @type {number} */ #mask;
277
+ /** @type {number} */ #hardMask;
278
+ /** @type {number} */ #easyMask;
279
+ /** @type {boolean} */ #normalized;
260
280
 
261
281
  /**
262
282
  * @param {CdcChunkerOptions} [options]
@@ -265,6 +285,7 @@ export default class CdcChunker extends ChunkingPort {
265
285
  minChunkSize = 65_536,
266
286
  maxChunkSize = 1_048_576,
267
287
  targetChunkSize = 262_144,
288
+ normalized = true,
268
289
  } = {}) {
269
290
  super();
270
291
  if (minChunkSize > maxChunkSize) {
@@ -286,11 +307,18 @@ export default class CdcChunker extends ChunkingPort {
286
307
  this.#minChunkSize = minChunkSize;
287
308
  this.#maxChunkSize = maxChunkSize;
288
309
  this.#targetChunkSize = targetChunkSize;
310
+ this.#normalized = normalized;
289
311
 
290
312
  // Mask: nearest power-of-2 minus 1 that is <= targetChunkSize.
291
313
  // E.g. target 262144 (2^18) -> mask 0x3FFFF (2^18 - 1).
292
314
  const bits = Math.floor(Math.log2(targetChunkSize));
293
315
  this.#mask = ((1 << bits) - 1) >>> 0;
316
+
317
+ // Dual-mask for normalized mode (FastCDC):
318
+ // hardMask: more bits → less likely to match (below target)
319
+ // easyMask: fewer bits → more likely to match (above target)
320
+ this.#hardMask = ((1 << Math.min(bits + 1, 31)) - 1) >>> 0;
321
+ this.#easyMask = ((1 << Math.max(bits - 1, 1)) - 1) >>> 0;
294
322
  }
295
323
 
296
324
  /** @override */
@@ -304,18 +332,19 @@ export default class CdcChunker extends ChunkingPort {
304
332
  target: this.#targetChunkSize,
305
333
  min: this.#minChunkSize,
306
334
  max: this.#maxChunkSize,
335
+ normalized: this.#normalized,
307
336
  };
308
337
  }
309
338
 
310
339
  /**
311
340
  * Splits an async byte stream into content-defined chunks.
312
341
  *
313
- * Yields `Buffer` instances. The caller may concatenate them or write
342
+ * Yields `Uint8Array` instances. The caller may concatenate them or write
314
343
  * each one directly to storage.
315
344
  *
316
345
  * @override
317
- * @param {AsyncIterable<Buffer>} source - Incoming byte stream.
318
- * @yields {Buffer} Content-defined chunks.
346
+ * @param {AsyncIterable<Uint8Array>} source - Incoming byte stream.
347
+ * @yields {Uint8Array} Content-defined chunks.
319
348
  */
320
349
  async *chunk(source) {
321
350
  /** @type {ChunkState} */
@@ -324,21 +353,26 @@ export default class CdcChunker extends ChunkingPort {
324
353
  win: new Uint8Array(WINDOW_SIZE),
325
354
  winPos: 0,
326
355
  hashFed: 0,
327
- chunkBuf: Buffer.allocUnsafe(this.#maxChunkSize),
356
+ chunkBuf: new Uint8Array(this.#maxChunkSize),
328
357
  chunkLen: 0,
329
358
  minSize: this.#minChunkSize,
330
359
  maxSize: this.#maxChunkSize,
331
360
  mask: this.#mask,
361
+ hardMask: this.#hardMask,
362
+ easyMask: this.#easyMask,
363
+ targetSize: this.#targetChunkSize,
364
+ normalized: this.#normalized,
332
365
  };
333
366
 
334
- for await (const buf of source) {
367
+ for await (const chunk of source) {
368
+ const buf = normalizeByteChunk(chunk);
335
369
  const chunks = processBuf(st, buf);
336
370
  for (const c of chunks) { yield c; }
337
371
  }
338
372
 
339
373
  // Flush final partial chunk (may be < minSize — allowed for EOF).
340
374
  if (st.chunkLen > 0) {
341
- yield Buffer.from(st.chunkBuf.subarray(0, st.chunkLen));
375
+ yield new Uint8Array(st.chunkBuf.subarray(0, st.chunkLen));
342
376
  }
343
377
  }
344
378
  }
@@ -1,4 +1,5 @@
1
1
  import ChunkingPort from '../../ports/ChunkingPort.js';
2
+ import { copyBytes, normalizeByteChunk } from '../../domain/bytes/ByteLayout.js';
2
3
 
3
4
  /**
4
5
  * {@link ChunkingPort} implementation that splits data into fixed-size chunks.
@@ -40,30 +41,37 @@ export default class FixedChunker extends ChunkingPort {
40
41
 
41
42
  /**
42
43
  * @override
43
- * @param {AsyncIterable<Buffer>} source - The input byte stream.
44
- * @yields {Buffer}
44
+ * @param {AsyncIterable<Uint8Array>} source - The input byte stream.
45
+ * @yields {Uint8Array}
45
46
  */
46
47
  async *chunk(source) {
47
48
  const cs = this.#chunkSize;
48
- const buf = Buffer.allocUnsafe(cs);
49
+ const buf = new Uint8Array(cs);
49
50
  let offset = 0;
50
51
 
51
- for await (const data of source) {
52
+ for await (const chunk of source) {
53
+ const data = normalizeByteChunk(chunk);
52
54
  let srcPos = 0;
53
55
  while (srcPos < data.length) {
54
56
  const n = Math.min(cs - offset, data.length - srcPos);
55
- data.copy(buf, offset, srcPos, srcPos + n);
57
+ copyBytes({
58
+ source: data,
59
+ target: buf,
60
+ targetOffset: offset,
61
+ sourceStart: srcPos,
62
+ sourceEnd: srcPos + n,
63
+ });
56
64
  offset += n;
57
65
  srcPos += n;
58
66
  if (offset === cs) {
59
- yield Buffer.from(buf);
67
+ yield new Uint8Array(buf);
60
68
  offset = 0;
61
69
  }
62
70
  }
63
71
  }
64
72
 
65
73
  if (offset > 0) {
66
- yield Buffer.from(buf.subarray(0, offset));
74
+ yield new Uint8Array(buf.subarray(0, offset));
67
75
  }
68
76
  }
69
77
  }
@@ -30,9 +30,11 @@ export default function resolveChunker({ chunker, chunking } = {}) {
30
30
  targetChunkSize: chunking.targetChunkSize,
31
31
  minChunkSize: chunking.minChunkSize,
32
32
  maxChunkSize: chunking.maxChunkSize,
33
+ normalized: chunking.normalized,
33
34
  });
34
35
  }
35
- // 'fixed' or unrecognized — fall through to default (FixedChunker via CasService)
36
+ // 'fixed' with valid chunkSize → FixedChunker; otherwise fall through
37
+ // to CasService's built-in FixedChunker default.
36
38
  if (chunking.strategy === 'fixed'
37
39
  && typeof chunking.chunkSize === 'number'
38
40
  && Number.isFinite(chunking.chunkSize)
@@ -8,7 +8,7 @@ export default class CborCodec extends CodecPort {
8
8
  /**
9
9
  * @override
10
10
  * @param {Record<string, unknown>} data - Data to encode.
11
- * @returns {Buffer}
11
+ * @returns {Uint8Array}
12
12
  */
13
13
  encode(data) {
14
14
  return encode(data);
@@ -16,11 +16,11 @@ export default class CborCodec extends CodecPort {
16
16
 
17
17
  /**
18
18
  * @override
19
- * @param {Buffer|string} buffer - CBOR-encoded data.
19
+ * @param {Uint8Array} buffer - CBOR-encoded data.
20
20
  * @returns {Record<string, unknown>}
21
21
  */
22
22
  decode(buffer) {
23
- return decode(/** @type {Buffer} */ (buffer));
23
+ return decode(buffer);
24
24
  }
25
25
 
26
26
  /** @override */
@@ -1,4 +1,5 @@
1
1
  import CodecPort from '../../ports/CodecPort.js';
2
+ import { utf8Decode, utf8Encode } from '../../domain/encoding/utf8.js';
2
3
 
3
4
  /**
4
5
  * {@link CodecPort} implementation that serializes manifests as pretty-printed JSON.
@@ -7,21 +8,20 @@ export default class JsonCodec extends CodecPort {
7
8
  /**
8
9
  * @override
9
10
  * @param {Record<string, unknown>} data - Data to encode.
10
- * @returns {string}
11
+ * @returns {Uint8Array}
11
12
  */
12
13
  encode(data) {
13
- // Determine if we need to handle Buffers specially for JSON
14
14
  // For now, we assume data is JSON-safe or uses toJSON() methods
15
- return JSON.stringify(data, null, 2);
15
+ return utf8Encode(JSON.stringify(data, null, 2));
16
16
  }
17
17
 
18
18
  /**
19
19
  * @override
20
- * @param {Buffer|string} buffer - JSON-encoded data.
20
+ * @param {Uint8Array} buffer - JSON-encoded data.
21
21
  * @returns {Record<string, unknown>}
22
22
  */
23
23
  decode(buffer) {
24
- return JSON.parse(buffer.toString('utf8'));
24
+ return JSON.parse(utf8Decode(buffer));
25
25
  }
26
26
 
27
27
  /** @override */
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @fileoverview Shared GitPlumbing factory helpers for runtime-aware CLI and
3
+ * test wiring.
4
+ */
5
+
6
+ import GitPlumbingFactoryAdapter, {
7
+ resolveGitRunnerEnv,
8
+ } from './adapters/GitPlumbingFactoryAdapter.js';
9
+
10
+ const defaultFactory = new GitPlumbingFactoryAdapter();
11
+
12
+ export { resolveGitRunnerEnv };
13
+
14
+ /**
15
+ * Construct a GitPlumbing instance for the requested working tree.
16
+ *
17
+ * @param {{ cwd?: string, env?: string, factory?: GitPlumbingFactoryAdapter }} [options]
18
+ * @returns {Promise<import('@git-stunts/plumbing').default>}
19
+ */
20
+ export async function createGitPlumbing({ cwd = '.', env, factory = defaultFactory } = {}) {
21
+ return await factory.create({ cwd, env });
22
+ }
@@ -0,0 +1 @@
1
+ export const PACKAGE_VERSION = '6.0.0';
@@ -35,9 +35,9 @@ export default class ChunkingPort {
35
35
  * Splits an async byte stream into chunks.
36
36
  *
37
37
  * @abstract
38
- * @param {AsyncIterable<Buffer>} _source - The input byte stream.
39
- * @yields {Buffer} Chunks of data whose size depends on the strategy.
40
- * @returns {AsyncGenerator<Buffer>}
38
+ * @param {AsyncIterable<Uint8Array>} _source - The input byte stream.
39
+ * @yields {Uint8Array} Chunks of data whose size depends on the strategy.
40
+ * @returns {AsyncGenerator<Uint8Array>}
41
41
  */
42
42
  async *chunk(_source) { // eslint-disable-line require-yield
43
43
  throw new Error('Not implemented');
@@ -4,17 +4,17 @@
4
4
  */
5
5
  export default class CodecPort {
6
6
  /**
7
- * Encodes data to a Buffer or string.
7
+ * Encodes data to bytes.
8
8
  * @param {Record<string, unknown>} _data - Data to encode.
9
- * @returns {Buffer|string}
9
+ * @returns {Uint8Array}
10
10
  */
11
11
  encode(_data) {
12
12
  throw new Error('Not implemented');
13
13
  }
14
14
 
15
15
  /**
16
- * Decodes data from a Buffer or string.
17
- * @param {Buffer|string} _buffer - Encoded data to decode.
16
+ * Decodes data from bytes.
17
+ * @param {Uint8Array} _buffer - Encoded data to decode.
18
18
  * @returns {Record<string, unknown>}
19
19
  */
20
20
  decode(_buffer) {
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Abstract port for compression and decompression of buffers and streams.
3
+ *
4
+ * Implementations provide a specific compression algorithm (e.g. gzip)
5
+ * and expose both buffer and streaming interfaces.
6
+ *
7
+ * @abstract
8
+ */
9
+ export default class CompressionPort {
10
+ constructor() {
11
+ if (new.target === CompressionPort) {
12
+ throw new Error('CompressionPort is abstract and cannot be instantiated directly');
13
+ }
14
+ }
15
+
16
+ /**
17
+ * Compresses a buffer.
18
+ * @abstract
19
+ * @param {Uint8Array} _buffer - Data to compress.
20
+ * @returns {Promise<Uint8Array>} Compressed data.
21
+ */
22
+ async compressBuffer(_buffer) {
23
+ throw new Error('Not implemented');
24
+ }
25
+
26
+ /**
27
+ * Decompresses a buffer.
28
+ * @abstract
29
+ * @param {Uint8Array} _buffer - Compressed data to decompress.
30
+ * @returns {Promise<Uint8Array>} Decompressed data.
31
+ */
32
+ async decompressBuffer(_buffer) {
33
+ throw new Error('Not implemented');
34
+ }
35
+
36
+ /**
37
+ * Compresses an async byte stream.
38
+ * @abstract
39
+ * @param {AsyncIterable<Uint8Array>} _source - The input byte stream.
40
+ * @yields {Uint8Array} Compressed chunks.
41
+ * @returns {AsyncGenerator<Uint8Array>}
42
+ */
43
+ async *compressStream(_source) { // eslint-disable-line require-yield
44
+ throw new Error('Not implemented');
45
+ }
46
+
47
+ /**
48
+ * Decompresses an async byte stream.
49
+ * @abstract
50
+ * @param {AsyncIterable<Uint8Array>} _source - The compressed byte stream.
51
+ * @yields {Uint8Array} Decompressed chunks.
52
+ * @returns {AsyncGenerator<Uint8Array>}
53
+ */
54
+ async *decompressStream(_source) { // eslint-disable-line require-yield
55
+ throw new Error('Not implemented');
56
+ }
57
+ }