@engenty/wizards-runtime 0.17.0 → 0.17.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/apps/runtime/dist/app.js +2 -0
- package/apps/runtime/dist/broker/account.js +20 -1
- package/apps/runtime/dist/broker/call.js +116 -20
- package/apps/runtime/dist/broker/host.js +8 -2
- package/apps/runtime/dist/broker/index.js +3 -2
- package/apps/runtime/dist/broker/log.js +149 -14
- package/apps/runtime/dist/broker/over.js +38 -0
- package/apps/runtime/dist/broker/rights.js +192 -0
- package/apps/runtime/dist/broker/rwx.js +295 -51
- package/apps/runtime/dist/broker/send.js +25 -12
- package/apps/runtime/dist/bundles/fetch.js +119 -0
- package/apps/runtime/dist/bundles/index.js +621 -0
- package/apps/runtime/dist/bundles/read.js +607 -0
- package/apps/runtime/dist/connectors/external.js +532 -61
- package/apps/runtime/dist/connectors/person-sign-ins.js +1 -0
- package/apps/runtime/dist/connectors/reload.js +73 -0
- package/apps/runtime/dist/connectors/space-connections.js +73 -6
- package/apps/runtime/dist/db/migrations/tenant/0058_mcp_state_across_roles.sql +26 -0
- package/apps/runtime/dist/db/migrations/tenant/0059_space_connection_paused.sql +2 -0
- package/apps/runtime/dist/db/migrations/tenant/0060_space_bundle.sql +21 -0
- package/apps/runtime/dist/db/migrations/tenant/0061_space_connection_limits.sql +2 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0058_snapshot.json +6696 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0059_snapshot.json +6710 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0060_snapshot.json +6857 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0061_snapshot.json +6871 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +28 -0
- package/apps/runtime/dist/db/schema.js +81 -3
- package/apps/runtime/dist/docs/dev/broker.md +251 -31
- package/apps/runtime/dist/docs/user-guide/capabilities.md +123 -5
- package/apps/runtime/dist/docs/user-guide/connectors.md +52 -5
- package/apps/runtime/dist/docs/user-guide/protocol.md +15 -4
- package/apps/runtime/dist/docs/user-guide/test-and-share.md +1 -1
- package/apps/runtime/dist/elements/caller.js +2 -2
- package/apps/runtime/dist/engenty/connections-external/build-connector.js +23 -8
- package/apps/runtime/dist/engenty/connections-external/import-service.js +18 -9
- package/apps/runtime/dist/engenty/connections-external/importer/classify.js +12 -0
- package/apps/runtime/dist/engenty/connections-external/invoke/http-invoker.js +1 -0
- package/apps/runtime/dist/engenty/connections-external/net/guarded-fetch.js +6 -3
- package/apps/runtime/dist/engenty/connections-sdk/oauth2.js +2 -2
- package/apps/runtime/dist/engenty/shims/web-ingest.js +64 -0
- package/apps/runtime/dist/engine/resources.js +15 -6
- package/apps/runtime/dist/engine/runner.js +2 -1
- package/apps/runtime/dist/env.js +2 -0
- package/apps/runtime/dist/index.js +11 -2
- package/apps/runtime/dist/mcp/handler.js +2 -2
- package/apps/runtime/dist/mcp/seen.js +71 -51
- package/apps/runtime/dist/mcp/tools.js +5 -1
- package/apps/runtime/dist/prompts/mcp.md +1 -1
- package/apps/runtime/dist/prompts/tools.md +16 -0
- package/apps/runtime/dist/routes/broker.js +1 -1
- package/apps/runtime/dist/routes/bundles.js +91 -0
- package/apps/runtime/dist/routes/connections.js +14 -3
- package/apps/runtime/dist/routes/rules.js +53 -9
- package/apps/runtime/dist/routes/studio.js +23 -18
- package/apps/runtime/dist/services/cloud.js +2 -0
- package/apps/runtime/dist/services/draft-events.js +79 -6
- package/apps/runtime/dist/services/files.js +2 -2
- package/apps/runtime/dist/services/skills.js +61 -5
- package/apps/runtime/dist/services/space-index.js +102 -10
- package/apps/runtime/dist/services/synced-spaces.js +5 -1
- package/apps/runtime/dist/services/wizards.js +48 -2
- package/apps/runtime/dist/sharing/jobs.js +6 -2
- package/apps/runtime/dist/sync/records.js +6 -1
- package/apps/runtime/dist/texts.js +36 -1
- package/apps/runtime/dist/tools/connections.js +8 -0
- package/apps/runtime/dist/tools/connector.js +13 -1
- package/apps/runtime/dist/tools/index.js +8 -3
- package/apps/runtime/dist/tools/skills.js +11 -1
- package/apps/web/dist/assets/{AboutDialog-B2Xmxyj4.js → AboutDialog-mZCBU7KF.js} +1 -1
- package/apps/web/dist/assets/{BlockEditor-D0HoUSih.js → BlockEditor-Dk0QwLSU.js} +1 -1
- package/apps/web/dist/assets/CapabilitiesPage-GkpgF-wZ.js +2 -0
- package/apps/web/dist/assets/{ChangelogDialog-BIrJbAKi.js → ChangelogDialog-BhyilZWA.js} +1 -1
- package/apps/web/dist/assets/{CodeEditor-DUVcXI5P.js → CodeEditor-DULYZbuE.js} +1 -1
- package/apps/web/dist/assets/EditorPage-D_mCdYdZ.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-BIag8_Be.js → FlowPreview-ykxZxWnk.js} +1 -1
- package/apps/web/dist/assets/{LangSwitch-CJ00IgaO.js → LangSwitch-iO54w9AP.js} +1 -1
- package/apps/web/dist/assets/{Marketplace-D7-ot9Dz.js → Marketplace-C97fH7UC.js} +2 -2
- package/apps/web/dist/assets/{NewWizardChannels-DI3SQ4iS.js → NewWizardChannels-CsSV7sm2.js} +1 -1
- package/apps/web/dist/assets/{NewWizardPage-CytheHxX.js → NewWizardPage-Ebgw-Vf_.js} +1 -1
- package/apps/web/dist/assets/{OnboardingPage-_91Pa8Ad.js → OnboardingPage-BZlloT7v.js} +1 -1
- package/apps/web/dist/assets/PreviewPane-CJuqY5uA.js +7 -0
- package/apps/web/dist/assets/ProtocolSection-CPaDKVpZ.js +1 -0
- package/apps/web/dist/assets/{PublicRunner-CEgXSk3r.js → PublicRunner-4Lf4SnwB.js} +1 -1
- package/apps/web/dist/assets/{ReadOnly-CWf5x74a.js → ReadOnly-CXQ41R9Q.js} +1 -1
- package/apps/web/dist/assets/{SettingsPage-Dr8SDk-L.js → SettingsPage-C-8BgK9O.js} +2 -2
- package/apps/web/dist/assets/{SetupPage-B68n0l4I.js → SetupPage-4_K083Wl.js} +1 -1
- package/apps/web/dist/assets/{SharePage-DfznN7ar.js → SharePage-CQjgMcDI.js} +1 -1
- package/apps/web/dist/assets/{SkillEditor-BIcIczRc.js → SkillEditor-DT5hQwbg.js} +1 -1
- package/apps/web/dist/assets/{Skills-CN4QE7Kx.js → Skills-D7V_9_xo.js} +1 -1
- package/apps/web/dist/assets/SpacePage-D3rYS1bA.js +2 -0
- package/apps/web/dist/assets/{UpdateCheck-QhBI3rlQ.js → UpdateCheck-DVgAJmy8.js} +2 -2
- package/apps/web/dist/assets/changelog-DzQCUSsx.js +1 -0
- package/apps/web/dist/assets/{code-editor-DkPo1C-L.js → code-editor-5T7ilBjd.js} +2 -2
- package/apps/web/dist/assets/{host-D6H6Z9Jp.js → host-CCijW1hj.js} +6 -6
- package/apps/web/dist/assets/i18n-DCPDesT-.js +55 -0
- package/apps/web/dist/assets/{index-De0Wb42y.js → index-C_iWl8iS.js} +3 -3
- package/apps/web/dist/assets/index-zcPlodHx.css +1 -0
- package/apps/web/dist/assets/minus-BpYkOkYw.js +1 -0
- package/apps/web/dist/assets/{read-aloud-CnFwDSGD.js → read-aloud-Qb719not.js} +1 -1
- package/apps/web/dist/assets/{runners-0sTPbWzr.js → runners-BeZ84YH_.js} +1 -1
- package/apps/web/dist/assets/{session-BMiUrqHg.js → session-CEJRkSP5.js} +1 -1
- package/apps/web/dist/assets/{theme-CkNTe-_Z.js → theme-y_owNosi.js} +1 -1
- package/apps/web/dist/assets/{ui-DAk_vjrL.js → ui-BacfkQ7Q.js} +1 -1
- package/apps/web/dist/assets/{useMutation-isHfB33W.js → useMutation-CgzFr4qH.js} +1 -1
- package/apps/web/dist/assets/{viewers-ijNZHJFG.js → viewers-CkyHAjnk.js} +2 -2
- package/apps/web/dist/index.html +12 -12
- package/apps/web/dist/mcp/flow.html +2 -2
- package/node_modules/@engenty/wizards-shared/dist/bundles.d.ts +219 -0
- package/node_modules/@engenty/wizards-shared/dist/bundles.js +19 -0
- package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +105 -4
- package/node_modules/@engenty/wizards-shared/dist/connectors.js +6 -0
- package/node_modules/@engenty/wizards-shared/dist/run.d.ts +8 -0
- package/node_modules/@engenty/wizards-shared/dist/run.js +16 -0
- package/node_modules/@engenty/wizards-shared/dist/rwx.d.ts +84 -1
- package/node_modules/@engenty/wizards-shared/dist/rwx.js +69 -1
- package/node_modules/@engenty/wizards-shared/dist/skills.d.ts +20 -3
- package/node_modules/@engenty/wizards-shared/dist/skills.js +5 -2
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/plugin.json +1 -1
- package/apps/web/dist/assets/CapabilitiesPage-C1th2cZE.js +0 -2
- package/apps/web/dist/assets/EditorPage-56sIqEfF.js +0 -3
- package/apps/web/dist/assets/PreviewPane-BDsYm-_K.js +0 -7
- package/apps/web/dist/assets/ProtocolSection-D_zaxHEL.js +0 -1
- package/apps/web/dist/assets/SpacePage-DiVTwhnJ.js +0 -2
- package/apps/web/dist/assets/changelog-a_CuplMX.js +0 -1
- package/apps/web/dist/assets/i18n-BaPKbQ1s.js +0 -55
- package/apps/web/dist/assets/index-CCUG6Vnh.css +0 -1
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
import { SKILL_LIMITS, SKILL_NAME, skillNameOf } from "@engenty/wizards-shared/skills";
|
|
2
|
+
import { unzipSync } from "fflate";
|
|
3
|
+
import { ServiceError } from "../services/errors.js";
|
|
4
|
+
import { asText, checkContent, contentOf } from "../services/skills.js";
|
|
5
|
+
/**
|
|
6
|
+
* Reads a plugin for Claude Code or Cursor out of a zip (docs/plans/capabilities-next.md, piece
|
|
7
|
+
* 4): a repository's archive or an uploaded file. Nothing here asks the network or the database.
|
|
8
|
+
*
|
|
9
|
+
* The formats, as their own docs describe them (code.claude.com/docs/en/plugins-reference,
|
|
10
|
+
* cursor.com/docs/reference/plugins, November 2026):
|
|
11
|
+
*
|
|
12
|
+
* - Claude Code: `.claude-plugin/plugin.json` (optional; `name` where it is there), MCP servers in
|
|
13
|
+
* `.mcp.json` and in the manifest's `mcpServers` (a path, a map, or a list of either; a later
|
|
14
|
+
* name replaces an earlier one), skills in `skills/<name>/SKILL.md` plus the folders the
|
|
15
|
+
* manifest's `skills` names.
|
|
16
|
+
* - Cursor: `.cursor-plugin/plugin.json`, MCP servers in `mcp.json` unless the manifest's
|
|
17
|
+
* `mcpServers` says otherwise, skills in `skills/` unless the manifest's `skills` says otherwise.
|
|
18
|
+
* Cursor also reads a `plugin.json` at the root (the open Agent Plugin format).
|
|
19
|
+
* - Both: a repository of several plugins lists them in `marketplace.json` beside the manifest;
|
|
20
|
+
* a `SKILL.md` at the root of a plugin without `skills/` is its one skill.
|
|
21
|
+
*
|
|
22
|
+
* Taken are servers over http (streamable HTTP, SSE) and skills. Everything else is named as
|
|
23
|
+
* left out: commands, agents, hooks, rules, servers started on the command line.
|
|
24
|
+
*/
|
|
25
|
+
const refuse = (server, params) => new ServiceError("invalid", { server, params });
|
|
26
|
+
/** Never listed: an archive with more files than this. */
|
|
27
|
+
const MAX_NAMES = 50_000;
|
|
28
|
+
/** A manifest, an MCP file, a hooks file: none is larger. */
|
|
29
|
+
const CONFIG_BYTES = 1_000_000;
|
|
30
|
+
/** As an uploaded skill: the files of one skill's folder that are looked at. */
|
|
31
|
+
const SKILL_ENTRIES = 500;
|
|
32
|
+
/** What one plugin may bring. */
|
|
33
|
+
export const BUNDLE_LIMITS = { servers: 20, skills: 60, leftOut: 200, headers: 10 };
|
|
34
|
+
/** What tells a plugin's root: a zip with these at its top is not unwrapped. */
|
|
35
|
+
const ROOT_SIGN = /^(\.claude-plugin\/|\.cursor-plugin\/|plugin\.json$|\.mcp\.json$|mcp\.json$|skills\/|SKILL\.md$)/;
|
|
36
|
+
/**
|
|
37
|
+
* A zip's files by path, read on request. The one folder around everything (a repository's
|
|
38
|
+
* archive has one, a zipped folder too) is taken off. Paths that leave the archive and the Mac's
|
|
39
|
+
* resource forks are not there.
|
|
40
|
+
*/
|
|
41
|
+
export class Archive {
|
|
42
|
+
data;
|
|
43
|
+
/** Every file's path and its size unpacked. */
|
|
44
|
+
files = new Map();
|
|
45
|
+
prefix;
|
|
46
|
+
cache = new Map();
|
|
47
|
+
constructor(data) {
|
|
48
|
+
this.data = data;
|
|
49
|
+
const names = [];
|
|
50
|
+
let seen = 0;
|
|
51
|
+
try {
|
|
52
|
+
unzipSync(data, {
|
|
53
|
+
filter: (f) => {
|
|
54
|
+
seen++;
|
|
55
|
+
if (seen <= MAX_NAMES && !f.name.endsWith("/")) {
|
|
56
|
+
names.push([f.name, f.originalSize]);
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
throw refuse("bundleUploadKind");
|
|
64
|
+
}
|
|
65
|
+
if (seen > MAX_NAMES) {
|
|
66
|
+
throw refuse("bundleTooLarge", { mb: MAX_ARCHIVE_MB });
|
|
67
|
+
}
|
|
68
|
+
const kept = names.filter(([name]) => {
|
|
69
|
+
const parts = name.split("/");
|
|
70
|
+
return !(name.startsWith("/") ||
|
|
71
|
+
name.includes("\\") ||
|
|
72
|
+
parts.includes("..") ||
|
|
73
|
+
parts.includes("__MACOSX"));
|
|
74
|
+
});
|
|
75
|
+
const tops = new Set(kept.map(([name]) => name.split("/")[0]));
|
|
76
|
+
const wrapped = tops.size === 1 &&
|
|
77
|
+
kept.every(([name]) => name.includes("/")) &&
|
|
78
|
+
!kept.some(([name]) => ROOT_SIGN.test(name));
|
|
79
|
+
this.prefix = wrapped ? `${[...tops][0]}/` : "";
|
|
80
|
+
for (const [name, size] of kept) {
|
|
81
|
+
this.files.set(name.slice(this.prefix.length), size);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
has(path) {
|
|
85
|
+
return this.files.has(path);
|
|
86
|
+
}
|
|
87
|
+
/** The files in a folder and below, by their path in the archive. `""` is the archive itself. */
|
|
88
|
+
under(dir) {
|
|
89
|
+
return [...this.files.keys()].filter((path) => path.startsWith(dir));
|
|
90
|
+
}
|
|
91
|
+
/** Unpacks files in one pass; one that is larger than `maxBytes` stays out. */
|
|
92
|
+
load(paths, maxBytes) {
|
|
93
|
+
const want = new Set();
|
|
94
|
+
for (const path of paths) {
|
|
95
|
+
const size = this.files.get(path);
|
|
96
|
+
if (size !== undefined && size <= maxBytes && !this.cache.has(path)) {
|
|
97
|
+
want.add(`${this.prefix}${path}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (!want.size) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
let found;
|
|
104
|
+
try {
|
|
105
|
+
found = unzipSync(this.data, {
|
|
106
|
+
filter: (f) => want.has(f.name) && f.originalSize <= maxBytes,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
throw refuse("bundleUploadKind");
|
|
111
|
+
}
|
|
112
|
+
for (const [name, bytes] of Object.entries(found)) {
|
|
113
|
+
this.cache.set(name.slice(this.prefix.length), bytes);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
bytes(path, maxBytes) {
|
|
117
|
+
this.load([path], maxBytes);
|
|
118
|
+
return this.cache.get(path) ?? null;
|
|
119
|
+
}
|
|
120
|
+
/** A small file as an object of JSON; null where it is not there, refused where it is no JSON. */
|
|
121
|
+
json(path) {
|
|
122
|
+
if (!this.has(path)) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
const bytes = this.bytes(path, CONFIG_BYTES);
|
|
126
|
+
const text = bytes ? asText(bytes) : null;
|
|
127
|
+
try {
|
|
128
|
+
const value = text === null ? null : JSON.parse(text);
|
|
129
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
130
|
+
return value;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// Said below.
|
|
135
|
+
}
|
|
136
|
+
throw refuse("bundleManifestUnreadable", { file: path });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/** The megabytes a repository's archive or an uploaded zip may weigh. */
|
|
140
|
+
export const MAX_ARCHIVE_MB = 60;
|
|
141
|
+
const isObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
142
|
+
const text = (v) => (typeof v === "string" && v.trim() ? v.trim() : null);
|
|
143
|
+
const list = (v) => (Array.isArray(v) ? v : v === undefined ? [] : [v]);
|
|
144
|
+
/** A path of a manifest as a folder or file below the plugin's root; null where it leaves it. */
|
|
145
|
+
function inside(path) {
|
|
146
|
+
const parts = path
|
|
147
|
+
.trim()
|
|
148
|
+
.replace(/^\.\//, "")
|
|
149
|
+
.split("/")
|
|
150
|
+
.filter((p) => p && p !== ".");
|
|
151
|
+
return parts.includes("..") || path.startsWith("/") || path.includes("\\")
|
|
152
|
+
? null
|
|
153
|
+
: parts.join("/");
|
|
154
|
+
}
|
|
155
|
+
/** A folder as a prefix: `""` for the root, `a/b/` else. */
|
|
156
|
+
const asDir = (path) => (path ? `${path.replace(/\/+$/, "")}/` : "");
|
|
157
|
+
function marketplaceAt(archive, dir) {
|
|
158
|
+
for (const format of ["claude", "cursor"]) {
|
|
159
|
+
const data = archive.json(`${dir}.${format}-plugin/marketplace.json`);
|
|
160
|
+
if (data) {
|
|
161
|
+
const metadata = isObject(data.metadata) ? data.metadata : {};
|
|
162
|
+
return {
|
|
163
|
+
format,
|
|
164
|
+
pluginRoot: inside(text(metadata.pluginRoot) ?? "") ?? "",
|
|
165
|
+
plugins: list(data.plugins).filter(isObject),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
/** `owner/name` out of a repository's address on GitHub, or of the short form itself. */
|
|
172
|
+
function repoOf(value) {
|
|
173
|
+
const m = /^(?:https?:\/\/(?:www\.)?github\.com\/)?([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+?)(?:\.git)?\/?$/.exec(value.trim());
|
|
174
|
+
return m ? `${m[1]}/${m[2]}` : null;
|
|
175
|
+
}
|
|
176
|
+
/** Where a marketplace's entry lives: a folder of this archive, or another repository on GitHub. */
|
|
177
|
+
function entryPlace(market, dir, entry) {
|
|
178
|
+
const source = entry.source;
|
|
179
|
+
if (typeof source === "string") {
|
|
180
|
+
const bare = !source.includes("/");
|
|
181
|
+
const path = inside(source);
|
|
182
|
+
if (path === null) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
// Cursor puts every source below `pluginRoot`, Claude Code only a bare name.
|
|
186
|
+
const below = market.pluginRoot && (market.format === "cursor" || bare);
|
|
187
|
+
return { path: `${dir}${below ? `${market.pluginRoot}/` : ""}${path}` };
|
|
188
|
+
}
|
|
189
|
+
if (!isObject(source)) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
const ref = text(source.ref);
|
|
193
|
+
if (source.source === "github") {
|
|
194
|
+
const repo = repoOf(text(source.repo) ?? "");
|
|
195
|
+
return repo ? { address: `https://github.com/${repo}${ref ? `/tree/${ref}` : ""}` } : null;
|
|
196
|
+
}
|
|
197
|
+
if (source.source === "git-subdir" || source.source === "url") {
|
|
198
|
+
const repo = repoOf(text(source.url) ?? "");
|
|
199
|
+
const path = inside(text(source.path) ?? "");
|
|
200
|
+
if (!repo || path === null) {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
const tail = path ? `/tree/${ref ?? "HEAD"}/${path}` : ref ? `/tree/${ref}` : "";
|
|
204
|
+
return { address: `https://github.com/${repo}${tail}` };
|
|
205
|
+
}
|
|
206
|
+
const path = inside(text(source.path) ?? "");
|
|
207
|
+
return path ? { path: `${dir}${path}` } : null;
|
|
208
|
+
}
|
|
209
|
+
function manifestAt(archive, root) {
|
|
210
|
+
const claude = archive.json(`${root}.claude-plugin/plugin.json`);
|
|
211
|
+
if (claude) {
|
|
212
|
+
return { format: "claude", data: claude };
|
|
213
|
+
}
|
|
214
|
+
const cursor = archive.json(`${root}.cursor-plugin/plugin.json`);
|
|
215
|
+
if (cursor) {
|
|
216
|
+
return { format: "cursor", data: cursor };
|
|
217
|
+
}
|
|
218
|
+
if (archive.has(`${root}plugin.json`)) {
|
|
219
|
+
const open = archive.json(`${root}plugin.json`);
|
|
220
|
+
if (open && text(open.name)) {
|
|
221
|
+
return { format: "agent", data: open };
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
/** Whether a folder holds what a plugin without a manifest is made of. */
|
|
227
|
+
const looksLikePlugin = (archive, root) => archive.has(`${root}.mcp.json`) ||
|
|
228
|
+
archive.has(`${root}mcp.json`) ||
|
|
229
|
+
archive.has(`${root}SKILL.md`) ||
|
|
230
|
+
archive.under(`${root}skills/`).some((path) => path.endsWith("/SKILL.md"));
|
|
231
|
+
// --- MCP servers ------------------------------------------------------------------------------
|
|
232
|
+
/** `${NAME:-default}` as its default; a value nobody gave stays as it is written. */
|
|
233
|
+
const withDefaults = (value) => value.replace(/\$\{[^}:]+:-([^}]*)\}/g, "$1");
|
|
234
|
+
const HEADER_NAME = /^[A-Za-z][A-Za-z0-9-]{0,63}$/;
|
|
235
|
+
/** Headers a plugin never sets: the request's own, and the MCP session's. */
|
|
236
|
+
const OWN_HEADERS = new Set([
|
|
237
|
+
"host",
|
|
238
|
+
"content-length",
|
|
239
|
+
"content-type",
|
|
240
|
+
"connection",
|
|
241
|
+
"transfer-encoding",
|
|
242
|
+
"accept",
|
|
243
|
+
"cookie",
|
|
244
|
+
"mcp-session-id",
|
|
245
|
+
"mcp-protocol-version",
|
|
246
|
+
]);
|
|
247
|
+
function headersOf(entry) {
|
|
248
|
+
const headers = [];
|
|
249
|
+
let keyHeader = null;
|
|
250
|
+
for (const [name, raw] of Object.entries(isObject(entry.headers) ? entry.headers : {})) {
|
|
251
|
+
if (typeof raw !== "string" || !HEADER_NAME.test(name) || OWN_HEADERS.has(name.toLowerCase())) {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
const value = withDefaults(raw);
|
|
255
|
+
if (!value.includes("${")) {
|
|
256
|
+
if (headers.length < BUNDLE_LIMITS.headers &&
|
|
257
|
+
value.length <= 500 &&
|
|
258
|
+
/^[^\r\n]+$/.test(value)) {
|
|
259
|
+
headers.push({ name, value });
|
|
260
|
+
}
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
// `Bearer ${TOKEN}` or `${TOKEN}`: a key the person gives, in this header.
|
|
264
|
+
const key = /^(?:([A-Za-z][A-Za-z0-9-]{0,19}) )?\$\{[^}]+\}$/.exec(value.trim());
|
|
265
|
+
if (key && !keyHeader) {
|
|
266
|
+
keyHeader = { name, ...(key[1] ? { scheme: key[1] } : {}) };
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return { headers, keyHeader };
|
|
270
|
+
}
|
|
271
|
+
/** One entry of an MCP file: a server over http, or why it stays out. */
|
|
272
|
+
function serverOf(key, entry) {
|
|
273
|
+
const type = (text(entry.type) ?? "").toLowerCase();
|
|
274
|
+
if (entry.command !== undefined || type === "stdio" || type === "sdk") {
|
|
275
|
+
return "stdio";
|
|
276
|
+
}
|
|
277
|
+
const url = withDefaults(text(entry.url) ?? text(entry.serverUrl) ?? "");
|
|
278
|
+
if (type === "ws" || type === "websocket" || /^wss?:/i.test(url)) {
|
|
279
|
+
return "socket";
|
|
280
|
+
}
|
|
281
|
+
if (!url) {
|
|
282
|
+
return "noAddress";
|
|
283
|
+
}
|
|
284
|
+
if (url.includes("${")) {
|
|
285
|
+
return "variable";
|
|
286
|
+
}
|
|
287
|
+
let parsed;
|
|
288
|
+
try {
|
|
289
|
+
parsed = new URL(url);
|
|
290
|
+
}
|
|
291
|
+
catch {
|
|
292
|
+
return "address";
|
|
293
|
+
}
|
|
294
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
295
|
+
return "address";
|
|
296
|
+
}
|
|
297
|
+
return { key, url, transport: type === "sse" ? "sse" : "http", ...headersOf(entry) };
|
|
298
|
+
}
|
|
299
|
+
/** The servers of an MCP file: below `mcpServers`, or the file itself as the map. */
|
|
300
|
+
function serverMap(data) {
|
|
301
|
+
return isObject(data.mcpServers) ? data.mcpServers : data;
|
|
302
|
+
}
|
|
303
|
+
function readServers(archive, root, manifest) {
|
|
304
|
+
const found = new Map();
|
|
305
|
+
const add = (map) => {
|
|
306
|
+
for (const [key, entry] of Object.entries(map)) {
|
|
307
|
+
if (isObject(entry) && key.length <= 100) {
|
|
308
|
+
found.set(key, serverOf(key, entry));
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
const addFile = (path) => {
|
|
313
|
+
const data = archive.json(`${root}${path}`);
|
|
314
|
+
if (data) {
|
|
315
|
+
add(serverMap(data));
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
const declared = manifest.data.mcpServers;
|
|
319
|
+
// Claude Code reads its file first and then what the manifest names; Cursor's manifest
|
|
320
|
+
// replaces its file. Where a format's own file is missing, the other format's is read.
|
|
321
|
+
if (manifest.format === "claude" || declared === undefined) {
|
|
322
|
+
const [own, other] = manifest.format === "claude" ? [".mcp.json", "mcp.json"] : ["mcp.json", ".mcp.json"];
|
|
323
|
+
addFile(archive.has(`${root}${own}`) ? own : other);
|
|
324
|
+
}
|
|
325
|
+
for (const shape of list(declared)) {
|
|
326
|
+
if (isObject(shape)) {
|
|
327
|
+
add(serverMap(shape));
|
|
328
|
+
}
|
|
329
|
+
else if (typeof shape === "string") {
|
|
330
|
+
const path = inside(shape);
|
|
331
|
+
if (/^https?:/i.test(shape) || /\.(mcpb|dxt)$/i.test(shape) || path === null) {
|
|
332
|
+
found.set(shape.split("/").pop() ?? shape, "file");
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
addFile(path);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
const servers = [];
|
|
340
|
+
const leftOut = [];
|
|
341
|
+
for (const [key, server] of found) {
|
|
342
|
+
if (typeof server === "string") {
|
|
343
|
+
leftOut.push({ kind: "server", name: key, reason: server });
|
|
344
|
+
}
|
|
345
|
+
else if (servers.length >= BUNDLE_LIMITS.servers) {
|
|
346
|
+
leftOut.push({ kind: "server", name: key, reason: "count" });
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
servers.push(server);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return { servers, leftOut };
|
|
353
|
+
}
|
|
354
|
+
// --- skills -----------------------------------------------------------------------------------
|
|
355
|
+
/** The folders that hold a `SKILL.md`, in a skills folder and up to three folders below it. */
|
|
356
|
+
function skillDirs(archive, dir) {
|
|
357
|
+
if (archive.has(`${dir}SKILL.md`)) {
|
|
358
|
+
return [dir];
|
|
359
|
+
}
|
|
360
|
+
const dirs = archive
|
|
361
|
+
.under(dir)
|
|
362
|
+
.filter((path) => path.endsWith("/SKILL.md"))
|
|
363
|
+
.map((path) => path.slice(0, -"SKILL.md".length))
|
|
364
|
+
.filter((skill) => skill.slice(dir.length).split("/").length <= 4)
|
|
365
|
+
.sort();
|
|
366
|
+
// A skill's folder is its own: a `SKILL.md` deeper inside it is one of its files.
|
|
367
|
+
return dirs.filter((skill) => !dirs.some((other) => other !== skill && skill.startsWith(other)));
|
|
368
|
+
}
|
|
369
|
+
function readSkills(archive, root, manifest, say) {
|
|
370
|
+
const declared = list(manifest.data.skills)
|
|
371
|
+
.filter((p) => typeof p === "string")
|
|
372
|
+
.map(inside)
|
|
373
|
+
.filter((p) => p !== null)
|
|
374
|
+
.map((p) => `${root}${asDir(p)}`);
|
|
375
|
+
const standard = `${root}skills/`;
|
|
376
|
+
const hasStandard = archive.under(standard).length > 0;
|
|
377
|
+
// Claude Code adds the manifest's folders to `skills/`; for Cursor they stand in its place.
|
|
378
|
+
const folders = manifest.format === "claude" || !declared.length ? [standard, ...declared] : declared;
|
|
379
|
+
const dirs = new Set(folders.flatMap((folder) => skillDirs(archive, folder)));
|
|
380
|
+
if (!(hasStandard || declared.length) && archive.has(`${root}SKILL.md`)) {
|
|
381
|
+
dirs.add(root);
|
|
382
|
+
}
|
|
383
|
+
const visible = (path) => !path.split("/").some((part) => part.startsWith("."));
|
|
384
|
+
const taken = [...dirs].sort().slice(0, BUNDLE_LIMITS.skills);
|
|
385
|
+
const filesOf = new Map(taken.map((dir) => [
|
|
386
|
+
dir,
|
|
387
|
+
archive
|
|
388
|
+
.under(dir)
|
|
389
|
+
.filter((path) => visible(path.slice(dir.length)))
|
|
390
|
+
.filter((path) => (archive.files.get(path) ?? 0) <= SKILL_LIMITS.blobFile)
|
|
391
|
+
.slice(0, SKILL_ENTRIES),
|
|
392
|
+
]));
|
|
393
|
+
archive.load([...filesOf.values()].flat(), SKILL_LIMITS.blobFile);
|
|
394
|
+
const skills = [];
|
|
395
|
+
const leftOut = [...dirs]
|
|
396
|
+
.sort()
|
|
397
|
+
.slice(BUNDLE_LIMITS.skills)
|
|
398
|
+
.map((dir) => ({ kind: "skill", name: dir.slice(root.length, -1) || ".", reason: "count" }));
|
|
399
|
+
const names = new Set();
|
|
400
|
+
for (const dir of taken) {
|
|
401
|
+
const path = dir.slice(root.length, -1) || ".";
|
|
402
|
+
try {
|
|
403
|
+
const intake = contentOf((filesOf.get(dir) ?? []).map((file) => {
|
|
404
|
+
const data = archive.bytes(file, SKILL_LIMITS.blobFile);
|
|
405
|
+
return { path: file.slice(dir.length), text: data ? asText(data) : null, data };
|
|
406
|
+
}));
|
|
407
|
+
// A name the format does not allow is made into one: from the name, else from the folder.
|
|
408
|
+
const name = SKILL_NAME.test(intake.content.name)
|
|
409
|
+
? intake.content.name
|
|
410
|
+
: skillNameOf(intake.content.name) || skillNameOf(path.split("/").pop() ?? "");
|
|
411
|
+
const content = checkContent({ ...intake.content, name });
|
|
412
|
+
if (names.has(content.name)) {
|
|
413
|
+
throw refuse("skillNameTaken", { name: content.name });
|
|
414
|
+
}
|
|
415
|
+
names.add(content.name);
|
|
416
|
+
skills.push({ path, intake: { ...intake, content } });
|
|
417
|
+
}
|
|
418
|
+
catch (err) {
|
|
419
|
+
if (!(err instanceof ServiceError)) {
|
|
420
|
+
throw err;
|
|
421
|
+
}
|
|
422
|
+
leftOut.push({ kind: "skill", name: path, reason: "invalid", detail: say(err) });
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return { skills, leftOut };
|
|
426
|
+
}
|
|
427
|
+
// --- what is not taken --------------------------------------------------------------------------
|
|
428
|
+
/** The Markdown files of a manifest's entry, or of the standard folder: by name, without ending. */
|
|
429
|
+
function namedFiles(archive, root, declared, standard, ending) {
|
|
430
|
+
if (isObject(declared)) {
|
|
431
|
+
return Object.keys(declared);
|
|
432
|
+
}
|
|
433
|
+
const paths = declared === undefined
|
|
434
|
+
? [standard]
|
|
435
|
+
: list(declared)
|
|
436
|
+
.filter((p) => typeof p === "string")
|
|
437
|
+
.map(inside)
|
|
438
|
+
.filter((p) => p !== null);
|
|
439
|
+
const names = [];
|
|
440
|
+
for (const path of paths) {
|
|
441
|
+
const files = archive.has(`${root}${path}`)
|
|
442
|
+
? [`${root}${path}`]
|
|
443
|
+
: archive.under(`${root}${asDir(path)}`);
|
|
444
|
+
for (const file of files) {
|
|
445
|
+
if (ending.test(file)) {
|
|
446
|
+
const name = file.slice(root.length).replace(ending, "");
|
|
447
|
+
names.push(name.startsWith(standard) ? name.slice(standard.length) : name);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return [...new Set(names)].sort();
|
|
452
|
+
}
|
|
453
|
+
/** The events a plugin's hooks listen to; `hooks` where the file names none. */
|
|
454
|
+
function hookNames(archive, root, declared) {
|
|
455
|
+
const events = new Set();
|
|
456
|
+
const add = (data) => {
|
|
457
|
+
for (const event of Object.keys(isObject(data?.hooks) ? data.hooks : (data ?? {}))) {
|
|
458
|
+
events.add(event);
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
let any = false;
|
|
462
|
+
const file = (path) => {
|
|
463
|
+
if (archive.has(`${root}${path}`)) {
|
|
464
|
+
any = true;
|
|
465
|
+
try {
|
|
466
|
+
add(archive.json(`${root}${path}`));
|
|
467
|
+
}
|
|
468
|
+
catch {
|
|
469
|
+
// A hooks file nobody can read is still a hooks file the space does not take.
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
file("hooks/hooks.json");
|
|
474
|
+
for (const shape of list(declared)) {
|
|
475
|
+
if (isObject(shape)) {
|
|
476
|
+
any = true;
|
|
477
|
+
add(shape);
|
|
478
|
+
}
|
|
479
|
+
else if (typeof shape === "string") {
|
|
480
|
+
const path = inside(shape);
|
|
481
|
+
if (path) {
|
|
482
|
+
file(path);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return events.size ? [...events].sort() : any ? ["hooks"] : [];
|
|
487
|
+
}
|
|
488
|
+
function readLeftOut(archive, root, manifest) {
|
|
489
|
+
const md = manifest.format === "claude" ? /\.md$/i : /\.(md|mdc|markdown|txt)$/i;
|
|
490
|
+
const { data } = manifest;
|
|
491
|
+
const out = [
|
|
492
|
+
...namedFiles(archive, root, data.commands, "commands/", md).map((name) => ({ kind: "command", name })),
|
|
493
|
+
...namedFiles(archive, root, data.agents, "agents/", /\.(md|mdc|markdown)$/i).map((name) => ({ kind: "agent", name })),
|
|
494
|
+
...hookNames(archive, root, data.hooks).map((name) => ({ kind: "hook", name })),
|
|
495
|
+
...(manifest.format === "claude"
|
|
496
|
+
? []
|
|
497
|
+
: namedFiles(archive, root, data.rules, "rules/", /\.(md|mdc|markdown)$/i).map((name) => ({ kind: "rule", name }))),
|
|
498
|
+
];
|
|
499
|
+
const others = [
|
|
500
|
+
["lsp", archive.has(`${root}.lsp.json`) || data.lspServers !== undefined],
|
|
501
|
+
["bin", archive.under(`${root}bin/`).length > 0],
|
|
502
|
+
["output-styles", archive.under(`${root}output-styles/`).length > 0],
|
|
503
|
+
["workflows", archive.under(`${root}workflows/`).length > 0],
|
|
504
|
+
["monitors", archive.under(`${root}monitors/`).length > 0],
|
|
505
|
+
["themes", archive.under(`${root}themes/`).length > 0],
|
|
506
|
+
];
|
|
507
|
+
for (const [name, there] of others) {
|
|
508
|
+
if (there) {
|
|
509
|
+
out.push({ kind: "other", name });
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
return out;
|
|
513
|
+
}
|
|
514
|
+
// --- the plugin -------------------------------------------------------------------------------
|
|
515
|
+
/**
|
|
516
|
+
* The plugin in an archive: at its root or in `path`. A repository of several plugins answers
|
|
517
|
+
* with the list to choose from, unless it lists exactly one that lives in it. `say` puts a
|
|
518
|
+
* refusal into the reader's words, for a skill that is left out.
|
|
519
|
+
*/
|
|
520
|
+
export function readPlugin(archive, options) {
|
|
521
|
+
const asked = inside(options.path ?? "");
|
|
522
|
+
if (asked === null) {
|
|
523
|
+
throw refuse("bundleNoFolder", { path: options.path ?? "" });
|
|
524
|
+
}
|
|
525
|
+
let root = asDir(asked);
|
|
526
|
+
if (root && !archive.under(root).length) {
|
|
527
|
+
throw refuse("bundleNoFolder", { path: asked });
|
|
528
|
+
}
|
|
529
|
+
let manifest = manifestAt(archive, root);
|
|
530
|
+
// The folder of one plugin in a repository of several: its entry there stands for a manifest.
|
|
531
|
+
let entry = null;
|
|
532
|
+
let entryFormat = "claude";
|
|
533
|
+
if (!manifest) {
|
|
534
|
+
const market = marketplaceAt(archive, root);
|
|
535
|
+
if (market) {
|
|
536
|
+
const places = market.plugins.map((plugin) => ({
|
|
537
|
+
plugin,
|
|
538
|
+
place: entryPlace(market, root, plugin),
|
|
539
|
+
}));
|
|
540
|
+
const here = places.filter((p) => p.place && "path" in p.place);
|
|
541
|
+
if (places.length === 1 && here.length === 1) {
|
|
542
|
+
const only = here[0];
|
|
543
|
+
root = asDir(only.place.path);
|
|
544
|
+
entry = only.plugin;
|
|
545
|
+
entryFormat = market.format;
|
|
546
|
+
manifest = manifestAt(archive, root);
|
|
547
|
+
}
|
|
548
|
+
else {
|
|
549
|
+
return {
|
|
550
|
+
choices: places
|
|
551
|
+
.filter((p) => p.place)
|
|
552
|
+
.map(({ plugin, place }) => ({
|
|
553
|
+
name: text(plugin.displayName) ?? text(plugin.name) ?? "",
|
|
554
|
+
description: text(plugin.description)?.slice(0, 400) ?? null,
|
|
555
|
+
path: place && "path" in place ? place.path : null,
|
|
556
|
+
address: place && "address" in place ? place.address : null,
|
|
557
|
+
}))
|
|
558
|
+
.filter((choice) => choice.name)
|
|
559
|
+
.slice(0, 200),
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
else if (root) {
|
|
564
|
+
const above = marketplaceAt(archive, "");
|
|
565
|
+
const listed = above?.plugins.find((plugin) => {
|
|
566
|
+
const place = entryPlace(above, "", plugin);
|
|
567
|
+
return place && "path" in place && asDir(place.path) === root;
|
|
568
|
+
});
|
|
569
|
+
if (above && listed) {
|
|
570
|
+
entry = listed;
|
|
571
|
+
entryFormat = above.format;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
if (!manifest) {
|
|
576
|
+
if (!(entry || looksLikePlugin(archive, root))) {
|
|
577
|
+
throw refuse("bundleNoPlugin");
|
|
578
|
+
}
|
|
579
|
+
manifest = { format: entryFormat, data: entry ?? {} };
|
|
580
|
+
}
|
|
581
|
+
const { data } = manifest;
|
|
582
|
+
const servers = readServers(archive, root, manifest);
|
|
583
|
+
const skills = readSkills(archive, root, manifest, options.say);
|
|
584
|
+
const version = data.version ?? entry?.version;
|
|
585
|
+
return {
|
|
586
|
+
plugin: {
|
|
587
|
+
format: manifest.format,
|
|
588
|
+
name: (text(data.displayName) ??
|
|
589
|
+
text(data.name) ??
|
|
590
|
+
text(entry?.name) ??
|
|
591
|
+
(root ? root.slice(0, -1).split("/").pop() : null) ??
|
|
592
|
+
options.fallbackName).slice(0, 120),
|
|
593
|
+
version: typeof version === "string" || typeof version === "number"
|
|
594
|
+
? String(version).slice(0, 60)
|
|
595
|
+
: null,
|
|
596
|
+
description: (text(data.description) ?? text(entry?.description))?.slice(0, 1000) ?? null,
|
|
597
|
+
root,
|
|
598
|
+
servers: servers.servers,
|
|
599
|
+
skills: skills.skills,
|
|
600
|
+
leftOut: [
|
|
601
|
+
...servers.leftOut,
|
|
602
|
+
...skills.leftOut,
|
|
603
|
+
...readLeftOut(archive, root, manifest),
|
|
604
|
+
].slice(0, BUNDLE_LIMITS.leftOut),
|
|
605
|
+
},
|
|
606
|
+
};
|
|
607
|
+
}
|