@totalreclaw/totalreclaw 3.3.1-rc.8 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/CHANGELOG.md +268 -1
  2. package/SKILL.md +29 -23
  3. package/api-client.ts +18 -11
  4. package/claims-helper.ts +47 -1
  5. package/config.ts +108 -4
  6. package/confirm-indexed.ts +191 -0
  7. package/crypto.ts +10 -2
  8. package/dist/api-client.js +226 -0
  9. package/dist/billing-cache.js +100 -0
  10. package/dist/claims-helper.js +624 -0
  11. package/dist/config.js +297 -0
  12. package/dist/confirm-indexed.js +127 -0
  13. package/dist/consolidation.js +258 -0
  14. package/dist/contradiction-sync.js +1034 -0
  15. package/dist/crypto.js +138 -0
  16. package/dist/digest-sync.js +361 -0
  17. package/dist/download-ux.js +63 -0
  18. package/dist/embedder-cache.js +185 -0
  19. package/dist/embedder-loader.js +121 -0
  20. package/dist/embedder-network.js +301 -0
  21. package/dist/embedding.js +141 -0
  22. package/dist/extractor.js +1225 -0
  23. package/dist/first-run.js +103 -0
  24. package/dist/fs-helpers.js +725 -0
  25. package/dist/gateway-url.js +197 -0
  26. package/dist/generate-mnemonic.js +13 -0
  27. package/dist/hot-cache-wrapper.js +101 -0
  28. package/dist/import-adapters/base-adapter.js +64 -0
  29. package/dist/import-adapters/chatgpt-adapter.js +238 -0
  30. package/dist/import-adapters/claude-adapter.js +114 -0
  31. package/dist/import-adapters/gemini-adapter.js +201 -0
  32. package/dist/import-adapters/index.js +26 -0
  33. package/dist/import-adapters/mcp-memory-adapter.js +219 -0
  34. package/dist/import-adapters/mem0-adapter.js +158 -0
  35. package/dist/import-adapters/types.js +1 -0
  36. package/dist/index.js +5388 -0
  37. package/dist/llm-client.js +687 -0
  38. package/dist/llm-profile-reader.js +346 -0
  39. package/dist/lsh.js +62 -0
  40. package/dist/onboarding-cli.js +750 -0
  41. package/dist/pair-cli.js +344 -0
  42. package/dist/pair-crypto.js +359 -0
  43. package/dist/pair-http.js +404 -0
  44. package/dist/pair-page.js +826 -0
  45. package/dist/pair-qr.js +107 -0
  46. package/dist/pair-remote-client.js +410 -0
  47. package/dist/pair-session-store.js +566 -0
  48. package/dist/pin.js +556 -0
  49. package/dist/qa-bug-report.js +301 -0
  50. package/dist/relay-headers.js +44 -0
  51. package/dist/reranker.js +409 -0
  52. package/dist/retype-setscope.js +368 -0
  53. package/dist/semantic-dedup.js +75 -0
  54. package/dist/subgraph-search.js +289 -0
  55. package/dist/subgraph-store.js +694 -0
  56. package/dist/tool-gating.js +58 -0
  57. package/download-ux.ts +91 -0
  58. package/embedder-cache.ts +230 -0
  59. package/embedder-loader.ts +189 -0
  60. package/embedder-network.ts +350 -0
  61. package/embedding.ts +118 -27
  62. package/fs-helpers.ts +277 -0
  63. package/gateway-url.ts +57 -9
  64. package/index.ts +469 -250
  65. package/llm-client.ts +4 -3
  66. package/lsh.ts +7 -2
  67. package/onboarding-cli.ts +114 -1
  68. package/package.json +24 -5
  69. package/pair-cli.ts +76 -8
  70. package/pair-crypto.ts +34 -24
  71. package/pair-page.ts +28 -17
  72. package/pair-qr.ts +152 -0
  73. package/pair-remote-client.ts +540 -0
  74. package/pin.ts +31 -0
  75. package/qa-bug-report.ts +84 -2
  76. package/relay-headers.ts +50 -0
  77. package/reranker.ts +40 -0
  78. package/retype-setscope.ts +69 -8
  79. package/skill.json +1 -1
  80. package/subgraph-search.ts +4 -3
  81. package/subgraph-store.ts +15 -10
