truecourse 0.5.12 → 0.6.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,44 +14,39 @@
14
14
  <a href="https://github.com/truecourse-ai/truecourse/actions/workflows/test.yml"><img src="https://github.com/truecourse-ai/truecourse/actions/workflows/test.yml/badge.svg" alt="Tests" /></a>
15
15
  <a href="https://www.npmjs.com/package/truecourse"><img src="https://img.shields.io/npm/v/truecourse" alt="npm version" /></a>
16
16
  <a href="https://github.com/truecourse-ai/truecourse/blob/main/LICENSE"><img src="https://img.shields.io/github/license/truecourse-ai/truecourse" alt="License" /></a>
17
- <a href="https://discord.gg/8AYwf26A"><img src="https://img.shields.io/badge/Discord-join-5865F2?logo=discord&logoColor=white" alt="Discord" /></a>
17
+ <a href="https://discord.gg/TanxB63arz"><img src="https://img.shields.io/badge/Discord-join-5865F2?logo=discord&logoColor=white" alt="Discord" /></a>
18
18
  </p>
19
19
 
20
- TrueCourse analyzes your codebase architecture and code to detect violations that traditional linters miss circular dependencies, layer violations, dead modules, race conditions, security anti-patterns, and more. It combines tree-sitter static analysis with LLM-powered review to surface findings with fix suggestions.
20
+ TrueCourse catches two classes of defect, through two independent toolsuse either on its own or both together:
21
+
22
+ - **Code defects** (`truecourse analyze`) — from the categories linters cover (unused code, style, missing types) through to ones they don't reach: circular dependencies, layer violations, dead modules, race conditions, security anti-patterns, performance footguns. Tree-sitter analysis combined with LLM review.
23
+ - **Business-logic drift** (`truecourse verify`) — when the implementation no longer matches what the docs say it should do. Wrong response codes, missing entity fields, illegal state transitions, bypassed auth, silently-dropped effects, formulas that have lost an input. TrueCourse extracts a contract from your PRDs/ADRs/READMEs and checks the code against it.
24
+
25
+ Both store their results under `.truecourse/` and surface them in a shared [dashboard](#dashboard-web-ui) for human review, with plain-text CLI output an agent can read directly.
21
26
 
22
27
  <p align="center">
23
28
  <img src="assets/demo.gif" alt="TrueCourse Screenshot" width="100%" />
24
29
  </p>
25
30
 
26
- ## What it catches
27
-
28
- **Architecture** — Circular dependencies, layer violations, god modules, dead modules, tight coupling, cross-service imports
29
-
30
- **Code quality** — Magic numbers, empty catch, console.log, cognitive complexity, unused variables, redundant code, missing type hints
31
-
32
- **Security** — SQL injection, hardcoded secrets, eval usage, insecure random, XSS, path traversal, unsafe deserialization
33
-
34
- **Bugs** — Race conditions, type mismatches, mutable defaults, implicit optional, off-by-one, unchecked returns
31
+ Jump to: **[1. Analyze](#1-analyze--code-intelligence)** · **[2. Spec → Verify](#2-spec--verify--business-logic-drift)** · **[Dashboard](#dashboard-web-ui)**
35
32
 
36
- **Performance** N+1 queries, O() string concat, unnecessary allocations, missing pagination, sync I/O in async
33
+ No setup step and no database: TrueCourse creates `.truecourse/` in your repo on first use and stores everything there as plain JSON files. It uses the [Claude Code CLI](https://docs.anthropic.com/en/docs/claude-code) for LLM-powered work if `claude` isn't on your PATH, deterministic analysis still runs and LLM-dependent features are skipped.
37
34
 
38
- **Reliability** — Unhandled promises, resource leaks, missing timeouts, swallowed exceptions, unsafe error handling
35
+ ---
39
36
 
40
- **Database** Missing indexes, missing transactions, lazy loading in loops, raw SQL bypassing ORM, schema issues
37
+ # 1. Analyze code intelligence
41
38
 
42
- **Style** Import ordering, naming conventions, docstring completeness, formatting preferences
39
+ Static + LLM analysis of your code: architecture, security, bugs, performance, and more.
43
40
 
44
41
  ## Quick Start
45
42
 
46
43
  ```bash
47
44
  cd <your-repo>
48
45
  npx truecourse analyze # Runs the full analysis in-process
49
- npx truecourse dashboard # Opens the web UI in your browser
46
+ npx truecourse list # Show the violations it found
50
47
  ```
51
48
 
52
- No setup step. TrueCourse creates `.truecourse/` in your repo on first analyze and stores everything there as plain JSON files no database, no daemon.
53
-
54
- TrueCourse uses the [Claude Code CLI](https://docs.anthropic.com/en/docs/claude-code) for LLM-powered rules. If `claude` isn't on your PATH, deterministic rules still run and LLM rules are skipped.
49
+ The first analyze creates `.truecourse/` and stores results as plain JSON. View them visually with [`truecourse dashboard`](#dashboard-web-ui).
55
50
 
56
51
  ## Setup
57
52
 
@@ -79,10 +74,44 @@ git commit -m "add truecourse baseline"
79
74
 
80
75
  `LATEST.json` is tracked, so `git worktree add ../feat-x` and fresh clones inherit the baseline through git. `truecourse analyze --diff` and the pre-commit hook both work on the first commit in a new worktree — no per-checkout cold-start. Inside a worktree, run `truecourse analyze --diff` to see what your in-flight changes introduce relative to `main`'s committed baseline; the diff result lands in `.truecourse/diff.json` (gitignored, per-checkout).
81
76
 
82
- ## CLI Commands
77
+ ## What it catches
78
+
79
+ **Architecture** — Circular dependencies, layer violations, god modules, dead modules, tight coupling, cross-service imports
80
+
81
+ **Code quality** — Magic numbers, empty catch, console.log, cognitive complexity, unused variables, redundant code, missing type hints
82
+
83
+ **Security** — SQL injection, hardcoded secrets, eval usage, insecure random, XSS, path traversal, unsafe deserialization
84
+
85
+ **Bugs** — Race conditions, type mismatches, mutable defaults, implicit optional, off-by-one, unchecked returns
86
+
87
+ **Performance** — N+1 queries, O(n²) string concat, unnecessary allocations, missing pagination, sync I/O in async
88
+
89
+ **Reliability** — Unhandled promises, resource leaks, missing timeouts, swallowed exceptions, unsafe error handling
90
+
91
+ **Database** — Missing indexes, missing transactions, lazy loading in loops, raw SQL bypassing ORM, schema issues
92
+
93
+ **Style** — Import ordering, naming conventions, docstring completeness, formatting preferences
94
+
95
+ ### Rule coverage
96
+
97
+ TrueCourse ships with **1,200+ deterministic rules** and **100 LLM rules** across 8 categories:
98
+
99
+ | Category | Deterministic | LLM | Total |
100
+ |---|---:|---:|---:|
101
+ | Security | 150+ | 1 | 150+ |
102
+ | Bugs | 250+ | 4 | 250+ |
103
+ | Architecture | 30+ | 7 | 40+ |
104
+ | Code Quality | 500+ | 3 | 500+ |
105
+ | Performance | 50+ | 10 | 60+ |
106
+ | Reliability | 40+ | 10 | 50+ |
107
+ | Database | 30+ | 5 | 35+ |
108
+ | Style | 50+ | — | 50+ |
109
+
110
+ **Deterministic rules** run via tree-sitter AST visitors — fast, zero-cost, no API calls. **LLM rules** send source code to the configured LLM for semantic analysis — deeper but requires an LLM provider.
111
+
112
+ ## Commands
83
113
 
84
114
  ```bash
85
- # Analysis
86
115
  truecourse analyze # Analyze current repo (prompts before stashing dirty trees)
87
116
  truecourse analyze --stash # Pre-approve stashing pending changes (CI-friendly)
88
117
  truecourse analyze --no-stash # Analyze working tree as-is, no stash
@@ -91,14 +120,6 @@ truecourse list # Show violations from latest analysis
91
120
  truecourse list --all # Show all violations (no pagination)
92
121
  truecourse list --diff # Show diff check results
93
122
  truecourse add # Register repo without analyzing
94
-
95
- # Dashboard (web UI)
96
- truecourse dashboard # Start + open the dashboard
97
- truecourse dashboard --reconfigure # Re-prompt for console vs background service mode
98
- truecourse dashboard stop # Stop the dashboard
99
- truecourse dashboard status # Show dashboard status
100
- truecourse dashboard logs # Tail dashboard logs (service mode only)
101
- truecourse dashboard uninstall # Remove the background service
102
123
  ```
103
124
 
104
125
  ### Rules
@@ -124,15 +145,9 @@ truecourse rules enable <ruleKey> # Re-enable a single rule
124
145
  truecourse rules reset [ruleKey] # Clear per-rule overrides (one or all)
125
146
  ```
126
147
 
127
- Disabled rules are skipped at analyze time (no detection cost, no LLM
128
- calls) and any existing violations from them are hidden from the
129
- dashboard and `truecourse list` until re-enabled. The list of disabled
130
- rule keys lives in `<repo>/.truecourse/config.json` under
131
- `disabledRules`, which is intended to be committed.
148
+ Disabled rules are skipped at analyze time (no detection cost, no LLM calls) and any existing violations from them are hidden from the dashboard and `truecourse list` until re-enabled. The list of disabled rule keys lives in `<repo>/.truecourse/config.json` under `disabledRules`, which is intended to be committed.
132
149
 
133
- In the dashboard you can also toggle rules from the Rules panel
134
- (Shield icon in the top-right) or silence a noisy rule directly from
135
- any violation card via the **⋮** menu → **Disable rule for this repo**.
150
+ In the dashboard you can also toggle rules from the Rules panel (Shield icon in the top-right) or silence a noisy rule directly from any violation card via the **⋮** menu → **Disable rule for this repo**.
136
151
 
137
152
  ### Git Hooks
138
153
 
@@ -158,34 +173,121 @@ pre-commit:
158
173
  llm: false # run LLM rules on every commit (tokens per commit)
159
174
  ```
160
175
 
161
- ### Telemetry
176
+ ---
177
+
178
+ # 2. Spec → Verify — business-logic drift
179
+
180
+ TrueCourse builds a machine-readable spec from your docs and verifies the code against it — catching where the implementation has drifted from documented intent. This is a separate pipeline from `analyze`: it answers a different question, has different prerequisites (it reads your docs), and runs on a different time scale.
181
+
182
+ > **Prerequisite:** the contract extractor and conflict resolver shell out to the Claude Code CLI (`claude -p`). Install Claude Code and sign in once before running `spec scan` or `contracts generate`.
183
+
184
+ ## Quick Start
185
+
186
+ ```bash
187
+ cd <your-repo>
188
+ truecourse spec scan # Read docs → extract claims → surface conflicts
189
+ truecourse spec resolve --all-defaults # Accept the recommended pick on each conflict
190
+ truecourse contracts generate # Canonical spec → .tc contract artifacts
191
+ truecourse verify # Check code against the contracts → drifts
192
+ ```
193
+
194
+ Resolve conflicts and review drifts visually in the [dashboard](#dashboard-web-ui)'s BL Drift section, or drive every step from the CLI.
195
+
196
+ ## How it works
197
+
198
+ Three stages run in order, each producing artifacts the next consumes:
162
199
 
163
- TrueCourse collects anonymous usage data to improve the product. It is automatically disabled in CI environments.
200
+ **1. Spec consolidation** Walks every `.md` file in the repo (PRDs, ADRs, RFCs, READMEs, design notes; `.truecourse/`, `node_modules/`, `.git/` etc. are skipped). An LLM relevance filter drops obvious non-spec material (task lists, research logs, AI agent prompts). For the docs that remain, an LLM extracts structured claims per block and groups them by `(topic, subject)`. Agreements auto-merge; genuine disagreements surface as **conflicts** in the dashboard with a plain-English explanation of what differs. Output: `.truecourse/specs/claims.json` (the structured snapshot every downstream stage consumes — modules + per-claim content + provenance) and `.truecourse/specs/decisions.json` (the user's resolutions, version chains, and overrides — committable).
201
+
202
+ Auto-resolve rules cut the conflict count substantially: byte-identical content, status-tolerant duplicates, same-file consolidation, docKind-dominance pickups, and detected version chains. [Plan](docs/contracts/PLAN_CONFLICT_RESOLUTION.md).
203
+
204
+ **2. Contract extraction** — Reads `claims.json` and emits `.truecourse/contracts/*.tc` files in a hand-written DSL covering 13 artifact kinds: `operation`, `entity`, `enum`, `state-machine`, `auth-requirement`, `authorization-rule`, `error-envelope`, `pagination-contract`, `idempotency-contract`, `effect-group`, `formula`, plus `unenforceable-obligation` for prose the verifier can't structurally check. A post-extraction **repair pass** validates structural completeness and re-prompts the LLM to fix deficient artifacts (missing forbids clauses, broad role selectors, unresolved cross-references). On the bundled fixture this hits **22/22 planted bugs with 0 false positives**.
205
+
206
+ **3. Verification** — Parses the contracts, walks the source tree, and runs per-kind comparators (operations, entities, state machines, etc.). Drifts surface in the dashboard alongside code violations, and on the CLI through `truecourse verify`. It's its own command — not a stage of `truecourse analyze`.
207
+
208
+ **4. Inference** — The mirror image of verification. `verify` asks "the spec says X — does the code do X?"; `truecourse infer` asks "the code does X — does any spec mention X?". It runs the code-side extractors *un-driven by a spec*, subtracts whatever the authored contracts already cover, and writes the remainder to `.truecourse/contracts/_inferred/` as `.tc` artifacts tagged with an `inferred-from "<code-path>" a..b` provenance line and a `confidence` level (instead of the authored `origin SOURCE "section" a..b`). It covers the full artifact spread — undocumented endpoints, entities (from ORM schema), enums, named constants, query policies, emitted events, computed formulas, architecture choices, and the cross-cutting conventions (auth, pagination, idempotency, error envelope). Confidence reflects fidelity: a value read straight from code is `high`; a synthesized convention (e.g. an assumed auth scheme) is a `low`-confidence draft to confirm. Because coverage is computed from authored contracts only, a decision drops out of `_inferred/` the moment it's documented — the directory is a shrinking backlog of "decisions your code made that your docs never recorded". Inferred contracts are descriptive, not prescriptive, so `verify` skips `_inferred/` by default.
209
+
210
+ ## What it catches
211
+
212
+ Operations whose responses, status codes, or headers don't match the spec. Entities with missing or mistyped fields. Immutability and lifecycle violations on state machines. Missing or forbidden side-effect emissions. Auth requirements bypassed. Pagination, idempotency, and error-envelope contracts violated. Formulas producing wrong results from drifted inputs.
213
+
214
+ ## Setup
215
+
216
+ The spec and a verify baseline are committable so they travel with the repo; everything else is local-only. Per-repo layout under `.truecourse/`:
217
+
218
+ ```
219
+ .truecourse/
220
+ ├── specs/ ← canonical spec (committable)
221
+ │ ├── claims.json ← structured snapshot: modules + claims + provenance
222
+ │ └── decisions.json ← user resolutions + version chains + manual includes
223
+ ├── contracts/ ← generated TC contract artifacts (gitignored by default)
224
+ │ └── _inferred/ ← reverse-engineered, undocumented decisions (`truecourse infer`)
225
+ ├── verifier/ ← drift store (mirrors analyze; `truecourse verify`)
226
+ │ ├── runs/ ← per-run drift snapshots (gitignored)
227
+ │ ├── LATEST.json ← current drift state + diff baseline (committable)
228
+ │ ├── history.json ← per-run summaries (gitignored)
229
+ │ └── diff.json ← current-vs-baseline drift diff (gitignored)
230
+ └── .cache/ ← LLM + slice cache (gitignored)
231
+ ```
232
+
233
+ Like analyze, `verifier/LATEST.json` is the committable baseline — commit it after merging to `main` (re-run `truecourse verify`, commit the result), not from feature branches. `truecourse verify --diff` then shows the drifts your uncommitted changes add or resolve against it.
234
+
235
+ ## Commands
164
236
 
165
237
  ```bash
166
- truecourse telemetry status # Check telemetry status
167
- truecourse telemetry disable # Opt out of anonymous telemetry
168
- truecourse telemetry enable # Opt back in
238
+ # Spec consolidation (docs canonical spec)
239
+ truecourse spec scan # Read docs, extract claims, surface conflicts, write claims.json
240
+ truecourse spec resolve --all-defaults # Accept the engine's recommended pick on every open conflict
241
+ truecourse spec status # Summary: docs, claims, modules, pending decisions
242
+
243
+ # Conflict resolution (also available in the dashboard Spec tab)
244
+ truecourse spec conflicts list # List open conflicts (add --decided / --all)
245
+ truecourse spec conflicts show <id> # Full detail for one conflict
246
+ truecourse spec conflicts pick <id> <index> # Resolve by picking a candidate
247
+ truecourse spec conflicts custom <id> --text "…" # Resolve with a custom answer
248
+ truecourse spec conflicts revoke <id> # Re-open a decided conflict
249
+ truecourse spec chains add --older A --newer B # Manually mark a version chain (escape hatch)
250
+ truecourse spec chains list / remove …
251
+ truecourse spec docs skipped # Docs the LLM relevance filter excluded
252
+ truecourse spec docs include <path> # Force-include a skipped doc
253
+ truecourse spec docs uninclude <path>
254
+
255
+ # Contract extraction (canonical spec → .tc artifacts)
256
+ truecourse contracts generate # Extract / re-extract TC contract files
257
+ truecourse contracts list # List generated contracts
258
+ truecourse contracts validate # Parse + resolve TC files; report unresolved refs
259
+
260
+ # Verification (code against contracts)
261
+ truecourse verify # Full run: stashes dirty tree (prompts), writes verifier/runs + LATEST + history
262
+ truecourse verify --diff # Git diff: working-tree drifts vs committed baseline (added/resolved/unchanged)
263
+ truecourse verify --stash / --no-stash # Pre-approve / skip stashing on a full run
264
+
265
+ # Inference (code → inferred contracts) — reverse-engineer undocumented decisions
266
+ truecourse infer # Write inferred .tc files to contracts/_inferred/
267
+ truecourse infer --dry-run # Report what would be written, touch nothing
169
268
  ```
170
269
 
171
- ## Analysis Rules
270
+ ---
172
271
 
173
- TrueCourse ships with **1,200+ deterministic rules** and **100 LLM rules** across 8 categories:
272
+ # Dashboard (web UI)
174
273
 
175
- | Category | Deterministic | LLM | Total |
176
- |---|---:|---:|---:|
177
- | Security | 150+ | 1 | 150+ |
178
- | Bugs | 250+ | 4 | 250+ |
179
- | Architecture | 30+ | 7 | 40+ |
180
- | Code Quality | 500+ | 3 | 500+ |
181
- | Performance | 50+ | 10 | 60+ |
182
- | Reliability | 40+ | 10 | 50+ |
183
- | Database | 30+ | 5 | 35+ |
184
- | Style | 50+ | — | 50+ |
274
+ One web UI for both capabilities browse code findings and business-logic drift side by side, with the architecture graph, analytics, and the spec/contracts/verify workflow.
275
+
276
+ ```bash
277
+ truecourse dashboard # Start + open the dashboard
278
+ truecourse dashboard --reconfigure # Re-prompt for console vs background service mode
279
+ truecourse dashboard stop # Stop the dashboard
280
+ truecourse dashboard status # Show dashboard status
281
+ truecourse dashboard logs # Tail dashboard logs (service mode only)
282
+ truecourse dashboard uninstall # Remove the background service
283
+ ```
284
+
285
+ - **Code Analysis** — architecture graph, violations list, severity/category analytics, code hotspots, trend over time; toggle rules and silence noisy ones inline.
286
+ - **BL Drift** — the Spec tab walks you through resolving each conflict (pick / write custom / mark superseded / include skipped doc); Contracts shows the generated `.tc` artifacts; Verify shows the drift analytics + list, with a Runs history and a Normal / Git-Diff toggle.
185
287
 
186
- **Deterministic rules** run via tree-sitter AST visitors — fast, zero-cost, no API calls.
288
+ ---
187
289
 
188
- **LLM rules** send source code to the configured LLM for semantic analysis — deeper but requires an LLM provider.
290
+ # Common
189
291
 
190
292
  ## Claude Code Skills
191
293
 
@@ -214,7 +316,7 @@ The first `truecourse analyze` (or `truecourse add`) in a fresh repo asks whethe
214
316
  ## Prerequisites
215
317
 
216
318
  - Node.js >= 20
217
- - [Claude Code](https://docs.anthropic.com/en/docs/claude-code) CLI on your PATH. Deterministic rules run without it, LLM-powered rules need it.
319
+ - [Claude Code](https://docs.anthropic.com/en/docs/claude-code) CLI on your PATH. Deterministic rules run without it; LLM-powered rules and the Spec → Verify pipeline need it.
218
320
 
219
321
  ## Configuration
220
322
 
@@ -230,7 +332,7 @@ CLAUDE_CODE_MAX_RETRIES=2 # retry attempts on parse/validation failu
230
332
  CLAUDE_CODE_MAX_CONCURRENCY=10 # max concurrent `claude` processes per run
231
333
  ```
232
334
 
233
- **`CLAUDE_CODE_MAX_CONCURRENCY`** caps how many Claude CLI processes TrueCourse spawns in parallel during a single analyze. Default `10`. Raise it on CI runners with spare headroom; lower it on resource-constrained machines (e.g. 8 GB laptops, shared VMs) to avoid OOM on large repos. Must be a positive integer.
335
+ **`CLAUDE_CODE_MAX_CONCURRENCY`** caps how many Claude CLI processes TrueCourse spawns in parallel during a single run. Default `10`. Raise it on CI runners with spare headroom; lower it on resource-constrained machines (e.g. 8 GB laptops, shared VMs) to avoid OOM on large repos. Must be a positive integer.
234
336
 
235
337
  For a one-off override, prefix the command:
236
338
 
@@ -255,6 +357,18 @@ scripts/ingest-epub.js
255
357
 
256
358
  Patterns are anchored to the file's location, so `src/generated/` matches the top-level directory only; use `**/generated/` to match at any depth.
257
359
 
360
+ ## Telemetry
361
+
362
+ TrueCourse collects anonymous usage data (event type, language, file count range, OS) to improve the product. No source code, file paths, or violation details are collected. It is automatically disabled in CI environments.
363
+
364
+ ```bash
365
+ truecourse telemetry status # Check telemetry status
366
+ truecourse telemetry disable # Opt out of anonymous telemetry
367
+ truecourse telemetry enable # Opt back in
368
+ ```
369
+
370
+ Or set `TRUECOURSE_TELEMETRY=0` to opt out.
371
+
258
372
  ## Development
259
373
 
260
374
  ```bash
@@ -268,13 +382,9 @@ pnpm build # Build all packages
268
382
 
269
383
  `pnpm dev` expects a `.truecourse/` folder at the repo root — created automatically on the first `truecourse analyze` against the repo (or simply `mkdir -p .truecourse`).
270
384
 
271
- ## Telemetry
272
-
273
- TrueCourse collects anonymous usage data (event type, language, file count range, OS). No source code, file paths, or violation details are collected. Opt out with `truecourse telemetry disable` or `TRUECOURSE_TELEMETRY=0`.
274
-
275
385
  ## Community
276
386
 
277
- Join the [TrueCourse Discord](https://discord.gg/8AYwf26A) to ask questions, share feedback, and follow what's shipping.
387
+ Join the [TrueCourse Discord](https://discord.gg/TanxB63arz) to ask questions, share feedback, and follow what's shipping.
278
388
 
279
389
  ## Contact
280
390