@venizia/vulcan 0.4.8 → 0.4.9-1

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 (179) hide show
  1. package/base/extensions/vulcan-guards.ts +48 -41
  2. package/base/hooks/antigravity-guards.ts +4 -3
  3. package/base/hooks/codex-guards.ts +17 -6
  4. package/base/hooks/guard-git.ts +8 -8
  5. package/base/hooks/guard-manifest.ts +5 -5
  6. package/base/hooks/guard-outside.ts +8 -8
  7. package/base/hooks/guard-package.ts +6 -6
  8. package/base/hooks/guard-remote-hosts.ts +14 -9
  9. package/base/hooks/guard-scripting.ts +6 -6
  10. package/base/hooks/guard-writes.ts +20 -11
  11. package/base/hooks/post-tool.ts +4 -3
  12. package/base/hooks/prompt-submit.ts +4 -3
  13. package/base/hooks/session-start.ts +5 -3
  14. package/base/hooks/stop.ts +4 -3
  15. package/base/hooks/subagent-start.ts +2 -2
  16. package/base/make/vulcan.mk +1 -4
  17. package/base/skills/build-a-feature/SKILL.md +1 -1
  18. package/base/skills/docs-update/SKILL.md +11 -5
  19. package/base/skills/docs-update/evals/evals.json +1 -1
  20. package/base/skills/docs-writing/SKILL.md +1 -1
  21. package/base/skills/plan-a-change/references/spec-card.md +1 -1
  22. package/base/skills/ship/SKILL.md +1 -1
  23. package/base/skills/visualize-work/SKILL.md +29 -6
  24. package/base/skills/visualize-work/references/spec.md +16 -5
  25. package/package.json +5 -6
  26. package/src/agents/atlas-block.ts +43 -43
  27. package/src/agents/codex-hooks.ts +55 -52
  28. package/src/agents/common/types.ts +1 -1
  29. package/src/agents/detect.ts +19 -16
  30. package/src/agents/exclude.ts +97 -98
  31. package/src/agents/hooks-json.ts +41 -43
  32. package/src/agents/local.ts +46 -43
  33. package/src/agents/prompt.ts +45 -42
  34. package/src/agents/render.ts +203 -201
  35. package/src/agents/resolve.ts +133 -134
  36. package/src/agents/table.ts +12 -8
  37. package/src/cli.ts +3 -1
  38. package/src/commands/add.command.ts +2 -2
  39. package/src/commands/agents.command.ts +11 -17
  40. package/src/commands/clean.command.ts +6 -6
  41. package/src/commands/doctor.command.ts +6 -4
  42. package/src/commands/help.command.ts +11 -9
  43. package/src/commands/init.command.ts +14 -8
  44. package/src/commands/preset.command.ts +2 -2
  45. package/src/commands/profile.command.ts +43 -50
  46. package/src/commands/sync.command.ts +109 -111
  47. package/src/commands/upgrade.command.ts +85 -78
  48. package/src/commands/visualize.command.ts +20 -5
  49. package/src/commands/x.command.ts +55 -50
  50. package/src/common/format.ts +23 -21
  51. package/src/common/index.ts +2 -0
  52. package/src/common/json.ts +8 -5
  53. package/src/common/layout-folder.ts +96 -111
  54. package/src/common/paths.ts +14 -12
  55. package/src/common/record.ts +7 -0
  56. package/src/common/text.ts +7 -0
  57. package/src/config/common/constants.ts +13 -1
  58. package/src/config/common/types.ts +8 -1
  59. package/src/config/loader.ts +53 -48
  60. package/src/config/packages.ts +17 -11
  61. package/src/config/schema.ts +54 -7
  62. package/src/create/add-app.ts +604 -493
  63. package/src/create/add-lib.ts +249 -242
  64. package/src/create/bunfig.ts +26 -23
  65. package/src/create/checks.ts +36 -34
  66. package/src/create/common/constants.ts +1 -0
  67. package/src/create/common/failure.ts +10 -0
  68. package/src/create/common/index.ts +2 -0
  69. package/src/create/common/preset-path.ts +11 -0
  70. package/src/create/common/types.ts +7 -2
  71. package/src/create/diff.ts +21 -23
  72. package/src/create/dockerignore.ts +26 -24
  73. package/src/create/files.ts +7 -5
  74. package/src/create/init-monorepo.ts +78 -80
  75. package/src/create/lib-preset.ts +62 -61
  76. package/src/create/manifest-json.ts +10 -4
  77. package/src/create/names.ts +217 -210
  78. package/src/create/next.ts +27 -24
  79. package/src/create/plan.ts +15 -12
  80. package/src/create/preset-diff.ts +415 -240
  81. package/src/create/preset-menu.ts +40 -34
  82. package/src/create/preset.ts +207 -194
  83. package/src/create/process.ts +80 -71
  84. package/src/create/scratch.ts +49 -48
  85. package/src/create/workspace.ts +423 -398
  86. package/src/doctor/checks.ts +1069 -998
  87. package/src/doctor/makefile.ts +17 -13
  88. package/src/doctor/runner.ts +88 -116
  89. package/src/doctor/skills.ts +97 -95
  90. package/src/doctor/tags.ts +44 -41
  91. package/src/hooks/codex-patch.ts +27 -24
  92. package/src/hooks/command-view.ts +44 -39
  93. package/src/hooks/common/constants.ts +0 -3
  94. package/src/hooks/common/types.ts +15 -1
  95. package/src/hooks/decision.ts +38 -42
  96. package/src/hooks/guard-git.ts +52 -50
  97. package/src/hooks/guard-manifest.ts +58 -55
  98. package/src/hooks/guard-outside.ts +109 -88
  99. package/src/hooks/guard-package.ts +86 -77
  100. package/src/hooks/guard-scripting.ts +20 -15
  101. package/src/hooks/guard-writes.ts +169 -111
  102. package/src/hooks/owner-reply.ts +128 -128
  103. package/src/hooks/post-tool.ts +94 -93
  104. package/src/hooks/project-guards.ts +93 -55
  105. package/src/hooks/project-tmp.ts +27 -24
  106. package/src/hooks/remote-hosts.ts +157 -149
  107. package/src/hooks/session-digest.ts +99 -95
  108. package/src/hooks/shell.ts +519 -500
  109. package/src/hooks/subagent-card.ts +11 -7
  110. package/src/hooks/trusted-scripts.ts +158 -80
  111. package/src/init/common/types.ts +1 -1
  112. package/src/init/scaffold.ts +137 -134
  113. package/src/local/clean.ts +39 -37
  114. package/src/local/format.ts +21 -17
  115. package/src/local/scan.ts +146 -140
  116. package/src/manifest/render.ts +127 -112
  117. package/src/owner/card.ts +51 -46
  118. package/src/owner/profile.ts +100 -96
  119. package/src/owner/reply-switch.ts +9 -6
  120. package/src/owner/shape.ts +72 -70
  121. package/src/owner/survey.ts +175 -164
  122. package/src/owner/view.ts +62 -59
  123. package/src/owner/violations.ts +119 -123
  124. package/src/router.ts +4 -1
  125. package/src/rules/base.ts +15 -11
  126. package/src/rules/common/types.ts +1 -1
  127. package/src/rules/parser.ts +39 -32
  128. package/src/rules/slots.ts +8 -6
  129. package/src/signals/claims.ts +30 -28
  130. package/src/signals/classify.ts +36 -33
  131. package/src/signals/loop.ts +39 -37
  132. package/src/signals/state.ts +80 -85
  133. package/src/skills/frontmatter.ts +28 -28
  134. package/src/sync/agent-files.ts +217 -199
  135. package/src/sync/agent-removal.ts +62 -68
  136. package/src/sync/atlas-block.ts +45 -43
  137. package/src/sync/base-rules.ts +32 -30
  138. package/src/sync/claude-launch.ts +74 -37
  139. package/src/sync/common/constants.ts +4 -0
  140. package/src/sync/common/index.ts +1 -0
  141. package/src/sync/common/symlink.ts +9 -0
  142. package/src/sync/common/types.ts +2 -2
  143. package/src/sync/exclude.ts +77 -69
  144. package/src/sync/local-choice.ts +50 -47
  145. package/src/sync/planner.ts +64 -68
  146. package/src/sync/prune.ts +52 -48
  147. package/src/sync/settings.ts +167 -168
  148. package/src/ui/capability.ts +12 -7
  149. package/src/ui/keyboard.ts +35 -33
  150. package/src/ui/prompt.ts +81 -77
  151. package/src/visualize/assets.ts +379 -195
  152. package/src/visualize/charts.ts +188 -176
  153. package/src/visualize/compare-css.ts +31 -0
  154. package/src/visualize/compare-render.ts +196 -0
  155. package/src/visualize/compare-schema.ts +81 -0
  156. package/src/visualize/compare-validate.ts +126 -0
  157. package/src/visualize/constants.ts +29 -3
  158. package/src/visualize/diagrams.ts +189 -174
  159. package/src/visualize/gate.ts +136 -0
  160. package/src/visualize/grid-span.ts +34 -0
  161. package/src/visualize/icons.ts +9 -4
  162. package/src/visualize/index.ts +2 -0
  163. package/src/visualize/kinds-css.ts +54 -0
  164. package/src/visualize/kinds-render.ts +698 -0
  165. package/src/visualize/kinds-schema.ts +148 -0
  166. package/src/visualize/kinds-validate.ts +186 -0
  167. package/src/visualize/labels-vi.ts +109 -0
  168. package/src/visualize/labels.ts +53 -0
  169. package/src/visualize/layout.ts +112 -92
  170. package/src/visualize/page.ts +140 -114
  171. package/src/visualize/render.ts +158 -114
  172. package/src/visualize/schema.ts +21 -1
  173. package/src/visualize/sections.ts +401 -309
  174. package/src/visualize/sources.ts +270 -0
  175. package/src/visualize/theme.ts +474 -0
  176. package/src/visualize/validate.ts +15 -5
  177. package/src/wiki/anchors.ts +39 -37
  178. package/src/wiki/command.ts +4 -4
  179. package/src/wiki/source-links.ts +49 -49
