@bjorntech/key-ferry 0.0.0-stage → 0.1.4

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 (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +209 -2
  3. package/SECURITY.md +87 -0
  4. package/dist/contracts.d.ts +133 -0
  5. package/dist/contracts.d.ts.map +1 -0
  6. package/dist/contracts.js +29 -0
  7. package/dist/contracts.js.map +1 -0
  8. package/dist/index.d.ts +7 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +12 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/options.d.ts +44 -0
  13. package/dist/options.d.ts.map +1 -0
  14. package/dist/options.js +260 -0
  15. package/dist/options.js.map +1 -0
  16. package/dist/plugin.d.ts +24 -0
  17. package/dist/plugin.d.ts.map +1 -0
  18. package/dist/plugin.js +215 -0
  19. package/dist/plugin.js.map +1 -0
  20. package/dist/relay/index.d.ts +37 -0
  21. package/dist/relay/index.d.ts.map +1 -0
  22. package/dist/relay/index.js +480 -0
  23. package/dist/relay/index.js.map +1 -0
  24. package/dist/remote.d.ts +62 -0
  25. package/dist/remote.d.ts.map +1 -0
  26. package/dist/remote.js +227 -0
  27. package/dist/remote.js.map +1 -0
  28. package/dist/rpc.d.ts +112 -0
  29. package/dist/rpc.d.ts.map +1 -0
  30. package/dist/rpc.js +117 -0
  31. package/dist/rpc.js.map +1 -0
  32. package/dist/services/process.d.ts +56 -0
  33. package/dist/services/process.d.ts.map +1 -0
  34. package/dist/services/process.js +208 -0
  35. package/dist/services/process.js.map +1 -0
  36. package/dist/tui.d.ts +59 -0
  37. package/dist/tui.d.ts.map +1 -0
  38. package/dist/tui.js +93 -0
  39. package/dist/tui.js.map +1 -0
  40. package/dist/varlock/manager.d.ts +6 -0
  41. package/dist/varlock/manager.d.ts.map +1 -0
  42. package/dist/varlock/manager.js +425 -0
  43. package/dist/varlock/manager.js.map +1 -0
  44. package/dist/varlock/protocol.d.ts +67 -0
  45. package/dist/varlock/protocol.d.ts.map +1 -0
  46. package/dist/varlock/protocol.js +248 -0
  47. package/dist/varlock/protocol.js.map +1 -0
  48. package/docs/architecture.md +179 -0
  49. package/docs/quality.md +102 -0
  50. package/docs/releasing.md +149 -0
  51. package/docs/troubleshooting.md +214 -0
  52. package/examples/.env.schema +17 -0
  53. package/examples/opencode.jsonc +44 -0
  54. package/package.json +96 -4
package/dist/remote.js ADDED
@@ -0,0 +1,227 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { isIP } from "node:net";
3
+ import { Effect, Scope } from "effect";
4
+ /** Must stay in sync with the standalone relay implementation. */
5
+ export const RELAY_AUTH_HEADER = "x-varlock-relay-token";
6
+ const HOP_BY_HOP = new Set([
7
+ "connection",
8
+ "keep-alive",
9
+ "proxy-authenticate",
10
+ "proxy-authorization",
11
+ "te",
12
+ "trailer",
13
+ "transfer-encoding",
14
+ "upgrade",
15
+ "host",
16
+ "content-length",
17
+ ]);
18
+ const MCP_PROTOCOL_HEADERS = new Set([
19
+ "accept",
20
+ "content-type",
21
+ "mcp-session-id",
22
+ "mcp-protocol-version",
23
+ "last-event-id",
24
+ "origin",
25
+ ]);
26
+ const CREDENTIAL_HEADERS = new Set(["authorization", "cookie", "proxy-authorization"]);
27
+ const HEADER_NAME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
28
+ const diagnostic = (server, code, message) => ({ server, code, message });
29
+ export function isRemoteProtection(value) {
30
+ return "remote" in value;
31
+ }
32
+ export function sourceEnvironmentKeys(mapping) {
33
+ if (!isRemoteProtection(mapping))
34
+ return Object.values(mapping);
35
+ return Object.values(mapping.remote.headers).map((value) => typeof value === "string" ? value : value.env);
36
+ }
37
+ export function validateRemoteUrl(value, allowPrivateNetwork = false) {
38
+ let url;
39
+ try {
40
+ url = new URL(value);
41
+ }
42
+ catch {
43
+ throw new TypeError("remote MCP URL is invalid");
44
+ }
45
+ if (url.protocol !== "https:" || url.username || url.password || url.hash) {
46
+ throw new TypeError("remote MCP URL must be HTTPS without credentials or fragments");
47
+ }
48
+ if (!allowPrivateNetwork && unsafeNetworkHost(url.hostname)) {
49
+ throw new TypeError("remote MCP URL targets a local or private network; set allowPrivateNetwork to opt in");
50
+ }
51
+ return url;
52
+ }
53
+ function unsafeNetworkHost(hostname) {
54
+ const host = hostname.toLowerCase().replace(/^\[/, "").replace(/\]$/, "");
55
+ if (host === "localhost" || host.endsWith(".localhost") || host === "0.0.0.0")
56
+ return true;
57
+ const version = isIP(host);
58
+ if (version === 6)
59
+ return (host === "::1" || host.startsWith("fc") || host.startsWith("fd") || host.startsWith("fe80:"));
60
+ if (version !== 4)
61
+ return false;
62
+ const octets = host.split(".").map(Number);
63
+ const [a, b] = octets;
64
+ return (a === 10 ||
65
+ a === 127 ||
66
+ (a === 169 && b === 254) ||
67
+ (a === 192 && b === 168) ||
68
+ (a === 172 && b >= 16 && b <= 31));
69
+ }
70
+ function mappingHeaderNames(mapping) {
71
+ return new Set(Object.keys(mapping.remote.headers).map((name) => name.toLowerCase()));
72
+ }
73
+ /** Remove mapped and dangerous configured headers from the native loopback config. */
74
+ export function safeForwardHeaders(headers, mapping) {
75
+ const mapped = mappingHeaderNames(mapping);
76
+ const result = Object.create(null);
77
+ for (const [name, value] of Object.entries(headers ?? {})) {
78
+ const lower = name.toLowerCase();
79
+ if (!HEADER_NAME.test(name) ||
80
+ name === "__proto__" ||
81
+ name === "prototype" ||
82
+ name === "constructor" ||
83
+ HOP_BY_HOP.has(lower) ||
84
+ MCP_PROTOCOL_HEADERS.has(lower))
85
+ return undefined;
86
+ if (mapped.has(lower))
87
+ continue;
88
+ if (CREDENTIAL_HEADERS.has(lower) || /[\r\n\0]/.test(value))
89
+ return undefined;
90
+ result[name] = value;
91
+ }
92
+ return result;
93
+ }
94
+ function placeholderHeaders(mapping, environment) {
95
+ const result = Object.create(null);
96
+ for (const [header, raw] of Object.entries(mapping.remote.headers)) {
97
+ const value = typeof raw === "string" ? { env: raw } : raw;
98
+ const placeholder = environment[value.env];
99
+ if (placeholder === undefined)
100
+ throw new Error("missing placeholder");
101
+ result[header] = `${value.prefix ?? ""}${placeholder}${value.suffix ?? ""}`;
102
+ }
103
+ return result;
104
+ }
105
+ function readProxyAndCa(environment) {
106
+ const proxyUrl = environment.HTTPS_PROXY ??
107
+ environment.https_proxy ??
108
+ environment.HTTP_PROXY ??
109
+ environment.http_proxy;
110
+ const caPath = environment.NODE_EXTRA_CA_CERTS;
111
+ if (!proxyUrl || !caPath || !caPath.startsWith("/"))
112
+ throw new Error("missing Varlock proxy wiring");
113
+ const caPem = readFileSync(caPath, "utf8");
114
+ if (caPem.length === 0 ||
115
+ caPem.length > 2 * 1024 * 1024 ||
116
+ !caPem.includes("-----BEGIN CERTIFICATE-----")) {
117
+ throw new Error("invalid Varlock CA certificate");
118
+ }
119
+ return { proxyUrl, caPem };
120
+ }
121
+ /** Coordinates relay replacement without exposing relay tokens or secrets. */
122
+ export function makeRemoteRelayCoordinator(factory, allowPrivateNetwork = false) {
123
+ const active = new Map();
124
+ let currentDiagnostics = [];
125
+ const stop = (handle) => handle.stop.pipe(Effect.catch(() => Effect.void));
126
+ const reconcile = (servers, mappings, environment, generation) => Effect.gen(function* () {
127
+ const nextDiagnostics = [];
128
+ for (const [name, mapping] of Object.entries(mappings)) {
129
+ if (!isRemoteProtection(mapping))
130
+ continue;
131
+ const server = servers.get(name);
132
+ const old = active.get(name);
133
+ if (!server || server.disabled === true) {
134
+ if (old) {
135
+ yield* stop(old.handle);
136
+ active.delete(name);
137
+ }
138
+ if (!server)
139
+ nextDiagnostics.push(diagnostic(name, "remote_unavailable", "selected remote MCP server is not configured"));
140
+ continue;
141
+ }
142
+ if (!factory) {
143
+ if (old) {
144
+ yield* stop(old.handle);
145
+ active.delete(name);
146
+ }
147
+ nextDiagnostics.push(diagnostic(name, "remote_unavailable", "remote protection is unavailable in this plugin runtime"));
148
+ continue;
149
+ }
150
+ if (server.oauth !== false) {
151
+ if (old) {
152
+ yield* stop(old.handle);
153
+ active.delete(name);
154
+ }
155
+ nextDiagnostics.push(diagnostic(name, "remote_oauth_required", "set oauth:false for API-key relay mode, or remove this Varlock mapping to keep native OAuth"));
156
+ continue;
157
+ }
158
+ let upstream;
159
+ let wiring;
160
+ let placeholders;
161
+ let forwarded;
162
+ try {
163
+ upstream = validateRemoteUrl(server.url, allowPrivateNetwork);
164
+ wiring = readProxyAndCa(environment);
165
+ placeholders = placeholderHeaders(mapping, environment);
166
+ forwarded = safeForwardHeaders(server.headers, mapping);
167
+ if (forwarded === undefined)
168
+ throw new Error("invalid remote header");
169
+ }
170
+ catch (error) {
171
+ if (old) {
172
+ yield* stop(old.handle);
173
+ active.delete(name);
174
+ }
175
+ const message = error instanceof Error && error.message === "missing placeholder"
176
+ ? "a mapped placeholder is unavailable"
177
+ : error instanceof Error && error.message === "invalid remote header"
178
+ ? "remote headers contain an unsafe or malformed field"
179
+ : error instanceof Error && error.message.includes("remote MCP URL")
180
+ ? error.message
181
+ : "Varlock proxy wiring is unavailable";
182
+ nextDiagnostics.push(diagnostic(name, message === "a mapped placeholder is unavailable"
183
+ ? "remote_missing_placeholder"
184
+ : message.startsWith("remote MCP URL")
185
+ ? "remote_invalid_url"
186
+ : message === "remote headers contain an unsafe or malformed field"
187
+ ? "remote_invalid_header"
188
+ : "remote_relay_failed", message));
189
+ continue;
190
+ }
191
+ if (old && old.generation === generation)
192
+ continue;
193
+ if (old) {
194
+ yield* stop(old.handle);
195
+ active.delete(name);
196
+ }
197
+ const started = yield* factory({
198
+ upstreamUrl: upstream.toString(),
199
+ proxyUrl: wiring.proxyUrl,
200
+ managerCaPem: wiring.caPem,
201
+ placeholderHeaders: placeholders,
202
+ oauth: false,
203
+ }).pipe(Effect.map((handle) => ({ ok: true, handle })), Effect.catch(() => Effect.succeed({ ok: false })));
204
+ if (started.ok)
205
+ active.set(name, { handle: started.handle, generation });
206
+ else
207
+ nextDiagnostics.push(diagnostic(name, "remote_relay_failed", "remote relay could not start"));
208
+ }
209
+ currentDiagnostics = nextDiagnostics;
210
+ });
211
+ return {
212
+ get handles() {
213
+ return new Map([...active].map(([name, record]) => [name, record.handle]));
214
+ },
215
+ get diagnostics() {
216
+ return currentDiagnostics;
217
+ },
218
+ reconcile,
219
+ get health() {
220
+ return Effect.suspend(() => Effect.forEach([...active.values()], (record) => record.handle.health.pipe(Effect.map((value) => value.listening), Effect.catch(() => Effect.succeed(false))), { concurrency: "unbounded" }).pipe(Effect.map((values) => values.every(Boolean))));
221
+ },
222
+ stopAll: Effect.suspend(() => Effect.forEach([...active.values()], (record) => stop(record.handle), {
223
+ concurrency: "unbounded",
224
+ }).pipe(Effect.tap(() => Effect.sync(() => active.clear())))),
225
+ };
226
+ }
227
+ //# sourceMappingURL=remote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote.js","sourceRoot":"","sources":["../src/remote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAGvC,kEAAkE;AAClE,MAAM,CAAC,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AAuDzD,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,YAAY;IACZ,YAAY;IACZ,oBAAoB;IACpB,qBAAqB;IACrB,IAAI;IACJ,SAAS;IACT,mBAAmB;IACnB,SAAS;IACT,MAAM;IACN,gBAAgB;CACjB,CAAC,CAAC;AACH,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACnC,QAAQ;IACR,cAAc;IACd,gBAAgB;IAChB,sBAAsB;IACtB,eAAe;IACf,QAAQ;CACT,CAAC,CAAC;AACH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,eAAe,EAAE,QAAQ,EAAE,qBAAqB,CAAC,CAAC,CAAC;AACvF,MAAM,WAAW,GAAG,+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,OAAO,CAAC,CAAC,CAAC,CACtD,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAC3B,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;YACpE,WAAW,EAAE,WAAW;SACzB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAC7D;KACF,CAAC;AACJ,CAAC"}
package/dist/rpc.d.ts ADDED
@@ -0,0 +1,112 @@
1
+ import { Schema } from "effect";
2
+ import { VarlockError, type SafeStatus } from "./contracts.js";
3
+ export declare const SafeStatusSchema: Schema.Struct<{
4
+ readonly phase: Schema.String;
5
+ readonly projectDirectory: Schema.String;
6
+ readonly generation: Schema.Number;
7
+ readonly pid: Schema.optional<Schema.Number>;
8
+ readonly endpoint: Schema.optional<Schema.String>;
9
+ readonly lastRefreshAt: Schema.optional<Schema.String>;
10
+ readonly error: Schema.optional<Schema.Struct<{
11
+ readonly code: Schema.String;
12
+ readonly message: Schema.String;
13
+ readonly retryable: Schema.Boolean;
14
+ }>>;
15
+ readonly diagnostics: Schema.optional<Schema.$Array<Schema.Struct<{
16
+ readonly code: Schema.String;
17
+ readonly server: Schema.String;
18
+ readonly message: Schema.String;
19
+ }>>>;
20
+ }>;
21
+ export declare const KeyFerryRpc: {
22
+ readonly id: "key-ferry";
23
+ readonly methods: {
24
+ readonly status: {
25
+ readonly input: Schema.Struct<{}>;
26
+ readonly output: Schema.Struct<{
27
+ readonly phase: Schema.String;
28
+ readonly projectDirectory: Schema.String;
29
+ readonly generation: Schema.Number;
30
+ readonly pid: Schema.optional<Schema.Number>;
31
+ readonly endpoint: Schema.optional<Schema.String>;
32
+ readonly lastRefreshAt: Schema.optional<Schema.String>;
33
+ readonly error: Schema.optional<Schema.Struct<{
34
+ readonly code: Schema.String;
35
+ readonly message: Schema.String;
36
+ readonly retryable: Schema.Boolean;
37
+ }>>;
38
+ readonly diagnostics: Schema.optional<Schema.$Array<Schema.Struct<{
39
+ readonly code: Schema.String;
40
+ readonly server: Schema.String;
41
+ readonly message: Schema.String;
42
+ }>>>;
43
+ }>;
44
+ readonly errors: {
45
+ readonly unavailable: Schema.Struct<{
46
+ readonly code: Schema.String;
47
+ }>;
48
+ };
49
+ };
50
+ readonly refresh: {
51
+ readonly input: Schema.Struct<{}>;
52
+ readonly output: Schema.Struct<{
53
+ readonly phase: Schema.String;
54
+ readonly projectDirectory: Schema.String;
55
+ readonly generation: Schema.Number;
56
+ readonly pid: Schema.optional<Schema.Number>;
57
+ readonly endpoint: Schema.optional<Schema.String>;
58
+ readonly lastRefreshAt: Schema.optional<Schema.String>;
59
+ readonly error: Schema.optional<Schema.Struct<{
60
+ readonly code: Schema.String;
61
+ readonly message: Schema.String;
62
+ readonly retryable: Schema.Boolean;
63
+ }>>;
64
+ readonly diagnostics: Schema.optional<Schema.$Array<Schema.Struct<{
65
+ readonly code: Schema.String;
66
+ readonly server: Schema.String;
67
+ readonly message: Schema.String;
68
+ }>>>;
69
+ }>;
70
+ readonly errors: {
71
+ readonly unavailable: Schema.Struct<{
72
+ readonly code: Schema.String;
73
+ }>;
74
+ };
75
+ };
76
+ readonly doctor: {
77
+ readonly input: Schema.Struct<{}>;
78
+ readonly output: Schema.Struct<{
79
+ readonly phase: Schema.String;
80
+ readonly projectDirectory: Schema.String;
81
+ readonly generation: Schema.Number;
82
+ readonly pid: Schema.optional<Schema.Number>;
83
+ readonly endpoint: Schema.optional<Schema.String>;
84
+ readonly lastRefreshAt: Schema.optional<Schema.String>;
85
+ readonly error: Schema.optional<Schema.Struct<{
86
+ readonly code: Schema.String;
87
+ readonly message: Schema.String;
88
+ readonly retryable: Schema.Boolean;
89
+ }>>;
90
+ readonly diagnostics: Schema.optional<Schema.$Array<Schema.Struct<{
91
+ readonly code: Schema.String;
92
+ readonly server: Schema.String;
93
+ readonly message: Schema.String;
94
+ }>>>;
95
+ }>;
96
+ readonly errors: {
97
+ readonly unavailable: Schema.Struct<{
98
+ readonly code: Schema.String;
99
+ }>;
100
+ };
101
+ };
102
+ };
103
+ readonly events: {};
104
+ };
105
+ declare const publicMessage: (error: VarlockError) => "Varlock configuration is invalid" | "Varlock could not start" | "Varlock refresh failed" | "Varlock operation timed out" | "Varlock is not ready" | "Varlock manager is stopped" | "Varlock returned an invalid response" | "Varlock is unavailable";
106
+ /** Rebuild a safe status without trusting an adapter error message. */
107
+ export declare function sanitizeStatus(status: SafeStatus): SafeStatus;
108
+ export declare function rpcError(error: VarlockError): {
109
+ code: "invalid_config" | "unavailable" | "start_failed" | "refresh_failed" | "not_ready" | "disposed" | "protocol_error" | "timeout";
110
+ };
111
+ export { publicMessage };
112
+ //# sourceMappingURL=rpc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAQ/D,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;EAiB3B,CAAC;AAcH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BtB,CAAC;AAEH,QAAA,MAAM,aAAa,GAAI,OAAO,YAAY,0PAmBzC,CAAC;AAEF,uEAAuE;AACvE,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAkC7D;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,YAAY;;EAE3C;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
package/dist/rpc.js ADDED
@@ -0,0 +1,117 @@
1
+ import { Rpc } from "@opencode/plugin/effect";
2
+ import { Schema } from "effect";
3
+ import { VarlockError } from "./contracts.js";
4
+ const statusError = Schema.Struct({
5
+ code: Schema.String,
6
+ message: Schema.String,
7
+ retryable: Schema.Boolean,
8
+ });
9
+ export const SafeStatusSchema = Schema.Struct({
10
+ phase: Schema.String,
11
+ projectDirectory: Schema.String,
12
+ generation: Schema.Number,
13
+ pid: Schema.optional(Schema.Number),
14
+ endpoint: Schema.optional(Schema.String),
15
+ lastRefreshAt: Schema.optional(Schema.String),
16
+ error: Schema.optional(statusError),
17
+ diagnostics: Schema.optional(Schema.Array(Schema.Struct({
18
+ code: Schema.String,
19
+ server: Schema.String,
20
+ message: Schema.String,
21
+ }))),
22
+ });
23
+ const Empty = Schema.Struct({});
24
+ const isVarlockErrorCode = (value) => value === "invalid_config" ||
25
+ value === "unavailable" ||
26
+ value === "start_failed" ||
27
+ value === "refresh_failed" ||
28
+ value === "not_ready" ||
29
+ value === "disposed" ||
30
+ value === "protocol_error" ||
31
+ value === "timeout";
32
+ export const KeyFerryRpc = Rpc.define({
33
+ id: "key-ferry",
34
+ methods: {
35
+ status: {
36
+ input: Empty,
37
+ output: SafeStatusSchema,
38
+ errors: {
39
+ unavailable: Schema.Struct({ code: Schema.String }),
40
+ },
41
+ },
42
+ refresh: {
43
+ input: Empty,
44
+ output: SafeStatusSchema,
45
+ errors: {
46
+ unavailable: Schema.Struct({ code: Schema.String }),
47
+ },
48
+ },
49
+ doctor: {
50
+ input: Empty,
51
+ output: SafeStatusSchema,
52
+ errors: {
53
+ unavailable: Schema.Struct({ code: Schema.String }),
54
+ },
55
+ },
56
+ },
57
+ events: {},
58
+ });
59
+ const publicMessage = (error) => {
60
+ switch (error.code) {
61
+ case "invalid_config":
62
+ return "Varlock configuration is invalid";
63
+ case "start_failed":
64
+ return "Varlock could not start";
65
+ case "refresh_failed":
66
+ return "Varlock refresh failed";
67
+ case "timeout":
68
+ return "Varlock operation timed out";
69
+ case "not_ready":
70
+ return "Varlock is not ready";
71
+ case "disposed":
72
+ return "Varlock manager is stopped";
73
+ case "protocol_error":
74
+ return "Varlock returned an invalid response";
75
+ default:
76
+ return "Varlock is unavailable";
77
+ }
78
+ };
79
+ /** Rebuild a safe status without trusting an adapter error message. */
80
+ export function sanitizeStatus(status) {
81
+ const errorCode = isVarlockErrorCode(status.error?.code) ? status.error.code : "unavailable";
82
+ return {
83
+ phase: status.phase,
84
+ projectDirectory: status.projectDirectory,
85
+ generation: status.generation,
86
+ ...(status.pid === undefined ? {} : { pid: status.pid }),
87
+ ...(status.endpoint === undefined ? {} : { endpoint: status.endpoint }),
88
+ ...(status.lastRefreshAt === undefined ? {} : { lastRefreshAt: status.lastRefreshAt }),
89
+ ...(status.error === undefined
90
+ ? {}
91
+ : {
92
+ error: new VarlockError({
93
+ code: errorCode,
94
+ message: publicMessage(new VarlockError({
95
+ code: errorCode,
96
+ message: "",
97
+ retryable: status.error.retryable === true,
98
+ })),
99
+ retryable: status.error.retryable,
100
+ }),
101
+ }),
102
+ ...(status.diagnostics === undefined
103
+ ? {}
104
+ : {
105
+ diagnostics: status.diagnostics.map((item) => ({
106
+ code: item.code,
107
+ server: item.server,
108
+ message: item.message,
109
+ })),
110
+ }),
111
+ };
112
+ }
113
+ export function rpcError(error) {
114
+ return { code: error.code };
115
+ }
116
+ export { publicMessage };
117
+ //# sourceMappingURL=rpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc.js","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,YAAY,EAAmB,MAAM,gBAAgB,CAAC;AAE/D,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC;IAChC,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C,MAAM;oBACnB,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB,CAAC,CAAC;aACJ,CAAC;KACP,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAmB;IAC1C,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;AAC9B,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,56 @@
1
+ import { Context, Effect, Layer } from "effect";
2
+ export type ProcessPhase = "spawn" | "running" | "timeout" | "capture-limit" | "exit";
3
+ declare const ProcessError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
4
+ readonly _tag: "ProcessError";
5
+ } & Readonly<A>;
6
+ /** Deliberately contains no command, arguments, or captured output. */
7
+ export declare class ProcessError extends ProcessError_base<{
8
+ readonly phase: ProcessPhase;
9
+ readonly code: "spawn-failed" | "timeout" | "capture-limit" | "non-zero" | "signal" | "io";
10
+ readonly message: string;
11
+ readonly exitCode?: number;
12
+ readonly signal?: string;
13
+ }> {
14
+ }
15
+ export interface ProcessExit {
16
+ readonly code: number | null;
17
+ readonly signal: string | null;
18
+ }
19
+ export interface ProcessHealth {
20
+ readonly pid: number;
21
+ readonly running: boolean;
22
+ readonly exit?: ProcessExit;
23
+ }
24
+ export interface RunInput {
25
+ readonly executable: string;
26
+ readonly args: readonly string[];
27
+ readonly cwd: string;
28
+ /** Exact child environment. Omit to run with an isolated empty environment. */
29
+ readonly env?: Readonly<Record<string, string | undefined>>;
30
+ readonly maxBytes?: number;
31
+ readonly timeoutMs?: number;
32
+ }
33
+ export interface RunResult extends ProcessExit {
34
+ readonly stdout: string;
35
+ readonly stderr: string;
36
+ }
37
+ export interface SpawnInput extends Omit<RunInput, "maxBytes" | "timeoutMs"> {
38
+ readonly terminateGraceMs?: number;
39
+ }
40
+ export interface ManagedProcess {
41
+ readonly pid: number;
42
+ readonly completion: Effect.Effect<ProcessExit, ProcessError>;
43
+ readonly health: Effect.Effect<ProcessHealth, never>;
44
+ readonly stop: Effect.Effect<void, ProcessError>;
45
+ }
46
+ export interface ProcessService {
47
+ run(input: RunInput): Effect.Effect<RunResult, ProcessError>;
48
+ spawn(input: SpawnInput): Effect.Effect<ManagedProcess, ProcessError, ScopeRequirement>;
49
+ }
50
+ export type ScopeRequirement = import("effect/Scope").Scope;
51
+ declare const Process_base: Context.ServiceClass<Process, "key-ferry/Process", ProcessService>;
52
+ export declare class Process extends Process_base {
53
+ }
54
+ export declare const ProcessLive: Layer.Layer<Process, never, never>;
55
+ export {};
56
+ //# sourceMappingURL=process.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/services/process.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAkB,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEhE,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,eAAe,GAAG,MAAM,CAAC;;;;AAEtF,uEAAuE;AACvE,qBAAa,YAAa,SAAQ,kBAAiC;IACjE,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,SAAS,GAAG,eAAe,GAAG,UAAU,GAAG,QAAQ,GAAG,IAAI,CAAC;IAC3F,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;CAAG;AAEL,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,aAAa;IAC5B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