@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,16 +1,6 @@
1
- import { createHash } from "node:crypto";
2
- import { promises as fs } from "node:fs";
3
1
  import path from "node:path";
2
+ import { writeFileAtomic } from "../../utils/io.js";
4
3
  const DEFAULT_STORE_NAME = ".rup-snapshots.json";
5
- /**
6
- * Lightweight SQLite-free snapshot store (uses a JSON file in the project root).
7
- *
8
- * Design goals:
9
- * - No extra runtime dependencies (SQLite bindings vary by runtime)
10
- * - Human-readable store file (git-committable if desired)
11
- * - Atomic writes via tmp-rename to prevent corruption
12
- * - Fast: entire store fits in memory for typical use (< 50 snapshots)
13
- */
14
4
  export class SnapshotStore {
15
5
  storePath;
16
6
  entries = [];
@@ -26,8 +16,7 @@ export class SnapshotStore {
26
16
  if (this.loaded)
27
17
  return;
28
18
  try {
29
- const raw = await fs.readFile(this.storePath, "utf8");
30
- const parsed = JSON.parse(raw);
19
+ const parsed = (await Bun.file(this.storePath).json());
31
20
  if (Array.isArray(parsed)) {
32
21
  this.entries = parsed;
33
22
  }
@@ -38,9 +27,7 @@ export class SnapshotStore {
38
27
  this.loaded = true;
39
28
  }
40
29
  async save() {
41
- const tmp = this.storePath + ".tmp";
42
- await fs.writeFile(tmp, JSON.stringify(this.entries, null, 2) + "\n", "utf8");
43
- await fs.rename(tmp, this.storePath);
30
+ await writeFileAtomic(this.storePath, JSON.stringify(this.entries, null, 2) + "\n");
44
31
  }
45
32
  async saveSnapshot(manifests, lockfileHashes, label) {
46
33
  await this.load();
@@ -76,32 +63,30 @@ export class SnapshotStore {
76
63
  return false;
77
64
  }
78
65
  }
79
- /** Captures current package.json and lockfile state for a set of directories. */
80
66
  export async function captureState(packageDirs) {
81
67
  const manifests = {};
82
68
  const lockfileHashes = {};
83
- const LOCKFILES = [
69
+ const lockfiles = [
84
70
  "package-lock.json",
85
71
  "pnpm-lock.yaml",
86
72
  "yarn.lock",
73
+ "bun.lock",
87
74
  "bun.lockb",
88
75
  ];
89
76
  await Promise.all(packageDirs.map(async (dir) => {
90
- // Read package.json
91
77
  try {
92
- const content = await fs.readFile(path.join(dir, "package.json"), "utf8");
93
- manifests[dir] = content;
78
+ manifests[dir] = await Bun.file(path.join(dir, "package.json")).text();
94
79
  }
95
80
  catch {
96
81
  // No package.json — skip
97
82
  }
98
- // Hash the first lockfile found
99
- for (const lf of LOCKFILES) {
83
+ for (const lockfileName of lockfiles) {
84
+ const filePath = path.join(dir, lockfileName);
100
85
  try {
101
- const content = await fs.readFile(path.join(dir, lf));
102
- lockfileHashes[dir] = createHash("sha256")
103
- .update(content)
104
- .digest("hex");
86
+ const file = Bun.file(filePath);
87
+ if (!(await file.exists()))
88
+ continue;
89
+ lockfileHashes[dir] = await hashFile(filePath);
105
90
  break;
106
91
  }
107
92
  catch {
@@ -111,16 +96,11 @@ export async function captureState(packageDirs) {
111
96
  }));
112
97
  return { manifests, lockfileHashes };
113
98
  }
114
- /** Restores package.json files from a snapshot's manifest map. */
115
99
  export async function restoreState(entry) {
116
100
  await Promise.all(Object.entries(entry.manifests).map(async ([dir, content]) => {
117
- const manifestPath = path.join(dir, "package.json");
118
- const tmp = manifestPath + ".tmp";
119
- await fs.writeFile(tmp, content, "utf8");
120
- await fs.rename(tmp, manifestPath);
101
+ await writeFileAtomic(path.join(dir, "package.json"), content);
121
102
  }));
122
103
  }
123
- /** Computes a diff of dependency versions between two manifest snapshots. */
124
104
  export function diffManifests(before, after) {
125
105
  const changes = [];
126
106
  for (const [dir, afterJson] of Object.entries(after)) {
@@ -142,12 +122,15 @@ export function diffManifests(before, after) {
142
122
  "optionalDependencies",
143
123
  ];
144
124
  for (const field of fields) {
145
- const before = beforeManifest[field] ?? {};
146
- const after = afterManifest[field] ?? {};
147
- const allNames = new Set([...Object.keys(before), ...Object.keys(after)]);
125
+ const beforeDeps = beforeManifest[field] ?? {};
126
+ const afterDeps = afterManifest[field] ?? {};
127
+ const allNames = new Set([
128
+ ...Object.keys(beforeDeps),
129
+ ...Object.keys(afterDeps),
130
+ ]);
148
131
  for (const name of allNames) {
149
- const fromVer = before[name] ?? "(removed)";
150
- const toVer = after[name] ?? "(removed)";
132
+ const fromVer = beforeDeps[name] ?? "(removed)";
133
+ const toVer = afterDeps[name] ?? "(removed)";
151
134
  if (fromVer !== toVer) {
152
135
  changes.push({ name, from: fromVer, to: toVer });
153
136
  }
@@ -156,3 +139,8 @@ export function diffManifests(before, after) {
156
139
  }
157
140
  return changes;
158
141
  }
142
+ async function hashFile(filePath) {
143
+ const hasher = new Bun.CryptoHasher("sha256");
144
+ hasher.update(await Bun.file(filePath).bytes());
145
+ return hasher.digest("hex");
146
+ }
@@ -1,9 +1,9 @@
1
1
  import path from "node:path";
2
- import process from "node:process";
3
2
  import { readManifest, } from "../../parsers/package-json.js";
4
3
  import { discoverPackageDirs } from "../../workspace/discover.js";
5
4
  import { writeFileAtomic } from "../../utils/io.js";
6
5
  import { stableStringify } from "../../utils/stable-json.js";
6
+ import { writeStderr, writeStdout } from "../../utils/runtime.js";
7
7
  import { scanDirectory } from "./scanner.js";
8
8
  import { matchDependencies, removeUnusedFromManifest } from "./matcher.js";
9
9
  /**
@@ -60,16 +60,15 @@ export async function runUnused(options) {
60
60
  // ─ Apply fix ─────────────────────────────────────────────────────────────
61
61
  if (options.fix && unused.length > 0) {
62
62
  if (options.dryRun) {
63
- process.stderr.write(`[unused] --dry-run: would remove ${unused.length} unused dep(s) from ${packageDir}/package.json\n`);
63
+ writeStderr(`[unused] --dry-run: would remove ${unused.length} unused dep(s) from ${packageDir}/package.json\n`);
64
64
  }
65
65
  else {
66
66
  try {
67
- const { promises: fs } = await import("node:fs");
68
67
  const manifestPath = path.join(packageDir, "package.json");
69
- const originalJson = await fs.readFile(manifestPath, "utf8");
68
+ const originalJson = await Bun.file(manifestPath).text();
70
69
  const updatedJson = removeUnusedFromManifest(originalJson, unused);
71
70
  await writeFileAtomic(manifestPath, updatedJson);
72
- process.stderr.write(`[unused] Removed ${unused.length} unused dep(s) from ${packageDir}/package.json\n`);
71
+ writeStderr(`[unused] Removed ${unused.length} unused dep(s) from ${packageDir}/package.json\n`);
73
72
  }
74
73
  catch (error) {
75
74
  result.errors.push(`Failed to update package.json in ${packageDir}: ${String(error)}`);
@@ -80,11 +79,11 @@ export async function runUnused(options) {
80
79
  result.totalUnused = result.unused.length;
81
80
  result.totalMissing = result.missing.length;
82
81
  // ─ Render output ─────────────────────────────────────────────────────────
83
- process.stdout.write(renderUnusedTable(result) + "\n");
82
+ writeStdout(renderUnusedTable(result) + "\n");
84
83
  // ─ JSON report ───────────────────────────────────────────────────────────
85
84
  if (options.jsonFile) {
86
85
  await writeFileAtomic(options.jsonFile, stableStringify(result, 2) + "\n");
87
- process.stderr.write(`[unused] JSON report written to ${options.jsonFile}\n`);
86
+ writeStderr(`[unused] JSON report written to ${options.jsonFile}\n`);
88
87
  }
89
88
  return result;
90
89
  }
@@ -93,34 +93,31 @@ export async function scanDirectory(dir) {
93
93
  async function walkDirectory(dir, collector) {
94
94
  let entries;
95
95
  try {
96
- entries = await fs.readdir(dir);
96
+ entries = await fs.readdir(dir, { withFileTypes: true });
97
97
  }
98
98
  catch {
99
99
  return;
100
100
  }
101
101
  const tasks = [];
102
- for (const entryName of entries) {
102
+ for (const entry of entries) {
103
+ const entryName = entry.name;
103
104
  if (IGNORED_DIRS.has(entryName))
104
105
  continue;
105
106
  const fullPath = path.join(dir, entryName);
106
- tasks.push(fs
107
- .stat(fullPath)
108
- .then((stat) => {
109
- if (stat.isDirectory()) {
110
- return walkDirectory(fullPath, collector);
111
- }
112
- if (stat.isFile()) {
113
- const ext = path.extname(entryName).toLowerCase();
114
- if (!SOURCE_EXTENSIONS.has(ext))
115
- return;
116
- return fs
117
- .readFile(fullPath, "utf8")
118
- .then((source) => {
119
- for (const name of extractImportsFromSource(source)) {
120
- collector.add(name);
121
- }
122
- })
123
- .catch(() => undefined);
107
+ if (entry.isDirectory()) {
108
+ tasks.push(walkDirectory(fullPath, collector));
109
+ continue;
110
+ }
111
+ if (!entry.isFile())
112
+ continue;
113
+ const ext = path.extname(entryName).toLowerCase();
114
+ if (!SOURCE_EXTENSIONS.has(ext))
115
+ continue;
116
+ tasks.push(Bun.file(fullPath)
117
+ .text()
118
+ .then((source) => {
119
+ for (const name of extractImportsFromSource(source)) {
120
+ collector.add(name);
124
121
  }
125
122
  })
126
123
  .catch(() => undefined));
@@ -1,4 +1,4 @@
1
- import type { CiProfile, DependencyKind, FailOnLevel, GroupBy, LockfileMode, LogLevel, OutputFormat, TargetLevel } from "../types/index.js";
1
+ import type { CiProfile, SelectedPackageManager, DependencyKind, FailOnLevel, GroupBy, LockfileMode, LogLevel, OutputFormat, TargetLevel } from "../types/index.js";
2
2
  export interface FileConfig {
3
3
  target?: TargetLevel;
4
4
  filter?: string;
@@ -39,7 +39,7 @@ export interface FileConfig {
39
39
  showImpact?: boolean;
40
40
  showHomepage?: boolean;
41
41
  install?: boolean;
42
- packageManager?: "auto" | "npm" | "pnpm";
42
+ packageManager?: SelectedPackageManager;
43
43
  sync?: boolean;
44
44
  }
45
45
  export declare function loadConfig(cwd: string): Promise<FileConfig>;
@@ -1,4 +1,3 @@
1
- import { promises as fs } from "node:fs";
2
1
  import path from "node:path";
3
2
  export async function loadConfig(cwd) {
4
3
  const fromRc = await loadRcFile(cwd);
@@ -13,8 +12,7 @@ async function loadRcFile(cwd) {
13
12
  for (const candidate of candidates) {
14
13
  const filePath = path.join(cwd, candidate);
15
14
  try {
16
- const content = await fs.readFile(filePath, "utf8");
17
- return JSON.parse(content);
15
+ return (await Bun.file(filePath).json());
18
16
  }
19
17
  catch {
20
18
  // noop
@@ -25,8 +23,7 @@ async function loadRcFile(cwd) {
25
23
  async function loadPackageConfig(cwd) {
26
24
  const packagePath = path.join(cwd, "package.json");
27
25
  try {
28
- const content = await fs.readFile(packagePath, "utf8");
29
- const parsed = JSON.parse(content);
26
+ const parsed = (await Bun.file(packagePath).json());
30
27
  return parsed.rainyUpdates ?? {};
31
28
  }
32
29
  catch {
@@ -1,19 +1,24 @@
1
- import { promises as fs } from "node:fs";
2
1
  import path from "node:path";
3
2
  export async function loadPolicy(cwd, policyFile) {
4
- const candidates = policyFile ? [policyFile] : [
5
- path.join(cwd, ".rainyupdates-policy.json"),
6
- path.join(cwd, "rainy-updates.policy.json"),
7
- ];
3
+ const candidates = policyFile
4
+ ? [policyFile]
5
+ : [
6
+ path.join(cwd, ".rainyupdates-policy.json"),
7
+ path.join(cwd, "rainy-updates.policy.json"),
8
+ ];
8
9
  for (const candidate of candidates) {
9
- const filePath = path.isAbsolute(candidate) ? candidate : path.resolve(cwd, candidate);
10
+ const filePath = path.isAbsolute(candidate)
11
+ ? candidate
12
+ : path.resolve(cwd, candidate);
10
13
  try {
11
- const content = await fs.readFile(filePath, "utf8");
12
- const parsed = JSON.parse(content);
14
+ const parsed = (await Bun.file(filePath).json());
13
15
  return {
14
16
  ignorePatterns: parsed.ignore ?? [],
15
17
  cooldownDays: asNonNegativeInt(parsed.cooldownDays),
16
- packageRules: new Map(Object.entries(parsed.packageRules ?? {}).map(([pkg, rule]) => [pkg, normalizeRule(rule)])),
18
+ packageRules: new Map(Object.entries(parsed.packageRules ?? {}).map(([pkg, rule]) => [
19
+ pkg,
20
+ normalizeRule(rule),
21
+ ])),
17
22
  matchRules: Object.values(parsed.packageRules ?? {})
18
23
  .map((rule) => normalizeRule(rule))
19
24
  .filter((rule) => typeof rule.match === "string" && rule.match.length > 0),
@@ -44,7 +49,9 @@ function normalizeRule(rule) {
44
49
  maxUpdatesPerRun: asNonNegativeInt(rule.maxUpdatesPerRun),
45
50
  cooldownDays: asNonNegativeInt(rule.cooldownDays),
46
51
  allowPrerelease: rule.allowPrerelease === true,
47
- group: typeof rule.group === "string" && rule.group.trim().length > 0 ? rule.group.trim() : undefined,
52
+ group: typeof rule.group === "string" && rule.group.trim().length > 0
53
+ ? rule.group.trim()
54
+ : undefined,
48
55
  priority: asNonNegativeInt(rule.priority),
49
56
  target: rule.target,
50
57
  autofix: rule.autofix !== false,
@@ -60,7 +67,9 @@ function matchesPattern(value, pattern) {
60
67
  return false;
61
68
  if (pattern === "*")
62
69
  return true;
63
- const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
70
+ const escaped = pattern
71
+ .replace(/[.+^${}()|[\]\\]/g, "\\$&")
72
+ .replace(/\*/g, ".*");
64
73
  const regex = new RegExp(`^${escaped}$`);
65
74
  return regex.test(value);
66
75
  }
@@ -1,4 +1,3 @@
1
- import process from "node:process";
2
1
  export async function runSilenced(fn) {
3
2
  const stdoutWrite = process.stdout.write.bind(process.stdout);
4
3
  const stderrWrite = process.stderr.write.bind(process.stderr);
@@ -1,10 +1,9 @@
1
- import crypto from "node:crypto";
2
1
  import path from "node:path";
3
2
  import { stableStringify } from "../utils/stable-json.js";
4
3
  import { writeFileAtomic } from "../utils/io.js";
5
4
  export function createRunId(command, options, result) {
6
- const hash = crypto.createHash("sha256");
7
- hash.update(stableStringify({
5
+ const hasher = new Bun.CryptoHasher("sha256");
6
+ hasher.update(stableStringify({
8
7
  command,
9
8
  cwd: path.resolve(options.cwd),
10
9
  target: options.target,
@@ -17,14 +16,15 @@ export function createRunId(command, options, result) {
17
16
  toRange: update.toRange,
18
17
  })),
19
18
  }, 0));
20
- return hash.digest("hex").slice(0, 16);
19
+ return hasher.digest("hex").slice(0, 16);
21
20
  }
22
21
  export async function writeArtifactManifest(command, options, result) {
23
22
  const shouldWrite = options.ci ||
24
23
  Boolean(options.jsonFile) ||
25
24
  Boolean(options.githubOutputFile) ||
26
25
  Boolean(options.sarifFile) ||
27
- Boolean(options.prReportFile);
26
+ Boolean(options.prReportFile) ||
27
+ Boolean(options.verificationReportFile);
28
28
  if (!shouldWrite)
29
29
  return null;
30
30
  const runId = result.summary.runId ?? createRunId(command, options, result);
@@ -41,6 +41,7 @@ export async function writeArtifactManifest(command, options, result) {
41
41
  githubOutputFile: options.githubOutputFile,
42
42
  sarifFile: options.sarifFile,
43
43
  prReportFile: options.prReportFile,
44
+ verificationReportFile: options.verificationReportFile,
44
45
  },
45
46
  };
46
47
  await writeFileAtomic(artifactManifestPath, stableStringify(manifest, 2) + "\n");
@@ -1,6 +1,6 @@
1
- import { promises as fs } from "node:fs";
2
1
  import path from "node:path";
3
2
  import { collectDependencies, readManifest } from "../parsers/package-json.js";
3
+ import { writeFileAtomic } from "../utils/io.js";
4
4
  import { discoverPackageDirs } from "../workspace/discover.js";
5
5
  export async function saveBaseline(options) {
6
6
  const entries = await collectBaselineEntries(options.cwd, options.workspace, options.includeKinds);
@@ -9,16 +9,14 @@ export async function saveBaseline(options) {
9
9
  createdAt: new Date().toISOString(),
10
10
  entries,
11
11
  };
12
- await fs.mkdir(path.dirname(options.filePath), { recursive: true });
13
- await fs.writeFile(options.filePath, JSON.stringify(payload, null, 2) + "\n", "utf8");
12
+ await writeFileAtomic(options.filePath, JSON.stringify(payload, null, 2) + "\n");
14
13
  return {
15
14
  filePath: options.filePath,
16
15
  entries: entries.length,
17
16
  };
18
17
  }
19
18
  export async function diffBaseline(options) {
20
- const content = await fs.readFile(options.filePath, "utf8");
21
- const baseline = JSON.parse(content);
19
+ const baseline = (await Bun.file(options.filePath).json());
22
20
  const currentEntries = await collectBaselineEntries(options.cwd, options.workspace, options.includeKinds);
23
21
  const baselineMap = new Map(baseline.entries.map((entry) => [toKey(entry), entry]));
24
22
  const currentMap = new Map(currentEntries.map((entry) => [toKey(entry), entry]));
@@ -1,5 +1,4 @@
1
1
  import path from "node:path";
2
- import process from "node:process";
3
2
  import { collectDependencies, readManifest } from "../parsers/package-json.js";
4
3
  import { matchesPattern } from "../utils/pattern.js";
5
4
  import { applyRangeStyle, classifyDiff, clampTarget, pickTargetVersionFromAvailable } from "../utils/semver.js";
@@ -11,6 +10,7 @@ import { loadPolicy, resolvePolicyRule } from "../config/policy.js";
11
10
  import { createSummary, finalizeSummary } from "./summary.js";
12
11
  import { applyImpactScores } from "./impact.js";
13
12
  import { formatClassifiedMessage } from "./errors.js";
13
+ import { writeStdout } from "../utils/runtime.js";
14
14
  export async function check(options) {
15
15
  const startedAt = Date.now();
16
16
  let discoveryMs = 0;
@@ -48,7 +48,7 @@ export async function check(options) {
48
48
  if (!options.stream)
49
49
  return;
50
50
  streamedEvents += 1;
51
- process.stdout.write(`${message}\n`);
51
+ writeStdout(`${message}\n`);
52
52
  };
53
53
  for (const packageDir of packageDirs) {
54
54
  let manifest;
package/dist/core/ci.js CHANGED
@@ -1,5 +1,8 @@
1
1
  import { check } from "./check.js";
2
2
  import { warmCache } from "./warm-cache.js";
3
+ import { buildReviewResult, createDoctorResult } from "./review-model.js";
4
+ import { createDecisionPlan, defaultDecisionPlanPath, writeDecisionPlan, } from "./decision-plan.js";
5
+ import { upgrade } from "./upgrade.js";
3
6
  export async function runCi(options) {
4
7
  const profile = options.ciProfile;
5
8
  if (profile !== "minimal") {
@@ -16,5 +19,53 @@ export async function runCi(options) {
16
19
  offline: profile === "minimal" ? options.offline : true,
17
20
  concurrency: profile === "enterprise" ? Math.max(options.concurrency, 32) : options.concurrency,
18
21
  };
19
- return await check(checkOptions);
22
+ if (options.ciGate === "check") {
23
+ return await check(checkOptions);
24
+ }
25
+ if (options.ciGate === "doctor") {
26
+ const review = await buildReviewResult(checkOptions);
27
+ createDoctorResult(review);
28
+ return reviewToCheckResult(review);
29
+ }
30
+ if (options.ciGate === "review") {
31
+ const review = await buildReviewResult(checkOptions);
32
+ const selectedItems = review.items.filter((item) => item.update.selectedByDefault !== false &&
33
+ item.update.decisionState !== "blocked");
34
+ const decisionPlanFile = options.decisionPlanFile ?? defaultDecisionPlanPath(options.cwd);
35
+ const plan = createDecisionPlan({
36
+ review,
37
+ selectedItems,
38
+ sourceCommand: "ci",
39
+ mode: "review",
40
+ focus: "all",
41
+ });
42
+ await writeDecisionPlan(decisionPlanFile, plan);
43
+ review.decisionPlan = plan;
44
+ review.summary.decisionPlan = decisionPlanFile;
45
+ review.summary.interactiveSurface = "dashboard";
46
+ review.summary.queueFocus = "all";
47
+ review.summary.suggestedCommand = `rup upgrade --from-plan ${decisionPlanFile}`;
48
+ return reviewToCheckResult(review);
49
+ }
50
+ const decisionPlanFile = options.decisionPlanFile ?? defaultDecisionPlanPath(options.cwd);
51
+ return upgrade({
52
+ ...checkOptions,
53
+ install: false,
54
+ packageManager: "auto",
55
+ sync: checkOptions.workspace,
56
+ fromPlanFile: decisionPlanFile,
57
+ });
58
+ }
59
+ function reviewToCheckResult(review) {
60
+ return {
61
+ projectPath: review.projectPath,
62
+ packagePaths: review.analysis.check.packagePaths,
63
+ packageManager: review.analysis.check.packageManager,
64
+ target: review.target,
65
+ timestamp: review.analysis.check.timestamp,
66
+ summary: review.summary,
67
+ updates: review.updates,
68
+ errors: review.errors,
69
+ warnings: review.warnings,
70
+ };
20
71
  }
@@ -0,0 +1,14 @@
1
+ import type { DashboardMode, DecisionPlan, PackageUpdate, QueueFocus, ReviewItem, ReviewResult, UpgradeOptions } from "../types/index.js";
2
+ export declare function defaultDecisionPlanPath(cwd: string): string;
3
+ export declare function filterReviewItemsByFocus(items: ReviewItem[], focus: QueueFocus): ReviewItem[];
4
+ export declare function createDecisionPlan(input: {
5
+ review: ReviewResult;
6
+ selectedItems: ReviewItem[];
7
+ sourceCommand: string;
8
+ mode: DashboardMode;
9
+ focus: QueueFocus;
10
+ }): DecisionPlan;
11
+ export declare function writeDecisionPlan(filePath: string, plan: DecisionPlan): Promise<void>;
12
+ export declare function readDecisionPlan(filePath: string): Promise<DecisionPlan>;
13
+ export declare function selectedUpdatesFromPlan(plan: DecisionPlan): PackageUpdate[];
14
+ export declare function resolveDecisionPlanPath(options: Pick<UpgradeOptions, "cwd" | "decisionPlanFile">, explicit?: string): string;
@@ -0,0 +1,107 @@
1
+ import path from "node:path";
2
+ import { stableStringify } from "../utils/stable-json.js";
3
+ import { writeFileAtomic } from "../utils/io.js";
4
+ export function defaultDecisionPlanPath(cwd) {
5
+ return path.resolve(cwd, ".artifacts/decision-plan.json");
6
+ }
7
+ export function filterReviewItemsByFocus(items, focus) {
8
+ if (focus === "security") {
9
+ return items.filter((item) => item.advisories.length > 0);
10
+ }
11
+ if (focus === "risk") {
12
+ return items.filter((item) => item.update.riskLevel === "critical" ||
13
+ item.update.riskLevel === "high");
14
+ }
15
+ if (focus === "major") {
16
+ return items.filter((item) => item.update.diffType === "major");
17
+ }
18
+ if (focus === "blocked") {
19
+ return items.filter((item) => item.update.decisionState === "blocked");
20
+ }
21
+ if (focus === "workspace") {
22
+ return items.filter((item) => Boolean(item.update.workspaceGroup));
23
+ }
24
+ return items;
25
+ }
26
+ export function createDecisionPlan(input) {
27
+ const selectedKeys = new Set(input.selectedItems.map((item) => packageUpdateKey(item.update)));
28
+ const items = input.review.items.map((item) => ({
29
+ ...toDecisionPlanItem(item.update),
30
+ selected: selectedKeys.has(packageUpdateKey(item.update)),
31
+ }));
32
+ return {
33
+ contractVersion: "1",
34
+ createdAt: new Date().toISOString(),
35
+ sourceCommand: input.sourceCommand,
36
+ mode: input.mode,
37
+ focus: input.focus,
38
+ projectPath: input.review.projectPath,
39
+ target: input.review.target,
40
+ interactiveSurface: "dashboard",
41
+ summary: {
42
+ totalItems: items.length,
43
+ selectedItems: items.filter((item) => item.selected).length,
44
+ },
45
+ items,
46
+ };
47
+ }
48
+ export async function writeDecisionPlan(filePath, plan) {
49
+ await writeFileAtomic(filePath, stableStringify(plan, 2) + "\n");
50
+ }
51
+ export async function readDecisionPlan(filePath) {
52
+ const parsed = (await Bun.file(filePath).json());
53
+ if (parsed.contractVersion !== "1" ||
54
+ !Array.isArray(parsed.items) ||
55
+ typeof parsed.projectPath !== "string") {
56
+ throw new Error(`Invalid decision plan: ${filePath}`);
57
+ }
58
+ return parsed;
59
+ }
60
+ export function selectedUpdatesFromPlan(plan) {
61
+ return plan.items.filter((item) => item.selected).map(toPackageUpdate);
62
+ }
63
+ export function resolveDecisionPlanPath(options, explicit) {
64
+ return (explicit ?? options.decisionPlanFile ?? defaultDecisionPlanPath(options.cwd));
65
+ }
66
+ function toDecisionPlanItem(update) {
67
+ return {
68
+ packagePath: update.packagePath,
69
+ name: update.name,
70
+ kind: update.kind,
71
+ fromRange: update.fromRange,
72
+ toRange: update.toRange,
73
+ toVersionResolved: update.toVersionResolved,
74
+ diffType: update.diffType,
75
+ riskLevel: update.riskLevel,
76
+ riskScore: update.riskScore,
77
+ policyAction: update.policyAction,
78
+ decisionState: update.decisionState,
79
+ selected: true,
80
+ };
81
+ }
82
+ function toPackageUpdate(item) {
83
+ return {
84
+ packagePath: item.packagePath,
85
+ name: item.name,
86
+ kind: item.kind,
87
+ fromRange: item.fromRange,
88
+ toRange: item.toRange,
89
+ toVersionResolved: item.toVersionResolved,
90
+ diffType: item.diffType,
91
+ filtered: false,
92
+ autofix: true,
93
+ riskLevel: item.riskLevel,
94
+ riskScore: item.riskScore,
95
+ policyAction: item.policyAction,
96
+ decisionState: item.decisionState,
97
+ };
98
+ }
99
+ function packageUpdateKey(update) {
100
+ return [
101
+ update.packagePath,
102
+ update.kind,
103
+ update.name,
104
+ update.fromRange,
105
+ update.toRange,
106
+ ].join("::");
107
+ }
@@ -17,6 +17,7 @@ export function createDoctorResult(review) {
17
17
  review.summary.primaryFindingCode = findings[0]?.code;
18
18
  review.summary.primaryFindingCategory = findings[0]?.category;
19
19
  review.summary.nextActionReason = nextActionReason;
20
+ review.summary.suggestedCommand = recommendedCommand;
20
21
  return {
21
22
  verdict,
22
23
  score,
@@ -31,11 +32,13 @@ export function createDoctorResult(review) {
31
32
  }
32
33
  function recommendDoctorCommand(review, verdict) {
33
34
  if (verdict === "blocked")
34
- return "rup review --interactive";
35
- if ((review.summary.securityPackages ?? 0) > 0)
36
- return "rup review --security-only";
37
- if (review.errors.length > 0 || review.items.length > 0)
38
- return "rup review --interactive";
35
+ return "rup dashboard --mode review --focus blocked";
36
+ if ((review.summary.securityPackages ?? 0) > 0) {
37
+ return "rup dashboard --mode review --focus security";
38
+ }
39
+ if (review.errors.length > 0 || review.items.length > 0) {
40
+ return "rup dashboard --mode review";
41
+ }
39
42
  return "rup check";
40
43
  }
41
44
  function describeNextActionReason(review, verdict) {