logicstamp-context 0.1.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/LICENSE +21 -0
- package/LLM_CONTEXT.md +260 -0
- package/README.md +949 -0
- package/dist/cli/commands/clean.d.ts +15 -0
- package/dist/cli/commands/clean.d.ts.map +1 -0
- package/dist/cli/commands/clean.js +142 -0
- package/dist/cli/commands/clean.js.map +1 -0
- package/dist/cli/commands/compare.d.ts +88 -0
- package/dist/cli/commands/compare.d.ts.map +1 -0
- package/dist/cli/commands/compare.js +519 -0
- package/dist/cli/commands/compare.js.map +1 -0
- package/dist/cli/commands/context.d.ts +24 -0
- package/dist/cli/commands/context.d.ts.map +1 -0
- package/dist/cli/commands/context.js +576 -0
- package/dist/cli/commands/context.js.map +1 -0
- package/dist/cli/commands/init.d.ts +14 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +71 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/validate.d.ts +52 -0
- package/dist/cli/commands/validate.d.ts.map +1 -0
- package/dist/cli/commands/validate.js +368 -0
- package/dist/cli/commands/validate.js.map +1 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +223 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/stamp.d.ts +7 -0
- package/dist/cli/stamp.d.ts.map +1 -0
- package/dist/cli/stamp.js +961 -0
- package/dist/cli/stamp.js.map +1 -0
- package/dist/cli/validate-index.d.ts +7 -0
- package/dist/cli/validate-index.d.ts.map +1 -0
- package/dist/cli/validate-index.js +55 -0
- package/dist/cli/validate-index.js.map +1 -0
- package/dist/core/astParser.d.ts +47 -0
- package/dist/core/astParser.d.ts.map +1 -0
- package/dist/core/astParser.js +417 -0
- package/dist/core/astParser.js.map +1 -0
- package/dist/core/contractBuilder.d.ts +48 -0
- package/dist/core/contractBuilder.d.ts.map +1 -0
- package/dist/core/contractBuilder.js +120 -0
- package/dist/core/contractBuilder.js.map +1 -0
- package/dist/core/manifest.d.ts +75 -0
- package/dist/core/manifest.d.ts.map +1 -0
- package/dist/core/manifest.js +173 -0
- package/dist/core/manifest.js.map +1 -0
- package/dist/core/pack.d.ts +190 -0
- package/dist/core/pack.d.ts.map +1 -0
- package/dist/core/pack.js +438 -0
- package/dist/core/pack.js.map +1 -0
- package/dist/core/signature.d.ts +47 -0
- package/dist/core/signature.d.ts.map +1 -0
- package/dist/core/signature.js +208 -0
- package/dist/core/signature.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/types/UIFContract.d.ts +112 -0
- package/dist/types/UIFContract.d.ts.map +1 -0
- package/dist/types/UIFContract.js +36 -0
- package/dist/types/UIFContract.js.map +1 -0
- package/dist/utils/config.d.ts +34 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +62 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/fsx.d.ts +85 -0
- package/dist/utils/fsx.d.ts.map +1 -0
- package/dist/utils/fsx.js +181 -0
- package/dist/utils/fsx.js.map +1 -0
- package/dist/utils/gitignore.d.ts +62 -0
- package/dist/utils/gitignore.d.ts.map +1 -0
- package/dist/utils/gitignore.js +183 -0
- package/dist/utils/gitignore.js.map +1 -0
- package/dist/utils/hash.d.ts +73 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +159 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/llmContext.d.ts +34 -0
- package/dist/utils/llmContext.d.ts.map +1 -0
- package/dist/utils/llmContext.js +136 -0
- package/dist/utils/llmContext.js.map +1 -0
- package/dist/utils/tokens.d.ts +23 -0
- package/dist/utils/tokens.d.ts.map +1 -0
- package/dist/utils/tokens.js +29 -0
- package/dist/utils/tokens.js.map +1 -0
- package/package.json +69 -0
- package/schema/logicstamp.context.schema.json +430 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 LogicStamp Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/LLM_CONTEXT.md
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# LogicStamp Context – LLM Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
- Generates AI-friendly context bundles from React/TypeScript projects without build steps.
|
|
5
|
+
- Ships as a global CLI (install with `npm install -g logicstamp-context`, then use `stamp context` command) that scans `.ts`/`.tsx`, extracts component contracts, and emits structured JSON.
|
|
6
|
+
- Optimizes output for consumption by assistants such as Claude or ChatGPT to improve code understanding and guidance.
|
|
7
|
+
- Works on Node.js ≥ 18 and requires access to the project's source tree.
|
|
8
|
+
|
|
9
|
+
**Note**: "Global CLI" means the tool is installed globally on your system (via `npm install -g`), making the `stamp` command available from any directory in your terminal, not just within a specific project folder.
|
|
10
|
+
|
|
11
|
+
## Core Workflow
|
|
12
|
+
- `src/cli/index.ts` and `src/cli/stamp.ts` orchestrate CLI execution: read CLI flags, call the analyzer pipeline, write bundles to disk, and handle compare/validate commands.
|
|
13
|
+
- `src/cli/commands/compare.ts` implements drift detection for single-file and multi-file comparison modes, including ADDED/ORPHANED/DRIFT/PASS detection.
|
|
14
|
+
- `src/core/astParser.ts` uses `ts-morph` to parse source files, derive component metadata, and normalize type information.
|
|
15
|
+
- `src/core/contractBuilder.ts` converts raw AST findings into UIF contracts and merges incremental updates.
|
|
16
|
+
- `src/core/manifest.ts` and `src/core/pack.ts` assemble dependency graphs, compute bundle hashes, and format final output entries.
|
|
17
|
+
- `src/types/UIFContract.ts` defines the UIF contract schema; `src/utils/fsx.ts` and `src/utils/hash.ts` provide file and hashing utilities.
|
|
18
|
+
|
|
19
|
+
## CLI Usage Cheatsheet
|
|
20
|
+
- Install globally: `npm install -g logicstamp-context`.
|
|
21
|
+
- Show version: `stamp --version` or `stamp -v` displays the version number.
|
|
22
|
+
- Default command `stamp context [target]` scans the current directory (or supplied path) and emits multiple `context.json` files (one per folder containing components) plus a `context_main.json` index file at the output root.
|
|
23
|
+
- Key flags: `--depth` (dependency traversal), `--include-code none|header|full`, `--profile llm-chat|llm-safe|ci-strict`, `--out <file>` (output directory or file path), `--max-nodes <n>`, `--quiet` or `-q` (suppress verbose output, show only errors).
|
|
24
|
+
- Profiles tune defaults: `llm-chat` (balanced), `llm-safe` (token-conservative), `ci-strict` (validation-first).
|
|
25
|
+
- Supports pretty and NDJSON formats via `--format`.
|
|
26
|
+
- Compare command: `stamp context compare` compares all context files (multi-file mode) to detect drift, ADDED/ORPHANED folders, and component changes. Supports `--approve` for auto-updates, `--clean-orphaned` for cleanup, `--stats` for per-folder token deltas, and `--quiet` or `-q` to show only diffs.
|
|
27
|
+
- Validate command: `stamp context validate [file]` checks context files for schema compliance. Supports `--quiet` or `-q` to show only errors.
|
|
28
|
+
- Clean command: `stamp context clean [path]` removes context artifacts. Supports `--quiet` or `-q` to suppress verbose output.
|
|
29
|
+
- Output structure: Context files are organized by folder, maintaining project directory hierarchy. Each folder gets its own `context.json` with bundles for that folder's components. The `context_main.json` index file provides metadata about all folders.
|
|
30
|
+
|
|
31
|
+
## Output Structure
|
|
32
|
+
|
|
33
|
+
LogicStamp Context generates **folder-organized, multi-file output**:
|
|
34
|
+
|
|
35
|
+
### File Organization
|
|
36
|
+
- Multiple `context.json` files, one per folder containing components
|
|
37
|
+
- Directory structure mirrors your project layout
|
|
38
|
+
- `context_main.json` index file at the output root with folder metadata
|
|
39
|
+
|
|
40
|
+
**Example structure:**
|
|
41
|
+
```
|
|
42
|
+
output/
|
|
43
|
+
├── context_main.json # Main index with folder metadata
|
|
44
|
+
├── context.json # Root folder bundles (if any)
|
|
45
|
+
├── src/
|
|
46
|
+
│ └── context.json # Bundles from src/ folder
|
|
47
|
+
├── src/components/
|
|
48
|
+
│ └── context.json # Bundles from src/components/
|
|
49
|
+
└── src/utils/
|
|
50
|
+
└── context.json # Bundles from src/utils/
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Main Index (`context_main.json`)
|
|
54
|
+
|
|
55
|
+
The `context_main.json` file serves as a directory index:
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
{
|
|
59
|
+
"type": "LogicStampIndex",
|
|
60
|
+
"schemaVersion": "0.1",
|
|
61
|
+
"projectRoot": ".",
|
|
62
|
+
"projectRootResolved": "/absolute/path/to/project",
|
|
63
|
+
"createdAt": "2025-01-15T10:30:00.000Z",
|
|
64
|
+
"summary": {
|
|
65
|
+
"totalComponents": 42,
|
|
66
|
+
"totalBundles": 15,
|
|
67
|
+
"totalFolders": 5,
|
|
68
|
+
"totalTokenEstimate": 13895
|
|
69
|
+
},
|
|
70
|
+
"folders": [
|
|
71
|
+
{
|
|
72
|
+
"path": "src/components",
|
|
73
|
+
"contextFile": "src/components/context.json",
|
|
74
|
+
"bundles": 3,
|
|
75
|
+
"components": ["Button.tsx", "Card.tsx"],
|
|
76
|
+
"isRoot": false,
|
|
77
|
+
"tokenEstimate": 5234
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"path": ".",
|
|
81
|
+
"contextFile": "context.json",
|
|
82
|
+
"bundles": 2,
|
|
83
|
+
"components": ["App.tsx"],
|
|
84
|
+
"isRoot": true,
|
|
85
|
+
"rootLabel": "Project Root",
|
|
86
|
+
"tokenEstimate": 2134
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
"meta": {
|
|
90
|
+
"source": "logicstamp-context@0.1.0"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Folder entry fields:**
|
|
96
|
+
- `path` - Relative path from project root
|
|
97
|
+
- `contextFile` - Path to this folder's context.json
|
|
98
|
+
- `bundles` - Number of bundles in this folder
|
|
99
|
+
- `components` - List of component file names
|
|
100
|
+
- `isRoot` - Whether this is an application entry point
|
|
101
|
+
- `rootLabel` - Label for root folders (e.g., "Next.js App", "Project Root")
|
|
102
|
+
- `tokenEstimate` - Token count for this folder's context
|
|
103
|
+
|
|
104
|
+
### Folder Context Files (`context.json`)
|
|
105
|
+
|
|
106
|
+
Each folder's `context.json` contains an array of LogicStamp bundles. Each bundle represents one entry point (component/module) plus its immediate dependency graph.
|
|
107
|
+
- **Design note**: LogicStamp Context uses per-root bundles (one bundle per entry point) rather than per-component files. This means each bundle contains the root component plus its complete dependency graph—all related components and their relationships in one self-contained unit. This design is optimized for AI consumption: when you need help with a specific page or feature, share that root bundle and the AI has complete context.
|
|
108
|
+
- Top-level fields: `position`, `type`, `schemaVersion`, `entryId`, `depth`, `createdAt`, `bundleHash`, `graph`, `meta`.
|
|
109
|
+
- `graph.nodes` holds UIF contracts describing functions, props, events, imports, and semantic/file hashes. Optional `codeHeader` stores contract headers or code snippets when requested.
|
|
110
|
+
- `graph.edges` lists dependency relationships between nodes (empty when analysis depth is 1).
|
|
111
|
+
- `meta` section contains two critical fields:
|
|
112
|
+
- `missing`: Array of unresolved dependencies. Each entry includes `name` (import path), `reason` (why it failed), and `referencedBy` (source component). Empty array indicates complete dependency resolution.
|
|
113
|
+
- `source`: Generator version string (e.g., `"logicstamp-context@0.1.0"`) for compatibility tracking.
|
|
114
|
+
- Example bundle skeleton:
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
```1:58:context.json
|
|
118
|
+
[
|
|
119
|
+
{
|
|
120
|
+
"position": "1/9",
|
|
121
|
+
"type": "LogicStampBundle",
|
|
122
|
+
"schemaVersion": "0.1",
|
|
123
|
+
"entryId": ".../src/cli/index.ts",
|
|
124
|
+
"graph": {
|
|
125
|
+
"nodes": [
|
|
126
|
+
{
|
|
127
|
+
"contract": {
|
|
128
|
+
"kind": "node:cli",
|
|
129
|
+
"version": {
|
|
130
|
+
"functions": ["generateContext", "main", "printHelp"],
|
|
131
|
+
"imports": ["../core/astParser.js", "..."]
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
- Bundles may include behavioral `prediction` hints when heuristics detect notable logic (e.g., form handling, data access).
|
|
136
|
+
|
|
137
|
+
## Interpreting Missing Dependencies
|
|
138
|
+
When `meta.missing` is non-empty, it signals incomplete dependency resolution:
|
|
139
|
+
|
|
140
|
+
**Common scenarios:**
|
|
141
|
+
1. **External packages** (`reason: "external package"`) - Expected. LogicStamp only analyzes project source, not node_modules.
|
|
142
|
+
2. **File not found** (`reason: "file not found"`) - Component references a deleted/moved file. May indicate refactoring in progress or broken imports.
|
|
143
|
+
3. **Outside scan path** (`reason: "outside scan path"`) - Dependency exists but wasn't included in the scan directory. Consider widening scan scope.
|
|
144
|
+
4. **Max depth exceeded** (`reason: "max depth exceeded"`) - Dependency chain deeper than `--depth` setting. Increase depth for fuller analysis.
|
|
145
|
+
5. **Circular dependency** (`reason: "circular dependency"`) - Import cycle detected. LogicStamp breaks the cycle to prevent infinite loops.
|
|
146
|
+
|
|
147
|
+
**Best practices for LLMs:**
|
|
148
|
+
- Check `meta.missing` before making assumptions about complete component coverage
|
|
149
|
+
- When missing deps exist, inform the user that analysis may be partial
|
|
150
|
+
- Suggest running with `--depth 2` or higher if many "max depth exceeded" entries appear
|
|
151
|
+
- Flag "file not found" entries as potential bugs in the codebase
|
|
152
|
+
|
|
153
|
+
## Suggestions for LLM Consumers
|
|
154
|
+
|
|
155
|
+
### Loading Context Files
|
|
156
|
+
|
|
157
|
+
1. **Start with the index**: Load `context_main.json` to understand the project structure and locate relevant folders.
|
|
158
|
+
2. **Load folder contexts**: Based on the index, load specific folder `context.json` files for the modules you need to analyze.
|
|
159
|
+
3. **Filter by `entryId`**: Within a folder's context file, filter bundles by `entryId` to focus on relevant modules.
|
|
160
|
+
4. **Combine multiple folders**: When a task spans multiple folders, load the relevant folder context files and combine their bundles.
|
|
161
|
+
|
|
162
|
+
### Working with the Index
|
|
163
|
+
|
|
164
|
+
- Use `context_main.json` to:
|
|
165
|
+
- Get an overview of all folders and their component counts
|
|
166
|
+
- Identify root folders (application entry points) via `isRoot` and `rootLabel`
|
|
167
|
+
- Estimate token costs per folder via `tokenEstimate`
|
|
168
|
+
- Locate context files for specific directories via `contextFile` paths
|
|
169
|
+
|
|
170
|
+
### Bundle Analysis
|
|
171
|
+
|
|
172
|
+
- Use `version.functions` and `logicSignature` to reason about available APIs without scanning full source.
|
|
173
|
+
- Combine multiple bundles when a task spans related modules; respect `max-nodes` constraints to stay within token budgets.
|
|
174
|
+
- For deeper understanding, rerun the CLI with `--include-code full` or higher `--depth` before querying the assistant.
|
|
175
|
+
- **Always inspect `meta.missing`** in each bundle to understand analysis completeness before providing architectural guidance.
|
|
176
|
+
|
|
177
|
+
### Folder-Based Organization Benefits
|
|
178
|
+
|
|
179
|
+
- **Targeted loading**: Load only the folder context files you need, reducing token usage
|
|
180
|
+
- **Project structure alignment**: Folder structure mirrors your codebase, making it easier to navigate
|
|
181
|
+
- **Incremental updates**: When code changes, only affected folder context files need regeneration
|
|
182
|
+
- **Root detection**: Use `isRoot` and `rootLabel` to identify application entry points and framework-specific folders
|
|
183
|
+
|
|
184
|
+
## Context Drift Detection
|
|
185
|
+
|
|
186
|
+
LogicStamp Context includes a `compare` command for detecting drift across all context files in a project:
|
|
187
|
+
|
|
188
|
+
### Multi-File Comparison Mode
|
|
189
|
+
|
|
190
|
+
The compare command operates in multi-file mode when comparing `context_main.json` indices:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
stamp context compare # Auto-mode: compares all files
|
|
194
|
+
stamp context compare old/context_main.json new/context_main.json # Manual mode
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
**What it detects:**
|
|
198
|
+
- **ADDED FILE** - New folders with context files (new features/modules added)
|
|
199
|
+
- **ORPHANED FILE** - Folders removed from project (but context files still exist on disk)
|
|
200
|
+
- **DRIFT** - Changed files with detailed component-level changes
|
|
201
|
+
- **PASS** - Unchanged files
|
|
202
|
+
|
|
203
|
+
**Three-tier output:**
|
|
204
|
+
1. **Folder-level summary** - Shows added/orphaned/changed/unchanged folder counts
|
|
205
|
+
2. **Component-level summary** - Total components added/removed/changed across all folders
|
|
206
|
+
3. **Detailed per-folder changes** - Component-by-component diffs for each folder with changes
|
|
207
|
+
|
|
208
|
+
### Use Cases for LLMs
|
|
209
|
+
|
|
210
|
+
1. **Change impact analysis**: When analyzing a codebase update, run `stamp context compare` to see exactly which folders and components changed
|
|
211
|
+
2. **Architectural drift**: Identify when new modules are added (`ADDED FILE`) or old ones removed (`ORPHANED FILE`)
|
|
212
|
+
3. **Per-folder token impact**: Use `--stats` to see token delta per folder, helping prioritize which changes to review
|
|
213
|
+
4. **Breaking change detection**: Check if component signatures (props, exports, hooks) changed, indicating potential breaking changes
|
|
214
|
+
|
|
215
|
+
### Key Features
|
|
216
|
+
|
|
217
|
+
- **Jest-style workflow**: Use `--approve` to auto-update all context files (like `jest -u` for snapshots)
|
|
218
|
+
- **Orphaned file cleanup**: Use `--clean-orphaned` with `--approve` to automatically delete stale context files
|
|
219
|
+
- **CI integration**: Exit code 1 if drift detected, making it CI-friendly for validation
|
|
220
|
+
- **Token statistics**: `--stats` shows per-folder token deltas to understand context size impact
|
|
221
|
+
|
|
222
|
+
### Example Output
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
$ stamp context compare
|
|
226
|
+
|
|
227
|
+
⚠️ DRIFT
|
|
228
|
+
|
|
229
|
+
📁 Folder Summary:
|
|
230
|
+
Total folders: 14
|
|
231
|
+
➕ Added folders: 1
|
|
232
|
+
~ Changed folders: 2
|
|
233
|
+
✓ Unchanged folders: 11
|
|
234
|
+
|
|
235
|
+
📦 Component Summary:
|
|
236
|
+
+ Added: 3
|
|
237
|
+
~ Changed: 2
|
|
238
|
+
|
|
239
|
+
📂 Folder Details:
|
|
240
|
+
|
|
241
|
+
➕ ADDED FILE: src/new-feature/context.json
|
|
242
|
+
Path: src/new-feature
|
|
243
|
+
|
|
244
|
+
⚠️ DRIFT: src/cli/commands/context.json
|
|
245
|
+
Path: src/cli/commands
|
|
246
|
+
~ Changed components (1):
|
|
247
|
+
~ compare.ts
|
|
248
|
+
Δ hash
|
|
249
|
+
old: uif:abc123...
|
|
250
|
+
new: uif:def456...
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Implementation Details
|
|
254
|
+
|
|
255
|
+
- **Truth from bundles**: Comparison is based on actual bundle content, not metadata (summary counts)
|
|
256
|
+
- **Bundle→folder mapping**: Verifies folder structure from `context_main.json`
|
|
257
|
+
- **Orphaned detection**: Checks disk for files that exist but aren't in the new index
|
|
258
|
+
- **Metadata ignored**: `totalComponents`, `totalBundles` counts are derived stats, not compared for drift
|
|
259
|
+
|
|
260
|
+
|