@delegance/claude-autopilot 5.5.2 → 7.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 (150) hide show
  1. package/CHANGELOG.md +1776 -6
  2. package/README.md +65 -1
  3. package/bin/_launcher.js +38 -23
  4. package/dist/src/adapters/council/openai.js +12 -6
  5. package/dist/src/adapters/deploy/_http.d.ts +43 -0
  6. package/dist/src/adapters/deploy/_http.js +99 -0
  7. package/dist/src/adapters/deploy/fly.d.ts +206 -0
  8. package/dist/src/adapters/deploy/fly.js +696 -0
  9. package/dist/src/adapters/deploy/index.d.ts +2 -0
  10. package/dist/src/adapters/deploy/index.js +33 -0
  11. package/dist/src/adapters/deploy/render.d.ts +181 -0
  12. package/dist/src/adapters/deploy/render.js +550 -0
  13. package/dist/src/adapters/deploy/types.d.ts +67 -3
  14. package/dist/src/adapters/deploy/vercel.d.ts +17 -1
  15. package/dist/src/adapters/deploy/vercel.js +29 -49
  16. package/dist/src/adapters/pricing.d.ts +36 -0
  17. package/dist/src/adapters/pricing.js +40 -0
  18. package/dist/src/adapters/review-engine/codex.js +10 -7
  19. package/dist/src/cli/autopilot.d.ts +75 -0
  20. package/dist/src/cli/autopilot.js +750 -0
  21. package/dist/src/cli/brainstorm.d.ts +23 -0
  22. package/dist/src/cli/brainstorm.js +131 -0
  23. package/dist/src/cli/costs.d.ts +15 -1
  24. package/dist/src/cli/costs.js +99 -10
  25. package/dist/src/cli/dashboard/index.d.ts +5 -0
  26. package/dist/src/cli/dashboard/index.js +49 -0
  27. package/dist/src/cli/dashboard/login.d.ts +22 -0
  28. package/dist/src/cli/dashboard/login.js +260 -0
  29. package/dist/src/cli/dashboard/logout.d.ts +12 -0
  30. package/dist/src/cli/dashboard/logout.js +45 -0
  31. package/dist/src/cli/dashboard/status.d.ts +30 -0
  32. package/dist/src/cli/dashboard/status.js +65 -0
  33. package/dist/src/cli/dashboard/upload.d.ts +16 -0
  34. package/dist/src/cli/dashboard/upload.js +48 -0
  35. package/dist/src/cli/deploy.d.ts +3 -3
  36. package/dist/src/cli/deploy.js +34 -9
  37. package/dist/src/cli/engine-flag-deprecation.d.ts +14 -0
  38. package/dist/src/cli/engine-flag-deprecation.js +20 -0
  39. package/dist/src/cli/fix.d.ts +18 -0
  40. package/dist/src/cli/fix.js +105 -11
  41. package/dist/src/cli/help-text.d.ts +52 -0
  42. package/dist/src/cli/help-text.js +416 -0
  43. package/dist/src/cli/implement.d.ts +91 -0
  44. package/dist/src/cli/implement.js +196 -0
  45. package/dist/src/cli/index.d.ts +2 -1
  46. package/dist/src/cli/index.js +774 -245
  47. package/dist/src/cli/json-envelope.d.ts +187 -0
  48. package/dist/src/cli/json-envelope.js +270 -0
  49. package/dist/src/cli/json-mode.d.ts +33 -0
  50. package/dist/src/cli/json-mode.js +201 -0
  51. package/dist/src/cli/migrate.d.ts +111 -0
  52. package/dist/src/cli/migrate.js +305 -0
  53. package/dist/src/cli/plan.d.ts +81 -0
  54. package/dist/src/cli/plan.js +149 -0
  55. package/dist/src/cli/pr.d.ts +106 -0
  56. package/dist/src/cli/pr.js +191 -19
  57. package/dist/src/cli/preflight.js +26 -0
  58. package/dist/src/cli/review.d.ts +27 -0
  59. package/dist/src/cli/review.js +126 -0
  60. package/dist/src/cli/runs-watch-renderer.d.ts +45 -0
  61. package/dist/src/cli/runs-watch-renderer.js +275 -0
  62. package/dist/src/cli/runs-watch.d.ts +41 -0
  63. package/dist/src/cli/runs-watch.js +395 -0
  64. package/dist/src/cli/runs.d.ts +122 -0
  65. package/dist/src/cli/runs.js +902 -0
  66. package/dist/src/cli/scaffold.d.ts +39 -0
  67. package/dist/src/cli/scaffold.js +287 -0
  68. package/dist/src/cli/scan.d.ts +93 -0
  69. package/dist/src/cli/scan.js +166 -40
  70. package/dist/src/cli/setup.d.ts +30 -0
  71. package/dist/src/cli/setup.js +137 -0
  72. package/dist/src/cli/spec.d.ts +66 -0
  73. package/dist/src/cli/spec.js +132 -0
  74. package/dist/src/cli/validate.d.ts +29 -0
  75. package/dist/src/cli/validate.js +131 -0
  76. package/dist/src/core/config/schema.d.ts +9 -0
  77. package/dist/src/core/config/schema.js +7 -0
  78. package/dist/src/core/config/types.d.ts +11 -0
  79. package/dist/src/core/council/runner.d.ts +10 -1
  80. package/dist/src/core/council/runner.js +25 -3
  81. package/dist/src/core/council/types.d.ts +7 -0
  82. package/dist/src/core/errors.d.ts +1 -1
  83. package/dist/src/core/errors.js +11 -0
  84. package/dist/src/core/logging/redaction.d.ts +13 -0
  85. package/dist/src/core/logging/redaction.js +20 -0
  86. package/dist/src/core/migrate/schema-validator.js +15 -1
  87. package/dist/src/core/phases/static-rules.d.ts +5 -1
  88. package/dist/src/core/phases/static-rules.js +2 -5
  89. package/dist/src/core/run-state/budget.d.ts +88 -0
  90. package/dist/src/core/run-state/budget.js +141 -0
  91. package/dist/src/core/run-state/cli-internal.d.ts +21 -0
  92. package/dist/src/core/run-state/cli-internal.js +174 -0
  93. package/dist/src/core/run-state/events.d.ts +59 -0
  94. package/dist/src/core/run-state/events.js +512 -0
  95. package/dist/src/core/run-state/lock.d.ts +61 -0
  96. package/dist/src/core/run-state/lock.js +206 -0
  97. package/dist/src/core/run-state/phase-context.d.ts +60 -0
  98. package/dist/src/core/run-state/phase-context.js +108 -0
  99. package/dist/src/core/run-state/phase-registry.d.ts +137 -0
  100. package/dist/src/core/run-state/phase-registry.js +162 -0
  101. package/dist/src/core/run-state/phase-runner.d.ts +80 -0
  102. package/dist/src/core/run-state/phase-runner.js +447 -0
  103. package/dist/src/core/run-state/provider-readback.d.ts +130 -0
  104. package/dist/src/core/run-state/provider-readback.js +426 -0
  105. package/dist/src/core/run-state/replay-decision.d.ts +69 -0
  106. package/dist/src/core/run-state/replay-decision.js +144 -0
  107. package/dist/src/core/run-state/resolve-engine.d.ts +45 -0
  108. package/dist/src/core/run-state/resolve-engine.js +74 -0
  109. package/dist/src/core/run-state/resume-preflight.d.ts +66 -0
  110. package/dist/src/core/run-state/resume-preflight.js +116 -0
  111. package/dist/src/core/run-state/run-phase-with-lifecycle.d.ts +69 -0
  112. package/dist/src/core/run-state/run-phase-with-lifecycle.js +193 -0
  113. package/dist/src/core/run-state/runs.d.ts +57 -0
  114. package/dist/src/core/run-state/runs.js +288 -0
  115. package/dist/src/core/run-state/snapshot.d.ts +14 -0
  116. package/dist/src/core/run-state/snapshot.js +114 -0
  117. package/dist/src/core/run-state/state.d.ts +40 -0
  118. package/dist/src/core/run-state/state.js +164 -0
  119. package/dist/src/core/run-state/types.d.ts +284 -0
  120. package/dist/src/core/run-state/types.js +19 -0
  121. package/dist/src/core/run-state/ulid.d.ts +11 -0
  122. package/dist/src/core/run-state/ulid.js +95 -0
  123. package/dist/src/core/schema-alignment/extractor/index.d.ts +1 -1
  124. package/dist/src/core/schema-alignment/extractor/index.js +2 -2
  125. package/dist/src/core/schema-alignment/extractor/prisma.d.ts +13 -1
  126. package/dist/src/core/schema-alignment/extractor/prisma.js +65 -10
  127. package/dist/src/core/schema-alignment/git-history.d.ts +19 -0
  128. package/dist/src/core/schema-alignment/git-history.js +53 -0
  129. package/dist/src/core/static-rules/rules/brand-tokens.js +2 -2
  130. package/dist/src/core/static-rules/rules/schema-alignment.js +14 -4
  131. package/dist/src/dashboard/auto-upload.d.ts +26 -0
  132. package/dist/src/dashboard/auto-upload.js +107 -0
  133. package/dist/src/dashboard/config.d.ts +22 -0
  134. package/dist/src/dashboard/config.js +109 -0
  135. package/dist/src/dashboard/upload/canonical.d.ts +3 -0
  136. package/dist/src/dashboard/upload/canonical.js +16 -0
  137. package/dist/src/dashboard/upload/chain.d.ts +9 -0
  138. package/dist/src/dashboard/upload/chain.js +27 -0
  139. package/dist/src/dashboard/upload/snapshot.d.ts +23 -0
  140. package/dist/src/dashboard/upload/snapshot.js +66 -0
  141. package/dist/src/dashboard/upload/uploader.d.ts +54 -0
  142. package/dist/src/dashboard/upload/uploader.js +330 -0
  143. package/package.json +19 -3
  144. package/scripts/autoregress.ts +1 -1
  145. package/scripts/test-runner.mjs +4 -0
  146. package/skills/claude-autopilot.md +1 -1
  147. package/skills/make-interfaces-feel-better/SKILL.md +104 -0
  148. package/skills/simplify-ui/SKILL.md +103 -0
  149. package/skills/ui/SKILL.md +117 -0
  150. package/skills/ui-ux-pro-max/SKILL.md +90 -0
