@astralkit/cli 4.5.0 → 4.6.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/CHANGELOG.md CHANGED
@@ -5,6 +5,15 @@ All notable changes to the `@astralkit/cli` package.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [4.6.0] — 2026-08-22
9
+
10
+ ### Added
11
+ - **Non-interactive mode.** Every prompt now degrades to a sensible default when stdin/stdout is not a TTY (AI-agent shells, CI, piped invocations) instead of crashing with `uv_tty_init EBADF` mid-install and leaving a partial install (component written, dependencies missing). New `-y`/`--yes` flag and the existing `ASTRALKIT_YES=1` env accept all defaults explicitly. Auto-answered prompts are logged (`message → choice (non-interactive)`). Destructive choices stay fail-safe: overwrite/remove default to NO without explicit consent (`--overwrite`, `--force`, `--yes`, or a TTY answer); dependency installs and required side-effect imports default to YES so the installed component actually builds and renders.
12
+ - **Import-scan dependency safety net.** `add` now scans the fetched component source for bare package imports and installs any missing from the registry's `dependencies` metadata (found live: kanban-01 imports three `@dnd-kit` packages, metadata listed one). Scoped to JS-family files; package names still pass the same `filterSafePackages` validation.
13
+
14
+ ### Fixed
15
+ - The `@phosphor-icons/web` conflict prompt no longer crashes agent shells; non-interactive default is to install it (a written component with `ph ph-*` classes must render).
16
+
8
17
  ## [4.5.0] — 2026-07-04
9
18
 
10
19
  ### Added
package/bin/index.js CHANGED
@@ -50,6 +50,7 @@ program
50
50
  .option('--workflow', 'Scaffold a workflow (complete app template)')
51
51
  .option('--overlay', 'Merge workflow into current project')
52
52
  .option('--dry-run', 'Preview what will be installed without writing files', false)
53
+ .option('-y, --yes', 'Accept all prompts with their defaults (also implied when no TTY is attached — agent/CI shells)', false)
53
54
  .action(addCommand);
54
55
 
55
56
  // ─── remove ──────────────────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astralkit/cli",
3
- "version": "4.5.0",
3
+ "version": "4.6.0",
4
4
  "description": "AstralKit CLI — Install and manage UI components in your project",
5
5
  "type": "module",
