docguard-cli 0.32.0 → 0.33.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/PHILOSOPHY.md CHANGED
@@ -115,6 +115,7 @@ CDD is a practitioner methodology whose patterns align with peer-reviewed resear
115
115
  - **Generate → validate → evaluate pipeline** — inspired by the AITPG framework (Lopez et al., IEEE TSE 2026): multi-agent generation grounded in standards produces more comprehensive documentation while staying semantically aligned with expert references.
116
116
  - **Calibrated quality evaluation** — DocGuard's HIGH/MEDIUM/LOW labels and multi-signal scoring adapt the CJE framework from TRACE (Lopez et al., IEEE TMLCN 2026).
117
117
  - **Standards-grounded generation** — each canonical document maps to a relevant standard (arc42, C4, OWASP ASVS, ISO 29119, OpenAPI, 12-Factor App).
118
+ - **Enforcement over instructions** — a 2026 ETH Zurich study (138 repos, 5,694 agent PRs) found the most common style of agent-instruction file *degrades* agent performance; practitioner reports converge on the same conclusion: written rules are routinely ignored, programmatic checks are respected. CDD's answer is to make the docs machine-verified rather than merely machine-readable.
118
119
 
119
120
  > **Lead researcher**: [Martin Manuel Lopez](https://github.com/martinmanuel9) · [ORCID 0009-0002-7652-2385](https://orcid.org/0009-0002-7652-2385), University of Arizona
120
121
 
package/PRIVACY.md ADDED
@@ -0,0 +1,45 @@
1
+ # Privacy Policy — DocGuard
2
+
3
+ **Effective: 2026-07-16**
4
+
5
+ DocGuard is a local-first command-line tool. This policy is short because the
6
+ honest answer is short: **DocGuard collects nothing.**
7
+
8
+ ## What DocGuard does with your data
9
+
10
+ - **All analysis runs locally.** Validators, scoring, reports, the MCP server —
11
+ everything reads files on your machine and writes output to your machine.
12
+ Nothing is uploaded, sampled, or "improved" with your code or docs.
13
+ - **No telemetry, no analytics, no crash reporting.** There is no phone-home
14
+ code path. The deterministic core makes no network calls at all.
15
+ - **No accounts.** DocGuard has no sign-up, no API keys of its own, and no
16
+ server-side component operated by us.
17
+
18
+ ## The explicit, user-initiated exceptions
19
+
20
+ Three commands can *prepare* outbound actions — each is opt-in, visible, and
21
+ executed by you or your own tooling, never silently by DocGuard:
22
+
23
+ | Command | What happens |
24
+ |---------|--------------|
25
+ | `docguard feedback` | Builds a **prefilled GitHub issue URL** (redacted and length-capped) and saves a local record. Nothing is sent unless you open the URL and submit it yourself. |
26
+ | `docguard upgrade --pr` / `impact --prs` | Shell out to **your** locally-authenticated `gh` CLI to interact with **your** repositories. DocGuard never holds credentials. |
27
+ | `docguard mcp --transport http` | Serves read-only tools over HTTP. Binds to loopback by default; binding a non-loopback address **refuses to start** without an `--api-key`. |
28
+
29
+ ## Data written to disk (yours, locally)
30
+
31
+ State lives under `.docguard/` in your repo (fix history, score history,
32
+ caches) and `.docguard.baseline.json` if you create one. All of it is plain
33
+ text, in your repository, under your version control — delete it any time.
34
+
35
+ ## Dependencies
36
+
37
+ One pinned runtime dependency (`@babel/parser`). The npm package is published
38
+ from GitHub Actions with provenance attestation, so you can verify the tarball
39
+ was built from this repository.
40
+
41
+ ## Changes & contact
42
+
43
+ Changes to this policy land in this file with a dated entry in
44
+ [CHANGELOG.md](CHANGELOG.md). Questions: open an issue at
45
+ <https://github.com/raccioly/docguard/issues> (see [SUPPORT.md](SUPPORT.md)).
package/README.md CHANGED
@@ -41,6 +41,7 @@
41
41
  - [Slash Commands](#-slash-commands)
42
42
  - [Examples](#-examples)
43
43
  - [Testing](#-testing)
44
+ - [Enterprise Adoption](#-enterprise-adoption)
44
45
  - [CI/CD Integration](#%EF%B8%8F-cicd-integration)
45
46
  - [What's New](#-whats-new)
46
47
  - [File Structure](#-file-structure)
@@ -68,7 +69,7 @@ DocGuard is an official [GitHub Spec Kit](https://github.com/github/spec-kit) co
68
69
 
69
70
  ```mermaid
70
71
  graph TD
71
- CLI["CLI Entry<br/>docguard.mjs"] --> Commands["Commands (18)"]
72
+ CLI["CLI Entry<br/>docguard.mjs"] --> Commands["Commands (20)"]
72
73
  Commands --> guard["guard"]
73
74
  Commands --> generate["generate"]
74
75
  Commands --> score["score"]
@@ -108,6 +109,14 @@ against what the code does, on every commit, with no LLM required. The full
108
109
  thesis (and the research behind it) lives in [PHILOSOPHY.md](PHILOSOPHY.md);
109
110
  recent feature highlights moved [below](#-whats-new).
110
111
 
112
+ The field data backs the enforcement-over-instructions bet: an ETH Zurich
113
+ study across 138 repos / 5,694 agent PRs found the most popular style of
114
+ agent-instruction file *hurts* agent performance, and practitioners keep
115
+ converging on the same lesson — written rules are routinely ignored;
116
+ programmatic checks are what agents (and humans) actually respect. That is
117
+ exactly the layer DocGuard provides: not another instructions file, but the
118
+ validator suite that makes the instructions and docs verifiably true.
119
+
111
120
  ---
112
121
 
113
122
  ## ⚡ Quick Start
@@ -247,7 +256,7 @@ This installs DocGuard's slash commands (`/docguard.init`, `/docguard.guard`, `/
247
256
 
248
257
  ## Usage
249
258
 
250
- DocGuard ships **18 commands** (the "Daily 5" + 13 situational tools, including the zero-install `demo` and the `mcp` server). Six additional one-shot scaffolders are accessed via `docguard init --with <name>`. Eight v0.19 commands continue to work as deprecation aliases through v0.20.x — see [MIGRATION-v0.20.md](docs-implementation/MIGRATION-v0.20.md).
259
+ DocGuard ships **20 commands** (the "Daily 5" + 15 situational tools, including the zero-install `demo`, the `mcp` server, and the `ci` pipeline gate). Six additional one-shot scaffolders are accessed via `docguard init --with <name>`. Seven v0.19 commands continue to work as deprecation aliases through v0.20.x — see [MIGRATION-v0.20.md](docs-implementation/MIGRATION-v0.20.md).
251
260
 
252
261
  **The Daily 5** — what you'll reach for 95% of the time:
253
262
 
@@ -274,7 +283,10 @@ DocGuard ships **18 commands** (the "Daily 5" + 13 situational tools, including
274
283
  | `verify --semantic` | Extract documented numbers/limits/enums (retention days, rate limits, GSI/role counts, status enums) as a task list for an agent to check against code — the semantic-drift class regex/AST can't see |
275
284
  | `verify --instructions` | Audit AGENTS.md/CLAUDE.md themselves for drift: duplicate rules, never-vs-always contradictions, stale file pointers, unknown commands — plus clustered rule pairs as agent judgment tasks |
276
285
  | `feedback` | Report likely false positives back to DocGuard — local-first record + a 1-click prefilled, redacted GitHub issue (zero typing) |
277
- | `mcp` | MCP server — exposes guard/score/explain/verify/diagnose as native tools for Claude, Cursor, and any MCP client. Stdio: `claude mcp add docguard -- npx docguard-cli mcp`. Team-shared HTTP: `docguard mcp --transport http --port 8585` (loopback by default; non-loopback binds require `--api-key`) |
286
+ | `mcp` | MCP server — exposes guard/score/explain/verify/report/diagnose as native tools for Claude, Cursor, and any MCP client. Stdio: `claude mcp add docguard -- npx docguard-cli mcp`. Team-shared HTTP: `docguard mcp --transport http --port 8585` (loopback by default; non-loopback binds require `--api-key`) |
287
+ | `report` | Compliance-evidence bundle for audits — guard verdict + CDD score + ALCOA+ attributes + fix history, stamped with git commit and a tamper-evident sha256 integrity hash (`--format json`, `--out <file>`). Evidence, not a gate: always exits 0 |
288
+ | `ci` | Pipeline gate: guard + score in one command — never scaffolds or touches source; its only write is its own `.docguard/history.jsonl` (opt out: `--no-history`). `--threshold <n>` fails below a score, `--fail-on-warning` for strict mode, `--format json` for parsers |
289
+ | `score --trend` | Score trajectory from recorded `ci` runs — sparkline, delta, and the last 10 runs with commit stamps |
278
290
  | `memory` | Per-domain accuracy headline (endpoints / entities / env / tech) |
279
291
  | `memory --diff` | Drill into which specific claims don't match code |
280
292
  | `memory --pack` | Write `.docguard/context-pack.md` — compact, code-truth-stamped session-start context for AI agents |
@@ -308,6 +320,8 @@ Run them solo (`docguard init --with hooks`) or stacked (`docguard init --with a
308
320
  | `--quiet` / `-q` | Suppress banner — for hooks, CI loops, scripts | All |
309
321
  | `--format json` | Machine-readable output (clean JSON, no ANSI bleed) | guard, score, diff, trace, diagnose, memory, impact, explain |
310
322
  | `--format sarif` | SARIF 2.1.0 output — findings as rules/results for GitHub Code Scanning and SARIF dashboards | guard |
323
+ | `--format junit` | JUnit XML output — one testcase per validator, for GitLab CI (`artifacts:reports:junit`), Jenkins, Azure DevOps, CircleCI | guard |
324
+ | `--update-baseline` | Adopt DocGuard on a legacy repo without a red day one: freeze today's findings into a committed `.docguard.baseline.json`; guard/ci then gate only NEW drift. Suppression is always visible ("N pre-existing finding(s) suppressed"), and `--no-baseline` shows the full picture | guard |
311
325
  | `--full` | Generate `llms-full.txt` (full doc bodies inlined) instead of the `llms.txt` link index | llms |
312
326
  | `--pack` | Write `.docguard/context-pack.md` — agent session-start context | memory |
313
327
  | `--sync` | Regenerate the agent-file family (CLAUDE.md, Copilot, Cursor, …) from AGENTS.md; hash-marked, never touches hand-written files without `--force` | agents |
@@ -440,6 +454,15 @@ DocGuard ships **18 professional templates** with metadata, badges, and revision
440
454
 
441
455
  ## 🤖 AI Agent Support
442
456
 
457
+ ### One-click MCP install
458
+
459
+ [![Add to Cursor](https://img.shields.io/badge/Cursor-Add_MCP_Server-000000?logo=cursor)](cursor://anysphere.cursor-deeplink/mcp/install?name=docguard&config=eyJjb21tYW5kIjogIm5weCIsICJhcmdzIjogWyIteSIsICJkb2NndWFyZC1jbGkiLCAibWNwIl19)
460
+ [![Install in VS Code](https://img.shields.io/badge/VS_Code-Install_MCP_Server-0098FF?logo=githubcopilot)](vscode:mcp/install?%7B%22name%22%3A%22docguard%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22docguard-cli%22%2C%22mcp%22%5D%7D)
461
+
462
+ - **Claude Code**: `claude mcp add docguard -- npx docguard-cli mcp`
463
+ - **Claude Desktop**: download `docguard-v<version>.mcpb` from the [latest release](https://github.com/raccioly/docguard/releases/latest) and drag it into Settings → Extensions — you'll be asked which project folder to analyze. No npm, no JSON editing.
464
+ - **Anything MCP**: DocGuard is a verified namespace on the [official MCP registry](https://registry.modelcontextprotocol.io/v0/servers?search=docguard) (`io.github.raccioly/docguard`).
465
+
443
466
  DocGuard works with **every major AI coding agent**. All canonical docs are plain markdown — no vendor lock-in.
444
467
 
445
468
  | Agent | Compatibility | Auto-Generate Config |
@@ -563,6 +586,20 @@ DocGuard runs its own `guard`, `score`, `diff`, `diagnose`, and `badge` commands
563
586
 
564
587
  ---
565
588
 
589
+ ## 🏢 Enterprise Adoption
590
+
591
+ Everything runs local or in your CI — no SaaS, no data leaving your infra.
592
+ The pieces that matter at company scale:
593
+
594
+ | Need | DocGuard answer |
595
+ |------|-----------------|
596
+ | **Adopt on a legacy repo** without a red pipeline on day one | `guard --update-baseline` freezes existing findings into a committed `.docguard.baseline.json`; only NEW drift gates from then on (suppression always visible) |
597
+ | **Audit trail** for compliance reviews | `docguard report` — commit-stamped evidence bundle (guard verdict, findings by code, CDD score, ALCOA+ data-integrity attributes, fix history) with a tamper-evident sha256 integrity hash |
598
+ | **Every CI system**, not just GitHub | `guard --format sarif` (GitHub Code Scanning) · `--format junit` (GitLab, Jenkins, Azure DevOps, CircleCI) · `--format json` (anything else) |
599
+ | **Trajectory, not snapshots** | `docguard ci` records every run to `.docguard/history.jsonl`; `score --trend` shows the sparkline + delta |
600
+ | **AI agents on the team** | MCP server (stdio or team-shared HTTP) exposes guard/score/explain/verify/report/diagnose as read-only tools; `agents --sync` keeps the whole agent-file family drift-proof |
601
+ | **Data-integrity framing auditors know** | ALCOA+ scoring (FDA 21 CFR Part 11 / EMA Annex 11 vocabulary) built into `score` and `report` |
602
+
566
603
  ## ⚙️ CI/CD Integration
567
604
 
568
605
  > **Full recipes:** see [`docs-canonical/CI-RECIPES.md`](./docs-canonical/CI-RECIPES.md) for guard, auto-fix (commits mechanical fixes back to PRs), nightly sync, score-on-PR, and pre-commit configs.
@@ -631,31 +668,27 @@ Two ready-to-use templates ship with the Spec Kit extension and as standalone fi
631
668
 
632
669
  ## ✨ What's New
633
670
 
634
- Recent highlights across the v0.16 → v0.19 line:
635
-
636
- - **`docguard explain <validator>`** — `docguard explain freshness` prints purpose, rules, common
637
- failures, and fix recipes for any of the 27 validators. No need to dig into source.
638
- - **`docguard memory --diff`** surface what changed in your canonical docs between two refs
639
- (`HEAD~10..HEAD` by default). Great for code review and changelog drafting.
640
- - **`docguard score --diff`** see exactly which validators moved the score up or down between
641
- two commits. Pinpoints regressions without re-running the full suite by hand.
642
- - **`docguard upgrade --apply --pr`** — when the config schema bumps, DocGuard migrates
643
- `.docguard.json` for you and (optionally) opens a PR with the change.
644
- - **Language-aware traceability** — both `docguard trace` *and* the guard-time Traceability validator
645
- understand Python, Rust, Go, Java, Ruby, and PHP layouts in addition to JS/TS, via a shared pattern
646
- set (`cli/shared-trace-patterns.mjs`) so the two never drift apart.
647
- - **Per-validator severity overrides** escalate `freshness` to `high` for production repos,
648
- demote `doc-quality` to `low` for prototypes. Configurable per-project.
649
- - **JSON Schema for `.docguard.json`** IDE autocomplete, in-line docs, and validation via
650
- `$schema`. Shipped in the package at `schemas/docguard-config.schema.json`.
651
- - **Version pin (`docguardVersion` + `--pin`)** — pin the CLI version your project supports so
652
- CI fails loudly if someone bumps DocGuard without re-running the suite.
653
- - **Cross-process plan cache** repeated runs reuse the validator plan across processes when
654
- the working tree hasn't changed. ~30% faster guard runs on typical repos.
655
- - **Headless-aware banner** — `--quiet`, `--format json`, `--write`, and `--changed-only`
656
- automatically suppress the banner so JSON output stays parse-clean.
657
- - **npm-pack smoke gate** — every release now extracts the actual tarball and runs the CLI
658
- end-to-end before publish, catching missing-file regressions.
671
+ Highlights of the current line (v0.29 → v0.33):
672
+
673
+ - **Adoption baseline** — `guard --update-baseline` freezes a legacy repo's existing findings
674
+ into a committed `.docguard.baseline.json`; guard/ci then gate only NEW drift, with suppression
675
+ always visible. Adopt today, burn down at your own pace.
676
+ - **`docguard report`** commit-stamped compliance-evidence bundle (guard verdict, findings by
677
+ code, CDD score, ALCOA+ attributes, fix history) with a tamper-evident sha256 integrity hash.
678
+ Also exposed as the `docguard_report` MCP tool.
679
+ - **Score history + `score --trend`** — `docguard ci` records every run to
680
+ `.docguard/history.jsonl`; the trend view shows the sparkline and delta over time.
681
+ - **Three machine formats for guard** — `--format json`, `--format sarif` (GitHub Code
682
+ Scanning), and `--format junit` (GitLab, Jenkins, Azure DevOps, CircleCI).
683
+ - **MCP server, stdio + team HTTP** — guard/score/explain/verify/report/diagnose as read-only
684
+ agent tools: `claude mcp add docguard -- npx docguard-cli mcp`.
685
+ - **Agent-file family sync** — `agents --sync` treats AGENTS.md as canonical and regenerates
686
+ CLAUDE.md / `.cursor/rules` / Copilot / Gemini variants with drift-proof source-hash markers.
687
+ - **`verify --semantic` and `verify --instructions`** — extract documented numbers/limits/enums
688
+ as agent verification tasks; audit the agent-instruction files themselves for contradictions
689
+ and stale pointers.
690
+ - **`docguard agent`**one-shot ordered task graph with pre-filled code-truth, collapsing ~10
691
+ agent round-trips into one call.
659
692
 
660
693
  See [CHANGELOG.md](CHANGELOG.md) for the full history.
661
694
 
@@ -745,6 +778,13 @@ See [CONTRIBUTING.md](CONTRIBUTING.md#research--academic-credits) for full citat
745
778
 
746
779
  ---
747
780
 
781
+ ## 🔒 Privacy & Supply Chain
782
+
783
+ DocGuard is local-first: no telemetry, no analytics, no phone-home — the full
784
+ (short) policy is in [PRIVACY.md](PRIVACY.md). npm releases are published with
785
+ [provenance attestation](https://docs.npmjs.com/generating-provenance-statements),
786
+ so you can verify each tarball was built by GitHub Actions from this repository.
787
+
748
788
  ## 📄 License
749
789
 
750
790
  [MIT](LICENSE) — Free to use, modify, and distribute.
@@ -6,11 +6,18 @@
6
6
  * 0 = All pass, score meets threshold
7
7
  * 1 = Guard errors or score below threshold
8
8
  * 2 = Guard warnings only
9
+ *
10
+ * v0.33: each run appends one line to `.docguard/history.jsonl` (score,
11
+ * grade, commit, guard counts) so `docguard score --trend` can show the
12
+ * trajectory. Opt out with `--no-history`. The append is silent-on-failure —
13
+ * recording history must never fail the pipeline it records.
9
14
  */
10
15
 
11
16
  import { c } from '../shared.mjs';
12
17
  import { runGuardInternal } from './guard.mjs';
13
18
  import { runScoreInternal } from './score.mjs';
19
+ import { appendHistory } from '../writers/history.mjs';
20
+ import { getHeadInfo, isGitRepo } from '../shared-git.mjs';
14
21
 
15
22
  export function runCI(projectDir, config, flags) {
16
23
  const threshold = parseInt(flags.threshold || '0', 10);
@@ -26,12 +33,41 @@ export function runCI(projectDir, config, flags) {
26
33
 
27
34
  // ── Run guard (internal — no subprocess) ──
28
35
  const guardData = runGuardInternal(projectDir, config);
29
- const hasErrors = guardData.errors > 0;
30
- const hasWarnings = guardData.warnings > 0;
36
+ // Severity-aware effective counts (M2): `guard` gates on these, so `ci`
37
+ // must too — a severity=low demotion or severity=high escalation has to
38
+ // produce the same verdict from both commands.
39
+ const hasErrors = guardData.effectiveErrors > 0;
40
+ const hasWarnings = guardData.effectiveWarnings > 0;
31
41
 
32
42
  // ── Get score ──
33
43
  const scoreData = runScoreInternal(projectDir, config);
34
44
 
45
+ // Status reflects EVERY gate, not just guard (L3): a threshold or
46
+ // --fail-on-warning failure exits 1 and must not be recorded as PASS in
47
+ // history or the JSON consumers parse.
48
+ const thresholdMet = threshold <= 0 || scoreData.score >= threshold;
49
+ const status =
50
+ hasErrors || !thresholdMet || (failOnWarning && hasWarnings) ? 'FAIL'
51
+ : hasWarnings ? 'WARN'
52
+ : 'PASS';
53
+
54
+ // ── Record history (unless opted out) ──
55
+ if (!flags.noHistory) {
56
+ const git = isGitRepo(projectDir) ? getHeadInfo(projectDir) : null;
57
+ appendHistory(projectDir, {
58
+ timestamp: new Date().toISOString(),
59
+ commit: git ? git.commit.slice(0, 12) : null,
60
+ score: scoreData.score,
61
+ grade: scoreData.grade,
62
+ errors: guardData.errors,
63
+ warnings: guardData.warnings,
64
+ baselineSuppressed: guardData.baselineSuppressed || 0,
65
+ passed: guardData.passed,
66
+ total: guardData.total,
67
+ status,
68
+ });
69
+ }
70
+
35
71
  // ── Output ──
36
72
  if (isJson) {
37
73
  const result = {
@@ -44,14 +80,18 @@ export function runCI(projectDir, config, flags) {
44
80
  passed: guardData.passed,
45
81
  total: guardData.total,
46
82
  status: guardData.status,
83
+ baselineSuppressed: guardData.baselineSuppressed || 0,
47
84
  validators: guardData.validators.filter(v => v.status !== 'skipped'),
48
85
  },
49
86
  threshold,
50
- thresholdMet: threshold <= 0 || scoreData.score >= threshold,
51
- status: hasErrors ? 'FAIL' : hasWarnings ? 'WARN' : 'PASS',
87
+ thresholdMet,
88
+ status,
52
89
  timestamp: new Date().toISOString(),
53
90
  };
54
- console.log(JSON.stringify(result, null, 2));
91
+ // Machine output must survive a pipe: stdout.write + natural exit, never
92
+ // console.log + process.exit (>8 KB payloads truncate mid-flush — same
93
+ // class as the guard --format json bug fixed in v0.28).
94
+ process.stdout.write(JSON.stringify(result, null, 2) + '\n');
55
95
  } else {
56
96
  // Text output
57
97
  const guardStatus = hasErrors
@@ -61,20 +101,19 @@ export function runCI(projectDir, config, flags) {
61
101
  : `${c.green}✅ PASS${c.reset}`;
62
102
 
63
103
  console.log(` ${c.bold}Guard:${c.reset} ${guardStatus} (${guardData.passed}/${guardData.total})`);
104
+ if (guardData.baselineSuppressed > 0) {
105
+ console.log(` ${c.dim}📋 ${guardData.baselineSuppressed} pre-existing finding(s) suppressed by the committed baseline${c.reset}`);
106
+ }
64
107
  console.log(` ${c.bold}Score:${c.reset} ${scoreData.score}/100 (${scoreData.grade})`);
65
108
 
66
109
  if (threshold > 0) {
67
- const met = scoreData.score >= threshold;
68
- console.log(` ${c.bold}Threshold:${c.reset} ${met ? `${c.green}✅ ≥${threshold}` : `${c.red}❌ <${threshold}`}${c.reset}`);
110
+ console.log(` ${c.bold}Threshold:${c.reset} ${thresholdMet ? `${c.green}✅ ≥${threshold}` : `${c.red}❌ <${threshold}`}${c.reset}`);
69
111
  }
70
112
 
71
113
  console.log('');
72
114
  }
73
115
 
74
- // Exit code determination
75
- if (hasErrors) process.exit(1);
76
- if (threshold > 0 && scoreData.score < threshold) process.exit(1);
77
- if (failOnWarning && hasWarnings) process.exit(1);
78
- if (hasWarnings) process.exit(2);
79
- process.exit(0);
116
+ // Exit code follows `status` exactly — one derivation, no drift between
117
+ // what history/JSON record and what the pipeline does.
118
+ process.exitCode = status === 'FAIL' ? 1 : status === 'WARN' ? 2 : 0;
80
119
  }
@@ -16,6 +16,8 @@ import { checkUpgradeStatus } from './upgrade.mjs';
16
16
  import { changedFilesSince, isGitRepo } from '../shared-git.mjs';
17
17
  import { extractSemanticClaims } from '../scanners/semantic-claims.mjs';
18
18
  import { toSarif } from '../writers/sarif.mjs';
19
+ import { toJUnit } from '../writers/junit.mjs';
20
+ import { loadBaseline, saveBaseline, fingerprintFinding, BASELINE_FILE } from '../writers/baseline.mjs';
19
21
  import { readFileSync, writeFileSync, existsSync } from 'node:fs';
20
22
  import { resolve as resolvePath, relative as relativePath } from 'node:path';
21
23
  import { fileURLToPath as fp } from 'node:url';
@@ -393,6 +395,42 @@ export function runGuardInternal(projectDir, config) {
393
395
  }
394
396
  }
395
397
 
398
+ // ── Adoption baseline (v0.33) ──
399
+ // If the repo committed `.docguard.baseline.json`, findings frozen at
400
+ // adoption time are suppressed BEFORE any tally — so exit codes, severity
401
+ // rollups, json/sarif/junit, ci, and report all gate only NEW drift.
402
+ // Suppression is visible (baselineSuppressed in the payload + a display
403
+ // note), applies only to findings-backed results (legacy string-only
404
+ // errors/warnings can't be fingerprinted), and `--no-baseline`
405
+ // (config.baseline === false) turns it off.
406
+ let baselineSuppressed = 0;
407
+ const baselineMap = config.baseline === false ? null : loadBaseline(projectDir);
408
+ if (baselineMap) {
409
+ // Occurrence budget: each fingerprint suppresses at most its frozen
410
+ // count (H2). Validators run in a fixed order, so consumption is
411
+ // deterministic — the same tree always suppresses the same instances.
412
+ const remaining = new Map(baselineMap);
413
+ for (const r of results) {
414
+ if (!Array.isArray(r.findings) || r.findings.length === 0) continue;
415
+ if (r.errors.length + r.warnings.length !== r.findings.length) continue;
416
+ const kept = r.findings.filter(f => {
417
+ const fp = fingerprintFinding(f);
418
+ const budget = remaining.get(fp) || 0;
419
+ if (budget <= 0) return true;
420
+ remaining.set(fp, budget - 1);
421
+ return false;
422
+ });
423
+ const removed = r.findings.length - kept.length;
424
+ if (removed === 0) continue;
425
+ baselineSuppressed += removed;
426
+ r.findings = kept;
427
+ r.errors = kept.filter(f => f.severity === 'error').map(f => f.message);
428
+ r.warnings = kept.filter(f => f.severity !== 'error').map(f => f.message);
429
+ r.total = r.passed + kept.length;
430
+ Object.assign(r, classifyResult(r));
431
+ }
432
+ }
433
+
396
434
  const activeResults = results.filter(r => r.status !== 'skipped');
397
435
  const totalErrors = activeResults.reduce((sum, r) => sum + r.errors.length, 0);
398
436
  const totalWarnings = activeResults.reduce((sum, r) => sum + r.warnings.length, 0);
@@ -464,6 +502,7 @@ export function runGuardInternal(projectDir, config) {
464
502
  // things they've marked as high-severity.
465
503
  effectiveErrors,
466
504
  effectiveWarnings,
505
+ baselineSuppressed,
467
506
  coverage,
468
507
  semanticClaims,
469
508
  validators: results,
@@ -555,6 +594,30 @@ export function runGuard(projectDir, config, flags) {
555
594
  console.log(`${c.cyan}⚡ docguard guard --changed-only${c.reset} ${c.dim}(${label})${c.reset}${escalatedNote}\n`);
556
595
  }
557
596
 
597
+ // ── `--update-baseline`: freeze the CURRENT full finding set ──
598
+ // Runs with the baseline disabled so the file captures everything visible
599
+ // today (updating through an active baseline would only ever shrink it).
600
+ if (flags.updateBaseline) {
601
+ // --changed-only rewrites config.validators to the 5-validator lite set;
602
+ // freezing THAT would silently shrink the committed team baseline to a
603
+ // subset (L1). Refuse the combination rather than corrupt the file.
604
+ if (flags.changedOnly) {
605
+ console.error(`${c.red}✗ --update-baseline cannot be combined with --changed-only — the baseline must freeze the FULL validator set, not the pre-commit lite subset.${c.reset}`);
606
+ process.exitCode = 1;
607
+ return;
608
+ }
609
+ const fullData = runGuardInternal(projectDir, { ...config, baseline: false });
610
+ const n = saveBaseline(projectDir, fullData.findings || []);
611
+ if (flags.format === 'json') {
612
+ process.stdout.write(JSON.stringify({ written: true, file: BASELINE_FILE, fingerprints: n, findings: (fullData.findings || []).length }, null, 2) + '\n');
613
+ } else {
614
+ console.log(`${c.green}✅ Baseline written:${c.reset} ${BASELINE_FILE} (${n} fingerprint(s))`);
615
+ console.log(`${c.dim} Commit it. guard/ci now gate only NEW findings; --no-baseline shows everything.${c.reset}`);
616
+ }
617
+ process.exitCode = 0;
618
+ return;
619
+ }
620
+
558
621
  const data = runGuardInternal(projectDir, config);
559
622
 
560
623
  // ── SARIF output (2.1.0) ──
@@ -567,6 +630,17 @@ export function runGuard(projectDir, config, flags) {
567
630
  return;
568
631
  }
569
632
 
633
+ // ── JUnit XML output ──
634
+ // SARIF is GitHub's language; JUnit is everyone else's (GitLab
635
+ // artifacts:reports:junit, Jenkins junit step, Azure DevOps, CircleCI).
636
+ // Exit-code semantics identical to sarif/json.
637
+ if (flags.format === 'junit') {
638
+ const xml = toJUnit(data);
639
+ process.exitCode = data.effectiveErrors > 0 ? 1 : data.effectiveWarnings > 0 ? 2 : 0;
640
+ process.stdout.write(xml + '\n');
641
+ return;
642
+ }
643
+
570
644
  // ── JSON output ──
571
645
  if (flags.format === 'json') {
572
646
  // Use severity-aware effective counts for exit code; raw counts stay in the JSON
@@ -671,6 +745,12 @@ export function runGuard(projectDir, config, flags) {
671
745
  console.log(` ${c.red}${c.bold}❌ FAIL${c.reset} ${c.red}— ${data.passed}/${data.total} passed, ${data.effectiveErrors} blocking issue(s)${warnSuffix}${c.reset}`);
672
746
  }
673
747
 
748
+ // Baseline suppression is always visible — a gate that hides findings
749
+ // silently is the false-green failure mode this tool exists to prevent.
750
+ if (data.baselineSuppressed > 0) {
751
+ console.log(` ${c.dim}📋 ${data.baselineSuppressed} pre-existing finding(s) suppressed by ${BASELINE_FILE} (--no-baseline to show)${c.reset}`);
752
+ }
753
+
674
754
  // ── Next steps — every run ends with a suggested action (v0.27) ──
675
755
  // The field-report principle: whenever DocGuard calls out an issue it must
676
756
  // suggest what to do next; on a clean run it points at the next workflow step
@@ -27,6 +27,7 @@ import { resolve, dirname } from 'node:path';
27
27
  import { fileURLToPath } from 'node:url';
28
28
  import { runGuardInternal } from './guard.mjs';
29
29
  import { runScoreInternal } from './score.mjs';
30
+ import { buildReport } from './report.mjs';
30
31
  import { loadConfig } from '../config.mjs';
31
32
  import { CODES } from '../findings.mjs';
32
33
  import { extractSemanticClaims, buildSemanticVerifyTasks } from '../scanners/semantic-claims.mjs';
@@ -110,6 +111,16 @@ const TOOLS = [
110
111
  },
111
112
  annotations: READONLY_ANNOTATIONS,
112
113
  },
114
+ {
115
+ name: 'docguard_report',
116
+ title: 'Compliance-evidence bundle',
117
+ description: 'Generate the commit-stamped compliance-evidence bundle: guard verdict per validator, findings grouped by stable code, CDD score, ALCOA+ data-integrity attributes, fix history, and a tamper-evident sha256 integrity hash. Evidence, not a gate — it reports state without failing.',
118
+ inputSchema: {
119
+ type: 'object',
120
+ properties: { ...PROJECT_DIR_PROP },
121
+ },
122
+ annotations: READONLY_ANNOTATIONS,
123
+ },
113
124
  {
114
125
  name: 'docguard_diagnose',
115
126
  title: 'Diagnose what to fix',
@@ -169,6 +180,11 @@ const TOOL_HANDLERS = {
169
180
  };
170
181
  },
171
182
 
183
+ docguard_report(args, defaultDir) {
184
+ const { dir, config } = resolveTarget(args, defaultDir);
185
+ return buildReport(dir, config);
186
+ },
187
+
172
188
  docguard_diagnose(args, defaultDir) {
173
189
  const { dir, config } = resolveTarget(args, defaultDir);
174
190
  const data = runGuardInternal(dir, config);