magicpath-ai 1.3.0-beta.3 → 1.3.0-beta.5

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 (57) 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.d.ts +2 -2
  8. package/dist/commands/auth.js +139 -38
  9. package/dist/commands/auth.js.map +1 -1
  10. package/dist/commands/clone.js +112 -86
  11. package/dist/commands/clone.js.map +1 -1
  12. package/dist/commands/info.d.ts +2 -0
  13. package/dist/commands/info.js +124 -0
  14. package/dist/commands/info.js.map +1 -0
  15. package/dist/commands/init.d.ts +2 -0
  16. package/dist/commands/init.js +284 -0
  17. package/dist/commands/init.js.map +1 -0
  18. package/dist/commands/integrate.js +282 -81
  19. package/dist/commands/integrate.js.map +1 -1
  20. package/dist/commands/list.d.ts +2 -0
  21. package/dist/commands/list.js +138 -0
  22. package/dist/commands/list.js.map +1 -0
  23. package/dist/commands/schema.d.ts +2 -0
  24. package/dist/commands/schema.js +213 -0
  25. package/dist/commands/schema.js.map +1 -0
  26. package/dist/commands/search.d.ts +2 -0
  27. package/dist/commands/search.js +120 -0
  28. package/dist/commands/search.js.map +1 -0
  29. package/dist/commands/skills.d.ts +2 -0
  30. package/dist/commands/skills.js +55 -0
  31. package/dist/commands/skills.js.map +1 -0
  32. package/dist/commands/view.d.ts +2 -0
  33. package/dist/commands/view.js +27 -0
  34. package/dist/commands/view.js.map +1 -0
  35. package/dist/commands/whoami.d.ts +2 -0
  36. package/dist/commands/whoami.js +58 -0
  37. package/dist/commands/whoami.js.map +1 -0
  38. package/dist/util/api.d.ts +3 -0
  39. package/dist/util/api.js +9 -0
  40. package/dist/util/api.js.map +1 -1
  41. package/dist/util/auth.js +5 -0
  42. package/dist/util/auth.js.map +1 -1
  43. package/dist/util/component.d.ts +8 -8
  44. package/dist/util/diff.d.ts +4 -0
  45. package/dist/util/diff.js +11 -3
  46. package/dist/util/diff.js.map +1 -1
  47. package/dist/util/integrate.d.ts +13 -2
  48. package/dist/util/integrate.js +67 -10
  49. package/dist/util/integrate.js.map +1 -1
  50. package/dist/util/output.d.ts +14 -0
  51. package/dist/util/output.js +27 -0
  52. package/dist/util/output.js.map +1 -0
  53. package/package.json +3 -2
  54. package/skills/magicpath-add-component/SKILL.md +49 -0
  55. package/skills/magicpath-integrate/SKILL.md +50 -0
  56. package/skills/magicpath-list/SKILL.md +38 -0
  57. package/skills/magicpath-shared/SKILL.md +34 -0
