contextforge-cli-ai-prompt-pirates 0.4.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 (72) hide show
  1. package/.contextforge/config.ai.example.json +28 -0
  2. package/.contextforge/config.example.json +29 -0
  3. package/.contextforge/prompts/README.md +50 -0
  4. package/.env.example +73 -0
  5. package/LICENSE +21 -0
  6. package/README.md +223 -0
  7. package/bin/contextforge.js +14 -0
  8. package/bin/postinstall-worker.js +14 -0
  9. package/bin/postinstall.js +26 -0
  10. package/package.json +65 -0
  11. package/prompts/README.md +50 -0
  12. package/prompts/response-schema.md +22 -0
  13. package/prompts/retry-addon.md +1 -0
  14. package/prompts/system.md +10 -0
  15. package/prompts/user-template.md +22 -0
  16. package/src/analyzers/ast-parser.js +139 -0
  17. package/src/analyzers/bugs-lite.js +118 -0
  18. package/src/analyzers/changelog.js +190 -0
  19. package/src/analyzers/code-insights.js +225 -0
  20. package/src/analyzers/dependencies.js +110 -0
  21. package/src/analyzers/detection-quality.js +106 -0
  22. package/src/analyzers/eslint-runner.js +56 -0
  23. package/src/analyzers/folder-tree.js +60 -0
  24. package/src/analyzers/git-insights.js +94 -0
  25. package/src/analyzers/project-meta.js +98 -0
  26. package/src/cli/commands/changes.js +36 -0
  27. package/src/cli/commands/doctor.js +152 -0
  28. package/src/cli/commands/generate.js +7 -0
  29. package/src/cli/commands/init.js +98 -0
  30. package/src/cli/commands/prompt.js +53 -0
  31. package/src/cli/commands/stop.js +10 -0
  32. package/src/cli/commands/summary.js +22 -0
  33. package/src/cli/commands/watch.js +9 -0
  34. package/src/cli/index.js +120 -0
  35. package/src/core/confidence.js +51 -0
  36. package/src/core/config.js +183 -0
  37. package/src/core/cursor-rules.js +293 -0
  38. package/src/core/ensure-setup.js +45 -0
  39. package/src/core/env.js +113 -0
  40. package/src/core/package-meta.js +35 -0
  41. package/src/core/paths.js +39 -0
  42. package/src/core/pipeline.js +256 -0
  43. package/src/core/postinstall.js +168 -0
  44. package/src/core/setup-env.js +86 -0
  45. package/src/core/setup-prompts.js +31 -0
  46. package/src/core/snapshot-hash.js +70 -0
  47. package/src/detectors/architecture.js +117 -0
  48. package/src/detectors/auth-deploy.js +51 -0
  49. package/src/detectors/database.js +127 -0
  50. package/src/detectors/tech-stack.js +180 -0
  51. package/src/generators/artifacts.js +44 -0
  52. package/src/generators/changes-markdown.js +72 -0
  53. package/src/generators/context-json.js +91 -0
  54. package/src/generators/context-markdown.js +571 -0
  55. package/src/generators/mermaid.js +59 -0
  56. package/src/index.js +13 -0
  57. package/src/scanner/change-detector.js +24 -0
  58. package/src/scanner/config-files.js +52 -0
  59. package/src/scanner/file-index.js +55 -0
  60. package/src/scanner/package-deps.js +32 -0
  61. package/src/scanner/repo-scanner.js +143 -0
  62. package/src/services/ai/background.js +87 -0
  63. package/src/services/ai/config.js +48 -0
  64. package/src/services/ai/enrich.js +87 -0
  65. package/src/services/ai/index.js +3 -0
  66. package/src/services/ai/prompt-loader.js +104 -0
  67. package/src/services/ai/prompt.js +42 -0
  68. package/src/services/ai/providers/groq.js +36 -0
  69. package/src/services/ai/providers/openai.js +32 -0
  70. package/src/services/ai/redact.js +33 -0
  71. package/src/services/ai/validate.js +70 -0
  72. package/src/watcher/watcher.js +128 -0
