@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
@@ -0,0 +1,367 @@
1
+ /**
2
+ * Interactive store wizard — guided flow for storing a file into git-cas.
3
+ *
4
+ * State machine with steps: filePath → slug → encryption → passphrase → compression → chunking → confirm.
5
+ * Renders within the TUI overlay system using the TEA architecture.
6
+ * Delegates generic step handling and rendering to WizardBlock.
7
+ */
8
+
9
+ import {
10
+ handleSelectKey,
11
+ handleTextKey,
12
+ handleToggleKey,
13
+ renderFieldLine,
14
+ renderSelectList,
15
+ renderTextInput,
16
+ renderToggle,
17
+ renderWizardPanel,
18
+ } from './blocks/wizard-block.js';
19
+ import { themeText } from './theme.js';
20
+
21
+ /**
22
+ * @typedef {import('@flyingrobots/bijou').BijouContext} BijouContext
23
+ * @typedef {import('@flyingrobots/bijou').Surface} Surface
24
+ */
25
+
26
+ /**
27
+ * @typedef {'filePath' | 'slug' | 'encryption' | 'passphrase' | 'compression' | 'chunking' | 'confirm' | 'storing' | 'done' | 'error'} WizardStep
28
+ */
29
+
30
+ /**
31
+ * @typedef {Object} StoreWizardState
32
+ * @property {WizardStep} step
33
+ * @property {string} filePath
34
+ * @property {string} slug
35
+ * @property {'none' | 'passphrase' | 'convergent'} encryption
36
+ * @property {string} passphrase
37
+ * @property {boolean} passphraseVisible
38
+ * @property {boolean} compression
39
+ * @property {'fixed' | 'cdc'} chunking
40
+ * @property {number} selectIndex
41
+ * @property {string | null} error
42
+ * @property {string | null} resultSlug
43
+ */
44
+
45
+ const ENCRYPTION_OPTIONS = ['none', 'passphrase', 'convergent'];
46
+ const CHUNKING_OPTIONS = ['fixed', 'cdc'];
47
+
48
+ /**
49
+ * Create a fresh wizard state.
50
+ *
51
+ * @returns {StoreWizardState}
52
+ */
53
+ export function createWizardState() {
54
+ return {
55
+ step: 'filePath',
56
+ filePath: '',
57
+ slug: '',
58
+ encryption: 'none',
59
+ passphrase: '',
60
+ passphraseVisible: false,
61
+ compression: false,
62
+ chunking: 'cdc',
63
+ selectIndex: 0,
64
+ error: null,
65
+ resultSlug: null,
66
+ };
67
+ }
68
+
69
+ /**
70
+ * @param {StoreWizardState} state
71
+ * @param {string} key
72
+ * @returns {StoreWizardState}
73
+ */
74
+ function handleFilePathKey(state, key) {
75
+ const result = handleTextKey(state.filePath, key);
76
+ if (result.confirmed) {
77
+ return { ...state, filePath: result.value, step: 'slug', slug: deriveSlug(result.value) };
78
+ }
79
+ return { ...state, filePath: result.value };
80
+ }
81
+
82
+ /**
83
+ * @param {StoreWizardState} state
84
+ * @param {string} key
85
+ * @returns {StoreWizardState}
86
+ */
87
+ function handleSlugKey(state, key) {
88
+ const result = handleTextKey(state.slug, key);
89
+ if (result.confirmed) {
90
+ return {
91
+ ...state,
92
+ slug: result.value,
93
+ step: 'encryption',
94
+ selectIndex: ENCRYPTION_OPTIONS.indexOf(state.encryption),
95
+ };
96
+ }
97
+ return { ...state, slug: result.value };
98
+ }
99
+
100
+ /**
101
+ * @param {StoreWizardState} state
102
+ * @param {string} key
103
+ * @returns {StoreWizardState}
104
+ */
105
+ function handleEncryptionKey(state, key) {
106
+ const result = handleSelectKey(state.selectIndex, ENCRYPTION_OPTIONS.length, key);
107
+ if (result.confirmed) {
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 };
113
+ }
114
+ return { ...state, selectIndex: result.selectIndex };
115
+ }
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
+
130
+ /**
131
+ * @param {StoreWizardState} state
132
+ * @param {string} key
133
+ * @returns {StoreWizardState}
134
+ */
135
+ function handleCompressionKey(state, key) {
136
+ const result = handleToggleKey(state.compression, key);
137
+ if (result.confirmed) {
138
+ return {
139
+ ...state,
140
+ compression: result.value,
141
+ step: 'chunking',
142
+ selectIndex: CHUNKING_OPTIONS.indexOf(state.chunking),
143
+ };
144
+ }
145
+ return { ...state, compression: result.value };
146
+ }
147
+
148
+ /**
149
+ * @param {StoreWizardState} state
150
+ * @param {string} key
151
+ * @returns {StoreWizardState}
152
+ */
153
+ function handleChunkingKey(state, key) {
154
+ const result = handleSelectKey(state.selectIndex, CHUNKING_OPTIONS.length, key);
155
+ if (result.confirmed) {
156
+ const chunking = /** @type {'fixed' | 'cdc'} */ (CHUNKING_OPTIONS[result.selectIndex]);
157
+ return { ...state, chunking, step: 'confirm' };
158
+ }
159
+ return { ...state, selectIndex: result.selectIndex };
160
+ }
161
+
162
+ /**
163
+ * @param {StoreWizardState} state
164
+ * @param {string} key
165
+ * @returns {StoreWizardState}
166
+ */
167
+ function handleConfirmKey(state, key) {
168
+ if (key === 'enter' || key === 'y') {
169
+ return { ...state, step: 'storing' };
170
+ }
171
+ if (key === 'n' || key === 'backspace') {
172
+ return { ...state, step: 'filePath' };
173
+ }
174
+ return state;
175
+ }
176
+
177
+ /** @type {Record<string, (state: StoreWizardState, key: string) => StoreWizardState>} */
178
+ const stepHandlers = {
179
+ filePath: handleFilePathKey,
180
+ slug: handleSlugKey,
181
+ encryption: handleEncryptionKey,
182
+ passphrase: handlePassphraseKey,
183
+ compression: handleCompressionKey,
184
+ chunking: handleChunkingKey,
185
+ confirm: handleConfirmKey,
186
+ };
187
+
188
+ /**
189
+ * Handle a key press within the wizard.
190
+ *
191
+ * @param {StoreWizardState} state
192
+ * @param {string} key
193
+ * @returns {StoreWizardState}
194
+ */
195
+ export function wizardHandleKey(state, key) {
196
+ if (state.step === 'storing' || state.step === 'done') {
197
+ return state;
198
+ }
199
+ if (key === 'escape') {
200
+ return { ...state, step: 'error', error: 'Cancelled' };
201
+ }
202
+ return stepHandlers[state.step]?.(state, key) ?? state;
203
+ }
204
+
205
+ /**
206
+ * Derive a slug from a file path.
207
+ *
208
+ * @param {string} filePath
209
+ * @returns {string}
210
+ */
211
+ function deriveSlug(filePath) {
212
+ const name = filePath.split('/').pop() || filePath;
213
+ const dotIndex = name.lastIndexOf('.');
214
+ return dotIndex > 0 ? name.slice(0, dotIndex) : name;
215
+ }
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
+
235
+ /** @type {Record<string, string>} */
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',
244
+ storing: 'Storing...',
245
+ done: 'Done',
246
+ error: 'Error',
247
+ };
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
+
260
+ /**
261
+ * Render the wizard overlay surface.
262
+ *
263
+ * @param {StoreWizardState} state
264
+ * @param {{ width: number, height: number, ctx: BijouContext }} opts
265
+ * @returns {Surface}
266
+ */
267
+ export function renderWizardSurface(state, opts) {
268
+ return renderWizardPanel({
269
+ title: `Store [${stepLabel(state)}]`,
270
+ body: renderWizardBody(state, opts.ctx),
271
+ screenWidth: opts.width,
272
+ screenHeight: opts.height,
273
+ ctx: opts.ctx,
274
+ });
275
+ }
276
+
277
+ /**
278
+ * @param {StoreWizardState} state
279
+ * @param {BijouContext} ctx
280
+ * @returns {string}
281
+ */
282
+ function renderWizardBody(state, ctx) {
283
+ if (state.step === 'error') {
284
+ return themeText(ctx, state.error ?? 'Cancelled', { tone: 'danger' });
285
+ }
286
+ if (state.step === 'storing') {
287
+ return themeText(ctx, `Storing ${state.slug}...`, { tone: 'info' });
288
+ }
289
+ if (state.step === 'done') {
290
+ return themeText(ctx, `Stored ${state.resultSlug}`, { tone: 'accent' });
291
+ }
292
+ if (state.step === 'confirm') {
293
+ return renderConfirmBody(state, ctx);
294
+ }
295
+ return renderStepBody(state, ctx);
296
+ }
297
+
298
+ /**
299
+ * @param {StoreWizardState} state
300
+ * @param {BijouContext} ctx
301
+ * @returns {string}
302
+ */
303
+ function renderStepBody(state, ctx) {
304
+ /** @type {Record<string, () => string[]>} */
305
+ const renderers = {
306
+ filePath: () => [
307
+ themeText(ctx, 'File path:', { tone: 'accent' }),
308
+ renderTextInput(state.filePath),
309
+ '',
310
+ themeText(ctx, 'Type the file path, then press enter.', { tone: 'subdued' }),
311
+ ],
312
+ slug: () => [
313
+ themeText(ctx, 'Slug name:', { tone: 'accent' }),
314
+ renderTextInput(state.slug),
315
+ '',
316
+ themeText(ctx, 'Edit the slug, then press enter.', { tone: 'subdued' }),
317
+ ],
318
+ encryption: () => [
319
+ themeText(ctx, 'Encryption:', { tone: 'accent' }),
320
+ renderSelectList(state.selectIndex, ENCRYPTION_OPTIONS, ctx),
321
+ '',
322
+ themeText(ctx, 'j/k to move, enter to select.', { tone: 'subdued' }),
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
+ ],
332
+ compression: () => [
333
+ themeText(ctx, 'Compression (gzip):', { tone: 'accent' }),
334
+ renderToggle(state.compression, ctx),
335
+ '',
336
+ themeText(ctx, 'space to toggle, enter to continue.', { tone: 'subdued' }),
337
+ ],
338
+ chunking: () => [
339
+ themeText(ctx, 'Chunking strategy:', { tone: 'accent' }),
340
+ renderSelectList(state.selectIndex, CHUNKING_OPTIONS, ctx),
341
+ '',
342
+ themeText(ctx, 'j/k to move, enter to select.', { tone: 'subdued' }),
343
+ ],
344
+ };
345
+ const render = renderers[state.step];
346
+ return render ? render().join('\n') : '';
347
+ }
348
+
349
+ /**
350
+ * @param {StoreWizardState} state
351
+ * @param {BijouContext} ctx
352
+ * @returns {string}
353
+ */
354
+ function renderConfirmBody(state, ctx) {
355
+ return [
356
+ themeText(ctx, 'Review and confirm:', { tone: 'accent', bold: true }),
357
+ '',
358
+ renderFieldLine(ctx, 'File:', state.filePath),
359
+ renderFieldLine(ctx, 'Slug:', state.slug),
360
+ renderFieldLine(ctx, 'Encryption:', state.encryption),
361
+ renderFieldLine(ctx, 'Passphrase:', state.encryption === 'none' ? 'none' : 'set'),
362
+ renderFieldLine(ctx, 'Compression:', state.compression ? 'gzip' : 'none'),
363
+ renderFieldLine(ctx, 'Chunking:', state.chunking),
364
+ '',
365
+ themeText(ctx, 'enter/y to store, n/backspace to restart.', { tone: 'subdued' }),
366
+ ].join('\n');
367
+ }
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Shared visual language for git-cas terminal surfaces.
3
+ */
4
+
5
+ import { parseAnsiToSurface } from '@flyingrobots/bijou';
6
+
7
+ export const GIT_CAS_PALETTE = {
8
+ ghost: [251, 252, 252],
9
+ pearl: [228, 235, 241],
10
+ slate: [188, 203, 216],
11
+ cyan: [35, 221, 210],
12
+ orange: [255, 163, 102],
13
+ midnight: [37, 49, 58],
14
+ ink: [34, 39, 64],
15
+ ruby: [255, 111, 136],
16
+ sky: [151, 194, 255],
17
+ violet: [186, 155, 255],
18
+ deepSlate: [108, 130, 148],
19
+ };
20
+
21
+ function rgbToHex(rgb) {
22
+ return `#${rgb.map((ch) => ch.toString(16).padStart(2, '0')).join('')}`;
23
+ }
24
+
25
+ function token(rgb, modifiers = [], bg) {
26
+ return {
27
+ hex: rgbToHex(rgb),
28
+ fgRGB: rgb,
29
+ ...(bg ? { bg: rgbToHex(bg), bgRGB: bg } : {}),
30
+ ...(modifiers.length ? { modifiers } : {}),
31
+ };
32
+ }
33
+
34
+ const {
35
+ ghost, pearl, slate, cyan, orange, midnight, ink, ruby, sky, violet, deepSlate,
36
+ } = GIT_CAS_PALETTE;
37
+
38
+ /**
39
+ * Bijou v5 theme for the git-cas cockpit.
40
+ *
41
+ * Keep this object aligned with Bijou's public Theme shape. App-specific
42
+ * colors belong in local helpers, not in stray token groups that components
43
+ * will never read.
44
+ */
45
+ export const GIT_CAS_THEME = {
46
+ name: 'git-cas-cockpit',
47
+ status: {
48
+ success: token(cyan, ['bold']),
49
+ error: token(ruby, ['bold']),
50
+ warning: token(orange, ['bold']),
51
+ info: token(sky),
52
+ pending: token(slate),
53
+ active: token(cyan, ['bold']),
54
+ muted: token(deepSlate),
55
+ },
56
+ semantic: {
57
+ success: token(cyan, ['bold']),
58
+ error: token(ruby, ['bold']),
59
+ warning: token(orange, ['bold']),
60
+ info: token(sky),
61
+ accent: token(orange, ['bold']),
62
+ muted: token(slate),
63
+ primary: token(ghost),
64
+ },
65
+ gradient: {
66
+ brand: [
67
+ { pos: 0, color: cyan },
68
+ { pos: 0.38, color: sky },
69
+ { pos: 0.72, color: violet },
70
+ { pos: 1, color: orange },
71
+ ],
72
+ progress: [
73
+ { pos: 0, color: deepSlate },
74
+ { pos: 0.5, color: sky },
75
+ { pos: 1, color: cyan },
76
+ ],
77
+ },
78
+ border: {
79
+ primary: token(cyan),
80
+ secondary: token(slate),
81
+ success: token(cyan),
82
+ warning: token(orange),
83
+ error: token(ruby),
84
+ muted: token(deepSlate),
85
+ },
86
+ ui: {
87
+ cursor: token(cyan, ['bold']),
88
+ scrollThumb: token(cyan),
89
+ scrollTrack: token(deepSlate),
90
+ sectionHeader: token(orange, ['bold']),
91
+ logo: token(cyan, ['bold']),
92
+ tableHeader: token(ghost, ['bold']),
93
+ trackEmpty: token(deepSlate),
94
+ },
95
+ surface: {
96
+ primary: token(ghost, [], midnight),
97
+ secondary: token(pearl, [], [43, 58, 68]),
98
+ elevated: token(ghost, [], [51, 68, 78]),
99
+ overlay: token(ghost, [], ink),
100
+ muted: token(slate, [], [31, 41, 49]),
101
+ },
102
+ };
103
+
104
+ const TEXT_TONES = {
105
+ brand: { fg: cyan, bold: true },
106
+ accent: { fg: orange, bold: true },
107
+ primary: { fg: ghost },
108
+ secondary: { fg: slate },
109
+ subdued: { fg: deepSlate },
110
+ info: { fg: sky, bold: true },
111
+ violet: { fg: violet, bold: true },
112
+ success: { fg: cyan, bold: true },
113
+ warning: { fg: orange, bold: true },
114
+ danger: { fg: ruby, bold: true },
115
+ };
116
+
117
+ export function themeText(ctx, text, options = {}) {
118
+ return applyThemeSpec(ctx, text, resolveSpec(options));
119
+ }
120
+
121
+ export function inlineSurface(ctx, text, options = {}) {
122
+ const styled = themeText(ctx, text, options);
123
+ return parseAnsiToSurface(styled, Math.max(1, text.length), 1);
124
+ }
125
+
126
+ export function sectionHeading(ctx, label, tone = 'brand') {
127
+ return themeText(ctx, `◆ ${label}`, { tone, bold: true });
128
+ }
129
+
130
+ export function shellRule(ctx, width) {
131
+ return themeText(ctx, '─'.repeat(Math.max(1, width)), { tone: 'subdued' });
132
+ }
133
+
134
+ function resolveSpec(options = {}) {
135
+ const tone = options.tone ? TEXT_TONES[options.tone] : null;
136
+ return {
137
+ fg: options.fg ?? tone?.fg,
138
+ bg: options.bg ?? tone?.bg,
139
+ bold: options.bold ?? tone?.bold ?? false,
140
+ };
141
+ }
142
+
143
+ function applyThemeSpec(ctx, text, spec) {
144
+ let styled = text;
145
+ if (spec.fg) {
146
+ styled = ctx.style.rgb(spec.fg[0], spec.fg[1], spec.fg[2], styled);
147
+ }
148
+ if (spec.bg) {
149
+ styled = ctx.style.bgRgb(spec.bg[0], spec.bg[1], spec.bg[2], styled);
150
+ }
151
+ if (spec.bold) {
152
+ styled = ctx.style.bold(styled);
153
+ }
154
+ return styled;
155
+ }