claude-everything-workflow 0.2.8 → 0.2.9
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/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +11 -18
- package/agents/e2e-runner.md +1 -1
- package/evals/routing-scenarios.json +253 -0
- package/harness/manifest.json +2 -28
- package/hooks/check-console-log.js +2 -2
- package/package.json +4 -2
- package/rules/01-base.md +2 -2
- package/rules/02-implementation.md +7 -6
- package/rules/05-git-workflow.md +4 -6
- package/rules/common/agent-orchestration.md +1 -1
- package/rules/common/pr-automation.md +1 -1
- package/rules/common/testing.md +2 -2
- package/scripts/eval-scenarios.js +106 -0
- package/scripts/install-rules.js +186 -17
- package/scripts/install.ps1 +42 -15
- package/scripts/install.sh +31 -12
- package/scripts/legacy-common-rule-hashes.json +4 -0
- package/scripts/retired-skill-files.json +7 -0
- package/scripts/verify/install-rules.test.js +80 -24
- package/scripts/verify/metadata-checks.js +7 -8
- package/scripts/verify/repository-checks.js +44 -368
- package/scripts/verify/scenario-checks.js +108 -0
- package/scripts/verify/scenario-checks.test.js +84 -0
- package/scripts/verify/workflow-checks.js +85 -586
- package/scripts/verify-harness.js +2 -0
- package/skills/README.md +2 -4
- package/skills/feature-acceptance/SKILL.md +8 -8
- package/skills/{e2e-testing/SKILL.md → feature-acceptance/references/e2e-testing.md} +3 -9
- package/skills/implement/SKILL.md +2 -0
- package/skills/{subagent-driven-development/SKILL.md → implement/references/parallel-delivery.md} +7 -9
- package/skills/implement/references/ticket-delivery.md +1 -1
- package/skills/using-superpowers/SKILL.md +24 -103
- package/rules/07-forbidden.md +0 -20
- package/rules/08-specialty-rules-index.md +0 -18
- package/rules/09-first-principles-adversarial-testing.md +0 -30
- package/scripts/verify/continuation-checks.test.js +0 -101
- package/scripts/verify/grilling-spec-gate-checks.js +0 -297
- package/scripts/verify/workflow-ownership-fixtures.js +0 -371
- package/scripts/verify/workflow-ownership.js +0 -780
- /package/skills/{e2e-testing → feature-acceptance}/references/playwright-patterns.md +0 -0
|
@@ -1,780 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const commonmark = require("commonmark");
|
|
4
|
-
const {
|
|
5
|
-
allowedFixtures,
|
|
6
|
-
rejectedFixtures,
|
|
7
|
-
repositoryScopeFixture,
|
|
8
|
-
} = require("./workflow-ownership-fixtures");
|
|
9
|
-
|
|
10
|
-
const markdownReader = new commonmark.Parser();
|
|
11
|
-
const HIDDEN_HTML_TAGS = new Set(["code", "pre", "script", "style", "template"]);
|
|
12
|
-
const ENGLISH_DELIVERY_ACTION =
|
|
13
|
-
"(?:publish(?:es|ed|ing)?|deploy(?:s|ed|ing)?|" +
|
|
14
|
-
"commit(?:s|ted|ting)?|merge(?:s|d|ing)?)";
|
|
15
|
-
const LOCAL_WORKFLOW_DIRECTIVE_PATTERNS = [
|
|
16
|
-
// Match ordered actions, not neutral statements that names are displayed in order.
|
|
17
|
-
new RegExp(
|
|
18
|
-
"(?:按顺序|依次|依序|先|随后|然后|接着|最后).{0,12}" +
|
|
19
|
-
"(?:执行|完成|处理|遵循|遵照|发布|部署|提交|合并)",
|
|
20
|
-
),
|
|
21
|
-
// Match local instructions that point back to a referenced workflow group.
|
|
22
|
-
/(?:执行|完成|遵循|遵照|按照|依照).{0,8}(?:上述|以上|前述|这些)(?:流程|步骤|门禁)?/,
|
|
23
|
-
new RegExp(
|
|
24
|
-
"(?:按|按照|依照|遵循|遵照)?" +
|
|
25
|
-
"(?:上述|以上|前述|这些)(?:流程|步骤|门禁).{0,8}" +
|
|
26
|
-
"(?:必须|需要|应当|应)?" +
|
|
27
|
-
"(?:执行|完成|遵循|遵照|操作|处理|落实|发布|部署|提交|合并)",
|
|
28
|
-
),
|
|
29
|
-
// Automatic delivery actions are local procedure even without an explicit step reference.
|
|
30
|
-
/(?:自动|自行).{0,8}(?:发布|部署|提交|合并)/,
|
|
31
|
-
/\b(?:execute|complete|follow)(?:\s+\w+){0,3}\s+in order\b/,
|
|
32
|
-
/\b(?:execute|complete|follow)(?:\s+\w+){0,4}\s+(?:above|these|previous|following)\s+(?:steps|workflow|gates)\b/,
|
|
33
|
-
/\b(?:execute|complete|follow)(?:\s+the)?\s+(?:steps|workflow|gates)\s+(?:above|previous|below)\b/,
|
|
34
|
-
new RegExp(
|
|
35
|
-
"\\b(?:above|these|previous|following)\\s+(?:steps|workflow|gates)" +
|
|
36
|
-
"(?:\\s+\\w+){0,4}\\s+" +
|
|
37
|
-
"(?:execute|executed|complete|completed|follow|followed|" +
|
|
38
|
-
"publish|published|deploy|deployed|commit|merge)\\b",
|
|
39
|
-
),
|
|
40
|
-
new RegExp(
|
|
41
|
-
"\\b(?:steps|workflow|gates)\\s+(?:above|previous|below)" +
|
|
42
|
-
"(?:\\s+\\w+){0,4}\\s+(?:executed|completed|followed|" +
|
|
43
|
-
`${ENGLISH_DELIVERY_ACTION})\\b`,
|
|
44
|
-
),
|
|
45
|
-
/\b(?:then|next|afterwards|finally)\s+(?:execute|complete|follow|publish|deploy|commit|merge)\b/,
|
|
46
|
-
new RegExp(
|
|
47
|
-
`\\b(?:automatically|auto)[-\\s]+(?:be\\s+)?${ENGLISH_DELIVERY_ACTION}\\b`,
|
|
48
|
-
),
|
|
49
|
-
new RegExp(`\\b${ENGLISH_DELIVERY_ACTION}\\s+automatically\\b`),
|
|
50
|
-
];
|
|
51
|
-
|
|
52
|
-
const WORKFLOW_DEFINITIONS = [
|
|
53
|
-
{
|
|
54
|
-
file: "rules/01-base.md",
|
|
55
|
-
label: "delivery Gate state machine",
|
|
56
|
-
authorityPath: "skills/using-superpowers/SKILL.md",
|
|
57
|
-
headings: ["开发流程", "最小闭环", "关键未知", "完整流程"],
|
|
58
|
-
signatureTokens: [
|
|
59
|
-
"Clarification Gate",
|
|
60
|
-
"User Review Gate",
|
|
61
|
-
"Ticket Gate",
|
|
62
|
-
"Red Test Gate",
|
|
63
|
-
"Task Review Gate",
|
|
64
|
-
"Verify Gate",
|
|
65
|
-
"PR Gate",
|
|
66
|
-
],
|
|
67
|
-
tokenAuthorityPaths: {
|
|
68
|
-
"Clarification Gate": ["skills/grilling/SKILL.md"],
|
|
69
|
-
"User Review Gate": ["skills/spec-gate/SKILL.md"],
|
|
70
|
-
"Ticket Gate": ["skills/to-tickets/SKILL.md"],
|
|
71
|
-
"Red Test Gate": ["skills/test-driven-development/SKILL.md"],
|
|
72
|
-
"Task Review Gate": ["skills/code-review/SKILL.md"],
|
|
73
|
-
"Verify Gate": ["commands/verify.md"],
|
|
74
|
-
"PR Gate": ["commands/pr.md"],
|
|
75
|
-
},
|
|
76
|
-
minimumSignatureMatches: 3,
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
file: "rules/common/testing.md",
|
|
80
|
-
label: "TDD state machine",
|
|
81
|
-
authorityPath: "skills/test-driven-development/SKILL.md",
|
|
82
|
-
headings: ["TDD 工作流"],
|
|
83
|
-
signatureTokens: [
|
|
84
|
-
"理解需求 -> 编写测试",
|
|
85
|
-
"运行测试 -> 确认失败",
|
|
86
|
-
"实现功能 -> 最小化实现",
|
|
87
|
-
"运行测试 -> 确认通过",
|
|
88
|
-
"重构代码 -> 保持测试通过",
|
|
89
|
-
],
|
|
90
|
-
detectionTokens: [
|
|
91
|
-
"理解需求",
|
|
92
|
-
"编写测试",
|
|
93
|
-
"运行测试",
|
|
94
|
-
"确认失败",
|
|
95
|
-
"实现功能",
|
|
96
|
-
"最小化实现",
|
|
97
|
-
"确认通过",
|
|
98
|
-
"重构代码",
|
|
99
|
-
"保持测试通过",
|
|
100
|
-
],
|
|
101
|
-
detectionMinimumMatches: 7,
|
|
102
|
-
minimumSignatureMatches: 3,
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
file: "rules/common/agent-orchestration.md",
|
|
106
|
-
label: "ticket and SDD execution procedure",
|
|
107
|
-
authorityPath: "skills/subagent-driven-development/SKILL.md",
|
|
108
|
-
headings: ["Tickets 先于跨会话执行"],
|
|
109
|
-
signatureTokens: [
|
|
110
|
-
"vertical slices",
|
|
111
|
-
"blocking edges",
|
|
112
|
-
"frontier ticket",
|
|
113
|
-
"fresh subagent",
|
|
114
|
-
"controller-owned integration worktree",
|
|
115
|
-
"联合验证后再 resolve",
|
|
116
|
-
],
|
|
117
|
-
tokenAuthorityPaths: {
|
|
118
|
-
"vertical slices": ["skills/to-tickets/SKILL.md"],
|
|
119
|
-
"blocking edges": ["skills/to-tickets/SKILL.md"],
|
|
120
|
-
"frontier ticket": ["skills/to-tickets/SKILL.md"],
|
|
121
|
-
},
|
|
122
|
-
minimumSignatureMatches: 3,
|
|
123
|
-
},
|
|
124
|
-
];
|
|
125
|
-
|
|
126
|
-
function htmlTagAt(value, start) {
|
|
127
|
-
if (value[start] !== "<") return null;
|
|
128
|
-
let cursor = start + 1;
|
|
129
|
-
let closing = false;
|
|
130
|
-
if (value[cursor] === "/") {
|
|
131
|
-
closing = true;
|
|
132
|
-
cursor += 1;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// HTML names start with ASCII letters; this excludes visible comparisons such as "a < b".
|
|
136
|
-
const nameMatch = value.slice(cursor).match(/^[A-Za-z][A-Za-z0-9:-]*/);
|
|
137
|
-
if (!nameMatch) return null;
|
|
138
|
-
const name = nameMatch[0].toLowerCase();
|
|
139
|
-
cursor += nameMatch[0].length;
|
|
140
|
-
|
|
141
|
-
let quote = "";
|
|
142
|
-
for (; cursor < value.length; cursor += 1) {
|
|
143
|
-
const character = value[cursor];
|
|
144
|
-
if (quote && character === quote) {
|
|
145
|
-
quote = "";
|
|
146
|
-
} else if (!quote && (character === '"' || character === "'")) {
|
|
147
|
-
quote = character;
|
|
148
|
-
} else if (!quote && character === ">") {
|
|
149
|
-
return { closing, end: cursor, name };
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function updateHiddenTagStack(stack, tag) {
|
|
156
|
-
const current = stack[stack.length - 1];
|
|
157
|
-
if (tag.closing) {
|
|
158
|
-
if (tag.name === current) stack.pop();
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
if (
|
|
162
|
-
HIDDEN_HTML_TAGS.has(tag.name) &&
|
|
163
|
-
(stack.length === 0 || current === "template")
|
|
164
|
-
) {
|
|
165
|
-
stack.push(tag.name);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function nodeText(node, includeLinkDestinations = true) {
|
|
170
|
-
let output = "";
|
|
171
|
-
const hiddenTags = [];
|
|
172
|
-
for (let child = node.firstChild; child; child = child.next) {
|
|
173
|
-
if (child.type === "html_inline") {
|
|
174
|
-
const tag = htmlTagAt(child.literal, 0);
|
|
175
|
-
if (tag) updateHiddenTagStack(hiddenTags, tag);
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
if (hiddenTags.length > 0) continue;
|
|
179
|
-
if (child.type === "text" || child.type === "code") {
|
|
180
|
-
output += child.literal;
|
|
181
|
-
} else if (child.type === "softbreak" || child.type === "linebreak") {
|
|
182
|
-
output += " ";
|
|
183
|
-
} else if (child.type === "link") {
|
|
184
|
-
output += nodeText(child, includeLinkDestinations);
|
|
185
|
-
if (includeLinkDestinations) output += ` ${child.destination || ""}`;
|
|
186
|
-
} else if (!child.type.startsWith("html") && child.type !== "code_block") {
|
|
187
|
-
output += nodeText(child, includeLinkDestinations);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return output;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function ancestorLists(node) {
|
|
194
|
-
let ancestor = node.parent;
|
|
195
|
-
const lists = [];
|
|
196
|
-
while (ancestor) {
|
|
197
|
-
if (ancestor.type === "list") lists.push(ancestor);
|
|
198
|
-
ancestor = ancestor.parent;
|
|
199
|
-
}
|
|
200
|
-
return lists;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function listReferenceContext(list) {
|
|
204
|
-
for (let previous = list?.prev; previous; previous = previous.prev) {
|
|
205
|
-
let content = "";
|
|
206
|
-
if (previous.type === "paragraph") content = nodeText(previous);
|
|
207
|
-
if (previous.type === "html_block") {
|
|
208
|
-
content = visibleHtmlText(previous.literal);
|
|
209
|
-
}
|
|
210
|
-
if (content.trim()) {
|
|
211
|
-
const [[startLine], [endLine]] = previous.sourcepos;
|
|
212
|
-
return { content, endLine, startLine };
|
|
213
|
-
}
|
|
214
|
-
if (!["paragraph", "html_block"].includes(previous.type)) return null;
|
|
215
|
-
}
|
|
216
|
-
return null;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
function stripHtmlTags(value) {
|
|
220
|
-
let output = "";
|
|
221
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
222
|
-
const tag = htmlTagAt(value, index);
|
|
223
|
-
if (tag) {
|
|
224
|
-
output += " ";
|
|
225
|
-
index = tag.end;
|
|
226
|
-
} else {
|
|
227
|
-
output += value[index];
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return output;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
function visibleHtmlSource(value) {
|
|
234
|
-
let output = "";
|
|
235
|
-
const hiddenTags = [];
|
|
236
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
237
|
-
if (value.startsWith("<!--", index)) {
|
|
238
|
-
const commentEnd = value.indexOf("-->", index + 4);
|
|
239
|
-
index = commentEnd < 0 ? value.length : commentEnd + 2;
|
|
240
|
-
continue;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const tag = htmlTagAt(value, index);
|
|
244
|
-
if (tag) {
|
|
245
|
-
const wasVisible = hiddenTags.length === 0;
|
|
246
|
-
updateHiddenTagStack(hiddenTags, tag);
|
|
247
|
-
if (wasVisible && hiddenTags.length === 0) {
|
|
248
|
-
output += value.slice(index, tag.end + 1);
|
|
249
|
-
}
|
|
250
|
-
index = tag.end;
|
|
251
|
-
} else if (hiddenTags.length === 0) {
|
|
252
|
-
output += value[index];
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return output;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
function decodeHtmlEntities(value) {
|
|
259
|
-
// Numeric HTML references may omit semicolons; CommonMark decodes their terminated form.
|
|
260
|
-
const numericDecoded = value.replace(
|
|
261
|
-
/&#(?:[xX][0-9A-Fa-f]+|\d+);?/g,
|
|
262
|
-
(entity) =>
|
|
263
|
-
nodeText(
|
|
264
|
-
markdownReader.parse(entity.endsWith(";") ? entity : `${entity};`),
|
|
265
|
-
false,
|
|
266
|
-
),
|
|
267
|
-
);
|
|
268
|
-
// Named references require semicolons here, matching CommonMark's strict entity grammar.
|
|
269
|
-
return numericDecoded.replace(/&[A-Za-z][A-Za-z0-9]+;/g, (entity) =>
|
|
270
|
-
nodeText(markdownReader.parse(entity), false),
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function visibleHtmlText(value) {
|
|
275
|
-
return decodeHtmlEntities(stripHtmlTags(visibleHtmlSource(value)));
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
function inlineHtmlSource(node) {
|
|
279
|
-
let output = "";
|
|
280
|
-
for (let child = node.firstChild; child; child = child.next) {
|
|
281
|
-
if (child.type === "html_inline") {
|
|
282
|
-
output += child.literal;
|
|
283
|
-
} else if (child.type === "text" || child.type === "code") {
|
|
284
|
-
output += child.literal.replaceAll("&", "&").replaceAll("<", "<");
|
|
285
|
-
} else if (child.type === "softbreak" || child.type === "linebreak") {
|
|
286
|
-
output += " ";
|
|
287
|
-
} else {
|
|
288
|
-
output += inlineHtmlSource(child);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
return output;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
function htmlHeadingTexts(value) {
|
|
295
|
-
const source = visibleHtmlSource(value);
|
|
296
|
-
const headings = [];
|
|
297
|
-
let activeHeading = null;
|
|
298
|
-
for (let index = 0; index < source.length; index += 1) {
|
|
299
|
-
const tag = htmlTagAt(source, index);
|
|
300
|
-
if (!tag) continue;
|
|
301
|
-
const isHeading =
|
|
302
|
-
tag.name.length === 2 &&
|
|
303
|
-
tag.name[0] === "h" &&
|
|
304
|
-
tag.name[1] >= "1" &&
|
|
305
|
-
tag.name[1] <= "6";
|
|
306
|
-
if (isHeading && !tag.closing && !activeHeading) {
|
|
307
|
-
activeHeading = { contentStart: tag.end + 1, name: tag.name };
|
|
308
|
-
} else if (tag.closing && tag.name === activeHeading?.name) {
|
|
309
|
-
const content = visibleHtmlText(
|
|
310
|
-
source.slice(activeHeading.contentStart, index),
|
|
311
|
-
).trim();
|
|
312
|
-
if (content) headings.push(content);
|
|
313
|
-
activeHeading = null;
|
|
314
|
-
}
|
|
315
|
-
index = tag.end;
|
|
316
|
-
}
|
|
317
|
-
if (activeHeading) {
|
|
318
|
-
const content = visibleHtmlText(source.slice(activeHeading.contentStart));
|
|
319
|
-
if (content.trim()) headings.push(content.trim());
|
|
320
|
-
}
|
|
321
|
-
return headings;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
function markdownPolicyStructure(body) {
|
|
325
|
-
const document = markdownReader.parse(body);
|
|
326
|
-
const headings = [];
|
|
327
|
-
const prose = [];
|
|
328
|
-
const listIds = new WeakMap();
|
|
329
|
-
let nextListId = 1;
|
|
330
|
-
const walker = document.walker();
|
|
331
|
-
let event;
|
|
332
|
-
while ((event = walker.next())) {
|
|
333
|
-
if (!event.entering) continue;
|
|
334
|
-
let content = "";
|
|
335
|
-
if (event.node.type === "heading") {
|
|
336
|
-
content = nodeText(event.node, false);
|
|
337
|
-
headings.push(content);
|
|
338
|
-
} else if (event.node.type === "html_block") {
|
|
339
|
-
headings.push(...htmlHeadingTexts(event.node.literal));
|
|
340
|
-
content = visibleHtmlText(event.node.literal);
|
|
341
|
-
} else if (event.node.type === "paragraph") {
|
|
342
|
-
content = nodeText(event.node);
|
|
343
|
-
headings.push(...htmlHeadingTexts(inlineHtmlSource(event.node)));
|
|
344
|
-
}
|
|
345
|
-
if (!content.trim()) continue;
|
|
346
|
-
const lists = ancestorLists(event.node);
|
|
347
|
-
const recordListIds = lists.map((list) => {
|
|
348
|
-
if (!listIds.has(list)) listIds.set(list, nextListId++);
|
|
349
|
-
return listIds.get(list);
|
|
350
|
-
});
|
|
351
|
-
const [[startLine], [endLine]] = event.node.sourcepos;
|
|
352
|
-
prose.push({
|
|
353
|
-
content,
|
|
354
|
-
endLine,
|
|
355
|
-
listId: recordListIds[0] ?? null,
|
|
356
|
-
listIds: recordListIds,
|
|
357
|
-
referenceContexts: lists
|
|
358
|
-
.map((list, index) => {
|
|
359
|
-
const reference = listReferenceContext(list);
|
|
360
|
-
if (!reference) return null;
|
|
361
|
-
return { ...reference, listId: recordListIds[index] };
|
|
362
|
-
})
|
|
363
|
-
.filter(Boolean),
|
|
364
|
-
startLine,
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
return { headings, prose };
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
function normalizeWorkflowText(value) {
|
|
371
|
-
return value
|
|
372
|
-
// Normalize ASCII and common Unicode arrows before comparing workflow signatures.
|
|
373
|
-
.replace(/\s*(?:->|[→⇒⟶])\s*/g, " -> ")
|
|
374
|
-
.trim()
|
|
375
|
-
// Markdown and decoded HTML may produce tabs, newlines, or non-breaking spaces.
|
|
376
|
-
.split(/\s+/)
|
|
377
|
-
.join(" ")
|
|
378
|
-
.toLowerCase();
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
function containsOwnedHeading(headings, definition) {
|
|
382
|
-
const normalized = new Set(headings.map(normalizeWorkflowText));
|
|
383
|
-
return definition.headings.some((heading) =>
|
|
384
|
-
normalized.has(normalizeWorkflowText(heading)),
|
|
385
|
-
);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
function neutralReferenceRemainder(
|
|
389
|
-
content,
|
|
390
|
-
definition,
|
|
391
|
-
normalizedTokens,
|
|
392
|
-
namesRequired = true,
|
|
393
|
-
) {
|
|
394
|
-
const line = normalizeWorkflowText(content);
|
|
395
|
-
const names = normalizedTokens.filter((token) => line.includes(token));
|
|
396
|
-
if (namesRequired && names.length === 0) return null;
|
|
397
|
-
let remainder = line;
|
|
398
|
-
for (const path of workflowAuthorityPaths(definition)) {
|
|
399
|
-
remainder = remainder.replaceAll(normalizeWorkflowText(path), "");
|
|
400
|
-
}
|
|
401
|
-
for (const token of names) remainder = remainder.replaceAll(token, "");
|
|
402
|
-
if (remainder.includes("->")) return remainder;
|
|
403
|
-
remainder = remainder.replace(/[\u2019']s\b/g, "");
|
|
404
|
-
// Only neutral citation vocabulary may remain after workflow names and the owner path are removed.
|
|
405
|
-
const neutralReferenceWords = new RegExp(
|
|
406
|
-
[
|
|
407
|
-
"详见", "参考", "权威来源", "权威", "为准", "名称", "术语", "流程",
|
|
408
|
-
"入口", "包括", "包含", "定义", "说明", "分别", "各自", "对应",
|
|
409
|
-
"相关", "均", "各", "下列", "本", "其", "的", "见", "以", "由", "及", "和",
|
|
410
|
-
].join("|"),
|
|
411
|
-
"g",
|
|
412
|
-
);
|
|
413
|
-
const neutralEnglishWords = new RegExp(
|
|
414
|
-
"\\b(?:see|refer|to|reference|authority|source|defined|definition|" +
|
|
415
|
-
"according|by|the|each|all|respectively|and|or|for|in|is|are|as)\\b",
|
|
416
|
-
"g",
|
|
417
|
-
);
|
|
418
|
-
remainder = remainder
|
|
419
|
-
.replace(neutralReferenceWords, "")
|
|
420
|
-
.replace(neutralEnglishWords, "")
|
|
421
|
-
// Punctuation and Markdown delimiters do not add local execution semantics.
|
|
422
|
-
.replace(/[\s,.;:,。;:、()[\]{}<>“”"'’`-]/g, "");
|
|
423
|
-
return remainder;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
function workflowAuthorityPaths(definition) {
|
|
427
|
-
const paths = new Set([definition.authorityPath]);
|
|
428
|
-
for (const tokenPaths of Object.values(definition.tokenAuthorityPaths ?? {})) {
|
|
429
|
-
for (const path of tokenPaths) paths.add(path);
|
|
430
|
-
}
|
|
431
|
-
return [...paths];
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
function authorityPathsForToken(definition, normalizedToken) {
|
|
435
|
-
const originalToken = definition.signatureTokens.find(
|
|
436
|
-
(token) => normalizeWorkflowText(token) === normalizedToken,
|
|
437
|
-
);
|
|
438
|
-
return [
|
|
439
|
-
definition.authorityPath,
|
|
440
|
-
...(definition.tokenAuthorityPaths?.[originalToken] ?? []),
|
|
441
|
-
];
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
function textOccurrences(line, values) {
|
|
445
|
-
const occurrences = [];
|
|
446
|
-
for (const value of values) {
|
|
447
|
-
const normalized = normalizeWorkflowText(value);
|
|
448
|
-
let offset = 0;
|
|
449
|
-
while (offset < line.length) {
|
|
450
|
-
const index = line.indexOf(normalized, offset);
|
|
451
|
-
if (index < 0) break;
|
|
452
|
-
occurrences.push({ index, value: normalized });
|
|
453
|
-
offset = index + normalized.length;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
return occurrences.sort((left, right) => left.index - right.index);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
function hasAuthoritiesForTokens(content, definition, normalizedTokens) {
|
|
460
|
-
const line = normalizeWorkflowText(content);
|
|
461
|
-
const names = textOccurrences(line, normalizedTokens);
|
|
462
|
-
if (names.length === 0) return false;
|
|
463
|
-
const paths = textOccurrences(line, workflowAuthorityPaths(definition));
|
|
464
|
-
if (paths.length === 0) return false;
|
|
465
|
-
const pathIsAllowed = (name, path) =>
|
|
466
|
-
authorityPathsForToken(definition, name.value)
|
|
467
|
-
.map(normalizeWorkflowText)
|
|
468
|
-
.includes(path.value);
|
|
469
|
-
if (paths.length === 1) {
|
|
470
|
-
return names.every((name) => pathIsAllowed(name, paths[0]));
|
|
471
|
-
}
|
|
472
|
-
if (paths.length !== names.length) return false;
|
|
473
|
-
return names.every((name, index) => pathIsAllowed(name, paths[index]));
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
function hasExplicitOwnerPath(content) {
|
|
477
|
-
return /(?:skills|commands|agents|rules)\/[\w./-]+\.md/i.test(content);
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
function withReferenceContext(content, referenceContent) {
|
|
481
|
-
if (hasExplicitOwnerPath(content)) return content;
|
|
482
|
-
return `${content} ${referenceContent}`.trim();
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
function hasCitationVocabulary(content) {
|
|
486
|
-
const normalized = normalizeWorkflowText(content);
|
|
487
|
-
return (
|
|
488
|
-
/见|详见|参考|为准|权威/.test(content) ||
|
|
489
|
-
/\b(?:see|refer(?:red)?\s+to|reference|authority|defined\s+by|according\s+to)\b/.test(
|
|
490
|
-
normalized,
|
|
491
|
-
)
|
|
492
|
-
);
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
function isNeutralReference(content, definition, normalizedTokens) {
|
|
496
|
-
if (!hasAuthoritiesForTokens(content, definition, normalizedTokens)) {
|
|
497
|
-
return false;
|
|
498
|
-
}
|
|
499
|
-
// Only explicit citation wording can turn workflow names into neutral references.
|
|
500
|
-
if (!hasCitationVocabulary(content)) return false;
|
|
501
|
-
return neutralReferenceRemainder(content, definition, normalizedTokens) === "";
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
function isNeutralContextIntro(content, definition) {
|
|
505
|
-
if (
|
|
506
|
-
!workflowAuthorityPaths(definition).some((path) => content.includes(path))
|
|
507
|
-
) {
|
|
508
|
-
return false;
|
|
509
|
-
}
|
|
510
|
-
// Context introductions use the same citation vocabulary but need no workflow signature name.
|
|
511
|
-
if (!hasCitationVocabulary(content)) return false;
|
|
512
|
-
return neutralReferenceRemainder(content, definition, [], false) === "";
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
function hasLocalWorkflowDirective(content) {
|
|
516
|
-
const normalized = normalizeWorkflowText(content);
|
|
517
|
-
return LOCAL_WORKFLOW_DIRECTIVE_PATTERNS.some((pattern) =>
|
|
518
|
-
pattern.test(normalized),
|
|
519
|
-
);
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
function adjacentRecords(groupRecords, records) {
|
|
523
|
-
const groupSet = new Set(groupRecords);
|
|
524
|
-
const firstLine = Math.min(...groupRecords.map((record) => record.startLine));
|
|
525
|
-
const lastLine = Math.max(...groupRecords.map((record) => record.endLine));
|
|
526
|
-
let previous = null;
|
|
527
|
-
let next = null;
|
|
528
|
-
for (const candidate of records) {
|
|
529
|
-
if (groupSet.has(candidate)) continue;
|
|
530
|
-
if (
|
|
531
|
-
candidate.endLine < firstLine &&
|
|
532
|
-
(!previous || candidate.endLine > previous.endLine)
|
|
533
|
-
) {
|
|
534
|
-
previous = candidate;
|
|
535
|
-
}
|
|
536
|
-
if (
|
|
537
|
-
candidate.startLine > lastLine &&
|
|
538
|
-
(!next || candidate.startLine < next.startLine)
|
|
539
|
-
) {
|
|
540
|
-
next = candidate;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
return { next, previous };
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
function extendAuthorityBoundaries(groupRecords, records, definition) {
|
|
547
|
-
const extended = [...groupRecords];
|
|
548
|
-
while (true) {
|
|
549
|
-
const { next, previous } = adjacentRecords(extended, records);
|
|
550
|
-
const neutralBoundaries = [previous, next].filter(
|
|
551
|
-
(candidate) =>
|
|
552
|
-
candidate && isNeutralContextIntro(candidate.content, definition),
|
|
553
|
-
);
|
|
554
|
-
if (neutralBoundaries.length === 0) return extended;
|
|
555
|
-
extended.push(...neutralBoundaries);
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
function hasAdjacentLocalDirective(groupRecords, records, definition) {
|
|
560
|
-
const extended = extendAuthorityBoundaries(
|
|
561
|
-
groupRecords,
|
|
562
|
-
records,
|
|
563
|
-
definition,
|
|
564
|
-
);
|
|
565
|
-
const { next, previous } = adjacentRecords(extended, records);
|
|
566
|
-
// A nearest visible block with execution wording changes citations into a local procedure.
|
|
567
|
-
return [previous, next].some(
|
|
568
|
-
(candidate) => candidate && hasLocalWorkflowDirective(candidate.content),
|
|
569
|
-
);
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
function listHasAdjacentDirective(
|
|
573
|
-
groupId,
|
|
574
|
-
records,
|
|
575
|
-
definition,
|
|
576
|
-
boundaryRecords = [],
|
|
577
|
-
) {
|
|
578
|
-
const groupRecords = [
|
|
579
|
-
...records.filter((record) => record.listIds.includes(groupId)),
|
|
580
|
-
...boundaryRecords,
|
|
581
|
-
];
|
|
582
|
-
return hasAdjacentLocalDirective(groupRecords, records, definition);
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
function independentReferenceGroup(record, records, definition, tokens) {
|
|
586
|
-
const recordIndex = records.indexOf(record);
|
|
587
|
-
let firstIndex = recordIndex;
|
|
588
|
-
let lastIndex = recordIndex;
|
|
589
|
-
const isReference = (candidate) => {
|
|
590
|
-
const normalized = normalizeWorkflowText(candidate.content);
|
|
591
|
-
const hasSignature = tokens.some((token) => normalized.includes(token));
|
|
592
|
-
return (
|
|
593
|
-
candidate.listId === null &&
|
|
594
|
-
hasSignature &&
|
|
595
|
-
hasCitationVocabulary(candidate.content)
|
|
596
|
-
);
|
|
597
|
-
};
|
|
598
|
-
while (firstIndex > 0 && isReference(records[firstIndex - 1])) {
|
|
599
|
-
firstIndex -= 1;
|
|
600
|
-
}
|
|
601
|
-
while (lastIndex + 1 < records.length && isReference(records[lastIndex + 1])) {
|
|
602
|
-
lastIndex += 1;
|
|
603
|
-
}
|
|
604
|
-
return records.slice(firstIndex, lastIndex + 1);
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
function independentReferencesUseOnlyCitations(
|
|
608
|
-
record,
|
|
609
|
-
records,
|
|
610
|
-
definition,
|
|
611
|
-
tokens,
|
|
612
|
-
) {
|
|
613
|
-
const group = independentReferenceGroup(record, records, definition, tokens);
|
|
614
|
-
return (
|
|
615
|
-
group.every((candidate) =>
|
|
616
|
-
isNeutralReference(candidate.content, definition, tokens),
|
|
617
|
-
) && !hasAdjacentLocalDirective(group, records, definition)
|
|
618
|
-
);
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
function listUsesOnlyDirectReferences(record, records, definition, tokens) {
|
|
622
|
-
return record.listIds.every((groupId) => {
|
|
623
|
-
if (listHasAdjacentDirective(groupId, records, definition)) return false;
|
|
624
|
-
return records
|
|
625
|
-
.filter((candidate) => candidate.listIds.includes(groupId))
|
|
626
|
-
.every((candidate) =>
|
|
627
|
-
isNeutralReference(candidate.content, definition, tokens),
|
|
628
|
-
);
|
|
629
|
-
});
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
function listUsesOnlyContextReferences(
|
|
633
|
-
record,
|
|
634
|
-
reference,
|
|
635
|
-
records,
|
|
636
|
-
definition,
|
|
637
|
-
tokens,
|
|
638
|
-
) {
|
|
639
|
-
const referenceIndex = record.listIds.indexOf(reference.listId);
|
|
640
|
-
if (referenceIndex < 0) return false;
|
|
641
|
-
const ancestorGroupIds = record.listIds.slice(referenceIndex);
|
|
642
|
-
return ancestorGroupIds.every((groupId) => {
|
|
643
|
-
if (listHasAdjacentDirective(groupId, records, definition, [reference])) {
|
|
644
|
-
return false;
|
|
645
|
-
}
|
|
646
|
-
return records
|
|
647
|
-
.filter((candidate) => candidate.listIds.includes(groupId))
|
|
648
|
-
.every((candidate) => {
|
|
649
|
-
const content = withReferenceContext(
|
|
650
|
-
candidate.content,
|
|
651
|
-
reference.content,
|
|
652
|
-
);
|
|
653
|
-
return (
|
|
654
|
-
isNeutralReference(content, definition, tokens) ||
|
|
655
|
-
isNeutralContextIntro(candidate.content, definition)
|
|
656
|
-
);
|
|
657
|
-
});
|
|
658
|
-
});
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
function isPureAuthorityReference(record, records, definition, tokens) {
|
|
662
|
-
if (isNeutralReference(record.content, definition, tokens)) {
|
|
663
|
-
const directReferencesArePure =
|
|
664
|
-
record.listId === null
|
|
665
|
-
? independentReferencesUseOnlyCitations(
|
|
666
|
-
record,
|
|
667
|
-
records,
|
|
668
|
-
definition,
|
|
669
|
-
tokens,
|
|
670
|
-
)
|
|
671
|
-
: listUsesOnlyDirectReferences(record, records, definition, tokens);
|
|
672
|
-
if (directReferencesArePure) {
|
|
673
|
-
return true;
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
for (const reference of record.referenceContexts) {
|
|
677
|
-
if (!isNeutralContextIntro(reference.content, definition)) continue;
|
|
678
|
-
const candidate = withReferenceContext(record.content, reference.content);
|
|
679
|
-
if (
|
|
680
|
-
isNeutralReference(candidate, definition, tokens) &&
|
|
681
|
-
listUsesOnlyContextReferences(
|
|
682
|
-
record,
|
|
683
|
-
reference,
|
|
684
|
-
records,
|
|
685
|
-
definition,
|
|
686
|
-
tokens,
|
|
687
|
-
)
|
|
688
|
-
) {
|
|
689
|
-
return true;
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
return false;
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
function containsOwnedSignatures(prose, definition) {
|
|
696
|
-
const matchedSignatures = new Set();
|
|
697
|
-
const matchedDetectionTokens = new Set();
|
|
698
|
-
const referenceTokens = definition.signatureTokens.map(normalizeWorkflowText);
|
|
699
|
-
const detectionTokens = (definition.detectionTokens ?? []).map(
|
|
700
|
-
normalizeWorkflowText,
|
|
701
|
-
);
|
|
702
|
-
for (const record of prose) {
|
|
703
|
-
const line = normalizeWorkflowText(record.content);
|
|
704
|
-
if (isPureAuthorityReference(record, prose, definition, referenceTokens)) {
|
|
705
|
-
continue;
|
|
706
|
-
}
|
|
707
|
-
for (const token of referenceTokens) {
|
|
708
|
-
if (line.includes(token)) matchedSignatures.add(token);
|
|
709
|
-
}
|
|
710
|
-
for (const token of detectionTokens) {
|
|
711
|
-
if (line.includes(token)) matchedDetectionTokens.add(token);
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
return (
|
|
715
|
-
matchedSignatures.size >= definition.minimumSignatureMatches ||
|
|
716
|
-
matchedDetectionTokens.size >= (definition.detectionMinimumMatches ?? Infinity)
|
|
717
|
-
);
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
function detectsWorkflowDefinition(body, definition) {
|
|
721
|
-
const { headings, prose } = markdownPolicyStructure(body);
|
|
722
|
-
return (
|
|
723
|
-
containsOwnedHeading(headings, definition) ||
|
|
724
|
-
containsOwnedSignatures(prose, definition)
|
|
725
|
-
);
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
function verifyDetectorFixtures(definition, fail) {
|
|
731
|
-
if (
|
|
732
|
-
allowedFixtures(definition).some((fixture) =>
|
|
733
|
-
detectsWorkflowDefinition(fixture, definition),
|
|
734
|
-
)
|
|
735
|
-
) {
|
|
736
|
-
fail(`workflow ownership detector must allow ${definition.label} references`);
|
|
737
|
-
}
|
|
738
|
-
if (
|
|
739
|
-
rejectedFixtures(definition).some((fixture) =>
|
|
740
|
-
!detectsWorkflowDefinition(fixture, definition),
|
|
741
|
-
)
|
|
742
|
-
) {
|
|
743
|
-
fail(`workflow ownership detector must reject copied ${definition.label}`);
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
function workflowCopyFiles(ruleFiles, read, definition) {
|
|
748
|
-
return ruleFiles.filter((file) =>
|
|
749
|
-
detectsWorkflowDefinition(read(file), definition),
|
|
750
|
-
);
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
function verifyRepositoryScopeFixture(definition, fail) {
|
|
754
|
-
const fixtureFile = "rules/common/unrelated.md";
|
|
755
|
-
const fixtureBody = repositoryScopeFixture(definition);
|
|
756
|
-
const copies = workflowCopyFiles([fixtureFile], () => fixtureBody, definition);
|
|
757
|
-
if (!copies.includes(fixtureFile)) {
|
|
758
|
-
fail(`workflow ownership detector must scan every Rule for ${definition.label}`);
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
/**
|
|
763
|
-
* Check that Rules reference workflow owners instead of copying their procedures.
|
|
764
|
-
* @param {object} context Harness file access and failure collector.
|
|
765
|
-
* @returns {void}
|
|
766
|
-
*/
|
|
767
|
-
function runWorkflowOwnershipChecks({ read, fail, managedFiles }) {
|
|
768
|
-
const ruleFiles = managedFiles().filter(
|
|
769
|
-
(file) => file.startsWith("rules/") && file.endsWith(".md"),
|
|
770
|
-
);
|
|
771
|
-
for (const definition of WORKFLOW_DEFINITIONS) {
|
|
772
|
-
verifyDetectorFixtures(definition, fail);
|
|
773
|
-
verifyRepositoryScopeFixture(definition, fail);
|
|
774
|
-
for (const file of workflowCopyFiles(ruleFiles, read, definition)) {
|
|
775
|
-
fail(`${file} must reference ${definition.label} rather than define it`);
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
module.exports = { runWorkflowOwnershipChecks };
|