@provian/mcp 0.0.0-stage → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +264 -2
  4. package/bin/provian-mcp.mjs +18 -0
  5. package/dist/agent-wallet-registration.d.ts +34 -0
  6. package/dist/agent-wallet-registration.d.ts.map +1 -0
  7. package/dist/agent-wallet-registration.js +440 -0
  8. package/dist/agent-wallet-registration.js.map +1 -0
  9. package/dist/core/challenge.d.ts +187 -0
  10. package/dist/core/challenge.d.ts.map +1 -0
  11. package/dist/core/challenge.js +536 -0
  12. package/dist/core/challenge.js.map +1 -0
  13. package/dist/core/crypto.d.ts +44 -0
  14. package/dist/core/crypto.d.ts.map +1 -0
  15. package/dist/core/crypto.js +124 -0
  16. package/dist/core/crypto.js.map +1 -0
  17. package/dist/core/disclosure-request.d.ts +169 -0
  18. package/dist/core/disclosure-request.d.ts.map +1 -0
  19. package/dist/core/disclosure-request.js +400 -0
  20. package/dist/core/disclosure-request.js.map +1 -0
  21. package/dist/core/genesis-offer.d.ts +25 -0
  22. package/dist/core/genesis-offer.d.ts.map +1 -0
  23. package/dist/core/genesis-offer.js +34 -0
  24. package/dist/core/genesis-offer.js.map +1 -0
  25. package/dist/core/harness-tool-vocabulary.d.ts +55 -0
  26. package/dist/core/harness-tool-vocabulary.d.ts.map +1 -0
  27. package/dist/core/harness-tool-vocabulary.js +116 -0
  28. package/dist/core/harness-tool-vocabulary.js.map +1 -0
  29. package/dist/core/keccak256.d.ts +15 -0
  30. package/dist/core/keccak256.d.ts.map +1 -0
  31. package/dist/core/keccak256.js +111 -0
  32. package/dist/core/keccak256.js.map +1 -0
  33. package/dist/core/key-custody.d.ts +33 -0
  34. package/dist/core/key-custody.d.ts.map +1 -0
  35. package/dist/core/key-custody.js +59 -0
  36. package/dist/core/key-custody.js.map +1 -0
  37. package/dist/core/meter-hash.d.ts +2 -0
  38. package/dist/core/meter-hash.d.ts.map +1 -0
  39. package/dist/core/meter-hash.js +8 -0
  40. package/dist/core/meter-hash.js.map +1 -0
  41. package/dist/core/meter-wire.d.ts +193 -0
  42. package/dist/core/meter-wire.d.ts.map +1 -0
  43. package/dist/core/meter-wire.js +418 -0
  44. package/dist/core/meter-wire.js.map +1 -0
  45. package/dist/core/output-signature.d.ts +162 -0
  46. package/dist/core/output-signature.d.ts.map +1 -0
  47. package/dist/core/output-signature.js +367 -0
  48. package/dist/core/output-signature.js.map +1 -0
  49. package/dist/core/presentation.d.ts +141 -0
  50. package/dist/core/presentation.d.ts.map +1 -0
  51. package/dist/core/presentation.js +160 -0
  52. package/dist/core/presentation.js.map +1 -0
  53. package/dist/core/recovery-seal.d.ts +36 -0
  54. package/dist/core/recovery-seal.d.ts.map +1 -0
  55. package/dist/core/recovery-seal.js +122 -0
  56. package/dist/core/recovery-seal.js.map +1 -0
  57. package/dist/core/server.d.ts +38 -0
  58. package/dist/core/server.d.ts.map +1 -0
  59. package/dist/core/server.js +106 -0
  60. package/dist/core/server.js.map +1 -0
  61. package/dist/core/thread-reader.d.ts +8 -0
  62. package/dist/core/thread-reader.d.ts.map +1 -0
  63. package/dist/core/thread-reader.js +47 -0
  64. package/dist/core/thread-reader.js.map +1 -0
  65. package/dist/core/tool-set.d.ts +28 -0
  66. package/dist/core/tool-set.d.ts.map +1 -0
  67. package/dist/core/tool-set.js +71 -0
  68. package/dist/core/tool-set.js.map +1 -0
  69. package/dist/core/tools.d.ts +151 -0
  70. package/dist/core/tools.d.ts.map +1 -0
  71. package/dist/core/tools.js +3621 -0
  72. package/dist/core/tools.js.map +1 -0
  73. package/dist/core/types.d.ts +189 -0
  74. package/dist/core/types.d.ts.map +1 -0
  75. package/dist/core/types.js +17 -0
  76. package/dist/core/types.js.map +1 -0
  77. package/dist/credentials.d.ts +46 -0
  78. package/dist/credentials.d.ts.map +1 -0
  79. package/dist/credentials.js +213 -0
  80. package/dist/credentials.js.map +1 -0
  81. package/dist/device-credentials.d.ts +57 -0
  82. package/dist/device-credentials.d.ts.map +1 -0
  83. package/dist/device-credentials.js +403 -0
  84. package/dist/device-credentials.js.map +1 -0
  85. package/dist/eip191.d.ts +18 -0
  86. package/dist/eip191.d.ts.map +1 -0
  87. package/dist/eip191.js +41 -0
  88. package/dist/eip191.js.map +1 -0
  89. package/dist/index.d.ts +21 -0
  90. package/dist/index.d.ts.map +1 -0
  91. package/dist/index.js +48 -0
  92. package/dist/index.js.map +1 -0
  93. package/dist/runtime-env.d.ts +131 -0
  94. package/dist/runtime-env.d.ts.map +1 -0
  95. package/dist/runtime-env.js +328 -0
  96. package/dist/runtime-env.js.map +1 -0
  97. package/dist/stdio.d.ts +6 -0
  98. package/dist/stdio.d.ts.map +1 -0
  99. package/dist/stdio.js +136 -0
  100. package/dist/stdio.js.map +1 -0
  101. package/package.json +60 -4
