magicpath-ai 1.3.0-beta.2 → 1.3.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +63 -8
  2. package/dist/cli.js +28 -1
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/add.d.ts +49 -0
  5. package/dist/commands/add.js +129 -25
  6. package/dist/commands/add.js.map +1 -1
  7. package/dist/commands/auth.js +33 -2
  8. package/dist/commands/auth.js.map +1 -1
  9. package/dist/commands/clone.js +112 -86
  10. package/dist/commands/clone.js.map +1 -1
  11. package/dist/commands/info.d.ts +2 -0
  12. package/dist/commands/info.js +124 -0
  13. package/dist/commands/info.js.map +1 -0
  14. package/dist/commands/init.d.ts +2 -0
  15. package/dist/commands/init.js +280 -0
  16. package/dist/commands/init.js.map +1 -0
  17. package/dist/commands/integrate.js +282 -81
  18. package/dist/commands/integrate.js.map +1 -1
  19. package/dist/commands/list.d.ts +2 -0
  20. package/dist/commands/list.js +138 -0
  21. package/dist/commands/list.js.map +1 -0
  22. package/dist/commands/schema.d.ts +2 -0
  23. package/dist/commands/schema.js +213 -0
  24. package/dist/commands/schema.js.map +1 -0
  25. package/dist/commands/search.d.ts +2 -0
  26. package/dist/commands/search.js +120 -0
  27. package/dist/commands/search.js.map +1 -0
  28. package/dist/commands/skills.d.ts +2 -0
  29. package/dist/commands/skills.js +55 -0
  30. package/dist/commands/skills.js.map +1 -0
  31. package/dist/commands/view.d.ts +2 -0
  32. package/dist/commands/view.js +27 -0
  33. package/dist/commands/view.js.map +1 -0
  34. package/dist/commands/whoami.d.ts +2 -0
  35. package/dist/commands/whoami.js +58 -0
  36. package/dist/commands/whoami.js.map +1 -0
  37. package/dist/util/api.d.ts +4 -0
  38. package/dist/util/api.js +12 -0
  39. package/dist/util/api.js.map +1 -1
  40. package/dist/util/auth.js +5 -0
  41. package/dist/util/auth.js.map +1 -1
  42. package/dist/util/component.d.ts +8 -8
  43. package/dist/util/diff.d.ts +4 -0
  44. package/dist/util/diff.js +11 -3
  45. package/dist/util/diff.js.map +1 -1
  46. package/dist/util/integrate.d.ts +13 -2
  47. package/dist/util/integrate.js +111 -9
  48. package/dist/util/integrate.js.map +1 -1
  49. package/dist/util/output.d.ts +14 -0
  50. package/dist/util/output.js +27 -0
  51. package/dist/util/output.js.map +1 -0
  52. package/package.json +3 -2
  53. package/skills/magicpath-add-component/SKILL.md +49 -0
  54. package/skills/magicpath-integrate/SKILL.md +50 -0
  55. package/skills/magicpath-list/SKILL.md +38 -0
  56. package/skills/magicpath-shared/SKILL.md +34 -0
