@totalreclaw/mcp-server 3.4.0 → 3.5.1-rc.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 (63) hide show
  1. package/README.md +63 -4
  2. package/SKILL.md +1 -1
  3. package/dist/cli/setup.d.ts +10 -0
  4. package/dist/cli/setup.d.ts.map +1 -1
  5. package/dist/cli/setup.js +10 -0
  6. package/dist/cli/setup.js.map +1 -1
  7. package/dist/contradiction-sync.d.ts.map +1 -1
  8. package/dist/contradiction-sync.js +5 -4
  9. package/dist/contradiction-sync.js.map +1 -1
  10. package/dist/dispatch.js +2 -2
  11. package/dist/dispatch.js.map +1 -1
  12. package/dist/embedding-codec.d.ts +81 -0
  13. package/dist/embedding-codec.d.ts.map +1 -0
  14. package/dist/embedding-codec.js +223 -0
  15. package/dist/embedding-codec.js.map +1 -0
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +286 -67
  18. package/dist/index.js.map +1 -1
  19. package/dist/pair-remote-client.d.ts +41 -0
  20. package/dist/pair-remote-client.d.ts.map +1 -1
  21. package/dist/pair-remote-client.js +130 -32
  22. package/dist/pair-remote-client.js.map +1 -1
  23. package/dist/prompts.d.ts +5 -5
  24. package/dist/prompts.d.ts.map +1 -1
  25. package/dist/prompts.js +8 -9
  26. package/dist/prompts.js.map +1 -1
  27. package/dist/subgraph/bundle.d.ts +129 -0
  28. package/dist/subgraph/bundle.d.ts.map +1 -0
  29. package/dist/subgraph/bundle.js +232 -0
  30. package/dist/subgraph/bundle.js.map +1 -0
  31. package/dist/subgraph/chain-config.d.ts +86 -3
  32. package/dist/subgraph/chain-config.d.ts.map +1 -1
  33. package/dist/subgraph/chain-config.js +71 -2
  34. package/dist/subgraph/chain-config.js.map +1 -1
  35. package/dist/subgraph/credentials.d.ts +83 -0
  36. package/dist/subgraph/credentials.d.ts.map +1 -0
  37. package/dist/subgraph/credentials.js +210 -0
  38. package/dist/subgraph/credentials.js.map +1 -0
  39. package/dist/subgraph/protobuf.d.ts +71 -0
  40. package/dist/subgraph/protobuf.d.ts.map +1 -0
  41. package/dist/subgraph/protobuf.js +114 -0
  42. package/dist/subgraph/protobuf.js.map +1 -0
  43. package/dist/subgraph/store.d.ts +38 -45
  44. package/dist/subgraph/store.d.ts.map +1 -1
  45. package/dist/subgraph/store.js +50 -105
  46. package/dist/subgraph/store.js.map +1 -1
  47. package/dist/tools/account.d.ts +40 -3
  48. package/dist/tools/account.d.ts.map +1 -1
  49. package/dist/tools/account.js +51 -5
  50. package/dist/tools/account.js.map +1 -1
  51. package/dist/tools/index.d.ts +1 -1
  52. package/dist/tools/index.d.ts.map +1 -1
  53. package/dist/tools/index.js +4 -2
  54. package/dist/tools/index.js.map +1 -1
  55. package/dist/tools/pair.d.ts +34 -6
  56. package/dist/tools/pair.d.ts.map +1 -1
  57. package/dist/tools/pair.js +125 -25
  58. package/dist/tools/pair.js.map +1 -1
  59. package/dist/tools/support.js +2 -2
  60. package/dist/tools/support.js.map +1 -1
  61. package/dist/tools/types.d.ts +5 -2
  62. package/dist/tools/types.d.ts.map +1 -1
  63. package/package.json +6 -4
@@ -8,7 +8,7 @@
8
8
  * (chain 100) after ops-1 — the legacy Free → Base Sepolia (84532) routing
9
9
  * was retired, so the local default here is 100, not 84532.
10
10
  */
