@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.
- package/ADVANCED_GUIDE.md +1027 -0
- package/ARCHITECTURE.md +514 -0
- package/CHANGELOG.md +449 -5
- package/CODE_OF_CONDUCT.md +33 -0
- package/GUIDE.md +926 -0
- package/README.md +106 -366
- package/SECURITY.md +993 -0
- package/SUPPORT.md +54 -0
- package/UPGRADING.md +299 -0
- package/bin/actions.js +70 -21
- package/bin/agent/cli.js +51 -0
- package/bin/agent/commands/doctor.js +99 -0
- package/bin/agent/commands/index.js +1489 -0
- package/bin/agent/input.js +619 -0
- package/bin/agent/passphrase-source.js +123 -0
- package/bin/agent/protocol.js +193 -0
- package/bin/build-version.js +64 -0
- package/bin/credentials.js +425 -0
- package/bin/git-cas.js +595 -449
- package/bin/passphrase-source.js +266 -0
- package/bin/restore-output-target.js +28 -0
- package/bin/ui/blocks/asset-card.js +109 -0
- package/bin/ui/blocks/health-dashboard.js +149 -0
- package/bin/ui/blocks/heatmap-block.js +67 -0
- package/bin/ui/blocks/merkle-explorer.js +163 -0
- package/bin/ui/blocks/operation-feed.js +176 -0
- package/bin/ui/blocks/wizard-block.js +168 -0
- package/bin/ui/components/short-sha.js +36 -0
- package/bin/ui/context.js +56 -1
- package/bin/ui/dashboard-cmds.js +1578 -13
- package/bin/ui/dashboard-view.js +612 -145
- package/bin/ui/dashboard.js +1255 -212
- package/bin/ui/encryption-card.js +69 -26
- package/bin/ui/heatmap.js +26 -54
- package/bin/ui/history-timeline.js +51 -19
- package/bin/ui/manifest-view.js +115 -60
- package/bin/ui/merkle-dag.js +83 -0
- package/bin/ui/progress.js +15 -9
- package/bin/ui/repo-treemap.js +328 -0
- package/bin/ui/shaders/bak-sneppen.js +180 -0
- package/bin/ui/shaders/fractal-zoom.js +99 -0
- package/bin/ui/shaders/merkle-tree.js +142 -0
- package/bin/ui/shaders/organic-flow.js +96 -0
- package/bin/ui/shaders/phase-portrait.js +93 -0
- package/bin/ui/store-wizard.js +367 -0
- package/bin/ui/theme.js +155 -0
- package/bin/ui/vault-report.js +495 -0
- package/build-info.json +4 -0
- package/docs/API.md +2254 -0
- package/docs/ENCRYPTION_MODES.md +33 -0
- package/docs/EXTENDING.md +174 -0
- package/docs/STORE_RESTORE_PIPELINE.md +199 -0
- package/docs/THREAT_MODEL.md +269 -0
- package/docs/VAULT_INTERNALS.md +251 -0
- package/docs/WALKTHROUGH.md +1868 -0
- package/docs/demo.gif +0 -0
- package/docs/releases/v6.0.0.md +104 -0
- package/examples/README.md +260 -0
- package/index.d.ts +273 -80
- package/index.js +220 -59
- package/package.json +35 -6
- package/scripts/migrate-encryption.js +680 -0
- package/src/domain/bytes/ByteLayout.js +96 -0
- package/src/domain/encoding/base64.js +91 -0
- package/src/domain/encoding/hex.js +14 -0
- package/src/domain/encoding/utf8.js +123 -0
- package/src/domain/encryption/schemes.js +132 -0
- package/src/domain/errors/CannotRemoveLastRecipientError.js +10 -0
- package/src/domain/errors/CasError.d.ts +28 -0
- package/src/domain/errors/CasError.js +43 -6
- package/src/domain/errors/Codes.js +54 -0
- package/src/domain/errors/DekUnwrapFailedError.js +10 -0
- package/src/domain/errors/GitError.js +10 -0
- package/src/domain/errors/GitPlumbingInitializationError.js +10 -0
- package/src/domain/errors/IntegrityError.js +10 -0
- package/src/domain/errors/InvalidChunkingStrategyError.js +10 -0
- package/src/domain/errors/InvalidOidError.js +10 -0
- package/src/domain/errors/InvalidOptionsError.js +10 -0
- package/src/domain/errors/ManifestIntegrityError.js +10 -0
- package/src/domain/errors/ManifestNotFoundError.js +10 -0
- package/src/domain/errors/NoMatchingRecipientError.js +10 -0
- package/src/domain/errors/PersistenceCapabilityRequiredError.js +10 -0
- package/src/domain/errors/PortNotImplementedError.js +10 -0
- package/src/domain/errors/RecipientAlreadyExistsError.js +10 -0
- package/src/domain/errors/RecipientNotFoundError.js +10 -0
- package/src/domain/errors/RestoreTooLargeError.js +10 -0
- package/src/domain/errors/RotationNotSupportedError.js +10 -0
- package/src/domain/errors/createCasError.js +68 -0
- package/src/domain/errors/index.js +20 -0
- package/src/domain/helpers/buildKdfMetadata.js +4 -2
- package/src/domain/helpers/codecBytes.js +34 -0
- package/src/domain/helpers/gitRefErrors.js +84 -0
- package/src/domain/helpers/scryptMaxmem.js +22 -0
- package/src/domain/outcomes/RestoreFailure.js +15 -0
- package/src/domain/outcomes/RestoreOutcome.js +11 -0
- package/src/domain/outcomes/RestoreSuccess.js +34 -0
- package/src/domain/outcomes/StoreFailure.js +15 -0
- package/src/domain/outcomes/StoreOutcome.js +11 -0
- package/src/domain/outcomes/StoreSuccess.js +17 -0
- package/src/domain/schemas/ManifestSchema.d.ts +40 -9
- package/src/domain/schemas/ManifestSchema.js +67 -13
- package/src/domain/services/CasService.d.ts +153 -53
- package/src/domain/services/CasService.js +322 -837
- package/src/domain/services/ChunkRepository.js +268 -0
- package/src/domain/services/CompressionStreams.js +72 -0
- package/src/domain/services/ConvergentEncryption.js +128 -0
- package/src/domain/services/GitTreeBuilder.js +86 -0
- package/src/domain/services/IntegrityVerifier.js +199 -0
- package/src/domain/services/KeyResolver.js +49 -42
- package/src/domain/services/ManifestDiff.js +56 -0
- package/src/domain/services/ManifestRepository.js +286 -0
- package/src/domain/services/PrefetchWindow.js +48 -0
- package/src/domain/services/RecipientService.js +157 -0
- package/src/domain/services/RedactingObservability.js +169 -0
- package/src/domain/services/RestorePipeline.js +68 -0
- package/src/domain/services/StorePipeline.js +201 -0
- package/src/domain/services/VaultKeyVerifier.js +101 -0
- package/src/domain/services/VaultMetadataCodec.js +206 -0
- package/src/domain/services/VaultMutationRetryPolicy.js +105 -0
- package/src/domain/services/VaultPersistence.js +410 -0
- package/src/domain/services/VaultPrivacyIndex.js +191 -0
- package/src/domain/services/VaultService.js +749 -251
- package/src/domain/services/VaultStateCache.js +225 -0
- package/src/domain/services/VaultTreeCodec.js +121 -0
- package/src/domain/services/rotateVaultPassphrase.js +37 -20
- package/src/domain/strategies/Aad.js +39 -0
- package/src/domain/strategies/FramedRecordCodec.js +204 -0
- package/src/domain/strategies/RestoreCompressed.js +40 -0
- package/src/domain/strategies/RestoreConvergent.js +44 -0
- package/src/domain/strategies/RestoreFramed.js +55 -0
- package/src/domain/strategies/RestorePlain.js +37 -0
- package/src/domain/strategies/RestoreStrategy.js +35 -0
- package/src/domain/strategies/RestoreWhole.js +135 -0
- package/src/domain/strategies/StoreConvergent.js +28 -0
- package/src/domain/strategies/StoreFramed.js +39 -0
- package/src/domain/strategies/StorePlain.js +20 -0
- package/src/domain/strategies/StoreStrategy.js +61 -0
- package/src/domain/strategies/StoreWhole.js +34 -0
- package/src/domain/value-objects/Chunk.js +1 -2
- package/src/domain/value-objects/EncryptionMetadata.js +87 -0
- package/src/domain/value-objects/Manifest.d.ts +40 -4
- package/src/domain/value-objects/Manifest.js +61 -20
- package/src/domain/value-objects/Oid.js +45 -0
- package/src/domain/value-objects/Slug.js +124 -0
- package/src/domain/value-objects/StoreEncryptionConfig.js +114 -0
- package/src/helpers/aesGcmMeta.js +55 -0
- package/src/helpers/canonicalBase64.js +1 -0
- package/src/helpers/kdfPolicy.js +194 -0
- package/src/infrastructure/adapters/BunCryptoAdapter.js +124 -8
- package/src/infrastructure/adapters/FileIOHelper.js +180 -13
- package/src/infrastructure/adapters/GitPersistenceAdapter.js +235 -42
- package/src/infrastructure/adapters/GitPlumbingFactoryAdapter.js +62 -0
- package/src/infrastructure/adapters/GitRefAdapter.js +19 -6
- package/src/infrastructure/adapters/NodeCompressionAdapter.js +64 -0
- package/src/infrastructure/adapters/NodeCryptoAdapter.js +130 -10
- package/src/infrastructure/adapters/WebCryptoAdapter.js +187 -77
- package/src/infrastructure/chunkers/CdcChunker.js +53 -19
- package/src/infrastructure/chunkers/FixedChunker.js +15 -7
- package/src/infrastructure/chunkers/resolveChunker.js +10 -6
- package/src/infrastructure/codecs/CborCodec.js +3 -3
- package/src/infrastructure/codecs/JsonCodec.js +5 -5
- package/src/infrastructure/createGitPlumbing.js +22 -0
- package/src/package-version.js +1 -0
- package/src/ports/ChunkingPort.js +3 -3
- package/src/ports/CodecPort.js +4 -4
- package/src/ports/CompressionPort.js +57 -0
- package/src/ports/CryptoPort.js +138 -50
- package/src/ports/GitPersistencePort.js +32 -2
- package/src/ports/GitPlumbingFactoryPort.js +16 -0
- package/src/ports/GitRefPort.js +1 -1
- package/src/types/ambient.d.ts +10 -5
- package/test/CONVENTIONS.md +94 -0
- package/test/cycles/README.md +13 -0
package/bin/ui/dashboard.js
CHANGED
|
@@ -1,306 +1,1349 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* TEA app shell for the
|
|
2
|
+
* TEA app shell for the V6 git-cas cockpit.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
import { startApp as bijouStartApp } from '@flyingrobots/bijou-node';
|
|
6
|
+
import {
|
|
7
|
+
cpFilter,
|
|
8
|
+
cpFocusNext,
|
|
9
|
+
cpFocusPrev,
|
|
10
|
+
cpPageDown,
|
|
11
|
+
cpPageUp,
|
|
12
|
+
cpSelectedItem,
|
|
13
|
+
createCommandPaletteState,
|
|
14
|
+
createNavigableTableState,
|
|
15
|
+
createNotificationState,
|
|
16
|
+
navTableFocusNext,
|
|
17
|
+
navTableFocusPrev,
|
|
18
|
+
navTablePageDown,
|
|
19
|
+
navTablePageUp,
|
|
20
|
+
notificationsNeedTick,
|
|
21
|
+
pushNotification,
|
|
22
|
+
quit,
|
|
23
|
+
tick as bijouTick,
|
|
24
|
+
tickNotifications,
|
|
25
|
+
} from '@flyingrobots/bijou-tui';
|
|
26
|
+
import { renderDashboard, tableSchema } from './dashboard-view.js';
|
|
27
|
+
import { createCliTuiContext } from './context.js';
|
|
28
|
+
import { formatTabSeparated } from './vault-list.js';
|
|
29
|
+
import {
|
|
30
|
+
loadBranchCmd,
|
|
31
|
+
loadDoctorCmd,
|
|
32
|
+
loadEntriesCmd,
|
|
33
|
+
loadManifestCmd,
|
|
34
|
+
loadRefsCmd,
|
|
35
|
+
loadStatsCmd,
|
|
36
|
+
loadTreemapCmd,
|
|
37
|
+
readSourceEntries,
|
|
38
|
+
} from './dashboard-cmds.js';
|
|
39
|
+
import { createWizardState, wizardHandleKey } from './store-wizard.js';
|
|
40
|
+
import { createFeedState } from './blocks/operation-feed.js';
|
|
41
|
+
import { shortenSha } from './components/short-sha.js';
|
|
9
42
|
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @typedef {{ type: 'quit' }
|
|
23
|
-
* | { type: 'move', delta: number }
|
|
24
|
-
* | { type: 'select' }
|
|
25
|
-
* | { type: 'filter-start' }
|
|
26
|
-
* | { type: 'scroll-detail', delta: number }
|
|
27
|
-
* } DashAction
|
|
28
|
-
*/
|
|
43
|
+
/** @typedef {import('../index.js').default} ContentAddressableStore */
|
|
44
|
+
/** @typedef {import('../src/domain/value-objects/Manifest.js').default} Manifest */
|
|
45
|
+
/** @typedef {import('../src/domain/services/VaultService.js').VaultEntry} VaultEntry */
|
|
46
|
+
/** @typedef {import('@flyingrobots/bijou').BijouContext} BijouContext */
|
|
47
|
+
/** @typedef {import('@flyingrobots/bijou-tui').CommandPaletteState} CommandPaletteState */
|
|
48
|
+
/** @typedef {import('@flyingrobots/bijou-tui').NavigableTableState} NavigableTableState */
|
|
49
|
+
/** @typedef {import('@flyingrobots/bijou-tui').NotificationState} NotificationState */
|
|
50
|
+
/** @typedef {import('./store-wizard.js').StoreWizardState} StoreWizardState */
|
|
51
|
+
/** @typedef {import('./blocks/operation-feed.js').OperationFeedState} OperationFeedState */
|
|
29
52
|
|
|
30
53
|
/**
|
|
31
|
-
* @typedef {
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* }
|
|
54
|
+
* @typedef {'title' | 'password' | 'dashboard'} AppPhase
|
|
55
|
+
* @typedef {'explorer' | 'atlas' | 'operations'} WorkspaceId
|
|
56
|
+
* @typedef {'ledger' | 'manifest' | 'merkle'} ExplorerMode
|
|
57
|
+
* @typedef {'table' | 'tree' | 'dag'} MerkleMode
|
|
58
|
+
* @typedef {{ type: 'vault' } | { type: 'ref', ref: string } | { type: 'oid', treeOid: string }} DashSource
|
|
35
59
|
*/
|
|
36
60
|
|
|
37
61
|
/**
|
|
38
62
|
* @typedef {Object} DashModel
|
|
63
|
+
* @property {AppPhase} phase
|
|
64
|
+
* @property {number} titleTimeMs
|
|
65
|
+
* @property {number} lastTickTime
|
|
66
|
+
* @property {number} fps
|
|
67
|
+
* @property {boolean} showPerfHud
|
|
68
|
+
* @property {number} vaultEntryCount
|
|
69
|
+
* @property {string} passphrase
|
|
70
|
+
* @property {string | null} authError
|
|
39
71
|
* @property {string} status
|
|
40
72
|
* @property {number} columns
|
|
41
73
|
* @property {number} rows
|
|
74
|
+
* @property {DashSource} source
|
|
75
|
+
* @property {WorkspaceId} workspace
|
|
76
|
+
* @property {ExplorerMode} explorerMode
|
|
77
|
+
* @property {MerkleMode} merkleMode
|
|
78
|
+
* @property {'ledger' | 'detail'} focusPane
|
|
79
|
+
* @property {number} chunkFocus
|
|
42
80
|
* @property {VaultEntry[]} entries
|
|
43
81
|
* @property {VaultEntry[]} filtered
|
|
44
|
-
* @property {number} cursor
|
|
45
82
|
* @property {string} filterText
|
|
46
83
|
* @property {boolean} filtering
|
|
47
84
|
* @property {any} metadata
|
|
48
85
|
* @property {Map<string, Manifest>} manifestCache
|
|
49
86
|
* @property {string | null} loadingSlug
|
|
50
|
-
* @property {number} detailScroll
|
|
51
87
|
* @property {string | null} error
|
|
88
|
+
* @property {NavigableTableState} table
|
|
89
|
+
* @property {CommandPaletteState | null} palette
|
|
90
|
+
* @property {boolean} showHelp
|
|
91
|
+
* @property {boolean} promptEnter
|
|
92
|
+
* @property {boolean} quitConfirm
|
|
93
|
+
* @property {any} refsStatus
|
|
94
|
+
* @property {any | null} refsInventory
|
|
95
|
+
* @property {string | null} refsError
|
|
96
|
+
* @property {any} statsStatus
|
|
97
|
+
* @property {any | null} statsReport
|
|
98
|
+
* @property {string | null} statsError
|
|
99
|
+
* @property {any} doctorStatus
|
|
100
|
+
* @property {any | null} doctorReport
|
|
101
|
+
* @property {string | null} doctorError
|
|
102
|
+
* @property {any} treemapScope
|
|
103
|
+
* @property {any} treemapWorktreeMode
|
|
104
|
+
* @property {any[]} treemapPath
|
|
105
|
+
* @property {number} treemapFocus
|
|
106
|
+
* @property {any} treemapStatus
|
|
107
|
+
* @property {any | null} treemapReport
|
|
108
|
+
* @property {string | null} treemapError
|
|
109
|
+
* @property {NotificationState} notifications
|
|
110
|
+
* @property {OperationFeedState} operationFeed
|
|
111
|
+
* @property {StoreWizardState | null} storeWizard
|
|
112
|
+
* @property {string | null} gitBranch
|
|
113
|
+
* @property {Buffer | null} vaultEncryptionKey
|
|
114
|
+
* @property {boolean} settingsOpen
|
|
52
115
|
*/
|
|
53
116
|
|
|
54
117
|
/**
|
|
55
118
|
* @typedef {Object} DashDeps
|
|
56
|
-
* @property {DashKeyMap} keyMap
|
|
57
119
|
* @property {ContentAddressableStore} cas
|
|
58
120
|
* @property {BijouContext} ctx
|
|
121
|
+
* @property {string} cwdLabel
|
|
122
|
+
* @property {DashSource} source
|
|
123
|
+
* @property {(ms: number, msg: any) => any} tick
|
|
59
124
|
*/
|
|
60
125
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
126
|
+
const TITLE_TICK_MS = 33;
|
|
127
|
+
const NOTIFICATION_TICK_MS = 40;
|
|
128
|
+
|
|
129
|
+
const FULL_COLUMNS = [
|
|
130
|
+
{ header: 'Slug' },
|
|
131
|
+
{ header: 'Tree OID' },
|
|
132
|
+
{ header: 'Size' },
|
|
133
|
+
{ header: 'Chunks' },
|
|
134
|
+
{ header: 'Crypto' },
|
|
135
|
+
{ header: 'Format' },
|
|
136
|
+
{ header: 'State' },
|
|
137
|
+
];
|
|
138
|
+
|
|
139
|
+
function formatSize(bytes) {
|
|
140
|
+
if (!Number.isFinite(bytes)) {
|
|
141
|
+
return '-';
|
|
142
|
+
}
|
|
143
|
+
if (bytes < 1024) {
|
|
144
|
+
return `${bytes}B`;
|
|
145
|
+
}
|
|
146
|
+
if (bytes < 1024 * 1024) {
|
|
147
|
+
return `${(bytes / 1024).toFixed(1)}K`;
|
|
148
|
+
}
|
|
149
|
+
if (bytes < 1024 * 1024 * 1024) {
|
|
150
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)}M`;
|
|
151
|
+
}
|
|
152
|
+
return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)}G`;
|
|
77
153
|
}
|
|
78
154
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
155
|
+
function manifestData(manifest) {
|
|
156
|
+
return manifest?.toJSON ? manifest.toJSON() : manifest;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function manifestFor(entry, manifestCache) {
|
|
160
|
+
return entry ? manifestData(manifestCache.get(entry.slug)) : null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function cryptoLabel(manifest) {
|
|
164
|
+
if (!manifest) {
|
|
165
|
+
return '-';
|
|
166
|
+
}
|
|
167
|
+
if (
|
|
168
|
+
manifest.encryption?.encrypted ||
|
|
169
|
+
manifest.encryption?.recipients?.length ||
|
|
170
|
+
manifest.encryption
|
|
171
|
+
) {
|
|
172
|
+
return 'encrypted';
|
|
173
|
+
}
|
|
174
|
+
return 'plain';
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function formatLabel(manifest) {
|
|
178
|
+
if (!manifest) {
|
|
179
|
+
return '-';
|
|
180
|
+
}
|
|
181
|
+
return manifest.formatVersion ?? (manifest.version ? `v${manifest.version}` : 'manifest');
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function chunkLabel(manifest) {
|
|
185
|
+
if (!manifest) {
|
|
186
|
+
return '-';
|
|
187
|
+
}
|
|
188
|
+
const chunks = manifest.chunks?.length ?? 0;
|
|
189
|
+
const subManifests = manifest.subManifests?.length ?? 0;
|
|
190
|
+
return subManifests > 0 ? `${chunks}+${subManifests}` : String(chunks);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function rowForEntry(entry, manifestCache) {
|
|
194
|
+
const manifest = manifestFor(entry, manifestCache);
|
|
195
|
+
return [
|
|
196
|
+
entry.slug,
|
|
197
|
+
shortenSha(entry.treeOid),
|
|
198
|
+
formatSize(manifest?.size),
|
|
199
|
+
chunkLabel(manifest),
|
|
200
|
+
cryptoLabel(manifest),
|
|
201
|
+
formatLabel(manifest),
|
|
202
|
+
manifest ? 'loaded' : 'pending',
|
|
203
|
+
];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function buildTableRows(entries, manifestCache) {
|
|
207
|
+
return entries.map((entry) => rowForEntry(entry, manifestCache));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function tableHeight(rows) {
|
|
211
|
+
return Math.max(4, Math.min(18, Math.max(1, rows - 10)));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function sourceEquals(left, right) {
|
|
215
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function filterEntries(entries, filterText, manifestCache) {
|
|
219
|
+
const query = filterText.trim().toLowerCase();
|
|
220
|
+
if (!query) {
|
|
221
|
+
return entries;
|
|
222
|
+
}
|
|
223
|
+
return entries.filter((entry) => {
|
|
224
|
+
const manifest = manifestFor(entry, manifestCache);
|
|
225
|
+
const haystack = [
|
|
226
|
+
entry.slug,
|
|
227
|
+
entry.treeOid,
|
|
228
|
+
manifest?.integrity,
|
|
229
|
+
manifest?.hash,
|
|
230
|
+
...(manifest?.chunks ?? []).flatMap((chunk) => [chunk.digest, chunk.blob]),
|
|
231
|
+
]
|
|
232
|
+
.filter(Boolean)
|
|
233
|
+
.join(' ')
|
|
234
|
+
.toLowerCase();
|
|
235
|
+
return haystack.includes(query);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function syncExplorer(model, patch = {}) {
|
|
240
|
+
const next = { ...model, ...patch };
|
|
241
|
+
const filtered = filterEntries(next.entries, next.filterText, next.manifestCache);
|
|
242
|
+
const table = createNavigableTableState({
|
|
243
|
+
columns: FULL_COLUMNS,
|
|
244
|
+
rows: buildTableRows(filtered, next.manifestCache),
|
|
245
|
+
height: tableHeight(next.rows),
|
|
246
|
+
focusRow: Math.min(next.table?.focusRow ?? 0, Math.max(0, filtered.length - 1)),
|
|
247
|
+
scrollY: next.table?.scrollY ?? 0,
|
|
248
|
+
});
|
|
249
|
+
return { ...next, filtered, table };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function selectedEntry(model) {
|
|
253
|
+
return (
|
|
254
|
+
model.filtered[Math.min(model.table.focusRow, Math.max(0, model.filtered.length - 1))] ?? null
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function selectedManifest(model) {
|
|
259
|
+
return manifestFor(selectedEntry(model), model.manifestCache);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function maybeLoadSelectedManifest(model, deps) {
|
|
263
|
+
const entry = selectedEntry(model);
|
|
264
|
+
if (!entry || model.manifestCache.has(entry.slug) || model.loadingSlug === entry.slug) {
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
return loadManifestCmd(deps.cas, {
|
|
268
|
+
slug: entry.slug,
|
|
269
|
+
treeOid: entry.treeOid,
|
|
270
|
+
source: model.source,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function createShellState(columns, rows, source) {
|
|
275
|
+
return {
|
|
276
|
+
phase: 'title',
|
|
277
|
+
titleTimeMs: 0,
|
|
278
|
+
lastTickTime: 0,
|
|
279
|
+
fps: 0,
|
|
280
|
+
showPerfHud: false,
|
|
281
|
+
vaultEntryCount: 0,
|
|
282
|
+
passphrase: '',
|
|
283
|
+
authError: null,
|
|
284
|
+
status: 'checking vault',
|
|
285
|
+
columns,
|
|
286
|
+
rows,
|
|
287
|
+
source,
|
|
288
|
+
workspace: 'explorer',
|
|
289
|
+
explorerMode: 'ledger',
|
|
290
|
+
merkleMode: 'table',
|
|
291
|
+
focusPane: 'ledger',
|
|
292
|
+
chunkFocus: 0,
|
|
293
|
+
promptEnter: false,
|
|
294
|
+
quitConfirm: false,
|
|
295
|
+
gitBranch: null,
|
|
296
|
+
vaultEncryptionKey: null,
|
|
297
|
+
settingsOpen: false,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function createExplorerState(rows) {
|
|
85
302
|
return {
|
|
86
|
-
status: 'loading',
|
|
87
|
-
columns: process.stdout.columns ?? 80,
|
|
88
|
-
rows: process.stdout.rows ?? 24,
|
|
89
303
|
entries: [],
|
|
90
304
|
filtered: [],
|
|
91
|
-
cursor: 0,
|
|
92
305
|
filterText: '',
|
|
93
306
|
filtering: false,
|
|
94
307
|
metadata: null,
|
|
95
308
|
manifestCache: new Map(),
|
|
96
309
|
loadingSlug: null,
|
|
97
|
-
detailScroll: 0,
|
|
98
310
|
error: null,
|
|
311
|
+
table: createNavigableTableState({
|
|
312
|
+
columns: FULL_COLUMNS,
|
|
313
|
+
rows: [],
|
|
314
|
+
height: tableHeight(rows),
|
|
315
|
+
}),
|
|
316
|
+
palette: null,
|
|
317
|
+
showHelp: false,
|
|
99
318
|
};
|
|
100
319
|
}
|
|
101
320
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
321
|
+
function createServiceState() {
|
|
322
|
+
return {
|
|
323
|
+
refsStatus: 'idle',
|
|
324
|
+
refsInventory: null,
|
|
325
|
+
refsError: null,
|
|
326
|
+
statsStatus: 'idle',
|
|
327
|
+
statsReport: null,
|
|
328
|
+
statsError: null,
|
|
329
|
+
doctorStatus: 'idle',
|
|
330
|
+
doctorReport: null,
|
|
331
|
+
doctorError: null,
|
|
332
|
+
treemapScope: 'repository',
|
|
333
|
+
treemapWorktreeMode: 'tracked',
|
|
334
|
+
treemapPath: [],
|
|
335
|
+
treemapFocus: 0,
|
|
336
|
+
treemapStatus: 'idle',
|
|
337
|
+
treemapReport: null,
|
|
338
|
+
treemapError: null,
|
|
339
|
+
notifications: createNotificationState(),
|
|
340
|
+
operationFeed: createFeedState(),
|
|
341
|
+
storeWizard: null,
|
|
342
|
+
};
|
|
112
343
|
}
|
|
113
344
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
345
|
+
function createInitModel(ctx, source) {
|
|
346
|
+
const rows = ctx.runtime.rows ?? 24;
|
|
347
|
+
const columns = ctx.runtime.columns ?? 80;
|
|
348
|
+
return syncExplorer({
|
|
349
|
+
...createShellState(columns, rows, source),
|
|
350
|
+
...createExplorerState(rows),
|
|
351
|
+
...createServiceState(),
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function checkVaultAuthCmd(cas) {
|
|
356
|
+
return async () => {
|
|
357
|
+
let metadata = null;
|
|
358
|
+
try {
|
|
359
|
+
metadata = await cas.getVaultMetadata();
|
|
360
|
+
} catch {
|
|
361
|
+
metadata = null;
|
|
362
|
+
}
|
|
363
|
+
if (metadata?.encryption) {
|
|
364
|
+
return { type: 'vault-auth-check', encrypted: true, entryCount: 0, metadata };
|
|
365
|
+
}
|
|
366
|
+
try {
|
|
367
|
+
const all = await cas.listVault();
|
|
368
|
+
return {
|
|
369
|
+
type: 'vault-auth-check',
|
|
370
|
+
encrypted: Boolean(metadata?.encryption),
|
|
371
|
+
entryCount: all.length,
|
|
372
|
+
metadata,
|
|
373
|
+
};
|
|
374
|
+
} catch {
|
|
375
|
+
return { type: 'vault-auth-check', encrypted: false, entryCount: 0, metadata: null };
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
async function deriveVaultKey(cas, metadata, passphrase) {
|
|
381
|
+
const kdf = metadata?.encryption?.kdf;
|
|
382
|
+
if (!kdf) {
|
|
383
|
+
throw new Error('Missing vault encryption KDF metadata');
|
|
384
|
+
}
|
|
385
|
+
const { key } = await cas.deriveKey({
|
|
386
|
+
passphrase,
|
|
387
|
+
salt: Buffer.from(kdf.salt, 'base64'),
|
|
388
|
+
algorithm: kdf.algorithm,
|
|
389
|
+
iterations: kdf.iterations,
|
|
390
|
+
cost: kdf.cost,
|
|
391
|
+
blockSize: kdf.blockSize,
|
|
392
|
+
parallelization: kdf.parallelization,
|
|
393
|
+
keyLength: kdf.keyLength,
|
|
394
|
+
});
|
|
395
|
+
return key;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
async function verifyVaultKeyAgainstEntries(cas, entries, encryptionKey) {
|
|
399
|
+
for (const entry of entries) {
|
|
400
|
+
const manifest = await cas.readManifest({ treeOid: entry.treeOid });
|
|
401
|
+
const data = manifestData(manifest);
|
|
402
|
+
if (data?.encryption?.encrypted || data?.encryption) {
|
|
403
|
+
return await cas.verifyIntegrity(manifest, { encryptionKey });
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return true;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function verifyPassphraseCmd(cas, passphrase) {
|
|
410
|
+
return async () => {
|
|
411
|
+
try {
|
|
412
|
+
const metadata = await cas.getVaultMetadata();
|
|
413
|
+
const encryptionKey = await deriveVaultKey(cas, metadata, passphrase);
|
|
414
|
+
const entries = await cas.listVault({ encryptionKey });
|
|
415
|
+
const ok = await verifyVaultKeyAgainstEntries(cas, entries, encryptionKey);
|
|
416
|
+
return ok
|
|
417
|
+
? { type: 'vault-auth-ok', encryptionKey }
|
|
418
|
+
: { type: 'vault-auth-fail', error: 'Wrong passphrase' };
|
|
419
|
+
} catch (err) {
|
|
420
|
+
const authErrorCodes = [
|
|
421
|
+
'INTEGRITY_ERROR',
|
|
422
|
+
'DEK_UNWRAP_FAILED',
|
|
423
|
+
'MISSING_KEY',
|
|
424
|
+
'NO_MATCHING_RECIPIENT',
|
|
425
|
+
];
|
|
426
|
+
const msg = authErrorCodes.includes(err.code)
|
|
427
|
+
? 'Wrong passphrase'
|
|
428
|
+
: (err.message ?? String(err));
|
|
429
|
+
return { type: 'vault-auth-fail', error: msg };
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function casForModel(cas, model) {
|
|
435
|
+
if (!model.vaultEncryptionKey) {
|
|
436
|
+
return cas;
|
|
437
|
+
}
|
|
438
|
+
return new Proxy(cas, {
|
|
439
|
+
get(target, prop, receiver) {
|
|
440
|
+
if (prop === 'listVault') {
|
|
441
|
+
return (options = {}) =>
|
|
442
|
+
target.listVault({ ...options, encryptionKey: model.vaultEncryptionKey });
|
|
443
|
+
}
|
|
444
|
+
if (prop === 'addToVault') {
|
|
445
|
+
return (options = {}) =>
|
|
446
|
+
target.addToVault({ ...options, encryptionKey: model.vaultEncryptionKey });
|
|
447
|
+
}
|
|
448
|
+
const value = Reflect.get(target, prop, receiver);
|
|
449
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
450
|
+
},
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
const WIZARD_GZIP_COMPRESSION = Object.freeze({ algorithm: 'gzip' });
|
|
455
|
+
const WIZARD_CHUNKING_CONFIG = Object.freeze({
|
|
456
|
+
fixed: Object.freeze({ strategy: 'fixed' }),
|
|
457
|
+
cdc: Object.freeze({ strategy: 'cdc' }),
|
|
458
|
+
});
|
|
459
|
+
const WIZARD_MISSING_PASSPHRASE_MESSAGE = 'Encryption passphrase is required';
|
|
460
|
+
|
|
461
|
+
function validateStoreWizardPlan(wizard) {
|
|
462
|
+
if (!wizard.passphrase) {
|
|
463
|
+
return wizard.encryption === 'none' ? null : WIZARD_MISSING_PASSPHRASE_MESSAGE;
|
|
464
|
+
}
|
|
465
|
+
return null;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
function storeWizardEncryptionOptions(wizard) {
|
|
469
|
+
if (wizard.encryption === 'none') {
|
|
470
|
+
return {};
|
|
471
|
+
}
|
|
472
|
+
if (wizard.encryption === 'convergent') {
|
|
473
|
+
return { passphrase: wizard.passphrase, encryption: { scheme: 'convergent' } };
|
|
474
|
+
}
|
|
475
|
+
return { passphrase: wizard.passphrase };
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function buildStoreWizardOptions(wizard) {
|
|
479
|
+
return {
|
|
480
|
+
filePath: wizard.filePath,
|
|
481
|
+
slug: wizard.slug,
|
|
482
|
+
...storeWizardEncryptionOptions(wizard),
|
|
483
|
+
...(wizard.compression ? { compression: WIZARD_GZIP_COMPRESSION } : {}),
|
|
484
|
+
chunking: WIZARD_CHUNKING_CONFIG[wizard.chunking],
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function runStoreWizardCmd(cas, wizard) {
|
|
489
|
+
return async () => {
|
|
490
|
+
try {
|
|
491
|
+
const validationError = validateStoreWizardPlan(wizard);
|
|
492
|
+
if (validationError) {
|
|
493
|
+
return { type: 'store-error', error: validationError };
|
|
494
|
+
}
|
|
495
|
+
const manifest = await cas.storeFile(buildStoreWizardOptions(wizard));
|
|
496
|
+
const treeOid = await cas.createTree({ manifest });
|
|
497
|
+
await cas.addToVault({ slug: wizard.slug, treeOid, force: true });
|
|
498
|
+
return { type: 'store-complete', slug: wizard.slug, treeOid, manifest };
|
|
499
|
+
} catch (err) {
|
|
500
|
+
return { type: 'store-error', error: err.message ?? String(err) };
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function enterDashboard(model, deps) {
|
|
506
|
+
const cas = casForModel(deps.cas, model);
|
|
507
|
+
return [
|
|
508
|
+
{
|
|
509
|
+
...model,
|
|
510
|
+
phase: 'dashboard',
|
|
511
|
+
promptEnter: false,
|
|
512
|
+
authError: null,
|
|
513
|
+
status: 'loading entries',
|
|
514
|
+
},
|
|
515
|
+
[loadEntriesCmd(cas, model.source), loadBranchCmd(cas), loadRefsCmd(cas)],
|
|
516
|
+
];
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function pushToast(model, spec) {
|
|
520
|
+
return {
|
|
127
521
|
...model,
|
|
128
|
-
|
|
522
|
+
notifications: pushNotification(
|
|
523
|
+
model.notifications,
|
|
524
|
+
{
|
|
525
|
+
variant: 'TOAST',
|
|
526
|
+
placement: 'LOWER_RIGHT',
|
|
527
|
+
width: 42,
|
|
528
|
+
...spec,
|
|
529
|
+
},
|
|
530
|
+
Date.now()
|
|
531
|
+
),
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function notificationTick(model, deps) {
|
|
536
|
+
return notificationsNeedTick(model.notifications)
|
|
537
|
+
? [deps.tick(NOTIFICATION_TICK_MS, { type: 'notification-tick' })]
|
|
538
|
+
: [];
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
function handleTickMsg(msg, model, deps) {
|
|
542
|
+
if (msg.type === 'notification-tick') {
|
|
543
|
+
const next = { ...model, notifications: tickNotifications(model.notifications, Date.now()) };
|
|
544
|
+
return [next, notificationTick(next, deps)];
|
|
545
|
+
}
|
|
546
|
+
if (msg.type !== 'title-tick' || (model.phase !== 'title' && model.phase !== 'password')) {
|
|
547
|
+
return [model, []];
|
|
548
|
+
}
|
|
549
|
+
const now = Date.now();
|
|
550
|
+
const elapsed = now - (model.lastTickTime || now);
|
|
551
|
+
const fps = elapsed > 0 ? Math.round(1000 / elapsed) : 0;
|
|
552
|
+
return [
|
|
553
|
+
{
|
|
554
|
+
...model,
|
|
555
|
+
titleTimeMs: (model.titleTimeMs || 0) + TITLE_TICK_MS,
|
|
556
|
+
lastTickTime: now,
|
|
557
|
+
fps: model.lastTickTime ? fps : 0,
|
|
558
|
+
},
|
|
559
|
+
[deps.tick(TITLE_TICK_MS, { type: 'title-tick' })],
|
|
560
|
+
];
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function handleVaultAuthCheck(msg, model) {
|
|
564
|
+
if (msg.encrypted) {
|
|
565
|
+
return [
|
|
566
|
+
{
|
|
567
|
+
...model,
|
|
568
|
+
phase: 'password',
|
|
569
|
+
metadata: msg.metadata,
|
|
570
|
+
vaultEntryCount: msg.entryCount,
|
|
571
|
+
status: 'vault locked',
|
|
572
|
+
},
|
|
573
|
+
[],
|
|
574
|
+
];
|
|
575
|
+
}
|
|
576
|
+
return [
|
|
577
|
+
{
|
|
578
|
+
...model,
|
|
579
|
+
metadata: msg.metadata,
|
|
580
|
+
promptEnter: true,
|
|
581
|
+
vaultEntryCount: msg.entryCount,
|
|
582
|
+
status: 'vault ready',
|
|
583
|
+
},
|
|
584
|
+
[],
|
|
585
|
+
];
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function handleLoadedEntries(msg, model, deps) {
|
|
589
|
+
if (!sourceEquals(msg.source, model.source)) {
|
|
590
|
+
return [model, []];
|
|
591
|
+
}
|
|
592
|
+
const next = syncExplorer(model, {
|
|
129
593
|
entries: msg.entries,
|
|
130
|
-
filtered,
|
|
131
|
-
cursor,
|
|
132
594
|
metadata: msg.metadata,
|
|
133
|
-
|
|
595
|
+
status: `${msg.entries.length} entries`,
|
|
596
|
+
error: null,
|
|
597
|
+
});
|
|
598
|
+
const manifestCmd = maybeLoadSelectedManifest(next, deps);
|
|
599
|
+
return [
|
|
600
|
+
next,
|
|
601
|
+
[loadStatsCmd(deps.cas, msg.entries, model.source), ...(manifestCmd ? [manifestCmd] : [])],
|
|
602
|
+
];
|
|
134
603
|
}
|
|
135
604
|
|
|
136
|
-
/**
|
|
137
|
-
* Handle a loaded-manifest message.
|
|
138
|
-
*
|
|
139
|
-
* @param {DashMsg & { type: 'loaded-manifest' }} msg
|
|
140
|
-
* @param {DashModel} model
|
|
141
|
-
* @returns {[DashModel, DashCmd[]]}
|
|
142
|
-
*/
|
|
143
605
|
function handleLoadedManifest(msg, model) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
606
|
+
if (!sourceEquals(msg.source, model.source)) {
|
|
607
|
+
return [model, []];
|
|
608
|
+
}
|
|
609
|
+
const manifestCache = new Map(model.manifestCache);
|
|
610
|
+
manifestCache.set(msg.slug, msg.manifest);
|
|
611
|
+
return [syncExplorer(model, { manifestCache, loadingSlug: null }), []];
|
|
147
612
|
}
|
|
148
613
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
614
|
+
function handleLoadError(msg, model) {
|
|
615
|
+
let next = model;
|
|
616
|
+
const error = msg.error ?? 'Unknown dashboard error';
|
|
617
|
+
if (msg.source === 'entries') {
|
|
618
|
+
next = { ...next, status: 'entry load failed', error };
|
|
619
|
+
} else if (msg.source === 'manifest') {
|
|
620
|
+
next = { ...next, loadingSlug: null, error };
|
|
621
|
+
} else if (msg.source === 'refs') {
|
|
622
|
+
next = { ...next, refsStatus: 'error', refsError: error };
|
|
623
|
+
} else if (msg.source === 'stats') {
|
|
624
|
+
next = { ...next, statsStatus: 'error', statsError: error };
|
|
625
|
+
} else if (msg.source === 'doctor') {
|
|
626
|
+
next = { ...next, doctorStatus: 'error', doctorError: error };
|
|
627
|
+
} else if (msg.source === 'treemap') {
|
|
628
|
+
next = { ...next, treemapStatus: 'error', treemapError: error };
|
|
629
|
+
}
|
|
630
|
+
return [pushToast(next, { title: 'Dashboard load failed', message: error, tone: 'ERROR' }), []];
|
|
160
631
|
}
|
|
161
632
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
633
|
+
function handleAuthOkMsg(_msg, model, deps) {
|
|
634
|
+
return enterDashboard({ ...model, vaultEncryptionKey: _msg.encryptionKey ?? null }, deps);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
function handleAuthFailMsg(msg, model) {
|
|
638
|
+
return [{ ...model, authError: msg.error, passphrase: '' }, []];
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
function handleLoadedRefsMsg(msg, model) {
|
|
642
|
+
return [{ ...model, refsStatus: 'ready', refsInventory: msg.refs, refsError: null }, []];
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function handleLoadedStatsMsg(msg, model) {
|
|
646
|
+
if (!sourceEquals(msg.source, model.source)) {
|
|
647
|
+
return [model, []];
|
|
648
|
+
}
|
|
649
|
+
return [{ ...model, statsStatus: 'ready', statsReport: msg.stats, statsError: null }, []];
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
function handleLoadedDoctorMsg(msg, model) {
|
|
653
|
+
if (!sourceEquals(msg.source, model.source)) {
|
|
654
|
+
return [model, []];
|
|
655
|
+
}
|
|
656
|
+
return [{ ...model, doctorStatus: 'ready', doctorReport: msg.report, doctorError: null }, []];
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
function handleLoadedTreemapMsg(msg, model) {
|
|
660
|
+
return [
|
|
661
|
+
{
|
|
662
|
+
...model,
|
|
663
|
+
treemapStatus: 'ready',
|
|
664
|
+
treemapReport: msg.report,
|
|
665
|
+
treemapFocus: 0,
|
|
666
|
+
treemapError: null,
|
|
667
|
+
},
|
|
668
|
+
[],
|
|
669
|
+
];
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
function handleLoadedBranchMsg(msg, model) {
|
|
673
|
+
return [{ ...model, gitBranch: msg.branch }, []];
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
function handleStoreCompleteMsg(msg, model, deps) {
|
|
677
|
+
const manifestCache = new Map(model.manifestCache);
|
|
678
|
+
manifestCache.set(msg.slug, msg.manifest);
|
|
679
|
+
const next = pushToast(
|
|
680
|
+
{
|
|
681
|
+
...syncExplorer(model, { manifestCache, storeWizard: null }),
|
|
682
|
+
operationFeed: completeLatestOperation(model.operationFeed, msg.slug, null),
|
|
683
|
+
},
|
|
684
|
+
{ title: 'Stored asset', message: `${msg.slug} -> ${shortenSha(msg.treeOid)}`, tone: 'SUCCESS' }
|
|
685
|
+
);
|
|
686
|
+
return [
|
|
687
|
+
next,
|
|
688
|
+
[loadEntriesCmd(casForModel(deps.cas, model), model.source), ...notificationTick(next, deps)],
|
|
689
|
+
];
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
function handleStoreErrorMsg(msg, model, deps) {
|
|
693
|
+
const next = pushToast(
|
|
694
|
+
{
|
|
695
|
+
...model,
|
|
696
|
+
storeWizard: model.storeWizard
|
|
697
|
+
? { ...model.storeWizard, step: 'error', error: msg.error }
|
|
698
|
+
: null,
|
|
699
|
+
operationFeed: completeLatestOperation(
|
|
700
|
+
model.operationFeed,
|
|
701
|
+
model.storeWizard?.slug ?? 'store',
|
|
702
|
+
msg.error
|
|
703
|
+
),
|
|
704
|
+
},
|
|
705
|
+
{ title: 'Store failed', message: msg.error, tone: 'ERROR' }
|
|
706
|
+
);
|
|
707
|
+
return [next, notificationTick(next, deps)];
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
const APP_MSG_HANDLERS = {
|
|
711
|
+
'notification-tick': handleTickMsg,
|
|
712
|
+
'title-tick': handleTickMsg,
|
|
713
|
+
'vault-auth-check': handleVaultAuthCheck,
|
|
714
|
+
'vault-auth-ok': handleAuthOkMsg,
|
|
715
|
+
'vault-auth-fail': handleAuthFailMsg,
|
|
716
|
+
'loaded-entries': handleLoadedEntries,
|
|
717
|
+
'loaded-manifest': handleLoadedManifest,
|
|
718
|
+
'loaded-refs': handleLoadedRefsMsg,
|
|
719
|
+
'loaded-stats': handleLoadedStatsMsg,
|
|
720
|
+
'loaded-doctor': handleLoadedDoctorMsg,
|
|
721
|
+
'loaded-treemap': handleLoadedTreemapMsg,
|
|
722
|
+
'loaded-branch': handleLoadedBranchMsg,
|
|
723
|
+
'store-complete': handleStoreCompleteMsg,
|
|
724
|
+
'store-error': handleStoreErrorMsg,
|
|
725
|
+
'load-error': handleLoadError,
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
function handleAppMsg(msg, model, deps) {
|
|
729
|
+
const handler = APP_MSG_HANDLERS[msg.type];
|
|
730
|
+
return handler ? handler(msg, model, deps) : [model, []];
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
function handleTitleKey(msg, model, deps) {
|
|
734
|
+
if (msg.key === '`') {
|
|
735
|
+
return [{ ...model, showPerfHud: !model.showPerfHud }, []];
|
|
736
|
+
}
|
|
737
|
+
if (msg.key === 'q' || msg.key === 'escape') {
|
|
738
|
+
return [model, [quit()]];
|
|
739
|
+
}
|
|
740
|
+
if (msg.key === 'enter' && model.promptEnter) {
|
|
741
|
+
return enterDashboard(model, deps);
|
|
742
|
+
}
|
|
743
|
+
return [model, []];
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
function handlePasswordKey(msg, model, deps) {
|
|
747
|
+
if (msg.key === '`') {
|
|
748
|
+
return [{ ...model, showPerfHud: !model.showPerfHud }, []];
|
|
749
|
+
}
|
|
750
|
+
if (msg.key === 'escape') {
|
|
751
|
+
return [model, [quit()]];
|
|
752
|
+
}
|
|
753
|
+
if (msg.key === 'enter') {
|
|
754
|
+
return [{ ...model, authError: null }, [verifyPassphraseCmd(deps.cas, model.passphrase)]];
|
|
172
755
|
}
|
|
173
756
|
if (msg.key === 'backspace') {
|
|
174
|
-
|
|
175
|
-
const filtered = applyFilter(model.entries, text);
|
|
176
|
-
return [{ ...model, filterText: text, filtered, cursor: 0 }, []];
|
|
757
|
+
return [{ ...model, passphrase: model.passphrase.slice(0, -1) }, []];
|
|
177
758
|
}
|
|
178
759
|
if (msg.key.length === 1) {
|
|
179
|
-
|
|
180
|
-
const filtered = applyFilter(model.entries, text);
|
|
181
|
-
return [{ ...model, filterText: text, filtered, cursor: 0 }, []];
|
|
760
|
+
return [{ ...model, passphrase: model.passphrase + msg.key }, []];
|
|
182
761
|
}
|
|
183
762
|
return [model, []];
|
|
184
763
|
}
|
|
185
764
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
765
|
+
function buildPaletteItems(model) {
|
|
766
|
+
return model.entries.map((entry) => {
|
|
767
|
+
const manifest = manifestFor(entry, model.manifestCache);
|
|
768
|
+
const digests = (manifest?.chunks ?? [])
|
|
769
|
+
.slice(0, 4)
|
|
770
|
+
.flatMap((chunk) => [chunk.digest, chunk.blob])
|
|
771
|
+
.filter(Boolean)
|
|
772
|
+
.join(' ');
|
|
773
|
+
return {
|
|
774
|
+
id: entry.slug,
|
|
775
|
+
label: entry.slug,
|
|
776
|
+
category: 'asset',
|
|
777
|
+
description: `${entry.treeOid} ${manifest?.integrity ?? ''} ${digests}`.trim(),
|
|
778
|
+
shortcut: 'enter',
|
|
779
|
+
};
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
function openPalette(model) {
|
|
784
|
+
return {
|
|
785
|
+
...model,
|
|
786
|
+
palette: createCommandPaletteState(buildPaletteItems(model), 9),
|
|
787
|
+
showHelp: false,
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
function selectPaletteItem(model, deps) {
|
|
792
|
+
const item = cpSelectedItem(model.palette);
|
|
793
|
+
if (!item) {
|
|
794
|
+
return [{ ...model, palette: null }, []];
|
|
795
|
+
}
|
|
796
|
+
const selected = model.entries.find((entry) => entry.slug === item.id);
|
|
797
|
+
const next = syncExplorer(model, {
|
|
798
|
+
workspace: 'explorer',
|
|
799
|
+
explorerMode: 'manifest',
|
|
800
|
+
palette: null,
|
|
801
|
+
filterText: selected ? selected.slug : model.filterText,
|
|
802
|
+
filtering: false,
|
|
803
|
+
});
|
|
804
|
+
const manifestCmd = maybeLoadSelectedManifest(next, deps);
|
|
805
|
+
return [next, manifestCmd ? [manifestCmd] : []];
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
const PALETTE_ACTIONS = {
|
|
809
|
+
close: (_msg, model) => [{ ...model, palette: null }, []],
|
|
810
|
+
select: (_msg, model, deps) => selectPaletteItem(model, deps),
|
|
811
|
+
next: (_msg, model) => [{ ...model, palette: cpFocusNext(model.palette) }, []],
|
|
812
|
+
previous: (_msg, model) => [{ ...model, palette: cpFocusPrev(model.palette) }, []],
|
|
813
|
+
pageDown: (_msg, model) => [{ ...model, palette: cpPageDown(model.palette) }, []],
|
|
814
|
+
pageUp: (_msg, model) => [{ ...model, palette: cpPageUp(model.palette) }, []],
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
const PALETTE_KEY_ACTIONS = {
|
|
818
|
+
escape: 'close',
|
|
819
|
+
enter: 'select',
|
|
820
|
+
down: 'next',
|
|
821
|
+
up: 'previous',
|
|
822
|
+
pagedown: 'pageDown',
|
|
823
|
+
pageup: 'pageUp',
|
|
824
|
+
};
|
|
825
|
+
|
|
826
|
+
function paletteAction(msg) {
|
|
827
|
+
if (msg.ctrl && msg.key === 'n') {
|
|
828
|
+
return 'next';
|
|
829
|
+
}
|
|
830
|
+
if (msg.ctrl && msg.key === 'p') {
|
|
831
|
+
return 'previous';
|
|
832
|
+
}
|
|
833
|
+
if (msg.ctrl && msg.key === 'd') {
|
|
834
|
+
return 'pageDown';
|
|
835
|
+
}
|
|
836
|
+
if (msg.ctrl && msg.key === 'u') {
|
|
837
|
+
return 'pageUp';
|
|
838
|
+
}
|
|
839
|
+
return PALETTE_KEY_ACTIONS[msg.key] ?? null;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
function paletteQueryForKey(msg, palette) {
|
|
843
|
+
if (msg.key === 'backspace') {
|
|
844
|
+
return palette.query.slice(0, -1);
|
|
845
|
+
}
|
|
846
|
+
if (msg.key.length === 1 && !msg.ctrl && !msg.alt) {
|
|
847
|
+
return `${palette.query}${msg.key}`;
|
|
848
|
+
}
|
|
849
|
+
return null;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
function handlePaletteKey(msg, model, deps) {
|
|
853
|
+
if (!model.palette) {
|
|
196
854
|
return [model, []];
|
|
197
855
|
}
|
|
198
|
-
const
|
|
199
|
-
|
|
856
|
+
const action = paletteAction(msg);
|
|
857
|
+
if (action) {
|
|
858
|
+
return PALETTE_ACTIONS[action](msg, model, deps);
|
|
859
|
+
}
|
|
860
|
+
const query = paletteQueryForKey(msg, model.palette);
|
|
861
|
+
return query === null ? [model, []] : [{ ...model, palette: cpFilter(model.palette, query) }, []];
|
|
200
862
|
}
|
|
201
863
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
* @returns {[DashModel, DashCmd[]]}
|
|
209
|
-
*/
|
|
210
|
-
function handleAction(action, model, deps) {
|
|
211
|
-
if (action.type === 'quit') { return [model, [quit()]]; }
|
|
212
|
-
if (action.type === 'move') { return handleMove(action, model); }
|
|
213
|
-
if (action.type === 'filter-start') {
|
|
214
|
-
return [{ ...model, filtering: true, filterText: '', filtered: model.entries, cursor: 0 }, []];
|
|
864
|
+
function handleFilterKey(msg, model) {
|
|
865
|
+
if (msg.key === 'escape') {
|
|
866
|
+
return [syncExplorer(model, { filtering: false }), []];
|
|
867
|
+
}
|
|
868
|
+
if (msg.key === 'enter') {
|
|
869
|
+
return [syncExplorer(model, { filtering: false }), []];
|
|
215
870
|
}
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
|
|
871
|
+
if (msg.key === 'backspace') {
|
|
872
|
+
return [syncExplorer(model, { filterText: model.filterText.slice(0, -1) }), []];
|
|
873
|
+
}
|
|
874
|
+
if (msg.key.length === 1 && !msg.ctrl && !msg.alt) {
|
|
875
|
+
return [syncExplorer(model, { filterText: `${model.filterText}${msg.key}` }), []];
|
|
219
876
|
}
|
|
220
|
-
if (action.type === 'select') { return handleSelect(model, deps); }
|
|
221
877
|
return [model, []];
|
|
222
878
|
}
|
|
223
879
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
880
|
+
const LEDGER_NAVIGATORS = {
|
|
881
|
+
j: navTableFocusNext,
|
|
882
|
+
down: navTableFocusNext,
|
|
883
|
+
k: navTableFocusPrev,
|
|
884
|
+
up: navTableFocusPrev,
|
|
885
|
+
d: navTablePageDown,
|
|
886
|
+
pagedown: navTablePageDown,
|
|
887
|
+
u: navTablePageUp,
|
|
888
|
+
pageup: navTablePageUp,
|
|
889
|
+
};
|
|
890
|
+
|
|
891
|
+
function handleExplorerNavigation(msg, model, deps) {
|
|
892
|
+
if (model.focusPane !== 'ledger') {
|
|
893
|
+
return null;
|
|
894
|
+
}
|
|
895
|
+
const navigate = LEDGER_NAVIGATORS[msg.key];
|
|
896
|
+
if (!navigate) {
|
|
897
|
+
return null;
|
|
898
|
+
}
|
|
899
|
+
const next = { ...model, table: navigate(model.table), chunkFocus: 0 };
|
|
900
|
+
const manifestCmd = maybeLoadSelectedManifest(next, deps);
|
|
901
|
+
return [next, manifestCmd ? [manifestCmd] : []];
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
function selectedChunks(model) {
|
|
905
|
+
return selectedManifest(model)?.chunks ?? [];
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
function clampChunkFocus(model, nextFocus) {
|
|
909
|
+
const chunks = selectedChunks(model);
|
|
910
|
+
return Math.max(0, Math.min(nextFocus, Math.max(0, chunks.length - 1)));
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
function chunkPageStep(model) {
|
|
914
|
+
return Math.max(1, Math.min(24, model.rows - 14));
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
function moveChunkFocus(model, delta) {
|
|
918
|
+
return [{ ...model, chunkFocus: clampChunkFocus(model, model.chunkFocus + delta) }, []];
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
function detailDeltaForKey(key, model) {
|
|
922
|
+
if (key === 'j' || key === 'down') {
|
|
923
|
+
return 1;
|
|
924
|
+
}
|
|
925
|
+
if (key === 'k' || key === 'up') {
|
|
926
|
+
return -1;
|
|
927
|
+
}
|
|
928
|
+
if (key === 'd' || key === 'pagedown') {
|
|
929
|
+
return chunkPageStep(model);
|
|
930
|
+
}
|
|
931
|
+
if (key === 'u' || key === 'pageup') {
|
|
932
|
+
return -chunkPageStep(model);
|
|
933
|
+
}
|
|
934
|
+
return null;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
function handleDetailNavigation(msg, model) {
|
|
938
|
+
if (model.focusPane !== 'detail' || model.explorerMode === 'ledger') {
|
|
939
|
+
return null;
|
|
940
|
+
}
|
|
941
|
+
if (selectedChunks(model).length === 0) {
|
|
942
|
+
return null;
|
|
943
|
+
}
|
|
944
|
+
const delta = detailDeltaForKey(msg.key, model);
|
|
945
|
+
if (delta !== null) {
|
|
946
|
+
return moveChunkFocus(model, delta);
|
|
947
|
+
}
|
|
948
|
+
if (msg.key === 'g') {
|
|
949
|
+
return [{ ...model, chunkFocus: 0 }, []];
|
|
950
|
+
}
|
|
951
|
+
return null;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
function switchWorkspace(model, workspace, deps) {
|
|
955
|
+
const next = { ...model, workspace, showHelp: false };
|
|
956
|
+
if (workspace === 'atlas' && next.treemapStatus === 'idle') {
|
|
957
|
+
const cas = casForModel(deps.cas, next);
|
|
958
|
+
return [
|
|
959
|
+
{ ...next, treemapStatus: 'loading' },
|
|
960
|
+
[
|
|
961
|
+
loadTreemapCmd(cas, {
|
|
962
|
+
source: next.source,
|
|
963
|
+
scope: next.treemapScope,
|
|
964
|
+
worktreeMode: next.treemapWorktreeMode,
|
|
965
|
+
drillPath: next.treemapPath,
|
|
966
|
+
}),
|
|
967
|
+
],
|
|
968
|
+
];
|
|
969
|
+
}
|
|
970
|
+
if (workspace === 'operations' && next.statsStatus === 'idle') {
|
|
971
|
+
return [
|
|
972
|
+
{ ...next, statsStatus: 'loading' },
|
|
973
|
+
[loadStatsCmd(deps.cas, next.entries, next.source)],
|
|
974
|
+
];
|
|
975
|
+
}
|
|
976
|
+
return [next, []];
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
function handleWorkspaceKey(msg, model, deps) {
|
|
980
|
+
if (msg.key === '1' || msg.key === 'e') {
|
|
981
|
+
return switchWorkspace(model, 'explorer', deps);
|
|
982
|
+
}
|
|
983
|
+
if (msg.key === '2' || msg.key === 'a') {
|
|
984
|
+
return switchWorkspace(model, 'atlas', deps);
|
|
985
|
+
}
|
|
986
|
+
if (msg.key === '3' || msg.key === 'o') {
|
|
987
|
+
return switchWorkspace(model, 'operations', deps);
|
|
988
|
+
}
|
|
989
|
+
return null;
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
function toggleExplorerDetail(model, deps) {
|
|
993
|
+
const enteringDetail = model.explorerMode === 'ledger';
|
|
994
|
+
const next = {
|
|
995
|
+
...model,
|
|
996
|
+
explorerMode: enteringDetail ? 'manifest' : 'ledger',
|
|
997
|
+
focusPane: enteringDetail ? 'detail' : 'ledger',
|
|
998
|
+
};
|
|
999
|
+
const manifestCmd = maybeLoadSelectedManifest(next, deps);
|
|
1000
|
+
return [next, manifestCmd ? [manifestCmd] : []];
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
function cycleMerkleMode(model) {
|
|
1004
|
+
const modes = /** @type {MerkleMode[]} */ (['table', 'tree', 'dag']);
|
|
1005
|
+
const nextMode = modes[(modes.indexOf(model.merkleMode) + 1) % modes.length];
|
|
1006
|
+
return [{ ...model, explorerMode: 'merkle', merkleMode: nextMode, focusPane: 'detail' }, []];
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
function toggleInspectorMode(model, deps) {
|
|
1010
|
+
const next = {
|
|
1011
|
+
...model,
|
|
1012
|
+
explorerMode: model.explorerMode === 'manifest' ? 'merkle' : 'manifest',
|
|
1013
|
+
focusPane: 'detail',
|
|
1014
|
+
};
|
|
1015
|
+
const manifestCmd = maybeLoadSelectedManifest(next, deps);
|
|
1016
|
+
return [next, manifestCmd ? [manifestCmd] : []];
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
function handleExplorerModeKey(msg, model, deps) {
|
|
1020
|
+
if (msg.key === 'enter') {
|
|
1021
|
+
return toggleExplorerDetail(model, deps);
|
|
1022
|
+
}
|
|
1023
|
+
if (msg.key === 'm') {
|
|
1024
|
+
return cycleMerkleMode(model);
|
|
1025
|
+
}
|
|
1026
|
+
if (msg.key === 'i') {
|
|
1027
|
+
return toggleInspectorMode(model, deps);
|
|
1028
|
+
}
|
|
1029
|
+
return null;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
function handleExplorerKey(msg, model, deps) {
|
|
1033
|
+
if (msg.key === 'tab') {
|
|
1034
|
+
return [{ ...model, focusPane: model.focusPane === 'ledger' ? 'detail' : 'ledger' }, []];
|
|
1035
|
+
}
|
|
1036
|
+
const detailNav = handleDetailNavigation(msg, model);
|
|
1037
|
+
if (detailNav) {
|
|
1038
|
+
return detailNav;
|
|
1039
|
+
}
|
|
1040
|
+
const nav = handleExplorerNavigation(msg, model, deps);
|
|
1041
|
+
if (nav) {
|
|
1042
|
+
return nav;
|
|
1043
|
+
}
|
|
1044
|
+
return handleExplorerModeKey(msg, model, deps);
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
function reloadTreemap(model, deps, patch = {}) {
|
|
1048
|
+
const next = { ...model, ...patch, treemapStatus: 'loading', treemapError: null };
|
|
1049
|
+
return [
|
|
1050
|
+
next,
|
|
1051
|
+
[
|
|
1052
|
+
loadTreemapCmd(casForModel(deps.cas, next), {
|
|
1053
|
+
source: next.source,
|
|
1054
|
+
scope: next.treemapScope,
|
|
1055
|
+
worktreeMode: next.treemapWorktreeMode,
|
|
1056
|
+
drillPath: next.treemapPath,
|
|
1057
|
+
}),
|
|
1058
|
+
],
|
|
1059
|
+
];
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
function focusAtlasTile(model, delta) {
|
|
1063
|
+
const tiles = model.treemapReport?.tiles ?? [];
|
|
1064
|
+
const maxFocus = Math.max(0, tiles.length - 1);
|
|
1065
|
+
return [
|
|
1066
|
+
{ ...model, treemapFocus: Math.max(0, Math.min(model.treemapFocus + delta, maxFocus)) },
|
|
1067
|
+
[],
|
|
1068
|
+
];
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
function drillIntoAtlasTile(model, deps) {
|
|
1072
|
+
const tile = model.treemapReport?.tiles?.[model.treemapFocus];
|
|
1073
|
+
return tile?.drillable && tile.path
|
|
1074
|
+
? reloadTreemap(model, deps, { treemapPath: [...model.treemapPath, tile.path] })
|
|
1075
|
+
: null;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
function drillOutAtlasTile(model, deps) {
|
|
1079
|
+
return model.treemapPath.length > 0
|
|
1080
|
+
? reloadTreemap(model, deps, { treemapPath: model.treemapPath.slice(0, -1) })
|
|
1081
|
+
: null;
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
const ATLAS_KEY_ACTIONS = {
|
|
1085
|
+
j: 'next',
|
|
1086
|
+
down: 'next',
|
|
1087
|
+
k: 'previous',
|
|
1088
|
+
up: 'previous',
|
|
1089
|
+
t: 'scope',
|
|
1090
|
+
i: 'worktreeMode',
|
|
1091
|
+
r: 'reload',
|
|
1092
|
+
'+': 'drillIn',
|
|
1093
|
+
enter: 'drillIn',
|
|
1094
|
+
'-': 'drillOut',
|
|
1095
|
+
backspace: 'drillOut',
|
|
1096
|
+
};
|
|
1097
|
+
|
|
1098
|
+
const ATLAS_ACTIONS = {
|
|
1099
|
+
next: (_msg, model) => focusAtlasTile(model, 1),
|
|
1100
|
+
previous: (_msg, model) => focusAtlasTile(model, -1),
|
|
1101
|
+
scope: (_msg, model, deps) =>
|
|
1102
|
+
reloadTreemap(model, deps, {
|
|
1103
|
+
treemapScope: model.treemapScope === 'repository' ? 'source' : 'repository',
|
|
1104
|
+
treemapPath: [],
|
|
1105
|
+
}),
|
|
1106
|
+
worktreeMode: (_msg, model, deps) =>
|
|
1107
|
+
reloadTreemap(model, deps, {
|
|
1108
|
+
treemapWorktreeMode: model.treemapWorktreeMode === 'tracked' ? 'ignored' : 'tracked',
|
|
1109
|
+
treemapPath: [],
|
|
1110
|
+
}),
|
|
1111
|
+
reload: (_msg, model, deps) => reloadTreemap(model, deps),
|
|
1112
|
+
drillIn: (_msg, model, deps) => drillIntoAtlasTile(model, deps),
|
|
1113
|
+
drillOut: (_msg, model, deps) => drillOutAtlasTile(model, deps),
|
|
1114
|
+
};
|
|
1115
|
+
|
|
1116
|
+
function handleAtlasKey(msg, model, deps) {
|
|
1117
|
+
const action = ATLAS_KEY_ACTIONS[msg.key];
|
|
1118
|
+
return action ? ATLAS_ACTIONS[action](msg, model, deps) : null;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
function startOperation(operationFeed, slug) {
|
|
1122
|
+
return {
|
|
1123
|
+
...operationFeed,
|
|
1124
|
+
entries: [
|
|
1125
|
+
{
|
|
1126
|
+
id: `store-${slug}-${Date.now()}`,
|
|
1127
|
+
type: 'store',
|
|
1128
|
+
slug,
|
|
1129
|
+
status: 'running',
|
|
1130
|
+
startTime: Date.now(),
|
|
1131
|
+
endTime: null,
|
|
1132
|
+
chunksTotal: 0,
|
|
1133
|
+
chunksProcessed: 0,
|
|
1134
|
+
error: null,
|
|
1135
|
+
},
|
|
1136
|
+
...operationFeed.entries,
|
|
1137
|
+
].slice(0, operationFeed.maxEntries),
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
function completeLatestOperation(operationFeed, slug, error) {
|
|
1142
|
+
return {
|
|
1143
|
+
...operationFeed,
|
|
1144
|
+
entries: operationFeed.entries.map((entry, index) => {
|
|
1145
|
+
if (index !== 0 || entry.slug !== slug) {
|
|
1146
|
+
return entry;
|
|
1147
|
+
}
|
|
1148
|
+
return {
|
|
1149
|
+
...entry,
|
|
1150
|
+
status: error ? 'error' : 'done',
|
|
1151
|
+
endTime: Date.now(),
|
|
1152
|
+
error,
|
|
1153
|
+
};
|
|
1154
|
+
}),
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
function handleWizardKey(msg, model, deps) {
|
|
1159
|
+
if (!model.storeWizard) {
|
|
1160
|
+
return null;
|
|
1161
|
+
}
|
|
1162
|
+
if (msg.key === 'escape') {
|
|
1163
|
+
return [{ ...model, storeWizard: null }, []];
|
|
1164
|
+
}
|
|
1165
|
+
const nextWizard = wizardHandleKey(model.storeWizard, msg.key);
|
|
1166
|
+
if (nextWizard.step === 'storing') {
|
|
1167
|
+
return [
|
|
1168
|
+
{
|
|
1169
|
+
...model,
|
|
1170
|
+
storeWizard: nextWizard,
|
|
1171
|
+
operationFeed: startOperation(model.operationFeed, nextWizard.slug),
|
|
1172
|
+
},
|
|
1173
|
+
[runStoreWizardCmd(casForModel(deps.cas, model), nextWizard)],
|
|
1174
|
+
];
|
|
1175
|
+
}
|
|
1176
|
+
return [{ ...model, storeWizard: nextWizard }, []];
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
function handleOperationsKey(msg, model, deps) {
|
|
1180
|
+
if (msg.key === 'n') {
|
|
1181
|
+
return [{ ...model, storeWizard: createWizardState() }, []];
|
|
1182
|
+
}
|
|
1183
|
+
if (msg.key === 's') {
|
|
1184
|
+
return [
|
|
1185
|
+
{ ...model, statsStatus: 'loading', statsError: null },
|
|
1186
|
+
[loadStatsCmd(deps.cas, model.entries, model.source)],
|
|
1187
|
+
];
|
|
1188
|
+
}
|
|
1189
|
+
if (msg.key === 'x') {
|
|
1190
|
+
return [
|
|
1191
|
+
{
|
|
1192
|
+
...model,
|
|
1193
|
+
doctorStatus: 'loading',
|
|
1194
|
+
doctorError: null,
|
|
1195
|
+
},
|
|
1196
|
+
[
|
|
1197
|
+
loadDoctorCmd(deps.cas, {
|
|
1198
|
+
source: model.source,
|
|
1199
|
+
entries: model.entries,
|
|
1200
|
+
encryptionKey: model.vaultEncryptionKey,
|
|
1201
|
+
}),
|
|
1202
|
+
],
|
|
1203
|
+
];
|
|
1204
|
+
}
|
|
1205
|
+
return null;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
function handleQuitConfirmKey(msg, model) {
|
|
1209
|
+
if (msg.key === 'y' || msg.key === 'enter') {
|
|
1210
|
+
return [model, [quit()]];
|
|
1211
|
+
}
|
|
1212
|
+
if (msg.key === 'n' || msg.key === 'escape' || msg.key === 'q') {
|
|
1213
|
+
return [{ ...model, quitConfirm: false }, []];
|
|
240
1214
|
}
|
|
241
1215
|
return [model, []];
|
|
242
1216
|
}
|
|
243
1217
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
1218
|
+
function clearDashboardOverlays(model) {
|
|
1219
|
+
return {
|
|
1220
|
+
...model,
|
|
1221
|
+
showHelp: false,
|
|
1222
|
+
storeWizard: null,
|
|
1223
|
+
palette: null,
|
|
1224
|
+
filtering: false,
|
|
1225
|
+
quitConfirm: false,
|
|
1226
|
+
settingsOpen: false,
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
function handleOverlayShortcut(msg, model) {
|
|
1231
|
+
if (msg.key === 'escape') {
|
|
1232
|
+
return [clearDashboardOverlays(model), []];
|
|
1233
|
+
}
|
|
1234
|
+
if (msg.key === 'f2') {
|
|
1235
|
+
return [{ ...model, settingsOpen: !model.settingsOpen, showHelp: false, palette: null }, []];
|
|
1236
|
+
}
|
|
1237
|
+
if (msg.key === '?' || (msg.shift && msg.key === '/')) {
|
|
1238
|
+
return [{ ...model, showHelp: !model.showHelp, palette: null }, []];
|
|
1239
|
+
}
|
|
1240
|
+
if (msg.key === 'q') {
|
|
1241
|
+
return [{ ...model, quitConfirm: true }, []];
|
|
1242
|
+
}
|
|
1243
|
+
return null;
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
function handleSearchShortcut(msg, model) {
|
|
1247
|
+
if (msg.key === '/' && !msg.ctrl) {
|
|
1248
|
+
return [syncExplorer(model, { workspace: 'explorer', filtering: true, palette: null }), []];
|
|
1249
|
+
}
|
|
1250
|
+
if ((msg.ctrl && msg.key === 'p') || msg.key === ':') {
|
|
1251
|
+
return [openPalette(model), []];
|
|
1252
|
+
}
|
|
1253
|
+
return null;
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
function handleGlobalDashboardKey(msg, model, deps) {
|
|
1257
|
+
const overlay = handleOverlayShortcut(msg, model);
|
|
1258
|
+
if (overlay) {
|
|
1259
|
+
return overlay;
|
|
1260
|
+
}
|
|
1261
|
+
const search = handleSearchShortcut(msg, model);
|
|
1262
|
+
if (search) {
|
|
1263
|
+
return search;
|
|
1264
|
+
}
|
|
1265
|
+
return handleWorkspaceKey(msg, model, deps);
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
const WORKSPACE_KEY_HANDLERS = {
|
|
1269
|
+
explorer: handleExplorerKey,
|
|
1270
|
+
atlas: handleAtlasKey,
|
|
1271
|
+
operations: handleOperationsKey,
|
|
1272
|
+
};
|
|
1273
|
+
|
|
1274
|
+
function handleWorkspaceSpecificKey(msg, model, deps) {
|
|
1275
|
+
const handler = WORKSPACE_KEY_HANDLERS[model.workspace];
|
|
1276
|
+
return handler ? handler(msg, model, deps) : null;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
function handleDashboardKey(msg, model, deps) {
|
|
1280
|
+
if (model.quitConfirm) {
|
|
1281
|
+
return handleQuitConfirmKey(msg, model);
|
|
1282
|
+
}
|
|
1283
|
+
if (model.palette) {
|
|
1284
|
+
return handlePaletteKey(msg, model, deps);
|
|
1285
|
+
}
|
|
1286
|
+
const wizard = handleWizardKey(msg, model, deps);
|
|
1287
|
+
if (wizard) {
|
|
1288
|
+
return wizard;
|
|
1289
|
+
}
|
|
1290
|
+
if (model.filtering) {
|
|
254
1291
|
return handleFilterKey(msg, model);
|
|
255
1292
|
}
|
|
1293
|
+
const global = handleGlobalDashboardKey(msg, model, deps);
|
|
1294
|
+
return global ?? handleWorkspaceSpecificKey(msg, model, deps) ?? [model, []];
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
function handleUpdate(msg, model, deps) {
|
|
256
1298
|
if (msg.type === 'key') {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
1299
|
+
if (model.phase === 'title') {
|
|
1300
|
+
return handleTitleKey(msg, model, deps);
|
|
1301
|
+
}
|
|
1302
|
+
if (model.phase === 'password') {
|
|
1303
|
+
return handlePasswordKey(msg, model, deps);
|
|
1304
|
+
}
|
|
1305
|
+
return handleDashboardKey(msg, model, deps);
|
|
260
1306
|
}
|
|
261
1307
|
if (msg.type === 'resize') {
|
|
262
|
-
return [
|
|
1308
|
+
return [syncExplorer(model, { columns: msg.columns, rows: msg.rows }), []];
|
|
263
1309
|
}
|
|
264
|
-
return handleAppMsg(
|
|
1310
|
+
return handleAppMsg(msg, model, deps);
|
|
265
1311
|
}
|
|
266
1312
|
|
|
267
|
-
/**
|
|
268
|
-
* Create the TEA app object for the dashboard.
|
|
269
|
-
*
|
|
270
|
-
* @param {DashDeps} deps
|
|
271
|
-
* @returns {import('@flyingrobots/bijou-tui').App<DashModel, DashMsg>}
|
|
272
|
-
*/
|
|
273
1313
|
export function createDashboardApp(deps) {
|
|
274
1314
|
return {
|
|
275
|
-
init: () =>
|
|
276
|
-
|
|
277
|
-
|
|
1315
|
+
init: () => [
|
|
1316
|
+
createInitModel(deps.ctx, deps.source),
|
|
1317
|
+
[checkVaultAuthCmd(deps.cas), deps.tick(TITLE_TICK_MS, { type: 'title-tick' })],
|
|
1318
|
+
],
|
|
1319
|
+
update: (msg, model) => handleUpdate(msg, model, deps),
|
|
1320
|
+
view: (model) => renderDashboard(model, deps),
|
|
278
1321
|
};
|
|
279
1322
|
}
|
|
280
1323
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
process.stdout.write(`${slug}\t${treeOid}\n`);
|
|
1324
|
+
async function printStaticList(cas, source, output) {
|
|
1325
|
+
const { entries } = await readSourceEntries(cas, source);
|
|
1326
|
+
output.write(formatTabSeparated(entries));
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
function normalizeLaunchContext(ctx) {
|
|
1330
|
+
if (!ctx.mode && !ctx.runtime) {
|
|
1331
|
+
throw new Error('launchDashboard requires ctx.runtime when ctx.mode is absent');
|
|
290
1332
|
}
|
|
1333
|
+
return ctx;
|
|
291
1334
|
}
|
|
292
1335
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
export async function launchDashboard(cas) {
|
|
299
|
-
if (!process.stdout.isTTY) {
|
|
300
|
-
return printStaticList(cas);
|
|
1336
|
+
export async function launchDashboard(cas, options = {}) {
|
|
1337
|
+
const ctx = options.ctx ? normalizeLaunchContext(options.ctx) : createCliTuiContext();
|
|
1338
|
+
const source = options.source ?? { type: 'vault' };
|
|
1339
|
+
if (ctx.mode !== 'interactive') {
|
|
1340
|
+
return printStaticList(cas, source, options.output || process.stdout);
|
|
301
1341
|
}
|
|
302
|
-
const
|
|
303
|
-
const
|
|
304
|
-
const
|
|
305
|
-
return
|
|
1342
|
+
const dashTick = options.tick || bijouTick;
|
|
1343
|
+
const deps = { cas, ctx, cwdLabel: options.cwd ?? process.cwd(), source, tick: dashTick };
|
|
1344
|
+
const runApp = options.runApp || bijouStartApp;
|
|
1345
|
+
return runApp(createDashboardApp(deps), { ctx });
|
|
306
1346
|
}
|
|
1347
|
+
|
|
1348
|
+
export { buildTableRows, selectedEntry, selectedManifest, tableSchema };
|
|
1349
|
+
export default launchDashboard;
|