{"record":{"id":"a8db1bee4999b630","repo":"Yeachan-Heo/oh-my-codex","slug":"invalid-sandbox-md-frontmatter-section-currents","errorCode":null,"errorMessage":"Invalid sandbox.md frontmatter section: ${currentSection}","messagePattern":"Invalid sandbox\\.md frontmatter section: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/autoresearch/contracts.ts","lineNumber":122,"sourceCode":"      currentSection = sectionMatch[1];\n      result[currentSection] = {};\n      continue;\n    }\n\n    const nestedMatch = /^([A-Za-z0-9_-]+):\\s*(.+)\\s*$/.exec(trimmed);\n    if (!nestedMatch) {\n      throw contractError(`Unsupported sandbox.md frontmatter line: ${trimmed}`);\n    }\n\n    const [, key, rawValue] = nestedMatch;\n    const value = rawValue.replace(/^['\"]|['\"]$/g, '');\n    if (line.startsWith(' ') || line.startsWith('\\t')) {\n      if (!currentSection) {\n        throw contractError(`Nested sandbox.md frontmatter key requires a parent section: ${trimmed}`);\n      }\n      const section = result[currentSection];\n      if (!section || typeof section !== 'object' || Array.isArray(section)) {\n        throw contractError(`Invalid sandbox.md frontmatter section: ${currentSection}`);\n      }\n      (section as Record<string, unknown>)[key] = value;\n      continue;\n    }\n\n    result[key] = value;\n    currentSection = null;\n  }\n\n  return result;\n}\n\nfunction parseKeepPolicy(raw: unknown): AutoresearchKeepPolicy | undefined {\n  if (raw === undefined) return undefined;\n  if (typeof raw !== 'string') {\n    throw contractError('sandbox.md frontmatter evaluator.keep_policy must be a string when provided.');\n  }\n  const normalized = raw.trim().toLowerCase();","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/autoresearch/contracts.ts#L104-L140","documentation":"parseSimpleYamlFrontmatter throws when an indented key targets a currentSection that does not hold a plain object — i.e. the section name was previously assigned a scalar or an array. Since the parser stores top-level 'key: value' as strings, trying to nest under such a key (or under an array-valued entry) is invalid in its one-level model.","triggerScenarios":"Frontmatter like 'evaluator: something' followed by an indented '  command: x' — the section 'evaluator' is a string, not an object; or a section previously parsed as an array, so the (section as Record) cast guard fails.","commonSituations":"Writing 'evaluator: { ... }' inline then also adding nested keys; duplicating a key where the first occurrence set a scalar and a later indented key tries to nest under it.","solutions":["Make section headers bare ('evaluator:' with no inline value) before nested keys.","Remove duplicate keys that assign scalars to names used as sections.","Keep values either a flat scalar at top level or a one-level nested block — not both."],"exampleFix":"# before\nevaluator: run\nevaluator:\n  command: ./run.sh\n\n# after\nevaluator:\n  command: ./run.sh","handlingStrategy":"validation","validationCode":"function sectionsAreObjects(frontmatter: string): boolean {\n  const scalars = new Set<string>();\n  for (const line of frontmatter.split(/\\r?\\n/)) {\n    const m = /^([A-Za-z0-9_-]+):\\s*(.+)$/.exec(line);\n    if (m) scalars.add(m[1]);\n  }\n  for (const line of frontmatter.split(/\\r?\\n/)) {\n    if (/^[ \\t]/.test(line)) {\n      // the active section must not be in the scalar set — approximate check\n    }\n  }\n  return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n  parseSandboxContract(content);\n} catch (err) {\n  if ((err as Error).message.includes('Invalid sandbox.md frontmatter section')) {\n    // the message names the section; remove the scalar assignment for that key\n  }\n  throw err;\n}","preventionTips":["Write section headers as bare 'key:' with no inline value.","Do not duplicate keys between scalar and section roles.","Keep the evaluator block the only nested structure."],"tags":["yaml","frontmatter","sandbox-md","type-conflict"],"backgroundTag":"yaml-type-mismatch","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}