ctxinit 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.
Files changed (221) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +484 -0
  3. package/bin/ctx.js +3 -0
  4. package/dist/analysis/index.d.ts +2 -0
  5. package/dist/analysis/index.d.ts.map +1 -0
  6. package/dist/analysis/index.js +18 -0
  7. package/dist/analysis/index.js.map +1 -0
  8. package/dist/analysis/static-analysis.d.ts +79 -0
  9. package/dist/analysis/static-analysis.d.ts.map +1 -0
  10. package/dist/analysis/static-analysis.js +279 -0
  11. package/dist/analysis/static-analysis.js.map +1 -0
  12. package/dist/bootstrap/index.d.ts +8 -0
  13. package/dist/bootstrap/index.d.ts.map +1 -0
  14. package/dist/bootstrap/index.js +13 -0
  15. package/dist/bootstrap/index.js.map +1 -0
  16. package/dist/bootstrap/orchestrator.d.ts +48 -0
  17. package/dist/bootstrap/orchestrator.d.ts.map +1 -0
  18. package/dist/bootstrap/orchestrator.js +363 -0
  19. package/dist/bootstrap/orchestrator.js.map +1 -0
  20. package/dist/bootstrap/validator.d.ts +25 -0
  21. package/dist/bootstrap/validator.d.ts.map +1 -0
  22. package/dist/bootstrap/validator.js +412 -0
  23. package/dist/bootstrap/validator.js.map +1 -0
  24. package/dist/build/atomic.d.ts +74 -0
  25. package/dist/build/atomic.d.ts.map +1 -0
  26. package/dist/build/atomic.js +235 -0
  27. package/dist/build/atomic.js.map +1 -0
  28. package/dist/build/index.d.ts +10 -0
  29. package/dist/build/index.d.ts.map +1 -0
  30. package/dist/build/index.js +26 -0
  31. package/dist/build/index.js.map +1 -0
  32. package/dist/build/lock.d.ts +102 -0
  33. package/dist/build/lock.d.ts.map +1 -0
  34. package/dist/build/lock.js +297 -0
  35. package/dist/build/lock.js.map +1 -0
  36. package/dist/build/manifest.d.ts +138 -0
  37. package/dist/build/manifest.d.ts.map +1 -0
  38. package/dist/build/manifest.js +269 -0
  39. package/dist/build/manifest.js.map +1 -0
  40. package/dist/build/orchestrator.d.ts +103 -0
  41. package/dist/build/orchestrator.d.ts.map +1 -0
  42. package/dist/build/orchestrator.js +524 -0
  43. package/dist/build/orchestrator.js.map +1 -0
  44. package/dist/cli/bootstrap.d.ts +77 -0
  45. package/dist/cli/bootstrap.d.ts.map +1 -0
  46. package/dist/cli/bootstrap.js +527 -0
  47. package/dist/cli/bootstrap.js.map +1 -0
  48. package/dist/cli/build.d.ts +32 -0
  49. package/dist/cli/build.d.ts.map +1 -0
  50. package/dist/cli/build.js +156 -0
  51. package/dist/cli/build.js.map +1 -0
  52. package/dist/cli/diff.d.ts +23 -0
  53. package/dist/cli/diff.d.ts.map +1 -0
  54. package/dist/cli/diff.js +226 -0
  55. package/dist/cli/diff.js.map +1 -0
  56. package/dist/cli/hooks.d.ts +29 -0
  57. package/dist/cli/hooks.d.ts.map +1 -0
  58. package/dist/cli/hooks.js +176 -0
  59. package/dist/cli/hooks.js.map +1 -0
  60. package/dist/cli/init.d.ts +53 -0
  61. package/dist/cli/init.d.ts.map +1 -0
  62. package/dist/cli/init.js +254 -0
  63. package/dist/cli/init.js.map +1 -0
  64. package/dist/cli/lint.d.ts +46 -0
  65. package/dist/cli/lint.d.ts.map +1 -0
  66. package/dist/cli/lint.js +210 -0
  67. package/dist/cli/lint.js.map +1 -0
  68. package/dist/cli/migrate.d.ts +28 -0
  69. package/dist/cli/migrate.d.ts.map +1 -0
  70. package/dist/cli/migrate.js +350 -0
  71. package/dist/cli/migrate.js.map +1 -0
  72. package/dist/cli/verify.d.ts +21 -0
  73. package/dist/cli/verify.d.ts.map +1 -0
  74. package/dist/cli/verify.js +209 -0
  75. package/dist/cli/verify.js.map +1 -0
  76. package/dist/cli.d.ts +8 -0
  77. package/dist/cli.d.ts.map +1 -0
  78. package/dist/cli.js +262 -0
  79. package/dist/cli.js.map +1 -0
  80. package/dist/compiler/agents-compiler.d.ts +24 -0
  81. package/dist/compiler/agents-compiler.d.ts.map +1 -0
  82. package/dist/compiler/agents-compiler.js +192 -0
  83. package/dist/compiler/agents-compiler.js.map +1 -0
  84. package/dist/compiler/base-compiler.d.ts +152 -0
  85. package/dist/compiler/base-compiler.d.ts.map +1 -0
  86. package/dist/compiler/base-compiler.js +180 -0
  87. package/dist/compiler/base-compiler.js.map +1 -0
  88. package/dist/compiler/claude-compiler.d.ts +24 -0
  89. package/dist/compiler/claude-compiler.d.ts.map +1 -0
  90. package/dist/compiler/claude-compiler.js +182 -0
  91. package/dist/compiler/claude-compiler.js.map +1 -0
  92. package/dist/compiler/cursor-compiler.d.ts +33 -0
  93. package/dist/compiler/cursor-compiler.d.ts.map +1 -0
  94. package/dist/compiler/cursor-compiler.js +136 -0
  95. package/dist/compiler/cursor-compiler.js.map +1 -0
  96. package/dist/compiler/index.d.ts +7 -0
  97. package/dist/compiler/index.d.ts.map +1 -0
  98. package/dist/compiler/index.js +24 -0
  99. package/dist/compiler/index.js.map +1 -0
  100. package/dist/compiler/rule-selector.d.ts +115 -0
  101. package/dist/compiler/rule-selector.d.ts.map +1 -0
  102. package/dist/compiler/rule-selector.js +273 -0
  103. package/dist/compiler/rule-selector.js.map +1 -0
  104. package/dist/compiler/token-estimator.d.ts +74 -0
  105. package/dist/compiler/token-estimator.d.ts.map +1 -0
  106. package/dist/compiler/token-estimator.js +191 -0
  107. package/dist/compiler/token-estimator.js.map +1 -0
  108. package/dist/config/index.d.ts +2 -0
  109. package/dist/config/index.d.ts.map +1 -0
  110. package/dist/config/index.js +18 -0
  111. package/dist/config/index.js.map +1 -0
  112. package/dist/config/loader.d.ts +48 -0
  113. package/dist/config/loader.d.ts.map +1 -0
  114. package/dist/config/loader.js +175 -0
  115. package/dist/config/loader.js.map +1 -0
  116. package/dist/git/gitignore.d.ts +59 -0
  117. package/dist/git/gitignore.d.ts.map +1 -0
  118. package/dist/git/gitignore.js +268 -0
  119. package/dist/git/gitignore.js.map +1 -0
  120. package/dist/git/hooks.d.ts +34 -0
  121. package/dist/git/hooks.d.ts.map +1 -0
  122. package/dist/git/hooks.js +129 -0
  123. package/dist/git/hooks.js.map +1 -0
  124. package/dist/git/husky.d.ts +52 -0
  125. package/dist/git/husky.d.ts.map +1 -0
  126. package/dist/git/husky.js +219 -0
  127. package/dist/git/husky.js.map +1 -0
  128. package/dist/git/index.d.ts +9 -0
  129. package/dist/git/index.d.ts.map +1 -0
  130. package/dist/git/index.js +15 -0
  131. package/dist/git/index.js.map +1 -0
  132. package/dist/index.d.ts +6 -0
  133. package/dist/index.d.ts.map +1 -0
  134. package/dist/index.js +23 -0
  135. package/dist/index.js.map +1 -0
  136. package/dist/llm/base-provider.d.ts +43 -0
  137. package/dist/llm/base-provider.d.ts.map +1 -0
  138. package/dist/llm/base-provider.js +91 -0
  139. package/dist/llm/base-provider.js.map +1 -0
  140. package/dist/llm/index.d.ts +17 -0
  141. package/dist/llm/index.d.ts.map +1 -0
  142. package/dist/llm/index.js +36 -0
  143. package/dist/llm/index.js.map +1 -0
  144. package/dist/llm/prompts/bootstrap-prompt.d.ts +27 -0
  145. package/dist/llm/prompts/bootstrap-prompt.d.ts.map +1 -0
  146. package/dist/llm/prompts/bootstrap-prompt.js +278 -0
  147. package/dist/llm/prompts/bootstrap-prompt.js.map +1 -0
  148. package/dist/llm/prompts/index.d.ts +5 -0
  149. package/dist/llm/prompts/index.d.ts.map +1 -0
  150. package/dist/llm/prompts/index.js +11 -0
  151. package/dist/llm/prompts/index.js.map +1 -0
  152. package/dist/llm/provider-factory.d.ts +27 -0
  153. package/dist/llm/provider-factory.d.ts.map +1 -0
  154. package/dist/llm/provider-factory.js +213 -0
  155. package/dist/llm/provider-factory.js.map +1 -0
  156. package/dist/llm/providers/claude-api.d.ts +21 -0
  157. package/dist/llm/providers/claude-api.d.ts.map +1 -0
  158. package/dist/llm/providers/claude-api.js +110 -0
  159. package/dist/llm/providers/claude-api.js.map +1 -0
  160. package/dist/llm/providers/claude-code.d.ts +21 -0
  161. package/dist/llm/providers/claude-code.d.ts.map +1 -0
  162. package/dist/llm/providers/claude-code.js +120 -0
  163. package/dist/llm/providers/claude-code.js.map +1 -0
  164. package/dist/llm/providers/codex-cli.d.ts +25 -0
  165. package/dist/llm/providers/codex-cli.d.ts.map +1 -0
  166. package/dist/llm/providers/codex-cli.js +129 -0
  167. package/dist/llm/providers/codex-cli.js.map +1 -0
  168. package/dist/llm/providers/cursor-cli.d.ts +24 -0
  169. package/dist/llm/providers/cursor-cli.d.ts.map +1 -0
  170. package/dist/llm/providers/cursor-cli.js +106 -0
  171. package/dist/llm/providers/cursor-cli.js.map +1 -0
  172. package/dist/llm/providers/gemini-api.d.ts +20 -0
  173. package/dist/llm/providers/gemini-api.d.ts.map +1 -0
  174. package/dist/llm/providers/gemini-api.js +121 -0
  175. package/dist/llm/providers/gemini-api.js.map +1 -0
  176. package/dist/llm/providers/gemini-cli.d.ts +20 -0
  177. package/dist/llm/providers/gemini-cli.d.ts.map +1 -0
  178. package/dist/llm/providers/gemini-cli.js +109 -0
  179. package/dist/llm/providers/gemini-cli.js.map +1 -0
  180. package/dist/llm/providers/interactive.d.ts +42 -0
  181. package/dist/llm/providers/interactive.d.ts.map +1 -0
  182. package/dist/llm/providers/interactive.js +200 -0
  183. package/dist/llm/providers/interactive.js.map +1 -0
  184. package/dist/llm/providers/openai-api.d.ts +21 -0
  185. package/dist/llm/providers/openai-api.d.ts.map +1 -0
  186. package/dist/llm/providers/openai-api.js +107 -0
  187. package/dist/llm/providers/openai-api.js.map +1 -0
  188. package/dist/llm/types.d.ts +128 -0
  189. package/dist/llm/types.d.ts.map +1 -0
  190. package/dist/llm/types.js +8 -0
  191. package/dist/llm/types.js.map +1 -0
  192. package/dist/parser/index.d.ts +3 -0
  193. package/dist/parser/index.d.ts.map +1 -0
  194. package/dist/parser/index.js +19 -0
  195. package/dist/parser/index.js.map +1 -0
  196. package/dist/parser/path-security.d.ts +40 -0
  197. package/dist/parser/path-security.d.ts.map +1 -0
  198. package/dist/parser/path-security.js +183 -0
  199. package/dist/parser/path-security.js.map +1 -0
  200. package/dist/parser/rule-parser.d.ts +50 -0
  201. package/dist/parser/rule-parser.d.ts.map +1 -0
  202. package/dist/parser/rule-parser.js +203 -0
  203. package/dist/parser/rule-parser.js.map +1 -0
  204. package/dist/schemas/config.d.ts +202 -0
  205. package/dist/schemas/config.d.ts.map +1 -0
  206. package/dist/schemas/config.js +96 -0
  207. package/dist/schemas/config.js.map +1 -0
  208. package/dist/schemas/index.d.ts +3 -0
  209. package/dist/schemas/index.d.ts.map +1 -0
  210. package/dist/schemas/index.js +19 -0
  211. package/dist/schemas/index.js.map +1 -0
  212. package/dist/schemas/rule.d.ts +67 -0
  213. package/dist/schemas/rule.d.ts.map +1 -0
  214. package/dist/schemas/rule.js +44 -0
  215. package/dist/schemas/rule.js.map +1 -0
  216. package/package.json +69 -0
  217. package/templates/architecture.md +35 -0
  218. package/templates/bootstrap-prompt.md +242 -0
  219. package/templates/config.yaml +25 -0
  220. package/templates/project.md +44 -0
  221. package/templates/rules/example.md +36 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ctxinit 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/README.md ADDED
