@dinyangetoh/codeplug-cli 0.1.4 → 0.1.5

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 (40) hide show
  1. package/README.md +130 -409
  2. package/dist/cli/commands/docs.d.ts +1 -3
  3. package/dist/cli/commands/docs.d.ts.map +1 -1
  4. package/dist/cli/commands/docs.js +1 -5
  5. package/dist/cli/commands/docs.js.map +1 -1
  6. package/dist/cli/index.js +1 -2
  7. package/dist/cli/index.js.map +1 -1
  8. package/dist/core/generator/DocGenerator.d.ts.map +1 -1
  9. package/dist/core/generator/DocGenerator.js +3 -31
  10. package/dist/core/generator/DocGenerator.js.map +1 -1
  11. package/dist/core/generator/documents/ArchitectureGenerator.d.ts.map +1 -1
  12. package/dist/core/generator/documents/ArchitectureGenerator.js +16 -23
  13. package/dist/core/generator/documents/ArchitectureGenerator.js.map +1 -1
  14. package/dist/core/generator/documents/ContributingGenerator.d.ts.map +1 -1
  15. package/dist/core/generator/documents/ContributingGenerator.js +15 -21
  16. package/dist/core/generator/documents/ContributingGenerator.js.map +1 -1
  17. package/dist/core/generator/documents/ConventionsGenerator.js +17 -17
  18. package/dist/core/generator/documents/ConventionsGenerator.js.map +1 -1
  19. package/dist/core/generator/documents/OnboardingGenerator.d.ts.map +1 -1
  20. package/dist/core/generator/documents/OnboardingGenerator.js +19 -29
  21. package/dist/core/generator/documents/OnboardingGenerator.js.map +1 -1
  22. package/dist/core/generator/documents/ReadmeGenerator.d.ts +4 -3
  23. package/dist/core/generator/documents/ReadmeGenerator.d.ts.map +1 -1
  24. package/dist/core/generator/documents/ReadmeGenerator.js +147 -150
  25. package/dist/core/generator/documents/ReadmeGenerator.js.map +1 -1
  26. package/dist/core/generator/documents/promptHelpers.d.ts +1 -1
  27. package/dist/core/generator/documents/promptHelpers.d.ts.map +1 -1
  28. package/dist/core/generator/documents/promptHelpers.js +1 -1
  29. package/dist/core/generator/documents/promptHelpers.js.map +1 -1
  30. package/dist/core/generator/documents/types.d.ts +2 -6
  31. package/dist/core/generator/documents/types.d.ts.map +1 -1
  32. package/dist/core/generator/facts/FactExtractor.d.ts +5 -0
  33. package/dist/core/generator/facts/FactExtractor.d.ts.map +1 -0
  34. package/dist/core/generator/facts/FactExtractor.js +90 -0
  35. package/dist/core/generator/facts/FactExtractor.js.map +1 -0
  36. package/dist/core/generator/facts/types.d.ts +18 -0
  37. package/dist/core/generator/facts/types.d.ts.map +1 -0
  38. package/dist/core/generator/facts/types.js +2 -0
  39. package/dist/core/generator/facts/types.js.map +1 -0
  40. package/package.json +1 -1
package/README.md CHANGED
@@ -1,63 +1,50 @@
1
1
  # CodePlug
2
2
 
3
- ## Executive Summary
4
-
5
- This document provides comprehensive technical documentation for CodePlug, a local-first CLI tool designed to detect, enforce, and document coding conventions across TypeScript/JavaScript codebases. The guide covers installation, configuration, usage commands, project architecture, and development workflows for teams seeking automated codebase governance with AI agent integration capabilities.
6
-
7
- ---
3
+ > The source of truth for codebase understanding & governance.
8
4
 
9
5
  ## Overview
10
6
 
11
- **The source of truth for codebase understanding and governance.**
12
-
13
- CodePlug is a local-first CLI tool that detects your codebase's coding conventions, enforces them with drift detection and compliance scoring, generates living documentation, and exports convention context for AI coding agents.
14
-
15
- The tool operates entirely on-device using ML models for pattern detection, ensuring your codebase data never leaves your machine unless you explicitly configure cloud LLM providers for enhanced documentation generation.
7
+ This document is the primary technical reference for **CodePlug** (`@dinyangetoh/codeplug-cli`), a professional-grade, local-first CLI tool designed to detect, enforce, and document coding conventions across TypeScript and JavaScript codebases. It covers installation, configuration, usage, and the underlying architecture to help developers integrate CodePlug into their workflows. CodePlug combines AST analysis with on-device ML inference to provide automated convention governance, living documentation generation, and structured AI agent context export — ensuring both human developers and AI assistants adhere to the same project standards.
16
8
 
