sentinelayer-cli 0.6.2 → 0.8.1
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.
- package/README.md +1009 -996
- package/bin/create-sentinelayer.js +5 -5
- package/bin/sentinelayer-cli.js +4 -4
- package/bin/sl.js +5 -5
- package/package.json +64 -63
- package/src/agents/ai-governance/index.js +12 -0
- package/src/agents/ai-governance/tools/base.js +171 -0
- package/src/agents/ai-governance/tools/eval-regression.js +47 -0
- package/src/agents/ai-governance/tools/hitl-audit.js +81 -0
- package/src/agents/ai-governance/tools/index.js +52 -0
- package/src/agents/ai-governance/tools/prompt-drift.js +42 -0
- package/src/agents/ai-governance/tools/provenance-check.js +69 -0
- package/src/agents/backend/index.js +12 -0
- package/src/agents/backend/tools/base.js +189 -0
- package/src/agents/backend/tools/circuit-breaker-check.js +123 -0
- package/src/agents/backend/tools/idempotency-audit.js +105 -0
- package/src/agents/backend/tools/index.js +87 -0
- package/src/agents/backend/tools/retry-audit.js +132 -0
- package/src/agents/backend/tools/timeout-audit.js +144 -0
- package/src/agents/code-quality/index.js +12 -0
- package/src/agents/code-quality/tools/base.js +159 -0
- package/src/agents/code-quality/tools/complexity-measure.js +197 -0
- package/src/agents/code-quality/tools/coupling-analysis.js +81 -0
- package/src/agents/code-quality/tools/cycle-detect.js +49 -0
- package/src/agents/code-quality/tools/dep-graph.js +196 -0
- package/src/agents/code-quality/tools/index.js +89 -0
- package/src/agents/data-layer/index.js +12 -0
- package/src/agents/data-layer/tools/base.js +181 -0
- package/src/agents/data-layer/tools/index-audit.js +165 -0
- package/src/agents/data-layer/tools/index.js +83 -0
- package/src/agents/data-layer/tools/migration-scan.js +135 -0
- package/src/agents/data-layer/tools/query-explain.js +120 -0
- package/src/agents/data-layer/tools/tenancy-scan.js +166 -0
- package/src/agents/documentation/index.js +12 -0
- package/src/agents/documentation/tools/api-diff.js +91 -0
- package/src/agents/documentation/tools/base.js +151 -0
- package/src/agents/documentation/tools/dead-link-check.js +58 -0
- package/src/agents/documentation/tools/docstring-coverage.js +78 -0
- package/src/agents/documentation/tools/index.js +52 -0
- package/src/agents/documentation/tools/readme-freshness.js +61 -0
- package/src/agents/envelope/fix-cycle.js +45 -0
- package/src/agents/envelope/index.js +31 -0
- package/src/agents/envelope/loop.js +150 -0
- package/src/agents/envelope/pulse.js +18 -0
- package/src/agents/envelope/stream.js +40 -0
- package/src/agents/infrastructure/index.js +12 -0
- package/src/agents/infrastructure/tools/base.js +171 -0
- package/src/agents/infrastructure/tools/checkov-run.js +32 -0
- package/src/agents/infrastructure/tools/drift-detect.js +59 -0
- package/src/agents/infrastructure/tools/iam-least-priv-check.js +78 -0
- package/src/agents/infrastructure/tools/index.js +52 -0
- package/src/agents/infrastructure/tools/tflint-run.js +31 -0
- package/src/agents/jules/config/definition.js +160 -160
- package/src/agents/jules/config/system-prompt.js +182 -182
- package/src/agents/jules/error-intake.js +51 -51
- package/src/agents/jules/fix-cycle.js +17 -17
- package/src/agents/jules/loop.js +460 -450
- package/src/agents/jules/pulse.js +10 -10
- package/src/agents/jules/stream.js +187 -186
- package/src/agents/jules/swarm/file-scanner.js +74 -74
- package/src/agents/jules/swarm/index.js +11 -11
- package/src/agents/jules/swarm/orchestrator.js +362 -362
- package/src/agents/jules/swarm/pattern-hunter.js +123 -123
- package/src/agents/jules/swarm/sub-agent.js +315 -309
- package/src/agents/jules/tools/aidenid-email.js +189 -189
- package/src/agents/jules/tools/auth-audit.js +1708 -1691
- package/src/agents/jules/tools/dispatch.js +340 -335
- package/src/agents/jules/tools/file-edit.js +2 -2
- package/src/agents/jules/tools/file-read.js +2 -2
- package/src/agents/jules/tools/frontend-analyze.js +570 -570
- package/src/agents/jules/tools/glob.js +2 -2
- package/src/agents/jules/tools/grep.js +2 -2
- package/src/agents/jules/tools/index.js +29 -29
- package/src/agents/jules/tools/path-guards.js +2 -2
- package/src/agents/jules/tools/runtime-audit.js +507 -507
- package/src/agents/jules/tools/shell.js +2 -2
- package/src/agents/jules/tools/url-policy.js +100 -100
- package/src/agents/mode.js +113 -0
- package/src/agents/observability/index.js +12 -0
- package/src/agents/observability/tools/alert-audit.js +39 -0
- package/src/agents/observability/tools/base.js +181 -0
- package/src/agents/observability/tools/dashboard-gap.js +42 -0
- package/src/agents/observability/tools/index.js +54 -0
- package/src/agents/observability/tools/log-schema-check.js +74 -0
- package/src/agents/observability/tools/span-coverage.js +74 -0
- package/src/agents/persona-visuals.js +102 -61
- package/src/agents/release/index.js +12 -0
- package/src/agents/release/tools/base.js +181 -0
- package/src/agents/release/tools/changelog-diff.js +86 -0
- package/src/agents/release/tools/feature-flag-audit.js +126 -0
- package/src/agents/release/tools/index.js +61 -0
- package/src/agents/release/tools/rollback-verify.js +129 -0
- package/src/agents/release/tools/semver-check.js +109 -0
- package/src/agents/reliability/index.js +12 -0
- package/src/agents/reliability/tools/backpressure-check.js +129 -0
- package/src/agents/reliability/tools/base.js +181 -0
- package/src/agents/reliability/tools/chaos-probe.js +109 -0
- package/src/agents/reliability/tools/graceful-degradation-check.js +114 -0
- package/src/agents/reliability/tools/health-check-audit.js +111 -0
- package/src/agents/reliability/tools/index.js +87 -0
- package/src/agents/run-persona.js +109 -0
- package/src/agents/security/index.js +12 -0
- package/src/agents/security/tools/authz-audit.js +134 -0
- package/src/agents/security/tools/base.js +190 -0
- package/src/agents/security/tools/crypto-review.js +175 -0
- package/src/agents/security/tools/index.js +97 -0
- package/src/agents/security/tools/sast-scan.js +175 -0
- package/src/agents/security/tools/secrets-scan.js +216 -0
- package/src/agents/shared-tools/dispatch-core.js +320 -315
- package/src/agents/shared-tools/file-edit.js +180 -180
- package/src/agents/shared-tools/file-read.js +100 -100
- package/src/agents/shared-tools/glob.js +168 -168
- package/src/agents/shared-tools/grep.js +228 -228
- package/src/agents/shared-tools/index.js +46 -46
- package/src/agents/shared-tools/path-guards.js +161 -161
- package/src/agents/shared-tools/shell.js +383 -383
- package/src/agents/supply-chain/index.js +12 -0
- package/src/agents/supply-chain/tools/attestation-check.js +42 -0
- package/src/agents/supply-chain/tools/base.js +151 -0
- package/src/agents/supply-chain/tools/index.js +52 -0
- package/src/agents/supply-chain/tools/lockfile-integrity.js +73 -0
- package/src/agents/supply-chain/tools/package-verify.js +56 -0
- package/src/agents/supply-chain/tools/sbom-diff.js +34 -0
- package/src/agents/testing/index.js +12 -0
- package/src/agents/testing/tools/base.js +202 -0
- package/src/agents/testing/tools/coverage-gap.js +144 -0
- package/src/agents/testing/tools/flake-detect.js +125 -0
- package/src/agents/testing/tools/index.js +85 -0
- package/src/agents/testing/tools/mutation-test.js +143 -0
- package/src/agents/testing/tools/snapshot-diff.js +103 -0
- package/src/ai/aidenid.js +1021 -1009
- package/src/ai/client.js +553 -553
- package/src/ai/domain-target-store.js +268 -268
- package/src/ai/identity-store.js +270 -270
- package/src/ai/proxy.js +137 -137
- package/src/ai/site-store.js +145 -145
- package/src/audit/agents/architecture.js +180 -180
- package/src/audit/agents/compliance.js +179 -179
- package/src/audit/agents/documentation.js +165 -165
- package/src/audit/agents/performance.js +145 -145
- package/src/audit/agents/security.js +215 -215
- package/src/audit/agents/testing.js +172 -172
- package/src/audit/orchestrator.js +557 -557
- package/src/audit/package.js +204 -204
- package/src/audit/registry.js +284 -284
- package/src/audit/replay.js +103 -103
- package/src/auth/gate.js +428 -371
- package/src/auth/http.js +681 -611
- package/src/auth/service.js +1106 -1106
- package/src/auth/session-store.js +813 -813
- package/src/cli.js +257 -252
- package/src/commands/ai/identity-lifecycle.js +1338 -1338
- package/src/commands/ai/provision-governance.js +1272 -1272
- package/src/commands/ai/shared.js +147 -147
- package/src/commands/ai.js +11 -11
- package/src/commands/apply.js +12 -12
- package/src/commands/audit.js +1171 -1166
- package/src/commands/auth.js +419 -419
- package/src/commands/chat.js +184 -191
- package/src/commands/config.js +184 -184
- package/src/commands/cost.js +311 -311
- package/src/commands/daemon/core.js +850 -850
- package/src/commands/daemon/extended.js +1048 -1048
- package/src/commands/daemon/shared.js +213 -213
- package/src/commands/daemon.js +11 -11
- package/src/commands/guide.js +174 -174
- package/src/commands/ingest.js +58 -58
- package/src/commands/init.js +55 -55
- package/src/commands/legacy-args.js +20 -10
- package/src/commands/mcp.js +461 -461
- package/src/commands/omargate.js +63 -29
- package/src/commands/persona.js +65 -20
- package/src/commands/plugin.js +260 -260
- package/src/commands/policy.js +132 -132
- package/src/commands/prompt.js +238 -238
- package/src/commands/review.js +704 -704
- package/src/commands/scan.js +865 -872
- package/src/commands/session.js +1238 -0
- package/src/commands/spec.js +771 -716
- package/src/commands/swarm.js +651 -651
- package/src/commands/telemetry.js +202 -202
- package/src/commands/watch.js +511 -511
- package/src/config/agent-dictionary.js +182 -182
- package/src/config/io.js +56 -56
- package/src/config/paths.js +18 -18
- package/src/config/schema.js +55 -55
- package/src/config/service.js +184 -184
- package/src/coord/events-log.js +141 -0
- package/src/coord/handshake.js +719 -0
- package/src/coord/index.js +35 -0
- package/src/coord/paths.js +84 -0
- package/src/coord/priority.js +62 -0
- package/src/coord/tarjan.js +157 -0
- package/src/cost/budget.js +235 -235
- package/src/cost/history.js +188 -188
- package/src/cost/tokenizer.js +160 -0
- package/src/cost/tracker.js +232 -171
- package/src/daemon/artifact-lineage.js +896 -534
- package/src/daemon/assignment-ledger.js +1083 -770
- package/src/daemon/ast-drift.js +496 -0
- package/src/daemon/ast-parser-layer.js +258 -258
- package/src/daemon/budget-governor.js +633 -633
- package/src/daemon/callgraph-overlay.js +646 -646
- package/src/daemon/error-worker.js +1209 -626
- package/src/daemon/fix-cycle.js +384 -377
- package/src/daemon/hybrid-mapper.js +929 -929
- package/src/daemon/ingest-refresh.js +79 -11
- package/src/daemon/jira-lifecycle.js +767 -632
- package/src/daemon/operator-control.js +657 -657
- package/src/daemon/pulse.js +327 -327
- package/src/daemon/reliability-lane.js +471 -471
- package/src/daemon/scope-engine.js +1068 -0
- package/src/daemon/watchdog.js +971 -971
- package/src/events/schema.js +190 -0
- package/src/guide/generator.js +316 -316
- package/src/ingest/engine.js +933 -918
- package/src/ingest/ownership.js +380 -0
- package/src/interactive/index.js +97 -97
- package/src/legacy-cli.js +3228 -2994
- package/src/mcp/registry.js +695 -695
- package/src/memory/blackboard.js +301 -301
- package/src/memory/retrieval.js +581 -581
- package/src/orchestrator/kai-chen.js +126 -0
- package/src/plugin/manifest.js +553 -553
- package/src/policy/packs.js +144 -144
- package/src/prompt/generator.js +136 -118
- package/src/review/ai-review.js +672 -679
- package/src/review/compliance-pack.js +389 -0
- package/src/review/investor-dd-config.js +54 -0
- package/src/review/investor-dd-file-loop.js +303 -0
- package/src/review/investor-dd-file-router.js +406 -0
- package/src/review/investor-dd-html-report.js +233 -0
- package/src/review/investor-dd-notification.js +120 -0
- package/src/review/investor-dd-orchestrator.js +405 -0
- package/src/review/investor-dd-persona-runner.js +275 -0
- package/src/review/live-validator.js +253 -0
- package/src/review/local-review.js +1351 -1305
- package/src/review/omargate-interactive.js +68 -68
- package/src/review/omargate-orchestrator.js +492 -300
- package/src/review/persona-prompts.js +484 -296
- package/src/review/reconciliation-rules.js +329 -0
- package/src/review/replay.js +235 -235
- package/src/review/report.js +664 -664
- package/src/review/reproducibility-chain.js +136 -0
- package/src/review/scan-modes.js +147 -42
- package/src/review/spec-binding.js +487 -487
- package/src/scaffold/generator.js +67 -67
- package/src/scaffold/templates.js +150 -150
- package/src/scan/generator.js +418 -418
- package/src/scan/gh-secrets.js +107 -107
- package/src/session/agent-registry.js +359 -0
- package/src/session/analytics.js +479 -0
- package/src/session/daemon.js +1396 -0
- package/src/session/file-locks.js +666 -0
- package/src/session/paths.js +37 -0
- package/src/session/recap.js +567 -0
- package/src/session/redact.js +82 -0
- package/src/session/runtime-bridge.js +762 -0
- package/src/session/scoring.js +406 -0
- package/src/session/setup-guides.js +304 -0
- package/src/session/store.js +704 -0
- package/src/session/stream.js +333 -0
- package/src/session/sync.js +753 -0
- package/src/session/tasks.js +1054 -0
- package/src/session/templates.js +188 -0
- package/src/spec/generator.js +619 -519
- package/src/spec/regenerate.js +237 -237
- package/src/spec/templates.js +91 -91
- package/src/swarm/dashboard.js +247 -247
- package/src/swarm/factory.js +363 -363
- package/src/swarm/pentest.js +934 -934
- package/src/swarm/registry.js +419 -419
- package/src/swarm/report.js +158 -158
- package/src/swarm/runtime.js +569 -576
- package/src/swarm/scenario-dsl.js +272 -272
- package/src/telemetry/ledger.js +302 -302
- package/src/telemetry/session-tracker.js +234 -234
- package/src/telemetry/sync.js +203 -203
- package/src/ui/command-hints.js +13 -13
- package/src/ui/markdown.js +220 -220
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Noah (reliability persona) — barrel export (#A18).
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
RELIABILITY_TOOLS,
|
|
5
|
+
RELIABILITY_TOOL_IDS,
|
|
6
|
+
dispatchReliabilityTool,
|
|
7
|
+
runAllReliabilityTools,
|
|
8
|
+
runBackpressureCheck,
|
|
9
|
+
runChaosProbe,
|
|
10
|
+
runGracefulDegradationCheck,
|
|
11
|
+
runHealthCheckAudit,
|
|
12
|
+
} from "./tools/index.js";
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// backpressure-check — flag queue / worker patterns without backpressure or DLQ (#A18).
|
|
2
|
+
//
|
|
3
|
+
// When a consumer can outrun its queue the system degrades silently (memory
|
|
4
|
+
// balloons, latency spikes, and eventual OOM). We look for queue consumers
|
|
5
|
+
// and flag those missing:
|
|
6
|
+
// - a bounded concurrency / queue size (backpressure)
|
|
7
|
+
// - a dead-letter queue / DLQ signal for poison messages
|
|
8
|
+
// - explicit retry limits
|
|
9
|
+
|
|
10
|
+
import fsp from "node:fs/promises";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
|
|
13
|
+
import { createFinding, findLineMatches, getLineContent, toPosix, walkRepoFiles } from "./base.js";
|
|
14
|
+
|
|
15
|
+
const CODE_EXTENSIONS = new Set([
|
|
16
|
+
".js",
|
|
17
|
+
".jsx",
|
|
18
|
+
".ts",
|
|
19
|
+
".tsx",
|
|
20
|
+
".mjs",
|
|
21
|
+
".cjs",
|
|
22
|
+
".py",
|
|
23
|
+
".go",
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
const QUEUE_CONSUMER_PATTERNS = [
|
|
27
|
+
/bull(?:mq)?\.\w+|new\s+Queue\s*\(/,
|
|
28
|
+
/kafka\w*\.consumer\s*\(/,
|
|
29
|
+
/sqs\w*\.receiveMessage\s*\(/,
|
|
30
|
+
/rabbit\w*\.consume\s*\(/,
|
|
31
|
+
/redis\w*\.subscribe\s*\(/,
|
|
32
|
+
/celery\.task\s*\(/,
|
|
33
|
+
/@task\s*\(/,
|
|
34
|
+
/@app\.task\s*\(/,
|
|
35
|
+
/\b(?:worker|consumer|processor)\s*=\s*(?:new\s+)?\w+/,
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
const BACKPRESSURE_SIGNALS = [
|
|
39
|
+
/concurrency\s*[:=]\s*\d+/,
|
|
40
|
+
/maxConcurrent/i,
|
|
41
|
+
/prefetch[_-]?count/i,
|
|
42
|
+
/max_queue_size|maxQueueSize/,
|
|
43
|
+
/rate[_-]?limit/i,
|
|
44
|
+
/drop[_-]?on[_-]?full/i,
|
|
45
|
+
/visibility[_-]?timeout/i,
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
const DLQ_SIGNALS = [
|
|
49
|
+
/dead[_-]?letter|DLQ/i,
|
|
50
|
+
/retry[_-]?policy|max[_-]?retries|retry_limit/i,
|
|
51
|
+
/poison[_-]?pill|poison[_-]?message/i,
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
export async function runBackpressureCheck({ rootPath, files = null } = {}) {
|
|
55
|
+
const resolvedRoot = path.resolve(String(rootPath || "."));
|
|
56
|
+
const iterator =
|
|
57
|
+
Array.isArray(files) && files.length > 0
|
|
58
|
+
? iterateExplicitFiles(resolvedRoot, files)
|
|
59
|
+
: walkRepoFiles({ rootPath: resolvedRoot, extensions: CODE_EXTENSIONS });
|
|
60
|
+
|
|
61
|
+
const findings = [];
|
|
62
|
+
for await (const { fullPath, relativePath } of iterator) {
|
|
63
|
+
let content;
|
|
64
|
+
try {
|
|
65
|
+
content = await fsp.readFile(fullPath, "utf-8");
|
|
66
|
+
} catch {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const consumerMatch = QUEUE_CONSUMER_PATTERNS.find((p) => p.test(content));
|
|
70
|
+
if (!consumerMatch) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const hasBackpressure = BACKPRESSURE_SIGNALS.some((p) => p.test(content));
|
|
74
|
+
const hasDlq = DLQ_SIGNALS.some((p) => p.test(content));
|
|
75
|
+
|
|
76
|
+
const line = findLineMatches(content, consumerMatch)[0]?.line || 1;
|
|
77
|
+
if (!hasBackpressure) {
|
|
78
|
+
findings.push(
|
|
79
|
+
createFinding({
|
|
80
|
+
tool: "backpressure-check",
|
|
81
|
+
kind: "reliability.no-backpressure",
|
|
82
|
+
severity: "P1",
|
|
83
|
+
file: toPosix(relativePath),
|
|
84
|
+
line,
|
|
85
|
+
evidence: getLineContent(content, line),
|
|
86
|
+
rootCause:
|
|
87
|
+
"Queue consumer declared without a concurrency limit, prefetch count, or queue-full handling. A faster producer will balloon the in-memory queue or downstream pool.",
|
|
88
|
+
recommendedFix:
|
|
89
|
+
"Bound concurrency: BullMQ `concurrency` option, Kafka `max.poll.records`, SQS `MaxNumberOfMessages`, Celery `worker_prefetch_multiplier`. Pair with a 1-2 second visibility timeout.",
|
|
90
|
+
confidence: 0.55,
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
if (!hasDlq) {
|
|
95
|
+
findings.push(
|
|
96
|
+
createFinding({
|
|
97
|
+
tool: "backpressure-check",
|
|
98
|
+
kind: "reliability.no-dlq",
|
|
99
|
+
severity: "P1",
|
|
100
|
+
file: toPosix(relativePath),
|
|
101
|
+
line,
|
|
102
|
+
evidence: getLineContent(content, line),
|
|
103
|
+
rootCause:
|
|
104
|
+
"No dead-letter queue / retry-limit / poison-pill handling. A bad message will loop forever until the worker is manually killed.",
|
|
105
|
+
recommendedFix:
|
|
106
|
+
"Configure a DLQ with max-receive-count (SQS), delivery-limit (Bull), or max_retries (Celery). Alert on DLQ depth > 0 so operators see poison messages.",
|
|
107
|
+
confidence: 0.6,
|
|
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
|
+
}
|