create-gtkx 2.0.0-beta.11 → 2.0.0-beta.13

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 (55) hide show
  1. package/README.md +5 -5
  2. package/dependency-ranges.json +7 -0
  3. package/dist/build-allowance.d.ts +43 -2
  4. package/dist/build-allowance.d.ts.map +1 -1
  5. package/dist/build-allowance.js +360 -10
  6. package/dist/build-allowance.js.map +1 -1
  7. package/dist/command.d.ts.map +1 -1
  8. package/dist/command.js +7 -2
  9. package/dist/command.js.map +1 -1
  10. package/dist/errors.d.ts.map +1 -1
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +1 -0
  14. package/dist/index.js.map +1 -1
  15. package/dist/manifest.d.ts.map +1 -1
  16. package/dist/package-managers.d.ts +6 -0
  17. package/dist/package-managers.d.ts.map +1 -1
  18. package/dist/package-managers.js +6 -0
  19. package/dist/package-managers.js.map +1 -1
  20. package/dist/project-name.d.ts +4 -2
  21. package/dist/project-name.d.ts.map +1 -1
  22. package/dist/project-name.js +12 -2
  23. package/dist/project-name.js.map +1 -1
  24. package/dist/scaffolder.d.ts.map +1 -1
  25. package/dist/scaffolder.js +181 -72
  26. package/dist/scaffolder.js.map +1 -1
  27. package/dist/templates/.claude/settings.json.ejs +4 -3
  28. package/dist/templates/.gitignore.ejs +3 -0
  29. package/dist/templates/.mcp.json.ejs +1 -1
  30. package/dist/templates/src/app.tsx.ejs +1 -1
  31. package/dist/templates/src/gtkx-env.d.ts.ejs +0 -1
  32. package/dist/templates/tsconfig.json.ejs +3 -2
  33. package/dist/templates.d.ts +3 -0
  34. package/dist/templates.d.ts.map +1 -1
  35. package/dist/templates.js +10 -6
  36. package/dist/templates.js.map +1 -1
  37. package/dist/workspace-mcp.d.ts +33 -0
  38. package/dist/workspace-mcp.d.ts.map +1 -0
  39. package/dist/workspace-mcp.js +75 -0
  40. package/dist/workspace-mcp.js.map +1 -0
  41. package/package.json +16 -47
  42. package/src/build-allowance.ts +488 -10
  43. package/src/command.ts +9 -4
  44. package/src/index.ts +1 -0
  45. package/src/package-managers.ts +6 -0
  46. package/src/project-name.ts +19 -2
  47. package/src/scaffolder.ts +278 -94
  48. package/src/templates/.claude/settings.json.ejs +4 -3
  49. package/src/templates/.gitignore.ejs +3 -0
  50. package/src/templates/.mcp.json.ejs +1 -1
  51. package/src/templates/src/app.tsx.ejs +1 -1
  52. package/src/templates/src/gtkx-env.d.ts.ejs +0 -1
  53. package/src/templates/tsconfig.json.ejs +3 -2
  54. package/src/templates.ts +17 -8
  55. package/src/workspace-mcp.ts +111 -0
@@ -1,41 +1,49 @@
1
1
  import * as p from "@clack/prompts";
2
2
  import { APPLICATION_ID_MAX_LENGTH, isValidApplicationId } from "@gtkx/config/internal";
3
- import { errorMessage, tryResolveExecutable, upperFirst } from "@gtkx/utils";
3
+ import { errorMessage, HEADLESS_DISPLAY_TOOLS, missingToolLines, tryResolveExecutable, upperFirst } from "@gtkx/utils";
4
4
  import { execFileSync } from "node:child_process";