17
9
  ---
18
10
 
19
- ## Key Features
20
-
21
- ### Convention Detection
22
-
23
- AST analysis with on-device ML identifies naming patterns, folder structure, component styles, test organization, error handling, and import conventions across your TypeScript/JavaScript codebase.
11
+ ## Key Descriptions
24
12
 
25
- ### Drift & Compliance
13
+ CodePlug acts as the **source of truth for codebase understanding**. It uses AST visitors and on-device ML models (via `@huggingface/transformers`, with no Python dependency) to identify patterns across naming, structure, components, and error handling. It generates "living documentation" and structured rule files for AI agents (Claude, Cursor, Copilot), and provides a compliance scoring engine to prevent architectural drift over time.
26
14
 
27
- Classifies git diffs against stored conventions, scores compliance with severity-weighted metrics, tracks trends over time, and auto-fixes what it can.
28
-
29
- ### Living Documentation
15
+ ---
30
16
 
31
- Generates and maintains README, ARCHITECTURE, CONVENTIONS, CONTRIBUTING, and ONBOARDING docs using ML summarization and optional LLM enhancement.
17
+ ## Key Features
32
18
 
33
- ### AI Agent Export
19
+ ### Convention Detection & Governance
20
+ - **Multi-Dimensional AST Analysis:** Six to seven specialized visitors identify naming patterns, component styles, test organization, error handling, and import conventions.
21
+ - **Drift & Compliance Scoring:** Classifies git diffs against stored conventions, scores compliance with severity-weighted metrics, and tracks trends via an internal `sql.js` time-series database.
22
+ - **Auto-Fix:** Supports automated renaming and provides guided remediation for complex violations.
34
23
 
35
- Exports your conventions as `CLAUDE.md`, `.cursor/rules`, `.github/copilot-instructions.md`, structured JSON, and SARIF-format CI reports.
24
+ ### Documentation & AI Integration
25
+ - **Living Documentation:** Automatically maintains `ARCHITECTURE.md`, `CONVENTIONS.md`, and `ONBOARDING.md` using ML summarization pipelines (BART, BERT).
26
+ - **AI Agent Export:** Generates context files including `CLAUDE.md`, `.cursor/rules`, and `.github/copilot-instructions.md`.
27
+ - **CI/CD Ready:** Exports SARIF-format reports for integration with GitHub Actions and other CI pipelines.
36
28
 
37
- ### All Features
29
+ ### Feature Matrix
38
30
 
39
- | Category | Feature | Command / Config | Notes |
40
- |----------|---------|------------------|-------|
41
- | CLI | Interactive wizard | `codeplug start` | Config, Convention, Docs, Export menus; see [COMMAND.md](COMMAND.md) |
42
- | Convention | Detection (6 dimensions) | `convention init` | Naming, Component, Test, ErrorHandling, Import, Schema visitors |
43
- | Convention | Structure (7th dimension) | `convention audit` | StructureVisitor in ViolationDetector |
44
- | Convention | Drift | `convention drift` | Rule-based diff classification |
45
- | Convention | Compliance | `convention audit`, `score` | Severity-weighted, sql.js time-series |
46
- | Convention | Auto-fix | `convention fix` | Rename + manual guidance |
47
- | Convention | Semantic coherence | `convention.enableSemanticCoherence` | Opt-in; zero-shot + sentenceSimilarity |
48
- | Convention | Custom rules | `.codeplug/rules.json` | Regex rules (filename, path, content) |
49
- | Docs | Generate / Status / Update | `docs generate/status/update` | 5 docs, ML pipeline + optional LLM; template fallback |
50
- | Export | Claude / Cursor / Copilot | `export --target` | CLAUDE.md, .cursor/rules, .github/copilot-instructions |
51
- | Export | JSON / CI (SARIF) | `export --target json/ci` | .codeplug/exports/, .codeplug/ci-report.json |
52
- | Config | Model tier, LLM provider | `config set` | default / lite; 8 providers |
31
+ | Category | Feature | Command | Notes |
32
+ |---|---|---|---|
33
+ | **CLI** | Interactive Wizard | `codeplug start` | Single entry point for all menus |
34
+ | **Audit** | Compliance Score | `codeplug convention score` | Severity-weighted, time-series tracking |
35
+ | **Docs** | ML Generation | `codeplug docs generate` | 5 core docs; optional LLM enhancement |
36
+ | **Export** | AI Context | `codeplug export --all` | Supports Claude, Cursor, Copilot, JSON |
37
+ | **Config** | Model Tiers | `codeplug config set` | Choose between `default` or `lite` models |
53
38
 
