@canonical/summon 0.17.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/generators/example/hello/index.ts +3 -9
  2. package/generators/example/webapp/index.ts +7 -5
  3. package/generators/init/index.ts +3 -8
  4. package/generators/init/templates/generator.ts.ejs +3 -9
  5. package/package.json +24 -27
  6. package/src/bin.tsx +199 -0
  7. package/src/completion.ts +4 -1
  8. package/src/components/App.tsx +108 -15
  9. package/src/components/ExecutionProgress.tsx +8 -4
  10. package/src/components/FileTreePreview.tsx +1 -1
  11. package/src/components/PromptSequence.tsx +1 -1
  12. package/src/discovery/loadGenerator.ts +37 -0
  13. package/src/display/index.ts +2 -0
  14. package/src/display/printGeneratorHelp.ts +133 -0
  15. package/src/display/printNode.ts +76 -0
  16. package/src/registration/buildCommandBarrel.ts +57 -0
  17. package/src/registration/index.ts +3 -0
  18. package/src/registration/registerFromBarrel.tsx +548 -0
  19. package/src/registration/types.ts +28 -0
  20. package/README.md +0 -446
  21. package/src/__tests__/combinators.test.ts +0 -895
  22. package/src/__tests__/dry-run.test.ts +0 -927
  23. package/src/__tests__/effect.test.ts +0 -816
  24. package/src/__tests__/interpreter.test.ts +0 -673
  25. package/src/__tests__/primitives.test.ts +0 -970
  26. package/src/__tests__/task.test.ts +0 -929
  27. package/src/__tests__/template.test.ts +0 -666
  28. package/src/cli-format.ts +0 -236
  29. package/src/cli-types.ts +0 -53
  30. package/src/cli.tsx +0 -1366
  31. package/src/combinators.ts +0 -294
  32. package/src/dry-run.ts +0 -434
  33. package/src/effect.ts +0 -224
  34. package/src/index.ts +0 -266
  35. package/src/interpreter.ts +0 -463
  36. package/src/primitives.ts +0 -442
  37. package/src/task.ts +0 -245
  38. package/src/template.ts +0 -537
  39. package/src/types.ts +0 -453
@@ -8,15 +8,9 @@
8
8
  */
9
9
 
10
10
  import * as path from "node:path";
11
- import {
12
- info,
13
- mkdir,
14
- sequence_,
15
- template,
16
- when,
17
- withHelpers,
18
- } from "../../../src/index.js";
19
- import type { GeneratorDefinition } from "../../../src/types.js";
11
+ import type { GeneratorDefinition } from "@canonical/summon-core";
12
+ import { template, withHelpers } from "@canonical/summon-core";
13
+ import { info, mkdir, sequence_, when } from "@canonical/task";
20
14
 
21
15
  // =============================================================================
22
16
  // Types
@@ -9,29 +9,31 @@
9
9
  */
10
10
 
11
11
  import * as path from "node:path";
12
+ import type { GeneratorDefinition } from "@canonical/summon-core";
13
+ import { template, withHelpers } from "@canonical/summon-core";
14
+ import type { Task } from "@canonical/task";
12
15
  import {
13
16
  appendFile,
14
17
  debug,
15
18
  exec,
16
19
  exists,
20
+ flatMap,
17
21
  getContext,
18
22
  ifElse,
19
23
  info,
24
+ map,
20
25
  mkdir,
21
26
  orElse,
22
27
  parallel,
28
+ pure,
23
29
  readFile,
24
30
  sequence_,
25
31
  setContext,
26
- template,
27
32
  traverse_,
28
33
  warn,
29
34
  when,
30
- withHelpers,
31
35
  writeFile,
32
- } from "../../../src/index.js";
33
- import { flatMap, map, pure } from "../../../src/task.js";
34
- import type { GeneratorDefinition, Task } from "../../../src/types.js";
36
+ } from "@canonical/task";
35
37
 
36
38
  // =============================================================================
37
39
  // Types