@@ -0,0 +1,280 @@
1
+ import path from 'path';
2
+ import fs from 'fs-extra';
3
+ import { isJsonMode, jsonResult } from '../util/output.js';
4
+ import { GREEN_CHECK } from '../util/ui.js';
5
+ // ── Shared content (editor-agnostic) ──────────────────────────────────
6
+ const DESCRIPTION = 'MagicPath is an external platform where the user builds and stores UI components. Use this when the user mentions "magicpath", wants to find/browse/search their MagicPath components, add a MagicPath component, preview a MagicPath component, or integrate one into their project. MagicPath components are NOT in the local git repo — they live on the MagicPath platform and must be fetched via the CLI.';
7
+ const SHARED_BODY = `# MagicPath
8
+
9
+ A platform for building, sharing, and installing UI components via AI. Components are added as source code to the user's project via the \`magicpath-ai\` CLI.
10
+
11
+ ## Getting Started
12
+
13
+ Run \`magicpath-ai info\` to check auth status and project context. If not authenticated, run \`magicpath-ai login\` (interactive) or \`magicpath-ai login --code <code>\` (non-interactive).
14
+
15
+ **In non-interactive contexts (agents, CI), NEVER run \`magicpath-ai login\` without \`--code\` — it opens a browser and hangs waiting for interactive input.**
16
+
17
+ ## Workflow
18
+
19
+ 1. **Check auth** — run \`magicpath-ai whoami\` to verify authentication.
20
+ 2. **Find components** — use \`magicpath-ai search <query>\` to search across all projects, or \`list-projects\` then \`list-components <projectId>\` to browse.
21
+ 3. **Confirm with the user (STOP and wait)** — unless the user specified an exact generatedName, tell the user what you found (name, generatedName, project), open a browser preview with \`magicpath-ai view <generatedName>\`, and ask if it's the right component. If multiple matches, list them all and ask which one. **This is a STOP point — end your response here and wait for the user to reply. Do NOT proceed to steps 4-7 until the user explicitly confirms.** Do not run \`add\` or \`add --inspect\` yet.
22
+ 4. **Inspect source** — only after the user confirms in step 3, use \`magicpath-ai add <generatedName> --inspect\` to see the component's source code without installing. Decide how it needs to be adapted (props to add, behavior to wire up).
23
+ 5. **Add to project** — use \`magicpath-ai add <generatedName> -y\` to install component files. Always pass \`-y\` in non-interactive contexts.
24
+ 6. **Use the component** — after adding, import the component from \`@/components/magicpath/<name>/\` using the \`importStatement\` from the add output. Edit the component file to add props as needed, then render it from the parent.
25
+ 7. **Integrate** — use the \`integrate\` CLI command to wire a component into an existing file via AI.
26
+
27
+ ## Critical Rules
28
+
29
+ - **\`add\` means install-to-use.** Only run \`add\` when you intend to import and render the installed component. If you just want to read the source code, use \`add --inspect\` instead.
30
+ - **After \`add\`, always import the component.** The whole point of \`add\` is to get source files you then import. Never add a component and then copy its styles/markup into another file — import and render the component directly.
31
+ - **MagicPath components are source code you own.** After \`add\`, the component files live in your project at \`src/components/magicpath/<name>/\`. You can and should edit them directly to add props, change behavior, adjust styles, or integrate with your app's state. This is the intended workflow — not copying code out of them.
32
+ - **When a component needs integration:** (1) \`add\` the component, (2) edit the component file to accept the props you need (e.g., \`onSubmit\`, \`placeholder\`, \`className\`), (3) import it from the parent and pass those props. Do NOT copy the component's JSX/styles into the parent file.
33
+ - **\`add --inspect\` for read-only inspection.** Shows full source code without writing any files. Use this when deciding whether a component fits your needs before committing to install.
34
+ - **Never run \`view\` commands in parallel.** The \`view\` command opens a browser window for the user to look at. Only open one preview at a time, and always tell the user what you're opening before running the command.
35
+
36
+ ## Quick Reference
37
+
38
+ \`\`\`bash
39
+ # Auth
40
+ magicpath-ai login --code <code> # non-interactive login
41
+ magicpath-ai whoami # check auth status
42
+ magicpath-ai info # full project context
43
+
44
+ # Find components
45
+ magicpath-ai search "input box" # search across all projects
46
+ magicpath-ai list-projects # list all projects
47
+ magicpath-ai list-components <id> # list components in a project
48
+
49
+ # Inspect components
50
+ magicpath-ai view <generatedName> # preview in browser
51
+ magicpath-ai add <generatedName> --inspect # show source code (no install)
52
+ magicpath-ai add <generatedName> --dry-run # show what would be installed
53
+
54
+ # Install and use components
55
+ magicpath-ai add <generatedName> -y # add to project (no prompts)
56
+ magicpath-ai integrate <name> <file> # AI-powered integration
57
+ \`\`\`
58
+
59
+ ## Key Concepts
60
+
61
+ - Each component has a **generatedName** (e.g., \`wispy-river-5234\`) — this is the identifier for all operations
62
+ - Components are added as source code to \`src/components/magicpath/<name>/\`
63
+ - The \`add\` command returns \`importStatement\` and \`usage\` — use these in code
64
+ - The \`integrate\` command returns modified file contents but does NOT write them — the agent must write the files
65
+ - Use \`add --inspect\` to inspect source code without installing — don't use \`add\` just to read code`;
66
+ const CLI_REFERENCE = `# MagicPath CLI Reference
67
+
68
+ > **IMPORTANT:** Always pass \`-y\` to skip interactive prompts when running from an agent context. Use \`-o json\` for structured output.
69
+
70
+ ## Commands
71
+
72
+ ### \`info\` — Project and auth context
73
+
74
+ \`\`\`bash
75
+ magicpath-ai info # human-readable
76
+ magicpath-ai info -o json # structured JSON
77
+ \`\`\`
78
+
79
+ Returns auth status, user info, projects, and CLI version.
80
+
81
+ ### \`login\` — Authenticate
82
+
83
+ \`\`\`bash
84
+ magicpath-ai login # interactive (opens browser)
85
+ magicpath-ai login --code <code> # non-interactive (exchange auth code)
86
+ \`\`\`
87
+
88
+ **WARNING:** \`magicpath-ai login\` without \`--code\` opens a browser and waits for interactive input. Never use this in an agent/CI context.
89
+
90
+ | Flag | Description |
91
+ |------|-------------|
92
+ | \`--code <code>\` | Exchange a browser authorization code non-interactively |
93
+
94
+ ### \`whoami\` — Check authentication
95
+
96
+ \`\`\`bash
97
+ magicpath-ai whoami
98
+ magicpath-ai whoami -o json
99
+ \`\`\`
100
+
101
+ ### \`search\` — Search components across all projects
102
+
103
+ \`\`\`bash
104
+ magicpath-ai search "input"
105
+ magicpath-ai search "button" -o json
106
+ magicpath-ai search "card" --limit 5
107
+ \`\`\`
108
+
109
+ Fuzzy searches component names across all projects. Returns matches with project context.
110
+
111
+ | Flag | Description | Default |
112
+ |------|-------------|---------|
113
+ | \`--limit <n>\` | Max results | 20 |
114
+
115
+ ### \`list-projects\` — List all projects
116
+
117
+ \`\`\`bash
118
+ magicpath-ai list-projects
119
+ magicpath-ai list-projects -o json
120
+ \`\`\`
121
+
122
+ ### \`list-components\` — List components in a project
123
+
124
+ \`\`\`bash
125
+ magicpath-ai list-components <projectId>
126
+ magicpath-ai list-components <projectId> -o json
127
+ \`\`\`
128
+
129
+ ### \`view\` — Preview a component
130
+
131
+ \`\`\`bash
132
+ magicpath-ai view <generatedName>
133
+ magicpath-ai view-component <generatedName> # alias
134
+ \`\`\`
135
+
136
+ Opens the component preview URL in the default browser. In JSON mode, returns the URL without opening.
137
+
138
+ ### \`add\` — Add a component to your project
139
+
140
+ > **IMPORTANT:** Only use \`add\` when you intend to import the component afterward. To inspect source code without installing, use \`add --inspect\`. After adding, always import and use the component — never add and then manually replicate its styles.
141
+
142
+ \`\`\`bash
143
+ magicpath-ai add <generatedName>
144
+ magicpath-ai add <generatedName> -y # skip prompts
145
+ magicpath-ai add <generatedName> --inspect # show source code (no install)
146
+ magicpath-ai add <generatedName> --dry-run # preview file list only
147
+ magicpath-ai add <generatedName> -y --overwrite # replace existing
148
+ \`\`\`
149
+
150
+ | Flag | Short | Description | Default |
151
+ |------|-------|-------------|---------|
152
+ | \`--yes\` | \`-y\` | Skip confirmation prompts | false |
153
+ | \`--overwrite\` | \`-o\` | Overwrite existing files | false |
154
+ | \`--path <path>\` | \`-p\` | Custom component path | src/components/magicpath |
155
+ | \`--dry-run\` | | Preview file list without writing | false |
156
+ | \`--inspect\` | | Show full source code without installing (implies --dry-run) | false |
157
+ | \`--debug\` | \`-d\` | Enable debug logging | false |
158
+
159
+ **\`--inspect\` vs \`--dry-run\`:** \`--dry-run\` shows file paths and dependencies. \`--inspect\` also shows the full source code of each file. Use \`--inspect\` when deciding whether a component fits your needs. In JSON mode, both include file contents.
160
+
161
+ **JSON output** (\`-o json\`) automatically implies \`-y\` (no prompts).
162
+
163
+ ### \`integrate\` — AI-powered component integration
164
+
165
+ \`\`\`bash
166
+ magicpath-ai integrate <generatedName> <targetFile>
167
+ \`\`\`
168
+
169
+ Uses AI to integrate a component into a target file. Returns modified file contents — does NOT write files directly.
170
+
171
+ ### \`init\` — Set up for AI agents
172
+
173
+ \`\`\`bash
174
+ magicpath-ai init # writes rules for Claude Code, Cursor, and GitHub Copilot
175
+ \`\`\`
176
+
177
+ ### \`schema\` — Output JSON schemas
178
+
179
+ \`\`\`bash
180
+ magicpath-ai schema # list available schemas
181
+ magicpath-ai schema add # schema for add command
182
+ \`\`\``;
183
+ // ── Editor-specific content ───────────────────────────────────────────
184
+ function buildClaudeSkill() {
185
+ // Claude Code uses triple-escaped backticks in template literals since
186
+ // the content is embedded in a JS string in init.ts. But when we write
187
+ // the file directly, we use normal backticks.
188
+ return `---
189
+ name: magicpath
190
+ description: ${DESCRIPTION} Also triggers for magicpath-ai CLI usage.
191
+ user-invocable: false
192
+ allowed-tools: Bash(magicpath-ai *)
193
+ ---
194
+
195
+ ${SHARED_BODY}
196
+
197
+ ## Current Project Context
198
+
199
+ \`\`\`json
200
+ !\`magicpath-ai info --json 2>/dev/null || echo '{"error": "magicpath-ai not found. Run: npx magicpath-ai info --json"}'\`
201
+ \`\`\`
202
+
203
+ The JSON above contains auth status, projects, and CLI version. If auth.authenticated is false, the user needs to log in before any other operations.
204
+
205
+ ## Detailed References
206
+
207
+ - [cli.md](./cli.md) — Full CLI command reference with all flags
208
+ `;
209
+ }
210
+ function buildCursorRule() {
211
+ // Use single quotes to avoid escaping double quotes in YAML
212
+ const yamlDesc = DESCRIPTION.replace(/'/g, "''");
213
+ return `---
214
+ description: '${yamlDesc}'
215
+ alwaysApply: false
216
+ ---
217
+
218
+ ${SHARED_BODY}
219
+
220
+ ## CLI Reference
221
+
222
+ ${CLI_REFERENCE}
223
+ `;
224
+ }
225
+ function buildCopilotInstructions() {
226
+ return `---
227
+ applyTo: "**"
228
+ ---
229
+
230
+ ${SHARED_BODY}
231
+
232
+ ## CLI Reference
233
+
234
+ ${CLI_REFERENCE}
235
+ `;
236
+ }
237
+ function getFileTargets() {
238
+ return [
239
+ // Claude Code
240
+ { path: '.claude/skills/magicpath/SKILL.md', content: buildClaudeSkill() },
241
+ { path: '.claude/skills/magicpath/cli.md', content: CLI_REFERENCE + '\n' },
242
+ // Cursor
243
+ { path: '.cursor/rules/magicpath.mdc', content: buildCursorRule() },
244
+ // GitHub Copilot
245
+ {
246
+ path: '.github/instructions/magicpath.instructions.md',
247
+ content: buildCopilotInstructions(),
248
+ },
249
+ ];
250
+ }
251
+ // ── Command ───────────────────────────────────────────────────────────
252
+ export function registerInitCommand(program) {
253
+ program
254
+ .command('init')
255
+ .description('Set up MagicPath for AI agents (Claude Code, Cursor, GitHub Copilot)')
256
+ .action(async () => {
257
+ const cwd = process.cwd();
258
+ const json = isJsonMode();
259
+ const created = [];
260
+ // Write all editor rule files
261
+ for (const target of getFileTargets()) {
262
+ const absPath = path.join(cwd, target.path);
263
+ fs.ensureDirSync(path.dirname(absPath));
264
+ fs.writeFileSync(absPath, target.content, 'utf8');
265
+ created.push(target.path);
266
+ if (!json)
267
+ console.log(`${GREEN_CHECK} Created ${target.path}`);
268
+ }
269
+ if (json) {
270
+ jsonResult({ created });
271
+ }
272
+ if (created.length === 0) {
273
+ console.log('\nNothing to do — MagicPath is already configured.');
274
+ }
275
+ else {
276
+ console.log('\nMagicPath is ready for AI agents (Claude Code, Cursor, GitHub Copilot).');
277
+ }
278
+ });
279
+ }
280
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EA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