MCPcopy Create free account
hub / github.com/SethGammon/Citadel / parseFrontmatter

Function parseFrontmatter

scripts/codex-compat.js:77–108  ·  view source on GitHub ↗
(content)

Source from the content-addressed store, hash-verified

75 "const { spawnSync } = require('child_process');\n" +
76 "const fs = require('fs');\n" +
77 "const path = require('path');\n" +
78 "const pluginRoot = fs.readFileSync(path.join(__dirname, '..', 'plugin-root.txt'), 'utf8').trim();\n" +
79 "const real = path.join(pluginRoot, 'scripts', " + JSON.stringify(scriptName) + ");\n" +
80 "const r = spawnSync(process.execPath, [real, ...process.argv.slice(2)], { stdio: 'inherit', env: process.env });\n" +
81 "process.exit(r.status === null ? 1 : r.status);\n"
82 );
83}
84
85function readJSON(filePath) {
86 try {
87 return JSON.parse(fs.readFileSync(filePath, 'utf8'));
88 } catch {
89 return null;
90 }
91}
92
93function parseFrontmatter(content) {
94 // Normalize line endings to \n for consistent parsing
95 const normalized = content.replace(/\r\n/g, '\n');
96 const match = normalized.match(/^---\n([\s\S]*?)\n---/);
97 if (!match) return {};
98 const fm = {};
99 for (const line of match[1].split('\n')) {
100 // Skip YAML list items (lines starting with -)
101 if (line.trim().startsWith('-')) continue;
102 const colonIdx = line.indexOf(':');
103 if (colonIdx === -1) continue;
104 const key = line.slice(0, colonIdx).trim();
105 // Skip indented keys (nested YAML)
106 if (line.match(/^\s+\w/)) continue;
107 let val = line.slice(colonIdx + 1).trim();
108 // Strip YAML quotes
109 if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
110 val = val.slice(1, -1);
111 }

Callers 2

translateAgentsFunction · 0.70
syncSkillsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected