@capybara-hq/plugin-sdk 0.1.0-rc.7 → 0.1.0-rc.70

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 (146) hide show
  1. package/README.md +1 -1
  2. package/agent-docs/agent-templates.md +14 -2
  3. package/agent-docs/concepts.md +14 -5
  4. package/agent-docs/connector-templates.md +11 -3
  5. package/agent-docs/extension-points/channel.md +1 -1
  6. package/agent-docs/extension-points/context.md +15 -0
  7. package/agent-docs/extension-points/device-provider.md +15 -0
  8. package/agent-docs/extension-points/file-preview.md +2 -0
  9. package/agent-docs/extension-points/model-provider.md +3 -1
  10. package/agent-docs/extension-points/object-store.md +2 -0
  11. package/agent-docs/extension-points/push-provider.md +17 -0
  12. package/agent-docs/extensions.md +76 -3
  13. package/agent-docs/plugin-format.md +51 -12
  14. package/agent-docs/setup.md +54 -0
  15. package/dist/agent-template.d.ts +15 -6
  16. package/dist/agent-template.js +32 -13
  17. package/dist/avatar-presets.d.ts +8 -0
  18. package/dist/avatar-presets.js +17 -0
  19. package/dist/bootstrap.d.ts +109 -1
  20. package/dist/bootstrap.js +185 -2
  21. package/dist/cards.d.ts +60 -13
  22. package/dist/cards.js +88 -18
  23. package/dist/channel.d.ts +128 -47
  24. package/dist/channel.js +10 -5
  25. package/dist/client-css.d.ts +36 -0
  26. package/dist/client-css.js +326 -0
  27. package/dist/client-section.d.ts +35 -0
  28. package/dist/client-section.js +133 -0
  29. package/dist/config-ui.d.ts +28 -6
  30. package/dist/config-ui.js +88 -25
  31. package/dist/config-url-fetch.d.ts +19 -0
  32. package/dist/config-url-fetch.js +43 -0
  33. package/dist/connector-auth.d.ts +13 -2
  34. package/dist/connector-auth.js +82 -8
  35. package/dist/connector.d.ts +74 -32
  36. package/dist/context.d.ts +40 -0
  37. package/dist/context.js +2 -0
  38. package/dist/ctx.d.ts +210 -30
  39. package/dist/ctx.js +9 -1
  40. package/dist/define-extension.d.ts +23 -13
  41. package/dist/define-extension.js +19 -5
  42. package/dist/device-denied-paths.d.ts +20 -0
  43. package/dist/device-denied-paths.js +118 -0
  44. package/dist/device-operation.d.ts +339 -0
  45. package/dist/device-operation.js +312 -0
  46. package/dist/device-protocol.d.ts +285 -50
  47. package/dist/device-protocol.js +755 -90
  48. package/dist/device-provider.d.ts +708 -0
  49. package/dist/device-provider.js +325 -0
  50. package/dist/device-service.d.ts +52 -0
  51. package/dist/device-service.js +105 -0
  52. package/dist/dial-in.d.ts +239 -0
  53. package/dist/dial-in.js +155 -0
  54. package/dist/directory.d.ts +15 -12
  55. package/dist/extension-point.d.ts +2 -0
  56. package/dist/extension-point.js +6 -2
  57. package/dist/field-meta.d.ts +19 -0
  58. package/dist/field-meta.js +54 -0
  59. package/dist/file-preview.d.ts +26 -10
  60. package/dist/git-hosts.d.ts +53 -0
  61. package/dist/git-hosts.js +98 -0
  62. package/dist/hooks.d.ts +125 -20
  63. package/dist/hooks.js +5 -0
  64. package/dist/http-access.d.ts +62 -0
  65. package/dist/http-access.js +12 -0
  66. package/dist/identity.d.ts +38 -9
  67. package/dist/identity.js +21 -1
  68. package/dist/index.d.ts +31 -4
  69. package/dist/index.js +31 -4
  70. package/dist/model-params.d.ts +41 -22
  71. package/dist/model-params.js +28 -15
  72. package/dist/model.d.ts +210 -75
  73. package/dist/model.js +152 -19
  74. package/dist/net.d.ts +52 -0
  75. package/dist/net.js +34 -0
  76. package/dist/network-classes.d.ts +98 -0
  77. package/dist/network-classes.js +291 -0
  78. package/dist/permissions.d.ts +65 -22
  79. package/dist/permissions.js +139 -43
  80. package/dist/platform-only.d.ts +27 -0
  81. package/dist/platform-only.js +35 -0
  82. package/dist/plugin-manifest.d.ts +40 -9
  83. package/dist/plugin-manifest.js +171 -60
  84. package/dist/plugin-package.d.ts +82 -39
  85. package/dist/plugin-package.js +68 -41
  86. package/dist/push.d.ts +75 -0
  87. package/dist/push.js +87 -0
  88. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  89. package/dist/sandbox-linux-runtime-source.js +2343 -0
  90. package/dist/sandbox-native-runtime-source.d.ts +10 -0
  91. package/dist/sandbox-native-runtime-source.js +476 -0
  92. package/dist/sandbox-runtime-source.d.ts +47 -0
  93. package/dist/sandbox-runtime-source.js +73 -0
  94. package/dist/sandbox-write-denies.d.ts +139 -0
  95. package/dist/sandbox-write-denies.js +869 -0
  96. package/dist/secret.d.ts +8 -2
  97. package/dist/secret.js +11 -4
  98. package/dist/setup-check.d.ts +128 -0
  99. package/dist/setup-check.js +142 -0
  100. package/dist/setup-guide-parse.d.ts +121 -0
  101. package/dist/setup-guide-parse.js +356 -0
  102. package/dist/setup-guide-render.d.ts +45 -0
  103. package/dist/setup-guide-render.js +351 -0
  104. package/dist/setup-guide.d.ts +86 -72
  105. package/dist/setup-guide.js +340 -108
  106. package/dist/shell-capabilities.d.ts +211 -0
  107. package/dist/shell-capabilities.js +44 -0
  108. package/dist/shell-environment.d.ts +57 -0
  109. package/dist/shell-environment.js +21 -0
  110. package/dist/skill.d.ts +27 -17
  111. package/dist/skill.js +40 -26
  112. package/dist/storage.d.ts +52 -25
  113. package/dist/svg-viewbox.d.ts +10 -0
  114. package/dist/svg-viewbox.js +24 -0
  115. package/dist/theme-assets.d.ts +55 -0
  116. package/dist/theme-assets.js +489 -0
  117. package/dist/theme-readability.d.ts +37 -0
  118. package/dist/theme-readability.js +145 -0
  119. package/dist/theme-tokens.generated.d.ts +299 -0
  120. package/dist/theme-tokens.generated.js +184 -0
  121. package/dist/theme.d.ts +190 -0
  122. package/dist/theme.js +471 -0
  123. package/dist/tool.d.ts +104 -30
  124. package/dist/tool.js +29 -9
  125. package/dist/ui-parts.d.ts +23 -0
  126. package/dist/ui-parts.js +385 -0
  127. package/dist/ui-resolve.d.ts +35 -0
  128. package/dist/ui-resolve.js +42 -0
  129. package/dist/ui-slots.d.ts +65 -0
  130. package/dist/ui-slots.js +261 -0
  131. package/dist/ui.d.ts +221 -77
  132. package/dist/ui.js +104 -27
  133. package/dist/url.d.ts +4 -1
  134. package/dist/url.js +4 -1
  135. package/dist/web.d.ts +26 -20
  136. package/package.json +13 -1
  137. package/schemas/bootstrap-extra.v1.schema.json +186 -0
  138. package/schemas/bootstrap.v1.schema.json +20 -0
  139. package/schemas/connector-template.v1.schema.json +62 -4
  140. package/schemas/plugin.v1.schema.json +93 -143
  141. package/schemas/theme.v1.schema.json +302 -0
  142. package/agent-docs/extension-points/sandbox.md +0 -15
  143. package/dist/org-access.d.ts +0 -27
  144. package/dist/org-access.js +0 -35
  145. package/dist/sandbox.d.ts +0 -254
  146. package/dist/sandbox.js +0 -153
