truecourse 0.5.11 → 0.6.0-next.0

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,9 +14,15 @@
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
18
  </p>
18
19
 
19
- 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:
21
+
22
+ - **Code defects** — from the same 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** — 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 the contract from your PRDs/ADRs/READMEs and checks the code against it.
24
+
25
+ Two commands, two concerns. `truecourse analyze` produces code findings. `truecourse verify` produces drift findings, once you've materialised the canonical spec and extracted contracts. Both kinds of output are structured — queryable as JSON for agent workflows, rendered in a dashboard for human review.
20
26
 
21
27
  <p align="center">
22
28
  <img src="assets/demo.gif" alt="TrueCourse Screenshot" width="100%" />
@@ -40,6 +46,8 @@ TrueCourse analyzes your codebase architecture and code to detect violations tha
40
46
 
41
47
  **Style** — Import ordering, naming conventions, docstring completeness, formatting preferences
42
48
 
49
+ **Spec / BL drift** — 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.
50
+
43
51
  ## Quick Start
44
52
 
45
53
  ```bash
@@ -98,6 +106,37 @@ truecourse dashboard stop # Stop the dashboard
98
106
  truecourse dashboard status # Show dashboard status
99
107
  truecourse dashboard logs # Tail dashboard logs (service mode only)
100
108
  truecourse dashboard uninstall # Remove the background service
109
+
110
+ # Spec consolidation (docs → canonical spec)
111
+ truecourse spec scan # Read docs, extract claims, surface conflicts, write claims.json
112
+ truecourse spec resolve --all-defaults # Accept the engine's recommended pick on every open conflict
113
+ truecourse spec status # Summary: docs, claims, modules, pending decisions
114
+
115
+ # Agent-friendly conflict surface (all support --json)
116
+ truecourse spec conflicts list # List open conflicts (add --decided / --all)
117
+ truecourse spec conflicts show <id> # Full detail for one conflict
118
+ truecourse spec conflicts pick <id> <index> # Resolve by picking a candidate
119
+ truecourse spec conflicts custom <id> --text "…" # Resolve with a custom answer
120
+ truecourse spec conflicts revoke <id> # Re-open a decided conflict
121
+ truecourse spec chains add --older A --newer B # Manually mark a version chain (escape hatch)
122
+ truecourse spec chains list / remove …
123
+ truecourse spec docs skipped # Docs the LLM relevance filter excluded
124
+ truecourse spec docs include <path> # Force-include a skipped doc
125
+ truecourse spec docs uninclude <path>
126
+
127
+ # Contract extraction (canonical spec → .tc artifacts)
128
+ truecourse contracts generate # Extract / re-extract TC contract files
129
+ truecourse contracts list # List generated contracts
130
+ truecourse contracts validate # Parse + resolve TC files; report unresolved refs
131
+
132
+ # Verification (code against contracts) — separate command, not part of `analyze`
133
+ truecourse verify # Full run: stashes dirty tree (prompts), writes verifier/runs + LATEST + history
134
+ truecourse verify --diff # Git diff: working-tree drifts vs committed baseline (added/resolved/unchanged)
135
+ truecourse verify --stash / --no-stash # Pre-approve / skip stashing on a full run
136
+
137
+ # Inference (code → inferred contracts) — reverse-engineer undocumented decisions
138
+ truecourse infer # Write inferred .tc files to contracts/_inferred/
139
+ truecourse infer --dry-run # Report what would be written, touch nothing
101
140
  ```
102
141
 
103
142
  ### Rules
@@ -133,6 +172,75 @@ In the dashboard you can also toggle rules from the Rules panel
133
172
  (Shield icon in the top-right) or silence a noisy rule directly from
134
173
  any violation card via the **⋮** menu → **Disable rule for this repo**.
135
174
 
