@canonical/summon 0.1.0 → 0.12.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/LICENSE +166 -0
- package/README.md +8 -1
- package/package.json +5 -4
- package/src/cli-format.ts +71 -0
- package/src/cli.tsx +53 -9
- package/src/completion.ts +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
|
166
|
+
|
package/README.md
CHANGED
|
@@ -47,11 +47,18 @@ Every prompt becomes a CLI flag. Boolean prompts with `default: true` use the `-
|
|
|
47
47
|
| Flag | Description |
|
|
48
48
|
|------|-------------|
|
|
49
49
|
| `-d, --dry-run` | Preview without writing files |
|
|
50
|
-
| `-y, --yes` | Skip confirmation prompts |
|
|
50
|
+
| `-y, --yes` | Skip confirmation prompts and preview |
|
|
51
51
|
| `-v, --verbose` | Show debug output |
|
|
52
|
+
| `--show-contents` | Show file contents in dry-run (useful for LLMs) |
|
|
52
53
|
| `--no-preview` | Skip the file preview |
|
|
53
54
|
| `--no-generated-stamp` | Disable generated file stamp comments |
|
|
54
55
|
|
|
56
|
+
**LLM Usage:** The `--show-contents` flag is particularly useful for AI assistants and LLM agents. When combined with `--dry-run`, it outputs the complete generated file contents, allowing the LLM to review, analyze, or use the generated code without writing to disk:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
summon component react src/components/Button --dry-run --show-contents -y
|
|
60
|
+
```
|
|
61
|
+
|
|
55
62
|
### Shell Autocompletion
|
|
56
63
|
|
|
57
64
|
Summon supports TAB completion for Bash, Zsh, and Fish shells. Completions are **dynamic** - they automatically detect newly installed generator packages without needing to re-run setup.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canonical/summon",
|
|
3
3
|
"description": "A monadic task-centric code generator framework with React Ink CLI.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "src/index.ts",
|
|
7
7
|
"types": "src/index.ts",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@biomejs/biome": "2.3.11",
|
|
43
|
-
"@canonical/biome-config": "^0.
|
|
44
|
-
"@canonical/typescript-config-base": "^0.
|
|
43
|
+
"@canonical/biome-config": "^0.12.0",
|
|
44
|
+
"@canonical/typescript-config-base": "^0.12.0",
|
|
45
45
|
"@types/ejs": "^3.1.5",
|
|
46
46
|
"@types/omelette": "^0.4.5",
|
|
47
47
|
"@types/react": "^19.0.0",
|
|
@@ -60,5 +60,6 @@
|
|
|
60
60
|
"ink-text-input": "^6.0.0",
|
|
61
61
|
"omelette": "^0.4.17",
|
|
62
62
|
"react": "^19.0.0"
|
|
63
|
-
}
|
|
63
|
+
},
|
|
64
|
+
"gitHead": "0b491caff8f797fef4ba4b7f5514a7c5b915a481"
|
|
64
65
|
}
|
package/src/cli-format.ts
CHANGED
|
@@ -163,3 +163,74 @@ export const formatEffectLine = (effect: Effect, isLast: boolean): string => {
|
|
|
163
163
|
|
|
164
164
|
return `${chalk.dim(connector)} ${colorFn(paddedLabel)}${payload}`;
|
|
165
165
|
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Maximum number of lines to show in content preview.
|
|
169
|
+
*/
|
|
170
|
+
const MAX_PREVIEW_LINES = 50;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Maximum width for content lines (will truncate).
|
|
174
|
+
*/
|
|
175
|
+
const MAX_LINE_WIDTH = 120;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Format file content for preview display.
|
|
179
|
+
* Shows line numbers and truncates long content.
|
|
180
|
+
*
|
|
181
|
+
* @param content - The file content to format
|
|
182
|
+
* @param maxLines - Maximum number of lines to show (default: MAX_PREVIEW_LINES)
|
|
183
|
+
*/
|
|
184
|
+
export const formatContentPreview = (
|
|
185
|
+
content: string,
|
|
186
|
+
maxLines: number = MAX_PREVIEW_LINES,
|
|
187
|
+
): string => {
|
|
188
|
+
const lines = content.split("\n");
|
|
189
|
+
const totalLines = lines.length;
|
|
190
|
+
const showLines = lines.slice(0, maxLines);
|
|
191
|
+
const lineNumWidth = String(Math.min(totalLines, maxLines)).length;
|
|
192
|
+
|
|
193
|
+
const formatted = showLines.map((line, i) => {
|
|
194
|
+
const lineNum = String(i + 1).padStart(lineNumWidth, " ");
|
|
195
|
+
const truncatedLine =
|
|
196
|
+
line.length > MAX_LINE_WIDTH
|
|
197
|
+
? `${line.slice(0, MAX_LINE_WIDTH - 3)}...`
|
|
198
|
+
: line;
|
|
199
|
+
return `${chalk.dim(`${lineNum} │`)} ${truncatedLine}`;
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
if (totalLines > maxLines) {
|
|
203
|
+
formatted.push(
|
|
204
|
+
chalk.dim(` ... (${totalLines - maxLines} more lines omitted)`),
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return formatted.join("\n");
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Format an effect with its content (for verbose dry-run mode).
|
|
213
|
+
* This is useful for LLM agents that need to see generated file contents.
|
|
214
|
+
*
|
|
215
|
+
* @param effect - The effect to format
|
|
216
|
+
* @param isLast - Whether this is the last effect in the list
|
|
217
|
+
*/
|
|
218
|
+
export const formatEffectWithContent = (
|
|
219
|
+
effect: Effect,
|
|
220
|
+
isLast: boolean,
|
|
221
|
+
): string => {
|
|
222
|
+
const baseLine = formatEffectLine(effect, isLast);
|
|
223
|
+
|
|
224
|
+
// Only show content for WriteFile and AppendFile effects
|
|
225
|
+
if (effect._tag === "WriteFile" || effect._tag === "AppendFile") {
|
|
226
|
+
const indent = isLast ? " " : "│ ";
|
|
227
|
+
const contentPreview = formatContentPreview(effect.content);
|
|
228
|
+
const indentedContent = contentPreview
|
|
229
|
+
.split("\n")
|
|
230
|
+
.map((line) => `${chalk.dim(indent)}${line}`)
|
|
231
|
+
.join("\n");
|
|
232
|
+
return `${baseLine}\n${indentedContent}`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return baseLine;
|
|
236
|
+
};
|
package/src/cli.tsx
CHANGED
|
@@ -888,10 +888,18 @@ const configureGroupedHelp = (
|
|
|
888
888
|
output += "\nGlobal Options:\n";
|
|
889
889
|
output += formatItem("-d, --dry-run", "Preview without writing files");
|
|
890
890
|
output += "\n";
|
|
891
|
-
output += formatItem(
|
|
891
|
+
output += formatItem(
|
|
892
|
+
"-y, --yes",
|
|
893
|
+
"Skip confirmation prompts and preview",
|
|
894
|
+
);
|
|
892
895
|
output += "\n";
|
|
893
896
|
output += formatItem("-v, --verbose", "Show debug output");
|
|
894
897
|
output += "\n";
|
|
898
|
+
output += formatItem(
|
|
899
|
+
"--show-contents",
|
|
900
|
+
"Show file contents in dry-run (useful for LLMs)",
|
|
901
|
+
);
|
|
902
|
+
output += "\n";
|
|
895
903
|
output += formatItem("--no-preview", "Skip the file preview");
|
|
896
904
|
output += "\n";
|
|
897
905
|
output += formatItem(
|
|
@@ -899,6 +907,11 @@ const configureGroupedHelp = (
|
|
|
899
907
|
"Disable generated file stamp comments",
|
|
900
908
|
);
|
|
901
909
|
output += "\n";
|
|
910
|
+
output += formatItem(
|
|
911
|
+
"-l, --llm",
|
|
912
|
+
"LLM mode: combines --dry-run --show-contents --yes",
|
|
913
|
+
);
|
|
914
|
+
output += "\n";
|
|
902
915
|
output += formatItem("-h, --help", "display help for command");
|
|
903
916
|
output += "\n";
|
|
904
917
|
|
|
@@ -1066,12 +1079,17 @@ const registerFromBarrel = (rootCmd: Command, barrel: CommandEntry[]): void => {
|
|
|
1066
1079
|
.command(commandSpec)
|
|
1067
1080
|
.description(entry.generator.meta.description)
|
|
1068
1081
|
.option("-d, --dry-run", "Preview without writing files")
|
|
1069
|
-
.option("-y, --yes", "Skip confirmation prompts")
|
|
1082
|
+
.option("-y, --yes", "Skip confirmation prompts and preview")
|
|
1070
1083
|
.option("-v, --verbose", "Show debug output")
|
|
1084
|
+
.option(
|
|
1085
|
+
"--show-contents",
|
|
1086
|
+
"Show file contents in dry-run (useful for LLMs)",
|
|
1087
|
+
)
|
|
1071
1088
|
.option("--no-preview", "Skip the file preview")
|
|
1089
|
+
.option("--no-generated-stamp", "Disable generated file stamp comments")
|
|
1072
1090
|
.option(
|
|
1073
|
-
"--
|
|
1074
|
-
"
|
|
1091
|
+
"-l, --llm",
|
|
1092
|
+
"LLM mode: combines --dry-run --show-contents --yes",
|
|
1075
1093
|
);
|
|
1076
1094
|
|
|
1077
1095
|
// Set custom usage to show positional arg before [options]
|
|
@@ -1128,6 +1146,13 @@ const configureGeneratorCommand = (
|
|
|
1128
1146
|
actualOptions = (positionalArg as Record<string, unknown>) ?? {};
|
|
1129
1147
|
}
|
|
1130
1148
|
|
|
1149
|
+
// Expand --llm flag into its component flags
|
|
1150
|
+
if (actualOptions.llm === true) {
|
|
1151
|
+
actualOptions.dryRun = true;
|
|
1152
|
+
actualOptions.showContents = true;
|
|
1153
|
+
actualOptions.yes = true;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1131
1156
|
// Extract only explicitly provided CLI answers (not defaults)
|
|
1132
1157
|
const cliAnswers = extractAnswers(actualOptions, generator.prompts);
|
|
1133
1158
|
|
|
@@ -1164,11 +1189,11 @@ const configureGeneratorCommand = (
|
|
|
1164
1189
|
if (hasAllAnswers && actualOptions.dryRun && !isTTY) {
|
|
1165
1190
|
// Batch dry-run mode (non-interactive)
|
|
1166
1191
|
const { dryRun } = await import("./dry-run.js");
|
|
1167
|
-
const { isVisibleEffect, formatEffectLine } =
|
|
1168
|
-
"./cli-format.js"
|
|
1169
|
-
);
|
|
1192
|
+
const { isVisibleEffect, formatEffectLine, formatEffectWithContent } =
|
|
1193
|
+
await import("./cli-format.js");
|
|
1170
1194
|
|
|
1171
1195
|
const verbose = actualOptions.verbose === true;
|
|
1196
|
+
const showContents = actualOptions.showContents === true;
|
|
1172
1197
|
|
|
1173
1198
|
console.log();
|
|
1174
1199
|
console.log(chalk.bold.magenta(generator.meta.name));
|
|
@@ -1192,11 +1217,25 @@ const configureGeneratorCommand = (
|
|
|
1192
1217
|
console.log(chalk.dim.bold("Plan:"));
|
|
1193
1218
|
visibleEffects.forEach((effect, index) => {
|
|
1194
1219
|
const isLast = index === visibleEffects.length - 1;
|
|
1195
|
-
|
|
1220
|
+
// Use content preview when --show-contents is enabled
|
|
1221
|
+
if (showContents) {
|
|
1222
|
+
console.log(formatEffectWithContent(effect, isLast));
|
|
1223
|
+
} else {
|
|
1224
|
+
console.log(formatEffectLine(effect, isLast));
|
|
1225
|
+
}
|
|
1196
1226
|
});
|
|
1197
1227
|
|
|
1198
1228
|
console.log();
|
|
1199
1229
|
console.log(chalk.dim("Dry-run complete. No files were modified."));
|
|
1230
|
+
|
|
1231
|
+
// Note about --show-contents if not already using it
|
|
1232
|
+
if (!showContents) {
|
|
1233
|
+
console.log(
|
|
1234
|
+
chalk.dim(
|
|
1235
|
+
"Tip: Use --show-contents to see generated file contents",
|
|
1236
|
+
),
|
|
1237
|
+
);
|
|
1238
|
+
}
|
|
1200
1239
|
} else {
|
|
1201
1240
|
// Interactive mode
|
|
1202
1241
|
// Only pass answers if:
|
|
@@ -1208,10 +1247,15 @@ const configureGeneratorCommand = (
|
|
|
1208
1247
|
? answersWithDefaults
|
|
1209
1248
|
: undefined;
|
|
1210
1249
|
|
|
1250
|
+
// When --yes is used, automatically skip preview (implies --no-preview)
|
|
1251
|
+
const shouldShowPreview = skipPrompts
|
|
1252
|
+
? false
|
|
1253
|
+
: (actualOptions.preview as boolean);
|
|
1254
|
+
|
|
1211
1255
|
const { waitUntilExit } = render(
|
|
1212
1256
|
<App
|
|
1213
1257
|
generator={generator}
|
|
1214
|
-
preview={
|
|
1258
|
+
preview={shouldShowPreview}
|
|
1215
1259
|
dryRunOnly={actualOptions.dryRun as boolean}
|
|
1216
1260
|
verbose={actualOptions.verbose as boolean}
|
|
1217
1261
|
answers={passedAnswers}
|