@capybara-hq/plugin-sdk 0.1.0-rc.4 → 0.1.0-rc.41

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.
Files changed (133) hide show
  1. package/agent-docs/agent-templates.md +15 -3
  2. package/agent-docs/concepts.md +13 -3
  3. package/agent-docs/connector-templates.md +2 -1
  4. package/agent-docs/extension-points/channel.md +2 -2
  5. package/agent-docs/extension-points/config-source.md +1 -1
  6. package/agent-docs/extension-points/connector.md +1 -1
  7. package/agent-docs/extension-points/context.md +15 -0
  8. package/agent-docs/extension-points/counter.md +1 -1
  9. package/agent-docs/extension-points/directory.md +1 -1
  10. package/agent-docs/extension-points/file-preview.md +3 -1
  11. package/agent-docs/extension-points/identity-source.md +1 -1
  12. package/agent-docs/extension-points/model-provider.md +4 -2
  13. package/agent-docs/extension-points/object-store.md +3 -1
  14. package/agent-docs/extension-points/sandbox.md +3 -3
  15. package/agent-docs/extension-points/secret-store.md +1 -1
  16. package/agent-docs/extension-points/web-fetch.md +1 -1
  17. package/agent-docs/extension-points/web-search.md +1 -1
  18. package/agent-docs/extensions.md +29 -4
  19. package/agent-docs/plugin-format.md +43 -3
  20. package/agent-docs/setup.md +46 -0
  21. package/agent-docs/skills.md +1 -1
  22. package/agent-docs/tool-naming.md +1 -1
  23. package/dist/agent-template.d.ts +15 -6
  24. package/dist/agent-template.js +32 -13
  25. package/dist/bootstrap.d.ts +15 -1
  26. package/dist/bootstrap.js +17 -1
  27. package/dist/cards.d.ts +67 -13
  28. package/dist/cards.js +91 -21
  29. package/dist/channel.d.ts +148 -48
  30. package/dist/channel.js +10 -5
  31. package/dist/client-css.d.ts +36 -0
  32. package/dist/client-css.js +326 -0
  33. package/dist/client-section.d.ts +35 -0
  34. package/dist/client-section.js +133 -0
  35. package/dist/config-ui.d.ts +22 -0
  36. package/dist/config-ui.js +64 -4
  37. package/dist/connector-auth.d.ts +7 -2
  38. package/dist/connector-auth.js +29 -8
  39. package/dist/connector.d.ts +74 -32
  40. package/dist/context.d.ts +40 -0
  41. package/dist/context.js +2 -0
  42. package/dist/ctx.d.ts +120 -29
  43. package/dist/define-extension.d.ts +26 -12
  44. package/dist/define-extension.js +11 -4
  45. package/dist/device-denied-paths.d.ts +14 -0
  46. package/dist/device-denied-paths.js +41 -0
  47. package/dist/device-protocol.d.ts +481 -0
  48. package/dist/device-protocol.js +1113 -0
  49. package/dist/extension-point.d.ts +2 -0
  50. package/dist/extension-point.js +5 -2
  51. package/dist/file-preview.d.ts +23 -6
  52. package/dist/git-hosts.d.ts +44 -0
  53. package/dist/git-hosts.js +81 -0
  54. package/dist/hooks.d.ts +125 -20
  55. package/dist/hooks.js +5 -0
  56. package/dist/http-access.d.ts +62 -0
  57. package/dist/http-access.js +12 -0
  58. package/dist/identity.d.ts +22 -9
  59. package/dist/index.d.ts +26 -1
  60. package/dist/index.js +26 -1
  61. package/dist/marketplace.d.ts +26 -0
  62. package/dist/marketplace.js +43 -1
  63. package/dist/model-params.d.ts +41 -22
  64. package/dist/model-params.js +28 -15
  65. package/dist/model.d.ts +206 -71
  66. package/dist/model.js +152 -19
  67. package/dist/net.d.ts +52 -0
  68. package/dist/net.js +34 -0
  69. package/dist/network-classes.d.ts +98 -0
  70. package/dist/network-classes.js +291 -0
  71. package/dist/permissions.d.ts +41 -21
  72. package/dist/permissions.js +101 -42
  73. package/dist/plugin-manifest.d.ts +45 -5
  74. package/dist/plugin-manifest.js +169 -6
  75. package/dist/plugin-package.d.ts +82 -38
  76. package/dist/plugin-package.js +61 -29
  77. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  78. package/dist/sandbox-linux-runtime-source.js +2318 -0
  79. package/dist/sandbox-native-runtime-source.d.ts +8 -0
  80. package/dist/sandbox-native-runtime-source.js +465 -0
  81. package/dist/sandbox-operation.d.ts +284 -0
  82. package/dist/sandbox-operation.js +262 -0
  83. package/dist/sandbox-runtime-source.d.ts +19 -0
  84. package/dist/sandbox-runtime-source.js +28 -0
  85. package/dist/sandbox-write-denies.d.ts +139 -0
  86. package/dist/sandbox-write-denies.js +869 -0
  87. package/dist/sandbox.d.ts +190 -16
  88. package/dist/sandbox.js +89 -14
  89. package/dist/secret.d.ts +4 -1
  90. package/dist/secret.js +4 -1
  91. package/dist/setup-check.d.ts +115 -0
  92. package/dist/setup-check.js +142 -0
  93. package/dist/setup-guide-parse.d.ts +121 -0
  94. package/dist/setup-guide-parse.js +350 -0
  95. package/dist/setup-guide-render.d.ts +45 -0
  96. package/dist/setup-guide-render.js +351 -0
  97. package/dist/setup-guide.d.ts +94 -0
  98. package/dist/setup-guide.js +336 -0
  99. package/dist/shell-capabilities.d.ts +88 -0
  100. package/dist/shell-capabilities.js +13 -0
  101. package/dist/shell-environment.d.ts +57 -0
  102. package/dist/shell-environment.js +16 -0
  103. package/dist/skill-invocation.d.ts +4 -3
  104. package/dist/skill-invocation.js +5 -4
  105. package/dist/skill.d.ts +34 -21
  106. package/dist/skill.js +48 -31
  107. package/dist/storage.d.ts +52 -25
  108. package/dist/theme-assets.d.ts +39 -0
  109. package/dist/theme-assets.js +449 -0
  110. package/dist/theme-readability.d.ts +37 -0
  111. package/dist/theme-readability.js +145 -0
  112. package/dist/theme-tokens.generated.d.ts +287 -0
  113. package/dist/theme-tokens.generated.js +176 -0
  114. package/dist/theme.d.ts +152 -0
  115. package/dist/theme.js +392 -0
  116. package/dist/tool.d.ts +69 -26
  117. package/dist/tool.js +29 -9
  118. package/dist/ui-parts.d.ts +23 -0
  119. package/dist/ui-parts.js +348 -0
  120. package/dist/ui-resolve.d.ts +35 -0
  121. package/dist/ui-resolve.js +42 -0
  122. package/dist/ui-slots.d.ts +65 -0
  123. package/dist/ui-slots.js +261 -0
  124. package/dist/ui.d.ts +212 -76
  125. package/dist/ui.js +101 -27
  126. package/dist/url.d.ts +4 -1
  127. package/dist/url.js +4 -1
  128. package/package.json +8 -1
  129. package/schemas/bootstrap.v1.schema.json +6 -0
  130. package/schemas/connector-template.v1.schema.json +35 -0
  131. package/schemas/marketplace.v1.schema.json +14 -0
  132. package/schemas/plugin.v1.schema.json +115 -3
  133. package/schemas/theme.v1.schema.json +225 -0
