@rainy-updates/cli 0.5.7 → 0.6.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 (84) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/README.md +90 -31
  3. package/dist/bin/cli.js +16 -16
  4. package/dist/bin/dispatch.js +29 -32
  5. package/dist/bin/help.js +32 -2
  6. package/dist/cache/cache.js +13 -11
  7. package/dist/commands/audit/parser.js +2 -2
  8. package/dist/commands/audit/runner.js +27 -46
  9. package/dist/commands/audit/targets.js +13 -13
  10. package/dist/commands/bisect/oracle.js +28 -11
  11. package/dist/commands/bisect/parser.js +3 -3
  12. package/dist/commands/bisect/runner.js +15 -8
  13. package/dist/commands/changelog/fetcher.js +11 -5
  14. package/dist/commands/dashboard/parser.js +103 -1
  15. package/dist/commands/dashboard/runner.d.ts +2 -2
  16. package/dist/commands/dashboard/runner.js +67 -37
  17. package/dist/commands/doctor/parser.js +9 -4
  18. package/dist/commands/doctor/runner.js +2 -2
  19. package/dist/commands/ga/parser.js +4 -4
  20. package/dist/commands/ga/runner.js +13 -7
  21. package/dist/commands/health/parser.js +2 -2
  22. package/dist/commands/licenses/runner.js +4 -4
  23. package/dist/commands/resolve/runner.js +9 -4
  24. package/dist/commands/review/parser.js +57 -4
  25. package/dist/commands/review/runner.js +31 -5
  26. package/dist/commands/snapshot/runner.js +17 -17
  27. package/dist/commands/snapshot/store.d.ts +0 -12
  28. package/dist/commands/snapshot/store.js +26 -38
  29. package/dist/commands/unused/runner.js +6 -7
  30. package/dist/commands/unused/scanner.js +17 -20
  31. package/dist/config/loader.d.ts +2 -2
  32. package/dist/config/loader.js +2 -5
  33. package/dist/config/policy.js +20 -11
  34. package/dist/core/analysis/run-silenced.js +0 -1
  35. package/dist/core/artifacts.js +6 -5
  36. package/dist/core/baseline.js +3 -5
  37. package/dist/core/check.js +2 -2
  38. package/dist/core/ci.js +52 -1
  39. package/dist/core/decision-plan.d.ts +14 -0
  40. package/dist/core/decision-plan.js +107 -0
  41. package/dist/core/doctor/result.js +8 -5
  42. package/dist/core/fix-pr-batch.js +38 -28
  43. package/dist/core/fix-pr.js +27 -24
  44. package/dist/core/init-ci.js +25 -21
  45. package/dist/core/options.js +95 -4
  46. package/dist/core/review-model.js +3 -0
  47. package/dist/core/summary.js +6 -0
  48. package/dist/core/upgrade.js +64 -2
  49. package/dist/core/verification.d.ts +2 -0
  50. package/dist/core/verification.js +106 -0
  51. package/dist/core/warm-cache.js +2 -2
  52. package/dist/output/format.js +15 -0
  53. package/dist/output/github.js +6 -0
  54. package/dist/output/sarif.js +12 -12
  55. package/dist/parsers/package-json.js +2 -4
  56. package/dist/pm/detect.d.ts +3 -1
  57. package/dist/pm/detect.js +24 -12
  58. package/dist/pm/install.d.ts +2 -1
  59. package/dist/pm/install.js +15 -16
  60. package/dist/registry/npm.js +34 -76
  61. package/dist/rup +0 -0
  62. package/dist/types/index.d.ts +76 -5
  63. package/dist/ui/tui.d.ts +4 -1
  64. package/dist/ui/tui.js +5 -4
  65. package/dist/utils/io.js +5 -6
  66. package/dist/utils/lockfile.js +24 -19
  67. package/dist/utils/runtime-paths.d.ts +4 -0
  68. package/dist/utils/runtime-paths.js +35 -0
  69. package/dist/utils/runtime.d.ts +7 -0
  70. package/dist/utils/runtime.js +32 -0
  71. package/dist/workspace/discover.js +55 -51
  72. package/package.json +16 -16
  73. package/dist/ui/dashboard/DashboardTUI.d.ts +0 -6
  74. package/dist/ui/dashboard/DashboardTUI.js +0 -34
  75. package/dist/ui/dashboard/components/DetailPanel.d.ts +0 -4
  76. package/dist/ui/dashboard/components/DetailPanel.js +0 -30
  77. package/dist/ui/dashboard/components/Footer.d.ts +0 -4
  78. package/dist/ui/dashboard/components/Footer.js +0 -9
  79. package/dist/ui/dashboard/components/Header.d.ts +0 -4
  80. package/dist/ui/dashboard/components/Header.js +0 -12
  81. package/dist/ui/dashboard/components/Sidebar.d.ts +0 -4
  82. package/dist/ui/dashboard/components/Sidebar.js +0 -23
  83. package/dist/ui/dashboard/store.d.ts +0 -34
  84. package/dist/ui/dashboard/store.js +0 -148
@@ -1,8 +1,7 @@
1
- import { spawn } from "node:child_process";
2
- import { promises as fs } from "node:fs";
3
- import os from "node:os";
1
+ import { $ } from "bun";
4
2
  import path from "node:path";
5
3
  import { readManifest, writeManifest } from "../parsers/package-json.js";
