@delegance/claude-autopilot 5.0.7 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +5 -1
  3. package/dist/src/adapters/review-engine/parse-output.js +21 -5
  4. package/dist/src/cli/fix.js +21 -3
  5. package/dist/src/cli/index.js +130 -2
  6. package/dist/src/cli/init-migrate.d.ts +35 -0
  7. package/dist/src/cli/init-migrate.js +299 -0
  8. package/dist/src/cli/migrate-doctor.d.ts +19 -0
  9. package/dist/src/cli/migrate-doctor.js +191 -0
  10. package/dist/src/core/migrate/alias-resolver.d.ts +18 -0
  11. package/dist/src/core/migrate/alias-resolver.js +150 -0
  12. package/dist/src/core/migrate/audit-log.d.ts +30 -0
  13. package/dist/src/core/migrate/audit-log.js +100 -0
  14. package/dist/src/core/migrate/contract.d.ts +27 -0
  15. package/dist/src/core/migrate/contract.js +35 -0
  16. package/dist/src/core/migrate/detector-rules.d.ts +26 -0
  17. package/dist/src/core/migrate/detector-rules.js +147 -0
  18. package/dist/src/core/migrate/detector.d.ts +16 -0
  19. package/dist/src/core/migrate/detector.js +105 -0
  20. package/dist/src/core/migrate/dispatcher.d.ts +19 -0
  21. package/dist/src/core/migrate/dispatcher.js +358 -0
  22. package/dist/src/core/migrate/doctor-checks.d.ts +19 -0
  23. package/dist/src/core/migrate/doctor-checks.js +304 -0
  24. package/dist/src/core/migrate/envelope.d.ts +25 -0
  25. package/dist/src/core/migrate/envelope.js +84 -0
  26. package/dist/src/core/migrate/executor.d.ts +33 -0
  27. package/dist/src/core/migrate/executor.js +102 -0
  28. package/dist/src/core/migrate/handshake.d.ts +17 -0
  29. package/dist/src/core/migrate/handshake.js +130 -0
  30. package/dist/src/core/migrate/migrator.d.ts +34 -0
  31. package/dist/src/core/migrate/migrator.js +302 -0
  32. package/dist/src/core/migrate/monorepo.d.ts +2 -0
  33. package/dist/src/core/migrate/monorepo.js +114 -0
  34. package/dist/src/core/migrate/policy-enforcer.d.ts +28 -0
  35. package/dist/src/core/migrate/policy-enforcer.js +111 -0
  36. package/dist/src/core/migrate/result-parser.d.ts +16 -0
  37. package/dist/src/core/migrate/result-parser.js +152 -0
  38. package/dist/src/core/migrate/schema-validator.d.ts +11 -0
  39. package/dist/src/core/migrate/schema-validator.js +103 -0
  40. package/dist/src/core/migrate/types.d.ts +49 -0
  41. package/dist/src/core/migrate/types.js +3 -0
  42. package/package.json +5 -1
  43. package/presets/aliases.lock.json +20 -0
  44. package/presets/schemas/migrate.schema.json +134 -0
  45. package/skills/autopilot/SKILL.md +29 -9
  46. package/skills/migrate/skill.manifest.json +7 -0
  47. package/skills/migrate-none/SKILL.md +40 -0
  48. package/skills/migrate-none/skill.manifest.json +7 -0
  49. package/skills/migrate-supabase/SKILL.md +126 -0
  50. package/skills/migrate-supabase/skill.manifest.json +7 -0
@@ -83,19 +83,39 @@ For each task:
83
83
  - Skip formal spec/quality review to maintain speed (the validate step catches issues)
84
84
  - If subagent fails to write to worktree: implement directly
85
85
 
86
- ### Step 4: Auto-Migrate
86
+ ### Step 4: Migrate
87
87
 
88
- For any `.sql` files created in `data/deltas/` during implementation:
88
+ After implementation creates schema changes, the autopilot pipeline runs the migrate phase via the canonical dispatcher contract. The dispatcher:
89
89
 