@@ -6,14 +6,9 @@
6
6
 
7
7
  import * as path from "node:path";
8
8
  import { fileURLToPath } from "node:url";
9
- import type { GeneratorDefinition } from "../../src/index.js";
10
- import {
11
- info,
12
- mkdir,
13
- sequence_,
14
- template,
15
- withHelpers,
16
- } from "../../src/index.js";
9
+ import type { GeneratorDefinition } from "@canonical/summon-core";
10
+ import { template, withHelpers } from "@canonical/summon-core";
11
+ import { info, mkdir, sequence_ } from "@canonical/task";
17
12
 
18
13
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
19
14
 
@@ -6,15 +6,9 @@
6
6
 
7
7
  import * as path from "node:path";
8
8
  import { fileURLToPath } from "node:url";
9
- import type { GeneratorDefinition } from "@canonical/summon";
10
- import {
11
- info,
12
- mkdir,
13
- sequence_,
14
- template,
15
- when,
16
- withHelpers,
17
- } from "@canonical/summon";
9
+ import type { GeneratorDefinition } from "@canonical/summon-core";
10
+ import { template, withHelpers } from "@canonical/summon-core";
11
+ import { info, mkdir, sequence_, when } from "@canonical/task";
18
12
 
19
13
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
20
14
 
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@canonical/summon",
3
- "description": "A monadic task-centric code generator framework with React Ink CLI.",
4
- "version": "0.17.0",
3
+ "description": "Summon CLI binary: interactive code generator with Ink UI, shell completion, and Commander registration.",
4
+ "version": "0.20.0",
5
5
  "type": "module",
6
- "module": "src/index.ts",
7
- "types": "src/index.ts",
6
+ "module": "src/bin.tsx",
8
7
  "bin": {
9
- "summon": "src/cli.tsx"
8
+ "summon": "src/bin.tsx"
10
9
  },
11
10
  "files": [
12
11
  "src",
@@ -28,40 +27,38 @@
28
27
  "scripts": {
29
28
  "build": "echo 'No build needed - runs directly from TypeScript'",
30
29
  "build:all": "bun run build",
31
- "check": "bun run check:biome && bun run check:ts && bun run check:webarchitect",
30
+ "check": "bun run check:biome && bun run check:ts",
32
31
  "check:fix": "bun run check:biome:fix && bun run check:ts",
33
32
  "check:biome": "biome check",
34
33
  "check:biome:fix": "biome check --write",
35
34
  "check:ts": "tsc --noEmit",
36
- "check:webarchitect": "webarchitect tool-ts",
37
- "test": "vitest run",
38
- "test:watch": "vitest",
39
- "test:coverage": "vitest run --coverage"
40
- },
41
- "devDependencies": {
42
- "@biomejs/biome": "2.4.5",
43
- "@canonical/biome-config": "^0.17.0",
44
- "@canonical/typescript-config": "^0.17.0",
45
- "@canonical/webarchitect": "^0.17.0",
46
- "@types/bun": "^1.3.8",
47
- "@types/ejs": "^3.1.5",
48
- "@types/node": "^24.10.13",
49
- "@types/omelette": "^0.4.5",
50
- "@types/react": "^19.2.13",
51
- "ink-testing-library": "^4.0.0",
52
- "typescript": "^5.9.3",
53
- "vitest": "^4.0.18"
35
+ "test": "vitest run --passWithNoTests",
36
+ "test:watch": "vitest"
54
37
  },
55
38
  "dependencies": {
39
+ "@canonical/cli-core": "^0.20.0",
40
+ "@canonical/summon-core": "^0.20.0",
41
+ "@canonical/task": "^0.20.0",
56
42
  "chalk": "^5.6.2",
57
43
  "commander": "^14.0.3",
58
- "ejs": "^4.0.1",
59
- "ink": "^6.7.0",
44
+ "ink": "^6.8.0",
60
45
  "ink-select-input": "^6.2.0",
61
46
  "ink-spinner": "^5.0.0",
62
47
  "ink-text-input": "^6.0.0",
63
48
  "omelette": "^0.4.17",
64
49
  "react": "^19.2.4"
65
50
  },
66
- "gitHead": "7797c6d0bc70e440c183e8a3f2b33c6d4f03e234"
51
+ "devDependencies": {
52
+ "@biomejs/biome": "2.4.6",
53
+ "@canonical/biome-config": "^0.20.0",
54
+ "@canonical/typescript-config": "^0.20.0",
55
+ "@types/bun": "^1.3.10",
56
+ "@types/node": "^24.12.0",
57
+ "@types/omelette": "^0.4.5",
58
+ "@types/react": "^19.2.14",
59
+ "ink-testing-library": "^4.0.0",
60
+ "typescript": "^5.9.3",
61
+ "vitest": "^4.0.18"
62
+ },
63
+ "gitHead": "1aee634b278922f2aa1cfe2a11d3b14e64280905"
67
64
  }
