Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,22 @@ export function createProgram(): Command {
await mod.handleDaemonLogs(opts);
});

// === Migration Commands (v3) ===

const migrate = program
.command("migrate")
.description("Migrate ARC data between versions");

migrate
.command("v2-to-v3")
.description("Ingest v2 state (history.json, chat sessions, activity log) into the v3 SQLite store")
.option("--dry-run", "Count without writing")
.option("--json", "Machine-readable output")
.action(async (opts: { dryRun?: boolean; json?: boolean }) => {
const mod = await import("./commands/migrate.js");
await mod.handleMigrate(opts);
});

// === Session Commands ===

program
Expand Down
67 changes: 67 additions & 0 deletions packages/cli/src/commands/migrate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* arc migrate v2-to-v3 — offline ingest of v2 state into the v3 SQLite store.
*
* Runs against the database file directly — does NOT require the daemon to be
* running. Idempotent: a second invocation reports "already migrated".
*/

import pc from "picocolors";
import { loadDaemonConfig, migrateV2ToV3, type MigrationReport } from "@axiom-labs/arc-daemon";
import { info, error, success } from "../display.js";

export interface MigrateOptions {
dryRun?: boolean;
json?: boolean;
}

export async function handleMigrate(opts: MigrateOptions): Promise<void> {
const cfg = loadDaemonConfig();
let report: MigrationReport;
try {
report = await migrateV2ToV3({
arcDir: cfg.arcDir,
dbPath: cfg.dbPath,
dryRun: opts.dryRun ?? false,
});
} catch (err) {
const msg = (err as Error).message;
if (opts.json) {
process.stdout.write(
JSON.stringify({ ok: false, error: msg }, null, 2) + "\n",
);
} else {
error(`migration failed: ${msg}`);
}
process.exit(1);
}

if (opts.json) {
process.stdout.write(JSON.stringify({ ok: true, ...report }, null, 2) + "\n");
return;
}

if (report.alreadyMigrated) {
info("already migrated, nothing to do");
return;
}

const prefix = report.dryRun ? pc.cyan("[dry-run]") : pc.green("[migrate]");
process.stdout.write(`${prefix} arcDir: ${cfg.arcDir}\n`);
process.stdout.write(`${prefix} dbPath: ${cfg.dbPath}\n`);
process.stdout.write(`${prefix} profiles: ${report.profiles}\n`);
process.stdout.write(`${prefix} agents: ${report.agents}\n`);
process.stdout.write(`${prefix} events: ${report.events}\n`);
process.stdout.write(`${prefix} chat msgs: ${report.chatMessages}\n`);
process.stdout.write(`${prefix} skipped: ${report.skipped}\n`);
if (report.errors.length > 0) {
process.stdout.write(pc.yellow(`${prefix} errors: ${report.errors.length}\n`));
for (const e of report.errors) {
process.stdout.write(pc.yellow(` - ${e}\n`));
}
}
if (report.dryRun) {
info("dry-run complete — no changes written");
} else {
success(`migration complete — v2 files preserved`);
}
}
1 change: 1 addition & 0 deletions packages/daemon/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { startDaemon, readPid, type DaemonHandle, type DaemonOptions } from "./b
export { loadConfig as loadDaemonConfig, DEFAULT_PORT, PROTOCOL_VERSION, type DaemonConfig } from "./config.js";
export { ensureAuthFile, pairClient, type AuthFile, type PairResult } from "./auth.js";
export { buildHealth, type DaemonHealth } from "./health.js";
export { migrateV2ToV3, type MigrationOptions, type MigrationReport } from "./migrations/v2-to-v3.js";
Loading
Loading