| 213 | } |
| 214 | |
| 215 | function validateBlock(blockRecord) { |
| 216 | const issues = []; |
| 217 | for (const key of ['id', 'type', 'scope', 'owner', 'confidence', 'last_verified', 'sources', 'body']) { |
| 218 | if (blockRecord[key] === undefined || blockRecord[key] === null || blockRecord[key] === '') issues.push(`missing ${key}`); |
| 219 | } |
| 220 | if (!BLOCK_TYPES.includes(blockRecord.type)) issues.push(`unknown type ${blockRecord.type}`); |
| 221 | if (!Array.isArray(blockRecord.scope) || blockRecord.scope.length === 0) issues.push('scope must be a non-empty array'); |
| 222 | if (!Array.isArray(blockRecord.sources) || blockRecord.sources.length === 0) issues.push('sources must be a non-empty array'); |
| 223 | return issues; |
| 224 | } |
| 225 | |
| 226 | function writeBlock(projectRoot, blockRecord) { |
| 227 | fs.mkdirSync(blocksDir(projectRoot), { recursive: true }); |