archsutra-ai 0.1.5 → 0.2.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.
Files changed (113) hide show
  1. package/CHANGELOG.md +58 -6
  2. package/README.md +87 -15
  3. package/dist/audit.js +125 -44
  4. package/dist/cli.js +184 -96
  5. package/dist/drift.js +29 -15
  6. package/dist/fsutil.js +117 -20
  7. package/dist/history.js +40 -0
  8. package/dist/html.js +10 -8
  9. package/dist/map.js +26 -5
  10. package/dist/mcp.js +70 -55
  11. package/dist/redact.js +24 -11
  12. package/dist/report.js +69 -19
  13. package/dist/rules-extra.js +59 -0
  14. package/dist/secret-patterns.js +69 -0
  15. package/dist/suppress.js +31 -19
  16. package/dist/verify.js +2 -2
  17. package/dist/write.js +71 -0
  18. package/docs/architecture/overview.html +29 -12
  19. package/docs/architecture/overview.md +2 -2
  20. package/docs/architecture/threat-model.html +28 -11
  21. package/docs/assets/charts/coverage-dark.svg +11 -0
  22. package/docs/assets/charts/coverage.svg +11 -0
  23. package/docs/assets/charts/finding-anatomy-dark.svg +20 -0
  24. package/docs/assets/charts/finding-anatomy.svg +20 -0
  25. package/docs/assets/charts/pipeline-dark.svg +13 -0
  26. package/docs/assets/charts/pipeline.svg +13 -0
  27. package/docs/assets/charts/precision-by-batch-dark.svg +12 -0
  28. package/docs/assets/charts/precision-by-batch.svg +12 -0
  29. package/docs/assets/charts/precision-by-rule-dark.svg +12 -0
  30. package/docs/assets/charts/precision-by-rule.svg +12 -0
  31. package/docs/assets/charts/sample-findings-by-severity-dark.svg +11 -0
  32. package/docs/assets/charts/sample-findings-by-severity.svg +11 -0
  33. package/docs/assets/charts/scan-time-dark.svg +11 -0
  34. package/docs/assets/charts/scan-time.svg +11 -0
  35. package/docs/assets/site.css +259 -138
  36. package/docs/assets/site.js +92 -6
  37. package/docs/community/good-first-issues.html +28 -11
  38. package/docs/compatibility/matrix.html +28 -11
  39. package/docs/compatibility/smoke-tests/index.html +28 -11
  40. package/docs/decisions/ADR-0001-deterministic-cli-plus-ide-skills.html +28 -11
  41. package/docs/guides/cheat-sheet.html +100 -0
  42. package/docs/guides/cheat-sheet.md +146 -0
  43. package/docs/guides/ci-recipes.html +170 -0
  44. package/docs/guides/ci-recipes.md +176 -0
  45. package/docs/guides/evidence-at-a-glance.html +93 -0
  46. package/docs/guides/evidence-at-a-glance.md +65 -0
  47. package/docs/guides/getting-started.html +151 -0
  48. package/docs/guides/getting-started.md +160 -0
  49. package/docs/guides/how-it-works.html +161 -0
  50. package/docs/guides/how-it-works.md +148 -0
  51. package/docs/guides/mcp-server.html +99 -0
  52. package/docs/guides/mcp-server.md +81 -0
  53. package/docs/guides/reading-a-report.html +119 -0
  54. package/docs/guides/reading-a-report.md +111 -0
  55. package/docs/guides/real-world-scenarios.html +287 -0
  56. package/docs/guides/real-world-scenarios.md +377 -0
  57. package/docs/handbook/01-executive-summary.html +30 -13
  58. package/docs/handbook/01-executive-summary.md +2 -2
  59. package/docs/handbook/02-functional-specification.html +30 -13
  60. package/docs/handbook/02-functional-specification.md +3 -3
  61. package/docs/handbook/03-technical-specification.html +31 -14
  62. package/docs/handbook/03-technical-specification.md +3 -3
  63. package/docs/handbook/04-architecture.html +29 -12
  64. package/docs/handbook/04-architecture.md +1 -1
  65. package/docs/handbook/05-user-guide.html +33 -15
  66. package/docs/handbook/05-user-guide.md +5 -4
  67. package/docs/handbook/06-cli-reference.html +52 -16
  68. package/docs/handbook/06-cli-reference.md +47 -4
  69. package/docs/handbook/07-security-privacy-legal.html +31 -12
  70. package/docs/handbook/07-security-privacy-legal.md +4 -0
  71. package/docs/handbook/08-testing-and-proof.html +32 -15
  72. package/docs/handbook/08-testing-and-proof.md +4 -4
  73. package/docs/handbook/09-compatibility-and-roadmap.html +33 -16
  74. package/docs/handbook/09-compatibility-and-roadmap.md +8 -7
  75. package/docs/handbook/10-contributor-guide.html +29 -12
  76. package/docs/handbook/10-contributor-guide.md +1 -1
  77. package/docs/handbook/11-glossary-and-faq.html +34 -13
  78. package/docs/handbook/11-glossary-and-faq.md +7 -1
  79. package/docs/handbook/12-rule-catalog.html +59 -19
  80. package/docs/handbook/12-rule-catalog.md +62 -5
  81. package/docs/handbook/13-trust-and-assurance.html +29 -12
  82. package/docs/handbook/13-trust-and-assurance.md +1 -1
  83. package/docs/handbook/14-real-world-evaluation.html +28 -11
  84. package/docs/handbook/15-supply-chain-and-release.html +28 -11
  85. package/docs/handbook/16-performance-and-quality-metrics.html +28 -11
  86. package/docs/handbook/16-performance-and-quality-metrics.md +1 -1
  87. package/docs/handbook/README.md +4 -2
  88. package/docs/handbook/index.html +31 -13
  89. package/docs/index.html +101 -51
  90. package/docs/legal/legal-review-brief.html +28 -11
  91. package/docs/legal/trademark-and-name-clearance.html +28 -11
  92. package/docs/proof/accessibility.html +28 -11
  93. package/docs/proof/benchmarks.json +9 -9
  94. package/docs/proof/benchmarks.md +4 -4
  95. package/docs/proof/test-results.txt +56 -40
  96. package/docs/rfc/0001-archsutra-v0.1.html +28 -11
  97. package/docs/sample-report/architecture-register.json +46 -0
  98. package/docs/sample-report/audit-report.html +123 -0
  99. package/docs/sample-report/audit-report.md +314 -0
  100. package/docs/sample-report/current-state.html +77 -0
  101. package/docs/sample-report/current-state.md +51 -0
  102. package/docs/sample-report/findings.json +478 -0
  103. package/docs/sample-report/findings.sarif +754 -0
  104. package/docs/sample-report/index.html +57 -0
  105. package/docs/sample-report/overview.md +11 -0
  106. package/docs/search-index.json +1 -0
  107. package/docs/sitemap.xml +39 -28
  108. package/llms.txt +12 -3
  109. package/package.json +3 -2
  110. package/schemas/findings.schema.json +4 -3
  111. package/skills/architecture-audit/SKILL.md +2 -2
  112. package/skills/architecture-audit/references/report-template.md +1 -1
  113. package/skills/architecture-verification/references/fitness-functions.md +1 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,64 @@
2
2
 