11
- import type { SubgraphStoreConfig } from './store.js';
11
+ import { type SubgraphStoreConfig } from './store.js';
12
12
  export interface ResolvedChainConfig {
13
13
  /** Chain to submit the write to (verbatim from billing, else Gnosis 100). */
14
14
  chainId: number;
@@ -21,11 +21,32 @@ export interface ResolvedChainConfig {
21
21
  * - `chain_id`: used verbatim when a finite number; otherwise Gnosis (100).
22
22
  * - `data_edge_address`: used only when a valid `0x…40hex` string; otherwise
23
23
  * left undefined so the caller falls through to env / the store default.
24
+ *
25
+ * `onMalformedDataEdge` fires when `data_edge_address` is PRESENT but fails
26
+ * the `0x…40hex` shape check — distinct from the field being simply absent
27
+ * (a legitimate response shape for some relay versions/tiers). A present-
28
+ * but-garbage value is evidence of a relay bug or a tampered response and
29
+ * was previously dropped silently; callers that care (currently
30
+ * `fetchChainConfig` below) should log it loudly rather than let a caller
31
+ * silently fall through to the store's default DataEdge with no trace of
32
+ * why.
24
33
  */
25
- export declare function resolveChainConfig(billing: Record<string, unknown> | null | undefined): ResolvedChainConfig;
34
+ export declare function resolveChainConfig(billing: Record<string, unknown> | null | undefined, onMalformedDataEdge?: (raw: unknown) => void): ResolvedChainConfig;
26
35
  export interface WriteConfigInput {
27
36
  relayUrl: string;
28
- mnemonic: string;
37
+ /**
38
+ * Exactly one of `mnemonic` / `ownerPrivateKeyHex` must be set (Option E
39
+ * Phase 2 / #581, P2-13). Mnemonic-mode clients set `mnemonic`;
40
+ * bundle-mode clients (no mnemonic anywhere in the process — derived-
41
+ * bundle-v1.md §4.6 point 1) set `ownerPrivateKeyHex` from
42
+ * `bundle.signing.private_key` instead. `store.ts`'s
43
+ * `resolveOwnerAccount` prefers `ownerPrivateKeyHex` when both happen to
44
+ * be present (never expected in practice, but privateKey is the more
45
+ * direct source of truth so it wins rather than erroring).
46
+ */
47
+ mnemonic?: string;
48
+ /** Bundle-mode signing key — 64 lowercase hex chars, no `0x` prefix. */
49
+ ownerPrivateKeyHex?: string;
29
50
  authKeyHex: string;
30
51
  walletAddress: string;
31
52
  chainId: number;
@@ -42,4 +63,66 @@ export interface WriteConfigInput {
42
63
  * ordering.
43
64
  */
44
65
  export declare function buildSubgraphOverrides(input: WriteConfigInput): Partial<SubgraphStoreConfig>;
66
+ /**
67
+ * `fetchChainConfig`'s result, extended with whether the billing call
68
+ * itself actually succeeded (200 + parseable JSON). Adversarial-review
69
+ * fixup (PR #618): a caller that only inspects `dataEdgeAddress` cannot
70
+ * tell "billing responded but omitted the field" (rare, arguably legitimate)
71
+ * apart from "billing was completely unreachable" (network error, timeout,
72
+ * non-200) — and those two cases need different responses in bundle mode.
73
+ * See `billingResolved`'s own doc comment.
74
+ */
75
+ export interface FetchedChainConfig extends ResolvedChainConfig {
76
+ /**
77
+ * True iff the billing endpoint responded 200 with parseable JSON —
78
+ * `resolveChainConfig` actually ran against real billing data (even if
79
+ * `chain_id`/`data_edge_address` were absent or malformed within it).
80
+ * False on network failure, timeout, or a non-200 response: the caller
81
+ * fell all the way back to `fallbackChainId` with NO environment
82
+ * information at all. Bundle-mode callers (`index.ts`'s
83
+ * `initSubgraphStateFromBundle`) MUST check this before proceeding — see
84
+ * that function's fail-closed guard.
85
+ */
86
+ billingResolved: boolean;
87
+ }
88
+ export interface FetchChainConfigOptions {
89
+ serverUrl: string;
90
+ smartAccountAddress: string;
91
+ authKeyHex: string;
92
+ /** Extra headers (client id, session tag, …) merged with Authorization. */
93
+ headers?: Record<string, string>;
94
+ /** Chain id to return when the billing call fails/is unreachable. */
95
+ fallbackChainId: number;
96
+ timeoutMs?: number;
97
+ /** Injectable for tests; defaults to the global `fetch`. */
98
+ fetchImpl?: typeof fetch;
99
+ /** Best-effort logger for the tier/chain line other init paths already print. */
100
+ onResolved?: (billing: Record<string, unknown>, resolved: ResolvedChainConfig) => void;
101
+ /**
102
+ * Fires whenever the billing call did NOT succeed — network error,
103
+ * timeout, or a non-200 response — right before falling back to
104
+ * `fallbackChainId` / no DataEdge. `reason` is a short, human-readable
105
+ * description (never contains key material — it only ever describes
106
+ * transport-level failure, ``err.message``/HTTP status).
107
+ */
108
+ onBillingUnavailable?: (reason: string) => void;
109
+ }
110
+ export declare function fetchChainConfig(opts: FetchChainConfigOptions): Promise<FetchedChainConfig>;
111
+ export interface AssertDataEdgeResolvableOptions {
112
+ /** From `fetchChainConfig`'s result. */
113
+ billingResolved: boolean;
114
+ /** `process.env.TOTALRECLAW_DATA_EDGE_ADDRESS` (or the test override). */
115
+ envDataEdgeOverride: string | undefined;
116
+ /** Relay base URL, for the error message only. */
117
+ serverUrl: string;
118
+ }
119
+ /**
120
+ * Throws an actionable error when bundle-mode state construction has no
121
+ * confirmed DataEdge for this environment (billing failed, no env
122
+ * override). No-op (returns) when either `billingResolved` is true (the
123
+ * billing call succeeded — even if it happened not to carry a
124
+ * `data_edge_address`, that's `resolveChainConfig`'s concern, not this
125
+ * guard's) or an explicit env override is present.
126
+ */
127
+ export declare function assertDataEdgeResolvable(opts: AssertDataEdgeResolvableOptions): void;
45
128
  //# sourceMappingURL=chain-config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"chain-config.d.ts","sourceRoot":"","sources":["../../src/subgraph/chain-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAQtD,MAAM,WAAW,mBAAmB;IAClC,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,GAClD,mBAAmB,CAcrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,mBAAmB,CAAC,CAmB9B"}
1
+ {"version":3,"file":"chain-config.d.ts","sourceRoot":"","sources":["../../src/subgraph/chain-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAA6B,KAAK,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAQjF,MAAM,WAAW,mBAAmB;IAClC,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,eAAe,CA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,KAAK,IAAI,CAAC;IACvF;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CACjD;AAID,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,uBAAuB,GAC5B,OAAO,CAAC,kBAAkB,CAAC,CA4B7B;AAuBD,MAAM,WAAW,+BAA+B;IAC9C,wCAAwC;IACxC,eAAe,EAAE,OAAO,CAAC;IACzB,0EAA0E;IAC1E,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,+BAA+B,GAAG,IAAI,CASpF"}
@@ -12,6 +12,9 @@
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.resolveChainConfig = resolveChainConfig;
14
14
  exports.buildSubgraphOverrides = buildSubgraphOverrides;
15
+ exports.fetchChainConfig = fetchChainConfig;
16
+ exports.assertDataEdgeResolvable = assertDataEdgeResolvable;
17
+ const store_js_1 = require("./store.js");
15
18
  /** Default chain when billing is silent — Gnosis mainnet (single-chain, both tiers). */
16
19
  const DEFAULT_CHAIN_ID = 100;
17
20
  /** A DataEdge address is a 20-byte hex string. Reject anything else. */
@@ -22,8 +25,17 @@ const DATA_EDGE_RE = /^0x[0-9a-fA-F]{40}$/;
22
25
  * - `chain_id`: used verbatim when a finite number; otherwise Gnosis (100).
23
26
  * - `data_edge_address`: used only when a valid `0x…40hex` string; otherwise
24
27
  * left undefined so the caller falls through to env / the store default.
28
+ *
29
+ * `onMalformedDataEdge` fires when `data_edge_address` is PRESENT but fails
30
+ * the `0x…40hex` shape check — distinct from the field being simply absent
31
+ * (a legitimate response shape for some relay versions/tiers). A present-
32
+ * but-garbage value is evidence of a relay bug or a tampered response and
33
+ * was previously dropped silently; callers that care (currently
34
+ * `fetchChainConfig` below) should log it loudly rather than let a caller
35
+ * silently fall through to the store's default DataEdge with no trace of
36
+ * why.
25
37
  */
26
- function resolveChainConfig(billing) {
38
+ function resolveChainConfig(billing, onMalformedDataEdge) {
27
39
  let chainId = DEFAULT_CHAIN_ID;
28
40
  const rawChain = billing?.chain_id;
29
41
  if (typeof rawChain === 'number' && Number.isFinite(rawChain)) {
@@ -34,6 +46,9 @@ function resolveChainConfig(billing) {
34
46
  if (typeof rawEdge === 'string' && DATA_EDGE_RE.test(rawEdge)) {
35
47
  dataEdgeAddress = rawEdge;
36
48
  }
49
+ else if (rawEdge !== undefined && rawEdge !== null) {
50
+ onMalformedDataEdge?.(rawEdge);
51
+ }
37
52
  return { chainId, dataEdgeAddress };
38
53
  }
39
54
  /**
@@ -49,10 +64,18 @@ function resolveChainConfig(billing) {
49
64
  function buildSubgraphOverrides(input) {
50
65
  const overrides = {
51
66
  relayUrl: input.relayUrl,
52
- mnemonic: input.mnemonic,
53
67
  authKeyHex: input.authKeyHex,
54
68
  walletAddress: input.walletAddress,
55
69
  };
70
+ // Exactly one signing source is threaded through — never both, and never
71
+ // neither (store.ts's resolveOwnerAccount throws an actionable error if
72
+ // neither ends up present on the final merged config).
73
+ if (input.ownerPrivateKeyHex) {
74
+ overrides.ownerPrivateKeyHex = input.ownerPrivateKeyHex;
75
+ }
76
+ else if (input.mnemonic) {
77
+ overrides.mnemonic = input.mnemonic;
78
+ }
56
79
  // Only thread a finite chainId — never let an undefined clobber the store's
57
80
  // Gnosis (100) default via the spread merge.
58
81
  if (typeof input.chainId === 'number' && Number.isFinite(input.chainId)) {
@@ -63,4 +86,50 @@ function buildSubgraphOverrides(input) {
63
86
  }
64
87
  return overrides;
65
88
  }
89
+ const DEFAULT_BILLING_TIMEOUT_MS = 5000;
90
+ async function fetchChainConfig(opts) {
91
+ const doFetch = opts.fetchImpl ?? fetch;
92
+ try {
93
+ const billingUrl = `${opts.serverUrl.replace(/\/+$/, '')}/v1/billing/status?wallet_address=${encodeURIComponent(opts.smartAccountAddress)}`;
94
+ const resp = await doFetch(billingUrl, {
95
+ method: 'GET',
96
+ headers: {
97
+ ...(opts.headers ?? {}),
98
+ Authorization: `Bearer ${opts.authKeyHex}`,
99
+ },
100
+ signal: AbortSignal.timeout(opts.timeoutMs ?? DEFAULT_BILLING_TIMEOUT_MS),
101
+ });
102
+ if (resp.ok) {
103
+ const billing = (await resp.json());
104
+ const resolved = resolveChainConfig(billing, (raw) => {
105
+ console.error(`TotalReclaw: billing returned malformed data_edge_address (${JSON.stringify(raw)}) — falling back to env/default.`);
106
+ });
107
+ opts.onResolved?.(billing, resolved);
108
+ return { ...resolved, billingResolved: true };
109
+ }
110
+ opts.onBillingUnavailable?.(`billing responded HTTP ${resp.status}`);
111
+ }
112
+ catch (err) {
113
+ const msg = err instanceof Error ? err.message : String(err);
114
+ opts.onBillingUnavailable?.(`billing fetch failed: ${msg}`);
115
+ }
116
+ return { chainId: opts.fallbackChainId, dataEdgeAddress: undefined, billingResolved: false };
117
+ }
118
+ /**
119
+ * Throws an actionable error when bundle-mode state construction has no
120
+ * confirmed DataEdge for this environment (billing failed, no env
121
+ * override). No-op (returns) when either `billingResolved` is true (the
122
+ * billing call succeeded — even if it happened not to carry a
123
+ * `data_edge_address`, that's `resolveChainConfig`'s concern, not this
124
+ * guard's) or an explicit env override is present.
125
+ */
126
+ function assertDataEdgeResolvable(opts) {
127
+ if (opts.billingResolved || opts.envDataEdgeOverride)
128
+ return;
129
+ throw new Error('derived-bundle-v1: cannot resolve environment DataEdge — refusing to guess the production ' +
130
+ `default (${store_js_1.DEFAULT_DATA_EDGE_ADDRESS}). The billing lookup to ` +
131
+ `${opts.serverUrl.replace(/\/+$/, '')}/v1/billing/status failed and no ` +
132
+ 'TOTALRECLAW_DATA_EDGE_ADDRESS override is set. Retry once the relay is reachable, or set ' +
133
+ 'TOTALRECLAW_DATA_EDGE_ADDRESS explicitly for this environment.');
134
+ }
66
135
  //# sourceMappingURL=chain-config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"chain-config.js","sourceRo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MAAM,IAAI,KAAK,CACb,4FAA4F;QAC1F,YAAY,oCAAyB,2BAA2B;QAChE,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,mCAAmC;QACxE,2FAA2F;QAC3F,gEAAgE,CACnE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * TotalReclaw MCP — managed-mode credential resolution (Option E Phase 2 /
3
+ * #581, P2-13).
4
+ *
5
+ * Reads `~/.totalreclaw/credentials.json` (or `TOTALRECLAW_RECOVERY_PHRASE`)
6
+ * and resolves EITHER a BIP-39 mnemonic OR a `derived-bundle-v1` bundle,
7
+ * mirroring the precedence `python/src/totalreclaw/agent/state.py::_try_auto_configure`
8
+ * implements for Hermes:
9
+ *
10
+ * 1. `TOTALRECLAW_RECOVERY_PHRASE` env — retained, deprecated (phrase).
11
+ * 2. `credentials.json` `version: 2` — a `derived-bundle-v1` bundle.
12
+ * 3. `credentials.json` legacy — plaintext `{"mnemonic": "…"}`.
13
+ *
14
+ * Deliberately narrower than the Python precedence chain: MCP has no
15
+ * `TOTALRECLAW_CREDENTIALS_PROVIDER` / external-provider transport
16
+ * (`credential_provider.py`) and no OS-keychain unwrap
17
+ * (`credentials_wrap.py`) — both are tracked as explicit known gaps (see
18
+ * `mcp/README.md`, CLAUDE.md's Known Gaps table) rather than silently
19
+ * unsupported. A `keychain_wrapped: true` v2 file is a LOUD, actionable
20
+ * error here, not a silent skip — the same "never silently downgrade"
21
+ * posture the unknown-`version` branch below takes.
22
+ *
23
+ * This module never reads self-hosted credentials (`ClientState`/
24
+ * `MASTER_PASSWORD` in `index.ts`) — self-hosted mode is a completely
25
+ * separate credential system with no BIP-39 root at all (derived-bundle-v1.md
26
+ * §4.5.1) and callers MUST route around this module entirely when
27
+ * `TOTALRECLAW_SELF_HOSTED=true`. See `index.ts`'s `main()` for the gate.
28
+ */
29
+ import { type DerivedBundleV1 } from './bundle.js';
30
+ export type ResolvedCredential = {
31
+ kind: 'mnemonic';
32
+ mnemonic: string;
33
+ } | {
34
+ kind: 'bundle';
35
+ bundle: DerivedBundleV1;
36
+ };
37
+ export interface ResolveManagedCredentialOptions {
38
+ /** Override the credentials.json path — for tests. */
39
+ credentialsPath?: string;
40
+ /** Override the env — for tests. */
41
+ env?: NodeJS.ProcessEnv;
42
+ }
43
+ /**
44
+ * Resolve the managed-mode credential per the precedence above.
45
+ *
46
+ * Returns `undefined` when nothing is configured (equivalent to today's
47
+ * `resolveMnemonic()` returning `undefined` — falls through to
48
+ * `unconfigured` mode).
49
+ *
50
+ * Throws — never returns — on a credentials.json that is present but
51
+ * malformed in a way that must not be silently downgraded:
52
+ * - `version` present and not `2` (derived-bundle-v1.md §4.7 / the
53
+ * client-consistency contract: unknown version is a loud error).
54
+ * - `version === 2` but `keychain_wrapped: true` (MCP has no keychain
55
+ * unwrap — see the module doc).
56
+ * - `version === 2` and the bundle fails `parseBundleV1`'s §4.7
57
+ * validation (malformed hex, unknown `signing.kind`, address/key
58
+ * mismatch, …).
59
+ *
60
+ * A missing file, an unreadable file, or a file that fails to parse as JSON
61
+ * at all are treated as "nothing configured" (`undefined`) — matching the
62
+ * pre-existing `resolveMnemonic()` behaviour exactly, since a bare ENOENT or
63
+ * a syntax error is not evidence of tampering the way a well-formed-but-
64
+ * wrong `version` is.
65
+ */
66
+ export declare function resolveManagedCredential(opts?: ResolveManagedCredentialOptions): ResolvedCredential | undefined;
67
+ /**
68
+ * Diagnostic-only check: does the credentials file at `credentialsPath`
69
+ * look like a `derived-bundle-v1` `version: 2` file? Plain `JSON.parse`,
70
+ * no WASM, no `parseBundleV1` — the only caller
71
+ * (`index.ts`'s `TOTALRECLAW_SELF_HOSTED` branch in `main()`) must never
72
+ * touch bundle parsing/validation at all; self-hosted mode is a wholly
73
+ * separate credential system (derived-bundle-v1.md §4.5.1) and this
74
+ * function exists purely to produce a more accurate diagnostic message —
75
+ * "is the `version` field present and `2`" — when self-hosted mode finds
76
+ * no usable mnemonic and would otherwise tell the operator to "set
77
+ * TOTALRECLAW_RECOVERY_PHRASE", which is actively wrong when a
78
+ * valid-but-wrong-mode bundle credential is already present.
79
+ *
80
+ * Never throws; a missing/corrupt/non-bundle file is simply `false`.
81
+ */
82
+ export declare function isV2BundleCredentialsFile(credentialsPath: string): boolean;
83
+ //# sourceMappingURL=credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../src/subgraph/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAOH,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAGlE,MAAM,MAAM,kBAAkB,GAC1B;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,CAAC;AAEhD,MAAM,WAAW,+BAA+B;IAC9C,sDAAsD;IACtD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oCAAoC;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CACzB;AASD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,GAAE,+BAAoC,GACzC,kBAAkB,GAAG,SAAS,CAwFhC;AAQD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAQ1E"}
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+ /**
3
+ * TotalReclaw MCP — managed-mode credential resolution (Option E Phase 2 /
4
+ * #581, P2-13).
5
+ *
6
+ * Reads `~/.totalreclaw/credentials.json` (or `TOTALRECLAW_RECOVERY_PHRASE`)
7
+ * and resolves EITHER a BIP-39 mnemonic OR a `derived-bundle-v1` bundle,
8
+ * mirroring the precedence `python/src/totalreclaw/agent/state.py::_try_auto_configure`
9
+ * implements for Hermes:
10
+ *
11
+ * 1. `TOTALRECLAW_RECOVERY_PHRASE` env — retained, deprecated (phrase).
12
+ * 2. `credentials.json` `version: 2` — a `derived-bundle-v1` bundle.
13
+ * 3. `credentials.json` legacy — plaintext `{"mnemonic": "…"}`.
14
+ *
15
+ * Deliberately narrower than the Python precedence chain: MCP has no
16
+ * `TOTALRECLAW_CREDENTIALS_PROVIDER` / external-provider transport
17
+ * (`credential_provider.py`) and no OS-keychain unwrap
18
+ * (`credentials_wrap.py`) — both are tracked as explicit known gaps (see
19
+ * `mcp/README.md`, CLAUDE.md's Known Gaps table) rather than silently
20
+ * unsupported. A `keychain_wrapped: true` v2 file is a LOUD, actionable
21
+ * error here, not a silent skip — the same "never silently downgrade"
22
+ * posture the unknown-`version` branch below takes.
23
+ *
24
+ * This module never reads self-hosted credentials (`ClientState`/
25
+ * `MASTER_PASSWORD` in `index.ts`) — self-hosted mode is a completely
26
+ * separate credential system with no BIP-39 root at all (derived-bundle-v1.md
27
+ * §4.5.1) and callers MUST route around this module entirely when
28
+ * `TOTALRECLAW_SELF_HOSTED=true`. See `index.ts`'s `main()` for the gate.
29
+ */
30
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
31
+ if (k2 === undefined) k2 = k;
32
+ var desc = Object.getOwnPropertyDescriptor(m, k);
33
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
34
+ desc = { enumerable: true, get: function() { return m[k]; } };
35
+ }
36
+ Object.defineProperty(o, k2, desc);
37
+ }) : (function(o, m, k, k2) {
38
+ if (k2 === undefined) k2 = k;
39
+ o[k2] = m[k];
40
+ }));
41
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
42
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
43
+ }) : function(o, v) {
44
+ o["default"] = v;
45
+ });
46
+ var __importStar = (this && this.__importStar) || (function () {
47
+ var ownKeys = function(o) {
48
+ ownKeys = Object.getOwnPropertyNames || function (o) {
49
+ var ar = [];
50
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
51
+ return ar;
52
+ };
53
+ return ownKeys(o);
54
+ };
55
+ return function (mod) {
56
+ if (mod && mod.__esModule) return mod;
57
+ var result = {};
58
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
59
+ __setModuleDefault(result, mod);
60
+ return result;
61
+ };
62
+ })();
63
+ Object.defineProperty(exports, "__esModule", { value: true });
64
+ exports.resolveManagedCredential = resolveManagedCredential;
65
+ exports.isV2BundleCredentialsFile = isV2BundleCredentialsFile;
66
+ const fs = __importStar(require("node:fs"));
67
+ const bip39_1 = require("@scure/bip39");
68
+ const english_js_1 = require("@scure/bip39/wordlists/english.js");
69
+ const bundle_js_1 = require("./bundle.js");
70
+ const setup_js_1 = require("../cli/setup.js");
71
+ function isValidBip39Mnemonic(candidate) {
72
+ const words = candidate.split(/\s+/);
73
+ if (words.length !== 12 && words.length !== 24)
74
+ return false;
75
+ const allWordsValid = words.every((w) => english_js_1.wordlist.includes(w));
76
+ return (0, bip39_1.validateMnemonic)(candidate, english_js_1.wordlist) || allWordsValid;
77
+ }
78
+ /**
79
+ * Resolve the managed-mode credential per the precedence above.
80
+ *
81
+ * Returns `undefined` when nothing is configured (equivalent to today's
82
+ * `resolveMnemonic()` returning `undefined` — falls through to
83
+ * `unconfigured` mode).
84
+ *
85
+ * Throws — never returns — on a credentials.json that is present but
86
+ * malformed in a way that must not be silently downgraded:
87
+ * - `version` present and not `2` (derived-bundle-v1.md §4.7 / the
88
+ * client-consistency contract: unknown version is a loud error).
89
+ * - `version === 2` but `keychain_wrapped: true` (MCP has no keychain
90
+ * unwrap — see the module doc).
91
+ * - `version === 2` and the bundle fails `parseBundleV1`'s §4.7
92
+ * validation (malformed hex, unknown `signing.kind`, address/key
93
+ * mismatch, …).
94
+ *
95
+ * A missing file, an unreadable file, or a file that fails to parse as JSON
96
+ * at all are treated as "nothing configured" (`undefined`) — matching the
97
+ * pre-existing `resolveMnemonic()` behaviour exactly, since a bare ENOENT or
98
+ * a syntax error is not evidence of tampering the way a well-formed-but-
99
+ * wrong `version` is.
100
+ */
101
+ function resolveManagedCredential(opts = {}) {
102
+ const env = opts.env ?? process.env;
103
+ // 1. TOTALRECLAW_RECOVERY_PHRASE env — retained, deprecated.
104
+ const envPhrase = env.TOTALRECLAW_RECOVERY_PHRASE;
105
+ if (envPhrase && envPhrase.trim().length > 0) {
106
+ // #618 adversarial-review NIT (mirrors
107
+ // python/src/totalreclaw/agent/state.py's equivalent env-branch
108
+ // logging): the env phrase wins the precedence race unconditionally,
109
+ // which silently shadows a v2 bundle if one also happens to exist at
110
+ // the same path — a state an operator mid-migration (env var not yet
111
+ // unset after provisioning a bundle) could easily land in without
112
+ // noticing. Best-effort, plain JSON peek only (no parseBundleV1 — this
113
+ // is a diagnostic, not a validation path); never throws.
114
+ try {
115
+ const credentialsPath = opts.credentialsPath ?? setup_js_1.CREDENTIALS_PATH;
116
+ const raw = fs.readFileSync(credentialsPath, 'utf-8');
117
+ const parsed = JSON.parse(raw);
118
+ if (parsed.version === 2) {
119
+ console.error('TotalReclaw: TOTALRECLAW_RECOVERY_PHRASE is set and takes precedence over the ' +
120
+ `derived-bundle-v1 bundle at ${credentialsPath} (version: 2), which is being ` +
121
+ 'shadowed. Unset the env var to use the bundle, or remove the bundle file if the ' +
122
+ 'env-var phrase is the intended credential.');
123
+ }
124
+ }
125
+ catch {
126
+ // No file, unreadable, or not JSON — nothing to shadow, stay silent.
127
+ }
128
+ return { kind: 'mnemonic', mnemonic: envPhrase.trim() };
129
+ }
130
+ // 2/3. credentials.json
131
+ const credentialsPath = opts.credentialsPath ?? setup_js_1.CREDENTIALS_PATH;
132
+ let raw;
133
+ try {
134
+ raw = fs.readFileSync(credentialsPath, 'utf-8');
135
+ }
136
+ catch {
137
+ return undefined; // no file — unconfigured, not an error.
138
+ }
139
+ let parsed;
140
+ try {
141
+ parsed = JSON.parse(raw);
142
+ }
143
+ catch {
144
+ return undefined; // unparsable — treated as unconfigured, matches legacy behaviour.
145
+ }
146
+ if (typeof parsed !== 'object' || parsed === null) {
147
+ return undefined;
148
+ }
149
+ const obj = parsed;
150
+ const version = obj.version;
151
+ if (version === 2) {
152
+ if (obj.keychain_wrapped === true) {
153
+ throw new Error('credentials.json has version=2 with keychain_wrapped=true, but the MCP server ' +
154
+ 'does not implement OS-keychain unwrapping (that is Python/Hermes-only — see ' +
155
+ 'derived-bundle-v1.md §4.3 and mcp/README.md\'s Known Gaps). Provision a ' +
156
+ 'plaintext derived-bundle-v1 bundle (the "headless / no keychain" storage form) ' +
157
+ 'for MCP hosts instead.');
158
+ }
159
+ // parseBundleV1 runs every derived-bundle-v1.md §4.7 invariant and
160
+ // throws a loud, actionable Error on any violation — never a silent
161
+ // downgrade to legacy mnemonic handling.
162
+ const bundle = (0, bundle_js_1.parseBundleV1)(JSON.stringify(obj));
163
+ return { kind: 'bundle', bundle };
164
+ }
165
+ if (version !== undefined) {
166
+ throw new Error(`credentials.json has an unrecognised version=${JSON.stringify(version)}. Expected 2 ` +
167
+ '(a derived-bundle-v1 bundle) or no version key at all (legacy plaintext mnemonic). ' +
168
+ 'Refusing to guess — an unknown version is never silently treated as legacy.');
169
+ }
170
+ // 4. Legacy: plaintext {"mnemonic": "…"}.
171
+ const mnemonicField = obj.mnemonic;
172
+ if (typeof mnemonicField === 'string' && mnemonicField.trim().length > 0) {
173
+ const trimmed = mnemonicField.trim();
174
+ if (isValidBip39Mnemonic(trimmed)) {
175
+ return { kind: 'mnemonic', mnemonic: trimmed };
176
+ }
177
+ }
178
+ return undefined;
179
+ }
180
+ // ---------------------------------------------------------------------------
181
+ // Self-hosted diagnostic (#618 adversarial-review item 2). Lives here
182
+ // (rather than inline in `index.ts`) so it has direct test coverage —
183
+ // `index.ts` cannot be unit-tested (importing it executes `main()`).
184
+ // ---------------------------------------------------------------------------
185
+ /**
186
+ * Diagnostic-only check: does the credentials file at `credentialsPath`
187
+ * look like a `derived-bundle-v1` `version: 2` file? Plain `JSON.parse`,
188
+ * no WASM, no `parseBundleV1` — the only caller
189
+ * (`index.ts`'s `TOTALRECLAW_SELF_HOSTED` branch in `main()`) must never
190
+ * touch bundle parsing/validation at all; self-hosted mode is a wholly
191
+ * separate credential system (derived-bundle-v1.md §4.5.1) and this
192
+ * function exists purely to produce a more accurate diagnostic message —
193
+ * "is the `version` field present and `2`" — when self-hosted mode finds
194
+ * no usable mnemonic and would otherwise tell the operator to "set
195
+ * TOTALRECLAW_RECOVERY_PHRASE", which is actively wrong when a
196
+ * valid-but-wrong-mode bundle credential is already present.
197
+ *
198
+ * Never throws; a missing/corrupt/non-bundle file is simply `false`.
199
+ */
200
+ function isV2BundleCredentialsFile(credentialsPath) {
201
+ try {
202
+ const raw = fs.readFileSync(credentialsPath, 'utf-8');
203
+ const parsed = JSON.parse(raw);
204
+ return parsed.version === 2;
205
+ }
206
+ catch {
207
+ return false;
208
+ }
209
+ }
210
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/subgraph/credentials.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDH,4DA0FC;AAuBD,8DAQC;AA1KD,4CAA8B;AAE9B,wCAAgD;AAChD,kEAA6D;AAE7D,2CAAkE;AAClE,8CAAmD;AAanD,SAAS,oBAAoB,CAAC,SAAiB;IAC7C,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,KAAK,CAAC,MAAM,KAAK,EAAE,IAAI,KAAK,CAAC,MAAM,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC;IAC7D,MAAM,aAAa,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAS,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,IAAI,OAAO,aAAa,KAAK,QAAQ,IAAI,aAAa,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzE,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,EAAE,CAAC;QACrC,IAAI,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC;YAClC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;QACjD,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,8EAA8E;AAC9E,sEAAsE;AACtE,sEAAsE;AACtE,qEAAqE;AACrE,8EAA8E;AAE9E;;;;;;;;;;;;;;GAcG;AACH,SAAgB,yBAAyB,CAAC,eAAuB;IAC/D,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QACtD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAA0B,CAAC;QACxD,OAAO,MAAM,CAAC,OAAO,KAAK,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * TotalReclaw MCP — outer protobuf encoder for on-chain fact payloads.
3
+ *
4
+ * Dependency-free on purpose: the cross-language parity suite
5
+ * (`tests/parity/outer-protobuf-parity.test.ts`) loads this file directly,
6
+ * without the MCP runtime dependencies installed. `subgraph/store.ts`
7
+ * re-exports everything here, so imports from `./subgraph/store.js` are
8
+ * unchanged.
9
+ *
10
+ * Wire layout is byte-identical to the canonical encoders for the same input:
11
+ * - Rust: rust/totalreclaw-core/src/protobuf.rs encode_fact_protobuf
12
+ * - Python: python/src/totalreclaw/protobuf.py encode_fact_protobuf
13
+ *
14
+ * Field numbers (server/proto/totalreclaw.proto):
15
+ * 1 id, 2 timestamp, 3 owner, 4 encrypted_blob (bytes),
16
+ * 5 blind_indices (repeated), 6 decay_score (double), 7 is_active,
17
+ * 8 version, 9 source (NOT WRITTEN), 10 content_fp,
18
+ * 11 agent_id (NOT WRITTEN), 12 sequence_id (assigned by the subgraph),
19
+ * 13 encrypted_embedding.
20
+ *
21
+ * Fields 9 and 11 left the wire in v3 (provenance lives inside the encrypted
22
+ * blob, field 4). MCP kept writing them as plaintext calldata until PRD-04
23
+ * F8 / DEP-6. Pinned by tests/parity/fixtures/outer-protobuf-v1.json.
24
+ */
25
+ /**
26
+ * Memory Taxonomy v1 outer protobuf wrapper version.
27
+ *
28
+ * The v1 contract (shipped 2026-04-18) mandates that all clients write
29
+ * `version = 4` on the outer protobuf so the subgraph + cross-client
30
+ * readers can recognize the inner blob as a v1 JSON `MemoryClaim`.
31
+ *
32
+ * Canonical source: `rust/totalreclaw-core/src/protobuf.rs`
33
+ * (`PROTOBUF_VERSION_V4 = 4`). The WASM/PyO3 bindings do not re-export
34
+ * this constant to TS; switch to an import from `@totalreclaw/core` if
35
+ * they ever do.
36
+ */
37
+ export declare const PROTOBUF_VERSION_V4 = 4;
38
+ export interface FactPayload {
39
+ id: string;
40
+ timestamp: string;
41
+ owner: string;
42
+ encryptedBlob: string;
43
+ blindIndices: string[];
44
+ decayScore: number;
45
+ /**
46
+ * Write-path label (e.g. `mcp_remember`). NOT encoded on-chain: outer
47
+ * field 9 left the wire in v3 (PRD-04 F8 / DEP-6). Kept on the type so
48
+ * call sites compile unchanged — the Rust `FactPayload.source` and Python
49
+ * `FactPayload.source` fields are likewise accepted and ignored.
50
+ */
51
+ source: string;
52
+ contentFp: string;
53
+ /**
54
+ * Writer id (e.g. `mcp-server`). NOT encoded on-chain: outer field 11
55
+ * left the wire in v3 (PRD-04 F8 / DEP-6). Kept for call-site
56
+ * compatibility, mirroring Rust/Python `agent_id`.
57
+ */
58
+ agentId: string;
59
+ encryptedEmbedding?: string;
60
+ }
61
+ /**
62
+ * Encode a fact payload as a minimal Protobuf wire format.
63
+ *
64
+ * Field 8 (`version`) is always `PROTOBUF_VERSION_V4` (4) — every MCP write
65
+ * carries a v1 inner blob. Fields 9 (`source`) and 11 (`agent_id`) are never
66
+ * written, whatever the caller puts in `fact.source` / `fact.agentId`.
67
+ */
68
+ export declare function encodeFactProtobuf(fact: FactPayload): Buffer;
69
+ /** Encode an integer as a Protobuf varint */
70
+ export declare function encodeVarint(value: number): Buffer;
71
+ //# sourceMappingURL=protobuf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protobuf.d.ts","sourceRoot":"","sources":["../../src/subgraph/protobuf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CA2D5D;AAED,6CAA6C;AAC7C,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CASlD"}