{"version":3,"sources":["../src/docker/ensureDemoProjectDirs.ts"],"sourcesContent":["// Walk a Claude projects tree (…/.claude/projects/**/*.jsonl), collect every\n// unique `cwd` value, and mkdir -p each one. Demo seed JSONLs reference paths\n// like /home/demo/projects/threadbase-mobile; when PTYManager resumes a\n// session it chdirs there, and a missing directory fails the spawn with\n// \"chdir(2) failed\". Deriving the list from the corpus removes the hardcoded\n// mkdir block in entrypoint.sh that drifted whenever a new seed was added.\n//\n// Compiled by tsup to dist/ensure-demo-project-dirs.cjs.\nimport { mkdirSync, readdirSync, readFileSync, statSync } from \"node:fs\";\nimport { isAbsolute, join } from \"node:path\";\n\n/** Recursively list *.jsonl files under `root`. */\nexport function listJsonlFiles(root: string): string[] {\n  const out: string[] = [];\n  const stack: string[] = [root];\n  while (stack.length > 0) {\n    const dir = stack.pop();\n    if (dir === undefined) break;\n    let entries: string[];\n    try {\n      entries = readdirSync(dir);\n    } catch (err) {\n      if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return out;\n      throw err;\n    }\n    for (const name of entries) {\n      const full = join(dir, name);\n      try {\n        const st = statSync(full);\n        if (st.isDirectory()) stack.push(full);\n        else if (st.isFile() && name.endsWith(\".jsonl\")) out.push(full);\n      } catch {\n        // Skip unreadable entries (races / permissions).\n      }\n    }\n  }\n  return out;\n}\n\n/**\n * Parse JSONL files under `projectsRoot` and return sorted unique absolute\n * `cwd` strings. Malformed lines and missing `cwd` are skipped.\n */\nexport function extractDemoCwds(projectsRoot: string): string[] {\n  const cwds = new Set<string>();\n  for (const file of listJsonlFiles(projectsRoot)) {\n    const text = readFileSync(file, \"utf8\");\n    for (const line of text.split(\"\\n\")) {\n      if (!line.trim()) continue;\n      try {\n        const obj = JSON.parse(line) as { cwd?: unknown };\n        // Absolute-only, to skip relative or garbage cwds we must not mkdir.\n        // This runs on Linux (the demo container), where isAbsolute is exactly\n        // startsWith(\"/\"); it is written portably so the unit tests can drive it\n        // with native temp paths on Windows.\n        if (typeof obj.cwd === \"string\" && obj.cwd.length > 0 && isAbsolute(obj.cwd)) {\n          cwds.add(obj.cwd);\n        }\n      } catch {\n        // Skip corrupt lines — same tolerance the scanner uses.\n      }\n    }\n  }\n  return [...cwds].sort();\n}\n\n/** Extract cwds from `projectsRoot` and create each directory. Returns the list. */\nexport function ensureDemoProjectDirs(projectsRoot: string): string[] {\n  const cwds = extractDemoCwds(projectsRoot);\n  for (const cwd of cwds) {\n    mkdirSync(cwd, { recursive: true });\n  }\n  return cwds;\n}\n\nfunction main(): void {\n  const projectsRoot = process.env.DEMO_PROJECTS_ROOT ?? process.argv[2];\n  if (!projectsRoot) {\n    console.error(\"[entrypoint] ensure-demo-project-dirs: DEMO_PROJECTS_ROOT or argv[2] required\");\n    process.exit(1);\n  }\n  try {\n    const cwds = ensureDemoProjectDirs(projectsRoot);\n    for (const cwd of cwds) {\n      console.log(cwd);\n    }\n  } catch (err) {\n    console.error(`[entrypoint] ${(err as Error).message}`);\n    process.exit(1);\n  }\n}\n\nif (require.main === module) {\n  main();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,qBAA+D;AAC/D,uBAAiC;AAG1B,SAAS,eAAe,MAAwB;AACrD,QAAM,MAAgB,CAAC;AACvB,QAAM,QAAkB,CAAC,IAAI;AAC7B,SAAO,MAAM,SAAS,GAAG;AACvB,UAAM,MAAM,MAAM,IAAI;AACtB,QAAI,QAAQ,OAAW;AACvB,QAAI;AACJ,QAAI;AACF,oBAAU,4BAAY,GAAG;AAAA,IAC3B,SAAS,KAAK;AACZ,UAAK,IAA8B,SAAS,SAAU,QAAO;AAC7D,YAAM;AAAA,IACR;AACA,eAAW,QAAQ,SAAS;AAC1B,YAAM,WAAO,uBAAK,KAAK,IAAI;AAC3B,UAAI;AACF,cAAM,SAAK,yBAAS,IAAI;AACxB,YAAI,GAAG,YAAY,EAAG,OAAM,KAAK,IAAI;AAAA,iBAC5B,GAAG,OAAO,KAAK,KA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