mirror of
https://github.com/garrytan/gbrain.git
synced 2026-07-27 22:15:33 +00:00
Replaces the stub from commit de027ce. The orchestrator runs all seven
phases of the v0.11.0 Minions adoption migration idempotently, resumable
from any prior status:"partial" run (the stopgap bash script writes
those).
Phases:
A. Schema — `gbrain init --migrate-only` (NEVER bare `gbrain init`,
which defaults to PGLite and clobbers existing configs —
Codex H1 show-stopper).
B. Smoke — `gbrain jobs smoke`. Abort loudly on non-zero.
C. Mode — --mode flag wins. Preserved from prefs on resume. Non-TTY
or --yes defaults pain_triggered with explicit print.
Interactive: numbered 1/2/3 menu via shared promptLine.
D. Prefs — savePreferences({minion_mode, set_at, set_in_version}).
E. Host — AGENTS.md marker injection + cron manifest rewrites. For
cron entries whose skill matches a gbrain builtin
(sync/embed/lint/import/extract/backlinks/autopilot-cycle)
rewrites kind:agentTurn → kind:shell with a
gbrain jobs submit command. PGLite branch keeps --follow
(inline execution, the only path that works without a
worker daemon); Postgres branch drops --follow + adds
--idempotency-key ${handler}:${slot} so long cron jobs
don't stack up (same Codex fix as the autopilot-cycle
dispatch). For non-builtin handlers (host-specific, like
ea-inbox-sweep, frameio-scan, x-dm-triage) emits a
structured TODO row to
~/.gbrain/migrations/pending-host-work.jsonl so the host
agent can walk through plugin-contract work per
skills/migrations/v0.11.0.md.
F. Install — `gbrain autopilot --install --yes`. Best-effort (failure
doesn't abort; user can run manually).
G. Record — append to completed.jsonl. status:"complete" unless
pending_host_work > 0, in which case status:"partial" +
apply_migrations_pending: true.
Safety guards (Codex code-quality tension #3: strict-skip, no rollback):
- Scope: $HOME/.claude + $HOME/.openclaw only by default. --host-dir
must be explicit to include $PWD or any other path.
- Symlink escape: SKIP if the resolved target leaves the scoped root.
- >1 MB files: SKIP with warning.
- Permission denied: SKIP with warning; other files continue.
- Malformed JSON manifest: SKIP with parse error logged; continue.
- mtime re-check right before write: bail the file if changed between
read + write; other files continue.
- Every edit writes a .bak.<ISO-timestamp> sibling first (second-
precision so two same-day runs don't collide).
- Idempotency: `_gbrain_migrated_by: "v0.11.0"` JSON property marker
on each rewritten cron entry (JSON can't have comments — Codex G);
AGENTS.md marker `<!-- gbrain:subagent-routing v0.11.0 -->`.
- TODO dedupe: JSONL appends deduped by (handler, manifest_path) so
reruns don't grow the file.
Post-run summary: when pending_host_work > 0, prints a one-liner
pointing the user at the JSONL path + the v0.11.0 skill file. The skill
(Lane C-3 / C-4) is the host-agent instruction manual.
test/migrations-v0_11_0.test.ts: 18 tests covering:
- AGENTS.md injection: happy path, .bak creation, idempotent rerun,
--dry-run no-op, symlink-escape SKIP, >1MB SKIP.
- Cron rewrite: builtin handlers rewrite to shell+gbrain jobs submit,
non-builtins emit JSONL TODOs without touching the manifest, mixed
manifests get both treatments in one pass, idempotent rerun, TODO
dedupe, malformed JSON SKIP, no-entries-array SKIP, --dry-run no-op.
- findAgentsMdFiles + findCronManifests: scoped walk to $HOME/.claude +
$HOME/.openclaw, --host-dir opt-in for $PWD.
- BUILTIN_HANDLERS frozen at the canonical 7 names.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>