{"version":3,"file":"status.mjs","names":[],"sources":["../src/status.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\"\nimport { join } from \"node:path\"\nimport { createRepoSlug, getRepoIdentity, getRepoRoot } from \"../../core/src/index.js\"\nimport { parseCliFlags } from \"./config.js\"\nimport { isDirectExecution } from \"./entrypoint.js\"\nimport {\n\tgetLatestRunPointerPath,\n\tgetRepoArtifactsDir,\n\tgetRepoLatestRunPointerPath,\n\tgetTownHomeDir,\n} from \"./paths.js\"\n\ninterface LatestRunPointer {\n\trepoSlug: string\n\trepoRoot: string\n\trunId?: string\n\trunDir?: string\n\tlatestDir: string\n\tmanifestPath: string\n\tmetricsPath: string\n\tsummaryPath: string\n\tupdatedAt?: string\n}\n\nfunction readJson<T>(path: string): T {\n\treturn JSON.parse(readFileSync(path, \"utf-8\")) as T\n}\n\nfunction createFallbackPointer(repoRoot: string, repoSlug: string): LatestRunPointer {\n\tconst latestDir = join(getRepoArtifactsDir(repoSlug), \"latest\")\n\treturn {\n\t\trepoSlug,\n\t\trepoRoot,\n\t\tlatestDir,\n\t\tmanifestPath: join(latestDir, \"manifest.json\"),\n\t\tmetricsPath: join(latestDir, \"metrics.json\"),\n\t\tsummaryPath: join(latestDir, \"run-summary.json\"),\n\t}\n}\n\nexport function resolveLatestRunPointer(argv = process.argv.slice(2)): LatestRunPointer | null {\n\tconst flags = parseCliFlags(argv)\n\n\tif (flags.repo) {\n\t\tconst repoRoot = getRepoRoot(flags.repo)\n\t\tconst repoSlug = createRepoSlug(getRepoIdentity(repoRoot), repoRoot)\n\t\tconst repoPointerPath = getRepoLatestRunPointerPath(repoSlug)\n\t\tif (existsSync(repoPointerPath)) return readJson<LatestRunPointer>(repoPointerPath)\n\t\treturn createFallbackPointer(repoRoot, repoSlug)\n\t}\n\n\tconst latestPointerPath = getLatestRunPointerPath()\n\tif (!existsSync(latestPointerPath)) return null\n\treturn readJson<LatestRunPointer>(latestPointerPath)\n}\n\nexport function showTownStatus(argv = process.argv.slice(2)) {\n\tconst latest = resolveLatestRunPointer(argv)\n\tconsole.log(\"[pitown] status\")\n\tconsole.log(`- town home: ${getTownHomeDir()}`)\n\n\tif (latest === null) {\n\t\tconsole.log(\"- no local runs found yet\")\n\t\tconsole.log(`- expected pointer: ${getLatestRunPointerPath()}`)\n\t\treturn\n\t}\n\n\tif (existsSync(latest.summaryPath)) {\n\t\tconst summary = readJson<{\n\t\t\trunId?: string\n\t\t\tmode?: string\n\t\t\tmessage?: string\n\t\t\tpiExitCode?: number\n\t\t}>(latest.summaryPath)\n\t\tif (summary.runId) console.log(`- latest run: ${summary.runId}`)\n\t\tif (summary.mode) console.log(`- mode: ${summary.mode}`)\n\t\tif (summary.piExitCode !== undefined) console.log(`- pi exit code: ${summary.piExitCode}`)\n\t\tif (summary.message) console.log(`- note: ${summary.message}`)\n\t}\n\n\tif (existsSync(latest.manifestPath)) {\n\t\tconst manifest = readJson<{\n\t\t\trepoRoot?: string\n\t\t\tbranch?: string\n\t\t\tgoal?: string | null\n\t\t\tplanPath?: string | null\n\t\t\trecommendedPlanDir?: string | null\n\t\t\tstopReason?: string | null\n\t\t}>(latest.manifestPath)\n\t\tif (manifest.repoRoot) console.log(`- repo root: ${manifest.repoRoot}`)\n\t\tif (manifest.branch) console.log(`- branch: ${manifest.branch}`)\n\t\tif (manifest.goal) console.log(`- goal: ${manifest.goal}`)\n\t\tif (manifest.planPath) console.log(`- plan path: ${manifest.planPath}`)\n\t\tif (!manifest.planPath && manifest.recommendedPlanDir) {\n\t\t\tconsole.log(`- recommended plans: ${manifest.recommendedPlanDir}`)\n\t\t}\n\t\tif (manifest.stopReason) console.log(`- stop reason: ${manifest.stopReason}`)\n\t}\n\n\tif (!existsSync(latest.metricsPath)) {\n\t\tconsole.log(\"- no metrics snapshot found yet\")\n\t\tconsole.log(`- expected path: ${latest.metricsPath}`)\n\t\treturn\n\t}\n\n\tconsole.log(`- metrics file: ${latest.metricsPath}`)\n\tconsole.log(readFileSync(latest.metricsPath, \"ut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