@uinaf/agent-plugin-stuff 2.0.0 → 2.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/dist/rules.js +49 -14
- package/package.json +1 -1
package/dist/rules.js
CHANGED
|
@@ -7,6 +7,11 @@ const ALLOWED_MDC_KEYS = /* @__PURE__ */ new Set([
|
|
|
7
7
|
"globs",
|
|
8
8
|
"trigger"
|
|
9
9
|
]);
|
|
10
|
+
const ALLOWED_MD_KEYS = /* @__PURE__ */ new Set([
|
|
11
|
+
"description",
|
|
12
|
+
"globs",
|
|
13
|
+
"trigger"
|
|
14
|
+
]);
|
|
10
15
|
const ALLOWED_TRIGGERS = /* @__PURE__ */ new Set([
|
|
11
16
|
"always_on",
|
|
12
17
|
"model_decision",
|
|
@@ -25,7 +30,7 @@ function checkRelativeLinks(body, dir, label, errors) {
|
|
|
25
30
|
if (!fs.existsSync(resolved)) errors.push(`${label}: link target does not exist: ${target}`);
|
|
26
31
|
}
|
|
27
32
|
}
|
|
28
|
-
function
|
|
33
|
+
function parseFrontmatter(text, label, allowedKeys, errors) {
|
|
29
34
|
const lines = text.split("\n");
|
|
30
35
|
if (lines[0] !== "---") {
|
|
31
36
|
errors.push(`${label}: frontmatter must open with --- on line 1`);
|
|
@@ -44,7 +49,7 @@ function parseMdc(text, label, errors) {
|
|
|
44
49
|
continue;
|
|
45
50
|
}
|
|
46
51
|
const [, key, raw] = m;
|
|
47
|
-
if (!
|
|
52
|
+
if (!allowedKeys.has(key)) {
|
|
48
53
|
errors.push(`${label}: unknown frontmatter key: ${key}`);
|
|
49
54
|
continue;
|
|
50
55
|
}
|
|
@@ -58,21 +63,43 @@ function parseMdc(text, label, errors) {
|
|
|
58
63
|
value
|
|
59
64
|
});
|
|
60
65
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
return {
|
|
67
|
+
fields,
|
|
68
|
+
body: lines.slice(close + 1).join("\n")
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function checkSharedFields(fields, label, errors) {
|
|
64
72
|
const description = fields.get("description");
|
|
65
73
|
if (description !== void 0 && description.value === "") errors.push(`${label}: description must be non-empty`);
|
|
66
74
|
const globs = fields.get("globs");
|
|
67
75
|
if (globs !== void 0 && globs.value === "") errors.push(`${label}: globs must be non-empty`);
|
|
68
76
|
const trigger = fields.get("trigger");
|
|
69
77
|
if (trigger !== void 0 && !ALLOWED_TRIGGERS.has(trigger.value)) errors.push(`${label}: invalid trigger: ${JSON.stringify(trigger.value)}`);
|
|
78
|
+
}
|
|
79
|
+
function parseMd(text, label, errors) {
|
|
80
|
+
const parsed = parseFrontmatter(text, label, ALLOWED_MD_KEYS, errors);
|
|
81
|
+
if (parsed === void 0) return;
|
|
82
|
+
const { fields } = parsed;
|
|
83
|
+
checkSharedFields(fields, label, errors);
|
|
84
|
+
const trigger = fields.get("trigger")?.value;
|
|
85
|
+
if (trigger === void 0) errors.push(`${label}: trigger is required when a .md rule has frontmatter`);
|
|
86
|
+
if (trigger === "model_decision" && !fields.get("description")?.value) errors.push(`${label}: description is required when trigger is model_decision`);
|
|
87
|
+
if (trigger === "glob" && !fields.get("globs")?.value) errors.push(`${label}: globs is required when trigger is glob`);
|
|
88
|
+
return parsed;
|
|
89
|
+
}
|
|
90
|
+
function parseMdc(text, label, errors) {
|
|
91
|
+
const parsed = parseFrontmatter(text, label, ALLOWED_MDC_KEYS, errors);
|
|
92
|
+
if (parsed === void 0) return;
|
|
93
|
+
const { fields } = parsed;
|
|
94
|
+
checkSharedFields(fields, label, errors);
|
|
95
|
+
const alwaysApply = fields.get("alwaysApply");
|
|
96
|
+
if (alwaysApply === void 0) errors.push(`${label}: alwaysApply is required (true or false)`);
|
|
97
|
+
else if (alwaysApply.raw !== "true" && alwaysApply.raw !== "false") errors.push(`${label}: alwaysApply must be true or false, got ${JSON.stringify(alwaysApply.raw)}`);
|
|
98
|
+
const description = fields.get("description");
|
|
99
|
+
const globs = fields.get("globs");
|
|
70
100
|
if (alwaysApply?.raw === "true" && !description?.value) errors.push(`${label}: description is required when alwaysApply is true`);
|
|
71
101
|
if (alwaysApply?.raw === "false" && !description?.value && !globs?.value) errors.push(`${label}: description or globs is required when alwaysApply is false`);
|
|
72
|
-
return
|
|
73
|
-
fields,
|
|
74
|
-
body: lines.slice(close + 1).join("\n")
|
|
75
|
-
};
|
|
102
|
+
return parsed;
|
|
76
103
|
}
|
|
77
104
|
function resolveDeclaredRulePaths(rawRules, root, manifestLabel, errors) {
|
|
78
105
|
if (typeof rawRules === "string") {
|
|
@@ -136,15 +163,21 @@ function lintRules(root) {
|
|
|
136
163
|
const mdSet = new Set(mdNames);
|
|
137
164
|
const mdcSet = new Set(mdcNames);
|
|
138
165
|
const mdBodies = /* @__PURE__ */ new Map();
|
|
166
|
+
const mdDescriptions = /* @__PURE__ */ new Map();
|
|
139
167
|
for (const name of mdNames) {
|
|
140
168
|
const file = path.join(rulesDir, `${name}.md`);
|
|
141
169
|
const label = path.relative(root, file).replaceAll("\\", "/");
|
|
142
170
|
const text = normalizeText(fs.readFileSync(file, "utf8"));
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
171
|
+
const hasFrontmatter = text === "---" || text.startsWith("---\n");
|
|
172
|
+
const parsed = hasFrontmatter ? parseMd(text, label, errors) : void 0;
|
|
173
|
+
const body = hasFrontmatter ? parsed?.body ?? "" : text;
|
|
174
|
+
const trimmed = body.trim();
|
|
175
|
+
if (trimmed === "") errors.push(`${label}: rule ${hasFrontmatter ? "body" : "file"} is empty`);
|
|
176
|
+
else checkRelativeLinks(body, rulesDir, label, errors);
|
|
177
|
+
if (!hasFrontmatter || parsed !== void 0) {
|
|
178
|
+
mdBodies.set(name, trimmed);
|
|
179
|
+
mdDescriptions.set(name, parsed?.fields.get("description")?.value);
|
|
180
|
+
}
|
|
148
181
|
if (hasCursorManifest && !mdcSet.has(name)) errors.push(`${label}: missing Cursor copy rules/${name}.mdc`);
|
|
149
182
|
}
|
|
150
183
|
for (const name of mdcNames) {
|
|
@@ -157,6 +190,8 @@ function lintRules(root) {
|
|
|
157
190
|
else if (!mdSet.has(name)) checkRelativeLinks(parsed.body, rulesDir, label, errors);
|
|
158
191
|
const mdBody = mdBodies.get(name);
|
|
159
192
|
if (mdBody !== void 0 && bodyTrimmed !== mdBody) errors.push(`${label}: body differs from rules/${name}.md`);
|
|
193
|
+
const mdDescription = mdDescriptions.get(name);
|
|
194
|
+
if (mdDescription !== void 0 && mdDescription !== parsed.fields.get("description")?.value) errors.push(`${label}: description differs from rules/${name}.md`);
|
|
160
195
|
}
|
|
161
196
|
if (hasCursorManifest) {
|
|
162
197
|
const manifestLabel = ".cursor-plugin/plugin.json";
|
package/package.json
CHANGED