indelible-mcp 3.9.0 → 4.1.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.
package/README.md CHANGED
@@ -67,19 +67,23 @@ indelible-mcp hook post-compact Post-compaction restore hook
67
67
  ## How It Works
68
68
 
69
69
  1. Your conversation is encrypted locally with your WIF key
70
- 2. An OP_RETURN transaction is built and signed locally using `@bsv/sdk`
71
- 3. The signed transaction is broadcast via Indelible's SPV bridge
72
- 4. Your private key **never** leaves your machine
70
+ 2. A minimal OP_RETURN transaction is built containing only `{protocol, encrypted}` — no metadata leaks
71
+ 3. The signed transaction is broadcast via Indelible's federation bridges
72
+ 4. Session metadata is automatically indexed across all federation bridges for fast retrieval
73
+ 5. Your private key **never** leaves your machine
73
74
 
74
75
  ## Federation
75
76
 
76
77
  Indelible uses a multi-seed architecture — your saves and loads automatically try multiple federation bridges. If one bridge is down, the next picks up. No single point of failure.
77
78
 
79
+ Bridges sync session metadata via SessionRelay (WebSocket peer-to-peer), so all your sessions are available from any bridge in the mesh. The web app and CLI read from bridges first, with blockchain fallback.
80
+
78
81
  The federation mesh is powered by [Relay Federation](https://github.com/zcoolz/relay-federation).
79
82
 
80
83
  ## Security
81
84
 
82
85
  - **Zero-knowledge encryption** - your WIF-derived AES-256-GCM key encrypts all data before it touches the network
86
+ - **Privacy-hardened transactions** - OP_RETURN contains only `{protocol, encrypted}` — no plaintext metadata on-chain
83
87
  - **Self-sovereign keys** - generated locally with `@bsv/sdk`, never transmitted
84
88
  - **Immutable storage** - once on BSV, your data cannot be altered or deleted
85
89
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "indelible-mcp",
3
- "version": "3.9.0",
3
+ "version": "4.1.0",
4
4
  "description": "Blockchain-backed memory and code storage for Claude Code. Save AI conversations and source code permanently on BSV.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/index.js CHANGED
@@ -13,6 +13,7 @@
13
13
  */
14
14
 
15
15
  import { createInterface } from 'node:readline'
16
+ import { execSync } from 'node:child_process'
16
17
  import { homedir } from 'node:os'
17
18
  import { join } from 'node:path'
18
19
  import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync, statSync } from 'node:fs'
@@ -30,6 +31,7 @@ import { updateVaultIndex } from './tools/update_vault_index.js'
30
31
  import { diaryConnect } from './tools/diary_connect.js'
31
32
  import { diaryChat } from './tools/diary_chat.js'
32
33
  import { diarySave } from './tools/diary_save.js'
34
+ import * as spv from './lib/spv.js'
33
35
 
34
36
  const CONTEXT_FILE = join(homedir(), '.indelible', 'indelible-context.jsonl')
35
37
 
@@ -254,7 +256,7 @@ Commands:
254
256
 