@@ -1,14 +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";
8
- import { SETUP_GUIDE_FILE_RE, SETUP_GUIDE_LANGUAGES, SETUP_GUIDE_LIMITS, SETUP_GUIDE_MODES, SETUP_GUIDE_PLACES, } from "./setup-guide.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";
9
13
  /**
10
14
  * The plugin manifest `.capybara-plugin/plugin.json` (package ecosystem spec §4.1). A plugin is a
11
- * 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:
12
17
  *
13
18
  * ```
14
19
  * package/package.json npm metadata; version equals plugin.json version
@@ -16,13 +21,14 @@ import { SETUP_GUIDE_FILE_RE, SETUP_GUIDE_LANGUAGES, SETUP_GUIDE_LIMITS, SETUP_G
16
21
  * package/skills/<name>/SKILL.md skills
17
22
  * package/connectors/<id>.json connector templates ({@link ConnectorTemplateFile})
18
23
  * package/agents/<name>.md agent templates (parsed by `parseAgentTemplate`)
24
+ * package/themes/<id>.json themes (parsed by `parseThemeFile`)
19
25
  * package/dist/index.mjs extension entry (only with an extension)
20
26
  * package/migrations/*.sql, package/ui/**
21
27
  * ```
22
28
  *
23
29
  * Paths start with `./` and stay inside the plugin root. Omitting `skills` / `connectorTemplates`
24
- * / `agents` means "scan `skills/*\/SKILL.md` / `connectors/*.json` / `agents/*.md`" (done by the
25
- * 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.
26
32
  *
27
33
  * The committed JSON Schema (`schemas/plugin.v1.schema.json`) is generated from
28
34
  * {@link PluginManifestSchema} by `pnpm gen:package-schemas` and drift-checked by
@@ -44,10 +50,14 @@ export const PLUGIN_MANIFEST_LIMITS = {
44
50
  connectorTemplates: 20,
45
51
  /** Agent templates ({@link AGENT_TEMPLATE_LIMITS}`.perPlugin`). */