package/src/bin.tsx ADDED
@@ -0,0 +1,199 @@
1
+ #!/usr/bin/env bun
2
+
3
+ /**
4
+ * Summon CLI — thin orchestrator.
5
+ *
6
+ * Wires together generator discovery, display, registration, and completion.
7
+ * All domain logic lives in the corresponding modules.
8
+ *
9
+ * @note Impure — CLI entry point.
10
+ */
11
+
12
+ import * as path from "node:path";
13
+ import {
14
+ discoverGeneratorTree,
15
+ type GeneratorNode,
16
+ } from "@canonical/summon-core";
17
+ import chalk from "chalk";
18
+ import { Command } from "commander";
19
+ import {
20
+ type CompletionNode,
21
+ handleSetupRequest,
22
+ initCompletion,
23
+ isCompletionRequest,
24
+ isSetupRequest,
25
+ } from "./completion.js";
26
+ import loadGenerator from "./discovery/loadGenerator.js";
27
+ import { printGeneratorHelp, printNode } from "./display/index.js";
28
+ import {
29
+ buildCommandBarrel,
30
+ registerFromBarrel,
31
+ } from "./registration/index.js";
32
+
33
+ // =============================================================================
34
+ // Helpers
35
+ // =============================================================================
36
+
37
+ /**
38
+ * Navigate the generator tree by path segments.
39
+ * Returns [node, remainingSegments] where node is as deep as we could go.
40
+ */
41
+ const navigateTree = (
42
+ root: GeneratorNode,
43
+ segments: string[],
44
+ ): [GeneratorNode, string[]] => {
45
+ let current = root;
46
+ let i = 0;
47
+
48
+ for (; i < segments.length; i++) {
49
+ const child = current.children.get(segments[i]);
50
+ if (!child) break;
51
+ current = child;
52
+ }
53
+
54
+ return [current, segments.slice(i)];
55
+ };
56
+
57
+ /**
58
+ * Convert GeneratorNode to CompletionNode for the completion module.
59
+ */
60
+ const toCompletionNode = (node: GeneratorNode): CompletionNode => ({
61
+ name: node.name,
62
+ indexPath: node.indexPath,
63
+ children: new Map(
64
+ [...node.children.entries()].map(([name, child]) => [
65
+ name,
66
+ toCompletionNode(child),
67
+ ]),
68
+ ),
69
+ });
70
+
71
+ /**
72
+ * Register all generator commands from the tree.
73
+ * Uses the barrel pattern: build flat list → sort by depth → register in order.
74
+ */
75
+ const registerGeneratorCommands = async (
76
+ parentCmd: Command,
77
+ node: GeneratorNode,
78
+ ): Promise<void> => {
79
+ const barrel = await buildCommandBarrel(node);
80
+ registerFromBarrel(parentCmd, barrel);
81
+ };
82
+
83
+ // =============================================================================
84
+ // Main
85
+ // =============================================================================
86
+
87
+ const program = new Command();
88
+
89
+ const main = async () => {
90
+ // Get generators path from args early (before full parse)
91
+ const generatorsIdx = process.argv.indexOf("--generators");
92
+ const gIdx = process.argv.indexOf("-g");
93
+ const generatorsPath =
94
+ generatorsIdx !== -1
95
+ ? process.argv[generatorsIdx + 1]
96
+ : gIdx !== -1
97
+ ? process.argv[gIdx + 1]
98
+ : undefined;
99
+
100
+ // Discover generators (needed for both completion and normal CLI)
101
+ const builtinDir = path.join(__dirname, "..", "generators");
102
+ const root = await discoverGeneratorTree(
103
+ generatorsPath ? { explicitPath: generatorsPath } : { builtinDir },
104
+ );
105
+
106
+ // Initialize shell completion (must happen before commander parsing)
107
+ if (isCompletionRequest() || isSetupRequest()) {
108
+ const completionTree = toCompletionNode(root);
109
+ const complete = await initCompletion(completionTree, loadGenerator);
110
+
111
+ // Handle setup/cleanup requests
112
+ if (isSetupRequest()) {
113
+ handleSetupRequest(complete);
114
+ return;
115
+ }
116
+
117
+ // For completion requests, omelette handles everything via init()
118
+ return;
119
+ }
120
+
121
+ program
122
+ .name("summon")
123
+ .description("A monadic task-centric code generator framework")
124
+ .version("0.1.0")
125
+ .option(
126
+ "-g, --generators <path>",
127
+ "Load generators ONLY from this path (for testing)",
128
+ )
129
+ .option("--setup-completion", "Install shell autocompletion")
130
+ .option("--cleanup-completion", "Remove shell autocompletion");
131
+
132
+ // If no arguments, show available topics
133
+ if (process.argv.length === 2) {
134
+ printNode(root, []);
135
+ console.log(
136
+ chalk.dim(
137
+ "Tip: Run 'summon --setup-completion' to enable TAB completion\n",
138
+ ),
139
+ );
140
+ return;
141
+ }
142
+
143
+ // Intercept --help --llm (or --help -l) for structured markdown help
144
+ const hasHelp =
145
+ process.argv.includes("--help") || process.argv.includes("-h");
146
+ const hasLlm =
147
+ process.argv.includes("--llm") ||
148
+ process.argv.includes("-l") ||
149
+ process.env.SUMMON_LLM === "1";
150
+ if (hasHelp && hasLlm) {
151
+ // Extract command path segments (skip flags and flag arguments)
152
+ const skipFlags = new Set([
153
+ "--help",
154
+ "-h",
155
+ "--llm",
156
+ "-l",
157
+ "--generators",
158
+ "-g",
159
+ "--format",
160
+ ]);
161
+ const args = process.argv.slice(2);
162
+ const segments: string[] = [];
163
+ let skipNext = false;
164
+ for (const arg of args) {
165
+ if (skipNext) {
166
+ skipNext = false;
167
+ continue;
168
+ }
169
+ if (skipFlags.has(arg)) {
170
+ if (arg === "--generators" || arg === "-g" || arg === "--format")
171
+ skipNext = true;
172
+ continue;
173
+ }
174
+ if (arg.startsWith("-")) continue;
175
+ segments.push(arg);
176
+ }
177
+
178
+ if (segments.length > 0) {
179
+ const [node] = navigateTree(root, segments);
180
+ if (node.indexPath) {
181
+ await printGeneratorHelp(node, segments, true);
182
+ return;
183
+ }
184
+ }
185
+ // Fall through to normal help if we can't find the generator
186
+ }
187
+
188
+ // Register generator commands dynamically
189
+ await registerGeneratorCommands(program, root);
190
+
191
+ // Parse and execute
192
+ program.parse();
193
+ };
194
+
195
+ // Run main
196
+ main().catch((err) => {
197
+ console.error(chalk.red("Error:"), err.message);
198
+ process.exit(1);
199
+ });
package/src/completion.ts CHANGED
@@ -11,8 +11,11 @@
11
11
 
