From 9dc244eb680c9c125a8064c4660468d65da345b3 Mon Sep 17 00:00:00 2001 From: Mikael Hugo Date: Mon, 11 May 2026 09:09:24 +0200 Subject: [PATCH] refactor: rf-10/rf-03 ask-gate wiring and skills frontmatter consolidation - rf-10: Wire gateAskUserQuestions (ask-gate.js) into ask-user-questions execute() via dynamic import; blocks autonomous ask_user_questions calls at tool layer - rf-03: Replace FRONTMATTER_RE + manual body extraction in skills/frontmatter.js with shared splitFrontmatter(); keep custom parseYaml() for skill-specific YAML handling Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/resources/extensions/ask-user-questions.js | 8 ++++++++ src/resources/extensions/sf/skills/frontmatter.js | 13 ++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/resources/extensions/ask-user-questions.js b/src/resources/extensions/ask-user-questions.js index 5756baf44..5f42783be 100644 --- a/src/resources/extensions/ask-user-questions.js +++ b/src/resources/extensions/ask-user-questions.js @@ -231,6 +231,14 @@ export default function AskUserQuestions(pi) { ], parameters: AskUserQuestionsParams, async execute(_toolCallId, params, signal, _onUpdate, ctx) { + // ── Autonomous mode gate ───────────────────────────────────────────── + const { gateAskUserQuestions } = await import( + "./sf/bootstrap/ask-gate.js" + ); + const gate = gateAskUserQuestions(params); + if (!gate.allow) { + return { content: [{ type: "text", text: gate.reason }] }; + } // ── Per-turn dedup: return cached result for identical question sets ── const sig = questionSignature(params.questions); const cached = turnCache.get(sig); diff --git a/src/resources/extensions/sf/skills/frontmatter.js b/src/resources/extensions/sf/skills/frontmatter.js index 7b7db12f2..14e88dae2 100644 --- a/src/resources/extensions/sf/skills/frontmatter.js +++ b/src/resources/extensions/sf/skills/frontmatter.js @@ -7,8 +7,7 @@ * * Consumer: skill loader, auto-skill creation, and permission gating. */ - -const FRONTMATTER_RE = /^---\s*\n([\s\S]*?)\n---\s*\n/; +import { splitFrontmatter } from "../../shared/frontmatter.js"; /** * Parse YAML frontmatter from skill markdown content. @@ -17,13 +16,9 @@ const FRONTMATTER_RE = /^---\s*\n([\s\S]*?)\n---\s*\n/; */ export function parseSkillFrontmatter(content) { if (!content) return null; - const match = content.match(FRONTMATTER_RE); - if (!match) return null; - - const yamlText = match[1]; - const body = content.slice(match[0].length); - - const frontmatter = parseYaml(yamlText); + const [fmLines, body] = splitFrontmatter(content); + if (!fmLines) return null; + const frontmatter = parseYaml(fmLines.join("\n")); return { frontmatter, body }; }