@venizia/vulcan 0.4.9-0 → 0.4.9-2
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/base/extensions/vulcan-guards.ts +48 -41
- package/base/hooks/antigravity-guards.ts +2 -2
- package/base/hooks/codex-guards.ts +15 -5
- package/base/hooks/guard-git.ts +8 -8
- package/base/hooks/guard-manifest.ts +4 -5
- package/base/hooks/guard-outside.ts +8 -8
- package/base/hooks/guard-package.ts +5 -6
- package/base/hooks/guard-remote-hosts.ts +6 -7
- package/base/hooks/guard-scripting.ts +5 -6
- package/base/hooks/guard-writes.ts +8 -9
- package/base/hooks/post-tool.ts +2 -2
- package/base/hooks/prompt-submit.ts +2 -2
- package/base/hooks/session-start.ts +3 -3
- package/base/hooks/stop.ts +2 -2
- package/base/hooks/subagent-start.ts +2 -2
- package/base/skills/docs-update/SKILL.md +4 -2
- package/base/skills/visualize-work/SKILL.md +9 -0
- package/package.json +3 -3
- package/src/agents/atlas-block.ts +43 -43
- package/src/agents/codex-hooks.ts +45 -43
- package/src/agents/detect.ts +19 -16
- package/src/agents/exclude.ts +96 -97
- package/src/agents/hooks-json.ts +38 -36
- package/src/agents/local.ts +46 -43
- package/src/agents/prompt.ts +45 -42
- package/src/agents/render.ts +201 -195
- package/src/agents/resolve.ts +133 -134
- package/src/agents/table.ts +12 -8
- package/src/commands/add.command.ts +2 -2
- package/src/commands/agents.command.ts +11 -17
- package/src/commands/clean.command.ts +6 -6
- package/src/commands/doctor.command.ts +4 -4
- package/src/commands/init.command.ts +12 -8
- package/src/commands/preset.command.ts +2 -2
- package/src/commands/profile.command.ts +42 -49
- package/src/commands/sync.command.ts +109 -111
- package/src/commands/upgrade.command.ts +80 -75
- package/src/commands/visualize.command.ts +7 -13
- package/src/commands/x.command.ts +55 -50
- package/src/common/format.ts +23 -21
- package/src/common/json.ts +8 -5
- package/src/common/layout-folder.ts +94 -91
- package/src/common/paths.ts +14 -12
- package/src/config/loader.ts +52 -49
- package/src/config/packages.ts +14 -11
- package/src/config/schema.ts +3 -3
- package/src/create/add-app.ts +519 -509
- package/src/create/add-lib.ts +237 -240
- package/src/create/bunfig.ts +26 -23
- package/src/create/checks.ts +36 -34
- package/src/create/diff.ts +21 -23
- package/src/create/dockerignore.ts +26 -24
- package/src/create/files.ts +7 -5
- package/src/create/init-monorepo.ts +75 -80
- package/src/create/lib-preset.ts +59 -63
- package/src/create/manifest-json.ts +10 -4
- package/src/create/names.ts +217 -210
- package/src/create/next.ts +26 -23
- package/src/create/plan.ts +15 -12
- package/src/create/preset-diff.ts +301 -303
- package/src/create/preset-menu.ts +38 -32
- package/src/create/preset.ts +202 -197
- package/src/create/process.ts +79 -72
- package/src/create/scratch.ts +48 -49
- package/src/create/workspace.ts +404 -396
- package/src/doctor/checks.ts +1027 -1014
- package/src/doctor/makefile.ts +17 -13
- package/src/doctor/runner.ts +88 -118
- package/src/doctor/skills.ts +97 -95
- package/src/doctor/tags.ts +42 -37
- package/src/hooks/codex-patch.ts +25 -22
- package/src/hooks/command-view.ts +44 -39
- package/src/hooks/decision.ts +37 -37
- package/src/hooks/guard-git.ts +51 -49
- package/src/hooks/guard-manifest.ts +58 -55
- package/src/hooks/guard-outside.ts +93 -91
- package/src/hooks/guard-package.ts +82 -79
- package/src/hooks/guard-scripting.ts +19 -14
- package/src/hooks/guard-writes.ts +154 -149
- package/src/hooks/owner-reply.ts +127 -127
- package/src/hooks/post-tool.ts +94 -93
- package/src/hooks/project-guards.ts +65 -62
- package/src/hooks/project-tmp.ts +27 -24
- package/src/hooks/remote-hosts.ts +153 -130
- package/src/hooks/session-digest.ts +98 -101
- package/src/hooks/shell.ts +509 -499
- package/src/hooks/subagent-card.ts +11 -7
- package/src/hooks/trusted-scripts.ts +106 -104
- package/src/init/scaffold.ts +135 -132
- package/src/local/clean.ts +38 -36
- package/src/local/format.ts +21 -17
- package/src/local/scan.ts +144 -138
- package/src/manifest/render.ts +110 -104
- package/src/owner/card.ts +51 -46
- package/src/owner/profile.ts +99 -93
- package/src/owner/reply-switch.ts +9 -6
- package/src/owner/shape.ts +71 -69
- package/src/owner/survey.ts +173 -171
- package/src/owner/view.ts +62 -59
- package/src/owner/violations.ts +119 -123
- package/src/rules/base.ts +15 -11
- package/src/rules/parser.ts +39 -32
- package/src/rules/slots.ts +8 -6
- package/src/signals/claims.ts +30 -28
- package/src/signals/classify.ts +38 -33
- package/src/signals/loop.ts +39 -37
- package/src/signals/state.ts +79 -81
- package/src/skills/frontmatter.ts +28 -28
- package/src/sync/agent-files.ts +217 -199
- package/src/sync/agent-removal.ts +56 -59
- package/src/sync/atlas-block.ts +45 -43
- package/src/sync/base-rules.ts +32 -30
- package/src/sync/claude-launch.ts +36 -34
- package/src/sync/exclude.ts +77 -69
- package/src/sync/local-choice.ts +50 -47
- package/src/sync/planner.ts +59 -61
- package/src/sync/prune.ts +52 -48
- package/src/sync/settings.ts +166 -167
- package/src/ui/capability.ts +12 -7
- package/src/ui/keyboard.ts +38 -38
- package/src/ui/prompt.ts +79 -77
- package/src/visualize/assets.ts +33 -24
- package/src/visualize/charts.ts +179 -176
- package/src/visualize/compare-css.ts +3 -2
- package/src/visualize/compare-render.ts +9 -7
- package/src/visualize/diagrams.ts +189 -174
- package/src/visualize/grid-span.ts +34 -0
- package/src/visualize/icons.ts +7 -5
- package/src/visualize/kinds-render.ts +50 -45
- package/src/visualize/kinds-validate.ts +12 -10
- package/src/visualize/labels.ts +21 -17
- package/src/visualize/layout.ts +112 -97
- package/src/visualize/page.ts +92 -104
- package/src/visualize/render.ts +143 -140
- package/src/visualize/sections.ts +395 -384
- package/src/visualize/sources.ts +2 -2
- package/src/visualize/theme.ts +12 -10
- package/src/visualize/validate.ts +13 -9
- package/src/wiki/anchors.ts +38 -36
- package/src/wiki/command.ts +4 -4
- package/src/wiki/source-links.ts +46 -44
package/src/sync/settings.ts
CHANGED
|
@@ -12,49 +12,6 @@ const mergeArrays = (opts: { base: unknown[]; overlay: unknown[] }): unknown[] =
|
|
|
12
12
|
return [...opts.base, ...opts.overlay.filter((entry) => !seen.has(JSON.stringify(entry)))];
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
/** `overlay` wins key by key; one level deep into the object-of-entries keys (SyncConstants.MERGE_ONE_LEVEL). */
|
|
16
|
-
export const mergeSettings = (opts: { base: TSettings; overlay: TSettings }): TSettings => {
|
|
17
|
-
const merged: TSettings = { ...opts.base };
|
|
18
|
-
|
|
19
|
-
for (const [key, value] of Object.entries(opts.overlay)) {
|
|
20
|
-
const current = { value: merged[key] };
|
|
21
|
-
const incoming = { value };
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
SyncConstants.UNION_ARRAYS.has(key) &&
|
|
25
|
-
Array.isArray(current.value) &&
|
|
26
|
-
Array.isArray(value)
|
|
27
|
-
) {
|
|
28
|
-
merged[key] = mergeArrays({ base: current.value, overlay: value });
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
!SyncConstants.MERGE_ONE_LEVEL.has(key) ||
|
|
34
|
-
!isSettingsObject(current) ||
|
|
35
|
-
!isSettingsObject(incoming)
|
|
36
|
-
) {
|
|
37
|
-
merged[key] = value;
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const inner: TSettings = { ...current.value };
|
|
42
|
-
|
|
43
|
-
for (const [innerKey, innerValue] of Object.entries(incoming.value)) {
|
|
44
|
-
const existing = inner[innerKey];
|
|
45
|
-
|
|
46
|
-
inner[innerKey] =
|
|
47
|
-
Array.isArray(existing) && Array.isArray(innerValue)
|
|
48
|
-
? mergeArrays({ base: existing, overlay: innerValue })
|
|
49
|
-
: innerValue;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
merged[key] = inner;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return merged;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
15
|
const toKey = (opts: { value: unknown }): string => JSON.stringify(opts.value);
|
|
59
16
|
|
|
60
17
|
/** The command of a hook; `undefined` when `hook` is not an object with a command string. */
|
|
@@ -85,43 +42,6 @@ const extractEntryCommands = (opts: { entries: unknown }): string[] =>
|
|
|
85
42
|
)
|
|
86
43
|
: [];
|
|
87
44
|
|
|
88
|
-
/** Every hook command of a settings file, across its events. */
|
|
89
|
-
export const extractHookCommands = (opts: { settings: TSettings | undefined }): string[] => {
|
|
90
|
-
const hooks = { value: opts.settings?.[SyncConstants.HOOKS_KEY] };
|
|
91
|
-
|
|
92
|
-
return isSettingsObject(hooks)
|
|
93
|
-
? Object.values(hooks.value).flatMap((entries) => extractEntryCommands({ entries }))
|
|
94
|
-
: [];
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* `entries` without the hooks whose command is in `commands`: an entry's other hooks and keys stay,
|
|
99
|
-
* an entry left with no hooks goes, and anything that is not an entry is kept as it is.
|
|
100
|
-
*/
|
|
101
|
-
export const removeHookCommands = (opts: {
|
|
102
|
-
entries: unknown[];
|
|
103
|
-
commands: Set<string>;
|
|
104
|
-
}): unknown[] =>
|
|
105
|
-
opts.entries.flatMap((entry) => {
|
|
106
|
-
const hookEntry = toHookEntry({ entry });
|
|
107
|
-
|
|
108
|
-
if (hookEntry === undefined) {
|
|
109
|
-
return [entry];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const kept = hookEntry.hooks.filter((hook) => {
|
|
113
|
-
const command = toHookCommand({ hook });
|
|
114
|
-
|
|
115
|
-
return command === undefined || !opts.commands.has(command);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
if (kept.length === hookEntry.hooks.length) {
|
|
119
|
-
return [entry];
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return kept.length > 0 ? [{ ...hookEntry.entry, hooks: kept }] : [];
|
|
123
|
-
});
|
|
124
|
-
|
|
125
45
|
/** `settings` with its keys in `reference`'s order: keys `reference` has keep their place, new keys follow. */
|
|
126
46
|
const orderKeysLike = (opts: { settings: TSettings; reference: TSettings }): TSettings => {
|
|
127
47
|
const keys = [
|
|
@@ -132,120 +52,199 @@ const orderKeysLike = (opts: { settings: TSettings; reference: TSettings }): TSe
|
|
|
132
52
|
return Object.fromEntries(keys.map((key) => [key, opts.settings[key]]));
|
|
133
53
|
};
|
|
134
54
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
55
|
+
export class ProjectSettings {
|
|
56
|
+
/** `overlay` wins key by key; one level deep into the object-of-entries keys (SyncConstants.MERGE_ONE_LEVEL). */
|
|
57
|
+
static merge(opts: { base: TSettings; overlay: TSettings }): TSettings {
|
|
58
|
+
const merged: TSettings = { ...opts.base };
|
|
59
|
+
|
|
60
|
+
for (const [key, value] of Object.entries(opts.overlay)) {
|
|
61
|
+
const current = { value: merged[key] };
|
|
62
|
+
const incoming = { value };
|
|
63
|
+
|
|
64
|
+
if (
|
|
65
|
+
SyncConstants.UNION_ARRAYS.has(key) &&
|
|
66
|
+
Array.isArray(current.value) &&
|
|
67
|
+
Array.isArray(value)
|
|
68
|
+
) {
|
|
69
|
+
merged[key] = mergeArrays({ base: current.value, overlay: value });
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (
|
|
74
|
+
!SyncConstants.MERGE_ONE_LEVEL.has(key) ||
|
|
75
|
+
!isSettingsObject(current) ||
|
|
76
|
+
!isSettingsObject(incoming)
|
|
77
|
+
) {
|
|
78
|
+
merged[key] = value;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const inner: TSettings = { ...current.value };
|
|
83
|
+
|
|
84
|
+
for (const [innerKey, innerValue] of Object.entries(incoming.value)) {
|
|
85
|
+
const existing = inner[innerKey];
|
|
86
|
+
|
|
87
|
+
inner[innerKey] =
|
|
88
|
+
Array.isArray(existing) && Array.isArray(innerValue)
|
|
89
|
+
? mergeArrays({ base: existing, overlay: innerValue })
|
|
90
|
+
: innerValue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
merged[key] = inner;
|
|
150
94
|
}
|
|
95
|
+
|
|
96
|
+
return merged;
|
|
151
97
|
}
|
|
152
98
|
|
|
153
|
-
|
|
154
|
-
}
|
|
99
|
+
/** Every hook command of a settings file, across its events. */
|
|
100
|
+
static extractHookCommands(opts: { settings: TSettings | undefined }): string[] {
|
|
101
|
+
const hooks = { value: opts.settings?.[SyncConstants.HOOKS_KEY] };
|
|
155
102
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
) {
|
|
172
|
-
const managedEntries = new Set(managedValue.map((entry) => toKey({ value: entry })));
|
|
173
|
-
const kept = current.value.filter((entry) => !managedEntries.has(toKey({ value: entry })));
|
|
174
|
-
|
|
175
|
-
if (kept.length > 0) {
|
|
176
|
-
remaining[key] = kept;
|
|
177
|
-
} else {
|
|
178
|
-
delete remaining[key];
|
|
103
|
+
return isSettingsObject(hooks)
|
|
104
|
+
? Object.values(hooks.value).flatMap((entries) => extractEntryCommands({ entries }))
|
|
105
|
+
: [];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* `entries` without the hooks whose command is in `commands`: an entry's other hooks and keys stay,
|
|
110
|
+
* an entry left with no hooks goes, and anything that is not an entry is kept as it is.
|
|
111
|
+
*/
|
|
112
|
+
static removeHookCommands(opts: { entries: unknown[]; commands: Set<string> }): unknown[] {
|
|
113
|
+
return opts.entries.flatMap((entry) => {
|
|
114
|
+
const hookEntry = toHookEntry({ entry });
|
|
115
|
+
|
|
116
|
+
if (hookEntry === undefined) {
|
|
117
|
+
return [entry];
|
|
179
118
|
}
|
|
180
119
|
|
|
181
|
-
|
|
182
|
-
|
|
120
|
+
const kept = hookEntry.hooks.filter((hook) => {
|
|
121
|
+
const command = toHookCommand({ hook });
|
|
183
122
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (toKey({ value: remaining[key] }) === toKey({ value: managedValue })) {
|
|
190
|
-
delete remaining[key];
|
|
123
|
+
return command === undefined || !opts.commands.has(command);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
if (kept.length === hookEntry.hooks.length) {
|
|
127
|
+
return [entry];
|
|
191
128
|
}
|
|
192
129
|
|
|
193
|
-
|
|
130
|
+
return kept.length > 0 ? [{ ...hookEntry.entry, hooks: kept }] : [];
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* `settings` in the key order the user's file already has, here and one level down: a sync that only
|
|
136
|
+
* reorders keys rewrites the file, and `doctor` then calls a fresh sync stale.
|
|
137
|
+
*/
|
|
138
|
+
static keepKeyOrder(opts: { settings: TSettings; reference: TSettings }): TSettings {
|
|
139
|
+
const ordered = orderKeysLike(opts);
|
|
140
|
+
|
|
141
|
+
for (const key of Object.keys(ordered).filter((entry) =>
|
|
142
|
+
SyncConstants.MERGE_ONE_LEVEL.has(entry),
|
|
143
|
+
)) {
|
|
144
|
+
const value = { value: ordered[key] };
|
|
145
|
+
const previous = { value: opts.reference[key] };
|
|
146
|
+
|
|
147
|
+
if (isSettingsObject(value) && isSettingsObject(previous)) {
|
|
148
|
+
ordered[key] = orderKeysLike({ settings: value.value, reference: previous.value });
|
|
149
|
+
}
|
|
194
150
|
}
|
|
195
151
|
|
|
196
|
-
|
|
152
|
+
return ordered;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** `settings` without what `managed` (the overlay of a previous sync) put there; anything else stays. */
|
|
156
|
+
static removeManaged(opts: { settings: TSettings; managed: TSettings }): TSettings {
|
|
157
|
+
const remaining: TSettings = { ...opts.settings };
|
|
197
158
|
|
|
198
|
-
for (const [
|
|
199
|
-
const
|
|
159
|
+
for (const [key, managedValue] of Object.entries(opts.managed)) {
|
|
160
|
+
const current = { value: remaining[key] };
|
|
161
|
+
const managed = { value: managedValue };
|
|
200
162
|
|
|
201
|
-
if (
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
entries: unmatched,
|
|
209
|
-
commands: new Set(extractEntryCommands({ entries: innerManaged })),
|
|
210
|
-
})
|
|
211
|
-
: unmatched;
|
|
163
|
+
if (
|
|
164
|
+
SyncConstants.UNION_ARRAYS.has(key) &&
|
|
165
|
+
Array.isArray(current.value) &&
|
|
166
|
+
Array.isArray(managedValue)
|
|
167
|
+
) {
|
|
168
|
+
const managedEntries = new Set(managedValue.map((entry) => toKey({ value: entry })));
|
|
169
|
+
const kept = current.value.filter((entry) => !managedEntries.has(toKey({ value: entry })));
|
|
212
170
|
|
|
213
171
|
if (kept.length > 0) {
|
|
214
|
-
|
|
172
|
+
remaining[key] = kept;
|
|
215
173
|
} else {
|
|
216
|
-
delete
|
|
174
|
+
delete remaining[key];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (
|
|
181
|
+
!SyncConstants.MERGE_ONE_LEVEL.has(key) ||
|
|
182
|
+
!isSettingsObject(current) ||
|
|
183
|
+
!isSettingsObject(managed)
|
|
184
|
+
) {
|
|
185
|
+
if (toKey({ value: remaining[key] }) === toKey({ value: managedValue })) {
|
|
186
|
+
delete remaining[key];
|
|
217
187
|
}
|
|
218
188
|
|
|
219
189
|
continue;
|
|
220
190
|
}
|
|
221
191
|
|
|
222
|
-
|
|
223
|
-
|
|
192
|
+
const inner: TSettings = { ...current.value };
|
|
193
|
+
|
|
194
|
+
for (const [innerKey, innerManaged] of Object.entries(managed.value)) {
|
|
195
|
+
const innerCurrent = inner[innerKey];
|
|
196
|
+
|
|
197
|
+
if (Array.isArray(innerCurrent) && Array.isArray(innerManaged)) {
|
|
198
|
+
const managedKeys = new Set(innerManaged.map((entry) => toKey({ value: entry })));
|
|
199
|
+
const unmatched = innerCurrent.filter(
|
|
200
|
+
(entry) => !managedKeys.has(toKey({ value: entry })),
|
|
201
|
+
);
|
|
202
|
+
// A hand-edited entry no longer matches whole: its managed hooks still go, by command.
|
|
203
|
+
const kept =
|
|
204
|
+
key === SyncConstants.HOOKS_KEY
|
|
205
|
+
? ProjectSettings.removeHookCommands({
|
|
206
|
+
entries: unmatched,
|
|
207
|
+
commands: new Set(extractEntryCommands({ entries: innerManaged })),
|
|
208
|
+
})
|
|
209
|
+
: unmatched;
|
|
210
|
+
|
|
211
|
+
if (kept.length > 0) {
|
|
212
|
+
inner[innerKey] = kept;
|
|
213
|
+
} else {
|
|
214
|
+
delete inner[innerKey];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (toKey({ value: innerCurrent }) === toKey({ value: innerManaged })) {
|
|
221
|
+
delete inner[innerKey];
|
|
222
|
+
}
|
|
224
223
|
}
|
|
225
|
-
}
|
|
226
224
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
225
|
+
if (Object.keys(inner).length > 0) {
|
|
226
|
+
remaining[key] = inner;
|
|
227
|
+
} else {
|
|
228
|
+
delete remaining[key];
|
|
229
|
+
}
|
|
231
230
|
}
|
|
231
|
+
|
|
232
|
+
return remaining;
|
|
232
233
|
}
|
|
233
234
|
|
|
234
|
-
|
|
235
|
-
}
|
|
235
|
+
/** The project's own hooks from config, in Claude Code's settings shape. */
|
|
236
|
+
static buildHook(opts: { hooks: TResolvedConfig['hooks'] }): TSettings {
|
|
237
|
+
const byEvent: Record<string, unknown[]> = {};
|
|
236
238
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
239
|
+
for (const hook of opts.hooks) {
|
|
240
|
+
const entry = {
|
|
241
|
+
...(hook.matcher === undefined ? {} : { matcher: hook.matcher }),
|
|
242
|
+
hooks: [{ type: 'command', command: hook.command }],
|
|
243
|
+
};
|
|
240
244
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
...(hook.matcher === undefined ? {} : { matcher: hook.matcher }),
|
|
244
|
-
hooks: [{ type: 'command', command: hook.command }],
|
|
245
|
-
};
|
|
245
|
+
byEvent[hook.event] = [...(byEvent[hook.event] ?? []), entry];
|
|
246
|
+
}
|
|
246
247
|
|
|
247
|
-
|
|
248
|
+
return { hooks: byEvent };
|
|
248
249
|
}
|
|
249
|
-
|
|
250
|
-
return { hooks: byEvent };
|
|
251
|
-
};
|
|
250
|
+
}
|
package/src/ui/capability.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export class TerminalCapability {
|
|
2
|
+
/**
|
|
3
|
+
* Whether the menus can draw: both ends are a terminal and it understands cursor movement. Anything
|
|
4
|
+
* else (a pipe, a redirect, `TERM=dumb`) keeps the plain questions, so what scripts and logs see does
|
|
5
|
+
* not change.
|
|
6
|
+
*/
|
|
7
|
+
static menusAvailable(): boolean {
|
|
8
|
+
return (
|
|
9
|
+
process.stdin.isTTY === true && process.stdout.isTTY === true && process.env.TERM !== 'dumb'
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
}
|
package/src/ui/keyboard.ts
CHANGED
|
@@ -8,43 +8,43 @@ const REFUSAL = [
|
|
|
8
8
|
/** The command was given piped lines where a menu needs key presses; the way out is already printed. */
|
|
9
9
|
export class PipedInputRefusal extends Error {}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
run: () => Promise<TResult
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
11
|
+
export class MenuInput {
|
|
12
|
+
/**
|
|
13
|
+
* A keyboard in raw mode sends CR for Enter, never LF. LF means the answers were piped in (a script
|
|
14
|
+
* feeding a pty), and a menu would wait for a key that never comes. So while a menu is open, the first
|
|
15
|
+
* LF restores the terminal, prints the way out and ends the menu with a `PipedInputRefusal`: a
|
|
16
|
+
* refusal, not a hang. It is thrown, not `process.exit`, so the `finally` blocks of the flow run (the
|
|
17
|
+
* scratch folder of a preset is removed) and the router turns it into exit code 1.
|
|
18
|
+
*/
|
|
19
|
+
static async guardAgainstPipedLines<TResult>(run: () => Promise<TResult>): Promise<TResult> {
|
|
20
|
+
let refuseMenu: (error: PipedInputRefusal) => void = () => {};
|
|
21
|
+
const refused = new Promise<never>((_resolve, reject) => {
|
|
22
|
+
refuseMenu = reject;
|
|
23
|
+
});
|
|
24
|
+
const refuse = (chunk: Buffer | string): void => {
|
|
25
|
+
const bytes = typeof chunk === 'string' ? Buffer.from(chunk) : chunk;
|
|
26
|
+
|
|
27
|
+
if (!bytes.includes(LINE_FEED)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (process.stdin.isTTY === true) {
|
|
32
|
+
process.stdin.setRawMode(false);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
process.stdout.write(SHOW_CURSOR);
|
|
36
|
+
process.stderr.write(`\n${REFUSAL}\n`);
|
|
37
|
+
refuseMenu(new PipedInputRefusal(REFUSAL));
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
process.stdin.on('data', refuse);
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const outcome = await Promise.race([run(), refused]);
|
|
44
|
+
|
|
45
|
+
return outcome;
|
|
46
|
+
} finally {
|
|
47
|
+
process.stdin.off('data', refuse);
|
|
30
48
|
}
|
|
31
|
-
|
|
32
|
-
if (process.stdin.isTTY === true) {
|
|
33
|
-
process.stdin.setRawMode(false);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
process.stdout.write(SHOW_CURSOR);
|
|
37
|
-
process.stderr.write(`\n${REFUSAL}\n`);
|
|
38
|
-
refuseMenu(new PipedInputRefusal(REFUSAL));
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
process.stdin.on('data', refuse);
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
const outcome = await Promise.race([run(), refused]);
|
|
45
|
-
|
|
46
|
-
return outcome;
|
|
47
|
-
} finally {
|
|
48
|
-
process.stdin.off('data', refuse);
|
|
49
49
|
}
|
|
50
|
-
}
|
|
50
|
+
}
|
package/src/ui/prompt.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { confirm, isCancel, multiselect, note, select, text } from '@clack/prompts';
|
|
2
|
-
import {
|
|
2
|
+
import { MenuInput } from './keyboard.ts';
|
|
3
3
|
|
|
4
4
|
/** One line of a menu: what it is called, and a short note beside it. */
|
|
5
5
|
interface IChoice {
|
|
@@ -8,89 +8,91 @@ interface IChoice {
|
|
|
8
8
|
hint?: string;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
11
|
+
export class TerminalPrompt {
|
|
12
|
+
/**
|
|
13
|
+
* Free text, only where there is nothing to pick from (a new name). A default, when there is one, is
|
|
14
|
+
* shown and taken on Enter; `validate` returns the message to show, or nothing when the text is fine.
|
|
15
|
+
* Every prompt answers `null` when the user cancelled (Esc, Ctrl-C): the command stops, never picks
|
|
16
|
+
* for them.
|
|
17
|
+
*/
|
|
18
|
+
static async promptText(opts: {
|
|
19
|
+
message: string;
|
|
20
|
+
defaultValue?: string;
|
|
21
|
+
validate?: (value: string) => string | undefined;
|
|
22
|
+
}): Promise<string | null> {
|
|
23
|
+
const value = await MenuInput.guardAgainstPipedLines(() =>
|
|
24
|
+
text({
|
|
25
|
+
message: opts.message,
|
|
26
|
+
...(opts.defaultValue === undefined
|
|
27
|
+
? {}
|
|
28
|
+
: { placeholder: opts.defaultValue, defaultValue: opts.defaultValue }),
|
|
29
|
+
validate: (input) => opts.validate?.(input ?? ''),
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
}
|
|
33
|
+
return isCancel(value) ? null : value;
|
|
34
|
+
}
|
|
34
35
|
|
|
35
|
-
/** Pick one: arrows to move, Enter to choose. */
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}): Promise<string | null>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
36
|
+
/** Pick one: arrows to move, Enter to choose. */
|
|
37
|
+
static async promptSelect(opts: {
|
|
38
|
+
message: string;
|
|
39
|
+
choices: IChoice[];
|
|
40
|
+
initial?: string;
|
|
41
|
+
}): Promise<string | null> {
|
|
42
|
+
const value = await MenuInput.guardAgainstPipedLines(() =>
|
|
43
|
+
select({
|
|
44
|
+
message: opts.message,
|
|
45
|
+
options: opts.choices.map((choice) => ({
|
|
46
|
+
value: choice.value,
|
|
47
|
+
label: choice.label,
|
|
48
|
+
...(choice.hint === undefined ? {} : { hint: choice.hint }),
|
|
49
|
+
})),
|
|
50
|
+
initialValue: opts.initial,
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
}
|
|
54
|
+
return isCancel(value) ? null : value;
|
|
55
|
+
}
|
|
55
56
|
|
|
56
|
-
/** Tick any number: arrows to move, space to toggle, `a` for all, Enter to confirm; what is ticked at the start is `initial`. */
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}): Promise<string[] | null>
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
57
|
+
/** Tick any number: arrows to move, space to toggle, `a` for all, Enter to confirm; what is ticked at the start is `initial`. */
|
|
58
|
+
static async promptMultiselect(opts: {
|
|
59
|
+
message: string;
|
|
60
|
+
choices: IChoice[];
|
|
61
|
+
initial: string[];
|
|
62
|
+
}): Promise<string[] | null> {
|
|
63
|
+
const value = await MenuInput.guardAgainstPipedLines(() =>
|
|
64
|
+
multiselect({
|
|
65
|
+
message: opts.message,
|
|
66
|
+
options: opts.choices.map((choice) => ({
|
|
67
|
+
value: choice.value,
|
|
68
|
+
label: choice.label,
|
|
69
|
+
...(choice.hint === undefined ? {} : { hint: choice.hint }),
|
|
70
|
+
})),
|
|
71
|
+
initialValues: opts.initial,
|
|
72
|
+
required: false,
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
}
|
|
76
|
+
return isCancel(value) ? null : value;
|
|
77
|
+
}
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}): Promise<boolean | null>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
static async promptConfirm(opts: {
|
|
80
|
+
message: string;
|
|
81
|
+
initial?: boolean;
|
|
82
|
+
}): Promise<boolean | null> {
|
|
83
|
+
const value = await MenuInput.guardAgainstPipedLines(() =>
|
|
84
|
+
confirm({ message: opts.message, initialValue: opts.initial ?? true }),
|
|
85
|
+
);
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
}
|
|
87
|
+
return isCancel(value) ? null : value;
|
|
88
|
+
}
|
|
88
89
|
|
|
89
|
-
/** The summary of what is about to be written, then the confirm; true only when the user said yes. */
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
/** The summary of what is about to be written, then the confirm; true only when the user said yes. */
|
|
91
|
+
static async promptPlan(opts: { title: string; lines: string[] }): Promise<boolean> {
|
|
92
|
+
note(opts.lines.join('\n'), opts.title);
|
|
92
93
|
|
|
93
|
-
|
|
94
|
+
const confirmed = await TerminalPrompt.promptConfirm({ message: 'Write these files?' });
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
}
|
|
96
|
+
return confirmed === true;
|
|
97
|
+
}
|
|
98
|
+
}
|