@modootoday/pmcp 0.17.3 → 0.18.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/.agents/plugins/marketplace.json +1 -1
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +60 -0
- package/README.md +29 -24
- package/dist/apply-4IGTXOCQ.js +242 -0
- package/dist/{attachment-tU5FZrgZ.d.ts → attachment-D84OGI6n.d.ts} +1 -1
- package/dist/available-DBSIVVJ6.js +73 -0
- package/dist/broadcast-3RY3OZGY.js +18 -0
- package/dist/chunk-25GHX674.js +1246 -0
- package/dist/chunk-2P4Z2NUX.js +28 -0
- package/dist/chunk-34DECPVC.js +22 -0
- package/dist/chunk-3NYG4SGU.js +45 -0
- package/dist/chunk-3PW4FI7U.js +32 -0
- package/dist/chunk-3Y3HDMHA.js +108 -0
- package/dist/chunk-47O3X4VS.js +113 -0
- package/dist/chunk-4NDEP7HU.js +26 -0
- package/dist/chunk-4VCC2NXE.js +104 -0
- package/dist/chunk-5OMOPUE6.js +39 -0
- package/dist/chunk-5QQWS4US.js +53 -0
- package/dist/chunk-5ZABTVSW.js +48 -0
- package/dist/chunk-65ZHM5RH.js +4985 -0
- package/dist/chunk-665TA55Z.js +419 -0
- package/dist/chunk-6STKGOCW.js +27 -0
- package/dist/chunk-6WXMJOMI.js +9 -0
- package/dist/chunk-73AKO4UL.js +24 -0
- package/dist/chunk-7BLPN3W6.js +31 -0
- package/dist/chunk-7DLZC73N.js +29 -0
- package/dist/chunk-7GBYECSK.js +72 -0
- package/dist/chunk-7TD53M7L.js +13 -0
- package/dist/chunk-A4PKLESO.js +112 -0
- package/dist/chunk-ABTJQ4QV.js +74 -0
- package/dist/chunk-BBTBJCFA.js +380 -0
- package/dist/chunk-BU65MNVU.js +13 -0
- package/dist/chunk-BVCTKPT3.js +83 -0
- package/dist/chunk-C4NHQGHL.js +142 -0
- package/dist/chunk-CJTKR6K6.js +1213 -0
- package/dist/chunk-DCU2EXQV.js +78 -0
- package/dist/chunk-DZ2MRTYT.js +135 -0
- package/dist/chunk-E2YOZ2FF.js +207 -0
- package/dist/chunk-E3DQB5LS.js +48 -0
- package/dist/chunk-E7OOHLQR.js +7 -0
- package/dist/chunk-EATCUWGG.js +66 -0
- package/dist/chunk-EIDIVIAD.js +33 -0
- package/dist/chunk-EJBZGIDK.js +1934 -0
- package/dist/chunk-ELAGZ635.js +252 -0
- package/dist/chunk-GZHHEHKY.js +44 -0
- package/dist/chunk-HDMBVLCZ.js +53 -0
- package/dist/chunk-HQOB7OQS.js +81 -0
- package/dist/chunk-IGYRMM62.js +28 -0
- package/dist/chunk-IJBSOWHK.js +86 -0
- package/dist/chunk-INT7QLEU.js +114 -0
- package/dist/chunk-J6QLLQVL.js +1025 -0
- package/dist/chunk-J7UYNJCR.js +9 -0
- package/dist/chunk-JEL35P7S.js +53 -0
- package/dist/chunk-JGJ4INEN.js +32 -0
- package/dist/chunk-JS5RTH4I.js +84 -0
- package/dist/chunk-JUXNIXN4.js +42 -0
- package/dist/chunk-JWRZDYB5.js +59 -0
- package/dist/chunk-KMXRRSKT.js +660 -0
- package/dist/chunk-LAZQBMAU.js +67 -0
- package/dist/chunk-LLBPVZXM.js +67 -0
- package/dist/chunk-LLT5FQBE.js +57 -0
- package/dist/chunk-LMT3PPXJ.js +17 -0
- package/dist/chunk-MM2Y43LC.js +87 -0
- package/dist/chunk-MPSQXSC6.js +346 -0
- package/dist/chunk-MVFH26QT.js +97 -0
- package/dist/chunk-MWFOUBFC.js +39 -0
- package/dist/chunk-N5AQ3PP7.js +211 -0
- package/dist/chunk-NQPURJT5.js +44 -0
- package/dist/chunk-NRBQK6UX.js +105 -0
- package/dist/chunk-NZS5CD72.js +333 -0
- package/dist/chunk-OEH47H6A.js +48 -0
- package/dist/chunk-OG7QR2DP.js +75 -0
- package/dist/chunk-OPYFEHKG.js +52 -0
- package/dist/chunk-P4N7DBD5.js +83 -0
- package/dist/chunk-PAX3QXX2.js +140 -0
- package/dist/chunk-PLX3BOOS.js +396 -0
- package/dist/chunk-PMJG2CXF.js +122 -0
- package/dist/chunk-PWSJJXLQ.js +643 -0
- package/dist/chunk-Q5H3L6Y4.js +23 -0
- package/dist/chunk-Q65R3XKX.js +155 -0
- package/dist/chunk-QEW4J3IZ.js +74 -0
- package/dist/chunk-QPL7E2HW.js +464 -0
- package/dist/chunk-R2GPCZUX.js +22 -0
- package/dist/chunk-R4L6LJJ2.js +778 -0
- package/dist/chunk-R5MT42JS.js +284 -0
- package/dist/chunk-RK4PYD7L.js +73 -0
- package/dist/chunk-RMATE45Z.js +197 -0
- package/dist/chunk-S3PIAMXV.js +230 -0
- package/dist/chunk-SG5TPMKH.js +93 -0
- package/dist/chunk-T3LKX23M.js +168 -0
- package/dist/chunk-T6GOWHK6.js +30 -0
- package/dist/chunk-TIA4SPU2.js +10 -0
- package/dist/chunk-TNCZ6444.js +57 -0
- package/dist/chunk-TVL5RTE6.js +269 -0
- package/dist/chunk-UOCLRM7P.js +151 -0
- package/dist/chunk-UPQTAHUK.js +189 -0
- package/dist/chunk-V4NPDK6X.js +14 -0
- package/dist/chunk-VJFEN6DJ.js +38 -0
- package/dist/chunk-WIW772I3.js +25 -0
- package/dist/chunk-XELAZAIM.js +136 -0
- package/dist/chunk-XNML2KIC.js +23 -0
- package/dist/chunk-XP2U3LO3.js +30 -0
- package/dist/chunk-YGOWIJPE.js +51 -0
- package/dist/chunk-YIXDHQYE.js +11 -0
- package/dist/chunk-YMHUM7AV.js +22 -0
- package/dist/chunk-YSAWTGNA.js +117 -0
- package/dist/chunk-Z4HRRXRF.js +478 -0
- package/dist/chunk-ZH6R642Z.js +102 -0
- package/dist/claude-U2JC2DNQ.js +77 -0
- package/dist/cli-VYCQJZ5X.js +41 -0
- package/dist/cli-ZTCBSDW4.js +46 -0
- package/dist/cli.js +144 -16160
- package/dist/completion-E7RRG3ZT.js +142 -0
- package/dist/config-DnpLL2kT.d.ts +46 -0
- package/dist/{service-qpCsOXkQ.d.ts → core-C1LPjxK6.d.ts} +2 -6
- package/dist/diagnostics-XXH4FLUG.js +93 -0
- package/dist/doctor-ZIOESU3N.js +538 -0
- package/dist/entry-ZNFCTDVE.js +305 -0
- package/dist/exec-mcp-X6372BLE.js +365 -0
- package/dist/harness-F2XFDYXF.js +177 -0
- package/dist/harness-egress-bridge.js +4 -4
- package/dist/harness-launch-gate.js +47 -940
- package/dist/harness-pane-runner.js +13 -80
- package/dist/harness-worker.js +21 -2703
- package/dist/hook-body.js +5221 -0
- package/dist/hook-spec-C5fWTSCH.d.ts +100 -0
- package/dist/hook.js +26 -0
- package/dist/hooks-FYE2L5RW.js +21 -0
- package/dist/host-GRY3VAHH.js +22 -0
- package/dist/host-X6BR6X4O.js +200 -0
- package/dist/host-run-GCA6H6SR.js +307 -0
- package/dist/http.d.ts +5 -42
- package/dist/http.js +21 -2234
- package/dist/import-mcp-2TTBPVLY.js +400 -0
- package/dist/index.d.ts +146 -168
- package/dist/index.js +133 -4911
- package/dist/init-627KFXTG.js +14 -0
- package/dist/install-GG7HHZK2.js +796 -0
- package/dist/invoke-LW22Z6ET.js +23 -0
- package/dist/list-MCP2FXUF.js +68 -0
- package/dist/list-NGMSQ5SH.js +65 -0
- package/dist/load-BEUBABtB.d.ts +21 -0
- package/dist/logout-6CSHUWWE.js +44 -0
- package/dist/logs-SPB6AANY.js +107 -0
- package/dist/mailbox/index.d.ts +10 -5
- package/dist/mailbox/index.js +53 -1572
- package/dist/mailbox-7BV54Q4R.js +285 -0
- package/dist/mailbox-GDJ7BWQN.js +189 -0
- package/dist/mainline-JQTTYJMI.js +639 -0
- package/dist/marketplace-G4VQET5W.js +191 -0
- package/dist/mcp-2DKVU3SW.js +15 -0
- package/dist/mcp-V23HC3LB.js +193 -0
- package/dist/models-ISU4DCMA.js +32 -0
- package/dist/opencode-CN7JLQYO.js +60 -0
- package/dist/pause-FFAYRBWI.js +18 -0
- package/dist/preview-DT7DWG5F.js +91 -0
- package/dist/project/hook-adapter.d.ts +6 -3
- package/dist/project/hook-adapter.js +66 -35
- package/dist/project-FY62G55N.js +70 -0
- package/dist/pty-XTJ4MIWK.js +94 -0
- package/dist/recovery-U6QB3PMT.js +100 -0
- package/dist/reindex-Y27QJFDB.js +22 -0
- package/dist/resume-UU4HZIUP.js +18 -0
- package/dist/run-HALGEJNJ.js +19 -0
- package/dist/run-OGA3P7FC.js +126 -0
- package/dist/serve-NBKT5BKY.js +104 -0
- package/dist/session-XM2CR425.js +159 -0
- package/dist/setup-DTKZLZUT.js +18 -0
- package/dist/start-login-UIQYQBMC.js +416 -0
- package/dist/status-A2OUTNGK.js +9 -0
- package/dist/status-H2VAHIDV.js +10 -0
- package/dist/status-NOOHW5WA.js +43 -0
- package/dist/status-VHODZPXB.js +55 -0
- package/dist/status-XQANBVXW.js +286 -0
- package/dist/stdio.d.ts +3 -13
- package/dist/stdio.js +16 -3186
- package/dist/sweep-64JDCGK6.js +18 -0
- package/dist/test-MKAXFJOL.js +561 -0
- package/dist/tools-gpHNq9Dh.d.ts +328 -0
- package/dist/tui-MWKAXE4K.js +153 -0
- package/dist/unbroadcast-KPUEFLZD.js +18 -0
- package/dist/validate-5GZ5YWNA.js +46 -0
- package/dist/worker-RQ575EJL.js +80 -0
- package/dist/worktree-create-PZSRB7PH.js +89 -0
- package/dist/worktree-list-JYB6VXLW.js +51 -0
- package/dist/worktree-sync-UF5CXPWV.js +30 -0
- package/docs/hooks/capabilities/antigravity.json +199 -0
- package/docs/hooks/capabilities/claude.json +179 -0
- package/docs/hooks/capabilities/codex.json +179 -0
- package/docs/hooks/capabilities/gemini.json +196 -0
- package/docs/hooks/capabilities/grok.json +192 -0
- package/docs/hooks/capabilities/opencode.json +184 -0
- package/docs/project-configuration.md +844 -4
- package/docs/terminal-harness.md +71 -28
- package/docs/terminal-workspace.md +91 -170
- package/gemini-extension.json +1 -1
- package/package.json +13 -1
- package/plugin.json +1 -1
- package/plugins/pmcp/.claude-plugin/plugin.json +4 -2
- package/plugins/pmcp/gemini-extension.json +1 -1
- package/plugins/pmcp/mod/commands.ts +72 -0
- package/plugins/pmcp/mod/contract.d.ts +39 -0
- package/plugins/pmcp/mod/draw.tsx +216 -0
- package/plugins/pmcp/mod/guard.ts +42 -0
- package/plugins/pmcp/mod/hooks.json +4 -0
- package/plugins/pmcp/mod/host.ts +46 -0
- package/plugins/pmcp/mod/model.ts +144 -0
- package/plugins/pmcp/mod/reader/index.ts +18 -0
- package/plugins/pmcp/mod/reader/read.ts +76 -0
- package/plugins/pmcp/mod/reader/settings.ts +54 -0
- package/plugins/pmcp/mod/reader/types.ts +38 -0
- package/plugins/pmcp/mod/register.tsx +73 -0
- package/plugins/pmcp/mod/sessions/format.ts +91 -0
- package/plugins/pmcp/mod/sessions/types.ts +162 -0
- package/plugins/pmcp/mod/snapshot.ts +75 -0
- package/plugins/pmcp/mod/spinner.tsx +30 -0
- package/plugins/pmcp/mod/state.ts +28 -0
- package/plugins/pmcp/plugin.json +1 -1
- package/plugins/pmcp/skills/agent-assets-migrate/SKILL.md +96 -0
- package/plugins/pmcp/skills/headless-agents-ci-scaffold/SKILL.md +100 -0
- package/plugins/pmcp/skills/marketplace-plugin-scaffold/SKILL.md +87 -0
- package/plugins/pmcp/skills/package-skill-catalog/SKILL.md +51 -11
- package/plugins/pmcp/skills/pmcp-project-init/SKILL.md +145 -0
- package/plugins/pmcp/skills/pmcp-sessions-and-git/SKILL.md +104 -0
- package/plugins/pmcp/skills/skill-package-scaffold/SKILL.md +88 -0
- package/schema/catalog-v1.json +158 -0
- package/schema/library.json +164 -0
- package/schema/marketplace-manifest.json +130 -0
- package/schema/plugin-manifest.json +55 -0
- package/schema/skill-frontmatter.json +144 -0
- package/schema/skill-metadata-core.json +110 -0
- package/skills/agent-assets-migrate/SKILL.md +96 -0
- package/skills/headless-agents-ci-scaffold/SKILL.md +100 -0
- package/skills/marketplace-plugin-scaffold/SKILL.md +87 -0
- package/skills/package-skill-catalog/SKILL.md +51 -11
- package/skills/pmcp-project-init/SKILL.md +145 -0
- package/skills/pmcp-sessions-and-git/SKILL.md +104 -0
- package/skills/skill-package-scaffold/SKILL.md +88 -0
- package/dist/config-BkSpjUG6.d.ts +0 -50
- package/dist/embed-DRROSD3F.d.ts +0 -53
- package/dist/hook-spec-PRSnYGLV.d.ts +0 -10
- package/dist/server-VWSY3Shw.d.ts +0 -543
- package/dist/tui-worker.js +0 -6549
- /package/dist/{tui-worker.d.ts → hook.d.ts} +0 -0
|
@@ -0,0 +1,1246 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normaliseIntent
|
|
3
|
+
} from "./chunk-6WXMJOMI.js";
|
|
4
|
+
import {
|
|
5
|
+
ASSET_KINDS,
|
|
6
|
+
assetRoot,
|
|
7
|
+
frontmatterObject,
|
|
8
|
+
kindOf,
|
|
9
|
+
readBody,
|
|
10
|
+
readCatalog,
|
|
11
|
+
readFrontmatterText,
|
|
12
|
+
specProblems,
|
|
13
|
+
withoutBody
|
|
14
|
+
} from "./chunk-KMXRRSKT.js";
|
|
15
|
+
import {
|
|
16
|
+
registerMailboxTools
|
|
17
|
+
} from "./chunk-TNCZ6444.js";
|
|
18
|
+
import {
|
|
19
|
+
RUNTIMES,
|
|
20
|
+
detectRuntime,
|
|
21
|
+
verifiedRuntimesOf
|
|
22
|
+
} from "./chunk-47O3X4VS.js";
|
|
23
|
+
|
|
24
|
+
// src/find.ts
|
|
25
|
+
import { createHash } from "crypto";
|
|
26
|
+
var DEFAULT_FIND_LIMIT = 5;
|
|
27
|
+
function tokens(text) {
|
|
28
|
+
return normaliseIntent(text).split(" ").filter(Boolean);
|
|
29
|
+
}
|
|
30
|
+
function bigrams(text) {
|
|
31
|
+
const flat = normaliseIntent(text).replaceAll(" ", "");
|
|
32
|
+
const out = /* @__PURE__ */ new Set();
|
|
33
|
+
for (let i = 0; i + 1 < flat.length; i += 1) out.add(flat.slice(i, i + 2));
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
function lexicalScore(intent, description) {
|
|
37
|
+
const wanted = tokens(intent);
|
|
38
|
+
if (wanted.length === 0) return 0;
|
|
39
|
+
const have = new Set(tokens(description));
|
|
40
|
+
const overlap = wanted.filter((token) => have.has(token)).length / wanted.length;
|
|
41
|
+
const a = bigrams(intent);
|
|
42
|
+
const b = bigrams(description);
|
|
43
|
+
if (a.size === 0 || b.size === 0) return overlap / 2;
|
|
44
|
+
let shared = 0;
|
|
45
|
+
for (const gram of a) if (b.has(gram)) shared += 1;
|
|
46
|
+
const dice = 2 * shared / (a.size + b.size);
|
|
47
|
+
return (overlap + dice) / 2;
|
|
48
|
+
}
|
|
49
|
+
function cosine(a, b) {
|
|
50
|
+
if (a.length !== b.length) return 0;
|
|
51
|
+
let dot = 0;
|
|
52
|
+
let na = 0;
|
|
53
|
+
let nb = 0;
|
|
54
|
+
for (let i = 0; i < a.length; i += 1) {
|
|
55
|
+
dot += a[i] * b[i];
|
|
56
|
+
na += a[i] * a[i];
|
|
57
|
+
nb += b[i] * b[i];
|
|
58
|
+
}
|
|
59
|
+
if (na === 0 || nb === 0) return 0;
|
|
60
|
+
return dot / (Math.sqrt(na) * Math.sqrt(nb));
|
|
61
|
+
}
|
|
62
|
+
async function find(options) {
|
|
63
|
+
const limit = options.limit ?? DEFAULT_FIND_LIMIT;
|
|
64
|
+
const semantic = options.embedder !== void 0 && options.vectors !== void 0 && options.vectors.size > 0;
|
|
65
|
+
if (semantic) {
|
|
66
|
+
const embedder = options.embedder;
|
|
67
|
+
const vectors = options.vectors;
|
|
68
|
+
const namespace = createHash("sha256").update(embedder.indexKey ?? embedder.modelId).digest("hex");
|
|
69
|
+
const cacheKey = `${namespace} ${normaliseIntent(options.intent)}`;
|
|
70
|
+
let query = options.cache?.get(cacheKey) ?? null;
|
|
71
|
+
if (!query) {
|
|
72
|
+
query = await embedder.embed(options.intent);
|
|
73
|
+
options.cache?.put(cacheKey, query);
|
|
74
|
+
}
|
|
75
|
+
const scored = [];
|
|
76
|
+
for (const entry of options.entries) {
|
|
77
|
+
const vector = vectors.get(entry.name);
|
|
78
|
+
if (!vector || vector.length !== query.length) continue;
|
|
79
|
+
scored.push({
|
|
80
|
+
name: entry.name,
|
|
81
|
+
package: entry.package,
|
|
82
|
+
description: entry.description,
|
|
83
|
+
score: cosine(query, vector)
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (scored.length === options.entries.length) {
|
|
87
|
+
return {
|
|
88
|
+
ranking: "semantic",
|
|
89
|
+
matches: rank(scored, limit)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
ranking: "lexical",
|
|
95
|
+
matches: rank(
|
|
96
|
+
options.entries.map((entry) => ({
|
|
97
|
+
name: entry.name,
|
|
98
|
+
package: entry.package,
|
|
99
|
+
description: entry.description,
|
|
100
|
+
score: lexicalScore(options.intent, entry.description)
|
|
101
|
+
})),
|
|
102
|
+
limit
|
|
103
|
+
)
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function rank(matches3, limit) {
|
|
107
|
+
return matches3.filter((match) => match.score > 0).sort((a, b) => b.score - a.score || a.name.localeCompare(b.name)).slice(0, limit);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/files/list.ts
|
|
111
|
+
import { createHash as createHash2 } from "crypto";
|
|
112
|
+
import { readFileSync, readdirSync, statSync } from "fs";
|
|
113
|
+
import { basename as basename2, join, relative, sep } from "path";
|
|
114
|
+
|
|
115
|
+
// src/files/redact.ts
|
|
116
|
+
import { basename } from "path";
|
|
117
|
+
var REDACTED = "<redacted>";
|
|
118
|
+
var SECRET_MAPS = /* @__PURE__ */ new Set(["env", "headers"]);
|
|
119
|
+
function redactValue(value) {
|
|
120
|
+
if (Array.isArray(value)) return value.map(redactValue);
|
|
121
|
+
if (value === null || typeof value !== "object") return value;
|
|
122
|
+
const out = {};
|
|
123
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
124
|
+
const isSecretMap = SECRET_MAPS.has(key.toLowerCase()) && inner !== null && typeof inner === "object" && !Array.isArray(inner);
|
|
125
|
+
out[key] = isSecretMap ? Object.fromEntries(Object.keys(inner).map((name) => [name, REDACTED])) : redactValue(inner);
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
function redactMcpConfig(text) {
|
|
130
|
+
let parsed;
|
|
131
|
+
try {
|
|
132
|
+
parsed = JSON.parse(text);
|
|
133
|
+
} catch {
|
|
134
|
+
return `${JSON.stringify({ redacted: REDACTED, reason: "not valid JSON" }, null, 2)}
|
|
135
|
+
`;
|
|
136
|
+
}
|
|
137
|
+
return `${JSON.stringify(redactValue(parsed), null, 2)}
|
|
138
|
+
`;
|
|
139
|
+
}
|
|
140
|
+
var isMcpConfig = (path) => basename(path) === ".mcp.json";
|
|
141
|
+
function servedBytes(path, raw) {
|
|
142
|
+
if (!isMcpConfig(path)) return raw;
|
|
143
|
+
return Buffer.from(redactMcpConfig(raw.toString("utf8")), "utf8");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/files/list.ts
|
|
147
|
+
var FILE_LIST_LIMIT = 200;
|
|
148
|
+
var sha256 = (bytes) => createHash2("sha256").update(bytes).digest("hex");
|
|
149
|
+
function describe(path, full) {
|
|
150
|
+
const bytes = servedBytes(full, readFileSync(full));
|
|
151
|
+
return { path, bytes: bytes.length, sha256: sha256(bytes) };
|
|
152
|
+
}
|
|
153
|
+
function listSkillFiles(root, limit = FILE_LIST_LIMIT) {
|
|
154
|
+
if (statSync(root).isFile()) {
|
|
155
|
+
return { files: [describe(basename2(root), root)], truncated: false };
|
|
156
|
+
}
|
|
157
|
+
const files = [];
|
|
158
|
+
const stack = [root];
|
|
159
|
+
while (stack.length > 0) {
|
|
160
|
+
const dir = stack.pop();
|
|
161
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
162
|
+
if (entry.name === "node_modules" || entry.name === ".git") continue;
|
|
163
|
+
const full = join(dir, entry.name);
|
|
164
|
+
if (entry.isDirectory()) {
|
|
165
|
+
stack.push(full);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (!entry.isFile()) continue;
|
|
169
|
+
if (files.length >= limit) return { files, truncated: true };
|
|
170
|
+
files.push(describe(relative(root, full).split(sep).join("/"), full));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
files.sort((a, b) => a.path.localeCompare(b.path));
|
|
174
|
+
return { files, truncated: false };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// src/server/_shared.ts
|
|
178
|
+
var DESCRIBE_FILE_LIMIT = FILE_LIST_LIMIT;
|
|
179
|
+
var CATALOG_PAGE_SIZE = 8;
|
|
180
|
+
var CATALOG_PAGE_MAX = 20;
|
|
181
|
+
|
|
182
|
+
// src/mime.ts
|
|
183
|
+
var TYPES = {
|
|
184
|
+
".md": "text/markdown",
|
|
185
|
+
".markdown": "text/markdown",
|
|
186
|
+
".txt": "text/plain",
|
|
187
|
+
".json": "application/json",
|
|
188
|
+
".jsonl": "application/jsonl",
|
|
189
|
+
".yaml": "text/yaml",
|
|
190
|
+
".yml": "text/yaml",
|
|
191
|
+
".toml": "application/toml",
|
|
192
|
+
".csv": "text/csv",
|
|
193
|
+
".tsv": "text/tab-separated-values",
|
|
194
|
+
".xml": "application/xml",
|
|
195
|
+
".html": "text/html",
|
|
196
|
+
".htm": "text/html",
|
|
197
|
+
".css": "text/css",
|
|
198
|
+
".js": "text/javascript",
|
|
199
|
+
".mjs": "text/javascript",
|
|
200
|
+
".cjs": "text/javascript",
|
|
201
|
+
".jsx": "text/javascript",
|
|
202
|
+
".ts": "text/typescript",
|
|
203
|
+
".tsx": "text/typescript",
|
|
204
|
+
".mts": "text/typescript",
|
|
205
|
+
".cts": "text/typescript",
|
|
206
|
+
".py": "text/x-python",
|
|
207
|
+
".rb": "text/x-ruby",
|
|
208
|
+
".go": "text/x-go",
|
|
209
|
+
".rs": "text/x-rust",
|
|
210
|
+
".java": "text/x-java",
|
|
211
|
+
".sh": "text/x-shellscript",
|
|
212
|
+
".bash": "text/x-shellscript",
|
|
213
|
+
".zsh": "text/x-shellscript",
|
|
214
|
+
".ps1": "text/x-powershell",
|
|
215
|
+
".sql": "application/sql",
|
|
216
|
+
".ejs": "text/x-ejs",
|
|
217
|
+
".hbs": "text/x-handlebars-template",
|
|
218
|
+
".mustache": "text/x-mustache",
|
|
219
|
+
".svg": "image/svg+xml",
|
|
220
|
+
".png": "image/png",
|
|
221
|
+
".jpg": "image/jpeg",
|
|
222
|
+
".jpeg": "image/jpeg",
|
|
223
|
+
".gif": "image/gif",
|
|
224
|
+
".webp": "image/webp",
|
|
225
|
+
".avif": "image/avif",
|
|
226
|
+
".ico": "image/x-icon",
|
|
227
|
+
".bmp": "image/bmp",
|
|
228
|
+
".mp3": "audio/mpeg",
|
|
229
|
+
".wav": "audio/wav",
|
|
230
|
+
".ogg": "audio/ogg",
|
|
231
|
+
".m4a": "audio/mp4",
|
|
232
|
+
".flac": "audio/flac",
|
|
233
|
+
".mp4": "video/mp4",
|
|
234
|
+
".webm": "video/webm",
|
|
235
|
+
".pdf": "application/pdf",
|
|
236
|
+
".zip": "application/zip",
|
|
237
|
+
".gz": "application/gzip",
|
|
238
|
+
".tar": "application/x-tar",
|
|
239
|
+
".wasm": "application/wasm",
|
|
240
|
+
".woff": "font/woff",
|
|
241
|
+
".woff2": "font/woff2",
|
|
242
|
+
".ttf": "font/ttf",
|
|
243
|
+
".otf": "font/otf",
|
|
244
|
+
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
245
|
+
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
246
|
+
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
|
247
|
+
};
|
|
248
|
+
var TEXT_APPLICATION = /* @__PURE__ */ new Set([
|
|
249
|
+
"application/json",
|
|
250
|
+
"application/jsonl",
|
|
251
|
+
"application/toml",
|
|
252
|
+
"application/xml",
|
|
253
|
+
"application/sql",
|
|
254
|
+
"image/svg+xml"
|
|
255
|
+
]);
|
|
256
|
+
function mimeOf(path) {
|
|
257
|
+
const slash = path.lastIndexOf("/");
|
|
258
|
+
const dot = path.lastIndexOf(".");
|
|
259
|
+
if (dot === -1 || dot < slash) return null;
|
|
260
|
+
return TYPES[path.slice(dot).toLowerCase()] ?? null;
|
|
261
|
+
}
|
|
262
|
+
function isUtf8Text(bytes) {
|
|
263
|
+
if (bytes.includes(0)) return false;
|
|
264
|
+
try {
|
|
265
|
+
new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
266
|
+
return true;
|
|
267
|
+
} catch {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function classify(path, bytes) {
|
|
272
|
+
const declared = mimeOf(path);
|
|
273
|
+
const textual = declared === null ? isUtf8Text(bytes) : declared.startsWith("text/") || TEXT_APPLICATION.has(declared);
|
|
274
|
+
if (textual && isUtf8Text(bytes)) {
|
|
275
|
+
return { kind: "text", mimeType: declared ?? "text/plain" };
|
|
276
|
+
}
|
|
277
|
+
if (declared?.startsWith("image/") && declared !== "image/svg+xml") {
|
|
278
|
+
return { kind: "image", mimeType: declared };
|
|
279
|
+
}
|
|
280
|
+
if (declared?.startsWith("audio/"))
|
|
281
|
+
return { kind: "audio", mimeType: declared };
|
|
282
|
+
return { kind: "blob", mimeType: declared ?? "application/octet-stream" };
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// src/files/read.ts
|
|
286
|
+
import { readFileSync as readFileSync2, statSync as statSync3 } from "fs";
|
|
287
|
+
|
|
288
|
+
// src/files/resolve.ts
|
|
289
|
+
import { realpathSync, statSync as statSync2 } from "fs";
|
|
290
|
+
import { dirname, isAbsolute, relative as relative2, resolve, sep as sep2 } from "path";
|
|
291
|
+
var ownFile = (entry) => relative2(assetRoot(entry), entry.path).split(sep2).join("/");
|
|
292
|
+
function resolveSkillFile(entry, wanted = ownFile(entry)) {
|
|
293
|
+
if (isAbsolute(wanted) || wanted.split(/[\\/]/u).includes("..")) {
|
|
294
|
+
return { ok: false, error: "path_outside_skill", detail: wanted };
|
|
295
|
+
}
|
|
296
|
+
const scope = realpathSync(assetRoot(entry));
|
|
297
|
+
const single = statSync2(scope).isFile();
|
|
298
|
+
const root = single ? dirname(scope) : scope;
|
|
299
|
+
let target;
|
|
300
|
+
try {
|
|
301
|
+
target = realpathSync(
|
|
302
|
+
single && wanted === "" ? scope : resolve(root, wanted)
|
|
303
|
+
);
|
|
304
|
+
} catch {
|
|
305
|
+
return { ok: false, error: "no_such_file", detail: wanted };
|
|
306
|
+
}
|
|
307
|
+
const inside = single ? target === scope : target === root || target.startsWith(root + sep2);
|
|
308
|
+
if (!inside)
|
|
309
|
+
return { ok: false, error: "path_outside_skill", detail: wanted };
|
|
310
|
+
return {
|
|
311
|
+
ok: true,
|
|
312
|
+
target,
|
|
313
|
+
path: relative2(root, target).split(sep2).join("/")
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// src/files/read.ts
|
|
318
|
+
var READ_BUDGET_BYTES = 256 * 1024;
|
|
319
|
+
function readSkillFile(entry, wanted, budget = READ_BUDGET_BYTES) {
|
|
320
|
+
const resolved = resolveSkillFile(entry, wanted);
|
|
321
|
+
if (!resolved.ok) return resolved;
|
|
322
|
+
const size = statSync3(resolved.target).size;
|
|
323
|
+
if (size > budget) {
|
|
324
|
+
return {
|
|
325
|
+
ok: false,
|
|
326
|
+
error: "over_budget",
|
|
327
|
+
detail: `${size} bytes > ${budget}`
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
const bytes = servedBytes(resolved.target, readFileSync2(resolved.target));
|
|
331
|
+
const { kind: kind2, mimeType } = classify(resolved.path, bytes);
|
|
332
|
+
return {
|
|
333
|
+
ok: true,
|
|
334
|
+
name: entry.name,
|
|
335
|
+
path: resolved.path,
|
|
336
|
+
bytes: bytes.length,
|
|
337
|
+
sha256: sha256(bytes),
|
|
338
|
+
mimeType,
|
|
339
|
+
kind: kind2,
|
|
340
|
+
...kind2 === "text" ? { text: bytes.toString("utf8") } : { blob: bytes.toString("base64") }
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// src/files/uri.ts
|
|
345
|
+
var SKILL_URI_AUTHORITY = "pmcp";
|
|
346
|
+
var PREFIX = `skill://${SKILL_URI_AUTHORITY}/`;
|
|
347
|
+
var skillFileUri = (entry, file = "SKILL.md") => `${PREFIX}${entry.name}/${file}`;
|
|
348
|
+
function resolveSkillFileUri(uri, entries) {
|
|
349
|
+
if (!uri.startsWith(PREFIX)) return null;
|
|
350
|
+
const rest = decodeURI(uri.slice(PREFIX.length));
|
|
351
|
+
let best = null;
|
|
352
|
+
for (const entry of entries) {
|
|
353
|
+
if (!rest.startsWith(`${entry.name}/`)) continue;
|
|
354
|
+
if (best === null || entry.name.length > best.name.length) best = entry;
|
|
355
|
+
}
|
|
356
|
+
if (best === null) return null;
|
|
357
|
+
const file = rest.slice(best.name.length + 1);
|
|
358
|
+
return file === "" ? null : { entry: best, file };
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// src/files/bundle.ts
|
|
362
|
+
import { readFileSync as readFileSync3, statSync as statSync4 } from "fs";
|
|
363
|
+
import { dirname as dirname2, join as join2 } from "path";
|
|
364
|
+
function bundleSkill(entry) {
|
|
365
|
+
const root = assetRoot(entry);
|
|
366
|
+
const base = statSync4(root).isFile() ? dirname2(root) : root;
|
|
367
|
+
const listing2 = listSkillFiles(root);
|
|
368
|
+
return {
|
|
369
|
+
name: entry.name,
|
|
370
|
+
truncated: listing2.truncated,
|
|
371
|
+
files: listing2.files.map((file) => ({
|
|
372
|
+
...file,
|
|
373
|
+
uri: skillFileUri(entry, file.path),
|
|
374
|
+
mimeType: classify(file.path, readFileSync3(join2(base, file.path))).mimeType
|
|
375
|
+
}))
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// src/server/filters.ts
|
|
380
|
+
function matches(entry, filters) {
|
|
381
|
+
const kind2 = filters?.kind ?? "skill";
|
|
382
|
+
if (kind2 !== "any" && kindOf(entry) !== kind2) return false;
|
|
383
|
+
if (!filters) return true;
|
|
384
|
+
const meta = entry.metadata ?? {};
|
|
385
|
+
const field = (key) => {
|
|
386
|
+
const value = meta[key];
|
|
387
|
+
return typeof value === "string" ? value : void 0;
|
|
388
|
+
};
|
|
389
|
+
if (filters.tier !== void 0 && entry.tier !== filters.tier) return false;
|
|
390
|
+
if (filters.package !== void 0 && entry.package !== filters.package)
|
|
391
|
+
return false;
|
|
392
|
+
if (filters.level !== void 0 && field("level") !== filters.level)
|
|
393
|
+
return false;
|
|
394
|
+
if (filters.domain !== void 0 && field("domain") !== filters.domain)
|
|
395
|
+
return false;
|
|
396
|
+
if (filters.medium !== void 0 && field("medium") !== filters.medium)
|
|
397
|
+
return false;
|
|
398
|
+
if (filters.verifiedOnly) {
|
|
399
|
+
const verified = verifiedRuntimesOf(entry.metadata);
|
|
400
|
+
if (filters.runtime === void 0) return verified.length > 0;
|
|
401
|
+
return verified.includes(filters.runtime);
|
|
402
|
+
}
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// src/server/ranking.ts
|
|
407
|
+
function verification(entry, runtime, asked) {
|
|
408
|
+
if (!asked) return {};
|
|
409
|
+
const verifiedRuntimes = verifiedRuntimesOf(entry?.metadata);
|
|
410
|
+
return {
|
|
411
|
+
...verifiedRuntimes.length > 0 ? { verifiedRuntimes } : {},
|
|
412
|
+
...runtime === null ? {} : { verified: verifiedRuntimes.includes(runtime) }
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
function verifiedFirst(items) {
|
|
416
|
+
return [
|
|
417
|
+
...items.filter((item) => item.verified === true),
|
|
418
|
+
...items.filter((item) => item.verified !== true)
|
|
419
|
+
];
|
|
420
|
+
}
|
|
421
|
+
function namedFirst(result, entries, intent) {
|
|
422
|
+
const text = intent.toLowerCase();
|
|
423
|
+
const named = entries.filter((entry) => {
|
|
424
|
+
const slug = entry.slug.toLowerCase();
|
|
425
|
+
if (slug.length < 4) return false;
|
|
426
|
+
const at = text.indexOf(slug);
|
|
427
|
+
if (at === -1) return false;
|
|
428
|
+
const before = text[at - 1] ?? " ";
|
|
429
|
+
const after = text[at + slug.length] ?? " ";
|
|
430
|
+
return !/[a-z0-9-]/.test(before) && !/[a-z0-9-]/.test(after);
|
|
431
|
+
});
|
|
432
|
+
if (named.length === 0) return result;
|
|
433
|
+
const top = result.matches[0]?.score ?? 1;
|
|
434
|
+
const names = new Set(named.map((entry) => entry.name));
|
|
435
|
+
const first = named.map((entry) => ({
|
|
436
|
+
name: entry.name,
|
|
437
|
+
package: entry.package,
|
|
438
|
+
description: entry.description,
|
|
439
|
+
score: result.matches.find((m) => m.name === entry.name)?.score ?? top
|
|
440
|
+
}));
|
|
441
|
+
const rest = result.matches.filter((match) => !names.has(match.name));
|
|
442
|
+
const size = Math.max(result.matches.length, first.length);
|
|
443
|
+
return { ...result, matches: [...first, ...rest].slice(0, size) };
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// src/server/catalog-item.ts
|
|
447
|
+
function catalogItem(entry, runtime, asked) {
|
|
448
|
+
return {
|
|
449
|
+
name: entry.name,
|
|
450
|
+
description: entry.description,
|
|
451
|
+
...entry.tier === void 0 ? {} : { tier: entry.tier },
|
|
452
|
+
...kindOf(entry) === "skill" ? {} : { kind: kindOf(entry) },
|
|
453
|
+
...verification(entry, runtime, asked)
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// src/server/catalog-page.ts
|
|
458
|
+
function catalogOperation(context, request = {}) {
|
|
459
|
+
const { options, catalog, byName } = context;
|
|
460
|
+
const client = options.rankByClientRuntime ? request.clientRuntime : null;
|
|
461
|
+
const runtime = request.runtime ?? client ?? null;
|
|
462
|
+
const asked = runtime !== null || request.verifiedOnly !== void 0;
|
|
463
|
+
const byPackage = /* @__PURE__ */ new Map();
|
|
464
|
+
let count = 0;
|
|
465
|
+
for (const entry of catalog()) {
|
|
466
|
+
if (!matches(entry, {
|
|
467
|
+
tier: request.tier,
|
|
468
|
+
kind: request.kind,
|
|
469
|
+
runtime: request.runtime,
|
|
470
|
+
verifiedOnly: request.verifiedOnly
|
|
471
|
+
}))
|
|
472
|
+
continue;
|
|
473
|
+
count += 1;
|
|
474
|
+
const list = byPackage.get(entry.package) ?? [];
|
|
475
|
+
list.push(catalogItem(entry, runtime, asked));
|
|
476
|
+
byPackage.set(entry.package, list);
|
|
477
|
+
}
|
|
478
|
+
const groups = [...byPackage.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([pkg, skills]) => [
|
|
479
|
+
pkg,
|
|
480
|
+
runtime === null ? skills : verifiedFirst(skills)
|
|
481
|
+
]);
|
|
482
|
+
const size = Math.min(
|
|
483
|
+
Math.max(request.pageSize ?? CATALOG_PAGE_SIZE, 1),
|
|
484
|
+
CATALOG_PAGE_MAX
|
|
485
|
+
);
|
|
486
|
+
const totalPages = Math.max(1, Math.ceil(groups.length / size));
|
|
487
|
+
const page2 = Math.min(Math.max(request.page ?? 1, 1), totalPages);
|
|
488
|
+
return {
|
|
489
|
+
count,
|
|
490
|
+
page: page2,
|
|
491
|
+
totalPages,
|
|
492
|
+
hasNext: page2 < totalPages,
|
|
493
|
+
packages: groups.slice((page2 - 1) * size, page2 * size).map(([pkg, skills]) => ({ package: pkg, skills }))
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// src/server/search.ts
|
|
498
|
+
function findOperation(context, intent, limit, filters, clientRuntime) {
|
|
499
|
+
const { options, catalog, byName } = context;
|
|
500
|
+
const client = options.rankByClientRuntime ? clientRuntime : null;
|
|
501
|
+
const runtime = filters?.runtime ?? client ?? null;
|
|
502
|
+
const asked = runtime !== null || filters?.verifiedOnly !== void 0;
|
|
503
|
+
const scoped = catalog().filter((entry) => matches(entry, filters)).map(
|
|
504
|
+
(entry) => entry.keywords && entry.keywords.length > 0 ? {
|
|
505
|
+
...entry,
|
|
506
|
+
description: `${entry.description} ${entry.keywords.join(" ")}`
|
|
507
|
+
} : entry
|
|
508
|
+
);
|
|
509
|
+
return find({
|
|
510
|
+
entries: scoped,
|
|
511
|
+
intent,
|
|
512
|
+
limit: runtime === null ? limit : scoped.length,
|
|
513
|
+
embedder: options.embedder,
|
|
514
|
+
cache: options.cache,
|
|
515
|
+
vectors: options.vectors
|
|
516
|
+
}).then((ranked) => {
|
|
517
|
+
const result = namedFirst(ranked, scoped, intent);
|
|
518
|
+
const marked = result.matches.map((match) => {
|
|
519
|
+
const entry = byName(match.name) ?? void 0;
|
|
520
|
+
return {
|
|
521
|
+
...match,
|
|
522
|
+
description: entry?.description ?? match.description,
|
|
523
|
+
...verification(entry, runtime, asked)
|
|
524
|
+
};
|
|
525
|
+
});
|
|
526
|
+
const ordered = runtime === null ? marked : verifiedFirst(marked);
|
|
527
|
+
return {
|
|
528
|
+
...result,
|
|
529
|
+
...asked ? { runtime } : {},
|
|
530
|
+
matches: runtime === null ? ordered : ordered.slice(0, limit ?? DEFAULT_FIND_LIMIT)
|
|
531
|
+
};
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// src/server/describe.ts
|
|
536
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
537
|
+
|
|
538
|
+
// src/server/metadata.ts
|
|
539
|
+
function flatMetadata(metadata) {
|
|
540
|
+
const flat = {};
|
|
541
|
+
for (const [key, value] of Object.entries(metadata ?? {})) {
|
|
542
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
543
|
+
flat[key] = value;
|
|
544
|
+
continue;
|
|
545
|
+
}
|
|
546
|
+
for (const [inner, leaf] of Object.entries(value ?? {})) {
|
|
547
|
+
flat[`${key}.${inner}`] = leaf;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return flat;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// src/server/describe.ts
|
|
554
|
+
function describeOperation(context, name) {
|
|
555
|
+
const { options, catalog, byName } = context;
|
|
556
|
+
const entry = byName(name);
|
|
557
|
+
if (!entry) return null;
|
|
558
|
+
const source = readFileSync4(entry.path, "utf8");
|
|
559
|
+
const listing2 = listSkillFiles(assetRoot(entry));
|
|
560
|
+
return {
|
|
561
|
+
name: entry.name,
|
|
562
|
+
kind: kindOf(entry),
|
|
563
|
+
package: entry.package,
|
|
564
|
+
description: entry.description,
|
|
565
|
+
...entry.tier === void 0 ? {} : { tier: entry.tier },
|
|
566
|
+
metadata: flatMetadata(entry.metadata),
|
|
567
|
+
frontmatter: readFrontmatterText(source),
|
|
568
|
+
files: listing2.files.map((file) => ({ ...file })),
|
|
569
|
+
filesTruncated: listing2.truncated
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// src/server/read.ts
|
|
574
|
+
function readOperation(context, name, path) {
|
|
575
|
+
const { options, catalog, byName } = context;
|
|
576
|
+
const entry = byName(name);
|
|
577
|
+
if (!entry) return { ok: false, error: "unknown_skill", detail: name };
|
|
578
|
+
return readSkillFile(entry, path);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// src/server/bundle.ts
|
|
582
|
+
function bundleOperation(context, name) {
|
|
583
|
+
const { options, catalog, byName } = context;
|
|
584
|
+
const entry = byName(name);
|
|
585
|
+
return entry ? bundleSkill(entry) : null;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// src/server/call.ts
|
|
589
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
590
|
+
function callOperation(context, name) {
|
|
591
|
+
const { options, catalog, byName } = context;
|
|
592
|
+
const entry = byName(name);
|
|
593
|
+
if (!entry) return null;
|
|
594
|
+
const bundle = bundleSkill(entry);
|
|
595
|
+
const own = ownFile(entry);
|
|
596
|
+
return {
|
|
597
|
+
name: entry.name,
|
|
598
|
+
body: readBody(
|
|
599
|
+
servedBytes(entry.path, readFileSync5(entry.path)).toString("utf8")
|
|
600
|
+
),
|
|
601
|
+
files: bundle.files.filter((file) => file.path !== own),
|
|
602
|
+
filesTruncated: bundle.truncated
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// src/server/tools.ts
|
|
607
|
+
function createSkillTools(options) {
|
|
608
|
+
const load = options.loadCatalog ?? readCatalog;
|
|
609
|
+
let entries = null;
|
|
610
|
+
const catalog = () => {
|
|
611
|
+
entries ??= load({
|
|
612
|
+
roots: options.roots,
|
|
613
|
+
scopes: options.scopes,
|
|
614
|
+
marketplaces: options.marketplaces,
|
|
615
|
+
packages: options.packages,
|
|
616
|
+
workspaces: options.workspaces,
|
|
617
|
+
onReject: options.onReject,
|
|
618
|
+
onWarning: options.onWarning
|
|
619
|
+
});
|
|
620
|
+
return entries;
|
|
621
|
+
};
|
|
622
|
+
const byName = (name) => {
|
|
623
|
+
const all = catalog();
|
|
624
|
+
const exact = all.find((candidate) => candidate.name === name);
|
|
625
|
+
if (exact) return exact;
|
|
626
|
+
const suffix = `/${name.replace(/^\/+/, "")}`;
|
|
627
|
+
const short = all.filter((candidate) => candidate.name.endsWith(suffix));
|
|
628
|
+
return short.length === 1 ? short[0] : null;
|
|
629
|
+
};
|
|
630
|
+
return {
|
|
631
|
+
catalog(request = {}) {
|
|
632
|
+
return catalogOperation({ options, catalog, byName }, request);
|
|
633
|
+
},
|
|
634
|
+
find(intent, limit, filters, clientRuntime) {
|
|
635
|
+
return findOperation(
|
|
636
|
+
{ options, catalog, byName },
|
|
637
|
+
intent,
|
|
638
|
+
limit,
|
|
639
|
+
filters,
|
|
640
|
+
clientRuntime
|
|
641
|
+
);
|
|
642
|
+
},
|
|
643
|
+
describe(name) {
|
|
644
|
+
return describeOperation({ options, catalog, byName }, name);
|
|
645
|
+
},
|
|
646
|
+
read(name, path) {
|
|
647
|
+
return readOperation({ options, catalog, byName }, name, path);
|
|
648
|
+
},
|
|
649
|
+
bundle(name) {
|
|
650
|
+
return bundleOperation({ options, catalog, byName }, name);
|
|
651
|
+
},
|
|
652
|
+
call(name) {
|
|
653
|
+
return callOperation({ options, catalog, byName }, name);
|
|
654
|
+
},
|
|
655
|
+
entry: (name) => byName(name),
|
|
656
|
+
refresh() {
|
|
657
|
+
entries = null;
|
|
658
|
+
},
|
|
659
|
+
entries: () => catalog().map(withoutBody),
|
|
660
|
+
skills: () => catalog()
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// src/prompts.ts
|
|
665
|
+
import { z } from "zod";
|
|
666
|
+
var promptName = (entry) => entry.name.replace(/^@/u, "").replace(/[^A-Za-z0-9_-]+/gu, "-");
|
|
667
|
+
function messageText(tools, name, task) {
|
|
668
|
+
const found = tools.call(name);
|
|
669
|
+
if (!found) return `The skill ${name} is no longer in this catalog.`;
|
|
670
|
+
const files = found.files.map((file) => `- ${file.path}`);
|
|
671
|
+
const parts = [found.body];
|
|
672
|
+
if (files.length > 0)
|
|
673
|
+
parts.push(
|
|
674
|
+
`Files in skill ${found.name} (skill_read returns each by path):
|
|
675
|
+
${files.join("\n")}`
|
|
676
|
+
);
|
|
677
|
+
if (task) parts.push(`Task: ${task}`);
|
|
678
|
+
return parts.join("\n\n");
|
|
679
|
+
}
|
|
680
|
+
function registerSkillPrompts(server, tools) {
|
|
681
|
+
const taken = /* @__PURE__ */ new Set();
|
|
682
|
+
for (const entry of tools.skills()) {
|
|
683
|
+
if (kindOf(entry) !== "skill") continue;
|
|
684
|
+
const name = promptName(entry);
|
|
685
|
+
if (taken.has(name)) continue;
|
|
686
|
+
taken.add(name);
|
|
687
|
+
server.registerPrompt(
|
|
688
|
+
name,
|
|
689
|
+
{
|
|
690
|
+
title: entry.name,
|
|
691
|
+
description: entry.description,
|
|
692
|
+
argsSchema: z.object({
|
|
693
|
+
task: z.string().optional().describe("What to apply the skill to.")
|
|
694
|
+
})
|
|
695
|
+
},
|
|
696
|
+
({ task }) => ({
|
|
697
|
+
messages: [
|
|
698
|
+
{
|
|
699
|
+
role: "user",
|
|
700
|
+
content: {
|
|
701
|
+
type: "text",
|
|
702
|
+
text: messageText(tools, entry.name, task)
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
]
|
|
706
|
+
})
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// src/resources.ts
|
|
712
|
+
import { statSync as statSync5 } from "fs";
|
|
713
|
+
import {
|
|
714
|
+
ResourceNotFoundError,
|
|
715
|
+
ResourceTemplate
|
|
716
|
+
} from "@modelcontextprotocol/server";
|
|
717
|
+
var RESOURCE_READ_BUDGET = 16 * 1024 * 1024;
|
|
718
|
+
var COMPLETION_LIMIT = 100;
|
|
719
|
+
function listing(entries) {
|
|
720
|
+
return entries.filter((entry) => kindOf(entry) === "skill").map((entry) => ({
|
|
721
|
+
uri: skillFileUri(entry, ownFile(entry)),
|
|
722
|
+
name: entry.name,
|
|
723
|
+
description: entry.description,
|
|
724
|
+
mimeType: "text/markdown",
|
|
725
|
+
size: statSync5(entry.path).size
|
|
726
|
+
}));
|
|
727
|
+
}
|
|
728
|
+
function complete(value, entries) {
|
|
729
|
+
const owner = entries.find((entry) => value.startsWith(`${entry.name}/`));
|
|
730
|
+
if (!owner) {
|
|
731
|
+
return entries.map((entry) => `${entry.name}/`).filter((name) => name.startsWith(value)).slice(0, COMPLETION_LIMIT);
|
|
732
|
+
}
|
|
733
|
+
return listSkillFiles(assetRoot(owner)).files.map((file) => `${owner.name}/${file.path}`).filter((path) => path.startsWith(value)).slice(0, COMPLETION_LIMIT);
|
|
734
|
+
}
|
|
735
|
+
function registerSkillResources(server, skills) {
|
|
736
|
+
server.registerResource(
|
|
737
|
+
"skill-files",
|
|
738
|
+
new ResourceTemplate(`skill://${SKILL_URI_AUTHORITY}/{+path}`, {
|
|
739
|
+
list: () => ({ resources: listing(skills()) }),
|
|
740
|
+
complete: { path: (value) => complete(value, skills()) }
|
|
741
|
+
}),
|
|
742
|
+
{
|
|
743
|
+
title: "Skill files",
|
|
744
|
+
description: "Files of the skills this catalog serves: SKILL.md, references, scripts and assets."
|
|
745
|
+
},
|
|
746
|
+
async (uri) => {
|
|
747
|
+
const href = uri.toString();
|
|
748
|
+
const found = resolveSkillFileUri(href, skills());
|
|
749
|
+
if (!found) throw new ResourceNotFoundError(href);
|
|
750
|
+
const file = readSkillFile(found.entry, found.file, RESOURCE_READ_BUDGET);
|
|
751
|
+
if (!file.ok) throw new ResourceNotFoundError(href);
|
|
752
|
+
return {
|
|
753
|
+
contents: [
|
|
754
|
+
file.kind === "text" ? { uri: href, mimeType: file.mimeType, text: file.text ?? "" } : { uri: href, mimeType: file.mimeType, blob: file.blob ?? "" }
|
|
755
|
+
]
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
// src/extension/entry.ts
|
|
762
|
+
import { createHash as createHash3 } from "crypto";
|
|
763
|
+
import { readFileSync as readFileSync6, readdirSync as readdirSync2, statSync as statSync6 } from "fs";
|
|
764
|
+
import { basename as basename3, dirname as dirname3, join as join3, relative as relative3, sep as sep3 } from "path";
|
|
765
|
+
var MAX_RESOURCES = 512;
|
|
766
|
+
var MAX_SKILL_BYTES = 16 * 1024 * 1024;
|
|
767
|
+
var digests = /* @__PURE__ */ new Map();
|
|
768
|
+
function facts(path) {
|
|
769
|
+
const stat = statSync6(path);
|
|
770
|
+
const key = `${stat.mtimeMs}:${stat.size}`;
|
|
771
|
+
const cached = digests.get(path);
|
|
772
|
+
if (cached?.key === key) return cached;
|
|
773
|
+
const bytes = servedBytes(path, readFileSync6(path));
|
|
774
|
+
const digest = `sha256:${createHash3("sha256").update(bytes).digest("hex")}`;
|
|
775
|
+
const fresh = { key, digest, size: bytes.length };
|
|
776
|
+
digests.set(path, fresh);
|
|
777
|
+
return fresh;
|
|
778
|
+
}
|
|
779
|
+
function filesUnder(root) {
|
|
780
|
+
const found = [];
|
|
781
|
+
const stack = [root];
|
|
782
|
+
while (stack.length > 0) {
|
|
783
|
+
const dir = stack.pop();
|
|
784
|
+
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
785
|
+
if (entry.name === "node_modules" || entry.name === ".git") continue;
|
|
786
|
+
const full = join3(dir, entry.name);
|
|
787
|
+
if (entry.isDirectory()) stack.push(full);
|
|
788
|
+
else if (entry.isFile()) found.push(full);
|
|
789
|
+
if (found.length > MAX_RESOURCES) return null;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
return found.sort();
|
|
793
|
+
}
|
|
794
|
+
function extensionEntry(entry) {
|
|
795
|
+
if (kindOf(entry) !== "skill" || basename3(entry.path) !== "SKILL.md")
|
|
796
|
+
return null;
|
|
797
|
+
const frontmatter = frontmatterObject(readFileSync6(entry.path, "utf8"));
|
|
798
|
+
const root = dirname3(entry.path);
|
|
799
|
+
if (specProblems(frontmatter, basename3(root)).length > 0) return null;
|
|
800
|
+
if (frontmatter?.["name"] !== entry.slug) return null;
|
|
801
|
+
const files = filesUnder(root);
|
|
802
|
+
if (files === null) return null;
|
|
803
|
+
let total = 0;
|
|
804
|
+
const resources = files.map((path) => {
|
|
805
|
+
const fact = facts(path);
|
|
806
|
+
total += fact.size;
|
|
807
|
+
const file = relative3(root, path).split(sep3).join("/");
|
|
808
|
+
return {
|
|
809
|
+
uri: skillFileUri(entry, file),
|
|
810
|
+
digest: fact.digest,
|
|
811
|
+
size: fact.size
|
|
812
|
+
};
|
|
813
|
+
});
|
|
814
|
+
if (total > MAX_SKILL_BYTES) return null;
|
|
815
|
+
return { uri: skillFileUri(entry), frontmatter, resources };
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
// src/extension/register.ts
|
|
819
|
+
import {
|
|
820
|
+
ProtocolError,
|
|
821
|
+
ProtocolErrorCode
|
|
822
|
+
} from "@modelcontextprotocol/server";
|
|
823
|
+
import { z as z2 } from "zod";
|
|
824
|
+
var SKILLS_EXTENSION = "io.modelcontextprotocol/skills";
|
|
825
|
+
var PAGE_SIZE = 50;
|
|
826
|
+
var TTL_MS = 6e4;
|
|
827
|
+
function entriesOf(skills) {
|
|
828
|
+
let memo = null;
|
|
829
|
+
return () => {
|
|
830
|
+
const source = skills();
|
|
831
|
+
if (memo?.source === source) return memo.entries;
|
|
832
|
+
const map = /* @__PURE__ */ new Map();
|
|
833
|
+
for (const entry of source) {
|
|
834
|
+
try {
|
|
835
|
+
const served = extensionEntry(entry);
|
|
836
|
+
if (served) map.set(served.uri, served);
|
|
837
|
+
} catch {
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
memo = { source, entries: map };
|
|
841
|
+
return map;
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
function page(all, cursor) {
|
|
845
|
+
const start = cursor ? Number.parseInt(cursor, 10) : 0;
|
|
846
|
+
if (!Number.isInteger(start) || start < 0 || start > all.length) {
|
|
847
|
+
throw new ProtocolError(ProtocolErrorCode.InvalidParams, "invalid cursor");
|
|
848
|
+
}
|
|
849
|
+
const end = start + PAGE_SIZE;
|
|
850
|
+
return {
|
|
851
|
+
skills: all.slice(start, end),
|
|
852
|
+
...end < all.length ? { nextCursor: String(end) } : {}
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
function registerSkillsExtension(server, skills, options = {}) {
|
|
856
|
+
const entries = entriesOf(skills);
|
|
857
|
+
const cache = { ttlMs: TTL_MS, cacheScope: options.cacheScope ?? "public" };
|
|
858
|
+
server.server.registerCapabilities({
|
|
859
|
+
extensions: { [SKILLS_EXTENSION]: {} }
|
|
860
|
+
});
|
|
861
|
+
server.server.setRequestHandler(
|
|
862
|
+
"skills/list",
|
|
863
|
+
{ params: z2.object({ cursor: z2.string().optional() }).passthrough() },
|
|
864
|
+
async (params) => ({
|
|
865
|
+
resultType: "complete",
|
|
866
|
+
...page([...entries().values()], params.cursor),
|
|
867
|
+
...cache
|
|
868
|
+
})
|
|
869
|
+
);
|
|
870
|
+
server.server.setRequestHandler(
|
|
871
|
+
"skills/get",
|
|
872
|
+
{ params: z2.object({ uri: z2.string() }).passthrough() },
|
|
873
|
+
async (params) => {
|
|
874
|
+
const skill = entries().get(params.uri);
|
|
875
|
+
if (!skill) {
|
|
876
|
+
throw new ProtocolError(
|
|
877
|
+
ProtocolErrorCode.InvalidParams,
|
|
878
|
+
`not a skill this server serves: ${params.uri}`
|
|
879
|
+
);
|
|
880
|
+
}
|
|
881
|
+
return { resultType: "complete", skill, ...cache };
|
|
882
|
+
}
|
|
883
|
+
);
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
// src/tools/schemas.ts
|
|
887
|
+
import { z as z3 } from "zod";
|
|
888
|
+
var kind = z3.enum(ASSET_KINDS);
|
|
889
|
+
var runtimeSchema = z3.enum(RUNTIMES);
|
|
890
|
+
var catalogItemSchema = z3.looseObject({
|
|
891
|
+
name: z3.string(),
|
|
892
|
+
description: z3.string(),
|
|
893
|
+
tier: z3.string().optional(),
|
|
894
|
+
kind: kind.optional(),
|
|
895
|
+
verifiedRuntimes: z3.array(runtimeSchema).optional(),
|
|
896
|
+
verified: z3.boolean().optional()
|
|
897
|
+
});
|
|
898
|
+
var catalogResponseSchema = z3.looseObject({
|
|
899
|
+
count: z3.number().int(),
|
|
900
|
+
page: z3.number().int(),
|
|
901
|
+
totalPages: z3.number().int(),
|
|
902
|
+
hasNext: z3.boolean(),
|
|
903
|
+
packages: z3.array(
|
|
904
|
+
z3.looseObject({ package: z3.string(), skills: z3.array(catalogItemSchema) })
|
|
905
|
+
)
|
|
906
|
+
});
|
|
907
|
+
var findResultSchema = z3.looseObject({
|
|
908
|
+
ranking: z3.enum(["semantic", "lexical"]),
|
|
909
|
+
runtime: runtimeSchema.nullable().optional(),
|
|
910
|
+
matches: z3.array(
|
|
911
|
+
z3.looseObject({
|
|
912
|
+
name: z3.string(),
|
|
913
|
+
package: z3.string(),
|
|
914
|
+
description: z3.string(),
|
|
915
|
+
score: z3.number(),
|
|
916
|
+
verifiedRuntimes: z3.array(runtimeSchema).optional(),
|
|
917
|
+
verified: z3.boolean().optional()
|
|
918
|
+
})
|
|
919
|
+
)
|
|
920
|
+
});
|
|
921
|
+
var skillFileSchema = z3.looseObject({
|
|
922
|
+
path: z3.string(),
|
|
923
|
+
bytes: z3.number().int(),
|
|
924
|
+
sha256: z3.string()
|
|
925
|
+
});
|
|
926
|
+
var describeResponseSchema = z3.looseObject({
|
|
927
|
+
name: z3.string(),
|
|
928
|
+
kind,
|
|
929
|
+
package: z3.string(),
|
|
930
|
+
description: z3.string(),
|
|
931
|
+
tier: z3.string().optional(),
|
|
932
|
+
metadata: z3.record(
|
|
933
|
+
z3.string(),
|
|
934
|
+
z3.union([z3.string(), z3.array(z3.string()).readonly()])
|
|
935
|
+
),
|
|
936
|
+
frontmatter: z3.string(),
|
|
937
|
+
files: z3.array(skillFileSchema),
|
|
938
|
+
filesTruncated: z3.boolean()
|
|
939
|
+
});
|
|
940
|
+
var bundleResponseSchema = z3.looseObject({
|
|
941
|
+
name: z3.string(),
|
|
942
|
+
truncated: z3.boolean(),
|
|
943
|
+
files: z3.array(
|
|
944
|
+
skillFileSchema.extend({ uri: z3.string(), mimeType: z3.string() })
|
|
945
|
+
)
|
|
946
|
+
});
|
|
947
|
+
|
|
948
|
+
// src/mcp.ts
|
|
949
|
+
import { McpServer } from "@modelcontextprotocol/server";
|
|
950
|
+
|
|
951
|
+
// src/tools/bundle.ts
|
|
952
|
+
import { z as z5 } from "zod";
|
|
953
|
+
|
|
954
|
+
// src/tools/content.ts
|
|
955
|
+
function fileBlock(file) {
|
|
956
|
+
if (file.kind === "text") {
|
|
957
|
+
return { type: "text", text: file.text ?? "" };
|
|
958
|
+
}
|
|
959
|
+
if (file.kind === "image" || file.kind === "audio") {
|
|
960
|
+
return {
|
|
961
|
+
type: file.kind,
|
|
962
|
+
data: file.blob ?? "",
|
|
963
|
+
mimeType: file.mimeType
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
return {
|
|
967
|
+
type: "resource",
|
|
968
|
+
resource: {
|
|
969
|
+
uri: skillFileUri({ name: file.name }, file.path),
|
|
970
|
+
mimeType: file.mimeType,
|
|
971
|
+
blob: file.blob ?? ""
|
|
972
|
+
}
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
var resourceLink = (file) => ({
|
|
976
|
+
type: "resource_link",
|
|
977
|
+
uri: file.uri,
|
|
978
|
+
name: file.path,
|
|
979
|
+
mimeType: file.mimeType,
|
|
980
|
+
size: file.bytes
|
|
981
|
+
});
|
|
982
|
+
|
|
983
|
+
// src/tools/shared.ts
|
|
984
|
+
import { z as z4 } from "zod";
|
|
985
|
+
var readOnly = {
|
|
986
|
+
readOnlyHint: true,
|
|
987
|
+
destructiveHint: false,
|
|
988
|
+
idempotentHint: true,
|
|
989
|
+
openWorldHint: false
|
|
990
|
+
};
|
|
991
|
+
var readOnlyTool = (title) => ({
|
|
992
|
+
title,
|
|
993
|
+
annotations: { ...readOnly, title }
|
|
994
|
+
});
|
|
995
|
+
var kindInput = z4.enum(["skill", "agent", "hook", "mcp", "any"]).optional().describe(
|
|
996
|
+
"skill (default), agent, hook, mcp, or any. Commands are skills; agents, hooks and MCP servers are installed with pmcp add rather than read."
|
|
997
|
+
);
|
|
998
|
+
var tierInput = z4.enum(["open", "free", "paid", "internal"]).optional();
|
|
999
|
+
var runtimeInput = runtimeSchema.optional().describe(
|
|
1000
|
+
"A runtime (claude-code, codex-cli, gemini-cli, grok-cli, antigravity). Skills whose metadata.verified-runtimes lists it are marked verified and listed first; the rest are kept. Without it, the order is the same as without verification data."
|
|
1001
|
+
);
|
|
1002
|
+
var verifiedOnlyInput = z4.boolean().optional().describe(
|
|
1003
|
+
"Drop skills that are not verified: on the given runtime, or on any runtime when none is given. The detected client runtime never filters."
|
|
1004
|
+
);
|
|
1005
|
+
var skillNameInput = z4.string().min(1).describe("A skill name as skill_find or skill_catalog returns it.");
|
|
1006
|
+
var asText = (value) => ({
|
|
1007
|
+
content: [{ type: "text", text: JSON.stringify(value, null, 2) }]
|
|
1008
|
+
});
|
|
1009
|
+
var structured = (value) => ({
|
|
1010
|
+
...asText(value),
|
|
1011
|
+
structuredContent: { ...value }
|
|
1012
|
+
});
|
|
1013
|
+
var unknownSkill = (name) => ({
|
|
1014
|
+
...asText({
|
|
1015
|
+
error: "unknown_skill",
|
|
1016
|
+
name,
|
|
1017
|
+
hint: "skill_catalog lists the names that exist."
|
|
1018
|
+
}),
|
|
1019
|
+
isError: true
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
// src/tools/bundle.ts
|
|
1023
|
+
function registerBundleTool(server, tools) {
|
|
1024
|
+
server.registerTool(
|
|
1025
|
+
"skill_bundle",
|
|
1026
|
+
{
|
|
1027
|
+
...readOnlyTool("List a skill's files"),
|
|
1028
|
+
description: "Every file of one skill with its path relative to the skill directory, size, media type and sha256, as resource links that resources/read returns. The bytes are not included in this result. Used to write a skill to a local skills directory.",
|
|
1029
|
+
inputSchema: z5.object({ name: skillNameInput }),
|
|
1030
|
+
outputSchema: bundleResponseSchema
|
|
1031
|
+
},
|
|
1032
|
+
async ({ name }) => {
|
|
1033
|
+
const bundle = tools.bundle(name);
|
|
1034
|
+
if (!bundle) return unknownSkill(name);
|
|
1035
|
+
const value = { ...bundle, files: [...bundle.files] };
|
|
1036
|
+
return {
|
|
1037
|
+
content: [
|
|
1038
|
+
{ type: "text", text: JSON.stringify(value, null, 2) },
|
|
1039
|
+
...bundle.files.map(resourceLink)
|
|
1040
|
+
],
|
|
1041
|
+
structuredContent: value
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
1044
|
+
);
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
// src/tools/call.ts
|
|
1048
|
+
import { z as z6 } from "zod";
|
|
1049
|
+
function manifest(found) {
|
|
1050
|
+
const lines = found.files.map(
|
|
1051
|
+
(file) => `- ${file.path} (${file.bytes} bytes, ${file.mimeType}, sha256 ${file.sha256.slice(0, 12)})`
|
|
1052
|
+
);
|
|
1053
|
+
if (found.filesTruncated)
|
|
1054
|
+
lines.push("- (list cut; skill_bundle has the rest)");
|
|
1055
|
+
return [
|
|
1056
|
+
`Files in skill ${found.name}. skill_read returns one by this name and its path; skill_bundle returns every file with its path:`,
|
|
1057
|
+
...lines
|
|
1058
|
+
].join("\n");
|
|
1059
|
+
}
|
|
1060
|
+
function registerCallTool(server, tools) {
|
|
1061
|
+
server.registerTool(
|
|
1062
|
+
"skill_call",
|
|
1063
|
+
{
|
|
1064
|
+
...readOnlyTool("Read a skill"),
|
|
1065
|
+
description: "The body of a single skill, by the name skill_find or skill_catalog returned, followed by the list of reference, script and asset files the skill carries, if any, as text; skill_read returns one of them and skill_bundle links them all. This is the only call that costs a document.",
|
|
1066
|
+
inputSchema: z6.object({
|
|
1067
|
+
name: z6.string().min(1).describe("The skill name, as <package>/<slug>.")
|
|
1068
|
+
})
|
|
1069
|
+
},
|
|
1070
|
+
async ({ name }) => {
|
|
1071
|
+
const found = tools.call(name);
|
|
1072
|
+
if (!found) return unknownSkill(name);
|
|
1073
|
+
const body = { type: "text", text: found.body };
|
|
1074
|
+
if (found.files.length === 0) return { content: [body] };
|
|
1075
|
+
return {
|
|
1076
|
+
content: [body, { type: "text", text: manifest(found) }]
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
);
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
// src/tools/catalog.ts
|
|
1083
|
+
import { z as z7 } from "zod";
|
|
1084
|
+
function registerCatalogTool(server, tools) {
|
|
1085
|
+
server.registerTool(
|
|
1086
|
+
"skill_catalog",
|
|
1087
|
+
{
|
|
1088
|
+
...readOnlyTool("List skills"),
|
|
1089
|
+
description: "Every skill the installed packages and marketplaces ship, grouped by package or plugin, with names, one-line descriptions and tier, and no bodies. Paged by group. With kind it lists agents, hooks or MCP servers instead. Items list the runtimes they were verified on (verifiedRuntimes). With runtime, verified items are marked and listed first within their group but the others are kept; verifiedOnly drops the unverified ones.",
|
|
1090
|
+
inputSchema: z7.object({
|
|
1091
|
+
page: z7.number().int().min(1).optional(),
|
|
1092
|
+
pageSize: z7.number().int().min(1).max(20).optional(),
|
|
1093
|
+
tier: tierInput,
|
|
1094
|
+
kind: kindInput,
|
|
1095
|
+
runtime: runtimeInput,
|
|
1096
|
+
verifiedOnly: verifiedOnlyInput
|
|
1097
|
+
}),
|
|
1098
|
+
outputSchema: catalogResponseSchema
|
|
1099
|
+
},
|
|
1100
|
+
async (request, ctx) => structured(
|
|
1101
|
+
tools.catalog({
|
|
1102
|
+
...request,
|
|
1103
|
+
clientRuntime: detectRuntime(server, ctx)
|
|
1104
|
+
})
|
|
1105
|
+
)
|
|
1106
|
+
);
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
// src/tools/describe.ts
|
|
1110
|
+
import { z as z8 } from "zod";
|
|
1111
|
+
function registerDescribeTool(server, tools) {
|
|
1112
|
+
server.registerTool(
|
|
1113
|
+
"skill_describe",
|
|
1114
|
+
{
|
|
1115
|
+
...readOnlyTool("Describe a skill"),
|
|
1116
|
+
description: "One skill's frontmatter, metadata (tier, level, requirements as requires.<name> entries, verified-runtimes, licence, approval), and the files it carries with sizes and sha256, without any body.",
|
|
1117
|
+
inputSchema: z8.object({ name: skillNameInput }),
|
|
1118
|
+
outputSchema: describeResponseSchema
|
|
1119
|
+
},
|
|
1120
|
+
async ({ name }) => {
|
|
1121
|
+
const described = tools.describe(name);
|
|
1122
|
+
return described ? structured(described) : unknownSkill(name);
|
|
1123
|
+
}
|
|
1124
|
+
);
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
// src/tools/find.ts
|
|
1128
|
+
import { z as z9 } from "zod";
|
|
1129
|
+
function registerFindTool(server, tools) {
|
|
1130
|
+
server.registerTool(
|
|
1131
|
+
"skill_find",
|
|
1132
|
+
{
|
|
1133
|
+
...readOnlyTool("Find skills"),
|
|
1134
|
+
description: "Skill names ranked against an intent, with descriptions and scores, and no bodies. The ranking compares the intent with skill descriptions, so a full sentence matches better than a single keyword. Each match lists the runtimes it was verified on (verifiedRuntimes). With runtime, verified matches are marked and listed first but the others are kept; verifiedOnly drops the unverified ones. The answer's runtime is the one the ordering used, or null.",
|
|
1135
|
+
inputSchema: z9.object({
|
|
1136
|
+
intent: z9.string().min(1).max(256).describe("What the task is, as a sentence."),
|
|
1137
|
+
limit: z9.number().int().min(1).max(25).optional(),
|
|
1138
|
+
runtime: runtimeInput,
|
|
1139
|
+
verifiedOnly: verifiedOnlyInput,
|
|
1140
|
+
filters: z9.object({
|
|
1141
|
+
kind: kindInput,
|
|
1142
|
+
tier: tierInput,
|
|
1143
|
+
package: z9.string().optional(),
|
|
1144
|
+
level: z9.string().optional(),
|
|
1145
|
+
domain: z9.string().optional(),
|
|
1146
|
+
medium: z9.string().optional()
|
|
1147
|
+
}).optional().describe("Exact-match filters over the catalog before ranking.")
|
|
1148
|
+
}),
|
|
1149
|
+
outputSchema: findResultSchema
|
|
1150
|
+
},
|
|
1151
|
+
async ({ intent, limit, runtime, verifiedOnly, filters }, ctx) => structured(
|
|
1152
|
+
await tools.find(
|
|
1153
|
+
intent,
|
|
1154
|
+
limit,
|
|
1155
|
+
{ ...filters, runtime, verifiedOnly },
|
|
1156
|
+
detectRuntime(server, ctx)
|
|
1157
|
+
)
|
|
1158
|
+
)
|
|
1159
|
+
);
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
// src/tools/read.ts
|
|
1163
|
+
import { z as z10 } from "zod";
|
|
1164
|
+
function registerReadTool(server, tools) {
|
|
1165
|
+
server.registerTool(
|
|
1166
|
+
"skill_read",
|
|
1167
|
+
{
|
|
1168
|
+
...readOnlyTool("Read a skill file"),
|
|
1169
|
+
description: "One file inside a skill's directory in this catalog, with its sha256 and media type: text as text, images and audio as image and audio content, other binary files as an embedded resource. path is relative to the skill, as skill_call, skill_bundle and skill_describe list it (layout: https://pmcp.build). Scripts are returned as content, never run, and no external API is called. Files over 256 KiB and paths outside the skill are refused.",
|
|
1170
|
+
inputSchema: z10.object({
|
|
1171
|
+
name: skillNameInput,
|
|
1172
|
+
path: z10.string().min(1).optional().describe(
|
|
1173
|
+
"Path relative to the skill directory. Defaults to SKILL.md."
|
|
1174
|
+
)
|
|
1175
|
+
})
|
|
1176
|
+
},
|
|
1177
|
+
async ({ name, path }) => {
|
|
1178
|
+
const result = tools.read(name, path);
|
|
1179
|
+
if (!result.ok) return { ...asText(result), isError: true };
|
|
1180
|
+
const { text: _text, blob: _blob, ...header } = result;
|
|
1181
|
+
return {
|
|
1182
|
+
content: [
|
|
1183
|
+
{ type: "text", text: JSON.stringify(header) },
|
|
1184
|
+
fileBlock(result)
|
|
1185
|
+
]
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
1188
|
+
);
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
// src/mcp.ts
|
|
1192
|
+
var SERVER_NAME = "pmcp";
|
|
1193
|
+
var SERVER_VERSION = "0.18.0";
|
|
1194
|
+
function registerSkillTools(server, tools) {
|
|
1195
|
+
registerCatalogTool(server, tools);
|
|
1196
|
+
registerFindTool(server, tools);
|
|
1197
|
+
registerDescribeTool(server, tools);
|
|
1198
|
+
registerReadTool(server, tools);
|
|
1199
|
+
registerCallTool(server, tools);
|
|
1200
|
+
registerBundleTool(server, tools);
|
|
1201
|
+
return server;
|
|
1202
|
+
}
|
|
1203
|
+
function createSkillServer(options) {
|
|
1204
|
+
const server = new McpServer({ name: SERVER_NAME, version: SERVER_VERSION });
|
|
1205
|
+
const tools = createSkillTools(options);
|
|
1206
|
+
registerSkillsExtension(server, tools.skills, options.skillsExtension);
|
|
1207
|
+
registerSkillResources(server, tools.skills);
|
|
1208
|
+
if (options.prompts) registerSkillPrompts(server, tools);
|
|
1209
|
+
if (options.mailbox) registerMailboxTools(server, options.mailbox);
|
|
1210
|
+
return registerSkillTools(server, tools);
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
export {
|
|
1214
|
+
DEFAULT_FIND_LIMIT,
|
|
1215
|
+
lexicalScore,
|
|
1216
|
+
cosine,
|
|
1217
|
+
find,
|
|
1218
|
+
listSkillFiles,
|
|
1219
|
+
DESCRIBE_FILE_LIMIT,
|
|
1220
|
+
CATALOG_PAGE_SIZE,
|
|
1221
|
+
CATALOG_PAGE_MAX,
|
|
1222
|
+
mimeOf,
|
|
1223
|
+
isUtf8Text,
|
|
1224
|
+
classify,
|
|
1225
|
+
READ_BUDGET_BYTES,
|
|
1226
|
+
readSkillFile,
|
|
1227
|
+
skillFileUri,
|
|
1228
|
+
resolveSkillFileUri,
|
|
1229
|
+
bundleSkill,
|
|
1230
|
+
createSkillTools,
|
|
1231
|
+
promptName,
|
|
1232
|
+
registerSkillPrompts,
|
|
1233
|
+
registerSkillResources,
|
|
1234
|
+
extensionEntry,
|
|
1235
|
+
SKILLS_EXTENSION,
|
|
1236
|
+
registerSkillsExtension,
|
|
1237
|
+
catalogResponseSchema,
|
|
1238
|
+
findResultSchema,
|
|
1239
|
+
describeResponseSchema,
|
|
1240
|
+
bundleResponseSchema,
|
|
1241
|
+
SERVER_NAME,
|
|
1242
|
+
SERVER_VERSION,
|
|
1243
|
+
registerSkillTools,
|
|
1244
|
+
createSkillServer
|
|
1245
|
+
};
|
|
1246
|
+
//# sourceMappingURL=chunk-25GHX674.js.map
|