@canonical/summon 0.29.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generators/example/hello/index.d.ts +18 -0
- package/dist/generators/example/hello/index.js +104 -0
- package/dist/generators/example/hello/index.js.map +1 -0
- package/dist/generators/example/webapp/index.d.ts +22 -0
- package/dist/generators/example/webapp/index.js +374 -0
- package/dist/generators/example/webapp/index.js.map +1 -0
- package/dist/generators/init/index.d.ts +16 -0
- package/dist/generators/init/index.js +98 -0
- package/dist/generators/init/index.js.map +1 -0
- package/dist/src/bin.d.ts +10 -0
- package/dist/src/bin.js +153 -0
- package/dist/src/bin.js.map +1 -0
- package/dist/src/completion.d.ts +63 -0
- package/dist/src/completion.js +375 -0
- package/dist/src/completion.js.map +1 -0
- package/dist/src/components/App.d.ts +48 -0
- package/dist/src/components/App.js +621 -0
- package/dist/src/components/App.js.map +1 -0
- package/dist/src/components/ExecutionProgress.d.ts +27 -0
- package/dist/src/components/ExecutionProgress.js +132 -0
- package/dist/src/components/ExecutionProgress.js.map +1 -0
- package/dist/src/components/FileTreePreview.d.ts +13 -0
- package/dist/src/components/FileTreePreview.js +55 -0
- package/dist/src/components/FileTreePreview.js.map +1 -0
- package/dist/src/components/PromptSequence.d.ts +22 -0
- package/dist/src/components/PromptSequence.js +215 -0
- package/dist/src/components/PromptSequence.js.map +1 -0
- package/dist/src/components/Spinner.d.ts +12 -0
- package/dist/src/components/Spinner.js +20 -0
- package/dist/src/components/Spinner.js.map +1 -0
- package/{src/components/index.ts → dist/src/components/index.d.ts} +0 -1
- package/dist/src/components/index.js +11 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/discovery/index.js +2 -0
- package/dist/src/discovery/index.js.map +1 -0
- package/dist/src/discovery/loadGenerator.d.ts +13 -0
- package/dist/src/discovery/loadGenerator.js +29 -0
- package/dist/src/discovery/loadGenerator.js.map +1 -0
- package/dist/src/display/index.js +3 -0
- package/dist/src/display/index.js.map +1 -0
- package/dist/src/display/printGeneratorHelp.d.ts +9 -0
- package/dist/src/display/printGeneratorHelp.js +99 -0
- package/dist/src/display/printGeneratorHelp.js.map +1 -0
- package/dist/src/display/printNode.d.ts +7 -0
- package/dist/src/display/printNode.js +64 -0
- package/dist/src/display/printNode.js.map +1 -0
- package/dist/src/registration/buildCommandBarrel.d.ts +11 -0
- package/dist/src/registration/buildCommandBarrel.js +45 -0
- package/dist/src/registration/buildCommandBarrel.js.map +1 -0
- package/dist/src/registration/index.js +3 -0
- package/dist/src/registration/index.js.map +1 -0
- package/dist/src/registration/registerFromBarrel.d.ts +16 -0
- package/dist/src/registration/registerFromBarrel.js +408 -0
- package/dist/src/registration/registerFromBarrel.js.map +1 -0
- package/dist/src/registration/types.d.ts +26 -0
- package/dist/src/registration/types.js +2 -0
- package/dist/src/registration/types.js.map +1 -0
- package/dist/src/ui/index.d.ts +24 -0
- package/dist/src/ui/index.js +29 -0
- package/dist/src/ui/index.js.map +1 -0
- package/package.json +23 -15
- package/generators/application/react/index.ts +0 -4
- package/generators/domain/index.ts +0 -4
- package/generators/example/hello/index.ts +0 -126
- package/generators/example/webapp/index.ts +0 -511
- package/generators/init/index.ts +0 -119
- package/generators/route/index.ts +0 -4
- package/generators/wrapper/index.ts +0 -4
- package/src/bin.tsx +0 -199
- package/src/completion.test.ts +0 -202
- package/src/completion.ts +0 -492
- package/src/components/App.tsx +0 -1053
- package/src/components/ExecutionProgress.tsx +0 -209
- package/src/components/FileTreePreview.tsx +0 -97
- package/src/components/PromptSequence.tsx +0 -483
- package/src/components/Spinner.tsx +0 -36
- package/src/discovery/loadGenerator.ts +0 -37
- package/src/display/printGeneratorHelp.ts +0 -128
- package/src/display/printNode.ts +0 -76
- package/src/registration/buildCommandBarrel.ts +0 -57
- package/src/registration/registerFromBarrel.tsx +0 -548
- package/src/registration/types.ts +0 -28
- /package/{generators → dist/generators}/example/hello/templates/README.md.ejs +0 -0
- /package/{generators → dist/generators}/example/hello/templates/index.ts.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/ARCHITECTURE.md.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/App.tsx.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/README.md.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/app.test.ts.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/app.ts.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/feature.ts.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/index.html.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/main.tsx.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/styles.css.ejs +0 -0
- /package/{generators → dist/generators}/init/templates/generator.ts.ejs +0 -0
- /package/{generators → dist/generators}/init/templates/template-index.ts.ejs +0 -0
- /package/{generators → dist/generators}/init/templates/template-test.ts.ejs +0 -0
- /package/{src/discovery/index.ts → dist/src/discovery/index.d.ts} +0 -0
- /package/{src/display/index.ts → dist/src/display/index.d.ts} +0 -0
- /package/{src/registration/index.ts → dist/src/registration/index.d.ts} +0 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App Component
|
|
3
|
+
*
|
|
4
|
+
* Main CLI application component using React Ink.
|
|
5
|
+
*/
|
|
6
|
+
import type { GeneratorDefinition, StampConfig } from "@canonical/summon-core";
|
|
7
|
+
import { type Effect, type Task, type TaskError } from "@canonical/task";
|
|
8
|
+
import { type TimedEffect } from "./ExecutionProgress.js";
|
|
9
|
+
export type AppState = {
|
|
10
|
+
phase: "loading";
|
|
11
|
+
} | {
|
|
12
|
+
phase: "prompting";
|
|
13
|
+
} | {
|
|
14
|
+
phase: "preview";
|
|
15
|
+
effects: Effect[];
|
|
16
|
+
} | {
|
|
17
|
+
phase: "confirming";
|
|
18
|
+
effects: Effect[];
|
|
19
|
+
promptAnswers: Record<string, unknown>;
|
|
20
|
+
} | {
|
|
21
|
+
phase: "executing";
|
|
22
|
+
task: Task<void>;
|
|
23
|
+
} | {
|
|
24
|
+
phase: "complete";
|
|
25
|
+
effects: TimedEffect[];
|
|
26
|
+
duration: number;
|
|
27
|
+
} | {
|
|
28
|
+
phase: "error";
|
|
29
|
+
error: TaskError;
|
|
30
|
+
answers?: Record<string, unknown>;
|
|
31
|
+
};
|
|
32
|
+
export interface AppProps {
|
|
33
|
+
/** The generator to run */
|
|
34
|
+
generator: GeneratorDefinition;
|
|
35
|
+
/** Whether to show a preview before executing */
|
|
36
|
+
preview?: boolean;
|
|
37
|
+
/** Whether to run in dry-run mode only */
|
|
38
|
+
dryRunOnly?: boolean;
|
|
39
|
+
/** Whether to reverse a previously executed generator */
|
|
40
|
+
undo?: boolean;
|
|
41
|
+
/** Whether to show debug output */
|
|
42
|
+
verbose?: boolean;
|
|
43
|
+
/** Pre-filled answers (for non-interactive mode) */
|
|
44
|
+
answers?: Record<string, unknown>;
|
|
45
|
+
/** Stamp configuration for generated files (undefined = no stamps) */
|
|
46
|
+
stamp?: StampConfig;
|
|
47
|
+
}
|
|
48
|
+
export declare const App: ({ generator, preview, dryRunOnly, undo, verbose, answers: prefilledAnswers, stamp, }: AppProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* App Component
|
|
4
|
+
*
|
|
5
|
+
* Main CLI application component using React Ink.
|
|
6
|
+
*/
|
|
7
|
+
import { formatContentPreview } from "@canonical/cli-core";
|
|
8
|
+
import { dryRun, } from "@canonical/task";
|
|
9
|
+
import { runUndo } from "@canonical/task/node";
|
|
10
|
+
import { Box, Text, useApp, useInput } from "ink";
|
|
11
|
+
import { useCallback, useEffect, useState } from "react";
|
|
12
|
+
import { ExecutionProgress } from "./ExecutionProgress.js";
|
|
13
|
+
import { PromptSequence } from "./PromptSequence.js";
|
|
14
|
+
import { Spinner } from "./Spinner.js";
|
|
15
|
+
/**
|
|
16
|
+
* Group effects by category for display.
|
|
17
|
+
* @param effects - The effects to group
|
|
18
|
+
* @param verbose - If true, include debug logs
|
|
19
|
+
*/
|
|
20
|
+
const groupEffects = (effects, verbose = false) => {
|
|
21
|
+
const groups = {
|
|
22
|
+
files: [],
|
|
23
|
+
directories: [],
|
|
24
|
+
commands: [],
|
|
25
|
+
logs: [],
|
|
26
|
+
};
|
|
27
|
+
for (const effect of effects) {
|
|
28
|
+
switch (effect._tag) {
|
|
29
|
+
case "WriteFile":
|
|
30
|
+
case "AppendFile":
|
|
31
|
+
case "CopyFile":
|
|
32
|
+
case "CopyDirectory":
|
|
33
|
+
case "DeleteFile":
|
|
34
|
+
groups.files.push(effect);
|
|
35
|
+
break;
|
|
36
|
+
case "MakeDir":
|
|
37
|
+
case "DeleteDirectory":
|
|
38
|
+
groups.directories.push(effect);
|
|
39
|
+
break;
|
|
40
|
+
case "Exec":
|
|
41
|
+
groups.commands.push(effect);
|
|
42
|
+
break;
|
|
43
|
+
case "Log":
|
|
44
|
+
// Filter out debug logs unless verbose is enabled
|
|
45
|
+
if (effect.level !== "debug" || verbose) {
|
|
46
|
+
groups.logs.push(effect);
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
// Ignore internal effects: ReadFile, Exists, Glob, ReadContext, WriteContext, Parallel, Race
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return groups;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Get human-readable action label for an effect.
|
|
56
|
+
*/
|
|
57
|
+
const getActionLabel = (effect) => {
|
|
58
|
+
switch (effect._tag) {
|
|
59
|
+
case "WriteFile":
|
|
60
|
+
return "Created file";
|
|
61
|
+
case "AppendFile":
|
|
62
|
+
return "Appended to";
|
|
63
|
+
case "MakeDir":
|
|
64
|
+
return "Created dir";
|
|
65
|
+
case "CopyFile":
|
|
66
|
+
return "Copied file";
|
|
67
|
+
case "CopyDirectory":
|
|
68
|
+
return "Copied dir";
|
|
69
|
+
case "DeleteFile":
|
|
70
|
+
return "Deleted file";
|
|
71
|
+
case "DeleteDirectory":
|
|
72
|
+
return "Deleted dir";
|
|
73
|
+
case "Exec":
|
|
74
|
+
return "Executed";
|
|
75
|
+
case "Log":
|
|
76
|
+
switch (effect.level) {
|
|
77
|
+
case "debug":
|
|
78
|
+
return "Debug";
|
|
79
|
+
case "info":
|
|
80
|
+
return "Info";
|
|
81
|
+
case "warn":
|
|
82
|
+
return "Warning";
|
|
83
|
+
case "error":
|
|
84
|
+
return "Error";
|
|
85
|
+
default:
|
|
86
|
+
return "Log";
|
|
87
|
+
}
|
|
88
|
+
default:
|
|
89
|
+
return effect._tag;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Get color for action label based on effect type.
|
|
94
|
+
*/
|
|
95
|
+
const getActionColor = (effect) => {
|
|
96
|
+
switch (effect._tag) {
|
|
97
|
+
case "WriteFile":
|
|
98
|
+
case "MakeDir":
|
|
99
|
+
return "green";
|
|
100
|
+
case "AppendFile":
|
|
101
|
+
return "magenta";
|
|
102
|
+
case "DeleteFile":
|
|
103
|
+
case "DeleteDirectory":
|
|
104
|
+
return "red";
|
|
105
|
+
case "CopyFile":
|
|
106
|
+
case "CopyDirectory":
|
|
107
|
+
return "cyan";
|
|
108
|
+
case "Exec":
|
|
109
|
+
return "yellow";
|
|
110
|
+
case "Log":
|
|
111
|
+
switch (effect.level) {
|
|
112
|
+
case "error":
|
|
113
|
+
return "red";
|
|
114
|
+
case "warn":
|
|
115
|
+
return "yellow";
|
|
116
|
+
case "debug":
|
|
117
|
+
return undefined; // dim by default
|
|
118
|
+
default:
|
|
119
|
+
return "blue";
|
|
120
|
+
}
|
|
121
|
+
default:
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Get the payload (description) for an effect.
|
|
127
|
+
*/
|
|
128
|
+
const getEffectPayload = (effect) => {
|
|
129
|
+
switch (effect._tag) {
|
|
130
|
+
case "WriteFile":
|
|
131
|
+
return effect.path;
|
|
132
|
+
case "AppendFile":
|
|
133
|
+
return effect.path;
|
|
134
|
+
case "MakeDir":
|
|
135
|
+
return effect.path;
|
|
136
|
+
case "CopyFile":
|
|
137
|
+
return `${effect.source} → ${effect.dest}`;
|
|
138
|
+
case "CopyDirectory":
|
|
139
|
+
return `${effect.source}/ → ${effect.dest}/`;
|
|
140
|
+
case "DeleteFile":
|
|
141
|
+
case "DeleteDirectory":
|
|
142
|
+
return effect.path;
|
|
143
|
+
case "Exec":
|
|
144
|
+
return `${effect.command} ${effect.args.join(" ")}`;
|
|
145
|
+
case "Log":
|
|
146
|
+
return effect.message;
|
|
147
|
+
default:
|
|
148
|
+
return effect._tag;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
// Fixed width for action label column (padded to align payloads)
|
|
152
|
+
const ACTION_LABEL_WIDTH = 14;
|
|
153
|
+
/**
|
|
154
|
+
* Render a single effect as a tree row with action label and payload.
|
|
155
|
+
*/
|
|
156
|
+
const EffectTreeRow = ({ effect, isLast, }) => {
|
|
157
|
+
const connector = isLast ? "└─" : "├─";
|
|
158
|
+
const actionLabel = getActionLabel(effect);
|
|
159
|
+
const color = getActionColor(effect);
|
|
160
|
+
const payload = getEffectPayload(effect);
|
|
161
|
+
return (_jsxs(Box, { children: [_jsxs(Text, { dimColor: true, children: [connector, " "] }), _jsx(Text, { color: color, children: actionLabel.padEnd(ACTION_LABEL_WIDTH) }), _jsx(Text, { children: payload })] }));
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Render a section of the effect tree (e.g., Files, Directories).
|
|
165
|
+
*/
|
|
166
|
+
const EffectTreeSection = ({ title, effects, }) => {
|
|
167
|
+
if (effects.length === 0) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
return (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Text, { bold: true, dimColor: true, children: [title, ":"] }), _jsx(Box, { flexDirection: "column", marginLeft: 1, children: effects.map((effect, index) => (_jsx(EffectTreeRow, { effect: effect, isLast: index === effects.length - 1 }, `${effect._tag}:${getEffectPayload(effect)}`))) })] }));
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Render a tree view of completed effects, grouped by category.
|
|
174
|
+
*/
|
|
175
|
+
const _EffectTree = ({ effects }) => {
|
|
176
|
+
const groups = groupEffects(effects);
|
|
177
|
+
const hasAnyEffects = groups.files.length > 0 ||
|
|
178
|
+
groups.directories.length > 0 ||
|
|
179
|
+
groups.commands.length > 0 ||
|
|
180
|
+
groups.logs.length > 0;
|
|
181
|
+
if (!hasAnyEffects) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(EffectTreeSection, { title: "Files", effects: groups.files }), _jsx(EffectTreeSection, { title: "Directories", effects: groups.directories }), _jsx(EffectTreeSection, { title: "Commands", effects: groups.commands }), _jsx(EffectTreeSection, { title: "Logs", effects: groups.logs })] }));
|
|
185
|
+
};
|
|
186
|
+
// =============================================================================
|
|
187
|
+
// Effect Timeline - Chronological display with timestamps
|
|
188
|
+
// =============================================================================
|
|
189
|
+
// Width for timestamp column (e.g., "+123ms")
|
|
190
|
+
const TIMESTAMP_WIDTH = 8;
|
|
191
|
+
/**
|
|
192
|
+
* Filter effects to only show user-relevant ones (not internal effects).
|
|
193
|
+
* @param effect - The effect to check
|
|
194
|
+
* @param verbose - If true, include debug logs
|
|
195
|
+
*/
|
|
196
|
+
const isVisibleEffect = (effect, verbose = false) => {
|
|
197
|
+
switch (effect._tag) {
|
|
198
|
+
case "WriteFile":
|
|
199
|
+
case "AppendFile":
|
|
200
|
+
case "MakeDir":
|
|
201
|
+
case "CopyFile":
|
|
202
|
+
case "CopyDirectory":
|
|
203
|
+
case "DeleteFile":
|
|
204
|
+
case "DeleteDirectory":
|
|
205
|
+
case "Exec":
|
|
206
|
+
return true;
|
|
207
|
+
case "Log":
|
|
208
|
+
// Filter out debug logs unless verbose is enabled
|
|
209
|
+
if (effect.level === "debug") {
|
|
210
|
+
return verbose;
|
|
211
|
+
}
|
|
212
|
+
return true;
|
|
213
|
+
// Internal effects are not shown
|
|
214
|
+
case "ReadFile":
|
|
215
|
+
case "Exists":
|
|
216
|
+
case "Glob":
|
|
217
|
+
case "ReadContext":
|
|
218
|
+
case "WriteContext":
|
|
219
|
+
case "Prompt":
|
|
220
|
+
case "Parallel":
|
|
221
|
+
case "Race":
|
|
222
|
+
return false;
|
|
223
|
+
default:
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* Render a single timeline row with timestamp, action, and payload.
|
|
229
|
+
*/
|
|
230
|
+
const TimelineRow = ({ effect, timestamp, showTimestamp, isLast, }) => {
|
|
231
|
+
const connector = isLast ? "└─" : "├─";
|
|
232
|
+
const actionLabel = getActionLabel(effect);
|
|
233
|
+
const color = getActionColor(effect);
|
|
234
|
+
const payload = getEffectPayload(effect);
|
|
235
|
+
const timestampStr = showTimestamp
|
|
236
|
+
? `+${Math.round(timestamp)}ms`.padEnd(TIMESTAMP_WIDTH)
|
|
237
|
+
: " ".repeat(TIMESTAMP_WIDTH);
|
|
238
|
+
return (_jsxs(Box, { children: [_jsx(Text, { dimColor: true, children: timestampStr }), _jsxs(Text, { dimColor: true, children: [connector, " "] }), _jsx(Text, { color: color, children: actionLabel.padEnd(ACTION_LABEL_WIDTH) }), _jsx(Text, { children: payload })] }));
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* Render effects in chronological order with timestamps.
|
|
242
|
+
* Timestamps are only shown when they differ from the previous effect.
|
|
243
|
+
* Duplicate MakeDir effects (same path) are deduplicated.
|
|
244
|
+
*/
|
|
245
|
+
const EffectTimeline = ({ effects, verbose = false, }) => {
|
|
246
|
+
// Filter to visible effects only and deduplicate MakeDir by path
|
|
247
|
+
const seenDirPaths = new Set();
|
|
248
|
+
const visibleEffects = effects.filter((e) => {
|
|
249
|
+
if (!isVisibleEffect(e.effect, verbose))
|
|
250
|
+
return false;
|
|
251
|
+
// Deduplicate MakeDir by path (keep only first occurrence)
|
|
252
|
+
if (e.effect._tag === "MakeDir") {
|
|
253
|
+
if (seenDirPaths.has(e.effect.path))
|
|
254
|
+
return false;
|
|
255
|
+
seenDirPaths.add(e.effect.path);
|
|
256
|
+
}
|
|
257
|
+
return true;
|
|
258
|
+
});
|
|
259
|
+
if (visibleEffects.length === 0) {
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
// Track which timestamps to show (only when different from previous)
|
|
263
|
+
let lastShownTimestamp = -1;
|
|
264
|
+
return (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { bold: true, dimColor: true, children: "Timeline:" }), _jsx(Box, { flexDirection: "column", marginLeft: 1, children: visibleEffects.map((item, index) => {
|
|
265
|
+
const roundedTimestamp = Math.round(item.timestamp);
|
|
266
|
+
const showTimestamp = roundedTimestamp !== lastShownTimestamp;
|
|
267
|
+
if (showTimestamp) {
|
|
268
|
+
lastShownTimestamp = roundedTimestamp;
|
|
269
|
+
}
|
|
270
|
+
// Effects are append-only, index is stable
|
|
271
|
+
const key = `${item.timestamp}-${item.effect._tag}-${index}`;
|
|
272
|
+
return (_jsx(TimelineRow, { effect: item.effect, timestamp: item.timestamp, showTimestamp: showTimestamp, isLast: index === visibleEffects.length - 1 }, key));
|
|
273
|
+
}) })] }));
|
|
274
|
+
};
|
|
275
|
+
// =============================================================================
|
|
276
|
+
// Dry-Run Timeline - Preview without timestamps
|
|
277
|
+
// =============================================================================
|
|
278
|
+
/**
|
|
279
|
+
* Render a single dry-run row (no timestamp column).
|
|
280
|
+
*/
|
|
281
|
+
const DryRunRow = ({ effect, isLast }) => {
|
|
282
|
+
const connector = isLast ? "└─" : "├─";
|
|
283
|
+
const actionLabel = getActionLabel(effect);
|
|
284
|
+
const color = getActionColor(effect);
|
|
285
|
+
const payload = getEffectPayload(effect);
|
|
286
|
+
return (_jsxs(Box, { children: [_jsxs(Text, { dimColor: true, children: [connector, " "] }), _jsx(Text, { color: color, children: actionLabel.padEnd(ACTION_LABEL_WIDTH) }), _jsx(Text, { children: payload })] }));
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Render effects as a preview timeline (dry-run mode).
|
|
290
|
+
* Shows the same format as execution timeline but without timestamps.
|
|
291
|
+
*/
|
|
292
|
+
const DryRunTimeline = ({ effects, title = "Plan:", verbose = false, }) => {
|
|
293
|
+
// Filter to visible effects only and deduplicate MakeDir by path
|
|
294
|
+
const seenDirPaths = new Set();
|
|
295
|
+
const visibleEffects = effects.filter((e) => {
|
|
296
|
+
if (!isVisibleEffect(e, verbose))
|
|
297
|
+
return false;
|
|
298
|
+
// Deduplicate MakeDir by path (keep only first occurrence)
|
|
299
|
+
if (e._tag === "MakeDir") {
|
|
300
|
+
if (seenDirPaths.has(e.path))
|
|
301
|
+
return false;
|
|
302
|
+
seenDirPaths.add(e.path);
|
|
303
|
+
}
|
|
304
|
+
return true;
|
|
305
|
+
});
|
|
306
|
+
if (visibleEffects.length === 0) {
|
|
307
|
+
return (_jsx(Box, { children: _jsx(Text, { dimColor: true, children: "No operations planned." }) }));
|
|
308
|
+
}
|
|
309
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, dimColor: true, children: title }), _jsx(Box, { flexDirection: "column", marginLeft: 1, children: visibleEffects.map((effect, index) => {
|
|
310
|
+
const key = `${effect._tag}-${index}`;
|
|
311
|
+
return (_jsx(DryRunRow, { effect: effect, isLast: index === visibleEffects.length - 1 }, key));
|
|
312
|
+
}) })] }));
|
|
313
|
+
};
|
|
314
|
+
// =============================================================================
|
|
315
|
+
// Completed Answers Display (for confirmation phase)
|
|
316
|
+
// =============================================================================
|
|
317
|
+
/**
|
|
318
|
+
* Format answer value for display based on prompt type.
|
|
319
|
+
*/
|
|
320
|
+
const formatAnswerValue = (value, prompt) => {
|
|
321
|
+
if (value === undefined || value === null)
|
|
322
|
+
return "";
|
|
323
|
+
if (prompt.type === "confirm") {
|
|
324
|
+
return value ? "Yes" : "No";
|
|
325
|
+
}
|
|
326
|
+
if (prompt.type === "select" && prompt.choices) {
|
|
327
|
+
const choice = prompt.choices.find((c) => c.value === value);
|
|
328
|
+
return choice?.label ?? String(value);
|
|
329
|
+
}
|
|
330
|
+
if (prompt.type === "multiselect" && Array.isArray(value)) {
|
|
331
|
+
if (value.length === 0)
|
|
332
|
+
return "None";
|
|
333
|
+
if (prompt.choices) {
|
|
334
|
+
return value
|
|
335
|
+
.map((v) => prompt.choices?.find((c) => c.value === v)?.label ?? v)
|
|
336
|
+
.join(", ");
|
|
337
|
+
}
|
|
338
|
+
return value.join(", ");
|
|
339
|
+
}
|
|
340
|
+
return String(value);
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* Display all completed answers in a borderless table format for confirmation review.
|
|
344
|
+
*/
|
|
345
|
+
const CompletedAnswersTable = ({ prompts, answers, }) => {
|
|
346
|
+
// Filter to only show prompts that have answers and pass their `when` condition
|
|
347
|
+
const activePrompts = prompts.filter((prompt) => {
|
|
348
|
+
if (prompt.when && !prompt.when(answers)) {
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
return prompt.name in answers;
|
|
352
|
+
});
|
|
353
|
+
if (activePrompts.length === 0) {
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
// Calculate max width for the question column (for alignment)
|
|
357
|
+
const maxQuestionWidth = Math.max(...activePrompts.map((p) => p.message.length));
|
|
358
|
+
return (_jsx(Box, { flexDirection: "column", marginBottom: 1, children: activePrompts.map((prompt) => {
|
|
359
|
+
const value = answers[prompt.name];
|
|
360
|
+
const displayValue = formatAnswerValue(value, prompt);
|
|
361
|
+
return (_jsxs(Box, { children: [_jsx(Text, { color: "green", children: "\u2714 " }), _jsx(Text, { dimColor: true, children: prompt.message.padEnd(maxQuestionWidth) }), _jsx(Text, { dimColor: true, children: " " }), _jsx(Text, { color: "cyan", children: displayValue })] }, prompt.name));
|
|
362
|
+
}) }));
|
|
363
|
+
};
|
|
364
|
+
/**
|
|
365
|
+
* Display a summary of planned effects in a borderless table format.
|
|
366
|
+
*/
|
|
367
|
+
const EffectsSummaryTable = ({ effects }) => {
|
|
368
|
+
const files = new Set();
|
|
369
|
+
const directories = new Set();
|
|
370
|
+
const copied = new Set();
|
|
371
|
+
const deleted = new Set();
|
|
372
|
+
let commands = 0;
|
|
373
|
+
for (const effect of effects) {
|
|
374
|
+
switch (effect._tag) {
|
|
375
|
+
case "WriteFile":
|
|
376
|
+
case "AppendFile":
|
|
377
|
+
files.add(effect.path);
|
|
378
|
+
break;
|
|
379
|
+
case "MakeDir":
|
|
380
|
+
directories.add(effect.path);
|
|
381
|
+
break;
|
|
382
|
+
case "CopyFile":
|
|
383
|
+
copied.add(effect.dest);
|
|
384
|
+
break;
|
|
385
|
+
case "CopyDirectory":
|
|
386
|
+
copied.add(effect.dest);
|
|
387
|
+
break;
|
|
388
|
+
case "DeleteFile":
|
|
389
|
+
case "DeleteDirectory":
|
|
390
|
+
deleted.add(effect.path);
|
|
391
|
+
break;
|
|
392
|
+
case "Exec":
|
|
393
|
+
commands++;
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
// Build rows for non-zero counts
|
|
398
|
+
const rows = [];
|
|
399
|
+
if (files.size > 0) {
|
|
400
|
+
rows.push({
|
|
401
|
+
label: `File${files.size > 1 ? "s" : ""} to create`,
|
|
402
|
+
count: files.size,
|
|
403
|
+
color: "green",
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
if (directories.size > 0) {
|
|
407
|
+
rows.push({
|
|
408
|
+
label: `Director${directories.size > 1 ? "ies" : "y"} to create`,
|
|
409
|
+
count: directories.size,
|
|
410
|
+
color: "green",
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
if (copied.size > 0) {
|
|
414
|
+
rows.push({
|
|
415
|
+
label: `Item${copied.size > 1 ? "s" : ""} to copy`,
|
|
416
|
+
count: copied.size,
|
|
417
|
+
color: "cyan",
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
if (deleted.size > 0) {
|
|
421
|
+
rows.push({
|
|
422
|
+
label: `Item${deleted.size > 1 ? "s" : ""} to delete`,
|
|
423
|
+
count: deleted.size,
|
|
424
|
+
color: "red",
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
if (commands > 0) {
|
|
428
|
+
rows.push({
|
|
429
|
+
label: `Command${commands > 1 ? "s" : ""} to run`,
|
|
430
|
+
count: commands,
|
|
431
|
+
color: "yellow",
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
if (rows.length === 0) {
|
|
435
|
+
return (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { dimColor: true, children: "No operations planned." }) }));
|
|
436
|
+
}
|
|
437
|
+
// Calculate max label width for alignment
|
|
438
|
+
const maxLabelWidth = Math.max(...rows.map((r) => r.label.length));
|
|
439
|
+
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(maxLabelWidth), " "] }), _jsx(Text, { color: row.color, children: row.count })] }, row.label)))] }));
|
|
440
|
+
};
|
|
441
|
+
/**
|
|
442
|
+
* Summarize effects into a human-readable string.
|
|
443
|
+
* Deduplicates paths to avoid counting the same directory multiple times.
|
|
444
|
+
*/
|
|
445
|
+
const summarizeEffects = (effects) => {
|
|
446
|
+
const files = new Set();
|
|
447
|
+
const directories = new Set();
|
|
448
|
+
const copied = new Set();
|
|
449
|
+
const deleted = new Set();
|
|
450
|
+
let commands = 0;
|
|
451
|
+
for (const { effect } of effects) {
|
|
452
|
+
switch (effect._tag) {
|
|
453
|
+
case "WriteFile":
|
|
454
|
+
files.add(effect.path);
|
|
455
|
+
break;
|
|
456
|
+
case "MakeDir":
|
|
457
|
+
directories.add(effect.path);
|
|
458
|
+
break;
|
|
459
|
+
case "CopyFile":
|
|
460
|
+
copied.add(effect.dest);
|
|
461
|
+
break;
|
|
462
|
+
case "DeleteFile":
|
|
463
|
+
case "DeleteDirectory":
|
|
464
|
+
deleted.add(effect.path);
|
|
465
|
+
break;
|
|
466
|
+
case "Exec":
|
|
467
|
+
commands++;
|
|
468
|
+
break;
|
|
469
|
+
// Log effects are not counted in summary
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
const parts = [];
|
|
473
|
+
if (files.size > 0) {
|
|
474
|
+
parts.push(`${files.size} file${files.size > 1 ? "s" : ""}`);
|
|
475
|
+
}
|
|
476
|
+
if (directories.size > 0) {
|
|
477
|
+
parts.push(`${directories.size} director${directories.size > 1 ? "ies" : "y"}`);
|
|
478
|
+
}
|
|
479
|
+
if (copied.size > 0) {
|
|
480
|
+
parts.push(`${copied.size} copied`);
|
|
481
|
+
}
|
|
482
|
+
if (deleted.size > 0) {
|
|
483
|
+
parts.push(`${deleted.size} deleted`);
|
|
484
|
+
}
|
|
485
|
+
if (commands > 0) {
|
|
486
|
+
parts.push(`${commands} command${commands > 1 ? "s" : ""}`);
|
|
487
|
+
}
|
|
488
|
+
if (parts.length === 0) {
|
|
489
|
+
return "No changes made";
|
|
490
|
+
}
|
|
491
|
+
return `Created ${parts.join(", ")}`;
|
|
492
|
+
};
|
|
493
|
+
// =============================================================================
|
|
494
|
+
// File Content View - Full file content display (for Ctrl+O toggle)
|
|
495
|
+
// =============================================================================
|
|
496
|
+
/**
|
|
497
|
+
* Display the full content of all WriteFile/AppendFile effects.
|
|
498
|
+
* Used when the user toggles file content view with Ctrl+O.
|
|
499
|
+
*/
|
|
500
|
+
const FileContentView = ({ effects }) => {
|
|
501
|
+
const writeEffects = effects.filter((e) => e._tag === "WriteFile" || e._tag === "AppendFile");
|
|
502
|
+
if (writeEffects.length === 0) {
|
|
503
|
+
return (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { dimColor: true, children: "No file contents to display." }) }));
|
|
504
|
+
}
|
|
505
|
+
return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { bold: true, dimColor: true, children: "File contents:" }), writeEffects.map((effect, i) => (
|
|
506
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: path may be duplicated across effects
|
|
507
|
+
_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { color: "green", bold: true, children: effect.path }), _jsx(Box, { marginLeft: 1, children: _jsx(Text, { children: formatContentPreview(effect.content) }) })] }, `${effect.path}-${i}`)))] }));
|
|
508
|
+
};
|
|
509
|
+
export const App = ({ generator, preview = true, dryRunOnly = false, undo = false, verbose = false, answers: prefilledAnswers, stamp, }) => {
|
|
510
|
+
const { exit } = useApp();
|
|
511
|
+
const [state, setState] = useState(prefilledAnswers ? { phase: "loading" } : { phase: "prompting" });
|
|
512
|
+
const [answers, setAnswers] = useState(prefilledAnswers ?? {});
|
|
513
|
+
const [showFiles, setShowFiles] = useState(false);
|
|
514
|
+
const handlePromptsComplete = useCallback((promptAnswers) => {
|
|
515
|
+
setAnswers(promptAnswers);
|
|
516
|
+
// Generate the task
|
|
517
|
+
const task = generator.generate(promptAnswers);
|
|
518
|
+
// Undo mode: run undo directly
|
|
519
|
+
if (undo) {
|
|
520
|
+
(async () => {
|
|
521
|
+
try {
|
|
522
|
+
const result = await runUndo(task);
|
|
523
|
+
setState({
|
|
524
|
+
phase: "complete",
|
|
525
|
+
effects: [],
|
|
526
|
+
duration: 0,
|
|
527
|
+
});
|
|
528
|
+
if (result.undoCount === 0) {
|
|
529
|
+
setState({
|
|
530
|
+
phase: "error",
|
|
531
|
+
error: { code: "NOTHING_TO_UNDO", message: "Nothing to undo." },
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
catch (err) {
|
|
536
|
+
setState({
|
|
537
|
+
phase: "error",
|
|
538
|
+
error: err instanceof Error
|
|
539
|
+
? { code: "UNDO_ERROR", message: err.message }
|
|
540
|
+
: { code: "UNKNOWN_ERROR", message: String(err) },
|
|
541
|
+
answers: promptAnswers,
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
})();
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
if (dryRunOnly || preview) {
|
|
548
|
+
// Run dry-run to collect effects
|
|
549
|
+
try {
|
|
550
|
+
const result = dryRun(task);
|
|
551
|
+
if (dryRunOnly) {
|
|
552
|
+
setState({ phase: "preview", effects: result.effects });
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
setState({
|
|
556
|
+
phase: "confirming",
|
|
557
|
+
effects: result.effects,
|
|
558
|
+
promptAnswers,
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
catch (err) {
|
|
563
|
+
setState({
|
|
564
|
+
phase: "error",
|
|
565
|
+
error: err instanceof Error
|
|
566
|
+
? { code: "DRY_RUN_ERROR", message: err.message }
|
|
567
|
+
: { code: "UNKNOWN_ERROR", message: String(err) },
|
|
568
|
+
answers: promptAnswers,
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
setState({ phase: "executing", task });
|
|
574
|
+
}
|
|
575
|
+
}, [generator, preview, dryRunOnly, undo]);
|
|
576
|
+
const handleConfirm = useCallback(() => {
|
|
577
|
+
const task = generator.generate(answers);
|
|
578
|
+
setState({ phase: "executing", task });
|
|
579
|
+
}, [generator, answers]);
|
|
580
|
+
const handleCancel = useCallback(() => {
|
|
581
|
+
exit();
|
|
582
|
+
}, [exit]);
|
|
583
|
+
const handleExecutionComplete = useCallback((effects, duration) => {
|
|
584
|
+
setState({ phase: "complete", effects, duration });
|
|
585
|
+
}, []);
|
|
586
|
+
const handleExecutionError = useCallback((error) => {
|
|
587
|
+
setState({ phase: "error", error, answers });
|
|
588
|
+
}, [answers]);
|
|
589
|
+
// Handle pre-filled answers
|
|
590
|
+
useEffect(() => {
|
|
591
|
+
if (prefilledAnswers && state.phase === "loading") {
|
|
592
|
+
handlePromptsComplete(prefilledAnswers);
|
|
593
|
+
}
|
|
594
|
+
}, [prefilledAnswers, state.phase, handlePromptsComplete]);
|
|
595
|
+
// Handle going back from confirmation to prompting
|
|
596
|
+
const handleGoBack = useCallback(() => {
|
|
597
|
+
setShowFiles(false);
|
|
598
|
+
setState({ phase: "prompting" });
|
|
599
|
+
}, []);
|
|
600
|
+
// Handle confirm/cancel/back/show-files input when in confirming state
|
|
601
|
+
useInput((input, key) => {
|
|
602
|
+
if (state.phase === "confirming") {
|
|
603
|
+
// Ctrl+O toggles file content view
|
|
604
|
+
if (key.ctrl && input === "o") {
|
|
605
|
+
setShowFiles((prev) => !prev);
|
|
606
|
+
}
|
|
607
|
+
else if (key.escape) {
|
|
608
|
+
handleGoBack();
|
|
609
|
+
}
|
|
610
|
+
else if (key.return || input.toLowerCase() === "y") {
|
|
611
|
+
// Enter or Y confirms
|
|
612
|
+
handleConfirm();
|
|
613
|
+
}
|
|
614
|
+
else if (input.toLowerCase() === "n") {
|
|
615
|
+
handleCancel();
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}, { isActive: state.phase === "confirming" });
|
|
619
|
+
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] })] }), _jsx(Text, { dimColor: true, children: generator.meta.description }), _jsx(Box, { marginBottom: 1 }), state.phase === "loading" && _jsx(Spinner, { label: "Loading..." }), state.phase === "prompting" && (_jsx(PromptSequence, { prompts: generator.prompts, onComplete: handlePromptsComplete, onCancel: handleCancel, initialAnswers: answers })), state.phase === "preview" && (_jsxs(Box, { flexDirection: "column", children: [_jsx(DryRunTimeline, { effects: state.effects, title: "Plan (dry-run):", verbose: verbose }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "Dry-run complete. No files were modified." }) })] })), state.phase === "confirming" && (_jsxs(Box, { flexDirection: "column", children: [_jsx(CompletedAnswersTable, { prompts: generator.prompts, answers: state.promptAnswers }), showFiles ? (_jsx(FileContentView, { effects: state.effects })) : (_jsx(EffectsSummaryTable, { effects: state.effects })), _jsxs(Box, { children: [_jsx(Text, { color: "magenta", children: "\u203A " }), _jsx(Text, { bold: true, children: "Proceed? " }), _jsx(Text, { dimColor: true, children: "(Y/n) " }), _jsxs(Text, { dimColor: true, italic: true, children: ["esc to go back \u00B7 ctrl+o ", showFiles ? "hide" : "show", " file contents"] })] })] })), state.phase === "executing" && (_jsx(ExecutionProgress, { task: state.task, onComplete: handleExecutionComplete, onError: handleExecutionError, stamp: stamp })), state.phase === "complete" && (_jsxs(Box, { flexDirection: "column", children: [_jsx(Box, { children: _jsx(Text, { color: "green", children: "\u2713 Generation complete!" }) }), _jsx(EffectTimeline, { effects: state.effects, verbose: verbose }), _jsx(Box, { marginTop: 1, children: _jsxs(Text, { dimColor: true, children: [summarizeEffects(state.effects), " in ", state.duration.toFixed(0), "ms"] }) })] })), state.phase === "error" && (_jsxs(Box, { flexDirection: "column", children: [_jsx(Box, { children: _jsxs(Text, { color: "red", children: ["\u2717 Error: ", state.error.message] }) }), state.error.code && (_jsx(Box, { marginTop: 1, children: _jsxs(Text, { dimColor: true, children: ["Code: ", state.error.code] }) })), state.answers && Object.keys(state.answers).length > 0 && (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { dimColor: true, bold: true, children: "Arguments:" }), _jsx(Box, { flexDirection: "column", marginLeft: 1, children: Object.entries(state.answers).map(([key, value]) => (_jsx(Box, { children: _jsxs(Text, { dimColor: true, children: [key, ": ", JSON.stringify(value)] }) }, key))) })] }))] }))] }));
|
|
620
|
+
};
|
|
621
|
+
//# sourceMappingURL=App.js.map
|