54
39
  ---
55
40
 
56
41
  ## Prerequisites
57
42
 
58
- - **Node.js 20+** (required) CodePlug is built with TypeScript and requires Node.js 20 or higher for native fetch and modern ESM support.
59
- - **Git** (required for drift detection and history analysis) — CodePlug integrates with Git for diff analysis, commit history inspection, and pre-commit hook management.
60
- - **Ollama** (optional) For LLM-enhanced documentation. Any OpenAI-compatible provider works as an alternative.
43
+ | Requirement | Version | Notes |
44
+ |---|---|---|
45
+ | **Node.js** | `>=20.0.0` | Required for native fetch and modern ESM support |
46
+ | **Git** | Any modern version | Required for drift detection and history analysis |
47
+ | **Ollama** | Optional | For local LLM-enhanced documentation; any OpenAI-compatible provider is also supported |
61
48
 
62
49
  ---
63
50
 
@@ -72,7 +59,7 @@ npm install -g @dinyangetoh/codeplug-cli
72
59
  ### Local Development
73
60
 
74
61
  ```bash
75
- git clone <repo-url>
62
+ git clone <repository-url>
76
63
  cd codeplug
77
64
  npm install
78
65
  npm run build
@@ -84,24 +71,15 @@ node dist/cli/index.js --help
84
71
  ## Quick Start
85
72
 
86
73
  ```bash
87
- # Install globally
88
- npm install -g @dinyangetoh/codeplug-cli
89
-
90
- # Navigate to your project
74
+ # Initialize and detect conventions in your project
91
75
  cd your-project
92
-
93
- # Interactive wizard — single entry point for new users
94
- codeplug start
95
- ```
96
-
97
- Or run commands directly:
98
-
99
- ```bash
100
- # Detect and confirm conventions
101
76
  codeplug convention init
102
77
 
103
- # Check compliance
78
+ # Run a compliance audit
104
79
  codeplug convention audit
80
+
81
+ # Launch the interactive wizard
82
+ codeplug start
105
83
  ```
106
84
 
107
85
  ---
@@ -110,419 +88,162 @@ codeplug convention audit
110
88
 
111
89
  ### Interactive Wizard
112
90
 
113
- ```bash
114
- codeplug start
115
- ```
116
-
117
- Launches an interactive menu with four core areas:
118
-
119
- | Menu | Options |
120
- | -------- | ----------------------------------------------------------------------- |
121
- | Config | View full config, Set provider/model/API key/tier, Back |
122
- | Convention | Initialize, Run audit, Check drift, Show score, Auto-fix, Back |
123
- | Docs | Generate docs, Check status, Update stale, Back |
124
- | Export | Export all targets, Check freshness, Back |
125
-
126
- Use arrow keys to navigate and Enter to select. Each sub-menu has a Back option to return.
127
-
128
- ### Convention Detection
129
-
130
- ```bash
131
- # Detect and interactively confirm conventions
132
- codeplug convention init
91
+ The `codeplug start` command provides a guided interface organized into four areas:
133
92
 
134
- # Re-run detection, overwrite existing conventions
135
- codeplug convention init --force
136
- ```
93
+ | Area | Description |
94
+ |---|---|
95
+ | **Config** | Manage LLM providers, API keys, and model tiers |
96
+ | **Convention** | Initialize detection, run audits, and apply auto-fixes |
97
+ | **Docs** | Generate and update stale documentation |
98
+ | **Export** | Refresh AI agent rule files |
137
99
 
138
- ### Compliance Audit
100
+ ### Common Commands
139
101
 
140
102
  ```bash
141
- # Full compliance report
142
- codeplug convention audit
143
-
144
- # Audit only changes from the last 7 days
103
+ # Audit changes from the last 7 days
145
104
  codeplug convention audit --since 7d