90
- ```bash
91
- /migrate
92
- ```
90
+ 1. Reads `.autopilot/stack.md` → looks up `migrate.skill` (default: `migrate@1`)
91
+ 2. Resolves the skill via the alias map (path-escape protected)
92
+ 3. Performs version handshake (skill manifest must declare a runtime range that includes the current `claude-autopilot` version, and an API version major matching the envelope contract)
93
+ 4. Builds an invocation envelope (`{ contractVersion, invocationId, nonce, env, repoRoot, changedFiles, gitBase, gitHead, ci, ... }`) passed to the skill via env vars + stdin
94
+ 5. Enforces policy (4-flag CI prod gate + clean-git + manual-approval + dry-run-first)
95
+ 6. Executes the configured command via `spawn(shell:false)` — structured argv only, no shell injection
96
+ 7. Parses the result artifact (file-first, nonce-bound stdout fallback only if skill manifest opts in)
97
+ 8. Writes a hash-chained audit log entry to `.autopilot/audit.log`
98
+ 9. Branches on `nextActions[]` from the result (e.g. `regenerate-types` triggers `npm run typecheck`)
99
+
100
+ For the autopilot pipeline, this is invoked once per migration affected by the implementation changes.
101
+
102
+ #### CI prod safety floor
103
+
104
+ Running `--env prod` from CI requires **all four** of these (skills cannot relax):
105
+ 1. `--yes` flag explicit
106
+ 2. `AUTOPILOT_CI_POLICY=allow-prod` env var
107
+ 3. `AUTOPILOT_TARGET_ENV=prod` env var (must match `--env`)
108
+ 4. `migrate.policy.allow_prod_in_ci: true` in stack.md
93
109
 
94
- Run against **dev only** by default. Stop after dev succeeds and continue the pipeline.
110
+ Plus a recognized CI provider env (GitHub Actions / GitLab CI / CircleCI / Buildkite / Jenkins) — or an explicit `AUTOPILOT_CI_PROVIDER=<name>` override for self-hosted CI.
95
111
 
96
- Only promote to QA → prod if the user has explicitly enabled it (e.g., `AUTOPILOT_ALLOW_PROD_MIGRATIONS=true` in their env) or asked for it directly. Production migrations are irreversible — never auto-promote without a clear signal.
112
+ #### Configuration source of truth
97
113
 
98
- If migration fails, fix the SQL and retry (max 2 retries). If it still fails, stop and report.
114
+ All migrate behavior is configured in `.autopilot/stack.md`. The autopilot skill never invokes a specific runner directly; it always dispatches through `claude-autopilot dispatch`. See:
115
+ - `docs/superpowers/specs/2026-04-29-migrate-skill-generalization-design.md` — full spec
116
+ - `docs/skills/rich-migrate-contract.md` — envelope + result artifact contract for skill authors
117
+ - `docs/skills/version-compatibility.md` — runtime/skill version compatibility matrix
118
+ - `presets/schemas/migrate.schema.json` — JSON Schema for the stack.md migrate block
99
119
 
100
120
  ### Step 5: Validate
101
121
 
@@ -157,7 +177,7 @@ Tell the user:
157
177
  ## Error Recovery
158
178
 
159
179
  - **Subagent failure:** Re-dispatch with more context or implement directly
160
- - **Migration failure:** Fix SQL, re-run /migrate
180
+ - **Migration failure:** Fix the migration source (per the configured `migrate.skill` in stack.md), re-dispatch via `claude-autopilot dispatch migrate`
161
181
  - **Validate failure:** Fix issues, re-run (max 3 retries)
162
182
  - **Codex critical findings:** Fix, push, re-review (max 2 retries)
163
183
  - **Bugbot findings:** /bugbot handles triage + fix automatically (max 3 rounds)
