@capybara-hq/plugin-sdk 0.1.0-rc.47 → 0.1.0-rc.48

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.
@@ -79,3 +79,74 @@ export declare function parseBootstrapManifest(json: unknown): BootstrapManifest
79
79
  };
80
80
  /** The file name of an entry's tgz in the bootstrap directory: `<name>-<version>.tgz`. */
81
81
  export declare function bootstrapFileName(e: BootstrapEntry): string;
82
+ /** Extra manifest format version. */
83
+ export declare const BOOTSTRAP_EXTRA_MANIFEST_SCHEMA_VERSION = 1;
84
+ /** A `git` entry: a plugin directory of a declared marketplace at a pinned commit. */
85
+ export interface BootstrapGitEntry {
86
+ /** Catalog item name. */
87
+ name: string;
88
+ source: "git";
89
+ /** A name from the manifest's `marketplaces`. */
90
+ marketplace: string;
91
+ /** 40-hex commit the tree is read at (never a branch). */
92
+ commit: string;
93
+ /** The plugin directory inside the repository: `./<path>`, or `.` / `./` for its root. */
94
+ path: string;
95
+ /** Exact semver. */
96
+ version: string;
97
+ /** `sha512-<base64>` of the kernel's canonical pack of the tree. */
98
+ integrity: string;
99
+ required?: boolean;
100
+ builtin?: boolean;
101
+ }
102
+ /** An entry of the extra manifest: npm (`required` optional) or git. */
103
+ export type BootstrapExtraEntry = (Omit<Extract<BootstrapEntry, {
104
+ source: "npm";
105
+ }>, "required"> & {
106
+ required?: boolean;
107
+ }) | BootstrapGitEntry;
108
+ /** A marketplace the extra manifest declares for its `git` entries. */
109
+ export interface BootstrapExtraMarketplace {
110
+ /** `^[a-z0-9][a-z0-9-]{0,63}$`, unique, not `official`. */
111
+ name: string;
112
+ /** An https URL without userinfo. */
113
+ url: string;
114
+ ref?: string;
115
+ /** HTTP basic username of the credential (`^[A-Za-z0-9._-]{1,64}$`). */
116
+ username?: string;
117
+ }
118
+ /**
119
+ * The extra bootstrap manifest (`bootstrap-extra.v1`): a second manifest a distribution supplies (the file
120
+ * `bootstrap.extraManifest` points at), merged into the built-in one (spec 2026-11-20-bootstrap-extra-manifest §2). It adds
121
+ * `marketplaces` the entries can name, `git` entries (a plugin directory of such a marketplace at
122
+ * a pinned commit) and an optional `defaultTheme`. `required` is optional here (default `false`).
123
+ * Objects are strict. The committed JSON Schema (`schemas/bootstrap-extra.v1.schema.json`) is
124
+ * generated from {@link BootstrapExtraManifestSchema}; the cross-field rules (unique names, a
125
+ * declared marketplace, `defaultTheme` naming a builtin entry, not both `required` and `builtin`)
126
+ * are decided only by {@link parseBootstrapExtraManifest}.
127
+ */
128
+ export interface BootstrapExtraManifest {
129
+ $schema?: string;
130
+ schemaVersion: 1;
131
+ marketplaces: BootstrapExtraMarketplace[];
132
+ plugins: BootstrapExtraEntry[];
133
+ /** The platform default theme: `plugin` is a builtin entry of this manifest. */
134
+ defaultTheme?: {
135
+ plugin: string;
136
+ theme: string;
137
+ };
138
+ }
139
+ /**
140
+ * The zod schema of the extra manifest (strict objects). The JSON Schema is generated with
141
+ * `z.toJSONSchema(BootstrapExtraManifestSchema, { io: "input" })`.
142
+ */
143
+ export declare const BootstrapExtraManifestSchema: z.ZodType<BootstrapExtraManifest>;
144
+ /**
145
+ * Validates and parses the extra manifest. Invalid input returns `{ errors }` (`<path>: <reason>`,
146
+ * at most 50); never throws.
147
+ */
148
+ export declare function parseBootstrapExtraManifest(json: unknown): {
149
+ manifest: BootstrapExtraManifest;
150
+ } | {
151
+ errors: string[];
152
+ };
package/dist/bootstrap.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
- import { CATALOG_ITEM_NAME_RE, NPM_PACKAGE_NAME_RE, SEMVER_VERSION_RE, SHA512_INTEGRITY_RE, } from "./plugin-package.js";
2
+ import { GIT_USERNAME_RE } from "./git-hosts.js";
3
+ import { CATALOG_ITEM_NAME_RE, isSafePackagePath, NPM_PACKAGE_NAME_RE, SEMVER_VERSION_RE, SHA512_INTEGRITY_RE, } from "./plugin-package.js";
3
4
  /**
4
5
  * The bootstrap manifest `packages/kernel/bootstrap.json` (package ecosystem spec §7): the plugins
5
6
  * a deployment installs at init, each pinned to an exact version and the sha512 of its tgz. The
@@ -123,3 +124,145 @@ export function parseBootstrapManifest(json) {
123
124
  export function bootstrapFileName(e) {
124
125
  return `${e.name}-${e.version}.tgz`;
125
126
  }
127
+ /** Extra manifest format version. */
128
+ export const BOOTSTRAP_EXTRA_MANIFEST_SCHEMA_VERSION = 1;
129
+ const RESERVED_MARKETPLACE_NAME = "official";
130
+ const extraCommon = {
131
+ name: common.name,
132
+ version: common.version,
133
+ integrity: common.integrity,
134
+ required: z.boolean().optional(),
135
+ builtin: common.builtin,
136
+ };
137
+ const extraEntry = z.discriminatedUnion("source", [
138
+ z.strictObject({
139
+ ...extraCommon,
140
+ source: z.literal("npm"),
141
+ npm: z
142
+ .string()
143
+ .max(214)
144
+ .regex(NPM_PACKAGE_NAME_RE, { message: "npm must be an npm package name" }),
145
+ }),
146
+ z.strictObject({
147
+ ...extraCommon,
148
+ source: z.literal("git"),
149
+ marketplace: common.name,
150
+ commit: z.string().regex(COMMIT_RE, { message: "commit must be 40 hex characters" }),
151
+ path: z
152
+ .string()
153
+ .max(512)
154
+ // "." / "./": the repository root (a single-plugin repository)
155
+ .refine((p) => p === "." || p === "./" || (p.startsWith("./") && isSafePackagePath(p.slice(2))), {
156
+ message: 'path must be "." (the repository root) or start with "./" and stay inside the repository',
157
+ }),
158
+ }),
159
+ ]);
160
+ const extraMarketplace = z.strictObject({
161
+ name: common.name,
162
+ url: z
163
+ .string()
164
+ .max(URL_CHARS)
165
+ .regex(HTTPS_URL_RE, { message: "url must be an https URL" })
166
+ .refine((s) => {
167
+ try {
168
+ const u = new URL(s);
169
+ return u.username === "" && u.password === "";
170
+ }
171
+ catch {
172
+ return false;
173
+ }
174
+ }, { message: "url must be a valid URL without userinfo" }),
175
+ ref: z.string().min(1).max(256).optional(),
176
+ username: z
177
+ .string()
178
+ .regex(GIT_USERNAME_RE, { message: "username must match ^[A-Za-z0-9._-]{1,64}$" })
179
+ .optional(),
180
+ });
181
+ const extraSchema = z
182
+ .strictObject({
183
+ $schema: z.string().max(URL_CHARS).optional(),
184
+ schemaVersion: z.literal(BOOTSTRAP_EXTRA_MANIFEST_SCHEMA_VERSION),
185
+ marketplaces: z.array(extraMarketplace).max(50),
186
+ plugins: z.array(extraEntry).max(500),
187
+ defaultTheme: z
188
+ .strictObject({
189
+ plugin: common.name,
190
+ theme: z.string().min(1).max(256),
191
+ })
192
+ .optional(),
193
+ })
194
+ .superRefine((m, ctx) => {
195
+ const marketplaces = new Set();
196
+ m.marketplaces.forEach((mk, i) => {
197
+ if (mk.name === RESERVED_MARKETPLACE_NAME) {
198
+ ctx.addIssue({
199
+ code: "custom",
200
+ path: ["marketplaces", i, "name"],
201
+ message: `the name ${RESERVED_MARKETPLACE_NAME} is reserved`,
202
+ });
203
+ }
204
+ if (marketplaces.has(mk.name)) {
205
+ ctx.addIssue({
206
+ code: "custom",
207
+ path: ["marketplaces", i, "name"],
208
+ message: `duplicate marketplace ${mk.name}`,
209
+ });
210
+ }
211
+ marketplaces.add(mk.name);
212
+ });
213
+ const seen = new Set();
214
+ m.plugins.forEach((e, i) => {
215
+ if (seen.has(e.name)) {
216
+ ctx.addIssue({
217
+ code: "custom",
218
+ path: ["plugins", i, "name"],
219
+ message: `duplicate entry ${e.name}`,
220
+ });
221
+ }
222
+ seen.add(e.name);
223
+ if (e.required === true && e.builtin === true) {
224
+ ctx.addIssue({
225
+ code: "custom",
226
+ path: ["plugins", i, "builtin"],
227
+ message: "an entry is either required or builtin, not both",
228
+ });
229
+ }
230
+ if (e.source === "git" && !marketplaces.has(e.marketplace)) {
231
+ ctx.addIssue({
232
+ code: "custom",
233
+ path: ["plugins", i, "marketplace"],
234
+ message: `marketplace "${e.marketplace}" is not declared`,
235
+ });
236
+ }
237
+ });
238
+ if (m.defaultTheme !== undefined) {
239
+ const target = m.plugins.find((e) => e.name === m.defaultTheme?.plugin);
240
+ if (target === undefined || target.builtin !== true) {
241
+ ctx.addIssue({
242
+ code: "custom",
243
+ path: ["defaultTheme", "plugin"],
244
+ message: "must name an entry of this manifest with builtin: true",
245
+ });
246
+ }
247
+ }
248
+ });
249
+ /**
250
+ * The zod schema of the extra manifest (strict objects). The JSON Schema is generated with
251
+ * `z.toJSONSchema(BootstrapExtraManifestSchema, { io: "input" })`.
252
+ */
253
+ export const BootstrapExtraManifestSchema = extraSchema;
254
+ /**
255
+ * Validates and parses the extra manifest. Invalid input returns `{ errors }` (`<path>: <reason>`,
256
+ * at most 50); never throws.
257
+ */
258
+ export function parseBootstrapExtraManifest(json) {
259
+ const r = BootstrapExtraManifestSchema.safeParse(json);
260
+ if (r.success)
261
+ return { manifest: r.data };
262
+ return {
263
+ errors: r.error.issues.slice(0, MAX_ERRORS).map((i) => {
264
+ const path = i.path.map(String).join(".");
265
+ return path ? `${path}: ${i.message}` : i.message;
266
+ }),
267
+ };
268
+ }
@@ -20,6 +20,15 @@ export declare const GIT_HOST_USERNAMES: {
20
20
  readonly "github.com": "x-access-token";
21
21
  readonly "*.ghe.com": "x-access-token";
22
22
  };
