Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(check-resolvable): count a skills/ delegation with a #anchor after .md (#6704)

time-attack0bd84c1d6174
diff --git a/src/core/check-resolvable.ts b/src/core/check-resolvable.ts
index 7de9319cd7..eaa366c639 100644
--- a/src/core/check-resolvable.ts
+++ b/src/core/check-resolvable.ts
@@ -268,7 +268,8 @@ export interface DelegationRef {
* 1. `> **Convention:** ... \`skills/<path>\` ...`
* 2. `> **Filing rule:** ... \`skills/<path>\` ...`
* 3. Inline backtick `\`skills/conventions/*.md\`` or
- * `\`skills/_brain-filing-rules.md\``
+ * `\`skills/_brain-filing-rules.md\``, optionally followed by a
+ * `#anchor` (`\`skills/conventions/quality.md#citations\``)
*
* Paths are normalized by stripping the leading `skills/` so they match the
* `conventions` field of CROSS_CUTTING_PATTERNS.
@@ -277,8 +278,9 @@ export function extractDelegationTargets(content: string): DelegationRef[] {
const refs: DelegationRef[] = [];
const lines = content.split('\n');
// Match backtick-wrapped skills/ paths that point at a known delegation
- // target. Scoped to conventions/ subtree and _brain-filing-rules.md.
- const pathRe = /`skills\/((?:conventions\/[^`]+\.md)|(?:_brain-filing-rules\.md))`/g;
+ // target. Scoped to conventions/ subtree and _brain-filing-rules.md. An
+ // anchor after `.md` is dropped so the path matches `conventions`.
+ const pathRe = /`skills\/((?:conventions\/[^`#]+\.md)|(?:_brain-filing-rules\.md))(?:#[^`\s]*)?`/g;
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
pathRe.lastIndex = 0;
diff --git a/test/check-resolvable.test.ts b/test/check-resolvable.test.ts
index 1a7933a7ea..9027476756 100644
--- a/test/check-resolvable.test.ts
+++ b/test/check-resolvable.test.ts
@@ -352,6 +352,21 @@ describe("extractDelegationTargets", () => {
expect(refs).toEqual([{ convention: "conventions/quality.md", line: 2 }]);
});
+ test("accepts a #anchor after .md and drops it from the path (#6704)", () => {
+ const refs = extractDelegationTargets(
+ "See `skills/conventions/quality.md#citations` and `skills/_brain-filing-rules.md#the-rule`.\n"
+ );
+ expect(refs).toEqual([
+ { convention: "conventions/quality.md", line: 1 },
+ { convention: "_brain-filing-rules.md", line: 1 },
+ ]);
+ });
+
+ test("accepts an anchor with dots and non-ASCII letters (#6704)", () => {
+ const refs = extractDelegationTargets("See `skills/conventions/quality.md#v1.2-引用`.\n");
+ expect(refs).toEqual([{ convention: "conventions/quality.md", line: 1 }]);
+ });
+
test("ignores backticks pointing outside known delegation targets", () => {
const refs = extractDelegationTargets(
"See `skills/random/README.md` for unrelated notes.\n"