5
- import { lstatSync, mkdirSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
5
+ import { lstatSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
6
+ import { homedir } from "node:os";
6
7
  import { basename, dirname, join, relative, resolve, sep } from "node:path";
7
8
  import { addDependency, detectPackageManager as nypmDetectPackageManager } from "nypm";
8
9
  import { x } from "tinyexec";
9
10
  import packageManifest from "../package.json" with { type: "json" };
10
- import { writeBuildAllowance } from "./build-allowance.js";
11
+ import { PACKAGE_MANAGER_CONFIG_FILES, enclosingWorkspace, packageManagerPin, writePackageManagerSettings, } from "./build-allowance.js";
11
12
  import { OperationCanceledError, ScaffoldAbortedError } from "./errors.js";
12
13
  import { updateManifest } from "./manifest.js";
13
14
  import { isKnownPackageManager, PACKAGE_MANAGER_VALUES, PACKAGE_MANAGERS, } from "./package-managers.js";
14
- import { isValidProjectName } from "./project-name.js";
15
+ import { isValidPackageName, packageNameFromDirectory, withoutAccents } from "./project-name.js";
15
16
  import { listTemplates, renderFile } from "./templates.js";
17
+ import { addWorkspaceMcpServer } from "./workspace-mcp.js";
16
18
  const selfVersion = packageManifest.version;
17
19
  const ICON_TEMPLATE_NAME = "icon.svg";
18
20
  const TYPESCRIPT_VERSION = "^6.0.3";
21
+ const DEPENDENCY_RANGES = {
22
+ ...JSON.parse(readFileSync(new URL("../dependency-ranges.json", import.meta.url), "utf8")),
23
+ typescript: TYPESCRIPT_VERSION,
24
+ };
19
25
  const DEPENDENCIES = ["@gtkx/cairo", "@gtkx/css", "@gtkx/runtime", "@gtkx/react", "react"];
20
- const DEV_DEPENDENCIES = ["@gtkx/cli", "@gtkx/config", "@gtkx/mcp", "vite"];
21
- const TYPESCRIPT_DEV_DEPENDENCIES = ["@types/node", "@types/react", "typescript"];
22
- const TESTING_DEV_DEPENDENCIES = ["@gtkx/testing", "vitest"];
26
+ const DEV_DEPENDENCIES = ["@gtkx/cli", "@gtkx/config", "@gtkx/mcp", "@gtkx/testing", "@types/react", "vite"];
27
+ const TYPESCRIPT_DEV_DEPENDENCIES = ["@types/node", "typescript"];
28
+ const TESTING_DEV_DEPENDENCIES = ["vitest"];
23
29
  const DEV_COMMAND = Object.fromEntries(PACKAGE_MANAGERS.map((manager) => [manager.value, manager.devCommand]));
24
30
  const INSTALL_COMMAND = Object.fromEntries(PACKAGE_MANAGERS.map((manager) => [manager.value, manager.installCommand]));
31
+ const RUN_COMMAND = Object.fromEntries(PACKAGE_MANAGERS.map((manager) => [manager.value, manager.runCommand]));
32
+ const TEST_COMMAND = Object.fromEntries(PACKAGE_MANAGERS.map((manager) => [manager.value, manager.testCommand]));
25
33
  const INHERITED_SCRIPT_POLICY_VARS = ["npm_config_allow_scripts", "npm_config_allow-scripts"];
34
+ const LENIENT_PNPM_BUILDS_ENV = { pnpm_config_strict_dep_builds: "false" };
26
35
  const TESTING_TEMPLATES = new Set(["vitest.config.ts", "tests/app.test.tsx"]);
27
36
  const TYPESCRIPT_TEMPLATES = new Set(["tsconfig.json", "src/gtkx-env.d.ts"]);
28
- const HEADLESS_COMPOSITOR_NOTE = `
29
-
30
- To run tests, you need a headless Wayland compositor installed:
31
- Fedora: sudo dnf install sway
32
- Ubuntu: sudo apt install sway`;
33
37
  const APPLICATION_ID_FORMAT_ERROR = "Application ID must be reverse domain notation (e.g., com.example.myapp)";
38
+ const PACKAGE_NAME_FORMAT_ERROR = "Package name must be a valid npm package name: lowercase, no spaces (e.g., my-app)";
34
39
  const APPLICATION_ID_PREFIX = "com.";
35
40
  const APPLICATION_ID_SUFFIX = ".app";
36
- const APPLICATION_ID_SEGMENT_LIMIT = APPLICATION_ID_MAX_LENGTH - APPLICATION_ID_PREFIX.length -
37
- APPLICATION_ID_SUFFIX.length;
38
- const displayNameFromProjectName = (name) => name.split("-").map((part) => upperFirst(part)).join(" ");
41
+ const APPLICATION_ID_SEGMENT_LIMIT = APPLICATION_ID_MAX_LENGTH - APPLICATION_ID_PREFIX.length - APPLICATION_ID_SUFFIX.length;
42
+ const displayNameFromDirectory = (directoryName) => directoryName
43
+ .split(/[\s._-]+/)
44
+ .filter((part) => part.length > 0)
45
+ .map((part) => upperFirst(part))
46
+ .join(" ");
39
47
  const gitConfigValue = (key) => {
40
48
  const git = tryResolveExecutable("git");
41
49
  if (git === undefined) {
@@ -48,13 +56,16 @@ const gitConfigValue = (key) => {
48
56
  return null;
49
57
  }
50
58
  };
51
- const applicationIdSegment = (name) => {
52
- const compact = name.replaceAll("-", "");
59
+ const compactIdentifier = (name) => withoutAccents(name).replaceAll(/[^A-Za-z0-9_]/g, "");
60
+ const applicationIdSegment = (directoryName, name) => {
61
+ const compact = compactIdentifier(directoryName) || compactIdentifier(name);
53
62
  const segment = /^[A-Za-z_]/.test(compact) ? compact : `_${compact}`;
54
63
  return segment.slice(0, APPLICATION_ID_SEGMENT_LIMIT);
55
64
  };
56
- const suggestApplicationId = (name) => `${APPLICATION_ID_PREFIX}${applicationIdSegment(name)}${APPLICATION_ID_SUFFIX}`;
57
- const deriveProjectName = (target) => basename(resolve(process.cwd(), target));
65
+ const suggestApplicationId = (directoryName, name) => `${APPLICATION_ID_PREFIX}${applicationIdSegment(directoryName, name)}${APPLICATION_ID_SUFFIX}`;
66
+ const HOME_PREFIX = /^~(?=$|\/)/;
67
+ const expandHome = (target) => target.replace(HOME_PREFIX, () => homedir());
68
+ const directoryNameOf = (target) => basename(resolve(process.cwd(), target));
58
69
  const isDirEmpty = (dir) => {
59
70
  const entries = readdirSync(dir);
60
71
  return entries.length === 0 || (entries.length === 1 && entries[0] === ".git");
@@ -81,15 +92,9 @@ const guardCancellation = (value) => {
81
92
  }
82
93
  return value;
83
94
  };
84
- const validateProjectName = (value) => {
85
- if (!value) {
86
- return "Project name is required";
87
- }
88
- if (!isValidProjectName(value)) {
89
- return "Project name must be lowercase letters, numbers, and hyphens only";
90
- }
91
- return undefined;
92
- };
95
+ const validatePackageNameFormat = (value) => isValidPackageName(value) ? undefined : PACKAGE_NAME_FORMAT_ERROR;
96
+ const validatePackageNameInput = (value) => value ? validatePackageNameFormat(value) : "Package name is required";
97
+ const validatePackageNameAnswer = (value) => value ? validatePackageNameFormat(value) : undefined;
93
98
  const validateApplicationIdFormat = (value) => isValidApplicationId(value) ? undefined : APPLICATION_ID_FORMAT_ERROR;
94
99
  const validateApplicationIdInput = (value) => value ? validateApplicationIdFormat(value) : "Application ID is required";
95
100
  const validateApplicationIdAnswer = (value) => value ? validateApplicationIdFormat(value) : undefined;
@@ -113,20 +118,20 @@ const requestedPackageManager = (value) => {
113
118
  }
114
119
  return value;
115
120
  };
116
- const validateTargetDir = (target) => {
117
- if (!target) {
118
- return "Project directory is required";
119
- }
120
- return validateProjectName(deriveProjectName(target));
121
- };
122
- const validateTargetAnswer = (value) => validateTargetDir(value ?? "");
121
+ const validateTargetDir = (target) => target ? undefined : "Project directory is required";
122
+ const validateTargetAnswer = (value) => validateTargetDir(expandHome(value ?? ""));
123
123
  const promptTarget = async () => guardCancellation(await p.text({
124
124
  message: "Project directory",
125
125
  placeholder: "my-app",
126
126
  validate: validateTargetAnswer,
127
127
  }));
128
- const promptApplicationId = async (name) => {
129
- const defaultApplicationId = suggestApplicationId(name);
128
+ const promptPackageName = async (derived) => guardCancellation(await p.text({
129
+ message: "Package name",
130
+ ...(derived === "" ? {} : { placeholder: derived, defaultValue: derived }),
131
+ validate: derived === "" ? validatePackageNameInput : validatePackageNameAnswer,
132
+ }));
133
+ const promptApplicationId = async (directoryName, name) => {
134
+ const defaultApplicationId = suggestApplicationId(directoryName, name);
130
135
  return guardCancellation(await p.text({
131
136
  message: "Application ID",
132
137
  placeholder: defaultApplicationId,
@@ -134,8 +139,8 @@ const promptApplicationId = async (name) => {
134
139
  validate: validateApplicationIdAnswer,
135
140
  }));
136
141
  };
137
- const promptDisplayName = async (name) => {
138
- const defaultDisplayName = displayNameFromProjectName(name);
142
+ const promptDisplayName = async (directoryName) => {
143
+ const defaultDisplayName = displayNameFromDirectory(directoryName);
139
144
  return guardCancellation(await p.text({
140
145
  message: "Display name",
141
146
  placeholder: defaultDisplayName,
@@ -231,21 +236,36 @@ const validateTargetAvailability = async (root, target, options, changes) => {
231
236
  };
232
237
  const resolveTarget = async (options) => {
233
238
  if (options.name === undefined && options.isInteractive) {
234
- return promptTarget();
239
+ return expandHome(await promptTarget());
235
240
  }
236
- const target = options.name ?? "";
241
+ const target = expandHome(options.name ?? "");
237
242
  const error = validateTargetDir(target);
238
243
  return error === undefined ? target : fail(error);
239
244
  };
240
- const resolveApplicationId = async (options, name) => {
245
+ const resolvePackageName = async (options, directoryName) => {
246
+ const derived = packageNameFromDirectory(directoryName);
247
+ if (derived === directoryName) {
248
+ return derived;
249
+ }
250
+ if (options.isInteractive) {
251
+ return promptPackageName(derived);
252
+ }
253
+ return derived === ""
254
+ ? fail(`Directory name "${directoryName}" has no Latin letters or numbers to derive a package name from. ` +
255
+ "Rename it, or run interactively to enter a package name")
256
+ : derived;
257
+ };
258
+ const resolveApplicationId = async (options, directoryName, name) => {
241
259
  const applicationId = options.applicationId ??
242
- (options.isInteractive ? await promptApplicationId(name) : suggestApplicationId(name));
260
+ (options.isInteractive
261
+ ? await promptApplicationId(directoryName, name)
262
+ : suggestApplicationId(directoryName, name));
243
263
  const error = validateApplicationIdInput(applicationId);
244
264
  return error === undefined ? applicationId : fail(error);
245
265
  };
246
- const resolveDisplayName = async (options, name) => {
266
+ const resolveDisplayName = async (options, directoryName) => {
247
267
  const value = options.displayName ??
248
- (options.isInteractive ? await promptDisplayName(name) : displayNameFromProjectName(name));
268
+ (options.isInteractive ? await promptDisplayName(directoryName) : displayNameFromDirectory(directoryName));
249
269
  const error = validateDisplayName(value);
250
270
  return error === undefined ? value.trim() : fail(error);
251
271
  };
@@ -261,9 +281,10 @@ const resolvePackageManager = async (requested, options) => {
261
281
  const resolveOptions = async (options) => {
262
282
  const requested = requestedPackageManager(options.packageManager);
263
283
  const target = await resolveTarget(options);
264
- const name = deriveProjectName(target);
265
- const displayName = await resolveDisplayName(options, name);
266
- const applicationId = await resolveApplicationId(options, name);
284
+ const directoryName = directoryNameOf(target);
285
+ const name = await resolvePackageName(options, directoryName);
286
+ const displayName = await resolveDisplayName(options, directoryName);
287
+ const applicationId = await resolveApplicationId(options, directoryName, name);
267
288
  const root = resolve(process.cwd(), target);
268
289
  const shouldInitialize = shouldInitializeGit(root);
269
290
  const packageManager = await resolvePackageManager(requested, options);
@@ -276,6 +297,7 @@ const resolveOptions = async (options) => {
276
297
  displayName,
277
298
  applicationId,
278
299
  packageManager,
300
+ workspace: enclosingWorkspace(root, packageManager),
279
301
  isTypescript,
280
302
  shouldIncludeTesting,
281
303
  shouldInitializeGit: shouldInitialize,
@@ -297,6 +319,10 @@ const destinationPath = (template, resolved) => {
297
319
  ? `${scriptPath.slice(0, -ICON_TEMPLATE_NAME.length)}${resolved.applicationId}.svg`
298
320
  : scriptPath;
299
321
  };
322
+ const scriptCommands = ({ packageManager, isTypescript, shouldIncludeTesting, }) => [
323
+ ...["dev", "build", "codegen", ...(isTypescript ? ["typecheck"] : [])].map((script) => `${RUN_COMMAND[packageManager]} ${script}`),
324
+ ...(shouldIncludeTesting ? [TEST_COMMAND[packageManager]] : []),
325
+ ];
300
326
  const templateContext = (resolved) => ({
301
327
  name: resolved.name,
302
328
  applicationId: resolved.applicationId,
@@ -306,6 +332,8 @@ const templateContext = (resolved) => ({
306
332
  importExtension: resolved.isTypescript ? ".js" : ".jsx",
307
333
  developerName: gitConfigValue("user.name") ?? resolved.displayName,
308
334
  developerEmail: gitConfigValue("user.email"),
335
+ packageManager: resolved.packageManager,
336
+ scriptCommands: scriptCommands(resolved),
309
337
  });
310
338
  const assertSafeAncestor = (ancestor) => {
311
339
  const entry = lstatSync(ancestor, { throwIfNoEntry: false });
@@ -350,18 +378,25 @@ const plannedScaffoldFiles = async (root, resolved) => {
350
378
  }
351
379
  return files;
352
380
  };
353
- const auxiliaryDestinations = (root, resolved) => resolved.packageManager === "pnpm" ? [join(root, "pnpm-workspace.yaml")] : [];
381
+ const configDestinations = (root, resolved) => resolved.workspace === null
382
+ ? PACKAGE_MANAGER_CONFIG_FILES[resolved.packageManager].map((file) => join(root, file))
383
+ : [];
354
384
  const planScaffoldProject = async (root, resolved) => {
355
385
  const files = await plannedScaffoldFiles(root, resolved);
356
- const destinations = [...files.map((file) => file.destination), ...auxiliaryDestinations(root, resolved)];
357
- const replaceDestinations = destinations.filter((destination) => hasExistingDestination(root, destination));
386
+ for (const destination of configDestinations(root, resolved)) {
387
+ hasExistingDestination(root, destination);
388
+ }
389
+ const replaceDestinations = files
390
+ .map((file) => file.destination)
391
+ .filter((destination) => hasExistingDestination(root, destination));
358
392
  return {
359
393
  files,
360
394
  replaceDestinations,
361
395
  changes: replaceDestinations.map((destination) => relative(root, destination)),
396
+ packageManagerPin: packageManagerPin(root, resolved.packageManager, resolved.workspace !== null),
362
397
  };
363
398
  };
364
- const scaffoldProject = (plan) => {
399
+ const scaffoldProject = (root, plan) => {
365
400
  for (const destination of plan.replaceDestinations) {
366
401
  rmSync(destination);
367
402
  }
@@ -369,6 +404,12 @@ const scaffoldProject = (plan) => {
369
404
  mkdirSync(dirname(file.destination), { recursive: true });
370
405
  writeFileSync(file.destination, file.contents);
371
406
  }
407
+ const pin = plan.packageManagerPin;
408
+ if (pin !== null) {
409
+ updateManifest(root, (manifest) => {
410
+ manifest.packageManager = pin;
411
+ });
412
+ }
372
413
  };
373
414
  const withoutInheritedScriptPolicy = async (run) => {
374
415
  const saved = INHERITED_SCRIPT_POLICY_VARS.map((key) => [key, process.env[key]]);
@@ -390,44 +431,83 @@ const dependencyVersions = (names) => Object.fromEntries(names.map((dependency)
390
431
  if (dependency.startsWith("@gtkx/")) {
391
432
  return [dependency, `^${selfVersion}`];
392
433
  }
393
- return [dependency, dependency === "typescript" ? TYPESCRIPT_VERSION : "latest"];
434
+ const range = DEPENDENCY_RANGES[dependency];
435
+ if (range === undefined) {
436
+ throw new Error(`No supported version range for ${dependency}`);
437
+ }
438
+ return [dependency, range];
394
439
  }));
395
- const dependencyArguments = (names) => Object.entries(dependencyVersions(names)).map(([name, version]) => version === "latest" ? name : `${name}@${version}`);
440
+ const dependencyArguments = (names) => Object.entries(dependencyVersions(names)).map(([name, version]) => `${name}@${version}`);
441
+ const declaredDependencies = (value) => typeof value === "object" && value !== null ? { ...value } : {};
396
442
  const writeDependencies = (root, devDependencies) => {
397
443
  updateManifest(root, (manifest) => {
398
- manifest.dependencies = dependencyVersions(DEPENDENCIES);
399
- manifest.devDependencies = dependencyVersions(devDependencies);
444
+ manifest.dependencies = {
445
+ ...dependencyVersions(DEPENDENCIES),
446
+ ...declaredDependencies(manifest.dependencies),
447
+ };
448
+ manifest.devDependencies = {
449
+ ...dependencyVersions(devDependencies),
450
+ ...declaredDependencies(manifest.devDependencies),
451
+ };
400
452
  });
401
453
  };
402
454
  const formatRecovery = (resolved) => `To finish setup, run ${INSTALL_COMMAND[resolved.packageManager]} in ${resolved.root}.`;
455
+ const startProgress = (message) => {
456
+ if (process.stdout.isTTY) {
457
+ const spinner = p.spinner();
458
+ spinner.start(message);
459
+ return spinner;
460
+ }
461
+ p.log.step(message);
462
+ return { stop: (done) => p.log.step(done), error: (failed) => p.log.error(failed) };
463
+ };
403
464
  const runWithSpinner = async (step) => {
404
- const spinner = p.spinner();
405
- spinner.start(step.pending);
465
+ const progress = startProgress(step.pending);
406
466
  try {
407
467
  await step.run();
408
- spinner.stop(step.done);
468
+ progress.stop(step.done);
409
469
  }
410
470
  catch (error) {
411
- spinner.error(step.failed);
471
+ progress.error(step.failed);
412
472
  p.log.error(errorMessage(error));
413
473
  step.explain?.();
414
474
  throw new ScaffoldAbortedError(step.failed);
415
475
  }
416
476
  };
477
+ const printWorkspaceAllowances = ({ root, packageManager, workspace }) => {
478
+ const installed = workspace === null ? null : enclosingWorkspace(root, packageManager);
479
+ if (installed === null || installed.missingSettings.length === 0) {
480
+ return;
481
+ }
482
+ p.log.warn(`The ${installed.packageManager} workspace lacks settings this app needs. ` +
483
+ `Set these entries, then run ${INSTALL_COMMAND[installed.packageManager]}:\n\n` +
484
+ installed.missingSettings
485
+ .map(({ file, section, entries }) => `${section === null ? file : `${file} (under ${section})`}:\n${entries}`)
486
+ .join("\n\n"));
487
+ };
488
+ const hasMissingAllowances = (resolved) => resolved.workspace?.packageManager === "pnpm" && resolved.workspace.missingSettings.length > 0;
417
489
  const installAllDependencies = async (resolved, devDependencies) => {
418
490
  const { root, packageManager } = resolved;
491
+ const env = hasMissingAllowances(resolved) ? LENIENT_PNPM_BUILDS_ENV : {};
419
492
  await runWithSpinner({
420
493
  pending: "Installing dependencies...",
421
494
  done: "Dependencies installed",
422
495
  failed: "Failed to install dependencies",
423
496
  run: async () => {
424
- await withoutInheritedScriptPolicy(async () => {
425
- const options = { cwd: root, packageManager, silent: true };
426
- await addDependency(dependencyArguments(DEPENDENCIES), options);
427
- await addDependency(dependencyArguments(devDependencies), { ...options, dev: true });
428
- });
497
+ try {
498
+ await withoutInheritedScriptPolicy(async () => {
499
+ const options = { cwd: root, packageManager, env, silent: true };
500
+ await addDependency(dependencyArguments(DEPENDENCIES), options);
501
+ await addDependency(dependencyArguments(devDependencies), { ...options, dev: true });
502
+ });
503
+ }
504
+ catch (error) {
505
+ writeDependencies(root, devDependencies);
506
+ throw error;
507
+ }
429
508
  },
430
509
  explain: () => {
510
+ printWorkspaceAllowances(resolved);
431
511
  p.log.info(formatRecovery(resolved));
432
512
  },
433
513
  });
@@ -449,23 +529,48 @@ const initializeGitRepo = async (root, shouldInitialize) => {
449
529
  if (!shouldInitialize || isInsideGitRepository(root)) {
450
530
  return;
451
531
  }
452
- const spinner = p.spinner();
453
- spinner.start("Initializing git repository...");
532
+ const progress = startProgress("Initializing git repository...");
454
533
  try {
455
534
  const opts = { nodeOptions: { cwd: root }, throwOnError: true };
456
535
  await x("git", ["init"], opts);
457
536
  await x("git", ["add", "-A"], opts);
458
537
  await x("git", ["commit", "-m", "Initial commit"], opts);
459
- spinner.stop("Git repository initialized");
538
+ progress.stop("Git repository initialized");
460
539
  }
461
540
  catch {
462
- spinner.error("Failed to initialize git repository");
541
+ progress.error("Failed to initialize git repository");
542
+ }
543
+ };
544
+ const missingHeadlessToolsNote = () => {
545
+ const missing = Object.values(HEADLESS_DISPLAY_TOOLS).filter((tool) => tryResolveExecutable(tool.command) === undefined);
546
+ return missing.length === 0
547
+ ? ""
548
+ : ["", "", "To run tests, install these tools:", ...missingToolLines(missing)].join("\n");
549
+ };
550
+ const addRootMcpServer = ({ workspace, name, root }) => {
551
+ if (workspace === null) {
552
+ return;
553
+ }
554
+ const result = addWorkspaceMcpServer(workspace, name);
555
+ if (result.kind === "added") {
556
+ p.log.info(`Added the MCP server "${result.key}" to ${result.path}, so an AI client opened at the workspace ` +
557
+ "root reaches this app.");
558
+ }
559
+ else if (result.kind === "shared") {
560
+ p.log.info(`The MCP server "${result.key}" in ${result.path} drives every running GTKX app, including this one, ` +
561
+ `so no server was added for it. To look up this app's bindings, pass projectRoot "${root}" to its ` +
562
+ "reference tools.");
563
+ }
564
+ else if (result.kind === "unreadable") {
565
+ p.log.warn(`Could not add this app's MCP server to ${result.path}: ${result.reason}. For an AI client opened ` +
566
+ `at the workspace root, add this entry under "mcpServers":\n\n` +
567
+ JSON.stringify({ [result.key]: result.server }, null, 4));
463
568
  }
464
569
  };
465
570
  const printNextSteps = (resolved) => {
466
571
  const devCmd = DEV_COMMAND[resolved.packageManager];
467
572
  const installStep = resolved.shouldInstallDependencies ? "" : `${INSTALL_COMMAND[resolved.packageManager]}\n`;
468
- const testingNote = resolved.shouldIncludeTesting ? HEADLESS_COMPOSITOR_NOTE : "";
573
+ const testingNote = resolved.shouldIncludeTesting ? missingHeadlessToolsNote() : "";
469
574
  p.note(`${installStep}${devCmd}${testingNote}`, `Run in ${resolved.root}`);
470
575
  };
471
576
  const createProjectStructure = async (root, resolved, plan) => {
@@ -475,8 +580,10 @@ const createProjectStructure = async (root, resolved, plan) => {
475
580
  failed: "Failed to create the project structure",
476
581
  run: () => {
477
582
  mkdirSync(root, { recursive: true });
478
- scaffoldProject(plan);
479
- writeBuildAllowance(root, resolved.packageManager);
583
+ scaffoldProject(root, plan);
584
+ if (resolved.workspace === null) {
585
+ writePackageManagerSettings(root, resolved.packageManager);
586
+ }
480
587
  },
481
588
  });
482
589
  };
@@ -491,10 +598,12 @@ const scaffold = async (options = {}) => {
491
598
  await createProjectStructure(root, resolved, plan);
492
599
  writeDependencies(root, devDeps);
493
600
  reportCompletedChanges(plan.changes);
601
+ addRootMcpServer(resolved);
494
602
  if (resolved.shouldInstallDependencies) {
495
603
  await installAllDependencies(resolved, devDeps);
496
604
  }
497
605
  await initializeGitRepo(root, resolved.shouldInitializeGit);
606
+ printWorkspaceAllowances(resolved);
498
607
  printNextSteps(resolved);
499
608
  };
500
609
  export { scaffold };