23
+ /** A valid HTTP basic username: `^[A-Za-z0-9._-]{1,64}$`. */
24
+ export declare const GIT_USERNAME_RE: RegExp;
25
+ /** The username a git marketplace credential is presented with when none is stored. */
26
+ export declare const GIT_MARKETPLACE_USERNAME_DEFAULT = "x-access-token";
27
+ /**
28
+ * A hint for forms: the basic username well-known git hosts document for a token. Other hosts
29
+ * return `undefined`; the user enters the username the host's documentation names.
30
+ */
31
+ export declare function suggestGitUsername(host: string): string | undefined;
23
32
  /** One git host and the username its credential is presented with. */
24
33
  export interface GitHostEntry {
25
34
  /** Lower-case hostname with no scheme, port, path, wildcard or userinfo. */
package/dist/git-hosts.js CHANGED
@@ -21,7 +21,24 @@ export const GIT_HOST_USERNAMES = {
21
21
  "github.com": "x-access-token",
22
22
  "*.ghe.com": "x-access-token",
23
23
  };
24
- const USERNAME_RE = /^[A-Za-z0-9._-]{1,64}$/;
24
+ /** A valid HTTP basic username: `^[A-Za-z0-9._-]{1,64}$`. */
25
+ export const GIT_USERNAME_RE = /^[A-Za-z0-9._-]{1,64}$/;
26
+ /** The username a git marketplace credential is presented with when none is stored. */
27
+ export const GIT_MARKETPLACE_USERNAME_DEFAULT = "x-access-token";
28
+ /**
29
+ * A hint for forms: the basic username well-known git hosts document for a token. Other hosts
30
+ * return `undefined`; the user enters the username the host's documentation names.
31
+ */
32
+ export function suggestGitUsername(host) {
33
+ const h = host.toLowerCase();
34
+ if (h === "github.com" || h.endsWith(".ghe.com"))
35
+ return GIT_MARKETPLACE_USERNAME_DEFAULT;
36
+ if (h === "bitbucket.org")
37
+ return "x-token-auth";
38
+ if (h === "gitlab.com")
39
+ return "oauth2";
40
+ return undefined;
41
+ }
25
42
  /** Why a host is refused; never echoes the value (it may be a pasted credential or URL). */
26
43
  function hostProblems(h) {
27
44
  if (/[@:/?#\s]/.test(h))
@@ -42,7 +59,7 @@ const GitHostEntrySchema = z.strictObject({
42
59
  }),
43
60
  username: z
44
61
  .string()
45
- .regex(USERNAME_RE, "username must match ^[A-Za-z0-9._-]{1,64}$ (letters, digits, '.', '_', '-')"),
62
+ .regex(GIT_USERNAME_RE, "username must match ^[A-Za-z0-9._-]{1,64}$ (letters, digits, '.', '_', '-')"),
46
63
  });
47
64
  /**
48
65
  * The zod schema of {@link GitSource} (strict objects, 1 to {@link GIT_HOSTS_LIMITS}`.hosts` hosts,
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.47";
1
+ export declare const SDK_VERSION = "0.1.0-rc.48";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./bootstrap.js";
4
4
  export * from "./cards.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = "0.1.0-rc.47";
1
+ export const SDK_VERSION = "0.1.0-rc.48";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./bootstrap.js";
4
4
  export * from "./cards.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-sdk",
3
- "version": "0.1.0-rc.47",
3
+ "version": "0.1.0-rc.48",
4
4
  "description": "Capybara plugin SDK: the types and pure functions plugins are written against",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -0,0 +1,172 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://capybarahq.com/schemas/bootstrap-extra.v1.schema.json",
4
+ "title": "Capybara extra bootstrap manifest bootstrap.extra.json (schemaVersion 1)",
5
+ "type": "object",
6
+ "properties": {
7
+ "$schema": {
8
+ "type": "string",
9
+ "maxLength": 2000
10
+ },
11
+ "schemaVersion": {
12
+ "type": "number",
13
+ "const": 1
14
+ },
15
+ "marketplaces": {
16
+ "maxItems": 50,
17
+ "type": "array",
18
+ "items": {
19
+ "type": "object",
20
+ "properties": {
21
+ "name": {
22
+ "type": "string",
23
+ "pattern": "^[a-z0-9][a-z0-9-]{0,63}$"
24
+ },
25
+ "url": {
26
+ "type": "string",
27
+ "maxLength": 2000,
28
+ "pattern": "^https:\\/\\/\\S+$"
29
+ },
30
+ "ref": {
31
+ "type": "string",
32
+ "minLength": 1,
33
+ "maxLength": 256
34
+ },
35
+ "username": {
36
+ "type": "string",
37
+ "pattern": "^[A-Za-z0-9._-]{1,64}$"
38
+ }
39
+ },
40
+ "required": [
41
+ "name",
42
+ "url"
43
+ ],
44
+ "additionalProperties": false
45
+ }
46
+ },
47
+ "plugins": {
48
+ "maxItems": 500,
49
+ "type": "array",
50
+ "items": {
51
+ "oneOf": [
52
+ {
53
+ "type": "object",
54
+ "properties": {
55
+ "name": {
56
+ "type": "string",
57
+ "pattern": "^[a-z0-9][a-z0-9-]{0,63}$"
58
+ },
59
+ "version": {
60
+ "type": "string",
61
+ "maxLength": 256,
62
+ "pattern": "^(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)(?:-(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\\+[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*)?$"
63
+ },
64
+ "integrity": {
65
+ "type": "string",
66
+ "pattern": "^sha512-[A-Za-z0-9+/]{86}==$"
67
+ },
68
+ "required": {
69
+ "type": "boolean"
70
+ },
71
+ "builtin": {
72
+ "type": "boolean"
73
+ },
74
+ "source": {
75
+ "type": "string",
76
+ "const": "npm"
77
+ },
78
+ "npm": {
79
+ "type": "string",
80
+ "maxLength": 214,
81
+ "pattern": "^(?:@[a-z0-9][a-z0-9._~-]*\\/)?[a-z0-9][a-z0-9._~-]*$"
82
+ }
83
+ },
84
+ "required": [
85
+ "name",
86
+ "version",
87
+ "integrity",
88
+ "source",
89
+ "npm"
90
+ ],
91
+ "additionalProperties": false
92
+ },
93
+ {
94
+ "type": "object",
95
+ "properties": {
96
+ "name": {
97
+ "type": "string",
98
+ "pattern": "^[a-z0-9][a-z0-9-]{0,63}$"
99
+ },
100
+ "version": {
101
+ "type": "string",
102
+ "maxLength": 256,
103
+ "pattern": "^(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)(?:-(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\\+[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*)?$"
104
+ },
105
+ "integrity": {
106
+ "type": "string",
107
+ "pattern": "^sha512-[A-Za-z0-9+/]{86}==$"
108
+ },
109
+ "required": {
110
+ "type": "boolean"
111
+ },
112
+ "builtin": {
113
+ "type": "boolean"
114
+ },
115
+ "source": {
116
+ "type": "string",
117
+ "const": "git"
118
+ },
119
+ "marketplace": {
120
+ "type": "string",
121
+ "pattern": "^[a-z0-9][a-z0-9-]{0,63}$"
122
+ },
123
+ "commit": {
124
+ "type": "string",
125
+ "pattern": "^[0-9a-f]{40}$"
126
+ },
127
+ "path": {
128
+ "type": "string",
129
+ "maxLength": 512
130
+ }
131
+ },
132
+ "required": [
133
+ "name",
134
+ "version",
135
+ "integrity",
136
+ "source",
137
+ "marketplace",
138
+ "commit",
139
+ "path"
140
+ ],
141
+ "additionalProperties": false
142
+ }
143
+ ]
144
+ }
145
+ },
146
+ "defaultTheme": {
147
+ "type": "object",
148
+ "properties": {
149
+ "plugin": {
150
+ "type": "string",
151
+ "pattern": "^[a-z0-9][a-z0-9-]{0,63}$"
152
+ },
153
+ "theme": {
154
+ "type": "string",
155
+ "minLength": 1,
156
+ "maxLength": 256
157
+ }
158
+ },
159
+ "required": [
160
+ "plugin",
161
+ "theme"
162
+ ],
163
+ "additionalProperties": false
164
+ }
165
+ },
166
+ "required": [
167
+ "schemaVersion",
168
+ "marketplaces",
169
+ "plugins"
170
+ ],
171
+ "additionalProperties": false
172
+ }