feat(cli): ao migrate — offline legacy→rewrite SQLite migration (#2129)#2144
Closed
harshitsinghbhandari wants to merge 5 commits into
Closed
feat(cli): ao migrate — offline legacy→rewrite SQLite migration (#2129)#2144harshitsinghbhandari wants to merge 5 commits into
harshitsinghbhandari wants to merge 5 commits into
Conversation
Vendored SQLite migrations from aoagents/ReverbCode pinned at commit 43ae7eb for the offline `ao migrate` DB writer (AgentWrapper#2129). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Goose-compatible runner (StatementBegin/End spans, NO-TRANSACTION + 0007 writable_schema via better-sqlite3 unsafeMode), v3 goose_db_version stamping, the >= vendored precondition guard (absent/locked/older/missing), and FK-ordered ON CONFLICT DO NOTHING inserts. Adds better-sqlite3 to the CLI's optionalDependencies for deterministic createRequire resolution and copies the vendored migrations into dist on build. Integration tests assert MAX(version_id)==12 and a cursor-harness insert (proves 0007 + writable_schema=RESET took effect) plus the full precondition matrix and a checksum drift guard pinned to 43ae7eb. Refs AgentWrapper#2129. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
migrate.ts: recovered pure project mappers from the closed draft AgentWrapper#2127 (buildProjectPlan/buildRewriteConfig/mapPermission/mapHarness/isValidRewriteProjectId), dropping the loopback-REST half now that migrate writes SQLite directly. migrate-orchestrator.ts: maps a project's single non-terminated orchestrator record to one sessions row (verbatim {prefix}-orchestrator, num=0), with the 8->5 activity-state map, per-harness agent_session_id selection, the terminal/aider skip filters, double-decoded lifecycle/statePayload, and claude-code transcript relocation inputs. Refs AgentWrapper#2129. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
migrate-claude.ts: compute source (realpath-resolved worktree) + destination (literal orchestrator-worktree template) Claude project slugs via the claude-code plugin's toClaudeProjectPath, and copy the transcript jsonl. Idempotent (dest exists -> already-present; source missing -> skipped). Refs AgentWrapper#2129. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Wire the offline migrator end-to-end: resolve dataDir/dbPath (§4), build the project rows (git origin, registered_at, display_name, config blob) + read each project's orchestrator + plan transcript copies, then either preview (--dry-run, no writes) or run preconditions -> relocate transcripts -> FK-ordered inserts. Emits the locked summary (human or --json) and the exit-code contract (non-zero on refusal or any failed row). Registers next to migrate-storage in program.ts, records start/finish activity events, and adds the ao-cli minor changeset. Refs AgentWrapper#2129. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Implements
ao migrate(#2129): a single offline command (run with the rewrite daemon stopped) that ports the legacy flat-file state into the rewrite's SQLite store so users keep their projects and resume their orchestrator after the cutover.It:
~/.ao/data/ao.db,creating the DB from a vendored copy of the rewrite schema when it does not exist. Idempotent: a re-run reports everything already-present and writes nothing new.
Build order (all steps completed)
migrate-db.ts. Copied ReverbCode0001–0012.sql(pinned@ 43ae7eb) intopackages/cli/src/lib/migrations/. Built a minimal goose runner (StatementBegin/End spans, per-file transactions,NO TRANSACTIONhandling for0007), stampedgoose_db_versionrows1..12in the exact v3.27.1 format, implemented the>= vendoredprecondition guard (absent→create, locked→refuse, older→refuse, present≥12→insert, better-sqlite3 missing→refuse), and FK-orderedON CONFLICT DO NOTHINGinserts. Addedbetter-sqlite3to the CLI'soptionalDependenciesand a build step copying migrations intodist/.MAX(version_id) == 12and that acursor-harness insert succeeds — the single highest-value assertion, proving0007ran andwritable_schema = RESETtook effect on better-sqlite3's bundled SQLite. (Implementation note: better-sqlite3 blockssqlite_masterwrites in safe mode, so0007runs underdb.unsafeMode(true).)migrate.ts) recovered from the closed draft feat(cli): addao migrateto port legacy projects + settings into the rewrite daemon #2127, HTTP/daemon half dropped; addedbuildProjectRowfor the server-side fields migrate now computes itself (repo_origin_url,registered_at,kind,display_name,config).migrate-orchestrator.ts). One row per project, verbatim id{prefix}-orchestrator,num = 0, the 8→5 activity-state map, per-harnessagent_session_id, terminal/aider skip filters, and double-decodedlifecycle/statePayload.migrate-claude.ts). claude-code orchestrators only; source slug realpath-resolved, destination slug from the literal orchestrator-worktree template.commands/migrate.ts) with--dry-runand--json, the locked exit-code + summary contract, registered inprogram.tsnext toregisterMigrateStorage. Added the@aoagents/ao-climinor changeset.Tests / gate
43ae7eb); project mappers; orchestrator mapper (state map, harness selection, filters, double-decode, prefix fallback); transcript relocation; command-level dry-run / real-run / idempotency / skip-accounting / schema-too-old refusal.pnpm build && pnpm typecheck && pnpm lintall green. CLI test suite green (the one failing test in a fullpnpm test,path-equality.test.ts > expands ~ to HOME, fails identically on a clean tree — a macOS/tmp→/privaterealpath env issue, unrelated to this change;tracker-linearfailures are the missing@composio/coreSDK in this environment).The vendored schema pin (
43ae7eb/VENDORED_SCHEMA_VERSION = 12) is built as-is but is awaiting the rewrite side's freeze confirmation (spec §15):>= v12,projects/sessionspre-flip,Re-vendor + bump
VENDORED_SCHEMA_VERSIONonly on the freeze owner's signal. The checksum test pins the vendored SQL so it cannot drift silently, and the>= vendoredguard refuses anything older.Closes #2129.
🤖 Generated with Claude Code