@mean-weasel/lineage 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/cli/lineageCli.ts", "../../src/server/assetCore.ts", "../../src/server/adapters/storage/s3StorageAdapter.ts", "../../src/server/localReview.ts", "../../src/server/assetLineageDb.ts", "../../src/server/assetLineageSelection.ts", "../../src/server/assetLineageWorkspaces.ts", "../../src/server/assetLineage.ts", "../../src/server/assetLineageHandoff.ts", "../../src/cli/lineage.ts"],
4
- "sourcesContent": ["import { existsSync, mkdirSync, readFileSync } from 'node:fs';\nimport { homedir, platform } from 'node:os';\nimport { dirname, join, resolve } from 'node:path';\nimport { spawn } from 'node:child_process';\nimport { fileURLToPath } from 'node:url';\nimport { defaultProduct } from '../server/assetCore';\nimport { getLineageNextAsset, getLineageSnapshot } from '../server/assetLineage';\nimport { getLineageBrief, linkSelectedLineageChild } from '../server/assetLineageHandoff';\n\nexport interface LineageCliConfig {\n binName: 'lineage' | 'lineage-dev';\n channel: 'stable' | 'development';\n defaultPort: number;\n displayName: string;\n}\n\ninterface StartOptions {\n dbPath: string;\n host: string;\n json: boolean;\n open: boolean;\n port: number;\n}\n\ninterface DataCommandOptions {\n assetId?: string;\n childAssetId?: string;\n confirmWrite: boolean;\n dbPath?: string;\n json: boolean;\n project: string;\n rootAssetId?: string;\n}\n\nconst signalExitCodes: Partial<Record<NodeJS.Signals, number>> = {\n SIGINT: 130,\n SIGTERM: 143,\n};\n\nfunction packageRoot(): string {\n return resolve(dirname(fileURLToPath(import.meta.url)), '..', '..');\n}\n\nfunction packageVersion(): string {\n try {\n const packageInfo = JSON.parse(readFileSync(join(packageRoot(), 'package.json'), 'utf8')) as { version?: string };\n return packageInfo.version || '0.0.0';\n } catch {\n return '0.0.0';\n }\n}\n\nfunction dataRoot(displayName: string): string {\n if (process.env.LINEAGE_HOME) return process.env.LINEAGE_HOME;\n if (platform() === 'darwin') return join(homedir(), 'Library', 'Application Support', displayName);\n if (platform() === 'win32') return join(process.env.APPDATA || join(homedir(), 'AppData', 'Roaming'), displayName);\n return join(process.env.XDG_DATA_HOME || join(homedir(), '.local', 'share'), displayName.toLowerCase().replace(/\\s+/g, '-'));\n}\n\nfunction readOption(args: string[], name: string): string | undefined {\n const prefix = `${name}=`;\n const inline = args.find(arg => arg.startsWith(prefix));\n if (inline) return inline.slice(prefix.length);\n const index = args.indexOf(name);\n if (index >= 0) return args[index + 1];\n return undefined;\n}\n\nexport function resolveStartOptions(config: LineageCliConfig, args: string[]): StartOptions {\n const runtimeDir = dataRoot(config.displayName);\n const rawPort = readOption(args, '--port') || process.env.PORT || String(config.defaultPort);\n const port = Number(rawPort);\n if (!Number.isInteger(port) || port < 1 || port > 65535) {\n throw new Error(`Invalid port: ${rawPort}`);\n }\n return {\n dbPath: readOption(args, '--db') || process.env.LINEAGE_DB || join(runtimeDir, `${config.binName}.sqlite`),\n host: readOption(args, '--host') || process.env.HOST || '127.0.0.1',\n json: args.includes('--json'),\n open: args.includes('--open'),\n port,\n };\n}\n\nfunction printHelp(config: LineageCliConfig): void {\n console.log(`${config.binName} ${packageVersion()}\n\nUsage:\n ${config.binName} start [--port <port>] [--host <host>] [--db <path>] [--open] [--json]\n ${config.binName} next [--project <project>] [--root <asset-id>] [--db <path>] [--json]\n ${config.binName} brief [--project <project>] [--root <asset-id>] [--db <path>] [--json]\n ${config.binName} inspect --asset-id <asset-id> [--project <project>] [--db <path>] [--json]\n ${config.binName} link-child --root <asset-id> --child <asset-id> [--project <project>] [--confirm-write] [--db <path>] [--json]\n ${config.binName} --help\n ${config.binName} --version\n\n${config.displayName} runs the bundled Lineage server for the ${config.channel} channel.`);\n}\n\nfunction openBrowser(url: string): void {\n const command = platform() === 'darwin' ? 'open' : platform() === 'win32' ? 'cmd' : 'xdg-open';\n const args = platform() === 'win32' ? ['/c', 'start', '', url] : [url];\n const opener = spawn(command, args, { detached: true, stdio: 'ignore' });\n opener.unref();\n}\n\nfunction positionalArgs(args: string[]): string[] {\n const values: string[] = [];\n for (let index = 0; index < args.length; index += 1) {\n const arg = args[index];\n if (arg.startsWith('--')) {\n if (!arg.includes('=') && args[index + 1] && !args[index + 1].startsWith('--')) index += 1;\n continue;\n }\n values.push(arg);\n }\n return values;\n}\n\nfunction resolveDataCommandOptions(args: string[]): DataCommandOptions {\n const positions = positionalArgs(args);\n const options = {\n assetId: readOption(args, '--asset-id') || positions[0],\n childAssetId: readOption(args, '--child'),\n confirmWrite: args.includes('--confirm-write'),\n dbPath: readOption(args, '--db'),\n json: args.includes('--json'),\n project: readOption(args, '--project') || process.env.LINEAGE_DEFAULT_PRODUCT || defaultProduct,\n rootAssetId: readOption(args, '--root'),\n };\n if (options.dbPath) process.env.LINEAGE_DB = options.dbPath;\n return options;\n}\n\nexport function runLineageDataCommand(command: string, args: string[]): unknown {\n const options = resolveDataCommandOptions(args);\n if (command === 'next') return getLineageNextAsset(options.project, options.rootAssetId || options.assetId);\n if (command === 'brief') return getLineageBrief(options.project, options.rootAssetId || options.assetId);\n if (command === 'inspect') {\n if (!options.assetId) throw new Error('lineage inspect requires --asset-id');\n return getLineageSnapshot(options.project, options.assetId);\n }\n if (command === 'link-child') {\n if (!options.childAssetId) throw new Error('lineage link-child requires --child');\n return linkSelectedLineageChild(options.project, {\n childAssetId: options.childAssetId,\n confirmWrite: options.confirmWrite,\n rootAssetId: options.rootAssetId || options.assetId,\n });\n }\n throw new Error(`Unknown command: ${command}`);\n}\n\nfunction printDataResult(command: string, result: unknown, json: boolean): void {\n if (json) {\n console.log(JSON.stringify(result, null, 2));\n return;\n }\n if (command === 'next' && result && typeof result === 'object' && 'reason' in result) {\n const next = result as { next_asset?: { asset_id: string; title: string } | null; reason: string; root_asset_id: string };\n console.log(next.next_asset ? `${next.next_asset.asset_id}: ${next.next_asset.title}` : `No next asset: ${next.reason}`);\n console.log(`Root: ${next.root_asset_id}`);\n return;\n }\n if (command === 'brief' && result && typeof result === 'object' && 'brief' in result) {\n const brief = result as { brief: { title: string; prompt: string } };\n console.log(brief.brief.title);\n console.log(brief.brief.prompt);\n return;\n }\n if (command === 'inspect' && result && typeof result === 'object' && 'nodes' in result) {\n const snapshot = result as { active_asset_id: string; edges: unknown[]; nodes: unknown[]; root_asset_id: string };\n console.log(`${snapshot.root_asset_id}: ${snapshot.nodes.length} node(s), ${snapshot.edges.length} edge(s)`);\n console.log(`Active: ${snapshot.active_asset_id}`);\n return;\n }\n if (command === 'link-child' && result && typeof result === 'object') {\n const link = result as { dryRun?: boolean; edge?: { child_asset_id: string; parent_asset_id: string }; message?: string };\n console.log(link.message || `${link.dryRun ? 'Dry run: ' : ''}Link ${link.edge?.child_asset_id || 'child'} from ${link.edge?.parent_asset_id || 'parent'}`);\n return;\n }\n console.log(String(result));\n}\n\nfunction start(config: LineageCliConfig, args: string[]): void {\n let options: StartOptions;\n const json = args.includes('--json');\n try {\n options = resolveStartOptions(config, args);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (json) console.error(JSON.stringify({ ok: false, error: message }, null, 2));\n else console.error(`${config.binName}: ${message}`);\n process.exit(1);\n }\n const serverPath = join(packageRoot(), 'dist', 'server.js');\n if (!existsSync(serverPath)) {\n const message = `Missing bundled server at ${serverPath}. Run npm run build before using ${config.binName} start from a source checkout.`;\n if (options.json) console.error(JSON.stringify({ ok: false, error: message }, null, 2));\n else console.error(`${config.binName}: ${message}`);\n process.exit(1);\n }\n\n mkdirSync(dirname(options.dbPath), { recursive: true });\n const url = `http://${options.host}:${options.port}`;\n if (options.json) {\n console.log(JSON.stringify({ channel: config.channel, dbPath: options.dbPath, host: options.host, port: options.port, status: 'starting', url }, null, 2));\n } else {\n console.log(`${config.displayName} starting at ${url}`);\n console.log(`SQLite: ${options.dbPath}`);\n }\n if (options.open) openBrowser(url);\n\n const child = spawn(process.execPath, [serverPath], {\n env: {\n ...process.env,\n HOST: options.host,\n LINEAGE_CHANNEL: config.channel,\n LINEAGE_DB: options.dbPath,\n NODE_ENV: 'production',\n PORT: String(options.port),\n },\n stdio: 'inherit',\n });\n\n let forwardedSignal: NodeJS.Signals | undefined;\n const stop = (signal: NodeJS.Signals) => {\n forwardedSignal = signal;\n child.kill(signal);\n };\n process.once('SIGINT', stop);\n process.once('SIGTERM', stop);\n child.on('exit', code => process.exit(code ?? (forwardedSignal ? signalExitCodes[forwardedSignal] || 1 : 0)));\n child.on('error', error => {\n console.error(`${config.binName}: failed to start server: ${error.message}`);\n process.exit(1);\n });\n}\n\nexport function runLineageCli(config: LineageCliConfig, args = process.argv.slice(2)): void {\n if (args.includes('--help') || args.includes('-h') || args.length === 0) {\n printHelp(config);\n process.exit(0);\n }\n\n if (args.includes('--version') || args.includes('-v')) {\n console.log(packageVersion());\n process.exit(0);\n }\n\n const normalizedArgs = args[0] === 'lineage' ? args.slice(1) : args;\n const [command] = normalizedArgs;\n if (command === 'start') {\n start(config, normalizedArgs.slice(1));\n return;\n }\n\n if (command === 'next' || command === 'brief' || command === 'inspect' || command === 'link-child') {\n const commandArgs = normalizedArgs.slice(1);\n const json = commandArgs.includes('--json');\n try {\n printDataResult(command, runLineageDataCommand(command, commandArgs), json);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (json) console.error(JSON.stringify({ ok: false, command, error: message }, null, 2));\n else console.error(`${config.binName}: ${message}`);\n process.exit(1);\n }\n process.exit(0);\n }\n\n const json = args.includes('--json');\n const message = `Unknown command: ${command}`;\n if (json) console.error(JSON.stringify({ ok: false, command, error: message }, null, 2));\n else console.error(`${config.binName}: ${message}`);\n process.exit(1);\n}\n", "import { existsSync, mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\nimport { spawnSync } from 'node:child_process';\nimport { fileURLToPath } from 'node:url';\nimport { createS3StorageAdapter } from './adapters/storage';\nimport { listLocalReviewAssets, localPreviewPath as resolveLocalPreviewPath } from './localReview';\nimport { syncLedgerPlacement } from './assetLedgerWorkflow';\nimport { appName } from '../shared/appConstants';\nimport type {\n AssetCatalog,\n AssetContentType,\n AssetFacets,\n DoctorReport,\n AssetLibrarySnapshot,\n GrowthAsset,\n ListAssetsOptions,\n LiveS3Object,\n MutationResponse,\n PlacementFields,\n PlacementStatus,\n PresignResponse,\n ProjectSummary,\n UploadFields,\n} from '../shared/types';\n\nfunction isPackageRoot(path: string): boolean {\n const packageJson = join(path, 'package.json');\n if (!existsSync(packageJson)) return false;\n try {\n const packageInfo = JSON.parse(readFileSync(packageJson, 'utf8')) as { name?: string };\n return packageInfo.name === '@mean-weasel/lineage';\n } catch {\n return false;\n }\n}\n\nfunction resolveRepoRoot(): string {\n const moduleDir = dirname(fileURLToPath(import.meta.url));\n const candidates = [\n process.env.LINEAGE_REPO_ROOT,\n resolve(moduleDir, '..'),\n resolve(moduleDir, '../..'),\n process.cwd(),\n ].filter((candidate): candidate is string => Boolean(candidate));\n const root = candidates.find(isPackageRoot);\n if (!root) throw new Error('Unable to locate Lineage package root');\n return root;\n}\n\nexport const repoRoot = resolveRepoRoot();\nexport const defaultProject = 'demo-project';\nexport const defaultProduct = process.env.LINEAGE_DEFAULT_PRODUCT || defaultProject;\nconst publicFallbackBucket = 'lineage-demo-assets';\nconst publicFallbackRegion = 'us-east-1';\nconst contentTypes = new Set<AssetContentType>(['image', 'video', 'gif', 'audio', 'doc', 'other']);\nconst baseChannels = ['linkedin', 'meta', 'tiktok', 'x-twitter', 'youtube'];\nconst placementStatuses = new Set<PlacementStatus>(['planned', 'scheduled', 'posted', 'skipped']);\nconst projectNamePattern = /^[a-z0-9][a-z0-9-]*$/;\n\ninterface CommandResult {\n stdout: string;\n stderr: string;\n}\n\nclass LineageAssetError extends Error {\n constructor(message: string, public status = 400) {\n super(message);\n }\n}\n\nexport function isLineageAssetError(error: unknown): error is LineageAssetError {\n return error instanceof LineageAssetError;\n}\n\nexport function cleanProject(project = defaultProject): string {\n if (!projectNamePattern.test(project)) {\n throw new LineageAssetError('Project must be lowercase kebab-case');\n }\n return project;\n}\n\nexport function catalogPath(project = defaultProject): string {\n return join(repoRoot, cleanProject(project), 'assets', 'catalog.json');\n}\n\nfunction fixtureCatalogPath(project = defaultProject): string {\n return join(repoRoot, 'fixtures', cleanProject(project), 'assets', 'catalog.json');\n}\n\nfunction resolvedCatalogPath(project = defaultProject): string {\n const path = catalogPath(project);\n if (existsSync(path)) return path;\n const clean = cleanProject(project);\n if (clean === defaultProject && existsSync(fixtureCatalogPath(clean))) return fixtureCatalogPath(clean);\n return path;\n}\n\nexport function normalizeCatalog(catalog: Partial<AssetCatalog>, fallbackProject = defaultProject): AssetCatalog {\n const project = cleanProject(catalog.project || catalog.product || fallbackProject);\n const product = catalog.product || project;\n return {\n ...catalog,\n project,\n product,\n default_bucket: catalog.default_bucket || '',\n default_region: catalog.default_region || '',\n assets: (catalog.assets || []).map(asset => ({\n ...asset,\n source: asset.source || 'catalog',\n project: asset.project || asset.product || project,\n product: asset.product || asset.project || project,\n })),\n };\n}\n\nfunction fallbackS3(assetId: string, channel: string, status = 'working') {\n return {\n bucket: publicFallbackBucket,\n checksum_sha256: undefined,\n content_type: 'image/png',\n key: `products/${defaultProject}/campaigns/2026-06-public-demo/channels/${channel}/audiences/creators/statuses/${status}/types/image/assets/${assetId}/${assetId}.png`,\n region: publicFallbackRegion,\n size_bytes: 2048,\n updated_at: '2026-06-24T12:00:00.000Z',\n version_id: 'public-demo-version',\n };\n}\n\nfunction fallbackAsset(fields: Omit<GrowthAsset, 'audience' | 'campaign' | 'content_type' | 'cta' | 'hook' | 'product' | 'project' | 'source' | 'utm_content'> & {\n audience?: string;\n campaign?: string;\n cta?: string;\n hook?: string;\n utm_content?: string;\n}): GrowthAsset {\n return {\n audience: fields.audience || 'creators',\n campaign: fields.campaign || '2026-06-public-demo',\n content_type: 'image',\n cta: fields.cta || 'Save the idea',\n hook: fields.hook || 'Public demo creative for local review.',\n product: defaultProject,\n project: defaultProject,\n source: 'catalog',\n utm_content: fields.utm_content || fields.asset_id.replace(/-/g, '_'),\n ...fields,\n };\n}\n\nfunction defaultFallbackCatalog(): AssetCatalog {\n return normalizeCatalog({\n assets: [\n fallbackAsset({\n asset_id: 'demo-meta-short-form-upload-demo-post-static',\n channel: 'meta',\n s3: fallbackS3('demo-meta-short-form-upload-demo-post-static', 'meta'),\n status: 'working',\n title: 'Meta short-form demo post static',\n }),\n fallbackAsset({\n asset_id: 'demo-linkedin-ledger-catalog-shared',\n channel: 'linkedin',\n hook: 'Shared ledger creative with catalog metadata.',\n s3: fallbackS3('demo-linkedin-ledger-catalog-shared', 'linkedin'),\n status: 'working',\n title: 'LinkedIn ledger catalog shared',\n }),\n fallbackAsset({\n asset_id: 'demo-linkedin-upload-demo-done-static-grounded-v2',\n channel: 'linkedin',\n placements: [{\n channel: 'linkedin',\n notes: 'Synthetic public scheduled placement.',\n scheduled_at: '2026-06-24T16:00:00-07:00',\n status: 'scheduled',\n updated_at: '2026-06-24T12:30:00.000Z',\n }],\n s3: fallbackS3('demo-linkedin-upload-demo-done-static-grounded-v2', 'linkedin', 'approved'),\n status: 'approved',\n title: 'LinkedIn upload demo scheduled static',\n }),\n fallbackAsset({\n asset_id: 'demo-tiktok-upload-demo-export-vertical',\n channel: 'tiktok',\n format: 'vertical',\n hook: 'Fast vertical demo export for content queue tests.',\n s3: fallbackS3('demo-tiktok-upload-demo-export-vertical', 'tiktok'),\n status: 'working',\n title: 'TikTok upload demo export vertical',\n }),\n fallbackAsset({\n asset_id: 'demo-youtube-short-demo-posted-cut',\n channel: 'youtube',\n placements: [{\n channel: 'youtube',\n notes: 'Synthetic public posted placement.',\n posted_at: '2026-06-25T16:00:00-07:00',\n status: 'posted',\n updated_at: '2026-06-25T17:00:00.000Z',\n }],\n s3: fallbackS3('demo-youtube-short-demo-posted-cut', 'youtube', 'published'),\n status: 'published',\n title: 'YouTube short demo posted cut',\n }),\n fallbackAsset({\n asset_id: 'demo-x-twitter-carousel-demo-working-static',\n channel: 'x-twitter',\n format: 'static',\n s3: fallbackS3('demo-x-twitter-carousel-demo-working-static', 'x-twitter'),\n status: 'working',\n title: 'X Twitter carousel demo working static',\n }),\n ],\n default_bucket: '',\n default_region: '',\n product: defaultProject,\n project: defaultProject,\n }, defaultProject);\n}\n\nfunction isDefaultFallbackCatalog(catalog: AssetCatalog): boolean {\n return catalog.project === defaultProject && !existsSync(catalogPath(defaultProject));\n}\n\nfunction fallbackPreviewDataUrl(asset: GrowthAsset): string {\n const label = `${asset.title}\\n${asset.channel} / ${asset.status}`;\n const svg = `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1200\" height=\"675\" viewBox=\"0 0 1200 675\"><rect width=\"1200\" height=\"675\" fill=\"#f7f5ef\"/><rect x=\"56\" y=\"56\" width=\"1088\" height=\"563\" rx=\"18\" fill=\"#10201c\"/><text x=\"96\" y=\"145\" fill=\"#9fe6c8\" font-family=\"Arial, sans-serif\" font-size=\"34\" font-weight=\"700\">Lineage public demo preview</text><text x=\"96\" y=\"230\" fill=\"#fff8e6\" font-family=\"Arial, sans-serif\" font-size=\"56\" font-weight=\"700\">${escapeSvgText(asset.asset_id)}</text><text x=\"96\" y=\"330\" fill=\"#d9e8df\" font-family=\"Arial, sans-serif\" font-size=\"34\">${escapeSvgText(label)}</text><text x=\"96\" y=\"500\" fill=\"#9fb7ae\" font-family=\"Arial, sans-serif\" font-size=\"26\">Synthetic local placeholder. No external storage requested.</text></svg>`;\n return `data:image/svg+xml;base64,${Buffer.from(svg).toString('base64')}`;\n}\n\nfunction escapeSvgText(value: string): string {\n return value\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;');\n}\n\nexport function loadCatalog(project = defaultProject): AssetCatalog {\n const path = catalogPath(project);\n if (existsSync(path)) {\n try {\n return normalizeCatalog(JSON.parse(readFileSync(path, 'utf8')) as Partial<AssetCatalog>, project);\n } catch (error) {\n if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {\n throw new LineageAssetError(`Missing catalog: ${path}`, 404);\n }\n throw error;\n }\n }\n const clean = cleanProject(project);\n if (clean === defaultProject) {\n const fixturePath = fixtureCatalogPath(clean);\n if (existsSync(fixturePath)) {\n return normalizeCatalog(JSON.parse(readFileSync(fixturePath, 'utf8')) as Partial<AssetCatalog>, project);\n }\n return defaultFallbackCatalog();\n }\n throw new LineageAssetError(`Missing catalog: ${path}`, 404);\n}\n\nfunction saveCatalog(project: string, catalog: AssetCatalog): AssetCatalog {\n const normalized = normalizeCatalog(catalog, project);\n mkdirSync(dirname(catalogPath(project)), { recursive: true });\n writeFileSync(catalogPath(project), `${JSON.stringify(normalized, null, 2)}\\n`);\n return normalized;\n}\n\nfunction run(command: string, args: string[]): CommandResult {\n const result = spawnSync(command, args, {\n cwd: repoRoot,\n encoding: 'utf8',\n stdio: ['ignore', 'pipe', 'pipe'],\n env: {\n ...process.env,\n AWS_REGION: process.env.AWS_REGION || 'us-east-1',\n AWS_DEFAULT_REGION: process.env.AWS_DEFAULT_REGION || 'us-east-1',\n },\n });\n\n if (result.status !== 0) {\n const detail = result.stderr.trim() || result.stdout.trim();\n throw new LineageAssetError(`${command} ${args.join(' ')} failed${detail ? `: ${detail}` : ''}`, 502);\n }\n\n return { stdout: result.stdout, stderr: result.stderr };\n}\n\nfunction runAws(args: string[]): CommandResult {\n return run('aws', args);\n}\n\nexport function listProjects(): ProjectSummary[] {\n const projects = readdirSync(repoRoot, { withFileTypes: true })\n .filter(entry => entry.isDirectory() && projectNamePattern.test(entry.name) && existsSync(catalogPath(entry.name)))\n .flatMap(entry => {\n try {\n const catalog = loadCatalog(entry.name);\n return [{ project: catalog.project, product: catalog.product, catalogPath: resolvedCatalogPath(entry.name), default_bucket: catalog.default_bucket, default_region: catalog.default_region, asset_count: catalog.assets.length }];\n } catch (error) {\n if (error instanceof LineageAssetError && error.status === 404) return [];\n throw error;\n }\n })\n .sort((a, b) => a.project.localeCompare(b.project));\n if (!projects.some(item => item.project === defaultProject)) {\n const catalog = loadCatalog(defaultProject);\n projects.push({ project: catalog.project, product: catalog.product, catalogPath: resolvedCatalogPath(defaultProject), default_bucket: catalog.default_bucket, default_region: catalog.default_region, asset_count: catalog.assets.length });\n projects.sort((a, b) => a.project.localeCompare(b.project));\n }\n return projects;\n}\n\nfunction assetById(catalog: AssetCatalog, assetId: string): GrowthAsset {\n const asset = catalog.assets.find(item => item.asset_id === assetId);\n if (!asset) throw new LineageAssetError(`Unknown asset: ${assetId}`, 404);\n return asset;\n}\n\nconst storageAdapter = createS3StorageAdapter({\n assetById,\n cleanProject,\n createError: (message, status) => new LineageAssetError(message, status),\n defaultProject,\n loadCatalog,\n runAws,\n repoRoot,\n saveCatalog,\n supportedContentTypes: contentTypes,\n});\n\nfunction uniqueSorted<T extends string>(values: Array<T | undefined>): T[] {\n return Array.from(new Set(values.filter(Boolean) as T[])).sort();\n}\n\nfunction facetsFor(assets: GrowthAsset[]): AssetFacets {\n return {\n audiences: uniqueSorted(assets.map(asset => asset.audience)),\n campaigns: uniqueSorted(assets.map(asset => asset.campaign)),\n channels: uniqueSorted([...baseChannels, ...assets.map(asset => asset.channel)]),\n contentTypes: uniqueSorted(assets.map(asset => asset.content_type)),\n placementStatuses: uniqueSorted(assets.flatMap(asset => asset.placements?.map(placement => placement.status) || [])),\n statuses: uniqueSorted(assets.map(asset => asset.status)),\n totalSizeBytes: assets.reduce((sum, asset) => sum + (asset.s3?.size_bytes || 0), 0),\n };\n}\n\nfunction filteredAssets(assets: GrowthAsset[], options: ListAssetsOptions): GrowthAsset[] {\n const query = options.query?.trim().toLowerCase();\n return assets.filter(asset => {\n if (options.status && options.status !== 'all' && asset.status !== options.status) return false;\n if (options.channel && options.channel !== 'all' && asset.channel !== options.channel) return false;\n if (options.type && options.type !== 'all' && asset.content_type !== options.type) return false;\n if (options.placementStatus === 'not-posted' && asset.placements?.some(placement => placement.status === 'posted')) return false;\n if (options.placementStatus && !['all', 'not-posted'].includes(options.placementStatus) && !asset.placements?.some(placement => placement.status === options.placementStatus)) return false;\n if (options.campaign && options.campaign !== 'all' && asset.campaign !== options.campaign) return false;\n if (options.audience && options.audience !== 'all' && asset.audience !== options.audience) return false;\n if (!query) return true;\n return [asset.asset_id, asset.title, asset.campaign, asset.channel, asset.audience, asset.hook, asset.cta]\n .join(' ')\n .toLowerCase()\n .includes(query);\n });\n}\n\nexport function listAssets(project = defaultProject, options: ListAssetsOptions = {}): AssetLibrarySnapshot {\n const catalog = loadCatalog(project);\n const pageSize = Math.min(Math.max(Number(options.pageSize || 10), 1), 100);\n const page = Math.max(Number(options.page || 1), 1);\n const localAssets = listLocalReviewAssets(repoRoot, catalog.project, catalog);\n const source = options.source || 'catalog';\n const sourceAssets = source === 'local' ? localAssets : source === 'all' ? [...localAssets, ...catalog.assets] : catalog.assets;\n const filtered = filteredAssets(sourceAssets, options);\n const totalPages = Math.max(Math.ceil(filtered.length / pageSize), 1);\n const safePage = Math.min(page, totalPages);\n const start = (safePage - 1) * pageSize;\n const pageAssets = filtered.slice(start, start + pageSize);\n let liveObjects: LiveS3Object[] = [];\n let error: string | undefined;\n if (options.includeLive && !isDefaultFallbackCatalog(catalog)) {\n try {\n liveObjects = storageAdapter.listLiveObjects(catalog);\n } catch (err) {\n error = err instanceof Error ? err.message : String(err);\n }\n }\n return {\n catalog: { project: catalog.project, product: catalog.product, default_bucket: catalog.default_bucket, default_region: catalog.default_region, asset_count: catalog.assets.length },\n assets: pageAssets,\n facets: facetsFor(catalog.assets),\n pagination: { page: safePage, pageSize, total: filtered.length, totalPages },\n liveObjects,\n orphanObjects: liveObjects.filter(object => !object.cataloged),\n identity: options.includeLive && !isDefaultFallbackCatalog(catalog) ? storageAdapter.getIdentity() : undefined,\n fetchedAt: new Date().toISOString(),\n error,\n };\n}\n\nexport function inspectAsset(project: string, assetId: string): GrowthAsset {\n return assetById(loadCatalog(project), assetId);\n}\n\nexport function validateProject(project = defaultProject): ProjectSummary {\n const catalog = loadCatalog(project);\n return { project: catalog.project, product: catalog.product, catalogPath: resolvedCatalogPath(project), default_bucket: catalog.default_bucket, default_region: catalog.default_region, asset_count: catalog.assets.length };\n}\n\nexport function doctorProject(project = defaultProject, options: { includeLive?: boolean } = {}): DoctorReport {\n const summary = validateProject(project);\n let liveCheck: DoctorReport['liveCheck'] = 'skipped';\n let liveError: string | undefined;\n if (options.includeLive && isDefaultFallbackCatalog(loadCatalog(project))) {\n liveCheck = 'skipped';\n liveError = `${appName} public fallback uses local catalog data only.`;\n } else if (options.includeLive) {\n try {\n storageAdapter.listLiveObjects(loadCatalog(project));\n liveCheck = 'ok';\n } catch (error) {\n liveCheck = 'error';\n liveError = error instanceof Error ? error.message : String(error);\n }\n }\n return { catalogExists: true, deleteEnabled: process.env.LINEAGE_ENABLE_CLOUD_DELETE === 'true', project: summary, liveCheck, liveError };\n}\n\nexport function pullAsset(project: string, assetId: string, out = '.asset-scratch'): MutationResponse {\n return storageAdapter.pullAsset(project, assetId, out);\n}\n\nfunction placementFromFields(fields: PlacementFields) {\n if (!fields.channel) throw new LineageAssetError('Placement requires channel');\n if (!placementStatuses.has(fields.status)) throw new LineageAssetError(`Unsupported placement status: ${fields.status}`);\n const now = new Date().toISOString();\n return {\n channel: fields.channel,\n status: fields.status,\n ...(fields.scheduledAt ? { scheduled_at: fields.scheduledAt } : {}),\n ...(fields.postedAt ? { posted_at: fields.postedAt } : {}),\n ...(fields.url ? { url: fields.url } : {}),\n ...(fields.notes ? { notes: fields.notes } : {}),\n updated_at: now,\n };\n}\n\nexport function previewPlacement(project: string, fields: PlacementFields) {\n const asset = inspectAsset(project, fields.assetId);\n return { asset_id: asset.asset_id, placement: placementFromFields(fields) };\n}\n\nexport function updatePlacement(project: string, fields: PlacementFields): MutationResponse {\n if (!fields.confirmWrite) throw new LineageAssetError('Placement updates require confirmWrite=true');\n const catalog = loadCatalog(project);\n const asset = assetById(catalog, fields.assetId);\n const placement = placementFromFields(fields);\n const existing = asset.placements?.findIndex(item => item.channel === placement.channel);\n if (existing !== undefined && existing >= 0) asset.placements![existing] = placement;\n else asset.placements = [...(asset.placements || []), placement];\n saveCatalog(project, catalog);\n syncLedgerPlacement(project, asset.asset_id, placement);\n return { ok: true, message: `Marked ${asset.asset_id} ${placement.status} for ${placement.channel}`, catalog };\n}\n\nexport function presignAsset(project: string, assetId: string, expiresIn = 900): PresignResponse {\n const catalog = loadCatalog(project);\n if (isDefaultFallbackCatalog(catalog)) {\n const asset = assetById(catalog, assetId);\n return { assetId: asset.asset_id, expiresIn, url: fallbackPreviewDataUrl(asset) };\n }\n return storageAdapter.presignAsset(project, assetId, expiresIn);\n}\n\nexport function localPreviewPath(relativePath: string): string {\n try {\n return resolveLocalPreviewPath(repoRoot, relativePath);\n } catch (error) {\n throw new LineageAssetError(error instanceof Error ? error.message : 'Unknown local review asset', 404);\n }\n}\n\nexport function promoteAsset(project: string, assetId: string, confirmWrite: boolean): MutationResponse {\n return storageAdapter.promoteAsset(project, assetId, confirmWrite);\n}\n\nexport function archiveAsset(project: string, assetId: string, confirmArchive: boolean): MutationResponse {\n if (!confirmArchive) throw new LineageAssetError('Archive requires confirmArchive=true');\n const catalog = loadCatalog(project);\n const asset = assetById(catalog, assetId);\n asset.status = 'archived';\n saveCatalog(project, catalog);\n return { ok: true, message: `Archived ${assetId}`, catalog };\n}\n\nexport function uploadAsset(file: string, fields: UploadFields): MutationResponse {\n return storageAdapter.uploadAsset(file, fields);\n}\n\nexport function deleteObjectGuarded(project: string, assetId: string, confirmation: string): MutationResponse {\n return storageAdapter.deleteObjectGuarded(project, assetId, confirmation);\n}\n\nexport function ensureUploadDir(): string {\n const dir = join(repoRoot, '.asset-scratch', 'studio-uploads');\n mkdirSync(dir, { recursive: true });\n return dir;\n}\n\nexport function cleanupUploadedTemp(file?: string): void {\n if (!file) return;\n const uploadRoot = ensureUploadDir();\n const resolved = resolve(file);\n if (resolved.startsWith(`${uploadRoot}/`) && existsSync(resolved)) {\n unlinkSync(resolved);\n }\n}\n", "import { copyFileSync, existsSync, mkdirSync, statSync } from 'node:fs';\nimport { basename, dirname, join } from 'node:path';\nimport { contentTypeFor, fileSha256 } from '../../localReview';\nimport type { AssetCatalog, LiveS3Object, MutationResponse, PresignResponse } from '../../../shared/types';\nimport type { StorageAdapter, StorageAdapterDependencies } from './types';\n\nexport function parseAssetIdFromS3Key(key: string): string | undefined {\n const marker = '/assets/';\n const index = key.indexOf(marker);\n if (index === -1) return undefined;\n return key.slice(index + marker.length).split('/')[0];\n}\n\nfunction previewDataUrl(asset: { asset_id: string; channel?: string; status?: string; title?: string }): string {\n const title = asset.title || asset.asset_id;\n const label = `${asset.channel || 'catalog'} / ${asset.status || 'working'}`;\n const svg = `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1200\" height=\"675\" viewBox=\"0 0 1200 675\"><rect width=\"1200\" height=\"675\" fill=\"#f7f5ef\"/><rect x=\"56\" y=\"56\" width=\"1088\" height=\"563\" rx=\"18\" fill=\"#10201c\"/><text x=\"96\" y=\"145\" fill=\"#9fe6c8\" font-family=\"Arial, sans-serif\" font-size=\"34\" font-weight=\"700\">Lineage catalog preview</text><text x=\"96\" y=\"230\" fill=\"#fff8e6\" font-family=\"Arial, sans-serif\" font-size=\"56\" font-weight=\"700\">${escapeSvgText(asset.asset_id)}</text><text x=\"96\" y=\"330\" fill=\"#d9e8df\" font-family=\"Arial, sans-serif\" font-size=\"34\">${escapeSvgText(title)}</text><text x=\"96\" y=\"500\" fill=\"#9fb7ae\" font-family=\"Arial, sans-serif\" font-size=\"26\">${escapeSvgText(label)}. No external storage requested.</text></svg>`;\n return `data:image/svg+xml;base64,${Buffer.from(svg).toString('base64')}`;\n}\n\nfunction escapeSvgText(value: string): string {\n return value\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;');\n}\n\nexport function createS3StorageAdapter(deps: StorageAdapterDependencies): StorageAdapter {\n return {\n deleteObjectGuarded(project, assetId, confirmation): MutationResponse {\n const enabled = process.env.LINEAGE_ENABLE_CLOUD_DELETE === 'true';\n if (!enabled) {\n throw deps.createError('S3 delete is disabled. Use archive unless a human enables LINEAGE_ENABLE_CLOUD_DELETE.', 403);\n }\n if (confirmation !== `delete ${assetId}`) {\n throw deps.createError(`Delete confirmation must exactly equal: delete ${assetId}`);\n }\n const catalog = deps.loadCatalog(project);\n const asset = deps.assetById(catalog, assetId);\n if (!asset.s3) throw deps.createError(`Asset has no S3 object: ${assetId}`);\n deps.runAws(['s3api', 'delete-object', '--bucket', asset.s3.bucket, '--key', asset.s3.key, '--region', asset.s3.region]);\n asset.status = 'archived';\n deps.saveCatalog(project, catalog);\n return { ok: true, message: `Deleted current S3 object and archived ${assetId}`, catalog };\n },\n\n getIdentity() {\n try {\n const output = deps.runAws(['sts', 'get-caller-identity', '--query', '{Account:Account,Arn:Arn}', '--output', 'json']);\n const parsed = JSON.parse(output.stdout) as { Account: string; Arn: string };\n return { account: parsed.Account, arn: parsed.Arn };\n } catch {\n return undefined;\n }\n },\n\n listLiveObjects(catalog: AssetCatalog): LiveS3Object[] {\n const bucket = catalog.default_bucket;\n const region = catalog.default_region;\n // Existing uploaded objects live under products/<project>; do not rewrite keys during project migration.\n const prefix = `products/${catalog.product}/`;\n const output = deps.runAws(['s3api', 'list-objects-v2', '--bucket', bucket, '--prefix', prefix, '--region', region, '--output', 'json']);\n const parsed = JSON.parse(output.stdout) as {\n Contents?: Array<{ Key: string; Size: number; LastModified: string; StorageClass?: string }>;\n };\n const catalogKeys = new Set(catalog.assets.map(asset => asset.s3?.key).filter(Boolean));\n return (parsed.Contents || []).map(item => ({\n key: item.Key,\n size: item.Size,\n lastModified: item.LastModified,\n storageClass: item.StorageClass,\n cataloged: catalogKeys.has(item.Key),\n assetId: parseAssetIdFromS3Key(item.Key),\n }));\n },\n\n presignAsset(project, assetId, expiresIn = 900): PresignResponse {\n const catalog = deps.loadCatalog(project);\n const asset = deps.assetById(catalog, assetId);\n return { assetId, expiresIn, url: previewDataUrl(asset) };\n },\n\n promoteAsset(project, assetId, confirmWrite): MutationResponse {\n if (!confirmWrite) throw deps.createError('Promote requires confirmWrite=true');\n const catalog = deps.loadCatalog(project);\n const asset = deps.assetById(catalog, assetId);\n asset.status = 'published';\n deps.saveCatalog(project, catalog);\n return {\n ok: true,\n message: `Promoted ${assetId}`,\n catalog,\n };\n },\n\n pullAsset(project, assetId, out = '.asset-scratch'): MutationResponse {\n const catalog = deps.loadCatalog(project);\n const asset = deps.assetById(catalog, assetId);\n return {\n ok: true,\n message: `Prepared ${assetId} for local review`,\n output: {\n assetId: asset.asset_id,\n out,\n storage: asset.local ? 'local' : asset.s3 ? 'catalog-s3-metadata' : 'catalog',\n note: 'Lineage public package does not pull cloud objects automatically.',\n },\n };\n },\n\n uploadAsset(file, fields): MutationResponse {\n if (!fields.confirmWrite) throw deps.createError('Upload requires confirmWrite=true');\n if (!existsSync(file)) throw deps.createError(`Upload file missing: ${file}`, 404);\n if (!['working', 'published'].includes(fields.status)) throw deps.createError('Upload status must be working or published');\n if (!deps.supportedContentTypes.has(fields.type)) throw deps.createError(`Unsupported asset type: ${fields.type}`);\n\n const project = deps.cleanProject(fields.project || fields.product || deps.defaultProject);\n const catalog = deps.loadCatalog(project);\n const relativePath = join('uploads', project, fields.assetId, basename(file));\n const absolutePath = join(deps.repoRoot, '.asset-scratch', relativePath);\n mkdirSync(dirname(absolutePath), { recursive: true });\n copyFileSync(file, absolutePath);\n const stats = statSync(absolutePath);\n const contentType = contentTypeFor(absolutePath);\n const checksumSha256 = fileSha256(absolutePath);\n const now = new Date().toISOString();\n const nextAsset = {\n asset_id: fields.assetId,\n audience: fields.audience,\n campaign: fields.campaign,\n channel: fields.channel,\n content_type: fields.type,\n cta: fields.cta,\n hook: fields.hook,\n ...(fields.format ? { format: fields.format } : {}),\n local: {\n absolute_path: absolutePath,\n checksum_sha256: checksumSha256,\n content_type: contentType,\n relative_path: relativePath,\n size_bytes: stats.size,\n updated_at: now,\n },\n ...(fields.messageFamily ? { message_family: fields.messageFamily } : {}),\n ...(fields.notes ? { notes: fields.notes } : {}),\n product: project,\n project,\n source: 'catalog' as const,\n status: fields.status,\n title: fields.title,\n utm_content: fields.utmContent,\n };\n const existing = catalog.assets.findIndex(asset => asset.asset_id === fields.assetId);\n if (existing >= 0) catalog.assets[existing] = { ...catalog.assets[existing], ...nextAsset };\n else catalog.assets.push(nextAsset);\n deps.saveCatalog(project, catalog);\n return {\n ok: true,\n message: `Recorded ${fields.assetId} locally`,\n output: {\n file: basename(absolutePath),\n relativePath,\n sizeBytes: stats.size,\n contentType,\n checksumSha256,\n },\n catalog,\n };\n },\n };\n}\n", "import { createHash } from 'node:crypto';\nimport { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';\nimport { basename, extname, join, relative, resolve } from 'node:path';\nimport type { AssetCatalog, AssetContentType, GrowthAsset } from '../shared/types';\n\nconst mimeByExt: Record<string, string> = {\n '.gif': 'image/gif',\n '.jpeg': 'image/jpeg',\n '.jpg': 'image/jpeg',\n '.mov': 'video/quicktime',\n '.mp4': 'video/mp4',\n '.png': 'image/png',\n '.svg': 'image/svg+xml',\n '.webp': 'image/webp',\n};\nconst localReviewExts = new Set(Object.keys(mimeByExt));\nconst channelFromName = /\\b(linkedin|meta|tiktok|youtube|x-twitter|x)\\b/i;\nconst campaignFromPath = /\\b(20\\d{2}-\\d{2}-[a-z0-9-]+)\\b/i;\n\nclass LocalReviewError extends Error {\n status = 400;\n}\n\nfunction localReviewRoot(repoRoot: string): string {\n return join(repoRoot, '.asset-scratch');\n}\n\nexport function contentTypeFor(file: string): string {\n return mimeByExt[extname(file).toLowerCase()] || 'application/octet-stream';\n}\n\nexport function fileSha256(file: string): string {\n return createHash('sha256').update(readFileSync(file)).digest('hex');\n}\n\nfunction isPathInside(child: string, parent: string): boolean {\n const relativePath = relative(parent, child);\n return Boolean(relativePath) && !relativePath.startsWith('..') && !relativePath.startsWith('/');\n}\n\nfunction walkLocalReviewFiles(dir: string, files: string[] = []): string[] {\n if (!existsSync(dir)) return files;\n let entries;\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return files;\n throw error;\n }\n for (const entry of entries) {\n if (entry.name === 'node_modules' || entry.name === '.git' || entry.name === 'studio-uploads') continue;\n if (process.env.NODE_ENV !== 'test' && /^vitest-/.test(entry.name)) continue;\n const path = join(dir, entry.name);\n if (entry.isDirectory()) walkLocalReviewFiles(path, files);\n else if (entry.isFile() && localReviewExts.has(extname(entry.name).toLowerCase())) files.push(path);\n }\n return files;\n}\n\nfunction inferCampaign(relativePath: string): string {\n return campaignFromPath.exec(relativePath)?.[1] || 'local-review';\n}\n\nfunction inferChannel(relativePath: string): string {\n const match = channelFromName.exec(relativePath);\n if (!match) return 'local';\n return match[1].toLowerCase() === 'x' ? 'x-twitter' : match[1].toLowerCase();\n}\n\nfunction inferContentType(file: string): AssetContentType {\n const mime = contentTypeFor(file);\n if (mime.startsWith('image/gif')) return 'gif';\n if (mime.startsWith('image/')) return 'image';\n if (mime.startsWith('video/')) return 'video';\n return 'other';\n}\n\nexport function listLocalReviewAssets(repoRoot: string, project: string, catalog: AssetCatalog): GrowthAsset[] {\n const catalogChecksums = new Set(catalog.assets.map(asset => asset.s3?.checksum_sha256).filter(Boolean));\n const root = localReviewRoot(repoRoot);\n return walkLocalReviewFiles(root)\n .flatMap(file => {\n try {\n const stats = statSync(file);\n const checksum = fileSha256(file);\n const relativePath = relative(root, file);\n return [{ checksum, file, relativePath, stats }];\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return [];\n throw error;\n }\n })\n .filter(item => !catalogChecksums.has(item.checksum))\n .map(item => {\n const fileSlug = basename(item.file, extname(item.file));\n const channel = inferChannel(item.relativePath);\n return {\n asset_id: `local-${item.checksum.slice(0, 12)}`,\n project,\n product: project,\n source: 'local',\n campaign: inferCampaign(item.relativePath),\n channel,\n audience: 'local-review',\n status: 'planned',\n content_type: inferContentType(item.file),\n title: fileSlug.replace(/[-_]+/g, ' '),\n hook: item.relativePath,\n cta: 'Review before upload',\n utm_content: fileSlug.replace(/[^a-zA-Z0-9]+/g, '_').replace(/^_+|_+$/g, '').toLowerCase() || 'local_review',\n notes: 'Local pre-push asset. Review and refine before uploading to S3.',\n local: {\n relative_path: item.relativePath,\n absolute_path: item.file,\n size_bytes: item.stats.size,\n content_type: contentTypeFor(item.file),\n checksum_sha256: item.checksum,\n updated_at: item.stats.mtime.toISOString(),\n },\n };\n });\n}\n\nexport function localPreviewPath(repoRoot: string, relativePath: string): string {\n const root = localReviewRoot(repoRoot);\n const resolved = resolve(root, relativePath);\n if (!isPathInside(resolved, root) || !existsSync(resolved)) throw new LocalReviewError('Unknown local review asset');\n if (!localReviewExts.has(extname(resolved).toLowerCase())) throw new LocalReviewError('Local preview type is not supported');\n return resolved;\n}\n", "import { createRequire } from 'node:module';\nimport type { DatabaseSync as DatabaseSyncType } from 'node:sqlite';\nimport { mkdirSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { repoRoot } from './assetCore';\n\nconst require = createRequire(import.meta.url);\nexport type DatabaseSync = DatabaseSyncType;\n\nexport function nowIso(): string {\n return new Date().toISOString();\n}\n\nexport function lineageDbPath(): string {\n return process.env.LINEAGE_DB || join(repoRoot, '.lineage', 'asset-lineage.sqlite');\n}\n\nexport function lineageDb(): DatabaseSync {\n mkdirSync(join(lineageDbPath(), '..'), { recursive: true });\n const { DatabaseSync } = require('node:sqlite') as typeof import('node:sqlite');\n const database = new DatabaseSync(lineageDbPath());\n database.exec('PRAGMA foreign_keys = ON'); database.exec('PRAGMA busy_timeout = 5000');\n database.exec(`\n create table if not exists projects (\n id text primary key,\n product text not null,\n catalog_path text,\n created_at text not null,\n updated_at text not null\n );\n create table if not exists assets (\n id text primary key,\n project_id text not null references projects(id),\n source text not null check (source in ('local', 'catalog')),\n local_path text,\n s3_key text,\n checksum_sha256 text,\n media_type text not null,\n title text not null,\n status text not null,\n channel text,\n campaign text,\n audience text,\n size_bytes integer,\n content_type text,\n created_at text not null,\n updated_at text not null,\n last_seen_at text not null\n );\n create index if not exists assets_project_source_seen on assets(project_id, source, last_seen_at);\n create index if not exists assets_project_checksum on assets(project_id, checksum_sha256);\n create index if not exists assets_project_channel_campaign on assets(project_id, channel, campaign);\n create table if not exists asset_edges (\n id text primary key,\n project_id text not null references projects(id),\n parent_asset_id text not null references assets(id),\n child_asset_id text not null references assets(id),\n relation_type text not null check (relation_type in ('derived_from')),\n created_at text not null,\n unique (project_id, parent_asset_id, child_asset_id, relation_type)\n );\n create index if not exists edges_parent on asset_edges(project_id, parent_asset_id);\n create index if not exists edges_child on asset_edges(project_id, child_asset_id);\n create table if not exists asset_reviews (\n asset_id text primary key references assets(id),\n review_state text not null check (review_state in ('unreviewed', 'approved', 'needs_revision', 'rejected', 'ignored')),\n reviewed_at text,\n ignored_at text,\n notes text,\n updated_at text not null\n );\n create table if not exists asset_selections (\n id text primary key,\n project_id text not null references projects(id),\n root_asset_id text not null references assets(id),\n asset_id text not null references assets(id),\n notes text,\n selected_at text not null,\n unique(project_id, root_asset_id)\n );\n create table if not exists asset_layouts (\n id text primary key,\n project_id text not null references projects(id),\n root_asset_id text not null references assets(id),\n asset_id text not null references assets(id),\n x real not null,\n y real not null,\n updated_at text not null,\n unique(project_id, root_asset_id, asset_id)\n );\n create table if not exists lineage_workspaces (\n id text primary key,\n project_id text not null references projects(id),\n root_asset_id text not null references assets(id),\n title text not null,\n status text not null check (status in ('active', 'paused', 'archived')),\n notes text,\n created_by text not null check (created_by in ('human', 'agent', 'system')),\n active_at text,\n created_at text not null,\n updated_at text not null,\n unique(project_id, root_asset_id)\n );\n create index if not exists lineage_workspaces_project_status on lineage_workspaces(project_id, status, updated_at);\n create index if not exists lineage_workspaces_project_active on lineage_workspaces(project_id, active_at);\n create table if not exists asset_ledger_records (\n id text primary key,\n project_id text not null references projects(id),\n canonical_asset_id text not null,\n checksum_sha256 text,\n media_type text not null,\n title text not null,\n status text not null,\n channel text,\n campaign text,\n audience text,\n created_at text not null,\n updated_at text not null,\n first_seen_at text not null default (datetime('now')),\n last_seen_at text not null\n );\n create index if not exists asset_ledger_records_project_seen on asset_ledger_records(project_id, last_seen_at);\n create index if not exists asset_ledger_records_project_checksum on asset_ledger_records(project_id, checksum_sha256);\n create table if not exists asset_ledger_sources (\n id text primary key,\n project_id text not null references projects(id),\n record_id text not null references asset_ledger_records(id) on delete cascade,\n source_type text not null check (source_type in ('local', 'catalog', 's3')),\n asset_id text,\n local_path text,\n s3_bucket text,\n s3_region text,\n s3_key text,\n s3_version_id text,\n etag text,\n size_bytes integer,\n content_type text,\n updated_at text,\n first_seen_at text not null default (datetime('now')),\n last_seen_at text not null\n );\n create index if not exists asset_ledger_sources_project_type on asset_ledger_sources(project_id, source_type);\n create index if not exists asset_ledger_sources_record on asset_ledger_sources(project_id, record_id);\n create index if not exists asset_ledger_sources_s3_key on asset_ledger_sources(project_id, s3_key);\n create table if not exists asset_ledger_placements (\n id text primary key,\n project_id text not null references projects(id),\n asset_id text not null,\n channel text not null,\n status text not null,\n scheduled_at text,\n posted_at text,\n url text,\n notes text,\n updated_at text not null,\n synced_at text not null,\n unique(project_id, asset_id, channel)\n );\n create index if not exists asset_ledger_placements_project_status on asset_ledger_placements(project_id, status);\n create index if not exists asset_ledger_placements_asset on asset_ledger_placements(project_id, asset_id);\n create table if not exists asset_ledger_index_runs (\n id text primary key,\n project_id text not null references projects(id),\n source_mode text not null check (source_mode in ('all', 'catalog', 'local')),\n include_live_s3 integer not null default 0,\n status text not null check (status in ('running', 'complete', 'failed')),\n started_at text not null,\n completed_at text,\n assets_indexed integer not null default 0,\n records_after integer not null default 0,\n catalog_sources_after integer not null default 0,\n local_sources_after integer not null default 0,\n s3_sources_after integer not null default 0,\n error text\n );\n create index if not exists asset_ledger_index_runs_project_started on asset_ledger_index_runs(project_id, started_at);\n create table if not exists content_batches (\n id text not null,\n project_id text not null references projects(id),\n title text not null,\n campaign text,\n channel text,\n status text not null check (status in ('active', 'archived')),\n notes text,\n created_at text not null,\n updated_at text not null,\n primary key(project_id, id)\n );\n create index if not exists content_batches_project_updated on content_batches(project_id, updated_at);\n create table if not exists content_posts (\n id text not null,\n project_id text not null references projects(id),\n batch_id text not null,\n channel text not null,\n title text not null,\n phase text not null check (phase in ('draft', 'review', 'scheduled', 'posted', 'skipped', 'archived')),\n campaign text,\n body text,\n cta text,\n scheduled_at text,\n posted_at text,\n url text,\n notes text,\n source_path text,\n created_at text not null,\n updated_at text not null,\n primary key(project_id, id),\n foreign key(project_id, batch_id) references content_batches(project_id, id) on delete cascade\n );\n create index if not exists content_posts_project_phase on content_posts(project_id, phase);\n create index if not exists content_posts_batch on content_posts(project_id, batch_id);\n create table if not exists content_post_assets (\n id text primary key,\n project_id text not null references projects(id),\n post_id text not null,\n asset_id text not null,\n role text not null,\n notes text,\n attached_at text not null,\n unique(project_id, post_id, asset_id, role),\n foreign key(project_id, post_id) references content_posts(project_id, id) on delete cascade\n );\n create index if not exists content_post_assets_post on content_post_assets(project_id, post_id);\n create index if not exists content_post_assets_asset on content_post_assets(project_id, asset_id);\n create table if not exists content_targets (\n project_id text primary key references projects(id),\n post_id text not null,\n notes text,\n selected_at text not null,\n updated_at text not null,\n foreign key(project_id, post_id) references content_posts(project_id, id) on delete cascade\n );\n create table if not exists selection_sets (\n id text primary key,\n project_id text not null references projects(id),\n kind text not null check (kind in ('current', 'review')),\n key text not null,\n label text not null,\n status text not null check (status in ('active', 'archived')),\n created_by text not null check (created_by in ('human', 'agent', 'system')),\n created_at text not null,\n updated_at text not null,\n unique(project_id, kind, key)\n );\n create index if not exists selection_sets_project_kind on selection_sets(project_id, kind, updated_at);\n create table if not exists selection_items (\n id text primary key,\n set_id text not null references selection_sets(id) on delete cascade,\n asset_id text not null,\n role text not null check (role in ('primary', 'candidate', 'next_base')),\n variation_label text,\n position integer not null default 0,\n selected_by text check (selected_by in ('human', 'agent', 'system')),\n selected_at text,\n deselected_at text,\n notes text,\n created_at text not null,\n updated_at text not null,\n unique(set_id, asset_id)\n );\n create index if not exists selection_items_set_position on selection_items(set_id, position);\n create unique index if not exists selection_items_set_label on selection_items(set_id, variation_label) where variation_label is not null;\n create table if not exists generation_jobs (\n id text primary key,\n project_id text not null references projects(id),\n provider text not null default 'codex-handoff',\n adapter_version text not null,\n source_mode text not null check (source_mode in ('lineage_selection')),\n root_asset_id text not null references assets(id),\n prompt text not null,\n expected_output_count integer not null check (expected_output_count > 0),\n status text not null check (status in ('planned', 'imported', 'failed', 'cancelled')),\n output_dir text,\n handoff_json text,\n created_at text not null,\n updated_at text not null,\n imported_at text\n );\n create index if not exists generation_jobs_project_created on generation_jobs(project_id, created_at);\n create table if not exists generation_job_inputs (\n id text primary key,\n job_id text not null references generation_jobs(id) on delete cascade,\n project_id text not null references projects(id),\n asset_id text not null references assets(id),\n root_asset_id text not null references assets(id),\n role text not null check (role in ('lineage_next_base', 'reference')),\n position integer not null,\n selection_strategy text not null,\n selection_snapshot_json text not null,\n unique(job_id, asset_id, role)\n );\n create index if not exists generation_job_inputs_job on generation_job_inputs(job_id, position);\n create table if not exists generation_job_outputs (\n id text primary key,\n job_id text not null references generation_jobs(id) on delete cascade,\n project_id text not null references projects(id),\n output_index integer not null,\n file_path text not null,\n checksum_sha256 text not null,\n size_bytes integer not null,\n content_type text not null,\n imported_asset_id text not null references assets(id),\n parent_asset_id text not null references assets(id),\n imported_at text not null,\n unique(job_id, output_index),\n unique(job_id, file_path)\n );\n create index if not exists generation_job_outputs_job on generation_job_outputs(job_id, output_index);\n create table if not exists generation_job_receipts (\n id text primary key,\n job_id text not null references generation_jobs(id) on delete cascade,\n receipt_type text not null check (receipt_type in ('plan', 'import', 'error')),\n status text not null check (status in ('ok', 'error')),\n command text not null,\n payload_json text not null,\n created_at text not null\n );\n create index if not exists generation_job_receipts_job on generation_job_receipts(job_id, created_at);\n create table if not exists adapter_settings (project_id text not null references projects(id), adapter_type text not null check (adapter_type in ('cloud', 'scheduler', 'image_generator')), provider text not null, enabled integer not null check (enabled in (0, 1)), secret_ref text, safe_config_json text not null, created_at text not null, updated_at text not null, primary key(project_id, adapter_type, provider)); create index if not exists adapter_settings_project_type on adapter_settings(project_id, adapter_type);\n `);\n migrateAssetSelections(database);\n dropLegacyAssetSelectionRootUnique(database);\n ensureColumn(database, 'asset_selections', 'notes', 'text');\n ensureColumn(database, 'asset_ledger_records', 'first_seen_at', 'text');\n ensureColumn(database, 'asset_ledger_records', 'indexed_by_run_id', 'text');\n ensureColumn(database, 'asset_ledger_sources', 'first_seen_at', 'text');\n ensureColumn(database, 'asset_ledger_sources', 'indexed_by_run_id', 'text');\n ensureReviewStateValues(database);\n return database;\n}\n\nfunction ensureColumn(database: DatabaseSync, table: string, column: string, definition: string): void {\n const rows = database.prepare(`pragma table_info(${table})`).all() as Array<{ name: string }>;\n if (!rows.some(row => row.name === column)) database.exec(`alter table ${table} add column ${column} ${definition}`);\n}\n\nfunction migrateAssetSelections(database: DatabaseSync): void {\n const rows = database.prepare('pragma table_info(asset_selections)').all() as Array<{ name: string }>;\n if (rows.some(row => row.name === 'position')) return;\n const notesSelect = rows.some(row => row.name === 'notes') ? 'notes' : 'null';\n\n database.exec(`\n create table if not exists asset_selections_v2 (\n id text primary key,\n project_id text not null references projects(id),\n root_asset_id text not null references assets(id),\n asset_id text not null references assets(id),\n position integer not null default 0,\n notes text,\n selected_at text not null,\n unique(project_id, root_asset_id, asset_id)\n );\n insert or ignore into asset_selections_v2 (id, project_id, root_asset_id, asset_id, position, notes, selected_at)\n select\n project_id || ':' || root_asset_id || ':selected:' || asset_id,\n project_id,\n root_asset_id,\n asset_id,\n 0,\n ${notesSelect},\n selected_at\n from asset_selections;\n drop table asset_selections;\n alter table asset_selections_v2 rename to asset_selections;\n create index if not exists asset_selections_project_root_position\n on asset_selections(project_id, root_asset_id, position, selected_at);\n `);\n}\n\nfunction dropLegacyAssetSelectionRootUnique(database: DatabaseSync): void {\n const indexes = database.prepare('pragma index_list(asset_selections)').all() as Array<{ name: string; unique: number }>;\n for (const index of indexes) {\n if (!index.unique) continue;\n const columns = database.prepare(`pragma index_info(${index.name})`).all() as Array<{ name: string }>;\n const columnNames = columns.map(column => column.name).join(',');\n if (columnNames === 'project_id,root_asset_id') database.exec(`drop index if exists ${index.name}`);\n }\n}\n\nfunction ensureReviewStateValues(database: DatabaseSync): void {\n const createSql = database.prepare(\"select sql from sqlite_master where type = 'table' and name = 'asset_reviews'\").get() as { sql?: string } | undefined;\n if (createSql?.sql?.includes('needs_revision')) return;\n\n database.exec(`\n alter table asset_reviews rename to asset_reviews_old;\n create table asset_reviews (\n asset_id text primary key references assets(id),\n review_state text not null check (review_state in ('unreviewed', 'approved', 'needs_revision', 'rejected', 'ignored')),\n reviewed_at text,\n ignored_at text,\n notes text,\n updated_at text not null\n );\n insert into asset_reviews (asset_id, review_state, reviewed_at, ignored_at, notes, updated_at)\n select asset_id, review_state, reviewed_at, ignored_at, notes, updated_at\n from asset_reviews_old;\n drop table asset_reviews_old;\n `);\n}\n", "import type { SelectionFields } from '../shared/types';\nimport type { DatabaseSync } from './assetLineageDb';\n\nexport const LINEAGE_NEXT_VARIATION_LIMIT = 3;\n\nexport interface LineageSelectionRow {\n asset_id: string;\n notes?: string;\n position: number;\n selected_at: string;\n}\n\nexport function selectionId(project: string, root: string, assetId: string): string {\n return `${project}:${root}:selected:${assetId}`;\n}\n\nexport function selectedRows(database: DatabaseSync, project: string, root: string): LineageSelectionRow[] {\n return database.prepare(`\n select asset_id, notes, position, selected_at\n from asset_selections\n where project_id = ? and root_asset_id = ?\n order by position, selected_at, asset_id\n `).all(project, root) as unknown as LineageSelectionRow[];\n}\n\nexport function normalizeSelectionInput(fields: SelectionFields): string[] {\n return [...new Set([...(fields.assetIds || []), fields.assetId || ''].map(assetId => assetId.trim()).filter(Boolean))];\n}\n", "import { lineageDb, nowIso, type DatabaseSync } from './assetLineageDb';\nimport type {\n LineageWorkspace,\n LineageWorkspaceActor,\n LineageWorkspaceFields,\n LineageWorkspaceSnapshot,\n LineageWorkspaceStatus,\n LineageWorkspaceUpdateFields,\n} from '../shared/types';\n\ntype Row = Record<string, unknown>;\n\nconst actors = new Set<LineageWorkspaceActor>(['human', 'agent', 'system']);\nconst statuses = new Set<LineageWorkspaceStatus>(['active', 'paused', 'archived']);\n\nexport class LineageWorkspaceError extends Error {\n constructor(message: string, public status = 400) {\n super(message);\n }\n}\n\nexport function isLineageWorkspaceError(error: unknown): error is LineageWorkspaceError {\n return error instanceof LineageWorkspaceError;\n}\n\nexport function lineageWorkspaceId(project: string, rootAssetId: string): string {\n return `${project}:lineage-workspace:${rootAssetId}`;\n}\n\nfunction ensureProject(database: DatabaseSync, project: string): void {\n const timestamp = nowIso();\n database.prepare(`\n insert into projects (id, product, created_at, updated_at)\n values (?, ?, ?, ?)\n on conflict(id) do update set product = excluded.product, updated_at = excluded.updated_at\n `).run(project, project, timestamp, timestamp);\n}\n\nfunction normalizeStatus(value: LineageWorkspaceStatus | undefined, fallback: LineageWorkspaceStatus): LineageWorkspaceStatus {\n const status = value || fallback;\n if (!statuses.has(status)) throw new LineageWorkspaceError(`Unsupported lineage workspace status: ${status}`);\n return status;\n}\n\nfunction normalizeActor(value: LineageWorkspaceActor | undefined): LineageWorkspaceActor {\n const actor = value || 'human';\n if (!actors.has(actor)) throw new LineageWorkspaceError(`Unsupported lineage workspace actor: ${actor}`);\n return actor;\n}\n\nfunction requireAsset(database: DatabaseSync, project: string, assetId: string): { id: string; title: string } {\n const row = database.prepare('select id, title from assets where project_id = ? and id = ?').get(project, assetId) as { id: string; title: string } | undefined;\n if (!row) throw new LineageWorkspaceError(`Unknown indexed asset: ${assetId}`, 404);\n return row;\n}\n\nfunction rowToWorkspace(row: Row): LineageWorkspace {\n return {\n id: String(row.id),\n project: String(row.project_id),\n root_asset_id: String(row.root_asset_id),\n title: String(row.title),\n status: String(row.status) as LineageWorkspaceStatus,\n notes: typeof row.notes === 'string' ? row.notes : undefined,\n created_by: String(row.created_by) as LineageWorkspaceActor,\n active_at: typeof row.active_at === 'string' ? row.active_at : undefined,\n created_at: String(row.created_at),\n updated_at: String(row.updated_at),\n };\n}\n\nfunction workspaceById(database: DatabaseSync, project: string, id: string): LineageWorkspace | null {\n const row = database.prepare('select * from lineage_workspaces where project_id = ? and id = ?').get(project, id) as Row | undefined;\n return row ? rowToWorkspace(row) : null;\n}\n\nfunction workspaceByRoot(database: DatabaseSync, project: string, rootAssetId: string): LineageWorkspace | null {\n const row = database.prepare('select * from lineage_workspaces where project_id = ? and root_asset_id = ?').get(project, rootAssetId) as Row | undefined;\n return row ? rowToWorkspace(row) : null;\n}\n\nfunction knownRoots(database: DatabaseSync, project: string): Array<{ root_asset_id: string; selected_at?: string }> {\n const rows = database.prepare(`\n select root_asset_id, max(selected_at) selected_at from asset_selections where project_id = ? group by root_asset_id\n union\n select root_asset_id, null selected_at from asset_layouts where project_id = ? group by root_asset_id\n union\n select parent_asset_id root_asset_id, null selected_at\n from asset_edges\n where project_id = ?\n and parent_asset_id not in (select child_asset_id from asset_edges where project_id = ?)\n group by parent_asset_id\n `).all(project, project, project, project) as Array<{ root_asset_id: string; selected_at?: string | null }>;\n return rows.map(row => ({ root_asset_id: row.root_asset_id, selected_at: row.selected_at || undefined }));\n}\n\nfunction seedLegacyWorkspaces(database: DatabaseSync, project: string): void {\n ensureProject(database, project);\n const timestamp = nowIso();\n const statement = database.prepare(`\n insert into lineage_workspaces (\n id, project_id, root_asset_id, title, status, notes, created_by, active_at, created_at, updated_at\n )\n select ?, ?, a.id, a.title || ' lineage', 'active', null, 'system', ?, ?, ?\n from assets a\n where a.project_id = ? and a.id = ?\n on conflict(project_id, root_asset_id) do nothing\n `);\n for (const root of knownRoots(database, project)) {\n statement.run(\n lineageWorkspaceId(project, root.root_asset_id),\n project,\n root.selected_at || null,\n timestamp,\n timestamp,\n project,\n root.root_asset_id\n );\n }\n}\n\nfunction listRows(database: DatabaseSync, project: string): LineageWorkspace[] {\n return (database.prepare(`\n select * from lineage_workspaces\n where project_id = ?\n order by\n case status when 'active' then 0 when 'paused' then 1 else 2 end,\n active_at desc nulls last,\n updated_at desc,\n title\n `).all(project) as Row[]).map(rowToWorkspace);\n}\n\nfunction activeWorkspace(database: DatabaseSync, project: string): LineageWorkspace | null {\n const row = database.prepare(`\n select * from lineage_workspaces\n where project_id = ? and status != 'archived'\n order by active_at desc nulls last, updated_at desc\n limit 1\n `).get(project) as Row | undefined;\n return row ? rowToWorkspace(row) : null;\n}\n\nexport function listLineageWorkspaces(project: string): LineageWorkspaceSnapshot {\n const database = lineageDb();\n try {\n seedLegacyWorkspaces(database, project);\n return {\n project,\n active_workspace: activeWorkspace(database, project),\n workspaces: listRows(database, project),\n fetchedAt: nowIso(),\n };\n } finally {\n database.close();\n }\n}\n\nexport function inspectLineageWorkspace(project: string, workspaceId: string): LineageWorkspace {\n const database = lineageDb();\n try {\n seedLegacyWorkspaces(database, project);\n const workspace = workspaceById(database, project, workspaceId) || workspaceByRoot(database, project, workspaceId);\n if (!workspace) throw new LineageWorkspaceError(`Unknown lineage workspace: ${workspaceId}`, 404);\n return workspace;\n } finally {\n database.close();\n }\n}\n\nexport function createLineageWorkspace(project: string, fields: LineageWorkspaceFields) {\n const rootAssetId = fields.rootAssetId.trim();\n if (!rootAssetId) throw new LineageWorkspaceError('Lineage workspace requires rootAssetId');\n const status = normalizeStatus(fields.status, 'active');\n const actor = normalizeActor(fields.createdBy);\n const database = lineageDb();\n try {\n const root = requireAsset(database, project, rootAssetId);\n const timestamp = nowIso();\n const workspace: LineageWorkspace = {\n id: lineageWorkspaceId(project, rootAssetId),\n project,\n root_asset_id: rootAssetId,\n title: fields.title?.trim() || `${root.title} lineage`,\n status,\n notes: fields.notes?.trim() || undefined,\n created_by: actor,\n active_at: fields.activate !== false && status !== 'archived' ? timestamp : undefined,\n created_at: timestamp,\n updated_at: timestamp,\n };\n if (!fields.confirmWrite) return { ok: true as const, dryRun: true as const, workspace };\n ensureProject(database, project);\n database.prepare(`\n insert into lineage_workspaces (\n id, project_id, root_asset_id, title, status, notes, created_by, active_at, created_at, updated_at\n ) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n on conflict(project_id, root_asset_id) do update set\n title = excluded.title,\n status = excluded.status,\n notes = excluded.notes,\n active_at = coalesce(excluded.active_at, lineage_workspaces.active_at),\n updated_at = excluded.updated_at\n `).run(\n workspace.id,\n project,\n workspace.root_asset_id,\n workspace.title,\n workspace.status,\n workspace.notes || null,\n workspace.created_by,\n workspace.active_at || null,\n workspace.created_at,\n workspace.updated_at\n );\n return {\n ok: true as const,\n message: `Saved lineage workspace ${workspace.title}`,\n workspace: workspaceById(database, project, workspace.id),\n };\n } finally {\n database.close();\n }\n}\n\nexport function updateLineageWorkspace(project: string, workspaceId: string, fields: LineageWorkspaceUpdateFields) {\n const database = lineageDb();\n try {\n seedLegacyWorkspaces(database, project);\n const current = workspaceById(database, project, workspaceId) || workspaceByRoot(database, project, workspaceId);\n if (!current) throw new LineageWorkspaceError(`Unknown lineage workspace: ${workspaceId}`, 404);\n const timestamp = nowIso();\n const next: LineageWorkspace = {\n ...current,\n title: fields.title?.trim() || current.title,\n status: normalizeStatus(fields.status, current.status),\n notes: fields.notes === undefined ? current.notes : fields.notes.trim() || undefined,\n active_at: fields.activate ? timestamp : current.active_at,\n updated_at: timestamp,\n };\n if (!fields.confirmWrite) return { ok: true as const, dryRun: true as const, workspace: next };\n database.prepare(`\n update lineage_workspaces\n set title = ?, status = ?, notes = ?, active_at = ?, updated_at = ?\n where project_id = ? and id = ?\n `).run(next.title, next.status, next.notes || null, next.active_at || null, timestamp, project, current.id);\n return {\n ok: true as const,\n message: `Updated lineage workspace ${next.title}`,\n workspace: workspaceById(database, project, current.id),\n };\n } finally {\n database.close();\n }\n}\n\nexport function activateLineageWorkspace(project: string, workspaceId: string, confirmWrite: boolean) {\n return updateLineageWorkspace(project, workspaceId, { activate: true, status: 'active', confirmWrite });\n}\n\nexport function archiveLineageWorkspace(project: string, workspaceId: string, confirmWrite: boolean) {\n const database = lineageDb();\n try {\n seedLegacyWorkspaces(database, project);\n const current = workspaceById(database, project, workspaceId) || workspaceByRoot(database, project, workspaceId);\n if (!current) throw new LineageWorkspaceError(`Unknown lineage workspace: ${workspaceId}`, 404);\n const timestamp = nowIso();\n const next: LineageWorkspace = {\n ...current,\n status: 'archived',\n active_at: undefined,\n updated_at: timestamp,\n };\n if (!confirmWrite) return { ok: true as const, dryRun: true as const, workspace: next };\n database.prepare(`\n update lineage_workspaces\n set status = 'archived', active_at = null, updated_at = ?\n where project_id = ? and id = ?\n `).run(timestamp, project, current.id);\n database.prepare('delete from asset_selections where project_id = ? and root_asset_id = ?').run(project, current.root_asset_id);\n return {\n ok: true as const,\n message: `Archived lineage workspace ${current.title}`,\n workspace: workspaceById(database, project, current.id),\n };\n } finally {\n database.close();\n }\n}\n\nexport function activeLineageWorkspaceRoot(project: string): string | undefined {\n const database = lineageDb();\n try {\n seedLegacyWorkspaces(database, project);\n return activeWorkspace(database, project)?.root_asset_id;\n } finally {\n database.close();\n }\n}\n", "import { join } from 'node:path';\nimport { defaultProject, listAssets, repoRoot } from './assetCore';\nimport { lineageDb as db, lineageDbPath, nowIso, type DatabaseSync } from './assetLineageDb';\nimport { LINEAGE_NEXT_VARIATION_LIMIT, normalizeSelectionInput, selectedRows, selectionId } from './assetLineageSelection';\nimport { activeLineageWorkspaceRoot } from './assetLineageWorkspaces';\nimport type {\n AssetReviewState,\n GrowthAsset,\n LineageEdge,\n LineageChildrenResponse,\n LineageIndexSummary,\n LineageLayoutFields,\n LineageLinkFields,\n LineageNode,\n LineageNextResponse,\n LineagePosition,\n LineageSnapshot,\n ReviewFields,\n SelectionFields,\n} from '../shared/types';\n\nexport class LineageError extends Error {\n constructor(message: string, public status = 400) {\n super(message);\n }\n}\n\nexport function isLineageError(error: unknown): error is LineageError {\n return error instanceof LineageError;\n}\n\nfunction collectAssets(project: string, source: 'catalog' | 'local'): GrowthAsset[] {\n const first = listAssets(project, { source, page: 1, pageSize: 100 });\n const assets = [...first.assets];\n for (let page = 2; page <= first.pagination.totalPages; page += 1) {\n assets.push(...listAssets(project, { source, page, pageSize: 100 }).assets);\n }\n return assets;\n}\n\nfunction upsertProject(database: DatabaseSync, project: string): void {\n const timestamp = nowIso();\n database.prepare(`\n insert into projects (id, product, catalog_path, created_at, updated_at)\n values (?, ?, ?, ?, ?)\n on conflict(id) do update set product = excluded.product, updated_at = excluded.updated_at\n `).run(project, project, join(repoRoot, project, 'assets', 'catalog.json'), timestamp, timestamp);\n}\n\nfunction upsertAsset(database: DatabaseSync, project: string, asset: GrowthAsset): void {\n const timestamp = nowIso();\n const source = asset.source === 'local' ? 'local' : 'catalog';\n database.prepare(`\n insert into assets (\n id, project_id, source, local_path, s3_key, checksum_sha256, media_type, title, status,\n channel, campaign, audience, size_bytes, content_type, created_at, updated_at, last_seen_at\n ) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n on conflict(id) do update set\n source = excluded.source, local_path = excluded.local_path, s3_key = excluded.s3_key,\n checksum_sha256 = excluded.checksum_sha256, media_type = excluded.media_type,\n title = excluded.title, status = excluded.status, channel = excluded.channel,\n campaign = excluded.campaign, audience = excluded.audience, size_bytes = excluded.size_bytes,\n content_type = excluded.content_type, updated_at = excluded.updated_at, last_seen_at = excluded.last_seen_at\n `).run(\n asset.asset_id, project, source, asset.local?.relative_path || null, asset.s3?.key || null,\n asset.local?.checksum_sha256 || asset.s3?.checksum_sha256 || null, asset.content_type, asset.title,\n asset.status, asset.channel || null, asset.campaign || null, asset.audience || null,\n asset.local?.size_bytes || asset.s3?.size_bytes || null, asset.local?.content_type || asset.s3?.content_type || null,\n timestamp, timestamp, timestamp\n );\n database.prepare(`\n insert into asset_reviews (asset_id, review_state, updated_at)\n values (?, 'unreviewed', ?)\n on conflict(asset_id) do nothing\n `).run(asset.asset_id, timestamp);\n}\n\nexport function indexLineageAssets(project = defaultProject): LineageIndexSummary {\n const database = db();\n const catalog = collectAssets(project, 'catalog');\n const local = collectAssets(project, 'local');\n upsertProject(database, project);\n for (const asset of [...catalog, ...local]) upsertAsset(database, project, asset);\n database.close();\n return { catalog: catalog.length, local: local.length, total: catalog.length + local.length, database: lineageDbPath() };\n}\n\nfunction requireAsset(database: DatabaseSync, project: string, assetId: string): void {\n const row = database.prepare('select id from assets where project_id = ? and id = ?').get(project, assetId);\n if (!row) throw new LineageError(`Unknown indexed asset: ${assetId}`, 404);\n}\n\nfunction parentOf(database: DatabaseSync, project: string, assetId: string): string | undefined {\n const row = database.prepare('select parent_asset_id from asset_edges where project_id = ? and child_asset_id = ? order by created_at limit 1').get(project, assetId) as { parent_asset_id?: string } | undefined;\n return row?.parent_asset_id;\n}\n\nfunction rootFor(database: DatabaseSync, project: string, assetId: string): string {\n let root = assetId;\n const seen = new Set<string>();\n while (!seen.has(root)) {\n seen.add(root);\n const parent = parentOf(database, project, root);\n if (!parent) return root;\n root = parent;\n }\n return assetId;\n}\n\nfunction latestSelectedRoot(database: DatabaseSync, project: string): string | undefined {\n const row = database.prepare('select root_asset_id from asset_selections where project_id = ? order by selected_at desc limit 1').get(project) as { root_asset_id?: string } | undefined;\n return row?.root_asset_id;\n}\n\nfunction resolveRoot(database: DatabaseSync, project: string, rootAssetId?: string): string {\n if (rootAssetId) {\n requireAsset(database, project, rootAssetId);\n return rootAssetId;\n }\n const root = activeLineageWorkspaceRoot(project) || latestSelectedRoot(database, project);\n if (!root) throw new LineageError('Lineage command requires --root unless a project selection exists');\n requireAsset(database, project, root);\n return root;\n}\n\nfunction edgeId(project: string, parent: string, child: string): string {\n return `${project}:${parent}:derived_from:${child}`;\n}\n\nfunction canPreviewLocally(mediaType: string, localPath?: string): boolean {\n return Boolean(localPath && ['image', 'video', 'gif'].includes(mediaType));\n}\n\nfunction localPreviewUrl(project: string, localPath?: string): string | undefined {\n if (!localPath) return undefined;\n const params = new URLSearchParams({ project, path: localPath });\n return `/api/assets/local-preview?${params.toString()}`;\n}\n\nexport function linkLineageAssets(project: string, fields: LineageLinkFields) {\n const database = db();\n requireAsset(database, project, fields.parentAssetId);\n requireAsset(database, project, fields.childAssetId);\n if (fields.parentAssetId === fields.childAssetId) throw new LineageError('Lineage link cannot point to itself');\n const edge = {\n id: edgeId(project, fields.parentAssetId, fields.childAssetId), parent_asset_id: fields.parentAssetId,\n child_asset_id: fields.childAssetId, relation_type: 'derived_from' as const, created_at: nowIso(),\n };\n if (!fields.confirmWrite) {\n database.close();\n return { ok: true as const, dryRun: true, edge };\n }\n database.prepare(`\n insert into asset_edges (id, project_id, parent_asset_id, child_asset_id, relation_type, created_at)\n values (?, ?, ?, ?, 'derived_from', ?)\n on conflict(project_id, parent_asset_id, child_asset_id, relation_type) do nothing\n `).run(edge.id, project, edge.parent_asset_id, edge.child_asset_id, edge.created_at);\n database.close();\n return { ok: true as const, message: `Linked ${edge.child_asset_id} from ${edge.parent_asset_id}`, edge };\n}\n\nfunction descendants(database: DatabaseSync, project: string, root: string): LineageEdge[] {\n const edges: LineageEdge[] = [];\n const queue = [root];\n const seen = new Set<string>();\n while (queue.length > 0) {\n const parent = queue.shift()!;\n if (seen.has(parent)) continue;\n seen.add(parent);\n const rows = database.prepare('select id, parent_asset_id, child_asset_id, relation_type, created_at from asset_edges where project_id = ? and parent_asset_id = ? order by created_at').all(project, parent) as unknown as LineageEdge[];\n edges.push(...rows);\n queue.push(...rows.map(row => row.child_asset_id));\n }\n return edges;\n}\n\nexport function getLineageSnapshot(project: string, assetId: string): LineageSnapshot {\n const database = db();\n requireAsset(database, project, assetId);\n const root = rootFor(database, project, assetId);\n const edges = descendants(database, project, root);\n const ids = [...new Set([root, ...edges.flatMap(edge => [edge.parent_asset_id, edge.child_asset_id])])];\n const placeholders = ids.map(() => '?').join(',');\n const rows = database.prepare(`\n select a.id asset_id, a.project_id project, a.source, a.title, a.media_type, a.status, a.channel, a.campaign,\n a.local_path, a.s3_key, a.checksum_sha256, coalesce(r.review_state, 'unreviewed') review_state,\n r.notes review_notes, l.x layout_x, l.y layout_y\n from assets a left join asset_reviews r on r.asset_id = a.id\n left join asset_layouts l on l.project_id = a.project_id and l.root_asset_id = ? and l.asset_id = a.id\n where a.project_id = ? and a.id in (${placeholders})\n `).all(root, project, ...ids) as Array<Omit<LineageNode, 'is_latest' | 'position' | 'preview_url' | 'selection_note' | 'user_selected'> & { layout_x?: number; layout_y?: number }>;\n const selected = selectedRows(database, project, root);\n const childIds = new Set(edges.map(edge => edge.parent_asset_id));\n const selectedIds = new Set(selected.map(row => row.asset_id));\n const selections = selected.map(row => ({\n asset_id: row.asset_id, notes: row.notes || undefined,\n position: Number(row.position || 0), selected_at: row.selected_at,\n }));\n const selection = selections[0] || null;\n const nodes = rows.map(row => {\n const position: LineagePosition | undefined = typeof row.layout_x === 'number' && typeof row.layout_y === 'number' ? { x: row.layout_x, y: row.layout_y } : undefined;\n const { layout_x: _layoutX, layout_y: _layoutY, ...node } = row;\n const nodeSelection = selections.find(item => item.asset_id === row.asset_id);\n return {\n ...node,\n is_latest: !childIds.has(row.asset_id),\n position,\n preview_url: canPreviewLocally(row.media_type, row.local_path) ? localPreviewUrl(project, row.local_path) : undefined,\n selection_note: nodeSelection?.notes,\n user_selected: selectedIds.has(row.asset_id),\n };\n });\n database.close();\n return {\n project,\n root_asset_id: root,\n active_asset_id: assetId,\n selected: selections.map(row => row.asset_id),\n selection,\n selections,\n latest: nodes.filter(node => node.is_latest).map(node => node.asset_id),\n nodes,\n edges,\n fetchedAt: nowIso(),\n };\n}\n\nexport function updateLineageLayout(project: string, fields: LineageLayoutFields) {\n if (fields.positions.length === 0) throw new LineageError('Lineage layout requires at least one position');\n const database = db();\n requireAsset(database, project, fields.rootAssetId);\n for (const position of fields.positions) requireAsset(database, project, position.assetId);\n if (!fields.confirmWrite) {\n database.close();\n return { ok: true as const, dryRun: true, root_asset_id: fields.rootAssetId, positions: fields.positions };\n }\n const timestamp = nowIso();\n const statement = database.prepare(`\n insert into asset_layouts (id, project_id, root_asset_id, asset_id, x, y, updated_at)\n values (?, ?, ?, ?, ?, ?, ?)\n on conflict(project_id, root_asset_id, asset_id) do update set\n x = excluded.x, y = excluded.y, updated_at = excluded.updated_at\n `);\n for (const position of fields.positions) {\n statement.run(`${project}:${fields.rootAssetId}:layout:${position.assetId}`, project, fields.rootAssetId, position.assetId, position.x, position.y, timestamp);\n }\n database.close();\n return { ok: true as const, message: `Saved ${fields.positions.length} lineage positions`, root_asset_id: fields.rootAssetId, positions: fields.positions };\n}\n\nexport function getLineageNextAsset(project: string, rootAssetId?: string): LineageNextResponse {\n const database = db();\n const root = resolveRoot(database, project, rootAssetId);\n database.close();\n const snapshot = getLineageSnapshot(project, root);\n const selectedNodes = snapshot.selected\n .map(assetId => snapshot.nodes.find(node => node.asset_id === assetId))\n .filter((node): node is LineageNode => Boolean(node));\n const latestNodes = snapshot.nodes.filter(node => snapshot.latest.includes(node.asset_id));\n const warnings: string[] = [];\n for (const selectedNode of selectedNodes) {\n if (selectedNode.is_latest) continue;\n warnings.push('Selected asset is not a latest leaf; agents should treat this as an intentional branch choice.');\n }\n if (selectedNodes.length > 0) {\n return {\n project,\n root_asset_id: snapshot.root_asset_id,\n strategy: 'selected',\n selection_mode: selectedNodes.length > 1 ? 'multiple' : 'single',\n recommended_action: 'evolve_variations',\n reason: 'user_selected',\n next_asset: selectedNodes[0],\n next_assets: selectedNodes,\n latest: snapshot.latest,\n selected: snapshot.selected,\n selection: snapshot.selection,\n selections: snapshot.selections,\n candidates: latestNodes,\n warnings,\n fetchedAt: nowIso(),\n };\n }\n if (latestNodes.length === 1) {\n return {\n project,\n root_asset_id: snapshot.root_asset_id,\n strategy: 'single_latest',\n selection_mode: 'fallback',\n recommended_action: 'evolve_variations',\n reason: 'single_latest_fallback',\n next_asset: latestNodes[0],\n next_assets: [latestNodes[0]],\n latest: snapshot.latest,\n selected: snapshot.selected,\n selection: snapshot.selection,\n selections: snapshot.selections,\n candidates: latestNodes,\n warnings,\n fetchedAt: nowIso(),\n };\n }\n return {\n project,\n root_asset_id: snapshot.root_asset_id,\n strategy: latestNodes.length > 1 ? 'ambiguous_latest' : 'empty',\n selection_mode: 'none',\n recommended_action: latestNodes.length > 1 ? 'choose_next_base' : 'none',\n reason: latestNodes.length > 1 ? 'multiple_latest_no_selection' : 'no_lineage_candidates',\n next_asset: null,\n next_assets: [],\n latest: snapshot.latest,\n selected: snapshot.selected,\n selection: snapshot.selection,\n selections: snapshot.selections,\n candidates: latestNodes,\n warnings,\n fetchedAt: nowIso(),\n };\n}\n\nexport function getLineageChildren(project: string, parentAssetId: string): LineageChildrenResponse {\n const snapshot = getLineageSnapshot(project, parentAssetId);\n const edges = snapshot.edges.filter(edge => edge.parent_asset_id === parentAssetId);\n const childIds = new Set(edges.map(edge => edge.child_asset_id));\n return {\n project, parent_asset_id: parentAssetId,\n children: snapshot.nodes.filter(node => childIds.has(node.asset_id)),\n edges, fetchedAt: nowIso(),\n };\n}\n\nexport function updateSelectedAsset(project: string, fields: SelectionFields) {\n const database = db();\n const inputAssetIds = normalizeSelectionInput(fields);\n const root = fields.rootAssetId || (inputAssetIds[0] ? rootFor(database, project, inputAssetIds[0]) : '');\n if (!root) throw new LineageError('Selection requires rootAssetId or assetId');\n requireAsset(database, project, root);\n for (const assetId of inputAssetIds) requireAsset(database, project, assetId);\n const mode = fields.mode || 'replace';\n const limit = fields.maxSelections || LINEAGE_NEXT_VARIATION_LIMIT;\n if (!fields.confirmWrite) {\n database.close();\n return { ok: true as const, dryRun: true, root_asset_id: root, asset_ids: inputAssetIds, mode, clear: Boolean(fields.clear), max_selections: limit };\n }\n const current = selectedRows(database, project, root);\n let nextIds = current.map(row => row.asset_id);\n if (fields.clear) {\n nextIds = [];\n } else if (mode === 'replace') {\n nextIds = inputAssetIds;\n } else if (mode === 'add') {\n nextIds = [...nextIds, ...inputAssetIds];\n } else if (mode === 'remove') {\n nextIds = nextIds.filter(assetId => !inputAssetIds.includes(assetId));\n } else if (mode === 'toggle') {\n for (const assetId of inputAssetIds) {\n nextIds = nextIds.includes(assetId) ? nextIds.filter(id => id !== assetId) : [...nextIds, assetId];\n }\n }\n nextIds = [...new Set(nextIds)];\n if (!fields.clear && inputAssetIds.length === 0) throw new LineageError('Selection set requires assetId or assetIds');\n if (nextIds.length > limit) throw new LineageError(`Select at most ${limit} assets for next variation`);\n database.prepare('delete from asset_selections where project_id = ? and root_asset_id = ?').run(project, root);\n const timestamp = nowIso();\n const insert = database.prepare(`\n insert into asset_selections (id, project_id, root_asset_id, asset_id, position, notes, selected_at)\n values (?, ?, ?, ?, ?, ?, ?)\n `);\n nextIds.forEach((assetId, position) => {\n const existing = current.find(row => row.asset_id === assetId);\n const notes = inputAssetIds.includes(assetId) ? fields.notes || existing?.notes : existing?.notes;\n insert.run(selectionId(project, root, assetId), project, root, assetId, position, notes || null, timestamp);\n });\n database.close();\n const message = nextIds.length === 0 ? `Cleared selected assets for ${root}` : `Selected ${nextIds.length} asset${nextIds.length === 1 ? '' : 's'} for ${root}`;\n return { ok: true as const, message, root_asset_id: root, asset_id: nextIds[0] || null, asset_ids: nextIds, mode };\n}\n\nexport function updateAssetReview(project: string, fields: ReviewFields) {\n const allowed = new Set<AssetReviewState>(['unreviewed', 'approved', 'needs_revision', 'rejected', 'ignored']);\n if (!allowed.has(fields.reviewState)) throw new LineageError(`Unsupported review state: ${fields.reviewState}`);\n const database = db();\n requireAsset(database, project, fields.assetId);\n if (!fields.confirmWrite) {\n database.close();\n return { ok: true as const, dryRun: true, asset_id: fields.assetId, review_state: fields.reviewState, notes: fields.notes };\n }\n const timestamp = nowIso();\n database.prepare(`\n insert into asset_reviews (asset_id, review_state, reviewed_at, ignored_at, notes, updated_at)\n values (?, ?, ?, ?, ?, ?)\n on conflict(asset_id) do update set\n review_state = excluded.review_state, reviewed_at = excluded.reviewed_at,\n ignored_at = excluded.ignored_at, notes = excluded.notes, updated_at = excluded.updated_at\n `).run(fields.assetId, fields.reviewState, timestamp, fields.reviewState === 'ignored' ? timestamp : null, fields.notes || null, timestamp);\n database.close();\n return { ok: true as const, message: `Marked ${fields.assetId} ${fields.reviewState}`, asset_id: fields.assetId, review_state: fields.reviewState };\n}\n", "import type { LineageBriefResponse, LineageSelectedChildFields } from '../shared/types';\nimport { getLineageNextAsset, LineageError, linkLineageAssets } from './assetLineage';\nimport { lineageDbPath, nowIso } from './assetLineageDb';\n\nconst publicPackageCommand = 'npx @mean-weasel/lineage';\n\nfunction shellQuote(value: string): string {\n return `'${value.replace(/'/g, \"'\\\\''\")}'`;\n}\n\nfunction lineageCommand(command: string, project: string, rootAssetId: string): string {\n return `${publicPackageCommand} ${command} --project ${shellQuote(project)} --root ${shellQuote(rootAssetId)} --db ${shellQuote(lineageDbPath())} --json`;\n}\n\nfunction linkChildCommand(project: string, rootAssetId: string): string {\n return `${publicPackageCommand} link-child --project ${shellQuote(project)} --root ${shellQuote(rootAssetId)} --child <asset-id> --confirm-write --db ${shellQuote(lineageDbPath())} --json`;\n}\n\nexport function getLineageBrief(project: string, rootAssetId?: string): LineageBriefResponse {\n const next = getLineageNextAsset(project, rootAssetId);\n const assets = next.next_assets;\n const asset = next.next_asset;\n const referenceAssetIds = assets.map(item => item.asset_id);\n const rationale = next.selections.map(selection => selection.notes).find(Boolean) || asset?.selection_note || next.selection?.notes;\n const channels = [...new Set(assets.map(item => item.channel || 'unknown'))];\n const campaigns = [...new Set(assets.map(item => item.campaign || 'unknown'))];\n const prompt = assets.length > 0\n ? [\n assets.length === 1\n ? `Create 3-4 variations from asset ${assets[0].asset_id} (${assets[0].title}).`\n : `Create 3-4 variations using these ${assets.length} selected references: ${referenceAssetIds.join(', ')}.`,\n rationale ? `Preserve this selection rationale: ${rationale}` : 'Preserve the strongest visible ideas while exploring distinct alternatives.',\n `Keep project=${project}, root=${next.root_asset_id}, channels=${channels.join(',')}, campaigns=${campaigns.join(',')}.`,\n 'After generation, index outputs and link chosen children with lineage link-child.',\n ].join(' ')\n : 'Select one to three latest lineage candidates before generating variations.';\n return {\n project,\n root_asset_id: next.root_asset_id,\n strategy: next.strategy,\n selection_mode: next.selection_mode,\n recommended_action: next.recommended_action,\n reason: next.reason,\n next_asset: asset,\n next_assets: assets,\n selection: next.selection,\n selections: next.selections,\n latest: next.latest,\n warnings: next.warnings,\n brief: {\n title: asset ? `Evolve ${assets.length > 1 ? `${assets.length} selected bases` : asset.title}` : 'Choose next lineage base',\n objective: asset ? 'Generate the next branch of visual variations from the selected lineage base or bases.' : 'Resolve the next base before generation.',\n prompt,\n reference_asset_id: asset?.asset_id,\n reference_asset_ids: referenceAssetIds,\n rationale,\n },\n handoff: {\n next_command: lineageCommand('next', project, next.root_asset_id),\n inspect_command: asset ? `${publicPackageCommand} inspect --project ${shellQuote(project)} --asset-id ${shellQuote(asset.asset_id)} --db ${shellQuote(lineageDbPath())} --json` : undefined,\n link_child_command: asset ? linkChildCommand(project, next.root_asset_id) : undefined,\n },\n fetchedAt: nowIso(),\n };\n}\n\nexport function linkSelectedLineageChild(project: string, fields: LineageSelectedChildFields) {\n const next = getLineageNextAsset(project, fields.rootAssetId);\n if (!next.next_asset) throw new LineageError('Cannot link child until a next base is selected or unambiguous');\n const result = linkLineageAssets(project, {\n childAssetId: fields.childAssetId,\n confirmWrite: fields.confirmWrite,\n parentAssetId: next.next_asset.asset_id,\n });\n return {\n ...result,\n root_asset_id: next.root_asset_id,\n parent_asset_id: next.next_asset.asset_id,\n child_asset_id: fields.childAssetId,\n reference_asset_ids: next.next_assets.map(asset => asset.asset_id),\n warning: next.next_assets.length > 1\n ? 'Linked child to the primary selected base; add explicit edges to other selected references if the child derives from them too.'\n : undefined,\n };\n}\n", "#!/usr/bin/env node\n\nimport { runLineageCli } from './lineageCli';\n\nrunLineageCli({ binName: 'lineage', channel: 'stable', defaultPort: 5197, displayName: 'Lineage' });\n"],
5
- "mappings": ";;;AAAA,SAAS,cAAAA,aAAY,aAAAC,YAAW,gBAAAC,qBAAoB;AACpD,SAAS,SAAS,gBAAgB;AAClC,SAAS,WAAAC,UAAS,QAAAC,OAAM,WAAA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,WAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,UAAID,MAAM,SAAQ,MAAM,KAAK,UAAU,EAAE,IAAI,OAAO,SAAS,OAAOC,SAAQ,GAAG,MAAM,CAAC,CAAC;AAAA,UAClF,SAAQ,MAAM,GAAG,OAAO,OAAO,KAAKA,QAAO,EAAE;AAClD,cAAQ,KAAK,CAAC;AAAA,IAChB;AACA,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,QAAM,OAAO,KAAK,SAAS,QAAQ;AACnC,QAAM,UAAU,oBAAoB,OAAO;AAC3C,MAAI,KAAM,SAAQ,MAAM,KAAK,UAAU,EAAE,IAAI,OAAO,SAAS,OAAO,QAAQ,GAAG,MAAM,CAAC,CAAC;AAAA,MAClF,SAAQ,MAAM,GAAG,OAAO,OAAO,KAAK,OAAO,EAAE;AAClD,UAAQ,KAAK,CAAC;AAChB;;;AShRA,cAAc,EAAE,SAAS,WAAW,SAAS,UAAU,aAAa,MAAM,aAAa,UAAU,CAAC;",
4
+ "sourcesContent": ["import { existsSync, mkdirSync, readFileSync } from 'node:fs';\nimport { homedir, platform } from 'node:os';\nimport { dirname, join, resolve } from 'node:path';\nimport { spawn } from 'node:child_process';\nimport { fileURLToPath } from 'node:url';\nimport { defaultProduct } from '../server/assetCore';\nimport { getLineageNextAsset, getLineageSnapshot } from '../server/assetLineage';\nimport { getLineageBrief, linkSelectedLineageChild } from '../server/assetLineageHandoff';\n\nexport interface LineageCliConfig {\n binName: 'lineage' | 'lineage-dev';\n channel: 'stable' | 'development';\n defaultHost: string;\n defaultPort: number;\n displayName: string;\n}\n\ninterface StartOptions {\n dbPath: string;\n host: string;\n json: boolean;\n open: boolean;\n port: number;\n}\n\ninterface DataCommandOptions {\n assetId?: string;\n childAssetId?: string;\n confirmWrite: boolean;\n dbPath?: string;\n json: boolean;\n project: string;\n rootAssetId?: string;\n}\n\nconst signalExitCodes: Partial<Record<NodeJS.Signals, number>> = {\n SIGINT: 130,\n SIGTERM: 143,\n};\n\nfunction packageRoot(): string {\n return resolve(dirname(fileURLToPath(import.meta.url)), '..', '..');\n}\n\nfunction packageVersion(): string {\n try {\n const packageInfo = JSON.parse(readFileSync(join(packageRoot(), 'package.json'), 'utf8')) as { version?: string };\n return packageInfo.version || '0.0.0';\n } catch {\n return '0.0.0';\n }\n}\n\nfunction dataRoot(displayName: string): string {\n if (process.env.LINEAGE_HOME) return process.env.LINEAGE_HOME;\n if (platform() === 'darwin') return join(homedir(), 'Library', 'Application Support', displayName);\n if (platform() === 'win32') return join(process.env.APPDATA || join(homedir(), 'AppData', 'Roaming'), displayName);\n return join(process.env.XDG_DATA_HOME || join(homedir(), '.local', 'share'), displayName.toLowerCase().replace(/\\s+/g, '-'));\n}\n\nfunction readOption(args: string[], name: string): string | undefined {\n const prefix = `${name}=`;\n const inline = args.find(arg => arg.startsWith(prefix));\n if (inline) return inline.slice(prefix.length);\n const index = args.indexOf(name);\n if (index >= 0) return args[index + 1];\n return undefined;\n}\n\nexport function resolveStartOptions(config: LineageCliConfig, args: string[]): StartOptions {\n const runtimeDir = dataRoot(config.displayName);\n const rawPort = readOption(args, '--port') || process.env.PORT || String(config.defaultPort);\n const port = Number(rawPort);\n if (!Number.isInteger(port) || port < 1 || port > 65535) {\n throw new Error(`Invalid port: ${rawPort}`);\n }\n return {\n dbPath: readOption(args, '--db') || process.env.LINEAGE_DB || join(runtimeDir, `${config.binName}.sqlite`),\n host: readOption(args, '--host') || process.env.HOST || config.defaultHost,\n json: args.includes('--json'),\n open: args.includes('--open'),\n port,\n };\n}\n\nfunction printHelp(config: LineageCliConfig): void {\n console.log(`${config.binName} ${packageVersion()}\n\nUsage:\n ${config.binName} start [--port <port>] [--host <host>] [--db <path>] [--open] [--json]\n ${config.binName} next [--project <project>] [--root <asset-id>] [--db <path>] [--json]\n ${config.binName} brief [--project <project>] [--root <asset-id>] [--db <path>] [--json]\n ${config.binName} inspect --asset-id <asset-id> [--project <project>] [--db <path>] [--json]\n ${config.binName} link-child --root <asset-id> --child <asset-id> [--project <project>] [--confirm-write] [--db <path>] [--json]\n ${config.binName} --help\n ${config.binName} --version\n\n${config.displayName} runs the bundled Lineage server for the ${config.channel} channel.`);\n}\n\nfunction openBrowser(url: string): void {\n const command = platform() === 'darwin' ? 'open' : platform() === 'win32' ? 'cmd' : 'xdg-open';\n const args = platform() === 'win32' ? ['/c', 'start', '', url] : [url];\n const opener = spawn(command, args, { detached: true, stdio: 'ignore' });\n opener.unref();\n}\n\nfunction positionalArgs(args: string[]): string[] {\n const values: string[] = [];\n for (let index = 0; index < args.length; index += 1) {\n const arg = args[index];\n if (arg.startsWith('--')) {\n if (!arg.includes('=') && args[index + 1] && !args[index + 1].startsWith('--')) index += 1;\n continue;\n }\n values.push(arg);\n }\n return values;\n}\n\nfunction resolveDataCommandOptions(args: string[]): DataCommandOptions {\n const positions = positionalArgs(args);\n const options = {\n assetId: readOption(args, '--asset-id') || positions[0],\n childAssetId: readOption(args, '--child'),\n confirmWrite: args.includes('--confirm-write'),\n dbPath: readOption(args, '--db'),\n json: args.includes('--json'),\n project: readOption(args, '--project') || process.env.LINEAGE_DEFAULT_PRODUCT || defaultProduct,\n rootAssetId: readOption(args, '--root'),\n };\n if (options.dbPath) process.env.LINEAGE_DB = options.dbPath;\n return options;\n}\n\nexport function runLineageDataCommand(command: string, args: string[]): unknown {\n const options = resolveDataCommandOptions(args);\n if (command === 'next') return getLineageNextAsset(options.project, options.rootAssetId || options.assetId);\n if (command === 'brief') return getLineageBrief(options.project, options.rootAssetId || options.assetId);\n if (command === 'inspect') {\n if (!options.assetId) throw new Error('lineage inspect requires --asset-id');\n return getLineageSnapshot(options.project, options.assetId);\n }\n if (command === 'link-child') {\n if (!options.childAssetId) throw new Error('lineage link-child requires --child');\n return linkSelectedLineageChild(options.project, {\n childAssetId: options.childAssetId,\n confirmWrite: options.confirmWrite,\n rootAssetId: options.rootAssetId || options.assetId,\n });\n }\n throw new Error(`Unknown command: ${command}`);\n}\n\nfunction printDataResult(command: string, result: unknown, json: boolean): void {\n if (json) {\n console.log(JSON.stringify(result, null, 2));\n return;\n }\n if (command === 'next' && result && typeof result === 'object' && 'reason' in result) {\n const next = result as { next_asset?: { asset_id: string; title: string } | null; reason: string; root_asset_id: string };\n console.log(next.next_asset ? `${next.next_asset.asset_id}: ${next.next_asset.title}` : `No next asset: ${next.reason}`);\n console.log(`Root: ${next.root_asset_id}`);\n return;\n }\n if (command === 'brief' && result && typeof result === 'object' && 'brief' in result) {\n const brief = result as { brief: { title: string; prompt: string } };\n console.log(brief.brief.title);\n console.log(brief.brief.prompt);\n return;\n }\n if (command === 'inspect' && result && typeof result === 'object' && 'nodes' in result) {\n const snapshot = result as { active_asset_id: string; edges: unknown[]; nodes: unknown[]; root_asset_id: string };\n console.log(`${snapshot.root_asset_id}: ${snapshot.nodes.length} node(s), ${snapshot.edges.length} edge(s)`);\n console.log(`Active: ${snapshot.active_asset_id}`);\n return;\n }\n if (command === 'link-child' && result && typeof result === 'object') {\n const link = result as { dryRun?: boolean; edge?: { child_asset_id: string; parent_asset_id: string }; message?: string };\n console.log(link.message || `${link.dryRun ? 'Dry run: ' : ''}Link ${link.edge?.child_asset_id || 'child'} from ${link.edge?.parent_asset_id || 'parent'}`);\n return;\n }\n console.log(String(result));\n}\n\nfunction start(config: LineageCliConfig, args: string[]): void {\n let options: StartOptions;\n const json = args.includes('--json');\n try {\n options = resolveStartOptions(config, args);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (json) console.error(JSON.stringify({ ok: false, error: message }, null, 2));\n else console.error(`${config.binName}: ${message}`);\n process.exit(1);\n }\n const serverPath = join(packageRoot(), 'dist', 'server.js');\n if (!existsSync(serverPath)) {\n const message = `Missing bundled server at ${serverPath}. Run npm run build before using ${config.binName} start from a source checkout.`;\n if (options.json) console.error(JSON.stringify({ ok: false, error: message }, null, 2));\n else console.error(`${config.binName}: ${message}`);\n process.exit(1);\n }\n\n mkdirSync(dirname(options.dbPath), { recursive: true });\n const url = `http://${options.host}:${options.port}`;\n if (options.json) {\n console.log(JSON.stringify({ channel: config.channel, dbPath: options.dbPath, host: options.host, port: options.port, status: 'starting', url }, null, 2));\n } else {\n console.log(`${config.displayName} starting at ${url}`);\n console.log(`SQLite: ${options.dbPath}`);\n }\n if (options.open) openBrowser(url);\n\n const child = spawn(process.execPath, [serverPath], {\n env: {\n ...process.env,\n HOST: options.host,\n LINEAGE_CHANNEL: config.channel,\n LINEAGE_DB: options.dbPath,\n NODE_ENV: 'production',\n PORT: String(options.port),\n },\n stdio: 'inherit',\n });\n\n let forwardedSignal: NodeJS.Signals | undefined;\n const stop = (signal: NodeJS.Signals) => {\n forwardedSignal = signal;\n child.kill(signal);\n };\n process.once('SIGINT', stop);\n process.once('SIGTERM', stop);\n child.on('exit', code => process.exit(code ?? (forwardedSignal ? signalExitCodes[forwardedSignal] || 1 : 0)));\n child.on('error', error => {\n console.error(`${config.binName}: failed to start server: ${error.message}`);\n process.exit(1);\n });\n}\n\nexport function runLineageCli(config: LineageCliConfig, args = process.argv.slice(2)): void {\n if (args.includes('--help') || args.includes('-h') || args.length === 0) {\n printHelp(config);\n process.exit(0);\n }\n\n if (args.includes('--version') || args.includes('-v')) {\n console.log(packageVersion());\n process.exit(0);\n }\n\n const normalizedArgs = args[0] === 'lineage' ? args.slice(1) : args;\n const [command] = normalizedArgs;\n if (command === 'start') {\n start(config, normalizedArgs.slice(1));\n return;\n }\n\n if (command === 'next' || command === 'brief' || command === 'inspect' || command === 'link-child') {\n const commandArgs = normalizedArgs.slice(1);\n const json = commandArgs.includes('--json');\n try {\n printDataResult(command, runLineageDataCommand(command, commandArgs), json);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (json) console.error(JSON.stringify({ ok: false, command, error: message }, null, 2));\n else console.error(`${config.binName}: ${message}`);\n process.exit(1);\n }\n process.exit(0);\n }\n\n const json = args.includes('--json');\n const message = `Unknown command: ${command}`;\n if (json) console.error(JSON.stringify({ ok: false, command, error: message }, null, 2));\n else console.error(`${config.binName}: ${message}`);\n process.exit(1);\n}\n", "import { existsSync, mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\nimport { spawnSync } from 'node:child_process';\nimport { fileURLToPath } from 'node:url';\nimport { createS3StorageAdapter } from './adapters/storage';\nimport { listLocalReviewAssets, localPreviewPath as resolveLocalPreviewPath } from './localReview';\nimport { syncLedgerPlacement } from './assetLedgerWorkflow';\nimport { appName } from '../shared/appConstants';\nimport type {\n AssetCatalog,\n AssetContentType,\n AssetFacets,\n DoctorReport,\n AssetLibrarySnapshot,\n GrowthAsset,\n ListAssetsOptions,\n LiveS3Object,\n MutationResponse,\n PlacementFields,\n PlacementStatus,\n PresignResponse,\n ProjectSummary,\n UploadFields,\n} from '../shared/types';\n\nfunction isPackageRoot(path: string): boolean {\n const packageJson = join(path, 'package.json');\n if (!existsSync(packageJson)) return false;\n try {\n const packageInfo = JSON.parse(readFileSync(packageJson, 'utf8')) as { name?: string };\n return packageInfo.name === '@mean-weasel/lineage';\n } catch {\n return false;\n }\n}\n\nfunction resolveRepoRoot(): string {\n const moduleDir = dirname(fileURLToPath(import.meta.url));\n const candidates = [\n process.env.LINEAGE_REPO_ROOT,\n resolve(moduleDir, '..'),\n resolve(moduleDir, '../..'),\n process.cwd(),\n ].filter((candidate): candidate is string => Boolean(candidate));\n const root = candidates.find(isPackageRoot);\n if (!root) throw new Error('Unable to locate Lineage package root');\n return root;\n}\n\nexport const repoRoot = resolveRepoRoot();\nexport const defaultProject = 'demo-project';\nexport const defaultProduct = process.env.LINEAGE_DEFAULT_PRODUCT || defaultProject;\nconst publicFallbackBucket = 'lineage-demo-assets';\nconst publicFallbackRegion = 'us-east-1';\nconst contentTypes = new Set<AssetContentType>(['image', 'video', 'gif', 'audio', 'doc', 'other']);\nconst baseChannels = ['linkedin', 'meta', 'tiktok', 'x-twitter', 'youtube'];\nconst placementStatuses = new Set<PlacementStatus>(['planned', 'scheduled', 'posted', 'skipped']);\nconst projectNamePattern = /^[a-z0-9][a-z0-9-]*$/;\n\ninterface CommandResult {\n stdout: string;\n stderr: string;\n}\n\nclass LineageAssetError extends Error {\n constructor(message: string, public status = 400) {\n super(message);\n }\n}\n\nexport function isLineageAssetError(error: unknown): error is LineageAssetError {\n return error instanceof LineageAssetError;\n}\n\nexport function cleanProject(project = defaultProject): string {\n if (!projectNamePattern.test(project)) {\n throw new LineageAssetError('Project must be lowercase kebab-case');\n }\n return project;\n}\n\nexport function catalogPath(project = defaultProject): string {\n return join(repoRoot, cleanProject(project), 'assets', 'catalog.json');\n}\n\nfunction fixtureCatalogPath(project = defaultProject): string {\n return join(repoRoot, 'fixtures', cleanProject(project), 'assets', 'catalog.json');\n}\n\nfunction resolvedCatalogPath(project = defaultProject): string {\n const path = catalogPath(project);\n if (existsSync(path)) return path;\n const clean = cleanProject(project);\n if (clean === defaultProject && existsSync(fixtureCatalogPath(clean))) return fixtureCatalogPath(clean);\n return path;\n}\n\nexport function normalizeCatalog(catalog: Partial<AssetCatalog>, fallbackProject = defaultProject): AssetCatalog {\n const project = cleanProject(catalog.project || catalog.product || fallbackProject);\n const product = catalog.product || project;\n return {\n ...catalog,\n project,\n product,\n default_bucket: catalog.default_bucket || '',\n default_region: catalog.default_region || '',\n assets: (catalog.assets || []).map(asset => ({\n ...asset,\n source: asset.source || 'catalog',\n project: asset.project || asset.product || project,\n product: asset.product || asset.project || project,\n })),\n };\n}\n\nfunction fallbackS3(assetId: string, channel: string, status = 'working') {\n return {\n bucket: publicFallbackBucket,\n checksum_sha256: undefined,\n content_type: 'image/png',\n key: `products/${defaultProject}/campaigns/2026-06-public-demo/channels/${channel}/audiences/creators/statuses/${status}/types/image/assets/${assetId}/${assetId}.png`,\n region: publicFallbackRegion,\n size_bytes: 2048,\n updated_at: '2026-06-24T12:00:00.000Z',\n version_id: 'public-demo-version',\n };\n}\n\nfunction fallbackAsset(fields: Omit<GrowthAsset, 'audience' | 'campaign' | 'content_type' | 'cta' | 'hook' | 'product' | 'project' | 'source' | 'utm_content'> & {\n audience?: string;\n campaign?: string;\n cta?: string;\n hook?: string;\n utm_content?: string;\n}): GrowthAsset {\n return {\n audience: fields.audience || 'creators',\n campaign: fields.campaign || '2026-06-public-demo',\n content_type: 'image',\n cta: fields.cta || 'Save the idea',\n hook: fields.hook || 'Public demo creative for local review.',\n product: defaultProject,\n project: defaultProject,\n source: 'catalog',\n utm_content: fields.utm_content || fields.asset_id.replace(/-/g, '_'),\n ...fields,\n };\n}\n\nfunction defaultFallbackCatalog(): AssetCatalog {\n return normalizeCatalog({\n assets: [\n fallbackAsset({\n asset_id: 'demo-meta-short-form-upload-demo-post-static',\n channel: 'meta',\n s3: fallbackS3('demo-meta-short-form-upload-demo-post-static', 'meta'),\n status: 'working',\n title: 'Meta short-form demo post static',\n }),\n fallbackAsset({\n asset_id: 'demo-linkedin-ledger-catalog-shared',\n channel: 'linkedin',\n hook: 'Shared ledger creative with catalog metadata.',\n s3: fallbackS3('demo-linkedin-ledger-catalog-shared', 'linkedin'),\n status: 'working',\n title: 'LinkedIn ledger catalog shared',\n }),\n fallbackAsset({\n asset_id: 'demo-linkedin-upload-demo-done-static-grounded-v2',\n channel: 'linkedin',\n placements: [{\n channel: 'linkedin',\n notes: 'Synthetic public scheduled placement.',\n scheduled_at: '2026-06-24T16:00:00-07:00',\n status: 'scheduled',\n updated_at: '2026-06-24T12:30:00.000Z',\n }],\n s3: fallbackS3('demo-linkedin-upload-demo-done-static-grounded-v2', 'linkedin', 'approved'),\n status: 'approved',\n title: 'LinkedIn upload demo scheduled static',\n }),\n fallbackAsset({\n asset_id: 'demo-tiktok-upload-demo-export-vertical',\n channel: 'tiktok',\n format: 'vertical',\n hook: 'Fast vertical demo export for content queue tests.',\n s3: fallbackS3('demo-tiktok-upload-demo-export-vertical', 'tiktok'),\n status: 'working',\n title: 'TikTok upload demo export vertical',\n }),\n fallbackAsset({\n asset_id: 'demo-youtube-short-demo-posted-cut',\n channel: 'youtube',\n placements: [{\n channel: 'youtube',\n notes: 'Synthetic public posted placement.',\n posted_at: '2026-06-25T16:00:00-07:00',\n status: 'posted',\n updated_at: '2026-06-25T17:00:00.000Z',\n }],\n s3: fallbackS3('demo-youtube-short-demo-posted-cut', 'youtube', 'published'),\n status: 'published',\n title: 'YouTube short demo posted cut',\n }),\n fallbackAsset({\n asset_id: 'demo-x-twitter-carousel-demo-working-static',\n channel: 'x-twitter',\n format: 'static',\n s3: fallbackS3('demo-x-twitter-carousel-demo-working-static', 'x-twitter'),\n status: 'working',\n title: 'X Twitter carousel demo working static',\n }),\n ],\n default_bucket: '',\n default_region: '',\n product: defaultProject,\n project: defaultProject,\n }, defaultProject);\n}\n\nfunction isDefaultFallbackCatalog(catalog: AssetCatalog): boolean {\n return catalog.project === defaultProject && !existsSync(catalogPath(defaultProject));\n}\n\nfunction fallbackPreviewDataUrl(asset: GrowthAsset): string {\n const label = `${asset.title}\\n${asset.channel} / ${asset.status}`;\n const svg = `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1200\" height=\"675\" viewBox=\"0 0 1200 675\"><rect width=\"1200\" height=\"675\" fill=\"#f7f5ef\"/><rect x=\"56\" y=\"56\" width=\"1088\" height=\"563\" rx=\"18\" fill=\"#10201c\"/><text x=\"96\" y=\"145\" fill=\"#9fe6c8\" font-family=\"Arial, sans-serif\" font-size=\"34\" font-weight=\"700\">Lineage public demo preview</text><text x=\"96\" y=\"230\" fill=\"#fff8e6\" font-family=\"Arial, sans-serif\" font-size=\"56\" font-weight=\"700\">${escapeSvgText(asset.asset_id)}</text><text x=\"96\" y=\"330\" fill=\"#d9e8df\" font-family=\"Arial, sans-serif\" font-size=\"34\">${escapeSvgText(label)}</text><text x=\"96\" y=\"500\" fill=\"#9fb7ae\" font-family=\"Arial, sans-serif\" font-size=\"26\">Synthetic local placeholder. No external storage requested.</text></svg>`;\n return `data:image/svg+xml;base64,${Buffer.from(svg).toString('base64')}`;\n}\n\nfunction escapeSvgText(value: string): string {\n return value\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;');\n}\n\nexport function loadCatalog(project = defaultProject): AssetCatalog {\n const path = catalogPath(project);\n if (existsSync(path)) {\n try {\n return normalizeCatalog(JSON.parse(readFileSync(path, 'utf8')) as Partial<AssetCatalog>, project);\n } catch (error) {\n if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {\n throw new LineageAssetError(`Missing catalog: ${path}`, 404);\n }\n throw error;\n }\n }\n const clean = cleanProject(project);\n if (clean === defaultProject) {\n const fixturePath = fixtureCatalogPath(clean);\n if (existsSync(fixturePath)) {\n return normalizeCatalog(JSON.parse(readFileSync(fixturePath, 'utf8')) as Partial<AssetCatalog>, project);\n }\n return defaultFallbackCatalog();\n }\n throw new LineageAssetError(`Missing catalog: ${path}`, 404);\n}\n\nfunction saveCatalog(project: string, catalog: AssetCatalog): AssetCatalog {\n const normalized = normalizeCatalog(catalog, project);\n mkdirSync(dirname(catalogPath(project)), { recursive: true });\n writeFileSync(catalogPath(project), `${JSON.stringify(normalized, null, 2)}\\n`);\n return normalized;\n}\n\nfunction run(command: string, args: string[]): CommandResult {\n const result = spawnSync(command, args, {\n cwd: repoRoot,\n encoding: 'utf8',\n stdio: ['ignore', 'pipe', 'pipe'],\n env: {\n ...process.env,\n AWS_REGION: process.env.AWS_REGION || 'us-east-1',\n AWS_DEFAULT_REGION: process.env.AWS_DEFAULT_REGION || 'us-east-1',\n },\n });\n\n if (result.status !== 0) {\n const detail = result.stderr.trim() || result.stdout.trim();\n throw new LineageAssetError(`${command} ${args.join(' ')} failed${detail ? `: ${detail}` : ''}`, 502);\n }\n\n return { stdout: result.stdout, stderr: result.stderr };\n}\n\nfunction runAws(args: string[]): CommandResult {\n return run('aws', args);\n}\n\nexport function listProjects(): ProjectSummary[] {\n const projects = readdirSync(repoRoot, { withFileTypes: true })\n .filter(entry => entry.isDirectory() && projectNamePattern.test(entry.name) && existsSync(catalogPath(entry.name)))\n .flatMap(entry => {\n try {\n const catalog = loadCatalog(entry.name);\n return [{ project: catalog.project, product: catalog.product, catalogPath: resolvedCatalogPath(entry.name), default_bucket: catalog.default_bucket, default_region: catalog.default_region, asset_count: catalog.assets.length }];\n } catch (error) {\n if (error instanceof LineageAssetError && error.status === 404) return [];\n throw error;\n }\n })\n .sort((a, b) => a.project.localeCompare(b.project));\n if (!projects.some(item => item.project === defaultProject)) {\n const catalog = loadCatalog(defaultProject);\n projects.push({ project: catalog.project, product: catalog.product, catalogPath: resolvedCatalogPath(defaultProject), default_bucket: catalog.default_bucket, default_region: catalog.default_region, asset_count: catalog.assets.length });\n projects.sort((a, b) => a.project.localeCompare(b.project));\n }\n return projects;\n}\n\nfunction assetById(catalog: AssetCatalog, assetId: string): GrowthAsset {\n const asset = catalog.assets.find(item => item.asset_id === assetId);\n if (!asset) throw new LineageAssetError(`Unknown asset: ${assetId}`, 404);\n return asset;\n}\n\nconst storageAdapter = createS3StorageAdapter({\n assetById,\n cleanProject,\n createError: (message, status) => new LineageAssetError(message, status),\n defaultProject,\n loadCatalog,\n runAws,\n repoRoot,\n saveCatalog,\n supportedContentTypes: contentTypes,\n});\n\nfunction uniqueSorted<T extends string>(values: Array<T | undefined>): T[] {\n return Array.from(new Set(values.filter(Boolean) as T[])).sort();\n}\n\nfunction facetsFor(assets: GrowthAsset[]): AssetFacets {\n return {\n audiences: uniqueSorted(assets.map(asset => asset.audience)),\n campaigns: uniqueSorted(assets.map(asset => asset.campaign)),\n channels: uniqueSorted([...baseChannels, ...assets.map(asset => asset.channel)]),\n contentTypes: uniqueSorted(assets.map(asset => asset.content_type)),\n placementStatuses: uniqueSorted(assets.flatMap(asset => asset.placements?.map(placement => placement.status) || [])),\n statuses: uniqueSorted(assets.map(asset => asset.status)),\n totalSizeBytes: assets.reduce((sum, asset) => sum + (asset.s3?.size_bytes || 0), 0),\n };\n}\n\nfunction filteredAssets(assets: GrowthAsset[], options: ListAssetsOptions): GrowthAsset[] {\n const query = options.query?.trim().toLowerCase();\n return assets.filter(asset => {\n if (options.status && options.status !== 'all' && asset.status !== options.status) return false;\n if (options.channel && options.channel !== 'all' && asset.channel !== options.channel) return false;\n if (options.type && options.type !== 'all' && asset.content_type !== options.type) return false;\n if (options.placementStatus === 'not-posted' && asset.placements?.some(placement => placement.status === 'posted')) return false;\n if (options.placementStatus && !['all', 'not-posted'].includes(options.placementStatus) && !asset.placements?.some(placement => placement.status === options.placementStatus)) return false;\n if (options.campaign && options.campaign !== 'all' && asset.campaign !== options.campaign) return false;\n if (options.audience && options.audience !== 'all' && asset.audience !== options.audience) return false;\n if (!query) return true;\n return [asset.asset_id, asset.title, asset.campaign, asset.channel, asset.audience, asset.hook, asset.cta]\n .join(' ')\n .toLowerCase()\n .includes(query);\n });\n}\n\nexport function listAssets(project = defaultProject, options: ListAssetsOptions = {}): AssetLibrarySnapshot {\n const catalog = loadCatalog(project);\n const pageSize = Math.min(Math.max(Number(options.pageSize || 10), 1), 100);\n const page = Math.max(Number(options.page || 1), 1);\n const localAssets = listLocalReviewAssets(repoRoot, catalog.project, catalog);\n const source = options.source || 'catalog';\n const sourceAssets = source === 'local' ? localAssets : source === 'all' ? [...localAssets, ...catalog.assets] : catalog.assets;\n const filtered = filteredAssets(sourceAssets, options);\n const totalPages = Math.max(Math.ceil(filtered.length / pageSize), 1);\n const safePage = Math.min(page, totalPages);\n const start = (safePage - 1) * pageSize;\n const pageAssets = filtered.slice(start, start + pageSize);\n let liveObjects: LiveS3Object[] = [];\n let error: string | undefined;\n if (options.includeLive && !isDefaultFallbackCatalog(catalog)) {\n try {\n liveObjects = storageAdapter.listLiveObjects(catalog);\n } catch (err) {\n error = err instanceof Error ? err.message : String(err);\n }\n }\n return {\n catalog: { project: catalog.project, product: catalog.product, default_bucket: catalog.default_bucket, default_region: catalog.default_region, asset_count: catalog.assets.length },\n assets: pageAssets,\n facets: facetsFor(catalog.assets),\n pagination: { page: safePage, pageSize, total: filtered.length, totalPages },\n liveObjects,\n orphanObjects: liveObjects.filter(object => !object.cataloged),\n identity: options.includeLive && !isDefaultFallbackCatalog(catalog) ? storageAdapter.getIdentity() : undefined,\n fetchedAt: new Date().toISOString(),\n error,\n };\n}\n\nexport function inspectAsset(project: string, assetId: string): GrowthAsset {\n return assetById(loadCatalog(project), assetId);\n}\n\nexport function validateProject(project = defaultProject): ProjectSummary {\n const catalog = loadCatalog(project);\n return { project: catalog.project, product: catalog.product, catalogPath: resolvedCatalogPath(project), default_bucket: catalog.default_bucket, default_region: catalog.default_region, asset_count: catalog.assets.length };\n}\n\nexport function doctorProject(project = defaultProject, options: { includeLive?: boolean } = {}): DoctorReport {\n const summary = validateProject(project);\n let liveCheck: DoctorReport['liveCheck'] = 'skipped';\n let liveError: string | undefined;\n if (options.includeLive && isDefaultFallbackCatalog(loadCatalog(project))) {\n liveCheck = 'skipped';\n liveError = `${appName} public fallback uses local catalog data only.`;\n } else if (options.includeLive) {\n try {\n storageAdapter.listLiveObjects(loadCatalog(project));\n liveCheck = 'ok';\n } catch (error) {\n liveCheck = 'error';\n liveError = error instanceof Error ? error.message : String(error);\n }\n }\n return { catalogExists: true, deleteEnabled: process.env.LINEAGE_ENABLE_CLOUD_DELETE === 'true', project: summary, liveCheck, liveError };\n}\n\nexport function pullAsset(project: string, assetId: string, out = '.asset-scratch'): MutationResponse {\n return storageAdapter.pullAsset(project, assetId, out);\n}\n\nfunction placementFromFields(fields: PlacementFields) {\n if (!fields.channel) throw new LineageAssetError('Placement requires channel');\n if (!placementStatuses.has(fields.status)) throw new LineageAssetError(`Unsupported placement status: ${fields.status}`);\n const now = new Date().toISOString();\n return {\n channel: fields.channel,\n status: fields.status,\n ...(fields.scheduledAt ? { scheduled_at: fields.scheduledAt } : {}),\n ...(fields.postedAt ? { posted_at: fields.postedAt } : {}),\n ...(fields.url ? { url: fields.url } : {}),\n ...(fields.notes ? { notes: fields.notes } : {}),\n updated_at: now,\n };\n}\n\nexport function previewPlacement(project: string, fields: PlacementFields) {\n const asset = inspectAsset(project, fields.assetId);\n return { asset_id: asset.asset_id, placement: placementFromFields(fields) };\n}\n\nexport function updatePlacement(project: string, fields: PlacementFields): MutationResponse {\n if (!fields.confirmWrite) throw new LineageAssetError('Placement updates require confirmWrite=true');\n const catalog = loadCatalog(project);\n const asset = assetById(catalog, fields.assetId);\n const placement = placementFromFields(fields);\n const existing = asset.placements?.findIndex(item => item.channel === placement.channel);\n if (existing !== undefined && existing >= 0) asset.placements![existing] = placement;\n else asset.placements = [...(asset.placements || []), placement];\n saveCatalog(project, catalog);\n syncLedgerPlacement(project, asset.asset_id, placement);\n return { ok: true, message: `Marked ${asset.asset_id} ${placement.status} for ${placement.channel}`, catalog };\n}\n\nexport function presignAsset(project: string, assetId: string, expiresIn = 900): PresignResponse {\n const catalog = loadCatalog(project);\n if (isDefaultFallbackCatalog(catalog)) {\n const asset = assetById(catalog, assetId);\n return { assetId: asset.asset_id, expiresIn, url: fallbackPreviewDataUrl(asset) };\n }\n return storageAdapter.presignAsset(project, assetId, expiresIn);\n}\n\nexport function localPreviewPath(relativePath: string): string {\n try {\n return resolveLocalPreviewPath(repoRoot, relativePath);\n } catch (error) {\n throw new LineageAssetError(error instanceof Error ? error.message : 'Unknown local review asset', 404);\n }\n}\n\nexport function promoteAsset(project: string, assetId: string, confirmWrite: boolean): MutationResponse {\n return storageAdapter.promoteAsset(project, assetId, confirmWrite);\n}\n\nexport function archiveAsset(project: string, assetId: string, confirmArchive: boolean): MutationResponse {\n if (!confirmArchive) throw new LineageAssetError('Archive requires confirmArchive=true');\n const catalog = loadCatalog(project);\n const asset = assetById(catalog, assetId);\n asset.status = 'archived';\n saveCatalog(project, catalog);\n return { ok: true, message: `Archived ${assetId}`, catalog };\n}\n\nexport function uploadAsset(file: string, fields: UploadFields): MutationResponse {\n return storageAdapter.uploadAsset(file, fields);\n}\n\nexport function deleteObjectGuarded(project: string, assetId: string, confirmation: string): MutationResponse {\n return storageAdapter.deleteObjectGuarded(project, assetId, confirmation);\n}\n\nexport function ensureUploadDir(): string {\n const dir = join(repoRoot, '.asset-scratch', 'studio-uploads');\n mkdirSync(dir, { recursive: true });\n return dir;\n}\n\nexport function cleanupUploadedTemp(file?: string): void {\n if (!file) return;\n const uploadRoot = ensureUploadDir();\n const resolved = resolve(file);\n if (resolved.startsWith(`${uploadRoot}/`) && existsSync(resolved)) {\n unlinkSync(resolved);\n }\n}\n", "import { copyFileSync, existsSync, mkdirSync, statSync } from 'node:fs';\nimport { basename, dirname, join } from 'node:path';\nimport { contentTypeFor, fileSha256 } from '../../localReview';\nimport type { AssetCatalog, LiveS3Object, MutationResponse, PresignResponse } from '../../../shared/types';\nimport type { StorageAdapter, StorageAdapterDependencies } from './types';\n\nexport function parseAssetIdFromS3Key(key: string): string | undefined {\n const marker = '/assets/';\n const index = key.indexOf(marker);\n if (index === -1) return undefined;\n return key.slice(index + marker.length).split('/')[0];\n}\n\nfunction previewDataUrl(asset: { asset_id: string; channel?: string; status?: string; title?: string }): string {\n const title = asset.title || asset.asset_id;\n const label = `${asset.channel || 'catalog'} / ${asset.status || 'working'}`;\n const svg = `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1200\" height=\"675\" viewBox=\"0 0 1200 675\"><rect width=\"1200\" height=\"675\" fill=\"#f7f5ef\"/><rect x=\"56\" y=\"56\" width=\"1088\" height=\"563\" rx=\"18\" fill=\"#10201c\"/><text x=\"96\" y=\"145\" fill=\"#9fe6c8\" font-family=\"Arial, sans-serif\" font-size=\"34\" font-weight=\"700\">Lineage catalog preview</text><text x=\"96\" y=\"230\" fill=\"#fff8e6\" font-family=\"Arial, sans-serif\" font-size=\"56\" font-weight=\"700\">${escapeSvgText(asset.asset_id)}</text><text x=\"96\" y=\"330\" fill=\"#d9e8df\" font-family=\"Arial, sans-serif\" font-size=\"34\">${escapeSvgText(title)}</text><text x=\"96\" y=\"500\" fill=\"#9fb7ae\" font-family=\"Arial, sans-serif\" font-size=\"26\">${escapeSvgText(label)}. No external storage requested.</text></svg>`;\n return `data:image/svg+xml;base64,${Buffer.from(svg).toString('base64')}`;\n}\n\nfunction escapeSvgText(value: string): string {\n return value\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;');\n}\n\nexport function createS3StorageAdapter(deps: StorageAdapterDependencies): StorageAdapter {\n return {\n deleteObjectGuarded(project, assetId, confirmation): MutationResponse {\n const enabled = process.env.LINEAGE_ENABLE_CLOUD_DELETE === 'true';\n if (!enabled) {\n throw deps.createError('S3 delete is disabled. Use archive unless a human enables LINEAGE_ENABLE_CLOUD_DELETE.', 403);\n }\n if (confirmation !== `delete ${assetId}`) {\n throw deps.createError(`Delete confirmation must exactly equal: delete ${assetId}`);\n }\n const catalog = deps.loadCatalog(project);\n const asset = deps.assetById(catalog, assetId);\n if (!asset.s3) throw deps.createError(`Asset has no S3 object: ${assetId}`);\n deps.runAws(['s3api', 'delete-object', '--bucket', asset.s3.bucket, '--key', asset.s3.key, '--region', asset.s3.region]);\n asset.status = 'archived';\n deps.saveCatalog(project, catalog);\n return { ok: true, message: `Deleted current S3 object and archived ${assetId}`, catalog };\n },\n\n getIdentity() {\n try {\n const output = deps.runAws(['sts', 'get-caller-identity', '--query', '{Account:Account,Arn:Arn}', '--output', 'json']);\n const parsed = JSON.parse(output.stdout) as { Account: string; Arn: string };\n return { account: parsed.Account, arn: parsed.Arn };\n } catch {\n return undefined;\n }\n },\n\n listLiveObjects(catalog: AssetCatalog): LiveS3Object[] {\n const bucket = catalog.default_bucket;\n const region = catalog.default_region;\n // Existing uploaded objects live under products/<project>; do not rewrite keys during project migration.\n const prefix = `products/${catalog.product}/`;\n const output = deps.runAws(['s3api', 'list-objects-v2', '--bucket', bucket, '--prefix', prefix, '--region', region, '--output', 'json']);\n const parsed = JSON.parse(output.stdout) as {\n Contents?: Array<{ Key: string; Size: number; LastModified: string; StorageClass?: string }>;\n };\n const catalogKeys = new Set(catalog.assets.map(asset => asset.s3?.key).filter(Boolean));\n return (parsed.Contents || []).map(item => ({\n key: item.Key,\n size: item.Size,\n lastModified: item.LastModified,\n storageClass: item.StorageClass,\n cataloged: catalogKeys.has(item.Key),\n assetId: parseAssetIdFromS3Key(item.Key),\n }));\n },\n\n presignAsset(project, assetId, expiresIn = 900): PresignResponse {\n const catalog = deps.loadCatalog(project);\n const asset = deps.assetById(catalog, assetId);\n return { assetId, expiresIn, url: previewDataUrl(asset) };\n },\n\n promoteAsset(project, assetId, confirmWrite): MutationResponse {\n if (!confirmWrite) throw deps.createError('Promote requires confirmWrite=true');\n const catalog = deps.loadCatalog(project);\n const asset = deps.assetById(catalog, assetId);\n asset.status = 'published';\n deps.saveCatalog(project, catalog);\n return {\n ok: true,\n message: `Promoted ${assetId}`,\n catalog,\n };\n },\n\n pullAsset(project, assetId, out = '.asset-scratch'): MutationResponse {\n const catalog = deps.loadCatalog(project);\n const asset = deps.assetById(catalog, assetId);\n return {\n ok: true,\n message: `Prepared ${assetId} for local review`,\n output: {\n assetId: asset.asset_id,\n out,\n storage: asset.local ? 'local' : asset.s3 ? 'catalog-s3-metadata' : 'catalog',\n note: 'Lineage public package does not pull cloud objects automatically.',\n },\n };\n },\n\n uploadAsset(file, fields): MutationResponse {\n if (!fields.confirmWrite) throw deps.createError('Upload requires confirmWrite=true');\n if (!existsSync(file)) throw deps.createError(`Upload file missing: ${file}`, 404);\n if (!['working', 'published'].includes(fields.status)) throw deps.createError('Upload status must be working or published');\n if (!deps.supportedContentTypes.has(fields.type)) throw deps.createError(`Unsupported asset type: ${fields.type}`);\n\n const project = deps.cleanProject(fields.project || fields.product || deps.defaultProject);\n const catalog = deps.loadCatalog(project);\n const relativePath = join('uploads', project, fields.assetId, basename(file));\n const absolutePath = join(deps.repoRoot, '.asset-scratch', relativePath);\n mkdirSync(dirname(absolutePath), { recursive: true });\n copyFileSync(file, absolutePath);\n const stats = statSync(absolutePath);\n const contentType = contentTypeFor(absolutePath);\n const checksumSha256 = fileSha256(absolutePath);\n const now = new Date().toISOString();\n const nextAsset = {\n asset_id: fields.assetId,\n audience: fields.audience,\n campaign: fields.campaign,\n channel: fields.channel,\n content_type: fields.type,\n cta: fields.cta,\n hook: fields.hook,\n ...(fields.format ? { format: fields.format } : {}),\n local: {\n absolute_path: absolutePath,\n checksum_sha256: checksumSha256,\n content_type: contentType,\n relative_path: relativePath,\n size_bytes: stats.size,\n updated_at: now,\n },\n ...(fields.messageFamily ? { message_family: fields.messageFamily } : {}),\n ...(fields.notes ? { notes: fields.notes } : {}),\n product: project,\n project,\n source: 'catalog' as const,\n status: fields.status,\n title: fields.title,\n utm_content: fields.utmContent,\n };\n const existing = catalog.assets.findIndex(asset => asset.asset_id === fields.assetId);\n if (existing >= 0) catalog.assets[existing] = { ...catalog.assets[existing], ...nextAsset };\n else catalog.assets.push(nextAsset);\n deps.saveCatalog(project, catalog);\n return {\n ok: true,\n message: `Recorded ${fields.assetId} locally`,\n output: {\n file: basename(absolutePath),\n relativePath,\n sizeBytes: stats.size,\n contentType,\n checksumSha256,\n },\n catalog,\n };\n },\n };\n}\n", "import { createHash } from 'node:crypto';\nimport { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';\nimport { basename, extname, join, relative, resolve } from 'node:path';\nimport type { AssetCatalog, AssetContentType, GrowthAsset } from '../shared/types';\n\nconst mimeByExt: Record<string, string> = {\n '.gif': 'image/gif',\n '.jpeg': 'image/jpeg',\n '.jpg': 'image/jpeg',\n '.mov': 'video/quicktime',\n '.mp4': 'video/mp4',\n '.png': 'image/png',\n '.svg': 'image/svg+xml',\n '.webp': 'image/webp',\n};\nconst localReviewExts = new Set(Object.keys(mimeByExt));\nconst channelFromName = /\\b(linkedin|meta|tiktok|youtube|x-twitter|x)\\b/i;\nconst campaignFromPath = /\\b(20\\d{2}-\\d{2}-[a-z0-9-]+)\\b/i;\n\nclass LocalReviewError extends Error {\n status = 400;\n}\n\nfunction localReviewRoot(repoRoot: string): string {\n return join(repoRoot, '.asset-scratch');\n}\n\nexport function contentTypeFor(file: string): string {\n return mimeByExt[extname(file).toLowerCase()] || 'application/octet-stream';\n}\n\nexport function fileSha256(file: string): string {\n return createHash('sha256').update(readFileSync(file)).digest('hex');\n}\n\nfunction isPathInside(child: string, parent: string): boolean {\n const relativePath = relative(parent, child);\n return Boolean(relativePath) && !relativePath.startsWith('..') && !relativePath.startsWith('/');\n}\n\nfunction walkLocalReviewFiles(dir: string, files: string[] = []): string[] {\n if (!existsSync(dir)) return files;\n let entries;\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return files;\n throw error;\n }\n for (const entry of entries) {\n if (entry.name === 'node_modules' || entry.name === '.git' || entry.name === 'studio-uploads') continue;\n if (process.env.NODE_ENV !== 'test' && /^vitest-/.test(entry.name)) continue;\n const path = join(dir, entry.name);\n if (entry.isDirectory()) walkLocalReviewFiles(path, files);\n else if (entry.isFile() && localReviewExts.has(extname(entry.name).toLowerCase())) files.push(path);\n }\n return files;\n}\n\nfunction inferCampaign(relativePath: string): string {\n return campaignFromPath.exec(relativePath)?.[1] || 'local-review';\n}\n\nfunction inferChannel(relativePath: string): string {\n const match = channelFromName.exec(relativePath);\n if (!match) return 'local';\n return match[1].toLowerCase() === 'x' ? 'x-twitter' : match[1].toLowerCase();\n}\n\nfunction inferContentType(file: string): AssetContentType {\n const mime = contentTypeFor(file);\n if (mime.startsWith('image/gif')) return 'gif';\n if (mime.startsWith('image/')) return 'image';\n if (mime.startsWith('video/')) return 'video';\n return 'other';\n}\n\nexport function listLocalReviewAssets(repoRoot: string, project: string, catalog: AssetCatalog): GrowthAsset[] {\n const catalogChecksums = new Set(catalog.assets.map(asset => asset.s3?.checksum_sha256).filter(Boolean));\n const root = localReviewRoot(repoRoot);\n return walkLocalReviewFiles(root)\n .flatMap(file => {\n try {\n const stats = statSync(file);\n const checksum = fileSha256(file);\n const relativePath = relative(root, file);\n return [{ checksum, file, relativePath, stats }];\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return [];\n throw error;\n }\n })\n .filter(item => !catalogChecksums.has(item.checksum))\n .map(item => {\n const fileSlug = basename(item.file, extname(item.file));\n const channel = inferChannel(item.relativePath);\n return {\n asset_id: `local-${item.checksum.slice(0, 12)}`,\n project,\n product: project,\n source: 'local',\n campaign: inferCampaign(item.relativePath),\n channel,\n audience: 'local-review',\n status: 'planned',\n content_type: inferContentType(item.file),\n title: fileSlug.replace(/[-_]+/g, ' '),\n hook: item.relativePath,\n cta: 'Review before upload',\n utm_content: fileSlug.replace(/[^a-zA-Z0-9]+/g, '_').replace(/^_+|_+$/g, '').toLowerCase() || 'local_review',\n notes: 'Local pre-push asset. Review and refine before uploading to S3.',\n local: {\n relative_path: item.relativePath,\n absolute_path: item.file,\n size_bytes: item.stats.size,\n content_type: contentTypeFor(item.file),\n checksum_sha256: item.checksum,\n updated_at: item.stats.mtime.toISOString(),\n },\n };\n });\n}\n\nexport function localPreviewPath(repoRoot: string, relativePath: string): string {\n const root = localReviewRoot(repoRoot);\n const resolved = resolve(root, relativePath);\n if (!isPathInside(resolved, root) || !existsSync(resolved)) throw new LocalReviewError('Unknown local review asset');\n if (!localReviewExts.has(extname(resolved).toLowerCase())) throw new LocalReviewError('Local preview type is not supported');\n return resolved;\n}\n", "import { createRequire } from 'node:module';\nimport type { DatabaseSync as DatabaseSyncType } from 'node:sqlite';\nimport { mkdirSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { repoRoot } from './assetCore';\n\nconst require = createRequire(import.meta.url);\nexport type DatabaseSync = DatabaseSyncType;\n\nexport function nowIso(): string {\n return new Date().toISOString();\n}\n\nexport function lineageDbPath(): string {\n return process.env.LINEAGE_DB || join(repoRoot, '.lineage', 'asset-lineage.sqlite');\n}\n\nexport function lineageDb(): DatabaseSync {\n mkdirSync(join(lineageDbPath(), '..'), { recursive: true });\n const { DatabaseSync } = require('node:sqlite') as typeof import('node:sqlite');\n const database = new DatabaseSync(lineageDbPath());\n database.exec('PRAGMA foreign_keys = ON'); database.exec('PRAGMA busy_timeout = 5000');\n database.exec(`\n create table if not exists projects (\n id text primary key,\n product text not null,\n catalog_path text,\n created_at text not null,\n updated_at text not null\n );\n create table if not exists assets (\n id text primary key,\n project_id text not null references projects(id),\n source text not null check (source in ('local', 'catalog')),\n local_path text,\n s3_key text,\n checksum_sha256 text,\n media_type text not null,\n title text not null,\n status text not null,\n channel text,\n campaign text,\n audience text,\n size_bytes integer,\n content_type text,\n created_at text not null,\n updated_at text not null,\n last_seen_at text not null\n );\n create index if not exists assets_project_source_seen on assets(project_id, source, last_seen_at);\n create index if not exists assets_project_checksum on assets(project_id, checksum_sha256);\n create index if not exists assets_project_channel_campaign on assets(project_id, channel, campaign);\n create table if not exists asset_edges (\n id text primary key,\n project_id text not null references projects(id),\n parent_asset_id text not null references assets(id),\n child_asset_id text not null references assets(id),\n relation_type text not null check (relation_type in ('derived_from')),\n created_at text not null,\n unique (project_id, parent_asset_id, child_asset_id, relation_type)\n );\n create index if not exists edges_parent on asset_edges(project_id, parent_asset_id);\n create index if not exists edges_child on asset_edges(project_id, child_asset_id);\n create table if not exists asset_reviews (\n asset_id text primary key references assets(id),\n review_state text not null check (review_state in ('unreviewed', 'approved', 'needs_revision', 'rejected', 'ignored')),\n reviewed_at text,\n ignored_at text,\n notes text,\n updated_at text not null\n );\n create table if not exists asset_selections (\n id text primary key,\n project_id text not null references projects(id),\n root_asset_id text not null references assets(id),\n asset_id text not null references assets(id),\n notes text,\n selected_at text not null,\n unique(project_id, root_asset_id)\n );\n create table if not exists asset_layouts (\n id text primary key,\n project_id text not null references projects(id),\n root_asset_id text not null references assets(id),\n asset_id text not null references assets(id),\n x real not null,\n y real not null,\n updated_at text not null,\n unique(project_id, root_asset_id, asset_id)\n );\n create table if not exists lineage_workspaces (\n id text primary key,\n project_id text not null references projects(id),\n root_asset_id text not null references assets(id),\n title text not null,\n status text not null check (status in ('active', 'paused', 'archived')),\n notes text,\n created_by text not null check (created_by in ('human', 'agent', 'system')),\n active_at text,\n created_at text not null,\n updated_at text not null,\n unique(project_id, root_asset_id)\n );\n create index if not exists lineage_workspaces_project_status on lineage_workspaces(project_id, status, updated_at);\n create index if not exists lineage_workspaces_project_active on lineage_workspaces(project_id, active_at);\n create table if not exists asset_ledger_records (\n id text primary key,\n project_id text not null references projects(id),\n canonical_asset_id text not null,\n checksum_sha256 text,\n media_type text not null,\n title text not null,\n status text not null,\n channel text,\n campaign text,\n audience text,\n created_at text not null,\n updated_at text not null,\n first_seen_at text not null default (datetime('now')),\n last_seen_at text not null\n );\n create index if not exists asset_ledger_records_project_seen on asset_ledger_records(project_id, last_seen_at);\n create index if not exists asset_ledger_records_project_checksum on asset_ledger_records(project_id, checksum_sha256);\n create table if not exists asset_ledger_sources (\n id text primary key,\n project_id text not null references projects(id),\n record_id text not null references asset_ledger_records(id) on delete cascade,\n source_type text not null check (source_type in ('local', 'catalog', 's3')),\n asset_id text,\n local_path text,\n s3_bucket text,\n s3_region text,\n s3_key text,\n s3_version_id text,\n etag text,\n size_bytes integer,\n content_type text,\n updated_at text,\n first_seen_at text not null default (datetime('now')),\n last_seen_at text not null\n );\n create index if not exists asset_ledger_sources_project_type on asset_ledger_sources(project_id, source_type);\n create index if not exists asset_ledger_sources_record on asset_ledger_sources(project_id, record_id);\n create index if not exists asset_ledger_sources_s3_key on asset_ledger_sources(project_id, s3_key);\n create table if not exists asset_ledger_placements (\n id text primary key,\n project_id text not null references projects(id),\n asset_id text not null,\n channel text not null,\n status text not null,\n scheduled_at text,\n posted_at text,\n url text,\n notes text,\n updated_at text not null,\n synced_at text not null,\n unique(project_id, asset_id, channel)\n );\n create index if not exists asset_ledger_placements_project_status on asset_ledger_placements(project_id, status);\n create index if not exists asset_ledger_placements_asset on asset_ledger_placements(project_id, asset_id);\n create table if not exists asset_ledger_index_runs (\n id text primary key,\n project_id text not null references projects(id),\n source_mode text not null check (source_mode in ('all', 'catalog', 'local')),\n include_live_s3 integer not null default 0,\n status text not null check (status in ('running', 'complete', 'failed')),\n started_at text not null,\n completed_at text,\n assets_indexed integer not null default 0,\n records_after integer not null default 0,\n catalog_sources_after integer not null default 0,\n local_sources_after integer not null default 0,\n s3_sources_after integer not null default 0,\n error text\n );\n create index if not exists asset_ledger_index_runs_project_started on asset_ledger_index_runs(project_id, started_at);\n create table if not exists content_batches (\n id text not null,\n project_id text not null references projects(id),\n title text not null,\n campaign text,\n channel text,\n status text not null check (status in ('active', 'archived')),\n notes text,\n created_at text not null,\n updated_at text not null,\n primary key(project_id, id)\n );\n create index if not exists content_batches_project_updated on content_batches(project_id, updated_at);\n create table if not exists content_posts (\n id text not null,\n project_id text not null references projects(id),\n batch_id text not null,\n channel text not null,\n title text not null,\n phase text not null check (phase in ('draft', 'review', 'scheduled', 'posted', 'skipped', 'archived')),\n campaign text,\n body text,\n cta text,\n scheduled_at text,\n posted_at text,\n url text,\n notes text,\n source_path text,\n created_at text not null,\n updated_at text not null,\n primary key(project_id, id),\n foreign key(project_id, batch_id) references content_batches(project_id, id) on delete cascade\n );\n create index if not exists content_posts_project_phase on content_posts(project_id, phase);\n create index if not exists content_posts_batch on content_posts(project_id, batch_id);\n create table if not exists content_post_assets (\n id text primary key,\n project_id text not null references projects(id),\n post_id text not null,\n asset_id text not null,\n role text not null,\n notes text,\n attached_at text not null,\n unique(project_id, post_id, asset_id, role),\n foreign key(project_id, post_id) references content_posts(project_id, id) on delete cascade\n );\n create index if not exists content_post_assets_post on content_post_assets(project_id, post_id);\n create index if not exists content_post_assets_asset on content_post_assets(project_id, asset_id);\n create table if not exists content_targets (\n project_id text primary key references projects(id),\n post_id text not null,\n notes text,\n selected_at text not null,\n updated_at text not null,\n foreign key(project_id, post_id) references content_posts(project_id, id) on delete cascade\n );\n create table if not exists selection_sets (\n id text primary key,\n project_id text not null references projects(id),\n kind text not null check (kind in ('current', 'review')),\n key text not null,\n label text not null,\n status text not null check (status in ('active', 'archived')),\n created_by text not null check (created_by in ('human', 'agent', 'system')),\n created_at text not null,\n updated_at text not null,\n unique(project_id, kind, key)\n );\n create index if not exists selection_sets_project_kind on selection_sets(project_id, kind, updated_at);\n create table if not exists selection_items (\n id text primary key,\n set_id text not null references selection_sets(id) on delete cascade,\n asset_id text not null,\n role text not null check (role in ('primary', 'candidate', 'next_base')),\n variation_label text,\n position integer not null default 0,\n selected_by text check (selected_by in ('human', 'agent', 'system')),\n selected_at text,\n deselected_at text,\n notes text,\n created_at text not null,\n updated_at text not null,\n unique(set_id, asset_id)\n );\n create index if not exists selection_items_set_position on selection_items(set_id, position);\n create unique index if not exists selection_items_set_label on selection_items(set_id, variation_label) where variation_label is not null;\n create table if not exists generation_jobs (\n id text primary key,\n project_id text not null references projects(id),\n provider text not null default 'codex-handoff',\n adapter_version text not null,\n source_mode text not null check (source_mode in ('lineage_selection')),\n root_asset_id text not null references assets(id),\n prompt text not null,\n expected_output_count integer not null check (expected_output_count > 0),\n status text not null check (status in ('planned', 'imported', 'failed', 'cancelled')),\n output_dir text,\n handoff_json text,\n created_at text not null,\n updated_at text not null,\n imported_at text\n );\n create index if not exists generation_jobs_project_created on generation_jobs(project_id, created_at);\n create table if not exists generation_job_inputs (\n id text primary key,\n job_id text not null references generation_jobs(id) on delete cascade,\n project_id text not null references projects(id),\n asset_id text not null references assets(id),\n root_asset_id text not null references assets(id),\n role text not null check (role in ('lineage_next_base', 'reference')),\n position integer not null,\n selection_strategy text not null,\n selection_snapshot_json text not null,\n unique(job_id, asset_id, role)\n );\n create index if not exists generation_job_inputs_job on generation_job_inputs(job_id, position);\n create table if not exists generation_job_outputs (\n id text primary key,\n job_id text not null references generation_jobs(id) on delete cascade,\n project_id text not null references projects(id),\n output_index integer not null,\n file_path text not null,\n checksum_sha256 text not null,\n size_bytes integer not null,\n content_type text not null,\n imported_asset_id text not null references assets(id),\n parent_asset_id text not null references assets(id),\n imported_at text not null,\n unique(job_id, output_index),\n unique(job_id, file_path)\n );\n create index if not exists generation_job_outputs_job on generation_job_outputs(job_id, output_index);\n create table if not exists generation_job_receipts (\n id text primary key,\n job_id text not null references generation_jobs(id) on delete cascade,\n receipt_type text not null check (receipt_type in ('plan', 'import', 'error')),\n status text not null check (status in ('ok', 'error')),\n command text not null,\n payload_json text not null,\n created_at text not null\n );\n create index if not exists generation_job_receipts_job on generation_job_receipts(job_id, created_at);\n create table if not exists adapter_settings (project_id text not null references projects(id), adapter_type text not null check (adapter_type in ('cloud', 'scheduler', 'image_generator')), provider text not null, enabled integer not null check (enabled in (0, 1)), secret_ref text, safe_config_json text not null, created_at text not null, updated_at text not null, primary key(project_id, adapter_type, provider)); create index if not exists adapter_settings_project_type on adapter_settings(project_id, adapter_type);\n `);\n migrateAssetSelections(database);\n dropLegacyAssetSelectionRootUnique(database);\n ensureColumn(database, 'asset_selections', 'notes', 'text');\n ensureColumn(database, 'asset_ledger_records', 'first_seen_at', 'text');\n ensureColumn(database, 'asset_ledger_records', 'indexed_by_run_id', 'text');\n ensureColumn(database, 'asset_ledger_sources', 'first_seen_at', 'text');\n ensureColumn(database, 'asset_ledger_sources', 'indexed_by_run_id', 'text');\n ensureReviewStateValues(database);\n return database;\n}\n\nfunction ensureColumn(database: DatabaseSync, table: string, column: string, definition: string): void {\n const rows = database.prepare(`pragma table_info(${table})`).all() as Array<{ name: string }>;\n if (!rows.some(row => row.name === column)) database.exec(`alter table ${table} add column ${column} ${definition}`);\n}\n\nfunction migrateAssetSelections(database: DatabaseSync): void {\n const rows = database.prepare('pragma table_info(asset_selections)').all() as Array<{ name: string }>;\n if (rows.some(row => row.name === 'position')) return;\n const notesSelect = rows.some(row => row.name === 'notes') ? 'notes' : 'null';\n\n database.exec(`\n create table if not exists asset_selections_v2 (\n id text primary key,\n project_id text not null references projects(id),\n root_asset_id text not null references assets(id),\n asset_id text not null references assets(id),\n position integer not null default 0,\n notes text,\n selected_at text not null,\n unique(project_id, root_asset_id, asset_id)\n );\n insert or ignore into asset_selections_v2 (id, project_id, root_asset_id, asset_id, position, notes, selected_at)\n select\n project_id || ':' || root_asset_id || ':selected:' || asset_id,\n project_id,\n root_asset_id,\n asset_id,\n 0,\n ${notesSelect},\n selected_at\n from asset_selections;\n drop table asset_selections;\n alter table asset_selections_v2 rename to asset_selections;\n create index if not exists asset_selections_project_root_position\n on asset_selections(project_id, root_asset_id, position, selected_at);\n `);\n}\n\nfunction dropLegacyAssetSelectionRootUnique(database: DatabaseSync): void {\n const indexes = database.prepare('pragma index_list(asset_selections)').all() as Array<{ name: string; unique: number }>;\n for (const index of indexes) {\n if (!index.unique) continue;\n const columns = database.prepare(`pragma index_info(${index.name})`).all() as Array<{ name: string }>;\n const columnNames = columns.map(column => column.name).join(',');\n if (columnNames === 'project_id,root_asset_id') database.exec(`drop index if exists ${index.name}`);\n }\n}\n\nfunction ensureReviewStateValues(database: DatabaseSync): void {\n const createSql = database.prepare(\"select sql from sqlite_master where type = 'table' and name = 'asset_reviews'\").get() as { sql?: string } | undefined;\n if (createSql?.sql?.includes('needs_revision')) return;\n\n database.exec(`\n alter table asset_reviews rename to asset_reviews_old;\n create table asset_reviews (\n asset_id text primary key references assets(id),\n review_state text not null check (review_state in ('unreviewed', 'approved', 'needs_revision', 'rejected', 'ignored')),\n reviewed_at text,\n ignored_at text,\n notes text,\n updated_at text not null\n );\n insert into asset_reviews (asset_id, review_state, reviewed_at, ignored_at, notes, updated_at)\n select asset_id, review_state, reviewed_at, ignored_at, notes, updated_at\n from asset_reviews_old;\n drop table asset_reviews_old;\n `);\n}\n", "import type { SelectionFields } from '../shared/types';\nimport type { DatabaseSync } from './assetLineageDb';\n\nexport const LINEAGE_NEXT_VARIATION_LIMIT = 3;\n\nexport interface LineageSelectionRow {\n asset_id: string;\n notes?: string;\n position: number;\n selected_at: string;\n}\n\nexport function selectionId(project: string, root: string, assetId: string): string {\n return `${project}:${root}:selected:${assetId}`;\n}\n\nexport function selectedRows(database: DatabaseSync, project: string, root: string): LineageSelectionRow[] {\n return database.prepare(`\n select asset_id, notes, position, selected_at\n from asset_selections\n where project_id = ? and root_asset_id = ?\n order by position, selected_at, asset_id\n `).all(project, root) as unknown as LineageSelectionRow[];\n}\n\nexport function normalizeSelectionInput(fields: SelectionFields): string[] {\n return [...new Set([...(fields.assetIds || []), fields.assetId || ''].map(assetId => assetId.trim()).filter(Boolean))];\n}\n", "import { lineageDb, nowIso, type DatabaseSync } from './assetLineageDb';\nimport type {\n LineageWorkspace,\n LineageWorkspaceActor,\n LineageWorkspaceFields,\n LineageWorkspaceSnapshot,\n LineageWorkspaceStatus,\n LineageWorkspaceUpdateFields,\n} from '../shared/types';\n\ntype Row = Record<string, unknown>;\n\nconst actors = new Set<LineageWorkspaceActor>(['human', 'agent', 'system']);\nconst statuses = new Set<LineageWorkspaceStatus>(['active', 'paused', 'archived']);\n\nexport class LineageWorkspaceError extends Error {\n constructor(message: string, public status = 400) {\n super(message);\n }\n}\n\nexport function isLineageWorkspaceError(error: unknown): error is LineageWorkspaceError {\n return error instanceof LineageWorkspaceError;\n}\n\nexport function lineageWorkspaceId(project: string, rootAssetId: string): string {\n return `${project}:lineage-workspace:${rootAssetId}`;\n}\n\nfunction ensureProject(database: DatabaseSync, project: string): void {\n const timestamp = nowIso();\n database.prepare(`\n insert into projects (id, product, created_at, updated_at)\n values (?, ?, ?, ?)\n on conflict(id) do update set product = excluded.product, updated_at = excluded.updated_at\n `).run(project, project, timestamp, timestamp);\n}\n\nfunction normalizeStatus(value: LineageWorkspaceStatus | undefined, fallback: LineageWorkspaceStatus): LineageWorkspaceStatus {\n const status = value || fallback;\n if (!statuses.has(status)) throw new LineageWorkspaceError(`Unsupported lineage workspace status: ${status}`);\n return status;\n}\n\nfunction normalizeActor(value: LineageWorkspaceActor | undefined): LineageWorkspaceActor {\n const actor = value || 'human';\n if (!actors.has(actor)) throw new LineageWorkspaceError(`Unsupported lineage workspace actor: ${actor}`);\n return actor;\n}\n\nfunction requireAsset(database: DatabaseSync, project: string, assetId: string): { id: string; title: string } {\n const row = database.prepare('select id, title from assets where project_id = ? and id = ?').get(project, assetId) as { id: string; title: string } | undefined;\n if (!row) throw new LineageWorkspaceError(`Unknown indexed asset: ${assetId}`, 404);\n return row;\n}\n\nfunction rowToWorkspace(row: Row): LineageWorkspace {\n return {\n id: String(row.id),\n project: String(row.project_id),\n root_asset_id: String(row.root_asset_id),\n title: String(row.title),\n status: String(row.status) as LineageWorkspaceStatus,\n notes: typeof row.notes === 'string' ? row.notes : undefined,\n created_by: String(row.created_by) as LineageWorkspaceActor,\n active_at: typeof row.active_at === 'string' ? row.active_at : undefined,\n created_at: String(row.created_at),\n updated_at: String(row.updated_at),\n };\n}\n\nfunction workspaceById(database: DatabaseSync, project: string, id: string): LineageWorkspace | null {\n const row = database.prepare('select * from lineage_workspaces where project_id = ? and id = ?').get(project, id) as Row | undefined;\n return row ? rowToWorkspace(row) : null;\n}\n\nfunction workspaceByRoot(database: DatabaseSync, project: string, rootAssetId: string): LineageWorkspace | null {\n const row = database.prepare('select * from lineage_workspaces where project_id = ? and root_asset_id = ?').get(project, rootAssetId) as Row | undefined;\n return row ? rowToWorkspace(row) : null;\n}\n\nfunction knownRoots(database: DatabaseSync, project: string): Array<{ root_asset_id: string; selected_at?: string }> {\n const rows = database.prepare(`\n select root_asset_id, max(selected_at) selected_at from asset_selections where project_id = ? group by root_asset_id\n union\n select root_asset_id, null selected_at from asset_layouts where project_id = ? group by root_asset_id\n union\n select parent_asset_id root_asset_id, null selected_at\n from asset_edges\n where project_id = ?\n and parent_asset_id not in (select child_asset_id from asset_edges where project_id = ?)\n group by parent_asset_id\n `).all(project, project, project, project) as Array<{ root_asset_id: string; selected_at?: string | null }>;\n return rows.map(row => ({ root_asset_id: row.root_asset_id, selected_at: row.selected_at || undefined }));\n}\n\nfunction seedLegacyWorkspaces(database: DatabaseSync, project: string): void {\n ensureProject(database, project);\n const timestamp = nowIso();\n const statement = database.prepare(`\n insert into lineage_workspaces (\n id, project_id, root_asset_id, title, status, notes, created_by, active_at, created_at, updated_at\n )\n select ?, ?, a.id, a.title || ' lineage', 'active', null, 'system', ?, ?, ?\n from assets a\n where a.project_id = ? and a.id = ?\n on conflict(project_id, root_asset_id) do nothing\n `);\n for (const root of knownRoots(database, project)) {\n statement.run(\n lineageWorkspaceId(project, root.root_asset_id),\n project,\n root.selected_at || null,\n timestamp,\n timestamp,\n project,\n root.root_asset_id\n );\n }\n}\n\nfunction listRows(database: DatabaseSync, project: string): LineageWorkspace[] {\n return (database.prepare(`\n select * from lineage_workspaces\n where project_id = ?\n order by\n case status when 'active' then 0 when 'paused' then 1 else 2 end,\n active_at desc nulls last,\n updated_at desc,\n title\n `).all(project) as Row[]).map(rowToWorkspace);\n}\n\nfunction activeWorkspace(database: DatabaseSync, project: string): LineageWorkspace | null {\n const row = database.prepare(`\n select * from lineage_workspaces\n where project_id = ? and status != 'archived'\n order by active_at desc nulls last, updated_at desc\n limit 1\n `).get(project) as Row | undefined;\n return row ? rowToWorkspace(row) : null;\n}\n\nexport function listLineageWorkspaces(project: string): LineageWorkspaceSnapshot {\n const database = lineageDb();\n try {\n seedLegacyWorkspaces(database, project);\n return {\n project,\n active_workspace: activeWorkspace(database, project),\n workspaces: listRows(database, project),\n fetchedAt: nowIso(),\n };\n } finally {\n database.close();\n }\n}\n\nexport function inspectLineageWorkspace(project: string, workspaceId: string): LineageWorkspace {\n const database = lineageDb();\n try {\n seedLegacyWorkspaces(database, project);\n const workspace = workspaceById(database, project, workspaceId) || workspaceByRoot(database, project, workspaceId);\n if (!workspace) throw new LineageWorkspaceError(`Unknown lineage workspace: ${workspaceId}`, 404);\n return workspace;\n } finally {\n database.close();\n }\n}\n\nexport function createLineageWorkspace(project: string, fields: LineageWorkspaceFields) {\n const rootAssetId = fields.rootAssetId.trim();\n if (!rootAssetId) throw new LineageWorkspaceError('Lineage workspace requires rootAssetId');\n const status = normalizeStatus(fields.status, 'active');\n const actor = normalizeActor(fields.createdBy);\n const database = lineageDb();\n try {\n const root = requireAsset(database, project, rootAssetId);\n const timestamp = nowIso();\n const workspace: LineageWorkspace = {\n id: lineageWorkspaceId(project, rootAssetId),\n project,\n root_asset_id: rootAssetId,\n title: fields.title?.trim() || `${root.title} lineage`,\n status,\n notes: fields.notes?.trim() || undefined,\n created_by: actor,\n active_at: fields.activate !== false && status !== 'archived' ? timestamp : undefined,\n created_at: timestamp,\n updated_at: timestamp,\n };\n if (!fields.confirmWrite) return { ok: true as const, dryRun: true as const, workspace };\n ensureProject(database, project);\n database.prepare(`\n insert into lineage_workspaces (\n id, project_id, root_asset_id, title, status, notes, created_by, active_at, created_at, updated_at\n ) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n on conflict(project_id, root_asset_id) do update set\n title = excluded.title,\n status = excluded.status,\n notes = excluded.notes,\n active_at = coalesce(excluded.active_at, lineage_workspaces.active_at),\n updated_at = excluded.updated_at\n `).run(\n workspace.id,\n project,\n workspace.root_asset_id,\n workspace.title,\n workspace.status,\n workspace.notes || null,\n workspace.created_by,\n workspace.active_at || null,\n workspace.created_at,\n workspace.updated_at\n );\n return {\n ok: true as const,\n message: `Saved lineage workspace ${workspace.title}`,\n workspace: workspaceById(database, project, workspace.id),\n };\n } finally {\n database.close();\n }\n}\n\nexport function updateLineageWorkspace(project: string, workspaceId: string, fields: LineageWorkspaceUpdateFields) {\n const database = lineageDb();\n try {\n seedLegacyWorkspaces(database, project);\n const current = workspaceById(database, project, workspaceId) || workspaceByRoot(database, project, workspaceId);\n if (!current) throw new LineageWorkspaceError(`Unknown lineage workspace: ${workspaceId}`, 404);\n const timestamp = nowIso();\n const next: LineageWorkspace = {\n ...current,\n title: fields.title?.trim() || current.title,\n status: normalizeStatus(fields.status, current.status),\n notes: fields.notes === undefined ? current.notes : fields.notes.trim() || undefined,\n active_at: fields.activate ? timestamp : current.active_at,\n updated_at: timestamp,\n };\n if (!fields.confirmWrite) return { ok: true as const, dryRun: true as const, workspace: next };\n database.prepare(`\n update lineage_workspaces\n set title = ?, status = ?, notes = ?, active_at = ?, updated_at = ?\n where project_id = ? and id = ?\n `).run(next.title, next.status, next.notes || null, next.active_at || null, timestamp, project, current.id);\n return {\n ok: true as const,\n message: `Updated lineage workspace ${next.title}`,\n workspace: workspaceById(database, project, current.id),\n };\n } finally {\n database.close();\n }\n}\n\nexport function activateLineageWorkspace(project: string, workspaceId: string, confirmWrite: boolean) {\n return updateLineageWorkspace(project, workspaceId, { activate: true, status: 'active', confirmWrite });\n}\n\nexport function archiveLineageWorkspace(project: string, workspaceId: string, confirmWrite: boolean) {\n const database = lineageDb();\n try {\n seedLegacyWorkspaces(database, project);\n const current = workspaceById(database, project, workspaceId) || workspaceByRoot(database, project, workspaceId);\n if (!current) throw new LineageWorkspaceError(`Unknown lineage workspace: ${workspaceId}`, 404);\n const timestamp = nowIso();\n const next: LineageWorkspace = {\n ...current,\n status: 'archived',\n active_at: undefined,\n updated_at: timestamp,\n };\n if (!confirmWrite) return { ok: true as const, dryRun: true as const, workspace: next };\n database.prepare(`\n update lineage_workspaces\n set status = 'archived', active_at = null, updated_at = ?\n where project_id = ? and id = ?\n `).run(timestamp, project, current.id);\n database.prepare('delete from asset_selections where project_id = ? and root_asset_id = ?').run(project, current.root_asset_id);\n return {\n ok: true as const,\n message: `Archived lineage workspace ${current.title}`,\n workspace: workspaceById(database, project, current.id),\n };\n } finally {\n database.close();\n }\n}\n\nexport function activeLineageWorkspaceRoot(project: string): string | undefined {\n const database = lineageDb();\n try {\n seedLegacyWorkspaces(database, project);\n return activeWorkspace(database, project)?.root_asset_id;\n } finally {\n database.close();\n }\n}\n", "import { join } from 'node:path';\nimport { defaultProject, listAssets, repoRoot } from './assetCore';\nimport { lineageDb as db, lineageDbPath, nowIso, type DatabaseSync } from './assetLineageDb';\nimport { LINEAGE_NEXT_VARIATION_LIMIT, normalizeSelectionInput, selectedRows, selectionId } from './assetLineageSelection';\nimport { activeLineageWorkspaceRoot } from './assetLineageWorkspaces';\nimport type {\n AssetReviewState,\n GrowthAsset,\n LineageEdge,\n LineageChildrenResponse,\n LineageIndexSummary,\n LineageLayoutFields,\n LineageLinkFields,\n LineageNode,\n LineageNextResponse,\n LineagePosition,\n LineageSnapshot,\n ReviewFields,\n SelectionFields,\n} from '../shared/types';\n\nexport class LineageError extends Error {\n constructor(message: string, public status = 400) {\n super(message);\n }\n}\n\nexport function isLineageError(error: unknown): error is LineageError {\n return error instanceof LineageError;\n}\n\nfunction collectAssets(project: string, source: 'catalog' | 'local'): GrowthAsset[] {\n const first = listAssets(project, { source, page: 1, pageSize: 100 });\n const assets = [...first.assets];\n for (let page = 2; page <= first.pagination.totalPages; page += 1) {\n assets.push(...listAssets(project, { source, page, pageSize: 100 }).assets);\n }\n return assets;\n}\n\nfunction upsertProject(database: DatabaseSync, project: string): void {\n const timestamp = nowIso();\n database.prepare(`\n insert into projects (id, product, catalog_path, created_at, updated_at)\n values (?, ?, ?, ?, ?)\n on conflict(id) do update set product = excluded.product, updated_at = excluded.updated_at\n `).run(project, project, join(repoRoot, project, 'assets', 'catalog.json'), timestamp, timestamp);\n}\n\nfunction upsertAsset(database: DatabaseSync, project: string, asset: GrowthAsset): void {\n const timestamp = nowIso();\n const source = asset.source === 'local' ? 'local' : 'catalog';\n database.prepare(`\n insert into assets (\n id, project_id, source, local_path, s3_key, checksum_sha256, media_type, title, status,\n channel, campaign, audience, size_bytes, content_type, created_at, updated_at, last_seen_at\n ) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n on conflict(id) do update set\n source = excluded.source, local_path = excluded.local_path, s3_key = excluded.s3_key,\n checksum_sha256 = excluded.checksum_sha256, media_type = excluded.media_type,\n title = excluded.title, status = excluded.status, channel = excluded.channel,\n campaign = excluded.campaign, audience = excluded.audience, size_bytes = excluded.size_bytes,\n content_type = excluded.content_type, updated_at = excluded.updated_at, last_seen_at = excluded.last_seen_at\n `).run(\n asset.asset_id, project, source, asset.local?.relative_path || null, asset.s3?.key || null,\n asset.local?.checksum_sha256 || asset.s3?.checksum_sha256 || null, asset.content_type, asset.title,\n asset.status, asset.channel || null, asset.campaign || null, asset.audience || null,\n asset.local?.size_bytes || asset.s3?.size_bytes || null, asset.local?.content_type || asset.s3?.content_type || null,\n timestamp, timestamp, timestamp\n );\n database.prepare(`\n insert into asset_reviews (asset_id, review_state, updated_at)\n values (?, 'unreviewed', ?)\n on conflict(asset_id) do nothing\n `).run(asset.asset_id, timestamp);\n}\n\nexport function indexLineageAssets(project = defaultProject): LineageIndexSummary {\n const database = db();\n const catalog = collectAssets(project, 'catalog');\n const local = collectAssets(project, 'local');\n upsertProject(database, project);\n for (const asset of [...catalog, ...local]) upsertAsset(database, project, asset);\n database.close();\n return { catalog: catalog.length, local: local.length, total: catalog.length + local.length, database: lineageDbPath() };\n}\n\nfunction requireAsset(database: DatabaseSync, project: string, assetId: string): void {\n const row = database.prepare('select id from assets where project_id = ? and id = ?').get(project, assetId);\n if (!row) throw new LineageError(`Unknown indexed asset: ${assetId}`, 404);\n}\n\nfunction parentOf(database: DatabaseSync, project: string, assetId: string): string | undefined {\n const row = database.prepare('select parent_asset_id from asset_edges where project_id = ? and child_asset_id = ? order by created_at limit 1').get(project, assetId) as { parent_asset_id?: string } | undefined;\n return row?.parent_asset_id;\n}\n\nfunction rootFor(database: DatabaseSync, project: string, assetId: string): string {\n let root = assetId;\n const seen = new Set<string>();\n while (!seen.has(root)) {\n seen.add(root);\n const parent = parentOf(database, project, root);\n if (!parent) return root;\n root = parent;\n }\n return assetId;\n}\n\nfunction latestSelectedRoot(database: DatabaseSync, project: string): string | undefined {\n const row = database.prepare('select root_asset_id from asset_selections where project_id = ? order by selected_at desc limit 1').get(project) as { root_asset_id?: string } | undefined;\n return row?.root_asset_id;\n}\n\nfunction resolveRoot(database: DatabaseSync, project: string, rootAssetId?: string): string {\n if (rootAssetId) {\n requireAsset(database, project, rootAssetId);\n return rootAssetId;\n }\n const root = activeLineageWorkspaceRoot(project) || latestSelectedRoot(database, project);\n if (!root) throw new LineageError('Lineage command requires --root unless a project selection exists');\n requireAsset(database, project, root);\n return root;\n}\n\nfunction edgeId(project: string, parent: string, child: string): string {\n return `${project}:${parent}:derived_from:${child}`;\n}\n\nfunction canPreviewLocally(mediaType: string, localPath?: string): boolean {\n return Boolean(localPath && ['image', 'video', 'gif'].includes(mediaType));\n}\n\nfunction localPreviewUrl(project: string, localPath?: string): string | undefined {\n if (!localPath) return undefined;\n const params = new URLSearchParams({ project, path: localPath });\n return `/api/assets/local-preview?${params.toString()}`;\n}\n\nexport function linkLineageAssets(project: string, fields: LineageLinkFields) {\n const database = db();\n requireAsset(database, project, fields.parentAssetId);\n requireAsset(database, project, fields.childAssetId);\n if (fields.parentAssetId === fields.childAssetId) throw new LineageError('Lineage link cannot point to itself');\n const edge = {\n id: edgeId(project, fields.parentAssetId, fields.childAssetId), parent_asset_id: fields.parentAssetId,\n child_asset_id: fields.childAssetId, relation_type: 'derived_from' as const, created_at: nowIso(),\n };\n if (!fields.confirmWrite) {\n database.close();\n return { ok: true as const, dryRun: true, edge };\n }\n database.prepare(`\n insert into asset_edges (id, project_id, parent_asset_id, child_asset_id, relation_type, created_at)\n values (?, ?, ?, ?, 'derived_from', ?)\n on conflict(project_id, parent_asset_id, child_asset_id, relation_type) do nothing\n `).run(edge.id, project, edge.parent_asset_id, edge.child_asset_id, edge.created_at);\n database.close();\n return { ok: true as const, message: `Linked ${edge.child_asset_id} from ${edge.parent_asset_id}`, edge };\n}\n\nfunction descendants(database: DatabaseSync, project: string, root: string): LineageEdge[] {\n const edges: LineageEdge[] = [];\n const queue = [root];\n const seen = new Set<string>();\n while (queue.length > 0) {\n const parent = queue.shift()!;\n if (seen.has(parent)) continue;\n seen.add(parent);\n const rows = database.prepare('select id, parent_asset_id, child_asset_id, relation_type, created_at from asset_edges where project_id = ? and parent_asset_id = ? order by created_at').all(project, parent) as unknown as LineageEdge[];\n edges.push(...rows);\n queue.push(...rows.map(row => row.child_asset_id));\n }\n return edges;\n}\n\nexport function getLineageSnapshot(project: string, assetId: string): LineageSnapshot {\n const database = db();\n requireAsset(database, project, assetId);\n const root = rootFor(database, project, assetId);\n const edges = descendants(database, project, root);\n const ids = [...new Set([root, ...edges.flatMap(edge => [edge.parent_asset_id, edge.child_asset_id])])];\n const placeholders = ids.map(() => '?').join(',');\n const rows = database.prepare(`\n select a.id asset_id, a.project_id project, a.source, a.title, a.media_type, a.status, a.channel, a.campaign,\n a.local_path, a.s3_key, a.checksum_sha256, coalesce(r.review_state, 'unreviewed') review_state,\n r.notes review_notes, l.x layout_x, l.y layout_y\n from assets a left join asset_reviews r on r.asset_id = a.id\n left join asset_layouts l on l.project_id = a.project_id and l.root_asset_id = ? and l.asset_id = a.id\n where a.project_id = ? and a.id in (${placeholders})\n `).all(root, project, ...ids) as Array<Omit<LineageNode, 'is_latest' | 'position' | 'preview_url' | 'selection_note' | 'user_selected'> & { layout_x?: number; layout_y?: number }>;\n const selected = selectedRows(database, project, root);\n const childIds = new Set(edges.map(edge => edge.parent_asset_id));\n const selectedIds = new Set(selected.map(row => row.asset_id));\n const selections = selected.map(row => ({\n asset_id: row.asset_id, notes: row.notes || undefined,\n position: Number(row.position || 0), selected_at: row.selected_at,\n }));\n const selection = selections[0] || null;\n const nodes = rows.map(row => {\n const position: LineagePosition | undefined = typeof row.layout_x === 'number' && typeof row.layout_y === 'number' ? { x: row.layout_x, y: row.layout_y } : undefined;\n const { layout_x: _layoutX, layout_y: _layoutY, ...node } = row;\n const nodeSelection = selections.find(item => item.asset_id === row.asset_id);\n return {\n ...node,\n is_latest: !childIds.has(row.asset_id),\n position,\n preview_url: canPreviewLocally(row.media_type, row.local_path) ? localPreviewUrl(project, row.local_path) : undefined,\n selection_note: nodeSelection?.notes,\n user_selected: selectedIds.has(row.asset_id),\n };\n });\n database.close();\n return {\n project,\n root_asset_id: root,\n active_asset_id: assetId,\n selected: selections.map(row => row.asset_id),\n selection,\n selections,\n latest: nodes.filter(node => node.is_latest).map(node => node.asset_id),\n nodes,\n edges,\n fetchedAt: nowIso(),\n };\n}\n\nexport function updateLineageLayout(project: string, fields: LineageLayoutFields) {\n if (fields.positions.length === 0) throw new LineageError('Lineage layout requires at least one position');\n const database = db();\n requireAsset(database, project, fields.rootAssetId);\n for (const position of fields.positions) requireAsset(database, project, position.assetId);\n if (!fields.confirmWrite) {\n database.close();\n return { ok: true as const, dryRun: true, root_asset_id: fields.rootAssetId, positions: fields.positions };\n }\n const timestamp = nowIso();\n const statement = database.prepare(`\n insert into asset_layouts (id, project_id, root_asset_id, asset_id, x, y, updated_at)\n values (?, ?, ?, ?, ?, ?, ?)\n on conflict(project_id, root_asset_id, asset_id) do update set\n x = excluded.x, y = excluded.y, updated_at = excluded.updated_at\n `);\n for (const position of fields.positions) {\n statement.run(`${project}:${fields.rootAssetId}:layout:${position.assetId}`, project, fields.rootAssetId, position.assetId, position.x, position.y, timestamp);\n }\n database.close();\n return { ok: true as const, message: `Saved ${fields.positions.length} lineage positions`, root_asset_id: fields.rootAssetId, positions: fields.positions };\n}\n\nexport function getLineageNextAsset(project: string, rootAssetId?: string): LineageNextResponse {\n const database = db();\n const root = resolveRoot(database, project, rootAssetId);\n database.close();\n const snapshot = getLineageSnapshot(project, root);\n const selectedNodes = snapshot.selected\n .map(assetId => snapshot.nodes.find(node => node.asset_id === assetId))\n .filter((node): node is LineageNode => Boolean(node));\n const latestNodes = snapshot.nodes.filter(node => snapshot.latest.includes(node.asset_id));\n const warnings: string[] = [];\n for (const selectedNode of selectedNodes) {\n if (selectedNode.is_latest) continue;\n warnings.push('Selected asset is not a latest leaf; agents should treat this as an intentional branch choice.');\n }\n if (selectedNodes.length > 0) {\n return {\n project,\n root_asset_id: snapshot.root_asset_id,\n strategy: 'selected',\n selection_mode: selectedNodes.length > 1 ? 'multiple' : 'single',\n recommended_action: 'evolve_variations',\n reason: 'user_selected',\n next_asset: selectedNodes[0],\n next_assets: selectedNodes,\n latest: snapshot.latest,\n selected: snapshot.selected,\n selection: snapshot.selection,\n selections: snapshot.selections,\n candidates: latestNodes,\n warnings,\n fetchedAt: nowIso(),\n };\n }\n if (latestNodes.length === 1) {\n return {\n project,\n root_asset_id: snapshot.root_asset_id,\n strategy: 'single_latest',\n selection_mode: 'fallback',\n recommended_action: 'evolve_variations',\n reason: 'single_latest_fallback',\n next_asset: latestNodes[0],\n next_assets: [latestNodes[0]],\n latest: snapshot.latest,\n selected: snapshot.selected,\n selection: snapshot.selection,\n selections: snapshot.selections,\n candidates: latestNodes,\n warnings,\n fetchedAt: nowIso(),\n };\n }\n return {\n project,\n root_asset_id: snapshot.root_asset_id,\n strategy: latestNodes.length > 1 ? 'ambiguous_latest' : 'empty',\n selection_mode: 'none',\n recommended_action: latestNodes.length > 1 ? 'choose_next_base' : 'none',\n reason: latestNodes.length > 1 ? 'multiple_latest_no_selection' : 'no_lineage_candidates',\n next_asset: null,\n next_assets: [],\n latest: snapshot.latest,\n selected: snapshot.selected,\n selection: snapshot.selection,\n selections: snapshot.selections,\n candidates: latestNodes,\n warnings,\n fetchedAt: nowIso(),\n };\n}\n\nexport function getLineageChildren(project: string, parentAssetId: string): LineageChildrenResponse {\n const snapshot = getLineageSnapshot(project, parentAssetId);\n const edges = snapshot.edges.filter(edge => edge.parent_asset_id === parentAssetId);\n const childIds = new Set(edges.map(edge => edge.child_asset_id));\n return {\n project, parent_asset_id: parentAssetId,\n children: snapshot.nodes.filter(node => childIds.has(node.asset_id)),\n edges, fetchedAt: nowIso(),\n };\n}\n\nexport function updateSelectedAsset(project: string, fields: SelectionFields) {\n const database = db();\n const inputAssetIds = normalizeSelectionInput(fields);\n const root = fields.rootAssetId || (inputAssetIds[0] ? rootFor(database, project, inputAssetIds[0]) : '');\n if (!root) throw new LineageError('Selection requires rootAssetId or assetId');\n requireAsset(database, project, root);\n for (const assetId of inputAssetIds) requireAsset(database, project, assetId);\n const mode = fields.mode || 'replace';\n const limit = fields.maxSelections || LINEAGE_NEXT_VARIATION_LIMIT;\n if (!fields.confirmWrite) {\n database.close();\n return { ok: true as const, dryRun: true, root_asset_id: root, asset_ids: inputAssetIds, mode, clear: Boolean(fields.clear), max_selections: limit };\n }\n const current = selectedRows(database, project, root);\n let nextIds = current.map(row => row.asset_id);\n if (fields.clear) {\n nextIds = [];\n } else if (mode === 'replace') {\n nextIds = inputAssetIds;\n } else if (mode === 'add') {\n nextIds = [...nextIds, ...inputAssetIds];\n } else if (mode === 'remove') {\n nextIds = nextIds.filter(assetId => !inputAssetIds.includes(assetId));\n } else if (mode === 'toggle') {\n for (const assetId of inputAssetIds) {\n nextIds = nextIds.includes(assetId) ? nextIds.filter(id => id !== assetId) : [...nextIds, assetId];\n }\n }\n nextIds = [...new Set(nextIds)];\n if (!fields.clear && inputAssetIds.length === 0) throw new LineageError('Selection set requires assetId or assetIds');\n if (nextIds.length > limit) throw new LineageError(`Select at most ${limit} assets for next variation`);\n database.prepare('delete from asset_selections where project_id = ? and root_asset_id = ?').run(project, root);\n const timestamp = nowIso();\n const insert = database.prepare(`\n insert into asset_selections (id, project_id, root_asset_id, asset_id, position, notes, selected_at)\n values (?, ?, ?, ?, ?, ?, ?)\n `);\n nextIds.forEach((assetId, position) => {\n const existing = current.find(row => row.asset_id === assetId);\n const notes = inputAssetIds.includes(assetId) ? fields.notes || existing?.notes : existing?.notes;\n insert.run(selectionId(project, root, assetId), project, root, assetId, position, notes || null, timestamp);\n });\n database.close();\n const message = nextIds.length === 0 ? `Cleared selected assets for ${root}` : `Selected ${nextIds.length} asset${nextIds.length === 1 ? '' : 's'} for ${root}`;\n return { ok: true as const, message, root_asset_id: root, asset_id: nextIds[0] || null, asset_ids: nextIds, mode };\n}\n\nexport function updateAssetReview(project: string, fields: ReviewFields) {\n const allowed = new Set<AssetReviewState>(['unreviewed', 'approved', 'needs_revision', 'rejected', 'ignored']);\n if (!allowed.has(fields.reviewState)) throw new LineageError(`Unsupported review state: ${fields.reviewState}`);\n const database = db();\n requireAsset(database, project, fields.assetId);\n if (!fields.confirmWrite) {\n database.close();\n return { ok: true as const, dryRun: true, asset_id: fields.assetId, review_state: fields.reviewState, notes: fields.notes };\n }\n const timestamp = nowIso();\n database.prepare(`\n insert into asset_reviews (asset_id, review_state, reviewed_at, ignored_at, notes, updated_at)\n values (?, ?, ?, ?, ?, ?)\n on conflict(asset_id) do update set\n review_state = excluded.review_state, reviewed_at = excluded.reviewed_at,\n ignored_at = excluded.ignored_at, notes = excluded.notes, updated_at = excluded.updated_at\n `).run(fields.assetId, fields.reviewState, timestamp, fields.reviewState === 'ignored' ? timestamp : null, fields.notes || null, timestamp);\n database.close();\n return { ok: true as const, message: `Marked ${fields.assetId} ${fields.reviewState}`, asset_id: fields.assetId, review_state: fields.reviewState };\n}\n", "import type { LineageBriefResponse, LineageSelectedChildFields } from '../shared/types';\nimport { getLineageNextAsset, LineageError, linkLineageAssets } from './assetLineage';\nimport { lineageDbPath, nowIso } from './assetLineageDb';\n\nconst publicPackageCommand = 'npx @mean-weasel/lineage';\n\nfunction shellQuote(value: string): string {\n return `'${value.replace(/'/g, \"'\\\\''\")}'`;\n}\n\nfunction lineageCommand(command: string, project: string, rootAssetId: string): string {\n return `${publicPackageCommand} ${command} --project ${shellQuote(project)} --root ${shellQuote(rootAssetId)} --db ${shellQuote(lineageDbPath())} --json`;\n}\n\nfunction linkChildCommand(project: string, rootAssetId: string): string {\n return `${publicPackageCommand} link-child --project ${shellQuote(project)} --root ${shellQuote(rootAssetId)} --child <asset-id> --confirm-write --db ${shellQuote(lineageDbPath())} --json`;\n}\n\nexport function getLineageBrief(project: string, rootAssetId?: string): LineageBriefResponse {\n const next = getLineageNextAsset(project, rootAssetId);\n const assets = next.next_assets;\n const asset = next.next_asset;\n const referenceAssetIds = assets.map(item => item.asset_id);\n const rationale = next.selections.map(selection => selection.notes).find(Boolean) || asset?.selection_note || next.selection?.notes;\n const channels = [...new Set(assets.map(item => item.channel || 'unknown'))];\n const campaigns = [...new Set(assets.map(item => item.campaign || 'unknown'))];\n const prompt = assets.length > 0\n ? [\n assets.length === 1\n ? `Create 3-4 variations from asset ${assets[0].asset_id} (${assets[0].title}).`\n : `Create 3-4 variations using these ${assets.length} selected references: ${referenceAssetIds.join(', ')}.`,\n rationale ? `Preserve this selection rationale: ${rationale}` : 'Preserve the strongest visible ideas while exploring distinct alternatives.',\n `Keep project=${project}, root=${next.root_asset_id}, channels=${channels.join(',')}, campaigns=${campaigns.join(',')}.`,\n 'After generation, index outputs and link chosen children with lineage link-child.',\n ].join(' ')\n : 'Select one to three latest lineage candidates before generating variations.';\n return {\n project,\n root_asset_id: next.root_asset_id,\n strategy: next.strategy,\n selection_mode: next.selection_mode,\n recommended_action: next.recommended_action,\n reason: next.reason,\n next_asset: asset,\n next_assets: assets,\n selection: next.selection,\n selections: next.selections,\n latest: next.latest,\n warnings: next.warnings,\n brief: {\n title: asset ? `Evolve ${assets.length > 1 ? `${assets.length} selected bases` : asset.title}` : 'Choose next lineage base',\n objective: asset ? 'Generate the next branch of visual variations from the selected lineage base or bases.' : 'Resolve the next base before generation.',\n prompt,\n reference_asset_id: asset?.asset_id,\n reference_asset_ids: referenceAssetIds,\n rationale,\n },\n handoff: {\n next_command: lineageCommand('next', project, next.root_asset_id),\n inspect_command: asset ? `${publicPackageCommand} inspect --project ${shellQuote(project)} --asset-id ${shellQuote(asset.asset_id)} --db ${shellQuote(lineageDbPath())} --json` : undefined,\n link_child_command: asset ? linkChildCommand(project, next.root_asset_id) : undefined,\n },\n fetchedAt: nowIso(),\n };\n}\n\nexport function linkSelectedLineageChild(project: string, fields: LineageSelectedChildFields) {\n const next = getLineageNextAsset(project, fields.rootAssetId);\n if (!next.next_asset) throw new LineageError('Cannot link child until a next base is selected or unambiguous');\n const result = linkLineageAssets(project, {\n childAssetId: fields.childAssetId,\n confirmWrite: fields.confirmWrite,\n parentAssetId: next.next_asset.asset_id,\n });\n return {\n ...result,\n root_asset_id: next.root_asset_id,\n parent_asset_id: next.next_asset.asset_id,\n child_asset_id: fields.childAssetId,\n reference_asset_ids: next.next_assets.map(asset => asset.asset_id),\n warning: next.next_assets.length > 1\n ? 'Linked child to the primary selected base; add explicit edges to other selected references if the child derives from them too.'\n : undefined,\n };\n}\n", "#!/usr/bin/env node\n\nimport { runLineageCli } from './lineageCli';\n\nrunLineageCli({ binName: 'lineage', channel: 'stable', defaultHost: 'lineage.localhost', defaultPort: 5197, displayName: 'Lineage' });\n"],
5
+ "mappings": ";;;AAAA,SAAS,cAAAA,aAAY,aAAAC,YAAW,gBAAAC,qBAAoB;AACpD,SAAS,SAAS,gBAAgB;AAClC,SAAS,WAAAC,UAAS,QAAAC,OAAM,WAAAC,gBAAe;AACvC,SAAS,aAAa;AACtB,SAAS,iBAAAC,sBAAqB;;;ACJ9B,SAAS,cAAAC,aAAY,aAAAC,YAAW,eAAAC,cAAa,gBAAAC,eAAc,YAAY,qBAAqB;AAC5F,SAAS,WAAAC,UAAS,QAAAC,OAAM,WAAAC,gBAAe;AACvC,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;;;ACH9B,SAAS,cAAc,cAAAC,aAAY,WAAW,YAAAC,iBAAgB;AAC9D,SAAS,YAAAC,WAAU,SAAS,QAAAC,aAAY;;;ACDxC,SAAS,kBAAkB;AAC3B,SAAS,YAAY,aAAa,cAAc,gBAAgB;AAChE,SAAS,UAAU,SAAS,MAAM,UAAU,eAAe;AAG3D,IAAM,YAAoC;AAAA,EACxC,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AACX;AACA,IAAM,kBAAkB,IAAI,IAAI,OAAO,KAAK,SAAS,CAAC;AAY/C,SAAS,eAAe,MAAsB;AACnD,SAAO,UAAU,QAAQ,IAAI,EAAE,YAAY,CAAC,KAAK;AACnD;AAEO,SAAS,WAAW,MAAsB;AAC/C,SAAO,WAAW,QAAQ,EAAE,OAAO,aAAa,IAAI,CAAC,EAAE,OAAO,KAAK;AACrE;;;AD3BO,SAAS,sBAAsB,KAAiC;AACrE,QAAM,SAAS;AACf,QAAM,QAAQ,IAAI,QAAQ,MAAM;AAChC,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Q,eAAe,MAAM,CAAC,CAAC;AACrC;AAAA,EACF;AAEA,MAAI,YAAY,UAAU,YAAY,WAAW,YAAY,aAAa,YAAY,cAAc;AAClG,UAAM,cAAc,eAAe,MAAM,CAAC;AAC1C,UAAMM,QAAO,YAAY,SAAS,QAAQ;AAC1C,QAAI;AACF,sBAAgB,SAAS,sBAAsB,SAAS,WAAW,GAAGA,KAAI;AAAA,IAC5E,SAAS,OAAO;AACd,YAAMC,WAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,UAAID,MAAM,SAAQ,MAAM,KAAK,UAAU,EAAE,IAAI,OAAO,SAAS,OAAOC,SAAQ,GAAG,MAAM,CAAC,CAAC;AAAA,UAClF,SAAQ,MAAM,GAAG,OAAO,OAAO,KAAKA,QAAO,EAAE;AAClD,cAAQ,KAAK,CAAC;AAAA,IAChB;AACA,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,QAAM,OAAO,KAAK,SAAS,QAAQ;AACnC,QAAM,UAAU,oBAAoB,OAAO;AAC3C,MAAI,KAAM,SAAQ,MAAM,KAAK,UAAU,EAAE,IAAI,OAAO,SAAS,OAAO,QAAQ,GAAG,MAAM,CAAC,CAAC;AAAA,MAClF,SAAQ,MAAM,GAAG,OAAO,OAAO,KAAK,OAAO,EAAE;AAClD,UAAQ,KAAK,CAAC;AAChB;;;ASjRA,cAAc,EAAE,SAAS,WAAW,SAAS,UAAU,aAAa,qBAAqB,aAAa,MAAM,aAAa,UAAU,CAAC;",
6
6
  "names": ["existsSync", "mkdirSync", "readFileSync", "dirname", "join", "resolve", "fileURLToPath", "existsSync", "mkdirSync", "readdirSync", "readFileSync", "dirname", "join", "resolve", "existsSync", "statSync", "basename", "join", "existsSync", "join", "basename", "statSync", "mkdirSync", "join", "require", "join", "mkdirSync", "join", "existsSync", "readFileSync", "dirname", "resolve", "join", "existsSync", "readFileSync", "mkdirSync", "dirname", "resolve", "dirname", "fileURLToPath", "readFileSync", "join", "existsSync", "mkdirSync", "json", "message"]
7
7
  }