@@ -1,7 +1,7 @@
1
1
  import { readSync } from 'node:fs';
2
2
 
3
- import { layoutFolderProblem, listedFoldersNote } from '../common/layout-folder.ts';
4
- import { menusAvailable, promptSelect, promptText } from '../ui/index.ts';
3
+ import { LayoutFolder } from '../common/layout-folder.ts';
4
+ import { TerminalCapability, TerminalPrompt } from '../ui/index.ts';
5
5
  import { AppSides, CreateConstants, CreateFlags } from './common/index.ts';
6
6
  import type {
7
7
  IAskOptions,
@@ -31,60 +31,13 @@ export const SIDE_FIELDS: Record<TAppSide, INameField> = {
31
31
  /** `@acme`: what `--scope` takes, for a library and for an app. */
32
32
  export const SCOPE_PATTERN = /^@[a-z0-9][a-z0-9-]*$/;
33
33
 
34
- /**
35
- * The optional scope question of a menu: a package scope typed, or nothing for a bare name. Asked only
36
- * where menus are drawn; a plain terminal and a script give `--scope`. `null` is a cancel.
37
- */
38
- export const askScope = async (): Promise<string | undefined | null> => {
39
- const answer = await promptText({
40
- message: 'Package scope (optional, like @acme; empty for none)',
41
- validate: (value) =>
42
- value.trim() === '' || SCOPE_PATTERN.test(value.trim())
43
- ? undefined
44
- : `'${value.trim()}' is not a scope like @acme`,
45
- });
46
-
47
- return answer === null ? null : answer.trim() === '' ? undefined : answer.trim();
48
- };
49
-
50
- export const readFlag = (opts: { args: string[]; flag: string }): string | undefined => {
51
- const index = opts.args.indexOf(opts.flag);
52
-
53
- return index === -1 ? undefined : opts.args[index + 1];
54
- };
55
-
56
- /** The scope the flag names, validated: none when absent, an error that names the flag when it is not `@scope`. */
57
- export const readScope = (opts: {
58
- args: string[];
59
- }): { ok: true; scope: string | undefined } | { ok: false; error: string } => {
60
- const given = readFlag({ args: opts.args, flag: CreateFlags.SCOPE });
61
-
62
- if (given === undefined) {
63
- return { ok: true, scope: undefined };
64
- }
65
-
66
- return SCOPE_PATTERN.test(given)
67
- ? { ok: true, scope: given }
68
- : { ok: false, error: `${CreateFlags.SCOPE} '${given}' is not a scope like @acme` };
69
- };
70
-
71
34
  const isValidName = (opts: { name: string }): boolean =>
72
35
  CreateConstants.NAME_PATTERN.test(opts.name);
73
36
 
74
- /** The message a menu shows under a typed name that is not one; nothing when it is fine. */
75
- export const nameProblem = (opts: { name: string }): string | undefined =>
76
- isValidName({ name: opts.name })
77
- ? undefined
78
- : `'${opts.name}' is not a name: lowercase letters, digits and '-', starting with a letter or digit`;
79
-
80
- /** Why a value is not valid for a field: a folder path for a path field, a name for the rest. Undefined when it is valid. */
81
- export const fieldProblem = (opts: { field: INameField; value: string }): string | undefined =>
82
- opts.field.isPath === true
83
- ? layoutFolderProblem({ folder: opts.value })
84
- : nameProblem({ name: opts.value });
85
-
86
37
  const NEWLINE = 0x0a;
38
+
87
39
  const CARRIAGE_RETURN = 0x0d;
40
+
88
41
  const RETRY_PAUSE_MILLISECONDS = 5;
89
42
 
90
43
  const readFromDescriptor: TByteReader = (opts) =>
@@ -98,219 +51,273 @@ const pauseBriefly = (): void => {
98
51
  const isWouldBlock = (opts: { error: unknown }): boolean =>
99
52
  opts.error instanceof Error && 'code' in opts.error && opts.error.code === 'EAGAIN';
100
53
 
101
- /**
102
- * One line from a file descriptor, read byte by byte so nothing past the newline is consumed.
103
- * Not Bun's prompt(): it returns null for an empty line, which is not end of input. An empty line
104
- * is '' here; null is only end of input (Ctrl-D, closed stdin) with nothing read. `read` and `pause`
105
- * are replaceable so a test can drive the non-blocking retry without a real pipe.
106
- */
107
- export const readLine = (opts: {
108
- descriptor: number;
109
- read?: TByteReader;
110
- pause?: () => void;
111
- }): string | null => {
112
- const { descriptor, read = readFromDescriptor, pause = pauseBriefly } = opts;
113
- const buffer = Buffer.alloc(1);
114
- const bytes: number[] = [];
115
-
116
- for (;;) {
117
- let count = 0;
118
-
119
- try {
120
- count = read({ descriptor, buffer });
121
- } catch (error) {
122
- // A non-blocking pipe with nothing buffered yet: wait for the writer instead of failing.
123
- if (isWouldBlock({ error })) {
124
- pause();
125
- continue;
126
- }
127
-
128
- throw error;
129
- }
54
+ export class ProjectNames {
55
+ /** Why a value is not valid for a field: a folder path for a path field, a name for the rest. Undefined when it is valid. */
56
+ private static fieldProblem(opts: { field: INameField; value: string }): string | undefined {
57
+ return opts.field.isPath === true
58
+ ? LayoutFolder.layoutFolderProblem({ folder: opts.value })
59
+ : ProjectNames.nameProblem({ name: opts.value });
60
+ }
130
61
 
131
- if (count === 0) {
132
- return bytes.length === 0 ? null : Buffer.from(bytes).toString('utf8');
133
- }
62
+ private static async askUntilValid(opts: {
63
+ field: INameField;
64
+ ask: TAsk;
65
+ }): Promise<string | null> {
66
+ const { field } = opts;
67
+ const validate = (value: string): string | undefined => {
68
+ const name = value.trim() === '' ? (field.previous ?? '') : value.trim();
134
69
 
135
- const value = buffer.readUInt8(0);
70
+ if (name === '' && field.optional === true) {
71
+ return undefined;
72
+ }
136
73
 
137
- if (value === NEWLINE) {
138
- break;
139
- }
74
+ return ProjectNames.fieldProblem({ field, value: name });
75
+ };
140
76
 
141
- bytes.push(value);
142
- }
77
+ for (;;) {
78
+ const answer = await opts.ask({
79
+ question: field.question,
80
+ previous: field.previous,
81
+ choices: field.choices,
82
+ validate,
83
+ });
143
84
 
144
- if (bytes.at(-1) === CARRIAGE_RETURN) {
145
- bytes.pop();
146
- }
85
+ if (answer === null) {
86
+ return null;
87
+ }
147
88
 
148
- return Buffer.from(bytes).toString('utf8');
149
- };
89
+ const name = answer.trim() === '' ? (opts.field.previous ?? '') : answer.trim();
150
90
 
151
- /** The shown default is the user's own earlier choice, never one VULCAN made up. */
152
- export const askWithPrompt = (opts: IAskOptions): string | null => {
153
- const choices =
154
- opts.choices !== undefined && opts.choices.length > 1 ? ` [${opts.choices.join(', ')}]` : '';
91
+ if (name === '' && opts.field.optional === true) {
92
+ return '';
93
+ }
155
94
 
156
- process.stdout.write(
157
- opts.previous === undefined
158
- ? `? ${opts.question}${choices} > `
159
- : `? ${opts.question}${choices} (${opts.previous}) > `,
160
- );
95
+ const problem = ProjectNames.fieldProblem({ field, value: name });
161
96
 
162
- return readLine({ descriptor: CreateConstants.STDIN_DESCRIPTOR });
163
- };
97
+ if (problem === undefined) {
98
+ return name;
99
+ }
164
100
 
165
- const NEW_FOLDER = ':new-folder';
101
+ process.stderr.write(` ${problem}\n`);
102
+ }
103
+ }
166
104
 
167
- /** A menu, not a line: existing folders are picked, a new name is typed with its default shown. */
168
- const askWithMenus: TAsk = async (opts) => {
169
- if (opts.choices !== undefined && opts.choices.length > 0) {
170
- const picked = await promptSelect({
171
- message: opts.question,
172
- choices: [
173
- ...opts.choices.map((value) => ({ value, label: value })),
174
- { value: NEW_FOLDER, label: 'New folder...' },
175
- ],
176
- initial: opts.previous,
105
+ /**
106
+ * The optional scope question of a menu: a package scope typed, or nothing for a bare name. Asked only
107
+ * where menus are drawn; a plain terminal and a script give `--scope`. `null` is a cancel.
108
+ */
109
+ static async askScope(): Promise<string | undefined | null> {
110
+ const answer = await TerminalPrompt.promptText({
111
+ message: 'Package scope (optional, like @acme; empty for none)',
112
+ validate: (value) =>
113
+ value.trim() === '' || SCOPE_PATTERN.test(value.trim())
114
+ ? undefined
115
+ : `'${value.trim()}' is not a scope like @acme`,
177
116
  });
178
117
 
179
- if (picked !== NEW_FOLDER) {
180
- return picked;
181
- }
118
+ return answer === null ? null : answer.trim() === '' ? undefined : answer.trim();
182
119
  }
183
120
 
184
- return promptText({
185
- message: opts.question,
186
- defaultValue: opts.previous,
187
- validate: opts.validate,
188
- });
189
- };
121
+ static readFlag(opts: { args: string[]; flag: string }): string | undefined {
122
+ const index = opts.args.indexOf(opts.flag);
190
123
 
191
- /** Menus in a terminal that can draw them, the plain question everywhere else. */
192
- export const askInTerminal: TAsk = (opts) =>
193
- menusAvailable() ? askWithMenus(opts) : askWithPrompt(opts);
124
+ return index === -1 ? undefined : opts.args[index + 1];
125
+ }
194
126
 
195
- const askUntilValid = async (opts: { field: INameField; ask: TAsk }): Promise<string | null> => {
196
- const { field } = opts;
197
- const validate = (value: string): string | undefined => {
198
- const name = value.trim() === '' ? (field.previous ?? '') : value.trim();
127
+ /** The scope the flag names, validated: none when absent, an error that names the flag when it is not `@scope`. */
128
+ static readScope(opts: {
129
+ args: string[];
130
+ }): { ok: true; scope: string | undefined } | { ok: false; error: string } {
131
+ const given = ProjectNames.readFlag({ args: opts.args, flag: CreateFlags.SCOPE });
199
132
 
200
- if (name === '' && field.optional === true) {
201
- return undefined;
133
+ if (given === undefined) {
134
+ return { ok: true, scope: undefined };
202
135
  }
203
136
 
204
- return fieldProblem({ field, value: name });
205
- };
137
+ return SCOPE_PATTERN.test(given)
138
+ ? { ok: true, scope: given }
139
+ : { ok: false, error: `${CreateFlags.SCOPE} '${given}' is not a scope like @acme` };
140
+ }
206
141
 
207
- for (;;) {
208
- const answer = await opts.ask({
209
- question: field.question,
210
- previous: field.previous,
211
- choices: field.choices,
212
- validate,
213
- });
142
+ /** The message a menu shows under a typed name that is not one; nothing when it is fine. */
143
+ static nameProblem(opts: { name: string }): string | undefined {
144
+ return isValidName({ name: opts.name })
145
+ ? undefined
146
+ : `'${opts.name}' is not a name: lowercase letters, digits and '-', starting with a letter or digit`;
147
+ }
214
148
 
215
- if (answer === null) {
216
- return null;
217
- }
149
+ /**
150
+ * One line from a file descriptor, read byte by byte so nothing past the newline is consumed.
151
+ * Not Bun's prompt(): it returns null for an empty line, which is not end of input. An empty line
152
+ * is '' here; null is only end of input (Ctrl-D, closed stdin) with nothing read. `read` and `pause`
153
+ * are replaceable so a test can drive the non-blocking retry without a real pipe.
154
+ */
155
+ static readLine(opts: {
156
+ descriptor: number;
157
+ read?: TByteReader;
158
+ pause?: () => void;
159
+ }): string | null {
160
+ const { descriptor, read = readFromDescriptor, pause = pauseBriefly } = opts;
161
+ const buffer = Buffer.alloc(1);
162
+ const bytes: number[] = [];
163
+
164
+ for (;;) {
165
+ let count = 0;
166
+
167
+ try {
168
+ count = read({ descriptor, buffer });
169
+ } catch (error) {
170
+ // A non-blocking pipe with nothing buffered yet: wait for the writer instead of failing.
171
+ if (isWouldBlock({ error })) {
172
+ pause();
173
+ continue;
174
+ }
175
+
176
+ throw error;
177
+ }
218
178
 
219
- const name = answer.trim() === '' ? (opts.field.previous ?? '') : answer.trim();
179
+ if (count === 0) {
180
+ return bytes.length === 0 ? null : Buffer.from(bytes).toString('utf8');
181
+ }
220
182
 
221
- if (name === '' && opts.field.optional === true) {
222
- return '';
223
- }
183
+ const value = buffer.readUInt8(0);
184
+
185
+ if (value === NEWLINE) {
186
+ break;
187
+ }
224
188
 
225
- const problem = fieldProblem({ field, value: name });
189
+ bytes.push(value);
190
+ }
226
191
 
227
- if (problem === undefined) {
228
- return name;
192
+ if (bytes.at(-1) === CARRIAGE_RETURN) {
193
+ bytes.pop();
229
194
  }
230
195
 
231
- process.stderr.write(` ${problem}\n`);
196
+ return Buffer.from(bytes).toString('utf8');
232
197
  }
233
- };
234
198
 
235
- /** Every name from its flag; a missing one is asked in a TTY and an error otherwise. */
236
- export const resolveNames = async (opts: {
237
- fields: INameField[];
238
- args: string[];
239
- interactive: boolean;
240
- ask: TAsk;
241
- }): Promise<TNamesResult> => {
242
- const names: Record<string, string> = {};
199
+ /** The shown default is the user's own earlier choice, never one VULCAN made up. */
200
+ static askWithPrompt(opts: IAskOptions): string | null {
201
+ const choices =
202
+ opts.choices !== undefined && opts.choices.length > 1 ? ` [${opts.choices.join(', ')}]` : '';
243
203
 
244
- for (const field of opts.fields) {
245
- const flagged = readFlag({ args: opts.args, flag: field.flag });
204
+ process.stdout.write(
205
+ opts.previous === undefined
206
+ ? `? ${opts.question}${choices} > `
207
+ : `? ${opts.question}${choices} (${opts.previous}) > `,
208
+ );
246
209
 
247
- if (flagged !== undefined) {
248
- const problem = fieldProblem({ field, value: flagged });
210
+ return ProjectNames.readLine({ descriptor: CreateConstants.STDIN_DESCRIPTOR });
211
+ }
249
212
 
250
- if (problem !== undefined) {
251
- return {
252
- ok: false,
253
- error:
254
- field.isPath === true
255
- ? `${field.flag} ${problem}`
256
- : `${field.flag} '${flagged}' is not a name: lowercase letters, digits and '-'`,
257
- };
213
+ /** Every name from its flag; a missing one is asked in a TTY and an error otherwise. */
214
+ static async resolve(opts: {
215
+ fields: INameField[];
216
+ args: string[];
217
+ interactive: boolean;
218
+ ask: TAsk;
219
+ }): Promise<TNamesResult> {
220
+ const names: Record<string, string> = {};
221
+
222
+ for (const field of opts.fields) {
223
+ const flagged = ProjectNames.readFlag({ args: opts.args, flag: field.flag });
224
+
225
+ if (flagged !== undefined) {
226
+ const problem = ProjectNames.fieldProblem({ field, value: flagged });
227
+
228
+ if (problem !== undefined) {
229
+ return {
230
+ ok: false,
231
+ error:
232
+ field.isPath === true
233
+ ? `${field.flag} ${problem}`
234
+ : `${field.flag} '${flagged}' is not a name: lowercase letters, digits and '-'`,
235
+ };
236
+ }
237
+
238
+ names[field.key] = flagged;
239
+ continue;
258
240
  }
259
241
 
260
- names[field.key] = flagged;
261
- continue;
262
- }
242
+ if (!opts.interactive) {
243
+ if (field.optional === true) {
244
+ names[field.key] = '';
245
+ continue;
246
+ }
263
247
 
264
- if (!opts.interactive) {
265
- if (field.optional === true) {
266
- names[field.key] = '';
267
- continue;
248
+ if (field.previous !== undefined) {
249
+ names[field.key] = field.previous;
250
+ continue;
251
+ }
252
+
253
+ const listed =
254
+ field.choices !== undefined && field.choices.length > 1
255
+ ? `; ${LayoutFolder.listedNote({ folders: field.choices })}`
256
+ : '';
257
+
258
+ return {
259
+ ok: false,
260
+ error: `missing ${field.flag} (${field.question}${listed}) - names are never chosen for you`,
261
+ };
268
262
  }
269
263
 
270
- if (field.previous !== undefined) {
264
+ if (field.fixed === true && field.previous !== undefined) {
271
265
  names[field.key] = field.previous;
272
266
  continue;
273
267
  }
274
268
 
275
- const listed =
276
- field.choices !== undefined && field.choices.length > 1
277
- ? `; ${listedFoldersNote({ folders: field.choices })}`
278
- : '';
269
+ const answer = await ProjectNames.askUntilValid({ field, ask: opts.ask });
279
270
 
280
- return {
281
- ok: false,
282
- error: `missing ${field.flag} (${field.question}${listed}) - names are never chosen for you`,
283
- };
284
- }
271
+ if (answer === null) {
272
+ return { ok: false, error: 'aborted' };
273
+ }
285
274
 
286
- if (field.fixed === true && field.previous !== undefined) {
287
- names[field.key] = field.previous;
288
- continue;
275
+ names[field.key] = answer;
289
276
  }
290
277
 
291
- const answer = await askUntilValid({ field, ask: opts.ask });
278
+ return { ok: true, names };
279
+ }
280
+
281
+ /** Two folders given the same name would mix kinds of code; the error names both flags. */
282
+ static findFolderClash(opts: { folders: { flag: string; value: string }[] }): string | undefined {
283
+ for (const [index, first] of opts.folders.entries()) {
284
+ const second = opts.folders.slice(index + 1).find((other) => other.value === first.value);
292
285
 
293
- if (answer === null) {
294
- return { ok: false, error: 'aborted' };
286
+ if (second !== undefined) {
287
+ return `${first.flag} and ${second.flag} both name '${first.value}' - each kind of code needs its own folder`;
288
+ }
295
289
  }
296
290
 
297
- names[field.key] = answer;
291
+ return undefined;
298
292
  }
293
+ }
299
294
 
300
- return { ok: true, names };
301
- };
295
+ const NEW_FOLDER = ':new-folder';
302
296
 
303
- /** Two folders given the same name would mix kinds of code; the error names both flags. */
304
- export const findFolderClash = (opts: {
305
- folders: { flag: string; value: string }[];
306
- }): string | undefined => {
307
- for (const [index, first] of opts.folders.entries()) {
308
- const second = opts.folders.slice(index + 1).find((other) => other.value === first.value);
297
+ /** A menu, not a line: existing folders are picked, a new name is typed with its default shown. */
298
+ const askWithMenus: TAsk = async (opts) => {
299
+ if (opts.choices !== undefined && opts.choices.length > 0) {
300
+ const picked = await TerminalPrompt.promptSelect({
301
+ message: opts.question,
302
+ choices: [
303
+ ...opts.choices.map((value) => ({ value, label: value })),
304
+ { value: NEW_FOLDER, label: 'New folder...' },
305
+ ],
306
+ initial: opts.previous,
307
+ });
309
308
 
310
- if (second !== undefined) {
311
- return `${first.flag} and ${second.flag} both name '${first.value}' - each kind of code needs its own folder`;
309
+ if (picked !== NEW_FOLDER) {
310
+ return picked;
312
311
  }
313
312
  }
314
313
 
315
- return undefined;
314
+ return TerminalPrompt.promptText({
315
+ message: opts.question,
316
+ defaultValue: opts.previous,
317
+ validate: opts.validate,
318
+ });
316
319
  };
320
+
321
+ /** Menus in a terminal that can draw them, the plain question everywhere else. */
322
+ export const askInTerminal: TAsk = (opts) =>
323
+ TerminalCapability.menusAvailable() ? askWithMenus(opts) : ProjectNames.askWithPrompt(opts);
@@ -1,9 +1,9 @@
1
1
  import { existsSync, readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
- import { readPort } from './workspace.ts';
3
+ import { PortRegistry } from './workspace.ts';
4
4
 
5
5
  /** One app of the monorepo as `make dev` serves it: its port, and the paths worth opening. */
6
- export interface INextApp {
6
+ interface INextApp {
7
7
  port: number;
8
8
  urls: string[];
9
9
  }
@@ -29,25 +29,28 @@ const readRecordedUrls = (opts: { directory: string }): string[] => {
29
29
  return Array.isArray(urls) ? urls.filter((url) => typeof url === 'string') : [];
30
30
  };
31
31
 
32
- /** The apps already in the monorepo: those with a `*PORT=` line in .env.example, as they were made. */
33
- export const readExistingApps = (opts: { root: string; paths: string[] }): INextApp[] =>
34
- opts.paths.flatMap((path) => {
35
- const directory = join(opts.root, path);
36
- const envFile = join(directory, '.env.example');
37
- const port = existsSync(envFile)
38
- ? readPort({ envExample: readFileSync(envFile, 'utf8') })
39
- : undefined;
40
-
41
- return port === undefined ? [] : [{ port, urls: readRecordedUrls({ directory }) }];
42
- });
43
-
44
- /** The closing message: what ran, then one `open` line per url, or per app root when it has none. */
45
- export const renderNext = (opts: { done: string; command: string; apps: INextApp[] }): string => {
46
- const lines = opts.apps.flatMap((app) =>
47
- (app.urls.length === 0 ? [''] : app.urls).map(
48
- (path) => ` open http://localhost:${app.port}${path}`,
49
- ),
50
- );
51
-
52
- return `${opts.done} Next:\n ${opts.command}\n${lines.join('\n')}\n`;
53
- };
32
+ export class NextStep {
33
+ /** The apps already in the monorepo: those with a `*PORT=` line in .env.example, as they were made. */
34
+ static readExistingApps(opts: { root: string; paths: string[] }): INextApp[] {
35
+ return opts.paths.flatMap((path) => {
36
+ const directory = join(opts.root, path);
37
+ const envFile = join(directory, '.env.example');
38
+ const port = existsSync(envFile)
39
+ ? PortRegistry.read({ envExample: readFileSync(envFile, 'utf8') })
40
+ : undefined;
41
+
42
+ return port === undefined ? [] : [{ port, urls: readRecordedUrls({ directory }) }];
43
+ });
44
+ }
45
+
46
+ /** The closing message: what ran, then one `open` line per url, or per app root when it has none. */
47
+ static render(opts: { done: string; command: string; apps: INextApp[] }): string {
48
+ const lines = opts.apps.flatMap((app) =>
49
+ (app.urls.length === 0 ? [''] : app.urls).map(
50
+ (path) => ` open http://localhost:${app.port}${path}`,
51
+ ),
52
+ );
53
+
54
+ return `${opts.done} Next:\n ${opts.command}\n${lines.join('\n')}\n`;
55
+ }
56
+ }
@@ -1,17 +1,20 @@
1
- import { menusAvailable, promptPlan } from '../ui/index.ts';
1
+ import { TerminalCapability, TerminalPrompt } from '../ui/index.ts';
2
2
 
3
- /** `label value` lines with the values in one column. */
4
- export const planLines = (opts: { rows: [label: string, value: string][] }): string[] => {
5
- const width = Math.max(...opts.rows.map(([label]) => label.length));
3
+ export class WritePlan {
4
+ /** `label value` lines with the values in one column. */
5
+ static planLines(opts: { rows: [label: string, value: string][] }): string[] {
6
+ const width = Math.max(...opts.rows.map(([label]) => label.length));
6
7
 
7
- return opts.rows.map(([label, value]) => `${label.padEnd(width)} ${value}`);
8
- };
8
+ return opts.rows.map(([label, value]) => `${label.padEnd(width)} ${value}`);
9
+ }
9
10
 
10
- /**
11
- * Before anything is written, a terminal that can draw menus shows what will be written and asks.
12
- * Without one nothing is asked: flags and pipes keep writing as they always did.
13
- */
14
- export const confirmWrite = async (opts: { title: string; lines: string[] }): Promise<boolean> =>
15
- menusAvailable() ? promptPlan(opts) : true;
11
+ /**
12
+ * Before anything is written, a terminal that can draw menus shows what will be written and asks.
13
+ * Without one nothing is asked: flags and pipes keep writing as they always did.
14
+ */
15
+ static async confirm(opts: { title: string; lines: string[] }): Promise<boolean> {
16
+ return TerminalCapability.menusAvailable() ? TerminalPrompt.promptPlan(opts) : true;
17
+ }
18
+ }
16
19
 
17
20
  export const ABORTED = 'aborted: nothing was written';