@foldkit/devtools-mcp 0.26.0-canary.54f8bcd443b4 → 0.26.0-canary.7dfe32f9d0cd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -32
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +2 -2
- package/dist/relayClient.d.ts +2 -2
- package/dist/relayClient.d.ts.map +1 -1
- package/dist/relayLocation.d.ts.map +1 -1
- package/dist/relayLocation.js +34 -5
- package/dist/relayRegistry.d.ts.map +1 -1
- package/dist/relayRegistry.js +14 -46
- package/dist/relayRegistryTrust.d.ts.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +140 -470
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +6 -6
- package/package.json +8 -8
- package/dist/relayLiveness.d.ts +0 -6
- package/dist/relayLiveness.d.ts.map +0 -1
- package/dist/relayLiveness.js +0 -80
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ With it attached, agents can:
|
|
|
6
6
|
|
|
7
7
|
- Read the current Model, or any historical Model by history index
|
|
8
8
|
- Narrow reads with dot-string paths and summarized payloads to fit token budgets
|
|
9
|
-
- List and inspect the Message history, with Command and Mount lifecycle, diffs, and
|
|
9
|
+
- List and inspect the Message history, with Command and Mount lifecycle, diffs, and Submodel chains
|
|
10
10
|
- Query history server-side: filter entries by changed Model paths, count Messages by tag, tail the latest entries, and diff the Models at two indices
|
|
11
11
|
- Read the recorded init Model, the Commands returned from `init`, and the Mounts that fired during the first render
|
|
12
12
|
- Inspect Runtime state: current index, retained history bounds, pause status
|
|
@@ -36,22 +36,17 @@ pnpm add -D @foldkit/devtools-mcp
|
|
|
36
36
|
yarn add -D @foldkit/devtools-mcp
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
Pass your `Message` Schema to `Runtime.makeApplication` to let the agent dispatch Messages. The Runtime rejects a payload that does not match the Schema before it reaches update:
|
|
40
40
|
|
|
41
41
|
```typescript
|
|
42
|
-
|
|
43
|
-
block: ApplicationBlock,
|
|
44
|
-
layer,
|
|
45
|
-
container,
|
|
42
|
+
Runtime.makeApplication({
|
|
46
43
|
devTools: {
|
|
47
44
|
// Rest of your DevTools config
|
|
48
|
-
|
|
45
|
+
Message,
|
|
49
46
|
},
|
|
50
47
|
})
|
|
51
48
|
```
|
|
52
49
|
|
|
53
|
-
If the completed Message Codec needs Services for decoding, `dispatch: true` adds them to the Program's requirements. Supply any remaining decoding Services through `program.provide(...)`; the dispatch opt-in does not provide them.
|
|
54
|
-
|
|
55
50
|
Restart your dev server, then restart your AI agent. The MCP server will appear with the `foldkit_*` tools attached.
|
|
56
51
|
|
|
57
52
|
The browser bridge runs inside your app, so the MCP server only sees a Runtime while the app is open in a browser tab. Close the tab and the Runtime disappears from `foldkit_list_runtimes`.
|
|
@@ -62,29 +57,29 @@ Treat this server as privileged access to the running application. A connected a
|
|
|
62
57
|
|
|
63
58
|
Keep API keys, passwords, access and refresh tokens, authorization headers, session material, and private personal data out of those values. Long-lived secrets belong behind a server boundary, including in local demos. If the browser must temporarily carry a sensitive value, use Effect `Redacted` with a `Schema.Redacted` field configured with `disallowJsonEncode: true`. `Redacted` protects normal string, JSON, and inspection output; it does not encrypt the value or hide a browser-side credential from the person running the browser.
|
|
64
59
|
|
|
65
|
-
`excludeFromHistory` is for noisy Messages, not sensitive ones. The resulting Model remains inspectable.
|
|
60
|
+
`excludeFromHistory` is for noisy Messages, not sensitive ones. The resulting Model remains inspectable. Omitting `DevToolsConfig.Message` disables dispatch only; read and replay tools remain available. Set `devToolsMcpPort: false` in the Foldkit Vite plugin options to keep the in-browser DevTools without starting the MCP relay, or set `devTools: false` in the application config to disable recording and the browser bridge too.
|
|
66
61
|
|
|
67
62
|
## Tools
|
|
68
63
|
|
|
69
64
|
Every tool except `foldkit_list_runtimes` accepts an optional `runtime_id`. Without one, the tool uses the most recently connected Runtime of the most recently started dev server.
|
|
70
65
|
|
|
71
|
-
| Tool | Description
|
|
72
|
-
| ------------------------------- |
|
|
73
|
-
| `foldkit_list_runtimes` | Returns metadata for every connected browser tab. Each tab carries the `projectRoot` of the dev server it belongs to, unless `FOLDKIT_DEVTOOLS_MCP_PORT` or `FOLDKIT_DEVTOOLS_MCP_HOST` is set. Agents call this first to discover which Runtime to target.
|
|
74
|
-
| `foldkit_get_model` | Snapshots the current Model. Accepts an optional `path` to narrow to a subtree and `expand` to control summarization.
|
|
75
|
-
| `foldkit_get_model_at` | Snapshots a historical Model after a given history entry. Pass `index: N - 1` to read the Model just before Message `N`. Same `path`/`expand` semantics as `foldkit_get_model`. Indices outside the readable range (older entries are evicted past the rolling buffer) are rejected with the valid bounds. For the initial Model (and the init Commands and Mounts), use `foldkit_get_init`.
|
|
76
|
-
| `foldkit_get_init` | Reads the recorded initial Model, the Commands returned from the application's `init` function, and the Mounts that fired during the first render. Each Command and Mount carries its declared args. Equivalent to selecting the synthetic "init" row in the DevTools panel.
|
|
77
|
-
| `foldkit_get_runtime_state` | Snapshots the Runtime's DevTools state: history bounds, current paused/live status, and whether init is recorded. Useful for understanding what `foldkit_list_messages` and `foldkit_get_message` will see and detecting whether the Runtime is paused.
|
|
78
|
-
| `foldkit_list_messages` | Lists Message history entries. Each entry carries the Message body, Commands triggered (with args), Mounts that started or ended during the resulting render (with args), timestamp, an `isModelChanged` flag, the diff path lists (`changedPaths` / `affectedPaths`), and any extracted
|
|
79
|
-
| `foldkit_count_messages_by_tag` | Counts retained history entries by Message tag, without payloads, sorted by count descending. A cheap reconnaissance call before paging through history: it surfaces the high-frequency Messages worth filtering out, and with `changed_paths_match` it answers which Message tags touch a Model subtree.
|
|
80
|
-
| `foldkit_diff_models` | Diffs the Models at two history indices server-side, returning path-level changes `{ path, before, after }` with summarized values. Each side is `{ _tag: 'Present', value }`, or `{ _tag: 'Absent' }` when the path does not exist on that side. Pass `changed_paths_match` to narrow the diff to a subtree.
|
|
81
|
-
| `foldkit_get_message` | Reads one entry at a given index. The response carries the SerializedEntry only; to inspect the Model around the entry, call `foldkit_get_model_at` with `index - 1` (before) and `index` (after). Use `foldkit_get_init` for the synthetic init entry.
|
|
82
|
-
| `foldkit_list_keyframes` | Returns the indices Foldkit can replay back to. Index `-1` is the initial Model.
|
|
83
|
-
| `foldkit_replay_to_keyframe` | Time-travels the Runtime to a previous state. The Runtime is paused at that snapshot until `foldkit_resume` is called.
|
|
84
|
-
| `foldkit_resume` | Resumes normal execution after a replay.
|
|
85
|
-
| `foldkit_get_message_schema` | Describes the Runtime's Message Schema so agents can construct valid Messages without reading the application source. With no arguments, returns a small variant index (top-level tag names plus payload fields). With `variant_tag` set to a dot-separated path of variant tags (e.g. `"GotChildMessage.Opened"`), narrows the JSON Schema along the chain and collapses deeper unions to summary placeholders. Returns `maybeResult: None` when
|
|
86
|
-
| `foldkit_dispatch_message` | Dispatches a Message into the Runtime as if your application produced it. The Runtime decodes the payload against your Schema and returns a clean error if it does not match.
|
|
87
|
-
| `foldkit_dispatch_messages` | Dispatches an ordered batch of 1 to 100 Messages in one call, first to last. The Runtime validates every payload before dispatching any of them, so one invalid entry rejects the whole batch with its zero-based position and nothing is dispatched. The response reports the predicted history index for each Message.
|
|
66
|
+
| Tool | Description |
|
|
67
|
+
| ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
68
|
+
| `foldkit_list_runtimes` | Returns metadata for every connected browser tab. Each tab carries the `projectRoot` of the dev server it belongs to, unless `FOLDKIT_DEVTOOLS_MCP_PORT` or `FOLDKIT_DEVTOOLS_MCP_HOST` is set. Agents call this first to discover which Runtime to target. |
|
|
69
|
+
| `foldkit_get_model` | Snapshots the current Model. Accepts an optional `path` to narrow to a subtree and `expand` to control summarization. |
|
|
70
|
+
| `foldkit_get_model_at` | Snapshots a historical Model after a given history entry. Pass `index: N - 1` to read the Model just before Message `N`. Same `path`/`expand` semantics as `foldkit_get_model`. Indices outside the readable range (older entries are evicted past the rolling buffer) are rejected with the valid bounds. For the initial Model (and the init Commands and Mounts), use `foldkit_get_init`. |
|
|
71
|
+
| `foldkit_get_init` | Reads the recorded initial Model, the Commands returned from the application's `init` function, and the Mounts that fired during the first render. Each Command and Mount carries its declared args. Equivalent to selecting the synthetic "init" row in the DevTools panel. |
|
|
72
|
+
| `foldkit_get_runtime_state` | Snapshots the Runtime's DevTools state: history bounds, current paused/live status, and whether init is recorded. Useful for understanding what `foldkit_list_messages` and `foldkit_get_message` will see and detecting whether the Runtime is paused. |
|
|
73
|
+
| `foldkit_list_messages` | Lists Message history entries. Each entry carries the Message body, Commands triggered (with args), Mounts that started or ended during the resulting render (with args), timestamp, an `isModelChanged` flag, the diff path lists (`changedPaths` / `affectedPaths`), and any extracted Submodel chain. Filter server-side with `changed_paths_match`, read the latest entries with `from_end`, and paginate forward with `since_index`. |
|
|
74
|
+
| `foldkit_count_messages_by_tag` | Counts retained history entries by Message tag, without payloads, sorted by count descending. A cheap reconnaissance call before paging through history: it surfaces the high-frequency Messages worth filtering out, and with `changed_paths_match` it answers which Message tags touch a Model subtree. |
|
|
75
|
+
| `foldkit_diff_models` | Diffs the Models at two history indices server-side, returning path-level changes `{ path, before, after }` with summarized values. Each side is `{ _tag: 'Present', value }`, or `{ _tag: 'Absent' }` when the path does not exist on that side. Pass `changed_paths_match` to narrow the diff to a subtree. |
|
|
76
|
+
| `foldkit_get_message` | Reads one entry at a given index. The response carries the SerializedEntry only; to inspect the Model around the entry, call `foldkit_get_model_at` with `index - 1` (before) and `index` (after). Use `foldkit_get_init` for the synthetic init entry. |
|
|
77
|
+
| `foldkit_list_keyframes` | Returns the indices Foldkit can replay back to. Index `-1` is the initial Model. |
|
|
78
|
+
| `foldkit_replay_to_keyframe` | Time-travels the Runtime to a previous state. The Runtime is paused at that snapshot until `foldkit_resume` is called. |
|
|
79
|
+
| `foldkit_resume` | Resumes normal execution after a replay. |
|
|
80
|
+
| `foldkit_get_message_schema` | Describes the Runtime's Message Schema so agents can construct valid Messages without reading the application source. With no arguments, returns a small variant index (top-level tag names plus payload fields). With `variant_tag` set to a dot-separated path of variant tags (e.g. `"GotChildMessage.Opened"`), narrows the JSON Schema along the chain and collapses deeper unions to summary placeholders. Returns `maybeResult: None` when the Runtime hasn't configured `DevToolsConfig.Message`. |
|
|
81
|
+
| `foldkit_dispatch_message` | Dispatches a Message into the Runtime as if your application produced it. The Runtime decodes the payload against your Schema and returns a clean error if it does not match. |
|
|
82
|
+
| `foldkit_dispatch_messages` | Dispatches an ordered batch of 1 to 100 Messages in one call, first to last. The Runtime validates every payload before dispatching any of them, so one invalid entry rejects the whole batch with its zero-based position and nothing is dispatched. The response reports the predicted history index for each Message. |
|
|
88
83
|
|
|
89
84
|
### Reading the Model efficiently
|
|
90
85
|
|
|
@@ -112,8 +107,6 @@ Three components cooperate:
|
|
|
112
107
|
|
|
113
108
|
Multiple browser tabs can be connected at once and each is addressable by its connection id. Tabs that close (gracefully or not) are pruned from the live Runtime list automatically.
|
|
114
109
|
|
|
115
|
-
The bridge derives JSON Schema for its transport boundary. A Message payload must have a supported JSON representation to be dispatched from MCP. Browser-memory values such as `File` cannot be constructed through this connection.
|
|
116
|
-
|
|
117
110
|
## Configuration
|
|
118
111
|
|
|
119
112
|
An agent started at a workspace root can inspect every Foldkit app running under it. If no dev server runs under the agent's project root, the MCP server finds the nearest root that encloses it. This also lets an agent started in `src/` or through a symlink find the app. `foldkit_list_runtimes` lists the Runtimes from every matching dev server and includes each server's `projectRoot`.
|
|
@@ -129,14 +122,12 @@ The MCP server connects when a tool is called. It checks the registry on every c
|
|
|
129
122
|
|
|
130
123
|
An automatically discovered relay's registry record contains a random token. The MCP client uses it to sign a connection challenge and checks the relay's response before sending tool requests. The plugin refuses to publish the record if another user can read or replace the registry directory. The MCP server applies the same check before reading it. Both reject symlinks and junctions; on macOS they also check directory ACLs. Clients without access to the registry cannot connect, but the agent using this MCP server can inspect the Runtime data.
|
|
131
124
|
|
|
132
|
-
On Linux, relay records also identify the publisher's PID and network namespaces. Readers omit relays from a known different network namespace without deleting their records. Matching PID namespaces allow the ordinary process check. When the PID namespace is different or unknown, a failed process check does not prove the relay is gone; the reader probes its port before retiring the record. Older records remain compatible.
|
|
133
|
-
|
|
134
125
|
On Windows, both processes use PowerShell to check the directory's owner, access list, ancestors, and reparse points. The registry must be a private direct child of the user's temporary directory. If the check cannot run or refuses the directory, configure `devToolsMcpPort` in Vite and set `FOLDKIT_DEVTOOLS_MCP_PORT` to the same port. A fixed port listens on every interface without a token. Do not use it on a shared or untrusted network.
|
|
135
126
|
|
|
136
127
|
## Notes
|
|
137
128
|
|
|
138
129
|
- The MCP bridge shares its lifecycle with Foldkit DevTools. If you set `devTools: false` in your program config, the bridge does not start and the Runtime is invisible to MCP. The default enables the bridge in dev.
|
|
139
|
-
-
|
|
130
|
+
- Without `Message` in your `DevToolsConfig`, dispatch is rejected. The other (read-only) tools still work.
|
|
140
131
|
- The relay only runs at dev time. Production builds never include the relay or the bridge, regardless of any `show` setting.
|
|
141
132
|
|
|
142
133
|
## Documentation
|
package/dist/install.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.d.ts","sources":["../src/install.ts"],"names":[],"mappings":"AAoEA;;;;;GAKG;AACH,eAAO,MAAM,OAAO,QAAO,IAkB1B,CAAA"}
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":"AAoEA;;;;;GAKG;AACH,eAAO,MAAM,OAAO,QAAO,IAkB1B,CAAA"}
|
package/dist/install.js
CHANGED
|
@@ -36,9 +36,9 @@ const printNextSteps = (alreadyRegistered) => {
|
|
|
36
36
|
console.log('');
|
|
37
37
|
console.log('Next steps:');
|
|
38
38
|
console.log('');
|
|
39
|
-
console.log(' 1.
|
|
39
|
+
console.log(' 1. Pass your Message Schema to Runtime.makeApplication (enables dispatch):');
|
|
40
40
|
console.log('');
|
|
41
|
-
console.log(' devTools: {
|
|
41
|
+
console.log(' devTools: { Message }');
|
|
42
42
|
console.log('');
|
|
43
43
|
console.log(' 2. Start your dev server, then restart your AI agent (Claude Code, Cursor, etc.).');
|
|
44
44
|
console.log('');
|
package/dist/relayClient.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type Cause, Effect, Option } from 'effect';
|
|
|
2
2
|
import { Request, type Response, type RuntimeInfo } from 'foldkit/devtools-protocol';
|
|
3
3
|
import type { RelayTarget } from './relayLocation.js';
|
|
4
4
|
export type ListedRuntime = Readonly<{
|
|
5
|
-
runtime: RuntimeInfo;
|
|
5
|
+
runtime: typeof RuntimeInfo.Type;
|
|
6
6
|
maybeProjectRoot: Option.Option<string>;
|
|
7
7
|
}>;
|
|
8
8
|
/**
|
|
@@ -25,7 +25,7 @@ export type ListedRuntime = Readonly<{
|
|
|
25
25
|
*/
|
|
26
26
|
export type RelayClient = Readonly<{
|
|
27
27
|
listRuntimes: Effect.Effect<ReadonlyArray<ListedRuntime>, Error>;
|
|
28
|
-
sendRequest: (request: Request, maybeRuntimeId: Option.Option<string>) => Effect.Effect<Response, Cause.TimeoutError | Error>;
|
|
28
|
+
sendRequest: (request: typeof Request.Type, maybeRuntimeId: Option.Option<string>) => Effect.Effect<typeof Response.Type, Cause.TimeoutError | Error>;
|
|
29
29
|
close: Effect.Effect<void>;
|
|
30
30
|
}>;
|
|
31
31
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relayClient.d.ts","sources":["../src/relayClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,KAAK,EAKV,MAAM,EAKN,MAAM,EASP,MAAM,QAAQ,CAAA;AACf,OAAO,EACL,OAAO,EAEP,KAAK,QAAQ,EAEb,KAAK,WAAW,EACjB,MAAM,2BAA2B,CAAA;AAIlC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAqDrD,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC;IACnC,OAAO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|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relayLocation.d.ts","sources":["../src/relayLocation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAGzD,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAE3B,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"relayLocation.d.ts","sourceRoot":"","sources":["../src/relayLocation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAGzD,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAE3B,MAAM,oBAAoB,CAAA;AAS3B,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC;IAC9B,mBAAmB,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC1C,mBAAmB,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC1C,WAAW,EAAE,MAAM,CAAA;CACpB,CAAC,CAAA;AAEF,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC;IACjC,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;CACxC,CAAC,CAAA;AAEF,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAe5B,CAAA;AAmDrB,eAAO,MAAM,kBAAkB,aACnB,QAAQ,KACjB,MAAM,CAAC,MAAM,CAAC,MAAM,CAiBtB,CAAA;AAED,eAAO,MAAM,mBAAmB,aACpB,QAAQ,kBACF,mBAAmB,KAClC,MAAM,CAAC,MAAM,CACd,aAAa,CAAC,WAAW,CAAC,EAC1B,KAAK,EACL,qBAAqB,GAAG,mBAAmB,CAAC,mBAAmB,CAmB7D,CAAA"}
|
package/dist/relayLocation.js
CHANGED
|
@@ -3,6 +3,10 @@ import { isIPv6 } from 'node:net';
|
|
|
3
3
|
import { discoverRelays, } from './relayRegistry.js';
|
|
4
4
|
const LEGACY_DEFAULT_PORT = 9988;
|
|
5
5
|
const DEFAULT_HOST = 'localhost';
|
|
6
|
+
const AUTOMATIC_RELAY_HOST = '127.0.0.1';
|
|
7
|
+
const AUTOMATIC_RELAY_PATH = '/__foldkit/devtools-mcp';
|
|
8
|
+
const RELAY_TOKEN_PARAMETER = 'token';
|
|
9
|
+
const RELAY_TOKEN_PATTERN = /^[0-9a-f]{64}$/;
|
|
6
10
|
export const loadSettings = Effect.gen(function* () {
|
|
7
11
|
const maybeConfiguredPort = yield* Config.option(Config.String('FOLDKIT_DEVTOOLS_MCP_PORT'));
|
|
8
12
|
const maybeConfiguredHost = yield* Config.option(Config.String('FOLDKIT_DEVTOOLS_MCP_HOST'));
|
|
@@ -20,6 +24,28 @@ const fixedTarget = (url) => ({
|
|
|
20
24
|
url,
|
|
21
25
|
maybeProjectRoot: Option.none(),
|
|
22
26
|
});
|
|
27
|
+
const parseUrl = Option.liftThrowable((url) => new URL(url));
|
|
28
|
+
const hasValidPort = (url) => {
|
|
29
|
+
const port = globalThis.Number(url.port);
|
|
30
|
+
return (url.port !== '' &&
|
|
31
|
+
globalThis.Number.isInteger(port) &&
|
|
32
|
+
port > 0 &&
|
|
33
|
+
port <= 65_535);
|
|
34
|
+
};
|
|
35
|
+
const isPublishedRelayUrl = (value) => Option.exists(parseUrl(value), url => {
|
|
36
|
+
if (url.protocol !== 'ws:' ||
|
|
37
|
+
url.username !== '' ||
|
|
38
|
+
url.password !== '' ||
|
|
39
|
+
url.hash !== '' ||
|
|
40
|
+
!hasValidPort(url)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
const parameters = Array.fromIterable(url.searchParams);
|
|
44
|
+
return (url.hostname === AUTOMATIC_RELAY_HOST &&
|
|
45
|
+
url.pathname === AUTOMATIC_RELAY_PATH &&
|
|
46
|
+
Array.length(parameters) === 1 &&
|
|
47
|
+
Option.exists(Array.head(parameters), ([name, token]) => name === RELAY_TOKEN_PARAMETER && RELAY_TOKEN_PATTERN.test(token)));
|
|
48
|
+
});
|
|
23
49
|
export const configuredRelayUrl = (settings) => {
|
|
24
50
|
const { maybeConfiguredHost, maybeConfiguredPort } = settings;
|
|
25
51
|
if (Option.isSome(maybeConfiguredHost) ||
|
|
@@ -34,9 +60,12 @@ export const configuredRelayUrl = (settings) => {
|
|
|
34
60
|
};
|
|
35
61
|
export const resolveRelayTargets = (settings, registryReader) => Option.match(configuredRelayUrl(settings), {
|
|
36
62
|
onSome: url => Effect.succeed([fixedTarget(url)]),
|
|
37
|
-
onNone: () => Effect.map(discoverRelays(settings.projectRoot, registryReader),
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
63
|
+
onNone: () => Effect.map(discoverRelays(settings.projectRoot, registryReader), records => {
|
|
64
|
+
const trustedRecords = Array.filter(records, record => isPublishedRelayUrl(record.url));
|
|
65
|
+
return Array.map(trustedRecords, (record) => ({
|
|
66
|
+
key: record.id,
|
|
67
|
+
url: record.url,
|
|
68
|
+
maybeProjectRoot: Option.some(record.root),
|
|
69
|
+
}));
|
|
70
|
+
}),
|
|
42
71
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relayRegistry.d.ts","sources":["../src/relayRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EACN,UAAU,EACV,OAAO,EAGP,IAAI,EACJ,GAAG,EAIJ,MAAM,QAAQ,CAAA;AACf,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,
|
|
1
|
+
{"version":3,"file":"relayRegistry.d.ts","sourceRoot":"","sources":["../src/relayRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EACN,UAAU,EACV,OAAO,EAGP,IAAI,EACJ,GAAG,EAIJ,MAAM,QAAQ,CAAA;AACf,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,EAGL,WAAW,EACZ,MAAM,2BAA2B,CAAA;AAGlC,OAAO,EACL,KAAK,kBAAkB,EAExB,MAAM,yBAAyB,CAAA;AAMhC,MAAM,MAAM,qBAAqB,GAAG,UAAU,CAAC,UAAU,GAAG,IAAI,CAAC,IAAI,CAAA;AAErE,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC;IACzC,KAAK,EAAE,kBAAkB,CAAA;IACzB,gBAAgB,EAAE,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA;CACnD,CAAC,CAAA;AAEF,KAAK,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,GAAG,UAAU,GAAG,KAAK,CAAC,CAAA;AA8FrE,eAAO,MAAM,YAAY,SACjB,MAAM,aACD,MAAM,WACR,WAAW,KACnB,OASF,CAAA;AAED,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,MAAM,CAAC,mBAAmB,CASnE,CAAA;AAwEJ,eAAO,MAAM,cAAc,gBACZ,MAAM,kBACH,mBAAmB,KAClC,MAAM,CAAC,MAAM,CACd,aAAa,CAAC,WAAW,CAAC,EAC1B,KAAK,EACL,qBAAqB,GAAG,mBAAmB,CAAC,mBAAmB,CAqD7D,CAAA"}
|
package/dist/relayRegistry.js
CHANGED
|
@@ -1,37 +1,10 @@
|
|
|
1
1
|
import { Array, Config, Console, Effect, FileSystem, HashSet, Option, Order, Path, Ref, Schema, String, pipe, } from 'effect';
|
|
2
2
|
import { RELAY_REGISTRY_DIRECTORY_NAME, RELAY_REGISTRY_DIRECTORY_VARIABLE, RelayRecord, } from 'foldkit/devtools-protocol';
|
|
3
3
|
import { homedir, tmpdir } from 'node:os';
|
|
4
|
-
import { checkRelay, readProcessNamespaces } from './relayLiveness.js';
|
|
5
4
|
import { relayRegistryTrust, } from './relayRegistryTrust.js';
|
|
6
5
|
const RUNTIME_DIRECTORY_VARIABLE = 'XDG_RUNTIME_DIR';
|
|
7
6
|
const RECORD_FILE_EXTENSION = '.json';
|
|
8
7
|
const RETIRING_RECORD_SUFFIX = '.retiring';
|
|
9
|
-
const AUTOMATIC_RELAY_HOST = '127.0.0.1';
|
|
10
|
-
const AUTOMATIC_RELAY_PATH = '/__foldkit/devtools-mcp';
|
|
11
|
-
const RELAY_TOKEN_PARAMETER = 'token';
|
|
12
|
-
const RELAY_TOKEN_PATTERN = /^[0-9a-f]{64}$/;
|
|
13
|
-
const parseUrl = Option.liftThrowable((url) => new URL(url));
|
|
14
|
-
const hasValidPort = (url) => {
|
|
15
|
-
const port = globalThis.Number(url.port);
|
|
16
|
-
return (url.port !== '' &&
|
|
17
|
-
globalThis.Number.isInteger(port) &&
|
|
18
|
-
port > 0 &&
|
|
19
|
-
port <= 65_535);
|
|
20
|
-
};
|
|
21
|
-
const isPublishedRelayUrl = (value) => Option.exists(parseUrl(value), url => {
|
|
22
|
-
if (url.protocol !== 'ws:' ||
|
|
23
|
-
url.username !== '' ||
|
|
24
|
-
url.password !== '' ||
|
|
25
|
-
url.hash !== '' ||
|
|
26
|
-
!hasValidPort(url)) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
const parameters = Array.fromIterable(url.searchParams);
|
|
30
|
-
return (url.hostname === AUTOMATIC_RELAY_HOST &&
|
|
31
|
-
url.pathname === AUTOMATIC_RELAY_PATH &&
|
|
32
|
-
Array.length(parameters) === 1 &&
|
|
33
|
-
Option.exists(Array.head(parameters), ([name, token]) => name === RELAY_TOKEN_PARAMETER && RELAY_TOKEN_PATTERN.test(token)));
|
|
34
|
-
});
|
|
35
8
|
const decodeRelayRecord = Schema.decodeUnknownOption(Schema.fromJsonString(RelayRecord));
|
|
36
9
|
const relayRegistryDirectory = Effect.gen(function* () {
|
|
37
10
|
const path = yield* Path.Path;
|
|
@@ -42,6 +15,15 @@ const relayRegistryDirectory = Effect.gen(function* () {
|
|
|
42
15
|
return path.join(Option.getOrElse(maybeRuntimeDirectory, () => defaultParent), RELAY_REGISTRY_DIRECTORY_NAME);
|
|
43
16
|
});
|
|
44
17
|
}).pipe(Effect.orDie);
|
|
18
|
+
const isProcessAlive = (pid) => {
|
|
19
|
+
try {
|
|
20
|
+
process.kill(pid, 0);
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return error instanceof Error && 'code' in error && error.code === 'EPERM';
|
|
25
|
+
}
|
|
26
|
+
};
|
|
45
27
|
const readRecordFile = (filePath) => Effect.gen(function* () {
|
|
46
28
|
const fileSystem = yield* FileSystem.FileSystem;
|
|
47
29
|
const raw = yield* fileSystem.readFileString(filePath);
|
|
@@ -63,26 +45,13 @@ const retireStaleRecord = (filePath, record) => Effect.gen(function* () {
|
|
|
63
45
|
}
|
|
64
46
|
yield* fileSystem.remove(retiringPath, { force: true }).pipe(Effect.ignore);
|
|
65
47
|
});
|
|
66
|
-
const readLiveRecordFile = (filePath
|
|
48
|
+
const readLiveRecordFile = (filePath) => Effect.gen(function* () {
|
|
67
49
|
const maybeRecord = yield* readRecordFile(filePath);
|
|
68
|
-
if (Option.
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
const record = maybeRecord.value;
|
|
72
|
-
if (!isPublishedRelayUrl(record.url)) {
|
|
73
|
-
return Option.none();
|
|
74
|
-
}
|
|
75
|
-
const status = yield* checkRelay(record, maybeOwnNamespaces);
|
|
76
|
-
if (status === 'Gone') {
|
|
77
|
-
yield* retireStaleRecord(filePath, record);
|
|
50
|
+
if (Option.isSome(maybeRecord) && !isProcessAlive(maybeRecord.value.pid)) {
|
|
51
|
+
yield* retireStaleRecord(filePath, maybeRecord.value);
|
|
78
52
|
return Option.none();
|
|
79
53
|
}
|
|
80
|
-
|
|
81
|
-
return Option.none();
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
return maybeRecord;
|
|
85
|
-
}
|
|
54
|
+
return maybeRecord;
|
|
86
55
|
});
|
|
87
56
|
const newestFirst = Order.mapInput(Order.flip(Order.Number), record => record.startedAt);
|
|
88
57
|
export const isWithinRoot = (root, candidate, pathApi) => {
|
|
@@ -147,8 +116,7 @@ export const discoverRelays = (projectRoot, registryReader) => Effect.gen(functi
|
|
|
147
116
|
.readDirectory(directory)
|
|
148
117
|
.pipe(Effect.orElseSucceed(() => []));
|
|
149
118
|
const recordFileNames = Array.filter(fileNames, String.endsWith(RECORD_FILE_EXTENSION));
|
|
150
|
-
const
|
|
151
|
-
const records = Array.getSomes(yield* Effect.forEach(recordFileNames, recordFileName => readLiveRecordFile(path.join(directory, recordFileName), maybeOwnNamespaces)));
|
|
119
|
+
const records = Array.getSomes(yield* Effect.forEach(recordFileNames, recordFileName => readLiveRecordFile(path.join(directory, recordFileName))));
|
|
152
120
|
const realProjectRoot = yield* realRoot(projectRoot);
|
|
153
121
|
const rootedRecords = yield* Effect.forEach(records, record => Effect.map(realRoot(record.root), root => ({ record, root })));
|
|
154
122
|
const recordsInside = Array.filter(rootedRecords, ({ root }) => isWithinRoot(realProjectRoot, root, path));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relayRegistryTrust.d.ts","sources":["../src/relayRegistryTrust.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EACN,UAAU,EACV,MAAM,EAIP,MAAM,QAAQ,CAAA;AACf,OAAO,EAAgB,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAyElE,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC;IAC7C,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;CACpC,CAAC,CAAA;AAEF,MAAM,MAAM,kBAAkB,GAAG,QA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|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sources":["../src/server.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":""}
|