12
12
  import * as fs from "node:fs";
13
13
  import * as path from "node:path";
14
+ import type {
15
+ GeneratorDefinition,
16
+ PromptDefinition,
17
+ } from "@canonical/summon-core";
14
18
  import omelette from "omelette";
15
- import type { GeneratorDefinition, PromptDefinition } from "./types.js";
16
19
 
17
20
  // =============================================================================
18
21
  // Types
@@ -4,17 +4,21 @@
4
4
  * Main CLI application component using React Ink.
5
5
  */
6
6
 
7
- import { Box, Text, useApp, useInput } from "ink";
8
- import { useCallback, useEffect, useState } from "react";
9
- import { dryRun } from "../dry-run.js";
10
- import type { StampConfig } from "../interpreter.js";
7
+ import { formatContentPreview } from "@canonical/cli-core";
11
8
  import type {
12
- Effect,
13
9
  GeneratorDefinition,
14
10
  PromptDefinition,
15
- Task,
16
- TaskError,
17
- } from "../types.js";
11
+ StampConfig,
12
+ } from "@canonical/summon-core";
13
+ import {
14
+ dryRun,
15
+ type Effect,
16
+ runUndo,
17
+ type Task,
18
+ type TaskError,
19
+ } from "@canonical/task";
20
+ import { Box, Text, useApp, useInput } from "ink";
21
+ import { useCallback, useEffect, useState } from "react";
18
22
  import { ExecutionProgress, type TimedEffect } from "./ExecutionProgress.js";