3
3
  All notable changes follow [Semantic Versioning](https://semver.org/).
4
4
 
5
+ ## 0.2.1 - 2026-12-01
6
+
7
+ Documentation only. The CLI behavior is the same as 0.2.0.
8
+
9
+ ### Documentation
10
+ - README said 36 tests. The suite is 52 passed, 0 failed (2026-12-01, Node v24.15.0, Windows 11). The proof file already had 52. The badge and the evidence table did not.
11
+ - README roadmap marked the Go, Java, Kotlin, C#, and Rust import graph, and the suppression and baseline gate, as not done. Both shipped before 0.2.0.
12
+ - Handbook known-gaps heading still said v0.1.3. Suppression and MCP text now match 0.2.0.
13
+ - `llms.txt` still said version 0.1.4.
14
+ - Install examples pin `archsutra-ai@0.2.1`.
15
+
16
+ ## 0.2.0 - 2026-12-01
17
+
18
+ Trust fixes from a deep review, a gate that fails only on new problems, wider secret and code rules, and a working MCP server.
19
+
20
+ ### Upgrading from 0.1.5
21
+ - The overview report is now `overview.md`. Update links that point at the generated `README.md`.
22
+ - Report commands stop (exit 2) instead of overwriting a file they did not create. Unknown options and missing paths also exit 2, so check CI scripts.
23
+ - A first `drift` against a 0.1.5 baseline shows previously hidden locations as added. Create a new baseline with `archsutra baseline create`.
24
+ - New rules and secret formats can raise new findings. Their precision has not been measured on real repositories.
25
+
26
+ ### Added
27
+ - `baseline create|update`, `audit --fail-on-new`, `exitReason` in JSON, `suppressions` command; suppressions accept a fingerprint or a glob and record an owner.
28
+ - More than 60 provider secret formats, credential files, `--history`.
29
+ - Rules AS-SEC-009 to AS-SEC-017; multi-line SQL; CWE and OWASP class on findings.
30
+ - `--include`, `--exclude`, `.archsutraignore`, `--respect-gitignore`, `--no-score`; scorecard shows rule count and confidence.
31
+ - Skipped paths and per-folder coverage in reports; declared workspaces define modules.
32
+ - SARIF: `%SRCROOT%`, CWE taxonomy, suppressions. CI validates SARIF and uploads it to code scanning.
33
+ - `scripts/docs-lint.mjs` runs in CI; MCP server guide.
34
+ - Rules AS-SEC-007 (unsafe deserialization) and AS-SEC-008 (weak hash). `--strict` (exit 6), `--max-files`, `--max-bytes`, `--time-budget`, `mcp --root`.
35
+
36
+ ### Changed
37
+ - Findings schema is 1.1.0; 1.0.0 files are still read.
38
+ - A scan that hits a limit now samples every folder instead of stopping alphabetically. `bin`, `build`, `out`, `obj`, `target` are scanned unless they are proven output.
39
+ - The overview report is `overview.md`, not `README.md`. `--output` always needs a value.
40
+ - Scorecard says `no findings` instead of `strong`; three or more low findings give `adequate`. AS-AI-001 is `info`.
41
+ - `#NNN` in a finding ID counts within its rule. Compared with a 0.1.5 baseline, previously hidden locations show up as added once.
42
+ - Not yet re-measured: precision on the 52-repository corpus with the new rules.
43
+
44
+ ### Fixed
45
+ - Report commands overwrote existing files such as your `README.md`. They now stop (exit 2) unless the file was generated by ArchSutra; `--force` backs it up first.
46
+ - `mcp` answered only after stdin closed and used the wrong framing. It is now a streaming newline-delimited JSON-RPC server limited to `--root`.
47
+ - A missing path or a mistyped option exited 0. Both now exit 2.
48
+ - Secrets in comments, tests, docs, or on lines containing "example" were skipped. More providers, connection strings and PGP or encrypted key blocks are detected.
49
+ - `model.eval()` was reported as code execution. f-string SQL was missed.
50
+ - Only 10 locations per rule were kept. All are in JSON and SARIF now; `drift` compares one location at a time; a path suppression hides only that path.
51
+ - SARIF now has the tool version, fingerprints, `security-severity`, rule help, and keeps repository-level findings.
52
+ - The checked-in sample report was regenerated from the wrong folder and showed no findings. Restored.
53
+
54
+ ### Documentation
55
+ - New "Start here" section on the docs site and in the repository: Get started in 5 minutes, seven real-world scenarios (legacy monolith, CI gate with baseline, architecture choice, AI agent threat model, board report, leaked key, strangler migration), How it works in pictures (seven diagrams), Reading and triaging a report, CI recipes, Cheat sheet, Evidence at a glance. Command output in the guides is real; anything illustrative is labeled.
56
+ - Charts (`docs/assets/charts/*.svg`) are generated from the proof data by `scripts/build-charts.mjs`: precision by batch and by rule, sample findings by severity, scan time, coverage, pipeline, finding anatomy.
57
+ - Site: redesigned landing page, search, callouts, figures, a hosted copy of the real sample report (`/sample-report/`).
58
+
59
+ ### Documentation corrections
60
+ - Docs now match the registry and CI. `archsutra-ai` is on npm (`0.1.2`, `0.1.3`). Homepage stats are 31 tests and Ubuntu plus Windows. OpenSSF Scorecard **5.7 / 10** (2026-11-06) is quoted with the failing checks. Install examples pin `archsutra-ai@0.1.3` because the `v0.1.2` tag has no `archsutra-ai` bin.
61
+ - Recorded the release split: no `v0.1.3` git tag, npm `0.1.3` `gitHead` is `4a7ab27`, no npm provenance. Next publish has to be `0.1.4` or later, from Actions.
62
+
5
63
  ## 0.1.5 - 2026-11-16
6
64
 
7
65
  First release that is tagged and published by the release workflow, so the GitHub release, the SBOM and checksums, the build attestation and the npm tarball come from one run of the same commit.
@@ -23,12 +81,6 @@ First release that is tagged and published by the release workflow, so the GitHu
23
81
  ### Changed
24
82
  - Release workflow publishes `npm publish --provenance --access public` after the GitHub release. This needs an npm trusted publisher for `release.yml`. `0.1.3` is not republished.
25
83
 
26
- ## Unreleased
27
-
28
- ### Changed
29
- - Docs now match the registry and CI. `archsutra-ai` is on npm (`0.1.2`, `0.1.3`). Homepage stats are 31 tests and Ubuntu plus Windows. OpenSSF Scorecard **5.7 / 10** (2026-11-06) is quoted with the failing checks. Install examples pin `archsutra-ai@0.1.3` because the `v0.1.2` tag has no `archsutra-ai` bin.
30
- - Recorded the release split: no `v0.1.3` git tag, npm `0.1.3` `gitHead` is `4a7ab27`, no npm provenance. Next publish has to be `0.1.4` or later, from Actions.
31
-
32
84
  ## 0.1.3 - 2026-11-06
33
85
 
34
86
  ### Fixed
package/README.md CHANGED
@@ -11,10 +11,12 @@
11
11
  [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
12
12
  ![Node](https://img.shields.io/badge/node-%E2%89%A520-339933)
13
13
  ![Runtime dependencies](https://img.shields.io/badge/runtime%20dependencies-0-brightgreen)
14
- ![Tests](https://img.shields.io/badge/tests-36%20passing-brightgreen)
14
+ ![Tests](https://img.shields.io/badge/tests-52%20passing-brightgreen)
15
15
  ![Coverage](https://img.shields.io/badge/coverage-92%25%20lines-brightgreen)
16
16
 
17
- [**Documentation site**](https://shahvatsalofficial.github.io/archsutra-ai/) · [Handbook](docs/handbook/README.md) · [**Trust and assurance register**](docs/handbook/13-trust-and-assurance.md) · [Real-world evaluation](docs/handbook/14-real-world-evaluation.md) · [Sample report](examples/brownfield-monolith/sample-output/audit-report.md)
17
+ [**Documentation site**](https://shahvatsalofficial.github.io/archsutra-ai/) · [**Get started in 5 minutes**](docs/guides/getting-started.md) · [Real-world scenarios](docs/guides/real-world-scenarios.md) · [Cheat sheet](docs/guides/cheat-sheet.md) · [Handbook](docs/handbook/README.md) · [Trust register](docs/handbook/13-trust-and-assurance.md)
18
+
19
+ <picture><source media="(prefers-color-scheme: dark)" srcset="docs/assets/charts/pipeline-dark.svg"><img src="docs/assets/charts/pipeline.svg" alt="ArchSutra pipeline: the CLI measures your repository read-only and produces evidence; your IDE model, guided by ArchSutra skills, verifies it and writes the report" width="860"></picture>
18
20
 
19
21
  </div>
20
22
 
@@ -30,6 +32,40 @@ Created by **[Vatsal Shah](https://shahvatsal.com)**. Licensed under Apache-2.0.
30
32
 
31
33
  [Why](#why-archsutra-ai) &middot; [60-second start](#60-second-start) &middot; [What you get](#what-you-get) &middot; [Proof](#proof-not-promises) &middot; [Sample output](#sample-output) &middot; [Supported IDEs](#supported-ai-ides) &middot; [Agents](#the-agent-team) &middot; [CLI](#cli-reference) &middot; [CI](#use-it-in-ci) &middot; [How it works](#how-it-works) &middot; [Security](#security-and-privacy) &middot; [Legal](#legal-and-trademarks) &middot; [Limitations](#limitations) &middot; [FAQ](#faq) &middot; [Roadmap](#roadmap) &middot; [Contribute](#contributing)
32
34
 
35
+ ## See it in action
36
+
37
+ ```text
38
+ $ npx archsutra-ai audit . --output arch-report
39
+
40
+ Files scanned: 7 Stack: TypeScript, Node.js
41
+ Findings: 12 (critical 0, high 3, medium 7, low 2)
42
+
43
+ HIGH SQL built by string interpolation src/services/user.ts:2 [observed]
44
+ HIGH Dynamic code or shell execution src/services/user.ts:3 [observed]
45
+ MEDIUM Circular dependency (src/api <-> src/db) src/api/routes.ts:1 [observed]
46
+
47
+ Security weak · Reliability not assessed · Cost not assessed
48
+ Open arch-report/index.html in a browser.
49
+ ```
50
+
51
+ That is real output for the sample project in this repository. The report opens as a web page with severity cards and a filter, and every report also exists as Markdown, JSON and SARIF. **[Open the real sample report](https://shahvatsalofficial.github.io/archsutra-ai/sample-report/audit-report.html)**.
52
+
53
+ ### Pick a story
54
+
55
+ Seven realistic situations with commands, output, diagrams and the decision made. Start with the one closest to yours.
56
+
57
+ | Scenario | Who | What you will see |
58
+ |---|---|---|
59
+ | [Day one on a legacy monolith](docs/guides/real-world-scenarios.md#1-day-one-on-a-legacy-monolith) | New tech lead | Audit, map, verify the highs, phased roadmap in two hours |
60
+ | [Stop regressions at the door](docs/guides/real-world-scenarios.md#2-stop-regressions-at-the-door) | Platform engineer | A CI gate that fails only on **new** problems, plus accepted risks with reasons and expiry |
61
+ | [A startup picks its architecture](docs/guides/real-world-scenarios.md#3-a-startup-picks-its-architecture) | Founder | Options scored with numbers, one ADR, a revisit trigger |
62
+ | [The support bot that can issue refunds](docs/guides/real-world-scenarios.md#4-the-support-bot-that-can-issue-refunds) | Engineer shipping an AI agent | Threat model with prompt-injection controls and tests |
63
+ | [The board asks "are we safe?"](docs/guides/real-world-scenarios.md#5-the-board-asks-are-we-safe) | Engineering manager | An honest one-paragraph answer from a scorecard that admits what it cannot see |
64
+ | [A key leaked into git](docs/guides/real-world-scenarios.md#6-a-key-leaked-into-git) | On-call engineer | Rotate first, find the rest, add the gate, nothing printed twice |
65
+ | [Strangler migration in six slices](docs/guides/real-world-scenarios.md#7-strangler-migration-in-six-slices) | Architect | Gantt, slice template, rollback and point of no return |
66
+
67
+ New to the report itself? [Reading and triaging a report](docs/guides/reading-a-report.md). Need the commands on one page? [Cheat sheet](docs/guides/cheat-sheet.md). Want the pictures behind the design? [How it works](docs/guides/how-it-works.md).
68
+
33
69
  ## Why ArchSutra AI
34
70
 
35
71
  | Problem | What ArchSutra does |
@@ -46,18 +82,18 @@ Requires Node.js 20+.
46
82
 
47
83
  ```bash
48
84
  # Windows and npm: this version installs a command named archsutra-ai.
49
- npx --yes archsutra-ai@0.1.3 audit . --output docs/architecture
85
+ npx --yes archsutra-ai@0.2.1 audit . --output docs/architecture
50
86
  # open docs/architecture/index.html
51
87
 
52
88
  # or from git (default branch has the same bin; the v0.1.2 tag does not):
53
89
  npx github:shahvatsalofficial/archsutra-ai audit . --output docs/architecture
54
90
 
55
91
  # install the skills into your project for your AI IDE (preview first)
56
- npx --yes archsutra-ai@0.1.3 install --host claude --target . --dry-run
57
- npx --yes archsutra-ai@0.1.3 install --host claude --target .
92
+ npx --yes archsutra-ai@0.2.1 install --host claude --target . --dry-run
93
+ npx --yes archsutra-ai@0.2.1 install --host claude --target .
58
94
  ```
59
95
 
60
- For anything beyond a first try, **pin a version** so the code cannot change under you. On npm, including Windows: `npx --yes archsutra-ai@0.1.3 audit . --output docs/architecture`. The git tag `v0.1.2` is the attested GitHub release, but that tarball's bin is only `archsutra`, so `npx archsutra-ai` against `v0.1.2` fails on Windows. There is no `v0.1.3` git tag, and the npm `0.1.3` tarball was not built by Actions (no npm provenance). Details: [supply chain](docs/handbook/15-supply-chain-and-release.md). Install **one** host per project; several hosts read the same skill folders.
96
+ For anything beyond a first try, **pin a version** so the code cannot change under you. On npm, including Windows: `npx --yes archsutra-ai@0.2.1 audit . --output docs/architecture`. A full commit SHA is the tightest pin: `npx github:shahvatsalofficial/archsutra-ai#<40-char sha> audit .`.
61
97
 
62
98
  Without `--output`, `audit` and `map` print one format to the terminal (`--format md` or `--format html`) and write nothing. With `--output`, every report is written as both a Markdown file and an HTML page.
63
99
 
@@ -73,7 +109,7 @@ Then ask your assistant:
73
109
  |---|---|---|
74
110
  | Architecture audit: severity, confidence, `file:line` evidence | `archsutra audit` + `architecture-audit` skill | CLI no; skill yes (your IDE) |
75
111
  | Reverse-engineer modules, dependencies, import cycles | `archsutra map` | No |
76
- | Secrets, injection, TLS, container, IaC, supply-chain checks (redacted) | `archsutra audit` (19 rules) | No |
112
+ | Secrets, injection, TLS, container, IaC, supply-chain checks (redacted) | `archsutra audit` (30 rules) | No |
77
113
  | C4-style context and module diagrams (Mermaid) | `archsutra export` | No |
78
114
  | SARIF 2.1.0 for GitHub code scanning | `archsutra export` | No |
79
115
  | Greenfield design, options, ADRs, roadmap | `architecture-design` skill | Yes (your IDE) |
@@ -90,6 +126,8 @@ Everything below is reproducible from a clean clone. The full, honest register o
90
126
 
91
127
  The tool was run on **52 public repositories** (Express, Django, Flask, Vue, webpack, Juice Shop, WebGoat, ...). **98 findings were labeled by hand** by reading the cited code. Results by batch:
92
128
 
129
+ <picture><source media="(prefers-color-scheme: dark)" srcset="docs/assets/charts/precision-by-batch-dark.svg"><img src="docs/assets/charts/precision-by-batch.svg" alt="Bar chart: precision 50% at baseline, 69% and 95% on unseen batches; actionable 29%, 34%, 52%; with 95% intervals" width="760"></picture>
130
+
93
131
  | Batch | When | Precision (95% CI) | Actionable (95% CI) |
94
132
  |---|---|---|---|
95
133
  | Baseline, v0.1.0 | before any fix | **50%** (36 to 64), n=48 | 29% (18 to 43) |
@@ -104,7 +142,7 @@ We published the 50% baseline, fixed the false positives it exposed (each has a
104
142
 
105
143
  | Evidence | Result |
106
144
  |---|---|
107
- | Automated tests (`npm test`) | **36 passed, 0 failed** ([output](docs/proof/test-results.txt)) |
145
+ | Automated tests (`npm test`) | **52 passed, 0 failed** on 2026-12-01, Node v24.15.0, Windows 11 ([output](docs/proof/test-results.txt)) |
108
146
  | Test coverage | 92% lines, 81% branches, 91% functions ([report](docs/proof/coverage.txt)) |
109
147
  | CI matrix | Ubuntu and Windows x Node 20, 22, 24 plus Ubuntu on the newest Node ([Actions](https://github.com/shahvatsalofficial/archsutra-ai/actions)). macOS is not in CI: GitHub cancelled those jobs before a runner started, and there is no Mac available to re-check them |
110
148
  | Robustness | ReDoS guard, hostile file names, binary files, path traversal, symlinks, byte and file budgets, all tested |
@@ -137,7 +175,7 @@ Scorecard: Security weak, Maintainability adequate; Reliability, Performance,
137
175
  Scalability, Data integrity, Cost: not assessed (needs runtime evidence)
138
176
  ```
139
177
 
140
- Every report comes in **HTML and Markdown**: open [`index.html`](examples/brownfield-monolith/sample-output/index.html) (readable web pages: [audit](examples/brownfield-monolith/sample-output/audit-report.html), [current state](examples/brownfield-monolith/sample-output/current-state.html)) or use the Markdown files in pull requests. Also generated: [`findings.json`](examples/brownfield-monolith/sample-output/findings.json) (schema v1.0.0) and [`findings.sarif`](examples/brownfield-monolith/sample-output/findings.sarif). Terminal only, no files: `archsutra audit . --format html`.
178
+ Every report comes in **HTML and Markdown**: open [`index.html`](examples/brownfield-monolith/sample-output/index.html) (readable web pages: [audit](examples/brownfield-monolith/sample-output/audit-report.html), [current state](examples/brownfield-monolith/sample-output/current-state.html)) or use the Markdown files in pull requests. Also generated: [`findings.json`](examples/brownfield-monolith/sample-output/findings.json) (schema v1.1.0) and [`findings.sarif`](examples/brownfield-monolith/sample-output/findings.sarif). Terminal only, no files: `archsutra audit . --format html`.
141
179
 
142
180
  Every finding carries: stable ID, severity, confidence, evidence (`observed` / `inferred` / `unknown`), impact, why it matters, fix, verification, acceptance criteria, owner type, effort, caveats and references. Schema: [`schemas/findings.schema.json`](schemas/findings.schema.json).
143
181
 
@@ -191,10 +229,44 @@ Exit codes: `0` ok, `1` findings at or above `--fail-on` / install conflict / fa
191
229
 
192
230
  `design`, `review`, `threat-model`, `modernize`, `cost`, `compare`, and `drift` run offline. They write evidence starters. Sections a parser cannot decide stay marked `unknown`. The IDE skill fills those. No model API is called. `compare` diffs two ArchSutra findings files. Semgrep overlap is `node scripts/compare.mjs` and is not run by the CLI. Full reference: [CLI reference](docs/handbook/06-cli-reference.md). Rule list: [rule catalog](docs/handbook/12-rule-catalog.md).
193
231
 
232
+ ## Use it as an MCP server
233
+
234
+ > Needs `0.2.0` or newer. The `mcp` command in `0.1.5` does not answer standard MCP clients.
235
+
236
+ ```json
237
+ { "mcpServers": { "archsutra": { "command": "npx", "args": ["--yes", "archsutra-ai@latest", "mcp", "--root", "."] } } }
238
+ ```
239
+
240
+ Tools: `archsutra_audit`, `archsutra_map`, `archsutra_drift`. All read-only. The server refuses any path outside `--root`, including through symlinks.
241
+
242
+ ## Safe by default
243
+
244
+ - Report commands never overwrite a file ArchSutra did not create. They stop with exit code 2; `--force` backs the original up to `.archsutra/backup/` first.
245
+ - A missing path or a mistyped option exits 2. Add `--strict` in CI so an empty or cut-short scan exits 6.
246
+ - The overview file is now `overview.md` (it was `README.md`).
247
+
248
+ ## Gate only new problems
249
+
250
+ ```bash
251
+ archsutra baseline create # once, commit the file
252
+ archsutra audit . --fail-on-new --fail-on high --strict
253
+ ```
254
+
255
+ Also new: `--history` (secrets in git history), `--include`, `--exclude`, `.archsutraignore`, `--no-score`, `suppressions`. See the [CLI reference](docs/handbook/06-cli-reference.md) and the [MCP guide](docs/guides/mcp-server.md).
256
+
257
+ | Exit code | Meaning |
258
+ |---|---|
259
+ | 0 | ok |
260
+ | 1 | findings at or above `--fail-on`, or install and doctor problems |
261
+ | 2 | usage error, path not found, or refusing to overwrite your file |
262
+ | 4 | verify failed |
263
+ | 5 | internal error |
264
+ | 6 | incomplete scan with `--strict` |
265
+
194
266
  ## Use it in CI
195
267
 
196
268
  ```yaml
197
- - run: npx --yes archsutra-ai@0.1.3 audit . --fail-on high
269
+ - run: npx --yes archsutra-ai@0.2.1 audit . --fail-on high
198
270
  ```
199
271
 
200
272
  Upload SARIF to GitHub code scanning: see the [user guide](docs/handbook/05-user-guide.md). Start with `--fail-on critical` on an existing codebase and tighten later; roughly half of valid findings need no action.
@@ -235,10 +307,10 @@ When you use the skills, **your AI IDE's model provider** processes your prompts
235
307
  ## Limitations
236
308
 
237
309
  - Static, heuristic rules: expect false positives and false negatives; every finding lists caveats, and about half of valid findings are not worth acting on.
238
- - Import graph covers JS/TS and Python. Other languages are detected but not graphed.
310
+ - Import graph covers JS/TS and Python, and matches import suffixes for Go, Java, Kotlin, C# and Rust. PHP, Ruby, Swift and Dart are detected and not graphed.
239
311
  - Reliability, performance, scalability, data integrity and cost are `not assessed` without runtime evidence.
240
312
  - Adapters are not yet verified in live hosts.
241
- - npm package `archsutra-ai` is published (`0.1.2` and `0.1.3`). `0.1.3` adds the `archsutra-ai` command name for Windows. It has no git tag and no npm provenance. The name `archsutra` (no `-ai`) was still unclaimed on 2026-11-06. Do not publish the stub in the parent folder.
313
+ - npm package `archsutra-ai` is published (latest `0.2.1`). The name `archsutra` (no `-ai`) is a different matter; always use `archsutra-ai`.
242
314
 
243
315
  ## FAQ
244
316
 
@@ -263,11 +335,11 @@ More: [glossary and FAQ](docs/handbook/11-glossary-and-faq.md).
263
335
  - [ ] Live smoke tests per AI IDE ([protocol](docs/compatibility/smoke-tests/README.md))
264
336
  - [ ] First run of the tool comparison workflow, results reviewed and published
265
337
  - [ ] Larger, multi-labeler evaluation corpus and a recall estimate
266
- - [ ] More analyzers: Java/Kotlin, C#, Go, Rust import graphs
267
- - [ ] Suppression/baseline file for accepted findings
338
+ - [x] Import-suffix graph for Go, Java, Kotlin, C#, and Rust. Still open: PHP, Ruby, Swift, Dart, path aliases, dynamic import, dependency injection
339
+ - [x] Suppression file and baseline gate (`.archsutra/suppress.json`, `baseline create`, `audit --fail-on-new`)
268
340
  - [ ] Independent security review; trademark clearance; legal review
269
341
  - [ ] Optional local-model and bring-your-own-key server mode, strictly opt-in
270
- - [x] npm package `archsutra-ai` published (`0.1.2`, `0.1.3`) — laptop publish, no provenance, no `v0.1.3` tag
342
+ - [x] npm package `archsutra-ai` published (latest `0.2.1`)
271
343
  - [ ] npm publish from GitHub Actions with provenance, one digest shared with the GitHub release (`v0.1.5`; `0.1.3` and `0.1.4` cannot be replaced)
272
344
 
273
345
  Full plan with acceptance tests: [roadmap](docs/handbook/09-compatibility-and-roadmap.md). Starter tasks: [good first issues](docs/community/good-first-issues.md).
package/dist/audit.js CHANGED
@@ -1,9 +1,12 @@
1
1
  import path from 'node:path';
2
2
  import { readLines, walk } from './fsutil.js';
3
3
  import { buildMap, readJson } from './map.js';
4
- import { isSuppressed, loadSuppressions } from './suppress.js';
4
+ import { applySuppressions, loadSuppressions } from './suppress.js';
5
+ import { fingerprints } from './drift.js';
5
6
  import { DEV_TOOLING_PATH, TEST_PATH, commentMask, isDataLike, isMinified, isVendoredPath, looksThirdParty } from './heuristics.js';
6
7
  import { detectSecrets, excerpt } from './redact.js';
8
+ import { scanHistory } from './history.js';
9
+ import { CLASSIFICATION, EXTRA_RULES, SQL_BLOCK, SQL_OPENER } from './rules-extra.js';
7
10
  const CODE_EXT = new Set([
8
11
  '.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs', '.py', '.java', '.kt', '.cs', '.go', '.rs', '.php', '.rb', '.swift', '.dart',
9
12
  ]);
@@ -16,7 +19,8 @@ function ev(f, line, text, kind = 'observed') {
16
19
  const LINE_RULES = [
17
20
  {
18
21
  rule: 'AS-SEC-004',
19
- re: /(?<!`)\beval\s*\(|(?<!`)new\s+Function\s*\(|child_process[^\n]*\bexec(?:Sync)?\s*\(\s*[`"'][^`"']*(?:\$\{|["']\s*\+)|\bos\.system\s*\(|subprocess\.[a-z_]+\([^)]*shell\s*=\s*True/,
22
+ // `.eval(` is usually an ordinary method (model.eval(), redis.eval); only the global one runs code.
23
+ re: /(?<![.\w`])(?<!def )eval\s*\(|\b(?:window|globalThis)\.eval\s*\(|(?<!`)new\s+Function\s*\(|child_process[^\n]*\bexec(?:Sync)?\s*\(\s*[`"'][^`"']*(?:\$\{|["']\s*\+)|\bos\.system\s*\(|subprocess\.[a-z_]+\([^)]*shell\s*=\s*True/,
20
24
  codeOnly: true,
21
25
  skipTests: true,
22
26
  make: (hits) => ({
@@ -35,7 +39,7 @@ const LINE_RULES = [
35
39
  {
36
40
  rule: 'AS-SEC-005',
37
41
  also: (t) => /\b(select|insert|update|delete|create|drop|alter)\b/i.test(t) && /\b(from|into|set|table|where|values|index)\b/i.test(t),
38
- re: /\b(?:query|execute|raw|prepare)\s*\(\s*(?:`[^`]*\$\{|["'][^"']*["']\s*\+)|(?:SELECT\s[^;\n]{0,80}\sFROM|INSERT\s+INTO|UPDATE\s+\w+\s+SET|DELETE\s+FROM)\b[^;\n]{0,100}(?:\$\{|["']\s*\+\s*\w|%s["']?\s*%\s*\w|\{\w+\}["']\s*\.format)/,
42
+ re: /\b(?:query|execute|executemany|executescript|raw|prepare)\s*\(\s*(?:[fF]"[^"\n]*\{|[fF]'[^'\n]*\{|`[^`]*\$\{|["'][^"']*["']\s*\+)|(?:SELECT\s[^;\n]{0,80}\sFROM|INSERT\s+INTO|UPDATE\s+\w+\s+SET|DELETE\s+FROM)\b[^;\n]{0,100}(?:\$\{|["']\s*\+\s*\w|%s["']?\s*%\s*\w|\{\w+\}["']\s*\.format)/,
39
43
  codeOnly: true,
40
44
  skipTests: true,
41
45
  make: (hits) => ({
@@ -51,6 +55,42 @@ const LINE_RULES = [
51
55
  references: [OWASP, 'https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html'],
52
56
  }),
53
57
  },
58
+ {
59
+ rule: 'AS-SEC-007',
60
+ re: /\b(?:pickle|cPickle|marshal|dill)\.loads?\s*\(|\byaml\.(?:unsafe_load|full_load)\s*\(|\byaml\.load\s*\((?![^\n]*Safe)/,
61
+ exts: new Set(['.py']),
62
+ skipTests: true,
63
+ make: (hits) => ({
64
+ rule: 'AS-SEC-007', title: 'Unsafe deserialization', category: 'security', severity: 'high', confidence: 'medium',
65
+ evidence: hits,
66
+ impact: 'Loading attacker-controlled data this way can execute arbitrary code.',
67
+ whyItMatters: 'Software and data integrity failures (OWASP A08, CWE-502).',
68
+ fix: 'Use JSON or yaml.safe_load. Load pickled data only from sources you sign and verify.',
69
+ verification: 'Trace where the loaded bytes come from.',
70
+ acceptanceCriteria: 'No unsafe loader reads data that crosses a trust boundary.',
71
+ effort: 'M', ownerType: 'application developer',
72
+ caveats: 'Pattern match only. The data may be trusted and local.',
73
+ references: ['https://cwe.mitre.org/data/definitions/502.html'],
74
+ }),
75
+ },
76
+ {
77
+ rule: 'AS-SEC-008',
78
+ re: /\bhashlib\.(?:md5|sha1)\s*\((?![^\n]*usedforsecurity\s*=\s*False)|\bcreateHash\s*\(\s*["'](?:md5|sha1)["']/,
79
+ codeOnly: true,
80
+ skipTests: true,
81
+ make: (hits) => ({
82
+ rule: 'AS-SEC-008', title: 'Weak hash algorithm (MD5 or SHA-1)', category: 'security', severity: 'medium', confidence: 'low',
83
+ evidence: hits,
84
+ impact: 'If used for passwords, signatures or tokens, values can be forged or recovered.',
85
+ whyItMatters: 'Cryptographic failures (OWASP A02, CWE-327).',
86
+ fix: 'Use SHA-256 or better; for passwords use scrypt, bcrypt or Argon2.',
87
+ verification: 'Confirm what the hash protects.',
88
+ acceptanceCriteria: 'No MD5 or SHA-1 protects a security decision.',
89
+ effort: 'S', ownerType: 'application developer',
90
+ caveats: 'Often a harmless checksum or cache key. Confirm the purpose.',
91
+ references: ['https://cwe.mitre.org/data/definitions/327.html'],
92
+ }),
93
+ },
54
94
  {
55
95
  rule: 'AS-SEC-006',
56
96
  re: /rejectUnauthorized\s*:\s*false|verify\s*=\s*False|InsecureSkipVerify\s*:\s*true|NODE_TLS_REJECT_UNAUTHORIZED\s*=\s*['"]?0/,
@@ -89,6 +129,14 @@ const LINE_RULES = [
89
129
  }),
90
130
  },
91
131
  ];
132
+ const ALL_LINE_RULES = [...LINE_RULES, ...EXTRA_RULES];
133
+ /** Files whose whole purpose is to hold a credential, and the line shape that shows one is filled in. */
134
+ const CREDENTIAL_FILES = {
135
+ '.npmrc': /_(?:authToken|auth|password)\s*=\s*(?!\$)\S{8,}/,
136
+ '.pypirc': /^\s*password\s*[:=]\s*(?!\$)\S{6,}/,
137
+ '.netrc': /\bpassword\s+(?!\$)\S{6,}/,
138
+ '.git-credentials': /\bhttps?:\/\/[^:@\s]+:[^@\s]+@/,
139
+ };
92
140
  const LAYERS = [
93
141
  { layer: 0, re: /(^|\/)(controllers?|routes?|handlers?|api|views?|pages|ui|web)(\/|$)/i },
94
142
  { layer: 1, re: /(^|\/)(services?|usecases?|application|domain)(\/|$)/i },
@@ -115,7 +163,7 @@ function looksLikeRealKey(lines, i) {
115
163
  const next = (lines[i + 1] ?? '').trim();
116
164
  return BASE64_LINE.test(next) || /^Proc-Type:/.test(next) || /PRIVATE KEY-----(?:\\n|\s)*[A-Za-z0-9+/=]{40,}/.test(lines[i]);
117
165
  }
118
- export async function runAudit(root, corpusIn) {
166
+ export async function runAudit(root, corpusIn, opts = {}) {
119
167
  const corpus = corpusIn ?? (await walk(root));
120
168
  const map = await buildMap(root, corpus);
121
169
  const drafts = [];
@@ -143,26 +191,28 @@ export async function runAudit(root, corpusIn) {
143
191
  const usesShell = isCode && lines.some((l) => /child_process|shelljs|execa/.test(l));
144
192
  if (isCode && lines.length > 1000 && !isTest && !vendored && !isDataLike(lines))
145
193
  push('AS-ARC-003', { path: f.rel, startLine: 1, endLine: lines.length, kind: 'observed', excerpt: `${lines.length} lines` });
194
+ const credential = CREDENTIAL_FILES[path.posix.basename(f.rel)];
146
195
  for (let i = 0; i < lines.length; i++) {
147
196
  const text = lines[i];
148
197
  if (text.length > 2000)
149
198
  continue;
150
- if (!isTest && !isDoc) {
151
- for (const hit of detectSecrets(text)) {
152
- if (hit.kind === 'private-key') {
153
- if (looksLikeRealKey(lines, i))
154
- push('AS-SEC-002', ev(f, i + 1, '-----BEGIN PRIVATE KEY----- [REDACTED]'));
155
- }
156
- else if (vendored || mask[i]) {
157
- continue;
158
- }
159
- else if (!/example|placeholder|changeme|your[_-]|xxxx|process\.env|os\.environ|getenv/i.test(text)) {
160
- push('AS-SEC-001', { ...ev(f, i + 1, text), excerpt: `${hit.kind}: ${excerpt(text, 80)}` });
161
- }
199
+ if (credential?.test(text) && !text.trimStart().startsWith('#')) {
200
+ push('AS-SEC-001', { path: f.rel, startLine: i + 1, endLine: i + 1, kind: 'observed', excerpt: `credential-file: ${path.posix.basename(f.rel)} holds a filled-in credential [REDACTED]` });
201
+ continue;
202
+ }
203
+ // A leaked key is leaked in a comment, test or README too. Only the generic name=value guess skips tests and docs.
204
+ for (const hit of detectSecrets(text).slice(0, 1)) {
205
+ if (hit.kind === 'private-key') {
206
+ if (looksLikeRealKey(lines, i))
207
+ push('AS-SEC-002', ev(f, i + 1, '-----BEGIN PRIVATE KEY----- [REDACTED]'));
208
+ }
209
+ else if (!vendored && !(hit.kind === 'credential-assignment' && (isTest || isDoc))) {
210
+ const where = isTest ? ' (test file)' : isDoc ? ' (documentation)' : mask[i] ? ' (comment)' : '';
211
+ push('AS-SEC-001', { ...ev(f, i + 1, text), excerpt: `${hit.kind}${where}: ${excerpt(text, 80)}` });
162
212
  }
163
213
  }
164
- for (const r of LINE_RULES) {
165
- if (r.codeOnly && !isCode)
214
+ for (const r of ALL_LINE_RULES) {
215
+ if (r.codeOnly && !isCode && !r.exts?.has(f.ext))
166
216
  continue;
167
217
  if (r.exts && !r.exts.has(f.ext))
168
218
  continue;
@@ -170,12 +220,17 @@ export async function runAudit(root, corpusIn) {
170
220
  continue;
171
221
  if (isDoc || vendored || mask[i])
172
222
  continue;
173
- if (r.re.test(text) && (!r.also || r.also(text)) && !(r.rule === 'AS-IAC-001' && publicWebPort(lines, i))) {
223
+ if (r.re.test(text) && (!r.also || r.also(text)) && (!r.near || r.near.test(lines.slice(Math.max(0, i - 5), i + 6).join('\n'))) && !(r.rule === 'AS-IAC-001' && publicWebPort(lines, i))) {
174
224
  push(r.rule, ev(f, i + 1, text));
175
225
  if (r.rule === 'AS-SEC-004')
176
226
  dangerFiles.add(f.rel);
177
227
  }
178
228
  }
229
+ if (isCode && !isTest && !vendored && !mask[i] && SQL_OPENER.test(text)) {
230
+ const block = lines.slice(i, i + 8).join('\n');
231
+ if (SQL_BLOCK.test(block) && /\b(select|insert|update|delete)\b[\s\S]*\b(from|into|set|where|values)\b/i.test(block))
232
+ push('AS-SEC-005', ev(f, i + 1, text));
233
+ }
179
234
  if (isCode && !isTest && !vendored && !mask[i] && usesShell && SHELL_EXEC.test(text)) {
180
235
  push('AS-SEC-004', ev(f, i + 1, text));
181
236
  dangerFiles.add(f.rel);
@@ -185,23 +240,28 @@ export async function runAudit(root, corpusIn) {
185
240
  }
186
241
  }
187
242
  }
188
- for (const r of LINE_RULES) {
243
+ for (const r of ALL_LINE_RULES) {
189
244
  const hits = byRule.get(r.rule);
190
245
  if (hits?.length)
191
- drafts.push(r.make(hits.slice(0, 10)));
246
+ drafts.push(r.make(hits));
192
247
  }
248
+ if (opts.history)
249
+ for (const e of await scanHistory(root, opts.historyLimit))
250
+ push('AS-SEC-001', e);
193
251
  const secretHits = byRule.get('AS-SEC-001');
194
252
  if (secretHits?.length) {
195
253
  drafts.push({
196
- rule: 'AS-SEC-001', title: 'Possible hard-coded credential', category: 'security', severity: 'critical', confidence: 'medium',
197
- evidence: secretHits.slice(0, 10),
254
+ rule: 'AS-SEC-001', title: 'Possible hard-coded credential', category: 'security', severity: 'critical',
255
+ // Hits only in tests, docs or comments are more often samples than live keys.
256
+ confidence: secretHits.every((e) => /^[\w-]+ \((?:test file|documentation|comment)\)/.test(e.excerpt ?? '')) ? 'low' : 'medium',
257
+ evidence: secretHits,
198
258
  impact: 'A leaked credential gives direct access to the protected system and lives forever in git history.',
199
259
  whyItMatters: 'Secrets in source are the most common cause of avoidable breaches.',
200
260
  fix: 'Revoke and rotate the credential first. Load it from environment variables or a secret manager. Purge history only after rotation.',
201
261
  verification: 'Run a dedicated scanner (e.g. gitleaks) over full history; confirm the old credential is revoked.',
202
262
  acceptanceCriteria: 'No credentials in the working tree or history; rotation recorded.',
203
263
  effort: 'S', ownerType: 'application developer + security',
204
- caveats: 'Pattern match. Values are redacted in this report. Test fixtures and docs are skipped.',
264
+ caveats: 'Pattern match. Values are redacted in this report. Hits in tests, docs and comments are labelled and may be samples.',
205
265
  references: ['https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures/'],
206
266
  });
207
267
  }
@@ -209,7 +269,7 @@ export async function runAudit(root, corpusIn) {
209
269
  if (keyHits?.length) {
210
270
  drafts.push({
211
271
  rule: 'AS-SEC-002', title: 'Private key material committed', category: 'security', severity: 'critical', confidence: 'high',
212
- evidence: keyHits.slice(0, 10),
272
+ evidence: keyHits,
213
273
  impact: 'Anyone with repository read access can impersonate the key owner.',
214
274
  whyItMatters: 'Private keys must never leave their trust boundary.',
215
275
  fix: 'Treat the key as compromised: rotate it, remove the file, and store keys in a secret manager.',
@@ -224,7 +284,7 @@ export async function runAudit(root, corpusIn) {
224
284
  if (archBig?.length) {
225
285
  drafts.push({
226
286
  rule: 'AS-ARC-003', title: 'Very large source files (low cohesion risk)', category: 'maintainability', severity: 'low', confidence: 'medium',
227
- evidence: archBig.slice(0, 10),
287
+ evidence: archBig,
228
288
  impact: 'Large files attract unrelated changes, raise merge conflicts, and are hard to test.',
229
289
  whyItMatters: 'Cohesion is a leading indicator of change cost.',
230
290
  fix: 'Split by responsibility along existing seams; add characterization tests first.',
@@ -240,7 +300,7 @@ export async function runAudit(root, corpusIn) {
240
300
  if (envFiles.length) {
241
301
  drafts.push({
242
302
  rule: 'AS-SEC-003', title: 'Environment file present in repository tree', category: 'security', severity: 'high', confidence: 'medium',
243
- evidence: envFiles.slice(0, 10).map((f) => ({ path: f.rel, kind: 'observed', excerpt: '(contents not read into report)' })),
303
+ evidence: envFiles.map((f) => ({ path: f.rel, kind: 'observed', excerpt: '(contents not read into report)' })),
244
304
  impact: 'Environment files usually hold credentials.',
245
305
  whyItMatters: 'Config with secrets must stay out of version control.',
246
306
  fix: 'Add to .gitignore, commit a .env.example with placeholders, rotate any real values.',
@@ -262,7 +322,7 @@ export async function runAudit(root, corpusIn) {
262
322
  drafts.push({
263
323
  rule: 'AS-ARC-001', title: `Circular dependency between modules (${map.cycles.map((c) => c.join(' <-> ')).join('; ')})`,
264
324
  category: 'architecture', severity: 'medium', confidence: 'high',
265
- evidence: evid.slice(0, 10),
325
+ evidence: evid,
266
326
  impact: 'Cyclic modules cannot be understood, tested, versioned or deployed independently.',
267
327
  whyItMatters: 'Acyclic dependencies keep change local and make extraction (e.g. to a service) feasible.',
268
328
  fix: 'Extract the shared concept into a lower-level module or invert one dependency behind an interface.',
@@ -299,7 +359,7 @@ export async function runAudit(root, corpusIn) {
299
359
  if (layerEvidence.length) {
300
360
  drafts.push({
301
361
  rule: 'AS-ARC-002', title: 'Lower layer depends on a higher layer', category: 'architecture', severity: 'medium', confidence: 'medium',
302
- evidence: layerEvidence.slice(0, 10),
362
+ evidence: layerEvidence,
303
363
  impact: 'Data or service code that imports presentation code inverts the intended dependency direction and blocks reuse.',
304
364
  whyItMatters: 'Layer direction is what keeps business and data logic independent of delivery mechanisms.',
305
365
  fix: 'Move shared types down, or introduce an interface owned by the lower layer and implemented above.',
@@ -356,7 +416,7 @@ export async function runAudit(root, corpusIn) {
356
416
  if (byRule.get('AS-OPS-003')?.length) {
357
417
  drafts.push({
358
418
  rule: 'AS-OPS-003', title: 'Container runs as root', category: 'security', severity: 'medium', confidence: 'high',
359
- evidence: byRule.get('AS-OPS-003').slice(0, 10),
419
+ evidence: byRule.get('AS-OPS-003'),
360
420
  impact: 'A compromised process has root inside the container, easing escape and file tampering.',
361
421
  whyItMatters: 'Non-root containers are baseline hardening.',
362
422
  fix: 'Create an unprivileged user and add `USER <name>` before the entrypoint.',
@@ -370,7 +430,7 @@ export async function runAudit(root, corpusIn) {
370
430
  if (byRule.get('AS-SUP-003')?.length) {
371
431
  drafts.push({
372
432
  rule: 'AS-SUP-003', title: 'Container base image not pinned', category: 'supply-chain', severity: 'low', confidence: 'medium',
373
- evidence: byRule.get('AS-SUP-003').slice(0, 10),
433
+ evidence: byRule.get('AS-SUP-003'),
374
434
  impact: 'Builds are not reproducible and can silently pick up a compromised or breaking image.',
375
435
  whyItMatters: 'Pinning is a core supply-chain control.',
376
436
  fix: 'Pin to a specific version tag, ideally with a digest, and update via automated PRs.',
@@ -403,7 +463,7 @@ export async function runAudit(root, corpusIn) {
403
463
  if (unlocked.length) {
404
464
  drafts.push({
405
465
  rule: 'AS-SUP-001', title: 'Dependency manifest without lockfile', category: 'supply-chain', severity: 'medium', confidence: 'high',
406
- evidence: unlocked.slice(0, 10),
466
+ evidence: unlocked,
407
467
  impact: 'Installs are not reproducible; a compromised new release can enter automatically.',
408
468
  whyItMatters: 'Lockfiles pin the exact dependency tree that was tested.',
409
469
  fix: 'Commit the lockfile and install with `npm ci` (or equivalent) in CI.',
@@ -417,7 +477,7 @@ export async function runAudit(root, corpusIn) {
417
477
  if (latest.length) {
418
478
  drafts.push({
419
479
  rule: 'AS-SUP-002', title: 'Unpinned dependency ranges ("latest" or "*")', category: 'supply-chain', severity: 'medium', confidence: 'high',
420
- evidence: latest.slice(0, 10),
480
+ evidence: latest,
421
481
  impact: 'Any future release, including a malicious one, is accepted.',
422
482
  whyItMatters: 'Unbounded ranges defeat review and reproducibility.',
423
483
  fix: 'Use a bounded semver range and rely on the lockfile plus automated update PRs.',
@@ -433,8 +493,8 @@ export async function runAudit(root, corpusIn) {
433
493
  const both = llmFiles.filter((l) => dangerFiles.has(l.f.rel));
434
494
  if (both.length) {
435
495
  drafts.push({
436
- rule: 'AS-AI-001', title: 'LLM call in the same file as dynamic code or shell execution', category: 'ai-security', severity: 'high', confidence: 'low',
437
- evidence: both.slice(0, 5).map((b) => ev(b.f, b.line, b.text, 'inferred')),
496
+ rule: 'AS-AI-001', title: 'LLM call in the same file as dynamic code or shell execution', category: 'ai-security', severity: 'info', confidence: 'low',
497
+ evidence: both.map((b) => ev(b.f, b.line, b.text, 'inferred')),
438
498
  impact: 'Model output (which can be steered by prompt injection) may reach an execution sink.',
439
499
  whyItMatters: 'LLM output must be treated as untrusted input (OWASP LLM Top 10).',
440
500
  fix: 'Never execute model output directly. Use allowlisted tools with schema-validated arguments, sandboxing and human approval for side effects.',
@@ -475,13 +535,28 @@ export async function runAudit(root, corpusIn) {
475
535
  }
476
536
  // ---- Assign stable IDs ------------------------------------------------
477
537
  const sevOrder = { critical: 0, high: 1, medium: 2, low: 3, info: 4 };
478
- const suppressions = await loadSuppressions(root);
479
- const visible = drafts.filter((d) => !isSuppressed(d, suppressions));
538
+ // Fingerprints come first, so suppressing one location never changes the identity of another.
539
+ const stamped = drafts.map((d) => {
540
+ const prints = fingerprints(d.rule, d.evidence.map((e) => ({ ...e, fingerprint: undefined })));
541
+ const [cwe, owasp] = CLASSIFICATION[d.rule] ?? [];
542
+ return { ...d, ...(cwe ? { cwe, owasp } : {}), evidence: d.evidence.map((e, i) => ({ ...e, fingerprint: prints[i] })) };
543
+ });
544
+ const { visible, hidden } = applySuppressions(stamped, await loadSuppressions(root));
480
545
  visible.sort((a, b) => sevOrder[a.severity] - sevOrder[b.severity] || a.rule.localeCompare(b.rule));
481
- const findings = visible.map((x, i) => ({ ...x, id: `${x.rule}#${String(i + 1).padStart(3, '0')}`, status: 'open' }));
482
- return { map, findings, scorecard: scorecard(findings, codeCount), failedChecks };
546
+ // Numbered within a rule, so fixing one finding never renames another.
547
+ const seen = new Map();
548
+ const withId = (x) => {
549
+ const n = (seen.get(x.rule) ?? 0) + 1;
550
+ seen.set(x.rule, n);
551
+ return { ...x, id: `${x.rule}#${String(n).padStart(3, '0')}`, status: 'open' };
552
+ };
553
+ const findings = visible.map(withId);
554
+ const suppressed = hidden.map(withId);
555
+ return { map, findings, suppressed, scorecard: opts.noScore ? [] : scorecard(findings, codeCount, map.coverage), failedChecks };
483
556
  }
484
- function scorecard(findings, codeCount) {
557
+ /** Rules that can lower each rating. */
558
+ const RULES_PER_CATEGORY = { Security: 19, Maintainability: 5, Operability: 2, 'Supply chain': 3, 'Developer experience': 2 };
559
+ function scorecard(findings, codeCount, coverage) {
485
560
  const cats = {
486
561
  Security: ['security', 'ai-security'],
487
562
  Maintainability: ['maintainability', 'architecture'],
@@ -489,21 +564,27 @@ function scorecard(findings, codeCount) {
489
564
  'Supply chain': ['supply-chain'],
490
565
  'Developer experience': ['developer-experience', 'governance'],
491
566
  };
567
+ const found = coverage.folders.reduce((n, f) => n + f.total, 0);
568
+ const share = found ? Math.round((coverage.filesScanned / found) * 100) : 100;
492
569
  const out = [];
493
570
  for (const [label, keys] of Object.entries(cats)) {
571
+ const rules = RULES_PER_CATEGORY[label];
494
572
  if (codeCount === 0) {
495
- out.push({ category: label, rating: 'not assessed', basis: 'No source files recognised.' });
573
+ out.push({ category: label, rating: 'not assessed', basis: 'No source files recognised.', rules: 0, confidence: 'none' });
496
574
  continue;
497
575
  }
498
576
  const fs = findings.filter((f) => keys.includes(f.category));
499
577
  const crit = fs.filter((f) => f.severity === 'critical').length;
500
578
  const high = fs.filter((f) => f.severity === 'high').length;
501
579
  const med = fs.filter((f) => f.severity === 'medium').length;
502
- const rating = crit ? 'critical' : high ? 'weak' : med ? 'adequate' : 'strong';
503
- out.push({ category: label, rating, basis: `${fs.length} finding(s): ${crit} critical, ${high} high, ${med} medium. Rule coverage only; absence of findings is not proof of quality.` });
580
+ const low = fs.filter((f) => f.severity === 'low').length;
581
+ const rating = crit ? 'critical' : high ? 'weak' : med || low >= 3 ? 'adequate' : 'no findings';
582
+ // A handful of rules can never support high confidence, however much was read.
583
+ const confidence = coverage.truncated || share < 80 || codeCount < 5 ? 'low' : share < 100 || rules < 10 ? 'medium' : 'high';
584
+ out.push({ category: label, rating, rules, confidence, basis: `${fs.length} finding(s): ${crit} critical, ${high} high, ${med} medium, ${low} low. ${rules} rule(s), ${share}% of listed files scanned. Absence of findings is not proof of quality.` });
504
585
  }
505
586
  for (const label of ['Reliability', 'Performance', 'Scalability', 'Data integrity', 'Cost']) {
506
- out.push({ category: label, rating: 'not assessed', basis: 'Needs runtime, load, data or billing evidence the static scan cannot observe. Use the architecture-audit skill with the maintainer.' });
587
+ out.push({ category: label, rating: 'not assessed', rules: 0, confidence: 'none', basis: 'Needs runtime, load, data or billing evidence the static scan cannot observe. Use the architecture-audit skill; see the roadmap in docs/handbook/09-compatibility-and-roadmap.md.' });
507
588
  }
508
589
  return out;
509
590
  }