@@ -0,0 +1,7 @@
1
+ {
2
+ "skillId": "migrate@1",
3
+ "skill_runtime_api_version": "1.0",
4
+ "min_runtime": "5.2.0",
5
+ "max_runtime": "5.x",
6
+ "stdoutFallback": false
7
+ }
@@ -0,0 +1,40 @@
1
+ ---
2
+ name: migrate-none
3
+ description: No-op migrate skill. Emits a skipped ResultArtifact and exits cleanly. Used when migrations are intentionally not configured (e.g., a doc-only PR, a brand-new project before any DB exists).
4
+ ---
5
+
6
+ # /migrate-none — Migration intentionally not configured
7
+
8
+ The explicit "no migrations" state for the autopilot pipeline. Set `migrate.skill: "none@1"` in `.autopilot/stack.md` to short-circuit the migrate phase.
9
+
10
+ ## What it does
11
+
12
+ 1. Read `AUTOPILOT_ENVELOPE` for the invocationId + nonce
13
+ 2. Write a ResultArtifact to `AUTOPILOT_RESULT_PATH` with:
14
+ - `status: "skipped"`
15
+ - `reasonCode: "migration-disabled"`
16
+ - `appliedMigrations: []`
17
+ - `destructiveDetected: false`
18
+ - `sideEffectsPerformed: ["no-side-effects"]`
19
+ - `nextActions: []`
20
+ 3. Exit with code 0
21
+
22
+ That's it. The dispatcher reads the result and continues to the next pipeline phase.
23
+
24
+ ## When to use
25
+
26
+ - Brand-new project with no schema yet (you don't have a DB or migration tool yet)
27
+ - Docs-only or refactor-only PRs that touch no schema
28
+ - Repos where migrations are managed entirely outside the autopilot pipeline
29
+
30
+ For everything else, use `migrate@1` (thin orchestrator) or `migrate.supabase@1` (rich Supabase runner).
31
+
32
+ ## Configuration
33
+
34
+ ```yaml
35
+ schema_version: 1
36
+ migrate:
37
+ skill: "none@1"
38
+ ```
39
+
40
+ No `envs` block needed.
@@ -0,0 +1,7 @@
1
+ {
2
+ "skillId": "none@1",
3
+ "skill_runtime_api_version": "1.0",
4
+ "min_runtime": "5.2.0",
5
+ "max_runtime": "5.x",
6
+ "stdoutFallback": false
7
+ }
@@ -0,0 +1,126 @@
1
+ ---
2
+ name: migrate-supabase
3
+ description: Run database migrations against Supabase environments (dev → QA → prod). Validates SQL, executes with ledger tracking, and auto-generates the configured types output. Reads paths from .autopilot/stack.md (migrate.supabase.deltas_dir / types_out / envs_file).
4
+ ---
5
+
6
+ # Database Migration — Supabase
7
+
8
+ Run a migration through the dev → QA → prod pipeline with validation at each step. This is the "rich" Supabase variant of the migrate skill, configured via `.autopilot/stack.md`.
9
+
10
+ All paths are parameterized — the skill reads them from stack.md instead of hardcoding repo-specific locations:
11
+
12
+ - `migrate.supabase.deltas_dir` — directory holding timestamped `.sql` delta files (e.g. `data/deltas`)
13
+ - `migrate.supabase.types_out` — generated TypeScript types output path (e.g. `types/supabase.ts`)
14
+ - `migrate.supabase.envs_file` — JSON file with per-env `dbUrl` values (e.g. `.claude/supabase-envs.json`, gitignored)
15
+
16
+ Examples below show common defaults in angle brackets. Substitute the values from your stack.md.
17
+
18
+ ## Usage
19
+
20
+ ### 1. Identify the migration file
21
+
22
+ If given as argument, use that. Otherwise find the most recently modified `.sql` file in the configured deltas directory (`${migrate.supabase.deltas_dir}`, e.g. `data/deltas/`).
23
+
24
+ ### 2. Validate (dry run on dev)
25
+
26
+ ```bash
27
+ npx tsx scripts/supabase/migrate.ts <file> --env dev --dry-run
28
+ ```
29
+
30
+ Present validation results. If errors, help the user fix them before proceeding.
31
+
32
+ ### 3. Run on dev
33
+
34
+ ```bash
35
+ npx tsx scripts/supabase/migrate.ts <file> --env dev
36
+ ```
37
+
38
+ ### 4. Ask the user
39
+
40
+ > "Migration succeeded on dev. The configured types output (`${migrate.supabase.types_out}`) was updated. Promote to QA?"
41
+
42
+ ### 5. Run on QA
43
+
44
+ ```bash
45
+ npx tsx scripts/supabase/migrate.ts --promote qa
46
+ ```
47
+
48
+ ### 6. Ask the user
49
+
50
+ > "Migration succeeded on QA. Promote to prod?"
51
+
52
+ ### 7. Run on prod
53
+
54
+ ```bash
55
+ npx tsx scripts/supabase/migrate.ts --promote prod --confirm-prod
56
+ ```
57
+
58
+ ### 8. Commit
59
+
60
+ After all environments are done, commit the updated types output and the migration file:
61
+
62
+ ```bash
63
+ git add ${migrate.supabase.types_out} ${migrate.supabase.deltas_dir}/<migration-file>
64
+ git commit -m "feat: <description of schema change>"
65
+ ```
66
+
67
+ ## Flags
68
+
69
+ | Flag | Purpose |
70
+ |------|---------|
71
+ | `--env dev\|qa\|prod` | Target environment |
72
+ | `--dry-run` | Validate only, don't execute |
73
+ | `--force` | Allow destructive operations (DROP, TRUNCATE) |
74
+ | `--confirm-prod` | Required for prod execution |
75
+ | `--promote qa\|prod` | Run missing migrations from source env |
76
+
77
+ ## Validation Checks
78
+
79
+ The system validates before every execution:
80
+ - Duplicate table/column detection
81
+ - snake_case naming enforcement
82
+ - RLS + policy required for every new table
83
+ - Destructive operation blocking (unless --force)
84
+ - Cross-env prerequisite verification
85
+ - Checksum integrity (modified files are rejected)
86
+ - Promotion chain enforcement (prod requires QA first)
87
+
88
+ ## Requirements
89
+
90
+ - The configured envs file (`${migrate.supabase.envs_file}`, e.g. `.claude/supabase-envs.json`) with `dbUrl` for each env (gitignored)
91
+ - `postgres` npm package installed
92
+
93
+ ## Canonical result artifact (autopilot dispatcher integration)
94
+
95
+ When invoked under the autopilot pipeline (`AUTOPILOT_ENVELOPE` env var set), this skill writes a result artifact to `AUTOPILOT_RESULT_PATH` (or to nonce-bound stdout markers if `stdoutFallback: true` is set in the manifest):
96
+
97
+ ```json
98
+ {
99
+ "contractVersion": "1.0",
100
+ "skillId": "migrate.supabase@1",
101
+ "invocationId": "<from envelope>",
102
+ "nonce": "<from envelope>",
103
+ "status": "applied" | "skipped" | "validation-failed" | "needs-human" | "error",
104
+ "reasonCode": "<short string>",
105
+ "appliedMigrations": ["<file.sql>"],
106
+ "destructiveDetected": false,
107
+ "sideEffectsPerformed": ["migration-ledger-updated", "types-regenerated"],
108
+ "nextActions": ["regenerate-types"]
109
+ }
110
+ ```
111
+
112
+ Required `sideEffectsPerformed` values reserved by the contract: `types-regenerated`, `migration-ledger-updated`, `schema-cache-refreshed`, `seed-data-applied`, `snapshot-written`, `no-side-effects`.
113
+
114
+ ## Stack.md configuration
115
+
116
+ ```yaml
117
+ schema_version: 1
118
+ migrate:
119
+ skill: "migrate.supabase@1"
120
+ supabase:
121
+ deltas_dir: "data/deltas"
122
+ types_out: "types/supabase.ts"
123
+ envs_file: ".claude/supabase-envs.json"
124
+ policy:
125
+ allow_prod_in_ci: false
126
+ ```
@@ -0,0 +1,7 @@
1
+ {
2
+ "skillId": "migrate.supabase@1",
3
+ "skill_runtime_api_version": "1.0",
4
+ "min_runtime": "5.2.0",
5
+ "max_runtime": "5.x",
6
+ "stdoutFallback": false
7
+ }