4
+ import { createTempDir } from "../utils/runtime-paths.js";
6
5
  export async function applyFixPrBatches(options, result) {
7
6
  const autofixUpdates = result.updates.filter((update) => update.autofix !== false);
8
7
  if (!options.fixPr || autofixUpdates.length === 0) {
@@ -12,14 +11,25 @@ export async function applyFixPrBatches(options, result) {
12
11
  const groups = groupUpdates(autofixUpdates, options.groupBy);
13
12
  const plans = planFixPrBatches(groups, options.fixBranch ?? "chore/rainy-updates", options.fixPrBatchSize ?? 1);
14
13
  if (options.fixDryRun) {
15
- return { applied: false, branches: plans.map((plan) => plan.branchName), commits: [] };
14
+ return {
15
+ applied: false,
16
+ branches: plans.map((plan) => plan.branchName),
17
+ commits: [],
18
+ };
16
19
  }
17
20
  const branches = [];
18
21
  const commits = [];
19
22
  for (const plan of plans) {
20
- const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "rainy-fix-pr-batch-"));
23
+ const tempDir = await createTempDir("rainy-fix-pr-batch-");
21
24
  try {
22
- await runGit(options.cwd, ["worktree", "add", "-B", plan.branchName, tempDir, baseRef]);
25
+ await runGit(options.cwd, [
26
+ "worktree",
27
+ "add",
28
+ "-B",
29
+ plan.branchName,
30
+ tempDir,
31
+ baseRef,
32
+ ]);
23
33
  await applyUpdatesInWorktree(options.cwd, tempDir, plan.updates);
24
34
  await stageUpdatedManifests(options.cwd, tempDir, plan.updates);
25
35
  const message = renderCommitMessage(options, plan, plans.length);
@@ -47,7 +57,9 @@ export function planFixPrBatches(groups, baseBranch, batchSize) {
47
57
  chunks.push(groups.slice(index, index + size));
48
58
  }
49
59
  return chunks.map((chunk, index) => {
50
- const suffix = chunk.length === 1 ? sanitizeBranchToken(chunk[0]?.key ?? `batch-${index + 1}`) : `batch-${index + 1}`;
60
+ const suffix = chunk.length === 1
61
+ ? sanitizeBranchToken(chunk[0]?.key ?? `batch-${index + 1}`)
62
+ : `batch-${index + 1}`;
51
63
  return {
52
64
  index: index + 1,
53
65
  groups: chunk,
@@ -147,27 +159,25 @@ function renderCommitMessage(options, plan, totalBatches) {
147
159
  return `${baseMessage} (${plan.index}/${totalBatches}, ${plan.updates.length} updates)`;
148
160
  }
149
161
  function sanitizeBranchToken(value) {
150
- return value.replace(/^@/, "").replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/^-+|-+$/g, "") || "batch";
162
+ return (value
163
+ .replace(/^@/, "")
164
+ .replace(/[^a-zA-Z0-9._-]+/g, "-")
165
+ .replace(/^-+|-+$/g, "") || "batch");
151
166
  }
152
167
  async function runGit(cwd, args, allowNonZero = false) {
153
- return await new Promise((resolve, reject) => {
154
- const child = spawn("git", args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
155
- let stdout = "";
156
- let stderr = "";
157
- child.stdout.on("data", (chunk) => {
158
- stdout += typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
159
- });
160
- child.stderr.on("data", (chunk) => {
161
- stderr += typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
162
- });
163
- child.on("error", reject);
164
- child.on("exit", (code) => {
165
- const normalized = code ?? 1;
166
- if (normalized !== 0 && !allowNonZero) {
167
- reject(new Error(`git ${args.join(" ")} failed (${normalized}): ${stderr.trim()}`));
168
- return;
169
- }
170
- resolve({ code: normalized, stdout, stderr });
171
- });
172
- });
168
+ try {
169
+ const res = await $ `git ${args}`.cwd(cwd).quiet().nothrow();
170
+ const code = res.exitCode;
171
+ const stdout = res.stdout.toString();
172
+ const stderr = res.stderr.toString();
173
+ if (code !== 0 && !allowNonZero) {
174
+ throw new Error(`git ${args.join(" ")} failed (${code}): ${stderr.trim()}`);
175
+ }
176
+ return { code, stdout, stderr };
177
+ }
178
+ catch (err) {
179
+ if (allowNonZero)
180
+ return { code: 1, stdout: "", stderr: "" };
181
+ throw err instanceof Error ? err : new Error(String(err));
182
+ }
173
183
  }
@@ -1,4 +1,4 @@
1
- import { spawn } from "node:child_process";
1
+ import { $ } from "bun";
2
2
  import path from "node:path";
3
3
  export async function applyFixPr(options, result, extraFiles) {
4
4
  if (!options.fixPr)
@@ -42,7 +42,8 @@ export async function applyFixPr(options, result, extraFiles) {
42
42
  : [];
43
43
  const filesToStage = Array.from(new Set([...manifestFiles, ...extraFiles, ...lockfileFiles]
44
44
  .map((entry) => path.resolve(options.cwd, entry))
45
- .filter((entry) => entry.startsWith(path.resolve(options.cwd) + path.sep) || entry === path.resolve(options.cwd)))).sort((a, b) => a.localeCompare(b));
45
+ .filter((entry) => entry.startsWith(path.resolve(options.cwd) + path.sep) ||
46
+ entry === path.resolve(options.cwd)))).sort((a, b) => a.localeCompare(b));
46
47
  if (filesToStage.length > 0) {
47
48
  await runGit(options.cwd, ["add", "--", ...filesToStage]);
48
49
  }
@@ -54,7 +55,8 @@ export async function applyFixPr(options, result, extraFiles) {
54
55
  commitSha: "",
55
56
  };
56
57
  }
57
- const message = options.fixCommitMessage ?? `chore(deps): apply rainy-updates (${autofixUpdates.length} updates)`;
58
+ const message = options.fixCommitMessage ??
59
+ `chore(deps): apply rainy-updates (${autofixUpdates.length} updates)`;
58
60
  await runGit(options.cwd, ["commit", "-m", message]);
59
61
  const rev = await runGit(options.cwd, ["rev-parse", "HEAD"]);
60
62
  return {
@@ -64,30 +66,31 @@ export async function applyFixPr(options, result, extraFiles) {
64
66
  };
65
67
  }
66
68
  async function runGit(cwd, args, allowNonZero = false) {
67
- return await new Promise((resolve, reject) => {
68
- const child = spawn("git", args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
69
- let stdout = "";
70
- let stderr = "";
71
- child.stdout.on("data", (chunk) => {
72
- stdout += typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
73
- });
74
- child.stderr.on("data", (chunk) => {
75
- stderr += typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
76
- });
77
- child.on("error", reject);
78
- child.on("exit", (code) => {
79
- const normalized = code ?? 1;
80
- if (normalized !== 0 && !allowNonZero) {
81
- reject(new Error(`git ${args.join(" ")} failed (${normalized}): ${stderr.trim()}`));
82
- return;
83
- }
84
- resolve({ code: normalized, stdout, stderr });
85
- });
86
- });
69
+ try {
70
+ const res = await $ `git ${args}`.cwd(cwd).quiet().nothrow();
71
+ const code = res.exitCode;
72
+ const stdout = res.stdout.toString();
73
+ const stderr = res.stderr.toString();
74
+ if (code !== 0 && !allowNonZero) {
75
+ throw new Error(`git ${args.join(" ")} failed (${code}): ${stderr.trim()}`);
76
+ }
77
+ return { code, stdout, stderr };
78
+ }
79
+ catch (err) {
80
+ if (allowNonZero)
81
+ return { code: 1, stdout: "", stderr: "" };
82
+ throw err instanceof Error ? err : new Error(String(err));
83
+ }
87
84
  }
88
85
  async function collectChangedLockfiles(cwd) {
89
86
  const status = await runGit(cwd, ["status", "--porcelain"], true);
90
- const allowed = new Set(["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lock"]);
87
+ const allowed = new Set([
88
+ "package-lock.json",
89
+ "npm-shrinkwrap.json",
90
+ "pnpm-lock.yaml",
91
+ "yarn.lock",
92
+ "bun.lock",
93
+ ]);
91
94
  const changed = status.stdout
92
95
  .split(/\r?\n/)
93
96
  .map((line) => line.trim())
@@ -1,17 +1,20 @@
1
- import { access, writeFile, mkdir } from "node:fs/promises";
1
+ import { mkdir } from "node:fs/promises";
2
2
  import path from "node:path";
3
+ import { detectPackageManager } from "../pm/detect.js";
3
4
  export async function initCiWorkflow(cwd, force, options) {
4
5
  const workflowPath = path.join(cwd, ".github", "workflows", "rainy-updates.yml");
5
6
  try {
6
7
  if (!force) {
7
- await access(workflowPath);
8
- return { path: workflowPath, created: false };
8
+ if (await Bun.file(workflowPath).exists()) {
9
+ return { path: workflowPath, created: false };
10
+ }
9
11
  }
10
12
  }
11
13
  catch {
12
14
  // missing file, continue create
13
15
  }
14
- const packageManager = await detectPackageManager(cwd);
16
+ const detected = await detectPackageManager(cwd);
17
+ const packageManager = detected === "unknown" || detected === "yarn" ? "npm" : detected;
15
18
  const scheduleBlock = renderScheduleBlock(options.schedule);
16
19
  const workflow = options.mode === "minimal"
17
20
  ? minimalWorkflowTemplate(scheduleBlock, packageManager)
@@ -19,19 +22,9 @@ export async function initCiWorkflow(cwd, force, options) {
19
22
  ? strictWorkflowTemplate(scheduleBlock, packageManager)
20
23
  : enterpriseWorkflowTemplate(scheduleBlock, packageManager);
21
24
  await mkdir(path.dirname(workflowPath), { recursive: true });
22
- await writeFile(workflowPath, workflow, "utf8");
25
+ await Bun.write(workflowPath, workflow);
23
26
  return { path: workflowPath, created: true };
24
27
  }
25
- async function detectPackageManager(cwd) {
26
- const pnpmLock = path.join(cwd, "pnpm-lock.yaml");
27
- try {
28
- await access(pnpmLock);
29
- return "pnpm";
30
- }
31
- catch {
32
- return "npm";
33
- }
34
- }
35
28
  function renderScheduleBlock(schedule) {
36
29
  if (schedule === "off") {
37
30
  return " workflow_dispatch:";
@@ -40,20 +33,31 @@ function renderScheduleBlock(schedule) {
40
33
  return ` schedule:\n - cron: '${cron}'\n workflow_dispatch:`;
41
34
  }
42
35
  function installStep(packageManager) {
36
+ if (packageManager === "bun") {
37
+ return ` - name: Install dependencies\n run: bun install`;
38
+ }
43
39
  if (packageManager === "pnpm") {
44
40
  return ` - name: Setup pnpm\n uses: pnpm/action-setup@v4\n with:\n version: 9\n\n - name: Install dependencies\n run: pnpm install --frozen-lockfile`;
45
41
  }
46
42
  return ` - name: Install dependencies\n run: npm ci`;
47
43
  }
48
44
  function minimalWorkflowTemplate(scheduleBlock, packageManager) {
49
- return `name: Rainy Updates\n\non:\n${scheduleBlock}\n\njobs:\n dependency-check:\n runs-on: ubuntu-latest\n steps:\n - name: Checkout\n uses: actions/checkout@v4\n\n - name: Setup Node\n uses: actions/setup-node@v4\n with:\n node-version: '20'\n\n${installStep(packageManager)}\n\n - name: Run dependency check\n run: |\n npx @rainy-updates/cli ci \\\n --workspace \\\n --mode minimal \\\n --ci \\\n --stream \\\n --registry-timeout-ms 12000 \\\n --registry-retries 4 \\\n --format table\n`;
45
+ return `name: Rainy Updates\n\non:\n${scheduleBlock}\n\njobs:\n dependency-check:\n runs-on: ubuntu-latest\n steps:\n - name: Checkout\n uses: actions/checkout@v4\n\n - name: Setup Bun\n uses: oven-sh/setup-bun@v1\n\n${installStep(packageManager)}\n\n - name: Run dependency check\n run: |\n bunx --bun @rainy-updates/cli ci \\\n --workspace \\\n --mode minimal \\\n --gate check \\\n --ci \\\n --stream \\\n --registry-timeout-ms 12000 \\\n --registry-retries 4 \\\n --format table\n`;
50
46
  }
51
47
  function strictWorkflowTemplate(scheduleBlock, packageManager) {
52
- return `name: Rainy Updates\n\non:\n${scheduleBlock}\n\npermissions:\n contents: read\n security-events: write\n\njobs:\n dependency-check:\n runs-on: ubuntu-latest\n steps:\n - name: Checkout\n uses: actions/checkout@v4\n\n - name: Setup Node\n uses: actions/setup-node@v4\n with:\n node-version: '20'\n\n${installStep(packageManager)}\n\n - name: Warm cache\n run: npx @rainy-updates/cli warm-cache --workspace --concurrency 32 --registry-timeout-ms 12000 --registry-retries 4\n\n - name: Run strict dependency check\n run: |\n npx @rainy-updates/cli ci \\\n --workspace \\\n --mode strict \\\n --ci \\\n --concurrency 32 \\\n --stream \\\n --registry-timeout-ms 12000 \\\n --registry-retries 4 \\\n --format github \\\n --json-file .artifacts/deps-report.json \\\n --pr-report-file .artifacts/deps-report.md \\\n --sarif-file .artifacts/deps-report.sarif \\\n --github-output $GITHUB_OUTPUT\n\n - name: Upload report artifacts\n uses: actions/upload-artifact@v4\n with:\n name: rainy-updates-report\n path: .artifacts/\n\n - name: Upload SARIF\n uses: github/codeql-action/upload-sarif@v3\n with:\n sarif_file: .artifacts/deps-report.sarif\n`;
48
+ return `name: Rainy Updates\n\non:\n${scheduleBlock}\n\npermissions:\n contents: read\n security-events: write\n\njobs:\n dependency-check:\n runs-on: ubuntu-latest\n steps:\n - name: Checkout\n uses: actions/checkout@v4\n\n - name: Setup Bun\n uses: oven-sh/setup-bun@v1\n\n${installStep(packageManager)}\n\n - name: Warm cache\n run: bunx --bun @rainy-updates/cli warm-cache --workspace --concurrency 32 --registry-timeout-ms 12000 --registry-retries 4\n\n - name: Generate reviewed decision plan\n run: |\n bunx --bun @rainy-updates/cli ci \\\n --workspace \\\n --mode strict \\\n --gate review \\\n --plan-file .artifacts/decision-plan.json \\\n --ci \\\n --concurrency 32 \\\n --stream \\\n --registry-timeout-ms 12000 \\\n --registry-retries 4 \\\n --format github \\\n --json-file .artifacts/deps-report.json \\\n --pr-report-file .artifacts/deps-report.md \\\n --sarif-file .artifacts/deps-report.sarif \\\n --github-output $GITHUB_OUTPUT\n\n - name: Upload report artifacts\n uses: actions/upload-artifact@v4\n with:\n name: rainy-updates-report\n path: .artifacts/\n\n - name: Upload SARIF\n uses: github/codeql-action/upload-sarif@v3\n with:\n sarif_file: .artifacts/deps-report.sarif\n`;
53
49
  }
54
50
  function enterpriseWorkflowTemplate(scheduleBlock, packageManager) {
55
- const detectedPmInstall = packageManager === "pnpm"
56
- ? "corepack enable && corepack prepare pnpm@9 --activate && pnpm install --frozen-lockfile"
57
- : "npm ci";
58
- return `name: Rainy Updates Enterprise\n\non:\n${scheduleBlock}\n\npermissions:\n contents: read\n security-events: write\n actions: read\n\nconcurrency:\n group: rainy-updates-\${{ github.ref }}\n cancel-in-progress: false\n\njobs:\n dependency-check:\n runs-on: ubuntu-latest\n strategy:\n fail-fast: false\n matrix:\n node: [20, 22]\n steps:\n - name: Checkout\n uses: actions/checkout@v4\n\n - name: Setup Node\n uses: actions/setup-node@v4\n with:\n node-version: \${{ matrix.node }}\n\n - name: Install dependencies\n run: ${detectedPmInstall}\n\n - name: Warm cache\n run: npx @rainy-updates/cli warm-cache --workspace --concurrency 32 --registry-timeout-ms 12000 --registry-retries 4\n\n - name: Check updates with rollout controls\n run: |\n npx @rainy-updates/cli ci \\\n --workspace \\\n --mode enterprise \\\n --concurrency 32 \\\n --stream \\\n --registry-timeout-ms 12000 \\\n --registry-retries 4 \\\n --lockfile-mode preserve \\\n --format github \\\n --fail-on minor \\\n --max-updates 50 \\\n --json-file .artifacts/deps-report-node-\${{ matrix.node }}.json \\\n --pr-report-file .artifacts/deps-report-node-\${{ matrix.node }}.md \\\n --sarif-file .artifacts/deps-report-node-\${{ matrix.node }}.sarif \\\n --github-output $GITHUB_OUTPUT\n\n - name: Upload report artifacts\n uses: actions/upload-artifact@v4\n with:\n name: rainy-updates-report-node-\${{ matrix.node }}\n path: .artifacts/\n retention-days: 14\n\n - name: Upload SARIF\n uses: github/codeql-action/upload-sarif@v3\n with:\n sarif_file: .artifacts/deps-report-node-\${{ matrix.node }}.sarif\n`;
51
+ let detectedPmInstall = "npm ci";
52
+ let testCmd = "npm test";
53
+ if (packageManager === "pnpm") {
54
+ detectedPmInstall =
55
+ "corepack enable && corepack prepare pnpm@9 --activate && pnpm install --frozen-lockfile";
56
+ testCmd = "pnpm test";
57
+ }
58
+ else if (packageManager === "bun") {
59
+ detectedPmInstall = "bun install";
60
+ testCmd = "bun test";
61
+ }
62
+ return `name: Rainy Updates Enterprise\n\non:\n${scheduleBlock}\n\npermissions:\n contents: read\n security-events: write\n actions: read\n\nconcurrency:\n group: rainy-updates-\${{ github.ref }}\n cancel-in-progress: false\n\njobs:\n dependency-check:\n runs-on: ubuntu-latest\n strategy:\n fail-fast: false\n matrix:\n node: [20, 22]\n steps:\n - name: Checkout\n uses: actions/checkout@v4\n\n - name: Setup Node\n uses: actions/setup-node@v4\n with:\n node-version: \${{ matrix.node }}\n\n - name: Setup Bun\n uses: oven-sh/setup-bun@v1\n\n - name: Install dependencies\n run: ${detectedPmInstall}\n\n - name: Warm cache\n run: bunx --bun @rainy-updates/cli warm-cache --workspace --concurrency 32 --registry-timeout-ms 12000 --registry-retries 4\n\n - name: Generate reviewed decision plan\n run: |\n bunx --bun @rainy-updates/cli ci \\\n --workspace \\\n --mode enterprise \\\n --gate review \\\n --plan-file .artifacts/decision-plan.json \\\n --concurrency 32 \\\n --stream \\\n --registry-timeout-ms 12000 \\\n --registry-retries 4 \\\n --lockfile-mode preserve \\\n --format github \\\n --fail-on minor \\\n --max-updates 50 \\\n --json-file .artifacts/deps-report-node-\${{ matrix.node }}.json \\\n --pr-report-file .artifacts/deps-report-node-\${{ matrix.node }}.md \\\n --sarif-file .artifacts/deps-report-node-\${{ matrix.node }}.sarif \\\n --github-output $GITHUB_OUTPUT\n\n - name: Replay approved plan with verification\n run: |\n bunx --bun @rainy-updates/cli ci \\\n --workspace \\\n --mode enterprise \\\n --gate upgrade \\\n --from-plan .artifacts/decision-plan.json \\\n --verify test \\\n --test-command "${testCmd}" \\\n --verification-report-file .artifacts/verification-node-\${{ matrix.node }}.json\n\n - name: Upload report artifacts\n uses: actions/upload-artifact@v4\n with:\n name: rainy-updates-report-node-\${{ matrix.node }}\n path: .artifacts/\n retention-days: 14\n\n - name: Upload SARIF\n uses: github/codeql-action/upload-sarif@v3\n with:\n sarif_file: .artifacts/deps-report-node-\${{ matrix.node }}.sarif\n`;
59
63
  }
@@ -1,6 +1,6 @@
1
1
  import path from "node:path";
2
- import process from "node:process";
3
2
  import { loadConfig } from "../config/loader.js";
3
+ import { getRuntimeCwd } from "../utils/runtime.js";
4
4
  const DEFAULT_INCLUDE_KINDS = [
5
5
  "dependencies",
6
6
  "devDependencies",
@@ -83,7 +83,7 @@ export async function parseCliArgs(argv) {
83
83
  return { command, options: parseGaArgs(args) };
84
84
  }
85
85
  const base = {
86
- cwd: process.cwd(),
86
+ cwd: getRuntimeCwd(),
87
87
  target: "latest",
88
88
  filter: undefined,
89
89
  reject: undefined,
@@ -122,6 +122,11 @@ export async function parseCliArgs(argv) {
122
122
  interactive: false,
123
123
  showImpact: false,
124
124
  showHomepage: false,
125
+ decisionPlanFile: undefined,
126
+ verify: "none",
127
+ testCommand: undefined,
128
+ verificationReportFile: undefined,
129
+ ciGate: "check",
125
130
  };
126
131
  let force = false;
127
132
  let initCiMode = "enterprise";
@@ -492,6 +497,54 @@ export async function parseCliArgs(argv) {
492
497
  if (current === "--file") {
493
498
  throw new Error("Missing value for --file");
494
499
  }
500
+ if (current === "--plan-file" && next) {
501
+ base.decisionPlanFile = path.resolve(base.cwd, next);
502
+ index += 1;
503
+ continue;
504
+ }
505
+ if (current === "--plan-file") {
506
+ throw new Error("Missing value for --plan-file");
507
+ }
508
+ if (current === "--from-plan" && next) {
509
+ base.decisionPlanFile = path.resolve(base.cwd, next);
510
+ index += 1;
511
+ continue;
512
+ }
513
+ if (current === "--from-plan") {
514
+ throw new Error("Missing value for --from-plan");
515
+ }
516
+ if (current === "--verify" && next) {
517
+ base.verify = ensureVerificationMode(next);
518
+ index += 1;
519
+ continue;
520
+ }
521
+ if (current === "--verify") {
522
+ throw new Error("Missing value for --verify");
523
+ }
524
+ if (current === "--test-command" && next) {
525
+ base.testCommand = next;
526
+ index += 1;
527
+ continue;
528
+ }
529
+ if (current === "--test-command") {
530
+ throw new Error("Missing value for --test-command");
531
+ }
532
+ if (current === "--verification-report-file" && next) {
533
+ base.verificationReportFile = path.resolve(base.cwd, next);
534
+ index += 1;
535
+ continue;
536
+ }
537
+ if (current === "--verification-report-file") {
538
+ throw new Error("Missing value for --verification-report-file");
539
+ }
540
+ if (current === "--gate" && next) {
541
+ base.ciGate = ensureCiGate(next);
542
+ index += 1;
543
+ continue;
544
+ }
545
+ if (current === "--gate") {
546
+ throw new Error("Missing value for --gate");
547
+ }
495
548
  if (current.startsWith("-")) {
496
549
  throw new Error(`Unknown option: ${current}`);
497
550
  }
@@ -526,6 +579,7 @@ export async function parseCliArgs(argv) {
526
579
  install: args.includes("--install") || resolvedConfig.install === true,
527
580
  packageManager: cliPm === "auto" ? (configPm ?? "auto") : cliPm,
528
581
  sync: args.includes("--sync") || resolvedConfig.sync === true,
582
+ fromPlanFile: base.decisionPlanFile,
529
583
  };
530
584
  return { command, options: upgradeOptions };
531
585
  }
@@ -687,16 +741,35 @@ function applyConfig(base, config) {
687
741
  if (typeof config.showHomepage === "boolean") {
688
742
  base.showHomepage = config.showHomepage;
689
743
  }
744
+ if (typeof config.decisionPlanFile === "string") {
745
+ base.decisionPlanFile = path.resolve(base.cwd, config.decisionPlanFile);
746
+ }
747
+ if (typeof config.verify === "string") {
748
+ base.verify = ensureVerificationMode(config.verify);
749
+ }
750
+ if (typeof config.testCommand === "string") {
751
+ base.testCommand = config.testCommand;
752
+ }
753
+ if (typeof config.verificationReportFile === "string") {
754
+ base.verificationReportFile = path.resolve(base.cwd, config.verificationReportFile);
755
+ }
756
+ if (typeof config.ciGate === "string") {
757
+ base.ciGate = ensureCiGate(config.ciGate);
758
+ }
690
759
  }
691
760
  function parsePackageManager(args) {
692
761
  const index = args.indexOf("--pm");
693
762
  if (index === -1)
694
763
  return "auto";
695
764
  const value = args[index + 1] ?? "auto";
696
- if (value === "auto" || value === "npm" || value === "pnpm") {
765
+ if (value === "auto" ||
766
+ value === "bun" ||
767
+ value === "npm" ||
768
+ value === "pnpm" ||
769
+ value === "yarn") {
697
770
  return value;
698
771
  }
699
- throw new Error("--pm must be auto, npm or pnpm");
772
+ throw new Error("--pm must be auto, bun, npm, pnpm or yarn");
700
773
  }
701
774
  function ensureTarget(value) {
702
775
  if (value === "patch" ||
@@ -800,3 +873,21 @@ export function ensureRiskLevel(value) {
800
873
  }
801
874
  throw new Error("--risk must be critical, high, medium or low");
802
875
  }
876
+ function ensureVerificationMode(value) {
877
+ if (value === "none" ||
878
+ value === "install" ||
879
+ value === "test" ||
880
+ value === "install,test") {
881
+ return value;
882
+ }
883
+ throw new Error("--verify must be none, install, test or install,test");
884
+ }
885
+ function ensureCiGate(value) {
886
+ if (value === "check" ||
887
+ value === "doctor" ||
888
+ value === "review" ||
889
+ value === "upgrade") {
890
+ return value;
891
+ }
892
+ throw new Error("--gate must be check, doctor, review or upgrade");
893
+ }
@@ -109,6 +109,9 @@ export function renderReviewResult(review) {
109
109
  }
110
110
  lines.push("");
111
111
  lines.push(`Summary: ${review.summary.updatesFound} updates, riskPackages=${review.summary.riskPackages ?? 0}, securityPackages=${review.summary.securityPackages ?? 0}, peerConflictPackages=${review.summary.peerConflictPackages ?? 0}`);
112
+ if (review.summary.decisionPlan) {
113
+ lines.push(`DecisionPlan: ${review.summary.decisionPlan}`);
114
+ }
112
115
  return lines.join("\n");
113
116
  }
114
117
  function matchesReviewFilters(item, options) {
@@ -69,6 +69,12 @@ export function createSummary(input) {
69
69
  primaryFindingCode: undefined,
70
70
  primaryFindingCategory: undefined,
71
71
  nextActionReason: undefined,
72
+ suggestedCommand: undefined,
73
+ decisionPlan: undefined,
74
+ interactiveSurface: undefined,
75
+ queueFocus: undefined,
76
+ verificationState: "not-run",
77
+ verificationFailures: 0,
72
78
  };
73
79
  }
74
80
  export function finalizeSummary(summary) {
@@ -5,17 +5,25 @@ import { detectPackageManager } from "../pm/detect.js";
5
5
  import { applyRangeStyle, parseVersion, compareVersions } from "../utils/semver.js";
6
6
  import { buildWorkspaceGraph } from "../workspace/graph.js";
7
7
  import { captureLockfileSnapshot, changedLockfiles, validateLockfileMode } from "../utils/lockfile.js";
8
+ import { createSummary, finalizeSummary } from "./summary.js";
9
+ import { readDecisionPlan, selectedUpdatesFromPlan } from "./decision-plan.js";
10
+ import { runVerification } from "./verification.js";
8
11
  export async function upgrade(options) {
9
12
  validateLockfileMode(options.lockfileMode, options.install);
10
13
  const lockfilesBefore = await captureLockfileSnapshot(options.cwd);
11
- const checkResult = await check(options);
14
+ const checkResult = options.fromPlanFile
15
+ ? await createUpgradeResultFromPlan(options)
16
+ : await check(options);
12
17
  if (checkResult.updates.length === 0) {
13
18
  return {
14
19
  ...checkResult,
15
20
  changed: false,
16
21
  };
17
22
  }
18
- await applySelectedUpdates(options, checkResult.updates);
23
+ const selectedUpdates = options.fromPlanFile
24
+ ? checkResult.updates
25
+ : checkResult.updates;
26
+ await applySelectedUpdates(options, selectedUpdates);
19
27
  const lockfileChanges = await changedLockfiles(options.cwd, lockfilesBefore);
20
28
  if (lockfileChanges.length > 0 && (options.lockfileMode === "preserve" || options.lockfileMode === "error")) {
21
29
  throw new Error(`Lockfile changes detected in ${options.lockfileMode} mode: ${lockfileChanges.join(", ")}`);
@@ -23,6 +31,18 @@ export async function upgrade(options) {
23
31
  if (lockfileChanges.length > 0 && options.lockfileMode === "update") {
24
32
  checkResult.warnings.push(`Lockfiles changed: ${lockfileChanges.map((item) => item.split("/").pop()).join(", ")}`);
25
33
  }
34
+ if (options.verify !== "none") {
35
+ const verification = await runVerification(options);
36
+ checkResult.summary.verificationState = verification.passed
37
+ ? "passed"
38
+ : "failed";
39
+ checkResult.summary.verificationFailures = verification.checks.filter((check) => !check.passed).length;
40
+ if (!verification.passed) {
41
+ checkResult.errors.push(...verification.checks
42
+ .filter((check) => !check.passed)
43
+ .map((check) => `Verification failed for ${check.name}: ${check.error ?? check.command}`));
44
+ }
45
+ }
26
46
  return {
27
47
  ...checkResult,
28
48
  changed: true,
@@ -59,6 +79,48 @@ export async function applySelectedUpdates(options, updates) {
59
79
  await installDependencies(options.cwd, options.packageManager, detected);
60
80
  }
61
81
  }
82
+ async function createUpgradeResultFromPlan(options) {
83
+ if (!options.fromPlanFile) {
84
+ throw new Error("Missing decision plan file.");
85
+ }
86
+ const plan = await readDecisionPlan(options.fromPlanFile);
87
+ const packageManager = await detectPackageManager(options.cwd);
88
+ const updates = selectedUpdatesFromPlan(plan);
89
+ const packagePaths = Array.from(new Set(updates.map((update) => update.packagePath))).sort((left, right) => left.localeCompare(right));
90
+ const summary = finalizeSummary(createSummary({
91
+ scannedPackages: packagePaths.length,
92
+ totalDependencies: updates.length,
93
+ checkedDependencies: updates.length,
94
+ updatesFound: updates.length,
95
+ upgraded: 0,
96
+ skipped: 0,
97
+ warmedPackages: 0,
98
+ errors: [],
99
+ warnings: [],
100
+ durations: {
101
+ totalMs: 0,
102
+ discoveryMs: 0,
103
+ registryMs: 0,
104
+ cacheMs: 0,
105
+ },
106
+ }));
107
+ summary.decisionPlan = options.fromPlanFile;
108
+ summary.interactiveSurface = plan.interactiveSurface;
109
+ summary.queueFocus = plan.focus;
110
+ summary.updatesFound = updates.length;
111
+ return {
112
+ projectPath: options.cwd,
113
+ packagePaths,
114
+ packageManager,
115
+ target: plan.target,
116
+ timestamp: new Date().toISOString(),
117
+ summary,
118
+ updates,
119
+ errors: [],
120
+ warnings: [],
121
+ changed: false,
122
+ };
123
+ }
62
124
  function applyWorkspaceSync(manifestsByPath, orderedPaths, localPackageNames, includeKinds, updates) {
63
125
  const desiredByPackage = new Map();
64
126
  for (const update of updates) {
@@ -0,0 +1,2 @@
1
+ import type { UpgradeOptions, VerificationResult } from "../types/index.js";
2
+ export declare function runVerification(options: Pick<UpgradeOptions, "cwd" | "verify" | "testCommand" | "verificationReportFile" | "packageManager">): Promise<VerificationResult>;
@@ -0,0 +1,106 @@
1
+ import { detectPackageManager, resolvePackageManager } from "../pm/detect.js";
2
+ import { installDependencies } from "../pm/install.js";
3
+ import { stableStringify } from "../utils/stable-json.js";
4
+ import { writeFileAtomic } from "../utils/io.js";
5
+ import { readEnv } from "../utils/runtime.js";
6
+ export async function runVerification(options) {
7
+ const mode = options.verify;
8
+ if (mode === "none") {
9
+ const result = {
10
+ mode,
11
+ passed: true,
12
+ checks: [],
13
+ };
14
+ await maybeWriteVerificationReport(options.verificationReportFile, result);
15
+ return result;
16
+ }
17
+ const checks = [];
18
+ const detected = await detectPackageManager(options.cwd);
19
+ if (includesInstall(mode)) {
20
+ checks.push(await runCheck("install", `${resolvePackageManager(options.packageManager, detected)} install`, async () => {
21
+ await installDependencies(options.cwd, options.packageManager, detected);
22
+ }));
23
+ }
24
+ if (includesTest(mode)) {
25
+ const command = options.testCommand ??
26
+ defaultTestCommand(options.packageManager, detected);
27
+ checks.push(await runShellCheck(options.cwd, command));
28
+ }
29
+ const result = {
30
+ mode,
31
+ passed: checks.every((check) => check.passed),
32
+ checks,
33
+ };
34
+ await maybeWriteVerificationReport(options.verificationReportFile, result);
35
+ return result;
36
+ }
37
+ function includesInstall(mode) {
38
+ return mode === "install" || mode === "install,test";
39
+ }
40
+ function includesTest(mode) {
41
+ return mode === "test" || mode === "install,test";
42
+ }
43
+ function defaultTestCommand(packageManager, detected) {
44
+ return `${resolvePackageManager(packageManager, detected, "bun")} test`;
45
+ }
46
+ async function runShellCheck(cwd, command) {
47
+ const startedAt = Date.now();
48
+ try {
49
+ const shell = readEnv("SHELL") || "sh";
50
+ const proc = Bun.spawn([shell, "-lc", command], {
51
+ cwd,
52
+ stdin: "inherit",
53
+ stdout: "inherit",
54
+ stderr: "inherit",
55
+ });
56
+ const exitCode = await proc.exited;
57
+ return {
58
+ name: "test",
59
+ command,
60
+ passed: exitCode === 0,
61
+ exitCode,
62
+ durationMs: Math.max(0, Date.now() - startedAt),
63
+ error: exitCode === 0
64
+ ? undefined
65
+ : `${command} failed with exit code ${exitCode}`,
66
+ };
67
+ }
68
+ catch (error) {
69
+ return {
70
+ name: "test",
71
+ command,
72
+ passed: false,
73
+ exitCode: 1,
74
+ durationMs: Math.max(0, Date.now() - startedAt),
75
+ error: String(error),
76
+ };
77
+ }
78
+ }
79
+ async function runCheck(name, command, action) {
80
+ const startedAt = Date.now();
81
+ try {
82
+ await action();
83
+ return {
84
+ name,
85
+ command,
86
+ passed: true,
87
+ exitCode: 0,
88
+ durationMs: Math.max(0, Date.now() - startedAt),
89
+ };
90
+ }
91
+ catch (error) {
92
+ return {
93
+ name,
94
+ command,
95
+ passed: false,
96
+ exitCode: 1,
97
+ durationMs: Math.max(0, Date.now() - startedAt),
98
+ error: String(error),
99
+ };
100
+ }
101
+ }
102
+ async function maybeWriteVerificationReport(filePath, result) {
103
+ if (!filePath)
104
+ return;
105
+ await writeFileAtomic(filePath, stableStringify(result, 2) + "\n");
106
+ }