@delegance/claude-autopilot 5.2.2 → 5.5.2

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 (32) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/README.md +49 -17
  3. package/dist/src/adapters/council/claude.js +2 -1
  4. package/dist/src/adapters/council/openai.js +2 -1
  5. package/dist/src/adapters/deploy/generic.d.ts +39 -0
  6. package/dist/src/adapters/deploy/generic.js +98 -0
  7. package/dist/src/adapters/deploy/index.d.ts +13 -0
  8. package/dist/src/adapters/deploy/index.js +45 -0
  9. package/dist/src/adapters/deploy/types.d.ts +157 -0
  10. package/dist/src/adapters/deploy/types.js +15 -0
  11. package/dist/src/adapters/deploy/vercel.d.ts +127 -0
  12. package/dist/src/adapters/deploy/vercel.js +446 -0
  13. package/dist/src/adapters/review-engine/claude.js +2 -1
  14. package/dist/src/adapters/review-engine/codex.js +2 -1
  15. package/dist/src/adapters/review-engine/gemini.js +2 -1
  16. package/dist/src/adapters/review-engine/openai-compatible.js +2 -1
  17. package/dist/src/adapters/sdk-loader.d.ts +15 -0
  18. package/dist/src/adapters/sdk-loader.js +77 -0
  19. package/dist/src/cli/deploy.d.ts +71 -0
  20. package/dist/src/cli/deploy.js +514 -0
  21. package/dist/src/cli/index.js +91 -3
  22. package/dist/src/cli/preflight.js +76 -1
  23. package/dist/src/core/config/schema.d.ts +34 -0
  24. package/dist/src/core/config/schema.js +18 -0
  25. package/dist/src/core/config/types.d.ts +6 -0
  26. package/dist/src/core/errors.d.ts +1 -1
  27. package/dist/src/core/errors.js +1 -0
  28. package/dist/src/core/migrate/detector-rules.js +6 -0
  29. package/dist/src/core/migrate/schema-validator.js +7 -0
  30. package/package.json +8 -5
  31. package/scripts/autoregress.ts +2 -1
  32. package/skills/migrate/SKILL.md +193 -47
@@ -1,83 +1,229 @@
1
1
  ---
2
2
  name: migrate
