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,83 @@
|
|
|
1
|
+
// Linh (data-layer persona) domain-tool registry (#A17).
|
|
2
|
+
|
|
3
|
+
import { runIndexAudit } from "./index-audit.js";
|
|
4
|
+
import { runMigrationScan } from "./migration-scan.js";
|
|
5
|
+
import { runQueryExplain } from "./query-explain.js";
|
|
6
|
+
import { runTenancyScan } from "./tenancy-scan.js";
|
|
7
|
+
|
|
8
|
+
export const DATA_LAYER_TOOLS = Object.freeze({
|
|
9
|
+
"query-explain": {
|
|
10
|
+
id: "query-explain",
|
|
11
|
+
description:
|
|
12
|
+
"Scan source for query anti-patterns: SELECT without LIMIT, findAll in a loop (N+1), string-concatenated SQL, SELECT *.",
|
|
13
|
+
schema: {
|
|
14
|
+
type: "object",
|
|
15
|
+
properties: {
|
|
16
|
+
rootPath: { type: "string" },
|
|
17
|
+
files: { type: "array", items: { type: "string" } },
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
handler: runQueryExplain,
|
|
21
|
+
},
|
|
22
|
+
"migration-scan": {
|
|
23
|
+
id: "migration-scan",
|
|
24
|
+
description:
|
|
25
|
+
"Scan migration files (.sql, alembic, prisma, knex, Rails db/migrate) for unsafe patterns: DROP TABLE/COLUMN, ADD COLUMN NOT NULL w/o default, CREATE INDEX w/o CONCURRENTLY, unbatched UPDATE.",
|
|
26
|
+
schema: {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {
|
|
29
|
+
rootPath: { type: "string" },
|
|
30
|
+
files: { type: "array", items: { type: "string" } },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
handler: runMigrationScan,
|
|
34
|
+
},
|
|
35
|
+
"index-audit": {
|
|
36
|
+
id: "index-audit",
|
|
37
|
+
description:
|
|
38
|
+
"Cross-reference WHERE / JOIN columns in application code vs. CREATE INDEX / @Index / db_index declarations in migrations + models. Flag lookups with no matching index.",
|
|
39
|
+
schema: {
|
|
40
|
+
type: "object",
|
|
41
|
+
properties: {
|
|
42
|
+
rootPath: { type: "string" },
|
|
43
|
+
files: { type: "array", items: { type: "string" } },
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
handler: runIndexAudit,
|
|
47
|
+
},
|
|
48
|
+
"tenancy-scan": {
|
|
49
|
+
id: "tenancy-scan",
|
|
50
|
+
description:
|
|
51
|
+
"Identify tenancy-owning tables (those whose schema includes tenant_id / org_id / workspace_id) and flag application queries that touch them without a tenancy filter.",
|
|
52
|
+
schema: {
|
|
53
|
+
type: "object",
|
|
54
|
+
properties: {
|
|
55
|
+
rootPath: { type: "string" },
|
|
56
|
+
files: { type: "array", items: { type: "string" } },
|
|
57
|
+
tenancyTables: { type: "array", items: { type: "string" } },
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
handler: runTenancyScan,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export const DATA_LAYER_TOOL_IDS = Object.freeze(Object.keys(DATA_LAYER_TOOLS));
|
|
65
|
+
|
|
66
|
+
export async function dispatchDataLayerTool(toolId, args = {}) {
|
|
67
|
+
const tool = DATA_LAYER_TOOLS[toolId];
|
|
68
|
+
if (!tool) {
|
|
69
|
+
throw new Error(`Unknown data-layer tool: ${toolId}`);
|
|
70
|
+
}
|
|
71
|
+
return tool.handler(args);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export async function runAllDataLayerTools({ rootPath, files = null } = {}) {
|
|
75
|
+
const findings = [];
|
|
76
|
+
for (const toolId of DATA_LAYER_TOOL_IDS) {
|
|
77
|
+
const out = await dispatchDataLayerTool(toolId, { rootPath, files });
|
|
78
|
+
findings.push(...out);
|
|
79
|
+
}
|
|
80
|
+
return findings;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { runIndexAudit, runMigrationScan, runQueryExplain, runTenancyScan };
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// migration-scan — flag unsafe migration patterns (#A17).
|
|
2
|
+
//
|
|
3
|
+
// Migration reviews are where data-layer review adds the most value. We
|
|
4
|
+
// scan .sql, alembic versions, prisma migrations, knex migrations for
|
|
5
|
+
// patterns that lock the table, drop data, or block app writes during a
|
|
6
|
+
// long backfill.
|
|
7
|
+
|
|
8
|
+
import fsp from "node:fs/promises";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
|
|
11
|
+
import { createFinding, findLineMatches, getLineContent, toPosix, walkRepoFiles } from "./base.js";
|
|
12
|
+
|
|
13
|
+
const MIGRATION_EXTENSIONS = new Set([".sql", ".py"]);
|
|
14
|
+
|
|
15
|
+
function isMigrationPath(relPath) {
|
|
16
|
+
const p = toPosix(relPath);
|
|
17
|
+
return (
|
|
18
|
+
/(^|\/)migrations?\//i.test(p) ||
|
|
19
|
+
/(^|\/)alembic\/versions\//.test(p) ||
|
|
20
|
+
/(^|\/)prisma\/migrations\//.test(p) ||
|
|
21
|
+
/(^|\/)knex\/migrations?\//i.test(p) ||
|
|
22
|
+
/(^|\/)db\/migrate\//.test(p) // Rails
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const RULES = [
|
|
27
|
+
{
|
|
28
|
+
id: "migration.drop-table",
|
|
29
|
+
pattern: /\bDROP\s+TABLE\b/i,
|
|
30
|
+
severity: "P0",
|
|
31
|
+
rootCause:
|
|
32
|
+
"DROP TABLE in a migration deletes data irreversibly. Even if the table seems unused, a rollback can't recover rows without a backup.",
|
|
33
|
+
recommendedFix:
|
|
34
|
+
"Phase the change: (1) stop writing to the table; (2) wait long enough for any in-flight reads to drain; (3) rename to `_<table>_deprecated` for N days; (4) then DROP once restoration is impossible.",
|
|
35
|
+
confidence: 0.95,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: "migration.drop-column",
|
|
39
|
+
pattern: /\bDROP\s+COLUMN\b/i,
|
|
40
|
+
severity: "P1",
|
|
41
|
+
rootCause:
|
|
42
|
+
"DROP COLUMN blocks writers from rolling back gracefully (the app still references the column until redeployed).",
|
|
43
|
+
recommendedFix:
|
|
44
|
+
"Migrate in two phases: remove app reads/writes first, deploy, then drop the column in a follow-up migration.",
|
|
45
|
+
confidence: 0.85,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: "migration.add-column-not-null-no-default",
|
|
49
|
+
pattern: /ALTER\s+TABLE[\s\S]{0,200}?ADD\s+(?:COLUMN\s+)?[`"]?\w+[`"]?\s+[\w()]+\s+NOT\s+NULL(?!\s+DEFAULT)/i,
|
|
50
|
+
severity: "P0",
|
|
51
|
+
rootCause:
|
|
52
|
+
"Adding a NOT NULL column with no DEFAULT rewrites every existing row at migration time — long AccessExclusiveLock on large tables, breaks writes.",
|
|
53
|
+
recommendedFix:
|
|
54
|
+
"Add the column nullable first, backfill in batches, then set NOT NULL (and DEFAULT) once the backfill is complete.",
|
|
55
|
+
confidence: 0.9,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: "migration.no-concurrent-index",
|
|
59
|
+
// Postgres-specific: CREATE INDEX without CONCURRENTLY blocks writes
|
|
60
|
+
pattern: /CREATE\s+(?!UNIQUE\s+)INDEX\s+(?!CONCURRENTLY)\b/i,
|
|
61
|
+
severity: "P1",
|
|
62
|
+
rootCause:
|
|
63
|
+
"CREATE INDEX without CONCURRENTLY holds a ShareLock on the table — no writes while the index builds. On hot tables this is effectively an outage.",
|
|
64
|
+
recommendedFix:
|
|
65
|
+
"Use `CREATE INDEX CONCURRENTLY`. It takes longer and can't run inside a transaction, but writes proceed throughout.",
|
|
66
|
+
confidence: 0.7,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: "migration.unbatched-update",
|
|
70
|
+
pattern: /\bUPDATE\s+[\w.`"]+\s+SET\b(?![\s\S]*?WHERE\s+[\s\S]{0,200}?\bLIMIT\b)/i,
|
|
71
|
+
severity: "P1",
|
|
72
|
+
rootCause:
|
|
73
|
+
"Unbatched UPDATE of an entire table — long transaction, large WAL / redo log, potential replication lag or disk fill.",
|
|
74
|
+
recommendedFix:
|
|
75
|
+
"Batch: `WHERE id BETWEEN :lo AND :hi LIMIT n` and commit per batch. For Postgres add pg_sleep between batches to give autovacuum time to catch up.",
|
|
76
|
+
confidence: 0.55,
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
export async function runMigrationScan({ rootPath, files = null } = {}) {
|
|
81
|
+
const resolvedRoot = path.resolve(String(rootPath || "."));
|
|
82
|
+
const iterator =
|
|
83
|
+
Array.isArray(files) && files.length > 0
|
|
84
|
+
? iterateExplicitFiles(resolvedRoot, files)
|
|
85
|
+
: walkRepoFiles({ rootPath: resolvedRoot, extensions: MIGRATION_EXTENSIONS });
|
|
86
|
+
|
|
87
|
+
const findings = [];
|
|
88
|
+
for await (const { fullPath, relativePath } of iterator) {
|
|
89
|
+
if (!isMigrationPath(relativePath)) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
let content;
|
|
93
|
+
try {
|
|
94
|
+
content = await fsp.readFile(fullPath, "utf-8");
|
|
95
|
+
} catch {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
for (const rule of RULES) {
|
|
99
|
+
for (const match of findLineMatches(content, rule.pattern)) {
|
|
100
|
+
findings.push(
|
|
101
|
+
createFinding({
|
|
102
|
+
tool: "migration-scan",
|
|
103
|
+
kind: rule.id,
|
|
104
|
+
severity: rule.severity,
|
|
105
|
+
file: toPosix(relativePath),
|
|
106
|
+
line: match.line,
|
|
107
|
+
evidence: getLineContent(content, match.line),
|
|
108
|
+
rootCause: rule.rootCause,
|
|
109
|
+
recommendedFix: rule.recommendedFix,
|
|
110
|
+
confidence: rule.confidence,
|
|
111
|
+
})
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return findings;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function* iterateExplicitFiles(resolvedRoot, files) {
|
|
120
|
+
for (const file of files) {
|
|
121
|
+
const trimmed = String(file || "").trim();
|
|
122
|
+
if (!trimmed) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const fullPath = path.isAbsolute(trimmed)
|
|
126
|
+
? trimmed
|
|
127
|
+
: path.join(resolvedRoot, trimmed);
|
|
128
|
+
const relativePath = path
|
|
129
|
+
.relative(resolvedRoot, fullPath)
|
|
130
|
+
.replace(/\\/g, "/");
|
|
131
|
+
yield { fullPath, relativePath };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export { RULES as MIGRATION_RULES, isMigrationPath };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// query-explain — flag unbounded / N+1 query shapes (#A17).
|
|
2
|
+
//
|
|
3
|
+
// We scan code for common data-access anti-patterns. Real EXPLAIN output is
|
|
4
|
+
// a database-side operation; this tool focuses on the source-level red
|
|
5
|
+
// flags (missing LIMIT, findAll in loops, string-concatenated SQL) that
|
|
6
|
+
// typically predict explosive queries before the DB actually runs them.
|
|
7
|
+
|
|
8
|
+
import fsp from "node:fs/promises";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
|
|
11
|
+
import { createFinding, findLineMatches, getLineContent, toPosix, walkRepoFiles } from "./base.js";
|
|
12
|
+
|
|
13
|
+
const CODE_EXTENSIONS = new Set([
|
|
14
|
+
".js",
|
|
15
|
+
".jsx",
|
|
16
|
+
".ts",
|
|
17
|
+
".tsx",
|
|
18
|
+
".mjs",
|
|
19
|
+
".cjs",
|
|
20
|
+
".py",
|
|
21
|
+
".go",
|
|
22
|
+
".rb",
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const RULES = [
|
|
26
|
+
{
|
|
27
|
+
id: "data.query-no-limit",
|
|
28
|
+
pattern: /SELECT[\s\S]{0,200}?FROM\s+[\w.`"]+\s*(?!.*\b(LIMIT|FETCH FIRST)\b)(?:WHERE\s[^;]*)?;?\s*[`'"]/i,
|
|
29
|
+
severity: "P1",
|
|
30
|
+
rootCause:
|
|
31
|
+
"Raw SELECT without LIMIT / FETCH FIRST. On a growing table this returns more rows every day and will eventually OOM the caller.",
|
|
32
|
+
recommendedFix:
|
|
33
|
+
"Always paginate: add LIMIT with a configured page size, or switch to cursor-based iteration (`WHERE id > :lastId ORDER BY id LIMIT n`).",
|
|
34
|
+
confidence: 0.6,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: "data.n-plus-one-findall-in-loop",
|
|
38
|
+
pattern: /for\s*\([^)]*\)\s*\{[\s\S]{0,400}?\b(?:findAll|findMany|find_one|find_all|objects\.all|objects\.filter|Model\.\w+|repository\.\w+|db\.[a-z_]+\.find)\s*\(/,
|
|
39
|
+
severity: "P1",
|
|
40
|
+
rootCause:
|
|
41
|
+
"Data-access call inside a for-loop body — classic N+1. Each iteration issues another round-trip to the database.",
|
|
42
|
+
recommendedFix:
|
|
43
|
+
"Batch the loop: fetch once with `WHERE id IN (…)` or an eager-loaded join; or use a dataloader (JS) / prefetch_related (Django) / bullet gem (Rails).",
|
|
44
|
+
confidence: 0.65,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: "data.string-concat-sql",
|
|
48
|
+
pattern: /(?:query|execute|db\.raw|sequelize\.query|knex\.raw|\.exec)\s*\(\s*[`'"][^`'"]*[`'"]\s*\+/,
|
|
49
|
+
severity: "P0",
|
|
50
|
+
rootCause:
|
|
51
|
+
"SQL built via string concatenation — if any concatenated term is user input, this is a SQLi path.",
|
|
52
|
+
recommendedFix:
|
|
53
|
+
"Use parameterized queries / prepared statements. Every major driver supports `?` / `$1` / `:named` placeholders.",
|
|
54
|
+
confidence: 0.85,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: "data.select-star",
|
|
58
|
+
pattern: /SELECT\s+\*\s+FROM\s+[\w.`"]+/i,
|
|
59
|
+
severity: "P3",
|
|
60
|
+
rootCause:
|
|
61
|
+
"`SELECT *` binds the caller to every column the table happens to have — a schema change (adding a BYTEA / LONGTEXT) can silently blow up payload size.",
|
|
62
|
+
recommendedFix:
|
|
63
|
+
"Enumerate the columns you actually need. If you really need everything, wrap in a view so the contract is explicit.",
|
|
64
|
+
confidence: 0.8,
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
export async function runQueryExplain({ rootPath, files = null } = {}) {
|
|
69
|
+
const resolvedRoot = path.resolve(String(rootPath || "."));
|
|
70
|
+
const iterator =
|
|
71
|
+
Array.isArray(files) && files.length > 0
|
|
72
|
+
? iterateExplicitFiles(resolvedRoot, files)
|
|
73
|
+
: walkRepoFiles({ rootPath: resolvedRoot, extensions: CODE_EXTENSIONS });
|
|
74
|
+
|
|
75
|
+
const findings = [];
|
|
76
|
+
for await (const { fullPath, relativePath } of iterator) {
|
|
77
|
+
let content;
|
|
78
|
+
try {
|
|
79
|
+
content = await fsp.readFile(fullPath, "utf-8");
|
|
80
|
+
} catch {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
for (const rule of RULES) {
|
|
84
|
+
for (const match of findLineMatches(content, rule.pattern)) {
|
|
85
|
+
findings.push(
|
|
86
|
+
createFinding({
|
|
87
|
+
tool: "query-explain",
|
|
88
|
+
kind: rule.id,
|
|
89
|
+
severity: rule.severity,
|
|
90
|
+
file: toPosix(relativePath),
|
|
91
|
+
line: match.line,
|
|
92
|
+
evidence: getLineContent(content, match.line),
|
|
93
|
+
rootCause: rule.rootCause,
|
|
94
|
+
recommendedFix: rule.recommendedFix,
|
|
95
|
+
confidence: rule.confidence,
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return findings;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function* iterateExplicitFiles(resolvedRoot, files) {
|
|
105
|
+
for (const file of files) {
|
|
106
|
+
const trimmed = String(file || "").trim();
|
|
107
|
+
if (!trimmed) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const fullPath = path.isAbsolute(trimmed)
|
|
111
|
+
? trimmed
|
|
112
|
+
: path.join(resolvedRoot, trimmed);
|
|
113
|
+
const relativePath = path
|
|
114
|
+
.relative(resolvedRoot, fullPath)
|
|
115
|
+
.replace(/\\/g, "/");
|
|
116
|
+
yield { fullPath, relativePath };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export { RULES as QUERY_RULES };
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// tenancy-scan — flag queries that may leak across tenants (#A17).
|
|
2
|
+
//
|
|
3
|
+
// In a multi-tenant system every row-level query needs to constrain on
|
|
4
|
+
// tenant_id / org_id / workspace_id (whatever the ambient tenancy column
|
|
5
|
+
// is). Missing that filter is a cross-tenant data leak — classic P0.
|
|
6
|
+
//
|
|
7
|
+
// Heuristic: we look for "tenancy-table" signals (tables or models whose
|
|
8
|
+
// schema mentions tenant_id / org_id / workspace_id) and then in application
|
|
9
|
+
// code we flag queries against those tables that don't include the tenancy
|
|
10
|
+
// column in the WHERE.
|
|
11
|
+
|
|
12
|
+
import fsp from "node:fs/promises";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
|
|
15
|
+
import { createFinding, toPosix, walkRepoFiles } from "./base.js";
|
|
16
|
+
|
|
17
|
+
const CODE_EXTENSIONS = new Set([
|
|
18
|
+
".js",
|
|
19
|
+
".jsx",
|
|
20
|
+
".ts",
|
|
21
|
+
".tsx",
|
|
22
|
+
".mjs",
|
|
23
|
+
".cjs",
|
|
24
|
+
".py",
|
|
25
|
+
".go",
|
|
26
|
+
".rb",
|
|
27
|
+
".sql",
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
const TENANCY_COLUMNS = ["tenant_id", "org_id", "organization_id", "workspace_id", "account_id"];
|
|
31
|
+
|
|
32
|
+
function tenancyTableRegex() {
|
|
33
|
+
// Match a schema / model declaration (CREATE TABLE, @Column, JS class,
|
|
34
|
+
// Python class) that sits within ~2 KB of one of the tenancy column
|
|
35
|
+
// names.
|
|
36
|
+
return new RegExp(
|
|
37
|
+
`(?:CREATE\\s+TABLE\\s+[\\w.]+|@Column|class\\s+\\w+\\s*[({:]|class\\s+\\w+\\s*\\{|model\\s*:\\s*\\w+)[\\s\\S]{0,2000}?(${TENANCY_COLUMNS.join("|")})`,
|
|
38
|
+
"gi"
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function queryRegex(tableName) {
|
|
43
|
+
// Match a SELECT / UPDATE / DELETE referencing the table name.
|
|
44
|
+
return new RegExp(
|
|
45
|
+
`(?:SELECT[\\s\\S]*?FROM|UPDATE|DELETE\\s+FROM)\\s+[\\w.\`"]*?\\b${tableName}\\b`,
|
|
46
|
+
"gi"
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function collectTenancyTables(rootPath) {
|
|
51
|
+
const tables = new Set();
|
|
52
|
+
for await (const { fullPath, relativePath } of walkRepoFiles({
|
|
53
|
+
rootPath,
|
|
54
|
+
extensions: CODE_EXTENSIONS,
|
|
55
|
+
})) {
|
|
56
|
+
const p = toPosix(relativePath);
|
|
57
|
+
const isSchemaFile =
|
|
58
|
+
/(^|\/)(schema|models?)\//i.test(p) ||
|
|
59
|
+
/(^|\/)migrations?\//i.test(p) ||
|
|
60
|
+
/(^|\/)alembic\/versions\//i.test(p) ||
|
|
61
|
+
/(^|\/)prisma\//i.test(p);
|
|
62
|
+
if (!isSchemaFile) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
let content;
|
|
66
|
+
try {
|
|
67
|
+
content = await fsp.readFile(fullPath, "utf-8");
|
|
68
|
+
} catch {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const regex = tenancyTableRegex();
|
|
72
|
+
let match;
|
|
73
|
+
while ((match = regex.exec(content)) !== null) {
|
|
74
|
+
// Pull the table / class name from the match prefix.
|
|
75
|
+
const prefix = match[0];
|
|
76
|
+
const tableMatch = prefix.match(/CREATE\s+TABLE\s+[`"]?(\w+)/i);
|
|
77
|
+
if (tableMatch) {
|
|
78
|
+
tables.add(tableMatch[1].toLowerCase());
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const classMatch = prefix.match(/class\s+(\w+)/);
|
|
82
|
+
if (classMatch) {
|
|
83
|
+
// Convention: class Foo → table foos / foo. Keep both.
|
|
84
|
+
const name = classMatch[1].toLowerCase();
|
|
85
|
+
tables.add(name);
|
|
86
|
+
tables.add(`${name}s`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return tables;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function runTenancyScan({ rootPath, files = null, tenancyTables = null } = {}) {
|
|
94
|
+
const resolvedRoot = path.resolve(String(rootPath || "."));
|
|
95
|
+
const tables =
|
|
96
|
+
tenancyTables instanceof Set
|
|
97
|
+
? tenancyTables
|
|
98
|
+
: await collectTenancyTables(resolvedRoot);
|
|
99
|
+
if (tables.size === 0) {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const findings = [];
|
|
104
|
+
const iterator =
|
|
105
|
+
Array.isArray(files) && files.length > 0
|
|
106
|
+
? iterateExplicitFiles(resolvedRoot, files)
|
|
107
|
+
: walkRepoFiles({ rootPath: resolvedRoot, extensions: CODE_EXTENSIONS });
|
|
108
|
+
|
|
109
|
+
for await (const { fullPath, relativePath } of iterator) {
|
|
110
|
+
let content;
|
|
111
|
+
try {
|
|
112
|
+
content = await fsp.readFile(fullPath, "utf-8");
|
|
113
|
+
} catch {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
for (const table of tables) {
|
|
117
|
+
const regex = queryRegex(table);
|
|
118
|
+
let match;
|
|
119
|
+
while ((match = regex.exec(content)) !== null) {
|
|
120
|
+
// Look at a ~200-char window after the match for a tenancy column
|
|
121
|
+
// in the WHERE clause.
|
|
122
|
+
const window = content.slice(match.index, match.index + 400);
|
|
123
|
+
const hasTenancyFilter = TENANCY_COLUMNS.some((col) =>
|
|
124
|
+
new RegExp(`\\b${col}\\s*(?:=|IN|\\?)`).test(window)
|
|
125
|
+
);
|
|
126
|
+
if (hasTenancyFilter) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const lineIndex = content.slice(0, match.index).split(/\r?\n/).length;
|
|
130
|
+
const lineContent = content.split(/\r?\n/)[lineIndex - 1] || "";
|
|
131
|
+
findings.push(
|
|
132
|
+
createFinding({
|
|
133
|
+
tool: "tenancy-scan",
|
|
134
|
+
kind: "data.missing-tenancy-filter",
|
|
135
|
+
severity: "P0",
|
|
136
|
+
file: toPosix(relativePath),
|
|
137
|
+
line: lineIndex,
|
|
138
|
+
evidence: lineContent.trim(),
|
|
139
|
+
rootCause: `Query against tenancy-owning table '${table}' has no tenant_id / org_id / workspace_id constraint in the WHERE.`,
|
|
140
|
+
recommendedFix: `Add a tenancy filter: "WHERE tenant_id = :tenantId" (or the equivalent tenancy column). Enforce with a database RLS policy when possible.`,
|
|
141
|
+
confidence: 0.7,
|
|
142
|
+
})
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return findings;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function* iterateExplicitFiles(resolvedRoot, files) {
|
|
151
|
+
for (const file of files) {
|
|
152
|
+
const trimmed = String(file || "").trim();
|
|
153
|
+
if (!trimmed) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const fullPath = path.isAbsolute(trimmed)
|
|
157
|
+
? trimmed
|
|
158
|
+
: path.join(resolvedRoot, trimmed);
|
|
159
|
+
const relativePath = path
|
|
160
|
+
.relative(resolvedRoot, fullPath)
|
|
161
|
+
.replace(/\\/g, "/");
|
|
162
|
+
yield { fullPath, relativePath };
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export { TENANCY_COLUMNS, collectTenancyTables };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Samir (documentation persona) — barrel export (#A23).
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
DOCUMENTATION_TOOLS,
|
|
5
|
+
DOCUMENTATION_TOOL_IDS,
|
|
6
|
+
dispatchDocumentationTool,
|
|
7
|
+
runAllDocumentationTools,
|
|
8
|
+
runApiDiff,
|
|
9
|
+
runDeadLinkCheck,
|
|
10
|
+
runDocstringCoverage,
|
|
11
|
+
runReadmeFreshness,
|
|
12
|
+
} from "./tools/index.js";
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// api-diff — flag API endpoints without corresponding doc coverage (#A23).
|
|
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
|
+
const CODE_EXTENSIONS = new Set([".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs", ".py"]);
|
|
9
|
+
const DOC_EXTENSIONS = new Set([".md", ".yaml", ".yml"]);
|
|
10
|
+
|
|
11
|
+
const ROUTE_REGEX = /\b(?:app|router|server|fastify|hono)\.(get|post|put|patch|delete)\s*\(\s*['"`]([^'"`]+)['"`]/g;
|
|
12
|
+
const NEXT_REGEX = /^export\s+async\s+function\s+(GET|POST|PUT|PATCH|DELETE)\s*\(/gm;
|
|
13
|
+
|
|
14
|
+
async function collectEndpoints(rootPath) {
|
|
15
|
+
const endpoints = new Set();
|
|
16
|
+
for await (const { fullPath, relativePath } of walkRepoFiles({
|
|
17
|
+
rootPath,
|
|
18
|
+
extensions: CODE_EXTENSIONS,
|
|
19
|
+
})) {
|
|
20
|
+
const rel = toPosix(relativePath);
|
|
21
|
+
if (/(^|\/)(tests?|__tests__|specs?)\//.test(rel)) continue;
|
|
22
|
+
let content;
|
|
23
|
+
try {
|
|
24
|
+
content = await fsp.readFile(fullPath, "utf-8");
|
|
25
|
+
} catch {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
let m;
|
|
29
|
+
while ((m = ROUTE_REGEX.exec(content)) !== null) {
|
|
30
|
+
endpoints.add(`${m[1].toUpperCase()} ${m[2]}`);
|
|
31
|
+
}
|
|
32
|
+
ROUTE_REGEX.lastIndex = 0;
|
|
33
|
+
if (/\/api\//.test(rel)) {
|
|
34
|
+
while ((m = NEXT_REGEX.exec(content)) !== null) {
|
|
35
|
+
const route = rel.replace(/^.*\/api\//, "/api/").replace(/\/route\.(ts|js)x?$/, "");
|
|
36
|
+
endpoints.add(`${m[1]} ${route}`);
|
|
37
|
+
}
|
|
38
|
+
NEXT_REGEX.lastIndex = 0;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return endpoints;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function collectDocumentedEndpoints(rootPath) {
|
|
45
|
+
const documented = new Set();
|
|
46
|
+
for await (const { fullPath, relativePath } of walkRepoFiles({
|
|
47
|
+
rootPath,
|
|
48
|
+
extensions: DOC_EXTENSIONS,
|
|
49
|
+
})) {
|
|
50
|
+
const rel = toPosix(relativePath);
|
|
51
|
+
if (!/(^|\/)(docs?|api|spec)\//i.test(rel) && !/API\.md$/.test(rel) && !/openapi|swagger/i.test(rel)) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
let content;
|
|
55
|
+
try {
|
|
56
|
+
content = await fsp.readFile(fullPath, "utf-8");
|
|
57
|
+
} catch {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const regex = /\b(GET|POST|PUT|PATCH|DELETE)\s+(\/[^\s`'"]*)/g;
|
|
61
|
+
let m;
|
|
62
|
+
while ((m = regex.exec(content)) !== null) {
|
|
63
|
+
documented.add(`${m[1]} ${m[2]}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return documented;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function runApiDiff({ rootPath } = {}) {
|
|
70
|
+
const resolvedRoot = path.resolve(String(rootPath || "."));
|
|
71
|
+
const endpoints = await collectEndpoints(resolvedRoot);
|
|
72
|
+
const documented = await collectDocumentedEndpoints(resolvedRoot);
|
|
73
|
+
const findings = [];
|
|
74
|
+
for (const endpoint of endpoints) {
|
|
75
|
+
if (documented.has(endpoint)) continue;
|
|
76
|
+
findings.push(
|
|
77
|
+
createFinding({
|
|
78
|
+
tool: "api-diff",
|
|
79
|
+
kind: "documentation.undocumented-endpoint",
|
|
80
|
+
severity: "P3",
|
|
81
|
+
file: "",
|
|
82
|
+
line: 0,
|
|
83
|
+
evidence: `${endpoint} — no matching entry found in docs/, openapi*, swagger*, API.md`,
|
|
84
|
+
rootCause: "Endpoints that ship without docs can't be discovered by downstream clients and bit-rot silently.",
|
|
85
|
+
recommendedFix: "Add the endpoint to openapi.yaml / API.md / docs/api.md with request + response shape and auth requirements.",
|
|
86
|
+
confidence: 0.45,
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return findings;
|
|
91
|
+
}
|