255
257
  function printHelp() {
256
258
  console.log(`
257
- Indelible MCP — Blockchain memory for Claude Code (v3.9.0)
259
+ Indelible MCP — Blockchain memory for Claude Code (v4.1.0)
258
260
 
259
261
  Setup:
260
262
  indelible-mcp setup --wif=KEY --pin=PIN Import and encrypt your private key
@@ -466,7 +468,7 @@ function readStdin() {
466
468
 
467
469
  const SERVER_INFO = {
468
470
  name: 'indelible',
469
- version: '3.9.0',
471
+ version: '4.1.0',
470
472
  description: 'Blockchain-backed memory and code storage for Claude Code'
471
473
  }
472
474
 
@@ -732,6 +734,258 @@ async function runMcpServer() {
732
734
  }
733
735
  }
734
736
 
737
+ // ============ SETUP WIZARD ============
738
+
739
+ async function runWizard() {
740
+ const rl = createInterface({ input: process.stdin, output: process.stdout })
741
+ const ask = (q) => new Promise(resolve => rl.question(q, resolve))
742
+
743
+ console.log('\n Welcome to Indelible!\n')
744
+ console.log(' This wizard will set everything up for you.\n')
745
+
746
+ // Check existing config — run health check or resume wizard
747
+ let config = null
748
+ try { config = await loadConfig() } catch {}
749
+
750
+ if (config && config.address) {
751
+ // Run health check
752
+ console.log(' Checking your setup...\n')
753
+ let allGood = true
754
+
755
+ // Claude Code
756
+ try {
757
+ execSync('claude --version', { stdio: 'pipe' })
758
+ console.log(' ✓ Claude Code installed')
759
+ } catch {
760
+ console.log(' ✗ Claude Code not found')
761
+ allGood = false
762
+ }
763
+
764
+ // MCP registered
765
+ const claudeSettings = join(homedir(), '.claude', 'settings.json')
766
+ let mcpOk = false
767
+ try {
768
+ const s = JSON.parse(readFileSync(claudeSettings, 'utf8'))
769
+ mcpOk = !!s?.mcpServers?.indelible
770
+ } catch {}
771
+ console.log(mcpOk ? ' ✓ MCP registered with Claude Code' : ' ✗ MCP not registered')
772
+ if (!mcpOk) allGood = false
773
+
774
+ // Hooks installed
775
+ const hooksPath = join(homedir(), '.claude', 'settings.local.json')
776
+ let hooksOk = false
777
+ try {
778
+ const s = JSON.parse(readFileSync(hooksPath, 'utf8'))
779
+ hooksOk = s?.hooks?.PreCompact?.some(h =>
780
+ h.hooks?.some(hh => hh.command?.includes('indelible-mcp')) ||
781
+ h.command?.includes('indelible-mcp')
782
+ ) && s?.hooks?.SessionStart?.some(h =>
783
+ h.hooks?.some(hh => hh.command?.includes('indelible-mcp')) ||
784
+ h.command?.includes('indelible-mcp')
785
+ )
786
+ } catch {}
787
+ console.log(hooksOk ? ' ✓ Auto-save hooks installed' : ' ✗ Auto-save hooks missing')
788
+ if (!hooksOk) allGood = false
789
+
790
+ // Wallet
791
+ console.log(` ✓ Wallet configured (${config.address})`)
792
+
793
+ // Funded
794
+ let funded = false
795
+ try {
796
+ const utxos = await spv.getUtxos(config.address)
797
+ if (utxos && utxos.length > 0) {
798
+ const total = utxos.reduce((sum, u) => sum + u.satoshis, 0)
799
+ console.log(` ✓ Wallet funded (${total} sats)`)
800
+ funded = true
801
+ } else {
802
+ console.log(' ✗ Wallet not funded')
803
+ allGood = false
804
+ }
805
+ } catch {
806
+ console.log(' ✗ Could not check balance')
807
+ allGood = false
808
+ }
809
+
810
+ // Style
811
+ const hasStyle = !!config.style_txid
812
+ console.log(hasStyle ? ' ✓ AI style saved' : ' ✗ No AI style chosen')
813
+ if (!hasStyle) allGood = false
814
+
815
+ // API reachable
816
+ try {
817
+ const res = await fetch('https://indelible.one/api/health')
818
+ console.log(res.ok ? ' ✓ API reachable' : ' ✗ API unreachable')
819
+ if (!res.ok) allGood = false
820
+ } catch {
821
+ console.log(' ✗ API unreachable')
822
+ allGood = false
823
+ }
824
+
825
+ console.log('')
826
+
827
+ if (allGood) {
828
+ console.log(' Everything looks good! Open Claude Code in VS Code and start coding.\n')
829
+ rl.close()
830
+ return
831
+ }
832
+
833
+ // Resume wizard at the right point
834
+ if (!funded) {
835
+ console.log(' Resuming setup — your wallet needs funding.\n')
836
+ // Fall through to balance polling below
837
+ } else if (!hasStyle) {
838
+ console.log(' Resuming setup — pick your AI style.\n')
839
+ // Skip to style selection (fall through, balance polling will pass instantly)
840
+ } else {
841
+ // Something else failed (hooks, MCP, etc) — try to fix
842
+ if (!mcpOk) {
843
+ console.log(' Fixing: registering MCP with Claude Code...')
844
+ try {
845
+ execSync('claude mcp add indelible -- indelible-mcp', { stdio: 'pipe' })
846
+ console.log(' ✓ MCP registered\n')
847
+ } catch {
848
+ console.log(' Run this yourself: claude mcp add indelible -- indelible-mcp\n')
849
+ }
850
+ }
851
+ if (!hooksOk) {
852
+ console.log(' Fixing: installing auto-save hooks...')
853
+ installHooks()
854
+ console.log(' ✓ Hooks installed\n')
855
+ }
856
+ rl.close()
857
+ return
858
+ }
859
+ } else {
860
+ // Fresh install — run full wizard
861
+
862
+ // Check for Claude Code
863
+ try {
864
+ execSync('claude --version', { stdio: 'pipe' })
865
+ console.log(' ✓ Claude Code found\n')
866
+ } catch {
867
+ console.log(' Claude Code not found. Installing...\n')
868
+ try {
869
+ execSync('npm install -g @anthropic-ai/claude-code', { stdio: 'inherit' })
870
+ console.log('\n ✓ Claude Code installed\n')
871
+ } catch {
872
+ console.log('\n Could not install Claude Code automatically.')
873
+ console.log(' Run this yourself: npm install -g @anthropic-ai/claude-code')
874
+ console.log(' Then run indelible-mcp again.\n')
875
+ rl.close()
876
+ return
877
+ }
878
+ }
879
+
880
+ // Ask for WIF
881
+ console.log(' Next: connect your wallet.\n')
882
+ console.log(' Go to https://indelible.one → Sign in → Settings → copy your Private Key (WIF)\n')
883
+ const wifInput = await ask(' Paste your WIF here: ')
884
+ if (!wifInput || !wifInput.trim()) {
885
+ console.log(' No WIF provided. Run indelible-mcp again when ready.\n')
886
+ rl.close()
887
+ return
888
+ }
889
+
890
+ // Ask for PIN
891
+ console.log('')
892
+ const pinInput = await ask(' Choose a PIN (min 4 characters — you\'ll need this to unlock): ')
893
+ if (!pinInput || pinInput.trim().length < 4) {
894
+ console.log(' PIN must be at least 4 characters. Run indelible-mcp again.\n')
895
+ rl.close()
896
+ return
897
+ }
898
+
899
+ // Run setupWallet
900
+ console.log('\n Setting up wallet...')
901
+ const result = await setupWallet(undefined, wifInput.trim(), pinInput.trim())
902
+ if (!result.success) {
903
+ console.log(` Error: ${result.error || result.message}\n`)
904
+ rl.close()
905
+ return
906
+ }
907
+ console.log(' ✓ Wallet configured\n')
908
+
909
+ // Register MCP with Claude Code
910
+ console.log(' Registering Indelible with Claude Code...')
911
+ try {
912
+ execSync('claude mcp add indelible -- indelible-mcp', { stdio: 'pipe' })
913
+ console.log(' ✓ MCP registered\n')
914
+ } catch {
915
+ console.log(' Could not register automatically.')
916
+ console.log(' Run this yourself: claude mcp add indelible -- indelible-mcp\n')
917
+ }
918
+
919
+ config = await loadConfig()
920
+ }
921
+ // Check if already funded — skip polling if so
922
+ let alreadyFunded = false
923
+ try {
924
+ const utxos = await spv.getUtxos(config.address)
925
+ if (utxos && utxos.length > 0) alreadyFunded = true
926
+ } catch {}
927
+
928
+ if (!alreadyFunded) {
929
+ console.log(` Your BSV address: ${config.address}`)
930
+ console.log(' Send BSV to this address to fund your wallet.')
931
+ console.log(' Each save costs less than $0.01 — even $1 gets you hundreds of saves.\n')
932
+ console.log(' Waiting for funds...')
933
+
934
+ while (true) {
935
+ try {
936
+ const utxos = await spv.getUtxos(config.address)
937
+ if (utxos && utxos.length > 0) {
938
+ const total = utxos.reduce((sum, u) => sum + u.satoshis, 0)
939
+ console.log(`\n ✓ Funded! Balance: ${total} sats\n`)
940
+ break
941
+ }
942
+ } catch {}
943
+ await new Promise(r => setTimeout(r, 10000))
944
+ process.stdout.write('.')
945
+ }
946
+ }
947
+
948
+ // Choose AI style — skip if already saved
949
+ if (!config.style_txid) {
950
+ console.log(' Last step — choose how your AI behaves:\n')
951
+ console.log(' 1. Strict — Confirm everything. Never assume. Never get creative.')
952
+ console.log(' 2. Collaborative — Suggest ideas but wait for approval before coding.')
953
+ console.log(' 3. Autonomous — Move fast. Fix what you see. Commit when ready.\n')
954
+
955
+ const styleChoice = await ask(' Pick 1, 2, or 3 (recommended: 1): ')
956
+ const styleMap = { '1': 'strict', '2': 'collaborative', '3': 'autonomous' }
957
+ const styleName = styleMap[styleChoice?.trim()] || 'strict'
958
+
959
+ console.log(`\n Saving "${styleName}" style to blockchain...`)
960
+ try {
961
+ const presetRes = await fetch('https://indelible.one/api/styles/presets/' + styleName)
962
+ if (presetRes.ok) {
963
+ const preset = await presetRes.json()
964
+ const rulesText = preset.rules.map((r, i) => `${i + 1}. ${r}`).join('\n')
965
+ const styleResult = await saveStyle(rulesText, preset.name, preset.description)
966
+ if (styleResult.success) {
967
+ console.log(` ✓ Style saved to blockchain (tx: ${styleResult.txId.slice(0, 8)}...)\n`)
968
+ } else {
969
+ console.log(` Warning: ${styleResult.error}\n`)
970
+ }
971
+ }
972
+ } catch (e) {
973
+ console.log(` Warning: Could not save style — ${e.message}\n`)
974
+ }
975
+ }
976
+
977
+ console.log(' =========================================')
978
+ console.log(' You\'re all set! Open Claude Code in VS Code and start coding.')
979
+ console.log('')
980
+ console.log(' Quick commands to tell your AI:')
981
+ console.log(' "Save this session to blockchain"')
982
+ console.log(' "Load my previous context"')
983
+ console.log(' "Delta save"')
984
+ console.log(' =========================================\n')
985
+
986
+ rl.close()
987
+ }
988
+
735
989
  // ============ MAIN ============
736
990
 
737
991
  const args = process.argv.slice(2)
@@ -765,5 +1019,5 @@ Add this to your Claude Code settings.json:
765
1019
  // No args, piped stdin = MCP server mode
766
1020
  runMcpServer().catch(console.error)
767
1021
  } else {
768
- printHelp()
1022
+ runWizard().catch(e => { console.error('Error:', e.message); process.exit(1) })
769
1023
  }
@@ -9,6 +9,7 @@
9
9
  */
10
10
 
11
11
  import { readFileSync, existsSync } from 'node:fs'
12
+ import { gunzipSync } from 'node:zlib'
12
13
  import { join } from 'node:path'
13
14
  import { homedir } from 'node:os'
14
15
  import { Transaction } from '@bsv/sdk'
@@ -21,6 +22,16 @@ import { loadStyle } from './load_style.js'
21
22
  const RECENT_MESSAGES_FULL = 25
22
23
  const OLDER_MESSAGES_SUMMARIZED = 15
23
24
 
25
+ /** Decrypt and optionally gunzip a session payload (handles gz: prefix) */
26
+ function decryptSession(encrypted, wif) {
27
+ const text = decrypt(encrypted, wif)
28
+ if (text.startsWith('gz:')) {
29
+ const buf = gunzipSync(Buffer.from(text.slice(3), 'base64'))
30
+ return JSON.parse(buf.toString('utf8'))
31
+ }
32
+ return JSON.parse(text)
33
+ }
34
+
24
35
  function mergeDeltaSessions(sessions) {
25
36
  if (sessions.length === 0) return sessions
26
37
  const ordered = [...sessions].reverse()
@@ -195,7 +206,7 @@ export async function loadContext(numSessions = 5) {
195
206
  for (const entry of recent) {
196
207
  try {
197
208
  if (entry.encrypted) {
198
- const data = JSON.parse(decrypt(entry.encrypted, wif))
209
+ const data = decryptSession(entry.encrypted, wif)
199
210
  decrypted.push(data)
200
211
  }
201
212
  } catch { /* skip sessions that fail to decrypt */ }
@@ -240,12 +251,12 @@ export async function loadContext(numSessions = 5) {
240
251
  for (const session of sessions) {
241
252
  try {
242
253
  if (session.encrypted) {
243
- const data = JSON.parse(decrypt(session.encrypted, wif))
254
+ const data = decryptSession(session.encrypted, wif)
244
255
  decrypted.push(data)
245
256
  } else if (session.txId) {
246
257
  const encrypted = await fetchEncryptedFromChain(session.txId)
247
258
  if (encrypted) {
248
- const data = JSON.parse(decrypt(encrypted, wif))
259
+ const data = decryptSession(encrypted, wif)
249
260
  decrypted.push(data)
250
261
  }
251
262
  }
@@ -4,6 +4,7 @@
4
4
  * Supports v1 (plaintext metadata) and v2 (encrypted metadata).
5
5
  */
6
6
 
7
+ import { gunzipSync } from 'node:zlib'
7
8
  import { writeFileSync } from 'node:fs'
8
9
  import { dirname } from 'node:path'
9
10
  import { mkdirSync, existsSync } from 'node:fs'
@@ -72,8 +73,10 @@ export async function loadFile(txId, options = {}) {
72
73
  }
73
74
  }
74
75
  content = decrypt(encryptedFull, wif)
76
+ if (content.startsWith('gz:')) content = gunzipSync(Buffer.from(content.slice(3), 'base64')).toString('utf8')
75
77
  } else {
76
78
  content = decrypt(payload.encrypted, wif)
79
+ if (content.startsWith('gz:')) content = gunzipSync(Buffer.from(content.slice(3), 'base64')).toString('utf8')
77
80
  }
78
81
 
79
82
  // Decrypt metadata (v2) or use plaintext (v1)
@@ -4,6 +4,7 @@
4
4
  * On-chain: only encrypted data, no plaintext filenames.
5
5
  */
6
6
 
7
+ import { gzipSync } from 'node:zlib'
7
8
  import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'
8
9
  import { basename, join } from 'node:path'
9
10
  import { homedir } from 'node:os'
@@ -40,8 +41,9 @@ export async function saveFile(filePath, options = {}) {
40
41
  const filename = basename(filePath)
41
42
  const relativePath = options.relativePath || filePath
42
43
 
43
- // Encrypt content and metadata
44
- const encrypted = encrypt(content, wif)
44
+ // Gzip compress then encrypt content
45
+ const compressed = gzipSync(Buffer.from(content))
46
+ const encrypted = encrypt('gz:' + compressed.toString('base64'), wif)
45
47
  const filenameEnc = encrypt(filename, wif)
46
48
  const pathEnc = encrypt(relativePath, wif)
47
49
 
@@ -14,6 +14,7 @@
14
14
  */
15
15
 
16
16
  import { readFileSync, writeFileSync, existsSync, statSync, mkdirSync, readdirSync } from 'node:fs'
17
+ import { gzipSync } from 'node:zlib'
17
18
  import { dirname, join } from 'node:path'
18
19
  import { homedir } from 'node:os'
19
20
  import { execSync } from 'node:child_process'
@@ -534,7 +535,8 @@ export async function saveSession(transcriptPath, summary) {
534
535
  if (estimatedFee > COST_WARNING_SATS) {
535
536
  process.stderr.write(`[indelible] WARNING: Estimated cost ~${estimatedFee} sats (~$${(estimatedFee / 1e8 * 15).toFixed(2)}). Rich mode is ${richMode ? 'ON' : 'OFF'}. Set "rich_saves": false in config to reduce cost.\n`)
536
537
  }
537
- const encrypted = encrypt(sessionJson, wif)
538
+ const compressed = gzipSync(Buffer.from(sessionJson))
539
+ const encrypted = encrypt('gz:' + compressed.toString('base64'), wif)
538
540
 
539
541
  // Build the blockchain payload
540
542
  const payload = {