{"record":{"id":"b8d7ebd28cd6d744","repo":"nexu-io/open-design","slug":"brand-json-not-found-in-the-extraction-project-t","errorCode":null,"errorMessage":"brand.json not found in the extraction project — the agent has not written the design system yet.","messagePattern":"brand\\.json not found in the extraction project — the agent has not written the design system yet\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/daemon/src/brands/index.ts","lineNumber":1338,"sourceCode":"\n/**\n * Finalize an agent-extracted brand: read `brand.json` (+ optional BRAND.md,\n * logos, fonts) the agent wrote into the backing project, validate it, derive\n * the deterministic brand-system artifacts, and register the `user:<id>`\n * design system. Marks the brand `ready`. Throws with a precise message when\n * the agent output is missing or invalid.\n */\nexport async function finalizeBrand(\n  opts: FinalizeBrandOptions,\n): Promise<BrandFinalizeResponse> {\n  const { id, brandsRoot, projectsRoot } = opts;\n  const meta = readMeta(brandsRoot, id);\n  if (!meta) throw new Error(`brand not found: ${id}`);\n  const projectId = opts.projectId ?? meta.projectId ?? brandProjectId(id);\n\n  const brandJsonRaw = await readProjectTextOrNull(projectsRoot, projectId, 'brand.json');\n  if (brandJsonRaw === null) {\n    throw new Error(\n      'brand.json not found in the extraction project — the agent has not written the design system yet.',\n    );\n  }\n  let parsed: unknown;\n  try {\n    parsed = JSON.parse(brandJsonRaw);\n  } catch {\n    const block = extractJsonBlock(brandJsonRaw);\n    if (block === null) throw new Error('brand.json is not valid JSON.');\n    parsed = block;\n  }\n  let brand: Brand;\n  try {\n    brand = validateBrand(parsed, meta.sourceUrl);\n  } catch (err) {\n    throw new Error(`brand.json failed validation: ${errorMessage(err)}`);\n  }\n","sourceCodeStart":1320,"sourceCodeEnd":1356,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/brands/index.ts#L1320-L1356","documentation":"Thrown by finalizeBrand when readProjectTextOrNull(projectsRoot, projectId, 'brand.json') returns null, meaning the backing project has no brand.json. finalizeBrand is meant to run after the extraction agent writes its output; this null result means the agent never wrote the file (still running, crashed, or never started).","triggerScenarios":"Calling finalize before the extraction agent reaches a terminal state; the agent errored mid-run without writing brand.json; the project was just created and the agent has not been dispatched yet.","commonSituations":"User clicks Finalize too early; the agent process was killed; an upstream provider error aborted the run before output was produced.","solutions":["Wait until the extraction run reaches a terminal status, then finalize.","Inspect the project run logs to see why the agent did not write brand.json, and re-run the extraction if it crashed.","If the agent is genuinely finished but produced no output, re-prompt or re-trigger the extraction."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const brandJsonRaw = await readProjectTextOrNull(projectsRoot, projectId, 'brand.json');\nif (brandJsonRaw === null) {\n  throw new ConflictError('Extraction is not finished yet — brand.json has not been written.');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await finalizeBrand(opts);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('agent has not written the design system yet')) {\n    return conflict('The extraction agent has not produced brand.json yet. Wait for it to finish, then retry.');\n  }\n  throw err;\n}","preventionTips":["Only call finalizeBrand after the extraction run reaches a terminal status.","Watch the run stream for completion or error events before enabling Finalize.","If the agent crashed, re-run the extraction rather than retrying finalize."],"tags":["brands","agent","lifecycle","finalize"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}