@intra-mart/accel 0.4.0 → 0.5.0-dev.202608040843

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 (41) hide show
  1. package/README.md +140 -4
  2. package/dist/asset/deployer.js +3 -4
  3. package/dist/asset/git-provider.js +53 -25
  4. package/dist/asset/installer.d.ts +4 -1
  5. package/dist/asset/installer.js +13 -0
  6. package/dist/asset/updater.d.ts +6 -1
  7. package/dist/asset/updater.js +122 -23
  8. package/dist/commands/cache.d.ts +1 -0
  9. package/dist/commands/cache.js +74 -0
  10. package/dist/commands/preset.d.ts +31 -0
  11. package/dist/commands/preset.js +396 -0
  12. package/dist/commands/switch.d.ts +28 -0
  13. package/dist/commands/switch.js +262 -0
  14. package/dist/commands/update.d.ts +4 -0
  15. package/dist/commands/update.js +75 -23
  16. package/dist/core/constants.d.ts +1 -1
  17. package/dist/core/constants.js +1 -1
  18. package/dist/core/types.d.ts +8 -0
  19. package/dist/core/validators.d.ts +2 -0
  20. package/dist/core/validators.js +7 -0
  21. package/dist/git/object-cache.d.ts +12 -0
  22. package/dist/git/object-cache.js +95 -0
  23. package/dist/git/object-store.d.ts +3 -1
  24. package/dist/git/object-store.js +49 -9
  25. package/dist/i18n/en.js +59 -0
  26. package/dist/i18n/ja.js +59 -0
  27. package/dist/i18n/zh_CN.js +59 -0
  28. package/dist/index.js +6 -0
  29. package/dist/interactive/prompts.d.ts +4 -1
  30. package/dist/interactive/prompts.js +51 -43
  31. package/dist/utils/concurrency.d.ts +1 -0
  32. package/dist/utils/concurrency.js +1 -0
  33. package/dist/utils/hash.d.ts +1 -0
  34. package/dist/utils/hash.js +5 -0
  35. package/dist/utils/preset-io.d.ts +23 -0
  36. package/dist/utils/preset-io.js +164 -0
  37. package/dist/utils/safe-rel-path.d.ts +1 -0
  38. package/dist/utils/safe-rel-path.js +5 -0
  39. package/dist/utils/settings-io.d.ts +1 -0
  40. package/dist/utils/settings-io.js +4 -2
  41. package/package.json +1 -1