19
23
  import { PromptSequence } from "./PromptSequence.js";
20
24
  import { Spinner } from "./Spinner.js";
@@ -713,6 +717,52 @@ const summarizeEffects = (effects: TimedEffect[]): string => {
713
717
  return `Created ${parts.join(", ")}`;
714
718
  };
715
719
 
720
+ // =============================================================================
721
+ // File Content View - Full file content display (for Ctrl+O toggle)
722
+ // =============================================================================
723
+
724
+ /**
725
+ * Display the full content of all WriteFile/AppendFile effects.
726
+ * Used when the user toggles file content view with Ctrl+O.
727
+ */
728
+ const FileContentView = ({ effects }: { effects: Effect[] }) => {
729
+ const writeEffects = effects.filter(
730
+ (e): e is Effect & { _tag: "WriteFile" | "AppendFile" } =>
731
+ e._tag === "WriteFile" || e._tag === "AppendFile",
732
+ );
733
+
734
+ if (writeEffects.length === 0) {
735
+ return (
736
+ <Box marginBottom={1}>
737
+ <Text dimColor>No file contents to display.</Text>
738
+ </Box>
739
+ );
740
+ }
741
+
742
+ return (
743
+ <Box flexDirection="column" marginBottom={1}>
744
+ <Text bold dimColor>
745
+ File contents:
746
+ </Text>
747
+ {writeEffects.map((effect, i) => (
748
+ // biome-ignore lint/suspicious/noArrayIndexKey: path may be duplicated across effects
749
+ <Box key={`${effect.path}-${i}`} flexDirection="column" marginTop={1}>
750
+ <Text color="green" bold>
751
+ {effect.path}
752
+ </Text>
753
+ <Box marginLeft={1}>
754
+ <Text>{formatContentPreview(effect.content)}</Text>
755
+ </Box>
756
+ </Box>
757
+ ))}
758
+ </Box>
759
+ );
760
+ };
761
+
762
+ // =============================================================================
763
+ // App State and Component
764
+ // =============================================================================
765
+
716
766
  export type AppState =
717
767
  | { phase: "loading" }
718
768
  | { phase: "prompting" }