@@ -0,0 +1,28 @@
1
+ {
2
+ "ignore": ["node_modules", "dist", ".next", "coverage", ".git"],
3
+ "watch": true,
4
+ "autoGenerate": true,
5
+ "includeGitHistory": true,
6
+ "detectBugs": true,
7
+ "debounceMs": 2000,
8
+ "refreshIntervalMinutes": 15,
9
+ "trackChanges": true,
10
+ "maxTreeDepth": 4,
11
+ "gitCommitLimit": 20,
12
+ "ai": {
13
+ "enabled": true,
14
+ "provider": "openai",
15
+ "fallbackProvider": "groq",
16
+ "enrichContext": true,
17
+ "background": true,
18
+ "openai": {
19
+ "model": "gpt-4o-mini"
20
+ },
21
+ "groq": {
22
+ "model": "llama-3.3-70b-versatile"
23
+ },
24
+ "maxTokens": 4096,
25
+ "timeoutMs": 120000,
26
+ "promptsDir": ".contextforge/prompts"
27
+ }
28
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "ignore": ["node_modules", "dist", "build", ".next", "coverage", ".git"],
3
+ "watch": true,
4
+ "autoGenerate": true,
5
+ "includeGitHistory": true,
6
+ "detectBugs": true,
7
+ "debounceMs": 2000,
8
+ "refreshIntervalMinutes": 0,
9
+ "trackChanges": true,
10
+ "maxTreeDepth": 4,
11
+ "gitCommitLimit": 20,
12
+ "maxFileSizeBytes": 524288,
13
+ "installCursorRules": true,
14
+ "postinstallGenerate": true,
15
+ "postinstallWatch": true,
16
+ "postinstallOnNpmInstall": true,
17
+ "ai": {
18
+ "enabled": false,
19
+ "provider": "openai",
20
+ "fallbackProvider": "groq",
21
+ "enrichContext": true,
22
+ "background": true,
23
+ "openai": { "model": "gpt-4o-mini" },
24
+ "groq": { "model": "llama-3.3-70b-versatile" },
25
+ "maxTokens": 4096,
26
+ "timeoutMs": 120000,
27
+ "promptsDir": ".contextforge/prompts"
28
+ }
29
+ }
@@ -0,0 +1,50 @@
1
+ # ContextForge Prompts
2
+
3
+ Edit these files to change how AI enriches `context.md` — **no code changes needed**.
4
+
5
+ ## Files
6
+
7
+ | File | Purpose |
8
+ |------|---------|
9
+ | `system.md` | System message sent to OpenAI / Groq |
10
+ | `user-template.md` | User message template (repository analysis request) |
11
+ | `response-schema.md` | Required JSON keys the AI must return |
12
+ | `retry-addon.md` | Extra instructions when validation fails (retry) |
13
+
14
+ ## Placeholders (user-template.md)
15
+
16
+ | Placeholder | Replaced with |
17
+ |-------------|----------------|
18
+ | `{{SCAN_DATA}}` | Sanitized JSON scan snapshot |
19
+ | `{{RETRY_NOTE}}` | Retry instructions (empty on first attempt) |
20
+ | `{{PROJECT_NAME}}` | Project name from scan |
21
+
22
+ ## Per-project customization
23
+
24
+ On `contextforge init`, prompts are copied to:
25
+
26
+ ```
27
+ .contextforge/prompts/
28
+ ```
29
+
30
+ Edit files there for **this project only**. Config key:
31
+
32
+ ```json
33
+ "ai": {
34
+ "promptsDir": ".contextforge/prompts"
35
+ }
36
+ ```
37
+
38
+ Point to another folder:
39
+
40
+ ```json
41
+ "ai": {
42
+ "promptsDir": "my-custom-prompts"
43
+ }
44
+ ```
45
+
46
+ ## Tips
47
+
48
+ - Keep `response-schema.md` keys in sync with `src/services/ai/validate.js` required keys.
49
+ - Do not ask AI to read source files — only scan JSON is sent.
50
+ - After edits, run: `npx contextforge generate --ai`
package/.env.example ADDED
@@ -0,0 +1,73 @@
1
+ # =============================================================================
2
+ # ContextForge — Environment Variables
3
+ # =============================================================================
4
+ # 1. Copy this file: cp .env.example .env (Windows: copy .env.example .env)
5
+ # 2. Fill in your API keys below
6
+ # 3. Never commit .env (it is gitignored)
7
+ # =============================================================================
8
+
9
+ # -----------------------------------------------------------------------------
10
+ # OpenAI — https://platform.openai.com/api-keys
11
+ # -----------------------------------------------------------------------------
12
+ OPENAI_API_KEY=
13
+
14
+ # Optional model override (default in config: gpt-4o-mini)
15
+ OPENAI_MODEL=gpt-4o-mini
16
+
17
+ # -----------------------------------------------------------------------------
18
+ # Groq — https://console.groq.com/keys
19
+ # -----------------------------------------------------------------------------
20
+ GROQ_API_KEY=
21
+
22
+ # Optional model override (default in config: llama-3.3-70b-versatile)
23
+ GROQ_MODEL=llama-3.3-70b-versatile
24
+
25
+ # -----------------------------------------------------------------------------
26
+ # ContextForge AI settings
27
+ # -----------------------------------------------------------------------------
28
+ # Primary provider when both keys are set: openai | groq
29
+ CONTEXTFORGE_AI_PROVIDER=openai
30
+
31
+ # Enable AI enrichment (used by generate / watch / npm install auto-setup)
32
+ CONTEXTFORGE_AI_ENABLED=true
33
+
34
+ # Alternate variable names (optional aliases)
35
+ # CONTEXTFORGE_OPENAI_API_KEY=
36
+ # CONTEXTFORGE_GROQ_API_KEY=
37
+
38
+ # -----------------------------------------------------------------------------
39
+ # npm install — auto-detect & start (no manual init required)
40
+ # -----------------------------------------------------------------------------
41
+ # Master switch: after npm install → create .contextforge + context.md + watch
42
+ CONTEXTFORGE_AUTO_START=true
43
+
44
+ # Run first context scan on install
45
+ CONTEXTFORGE_POSTINSTALL_GENERATE=true
46
+
47
+ # Start background watcher on install (updates on file save + timer below)
48
+ CONTEXTFORGE_POSTINSTALL_WATCH=true
49
+
50
+ # Disable all postinstall automation (same as AUTO_START=false)
51
+ # CONTEXTFORGE_SKIP_POSTINSTALL=1
52
+
53
+ # Allow postinstall in CI (skipped by default when CI=true)
54
+ # CONTEXTFORGE_RUN_IN_CI=1
55
+
56
+ # -----------------------------------------------------------------------------
57
+ # Watch — auto-refresh timer (minutes). 0 = only when you save files.
58
+ # -----------------------------------------------------------------------------
59
+ CONTEXTFORGE_REFRESH_INTERVAL_MINUTES=15
60
+
61
+ # Same as above (alias)
62
+ # CONTEXTFORGE_WATCH_INTERVAL_MINUTES=15
63
+
64
+ # Or use seconds instead of minutes (e.g. 300 = every 5 minutes)
65
+ # CONTEXTFORGE_REFRESH_INTERVAL_SECONDS=300
66
+
67
+ # Wait this long after a file save before regenerating (milliseconds)
68
+ # CONTEXTFORGE_DEBOUNCE_MS=2000
69
+
70
+ # -----------------------------------------------------------------------------
71
+ # Node (optional)
72
+ # -----------------------------------------------------------------------------
73
+ # NODE_ENV=development
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ContextForge 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,223 @@
1
+ # ContextForge
2
+
3
+ **Persistent AI memory for your repository.** Install once with `npm install` — ContextForge scans your codebase in the background and keeps `.contextforge/context.md` (and a Cursor rule) up to date for ChatGPT, Claude, and Cursor.
4
+
5
+ ## Install (npm — works like local)
6
+
7
+ In **any** Node.js 18+ project:
8
+
9
+ ```bash
10
+ npm install -D contextforge-cli-ai-prompt-pirates
11
+ ```
12
+
13
+ That is the only required step. On install, ContextForge automatically:
14
+
15
+ 1. Creates `.env` from `.env.example` (if you do not have one)
16
+ 2. Creates `.contextforge/` and generates `context.md`
17
+ 3. Writes `.cursor/rules/contextforge.mdc` for Cursor
18
+ 4. Starts a background watcher (`watch --daemon`) for file saves + optional timer
19
+
20
+ You should see:
21
+
22
+ ```text
23
+ [contextforge] npm install → auto setup starting in background
24
+ ```
25
+
26
+ Verify after ~10–30 seconds:
27
+
28
+ ```bash
29
+ npx contextforge-cli-ai-prompt-pirates doctor
30
+ # or
31
+ npx cfpirates doctor
32
+ ```
33
+
34
+ Logs: `.contextforge/logs/postinstall.log` · Stop watcher: `npx cfpirates stop`
35
+
36
+ ### Optional: AI enrichment
37
+
38
+ Edit `.env` in your project (created on first install):
39
+
40
+ ```env
41
+ OPENAI_API_KEY=sk-...
42
+ GROQ_API_KEY=gsk_...
43
+ CONTEXTFORGE_AI_PROVIDER=openai
44
+ CONTEXTFORGE_AI_ENABLED=true
45
+ CONTEXTFORGE_REFRESH_INTERVAL_MINUTES=15
46
+ ```
47
+
48
+ Regenerate with AI: `npx cfpirates generate`
49
+
50
+ ### Disable auto-start on install
51
+
52
+ ```env
53
+ CONTEXTFORGE_AUTO_START=false
54
+ ```
55
+
56
+ Or:
57
+
58
+ ```json
59
+ "contextforge": { "postinstall": false }
60
+ ```
61
+
62
+ Or: `CONTEXTFORGE_SKIP_POSTINSTALL=1`
63
+
64
+ ### Important: npm install flags
65
+
66
+ | Command | Auto-setup |
67
+ |---------|------------|
68
+ | `npm install` | Yes |
69
+ | `npm install --ignore-scripts` | **No** (npm skips postinstall) |
70
+ | `npm ci` | Yes (unless ignore-scripts) |
71
+
72
+ ## Local development (this repo)
73
+
74
+ ```bash
75
+ git clone <your-repo>
76
+ cd contextforge-cli-ai-prompt-pirates # your repo folder name may differ
77
+ npm install
78
+ npm test
79
+ npx cfpirates doctor
80
+ ```
81
+
82
+ Uses the same `postinstall` hook as published users.
83
+
84
+ ## Manual commands (optional)
85
+
86
+ ```bash
87
+ npx cfpirates init # full setup + tips
88
+ npx cfpirates generate # regenerate on demand
89
+ npx cfpirates watch # foreground watcher
90
+ npx cfpirates changes # change history
91
+ npx cfpirates prompt # export context for AI chat
92
+ ```
93
+
94
+ ## Output layout
95
+
96
+ ```
97
+ .contextforge/
98
+ ├── config.json
99
+ ├── context.md ← full project memory for AI
100
+ ├── CHANGES.md
101
+ ├── context.json
102
+ ├── architecture.json
103
+ ├── git-insights.json
104
+ ├── bugs-report.json
105
+ ├── cache/
106
+ └── logs/
107
+ .cursor/rules/
108
+ └── contextforge.mdc ← Cursor auto-rule (synced on generate)
109
+ ```
110
+
111
+ ## CLI commands
112
+
113
+ | Command | Description |
114
+ |---------|-------------|
115
+ | `init` | Create `.contextforge/`, config, first context |
116
+ | `generate` | Scan repo and regenerate artifacts |
117
+ | `watch` | Watch files + optional timer refresh |
118
+ | `changes` | Show change history between runs |
119
+ | `stop` | Stop background watcher (`watch --daemon`) |
120
+ | `doctor` | Health check |
121
+ | `summary` | Short stdout summary |
122
+ | `prompt` | Export context block for AI prompts |
123
+
124
+ ```bash
125
+ npx cfpirates generate --cwd /path/to/project
126
+ npx cfpirates watch --verbose
127
+ npx cfpirates watch --interval 15
128
+ npx cfpirates generate --ai
129
+ npx cfpirates generate --no-ai
130
+ ```
131
+
132
+ ## Environment variables (`.env`)
133
+
134
+ | Variable | Default | Purpose |
135
+ |----------|---------|---------|
136
+ | `CONTEXTFORGE_AUTO_START` | `true` | Auto setup on `npm install` |
137
+ | `CONTEXTFORGE_POSTINSTALL_GENERATE` | `true` | Create `context.md` on install |
138
+ | `CONTEXTFORGE_POSTINSTALL_WATCH` | `true` | Start background watch on install |
139
+ | `CONTEXTFORGE_SKIP_POSTINSTALL` | — | Set `1` to disable all install automation |
140
+ | `CONTEXTFORGE_AI_ENABLED` | — | `true` / `false` overrides config |
141
+ | `CONTEXTFORGE_AI_PROVIDER` | `openai` | `openai` or `groq` |
142
+ | `CONTEXTFORGE_REFRESH_INTERVAL_MINUTES` | `0` | Timer while watch runs (`0` = file saves only) |
143
+ | `OPENAI_API_KEY` / `GROQ_API_KEY` | — | AI enrichment |
144
+
145
+ Copy from `.env.example` in your project after install.
146
+
147
+ ## Cursor integration
148
+
149
+ ContextForge syncs **one rule file**: `.cursor/rules/contextforge.mdc` (includes stack summary + link to full `context.md`).
150
+
151
+ Or add manually:
152
+
153
+ > Read `.contextforge/context.md` before coding in this repository.
154
+
155
+ ## Configuration
156
+
157
+ `.contextforge/config.json` (created automatically):
158
+
159
+ ```json
160
+ {
161
+ "watch": true,
162
+ "autoGenerate": true,
163
+ "installCursorRules": true,
164
+ "postinstallGenerate": true,
165
+ "postinstallWatch": true,
166
+ "refreshIntervalMinutes": 0,
167
+ "ai": {
168
+ "enabled": false,
169
+ "provider": "openai",
170
+ "background": true
171
+ }
172
+ }
173
+ ```
174
+
175
+ `.env` overrides timer, debounce, and AI provider. Run `npx cfpirates init --force` to merge new config fields.
176
+
177
+ ## Programmatic API
178
+
179
+ ```js
180
+ import { runPipeline, loadConfig } from 'contextforge-cli-ai-prompt-pirates';
181
+
182
+ await runPipeline('/path/to/project', { verbose: true });
183
+ ```
184
+
185
+ ## Security
186
+
187
+ - Static scan runs locally
188
+ - AI sends aggregated metadata only (not `.env` or full source)
189
+ - API keys stay in your `.env` (never published with the package)
190
+
191
+ ## Publish to npm
192
+
193
+ **Before publish** (maintainers):
194
+
195
+ ```bash
196
+ npm test
197
+ npm run verify:pack
198
+ npm publish --access public
199
+ ```
200
+
201
+ Full guide: **[PUBLISHING.md](./PUBLISHING.md)**
202
+
203
+ **After publish**, users only need:
204
+
205
+ ```bash
206
+ npm install -D contextforge-cli-ai-prompt-pirates-cli-ai-prompt-pirates
207
+ ```
208
+
209
+ No `file:` link or local path required.
210
+
211
+ ## Troubleshooting
212
+
213
+ | Problem | Fix |
214
+ |---------|-----|
215
+ | No `.contextforge` after install | Do not use `--ignore-scripts`; check `CONTEXTFORGE_AUTO_START` |
216
+ | Works locally, not from npm | Publish **contextforge-cli-ai-prompt-pirates@0.4.0**; run `npm run verify:pack` |
217
+ | Old name `contextforge` blocked on npm | Use **contextforge-cli-ai-prompt-pirates** (name `context-forge` was taken) |
218
+ | Watch keeps running | `npx cfpirates stop` |
219
+ | No Git history in context | Install Git and add to PATH |
220
+
221
+ ## License
222
+
223
+ MIT
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { loadProjectEnv } from '../src/core/env.js';
6
+ import { runCli } from '../src/cli/index.js';
7
+
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
+ await loadProjectEnv(path.join(__dirname, '..'));
10
+
11
+ runCli(process.argv).catch((err) => {
12
+ console.error(err.message || err);
13
+ process.exit(1);
14
+ });
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { loadProjectEnv } from '../src/core/env.js';
5
+ import { runPostinstall } from '../src/core/postinstall.js';
6
+
7
+ const projectRoot = process.argv[2];
8
+ if (!projectRoot) {
9
+ process.exit(1);
10
+ }
11
+
12
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
13
+ await loadProjectEnv(path.join(__dirname, '..'));
14
+ await runPostinstall(path.resolve(projectRoot));
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * npm lifecycle: runs after `npm install` in the consuming project (INIT_CWD).
4
+ * Spawns a background worker — does not block install.
5
+ */
6
+ import { loadProjectEnv } from '../src/core/env.js';
7
+ import {
8
+ resolveInstallProjectRoot,
9
+ shouldRunPostinstall,
10
+ spawnPostinstallWorker,
11
+ } from '../src/core/postinstall.js';
12
+
13
+ const projectRoot = resolveInstallProjectRoot();
14
+ await loadProjectEnv(projectRoot);
15
+
16
+ if (await shouldRunPostinstall(projectRoot)) {
17
+ console.log('');
18
+ console.log('[contextforge] npm install → auto setup starting in background');
19
+ console.log(' • .contextforge/ + context.md');
20
+ console.log(' • .cursor/rules/contextforge.mdc');
21
+ console.log(' • background watch (file saves + timer from .env)');
22
+ console.log(' • log: .contextforge/logs/postinstall.log');
23
+ console.log(' • stop watch: npx contextforge stop');
24
+ console.log('');
25
+ spawnPostinstallWorker(projectRoot);
26
+ }
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "contextforge-cli-ai-prompt-pirates",
3
+ "version": "0.4.0",
4
+ "description": "Background AI context engine — auto-generates context.md on npm install for Cursor, Claude, and ChatGPT",
5
+ "type": "module",
6
+ "main": "./src/index.js",
7
+ "exports": {
8
+ ".": "./src/index.js"
9
+ },
10
+ "bin": {
11
+ "contextforge-cli-ai-prompt-pirates": "./bin/contextforge.js",
12
+ "cfpirates": "./bin/contextforge.js"
13
+ },
14
+ "files": [
15
+ "bin",
16
+ "src",
17
+ "prompts",
18
+ "README.md",
19
+ "LICENSE",
20
+ ".env.example",
21
+ ".contextforge/config.example.json",
22
+ ".contextforge/config.ai.example.json"
23
+ ],
24
+ "scripts": {
25
+ "test": "vitest run",
26
+ "test:watch": "vitest",
27
+ "generate": "node bin/contextforge.js generate --cwd .",
28
+ "watch": "node bin/contextforge.js watch --cwd .",
29
+ "postinstall": "node bin/postinstall.js",
30
+ "prepublishOnly": "npm test",
31
+ "verify:pack": "node scripts/verify-pack.js"
32
+ },
33
+ "keywords": [
34
+ "ai",
35
+ "context",
36
+ "cursor",
37
+ "claude",
38
+ "chatgpt",
39
+ "copilot",
40
+ "repository",
41
+ "documentation",
42
+ "developer-tools",
43
+ "contextforge",
44
+ "postinstall"
45
+ ],
46
+ "author": "",
47
+ "license": "MIT",
48
+ "engines": {
49
+ "node": ">=18.0.0"
50
+ },
51
+ "dependencies": {
52
+ "@babel/parser": "^7.26.3",
53
+ "chokidar": "^4.0.3",
54
+ "commander": "^13.1.0",
55
+ "fs-extra": "^11.3.0",
56
+ "glob": "^11.0.1",
57
+ "ignore": "^7.0.3",
58
+ "dotenv": "^16.4.7",
59
+ "openai": "^4.77.0",
60
+ "simple-git": "^3.27.0"
61
+ },
62
+ "devDependencies": {
63
+ "vitest": "^3.0.5"
64
+ }
65
+ }
@@ -0,0 +1,50 @@
1
+ # ContextForge Prompts
2
+
3
+ Edit these files to change how AI enriches `context.md` — **no code changes needed**.
4
+
5
+ ## Files
6
+
7
+ | File | Purpose |
8
+ |------|---------|
9
+ | `system.md` | System message sent to OpenAI / Groq |
10
+ | `user-template.md` | User message template (repository analysis request) |
11
+ | `response-schema.md` | Required JSON keys the AI must return |
12
+ | `retry-addon.md` | Extra instructions when validation fails (retry) |
13
+
14
+ ## Placeholders (user-template.md)
15
+
16
+ | Placeholder | Replaced with |
17
+ |-------------|----------------|
18
+ | `{{SCAN_DATA}}` | Sanitized JSON scan snapshot |
19
+ | `{{RETRY_NOTE}}` | Retry instructions (empty on first attempt) |
20
+ | `{{PROJECT_NAME}}` | Project name from scan |
21
+
22
+ ## Per-project customization
23
+
24
+ On `contextforge init`, prompts are copied to:
25
+
26
+ ```
27
+ .contextforge/prompts/
28
+ ```
29
+
30
+ Edit files there for **this project only**. Config key:
31
+
32
+ ```json
33
+ "ai": {
34
+ "promptsDir": ".contextforge/prompts"
35
+ }
36
+ ```
37
+
38
+ Point to another folder:
39
+
40
+ ```json
41
+ "ai": {
42
+ "promptsDir": "my-custom-prompts"
43
+ }
44
+ ```
45
+
46
+ ## Tips
47
+
48
+ - Keep `response-schema.md` keys in sync with `src/services/ai/validate.js` required keys.
49
+ - Do not ask AI to read source files — only scan JSON is sent.
50
+ - After edits, run: `npx contextforge generate --ai`
@@ -0,0 +1,22 @@
1
+ Return JSON with exactly these keys:
2
+
3
+ ```json
4
+ {
5
+ "executiveSummary": "2-4 sentences overview of the project purpose and stack",
6
+ "techStackNarrative": "paragraph combining frontend, backend, database, and tools",
7
+ "architectureDeepDive": "detailed architecture explanation with folder/layer roles",
8
+ "apiAndDataFlow": "how HTTP/API requests move from client to database",
9
+ "businessLogicAnalysis": "where business logic lives; key modules and patterns",
10
+ "databaseAnalysis": "ORM/models, collections, relationships",
11
+ "authenticationNotes": "auth strategy, JWT/session/OAuth, middleware",
12
+ "deploymentNotes": "Docker, Vercel, env vars, how to run in production",
13
+ "gitEvolution": "what recent git activity suggests (or not a git repo)",
14
+ "importantRules": ["rule 1 for AI assistants", "rule 2"],
15
+ "codingConventions": ["convention 1", "convention 2"],
16
+ "possibleIssues": ["issue 1 from scan/heuristics"],
17
+ "suggestedImprovements": ["actionable improvement 1"]
18
+ }
19
+ ```
20
+
21
+ - `importantRules`, `codingConventions`, `possibleIssues`, `suggestedImprovements` must be JSON **arrays of strings**.
22
+ - All other fields are strings (can be multi-sentence).
@@ -0,0 +1 @@
1
+ **RETRY:** Your previous response was invalid or incomplete. Output complete valid JSON with ALL required keys. Do not omit any field. Do not invent technologies absent from the scan.
@@ -0,0 +1,10 @@
1
+ You are ContextForge, an expert software architect and technical writer.
2
+
3
+ Your job is to analyze repository scan data and produce accurate, actionable documentation for AI coding assistants (Cursor, Claude, ChatGPT, Copilot).
4
+
5
+ Rules:
6
+ - Output ONLY valid JSON (no markdown code fences, no commentary outside JSON).
7
+ - Never invent frameworks, libraries, or files not supported by the scan data.
8
+ - Be specific: name folders, patterns, and layers that appear in the scan.
9
+ - Write rules that help AI assistants write code consistent with this project.
10
+ - If data is missing, say "not detected" rather than guessing.
@@ -0,0 +1,22 @@
1
+ Analyze the repository scan below and produce detailed AI-ready project context for **{{PROJECT_NAME}}**.
2
+
3
+ {{RETRY_NOTE}}
4
+
5
+ ## Analysis goals
6
+
7
+ 1. Explain architecture and how requests/data flow through the system.
8
+ 2. Describe where business logic lives (services, controllers, components).
9
+ 3. Summarize database/ORM usage and relationships.
10
+ 4. Document authentication and deployment approach.
11
+ 5. List **importantRules** AI assistants must follow when editing this codebase.
12
+ 6. Note risks and improvements based only on scan evidence.
13
+
14
+ ## Scan data (JSON)
15
+
16
+ ```json
17
+ {{SCAN_DATA}}
18
+ ```
19
+
20
+ Return a single JSON object matching the schema in your instructions. Use only facts from the scan.
21
+
22
+ Be **thorough**: each text field should be 3–6 sentences with concrete file paths, library names, and patterns from the scan. `importantRules` should have at least 5 actionable items for developers and AI assistants.