wp-typia 0.22.9 → 0.22.10

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.
@@ -11,13 +11,15 @@ import {
11
11
  WP_TYPIA_TOP_LEVEL_COMMAND_NAMES,
12
12
  buildCommandOptions,
13
13
  emitCliDiagnosticFailure,
14
+ formatAddKindList,
15
+ formatAddKindUsagePlaceholder,
14
16
  getAddBlockDefaults,
15
17
  getCreateDefaults,
16
18
  getMcpSchemaSources,
17
19
  package_default,
18
20
  prefersStructuredCliOutput,
19
21
  resolveCommandOptionValues
20
- } from "./cli-y934dq2k.js";
22
+ } from "./cli-spdrcg8k.js";
21
23
  import {
22
24
  Result,
23
25
  TaggedError,
@@ -182,6 +184,7 @@ function assertAddBlockTemplateId(context, templateId) {
182
184
  }
183
185
 
184
186
  // src/add-kinds/ability.ts
187
+ var ABILITY_MISSING_NAME_MESSAGE = "`wp-typia add ability` requires <name>. Usage: wp-typia add ability <name>.";
185
188
  var abilityAddKindEntry = defineAddKindRegistryEntry({
186
189
  completion: {
187
190
  nextSteps: (values) => [
@@ -206,7 +209,7 @@ var abilityAddKindEntry = defineAddKindRegistryEntry({
206
209
  abilitySlug: result.abilitySlug
207
210
  }),
208
211
  getWarnings: (result) => result.warnings,
209
- missingNameMessage: "`wp-typia add ability` requires <name>. Usage: wp-typia add ability <name>.",
212
+ missingNameMessage: ABILITY_MISSING_NAME_MESSAGE,
210
213
  warnLine: context.warnLine
211
214
  });
212
215
  },
@@ -257,6 +260,7 @@ function readOptionalPairedStrictStringFlags(flags, leftName, rightName, message
257
260
  }
258
261
 
259
262
  // src/add-kinds/admin-view.ts
263
+ var ADMIN_VIEW_MISSING_NAME_MESSAGE = "`wp-typia add admin-view` requires <name>. Usage: wp-typia add admin-view <name> [--source <rest-resource:slug|core-data:kind/name>].";
260
264
  var adminViewAddKindEntry = defineAddKindRegistryEntry({
261
265
  completion: {
262
266
  nextSteps: (values) => [
@@ -273,7 +277,7 @@ var adminViewAddKindEntry = defineAddKindRegistryEntry({
273
277
  description: "Add an opt-in DataViews-powered admin screen",
274
278
  nameLabel: "Admin view name",
275
279
  async prepareExecution(context) {
276
- const name = requireAddKindName(context, "`wp-typia add admin-view` requires <name>. Usage: wp-typia add admin-view <name> [--source <rest-resource:slug|core-data:kind/name>].");
280
+ const name = requireAddKindName(context, ADMIN_VIEW_MISSING_NAME_MESSAGE);
277
281
  const source = readOptionalStrictStringFlag(context.flags, "source");
278
282
  return createNamedExecutionPlan(context, {
279
283
  execute: ({ cwd, name: name2 }) => context.addRuntime.runAddAdminViewCommand({
@@ -285,7 +289,7 @@ var adminViewAddKindEntry = defineAddKindRegistryEntry({
285
289
  adminViewSlug: result.adminViewSlug,
286
290
  ...result.source ? { source: result.source } : {}
287
291
  }),
288
- missingNameMessage: "`wp-typia add admin-view` requires <name>. Usage: wp-typia add admin-view <name> [--source <rest-resource:slug|core-data:kind/name>].",
292
+ missingNameMessage: ADMIN_VIEW_MISSING_NAME_MESSAGE,
289
293
  name
290
294
  });
291
295
  },
@@ -296,6 +300,7 @@ var adminViewAddKindEntry = defineAddKindRegistryEntry({
296
300
  });
297
301
 
298
302
  // src/add-kinds/ai-feature.ts
303
+ var AI_FEATURE_MISSING_NAME_MESSAGE = "`wp-typia add ai-feature` requires <name>. Usage: wp-typia add ai-feature <name> [--namespace <vendor/v1>].";
299
304
  var aiFeatureAddKindEntry = defineAddKindRegistryEntry({
300
305
  completion: {
301
306
  nextSteps: (values) => [
@@ -312,7 +317,7 @@ var aiFeatureAddKindEntry = defineAddKindRegistryEntry({
312
317
  description: "Add a server-owned WordPress AI feature endpoint",
313
318
  nameLabel: "AI feature name",
314
319
  async prepareExecution(context) {
315
- const name = requireAddKindName(context, "`wp-typia add ai-feature` requires <name>. Usage: wp-typia add ai-feature <name> [--namespace <vendor/v1>].");
320
+ const name = requireAddKindName(context, AI_FEATURE_MISSING_NAME_MESSAGE);
316
321
  const namespace = readOptionalStrictStringFlag(context.flags, "namespace");
317
322
  return createNamedExecutionPlan(context, {
318
323
  execute: ({ cwd, name: name2 }) => context.addRuntime.runAddAiFeatureCommand({
@@ -325,7 +330,7 @@ var aiFeatureAddKindEntry = defineAddKindRegistryEntry({
325
330
  namespace: result.namespace
326
331
  }),
327
332
  getWarnings: (result) => result.warnings,
328
- missingNameMessage: "`wp-typia add ai-feature` requires <name>. Usage: wp-typia add ai-feature <name> [--namespace <vendor/v1>].",
333
+ missingNameMessage: AI_FEATURE_MISSING_NAME_MESSAGE,
329
334
  name,
330
335
  warnLine: context.warnLine
331
336
  });
@@ -337,6 +342,7 @@ var aiFeatureAddKindEntry = defineAddKindRegistryEntry({
337
342
  });
338
343
 
339
344
  // src/add-kinds/binding-source.ts
345
+ var BINDING_SOURCE_MISSING_NAME_MESSAGE = "`wp-typia add binding-source` requires <name>. Usage: wp-typia add binding-source <name> [--block <block-slug|namespace/block-slug> --attribute <attribute>].";
340
346
  var bindingSourceAddKindEntry = defineAddKindRegistryEntry({
341
347
  completion: {
342
348
  nextSteps: (values) => [
@@ -356,7 +362,7 @@ var bindingSourceAddKindEntry = defineAddKindRegistryEntry({
356
362
  description: "Add a shared block bindings source",
357
363
  nameLabel: "Binding source name",
358
364
  async prepareExecution(context) {
359
- const name = requireAddKindName(context, "`wp-typia add binding-source` requires <name>. Usage: wp-typia add binding-source <name> [--block <block-slug|namespace/block-slug> --attribute <attribute>].");
365
+ const name = requireAddKindName(context, BINDING_SOURCE_MISSING_NAME_MESSAGE);
360
366
  const [blockName, attributeName] = readOptionalPairedStrictStringFlags(context.flags, "block", "attribute", "`wp-typia add binding-source` requires --block and --attribute to be provided together.");
361
367
  return createNamedExecutionPlan(context, {
362
368
  execute: ({ cwd, name: name2 }) => context.addRuntime.runAddBindingSourceCommand({
@@ -370,7 +376,7 @@ var bindingSourceAddKindEntry = defineAddKindRegistryEntry({
370
376
  ...result.blockSlug ? { blockSlug: result.blockSlug } : {},
371
377
  bindingSourceSlug: result.bindingSourceSlug
372
378
  }),
373
- missingNameMessage: "`wp-typia add binding-source` requires <name>. Usage: wp-typia add binding-source <name> [--block <block-slug|namespace/block-slug> --attribute <attribute>].",
379
+ missingNameMessage: BINDING_SOURCE_MISSING_NAME_MESSAGE,
374
380
  name
375
381
  });
376
382
  },
@@ -397,6 +403,7 @@ function toExternalLayerPromptOptions(options) {
397
403
  }
398
404
 
399
405
  // src/add-kinds/block.ts
406
+ var BLOCK_MISSING_NAME_MESSAGE = "`wp-typia add block` requires <name>. Usage: wp-typia add block <name> [--template <basic|interactivity|persistence|compound>]";
400
407
  var blockAddKindEntry = defineAddKindRegistryEntry({
401
408
  completion: {
402
409
  nextSteps: () => [
@@ -414,7 +421,7 @@ var blockAddKindEntry = defineAddKindRegistryEntry({
414
421
  hiddenStringSubmitFields: ["external-layer-id", "external-layer-source"],
415
422
  nameLabel: "Block name",
416
423
  async prepareExecution(context) {
417
- const name = requireAddKindName(context, "`wp-typia add block` requires <name>. Usage: wp-typia add block <name> [--template <basic|interactivity|persistence|compound>]");
424
+ const name = requireAddKindName(context, BLOCK_MISSING_NAME_MESSAGE);
418
425
  const externalLayerId = readOptionalStrictStringFlag(context.flags, "external-layer-id");
419
426
  const externalLayerSource = readOptionalStrictStringFlag(context.flags, "external-layer-source");
420
427
  const shouldPromptForLayerSelection = Boolean(externalLayerSource) && !Boolean(externalLayerId) && context.isInteractiveSession;
@@ -452,7 +459,7 @@ var blockAddKindEntry = defineAddKindRegistryEntry({
452
459
  templateId: result.templateId
453
460
  }),
454
461
  getWarnings: (result) => result.warnings,
455
- missingNameMessage: "`wp-typia add block` requires <name>. Usage: wp-typia add block <name> [--template <basic|interactivity|persistence|compound>]",
462
+ missingNameMessage: BLOCK_MISSING_NAME_MESSAGE,
456
463
  name,
457
464
  warnLine: context.warnLine
458
465
  });
@@ -475,6 +482,7 @@ var blockAddKindEntry = defineAddKindRegistryEntry({
475
482
  });
476
483
 
477
484
  // src/add-kinds/editor-plugin.ts
485
+ var EDITOR_PLUGIN_MISSING_NAME_MESSAGE = "`wp-typia add editor-plugin` requires <name>. Usage: wp-typia add editor-plugin <name> [--slot <sidebar|document-setting-panel>].";
478
486
  var editorPluginAddKindEntry = defineAddKindRegistryEntry({
479
487
  completion: {
480
488
  nextSteps: (values) => [
@@ -491,7 +499,7 @@ var editorPluginAddKindEntry = defineAddKindRegistryEntry({
491
499
  description: "Add a slot-aware document editor extension shell",
492
500
  nameLabel: "Editor plugin name",
493
501
  async prepareExecution(context) {
494
- const name = requireAddKindName(context, "`wp-typia add editor-plugin` requires <name>. Usage: wp-typia add editor-plugin <name> [--slot <sidebar|document-setting-panel>].");
502
+ const name = requireAddKindName(context, EDITOR_PLUGIN_MISSING_NAME_MESSAGE);
495
503
  const slot = readOptionalStrictStringFlag(context.flags, "slot");
496
504
  return createNamedExecutionPlan(context, {
497
505
  execute: ({ cwd, name: name2 }) => context.addRuntime.runAddEditorPluginCommand({
@@ -503,7 +511,7 @@ var editorPluginAddKindEntry = defineAddKindRegistryEntry({
503
511
  editorPluginSlug: result.editorPluginSlug,
504
512
  slot: result.slot
505
513
  }),
506
- missingNameMessage: "`wp-typia add editor-plugin` requires <name>. Usage: wp-typia add editor-plugin <name> [--slot <sidebar|document-setting-panel>].",
514
+ missingNameMessage: EDITOR_PLUGIN_MISSING_NAME_MESSAGE,
507
515
  name
508
516
  });
509
517
  },
@@ -514,6 +522,7 @@ var editorPluginAddKindEntry = defineAddKindRegistryEntry({
514
522
  });
515
523
 
516
524
  // src/add-kinds/hooked-block.ts
525
+ var HOOKED_BLOCK_MISSING_NAME_MESSAGE = "`wp-typia add hooked-block` requires <block-slug>. Usage: wp-typia add hooked-block <block-slug> --anchor <anchor-block-name> --position <before|after|firstChild|lastChild>.";
517
526
  var hookedBlockAddKindEntry = defineAddKindRegistryEntry({
518
527
  completion: {
519
528
  nextSteps: (values) => [
@@ -531,7 +540,7 @@ var hookedBlockAddKindEntry = defineAddKindRegistryEntry({
531
540
  description: "Add block.json hook metadata to an existing block",
532
541
  nameLabel: "Target block",
533
542
  async prepareExecution(context) {
534
- const name = requireAddKindName(context, "`wp-typia add hooked-block` requires <block-slug>. Usage: wp-typia add hooked-block <block-slug> --anchor <anchor-block-name> --position <before|after|firstChild|lastChild>.");
543
+ const name = requireAddKindName(context, HOOKED_BLOCK_MISSING_NAME_MESSAGE);
535
544
  const anchorBlockName = requireStrictStringFlag(context.flags, "anchor", "`wp-typia add hooked-block` requires --anchor <anchor-block-name>.");
536
545
  const position = requireStrictStringFlag(context.flags, "position", "`wp-typia add hooked-block` requires --position <before|after|firstChild|lastChild>.");
537
546
  return createNamedExecutionPlan(context, {
@@ -546,7 +555,7 @@ var hookedBlockAddKindEntry = defineAddKindRegistryEntry({
546
555
  blockSlug: result.blockSlug,
547
556
  position: result.position
548
557
  }),
549
- missingNameMessage: "`wp-typia add hooked-block` requires <block-slug>. Usage: wp-typia add hooked-block <block-slug> --anchor <anchor-block-name> --position <before|after|firstChild|lastChild>.",
558
+ missingNameMessage: HOOKED_BLOCK_MISSING_NAME_MESSAGE,
550
559
  name
551
560
  });
552
561
  },
@@ -557,6 +566,7 @@ var hookedBlockAddKindEntry = defineAddKindRegistryEntry({
557
566
  });
558
567
 
559
568
  // src/add-kinds/pattern.ts
569
+ var PATTERN_MISSING_NAME_MESSAGE = "`wp-typia add pattern` requires <name>. Usage: wp-typia add pattern <name>.";
560
570
  var patternAddKindEntry = defineAddKindRegistryEntry({
561
571
  completion: {
562
572
  nextSteps: (values) => [
@@ -580,7 +590,8 @@ var patternAddKindEntry = defineAddKindRegistryEntry({
580
590
  getValues: (result) => ({
581
591
  patternSlug: result.patternSlug
582
592
  }),
583
- missingNameMessage: "`wp-typia add pattern` requires <name>. Usage: wp-typia add pattern <name>."
593
+ missingNameMessage: PATTERN_MISSING_NAME_MESSAGE,
594
+ warnLine: context.warnLine
584
595
  });
585
596
  },
586
597
  sortOrder: 60,
@@ -590,6 +601,7 @@ var patternAddKindEntry = defineAddKindRegistryEntry({
590
601
  });
591
602
 
592
603
  // src/add-kinds/rest-resource.ts
604
+ var REST_RESOURCE_MISSING_NAME_MESSAGE = "`wp-typia add rest-resource` requires <name>. Usage: wp-typia add rest-resource <name> [--namespace <vendor/v1>] [--methods <list,read,create,update,delete>].";
593
605
  var restResourceAddKindEntry = defineAddKindRegistryEntry({
594
606
  completion: {
595
607
  nextSteps: (values) => [
@@ -607,7 +619,7 @@ var restResourceAddKindEntry = defineAddKindRegistryEntry({
607
619
  description: "Add a plugin-level typed REST resource",
608
620
  nameLabel: "REST resource name",
609
621
  async prepareExecution(context) {
610
- const name = requireAddKindName(context, "`wp-typia add rest-resource` requires <name>. Usage: wp-typia add rest-resource <name> [--namespace <vendor/v1>] [--methods <list,read,create,update,delete>].");
622
+ const name = requireAddKindName(context, REST_RESOURCE_MISSING_NAME_MESSAGE);
611
623
  const methods = readOptionalStrictStringFlag(context.flags, "methods");
612
624
  const namespace = readOptionalStrictStringFlag(context.flags, "namespace");
613
625
  return createNamedExecutionPlan(context, {
@@ -622,7 +634,7 @@ var restResourceAddKindEntry = defineAddKindRegistryEntry({
622
634
  namespace: result.namespace,
623
635
  restResourceSlug: result.restResourceSlug
624
636
  }),
625
- missingNameMessage: "`wp-typia add rest-resource` requires <name>. Usage: wp-typia add rest-resource <name> [--namespace <vendor/v1>] [--methods <list,read,create,update,delete>].",
637
+ missingNameMessage: REST_RESOURCE_MISSING_NAME_MESSAGE,
626
638
  name
627
639
  });
628
640
  },
@@ -633,6 +645,7 @@ var restResourceAddKindEntry = defineAddKindRegistryEntry({
633
645
  });
634
646
 
635
647
  // src/add-kinds/style.ts
648
+ var STYLE_MISSING_NAME_MESSAGE = "`wp-typia add style` requires <name>. Usage: wp-typia add style <name> --block <block-slug>.";
636
649
  var styleAddKindEntry = defineAddKindRegistryEntry({
637
650
  completion: {
638
651
  nextSteps: (values) => [
@@ -649,7 +662,7 @@ var styleAddKindEntry = defineAddKindRegistryEntry({
649
662
  description: "Add a Block Styles registration to an existing block",
650
663
  nameLabel: "Style name",
651
664
  async prepareExecution(context) {
652
- const name = requireAddKindName(context, "`wp-typia add style` requires <name>. Usage: wp-typia add style <name> --block <block-slug>.");
665
+ const name = requireAddKindName(context, STYLE_MISSING_NAME_MESSAGE);
653
666
  const blockSlug = requireStrictStringFlag(context.flags, "block", "`wp-typia add style` requires --block <block-slug>.");
654
667
  return createNamedExecutionPlan(context, {
655
668
  execute: ({ cwd, name: name2 }) => context.addRuntime.runAddBlockStyleCommand({
@@ -661,7 +674,7 @@ var styleAddKindEntry = defineAddKindRegistryEntry({
661
674
  blockSlug: result.blockSlug,
662
675
  styleSlug: result.styleSlug
663
676
  }),
664
- missingNameMessage: "`wp-typia add style` requires <name>. Usage: wp-typia add style <name> --block <block-slug>.",
677
+ missingNameMessage: STYLE_MISSING_NAME_MESSAGE,
665
678
  name
666
679
  });
667
680
  },
@@ -672,6 +685,7 @@ var styleAddKindEntry = defineAddKindRegistryEntry({
672
685
  });
673
686
 
674
687
  // src/add-kinds/transform.ts
688
+ var TRANSFORM_MISSING_NAME_MESSAGE = "`wp-typia add transform` requires <name>. Usage: wp-typia add transform <name> --from <namespace/block> --to <block-slug|namespace/block-slug>.";
675
689
  var transformAddKindEntry = defineAddKindRegistryEntry({
676
690
  completion: {
677
691
  nextSteps: (values) => [
@@ -689,7 +703,7 @@ var transformAddKindEntry = defineAddKindRegistryEntry({
689
703
  description: "Add a block-to-block transform into a workspace block",
690
704
  nameLabel: "Transform name",
691
705
  async prepareExecution(context) {
692
- const name = requireAddKindName(context, "`wp-typia add transform` requires <name>. Usage: wp-typia add transform <name> --from <namespace/block> --to <block-slug|namespace/block-slug>.");
706
+ const name = requireAddKindName(context, TRANSFORM_MISSING_NAME_MESSAGE);
693
707
  const fromBlockName = requireStrictStringFlag(context.flags, "from", "`wp-typia add transform` requires --from <namespace/block>.");
694
708
  const toBlockName = requireStrictStringFlag(context.flags, "to", "`wp-typia add transform` requires --to <block-slug|namespace/block-slug>.");
695
709
  return createNamedExecutionPlan(context, {
@@ -705,7 +719,7 @@ var transformAddKindEntry = defineAddKindRegistryEntry({
705
719
  toBlockName: result.toBlockName,
706
720
  transformSlug: result.transformSlug
707
721
  }),
708
- missingNameMessage: "`wp-typia add transform` requires <name>. Usage: wp-typia add transform <name> --from <namespace/block> --to <block-slug|namespace/block-slug>.",
722
+ missingNameMessage: TRANSFORM_MISSING_NAME_MESSAGE,
709
723
  name
710
724
  });
711
725
  },
@@ -716,6 +730,7 @@ var transformAddKindEntry = defineAddKindRegistryEntry({
716
730
  });
717
731
 
718
732
  // src/add-kinds/variation.ts
733
+ var VARIATION_MISSING_NAME_MESSAGE = "`wp-typia add variation` requires <name>. Usage: wp-typia add variation <name> --block <block-slug>";
719
734
  var variationAddKindEntry = defineAddKindRegistryEntry({
720
735
  completion: {
721
736
  nextSteps: (values) => [
@@ -732,7 +747,7 @@ var variationAddKindEntry = defineAddKindRegistryEntry({
732
747
  description: "Add a variation to an existing block",
733
748
  nameLabel: "Variation name",
734
749
  async prepareExecution(context) {
735
- const name = requireAddKindName(context, "`wp-typia add variation` requires <name>. Usage: wp-typia add variation <name> --block <block-slug>");
750
+ const name = requireAddKindName(context, VARIATION_MISSING_NAME_MESSAGE);
736
751
  const blockSlug = requireStrictStringFlag(context.flags, "block", "`wp-typia add variation` requires --block <block-slug>.");
737
752
  return createNamedExecutionPlan(context, {
738
753
  execute: ({ cwd, name: name2 }) => context.addRuntime.runAddVariationCommand({
@@ -744,7 +759,7 @@ var variationAddKindEntry = defineAddKindRegistryEntry({
744
759
  blockSlug: result.blockSlug,
745
760
  variationSlug: result.variationSlug
746
761
  }),
747
- missingNameMessage: "`wp-typia add variation` requires <name>. Usage: wp-typia add variation <name> --block <block-slug>",
762
+ missingNameMessage: VARIATION_MISSING_NAME_MESSAGE,
748
763
  name
749
764
  });
750
765
  },
@@ -783,12 +798,6 @@ function buildAddKindCompletionDetails(kind, options) {
783
798
  title: descriptor.title
784
799
  };
785
800
  }
786
- function formatAddKindList() {
787
- return ADD_KIND_IDS.join(", ");
788
- }
789
- function formatAddKindUsagePlaceholder() {
790
- return `<${ADD_KIND_IDS.join("|")}>`;
791
- }
792
801
  function supportsAddKindDryRun(kind) {
793
802
  return ADD_KIND_REGISTRY[kind].supportsDryRun;
794
803
  }
@@ -835,6 +844,55 @@ async function copyWorkspaceProject(sourceDir, targetDir) {
835
844
  recursive: true
836
845
  });
837
846
  }
847
+ function formatInstallMarkerError(error) {
848
+ if (error instanceof Error) {
849
+ return error.message;
850
+ }
851
+ return String(error);
852
+ }
853
+ function formatInstallMarkerFailures(failures) {
854
+ return failures.map((failure) => `${failure.operation}: ${failure.reason}`).join("; ");
855
+ }
856
+ function ensureWorkspaceInstallMarker({
857
+ fsAdapter = fs2,
858
+ sourceMarker,
859
+ targetMarker
860
+ }) {
861
+ const failures = [];
862
+ try {
863
+ fsAdapter.symlinkSync(sourceMarker, targetMarker);
864
+ return;
865
+ } catch (error) {
866
+ failures.push({
867
+ operation: "symlink",
868
+ reason: formatInstallMarkerError(error)
869
+ });
870
+ }
871
+ try {
872
+ fsAdapter.linkSync(sourceMarker, targetMarker);
873
+ return;
874
+ } catch (error) {
875
+ failures.push({
876
+ operation: "hard link",
877
+ reason: formatInstallMarkerError(error)
878
+ });
879
+ }
880
+ try {
881
+ fsAdapter.copyFileSync(sourceMarker, targetMarker);
882
+ return;
883
+ } catch (error) {
884
+ failures.push({
885
+ operation: "copy",
886
+ reason: formatInstallMarkerError(error)
887
+ });
888
+ }
889
+ throw new Error([
890
+ "Failed to prepare dry-run install marker.",
891
+ `Source: ${sourceMarker}`,
892
+ `Target: ${targetMarker}`,
893
+ `Fallback failures: ${formatInstallMarkerFailures(failures)}`
894
+ ].join(" "));
895
+ }
838
896
  function ensureWorkspaceInstallMarkers(sourceDir, targetDir) {
839
897
  const sourceNodeModules = path.join(sourceDir, "node_modules");
840
898
  if (fs2.existsSync(sourceNodeModules)) {
@@ -846,15 +904,7 @@ function ensureWorkspaceInstallMarkers(sourceDir, targetDir) {
846
904
  continue;
847
905
  }
848
906
  const targetMarker = path.join(targetDir, marker);
849
- try {
850
- fs2.symlinkSync(sourceMarker, targetMarker);
851
- } catch {
852
- try {
853
- fs2.linkSync(sourceMarker, targetMarker);
854
- } catch {
855
- fs2.copyFileSync(sourceMarker, targetMarker);
856
- }
857
- }
907
+ ensureWorkspaceInstallMarker({ sourceMarker, targetMarker });
858
908
  }
859
909
  }
860
910
  async function listWorkspaceFiles(rootDir) {
@@ -1015,47 +1065,38 @@ function stripLeadingOutputMarker(text, kind) {
1015
1065
  return text.replace(new RegExp(`^(?:${markerPattern})\\s*`, "u"), "");
1016
1066
  }
1017
1067
 
1018
- // src/print-block.ts
1019
- function printBlock(printLine, lines) {
1020
- for (const line of lines) {
1021
- printLine(line);
1022
- }
1068
+ // src/runtime-output/init.ts
1069
+ function buildInitCompletionPayload(plan, markerOptions) {
1070
+ const changeLines = [
1071
+ ...plan.packageChanges.addDevDependencies.map((dependency) => `devDependency ${dependency.action} ${dependency.name} -> ${dependency.requiredValue}`),
1072
+ ...plan.packageChanges.packageManagerField ? [
1073
+ `packageManager ${plan.packageChanges.packageManagerField.action} -> ${plan.packageChanges.packageManagerField.requiredValue}`
1074
+ ] : [],
1075
+ ...plan.packageChanges.scripts.map((script) => `script ${script.action} ${script.name} -> ${script.requiredValue}`),
1076
+ ...plan.plannedFiles.map((filePlan) => `file ${filePlan.action} ${filePlan.path} (${filePlan.purpose})`),
1077
+ ...plan.commandMode === "preview-only" ? plan.generatedArtifacts.map((artifactPath) => `generated artifact ${artifactPath}`) : []
1078
+ ];
1079
+ const modeLine = plan.commandMode === "apply" ? plan.status === "already-initialized" ? "Mode: apply requested; no files were written because the retrofit surface already existed." : "Mode: apply; package.json and retrofit helper files were written." : "Mode: preview only; no files were written.";
1080
+ const optionalTitle = plan.commandMode === "apply" ? `Applied adoption changes (${changeLines.length}):` : `Planned adoption changes (${changeLines.length}):`;
1081
+ const title = plan.status === "already-initialized" ? formatOutputMarker("success", `wp-typia init: ${plan.projectName} is already initialized`, markerOptions) : plan.commandMode === "apply" ? formatOutputMarker("success", `Applied retrofit init for ${plan.projectName}`, markerOptions) : formatOutputMarker("dryRun", `Retrofit init plan for ${plan.projectName}`, markerOptions);
1082
+ return {
1083
+ nextSteps: plan.nextSteps,
1084
+ optionalLines: changeLines,
1085
+ optionalNote: plan.summary,
1086
+ optionalTitle,
1087
+ summaryLines: [
1088
+ `Project directory: ${plan.projectDir}`,
1089
+ `Detected layout: ${plan.detectedLayout.description}`,
1090
+ ...plan.detectedLayout.blockNames.length > 0 ? [`Block targets: ${plan.detectedLayout.blockNames.join(", ")}`] : [],
1091
+ `Package manager: ${plan.packageManager}`,
1092
+ modeLine
1093
+ ],
1094
+ title,
1095
+ warningLines: plan.notes
1096
+ };
1023
1097
  }
1024
1098
 
1025
- // src/runtime-bridge-output.ts
1026
- function printCompletionPayload(payload, options = {}) {
1027
- const printLine = options.printLine ?? console.log;
1028
- const warnLine = options.warnLine ?? printLine;
1029
- for (const line of payload.preambleLines ?? []) {
1030
- printLine(line);
1031
- }
1032
- for (const warning of payload.warningLines ?? []) {
1033
- warnLine(formatOutputMarker("warning", warning, options.markerOptions));
1034
- }
1035
- const hasDetails = (payload.summaryLines?.length ?? 0) > 0 || (payload.nextSteps?.length ?? 0) > 0 || (payload.optionalLines?.length ?? 0) > 0 || Boolean(payload.optionalNote);
1036
- const hasLeadingContext = (payload.preambleLines?.length ?? 0) > 0 || (payload.warningLines?.length ?? 0) > 0;
1037
- printLine(hasLeadingContext && hasDetails ? `
1038
- ${payload.title}` : payload.title);
1039
- for (const line of payload.summaryLines ?? []) {
1040
- printLine(line);
1041
- }
1042
- if ((payload.nextSteps?.length ?? 0) > 0) {
1043
- printLine("Next steps:");
1044
- for (const step of payload.nextSteps ?? []) {
1045
- printLine(` ${step}`);
1046
- }
1047
- }
1048
- if ((payload.optionalLines?.length ?? 0) > 0) {
1049
- printLine(`
1050
- ${payload.optionalTitle ?? "Optional:"}`);
1051
- for (const step of payload.optionalLines ?? []) {
1052
- printLine(` ${step}`);
1053
- }
1054
- }
1055
- if (payload.optionalNote) {
1056
- printLine(`Note: ${payload.optionalNote}`);
1057
- }
1058
- }
1099
+ // src/runtime-output/structured.ts
1059
1100
  function toNonEmptyArray(values) {
1060
1101
  return values && values.length > 0 ? values : undefined;
1061
1102
  }
@@ -1064,13 +1105,6 @@ function extractPlannedFiles(payload) {
1064
1105
  return toNonEmptyArray(files);
1065
1106
  }
1066
1107
  var PROJECT_DIRECTORY_SUMMARY_PREFIX = "Project directory: ";
1067
- function resolveCreateCompletionPackageManager(packageManager) {
1068
- const parsedPackageManager = parsePackageManagerField(packageManager);
1069
- if (parsedPackageManager) {
1070
- return parsedPackageManager;
1071
- }
1072
- throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, `Unsupported package manager "${packageManager}" in create completion payload. Expected one of: ${PACKAGE_MANAGER_IDS.join(", ")}.`);
1073
- }
1074
1108
  function extractCompletionProjectDir(completion) {
1075
1109
  const projectDir = completion?.summaryLines?.find((line) => line.startsWith(PROJECT_DIRECTORY_SUMMARY_PREFIX))?.slice(PROJECT_DIRECTORY_SUMMARY_PREFIX.length).trim();
1076
1110
  return projectDir && projectDir.length > 0 ? projectDir : undefined;
@@ -1123,6 +1157,28 @@ function buildStructuredInitSuccessPayload(plan) {
1123
1157
  }
1124
1158
  };
1125
1159
  }
1160
+ // src/runtime-output/create.ts
1161
+ function escapeRegExp2(source) {
1162
+ return source.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
1163
+ }
1164
+ var LOOSE_CREATE_COMPLETION_PACKAGE_MANAGER_PATTERN = new RegExp(`^(?:corepack\\s+)?(${PACKAGE_MANAGER_IDS.map(escapeRegExp2).join("|")})(?=$|[@:/+\\s])`, "iu");
1165
+ function parseCreateCompletionPackageManager(packageManager) {
1166
+ const normalizedPackageManager = packageManager.trim();
1167
+ const parsedPackageManager = parsePackageManagerField(normalizedPackageManager);
1168
+ if (parsedPackageManager) {
1169
+ return parsedPackageManager;
1170
+ }
1171
+ const looseMatch = LOOSE_CREATE_COMPLETION_PACKAGE_MANAGER_PATTERN.exec(normalizedPackageManager);
1172
+ const loosePackageManager = looseMatch?.[1]?.toLowerCase();
1173
+ return PACKAGE_MANAGER_IDS.includes(loosePackageManager) ? loosePackageManager : null;
1174
+ }
1175
+ function resolveCreateCompletionPackageManager(packageManager) {
1176
+ const parsedPackageManager = parseCreateCompletionPackageManager(packageManager);
1177
+ if (parsedPackageManager) {
1178
+ return parsedPackageManager;
1179
+ }
1180
+ throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, `Unsupported package manager "${packageManager}" in create completion payload. Expected one of: ${PACKAGE_MANAGER_IDS.join(", ")}.`);
1181
+ }
1126
1182
  function formatCreateProgressLine(payload, markerOptions) {
1127
1183
  return formatOutputMarker("progress", `${payload.title}: ${payload.detail}`, markerOptions);
1128
1184
  }
@@ -1168,42 +1224,7 @@ function buildCreateDryRunPayload(flow, markerOptions) {
1168
1224
  warningLines: flow.result.warnings
1169
1225
  };
1170
1226
  }
1171
- function buildInitCompletionPayload(plan, markerOptions) {
1172
- const changeLines = [
1173
- ...plan.packageChanges.addDevDependencies.map((dependency) => `devDependency ${dependency.action} ${dependency.name} -> ${dependency.requiredValue}`),
1174
- ...plan.packageChanges.packageManagerField ? [
1175
- `packageManager ${plan.packageChanges.packageManagerField.action} -> ${plan.packageChanges.packageManagerField.requiredValue}`
1176
- ] : [],
1177
- ...plan.packageChanges.scripts.map((script) => `script ${script.action} ${script.name} -> ${script.requiredValue}`),
1178
- ...plan.plannedFiles.map((filePlan) => `file ${filePlan.action} ${filePlan.path} (${filePlan.purpose})`),
1179
- ...plan.commandMode === "preview-only" ? plan.generatedArtifacts.map((artifactPath) => `generated artifact ${artifactPath}`) : []
1180
- ];
1181
- const modeLine = plan.commandMode === "apply" ? plan.status === "already-initialized" ? "Mode: apply requested; no files were written because the retrofit surface already existed." : "Mode: apply; package.json and retrofit helper files were written." : "Mode: preview only; no files were written.";
1182
- const optionalTitle = plan.commandMode === "apply" ? `Applied adoption changes (${changeLines.length}):` : `Planned adoption changes (${changeLines.length}):`;
1183
- const title = plan.status === "already-initialized" ? formatOutputMarker("success", `wp-typia init: ${plan.projectName} is already initialized`, markerOptions) : plan.commandMode === "apply" ? formatOutputMarker("success", `Applied retrofit init for ${plan.projectName}`, markerOptions) : formatOutputMarker("dryRun", `Retrofit init plan for ${plan.projectName}`, markerOptions);
1184
- return {
1185
- nextSteps: plan.nextSteps,
1186
- optionalLines: changeLines,
1187
- optionalNote: plan.summary,
1188
- optionalTitle,
1189
- summaryLines: [
1190
- `Project directory: ${plan.projectDir}`,
1191
- `Detected layout: ${plan.detectedLayout.description}`,
1192
- ...plan.detectedLayout.blockNames.length > 0 ? [`Block targets: ${plan.detectedLayout.blockNames.join(", ")}`] : [],
1193
- `Package manager: ${plan.packageManager}`,
1194
- modeLine
1195
- ],
1196
- title,
1197
- warningLines: plan.notes
1198
- };
1199
- }
1200
- function buildMigrationCompletionPayload(options, markerOptions) {
1201
- const summaryLines = options.lines.filter((line) => line.trim().length > 0);
1202
- return {
1203
- summaryLines,
1204
- title: formatOutputMarker("success", `Completed wp-typia migrate ${options.command}`, markerOptions)
1205
- };
1206
- }
1227
+ // src/runtime-output/add.ts
1207
1228
  function buildAddCompletionPayload(options, markerOptions) {
1208
1229
  const verificationLines = [
1209
1230
  formatPackageExecCommand(options.packageManager ?? inferPackageManagerId(options.projectDir), `wp-typia@${package_default.version}`, "doctor")
@@ -1235,6 +1256,15 @@ function buildAddDryRunPayload(options, markerOptions) {
1235
1256
  warningLines: options.completion.warningLines
1236
1257
  };
1237
1258
  }
1259
+ // src/runtime-output/migrate.ts
1260
+ function buildMigrationCompletionPayload(options, markerOptions) {
1261
+ const summaryLines = options.lines.filter((line) => line.trim().length > 0);
1262
+ return {
1263
+ summaryLines,
1264
+ title: formatOutputMarker("success", `Completed wp-typia migrate ${options.command}`, markerOptions)
1265
+ };
1266
+ }
1267
+ // src/runtime-output/sync.ts
1238
1268
  function buildSyncDryRunPayload(options, markerOptions) {
1239
1269
  const targetSuffix = options.target === "ai" ? " ai" : "";
1240
1270
  const targetSummary = options.target === "ai" ? "Sync target: AI artifacts only." : options.target === "default" ? "Sync target: generated project defaults." : undefined;
@@ -1251,7 +1281,47 @@ function buildSyncDryRunPayload(options, markerOptions) {
1251
1281
  title: formatOutputMarker("dryRun", `Dry run for wp-typia sync${targetSuffix}`, markerOptions)
1252
1282
  };
1253
1283
  }
1284
+ // src/print-block.ts
1285
+ function printBlock(printLine, lines) {
1286
+ for (const line of lines) {
1287
+ printLine(line);
1288
+ }
1289
+ }
1254
1290
 
1291
+ // src/runtime-output/print.ts
1292
+ function printCompletionPayload(payload, options = {}) {
1293
+ const printLine = options.printLine ?? console.log;
1294
+ const warnLine = options.warnLine ?? printLine;
1295
+ for (const line of payload.preambleLines ?? []) {
1296
+ printLine(line);
1297
+ }
1298
+ for (const warning of payload.warningLines ?? []) {
1299
+ warnLine(formatOutputMarker("warning", warning, options.markerOptions));
1300
+ }
1301
+ const hasDetails = (payload.summaryLines?.length ?? 0) > 0 || (payload.nextSteps?.length ?? 0) > 0 || (payload.optionalLines?.length ?? 0) > 0 || Boolean(payload.optionalNote);
1302
+ const hasLeadingContext = (payload.preambleLines?.length ?? 0) > 0 || (payload.warningLines?.length ?? 0) > 0;
1303
+ printLine(hasLeadingContext && hasDetails ? `
1304
+ ${payload.title}` : payload.title);
1305
+ for (const line of payload.summaryLines ?? []) {
1306
+ printLine(line);
1307
+ }
1308
+ if ((payload.nextSteps?.length ?? 0) > 0) {
1309
+ printLine("Next steps:");
1310
+ for (const step of payload.nextSteps ?? []) {
1311
+ printLine(` ${step}`);
1312
+ }
1313
+ }
1314
+ if ((payload.optionalLines?.length ?? 0) > 0) {
1315
+ printLine(`
1316
+ ${payload.optionalTitle ?? "Optional:"}`);
1317
+ for (const step of payload.optionalLines ?? []) {
1318
+ printLine(` ${step}`);
1319
+ }
1320
+ }
1321
+ if (payload.optionalNote) {
1322
+ printLine(`Note: ${payload.optionalNote}`);
1323
+ }
1324
+ }
1255
1325
  // src/runtime-capabilities.ts
1256
1326
  function isInteractiveTerminal({
1257
1327
  stdin = process.stdin,
@@ -1264,230 +1334,34 @@ function supportsInteractiveTui(options = {}) {
1264
1334
  const hasBunRuntime = options.hasBunRuntime ?? typeof Bun !== "undefined";
1265
1335
  return hasBunRuntime && isInteractiveTerminal(options);
1266
1336
  }
1267
- // src/runtime-bridge-sync.ts
1268
- import { spawnSync } from "child_process";
1269
- import fs3 from "fs";
1270
- import path2 from "path";
1271
- var SYNC_INSTALL_MARKERS = [
1272
- "node_modules",
1273
- ".pnp.cjs",
1274
- ".pnp.loader.mjs"
1275
- ];
1276
- var LOCAL_SYNC_TOOL_PATTERN = /(^|[\s;&|()])(?:tsx|wp-scripts)(?=($|[\s;&|()]))/u;
1277
- var CAPTURED_SYNC_OUTPUT_MAX_BUFFER = 16 * 1024 * 1024;
1278
- function resolveSyncExecutionTarget(subcommand) {
1279
- if (!subcommand) {
1280
- return "default";
1337
+
1338
+ // src/runtime-bridge-shared.ts
1339
+ var loadCliDiagnosticsRuntime = () => import("./cli-diagnostics-5dvztm7q.js");
1340
+ async function wrapCliCommandError(command, error) {
1341
+ const { createCliCommandError } = await loadCliDiagnosticsRuntime();
1342
+ return createCliCommandError({ command, error });
1343
+ }
1344
+ function shouldWrapCliCommandError(options) {
1345
+ if (options.emitOutput === false) {
1346
+ return false;
1281
1347
  }
1282
- if (subcommand === "ai") {
1283
- return "ai";
1348
+ if (options.renderLine) {
1349
+ return false;
1284
1350
  }
1285
- throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_COMMAND, `Unknown sync subcommand "${subcommand}". Expected one of: "ai".`);
1351
+ return true;
1286
1352
  }
1287
- function getSyncRootError(cwd) {
1288
- return createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.OUTSIDE_PROJECT_ROOT, `No generated wp-typia project root was found at ${cwd}. Run \`wp-typia sync\` from a scaffolded project or official workspace root that already contains generated sync scripts. If you expected this directory to work, cd into the scaffold root first or rerun the scaffold before syncing.`);
1353
+ function emitCompletion(payload, options) {
1354
+ if (options.emitOutput) {
1355
+ printCompletionPayload(payload, {
1356
+ printLine: options.printLine,
1357
+ warnLine: options.warnLine
1358
+ });
1359
+ }
1360
+ return payload;
1289
1361
  }
1290
- function resolveSyncProjectContext(cwd) {
1291
- const packageJsonPath = path2.join(cwd, "package.json");
1292
- if (!fs3.existsSync(packageJsonPath)) {
1293
- throw getSyncRootError(cwd);
1294
- }
1295
- const packageJson = JSON.parse(fs3.readFileSync(packageJsonPath, "utf8"));
1296
- const scripts = packageJson.scripts ?? {};
1297
- const syncScripts = {
1298
- sync: typeof scripts.sync === "string" ? {
1299
- command: scripts.sync,
1300
- scriptName: "sync"
1301
- } : undefined,
1302
- "sync-ai": typeof scripts["sync-ai"] === "string" ? {
1303
- command: scripts["sync-ai"],
1304
- scriptName: "sync-ai"
1305
- } : typeof scripts["sync-wordpress-ai"] === "string" ? {
1306
- command: scripts["sync-wordpress-ai"],
1307
- scriptName: "sync-wordpress-ai"
1308
- } : undefined,
1309
- "sync-rest": typeof scripts["sync-rest"] === "string" ? {
1310
- command: scripts["sync-rest"],
1311
- scriptName: "sync-rest"
1312
- } : undefined,
1313
- "sync-types": typeof scripts["sync-types"] === "string" ? {
1314
- command: scripts["sync-types"],
1315
- scriptName: "sync-types"
1316
- } : undefined
1317
- };
1318
- return {
1319
- cwd,
1320
- packageJsonPath,
1321
- packageManager: inferPackageManagerId(cwd, packageJson.packageManager),
1322
- scripts: syncScripts
1323
- };
1324
- }
1325
- function findInstalledDependencyMarkerDir(projectDir) {
1326
- let currentDir = path2.resolve(projectDir);
1327
- while (true) {
1328
- if (SYNC_INSTALL_MARKERS.some((marker) => fs3.existsSync(path2.join(currentDir, marker)))) {
1329
- return currentDir;
1330
- }
1331
- const parentDir = path2.dirname(currentDir);
1332
- if (parentDir === currentDir) {
1333
- return null;
1334
- }
1335
- currentDir = parentDir;
1336
- }
1337
- }
1338
- function scriptsLikelyNeedInstalledDependencies(project, target) {
1339
- const candidateScripts = target === "ai" ? [project.scripts["sync-ai"]] : project.scripts.sync ? [project.scripts.sync] : [
1340
- project.scripts["sync-types"],
1341
- project.scripts["sync-rest"],
1342
- project.scripts["sync-ai"]
1343
- ];
1344
- return candidateScripts.some((script) => script !== undefined && LOCAL_SYNC_TOOL_PATTERN.test(script.command));
1345
- }
1346
- function assertSyncDependenciesInstalled(project, target) {
1347
- if (!scriptsLikelyNeedInstalledDependencies(project, target)) {
1348
- return;
1349
- }
1350
- const markerDir = findInstalledDependencyMarkerDir(project.cwd);
1351
- if (markerDir) {
1352
- return;
1353
- }
1354
- throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.DEPENDENCIES_NOT_INSTALLED, `Project dependencies have not been installed yet. Run \`${formatInstallCommand(project.packageManager)}\` from the project root before \`wp-typia sync\`. The generated sync scripts rely on local tools such as \`tsx\`.`);
1355
- }
1356
- function getPackageManagerRunInvocation(packageManager, scriptName, extraArgs) {
1357
- switch (packageManager) {
1358
- case "bun":
1359
- return { args: ["run", scriptName, ...extraArgs], command: "bun" };
1360
- case "npm":
1361
- return {
1362
- args: [
1363
- "run",
1364
- scriptName,
1365
- ...extraArgs.length > 0 ? ["--", ...extraArgs] : []
1366
- ],
1367
- command: "npm"
1368
- };
1369
- case "pnpm":
1370
- return { args: ["run", scriptName, ...extraArgs], command: "pnpm" };
1371
- case "yarn":
1372
- return { args: ["run", scriptName, ...extraArgs], command: "yarn" };
1373
- }
1374
- }
1375
- function createSyncPlannedCommand(project, scriptName, extraArgs) {
1376
- const script = project.scripts[scriptName];
1377
- if (!script) {
1378
- return null;
1379
- }
1380
- const invocation = getPackageManagerRunInvocation(project.packageManager, script.scriptName, extraArgs);
1381
- return {
1382
- args: invocation.args,
1383
- command: invocation.command,
1384
- displayCommand: formatRunScript(project.packageManager, script.scriptName, extraArgs.join(" ")),
1385
- scriptName: script.scriptName
1386
- };
1387
- }
1388
- function buildSyncPlannedCommands(project, extraArgs, target) {
1389
- if (target === "ai") {
1390
- const syncAiCommand2 = createSyncPlannedCommand(project, "sync-ai", extraArgs);
1391
- if (!syncAiCommand2) {
1392
- throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.CONFIGURATION_MISSING, `Expected ${project.packageJsonPath} to define a \`sync-ai\` script for \`wp-typia sync ai\`.`);
1393
- }
1394
- return [syncAiCommand2];
1395
- }
1396
- if (project.scripts.sync) {
1397
- return [createSyncPlannedCommand(project, "sync", extraArgs)];
1398
- }
1399
- const syncTypesCommand = createSyncPlannedCommand(project, "sync-types", extraArgs);
1400
- if (!syncTypesCommand) {
1401
- throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.CONFIGURATION_MISSING, `Expected ${project.packageJsonPath} to define either a \`sync\` or \`sync-types\` script.`);
1402
- }
1403
- const plannedCommands = [syncTypesCommand];
1404
- const syncRestCommand = createSyncPlannedCommand(project, "sync-rest", extraArgs);
1405
- if (syncRestCommand) {
1406
- plannedCommands.push(syncRestCommand);
1407
- }
1408
- const syncAiCommand = createSyncPlannedCommand(project, "sync-ai", extraArgs);
1409
- if (syncAiCommand) {
1410
- plannedCommands.push(syncAiCommand);
1411
- }
1412
- return plannedCommands;
1413
- }
1414
- function runProjectScript(project, plannedCommand, options) {
1415
- const result = spawnSync(plannedCommand.command, plannedCommand.args, {
1416
- cwd: project.cwd,
1417
- encoding: options.captureOutput ? "utf8" : undefined,
1418
- ...options.captureOutput ? { maxBuffer: CAPTURED_SYNC_OUTPUT_MAX_BUFFER } : {},
1419
- shell: process.platform === "win32",
1420
- stdio: options.captureOutput ? "pipe" : "inherit"
1421
- });
1422
- const stderr = options.captureOutput && typeof result.stderr === "string" ? result.stderr : undefined;
1423
- const stdout = options.captureOutput && typeof result.stdout === "string" ? result.stdout : undefined;
1424
- if (result.error || result.status !== 0) {
1425
- throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.COMMAND_EXECUTION, `\`${plannedCommand.displayCommand}\` failed.`, {
1426
- cause: result.error ?? (stderr ? new Error(stderr.trim()) : undefined)
1427
- });
1428
- }
1429
- return {
1430
- ...plannedCommand,
1431
- exitCode: result.status ?? 0,
1432
- ...stderr !== undefined ? { stderr } : {},
1433
- ...stdout !== undefined ? { stdout } : {}
1434
- };
1435
- }
1436
- async function executeSyncCommand({
1437
- captureOutput = false,
1438
- check = false,
1439
- cwd,
1440
- dryRun = false,
1441
- target = "default"
1442
- }) {
1443
- const project = resolveSyncProjectContext(cwd);
1444
- const extraArgs = check ? ["--check"] : [];
1445
- const plannedCommands = buildSyncPlannedCommands(project, extraArgs, target);
1446
- const result = {
1447
- check,
1448
- dryRun,
1449
- packageJsonPath: project.packageJsonPath,
1450
- packageManager: project.packageManager,
1451
- plannedCommands,
1452
- projectDir: project.cwd,
1453
- target
1454
- };
1455
- if (dryRun) {
1456
- return result;
1457
- }
1458
- assertSyncDependenciesInstalled(project, target);
1459
- result.executedCommands = plannedCommands.map((plannedCommand) => runProjectScript(project, plannedCommand, {
1460
- captureOutput
1461
- }));
1462
- return result;
1463
- }
1464
-
1465
- // src/runtime-bridge.ts
1466
- var loadCliAddRuntime = () => import("./cli-add-6dn9h94t.js");
1467
- var loadCliDiagnosticsRuntime = () => import("./cli-diagnostics-5dvztm7q.js");
1468
- var loadCliDoctorRuntime = () => import("./cli-doctor-564c43ay.js");
1469
- var loadCliInitRuntime = () => import("./cli-init-znhqp8tr.js");
1470
- var loadCliPromptRuntime = () => import("./cli-prompt-614tq57c.js");
1471
- var loadCliScaffoldRuntime = () => import("./cli-scaffold-6trxyyk6.js");
1472
- var loadCliTemplatesRuntime = () => import("./cli-templates-hc71dfc2.js");
1473
- var loadCreateTemplateValidationRuntime = () => import("./create-template-validation-rtec5sng.js");
1474
- var loadMigrationsRuntime = () => import("./migrations-qc1r0yqe.js");
1475
- async function wrapCliCommandError(command, error) {
1476
- const { createCliCommandError } = await loadCliDiagnosticsRuntime();
1477
- return createCliCommandError({ command, error });
1478
- }
1479
- function shouldWrapCliCommandError(options) {
1480
- if (options.emitOutput === false) {
1481
- return false;
1482
- }
1483
- if (options.renderLine) {
1484
- return false;
1485
- }
1486
- return true;
1487
- }
1488
- function pushFlag(argv, name, value) {
1489
- if (value === undefined || value === null || value === false) {
1490
- return;
1362
+ function pushFlag(argv, name, value) {
1363
+ if (value === undefined || value === null || value === false) {
1364
+ return;
1491
1365
  }
1492
1366
  if (value === true) {
1493
1367
  argv.push(`--${name}`);
@@ -1495,6 +1369,10 @@ function pushFlag(argv, name, value) {
1495
1369
  }
1496
1370
  argv.push(`--${name}`, String(value));
1497
1371
  }
1372
+
1373
+ // src/runtime-bridge-add.ts
1374
+ var loadCliAddRuntime = () => import("./cli-add-8rvmezy0.js");
1375
+ var loadCliPromptRuntime = () => import("./cli-prompt-614tq57c.js");
1498
1376
  async function executeWorkspaceAddWithOptionalDryRun(options) {
1499
1377
  const simulated = options.dryRun ? await simulateWorkspaceAddDryRun({
1500
1378
  cwd: options.cwd,
@@ -1538,6 +1416,72 @@ async function executePlannedAddKind(kind, executionContext, context) {
1538
1416
  const plan = await getAddKindExecutionPlan(kind, executionContext);
1539
1417
  return executePreparedAddKind(kind, context, plan);
1540
1418
  }
1419
+ async function executeAddCommand({
1420
+ cwd,
1421
+ emitOutput = true,
1422
+ flags,
1423
+ interactive,
1424
+ kind,
1425
+ name,
1426
+ printLine = console.log,
1427
+ prompt,
1428
+ warnLine = console.warn
1429
+ }) {
1430
+ let activePrompt;
1431
+ const dryRun = Boolean(flags["dry-run"]);
1432
+ try {
1433
+ const addRuntime = await loadCliAddRuntime();
1434
+ const isInteractiveSession = interactive ?? isInteractiveTerminal();
1435
+ if (!kind) {
1436
+ if (shouldPrintMissingAddKindHelp({ emitOutput })) {
1437
+ printLine(addRuntime.formatAddHelpText());
1438
+ }
1439
+ throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.MISSING_ARGUMENT, formatMissingAddKindDetailLine());
1440
+ }
1441
+ if (!isAddKindId(kind)) {
1442
+ throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_COMMAND, `Unknown add kind "${kind}". Expected one of: ${formatAddKindList()}.`);
1443
+ }
1444
+ if (dryRun && !supportsAddKindDryRun(kind)) {
1445
+ throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, `\`wp-typia add ${kind}\` does not support \`--dry-run\` yet.`);
1446
+ }
1447
+ const executionContext = {
1448
+ addRuntime,
1449
+ cwd,
1450
+ flags,
1451
+ getOrCreatePrompt: async () => {
1452
+ if (activePrompt) {
1453
+ return activePrompt;
1454
+ }
1455
+ const { createReadlinePrompt } = await loadCliPromptRuntime();
1456
+ activePrompt = prompt ?? createReadlinePrompt();
1457
+ return activePrompt;
1458
+ },
1459
+ isInteractiveSession,
1460
+ name,
1461
+ warnLine
1462
+ };
1463
+ return await executePlannedAddKind(kind, executionContext, {
1464
+ cwd,
1465
+ dryRun,
1466
+ emitOutput,
1467
+ printLine
1468
+ });
1469
+ } catch (error) {
1470
+ if (!shouldWrapCliCommandError({ emitOutput })) {
1471
+ throw error;
1472
+ }
1473
+ throw await wrapCliCommandError("add", error);
1474
+ } finally {
1475
+ if (activePrompt && activePrompt !== prompt) {
1476
+ activePrompt.close();
1477
+ }
1478
+ }
1479
+ }
1480
+ // src/runtime-bridge-create.ts
1481
+ var loadCliPromptRuntime2 = () => import("./cli-prompt-614tq57c.js");
1482
+ var loadCliScaffoldRuntime = () => import("./cli-scaffold-b1ex2y80.js");
1483
+ var loadCliTemplatesRuntime = () => import("./cli-templates-hc71dfc2.js");
1484
+ var loadCreateTemplateValidationRuntime = () => import("./create-template-validation-rtec5sng.js");
1541
1485
  var PACKAGE_MANAGER_PROMPT_OPTIONS = [
1542
1486
  { label: "npm", value: "npm", hint: "Use npm" },
1543
1487
  { label: "pnpm", value: "pnpm", hint: "Use pnpm" },
@@ -1564,15 +1508,6 @@ var BOOLEAN_PROMPT_OPTIONS = [
1564
1508
  { label: "Yes", value: "yes", hint: "Enable this option" },
1565
1509
  { label: "No", value: "no", hint: "Keep the default disabled state" }
1566
1510
  ];
1567
- function emitCompletion(payload, options) {
1568
- if (options.emitOutput) {
1569
- printCompletionPayload(payload, {
1570
- printLine: options.printLine,
1571
- warnLine: options.warnLine
1572
- });
1573
- }
1574
- return payload;
1575
- }
1576
1511
  async function executeCreateCommand({
1577
1512
  projectDir,
1578
1513
  cwd,
@@ -1593,7 +1528,7 @@ async function executeCreateCommand({
1593
1528
  { runScaffoldFlow },
1594
1529
  { getTemplateSelectOptions }
1595
1530
  ] = await Promise.all([
1596
- loadCliPromptRuntime(),
1531
+ loadCliPromptRuntime2(),
1597
1532
  loadCliScaffoldRuntime(),
1598
1533
  loadCliTemplatesRuntime()
1599
1534
  ]);
@@ -1663,99 +1598,23 @@ async function executeCreateCommand({
1663
1598
  }
1664
1599
  }
1665
1600
  }
1666
- async function executeAddCommand({
1667
- cwd,
1668
- emitOutput = true,
1669
- flags,
1670
- interactive,
1671
- kind,
1672
- name,
1673
- printLine = console.log,
1674
- prompt,
1675
- warnLine = console.warn
1676
- }) {
1677
- let activePrompt;
1678
- const dryRun = Boolean(flags["dry-run"]);
1679
- try {
1680
- const addRuntime = await loadCliAddRuntime();
1681
- const isInteractiveSession = interactive ?? isInteractiveTerminal();
1682
- if (!kind) {
1683
- if (shouldPrintMissingAddKindHelp({ emitOutput })) {
1684
- printLine(addRuntime.formatAddHelpText());
1685
- }
1686
- throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.MISSING_ARGUMENT, formatMissingAddKindDetailLine());
1687
- }
1688
- if (!isAddKindId(kind)) {
1689
- throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_COMMAND, `Unknown add kind "${kind}". Expected one of: ${formatAddKindList()}.`);
1690
- }
1691
- if (dryRun && !supportsAddKindDryRun(kind)) {
1692
- throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, `\`wp-typia add ${kind}\` does not support \`--dry-run\` yet.`);
1693
- }
1694
- const executionContext = {
1695
- addRuntime,
1696
- cwd,
1697
- flags,
1698
- getOrCreatePrompt: async () => {
1699
- if (activePrompt) {
1700
- return activePrompt;
1701
- }
1702
- const { createReadlinePrompt } = await loadCliPromptRuntime();
1703
- activePrompt = prompt ?? createReadlinePrompt();
1704
- return activePrompt;
1705
- },
1706
- isInteractiveSession,
1707
- name,
1708
- warnLine
1709
- };
1710
- return await executePlannedAddKind(kind, executionContext, {
1711
- cwd,
1712
- dryRun,
1713
- emitOutput,
1714
- printLine
1715
- });
1716
- } catch (error) {
1717
- if (!shouldWrapCliCommandError({ emitOutput })) {
1718
- throw error;
1719
- }
1720
- throw await wrapCliCommandError("add", error);
1721
- } finally {
1722
- if (activePrompt && activePrompt !== prompt) {
1723
- activePrompt.close();
1724
- }
1725
- }
1726
- }
1727
- async function executeTemplatesCommand({ flags }, printLine = console.log) {
1728
- const {
1729
- formatTemplateDetails,
1730
- formatTemplateFeatures,
1731
- formatTemplateSummary,
1732
- getTemplateById,
1733
- listTemplates
1734
- } = await loadCliTemplatesRuntime();
1735
- const subcommand = flags.subcommand ?? "list";
1736
- if (subcommand === "list") {
1737
- for (const template of listTemplates()) {
1738
- printBlock(printLine, [formatTemplateSummary(template), formatTemplateFeatures(template)]);
1739
- }
1740
- return;
1741
- }
1742
- if (subcommand === "inspect") {
1743
- if (!flags.id) {
1744
- throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.MISSING_ARGUMENT, "`wp-typia templates inspect` requires <template-id>.");
1745
- }
1746
- const template = getTemplateById(flags.id);
1747
- if (!template) {
1748
- throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, `Unknown template "${flags.id}".`);
1749
- }
1750
- printBlock(printLine, [formatTemplateDetails(template)]);
1751
- return;
1601
+ // src/runtime-bridge-doctor.ts
1602
+ var loadCliDoctorRuntime = () => import("./cli-doctor-5m6xyx9q.js");
1603
+ async function executeDoctorCommand(cwd) {
1604
+ try {
1605
+ const { runDoctor } = await loadCliDoctorRuntime();
1606
+ await runDoctor(cwd);
1607
+ } catch (error) {
1608
+ throw await wrapCliCommandError("doctor", error);
1752
1609
  }
1753
- throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_COMMAND, `Unknown templates subcommand "${subcommand}". Expected list or inspect.`);
1754
1610
  }
1611
+ // src/runtime-bridge-init.ts
1612
+ import path2 from "path";
1613
+ var loadCliInitRuntime = () => import("./cli-init-qv3zxmvc.js");
1755
1614
  async function executeInitCommand({ apply, cwd, packageManager, projectDir }, options = {}) {
1756
1615
  try {
1757
1616
  const { runInitCommand } = await loadCliInitRuntime();
1758
- const resolvedProjectDir = projectDir ? (await import("path")).resolve(cwd, projectDir) : cwd;
1617
+ const resolvedProjectDir = projectDir ? path2.resolve(cwd, projectDir) : cwd;
1759
1618
  const plan = await runInitCommand({
1760
1619
  apply,
1761
1620
  packageManager,
@@ -1776,14 +1635,8 @@ async function executeInitCommand({ apply, cwd, packageManager, projectDir }, op
1776
1635
  throw await wrapCliCommandError("init", error);
1777
1636
  }
1778
1637
  }
1779
- async function executeDoctorCommand(cwd) {
1780
- try {
1781
- const { runDoctor } = await loadCliDoctorRuntime();
1782
- await runDoctor(cwd);
1783
- } catch (error) {
1784
- throw await wrapCliCommandError("doctor", error);
1785
- }
1786
- }
1638
+ // src/runtime-bridge-migrate.ts
1639
+ var loadMigrationsRuntime = () => import("./migrations-7g9rag5d.js");
1787
1640
  async function executeMigrateCommand({
1788
1641
  command,
1789
1642
  cwd,
@@ -1791,12 +1644,17 @@ async function executeMigrateCommand({
1791
1644
  prompt,
1792
1645
  renderLine
1793
1646
  }) {
1794
- const { formatMigrationHelpText, parseMigrationArgs, runMigrationCommand } = await loadMigrationsRuntime();
1795
- if (!command) {
1796
- console.log(formatMigrationHelpText());
1797
- return;
1798
- }
1799
1647
  try {
1648
+ const { formatMigrationHelpText, parseMigrationArgs, runMigrationCommand } = await loadMigrationsRuntime();
1649
+ if (!command) {
1650
+ const helpText = formatMigrationHelpText();
1651
+ if (renderLine) {
1652
+ renderLine(helpText);
1653
+ } else {
1654
+ console.log(helpText);
1655
+ }
1656
+ return;
1657
+ }
1800
1658
  const argv = [command];
1801
1659
  pushFlag(argv, "all", flags.all);
1802
1660
  pushFlag(argv, "force", flags.force);
@@ -1836,11 +1694,246 @@ async function executeMigrateCommand({
1836
1694
  throw await wrapCliCommandError("migrate", error);
1837
1695
  }
1838
1696
  }
1697
+ // src/runtime-bridge-templates.ts
1698
+ var loadCliTemplatesRuntime2 = () => import("./cli-templates-hc71dfc2.js");
1699
+ async function executeTemplatesCommand({ flags }, printLine = console.log) {
1700
+ const {
1701
+ formatTemplateDetails,
1702
+ formatTemplateFeatures,
1703
+ formatTemplateSummary,
1704
+ getTemplateById,
1705
+ listTemplates
1706
+ } = await loadCliTemplatesRuntime2();
1707
+ const subcommand = flags.subcommand ?? "list";
1708
+ if (subcommand === "list") {
1709
+ for (const template of listTemplates()) {
1710
+ printBlock(printLine, [formatTemplateSummary(template), formatTemplateFeatures(template)]);
1711
+ }
1712
+ return;
1713
+ }
1714
+ if (subcommand === "inspect") {
1715
+ if (!flags.id) {
1716
+ throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.MISSING_ARGUMENT, "`wp-typia templates inspect` requires <template-id>.");
1717
+ }
1718
+ const template = getTemplateById(flags.id);
1719
+ if (!template) {
1720
+ throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, `Unknown template "${flags.id}".`);
1721
+ }
1722
+ printBlock(printLine, [formatTemplateDetails(template)]);
1723
+ return;
1724
+ }
1725
+ throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_COMMAND, `Unknown templates subcommand "${subcommand}". Expected list or inspect.`);
1726
+ }
1839
1727
  async function listTemplatesForRuntime() {
1840
- const { listTemplates } = await loadCliTemplatesRuntime();
1728
+ const { listTemplates } = await loadCliTemplatesRuntime2();
1841
1729
  return listTemplates();
1842
1730
  }
1843
-
1731
+ // src/runtime-bridge-sync.ts
1732
+ import { spawnSync } from "child_process";
1733
+ import fs3 from "fs";
1734
+ import path3 from "path";
1735
+ var SYNC_INSTALL_MARKERS = [
1736
+ "node_modules",
1737
+ ".pnp.cjs",
1738
+ ".pnp.loader.mjs"
1739
+ ];
1740
+ var LOCAL_SYNC_TOOL_PATTERN = /(^|[\s;&|()])(?:tsx|wp-scripts)(?=($|[\s;&|()]))/u;
1741
+ var CAPTURED_SYNC_OUTPUT_MAX_BUFFER = 16 * 1024 * 1024;
1742
+ function resolveSyncExecutionTarget(subcommand) {
1743
+ if (!subcommand) {
1744
+ return "default";
1745
+ }
1746
+ if (subcommand === "ai") {
1747
+ return "ai";
1748
+ }
1749
+ throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_COMMAND, `Unknown sync subcommand "${subcommand}". Expected one of: "ai".`);
1750
+ }
1751
+ function getSyncRootError(cwd) {
1752
+ return createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.OUTSIDE_PROJECT_ROOT, `No generated wp-typia project root was found at ${cwd}. Run \`wp-typia sync\` from a scaffolded project or official workspace root that already contains generated sync scripts. If you expected this directory to work, cd into the scaffold root first or rerun the scaffold before syncing.`);
1753
+ }
1754
+ function readSyncPackageJson(packageJsonPath) {
1755
+ const source = fs3.readFileSync(packageJsonPath, "utf8");
1756
+ try {
1757
+ return JSON.parse(source);
1758
+ } catch (error) {
1759
+ const message = error instanceof Error ? error.message : String(error);
1760
+ throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, `Unable to parse ${packageJsonPath}: ${message}`, error instanceof Error ? { cause: error } : undefined);
1761
+ }
1762
+ }
1763
+ function resolveSyncProjectContext(cwd) {
1764
+ const packageJsonPath = path3.join(cwd, "package.json");
1765
+ if (!fs3.existsSync(packageJsonPath)) {
1766
+ throw getSyncRootError(cwd);
1767
+ }
1768
+ const packageJson = readSyncPackageJson(packageJsonPath);
1769
+ const scripts = packageJson.scripts ?? {};
1770
+ const syncScripts = {
1771
+ sync: typeof scripts.sync === "string" ? {
1772
+ command: scripts.sync,
1773
+ scriptName: "sync"
1774
+ } : undefined,
1775
+ "sync-ai": typeof scripts["sync-ai"] === "string" ? {
1776
+ command: scripts["sync-ai"],
1777
+ scriptName: "sync-ai"
1778
+ } : typeof scripts["sync-wordpress-ai"] === "string" ? {
1779
+ command: scripts["sync-wordpress-ai"],
1780
+ scriptName: "sync-wordpress-ai"
1781
+ } : undefined,
1782
+ "sync-rest": typeof scripts["sync-rest"] === "string" ? {
1783
+ command: scripts["sync-rest"],
1784
+ scriptName: "sync-rest"
1785
+ } : undefined,
1786
+ "sync-types": typeof scripts["sync-types"] === "string" ? {
1787
+ command: scripts["sync-types"],
1788
+ scriptName: "sync-types"
1789
+ } : undefined
1790
+ };
1791
+ return {
1792
+ cwd,
1793
+ packageJsonPath,
1794
+ packageManager: inferPackageManagerId(cwd, packageJson.packageManager),
1795
+ scripts: syncScripts
1796
+ };
1797
+ }
1798
+ function findInstalledDependencyMarkerDir(projectDir) {
1799
+ let currentDir = path3.resolve(projectDir);
1800
+ while (true) {
1801
+ if (SYNC_INSTALL_MARKERS.some((marker) => fs3.existsSync(path3.join(currentDir, marker)))) {
1802
+ return currentDir;
1803
+ }
1804
+ const parentDir = path3.dirname(currentDir);
1805
+ if (parentDir === currentDir) {
1806
+ return null;
1807
+ }
1808
+ currentDir = parentDir;
1809
+ }
1810
+ }
1811
+ function scriptsLikelyNeedInstalledDependencies(project, target) {
1812
+ const candidateScripts = target === "ai" ? [project.scripts["sync-ai"]] : project.scripts.sync ? [project.scripts.sync] : [
1813
+ project.scripts["sync-types"],
1814
+ project.scripts["sync-rest"],
1815
+ project.scripts["sync-ai"]
1816
+ ];
1817
+ return candidateScripts.some((script) => script !== undefined && LOCAL_SYNC_TOOL_PATTERN.test(script.command));
1818
+ }
1819
+ function assertSyncDependenciesInstalled(project, target) {
1820
+ if (!scriptsLikelyNeedInstalledDependencies(project, target)) {
1821
+ return;
1822
+ }
1823
+ const markerDir = findInstalledDependencyMarkerDir(project.cwd);
1824
+ if (markerDir) {
1825
+ return;
1826
+ }
1827
+ throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.DEPENDENCIES_NOT_INSTALLED, `Project dependencies have not been installed yet. Run \`${formatInstallCommand(project.packageManager)}\` from the project root before \`wp-typia sync\`. The generated sync scripts rely on local tools such as \`tsx\`.`);
1828
+ }
1829
+ function getPackageManagerRunInvocation(packageManager, scriptName, extraArgs) {
1830
+ switch (packageManager) {
1831
+ case "bun":
1832
+ return { args: ["run", scriptName, ...extraArgs], command: "bun" };
1833
+ case "npm":
1834
+ return {
1835
+ args: [
1836
+ "run",
1837
+ scriptName,
1838
+ ...extraArgs.length > 0 ? ["--", ...extraArgs] : []
1839
+ ],
1840
+ command: "npm"
1841
+ };
1842
+ case "pnpm":
1843
+ return { args: ["run", scriptName, ...extraArgs], command: "pnpm" };
1844
+ case "yarn":
1845
+ return { args: ["run", scriptName, ...extraArgs], command: "yarn" };
1846
+ }
1847
+ }
1848
+ function createSyncPlannedCommand(project, scriptName, extraArgs) {
1849
+ const script = project.scripts[scriptName];
1850
+ if (!script) {
1851
+ return null;
1852
+ }
1853
+ const invocation = getPackageManagerRunInvocation(project.packageManager, script.scriptName, extraArgs);
1854
+ return {
1855
+ args: invocation.args,
1856
+ command: invocation.command,
1857
+ displayCommand: formatRunScript(project.packageManager, script.scriptName, extraArgs.join(" ")),
1858
+ scriptName: script.scriptName
1859
+ };
1860
+ }
1861
+ function buildSyncPlannedCommands(project, extraArgs, target) {
1862
+ if (target === "ai") {
1863
+ const syncAiCommand2 = createSyncPlannedCommand(project, "sync-ai", extraArgs);
1864
+ if (!syncAiCommand2) {
1865
+ throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.CONFIGURATION_MISSING, `Expected ${project.packageJsonPath} to define a \`sync-ai\` script for \`wp-typia sync ai\`.`);
1866
+ }
1867
+ return [syncAiCommand2];
1868
+ }
1869
+ if (project.scripts.sync) {
1870
+ return [createSyncPlannedCommand(project, "sync", extraArgs)];
1871
+ }
1872
+ const syncTypesCommand = createSyncPlannedCommand(project, "sync-types", extraArgs);
1873
+ if (!syncTypesCommand) {
1874
+ throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.CONFIGURATION_MISSING, `Expected ${project.packageJsonPath} to define either a \`sync\` or \`sync-types\` script.`);
1875
+ }
1876
+ const plannedCommands = [syncTypesCommand];
1877
+ const syncRestCommand = createSyncPlannedCommand(project, "sync-rest", extraArgs);
1878
+ if (syncRestCommand) {
1879
+ plannedCommands.push(syncRestCommand);
1880
+ }
1881
+ const syncAiCommand = createSyncPlannedCommand(project, "sync-ai", extraArgs);
1882
+ if (syncAiCommand) {
1883
+ plannedCommands.push(syncAiCommand);
1884
+ }
1885
+ return plannedCommands;
1886
+ }
1887
+ function runProjectScript(project, plannedCommand, options) {
1888
+ const result = spawnSync(plannedCommand.command, plannedCommand.args, {
1889
+ cwd: project.cwd,
1890
+ encoding: options.captureOutput ? "utf8" : undefined,
1891
+ ...options.captureOutput ? { maxBuffer: CAPTURED_SYNC_OUTPUT_MAX_BUFFER } : {},
1892
+ shell: process.platform === "win32",
1893
+ stdio: options.captureOutput ? "pipe" : "inherit"
1894
+ });
1895
+ const stderr = options.captureOutput && typeof result.stderr === "string" ? result.stderr : undefined;
1896
+ const stdout = options.captureOutput && typeof result.stdout === "string" ? result.stdout : undefined;
1897
+ if (result.error || result.status !== 0) {
1898
+ throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.COMMAND_EXECUTION, `\`${plannedCommand.displayCommand}\` failed.`, {
1899
+ cause: result.error ?? (stderr ? new Error(stderr.trim()) : undefined)
1900
+ });
1901
+ }
1902
+ return {
1903
+ ...plannedCommand,
1904
+ exitCode: result.status ?? 0,
1905
+ ...stderr !== undefined ? { stderr } : {},
1906
+ ...stdout !== undefined ? { stdout } : {}
1907
+ };
1908
+ }
1909
+ async function executeSyncCommand({
1910
+ captureOutput = false,
1911
+ check = false,
1912
+ cwd,
1913
+ dryRun = false,
1914
+ target = "default"
1915
+ }) {
1916
+ const project = resolveSyncProjectContext(cwd);
1917
+ const extraArgs = check ? ["--check"] : [];
1918
+ const plannedCommands = buildSyncPlannedCommands(project, extraArgs, target);
1919
+ const result = {
1920
+ check,
1921
+ dryRun,
1922
+ packageJsonPath: project.packageJsonPath,
1923
+ packageManager: project.packageManager,
1924
+ plannedCommands,
1925
+ projectDir: project.cwd,
1926
+ target
1927
+ };
1928
+ if (dryRun) {
1929
+ return result;
1930
+ }
1931
+ assertSyncDependenciesInstalled(project, target);
1932
+ result.executedCommands = plannedCommands.map((plannedCommand) => runProjectScript(project, plannedCommand, {
1933
+ captureOutput
1934
+ }));
1935
+ return result;
1936
+ }
1844
1937
  // src/ui/lazy-flow.tsx
1845
1938
  var import_react33 = __toESM(require_react(), 1);
1846
1939
 
@@ -2420,7 +2513,7 @@ var doctorCommand = defineCommand({
2420
2513
  const prefersStructuredOutput = prefersStructuredCliOutput(args);
2421
2514
  if (prefersStructuredOutput) {
2422
2515
  const [{ getDoctorChecks }, { getDoctorFailureDetailLines }] = await Promise.all([
2423
- import("./cli-doctor-564c43ay.js"),
2516
+ import("./cli-doctor-5m6xyx9q.js"),
2424
2517
  import("./cli-diagnostics-5dvztm7q.js")
2425
2518
  ]);
2426
2519
  const checks = await getDoctorChecks(args.cwd);
@@ -2479,7 +2572,7 @@ var initCommand = defineCommand({
2479
2572
 
2480
2573
  // src/mcp.ts
2481
2574
  import fs4 from "fs/promises";
2482
- import path3 from "path";
2575
+ import path4 from "path";
2483
2576
 
2484
2577
  // ../../node_modules/.bun/@bunli+plugin-mcp@0.2.5+ef72ce197b058209/node_modules/@bunli/plugin-mcp/src/errors.ts
2485
2578
  class SchemaConversionError extends TaggedError("SchemaConversionError")() {
@@ -2498,7 +2591,7 @@ class McpToolsProviderError extends TaggedError("McpToolsProviderError")() {
2498
2591
  function jsonSchemaToZodSchema(schema, options = {}) {
2499
2592
  return convertSchema(schema, options, "$");
2500
2593
  }
2501
- function convertSchema(schema, options, path3) {
2594
+ function convertSchema(schema, options, path4) {
2502
2595
  const { coerce = true } = options;
2503
2596
  if (!schema || typeof schema !== "object") {
2504
2597
  return Result.ok(exports_external.unknown());
@@ -2513,49 +2606,49 @@ function convertSchema(schema, options, path3) {
2513
2606
  return Result.ok(exports_external.enum(enumValues));
2514
2607
  }
2515
2608
  const literals = enumValues.map((v) => exports_external.literal(v));
2516
- return unionFromSchemas(literals, path3);
2609
+ return unionFromSchemas(literals, path4);
2517
2610
  }
2518
2611
  }
2519
2612
  if (schema.anyOf && schema.anyOf.length > 0) {
2520
- const schemas = mapSchemas(schema.anyOf, options, `${path3}.anyOf`);
2613
+ const schemas = mapSchemas(schema.anyOf, options, `${path4}.anyOf`);
2521
2614
  if (Result.isError(schemas)) {
2522
2615
  return schemas;
2523
2616
  }
2524
- return unionFromSchemas(schemas.value, `${path3}.anyOf`);
2617
+ return unionFromSchemas(schemas.value, `${path4}.anyOf`);
2525
2618
  }
2526
2619
  if (schema.oneOf && schema.oneOf.length > 0) {
2527
- const schemas = mapSchemas(schema.oneOf, options, `${path3}.oneOf`);
2620
+ const schemas = mapSchemas(schema.oneOf, options, `${path4}.oneOf`);
2528
2621
  if (Result.isError(schemas)) {
2529
2622
  return schemas;
2530
2623
  }
2531
- return unionFromSchemas(schemas.value, `${path3}.oneOf`);
2624
+ return unionFromSchemas(schemas.value, `${path4}.oneOf`);
2532
2625
  }
2533
2626
  const schemaType = Array.isArray(schema.type) ? schema.type[0] : schema.type;
2534
2627
  switch (schemaType) {
2535
2628
  case "string":
2536
- return buildStringSchema(schema, path3);
2629
+ return buildStringSchema(schema, path4);
2537
2630
  case "number":
2538
2631
  case "integer":
2539
2632
  return Result.ok(buildNumberSchema(schema, coerce));
2540
2633
  case "boolean":
2541
2634
  return Result.ok(buildBooleanSchema());
2542
2635
  case "array":
2543
- return buildArraySchema(schema, options, path3);
2636
+ return buildArraySchema(schema, options, path4);
2544
2637
  case "object":
2545
- return buildObjectSchema(schema, options, path3);
2638
+ return buildObjectSchema(schema, options, path4);
2546
2639
  case "null":
2547
2640
  return Result.ok(exports_external.null());
2548
2641
  default:
2549
2642
  if (schema.properties) {
2550
- return buildObjectSchema(schema, options, path3);
2643
+ return buildObjectSchema(schema, options, path4);
2551
2644
  }
2552
2645
  if (schema.items) {
2553
- return buildArraySchema(schema, options, path3);
2646
+ return buildArraySchema(schema, options, path4);
2554
2647
  }
2555
2648
  return Result.ok(exports_external.unknown());
2556
2649
  }
2557
2650
  }
2558
- function buildStringSchema(schema, path3) {
2651
+ function buildStringSchema(schema, path4) {
2559
2652
  let zodSchema = exports_external.string();
2560
2653
  if (schema.minLength !== undefined) {
2561
2654
  zodSchema = zodSchema.min(schema.minLength);
@@ -2568,7 +2661,7 @@ function buildStringSchema(schema, path3) {
2568
2661
  const regexResult = Result.try({
2569
2662
  try: () => new RegExp(pattern),
2570
2663
  catch: (cause) => new SchemaConversionError({
2571
- path: path3,
2664
+ path: path4,
2572
2665
  message: `Invalid regex pattern "${pattern}"`,
2573
2666
  cause
2574
2667
  })
@@ -2625,19 +2718,19 @@ function buildNumberSchema(schema, coerce) {
2625
2718
  function buildBooleanSchema() {
2626
2719
  return exports_external.boolean();
2627
2720
  }
2628
- function buildArraySchema(schema, options, path3) {
2721
+ function buildArraySchema(schema, options, path4) {
2629
2722
  let itemSchema = exports_external.unknown();
2630
2723
  if (schema.items) {
2631
2724
  if (Array.isArray(schema.items)) {
2632
2725
  if (schema.items.length > 0) {
2633
- const itemResult = convertSchema(schema.items[0], options, `${path3}.items[0]`);
2726
+ const itemResult = convertSchema(schema.items[0], options, `${path4}.items[0]`);
2634
2727
  if (Result.isError(itemResult)) {
2635
2728
  return itemResult;
2636
2729
  }
2637
2730
  itemSchema = itemResult.value;
2638
2731
  }
2639
2732
  } else {
2640
- const itemResult = convertSchema(schema.items, options, `${path3}.items`);
2733
+ const itemResult = convertSchema(schema.items, options, `${path4}.items`);
2641
2734
  if (Result.isError(itemResult)) {
2642
2735
  return itemResult;
2643
2736
  }
@@ -2653,14 +2746,14 @@ function buildArraySchema(schema, options, path3) {
2653
2746
  }
2654
2747
  return Result.ok(zodSchema);
2655
2748
  }
2656
- function buildObjectSchema(schema, options, path3) {
2749
+ function buildObjectSchema(schema, options, path4) {
2657
2750
  if (!schema.properties) {
2658
2751
  return Result.ok(exports_external.record(exports_external.string(), exports_external.unknown()));
2659
2752
  }
2660
2753
  const shape = {};
2661
2754
  const requiredFields = new Set(schema.required || []);
2662
2755
  for (const [propName, propSchema] of Object.entries(schema.properties)) {
2663
- const propResult = convertSchema(propSchema, options, `${path3}.properties.${propName}`);
2756
+ const propResult = convertSchema(propSchema, options, `${path4}.properties.${propName}`);
2664
2757
  if (Result.isError(propResult)) {
2665
2758
  return propResult;
2666
2759
  }
@@ -2675,10 +2768,10 @@ function buildObjectSchema(schema, options, path3) {
2675
2768
  }
2676
2769
  return Result.ok(exports_external.object(shape));
2677
2770
  }
2678
- function mapSchemas(schemas, options, path3) {
2771
+ function mapSchemas(schemas, options, path4) {
2679
2772
  const zodSchemas = [];
2680
2773
  for (let index = 0;index < schemas.length; index += 1) {
2681
- const converted = convertSchema(schemas[index], options, `${path3}[${index}]`);
2774
+ const converted = convertSchema(schemas[index], options, `${path4}[${index}]`);
2682
2775
  if (Result.isError(converted)) {
2683
2776
  return converted;
2684
2777
  }
@@ -2686,11 +2779,11 @@ function mapSchemas(schemas, options, path3) {
2686
2779
  }
2687
2780
  return Result.ok(zodSchemas);
2688
2781
  }
2689
- function unionFromSchemas(schemas, path3) {
2782
+ function unionFromSchemas(schemas, path4) {
2690
2783
  if (schemas.length === 0) {
2691
2784
  return Result.err(new SchemaConversionError({
2692
- path: path3,
2693
- message: `Cannot create union from an empty schema set at ${path3}`,
2785
+ path: path4,
2786
+ message: `Cannot create union from an empty schema set at ${path4}`,
2694
2787
  cause: new Error("Empty schema union")
2695
2788
  }));
2696
2789
  }
@@ -3013,7 +3106,7 @@ function getErrorCauseOptions(error) {
3013
3106
  return error instanceof Error ? { cause: error } : undefined;
3014
3107
  }
3015
3108
  async function readSchemaSource(cwd, source) {
3016
- const schemaPath = path3.resolve(cwd, source.path);
3109
+ const schemaPath = path4.resolve(cwd, source.path);
3017
3110
  const raw = await fs4.readFile(schemaPath, "utf8");
3018
3111
  let parsed;
3019
3112
  try {
@@ -3035,7 +3128,7 @@ async function readSchemaSource(cwd, source) {
3035
3128
  async function loadMcpToolGroups(cwd, schemaSources) {
3036
3129
  return Promise.all(schemaSources.map((source) => readSchemaSource(cwd, source)));
3037
3130
  }
3038
- async function syncMcpSchemas(cwd, schemaSources, outputDir = path3.join(cwd, ".bunli", "mcp")) {
3131
+ async function syncMcpSchemas(cwd, schemaSources, outputDir = path4.join(cwd, ".bunli", "mcp")) {
3039
3132
  const groups = await loadMcpToolGroups(cwd, schemaSources);
3040
3133
  const result = await generateMCPTypes({
3041
3134
  outputDir,
@@ -3058,7 +3151,7 @@ async function syncMcpSchemas(cwd, schemaSources, outputDir = path3.join(cwd, ".
3058
3151
  }
3059
3152
  }
3060
3153
  await fs4.mkdir(outputDir, { recursive: true });
3061
- await fs4.writeFile(path3.join(outputDir, "registry.json"), `${JSON.stringify(registry, null, 2)}
3154
+ await fs4.writeFile(path4.join(outputDir, "registry.json"), `${JSON.stringify(registry, null, 2)}
3062
3155
  `, "utf8");
3063
3156
  return {
3064
3157
  commandCount: registry.reduce((count, group) => count + group.tools.length, 0),
@@ -3068,12 +3161,31 @@ async function syncMcpSchemas(cwd, schemaSources, outputDir = path3.join(cwd, ".
3068
3161
  }
3069
3162
 
3070
3163
  // src/commands/mcp.ts
3164
+ var defaultPrintLine = (line) => {
3165
+ process.stdout.write(`${line}
3166
+ `);
3167
+ };
3168
+ function resolveMcpPrintLine(args) {
3169
+ return args.printLine ?? defaultPrintLine;
3170
+ }
3171
+ function printMcpToolGroupSummary(summary, printLine) {
3172
+ for (const group of summary) {
3173
+ printLine(`${group.namespace} (${group.toolCount})`);
3174
+ for (const tool of group.tools) {
3175
+ printLine(` - ${tool}`);
3176
+ }
3177
+ }
3178
+ }
3179
+ function printMcpSyncSummary(result, printLine) {
3180
+ printLine(`Synced ${result.commandCount} MCP tools across ${result.groups.length} namespaces into ${result.outputDir}.`);
3181
+ }
3071
3182
  var mcpCommand = defineCommand({
3072
3183
  defaultFormat: "json",
3073
3184
  description: "Inspect or sync schema-driven MCP metadata for wp-typia.",
3074
3185
  handler: async (args) => {
3075
3186
  const subcommand = args.positional[0] ?? "list";
3076
3187
  const prefersStructuredOutput = prefersStructuredCliOutput(args);
3188
+ const printLine = resolveMcpPrintLine(args);
3077
3189
  const userConfig = args.context?.store?.wpTypiaUserConfig && typeof args.context.store.wpTypiaUserConfig === "object" ? args.context.store.wpTypiaUserConfig : {};
3078
3190
  const schemaSources = getMcpSchemaSources(userConfig);
3079
3191
  if (schemaSources.length === 0) {
@@ -3098,12 +3210,7 @@ var mcpCommand = defineCommand({
3098
3210
  args.output({ groups: summary });
3099
3211
  return;
3100
3212
  }
3101
- for (const group of summary) {
3102
- console.log(`${group.namespace} (${group.toolCount})`);
3103
- for (const tool of group.tools) {
3104
- console.log(` - ${tool}`);
3105
- }
3106
- }
3213
+ printMcpToolGroupSummary(summary, printLine);
3107
3214
  return;
3108
3215
  }
3109
3216
  if (subcommand === "sync") {
@@ -3113,7 +3220,7 @@ var mcpCommand = defineCommand({
3113
3220
  args.output({ sync: result });
3114
3221
  return;
3115
3222
  }
3116
- console.log(`Synced ${result.commandCount} MCP tools across ${result.groups.length} namespaces into ${result.outputDir}.`);
3223
+ printMcpSyncSummary(result, printLine);
3117
3224
  return;
3118
3225
  }
3119
3226
  emitCliDiagnosticFailure(args, {
@@ -3297,4 +3404,4 @@ export {
3297
3404
  wpTypiaCommands
3298
3405
  };
3299
3406
 
3300
- //# debugId=1A737B9B812DF37F64756E2164756E21
3407
+ //# debugId=8B3272B9527B417864756E2164756E21