Skip to content

Commit a2f101e

Browse files
authored
Merge pull request #4 from Shellghostt/feat/m4-implementation
feat(m4): add terminal reports and redacted offline bundles
2 parents 6cf3581 + 0ed86f9 commit a2f101e

57 files changed

Lines changed: 6756 additions & 117 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
99

1010
### Added
1111

12+
- M4 ENV-024–ENV-026: scrolling Bubble Tea reports with plain fallback, explicit
13+
`--format text|markdown|json`, `--plain` and escaped, bounded Markdown export.
14+
- Version-1 diagnostic bundles with typed allowlisted sharing evidence, opaque path/host aliases,
15+
Git identity presence facts, explicit omissions, strict archive/JSON bounds and atomic publication.
16+
`--include-logs` contains only structured collector statuses/timings.
17+
- Offline `diagnose --from-bundle`, recomputing current builtin findings from validated evidence with
18+
capture/evaluator provenance and no collectors or network work.
19+
- Accepted [ADR 0006](docs/adr/0006-m4-reports-and-bundles.md), sharing schemas, archive/privacy/renderer/
20+
CLI tests, a real terminal capture and [M4 validation](docs/testing/m4-validation.md).
21+
Local gates and native M4 Windows/Ubuntu/macOS GitHub CI passed;
22+
[PR #4](https://github.com/Shellghostt/EnvDoctor/pull/4) is open for review.
1223
- M3 rules ENV007–ENV012: known Docker API incompatibility, explicitly required dependency absence,
1324
package-manager/lockfile disagreements, effective Git identity/explicit autocrlf policy,
1425
canonical virtualenv/interpreter mismatch and opt-in proxy refusal/no-route evidence.
@@ -21,7 +32,7 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
2132
CLI, cancellation and socket lifecycle regressions.
2233
- Accepted [ADR 0005](docs/adr/0005-m3-evidence-and-rule-registry.md),
2334
[M3 acceptance requirements](docs/phases/M3.md), [validation evidence](docs/testing/m3-validation.md)
24-
and [development-tool audit](docs/DEVELOPMENT-TOOLS.md). M3 is complete on the feature branch;
35+
and [development-tool audit](docs/DEVELOPMENT-TOOLS.md). M3 is complete and merged through PR #3;
2536
[CI 43723839978](https://github.com/Shellghostt/EnvDoctor/actions/runs/43723839978) passed native
2637
Windows/Ubuntu/macOS race, tests and builds, plus lint and the vulnerability scan.
2738

@@ -35,6 +46,9 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
3546

3647
### Changed
3748

49+
- Optional bundle-source metadata extends report schema v1 and stays absent from ordinary reports.
50+
- Terminal dependencies are pinned/audited, including Bubble Tea v1.3.10, x/term v0.48.0,
51+
x/sys v0.50.0 and x/text v0.44.0; see [M4 dependency review](docs/testing/m4-dependencies.md).
3852
- Optional M3 snapshot evidence extends schema v1 compatibly; project and rule-registry JSON have
3953
separate version-1 schemas. Explicit typed partial collector evidence retains degraded notices
4054
and disables dependent rules.
@@ -72,7 +86,7 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
7286

7387
### Planned
7488

75-
- M4 reports and bundles; later rules ENV013–ENV018, confirmed fixes and signed releases.
89+
- Rules ENV013–ENV018, confirmed fixes and signed releases.
7690

7791
## [0.1.0] - 2026-11-13
7892

‎CONTRIBUTING.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Thanks for taking the time. This document is deliberately short and specific.
99
2. [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) - how the pieces fit together.
1010
3. [docs/adr/](docs/adr/) - decisions that have already been argued about. Do not relitigate them
1111
without a new ADR.
12-
4. [docs/phases/M3.md](docs/phases/M3.md) and [ADR 0005](docs/adr/0005-m3-evidence-and-rule-registry.md) -
13-
implemented M3 evidence contracts and verified three-OS CI gate.
12+
4. [docs/phases/M4.md](docs/phases/M4.md) - report/bundle contracts, dependency order and acceptance gates;
13+
preserve [M3 evidence contracts](docs/phases/M3.md) and accepted ADRs 0005/0006.
1414
5. [docs/DEVELOPMENT-TOOLS.md](docs/DEVELOPMENT-TOOLS.md) - CodeGraph freshness, static-analysis coverage
1515
and profiling appropriate to this repository's runtime.
1616

@@ -36,6 +36,8 @@ the CLI and runs all 172 golden cases through it, including the unchanged 54 M2
3636
Each new rule needs positive, negative and edge snapshots for Windows, Linux and macOS. Expected
3737
findings are reviewed evidence, not output regenerated from the implementation. See
3838
[M3 validation](docs/testing/m3-validation.md) for native Windows and Linux race commands and limits.
39+
[M4 validation](docs/testing/m4-validation.md) records terminal, sharing, archive, offline and resource
40+
cases. M4 local gates and native Windows/Ubuntu/macOS GitHub CI pass.
3941
Windows race tests need a 64-bit MinGW-w64-compatible GCC configured in Go's CC/CXX; ordinary static
4042
builds use `make build`, which disables CGO only for that target.
4143

‎README.md‎

Lines changed: 78 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22

33
> A cross-platform CLI that detects, diagnoses and helps resolve development environment problems.
44
5-
![status](https://img.shields.io/badge/status-M3_complete-green)
5+
![status](https://img.shields.io/badge/status-M4_verified-green)
66
[![license](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
77
![Go](https://img.shields.io/badge/go-1.26-00ADD8?logo=go&logoColor=white)
88

9-
**Status: M3 complete on `feat/m3-implementation`; Windows, Ubuntu and macOS CI passed.**
9+
**Status: M1–M3 merged; M4 implemented and verified on `feat/m4-implementation`.**
10+
Native Windows/Ubuntu/macOS race, tests and builds, lint and the vulnerability scan passed in
11+
[M4 CI](https://github.com/Shellghostt/EnvDoctor/actions/runs/44421272870).
12+
[PR #4](https://github.com/Shellghostt/EnvDoctor/pull/4) is open for review.
1013
Nine collectors feed twelve rules covering platform, shell, PATH, Python/Node runtime, requested TCP ports,
1114
effective Git config, local Docker/API metadata, explicit project dependencies and proxy configuration.
12-
Reports are plain text or versioned JSON; `explain` and `rules --json` work offline.
15+
Reports support a scrolling terminal viewer, plain text, Markdown and versioned JSON.
16+
Redacted diagnostic bundles can be evaluated offline; `explain` and `rules --json` also work offline.
1317
Diagnosis never applies fixes or executes interpreters found on PATH. The
14-
[M3 validation record](docs/testing/m3-validation.md) records commands, live checks and limits.
18+
[M4 validation record](docs/testing/m4-validation.md) records commands, live checks and limits;
19+
[M3 validation](docs/testing/m3-validation.md) preserves the merged baseline evidence.
1520

1621
## Why this exists
1722

@@ -35,8 +40,8 @@ explains the cause instead of dumping raw output.
3540
| Detect virtualenv/interpreter mismatch | M3 | **Implemented**, known canonical environment metadata |
3641
| Inspect proxy configuration and optional reachability | M3 | **Implemented**, redacted and offline by default |
3742
| Explain rules and export the rule registry | M3 | **Implemented**, no collectors invoked |
38-
| Generate diagnostic bundles | M4 | Not started |
39-
| Human-readable reports | M2/M4 | **Done** plain text; interactive polish is M4 |
43+
| Generate redacted diagnostic bundles and evaluate them offline | M4 | **Implemented and verified** locally and in native CI |
44+
| Human-readable reports | M2/M4 | Plain text, scrolling terminal viewer and escaped Markdown |
4045
| JSON export | M1 | **Done** |
4146
| Safe, opt-in automated remediation | M5 | Not started |
4247
| Windows, Linux and macOS support | M2/M6 | Three-OS code and fixtures; signed release/clean-host verification is M6 |
@@ -49,7 +54,10 @@ flowchart TD
4954
COL --> SNAP[Typed snapshot and redaction]
5055
SNAP --> ENGINE[Pure diagnostic engine]
5156
REG[Rule registry] --> ENGINE
52-
ENGINE --> REPORT[Plain text or JSON with manual advice]
57+
ENGINE --> REPORT[Terminal, text, Markdown or JSON report]
58+
SNAP --> BUNDLE[Allowlisted sharing evidence and bounded ZIP]
59+
BUNDLE --> OFFLINE[Validated captured evidence]
60+
OFFLINE --> ENGINE
5361
META[explain and rules] --> REG
5462
REG --> PAGES[Generated rule pages]
5563
```
@@ -110,6 +118,51 @@ in the test suite; the snapshot inside it is described by
110118
[docs/schema/snapshot-v1.schema.json](docs/schema/snapshot-v1.schema.json). Home directories are replaced
111119
with `~`, and credential-bearing URLs are redacted before anything is written.
112120

121+
## Terminal reports and sharing bundles
122+
123+
The default report opens a scrolling viewer when stdin, stdout and stderr are terminals. Use arrows,
124+
Page Up/Page Down and `q`; quitting retains the diagnosis exit code and leaves a plain report behind.
125+
Interrupts and rendering failures exit 3 and restore terminal state. Redirects, `TERM=dumb`, `NO_COLOR`
126+
(including an empty value), `--plain` and explicit text select plain output.
127+
128+
![EnvDoctor M4 terminal viewer](docs/images/m4-terminal.jpg)
129+
130+
This is real Windows PTY output from the implemented CLI, displayed in xterm.js with the committed
131+
synthetic [viewer fixture](docs/testing/fixtures/m4-viewer/snapshot.json). Its identities and paths are
132+
examples. The browser display is a captured terminal preview; native console restoration and resize
133+
were checked separately.
134+
135+
```powershell
136+
.\bin\envdoctor.exe diagnose --plain
137+
.\bin\envdoctor.exe diagnose --format markdown > diagnosis.md
138+
.\bin\envdoctor.exe diagnose --format json > diagnosis.json
139+
.\bin\envdoctor.exe bundle --output envdoctor-bundle.zip --include-logs
140+
.\bin\envdoctor.exe diagnose --from-bundle envdoctor-bundle.zip --json
141+
```
142+
143+
JSON and Markdown bypass the viewer. `--json` remains an alias for `--format json`; conflicting formats
144+
or `--plain` with JSON/Markdown exit 4 before collection. Markdown includes evidence, manual suggestions,
145+
verification, limitations, degraded collectors and skipped prerequisites, with dynamic markup escaped.
146+
147+
Bundle export uses a separate typed allowlist: Git identity becomes presence booleans, paths and hosts
148+
become deterministic capture-local aliases, and unsupported required evidence is explicitly omitted and
149+
degraded. Raw environment values, identities, project contents and free-text logs/errors are excluded.
150+
`--include-logs` adds only structured collector statuses and bounded timings. Numeric versions, ports and
151+
diagnostic facts still describe the captured setup; review the bundle before sharing it.
152+
153+
The ZIP is below 2,000,000 bytes, with independent member, decompression and JSON-work bounds. Publication
154+
stages a private file and replaces the destination atomically after validation. The bounded `Writing...`
155+
status precedes replacement; exit 0 confirms publication, including captures with findings or degradation.
156+
Usage exits 4; capture, archive, cancellation, output and file failures exit 3.
157+
158+
`--from-bundle` validates evidence and evaluates the current builtin rules without collectors or network
159+
work. It preserves capture provenance and omissions; saved verdicts and commands remain reference data.
160+
It conflicts with `--fixture-dir`, `--port`, `--probe-network` and `--package-manager`. Valid offline
161+
diagnosis retains exits 0/1/2/3, including 3 for unavailable required evidence. Ordinary JSON keeps its
162+
existing fields and Git identity; bundle-source metadata is an optional addition used by offline reports.
163+
Read [ADR 0006](docs/adr/0006-m4-reports-and-bundles.md) and the
164+
[sharing schemas](docs/schema/bundle-snapshot-v1.schema.json) for the exact policy and limits.
165+
113166
Exit codes: `0` nothing at or above warning, `1` warnings, `2` at least one error, `3` the tool itself failed
114167
(including a collector timeout), `4` invalid usage. Captured collector errors retain exit 3 during offline
115168
diagnosis. A degraded report still contains the findings that could be evaluated.
@@ -188,7 +241,7 @@ Different Docker product versions alone do not establish API incompatibility. Wi
188241
opaque shims and protected package paths remain unresolved metadata.
189242

190243
Home paths and credential-bearing URLs are redacted, including error notices. JSON includes Git identity;
191-
review it before sharing. Diagnostic bundles with broader redaction remain M4.
244+
review it before sharing. Use the M4 bundle command for the separate allowlisted sharing representation.
192245

193246
## Testing
194247

@@ -206,8 +259,10 @@ The suite includes 172 exact golden cases, preserving all 54 original M2 snapsho
206259
It builds the CLI and checks those cases through real subprocesses, validating JSON and exit codes.
207260
Native Windows and Linux race suites passed locally. The native Windows, Ubuntu and macOS race/test/build
208261
matrix, lint and vulnerability scan passed in [M3 CI](https://github.com/Shellghostt/EnvDoctor/actions/runs/43723839978).
209-
Both macOS architectures also cross-build. Commands, allocation measurements,
210-
socket lifecycle evidence and limits are in [docs/testing/m3-validation.md](docs/testing/m3-validation.md).
262+
M4 passes local Windows/Linux race, all canonical targets, bounded fuzzing, archive/privacy tests and
263+
all six static build targets. Native Windows/Ubuntu/macOS M4 CI also passed. Commands, terminal evidence,
264+
allocation measurements and limits are in [M4 validation](docs/testing/m4-validation.md);
265+
[M3 validation](docs/testing/m3-validation.md) records the earlier socket and CI evidence.
211266

212267
`make docs` regenerates all twelve rule pages from the same registry as findings, `explain` and `rules`.
213268
`make check-docs` and CI detect documentation drift. Do not edit generated pages directly.
@@ -218,7 +273,8 @@ A local release build of all six targets:
218273
goreleaser build --snapshot --clean
219274
```
220275

221-
`goreleaser check` and the local six-target snapshot build passed. A snapshot build does not publish a release.
276+
M3 validation records the passing GoReleaser check and six-target snapshot build. M4 verifies static
277+
builds separately; packaging, signed releases and clean-host checks remain M6.
222278

223279
## Repository layout
224280

@@ -230,9 +286,10 @@ goreleaser build --snapshot --clean
230286
| `internal/config` | Resolved options, schema version, collector timeout |
231287
| `internal/collector` | Parallel runner and nine collectors, including project and proxy evidence |
232288
| `internal/diagnostic` | Rule registry, pure engine, severity model, fixture harness |
233-
| `internal/report` | Terminal renderer, JSON renderer |
289+
| `internal/report` | Terminal lifecycle, plain text, Markdown and JSON renderers |
290+
| `internal/bundle` | Allowlisted export, strict bounded reader and atomic publication |
234291
| `internal/fix` | Remediation plans, dry-run by default (empty until M5) |
235-
| `internal/system` | Thin wrappers over OS facilities, the only place syscalls live |
292+
| `internal/system` | Machine-inspection wrappers; bundle file I/O and terminal control have separate boundaries |
236293
| `docs/schema` | Committed JSON schemas, enforced by tests |
237294
| `tests/golden` | 172 snapshot-to-diagnosis fixtures |
238295
| `tests/integration` | Built CLI tests against all golden cases |
@@ -241,16 +298,21 @@ goreleaser build --snapshot --clean
241298

242299
## Roadmap
243300

244-
M3 is **complete on the feature branch, including three-OS CI**. Read the
301+
M3 is **complete and merged** through [PR #3](https://github.com/Shellghostt/EnvDoctor/pull/3), with
302+
successful [main CI](https://github.com/Shellghostt/EnvDoctor/actions/runs/43802280915). Read the
245303
[M3 acceptance gates](docs/phases/M3.md), [accepted ADR 0005](docs/adr/0005-m3-evidence-and-rule-registry.md)
246304
and [validation record](docs/testing/m3-validation.md) for its contracts and evidence.
305+
M4 ENV-024–ENV-026 are implemented and verified under the
306+
[M4 requirements](docs/phases/M4.md) and [accepted ADR 0006](docs/adr/0006-m4-reports-and-bundles.md).
307+
[Validation](docs/testing/m4-validation.md) records local evidence and passing native GitHub CI;
308+
[PR #4](https://github.com/Shellghostt/EnvDoctor/pull/4) is open for review.
247309

248310
| Milestone | Deliverable | Status |
249311
|---|---|---|
250312
| M1 | CLI foundation, collector interface, system information | **Done** (v0.1.0) |
251313
| M2 | Cross-platform collectors and rules ENV001–ENV006 | **Done (merged)** |
252-
| M3 | Rules ENV007–ENV012, Docker/dependency/proxy evidence, offline registry commands | **Done (feature branch, CI passed)** |
253-
| M4 | Polished terminal output, Markdown export, diagnostic bundles | Not started |
314+
| M3 | Rules ENV007–ENV012, Docker/dependency/proxy evidence, offline registry commands | **Done (merged)** |
315+
| M4 | Terminal viewer, Markdown, redacted bundles and offline diagnosis | Verified; [PR #4](https://github.com/Shellghostt/EnvDoctor/pull/4) open |
254316
| M5 | Safe, confirmed automated remediation | Not started |
255317
| M6 | Windows, Linux, macOS packaging and signed releases | Not started |
256318

‎cmd/envdoctor/main.go‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
package main
77

88
import (
9+
"context"
910
"os"
11+
"os/signal"
12+
"syscall"
1013

1114
"github.com/shellghostt/envdoctor/internal/cli"
1215
)
@@ -17,10 +20,15 @@ import (
1720
var version = "dev"
1821

1922
func main() {
23+
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
24+
defer stop()
2025
os.Exit(cli.Main(os.Args, cli.App{
21-
Version: version,
22-
Stdout: os.Stdout,
23-
Stderr: os.Stderr,
24-
Getenv: os.Getenv,
26+
Version: version,
27+
Stdin: os.Stdin,
28+
Stdout: os.Stdout,
29+
Stderr: os.Stderr,
30+
Getenv: os.Getenv,
31+
LookupEnv: os.LookupEnv,
32+
Context: ctx,
2533
}))
2634
}

0 commit comments

Comments
 (0)