46
52
  agents: AGENT_TEMPLATE_LIMITS.perPlugin,
53
+ /** Themes ({@link THEME_LIMITS}`.perPlugin`). */
54
+ themes: THEME_LIMITS.perPlugin,
47
55
  descriptionChars: 1024,
48
56
  publisherChars: 100,
49
57
  displayNameChars: 100,
50
58
  pathChars: 512,
59
+ /** Entries of `suggestedAppearance.replacements`. */
60
+ appearanceReplacements: 8,
51
61
  };
52
62
  /** A plugin description as `{ en, zh? }` (a plain string is the English text). */
53
63
  export function pluginDescription(d) {
@@ -56,6 +66,7 @@ export function pluginDescription(d) {
56
66
  const L = PLUGIN_MANIFEST_LIMITS;
57
67
  const MAX_ERRORS = 50;
58
68
  const ICON_RE = /\.(?:svg|png)$/i;
69
+ const COMPONENT_ID_RE = /^[a-z][a-z0-9-]{0,39}$/;
59
70
  const HTTPS_URL_RE = /^https:\/\/\S+$/;
60
71
  const text = (max, what) => z
61
72
  .string()
@@ -82,6 +93,11 @@ const baseId = (p) => (p.split("/").pop() ?? "").replace(/\.json$/, "");
82
93
  const configFields = z
83
94
  .array(z.strictObject({ path: z.string().max(1000), secret: z.boolean(), hot: z.boolean() }))
84
95
  .max(1000);
96
+ const configSchemaJson = z
97
+ .record(z.string(), z.unknown())
98
+ .refine((v) => new TextEncoder().encode(JSON.stringify(v)).length <= CONFIG_UI_LIMITS.configSchemaBytes, {
99
+ message: `must be at most ${CONFIG_UI_LIMITS.configSchemaBytes} bytes of JSON (${CONFIG_UI_LIMITS.configSchemaBytes / 1024} KiB)`,
100
+ });
85
101
  const staticExtensionManifest = z.strictObject({
86
102
  name: z.string(),
87
103
  version: z.string(),
@@ -91,39 +107,39 @@ const staticExtensionManifest = z.strictObject({
91
107
  optional: z.array(z.string()),
92
108
  permissions: z.record(z.string(), z.unknown()),
93
109
  ui: z.array(z.record(z.string(), z.unknown())).optional(),
94
- config: z.strictObject({ deployment: configFields, org: configFields }),
95
- });
96
- const configSchemaJson = z
97
- .record(z.string(), z.unknown())
98
- .refine((v) => new TextEncoder().encode(JSON.stringify(v)).length <= CONFIG_UI_LIMITS.configSchemaBytes, {
99
- message: `must be at most ${CONFIG_UI_LIMITS.configSchemaBytes} bytes of JSON (${CONFIG_UI_LIMITS.configSchemaBytes / 1024} KiB)`,
110
+ config: z.strictObject({ deployment: configFields }),
100
111
  });
101
- const guideText = (max, what) => z.strictObject({ en: text(max, `${what}.en`), zh: text(max, `${what}.zh`).optional() });
102
112
  const setupGuide = z.strictObject({
103
113
  id: z.string().regex(CATALOG_ITEM_NAME_RE, {
104
114
  message: "id must match ^[a-z0-9][a-z0-9-]{0,63}$",
105
115
  }),
106
116
  place: z.enum(SETUP_GUIDE_PLACES),
107
- title: guideText(SETUP_GUIDE_LIMITS.titleChars, "title"),
108
- steps: z
109
- .array(z.strictObject({
110
- en: text(SETUP_GUIDE_LIMITS.stepChars, "en"),
111
- zh: text(SETUP_GUIDE_LIMITS.stepChars, "zh").optional(),
112
- mode: z.string().max(64).optional(),
117
+ templates: z
118
+ .array(z.string().regex(CATALOG_ITEM_NAME_RE, {
119
+ message: "a template must match ^[a-z0-9][a-z0-9-]{0,63}$",
113
120
  }))
114
- .max(SETUP_GUIDE_LIMITS.steps)
121
+ .min(1)
122
+ .max(SETUP_GUIDE_LIMITS.templatesPerGuide)
115
123
  .optional(),
116
- files: z
117
- .array(z.strictObject({
118
- path: dotPath("path").regex(SETUP_GUIDE_FILE_RE, {
119
- message: "path must be a .tmpl, .yaml, .yml, .json or .txt file",
120
- }),
121
- title: guideText(SETUP_GUIDE_LIMITS.titleChars, "title"),
122
- language: z.enum(SETUP_GUIDE_LANGUAGES),
123
- mode: z.string().max(64).optional(),
124
- }))
125
- .max(SETUP_GUIDE_LIMITS.files)
124
+ });
125
+ const clientSection = z
126
+ .strictObject({
127
+ entry: z.string().max(L.pathChars).optional(),
128
+ styles: z.array(z.string().max(L.pathChars)).max(64).optional(),
129
+ assets: z.array(z.string().max(L.pathChars)).max(256).optional(),
130
+ integrity: z.record(z.string().max(L.pathChars), z.string().max(128)),
131
+ apiVersion: z.number().int().min(1),
132
+ })
133
+ .superRefine((c, ctx) => {
134
+ for (const e of validateClientSection(c))
135
+ ctx.addIssue({ code: "custom", path: [], message: e });
136
+ });
137
+ const suggestedAppearance = z.strictObject({
138
+ theme: z
139
+ .string()
140
+ .regex(CATALOG_ITEM_NAME_RE, { message: "theme must match ^[a-z0-9][a-z0-9-]{0,63}$" })
126
141
  .optional(),
142
+ replacements: z.record(z.string().max(100), z.string().max(100)).optional(),
127
143
  });
128
144
  const extensionSection = z.strictObject({
129
145
  entry: dotPath("entry").refine((p) => p.endsWith(".mjs"), {
@@ -132,9 +148,8 @@ const extensionSection = z.strictObject({
132
148
  manifest: staticExtensionManifest,
133
149
  migrations: dotPath("migrations").optional(),
134
150
  ui: dotPath("ui").optional(),
135
- configSchemas: z
136
- .strictObject({ deployment: configSchemaJson.optional(), org: configSchemaJson.optional() })
137
- .optional(),
151
+ configSchemas: z.strictObject({ deployment: configSchemaJson.optional() }).optional(),
152
+ client: clientSection.optional(),
138
153
  });
139
154
  const schema = z
140
155
  .strictObject({
@@ -181,7 +196,7 @@ const schema = z
181
196
  .max(L.dependencies)
182
197
  .optional(),
183
198
  skills: z
184
- .array(z.strictObject({ path: dotPath("path"), pinned: z.boolean().optional() }))
199
+ .array(z.strictObject({ path: dotPath("path") }))
185
200
  .max(L.skills)
186
201
  .optional(),
187
202
  connectorTemplates: z
@@ -196,7 +211,14 @@ const schema = z
196
211
  }))
197
212
  .max(L.agents)
198
213
  .optional(),
214
+ themes: z
215
+ .array(z.strictObject({
216
+ 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}$" }),
217
+ }))
218
+ .max(L.themes)
219
+ .optional(),
199
220
  setupGuides: z.array(setupGuide).max(SETUP_GUIDE_LIMITS.guides).optional(),
221
+ suggestedAppearance: suggestedAppearance.optional(),
200
222
  extension: extensionSection.optional(),
201
223
  })
202
224
  .superRefine((m, ctx) => {
@@ -235,47 +257,119 @@ const schema = z
235
257
  issue(["agents", i, "path"], `duplicate agent template path ${a.path}`);
236
258
  agentPaths.add(a.path);
237
259
  });
260
+ const themeIds = new Set();
261
+ m.themes?.forEach((t, i) => {
262
+ const id = themeIdOf(t.path);
263
+ if (themeIds.has(id))
264
+ issue(["themes", i, "path"], `duplicate theme id ${id}`);
265
+ themeIds.add(id);
266
+ });
238
267
  const guideIds = new Set();
268
+ const guideTemplates = new Set();
269
+ let channelGuides = 0;
239
270
  m.setupGuides?.forEach((g, i) => {
240
271
  if (guideIds.has(g.id))
241
272
  issue(["setupGuides", i, "id"], `duplicate setup guide id ${g.id}`);
242
273
  guideIds.add(g.id);
243
- if ((g.steps?.length ?? 0) === 0 && (g.files?.length ?? 0) === 0) {
244
- issue(["setupGuides", i], "a setup guide needs at least one step or file");
245
- }
246
- const modes = SETUP_GUIDE_MODES[g.place];
247
- const badMode = (mode, path) => {
248
- if (mode !== undefined && !modes.includes(mode)) {
249
- issue(path, `mode must be one of ${modes.join(", ")} for place ${g.place}`);
274
+ if (g.place === "connector-template") {
275
+ if (g.templates === undefined) {
276
+ issue(["setupGuides", i, "templates"], "templates is required for a connector-template guide");
250
277
  }
251
- };
252
- g.steps?.forEach((s, j) => {
253
- badMode(s.mode, ["setupGuides", i, "steps", j, "mode"]);
254
- });
255
- const paths = new Set();
256
- g.files?.forEach((f, j) => {
257
- badMode(f.mode, ["setupGuides", i, "files", j, "mode"]);
258
- if (paths.has(f.path)) {
259
- issue(["setupGuides", i, "files", j, "path"], `duplicate file ${f.path} in the guide`);
278
+ else {
279
+ g.templates.forEach((t, j) => {
280
+ if (m.connectorTemplates !== undefined && !ids.has(t)) {
281
+ issue(["setupGuides", i, "templates", j], `template ${t} is not one of the plugin's connector templates`);
282
+ }
283
+ if (guideTemplates.has(t)) {
284
+ issue(["setupGuides", i, "templates", j], `at most one setup guide per connector template (${t} is named twice)`);
285
+ }
286
+ guideTemplates.add(t);
287
+ });
260
288
  }
261
- paths.add(f.path);
262
- });
289
+ }
290
+ else if (g.templates !== undefined) {
291
+ issue(["setupGuides", i, "templates"], "templates is only for connector-template guides");
292
+ }
293
+ if (g.place === "channel-connection") {
294
+ channelGuides++;
295
+ if (channelGuides === 2) {
296
+ issue(["setupGuides", i, "place"], "a plugin has at most one channel-connection guide");
297
+ }
298
+ }
263
299
  if (g.place === "channel-connection" &&
264
300
  m.extension !== undefined &&
265
301
  !m.extension.manifest.provides.some((p) => p.startsWith("channel@"))) {
266
302
  issue(["setupGuides", i, "place"], "a channel-connection guide needs the plugin's extension to provide channel@1");
267
303
  }
268
304
  });
305
+ const sa = m.suggestedAppearance;
306
+ if (sa !== undefined) {
307
+ const at = ["suggestedAppearance"];
308
+ if (sa.theme === undefined && sa.replacements === undefined) {
309
+ issue(at, "suggestedAppearance needs theme or replacements");
310
+ }
311
+ if (sa.theme !== undefined && m.themes !== undefined && !themeIds.has(sa.theme)) {
312
+ issue([...at, "theme"], `suggestedAppearance.theme names ${sa.theme}, which is not a theme of the plugin`);
313
+ }
314
+ if (sa.replacements !== undefined) {
315
+ const entries = Object.entries(sa.replacements);
316
+ if (m.extension === undefined) {
317
+ issue([...at, "replacements"], "suggestedAppearance.replacements needs an extension");
318
+ }
319
+ if (entries.length > L.appearanceReplacements) {
320
+ issue([...at, "replacements"], `suggestedAppearance.replacements has ${entries.length} entries; the limit is ${L.appearanceReplacements}`);
321
+ }
322
+ const seen = new Set();
323
+ for (const [slot, id] of entries) {
324
+ const ref = parseSlotRef(slot);
325
+ if (ref === null) {
326
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} is not a slot ref`);
327
+ continue;
328
+ }
329
+ if (seen.has(ref.id)) {
330
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} names the slot ${ref.id} again; give each slot once`);
331
+ continue;
332
+ }
333
+ seen.add(ref.id);
334
+ if (!COMPONENT_ID_RE.test(id)) {
335
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} names ${id}, which is not a contribution id`);
336
+ continue;
337
+ }
338
+ const known = uiSlot(ref.id);
339
+ if (known === undefined)
340
+ continue;
341
+ if (known.cardinality !== "single") {
342
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} is not a replaceable slot`);
343
+ continue;
344
+ }
345
+ const ok = (m.extension?.manifest.ui ?? []).some((u) => {
346
+ const us = typeof u.slot === "string" ? parseSlotRef(u.slot) : null;
347
+ return u.id === id && u.kind === "component" && us?.id === ref.id;
348
+ });
349
+ if (!ok) {
350
+ issue([...at, "replacements"], `suggestedAppearance.replacements: ${slot} names ${id}, which is not a component contribution in that slot`);
351
+ }
352
+ }
353
+ }
354
+ }
269
355
  if (m.extension === undefined &&
270
356
  m.skills?.length === 0 &&
271
357
  m.connectorTemplates?.length === 0 &&
272
- (m.agents === undefined || m.agents.length === 0)) {
273
- issue([], "a plugin must contain an extension, a skill, a connector template or an agent template");
358
+ (m.agents === undefined || m.agents.length === 0) &&
359
+ (m.themes === undefined || m.themes.length === 0)) {
360
+ issue([], "a plugin must contain an extension, a skill, a connector template, an agent template or a theme");
274
361
  }
275
362
  const ext = m.extension;
276
363
  if (ext === undefined)
277
364
  return;
278
365
  const em = ext.manifest;
366
+ const hasClientPermission = em.permissions.client === true;
367
+ if (ext.client !== undefined && !hasClientPermission) {
368
+ issue(["extension", "client"], "extension.client needs permissions.client: true");
369
+ }
370
+ if (ext.client === undefined && hasClientPermission) {
371
+ 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)");
372
+ }
279
373
  if (!EXTENSION_NAME_RE.test(m.name)) {
280
374
  issue(["name"], `a plugin with an extension needs an extension name (${EXTENSION_NAME_RE})`);
281
375
  }
@@ -288,14 +382,12 @@ const schema = z
288
382
  if (semver.validRange(em.sdk) !== null && !hasUpperBound(em.sdk)) {
289
383
  issue(["extension", "manifest", "sdk"], `"${em.sdk}" has no upper bound: use a range such as ^0.1.0 so a future major SDK is not assumed compatible`);
290
384
  }
291
- for (const k of ["deployment", "org"]) {
292
- const seen = new Set();
293
- for (const f of em.config[k]) {
294
- if (seen.has(f.path)) {
295
- issue(["extension", "manifest", "config", k], `duplicate config path "${f.path}"`);
296
- }
297
- seen.add(f.path);
385
+ const seen = new Set();
386
+ for (const f of em.config.deployment) {
387
+ if (seen.has(f.path)) {
388
+ issue(["extension", "manifest", "config", "deployment"], `duplicate config path "${f.path}"`);
298
389
  }
390
+ seen.add(f.path);
299
391
  }
300
392
  // Name, version, sdk range, extension point refs, permissions, UI contributions: the same
301
393
  // rules as defineExtension (with a placeholder setup).
@@ -328,12 +420,21 @@ const template = z.strictObject({
328
420
  auth: z.record(z.string(), z.unknown()),
329
421
  ownership: z.enum(["org", "personal"]).optional(),
330
422
  defaultToolPolicies: z.record(z.string(), z.enum(["allow", "ask", "deny"])).optional(),
423
+ git: GitSourceSchema.optional(),
331
424
  icon: z.string().max(L.pathChars).optional(),
332
425
  });
333
426
  const templateFile = z
334
427
  .strictObject({
335
428
  displayName: localized,
336
- description: text(CONNECTOR_TEMPLATE_LIMITS.descriptionChars, "description").optional(),
429
+ description: z
430
+ .union([
431
+ text(CONNECTOR_TEMPLATE_LIMITS.descriptionChars, "description"),
432
+ z.strictObject({
433
+ zh: text(CONNECTOR_TEMPLATE_LIMITS.descriptionChars, "description.zh"),
434
+ en: text(CONNECTOR_TEMPLATE_LIMITS.descriptionChars, "description.en"),
435
+ }),
436
+ ])
437
+ .optional(),
337
438
  icon: z
338
439
  .string()
339
440
  .max(L.pathChars)
@@ -400,3 +501,13 @@ export function parsePluginManifest(json) {
400
501
  export function parseConnectorTemplateFile(json) {
401
502
  return parseWith(ConnectorTemplateFileSchema, json, "connector template file");
402
503
  }
504
+ /**
505
+ * The theme check of `suggestedAppearance` after the themes are known (the manifest may omit
506
+ * `themes` and let the scan find them): shared by the packer and the kernel.
507
+ */
508
+ export function appearanceIssues(manifest, themeIds) {
509
+ const theme = manifest.suggestedAppearance?.theme;
510
+ if (theme === undefined || themeIds.includes(theme))
511
+ return [];
512
+ return [`suggestedAppearance.theme names ${theme}, which is not a theme of the plugin`];
513
+ }
@@ -1,4 +1,5 @@
1
1
  import { type ExtensionManifest } from "./define-extension.js";
2
+ import { type GitSource } from "./git-hosts.js";
2
3
  import type { ExtensionPermissions } from "./permissions.js";
3
4
  import type { PluginManifest } from "./plugin-manifest.js";
4
5
  /**
@@ -10,17 +11,29 @@ import type { PluginManifest } from "./plugin-manifest.js";
10
11
  * entry is single-file ESM with third-party dependencies bundled; only {@link HOST_PROVIDED_PACKAGES}
11
12
  * come from the host.
12
13
  */
13
- /** 宿主提供的包(peerDependencies,安装时链接到宿主副本);其余三方依赖必须打进 entry。 */
14
+ /**
15
+ * Packages provided by the host (peerDependencies, linked to the host's copy on install); every
16
+ * other third-party dependency must be bundled into the entry.
17
+ */
14
18
  export declare const HOST_PROVIDED_PACKAGES: readonly ["@capybara-hq/plugin-sdk", "zod"];
15
- /** npm 安装时会自动执行的脚本:插件包一律不许有(安装不跑脚本,有也是误导)。 */
19
+ /**
20
+ * Scripts npm runs automatically on install: a plugin package must never have any (installs run no
21
+ * scripts, so having them would mislead).
22
+ */
16
23
  export declare const FORBIDDEN_INSTALL_SCRIPTS: readonly ["preinstall", "install", "postinstall", "prepare"];
17
- /** 静态清单里的一个配置字段(点路径,根即叶子时为空串)。 */
24
+ /**
25
+ * A config field in the static manifest (a dotted path; an empty string when the root is itself the
26
+ * leaf).
27
+ */
18
28
  export interface StaticConfigField {
19
29
  path: string;
20
30
  secret: boolean;
21
31
  hot: boolean;
22
32
  }
23
- /** 插件清单的静态部分(可 JSON 序列化;不含 setup、zod schema、migrations 路径)。 */
33
+ /**
34
+ * The static part of the plugin manifest (JSON-serializable; excludes setup, zod schemas and
35
+ * migration paths).
36
+ */
24
37
  export interface StaticExtensionManifest {
25
38
  name: string;
26
39
  version: string;
@@ -32,30 +45,40 @@ export interface StaticExtensionManifest {
32
45
  ui?: ExtensionManifest["ui"];
33
46
  config: {
34
47
  deployment: StaticConfigField[];
35
- org: StaticConfigField[];
36
48
  };
37
49
  }
38
- /** 入口模块里的一个 import:`name` 是 specifier(非字面量的动态 import 时为空串)。 */
50
+ /**
51
+ * An import in the entry module: `name` is the specifier (an empty string for a dynamic import that
52
+ * is not a literal).
53
+ */
39
54
  export interface EntryImport {
40
55
  name: string;
41
56
  dynamic: boolean;
42
57
  literal: boolean;
43
58
  }
44
- /** npm 包名规则(简化):可带 scope,小写,≤ 214 字符(长度另行检查)。 */
59
+ /**
60
+ * npm package name rule (simplified): may carry a scope, lowercase, ≤ 214 characters (the length is
61
+ * checked separately).
62
+ */
45
63
  export declare const NPM_PACKAGE_NAME_RE: RegExp;
46
64
  /**
47
- * 包内相对路径是否安全:非空、不以 `/` 开头、不含 `\`、控制字符与盘符,没有空段、`.` 与 `..` 段,≤ 1024 字符。
65
+ * Whether a path relative to the package is safe: non-empty, not starting with `/`, no `\`, control
66
+ * characters or drive letters, no empty segments, `.` or `..` segments, ≤ 1024 characters.
48
67
  */
49
68
  export declare function isSafePackagePath(p: string): boolean;
50
69
  /**
51
- * 核对入口模块的 import(C11):静态与字面量动态 import 只许 `node:*`、{@link HOST_PROVIDED_PACKAGES}(含子路径)
52
- * 与包内相对路径(`./`、`../`;是否越出包外由调用方按文件位置判断);非字面量的动态 import 一律拒绝。
53
- * 返回问题列表(空表示合法)。
70
+ * Checks the entry module's imports (C11): static and literal dynamic imports may only be `node:*`,
71
+ * {@link HOST_PROVIDED_PACKAGES} (subpaths included)
72
+ * and in-package relative paths (`./`, `../`; whether they escape the package is judged by the
73
+ * caller from the file location); non-literal dynamic imports are always rejected.
74
+ * Returns the list of problems (empty means valid).
54
75
  */
55
76
  export declare function checkEntryImports(specifiers: EntryImport[]): string[];
56
77
  /**
57
- * 真实清单的静态部分:打包时写进 `capybara.manifest`,加载时与包内的比对(`manifest_mismatch`)。
58
- * 结果可 JSON 往返(undefined 字段去掉);配置字段按路径排序。
78
+ * The static part of the real manifest: written into `capybara.manifest` when packing, and compared
79
+ * with the in-package one at load time (`manifest_mismatch`).
80
+ * The result survives a JSON round trip (undefined fields removed); config fields are sorted by
81
+ * path.
59
82
  */
60
83
  export declare function staticManifestOf(m: ExtensionManifest): StaticExtensionManifest;
61
84
  /**
@@ -78,62 +101,82 @@ export declare function validatePluginPackageJsonFor(pkg: unknown, manifest: Plu
78
101
  */
79
102
  export declare function hostSdkProblem(sdk: string, hostSdkVersion: string): string | undefined;
80
103
  /**
81
- * 连接器模板(C30):连接器插件引用 + `Connector.kind` + 端点预设 + 组织可改的端点路径 + 认证预设(不含凭据)+
82
- * 默认 ownership + 各工具默认策略 + 图标。组织安装时只能填凭据、客户端 id / secret 与 `editableEndpoint` 里的字段。
104
+ * Connector template (C30): connector plugin reference + `Connector.kind` + endpoint preset +
105
+ * endpoint paths an org may change + auth preset (no credentials) +
106
+ * default ownership + default policy per tool + icon. When installing, an org may only fill in
107
+ * credentials, the client id / secret and the fields in `editableEndpoint`.
83
108
  */
84
109
  export interface ConnectorTemplateSpec {
85
- /** 连接器插件名(如 `connector-mcp`)。 */
110
+ /** Connector plugin name (e.g. `connector-mcp`). */
86
111
  plugin: string;
87
- /** 连接器插件的 semver 范围,可选。 */
112
+ /** Semver range of the connector plugin, optional. */
88
113
  pluginVersion?: string;
89
- /** `Connector.kind`(如 `"mcp"`)。 */
114
+ /** `Connector.kind` (e.g. `"mcp"`). */
90
115
  connector: string;
91
- /** 端点预设;导入时内核按该连接器的 `endpointSchema` 校验。 */
116
+ /**
117
+ * Endpoint preset; on import the kernel validates it against that connector's `endpointSchema`.
118
+ */
92
119
  endpoint: Record<string, unknown>;
93
- /** 组织安装时允许改的点路径(如 `"url"`);其余以模板为准。路径必须存在于连接器的端点 schema 中。 */
120
+ /**
121
+ * Dotted paths an org may change when installing (e.g. `"url"`); everything else follows the
122
+ * template. The paths must exist in the connector's endpoint schema.
123
+ */
94
124
  editableEndpoint?: string[];
95
- /** 与连接器安装接口的认证方式同形({@link ConnectorAuthSchema}),不含任何凭据。 */
125
+ /**
126
+ * The same shape as the auth method of the connector install API ({@link ConnectorAuthSchema}),
127
+ * carrying no credentials.
128
+ */
96
129
  auth: Record<string, unknown>;
97
- /** 缺省取 `auth.ownership`;给了就必须与之一致。 */
130
+ /** Defaults to `auth.ownership`; if given it must agree. */
98
131
  ownership?: "org" | "personal";
99
- /** 工具名 → 默认策略(安装后记 `policy_source 'template'`)。 */
132
+ /** Tool name -> default policy (recorded as `policy_source 'template'` after install). */
100
133
  defaultToolPolicies?: Record<string, "allow" | "ask" | "deny">;
101
- /** 包内路径,svg / png,≤ {@link CONNECTOR_TEMPLATE_LIMITS}`.iconBytes`。 */
134
+ /** Git hosts this connector's credential serves in sandboxes ({@link GitSource}). */
135
+ git?: GitSource;
136
+ /** In-package path, svg / png, ≤ {@link CONNECTOR_TEMPLATE_LIMITS}`.iconBytes`. */
102
137
  icon?: string;
103
138
  }
104
- /** 双语显示名。 */
139
+ /** Bilingual display name. */
105
140
  export interface LocalizedName {
106
141
  zh: string;
107
142
  en: string;
108
143
  }
109
- /** 连接器模板与目录段的上限。 */
144
+ /** Limits of connector templates and catalog segments. */
110
145
  export declare const CONNECTOR_TEMPLATE_LIMITS: {
111
- /** 图标字节数上限。 */
146
+ /** Upper bound on icon bytes. */
112
147
  readonly iconBytes: number;
113
- /** 端点预设 JSON 序列化后的字符数上限。 */
148
+ /** Upper bound on the characters of the endpoint preset after JSON serialization. */
114
149
  readonly endpointChars: number;
115
- /** `editableEndpoint` 条数上限。 */
150
+ /** Upper bound on the number of `editableEndpoint` entries. */
116
151
  readonly editablePaths: 50;
117
- /** `defaultToolPolicies` 条数上限。 */
152
+ /** Upper bound on the number of `defaultToolPolicies` entries. */
118
153
  readonly toolPolicies: 1000;
119
- /** publisher 字符数上限。 */
154
+ /** Upper bound on the characters of publisher. */
120
155
  readonly publisherChars: 100;
121
- /** description 字符数上限。 */
156
+ /** Upper bound on the characters of description (per language when it is `{ zh, en }`). */
122
157
  readonly descriptionChars: 1024;
123
- /** displayName 每种语言的字符数上限。 */
158
+ /** Upper bound on the characters of displayName per language. */
124
159
  readonly displayNameChars: 100;
125
160
  };
126
- /** 目录条目名(与清单条目名同一规则):小写字母或数字开头,之后小写字母、数字、连字符,≤ 64。 */
161
+ /**
162
+ * Catalog entry name (the same rule as manifest entry names): starts with a lowercase letter or
163
+ * digit, then lowercase letters, digits and hyphens, ≤ 64.
164
+ */
127
165
  export declare const CATALOG_ITEM_NAME_RE: RegExp;
128
166
  /** An exact semver version (a regex JSON Schema can use). */
129
167
  export declare const SEMVER_VERSION_RE: RegExp;
130
168
  /** The sha512 SRI of an npm package tgz: `sha512-<86 base64 chars>==`. */
131
169
  export declare const SHA512_INTEGRITY_RE: RegExp;
132
170
  /**
133
- * 校验连接器模板({@link ConnectorTemplateSpec})的静态部分,返回问题列表(空表示合法;路径相对模板根,不回显值):
134
- * 字段齐全、无未知字段;`auth` 符合 {@link ConnectorAuthSchema}(strict:夹带 `token` 等多余字段即拒绝);
135
- * 端点预设里任何层级都不许有凭据样式的键;`editableEndpoint` 是不重复的点路径;`ownership` 与 `auth.ownership`
136
- * 一致;默认策略只许 allow / ask / deny;icon 是包内 .svg / .png 路径。
137
- * 端点是否符合连接器的 `endpointSchema`、`editableEndpoint` 是否存在于其中,由内核在导入时按已加载的连接器校验。
171
+ * Validates the static part of a connector template ({@link ConnectorTemplateSpec}) and returns the
172
+ * list of problems (empty means valid; paths are relative to the template root, values are not
173
+ * echoed):
174
+ * fields complete, no unknown fields; `auth` conforms to {@link ConnectorAuthSchema} (strict: extra
175
+ * fields such as `token` are rejected);
176
+ * no credential-style key at any level of the endpoint preset; `editableEndpoint` is a list of
177
+ * distinct dotted paths; `ownership` agrees with `auth.ownership`;
178
+ * default policies may only be allow / ask / deny; icon is an in-package .svg / .png path.
179
+ * Whether the endpoint conforms to the connector's `endpointSchema` and whether `editableEndpoint`
180
+ * exists in it is checked by the kernel on import against the loaded connector.
138
181
  */
139
182
  export declare function validateConnectorTemplate(t: unknown): string[];