@canonical/summon-core 0.31.0 → 0.33.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 (109) hide show
  1. package/dist/esm/execute/GeneratorResult.js +13 -0
  2. package/dist/esm/execute/GeneratorResult.js.map +1 -0
  3. package/dist/esm/execute/collectAnswers.js +92 -0
  4. package/dist/esm/execute/collectAnswers.js.map +1 -0
  5. package/dist/esm/execute/execute.js +73 -0
  6. package/dist/esm/execute/execute.js.map +1 -0
  7. package/dist/esm/execute/index.js +4 -0
  8. package/dist/esm/execute/index.js.map +1 -0
  9. package/dist/esm/execute/validateAnswers.js +47 -0
  10. package/dist/esm/execute/validateAnswers.js.map +1 -0
  11. package/dist/esm/format/effects.js +581 -0
  12. package/dist/esm/format/effects.js.map +1 -0
  13. package/dist/esm/format/index.js +2 -0
  14. package/dist/esm/format/index.js.map +1 -0
  15. package/dist/esm/index.js +8 -1
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/prompt/answerPromptWithDefaults.js +26 -0
  18. package/dist/esm/prompt/answerPromptWithDefaults.js.map +1 -0
  19. package/dist/esm/prompt/autoPrompt.js +50 -0
  20. package/dist/esm/prompt/autoPrompt.js.map +1 -0
  21. package/dist/esm/prompt/index.js +12 -0
  22. package/dist/esm/prompt/index.js.map +1 -0
  23. package/dist/esm/prompt/ink/Spinner.js +18 -0
  24. package/dist/esm/prompt/ink/Spinner.js.map +1 -0
  25. package/dist/esm/prompt/ink/Wizard.js +116 -0
  26. package/dist/esm/prompt/ink/Wizard.js.map +1 -0
  27. package/dist/esm/prompt/ink/answerValidation.js +32 -0
  28. package/dist/esm/prompt/ink/answerValidation.js.map +1 -0
  29. package/dist/esm/prompt/ink/mount.js +41 -0
  30. package/dist/esm/prompt/ink/mount.js.map +1 -0
  31. package/dist/esm/prompt/ink/progressWindow.js +143 -0
  32. package/dist/esm/prompt/ink/progressWindow.js.map +1 -0
  33. package/dist/esm/prompt/ink/prompts.js +219 -0
  34. package/dist/esm/prompt/ink/prompts.js.map +1 -0
  35. package/dist/esm/prompt/ink/selectChoices.js +28 -0
  36. package/dist/esm/prompt/ink/selectChoices.js.map +1 -0
  37. package/dist/esm/prompt/ink/session.js +176 -0
  38. package/dist/esm/prompt/ink/session.js.map +1 -0
  39. package/dist/esm/prompt/inkPrompt.js +55 -0
  40. package/dist/esm/prompt/inkPrompt.js.map +1 -0
  41. package/dist/esm/prompt/mcpPrompt.js +29 -0
  42. package/dist/esm/prompt/mcpPrompt.js.map +1 -0
  43. package/dist/esm/prompt/types.js +12 -0
  44. package/dist/esm/prompt/types.js.map +1 -0
  45. package/dist/esm/run/index.js +2 -0
  46. package/dist/esm/run/index.js.map +1 -0
  47. package/dist/esm/run/runGeneratorTask.js +63 -0
  48. package/dist/esm/run/runGeneratorTask.js.map +1 -0
  49. package/dist/esm/stamp/createGeneratorStamp.js +19 -0
  50. package/dist/esm/stamp/createGeneratorStamp.js.map +1 -0
  51. package/dist/esm/stamp/createStampOnEffectStart.js +23 -0
  52. package/dist/esm/stamp/createStampOnEffectStart.js.map +1 -0
  53. package/dist/esm/stamp/index.js +2 -0
  54. package/dist/esm/stamp/index.js.map +1 -1
  55. package/dist/types/execute/GeneratorResult.d.ts +23 -0
  56. package/dist/types/execute/GeneratorResult.d.ts.map +1 -0
  57. package/dist/types/execute/collectAnswers.d.ts +52 -0
  58. package/dist/types/execute/collectAnswers.d.ts.map +1 -0
  59. package/dist/types/execute/execute.d.ts +57 -0
  60. package/dist/types/execute/execute.d.ts.map +1 -0
  61. package/dist/types/execute/index.d.ts +6 -0
  62. package/dist/types/execute/index.d.ts.map +1 -0
  63. package/dist/types/execute/validateAnswers.d.ts +23 -0
  64. package/dist/types/execute/validateAnswers.d.ts.map +1 -0
  65. package/dist/types/format/effects.d.ts +86 -0
  66. package/dist/types/format/effects.d.ts.map +1 -0
  67. package/dist/types/format/index.d.ts +2 -0
  68. package/dist/types/format/index.d.ts.map +1 -0
  69. package/dist/types/index.d.ts +8 -1
  70. package/dist/types/index.d.ts.map +1 -1
  71. package/dist/types/prompt/answerPromptWithDefaults.d.ts +17 -0
  72. package/dist/types/prompt/answerPromptWithDefaults.d.ts.map +1 -0
  73. package/dist/types/prompt/autoPrompt.d.ts +35 -0
  74. package/dist/types/prompt/autoPrompt.d.ts.map +1 -0
  75. package/dist/types/prompt/index.d.ts +14 -0
  76. package/dist/types/prompt/index.d.ts.map +1 -0
  77. package/dist/types/prompt/ink/Spinner.d.ts +11 -0
  78. package/dist/types/prompt/ink/Spinner.d.ts.map +1 -0
  79. package/dist/types/prompt/ink/Wizard.d.ts +14 -0
  80. package/dist/types/prompt/ink/Wizard.d.ts.map +1 -0
  81. package/dist/types/prompt/ink/answerValidation.d.ts +31 -0
  82. package/dist/types/prompt/ink/answerValidation.d.ts.map +1 -0
  83. package/dist/types/prompt/ink/mount.d.ts +31 -0
  84. package/dist/types/prompt/ink/mount.d.ts.map +1 -0
  85. package/dist/types/prompt/ink/progressWindow.d.ts +48 -0
  86. package/dist/types/prompt/ink/progressWindow.d.ts.map +1 -0
  87. package/dist/types/prompt/ink/prompts.d.ts +35 -0
  88. package/dist/types/prompt/ink/prompts.d.ts.map +1 -0
  89. package/dist/types/prompt/ink/selectChoices.d.ts +42 -0
  90. package/dist/types/prompt/ink/selectChoices.d.ts.map +1 -0
  91. package/dist/types/prompt/ink/session.d.ts +103 -0
  92. package/dist/types/prompt/ink/session.d.ts.map +1 -0
  93. package/dist/types/prompt/inkPrompt.d.ts +64 -0
  94. package/dist/types/prompt/inkPrompt.d.ts.map +1 -0
  95. package/dist/types/prompt/mcpPrompt.d.ts +20 -0
  96. package/dist/types/prompt/mcpPrompt.d.ts.map +1 -0
  97. package/dist/types/prompt/types.d.ts +23 -0
  98. package/dist/types/prompt/types.d.ts.map +1 -0
  99. package/dist/types/run/index.d.ts +3 -0
  100. package/dist/types/run/index.d.ts.map +1 -0
  101. package/dist/types/run/runGeneratorTask.d.ts +51 -0
  102. package/dist/types/run/runGeneratorTask.d.ts.map +1 -0
  103. package/dist/types/stamp/createGeneratorStamp.d.ts +16 -0
  104. package/dist/types/stamp/createGeneratorStamp.d.ts.map +1 -0
  105. package/dist/types/stamp/createStampOnEffectStart.d.ts +17 -0
  106. package/dist/types/stamp/createStampOnEffectStart.d.ts.map +1 -0
  107. package/dist/types/stamp/index.d.ts +2 -0
  108. package/dist/types/stamp/index.d.ts.map +1 -1
  109. package/package.json +17 -10
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The non-interactive prompt strategy: flags/args + defaults, with a structured
3
+ * failure for a missing required answer.
4
+ *
5
+ * This is the evolved `answerPromptWithDefaults` the seam calls for `--yes`, a
6
+ * non-interactive terminal, or CI. Because {@link collectAnswers} only emits a
7
+ * `Prompt` effect for a prompt NOT already provided, this handler is reached
8
+ * only for unprovided answers: it returns the prompt's declared default, or —
9
+ * when a prompt has no default (a required, unprovided answer) — rejects with a
10
+ * structured `MISSING_REQUIRED_ANSWER` task error rather than silently
11
+ * substituting a bare `""` / first-choice value (the old exit-3 safety).
12
+ */
13
+ import { TaskExecutionError } from "@canonical/task";
14
+ /** The task-error code raised when a required answer is neither provided nor defaulted. */
15
+ export const MISSING_REQUIRED_ANSWER = "MISSING_REQUIRED_ANSWER";
16
+ /** Convert a camelCase answer key to its kebab-case CLI flag form. */
17
+ const toKebab = (name) => name.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
18
+ /**
19
+ * Build the structured error for a required, unprovided answer.
20
+ *
21
+ * @param effect - The `Prompt` effect whose answer is missing.
22
+ * @param noun - How to name the missing input in the message ("flag" / "argument").
23
+ * @returns A {@link TaskExecutionError} the interpreter routes as a task failure.
24
+ */
25
+ export function missingRequiredError(effect, noun = "flag") {
26
+ const { name, message } = effect.question;
27
+ return new TaskExecutionError({
28
+ code: MISSING_REQUIRED_ANSWER,
29
+ message: `Missing required ${noun} --${toKebab(name)} (${message}). Provide it non-interactively, or run interactively to be prompted.`,
30
+ context: { answer: name },
31
+ });
32
+ }
33
+ /**
34
+ * A prompt handler that resolves each unprovided prompt to its default, or
35
+ * fails with {@link missingRequiredError} when no default exists.
36
+ *
37
+ * @param _params - The already-provided answers (accepted for symmetry with the
38
+ * other strategies; {@link collectAnswers} has already filtered these out, so
39
+ * this handler only ever sees unprovided prompts).
40
+ * @returns The non-interactive {@link PromptHandler}.
41
+ */
42
+ export default function autoPrompt(_params = {}) {
43
+ return (effect) => {
44
+ const q = effect.question;
45
+ if (q.default !== undefined)
46
+ return Promise.resolve(q.default);
47
+ return Promise.reject(missingRequiredError(effect, "flag"));
48
+ };
49
+ }
50
+ //# sourceMappingURL=autoPrompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autoPrompt.js","sourceRoot":"","sources":["../../../src/prompt/autoPrompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAGrD,2FAA2F;AAC3F,MAAM,CAAC,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AAEjE,sEAAsE;AACtE,MAAM,OAAO,GAAG,CAAC,IAAY,EAAU,EAAE,CACvC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAoB,EACpB,OAA4B,MAAM;IAElC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC;IAC1C,OAAO,IAAI,kBAAkB,CAAC;QAC5B,IAAI,EAAE,uBAAuB;QAC7B,OAAO,EAAE,oBAAoB,IAAI,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,uEAAuE;QACvI,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;KAC1B,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,UAA6C,EAAE;IAE/C,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC;QAC1B,IAAI,CAAC,CAAC,OAAO,KAAK,SAAS;YAAE,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAC/D,OAAO,OAAO,CAAC,MAAM,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC9D,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The prompt-strategy barrel. STATIC exports only — no JSX, no static
3
+ * `import` of `ink`/`react`. The Ink strategy ({@link inkPrompt}) reaches its
4
+ * React UI ONLY through `await import("./ink/mount.js")` on first draw, so
5
+ * importing this barrel (or summon-core's root) never loads React. The
6
+ * lazy-React guard test enforces exactly this boundary.
7
+ */
8
+ export { default as answerPromptWithDefaults } from "./answerPromptWithDefaults.js";
9
+ export { default as autoPrompt, MISSING_REQUIRED_ANSWER, missingRequiredError, } from "./autoPrompt.js";
10
+ export { default as inkPrompt } from "./inkPrompt.js";
11
+ export { default as mcpPrompt } from "./mcpPrompt.js";
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/prompt/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,EACL,OAAO,IAAI,UAAU,EACrB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * A minimal braille loading spinner. Under `prompt/ink/**` — dynamic-only.
4
+ */
5
+ import { Box, Text } from "ink";
6
+ import { useEffect, useState } from "react";
7
+ const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
8
+ export const Spinner = ({ color = "cyan", label }) => {
9
+ const [frameIndex, setFrameIndex] = useState(0);
10
+ useEffect(() => {
11
+ const timer = setInterval(() => {
12
+ setFrameIndex((prev) => (prev + 1) % frames.length);
13
+ }, 80);
14
+ return () => clearInterval(timer);
15
+ }, []);
16
+ return (_jsxs(Box, { children: [_jsx(Text, { color: color, children: frames[frameIndex] }), label && _jsxs(Text, { children: [" ", label] })] }));
17
+ };
18
+ //# sourceMappingURL=Spinner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Spinner.js","sourceRoot":"","sources":["../../../../src/prompt/ink/Spinner.tsx"],"names":[],"mappings":";AAAA;;GAEG;AAEH,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AASlE,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAgB,EAAE,EAAE;IACjE,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEhD,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;YAC7B,aAAa,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;QACtD,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,MAAC,GAAG,eACF,KAAC,IAAI,IAAC,KAAK,EAAE,KAAK,YAAG,MAAM,CAAC,UAAU,CAAC,GAAQ,EAC9C,KAAK,IAAI,MAAC,IAAI,oBAAG,KAAK,IAAQ,IAC3B,CACP,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,116 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * The root Ink view — a pure projection of {@link SessionController} state.
4
+ * Under `prompt/ink/**` — dynamic-only. Ported from the summon wizard's App,
5
+ * but it OWNS no execution: the seam runs the task; this view only renders the
6
+ * prompt sequence, the preview/confirm gate, live progress, and the outcome.
7
+ */
8
+ import { describeEffect } from "@canonical/task";
9
+ import { Box, Static, Text, useInput } from "ink";
10
+ import { useEffect, useState } from "react";
11
+ import { truncateMiddle } from "./progressWindow.js";
12
+ import { AnswersTable, ProgressHeader, QuestionView } from "./prompts.js";
13
+ import { Spinner } from "./Spinner.js";
14
+ /** A compact summary of the effects the confirm gate is about to apply. */
15
+ const EffectsSummary = ({ effects }) => {
16
+ const files = new Set();
17
+ const dirs = new Set();
18
+ const links = new Set();
19
+ let commands = 0;
20
+ for (const effect of effects) {
21
+ switch (effect._tag) {
22
+ case "WriteFile":
23
+ case "AppendFile":
24
+ files.add(effect.path);
25
+ break;
26
+ case "MakeDir":
27
+ dirs.add(effect.path);
28
+ break;
29
+ case "Symlink":
30
+ links.add(effect.path);
31
+ break;
32
+ case "Exec":
33
+ commands++;
34
+ break;
35
+ }
36
+ }
37
+ const rows = [];
38
+ if (files.size > 0)
39
+ rows.push({
40
+ label: `File${files.size > 1 ? "s" : ""} to create`,
41
+ count: files.size,
42
+ });
43
+ if (dirs.size > 0)
44
+ rows.push({
45
+ label: `Director${dirs.size > 1 ? "ies" : "y"} to create`,
46
+ count: dirs.size,
47
+ });
48
+ if (links.size > 0)
49
+ rows.push({
50
+ label: `Symlink${links.size > 1 ? "s" : ""} to create`,
51
+ count: links.size,
52
+ });
53
+ if (commands > 0)
54
+ rows.push({
55
+ label: `Command${commands > 1 ? "s" : ""} to run`,
56
+ count: commands,
57
+ });
58
+ if (rows.length === 0) {
59
+ return (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { dimColor: true, children: "No operations planned." }) }));
60
+ }
61
+ const width = Math.max(...rows.map((r) => r.label.length));
62
+ return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { bold: true, dimColor: true, children: "Operations:" }), rows.map((row) => (_jsxs(Box, { children: [_jsxs(Text, { dimColor: true, children: [" ", row.label.padEnd(width), " "] }), _jsx(Text, { color: "green", children: row.count })] }, row.label)))] }));
63
+ };
64
+ /**
65
+ * Live progress: the file effects completed so far.
66
+ *
67
+ * The completed lines render under Ink's `<Static>` (C7): each is printed ONCE,
68
+ * to the scrollback above the live region, instead of the whole history being
69
+ * re-rendered on every new effect — the flicker/scroll a big scaffold otherwise
70
+ * caused. Each line is middle-truncated so a long path stays on ONE row. Only
71
+ * the trailing spinner remains in the live (re-rendered) frame.
72
+ */
73
+ const Progress = ({ state }) => {
74
+ const shown = state.progress.filter((t) => t.effect._tag !== "Log" &&
75
+ t.effect._tag !== "Exists" &&
76
+ t.effect._tag !== "ReadFile" &&
77
+ t.effect._tag !== "ReadContext" &&
78
+ t.effect._tag !== "WriteContext" &&
79
+ t.effect._tag !== "Prompt" &&
80
+ t.effect._tag !== "Parallel" &&
81
+ t.effect._tag !== "Race");
82
+ return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Static, { items: shown, children: (t, i) => (
83
+ // biome-ignore lint/suspicious/noArrayIndexKey: append-only progress; a path may repeat
84
+ _jsxs(Text, { children: [_jsx(Text, { color: "green", children: "\u2713" }), " ", truncateMiddle(describeEffect(t.effect))] }, `${t.effect._tag}-${i}`)) }), state.phase === "executing" && (_jsx(Box, { children: _jsx(Spinner, { color: "blue", label: "Generating\u2026" }) }))] }));
85
+ };
86
+ /** The wizard view — subscribes to the controller and renders its phase. */
87
+ export const Wizard = ({ controller }) => {
88
+ const [state, setState] = useState(controller.getSnapshot());
89
+ useEffect(() => controller.subscribe(() => setState(controller.getSnapshot())), [controller]);
90
+ // Ctrl-C cancels from any phase (Ink is mounted with exitOnCtrlC:false, so the
91
+ // key reaches here). Cancelling rejects the pending prompt, failing the task.
92
+ useInput((input, key) => {
93
+ if (key.ctrl && input === "c")
94
+ controller.cancel();
95
+ });
96
+ useInput((input, key) => {
97
+ if (state.phase !== "confirming")
98
+ return;
99
+ if (key.return || input.toLowerCase() === "y")
100
+ controller.submitConfirm(true);
101
+ else if (input.toLowerCase() === "n" || key.escape)
102
+ controller.submitConfirm(false);
103
+ }, { isActive: state.phase === "confirming" });
104
+ const { generator } = state;
105
+ return (_jsxs(Box, { flexDirection: "column", padding: 1, children: [_jsxs(Box, { marginBottom: 1, children: [_jsx(Text, { bold: true, color: "magenta", children: generator.meta.name }), _jsxs(Text, { dimColor: true, children: [" v", generator.meta.version] })] }), state.phase === "idle" && _jsx(Spinner, { label: "Loading\u2026" }), state.phase === "prompting" && state.activeQuestion && (_jsxs(Box, { flexDirection: "column", children: [_jsx(ProgressHeader, { current: state.step, total: state.total }), _jsx(AnswersTable, { prompts: generator.prompts, answers: state.answers }), _jsx(QuestionView, { question: state.activeQuestion.question, validate: generator.prompts.find((p) => p.name === state.activeQuestion?.question.name)?.validate, onSubmit: (value) => controller.submitAnswer(value), onCancel: () => controller.cancel() })] })), state.phase === "confirming" && (_jsxs(Box, { flexDirection: "column", children: [_jsx(AnswersTable, { prompts: generator.prompts, answers: state.answers }), _jsx(EffectsSummary, { effects: state.previewEffects }), _jsxs(Box, { children: [_jsx(Text, { color: "magenta", children: "\u203A " }), _jsx(Text, { bold: true, children: "Proceed? " }), _jsx(Text, { dimColor: true, children: "(Y/n)" })] })] })), (state.phase === "executing" || state.phase === "complete") && (_jsx(Progress, { state: state })), state.phase === "complete" && (_jsx(Box, { marginTop: 1, children: _jsx(Text, { color: "green", children: "\u2713 Generation complete!" }) })), state.phase === "cancelled" &&
106
+ (() => {
107
+ // Truthful (H2): a Ctrl-C mid-execution may have written some files
108
+ // before the abort landed, so count the completed write-like effects
109
+ // the session already tracked rather than always claiming none.
110
+ const written = state.progress.filter((t) => ["WriteFile", "AppendFile", "Symlink", "CopyFile"].includes(t.effect._tag)).length;
111
+ return (_jsxs(Text, { color: "yellow", children: ["\u2717 Cancelled.", " ", written === 0
112
+ ? "No files were written."
113
+ : `${written} file(s) were written.`] }));
114
+ })(), state.phase === "error" && (_jsxs(Text, { color: "red", children: ["\u2717 Error: ", state.error?.message] }))] }));
115
+ };
116
+ //# sourceMappingURL=Wizard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Wizard.js","sourceRoot":"","sources":["../../../../src/prompt/ink/Wizard.tsx"],"names":[],"mappings":";AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAe,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,2EAA2E;AAC3E,MAAM,cAAc,GAAG,CAAC,EAAE,OAAO,EAAkC,EAAE,EAAE;IACrE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU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f,KAAC,IAAI,IAAC,KAAK,EAAC,OAAO,4CAA8B,GAC7C,CACP,EAEA,KAAK,CAAC,KAAK,KAAK,WAAW;gBAC1B,CAAC,GAAG,EAAE;oBACJ,oEAAoE;oBACpE,qEAAqE;oBACrE,gEAAgE;oBAChE,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAC1C,CAAC,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,QAAQ,CACzD,CAAC,CAAC,MAAM,CAAC,IAAI,CACd,CACF,CAAC,MAAM,CAAC;oBACT,OAAO,CACL,MAAC,IAAI,IAAC,KAAK,EAAC,QAAQ,kCACL,GAAG,EACf,OAAO,KAAK,CAAC;gCACZ,CAAC,CAAC,wBAAwB;gCAC1B,CAAC,CAAC,GAAG,OAAO,wBAAwB,IACjC,CACR,CAAC;gBACJ,CAAC,CAAC,EAAE,EAEL,KAAK,CAAC,KAAK,KAAK,OAAO,IAAI,CAC1B,MAAC,IAAI,IAAC,KAAK,EAAC,KAAK,+BAAW,KAAK,CAAC,KAAK,EAAE,OAAO,IAAQ,CACzD,IACG,CACP,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Pure evaluation of a prompt's `validate` for the Ink widgets, so
3
+ * select/multiselect/confirm can run it INLINE with recovery (C6/M5) exactly as
4
+ * the text widget already does — instead of only catching a bad answer
5
+ * post-collection in `validateAnswers`, which fails the whole run with no chance
6
+ * to correct it in place. This is also the mechanism a multiselect uses to
7
+ * enforce a minimum selection (C-lo3): a validator that rejects an empty array.
8
+ *
9
+ * A `.ts` sibling of the JSX widgets so the accept/reject decision is unit
10
+ * testable without an Ink render.
11
+ */
12
+ /** The fallback message when a validator rejects without its own string. */
13
+ export const DEFAULT_INVALID_MESSAGE = "Invalid input";
14
+ /**
15
+ * Run a prompt's optional `validate` against a candidate answer.
16
+ *
17
+ * @param validate - The prompt's validator, or `undefined` (always accepts).
18
+ * @param value - The candidate answer to check.
19
+ * @returns A {@link ValidationResult} — `ok` when accepted, else the message.
20
+ */
21
+ export function evaluateValidation(validate, value) {
22
+ if (!validate)
23
+ return { ok: true };
24
+ const verdict = validate(value);
25
+ if (verdict === true)
26
+ return { ok: true };
27
+ return {
28
+ ok: false,
29
+ message: typeof verdict === "string" ? verdict : DEFAULT_INVALID_MESSAGE,
30
+ };
31
+ }
32
+ //# sourceMappingURL=answerValidation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"answerValidation.js","sourceRoot":"","sources":["../../../../src/prompt/ink/answerValidation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAUH,4EAA4E;AAC5E,MAAM,CAAC,MAAM,uBAAuB,GAAG,eAAe,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAAgC,EAChC,KAAc;IAEd,IAAI,CAAC,QAAQ;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IACnC,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChC,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IAC1C,OAAO;QACL,EAAE,EAAE,KAAK;QACT,OAAO,EAAE,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,uBAAuB;KACzE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { render } from "ink";
3
+ import { SessionController } from "./session.js";
4
+ import { Wizard } from "./Wizard.js";
5
+ /**
6
+ * Mount the wizard for a generator and return its seam handle.
7
+ *
8
+ * @param generator - The generator being run.
9
+ * @param options - The abort signal.
10
+ * @returns The {@link MountedSession} the prompt handler and effect callbacks drive.
11
+ * @note Impure — renders an Ink app to stderr and reads stdin.
12
+ */
13
+ export function mountPromptSession(generator, options = {}) {
14
+ // Thread the run's cancel (H2): an in-Ink Ctrl-C/escape calls
15
+ // controller.cancel(), which invokes this to abort the interpreter.
16
+ const controller = new SessionController(generator, options.onCancel);
17
+ const instance = render(_jsx(Wizard, { controller: controller }), {
18
+ stdout: process.stderr,
19
+ stdin: process.stdin,
20
+ exitOnCtrlC: false,
21
+ });
22
+ const { signal } = options;
23
+ const onAbort = () => controller.cancel();
24
+ signal?.addEventListener("abort", onAbort);
25
+ let disposed = false;
26
+ return {
27
+ answerPrompt: (effect) => controller.request(effect),
28
+ reportEffectStart: (effect) => controller.reportEffectStart(effect),
29
+ reportEffectComplete: (effect, duration) => controller.reportEffectComplete(effect, duration),
30
+ reportLog: (level, message) => controller.reportLog(level, message),
31
+ dispose: () => {
32
+ if (disposed)
33
+ return;
34
+ disposed = true;
35
+ controller.markComplete();
36
+ signal?.removeEventListener("abort", onAbort);
37
+ instance.unmount();
38
+ },
39
+ };
40
+ }
41
+ //# sourceMappingURL=mount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount.js","sourceRoot":"","sources":["../../../../src/prompt/ink/mount.tsx"],"names":[],"mappings":";AAWA,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAI7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAWrC;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAChC,SAA8B,EAC9B,UAA4B,EAAE;IAE9B,8DAA8D;IAC9D,oEAAoE;IACpE,MAAM,UAAU,GAAG,IAAI,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACtE,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAC,MAAM,IAAC,UAAU,EAAE,UAAU,GAAI,EAAE;QAC1D,MAAM,EAAE,OAAO,CAAC,MAAuC;QACvD,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,WAAW,EAAE,KAAK;KACnB,CAAC,CAAC;IAEH,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,OAAO,GAAG,GAAS,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;IAChD,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAE3C,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,OAAO;QACL,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC;QACpD,iBAAiB,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC;QACnE,oBAAoB,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CACzC,UAAU,CAAC,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC;QACnD,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC;QACnE,OAAO,EAAE,GAAG,EAAE;YACZ,IAAI,QAAQ;gBAAE,OAAO;YACrB,QAAQ,GAAG,IAAI,CAAC;YAChB,UAAU,CAAC,YAAY,EAAE,CAAC;YAC1B,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC9C,QAAQ,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Pure helpers for the wizard's live progress view (C7/M7): keep each completed
3
+ * effect on ONE line by middle-truncating long paths, so a big application
4
+ * scaffold's progress does not wrap and jitter. Paired with rendering the
5
+ * completed lines under Ink's `<Static>` in `Wizard.tsx` — which is what
6
+ * actually stops the full-history re-render on every effect (the flicker/scroll
7
+ * root) — this keeps the live frame to a bounded, single-line-per-effect window.
8
+ *
9
+ * Truncation is DISPLAY-WIDTH aware, not UTF-16-code-unit aware. It iterates
10
+ * whole Unicode code points (so a supplementary-plane character is never sliced
11
+ * between its surrogate halves into a lone-surrogate `�`), and it counts East
12
+ * Asian Wide / Fullwidth / emoji code points as two terminal columns — because
13
+ * Ink lays the line out by cell width, so a code-unit cap alone would still let
14
+ * wide glyphs overflow and wrap. {@link measureDisplayWidth} is the shared
15
+ * width approximation both concerns rely on.
16
+ *
17
+ * A `.ts` sibling of the JSX view so the string math is unit testable.
18
+ */
19
+ /** Max display columns a single progress line may occupy before it is truncated. */
20
+ export const MAX_PROGRESS_LINE = 72;
21
+ /** The single-column marker inserted where a truncated middle was elided. */
22
+ export const TRUNCATION_MARKER = "…";
23
+ /**
24
+ * East Asian Wide / Fullwidth / emoji code-point ranges, each an inclusive
25
+ * `[low, high]` pair. A code point inside any range is rendered by terminals in
26
+ * two columns rather than one. This is a compact approximation of a full
27
+ * `wcwidth` table — enough to keep a path on one row (the wizard's only need),
28
+ * covering the CJK blocks, Hangul, kana, fullwidth forms, and the common emoji
29
+ * planes — not an exhaustive Unicode width oracle.
30
+ */
31
+ const WIDE_RANGES = [
32
+ [0x1100, 0x115f], // Hangul Jamo
33
+ [0x2e80, 0x303e], // CJK radicals, Kangxi, CJK symbols & punctuation
34
+ [0x3041, 0x33ff], // Hiragana, Katakana, CJK compatibility
35
+ [0x3400, 0x4dbf], // CJK Unified Ideographs Extension A
36
+ [0x4e00, 0x9fff], // CJK Unified Ideographs
37
+ [0xa000, 0xa4cf], // Yi syllables and radicals
38
+ [0xac00, 0xd7a3], // Hangul syllables
39
+ [0xf900, 0xfaff], // CJK compatibility ideographs
40
+ [0xfe30, 0xfe4f], // CJK compatibility forms
41
+ [0xff00, 0xff60], // Fullwidth forms
42
+ [0xffe0, 0xffe6], // Fullwidth signs
43
+ [0x1f300, 0x1faff], // Miscellaneous symbols & pictographs, emoji
44
+ [0x20000, 0x3fffd], // CJK Unified Ideographs Extension B and beyond
45
+ ];
46
+ /**
47
+ * Report whether a Unicode code point renders as two terminal columns.
48
+ *
49
+ * @param codePoint - A Unicode scalar value (as from `String.codePointAt`).
50
+ * @returns `true` for East Asian Wide / Fullwidth / emoji code points.
51
+ */
52
+ function isWideCodePoint(codePoint) {
53
+ for (const [low, high] of WIDE_RANGES) {
54
+ if (codePoint >= low && codePoint <= high)
55
+ return true;
56
+ }
57
+ return false;
58
+ }
59
+ /**
60
+ * Decode the Unicode scalar value a single iterator character represents.
61
+ *
62
+ * A string iterator yields one code point per step as a one- or two-code-unit
63
+ * string; a two-unit string is a surrogate pair, recombined here into its
64
+ * scalar value. `charCodeAt` (which returns a number, never `undefined`) reads
65
+ * the code units, so no non-null assertion is needed.
66
+ *
67
+ * @param char - One code-point string, as produced by iterating a string.
68
+ * @returns The scalar Unicode code point value.
69
+ */
70
+ function decodeCodePoint(char) {
71
+ const high = char.charCodeAt(0);
72
+ if (char.length < 2)
73
+ return high;
74
+ const low = char.charCodeAt(1);
75
+ return (high - 0xd800) * 0x400 + (low - 0xdc00) + 0x10000;
76
+ }
77
+ /**
78
+ * Measure the terminal-column width of a string, summing per-code-point widths:
79
+ * one column for most code points, two for East Asian Wide / emoji ones (see
80
+ * {@link isWideCodePoint}). Iterating code points rather than UTF-16 code units
81
+ * means a surrogate pair counts once, as the single glyph it renders to.
82
+ *
83
+ * @param text - The string to measure.
84
+ * @returns The approximate number of terminal columns `text` occupies.
85
+ */
86
+ export function measureDisplayWidth(text) {
87
+ let width = 0;
88
+ for (const char of text) {
89
+ width += isWideCodePoint(decodeCodePoint(char)) ? 2 : 1;
90
+ }
91
+ return width;
92
+ }
93
+ /**
94
+ * Concatenate the longest run of code points taken from `chars` in order whose
95
+ * combined display width fits `budget`, stopping before the first code point
96
+ * that would overflow it — so a surrogate pair or a wide glyph is never
97
+ * partially included.
98
+ *
99
+ * @param chars - Code points (each a whole-character string) to draw from.
100
+ * @param budget - The display-width budget, in terminal columns.
101
+ * @returns The width-bounded prefix of `chars`, joined back into a string.
102
+ */
103
+ function collectWithinWidth(chars, budget) {
104
+ let width = 0;
105
+ let out = "";
106
+ for (const char of chars) {
107
+ const next = width + measureDisplayWidth(char);
108
+ if (next > budget)
109
+ break;
110
+ width = next;
111
+ out += char;
112
+ }
113
+ return out;
114
+ }
115
+ /**
116
+ * Middle-truncate a progress line to `max` DISPLAY columns, preserving BOTH
117
+ * ends — a described effect's verb prefix (e.g. `Write file:`) and the tail of
118
+ * its path (the most identifying part) — and eliding the middle with
119
+ * {@link TRUNCATION_MARKER}.
120
+ *
121
+ * Width is measured and cut by {@link measureDisplayWidth}, iterating whole
122
+ * code points, so the one-row guarantee holds for multibyte and wide (CJK /
123
+ * emoji) paths and a surrogate pair is never split into a lone-surrogate `�`.
124
+ *
125
+ * @param line - The described-effect line (e.g. `Write file: a/b/c.ts (12 bytes)`).
126
+ * @param max - The width cap, in columns; defaults to {@link MAX_PROGRESS_LINE}.
127
+ * @returns The line unchanged when within the cap, else its truncated form.
128
+ */
129
+ export function truncateMiddle(line, max = MAX_PROGRESS_LINE) {
130
+ if (measureDisplayWidth(line) <= max)
131
+ return line;
132
+ const budget = Math.max(0, max - measureDisplayWidth(TRUNCATION_MARKER));
133
+ const headBudget = Math.ceil(budget / 2);
134
+ const tailBudget = Math.floor(budget / 2);
135
+ const chars = [...line];
136
+ const head = collectWithinWidth(chars, headBudget);
137
+ // The tail is collected from the reversed code points, then re-reversed back
138
+ // into reading order — keeping every code point whole throughout.
139
+ const reversedTail = collectWithinWidth([...chars].reverse(), tailBudget);
140
+ const tail = [...reversedTail].reverse().join("");
141
+ return `${head}${TRUNCATION_MARKER}${tail}`;
142
+ }
143
+ //# sourceMappingURL=progressWindow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"progressWindow.js","sourceRoot":"","sources":["../../../../src/prompt/ink/progressWindow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,oFAAoF;AACpF,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAEpC,6EAA6E;AAC7E,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