175
+ ### Spec → Contracts → Verify (BL drift detection)
176
+
177
+ In addition to the rule-based static analysis, TrueCourse builds a
178
+ machine-readable spec from your docs and verifies the code against it.
179
+ Three stages run in order, each producing artifacts the next stage
180
+ consumes:
181
+
182
+ **1. Spec consolidation** — Walks every `.md` file in the repo (PRDs,
183
+ ADRs, RFCs, READMEs, design notes; `.truecourse/`, `node_modules/`,
184
+ `.git/` etc. are skipped). An LLM relevance filter drops obvious
185
+ non-spec material (task lists, research logs, AI agent prompts). For
186
+ the docs that remain, an LLM extracts structured claims per block and
187
+ groups them by `(topic, subject)`. Agreements auto-merge; genuine
188
+ disagreements surface as **conflicts** in the dashboard with a plain-
189
+ English explanation of what differs. Output:
190
+ `.truecourse/specs/claims.json` (the structured snapshot every
191
+ downstream stage consumes — modules + per-claim content + provenance)
192
+ and `.truecourse/specs/decisions.json` (the user's resolutions, version
193
+ chains, and overrides — committable).
194
+
195
+ Auto-resolve rules cut the conflict count substantially: byte-
196
+ identical content, status-tolerant duplicates, same-file consolidation,
197
+ docKind-dominance pickups, and detected version chains.
198
+ [Plan](docs/contracts/PLAN_CONFLICT_RESOLUTION.md).
199
+
200
+ **2. Contract extraction** — Reads `claims.json` and emits
201
+ `.truecourse/contracts/*.tc` files in a hand-written DSL
202
+ covering 13 artifact kinds: `operation`, `entity`, `enum`,
203
+ `state-machine`, `auth-requirement`, `authorization-rule`,
204
+ `error-envelope`, `pagination-contract`, `idempotency-contract`,
205
+ `effect-group`, `formula`, plus `unenforceable-obligation` for prose
206
+ the verifier can't structurally check. A post-extraction **repair
207
+ pass** validates structural completeness and re-prompts the LLM to fix
208
+ deficient artifacts (missing forbids clauses, broad role selectors,
209
+ unresolved cross-references). On the bundled fixture this hits
210
+ **22/22 planted bugs with 0 false positives**.
211
+
212
+ **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 from the CLI as JSON. Verification is its own command — `truecourse verify` — not a stage of `truecourse analyze`, because the two pipelines answer different questions, have different prerequisites, and run on different time scales.
213
+
214
+ **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 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, or a state machine whose transitions can't be reconstructed) 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.
215
+
216
+ **Storage layout** (per repo, 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
+ ├── analyses/ ← analysis snapshots (gitignored)
226
+ ├── LATEST.json ← analyze current-state view (committable)
227
+ ├── verifier/ ← drift store (mirrors analyze; `truecourse verify`)
228
+ │ ├── runs/ ← per-run drift snapshots (gitignored)
229
+ │ ├── LATEST.json ← current drift state + diff baseline (committable)
230
+ │ ├── history.json ← per-run summaries (gitignored)
231
+ │ └── diff.json ← current-vs-baseline drift diff (gitignored)
232
+ └── .cache/ ← LLM + slice cache (gitignored)
233
+ ```
234
+
235
+ The dashboard's Spec tab walks you through resolving each conflict
236
+ (pick / write custom / mark superseded / include skipped doc). The
237
+ same actions are also available via the CLI subcommands shown above
238
+ (every command supports `--json` for agent-driven workflows).
239
+
240
+ **Prerequisite:** the contract extractor and the conflict resolver
241
+ shell out to the Claude Code CLI (`claude -p`). Install Claude Code
242
+ and sign in once before running `spec scan` or `contracts generate`.
243
+
136
244
  ### Git Hooks
137
245
 
138
246
  TrueCourse can install a pre-commit hook that blocks commits introducing new violations at or above a configured severity:
@@ -271,6 +379,10 @@ pnpm build # Build all packages
271
379
 
272
380
  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`.
273
381
 
382
+ ## Community
383
+
384
+ Join the [TrueCourse Discord](https://discord.gg/8AYwf26A) to ask questions, share feedback, and follow what's shipping.
385
+
274
386
  ## Contact
275
387
 
276
388
  Questions, feedback, or security reports: **Mushegh Gevorgyan** — [mushegh@truecourse.dev](mailto:mushegh@truecourse.dev).