Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
revert(markdown): drop alias-specific refusal guidance (PR 4b frontmatter_alias_limit owns it); keep the js-yaml load source scan (GBRA-133 PR 1)
garrytan63dfd3a5567e
diff --git a/src/core/markdown.ts b/src/core/markdown.tsindex 2fb5d55af2..9c3b78eb80 100644--- a/src/core/markdown.ts+++ b/src/core/markdown.ts@@ -533,14 +533,10 @@ const HOLD_GUIDANCE: Record<InvalidFrontmatterReason, string> = {ambiguous_protected_key: 'gbrain never guesses who may read a page or where it came from. Write that key on its own line with one quoted value, then import it again.',};-/** S-47: the alias-bound refusal (data-frontmatter.ts YamlAliasBoundError) needs its own advice; quoting a value does not shrink an alias. */-const ALIAS_BOUND_GUIDANCE = 'Replace the anchors (&name) and aliases (*name) in that block with plain values, then import it again.';-const ALIAS_BOUND_CAUSE = /aliases expand past the frontmatter size limit/;-const HOLD_MESSAGE = new RegExp(`^Invalid YAML frontmatter: (?:ambiguous (?:protected|identity) key(?: "[\\w-]{1,100}")? at line \\d+`+ `|key(?: "[\\w-]{1,100}")? at line \\d+ (?:continues on unquoted lines|appears more than once|opens \\[ or \\{ without closing it)`+ `|[a-z ;,'-]{1,200}(?: at line \\d+(?:, column \\d+)?)?(?: \\(key "[\\w-]{1,100}"\\))?)\\. `- + `(?:${[...Object.values(HOLD_GUIDANCE), ALIAS_BOUND_GUIDANCE].map(text => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|')})$`);+ + `(?:${Object.values(HOLD_GUIDANCE).map(text => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|')})$`);/** True for a frontmatter hold message exactly as `classifyImportHold` builds it: key, line and cause only, safe to show. */export function isFrontmatterHoldMessage(message: string | null | undefined): boolean {@@ -583,7 +579,7 @@ export function classifyImportHold(parsed: ParsedMarkdown, ctx: {: reason === 'needs_interpretation' ? `key "${key}"${where} ${step!.kind === 'dup' ? 'appears more than once' : step!.kind === 'fold' ? 'continues on unquoted lines' : 'opens [ or { without closing it'}`: `${(yaml?.message ?? '').replace(/^YAML parse failed:\s*/, '') || 'malformed YAML'}${key ? ` (key "${key}")` : ''}`;return { code: 'invalid_frontmatter', reason, ...(key ? { key } : {}), ...(line !== undefined ? { line } : {}),- message: `Invalid YAML frontmatter: ${detail}. ${reason === 'yaml_parse' && ALIAS_BOUND_CAUSE.test(yaml?.message ?? '') ? ALIAS_BOUND_GUIDANCE : HOLD_GUIDANCE[reason]}` };+ message: `Invalid YAML frontmatter: ${detail}. ${HOLD_GUIDANCE[reason]}` };}const expected = ctx.expectedSlug;if (expected && parsed.slug !== expected && slugifyPath(parsed.slug) !== expected && !ctx.slugExempt?.(parsed.slug)) {diff --git a/test/yaml-load-bounded-only.test.ts b/test/yaml-load-bounded-only.test.tsindex 132a76ed78..e799a08c8b 100644--- a/test/yaml-load-bounded-only.test.ts+++ b/test/yaml-load-bounded-only.test.ts@@ -1,13 +1,11 @@/**- * GBRA-133 PR 1 (PR 0 follow-ups): js-yaml's `load` is unbounded on aliases, so+ * GBRA-133 PR 1 (PR 0 follow-up): js-yaml's `load` is unbounded on aliases, so* src/core/data-frontmatter.ts (loadBoundedYaml) is the only module that may- * import it; and the alias-bound refusal advises removing anchors and aliases,- * not quoting a value.+ * import it.*/import { describe, expect, test } from 'bun:test';import { readdirSync, readFileSync } from 'node:fs';import { join, relative } from 'node:path';-import { classifyImportHold, isFrontmatterHoldMessage, parseMarkdown } from '../src/core/markdown.ts';const ROOT = join(import.meta.dir, '..');const SRC = join(ROOT, 'src');@@ -55,28 +53,3 @@ describe('js-yaml load is imported only by data-frontmatter.ts', () => {expect(yamlLoadImports("import { dump, type Schema } from 'js-yaml';")).toEqual([]);});});--describe('S-47 alias-bound refusal guidance', () => {- const bomb = (levels: number) => {- const lines = ['a0: &a0 [x, x, x, x, x, x, x, x, x]'];- for (let level = 1; level <= levels; level++) lines.push(`a${level}: &a${level} [${Array(9).fill(`*a${level - 1}`).join(', ')}]`);- return lines.join('\n');- };-- test('names anchors and aliases, never the quote-a-value advice, and stays a well-formed hold message', () => {- const content = `---\ntitle: Bomb note\ntype: note\n${bomb(6)}\n---\nBody.\n`;- const hold = classifyImportHold(parseMarkdown(content, 'notes/bomb.md', { validate: true }));- expect(hold).toMatchObject({ code: 'invalid_frontmatter', reason: 'yaml_parse' });- expect(hold!.message).toContain('Replace the anchors (&name) and aliases (*name) in that block with plain values');- expect(hold!.message).not.toContain('quote a value');- expect(isFrontmatterHoldMessage(hold!.message)).toBe(true);- });-- test('an ordinary YAML error keeps the quote-a-value advice', () => {- const hold = classifyImportHold(parseMarkdown('---\ntitle: x\n\tbad: tab\ntype: note\n---\nBody.\n', 'notes/broken.md', { validate: true }));- expect(hold).toMatchObject({ code: 'invalid_frontmatter', reason: 'yaml_parse' });- expect(hold!.message).toContain('quote a value');- expect(hold!.message).not.toContain('anchors (&name)');- expect(isFrontmatterHoldMessage(hold!.message)).toBe(true);- });-});