@introspection-ai/recipes 0.53.0 → 0.54.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.
- package/dist/connector-tools.d.ts +1 -1
- package/dist/connector-tools.d.ts.map +1 -1
- package/dist/connector-tools.js +1 -0
- package/dist/connector-tools.js.map +1 -1
- package/dist/introspection-open.d.ts +2 -2
- package/dist/introspection-open.d.ts.map +1 -1
- package/dist/introspection-open.js +27 -9
- package/dist/introspection-open.js.map +1 -1
- package/dist/issues/index.d.ts +1 -1
- package/dist/issues/index.d.ts.map +1 -1
- package/dist/issues/index.js +1 -1
- package/dist/issues/index.js.map +1 -1
- package/dist/issues/module.d.ts +3 -0
- package/dist/issues/module.d.ts.map +1 -1
- package/dist/issues/module.js +4 -0
- package/dist/issues/module.js.map +1 -1
- package/dist/mcp/cli/command-context.d.ts +13 -0
- package/dist/mcp/cli/command-context.d.ts.map +1 -1
- package/dist/mcp/cli/command-context.js +56 -16
- package/dist/mcp/cli/command-context.js.map +1 -1
- package/dist/mcp/cli/core.d.ts +1 -1
- package/dist/mcp/cli/core.d.ts.map +1 -1
- package/dist/mcp/cli/core.js +25 -16
- package/dist/mcp/cli/core.js.map +1 -1
- package/dist/mcp/client-entry.js +1 -1
- package/dist/mcp/client-entry.js.map +1 -1
- package/dist/mcp/daemon/client.d.ts +10 -1
- package/dist/mcp/daemon/client.d.ts.map +1 -1
- package/dist/mcp/daemon/client.js +41 -17
- package/dist/mcp/daemon/client.js.map +1 -1
- package/dist/mcp/daemon/hosted.d.ts +22 -0
- package/dist/mcp/daemon/hosted.d.ts.map +1 -0
- package/dist/mcp/daemon/hosted.js +98 -0
- package/dist/mcp/daemon/hosted.js.map +1 -0
- package/dist/mcp/daemon/index.js +18 -423
- package/dist/mcp/daemon/index.js.map +1 -1
- package/dist/mcp/daemon/protocol.d.ts +4 -0
- package/dist/mcp/daemon/protocol.d.ts.map +1 -1
- package/dist/mcp/daemon/protocol.js +10 -0
- package/dist/mcp/daemon/protocol.js.map +1 -1
- package/dist/mcp/daemon/server.d.ts +41 -0
- package/dist/mcp/daemon/server.d.ts.map +1 -0
- package/dist/mcp/daemon/server.js +547 -0
- package/dist/mcp/daemon/server.js.map +1 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +5 -3
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/pi-runtime.d.ts +4 -2
- package/dist/mcp/pi-runtime.d.ts.map +1 -1
- package/dist/mcp/pi-runtime.js +12 -6
- package/dist/mcp/pi-runtime.js.map +1 -1
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +16 -5
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp-chunks/chunk-53T5TVPR.js +546 -0
- package/dist/mcp-chunks/{chunk-QUDOU7MQ.js → chunk-757ZF552.js} +1 -1
- package/dist/mcp-chunks/{chunk-T5BPTC3T.js → chunk-D6OGGMWS.js} +89 -45
- package/dist/mcp-chunks/{chunk-IMG2JMBS.js → chunk-MYAMG6VL.js} +1 -1
- package/dist/mcp-chunks/{chunk-LQKMNWDE.js → chunk-OIK5AH2S.js} +5 -5
- package/dist/mcp-chunks/{chunk-3UVHZECT.js → chunk-OWGTNJNR.js} +9 -7
- package/dist/mcp-chunks/chunk-TUPFPO4L.js +400 -0
- package/dist/mcp-chunks/{cli-BM23ZXPJ.js → cli-UQ5QXFXU.js} +31 -31
- package/dist/mcp-chunks/{client-RKTAKDAY.js → client-SBELHRAE.js} +3 -3
- package/dist/mcp-chunks/{daemon-command-VU6WTFCJ.js → daemon-command-MQS6AP2W.js} +5 -5
- package/dist/mcp-chunks/dist-SDPPH7XQ.js +65 -0
- package/dist/mcp-chunks/{generate-cli-runner-JAAPSWGX.js → generate-cli-runner-LQBBQ7F5.js} +3 -3
- package/dist/mcp-chunks/{generated-daemon-runtime-LX4L2X7Z.js → generated-daemon-runtime-TUCZ3JEP.js} +4 -4
- package/dist/mcp-chunks/{pi-mcp-runtime-GHDEPXUL.js → pi-mcp-runtime-OLO25D7A.js} +1 -29
- package/dist/mcp-chunks/{runtime-T63YI7TC.js → runtime-5SOGEUTQ.js} +2 -2
- package/dist/mcp-chunks/{serve-command-75P4VBJ6.js → serve-command-YKSIXG7K.js} +3 -3
- package/dist/mcp-chunks/server-SLD55EBC.js +41 -0
- package/dist/mcp-daemon.js +29 -432
- package/dist/mcp-run-worker.js +9 -8
- package/dist/open.d.ts +9 -2
- package/dist/open.d.ts.map +1 -1
- package/dist/open.js +31 -3
- package/dist/open.js.map +1 -1
- package/dist/pi-extension.d.ts.map +1 -1
- package/dist/pi-extension.js +1 -1
- package/dist/pi-extension.js.map +1 -1
- package/dist/recipe/companions.d.ts +6 -0
- package/dist/recipe/companions.d.ts.map +1 -1
- package/dist/recipe/companions.js +22 -4
- package/dist/recipe/companions.js.map +1 -1
- package/dist/recipe/manifest.generated.d.ts +1 -1
- package/dist/recipe/manifest.generated.js +1 -1
- package/dist/recipe/suggestions.d.ts +15 -7
- package/dist/recipe/suggestions.d.ts.map +1 -1
- package/dist/recipe/suggestions.js +33 -11
- package/dist/recipe/suggestions.js.map +1 -1
- package/dist/suggestion-picker.d.ts +2 -2
- package/dist/suggestion-picker.d.ts.map +1 -1
- package/dist/suggestion-picker.js +3 -3
- package/dist/suggestion-picker.js.map +1 -1
- package/docs/interactions.md +20 -15
- package/docs/issues/README.md +6 -1
- package/docs/mcp-configuration.md +11 -3
- package/docs/recipe-format.md +30 -13
- package/package.json +5 -5
- package/skills/issues/SKILL.md +108 -0
- package/dist/mcp-chunks/{auth-command-UYFOGGQR.js → auth-command-PZLSOYAT.js} +6 -6
- package/dist/mcp-chunks/{call-command-6U5BNDR7.js → call-command-VILJIFYG.js} +6 -6
- package/dist/mcp-chunks/{chunk-36D4FILJ.js → chunk-ORJND4AI.js} +3 -3
- package/dist/mcp-chunks/{resource-command-DUY4SVE5.js → resource-command-SRFQQROJ.js} +4 -4
package/dist/mcp-daemon.js
CHANGED
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
startMcpDaemonServer
|
|
5
|
+
} from "./mcp-chunks/chunk-53T5TVPR.js";
|
|
3
6
|
import {
|
|
4
7
|
MCP_DAEMON_FINGERPRINT_ENV,
|
|
5
|
-
MCP_DAEMON_MAX_FRAME_BYTES,
|
|
6
8
|
MCP_DAEMON_PARENT_PID_ENV,
|
|
7
9
|
MCP_DAEMON_SOCKET_ENV,
|
|
8
|
-
MCP_DAEMON_TOKEN_ENV
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
installMcpCommandIoRouting,
|
|
13
|
-
mcpDaemonRequestContext,
|
|
14
|
-
serializeMcpDaemonEnvelope
|
|
15
|
-
} from "./mcp-chunks/chunk-T5BPTC3T.js";
|
|
16
|
-
import {
|
|
17
|
-
createMcpRuntime
|
|
18
|
-
} from "./mcp-chunks/chunk-3UVHZECT.js";
|
|
19
|
-
import "./mcp-chunks/chunk-QUDOU7MQ.js";
|
|
10
|
+
MCP_DAEMON_TOKEN_ENV
|
|
11
|
+
} from "./mcp-chunks/chunk-D6OGGMWS.js";
|
|
12
|
+
import "./mcp-chunks/chunk-TUPFPO4L.js";
|
|
13
|
+
import "./mcp-chunks/chunk-757ZF552.js";
|
|
20
14
|
import "./mcp-chunks/chunk-HNQSUT44.js";
|
|
21
|
-
import "./mcp-chunks/chunk-
|
|
15
|
+
import "./mcp-chunks/chunk-OIK5AH2S.js";
|
|
16
|
+
import "./mcp-chunks/chunk-MYAMG6VL.js";
|
|
17
|
+
import "./mcp-chunks/chunk-OWGTNJNR.js";
|
|
22
18
|
import "./mcp-chunks/chunk-3SXP4S2A.js";
|
|
23
|
-
import "./mcp-chunks/chunk-
|
|
24
|
-
import "./mcp-chunks/chunk-IMG2JMBS.js";
|
|
25
|
-
import "./mcp-chunks/chunk-36D4FILJ.js";
|
|
19
|
+
import "./mcp-chunks/chunk-ORJND4AI.js";
|
|
26
20
|
import "./mcp-chunks/chunk-2AKSS7WR.js";
|
|
27
21
|
import "./mcp-chunks/chunk-6P3KAQ5N.js";
|
|
28
22
|
import "./mcp-chunks/chunk-F2X4Y2TQ.js";
|
|
@@ -37,436 +31,39 @@ import "./mcp-chunks/chunk-7U5NSQ5T.js";
|
|
|
37
31
|
import "./mcp-chunks/chunk-3LENTPGE.js";
|
|
38
32
|
import "./mcp-chunks/chunk-JEHI2YU4.js";
|
|
39
33
|
import "./mcp-chunks/chunk-IWCVZ46B.js";
|
|
34
|
+
import "./mcp-chunks/chunk-O3RTM5HD.js";
|
|
40
35
|
import "./mcp-chunks/chunk-T4MQCFIK.js";
|
|
41
36
|
import "./mcp-chunks/chunk-BHXCAVFP.js";
|
|
42
|
-
import "./mcp-chunks/chunk-O3RTM5HD.js";
|
|
43
37
|
import "./mcp-chunks/chunk-MHUMLEBO.js";
|
|
44
38
|
import "./mcp-chunks/chunk-IRSL7JRH.js";
|
|
45
39
|
import "./mcp-chunks/chunk-UVRJ3AAD.js";
|
|
46
40
|
import "./mcp-chunks/chunk-O7SIXJM6.js";
|
|
41
|
+
import "./mcp-chunks/chunk-B6S43WID.js";
|
|
47
42
|
import "./mcp-chunks/chunk-LRKZP7DJ.js";
|
|
48
43
|
|
|
49
44
|
// src/mcp/daemon/index.ts
|
|
50
|
-
import { rm } from "node:fs/promises";
|
|
51
|
-
import { createServer } from "node:net";
|
|
52
|
-
import { Readable, Writable } from "node:stream";
|
|
53
|
-
import { setTimeout as delay } from "node:timers/promises";
|
|
54
45
|
import { existsSync } from "node:fs";
|
|
55
46
|
import { fileURLToPath } from "node:url";
|
|
56
|
-
|
|
57
|
-
var
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
if (!configuredSocketPath || !configuredToken || !configuredFingerprint) {
|
|
47
|
+
var socketPath = process.env[MCP_DAEMON_SOCKET_ENV];
|
|
48
|
+
var token = process.env[MCP_DAEMON_TOKEN_ENV];
|
|
49
|
+
var fingerprint = process.env[MCP_DAEMON_FINGERPRINT_ENV];
|
|
50
|
+
if (!socketPath || !token || !fingerprint) {
|
|
61
51
|
throw new Error("MCP daemon environment is incomplete.");
|
|
62
52
|
}
|
|
63
|
-
var socketPath = configuredSocketPath;
|
|
64
|
-
var token = configuredToken;
|
|
65
|
-
var fingerprint = configuredFingerprint;
|
|
66
|
-
var restoreIo = installMcpCommandIoRouting();
|
|
67
|
-
var runtimePromise;
|
|
68
|
-
var catalogPreloadPromise;
|
|
69
|
-
var catalogPreloadResult;
|
|
70
|
-
var wakeCatalogRetry;
|
|
71
|
-
var catalogDemanded = false;
|
|
72
|
-
var stopping = false;
|
|
73
|
-
var active = /* @__PURE__ */ new Map();
|
|
74
|
-
var SHUTDOWN_GRACE_MS = 1e3;
|
|
75
|
-
var CATALOG_PRELOAD_BACKOFF_MS = [100, 250, 500, 1e3, 2e3];
|
|
76
|
-
function runtime() {
|
|
77
|
-
runtimePromise ??= createMcpRuntime(process.env.MCPORTER_CONFIG).catch(
|
|
78
|
-
(error) => {
|
|
79
|
-
runtimePromise = void 0;
|
|
80
|
-
throw error;
|
|
81
|
-
}
|
|
82
|
-
);
|
|
83
|
-
return runtimePromise;
|
|
84
|
-
}
|
|
85
|
-
function catalogHealthy(catalogs) {
|
|
86
|
-
return catalogs.every((server2) => !server2.error);
|
|
87
|
-
}
|
|
88
|
-
async function catalogRetryDelay(timeoutMs) {
|
|
89
|
-
await Promise.race([
|
|
90
|
-
delay(timeoutMs),
|
|
91
|
-
new Promise((resolve) => {
|
|
92
|
-
wakeCatalogRetry = resolve;
|
|
93
|
-
})
|
|
94
|
-
]);
|
|
95
|
-
wakeCatalogRetry = void 0;
|
|
96
|
-
}
|
|
97
|
-
function preloadCatalogs(timeoutMs) {
|
|
98
|
-
if (catalogPreloadResult && catalogHealthy(catalogPreloadResult)) {
|
|
99
|
-
return Promise.resolve(catalogPreloadResult);
|
|
100
|
-
}
|
|
101
|
-
if (catalogPreloadPromise) return catalogPreloadPromise;
|
|
102
|
-
catalogDemanded = false;
|
|
103
|
-
const preload = (async () => {
|
|
104
|
-
let latest = [];
|
|
105
|
-
let latestError;
|
|
106
|
-
for (let attempt = 0; attempt <= CATALOG_PRELOAD_BACKOFF_MS.length; attempt += 1) {
|
|
107
|
-
try {
|
|
108
|
-
latest = await discoverMcpCatalogs(await runtime(), timeoutMs);
|
|
109
|
-
latestError = void 0;
|
|
110
|
-
catalogPreloadResult = latest;
|
|
111
|
-
if (catalogHealthy(latest)) {
|
|
112
|
-
return latest;
|
|
113
|
-
}
|
|
114
|
-
} catch (error) {
|
|
115
|
-
latestError = error;
|
|
116
|
-
}
|
|
117
|
-
if (catalogDemanded && attempt > 0) break;
|
|
118
|
-
const backoffMs = CATALOG_PRELOAD_BACKOFF_MS[attempt];
|
|
119
|
-
if (backoffMs === void 0) break;
|
|
120
|
-
await catalogRetryDelay(backoffMs);
|
|
121
|
-
}
|
|
122
|
-
if (latestError && latest.length === 0) throw latestError;
|
|
123
|
-
return latest;
|
|
124
|
-
})();
|
|
125
|
-
catalogPreloadPromise = preload;
|
|
126
|
-
void preload.then(
|
|
127
|
-
() => {
|
|
128
|
-
if (catalogPreloadPromise === preload) catalogPreloadPromise = void 0;
|
|
129
|
-
},
|
|
130
|
-
() => {
|
|
131
|
-
if (catalogPreloadPromise === preload) catalogPreloadPromise = void 0;
|
|
132
|
-
}
|
|
133
|
-
);
|
|
134
|
-
return preload;
|
|
135
|
-
}
|
|
136
|
-
async function joinCatalogPreload() {
|
|
137
|
-
const preload = catalogPreloadPromise;
|
|
138
|
-
if (!preload) return;
|
|
139
|
-
catalogDemanded = true;
|
|
140
|
-
wakeCatalogRetry?.();
|
|
141
|
-
await preload.catch(() => {
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
function send(socket, envelope, serializationError = "response_too_large") {
|
|
145
|
-
if (!socket.destroyed && !socket.writableEnded) {
|
|
146
|
-
try {
|
|
147
|
-
socket.write(serializeMcpDaemonEnvelope(envelope), () => {
|
|
148
|
-
});
|
|
149
|
-
} catch {
|
|
150
|
-
socket.write(
|
|
151
|
-
`${JSON.stringify({
|
|
152
|
-
id: envelope.id,
|
|
153
|
-
error: serializationError
|
|
154
|
-
})}
|
|
155
|
-
`,
|
|
156
|
-
() => {
|
|
157
|
-
}
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
function stream(id, name, socket) {
|
|
163
|
-
return new Writable({
|
|
164
|
-
write(chunk, _encoding, callback) {
|
|
165
|
-
send(socket, { id, stream: name, data: String(chunk) });
|
|
166
|
-
callback();
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
function runTimeoutMs() {
|
|
171
|
-
const value = Number(process.env.PI_RECIPES_MCP_RUN_TIMEOUT_MS ?? 12e4);
|
|
172
|
-
return Number.isSafeInteger(value) && value > 0 ? value : 12e4;
|
|
173
|
-
}
|
|
174
53
|
function runWorkerPath() {
|
|
175
54
|
const bundled = new URL("./mcp-run-worker.js", import.meta.url);
|
|
176
55
|
if (existsSync(bundled)) return fileURLToPath(bundled);
|
|
177
56
|
return fileURLToPath(new URL("../cli/run-worker.js", import.meta.url));
|
|
178
57
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
const hardTimeout = setTimeout(
|
|
189
|
-
() => void worker.terminate(),
|
|
190
|
-
runTimeoutMs() + 2e3
|
|
191
|
-
);
|
|
192
|
-
const abort = () => void worker.terminate();
|
|
193
|
-
controller.signal.addEventListener("abort", abort, { once: true });
|
|
194
|
-
try {
|
|
195
|
-
return await new Promise((resolve, reject) => {
|
|
196
|
-
let settled = false;
|
|
197
|
-
const finish = (task) => {
|
|
198
|
-
if (settled) return;
|
|
199
|
-
settled = true;
|
|
200
|
-
task();
|
|
201
|
-
};
|
|
202
|
-
worker.on("message", (message) => {
|
|
203
|
-
if (message.type === "stream") {
|
|
204
|
-
send(socket, {
|
|
205
|
-
id: request.id,
|
|
206
|
-
stream: message.stream,
|
|
207
|
-
data: String(message.data)
|
|
208
|
-
});
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
if (message.type === "toolCall") {
|
|
212
|
-
void sharedRuntime.callTool(
|
|
213
|
-
String(message.server),
|
|
214
|
-
String(message.tool),
|
|
215
|
-
message.options
|
|
216
|
-
).then(
|
|
217
|
-
(result) => worker.postMessage({
|
|
218
|
-
type: "toolResult",
|
|
219
|
-
id: message.id,
|
|
220
|
-
result
|
|
221
|
-
}),
|
|
222
|
-
(error) => worker.postMessage({
|
|
223
|
-
type: "toolError",
|
|
224
|
-
id: message.id,
|
|
225
|
-
message: error instanceof Error ? error.message : String(error)
|
|
226
|
-
})
|
|
227
|
-
);
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
if (message.type === "complete") {
|
|
231
|
-
finish(() => resolve(Number(message.exitCode)));
|
|
232
|
-
} else if (message.type === "failed") {
|
|
233
|
-
finish(() => reject(new Error(String(message.message))));
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
worker.once("error", (error) => finish(() => reject(error)));
|
|
237
|
-
worker.once("exit", (code) => {
|
|
238
|
-
if (settled) return;
|
|
239
|
-
if (controller.signal.aborted) finish(() => resolve(130));
|
|
240
|
-
else
|
|
241
|
-
finish(
|
|
242
|
-
() => reject(
|
|
243
|
-
new Error(`mcp run worker exited before completion (${code}).`)
|
|
244
|
-
)
|
|
245
|
-
);
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
} finally {
|
|
249
|
-
clearTimeout(hardTimeout);
|
|
250
|
-
controller.signal.removeEventListener("abort", abort);
|
|
251
|
-
await worker.terminate().catch(() => {
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
async function execute(request, socket) {
|
|
256
|
-
return context.with(
|
|
257
|
-
mcpDaemonRequestContext(request.trace),
|
|
258
|
-
() => executeRequest(request, socket)
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
async function executeRequest(request, socket) {
|
|
262
|
-
const controller = new AbortController();
|
|
263
|
-
active.set(request.id, controller);
|
|
264
|
-
socket.once("close", () => controller.abort());
|
|
265
|
-
try {
|
|
266
|
-
await joinCatalogPreload();
|
|
267
|
-
if (controller.signal.aborted) {
|
|
268
|
-
send(socket, { id: request.id, exitCode: 130 });
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
const exitCode = request.args[0] === "run" ? await executeRun(request, socket, controller) : await executeMcpCommand({
|
|
272
|
-
args: request.args,
|
|
273
|
-
runtime: await runtime(),
|
|
274
|
-
stdin: Readable.from([request.stdin]),
|
|
275
|
-
stdout: stream(request.id, "stdout", socket),
|
|
276
|
-
stderr: stream(request.id, "stderr", socket),
|
|
277
|
-
signal: controller.signal
|
|
278
|
-
});
|
|
279
|
-
send(socket, { id: request.id, exitCode });
|
|
280
|
-
} catch (error) {
|
|
281
|
-
send(socket, {
|
|
282
|
-
id: request.id,
|
|
283
|
-
stream: "stderr",
|
|
284
|
-
data: `${error instanceof Error ? error.message : String(error)}
|
|
285
|
-
`
|
|
286
|
-
});
|
|
287
|
-
send(socket, { id: request.id, exitCode: 1 });
|
|
288
|
-
} finally {
|
|
289
|
-
active.delete(request.id);
|
|
290
|
-
socket.end();
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
async function callTool(request, socket) {
|
|
294
|
-
return context.with(
|
|
295
|
-
mcpDaemonRequestContext(request.trace),
|
|
296
|
-
() => callToolRequest(request, socket)
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
async function callToolRequest(request, socket) {
|
|
300
|
-
const controller = new AbortController();
|
|
301
|
-
let dispatched = false;
|
|
302
|
-
active.set(request.id, controller);
|
|
303
|
-
socket.once("close", () => controller.abort());
|
|
304
|
-
try {
|
|
305
|
-
const cachedCatalog = catalogPreloadResult?.find(
|
|
306
|
-
(server2) => server2.id === request.server && !server2.error && server2.tools.some((tool) => tool.name === request.tool)
|
|
307
|
-
);
|
|
308
|
-
const catalogs = cachedCatalog ? catalogPreloadResult : await preloadCatalogs(request.timeoutMs);
|
|
309
|
-
const catalog = cachedCatalog ?? catalogs.find((server2) => server2.id === request.server);
|
|
310
|
-
const allowed = catalog?.tools.some((tool) => tool.name === request.tool);
|
|
311
|
-
if (!catalog || catalog.error || !allowed) {
|
|
312
|
-
throw new Error(
|
|
313
|
-
`MCP tool '${request.server}.${request.tool}' is not authorized in this daemon generation.`
|
|
314
|
-
);
|
|
315
|
-
}
|
|
316
|
-
if (controller.signal.aborted) {
|
|
317
|
-
throw new Error(
|
|
318
|
-
`MCP tool call '${request.server}.${request.tool}' was cancelled before execution.`
|
|
319
|
-
);
|
|
320
|
-
}
|
|
321
|
-
const result = await runtime().then((value) => {
|
|
322
|
-
dispatched = true;
|
|
323
|
-
return value.callTool(request.server, request.tool, {
|
|
324
|
-
args: request.arguments,
|
|
325
|
-
timeoutMs: request.timeoutMs,
|
|
326
|
-
disableOAuth: true,
|
|
327
|
-
signal: controller.signal
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
if (controller.signal.aborted) {
|
|
331
|
-
throw new Error(
|
|
332
|
-
`MCP tool call '${request.server}.${request.tool}' was cancelled; remote outcome is unknown.`
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
send(
|
|
336
|
-
socket,
|
|
337
|
-
{ id: request.id, result },
|
|
338
|
-
`MCP tool call '${request.server}.${request.tool}' completed but its response could not be returned; remote outcome is unknown; do not retry automatically.`
|
|
339
|
-
);
|
|
340
|
-
} catch (error) {
|
|
341
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
342
|
-
send(socket, {
|
|
343
|
-
id: request.id,
|
|
344
|
-
error: dispatched && !message.includes("do not retry automatically") ? `${message}; remote outcome is unknown; do not retry automatically.` : message
|
|
345
|
-
});
|
|
346
|
-
} finally {
|
|
347
|
-
active.delete(request.id);
|
|
348
|
-
socket.end();
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
async function shutdown() {
|
|
352
|
-
if (stopping) return;
|
|
353
|
-
stopping = true;
|
|
354
|
-
for (const controller of active.values()) controller.abort();
|
|
355
|
-
server.close();
|
|
356
|
-
if (runtimePromise) {
|
|
357
|
-
await Promise.race([
|
|
358
|
-
runtimePromise.then((value) => value.close()).catch(() => {
|
|
359
|
-
}),
|
|
360
|
-
new Promise((resolve) => {
|
|
361
|
-
const timer = setTimeout(resolve, SHUTDOWN_GRACE_MS);
|
|
362
|
-
timer.unref();
|
|
363
|
-
})
|
|
364
|
-
]);
|
|
365
|
-
}
|
|
366
|
-
restoreIo();
|
|
367
|
-
if (process.platform !== "win32") await rm(socketPath, { force: true });
|
|
368
|
-
}
|
|
369
|
-
function handle(request, socket) {
|
|
370
|
-
if (request.token !== token) {
|
|
371
|
-
send(socket, { id: request.id, error: "unauthorized" });
|
|
372
|
-
socket.end();
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
if (request.type === "ping") {
|
|
376
|
-
if (stopping) {
|
|
377
|
-
send(socket, { id: request.id, error: "daemon_unavailable" });
|
|
378
|
-
} else if (request.fingerprint !== fingerprint) {
|
|
379
|
-
send(socket, { id: request.id, error: "configuration_mismatch" });
|
|
380
|
-
} else {
|
|
381
|
-
send(socket, { id: request.id, ready: true, fingerprint });
|
|
382
|
-
}
|
|
383
|
-
socket.end();
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
if ((request.type === "execute" || request.type === "call") && active.has(request.id)) {
|
|
387
|
-
send(socket, { id: request.id, error: "duplicate_request_id" });
|
|
388
|
-
socket.end();
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
if (request.type === "cancel") {
|
|
392
|
-
active.get(request.requestId)?.abort();
|
|
393
|
-
send(socket, { id: request.id, exitCode: 0 });
|
|
394
|
-
socket.end();
|
|
395
|
-
return;
|
|
396
|
-
}
|
|
397
|
-
if (request.type === "stop") {
|
|
398
|
-
send(socket, { id: request.id, exitCode: 0 });
|
|
399
|
-
socket.end(() => void shutdown().then(() => process.exit(0)));
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
if (stopping || request.fingerprint !== fingerprint) {
|
|
403
|
-
send(socket, { id: request.id, error: "daemon_unavailable" });
|
|
404
|
-
socket.end();
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
if (request.type === "catalog") {
|
|
408
|
-
const catalogs = request.allowPartial ? runtime().then((value) => discoverMcpCatalogs(value, request.timeoutMs)).then((result) => {
|
|
409
|
-
catalogPreloadResult = result;
|
|
410
|
-
if (!catalogHealthy(result)) {
|
|
411
|
-
void preloadCatalogs(request.timeoutMs).catch(() => {
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
return result;
|
|
415
|
-
}) : preloadCatalogs(request.timeoutMs);
|
|
416
|
-
void catalogs.then(
|
|
417
|
-
(catalogs2) => send(socket, { id: request.id, catalogs: catalogs2 }),
|
|
418
|
-
(error) => send(socket, {
|
|
419
|
-
id: request.id,
|
|
420
|
-
error: error instanceof Error ? error.message : String(error)
|
|
421
|
-
})
|
|
422
|
-
).finally(() => socket.end());
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
if (request.type === "call") {
|
|
426
|
-
void callTool(request, socket);
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
void execute(request, socket);
|
|
430
|
-
}
|
|
431
|
-
var server = createServer((socket) => {
|
|
432
|
-
socket.on("error", () => {
|
|
433
|
-
});
|
|
434
|
-
socket.setEncoding("utf8");
|
|
435
|
-
let buffer = "";
|
|
436
|
-
socket.on("data", (chunk) => {
|
|
437
|
-
buffer += chunk;
|
|
438
|
-
const newline = buffer.indexOf("\n");
|
|
439
|
-
if (newline < 0 && Buffer.byteLength(buffer, "utf8") > MCP_DAEMON_MAX_FRAME_BYTES) {
|
|
440
|
-
send(socket, { id: "unknown", error: "request_too_large" });
|
|
441
|
-
socket.end();
|
|
442
|
-
return;
|
|
443
|
-
}
|
|
444
|
-
if (newline < 0) return;
|
|
445
|
-
const line = buffer.slice(0, newline);
|
|
446
|
-
buffer = buffer.slice(newline + 1);
|
|
447
|
-
if (Buffer.byteLength(line, "utf8") > MCP_DAEMON_MAX_FRAME_BYTES) {
|
|
448
|
-
send(socket, { id: "unknown", error: "request_too_large" });
|
|
449
|
-
socket.end();
|
|
450
|
-
return;
|
|
451
|
-
}
|
|
452
|
-
try {
|
|
453
|
-
handle(JSON.parse(line), socket);
|
|
454
|
-
} catch {
|
|
455
|
-
send(socket, { id: "unknown", error: "invalid_request" });
|
|
456
|
-
socket.end();
|
|
457
|
-
}
|
|
458
|
-
});
|
|
459
|
-
});
|
|
460
|
-
if (process.platform !== "win32") await rm(socketPath, { force: true });
|
|
461
|
-
await new Promise((resolve, reject) => {
|
|
462
|
-
server.once("error", reject);
|
|
463
|
-
server.listen(socketPath, () => {
|
|
464
|
-
server.off("error", reject);
|
|
465
|
-
resolve();
|
|
466
|
-
});
|
|
467
|
-
});
|
|
468
|
-
void runtime().catch(() => {
|
|
58
|
+
var server = await startMcpDaemonServer({
|
|
59
|
+
socketPath,
|
|
60
|
+
token,
|
|
61
|
+
fingerprint,
|
|
62
|
+
env: process.env,
|
|
63
|
+
runWorkerPath: runWorkerPath(),
|
|
64
|
+
onStop: () => process.exit(0)
|
|
469
65
|
});
|
|
66
|
+
var exit = () => void server.close().then(() => process.exit(0));
|
|
470
67
|
var ownerPid = Number(process.env[MCP_DAEMON_PARENT_PID_ENV]);
|
|
471
68
|
if (Number.isSafeInteger(ownerPid) && ownerPid > 0) {
|
|
472
69
|
const ownerWatch = setInterval(() => {
|
|
@@ -475,12 +72,12 @@ if (Number.isSafeInteger(ownerPid) && ownerPid > 0) {
|
|
|
475
72
|
} catch (error) {
|
|
476
73
|
if (error.code === "ESRCH") {
|
|
477
74
|
clearInterval(ownerWatch);
|
|
478
|
-
|
|
75
|
+
exit();
|
|
479
76
|
}
|
|
480
77
|
}
|
|
481
78
|
}, 1e3);
|
|
482
79
|
ownerWatch.unref();
|
|
483
80
|
}
|
|
484
|
-
process.once("SIGINT",
|
|
485
|
-
process.once("SIGTERM",
|
|
486
|
-
process.once("SIGQUIT",
|
|
81
|
+
process.once("SIGINT", exit);
|
|
82
|
+
process.once("SIGTERM", exit);
|
|
83
|
+
process.once("SIGQUIT", exit);
|
package/dist/mcp-run-worker.js
CHANGED
|
@@ -2,15 +2,15 @@ import { createRequire as __createRequire } from "node:module"; const require =
|
|
|
2
2
|
import {
|
|
3
3
|
executeMcpCommand,
|
|
4
4
|
installMcpCommandIoRouting
|
|
5
|
-
} from "./mcp-chunks/chunk-
|
|
6
|
-
import "./mcp-chunks/chunk-
|
|
7
|
-
import "./mcp-chunks/chunk-
|
|
5
|
+
} from "./mcp-chunks/chunk-D6OGGMWS.js";
|
|
6
|
+
import "./mcp-chunks/chunk-TUPFPO4L.js";
|
|
7
|
+
import "./mcp-chunks/chunk-757ZF552.js";
|
|
8
8
|
import "./mcp-chunks/chunk-HNQSUT44.js";
|
|
9
|
-
import "./mcp-chunks/chunk-
|
|
9
|
+
import "./mcp-chunks/chunk-OIK5AH2S.js";
|
|
10
|
+
import "./mcp-chunks/chunk-MYAMG6VL.js";
|
|
11
|
+
import "./mcp-chunks/chunk-OWGTNJNR.js";
|
|
10
12
|
import "./mcp-chunks/chunk-3SXP4S2A.js";
|
|
11
|
-
import "./mcp-chunks/chunk-
|
|
12
|
-
import "./mcp-chunks/chunk-IMG2JMBS.js";
|
|
13
|
-
import "./mcp-chunks/chunk-36D4FILJ.js";
|
|
13
|
+
import "./mcp-chunks/chunk-ORJND4AI.js";
|
|
14
14
|
import "./mcp-chunks/chunk-2AKSS7WR.js";
|
|
15
15
|
import "./mcp-chunks/chunk-6P3KAQ5N.js";
|
|
16
16
|
import "./mcp-chunks/chunk-F2X4Y2TQ.js";
|
|
@@ -25,13 +25,14 @@ import "./mcp-chunks/chunk-7U5NSQ5T.js";
|
|
|
25
25
|
import "./mcp-chunks/chunk-3LENTPGE.js";
|
|
26
26
|
import "./mcp-chunks/chunk-JEHI2YU4.js";
|
|
27
27
|
import "./mcp-chunks/chunk-IWCVZ46B.js";
|
|
28
|
+
import "./mcp-chunks/chunk-O3RTM5HD.js";
|
|
28
29
|
import "./mcp-chunks/chunk-T4MQCFIK.js";
|
|
29
30
|
import "./mcp-chunks/chunk-BHXCAVFP.js";
|
|
30
|
-
import "./mcp-chunks/chunk-O3RTM5HD.js";
|
|
31
31
|
import "./mcp-chunks/chunk-MHUMLEBO.js";
|
|
32
32
|
import "./mcp-chunks/chunk-IRSL7JRH.js";
|
|
33
33
|
import "./mcp-chunks/chunk-UVRJ3AAD.js";
|
|
34
34
|
import "./mcp-chunks/chunk-O7SIXJM6.js";
|
|
35
|
+
import "./mcp-chunks/chunk-B6S43WID.js";
|
|
35
36
|
import "./mcp-chunks/chunk-LRKZP7DJ.js";
|
|
36
37
|
|
|
37
38
|
// src/mcp/cli/run-worker.ts
|
package/dist/open.d.ts
CHANGED
|
@@ -45,6 +45,11 @@ export type IntrospectionOpenTarget =
|
|
|
45
45
|
kind: "task";
|
|
46
46
|
task: string;
|
|
47
47
|
}
|
|
48
|
+
/** An Introspection issue: its handle as the issues tool returned it (`introspection:I-7`) or its id. */
|
|
49
|
+
| {
|
|
50
|
+
kind: "issue";
|
|
51
|
+
issue: string;
|
|
52
|
+
}
|
|
48
53
|
/** A new repository the person creates on GitHub, registered once the App reaches it. */
|
|
49
54
|
| {
|
|
50
55
|
kind: "repository";
|
|
@@ -58,19 +63,21 @@ export declare const INTROSPECTION_OPEN_TARGET_KINDS: readonly IntrospectionOpen
|
|
|
58
63
|
export declare const INTROSPECTION_OPEN_ANSWER: {
|
|
59
64
|
/** The person finished the connection. */
|
|
60
65
|
readonly connected: "connected";
|
|
61
|
-
/** The person came back from a page with nothing to connect (`runtime`, `task`). */
|
|
66
|
+
/** The person came back from a page with nothing to connect (`runtime`, `task`, `issue`). */
|
|
62
67
|
readonly returned: "returned";
|
|
63
68
|
};
|
|
64
69
|
/** `failed: <error>`, the answer for a flow the provider ended with an error. */
|
|
65
70
|
export declare function introspectionOpenFailed(error: string): string;
|
|
66
71
|
/**
|
|
67
|
-
* Whether opening the target is the whole action: a `runtime` or `
|
|
72
|
+
* Whether opening the target is the whole action: a `runtime`, `task` or `issue` page,
|
|
68
73
|
* where the person has nothing to finish. Hosts answer `returned` as soon as it
|
|
69
74
|
* opens instead of waiting for the person to come back.
|
|
70
75
|
*/
|
|
71
76
|
export declare function introspectionOpenIsPage(target: IntrospectionOpenTarget): boolean;
|
|
72
77
|
/** The answer for a target the person completed: `returned` for a page, `connected` otherwise. */
|
|
73
78
|
export declare function introspectionOpenDone(target: IntrospectionOpenTarget): string;
|
|
79
|
+
/** The provider an issue handle names (`linear` in `linear:ENG-1`), or null for a bare id. */
|
|
80
|
+
export declare function issueHandleProvider(issue: string): string | null;
|
|
74
81
|
/**
|
|
75
82
|
* A target read back from untrusted input (a tool call's arguments, an
|
|
76
83
|
* interrupt's metadata), or null when it isn't one. Only the fields its kind
|
package/dist/open.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"open.d.ts","sourceRoot":"","sources":["../src/open.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,eAAO,MAAM,4BAA4B,uBAAuB,CAAC;AAEjE,+EAA+E;AAC/E,MAAM,MAAM,uBAAuB;AACjC,kDAAkD;AAChD;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE;AAC3C,+DAA+D;GAC7D;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE;AACzC,8EAA8E;GAC5E;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE;AAC1C,gEAAgE;GAC9D;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE;AACnC,uCAAuC;GACrC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE;AAC1E,wBAAwB;GACtB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE;AACtC,qBAAqB;GACnB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE;AAChC,yFAAyF;GACvF;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhF,MAAM,MAAM,2BAA2B,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC;AAE1E,eAAO,MAAM,+BAA+B,EAAE,SAAS,2BAA2B,
|
|
1
|
+
{"version":3,"file":"open.d.ts","sourceRoot":"","sources":["../src/open.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,eAAO,MAAM,4BAA4B,uBAAuB,CAAC;AAEjE,+EAA+E;AAC/E,MAAM,MAAM,uBAAuB;AACjC,kDAAkD;AAChD;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE;AAC3C,+DAA+D;GAC7D;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE;AACzC,8EAA8E;GAC5E;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE;AAC1C,gEAAgE;GAC9D;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE;AACnC,uCAAuC;GACrC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE;AAC1E,wBAAwB;GACtB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE;AACtC,qBAAqB;GACnB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE;AAChC,yGAAyG;GACvG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE;AAClC,yFAAyF;GACvF;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhF,MAAM,MAAM,2BAA2B,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC;AAE1E,eAAO,MAAM,+BAA+B,EAAE,SAAS,2BAA2B,EAW/E,CAAC;AAEJ,8FAA8F;AAC9F,eAAO,MAAM,yBAAyB;IACpC,0CAA0C;aAC1C,SAAS,EAAE,WAAW;IACtB,6FAA6F;aAC7F,QAAQ,EAAE,UAAU;CACZ,CAAC;AAEX,iFAAiF;AACjF,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAG7D;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAMT;AAED,kGAAkG;AAClG,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,uBAAuB,GAAG,MAAM,CAI7E;AAiBD,8FAA8F;AAC9F,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGhE;AAUD;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,OAAO,GACb,uBAAuB,GAAG,IAAI,CAqDhC;AAED,6FAA6F;AAC7F,wBAAgB,yBAAyB,CAAC,SAAS,EAAE;IACnD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,GAAG,uBAAuB,GAAG,IAAI,CAIjC;AAgBD,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAQrD;AAED,2FAA2F;AAC3F,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,uBAAuB,GAC9B,MAAM,CAqBR"}
|
package/dist/open.js
CHANGED
|
@@ -14,13 +14,14 @@ export const INTROSPECTION_OPEN_TARGET_KINDS = [
|
|
|
14
14
|
"binding",
|
|
15
15
|
"runtime",
|
|
16
16
|
"task",
|
|
17
|
+
"issue",
|
|
17
18
|
"repository",
|
|
18
19
|
];
|
|
19
20
|
/** The answers a host resumes an `introspection_open` interrupt with, as `payload.answer`. */
|
|
20
21
|
export const INTROSPECTION_OPEN_ANSWER = {
|
|
21
22
|
/** The person finished the connection. */
|
|
22
23
|
connected: "connected",
|
|
23
|
-
/** The person came back from a page with nothing to connect (`runtime`, `task`). */
|
|
24
|
+
/** The person came back from a page with nothing to connect (`runtime`, `task`, `issue`). */
|
|
24
25
|
returned: "returned",
|
|
25
26
|
};
|
|
26
27
|
/** `failed: <error>`, the answer for a flow the provider ended with an error. */
|
|
@@ -29,12 +30,14 @@ export function introspectionOpenFailed(error) {
|
|
|
29
30
|
return `failed: ${reason || "unknown error"}`;
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
|
-
* Whether opening the target is the whole action: a `runtime` or `
|
|
33
|
+
* Whether opening the target is the whole action: a `runtime`, `task` or `issue` page,
|
|
33
34
|
* where the person has nothing to finish. Hosts answer `returned` as soon as it
|
|
34
35
|
* opens instead of waiting for the person to come back.
|
|
35
36
|
*/
|
|
36
37
|
export function introspectionOpenIsPage(target) {
|
|
37
|
-
return target.kind === "runtime" ||
|
|
38
|
+
return (target.kind === "runtime" ||
|
|
39
|
+
target.kind === "task" ||
|
|
40
|
+
target.kind === "issue");
|
|
38
41
|
}
|
|
39
42
|
/** The answer for a target the person completed: `returned` for a page, `connected` otherwise. */
|
|
40
43
|
export function introspectionOpenDone(target) {
|
|
@@ -50,6 +53,23 @@ function record(value) {
|
|
|
50
53
|
function text(value) {
|
|
51
54
|
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
52
55
|
}
|
|
56
|
+
const ISSUE_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
57
|
+
/** What follows `introspection:` in a handle: the project's key (`I-7`), its number, or the issue id. */
|
|
58
|
+
const ISSUE_REF = /^(?:[a-z]{1,5}-\d+|\d+)$/i;
|
|
59
|
+
/** The provider an issue handle names (`linear` in `linear:ENG-1`), or null for a bare id. */
|
|
60
|
+
export function issueHandleProvider(issue) {
|
|
61
|
+
const colon = issue.indexOf(":");
|
|
62
|
+
return colon > 0 ? issue.slice(0, colon).trim().toLowerCase() : null;
|
|
63
|
+
}
|
|
64
|
+
/** Whether `issue` names an Introspection issue: `introspection:<key, number or id>`, or a bare id. */
|
|
65
|
+
function isIntrospectionIssue(issue) {
|
|
66
|
+
if (ISSUE_ID.test(issue))
|
|
67
|
+
return true;
|
|
68
|
+
if (issueHandleProvider(issue) !== "introspection")
|
|
69
|
+
return false;
|
|
70
|
+
const ref = issue.slice(issue.indexOf(":") + 1).trim();
|
|
71
|
+
return ISSUE_REF.test(ref) || ISSUE_ID.test(ref);
|
|
72
|
+
}
|
|
53
73
|
/**
|
|
54
74
|
* A target read back from untrusted input (a tool call's arguments, an
|
|
55
75
|
* interrupt's metadata), or null when it isn't one. Only the fields its kind
|
|
@@ -88,6 +108,12 @@ export function parseIntrospectionOpenTarget(value) {
|
|
|
88
108
|
const task = text(raw.task);
|
|
89
109
|
return task ? { kind: "task", task } : null;
|
|
90
110
|
}
|
|
111
|
+
case "issue": {
|
|
112
|
+
const issue = text(raw.issue);
|
|
113
|
+
return issue && isIntrospectionIssue(issue)
|
|
114
|
+
? { kind: "issue", issue }
|
|
115
|
+
: null;
|
|
116
|
+
}
|
|
91
117
|
case "repository": {
|
|
92
118
|
const name = text(raw.name);
|
|
93
119
|
const template = text(raw.template);
|
|
@@ -153,6 +179,8 @@ export function introspectionOpenAction(target) {
|
|
|
153
179
|
return "Open the runtime";
|
|
154
180
|
case "task":
|
|
155
181
|
return "Open the task";
|
|
182
|
+
case "issue":
|
|
183
|
+
return "Open the issue";
|
|
156
184
|
case "repository":
|
|
157
185
|
return `Create ${target.name} on GitHub`;
|
|
158
186
|
}
|