diff --git a/src/resources/extensions/sf/commands/handlers/core.js b/src/resources/extensions/sf/commands/handlers/core.js index 66a556b3c..8fdda0d4e 100644 --- a/src/resources/extensions/sf/commands/handlers/core.js +++ b/src/resources/extensions/sf/commands/handlers/core.js @@ -958,11 +958,19 @@ async function handleDiffCommand(args, ctx) { // ─── /theme ───────────────────────────────────────────────────────────────── +function extractBodyAfterFrontmatterLocal(content) { + const closingIdx = content.indexOf("\n---", content.indexOf("---")); + if (closingIdx === -1) return null; + const afterFrontmatter = content.slice(closingIdx + 4); + return afterFrontmatter.trim() ? afterFrontmatter : null; +} + async function handleThemeCommand(args, ctx) { const THEMES = ["dark", "light", "dim", "auto"]; const { loadEffectiveSFPreferences } = await import("../../preferences.js"); - const { extractBodyAfterFrontmatter, serializePreferencesToFrontmatter } = - await import("../../commands-prefs-wizard.js"); + const { serializePreferencesToFrontmatter } = await import( + "../../commands-prefs-wizard.js" + ); const { readFileSync, writeFileSync, existsSync } = await import("node:fs"); if (!args) { @@ -990,7 +998,9 @@ async function handleThemeCommand(args, ctx) { let body = "\n# SF Preferences\n\nSee `~/.sf/agent/extensions/sf/docs/preferences-reference.md` for full documentation.\n"; if (existsSync(path)) { - const preserved = extractBodyAfterFrontmatter(readFileSync(path, "utf-8")); + const preserved = extractBodyAfterFrontmatterLocal( + readFileSync(path, "utf-8"), + ); if (preserved) body = preserved; } const { mkdirSync } = await import("node:fs"); diff --git a/src/resources/extensions/sf/experimental.js b/src/resources/extensions/sf/experimental.js index 78f82b8dd..b254d1c58 100644 --- a/src/resources/extensions/sf/experimental.js +++ b/src/resources/extensions/sf/experimental.js @@ -10,16 +10,21 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; import { dirname } from "node:path"; -import { - extractBodyAfterFrontmatter, - serializePreferencesToFrontmatter, -} from "./commands-prefs-wizard.js"; +import { serializePreferencesToFrontmatter } from "./commands-prefs-wizard.js"; import { getProjectSFPreferencesPath, loadEffectiveSFPreferences, loadProjectSFPreferences, } from "./preferences.js"; +/** Extract the body section that follows a YAML frontmatter block. */ +function extractBodyAfterFrontmatter(content) { + const closingIdx = content.indexOf("\n---", content.indexOf("---")); + if (closingIdx === -1) return null; + const afterFrontmatter = content.slice(closingIdx + 4); + return afterFrontmatter.trim() ? afterFrontmatter : null; +} + /** All recognized experimental feature flags with descriptions. */ export const EXPERIMENTAL_FLAGS = { status_line: