@a-company/paradigm 1.5.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/README.md +142 -0
- package/dist/accept-orchestration-CWZNCGZX.js +188 -0
- package/dist/agents-suggest-35LIQKDH.js +83 -0
- package/dist/aggregate-W7Q6VIM2.js +88 -0
- package/dist/auto-IU7VN55K.js +470 -0
- package/dist/beacon-B47XSTL7.js +251 -0
- package/dist/chunk-2M6OSOIG.js +1302 -0
- package/dist/chunk-4NCFWYGG.js +110 -0
- package/dist/chunk-5C4SGQKH.js +705 -0
- package/dist/chunk-5GOA7WYD.js +1095 -0
- package/dist/chunk-5JGJACDU.js +37 -0
- package/dist/chunk-6QC3YGB6.js +114 -0
- package/dist/chunk-753RICFF.js +325 -0
- package/dist/chunk-AD2LSCHB.js +1595 -0
- package/dist/chunk-CHSHON3O.js +669 -0
- package/dist/chunk-ELLR7WP6.js +3175 -0
- package/dist/chunk-ILOWBJRC.js +12 -0
- package/dist/chunk-IRKUEJVW.js +405 -0
- package/dist/chunk-MC7XC7XQ.js +533 -0
- package/dist/chunk-MO4EEYFW.js +38 -0
- package/dist/chunk-MQWH7PFI.js +13366 -0
- package/dist/chunk-N6PJAPDE.js +364 -0
- package/dist/chunk-PBHIFAL4.js +259 -0
- package/dist/chunk-PMXRGPRQ.js +305 -0
- package/dist/chunk-PW2EXJQT.js +689 -0
- package/dist/chunk-TAP5N3HH.js +245 -0
- package/dist/chunk-THFVK5AE.js +148 -0
- package/dist/chunk-UM54F7G5.js +1533 -0
- package/dist/chunk-UUZ2DMG5.js +185 -0
- package/dist/chunk-WS5KM7OL.js +780 -0
- package/dist/chunk-YDNKXH4Z.js +2316 -0
- package/dist/chunk-YO6DVTL7.js +99 -0
- package/dist/claude-SUYNN72C.js +362 -0
- package/dist/claude-cli-OF43XAO3.js +276 -0
- package/dist/claude-code-PW6SKD2M.js +126 -0
- package/dist/claude-code-teams-JLZ5IXB6.js +199 -0
- package/dist/constellation-K3CIQCHI.js +225 -0
- package/dist/cost-AEK6R7HK.js +174 -0
- package/dist/cost-KYXIQ62X.js +93 -0
- package/dist/cursor-cli-IHJMPRCW.js +269 -0
- package/dist/cursorrules-KI5QWHIX.js +84 -0
- package/dist/diff-AJJ5H6HV.js +125 -0
- package/dist/dist-7MPIRMTZ-IOQOREMZ.js +10866 -0
- package/dist/dist-NHJQVVUW.js +68 -0
- package/dist/dist-ZEMSQV74.js +20 -0
- package/dist/doctor-6Y6L6HEB.js +11 -0
- package/dist/echo-VYZW3OTT.js +248 -0
- package/dist/export-R4FJ5NOH.js +38 -0
- package/dist/history-EVO3L6SC.js +277 -0
- package/dist/hooks-MBWE4ILT.js +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +568 -0
- package/dist/lint-HXKTWRNO.js +316 -0
- package/dist/manual-Y3QOXWYA.js +204 -0
- package/dist/mcp.js +14745 -0
- package/dist/orchestrate-4ZH5GUQH.js +323 -0
- package/dist/probe-OYCP4JYG.js +151 -0
- package/dist/promote-Z52ZJTJU.js +181 -0
- package/dist/providers-4PGPZEWP.js +104 -0
- package/dist/remember-6VZ74B7E.js +77 -0
- package/dist/ripple-SBQOSTZD.js +215 -0
- package/dist/sentinel-LCFD56OJ.js +43 -0
- package/dist/server-F5ITNK6T.js +9846 -0
- package/dist/server-T6WIFYRQ.js +16076 -0
- package/dist/setup-DF4F3ICN.js +25 -0
- package/dist/setup-JHBPZAG7.js +296 -0
- package/dist/shift-HKIAP4ZN.js +226 -0
- package/dist/snapshot-GTVPRYZG.js +62 -0
- package/dist/spawn-BJRQA2NR.js +196 -0
- package/dist/summary-H6J6N6PJ.js +140 -0
- package/dist/switch-6EANJ7O6.js +232 -0
- package/dist/sync-BEOCW7TZ.js +11 -0
- package/dist/team-NWP2KJAB.js +32 -0
- package/dist/test-MA5TWJQV.js +934 -0
- package/dist/thread-JCJVRUQR.js +258 -0
- package/dist/triage-ETVXXFMV.js +1880 -0
- package/dist/tutorial-L5Q3ZDHK.js +666 -0
- package/dist/university-R2WDQLSI.js +40 -0
- package/dist/upgrade-5B3YGGC6.js +550 -0
- package/dist/validate-F3YHBCRZ.js +39 -0
- package/dist/validate-QEEY6KFS.js +64 -0
- package/dist/watch-4LT4O6K7.js +123 -0
- package/dist/watch-6IIWPWDN.js +111 -0
- package/dist/wisdom-LRM4FFCH.js +319 -0
- package/package.json +68 -0
- package/templates/paradigm/config.yaml +175 -0
- package/templates/paradigm/docs/commands.md +727 -0
- package/templates/paradigm/docs/decisions/000-template.md +47 -0
- package/templates/paradigm/docs/decisions/README.md +26 -0
- package/templates/paradigm/docs/error-patterns.md +215 -0
- package/templates/paradigm/docs/patterns.md +358 -0
- package/templates/paradigm/docs/queries.md +200 -0
- package/templates/paradigm/docs/troubleshooting.md +477 -0
- package/templates/paradigm/echoes.yaml +25 -0
- package/templates/paradigm/prompts/add-feature.md +152 -0
- package/templates/paradigm/prompts/add-gate.md +117 -0
- package/templates/paradigm/prompts/debug-auth.md +174 -0
- package/templates/paradigm/prompts/implement-ftux.md +722 -0
- package/templates/paradigm/prompts/implement-sandbox.md +651 -0
- package/templates/paradigm/prompts/read-docs.md +84 -0
- package/templates/paradigm/prompts/refactor.md +106 -0
- package/templates/paradigm/prompts/run-e2e-tests.md +340 -0
- package/templates/paradigm/prompts/trace-flow.md +202 -0
- package/templates/paradigm/prompts/validate-portals.md +279 -0
- package/templates/paradigm/specs/context-tracking.md +200 -0
- package/templates/paradigm/specs/context.md +461 -0
- package/templates/paradigm/specs/disciplines.md +413 -0
- package/templates/paradigm/specs/history.md +339 -0
- package/templates/paradigm/specs/logger.md +303 -0
- package/templates/paradigm/specs/navigator.md +236 -0
- package/templates/paradigm/specs/purpose.md +265 -0
- package/templates/paradigm/specs/scan.md +177 -0
- package/templates/paradigm/specs/symbols.md +451 -0
- package/templates/paradigm/specs/wisdom.md +294 -0
|
@@ -0,0 +1,2316 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
parseParadigmConfig
|
|
4
|
+
} from "./chunk-YO6DVTL7.js";
|
|
5
|
+
|
|
6
|
+
// src/core/ide-adapters/index.ts
|
|
7
|
+
import * as fs6 from "fs";
|
|
8
|
+
import * as path6 from "path";
|
|
9
|
+
|
|
10
|
+
// src/core/ide-adapters/cursor.ts
|
|
11
|
+
import * as fs from "fs";
|
|
12
|
+
import * as path from "path";
|
|
13
|
+
import * as os2 from "os";
|
|
14
|
+
import * as yaml from "js-yaml";
|
|
15
|
+
|
|
16
|
+
// src/core/ide-adapters/base.ts
|
|
17
|
+
import * as os from "os";
|
|
18
|
+
function generateHeader(projectName, ideName) {
|
|
19
|
+
const lines = [];
|
|
20
|
+
lines.push(`# ${projectName} - Paradigm Context`);
|
|
21
|
+
lines.push("");
|
|
22
|
+
lines.push(`Generated for ${ideName} by Paradigm.`);
|
|
23
|
+
lines.push("");
|
|
24
|
+
return lines.join("\n");
|
|
25
|
+
}
|
|
26
|
+
function generateOverview(config) {
|
|
27
|
+
const lines = [];
|
|
28
|
+
if (config["agent-guidelines"]?.overview) {
|
|
29
|
+
lines.push("## Overview");
|
|
30
|
+
lines.push("");
|
|
31
|
+
lines.push(config["agent-guidelines"].overview);
|
|
32
|
+
lines.push("");
|
|
33
|
+
}
|
|
34
|
+
if (config["agent-guidelines"]?.["how-to-use"]?.length) {
|
|
35
|
+
lines.push("## How to Use Paradigm");
|
|
36
|
+
lines.push("");
|
|
37
|
+
for (const instruction of config["agent-guidelines"]["how-to-use"]) {
|
|
38
|
+
lines.push(`- ${instruction}`);
|
|
39
|
+
}
|
|
40
|
+
lines.push("");
|
|
41
|
+
}
|
|
42
|
+
return lines.join("\n");
|
|
43
|
+
}
|
|
44
|
+
function generateSymbolSystem(config) {
|
|
45
|
+
const lines = [];
|
|
46
|
+
lines.push("## Symbol System");
|
|
47
|
+
lines.push("");
|
|
48
|
+
lines.push("Use these prefixes to reference project elements:");
|
|
49
|
+
lines.push("");
|
|
50
|
+
lines.push("| Symbol | Name | Description |");
|
|
51
|
+
lines.push("|--------|------|-------------|");
|
|
52
|
+
const symbolSystem = config["symbol-system"];
|
|
53
|
+
if (symbolSystem) {
|
|
54
|
+
for (const [prefix, def] of Object.entries(symbolSystem)) {
|
|
55
|
+
lines.push(`| \`${prefix}\` | ${def.name} | ${def.description} |`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
lines.push("");
|
|
59
|
+
lines.push("See `.paradigm/specs/symbols.md` for complete reference.");
|
|
60
|
+
lines.push("");
|
|
61
|
+
return lines.join("\n");
|
|
62
|
+
}
|
|
63
|
+
function generateLoggingRules(config) {
|
|
64
|
+
const lines = [];
|
|
65
|
+
if (!config.logging?.enforce) {
|
|
66
|
+
return "";
|
|
67
|
+
}
|
|
68
|
+
lines.push("## Paradigm Logging");
|
|
69
|
+
lines.push("");
|
|
70
|
+
lines.push("**IMPORTANT:** Use the Paradigm logger instead of raw console.log/print.");
|
|
71
|
+
lines.push("");
|
|
72
|
+
lines.push("```");
|
|
73
|
+
lines.push("// Use this pattern:");
|
|
74
|
+
lines.push("log.component('#login-handler').info('Starting login', { email });");
|
|
75
|
+
lines.push("log.component('#database').debug('Query executed', { duration });");
|
|
76
|
+
lines.push("log.gate('^authenticated').warn('Access denied', { userId });");
|
|
77
|
+
lines.push("log.signal('!login-success').info('User authenticated');");
|
|
78
|
+
lines.push("```");
|
|
79
|
+
lines.push("");
|
|
80
|
+
if (config.logging["symbol-mapping"]) {
|
|
81
|
+
lines.push("### Symbol Mapping by Directory");
|
|
82
|
+
lines.push("");
|
|
83
|
+
lines.push("| Directory | Symbol | Logger Method |");
|
|
84
|
+
lines.push("|-----------|--------|---------------|");
|
|
85
|
+
for (const [pattern, symbol] of Object.entries(config.logging["symbol-mapping"])) {
|
|
86
|
+
const method = getLogMethodForSymbol(symbol);
|
|
87
|
+
lines.push(`| \`${pattern}\` | \`${symbol}\` | \`log.${method}()\` |`);
|
|
88
|
+
}
|
|
89
|
+
lines.push("");
|
|
90
|
+
}
|
|
91
|
+
lines.push("See `.paradigm/specs/logger.md` for full specification.");
|
|
92
|
+
lines.push("");
|
|
93
|
+
return lines.join("\n");
|
|
94
|
+
}
|
|
95
|
+
function getLogMethodForSymbol(symbol) {
|
|
96
|
+
const mapping = {
|
|
97
|
+
"#": "component",
|
|
98
|
+
"^": "gate",
|
|
99
|
+
"!": "signal",
|
|
100
|
+
"$": "flow",
|
|
101
|
+
"~": "aspect",
|
|
102
|
+
// v1 backwards compat — all map to component() in v2
|
|
103
|
+
"@": "component",
|
|
104
|
+
"%": "component",
|
|
105
|
+
"&": "component"
|
|
106
|
+
};
|
|
107
|
+
return mapping[symbol] || "raw";
|
|
108
|
+
}
|
|
109
|
+
function generateScanProtocol(config) {
|
|
110
|
+
if (!config.scan?.enabled) {
|
|
111
|
+
return "";
|
|
112
|
+
}
|
|
113
|
+
const lines = [];
|
|
114
|
+
lines.push("## Paradigm Scan");
|
|
115
|
+
lines.push("");
|
|
116
|
+
lines.push('When the user says "**paradigm scan**" with an image:');
|
|
117
|
+
lines.push("");
|
|
118
|
+
lines.push("1. Analyze the image for UI elements");
|
|
119
|
+
lines.push("2. Cross-reference with `.paradigm/scan-index.json`");
|
|
120
|
+
lines.push("3. Return structured mapping of visual elements to code");
|
|
121
|
+
lines.push("");
|
|
122
|
+
lines.push("| Mode | Use Case |");
|
|
123
|
+
lines.push("|------|----------|");
|
|
124
|
+
lines.push("| `paradigm scan` | Map any image to code |");
|
|
125
|
+
lines.push("| `paradigm scan ui` | Screenshot of running app |");
|
|
126
|
+
lines.push("| `paradigm scan design` | Mockup - gap analysis |");
|
|
127
|
+
lines.push("| `paradigm scan error` | Error screenshot |");
|
|
128
|
+
lines.push("");
|
|
129
|
+
lines.push("See `.paradigm/specs/scan.md` for full protocol.");
|
|
130
|
+
lines.push("");
|
|
131
|
+
return lines.join("\n");
|
|
132
|
+
}
|
|
133
|
+
function generateConventions(config) {
|
|
134
|
+
if (!config.conventions?.length) {
|
|
135
|
+
return "";
|
|
136
|
+
}
|
|
137
|
+
const lines = [];
|
|
138
|
+
lines.push("## Conventions");
|
|
139
|
+
lines.push("");
|
|
140
|
+
for (const convention of config.conventions) {
|
|
141
|
+
lines.push(`- ${convention}`);
|
|
142
|
+
}
|
|
143
|
+
lines.push("");
|
|
144
|
+
return lines.join("\n");
|
|
145
|
+
}
|
|
146
|
+
function generateUpdateRules(config) {
|
|
147
|
+
if (!config["agent-guidelines"]?.["update-rules"]?.length) {
|
|
148
|
+
return "";
|
|
149
|
+
}
|
|
150
|
+
const lines = [];
|
|
151
|
+
lines.push("## When to Update Paradigm Files");
|
|
152
|
+
lines.push("");
|
|
153
|
+
for (const rule of config["agent-guidelines"]["update-rules"]) {
|
|
154
|
+
lines.push(`- ${rule}`);
|
|
155
|
+
}
|
|
156
|
+
lines.push("");
|
|
157
|
+
return lines.join("\n");
|
|
158
|
+
}
|
|
159
|
+
function generateCommandsReference() {
|
|
160
|
+
const lines = [];
|
|
161
|
+
lines.push("## Paradigm Commands");
|
|
162
|
+
lines.push("");
|
|
163
|
+
lines.push("| Command | Description |");
|
|
164
|
+
lines.push("|---------|-------------|");
|
|
165
|
+
lines.push("| `paradigm init` | Initialize Paradigm in a project |");
|
|
166
|
+
lines.push("| `paradigm sync` | Regenerate IDE instruction files |");
|
|
167
|
+
lines.push("| `paradigm index` | Generate scan index |");
|
|
168
|
+
lines.push("| `paradigm doctor` | Health check |");
|
|
169
|
+
lines.push("| `paradigm status` | Show project status |");
|
|
170
|
+
lines.push("| `paradigm watch` | Auto-sync on changes |");
|
|
171
|
+
lines.push("");
|
|
172
|
+
lines.push("See `.paradigm/docs/commands.md` for full reference.");
|
|
173
|
+
lines.push("");
|
|
174
|
+
return lines.join("\n");
|
|
175
|
+
}
|
|
176
|
+
function generateNavigationSection(_config) {
|
|
177
|
+
const lines = [];
|
|
178
|
+
lines.push("## Paradigm Navigation");
|
|
179
|
+
lines.push("");
|
|
180
|
+
lines.push("Before exploring this codebase:");
|
|
181
|
+
lines.push("");
|
|
182
|
+
lines.push("1. Read `.paradigm/navigator.yaml` for structure map");
|
|
183
|
+
lines.push("2. Query by symbol - lookup paths directly");
|
|
184
|
+
lines.push("3. Respect skip patterns (node_modules, dist, etc.)");
|
|
185
|
+
lines.push("");
|
|
186
|
+
lines.push("### Exploration Protocol");
|
|
187
|
+
lines.push("");
|
|
188
|
+
lines.push("**INSTEAD OF:** Broad exploration (expensive token usage)");
|
|
189
|
+
lines.push("");
|
|
190
|
+
lines.push("**DO THIS:**");
|
|
191
|
+
lines.push("1. Read `.paradigm/navigator.yaml` for structure map");
|
|
192
|
+
lines.push("2. Find relevant symbol \u2192 go to path");
|
|
193
|
+
lines.push("3. Read only needed files");
|
|
194
|
+
lines.push("");
|
|
195
|
+
lines.push("### Task Recipes");
|
|
196
|
+
lines.push("");
|
|
197
|
+
lines.push("**Adding a feature:**");
|
|
198
|
+
lines.push("1. Check `navigator.yaml` \u2192 `structure.features.paths`");
|
|
199
|
+
lines.push("2. Read existing feature as template");
|
|
200
|
+
lines.push("3. Create in same location");
|
|
201
|
+
lines.push("");
|
|
202
|
+
lines.push("**Modifying a component:**");
|
|
203
|
+
lines.push("1. Look up symbol in `navigator.yaml` \u2192 `symbols`");
|
|
204
|
+
lines.push("2. Go directly to the path");
|
|
205
|
+
lines.push("3. Check `paradigm_ripple` for impact");
|
|
206
|
+
lines.push("");
|
|
207
|
+
lines.push("**Using MCP Tools:**");
|
|
208
|
+
lines.push('- `paradigm_navigate({ intent: "find", target: "#checkout" })` - locate symbol');
|
|
209
|
+
lines.push('- `paradigm_navigate({ intent: "explore", target: "auth" })` - browse area');
|
|
210
|
+
lines.push('- `paradigm_navigate({ intent: "context", task: "add login" })` - task context');
|
|
211
|
+
lines.push("");
|
|
212
|
+
lines.push("### PM Governance (Before/After Tasks)");
|
|
213
|
+
lines.push("");
|
|
214
|
+
lines.push("| When | Tool | Purpose |");
|
|
215
|
+
lines.push("|------|------|---------|");
|
|
216
|
+
lines.push("| Starting any task | `paradigm_pm_preflight` | Get compliance plan, affected symbols, required checks |");
|
|
217
|
+
lines.push("| Finishing any task | `paradigm_pm_postflight` | Check for violations: missing .purpose, missing gates |");
|
|
218
|
+
lines.push("");
|
|
219
|
+
return lines.join("\n");
|
|
220
|
+
}
|
|
221
|
+
function generateTerminalGuidance() {
|
|
222
|
+
const platform3 = os.platform();
|
|
223
|
+
const isWindows = platform3 === "win32";
|
|
224
|
+
const lines = [];
|
|
225
|
+
lines.push("## Terminal Syntax");
|
|
226
|
+
lines.push("");
|
|
227
|
+
if (isWindows) {
|
|
228
|
+
lines.push("This project runs on **Windows**. Use appropriate syntax:");
|
|
229
|
+
lines.push("");
|
|
230
|
+
lines.push("| Operation | Windows Syntax |");
|
|
231
|
+
lines.push("|-----------|----------------|");
|
|
232
|
+
lines.push("| Chain commands | `cmd1 ; cmd2` or `cmd1 && cmd2` (PowerShell) |");
|
|
233
|
+
lines.push("| Path separator | `\\` (backslash) |");
|
|
234
|
+
lines.push("| Environment vars | `$env:VAR` (PowerShell) or `%VAR%` (CMD) |");
|
|
235
|
+
lines.push("| Null device | `$null` (PowerShell) or `NUL` (CMD) |");
|
|
236
|
+
lines.push("| List files | `dir` or `Get-ChildItem` |");
|
|
237
|
+
lines.push("| Remove files | `del` or `Remove-Item` |");
|
|
238
|
+
lines.push("");
|
|
239
|
+
lines.push("**IMPORTANT:** Do NOT use Unix-style commands like `rm`, `cat`, `grep` directly.");
|
|
240
|
+
} else {
|
|
241
|
+
const osName = platform3 === "darwin" ? "macOS" : "Linux";
|
|
242
|
+
lines.push(`This project runs on **${osName}**. Use appropriate syntax:`);
|
|
243
|
+
lines.push("");
|
|
244
|
+
lines.push("| Operation | Unix Syntax |");
|
|
245
|
+
lines.push("|-----------|-------------|");
|
|
246
|
+
lines.push("| Chain commands | `cmd1 && cmd2` (stop on error) or `cmd1 ; cmd2` (always continue) |");
|
|
247
|
+
lines.push("| Path separator | `/` (forward slash) |");
|
|
248
|
+
lines.push("| Environment vars | `$VAR` or `${VAR}` |");
|
|
249
|
+
lines.push("| Null device | `/dev/null` |");
|
|
250
|
+
lines.push("| List files | `ls` |");
|
|
251
|
+
lines.push("| Remove files | `rm` |");
|
|
252
|
+
lines.push("");
|
|
253
|
+
lines.push("**IMPORTANT:** Do NOT use Windows-style commands like `dir`, `del`, or `%VAR%`.");
|
|
254
|
+
}
|
|
255
|
+
lines.push("");
|
|
256
|
+
return lines.join("\n");
|
|
257
|
+
}
|
|
258
|
+
function generateCommitConvention() {
|
|
259
|
+
const lines = [];
|
|
260
|
+
lines.push("## Commit Messages");
|
|
261
|
+
lines.push("");
|
|
262
|
+
lines.push("Use v2 symbols in commits for history tracking:");
|
|
263
|
+
lines.push("");
|
|
264
|
+
lines.push("### Format");
|
|
265
|
+
lines.push("```");
|
|
266
|
+
lines.push("type(#primary-symbol): short description");
|
|
267
|
+
lines.push("");
|
|
268
|
+
lines.push("- Detail with #component references");
|
|
269
|
+
lines.push("- Gate changes: ^gate-name");
|
|
270
|
+
lines.push("- Signals emitted: !signal-name");
|
|
271
|
+
lines.push("");
|
|
272
|
+
lines.push("Symbols: #symbol-a, #symbol-b, !signal-c");
|
|
273
|
+
lines.push("```");
|
|
274
|
+
lines.push("");
|
|
275
|
+
lines.push("### Convention");
|
|
276
|
+
lines.push("- **Subject**: `type(#symbol): description` \u2014 primary symbol in parens");
|
|
277
|
+
lines.push("- **Body**: Reference affected symbols with prefixes (# $ ^ ! ~)");
|
|
278
|
+
lines.push("- **Trailer**: `Symbols: #a, #b, !c` \u2014 machine-readable list of ALL affected symbols");
|
|
279
|
+
lines.push("- The `Symbols:` trailer is parsed by the post-commit hook for automatic history capture");
|
|
280
|
+
lines.push("");
|
|
281
|
+
lines.push("### Examples");
|
|
282
|
+
lines.push("```");
|
|
283
|
+
lines.push("feat(#payment-form): add Apple Pay support");
|
|
284
|
+
lines.push("");
|
|
285
|
+
lines.push("- Add #apple-pay-button component");
|
|
286
|
+
lines.push("- Update $checkout-flow with new payment step");
|
|
287
|
+
lines.push("- Emit !payment-method-added signal");
|
|
288
|
+
lines.push("- Gate: ^authenticated required");
|
|
289
|
+
lines.push("");
|
|
290
|
+
lines.push("Symbols: #payment-form, #apple-pay-button, $checkout-flow, !payment-method-added");
|
|
291
|
+
lines.push("```");
|
|
292
|
+
lines.push("");
|
|
293
|
+
return lines.join("\n");
|
|
294
|
+
}
|
|
295
|
+
function generateMcpToolReference() {
|
|
296
|
+
const lines = [];
|
|
297
|
+
lines.push("## MCP Tools");
|
|
298
|
+
lines.push("");
|
|
299
|
+
lines.push("Paradigm provides MCP tools for token-efficient, always-fresh data. Prefer these over reading files directly.");
|
|
300
|
+
lines.push("");
|
|
301
|
+
lines.push("| Tool | Description | When to Use |");
|
|
302
|
+
lines.push("|------|-------------|-------------|");
|
|
303
|
+
lines.push("| `paradigm_status` | Project overview and symbol counts | Starting a session |");
|
|
304
|
+
lines.push("| `paradigm_search` | Find symbols by name, description, or tags | Looking for symbols |");
|
|
305
|
+
lines.push("| `paradigm_navigate` | Find code locations, explore areas, get task context | Locating code |");
|
|
306
|
+
lines.push("| `paradigm_ripple` | Dependency and impact analysis | Before modifying symbols |");
|
|
307
|
+
lines.push("| `paradigm_related` | Direct relationships for a symbol | Understanding connections |");
|
|
308
|
+
lines.push("| `paradigm_gates_for_route` | Suggest gates for an API endpoint | Adding API routes |");
|
|
309
|
+
lines.push("| `paradigm_wisdom_context` | Team preferences and antipatterns | Before implementing |");
|
|
310
|
+
lines.push("| `paradigm_history_fragility` | Stability warnings for symbols | Before modifying fragile areas |");
|
|
311
|
+
lines.push("| `paradigm_flow_validate` | Validate flow definitions | Before/after implementing flows |");
|
|
312
|
+
lines.push("| `paradigm_flows_affected` | Flows impacted by symbol changes | After modifying symbols |");
|
|
313
|
+
lines.push("| `paradigm_test_fixtures` | Get test data for validation | Writing tests |");
|
|
314
|
+
lines.push("| `paradigm_orchestrate_inline` | Multi-agent task planning | Complex tasks (3+ files) |");
|
|
315
|
+
lines.push("| `paradigm_pm_preflight` | Pre-task compliance check | Starting any task |");
|
|
316
|
+
lines.push("| `paradigm_pm_postflight` | Post-task violation detection | Finishing any task |");
|
|
317
|
+
lines.push("| `paradigm_session_recover` | Load previous session breadcrumbs | Starting a new session |");
|
|
318
|
+
lines.push("| `paradigm_context_check` | Check context window usage | Every 10-15 tool calls |");
|
|
319
|
+
lines.push("| `paradigm_handoff_prepare` | Prepare session handoff summary | When context is high |");
|
|
320
|
+
lines.push("| `paradigm_reindex` | Rebuild static index files | After modifying .purpose files |");
|
|
321
|
+
lines.push("| `paradigm_session_checkpoint` | Save cognitive-transition checkpoint | Phase transitions |");
|
|
322
|
+
lines.push("| `paradigm_session_stats` | Current session token usage | Checking budget |");
|
|
323
|
+
lines.push("");
|
|
324
|
+
lines.push("**Rule**: Use MCP tools for discovery and validation, file reads for implementation.");
|
|
325
|
+
lines.push("");
|
|
326
|
+
return lines.join("\n");
|
|
327
|
+
}
|
|
328
|
+
function generateWorkflowProtocol() {
|
|
329
|
+
const lines = [];
|
|
330
|
+
lines.push("## Workflow Protocol");
|
|
331
|
+
lines.push("");
|
|
332
|
+
lines.push("### Before Each Task");
|
|
333
|
+
lines.push("");
|
|
334
|
+
lines.push("1. **Preflight**: Call `paradigm_pm_preflight` with your task description");
|
|
335
|
+
lines.push(" - Returns affected symbols, ripple analysis, required agents");
|
|
336
|
+
lines.push("2. **Impact check**: Call `paradigm_ripple` for any symbols you'll modify");
|
|
337
|
+
lines.push("3. **Gate check**: Call `paradigm_gates_for_route` before adding API endpoints");
|
|
338
|
+
lines.push('4. **Complex tasks** (3+ files, security + implementation): Call `paradigm_orchestrate_inline` with mode="plan"');
|
|
339
|
+
lines.push("");
|
|
340
|
+
lines.push("### After Each Task");
|
|
341
|
+
lines.push("");
|
|
342
|
+
lines.push("1. **Postflight**: Call `paradigm_pm_postflight` with modified files and symbols");
|
|
343
|
+
lines.push(" - Checks for missing .purpose files, unregistered routes, uncaptured wisdom");
|
|
344
|
+
lines.push("2. **Reindex**: Call `paradigm_reindex` to rebuild static index files");
|
|
345
|
+
lines.push("3. **Validate flows**: Call `paradigm_flow_validate` if you touched flow-related symbols");
|
|
346
|
+
lines.push("");
|
|
347
|
+
return lines.join("\n");
|
|
348
|
+
}
|
|
349
|
+
function generateHandoffProtocol() {
|
|
350
|
+
const lines = [];
|
|
351
|
+
lines.push("## Session Recovery & Handoff");
|
|
352
|
+
lines.push("");
|
|
353
|
+
lines.push("### Session Start (EVERY new session)");
|
|
354
|
+
lines.push("");
|
|
355
|
+
lines.push("Call `paradigm_session_recover` to load previous session breadcrumbs.");
|
|
356
|
+
lines.push("Returns: symbols modified, files explored, recent actions, and suggestions.");
|
|
357
|
+
lines.push("");
|
|
358
|
+
lines.push("### Context Monitoring");
|
|
359
|
+
lines.push("");
|
|
360
|
+
lines.push("Call `paradigm_context_check` every 10-15 tool calls to track context usage.");
|
|
361
|
+
lines.push("");
|
|
362
|
+
lines.push("| Usage | Recommendation | Action |");
|
|
363
|
+
lines.push("|-------|----------------|--------|");
|
|
364
|
+
lines.push("| <50% | continue | Keep working |");
|
|
365
|
+
lines.push("| 50-70% | consider-handoff | Plan a stopping point |");
|
|
366
|
+
lines.push("| 70-85% | handoff-recommended | Prepare handoff soon |");
|
|
367
|
+
lines.push("| >85% | handoff-urgent | Handoff after current task |");
|
|
368
|
+
lines.push("");
|
|
369
|
+
lines.push("### Handoff Process");
|
|
370
|
+
lines.push("");
|
|
371
|
+
lines.push("1. Call `paradigm_handoff_prepare` with summary, next steps, and target agent");
|
|
372
|
+
lines.push('2. User runs: `paradigm team handoff --to <agent> --summary "..."`');
|
|
373
|
+
lines.push("3. New session accepts: `paradigm team accept <handoff-id>`");
|
|
374
|
+
lines.push("");
|
|
375
|
+
return lines.join("\n");
|
|
376
|
+
}
|
|
377
|
+
function generateCheckpointProtocol() {
|
|
378
|
+
const lines = [];
|
|
379
|
+
lines.push("## Session Checkpoints");
|
|
380
|
+
lines.push("");
|
|
381
|
+
lines.push("**Auto-recovery**: Recovery data is automatically surfaced on your first Paradigm tool call \u2014 no action needed to receive it.");
|
|
382
|
+
lines.push("");
|
|
383
|
+
lines.push("Save checkpoints when transitioning between workflow phases to enable crash recovery:");
|
|
384
|
+
lines.push("");
|
|
385
|
+
lines.push("| Phase | Trigger | What to Capture |");
|
|
386
|
+
lines.push("|-------|---------|-----------------|");
|
|
387
|
+
lines.push("| `planning` | After reading requirements / before coding | Plan, approach, key decisions |");
|
|
388
|
+
lines.push("| `implementing` | After starting code changes | Modified files, symbols touched, decisions made |");
|
|
389
|
+
lines.push("| `validating` | After implementation, before tests/review | All modified files, test plan |");
|
|
390
|
+
lines.push("| `complete` | Task finished | Summary, final file list |");
|
|
391
|
+
lines.push("");
|
|
392
|
+
lines.push("### Usage");
|
|
393
|
+
lines.push("");
|
|
394
|
+
lines.push("```");
|
|
395
|
+
lines.push("paradigm_session_checkpoint({");
|
|
396
|
+
lines.push(' phase: "implementing",');
|
|
397
|
+
lines.push(' context: "Adding JWT auth middleware to /api/projects routes",');
|
|
398
|
+
lines.push(' modifiedFiles: ["src/middleware/auth.ts", "src/routes/projects.ts"],');
|
|
399
|
+
lines.push(' symbolsTouched: ["^authenticated", "#project-routes"],');
|
|
400
|
+
lines.push(' decisions: ["Using RS256 for JWT signing", "Storing refresh tokens in httpOnly cookies"]');
|
|
401
|
+
lines.push("})");
|
|
402
|
+
lines.push("```");
|
|
403
|
+
lines.push("");
|
|
404
|
+
lines.push("Keep it lightweight: `phase` + `context` are required, everything else is optional.");
|
|
405
|
+
lines.push("");
|
|
406
|
+
return lines.join("\n");
|
|
407
|
+
}
|
|
408
|
+
function generateFooter() {
|
|
409
|
+
const lines = [];
|
|
410
|
+
lines.push("---");
|
|
411
|
+
lines.push("");
|
|
412
|
+
lines.push("## Reference Files");
|
|
413
|
+
lines.push("");
|
|
414
|
+
lines.push("- `.paradigm/specs/symbols.md` - Symbol system reference");
|
|
415
|
+
lines.push("- `.paradigm/specs/logger.md` - Logging specification");
|
|
416
|
+
lines.push("- `.paradigm/specs/scan.md` - Scan protocol");
|
|
417
|
+
lines.push("- `.paradigm/docs/commands.md` - CLI reference");
|
|
418
|
+
lines.push("- `.paradigm/docs/patterns.md` - Coding patterns");
|
|
419
|
+
lines.push("- `.paradigm/docs/troubleshooting.md` - Common issues");
|
|
420
|
+
lines.push("- `.paradigm/prompts/` - Pre-written task prompts");
|
|
421
|
+
lines.push("");
|
|
422
|
+
lines.push("*Generated by Paradigm. Run `paradigm sync` to regenerate.*");
|
|
423
|
+
return lines.join("\n");
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// src/core/ide-adapters/cursor.ts
|
|
427
|
+
function frontmatter(description, options = {}) {
|
|
428
|
+
const lines = ["---", `description: ${description}`];
|
|
429
|
+
if (options.globs) {
|
|
430
|
+
lines.push(`globs: ${options.globs}`);
|
|
431
|
+
}
|
|
432
|
+
if (options.alwaysApply !== void 0) {
|
|
433
|
+
lines.push(`alwaysApply: ${options.alwaysApply}`);
|
|
434
|
+
}
|
|
435
|
+
lines.push("---", "");
|
|
436
|
+
return lines.join("\n");
|
|
437
|
+
}
|
|
438
|
+
var CursorAdapter = class {
|
|
439
|
+
name = "cursor";
|
|
440
|
+
displayName = "Cursor";
|
|
441
|
+
outputPath = ".cursor/rules";
|
|
442
|
+
multiFile = true;
|
|
443
|
+
detect(rootDir) {
|
|
444
|
+
if (fs.existsSync(path.join(rootDir, ".cursor"))) {
|
|
445
|
+
return true;
|
|
446
|
+
}
|
|
447
|
+
if (fs.existsSync(path.join(rootDir, ".cursorrules"))) {
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
if (fs.existsSync(path.join(rootDir, ".vscode"))) {
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Generate single file content (legacy fallback)
|
|
457
|
+
*/
|
|
458
|
+
generate(files) {
|
|
459
|
+
const generatedFiles = this.generateFiles(files);
|
|
460
|
+
return generatedFiles.map((f) => `# ${f.path}
|
|
461
|
+
|
|
462
|
+
${f.content}`).join("\n\n---\n\n");
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Generate multiple .mdc files for the modern Cursor format
|
|
466
|
+
*/
|
|
467
|
+
generateFiles(files, rootDir) {
|
|
468
|
+
const { config, projectName } = files;
|
|
469
|
+
const generatedFiles = [];
|
|
470
|
+
generatedFiles.push({
|
|
471
|
+
path: "paradigm-core.mdc",
|
|
472
|
+
content: this.generateCoreRules(projectName, config)
|
|
473
|
+
});
|
|
474
|
+
generatedFiles.push({
|
|
475
|
+
path: "paradigm-symbols.mdc",
|
|
476
|
+
content: this.generateSymbolRules(config)
|
|
477
|
+
});
|
|
478
|
+
const loggingContent = generateLoggingRules(config);
|
|
479
|
+
if (loggingContent) {
|
|
480
|
+
generatedFiles.push({
|
|
481
|
+
path: "paradigm-logging.mdc",
|
|
482
|
+
content: this.generateLoggingMdc(config)
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
generatedFiles.push({
|
|
486
|
+
path: "paradigm-purpose.mdc",
|
|
487
|
+
content: this.generatePurposeMdc()
|
|
488
|
+
});
|
|
489
|
+
generatedFiles.push({
|
|
490
|
+
path: "paradigm-portal.mdc",
|
|
491
|
+
content: this.generatePortalMdc()
|
|
492
|
+
});
|
|
493
|
+
generatedFiles.push({
|
|
494
|
+
path: "paradigm-commands.mdc",
|
|
495
|
+
content: this.generateCommandsMdc()
|
|
496
|
+
});
|
|
497
|
+
generatedFiles.push({
|
|
498
|
+
path: "paradigm-conventions.mdc",
|
|
499
|
+
content: this.generateConventionsMdc(config)
|
|
500
|
+
});
|
|
501
|
+
generatedFiles.push({
|
|
502
|
+
path: "paradigm-agent-hints.mdc",
|
|
503
|
+
content: this.generateAgentHintsMdc()
|
|
504
|
+
});
|
|
505
|
+
generatedFiles.push({
|
|
506
|
+
path: "paradigm-navigator.mdc",
|
|
507
|
+
content: this.generateNavigatorMdc()
|
|
508
|
+
});
|
|
509
|
+
generatedFiles.push({
|
|
510
|
+
path: "paradigm-context.mdc",
|
|
511
|
+
content: this.generateContextMdc()
|
|
512
|
+
});
|
|
513
|
+
const agentsManifest = rootDir ? this.loadAgentsManifest(rootDir) : null;
|
|
514
|
+
generatedFiles.push({
|
|
515
|
+
path: "paradigm-orchestration.mdc",
|
|
516
|
+
content: this.generateOrchestrationMdc(agentsManifest)
|
|
517
|
+
});
|
|
518
|
+
generatedFiles.push({
|
|
519
|
+
path: "paradigm-flows.mdc",
|
|
520
|
+
content: this.generateFlowsMdc()
|
|
521
|
+
});
|
|
522
|
+
generatedFiles.push({
|
|
523
|
+
path: "paradigm-commits.mdc",
|
|
524
|
+
content: this.generateCommitsMdc()
|
|
525
|
+
});
|
|
526
|
+
return generatedFiles;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Core rules - project overview and fundamentals
|
|
530
|
+
*/
|
|
531
|
+
generateCoreRules(projectName, config) {
|
|
532
|
+
const overview = generateOverview(config);
|
|
533
|
+
return frontmatter("Paradigm core rules - project overview and fundamentals", { alwaysApply: true }) + `# Paradigm - ${projectName}
|
|
534
|
+
|
|
535
|
+
` + overview + "\n\n" + generateUpdateRules(config);
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Symbol system rules
|
|
539
|
+
*/
|
|
540
|
+
generateSymbolRules(config) {
|
|
541
|
+
return frontmatter("Paradigm symbol system - understand #components, $flows, ^gates, !signals, ~aspects", { alwaysApply: true }) + generateSymbolSystem(config);
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Logging rules for TypeScript/JavaScript
|
|
545
|
+
*/
|
|
546
|
+
generateLoggingMdc(config) {
|
|
547
|
+
return frontmatter("Paradigm logger usage for TypeScript/JavaScript code", {
|
|
548
|
+
globs: "**/*.{ts,tsx,js,jsx}",
|
|
549
|
+
alwaysApply: false
|
|
550
|
+
}) + generateLoggingRules(config);
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Purpose file conventions
|
|
554
|
+
*/
|
|
555
|
+
generatePurposeMdc() {
|
|
556
|
+
return frontmatter("Purpose file conventions - .purpose file format and usage", {
|
|
557
|
+
globs: "**/.purpose",
|
|
558
|
+
alwaysApply: false
|
|
559
|
+
}) + `# Purpose Files
|
|
560
|
+
|
|
561
|
+
Purpose files (\`.purpose\`) define the context for directories.
|
|
562
|
+
|
|
563
|
+
## Format
|
|
564
|
+
|
|
565
|
+
\`\`\`yaml
|
|
566
|
+
# Directory context
|
|
567
|
+
description: What this directory contains and why
|
|
568
|
+
|
|
569
|
+
# Components (# symbol) \u2014 all documented code units
|
|
570
|
+
components:
|
|
571
|
+
component-name:
|
|
572
|
+
description: What this component does
|
|
573
|
+
tags: [feature] # Classification via tag bank
|
|
574
|
+
gates: [^gate1, ^gate2] # Required gates
|
|
575
|
+
signals: [!signal1] # Events emitted
|
|
576
|
+
used-by: [#other-component]
|
|
577
|
+
\`\`\`
|
|
578
|
+
|
|
579
|
+
## Symbol References (v2)
|
|
580
|
+
|
|
581
|
+
- Reference components: \`#component-name\`
|
|
582
|
+
- Reference flows: \`$flow-name\`
|
|
583
|
+
- Reference gates: \`^gate-name\`
|
|
584
|
+
- Reference signals: \`!signal-name\`
|
|
585
|
+
- Reference aspects: \`~aspect-name\`
|
|
586
|
+
`;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Portal rules
|
|
590
|
+
*/
|
|
591
|
+
generatePortalMdc() {
|
|
592
|
+
return frontmatter("Portal (gate) configuration rules", {
|
|
593
|
+
globs: "**/portal.yaml",
|
|
594
|
+
alwaysApply: false
|
|
595
|
+
}) + `# Portal Configuration
|
|
596
|
+
|
|
597
|
+
Portal files (\`portal.yaml\`) define authorization topology.
|
|
598
|
+
|
|
599
|
+
## Format
|
|
600
|
+
|
|
601
|
+
\`\`\`yaml
|
|
602
|
+
version: "1.0"
|
|
603
|
+
|
|
604
|
+
gates:
|
|
605
|
+
gate-name:
|
|
606
|
+
description: What this gate protects
|
|
607
|
+
locks:
|
|
608
|
+
- id: lock-id
|
|
609
|
+
description: Requirement description
|
|
610
|
+
keys:
|
|
611
|
+
- expression: "user.authenticated"
|
|
612
|
+
description: User must be logged in
|
|
613
|
+
prizes:
|
|
614
|
+
- id: prize-id
|
|
615
|
+
oneTime: true
|
|
616
|
+
metadata:
|
|
617
|
+
event: "gate_passed"
|
|
618
|
+
|
|
619
|
+
flows:
|
|
620
|
+
flow-name:
|
|
621
|
+
description: User journey
|
|
622
|
+
gates: [gate1, gate2, gate3]
|
|
623
|
+
\`\`\`
|
|
624
|
+
|
|
625
|
+
## Portal Validation
|
|
626
|
+
|
|
627
|
+
Use the Portal Validator for authorization checks:
|
|
628
|
+
|
|
629
|
+
\`\`\`typescript
|
|
630
|
+
import { portal } from '@a-company/portal-sdk/validator';
|
|
631
|
+
|
|
632
|
+
const gate = portal.check('^gate-name')
|
|
633
|
+
.requires('requirement description')
|
|
634
|
+
.context({ userId, role });
|
|
635
|
+
|
|
636
|
+
if (!condition) {
|
|
637
|
+
gate.deny('Reason for denial');
|
|
638
|
+
return redirect('/unauthorized');
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
gate.allow('Access granted');
|
|
642
|
+
\`\`\`
|
|
643
|
+
`;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Commands reference
|
|
647
|
+
*/
|
|
648
|
+
generateCommandsMdc() {
|
|
649
|
+
return frontmatter("Paradigm CLI commands reference", { alwaysApply: false }) + generateCommandsReference();
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Conventions
|
|
653
|
+
*/
|
|
654
|
+
generateConventionsMdc(config) {
|
|
655
|
+
return frontmatter("Paradigm coding conventions", {
|
|
656
|
+
globs: "**/*.{ts,tsx,js,jsx}",
|
|
657
|
+
alwaysApply: false
|
|
658
|
+
}) + generateConventions(config);
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Agent Hints - when to query CLI commands
|
|
662
|
+
*/
|
|
663
|
+
generateAgentHintsMdc() {
|
|
664
|
+
return frontmatter("Paradigm CLI queries for AI agents - prefer CLI over reading large files", {
|
|
665
|
+
alwaysApply: true
|
|
666
|
+
}) + `# Agent CLI Queries (Token-Efficient)
|
|
667
|
+
|
|
668
|
+
Instead of reading large context files, query Paradigm CLI on-demand for fresh, precise data.
|
|
669
|
+
|
|
670
|
+
## When to Query
|
|
671
|
+
|
|
672
|
+
| Before doing this... | Run this command |
|
|
673
|
+
|---------------------|------------------|
|
|
674
|
+
| Modifying a symbol | \`paradigm ripple #symbol --json\` |
|
|
675
|
+
| Debugging an error | \`paradigm echo ERROR_CODE --json\` |
|
|
676
|
+
| Starting a session | \`paradigm thread --json\` |
|
|
677
|
+
| Understanding relationships | \`paradigm constellation\` |
|
|
678
|
+
| Getting oriented | \`paradigm beacon --json\` |
|
|
679
|
+
|
|
680
|
+
## Query Patterns
|
|
681
|
+
|
|
682
|
+
### Before Changing Code
|
|
683
|
+
|
|
684
|
+
\`\`\`bash
|
|
685
|
+
# See what depends on what you're changing
|
|
686
|
+
paradigm ripple #checkout --json
|
|
687
|
+
|
|
688
|
+
# Output includes: upstream deps, downstream effects, flow membership
|
|
689
|
+
\`\`\`
|
|
690
|
+
|
|
691
|
+
### When Debugging
|
|
692
|
+
|
|
693
|
+
\`\`\`bash
|
|
694
|
+
# Look up error context
|
|
695
|
+
paradigm echo AUTH_REQUIRED --json
|
|
696
|
+
|
|
697
|
+
# Then check ripple effects of the related symbol
|
|
698
|
+
paradigm ripple ^authenticated --json
|
|
699
|
+
\`\`\`
|
|
700
|
+
|
|
701
|
+
### Starting Work
|
|
702
|
+
|
|
703
|
+
\`\`\`bash
|
|
704
|
+
# Check previous session context
|
|
705
|
+
paradigm thread --json
|
|
706
|
+
|
|
707
|
+
# Quick orientation
|
|
708
|
+
paradigm beacon --json
|
|
709
|
+
\`\`\`
|
|
710
|
+
|
|
711
|
+
### Querying Constellation
|
|
712
|
+
|
|
713
|
+
\`\`\`bash
|
|
714
|
+
# Get specific symbol
|
|
715
|
+
jq '.stars["#checkout"]' .paradigm/constellation.json
|
|
716
|
+
|
|
717
|
+
# Find what requires a gate
|
|
718
|
+
jq '[.stars | to_entries[] | select(.value.gates[]? == "^authenticated") | .key]' .paradigm/constellation.json
|
|
719
|
+
|
|
720
|
+
# List all flows
|
|
721
|
+
jq '.orbits | keys' .paradigm/constellation.json
|
|
722
|
+
\`\`\`
|
|
723
|
+
|
|
724
|
+
## Benefits
|
|
725
|
+
|
|
726
|
+
- **Fresh data**: Always current, not stale from file generation
|
|
727
|
+
- **Precise**: Only get the data you need
|
|
728
|
+
- **Token-efficient**: ~100 tokens per query vs ~2000 upfront
|
|
729
|
+
`;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Navigator rules - AI exploration optimization
|
|
733
|
+
*/
|
|
734
|
+
generateNavigatorMdc() {
|
|
735
|
+
return frontmatter("Paradigm Navigator - efficient codebase exploration", {
|
|
736
|
+
alwaysApply: true
|
|
737
|
+
}) + `# Paradigm Navigator
|
|
738
|
+
|
|
739
|
+
## Exploration Protocol
|
|
740
|
+
|
|
741
|
+
Before exploring this codebase:
|
|
742
|
+
|
|
743
|
+
1. **Read \`.paradigm/navigator.yaml\`** for the structure map
|
|
744
|
+
2. **Query by symbol** - lookup paths directly from the symbols map
|
|
745
|
+
3. **Respect skip patterns** - avoid node_modules, dist, .git, etc.
|
|
746
|
+
|
|
747
|
+
## Navigation Strategy
|
|
748
|
+
|
|
749
|
+
**INSTEAD OF:** Broad exploration (expensive token usage)
|
|
750
|
+
|
|
751
|
+
**DO THIS:**
|
|
752
|
+
1. Read \`.paradigm/navigator.yaml\` for project structure
|
|
753
|
+
2. Find relevant symbol \u2192 go directly to path
|
|
754
|
+
3. Read only needed files
|
|
755
|
+
|
|
756
|
+
## Using MCP Navigate Tool
|
|
757
|
+
|
|
758
|
+
\`\`\`
|
|
759
|
+
# Find a specific symbol
|
|
760
|
+
paradigm_navigate({ intent: "find", target: "#checkout" })
|
|
761
|
+
|
|
762
|
+
# Explore an area
|
|
763
|
+
paradigm_navigate({ intent: "explore", target: "authentication" })
|
|
764
|
+
|
|
765
|
+
# Get context for a task
|
|
766
|
+
paradigm_navigate({ intent: "context", task: "add Apple Pay" })
|
|
767
|
+
\`\`\`
|
|
768
|
+
|
|
769
|
+
## Task Recipes
|
|
770
|
+
|
|
771
|
+
### Adding a Feature
|
|
772
|
+
1. Check \`navigator.yaml\` \u2192 \`structure.features.paths\`
|
|
773
|
+
2. Read an existing feature as template
|
|
774
|
+
3. Create in the same location
|
|
775
|
+
|
|
776
|
+
### Modifying a Component
|
|
777
|
+
1. Look up symbol in \`navigator.yaml\` \u2192 \`symbols\`
|
|
778
|
+
2. Go directly to the path
|
|
779
|
+
3. Use \`paradigm_ripple\` to check impact
|
|
780
|
+
|
|
781
|
+
### Understanding Dependencies
|
|
782
|
+
1. Use \`paradigm_navigate({ intent: "context", task: "..." })\`
|
|
783
|
+
2. Read suggested files in order
|
|
784
|
+
3. Skip patterns in the \`skip\` array
|
|
785
|
+
|
|
786
|
+
## Key Files (Quick Reference)
|
|
787
|
+
|
|
788
|
+
Always available in \`navigator.yaml\`:
|
|
789
|
+
- \`key_files.config\` - Configuration files
|
|
790
|
+
- \`key_files.entry\` - Entry points
|
|
791
|
+
- \`key_files.types\` - Type definitions
|
|
792
|
+
`;
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Context monitoring rules - session management and handoff
|
|
796
|
+
*/
|
|
797
|
+
generateContextMdc() {
|
|
798
|
+
return frontmatter("Session recovery and handoff - call paradigm_session_recover at session start, paradigm_context_check periodically during long sessions, paradigm_handoff_prepare when context is high.") + `# Context Monitoring Protocol
|
|
799
|
+
|
|
800
|
+
## Session Start (EVERY new session)
|
|
801
|
+
|
|
802
|
+
Call \`paradigm_session_recover\` to load previous session breadcrumbs.
|
|
803
|
+
Returns: symbols modified, files explored, recent actions, and suggestions.
|
|
804
|
+
|
|
805
|
+
## Periodic Checks
|
|
806
|
+
|
|
807
|
+
**Every 10-15 tool calls** (or when user asks about context), call:
|
|
808
|
+
|
|
809
|
+
\`\`\`
|
|
810
|
+
paradigm_context_check()
|
|
811
|
+
\`\`\`
|
|
812
|
+
|
|
813
|
+
This returns a recommendation: \`continue\`, \`consider-handoff\`, \`handoff-recommended\`, or \`handoff-urgent\`.
|
|
814
|
+
|
|
815
|
+
## When to Handoff
|
|
816
|
+
|
|
817
|
+
| Usage | Recommendation | Action |
|
|
818
|
+
|-------|----------------|--------|
|
|
819
|
+
| <50% | continue | Keep working |
|
|
820
|
+
| 50-70% | consider-handoff | Plan stopping point |
|
|
821
|
+
| 70-85% | handoff-recommended | Prepare handoff soon |
|
|
822
|
+
| >85% | handoff-urgent | Handoff after current task |
|
|
823
|
+
|
|
824
|
+
## When Recommendation is NOT "continue"
|
|
825
|
+
|
|
826
|
+
1. **Inform user**: "Context usage is at ~X%. Recommend handoff soon."
|
|
827
|
+
2. **Offer to prepare**: Ask if user wants handoff summary
|
|
828
|
+
3. **If urgent (>85%)**: Prioritize completing current task, then handoff
|
|
829
|
+
|
|
830
|
+
## Handoff Process
|
|
831
|
+
|
|
832
|
+
1. Call \`paradigm_handoff_prepare\` with:
|
|
833
|
+
- Summary of work completed
|
|
834
|
+
- List of next steps
|
|
835
|
+
- Target agent role
|
|
836
|
+
|
|
837
|
+
2. User runs CLI command:
|
|
838
|
+
\`\`\`bash
|
|
839
|
+
paradigm team handoff --to <agent> --summary "..."
|
|
840
|
+
\`\`\`
|
|
841
|
+
|
|
842
|
+
3. New session accepts:
|
|
843
|
+
\`\`\`bash
|
|
844
|
+
paradigm team accept <handoff-id>
|
|
845
|
+
\`\`\`
|
|
846
|
+
|
|
847
|
+
## Session Stats
|
|
848
|
+
|
|
849
|
+
Get current stats anytime:
|
|
850
|
+
\`\`\`
|
|
851
|
+
paradigm_session_stats()
|
|
852
|
+
\`\`\`
|
|
853
|
+
|
|
854
|
+
${generateCheckpointProtocol()}`;
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Load agents manifest from .paradigm/agents.yaml
|
|
858
|
+
*/
|
|
859
|
+
loadAgentsManifest(rootDir) {
|
|
860
|
+
const agentsPath = path.join(rootDir, ".paradigm", "agents.yaml");
|
|
861
|
+
if (!fs.existsSync(agentsPath)) {
|
|
862
|
+
return null;
|
|
863
|
+
}
|
|
864
|
+
try {
|
|
865
|
+
const content = fs.readFileSync(agentsPath, "utf-8");
|
|
866
|
+
return yaml.load(content);
|
|
867
|
+
} catch {
|
|
868
|
+
return null;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* Orchestration protocol rules - multi-agent workflow
|
|
873
|
+
*/
|
|
874
|
+
generateOrchestrationMdc(agentsManifest) {
|
|
875
|
+
let agentList = "(Run `paradigm team init` to configure agents)";
|
|
876
|
+
if (agentsManifest) {
|
|
877
|
+
const agents = agentsManifest.agents || agentsManifest.roles;
|
|
878
|
+
if (agents && typeof agents === "object") {
|
|
879
|
+
try {
|
|
880
|
+
agentList = Object.entries(agents).map(([name, agent]) => {
|
|
881
|
+
const roleText = agent.role || agent.description || "";
|
|
882
|
+
const roleFirstLine = roleText.split("\n")[0].trim() || name;
|
|
883
|
+
const writes = agent.focus?.writes;
|
|
884
|
+
const writesStr = Array.isArray(writes) ? writes.join(", ") : "any";
|
|
885
|
+
const model = agent.defaultModel || "sonnet";
|
|
886
|
+
return `- **${name}** (${model}): ${roleFirstLine} (writes: ${writesStr})`;
|
|
887
|
+
}).join("\n");
|
|
888
|
+
} catch {
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
const platform3 = os2.platform();
|
|
893
|
+
const isWindows = platform3 === "win32";
|
|
894
|
+
const terminalGuidance = isWindows ? `## Terminal Syntax (Windows)
|
|
895
|
+
|
|
896
|
+
This project runs on **Windows**. Use appropriate syntax:
|
|
897
|
+
|
|
898
|
+
| Operation | Windows Syntax |
|
|
899
|
+
|-----------|----------------|
|
|
900
|
+
| Chain commands | \`cmd1 ; cmd2\` or \`cmd1 && cmd2\` (PowerShell) |
|
|
901
|
+
| Path separator | \`\\\` (backslash) |
|
|
902
|
+
| Environment vars | \`$env:VAR\` (PowerShell) or \`%VAR%\` (CMD) |
|
|
903
|
+
| Null device | \`$null\` (PowerShell) or \`NUL\` (CMD) |
|
|
904
|
+
| List files | \`dir\` or \`Get-ChildItem\` |
|
|
905
|
+
| Remove files | \`del\` or \`Remove-Item\` |
|
|
906
|
+
|
|
907
|
+
**IMPORTANT:** Do NOT use Unix-style commands like \`rm\`, \`cat\`, \`grep\` directly.` : `## Terminal Syntax (${platform3 === "darwin" ? "macOS" : "Linux"})
|
|
908
|
+
|
|
909
|
+
This project runs on **${platform3 === "darwin" ? "macOS" : "Linux"}**. Use appropriate syntax:
|
|
910
|
+
|
|
911
|
+
| Operation | Unix Syntax |
|
|
912
|
+
|-----------|-------------|
|
|
913
|
+
| Chain commands | \`cmd1 && cmd2\` (stop on error) or \`cmd1 ; cmd2\` (always continue) |
|
|
914
|
+
| Path separator | \`/\` (forward slash) |
|
|
915
|
+
| Environment vars | \`$VAR\` or \`\${VAR}\` |
|
|
916
|
+
| Null device | \`/dev/null\` |
|
|
917
|
+
| List files | \`ls\` |
|
|
918
|
+
| Remove files | \`rm\` |
|
|
919
|
+
|
|
920
|
+
**IMPORTANT:** Do NOT use Windows-style commands like \`dir\`, \`del\`, or \`%VAR%\`.`;
|
|
921
|
+
return frontmatter("Multi-agent orchestration - use when task affects 3+ files, involves security AND implementation, or spans multiple features. Call paradigm_orchestrate_inline for planning.") + `# Paradigm Orchestration Protocol
|
|
922
|
+
|
|
923
|
+
${terminalGuidance}
|
|
924
|
+
|
|
925
|
+
## CRITICAL: When to Use Orchestration
|
|
926
|
+
|
|
927
|
+
**ALWAYS call \`paradigm_orchestrate_inline\` FIRST when:**
|
|
928
|
+
- Task affects 3+ files
|
|
929
|
+
- Task involves security/auth AND implementation
|
|
930
|
+
- Task mentions multiple features (#symbols)
|
|
931
|
+
- Building a new feature end-to-end
|
|
932
|
+
- User explicitly requests multi-agent workflow
|
|
933
|
+
|
|
934
|
+
## Workflow
|
|
935
|
+
|
|
936
|
+
1. **Plan first:** \`paradigm_orchestrate_inline({ task: "...", mode: "plan" })\`
|
|
937
|
+
- Review suggested agents and estimated tokens
|
|
938
|
+
- Check if parallel execution is possible
|
|
939
|
+
|
|
940
|
+
2. **Execute:** \`paradigm_orchestrate_inline({ task: "...", mode: "execute" })\`
|
|
941
|
+
- Get full prompts and execution strategy
|
|
942
|
+
- Note which stages can run in parallel
|
|
943
|
+
|
|
944
|
+
3. **Follow the plan sequentially:**
|
|
945
|
+
- For each stage/agent, adopt that role's prompt and focus areas
|
|
946
|
+
- Stage 0 (architect): Design and spec only \u2014 do NOT write implementation code
|
|
947
|
+
- Stage 1 (builder): Implement following the architect's design
|
|
948
|
+
- Stage 2 (tester/reviewer): Verify and test the implementation
|
|
949
|
+
- Pass context between phases as if handing off to a teammate
|
|
950
|
+
|
|
951
|
+
4. **For true parallel execution**, suggest user runs:
|
|
952
|
+
\`paradigm team orchestrate "task description"\`
|
|
953
|
+
|
|
954
|
+
5. **Record history:** \`paradigm_history_record({ type: "implement", symbols: [...], description: "..." })\`
|
|
955
|
+
|
|
956
|
+
## Available Agents
|
|
957
|
+
|
|
958
|
+
${agentList}
|
|
959
|
+
|
|
960
|
+
## Red Flags - STOP and Orchestrate
|
|
961
|
+
|
|
962
|
+
If you find yourself:
|
|
963
|
+
- Implementing 5+ files without planning \u2192 STOP, call orchestrate
|
|
964
|
+
- Adding auth without security review \u2192 STOP, involve security agent
|
|
965
|
+
- Writing code without specs \u2192 STOP, involve architect first
|
|
966
|
+
- Making cross-cutting changes \u2192 STOP, plan the stages
|
|
967
|
+
|
|
968
|
+
## DO NOT Skip Orchestration
|
|
969
|
+
|
|
970
|
+
Complex tasks need specialist agents. One agent trying to do everything leads to:
|
|
971
|
+
- Missed security gates
|
|
972
|
+
- Inconsistent patterns
|
|
973
|
+
- Poor test coverage
|
|
974
|
+
- Context overflow
|
|
975
|
+
|
|
976
|
+
## CLI Shortcut
|
|
977
|
+
|
|
978
|
+
You can also suggest agents via CLI:
|
|
979
|
+
\`\`\`bash
|
|
980
|
+
paradigm team agents suggest "Add user authentication with JWT"
|
|
981
|
+
\`\`\`
|
|
982
|
+
`;
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
* Flow-First Development rules
|
|
986
|
+
*/
|
|
987
|
+
generateFlowsMdc() {
|
|
988
|
+
return frontmatter("Flow-first development - apply when implementing features spanning multiple steps, requiring gates, or emitting signals. Define $flows before coding.") + `# Flow-First Development
|
|
989
|
+
|
|
990
|
+
## What are Flows?
|
|
991
|
+
|
|
992
|
+
Flows ($symbols) are composable sequences of gates, actions, and signals that represent the "happy path" for a feature.
|
|
993
|
+
|
|
994
|
+
\`\`\`yaml
|
|
995
|
+
# .paradigm/flows.yaml
|
|
996
|
+
flows:
|
|
997
|
+
$task-creation:
|
|
998
|
+
name: Task Creation Flow
|
|
999
|
+
description: Complete flow for creating a new task
|
|
1000
|
+
trigger: "POST /api/tasks"
|
|
1001
|
+
steps:
|
|
1002
|
+
- type: gate
|
|
1003
|
+
symbol: ^authenticated
|
|
1004
|
+
description: User must be logged in
|
|
1005
|
+
- type: gate
|
|
1006
|
+
symbol: ^project-member
|
|
1007
|
+
description: User must be member of target project
|
|
1008
|
+
- type: action
|
|
1009
|
+
symbol: "#validate-task-input"
|
|
1010
|
+
description: Validate task data
|
|
1011
|
+
- type: action
|
|
1012
|
+
symbol: "#create-task"
|
|
1013
|
+
description: Create task in database
|
|
1014
|
+
- type: signal
|
|
1015
|
+
symbol: "!task-created"
|
|
1016
|
+
description: Emit success event
|
|
1017
|
+
successSignal: "!task-created"
|
|
1018
|
+
failureSignal: "!task-creation-failed"
|
|
1019
|
+
\`\`\`
|
|
1020
|
+
|
|
1021
|
+
## When to Define Flows
|
|
1022
|
+
|
|
1023
|
+
**BEFORE implementing features that:**
|
|
1024
|
+
- Span multiple steps or components
|
|
1025
|
+
- Require authorization gates
|
|
1026
|
+
- Emit signals/events
|
|
1027
|
+
- Integrate with external systems
|
|
1028
|
+
|
|
1029
|
+
## Flow-First Protocol
|
|
1030
|
+
|
|
1031
|
+
1. **Define the flow first** in \`.paradigm/flows.yaml\`:
|
|
1032
|
+
- What gates must pass?
|
|
1033
|
+
- What actions occur in what order?
|
|
1034
|
+
- What signals are emitted?
|
|
1035
|
+
|
|
1036
|
+
2. **Validate before implementing:**
|
|
1037
|
+
\`\`\`
|
|
1038
|
+
paradigm_flow_validate({ flowId: "$task-creation" })
|
|
1039
|
+
\`\`\`
|
|
1040
|
+
- Ensures all gates are declared in portal.yaml
|
|
1041
|
+
- Checks for missing symbols
|
|
1042
|
+
|
|
1043
|
+
3. **Implement following the flow:**
|
|
1044
|
+
- Each step becomes a clear implementation target
|
|
1045
|
+
- Gates \u2192 middleware/authorization checks
|
|
1046
|
+
- Actions \u2192 business logic functions
|
|
1047
|
+
- Signals \u2192 event emitters/hooks
|
|
1048
|
+
|
|
1049
|
+
## Flow Validation
|
|
1050
|
+
|
|
1051
|
+
Call \`paradigm_flow_validate\` to check flows:
|
|
1052
|
+
|
|
1053
|
+
\`\`\`
|
|
1054
|
+
// Validate specific flow
|
|
1055
|
+
paradigm_flow_validate({ flowId: "$task-creation" })
|
|
1056
|
+
|
|
1057
|
+
// Validate all flows
|
|
1058
|
+
paradigm_flow_validate({ checkImplementation: true })
|
|
1059
|
+
\`\`\`
|
|
1060
|
+
|
|
1061
|
+
**What gets checked:**
|
|
1062
|
+
- All ^gates are declared in portal.yaml
|
|
1063
|
+
- All #actions reference existing components
|
|
1064
|
+
- All !signals are documented
|
|
1065
|
+
|
|
1066
|
+
## Benefits
|
|
1067
|
+
|
|
1068
|
+
1. **Clear implementation targets** - Each flow step is a discrete unit
|
|
1069
|
+
2. **Gate coverage** - All authorization points are explicit
|
|
1070
|
+
3. **Testability** - Flows can be tested step-by-step
|
|
1071
|
+
4. **Documentation** - The flow IS the documentation
|
|
1072
|
+
5. **Parallel work** - Different team members can implement different steps
|
|
1073
|
+
|
|
1074
|
+
## Red Flags
|
|
1075
|
+
|
|
1076
|
+
**STOP and define a flow if:**
|
|
1077
|
+
- You're implementing a "happy path" without documenting it
|
|
1078
|
+
- You're adding gates without knowing the full sequence
|
|
1079
|
+
- You're emitting signals without knowing what listens
|
|
1080
|
+
- You're modifying existing flows without checking validation
|
|
1081
|
+
|
|
1082
|
+
## MCP Tools
|
|
1083
|
+
|
|
1084
|
+
| Tool | Purpose |
|
|
1085
|
+
|------|---------|
|
|
1086
|
+
| \`paradigm_flow_validate\` | Validate flow definitions |
|
|
1087
|
+
| \`paradigm_flows_affected\` | Check which flows are impacted by symbol changes |
|
|
1088
|
+
|
|
1089
|
+
## CLI Commands
|
|
1090
|
+
|
|
1091
|
+
\`\`\`bash
|
|
1092
|
+
# Validate all flows
|
|
1093
|
+
paradigm flow validate --all
|
|
1094
|
+
|
|
1095
|
+
# Validate specific flow
|
|
1096
|
+
paradigm flow validate $task-creation
|
|
1097
|
+
\`\`\`
|
|
1098
|
+
`;
|
|
1099
|
+
}
|
|
1100
|
+
/**
|
|
1101
|
+
* Commit convention rules
|
|
1102
|
+
*/
|
|
1103
|
+
generateCommitsMdc() {
|
|
1104
|
+
return frontmatter("Paradigm commit conventions with Symbols: trailer - apply when creating git commits for history tracking.") + generateCommitConvention();
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* Generate MCP configuration for Cursor
|
|
1108
|
+
*/
|
|
1109
|
+
generateMcpConfig(rootDir) {
|
|
1110
|
+
return {
|
|
1111
|
+
mcpServers: {
|
|
1112
|
+
paradigm: {
|
|
1113
|
+
command: "paradigm-mcp",
|
|
1114
|
+
args: ["."],
|
|
1115
|
+
cwd: rootDir
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
};
|
|
1121
|
+
var cursorAdapter = new CursorAdapter();
|
|
1122
|
+
|
|
1123
|
+
// src/core/ide-adapters/copilot.ts
|
|
1124
|
+
import * as fs2 from "fs";
|
|
1125
|
+
import * as path2 from "path";
|
|
1126
|
+
function frontmatter2(applyTo, excludeAgent) {
|
|
1127
|
+
if (!applyTo && !excludeAgent) {
|
|
1128
|
+
return "";
|
|
1129
|
+
}
|
|
1130
|
+
const lines = ["---"];
|
|
1131
|
+
if (applyTo) {
|
|
1132
|
+
lines.push(`applyTo: "${applyTo}"`);
|
|
1133
|
+
}
|
|
1134
|
+
if (excludeAgent) {
|
|
1135
|
+
lines.push(`excludeAgent: "${excludeAgent}"`);
|
|
1136
|
+
}
|
|
1137
|
+
lines.push("---", "");
|
|
1138
|
+
return lines.join("\n");
|
|
1139
|
+
}
|
|
1140
|
+
var CopilotAdapter = class {
|
|
1141
|
+
name = "copilot";
|
|
1142
|
+
displayName = "GitHub Copilot";
|
|
1143
|
+
outputPath = ".github/instructions";
|
|
1144
|
+
multiFile = true;
|
|
1145
|
+
detect(rootDir) {
|
|
1146
|
+
if (fs2.existsSync(path2.join(rootDir, ".github", "instructions"))) {
|
|
1147
|
+
return true;
|
|
1148
|
+
}
|
|
1149
|
+
if (fs2.existsSync(path2.join(rootDir, ".github", "copilot-instructions.md"))) {
|
|
1150
|
+
return true;
|
|
1151
|
+
}
|
|
1152
|
+
return false;
|
|
1153
|
+
}
|
|
1154
|
+
/**
|
|
1155
|
+
* Generate single file content (legacy fallback)
|
|
1156
|
+
*/
|
|
1157
|
+
generate(files) {
|
|
1158
|
+
const generatedFiles = this.generateFiles(files);
|
|
1159
|
+
return generatedFiles.map((f) => `# ${f.path}
|
|
1160
|
+
|
|
1161
|
+
${f.content}`).join("\n\n---\n\n");
|
|
1162
|
+
}
|
|
1163
|
+
/**
|
|
1164
|
+
* Generate multiple .instructions.md files for the modern Copilot format
|
|
1165
|
+
*/
|
|
1166
|
+
generateFiles(files) {
|
|
1167
|
+
const { config, projectName } = files;
|
|
1168
|
+
const generatedFiles = [];
|
|
1169
|
+
generatedFiles.push({
|
|
1170
|
+
path: "../copilot-instructions.md",
|
|
1171
|
+
// Goes to .github/copilot-instructions.md
|
|
1172
|
+
content: this.generateCoreInstructions(projectName, config)
|
|
1173
|
+
});
|
|
1174
|
+
generatedFiles.push({
|
|
1175
|
+
path: "paradigm-symbols.instructions.md",
|
|
1176
|
+
content: this.generateSymbolInstructions(config)
|
|
1177
|
+
});
|
|
1178
|
+
const loggingContent = generateLoggingRules(config);
|
|
1179
|
+
if (loggingContent) {
|
|
1180
|
+
generatedFiles.push({
|
|
1181
|
+
path: "paradigm-logging.instructions.md",
|
|
1182
|
+
content: this.generateLoggingInstructions(config)
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
generatedFiles.push({
|
|
1186
|
+
path: "paradigm-purpose.instructions.md",
|
|
1187
|
+
content: this.generatePurposeInstructions()
|
|
1188
|
+
});
|
|
1189
|
+
generatedFiles.push({
|
|
1190
|
+
path: "paradigm-portal.instructions.md",
|
|
1191
|
+
content: this.generatePortalInstructions()
|
|
1192
|
+
});
|
|
1193
|
+
generatedFiles.push({
|
|
1194
|
+
path: "paradigm-conventions.instructions.md",
|
|
1195
|
+
content: this.generateConventionsInstructions(config)
|
|
1196
|
+
});
|
|
1197
|
+
generatedFiles.push({
|
|
1198
|
+
path: "paradigm-commands.instructions.md",
|
|
1199
|
+
content: this.generateCommandsInstructions()
|
|
1200
|
+
});
|
|
1201
|
+
generatedFiles.push({
|
|
1202
|
+
path: "paradigm-agent-hints.instructions.md",
|
|
1203
|
+
content: this.generateAgentHintsInstructions()
|
|
1204
|
+
});
|
|
1205
|
+
generatedFiles.push({
|
|
1206
|
+
path: "paradigm-commits.instructions.md",
|
|
1207
|
+
content: this.generateCommitsInstructions()
|
|
1208
|
+
});
|
|
1209
|
+
return generatedFiles;
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* Core instructions - always applies (via copilot-instructions.md)
|
|
1213
|
+
*/
|
|
1214
|
+
generateCoreInstructions(projectName, config) {
|
|
1215
|
+
const overview = generateOverview(config);
|
|
1216
|
+
return `# Copilot Instructions for ${projectName}
|
|
1217
|
+
|
|
1218
|
+
This file provides context for GitHub Copilot. Generated by Paradigm.
|
|
1219
|
+
|
|
1220
|
+
${overview}
|
|
1221
|
+
|
|
1222
|
+
${generateUpdateRules(config)}
|
|
1223
|
+
|
|
1224
|
+
---
|
|
1225
|
+
|
|
1226
|
+
## Additional Context
|
|
1227
|
+
|
|
1228
|
+
For detailed specifications, reference these files:
|
|
1229
|
+
|
|
1230
|
+
- \`.paradigm/specs/symbols.md\` - Complete symbol reference
|
|
1231
|
+
- \`.paradigm/specs/logger.md\` - Logging specification
|
|
1232
|
+
- \`.paradigm/specs/scan.md\` - Visual discovery protocol
|
|
1233
|
+
- \`.paradigm/docs/\` - Documentation and troubleshooting
|
|
1234
|
+
- \`.paradigm/prompts/\` - Pre-written task prompts
|
|
1235
|
+
|
|
1236
|
+
*Generated by Paradigm. Run \`paradigm sync copilot\` to regenerate.*
|
|
1237
|
+
`;
|
|
1238
|
+
}
|
|
1239
|
+
/**
|
|
1240
|
+
* Symbol system instructions
|
|
1241
|
+
*/
|
|
1242
|
+
generateSymbolInstructions(config) {
|
|
1243
|
+
return frontmatter2("**/*.ts,**/*.tsx,**/*.js,**/*.jsx") + `# Paradigm Symbol System
|
|
1244
|
+
|
|
1245
|
+
${generateSymbolSystem(config)}
|
|
1246
|
+
`;
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Logging instructions
|
|
1250
|
+
*/
|
|
1251
|
+
generateLoggingInstructions(config) {
|
|
1252
|
+
return frontmatter2("**/*.ts,**/*.tsx,**/*.js,**/*.jsx") + `# Paradigm Logging
|
|
1253
|
+
|
|
1254
|
+
${generateLoggingRules(config)}
|
|
1255
|
+
`;
|
|
1256
|
+
}
|
|
1257
|
+
/**
|
|
1258
|
+
* Purpose file instructions
|
|
1259
|
+
*/
|
|
1260
|
+
generatePurposeInstructions() {
|
|
1261
|
+
return frontmatter2("**/.purpose") + `# Purpose Files
|
|
1262
|
+
|
|
1263
|
+
Purpose files (\`.purpose\`) define the context for directories.
|
|
1264
|
+
|
|
1265
|
+
## Format
|
|
1266
|
+
|
|
1267
|
+
\`\`\`yaml
|
|
1268
|
+
# Directory context
|
|
1269
|
+
description: What this directory contains and why
|
|
1270
|
+
|
|
1271
|
+
# Components (# symbol) \u2014 all documented code units
|
|
1272
|
+
components:
|
|
1273
|
+
component-name:
|
|
1274
|
+
description: What this component does
|
|
1275
|
+
tags: [feature] # Classification via tag bank
|
|
1276
|
+
gates: [^gate1, ^gate2] # Required gates
|
|
1277
|
+
signals: [!signal1] # Events emitted
|
|
1278
|
+
used-by: [#other-component]
|
|
1279
|
+
\`\`\`
|
|
1280
|
+
|
|
1281
|
+
## Symbol References (v2)
|
|
1282
|
+
|
|
1283
|
+
- Reference components: \`#component-name\`
|
|
1284
|
+
- Reference flows: \`$flow-name\`
|
|
1285
|
+
- Reference gates: \`^gate-name\`
|
|
1286
|
+
- Reference signals: \`!signal-name\`
|
|
1287
|
+
- Reference aspects: \`~aspect-name\`
|
|
1288
|
+
`;
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Portal instructions
|
|
1292
|
+
*/
|
|
1293
|
+
generatePortalInstructions() {
|
|
1294
|
+
return frontmatter2("**/portal.yaml") + `# Portal Configuration
|
|
1295
|
+
|
|
1296
|
+
Portal files (\`portal.yaml\`) define authorization topology.
|
|
1297
|
+
|
|
1298
|
+
## Format
|
|
1299
|
+
|
|
1300
|
+
\`\`\`yaml
|
|
1301
|
+
version: "1.0"
|
|
1302
|
+
|
|
1303
|
+
gates:
|
|
1304
|
+
gate-name:
|
|
1305
|
+
description: What this gate protects
|
|
1306
|
+
locks:
|
|
1307
|
+
- id: lock-id
|
|
1308
|
+
description: Requirement description
|
|
1309
|
+
keys:
|
|
1310
|
+
- expression: "user.authenticated"
|
|
1311
|
+
description: User must be logged in
|
|
1312
|
+
prizes:
|
|
1313
|
+
- id: prize-id
|
|
1314
|
+
oneTime: true
|
|
1315
|
+
metadata:
|
|
1316
|
+
event: "gate_passed"
|
|
1317
|
+
|
|
1318
|
+
flows:
|
|
1319
|
+
flow-name:
|
|
1320
|
+
description: User journey
|
|
1321
|
+
gates: [gate1, gate2, gate3]
|
|
1322
|
+
\`\`\`
|
|
1323
|
+
|
|
1324
|
+
## Portal Validation
|
|
1325
|
+
|
|
1326
|
+
Use the Portal Validator for authorization checks:
|
|
1327
|
+
|
|
1328
|
+
\`\`\`typescript
|
|
1329
|
+
import { portal } from '@a-company/portal-sdk/validator';
|
|
1330
|
+
|
|
1331
|
+
const gate = portal.check('^gate-name')
|
|
1332
|
+
.requires('requirement description')
|
|
1333
|
+
.context({ userId, role });
|
|
1334
|
+
|
|
1335
|
+
if (!condition) {
|
|
1336
|
+
gate.deny('Reason for denial');
|
|
1337
|
+
return redirect('/unauthorized');
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
gate.allow('Access granted');
|
|
1341
|
+
\`\`\`
|
|
1342
|
+
`;
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Conventions instructions
|
|
1346
|
+
*/
|
|
1347
|
+
generateConventionsInstructions(config) {
|
|
1348
|
+
return frontmatter2("**/*.ts,**/*.tsx,**/*.js,**/*.jsx") + `# Paradigm Conventions
|
|
1349
|
+
|
|
1350
|
+
${generateConventions(config)}
|
|
1351
|
+
`;
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Commands reference instructions
|
|
1355
|
+
*/
|
|
1356
|
+
generateCommandsInstructions() {
|
|
1357
|
+
return `# Paradigm CLI Commands
|
|
1358
|
+
|
|
1359
|
+
${generateCommandsReference()}
|
|
1360
|
+
`;
|
|
1361
|
+
}
|
|
1362
|
+
/**
|
|
1363
|
+
* Agent Hints instructions - when to query CLI
|
|
1364
|
+
*/
|
|
1365
|
+
generateAgentHintsInstructions() {
|
|
1366
|
+
return `# Agent CLI Queries (Token-Efficient)
|
|
1367
|
+
|
|
1368
|
+
Instead of reading large context files, query Paradigm CLI on-demand for fresh, precise data.
|
|
1369
|
+
|
|
1370
|
+
## When to Query
|
|
1371
|
+
|
|
1372
|
+
| Before doing this... | Run this command |
|
|
1373
|
+
|---------------------|------------------|
|
|
1374
|
+
| Modifying a symbol | \`paradigm ripple #symbol --json\` |
|
|
1375
|
+
| Debugging an error | \`paradigm echo ERROR_CODE --json\` |
|
|
1376
|
+
| Starting a session | \`paradigm thread --json\` |
|
|
1377
|
+
| Understanding relationships | \`paradigm constellation\` |
|
|
1378
|
+
| Getting oriented | \`paradigm beacon --json\` |
|
|
1379
|
+
|
|
1380
|
+
## Query Patterns
|
|
1381
|
+
|
|
1382
|
+
### Before Changing Code
|
|
1383
|
+
|
|
1384
|
+
\`\`\`bash
|
|
1385
|
+
# See what depends on what you're changing
|
|
1386
|
+
paradigm ripple #checkout --json
|
|
1387
|
+
|
|
1388
|
+
# Output includes: upstream deps, downstream effects, flow membership
|
|
1389
|
+
\`\`\`
|
|
1390
|
+
|
|
1391
|
+
### When Debugging
|
|
1392
|
+
|
|
1393
|
+
\`\`\`bash
|
|
1394
|
+
# Look up error context
|
|
1395
|
+
paradigm echo AUTH_REQUIRED --json
|
|
1396
|
+
|
|
1397
|
+
# Then check ripple effects of the related symbol
|
|
1398
|
+
paradigm ripple ^authenticated --json
|
|
1399
|
+
\`\`\`
|
|
1400
|
+
|
|
1401
|
+
### Starting Work
|
|
1402
|
+
|
|
1403
|
+
\`\`\`bash
|
|
1404
|
+
# Check previous session context
|
|
1405
|
+
paradigm thread --json
|
|
1406
|
+
|
|
1407
|
+
# Quick orientation
|
|
1408
|
+
paradigm beacon --json
|
|
1409
|
+
\`\`\`
|
|
1410
|
+
|
|
1411
|
+
### Querying Constellation
|
|
1412
|
+
|
|
1413
|
+
\`\`\`bash
|
|
1414
|
+
# Get specific symbol
|
|
1415
|
+
jq '.stars["#checkout"]' .paradigm/constellation.json
|
|
1416
|
+
|
|
1417
|
+
# Find what requires a gate
|
|
1418
|
+
jq '[.stars | to_entries[] | select(.value.gates[]? == "^authenticated") | .key]' .paradigm/constellation.json
|
|
1419
|
+
|
|
1420
|
+
# List all flows
|
|
1421
|
+
jq '.orbits | keys' .paradigm/constellation.json
|
|
1422
|
+
\`\`\`
|
|
1423
|
+
|
|
1424
|
+
## Benefits
|
|
1425
|
+
|
|
1426
|
+
- **Fresh data**: Always current, not stale from file generation
|
|
1427
|
+
- **Precise**: Only get the data you need
|
|
1428
|
+
- **Token-efficient**: ~100 tokens per query vs ~2000 upfront
|
|
1429
|
+
`;
|
|
1430
|
+
}
|
|
1431
|
+
/**
|
|
1432
|
+
* Commit conventions instructions
|
|
1433
|
+
*/
|
|
1434
|
+
generateCommitsInstructions() {
|
|
1435
|
+
return `# Paradigm Commit Conventions
|
|
1436
|
+
|
|
1437
|
+
${generateCommitConvention()}
|
|
1438
|
+
`;
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
var copilotAdapter = new CopilotAdapter();
|
|
1442
|
+
|
|
1443
|
+
// src/core/ide-adapters/windsurf.ts
|
|
1444
|
+
import * as fs3 from "fs";
|
|
1445
|
+
import * as path3 from "path";
|
|
1446
|
+
var WindsurfAdapter = class {
|
|
1447
|
+
name = "windsurf";
|
|
1448
|
+
displayName = "Windsurf";
|
|
1449
|
+
outputPath = ".windsurfrules";
|
|
1450
|
+
detect(rootDir) {
|
|
1451
|
+
if (fs3.existsSync(path3.join(rootDir, ".windsurfrules"))) {
|
|
1452
|
+
return true;
|
|
1453
|
+
}
|
|
1454
|
+
if (fs3.existsSync(path3.join(rootDir, ".windsurf"))) {
|
|
1455
|
+
return true;
|
|
1456
|
+
}
|
|
1457
|
+
return false;
|
|
1458
|
+
}
|
|
1459
|
+
generate(files) {
|
|
1460
|
+
const { config, projectName } = files;
|
|
1461
|
+
const sections = [];
|
|
1462
|
+
sections.push(generateHeader(projectName, this.displayName));
|
|
1463
|
+
sections.push(generateOverview(config));
|
|
1464
|
+
sections.push(generateSymbolSystem(config));
|
|
1465
|
+
const loggingSection = generateLoggingRules(config);
|
|
1466
|
+
if (loggingSection) {
|
|
1467
|
+
sections.push(loggingSection);
|
|
1468
|
+
}
|
|
1469
|
+
const scanSection = generateScanProtocol(config);
|
|
1470
|
+
if (scanSection) {
|
|
1471
|
+
sections.push(scanSection);
|
|
1472
|
+
}
|
|
1473
|
+
sections.push(generateUpdateRules(config));
|
|
1474
|
+
sections.push(generateConventions(config));
|
|
1475
|
+
sections.push(generateCommitConvention());
|
|
1476
|
+
sections.push(generateCommandsReference());
|
|
1477
|
+
sections.push(generateFooter());
|
|
1478
|
+
return sections.filter((s) => s.trim()).join("\n");
|
|
1479
|
+
}
|
|
1480
|
+
};
|
|
1481
|
+
var windsurfAdapter = new WindsurfAdapter();
|
|
1482
|
+
|
|
1483
|
+
// src/core/ide-adapters/claude.ts
|
|
1484
|
+
import * as fs4 from "fs";
|
|
1485
|
+
import * as path4 from "path";
|
|
1486
|
+
var ClaudeAdapter = class {
|
|
1487
|
+
name = "claude";
|
|
1488
|
+
displayName = "Claude";
|
|
1489
|
+
outputPath = "CLAUDE.md";
|
|
1490
|
+
detect(rootDir) {
|
|
1491
|
+
if (fs4.existsSync(path4.join(rootDir, "CLAUDE.md"))) {
|
|
1492
|
+
return true;
|
|
1493
|
+
}
|
|
1494
|
+
return false;
|
|
1495
|
+
}
|
|
1496
|
+
generate(files) {
|
|
1497
|
+
const { config, projectName } = files;
|
|
1498
|
+
const sections = [];
|
|
1499
|
+
sections.push(`# ${projectName} - Claude Context`);
|
|
1500
|
+
sections.push("");
|
|
1501
|
+
sections.push("> **Paradigm v2.0** | For Claude Code, Claude API, and Claude-native interfaces");
|
|
1502
|
+
sections.push("");
|
|
1503
|
+
sections.push("## Project Overview");
|
|
1504
|
+
sections.push("");
|
|
1505
|
+
if (config["agent-guidelines"]?.overview) {
|
|
1506
|
+
sections.push(config["agent-guidelines"].overview);
|
|
1507
|
+
}
|
|
1508
|
+
sections.push("");
|
|
1509
|
+
sections.push("## Quick Orientation");
|
|
1510
|
+
sections.push("");
|
|
1511
|
+
sections.push("```");
|
|
1512
|
+
sections.push(".paradigm/config.yaml \u2192 Project configuration");
|
|
1513
|
+
sections.push(".paradigm/specs/ \u2192 Detailed specifications");
|
|
1514
|
+
sections.push(".paradigm/docs/ \u2192 Commands, patterns, troubleshooting");
|
|
1515
|
+
sections.push(".cursorrules \u2192 IDE instructions (if using Cursor)");
|
|
1516
|
+
sections.push("portal.yaml \u2192 Security/auth definitions");
|
|
1517
|
+
sections.push("```");
|
|
1518
|
+
sections.push("");
|
|
1519
|
+
sections.push(generateTerminalGuidance());
|
|
1520
|
+
sections.push("## Agent Onboarding");
|
|
1521
|
+
sections.push("");
|
|
1522
|
+
sections.push("**First Session:**");
|
|
1523
|
+
sections.push("1. Call `paradigm_status` for project overview");
|
|
1524
|
+
sections.push("2. Read `.paradigm/config.yaml` for conventions");
|
|
1525
|
+
sections.push("3. Check if `portal.yaml` exists (for auth gates)");
|
|
1526
|
+
sections.push("");
|
|
1527
|
+
sections.push("**Before Each Task:**");
|
|
1528
|
+
sections.push("1. `paradigm_wisdom_context` for symbols you'll modify");
|
|
1529
|
+
sections.push("2. `paradigm_ripple` to check impact");
|
|
1530
|
+
sections.push("3. `paradigm_history_fragility` for stability warnings");
|
|
1531
|
+
sections.push("");
|
|
1532
|
+
sections.push("## Symbol System");
|
|
1533
|
+
sections.push("");
|
|
1534
|
+
sections.push("Use these prefixes in documentation and commits:");
|
|
1535
|
+
sections.push("");
|
|
1536
|
+
sections.push("| Symbol | Meaning | Example |");
|
|
1537
|
+
sections.push("|--------|---------|---------|");
|
|
1538
|
+
const symbolSystem = config["symbol-system"];
|
|
1539
|
+
if (symbolSystem) {
|
|
1540
|
+
for (const [prefix, def] of Object.entries(symbolSystem)) {
|
|
1541
|
+
const example = def.examples?.[0] || `${prefix}example`;
|
|
1542
|
+
sections.push(`| \`${prefix}\` | ${def.name} | \`${example}\` |`);
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
sections.push("");
|
|
1546
|
+
sections.push("## First Actions for New Sessions");
|
|
1547
|
+
sections.push("");
|
|
1548
|
+
sections.push("**Resuming a session:** Call `paradigm_session_recover` for previous session context.");
|
|
1549
|
+
sections.push("");
|
|
1550
|
+
sections.push("1. **Orient:** Call `paradigm_status` to see project overview and available symbols");
|
|
1551
|
+
sections.push("2. **Verify:** Check `.paradigm/config.yaml` for discipline and conventions");
|
|
1552
|
+
sections.push('3. **Locate:** Use `paradigm_navigate` with "context" intent for your task');
|
|
1553
|
+
sections.push("4. **Review:** Read the nearest `.purpose` file before making changes");
|
|
1554
|
+
sections.push("5. **Check:** Call `paradigm_gates_for_route` before adding API endpoints");
|
|
1555
|
+
sections.push("");
|
|
1556
|
+
sections.push("## Before Implementing (Every Task)");
|
|
1557
|
+
sections.push("");
|
|
1558
|
+
sections.push("1. **Is this task complex?** (3+ files, security + implementation, multiple features)");
|
|
1559
|
+
sections.push(' \u2192 Call `paradigm_orchestrate_inline` with mode="plan" BEFORE writing code');
|
|
1560
|
+
sections.push("2. **Does it affect existing symbols?** \u2192 Call `paradigm_ripple`");
|
|
1561
|
+
sections.push("3. **Does it add API endpoints?** \u2192 Call `paradigm_gates_for_route`");
|
|
1562
|
+
sections.push("");
|
|
1563
|
+
sections.push("## Portal Protocol (Authorization)");
|
|
1564
|
+
sections.push("");
|
|
1565
|
+
sections.push("**Portal.yaml is REQUIRED when the project has protected routes.**");
|
|
1566
|
+
sections.push("");
|
|
1567
|
+
sections.push("### When to Create portal.yaml");
|
|
1568
|
+
sections.push("");
|
|
1569
|
+
sections.push("Create `portal.yaml` in project root when:");
|
|
1570
|
+
sections.push("- Adding any endpoint that requires authentication");
|
|
1571
|
+
sections.push("- Adding role-based access (admin, member, owner)");
|
|
1572
|
+
sections.push("- Adding resource ownership checks (user can only edit their own data)");
|
|
1573
|
+
sections.push("");
|
|
1574
|
+
sections.push("### Portal.yaml Structure");
|
|
1575
|
+
sections.push("");
|
|
1576
|
+
sections.push("```yaml");
|
|
1577
|
+
sections.push('version: "1.0"');
|
|
1578
|
+
sections.push("gates:");
|
|
1579
|
+
sections.push(" ^authenticated:");
|
|
1580
|
+
sections.push(" description: User must be logged in");
|
|
1581
|
+
sections.push(" check: req.user != null");
|
|
1582
|
+
sections.push(" ^project-admin:");
|
|
1583
|
+
sections.push(" description: User must be admin of the project");
|
|
1584
|
+
sections.push(" check: project.admins.includes(req.user.id)");
|
|
1585
|
+
sections.push(" ^comment-author:");
|
|
1586
|
+
sections.push(" description: User must be the comment author");
|
|
1587
|
+
sections.push(" check: comment.authorId === req.user.id");
|
|
1588
|
+
sections.push("");
|
|
1589
|
+
sections.push("routes:");
|
|
1590
|
+
sections.push(' "GET /api/projects/:id": [^authenticated, ^project-member]');
|
|
1591
|
+
sections.push(' "PUT /api/projects/:id": [^authenticated, ^project-admin]');
|
|
1592
|
+
sections.push(' "DELETE /api/comments/:id": [^authenticated, ^comment-author]');
|
|
1593
|
+
sections.push("```");
|
|
1594
|
+
sections.push("");
|
|
1595
|
+
sections.push("### When Adding New Endpoints");
|
|
1596
|
+
sections.push("");
|
|
1597
|
+
sections.push("**ALWAYS update portal.yaml when adding routes:**");
|
|
1598
|
+
sections.push("");
|
|
1599
|
+
sections.push("1. Call `paradigm_gates_for_route` to get suggestions");
|
|
1600
|
+
sections.push("2. Add the route to portal.yaml with required gates");
|
|
1601
|
+
sections.push("3. Implement the gate checks in your middleware/code");
|
|
1602
|
+
sections.push("4. Test that unauthorized access returns 403");
|
|
1603
|
+
sections.push("");
|
|
1604
|
+
sections.push("### Common Gate Patterns");
|
|
1605
|
+
sections.push("");
|
|
1606
|
+
sections.push("| Pattern | Gate Name | Description |");
|
|
1607
|
+
sections.push("|---------|-----------|-------------|");
|
|
1608
|
+
sections.push("| Any logged-in user | `^authenticated` | Basic auth check |");
|
|
1609
|
+
sections.push("| Resource membership | `^{resource}-member` | User is member of resource |");
|
|
1610
|
+
sections.push("| Resource admin | `^{resource}-admin` | User is admin of resource |");
|
|
1611
|
+
sections.push("| Resource owner | `^{resource}-owner` | User owns the resource |");
|
|
1612
|
+
sections.push("| Author only | `^{resource}-author` | User created the resource |");
|
|
1613
|
+
sections.push("");
|
|
1614
|
+
sections.push("## Context Discovery");
|
|
1615
|
+
sections.push("");
|
|
1616
|
+
sections.push("**Before making changes:**");
|
|
1617
|
+
sections.push("");
|
|
1618
|
+
sections.push("1. Check `.paradigm/config.yaml` for project configuration");
|
|
1619
|
+
sections.push("2. Read the `.purpose` file in the directory you're modifying");
|
|
1620
|
+
sections.push("3. Check `portal.yaml` for existing auth gates");
|
|
1621
|
+
sections.push("4. Check `.paradigm/docs/patterns.md` for coding patterns");
|
|
1622
|
+
sections.push("");
|
|
1623
|
+
sections.push(generateNavigationSection(config));
|
|
1624
|
+
sections.push("## Context Monitoring Protocol");
|
|
1625
|
+
sections.push("");
|
|
1626
|
+
sections.push("**Periodically check context usage** by calling `paradigm_context_check` (every 10-15 tool calls or when user asks).");
|
|
1627
|
+
sections.push("");
|
|
1628
|
+
sections.push('**When recommendation is NOT "continue":**');
|
|
1629
|
+
sections.push('1. Inform user: "Context usage is at ~X%. Recommend handoff soon."');
|
|
1630
|
+
sections.push("2. Offer to prepare handoff summary");
|
|
1631
|
+
sections.push("3. If urgent (>85%), prioritize completing current task then handoff");
|
|
1632
|
+
sections.push("");
|
|
1633
|
+
sections.push("**To handoff:**");
|
|
1634
|
+
sections.push("1. Call `paradigm_handoff_prepare` with summary and next steps");
|
|
1635
|
+
sections.push('2. User runs: `paradigm team handoff --to <agent> --summary "..."`');
|
|
1636
|
+
sections.push("3. New session accepts with: `paradigm team accept <id>`");
|
|
1637
|
+
sections.push("");
|
|
1638
|
+
sections.push(generateCheckpointProtocol());
|
|
1639
|
+
sections.push("## MCP Workflow Protocol");
|
|
1640
|
+
sections.push("");
|
|
1641
|
+
sections.push("**Query before modifying** - Use MCP tools for token-efficient, fresh data:");
|
|
1642
|
+
sections.push("");
|
|
1643
|
+
sections.push("| Before doing this... | Call this tool |");
|
|
1644
|
+
sections.push("|---------------------|----------------|");
|
|
1645
|
+
sections.push("| Modifying a symbol | `paradigm_ripple` with the symbol |");
|
|
1646
|
+
sections.push("| Understanding code | `paradigm_navigate` with explore intent |");
|
|
1647
|
+
sections.push("| Checking dependencies | `paradigm_related` for connections |");
|
|
1648
|
+
sections.push("| Getting oriented | `paradigm_status` for project overview |");
|
|
1649
|
+
sections.push("| **Adding API endpoint** | `paradigm_gates_for_route` for auth gates |");
|
|
1650
|
+
sections.push("| **Validating changes** | `paradigm_flows_affected` for flow impact |");
|
|
1651
|
+
sections.push("| **Getting test data** | `paradigm_test_fixtures` for fixtures |");
|
|
1652
|
+
sections.push('| **Building a feature (3+ files)** | `paradigm_orchestrate_inline` mode="plan" |');
|
|
1653
|
+
sections.push('| **Task involves security + code** | `paradigm_orchestrate_inline` mode="plan" |');
|
|
1654
|
+
sections.push("| **Finishing work session** | `paradigm_reindex` to rebuild static index |");
|
|
1655
|
+
sections.push("");
|
|
1656
|
+
sections.push("**Benefits**: ~100 tokens per query vs ~2000 for reading files. Always fresh data from live index.");
|
|
1657
|
+
sections.push("");
|
|
1658
|
+
sections.push("**Authorization workflow:**");
|
|
1659
|
+
sections.push("1. Adding endpoint? \u2192 Call `paradigm_gates_for_route`");
|
|
1660
|
+
sections.push("2. Get suggested gates \u2192 Add them to `portal.yaml`");
|
|
1661
|
+
sections.push("3. Implement gate checks \u2192 Test 403 responses");
|
|
1662
|
+
sections.push("");
|
|
1663
|
+
sections.push("## Token Budget Reference");
|
|
1664
|
+
sections.push("");
|
|
1665
|
+
sections.push("| Operation | Typical Tokens | Use When |");
|
|
1666
|
+
sections.push("|-----------|---------------|----------|");
|
|
1667
|
+
sections.push("| `paradigm_status` | ~100 | Starting a session |");
|
|
1668
|
+
sections.push("| `paradigm_search` | ~150 | Looking for symbols |");
|
|
1669
|
+
sections.push("| `paradigm_navigate` | ~200 | Finding code locations |");
|
|
1670
|
+
sections.push("| `paradigm_ripple` | ~300 | Before modifying symbols |");
|
|
1671
|
+
sections.push("| `paradigm_gates_for_route` | ~150 | Adding API endpoints |");
|
|
1672
|
+
sections.push("| File read (small) | ~500 | Need exact code |");
|
|
1673
|
+
sections.push("| File read (large) | ~2000+ | Avoid if possible |");
|
|
1674
|
+
sections.push("| Full .purpose + config | ~1500 | Initial orientation |");
|
|
1675
|
+
sections.push("");
|
|
1676
|
+
sections.push("**Tip**: Prefer MCP queries over file reads. Check `paradigm_session_stats` for actual usage.");
|
|
1677
|
+
sections.push("");
|
|
1678
|
+
sections.push("### When to Use MCP vs File Reads");
|
|
1679
|
+
sections.push("");
|
|
1680
|
+
sections.push("| Need | Use MCP | Use File Read |");
|
|
1681
|
+
sections.push("|------|---------|---------------|");
|
|
1682
|
+
sections.push("| Find symbol | `paradigm_navigate` | Never |");
|
|
1683
|
+
sections.push("| Check impact | `paradigm_ripple` | Never |");
|
|
1684
|
+
sections.push("| Read implementation | MCP first | Then specific file |");
|
|
1685
|
+
sections.push("| Write code | N/A | Existing patterns |");
|
|
1686
|
+
sections.push("| Check team wisdom | `paradigm_wisdom_context` | Never |");
|
|
1687
|
+
sections.push("");
|
|
1688
|
+
sections.push("**Rule**: MCP for discovery, files for implementation.");
|
|
1689
|
+
sections.push("");
|
|
1690
|
+
sections.push("## MCP Resources (On-Demand Content)");
|
|
1691
|
+
sections.push("");
|
|
1692
|
+
sections.push("Reference content is served via MCP resources instead of being stored locally:");
|
|
1693
|
+
sections.push("");
|
|
1694
|
+
sections.push("| Resource | URI | Content |");
|
|
1695
|
+
sections.push("|----------|-----|---------|");
|
|
1696
|
+
sections.push("| Prompts | `paradigm://prompts` | Task templates (add-feature, refactor, etc.) |");
|
|
1697
|
+
sections.push("| Commands | `paradigm://docs/commands` | CLI command reference |");
|
|
1698
|
+
sections.push("| Queries | `paradigm://docs/queries` | jq query examples |");
|
|
1699
|
+
sections.push("| Disciplines | `paradigm://specs/disciplines` | Symbol mappings by domain |");
|
|
1700
|
+
sections.push("| Scan | `paradigm://specs/scan` | Visual discovery protocol |");
|
|
1701
|
+
sections.push("");
|
|
1702
|
+
sections.push("**Usage**: Read resources with `paradigm://prompts/{name}` (e.g., `paradigm://prompts/add-feature`).");
|
|
1703
|
+
sections.push("");
|
|
1704
|
+
sections.push("**Session Tracking**: Call `paradigm_session_stats` to see token usage and cost breakdown.");
|
|
1705
|
+
sections.push("");
|
|
1706
|
+
if (config["purpose-required"]?.length) {
|
|
1707
|
+
sections.push("## Directory Structure");
|
|
1708
|
+
sections.push("");
|
|
1709
|
+
sections.push("`.purpose` files exist in:");
|
|
1710
|
+
for (const req of config["purpose-required"]) {
|
|
1711
|
+
sections.push(`- \`${req.pattern}\``);
|
|
1712
|
+
}
|
|
1713
|
+
sections.push("");
|
|
1714
|
+
}
|
|
1715
|
+
const loggingSection = generateLoggingRules(config);
|
|
1716
|
+
if (loggingSection) {
|
|
1717
|
+
sections.push(loggingSection);
|
|
1718
|
+
}
|
|
1719
|
+
const conventionsSection = generateConventions(config);
|
|
1720
|
+
if (conventionsSection) {
|
|
1721
|
+
sections.push(conventionsSection);
|
|
1722
|
+
}
|
|
1723
|
+
const updateSection = generateUpdateRules(config);
|
|
1724
|
+
if (updateSection) {
|
|
1725
|
+
sections.push(updateSection);
|
|
1726
|
+
}
|
|
1727
|
+
sections.push("## Multi-Agent Orchestration");
|
|
1728
|
+
sections.push("");
|
|
1729
|
+
sections.push("Paradigm supports multi-agent orchestration via `paradigm team` commands:");
|
|
1730
|
+
sections.push("");
|
|
1731
|
+
sections.push("### Commands");
|
|
1732
|
+
sections.push("");
|
|
1733
|
+
sections.push("| Command | Description |");
|
|
1734
|
+
sections.push("|---------|-------------|");
|
|
1735
|
+
sections.push('| `paradigm team spawn <agent> --task "..."` | Spawn a single agent |');
|
|
1736
|
+
sections.push('| `paradigm team orchestrate "task"` | AI orchestrator coordinates agents |');
|
|
1737
|
+
sections.push('| `paradigm team orchestrate "task" --solo` | Single Claude mode (no splitting) |');
|
|
1738
|
+
sections.push('| `paradigm team orchestrate "task" --compare` | A/B test solo vs faceted |');
|
|
1739
|
+
sections.push('| `paradigm team agents suggest "task"` | Suggest agents based on task triggers |');
|
|
1740
|
+
sections.push("| `paradigm team providers` | Show available providers |");
|
|
1741
|
+
sections.push("| `paradigm team providers --set X` | Set preferred provider |");
|
|
1742
|
+
sections.push("| `paradigm team models` | View/configure agent model assignments |");
|
|
1743
|
+
sections.push("| `paradigm team models --refresh` | Re-discover models from environment |");
|
|
1744
|
+
sections.push("");
|
|
1745
|
+
sections.push("### Agent Suggestions");
|
|
1746
|
+
sections.push("");
|
|
1747
|
+
sections.push("Before orchestrating, you can preview which agents will be involved:");
|
|
1748
|
+
sections.push("");
|
|
1749
|
+
sections.push("```bash");
|
|
1750
|
+
sections.push('paradigm team agents suggest "Add user authentication with JWT"');
|
|
1751
|
+
sections.push("```");
|
|
1752
|
+
sections.push("");
|
|
1753
|
+
sections.push("Or via MCP (returns `suggestedAgents` in plan mode):");
|
|
1754
|
+
sections.push("```");
|
|
1755
|
+
sections.push('paradigm_orchestrate_inline({ task: "...", mode: "plan" })');
|
|
1756
|
+
sections.push("```");
|
|
1757
|
+
sections.push("");
|
|
1758
|
+
sections.push("## Flow-First Development");
|
|
1759
|
+
sections.push("");
|
|
1760
|
+
sections.push("**Define flows BEFORE implementing features that span multiple steps.**");
|
|
1761
|
+
sections.push("");
|
|
1762
|
+
sections.push("### When to Define Flows");
|
|
1763
|
+
sections.push("");
|
|
1764
|
+
sections.push("Create a flow ($symbol) when your feature:");
|
|
1765
|
+
sections.push("- Has multiple authorization gates");
|
|
1766
|
+
sections.push("- Spans multiple components or services");
|
|
1767
|
+
sections.push("- Emits events that trigger other actions");
|
|
1768
|
+
sections.push('- Needs clear documentation of the "happy path"');
|
|
1769
|
+
sections.push("");
|
|
1770
|
+
sections.push("### Flow Definition");
|
|
1771
|
+
sections.push("");
|
|
1772
|
+
sections.push("Define flows in `.paradigm/flows.yaml`:");
|
|
1773
|
+
sections.push("");
|
|
1774
|
+
sections.push("```yaml");
|
|
1775
|
+
sections.push('version: "1.0"');
|
|
1776
|
+
sections.push("flows:");
|
|
1777
|
+
sections.push(" $task-creation:");
|
|
1778
|
+
sections.push(" name: Task Creation Flow");
|
|
1779
|
+
sections.push(' trigger: "POST /api/tasks"');
|
|
1780
|
+
sections.push(" steps:");
|
|
1781
|
+
sections.push(" - type: gate");
|
|
1782
|
+
sections.push(" symbol: ^authenticated");
|
|
1783
|
+
sections.push(" - type: gate");
|
|
1784
|
+
sections.push(" symbol: ^project-member");
|
|
1785
|
+
sections.push(" - type: action");
|
|
1786
|
+
sections.push(' symbol: "#create-task"');
|
|
1787
|
+
sections.push(" - type: signal");
|
|
1788
|
+
sections.push(' symbol: "!task-created"');
|
|
1789
|
+
sections.push(' successSignal: "!task-created"');
|
|
1790
|
+
sections.push("```");
|
|
1791
|
+
sections.push("");
|
|
1792
|
+
sections.push("### Flow-First Protocol");
|
|
1793
|
+
sections.push("");
|
|
1794
|
+
sections.push("1. **Define the flow first** - What gates, actions, and signals?");
|
|
1795
|
+
sections.push("2. **Validate** - Call `paradigm_flow_validate` to check completeness");
|
|
1796
|
+
sections.push("3. **Implement** - Each step becomes a clear implementation target");
|
|
1797
|
+
sections.push("");
|
|
1798
|
+
sections.push("## Flow Validation");
|
|
1799
|
+
sections.push("");
|
|
1800
|
+
sections.push("**Validate flows before and after implementing:**");
|
|
1801
|
+
sections.push("");
|
|
1802
|
+
sections.push("```");
|
|
1803
|
+
sections.push("# Validate specific flow");
|
|
1804
|
+
sections.push('paradigm_flow_validate({ flowId: "$task-creation" })');
|
|
1805
|
+
sections.push("");
|
|
1806
|
+
sections.push("# Validate all flows");
|
|
1807
|
+
sections.push("paradigm_flow_validate({})");
|
|
1808
|
+
sections.push("");
|
|
1809
|
+
sections.push("# Deep check (verify implementation exists)");
|
|
1810
|
+
sections.push("paradigm_flow_validate({ checkImplementation: true })");
|
|
1811
|
+
sections.push("```");
|
|
1812
|
+
sections.push("");
|
|
1813
|
+
sections.push("**After modifying symbols, check affected flows:**");
|
|
1814
|
+
sections.push("");
|
|
1815
|
+
sections.push("```");
|
|
1816
|
+
sections.push("# Check what flows are affected by #tasks");
|
|
1817
|
+
sections.push('paradigm_flows_affected({ symbol: "#tasks" })');
|
|
1818
|
+
sections.push("```");
|
|
1819
|
+
sections.push("");
|
|
1820
|
+
sections.push(generateCommitConvention());
|
|
1821
|
+
sections.push("## Automatic Enforcement (Claude Code Hooks)");
|
|
1822
|
+
sections.push("");
|
|
1823
|
+
sections.push("This project uses Claude Code hooks for paradigm compliance. These are installed");
|
|
1824
|
+
sections.push("automatically via `paradigm shift` or `paradigm hooks install`.");
|
|
1825
|
+
sections.push("");
|
|
1826
|
+
sections.push("| Hook | Type | Behavior |");
|
|
1827
|
+
sections.push("|------|------|----------|");
|
|
1828
|
+
sections.push("| **Stop hook** | Stop | **BLOCKS** you from finishing if source files were modified without .purpose updates |");
|
|
1829
|
+
sections.push("| **Pre-commit hook** | PreToolUse (Bash) | Auto-rebuilds index before `git commit` \u2014 never blocks |");
|
|
1830
|
+
sections.push("| **Post-write hook** | PostToolUse (Edit/Write) | Advisory reminder when editing files without .purpose coverage |");
|
|
1831
|
+
sections.push("");
|
|
1832
|
+
sections.push("**If the Stop hook blocks you:**");
|
|
1833
|
+
sections.push("1. Update the nearest `.purpose` file for each modified code area");
|
|
1834
|
+
sections.push("2. Update `portal.yaml` if you added routes or gates");
|
|
1835
|
+
sections.push("3. Call `paradigm_reindex` to rebuild the static index");
|
|
1836
|
+
sections.push("4. Then finish your session");
|
|
1837
|
+
sections.push("");
|
|
1838
|
+
sections.push("## Troubleshooting");
|
|
1839
|
+
sections.push("");
|
|
1840
|
+
sections.push("| Issue | Solution |");
|
|
1841
|
+
sections.push("|-------|----------|");
|
|
1842
|
+
sections.push('| "Symbol not found" | Run `paradigm scan` to rebuild index |');
|
|
1843
|
+
sections.push('| "Navigator not found" | Run `paradigm scan` to generate navigator.yaml |');
|
|
1844
|
+
sections.push("| Empty search results | Check that .purpose files define symbols |");
|
|
1845
|
+
sections.push("| High context usage | Call `paradigm_handoff_prepare` |");
|
|
1846
|
+
sections.push("| Gate suggestions missing | Check that portal.yaml exists and defines gates |");
|
|
1847
|
+
sections.push('| "Flow index not found" | Run `paradigm scan` and add flows to .purpose files |');
|
|
1848
|
+
sections.push('| "Fixtures not found" | Create `.paradigm/fixtures.yaml` with test data |');
|
|
1849
|
+
sections.push("");
|
|
1850
|
+
sections.push("## Maintaining Paradigm Files");
|
|
1851
|
+
sections.push("");
|
|
1852
|
+
sections.push("**You MUST update Paradigm files when making code changes. The Stop hook will block you if you don't:**");
|
|
1853
|
+
sections.push("");
|
|
1854
|
+
sections.push("| Change Type | Action Required |");
|
|
1855
|
+
sections.push("|-------------|-----------------|");
|
|
1856
|
+
sections.push("| Add feature | Create `.purpose` in feature directory |");
|
|
1857
|
+
sections.push("| Add ANY protected route | Create/update `portal.yaml` with gates |");
|
|
1858
|
+
sections.push("| Add ownership check | Add `^{resource}-owner` gate to `portal.yaml` |");
|
|
1859
|
+
sections.push("| Add role-based access | Add `^{role}` gate to `portal.yaml` |");
|
|
1860
|
+
sections.push("| Add signal/event | Add to emitting feature's `.purpose` |");
|
|
1861
|
+
sections.push("| Add multi-step flow | Document as `$flow` in `.purpose` |");
|
|
1862
|
+
sections.push("| Rename/delete symbol | Update all `.purpose` references |");
|
|
1863
|
+
sections.push("| Learn antipattern | Add to `.paradigm/wisdom/antipatterns.yaml` |");
|
|
1864
|
+
sections.push("");
|
|
1865
|
+
sections.push("**CRITICAL: Authorization requires portal.yaml**");
|
|
1866
|
+
sections.push("");
|
|
1867
|
+
sections.push("If your code has ANY of these, `portal.yaml` MUST exist:");
|
|
1868
|
+
sections.push("- JWT/session authentication");
|
|
1869
|
+
sections.push("- Role checks (admin, member, etc.)");
|
|
1870
|
+
sections.push("- Ownership checks (user can only edit own resources)");
|
|
1871
|
+
sections.push("- Protected API endpoints");
|
|
1872
|
+
sections.push("");
|
|
1873
|
+
sections.push("**Validation**: Run `paradigm doctor` to check for inconsistencies.");
|
|
1874
|
+
sections.push("");
|
|
1875
|
+
sections.push("See `.paradigm/docs/ai-maintenance-protocol.md` for detailed guidance.");
|
|
1876
|
+
sections.push("");
|
|
1877
|
+
sections.push("---");
|
|
1878
|
+
sections.push("");
|
|
1879
|
+
sections.push("*See `.cursorrules` for IDE-specific instructions, `.paradigm/specs/` for detailed specifications.*");
|
|
1880
|
+
return sections.filter((s) => s !== void 0).join("\n");
|
|
1881
|
+
}
|
|
1882
|
+
/**
|
|
1883
|
+
* Generate MCP configuration for Claude
|
|
1884
|
+
*/
|
|
1885
|
+
generateMcpConfig(rootDir) {
|
|
1886
|
+
return {
|
|
1887
|
+
mcpServers: {
|
|
1888
|
+
paradigm: {
|
|
1889
|
+
command: "paradigm-mcp",
|
|
1890
|
+
args: ["."],
|
|
1891
|
+
cwd: rootDir
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
};
|
|
1895
|
+
}
|
|
1896
|
+
/**
|
|
1897
|
+
* Generate nested CLAUDE.md files for directories with .purpose files
|
|
1898
|
+
*/
|
|
1899
|
+
generateNestedContexts(rootDir, files) {
|
|
1900
|
+
const generatedFiles = [];
|
|
1901
|
+
const purposeFiles = findPurposeFiles(rootDir);
|
|
1902
|
+
for (const purposePath of purposeFiles) {
|
|
1903
|
+
const dirPath = path4.dirname(purposePath);
|
|
1904
|
+
const relativePath = path4.relative(rootDir, dirPath);
|
|
1905
|
+
if (relativePath === "" || relativePath === ".") continue;
|
|
1906
|
+
const purposeContent = fs4.readFileSync(purposePath, "utf8");
|
|
1907
|
+
const contextContent = this.generateDirectoryContext(relativePath, purposeContent, files);
|
|
1908
|
+
generatedFiles.push({
|
|
1909
|
+
path: path4.join(relativePath, "CLAUDE.md"),
|
|
1910
|
+
content: contextContent
|
|
1911
|
+
});
|
|
1912
|
+
}
|
|
1913
|
+
return generatedFiles;
|
|
1914
|
+
}
|
|
1915
|
+
/**
|
|
1916
|
+
* Generate context for a specific directory
|
|
1917
|
+
*/
|
|
1918
|
+
generateDirectoryContext(dirPath, purposeContent, files) {
|
|
1919
|
+
const sections = [];
|
|
1920
|
+
const dirName = path4.basename(dirPath);
|
|
1921
|
+
sections.push(`# ${dirName} - Directory Context`);
|
|
1922
|
+
sections.push("");
|
|
1923
|
+
sections.push(`> Part of ${files.projectName} | See root CLAUDE.md for project overview`);
|
|
1924
|
+
sections.push("");
|
|
1925
|
+
sections.push("## Purpose");
|
|
1926
|
+
sections.push("");
|
|
1927
|
+
sections.push("```yaml");
|
|
1928
|
+
sections.push(purposeContent.trim());
|
|
1929
|
+
sections.push("```");
|
|
1930
|
+
sections.push("");
|
|
1931
|
+
sections.push("## Quick Reference");
|
|
1932
|
+
sections.push("");
|
|
1933
|
+
sections.push(`- **Path**: \`${dirPath}\``);
|
|
1934
|
+
sections.push("- **Config**: See `.paradigm/config.yaml`");
|
|
1935
|
+
sections.push("- **Patterns**: See `.paradigm/docs/patterns.md`");
|
|
1936
|
+
sections.push("");
|
|
1937
|
+
sections.push("## Symbols");
|
|
1938
|
+
sections.push("");
|
|
1939
|
+
sections.push("`#` component | `$` flow | `^` gate | `!` signal | `~` aspect");
|
|
1940
|
+
sections.push("");
|
|
1941
|
+
sections.push("---");
|
|
1942
|
+
sections.push("");
|
|
1943
|
+
sections.push("*Auto-generated by `paradigm sync claude`. Edit .purpose file to update.*");
|
|
1944
|
+
return sections.join("\n");
|
|
1945
|
+
}
|
|
1946
|
+
};
|
|
1947
|
+
function findPurposeFiles(dir) {
|
|
1948
|
+
const results = [];
|
|
1949
|
+
function walk(currentDir) {
|
|
1950
|
+
const entries = fs4.readdirSync(currentDir, { withFileTypes: true });
|
|
1951
|
+
for (const entry of entries) {
|
|
1952
|
+
const fullPath = path4.join(currentDir, entry.name);
|
|
1953
|
+
if (entry.isDirectory()) {
|
|
1954
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
1955
|
+
walk(fullPath);
|
|
1956
|
+
} else if (entry.name === ".purpose") {
|
|
1957
|
+
results.push(fullPath);
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
walk(dir);
|
|
1962
|
+
return results;
|
|
1963
|
+
}
|
|
1964
|
+
var claudeAdapter = new ClaudeAdapter();
|
|
1965
|
+
|
|
1966
|
+
// src/core/ide-adapters/agents.ts
|
|
1967
|
+
import * as fs5 from "fs";
|
|
1968
|
+
import * as path5 from "path";
|
|
1969
|
+
var AgentsAdapter = class {
|
|
1970
|
+
name = "agents";
|
|
1971
|
+
displayName = "AGENTS.md";
|
|
1972
|
+
outputPath = "AGENTS.md";
|
|
1973
|
+
multiFile = false;
|
|
1974
|
+
detect(rootDir) {
|
|
1975
|
+
return fs5.existsSync(path5.join(rootDir, "AGENTS.md"));
|
|
1976
|
+
}
|
|
1977
|
+
generate(files) {
|
|
1978
|
+
const { config, projectName } = files;
|
|
1979
|
+
const sections = [];
|
|
1980
|
+
sections.push(`# ${projectName} - AI Agent Instructions`);
|
|
1981
|
+
sections.push("");
|
|
1982
|
+
sections.push("> Generated by [Paradigm](https://github.com/anthropics/paradigm) v2.0 | Universal AI agent instruction file");
|
|
1983
|
+
sections.push("");
|
|
1984
|
+
sections.push(generateOverview(config));
|
|
1985
|
+
sections.push(generateSymbolSystem(config));
|
|
1986
|
+
const conventionsSection = generateConventions(config);
|
|
1987
|
+
if (conventionsSection) {
|
|
1988
|
+
sections.push(conventionsSection);
|
|
1989
|
+
}
|
|
1990
|
+
const loggingSection = generateLoggingRules(config);
|
|
1991
|
+
if (loggingSection) {
|
|
1992
|
+
sections.push(loggingSection);
|
|
1993
|
+
}
|
|
1994
|
+
sections.push(generateMcpToolReference());
|
|
1995
|
+
sections.push(generateNavigationSection(config));
|
|
1996
|
+
sections.push(generateWorkflowProtocol());
|
|
1997
|
+
sections.push(generateCommitConvention());
|
|
1998
|
+
sections.push(generateHandoffProtocol());
|
|
1999
|
+
const updateSection = generateUpdateRules(config);
|
|
2000
|
+
if (updateSection) {
|
|
2001
|
+
sections.push(updateSection);
|
|
2002
|
+
}
|
|
2003
|
+
sections.push(generateCommandsReference());
|
|
2004
|
+
sections.push("---");
|
|
2005
|
+
sections.push("");
|
|
2006
|
+
sections.push("*Generated by Paradigm. Run `paradigm sync agents` to regenerate.*");
|
|
2007
|
+
return sections.filter((s) => s !== void 0 && s !== "").join("\n");
|
|
2008
|
+
}
|
|
2009
|
+
};
|
|
2010
|
+
var agentsAdapter = new AgentsAdapter();
|
|
2011
|
+
|
|
2012
|
+
// src/core/ide-adapters/index.ts
|
|
2013
|
+
var adapters = /* @__PURE__ */ new Map([
|
|
2014
|
+
["cursor", cursorAdapter],
|
|
2015
|
+
["copilot", copilotAdapter],
|
|
2016
|
+
["windsurf", windsurfAdapter],
|
|
2017
|
+
["claude", claudeAdapter],
|
|
2018
|
+
["agents", agentsAdapter]
|
|
2019
|
+
]);
|
|
2020
|
+
function getAdapter(name) {
|
|
2021
|
+
return adapters.get(name.toLowerCase());
|
|
2022
|
+
}
|
|
2023
|
+
function getAdapterNames() {
|
|
2024
|
+
return Array.from(adapters.keys());
|
|
2025
|
+
}
|
|
2026
|
+
function detectIDE(rootDir) {
|
|
2027
|
+
if (cursorAdapter.detect(rootDir)) {
|
|
2028
|
+
return {
|
|
2029
|
+
detected: "cursor",
|
|
2030
|
+
confidence: "high",
|
|
2031
|
+
reason: "Found .cursor directory or .cursorrules file"
|
|
2032
|
+
};
|
|
2033
|
+
}
|
|
2034
|
+
if (windsurfAdapter.detect(rootDir)) {
|
|
2035
|
+
return {
|
|
2036
|
+
detected: "windsurf",
|
|
2037
|
+
confidence: "high",
|
|
2038
|
+
reason: "Found .windsurf directory or .windsurfrules file"
|
|
2039
|
+
};
|
|
2040
|
+
}
|
|
2041
|
+
if (copilotAdapter.detect(rootDir)) {
|
|
2042
|
+
return {
|
|
2043
|
+
detected: "copilot",
|
|
2044
|
+
confidence: "medium",
|
|
2045
|
+
reason: "Found .github/copilot-instructions.md file"
|
|
2046
|
+
};
|
|
2047
|
+
}
|
|
2048
|
+
if (fs6.existsSync(path6.join(rootDir, ".vscode"))) {
|
|
2049
|
+
return {
|
|
2050
|
+
detected: "cursor",
|
|
2051
|
+
confidence: "low",
|
|
2052
|
+
reason: "Found .vscode directory, defaulting to Cursor format"
|
|
2053
|
+
};
|
|
2054
|
+
}
|
|
2055
|
+
return {
|
|
2056
|
+
detected: null,
|
|
2057
|
+
confidence: "low",
|
|
2058
|
+
reason: "No IDE markers found"
|
|
2059
|
+
};
|
|
2060
|
+
}
|
|
2061
|
+
function loadParadigmFiles(rootDir) {
|
|
2062
|
+
const paradigmDir = path6.join(rootDir, ".paradigm");
|
|
2063
|
+
const paradigmFile = path6.join(rootDir, ".paradigm");
|
|
2064
|
+
let configPath;
|
|
2065
|
+
let specsDir;
|
|
2066
|
+
let docsDir;
|
|
2067
|
+
if (fs6.existsSync(paradigmDir) && fs6.statSync(paradigmDir).isDirectory()) {
|
|
2068
|
+
configPath = path6.join(paradigmDir, "config.yaml");
|
|
2069
|
+
specsDir = path6.join(paradigmDir, "specs");
|
|
2070
|
+
docsDir = path6.join(paradigmDir, "docs");
|
|
2071
|
+
} else if (fs6.existsSync(paradigmFile) && fs6.statSync(paradigmFile).isFile()) {
|
|
2072
|
+
configPath = paradigmFile;
|
|
2073
|
+
specsDir = "";
|
|
2074
|
+
docsDir = "";
|
|
2075
|
+
} else {
|
|
2076
|
+
return null;
|
|
2077
|
+
}
|
|
2078
|
+
if (!fs6.existsSync(configPath)) {
|
|
2079
|
+
return null;
|
|
2080
|
+
}
|
|
2081
|
+
let config;
|
|
2082
|
+
try {
|
|
2083
|
+
const configContent = fs6.readFileSync(configPath, "utf8");
|
|
2084
|
+
config = parseParadigmConfig(configContent);
|
|
2085
|
+
} catch {
|
|
2086
|
+
return null;
|
|
2087
|
+
}
|
|
2088
|
+
const specs = {};
|
|
2089
|
+
if (specsDir && fs6.existsSync(specsDir)) {
|
|
2090
|
+
const specFiles = ["logger.md", "scan.md", "symbols.md"];
|
|
2091
|
+
for (const file of specFiles) {
|
|
2092
|
+
const filePath = path6.join(specsDir, file);
|
|
2093
|
+
if (fs6.existsSync(filePath)) {
|
|
2094
|
+
const key = file.replace(".md", "");
|
|
2095
|
+
specs[key] = fs6.readFileSync(filePath, "utf8");
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
const docs = {};
|
|
2100
|
+
if (docsDir && fs6.existsSync(docsDir)) {
|
|
2101
|
+
const docFiles = ["commands.md", "patterns.md", "troubleshooting.md"];
|
|
2102
|
+
for (const file of docFiles) {
|
|
2103
|
+
const filePath = path6.join(docsDir, file);
|
|
2104
|
+
if (fs6.existsSync(filePath)) {
|
|
2105
|
+
const key = file.replace(".md", "");
|
|
2106
|
+
docs[key] = fs6.readFileSync(filePath, "utf8");
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
return {
|
|
2111
|
+
config,
|
|
2112
|
+
specs,
|
|
2113
|
+
docs,
|
|
2114
|
+
projectName: path6.basename(rootDir)
|
|
2115
|
+
};
|
|
2116
|
+
}
|
|
2117
|
+
function syncToIDE(rootDir, ideName, files, force = false) {
|
|
2118
|
+
const adapter = getAdapter(ideName);
|
|
2119
|
+
if (!adapter) {
|
|
2120
|
+
return {
|
|
2121
|
+
success: false,
|
|
2122
|
+
ide: ideName,
|
|
2123
|
+
outputPath: "",
|
|
2124
|
+
message: `Unknown IDE: ${ideName}. Available: ${getAdapterNames().join(", ")}`
|
|
2125
|
+
};
|
|
2126
|
+
}
|
|
2127
|
+
const outputPath = path6.join(rootDir, adapter.outputPath);
|
|
2128
|
+
try {
|
|
2129
|
+
if (adapter.multiFile && adapter.generateFiles) {
|
|
2130
|
+
return syncMultiFileAdapter(rootDir, adapter, files, force);
|
|
2131
|
+
}
|
|
2132
|
+
if (!force && fs6.existsSync(outputPath)) {
|
|
2133
|
+
}
|
|
2134
|
+
const parentDir = path6.dirname(outputPath);
|
|
2135
|
+
if (!fs6.existsSync(parentDir)) {
|
|
2136
|
+
fs6.mkdirSync(parentDir, { recursive: true });
|
|
2137
|
+
}
|
|
2138
|
+
const content = adapter.generate(files);
|
|
2139
|
+
fs6.writeFileSync(outputPath, content, "utf8");
|
|
2140
|
+
return {
|
|
2141
|
+
success: true,
|
|
2142
|
+
ide: ideName,
|
|
2143
|
+
outputPath,
|
|
2144
|
+
message: `Generated ${adapter.outputPath}`
|
|
2145
|
+
};
|
|
2146
|
+
} catch (error) {
|
|
2147
|
+
return {
|
|
2148
|
+
success: false,
|
|
2149
|
+
ide: ideName,
|
|
2150
|
+
outputPath,
|
|
2151
|
+
message: `Failed to write ${adapter.outputPath}: ${error.message}`
|
|
2152
|
+
};
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
function syncMultiFileAdapter(rootDir, adapter, files, force) {
|
|
2156
|
+
const outputDir = path6.join(rootDir, adapter.outputPath);
|
|
2157
|
+
if (!fs6.existsSync(outputDir)) {
|
|
2158
|
+
fs6.mkdirSync(outputDir, { recursive: true });
|
|
2159
|
+
}
|
|
2160
|
+
const generatedFiles = adapter.generateFiles(files, rootDir);
|
|
2161
|
+
const writtenFiles = [];
|
|
2162
|
+
for (const file of generatedFiles) {
|
|
2163
|
+
let filePath;
|
|
2164
|
+
if (file.path.startsWith("../")) {
|
|
2165
|
+
filePath = path6.join(outputDir, file.path);
|
|
2166
|
+
} else {
|
|
2167
|
+
filePath = path6.join(outputDir, file.path);
|
|
2168
|
+
}
|
|
2169
|
+
const parentDir = path6.dirname(filePath);
|
|
2170
|
+
if (!fs6.existsSync(parentDir)) {
|
|
2171
|
+
fs6.mkdirSync(parentDir, { recursive: true });
|
|
2172
|
+
}
|
|
2173
|
+
if (!force && fs6.existsSync(filePath)) {
|
|
2174
|
+
}
|
|
2175
|
+
fs6.writeFileSync(filePath, file.content, "utf8");
|
|
2176
|
+
writtenFiles.push(file.path);
|
|
2177
|
+
}
|
|
2178
|
+
if (adapter.name === "cursor") {
|
|
2179
|
+
const legacyCursorrules = path6.join(rootDir, ".cursorrules");
|
|
2180
|
+
if (fs6.existsSync(legacyCursorrules)) {
|
|
2181
|
+
const backupPath = path6.join(rootDir, ".cursorrules.bak");
|
|
2182
|
+
if (!fs6.existsSync(backupPath)) {
|
|
2183
|
+
fs6.renameSync(legacyCursorrules, backupPath);
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
const mainDirFiles = writtenFiles.filter((f) => !f.startsWith("../"));
|
|
2188
|
+
const extraFiles = writtenFiles.filter((f) => f.startsWith("../"));
|
|
2189
|
+
let message = `Generated ${mainDirFiles.length} files in ${adapter.outputPath}/`;
|
|
2190
|
+
if (extraFiles.length > 0) {
|
|
2191
|
+
message += ` + ${extraFiles.length} additional file(s)`;
|
|
2192
|
+
}
|
|
2193
|
+
return {
|
|
2194
|
+
success: true,
|
|
2195
|
+
ide: adapter.name,
|
|
2196
|
+
outputPath: outputDir,
|
|
2197
|
+
message
|
|
2198
|
+
};
|
|
2199
|
+
}
|
|
2200
|
+
function syncToAllIDEs(rootDir, files, force = false) {
|
|
2201
|
+
const results = [];
|
|
2202
|
+
for (const [name] of adapters) {
|
|
2203
|
+
results.push(syncToIDE(rootDir, name, files, force));
|
|
2204
|
+
}
|
|
2205
|
+
return results;
|
|
2206
|
+
}
|
|
2207
|
+
function writeMcpConfig(rootDir, ideName) {
|
|
2208
|
+
const adapter = getAdapter(ideName);
|
|
2209
|
+
if (!adapter || !adapter.generateMcpConfig) {
|
|
2210
|
+
return {
|
|
2211
|
+
success: false,
|
|
2212
|
+
path: "",
|
|
2213
|
+
message: `IDE ${ideName} does not support MCP configuration`
|
|
2214
|
+
};
|
|
2215
|
+
}
|
|
2216
|
+
const mcpConfig = adapter.generateMcpConfig(rootDir);
|
|
2217
|
+
let configPath;
|
|
2218
|
+
switch (ideName) {
|
|
2219
|
+
case "cursor":
|
|
2220
|
+
configPath = path6.join(rootDir, ".cursor", "mcp.json");
|
|
2221
|
+
break;
|
|
2222
|
+
case "claude":
|
|
2223
|
+
configPath = path6.join(rootDir, ".mcp.json");
|
|
2224
|
+
break;
|
|
2225
|
+
default:
|
|
2226
|
+
return {
|
|
2227
|
+
success: false,
|
|
2228
|
+
path: "",
|
|
2229
|
+
message: `Unknown MCP config path for ${ideName}`
|
|
2230
|
+
};
|
|
2231
|
+
}
|
|
2232
|
+
try {
|
|
2233
|
+
const parentDir = path6.dirname(configPath);
|
|
2234
|
+
if (!fs6.existsSync(parentDir)) {
|
|
2235
|
+
fs6.mkdirSync(parentDir, { recursive: true });
|
|
2236
|
+
}
|
|
2237
|
+
let existingConfig = {};
|
|
2238
|
+
if (fs6.existsSync(configPath)) {
|
|
2239
|
+
const content = fs6.readFileSync(configPath, "utf8");
|
|
2240
|
+
existingConfig = JSON.parse(content);
|
|
2241
|
+
}
|
|
2242
|
+
const mergedConfig = {
|
|
2243
|
+
...existingConfig,
|
|
2244
|
+
mcpServers: {
|
|
2245
|
+
...existingConfig.mcpServers || {},
|
|
2246
|
+
...mcpConfig.mcpServers
|
|
2247
|
+
}
|
|
2248
|
+
};
|
|
2249
|
+
if (ideName === "claude") {
|
|
2250
|
+
const existingPermissions = existingConfig.permissions || {};
|
|
2251
|
+
const existingAllow = existingPermissions.allow || [];
|
|
2252
|
+
const paradigmPermission = "Bash(paradigm *)";
|
|
2253
|
+
if (!existingAllow.includes(paradigmPermission)) {
|
|
2254
|
+
mergedConfig.permissions = {
|
|
2255
|
+
...existingPermissions,
|
|
2256
|
+
allow: [...existingAllow, paradigmPermission]
|
|
2257
|
+
};
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
fs6.writeFileSync(configPath, JSON.stringify(mergedConfig, null, 2));
|
|
2261
|
+
return {
|
|
2262
|
+
success: true,
|
|
2263
|
+
path: configPath,
|
|
2264
|
+
message: `MCP configuration written to ${path6.relative(rootDir, configPath)}`
|
|
2265
|
+
};
|
|
2266
|
+
} catch (error) {
|
|
2267
|
+
return {
|
|
2268
|
+
success: false,
|
|
2269
|
+
path: configPath,
|
|
2270
|
+
message: `Failed to write MCP config: ${error.message}`
|
|
2271
|
+
};
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
function writeNestedContexts(rootDir, ideName, files) {
|
|
2275
|
+
const adapter = getAdapter(ideName);
|
|
2276
|
+
if (!adapter || !adapter.generateNestedContexts) {
|
|
2277
|
+
return {
|
|
2278
|
+
success: false,
|
|
2279
|
+
count: 0,
|
|
2280
|
+
message: `IDE ${ideName} does not support nested contexts`
|
|
2281
|
+
};
|
|
2282
|
+
}
|
|
2283
|
+
try {
|
|
2284
|
+
const generatedFiles = adapter.generateNestedContexts(rootDir, files);
|
|
2285
|
+
for (const file of generatedFiles) {
|
|
2286
|
+
const filePath = path6.join(rootDir, file.path);
|
|
2287
|
+
const parentDir = path6.dirname(filePath);
|
|
2288
|
+
if (!fs6.existsSync(parentDir)) {
|
|
2289
|
+
fs6.mkdirSync(parentDir, { recursive: true });
|
|
2290
|
+
}
|
|
2291
|
+
fs6.writeFileSync(filePath, file.content, "utf8");
|
|
2292
|
+
}
|
|
2293
|
+
return {
|
|
2294
|
+
success: true,
|
|
2295
|
+
count: generatedFiles.length,
|
|
2296
|
+
message: `Generated ${generatedFiles.length} nested context files`
|
|
2297
|
+
};
|
|
2298
|
+
} catch (error) {
|
|
2299
|
+
return {
|
|
2300
|
+
success: false,
|
|
2301
|
+
count: 0,
|
|
2302
|
+
message: `Failed to write nested contexts: ${error.message}`
|
|
2303
|
+
};
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
export {
|
|
2308
|
+
getAdapter,
|
|
2309
|
+
getAdapterNames,
|
|
2310
|
+
detectIDE,
|
|
2311
|
+
loadParadigmFiles,
|
|
2312
|
+
syncToIDE,
|
|
2313
|
+
syncToAllIDEs,
|
|
2314
|
+
writeMcpConfig,
|
|
2315
|
+
writeNestedContexts
|
|
2316
|
+
};
|