@@ -1,6 +1,9 @@
1
1
  import { POLICY_HOOKS } from "./hooks.js";
2
+ import { HTTP_ACCESS } from "./http-access.js";
3
+ import { SETUP_CHECK_ID_RE, SETUP_CHECK_LIMITS } from "./setup-check.js";
2
4
  import { UI_ICONS } from "./ui.js";
3
- /** hook 挂载点(封闭列表,见总设计 2.4)。 */
5
+ import { isCompactForm, parseSlotRef, uiSlot } from "./ui-slots.js";
6
+ /** Hook mount points (a closed list, see the overall design 2.4). */
4
7
  export const HOOK_MOUNT_POINTS = [
5
8
  "session.start",
6
9
  "session.end",
@@ -10,6 +13,9 @@ export const HOOK_MOUNT_POINTS = [
10
13
  "tool.preExecute",
11
14
  "tool.postExecute",
12
15
  "usage.report",
16
+ "org.member_removed",
17
+ "agent.deleted",
18
+ "org.deleted",
13
19
  ];
14
20
  const HOOKS = new Set(HOOK_MOUNT_POINTS);
15
21
  /** A platform API not declared in the manifest was used. */
@@ -36,6 +42,8 @@ const KEYS = new Set([
36
42
  "storage",
37
43
  "network",
38
44
  "ui",
45
+ "client",
46
+ "setupChecks",
39
47
  ]);
40
48
  const POLICY = new Set(POLICY_HOOKS);
41
49
  const METHODS = new Set(["GET", "POST", "PUT", "DELETE"]);
@@ -57,7 +65,7 @@ function strList(label, v, errs) {
57
65
  }
58
66
  return out;
59
67
  }
60
- /** 校验权限清单,返回错误列表(空表示合法)。 */
68
+ /** Validates the permission manifest and returns the list of errors (empty means valid). */
61
69
  export function validatePermissions(plugin, p) {
62
70
  if (p === undefined)
63
71
  return [];
@@ -68,7 +76,7 @@ export function validatePermissions(plugin, p) {
68
76
  if (!KEYS.has(k))
69
77
  errs.push(`unknown permissions key "${k}"`);
70
78
  }
71
- for (const k of ["secrets", "storage"]) {
79
+ for (const k of ["secrets", "storage", "client"]) {
72
80
  if (p[k] !== undefined && typeof p[k] !== "boolean") {
73
81
  errs.push(`permissions.${k} must be a boolean`);
74
82
  }
@@ -110,14 +118,27 @@ export function validatePermissions(plugin, p) {
110
118
  !METHODS.has(r.method) ||
111
119
  typeof r.path !== "string" ||
112
120
  !r.path.startsWith("/") ||
113
- (r.public !== undefined && typeof r.public !== "boolean")) {
114
- errs.push("permissions.http entries need method GET/POST/PUT/DELETE and a path starting with /");
121
+ typeof r.access !== "string" ||
122
+ !HTTP_ACCESS.includes(r.access)) {
123
+ errs.push("permissions.http entries need method GET/POST/PUT/DELETE, a path starting with /, and access public/embed/member/admin");
115
124
  continue;
116
125
  }
117
126
  const key = `${r.method} ${r.path}`;
118
127
  if (seen.has(key))
119
128
  errs.push(`permissions.http has duplicate route "${key}"`);
120
129
  seen.add(key);
130
+ if (r.path === "/orgs" || r.path.startsWith("/orgs/")) {
131
+ errs.push(`permissions.http route "${key}" must not start with /orgs/ (reserved for org routes)`);
132
+ }
133
+ if (r.access === "embed" && !r.path.startsWith(UI_EMBED_PREFIX)) {
134
+ errs.push(`permissions.http embed route "${key}" must be under ${UI_EMBED_PREFIX}`);
135
+ }
136
+ if ((r.access === "member" || r.access === "admin") &&
137
+ // anywhere, not only after a slash: find-my-way lets a later duplicate param win, so
138
+ // `/x-:orgId` would override the mount's `:orgId`
139
+ /:orgId(?![A-Za-z0-9_])/.test(r.path)) {
140
+ errs.push(`permissions.http route "${key}" must not contain :orgId (the org comes from the mount)`);
141
+ }
121
142
  }
122
143
  }
123
144
  }
