sentinelayer-cli 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/README.md +23 -2
  2. package/package.json +4 -4
  3. package/src/agents/ai-governance/index.js +12 -0
  4. package/src/agents/ai-governance/tools/base.js +171 -0
  5. package/src/agents/ai-governance/tools/eval-regression.js +47 -0
  6. package/src/agents/ai-governance/tools/hitl-audit.js +81 -0
  7. package/src/agents/ai-governance/tools/index.js +52 -0
  8. package/src/agents/ai-governance/tools/prompt-drift.js +42 -0
  9. package/src/agents/ai-governance/tools/provenance-check.js +69 -0
  10. package/src/agents/backend/index.js +12 -0
  11. package/src/agents/backend/tools/base.js +189 -0
  12. package/src/agents/backend/tools/circuit-breaker-check.js +123 -0
  13. package/src/agents/backend/tools/idempotency-audit.js +105 -0
  14. package/src/agents/backend/tools/index.js +87 -0
  15. package/src/agents/backend/tools/retry-audit.js +132 -0
  16. package/src/agents/backend/tools/timeout-audit.js +144 -0
  17. package/src/agents/code-quality/index.js +12 -0
  18. package/src/agents/code-quality/tools/base.js +159 -0
  19. package/src/agents/code-quality/tools/complexity-measure.js +197 -0
  20. package/src/agents/code-quality/tools/coupling-analysis.js +81 -0
  21. package/src/agents/code-quality/tools/cycle-detect.js +49 -0
  22. package/src/agents/code-quality/tools/dep-graph.js +196 -0
  23. package/src/agents/code-quality/tools/index.js +89 -0
  24. package/src/agents/data-layer/index.js +12 -0
  25. package/src/agents/data-layer/tools/base.js +181 -0
  26. package/src/agents/data-layer/tools/index-audit.js +165 -0
  27. package/src/agents/data-layer/tools/index.js +83 -0
  28. package/src/agents/data-layer/tools/migration-scan.js +135 -0
  29. package/src/agents/data-layer/tools/query-explain.js +120 -0
  30. package/src/agents/data-layer/tools/tenancy-scan.js +166 -0
  31. package/src/agents/documentation/index.js +12 -0
  32. package/src/agents/documentation/tools/api-diff.js +91 -0
  33. package/src/agents/documentation/tools/base.js +151 -0
  34. package/src/agents/documentation/tools/dead-link-check.js +58 -0
  35. package/src/agents/documentation/tools/docstring-coverage.js +78 -0
  36. package/src/agents/documentation/tools/index.js +52 -0
  37. package/src/agents/documentation/tools/readme-freshness.js +61 -0
  38. package/src/agents/envelope/fix-cycle.js +45 -0
  39. package/src/agents/envelope/index.js +31 -0
  40. package/src/agents/envelope/loop.js +150 -0
  41. package/src/agents/envelope/pulse.js +18 -0
  42. package/src/agents/envelope/stream.js +40 -0
  43. package/src/agents/infrastructure/index.js +12 -0
  44. package/src/agents/infrastructure/tools/base.js +171 -0
  45. package/src/agents/infrastructure/tools/checkov-run.js +32 -0
  46. package/src/agents/infrastructure/tools/drift-detect.js +59 -0
  47. package/src/agents/infrastructure/tools/iam-least-priv-check.js +78 -0
  48. package/src/agents/infrastructure/tools/index.js +52 -0
  49. package/src/agents/infrastructure/tools/tflint-run.js +31 -0
  50. package/src/agents/jules/loop.js +7 -4
  51. package/src/agents/jules/swarm/sub-agent.js +5 -1
  52. package/src/agents/jules/tools/auth-audit.js +10 -1
  53. package/src/agents/mode.js +113 -0
  54. package/src/agents/observability/index.js +12 -0
  55. package/src/agents/observability/tools/alert-audit.js +39 -0
  56. package/src/agents/observability/tools/base.js +181 -0
  57. package/src/agents/observability/tools/dashboard-gap.js +42 -0
  58. package/src/agents/observability/tools/index.js +54 -0
  59. package/src/agents/observability/tools/log-schema-check.js +74 -0
  60. package/src/agents/observability/tools/span-coverage.js +74 -0
  61. package/src/agents/persona-visuals.js +38 -0
  62. package/src/agents/release/index.js +12 -0
  63. package/src/agents/release/tools/base.js +181 -0
  64. package/src/agents/release/tools/changelog-diff.js +86 -0
  65. package/src/agents/release/tools/feature-flag-audit.js +126 -0
  66. package/src/agents/release/tools/index.js +61 -0
  67. package/src/agents/release/tools/rollback-verify.js +129 -0
  68. package/src/agents/release/tools/semver-check.js +109 -0
  69. package/src/agents/reliability/index.js +12 -0
  70. package/src/agents/reliability/tools/backpressure-check.js +129 -0
  71. package/src/agents/reliability/tools/base.js +181 -0
  72. package/src/agents/reliability/tools/chaos-probe.js +109 -0
  73. package/src/agents/reliability/tools/graceful-degradation-check.js +114 -0
  74. package/src/agents/reliability/tools/health-check-audit.js +111 -0
  75. package/src/agents/reliability/tools/index.js +87 -0
  76. package/src/agents/run-persona.js +109 -0
  77. package/src/agents/security/index.js +12 -0
  78. package/src/agents/security/tools/authz-audit.js +134 -0
  79. package/src/agents/security/tools/base.js +190 -0
  80. package/src/agents/security/tools/crypto-review.js +175 -0
  81. package/src/agents/security/tools/index.js +97 -0
  82. package/src/agents/security/tools/sast-scan.js +175 -0
  83. package/src/agents/security/tools/secrets-scan.js +216 -0
  84. package/src/agents/supply-chain/index.js +12 -0
  85. package/src/agents/supply-chain/tools/attestation-check.js +42 -0
  86. package/src/agents/supply-chain/tools/base.js +151 -0
  87. package/src/agents/supply-chain/tools/index.js +52 -0
  88. package/src/agents/supply-chain/tools/lockfile-integrity.js +73 -0
  89. package/src/agents/supply-chain/tools/package-verify.js +56 -0
  90. package/src/agents/supply-chain/tools/sbom-diff.js +34 -0
  91. package/src/agents/testing/index.js +12 -0
  92. package/src/agents/testing/tools/base.js +202 -0
  93. package/src/agents/testing/tools/coverage-gap.js +144 -0
  94. package/src/agents/testing/tools/flake-detect.js +125 -0
  95. package/src/agents/testing/tools/index.js +85 -0
  96. package/src/agents/testing/tools/mutation-test.js +143 -0
  97. package/src/agents/testing/tools/snapshot-diff.js +103 -0
  98. package/src/auth/gate.js +65 -37
  99. package/src/cli.js +1 -1
  100. package/src/commands/chat.js +3 -10
  101. package/src/commands/legacy-args.js +10 -0
  102. package/src/commands/omargate.js +36 -2
  103. package/src/commands/persona.js +46 -1
  104. package/src/commands/scan.js +3 -10
  105. package/src/commands/session.js +654 -6
  106. package/src/commands/spec.js +3 -10
  107. package/src/coord/events-log.js +141 -0
  108. package/src/coord/handshake.js +719 -0
  109. package/src/coord/index.js +35 -0
  110. package/src/coord/paths.js +84 -0
  111. package/src/coord/priority.js +62 -0
  112. package/src/coord/tarjan.js +157 -0
  113. package/src/cost/tokenizer.js +160 -0
  114. package/src/cost/tracker.js +61 -0
  115. package/src/daemon/artifact-lineage.js +362 -0
  116. package/src/daemon/assignment-ledger.js +117 -0
  117. package/src/daemon/ast-drift.js +496 -0
  118. package/src/daemon/ingest-refresh.js +69 -2
  119. package/src/ingest/engine.js +15 -0
  120. package/src/ingest/ownership.js +380 -0
  121. package/src/legacy-cli.js +68 -1
  122. package/src/orchestrator/kai-chen.js +126 -0
  123. package/src/review/ai-review.js +3 -10
  124. package/src/review/compliance-pack.js +389 -0
  125. package/src/review/investor-dd-config.js +54 -0
  126. package/src/review/investor-dd-file-loop.js +303 -0
  127. package/src/review/investor-dd-file-router.js +406 -0
  128. package/src/review/investor-dd-html-report.js +233 -0
  129. package/src/review/investor-dd-notification.js +120 -0
  130. package/src/review/investor-dd-orchestrator.js +405 -0
  131. package/src/review/investor-dd-persona-runner.js +275 -0
  132. package/src/review/live-validator.js +253 -0
  133. package/src/review/omargate-orchestrator.js +90 -2
  134. package/src/review/persona-prompts.js +244 -56
  135. package/src/review/reconciliation-rules.js +329 -0
  136. package/src/review/reproducibility-chain.js +136 -0
  137. package/src/review/scan-modes.js +102 -3
  138. package/src/session/agent-registry.js +7 -0
  139. package/src/session/analytics.js +479 -0
  140. package/src/session/daemon.js +609 -14
  141. package/src/session/file-locks.js +666 -0
  142. package/src/session/paths.js +4 -0
  143. package/src/session/recap.js +567 -0
  144. package/src/session/redact.js +82 -0
  145. package/src/session/runtime-bridge.js +24 -1
  146. package/src/session/scoring.js +406 -0
  147. package/src/session/setup-guides.js +304 -0
  148. package/src/session/store.js +318 -2
  149. package/src/session/stream.js +9 -1
  150. package/src/session/sync.js +753 -0
  151. package/src/session/tasks.js +1054 -0
  152. package/src/session/templates.js +188 -0
  153. package/src/swarm/runtime.js +1 -8