146
105
 
147
- # CI mode -- exits non-zero if score drops below threshold
106
+ # CI mode exits non-zero if score is below threshold
148
107
  codeplug convention audit --ci
149
- ```
150
-
151
- ### Drift Detection
152
-
153
- ```bash
154
- # Check recent commits for convention drift
155
- codeplug convention drift
156
- ```
157
-
158
- ### Compliance Score
159
-
160
- ```bash
161
- # Show current score
162
- codeplug convention score
163
-
164
- # Show score history and trend chart
165
- codeplug convention score --trend
166
- ```
167
-
168
- ### Auto-Fix
169
108
 
170
- ```bash
171
- # Apply all safe auto-fixes
172
- codeplug convention fix --auto
173
-
174
- # Fix a specific finding by ID
175
- codeplug convention fix --id naming-pascal-components
176
- ```
177
-
178
- ### Documentation Generation
179
-
180
- ```bash
181
- # Generate all 5 documents
182
- codeplug docs generate
183
-
184
- # Generate a specific document
185
- codeplug docs generate --doc ARCHITECTURE
186
-
187
- # Tune for audience and style
109
+ # Generate docs for a junior audience in concise style
188
110
  codeplug docs generate --audience junior --style concise
189
111
 
190
- # Check which docs are stale
191
- codeplug docs status
192
-
193
- # Regenerate only stale sections
194
- codeplug docs update
195
- ```
196
-
197
- ### Export for AI Agents
198
-
199
- ```bash
200
- # Export for a specific target
201
- codeplug export --target claude
112
+ # Export rules for Cursor
202
113
  codeplug export --target cursor
203
- codeplug export --target copilot
204
114
 
205
- # Export all targets at once
115
+ # Export all AI agent context files
206
116
  codeplug export --all
207
-
208
- # Check if exports are up to date
209
- codeplug export --check
210
- ```
211
-
212
- ### Configuration
213
-
214
- ```bash
215
- # View all settings
216
- codeplug config list
217
-
218
- # Get a specific value
219
- codeplug config get llm.provider
220
-
221
- # Set values
222
- codeplug config set llm.provider openai
223
- codeplug config set llm.model gpt-4o
224
- codeplug config set llm.apiKey sk-...
225
117
  ```
226
118
 
227
- ### Planned / Partial Features
228
-
229
- - **`convention show <commit>`**: Listed in help; returns "Not yet implemented. Coming in Phase 2."
230
- - **Pre-commit hook**: PreCommitHook class exists; `codeplug hook install/uninstall` commands are not yet exposed (programmatic API; coming soon).
231
- - **Export `--target ci`**: Produces SARIF 2.1.0 at `.codeplug/ci-report.json` for CI integration.
232
-
233
119
  ---
234
120
 
235
121
  ## Configuration
236
122
 
237
- CodePlug stores project-level configuration in `.codeplug/config.json`. The `config` command manages this file.
238
-
239
- ### LLM Provider
123
+ CodePlug stores project-level settings in `.codeplug/config.json`.
240
124
 
241
- The default provider is Ollama (local). Setting a provider auto-fills its base URL and default model:
125
+ ### LLM Providers
242
126
 
243
- ```bash
244
- codeplug config set llm.provider ollama # local, no API key needed
245
- codeplug config set llm.provider openai # sets baseUrl + model automatically
246
- codeplug config set llm.provider anthropic
247
- ```
127
+ Convention detection runs entirely on-device. Documentation prose generation can optionally be enhanced via a local or cloud LLM provider:
248
128
 
249
- You can also set individual fields for custom endpoints:
129
+ - **Local:** Ollama (default)
130
+ - **Cloud:** OpenAI, Anthropic, Gemini, OpenRouter, Groq, DeepSeek, Grok
250
131
 
251
132
  ```bash
252
- codeplug config set llm.baseUrl https://my-proxy.example.com/v1
253
- codeplug config set llm.model my-custom-model
254
- codeplug config set llm.apiKey my-key
133
+ codeplug config set llm.provider openai
134
+ codeplug config set llm.apiKey sk-...
255
135
  ```
256
136
 
257
- ### Model Tier
258
-
259
- ```bash
260
- # Full-size models (default) -- best quality, ~1.1GB disk, 8GB+ RAM recommended
261
- codeplug config set models.tier default
137
+ ### Model Tiers
262
138
 
