forked from openai/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.js
More file actions
291 lines (273 loc) · 8.92 KB
/
Copy pathplugin.js
File metadata and controls
291 lines (273 loc) · 8.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
import path from "node:path";
import { createArtifact, createCheck, createMetric } from "../core/schema.js";
import { evaluateSkill } from "./skill.js";
import { discoverPluginSkillDirectories } from "../core/target.js";
import { pathExists, readJson, relativePath } from "../lib/files.js";
function isHyphenCase(value) {
return /^[a-z0-9-]+$/.test(value) && !value.startsWith("-") && !value.endsWith("-") && !value.includes("--");
}
export async function evaluatePlugin(pluginRoot) {
const manifestPath = path.join(pluginRoot, ".codex-plugin", "plugin.json");
const targetPath = relativePath(process.cwd(), pluginRoot);
const checks = [];
const metrics = [];
const artifacts = [];
if (!(await pathExists(manifestPath))) {
checks.push(
createCheck({
id: "plugin-manifest-missing",
category: "manifest",
severity: "error",
status: "fail",
message: "The plugin root is missing .codex-plugin/plugin.json.",
evidence: [targetPath],
remediation: ["Add .codex-plugin/plugin.json to the plugin root."],
targetPath,
}),
);
return { checks, metrics, artifacts };
}
let manifest;
try {
manifest = await readJson(manifestPath);
} catch (error) {
checks.push(
createCheck({
id: "plugin-manifest-invalid-json",
category: "manifest",
severity: "error",
status: "fail",
message: "plugin.json could not be parsed as JSON.",
evidence: [error instanceof Error ? error.message : String(error)],
remediation: ["Fix the JSON syntax in .codex-plugin/plugin.json."],
targetPath,
}),
);
return { checks, metrics, artifacts };
}
const requiredFields = ["name", "version", "description", "author", "interface"];
for (const field of requiredFields) {
if (!(field in manifest)) {
checks.push(
createCheck({
id: `manifest-missing-${field}`,
category: "manifest",
severity: "error",
status: "fail",
message: `plugin.json is missing the required \`${field}\` field.`,
evidence: [manifestPath],
remediation: [`Add \`${field}\` to plugin.json.`],
targetPath,
}),
);
}
}
if (manifest.name && !isHyphenCase(manifest.name)) {
checks.push(
createCheck({
id: "manifest-name-not-hyphen-case",
category: "manifest",
severity: "error",
status: "fail",
message: "The plugin name should be lowercase hyphen-case.",
evidence: [`Current name: ${manifest.name}`],
remediation: ["Rename the plugin using lowercase letters, digits, and single hyphens only."],
targetPath,
}),
);
}
if (manifest.name && manifest.name !== path.basename(pluginRoot)) {
checks.push(
createCheck({
id: "manifest-name-directory-mismatch",
category: "manifest",
severity: "warning",
status: "warn",
message: "The plugin manifest name does not match the plugin directory name.",
evidence: [`Directory: ${path.basename(pluginRoot)}`, `Manifest: ${manifest.name}`],
remediation: ["Keep the plugin directory name and plugin.json name aligned."],
targetPath,
}),
);
}
const interfaceFields = [
"displayName",
"shortDescription",
"longDescription",
"developerName",
"category",
"capabilities",
"websiteURL",
"privacyPolicyURL",
"termsOfServiceURL",
"defaultPrompt",
];
const iface = manifest.interface || {};
for (const field of interfaceFields) {
if (!(field in iface)) {
checks.push(
createCheck({
id: `interface-missing-${field}`,
category: "manifest",
severity: "error",
status: "fail",
message: `plugin.json interface is missing \`${field}\`.`,
evidence: [manifestPath],
remediation: [`Add interface.${field} to plugin.json.`],
targetPath,
}),
);
}
}
const pathFields = [
["skills", manifest.skills],
["hooks", manifest.hooks],
["mcpServers", manifest.mcpServers],
["apps", manifest.apps],
["interface.composerIcon", iface.composerIcon],
["interface.logo", iface.logo],
];
for (const [label, fieldValue] of pathFields) {
if (!fieldValue) {
continue;
}
if (typeof fieldValue !== "string" || !fieldValue.startsWith("./")) {
checks.push(
createCheck({
id: `${label}-path-invalid`,
category: "manifest",
severity: "error",
status: "fail",
message: `${label} should use a plugin-relative path that starts with ./`,
evidence: [`Current value: ${String(fieldValue)}`],
remediation: [`Rewrite ${label} as a plugin-relative path like ./skills/.`],
targetPath,
}),
);
continue;
}
const resolvedPath = path.resolve(pluginRoot, fieldValue);
if (!(await pathExists(resolvedPath))) {
checks.push(
createCheck({
id: `${label}-path-missing`,
category: "manifest",
severity: "error",
status: "fail",
message: `${label} points to a missing file or directory.`,
evidence: [fieldValue],
remediation: [`Create the target for ${label} or remove the field.`],
targetPath,
}),
);
}
}
if (Array.isArray(iface.defaultPrompt)) {
if (iface.defaultPrompt.length > 3) {
checks.push(
createCheck({
id: "default-prompt-too-many",
category: "manifest",
severity: "warning",
status: "warn",
message: "Only the first three default prompts are used by Codex.",
evidence: [`Prompt count: ${iface.defaultPrompt.length}`],
remediation: ["Trim interface.defaultPrompt to three strong starters."],
targetPath,
}),
);
}
const oversizedPrompts = iface.defaultPrompt.filter((prompt) => prompt.length > 128);
if (oversizedPrompts.length > 0) {
checks.push(
createCheck({
id: "default-prompt-too-long",
category: "manifest",
severity: "warning",
status: "warn",
message: "One or more default prompts exceed the UI-friendly length budget.",
evidence: oversizedPrompts.map((prompt) => `${prompt.slice(0, 140)} (${prompt.length} chars)`),
remediation: ["Keep default prompts under 128 characters and ideally closer to 50."],
targetPath,
}),
);
}
}
if (iface.brandColor && !/^#[0-9A-Fa-f]{6}$/.test(iface.brandColor)) {
checks.push(
createCheck({
id: "brand-color-invalid",
category: "manifest",
severity: "warning",
status: "warn",
message: "brandColor should be a six-character hex color.",
evidence: [`Current value: ${iface.brandColor}`],
remediation: ["Use a color like #0F766E."],
targetPath,
}),
);
}
const skillDirs = await discoverPluginSkillDirectories(pluginRoot, manifest);
if (skillDirs.length === 0) {
checks.push(
createCheck({
id: "plugin-skills-missing",
category: "manifest",
severity: "warning",
status: "warn",
message: "The plugin did not expose any discoverable skills.",
evidence: [manifest.skills || "./skills/"],
remediation: ["Add at least one skill under the configured skills path."],
targetPath,
}),
);
}
for (const skillDir of skillDirs) {
const prefix = `skill:${path.basename(skillDir)}`;
const fragment = await evaluateSkill(skillDir, { prefix });
checks.push(...fragment.checks);
metrics.push(...fragment.metrics);
artifacts.push(...fragment.artifacts);
}
metrics.push(
createMetric({
id: "plugin_skill_count",
category: "manifest",
value: skillDirs.length,
unit: "skills",
band: skillDirs.length > 0 ? "good" : "moderate",
targetPath,
}),
createMetric({
id: "plugin_keyword_count",
category: "manifest",
value: Array.isArray(manifest.keywords) ? manifest.keywords.length : 0,
unit: "keywords",
band: Array.isArray(manifest.keywords) && manifest.keywords.length > 0 ? "good" : "info",
targetPath,
}),
createMetric({
id: "plugin_default_prompt_count",
category: "manifest",
value: Array.isArray(iface.defaultPrompt) ? iface.defaultPrompt.length : 0,
unit: "prompts",
band:
Array.isArray(iface.defaultPrompt) && iface.defaultPrompt.length <= 3
? "good"
: "moderate",
targetPath,
}),
);
artifacts.push(
createArtifact({
id: "plugin-skill-inventory",
type: "inventory",
label: "Plugin skills",
description: "Discoverable skills under the plugin.",
data: {
skills: skillDirs.map((skillDir) => relativePath(pluginRoot, skillDir)),
},
}),
);
return { checks, metrics, artifacts, manifest };
}