@@ -0,0 +1,396 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { defineCommand } from "citty";
3
+ import * as p from "@clack/prompts";
4
+ import { findReleaseById } from "../core/catalog.js";
5
+ import { createPresetNameValidator } from "../core/validators.js";
6
+ import { printIntro, promptModules, promptFeatures, promptAgents, collectSettingsErrors, } from "../interactive/prompts.js";
7
+ import { withHint, displayWidth } from "../interactive/format.js";
8
+ import { getMessage } from "../i18n/index.js";
9
+ import { detectLocale } from "../utils/locale-detect.js";
10
+ import { readSettingsSafe } from "../utils/settings-io.js";
11
+ import { presetPath, writePreset, presetExists, deletePreset, listPresetSummaries, formatPresetDisplayName, } from "../utils/preset-io.js";
12
+ import { sanitizeDisplayText } from "../utils/sanitize-text.js";
13
+ const requirePresetContext = async (argLocale) => {
14
+ const projectDir = process.cwd();
15
+ const fallbackLocale = argLocale ?? detectLocale();
16
+ const settings = await readSettingsSafe(projectDir);
17
+ if (!settings) {
18
+ p.log.error(getMessage("preset.error.noSettings", fallbackLocale));
19
+ process.exit(1);
20
+ }
21
+ return {
22
+ projectDir,
23
+ settings,
24
+ locale: argLocale ?? settings.locale ?? fallbackLocale,
25
+ };
26
+ };
27
+ const resolveRelease = (settings, locale) => {
28
+ const release = findReleaseById(settings.accelplatformVersion.label);
29
+ if (!release) {
30
+ p.log.error(getMessage("error.invalidVersion", locale, {
31
+ version: settings.accelplatformVersion.label,
32
+ }));
33
+ process.exit(1);
34
+ }
35
+ return release;
36
+ };
37
+ const buildPreset = (name, label, description, modules, features, agents) => ({
38
+ name,
39
+ ...(label !== "" ? { label } : {}),
40
+ ...(description !== "" ? { description } : {}),
41
+ modules,
42
+ features,
43
+ agents,
44
+ });
45
+ const defaultPrompts = {
46
+ text: (opts) => p.text(opts),
47
+ confirm: (opts) => p.confirm(opts),
48
+ modules: promptModules,
49
+ features: promptFeatures,
50
+ agents: promptAgents,
51
+ };
52
+ const resolveTextInput = (input) => {
53
+ if (p.isCancel(input))
54
+ process.exit(0);
55
+ return typeof input === "string" ? input.trim() : "";
56
+ };
57
+ const resolveConfirmInput = (input) => {
58
+ if (p.isCancel(input))
59
+ process.exit(0);
60
+ return input === true;
61
+ };
62
+ export const runPresetCreateInteractive = async (ctx, release, cli, force = false, prompts = defaultPrompts) => {
63
+ const { projectDir, locale } = ctx;
64
+ const nameValidator = createPresetNameValidator(locale);
65
+ const allModuleIds = release.modules.map((m) => m.artifactId);
66
+ printIntro("preset", locale);
67
+ let first = true;
68
+ let again = true;
69
+ while (again) {
70
+ let name = first ? cli.name : undefined;
71
+ const nameFromArg = name !== undefined;
72
+ for (;;) {
73
+ if (name === undefined) {
74
+ name = resolveTextInput(await prompts.text({
75
+ message: withHint("preset.prompt.name", locale),
76
+ validate: (value) => nameValidator(value ?? ""),
77
+ }));
78
+ }
79
+ if (!(await presetExists(projectDir, name)))
80
+ break;
81
+ if (first && force)
82
+ break;
83
+ const overwrite = resolveConfirmInput(await prompts.confirm({
84
+ message: getMessage("preset.prompt.overwrite", locale, { name }),
85
+ initialValue: false,
86
+ }));
87
+ if (overwrite)
88
+ break;
89
+ if (nameFromArg) {
90
+ p.log.info(getMessage("preset.cancelled", locale));
91
+ process.exit(0);
92
+ }
93
+ name = undefined;
94
+ }
95
+ const label = first && cli.label !== undefined
96
+ ? cli.label
97
+ : resolveTextInput(await prompts.text({
98
+ message: withHint("preset.prompt.label", locale),
99
+ }));
100
+ const description = first && cli.description !== undefined
101
+ ? cli.description
102
+ : resolveTextInput(await prompts.text({
103
+ message: withHint("preset.prompt.description", locale),
104
+ }));
105
+ const modules = await prompts.modules(release, (first ? cli.modules : undefined) ?? allModuleIds, locale);
106
+ const features = await prompts.features(release, first ? cli.features : undefined, locale);
107
+ const agents = await prompts.agents(first ? cli.agents : undefined, locale);
108
+ await writePreset(projectDir, buildPreset(name, label, description, modules, features, agents));
109
+ p.log.success(getMessage("preset.created", locale, { name }));
110
+ again = resolveConfirmInput(await prompts.confirm({
111
+ message: getMessage("preset.prompt.continue", locale),
112
+ initialValue: false,
113
+ }));
114
+ first = false;
115
+ }
116
+ };
117
+ const createCommand = defineCommand({
118
+ meta: {
119
+ name: "create",
120
+ description: "Create a configuration preset (modules / features / agents)",
121
+ },
122
+ args: {
123
+ name: {
124
+ type: "positional",
125
+ description: "Preset name (ID; alphanumerics, - and _ only)",
126
+ required: false,
127
+ },
128
+ label: {
129
+ type: "string",
130
+ description: "Display name shown in lists and selection prompts",
131
+ },
132
+ description: {
133
+ type: "string",
134
+ description: "Preset description",
135
+ },
136
+ module: {
137
+ type: "string",
138
+ description: "Modules to use (comma-separated artifactIds, e.g., im_workflow)",
139
+ },
140
+ feature: {
141
+ type: "string",
142
+ description: 'Features to use (comma-separated function ids; "" for none)',
143
+ },
144
+ agent: {
145
+ type: "string",
146
+ description: "Agent type",
147
+ },
148
+ force: {
149
+ type: "boolean",
150
+ description: "Overwrite an existing preset without confirmation",
151
+ default: false,
152
+ },
153
+ locale: {
154
+ type: "string",
155
+ description: "Locale (ja, en, zh_CN)",
156
+ },
157
+ "non-interactive": {
158
+ type: "boolean",
159
+ description: "Non-interactive mode",
160
+ default: false,
161
+ },
162
+ },
163
+ run: async ({ args }) => {
164
+ const ctx = await requirePresetContext(args.locale);
165
+ const { projectDir, settings, locale } = ctx;
166
+ const nameArg = args.name;
167
+ const moduleArg = args.module;
168
+ const featureArg = args.feature;
169
+ const agentArg = args.agent;
170
+ const cli = {
171
+ name: nameArg,
172
+ label: args.label,
173
+ description: args.description,
174
+ modules: moduleArg === undefined
175
+ ? undefined
176
+ : moduleArg.split(",").map((m) => m.trim()),
177
+ features: featureArg === undefined
178
+ ? undefined
179
+ : featureArg === ""
180
+ ? []
181
+ : featureArg.split(",").map((f) => f.trim()),
182
+ agents: agentArg === undefined
183
+ ? undefined
184
+ : agentArg.split(",").map((a) => a.trim()),
185
+ };
186
+ const errors = [];
187
+ if (cli.name !== undefined) {
188
+ const nameError = createPresetNameValidator(locale)(cli.name);
189
+ if (nameError)
190
+ errors.push(nameError);
191
+ }
192
+ errors.push(...collectSettingsErrors({
193
+ module: cli.modules,
194
+ feature: cli.features,
195
+ agent: cli.agents,
196
+ locale,
197
+ isInit: false,
198
+ }, locale, settings.accelplatformVersion.label));
199
+ if (errors.length > 0) {
200
+ p.log.error(errors.join("\n"));
201
+ process.exit(1);
202
+ }
203
+ const release = resolveRelease(settings, locale);
204
+ const isInteractive = !args["non-interactive"];
205
+ if (isInteractive) {
206
+ await runPresetCreateInteractive(ctx, release, cli, args.force);
207
+ return;
208
+ }
209
+ const requiredErrors = [];
210
+ if (cli.name === undefined) {
211
+ requiredErrors.push(getMessage("preset.error.missingName", locale, { command: "create" }));
212
+ }
213
+ const missing = [];
214
+ if (cli.modules === undefined)
215
+ missing.push("--module");
216
+ if (cli.features === undefined)
217
+ missing.push("--feature");
218
+ if (cli.agents === undefined)
219
+ missing.push("--agent");
220
+ if (missing.length > 0) {
221
+ requiredErrors.push(getMessage("error.missingRequiredOptions", locale, {
222
+ options: missing.join(", "),
223
+ }));
224
+ }
225
+ if (requiredErrors.length > 0) {
226
+ p.log.error(requiredErrors.join("\n"));
227
+ process.exit(1);
228
+ }
229
+ if ((await presetExists(projectDir, cli.name)) &&
230
+ !args.force) {
231
+ p.log.error(getMessage("preset.error.exists", locale, { name: cli.name }));
232
+ process.exit(1);
233
+ }
234
+ await writePreset(projectDir, buildPreset(cli.name, cli.label ?? "", cli.description ?? "", cli.modules, cli.features, cli.agents));
235
+ p.log.success(getMessage("preset.created", locale, { name: cli.name }));
236
+ },
237
+ });
238
+ export const buildPresetListBody = (summaries) => {
239
+ const displays = summaries.map(formatPresetDisplayName);
240
+ const maxWidth = Math.max(...displays.map((d) => displayWidth(d)));
241
+ return summaries
242
+ .map((summary, i) => {
243
+ const display = displays[i];
244
+ if (!summary.description)
245
+ return display;
246
+ const pad = " ".repeat(Math.max(0, maxWidth - displayWidth(display)));
247
+ return `${display}${pad} — ${sanitizeDisplayText(summary.description)}`;
248
+ })
249
+ .join("\n");
250
+ };
251
+ const listCommand = defineCommand({
252
+ meta: {
253
+ name: "list",
254
+ description: "List registered configuration presets",
255
+ },
256
+ run: async () => {
257
+ const { projectDir, locale } = await requirePresetContext();
258
+ const summaries = await listPresetSummaries(projectDir);
259
+ if (summaries.length === 0) {
260
+ p.log.info(getMessage("preset.list.empty", locale));
261
+ return;
262
+ }
263
+ p.log.info(buildPresetListBody(summaries));
264
+ },
265
+ });
266
+ export const buildPresetShowBody = (raw, locale) => {
267
+ const empty = getMessage("summary.empty", locale);
268
+ const text = (value) => typeof value === "string" && value !== ""
269
+ ? sanitizeDisplayText(value)
270
+ : empty;
271
+ const array = (value) => Array.isArray(value) && value.length > 0
272
+ ? value.map((v) => sanitizeDisplayText(String(v))).join(", ")
273
+ : empty;
274
+ const rows = [
275
+ [getMessage("preset.show.label", locale), text(raw.label)],
276
+ [getMessage("preset.show.description", locale), text(raw.description)],
277
+ [getMessage("preset.show.modules", locale), array(raw.modules)],
278
+ [getMessage("preset.show.features", locale), array(raw.features)],
279
+ [getMessage("preset.show.agents", locale), array(raw.agents)],
280
+ ];
281
+ const maxWidth = Math.max(...rows.map(([label]) => displayWidth(label)));
282
+ return rows
283
+ .map(([label, value]) => {
284
+ const pad = " ".repeat(Math.max(0, maxWidth - displayWidth(label)));
285
+ return `${label}${pad} : ${value}`;
286
+ })
287
+ .join("\n");
288
+ };
289
+ const requirePresetName = (nameArg, command, locale) => {
290
+ if (!nameArg) {
291
+ p.log.error(getMessage("preset.error.missingName", locale, { command }));
292
+ process.exit(1);
293
+ }
294
+ const nameError = createPresetNameValidator(locale)(nameArg);
295
+ if (nameError) {
296
+ p.log.error(nameError);
297
+ process.exit(1);
298
+ }
299
+ return nameArg;
300
+ };
301
+ const showCommand = defineCommand({
302
+ meta: {
303
+ name: "show",
304
+ description: "Show the contents of a configuration preset",
305
+ },
306
+ args: {
307
+ name: {
308
+ type: "positional",
309
+ description: "Preset name (ID)",
310
+ required: false,
311
+ },
312
+ },
313
+ run: async ({ args }) => {
314
+ const { projectDir, locale } = await requirePresetContext();
315
+ const name = requirePresetName(args.name, "show", locale);
316
+ let content;
317
+ try {
318
+ content = await readFile(presetPath(projectDir, name), "utf-8");
319
+ }
320
+ catch {
321
+ p.log.error(getMessage("preset.error.notFound", locale, { name }));
322
+ process.exit(1);
323
+ }
324
+ let raw;
325
+ try {
326
+ const parsed = JSON.parse(content);
327
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
328
+ throw new Error("not an object");
329
+ }
330
+ raw = parsed;
331
+ }
332
+ catch (err) {
333
+ p.log.error(getMessage("preset.error.invalid", locale, {
334
+ name,
335
+ errors: ` - ${getMessage("preset.error.parse", locale, {
336
+ message: sanitizeDisplayText(err instanceof Error ? err.message : String(err)),
337
+ })}`,
338
+ }));
339
+ process.exit(1);
340
+ }
341
+ p.note(buildPresetShowBody(raw, locale), formatPresetDisplayName({
342
+ name,
343
+ label: typeof raw.label === "string" ? raw.label : undefined,
344
+ }));
345
+ },
346
+ });
347
+ const deleteCommand = defineCommand({
348
+ meta: {
349
+ name: "delete",
350
+ description: "Delete a configuration preset",
351
+ },
352
+ args: {
353
+ name: {
354
+ type: "positional",
355
+ description: "Preset name (ID)",
356
+ required: false,
357
+ },
358
+ "non-interactive": {
359
+ type: "boolean",
360
+ description: "Non-interactive mode (delete without confirmation)",
361
+ default: false,
362
+ },
363
+ },
364
+ run: async ({ args }) => {
365
+ const { projectDir, locale } = await requirePresetContext();
366
+ const name = requirePresetName(args.name, "delete", locale);
367
+ if (!(await presetExists(projectDir, name))) {
368
+ p.log.error(getMessage("preset.error.notFound", locale, { name }));
369
+ process.exit(1);
370
+ }
371
+ if (!args["non-interactive"]) {
372
+ const ok = await p.confirm({
373
+ message: getMessage("preset.prompt.delete", locale, { name }),
374
+ initialValue: false,
375
+ });
376
+ if (p.isCancel(ok) || ok !== true) {
377
+ p.log.info(getMessage("preset.cancelled", locale));
378
+ process.exit(0);
379
+ }
380
+ }
381
+ await deletePreset(projectDir, name);
382
+ p.log.success(getMessage("preset.deleted", locale, { name }));
383
+ },
384
+ });
385
+ export const presetCommand = defineCommand({
386
+ meta: {
387
+ name: "preset",
388
+ description: "Manage configuration presets shared via .accel/presets/ (create / list / show / delete)",
389
+ },
390
+ subCommands: {
391
+ create: createCommand,
392
+ list: listCommand,
393
+ show: showCommand,
394
+ delete: deleteCommand,
395
+ },
396
+ });
@@ -0,0 +1,28 @@
1
+ export declare const switchCommand: import("citty").CommandDef<{
2
+ module: {
3
+ type: "string";
4
+ description: string;
5
+ };
6
+ feature: {
7
+ type: "string";
8
+ description: string;
9
+ };
10
+ agent: {
11
+ type: "string";
12
+ description: string;
13
+ };
14
+ preset: {
15
+ type: "string";
16
+ description: string;
17
+ };
18
+ "non-interactive": {
19
+ type: "boolean";
20
+ description: string;
21
+ default: false;
22
+ };
23
+ "skip-install": {
24
+ type: "boolean";
25
+ description: string;
26
+ default: false;
27
+ };
28
+ }>;
@@ -0,0 +1,262 @@
1
+ import { defineCommand } from "citty";
2
+ import * as p from "@clack/prompts";
3
+ import { CLI_VERSION } from "../core/constants.js";
4
+ import { findReleaseById } from "../core/catalog.js";
5
+ import { collectSettingsErrors, printIntro, promptAgents, promptFeatures, promptModules, } from "../interactive/prompts.js";
6
+ import { createGitAssetProvider } from "../asset/git-provider.js";
7
+ import { applyUpdateActions, buildRenderedPlan, buildUpdatedRecords, classifySwitch, collectFileStates, } from "../asset/updater.js";
8
+ import { createMessageCollector } from "../asset/messages.js";
9
+ import { printAssetMessages } from "../interactive/asset-messages.js";
10
+ import { installTriggerChanged, runInstallBuild } from "../asset/installer.js";
11
+ import { readSettingsSafe, readHashsum, writeSettings, writeHashsum, } from "../utils/settings-io.js";
12
+ import { loadAndValidatePreset, listPresetSummaries, buildPresetSelectOptions, parsePresetChoice, } from "../utils/preset-io.js";
13
+ import { getMessage } from "../i18n/index.js";
14
+ import { detectLocale } from "../utils/locale-detect.js";
15
+ import { printSummary } from "../interactive/summary.js";
16
+ import { buildProgressCallbacks } from "../interactive/progress.js";
17
+ const shortSha = (sha) => sha.slice(0, 7);
18
+ const SKIP_MESSAGE_KEYS = {
19
+ edited: "switch.result.skippedEdited",
20
+ deleted: "switch.result.skippedDeleted",
21
+ "out-of-scope": "switch.result.skippedOutOfScope",
22
+ unmanaged: "switch.result.skippedUnmanaged",
23
+ };
24
+ const printSwitchResult = (summary, actions, locale) => {
25
+ const lines = [
26
+ [summary.updated, "switch.result.updated"],
27
+ [summary.added, "switch.result.added"],
28
+ [summary.adopted, "switch.result.adopted"],
29
+ [summary.deleted, "switch.result.deleted"],
30
+ ];
31
+ for (const [paths, key] of lines) {
32
+ for (const path of paths) {
33
+ p.log.info(getMessage(key, locale, { path }));
34
+ }
35
+ }
36
+ for (const action of actions) {
37
+ if (action.outcome !== "skipped-switch" || !action.skipReason)
38
+ continue;
39
+ p.log.info(getMessage(SKIP_MESSAGE_KEYS[action.skipReason], locale, {
40
+ path: action.relativePath,
41
+ }));
42
+ }
43
+ const changedCount = summary.updated.length +
44
+ summary.added.length +
45
+ summary.adopted.length +
46
+ summary.deleted.length;
47
+ if (changedCount === 0 && summary.skippedSwitch.length === 0) {
48
+ p.log.success(getMessage("switch.upToDate", locale));
49
+ }
50
+ else {
51
+ p.log.success(getMessage("switch.complete", locale, {
52
+ updated: String(summary.updated.length),
53
+ added: String(summary.added.length),
54
+ deleted: String(summary.deleted.length),
55
+ }));
56
+ }
57
+ if (summary.skippedSwitch.length > 0) {
58
+ const list = summary.skippedSwitch.map((c) => ` - ${c}`).join("\n");
59
+ p.log.warning(`${getMessage("switch.skippedSummary", locale, {
60
+ count: String(summary.skippedSwitch.length),
61
+ })}\n${list}`);
62
+ }
63
+ };
64
+ export const switchCommand = defineCommand({
65
+ meta: {
66
+ name: "switch",
67
+ description: "Switch the deployed asset configuration (modules / features / agents) without downloading",
68
+ },
69
+ args: {
70
+ module: {
71
+ type: "string",
72
+ description: "Modules to use (comma-separated artifactIds, e.g., im_workflow)",
73
+ },
74
+ feature: {
75
+ type: "string",
76
+ description: "Features to use (comma-separated function ids, e.g., jssp)",
77
+ },
78
+ agent: {
79
+ type: "string",
80
+ description: "Agent type",
81
+ },
82
+ preset: {
83
+ type: "string",
84
+ description: "Configuration preset name to apply (mutually exclusive with --module / --feature / --agent)",
85
+ },
86
+ "non-interactive": {
87
+ type: "boolean",
88
+ description: "Non-interactive mode",
89
+ default: false,
90
+ },
91
+ "skip-install": {
92
+ type: "boolean",
93
+ description: "Skip install / build even when dependency files changed",
94
+ default: false,
95
+ },
96
+ },
97
+ run: async ({ args }) => {
98
+ const projectDir = process.cwd();
99
+ let locale = detectLocale();
100
+ const settings = await readSettingsSafe(projectDir);
101
+ if (!settings) {
102
+ p.log.error(getMessage("error.accelNotFound", locale));
103
+ process.exit(1);
104
+ }
105
+ locale = settings.locale ?? locale;
106
+ const assetSource = settings.assetSource;
107
+ if (!assetSource) {
108
+ p.log.error(getMessage("switch.error.legacyProject", locale));
109
+ process.exit(1);
110
+ }
111
+ if (assetSource.type !== "git" || !assetSource.commit || !assetSource.ref) {
112
+ p.log.error(getMessage("switch.error.notGitSource", locale));
113
+ process.exit(1);
114
+ }
115
+ const source = {
116
+ ...assetSource,
117
+ commit: assetSource.commit,
118
+ ref: assetSource.ref,
119
+ };
120
+ const isInteractive = !args["non-interactive"];
121
+ const presetArg = args.preset;
122
+ if (presetArg !== undefined &&
123
+ (args.module !== undefined ||
124
+ args.feature !== undefined ||
125
+ args.agent !== undefined)) {
126
+ p.log.error(getMessage("preset.error.conflictingFlags", locale));
127
+ process.exit(1);
128
+ }
129
+ let presetValues;
130
+ if (presetArg !== undefined) {
131
+ try {
132
+ presetValues = await loadAndValidatePreset(projectDir, presetArg, settings.accelplatformVersion.label, locale);
133
+ }
134
+ catch (err) {
135
+ p.log.error(err instanceof Error ? err.message : String(err));
136
+ process.exit(1);
137
+ }
138
+ }
139
+ const cliOnlyOpts = {
140
+ module: presetValues?.modules ??
141
+ args.module?.split(",").map((m) => m.trim()),
142
+ feature: presetValues?.features ??
143
+ args.feature?.split(",").map((f) => f.trim()),
144
+ agent: presetValues?.agents ??
145
+ args.agent?.split(",").map((a) => a.trim()),
146
+ locale,
147
+ isInit: false,
148
+ };
149
+ const cliErrors = collectSettingsErrors(cliOnlyOpts, locale, settings.accelplatformVersion.label);
150
+ if (cliErrors.length > 0) {
151
+ p.log.error(cliErrors.join("\n"));
152
+ process.exit(1);
153
+ }
154
+ let modules = cliOnlyOpts.module ?? settings.modules;
155
+ let features = cliOnlyOpts.feature ?? settings.features ?? [];
156
+ let agents = cliOnlyOpts.agent ?? settings.agents;
157
+ if (isInteractive) {
158
+ printIntro("switch", locale);
159
+ const release = findReleaseById(settings.accelplatformVersion.label);
160
+ if (!release) {
161
+ p.log.error(getMessage("error.invalidVersion", locale, {
162
+ version: settings.accelplatformVersion.label,
163
+ }));
164
+ process.exit(1);
165
+ }
166
+ let presetSelected = presetArg !== undefined;
167
+ const cliSpecified = presetSelected ||
168
+ args.module !== undefined ||
169
+ args.feature !== undefined ||
170
+ args.agent !== undefined;
171
+ if (!cliSpecified) {
172
+ const presets = await listPresetSummaries(projectDir);
173
+ if (presets.length > 0) {
174
+ const choice = await p.select({
175
+ message: getMessage("preset.prompt.switchSelect", locale),
176
+ options: [
177
+ {
178
+ value: "__none__",
179
+ label: getMessage("preset.prompt.switchSelect.none", locale),
180
+ },
181
+ ...buildPresetSelectOptions(presets, locale),
182
+ ],
183
+ initialValue: "__none__",
184
+ });
185
+ if (p.isCancel(choice))
186
+ process.exit(0);
187
+ const presetName = parsePresetChoice(choice);
188
+ if (presetName !== undefined) {
189
+ try {
190
+ const preset = await loadAndValidatePreset(projectDir, presetName, settings.accelplatformVersion.label, locale);
191
+ modules = preset.modules;
192
+ features = preset.features;
193
+ agents = preset.agents;
194
+ presetSelected = true;
195
+ }
196
+ catch (err) {
197
+ p.log.error(err instanceof Error ? err.message : String(err));
198
+ process.exit(1);
199
+ }
200
+ }
201
+ }
202
+ }
203
+ if (!presetSelected) {
204
+ modules = await promptModules(release, modules, locale);
205
+ features = await promptFeatures(release, features, locale);
206
+ agents = await promptAgents(agents, locale);
207
+ }
208
+ }
209
+ const newSettings = {
210
+ ...settings,
211
+ cliVersion: CLI_VERSION,
212
+ modules,
213
+ features,
214
+ agents,
215
+ };
216
+ if (isInteractive) {
217
+ printSummary(newSettings, projectDir, locale);
218
+ const ok = await p.confirm({
219
+ message: getMessage("switch.confirmApply", locale),
220
+ });
221
+ if (p.isCancel(ok) || ok !== true) {
222
+ p.log.info(getMessage("switch.cancelled", locale));
223
+ process.exit(0);
224
+ }
225
+ }
226
+ const provider = createGitAssetProvider(source.url, source.ref, { locale });
227
+ try {
228
+ p.log.info(getMessage("switch.progress", locale, { sha: shortSha(source.commit) }));
229
+ const tree = await provider.openCommit(source.commit);
230
+ const messageCollector = createMessageCollector();
231
+ const theirsPlan = await buildRenderedPlan(tree, newSettings, tree.materialize, messageCollector.collect);
232
+ const basePlan = await buildRenderedPlan(tree, settings, tree.materialize);
233
+ const oldHashsum = await readHashsum(projectDir);
234
+ const states = await collectFileStates(projectDir, basePlan, theirsPlan, oldHashsum);
235
+ const actions = classifySwitch(states);
236
+ const summary = await applyUpdateActions(projectDir, actions);
237
+ const { hashEntries, deployedAssets } = buildUpdatedRecords(oldHashsum, actions);
238
+ await writeSettings(projectDir, { ...newSettings, deployedAssets });
239
+ await writeHashsum(projectDir, hashEntries);
240
+ printAssetMessages(messageCollector.drain());
241
+ const skipInstall = args["skip-install"];
242
+ const changedPaths = actions
243
+ .filter((a) => a.op !== "none")
244
+ .map((a) => a.relativePath);
245
+ if (!skipInstall && installTriggerChanged(changedPaths)) {
246
+ const { success } = runInstallBuild(projectDir, newSettings.packageManager, buildProgressCallbacks(locale));
247
+ if (!success && summary.skippedSwitch.length > 0) {
248
+ const list = summary.skippedSwitch.map((c) => ` - ${c}`).join("\n");
249
+ p.log.warning(`${getMessage("switch.installFailedHint", locale)}\n${list}`);
250
+ }
251
+ }
252
+ printSwitchResult(summary, actions, locale);
253
+ }
254
+ catch (err) {
255
+ p.log.error(err instanceof Error ? err.message : String(err));
256
+ process.exit(1);
257
+ }
258
+ finally {
259
+ await provider.cleanup().catch(() => { });
260
+ }
261
+ },
262
+ });
@@ -43,6 +43,10 @@ export declare const updateCommand: import("citty").CommandDef<{
43
43
  type: "string";
44
44
  description: string;
45
45
  };
46
+ preset: {
47
+ type: "string";
48
+ description: string;
49
+ };
46
50
  locale: {
47
51
  type: "string";
48
52
  description: string;