263
- # Lightweight models -- reduced quality, ~420MB disk, 4GB RAM minimum
264
- codeplug config set models.tier lite
265
- ```
139
+ | Tier | RAM | Disk | Use Case |
140
+ |---|---|---|---|
141
+ | **Default** | 8 GB+ | ~1.2 GB | Production quality, CI pipelines |
142
+ | **Lite** | 4 GB+ | ~450 MB | Constrained local hardware |
266
143
 
267
- Switching to `lite` prints a warning about potential quality degradation.
268
-
269
- ### Configurable Sections
270
-
271
- CodePlug supports optional sections in `.codeplug/config.json`. Each section merges with built-in defaults (shallow merge). Omit a section to keep defaults.
272
-
273
- ```mermaid
274
- flowchart TB
275
- subgraph sources [Config Sources]
276
- Defaults[DEFAULT_CONFIG]
277
- User[config.json]
278
- end
279
- Defaults --> Merge[ConfigManager.load]
280
- User --> Merge
281
- Merge --> Config[CodePlugConfig]
282
- Config --> Structure[structure]
283
- Config --> Analysis[analysis]
284
- Config --> Scoring[scoring]
285
- Config --> Convention[convention]
286
- Config --> Drift[drift]
287
- Config --> Docs[docs]
288
- Config --> Naming[naming]
144
+ ```bash
145
+ codeplug config set model.tier lite
289
146
  ```
290
147
 
291
- | Section | Purpose |
292
- |---------|---------|
293
- | `structure` | Architecture patterns (feature-based, MVC, layered) and directory placement rules (e.g. *Helper in helpers/) |
294
- | `analysis` | Glob `include` and `ignore` for file discovery |
295
- | `scoring` | Severity weights, compliance threshold, trend window |
296
- | `convention` | Confidence threshold and dimension → severity map |
297
- | `drift` | Confidence threshold and naming pattern regexes |
298
- | `docs` | Tracked doc names, export targets, dev scripts |
299
- | `naming` | Stem stopwords for file-responsibility extraction |
300
-
301
148
  ### Custom Rules
302
149
 
303
- Add regex-based rules via `.codeplug/rules.json`. Schema: `id`, `pattern`, `scope` (filename | path | content), `message`, `severity` (optional).
150
+ Define regex-based rules in `.codeplug/rules.json` to extend or override detected conventions:
304
151
 
305
152
  ```json
306
- [{ "id": "no-index-export", "pattern": "export \\* from", "scope": "content", "message": "Prefer named exports", "severity": "low" }]
153
+ [{
154
+ "id": "no-index-export",
155
+ "pattern": "export \\* from",
156
+ "scope": "content",
157
+ "message": "Prefer named exports",
158
+ "severity": "low"
159
+ }]
307
160
  ```
308
161
 
309
- ### Data Files
310
-
311
- | File | Purpose |
312
- |------|---------|
313
- | `.codeplug/config.json` | Project config (LLM, models, analysis, etc.) |
314
- | `.codeplug/conventions.json` | Stored conventions from `convention init` |
315
- | `.codeplug/rules.json` | Custom regex rules for audit |
316
- | `.codeplug/scores.json` | Compliance score history (sql.js) |
317
- | `.codeplug/violations.json` | Recent violation records |
318
-
319
162
  ---
320
163
 
