logicstamp-context 0.8.2 → 0.8.4

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 (51) hide show
  1. package/LICENSE +21 -21
  2. package/LLM_CONTEXT.md +703 -703
  3. package/README.md +404 -459
  4. package/dist/cli/commands/clean.d.ts.map +1 -1
  5. package/dist/cli/commands/clean.js +1 -6
  6. package/dist/cli/commands/clean.js.map +1 -1
  7. package/dist/cli/commands/context/fileWriter.js +2 -2
  8. package/dist/cli/commands/context/fileWriter.js.map +1 -1
  9. package/dist/cli/commands/context/statsCalculator.d.ts +3 -2
  10. package/dist/cli/commands/context/statsCalculator.d.ts.map +1 -1
  11. package/dist/cli/commands/context/statsCalculator.js +45 -104
  12. package/dist/cli/commands/context/statsCalculator.js.map +1 -1
  13. package/dist/cli/commands/context/watchMode/watchMode.d.ts.map +1 -1
  14. package/dist/cli/commands/context/watchMode/watchMode.js +124 -39
  15. package/dist/cli/commands/context/watchMode/watchMode.js.map +1 -1
  16. package/dist/cli/commands/init.js +20 -20
  17. package/dist/cli/commands/security.js +3 -3
  18. package/dist/cli/commands/security.js.map +1 -1
  19. package/dist/cli/commands/validate.d.ts.map +1 -1
  20. package/dist/cli/commands/validate.js +1 -6
  21. package/dist/cli/commands/validate.js.map +1 -1
  22. package/dist/cli/handlers/initHandler.js +5 -5
  23. package/dist/cli/index.d.ts +6 -2
  24. package/dist/cli/index.d.ts.map +1 -1
  25. package/dist/cli/index.js +100 -96
  26. package/dist/cli/index.js.map +1 -1
  27. package/dist/cli/parser/helpText.js +570 -570
  28. package/dist/cli/validate-index.js +26 -26
  29. package/dist/core/astParser/detectors.d.ts.map +1 -1
  30. package/dist/core/astParser/detectors.js +3 -2
  31. package/dist/core/astParser/detectors.js.map +1 -1
  32. package/dist/core/pack/loader.js +3 -3
  33. package/dist/core/pack/loader.js.map +1 -1
  34. package/dist/utils/codeSanitizer.d.ts.map +1 -1
  35. package/dist/utils/codeSanitizer.js +3 -2
  36. package/dist/utils/codeSanitizer.js.map +1 -1
  37. package/dist/utils/fsx.d.ts +5 -0
  38. package/dist/utils/fsx.d.ts.map +1 -1
  39. package/dist/utils/fsx.js +9 -2
  40. package/dist/utils/fsx.js.map +1 -1
  41. package/dist/utils/git.d.ts.map +1 -1
  42. package/dist/utils/git.js +2 -1
  43. package/dist/utils/git.js.map +1 -1
  44. package/dist/utils/gitignore.d.ts.map +1 -1
  45. package/dist/utils/gitignore.js +2 -1
  46. package/dist/utils/gitignore.js.map +1 -1
  47. package/dist/utils/secretDetector.d.ts.map +1 -1
  48. package/dist/utils/secretDetector.js +17 -10
  49. package/dist/utils/secretDetector.js.map +1 -1
  50. package/package.json +85 -84
  51. package/schema/logicstamp.context.schema.json +1250 -1250