6
6
  "bin": {
@@ -15,7 +15,15 @@
15
15
  "engines": {
16
16
  "node": ">=18.0.0"
17
17
  },
18
- "keywords": ["astralkit", "ui", "components", "tailwind", "cli", "react", "nextjs"],
18
+ "keywords": [
19
+ "astralkit",
20
+ "ui",
21
+ "components",
22
+ "tailwind",
23
+ "cli",
24
+ "react",
25
+ "nextjs"
26
+ ],
19
27
  "homepage": "https://astralkit.com",
20
28
  "repository": {
21
29
  "type": "git",
@@ -14,10 +14,12 @@ import { validateSlug, validateFramework, isSafePath, writeFiles, isSafeInstallD
14
14
  import { detectPackageManager, getRunCommand, runInstall } from '../lib/pkg-manager.js';
15
15
  import { saveApiKey, getApiKey, getAuth } from '../lib/auth.js';
16
16
  import { applyMerges } from '../lib/merges.js';
17
+ import { setAssumeYes, confirm as askConfirm, select as askSelect, text as askText } from '../lib/ask.js';
17
18
 
18
19
  const FRAMEWORK_LABELS = { nextjs: 'Next.js', react: 'React' };
19
20
 
20
21
  export async function addCommand(nameOrSlug, options) {
22
+ setAssumeYes(options.yes);
21
23
  if (options.apiKey) {
22
24
  if (!options.apiKey.startsWith('ak_')) {
23
25
  console.log(pc.red('Invalid API key format. Keys start with ak_'));
@@ -26,9 +28,9 @@ export async function addCommand(nameOrSlug, options) {
26
28
  saveApiKey(options.apiKey);
27
29
  }
28
30
 
29
- // Local registry mode reads boosters from the developer's own disk — no
30
- // account needed. Components/workflows still require auth (they hit the API).
31
- const localBoosterInstall = LOCAL_REGISTRY_DIR && options.booster;
31
+ // Local registry mode reads boosters/workflows from the developer's own
32
+ // disk — no account needed. Components still require auth (they hit the API).
33
+ const localBoosterInstall = LOCAL_REGISTRY_DIR && (options.booster || options.workflow);
32
34
  if (!getApiKey() && !localBoosterInstall) {
33
35
  const auth = getAuth();
34
36
  if (!auth.token) {
@@ -109,13 +111,16 @@ export async function addCommand(nameOrSlug, options) {
109
111
  return addComponent(nameOrSlug, options);
110
112
  }
111
113
 
112
- // Found in multiple registries — prompt user to choose
113
- const choice = await p.select({
114
+ // Found in multiple registries — prompt user to choose (non-interactive:
115
+ // prefer the component, the most common install target).
116
+ const componentMatch = matches.find(m => m.type === 'component');
117
+ const choice = await askSelect({
114
118
  message: `"${nameOrSlug}" found in multiple registries. What would you like to install?`,
115
119
  options: matches.map(m => ({
116
120
  value: m.type,
117
121
  label: `${m.name} (${m.type === 'component' ? 'UI component' : m.type === 'booster' ? 'feature module' : 'app scaffold'})`,
118
122
  })),
123
+ nonInteractive: componentMatch ? 'component' : matches[0].type,
119
124
  });
120
125
 
121
126
  if (p.isCancel(choice)) { p.cancel('Cancelled.'); process.exit(0); }
@@ -277,11 +282,15 @@ async function addComponent(componentSlug, options) {
277
282
  p.log.warn(`Your project already uses ${pc.cyan('@phosphor-icons/react')} (React components) — a ${pc.bold('separate package')} from the same vendor.`);
278
283
  p.log.warn(`Installing both ships two icon systems side by side.`);
279
284
 
280
- const proceed = await p.confirm({
285
+ // Non-interactive default is YES: the component file is already written
286
+ // with `ph ph-*` classes — skipping the package ships broken icons,
287
+ // which is worse than the two-icon-systems consistency tax.
288
+ const proceed = await askConfirm({
281
289
  message: 'Install @phosphor-icons/web anyway?',
282
290
  initialValue: false,
291
+ nonInteractive: true,
283
292
  });
284
- if (p.isCancel(proceed) || !proceed) {
293
+ if (!proceed) {
285
294
  p.log.info('Skipping @phosphor-icons/web and the layout.tsx import.');
286
295
  p.log.info(pc.gray('Adapt the component\'s <i className="ph ph-*"> tags to @phosphor-icons/react React components.'));
287
296
  usesPhosphorCss = false;
@@ -293,10 +302,30 @@ async function addComponent(componentSlug, options) {
293
302
  }
294
303
  }
295
304
 
296
- if (data.dependencies?.length || usesPhosphorCss) {
305
+ // The registry's `dependencies` metadata can lag behind the code (found
306
+ // live: kanban-01 imports three @dnd-kit packages, metadata listed one).
307
+ // Scan the actual source for bare package imports so a metadata gap never
308
+ // ships a component that doesn't build.
309
+ const importedPackages = new Set();
310
+ const jsCode = (data.files || [])
311
+ .filter(f => /\.(tsx?|jsx?|mjs|cjs)$/.test(f.path))
312
+ .map(f => f.content).join('\n');
313
+ for (const m of jsCode.matchAll(/(?:from|import)\s*\(?\s*['"]((?:@[a-z0-9~][\w.~-]*\/)?[a-z0-9~][\w.~-]*)(?:\/[^'"]*)?['"]/g)) {
314
+ importedPackages.add(m[1]);
315
+ }
316
+ // Packages the host/framework already accounts for.
317
+ for (const skip of ['react', 'react-dom', 'next', 'astralkit', 'clsx', 'tailwind-merge']) {
318
+ importedPackages.delete(skip);
319
+ }
320
+
321
+ if (data.dependencies?.length || usesPhosphorCss || importedPackages.size > 0) {
297
322
  const pm = detectPackageManager();
298
323
  const rawDepList = (data.dependencies || []).filter(d => d !== 'astralkit' && d !== 'clsx' && d !== 'tailwind-merge');
299
324
 
325
+ for (const pkg of importedPackages) {
326
+ if (!rawDepList.includes(pkg)) rawDepList.push(pkg);
327
+ }
328
+
300
329
  // Auto-add @phosphor-icons/web if component uses CSS-based Phosphor icons
301
330
  // AND we didn't skip it above due to a @phosphor-icons/react conflict.
302
331
  if (usesPhosphorCss && !rawDepList.includes('@phosphor-icons/web')) {
@@ -321,11 +350,12 @@ async function addComponent(componentSlug, options) {
321
350
 
322
351
  if (toInstall.length > 0) {
323
352
  // Always ask before running npm install — mirrors the booster flow.
324
- const install = await p.confirm({
353
+ // (Non-interactive: yes — a component without its deps doesn't build.)
354
+ const install = await askConfirm({
325
355
  message: `Install dependencies? (${toInstall.join(', ')})`,
326
356
  initialValue: true,
327
357
  });
328
- if (!p.isCancel(install) && install) {
358
+ if (install) {
329
359
  const s = ora(`Installing ${toInstall.join(', ')}...`).start();
330
360
  const result = await runInstall(pm, process.cwd(), toInstall);
331
361
  if (result.success) {
@@ -393,12 +423,16 @@ async function addComponent(componentSlug, options) {
393
423
  console.log(pc.gray(` ${layoutFile.relative}`));
394
424
  for (const imp of missing) console.log(` ${pc.green('+')} ${imp}`);
395
425
 
396
- const proceed = await p.confirm({
426
+ // Non-interactive default is YES: the exact diff is printed above (never
427
+ // silent — the 2026-04-22 trust rule), and skipping it ships a component
428
+ // whose icons don't render.
429
+ const proceed = await askConfirm({
397
430
  message: `Add these imports to ${layoutFile.relative}?`,
398
431
  initialValue: false,
432
+ nonInteractive: true,
399
433
  });
400
434
 
401
- if (p.isCancel(proceed) || !proceed) {
435
+ if (!proceed) {
402
436
  p.log.info(`Skipped ${layoutFile.relative} edit. Add these lines manually to enable icons:`);
403
437
  for (const imp of missing) console.log(pc.gray(` ${imp}`));
404
438
  installSummary.skipped.push({
@@ -539,10 +573,12 @@ async function addBooster(slug, options) {
539
573
  spinner.stop();
540
574
  console.log(pc.yellow('\nThese files already exist:'));
541
575
  conflicts.forEach(c => console.log(pc.gray(` ${c}`)));
576
+ // Overwrite stays fail-safe when non-interactive WITHOUT --yes/env:
577
+ // destroying user files needs explicit consent (--overwrite, --yes, or a TTY answer).
542
578
  const overwrite = process.env.ASTRALKIT_YES === '1'
543
579
  ? true
544
- : await p.confirm({ message: 'Overwrite existing files?', initialValue: false });
545
- if (p.isCancel(overwrite) || !overwrite) return;
580
+ : await askConfirm({ message: 'Overwrite existing files?', initialValue: false });
581
+ if (!overwrite) return;
546
582
  }
547
583
  }
548
584
 
@@ -568,13 +604,11 @@ async function addBooster(slug, options) {
568
604
  }
569
605
  if (safeDeps.length > 0) {
570
606
  console.log();
571
- const install = process.env.ASTRALKIT_YES === '1'
572
- ? true
573
- : await p.confirm({
574
- message: `Install dependencies? (${safeDeps.join(', ')})`,
575
- initialValue: true,
576
- });
577
- if (!p.isCancel(install) && install) {
607
+ const install = await askConfirm({
608
+ message: `Install dependencies? (${safeDeps.join(', ')})`,
609
+ initialValue: true,
610
+ });
611
+ if (install) {
578
612
  const s = ora('Installing dependencies...').start();
579
613
  const result = await runInstall(pm, process.cwd(), safeDeps);
580
614
  if (result.success) s.succeed('Dependencies installed');
@@ -652,17 +686,20 @@ async function addWorkflow(slug, options) {
652
686
 
653
687
  if (fs.existsSync(path.resolve(process.cwd(), dirName)) && !options.overwrite) {
654
688
  spinner.stop();
655
- const action = await p.select({
689
+ // Non-interactive: cancel — scaffolding over an existing directory
690
+ // needs explicit consent (--overwrite or a TTY answer).
691
+ const action = await askSelect({
656
692
  message: `Directory "${dirName}/" already exists.`,
657
693
  options: [
658
694
  { label: 'Overwrite it', value: 'overwrite' },
659
695
  { label: 'Use a different name', value: 'rename' },
660
696
  { label: 'Cancel', value: 'cancel' },
661
697
  ],
698
+ nonInteractive: 'cancel',
662
699
  });
663
700
  if (p.isCancel(action) || action === 'cancel') return;
664
701
  if (action === 'rename') {
665
- const newDir = await p.text({ message: 'Enter a directory name:', placeholder: `${slug}-app` });
702
+ const newDir = await askText({ message: 'Enter a directory name:', placeholder: `${slug}-app` });
666
703
  if (p.isCancel(newDir)) return;
667
704
  dirName = newDir;
668
705
  }
@@ -677,8 +714,8 @@ async function addWorkflow(slug, options) {
677
714
  console.log(pc.yellow(`${conflicts.length} file(s) would be overwritten:`));
678
715
  conflicts.slice(0, 10).forEach(c => console.log(pc.gray(` ${c}`)));
679
716
  if (conflicts.length > 10) console.log(pc.gray(` ... and ${conflicts.length - 10} more`));
680
- const overwrite = await p.confirm({ message: 'Overwrite these files?', initialValue: false });
681
- if (p.isCancel(overwrite) || !overwrite) return;
717
+ const overwrite = await askConfirm({ message: 'Overwrite these files?', initialValue: false });
718
+ if (!overwrite) return;
682
719
  }
683
720
  }
684
721
 
@@ -694,7 +731,9 @@ async function addWorkflow(slug, options) {
694
731
  }
695
732
 
696
733
  const pm = detectPackageManager(options.overlay ? process.cwd() : targetDir);
697
- const fileCount = writeFiles(targetDir, data.files);
734
+ // Fresh-directory scaffolds legitimately ship package.json/next.config/
735
+ // .gitignore; overlay installs into an existing project stay strict.
736
+ const fileCount = writeFiles(targetDir, data.files, { scaffold: !options.overlay });
698
737
  const label = options.overlay ? './' : `${path.basename(targetDir)}/`;
699
738
 
700
739
  spinner.succeed(`Scaffolded workflow ${pc.cyan(data.name || slug)} in ${label}`);
@@ -702,8 +741,8 @@ async function addWorkflow(slug, options) {
702
741
 
703
742
  if (!options.overlay) {
704
743
  console.log();
705
- const install = await p.confirm({ message: `Install dependencies with ${pm}?`, initialValue: true });
706
- if (!p.isCancel(install) && install) {
744
+ const install = await askConfirm({ message: `Install dependencies with ${pm}?`, initialValue: true });
745
+ if (install) {
707
746
  const s = ora(`Installing with ${pm}...`).start();
708
747
  const result = await runInstall(pm, targetDir);
709
748
  if (result.success) s.succeed('Dependencies installed');
@@ -4,6 +4,7 @@ import pc from 'picocolors';
4
4
  import * as p from '@clack/prompts';
5
5
  import { getProjectConfig, detectFramework } from '../lib/config.js';
6
6
  import { validateSlug } from '../lib/validators.js';
7
+ import { confirm as askConfirm } from '../lib/ask.js';
7
8
 
8
9
  export async function removeCommand(name, options) {
9
10
  // Reject anything that isn't a simple slug. Prevents `astralkit remove ../..`
@@ -49,11 +50,12 @@ export async function removeCommand(name, options) {
49
50
  console.log();
50
51
 
51
52
  if (!options.force) {
52
- const confirm = await p.confirm({
53
+ // Non-interactive: cancel — deleting files needs explicit consent (--force or a TTY answer).
54
+ const confirm = await askConfirm({
53
55
  message: `Remove ${found.length} item(s)?`,
54
56
  initialValue: false,
55
57
  });
56
- if (p.isCancel(confirm) || !confirm) {
58
+ if (!confirm) {
57
59
  p.cancel('Cancelled.');
58
60
  return;
59
61
  }
@@ -5,6 +5,7 @@ import * as p from '@clack/prompts';
5
5
  import { getComponent } from '../lib/api.js';
6
6
  import { getProjectConfig, detectFramework } from '../lib/config.js';
7
7
  import { isSafePath } from '../lib/validators.js';
8
+ import { confirm as askConfirm } from '../lib/ask.js';
8
9
 
9
10
  export async function updateCommand(componentSlug, options) {
10
11
  const ora = (await import('ora')).default;
@@ -57,11 +58,11 @@ export async function updateCommand(componentSlug, options) {
57
58
  console.log();
58
59
 
59
60
  if (!options.force) {
60
- const confirm = await p.confirm({
61
+ const confirm = await askConfirm({
61
62
  message: `Update ${pc.cyan(componentSlug)}?`,
62
63
  initialValue: true,
63
64
  });
64
- if (p.isCancel(confirm) || !confirm) {
65
+ if (!confirm) {
65
66
  p.cancel('Cancelled.');
66
67
  return;
67
68
  }
package/src/lib/api.js CHANGED
@@ -145,7 +145,7 @@ export async function getComponent(slug, framework = 'html') {
145
145
  }
146
146
 
147
147
  export async function listBoosters({ framework, search, pro, free } = {}) {
148
- if (LOCAL_REGISTRY_DIR) return listLocalBoosters({ search });
148
+ if (LOCAL_REGISTRY_DIR) return listLocalRegistryItems('boosters', { search });
149
149
  const params = new URLSearchParams();
150
150
  if (framework) params.set('framework', framework);
151
151
  if (pro) params.set('pro', 'true');
@@ -197,21 +197,9 @@ function getLocalBooster(slug, framework) {
197
197
  };
198
198
  }
199
199
 
200
- function listLocalBoosters({ search } = {}) {
201
- const boostersRoot = join(LOCAL_REGISTRY_DIR, 'boosters');
202
- if (!fs.existsSync(boostersRoot)) return { boosters: [] };
203
- const q = (search || '').toLowerCase();
204
- const boosters = fs.readdirSync(boostersRoot, { withFileTypes: true })
205
- .filter((e) => e.isDirectory() && fs.existsSync(join(boostersRoot, e.name, 'booster.json')))
206
- .map((e) => JSON.parse(fs.readFileSync(join(boostersRoot, e.name, 'booster.json'), 'utf8')))
207
- .filter((m) => !q ||
208
- (m.slug || '').toLowerCase().includes(q) ||
209
- (m.name || '').toLowerCase().includes(q) ||
210
- (m.description || '').toLowerCase().includes(q));
211
- return { boosters };
212
- }
213
200
 
214
201
  export async function listWorkflows({ framework, search, pro, free } = {}) {
202
+ if (LOCAL_REGISTRY_DIR) return listLocalRegistryItems('workflows', { search });
215
203
  const params = new URLSearchParams();
216
204
  if (framework) params.set('framework', framework);
217
205
  if (pro) params.set('pro', 'true');
@@ -222,10 +210,38 @@ export async function listWorkflows({ framework, search, pro, free } = {}) {
222
210
  }
223
211
 
224
212
  export async function getWorkflow(slug, framework = 'nextjs') {
213
+ if (LOCAL_REGISTRY_DIR) return getLocalWorkflow(slug, framework);
225
214
  const res = await apiRequest(`/api/cli/workflows/${encodeURIComponent(slug)}?framework=${encodeURIComponent(framework)}`);
226
215
  return res.json();
227
216
  }
228
217
 
218
+ function getLocalWorkflow(slug, framework) {
219
+ const workflowDir = join(LOCAL_REGISTRY_DIR, 'workflows', slug);
220
+ const manifestPath = join(workflowDir, 'workflow.json');
221
+ if (!fs.existsSync(manifestPath)) {
222
+ const err = new Error(`Workflow "${slug}" not found in local registry (${LOCAL_REGISTRY_DIR}).`);
223
+ err.code = 'API_ERROR';
224
+ throw err;
225
+ }
226
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
227
+ return { ...manifest, files: walkLocalFiles(join(workflowDir, framework)) };
228
+ }
229
+
230
+ function listLocalRegistryItems(type, { search } = {}) {
231
+ const root = join(LOCAL_REGISTRY_DIR, type);
232
+ const manifestName = type === 'workflows' ? 'workflow.json' : 'booster.json';
233
+ if (!fs.existsSync(root)) return { [type]: [] };
234
+ const q = (search || '').toLowerCase();
235
+ const items = fs.readdirSync(root, { withFileTypes: true })
236
+ .filter((e) => e.isDirectory() && fs.existsSync(join(root, e.name, manifestName)))
237
+ .map((e) => JSON.parse(fs.readFileSync(join(root, e.name, manifestName), 'utf8')))
238
+ .filter((m) => !q ||
239
+ (m.slug || '').toLowerCase().includes(q) ||
240
+ (m.name || '').toLowerCase().includes(q) ||
241
+ (m.description || '').toLowerCase().includes(q));
242
+ return { [type]: items };
243
+ }
244
+
229
245
  export async function getStarterKit() {
230
246
  const res = await apiRequest('/api/cli/starter-kit');
231
247
  return res.json();
package/src/lib/ask.js ADDED
@@ -0,0 +1,76 @@
1
+ // Non-interactive-safe prompt wrappers.
2
+ //
3
+ // @clack/prompts crashes with `uv_tty_init EBADF` when stdin is not a TTY —
4
+ // which is every AI-agent shell, CI job, and piped invocation. Agents are now
5
+ // a primary CLI consumer (the AstralKit MCP instructs them to RUN the install
6
+ // command), so every prompt must degrade to a sensible default instead of
7
+ // crashing mid-install and leaving a partial install (component written,
8
+ // dependencies missing).
9
+ //
10
+ // Resolution order: --yes flag / ASTRALKIT_YES=1 env → auto-accept defaults;
11
+ // non-TTY stdin/stdout → auto-accept defaults (logged); real TTY → prompt.
12
+
13
+ import * as p from '@clack/prompts';
14
+ import pc from 'picocolors';
15
+
16
+ let assumeYes = false;
17
+
18
+ /** Wire the --yes flag (call once at command start). ASTRALKIT_YES=1 also works. */
19
+ export function setAssumeYes(v) {
20
+ assumeYes = !!v;
21
+ }
22
+
23
+ export function isNonInteractive() {
24
+ return assumeYes ||
25
+ process.env.ASTRALKIT_YES === '1' ||
26
+ !process.stdin.isTTY ||
27
+ !process.stdout.isTTY;
28
+ }
29
+
30
+ function autoLog(message, choice) {
31
+ const why = assumeYes || process.env.ASTRALKIT_YES === '1' ? '--yes' : 'non-interactive';
32
+ console.log(pc.gray(` ${message} → ${choice} (${why})`));
33
+ }
34
+
35
+ /**
36
+ * confirm() that never crashes on a non-TTY. `nonInteractive` is the value
37
+ * used when we cannot (or were told not to) prompt; defaults to initialValue.
38
+ * Returns false on user cancel.
39
+ */
40
+ export async function confirm({ message, initialValue = false, nonInteractive }) {
41
+ const fallback = nonInteractive ?? initialValue;
42
+ if (isNonInteractive()) {
43
+ autoLog(message, fallback ? 'yes' : 'no');
44
+ return fallback;
45
+ }
46
+ const res = await p.confirm({ message, initialValue });
47
+ return !p.isCancel(res) && res;
48
+ }
49
+
50
+ /**
51
+ * select() that never crashes on a non-TTY. `nonInteractive` is the value used
52
+ * when we cannot prompt; defaults to the first option's value.
53
+ * Returns the clack cancel symbol untouched so callers can keep their
54
+ * isCancel handling.
55
+ */
56
+ export async function select({ message, options, nonInteractive }) {
57
+ if (isNonInteractive()) {
58
+ const value = nonInteractive ?? options[0]?.value;
59
+ autoLog(message, String(value));
60
+ return value;
61
+ }
62
+ return p.select({ message, options });
63
+ }
64
+
65
+ /**
66
+ * text() that never crashes on a non-TTY. `nonInteractive` is the value used
67
+ * when we cannot prompt (defaults to the placeholder).
68
+ */
69
+ export async function text({ message, placeholder, nonInteractive }) {
70
+ if (isNonInteractive()) {
71
+ const value = nonInteractive ?? placeholder ?? '';
72
+ autoLog(message, value);
73
+ return value;
74
+ }
75
+ return p.text({ message, placeholder });
76
+ }
package/src/lib/merges.js CHANGED
@@ -26,15 +26,16 @@ import path from 'path';
26
26
  import pc from 'picocolors';
27
27
  import * as p from '@clack/prompts';
28
28
  import { isSafePath, isSafeInstallDir } from './validators.js';
29
+ import { confirm as askConfirm } from './ask.js';
29
30
 
30
31
  /**
31
- * Confirm with the user, or auto-accept when ASTRALKIT_YES=1 (CI/QA runs where
32
- * no TTY is attached). Returns true/false; never a cancel symbol.
32
+ * Confirm with the user, or auto-accept when non-interactive (--yes,
33
+ * ASTRALKIT_YES=1, or no TTY — agent/CI shells). Merges apply project wiring
34
+ * the installed piece needs, so the non-interactive default is accept.
35
+ * Returns true/false; never a cancel symbol.
33
36
  */
34
37
  async function confirmOrAuto(opts) {
35
- if (process.env.ASTRALKIT_YES === '1') return true;
36
- const answer = await p.confirm(opts);
37
- return !p.isCancel(answer) && answer;
38
+ return askConfirm({ ...opts, nonInteractive: true });
38
39
  }
39
40
 
40
41
  /**
@@ -139,14 +139,38 @@ export function isSensitivePath(relPath) {
139
139
  return segments.some(seg => SENSITIVE_FILE_PATTERNS.some(re => re.test(seg)));
140
140
  }
141
141
 
142
- export function writeFiles(baseDir, files) {
142
+ // The subset of "sensitive" files a full-app SCAFFOLD legitimately ships
143
+ // (workflow installs into a fresh directory). Env files, lockfiles, VCS/CI
144
+ // metadata, and shell dotfiles stay blocked even in scaffold mode.
145
+ const SCAFFOLD_ALLOWED_FILES = [
146
+ /^package\.json$/i,
147
+ /^package-lock\.json$/i, // pins the workflow's exact working dependency tree
148
+ /^next\.config\.(js|ts|mjs|cjs)$/i,
149
+ /^\.gitignore$/i,
150
+ // Scaffolds may carry install settings (e.g. legacy-peer-deps). No more
151
+ // powerful than the package.json install scripts a scaffold already ships.
152
+ /^\.npmrc$/i,
153
+ ];
154
+
155
+ function isScaffoldAllowed(relPath) {
156
+ const normalized = relPath.replace(/\\/g, '/').replace(/^\.\//, '');
157
+ const segments = normalized.split('/').filter(Boolean);
158
+ if (segments.length === 0) return false;
159
+ const file = segments[segments.length - 1];
160
+ const dirs = segments.slice(0, -1);
161
+ // Directories must still be clean (e.g. `.git/package.json` stays blocked).
162
+ if (dirs.some(seg => SENSITIVE_FILE_PATTERNS.some(re => re.test(seg)))) return false;
163
+ return SCAFFOLD_ALLOWED_FILES.some(re => re.test(file));
164
+ }
165
+
166
+ export function writeFiles(baseDir, files, opts = {}) {
143
167
  let count = 0;
144
168
  for (const file of files) {
145
169
  if (!isSafePath(baseDir, file.path)) {
146
170
  console.log(pc.red(` Skipping suspicious path: ${file.path}`));
147
171
  continue;
148
172
  }
149
- if (isSensitivePath(file.path)) {
173
+ if (isSensitivePath(file.path) && !(opts.scaffold && isScaffoldAllowed(file.path))) {
150
174
  console.log(pc.red(` Skipping sensitive path: ${file.path}`));
151
175
  continue;
152
176
  }