@@ -733,6 +783,8 @@ export interface AppProps {
733
783
  preview?: boolean;
734
784
  /** Whether to run in dry-run mode only */
735
785
  dryRunOnly?: boolean;
786
+ /** Whether to reverse a previously executed generator */
787
+ undo?: boolean;
736
788
  /** Whether to show debug output */
737
789
  verbose?: boolean;
738
790
  /** Pre-filled answers (for non-interactive mode) */
@@ -745,6 +797,7 @@ export const App = ({
745
797
  generator,
746
798
  preview = true,
747
799
  dryRunOnly = false,
800
+ undo = false,
748
801
  verbose = false,
749
802
  answers: prefilledAnswers,
750
803
  stamp,
@@ -756,6 +809,7 @@ export const App = ({
756
809
  const [answers, setAnswers] = useState<Record<string, unknown>>(
757
810
  prefilledAnswers ?? {},
758
811
  );
812
+ const [showFiles, setShowFiles] = useState(false);
759
813
 
760
814
  const handlePromptsComplete = useCallback(
761
815
  (promptAnswers: Record<string, unknown>) => {
@@ -764,6 +818,36 @@ export const App = ({
764
818
  // Generate the task
765
819
  const task = generator.generate(promptAnswers);
766
820
 
821
+ // Undo mode: run undo directly
822
+ if (undo) {
823
+ (async () => {
824
+ try {
825
+ const result = await runUndo(task);
826
+ setState({
827
+ phase: "complete",
828
+ effects: [],
829
+ duration: 0,
830
+ });
831
+ if (result.undoCount === 0) {
832
+ setState({
833
+ phase: "error",
834
+ error: { code: "NOTHING_TO_UNDO", message: "Nothing to undo." },
835
+ });
836
+ }
837
+ } catch (err) {
838
+ setState({
839
+ phase: "error",
840
+ error:
841
+ err instanceof Error
842
+ ? { code: "UNDO_ERROR", message: err.message }
843
+ : { code: "UNKNOWN_ERROR", message: String(err) },
844
+ answers: promptAnswers,
845
+ });
846
+ }
847
+ })();
848
+ return;
849
+ }
850
+
767
851
  if (dryRunOnly || preview) {
768
852
  // Run dry-run to collect effects
769
853
  try {
@@ -791,7 +875,7 @@ export const App = ({
791
875
  setState({ phase: "executing", task });
792
876
  }
793
877
  },
794
- [generator, preview, dryRunOnly],
878
+ [generator, preview, dryRunOnly, undo],
795
879
  );
796
880
 
797
881
  const handleConfirm = useCallback(() => {
@@ -826,14 +910,18 @@ export const App = ({
826
910
 
827
911
  // Handle going back from confirmation to prompting
828
912
  const handleGoBack = useCallback(() => {
913
+ setShowFiles(false);
829
914
  setState({ phase: "prompting" });
830
915
  }, []);
831
916
 
832
- // Handle confirm/cancel/back input when in confirming state
917
+ // Handle confirm/cancel/back/show-files input when in confirming state
833
918
  useInput(
834
919
  (input, key) => {
835
920
  if (state.phase === "confirming") {
836
- if (key.escape) {
921
+ // Ctrl+O toggles file content view
922
+ if (key.ctrl && input === "o") {
923
+ setShowFiles((prev) => !prev);
924
+ } else if (key.escape) {
837
925
  handleGoBack();
838
926
  } else if (key.return || input.toLowerCase() === "y") {
839
927
  // Enter or Y confirms
@@ -890,15 +978,20 @@ export const App = ({
890
978
  prompts={generator.prompts}
891
979
  answers={state.promptAnswers}
892
980
  />
893
- {/* Show effects summary table */}
894
- <EffectsSummaryTable effects={state.effects} />
895
- {/* Confirmation prompt with escape hint */}
981
+ {/* Show effects summary or file contents based on toggle */}
982
+ {showFiles ? (
983
+ <FileContentView effects={state.effects} />
984
+ ) : (
985
+ <EffectsSummaryTable effects={state.effects} />
986
+ )}
987
+ {/* Confirmation prompt with escape hint and Ctrl+O hint */}
896
988
  <Box>
897
989
  <Text color="magenta">› </Text>
898
990
  <Text bold>Proceed? </Text>
899
991
  <Text dimColor>(Y/n) </Text>
900
992
  <Text dimColor italic>
901
- esc to go back
993
+ esc to go back · ctrl+o {showFiles ? "hide" : "show"} file
994
+ contents
902
995
  </Text>
903
996
  </Box>
904
997
  </Box>
@@ -4,12 +4,16 @@
4
4
  * Displays the progress of task execution with effect-by-effect feedback.
5
5
  */
6
6
 
7
+ import { runTaskWithStamp, type StampConfig } from "@canonical/summon-core";
8
+ import {
9
+ describeEffect,
10
+ type Effect,
11
+ type Task,
12
+ type TaskError,
13
+ } from "@canonical/task";
7
14
  import { Box, Text } from "ink";
8
15
  import type React from "react";
9
16
  import { useEffect, useState } from "react";
10
- import { describeEffect } from "../effect.js";
11
- import { runTask, type StampConfig } from "../interpreter.js";
12
- import type { Effect, Task, TaskError } from "../types.js";
13
17
  import { Spinner } from "./Spinner.js";
14
18
 
15
19
  /** Effect with timing information for the completion timeline */
@@ -89,7 +93,7 @@ export const ExecutionProgress: React.FC<ExecutionProgressProps> = ({
89
93
 
90
94
  const executeWithProgress = async () => {
91
95
  try {
92
- await runTask(task, {
96
+ await runTaskWithStamp(task, {
93
97
  stamp,
94
98
  onEffectStart: (effect) => {
95
99
  // Skip showing duplicate MakeDir in spinner
@@ -4,8 +4,8 @@
4
4
  * Displays a list of files that will be created/modified.
5
5
  */
6
6
 
7
+ import type { Effect } from "@canonical/task";
7
8
  import { Box, Text } from "ink";
8
- import type { Effect } from "../types.js";
9
9
 
10
10
  export interface FileTreePreviewProps {
11
11
  /** Effects to display */
@@ -9,11 +9,11 @@
9
9
  * - Group headers
10
10
  */
11
11
 
12
+ import type { PromptDefinition } from "@canonical/summon-core";
12
13
  import { Box, Text, useInput } from "ink";
13
14
  import SelectInput from "ink-select-input";
14
15
  import TextInput from "ink-text-input";
15
16
  import { useCallback, useEffect, useState } from "react";
16
- import type { PromptDefinition } from "../types.js";
17
17
 
18
18
  export interface PromptSequenceProps {
19
19
  /** List of prompts to display */
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Load a generator definition from a file path or the in-memory cache.
3
+ *
4
+ * Cached entries are inserted by {@link discoverGeneratorTree} when it
5
+ * processes barrel exports from summon-* packages.
6
+ */
7
+
8
+ import type { GeneratorDefinition } from "@canonical/summon-core";
9
+ import { generatorCache } from "@canonical/summon-core";
10
+
11
+ /**
12
+ * Load a generator from a path or the cache.
13
+ *
14
+ * @note Impure — performs dynamic import when the generator is not cached.
15
+ */
16
+ export default async function loadGenerator(
17
+ generatorPath: string,
18
+ ): Promise<GeneratorDefinition> {
19
+ // Check if this is a cached generator from a package barrel
20
+ if (generatorPath.startsWith("cache:")) {
21
+ const cacheKey = generatorPath.slice(6);
22
+ const cached = generatorCache.get(cacheKey);
23
+ if (cached) return cached;
24
+ throw new Error(`Generator not found in cache: ${cacheKey}`);
25
+ }
26
+
27
+ const module = await import(generatorPath);
28
+ const generator = module.default ?? module.generator;
29
+
30
+ if (!generator) {
31
+ throw new Error(
32
+ `No default export or 'generator' export found in ${generatorPath}`,
33
+ );
34
+ }
35
+
36
+ return generator as GeneratorDefinition;
37
+ }
@@ -0,0 +1,2 @@
1
+ export { default as printGeneratorHelp } from "./printGeneratorHelp.js";
2
+ export { default as printNode } from "./printNode.js";