@@ -0,0 +1,181 @@
1
+ // Shared helpers for Omar's (release) domain tools (#A19).
2
+
3
+ import fsp from "node:fs/promises";
4
+ import path from "node:path";
5
+ import process from "node:process";
6
+
7
+ import ignore from "ignore";
8
+
9
+ const DEFAULT_IGNORED_DIRS = new Set([
10
+ ".git",
11
+ "node_modules",
12
+ ".venv",
13
+ ".next",
14
+ "dist",
15
+ "build",
16
+ "coverage",
17
+ ".sentinelayer",
18
+ ".sentinel",
19
+ ".turbo",
20
+ ".idea",
21
+ ".vscode",
22
+ "__pycache__",
23
+ ".cache",
24
+ ]);
25
+ const MAX_FILE_SIZE_BYTES = 1024 * 1024;
26
+ const SEVERITIES = Object.freeze(["P0", "P1", "P2", "P3"]);
27
+
28
+ export function toPosix(value) {
29
+ return String(value || "").replace(/\\/g, "/");
30
+ }
31
+
32
+ export function normalizeSeverity(value) {
33
+ const normalized = String(value || "").trim().toUpperCase();
34
+ if (SEVERITIES.includes(normalized)) {
35
+ return normalized;
36
+ }
37
+ return "P2";
38
+ }
39
+
40
+ export function createFinding({
41
+ severity,
42
+ kind,
43
+ file,
44
+ line = 0,
45
+ evidence = "",
46
+ rootCause = "",
47
+ recommendedFix = "",
48
+ confidence = null,
49
+ tool = "",
50
+ persona = "release",
51
+ } = {}) {
52
+ return {
53
+ persona,
54
+ tool: String(tool || "").trim(),
55
+ kind: String(kind || "").trim() || "release",
56
+ severity: normalizeSeverity(severity),
57
+ file: toPosix(file || ""),
58
+ line: Number.isFinite(Number(line)) ? Math.max(0, Math.floor(Number(line))) : 0,
59
+ evidence: String(evidence || "").trim().slice(0, 400),
60
+ rootCause: String(rootCause || "").trim(),
61
+ recommendedFix: String(recommendedFix || "").trim(),
62
+ confidence:
63
+ confidence === null || confidence === undefined
64
+ ? null
65
+ : Math.max(0, Math.min(1, Number(confidence) || 0)),
66
+ };
67
+ }
68
+
69
+ async function readIgnorePatterns(filePath) {
70
+ try {
71
+ const raw = await fsp.readFile(filePath, "utf-8");
72
+ return String(raw || "")
73
+ .split(/\r?\n/)
74
+ .map((line) => line.trim())
75
+ .filter((line) => line && !line.startsWith("#"));
76
+ } catch (err) {
77
+ if (err && typeof err === "object" && err.code === "ENOENT") {
78
+ return [];
79
+ }
80
+ throw err;
81
+ }
82
+ }
83
+
84
+ async function createIgnoreMatcher(rootPath) {
85
+ const matcher = ignore();
86
+ const gitignore = await readIgnorePatterns(path.join(rootPath, ".gitignore"));
87
+ const sentinel = await readIgnorePatterns(
88
+ path.join(rootPath, ".sentinelayerignore")
89
+ );
90
+ matcher.add([...gitignore, ...sentinel]);
91
+ return (relativePath, isDirectory) => {
92
+ const normalized = toPosix(relativePath);
93
+ if (!normalized) {
94
+ return false;
95
+ }
96
+ const candidate = isDirectory ? `${normalized}/` : normalized;
97
+ return matcher.ignores(candidate);
98
+ };
99
+ }
100
+
101
+ export async function* walkRepoFiles({
102
+ rootPath = process.cwd(),
103
+ extensions = new Set(),
104
+ maxFileSize = MAX_FILE_SIZE_BYTES,
105
+ } = {}) {
106
+ const resolvedRoot = path.resolve(rootPath);
107
+ const ignoreMatcher = await createIgnoreMatcher(resolvedRoot);
108
+ const wantedExtensions =
109
+ extensions instanceof Set
110
+ ? extensions
111
+ : new Set(Array.isArray(extensions) ? extensions : []);
112
+ const stack = [resolvedRoot];
113
+ while (stack.length > 0) {
114
+ const current = stack.pop();
115
+ let entries = [];
116
+ try {
117
+ entries = await fsp.readdir(current, { withFileTypes: true });
118
+ } catch {
119
+ continue;
120
+ }
121
+ for (const entry of entries) {
122
+ const fullPath = path.join(current, entry.name);
123
+ const relativePath = toPosix(path.relative(resolvedRoot, fullPath));
124
+ if (entry.isDirectory()) {
125
+ if (!relativePath || DEFAULT_IGNORED_DIRS.has(entry.name)) {
126
+ continue;
127
+ }
128
+ if (ignoreMatcher(relativePath, true)) {
129
+ continue;
130
+ }
131
+ stack.push(fullPath);
132
+ continue;
133
+ }
134
+ if (!entry.isFile()) {
135
+ continue;
136
+ }
137
+ if (ignoreMatcher(relativePath, false)) {
138
+ continue;
139
+ }
140
+ const ext = path.extname(entry.name).toLowerCase();
141
+ if (wantedExtensions.size > 0 && !wantedExtensions.has(ext) && !wantedExtensions.has("")) {
142
+ continue;
143
+ }
144
+ let stat = null;
145
+ try {
146
+ stat = await fsp.stat(fullPath);
147
+ } catch {
148
+ stat = null;
149
+ }
150
+ if (!stat || stat.size > maxFileSize) {
151
+ continue;
152
+ }
153
+ yield { fullPath, relativePath, stat };
154
+ }
155
+ }
156
+ }
157
+
158
+ export function findLineMatches(content, pattern) {
159
+ const text = String(content || "");
160
+ if (!pattern) {
161
+ return [];
162
+ }
163
+ const global = new RegExp(
164
+ pattern.source,
165
+ pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`
166
+ );
167
+ const matches = [];
168
+ let match;
169
+ while ((match = global.exec(text)) !== null) {
170
+ const lineIndex = text.slice(0, match.index).split(/\r?\n/).length;
171
+ matches.push({ index: match.index, line: lineIndex, match: match[0] });
172
+ }
173
+ return matches;
174
+ }
175
+
176
+ export function getLineContent(content, line) {
177
+ const lines = String(content || "").split(/\r?\n/);
178
+ return (lines[Math.max(0, (Number(line) || 1) - 1)] || "").trim();
179
+ }
180
+
181
+ export { DEFAULT_IGNORED_DIRS, MAX_FILE_SIZE_BYTES, SEVERITIES };
@@ -0,0 +1,86 @@
1
+ // changelog-diff — verify the changelog has an entry for the current version (#A19).
2
+
3
+ import fsp from "node:fs/promises";
4
+ import path from "node:path";
5
+
6
+ import { createFinding, toPosix, walkRepoFiles } from "./base.js";
7
+
8
+ export async function runChangelogDiff({ rootPath, files = null } = {}) {
9
+ const resolvedRoot = path.resolve(String(rootPath || "."));
10
+ const iterator =
11
+ Array.isArray(files) && files.length > 0
12
+ ? iterateExplicitFiles(resolvedRoot, files)
13
+ : walkRepoFiles({ rootPath: resolvedRoot, extensions: new Set([".json"]) });
14
+
15
+ const findings = [];
16
+ for await (const { fullPath, relativePath } of iterator) {
17
+ if (!/(^|\/)package\.json$/.test(toPosix(relativePath))) {
18
+ continue;
19
+ }
20
+ let raw;
21
+ try {
22
+ raw = await fsp.readFile(fullPath, "utf-8");
23
+ } catch {
24
+ continue;
25
+ }
26
+ let parsed;
27
+ try {
28
+ parsed = JSON.parse(raw);
29
+ } catch {
30
+ continue;
31
+ }
32
+ if (!parsed?.version || parsed.private === true) {
33
+ continue;
34
+ }
35
+ const dir = path.dirname(fullPath);
36
+ let changelog = "";
37
+ for (const candidate of ["CHANGELOG.md", "CHANGES.md"]) {
38
+ try {
39
+ changelog = await fsp.readFile(path.join(dir, candidate), "utf-8");
40
+ break;
41
+ } catch {
42
+ /* try next */
43
+ }
44
+ }
45
+ if (!changelog) {
46
+ continue; // semver-check already advises on missing changelog
47
+ }
48
+ const versionPattern = new RegExp(
49
+ `##\\s*(?:\\[|v)?\\s*${String(parsed.version).replace(/\./g, "\\.")}\\b`
50
+ );
51
+ if (!versionPattern.test(changelog)) {
52
+ findings.push(
53
+ createFinding({
54
+ tool: "changelog-diff",
55
+ kind: "release.version-not-in-changelog",
56
+ severity: "P2",
57
+ file: toPosix(relativePath),
58
+ line: 0,
59
+ evidence: `package.json version "${parsed.version}" not found as a heading in the colocated changelog`,
60
+ rootCause:
61
+ "Changelog is out of sync with the manifest. Releases shipped without a changelog entry are invisible to consumers tracking what's new.",
62
+ recommendedFix:
63
+ "Add a `## [${version}] - YYYY-MM-DD` heading to the changelog before publishing. Wire release-please / changesets to keep them in sync automatically.",
64
+ confidence: 0.8,
65
+ })
66
+ );
67
+ }
68
+ }
69
+ return findings;
70
+ }
71
+
72
+ async function* iterateExplicitFiles(resolvedRoot, files) {
73
+ for (const file of files) {
74
+ const trimmed = String(file || "").trim();
75
+ if (!trimmed) {
76
+ continue;
77
+ }
78
+ const fullPath = path.isAbsolute(trimmed)
79
+ ? trimmed
80
+ : path.join(resolvedRoot, trimmed);
81
+ const relativePath = path
82
+ .relative(resolvedRoot, fullPath)
83
+ .replace(/\\/g, "/");
84
+ yield { fullPath, relativePath };
85
+ }
86
+ }
@@ -0,0 +1,126 @@
1
+ // feature-flag-audit — find stale feature flags (#A19).
2
+ //
3
+ // Flag debt: a flag that's been "temporary" for six months is now load-
4
+ // bearing architecture. We walk the repo for `flag.isEnabled("foo")` /
5
+ // `useFlag("foo")` / `featureFlag("foo")` calls and flag flags that:
6
+ // 1. Have been referenced for a long time (file mtime > 90 days)
7
+ // 2. Have no corresponding cleanup date in a comment near the call site
8
+
9
+ import fsp from "node:fs/promises";
10
+ import path from "node:path";
11
+
12
+ import { createFinding, findLineMatches, getLineContent, toPosix, walkRepoFiles } from "./base.js";
13
+
14
+ const CODE_EXTENSIONS = new Set([
15
+ ".js",
16
+ ".jsx",
17
+ ".ts",
18
+ ".tsx",
19
+ ".mjs",
20
+ ".cjs",
21
+ ".py",
22
+ ".go",
23
+ ]);
24
+
25
+ const FLAG_PATTERNS = [
26
+ /flag(?:s)?\.isEnabled\s*\(\s*['"`]([^'"`]+)['"`]/g,
27
+ /useFlag\s*\(\s*['"`]([^'"`]+)['"`]/g,
28
+ /useFeatureFlag\s*\(\s*['"`]([^'"`]+)['"`]/g,
29
+ /launchdarkly\.variation\s*\(\s*['"`]([^'"`]+)['"`]/g,
30
+ /optimizely\.isFeatureEnabled\s*\(\s*['"`]([^'"`]+)['"`]/g,
31
+ /unleash\.isEnabled\s*\(\s*['"`]([^'"`]+)['"`]/g,
32
+ /growthbook\.isOn\s*\(\s*['"`]([^'"`]+)['"`]/g,
33
+ ];
34
+
35
+ const STALE_DAYS = 90;
36
+
37
+ function hasCleanupAnnotation(contextLines) {
38
+ return /remove[_-]?by|cleanup[_-]?by|expires?[_-]?on|retire[_-]?by/i.test(
39
+ contextLines.join("\n")
40
+ );
41
+ }
42
+
43
+ export async function runFeatureFlagAudit({
44
+ rootPath,
45
+ files = null,
46
+ staleDays = STALE_DAYS,
47
+ } = {}) {
48
+ const resolvedRoot = path.resolve(String(rootPath || "."));
49
+ const iterator =
50
+ Array.isArray(files) && files.length > 0
51
+ ? iterateExplicitFiles(resolvedRoot, files)
52
+ : walkRepoFiles({ rootPath: resolvedRoot, extensions: CODE_EXTENSIONS });
53
+
54
+ const now = Date.now();
55
+ const staleThreshold = now - staleDays * 24 * 60 * 60 * 1000;
56
+ const findings = [];
57
+
58
+ for await (const { fullPath, relativePath, stat } of iterator) {
59
+ let content;
60
+ try {
61
+ content = await fsp.readFile(fullPath, "utf-8");
62
+ } catch {
63
+ continue;
64
+ }
65
+ const mtime = stat ? Number(stat.mtimeMs || 0) : now;
66
+ const isOld = mtime && mtime < staleThreshold;
67
+ const lines = content.split(/\r?\n/);
68
+
69
+ for (const pattern of FLAG_PATTERNS) {
70
+ for (const match of findLineMatches(content, pattern)) {
71
+ const flagName =
72
+ match.match.match(/['"`]([^'"`]+)['"`]/)?.[1] || "<unknown>";
73
+ const contextStart = Math.max(0, match.line - 3);
74
+ const contextEnd = Math.min(lines.length, match.line + 2);
75
+ const contextLines = lines.slice(contextStart, contextEnd);
76
+ if (hasCleanupAnnotation(contextLines)) {
77
+ continue;
78
+ }
79
+ if (!isOld) {
80
+ continue;
81
+ }
82
+ const ageDays = Math.floor((now - mtime) / (24 * 60 * 60 * 1000));
83
+ findings.push(
84
+ createFinding({
85
+ tool: "feature-flag-audit",
86
+ kind: "release.stale-flag",
87
+ severity: "P3",
88
+ file: toPosix(relativePath),
89
+ line: match.line,
90
+ evidence: `${getLineContent(content, match.line)} (file unchanged ${ageDays} days)`,
91
+ rootCause: `Flag '${flagName}' has been referenced for ≥ ${staleDays} days with no cleanup-by annotation.`,
92
+ recommendedFix:
93
+ "Add a `// cleanup-by: YYYY-MM-DD` comment near the call, or inline the chosen branch and delete the flag.",
94
+ confidence: 0.45,
95
+ })
96
+ );
97
+ }
98
+ }
99
+ }
100
+ return findings;
101
+ }
102
+
103
+ async function* iterateExplicitFiles(resolvedRoot, files) {
104
+ for (const file of files) {
105
+ const trimmed = String(file || "").trim();
106
+ if (!trimmed) {
107
+ continue;
108
+ }
109
+ const fullPath = path.isAbsolute(trimmed)
110
+ ? trimmed
111
+ : path.join(resolvedRoot, trimmed);
112
+ const relativePath = path
113
+ .relative(resolvedRoot, fullPath)
114
+ .replace(/\\/g, "/");
115
+ const fsp = await import("node:fs/promises");
116
+ let stat = null;
117
+ try {
118
+ stat = await fsp.stat(fullPath);
119
+ } catch {
120
+ /* ignore */
121
+ }
122
+ yield { fullPath, relativePath, stat };
123
+ }
124
+ }
125
+
126
+ export { STALE_DAYS };
@@ -0,0 +1,61 @@
1
+ // Omar (release persona) domain-tool registry (#A19).
2
+
3
+ import { runChangelogDiff } from "./changelog-diff.js";
4
+ import { runFeatureFlagAudit } from "./feature-flag-audit.js";
5
+ import { runRollbackVerify } from "./rollback-verify.js";
6
+ import { runSemverCheck } from "./semver-check.js";
7
+
8
+ export const RELEASE_TOOLS = Object.freeze({
9
+ "semver-check": {
10
+ id: "semver-check",
11
+ description: "Verify every non-private package.json has a valid semver version and a colocated changelog.",
12
+ schema: { type: "object", properties: { rootPath: { type: "string" }, files: { type: "array", items: { type: "string" } } } },
13
+ handler: runSemverCheck,
14
+ },
15
+ "changelog-diff": {
16
+ id: "changelog-diff",
17
+ description: "Verify the current version in package.json has a matching heading in the colocated CHANGELOG.md.",
18
+ schema: { type: "object", properties: { rootPath: { type: "string" }, files: { type: "array", items: { type: "string" } } } },
19
+ handler: runChangelogDiff,
20
+ },
21
+ "rollback-verify": {
22
+ id: "rollback-verify",
23
+ description: "Ensure Alembic / Rails / Knex migrations define a down / downgrade / change path so `db:rollback` isn't a no-op.",
24
+ schema: { type: "object", properties: { rootPath: { type: "string" }, files: { type: "array", items: { type: "string" } } } },
25
+ handler: runRollbackVerify,
26
+ },
27
+ "feature-flag-audit": {
28
+ id: "feature-flag-audit",
29
+ description: "Flag feature-flag call sites in files not touched in ≥ 90 days, with no cleanup-by annotation nearby.",
30
+ schema: {
31
+ type: "object",
32
+ properties: {
33
+ rootPath: { type: "string" },
34
+ staleDays: { type: "number" },
35
+ files: { type: "array", items: { type: "string" } },
36
+ },
37
+ },
38
+ handler: runFeatureFlagAudit,
39
+ },
40
+ });
41
+
42
+ export const RELEASE_TOOL_IDS = Object.freeze(Object.keys(RELEASE_TOOLS));
43
+
44
+ export async function dispatchReleaseTool(toolId, args = {}) {
45
+ const tool = RELEASE_TOOLS[toolId];
46
+ if (!tool) {
47
+ throw new Error(`Unknown release tool: ${toolId}`);
48
+ }
49
+ return tool.handler(args);
50
+ }
51
+
52
+ export async function runAllReleaseTools({ rootPath, files = null } = {}) {
53
+ const findings = [];
54
+ for (const toolId of RELEASE_TOOL_IDS) {
55
+ const out = await dispatchReleaseTool(toolId, { rootPath, files });
56
+ findings.push(...out);
57
+ }
58
+ return findings;
59
+ }
60
+
61
+ export { runChangelogDiff, runFeatureFlagAudit, runRollbackVerify, runSemverCheck };
@@ -0,0 +1,129 @@
1
+ // rollback-verify — ensure recent migrations + deploy configs support rollback (#A19).
2
+ //
3
+ // We check:
4
+ // - Alembic versions have a downgrade() body (not just pass)
5
+ // - Rails migrations have a `def down` or `reversible` block
6
+ // - Infrastructure / deploy configs mention rollback / revert strategies
7
+
8
+ import fsp from "node:fs/promises";
9
+ import path from "node:path";
10
+
11
+ import { createFinding, toPosix, walkRepoFiles } from "./base.js";
12
+
13
+ const MIGRATION_EXTENSIONS = new Set([".py", ".rb", ".sql", ".js", ".ts"]);
14
+
15
+ function isAlembicFile(relPath) {
16
+ return /(^|\/)alembic\/versions\//.test(toPosix(relPath));
17
+ }
18
+
19
+ function isRailsMigrationFile(relPath) {
20
+ return /(^|\/)db\/migrate\/[^/]+\.rb$/.test(toPosix(relPath));
21
+ }
22
+
23
+ function isKnexMigrationFile(relPath) {
24
+ return /(^|\/)knex\/migrations?\//i.test(toPosix(relPath));
25
+ }
26
+
27
+ export async function runRollbackVerify({ rootPath, files = null } = {}) {
28
+ const resolvedRoot = path.resolve(String(rootPath || "."));
29
+ const iterator =
30
+ Array.isArray(files) && files.length > 0
31
+ ? iterateExplicitFiles(resolvedRoot, files)
32
+ : walkRepoFiles({ rootPath: resolvedRoot, extensions: MIGRATION_EXTENSIONS });
33
+
34
+ const findings = [];
35
+ for await (const { fullPath, relativePath } of iterator) {
36
+ const rel = toPosix(relativePath);
37
+ let content;
38
+ try {
39
+ content = await fsp.readFile(fullPath, "utf-8");
40
+ } catch {
41
+ continue;
42
+ }
43
+
44
+ if (isAlembicFile(rel)) {
45
+ const downgradeMatch = content.match(
46
+ /def\s+downgrade\s*\(\s*\)\s*(?:->[\s\S]*?)?\s*:\s*([\s\S]*?)(?=\ndef|\Z)/
47
+ );
48
+ const body = downgradeMatch ? downgradeMatch[1].trim() : "";
49
+ if (!downgradeMatch || body === "" || body === "pass" || /^\s*pass\s*$/.test(body)) {
50
+ findings.push(
51
+ createFinding({
52
+ tool: "rollback-verify",
53
+ kind: "release.empty-downgrade",
54
+ severity: "P1",
55
+ file: rel,
56
+ line: 0,
57
+ evidence: downgradeMatch ? "downgrade() body is empty / pass" : "no downgrade() defined",
58
+ rootCause:
59
+ "Alembic migration has no downgrade path. If the upgrade breaks production, we have no clean rollback.",
60
+ recommendedFix:
61
+ "Implement downgrade() that reverses upgrade() exactly. If data loss is inevitable, document it explicitly and gate upgrade() on a confirmation flag.",
62
+ confidence: 0.85,
63
+ })
64
+ );
65
+ }
66
+ }
67
+
68
+ if (isRailsMigrationFile(rel)) {
69
+ const hasDown = /\bdef\s+down\b/.test(content);
70
+ const hasReversible = /\breversible\b/.test(content);
71
+ const hasChange = /\bdef\s+change\b/.test(content);
72
+ if (!hasDown && !hasReversible && !hasChange) {
73
+ findings.push(
74
+ createFinding({
75
+ tool: "rollback-verify",
76
+ kind: "release.no-rails-down",
77
+ severity: "P1",
78
+ file: rel,
79
+ line: 0,
80
+ evidence: "No `def change`, `def down`, or `reversible` block",
81
+ rootCause:
82
+ "Rails migration without a reversible path. `rails db:rollback` will not undo this.",
83
+ recommendedFix:
84
+ "Use `def change` (Rails 4+ auto-reversible) or define an explicit `def down`.",
85
+ confidence: 0.85,
86
+ })
87
+ );
88
+ }
89
+ }
90
+
91
+ if (isKnexMigrationFile(rel)) {
92
+ const hasDown = /exports\.down\s*=|export\s+(?:async\s+)?function\s+down\b/.test(content);
93
+ if (!hasDown) {
94
+ findings.push(
95
+ createFinding({
96
+ tool: "rollback-verify",
97
+ kind: "release.no-knex-down",
98
+ severity: "P1",
99
+ file: rel,
100
+ line: 0,
101
+ evidence: "No exports.down / export function down in Knex migration",
102
+ rootCause:
103
+ "Knex migration without a down step — `knex migrate:rollback` will fail.",
104
+ recommendedFix:
105
+ "Pair every `exports.up` with an `exports.down` that reverses it.",
106
+ confidence: 0.85,
107
+ })
108
+ );
109
+ }
110
+ }
111
+ }
112
+ return findings;
113
+ }
114
+
115
+ async function* iterateExplicitFiles(resolvedRoot, files) {
116
+ for (const file of files) {
117
+ const trimmed = String(file || "").trim();
118
+ if (!trimmed) {
119
+ continue;
120
+ }
121
+ const fullPath = path.isAbsolute(trimmed)
122
+ ? trimmed
123
+ : path.join(resolvedRoot, trimmed);
124
+ const relativePath = path
125
+ .relative(resolvedRoot, fullPath)
126
+ .replace(/\\/g, "/");
127
+ yield { fullPath, relativePath };
128
+ }
129
+ }
@@ -0,0 +1,109 @@
1
+ // semver-check — verify package.json version follows semver + matches the
2
+ // scope of its last release (#A19).
3
+ //
4
+ // Heuristic: look at every package.json the repo publishes and:
5
+ // 1. Verify the version literal parses as semver (N.N.N or N.N.N-prerelease)
6
+ // 2. Verify a CHANGELOG.md / CHANGES.md exists alongside it — having a
7
+ // versioned artifact without a changelog is a release-discipline miss
8
+
9
+ import fsp from "node:fs/promises";
10
+ import path from "node:path";
11
+
12
+ import { createFinding, toPosix, walkRepoFiles } from "./base.js";
13
+
14
+ const PKG_EXTENSIONS = new Set([".json"]);
15
+ const SEMVER_PATTERN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
16
+
17
+ export async function runSemverCheck({ rootPath, files = null } = {}) {
18
+ const resolvedRoot = path.resolve(String(rootPath || "."));
19
+ const iterator =
20
+ Array.isArray(files) && files.length > 0
21
+ ? iterateExplicitFiles(resolvedRoot, files)
22
+ : walkRepoFiles({ rootPath: resolvedRoot, extensions: PKG_EXTENSIONS });
23
+
24
+ const findings = [];
25
+ for await (const { fullPath, relativePath } of iterator) {
26
+ if (!/(^|\/)package\.json$/.test(toPosix(relativePath))) {
27
+ continue;
28
+ }
29
+ let raw;
30
+ try {
31
+ raw = await fsp.readFile(fullPath, "utf-8");
32
+ } catch {
33
+ continue;
34
+ }
35
+ let parsed;
36
+ try {
37
+ parsed = JSON.parse(raw);
38
+ } catch {
39
+ continue;
40
+ }
41
+ if (!parsed?.version || parsed.private === true) {
42
+ continue;
43
+ }
44
+ if (!SEMVER_PATTERN.test(String(parsed.version))) {
45
+ findings.push(
46
+ createFinding({
47
+ tool: "semver-check",
48
+ kind: "release.invalid-semver",
49
+ severity: "P1",
50
+ file: toPosix(relativePath),
51
+ line: 0,
52
+ evidence: `version = "${parsed.version}"`,
53
+ rootCause:
54
+ "package.json version doesn't parse as semver. npm / Yarn / pnpm tooling and npm registry itself rely on strict semver.",
55
+ recommendedFix: "Use the form MAJOR.MINOR.PATCH (optionally with -prerelease or +buildmeta).",
56
+ confidence: 0.95,
57
+ })
58
+ );
59
+ }
60
+
61
+ // Look for a changelog next to the package.json.
62
+ const dir = path.dirname(fullPath);
63
+ const candidates = ["CHANGELOG.md", "CHANGES.md", "CHANGELOG.txt"];
64
+ let hasChangelog = false;
65
+ for (const candidate of candidates) {
66
+ try {
67
+ await fsp.stat(path.join(dir, candidate));
68
+ hasChangelog = true;
69
+ break;
70
+ } catch {
71
+ /* missing — try next */
72
+ }
73
+ }
74
+ if (!hasChangelog) {
75
+ findings.push(
76
+ createFinding({
77
+ tool: "semver-check",
78
+ kind: "release.no-changelog",
79
+ severity: "P2",
80
+ file: toPosix(relativePath),
81
+ line: 0,
82
+ evidence: `No CHANGELOG.md / CHANGES.md next to ${toPosix(relativePath)}`,
83
+ rootCause:
84
+ "A published package without a changelog leaves consumers guessing what changed between versions.",
85
+ recommendedFix:
86
+ "Add CHANGELOG.md (Keep-a-Changelog format) and wire it to release-please / changesets so version bumps and entries stay in sync.",
87
+ confidence: 0.75,
88
+ })
89
+ );
90
+ }
91
+ }
92
+ return findings;
93
+ }
94
+
95
+ async function* iterateExplicitFiles(resolvedRoot, files) {
96
+ for (const file of files) {
97
+ const trimmed = String(file || "").trim();
98
+ if (!trimmed) {
99
+ continue;
100
+ }
101
+ const fullPath = path.isAbsolute(trimmed)
102
+ ? trimmed
103
+ : path.join(resolvedRoot, trimmed);
104
+ const relativePath = path
105
+ .relative(resolvedRoot, fullPath)
106
+ .replace(/\\/g, "/");
107
+ yield { fullPath, relativePath };
108
+ }
109
+ }