321
- ## Supported LLM Providers
322
-
323
- All providers work through a single unified client via the OpenAI SDK.
324
-
325
- | Provider | Setup |
326
- |----------|-------|
327
- | Ollama | `codeplug config set llm.provider ollama` (default, no API key) |
328
- | OpenAI | `codeplug config set llm.provider openai` then set `llm.apiKey` |
329
- | Anthropic | `codeplug config set llm.provider anthropic` then set `llm.apiKey` |
330
- | Gemini | `codeplug config set llm.provider gemini` then set `llm.apiKey` |
331
- | OpenRouter | `codeplug config set llm.provider openrouter` then set `llm.apiKey` |
332
- | Groq | `codeplug config set llm.provider groq` then set `llm.apiKey` |
333
- | DeepSeek | `codeplug config set llm.provider deepseek` then set `llm.apiKey` |
334
- | Grok | `codeplug config set llm.provider grok` then set `llm.apiKey` |
335
-
336
- ---
337
-
338
- ## Model Tiers
339
-
340
- | | Default | Lite |
341
- |---|---------|------|
342
- | Target machine | 8GB+ RAM | 4GB+ RAM |
343
- | Disk usage | ~1.2GB | ~450MB |
344
- | Classification | CodeBERT-base (125M params) | CodeBERTa-small (84M params) |
345
- | Summarization | BART-large-CNN (406M params) | DistilBART (230M params) |
346
- | NER | BERT-base-NER (110M params) | DistilBERT-NER (66M params) |
347
- | Zero-shot | DistilBERT-MNLI (68MB) | DistilBERT-MNLI (68MB) |
348
- | Sentence similarity | all-MiniLM-L6-v2 (23MB) | all-MiniLM-L6-v2 (23MB) |
349
- | When to use | Production quality, CI pipelines | Local development on constrained hardware |
350
-
351
- **Model usage (all 6 roles used):**
352
-
353
- | Role | Default | Lite | Used By |
354
- |------|---------|------|---------|
355
- | classifier | CodeBERT-base | CodeBERTa-small | ConventionMlResolver (convention init) |
356
- | zeroShot | DistilBERT-MNLI | same | SemanticCoherenceService (opt-in) |
357
- | sentenceSimilarity | all-MiniLM-L6-v2 | same | SemanticCoherenceService (fallback) |
358
- | summarizer | BART-large-CNN | DistilBART | DocGenerator (docs generate) |
359
- | extractor | DistilBERT-SQuAD | same | DocGenerator |
360
- | ner | BERT-base-NER | DistilBERT-NER | DocGenerator |
361
-
362
- Convention detection: AST visitors + CodeBERT (ConventionMlResolver) + zero-shot/sentenceSimilarity when semantic coherence enabled. Doc generation: summarizer, extractor, ner via PipelineOrchestrator (default); falls back to template-only on model load failure.
164
+ ## Project Structure & Architecture
363
165
 
364
- Models are downloaded on first use and cached in `~/.codeplug/models/`.
166
+ ### Folder Structure
365
167
 
366
- ### Tradeoffs
367
-
368
- - **Default vs Lite**: Quality vs resource usage (8GB vs 4GB RAM; ~1.2GB vs ~450MB disk).
369
- - **Semantic coherence**: Enable for stricter "export fits context" checks; adds ~68MB model load and inference time per audit.
370
- - **LLM for docs**: Optional; template-only fallback when LLM unavailable.
371
- - **Performance targets**: CLI startup <1s; init ~500 files <15s; drift <3s; audit <30s; docs (all 5) <2min.
372
-
373
- ### Hugging Face Transformers
374
-
375
- Convention detection, drift, and compliance use **on-device ML only** via `@huggingface/transformers`. No API keys or network calls for convention features.
376
-
377
- **Why Transformers / Local-First ML**
378
-
379
- ```mermaid
380
- flowchart LR
381
- subgraph design [Design Rationale]
382
- A[Privacy: no data leaves machine]
383
- B[Zero cost for convention features]
384
- C[Python-free Node.js inference]
385
- D[Deterministic logic first ML fallback]
386
- end
387
- ```
388
-
389
- - **Privacy**: Convention detection, drift, compliance run entirely on-device — no API keys, no network calls.
390
- - **Cost**: Zero runtime cost; models cached in `~/.codeplug/models/`.
391
- - **Portability**: `@huggingface/transformers` runs in Node.js — no Python, no separate ML server.
392
- - **Explainability**: Rule-based detection first; ML used for ambiguous cases (e.g., semantic coherence) to keep outputs explainable.
393
-
394
- **Feature → Model usage:**
395
-
396
- ```mermaid
397
- flowchart TB
398
- subgraph convention [Convention Features]
399
- Init[convention init]
400
- Audit[convention audit]
401
- end
402
- subgraph conventionML [Convention ML]
403
- CodeBERT[classifier: CodeBERT]
404
- ZeroShot[zeroShot: DistilBERT-MNLI]
405
- SentSim[sentenceSimilarity: all-MiniLM]
406
- end
407
- subgraph docsML [Docs ML]
408
- BART[summarizer]
409
- Extractor[extractor]
410
- NER[ner]
411
- end
412
- Init --> CodeBERT
413
- Init --> ZeroShot
414
- Init --> SentSim
415
- Audit --> conventionML
416
- DocsGenerate[docs generate] --> BART
417
- DocsGenerate --> Extractor
418
- DocsGenerate --> NER
419
- ```
420
-
421
- **Pipelines by feature:**
422
-
423
- | Feature | Pipeline | Use |
424
- |---------|----------|-----|
425
- | Convention discovery | Feature extraction (CodeBERT embedding via ConventionMlResolver) | Pattern similarity during init |
426
- | Convention (opt-in) | Zero-shot, sentence similarity (all-MiniLM) | Semantic coherence: "export fits file context" |
427
- | Doc generation | Summarization (BART), Q&A (DistilBERT-SQuAD), NER (BERT-NER) | Living documentation; template fallback on load failure |
428
-
429
- **LLM scope:** The LLM is **optional** and used only for prose generation in docs. Convention detection, drift, and compliance do not use an LLM.
430
-
431
- **Cost:** Zero runtime cost for convention features; models are cached locally.
432
-
433
- ---
434
-
435
- ## Project Structure
436
-
437
- ```
438
- src/
168
+ ```text
169
+ src/ # 66 source files
439
170
  ├── cli/