@@ -0,0 +1,45 @@
1
+ // `claude-autopilot dashboard logout` — revoke server-side, delete config locally.
2
+ //
3
+ // Idempotent: missing config or HTTP failure both still result in the
4
+ // local file being deleted. Server-side revocation is best-effort but we
5
+ // surface the status code on stdout for transparency.
6
+ import { readConfig, deleteConfig } from "../../dashboard/config.js";
7
+ export async function runDashboardLogout(opts = {}) {
8
+ const fetchImpl = opts.fetchImpl ?? fetch;
9
+ const baseUrl = opts.baseUrl ?? process.env.AUTOPILOT_DASHBOARD_BASE_URL ?? 'https://autopilot.dev';
10
+ const cfg = await readConfig();
11
+ if (!cfg) {
12
+ if (!opts.silent)
13
+ process.stdout.write(`[autopilot] not logged in.\n`);
14
+ await deleteConfig();
15
+ return { hadConfig: false, serverRevoked: false, serverStatus: null };
16
+ }
17
+ let status = null;
18
+ let revoked = false;
19
+ try {
20
+ const res = await fetchImpl(`${baseUrl}/api/dashboard/api-keys/revoke`, {
21
+ method: 'POST',
22
+ headers: {
23
+ authorization: `Bearer ${cfg.apiKey}`,
24
+ 'content-type': 'application/json',
25
+ },
26
+ body: JSON.stringify({ apiKey: cfg.apiKey }),
27
+ });
28
+ status = res.status;
29
+ revoked = res.ok;
30
+ }
31
+ catch {
32
+ /* network error — local delete still proceeds */
33
+ }
34
+ await deleteConfig();
35
+ if (!opts.silent) {
36
+ if (revoked) {
37
+ process.stdout.write(`[autopilot] logged out (key ${cfg.fingerprint} revoked).\n`);
38
+ }
39
+ else {
40
+ process.stdout.write(`[autopilot] local config deleted; server revocation status=${status ?? 'network error'}.\n`);
41
+ }
42
+ }
43
+ return { hadConfig: true, serverRevoked: revoked, serverStatus: status };
44
+ }
45
+ //# sourceMappingURL=logout.js.map
@@ -0,0 +1,30 @@
1
+ export interface StatusOptions {
2
+ baseUrl?: string;
3
+ fetchImpl?: typeof fetch;
4
+ silent?: boolean;
5
+ }
6
+ export interface MeResponse {
7
+ email: string | null;
8
+ fingerprint: string | null;
9
+ organizations: Array<{
10
+ id: string;
11
+ name: string;
12
+ role: string;
13
+ }>;
14
+ lastUploadAt: string | null;
15
+ }
16
+ export interface StatusResult {
17
+ loggedIn: boolean;
18
+ fingerprint: string | null;
19
+ email: string | null;
20
+ serverOk: boolean;
21
+ organizations: Array<{
22
+ id: string;
23
+ name: string;
24
+ role: string;
25
+ }>;
26
+ lastUploadAt: string | null;
27
+ permissiveWarning: string | null;
28
+ }
29
+ export declare function runDashboardStatus(opts?: StatusOptions): Promise<StatusResult>;
30
+ //# sourceMappingURL=status.d.ts.map
@@ -0,0 +1,65 @@
1
+ // `claude-autopilot dashboard status` — read config + call /me + print.
2
+ import { readConfig, warnIfPermissive, getConfigPath, } from "../../dashboard/config.js";
3
+ export async function runDashboardStatus(opts = {}) {
4
+ const fetchImpl = opts.fetchImpl ?? fetch;
5
+ const baseUrl = opts.baseUrl ?? process.env.AUTOPILOT_DASHBOARD_BASE_URL ?? 'https://autopilot.dev';
6
+ const cfg = await readConfig();
7
+ const permissive = await warnIfPermissive();
8
+ if (!cfg) {
9
+ if (!opts.silent) {
10
+ process.stdout.write(`[autopilot] not logged in. Run: claude-autopilot dashboard login\n`);
11
+ process.stdout.write(` (config path: ${getConfigPath()})\n`);
12
+ }
13
+ return {
14
+ loggedIn: false,
15
+ fingerprint: null,
16
+ email: null,
17
+ serverOk: false,
18
+ organizations: [],
19
+ lastUploadAt: null,
20
+ permissiveWarning: permissive,
21
+ };
22
+ }
23
+ let me = null;
24
+ let serverOk = false;
25
+ try {
26
+ const res = await fetchImpl(`${baseUrl}/api/dashboard/me`, {
27
+ method: 'GET',
28
+ headers: { authorization: `Bearer ${cfg.apiKey}` },
29
+ });
30
+ if (res.ok) {
31
+ me = await res.json();
32
+ serverOk = true;
33
+ }
34
+ }
35
+ catch {
36
+ /* network error — fall through with serverOk=false */
37
+ }
38
+ if (!opts.silent) {
39
+ process.stdout.write(`[autopilot] logged in as ${cfg.accountEmail} (${cfg.fingerprint}).\n`);
40
+ if (serverOk && me) {
41
+ if (me.organizations.length > 0) {
42
+ process.stdout.write(` organizations: ${me.organizations.map((o) => `${o.name} (${o.role})`).join(', ')}\n`);
43
+ }
44
+ if (me.lastUploadAt) {
45
+ process.stdout.write(` last upload: ${me.lastUploadAt}\n`);
46
+ }
47
+ }
48
+ else {
49
+ process.stdout.write(` (server unreachable; using cached config)\n`);
50
+ }
51
+ if (permissive) {
52
+ process.stderr.write(`${permissive}\n`);
53
+ }
54
+ }
55
+ return {
56
+ loggedIn: true,
57
+ fingerprint: cfg.fingerprint,
58
+ email: cfg.accountEmail,
59
+ serverOk,
60
+ organizations: me?.organizations ?? [],
61
+ lastUploadAt: me?.lastUploadAt ?? null,
62
+ permissiveWarning: permissive,
63
+ };
64
+ }
65
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1,16 @@
1
+ import { type UploadResult } from '../../dashboard/upload/uploader.ts';
2
+ export interface ManualUploadOptions {
3
+ runId: string;
4
+ runsDir?: string;
5
+ baseUrl?: string;
6
+ fetchImpl?: typeof fetch;
7
+ silent?: boolean;
8
+ signal?: AbortSignal;
9
+ }
10
+ export interface ManualUploadResult extends UploadResult {
11
+ notLoggedIn?: boolean;
12
+ runDirMissing?: boolean;
13
+ runDir?: string;
14
+ }
15
+ export declare function runDashboardUpload(opts: ManualUploadOptions): Promise<ManualUploadResult>;
16
+ //# sourceMappingURL=upload.d.ts.map
@@ -0,0 +1,48 @@
1
+ // `claude-autopilot dashboard upload <runId>` — manual upload wrapper.
2
+ //
3
+ // Locates run dir at <homeDir>/runs/<runId>, calls uploadRun() directly,
4
+ // and prints the result. Intended for resuming interrupted auto-uploads.
5
+ import * as path from 'node:path';
6
+ import { promises as fs } from 'node:fs';
7
+ import { readConfig, getConfigDir } from "../../dashboard/config.js";
8
+ import { uploadRun } from "../../dashboard/upload/uploader.js";
9
+ export async function runDashboardUpload(opts) {
10
+ const cfg = await readConfig();
11
+ if (!cfg) {
12
+ if (!opts.silent) {
13
+ process.stderr.write(`[autopilot] not logged in. Run: claude-autopilot dashboard login\n`);
14
+ }
15
+ return { ok: false, notLoggedIn: true };
16
+ }
17
+ const runsDir = opts.runsDir ?? path.join(getConfigDir(), 'runs');
18
+ const runDir = path.join(runsDir, opts.runId);
19
+ try {
20
+ await fs.access(runDir);
21
+ }
22
+ catch {
23
+ if (!opts.silent) {
24
+ process.stderr.write(`[autopilot] run dir not found: ${runDir}\n`);
25
+ }
26
+ return { ok: false, runDirMissing: true, runDir };
27
+ }
28
+ const uploadOpts = {
29
+ apiKey: cfg.apiKey,
30
+ ...(opts.baseUrl !== undefined ? { baseUrl: opts.baseUrl } : {}),
31
+ ...(opts.fetchImpl !== undefined ? { fetchImpl: opts.fetchImpl } : {}),
32
+ ...(opts.signal !== undefined ? { signal: opts.signal } : {}),
33
+ };
34
+ const res = await uploadRun(opts.runId, runDir, uploadOpts);
35
+ if (!opts.silent) {
36
+ if (res.ok && res.url) {
37
+ process.stdout.write(`[autopilot] uploaded to ${res.url}\n`);
38
+ }
39
+ else if (res.ok && res.skipped) {
40
+ process.stdout.write(`[autopilot] skipping upload — events.ndjson is empty\n`);
41
+ }
42
+ else {
43
+ process.stderr.write(`[autopilot] upload failed: ${res.error}\n`);
44
+ }
45
+ }
46
+ return { ...res, runDir };
47
+ }
48
+ //# sourceMappingURL=upload.js.map
@@ -2,7 +2,7 @@ import type { DeployAdapter, DeployConfig } from '../adapters/deploy/types.ts';
2
2
  export interface RunDeployOptions {
3
3
  configPath?: string;
4
4
  /** When set, overrides `deploy.adapter` from config. */
5
- adapterOverride?: 'vercel' | 'generic';
5
+ adapterOverride?: 'vercel' | 'fly' | 'render' | 'generic';
6
6
  ref?: string;
7
7
  commitSha?: string;
8
8
  cwd?: string;
@@ -39,7 +39,7 @@ export interface RunDeployOptions {
39
39
  export declare function runDeploy(opts: RunDeployOptions): Promise<number>;
40
40
  export interface RunDeployRollbackOptions {
41
41
  configPath?: string;
42
- adapterOverride?: 'vercel' | 'generic';
42
+ adapterOverride?: 'vercel' | 'fly' | 'render' | 'generic';
43
43
  /** Specific deploy ID to roll back to. When omitted, the previous prod deploy is used. */
44
44
  to?: string;
45
45
  cwd?: string;
@@ -48,7 +48,7 @@ export interface RunDeployRollbackOptions {
48
48
  }
49
49
  export interface RunDeployStatusOptions {
50
50
  configPath?: string;
51
- adapterOverride?: 'vercel' | 'generic';
51
+ adapterOverride?: 'vercel' | 'fly' | 'render' | 'generic';
52
52
  cwd?: string;
53
53
  adapterFactory?: (config: DeployConfig) => DeployAdapter;
54
54
  }
@@ -55,7 +55,7 @@ async function loadDeployConfigAsync(opts) {
55
55
  const adapter = opts.adapterOverride ?? configBlock?.adapter;
56
56
  if (!adapter) {
57
57
  console.error('\x1b[31m[deploy] no deploy adapter configured\x1b[0m\n' +
58
- ' hint: set `deploy.adapter` in guardrail.config.yaml, or pass --adapter <vercel|generic>');
58
+ ' hint: set `deploy.adapter` in guardrail.config.yaml, or pass --adapter <vercel|fly|render|generic>');
59
59
  return { errorCode: 1 };
60
60
  }
61
61
  const merged = {
@@ -85,6 +85,16 @@ export async function runDeploy(opts) {
85
85
  let onDeployStart;
86
86
  if (opts.watch) {
87
87
  if (typeof deployAdapter.streamLogs === 'function') {
88
+ // Phase 3 of v5.6 — when an adapter advertises `streamMode: 'polling'`
89
+ // (currently only Render), surface a one-line stderr notice BEFORE
90
+ // iteration starts so users understand why their log lines arrive
91
+ // in batches with short gaps. Adapters with `streamMode: 'websocket'`
92
+ // (Vercel SSE, Fly WS) or `'none'`/undefined get no notice — their
93
+ // streaming behavior matches user expectations. Spec: § "Capability
94
+ // metadata".
95
+ if (deployAdapter.capabilities?.streamMode === 'polling') {
96
+ process.stderr.write(`[deploy] note: ${deployAdapter.name} uses 2s log polling — lines may arrive in batches and could include short gaps. See docs/deploy/adapters.md#log-streaming for details.\n`);
97
+ }
88
98
  streamController = new AbortController();
89
99
  const streamFn = deployAdapter.streamLogs.bind(deployAdapter);
90
100
  const ctrlSignal = streamController.signal;
@@ -142,12 +152,20 @@ export async function runDeploy(opts) {
142
152
  const wantRollback = triggers.includes('healthCheckFailure');
143
153
  if (wantRollback) {
144
154
  if (typeof deployAdapter.rollback === 'function') {
155
+ // BOUND: exactly one auto-rollback per deploy attempt (spec §
156
+ // "Health-check policy" → "After rollback completes (success
157
+ // or failure), the adapter returns; no second rollback
158
+ // attempt"). The single `rollback({})` call below is the only
159
+ // place this path is invoked; we do NOT loop. Result status
160
+ // becomes one of the two new terminal values:
161
+ // - `fail_rolled_back` — rollback returned `pass`
162
+ // - `fail_rollback_failed` — rollback returned non-pass OR threw
145
163
  try {
146
164
  const rb = await deployAdapter.rollback({});
147
165
  if (rb.status === 'pass') {
148
166
  result = {
149
167
  ...result,
150
- status: 'fail',
168
+ status: 'fail_rolled_back',
151
169
  rolledBackTo: rb.rolledBackTo ?? rb.deployId,
152
170
  output: `Deploy passed; health check failed (${healthOutcome.lastError}); auto-rolled back to ${rb.rolledBackTo ?? rb.deployId ?? '<unknown>'}.`,
153
171
  };
@@ -156,7 +174,7 @@ export async function runDeploy(opts) {
156
174
  else {
157
175
  result = {
158
176
  ...result,
159
- status: 'fail',
177
+ status: 'fail_rollback_failed',
160
178
  output: `Deploy passed; health check failed; auto-rollback ALSO failed: ${rb.output ?? '<no output>'}`,
161
179
  };
162
180
  printAutoRollbackFailed(rb.output ?? 'rollback returned non-pass');
@@ -166,7 +184,7 @@ export async function runDeploy(opts) {
166
184
  const msg = err?.message ?? String(err);
167
185
  result = {
168
186
  ...result,
169
- status: 'fail',
187
+ status: 'fail_rollback_failed',
170
188
  output: `Deploy passed; health check failed; auto-rollback ERRORED: ${msg}`,
171
189
  };
172
190
  printAutoRollbackFailed(msg);
@@ -364,15 +382,22 @@ function formatAge(createdAtMs) {
364
382
  const days = Math.floor(hours / 24);
365
383
  return `${days}d`;
366
384
  }
385
+ /** Per v5.6 spec § "Health-check policy" — cap retries at 5× with 6s backoff. */
386
+ const HEALTH_CHECK_MAX_ATTEMPTS = 5;
387
+ const HEALTH_CHECK_BACKOFF_MS = 6000;
367
388
  /**
368
- * Probe a URL up to 3 times with 2s backoff between attempts. 2xx → pass.
389
+ * Probe a URL up to {@link HEALTH_CHECK_MAX_ATTEMPTS} times with
390
+ * {@link HEALTH_CHECK_BACKOFF_MS} backoff between attempts. 2xx → pass.
369
391
  * Per-attempt timeout is 10s. Network errors are treated as failures and
370
392
  * retried.
393
+ *
394
+ * Total wall-clock budget: ~30s (5 attempts × 6s backoff between, minus
395
+ * the trailing skip — matches the spec's "max ~30s window").
371
396
  */
372
397
  async function runHealthCheck(opts) {
373
398
  const { url, fetchImpl, sleepImpl } = opts;
374
399
  let lastError = '';
375
- for (let attempt = 1; attempt <= 3; attempt += 1) {
400
+ for (let attempt = 1; attempt <= HEALTH_CHECK_MAX_ATTEMPTS; attempt += 1) {
376
401
  const ctrl = new AbortController();
377
402
  const timer = setTimeout(() => ctrl.abort(), 10_000);
378
403
  try {
@@ -387,8 +412,8 @@ async function runHealthCheck(opts) {
387
412
  clearTimeout(timer);
388
413
  lastError = err?.message ?? String(err);
389
414
  }
390
- if (attempt < 3)
391
- await sleepImpl(2000);
415
+ if (attempt < HEALTH_CHECK_MAX_ATTEMPTS)
416
+ await sleepImpl(HEALTH_CHECK_BACKOFF_MS);
392
417
  }
393
418
  return { status: 'fail', url, lastError };
394
419
  }
@@ -406,7 +431,7 @@ function printAutoRollback(adapter, hc, rb) {
406
431
  const reset = '\x1b[0m';
407
432
  const target = rb.rolledBackTo ?? rb.deployId ?? '<unknown>';
408
433
  console.log(`${yellow}🔄 [deploy] auto-rolled-back-to=${target} via=${adapter} health-check-url=${hc.url}${reset}`);
409
- console.log(`${dim} reason: health check failed 3x against ${hc.url} (${hc.lastError})${reset}`);
434
+ console.log(`${dim} reason: health check failed ${HEALTH_CHECK_MAX_ATTEMPTS}x against ${hc.url} (${hc.lastError})${reset}`);
410
435
  if (rb.deployUrl) {
411
436
  console.log(`${dim} current: ${rb.deployUrl}${reset}`);
412
437
  }
@@ -0,0 +1,14 @@
1
+ /** Banner emitted to stderr (once per process) when `--engine` is
2
+ * passed in v7.0+. The flag is preserved as a no-op shim; the engine
3
+ * is unconditionally on. Codex pass-3 NOTE #2. */
4
+ export declare const ENGINE_FLAG_DEPRECATION_MESSAGE = "[deprecation] --engine is a no-op in v7.0+ (engine is always on). Drop the flag from your scripts.";
5
+ /** Banner emitted to stderr when `--no-engine` is passed in v7.0+. The
6
+ * dispatcher rejects with `invalid_config` exit 1 immediately after. */
7
+ export declare const ENGINE_OFF_REMOVED_MESSAGE = "[deprecation] --no-engine was removed in v7.0. The engine is always on. See docs/v7/breaking-changes.md.";
8
+ /** Banner emitted to stderr (once per process) when
9
+ * `CLAUDE_AUTOPILOT_ENGINE` is set to an off-style value. The env value
10
+ * is otherwise ignored — softer than the `--no-engine` rejection
11
+ * because env vars in CI are sticky and silently breaking every
12
+ * v6.x → v7 upgrade in CI on day one would burn user trust. */
13
+ export declare const ENGINE_OFF_ENV_REMOVED_MESSAGE = "[deprecation] CLAUDE_AUTOPILOT_ENGINE=off has no effect in v7.0+ (engine is always on). Unset the env var.";
14
+ //# sourceMappingURL=engine-flag-deprecation.d.ts.map
@@ -0,0 +1,20 @@
1
+ // src/cli/engine-flag-deprecation.ts
2
+ //
3
+ // v7.0 — exported deprecation constants for the engine-flag removal.
4
+ // Pulled out of src/cli/index.ts so tests can import them without
5
+ // triggering the dispatcher's top-level switch (which exits the
6
+ // process on module load).
7
+ /** Banner emitted to stderr (once per process) when `--engine` is
8
+ * passed in v7.0+. The flag is preserved as a no-op shim; the engine
9
+ * is unconditionally on. Codex pass-3 NOTE #2. */
10
+ export const ENGINE_FLAG_DEPRECATION_MESSAGE = '[deprecation] --engine is a no-op in v7.0+ (engine is always on). Drop the flag from your scripts.';
11
+ /** Banner emitted to stderr when `--no-engine` is passed in v7.0+. The
12
+ * dispatcher rejects with `invalid_config` exit 1 immediately after. */
13
+ export const ENGINE_OFF_REMOVED_MESSAGE = '[deprecation] --no-engine was removed in v7.0. The engine is always on. See docs/v7/breaking-changes.md.';
14
+ /** Banner emitted to stderr (once per process) when
15
+ * `CLAUDE_AUTOPILOT_ENGINE` is set to an off-style value. The env value
16
+ * is otherwise ignored — softer than the `--no-engine` rejection
17
+ * because env vars in CI are sticky and silently breaking every
18
+ * v6.x → v7 upgrade in CI on day one would burn user trust. */
19
+ export const ENGINE_OFF_ENV_REMOVED_MESSAGE = '[deprecation] CLAUDE_AUTOPILOT_ENGINE=off has no effect in v7.0+ (engine is always on). Unset the env var.';
20
+ //# sourceMappingURL=engine-flag-deprecation.js.map
@@ -1,3 +1,4 @@
1
+ import type { ReviewEngine } from '../adapters/review-engine/types.ts';
1
2
  export interface FixCommandOptions {
2
3
  cwd?: string;
3
4
  configPath?: string;
@@ -5,6 +6,23 @@ export interface FixCommandOptions {
5
6
  dryRun?: boolean;
6
7
  yes?: boolean;
7
8
  noVerify?: boolean;
9
+ /**
10
+ * v6.0.2 — engine knob inputs. Same shape and precedence as scan / costs
11
+ * (CLI > env > config > built-in default off in v6.0.x). The CLI
12
+ * dispatcher wires `cliEngine` from `--engine` / `--no-engine`;
13
+ * `envEngine` from `process.env.CLAUDE_AUTOPILOT_ENGINE`. An absent CLI
14
+ * flag + absent env value falls through to the loaded config and then to
15
+ * the built-in default.
16
+ */
17
+ cliEngine?: boolean;
18
+ envEngine?: string;
19
+ /**
20
+ * Test-only seam — injects a pre-built ReviewEngine so tests can exercise
21
+ * the engine-wrap path without hitting `loadAdapter()` (and therefore
22
+ * without needing an LLM API key in the environment). Mirrors the seam
23
+ * in `scan.ts`. Production callers MUST NOT pass this.
24
+ */
25
+ __testReviewEngine?: ReviewEngine;
8
26
  }
9
27
  export declare function runFix(options?: FixCommandOptions): Promise<number>;
10
28
  //# sourceMappingURL=fix.d.ts.map
@@ -6,6 +6,7 @@ import { loadCachedFindings } from "../core/persist/findings-cache.js";
6
6
  import { loadConfig } from "../core/config/loader.js";
7
7
  import { loadAdapter } from "../adapters/loader.js";
8
8
  import { generateFix, buildUnifiedDiff } from "../core/fix/generator.js";
9
+ import { runPhaseWithLifecycle } from "../core/run-state/run-phase-with-lifecycle.js";
9
10
  const C = {
10
11
  reset: '\x1b[0m', bold: '\x1b[1m', dim: '\x1b[2m',
11
12
  green: '\x1b[32m', yellow: '\x1b[33m', red: '\x1b[31m', cyan: '\x1b[36m',
@@ -90,14 +91,22 @@ export async function runFix(options = {}) {
90
91
  let loadedConfig = null;
91
92
  try {
92
93
  loadedConfig = fs.existsSync(configPath) ? await loadConfig(configPath) : null;
93
- const ref = loadedConfig
94
- ? (typeof loadedConfig.reviewEngine === 'string' ? loadedConfig.reviewEngine : (loadedConfig.reviewEngine?.adapter ?? 'auto'))
95
- : 'auto';
96
- engine = await loadAdapter({
97
- point: 'review-engine',
98
- ref,
99
- options: loadedConfig && typeof loadedConfig.reviewEngine === 'object' ? loadedConfig.reviewEngine.options : undefined,
100
- });
94
+ if (options.__testReviewEngine) {
95
+ // Test-only fast path skip the adapter loader (and therefore the
96
+ // implicit LLM key check inside the auto-loader). Same seam as scan's
97
+ // `__testReviewEngine`. Production callers do not pass this.
98
+ engine = options.__testReviewEngine;
99
+ }
100
+ else {
101
+ const ref = loadedConfig
102
+ ? (typeof loadedConfig.reviewEngine === 'string' ? loadedConfig.reviewEngine : (loadedConfig.reviewEngine?.adapter ?? 'auto'))
103
+ : 'auto';
104
+ engine = await loadAdapter({
105
+ point: 'review-engine',
106
+ ref,
107
+ options: loadedConfig && typeof loadedConfig.reviewEngine === 'object' ? loadedConfig.reviewEngine.options : undefined,
108
+ });
109
+ }
101
110
  }
102
111
  catch (err) {
103
112
  console.error(fmt('red', `[fix] Could not load review engine: ${err instanceof Error ? err.message : String(err)}`));
@@ -108,6 +117,81 @@ export async function runFix(options = {}) {
108
117
  if (shouldVerify) {
109
118
  console.log(fmt('dim', `[fix] Verified mode — running "${testCommand}" after each fix\n`));
110
119
  }
120
+ const fixInput = {
121
+ cwd,
122
+ fixable,
123
+ engine,
124
+ testCommand,
125
+ shouldVerify,
126
+ // The early-return above already exits when options.dryRun is true, so
127
+ // we're always entering the apply loop here with dryRun=false. Keep the
128
+ // field on FixInput for shape parity (renderFixOutput consumes it) and
129
+ // for future engine-resume scenarios where the snapshot is replayed.
130
+ dryRun: false,
131
+ yes: options.yes === true,
132
+ };
133
+ // The wrapped phase body — runs the apply loop with native readline +
134
+ // per-finding console output INSIDE the phase body. The recipe doc says
135
+ // "no console output" for phase bodies, but `fix` is fundamentally
136
+ // interactive: the user must see each diff and approve it. Same precedent
137
+ // as scan keeping its LLM call inside the phase body. Documented
138
+ // deviation, intentional.
139
+ const phase = {
140
+ name: 'fix',
141
+ // Same-input → same-output: the LLM fix generator is deterministic per
142
+ // (finding, file content) pair, and applied diffs are exact text
143
+ // replacements. Re-running against the same cached findings against an
144
+ // unchanged tree produces the same results.
145
+ idempotent: true,
146
+ // Local file edits only — no remote / git push / PR creation in the
147
+ // existing `fix` flow. Per the recipe table, "side effects" means
148
+ // platform-side mutations (PR comments, git push, deploy). Local file
149
+ // writes are inside the project tree and the engine treats them like
150
+ // findings-cache writes (already overwrite-style).
151
+ hasSideEffects: false,
152
+ run: async (input) => executeFixPhase(input),
153
+ };
154
+ // v6.0.6 — lifecycle wiring lives in `runPhaseWithLifecycle`. The helper
155
+ // owns the engine-on/engine-off branch and the failure banner; the caller
156
+ // just supplies the phase, the input, and the engine-off escape hatch.
157
+ // The fix phase body is interactive (readline + per-finding diff prints
158
+ // INSIDE executeFixPhase) — that deviation from "pure phase body" is
159
+ // documented in fix's executeFixPhase header comment and unaffected by
160
+ // the helper extract: the helper still calls phase.run, which IS
161
+ // executeFixPhase, exactly as before.
162
+ let output;
163
+ try {
164
+ const result = await runPhaseWithLifecycle({
165
+ cwd,
166
+ phase,
167
+ input: fixInput,
168
+ // The helper only consults `config.engine.enabled` — pass through
169
+ // `loadedConfig` if we have one, otherwise an empty default.
170
+ config: loadedConfig ?? { configVersion: 1 },
171
+ cliEngine: options.cliEngine,
172
+ envEngine: options.envEngine,
173
+ runEngineOff: () => executeFixPhase(fixInput),
174
+ });
175
+ output = result.output;
176
+ }
177
+ catch {
178
+ // Helper already printed the failure banner + emitted run.complete
179
+ // failed + refreshed state.json + released the lock.
180
+ return 1;
181
+ }
182
+ return renderFixOutput(output, fixInput);
183
+ }
184
+ // ---------------------------------------------------------------------------
185
+ // Phase body — drive the apply loop. INTENTIONAL DEVIATION from the recipe:
186
+ // the loop emits per-finding console output and prompts via readline. Pure
187
+ // side-effect-free phase bodies are the recipe default; interactive verbs
188
+ // like `fix` are an explicit exception (same precedent as scan's LLM call
189
+ // inside its phase body). The summary banner + exit code logic still lives
190
+ // in `renderFixOutput` so the engine path's idempotency isn't coupled to
191
+ // the final stdout shape.
192
+ // ---------------------------------------------------------------------------
193
+ async function executeFixPhase(input) {
194
+ const { cwd, fixable, engine, testCommand, shouldVerify, dryRun, yes } = input;
111
195
  const results = [];
112
196
  let quit = false;
113
197
  for (const finding of fixable) {
@@ -135,7 +219,7 @@ export async function runFix(options = {}) {
135
219
  }
136
220
  // Show diff
137
221
  const diff = buildUnifiedDiff(result.originalLines, result.replacementLines, finding.file, result.startLine);
138
- if (options.dryRun) {
222
+ if (dryRun) {
139
223
  console.log('');
140
224
  console.log(diff);
141
225
  console.log(fmt('dim', ' (dry run — not applied)'));
@@ -143,7 +227,7 @@ export async function runFix(options = {}) {
143
227
  continue;
144
228
  }
145
229
  // Interactive confirmation (unless --yes)
146
- if (!options.yes) {
230
+ if (!yes) {
147
231
  const answer = await confirmFix(diff, finding);
148
232
  if (answer === 'quit') {
149
233
  quit = true;
@@ -197,12 +281,22 @@ export async function runFix(options = {}) {
197
281
  results.push({ file: finding.file, line: finding.line, findingMessage: finding.message, status: 'failed', reason: String(err) });
198
282
  }
199
283
  }
284
+ return { results, dryRun };
285
+ }
286
+ // ---------------------------------------------------------------------------
287
+ // Render — translate FixOutput back to the legacy stdout summary + exit
288
+ // code. Lives outside the wrapped phase so the engine path's idempotency
289
+ // isn't coupled to the final summary line shape.
290
+ // ---------------------------------------------------------------------------
291
+ function renderFixOutput(output, input) {
292
+ const { results, dryRun } = output;
293
+ const { fixable } = input;
200
294
  const fixed = results.filter(r => r.status === 'fixed').length;
201
295
  const rejected = results.filter(r => r.status === 'rejected').length;
202
296
  const failed = results.filter(r => r.status === 'failed').length;
203
297
  const skipped = results.filter(r => r.status === 'skipped').length;
204
298
  console.log('');
205
- if (options.dryRun) {
299
+ if (dryRun) {
206
300
  console.log(fmt('yellow', `[fix] Dry run complete — ${fixable.length} finding${fixable.length !== 1 ? 's' : ''} previewed, no files modified.\n`));
207
301
  }
208
302
  else {
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Two-level help grouping for the claude-autopilot CLI.
3
+ *
4
+ * The CLI ships ~25 subcommands. A flat list crowds the welcome screen and
5
+ * makes it hard for new users to find the verb they need. This module owns
6
+ * the canonical grouping (Pipeline / Review / Deploy / Migrate / Diagnostics
7
+ * / Advanced), the per-verb summaries, and the per-verb Options blocks.
8
+ *
9
+ * The dispatcher in index.ts imports these helpers — keeping the data here
10
+ * means the help text can be rendered into a string for tests without firing
11
+ * the side-effecting top-level switch statement in index.ts.
12
+ *
13
+ * Group assignments are asserted by tests/cli/help-text.test.ts so newly
14
+ * added verbs are forced into the structure rather than silently dropped.
15
+ *
16
+ * Groups are ordered roughly by user journey:
17
+ * Pipeline — brainstorm → spec → plan → implement → PR
18
+ * Review — operates on findings / runs the LLM-backed code review
19
+ * Deploy — platform-specific deploy verbs
20
+ * Migrate — database migration dispatch
21
+ * Diagnostics — sanity checks, second-opinion, test scaffolding
22
+ * Advanced — long-running daemons / niche / experimental verbs
23
+ */
24
+ export type HelpVerb = {
25
+ verb: string;
26
+ summary: string;
27
+ };
28
+ export type HelpGroup = {
29
+ name: string;
30
+ tagline: string;
31
+ verbs: HelpVerb[];
32
+ };
33
+ export declare const HELP_GROUPS: HelpGroup[];
34
+ /**
35
+ * Per-verb Options blocks. Keyed by the verb that owns the block. Some verbs
36
+ * have no documented flags (e.g. `costs`, `lsp`, `report`) and are absent here;
37
+ * `claude-autopilot help <verb>` will show just the row in that case.
38
+ */
39
+ export declare const HELP_OPTIONS: Record<string, string>;
40
+ /**
41
+ * Global flags advertised in --help. These work across most verbs (per-verb
42
+ * support varies; v6.0.1 wires them into `scan` first, additional verbs land
43
+ * in subsequent v6.0.x point releases per docs/v6/wrapping-pipeline-phases.md).
44
+ */
45
+ export declare const GLOBAL_FLAGS_BLOCK = "Global flags:\n --json Emit a structured JSON envelope on stdout (most verbs)\n --engine [v7.0 deprecated no-op] engine is always on; flag emits a warning\n v7.0 removed the engine-off opt-out flag and code path entirely.\n CLAUDE_AUTOPILOT_ENGINE=off is now ignored (warns once per process)\n instead of disabling the engine. See docs/v7/breaking-changes.md.";
46
+ /** Build the full two-level help text. Returned as a string so tests can assert against it without spawning. */
47
+ export declare function buildHelpText(): string;
48
+ /** Build help text for a single verb. Returns null if the verb is unknown. */
49
+ export declare function buildCommandHelpText(verb: string): string | null;
50
+ /** Set of verbs that have a row in HELP_GROUPS — used by `help <verb>` lookup and by tests. */
51
+ export declare const HELP_VERBS: readonly string[];
52
+ //# sourceMappingURL=help-text.d.ts.map