{"record":{"id":"660fab07e2dcf424","repo":"ruvnet/RuView","slug":"brain-line-index-1-error-message-660fab","errorCode":null,"errorMessage":"brain line ${index + 1}: ${error.message}","messagePattern":"brain line (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"harness/ruview/src/brain.js","lineNumber":49,"sourceCode":"    errors.push('source.path must be repository-relative without traversal');\n  }\n  if (!Array.isArray(record.tags) || record.tags.some((tag) => typeof tag !== 'string')) errors.push('tags must be strings');\n  if ((record.content || '').length > 8192) errors.push('content exceeds 8192 characters');\n  if ((record.title || '').length > 200) errors.push('title exceeds 200 characters');\n  if (canonical && record.reviewed !== true) errors.push('canonical records must be reviewed');\n  const combined = `${record.title || ''}\\n${record.content || ''}`;\n  if (SECRET.test(combined)) errors.push('record appears to contain a secret');\n  if (INJECTION.test(combined)) errors.push('record contains instruction-like prompt injection');\n  return errors;\n}\n\nexport function loadBrain(path = CORPUS_PATH) {\n  const raw = readFileSync(path, 'utf8').replace(/\\r\\n/g, '\\n');\n  if (Buffer.byteLength(raw) > 1_048_576) throw new Error('brain corpus exceeds 1 MiB');\n  const records = raw.split('\\n').filter(Boolean).map((line, index) => {\n    if (Buffer.byteLength(line) > 16_384) throw new Error(`brain line ${index + 1}: exceeds 16 KiB`);\n    let record;\n    try { record = JSON.parse(line); } catch (error) { throw new Error(`brain line ${index + 1}: ${error.message}`); }\n    const errors = validateBrainRecord(record, { canonical: true });\n    if (errors.length) throw new Error(`brain line ${index + 1}: ${errors.join('; ')}`);\n    return Object.freeze(record);\n  });\n  if (records.length > 1000) throw new Error('brain corpus exceeds 1000 records');\n  const ids = new Set();\n  for (const record of records) {\n    if (ids.has(record.id)) throw new Error(`duplicate brain id: ${record.id}`);\n    ids.add(record.id);\n  }\n  return { records, digest: sha256(raw), bytes: Buffer.byteLength(raw) };\n}\n\nfunction terms(value) {\n  return new Set(String(value).toLowerCase().match(/[a-z0-9][a-z0-9_-]{1,}/g) || []);\n}\n\nexport function searchBrain(query, { limit = 8, path = CORPUS_PATH } = {}) {","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/harness/ruview/src/brain.js#L31-L67","documentation":"Every non-empty line of the brain corpus must parse via JSON.parse; the underlying parse error message is included alongside the 1-based line number. Empty lines are skipped (filter(Boolean)), but whitespace-only lines are not filtered and also fail parsing.","triggerScenarios":"Hand-edited JSONL with trailing commas, single or smart quotes, an object split across two lines, a whitespace-only line, or a UTF-8 BOM at the start of the file.","commonSituations":"Editor auto-formatting that rewraps JSON, merge conflicts inside the corpus, copy-paste from rendered documentation.","solutions":["Read the line number and parser reason in the message and fix that exact line","Remove whitespace-only lines and any BOM","Generate records with 'brain propose' or jq -c instead of editing by hand"],"exampleFix":"// before (line 7)\n{\"id\": \"lesson\", }\n\n// after\n{\"id\": \"lesson\"}","handlingStrategy":"validation","validationCode":"import { readFileSync } from 'node:fs';\nfunction invalidJsonLines(path) {\n  const bad = [];\n  readFileSync(path, 'utf8').split('\\n').forEach((line, i) => {\n    if (!line.trim()) return;\n    try { JSON.parse(line); } catch { bad.push(i + 1); }\n  });\n  return bad;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const brain = loadBrain(path);\n} catch (error) {\n  if (error.message.startsWith('brain line')) {\n    console.error(`corpus parse failure: ${error.message}`);\n    process.exit(1);\n  }\n  throw error;\n}","preventionTips":["Write records programmatically (jq -c or brain propose), never by hand in a formatting editor","Strip whitespace-only lines and BOMs when editing the corpus","Run a per-line JSON.parse lint in CI before loadBrain ever executes"],"tags":["validation","json","jsonl","brain","ruview"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}