Git for the intent behind agent-written code. Records what your coding agent decided and why, and links every commit to it.
JavaScript ai-codingclaudeclaude-codeclaude-code-pluginclicoding-agentsdeveloper-toolsgitllmtypescript
feat(cli): add config prune for missing projects
Eren51ad7d2cff4e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bf65329..cccd2ac 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]### Added+- `codelineage config prune [--dry-run]`: removes registry entries whose project directory no longer exists, lists every removed entry and leaves the registry untouched with `--dry-run` (a corrupt registry is refused, never treated as empty).- Global panel: `codelineage build` also refreshes `~/.config/codelineage/panel.html` (honouring `CODELINEAGE_HOME` / `XDG_CONFIG_HOME`) with one card per registered project — last activity, pending `needsUser` count, a `file://` link to its map, a "missing" mark when the directory is gone and read-only settings from `config.json`; `codelineage open` without a directory builds and opens it.## [0.3.0] - 2026-10-21diff --git a/packages/cli/src/commands/config.ts b/packages/cli/src/commands/config.tsindex 7f93028..c17e3ff 100644--- a/packages/cli/src/commands/config.ts+++ b/packages/cli/src/commands/config.ts@@ -1,6 +1,7 @@import { CliError, type Io } from "../io.js";-import { Config } from "../schema/config.js";-import { loadConfig, updateConfig } from "../store/stores.js";+import { Config, type RegistryEntry } from "../schema/config.js";+import { isDirectory } from "../store/fs.js";+import { loadConfig, loadRegistry, updateConfig, updateRegistry } from "../store/stores.js";export const CONFIG_KEYS = Object.keys(Config.shape).filter((k) => k !== "schema") as Exclude<keyof Config,@@ -48,3 +49,36 @@ export async function configSet(key: string, raw: string, io: Io): Promise<void>await updateConfig((c) => ({ ...c, [key]: next.data[key] }), io.env);io.out(`${key} = ${JSON.stringify(next.data[key])}`);}++export interface PruneOptions {+ /** Lists the entries but leaves `projects.json` untouched. */+ dryRun?: boolean;+}++/**+ * Drops registry entries whose directory is gone. A corrupt registry is an error+ * rather than an empty list, so a typo never wipes every project.+ */+export async function configPrune(opts: PruneOptions, io: Io): Promise<void> {+ const loaded = await loadRegistry(io.env);+ if (loaded.found && !loaded.ok) throw new CliError(`registry: ${loaded.error}`);+ const entries = loaded.found && loaded.ok ? loaded.data.projects : [];++ const missing: RegistryEntry[] = [];+ for (const entry of entries) {+ if (!(await isDirectory(entry.path))) missing.push(entry);+ }++ if (missing.length === 0) {+ io.out("No missing projects");+ return;+ }+ for (const entry of missing) {+ io.out(`${opts.dryRun === true ? "Would remove" : "Removed"} ${entry.name} (${entry.path})`);+ }+ if (opts.dryRun === true) return;+ await updateRegistry(+ (r) => ({ ...r, projects: r.projects.filter((p) => !missing.some((m) => m.path === p.path)) }),+ io.env,+ );+}diff --git a/packages/cli/src/program.ts b/packages/cli/src/program.tsindex c386212..441b0f6 100644--- a/packages/cli/src/program.ts+++ b/packages/cli/src/program.ts@@ -1,7 +1,7 @@import { Command, InvalidArgumentError, Option } from "commander";import pkg from "../package.json" with { type: "json" };import { buildProject } from "./commands/build.js";-import { configGet, configSet } from "./commands/config.js";+import { configGet, configPrune, configSet } from "./commands/config.js";import { epochAdd } from "./commands/epoch.js";import { type InitOptions, init } from "./commands/init.js";import { openPanel, openProject } from "./commands/open.js";@@ -94,6 +94,15 @@ export function createProgram(makeIo: IoFactory = processIo, deps: ProgramDeps =.argument("<key>").argument("<value>").action(run(async (key: string, value: string) => configSet(key, value, makeIo(false))));+ config+ .command("prune")+ .description("remove registered projects whose directory no longer exists")+ .option("--dry-run", "list what would be removed without changing the registry")+ .action(+ run(async (opts: { dryRun?: boolean }) =>+ configPrune({ dryRun: opts.dryRun === true }, makeIo(false)),+ ),+ );const epoch = program.command("epoch").description("manage epochs (features, epics)");epochdiff --git a/packages/cli/src/store/fs.ts b/packages/cli/src/store/fs.tsindex 809dd39..99987c9 100644--- a/packages/cli/src/store/fs.ts+++ b/packages/cli/src/store/fs.ts@@ -1,7 +1,16 @@import { randomBytes } from "node:crypto";-import { mkdir, open, readFile, rename, rm } from "node:fs/promises";+import { mkdir, open, readFile, rename, rm, stat } from "node:fs/promises";import { basename, dirname, join } from "node:path";+/** True only for an existing directory; any error (missing, file, permissions) is false. */+export async function isDirectory(path: string): Promise<boolean> {+ try {+ return (await stat(path)).isDirectory();+ } catch {+ return false;+ }+}+/** Writes via a temp file in the same directory and renames it into place. */export async function atomicWrite(file: string, data: string): Promise<void> {const dir = dirname(file);diff --git a/packages/cli/src/view/panel.ts b/packages/cli/src/view/panel.tsindex fdffa8a..b6c6d77 100644--- a/packages/cli/src/view/panel.ts+++ b/packages/cli/src/view/panel.ts@@ -1,9 +1,8 @@-import { stat } from "node:fs/promises";import { pathToFileURL } from "node:url";import type { Io } from "../io.js";import { redactDeep } from "../redact.js";import type { RegistryEntry } from "../schema/config.js";-import { atomicWrite } from "../store/fs.js";+import { atomicWrite, isDirectory } from "../store/fs.js";import { globalPaths, projectPaths } from "../store/paths.js";import { loadAllSessions, loadConfig, loadRegistry } from "../store/stores.js";import { embedViewModel, statusCard } from "./lineage.js";@@ -19,14 +18,6 @@ export interface PanelOptions {const PANEL_TITLE = "<title>codelineage — panel</title>";-async function isDirectory(path: string): Promise<boolean> {- try {- return (await stat(path)).isDirectory();- } catch {- return false;- }-}-/*** One card per registry entry. A directory that is gone is marked missing* instead of failing the panel; one unreadable project is a warning.diff --git a/packages/cli/test/config-epoch.test.ts b/packages/cli/test/config-epoch.test.tsindex 903c2e0..d053b39 100644--- a/packages/cli/test/config-epoch.test.ts+++ b/packages/cli/test/config-epoch.test.ts@@ -1,12 +1,13 @@import { mkdir, writeFile } from "node:fs/promises";import { join } from "node:path";import { beforeEach, describe, expect, it } from "vitest";-import { configGet, configSet } from "../src/commands/config.js";+import { configGet, configPrune, configSet } from "../src/commands/config.js";import { epochAdd } from "../src/commands/epoch.js";import { init } from "../src/commands/init.js";import { CliError } from "../src/io.js";-import { loadConfig, loadProject } from "../src/store/stores.js";-import { envFor, fakeIo, tempDir } from "./helpers.js";+import { globalPaths } from "../src/store/paths.js";+import { loadConfig, loadProject, loadRegistry, updateRegistry } from "../src/store/stores.js";+import { envFor, fakeIo, T0, tempDir } from "./helpers.js";let dir: string;let env: NodeJS.ProcessEnv;@@ -48,6 +49,69 @@ describe("config", () => {});});+describe("config prune", () => {+ let alive: string;+ let gone: string;++ async function registerBoth(): Promise<void> {+ await updateRegistry(+ (r) => ({+ ...r,+ projects: [+ { path: alive, name: "alive", addedAt: T0 },+ { path: gone, name: "gone", addedAt: T0 },+ ],+ }),+ env,+ );+ }++ beforeEach(async () => {+ alive = join(dir, "alive");+ gone = join(dir, "gone");+ await mkdir(alive);+ await registerBoth();+ });++ it("removes entries whose directory is gone and keeps the rest", async () => {+ const io = fakeIo(env);+ await configPrune({}, io);+ expect(io.lines).toEqual([`Removed gone (${gone})`]);+ expect(await loadRegistry(env)).toMatchObject({+ ok: true,+ data: { projects: [{ path: alive, name: "alive" }] },+ });+ });++ it("--dry-run lists the entries without touching the registry", async () => {+ const io = fakeIo(env);+ await configPrune({ dryRun: true }, io);+ expect(io.lines).toEqual([`Would remove gone (${gone})`]);+ expect(await loadRegistry(env)).toMatchObject({+ ok: true,+ data: { projects: [{ path: alive }, { path: gone }] },+ });+ });++ it("prints a friendly line when nothing is missing or no registry exists", async () => {+ const io = fakeIo(env);+ await configPrune({}, io);+ await configPrune({}, io);+ expect(io.lines).toEqual([`Removed gone (${gone})`, "No missing projects"]);++ const fresh = fakeIo(envFor(await tempDir()));+ await configPrune({ dryRun: true }, fresh);+ expect(fresh.lines).toEqual(["No missing projects"]);+ });++ it("refuses to prune a corrupt registry", async () => {+ await mkdir(globalPaths(env).base, { recursive: true });+ await writeFile(globalPaths(env).registry, "{not json");+ await expect(configPrune({}, fakeIo(env))).rejects.toBeInstanceOf(CliError);+ await expect(configPrune({}, fakeIo(env))).rejects.toThrow(/registry: invalid JSON/);+ });+});+describe("epoch add", () => {let root: string;beforeEach(async () => {diff --git a/packages/cli/test/program-commands.test.ts b/packages/cli/test/program-commands.test.tsindex e719e33..946d46f 100644--- a/packages/cli/test/program-commands.test.ts+++ b/packages/cli/test/program-commands.test.ts@@ -1,5 +1,5 @@import { existsSync } from "node:fs";-import { mkdir, writeFile } from "node:fs/promises";+import { mkdir, rm, writeFile } from "node:fs/promises";import { join } from "node:path";import { beforeEach, describe, expect, it } from "vitest";import { createProgram } from "../src/program.js";@@ -99,6 +99,19 @@ describe("commands through the CLI", () => {expect(io.lines.at(-1)).toMatch(/^Opened .*panel\.html$/);});+ it("prunes projects whose directory is gone, honouring --dry-run", async () => {+ await cli("init", root, "--yes", "--retention", "keep");+ const gone = join(dir, "gone");+ await mkdir(gone);+ await cli("init", gone, "--yes", "--retention", "keep");+ await rm(gone, { recursive: true });++ await cli("config", "prune", "--dry-run");+ expect(io.lines.at(-1)).toMatch(new RegExp(`^Would remove .+ \\(${gone}\\)$`));+ await cli("config", "prune");+ expect(io.lines.at(-1)).toMatch(new RegExp(`^Removed .+ \\(${gone}\\)$`));+ });+it("prints user errors as one line", async () => {expect(await cli("config", "get", "nope")).toMatch(/^error: unknown key "nope"/);});