@git-stunts/git-cas 5.3.2 → 6.0.1

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 +1027 -0
  2. package/ARCHITECTURE.md +514 -0
  3. package/CHANGELOG.md +449 -5
  4. package/CODE_OF_CONDUCT.md +33 -0
  5. package/GUIDE.md +926 -0
  6. package/README.md +106 -366
  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 +1255 -212
  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 +367 -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 +2254 -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 +273 -80
  60. package/index.js +220 -59
  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 +153 -53
  103. package/src/domain/services/CasService.js +322 -837
  104. package/src/domain/services/ChunkRepository.js +268 -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 +180 -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 +10 -6
  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
@@ -2,48 +2,91 @@
2
2
  * Encryption info card — visual summary of vault crypto configuration.
3
3
  */
4
4
 
5
- import { box, badge, headerBox } from '@flyingrobots/bijou';
5
+ import { badge, createSurface, parseAnsiToSurface } from '@flyingrobots/bijou';
6
+ import { hstackSurface, vstackSurface } from '@flyingrobots/bijou-tui';
6
7
  import { getCliContext } from './context.js';
8
+ import { sectionHeading, themeText } from './theme.js';
9
+
10
+ function textSurface(text, width) {
11
+ return parseAnsiToSurface(text, Math.max(1, width), 1);
12
+ }
13
+
14
+ function stripAnsiLength(str) {
15
+ // eslint-disable-next-line no-control-regex
16
+ return str.replace(/\x1b\[[0-9;]*m/g, '').length;
17
+ }
18
+
19
+ /**
20
+ * Build key-value rows for the encryption profile.
21
+ *
22
+ * @param {{ cipher: string, kdf: any }} encryption
23
+ * @returns {[string, string][]}
24
+ */
25
+ function buildKdfRows(encryption) {
26
+ const { kdf } = encryption;
27
+ /** @type {[string, string][]} */
28
+ const rows = [
29
+ ['cipher', encryption.cipher],
30
+ ['kdf', kdf.algorithm],
31
+ ];
32
+ if (kdf.algorithm === 'pbkdf2') {
33
+ rows.push(['iterations', /** @type {number} */ (kdf.iterations).toLocaleString()]);
34
+ } else if (kdf.algorithm === 'scrypt') {
35
+ rows.push(['cost', String(kdf.cost)]);
36
+ rows.push(['blockSize', String(kdf.blockSize)]);
37
+ rows.push(['parallel', String(kdf.parallelization)]);
38
+ }
39
+ rows.push(['key length', `${kdf.keyLength} bytes`]);
40
+ rows.push(['salt', `${kdf.salt.slice(0, 12)}...`]);
41
+ return rows;
42
+ }
7
43
 
8
44
  /**
9
45
  * Render an encryption info card for the vault.
10
46
  *
11
47
  * @param {Object} options
12
- * @param {import('../../index.js').VaultMetadata | null} options.metadata - Vault metadata (from getVaultMetadata()).
13
- * @param {boolean} [options.unlocked] - Whether a key/passphrase was provided.
14
- * @returns {string}
48
+ * @param {import('../../index.js').VaultMetadata | null} options.metadata
49
+ * @param {boolean} [options.unlocked]
50
+ * @returns {import('@flyingrobots/bijou').Surface}
15
51
  */
16
52
  export function renderEncryptionCard({ metadata, unlocked = false }) {
17
53
  const ctx = getCliContext();
18
54
 
19
55
  if (!metadata?.encryption) {
20
- return box('No encryption configured', { ctx });
56
+ return textSurface('No encryption configured', 26);
21
57
  }
22
58
 
23
- const { encryption } = metadata;
24
- const { kdf } = encryption;
59
+ const rows = buildKdfRows(metadata.encryption);
60
+ const maxKey = Math.max(...rows.map(([k]) => k.length));
25
61
 
26
- const status = unlocked
27
- ? badge('unlocked', { variant: 'success', ctx })
28
- : badge('locked', { variant: 'error', ctx });
62
+ const kvSurfaces = rows.map(([k, v]) => {
63
+ const label = themeText(ctx, k.padEnd(maxKey), { tone: 'accent' });
64
+ return hstackSurface(2,
65
+ createSurface(2, 1),
66
+ textSurface(label, stripAnsiLength(label)),
67
+ textSurface(v, stripAnsiLength(v))
68
+ );
69
+ });
29
70
 
30
- const rows = [
31
- ` cipher ${encryption.cipher}`,
32
- ` kdf ${kdf.algorithm}`,
33
- ];
71
+ const statusBadge = badge(unlocked ? 'unlocked' : 'locked', {
72
+ variant: unlocked ? 'success' : 'danger',
73
+ ctx,
74
+ });
34
75
 
35
- if (kdf.algorithm === 'pbkdf2') {
36
- rows.push(` iterations ${/** @type {number} */ (kdf.iterations).toLocaleString()}`);
37
- } else if (kdf.algorithm === 'scrypt') {
38
- rows.push(` cost ${kdf.cost}`);
39
- rows.push(` blockSize ${kdf.blockSize}`);
40
- rows.push(` parallel ${kdf.parallelization}`);
41
- }
76
+ const statusLabel = themeText(ctx, 'status'.padEnd(maxKey), { tone: 'accent' });
77
+ const statusRow = hstackSurface(2,
78
+ createSurface(2, 1),
79
+ textSurface(statusLabel, stripAnsiLength(statusLabel)),
80
+ statusBadge,
81
+ );
42
82
 
43
- rows.push(` key length ${kdf.keyLength} bytes`);
44
- rows.push(` salt ${kdf.salt.slice(0, 12)}...`);
45
- rows.push(` status ${status}`);
83
+ const headingText = sectionHeading(ctx, 'Encryption Profile', 'warning');
46
84
 
47
- const content = rows.join('\n');
48
- return `${headerBox('Encryption', { ctx })}\n${box(content, { ctx })}`;
85
+ return vstackSurface(
86
+ textSurface(themeText(ctx, 'Vault Envelope', { tone: 'brand' }), 14),
87
+ textSurface(themeText(ctx, 'Cipher, KDF shape, and unlock posture.', { tone: 'subdued' }), 38),
88
+ textSurface(headingText, stripAnsiLength(headingText)),
89
+ ...kvSurfaces,
90
+ statusRow
91
+ );
49
92
  }
package/bin/ui/heatmap.js CHANGED
@@ -2,19 +2,16 @@
2
2
  * Chunk heatmap visualization — visual block map of chunks.
3
3
  */
4
4
 
5
- import { gradientText } from '@flyingrobots/bijou';
6
5
  import { getCliContext } from './context.js';
6
+ import { renderHeatmapGrid } from './blocks/heatmap-block.js';
7
7
 
8
8
  /**
9
9
  * @typedef {import('../../src/domain/value-objects/Manifest.js').ManifestData} ManifestData
10
10
  * @typedef {import('../../src/domain/value-objects/Manifest.js').SubManifestRef} SubManifestRef
11
11
  */
12
12
 
13
- /** @type {import('@flyingrobots/bijou').GradientStop[]} */
14
- const GRADIENT_STOPS = [
15
- { pos: 0, color: [0, 255, 255] },
16
- { pos: 1, color: [255, 0, 255] },
17
- ];
13
+ const HEATMAP_MAX_WIDTH = 60;
14
+ const HEATMAP_MARGIN = 10;
18
15
 
19
16
  /**
20
17
  * Format bytes as human-readable string.
@@ -35,39 +32,6 @@ function formatBytes(bytes) {
35
32
  return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GiB`;
36
33
  }
37
34
 
38
- /**
39
- * Build the block grid string from chunks.
40
- *
41
- * @param {ManifestData['chunks']} chunks
42
- * @param {Set<number>} boundaries
43
- * @param {number} width
44
- * @returns {string}
45
- */
46
- function buildGrid(chunks, boundaries, width) {
47
- let grid = '';
48
- let col = 0;
49
-
50
- for (let i = 0; i < chunks.length; i++) {
51
- if (boundaries.has(i) && col > 0) {
52
- grid += '\n';
53
- col = 0;
54
- }
55
-
56
- grid += '\u2588';
57
- col++;
58
-
59
- if (col >= width) {
60
- grid += '\n';
61
- col = 0;
62
- }
63
- }
64
-
65
- if (col > 0) {
66
- grid += '\n';
67
- }
68
- return grid;
69
- }
70
-
71
35
  /**
72
36
  * Build the legend line.
73
37
  *
@@ -88,33 +52,41 @@ function buildLegend(chunks, subManifests) {
88
52
  }
89
53
 
90
54
  /**
91
- * Render a chunk heatmap for a manifest.
55
+ * Collect sub-manifest boundary indices.
56
+ *
57
+ * @param {SubManifestRef[]} subManifests
58
+ * @returns {number[]}
59
+ */
60
+ function collectBreaks(subManifests) {
61
+ return subManifests
62
+ .filter((sm) => sm.startIndex > 0)
63
+ .map((sm) => sm.startIndex);
64
+ }
65
+
66
+ /**
67
+ * Render a chunk heatmap for pre-normalized manifest data.
92
68
  *
93
69
  * @param {Object} options
94
- * @param {ManifestData | { toJSON(): ManifestData }} options.manifest - The manifest (Manifest instance or plain ManifestData).
70
+ * @param {ManifestData} options.manifest - Pre-normalized manifest data.
95
71
  * @returns {string}
96
72
  */
97
73
  export function renderHeatmap({ manifest }) {
98
74
  const ctx = getCliContext();
99
- const m = /** @type {ManifestData} */ ('toJSON' in manifest ? manifest.toJSON() : manifest);
100
- const chunks = m.chunks || [];
75
+ const chunks = manifest.chunks || [];
101
76
 
102
77
  if (chunks.length === 0) {
103
78
  return 'No chunks to display\n';
104
79
  }
105
80
 
106
- const width = Math.min(60, (ctx.runtime.columns || 80) - 10);
107
- const subManifests = m.subManifests || [];
108
-
109
- const boundaries = new Set();
110
- for (const sm of subManifests) {
111
- if (sm.startIndex > 0) {
112
- boundaries.add(sm.startIndex);
113
- }
114
- }
81
+ const width = Math.min(HEATMAP_MAX_WIDTH, (ctx.runtime.columns || 80) - HEATMAP_MARGIN);
82
+ const subManifests = manifest.subManifests || [];
83
+ const breaks = collectBreaks(subManifests);
115
84
 
116
- const grid = buildGrid(chunks, boundaries, width);
117
- const colored = gradientText(grid, GRADIENT_STOPS, { style: ctx.style });
85
+ const colored = renderHeatmapGrid(chunks.length, {
86
+ width,
87
+ breaks,
88
+ style: ctx.style,
89
+ });
118
90
  const legend = buildLegend(chunks, subManifests);
119
91
 
120
92
  return `${colored}\n${legend}\n`;
@@ -5,14 +5,22 @@
5
5
  import { timeline, paginator } from '@flyingrobots/bijou';
6
6
  import { getCliContext } from './context.js';
7
7
 
8
+ /**
9
+ * @typedef {{ oid: string, operation: string, slug: string | null }} VaultCommitEvent
10
+ */
11
+
8
12
  /**
9
13
  * Parse a vault commit line into structured data.
10
14
  * Input format: "eff5569 vault: add photos/beach"
11
15
  *
16
+ * This is git-log output parsing — an infrastructure/adapter concern
17
+ * exported here for convenience. Callers doing their own git interaction
18
+ * should use this to normalize raw log lines before passing to the view.
19
+ *
12
20
  * @param {string} line
13
- * @returns {{ oid: string, operation: string, slug: string|null }|null}
21
+ * @returns {VaultCommitEvent | null}
14
22
  */
15
- function parseCommitLine(line) {
23
+ export function parseCommitLine(line) {
16
24
  const trimmed = line.trim();
17
25
  if (!trimmed) {
18
26
  return null;
@@ -34,6 +42,20 @@ function parseCommitLine(line) {
34
42
  return { oid, operation: match[1], slug: match[2] || null };
35
43
  }
36
44
 
45
+ /**
46
+ * Parse raw git log output into structured vault commit events.
47
+ *
48
+ * @param {string} gitLogOutput - Raw output from `git log --oneline`.
49
+ * @returns {VaultCommitEvent[]}
50
+ */
51
+ export function parseGitLog(gitLogOutput) {
52
+ return gitLogOutput
53
+ .split('\n')
54
+ .filter(Boolean)
55
+ .map(parseCommitLine)
56
+ .filter(/** @returns {e is VaultCommitEvent} */ (e) => e !== null);
57
+ }
58
+
37
59
  /** @type {Record<string, string>} */
38
60
  const STATUS_MAP = {
39
61
  init: 'info',
@@ -44,39 +66,34 @@ const STATUS_MAP = {
44
66
  };
45
67
 
46
68
  /**
47
- * Render vault history as a color-coded timeline.
69
+ * Render vault history as a color-coded timeline from pre-parsed events.
48
70
  *
49
- * @param {string} gitLogOutput - Raw output from `git log --oneline`.
71
+ * @param {VaultCommitEvent[]} events - Pre-parsed vault commit events.
50
72
  * @param {Object} [options]
51
73
  * @param {number} [options.page] - Current page (1-based).
52
74
  * @param {number} [options.perPage] - Entries per page (default 20).
53
75
  * @returns {string}
54
76
  */
55
- export function renderHistoryTimeline(gitLogOutput, options = {}) {
77
+ export function renderTimeline(events, options = {}) {
56
78
  const ctx = getCliContext();
57
79
  const perPage = options.perPage ?? 20;
58
80
  const page = options.page ?? 1;
59
81
 
60
- const lines = gitLogOutput.split('\n').filter(Boolean);
61
- if (lines.length === 0) {
82
+ if (events.length === 0) {
62
83
  return 'No history\n';
63
84
  }
64
85
 
65
- const totalPages = Math.ceil(lines.length / perPage);
86
+ const totalPages = Math.ceil(events.length / perPage);
66
87
  const start = (page - 1) * perPage;
67
- const pageLines = lines.slice(start, start + perPage);
88
+ const pageEvents = events.slice(start, start + perPage);
68
89
 
69
- const parsed = pageLines.map(parseCommitLine).filter(Boolean);
70
- const events = parsed.map((entry) => {
71
- const { oid, operation, slug } = /** @type {{ oid: string, operation: string, slug: string | null }} */ (entry);
72
- return {
73
- label: slug ? `vault: ${operation} ${slug}` : `vault: ${operation}`,
74
- description: oid,
75
- status: /** @type {import('@flyingrobots/bijou').BaseStatusKey} */ (STATUS_MAP[operation] || 'pending'),
76
- };
77
- });
90
+ const timelineData = pageEvents.map(({ oid, operation, slug }) => ({
91
+ label: slug ? `vault: ${operation} ${slug}` : `vault: ${operation}`,
92
+ description: oid,
93
+ status: /** @type {import('@flyingrobots/bijou').BaseStatusKey} */ (STATUS_MAP[operation] || 'pending'),
94
+ }));
78
95
 
79
- let output = timeline(events, { ctx });
96
+ let output = timeline(timelineData, { ctx });
80
97
 
81
98
  if (totalPages > 1) {
82
99
  output += `\n${paginator({ current: page, total: totalPages, ctx })}`;
@@ -84,3 +101,18 @@ export function renderHistoryTimeline(gitLogOutput, options = {}) {
84
101
 
85
102
  return output;
86
103
  }
104
+
105
+ /**
106
+ * Render vault history from raw git log output (convenience wrapper).
107
+ *
108
+ * Parses the raw log, then delegates to renderTimeline.
109
+ *
110
+ * @param {string} gitLogOutput - Raw output from `git log --oneline`.
111
+ * @param {Object} [options]
112
+ * @param {number} [options.page] - Current page (1-based).
113
+ * @param {number} [options.perPage] - Entries per page (default 20).
114
+ * @returns {string}
115
+ */
116
+ export function renderHistoryTimeline(gitLogOutput, options = {}) {
117
+ return renderTimeline(parseGitLog(gitLogOutput), options);
118
+ }
@@ -2,12 +2,16 @@
2
2
  * Manifest anatomy view — rich visual breakdown of a manifest.
3
3
  */
4
4
 
5
- import { box, badge, table, tree, headerBox } from '@flyingrobots/bijou';
5
+ import { box } from '@flyingrobots/bijou';
6
6
  import { getCliContext } from './context.js';
7
+ import { renderBadgeRow } from './blocks/asset-card.js';
8
+ import { renderChunkTable, renderSubManifestTree } from './blocks/merkle-explorer.js';
9
+ import { sectionHeading, themeText } from './theme.js';
7
10
 
8
11
  /**
9
12
  * @typedef {import('../../src/domain/value-objects/Manifest.js').ManifestData} ManifestData
10
13
  * @typedef {import('@flyingrobots/bijou').BijouContext} BijouContext
14
+ * @typedef {import('@flyingrobots/bijou').AccordionSection} AccordionSection
11
15
  */
12
16
 
13
17
  /**
@@ -30,98 +34,114 @@ function formatBytes(bytes) {
30
34
  }
31
35
 
32
36
  /**
33
- * Build the header badges line.
37
+ * Format key-value pairs with aligned themed labels.
34
38
  *
35
- * @param {ManifestData} m
39
+ * @param {[string, string][]} rows
36
40
  * @param {BijouContext} ctx
37
41
  * @returns {string}
38
42
  */
39
- function renderBadges(m, ctx) {
40
- const badges = [badge(`v${m.version}`, { ctx })];
41
- if (m.encryption) {
42
- badges.push(badge('encrypted', { variant: 'warning', ctx }));
43
- }
44
- if (m.compression) {
45
- badges.push(badge(m.compression.algorithm, { variant: 'info', ctx }));
46
- }
47
- if (m.subManifests?.length) {
48
- badges.push(badge('merkle', { variant: 'info', ctx }));
49
- }
50
- return badges.join(' ');
43
+ function formatKv(rows, ctx) {
44
+ const maxKey = Math.max(...rows.map(([k]) => k.length));
45
+ return rows.map(([k, v]) => ` ${themeText(ctx, k.padEnd(maxKey), { tone: 'accent' })} ${v}`).join('\n');
51
46
  }
52
47
 
48
+ // Badge rendering delegated to blocks/asset-card.js (renderBadgeRow)
49
+
53
50
  /**
54
- * Build the encryption section.
51
+ * Build the encryption section body.
55
52
  *
56
53
  * @param {NonNullable<ManifestData['encryption']>} enc
57
54
  * @param {BijouContext} ctx
58
55
  * @returns {string}
59
56
  */
60
- function renderEncryptionSection(enc, ctx) {
61
- const rows = [` algorithm ${enc.algorithm}`];
57
+ function encryptionBody(enc, ctx) {
58
+ /** @type {[string, string][]} */
59
+ const rows = [['algorithm', enc.algorithm]];
62
60
  if (enc.kdf) {
63
- rows.push(` kdf ${enc.kdf.algorithm}`);
61
+ rows.push(['kdf', enc.kdf.algorithm]);
64
62
  if (enc.kdf.iterations) {
65
- rows.push(` iterations ${enc.kdf.iterations.toLocaleString()}`);
63
+ rows.push(['iterations', enc.kdf.iterations.toLocaleString()]);
66
64
  }
67
65
  if (enc.kdf.cost) {
68
- rows.push(` cost ${enc.kdf.cost}`);
66
+ rows.push(['cost', String(enc.kdf.cost)]);
69
67
  }
70
68
  }
71
69
  if (enc.nonce) {
72
- rows.push(` nonce ${enc.nonce.slice(0, 16)}...`);
70
+ rows.push(['nonce', `${enc.nonce.slice(0, 16)}...`]);
73
71
  }
74
72
  if (enc.tag) {
75
- rows.push(` tag ${enc.tag.slice(0, 16)}...`);
73
+ rows.push(['tag', `${enc.tag.slice(0, 16)}...`]);
76
74
  }
77
- return `${headerBox('Encryption', { ctx })}\n${box(rows.join('\n'), { ctx })}`;
75
+ return box(formatKv(rows, ctx), { ctx });
78
76
  }
79
77
 
80
78
  /**
81
- * Build the chunks section.
79
+ * Build the encryption section (headed).
80
+ *
81
+ * @param {NonNullable<ManifestData['encryption']>} enc
82
+ * @param {BijouContext} ctx
83
+ * @returns {string}
84
+ */
85
+ function renderEncryptionSection(enc, ctx) {
86
+ return `${sectionHeading(ctx, 'Encryption Profile', 'warning')}\n${encryptionBody(enc, ctx)}`;
87
+ }
88
+
89
+ /**
90
+ * Build the chunks section body.
82
91
  *
83
92
  * @param {ManifestData['chunks']} chunks
84
93
  * @param {BijouContext} ctx
85
94
  * @returns {string}
86
95
  */
87
- function renderChunksSection(chunks, ctx) {
88
- const displayChunks = chunks.slice(0, 20);
89
- const chunkRows = displayChunks.map((/** @type {{ index: number, size: number, digest: string, blob?: string }} */ c) => [
90
- String(c.index),
91
- formatBytes(c.size),
92
- typeof c.digest === 'string' ? `${c.digest.slice(0, 12)}...` : '-',
93
- typeof c.blob === 'string' ? `${c.blob.slice(0, 12)}...` : '-',
94
- ]);
95
- const chunkTable = table({
96
- columns: [{ header: '#' }, { header: 'Size' }, { header: 'Digest' }, { header: 'Blob' }],
97
- rows: chunkRows,
98
- ctx,
99
- });
100
- const suffix = chunks.length > 20
101
- ? `\n ...and ${chunks.length - 20} more`
102
- : '';
103
- return `${headerBox(`Chunks (${chunks.length})`, { ctx })}\n${chunkTable}${suffix}`;
96
+ /**
97
+ * Build the chunks section (headed). Delegates to MerkleExplorer block.
98
+ *
99
+ * @param {ManifestData} m
100
+ * @param {BijouContext} ctx
101
+ * @returns {string}
102
+ */
103
+ function renderChunksSection(m, ctx) {
104
+ const chunks = m.chunks || [];
105
+ return `${sectionHeading(ctx, `Chunk Ledger (${chunks.length})`, 'info')}\n${renderChunkTable(m, ctx)}`;
104
106
  }
105
107
 
106
108
  /**
107
- * Build the metadata section.
109
+ * Build the metadata section body.
108
110
  *
109
111
  * @param {ManifestData} m
110
112
  * @param {BijouContext} ctx
111
113
  * @returns {string}
112
114
  */
113
- function renderMetadataSection(m, ctx) {
114
- const meta = [
115
- ` slug ${m.slug}`,
116
- ` filename ${m.filename}`,
117
- ` size ${formatBytes(m.size)}`,
118
- ` chunks ${m.chunks?.length ?? 0}`,
115
+ function metadataBody(m, ctx) {
116
+ const rows = [
117
+ ['slug', m.slug ?? '-'],
118
+ ['filename', m.filename ?? '-'],
119
+ ['size', formatBytes(m.size)],
120
+ ['chunks', String(m.chunks?.length ?? 0)],
119
121
  ];
120
- return `${headerBox('Metadata', { ctx })}\n${box(meta.join('\n'), { ctx })}`;
122
+ return box(formatKv(rows, ctx), { ctx });
123
+ }
124
+
125
+ /**
126
+ * Build the metadata section (headed).
127
+ *
128
+ * @param {ManifestData} m
129
+ * @param {BijouContext} ctx
130
+ * @returns {string}
131
+ */
132
+ function renderMetadataSection(m, ctx) {
133
+ return `${sectionHeading(ctx, 'Asset Metadata', 'brand')}\n${metadataBody(m, ctx)}`;
121
134
  }
122
135
 
123
136
  /**
124
- * Build the sub-manifests section.
137
+ * Build the sub-manifests section body.
138
+ *
139
+ * @param {ManifestData} m
140
+ * @param {BijouContext} ctx
141
+ * @returns {string}
142
+ */
143
+ /**
144
+ * Build the sub-manifests section (headed). Delegates to MerkleExplorer block.
125
145
  *
126
146
  * @param {ManifestData} m
127
147
  * @param {BijouContext} ctx
@@ -129,36 +149,71 @@ function renderMetadataSection(m, ctx) {
129
149
  */
130
150
  function renderSubManifestsSection(m, ctx) {
131
151
  const subs = m.subManifests || [];
132
- const nodes = subs.map((/** @type {import('../../src/domain/value-objects/Manifest.js').SubManifestRef} */ sm, /** @type {number} */ i) => ({
133
- label: `sub-${i} ${sm.chunkCount} chunks start: ${sm.startIndex} oid: ${sm.oid.slice(0, 8)}...`,
134
- }));
135
- return `${headerBox(`Sub-manifests (${subs.length})`, { ctx })}\n${tree(nodes, { ctx })}`;
152
+ return `${sectionHeading(ctx, `Merkle Branches (${subs.length})`, 'accent')}\n${renderSubManifestTree(m, ctx)}`;
136
153
  }
137
154
 
138
155
  /**
139
156
  * Render a full manifest anatomy view.
140
157
  *
141
158
  * @param {Object} options
142
- * @param {ManifestData | { toJSON(): ManifestData }} options.manifest - The manifest (Manifest instance or plain ManifestData).
159
+ * @param {ManifestData} options.manifest - Pre-normalized manifest data.
143
160
  * @param {BijouContext} [options.ctx] - Optional bijou context override.
144
161
  * @returns {string}
145
162
  */
146
163
  export function renderManifestView({ manifest, ctx = getCliContext() }) {
147
- const m = /** @type {ManifestData} */ ('toJSON' in manifest ? manifest.toJSON() : manifest);
148
- const sections = [renderBadges(m, ctx), renderMetadataSection(m, ctx)];
164
+ const m = manifest;
165
+ const badges = renderBadgeRow(m, ctx);
166
+ const sections = [themeText(ctx, 'Manifest Ledger', { tone: 'brand' })];
167
+ if (badges) {
168
+ sections.push(badges);
169
+ }
170
+ sections.push(renderMetadataSection(m, ctx));
149
171
 
150
172
  if (m.encryption) {
151
173
  sections.push(renderEncryptionSection(m.encryption, ctx));
152
174
  }
153
175
  if (m.compression) {
154
- sections.push(`${headerBox('Compression', { ctx })}\n${box(` algorithm ${m.compression.algorithm}`, { ctx })}`);
176
+ sections.push(`${sectionHeading(ctx, 'Compression Profile', 'info')}\n${box(` algorithm ${m.compression.algorithm}`, { ctx })}`);
155
177
  }
156
178
  if (m.subManifests?.length) {
157
179
  sections.push(renderSubManifestsSection(m, ctx));
158
180
  }
159
181
  if (m.chunks?.length) {
160
- sections.push(renderChunksSection(m.chunks, ctx));
182
+ sections.push(renderChunksSection(m, ctx));
161
183
  }
162
184
 
163
185
  return `${sections.join('\n\n')}\n`;
164
186
  }
187
+
188
+ /**
189
+ * Build structured accordion sections from manifest data.
190
+ *
191
+ * Each section has a title and content string. Metadata is expanded by
192
+ * default; all other sections are collapsed. Only sections relevant to the
193
+ * manifest are included (e.g. no encryption section for plaintext assets).
194
+ *
195
+ * @param {Object} options
196
+ * @param {ManifestData} options.manifest - Pre-normalized manifest data.
197
+ * @param {BijouContext} [options.ctx] - Optional bijou context override.
198
+ * @returns {AccordionSection[]}
199
+ */
200
+ export function buildManifestSections({ manifest, ctx = getCliContext() }) {
201
+ const m = manifest;
202
+ /** @type {AccordionSection[]} */
203
+ const sections = [
204
+ { title: 'Asset Metadata', content: metadataBody(m, ctx), expanded: true },
205
+ ];
206
+ if (m.encryption) {
207
+ sections.push({ title: 'Encryption Profile', content: encryptionBody(m.encryption, ctx), expanded: true });
208
+ }
209
+ if (m.compression) {
210
+ sections.push({ title: 'Compression Profile', content: box(` algorithm ${m.compression.algorithm}`, { ctx }), expanded: true });
211
+ }
212
+ if (m.subManifests?.length) {
213
+ sections.push({ title: `Merkle Branches (${m.subManifests.length})`, content: renderSubManifestTree(m, ctx), expanded: true });
214
+ }
215
+ if (m.chunks?.length) {
216
+ sections.push({ title: `Chunk Ledger (${m.chunks.length})`, content: renderChunkTable(m, ctx), expanded: true });
217
+ }
218
+ return sections;
219
+ }