package/README.md CHANGED
@@ -1,459 +1,404 @@
1
- <div align="center">
2
- <a href="https://logicstamp.dev">
3
- <picture>
4
- <source media="(prefers-color-scheme: dark)" srcset="assets/logicstamp-woodmark-dark.png">
5
- <source media="(prefers-color-scheme: light)" srcset="assets/logicstamp-woodmark-light.png">
6
- <img src="assets/logicstamp-woodmark-light.png" alt="LogicStamp" width="400" height="auto">
7
- </picture>
8
- </a>
9
-
10
- ## The Context Compiler for TypeScript.
11
-
12
- <em>Supports: React · Next.js · Vue (TS/TSX) · Express · NestJS</em>
13
-
14
- <br/>
15
- </div>
16
-
17
- LogicStamp Context is a CLI that compiles TypeScript codebases into deterministic, diffable architectural contracts and dependency graphs - a compact, structured source of truth for AI coding workflows.
18
-
19
- Includes watch mode, strict, auditable diffs, and real-time breaking change detection.
20
- Use with [logicstamp-mcp](https://github.com/LogicStamp/logicstamp-mcp) to feed structured context into **Claude**, **Cursor**, and other MCP-compatible assistants.
21
-
22
- <div align="center">
23
-
24
- <br/>
25
- <a href="https://github.com/LogicStamp">
26
- <img src="./assets/logicstamp-fox.svg" alt="LogicStamp Fox Mascot" width="100" style="min-width: 80px;">
27
- </a>
28
-
29
- [![Version](https://img.shields.io/npm/v/logicstamp-context?color=8b5cf6&label=version)](https://www.npmjs.com/package/logicstamp-context)
30
- ![Beta](https://img.shields.io/badge/status-beta-orange.svg)
31
- [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
32
- ![Node](https://img.shields.io/badge/node-%3E%3D20-brightgreen.svg)
33
- [![CI](https://github.com/LogicStamp/logicstamp-context/workflows/CI/badge.svg)](https://github.com/LogicStamp/logicstamp-context/actions)
34
-
35
- </div>
36
- <br/>
37
-
38
- <details>
39
- <summary><strong>📑 Table of Contents</strong></summary>
40
-
41
- - [The Problem](#the-problem)
42
- - [Quick Start](#quick-start)
43
- - [Why Structured Context?](#why-structured-context)
44
- - [Features](#-features)
45
- - [Watch Mode](#watch-mode)
46
- - [How it Works](#how-it-works)
47
- - [MCP Server](#mcp-server)
48
- - [Example Output](#example-output)
49
- - [Installation](#installation)
50
- - [Security](#security)
51
- - [Usage](#usage)
52
- - [Framework Support](#framework-support)
53
- - [Documentation](#documentation)
54
- - [Known Limitations](#known-limitations)
55
- - [Requirements](#requirements)
56
- - [Need Help?](#need-help)
57
- - [License](#license)
58
- </details>
59
-
60
- ## The Problem
61
-
62
- AI coding assistants read your source code - but they don’t understand its structure.
63
- They hallucinate props, miss dependencies, and can’t detect when a breaking change impacts consumers.
64
-
65
- Example: your `Button` accepts `variant` and `disabled`, but the AI suggests `isLoading` because it saw that pattern elsewhere. Without a structured contract, there is no reliable source of truth.
66
-
67
- **LogicStamp Context** compiles TypeScript into deterministic architectural contracts and dependency graphs - a machine-readable representation of your system that AI tools can consume instead of parsing raw implementation code.
68
-
69
- These contracts:
70
-
71
- - Stay in sync with your code (watch mode auto-regenerates)
72
- - Expose interfaces (props, hooks, APIs) without implementation noise
73
- - Are deterministic, diffable, and auditable
74
- - Enable early detection of architectural drift and breaking changes
75
-
76
- ![LogicStamp MCP Workflow](./assets/logicstamp-workflow.gif)
77
- *Example workflow: `stamp context --strict-watch` generates context bundles that MCP-powered assistants use to explain component architecture (ThemeContext shown here).*
78
-
79
- **Same code ⇒ same context output.** Contracts are diffable, so you can detect drift and breaking changes.
80
-
81
- ```
82
- TypeScript Code → Compilation → Deterministic Contracts → AI Assistant
83
- (.ts/.tsx) (ts-morph) (context.json bundles) (Claude, Cursor)
84
- ```
85
-
86
- ---
87
-
88
- ## Quick Start
89
-
90
- **Try it in 30 seconds (no install required):**
91
- ```bash
92
- npx logicstamp-context context
93
- ```
94
-
95
- Scans your repo and writes `context.json` files + `context_main.json` for AI tools.
96
-
97
- **What you get:**
98
- - 📁 `context.json` files - one per folder with components, preserving your directory structure
99
- - 📋 `context_main.json` - index file with project overview and folder metadata
100
-
101
- **For a complete setup (recommended):**
102
- ```bash
103
- npm install -g logicstamp-context
104
- stamp init # sets up .gitignore, scans for secrets
105
- stamp context
106
- ```
107
-
108
- > **ℹ️ Note:** With `npx`, run `npx logicstamp-context context`. After global install, use `stamp context`.
109
-
110
- 📋 **For detailed setup instructions, see the [Getting Started Guide](https://logicstamp.dev/docs/getting-started).**
111
-
112
- ## Why Structured Context?
113
-
114
- | Without LogicStamp Context | With LogicStamp Context |
115
- |-------------------|-----------------|
116
- | AI parses 200 lines of implementation to infer a component's interface | AI reads a 20-line interface contract |
117
- | Props/hooks inferred (often wrong) | Props/hooks explicit and verified |
118
- | No way to know if context is stale | Watch mode catches changes in real-time |
119
- | Different prompts = different understanding | Deterministic: same code = same contract |
120
- | Manual context gathering: "Here's my Button component..." | Structured contracts: AI understands architecture automatically |
121
-
122
- **The key insight:** AI assistants don't need your implementation - they need your *interfaces*. LogicStamp Context extracts what matters and discards the noise.
123
-
124
- ### What "Structured" Means
125
-
126
- Instead of shipping raw source code to AI:
127
-
128
- ```typescript
129
- // Raw: AI must parse and infer
130
- export const Button = ({ variant = 'primary', disabled, onClick, children }) => {
131
- const [isHovered, setIsHovered] = useState(false);
132
- // ... 150 more lines of implementation
133
- }
134
- ```
135
-
136
- LogicStamp Context generates:
137
-
138
- ```json
139
- {
140
- "kind": "react:component",
141
- "interface": {
142
- "props": {
143
- "variant": { "type": "literal-union", "literals": ["primary", "secondary"] },
144
- "disabled": { "type": "boolean" },
145
- "onClick": { "type": "function", "signature": "() => void" }
146
- }
147
- },
148
- "composition": { "hooks": ["useState"], "components": ["./Icon"] }
149
- }
150
- ```
151
-
152
- Pre-parsed. Categorized. Stable. The AI reads contracts, not implementations.
153
-
154
- ## Features
155
-
156
- **Core:**
157
- - **Deterministic contracts** - Same input = same output, auditable in version control
158
- - **Watch mode** - Auto-regenerate on file changes with incremental rebuilds
159
- - **Breaking change detection** - Strict watch mode catches removed props, events, functions in real-time
160
- - **MCP-ready** - AI agents consume context via standardized MCP interface
161
-
162
- **Analysis:**
163
- - React/Next.js/Vue component extraction (props, hooks, state, deps)
164
- - Backend API extraction (Express.js, NestJS routes and controllers)
165
- - Dependency graphs (handles circular dependencies)
166
- - Style metadata extraction (Tailwind, SCSS, MUI, shadcn)
167
- - Next.js App Router detection (client/server, layouts, pages)
168
-
169
- **Developer experience:**
170
- - Per-folder bundles matching your project structure
171
- - Accurate token estimates (GPT/Claude)
172
- - Security-first: automatic secret detection and sanitization
173
- - Zero config required - sensible defaults, works out of the box
174
-
175
- ## Watch Mode
176
-
177
- <p align="center">
178
- <img src="./assets/logicstamp-strict-watch.gif" width="820" />
179
- </p>
180
-
181
- *Strict watch mode in action: detecting violations and clearing them when resolved.*
182
-
183
- For development, run watch mode to keep context fresh as you code:
184
-
185
- ```bash
186
- stamp context --watch # regenerate on changes
187
- stamp context --strict-watch # also detect breaking changes (implies --watch)
188
- ```
189
- Strict watch catches breaking changes that affect consumers:
190
-
191
- | Violation | Example |
192
- |-----------|---------|
193
- | `breaking_change_prop_removed` | Removed `disabled` prop from Button |
194
- | `breaking_change_event_removed` | Removed `onSubmit` callback |
195
- | `breaking_change_function_removed` | Deleted exported `formatDate()` |
196
- | `contract_removed` | Deleted entire component |
197
-
198
- **Errors vs Warnings:** Violations are classified by severity:
199
-
200
- **❌ Errors** indicate breaking changes that will affect consumers (removed props, events, functions, or entire contracts).
201
-
202
- **⚠️ Warnings** indicate less severe changes (type signature changes, removed internal state). Violations are tracked in real-time and automatically cleared when resolved.
203
-
204
- **Session Status Tracking:** Strict watch mode displays a session status block showing cumulative statistics:
205
- - **Errors/Warnings detected**: Total violations detected during the session
206
- - **Resolved**: Number of times all violations were completely resolved
207
- - **Active**: Current number of active violations
208
-
209
- The status block only appears when violations change (not on every file change), keeping terminal output clean.
210
-
211
- ![Strict Watch Mode Terminal Output](./assets/logicstamp-strict-watch-output.png)
212
-
213
- *Example terminal output showing violations and session status.*
214
-
215
- > ℹ️ **Note:** Strict Watch currently detects breaking changes at the source. Next step: a symbol-level import/export reverse index to trace which consumer files will break. See [docs/cli/watch.md](docs/cli/watch.md) for complete documentation.
216
-
217
- ### One-time Comparison
218
-
219
- Compare regenerated context against existing files:
220
-
221
- ```bash
222
- stamp context compare # detect changes
223
- stamp context compare --approve # update (like jest -u)
224
- ```
225
-
226
- Useful for reviewing changes before committing or validating context is up-to-date.
227
-
228
- **Git baseline comparison** *(v0.7.2)*: Compare against any git ref:
229
- ```bash
230
- stamp context compare --baseline git:main # Compare against main branch
231
- stamp context compare --baseline git:HEAD # Compare against HEAD
232
- stamp context compare --baseline git:v1.0.0 # Compare against a tag
233
- ```
234
-
235
- > **ℹ️ Note:** Context files are gitignored by default. Git baseline comparison uses git worktrees to generate context for both the baseline ref and the current working tree, then performs a structural contract comparison. See [docs/cli/compare.md](docs/cli/compare.md) for complete documentation.
236
-
237
- ## How it Works
238
-
239
- The compilation pipeline:
240
-
241
- 1. **Scan** - Discovers all `.ts` and `.tsx` source files
242
- 2. **Parse** - Builds AST (Abstract Syntax Tree) via `ts-morph` using the TypeScript compiler API
243
- 3. **Extract** - Compiles contracts with props, hooks, state, signatures
244
- 4. **Graph** - Resolves dependency relationships
245
- 5. **Emit** - Outputs `context.json` bundles per folder
246
- 6. **Index** - Generates `context_main.json` with metadata and statistics
247
-
248
- **Why AST-based compilation matters:** LogicStamp leverages the full TypeScript compiler (via ts-morph) for deterministic, type-aware contract extraction. Prop types, hooks, and composition patterns are resolved structurally - not inferred from text or retrieval.
249
-
250
- One command. No build step required.
251
-
252
- > **💡Tip:** Use `stamp context` for basic contracts. Use `stamp context style` when you need style metadata (Tailwind classes, SCSS selectors, layout patterns). Use `--style-mode lean` (default) for compact output or `--style-mode full` for detailed arrays.
253
-
254
- <details>
255
- <summary><strong>📋 What LogicStamp Context Is (and Isn't)</strong></summary>
256
-
257
- **LogicStamp Context IS:**
258
-
259
- ✅ **A context compiler** - Uses the TypeScript compiler API (via ts-morph) to compile source code into deterministic architectural contracts.
260
-
261
- ✅ **Deterministic** - Same input always produces the same output. Contracts are auditable and diffable.
262
-
263
- ✅ **Local execution** - Runs entirely on your machine (no cloud services, no network calls).
264
-
265
- ✅ **Framework-aware** - Understands React, Next.js, Vue, Express, and NestJS patterns and extracts relevant metadata.
266
-
267
- ✅ **Non-opinionated** - Describes what exists without enforcing patterns or architectural decisions.
268
-
269
- **LogicStamp Context IS NOT:**
270
-
271
- ❌ **A code generator** - It never writes or modifies your source code.
272
-
273
- ❌ **A documentation generator** - It produces structured contracts, not documentation.
274
-
275
- ❌ **A build or runtime tool** - It compiles contracts from static source code. it does not execute or bundle your application.
276
-
277
- ❌ **A linter, formatter, or testing framework** - It does not check code quality or run tests.
278
-
279
- ❌ **An AI behavior controller** - It provides structured context. it does not alter AI responses.
280
-
281
- ❌ **A replacement for reading code** - It accelerates understanding without replacing engineering judgment.
282
-
283
- </details>
284
-
285
- ## MCP Server
286
-
287
- For AI assistants with MCP support (Claude Desktop, Cursor, etc.):
288
-
289
- ```bash
290
- npm install -g logicstamp-mcp
291
- ```
292
-
293
- Then configure your AI assistant to use the LogicStamp MCP Server.
294
-
295
- 🔗 **See [LogicStamp MCP Server Repository](https://github.com/LogicStamp/logicstamp-mcp)**
296
-
297
- 📋 **See [MCP Getting Started Guide](https://logicstamp.dev/docs/mcp/getting-started)** for setup instructions.
298
-
299
- ## Example Output
300
-
301
- LogicStamp Context generates structured JSON bundles organized by folder:
302
-
303
- ```json
304
- {
305
- "type": "LogicStampBundle",
306
- "entryId": "src/components/Button.tsx",
307
- "graph": {
308
- "nodes": [
309
- {
310
- "entryId": "src/components/Button.tsx",
311
- "contract": {
312
- "kind": "react:component",
313
- "interface": {
314
- "props": {
315
- "variant": { "type": "literal-union", "literals": ["primary", "secondary"] },
316
- "onClick": { "type": "function", "signature": "() => void" }
317
- }
318
- },
319
- "composition": {
320
- "hooks": ["useState"],
321
- "components": ["./Icon"]
322
- }
323
- }
324
- }
325
- ],
326
- "edges": [["src/components/Button.tsx", "./Icon"]]
327
- }
328
- }
329
- ```
330
-
331
- 📋 **See [docs/reference/schema.md](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/reference/schema.md)** for complete format documentation.
332
-
333
- ## Installation
334
-
335
- ```bash
336
- npm install -g logicstamp-context
337
- ```
338
-
339
- After installation, the `stamp` command is available globally.
340
-
341
- ## Security
342
-
343
- **Automatic Secret Protection**
344
-
345
- LogicStamp Context protects sensitive data in generated context:
346
-
347
- - **Security scanning by default** - `stamp init` scans source files (`.ts`, `.tsx`, `.js`, `.jsx`) and `.json` files for hard-coded secrets before context compilation
348
- - **Automatic sanitization** - Detected secrets replaced with `"PRIVATE_DATA"` in output
349
- - **Manual exclusions** - Use `stamp ignore <file>` to exclude files via `.stampignore`
350
- - **Safe by default** - Only metadata included. Credentials only appear in `--include-code full` mode
351
-
352
- > **⚠️ Seeing `"PRIVATE_DATA"` in output?** Review `stamp_security_report.json`, remove hardcoded secrets from source, use environment variables instead.
353
-
354
- 🔒 **See [SECURITY.md](https://github.com/LogicStamp/logicstamp-context/blob/main/SECURITY.md)** for complete security documentation.
355
-
356
- ## Usage
357
-
358
- <details>
359
- <summary><strong>💻 CLI Usage Reference</strong></summary>
360
-
361
- ```bash
362
- stamp --version # Show version
363
- stamp --help # Show help
364
- stamp init [path] # Initialize project (security scan by default)
365
- stamp ignore <path> # Add to .stampignore
366
- stamp context [path] # Generate context bundles
367
- stamp context style [path] # Generate with style metadata (lean mode by default)
368
- stamp context style --style-mode full # Generate with full style details (verbose)
369
- stamp context --watch # Watch mode
370
- stamp context --strict-watch # Watch with breaking change detection (--watch optional)
371
- stamp context compare # Detect changes vs existing context
372
- stamp context validate [file] # Validate context files
373
- stamp context clean [path] # Remove generated files
374
- ```
375
-
376
- ### Common Options
377
-
378
- | Option | Description |
379
- |--------|-------------|
380
- | `--depth <n>` | Dependency traversal depth (default: 2) |
381
- | `--include-code <mode>` | Code inclusion: `none\|header\|full` (default: header) |
382
- | `--include-style` | Extract style metadata (Tailwind, SCSS, animations) |
383
- | `--format <fmt>` | Output format: `json\|pretty\|ndjson\|toon` (default: json) |
384
- | `--max-nodes <n>` | Maximum nodes per bundle (default: 100) |
385
- | `--profile <p>` | Preset: `llm-chat`, `llm-safe`, `ci-strict`, `watch-fast` |
386
- | `--compare-modes` | Show token cost comparison across all modes |
387
- | `--stats` | Emit JSON stats with token estimates |
388
- | `--out <path>` | Output directory |
389
- | `--quiet` | Suppress verbose output |
390
- | `--strict-missing` | Exit with error if any missing dependencies found (CI-friendly) |
391
- | `--debug` | Show detailed hash info (watch mode) |
392
- | `--log-file` | Write change logs to `.logicstamp/` (watch mode) |
393
-
394
- </details>
395
-
396
- 📋 **See [docs/cli/commands.md](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/cli/commands.md)** for complete reference.
397
-
398
- ## Framework Support
399
-
400
- | Framework | Support Level | What's Extracted |
401
- |-----------|--------------|------------------|
402
- | **React** | Full | Components, hooks, props, styles |
403
- | **Next.js** | Full | App Router roles, segment paths, metadata |
404
- | **Vue 3** | Partial | Composition API (TS/TSX only, not .vue SFC) |
405
- | **Express.js** | Full | Routes, API signatures (middleware not extracted. see [limitations](docs/reference/limitations.md)) |
406
- | **NestJS** | Full | Controllers, decorators, API signatures |
407
- | **UI Libraries** | Full | Material UI, ShadCN, Radix, Tailwind, Styled Components, SCSS, Chakra UI, Ant Design (component usage, props, composition. not raw CSS) |
408
-
409
- > **ℹ️ Note:** LogicStamp Context analyzes `.ts` and `.tsx` files only. JavaScript files are not analyzed.
410
-
411
- ## Documentation
412
-
413
- **Full documentation at [logicstamp.dev/docs](https://logicstamp.dev/docs)**
414
-
415
- - [Getting Started Guide](https://logicstamp.dev/docs/getting-started)
416
- - [Usage Guide](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/guides/usage.md)
417
- - [Monorepo Support](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/guides/monorepo.md)
418
- - [Output Schema](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/reference/schema.md)
419
- - [UIF Contracts](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/reference/uif-contracts.md)
420
- - [Watch Mode](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/cli/watch.md)
421
- - [Troubleshooting](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/guides/usage.md#troubleshooting)
422
-
423
- ## Known Limitations
424
-
425
- LogicStamp Context is in beta. Some edge cases are not fully supported.
426
-
427
- 📋 **See [docs/reference/limitations.md](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/reference/limitations.md)** for the full list.
428
-
429
- ## Requirements
430
-
431
- - Node.js >= 20
432
- - TypeScript codebase (React, Next.js, Vue (TS/TSX), Express, or NestJS)
433
-
434
- ## Need Help?
435
-
436
- - **Issues** - [github.com/LogicStamp/logicstamp-context/issues](https://github.com/LogicStamp/logicstamp-context/issues)
437
- - **Roadmap** - [logicstamp.dev/roadmap](https://logicstamp.dev/roadmap)
438
-
439
- ## License
440
-
441
- [MIT](LICENSE)
442
-
443
- ---
444
-
445
- <details>
446
- <summary>Branding & Attribution</summary>
447
-
448
- The LogicStamp Fox mascot and related brand assets are © 2025 Amit Levi. These assets may not be used for third-party branding without permission.
449
- </details>
450
-
451
- <details>
452
- <summary>Contributing</summary>
453
-
454
- Issues and PRs welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
455
-
456
- This project follows a [Code of Conduct](CODE_OF_CONDUCT.md).
457
- </details>
458
-
459
- **Links:** [Website](https://logicstamp.dev) · [GitHub](https://github.com/LogicStamp/logicstamp-context) · [MCP Server](https://github.com/LogicStamp/logicstamp-mcp) · [Changelog](https://github.com/LogicStamp/logicstamp-context/blob/main/CHANGELOG.md)
1
+ <div align="center">
2
+ <a href="https://logicstamp.dev">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="assets/logicstamp-wordmark-dark.png">
5
+ <source media="(prefers-color-scheme: light)" srcset="assets/logicstamp-wordmark-light.png">
6
+ <img src="assets/logicstamp-wordmark-light.png" alt="LogicStamp" width="400" height="auto">
7
+ </picture>
8
+ </a>
9
+
10
+ ## The Context Compiler for TypeScript.
11
+
12
+ <em>Supports: React · Next.js · Vue (TS/TSX) · Express · NestJS</em>
13
+
14
+ <br/>
15
+ </div>
16
+
17
+ LogicStamp Context is a CLI that compiles TypeScript codebases into deterministic, diffable architectural contracts and dependency graphs - a compact, structured source of truth for AI coding workflows.
18
+
19
+ Includes watch mode, strict, auditable diffs, and real-time breaking change detection.
20
+ Use with [logicstamp-mcp](https://github.com/LogicStamp/logicstamp-mcp) to feed structured context into **Claude**, **Cursor**, and other MCP-compatible assistants.
21
+
22
+ <div align="center">
23
+
24
+ <br/>
25
+ <a href="https://github.com/LogicStamp">
26
+ <img src="./assets/logicstamp-fox.svg" alt="LogicStamp Fox Mascot" width="100" style="min-width: 80px;">
27
+ </a>
28
+
29
+ [![Version](https://img.shields.io/npm/v/logicstamp-context?color=8b5cf6&label=version)](https://www.npmjs.com/package/logicstamp-context)
30
+ ![Beta](https://img.shields.io/badge/status-beta-orange.svg)
31
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
32
+ ![Node](https://img.shields.io/badge/node-%3E%3D20-brightgreen.svg)
33
+ [![CI](https://github.com/LogicStamp/logicstamp-context/workflows/CI/badge.svg)](https://github.com/LogicStamp/logicstamp-context/actions)
34
+
35
+ </div>
36
+ <br/>
37
+
38
+ <details>
39
+ <summary><strong>📑 Table of Contents</strong></summary>
40
+
41
+ - [The Problem](#the-problem)
42
+ - [Quick Start](#quick-start)
43
+ - [Why Structured Context?](#why-structured-context)
44
+ - [Features](#-features)
45
+ - [Watch Mode](#watch-mode)
46
+ - [How it Works](#how-it-works)
47
+ - [MCP Server](#mcp-server)
48
+ - [Security](#security)
49
+ - [Usage](#usage)
50
+ - [Framework Support](#framework-support)
51
+ - [Documentation](#documentation)
52
+ - [Known Limitations](#known-limitations)
53
+ - [Benchmarks](#benchmarks)
54
+ - [Requirements](#requirements)
55
+ - [Need Help?](#need-help)
56
+ - [License](#license)
57
+ </details>
58
+
59
+ ## The Problem
60
+
61
+ AI coding assistants read your source code - but they don’t understand its structure.
62
+ They hallucinate props, miss dependencies, and can’t detect when a breaking change impacts consumers.
63
+
64
+ Example: your `Button` accepts `variant` and `disabled`, but the AI suggests `isLoading` because it saw that pattern elsewhere. Without a structured contract, there is no reliable source of truth.
65
+
66
+ **LogicStamp Context** derives that layer from your TypeScript - explicit interfaces and dependency structure for tools to consume instead of inferring from implementation.
67
+
68
+ ![LogicStamp MCP Workflow](./assets/logicstamp-workflow.gif)
69
+ *Example workflow: `stamp context --strict-watch` generates context bundles that MCP-powered assistants use to explain component architecture (ThemeContext shown here).*
70
+
71
+ ```
72
+ TypeScript Code → Compilation → Deterministic Contracts → AI Assistant
73
+ (.ts/.tsx) (ts-morph) (context.json bundles) (Claude, Cursor)
74
+ ```
75
+
76
+ ---
77
+
78
+ ## Quick Start
79
+
80
+ No install required:
81
+
82
+ ```bash
83
+ npx logicstamp-context context
84
+ ```
85
+
86
+ Scans your repo and writes `context.json` files + `context_main.json` for AI tools.
87
+
88
+ **What you get:**
89
+ - 📁 `context.json` files - one per folder with components, preserving your directory structure
90
+ - 📋 `context_main.json` - index file with project overview and folder metadata
91
+
92
+ ### Installation
93
+
94
+ For ongoing use, install the CLI globally:
95
+
96
+ ```bash
97
+ npm install -g logicstamp-context
98
+ ```
99
+
100
+ The `stamp` command is then available everywhere. Initialize and generate context:
101
+
102
+ ```bash
103
+ stamp init # sets up .gitignore, scans for secrets
104
+ stamp context
105
+ ```
106
+
107
+ > **ℹ️ Note:** With `npx`, run `npx logicstamp-context context`. after a global install, use `stamp context`. If `npx` breaks but `stamp` works, remove the stale global CLI (`npm uninstall -g logicstamp-context`) and reinstall or run `npx logicstamp-context@latest context`.
108
+
109
+ 📋 **For detailed setup instructions, see the [Getting Started Guide](https://logicstamp.dev/docs/getting-started).**
110
+
111
+ ## Why Structured Context?
112
+
113
+ | Without LogicStamp Context | With LogicStamp Context |
114
+ |-------------------|-----------------|
115
+ | AI parses ~200 lines of implementation to infer a component's interface | AI reads a ~20-line interface contract |
116
+ | Props/hooks inferred (often wrong) | Props/hooks explicit and verified |
117
+ | No way to know if context is stale | Watch mode catches changes in real-time |
118
+ | Different prompts = different understanding | Deterministic: same code = same contract |
119
+ | Manual context gathering: "Here's my Button component..." | Structured contracts: AI understands architecture automatically |
120
+
121
+ **Key insight:** AI assistants don’t need your implementation - they need your *interfaces*.
122
+ LogicStamp extracts what matters and discards the noise.
123
+
124
+ ### What "Structured" Means
125
+
126
+ Instead of sending raw source code to AI:
127
+
128
+ ```typescript
129
+ // Raw: AI must parse and infer
130
+ export const Button = ({ variant = 'primary', disabled, onClick, children }) => {
131
+ const [isHovered, setIsHovered] = useState(false);
132
+ // ... 150 more lines of implementation
133
+ }
134
+ ```
135
+
136
+ LogicStamp Context generates:
137
+
138
+ ```json
139
+ {
140
+ "kind": "react:component",
141
+ "interface": {
142
+ "props": {
143
+ "variant": { "type": "literal-union", "literals": ["primary", "secondary"] },
144
+ "disabled": { "type": "boolean" },
145
+ "onClick": { "type": "function", "signature": "() => void" }
146
+ }
147
+ },
148
+ "composition": { "hooks": ["useState"], "components": ["./Icon"] }
149
+ }
150
+ ```
151
+
152
+ Pre-parsed. Categorized. Stable. The AI reads contracts, not implementations.
153
+
154
+ On disk, each folder’s `context.json` is a **LogicStampBundle**: contracts live under `graph.nodes`, with `graph.edges` for dependencies. **`context_main.json`** indexes folders and metadata. **Full JSON shape:** [docs/reference/schema.md](docs/reference/schema.md).
155
+
156
+ ## ⚡ Features
157
+
158
+ **Under the hood:** the TypeScript compiler API (via ts-morph). **Analysis-only** - it describes your codebase and emits context files. it does not transform or refactor your source.
159
+
160
+ **Core:**
161
+ - **Deterministic contracts** - Same input = same output, auditable in version control
162
+ - **Watch mode** - Auto-regenerate on file changes with incremental rebuilds
163
+ - **Breaking change detection** - Strict watch mode catches removed props, events, functions in real-time
164
+ - **MCP-ready** - AI agents consume context via standardized MCP interface
165
+
166
+ **Analysis:**
167
+ - React/Next.js/Vue component extraction (props, hooks, state, deps)
168
+ - Backend API extraction (Express.js, NestJS routes and controllers)
169
+ - Dependency graphs (handles circular dependencies)
170
+ - Style metadata extraction (Tailwind, SCSS, MUI, shadcn)
171
+ - Next.js App Router detection (client/server, layouts, pages)
172
+
173
+ **Developer experience:**
174
+ - Per-folder bundles matching your project structure
175
+ - Accurate token estimates (GPT/Claude)
176
+ - Security-first: automatic secret detection and sanitization
177
+ - Zero config required - sensible defaults, works out of the box
178
+
179
+ ### How it fits your stack
180
+
181
+ - **Works alongside `tsc`** - Focuses on contract structure and change detection, not type-checking. Use `tsc --noEmit` for compiler errors. `compare --strict` and `--strict-watch` flag **contract-level** breaking changes.
182
+ - **Beyond `.d.ts`** - Adds semantic contracts, dependency graphs, and diffable hashes (`semanticHash`, `bundleHash`) alongside declaration surfaces.
183
+ - **Context, not control** - Feeds structured context to assistants. Decisions stay with you.
184
+
185
+ 📋 **For detailed behavior, CLI options, and workflows, see the [Usage guide](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/guides/usage.md).**
186
+
187
+ ## Watch Mode
188
+
189
+ <p align="center">
190
+ <img src="./assets/logicstamp-strict-watch.gif" width="820" />
191
+ </p>
192
+
193
+ *Strict watch mode in action: detecting violations and clearing them when resolved.*
194
+
195
+ For development, run watch mode to keep context fresh as you code:
196
+
197
+ ```bash
198
+ stamp context --watch # regenerate on changes
199
+ stamp context --strict-watch # also detect breaking changes (implies --watch)
200
+ ```
201
+ Strict watch catches breaking changes that affect consumers:
202
+
203
+ | Violation | Example |
204
+ |-----------|---------|
205
+ | `breaking_change_prop_removed` | Removed `disabled` prop from Button |
206
+ | `breaking_change_event_removed` | Removed `onSubmit` callback |
207
+ | `breaking_change_function_removed` | Deleted exported `formatDate()` |
208
+ | `contract_removed` | Deleted entire component |
209
+
210
+ **Errors vs Warnings:** Violations are classified by severity:
211
+
212
+ **❌ Errors** indicate breaking changes that will affect consumers (removed props, events, functions, or entire contracts).
213
+
214
+ **⚠️ Warnings** indicate less severe changes (type signature changes, removed internal state). Violations are tracked in real-time and automatically cleared when resolved.
215
+
216
+ **Session Status Tracking:** Strict watch mode displays a session status block showing cumulative statistics:
217
+ - **Errors/Warnings detected**: Total violations detected during the session
218
+ - **Resolved**: Number of times all violations were completely resolved
219
+ - **Active**: Current number of active violations
220
+
221
+ The status block only appears when violations change (not on every file change), keeping terminal output clean.
222
+
223
+ ![Strict Watch Mode Terminal Output](./assets/logicstamp-strict-watch-output.png)
224
+
225
+ *Example terminal output showing violations and session status.*
226
+
227
+ > ℹ️ **Note:** Strict Watch currently detects breaking changes at the source. Next step: a symbol-level import/export reverse index to trace which consumer files will break. See [docs/cli/watch.md](docs/cli/watch.md) for complete documentation.
228
+
229
+ ### One-time Comparison
230
+
231
+ Compare regenerated context against existing files:
232
+
233
+ ```bash
234
+ stamp context compare # detect changes
235
+ stamp context compare --approve # update (like jest -u)
236
+ ```
237
+
238
+ Useful for reviewing changes before committing or validating context is up-to-date.
239
+
240
+ **Git baseline comparison** *(v0.7.2)*: Compare against any git ref:
241
+ ```bash
242
+ stamp context compare --baseline git:main # Compare against main branch
243
+ stamp context compare --baseline git:HEAD # Compare against HEAD
244
+ stamp context compare --baseline git:v1.0.0 # Compare against a tag
245
+ ```
246
+
247
+ > **ℹ️ Note:** Context files are gitignored by default. Git baseline comparison uses git worktrees to generate context for both the baseline ref and the current working tree, then performs a structural contract comparison. See [docs/cli/compare.md](docs/cli/compare.md) for complete documentation.
248
+
249
+ ## How it Works
250
+
251
+ The compilation pipeline:
252
+
253
+ 1. **Scan** - Discovers all `.ts` and `.tsx` source files
254
+ 2. **Parse** - Builds AST (Abstract Syntax Tree) via `ts-morph` using the TypeScript compiler API
255
+ 3. **Extract** - Compiles contracts with props, hooks, state, signatures
256
+ 4. **Graph** - Resolves dependency relationships
257
+ 5. **Emit** - Outputs `context.json` bundles per folder
258
+ 6. **Index** - Generates `context_main.json` with metadata and statistics
259
+
260
+ One command. No build step required.
261
+
262
+ > **💡Tip:** Use `stamp context` for basic contracts. Use `stamp context style` when you need style metadata (Tailwind classes, SCSS selectors, layout patterns). Use `--style-mode lean` (default) for compact output or `--style-mode full` for detailed arrays.
263
+
264
+ ## MCP Server
265
+
266
+ For AI assistants with MCP support (Claude Desktop, Cursor, etc.):
267
+
268
+ ```bash
269
+ npm install -g logicstamp-mcp
270
+ ```
271
+
272
+ Then configure your AI assistant to use the LogicStamp MCP Server.
273
+
274
+ 🔗 **See [LogicStamp MCP Server Repository](https://github.com/LogicStamp/logicstamp-mcp)**
275
+
276
+ 📋 **See [MCP Getting Started Guide](https://logicstamp.dev/docs/mcp/getting-started)** for setup instructions.
277
+
278
+ ## Security
279
+
280
+ **Automatic Secret Protection**
281
+
282
+ LogicStamp Context protects sensitive data in generated context:
283
+
284
+ - **Security scanning by default** - `stamp init` scans source files (`.ts`, `.tsx`, `.js`, `.jsx`) and `.json` files for hard-coded secrets before context compilation
285
+ - **Automatic sanitization** - Detected secrets replaced with `"PRIVATE_DATA"` in output
286
+ - **Manual exclusions** - Use `stamp ignore <file>` to exclude files via `.stampignore`
287
+ - **Safe by default** - Only metadata included. Credentials only appear in `--include-code full` mode
288
+
289
+ > **⚠️ Seeing `"PRIVATE_DATA"` in output?** Review `stamp_security_report.json`, remove hardcoded secrets from source, use environment variables instead.
290
+
291
+ 🔒 **See [SECURITY.md](https://github.com/LogicStamp/logicstamp-context/blob/main/SECURITY.md)** for complete security documentation.
292
+
293
+ ## Usage
294
+
295
+ <details>
296
+ <summary><strong>💻 CLI Usage Reference</strong></summary>
297
+
298
+ ```bash
299
+ stamp --version # Show version
300
+ stamp --help # Show help
301
+ stamp init [path] # Initialize project (security scan by default)
302
+ stamp ignore <path> # Add to .stampignore
303
+ stamp context [path] # Generate context bundles
304
+ stamp context style [path] # Generate with style metadata (lean mode by default)
305
+ stamp context style --style-mode full # Generate with full style details (verbose)
306
+ stamp context --watch # Watch mode
307
+ stamp context --strict-watch # Watch with breaking change detection (--watch optional)
308
+ stamp context compare # Detect changes vs existing context
309
+ stamp context validate [file] # Validate context files
310
+ stamp context clean [path] # Remove generated files
311
+ ```
312
+
313
+ ### Common Options
314
+
315
+ | Option | Description |
316
+ |--------|-------------|
317
+ | `--depth <n>` | Dependency traversal depth (default: 2) |
318
+ | `--include-code <mode>` | Code inclusion: `none\|header\|full` (default: header) |
319
+ | `--include-style` | Extract style metadata (Tailwind, SCSS, animations) |
320
+ | `--format <fmt>` | Output format: `json\|pretty\|ndjson\|toon` (default: json) |
321
+ | `--max-nodes <n>` | Maximum nodes per bundle (default: 100) |
322
+ | `--profile <p>` | Preset: `llm-chat`, `llm-safe`, `ci-strict`, `watch-fast` |
323
+ | `--compare-modes` | Show token cost comparison across all modes |
324
+ | `--stats` | Emit JSON stats with token estimates |
325
+ | `--out <path>` | Output directory |
326
+ | `--quiet` | Suppress verbose output |
327
+ | `--strict-missing` | Exit with error if any missing dependencies found (CI-friendly) |
328
+ | `--debug` | Show detailed hash info (watch mode) |
329
+ | `--log-file` | Write change logs to `.logicstamp/` (watch mode) |
330
+
331
+ </details>
332
+
333
+ 📋 **See [docs/cli/commands.md](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/cli/commands.md)** for complete reference.
334
+
335
+ ## Framework Support
336
+
337
+ | Framework | Support Level | What's Extracted |
338
+ |-----------|--------------|------------------|
339
+ | **React** | Full | Components, hooks, props, styles |
340
+ | **Next.js** | Full | App Router roles, segment paths, metadata |
341
+ | **Vue 3** | Partial | Composition API (TS/TSX only, not .vue SFC) |
342
+ | **Express.js** | Full | Routes, API signatures (middleware not extracted. see [limitations](docs/reference/limitations.md)) |
343
+ | **NestJS** | Full | Controllers, decorators, API signatures |
344
+ | **UI Libraries** | Full | Material UI, ShadCN, Radix, Tailwind, Styled Components, CSS/SCSS (modules & imports), Chakra UI, Ant Design |
345
+
346
+ > ℹ️ **Note:** LogicStamp Context analyzes `.ts` and `.tsx` files only (JavaScript is not analyzed). Styling (Tailwind, SCSS, CSS Modules, UI libraries) is extracted as **structured style metadata**, not raw CSS. See the [Style command](docs/cli/style.md).
347
+
348
+ ## Documentation
349
+
350
+ **Full documentation at [logicstamp.dev/docs](https://logicstamp.dev/docs)**
351
+
352
+ - [Getting Started Guide](https://logicstamp.dev/docs/getting-started)
353
+ - [Usage Guide](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/guides/usage.md)
354
+ - [Monorepo Support](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/guides/monorepo.md)
355
+ - [Output Schema](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/reference/schema.md)
356
+ - [UIF Contracts](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/reference/uif-contracts.md)
357
+ - [Watch Mode](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/cli/watch.md)
358
+ - [Troubleshooting](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/guides/usage.md#troubleshooting)
359
+
360
+ ## Known Limitations
361
+
362
+ LogicStamp Context is in beta. Some edge cases are not fully supported.
363
+
364
+ 📋 **See [docs/reference/limitations.md](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/reference/limitations.md)** for the full list.
365
+
366
+ ## Benchmarks
367
+
368
+ You can compare bundle token costs across modes on your repo with `stamp context --compare-modes` (see [compare modes](https://github.com/LogicStamp/logicstamp-context/blob/main/docs/cli/compare-modes.md)).
369
+
370
+ **Formal benchmarks** are on the [roadmap](https://github.com/LogicStamp/logicstamp-context/blob/main/ROADMAP.md#performance--optimization):
371
+ - CLI/runtime baselines
372
+ - LLM evaluations (with vs without LogicStamp context)
373
+
374
+ ## Requirements
375
+
376
+ - **Node.js** >= 20
377
+ - **TypeScript codebase** - `.ts` / `.tsx` only (JavaScript is not yet analyzed). Frameworks, UI libraries, and limits: **[Framework support](#framework-support)**.
378
+
379
+ ## Need Help?
380
+
381
+ - **Issues** - [github.com/LogicStamp/logicstamp-context/issues](https://github.com/LogicStamp/logicstamp-context/issues)
382
+ - **Roadmap** - [logicstamp.dev/roadmap](https://logicstamp.dev/roadmap)
383
+
384
+ ## License
385
+
386
+ [MIT](LICENSE)
387
+
388
+ ---
389
+
390
+ <details>
391
+ <summary>Branding & Attribution</summary>
392
+
393
+ The LogicStamp Fox mascot and related brand assets are © 2025 Amit Levi. These assets may not be used for third-party branding without permission.
394
+ </details>
395
+
396
+ <details>
397
+ <summary>Contributing</summary>
398
+
399
+ Issues and PRs welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
400
+
401
+ This project follows a [Code of Conduct](CODE_OF_CONDUCT.md).
402
+ </details>
403
+
404
+ **Links:** [Website](https://logicstamp.dev) · [GitHub](https://github.com/LogicStamp/logicstamp-context) · [MCP Server](https://github.com/LogicStamp/logicstamp-mcp) · [Changelog](https://github.com/LogicStamp/logicstamp-context/blob/main/CHANGELOG.md)