@@ -0,0 +1,124 @@
1
+ import axios from 'axios';
2
+ import { readFileSync } from 'fs';
3
+ import { getAuthHeaders, loadTokens } from '../util/auth.js';
4
+ import { getUserUrl, getUserProjectsUrl } from '../util/api.js';
5
+ import { isJsonMode, jsonResult, jsonError } from '../util/output.js';
6
+ const pkg = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8'));
7
+ export function registerInfoCommand(program) {
8
+ program
9
+ .command('info')
10
+ .description('Show project and auth status (useful for agent context injection)')
11
+ .action(async () => {
12
+ const json = isJsonMode();
13
+ try {
14
+ // Determine auth method
15
+ let authMethod = null;
16
+ let authenticated = false;
17
+ let headers = null;
18
+ if (process.env.MAGICPATH_TOKEN) {
19
+ authMethod = 'environment';
20
+ authenticated = true;
21
+ headers = getAuthHeaders();
22
+ }
23
+ else if (loadTokens()) {
24
+ authMethod = 'stored';
25
+ authenticated = true;
26
+ headers = getAuthHeaders();
27
+ }
28
+ // Fetch user info
29
+ let user = null;
30
+ if (authenticated && headers) {
31
+ try {
32
+ const response = await axios.get(getUserUrl(), { headers });
33
+ const u = response.data.user ?? response.data;
34
+ user = { id: u.id, name: u.name, email: u.email };
35
+ }
36
+ catch {
37
+ // user fetch failed, leave null
38
+ }
39
+ }
40
+ // Fetch projects
41
+ let projects = null;
42
+ if (authenticated && headers) {
43
+ try {
44
+ const response = await axios.get(getUserProjectsUrl(), { headers });
45
+ const raw = response.data.data?.projects ??
46
+ response.data.projects ??
47
+ response.data;
48
+ if (Array.isArray(raw)) {
49
+ projects = raw.map((p) => ({
50
+ id: p.id,
51
+ name: p.name,
52
+ componentCount: p.componentCount ?? p._count?.components ?? 0,
53
+ }));
54
+ }
55
+ }
56
+ catch {
57
+ // projects fetch failed, leave null
58
+ }
59
+ }
60
+ const result = {
61
+ auth: {
62
+ authenticated,
63
+ method: authMethod,
64
+ user,
65
+ },
66
+ projects,
67
+ cli: {
68
+ version: pkg.version,
69
+ commands: [
70
+ 'add',
71
+ 'view',
72
+ 'search',
73
+ 'list-projects',
74
+ 'list-components',
75
+ 'integrate',
76
+ 'login',
77
+ 'logout',
78
+ 'whoami',
79
+ 'info',
80
+ 'init',
81
+ 'schema',
82
+ ],
83
+ },
84
+ };
85
+ if (json) {
86
+ jsonResult(result);
87
+ }
88
+ // Human-readable output
89
+ console.log('');
90
+ console.log(` MagicPath CLI v${pkg.version}`);
91
+ console.log('');
92
+ if (authenticated && user) {
93
+ console.log(` Authenticated: yes (${authMethod})`);
94
+ console.log(` User: ${user.name} <${user.email}>`);
95
+ }
96
+ else if (authenticated) {
97
+ console.log(` Authenticated: yes (${authMethod})`);
98
+ console.log(' User: (could not fetch)');
99
+ }
100
+ else {
101
+ console.log(' Authenticated: no');
102
+ console.log(' Run `magicpath-ai login` to authenticate.');
103
+ }
104
+ console.log('');
105
+ if (projects && projects.length > 0) {
106
+ console.log(` Projects: ${projects.length}`);
107
+ for (const p of projects) {
108
+ console.log(` - ${p.name} (${p.componentCount} components)`);
109
+ }
110
+ }
111
+ else if (authenticated) {
112
+ console.log(' Projects: none');
113
+ }
114
+ console.log('');
115
+ }
116
+ catch (err) {
117
+ if (json)
118
+ jsonError(err);
119
+ console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
120
+ process.exit(1);
121
+ }
122
+ });
123
+ }
124
+ //# sourceMappingURL=info.js.map
@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GAAG,CAAC,EAAE,CAAC;gBACpC,OAAO,CAAC,GAAG,CAAC,eAAe,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;gBAC9C,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;oBACzB,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,cAAc,cAAc,CAAC,CAAC;gBAClE,CAAC;YACH,CAAC;iBAAM,IAAI,aAAa,EAAE,CAAC;gBACzB,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YAClC,CAAC;YAED,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,IAAI;gBAAE,SAAS,CAAC,GAAG,CAAC,CAAC;YACzB,OAAO,CAAC,KAAK,CACX,UAAU,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAC7D,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { Command } from 'commander';
2
+ export declare function registerInitCommand(program: Command): void;
@@ -0,0 +1,284 @@
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.
14
+
15
+ **If not authenticated, follow this flow:**
16
+
17
+ 1. Run \`magicpath-ai login\` — this opens the browser for one-click auth (auto-completes if already signed in)
18
+ 2. Login completes automatically when the user authorizes in the browser
19
+ 3. Verify with \`magicpath-ai whoami\`
20
+
21
+ ## Workflow
22
+
23
+ 1. **Check auth** — run \`magicpath-ai whoami\` to verify authentication.
24
+ 2. **Find components** — use \`magicpath-ai search <query>\` to search across all projects, or \`list-projects\` then \`list-components <projectId>\` to browse.
25
+ 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.
26
+ 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).
27
+ 5. **Add to project** — use \`magicpath-ai add <generatedName> -y\` to install component files. Always pass \`-y\` in non-interactive contexts.
28
+ 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.
29
+ 7. **Integrate** — use the \`integrate\` CLI command to wire a component into an existing file via AI.
30
+
31
+ ## Critical Rules
32
+
33
+ - **\`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.
34
+ - **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.
35
+ - **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.
36
+ - **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.
37
+ - **\`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.
38
+ - **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.
39
+
40
+ ## Quick Reference
41
+
42
+ \`\`\`bash
43
+ # Auth
44
+ magicpath-ai login # one-click browser login
45
+ magicpath-ai whoami # check auth status
46
+ magicpath-ai info # full project context
47
+
48
+ # Find components
49
+ magicpath-ai search "input box" # search across all projects
50
+ magicpath-ai list-projects # list all projects
51
+ magicpath-ai list-components <id> # list components in a project
52
+
53
+ # Inspect components
54
+ magicpath-ai view <generatedName> # preview in browser
55
+ magicpath-ai add <generatedName> --inspect # show source code (no install)
56
+ magicpath-ai add <generatedName> --dry-run # show what would be installed
57
+
58
+ # Install and use components
59
+ magicpath-ai add <generatedName> -y # add to project (no prompts)
60
+ magicpath-ai integrate <name> <file> # AI-powered integration
61
+ \`\`\`
62
+
63
+ ## Key Concepts
64
+
65
+ - Each component has a **generatedName** (e.g., \`wispy-river-5234\`) — this is the identifier for all operations
66
+ - Components are added as source code to \`src/components/magicpath/<name>/\`
67
+ - The \`add\` command returns \`importStatement\` and \`usage\` — use these in code
68
+ - The \`integrate\` command returns modified file contents but does NOT write them — the agent must write the files
69
+ - Use \`add --inspect\` to inspect source code without installing — don't use \`add\` just to read code`;
70
+ const CLI_REFERENCE = `# MagicPath CLI Reference
71
+
72
+ > **IMPORTANT:** Always pass \`-y\` to skip interactive prompts when running from an agent context. Use \`-o json\` for structured output.
73
+
74
+ ## Commands
75
+
76
+ ### \`info\` — Project and auth context
77
+
78
+ \`\`\`bash
79
+ magicpath-ai info # human-readable
80
+ magicpath-ai info -o json # structured JSON
81
+ \`\`\`
82
+
83
+ Returns auth status, user info, projects, and CLI version.
84
+
85
+ ### \`login\` — Authenticate
86
+
87
+ \`\`\`bash
88
+ magicpath-ai login # one-click browser login (auto-completes)
89
+ magicpath-ai login --code <code> # exchange auth code directly (headless fallback)
90
+ \`\`\`
91
+
92
+ Opens the browser and completes login automatically when the user authorizes.
93
+
94
+ | Flag | Description |
95
+ |------|-------------|
96
+ | \`--code <code>\` | Exchange a browser authorization code directly (headless fallback) |
97
+
98
+ ### \`whoami\` — Check authentication
99
+
100
+ \`\`\`bash
101
+ magicpath-ai whoami
102
+ magicpath-ai whoami -o json
103
+ \`\`\`
104
+
105
+ ### \`search\` — Search components across all projects
106
+
107
+ \`\`\`bash
108
+ magicpath-ai search "input"
109
+ magicpath-ai search "button" -o json
110
+ magicpath-ai search "card" --limit 5
111
+ \`\`\`
112
+
113
+ Fuzzy searches component names across all projects. Returns matches with project context.
114
+
115
+ | Flag | Description | Default |
116
+ |------|-------------|---------|
117
+ | \`--limit <n>\` | Max results | 20 |
118
+
119
+ ### \`list-projects\` — List all projects
120
+
121
+ \`\`\`bash
122
+ magicpath-ai list-projects
123
+ magicpath-ai list-projects -o json
124
+ \`\`\`
125
+
126
+ ### \`list-components\` — List components in a project
127
+
128
+ \`\`\`bash
129
+ magicpath-ai list-components <projectId>
130
+ magicpath-ai list-components <projectId> -o json
131
+ \`\`\`
132
+
133
+ ### \`view\` — Preview a component
134
+
135
+ \`\`\`bash
136
+ magicpath-ai view <generatedName>
137
+ magicpath-ai view-component <generatedName> # alias
138
+ \`\`\`
139
+
140
+ Opens the component preview URL in the default browser. In JSON mode, returns the URL without opening.
141
+
142
+ ### \`add\` — Add a component to your project
143
+
144
+ > **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.
145
+
146
+ \`\`\`bash
147
+ magicpath-ai add <generatedName>
148
+ magicpath-ai add <generatedName> -y # skip prompts
149
+ magicpath-ai add <generatedName> --inspect # show source code (no install)
150
+ magicpath-ai add <generatedName> --dry-run # preview file list only
151
+ magicpath-ai add <generatedName> -y --overwrite # replace existing
152
+ \`\`\`
153
+
154
+ | Flag | Short | Description | Default |
155
+ |------|-------|-------------|---------|
156
+ | \`--yes\` | \`-y\` | Skip confirmation prompts | false |
157
+ | \`--overwrite\` | \`-o\` | Overwrite existing files | false |
158
+ | \`--path <path>\` | \`-p\` | Custom component path | src/components/magicpath |
159
+ | \`--dry-run\` | | Preview file list without writing | false |
160
+ | \`--inspect\` | | Show full source code without installing (implies --dry-run) | false |
161
+ | \`--debug\` | \`-d\` | Enable debug logging | false |
162
+
163
+ **\`--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.
164
+
165
+ **JSON output** (\`-o json\`) automatically implies \`-y\` (no prompts).
166
+
167
+ ### \`integrate\` — AI-powered component integration
168
+
169
+ \`\`\`bash
170
+ magicpath-ai integrate <generatedName> <targetFile>
171
+ \`\`\`
172
+
173
+ Uses AI to integrate a component into a target file. Returns modified file contents — does NOT write files directly.
174
+
175
+ ### \`init\` — Set up for AI agents
176
+
177
+ \`\`\`bash
178
+ magicpath-ai init # writes rules for Claude Code, Cursor, and GitHub Copilot
179
+ \`\`\`
180
+
181
+ ### \`schema\` — Output JSON schemas
182
+
183
+ \`\`\`bash
184
+ magicpath-ai schema # list available schemas
185
+ magicpath-ai schema add # schema for add command
186
+ \`\`\``;
187
+ // ── Editor-specific content ───────────────────────────────────────────
188
+ function buildClaudeSkill() {
189
+ // Claude Code uses triple-escaped backticks in template literals since
190
+ // the content is embedded in a JS string in init.ts. But when we write
191
+ // the file directly, we use normal backticks.
192
+ return `---
193
+ name: magicpath
194
+ description: ${DESCRIPTION} Also triggers for magicpath-ai CLI usage.
195
+ user-invocable: false
196
+ allowed-tools: Bash(magicpath-ai *)
197
+ ---
198
+
199
+ ${SHARED_BODY}
200
+
201
+ ## Current Project Context
202
+
203
+ \`\`\`json
204
+ !\`magicpath-ai info --json 2>/dev/null || echo '{"error": "magicpath-ai not found. Run: npx magicpath-ai info --json"}'\`
205
+ \`\`\`
206
+
207
+ 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.
208
+
209
+ ## Detailed References
210
+
211
+ - [cli.md](./cli.md) — Full CLI command reference with all flags
212
+ `;
213
+ }
214
+ function buildCursorRule() {
215
+ // Use single quotes to avoid escaping double quotes in YAML
216
+ const yamlDesc = DESCRIPTION.replace(/'/g, "''");
217
+ return `---
218
+ description: '${yamlDesc}'
219
+ alwaysApply: false
220
+ ---
221
+
222
+ ${SHARED_BODY}
223
+
224
+ ## CLI Reference
225
+
226
+ ${CLI_REFERENCE}
227
+ `;
228
+ }
229
+ function buildCopilotInstructions() {
230
+ return `---
231
+ applyTo: "**"
232
+ ---
233
+
234
+ ${SHARED_BODY}
235
+
236
+ ## CLI Reference
237
+
238
+ ${CLI_REFERENCE}
239
+ `;
240
+ }
241
+ function getFileTargets() {
242
+ return [
243
+ // Claude Code
244
+ { path: '.claude/skills/magicpath/SKILL.md', content: buildClaudeSkill() },
245
+ { path: '.claude/skills/magicpath/cli.md', content: CLI_REFERENCE + '\n' },
246
+ // Cursor
247
+ { path: '.cursor/rules/magicpath.mdc', content: buildCursorRule() },
248
+ // GitHub Copilot
249
+ {
250
+ path: '.github/instructions/magicpath.instructions.md',
251
+ content: buildCopilotInstructions(),
252
+ },
253
+ ];
254
+ }
255
+ // ── Command ───────────────────────────────────────────────────────────
256
+ export function registerInitCommand(program) {
257
+ program
258
+ .command('init')
259
+ .description('Set up MagicPath for AI agents (Claude Code, Cursor, GitHub Copilot)')
260
+ .action(async () => {
261
+ const cwd = process.cwd();
262
+ const json = isJsonMode();
263
+ const created = [];
264
+ // Write all editor rule files
265
+ for (const target of getFileTargets()) {
266
+ const absPath = path.join(cwd, target.path);
267
+ fs.ensureDirSync(path.dirname(absPath));
268
+ fs.writeFileSync(absPath, target.content, 'utf8');
269
+ created.push(target.path);
270
+ if (!json)
271
+ console.log(`${GREEN_CHECK} Created ${target.path}`);
272
+ }
273
+ if (json) {
274
+ jsonResult({ created });
275
+ }
276
+ if (created.length === 0) {
277
+ console.log('\nNothing to do — MagicPath is already configured.');
278
+ }
279
+ else {
280
+ console.log('\nMagicPath is ready for AI agents (Claude Code, Cursor, GitHub Copilot).');
281
+ }
282
+ });
283
+ }
284
+ //# 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,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,yEAAyE;AAEzE,MAAM,WAAW,GACf,iZAAiZ,CAAC;AAEpZ,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wGA8DoF,CAAC;AAEzG,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoHf,CAAC;AAER,yEAAyE;AAEzE,SAAS,gBAAgB;IACvB,uEAAuE;IACvE,uEAAuE;IACvE,8CAA8C;IAC9C,OAAO;;eAEM,WAAW;;;;;EAKxB,WAAW;;;;;;;;;;;;;CAaZ,CAAC;AACF,CAAC;AAED,SAAS,eAAe;IACtB,4DAA4D;IAC5D,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACjD,OAAO;gBACO,QAAQ;;;;EAItB,WAAW;;;;EAIX,aAAa;CACd,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