440
- │ └── commands/ # Command handlers (convention, docs, export, config)
441
- ├── config/ # ConfigManager, Zod schemas, types, provider presets
171
+ │ └── commands/ # Command handlers (convention, docs, export)
172
+ ├── config/ # Zod schemas and provider presets
442
173
  ├── core/
443
- │ ├── analyzer/ # AST analysis: 6 visitors (init), 7 for audit (adds StructureVisitor), PatternAggregator
444
- │ ├── classifier/ # Drift classification + confidence gating
445
- │ ├── scorer/ # Compliance scoring, violation detection, auto-fix, trends
446
- │ ├── generator/ # Doc generation, ML pipelines, LLM client, staleness tracking
447
- │ ├── exporter/ # Export engine + 5 formatters (Claude, Cursor, Copilot, JSON, CI)
448
- │ └── git/ # Git integration + pre-commit hook management
449
- ├── models/ # ML model manager + tier-aware registry
450
- ├── storage/ # ConventionStore, ScoreStore (sql.js), ViolationStore, CustomRuleStore
451
- ├── templates/ # Export templates (Claude, Cursor, Copilot)
452
- └── tests/ # Unit tests, integration tests, fixture repos
453
- ```
454
-
455
- ### Directory Details
456
-
457
- | Directory | Purpose |
458
- |-----------|---------|
459
- | `cli/commands/` | Command handlers for the CLI interface |
460
- | `config/` | Configuration management with Zod validation |
461
- | `core/analyzer/` | AST-based code analysis with pattern aggregation |
462
- | `core/classifier/` | Drift detection and severity classification |
463
- | `core/scorer/` | Compliance scoring engine with trend analysis |
464
- | `core/generator/` | Doc generation; PipelineOrchestrator (summarizer, extractor, ner) + LLM; template fallback on failure |
465
- | `core/exporter/` | Multi-format export for AI coding agents |
466
- | `core/git/` | Git integration, diff analysis, PreCommitHook (CLI not yet exposed) |
467
- | `models/` | ML model lifecycle management |
468
- | `storage/` | ConventionStore, ScoreStore (sql.js), ViolationStore, CustomRuleStore (rules.json) |
174
+ │ ├── analyzer/ # AST analysis 67 specialized visitors
175
+ │ ├── classifier/ # Drift classification & confidence gating
176
+ │ ├── scorer/ # Compliance engine & violation detection
177
+ │ ├── generator/ # ML pipelines (BART, BERT) & LLM client
178
+ │ ├── exporter/ # Formatters (Claude, Cursor, SARIF)
179
+ │ └── git/ # Diff analysis & hook management
180
+ ├── models/ # Tier-aware ML model registry
181
+ ├── storage/ # sql.js (scores) and JSON stores
182
+ └── templates/ # Export templates for AI agents
183
+
184
+ tests/ # 18 test files
185
+ ├── unit/
186
+ │ ├── analyzer/
187
+ │ ├── config/
188
+ │ ├── exporter/
189
+ │ ├── generator/
190
+ │ ├── models/
191
+ │ └── scorer/
192
+ └── fixtures/
193
+ └── sample-react-app/
194
+ ```
195
+
196
+ ### Technical Stack
197
+
198
+ | Layer | Technology |
199
+ |---|---|
200
+ | **ML Inference** | `@huggingface/transformers` — Python-free, Node.js native |
201
+ | **Summarization** | BART (documentation prose) |
202
+ | **Embeddings** | BERT (pattern classification) |
203
+ | **Database** | `sql.js` (compliance time-series) |
204
+ | **Schema Validation** | Zod |
205
+ | **Test Runner** | Vitest |
469
206
 
