{"version":3,"sources":["../src/workspace/types.ts","../src/workspace/manifest.ts","../src/workspace/fs.ts"],"names":["path","access","constants","readdir","readFile","mkdir","writeFile","stat","rm"],"mappings":";;;;;;;;;;;AAWO,IAAM,wBAAA,GAA2B;AAGjC,IAAM,kBAAA,GAAqB;AAG3B,IAAM,2BAAA,GAA8B;;;ACEpC,IAAM,wBAAA,GAA2B;AAAA,EACtC,SAAA,EAAW,CAAC,MAAM,CAAA;AAAA,EAClB,UAAA,EAAY,SAAA;AAAA,EACZ,YAAA,EAAc,WAAA;AAAA,EACd,UAAA,EAAY,SAAA;AAAA,EACZ,QAAA,EAAU;AACZ;AAEA,IAAM,yBAAA,GAAuD,OAAA;AAE7D,IAAM,kBAAA,GAA2D;AAAA,EAC/D,OAAA;AAAA,EACA,OAAA;AAAA,EACA;AACF,CAAA;AAEA,IAAM,WAAA,GAA6C,CAAC,MAAA,EAAQ,QAAA,EAAU,QAAQ,CAAA;AAGvE,IAAM,+BAA+B,EAAA,GAAK;AAmB1C,SAAS,+BACd,OAAA,EAC+B;AAC/B,EAAA,MAAM,OAAA,GAAU,OAAO,OAAA,CAAQ,OAAA,KAAY,WAAW,OAAA,CAAQ,OAAA,CAAQ,MAAK,GAAI,EAAA;AAC/E,EAAA,MAAM,KAAA,GAA8B;AAAA,IAClC,OAAA,EAAS,OAAA,CAAQ,KAAA,EAAO,OAAA,IAAW,KAAA;AAAA,IACnC,IAAA,EAAM,OAAA,CAAQ,KAAA,EAAO,IAAA,IAAQ,MAAA;AAAA,IAC7B,GAAI,OAAA,CAAQ,KAAA,EAAO,IAAA,KAAS,MAAA,GAAY,EAAE,IAAA,EAAM,OAAA,CAAQ,KAAA,CAAM,IAAA,EAAK,GAAI;AAAC,GAC1E;AAEA,EAAA,OAAO;AAAA,IACL,aAAA,EAAe,wBAAA;AAAA,IACf,OAAA;AAAA,IACA,WAAW,OAAA,CAAQ,SAAA,IAAA,iBAAa,IAAI,IAAA,IAAO,WAAA,EAAY;AAAA,IACvD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W,MAAM,CAAA;AAClD,EAAA,OAAO,EAAE,IAAI,MAAA,EAAO;AACtB;AAmBA,eAAsB,cAAA,CACpB,QAAA,EACA,QAAA,EACA,OAAA,GAAiC,EAAC,EACH;AAC/B,EAAA,MAAM,MAAA,GAAS,QAAQ,OAAA,KAAY,IAAA;AACnC,EAAA,MAAM,UAAU,UAAA,CAAW;AAAA,IACzB,QAAA,CAAS,UAAA;AAAA,IACT,QAAA,CAAS,YAAA;AAAA,IACT,QAAA,CAAS,UAAA;AAAA,IACT,QAAA,CAAS,MAAM,IAAA,IAAQ;AAAA,GACxB,CAAA;AAED,EAAA,MAAM,UAAoB,EAAC;AAC3B,EAAA,KAAA,MAAW,OAAO,OAAA,EAAS;AACzB,IAAA,MAAM,GAAA,GAAM,sBAAA,CAAuB,QAAA,CAAS,YAAA,EAAc,GAAG,CAAA;AAC7D,IAAA,IAAI,OAAA;AACJ,IAAA,IAAI;AACF,MAAA,OAAA,GAAU,MAAMJ,iBAAQ,GAAG,CAAA;AAAA,IAC7B,CAAA,CAAA,MAAQ;AACN,MAAA;AAAA,IACF;AACA,IAAA,KAAA,MAAW,SAAS,OAAA,EAAS;AAC3B,MAAA,MAAM,OAAA,GAAU,CAAA,EAAG,GAAG,CAAA,CAAA,EAAI,KAAK,CAAA,CAAA;AAC/B,MAAA,OAAA,CAAQ,KAAK,OAAO,CAAA;AACpB,MAAA,IAAI,CAAC,MAAA,EAAQ;AACX,QAAA,MAAMK,WAAA,CAAGR,qBAAA,CAAK,IAAA,CAAK,GAAA,EAAK,KAAK,CAAA,EAAG,EAAE,SAAA,EAAW,IAAA,EAAM,KAAA,EAAO,IAAA,EAAM,CAAA;AAAA,MAClE;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,EAAE,QAAQ,OAAA,EAAQ;AAC3B","file":"workspace.cjs","sourcesContent":["/**\n * Internal workspace manifest types (v4.0).\n *\n * @remarks\n * Experimental and internal to `@agent-inspect/core`. This module is not part\n * of any published entry point. Adding a public `agent-inspect/workspace`\n * export is a separate, maintainer-gated step (see\n * `docs/proposals/LOCAL-TRACE-WORKSPACE.md`).\n */\n\n/** Fixed manifest schema version for the v4.0 workspace model. */\nexport const WORKSPACE_SCHEMA_VERSION = \"1.0\" as const;\n\n/** Standard workspace directory name at a project root. */\nexport const WORKSPACE_DIR_NAME = \".agent-inspect\" as const;\n\n/** Standard manifest filename inside {@link WORKSPACE_DIR_NAME}. */\nexport const WORKSPACE_MANIFEST_FILENAME = \"workspace.json\" as const;\n\n/** Default share-safety posture applied to a workspace. */\nexport type WorkspaceRedactionProfile = \"local\" | \"share\" | \"strict\";\n\n/** Optional local index kind (SQLite index arrives as an opt-in package in v4.1). */\nexport type WorkspaceIndexType = \"none\" | \"sqlite\" | \"custom\";\n\n/** Optional local index descriptor. */\nexport interface WorkspaceIndexConfig {\n  enabled: boolean;\n  type: WorkspaceIndexType;\n  path?: string;\n}\n\n/**\n * The `.agent-inspect/workspace.json` manifest.\n *\n * @remarks\n * All directory fields are paths relative to the workspace root and must\n * resolve inside it (no absolute paths, no `..` traversal).\n */\nexport interface AgentInspectWorkspaceManifest {\n  schemaVersion: typeof WORKSPACE_SCHEMA_VERSION;\n  project: string;\n  createdAt: string;\n  traceDirs: string[];\n  reportsDir: string;\n  artifactsDir: string;\n  bundlesDir: string;\n  notesDir: string;\n  redactionProfile: WorkspaceRedactionProfile;\n  index: WorkspaceIndexConfig;\n}\n\n/** Result of validating unknown input against the manifest contract. */\nexport interface WorkspaceManifestValidationResult {\n  ok: boolean;\n  manifest?: AgentInspectWorkspaceManifest;\n  errors: string[];\n  warnings: string[];\n}\n","import {\n  WORKSPACE_SCHEMA_VERSION,\n  type AgentInspectWorkspaceManifest,\n  type WorkspaceIndexConfig,\n  type WorkspaceIndexType,\n  type WorkspaceManifestValidationResult,\n  type WorkspaceRedactionProfile,\n} from \"./types.js\";\n\n/**\n * Internal workspace manifest validation + default generation (v4.0).\n *\n * @remarks\n * Pure, non-throwing helpers. Validation is conservative: unknown or malformed\n * input is rejected with clear messages rather than coerced. No filesystem or\n * network access happens here (filesystem helpers arrive in a later chunk).\n */\n\n/** Default relative layout used when generating a fresh manifest. */\nexport const DEFAULT_WORKSPACE_LAYOUT = {\n  traceDirs: [\"runs\"],\n  reportsDir: \"reports\",\n  artifactsDir: \"artifacts\",\n  bundlesDir: \"bundles\",\n  notesDir: \"notes\",\n} as const;\n\nconst DEFAULT_REDACTION_PROFILE: WorkspaceRedactionProfile = \"share\";\n\nconst REDACTION_PROFILES: readonly WorkspaceRedactionProfile[] = [\n  \"local\",\n  \"share\",\n  \"strict\",\n];\n\nconst INDEX_TYPES: readonly WorkspaceIndexType[] = [\"none\", \"sqlite\", \"custom\"];\n\n/** Upper bound on serialized manifest input accepted by {@link parseWorkspaceManifest}. */\nexport const MAX_WORKSPACE_MANIFEST_BYTES = 64 * 1024;\n\n/** Options for {@link createDefaultWorkspaceManifest}. */\nexport interface CreateWorkspaceManifestOptions {\n  project: string;\n  createdAt?: string;\n  traceDirs?: string[];\n  reportsDir?: string;\n  artifactsDir?: string;\n  bundlesDir?: string;\n  notesDir?: string;\n  redactionProfile?: WorkspaceRedactionProfile;\n  index?: Partial<WorkspaceIndexConfig>;\n}\n\n/**\n * Generates a default workspace manifest for a project using the standard\n * layout. The returned object is always shape-valid.\n */\nexport function createDefaultWorkspaceManifest(\n  options: CreateWorkspaceManifestOptions,\n): AgentInspectWorkspaceManifest {\n  const project = typeof options.project === \"string\" ? options.project.trim() : \"\";\n  const index: WorkspaceIndexConfig = {\n    enabled: options.index?.enabled ?? false,\n    type: options.index?.type ?? \"none\",\n    ...(options.index?.path !== undefined ? { path: options.index.path } : {}),\n  };\n\n  return {\n    schemaVersion: WORKSPACE_SCHEMA_VERSION,\n    project,\n    createdAt: options.createdAt ?? new Date().toISOString(),\n    traceDirs: options.traceDirs\n      ? [...options.traceDirs]\n      : [...DEFAULT_WORKSPACE_LAYOUT.traceDirs],\n    reportsDir: options.reportsDir ?? DEFAULT_WORKSPACE_LAYOUT.reportsDir,\n    artifactsDir: options.artifactsDir ?? DEFAULT_WORKSPACE_LAYOUT.artifactsDir,\n    bundlesDir: options.bundlesDir ?? DEFAULT_WORKSPACE_LAYOUT.bundlesDir,\n    notesDir: options.notesDir ?? DEFAULT_WORKSPACE_LAYOUT.notesDir,\n    redactionProfile: options.redactionProfile ?? DEFAULT_REDACTION_PROFILE,\n    index,\n  };\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n  return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Returns true when `p` is a non-empty relative path that stays within the\n * workspace root: no absolute paths, no `..` traversal, no Windows drive roots.\n */\nexport function isSafeRelativeWorkspacePath(p: unknown): p is string {\n  if (typeof p !== \"string\") return false;\n  const trimmed = p.trim();\n  if (trimmed === \"\") return false;\n  if (trimmed.startsWith(\"/\") || trimmed.startsWith(\"\\\\\")) return false;\n  if (/^[a-zA-Z]:/.test(trimmed)) return false;\n  const segments = trimmed.split(/[/\\\\]+/);\n  return !segments.some((seg) => seg === \"..\");\n}\n\nfunction validateDirField(\n  value: unknown,\n  field: string,\n  errors: string[],\n): void {\n  if (typeof value !== \"string\" || value.trim() === \"\") {\n    errors.push(`${field} must be a non-empty string`);\n    return;\n  }\n  if (!isSafeRelativeWorkspacePath(value)) {\n    errors.push(\n      `${field} must be a relative path inside the workspace (no absolute paths or \"..\" traversal)`,\n    );\n  }\n}\n\nfunction validateIndex(value: unknown, errors: string[]): WorkspaceIndexConfig | undefined {\n  if (!isPlainObject(value)) {\n    errors.push(\"index must be an object\");\n    return undefined;\n  }\n  if (typeof value.enabled !== \"boolean\") {\n    errors.push(\"index.enabled must be a boolean\");\n  }\n  if (!INDEX_TYPES.includes(value.type as WorkspaceIndexType)) {\n    errors.push(`index.type must be one of: ${INDEX_TYPES.join(\", \")}`);\n  }\n  if (value.path !== undefined && !isSafeRelativeWorkspacePath(value.path)) {\n    errors.push(\n      'index.path must be a relative path inside the workspace (no absolute paths or \"..\" traversal)',\n    );\n  }\n  if (errors.length > 0) return undefined;\n  return {\n    enabled: value.enabled as boolean,\n    type: value.type as WorkspaceIndexType,\n    ...(value.path !== undefined ? { path: value.path as string } : {}),\n  };\n}\n\n/**\n * Conservatively validates unknown input against the workspace manifest\n * contract. Never throws; returns a result with `ok`, the normalized\n * `manifest` (when valid), `errors`, and non-fatal `warnings`.\n */\nexport function validateWorkspaceManifest(\n  input: unknown,\n): WorkspaceManifestValidationResult {\n  const errors: string[] = [];\n  const warnings: string[] = [];\n\n  if (!isPlainObject(input)) {\n    return { ok: false, errors: [\"manifest must be an object\"], warnings };\n  }\n\n  if (input.schemaVersion !== WORKSPACE_SCHEMA_VERSION) {\n    errors.push(\n      `schemaVersion must be \"${WORKSPACE_SCHEMA_VERSION}\" (received ${JSON.stringify(\n        input.schemaVersion,\n      )})`,\n    );\n  }\n\n  if (typeof input.project !== \"string\" || input.project.trim() === \"\") {\n    errors.push(\"project must be a non-empty string\");\n  }\n\n  if (typeof input.createdAt !== \"string\" || input.createdAt.trim() === \"\") {\n    errors.push(\"createdAt must be a non-empty ISO-8601 string\");\n  } else if (Number.isNaN(Date.parse(input.createdAt))) {\n    errors.push(\"createdAt must be a valid ISO-8601 date string\");\n  }\n\n  if (!Array.isArray(input.traceDirs) || input.traceDirs.length === 0) {\n    errors.push(\"traceDirs must be a non-empty array\");\n  } else {\n    input.traceDirs.forEach((dir, i) => {\n      if (typeof dir !== \"string\" || dir.trim() === \"\") {\n        errors.push(`traceDirs[${i}] must be a non-empty string`);\n      } else if (!isSafeRelativeWorkspacePath(dir)) {\n        errors.push(\n          `traceDirs[${i}] must be a relative path inside the workspace (no absolute paths or \"..\" traversal)`,\n        );\n      }\n    });\n  }\n\n  validateDirField(input.reportsDir, \"reportsDir\", errors);\n  validateDirField(input.artifactsDir, \"artifactsDir\", errors);\n  validateDirField(input.bundlesDir, \"bundlesDir\", errors);\n  validateDirField(input.notesDir, \"notesDir\", errors);\n\n  if (!REDACTION_PROFILES.includes(input.redactionProfile as WorkspaceRedactionProfile)) {\n    errors.push(`redactionProfile must be one of: ${REDACTION_PROFILES.join(\", \")}`);\n  }\n\n  const indexErrors: string[] = [];\n  const index = validateIndex(input.index, indexErrors);\n  errors.push(...indexErrors);\n\n  if (index && index.type !== \"none\" && !index.enabled) {\n    warnings.push(`index.type is \"${index.type}\" but index.enabled is false`);\n  }\n\n  if (errors.length > 0 || index === undefined) {\n    return { ok: false, errors, warnings };\n  }\n\n  const manifest: AgentInspectWorkspaceManifest = {\n    schemaVersion: WORKSPACE_SCHEMA_VERSION,\n    project: (input.project as string).trim(),\n    createdAt: input.createdAt as string,\n    traceDirs: (input.traceDirs as string[]).map((d) => d.trim()),\n    reportsDir: (input.reportsDir as string).trim(),\n    artifactsDir: (input.artifactsDir as string).trim(),\n    bundlesDir: (input.bundlesDir as string).trim(),\n    notesDir: (input.notesDir as string).trim(),\n    redactionProfile: input.redactionProfile as WorkspaceRedactionProfile,\n    index,\n  };\n\n  return { ok: true, manifest, errors, warnings };\n}\n\n/**\n * Safely parses a serialized manifest string and validates it. Bounds input\n * size and rejects invalid JSON without throwing.\n */\nexport function parseWorkspaceManifest(\n  json: string,\n): WorkspaceManifestValidationResult {\n  const warnings: string[] = [];\n\n  if (typeof json !== \"string\") {\n    return { ok: false, errors: [\"manifest input must be a string\"], warnings };\n  }\n  if (json.length > MAX_WORKSPACE_MANIFEST_BYTES) {\n    return {\n      ok: false,\n      errors: [\n        `manifest exceeds maximum size of ${MAX_WORKSPACE_MANIFEST_BYTES} bytes`,\n      ],\n      warnings,\n    };\n  }\n\n  let parsed: unknown;\n  try {\n    parsed = JSON.parse(json) as unknown;\n  } catch {\n    return { ok: false, errors: [\"manifest is not valid JSON\"], warnings };\n  }\n\n  return validateWorkspaceManifest(parsed);\n}\n\n/** Serializes a manifest to deterministic, pretty-printed JSON with a trailing newline. */\nexport function serializeWorkspaceManifest(\n  manifest: AgentInspectWorkspaceManifest,\n): string {\n  return `${JSON.stringify(manifest, null, 2)}\\n`;\n}\n","import { constants } from \"node:fs\";\nimport { access, mkdir, readdir, readFile, rm, stat, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\nimport {\n  createDefaultWorkspaceManifest,\n  parseWorkspaceManifest,\n  serializeWorkspaceManifest,\n} from \"./manifest.js\";\nimport {\n  WORKSPACE_DIR_NAME,\n  WORKSPACE_MANIFEST_FILENAME,\n  type AgentInspectWorkspaceManifest,\n  type WorkspaceRedactionProfile,\n} from \"./types.js\";\n\n/**\n * Internal workspace filesystem helpers (v4.0).\n *\n * @remarks\n * Local-only. Never deletes trace files. All manifest-derived paths are\n * resolved and confirmed to stay within the workspace directory\n * (path-traversal guarded). No network access.\n */\n\n/** Resolved on-disk location of a workspace. */\nexport interface WorkspaceLocation {\n  /** Project directory that contains the `.agent-inspect` folder. */\n  projectRoot: string;\n  /** The `.agent-inspect` workspace directory (root for relative manifest paths). */\n  workspaceDir: string;\n  /** Absolute path to `workspace.json`. */\n  manifestPath: string;\n}\n\nconst INDEX_DIR_NAME = \"index\";\n\n/** Resolves the workspace location for a given project directory. */\nexport function resolveWorkspaceLocation(cwd: string = process.cwd()): WorkspaceLocation {\n  const projectRoot = path.resolve(cwd);\n  const workspaceDir = path.join(projectRoot, WORKSPACE_DIR_NAME);\n  return {\n    projectRoot,\n    workspaceDir,\n    manifestPath: path.join(workspaceDir, WORKSPACE_MANIFEST_FILENAME),\n  };\n}\n\n/**\n * Resolves a manifest-relative path against the workspace directory, rejecting\n * any path that escapes it.\n */\nexport function resolveInsideWorkspace(workspaceDir: string, relative: string): string {\n  const base = path.resolve(workspaceDir);\n  const resolved = path.resolve(base, relative);\n  const rel = path.relative(base, resolved);\n  if (rel === \"\" || rel === \".\" || (!rel.startsWith(\"..\") && !path.isAbsolute(rel))) {\n    return resolved;\n  }\n  throw new Error(\n    `Workspace path \"${relative}\" resolves outside the workspace directory`,\n  );\n}\n\nasync function pathExists(p: string): Promise<boolean> {\n  try {\n    await access(p);\n    return true;\n  } catch {\n    return false;\n  }\n}\n\nasync function isWritable(p: string): Promise<boolean> {\n  try {\n    await access(p, constants.W_OK);\n    return true;\n  } catch {\n    return false;\n  }\n}\n\nasync function listJsonl(dir: string): Promise<string[]> {\n  try {\n    const entries = await readdir(dir);\n    return entries.filter((f) => f.endsWith(\".jsonl\"));\n  } catch {\n    return [];\n  }\n}\n\nasync function countFiles(dir: string): Promise<number> {\n  try {\n    const entries = await readdir(dir, { withFileTypes: true });\n    return entries.filter((e) => e.isFile()).length;\n  } catch {\n    return 0;\n  }\n}\n\n/** Result of reading a workspace manifest from disk. */\nexport interface ReadWorkspaceManifestResult {\n  exists: boolean;\n  ok: boolean;\n  manifest?: AgentInspectWorkspaceManifest;\n  errors: string[];\n  warnings: string[];\n}\n\n/** Reads and validates `workspace.json` at the given location. Never throws. */\nexport async function readWorkspaceManifestFile(\n  location: WorkspaceLocation,\n): Promise<ReadWorkspaceManifestResult> {\n  let raw: string;\n  try {\n    raw = await readFile(location.manifestPath, \"utf-8\");\n  } catch {\n    return { exists: false, ok: false, errors: [\"workspace.json not found\"], warnings: [] };\n  }\n  const parsed = parseWorkspaceManifest(raw);\n  return {\n    exists: true,\n    ok: parsed.ok,\n    ...(parsed.manifest ? { manifest: parsed.manifest } : {}),\n    errors: parsed.errors,\n    warnings: parsed.warnings,\n  };\n}\n\n/** Options for {@link createWorkspace}. */\nexport interface CreateWorkspaceOptions {\n  cwd?: string;\n  project?: string;\n  redactionProfile?: WorkspaceRedactionProfile;\n  /** Preview only: do not write anything to disk. */\n  dryRun?: boolean;\n}\n\n/** Outcome of {@link createWorkspace}. */\nexport interface CreateWorkspaceResult {\n  location: WorkspaceLocation;\n  manifest: AgentInspectWorkspaceManifest;\n  /** True when a fresh manifest was written. */\n  created: boolean;\n  /** True when an existing workspace/trace directory was adopted without rewrite. */\n  adopted: boolean;\n  /** Relative directories created (or that would be created in dry-run). */\n  createdDirs: string[];\n  /** True when top-level `.jsonl` traces were detected and preserved. */\n  detectedExistingTraces: boolean;\n  dryRun: boolean;\n}\n\n/**\n * Creates or adopts a workspace. Never deletes or rewrites existing traces.\n * When a manifest already exists it is adopted (missing folders are created,\n * the manifest is left untouched).\n */\nexport async function createWorkspace(\n  options: CreateWorkspaceOptions = {},\n): Promise<CreateWorkspaceResult> {\n  const location = resolveWorkspaceLocation(options.cwd);\n  const dryRun = options.dryRun === true;\n\n  const existing = await readWorkspaceManifestFile(location);\n  const topLevelTraces = await listJsonl(location.workspaceDir);\n  const detectedExistingTraces = topLevelTraces.length > 0;\n\n  let manifest: AgentInspectWorkspaceManifest;\n  let created: boolean;\n  let adopted: boolean;\n\n  if (existing.exists && existing.ok && existing.manifest) {\n    manifest = existing.manifest;\n    created = false;\n    adopted = true;\n  } else {\n    const project =\n      options.project?.trim() ||\n      path.basename(location.projectRoot) ||\n      \"workspace\";\n    const traceDirs = detectedExistingTraces ? [\"runs\", \".\"] : [\"runs\"];\n    manifest = createDefaultWorkspaceManifest({\n      project,\n      traceDirs,\n      ...(options.redactionProfile ? { redactionProfile: options.redactionProfile } : {}),\n    });\n    created = true;\n    adopted = detectedExistingTraces || (existing.exists && !existing.ok);\n  }\n\n  const relDirs = uniqueDirs([\n    ...manifest.traceDirs.filter((d) => d !== \".\"),\n    manifest.reportsDir,\n    manifest.artifactsDir,\n    manifest.bundlesDir,\n    manifest.notesDir,\n    INDEX_DIR_NAME,\n  ]);\n\n  const createdDirs: string[] = [];\n  for (const rel of relDirs) {\n    const abs = resolveInsideWorkspace(location.workspaceDir, rel);\n    if (await pathExists(abs)) continue;\n    createdDirs.push(rel);\n    if (!dryRun) await mkdir(abs, { recursive: true });\n  }\n\n  if (!dryRun && created) {\n    await mkdir(location.workspaceDir, { recursive: true });\n    await writeFile(location.manifestPath, serializeWorkspaceManifest(manifest), \"utf-8\");\n  }\n\n  return {\n    location,\n    manifest,\n    created,\n    adopted,\n    createdDirs,\n    detectedExistingTraces,\n    dryRun,\n  };\n}\n\nfunction uniqueDirs(dirs: string[]): string[] {\n  const seen = new Set<string>();\n  const out: string[] = [];\n  for (const d of dirs) {\n    const t = d.trim();\n    if (t === \"\" || t === \".\" || seen.has(t)) continue;\n    seen.add(t);\n    out.push(t);\n  }\n  return out;\n}\n\n/** Index presence/status for {@link getWorkspaceStatus}. */\nexport interface WorkspaceIndexStatus {\n  enabled: boolean;\n  type: string;\n  exists: boolean;\n}\n\n/** Aggregate, read-only workspace status. */\nexport interface WorkspaceStatus {\n  project: string;\n  traceFiles: number;\n  reports: number;\n  artifacts: number;\n  bundles: number;\n  notes: number;\n  index: WorkspaceIndexStatus;\n}\n\n/** Computes read-only counts for a workspace. Requires a valid manifest. */\nexport async function getWorkspaceStatus(\n  location: WorkspaceLocation,\n  manifest: AgentInspectWorkspaceManifest,\n): Promise<WorkspaceStatus> {\n  let traceFiles = 0;\n  for (const rel of manifest.traceDirs) {\n    const abs = resolveInsideWorkspace(location.workspaceDir, rel);\n    traceFiles += (await listJsonl(abs)).length;\n  }\n\n  const reports = await countFiles(\n    resolveInsideWorkspace(location.workspaceDir, manifest.reportsDir),\n  );\n  const artifacts = await countFiles(\n    resolveInsideWorkspace(location.workspaceDir, manifest.artifactsDir),\n  );\n  const bundles = await countFiles(\n    resolveInsideWorkspace(location.workspaceDir, manifest.bundlesDir),\n  );\n  const notes = await countFiles(\n    resolveInsideWorkspace(location.workspaceDir, manifest.notesDir),\n  );\n\n  const indexPath = manifest.index.path\n    ? resolveInsideWorkspace(location.workspaceDir, manifest.index.path)\n    : resolveInsideWorkspace(location.workspaceDir, INDEX_DIR_NAME);\n\n  return {\n    project: manifest.project,\n    traceFiles,\n    reports,\n    artifacts,\n    bundles,\n    notes,\n    index: {\n      enabled: manifest.index.enabled,\n      type: manifest.index.type,\n      exists: await pathExists(indexPath),\n    },\n  };\n}\n\n/** A single workspace doctor check. */\nexport interface WorkspaceDoctorCheck {\n  id: string;\n  status: \"pass\" | \"warn\" | \"fail\";\n  message: string;\n}\n\n/** Result of {@link doctorWorkspace}. */\nexport interface WorkspaceDoctorResult {\n  ok: boolean;\n  checks: WorkspaceDoctorCheck[];\n}\n\n/**\n * Validates a workspace: manifest presence/shape, folder permissions, trace\n * readability, and index staleness. Read-only; never throws.\n */\nexport async function doctorWorkspace(\n  location: WorkspaceLocation,\n): Promise<WorkspaceDoctorResult> {\n  const checks: WorkspaceDoctorCheck[] = [];\n  const manifestResult = await readWorkspaceManifestFile(location);\n\n  if (!manifestResult.exists) {\n    checks.push({\n      id: \"manifest\",\n      status: \"fail\",\n      message: \"workspace.json not found (run `agent-inspect workspace init`)\",\n    });\n    return { ok: false, checks };\n  }\n  if (!manifestResult.ok || !manifestResult.manifest) {\n    checks.push({\n      id: \"manifest\",\n      status: \"fail\",\n      message: `workspace.json is invalid: ${manifestResult.errors.join(\"; \")}`,\n    });\n    return { ok: false, checks };\n  }\n\n  const manifest = manifestResult.manifest;\n  checks.push({ id: \"manifest\", status: \"pass\", message: \"workspace.json is valid\" });\n  for (const warning of manifestResult.warnings) {\n    checks.push({ id: \"manifest-warning\", status: \"warn\", message: warning });\n  }\n\n  const dirFields: Array<[string, string]> = [\n    ...manifest.traceDirs\n      .filter((d) => d !== \".\")\n      .map((d, i) => [`traceDir[${i}]`, d] as [string, string]),\n    [\"reportsDir\", manifest.reportsDir],\n    [\"artifactsDir\", manifest.artifactsDir],\n    [\"bundlesDir\", manifest.bundlesDir],\n    [\"notesDir\", manifest.notesDir],\n  ];\n\n  for (const [id, rel] of dirFields) {\n    let abs: string;\n    try {\n      abs = resolveInsideWorkspace(location.workspaceDir, rel);\n    } catch (error) {\n      checks.push({\n        id,\n        status: \"fail\",\n        message: error instanceof Error ? error.message : String(error),\n      });\n      continue;\n    }\n    if (!(await pathExists(abs))) {\n      checks.push({ id, status: \"warn\", message: `${rel}/ does not exist yet` });\n    } else if (!(await isWritable(abs))) {\n      checks.push({ id, status: \"fail\", message: `${rel}/ is not writable` });\n    } else {\n      checks.push({ id, status: \"pass\", message: `${rel}/ is present and writable` });\n    }\n  }\n\n  // Trace readability + index staleness.\n  let newestTraceMtime = 0;\n  for (const rel of manifest.traceDirs) {\n    const abs = resolveInsideWorkspace(location.workspaceDir, rel);\n    for (const file of await listJsonl(abs)) {\n      try {\n        const s = await stat(path.join(abs, file));\n        newestTraceMtime = Math.max(newestTraceMtime, s.mtimeMs);\n      } catch {\n        checks.push({ id: \"trace-readability\", status: \"warn\", message: `cannot stat ${rel}/${file}` });\n      }\n    }\n  }\n\n  if (manifest.index.enabled) {\n    const indexPath = manifest.index.path\n      ? resolveInsideWorkspace(location.workspaceDir, manifest.index.path)\n      : resolveInsideWorkspace(location.workspaceDir, INDEX_DIR_NAME);\n    if (!(await pathExists(indexPath))) {\n      checks.push({ id: \"index\", status: \"warn\", message: \"index enabled but not built\" });\n    } else {\n      try {\n        const s = await stat(indexPath);\n        if (newestTraceMtime > s.mtimeMs) {\n          checks.push({ id: \"index\", status: \"warn\", message: \"index is stale (traces are newer)\" });\n        } else {\n          checks.push({ id: \"index\", status: \"pass\", message: \"index is present\" });\n        }\n      } catch {\n        checks.push({ id: \"index\", status: \"warn\", message: \"cannot stat index\" });\n      }\n    }\n  }\n\n  const ok = !checks.some((c) => c.status === \"fail\");\n  return { ok, checks };\n}\n\n/** Options for {@link cleanWorkspace}. */\nexport interface CleanWorkspaceOptions {\n  /** Actually delete. When false (default), the operation is a dry-run. */\n  confirm?: boolean;\n}\n\n/** Result of {@link cleanWorkspace}. */\nexport interface CleanWorkspaceResult {\n  dryRun: boolean;\n  /** Relative paths removed (or that would be removed in dry-run). */\n  removed: string[];\n}\n\n/**\n * Removes generated workspace content (reports, artifacts, bundles, index).\n * Dry-run by default; trace directories are never touched.\n */\nexport async function cleanWorkspace(\n  location: WorkspaceLocation,\n  manifest: AgentInspectWorkspaceManifest,\n  options: CleanWorkspaceOptions = {},\n): Promise<CleanWorkspaceResult> {\n  const dryRun = options.confirm !== true;\n  const targets = uniqueDirs([\n    manifest.reportsDir,\n    manifest.artifactsDir,\n    manifest.bundlesDir,\n    manifest.index.path ?? INDEX_DIR_NAME,\n  ]);\n\n  const removed: string[] = [];\n  for (const rel of targets) {\n    const abs = resolveInsideWorkspace(location.workspaceDir, rel);\n    let entries: string[];\n    try {\n      entries = await readdir(abs);\n    } catch {\n      continue;\n    }\n    for (const entry of entries) {\n      const relPath = `${rel}/${entry}`;\n      removed.push(relPath);\n      if (!dryRun) {\n        await rm(path.join(abs, entry), { recursive: true, force: true });\n      }\n    }\n  }\n\n  return { dryRun, removed };\n}\n"]}