feat(plugin): custom SVG icons, market stats, submit link, and native locale scaffold (#170)
* feat(plugin): custom SVG icons, market stats, submit link, and native locale scaffold * chore(ci): allow spaces in PR model names and rename agent declaration to tool * fix(plugin): validate icon.svg size and markup during static scan
This commit is contained in:
33 files changed
+543
-72
No files matched your search
@@ -1,8 +1,11 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
const MODEL_LINE_RE = /^ {0,3}model:[ \t]+[\p{L}\p{N}][\p{L}\p{N}_.+() -]*\/[\p{L}\p{N}][\p{L}\p{N}_.+() -]*$/u;
|
||||
const TOOL_LINE_RE = /^ {0,3}(?:tool|agent):[ \t]+[\p{L}\p{N}][\p{L}\p{N}_.+() /-]*$/u;
|
||||
|
||||
export function missingDeclarations(body) {
|
||||
const missing = new Set(["model", "agent"]);
|
||||
const missing = new Set(["model", "tool"]);
|
||||
if (typeof body !== "string") return [...missing];
|
||||
let fence = null;
|
||||
for (const line of body.replace(/<!--[^]*?(?:-->|$)/g, "").split(/\r?\n/)) {
|
||||
@@ -11,10 +14,13 @@ export function missingDeclarations(body) {
|
||||
if (delimiter && delimiter[1][0] === fence[0] && delimiter[1].length >= fence.length && !delimiter[2].trim()) fence = null;
|
||||
} else if (delimiter) {
|
||||
fence = delimiter[1];
|
||||
} else if (/^ {0,3}model:[ \t]+[\p{L}\p{N}_.-]+\/[\p{L}\p{N}_.-]+[ \t]*$/u.test(line)) {
|
||||
missing.delete("model");
|
||||
} else if (/^ {0,3}agent:[ \t]+[\p{L}\p{N}][\p{L}\p{N}_.+() /-]*$/u.test(line.trimEnd())) {
|
||||
missing.delete("agent");
|
||||
} else {
|
||||
const trimmed = line.trimEnd();
|
||||
if (MODEL_LINE_RE.test(trimmed)) {
|
||||
missing.delete("model");
|
||||
} else if (TOOL_LINE_RE.test(trimmed)) {
|
||||
missing.delete("tool");
|
||||
}
|
||||
}
|
||||
if (missing.size === 0) break;
|
||||
}
|
||||
@@ -52,7 +58,7 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
|
||||
token: process.env.GITHUB_TOKEN,
|
||||
});
|
||||
if (result.status === "closed") {
|
||||
console.error(`::error::PR closed because its description is missing ${result.missing.join(" and ")}. Declare the actual model and agent used (format examples: model: deepseek/deepseek-R1 and agent: WorkBuddy).`);
|
||||
console.error(`::error::PR closed because its description is missing ${result.missing.join(" and ")}. Declare the actual model and coding tool used (format examples: model: deepseek/deepseek-R1 and tool: Cursor).`);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
}
|
||||
@@ -6,23 +6,29 @@ const declaration = "model: deepseek/deepseek-R1";
|
||||
const opened = { action: "opened", pull_request: { number: 42, base: { ref: "main" } } };
|
||||
const options = { apiUrl: "https://api.example.invalid", repository: "owner/repo", token: "test" };
|
||||
|
||||
test("requires visible model and agent declarations", () => {
|
||||
for (const agent of ["WorkBuddy", "豆包", "OpenAI Codex"]) {
|
||||
assert.deepEqual(missingDeclarations(`${declaration}\r\nagent: ${agent}`), []);
|
||||
test("requires visible model and coding tool declarations", () => {
|
||||
for (const model of ["deepseek/deepseek-R1", "google/Gemini 4 Neon", "anthropic/Claude 4.5 Sonnet"]) {
|
||||
for (const tool of ["tool: Cursor", "tool: WorkBuddy", "tool: 豆包", "tool: OpenAI Codex", "agent: WorkBuddy"]) {
|
||||
assert.deepEqual(missingDeclarations(`model: ${model}\r\n${tool}`), []);
|
||||
}
|
||||
}
|
||||
assert.deepEqual(missingDeclarations(declaration), ["agent"]);
|
||||
assert.deepEqual(missingDeclarations("agent: 豆包"), ["model"]);
|
||||
assert.deepEqual(missingDeclarations(`${declaration}\nagent: `), ["agent"]);
|
||||
assert.deepEqual(missingDeclarations(`${declaration}\n<!-- agent: WorkBuddy -->`), ["agent"]);
|
||||
assert.deepEqual(missingDeclarations("```\n" + declaration + "\nagent: 豆包\n```"), ["model", "agent"]);
|
||||
assert.deepEqual(missingDeclarations(null), ["model", "agent"]);
|
||||
assert.deepEqual(missingDeclarations(declaration), ["tool"]);
|
||||
assert.deepEqual(missingDeclarations("tool: 豆包"), ["model"]);
|
||||
assert.deepEqual(missingDeclarations("model: google/\ntool: Cursor"), ["model"]);
|
||||
assert.deepEqual(missingDeclarations("model: /gemini\ntool: Cursor"), ["model"]);
|
||||
assert.deepEqual(missingDeclarations("model: gemini\ntool: Cursor"), ["model"]);
|
||||
assert.deepEqual(missingDeclarations(`${declaration}\ntool: `), ["tool"]);
|
||||
assert.deepEqual(missingDeclarations(`${declaration}\n<!-- tool: WorkBuddy -->`), ["tool"]);
|
||||
assert.deepEqual(missingDeclarations("```\n" + declaration + "\ntool: 豆包\n```"), ["model", "tool"]);
|
||||
assert.deepEqual(missingDeclarations(null), ["model", "tool"]);
|
||||
});
|
||||
|
||||
test("closes a new PR when either declaration is missing from its current description", async () => {
|
||||
const cases = [
|
||||
["", ["model", "agent"]],
|
||||
[declaration, ["agent"]],
|
||||
["agent: 豆包", ["model"]],
|
||||
["", ["model", "tool"]],
|
||||
[declaration, ["tool"]],
|
||||
["tool: 豆包", ["model"]],
|
||||
[`${declaration}\ntool: WorkBuddy`, []],
|
||||
[`${declaration}\nagent: WorkBuddy`, []],
|
||||
];
|
||||
for (const [body, missing] of cases) {
|
||||
|
||||
Reference in new issue
Block a user