470
207
  ---
471
208
 
472
209
  ## Conventions
473
210
 
474
- CodePlug follows these conventions throughout the codebase:
211
+ These are the conventions CodePlug enforces and itself follows internally.
475
212
 
476
- ### Naming Conventions
213
+ ### Naming
477
214
 
478
- - **Utility files** Use camelCase (e.g., `formatDate.ts`, `parseConfig.ts`)
479
- - **Class/service files** — Use PascalCase (e.g., `ConfigManager.ts`, `ConventionStore.ts`)
480
- - **React components** Use PascalCase file names (e.g., `Button.tsx`, `UserProfile.tsx`)
481
- - **Hooks** Use "use" prefix with camelCase (e.g., `useAuth.ts`, `useTheme.ts`)
215
+ | Target | Convention | Example |
216
+ |---|---|---|
217
+ | Class / service files | `PascalCase` | `ConfigManager.ts` |
218
+ | Utility files | `camelCase` | `formatDate.ts` |
219
+ | Class names | `PascalCase` | `class ConventionScorer` |
220
+ | Interface names | `PascalCase` | `interface RuleConfig` |
221
+ | Type aliases | `PascalCase` | `type SeverityLevel` |
222
+ | Factory functions | `camelCase` | `createAnalyzer()` |
482
223
 
483
- ### Testing Conventions
224
+ > **Note:** Kebab-case filenames are not used anywhere in this project.
484
225
 
485
- - **Separate tests/** directory — Integration and e2e tests live outside `src/`
486
- - **Test file naming** — Use `.test.ts` or `.spec.ts` suffix
487
- - **Co-located tests** — Use `__tests__/` directories for unit tests near source files
226
+ ### API & Async Patterns
488
227
 
489
- ### Project Structure Conventions
228
+ - All I/O operations use `async/await`; callbacks and raw Promise chains are avoided.
490
229
 
491
- - **Source root** — All source code resides in `src/`
492
- - **Entry points** — CLI entry at `src/cli/index.ts`
493
- - **Core modules** Domain logic in `src/core/` subdirectories by responsibility
230
+ ### Testing
231
+
232
+ - Integration tests live in the root `tests/` directory.
233
+ - Unit tests are co-located in `__tests__/` subdirectories alongside source files.
234
+ - Test files follow the `.test.{ext}` naming convention.
494
235
 
495
236
  ---
496
237
 
497
238
  ## Development
498
239
 
499
240
  ```bash
500
- # Install dependencies
501
- npm install
502
-
503
- # Build
504
- npm run build
505
-
506
- # Type check without emitting
507
- npm run typecheck
508
-
509
- # Run tests
510
- npm test
511
-
512
- # Run tests in watch mode
513
- npm run test:watch
514
-
515
- # Run with coverage
516
- npm run coverage
517
-
518
- # Lint
519
- npm run lint
520
-
521
- # Lint with auto-fix
522
- npm run lint:fix
523
-
524
- # Watch build during development
525
- npm run dev
241
+ npm run build # Compile TypeScript
242
+ npm run dev # Watch mode for active development
243
+ npm run test # Run the full Vitest suite
244
+ npm run coverage # Generate test coverage report
245
+ npm run lint # Check code style
246
+ npm run typecheck # Verify TypeScript types
526
247
  ```
527
248
 
528
249
  ---
@@ -1,7 +1,5 @@
1
1
  import type { DocsGenerateOptions } from '../../config/types.js';
2
- export declare function handleDocsGenerate(options: DocsGenerateOptions & {
3
- ml?: boolean;
4
- }): Promise<void>;
2
+ export declare function handleDocsGenerate(options: DocsGenerateOptions): Promise<void>;
5
3
  export declare function handleDocsStatus(): Promise<void>;
6
4
  export declare function handleDocsUpdate(): Promise<void>;
7
5
  //# sourceMappingURL=docs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/docs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEjE,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG;IAAE,EAAE,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAwBvG;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CA0BtD;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CActD"}
1
+ {"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/docs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEjE,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAoBpF;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CA0BtD;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CActD"}