3
- description: Run database migrations against Supabase environments (dev QA prod). Validates SQL, executes with ledger tracking, and auto-generates types/supabase.ts.
3
+ description: Framework-agnostic database migration orchestrator. Reads .autopilot/stack.md, runs the configured per-env command (Rails, Alembic, Prisma, Drizzle, golang-migrate, dbmate, flyway, supabase-cli, custom), enforces policy gates, and emits a structured result artifact. For Supabase-specific repos with data/deltas/* layout use `migrate-supabase` instead.
4
4
  ---
5
5
 
6
- # Database Migration
6
+ # /migrate — Generic database migration orchestrator
7
7
 
8
- Run a migration through the dev QA prod pipeline with validation at each step.
8
+ The thin, framework-agnostic migrate skill. Wraps any migration tool in a uniform contract:
9
9
 
10
- ## Usage
10
+ 1. Validate `.autopilot/stack.md` against the JSON schema
11
+ 2. Resolve the configured skill + apply policy (clean git, manual approval, prod-in-CI gate)
12
+ 3. Run `migrate.envs.<env>.command` via `spawn(shell: false)` — no shell injection surface
13
+ 4. Capture stdout/stderr, parse the result artifact, append an audit-log entry
14
+ 5. Return a `ResultArtifact` to the caller (autopilot pipeline or CLI)
11
15
 
12
- ### 1. Identify the migration file
16
+ This skill **does not know what your migration tool is**. It just executes the command you point it at and reports the outcome. Tool-specific behavior (e.g., Supabase's `data/deltas/*.sql` ledger or auto-regenerating `types/supabase.ts`) lives in `migrate-supabase`. Everything else uses this one.
13
17
 
14
- If given as argument, use that. Otherwise find the most recently modified `.sql` file in `data/deltas/`.
18
+ ## Usage
15
19
 
16
- ### 2. Validate (dry run on dev)
20
+ ### CLI
17
21
 
18
22
  ```bash
19
- npx tsx scripts/supabase/migrate.ts <file> --env dev --dry-run
23
+ claude-autopilot migrate # default env: dev
24
+ claude-autopilot migrate --env qa
25
+ claude-autopilot migrate --env prod --yes # required for prod (manual approval)
26
+ claude-autopilot migrate doctor # validate stack.md without running
20
27
  ```
21
28
 
22
- Present validation results. If errors, help the user fix them before proceeding.
29
+ ### Autopilot pipeline
30
+
31
+ The dispatcher invokes the skill automatically when `migrate` is in the pipeline plan. The skill receives the invocation envelope via `AUTOPILOT_ENVELOPE` and writes its result to `AUTOPILOT_RESULT_PATH`.
32
+
33
+ ## Configuration
34
+
35
+ Add a `migrate` block to `.autopilot/stack.md`:
36
+
37
+ ```yaml
38
+ schema_version: 1
39
+ migrate:
40
+ skill: "migrate@1"
41
+ envs:
42
+ dev:
43
+ command: { exec: "<tool>", args: ["<args>"] }
44
+ env_file: ".env.dev"
45
+ qa:
46
+ command: { exec: "<tool>", args: ["<args>"] }
47
+ prod:
48
+ command: { exec: "<tool>", args: ["<args>"] }
49
+ policy:
50
+ allow_prod_in_ci: false
51
+ require_clean_git: true
52
+ require_manual_approval: true
53
+ require_dry_run_first: false
54
+ ```
23
55
 
24
- ### 3. Run on dev
56
+ The `init` flow auto-detects most common toolchains and pre-fills sensible commands. Run `claude-autopilot init` once to bootstrap.
25
57
 
26
- ```bash
27
- npx tsx scripts/supabase/migrate.ts <file> --env dev
58
+ ## Examples by toolchain
59
+
60
+ ### Rails (Active Record)
61
+
62
+ ```yaml
63
+ migrate:
64
+ skill: "migrate@1"
65
+ envs:
66
+ dev:
67
+ command: { exec: "rails", args: ["db:migrate"] }
68
+ env_file: ".env.development"
69
+ prod:
70
+ command: { exec: "rails", args: ["db:migrate", "RAILS_ENV=production"] }
28
71
  ```
29
72
 
30
- ### 4. Ask the user
73
+ ### Alembic (Python)
74
+
75
+ ```yaml
76
+ migrate:
77
+ skill: "migrate@1"
78
+ envs:
79
+ dev:
80
+ command: { exec: "alembic", args: ["upgrade", "head"] }
81
+ env_file: ".env.dev"
82
+ prod:
83
+ command: { exec: "alembic", args: ["-x", "env=prod", "upgrade", "head"] }
84
+ ```
31
85
 
32
- > "Migration succeeded on dev. `types/supabase.ts` updated. Promote to QA?"
86
+ ### Django
33
87
 
34
- ### 5. Run on QA
88
+ ```yaml
89
+ migrate:
90
+ skill: "migrate@1"
91
+ envs:
92
+ dev:
93
+ command: { exec: "python", args: ["manage.py", "migrate"] }
94
+ env_file: ".env.dev"
95
+ ```
35
96
 
36
- ```bash
37
- npx tsx scripts/supabase/migrate.ts --promote qa
97
+ ### golang-migrate
98
+
99
+ ```yaml
100
+ migrate:
101
+ skill: "migrate@1"
102
+ envs:
103
+ dev:
104
+ command: { exec: "migrate", args: ["-database", "$DATABASE_URL", "-path", "migrations", "up"] }
105
+ env_file: ".env.dev"
38
106
  ```
39
107
 
40
- ### 6. Ask the user
108
+ ### Prisma
41
109
 
42
- > "Migration succeeded on QA. Promote to prod?"
110
+ ```yaml
111
+ migrate:
112
+ skill: "migrate@1"
113
+ envs:
114
+ dev:
115
+ command: { exec: "prisma", args: ["migrate", "dev"] }
116
+ prod:
117
+ command: { exec: "prisma", args: ["migrate", "deploy"] }
118
+ ```
43
119
 
44
- ### 7. Run on prod
120
+ ### Drizzle
45
121
 
46
- ```bash
47
- npx tsx scripts/supabase/migrate.ts --promote prod --confirm-prod
122
+ ```yaml
123
+ migrate:
124
+ skill: "migrate@1"
125
+ envs:
126
+ dev:
127
+ command: { exec: "drizzle-kit", args: ["migrate"] }
128
+ env_file: ".env.dev"
48
129
  ```
49
130
 
50
- ### 8. Commit
131
+ ### dbmate
51
132
 
52
- After all environments are done, commit the updated `types/supabase.ts` and the migration file:
133
+ ```yaml
134
+ migrate:
135
+ skill: "migrate@1"
136
+ envs:
137
+ dev:
138
+ command: { exec: "dbmate", args: ["up"] }
139
+ env_file: ".env.dev"
140
+ ```
53
141
 
54
- ```bash
55
- git add types/supabase.ts data/deltas/<migration-file>
56
- git commit -m "feat: <description of schema change>"
142
+ ### Flyway
143
+
144
+ ```yaml
145
+ migrate:
146
+ skill: "migrate@1"
147
+ envs:
148
+ dev:
149
+ command: { exec: "flyway", args: ["migrate"] }
57
150
  ```
58
151
 
59
- ## Flags
152
+ ### Supabase CLI
153
+
154
+ ```yaml
155
+ migrate:
156
+ skill: "migrate@1"
157
+ envs:
158
+ dev:
159
+ command: { exec: "supabase", args: ["migration", "up"] }
160
+ ```
60
161
 
61
- | Flag | Purpose |
62
- |------|---------|
63
- | `--env dev\|qa\|prod` | Target environment |
64
- | `--dry-run` | Validate only, don't execute |
65
- | `--force` | Allow destructive operations (DROP, TRUNCATE) |
66
- | `--confirm-prod` | Required for prod execution |
67
- | `--promote qa\|prod` | Run missing migrations from source env |
162
+ ### Custom script
68
163
 
69
- ## Validation Checks
164
+ Anything goes — the dispatcher just runs `exec` with `args`:
70
165
 
71
- The system validates before every execution:
72
- - Duplicate table/column detection
73
- - snake_case naming enforcement
74
- - RLS + policy required for every new table
75
- - Destructive operation blocking (unless --force)
76
- - Cross-env prerequisite verification
77
- - Checksum integrity (modified files are rejected)
78
- - Promotion chain enforcement (prod requires QA first)
166
+ ```yaml
167
+ migrate:
168
+ skill: "migrate@1"
169
+ envs:
170
+ dev:
171
+ command: { exec: "./scripts/db/migrate.sh", args: ["--env", "dev"] }
172
+ env_file: ".env.dev"
173
+ ```
174
+
175
+ ## When to use `migrate-supabase` instead
176
+
177
+ Use `migrate.supabase@1` if your repo has the canonical Delegance/Supabase layout:
178
+ - `data/deltas/<timestamp>_<name>.sql` files as the source of truth
179
+ - `.claude/supabase-envs.json` with per-env `dbUrl`
180
+ - Auto-regeneration of `types/supabase.ts` after each apply
181
+ - Built-in promotion chain (dev → qa → prod with checksum verification)
182
+
183
+ Otherwise, use `migrate@1` with the appropriate command above.
184
+
185
+ ## Policy enforcement
186
+
187
+ Every run goes through `policy-enforcer.ts` before the command executes. The default policy:
188
+
189
+ | Setting | Default | Effect |
190
+ |---------|---------|--------|
191
+ | `allow_prod_in_ci` | `false` | Fail if `--env prod` runs in CI without explicit override |
192
+ | `require_clean_git` | `true` | Fail if working tree has uncommitted changes |
193
+ | `require_manual_approval` | `true` | Fail prod runs without `--yes` flag |
194
+ | `require_dry_run_first` | `false` | Force a dry-run before apply (opt-in) |
195
+
196
+ Override per-environment if your workflow needs it. Tighter is better — these defaults catch real foot-guns.
197
+
198
+ ## Result artifact
199
+
200
+ When invoked under the autopilot pipeline (`AUTOPILOT_ENVELOPE` set), the skill writes:
201
+
202
+ ```json
203
+ {
204
+ "contractVersion": "1.0",
205
+ "skillId": "migrate@1",
206
+ "invocationId": "<uuid>",
207
+ "nonce": "<from envelope>",
208
+ "status": "applied" | "skipped" | "validation-failed" | "needs-human" | "error",
209
+ "reasonCode": "<short string>",
210
+ "appliedMigrations": [],
211
+ "destructiveDetected": false,
212
+ "sideEffectsPerformed": ["no-side-effects"],
213
+ "nextActions": []
214
+ }
215
+ ```
216
+
217
+ The generic skill cannot enumerate `appliedMigrations` (that's tool-specific) — it leaves the array empty and reports `status: "applied"` if the command exited 0. Tool-specific result enrichment is the job of skills like `migrate-supabase` that understand the migration ledger format.
218
+
219
+ ## Auditing
220
+
221
+ Every dispatch — success, failure, dry-run — writes one entry to `.autopilot/audit.log` (chained via `seq` + `prev_hash`). Inspect with:
222
+
223
+ ```bash
224
+ claude-autopilot migrate doctor --audit-tail 10
225
+ ```
79
226
 
80
- ## Requirements
227
+ ## Stack.md schema
81
228
 
82
- - `.claude/supabase-envs.json` with `dbUrl` for each env (gitignored)
83
- - `postgres` npm package installed
229
+ See `presets/schemas/migrate.schema.json` for the full JSON schema. Validation happens automatically on every dispatch — invalid `.autopilot/stack.md` fails closed before any command runs.