linework-cli 0.0.0-stage → 0.1.1

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 CHANGED
@@ -1,3 +1,82 @@
1
- # Temporary Holding Version
1
+ # linework-cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Official CLI for **[Linework](https://linework.rdev.web.id)** — semantic SVG icons and editorial illustrations engineered for React, Next.js, Vite, Astro, Remix, and React Router.
4
+
5
+ Initialize semantic `--rdev-*` light/dark CSS tokens and pull live TSX components or full React packages straight into your project. Newly published icons and illustrations on Linework are available immediately through the CLI without waiting for CLI releases.
6
+
7
+ ---
8
+
9
+ ## Quick Start
10
+
11
+ Initialize `linework.json` and configure all 5 semantic CSS custom properties:
12
+
13
+ ```bash
14
+ # pnpm
15
+ pnpm dlx linework-cli@latest init -t next
16
+
17
+ # npm
18
+ npx linework-cli@latest init -t next
19
+
20
+ # yarn
21
+ yarn dlx linework-cli@latest init -t next
22
+
23
+ # bun
24
+ bunx --bun linework-cli@latest init -t next
25
+ ```
26
+
27
+ Supported framework presets (`-t`): `next`, `vite`, `astro`, `remix`, `react-router`, `react`.
28
+
29
+ ---
30
+
31
+ ## Add Icons & Illustrations (`add`)
32
+
33
+ Pull typed, zero-dependency TSX component files straight from the live Linework registry into `src/components/linework/` (or your custom `--dir`):
34
+
35
+ ```bash
36
+ pnpm dlx linework-cli@latest add friendly-ghost shield-check
37
+ ```
38
+
39
+ Options:
40
+ - `--size <px>` — Default SVG width/height (default `48`)
41
+ - `-o, --dir <path>` — Custom output directory
42
+ - `--overwrite` — Replace existing `.tsx` files
43
+ - `--all-illustrations` — Pull all free illustrations at once
44
+
45
+ ---
46
+
47
+ ## Search & Sync
48
+
49
+ ```bash
50
+ # Search live icons & illustrations from the terminal
51
+ pnpm dlx linework-cli@latest search astronaut --type illustration
52
+
53
+ # Refresh installed @rdev/icons-react & @rdev/illustrations-react .tgz packages
54
+ pnpm dlx linework-cli@latest sync
55
+ ```
56
+
57
+ ---
58
+
59
+ ## 5 Semantic Color Tokens
60
+
61
+ Every icon and illustration automatically maps paths to 5 theme tokens configured by `linework-cli init`:
62
+
63
+ | Token | CSS Variable | Role |
64
+ |---|---|---|
65
+ | `primary` | `--rdev-primary` | Dominant fill / foreground subject |
66
+ | `secondary` | `--rdev-secondary` | Supporting planes & depth |
67
+ | `accent` | `--rdev-accent` | Warm highlights & badges |
68
+ | `outline` | `--rdev-outline` | Structural ink contours |
69
+ | `highlight` | `--rdev-highlight` | Specular paper/card shine |
70
+
71
+ ---
72
+
73
+ ## Documentation
74
+
75
+ - Introduction: https://linework.rdev.web.id/docs
76
+ - Installation Guide: https://linework.rdev.web.id/docs/installation
77
+ - CLI Reference: https://linework.rdev.web.id/docs/cli
78
+ - State Page Builder (404 / 500): https://linework.rdev.web.id/builder
79
+
80
+ ## License
81
+
82
+ MIT — RDEV Studio
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { runCli } from '../src/cli.mjs';
3
+
4
+ const exitCode = await runCli(process.argv.slice(2));
5
+ if (exitCode !== 0) {
6
+ process.exitCode = exitCode;
7
+ }
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "linework-cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "CLI for initializing Linework semantic color tokens and adding live vector icons and illustrations to React projects.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "RDEV Studio",
8
+ "homepage": "https://linework.rdev.web.id/docs/cli",
9
+ "keywords": [
10
+ "icons",
11
+ "illustrations",
12
+ "svg",
13
+ "react",
14
+ "nextjs",
15
+ "tailwindcss",
16
+ "design-tokens",
17
+ "linework",
18
+ "cli"
19
+ ],
20
+ "bin": {
21
+ "linework-cli": "bin/linework-cli.mjs",
22
+ "linework": "bin/linework-cli.mjs"
23
+ },
24
+ "main": "./src/cli.mjs",
25
+ "exports": {
26
+ ".": "./src/cli.mjs"
27
+ },
28
+ "files": [
29
+ "bin",
30
+ "src",
31
+ "README.md"
32
+ ],
33
+ "engines": {
34
+ "node": ">=18.0.0"
35
+ },
36
+ "scripts": {
37
+ "test": "node --test tests/*.test.mjs",
38
+ "prepublishOnly": "npm test",
39
+ "release:patch": "npm version patch && npm publish --access public",
40
+ "release:minor": "npm version minor && npm publish --access public"
41
+ }
42
+ }
package/src/cli.mjs ADDED
@@ -0,0 +1,486 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { spawnSync } from 'node:child_process';
4
+
5
+ const PKG_JSON = JSON.parse(
6
+ fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8'),
7
+ );
8
+
9
+ export const DEFAULT_REGISTRY_URL = 'https://linework.rdev.web.id';
10
+ export const CLI_VERSION = String(PKG_JSON.version || '0.0.0');
11
+
12
+ const TOKEN_BLOCK_START = '/* linework-tokens:start */';
13
+ const TOKEN_BLOCK_END = '/* linework-tokens:end */';
14
+
15
+ const DEFAULT_TOKENS = {
16
+ primary: '#224A3E',
17
+ secondary: '#90A99A',
18
+ accent: '#E6A56D',
19
+ outline: '#141413',
20
+ highlight: '#F1E5C7',
21
+ };
22
+
23
+ const VALID_FRAMEWORKS = new Set(['next', 'vite', 'astro', 'remix', 'react-router', 'react']);
24
+ const SLUG_RE = /^[a-z0-9-]+$/;
25
+
26
+ export function toPascalCase(slug) {
27
+ return String(slug)
28
+ .split(/[^a-zA-Z0-9]+/)
29
+ .filter(Boolean)
30
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
31
+ .join('');
32
+ }
33
+
34
+ export function detectPackageManager(cwd) {
35
+ if (fs.existsSync(path.join(cwd, 'pnpm-lock.yaml'))) return 'pnpm';
36
+ if (fs.existsSync(path.join(cwd, 'yarn.lock'))) return 'yarn';
37
+ if (
38
+ fs.existsSync(path.join(cwd, 'bun.lock')) ||
39
+ fs.existsSync(path.join(cwd, 'bun.lockb'))
40
+ ) {
41
+ return 'bun';
42
+ }
43
+ if (fs.existsSync(path.join(cwd, 'package-lock.json'))) return 'npm';
44
+
45
+ const ua = process.env.npm_config_user_agent || '';
46
+ if (ua.startsWith('pnpm/')) return 'pnpm';
47
+ if (ua.startsWith('yarn/')) return 'yarn';
48
+ if (ua.startsWith('bun/')) return 'bun';
49
+ return 'npm';
50
+ }
51
+
52
+ export function detectFramework(cwd, override) {
53
+ if (override) {
54
+ const normalized = String(override).trim().toLowerCase();
55
+ if (VALID_FRAMEWORKS.has(normalized)) return normalized;
56
+ }
57
+ const pkgPath = path.join(cwd, 'package.json');
58
+ if (fs.existsSync(pkgPath)) {
59
+ try {
60
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
61
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
62
+ if (deps.next) return 'next';
63
+ if (deps['@react-router/dev'] || deps['react-router']) return 'react-router';
64
+ if (deps['@remix-run/react']) return 'remix';
65
+ if (deps.astro) return 'astro';
66
+ if (deps.vite) return 'vite';
67
+ } catch {
68
+ // Ignore malformed package.json and use generic React fallback
69
+ }
70
+ }
71
+ return 'react';
72
+ }
73
+
74
+ export function detectCssFile(cwd, framework) {
75
+ const candidates = [
76
+ 'src/app/globals.css',
77
+ 'app/globals.css',
78
+ 'src/index.css',
79
+ 'src/App.css',
80
+ 'src/styles/globals.css',
81
+ 'src/styles/global.css',
82
+ 'styles/globals.css',
83
+ ];
84
+ for (const rel of candidates) {
85
+ if (fs.existsSync(path.join(cwd, rel))) {
86
+ return rel;
87
+ }
88
+ }
89
+ if (framework === 'next') {
90
+ return fs.existsSync(path.join(cwd, 'src')) ? 'src/app/globals.css' : 'app/globals.css';
91
+ }
92
+ return fs.existsSync(path.join(cwd, 'src')) ? 'src/index.css' : 'styles/globals.css';
93
+ }
94
+
95
+ export function detectComponentsDir(cwd, override) {
96
+ if (override) return override;
97
+ const cfgPath = path.join(cwd, 'linework.json');
98
+ if (fs.existsSync(cfgPath)) {
99
+ try {
100
+ const cfg = JSON.parse(fs.readFileSync(cfgPath, 'utf8'));
101
+ if (cfg.componentsDir && typeof cfg.componentsDir === 'string') {
102
+ return cfg.componentsDir;
103
+ }
104
+ } catch {
105
+ // Fallback cleanly to heuristic
106
+ }
107
+ }
108
+ return fs.existsSync(path.join(cwd, 'src')) ? 'src/components/linework' : 'components/linework';
109
+ }
110
+
111
+ function buildTokenCssBlock(tokens = DEFAULT_TOKENS) {
112
+ return [
113
+ TOKEN_BLOCK_START,
114
+ ':root {',
115
+ ` --rdev-primary: ${tokens.primary};`,
116
+ ` --rdev-secondary: ${tokens.secondary};`,
117
+ ` --rdev-accent: ${tokens.accent};`,
118
+ ` --rdev-outline: ${tokens.outline};`,
119
+ ` --rdev-highlight: ${tokens.highlight};`,
120
+ '}',
121
+ '',
122
+ '.dark {',
123
+ ' --rdev-primary: #52B788;',
124
+ ' --rdev-secondary: #74C69D;',
125
+ ' --rdev-accent: #F4A261;',
126
+ ' --rdev-outline: #E8E6DF;',
127
+ ' --rdev-highlight: #1B2622;',
128
+ '}',
129
+ TOKEN_BLOCK_END,
130
+ ].join('\n');
131
+ }
132
+
133
+ export function upsertTokenCss(fullCssPath, tokens = DEFAULT_TOKENS) {
134
+ fs.mkdirSync(path.dirname(fullCssPath), { recursive: true });
135
+ const existing = fs.existsSync(fullCssPath) ? fs.readFileSync(fullCssPath, 'utf8') : '';
136
+ const block = buildTokenCssBlock(tokens);
137
+
138
+ if (existing.includes(TOKEN_BLOCK_START) && existing.includes(TOKEN_BLOCK_END)) {
139
+ const startIdx = existing.indexOf(TOKEN_BLOCK_START);
140
+ const endIdx = existing.indexOf(TOKEN_BLOCK_END) + TOKEN_BLOCK_END.length;
141
+ const updated = `${existing.slice(0, startIdx)}${block}${existing.slice(endIdx)}`;
142
+ fs.writeFileSync(fullCssPath, updated, 'utf8');
143
+ return 'updated';
144
+ }
145
+
146
+ if (existing.includes('--rdev-primary')) {
147
+ return 'skipped';
148
+ }
149
+
150
+ const separator = existing && !existing.endsWith('\n') ? '\n\n' : existing ? '\n' : '';
151
+ fs.writeFileSync(fullCssPath, `${existing}${separator}${block}\n`, 'utf8');
152
+ return 'added';
153
+ }
154
+
155
+ function resolveRegistryUrl(cwd, override) {
156
+ const candidate = override || readConfig(cwd)?.registry || DEFAULT_REGISTRY_URL;
157
+ let parsed;
158
+ try {
159
+ parsed = new URL(candidate);
160
+ } catch {
161
+ throw new Error(`Invalid registry URL: ${candidate}`);
162
+ }
163
+ if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {
164
+ throw new Error(`Unsupported registry protocol: ${parsed.protocol}`);
165
+ }
166
+ return parsed.origin;
167
+ }
168
+
169
+ function readConfig(cwd) {
170
+ const cfgPath = path.join(cwd, 'linework.json');
171
+ if (!fs.existsSync(cfgPath)) return null;
172
+ try {
173
+ return JSON.parse(fs.readFileSync(cfgPath, 'utf8'));
174
+ } catch {
175
+ return null;
176
+ }
177
+ }
178
+
179
+ function parseArgs(argv) {
180
+ const positionals = [];
181
+ const flags = {};
182
+
183
+ for (let i = 0; i < argv.length; i++) {
184
+ const arg = argv[i];
185
+ if (arg === '--') {
186
+ positionals.push(...argv.slice(i + 1));
187
+ break;
188
+ }
189
+ if (arg.startsWith('--')) {
190
+ const eqIdx = arg.indexOf('=');
191
+ if (eqIdx !== -1) {
192
+ flags[arg.slice(2, eqIdx)] = arg.slice(eqIdx + 1);
193
+ } else {
194
+ const key = arg.slice(2);
195
+ const next = argv[i + 1];
196
+ if (next && !next.startsWith('-')) {
197
+ flags[key] = next;
198
+ i += 1;
199
+ } else {
200
+ flags[key] = true;
201
+ }
202
+ }
203
+ } else if (arg.startsWith('-') && arg.length === 2) {
204
+ const key = arg.slice(1);
205
+ const next = argv[i + 1];
206
+ if (next && !next.startsWith('-')) {
207
+ flags[key] = next;
208
+ i += 1;
209
+ } else {
210
+ flags[key] = true;
211
+ }
212
+ } else {
213
+ positionals.push(arg);
214
+ }
215
+ }
216
+
217
+ return { positionals, flags };
218
+ }
219
+
220
+ function buildInstallArgs(pm, packageSpecs) {
221
+ if (pm === 'npm') return ['install', ...packageSpecs];
222
+ return ['add', ...packageSpecs];
223
+ }
224
+
225
+ function defaultRunCommand(pm, args, cwd) {
226
+ const res = spawnSync(pm, args, { cwd, stdio: 'inherit', shell: process.platform === 'win32' });
227
+ return { status: res.status ?? 1 };
228
+ }
229
+
230
+ export function formatHelp() {
231
+ return [
232
+ `linework-cli v${CLI_VERSION} — Semantic SVG icons & illustrations for React`,
233
+ '',
234
+ 'Usage:',
235
+ ' linework-cli init [-t next|vite|astro|remix|react-router|react] [--dir <path>] [--install] [--no-css] [-y]',
236
+ ' linework-cli add <slug...> [-o <dir>] [--size <px>] [--overwrite] [--all-illustrations]',
237
+ ' linework-cli search <query> [--type icon|illustration] [--limit <n>]',
238
+ ' linework-cli sync',
239
+ '',
240
+ 'Options:',
241
+ ' -t, --template <framework> Framework preset (next, vite, astro, remix, react-router, react)',
242
+ ' -d, --dir <path> Target directory for added components (default: components/linework)',
243
+ ' --install Install live @rdev/icons-react & @rdev/illustrations-react .tgz packages',
244
+ ' --no-css Skip writing --rdev-* CSS custom properties',
245
+ ' --size <px> Default icon/illustration width/height for added TSX (default: 48)',
246
+ ' --overwrite Overwrite existing local .tsx component files',
247
+ ' -h, --help Show help',
248
+ ' -v, --version Show version',
249
+ '',
250
+ 'Examples:',
251
+ ' pnpm dlx linework-cli@latest init -t next',
252
+ ' pnpm dlx linework-cli@latest add friendly-ghost shield-check',
253
+ ' pnpm dlx linework-cli@latest search astronaut --type illustration',
254
+ ].join('\n');
255
+ }
256
+
257
+ export async function runCli(argv, deps = {}) {
258
+ const cwd = deps.cwd || process.cwd();
259
+ const fetchFn = deps.fetch || globalThis.fetch;
260
+ const runCommand = deps.runCommand || defaultRunCommand;
261
+ const log = deps.log || console.log;
262
+ const errLog = deps.errLog || console.error;
263
+
264
+ const { positionals, flags } = parseArgs(argv);
265
+ const cmd = positionals[0];
266
+
267
+ if (!cmd || flags.h || flags.help || cmd === 'help') {
268
+ log(formatHelp());
269
+ return 0;
270
+ }
271
+
272
+ if (flags.v || flags.version || cmd === 'version') {
273
+ log(CLI_VERSION);
274
+ return 0;
275
+ }
276
+
277
+ let registry;
278
+ try {
279
+ registry = resolveRegistryUrl(cwd, typeof flags.registry === 'string' ? flags.registry : undefined);
280
+ } catch (err) {
281
+ errLog(err instanceof Error ? err.message : String(err));
282
+ return 1;
283
+ }
284
+
285
+ if (cmd === 'init') {
286
+ const framework = detectFramework(cwd, flags.t || flags.template);
287
+ const pm = detectPackageManager(cwd);
288
+ const cssRel = typeof flags.css === 'string' ? flags.css : detectCssFile(cwd, framework);
289
+ const componentsDir = detectComponentsDir(cwd, typeof (flags.d || flags.dir) === 'string' ? (flags.d || flags.dir) : undefined);
290
+
291
+ const cfgPath = path.join(cwd, 'linework.json');
292
+ const cfg = {
293
+ framework,
294
+ css: cssRel,
295
+ componentsDir,
296
+ registry,
297
+ tokens: DEFAULT_TOKENS,
298
+ };
299
+ fs.writeFileSync(cfgPath, `${JSON.stringify(cfg, null, 2)}\n`, 'utf8');
300
+ log(`✔ Created linework.json (framework: ${framework}, components: ${componentsDir})`);
301
+
302
+ if (!flags['no-css']) {
303
+ const cssFullPath = path.resolve(cwd, cssRel);
304
+ const cssStatus = upsertTokenCss(cssFullPath, DEFAULT_TOKENS);
305
+ if (cssStatus === 'added') {
306
+ log(`✔ Added 5 semantic --rdev-* tokens to ${cssRel}`);
307
+ } else if (cssStatus === 'updated') {
308
+ log(`✔ Updated Linework semantic tokens in ${cssRel}`);
309
+ } else {
310
+ log(`• Semantic tokens already configured in ${cssRel}`);
311
+ }
312
+ }
313
+
314
+ if (flags.install || flags.packages) {
315
+ const specs = [
316
+ `${registry}/api/packages/icons-react.tgz`,
317
+ `${registry}/api/packages/illustrations-react.tgz`,
318
+ ];
319
+ const args = buildInstallArgs(pm, specs);
320
+ log(`Installing @rdev/icons-react and @rdev/illustrations-react via ${pm}...`);
321
+ const res = runCommand(pm, args, cwd);
322
+ if (res.status !== 0) {
323
+ errLog(`Package installation failed with exit code ${res.status}.`);
324
+ return res.status;
325
+ }
326
+ log('✔ Packages installed.');
327
+ }
328
+
329
+ log('');
330
+ log('Next steps:');
331
+ const dlxPrefix = pm === 'npm' ? 'npx' : pm === 'bun' ? 'bunx --bun' : `${pm} dlx`;
332
+ log(` ${dlxPrefix} linework-cli@latest add friendly-ghost shield-check`);
333
+ return 0;
334
+ }
335
+
336
+ if (cmd === 'add') {
337
+ let slugs = positionals.slice(1).map((s) => s.trim().toLowerCase()).filter(Boolean);
338
+ const outDirRel =
339
+ typeof (flags.o || flags.dir || flags.d) === 'string'
340
+ ? String(flags.o || flags.dir || flags.d)
341
+ : detectComponentsDir(cwd);
342
+ const outDirAbs = path.resolve(cwd, outDirRel);
343
+ const overwrite = Boolean(flags.overwrite);
344
+ const requestedSize = flags.size ? Number(flags.size) : undefined;
345
+
346
+ if (flags['all-illustrations']) {
347
+ const res = await fetchFn(`${registry}/api/agent/search?type=illustration&access=free&limit=100`);
348
+ if (!res.ok) {
349
+ errLog(`Failed to fetch illustration list (${res.status}).`);
350
+ return 1;
351
+ }
352
+ const data = await res.json();
353
+ const rawList = Array.isArray(data.results) ? data.results : Array.isArray(data.assets) ? data.assets : [];
354
+ const fetchedSlugs = rawList.map((a) => a.assetId || a.slug).filter(Boolean);
355
+ slugs = Array.from(new Set([...slugs, ...fetchedSlugs]));
356
+ }
357
+
358
+ if (slugs.length === 0) {
359
+ errLog('Specify at least one asset slug, e.g.: linework-cli add friendly-ghost shield-check');
360
+ return 1;
361
+ }
362
+
363
+ fs.mkdirSync(outDirAbs, { recursive: true });
364
+ let failures = 0;
365
+
366
+ for (const slug of slugs) {
367
+ if (!SLUG_RE.test(slug)) {
368
+ errLog(`✖ Invalid slug "${slug}" (expected kebab-case).`);
369
+ failures += 1;
370
+ continue;
371
+ }
372
+
373
+ const defaultSize = Number.isFinite(requestedSize) && requestedSize > 0 ? requestedSize : undefined;
374
+ const url = defaultSize
375
+ ? `${registry}/api/agent/code/${slug}?format=json&size=${defaultSize}`
376
+ : `${registry}/api/agent/code/${slug}?format=json`;
377
+ const res = await fetchFn(url);
378
+
379
+ if (!res.ok) {
380
+ errLog(`✖ Asset "${slug}" not found on registry (${res.status}).`);
381
+ const searchRes = await fetchFn(
382
+ `${registry}/api/agent/search?q=${encodeURIComponent(slug)}&limit=3`,
383
+ ).catch(() => null);
384
+ if (searchRes?.ok) {
385
+ const searchData = await searchRes.json();
386
+ const hits = Array.isArray(searchData.results) ? searchData.results : searchData.assets;
387
+ if (Array.isArray(hits) && hits.length > 0) {
388
+ errLog(
389
+ ` Did you mean: ${hits.map((a) => a.assetId || a.slug).join(', ')}`,
390
+ );
391
+ }
392
+ }
393
+ failures += 1;
394
+ continue;
395
+ }
396
+
397
+ const payload = await res.json();
398
+ const tsxSource = payload.reactInlineComponent || payload.tsx;
399
+ if (payload.access === 'premium' || !tsxSource) {
400
+ errLog(`✖ "${slug}" requires a commercial Asset Kit (${payload.marketplaceUrl || registry}).`);
401
+ failures += 1;
402
+ continue;
403
+ }
404
+
405
+ const componentName = payload.componentName || toPascalCase(slug);
406
+ const safeFileName = `${path.basename(componentName)}.tsx`;
407
+ const targetFile = path.join(outDirAbs, safeFileName);
408
+
409
+ if (fs.existsSync(targetFile) && !overwrite) {
410
+ log(`• Skipped ${path.relative(cwd, targetFile)} (already exists; pass --overwrite to replace)`);
411
+ continue;
412
+ }
413
+
414
+ fs.writeFileSync(targetFile, `${tsxSource.trimEnd()}\n`, 'utf8');
415
+ log(`✔ Added ${path.relative(cwd, targetFile)} (<${componentName} />)`);
416
+ }
417
+
418
+ return failures > 0 ? 1 : 0;
419
+ }
420
+
421
+ if (cmd === 'search') {
422
+ const query = positionals.slice(1).join(' ').trim();
423
+ const limit = flags.limit ? Math.max(1, Math.min(50, Number(flags.limit) || 15)) : 15;
424
+ const type = typeof flags.type === 'string' ? flags.type : '';
425
+ const params = new URLSearchParams();
426
+ if (query) params.set('q', query);
427
+ if (type === 'icon' || type === 'illustration') params.set('type', type);
428
+ params.set('limit', String(limit));
429
+
430
+ const res = await fetchFn(`${registry}/api/agent/search?${params.toString()}`);
431
+ if (!res.ok) {
432
+ errLog(`Search failed (${res.status}).`);
433
+ return 1;
434
+ }
435
+ const data = await res.json();
436
+ const items = Array.isArray(data.results) ? data.results : Array.isArray(data.assets) ? data.assets : [];
437
+ if (items.length === 0) {
438
+ log(`No assets matched "${query}".`);
439
+ return 0;
440
+ }
441
+ for (const item of items) {
442
+ const id = item.assetId || item.slug;
443
+ log(
444
+ `${String(id).padEnd(28)} <${item.componentName} /> [${item.assetType}, ${item.access}] (${item.collectionSlug})`,
445
+ );
446
+ }
447
+ return 0;
448
+ }
449
+
450
+ if (cmd === 'sync' || cmd === 'update') {
451
+ const pm = detectPackageManager(cwd);
452
+ const pkgPath = path.join(cwd, 'package.json');
453
+ let deps = {};
454
+ if (fs.existsSync(pkgPath)) {
455
+ try {
456
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
457
+ deps = { ...pkg.dependencies, ...pkg.devDependencies };
458
+ } catch {
459
+ // fallback below
460
+ }
461
+ }
462
+
463
+ const targets = [];
464
+ if (deps['@rdev/icons-react']) targets.push(`${registry}/api/packages/icons-react.tgz`);
465
+ if (deps['@rdev/illustrations-react']) targets.push(`${registry}/api/packages/illustrations-react.tgz`);
466
+ if (targets.length === 0) {
467
+ targets.push(
468
+ `${registry}/api/packages/icons-react.tgz`,
469
+ `${registry}/api/packages/illustrations-react.tgz`,
470
+ );
471
+ }
472
+
473
+ const args = buildInstallArgs(pm, targets);
474
+ log(`Syncing Linework React packages via ${pm}...`);
475
+ const res = runCommand(pm, args, cwd);
476
+ if (res.status !== 0) {
477
+ errLog(`Sync failed with exit code ${res.status}.`);
478
+ return res.status;
479
+ }
480
+ log('✔ Synced latest icons & illustrations into node_modules.');
481
+ return 0;
482
+ }
483
+
484
+ errLog(`Unknown command "${cmd}". Run "linework-cli --help" for usage.`);
485
+ return 1;
486
+ }