@@ -0,0 +1,103 @@
1
+ /**
2
+ * first-run — detect a fresh machine and return the welcome/branch-question
3
+ * copy that the `before_agent_start` hook prepends to the first agent prompt
4
+ * after install.
5
+ *
6
+ * Shipped 2026-04-20 as part of the 3.3.0-rc.2 UX polish. Paired with the
7
+ * scanner false-positive fix that unblocked rc.1 install.
8
+ *
9
+ * Scope and scanner surface
10
+ * -------------------------
11
+ * - This module reads credentials.json via `loadCredentialsJson` from
12
+ * `fs-helpers.ts` (the one file in the plugin that is allowed to touch
13
+ * disk) — we do NOT import `node:fs` directly. That preserves the
14
+ * file-level isolation pattern introduced in 3.0.8 (see `fs-helpers.ts`
15
+ * header) and ensures the expanded `check-scanner.mjs` rules cannot
16
+ * flag this file even incidentally.
17
+ * - No network. No env-var reads. No dynamic code execution.
18
+ * - All user-facing copy is exported as `COPY` so tests can assert on
19
+ * exact strings and a future localisation pass has a single seam.
20
+ *
21
+ * Design notes
22
+ * ------------
23
+ * - `detectFirstRun` is deliberately lax: missing file, empty file,
24
+ * JSON-parse-error, or a file that parses but carries no usable
25
+ * mnemonic (neither `mnemonic` nor the `recovery_phrase` alias) all
26
+ * count as first-run. Anything looser would risk double-welcoming a
27
+ * returning user whose credentials.json has been hand-edited.
28
+ * - `buildWelcomePrepend` branches on `'local'` vs `'remote'` gateway
29
+ * mode. The caller in `index.ts` resolves the mode from
30
+ * `api.config.gateway.remote.url` the same way `buildPairingUrl`
31
+ * already does.
32
+ * - Terminology: "recovery phrase" everywhere in user-facing copy. The
33
+ * prior mix of "account key", "mnemonic", "seed phrase", and "recovery
34
+ * phrase" across the plugin was confusing users; 3.3.0-rc.2
35
+ * standardises on "recovery phrase". Internal variable names
36
+ * (`mnemonic`, etc.) are intentionally kept so we do not churn the
37
+ * crypto code for a copy change.
38
+ */
39
+ import { loadCredentialsJson, extractBootstrapMnemonic } from './fs-helpers.js';
40
+ // ---------------------------------------------------------------------------
41
+ // Canonical copy — single source of truth for the welcome-on-first-run UX.
42
+ // Tests import these constants and assert on exact-match substrings; the
43
+ // `index.ts` before_agent_start hook consumes them via `buildWelcomePrepend`.
44
+ // ---------------------------------------------------------------------------
45
+ export const WELCOME = 'Welcome to TotalReclaw — encrypted, agent-portable memory.\n\n' +
46
+ 'Your memories are stored end-to-end encrypted and on-chain. You can restore them on any agent — OpenClaw, Hermes, or NanoClaw — with a single recovery phrase.';
47
+ export const BRANCH_QUESTION = "Let's set up your account. Do you already have a recovery phrase, or should we generate a new one?";
48
+ export const LOCAL_MODE_INSTRUCTIONS = 'If you have one, run: openclaw plugin totalreclaw onboard restore\n' +
49
+ 'If you need a new one, run: openclaw plugin totalreclaw onboard generate';
50
+ export const REMOTE_MODE_INSTRUCTIONS = 'Run: openclaw plugin totalreclaw pair start\n' +
51
+ 'This opens a browser page with a QR code. Scan it (or open the URL) to complete setup securely — your recovery phrase never passes through the chat.';
52
+ export const STORAGE_GUIDANCE = 'Your recovery phrase is 12 words. Store it somewhere safe — a password manager works well. Use it only for TotalReclaw. Don\'t reuse it anywhere else. Don\'t put funds on it.';
53
+ export const RESTORE_PROMPT = 'Enter your 12-word recovery phrase to restore your account.';
54
+ export const GENERATED_CONFIRMATION = 'A new recovery phrase has been generated. Write it down now, somewhere safe. This is the only way to restore your account later.';
55
+ export const COPY = {
56
+ WELCOME,
57
+ BRANCH_QUESTION,
58
+ LOCAL_MODE_INSTRUCTIONS,
59
+ REMOTE_MODE_INSTRUCTIONS,
60
+ STORAGE_GUIDANCE,
61
+ RESTORE_PROMPT,
62
+ GENERATED_CONFIRMATION,
63
+ };
64
+ /**
65
+ * Returns `true` when the machine at `credentialsPath` has never been
66
+ * onboarded. Specifically: the file is missing, unreadable, invalid JSON,
67
+ * or parses but carries neither `mnemonic` nor `recovery_phrase`.
68
+ *
69
+ * All failure modes collapse to "first run" so the welcome can always
70
+ * recover from a broken install. The caller is responsible for deciding
71
+ * whether to ALSO preserve the broken file for recovery (the onboarding
72
+ * wizard already handles that via `autoBootstrapCredentials`).
73
+ */
74
+ export async function detectFirstRun(credentialsPath) {
75
+ const creds = loadCredentialsJson(credentialsPath);
76
+ if (!creds)
77
+ return true;
78
+ const mnemonic = extractBootstrapMnemonic(creds);
79
+ return mnemonic === null || mnemonic.length === 0;
80
+ }
81
+ /**
82
+ * Build the exact text to feed `prependContext` on first run. The text is
83
+ * structured as a markdown block with a visible heading so the agent and
84
+ * user can both tell at a glance that this is the one-shot first-run
85
+ * banner, not arbitrary injected context.
86
+ *
87
+ * The mode-specific instructions branch on whether the gateway is running
88
+ * locally (user has shell access → CLI onboard wizard) or remotely (user
89
+ * needs QR-pairing). The caller resolves the mode from
90
+ * `api.config.gateway.remote.url` — same resolution `buildPairingUrl`
91
+ * uses.
92
+ */
93
+ export function buildWelcomePrepend(mode) {
94
+ const instructions = mode === 'local' ? LOCAL_MODE_INSTRUCTIONS : REMOTE_MODE_INSTRUCTIONS;
95
+ return ('## Welcome to TotalReclaw\n\n' +
96
+ WELCOME +
97
+ '\n\n' +
98
+ BRANCH_QUESTION +
99
+ '\n\n' +
100
+ instructions +
101
+ '\n\n' +
102
+ STORAGE_GUIDANCE);
103
+ }