skillar 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +280 -0
- package/README.md +37 -5
- package/dist/analysis/finding.js +8 -190
- package/dist/analysis/kernel.js +896 -0
- package/dist/analysis/tree.js +7 -154
- package/dist/analysis/usage.js +9 -394
- package/dist/api/flows.js +42 -212
- package/dist/api/report-kernel.js +1063 -0
- package/dist/api/routes.js +12 -2
- package/dist/catalog/fields.js +138 -146
- package/dist/catalog/watcher.js +7 -2
- package/dist/cli/init.js +45 -0
- package/dist/cli/main.js +76 -3
- package/dist/cli/private-skills.js +122 -0
- package/dist/cli/serve.js +15 -1
- package/dist/cli/sync.js +124 -0
- package/dist/dashboard/NOTICE +280 -0
- package/dist/dashboard/assets/app.js +737 -275
- package/dist/dashboard/assets/astryx-reset.css +407 -0
- package/dist/dashboard/assets/astryx.css +1077 -0
- package/dist/dashboard/assets/charts.css +54 -0
- package/dist/dashboard/assets/chunk-TPGDA2J4.js +1 -0
- package/dist/dashboard/assets/chunk-YLWHVDMP.js +36 -0
- package/dist/dashboard/assets/controls.css +207 -0
- package/dist/dashboard/assets/overlays.css +132 -0
- package/dist/dashboard/assets/p1.css +135 -0
- package/dist/dashboard/assets/shell.css +71 -0
- package/dist/dashboard/assets/skillar-theme.css +692 -0
- package/dist/dashboard/assets/styles.css +224 -121
- package/dist/dashboard/assets/tokens.css +278 -0
- package/dist/dashboard/assets/widgets.css +83 -0
- package/dist/dashboard/index.html +11 -2
- package/dist/dashboard/viewers/viewers.css +61 -0
- package/dist/ingest/attribution.js +5 -1
- package/dist/ingest/pipeline.js +2 -0
- package/dist/ingest/request-recorder.js +39 -0
- package/dist/mcp/dispatch.js +2 -2
- package/dist/mcp/http.js +43 -3
- package/dist/mcp/skills-extension.js +42 -15
- package/dist/mcp/stdio-proxy.js +24 -3
- package/dist/mcp/tools.js +38 -24
- package/dist/packs/claude-code.js +22 -11
- package/dist/packs/cursor.js +9 -4
- package/dist/packs/gemini.js +9 -4
- package/dist/packs/json-config.js +41 -0
- package/dist/packs/omo.js +15 -6
- package/dist/request-status.js +81 -0
- package/dist/search/fts.js +93 -58
- package/dist/search/fusion.js +49 -47
- package/dist/search/guidance.js +18 -6
- package/dist/search/index.js +291 -70
- package/dist/search/lexical.js +71 -63
- package/dist/server.js +12 -0
- package/dist/skills/apply.js +130 -0
- package/dist/skills/capture.js +54 -0
- package/dist/skills/cloud-plan.js +57 -0
- package/dist/skills/cloud.js +81 -0
- package/dist/skills/fs.js +133 -0
- package/dist/skills/package.js +734 -0
- package/dist/skills/plan.js +83 -0
- package/dist/skills/receipt.js +44 -0
- package/dist/skills/rollback.js +119 -0
- package/dist/skills/transfer.js +51 -0
- package/dist/store/db.js +7 -1
- package/dist/store/execution.js +2 -34
- package/dist/store/export.js +25 -4
- package/dist/store/migrations/007_sync.sql +49 -0
- package/dist/store/migrations/008_connector_commands.sql +12 -0
- package/dist/store/queries.js +33 -7
- package/dist/store/writes.js +38 -5
- package/dist/sync/cloud-blobs.js +175 -0
- package/dist/sync/cloud-commands.js +101 -0
- package/dist/sync/cloud-connection.js +105 -0
- package/dist/sync/cloud-delivery.js +114 -0
- package/dist/sync/cloud-documents.js +103 -0
- package/dist/sync/cloud-export.js +67 -0
- package/dist/sync/cloud-http.js +150 -0
- package/dist/sync/cloud-jobs.js +94 -0
- package/dist/sync/cloud-pending.js +143 -0
- package/dist/sync/cloud-prepare.js +101 -0
- package/dist/sync/cloud-restore.js +136 -0
- package/dist/sync/cloud-rollback.js +24 -0
- package/dist/sync/cloud-runner.js +86 -0
- package/dist/sync/cloud-runtime.js +293 -0
- package/dist/sync/cloud-schema.js +32 -0
- package/dist/sync/cloud-stage.js +112 -0
- package/dist/sync/cloud-wire.js +693 -0
- package/dist/sync/cloud-worker.js +57 -0
- package/dist/sync/cloud.js +157 -0
- package/dist/sync/command-apply.js +140 -0
- package/dist/sync/command-control.js +25 -0
- package/dist/sync/command-wire.js +437 -0
- package/dist/sync/consent.js +130 -0
- package/dist/sync/journal.js +43 -0
- package/dist/sync/outbox.js +134 -0
- package/dist/sync/restore-rows.js +125 -0
- package/dist/sync/restore.js +174 -0
- package/dist/sync/snapshot.js +78 -0
- package/dist/sync/spool-request.js +103 -0
- package/dist/sync/tables.js +27 -0
- package/dist/sync/triggers.js +34 -0
- package/dist/workflow/compare.js +3 -43
- package/docs/cloud-sync.md +94 -0
- package/docs/private-skills.md +75 -0
- package/docs/sync-p4.md +102 -0
- package/docs/sync-restore.md +167 -0
- package/package.json +18 -5
- package/src/store/migrations/007_sync.sql +49 -0
- package/src/store/migrations/008_connector_commands.sql +12 -0
- package/dist/dashboard/assets/chunk-5DFWNJC2.js +0 -1
- package/dist/dashboard/assets/chunk-S6B2HJQA.js +0 -17
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { activeRequests } from "../request-status.js";
|
|
3
|
+
import { mcpBase } from "./mcp-recorder.js";
|
|
4
|
+
import { makeEvent } from "./hooks.js";
|
|
5
|
+
import { ingest } from "./pipeline.js";
|
|
6
|
+
/** Request IDs correlate start, terminal outcome, and the existing detailed observations. */
|
|
7
|
+
export function beginRequest(deps, ctx, operation, uri) {
|
|
8
|
+
const requestId = randomUUID();
|
|
9
|
+
const startedAt = deps.now?.() ?? Date.now();
|
|
10
|
+
const base = mcpBase(ctx);
|
|
11
|
+
const traceId = ctx.meta?.["app.skillar/traceId"] ?? ctx.meta?.["app.gisool/traceId"];
|
|
12
|
+
let finished = false;
|
|
13
|
+
const record = (status, detail = {}) => {
|
|
14
|
+
const event = makeEvent("skill_request", "mcp", base.ref, deps.now?.() ?? Date.now(), {
|
|
15
|
+
...(base.toolUseId ? { toolUseId: base.toolUseId } : {}),
|
|
16
|
+
...(typeof traceId === "string" ? { traceId } : {}), ...(uri ? { skillUri: uri } : {}),
|
|
17
|
+
data: { ...base.data, requestId, operation, status, startedAt, ...(uri ? { uri } : {}), ...detail },
|
|
18
|
+
});
|
|
19
|
+
ingest(event, deps);
|
|
20
|
+
};
|
|
21
|
+
activeRequests.add(requestId);
|
|
22
|
+
record("in_progress");
|
|
23
|
+
const attempt = {
|
|
24
|
+
requestId,
|
|
25
|
+
finish(status, detail = {}) {
|
|
26
|
+
if (finished)
|
|
27
|
+
return;
|
|
28
|
+
finished = true;
|
|
29
|
+
ctx.signal?.removeEventListener("abort", onCancel);
|
|
30
|
+
activeRequests.delete(requestId);
|
|
31
|
+
record(status, detail);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const onCancel = () => attempt.finish("cancelled");
|
|
35
|
+
ctx.signal?.addEventListener("abort", onCancel, { once: true });
|
|
36
|
+
if (ctx.signal?.aborted)
|
|
37
|
+
onCancel();
|
|
38
|
+
return attempt;
|
|
39
|
+
}
|
package/dist/mcp/dispatch.js
CHANGED
|
@@ -9,9 +9,9 @@ const toolParams = z.object({ name: z.string(), arguments: z.record(z.string(),
|
|
|
9
9
|
export function createDispatcher(deps) {
|
|
10
10
|
const search = createSearchTool(deps);
|
|
11
11
|
const serverInfo = { name: "skillar", version: packageVersion() };
|
|
12
|
-
return async (request, params) => {
|
|
12
|
+
return async (request, params, signal) => {
|
|
13
13
|
const clientInfo = params._meta[CLIENT_INFO_KEY];
|
|
14
|
-
const ctx = { ...(clientInfo ? { clientName: clientInfo.name } : {}), meta: params._meta };
|
|
14
|
+
const ctx = { signal, ...(clientInfo ? { clientName: clientInfo.name } : {}), meta: params._meta };
|
|
15
15
|
let result;
|
|
16
16
|
switch (request.method) {
|
|
17
17
|
case "server/discover":
|
package/dist/mcp/http.js
CHANGED
|
@@ -13,6 +13,33 @@ const MAX_LEGACY_SESSIONS = 1024;
|
|
|
13
13
|
export function registerMcp(app, deps) {
|
|
14
14
|
const dispatch = createDispatcher(deps);
|
|
15
15
|
const sessions = new Map();
|
|
16
|
+
const running = new Map();
|
|
17
|
+
// A JSON-RPC ID is only unique within a caller. Anonymous HTTP requests cannot cancel
|
|
18
|
+
// each other; a runtime identity or established legacy transport session is required.
|
|
19
|
+
const requestKey = (message, params, req, id = message.id) => {
|
|
20
|
+
const legacyId = req.header("Mcp-Session-Id");
|
|
21
|
+
const stdioId = req.header("X-Skillar-Stdio-Session");
|
|
22
|
+
const meta = params._meta;
|
|
23
|
+
const runtimeId = meta.sessionId ?? meta.threadId ?? meta["ai.opencode/sessionID"];
|
|
24
|
+
const scope = stdioId ? ["stdio", stdioId] : legacyId && sessions.has(legacyId) ? ["legacy", legacyId]
|
|
25
|
+
: typeof runtimeId === "string" && runtimeId ? ["runtime", meta["io.modelcontextprotocol/clientInfo"]?.name ?? "unknown", runtimeId] : undefined;
|
|
26
|
+
return scope && id !== undefined ? JSON.stringify([scope, id]) : undefined;
|
|
27
|
+
};
|
|
28
|
+
const trackedDispatch = async (message, params, req) => {
|
|
29
|
+
const key = requestKey(message, params, req);
|
|
30
|
+
if (!key)
|
|
31
|
+
return dispatch(message, params);
|
|
32
|
+
if (running.has(key))
|
|
33
|
+
throw new RpcError(-32600, "Request ID is already in flight");
|
|
34
|
+
const controller = new AbortController();
|
|
35
|
+
running.set(key, controller);
|
|
36
|
+
try {
|
|
37
|
+
return await dispatch(message, params, controller.signal);
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
running.delete(key);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
16
43
|
const legacy = async (message, req, res) => {
|
|
17
44
|
try {
|
|
18
45
|
let result;
|
|
@@ -33,7 +60,7 @@ export function registerMcp(app, deps) {
|
|
|
33
60
|
const local = legacyLocalResult(message.method);
|
|
34
61
|
const sessionId = req.header("Mcp-Session-Id");
|
|
35
62
|
const modern = toModernMessage(message, sessionId ? sessions.get(sessionId) : undefined);
|
|
36
|
-
result = local ?? toLegacyResult(await
|
|
63
|
+
result = local ?? toLegacyResult(await trackedDispatch(modern, parseParams(modern), req));
|
|
37
64
|
}
|
|
38
65
|
if (!res.destroyed)
|
|
39
66
|
res.json({ jsonrpc: "2.0", id: message.id, result });
|
|
@@ -59,7 +86,20 @@ export function registerMcp(app, deps) {
|
|
|
59
86
|
}
|
|
60
87
|
const message = parsed.data;
|
|
61
88
|
if (message.id === undefined) {
|
|
62
|
-
|
|
89
|
+
if (message.method === "notifications/cancelled") {
|
|
90
|
+
try {
|
|
91
|
+
const legacyId = req.header("Mcp-Session-Id");
|
|
92
|
+
const modern = toModernMessage(message, legacyId ? sessions.get(legacyId) : undefined);
|
|
93
|
+
const params = parseParams(modern);
|
|
94
|
+
const id = params.requestId;
|
|
95
|
+
if (typeof id === "string" || typeof id === "number") {
|
|
96
|
+
const key = requestKey(modern, params, req, id);
|
|
97
|
+
if (key)
|
|
98
|
+
running.get(key)?.abort(new DOMException("Explicit client cancellation", "AbortError"));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch { /* Invalid notifications have no response body and cannot cancel a request. */ }
|
|
102
|
+
}
|
|
63
103
|
res.status(202).end();
|
|
64
104
|
return;
|
|
65
105
|
}
|
|
@@ -80,7 +120,7 @@ export function registerMcp(app, deps) {
|
|
|
80
120
|
res.status(406).json(errorResponse(message.id, new RpcError(-32600, "Accept must include application/json and text/event-stream")));
|
|
81
121
|
return;
|
|
82
122
|
}
|
|
83
|
-
const result = await
|
|
123
|
+
const result = await trackedDispatch(message, params, req);
|
|
84
124
|
if (!res.destroyed)
|
|
85
125
|
res.json({ jsonrpc: "2.0", id: message.id, result });
|
|
86
126
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { beginRequest } from "../ingest/request-recorder.js";
|
|
1
2
|
import { randomUUID } from "node:crypto";
|
|
2
3
|
import { CatalogError } from "../catalog/index.js";
|
|
3
4
|
import { errorEvent, loadEvent, readFileEvent } from "../ingest/mcp-recorder.js";
|
|
@@ -47,31 +48,57 @@ export async function readResource(deps, uri, ctx) {
|
|
|
47
48
|
const now = () => deps.ingest.now?.() ?? Date.now();
|
|
48
49
|
const trace = ctx.meta?.[TRACE_KEY] ?? ctx.meta?.["app.gisool/traceId"];
|
|
49
50
|
const ids = typeof trace === "string" ? { traceId: trace } : {};
|
|
51
|
+
// Only the skill entry document is a load; supporting resources have their own read events.
|
|
52
|
+
const knownSupportingFile = deps.catalog.list().some((skill) => skill.uri !== uri && skill.resources.some((resource) => resource.uri === uri));
|
|
53
|
+
const isSkill = Boolean(deps.catalog.get(uri)) || uri.endsWith("/SKILL.md") && !knownSupportingFile;
|
|
54
|
+
const attempt = isSkill ? beginRequest(deps.ingest, ctx, "load", uri) : undefined;
|
|
50
55
|
let file;
|
|
51
56
|
try {
|
|
57
|
+
ctx.signal?.throwIfAborted();
|
|
52
58
|
file = await deps.catalog.readResource(uri);
|
|
59
|
+
ctx.signal?.throwIfAborted();
|
|
53
60
|
}
|
|
54
61
|
catch (error) {
|
|
62
|
+
if (ctx.signal?.aborted) {
|
|
63
|
+
attempt?.finish("cancelled");
|
|
64
|
+
throw new RpcError(-32800, "Request cancelled");
|
|
65
|
+
}
|
|
55
66
|
const code = error instanceof CatalogError && error.code !== "digest_mismatch" ? -32602 : -32603;
|
|
56
67
|
const reason = error instanceof CatalogError ? error.code : "internal_error";
|
|
57
68
|
const message = code === -32602 ? `Resource not found or invalid: ${uri}` : `Resource unavailable; refresh skills/get before retrying: ${uri}`;
|
|
58
|
-
|
|
69
|
+
const event = errorEvent(ctx, { code: reason, message, tool: "resources/read", ...ids, ...(isSkill ? { skillUri: uri } : {}) }, now());
|
|
70
|
+
event.data.uri = uri;
|
|
71
|
+
event.data.resourceKind = isSkill ? "skill" : "supporting_file";
|
|
72
|
+
if (attempt)
|
|
73
|
+
event.data.requestId = attempt.requestId;
|
|
74
|
+
ingest(event, deps.ingest);
|
|
75
|
+
attempt?.finish("failed", { errorCode: reason });
|
|
59
76
|
throw new RpcError(code, message, { reason });
|
|
60
77
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
78
|
+
try {
|
|
79
|
+
const entry = deps.catalog.get(uri);
|
|
80
|
+
if (entry) {
|
|
81
|
+
// IDs identify observations, not content or connections. Two callers never share a load handle.
|
|
82
|
+
const loadId = randomUUID();
|
|
83
|
+
deps.store.putLoad({ loadId, uri, manifestDigest: entry.manifestDigest, resources: entry.resources, ...ids });
|
|
84
|
+
const event = loadEvent(ctx, { uri, loadId, manifestDigest: entry.manifestDigest, ...ids }, now());
|
|
85
|
+
if (attempt)
|
|
86
|
+
event.data.requestId = attempt.requestId;
|
|
87
|
+
ingest(event, deps.ingest);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const owner = deps.catalog.list().filter((skill) => skill.resources.some((r) => r.uri === uri)).sort((a, b) => b.uri.length - a.uri.length)[0];
|
|
91
|
+
if (owner)
|
|
92
|
+
ingest(readFileEvent(ctx, { skillUri: owner.uri, uri, bytes: file.size, ...ids }, now()), deps.ingest);
|
|
93
|
+
}
|
|
94
|
+
const bytes = Buffer.from(file.bytes);
|
|
95
|
+
const text = TEXT_EXTENSIONS.has(extensionOf(uri)) && Buffer.from(file.text, "utf8").equals(bytes);
|
|
96
|
+
const content = text ? { uri, mimeType: mimeOf(uri), text: file.text } : { uri, mimeType: mimeOf(uri), blob: bytes.toString("base64") };
|
|
97
|
+
attempt?.finish("succeeded");
|
|
98
|
+
return { contents: [content], ...CACHE };
|
|
67
99
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
ingest(readFileEvent(ctx, { skillUri: owner.uri, uri, bytes: file.size, ...ids }, now()), deps.ingest);
|
|
100
|
+
catch (error) {
|
|
101
|
+
attempt?.finish("failed", { errorCode: "internal_error" });
|
|
102
|
+
throw error;
|
|
72
103
|
}
|
|
73
|
-
const bytes = Buffer.from(file.bytes);
|
|
74
|
-
const text = TEXT_EXTENSIONS.has(extensionOf(uri)) && Buffer.from(file.text, "utf8").equals(bytes);
|
|
75
|
-
const content = text ? { uri, mimeType: mimeOf(uri), text: file.text } : { uri, mimeType: mimeOf(uri), blob: bytes.toString("base64") };
|
|
76
|
-
return { contents: [content], ...CACHE };
|
|
77
104
|
}
|
package/dist/mcp/stdio-proxy.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createInterface } from "node:readline";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
2
3
|
import { initializeResult, initializeSchema, isLegacyRequest, legacyLocalResult, negotiateVersion, toLegacyResult, toModernMessage } from "./legacy.js";
|
|
3
4
|
import { checkVersion, errorResponse, idSchema, messageId, messageSchema, parseParams, requestHeaders, responseSchema, RpcError, rpcFailure } from "./protocol.js";
|
|
4
5
|
/**
|
|
@@ -9,6 +10,9 @@ export async function runStdioProxy(opts) {
|
|
|
9
10
|
let legacyClient;
|
|
10
11
|
const lines = createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
11
12
|
const pending = new Map();
|
|
13
|
+
const forwarded = new Map();
|
|
14
|
+
// Transport identity scopes cancellation without inventing a runtime session for attribution.
|
|
15
|
+
const transportId = randomUUID();
|
|
12
16
|
const send = (value) => { process.stdout.write(JSON.stringify(value) + "\n"); };
|
|
13
17
|
let closing = false;
|
|
14
18
|
const shutdown = () => {
|
|
@@ -16,6 +20,7 @@ export async function runStdioProxy(opts) {
|
|
|
16
20
|
for (const controller of pending.values())
|
|
17
21
|
controller.abort();
|
|
18
22
|
pending.clear();
|
|
23
|
+
forwarded.clear();
|
|
19
24
|
lines.close();
|
|
20
25
|
process.stdin.pause();
|
|
21
26
|
};
|
|
@@ -37,8 +42,21 @@ export async function runStdioProxy(opts) {
|
|
|
37
42
|
if (message.id === undefined) {
|
|
38
43
|
if (message.method === "notifications/cancelled" && typeof message.params === "object" && message.params !== null && "requestId" in message.params) {
|
|
39
44
|
const id = idSchema.safeParse(message.params.requestId);
|
|
40
|
-
if (id.success)
|
|
45
|
+
if (id.success) {
|
|
46
|
+
const request = forwarded.get(id.data);
|
|
41
47
|
pending.get(id.data)?.abort();
|
|
48
|
+
if (request) {
|
|
49
|
+
const notification = { ...message, params: { ...message.params, _meta: parseParams(request)._meta } };
|
|
50
|
+
try {
|
|
51
|
+
await fetch(`http://127.0.0.1:${opts.port}/mcp`, {
|
|
52
|
+
method: "POST",
|
|
53
|
+
headers: { ...requestHeaders(notification, parseParams(notification)), Authorization: `Bearer ${opts.token}`, "X-Skillar-Stdio-Session": transportId },
|
|
54
|
+
body: JSON.stringify(notification), signal: AbortSignal.timeout(5000),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch { /* An unreachable daemon provides no evidence of a cancelled request. */ }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
42
60
|
}
|
|
43
61
|
return;
|
|
44
62
|
}
|
|
@@ -46,9 +64,10 @@ export async function runStdioProxy(opts) {
|
|
|
46
64
|
const forward = async (request, signal) => {
|
|
47
65
|
const params = parseParams(request);
|
|
48
66
|
checkVersion(params._meta);
|
|
67
|
+
forwarded.set(request.id, request);
|
|
49
68
|
const response = await fetch(`http://127.0.0.1:${opts.port}/mcp`, {
|
|
50
69
|
method: "POST",
|
|
51
|
-
headers: { ...requestHeaders(request, params), Authorization: `Bearer ${opts.token}
|
|
70
|
+
headers: { ...requestHeaders(request, params), Authorization: `Bearer ${opts.token}`, "X-Skillar-Stdio-Session": transportId },
|
|
52
71
|
body: JSON.stringify(request),
|
|
53
72
|
signal: AbortSignal.any([signal, AbortSignal.timeout(60_000)]),
|
|
54
73
|
});
|
|
@@ -91,8 +110,10 @@ export async function runStdioProxy(opts) {
|
|
|
91
110
|
send(errorResponse(message.id, rpcFailure(error)));
|
|
92
111
|
}
|
|
93
112
|
finally {
|
|
94
|
-
if (controller && pending.get(message.id) === controller)
|
|
113
|
+
if (controller && pending.get(message.id) === controller) {
|
|
95
114
|
pending.delete(message.id);
|
|
115
|
+
forwarded.delete(message.id);
|
|
116
|
+
}
|
|
96
117
|
}
|
|
97
118
|
};
|
|
98
119
|
process.once("SIGTERM", shutdown);
|
package/dist/mcp/tools.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { beginRequest } from "../ingest/request-recorder.js";
|
|
1
2
|
import { readFileSync } from "node:fs";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import { errorEvent, searchEvent } from "../ingest/mcp-recorder.js";
|
|
@@ -29,31 +30,44 @@ export function createSearchTool(deps) {
|
|
|
29
30
|
let windowStart = 0;
|
|
30
31
|
let calls = 0;
|
|
31
32
|
return (args, ctx) => {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
const attempt = beginRequest(deps.ingest, ctx, "search");
|
|
34
|
+
try {
|
|
35
|
+
const now = deps.ingest.now?.() ?? Date.now();
|
|
36
|
+
const parsed = searchSchema.safeParse(args ?? {});
|
|
37
|
+
if (now - windowStart >= 60_000) {
|
|
38
|
+
windowStart = now;
|
|
39
|
+
calls = 0;
|
|
40
|
+
}
|
|
41
|
+
const failure = !parsed.success ? { code: "invalid_arguments", message: parsed.error.message }
|
|
42
|
+
: ++calls > 120 ? { code: "rate_limited", message: "Search limit reached; retry after the current minute" } : undefined;
|
|
43
|
+
if (failure) {
|
|
44
|
+
const error = errorEvent(ctx, { ...failure, tool: "search_skills" }, now);
|
|
45
|
+
error.data.requestId = attempt.requestId;
|
|
46
|
+
ingest(error, deps.ingest);
|
|
47
|
+
attempt.finish("failed", { errorCode: failure.code });
|
|
48
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: failure }) }], isError: true };
|
|
49
|
+
}
|
|
50
|
+
if (!parsed.success)
|
|
51
|
+
throw parsed.error;
|
|
52
|
+
const { query, mode, limit, offset } = parsed.data;
|
|
53
|
+
const all = deps.search.search(query ?? "", { mode, limit: Math.max(1, deps.catalog.list().length) });
|
|
54
|
+
const page = all.candidates.slice(offset, offset + limit);
|
|
55
|
+
const event = searchEvent(ctx, { ...all, candidates: page }, { total: all.candidates.length }, now);
|
|
56
|
+
event.data.requestId = attempt.requestId;
|
|
57
|
+
ingest(event, deps.ingest);
|
|
58
|
+
attempt.finish("succeeded", { total: all.candidates.length, firstCandidateUri: all.candidates[0]?.uri, ...(all.abstained ? { abstained: all.abstained } : {}) });
|
|
59
|
+
const body = {
|
|
60
|
+
trace_id: all.traceId,
|
|
61
|
+
candidates: page.map(({ uri, name, description, score, rank, invocation, digest }) => ({ uri, name, description, score, rank, invocation, digest })),
|
|
62
|
+
...(all.abstained ? { abstained: all.abstained } : {}),
|
|
63
|
+
total: all.candidates.length,
|
|
64
|
+
note: "Search does not activate skills. Read a chosen SKILL.md URI using the host's resource reader on this server.",
|
|
65
|
+
};
|
|
66
|
+
return { content: [{ type: "text", text: JSON.stringify(body) }], structuredContent: body };
|
|
37
67
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
ingest(errorEvent(ctx, { ...failure, tool: "search_skills" }, now), deps.ingest);
|
|
42
|
-
return { content: [{ type: "text", text: JSON.stringify({ error: failure }) }], isError: true };
|
|
68
|
+
catch (error) {
|
|
69
|
+
attempt.finish("failed", { errorCode: "internal_error" });
|
|
70
|
+
throw error;
|
|
43
71
|
}
|
|
44
|
-
if (!parsed.success)
|
|
45
|
-
throw parsed.error;
|
|
46
|
-
const { query, mode, limit, offset } = parsed.data;
|
|
47
|
-
const all = deps.search.search(query ?? "", { mode, limit: Math.max(1, deps.catalog.list().length) });
|
|
48
|
-
const page = all.candidates.slice(offset, offset + limit);
|
|
49
|
-
ingest(searchEvent(ctx, { ...all, candidates: page }, { total: all.candidates.length }, now), deps.ingest);
|
|
50
|
-
const body = {
|
|
51
|
-
trace_id: all.traceId,
|
|
52
|
-
candidates: page.map(({ uri, name, description, score, rank, invocation, digest }) => ({ uri, name, description, score, rank, invocation, digest })),
|
|
53
|
-
...(all.abstained ? { abstained: all.abstained } : {}),
|
|
54
|
-
total: all.candidates.length,
|
|
55
|
-
note: "Search does not activate skills. Read a chosen SKILL.md URI using the host's resource reader on this server.",
|
|
56
|
-
};
|
|
57
|
-
return { content: [{ type: "text", text: JSON.stringify(body) }], structuredContent: body };
|
|
58
72
|
};
|
|
59
73
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { accessSync, constants, existsSync, readFileSync, statSync } from "node:fs";
|
|
2
2
|
import { join, delimiter } from "node:path";
|
|
3
|
-
import { localServerName } from "./json-config.js";
|
|
3
|
+
import { localServerName, REMOTE_ALREADY_REGISTERED, remoteConflictWarning, remoteEntryUrl, SKILLAR_REMOTE_MCP_URL } from "./json-config.js";
|
|
4
4
|
const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
5
5
|
const jsonEsc = (v) => JSON.stringify(v).slice(1, -1);
|
|
6
6
|
function onPath(bin, env) {
|
|
@@ -121,26 +121,37 @@ export const claudeCodePack = {
|
|
|
121
121
|
plan.files.push({ path, before, after, mode: 0o600 });
|
|
122
122
|
}
|
|
123
123
|
let name = "skillar";
|
|
124
|
+
let remoteUrl = null;
|
|
124
125
|
try {
|
|
125
126
|
const servers = JSON.parse(readText(join(ctx.home, ".claude.json")) ?? "{}").mcpServers;
|
|
126
127
|
if (isObj(servers)) {
|
|
127
128
|
name = localServerName(servers);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
remoteUrl = remoteEntryUrl(servers.skillar, ["url"]);
|
|
130
|
+
if (remoteUrl === null && isObj(servers.skillar) && JSON.stringify(servers.skillar).includes("mcp-remote")) {
|
|
131
|
+
remoteUrl = "unparsed remote target";
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
135
|
catch { /* Claude owns its registration file; the CLI will validate it. */ }
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
// A different remote MCP holding the skillar name: hands off this runtime entirely.
|
|
137
|
+
if (remoteUrl !== null && remoteUrl !== SKILLAR_REMOTE_MCP_URL) {
|
|
138
|
+
return { files: [], commands: [], notes: [remoteConflictWarning(remoteUrl)], conflicts: [] };
|
|
139
|
+
}
|
|
140
|
+
// Already pointing at the hosted skillar MCP: keep the registration, still install capture.
|
|
141
|
+
if (remoteUrl === SKILLAR_REMOTE_MCP_URL) {
|
|
142
|
+
plan.notes.push(REMOTE_ALREADY_REGISTERED);
|
|
141
143
|
}
|
|
142
144
|
else {
|
|
143
|
-
|
|
145
|
+
const argv = ["claude", "mcp", "add", "--transport", "http", "--scope", "user", name,
|
|
146
|
+
`http://127.0.0.1:${ctx.port}/mcp`, "--header", `Authorization: Bearer ${ctx.token}`];
|
|
147
|
+
const shown = `claude mcp add --transport http --scope user ${name} http://127.0.0.1:${ctx.port}/mcp --header "Authorization: Bearer ${ctx.token}"`;
|
|
148
|
+
if (onPath("claude", ctx.env) && !(ctx.env.SKILLAR_NO_CLI ?? ctx.env.GISOOL_NO_CLI)) {
|
|
149
|
+
plan.commands.push({ argv, description: "Register the skillar MCP server with Claude Code (user scope)",
|
|
150
|
+
undo: { argv: ["claude", "mcp", "remove", "--scope", "user", name], description: "Remove the skillar MCP server" } });
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
plan.notes.push(`manual step: run ${shown}`);
|
|
154
|
+
}
|
|
144
155
|
}
|
|
145
156
|
if (ctx.disableRemote && remoteRegistered(ctx.home)) {
|
|
146
157
|
plan.notes.push("manual step: run claude mcp remove --scope user gisul");
|
package/dist/packs/cursor.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { isObject, isRemoteEntry, localServerName, noop, planJsonFile, readJsonConfig, refuse } from "./json-config.js";
|
|
3
|
+
import { isObject, isRemoteEntry, localServerName, noop, planJsonFile, readJsonConfig, refuse, REMOTE_ALREADY_REGISTERED, remoteConflictWarning, remoteEntryUrl, SKILLAR_REMOTE_MCP_URL } from "./json-config.js";
|
|
4
4
|
// Hook shape confirmed against https://cursor.com/docs/agent/hooks : hooks.json is { "version": 1, "hooks": { <event>: [{ "command": ... }] } }
|
|
5
5
|
// and Cursor reloads hooks config files automatically. MCP servers live in ~/.cursor/mcp.json under mcpServers.
|
|
6
6
|
const HOOK_EVENTS = ["beforeSubmitPrompt", "sessionStart", "sessionEnd"];
|
|
@@ -49,9 +49,14 @@ export const cursorPack = {
|
|
|
49
49
|
if (ctx.disableRemote && isRemoteEntry(servers.gisul, URL_KEYS)) {
|
|
50
50
|
notes.push("Remote skillar MCP entry left enabled: Cursor's disable key is unverified, so disable it manually.");
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
const remoteUrl = remoteEntryUrl(servers.skillar, URL_KEYS);
|
|
53
|
+
if (remoteUrl !== null && remoteUrl !== SKILLAR_REMOTE_MCP_URL)
|
|
54
|
+
return noop(remoteConflictWarning(remoteUrl));
|
|
55
|
+
// Already pointing at the hosted skillar MCP: keep the registration, still install capture.
|
|
56
|
+
if (remoteUrl === SKILLAR_REMOTE_MCP_URL)
|
|
57
|
+
notes.push(REMOTE_ALREADY_REGISTERED);
|
|
58
|
+
else
|
|
59
|
+
servers[localServerName(servers)] = { url: localMcpUrl(ctx.port), headers: { Authorization: `Bearer ${ctx.token}` } };
|
|
55
60
|
nextMcp.mcpServers = servers;
|
|
56
61
|
if (hooksFile.obj.version !== undefined && hooksFile.obj.version !== 1) {
|
|
57
62
|
return refuse(hooksPath, "invalid_shape", "hooks.json version must be 1");
|
package/dist/packs/gemini.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { isObject, isRemoteEntry, localServerName, noop, planJsonFile, readJsonConfig, refuse } from "./json-config.js";
|
|
3
|
+
import { isObject, isRemoteEntry, localServerName, noop, planJsonFile, readJsonConfig, refuse, REMOTE_ALREADY_REGISTERED, remoteConflictWarning, remoteEntryUrl, SKILLAR_REMOTE_MCP_URL } from "./json-config.js";
|
|
4
4
|
// Hook shape confirmed against https://geminicli.com/docs/hooks/ : settings.json "hooks" maps an event name to groups
|
|
5
5
|
// of { matcher?, hooks: [{ type: "command", name, command, timeout }] }; timeout is in milliseconds. BeforeAgent is a
|
|
6
6
|
// lifecycle event (exact-string matcher, so none is written); AfterTool matchers are regular expressions over tool names.
|
|
@@ -48,9 +48,14 @@ export const geminiPack = {
|
|
|
48
48
|
if (ctx.disableRemote && isRemoteEntry(servers.gisul, URL_KEYS)) {
|
|
49
49
|
notes.push("Remote skillar MCP entry left enabled: Gemini's disable key is unverified, so disable it manually.");
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
const remoteUrl = remoteEntryUrl(servers.skillar, URL_KEYS);
|
|
52
|
+
if (remoteUrl !== null && remoteUrl !== SKILLAR_REMOTE_MCP_URL)
|
|
53
|
+
return noop(remoteConflictWarning(remoteUrl));
|
|
54
|
+
// Already pointing at the hosted skillar MCP: keep the registration, still install capture.
|
|
55
|
+
if (remoteUrl === SKILLAR_REMOTE_MCP_URL)
|
|
56
|
+
notes.push(REMOTE_ALREADY_REGISTERED);
|
|
57
|
+
else
|
|
58
|
+
servers[localServerName(servers)] = { httpUrl: localMcpUrl(ctx.port), headers: { Authorization: `Bearer ${ctx.token}` } };
|
|
54
59
|
next.mcpServers = servers;
|
|
55
60
|
for (const { event, matcher } of HOOK_EVENTS) {
|
|
56
61
|
const groups = hooks[event] ?? [];
|
|
@@ -53,3 +53,44 @@ export function isRemoteEntry(entry, urlKeys) {
|
|
|
53
53
|
export function localServerName(servers) {
|
|
54
54
|
return !Object.hasOwn(servers, "skillar") && isObject(servers.gisool) && !isRemoteEntry(servers.gisool, ["url", "httpUrl"]) ? "gisool" : "skillar";
|
|
55
55
|
}
|
|
56
|
+
/** The hosted skillar MCP endpoint a previous remote registration points at. */
|
|
57
|
+
export const SKILLAR_REMOTE_MCP_URL = "https://skillar.sh/mcp";
|
|
58
|
+
/**
|
|
59
|
+
* Normalized remote URL of an MCP entry (url-style keys or an mcp-remote
|
|
60
|
+
* command bridge), or null when the entry is local or carries no remote URL.
|
|
61
|
+
*/
|
|
62
|
+
export function remoteEntryUrl(entry, urlKeys) {
|
|
63
|
+
if (!isObject(entry))
|
|
64
|
+
return null;
|
|
65
|
+
const from = (raw) => {
|
|
66
|
+
if (typeof raw !== "string")
|
|
67
|
+
return null;
|
|
68
|
+
try {
|
|
69
|
+
const url = new URL(raw);
|
|
70
|
+
if (url.protocol !== "https:" && url.protocol !== "http:")
|
|
71
|
+
return null;
|
|
72
|
+
return LOOPBACK_HOSTS.has(url.hostname) ? null : url.toString().replace(/\/+$/, "");
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
for (const key of urlKeys) {
|
|
79
|
+
const found = from(entry[key]);
|
|
80
|
+
if (found !== null)
|
|
81
|
+
return found;
|
|
82
|
+
}
|
|
83
|
+
const argv = [entry.command, ...(Array.isArray(entry.args) ? entry.args : [])];
|
|
84
|
+
for (const arg of argv) {
|
|
85
|
+
const found = from(arg);
|
|
86
|
+
if (found !== null)
|
|
87
|
+
return found;
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
/** Skip note when the existing remote registration already is the hosted skillar MCP. */
|
|
92
|
+
export const REMOTE_ALREADY_REGISTERED = `existing remote skillar registration (${SKILLAR_REMOTE_MCP_URL}) kept; skipping local daemon registration for this runtime`;
|
|
93
|
+
/** Skip note when a different remote MCP holds the skillar name. */
|
|
94
|
+
export function remoteConflictWarning(url) {
|
|
95
|
+
return `warning: a different remote MCP named skillar (${url}) is registered; skipping this runtime - remove that registration to install the local daemon`;
|
|
96
|
+
}
|
package/dist/packs/omo.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, lstatSync, readFileSync } from "node:fs";
|
|
2
2
|
import { isAbsolute, join, resolve } from "node:path";
|
|
3
|
-
import { localServerName } from "./json-config.js";
|
|
3
|
+
import { localServerName, noop, REMOTE_ALREADY_REGISTERED, remoteConflictWarning, remoteEntryUrl, SKILLAR_REMOTE_MCP_URL } from "./json-config.js";
|
|
4
4
|
const EXT_FILES = ["index.js", "discovery.md"];
|
|
5
5
|
const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
6
6
|
function readOrNull(path) {
|
|
@@ -96,17 +96,26 @@ export function createPiPack(spec) {
|
|
|
96
96
|
return plan;
|
|
97
97
|
}
|
|
98
98
|
const servers = { ...(isObject(cfg.mcpServers) ? cfg.mcpServers : {}) };
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return
|
|
99
|
+
const remoteUrl = remoteEntryUrl(servers.skillar, ["url"]);
|
|
100
|
+
if (remoteUrl !== null && remoteUrl !== SKILLAR_REMOTE_MCP_URL)
|
|
101
|
+
return noop(remoteConflictWarning(remoteUrl));
|
|
102
|
+
if (remoteUrl === null && isRemoteSkillar(servers.skillar))
|
|
103
|
+
return noop(remoteConflictWarning("unparsed remote target"));
|
|
104
|
+
// Already pointing at the hosted skillar MCP: keep the registration, still install capture.
|
|
105
|
+
if (remoteUrl === SKILLAR_REMOTE_MCP_URL) {
|
|
106
|
+
plan.notes.push(REMOTE_ALREADY_REGISTERED);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
servers[localServerName(servers)] = { type: "http", url: `http://127.0.0.1:${ctx.port}/mcp`, headers: { Authorization: `Bearer ${ctx.token}` } };
|
|
102
110
|
}
|
|
103
|
-
servers[localServerName(servers)] = { type: "http", url: `http://127.0.0.1:${ctx.port}/mcp`, headers: { Authorization: `Bearer ${ctx.token}` } };
|
|
104
111
|
if (ctx.disableRemote && isRemoteSkillar(servers.gisul)) {
|
|
105
112
|
servers.gisul = { ...servers.gisul, enabled: false };
|
|
106
113
|
plan.notes.push("legacy remote gisul entry set to enabled:false (original definition kept)");
|
|
107
114
|
}
|
|
108
115
|
const mcpAfter = JSON.stringify({ ...cfg, mcpServers: servers }, null, 2) + "\n";
|
|
109
|
-
|
|
116
|
+
const mcpUnchanged = before !== null && JSON.stringify(JSON.parse(before)) === JSON.stringify({ ...cfg, mcpServers: servers });
|
|
117
|
+
if (!mcpUnchanged)
|
|
118
|
+
plan.files.push({ path: mcpPath, before, after: mcpAfter, mode: 0o600 });
|
|
110
119
|
const dir = extDir(agentDir);
|
|
111
120
|
const source = join(ctx.packageRoot, "packs", spec.id, "extension");
|
|
112
121
|
const add = (path, after) => {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** Status belongs to one request; a session is a collection, never a winning status. */
|
|
2
|
+
export const REQUEST_STATUSES = ["not_attempted", "in_progress", "succeeded", "failed", "cancelled", "unknown"];
|
|
3
|
+
export const NO_CANDIDATE_REASONS = ["empty_query", "no_overlap", "below_threshold", "explicit_only"];
|
|
4
|
+
// A start event alone proves only that a request once started. Only the process executing it
|
|
5
|
+
// may call it in_progress. After a restart/import it is unknown, not failed or cancelled.
|
|
6
|
+
export const activeRequests = new Set();
|
|
7
|
+
const str = (value) => typeof value === "string" ? value : undefined;
|
|
8
|
+
export function searchResult(data) {
|
|
9
|
+
const abstained = data.abstained;
|
|
10
|
+
const reason = NO_CANDIDATE_REASONS.find((r) => r === abstained?.reason);
|
|
11
|
+
// Use total, not this page's size: an empty page is not a search with no candidates.
|
|
12
|
+
if (typeof data.total === "number" && data.total > 0 || Array.isArray(data.candidates) && data.candidates.length > 0)
|
|
13
|
+
return { result: "candidates_found" };
|
|
14
|
+
if (reason || data.total === 0)
|
|
15
|
+
return { result: "no_candidates", ...(reason ? { reason } : {}) };
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
export function requestRecords(events, active = activeRequests) {
|
|
19
|
+
const records = new Map();
|
|
20
|
+
const tracked = new Set(events.filter((e) => e.kind === "skill_request").map((e) => str(e.data.requestId)).filter(Boolean));
|
|
21
|
+
for (const event of events) {
|
|
22
|
+
const { data } = event;
|
|
23
|
+
if (event.kind === "skill_request") {
|
|
24
|
+
const id = str(data.requestId);
|
|
25
|
+
const operation = data.operation;
|
|
26
|
+
if (!id || operation !== "search" && operation !== "load")
|
|
27
|
+
continue;
|
|
28
|
+
const status = data.status;
|
|
29
|
+
if (!REQUEST_STATUSES.includes(status) || status === "not_attempted")
|
|
30
|
+
continue;
|
|
31
|
+
const previous = records.get(id);
|
|
32
|
+
// Out-of-order delivery of a start must not overwrite a terminal outcome.
|
|
33
|
+
if (status === "in_progress" && previous?.endedAt !== undefined)
|
|
34
|
+
continue;
|
|
35
|
+
records.set(id, {
|
|
36
|
+
id, operation, status: status === "in_progress" ? active.has(id) ? "in_progress" : "unknown" : status,
|
|
37
|
+
startedAt: previous?.startedAt ?? (typeof data.startedAt === "number" ? data.startedAt : event.ts),
|
|
38
|
+
...(status !== "in_progress" ? { endedAt: event.ts } : {}),
|
|
39
|
+
...(str(data.uri) ?? str(data.firstCandidateUri) ? { uri: str(data.uri) ?? str(data.firstCandidateUri) } : {}),
|
|
40
|
+
...(operation === "search" && status === "succeeded" ? searchResult(data) : {}),
|
|
41
|
+
...(str(data.errorCode) ? { errorCode: str(data.errorCode) } : {}),
|
|
42
|
+
});
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (tracked.has(str(data.requestId)))
|
|
46
|
+
continue;
|
|
47
|
+
// Historical completed search/load observations are still useful. Generic errors,
|
|
48
|
+
// native skill activation, and supporting-file reads do not prove a load attempt.
|
|
49
|
+
if (event.kind === "search" || event.kind === "load") {
|
|
50
|
+
records.set(event.id, { id: event.id, operation: event.kind, status: "succeeded", endedAt: event.ts,
|
|
51
|
+
...(event.kind === "search" ? { ...searchResult(data), uri: Array.isArray(data.candidates) ? str(data.candidates[0]?.uri) : undefined } : { uri: event.skillUri ?? str(data.uri) }) });
|
|
52
|
+
}
|
|
53
|
+
else if (event.kind === "error") {
|
|
54
|
+
const uri = event.skillUri ?? str(data.uri);
|
|
55
|
+
const operation = data.tool === "search_skills" ? "search"
|
|
56
|
+
: data.tool === "load_skill" || data.tool === "resources/read" && data.resourceKind !== "supporting_file" && uri?.endsWith("/SKILL.md") ? "load" : undefined;
|
|
57
|
+
if (operation)
|
|
58
|
+
records.set(event.id, { id: event.id, operation, status: "failed", endedAt: event.ts,
|
|
59
|
+
...(uri ? { uri } : {}), ...(str(data.code) ? { errorCode: str(data.code) } : {}) });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return [...records.values()];
|
|
63
|
+
}
|
|
64
|
+
export function summarizeRequests(records) {
|
|
65
|
+
const empty = () => ({ total: 0, counts: { in_progress: 0, succeeded: 0, failed: 0, cancelled: 0, unknown: 0 },
|
|
66
|
+
results: { candidates_found: 0, no_candidates: 0 }, reasons: {} });
|
|
67
|
+
const summary = { search: empty(), load: empty() };
|
|
68
|
+
for (const record of records) {
|
|
69
|
+
const group = summary[record.operation];
|
|
70
|
+
group.total++;
|
|
71
|
+
group.counts[record.status]++;
|
|
72
|
+
if (record.result)
|
|
73
|
+
group.results[record.result]++;
|
|
74
|
+
if (record.reason)
|
|
75
|
+
group.reasons[record.reason] = (group.reasons[record.reason] ?? 0) + 1;
|
|
76
|
+
}
|
|
77
|
+
return summary;
|
|
78
|
+
}
|
|
79
|
+
export function hasStatus(summary, status) {
|
|
80
|
+
return status === "not_attempted" ? summary.total === 0 : summary.counts[status] > 0;
|
|
81
|
+
}
|