@rollrook-ai/plugin-cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/rollrook-plugin.js +2 -0
- package/dist/cli.d.ts +25 -0
- package/dist/cli.js +194 -0
- package/dist/cli.js.map +1 -0
- package/dist/errors.d.ts +10 -0
- package/dist/errors.js +12 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +3 -0
- package/dist/main.js.map +1 -0
- package/dist/manifest.d.ts +200 -0
- package/dist/manifest.js +723 -0
- package/dist/manifest.js.map +1 -0
- package/dist/packer.d.ts +44 -0
- package/dist/packer.js +78 -0
- package/dist/packer.js.map +1 -0
- package/dist/project.d.ts +59 -0
- package/dist/project.js +149 -0
- package/dist/project.js.map +1 -0
- package/dist/scaffold.d.ts +49 -0
- package/dist/scaffold.js +127 -0
- package/dist/scaffold.js.map +1 -0
- package/dist/vite.d.ts +40 -0
- package/dist/vite.js +124 -0
- package/dist/vite.js.map +1 -0
- package/package.json +49 -4
- package/src/cli.ts +206 -0
- package/src/errors.ts +11 -0
- package/src/index.ts +24 -0
- package/src/main.ts +3 -0
- package/src/manifest.ts +882 -0
- package/src/packer.ts +104 -0
- package/src/project.ts +168 -0
- package/src/scaffold.ts +156 -0
- package/src/vite.ts +136 -0
- package/template/README.md +12 -0
- package/template/_gitignore +4 -0
- package/template/icon.svg +14 -0
- package/template/index.html +33 -0
- package/template/package.json +22 -0
- package/template/rollrook-plugin.json +18 -0
- package/template/src/main.ts +78 -0
- package/template/src/style.css +35 -0
- package/template/src/vite-env.d.ts +1 -0
- package/template/tsconfig.json +18 -0
- package/template/vite.config.ts +10 -0
- package/README.md +0 -3
package/src/manifest.ts
ADDED
|
@@ -0,0 +1,882 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { extname, isAbsolute, join } from "node:path";
|
|
3
|
+
|
|
4
|
+
/** Where a view shows in RollRook's stage; a `background` view is a hidden page kept loaded while the plugin is on. */
|
|
5
|
+
export type ViewSlot = "dock" | "sidebar" | "footbar" | "popover" | "settings" | "background";
|
|
6
|
+
|
|
7
|
+
/** One view of a plugin: a page in one place of the stage. */
|
|
8
|
+
export interface PluginView {
|
|
9
|
+
id: string;
|
|
10
|
+
slot: ViewSlot;
|
|
11
|
+
/** The page, relative to the plugin's root. */
|
|
12
|
+
entry: string;
|
|
13
|
+
/** A dock or sidebar view's title. */
|
|
14
|
+
title: string | undefined;
|
|
15
|
+
/** A dock or sidebar view's icon, relative to the plugin's root. */
|
|
16
|
+
icon: string | undefined;
|
|
17
|
+
/** A footbar view's width in points, or `fill`; a popover's width. */
|
|
18
|
+
width: number | "fill" | undefined;
|
|
19
|
+
/** A popover's height in points, or a settings view's (320 when not given). */
|
|
20
|
+
height: number | undefined;
|
|
21
|
+
/** Which end of the footbar the view sits at. */
|
|
22
|
+
align: "leading" | "trailing" | undefined;
|
|
23
|
+
/** Where the view sits among the footbar's items, lower first. */
|
|
24
|
+
order: number | undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The kinds of value a setting holds. */
|
|
28
|
+
export type SettingType = "string" | "number" | "boolean" | "enum" | "json";
|
|
29
|
+
|
|
30
|
+
/** One choice of an `enum` setting. */
|
|
31
|
+
export interface SettingOption {
|
|
32
|
+
value: string;
|
|
33
|
+
title: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A setting the manifest declares. */
|
|
37
|
+
export interface PluginSetting {
|
|
38
|
+
key: string;
|
|
39
|
+
type: SettingType;
|
|
40
|
+
title: string;
|
|
41
|
+
/** The value before the user sets one, or undefined for the type's own. */
|
|
42
|
+
default_value: unknown;
|
|
43
|
+
list_options: SettingOption[];
|
|
44
|
+
min: number | undefined;
|
|
45
|
+
max: number | undefined;
|
|
46
|
+
step: number | undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A tool the plugin offers RollRook's assistant, answered in its background view. */
|
|
50
|
+
export interface AssistantTool {
|
|
51
|
+
/** snake_case, unique in the plugin. */
|
|
52
|
+
name: string;
|
|
53
|
+
/** What the tool does and when to use it, for the assistant. */
|
|
54
|
+
description: string;
|
|
55
|
+
/** The JSON Schema of its input; `{ type: "object" }` when the manifest gives none. */
|
|
56
|
+
input: Record<string, unknown>;
|
|
57
|
+
/** Whether the user approves each call, after a preview, before it runs. */
|
|
58
|
+
is_confirmed: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** What a plugin adds to RollRook beyond its views: `contributes` in the manifest. */
|
|
62
|
+
export interface PluginContributions {
|
|
63
|
+
/** The plugin's items in RollRook's calendar, under this title; undefined when it shows none. */
|
|
64
|
+
calendar_title: string | undefined;
|
|
65
|
+
list_tools: AssistantTool[];
|
|
66
|
+
/** A Markdown file inside the plugin teaching the assistant to use the tools. */
|
|
67
|
+
skill: string | undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A plugin's `rollrook-plugin.json`, with the SDK's names. */
|
|
71
|
+
export interface PluginManifest {
|
|
72
|
+
id: string;
|
|
73
|
+
name: string;
|
|
74
|
+
version: string;
|
|
75
|
+
description: string | undefined;
|
|
76
|
+
publisher: string | undefined;
|
|
77
|
+
/** The older form's page; `list_views` holds it as the `main` dock view. */
|
|
78
|
+
main: string | undefined;
|
|
79
|
+
icon: string | undefined;
|
|
80
|
+
/** The views, the older form's `main` included. */
|
|
81
|
+
list_views: PluginView[];
|
|
82
|
+
list_settings: PluginSetting[];
|
|
83
|
+
list_permissions: string[];
|
|
84
|
+
contributes: PluginContributions;
|
|
85
|
+
min_rollrook: string | undefined;
|
|
86
|
+
repository: string | undefined;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** One thing wrong with a manifest. */
|
|
90
|
+
export interface ManifestProblem {
|
|
91
|
+
/** The manifest field at fault, or `manifest` for the file as a whole. */
|
|
92
|
+
field: string;
|
|
93
|
+
message: string;
|
|
94
|
+
/** Errors refuse the install; warnings do not. */
|
|
95
|
+
severity: "error" | "warning";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The outcome of checking a manifest. */
|
|
99
|
+
export interface ManifestReport {
|
|
100
|
+
/** The manifest, when it has no errors. */
|
|
101
|
+
manifest: PluginManifest | undefined;
|
|
102
|
+
list_problems: ManifestProblem[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Options for checking a manifest. */
|
|
106
|
+
export interface ManifestCheckOptions {
|
|
107
|
+
/** The folder the manifest sits in; when given, `main` and `icon` must exist there. */
|
|
108
|
+
folder?: string;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Checks `rollrook-plugin.json` against the rules RollRook installs by. */
|
|
112
|
+
export class ManifestValidator {
|
|
113
|
+
/** The manifest's file name, at the plugin's root. */
|
|
114
|
+
static readonly MANIFEST_FILE = "rollrook-plugin.json";
|
|
115
|
+
|
|
116
|
+
/** Two or more dot-separated parts of lowercase letters, digits and dashes. */
|
|
117
|
+
static readonly ID_PATTERN = /^[a-z0-9-]+(\.[a-z0-9-]+)+$/;
|
|
118
|
+
|
|
119
|
+
/** Semantic versioning 2.0.0. */
|
|
120
|
+
static readonly SEMVER_PATTERN =
|
|
121
|
+
/^(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-]+)*))?$/;
|
|
122
|
+
|
|
123
|
+
/** A host name for `net:<host>`, optionally with a leading `*.` for its subdomains. */
|
|
124
|
+
static readonly HOST_PATTERN = /^(\*\.)?([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)*[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
|
|
125
|
+
|
|
126
|
+
/** The permissions a plugin may ask for, besides `net:<host>`. */
|
|
127
|
+
static readonly LIST_KNOWN_PERMISSIONS = ["raven", "agents.read", "audio", "video"];
|
|
128
|
+
|
|
129
|
+
/** What every plugin has without asking; listing them is refused as unknown. */
|
|
130
|
+
static readonly LIST_DEFAULT_PERMISSIONS = ["context", "storage", "files", "settings", "ui", "system", "plugin"];
|
|
131
|
+
|
|
132
|
+
/** A view's id: lowercase letters, digits and dashes. */
|
|
133
|
+
static readonly VIEW_ID_PATTERN = /^[a-z0-9-]+$/;
|
|
134
|
+
|
|
135
|
+
/** The slots a view may show in. */
|
|
136
|
+
static readonly LIST_SLOTS: readonly ViewSlot[] = ["dock", "sidebar", "footbar", "popover", "settings", "background"];
|
|
137
|
+
|
|
138
|
+
/** The fields each slot takes besides `id`, `slot` and `entry`. */
|
|
139
|
+
static readonly map_slot_fields: Record<ViewSlot, string[]> = {
|
|
140
|
+
dock: ["title", "icon"],
|
|
141
|
+
sidebar: ["title", "icon"],
|
|
142
|
+
footbar: ["width", "align", "order"],
|
|
143
|
+
popover: ["width", "height"],
|
|
144
|
+
settings: ["height"],
|
|
145
|
+
background: [],
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/** A tool's name: snake_case words of lowercase letters and digits joined by single underscores, a letter first. */
|
|
149
|
+
static readonly TOOL_NAME_PATTERN = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/;
|
|
150
|
+
|
|
151
|
+
/** The longest a tool's name may be; RollRook prefixes it with the plugin's name for the assistant. */
|
|
152
|
+
static readonly TOOL_NAME_MAX_LENGTH = 32;
|
|
153
|
+
|
|
154
|
+
/** The most tools a plugin may give the assistant. */
|
|
155
|
+
static readonly TOOL_LIMIT = 40;
|
|
156
|
+
|
|
157
|
+
/** The longest the calendar layer's title may be. */
|
|
158
|
+
static readonly CALENDAR_TITLE_MAX_LENGTH = 40;
|
|
159
|
+
|
|
160
|
+
/** The fields `contributes` takes. */
|
|
161
|
+
static readonly LIST_CONTRIBUTION_FIELDS = ["calendar", "raven"];
|
|
162
|
+
|
|
163
|
+
/** The fields a tool takes. */
|
|
164
|
+
static readonly LIST_TOOL_FIELDS = ["name", "description", "input", "confirm"];
|
|
165
|
+
|
|
166
|
+
/** The extension of the assistant's skill file. */
|
|
167
|
+
static readonly SKILL_EXTENSION = ".md";
|
|
168
|
+
|
|
169
|
+
/** The slots a plugin needs at least one view in: the others are opened from those. */
|
|
170
|
+
static readonly LIST_STANDING_SLOTS: readonly ViewSlot[] = ["dock", "sidebar", "footbar"];
|
|
171
|
+
|
|
172
|
+
/** A settings view's height when the manifest gives none, in points. */
|
|
173
|
+
static readonly SETTINGS_DEFAULT_HEIGHT = 320;
|
|
174
|
+
|
|
175
|
+
/** The widest a footbar view may be, in points. */
|
|
176
|
+
static readonly FOOTBAR_MAX_WIDTH = 600;
|
|
177
|
+
|
|
178
|
+
/** The largest a popover may be either way, in points. */
|
|
179
|
+
static readonly POPOVER_MAX_SIZE = 800;
|
|
180
|
+
|
|
181
|
+
/** The kinds of value a setting holds. */
|
|
182
|
+
static readonly LIST_SETTING_TYPES: readonly SettingType[] = ["string", "number", "boolean", "enum", "json"];
|
|
183
|
+
|
|
184
|
+
/** The longest a setting's key may be. */
|
|
185
|
+
static readonly SETTING_KEY_MAX_LENGTH = 200;
|
|
186
|
+
|
|
187
|
+
/** The id of the view the older form's `main` page becomes. */
|
|
188
|
+
static readonly MAIN_VIEW_ID = "main";
|
|
189
|
+
|
|
190
|
+
/** The prefix of a network permission. */
|
|
191
|
+
static readonly NET_PREFIX = "net:";
|
|
192
|
+
|
|
193
|
+
/** The permission to reach any site. */
|
|
194
|
+
static readonly NET_ANY_PERMISSION = "net:*";
|
|
195
|
+
|
|
196
|
+
/** The bytes of a PNG up to the end of its size in the IHDR chunk. */
|
|
197
|
+
static readonly PNG_HEADER_LENGTH = 24;
|
|
198
|
+
|
|
199
|
+
/** The icon formats RollRook shows. */
|
|
200
|
+
static readonly LIST_ICON_EXTENSIONS = [".png", ".svg"];
|
|
201
|
+
|
|
202
|
+
/** The fields the manifest defines. */
|
|
203
|
+
static readonly LIST_FIELDS = [
|
|
204
|
+
"id",
|
|
205
|
+
"name",
|
|
206
|
+
"version",
|
|
207
|
+
"description",
|
|
208
|
+
"publisher",
|
|
209
|
+
"main",
|
|
210
|
+
"icon",
|
|
211
|
+
"views",
|
|
212
|
+
"settings",
|
|
213
|
+
"permissions",
|
|
214
|
+
"contributes",
|
|
215
|
+
"minRollRook",
|
|
216
|
+
"repository",
|
|
217
|
+
];
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Read and check the manifest in a folder.
|
|
221
|
+
*
|
|
222
|
+
* @param folder - the plugin's folder
|
|
223
|
+
* @returns the manifest and its problems
|
|
224
|
+
*/
|
|
225
|
+
static read(folder: string): ManifestReport {
|
|
226
|
+
const path = join(folder, ManifestValidator.MANIFEST_FILE);
|
|
227
|
+
if (!existsSync(path)) {
|
|
228
|
+
return ManifestValidator.failed(`no ${ManifestValidator.MANIFEST_FILE} in ${folder}`);
|
|
229
|
+
}
|
|
230
|
+
let raw: unknown;
|
|
231
|
+
try {
|
|
232
|
+
raw = JSON.parse(readFileSync(path, "utf8"));
|
|
233
|
+
} catch (err: unknown) {
|
|
234
|
+
if (err instanceof SyntaxError) {
|
|
235
|
+
return ManifestValidator.failed(`${ManifestValidator.MANIFEST_FILE} is not valid JSON: ${err.message}`);
|
|
236
|
+
}
|
|
237
|
+
throw err;
|
|
238
|
+
}
|
|
239
|
+
return ManifestValidator.check(raw, { folder });
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Check a parsed manifest.
|
|
244
|
+
*
|
|
245
|
+
* @param raw - the parsed JSON
|
|
246
|
+
* @param options - the folder to look for `main` and `icon` in
|
|
247
|
+
* @returns the manifest and its problems
|
|
248
|
+
*/
|
|
249
|
+
static check(raw: unknown, options: ManifestCheckOptions = {}): ManifestReport {
|
|
250
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
251
|
+
return ManifestValidator.failed("the manifest must be a JSON object");
|
|
252
|
+
}
|
|
253
|
+
return new ManifestValidator({ ...raw }, options.folder).run();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Whether a permission is one RollRook knows.
|
|
258
|
+
*
|
|
259
|
+
* @param permission - the permission as written in the manifest
|
|
260
|
+
* @returns true for `raven`, `agents.read`, `audio`, `video`, `net:*` and a well-formed `net:<host>` with a dot in its host
|
|
261
|
+
*/
|
|
262
|
+
static is_known_permission(permission: string): boolean {
|
|
263
|
+
if (
|
|
264
|
+
ManifestValidator.LIST_KNOWN_PERMISSIONS.includes(permission)
|
|
265
|
+
|| permission === ManifestValidator.NET_ANY_PERMISSION
|
|
266
|
+
) {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
if (!permission.startsWith(ManifestValidator.NET_PREFIX)) {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
const host = permission.slice(ManifestValidator.NET_PREFIX.length);
|
|
273
|
+
const bare_host = host.startsWith("*.") ? host.slice(2) : host;
|
|
274
|
+
return ManifestValidator.HOST_PATTERN.test(host) && bare_host.includes(".");
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
private static failed(message: string): ManifestReport {
|
|
278
|
+
return {
|
|
279
|
+
manifest: undefined,
|
|
280
|
+
list_problems: [{ field: "manifest", message, severity: "error" }],
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
private readonly record: Record<string, unknown>;
|
|
285
|
+
private readonly folder: string | undefined;
|
|
286
|
+
private readonly list_problems: ManifestProblem[] = [];
|
|
287
|
+
|
|
288
|
+
private constructor(record: Record<string, unknown>, folder: string | undefined) {
|
|
289
|
+
this.record = record;
|
|
290
|
+
this.folder = folder;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private run(): ManifestReport {
|
|
294
|
+
const id = this.text_field("id", true);
|
|
295
|
+
if (id !== undefined && !ManifestValidator.ID_PATTERN.test(id)) {
|
|
296
|
+
this.error("id", "must be two or more dot-separated parts of lowercase letters, digits and dashes, the first the publisher's (e.g. octo.pomodoro)");
|
|
297
|
+
}
|
|
298
|
+
const name = this.text_field("name", true);
|
|
299
|
+
const version = this.text_field("version", true);
|
|
300
|
+
if (version !== undefined && !ManifestValidator.SEMVER_PATTERN.test(version)) {
|
|
301
|
+
this.error("version", `${version} is not a semantic version (e.g. 1.2.0)`);
|
|
302
|
+
}
|
|
303
|
+
const description = this.text_field("description", false);
|
|
304
|
+
const publisher = this.text_field("publisher", false);
|
|
305
|
+
const id_publisher = id?.split(".")[0];
|
|
306
|
+
if (publisher !== undefined && id_publisher !== undefined && id_publisher !== publisher) {
|
|
307
|
+
this.warning("publisher", `the id's first part (${id_publisher}) should be the publisher (${publisher})`);
|
|
308
|
+
}
|
|
309
|
+
const has_views = this.record["views"] !== undefined;
|
|
310
|
+
const main = this.text_field("main", !has_views);
|
|
311
|
+
if (main !== undefined && has_views) {
|
|
312
|
+
this.warning("main", "is ignored when views are given");
|
|
313
|
+
} else if (main !== undefined) {
|
|
314
|
+
this.check_path("main", main);
|
|
315
|
+
}
|
|
316
|
+
const icon = this.text_field("icon", false);
|
|
317
|
+
if (icon !== undefined) {
|
|
318
|
+
if (!ManifestValidator.LIST_ICON_EXTENSIONS.includes(extname(icon).toLowerCase())) {
|
|
319
|
+
this.error("icon", "must be a PNG or an SVG");
|
|
320
|
+
} else if (this.check_path("icon", icon)) {
|
|
321
|
+
this.check_png_square(icon);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
const list_views = has_views ? this.check_views() : [];
|
|
325
|
+
if (!has_views && main !== undefined && name !== undefined) {
|
|
326
|
+
list_views.push({
|
|
327
|
+
id: ManifestValidator.MAIN_VIEW_ID,
|
|
328
|
+
slot: "dock",
|
|
329
|
+
entry: main,
|
|
330
|
+
title: name,
|
|
331
|
+
icon: undefined,
|
|
332
|
+
width: undefined,
|
|
333
|
+
height: undefined,
|
|
334
|
+
align: undefined,
|
|
335
|
+
order: undefined,
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
const list_settings = this.check_settings();
|
|
339
|
+
const list_permissions = this.check_permissions();
|
|
340
|
+
const contributes = this.check_contributes(list_views);
|
|
341
|
+
const min_rollrook = this.text_field("minRollRook", false);
|
|
342
|
+
if (min_rollrook !== undefined && !ManifestValidator.SEMVER_PATTERN.test(min_rollrook)) {
|
|
343
|
+
this.error("minRollRook", `${min_rollrook} is not a semantic version`);
|
|
344
|
+
}
|
|
345
|
+
const repository = this.text_field("repository", false);
|
|
346
|
+
if (repository !== undefined && !repository.startsWith("https://")) {
|
|
347
|
+
this.warning("repository", "should be an https URL");
|
|
348
|
+
}
|
|
349
|
+
for (const key of Object.keys(this.record)) {
|
|
350
|
+
if (!ManifestValidator.LIST_FIELDS.includes(key)) {
|
|
351
|
+
this.warning(key, "is not a manifest field and is ignored");
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
const has_error = this.list_problems.some((problem: ManifestProblem) => problem.severity === "error");
|
|
355
|
+
if (
|
|
356
|
+
has_error
|
|
357
|
+
|| id === undefined
|
|
358
|
+
|| name === undefined
|
|
359
|
+
|| version === undefined
|
|
360
|
+
|| list_views.length === 0
|
|
361
|
+
) {
|
|
362
|
+
return { manifest: undefined, list_problems: this.list_problems };
|
|
363
|
+
}
|
|
364
|
+
return {
|
|
365
|
+
manifest: {
|
|
366
|
+
id,
|
|
367
|
+
name,
|
|
368
|
+
version,
|
|
369
|
+
description,
|
|
370
|
+
publisher,
|
|
371
|
+
main,
|
|
372
|
+
icon,
|
|
373
|
+
list_views,
|
|
374
|
+
list_settings,
|
|
375
|
+
list_permissions,
|
|
376
|
+
contributes,
|
|
377
|
+
min_rollrook,
|
|
378
|
+
repository,
|
|
379
|
+
},
|
|
380
|
+
list_problems: this.list_problems,
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
private error(field: string, message: string): void {
|
|
385
|
+
this.list_problems.push({ field, message, severity: "error" });
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
private warning(field: string, message: string): void {
|
|
389
|
+
this.list_problems.push({ field, message, severity: "warning" });
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
private text_field(key: string, is_required: boolean): string | undefined {
|
|
393
|
+
const value = this.record[key];
|
|
394
|
+
if (value === undefined) {
|
|
395
|
+
if (is_required) {
|
|
396
|
+
this.error(key, "is required");
|
|
397
|
+
}
|
|
398
|
+
return undefined;
|
|
399
|
+
}
|
|
400
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
401
|
+
this.error(key, "must be a non-empty string");
|
|
402
|
+
return undefined;
|
|
403
|
+
}
|
|
404
|
+
return value;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
private check_path(field: string, path: string): boolean {
|
|
408
|
+
if (isAbsolute(path) || path.split(/[\\/]/).includes("..")) {
|
|
409
|
+
this.error(field, "must be a path inside the plugin's folder");
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
if (this.folder === undefined) {
|
|
413
|
+
return true;
|
|
414
|
+
}
|
|
415
|
+
const full_path = join(this.folder, path);
|
|
416
|
+
if (!existsSync(full_path) || !statSync(full_path).isFile()) {
|
|
417
|
+
this.error(field, `${path} does not exist in ${this.folder}`);
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
420
|
+
return true;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
private check_png_square(icon: string): void {
|
|
424
|
+
if (this.folder === undefined || extname(icon).toLowerCase() !== ".png") {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
const data = readFileSync(join(this.folder, icon));
|
|
428
|
+
if (data.length < ManifestValidator.PNG_HEADER_LENGTH || data.toString("ascii", 12, 16) !== "IHDR") {
|
|
429
|
+
this.error("icon", "is not a PNG file");
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
const width = data.readUInt32BE(16);
|
|
433
|
+
const height = data.readUInt32BE(20);
|
|
434
|
+
if (width !== height) {
|
|
435
|
+
this.error("icon", `must be square, not ${width}×${height}`);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
private check_views(): PluginView[] {
|
|
440
|
+
const raw = this.record["views"];
|
|
441
|
+
if (!Array.isArray(raw) || raw.length === 0) {
|
|
442
|
+
this.error("views", "must be a non-empty array of views");
|
|
443
|
+
return [];
|
|
444
|
+
}
|
|
445
|
+
const list_views: PluginView[] = [];
|
|
446
|
+
const set_ids = new Set<string>();
|
|
447
|
+
for (const [index, item] of raw.entries()) {
|
|
448
|
+
const view = this.check_view(item, index);
|
|
449
|
+
if (view === undefined) {
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
if (set_ids.has(view.id)) {
|
|
453
|
+
this.error(`views[${index}].id`, `two views are called ${view.id}`);
|
|
454
|
+
}
|
|
455
|
+
set_ids.add(view.id);
|
|
456
|
+
list_views.push(view);
|
|
457
|
+
}
|
|
458
|
+
if (list_views.length > 0 && !list_views.some((view: PluginView) => ManifestValidator.LIST_STANDING_SLOTS.includes(view.slot))) {
|
|
459
|
+
this.error("views", "needs a dock, sidebar or footbar view; popover and settings views are opened from those");
|
|
460
|
+
}
|
|
461
|
+
const list_settings_views = list_views.filter((view: PluginView) => view.slot === "settings");
|
|
462
|
+
if (list_settings_views.length > 1) {
|
|
463
|
+
this.error("views", "may have only one settings view");
|
|
464
|
+
}
|
|
465
|
+
const list_background_views = list_views.filter((view: PluginView) => view.slot === "background");
|
|
466
|
+
if (list_background_views.length > 1) {
|
|
467
|
+
this.error("views", "may have only one background view");
|
|
468
|
+
}
|
|
469
|
+
return list_views;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
private check_view(item: unknown, index: number): PluginView | undefined {
|
|
473
|
+
const field = `views[${index}]`;
|
|
474
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
475
|
+
this.error(field, "must be an object");
|
|
476
|
+
return undefined;
|
|
477
|
+
}
|
|
478
|
+
const view: Record<string, unknown> = { ...item };
|
|
479
|
+
const id = view["id"];
|
|
480
|
+
if (typeof id !== "string" || !ManifestValidator.VIEW_ID_PATTERN.test(id)) {
|
|
481
|
+
this.error(`${field}.id`, "must be lowercase letters, digits and dashes");
|
|
482
|
+
}
|
|
483
|
+
const slot = ManifestValidator.LIST_SLOTS.find((candidate: ViewSlot) => candidate === view["slot"]);
|
|
484
|
+
if (slot === undefined) {
|
|
485
|
+
this.error(`${field}.slot`, `must be one of ${ManifestValidator.LIST_SLOTS.join(", ")}`);
|
|
486
|
+
}
|
|
487
|
+
const entry = view["entry"];
|
|
488
|
+
if (typeof entry !== "string" || entry === "") {
|
|
489
|
+
this.error(`${field}.entry`, "must be the path of a page inside the plugin");
|
|
490
|
+
} else {
|
|
491
|
+
this.check_path(`${field}.entry`, entry);
|
|
492
|
+
}
|
|
493
|
+
if (typeof id !== "string" || slot === undefined || typeof entry !== "string") {
|
|
494
|
+
return undefined;
|
|
495
|
+
}
|
|
496
|
+
const list_allowed = ["id", "slot", "entry", ...ManifestValidator.map_slot_fields[slot]];
|
|
497
|
+
for (const key of Object.keys(view)) {
|
|
498
|
+
if (!list_allowed.includes(key)) {
|
|
499
|
+
this.warning(`${field}.${key}`, `is not a field of a ${slot} view and is ignored`);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
const title = view["title"];
|
|
503
|
+
if (title !== undefined && (typeof title !== "string" || title.trim() === "")) {
|
|
504
|
+
this.error(`${field}.title`, "must be a non-empty string");
|
|
505
|
+
}
|
|
506
|
+
const icon = view["icon"];
|
|
507
|
+
if (icon !== undefined) {
|
|
508
|
+
if (typeof icon !== "string" || !ManifestValidator.LIST_ICON_EXTENSIONS.includes(extname(icon).toLowerCase())) {
|
|
509
|
+
this.error(`${field}.icon`, "must be a PNG or an SVG");
|
|
510
|
+
} else if (this.check_path(`${field}.icon`, icon)) {
|
|
511
|
+
this.check_png_square(icon);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
const width = view["width"];
|
|
515
|
+
const height = view["height"];
|
|
516
|
+
const align = view["align"];
|
|
517
|
+
const order = view["order"];
|
|
518
|
+
if (slot === "footbar") {
|
|
519
|
+
if (width !== undefined && width !== "fill" && !ManifestValidator.is_size(width, ManifestValidator.FOOTBAR_MAX_WIDTH)) {
|
|
520
|
+
this.error(`${field}.width`, `must be "fill" or a number of points from 1 to ${ManifestValidator.FOOTBAR_MAX_WIDTH}`);
|
|
521
|
+
}
|
|
522
|
+
if (align !== undefined && align !== "leading" && align !== "trailing") {
|
|
523
|
+
this.error(`${field}.align`, "must be leading or trailing");
|
|
524
|
+
}
|
|
525
|
+
if (order !== undefined && (typeof order !== "number" || !Number.isFinite(order))) {
|
|
526
|
+
this.error(`${field}.order`, "must be a number");
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (slot === "popover") {
|
|
530
|
+
if (!ManifestValidator.is_size(width, ManifestValidator.POPOVER_MAX_SIZE)) {
|
|
531
|
+
this.error(`${field}.width`, `a popover needs a width from 1 to ${ManifestValidator.POPOVER_MAX_SIZE} points`);
|
|
532
|
+
}
|
|
533
|
+
if (!ManifestValidator.is_size(height, ManifestValidator.POPOVER_MAX_SIZE)) {
|
|
534
|
+
this.error(`${field}.height`, `a popover needs a height from 1 to ${ManifestValidator.POPOVER_MAX_SIZE} points`);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
if (slot === "settings" && height !== undefined && !ManifestValidator.is_size(height, ManifestValidator.POPOVER_MAX_SIZE)) {
|
|
538
|
+
this.error(`${field}.height`, `must be a number of points from 1 to ${ManifestValidator.POPOVER_MAX_SIZE}`);
|
|
539
|
+
}
|
|
540
|
+
return {
|
|
541
|
+
id,
|
|
542
|
+
slot,
|
|
543
|
+
entry,
|
|
544
|
+
title: typeof title === "string" ? title : undefined,
|
|
545
|
+
icon: typeof icon === "string" ? icon : undefined,
|
|
546
|
+
width: width === "fill" || typeof width === "number" ? width : undefined,
|
|
547
|
+
height: typeof height === "number"
|
|
548
|
+
? height
|
|
549
|
+
: slot === "settings" ? ManifestValidator.SETTINGS_DEFAULT_HEIGHT : undefined,
|
|
550
|
+
align: align === "leading" || align === "trailing" ? align : undefined,
|
|
551
|
+
order: typeof order === "number" ? order : undefined,
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
private check_settings(): PluginSetting[] {
|
|
556
|
+
const raw = this.record["settings"];
|
|
557
|
+
if (raw === undefined) {
|
|
558
|
+
return [];
|
|
559
|
+
}
|
|
560
|
+
if (!Array.isArray(raw)) {
|
|
561
|
+
this.error("settings", "must be an array of settings");
|
|
562
|
+
return [];
|
|
563
|
+
}
|
|
564
|
+
const list_settings: PluginSetting[] = [];
|
|
565
|
+
const set_keys = new Set<string>();
|
|
566
|
+
for (const [index, item] of raw.entries()) {
|
|
567
|
+
const setting = this.check_setting(item, index);
|
|
568
|
+
if (setting === undefined) {
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
if (set_keys.has(setting.key)) {
|
|
572
|
+
this.error(`settings[${index}].key`, `two settings are called ${setting.key}`);
|
|
573
|
+
}
|
|
574
|
+
set_keys.add(setting.key);
|
|
575
|
+
list_settings.push(setting);
|
|
576
|
+
}
|
|
577
|
+
return list_settings;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
private check_setting(item: unknown, index: number): PluginSetting | undefined {
|
|
581
|
+
const field = `settings[${index}]`;
|
|
582
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
583
|
+
this.error(field, "must be an object");
|
|
584
|
+
return undefined;
|
|
585
|
+
}
|
|
586
|
+
const setting: Record<string, unknown> = { ...item };
|
|
587
|
+
const key = setting["key"];
|
|
588
|
+
if (typeof key !== "string" || key === "" || key.length > ManifestValidator.SETTING_KEY_MAX_LENGTH) {
|
|
589
|
+
this.error(`${field}.key`, `must be a string of 1 to ${ManifestValidator.SETTING_KEY_MAX_LENGTH} characters`);
|
|
590
|
+
}
|
|
591
|
+
const type = ManifestValidator.LIST_SETTING_TYPES.find((candidate: SettingType) => candidate === setting["type"]);
|
|
592
|
+
if (type === undefined) {
|
|
593
|
+
this.error(`${field}.type`, `must be one of ${ManifestValidator.LIST_SETTING_TYPES.join(", ")}`);
|
|
594
|
+
}
|
|
595
|
+
const title = setting["title"];
|
|
596
|
+
if (typeof title !== "string" || title.trim() === "") {
|
|
597
|
+
this.error(`${field}.title`, "must be a non-empty string");
|
|
598
|
+
}
|
|
599
|
+
if (typeof key !== "string" || type === undefined || typeof title !== "string") {
|
|
600
|
+
return undefined;
|
|
601
|
+
}
|
|
602
|
+
const list_options = type === "enum" ? this.check_options(setting["options"], field) : [];
|
|
603
|
+
if (type !== "enum" && setting["options"] !== undefined) {
|
|
604
|
+
this.warning(`${field}.options`, "applies only to enum settings and is ignored");
|
|
605
|
+
}
|
|
606
|
+
const map_bounds: Record<string, number | undefined> = {};
|
|
607
|
+
for (const bound of ["min", "max", "step"]) {
|
|
608
|
+
const value = setting[bound];
|
|
609
|
+
if (value === undefined) {
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
if (type !== "number") {
|
|
613
|
+
this.warning(`${field}.${bound}`, "applies only to number settings and is ignored");
|
|
614
|
+
} else if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
615
|
+
this.error(`${field}.${bound}`, "must be a number");
|
|
616
|
+
} else {
|
|
617
|
+
map_bounds[bound] = value;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
const min = map_bounds["min"];
|
|
621
|
+
const max = map_bounds["max"];
|
|
622
|
+
if (min !== undefined && max !== undefined && min > max) {
|
|
623
|
+
this.error(`${field}.min`, "is greater than max");
|
|
624
|
+
}
|
|
625
|
+
const default_value = setting["default"];
|
|
626
|
+
if (default_value !== undefined) {
|
|
627
|
+
this.check_default({
|
|
628
|
+
field: `${field}.default`,
|
|
629
|
+
type,
|
|
630
|
+
value: default_value,
|
|
631
|
+
list_options,
|
|
632
|
+
min,
|
|
633
|
+
max,
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
for (const name of Object.keys(setting)) {
|
|
637
|
+
if (!["key", "type", "title", "default", "options", "min", "max", "step"].includes(name)) {
|
|
638
|
+
this.warning(`${field}.${name}`, "is not a field of a setting and is ignored");
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
return {
|
|
642
|
+
key,
|
|
643
|
+
type,
|
|
644
|
+
title,
|
|
645
|
+
default_value,
|
|
646
|
+
list_options,
|
|
647
|
+
min,
|
|
648
|
+
max,
|
|
649
|
+
step: map_bounds["step"],
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
private check_options(raw: unknown, field: string): SettingOption[] {
|
|
654
|
+
if (!Array.isArray(raw) || raw.length === 0) {
|
|
655
|
+
this.error(`${field}.options`, "an enum setting needs options: [{ value, title }]");
|
|
656
|
+
return [];
|
|
657
|
+
}
|
|
658
|
+
const list_options: SettingOption[] = [];
|
|
659
|
+
for (const option of raw) {
|
|
660
|
+
if (
|
|
661
|
+
typeof option === "object"
|
|
662
|
+
&& option !== null
|
|
663
|
+
&& typeof option.value === "string"
|
|
664
|
+
&& typeof option.title === "string"
|
|
665
|
+
) {
|
|
666
|
+
list_options.push({ value: option.value, title: option.title });
|
|
667
|
+
} else {
|
|
668
|
+
this.error(`${field}.options`, "each option is { value, title }, both strings");
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
return list_options;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
private check_default(check: {
|
|
675
|
+
field: string;
|
|
676
|
+
type: SettingType;
|
|
677
|
+
value: unknown;
|
|
678
|
+
list_options: SettingOption[];
|
|
679
|
+
min: number | undefined;
|
|
680
|
+
max: number | undefined;
|
|
681
|
+
}): void {
|
|
682
|
+
const { field, type, value } = check;
|
|
683
|
+
const is_valid = type === "string" ? typeof value === "string"
|
|
684
|
+
: type === "number" ? typeof value === "number" && Number.isFinite(value)
|
|
685
|
+
: type === "boolean" ? typeof value === "boolean"
|
|
686
|
+
: type === "enum" ? check.list_options.some((option: SettingOption) => option.value === value)
|
|
687
|
+
: ManifestValidator.is_json(value);
|
|
688
|
+
if (!is_valid) {
|
|
689
|
+
this.error(field, type === "enum" ? "must be one of the options' values" : `must be a ${type} value`);
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
if (
|
|
693
|
+
typeof value === "number"
|
|
694
|
+
&& ((check.min !== undefined && value < check.min) || (check.max !== undefined && value > check.max))
|
|
695
|
+
) {
|
|
696
|
+
this.warning(field, "lies outside min and max; RollRook clamps it");
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
private static is_size(value: unknown, maximum: number): boolean {
|
|
701
|
+
return typeof value === "number" && value >= 1 && value <= maximum;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
private static is_json(value: unknown): boolean {
|
|
705
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") {
|
|
706
|
+
return true;
|
|
707
|
+
}
|
|
708
|
+
if (typeof value === "number") {
|
|
709
|
+
return Number.isFinite(value);
|
|
710
|
+
}
|
|
711
|
+
if (Array.isArray(value)) {
|
|
712
|
+
return value.every((item: unknown) => ManifestValidator.is_json(item));
|
|
713
|
+
}
|
|
714
|
+
return typeof value === "object" && Object.values(value).every((item: unknown) => ManifestValidator.is_json(item));
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
private check_contributes(list_views: PluginView[]): PluginContributions {
|
|
718
|
+
const contributes: PluginContributions = {
|
|
719
|
+
calendar_title: undefined,
|
|
720
|
+
list_tools: [],
|
|
721
|
+
skill: undefined,
|
|
722
|
+
};
|
|
723
|
+
const raw = this.record["contributes"];
|
|
724
|
+
if (raw === undefined) {
|
|
725
|
+
return contributes;
|
|
726
|
+
}
|
|
727
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
728
|
+
this.error("contributes", "must be an object");
|
|
729
|
+
return contributes;
|
|
730
|
+
}
|
|
731
|
+
const record: Record<string, unknown> = { ...raw };
|
|
732
|
+
for (const key of Object.keys(record)) {
|
|
733
|
+
if (!ManifestValidator.LIST_CONTRIBUTION_FIELDS.includes(key)) {
|
|
734
|
+
this.warning(`contributes.${key}`, "is not something a plugin contributes and is ignored");
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
const has_background = list_views.some((view: PluginView) => view.slot === "background");
|
|
738
|
+
const calendar = record["calendar"];
|
|
739
|
+
if (calendar !== undefined) {
|
|
740
|
+
const title = typeof calendar === "object" && calendar !== null && !Array.isArray(calendar)
|
|
741
|
+
? Reflect.get(calendar, "title")
|
|
742
|
+
: undefined;
|
|
743
|
+
if (typeof title !== "string" || title.trim() === "" || title.length > ManifestValidator.CALENDAR_TITLE_MAX_LENGTH) {
|
|
744
|
+
this.error("contributes.calendar", `must be { title }, 1 to ${ManifestValidator.CALENDAR_TITLE_MAX_LENGTH} characters, the layer RollRook shows the plugin's items under`);
|
|
745
|
+
} else {
|
|
746
|
+
contributes.calendar_title = title;
|
|
747
|
+
if (!has_background) {
|
|
748
|
+
this.warning("contributes.calendar", "has no background view to follow calendar.move and keep the items published while no view shows");
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
const raven = record["raven"];
|
|
753
|
+
if (raven !== undefined) {
|
|
754
|
+
if (typeof raven !== "object" || raven === null || Array.isArray(raven)) {
|
|
755
|
+
this.error("contributes.raven", "must be { tools, skill? }");
|
|
756
|
+
} else {
|
|
757
|
+
const raven_record: Record<string, unknown> = { ...raven };
|
|
758
|
+
contributes.list_tools = this.check_tools(raven_record["tools"]);
|
|
759
|
+
contributes.skill = this.check_skill(raven_record["skill"]);
|
|
760
|
+
if (contributes.list_tools.length > 0 && !has_background) {
|
|
761
|
+
this.error("contributes.raven.tools", "are answered in a background view; add a view with \"slot\": \"background\"");
|
|
762
|
+
}
|
|
763
|
+
for (const key of Object.keys(raven_record)) {
|
|
764
|
+
if (key !== "tools" && key !== "skill") {
|
|
765
|
+
this.warning(`contributes.raven.${key}`, "is not a field of contributes.raven and is ignored");
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
return contributes;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
private check_tools(raw: unknown): AssistantTool[] {
|
|
774
|
+
const field = "contributes.raven.tools";
|
|
775
|
+
if (raw === undefined) {
|
|
776
|
+
return [];
|
|
777
|
+
}
|
|
778
|
+
if (!Array.isArray(raw)) {
|
|
779
|
+
this.error(field, "must be an array of tools");
|
|
780
|
+
return [];
|
|
781
|
+
}
|
|
782
|
+
if (raw.length > ManifestValidator.TOOL_LIMIT) {
|
|
783
|
+
this.error(field, `may hold at most ${ManifestValidator.TOOL_LIMIT} tools`);
|
|
784
|
+
}
|
|
785
|
+
const list_tools: AssistantTool[] = [];
|
|
786
|
+
const set_names = new Set<string>();
|
|
787
|
+
for (const [index, item] of raw.entries()) {
|
|
788
|
+
const tool_field = `${field}[${index}]`;
|
|
789
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
790
|
+
this.error(tool_field, "must be { name, description, input, confirm? }");
|
|
791
|
+
continue;
|
|
792
|
+
}
|
|
793
|
+
const tool: Record<string, unknown> = { ...item };
|
|
794
|
+
const name = tool["name"];
|
|
795
|
+
const description = tool["description"];
|
|
796
|
+
const input = tool["input"] ?? { type: "object" };
|
|
797
|
+
const confirm = tool["confirm"];
|
|
798
|
+
let is_valid = true;
|
|
799
|
+
if (
|
|
800
|
+
typeof name !== "string"
|
|
801
|
+
|| !ManifestValidator.TOOL_NAME_PATTERN.test(name)
|
|
802
|
+
|| name.length > ManifestValidator.TOOL_NAME_MAX_LENGTH
|
|
803
|
+
) {
|
|
804
|
+
this.error(`${tool_field}.name`, `must be snake_case (words of lowercase letters and digits joined by single underscores, a letter first), at most ${ManifestValidator.TOOL_NAME_MAX_LENGTH} characters`);
|
|
805
|
+
is_valid = false;
|
|
806
|
+
} else if (set_names.has(name)) {
|
|
807
|
+
this.error(`${tool_field}.name`, `two tools are called ${name}`);
|
|
808
|
+
}
|
|
809
|
+
if (typeof description !== "string" || description.trim() === "") {
|
|
810
|
+
this.error(`${tool_field}.description`, "must say what the tool does and when to use it");
|
|
811
|
+
is_valid = false;
|
|
812
|
+
}
|
|
813
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
814
|
+
this.error(`${tool_field}.input`, "must be a JSON Schema object");
|
|
815
|
+
is_valid = false;
|
|
816
|
+
} else if (Reflect.get(input, "type") !== "object") {
|
|
817
|
+
this.error(`${tool_field}.input`, "must be a JSON Schema of an object: { \"type\": \"object\", \"properties\": { ... } }");
|
|
818
|
+
is_valid = false;
|
|
819
|
+
} else if (!ManifestValidator.is_json(input)) {
|
|
820
|
+
this.error(`${tool_field}.input`, "must be JSON");
|
|
821
|
+
is_valid = false;
|
|
822
|
+
}
|
|
823
|
+
if (confirm !== undefined && typeof confirm !== "boolean") {
|
|
824
|
+
this.error(`${tool_field}.confirm`, "must be true or false");
|
|
825
|
+
}
|
|
826
|
+
for (const key of Object.keys(tool)) {
|
|
827
|
+
if (!ManifestValidator.LIST_TOOL_FIELDS.includes(key)) {
|
|
828
|
+
this.warning(`${tool_field}.${key}`, "is not a field of a tool and is ignored");
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
if (!is_valid || typeof name !== "string" || typeof description !== "string" || typeof input !== "object" || input === null) {
|
|
832
|
+
continue;
|
|
833
|
+
}
|
|
834
|
+
set_names.add(name);
|
|
835
|
+
list_tools.push({
|
|
836
|
+
name,
|
|
837
|
+
description,
|
|
838
|
+
input: { ...input },
|
|
839
|
+
is_confirmed: confirm === true,
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
return list_tools;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
private check_skill(raw: unknown): string | undefined {
|
|
846
|
+
const field = "contributes.raven.skill";
|
|
847
|
+
if (raw === undefined) {
|
|
848
|
+
return undefined;
|
|
849
|
+
}
|
|
850
|
+
if (typeof raw !== "string" || extname(raw).toLowerCase() !== ManifestValidator.SKILL_EXTENSION) {
|
|
851
|
+
this.error(field, "must be the path of a Markdown file inside the plugin");
|
|
852
|
+
return undefined;
|
|
853
|
+
}
|
|
854
|
+
return this.check_path(field, raw) ? raw : undefined;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
private check_permissions(): string[] {
|
|
858
|
+
const raw = this.record["permissions"];
|
|
859
|
+
if (raw === undefined) {
|
|
860
|
+
return [];
|
|
861
|
+
}
|
|
862
|
+
if (!Array.isArray(raw)) {
|
|
863
|
+
this.error("permissions", "must be an array of strings");
|
|
864
|
+
return [];
|
|
865
|
+
}
|
|
866
|
+
const list_permissions: string[] = [];
|
|
867
|
+
for (const permission of raw) {
|
|
868
|
+
if (typeof permission !== "string") {
|
|
869
|
+
this.error("permissions", "must be an array of strings");
|
|
870
|
+
} else if (ManifestValidator.LIST_DEFAULT_PERMISSIONS.includes(permission)) {
|
|
871
|
+
this.error("permissions", `${permission} is granted to every plugin; remove it, RollRook refuses permissions it does not know`);
|
|
872
|
+
} else if (!ManifestValidator.is_known_permission(permission)) {
|
|
873
|
+
this.error("permissions", `${permission} is not a known permission (raven, agents.read, audio, video, net:<host>, net:*)`);
|
|
874
|
+
} else if (list_permissions.includes(permission)) {
|
|
875
|
+
this.warning("permissions", `${permission} is listed twice`);
|
|
876
|
+
} else {
|
|
877
|
+
list_permissions.push(permission);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
return list_permissions;
|
|
881
|
+
}
|
|
882
|
+
}
|