@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
@@ -0,0 +1,296 @@
1
+ /**
2
+ * Interactive store wizard — guided flow for storing a file into git-cas.
3
+ *
4
+ * State machine with steps: filePath → slug → encryption → 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, handleTextKey, handleToggleKey,
11
+ renderFieldLine, renderSelectList, renderTextInput, renderToggle,
12
+ renderWizardPanel,
13
+ } from './blocks/wizard-block.js';
14
+ import { themeText } from './theme.js';
15
+
16
+ /**
17
+ * @typedef {import('@flyingrobots/bijou').BijouContext} BijouContext
18
+ * @typedef {import('@flyingrobots/bijou').Surface} Surface
19
+ */
20
+
21
+ /**
22
+ * @typedef {'filePath' | 'slug' | 'encryption' | 'compression' | 'chunking' | 'confirm' | 'storing' | 'done' | 'error'} WizardStep
23
+ */
24
+
25
+ /**
26
+ * @typedef {Object} StoreWizardState
27
+ * @property {WizardStep} step
28
+ * @property {string} filePath
29
+ * @property {string} slug
30
+ * @property {'none' | 'passphrase' | 'convergent'} encryption
31
+ * @property {string} passphrase
32
+ * @property {boolean} passphraseVisible
33
+ * @property {boolean} compression
34
+ * @property {'whole' | 'fixed' | 'cdc'} chunking
35
+ * @property {number} selectIndex
36
+ * @property {string | null} error
37
+ * @property {string | null} resultSlug
38
+ */
39
+
40
+ const ENCRYPTION_OPTIONS = ['none', 'passphrase', 'convergent'];
41
+ const CHUNKING_OPTIONS = ['whole', 'fixed', 'cdc'];
42
+
43
+ /**
44
+ * Create a fresh wizard state.
45
+ *
46
+ * @returns {StoreWizardState}
47
+ */
48
+ export function createWizardState() {
49
+ return {
50
+ step: 'filePath',
51
+ filePath: '',
52
+ slug: '',
53
+ encryption: 'none',
54
+ passphrase: '',
55
+ passphraseVisible: false,
56
+ compression: false,
57
+ chunking: 'cdc',
58
+ selectIndex: 0,
59
+ error: null,
60
+ resultSlug: null,
61
+ };
62
+ }
63
+
64
+ /**
65
+ * @param {StoreWizardState} state
66
+ * @param {string} key
67
+ * @returns {StoreWizardState}
68
+ */
69
+ function handleFilePathKey(state, key) {
70
+ const result = handleTextKey(state.filePath, key);
71
+ if (result.confirmed) {
72
+ return { ...state, filePath: result.value, step: 'slug', slug: deriveSlug(result.value) };
73
+ }
74
+ return { ...state, filePath: result.value };
75
+ }
76
+
77
+ /**
78
+ * @param {StoreWizardState} state
79
+ * @param {string} key
80
+ * @returns {StoreWizardState}
81
+ */
82
+ function handleSlugKey(state, key) {
83
+ const result = handleTextKey(state.slug, key);
84
+ if (result.confirmed) {
85
+ return { ...state, slug: result.value, step: 'encryption', selectIndex: ENCRYPTION_OPTIONS.indexOf(state.encryption) };
86
+ }
87
+ return { ...state, slug: result.value };
88
+ }
89
+
90
+ /**
91
+ * @param {StoreWizardState} state
92
+ * @param {string} key
93
+ * @returns {StoreWizardState}
94
+ */
95
+ function handleEncryptionKey(state, key) {
96
+ const result = handleSelectKey(state.selectIndex, ENCRYPTION_OPTIONS.length, key);
97
+ if (result.confirmed) {
98
+ const encryption = /** @type {'none' | 'passphrase' | 'convergent'} */ (ENCRYPTION_OPTIONS[result.selectIndex]);
99
+ return { ...state, encryption, selectIndex: 0, step: 'compression' };
100
+ }
101
+ return { ...state, selectIndex: result.selectIndex };
102
+ }
103
+
104
+ /**
105
+ * @param {StoreWizardState} state
106
+ * @param {string} key
107
+ * @returns {StoreWizardState}
108
+ */
109
+ function handleCompressionKey(state, key) {
110
+ const result = handleToggleKey(state.compression, key);
111
+ if (result.confirmed) {
112
+ return { ...state, compression: result.value, step: 'chunking', selectIndex: CHUNKING_OPTIONS.indexOf(state.chunking) };
113
+ }
114
+ return { ...state, compression: result.value };
115
+ }
116
+
117
+ /**
118
+ * @param {StoreWizardState} state
119
+ * @param {string} key
120
+ * @returns {StoreWizardState}
121
+ */
122
+ function handleChunkingKey(state, key) {
123
+ const result = handleSelectKey(state.selectIndex, CHUNKING_OPTIONS.length, key);
124
+ if (result.confirmed) {
125
+ const chunking = /** @type {'whole' | 'fixed' | 'cdc'} */ (CHUNKING_OPTIONS[result.selectIndex]);
126
+ return { ...state, chunking, step: 'confirm' };
127
+ }
128
+ return { ...state, selectIndex: result.selectIndex };
129
+ }
130
+
131
+ /**
132
+ * @param {StoreWizardState} state
133
+ * @param {string} key
134
+ * @returns {StoreWizardState}
135
+ */
136
+ function handleConfirmKey(state, key) {
137
+ if (key === 'enter' || key === 'y') {
138
+ return { ...state, step: 'storing' };
139
+ }
140
+ if (key === 'n' || key === 'backspace') {
141
+ return { ...state, step: 'filePath' };
142
+ }
143
+ return state;
144
+ }
145
+
146
+ /** @type {Record<string, (state: StoreWizardState, key: string) => StoreWizardState>} */
147
+ const stepHandlers = {
148
+ filePath: handleFilePathKey,
149
+ slug: handleSlugKey,
150
+ encryption: handleEncryptionKey,
151
+ compression: handleCompressionKey,
152
+ chunking: handleChunkingKey,
153
+ confirm: handleConfirmKey,
154
+ };
155
+
156
+ /**
157
+ * Handle a key press within the wizard.
158
+ *
159
+ * @param {StoreWizardState} state
160
+ * @param {string} key
161
+ * @returns {StoreWizardState}
162
+ */
163
+ export function wizardHandleKey(state, key) {
164
+ if (state.step === 'storing' || state.step === 'done') {
165
+ return state;
166
+ }
167
+ if (key === 'escape') {
168
+ return { ...state, step: 'error', error: 'Cancelled' };
169
+ }
170
+ return stepHandlers[state.step]?.(state, key) ?? state;
171
+ }
172
+
173
+ /**
174
+ * Derive a slug from a file path.
175
+ *
176
+ * @param {string} filePath
177
+ * @returns {string}
178
+ */
179
+ function deriveSlug(filePath) {
180
+ const name = filePath.split('/').pop() || filePath;
181
+ const dotIndex = name.lastIndexOf('.');
182
+ return dotIndex > 0 ? name.slice(0, dotIndex) : name;
183
+ }
184
+
185
+ /** @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',
193
+ storing: 'Storing...',
194
+ done: 'Done',
195
+ error: 'Error',
196
+ };
197
+
198
+ /**
199
+ * Render the wizard overlay surface.
200
+ *
201
+ * @param {StoreWizardState} state
202
+ * @param {{ width: number, height: number, ctx: BijouContext }} opts
203
+ * @returns {Surface}
204
+ */
205
+ export function renderWizardSurface(state, opts) {
206
+ return renderWizardPanel({
207
+ title: `Store [${STEP_LABELS[state.step] ?? state.step}]`,
208
+ body: renderWizardBody(state, opts.ctx),
209
+ screenWidth: opts.width,
210
+ screenHeight: opts.height,
211
+ ctx: opts.ctx,
212
+ });
213
+ }
214
+
215
+ /**
216
+ * @param {StoreWizardState} state
217
+ * @param {BijouContext} ctx
218
+ * @returns {string}
219
+ */
220
+ function renderWizardBody(state, ctx) {
221
+ if (state.step === 'error') {
222
+ return themeText(ctx, state.error ?? 'Cancelled', { tone: 'danger' });
223
+ }
224
+ if (state.step === 'storing') {
225
+ return themeText(ctx, `Storing ${state.slug}...`, { tone: 'info' });
226
+ }
227
+ if (state.step === 'done') {
228
+ return themeText(ctx, `Stored ${state.resultSlug}`, { tone: 'accent' });
229
+ }
230
+ if (state.step === 'confirm') {
231
+ return renderConfirmBody(state, ctx);
232
+ }
233
+ return renderStepBody(state, ctx);
234
+ }
235
+
236
+ /**
237
+ * @param {StoreWizardState} state
238
+ * @param {BijouContext} ctx
239
+ * @returns {string}
240
+ */
241
+ function renderStepBody(state, ctx) {
242
+ /** @type {Record<string, () => string[]>} */
243
+ const renderers = {
244
+ filePath: () => [
245
+ themeText(ctx, 'File path:', { tone: 'accent' }),
246
+ renderTextInput(state.filePath),
247
+ '',
248
+ themeText(ctx, 'Type the file path, then press enter.', { tone: 'subdued' }),
249
+ ],
250
+ slug: () => [
251
+ themeText(ctx, 'Slug name:', { tone: 'accent' }),
252
+ renderTextInput(state.slug),
253
+ '',
254
+ themeText(ctx, 'Edit the slug, then press enter.', { tone: 'subdued' }),
255
+ ],
256
+ encryption: () => [
257
+ themeText(ctx, 'Encryption:', { tone: 'accent' }),
258
+ renderSelectList(state.selectIndex, ENCRYPTION_OPTIONS, ctx),
259
+ '',
260
+ themeText(ctx, 'j/k to move, enter to select.', { tone: 'subdued' }),
261
+ ],
262
+ compression: () => [
263
+ themeText(ctx, 'Compression (gzip):', { tone: 'accent' }),
264
+ renderToggle(state.compression, ctx),
265
+ '',
266
+ themeText(ctx, 'space to toggle, enter to continue.', { tone: 'subdued' }),
267
+ ],
268
+ chunking: () => [
269
+ themeText(ctx, 'Chunking strategy:', { tone: 'accent' }),
270
+ renderSelectList(state.selectIndex, CHUNKING_OPTIONS, ctx),
271
+ '',
272
+ themeText(ctx, 'j/k to move, enter to select.', { tone: 'subdued' }),
273
+ ],
274
+ };
275
+ const render = renderers[state.step];
276
+ return render ? render().join('\n') : '';
277
+ }
278
+
279
+ /**
280
+ * @param {StoreWizardState} state
281
+ * @param {BijouContext} ctx
282
+ * @returns {string}
283
+ */
284
+ function renderConfirmBody(state, ctx) {
285
+ return [
286
+ themeText(ctx, 'Review and confirm:', { tone: 'accent', bold: true }),
287
+ '',
288
+ renderFieldLine(ctx, 'File:', state.filePath),
289
+ renderFieldLine(ctx, 'Slug:', state.slug),
290
+ renderFieldLine(ctx, 'Encryption:', state.encryption),
291
+ renderFieldLine(ctx, 'Compression:', state.compression ? 'gzip' : 'none'),
292
+ renderFieldLine(ctx, 'Chunking:', state.chunking),
293
+ '',
294
+ themeText(ctx, 'enter/y to store, n/backspace to restart.', { tone: 'subdued' }),
295
+ ].join('\n');
296
+ }
@@ -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
+ }