@@ -126,9 +147,11 @@ export function validatePermissions(plugin, p) {
126
147
  errs.push("permissions.ui must be an object");
127
148
  else {
128
149
  for (const k of Object.keys(p.ui)) {
129
- if (k !== "views" && k !== "embeds")
150
+ if (k !== "views" && k !== "embeds" && k !== "components")
130
151
  errs.push(`unknown permissions.ui key "${k}"`);
131
152
  }
153
+ if (p.ui.components !== undefined)
154
+ strList("permissions.ui.components", p.ui.components, errs);
132
155
  const views = p.ui.views === undefined ? [] : strList("permissions.ui.views", p.ui.views, errs);
133
156
  const embeds = p.ui.embeds === undefined ? [] : strList("permissions.ui.embeds", p.ui.embeds, errs);
134
157
  for (const id of views) {
@@ -137,6 +160,17 @@ export function validatePermissions(plugin, p) {
137
160
  }
138
161
  }
139
162
  }
163
+ if (p.setupChecks !== undefined) {
164
+ const ids = strList("permissions.setupChecks", p.setupChecks, errs);
165
+ for (const id of ids) {
166
+ if (!SETUP_CHECK_ID_RE.test(id)) {
167
+ errs.push(`permissions.setupChecks id "${id}" must match ${SETUP_CHECK_ID_RE}`);
168
+ }
169
+ }
170
+ if (ids.length > SETUP_CHECK_LIMITS.idsPerExtension) {
171
+ errs.push(`permissions.setupChecks has more than ${SETUP_CHECK_LIMITS.idsPerExtension} ids`);
172
+ }
173
+ }
140
174
  if (p.models !== undefined) {
141
175
  if (!Array.isArray(p.models))
142
176
  errs.push("permissions.models must be an array");
@@ -146,13 +180,13 @@ export function validatePermissions(plugin, p) {
146
180
  const label = isObj(m) && isObj(m.label) ? m.label : undefined;
147
181
  if (!isObj(m) ||
148
182
  typeof m.purpose !== "string" ||
149
- (m.kind !== "chat" && m.kind !== "embedding") ||
183
+ (m.kind !== "chat" && m.kind !== "embedding" && m.kind !== "image_generation") ||
150
184
  !label ||
151
185
  typeof label.zh !== "string" ||
152
186
  label.zh === "" ||
153
187
  typeof label.en !== "string" ||
154
188
  label.en === "") {
155
- errs.push("permissions.models entries need purpose, kind chat/embedding and label zh/en");
189
+ errs.push("permissions.models entries need purpose, kind chat/embedding/image_generation, label zh/en");
156
190
  continue;
157
191
  }
158
192
  if (!m.purpose.startsWith(`${plugin}.`) || m.purpose.length === plugin.length + 1) {
@@ -168,20 +202,20 @@ export function validatePermissions(plugin, p) {
168
202
  }
169
203
  const UI_ID_RE = /^[a-z][a-z0-9-]{0,39}$/;
170
204
  const UI_TITLE_MAX = 100;
171
- const UI_PLACES = [
172
- "conversation",
173
- "panel",
174
- "section",
175
- "inline",
176
- "page",
177
- "file-preview",
178
- ];
179
205
  const UI_EMBED_PREFIX = "/ui/";
180
206
  /**
181
- * 校验清单 `ui` 并与权限清单交叉核对,返回错误列表(空表示合法):
182
- * 每个贡献的 id 恰好出现在 `permissions.ui.views`(kind view)或 `permissions.ui.embeds`(kind embed)里,
183
- * `permissions.ui` 里也不能有清单 `ui` 没有的 id;embed 的 path 以 `/ui/` 开头并在 `permissions.http` 中声明为 GET。
184
- * 假定 `permissions` 已经过 {@link validatePermissions}。
207
+ * Checks the structure of the manifest's `ui` and cross-checks it with the permission manifest;
208
+ * returns the problems (empty = valid). Only structural problems (UI slots spec §3.2, client
209
+ * extensions spec §5.1): each contribution's id is listed in the list of its kind,
210
+ * `permissions.ui.views` (view), `permissions.ui.embeds` (embed) or `permissions.ui.components`
211
+ * (component), an id is in at most one of the three, and `permissions.ui` lists no id the `ui`
212
+ * lacks; `permissions.ui.components` needs `permissions.client: true`; an embed's path starts with
213
+ * `/ui/` and is declared in `permissions.http` as GET, a view or component has no path; exactly one
214
+ * of `slot` (a well-formed slot reference) and `place` (a known place); for a slot the catalog
215
+ * knows at the version named, a kind it accepts and, unless an alias, the icon it requires. An
216
+ * unknown slot id or version is not a problem here: `resolveUiSlots` drops that contribution and
217
+ * the rest of the extension loads.
218
+ * Assumes `permissions` passed {@link validatePermissions}.
185
219
  */
186
220
  export function validateUiContributions(ui, permissions) {
187
221
  const perms = isObj(permissions) ? permissions : {};
@@ -191,10 +225,21 @@ export function validateUiContributions(ui, permissions) {
191
225
  : [];
192
226
  const views = listed("views");
193
227
  const embeds = listed("embeds");
228
+ const components = listed("components");
229
+ // an id in more than one list is reported once, not again as a mismatch of each list
230
+ const multiListed = new Set();
231
+ for (const id of new Set([...views, ...embeds, ...components])) {
232
+ if ([views, embeds, components].filter((l) => l.includes(id)).length > 1)
233
+ multiListed.add(id);
234
+ }
194
235
  const gets = new Set((Array.isArray(perms.http) ? perms.http : [])
195
- .filter((r) => isObj(r) && r.method === "GET")
236
+ .filter((r) => isObj(r) && r.method === "GET" && r.access === "public")
196
237
  .map((r) => r.path));
197
238
  const errs = [];
239
+ for (const id of multiListed)
240
+ errs.push(`ui "${id}" is listed in more than one of permissions.ui.views / embeds / components`);
241
+ if (components.length > 0 && perms.client !== true)
242
+ errs.push("permissions.ui.components needs permissions.client: true");
198
243
  const contributions = [];
199
244
  if (ui !== undefined) {
200
245
  if (!Array.isArray(ui))
@@ -203,7 +248,6 @@ export function validateUiContributions(ui, permissions) {
203
248
  contributions.push(...ui);
204
249
  }
205
250
  const seen = new Map();
206
- const aliases = [];
207
251
  contributions.forEach((c, i) => {
208
252
  const at = `ui[${i}]`;
209
253
  if (!isObj(c)) {
@@ -219,53 +263,68 @@ export function validateUiContributions(ui, permissions) {
219
263
  if (!title ||
220
264
  [title.zh, title.en].some((t) => typeof t !== "string" || t === "" || t.length > UI_TITLE_MAX))
221
265
  errs.push(`ui "${id}" title needs non-empty zh and en of at most ${UI_TITLE_MAX} characters`);
222
- if (!UI_PLACES.includes(c.place))
223
- errs.push(`ui "${id}" place must be one of ${UI_PLACES.join(", ")}`);
224
- if (c.kind !== "view" && c.kind !== "embed") {
225
- errs.push(`ui "${id}" kind must be view or embed`);
266
+ // the slot it names, when it is well formed (known to the catalog or not)
267
+ const slotRef = typeof c.slot === "string" ? parseSlotRef(c.slot) : null;
268
+ if (slotRef === null)
269
+ errs.push(`ui "${id}" slot must be a slot reference like "org.page" or "org.page@1"`);
270
+ if (c.after !== undefined && typeof c.after !== "string")
271
+ errs.push(`ui "${id}" after must be a string`);
272
+ if (c.kind !== "view" && c.kind !== "embed" && c.kind !== "component") {
273
+ errs.push(`ui "${id}" kind must be view, embed or component`);
226
274
  return;
227
275
  }
276
+ if (c.compact !== undefined && !isCompactForm(c.compact))
277
+ errs.push(`ui "${id}" compact must be one of kept, drawer, hidden`);
228
278
  if (c.icon !== undefined && !UI_ICONS.includes(c.icon))
229
279
  errs.push(`ui "${id}" icon must be one of ${UI_ICONS.join(", ")}`);
230
- if (c.aliasOf !== undefined)
231
- aliases.push({ id, kind: c.kind, target: c.aliasOf });
280
+ // the slot checks describe only the catalog's version: another version is left to
281
+ // resolveUiSlots, which drops it (unsupported-version) without failing the extension
282
+ const known = slotRef === null ? undefined : uiSlot(slotRef.id);
283
+ const spec = known !== undefined && known.version === slotRef?.version ? known : undefined;
284
+ if (spec !== undefined) {
285
+ if (!spec.accepts.includes(c.kind))
286
+ errs.push(`ui "${id}" slot ${spec.id} does not accept kind ${c.kind}`);
287
+ if (spec.icon === "required" && c.icon === undefined)
288
+ errs.push(`ui "${id}" slot ${spec.id} needs an icon`);
289
+ }
232
290
  if (seen.has(id))
233
291
  errs.push(`ui has duplicate id "${id}"`);
234
292
  seen.set(id, c.kind);
235
293
  if (c.kind === "view") {
236
- if (c.place === "file-preview")
237
- errs.push(`ui "${id}" place file-preview is only allowed for kind embed`);
238
294
  if (c.path !== undefined)
239
295
  errs.push(`ui "${id}" path is only allowed for kind embed`);
240
- if (!views.includes(id))
296
+ if (!views.includes(id) && !multiListed.has(id))
241
297
  errs.push(`ui "${id}" (view) must be listed in permissions.ui.views`);
242
298
  return;
243
299
  }
244
- if (!embeds.includes(id))
300
+ if (c.kind === "component") {
301
+ if (c.path !== undefined)
302
+ errs.push(`ui "${id}" is a component and cannot have a path`);
303
+ if (!components.includes(id) && !multiListed.has(id))
304
+ errs.push(`ui "${id}" is a component; list it in permissions.ui.components`);
305
+ return;
306
+ }
307
+ if (!embeds.includes(id) && !multiListed.has(id))
245
308
  errs.push(`ui "${id}" (embed) must be listed in permissions.ui.embeds`);
246
309
  if (typeof c.path !== "string" || !c.path.startsWith(UI_EMBED_PREFIX)) {
247
310
  errs.push(`ui "${id}" (embed) path must start with "${UI_EMBED_PREFIX}"`);
248
311
  }
249
312
  else if (!gets.has(c.path)) {
250
- errs.push(`ui "${id}" (embed) path must be declared in permissions.http as "GET ${c.path}"`);
313
+ errs.push(`ui "${id}" embed path "${c.path}" must be declared in permissions.http as GET with access public`);
251
314
  }
252
315
  });
253
- const aliasIds = new Set(aliases.map((a) => a.id));
254
- for (const a of aliases) {
255
- if (typeof a.target !== "string" ||
256
- a.target === a.id ||
257
- aliasIds.has(a.target) ||
258
- seen.get(a.target) !== a.kind)
259
- errs.push(`ui "${a.id}" aliasOf must name another, non-alias ${a.kind} contribution`);
260
- }
261
316
  for (const [k, kind, ids] of [
262
317
  ["views", "view", views],
263
318
  ["embeds", "embed", embeds],
264
319
  ]) {
265
320
  for (const id of ids) {
266
- if (seen.get(id) !== kind)
321
+ if (seen.get(id) !== kind && !multiListed.has(id))
267
322
  errs.push(`permissions.ui.${k} entry "${id}" has no matching ${kind} contribution in ui`);
268
323
  }
269
324
  }
325
+ for (const id of components) {
326
+ if (seen.get(id) !== "component" && !multiListed.has(id))
327
+ errs.push(`permissions.ui.components lists "${id}", which is not a component contribution`);
328
+ }
270
329
  return errs;
271
330
  }
@@ -1,9 +1,13 @@
1
1
  import { z } from "zod";
2
+ import { type PluginClientSection } from "./client-section.js";
2
3
  import { type JsonSchema } from "./config-ui.js";
3
4
  import { type ConnectorTemplateSpec, type LocalizedName, type StaticExtensionManifest } from "./plugin-package.js";
5
+ import { type PluginSetupGuide } from "./setup-guide.js";
6
+ import { type PluginThemeRef } from "./theme.js";
4
7
  /**
5
8
  * The plugin manifest `.capybara-plugin/plugin.json` (package ecosystem spec §4.1). A plugin is a
6
- * bundle of at most one extension, skills and connector templates, packed as an npm-pack tgz:
9
+ * bundle of at most one extension, skills, connector templates, agent templates and themes, packed as
10
+ * an npm-pack tgz:
7
11
  *
8
12
  * ```
9
13
  * package/package.json npm metadata; version equals plugin.json version
@@ -11,13 +15,14 @@ import { type ConnectorTemplateSpec, type LocalizedName, type StaticExtensionMan
11
15
  * package/skills/<name>/SKILL.md skills
12
16
  * package/connectors/<id>.json connector templates ({@link ConnectorTemplateFile})
13
17
  * package/agents/<name>.md agent templates (parsed by `parseAgentTemplate`)
18
+ * package/themes/<id>.json themes (parsed by `parseThemeFile`)
14
19
  * package/dist/index.mjs extension entry (only with an extension)
15
20
  * package/migrations/*.sql, package/ui/**
16
21
  * ```
17
22
  *
18
23
  * Paths start with `./` and stay inside the plugin root. Omitting `skills` / `connectorTemplates`
19
- * / `agents` means "scan `skills/*\/SKILL.md` / `connectors/*.json` / `agents/*.md`" (done by the
20
- * kernel when it reads the package). `extension` is written by the packer, never by hand.
24
+ * / `agents` / `themes` means "scan `skills/*\/SKILL.md` / `connectors/*.json` / `agents/*.md` /
25
+ * `themes/*.json`" (done by the kernel when it reads the package). `extension` is written by the packer, never by hand.
21
26
  *
22
27
  * The committed JSON Schema (`schemas/plugin.v1.schema.json`) is generated from
23
28
  * {@link PluginManifestSchema} by `pnpm gen:package-schemas` and drift-checked by
@@ -39,10 +44,14 @@ export declare const PLUGIN_MANIFEST_LIMITS: {
39
44
  readonly connectorTemplates: 20;
40
45
  /** Agent templates ({@link AGENT_TEMPLATE_LIMITS}`.perPlugin`). */
41
46
  readonly agents: 64;
47
+ /** Themes ({@link THEME_LIMITS}`.perPlugin`). */
48
+ readonly themes: 10;
42
49
  readonly descriptionChars: 1024;
43
50
  readonly publisherChars: 100;
44
51
  readonly displayNameChars: 100;
45
52
  readonly pathChars: 512;
53
+ /** Entries of `suggestedAppearance.replacements`. */
54
+ readonly appearanceReplacements: 8;
46
55
  };
47
56
  /** A plugin this one depends on: a plugin name and a semver range. */
48
57
  export interface PluginDependency {
@@ -54,8 +63,6 @@ export interface PluginDependency {
54
63
  /** A skill of the plugin: a `./…` directory holding SKILL.md. */
55
64
  export interface PluginSkillRef {
56
65
  path: string;
57
- /** Suggested as pinned when an agent selects the skill (spec §9.1). */
58
- pinned?: boolean;
59
66
  }
60
67
  /** A connector template of the plugin: a `./…/<id>.json` file ({@link ConnectorTemplateFile}). */
61
68
  export interface PluginConnectorTemplateRef {
@@ -84,6 +91,18 @@ export interface PluginExtensionSection {
84
91
  deployment?: JsonSchema;
85
92
  org?: JsonSchema;
86
93
  };
94
+ /** Browser code, styles and assets (needs `permissions.client: true`); see {@link PluginClientSection}. */
95
+ client?: PluginClientSection;
96
+ }
97
+ /**
98
+ * How the plugin suggests it should look when chosen (client extensions spec §6.5). Nothing applies
99
+ * on install; an admin applies it in one confirmed step.
100
+ */
101
+ export interface SuggestedAppearance {
102
+ /** A theme id (file base name) of this plugin. */
103
+ theme?: string;
104
+ /** Replaceable slot id → a `component` contribution id of this plugin's extension in that slot. */
105
+ replacements?: Record<string, string>;
87
106
  }
88
107
  /**
89
108
  * A plugin's description: a string (English) or `{ en, zh? }`, each ≤ 1024 characters. Read it
@@ -123,6 +142,16 @@ export interface PluginManifest {
123
142
  connectorTemplates?: PluginConnectorTemplateRef[];
124
143
  /** Agent templates; omitted = scan `agents/*.md`. */
125
144
  agents?: PluginAgentRef[];
145
+ /** Themes; omitted = scan `themes/*.json`. */
146
+ themes?: PluginThemeRef[];
147
+ /**
148
+ * Setup guides (spec `2026-11-09-setup-guides-v2-design.md`): Markdown documents at
149
+ * `guides/<id>.md` (+ `guides/<id>.zh.md`) the kernel renders for a place; see
150
+ * {@link PluginSetupGuide}.
151
+ */
152
+ setupGuides?: PluginSetupGuide[];
153
+ /** See {@link SuggestedAppearance}. */
154
+ suggestedAppearance?: SuggestedAppearance;
126
155
  extension?: PluginExtensionSection;
127
156
  }
128
157
  /** A connector template file `connectors/<id>.json`; the template id is the file's base name. */
@@ -131,6 +160,12 @@ export interface ConnectorTemplateFile {
131
160
  description?: string;
132
161
  /** Safe path relative to the plugin root (an optional leading `./`), .svg / .png. */
133
162
  icon?: string;
163
+ /**
164
+ * `false`: the template starts switched off in every org, even where its plugin is on, until an
165
+ * org admin switches it on (it then needs no org input while off). Default `true`: on wherever
166
+ * its plugin is. Ignored for a builtin plugin.
167
+ */
168
+ defaultEnabled?: boolean;
134
169
  /** Validated by {@link validateConnectorTemplate}. */
135
170
  template: ConnectorTemplateSpec;
136
171
  }
@@ -162,3 +197,8 @@ export declare function parsePluginManifest(json: unknown): PluginManifest | {
162
197
  export declare function parseConnectorTemplateFile(json: unknown): ConnectorTemplateFile | {
163
198
  errors: string[];
164
199
  };
200
+ /**
201
+ * The theme check of `suggestedAppearance` after the themes are known (the manifest may omit
202
+ * `themes` and let the scan find them): shared by the packer and the kernel.
203
+ */
204
+ export declare function appearanceIssues(manifest: PluginManifest, themeIds: readonly string[]): string[];
@@ -1,13 +1,19 @@
1
1
  import semver from "semver";
2
2
  import { z } from "zod";
3
3
  import { AGENT_TEMPLATE_LIMITS } from "./agent-template.js";
4
+ import { validateClientSection } from "./client-section.js";
4
5
  import { CONFIG_UI_LIMITS } from "./config-ui.js";
5
6
  import { defineExtension, EXTENSION_NAME_RE } from "./define-extension.js";
7
+ import { GitSourceSchema } from "./git-hosts.js";
6
8
  import { CATALOG_ITEM_NAME_RE, CONNECTOR_TEMPLATE_LIMITS, isSafePackagePath, SEMVER_VERSION_RE, validateConnectorTemplate, } from "./plugin-package.js";
7
9
  import { hasUpperBound } from "./semver-range.js";
10
+ import { SETUP_GUIDE_LIMITS, SETUP_GUIDE_PLACES } from "./setup-guide.js";
11
+ import { THEME_LIMITS, themeIdOf } from "./theme.js";
12
+ import { parseSlotRef, uiSlot } from "./ui-slots.js";
8
13
  /**
9
14
  * The plugin manifest `.capybara-plugin/plugin.json` (package ecosystem spec §4.1). A plugin is a
10
- * bundle of at most one extension, skills and connector templates, packed as an npm-pack tgz:
15
+ * bundle of at most one extension, skills, connector templates, agent templates and themes, packed as
16
+ * an npm-pack tgz:
11
17
  *
12
18
  * ```
13
19
  * package/package.json npm metadata; version equals plugin.json version
@@ -15,13 +21,14 @@ import { hasUpperBound } from "./semver-range.js";
15
21
  * package/skills/<name>/SKILL.md skills
16
22
  * package/connectors/<id>.json connector templates ({@link ConnectorTemplateFile})
17
23
  * package/agents/<name>.md agent templates (parsed by `parseAgentTemplate`)
24
+ * package/themes/<id>.json themes (parsed by `parseThemeFile`)
18
25
  * package/dist/index.mjs extension entry (only with an extension)
19
26
  * package/migrations/*.sql, package/ui/**
20
27
  * ```
21
28
  *
22
29
  * Paths start with `./` and stay inside the plugin root. Omitting `skills` / `connectorTemplates`
23
- * / `agents` means "scan `skills/*\/SKILL.md` / `connectors/*.json` / `agents/*.md`" (done by the
24
- * kernel when it reads the package). `extension` is written by the packer, never by hand.
30
+ * / `agents` / `themes` means "scan `skills/*\/SKILL.md` / `connectors/*.json` / `agents/*.md` /
31
+ * `themes/*.json`" (done by the kernel when it reads the package). `extension` is written by the packer, never by hand.
25
32
  *
26
33
  * The committed JSON Schema (`schemas/plugin.v1.schema.json`) is generated from
27
34
  * {@link PluginManifestSchema} by `pnpm gen:package-schemas` and drift-checked by
@@ -43,10 +50,14 @@ export const PLUGIN_MANIFEST_LIMITS = {
43
50
  connectorTemplates: 20,
44
51
  /** Agent templates ({@link AGENT_TEMPLATE_LIMITS}`.perPlugin`). */
45
52
  agents: AGENT_TEMPLATE_LIMITS.perPlugin,
53
+ /** Themes ({@link THEME_LIMITS}`.perPlugin`). */
54
+ themes: THEME_LIMITS.perPlugin,
46
55
  descriptionChars: 1024,
47
56
  publisherChars: 100,
48
57
  displayNameChars: 100,
49
58
  pathChars: 512,
59
+ /** Entries of `suggestedAppearance.replacements`. */
60
+ appearanceReplacements: 8,
50
61
  };
51
62
  /** A plugin description as `{ en, zh? }` (a plain string is the English text). */
52
63
  export function pluginDescription(d) {
@@ -55,6 +66,7 @@ export function pluginDescription(d) {
55
66
  const L = PLUGIN_MANIFEST_LIMITS;
56
67
  const MAX_ERRORS = 50;
57
68
  const ICON_RE = /\.(?:svg|png)$/i;
69
+ const COMPONENT_ID_RE = /^[a-z][a-z0-9-]{0,39}$/;
58
70
  const HTTPS_URL_RE = /^https:\/\/\S+$/;
59
71
  const text = (max, what) => z
60
72
  .string()
@@ -97,6 +109,35 @@ const configSchemaJson = z
97
109
  .refine((v) => new TextEncoder().encode(JSON.stringify(v)).length <= CONFIG_UI_LIMITS.configSchemaBytes, {
98
110
  message: `must be at most ${CONFIG_UI_LIMITS.configSchemaBytes} bytes of JSON (${CONFIG_UI_LIMITS.configSchemaBytes / 1024} KiB)`,
99
111
  });
112
+ const setupGuide = z.strictObject({
113
+ id: z.string().regex(CATALOG_ITEM_NAME_RE, {
114
+ message: "id must match ^[a-z0-9][a-z0-9-]{0,63}$",
115
+ }),
116
+ place: z.enum(SETUP_GUIDE_PLACES),
117
+ template: z
118
+ .string()
119
+ .regex(CATALOG_ITEM_NAME_RE, { message: "template must match ^[a-z0-9][a-z0-9-]{0,63}$" })
120
+ .optional(),
121
+ });
122
+ const clientSection = z
123
+ .strictObject({
124
+ entry: z.string().max(L.pathChars).optional(),
125
+ styles: z.array(z.string().max(L.pathChars)).max(64).optional(),
126
+ assets: z.array(z.string().max(L.pathChars)).max(256).optional(),
127
+ integrity: z.record(z.string().max(L.pathChars), z.string().max(128)),
128
+ apiVersion: z.number().int().min(1),
129
+ })
130
+ .superRefine((c, ctx) => {
131
+ for (const e of validateClientSection(c))
132
+ ctx.addIssue({ code: "custom", path: [], message: e });
133
+ });
134
+ const suggestedAppearance = z.strictObject({
135
+ theme: z
136
+ .string()
137
+ .regex(CATALOG_ITEM_NAME_RE, { message: "theme must match ^[a-z0-9][a-z0-9-]{0,63}$" })
138
+ .optional(),
139
+ replacements: z.record(z.string().max(100), z.string().max(100)).optional(),
140
+ });
100
141
  const extensionSection = z.strictObject({
101
142
  entry: dotPath("entry").refine((p) => p.endsWith(".mjs"), {
102
143
  message: "entry must be a .mjs file",
@@ -107,6 +148,7 @@ const extensionSection = z.strictObject({
107
148
  configSchemas: z
108
149
  .strictObject({ deployment: configSchemaJson.optional(), org: configSchemaJson.optional() })
109
150
  .optional(),
151
+ client: clientSection.optional(),
110
152
  });
111
153
  const schema = z
112
154
  .strictObject({
@@ -153,7 +195,7 @@ const schema = z
153
195
  .max(L.dependencies)
154
196
  .optional(),
155
197
  skills: z
156
- .array(z.strictObject({ path: dotPath("path"), pinned: z.boolean().optional() }))
198
+ .array(z.strictObject({ path: dotPath("path") }))
157
199
  .max(L.skills)
158
200
  .optional(),
159
201
  connectorTemplates: z
@@ -168,6 +210,14 @@ const schema = z
168
210
  }))
169
211
  .max(L.agents)
170
212
  .optional(),
213
+ themes: z
214
+ .array(z.strictObject({
215
+ path: dotPath("path").refine((p) => p.endsWith(".json") && CATALOG_ITEM_NAME_RE.test(themeIdOf(p)), { message: "path must be a <id>.json file with id matching ^[a-z0-9][a-z0-9-]{0,63}$" }),
216
+ }))
217
+ .max(L.themes)
218
+ .optional(),
219
+ setupGuides: z.array(setupGuide).max(SETUP_GUIDE_LIMITS.guides).optional(),
220
+ suggestedAppearance: suggestedAppearance.optional(),
171
221
  extension: extensionSection.optional(),
172
222
  })
173
223
  .superRefine((m, ctx) => {
@@ -206,16 +256,117 @@ const schema = z
206
256
  issue(["agents", i, "path"], `duplicate agent template path ${a.path}`);
207
257
  agentPaths.add(a.path);
208
258
  });
259
+ const themeIds = new Set();
260
+ m.themes?.forEach((t, i) => {
261
+ const id = themeIdOf(t.path);
262
+ if (themeIds.has(id))
263
+ issue(["themes", i, "path"], `duplicate theme id ${id}`);
264
+ themeIds.add(id);
265
+ });
266
+ const guideIds = new Set();
267
+ const guideTemplates = new Set();
268
+ let channelGuides = 0;
269
+ m.setupGuides?.forEach((g, i) => {
270
+ if (guideIds.has(g.id))
271
+ issue(["setupGuides", i, "id"], `duplicate setup guide id ${g.id}`);
272
+ guideIds.add(g.id);
273
+ if (g.place === "connector-template") {
274
+ if (g.template === undefined) {
275
+ issue(["setupGuides", i, "template"], "template is required for a connector-template guide");
276
+ }
277
+ else {
278
+ if (m.connectorTemplates !== undefined && !ids.has(g.template)) {
279
+ issue(["setupGuides", i, "template"], `template ${g.template} is not one of the plugin's connector templates`);
280
+ }
281
+ if (guideTemplates.has(g.template)) {
282
+ issue(["setupGuides", i, "template"], `at most one setup guide per connector template (${g.template} has two)`);
283
+ }
284
+ guideTemplates.add(g.template);
285
+ }
286
+ }
287
+ else if (g.template !== undefined) {
288
+ issue(["setupGuides", i, "template"], "template is only for connector-template guides");
289
+ }
290
+ if (g.place === "channel-connection") {
291
+ channelGuides++;
292
+ if (channelGuides === 2) {
293
+ issue(["setupGuides", i, "place"], "a plugin has at most one channel-connection guide");
294
+ }
295
+ }
296
+ if (g.place === "channel-connection" &&
297
+ m.extension !== undefined &&
298
+ !m.extension.manifest.provides.some((p) => p.startsWith("channel@"))) {
299
+ issue(["setupGuides", i, "place"], "a channel-connection guide needs the plugin's extension to provide channel@1");
300
+ }
301
+ });
302
+ const sa = m.suggestedAppearance;
303
+ if (sa !== undefined) {
304
+ const at = ["suggestedAppearance"];
305
+ if (sa.theme === undefined && sa.replacements === undefined) {
306
+ issue(at, "suggestedAppearance needs theme or replacements");
307
+ }
308
+ if (sa.theme !== undefined && m.themes !== undefined && !themeIds.has(sa.theme)) {
309
+ issue([...at, "theme"], `suggestedAppearance.theme names ${sa.theme}, which is not a theme of the plugin`);
310
+ }
311
+ if (sa.replacements !== undefined) {
312
+ const entries = Object.entries(sa.replacements);
313
+ if (m.extension === undefined) {
314
+ issue([...at, "replacements"], "suggestedAppearance.replacements needs an extension");
315
+ }
316
+ if (entries.length > L.appearanceReplacements) {
317
+ issue([...at, "replacements"], `suggestedAppearance.replacements has ${entries.length} entries; the limit is ${L.appearanceReplacements}`);
318
+ }
319
+ const seen = new Set();
320
+ for (const [slot, id] of entries) {
321
+ const ref = parseSlotRef(slot);
322
+ if (ref === null) {
323
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} is not a slot ref`);
324
+ continue;
325
+ }
326
+ if (seen.has(ref.id)) {
327
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} names the slot ${ref.id} again; give each slot once`);
328
+ continue;
329
+ }
330
+ seen.add(ref.id);
331
+ if (!COMPONENT_ID_RE.test(id)) {
332
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} names ${id}, which is not a contribution id`);
333
+ continue;
334
+ }
335
+ const known = uiSlot(ref.id);
336
+ if (known === undefined)
337
+ continue;
338
+ if (known.cardinality !== "single") {
339
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} is not a replaceable slot`);
340
+ continue;
341
+ }
342
+ const ok = (m.extension?.manifest.ui ?? []).some((u) => {
343
+ const us = typeof u.slot === "string" ? parseSlotRef(u.slot) : null;
344
+ return u.id === id && u.kind === "component" && us?.id === ref.id;
345
+ });
346
+ if (!ok) {
347
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} names ${id}, which is not a component contribution in that slot`);
348
+ }
349
+ }
350
+ }
351
+ }
209
352
  if (m.extension === undefined &&
210
353
  m.skills?.length === 0 &&
211
354
  m.connectorTemplates?.length === 0 &&
212
- (m.agents === undefined || m.agents.length === 0)) {
213
- issue([], "a plugin must contain an extension, a skill, a connector template or an agent template");
355
+ (m.agents === undefined || m.agents.length === 0) &&
356
+ (m.themes === undefined || m.themes.length === 0)) {
357
+ issue([], "a plugin must contain an extension, a skill, a connector template, an agent template or a theme");
214
358
  }
215
359
  const ext = m.extension;
216
360
  if (ext === undefined)
217
361
  return;
218
362
  const em = ext.manifest;
363
+ const hasClientPermission = em.permissions.client === true;
364
+ if (ext.client !== undefined && !hasClientPermission) {
365
+ issue(["extension", "client"], "extension.client needs permissions.client: true");
366
+ }
367
+ if (ext.client === undefined && hasClientPermission) {
368
+ issue(["extension", "manifest", "permissions", "client"], "permissions.client is true but extension.client is missing (pack the plugin with its client code, or drop permissions.client)");
369
+ }
219
370
  if (!EXTENSION_NAME_RE.test(m.name)) {
220
371
  issue(["name"], `a plugin with an extension needs an extension name (${EXTENSION_NAME_RE})`);
221
372
  }
@@ -268,6 +419,7 @@ const template = z.strictObject({
268
419
  auth: z.record(z.string(), z.unknown()),
269
420
  ownership: z.enum(["org", "personal"]).optional(),
270
421
  defaultToolPolicies: z.record(z.string(), z.enum(["allow", "ask", "deny"])).optional(),
422
+ git: GitSourceSchema.optional(),
271
423
  icon: z.string().max(L.pathChars).optional(),
272
424
  });
273
425
  const templateFile = z
@@ -281,6 +433,7 @@ const templateFile = z
281
433
  message: "icon must be a relative .svg or .png path inside the plugin",
282
434
  })
283
435
  .optional(),
436
+ defaultEnabled: z.boolean().optional(),
284
437
  template,
285
438
  })
286
439
  // Field rules (no credentials, auth presets, editableEndpoint, ...) belong to validateConnectorTemplate.
@@ -339,3 +492,13 @@ export function parsePluginManifest(json) {
339
492
  export function parseConnectorTemplateFile(json) {
340
493
  return parseWith(ConnectorTemplateFileSchema, json, "connector template file");
341
494
  }
495
+ /**
496
+ * The theme check of `suggestedAppearance` after the themes are known (the manifest may omit
497
+ * `themes` and let the scan find them): shared by the packer and the kernel.
498
+ */
499
+ export function appearanceIssues(manifest, themeIds) {
500
+ const theme = manifest.suggestedAppearance?.theme;
501
+ if (theme === undefined || themeIds.includes(theme))
502
+ return [];
503
+ return [`suggestedAppearance.theme names ${theme}, which is not a theme of the plugin`];
504
+ }