@@ -0,0 +1,131 @@
1
+ /**
2
+ * runtime-env — carry the box's egress environment (forward proxy, loopback
3
+ * bypass, extra CA) into EVERY Provian Node process,
4
+ * however that process was started (, requirement C).
5
+ *
6
+ * THE DEFECT THIS CLOSES (§3). On a cloud-VM agent box whose only egress
7
+ * is a forward proxy (a hosted agent's runtime cell; Grok Bot under Network
8
+ * Controls), Node's global `fetch` ignores `HTTPS_PROXY` and fails `EAI_AGAIN`,
9
+ * and Node never reads the system CA store, so a TLS-inspecting proxy's CA is
10
+ * untrusted. Node honours both only when told at PROCESS START:
11
+ * `NODE_USE_ENV_PROXY=1` (Node ≥ 22.21 / ≥ 24.5) routes `fetch` AND
12
+ * `http(s).request` through `HTTP(S)_PROXY` minus `NO_PROXY`, and
13
+ * `NODE_EXTRA_CA_CERTS` adds trust anchors. Neither can be switched on from
14
+ * inside a running process. And the variables the install shell had never
15
+ * reached a daemon started by systemd, launchd or cron.
16
+ *
17
+ * THE MECHANISM (one, uniform for every entry). The installer writes the box's
18
+ * egress variables to `~/.provian/runtime.env` (0600, allowlisted keys only).
19
+ * Every Node entry point — the bundle dispatcher (install, `observe`,
20
+ * `report-pe` from the git hook), the npm observer, the npm hook — calls
21
+ * `applyRuntimeEnvAtEntry()` FIRST. It merges the file under the live
22
+ * environment (the live environment always wins), guarantees loopback is in
23
+ * `NO_PROXY` whenever a proxy is in effect (the OTLP receiver
24
+ * and model shim are loopback and must never be proxied), and, when a
25
+ * start-time-only variable differs from what this process started with,
26
+ * re-executes itself once with the merged environment (`process.execve` when
27
+ * the runtime has it, else a supervised child). So a service unit, a cron line
28
+ * or a hook needs to carry nothing — the file is the one source.
29
+ *
30
+ * INVARIANTS.
31
+ * - Destination checks are unchanged: the SDK egress guard still judges the
32
+ * DESTINATION host, never the proxy; bundle hashes and signed-channel
33
+ * signatures are verified exactly as before (TLS to the relay still verifies,
34
+ * against the system anchors plus any extra CA).
35
+ * - Loopback is never proxied (`127.0.0.1`, `localhost`, ` :1` always in
36
+ * `NO_PROXY` when a proxy is set).
37
+ * - Only allowlisted keys are ever read from or written to the file, so it can
38
+ * never inject `NODE_OPTIONS`, a preload, or anything else executable.
39
+ * - One re-exec at most (guard variable), never a loop.
40
+ */
41
+ import { spawnSync } from 'child_process';
42
+ /** Where the installer records the box's egress environment. */
43
+ export declare function runtimeEnvPath(home?: string): string;
44
+ /** Proxy variables Node's env-proxy support reads (both cases, as curl does). */
45
+ export declare const PROXY_KEYS: readonly ["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"];
46
+ export declare const NO_PROXY_KEYS: readonly ["NO_PROXY", "no_proxy"];
47
+ /**
48
+ * The ONLY keys runtime.env may carry. Anything else in the file is ignored on
49
+ * read and never written. (retired the local witness endpoint; its
50
+ * PROVIAN_WITNESS_* opt-ins are no longer carried — a line an earlier installer
51
+ * wrote is ignored, and an updated daemon prunes it.)
52
+ */
53
+ export declare const RUNTIME_ENV_KEYS: readonly string[];
54
+ /** Hosts that are always loopback and must never be sent to a proxy. */
55
+ export declare const LOOPBACK_NO_PROXY: readonly ["127.0.0.1", "localhost", "::1"];
56
+ /** Guard so a re-executed process never re-executes again. */
57
+ export declare const RUNTIME_ENV_REEXEC_GUARD = "PROVIAN_RUNTIME_ENV_REEXEC";
58
+ /**
59
+ * System CA bundles, most common first. Used only on Linux, where a
60
+ * TLS-inspecting proxy's CA is installed into the OS store (curl trusts it) but
61
+ * Node does not read that store.
62
+ */
63
+ export declare const LINUX_SYSTEM_CA_BUNDLES: readonly ["/etc/ssl/certs/ca-certificates.crt", "/etc/pki/tls/certs/ca-bundle.crt", "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem", "/etc/ssl/ca-bundle.pem", "/etc/ssl/cert.pem"];
64
+ /** Does this Node runtime honour `NODE_USE_ENV_PROXY` for fetch and http(s)? */
65
+ export declare function nodeSupportsEnvProxy(nodeVersion?: string): boolean;
66
+ export declare function hasProxy(env: NodeJS.ProcessEnv): boolean;
67
+ /** Merge the loopback hosts into a NO_PROXY list, preserving the caller's entries and order. */
68
+ export declare function withLoopbackNoProxy(value: string | undefined): string;
69
+ export interface RuntimeEnvProbe {
70
+ platform?: NodeJS.Platform;
71
+ exists?: (p: string) => boolean;
72
+ }
73
+ /** The extra-CA file this box needs Node to trust, or null. */
74
+ export declare function resolveExtraCaFile(env: NodeJS.ProcessEnv, probe?: RuntimeEnvProbe): string | null;
75
+ /**
76
+ * The runtime environment the INSTALLER captures from its own shell. Pure over
77
+ * `env` + `probe`. Empty when the box has no proxy and no extra CA.
78
+ */
79
+ export declare function computeRuntimeEnv(env: NodeJS.ProcessEnv, probe?: RuntimeEnvProbe): Record<string, string>;
80
+ /** Serialize (allowlisted keys only; values with a newline are dropped, never escaped). */
81
+ export declare function serializeRuntimeEnv(values: Record<string, string>): string;
82
+ /** Parse the file (allowlisted keys only; comments and unknown keys ignored). */
83
+ export declare function parseRuntimeEnv(text: string): Record<string, string>;
84
+ export declare function readRuntimeEnvFile(file?: string): Record<string, string>;
85
+ /**
86
+ * Persist what the installer saw. Replaces the file (a re-install from a shell
87
+ * with a different proxy must not keep the stale one); removes it when there is
88
+ * nothing to carry. Returns the keys written.
89
+ */
90
+ export declare function persistRuntimeEnv(env: NodeJS.ProcessEnv, opts?: {
91
+ file?: string;
92
+ probe?: RuntimeEnvProbe;
93
+ }): string[];
94
+ export interface RuntimeEnvDecision {
95
+ /** The environment this process should run with. */
96
+ env: NodeJS.ProcessEnv;
97
+ /** True when a start-time-only variable differs from what the process started with. */
98
+ reexec: boolean;
99
+ /** Plain notes for the log (never a secret value). */
100
+ notes: string[];
101
+ }
102
+ /**
103
+ * Decide the effective environment for THIS process. Pure: `current` is the
104
+ * environment the process started with, `fromFile` what the installer recorded.
105
+ */
106
+ export declare function decideRuntimeEnv(current: NodeJS.ProcessEnv, fromFile: Record<string, string>, nodeVersion?: string): RuntimeEnvDecision;
107
+ export interface ApplyRuntimeEnvDeps {
108
+ env?: NodeJS.ProcessEnv;
109
+ file?: string;
110
+ /**
111
+ * Merge these in place of the file. `onboard` passes what it read from its own shell, which is
112
+ * authoritative for an install, so it can reach the relay before it has written anything.
113
+ */
114
+ recorded?: Record<string, string>;
115
+ nodeVersion?: string;
116
+ execPath?: string;
117
+ execArgv?: string[];
118
+ argv?: string[];
119
+ log?: (line: string) => void;
120
+ /** `process.execve` (Node ≥ 22.15) — replaces the process image, same pid. */
121
+ execve?: ((file: string, args: string[], env: NodeJS.ProcessEnv) => never) | null;
122
+ spawnSync?: typeof spawnSync;
123
+ exit?: (code: number) => never;
124
+ }
125
+ /**
126
+ * Call FIRST in every Node entry point. Returns normally when this process
127
+ * already runs with the right environment (after updating `process.env` with the
128
+ * non-start-time values). Otherwise re-executes and never returns.
129
+ */
130
+ export declare function applyRuntimeEnvAtEntry(deps?: ApplyRuntimeEnvDeps): void;
131
+ //# sourceMappingURL=runtime-env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-env.d.ts","sourceRoot":"","sources":["../src/runtime-env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,KAAK,KAAK,CAAC,GAAG,IAAI,CAAC;IAClF,SAAS,CAAC,EAAE,OAAO,SAAS,CAAC;IAC7B,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,KAAK,CAAC;CAChC;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,GAAE,mBAAwB,GAAG,IAAI,CA+B3E"}
@@ -0,0 +1,328 @@
1
+ "use strict";
2
+ /**
3
+ * runtime-env — carry the box's egress environment (forward proxy, loopback
4
+ * bypass, extra CA) into EVERY Provian Node process,
5
+ * however that process was started (, requirement C).
6
+ *
7
+ * THE DEFECT THIS CLOSES (§3). On a cloud-VM agent box whose only egress
8
+ * is a forward proxy (a hosted agent's runtime cell; Grok Bot under Network
9
+ * Controls), Node's global `fetch` ignores `HTTPS_PROXY` and fails `EAI_AGAIN`,
10
+ * and Node never reads the system CA store, so a TLS-inspecting proxy's CA is
11
+ * untrusted. Node honours both only when told at PROCESS START:
12
+ * `NODE_USE_ENV_PROXY=1` (Node ≥ 22.21 / ≥ 24.5) routes `fetch` AND
13
+ * `http(s).request` through `HTTP(S)_PROXY` minus `NO_PROXY`, and
14
+ * `NODE_EXTRA_CA_CERTS` adds trust anchors. Neither can be switched on from
15
+ * inside a running process. And the variables the install shell had never
16
+ * reached a daemon started by systemd, launchd or cron.
17
+ *
18
+ * THE MECHANISM (one, uniform for every entry). The installer writes the box's
19
+ * egress variables to `~/.provian/runtime.env` (0600, allowlisted keys only).
20
+ * Every Node entry point — the bundle dispatcher (install, `observe`,
21
+ * `report-pe` from the git hook), the npm observer, the npm hook — calls
22
+ * `applyRuntimeEnvAtEntry()` FIRST. It merges the file under the live
23
+ * environment (the live environment always wins), guarantees loopback is in
24
+ * `NO_PROXY` whenever a proxy is in effect (the OTLP receiver
25
+ * and model shim are loopback and must never be proxied), and, when a
26
+ * start-time-only variable differs from what this process started with,
27
+ * re-executes itself once with the merged environment (`process.execve` when
28
+ * the runtime has it, else a supervised child). So a service unit, a cron line
29
+ * or a hook needs to carry nothing — the file is the one source.
30
+ *
31
+ * INVARIANTS.
32
+ * - Destination checks are unchanged: the SDK egress guard still judges the
33
+ * DESTINATION host, never the proxy; bundle hashes and signed-channel
34
+ * signatures are verified exactly as before (TLS to the relay still verifies,
35
+ * against the system anchors plus any extra CA).
36
+ * - Loopback is never proxied (`127.0.0.1`, `localhost`, ` :1` always in
37
+ * `NO_PROXY` when a proxy is set).
38
+ * - Only allowlisted keys are ever read from or written to the file, so it can
39
+ * never inject `NODE_OPTIONS`, a preload, or anything else executable.
40
+ * - One re-exec at most (guard variable), never a loop.
41
+ */
42
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
43
+ if (k2 === undefined) k2 = k;
44
+ var desc = Object.getOwnPropertyDescriptor(m, k);
45
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
46
+ desc = { enumerable: true, get: function() { return m[k]; } };
47
+ }
48
+ Object.defineProperty(o, k2, desc);
49
+ }) : (function(o, m, k, k2) {
50
+ if (k2 === undefined) k2 = k;
51
+ o[k2] = m[k];
52
+ }));
53
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
54
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
55
+ }) : function(o, v) {
56
+ o["default"] = v;
57
+ });
58
+ var __importStar = (this && this.__importStar) || (function () {
59
+ var ownKeys = function(o) {
60
+ ownKeys = Object.getOwnPropertyNames || function (o) {
61
+ var ar = [];
62
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
63
+ return ar;
64
+ };
65
+ return ownKeys(o);
66
+ };
67
+ return function (mod) {
68
+ if (mod && mod.__esModule) return mod;
69
+ var result = {};
70
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
71
+ __setModuleDefault(result, mod);
72
+ return result;
73
+ };
74
+ })();
75
+ Object.defineProperty(exports, "__esModule", { value: true });
76
+ exports.LINUX_SYSTEM_CA_BUNDLES = exports.RUNTIME_ENV_REEXEC_GUARD = exports.LOOPBACK_NO_PROXY = exports.RUNTIME_ENV_KEYS = exports.NO_PROXY_KEYS = exports.PROXY_KEYS = void 0;
77
+ exports.runtimeEnvPath = runtimeEnvPath;
78
+ exports.nodeSupportsEnvProxy = nodeSupportsEnvProxy;
79
+ exports.hasProxy = hasProxy;
80
+ exports.withLoopbackNoProxy = withLoopbackNoProxy;
81
+ exports.resolveExtraCaFile = resolveExtraCaFile;
82
+ exports.computeRuntimeEnv = computeRuntimeEnv;
83
+ exports.serializeRuntimeEnv = serializeRuntimeEnv;
84
+ exports.parseRuntimeEnv = parseRuntimeEnv;
85
+ exports.readRuntimeEnvFile = readRuntimeEnvFile;
86
+ exports.persistRuntimeEnv = persistRuntimeEnv;
87
+ exports.decideRuntimeEnv = decideRuntimeEnv;
88
+ exports.applyRuntimeEnvAtEntry = applyRuntimeEnvAtEntry;
89
+ const fs = __importStar(require("fs"));
90
+ const path = __importStar(require("path"));
91
+ const os_1 = require("os");
92
+ const child_process_1 = require("child_process");
93
+ /** Where the installer records the box's egress environment. */
94
+ function runtimeEnvPath(home = (0, os_1.homedir)()) {
95
+ return path.join(home, '.provian', 'runtime.env');
96
+ }
97
+ /** Proxy variables Node's env-proxy support reads (both cases, as curl does). */
98
+ exports.PROXY_KEYS = ['HTTPS_PROXY', 'https_proxy', 'HTTP_PROXY', 'http_proxy'];
99
+ exports.NO_PROXY_KEYS = ['NO_PROXY', 'no_proxy'];
100
+ /**
101
+ * The ONLY keys runtime.env may carry. Anything else in the file is ignored on
102
+ * read and never written. (retired the local witness endpoint; its
103
+ * PROVIAN_WITNESS_* opt-ins are no longer carried — a line an earlier installer
104
+ * wrote is ignored, and an updated daemon prunes it.)
105
+ */
106
+ exports.RUNTIME_ENV_KEYS = [
107
+ ...exports.PROXY_KEYS,
108
+ ...exports.NO_PROXY_KEYS,
109
+ 'NODE_USE_ENV_PROXY',
110
+ 'NODE_EXTRA_CA_CERTS',
111
+ ];
112
+ /** Variables Node reads once at process start — a change requires a re-exec. */
113
+ const START_TIME_KEYS = [
114
+ 'NODE_USE_ENV_PROXY', 'NODE_EXTRA_CA_CERTS', ...exports.PROXY_KEYS, ...exports.NO_PROXY_KEYS,
115
+ ];
116
+ /** Hosts that are always loopback and must never be sent to a proxy. */
117
+ exports.LOOPBACK_NO_PROXY = ['127.0.0.1', 'localhost', '::1'];
118
+ /** Guard so a re-executed process never re-executes again. */
119
+ exports.RUNTIME_ENV_REEXEC_GUARD = 'PROVIAN_RUNTIME_ENV_REEXEC';
120
+ /**
121
+ * System CA bundles, most common first. Used only on Linux, where a
122
+ * TLS-inspecting proxy's CA is installed into the OS store (curl trusts it) but
123
+ * Node does not read that store.
124
+ */
125
+ exports.LINUX_SYSTEM_CA_BUNDLES = [
126
+ '/etc/ssl/certs/ca-certificates.crt', // Debian, Ubuntu, Alpine (ca-certificates)
127
+ '/etc/pki/tls/certs/ca-bundle.crt', // RHEL, Fedora, Amazon Linux
128
+ '/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem', // RHEL 7+ extracted
129
+ '/etc/ssl/ca-bundle.pem', // openSUSE
130
+ '/etc/ssl/cert.pem', // Alpine / generic OpenSSL
131
+ ];
132
+ /** Does this Node runtime honour `NODE_USE_ENV_PROXY` for fetch and http(s)? */
133
+ function nodeSupportsEnvProxy(nodeVersion = process.versions.node) {
134
+ const [major, minor] = nodeVersion.replace(/^v/, '').split('.').map((n) => Number.parseInt(n, 10));
135
+ if (!Number.isFinite(major) || !Number.isFinite(minor))
136
+ return false;
137
+ if (major === 22)
138
+ return minor >= 21;
139
+ if (major === 24)
140
+ return minor >= 5;
141
+ return major >= 25;
142
+ }
143
+ function hasProxy(env) {
144
+ return exports.PROXY_KEYS.some((k) => typeof env[k] === 'string' && env[k].trim().length > 0);
145
+ }
146
+ /** Merge the loopback hosts into a NO_PROXY list, preserving the caller's entries and order. */
147
+ function withLoopbackNoProxy(value) {
148
+ const entries = (value ?? '').split(',').map((s) => s.trim()).filter((s) => s.length > 0);
149
+ const missing = exports.LOOPBACK_NO_PROXY.filter((h) => !entries.includes(h));
150
+ return [...missing, ...entries].join(',');
151
+ }
152
+ /** The extra-CA file this box needs Node to trust, or null. */
153
+ function resolveExtraCaFile(env, probe = {}) {
154
+ const exists = probe.exists ?? ((p) => {
155
+ try {
156
+ return fs.statSync(p).isFile();
157
+ }
158
+ catch {
159
+ return false;
160
+ }
161
+ });
162
+ // An operator's explicit choice, in the order the common tools read them.
163
+ for (const key of ['NODE_EXTRA_CA_CERTS', 'SSL_CERT_FILE', 'CURL_CA_BUNDLE', 'REQUESTS_CA_BUNDLE']) {
164
+ const v = env[key];
165
+ if (typeof v === 'string' && v.length > 0 && exists(v))
166
+ return v;
167
+ }
168
+ // The OS store, on Linux only (macOS/Windows keep corporate anchors in a
169
+ // keychain/cert store, not a PEM file, so there is nothing to point at).
170
+ if ((probe.platform ?? process.platform) === 'linux') {
171
+ for (const candidate of exports.LINUX_SYSTEM_CA_BUNDLES) {
172
+ if (exists(candidate))
173
+ return candidate;
174
+ }
175
+ }
176
+ return null;
177
+ }
178
+ /**
179
+ * The runtime environment the INSTALLER captures from its own shell. Pure over
180
+ * `env` + `probe`. Empty when the box has no proxy and no extra CA.
181
+ */
182
+ function computeRuntimeEnv(env, probe = {}) {
183
+ const out = {};
184
+ if (hasProxy(env)) {
185
+ for (const k of exports.PROXY_KEYS) {
186
+ const v = env[k];
187
+ if (typeof v === 'string' && v.trim().length > 0)
188
+ out[k] = v.trim();
189
+ }
190
+ const noProxy = withLoopbackNoProxy(env.NO_PROXY ?? env.no_proxy);
191
+ out.NO_PROXY = noProxy;
192
+ out.no_proxy = noProxy;
193
+ out.NODE_USE_ENV_PROXY = '1';
194
+ }
195
+ const ca = resolveExtraCaFile(env, probe);
196
+ if (ca)
197
+ out.NODE_EXTRA_CA_CERTS = ca;
198
+ return out;
199
+ }
200
+ /** Serialize (allowlisted keys only; values with a newline are dropped, never escaped). */
201
+ function serializeRuntimeEnv(values) {
202
+ const lines = ['# Written by the Provian installer. Loaded by every Provian process on this machine.'];
203
+ for (const key of exports.RUNTIME_ENV_KEYS) {
204
+ const v = values[key];
205
+ if (typeof v !== 'string' || v.length === 0 || /[\r\n]/.test(v))
206
+ continue;
207
+ lines.push(`${key}=${v}`);
208
+ }
209
+ return `${lines.join('\n')}\n`;
210
+ }
211
+ /** Parse the file (allowlisted keys only; comments and unknown keys ignored). */
212
+ function parseRuntimeEnv(text) {
213
+ const out = {};
214
+ for (const raw of text.split(/\r?\n/)) {
215
+ const line = raw.trim();
216
+ if (!line || line.startsWith('#'))
217
+ continue;
218
+ const eq = line.indexOf('=');
219
+ if (eq <= 0)
220
+ continue;
221
+ const key = line.slice(0, eq).trim();
222
+ if (!exports.RUNTIME_ENV_KEYS.includes(key))
223
+ continue;
224
+ out[key] = line.slice(eq + 1);
225
+ }
226
+ return out;
227
+ }
228
+ function readRuntimeEnvFile(file = runtimeEnvPath()) {
229
+ try {
230
+ return parseRuntimeEnv(fs.readFileSync(file, 'utf8'));
231
+ }
232
+ catch {
233
+ return {};
234
+ }
235
+ }
236
+ /**
237
+ * Persist what the installer saw. Replaces the file (a re-install from a shell
238
+ * with a different proxy must not keep the stale one); removes it when there is
239
+ * nothing to carry. Returns the keys written.
240
+ */
241
+ function persistRuntimeEnv(env, opts = {}) {
242
+ const file = opts.file ?? runtimeEnvPath();
243
+ const values = computeRuntimeEnv(env, opts.probe);
244
+ const keys = Object.keys(values);
245
+ if (keys.length === 0) {
246
+ try {
247
+ fs.unlinkSync(file);
248
+ }
249
+ catch { /* absent is fine */ }
250
+ return [];
251
+ }
252
+ fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
253
+ const tmp = `${file}.${process.pid}.tmp`;
254
+ fs.writeFileSync(tmp, serializeRuntimeEnv(values), { mode: 0o600 });
255
+ fs.renameSync(tmp, file);
256
+ return keys;
257
+ }
258
+ /**
259
+ * Decide the effective environment for THIS process. Pure: `current` is the
260
+ * environment the process started with, `fromFile` what the installer recorded.
261
+ */
262
+ function decideRuntimeEnv(current, fromFile, nodeVersion = process.versions.node) {
263
+ const env = { ...current };
264
+ const notes = [];
265
+ // The live environment wins; the file only fills what is missing.
266
+ for (const [k, v] of Object.entries(fromFile)) {
267
+ if (env[k] === undefined || env[k] === '')
268
+ env[k] = v;
269
+ }
270
+ // A proxy in effect → loopback bypass + Node's env-proxy support, both cases of NO_PROXY.
271
+ if (hasProxy(env)) {
272
+ const merged = withLoopbackNoProxy(env.NO_PROXY ?? env.no_proxy);
273
+ env.NO_PROXY = merged;
274
+ env.no_proxy = merged;
275
+ if (nodeSupportsEnvProxy(nodeVersion)) {
276
+ if (!env.NODE_USE_ENV_PROXY)
277
+ env.NODE_USE_ENV_PROXY = '1';
278
+ }
279
+ else {
280
+ notes.push(`this Node (${nodeVersion}) cannot route through the configured proxy; `
281
+ + 'Node 22.21+ is needed (the hosted install line fetches one)');
282
+ }
283
+ }
284
+ const alreadyReexeced = current[exports.RUNTIME_ENV_REEXEC_GUARD] === '1';
285
+ const changed = START_TIME_KEYS.some((k) => (current[k] ?? '') !== (env[k] ?? ''));
286
+ return { env, reexec: changed && !alreadyReexeced, notes };
287
+ }
288
+ /**
289
+ * Call FIRST in every Node entry point. Returns normally when this process
290
+ * already runs with the right environment (after updating `process.env` with the
291
+ * non-start-time values). Otherwise re-executes and never returns.
292
+ */
293
+ function applyRuntimeEnvAtEntry(deps = {}) {
294
+ const current = deps.env ?? process.env;
295
+ const decision = decideRuntimeEnv(current, deps.recorded ?? readRuntimeEnvFile(deps.file), deps.nodeVersion);
296
+ const log = deps.log ?? ((line) => process.stderr.write(`${line}\n`));
297
+ for (const note of decision.notes)
298
+ log(`[provian] ${note}`);
299
+ if (!decision.reexec) {
300
+ // Non-start-time values are read later from process.env; apply them in place.
301
+ for (const [k, v] of Object.entries(decision.env)) {
302
+ if (v !== undefined && current[k] !== v)
303
+ current[k] = v;
304
+ }
305
+ return;
306
+ }
307
+ const childEnv = { ...decision.env, [exports.RUNTIME_ENV_REEXEC_GUARD]: '1' };
308
+ const execPath = deps.execPath ?? process.execPath;
309
+ const args = [...(deps.execArgv ?? process.execArgv), ...(deps.argv ?? process.argv).slice(1)];
310
+ const execve = deps.execve !== undefined
311
+ ? deps.execve
312
+ : (typeof process.execve === 'function'
313
+ ? (process.execve.bind(process))
314
+ : null);
315
+ if (execve) {
316
+ try {
317
+ execve(execPath, [execPath, ...args], childEnv);
318
+ }
319
+ catch {
320
+ // Fall through to the supervised child below.
321
+ }
322
+ }
323
+ const run = deps.spawnSync ?? child_process_1.spawnSync;
324
+ const res = run(execPath, args, { stdio: 'inherit', env: childEnv });
325
+ const exit = deps.exit ?? ((code) => process.exit(code));
326
+ exit(typeof res.status === 'number' ? res.status : 1);
327
+ }
328
+ //# sourceMappingURL=runtime-env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-env.js","sourceRoot":"","sources":["../src/runtime-env.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQH,wCAEC;AA4CD,oDAMC;AAED,4BAEC;AAGD,kDAIC;AAQD,gDAiBC;AAMD,8CAeC;AAGD,kDAQC;AAGD,0CAYC;AAED,gDAEC;AAOD,8CAgBC;AAeD,4CA4BC;AA0BD,wDA+BC;AA5QD,uCAAyB;AACzB,2CAA6B;AAC7B,2BAA6B;AAC7B,iDAA0C;AAE1C,gEAAgE;AAChE,SAAgB,cAAc,CAAC,OAAe,IAAA,YAAO,GAAE;IACrD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;AACpD,CA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** Build the local ToolContext. Re-resolved per tool call so a create_wallet
3
+ * in this session makes later authenticated calls work immediately. */
4
+ export declare function buildLocalContext(env?: NodeJS.ProcessEnv): ToolContext;
5
+ export declare function startStdioServer(): Promise<void>;
6
+ //# sourceMappingURL=stdio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AA4BhD;wEACwE;AACxE,wBAAgB,iBAAiB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,WAAW,CAqFnF;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAoBtD"}
package/dist/stdio.js ADDED
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildLocalContext = buildLocalContext;
4
+ exports.startStdioServer = startStdioServer;
5
+ const thread_reader_1 = require("./core/thread-reader");
6
+ /**
7
+ * Local stdio MCP server entrypoint (`npx @provian/mcp`).
8
+ *
9
+ * Wires the shared tool core to a StdioServerTransport with local credential
10
+ * resolution:
11
+ * - agent API creds: PROVIAN_API_KEY/PROVIAN_API_SECRET env, else
12
+ * ~/.provian/agent-credentials.json (0600)
13
+ * - device creds: PROVIAN_DEVICE_KEY/PROVIAN_DEVICE_SECRET env, else an
14
+ * agent-owned ~/.provian/credentials
15
+ * - relay URL: PROVIAN_RELAY_URL env (default https://api.provian.ai)
16
+ *
17
+ * NEVER write to stdout here — it is the MCP protocol channel. Diagnostics go
18
+ * to stderr.
19
+ */
20
+ const stdio_1 = require("@modelcontextprotocol/server/stdio");
21
+ const server_1 = require("./core/server");
22
+ const genesis_offer_1 = require("./core/genesis-offer");
23
+ const credentials_1 = require("./credentials");
24
+ const device_credentials_1 = require("./device-credentials");
25
+ const eip191_1 = require("./eip191");
26
+ const recovery_seal_1 = require("./core/recovery-seal");
27
+ const crypto_1 = require("./core/crypto");
28
+ const agent_wallet_registration_1 = require("./agent-wallet-registration");
29
+ const DEFAULT_RELAY_URL = 'https://api.provian.ai';
30
+ /** Held so the stdio transport (reading process stdin) is not garbage-collected
31
+ * and the process stays alive for the connection's lifetime. */
32
+ let activeStdioHandle = null;
33
+ /** Build the local ToolContext. Re-resolved per tool call so a create_wallet
34
+ * in this session makes later authenticated calls work immediately. */
35
+ function buildLocalContext(env = process.env) {
36
+ (0, device_credentials_1.reconcileInstalledDeviceRegistration)();
37
+ return {
38
+ baseUrl: (env.PROVIAN_RELAY_URL || DEFAULT_RELAY_URL).replace(/\/$/, ''),
39
+ fetchImpl: fetch,
40
+ auth: (0, credentials_1.resolveLocalAuth)(env),
41
+ mode: 'local',
42
+ persistCredentials: (creds) => (0, credentials_1.persistAgentCredentials)(creds),
43
+ loadOrCreatePendingAgentWalletRegistration: (context) => {
44
+ const passphrase = env.PROVIAN_KEYSTORE_PASSPHRASE;
45
+ if (!passphrase) {
46
+ throw new Error('PROVIAN_KEYSTORE_PASSPHRASE is required for local create_wallet');
47
+ }
48
+ return (0, agent_wallet_registration_1.loadOrCreatePendingAgentWalletRegistration)(context, passphrase);
49
+ },
50
+ reloadPendingAgentWalletRegistration: (context, expected) => {
51
+ const passphrase = env.PROVIAN_KEYSTORE_PASSPHRASE;
52
+ if (!passphrase) {
53
+ throw new Error('PROVIAN_KEYSTORE_PASSPHRASE is required for local create_wallet');
54
+ }
55
+ return (0, agent_wallet_registration_1.reloadPendingAgentWalletRegistration)(context, passphrase, expected);
56
+ },
57
+ loadCompletedAgentWalletRegistration: (context) => {
58
+ const passphrase = env.PROVIAN_KEYSTORE_PASSPHRASE;
59
+ if (!passphrase) {
60
+ throw new Error('PROVIAN_KEYSTORE_PASSPHRASE is required for local create_wallet');
61
+ }
62
+ const completed = (0, agent_wallet_registration_1.loadCompletedAgentWalletIdentity)(passphrase, undefined, context);
63
+ if (!completed)
64
+ return null;
65
+ const credentials = (0, credentials_1.loadBoundAgentCredentialsFile)();
66
+ if (!credentials
67
+ || credentials.wallet_id !== completed.walletId
68
+ || credentials.address.toLowerCase() !== completed.address.toLowerCase()) {
69
+ throw new Error('Completed MCP wallet credentials do not match the final encrypted identity');
70
+ }
71
+ (0, agent_wallet_registration_1.clearCompletedAgentWalletPending)(passphrase, context);
72
+ return {
73
+ ...completed,
74
+ apiKey: credentials.api_key,
75
+ apiSecret: credentials.api_secret,
76
+ credentialsPersistedTo: credentials_1.AGENT_CREDS_PATH,
77
+ };
78
+ },
79
+ completePendingAgentWalletRegistration: (registrationId, wallet, context) => {
80
+ const passphrase = env.PROVIAN_KEYSTORE_PASSPHRASE;
81
+ if (!passphrase) {
82
+ throw new Error('PROVIAN_KEYSTORE_PASSPHRASE is required for local create_wallet');
83
+ }
84
+ return (0, agent_wallet_registration_1.completePendingAgentWalletRegistration)(registrationId, wallet, {
85
+ passphrase,
86
+ context,
87
+ });
88
+ },
89
+ signEip191: eip191_1.signEip191Message,
90
+ withLocalSovereignIdentity: (fn) => {
91
+ const passphrase = env.PROVIAN_KEYSTORE_PASSPHRASE;
92
+ if (!passphrase) {
93
+ throw new Error('PROVIAN_KEYSTORE_PASSPHRASE is required to sign with the local sovereign identity');
94
+ }
95
+ const completed = (0, agent_wallet_registration_1.loadCompletedAgentWalletIdentity)(passphrase);
96
+ if (!completed) {
97
+ throw new Error('No completed local agent wallet identity found — run create_wallet first (or sign locally and pass the pre-signed fields).');
98
+ }
99
+ // The decrypted private key is confined to this closure: the signing
100
+ // helpers close over it, but it is NEVER returned to the tool handler or
101
+ // placed in any tool argument/result (F32).
102
+ const privateKey = completed.privateKey;
103
+ const pubkey = (0, crypto_1.derivePublicKeyFromPrivateKey)(privateKey);
104
+ return fn({
105
+ address: completed.address,
106
+ walletId: completed.walletId,
107
+ pubkey,
108
+ signEip191: (message) => (0, eip191_1.signEip191Message)(privateKey, message),
109
+ signPop: (binding) => (0, crypto_1.signPoPChallenge)(privateKey, binding),
110
+ readThreadMessage: (ciphertext) => (0, thread_reader_1.decryptLocalThreadMessage)(privateKey, ciphertext),
111
+ sealRecoveryKey: (anchorPubkeyB64u) => (0, recovery_seal_1.sealToRecoveryAnchor)(anchorPubkeyB64u, privateKey),
112
+ });
113
+ },
114
+ };
115
+ }
116
+ async function startStdioServer() {
117
+ // serveStdio owns the era decision: the opening exchange selects the wire era
118
+ // and pins ONE instance from this factory for the connection's lifetime.
119
+ // legacy:'serve' (the default) keeps serving current-era clients that open
120
+ // with the 2025 `initialize` handshake, alongside modern 2026-07-28 clients.
121
+ // The handle is held so the transport (reading process stdin) keeps the
122
+ // process alive.
123
+ activeStdioHandle = (0, stdio_1.serveStdio)(() => (0, server_1.buildProvianMcpServer)(() => buildLocalContext()), {
124
+ legacy: 'serve',
125
+ });
126
+ const auth = (0, credentials_1.resolveLocalAuth)();
127
+ // The Genesis offer LEADS the startup output while the window is open (stderr only —
128
+ // stdout is the MCP channel). Nothing after the window closes.
129
+ for (const line of (0, genesis_offer_1.genesisOfferLines)())
130
+ console.error(line);
131
+ console.error(`provian-mcp: stdio server ready (relay: ${process.env.PROVIAN_RELAY_URL || DEFAULT_RELAY_URL}; ` +
132
+ (auth
133
+ ? 'agent credentials resolved)'
134
+ : `no agent credentials yet — call create_wallet, or set PROVIAN_API_KEY/PROVIAN_API_SECRET or ${credentials_1.AGENT_CREDS_PATH})`));
135
+ }
136
+ //# sourceMappingURL=stdio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stdio.js","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":";;AAgDA,8CAqFC;AAED,4CAoBC;AA3JD,wDAAiE;AACjE;;;;;;;;;;;;;GAaG;AAEH,8DAAgE;AAChE,0CAAsD;AAEtD,wDAAyD;AACzD,+CAKuB;AACvB,6DAE8B;AAC9B,qCAA6C;AAC7C,wDAA4D;AAC5D,0CAAgF;AAChF,2EAMqC;AAErC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAEnD;iEACiE;AAC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