@@ -0,0 +1,484 @@
1
+ # ctxinit
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+ [![Node.js Version](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen)](https://nodejs.org)
5
+ [![npm version](https://img.shields.io/npm/v/ctxinit.svg)](https://www.npmjs.com/package/ctxinit)
6
+
7
+ A CLI tool for managing AI context files across multiple IDE targets. Compile your project context and rules into optimized formats for Claude Code, Cursor, and general AI agents.
8
+
9
+ ## Table of Contents
10
+
11
+ - [Features](#features)
12
+ - [Installation](#installation)
13
+ - [Quick Start](#quick-start)
14
+ - [Project Structure](#project-structure)
15
+ - [Configuration](#configuration)
16
+ - [Writing Rules](#writing-rules)
17
+ - [Commands](#commands)
18
+ - [Output Formats](#output-formats)
19
+ - [Self-Healing Features](#self-healing-features)
20
+ - [Programmatic API](#programmatic-api)
21
+ - [Development](#development)
22
+ - [Contributing](#contributing)
23
+ - [License](#license)
24
+
25
+ ## Features
26
+
27
+ - **Multi-Target Compilation**: Generate context files for Claude (`CLAUDE.md`), Cursor (`.cursor/rules/*.mdc`), and general agents (`AGENTS.md`)
28
+ - **Token Budget Management**: Intelligent rule selection to fit within configurable token limits
29
+ - **Rule Priority System**: Control which rules get included when space is limited
30
+ - **Glob-Based Filtering**: Apply rules conditionally based on file patterns
31
+ - **Incremental Builds**: Only rebuild when source files change
32
+ - **Self-Healing Verification**: Detect tampering with SHA-256 checksums
33
+ - **Watch Mode (planned)**: Automatically rebuild on file changes
34
+
35
+ ## Installation
36
+
37
+ ```bash
38
+ npm install -g ctxinit
39
+ ```
40
+
41
+ Or use with npx:
42
+
43
+ ```bash
44
+ npx ctxinit init
45
+ ```
46
+
47
+ ## Quick Start
48
+
49
+ ```bash
50
+ # Initialize a new context project
51
+ ctx init
52
+
53
+ # Build context files for all targets
54
+ ctx build
55
+
56
+ # Verify output integrity
57
+ ctx verify
58
+
59
+ # Check whether outputs are up to date (no writes)
60
+ ctx build --check
61
+ ```
62
+
63
+ ## Project Structure
64
+
65
+ After initialization, your project will have:
66
+
67
+ ```text
68
+ .context/
69
+ config.yaml # Main configuration file
70
+ project.md # Project description (required)
71
+ architecture.md # Architecture overview (optional)
72
+ rules/ # Rule files
73
+ *.md # Individual rule files
74
+ ```
75
+
76
+ ## Configuration
77
+
78
+ The `.context/config.yaml` file controls compilation:
79
+
80
+ ```yaml
81
+ version: '1.0'
82
+ project:
83
+ name: my-project
84
+ description: Project description
85
+
86
+ compile:
87
+ claude:
88
+ max_tokens: 4000
89
+ strategy: priority
90
+ always_include:
91
+ - core-rules
92
+
93
+ cursor:
94
+ strategy: all
95
+
96
+ agents:
97
+ max_tokens: 8000
98
+ ```
99
+
100
+ ### Compilation Strategies
101
+
102
+ - **all**: Include all rules (default for Cursor)
103
+ - **priority**: Include rules by priority until token budget is reached
104
+ - **directory**: Include rules from specific directories
105
+ - **glob**: Include rules whose globs match current context files
106
+ - **tag**: Filter rules by tags
107
+
108
+ ## Writing Rules
109
+
110
+ Rules are markdown files with YAML frontmatter:
111
+
112
+ ```markdown
113
+ ---
114
+ id: coding-standards
115
+ description: Project coding standards
116
+ priority: 10
117
+ always_apply: true
118
+ globs:
119
+ - "**/*.ts"
120
+ - "**/*.js"
121
+ tags:
122
+ - code-quality
123
+ domain: backend
124
+ ---
125
+
126
+ # Coding Standards
127
+
128
+ Your rule content here...
129
+ ```
130
+
131
+ ### Frontmatter Fields
132
+
133
+ | Field | Type | Description |
134
+ |-------|------|-------------|
135
+ | `id` | string | Unique rule identifier (required) |
136
+ | `description` | string | Brief description |
137
+ | `priority` | number | Higher = more important (0-100) |
138
+ | `always_apply` | boolean | Always include regardless of globs |
139
+ | `globs` | string[] | File patterns for conditional application |
140
+ | `tags` | string[] | Categorization tags |
141
+ | `domain` | string | Domain category |
142
+
143
+ ## Commands
144
+
145
+ ### `ctx init`
146
+
147
+ Initialize a new context project in the current directory. By default, this also runs the enhanced LLM bootstrap and then builds compiled outputs.
148
+
149
+ ```bash
150
+ ctx init [options]
151
+ ```
152
+
153
+ Options:
154
+ - `--force`: Overwrite existing .context directory (creates backup)
155
+ - `--bootstrap, -b`: Run LLM bootstrap after init (default)
156
+ - `--no-bootstrap`: Skip LLM bootstrap (only create templates)
157
+ - `--no-interactive`: Run without prompts (use defaults)
158
+ - `--wizard`: Launch guided migration wizard
159
+ - `--dry-run`: Show what would happen without making changes
160
+
161
+ ### `ctx build`
162
+
163
+ Compile rules to target formats.
164
+
165
+ ```bash
166
+ ctx build [targets...] [options]
167
+ ```
168
+
169
+ Options:
170
+ - `-i, --incremental`: Only rebuild changed files
171
+ - `--force`: Force full rebuild
172
+ - `--skip-validation`: Skip rule validation
173
+ - `--check`: Check whether outputs are up to date (no writes)
174
+ - `-t, --target <targets...>`: Specific targets to build (claude, cursor, agents)
175
+ - `-v, --verbose`: Verbose output
176
+ - `-q, --quiet`: Suppress output except errors
177
+
178
+ Examples:
179
+ ```bash
180
+ ctx build # Build all targets
181
+ ctx build claude cursor # Build specific targets
182
+ ctx build --target claude # Build specific targets (flag)
183
+ ctx build --check # Check outputs match sources
184
+ ```
185
+
186
+ ### `ctx verify`
187
+
188
+ Verify compiled output integrity using checksums.
189
+
190
+ ```bash
191
+ ctx verify [options]
192
+ ```
193
+
194
+ Options:
195
+ - `--json`: Output in JSON format
196
+ - `-v, --verbose`: Show detailed information
197
+
198
+ Examples:
199
+ ```bash
200
+ ctx verify # Verify all outputs
201
+ ctx verify --json # JSON output
202
+ ctx verify --verbose # Detailed output
203
+ ```
204
+
205
+ ### `ctx lint`
206
+
207
+ Validate rules without building. Alias: `ctx validate`.
208
+
209
+ ```bash
210
+ ctx lint [files...] [options]
211
+ ```
212
+
213
+ Options:
214
+ - `--json`: Output in JSON format
215
+ - `-v, --verbose`: Show detailed output
216
+ - `-q, --quiet`: Suppress output except errors
217
+
218
+ Examples:
219
+ ```bash
220
+ ctx lint # Lint all rules
221
+ ctx lint .context/rules/foo.md # Lint specific files
222
+ ctx validate --json # Alias
223
+ ```
224
+
225
+ Additional commands: `ctx diff`, `ctx migrate`, `ctx hooks`, `ctx bootstrap` (see `ctx --help`).
226
+
227
+ ## Output Formats
228
+
229
+ ### Claude (CLAUDE.md)
230
+
231
+ Single markdown file optimized for Claude Code:
232
+ - Project context and architecture
233
+ - Rule directory index
234
+ - Selected rules based on token budget
235
+ - Context hygiene meta-rule
236
+
237
+ ### Cursor (.cursor/rules/*.mdc)
238
+
239
+ Individual `.mdc` files with Cursor-compatible frontmatter:
240
+ - One file per rule
241
+ - YAML frontmatter with description, globs, alwaysApply
242
+ - Full rule content
243
+
244
+ ### Agents (AGENTS.md)
245
+
246
+ Comprehensive file for general AI agents:
247
+ - Full project overview
248
+ - Complete architecture documentation
249
+ - Rule summaries with metadata
250
+ - Navigation-friendly structure
251
+
252
+ ## Self-Healing Features
253
+
254
+ ctxinit embeds metadata in compiled outputs for integrity verification:
255
+
256
+ ```html
257
+ <!-- ctx build metadata -->
258
+ <!-- timestamp: 2024-01-15T10:30:00.000Z -->
259
+ <!-- checksum: sha256:abc123... -->
260
+ ```
261
+
262
+ Use `ctx verify` to detect tampering or accidental modifications.
263
+
264
+ ## Programmatic API
265
+
266
+ ```typescript
267
+ import { ConfigLoader, RuleParser, ClaudeCompiler } from 'ctxinit';
268
+
269
+ // Load configuration
270
+ const configLoader = new ConfigLoader(projectRoot);
271
+ const config = configLoader.loadConfig();
272
+
273
+ // Parse rules
274
+ const parser = new RuleParser(projectRoot);
275
+ const rules = parser.discoverAndParse();
276
+
277
+ // Compile
278
+ const compiler = new ClaudeCompiler({
279
+ projectRoot,
280
+ config,
281
+ rules
282
+ });
283
+ const result = await compiler.compile();
284
+ ```
285
+
286
+ ## Development
287
+
288
+ ### Prerequisites
289
+
290
+ - Node.js >= 18.0.0
291
+ - npm or yarn
292
+
293
+ ### Setup
294
+
295
+ ```bash
296
+ # Clone the repository
297
+ git clone https://github.com/stone16/ctxinit.git
298
+ cd ctxinit
299
+
300
+ # Install dependencies
301
+ npm install
302
+
303
+ # Build the project
304
+ npm run build
305
+ ```
306
+
307
+ ### Local Testing with npm pack
308
+
309
+ To test your changes as an end user would experience them, use `npm pack` to create a tarball and install it in a separate directory:
310
+
311
+ ```bash
312
+ # 1. Build and pack the project
313
+ npm run build
314
+ npm pack
315
+ # Creates ctxinit-x.x.x.tgz
316
+
317
+ # 2. In a separate test directory, install from the tarball
318
+ mkdir ~/test-project && cd ~/test-project
319
+ npm install /path/to/ctxinit/ctxinit-x.x.x.tgz
320
+
321
+ # 3. Test the CLI commands
322
+ npx ctx init
323
+ npx ctx build
324
+ npx ctx verify
325
+ ```
326
+
327
+ For global installation testing:
328
+
329
+ ```bash
330
+ npm install -g /path/to/ctxinit/ctxinit-x.x.x.tgz
331
+ ctx init
332
+ ctx build
333
+ ```
334
+
335
+ ### Running Tests
336
+
337
+ ```bash
338
+ # Run all tests
339
+ npm test
340
+
341
+ # Run tests with coverage
342
+ npm run test:coverage
343
+
344
+ # Run tests in watch mode
345
+ npm test -- --watch
346
+
347
+ # Run a specific test file
348
+ npm test -- tests/compiler/claude-compiler.test.ts
349
+
350
+ # Run tests matching a pattern
351
+ npm test -- --testNamePattern="should compile"
352
+ ```
353
+
354
+ ### Code Quality
355
+
356
+ ```bash
357
+ # Run linting
358
+ npm run lint
359
+
360
+ # Fix linting issues automatically
361
+ npm run lint:fix
362
+
363
+ # Check code formatting
364
+ npm run format:check
365
+
366
+ # Format code
367
+ npm run format
368
+ ```
369
+
370
+ ### Development Workflow
371
+
372
+ ```bash
373
+ # Watch mode for TypeScript compilation
374
+ npm run dev
375
+
376
+ # In another terminal, test your changes
377
+ ctx build --verbose
378
+ ```
379
+
380
+ ### Project Structure
381
+
382
+ ```text
383
+ ctxinit/
384
+ ├── bin/ # CLI entry point
385
+ │ └── ctx.js
386
+ ├── src/ # Source code
387
+ │ ├── cli/ # CLI commands
388
+ │ ├── compiler/ # Target compilers
389
+ │ ├── config/ # Configuration loading
390
+ │ ├── parser/ # Rule parsing
391
+ │ ├── build/ # Build orchestration
392
+ │ ├── schemas/ # Zod schemas
393
+ │ └── index.ts # Public API exports
394
+ ├── tests/ # Test files
395
+ │ ├── cli/ # CLI command tests
396
+ │ ├── compiler/ # Compiler tests
397
+ │ ├── config/ # Config tests
398
+ │ ├── parser/ # Parser tests
399
+ │ ├── build/ # Build tests
400
+ │ ├── integration/ # Integration tests
401
+ │ ├── performance/ # Performance benchmarks
402
+ │ └── __mocks__/ # Test mocks
403
+ ├── templates/ # Template files for ctx init
404
+ ├── docs/ # Documentation
405
+ └── examples/ # Example projects
406
+ ```
407
+
408
+ ### Writing Tests
409
+
410
+ Tests use Jest and follow this structure:
411
+
412
+ ```typescript
413
+ import { describe, it, expect, beforeEach, afterEach } from '@jest/globals';
414
+
415
+ describe('MyFeature', () => {
416
+ beforeEach(() => {
417
+ // Setup
418
+ });
419
+
420
+ afterEach(() => {
421
+ // Cleanup
422
+ });
423
+
424
+ it('should do something', () => {
425
+ // Test
426
+ expect(result).toBe(expected);
427
+ });
428
+ });
429
+ ```
430
+
431
+ ### Debugging
432
+
433
+ ```bash
434
+ # Run with Node.js inspector
435
+ node --inspect-brk bin/ctx.js build
436
+
437
+ # Debug tests
438
+ node --inspect-brk node_modules/.bin/jest --runInBand
439
+ ```
440
+
441
+ ## Contributing
442
+
443
+ We welcome contributions! Here's how you can help:
444
+
445
+ ### Reporting Issues
446
+
447
+ - Search [existing issues](https://github.com/stone16/ctxinit/issues) first
448
+ - Include reproduction steps, expected vs actual behavior
449
+ - Provide your environment details (Node.js version, OS, etc.)
450
+
451
+ ### Pull Requests
452
+
453
+ 1. Fork the repository
454
+ 2. Create a feature branch: `git checkout -b feature/my-feature`
455
+ 3. Make your changes
456
+ 4. Add or update tests as needed
457
+ 5. Ensure all tests pass: `npm test`
458
+ 6. Ensure linting passes: `npm run lint`
459
+ 7. Commit with a clear message
460
+ 8. Push and open a Pull Request
461
+
462
+ ### Development Guidelines
463
+
464
+ - Follow existing code style
465
+ - Write tests for new features
466
+ - Update documentation as needed
467
+ - Keep commits focused and atomic
468
+ - Use conventional commit messages when possible
469
+
470
+ ### Areas for Contribution
471
+
472
+ - Bug fixes and improvements
473
+ - New compilation targets
474
+ - Documentation improvements
475
+ - Performance optimizations
476
+ - Test coverage improvements
477
+
478
+ ## License
479
+
480
+ MIT License - see [LICENSE](LICENSE) for details.
481
+
482
+ ---
483
+
484
+ **Questions?** Open an issue or start a discussion on GitHub.
package/bin/ctx.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ require('../dist/cli').run();
@@ -0,0 +1,2 @@
1
+ export * from './static-analysis';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/analysis/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./static-analysis"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/analysis/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC"}
@@ -0,0 +1,79 @@
1
+ import { ParsedRule, RuleValidationError, RuleValidationWarning, RuleValidationResult } from '../schemas/rule';
2
+ import { Config } from '../schemas/config';
3
+ /**
4
+ * Analysis result for a complete validation run
5
+ */
6
+ export interface AnalysisResult {
7
+ /** Whether validation passed (no blocking errors) */
8
+ valid: boolean;
9
+ /** Blocking errors that prevent compilation */
10
+ errors: RuleValidationError[];
11
+ /** Non-blocking warnings */
12
+ warnings: RuleValidationWarning[];
13
+ /** Total rules analyzed */
14
+ rulesAnalyzed: number;
15
+ }
16
+ /**
17
+ * Options for static analysis
18
+ */
19
+ export interface AnalysisOptions {
20
+ /** Project root directory */
21
+ projectRoot: string;
22
+ /** Configuration for token limits */
23
+ config?: Config;
24
+ }
25
+ /**
26
+ * Analyze rules for duplicate IDs
27
+ *
28
+ * @param rules - Parsed rules to analyze
29
+ * @returns Array of duplicate ID errors
30
+ */
31
+ export declare function findDuplicateIds(rules: ParsedRule[]): RuleValidationError[];
32
+ /**
33
+ * Find dead links in markdown content
34
+ *
35
+ * @param rule - Parsed rule to analyze
36
+ * @param projectRoot - Project root for resolving relative links
37
+ * @returns Array of dead link errors
38
+ */
39
+ export declare function findDeadLinks(rule: ParsedRule, projectRoot: string): RuleValidationError[];
40
+ /**
41
+ * Find ghost rules (globs that match no files)
42
+ *
43
+ * @param rule - Parsed rule to analyze
44
+ * @param projectRoot - Project root for glob matching
45
+ * @returns Array of ghost rule warnings
46
+ */
47
+ export declare function findGhostRules(rule: ParsedRule, projectRoot: string): RuleValidationWarning[];
48
+ /**
49
+ * Check for potential token limit issues
50
+ *
51
+ * @param rules - Parsed rules to analyze
52
+ * @param config - Configuration with token limits
53
+ * @returns Array of token limit warnings
54
+ */
55
+ export declare function checkTokenLimits(rules: ParsedRule[], config?: Config): RuleValidationWarning[];
56
+ /**
57
+ * Detect circular references in rule imports
58
+ *
59
+ * @param rules - Parsed rules to analyze
60
+ * @returns Array of circular reference errors
61
+ */
62
+ export declare function findCircularReferences(rules: ParsedRule[]): RuleValidationError[];
63
+ /**
64
+ * Validate a single rule
65
+ *
66
+ * @param rule - Parsed rule to validate
67
+ * @param options - Analysis options
68
+ * @returns Validation result for the rule
69
+ */
70
+ export declare function validateRule(rule: ParsedRule, options: AnalysisOptions): RuleValidationResult;
71
+ /**
72
+ * Run complete static analysis on all rules
73
+ *
74
+ * @param rules - Parsed rules to analyze
75
+ * @param options - Analysis options
76
+ * @returns Complete analysis result
77
+ */
78
+ export declare function analyzeRules(rules: ParsedRule[], options: AnalysisOptions): AnalysisResult;
79
+ //# sourceMappingURL=static-analysis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static-analysis.d.ts","sourceRoot":"","sources":["../../src/analysis/static-analysis.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC/G,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,qDAAqD;IACrD,KAAK,EAAE,OAAO,CAAC;IACf,+CAA+C;IAC/C,MAAM,EAAE,mBAAmB,EAAE,CAAC;IAC9B,4BAA4B;IAC5B,QAAQ,EAAE,qBAAqB,EAAE,CAAC;IAClC,2BAA2B;IAC3B,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,6BAA6B;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,mBAAmB,EAAE,CAwB3E;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,mBAAmB,EAAE,CAuC1F;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,qBAAqB,EAAE,CA6B7F;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,qBAAqB,EAAE,CAyB9F;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,mBAAmB,EAAE,CA6CjF;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,eAAe,GAAG,oBAAoB,CAe7F;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,OAAO,EAAE,eAAe,GAAG,cAAc,CA0B1F"}