@minniexcode/codex-switch 0.0.4 → 0.0.6
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/README.md +35 -97
- package/dist/app/add-provider.js +40 -3
- package/dist/app/edit-provider.js +76 -3
- package/dist/app/export-providers.js +2 -2
- package/dist/app/get-current-profile.js +1 -1
- package/dist/app/get-status.js +10 -3
- package/dist/app/import-providers.js +47 -3
- package/dist/app/list-backups.js +1 -1
- package/dist/app/list-config-profiles.js +30 -0
- package/dist/app/list-providers.js +1 -1
- package/dist/app/remove-provider.js +35 -3
- package/dist/app/rollback-backup.js +1 -1
- package/dist/app/rollback-latest.js +1 -1
- package/dist/app/run-doctor.js +44 -26
- package/dist/app/run-mutation.js +2 -2
- package/dist/app/setup-codex.js +37 -20
- package/dist/app/show-config.js +34 -0
- package/dist/app/show-provider.js +1 -1
- package/dist/app/switch-provider.js +8 -5
- package/dist/cli/add-interactive.js +7 -106
- package/dist/cli/args.js +5 -126
- package/dist/cli/help.js +5 -276
- package/dist/cli/interactive.js +16 -171
- package/dist/cli/output.js +23 -1
- package/dist/cli/prompt.js +3 -108
- package/dist/cli.js +10 -315
- package/dist/commands/args.js +132 -0
- package/dist/commands/dispatch.js +16 -0
- package/dist/commands/handlers.js +391 -0
- package/dist/commands/help.js +119 -0
- package/dist/commands/registry.js +291 -0
- package/dist/commands/types.js +2 -0
- package/dist/domain/config.js +548 -39
- package/dist/infra/backup-repo.js +8 -208
- package/dist/infra/codex-cli.js +8 -113
- package/dist/infra/codex-discovery.js +3 -41
- package/dist/infra/codex-paths.js +5 -69
- package/dist/infra/config-repo.js +161 -9
- package/dist/infra/fs-utils.js +7 -95
- package/dist/infra/lock-repo.js +3 -97
- package/dist/infra/providers-repo.js +7 -96
- package/dist/interaction/add-interactive.js +108 -0
- package/dist/interaction/interactive.js +216 -0
- package/dist/interaction/prompt.js +110 -0
- package/dist/runtime/codex-cli.js +130 -0
- package/dist/runtime/codex-probe.js +50 -0
- package/dist/runtime/types.js +2 -0
- package/dist/storage/backup-repo.js +210 -0
- package/dist/storage/codex-paths.js +71 -0
- package/dist/storage/config-repo.js +208 -0
- package/dist/storage/fs-utils.js +97 -0
- package/dist/storage/lock-repo.js +99 -0
- package/dist/storage/providers-repo.js +98 -0
- package/docs/Design/codex-switch-v0.0.5-design.md +932 -0
- package/docs/Design/codex-switch-v0.0.6-design.md +708 -0
- package/docs/PRD/codex-switch-prd-v0.0.5-to-v0.1.0.md +340 -0
- package/docs/PRD/codex-switch-prd-v0.1.0.md +215 -291
- package/docs/PRD/codex-switch-prd.md +1 -1
- package/docs/cli-usage.md +2 -1
- package/docs/codex-switch-technical-architecture.md +73 -4
- package/docs/test-report-0.0.5.md +163 -0
- package/docs/testing.md +131 -0
- package/package.json +1 -1
- /package/docs/{codex-switch-v0.0.4-design.md → Design/codex-switch-v0.0.4-design.md} +0 -0
package/dist/cli/help.js
CHANGED
|
@@ -1,278 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getKnownCommandNames =
|
|
4
|
-
|
|
5
|
-
exports
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
write: "Change Commands",
|
|
9
|
-
recovery: "Diagnostics And Recovery",
|
|
10
|
-
};
|
|
11
|
-
const COMMANDS = [
|
|
12
|
-
{
|
|
13
|
-
name: "setup",
|
|
14
|
-
group: "write",
|
|
15
|
-
summary: "Initialize providers.json from an existing Codex directory.",
|
|
16
|
-
usage: ["codexs setup [--json] [--codex-dir <path>] [--merge|--overwrite]"],
|
|
17
|
-
details: [
|
|
18
|
-
"Reads config.toml profiles, collects complete provider records, then writes providers.json under managed backup flow.",
|
|
19
|
-
"TTY mode can collect missing provider details and choose merge or overwrite when providers.json already exists.",
|
|
20
|
-
"Non-TTY and --json runs stay non-interactive and require explicit strategy when providers.json already exists.",
|
|
21
|
-
],
|
|
22
|
-
examples: ["codexs setup", "codexs setup --overwrite --json --codex-dir ~/.codex"],
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
name: "list",
|
|
26
|
-
group: "read",
|
|
27
|
-
summary: "List configured providers from providers.json.",
|
|
28
|
-
usage: ["codexs list [--json] [--codex-dir <path>]"],
|
|
29
|
-
details: [
|
|
30
|
-
"Reads providers.json and prints provider-to-profile mappings.",
|
|
31
|
-
"Use --json for machine-readable automation output.",
|
|
32
|
-
],
|
|
33
|
-
examples: ["codexs list", "codexs list --json"],
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
name: "show",
|
|
37
|
-
group: "read",
|
|
38
|
-
summary: "Show one provider record from providers.json.",
|
|
39
|
-
usage: ["codexs show <provider> [--json] [--codex-dir <path>]"],
|
|
40
|
-
details: [
|
|
41
|
-
"Human-readable output masks apiKey by default.",
|
|
42
|
-
"TTY mode can select a missing provider interactively before showing its record.",
|
|
43
|
-
"JSON mode returns the full provider payload for local automation.",
|
|
44
|
-
],
|
|
45
|
-
examples: ["codexs show packycode", "codexs show packycode --json"],
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
name: "current",
|
|
49
|
-
group: "read",
|
|
50
|
-
summary: "Show the active top-level profile from config.toml.",
|
|
51
|
-
usage: ["codexs current [--json] [--codex-dir <path>]"],
|
|
52
|
-
details: [
|
|
53
|
-
"Reads the currently active top-level profile.",
|
|
54
|
-
"Fails when config.toml is missing or has no top-level profile.",
|
|
55
|
-
],
|
|
56
|
-
examples: ["codexs current", "codexs current --json"],
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
name: "status",
|
|
60
|
-
group: "read",
|
|
61
|
-
summary: "Show a quick status summary for the local Codex directory.",
|
|
62
|
-
usage: ["codexs status [--json] [--codex-dir <path>]"],
|
|
63
|
-
details: [
|
|
64
|
-
"Reports file presence, current profile, and whether the live profile is mapped.",
|
|
65
|
-
"Use doctor for deeper diagnostics.",
|
|
66
|
-
],
|
|
67
|
-
examples: ["codexs status", "codexs status --json --codex-dir ./.tmp-codex"],
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
name: "edit",
|
|
71
|
-
group: "write",
|
|
72
|
-
summary: "Update fields on a single provider record.",
|
|
73
|
-
usage: [
|
|
74
|
-
"codexs edit <provider> [--profile <name>] [--api-key <key>] [--base-url <url>] [--note <text>] [--tag <tag> ...] [--json] [--codex-dir <path>]",
|
|
75
|
-
],
|
|
76
|
-
details: [
|
|
77
|
-
"Passed flags replace only the selected fields and keep the rest unchanged.",
|
|
78
|
-
"TTY mode can first select a provider, then prompt for fields when no editable options were provided.",
|
|
79
|
-
"Interactive tags use preset multi-select plus optional custom comma-separated input.",
|
|
80
|
-
"Backs up providers.json before writing.",
|
|
81
|
-
],
|
|
82
|
-
examples: ["codexs edit packycode --note primary", "codexs edit packycode --tag daily --tag paid --json"],
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
name: "add",
|
|
86
|
-
group: "write",
|
|
87
|
-
summary: "Add a provider with explicit flags or progressive TTY prompts.",
|
|
88
|
-
usage: [
|
|
89
|
-
"codexs add <provider> --profile <name> --api-key <key> [--base-url <url>] [--note <text>] [--tag <tag> ...]",
|
|
90
|
-
"codexs add [--profile <name>] [--api-key <key>] [--base-url <url>] [--note <text>] [--tag <tag> ...]",
|
|
91
|
-
],
|
|
92
|
-
details: [
|
|
93
|
-
"Prompts only for missing required values when stdin/stdout are TTYs and --json is not set.",
|
|
94
|
-
"Interactive add collects provider name, profile, and apiKey progressively as plain text inputs.",
|
|
95
|
-
"Confirm API key when prompted interactively because the hidden prompt asks twice before writing.",
|
|
96
|
-
"Interactive tags use preset multi-select plus optional custom comma-separated input.",
|
|
97
|
-
"Automation and non-TTY environments must pass all required values explicitly.",
|
|
98
|
-
],
|
|
99
|
-
examples: [
|
|
100
|
-
"codexs add packycode --profile packycode --api-key sk-xxx",
|
|
101
|
-
"codexs add packycode --profile packycode",
|
|
102
|
-
"codexs add",
|
|
103
|
-
],
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
name: "switch",
|
|
107
|
-
group: "write",
|
|
108
|
-
summary: "Switch to a provider and optionally refresh Codex login.",
|
|
109
|
-
usage: ["codexs switch <provider> [--no-login] [--json] [--codex-dir <path>]"],
|
|
110
|
-
details: [
|
|
111
|
-
"When <provider> is omitted in a TTY, an interactive provider selector is shown.",
|
|
112
|
-
"When <provider> is passed explicitly, switch proceeds directly without extra confirmation.",
|
|
113
|
-
"--no-login remains explicit and is never prompted interactively.",
|
|
114
|
-
"Backs up config.toml and auth.json, then rolls back on failure.",
|
|
115
|
-
],
|
|
116
|
-
examples: ["codexs switch freemodel", "codexs switch --no-login", "codexs switch freemodel --no-login --json"],
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
name: "remove",
|
|
120
|
-
group: "write",
|
|
121
|
-
summary: "Remove a provider from providers.json.",
|
|
122
|
-
usage: ["codexs remove <provider> [--force] [--json] [--codex-dir <path>]"],
|
|
123
|
-
details: [
|
|
124
|
-
"TTY mode can select a missing provider interactively and always asks for deletion confirmation.",
|
|
125
|
-
"Non-TTY and --json automation still require both <provider> and --force.",
|
|
126
|
-
"The confirmation prompt includes the provider name and cancels without writing when declined.",
|
|
127
|
-
"Backs up providers.json before removing the record.",
|
|
128
|
-
],
|
|
129
|
-
examples: ["codexs remove freemodel", "codexs remove freemodel --force --json"],
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
name: "import",
|
|
133
|
-
group: "write",
|
|
134
|
-
summary: "Replace providers.json with an external JSON file.",
|
|
135
|
-
usage: ["codexs import <file> [--json] [--codex-dir <path>]"],
|
|
136
|
-
details: [
|
|
137
|
-
"The file path is always explicit; there is no path wizard in this release.",
|
|
138
|
-
"TTY mode asks for confirmation before replacing or merging into the current providers registry.",
|
|
139
|
-
"Non-TTY and --json runs stay non-interactive and validate the file before writing.",
|
|
140
|
-
],
|
|
141
|
-
examples: ["codexs import ./providers.json", "codexs import ./providers.json --merge --json"],
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
name: "export",
|
|
145
|
-
group: "write",
|
|
146
|
-
summary: "Export the current providers.json to another file.",
|
|
147
|
-
usage: ["codexs export <file> [--force] [--json] [--codex-dir <path>]"],
|
|
148
|
-
details: [
|
|
149
|
-
"The file path is always explicit; there is no path wizard in this release.",
|
|
150
|
-
"TTY mode asks before overwriting an existing target when --force is not supplied.",
|
|
151
|
-
"Non-TTY and --json automation require --force to overwrite an existing file.",
|
|
152
|
-
],
|
|
153
|
-
examples: ["codexs export ./providers-backup.json", "codexs export ./providers-backup.json --force"],
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
name: "backups",
|
|
157
|
-
group: "recovery",
|
|
158
|
-
summary: "List historical backup entries.",
|
|
159
|
-
usage: ["codexs backups list [--json] [--codex-dir <path>]"],
|
|
160
|
-
details: [
|
|
161
|
-
"Enumerates backups/ manifests and returns them newest first.",
|
|
162
|
-
"Corrupt backup manifests are skipped with warnings instead of failing the whole command.",
|
|
163
|
-
],
|
|
164
|
-
examples: ["codexs backups list", "codexs backups list --json"],
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
name: "doctor",
|
|
168
|
-
group: "recovery",
|
|
169
|
-
summary: "Run configuration and environment diagnostics.",
|
|
170
|
-
usage: ["codexs doctor [--json] [--codex-dir <path>]"],
|
|
171
|
-
details: [
|
|
172
|
-
"Checks the expected config files, provider/profile consistency, and Codex CLI availability.",
|
|
173
|
-
"Returns structured issues so users and AI agents can act on them.",
|
|
174
|
-
],
|
|
175
|
-
examples: ["codexs doctor", "codexs doctor --json"],
|
|
176
|
-
},
|
|
177
|
-
{
|
|
178
|
-
name: "rollback",
|
|
179
|
-
group: "recovery",
|
|
180
|
-
summary: "Restore the latest managed backup or a specific backup id.",
|
|
181
|
-
usage: ["codexs rollback [<backup-id>] [--json] [--codex-dir <path>]"],
|
|
182
|
-
details: [
|
|
183
|
-
"TTY mode previews the target backup path and affected files, then asks for confirmation.",
|
|
184
|
-
"Non-TTY and --json runs stay non-interactive and execute immediately.",
|
|
185
|
-
"Use after a failed or undesired managed mutation.",
|
|
186
|
-
],
|
|
187
|
-
examples: ["codexs rollback", "codexs rollback 20260511-221457-switch --json"],
|
|
188
|
-
},
|
|
189
|
-
];
|
|
190
|
-
const COMMAND_NAME_SET = new Set(COMMANDS.map((command) => command.name));
|
|
191
|
-
function getKnownCommandNames() {
|
|
192
|
-
return COMMANDS.map((command) => command.name);
|
|
193
|
-
}
|
|
194
|
-
function isKnownCommandName(commandName) {
|
|
195
|
-
return COMMAND_NAME_SET.has(commandName) || commandName === "backups-list";
|
|
196
|
-
}
|
|
197
|
-
function buildHelpText(commandName) {
|
|
198
|
-
const normalizedCommandName = commandName === "backups-list" ? "backups" : commandName;
|
|
199
|
-
if (!commandName) {
|
|
200
|
-
return [
|
|
201
|
-
"codex-switch",
|
|
202
|
-
"",
|
|
203
|
-
"Manage and switch local Codex provider/profile configuration safely.",
|
|
204
|
-
"",
|
|
205
|
-
"Usage:",
|
|
206
|
-
" codexs <command> [options]",
|
|
207
|
-
" codexs help <command>",
|
|
208
|
-
"",
|
|
209
|
-
...renderGroupedCommands(),
|
|
210
|
-
"",
|
|
211
|
-
"Global options:",
|
|
212
|
-
" --json Output the standard JSON envelope and disable all prompts.",
|
|
213
|
-
" --codex-dir <path> Target a specific Codex directory instead of ~/.codex.",
|
|
214
|
-
" --help Show top-level or command-specific help.",
|
|
215
|
-
" --version Print the current CLI version.",
|
|
216
|
-
"",
|
|
217
|
-
"Environment:",
|
|
218
|
-
" CODEXS_CODEX_DIR Default Codex directory when --codex-dir is not passed.",
|
|
219
|
-
" NODE_ENV=development defaults to ./test-fixtures/sample-codex when no override is set.",
|
|
220
|
-
"",
|
|
221
|
-
"Interactive rules:",
|
|
222
|
-
" Progressive prompts only run in a real TTY and never run under --json.",
|
|
223
|
-
" Human write commands may guide missing inputs or ask for dangerous-action confirmation.",
|
|
224
|
-
" Automation should pass explicit arguments and prefer --json for stable parsing.",
|
|
225
|
-
"",
|
|
226
|
-
"Dangerous commands:",
|
|
227
|
-
" remove deletes provider records.",
|
|
228
|
-
" import replaces or merges providers.json.",
|
|
229
|
-
" export may overwrite a target file.",
|
|
230
|
-
" rollback restores files from a managed backup.",
|
|
231
|
-
"",
|
|
232
|
-
"Examples:",
|
|
233
|
-
" codexs setup",
|
|
234
|
-
" codexs list",
|
|
235
|
-
" codexs switch",
|
|
236
|
-
" codexs add packycode --profile packycode --api-key sk-xxx",
|
|
237
|
-
" codexs remove freemodel",
|
|
238
|
-
" codexs backups list",
|
|
239
|
-
" codexs rollback",
|
|
240
|
-
" codexs help add",
|
|
241
|
-
].join("\n");
|
|
242
|
-
}
|
|
243
|
-
const command = COMMANDS.find((candidate) => candidate.name === normalizedCommandName);
|
|
244
|
-
if (!command) {
|
|
245
|
-
return [
|
|
246
|
-
`Unknown help topic: ${normalizedCommandName}`,
|
|
247
|
-
"",
|
|
248
|
-
"Available commands:",
|
|
249
|
-
...getKnownCommandNames().map((name) => ` ${name}`),
|
|
250
|
-
].join("\n");
|
|
251
|
-
}
|
|
252
|
-
return [
|
|
253
|
-
`codexs ${command.name}`,
|
|
254
|
-
"",
|
|
255
|
-
command.summary,
|
|
256
|
-
"",
|
|
257
|
-
"Usage:",
|
|
258
|
-
...command.usage.map((usage) => ` ${usage}`),
|
|
259
|
-
"",
|
|
260
|
-
"Details:",
|
|
261
|
-
...command.details.map((detail) => ` ${detail}`),
|
|
262
|
-
"",
|
|
263
|
-
"Examples:",
|
|
264
|
-
...command.examples.map((example) => ` ${example}`),
|
|
265
|
-
].join("\n");
|
|
266
|
-
}
|
|
267
|
-
function renderGroupedCommands() {
|
|
268
|
-
const lines = [];
|
|
269
|
-
for (const group of ["read", "write", "recovery"]) {
|
|
270
|
-
lines.push(`${GROUP_TITLES[group]}:`);
|
|
271
|
-
for (const command of COMMANDS.filter((candidate) => candidate.group === group)) {
|
|
272
|
-
lines.push(` ${command.name.padEnd(8, " ")} ${command.summary}`);
|
|
273
|
-
}
|
|
274
|
-
lines.push("");
|
|
275
|
-
}
|
|
276
|
-
lines.pop();
|
|
277
|
-
return lines;
|
|
278
|
-
}
|
|
3
|
+
exports.isKnownCommandName = exports.getKnownCommandNames = exports.buildHelpText = void 0;
|
|
4
|
+
var help_1 = require("../commands/help");
|
|
5
|
+
Object.defineProperty(exports, "buildHelpText", { enumerable: true, get: function () { return help_1.buildHelpText; } });
|
|
6
|
+
Object.defineProperty(exports, "getKnownCommandNames", { enumerable: true, get: function () { return help_1.getKnownCommandNames; } });
|
|
7
|
+
Object.defineProperty(exports, "isKnownCommandName", { enumerable: true, get: function () { return help_1.isKnownCommandNameForHelp; } });
|
package/dist/cli/interactive.js
CHANGED
|
@@ -1,173 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.canPrompt =
|
|
37
|
-
|
|
38
|
-
exports.
|
|
39
|
-
exports.
|
|
40
|
-
exports.
|
|
41
|
-
exports.
|
|
42
|
-
exports.
|
|
43
|
-
exports.
|
|
44
|
-
exports.
|
|
45
|
-
exports.
|
|
46
|
-
exports.
|
|
47
|
-
exports.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const providers_repo_1 = require("../infra/providers-repo");
|
|
53
|
-
const backup_repo_1 = require("../infra/backup-repo");
|
|
54
|
-
const add_interactive_1 = require("./add-interactive");
|
|
55
|
-
/**
|
|
56
|
-
* Keeps CLI-side interactivity rules in one place so automation paths remain explicit.
|
|
57
|
-
*/
|
|
58
|
-
function canPrompt(runtime, jsonMode) {
|
|
59
|
-
return !jsonMode && runtime.isInteractive();
|
|
60
|
-
}
|
|
61
|
-
async function promptForProviderSelection(runtime, providersPath, message) {
|
|
62
|
-
const providers = (0, providers_repo_1.readProvidersFile)(providersPath);
|
|
63
|
-
const choices = Object.entries(providers.providers)
|
|
64
|
-
.sort(([left], [right]) => left.localeCompare(right))
|
|
65
|
-
.map(([providerName, provider]) => ({
|
|
66
|
-
value: providerName,
|
|
67
|
-
label: providerName,
|
|
68
|
-
hint: provider.profile,
|
|
69
|
-
}));
|
|
70
|
-
if (choices.length === 0) {
|
|
71
|
-
throw (0, errors_1.cliError)("PROVIDER_NOT_FOUND", "No providers are configured.");
|
|
72
|
-
}
|
|
73
|
-
return runtime.selectOne(message, choices);
|
|
74
|
-
}
|
|
75
|
-
async function confirmProviderRemoval(runtime, providerName) {
|
|
76
|
-
const confirmed = await runtime.confirmAction(`Remove provider "${providerName}"?`, {
|
|
77
|
-
defaultValue: false,
|
|
78
|
-
});
|
|
79
|
-
if (!confirmed) {
|
|
80
|
-
throw (0, errors_1.cliError)("PROMPT_CANCELLED", `Removal cancelled for provider "${providerName}".`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
async function confirmImport(runtime, sourceFile, merge = false) {
|
|
84
|
-
const confirmed = await runtime.confirmAction(merge
|
|
85
|
-
? `Import providers from ${path.resolve(sourceFile)} and merge into the current registry?`
|
|
86
|
-
: `Import providers from ${path.resolve(sourceFile)} and replace the current registry?`, { defaultValue: false });
|
|
87
|
-
if (!confirmed) {
|
|
88
|
-
throw (0, errors_1.cliError)("PROMPT_CANCELLED", "Import cancelled.");
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
async function confirmExportOverwrite(runtime, targetFile) {
|
|
92
|
-
return runtime.confirmAction(`Overwrite existing export target ${path.resolve(targetFile)}?`, {
|
|
93
|
-
defaultValue: false,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
function exportTargetExists(targetFile) {
|
|
97
|
-
return fs.existsSync(path.resolve(targetFile));
|
|
98
|
-
}
|
|
99
|
-
function getRollbackSummary(latestBackupPath) {
|
|
100
|
-
const manifest = (0, backup_repo_1.loadLatestManifest)(latestBackupPath);
|
|
101
|
-
return buildRollbackSummary(manifest);
|
|
102
|
-
}
|
|
103
|
-
function getRollbackSummaryById(backupsDir, backupId) {
|
|
104
|
-
const manifest = (0, backup_repo_1.loadManifestById)(backupsDir, backupId);
|
|
105
|
-
return buildRollbackSummary(manifest);
|
|
106
|
-
}
|
|
107
|
-
function buildRollbackSummary(manifest) {
|
|
108
|
-
const previewLines = [
|
|
109
|
-
"Rollback preview",
|
|
110
|
-
`Backup ID: ${(0, backups_1.getBackupId)(manifest.backupDir)}`,
|
|
111
|
-
`Backup: ${manifest.backupDir}`,
|
|
112
|
-
...manifest.files.map((file) => {
|
|
113
|
-
const suffix = file.existed ? "restore" : "remove";
|
|
114
|
-
return `- ${file.relativePath} (${suffix})`;
|
|
115
|
-
}),
|
|
116
|
-
];
|
|
117
|
-
return { manifest, previewLines };
|
|
118
|
-
}
|
|
119
|
-
async function confirmRollback(runtime, latestBackupPath, backupsDir, backupId) {
|
|
120
|
-
const { previewLines } = backupId && backupsDir
|
|
121
|
-
? getRollbackSummaryById(backupsDir, backupId)
|
|
122
|
-
: getRollbackSummary(latestBackupPath);
|
|
123
|
-
for (const line of previewLines) {
|
|
124
|
-
runtime.writeLine(line);
|
|
125
|
-
}
|
|
126
|
-
const confirmed = await runtime.confirmAction(backupId ? `Restore files from backup "${backupId}"?` : "Restore files from the latest backup?", {
|
|
127
|
-
defaultValue: false,
|
|
128
|
-
});
|
|
129
|
-
if (!confirmed) {
|
|
130
|
-
throw (0, errors_1.cliError)("PROMPT_CANCELLED", "Rollback cancelled.");
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
async function chooseSetupStrategy(runtime) {
|
|
134
|
-
return runtime.selectOne("providers.json already exists. Choose a setup strategy.", [
|
|
135
|
-
{ value: "merge", label: "merge", hint: "keep existing providers and override by imported names" },
|
|
136
|
-
{ value: "overwrite", label: "overwrite", hint: "replace the existing registry" },
|
|
137
|
-
{ value: "cancel", label: "cancel", hint: "abort setup without writing" },
|
|
138
|
-
]);
|
|
139
|
-
}
|
|
140
|
-
async function collectSetupProviderDetails(runtime, profiles) {
|
|
141
|
-
const result = {};
|
|
142
|
-
for (const profile of profiles) {
|
|
143
|
-
const providerName = (await runtime.inputText(`Provider name for profile "${profile}"`, {
|
|
144
|
-
defaultValue: profile,
|
|
145
|
-
})).trim();
|
|
146
|
-
const apiKey = (await runtime.inputSecret(`API key for profile "${profile}"`)).trim();
|
|
147
|
-
const baseUrl = (await runtime.inputText(`Base URL for profile "${profile}" (optional)`)).trim();
|
|
148
|
-
const note = (await runtime.inputText(`Note for profile "${profile}" (optional)`)).trim();
|
|
149
|
-
const tags = await (0, add_interactive_1.promptTags)(runtime);
|
|
150
|
-
result[profile] = {
|
|
151
|
-
providerName: providerName || profile,
|
|
152
|
-
apiKey,
|
|
153
|
-
baseUrl: baseUrl || undefined,
|
|
154
|
-
note: note || undefined,
|
|
155
|
-
tags: tags.length > 0 ? tags : undefined,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
return result;
|
|
159
|
-
}
|
|
160
|
-
async function collectEditInput(runtime, current) {
|
|
161
|
-
const profile = (await runtime.inputText("Profile", { defaultValue: current.profile })).trim();
|
|
162
|
-
const apiKey = (await runtime.inputSecret("API key")).trim() || current.apiKey;
|
|
163
|
-
const baseUrl = (await runtime.inputText("Base URL (optional)", { defaultValue: current.baseUrl ?? "" })).trim();
|
|
164
|
-
const note = (await runtime.inputText("Note (optional)", { defaultValue: current.note ?? "" })).trim();
|
|
165
|
-
const tags = await (0, add_interactive_1.promptTags)(runtime, current.tags ?? []);
|
|
166
|
-
return {
|
|
167
|
-
profile,
|
|
168
|
-
apiKey,
|
|
169
|
-
baseUrl: baseUrl || undefined,
|
|
170
|
-
note: note || undefined,
|
|
171
|
-
tags,
|
|
172
|
-
};
|
|
173
|
-
}
|
|
3
|
+
exports.promptForProviderSelection = exports.getRollbackSummaryById = exports.getRollbackSummary = exports.exportTargetExists = exports.confirmRollback = exports.confirmProviderRemoval = exports.confirmImport = exports.confirmExportOverwrite = exports.collectSetupProviderDetails = exports.collectEditInput = exports.chooseSetupStrategy = exports.chooseSetupProfiles = exports.chooseCodexDir = exports.canPrompt = void 0;
|
|
4
|
+
var interactive_1 = require("../interaction/interactive");
|
|
5
|
+
Object.defineProperty(exports, "canPrompt", { enumerable: true, get: function () { return interactive_1.canPrompt; } });
|
|
6
|
+
Object.defineProperty(exports, "chooseCodexDir", { enumerable: true, get: function () { return interactive_1.chooseCodexDir; } });
|
|
7
|
+
Object.defineProperty(exports, "chooseSetupProfiles", { enumerable: true, get: function () { return interactive_1.chooseSetupProfiles; } });
|
|
8
|
+
Object.defineProperty(exports, "chooseSetupStrategy", { enumerable: true, get: function () { return interactive_1.chooseSetupStrategy; } });
|
|
9
|
+
Object.defineProperty(exports, "collectEditInput", { enumerable: true, get: function () { return interactive_1.collectEditInput; } });
|
|
10
|
+
Object.defineProperty(exports, "collectSetupProviderDetails", { enumerable: true, get: function () { return interactive_1.collectSetupProviderDetails; } });
|
|
11
|
+
Object.defineProperty(exports, "confirmExportOverwrite", { enumerable: true, get: function () { return interactive_1.confirmExportOverwrite; } });
|
|
12
|
+
Object.defineProperty(exports, "confirmImport", { enumerable: true, get: function () { return interactive_1.confirmImport; } });
|
|
13
|
+
Object.defineProperty(exports, "confirmProviderRemoval", { enumerable: true, get: function () { return interactive_1.confirmProviderRemoval; } });
|
|
14
|
+
Object.defineProperty(exports, "confirmRollback", { enumerable: true, get: function () { return interactive_1.confirmRollback; } });
|
|
15
|
+
Object.defineProperty(exports, "exportTargetExists", { enumerable: true, get: function () { return interactive_1.exportTargetExists; } });
|
|
16
|
+
Object.defineProperty(exports, "getRollbackSummary", { enumerable: true, get: function () { return interactive_1.getRollbackSummary; } });
|
|
17
|
+
Object.defineProperty(exports, "getRollbackSummaryById", { enumerable: true, get: function () { return interactive_1.getRollbackSummaryById; } });
|
|
18
|
+
Object.defineProperty(exports, "promptForProviderSelection", { enumerable: true, get: function () { return interactive_1.promptForProviderSelection; } });
|
package/dist/cli/output.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.renderSuccess = renderSuccess;
|
|
|
4
4
|
exports.renderFailure = renderFailure;
|
|
5
5
|
exports.outputSuccess = outputSuccess;
|
|
6
6
|
exports.outputFailure = outputFailure;
|
|
7
|
-
const fs_utils_1 = require("../
|
|
7
|
+
const fs_utils_1 = require("../storage/fs-utils");
|
|
8
8
|
/**
|
|
9
9
|
* Renders a successful command result for either JSON or human-readable output.
|
|
10
10
|
*/
|
|
@@ -120,7 +120,23 @@ function renderHumanSuccess(command, data, warnings) {
|
|
|
120
120
|
lines.push(`providersExists: ${String(data?.providersExists ?? false)}`);
|
|
121
121
|
lines.push(`currentProfile: ${String(data?.currentProfile ?? "")}`);
|
|
122
122
|
lines.push(`mappedProvider: ${String(data?.provider ?? "")}`);
|
|
123
|
+
lines.push(`issues: ${Array.isArray(data?.issues) ? (data?.issues).length : 0}`);
|
|
123
124
|
break;
|
|
125
|
+
case "config-show": {
|
|
126
|
+
lines.push(`activeProfile: ${String(data?.activeProfile ?? "")}`);
|
|
127
|
+
const profiles = data?.profiles ?? [];
|
|
128
|
+
for (const profile of profiles) {
|
|
129
|
+
lines.push(`${String(profile.name)} managed=${String(profile.managed)} active=${String(profile.isActive)} source=${String(profile.source)} model=${String(profile.model ?? "")} modelProvider=${String(profile.modelProvider ?? "")} baseUrl=${String(profile.baseUrl ?? "")}`);
|
|
130
|
+
}
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
case "config-list-profiles": {
|
|
134
|
+
const profiles = data?.profiles ?? [];
|
|
135
|
+
for (const profile of profiles) {
|
|
136
|
+
lines.push(`${String(profile.name)} managed=${String(profile.managed)} active=${String(profile.isActive)} source=${String(profile.source)}`);
|
|
137
|
+
}
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
124
140
|
case "switch":
|
|
125
141
|
lines.push(`Switched to provider ${String(data?.provider ?? "")} using profile ${String(data?.profile ?? "")}.`);
|
|
126
142
|
lines.push(`Backup: ${String(data?.backupPath ?? "")}`);
|
|
@@ -144,9 +160,15 @@ function renderHumanSuccess(command, data, warnings) {
|
|
|
144
160
|
break;
|
|
145
161
|
case "add":
|
|
146
162
|
lines.push(`Added provider ${String(data?.provider ?? "")}. Backup: ${String(data?.backupPath ?? "")}`);
|
|
163
|
+
if (Array.isArray(data?.createdProfileSections) && (data?.createdProfileSections).length > 0) {
|
|
164
|
+
lines.push(`Created profiles: ${(data?.createdProfileSections).join(", ")}`);
|
|
165
|
+
}
|
|
147
166
|
break;
|
|
148
167
|
case "remove":
|
|
149
168
|
lines.push(`Removed provider ${String(data?.provider ?? "")}. Backup: ${String(data?.backupPath ?? "")}`);
|
|
169
|
+
if (Array.isArray(data?.deletedProfileSections) && (data?.deletedProfileSections).length > 0) {
|
|
170
|
+
lines.push(`Deleted profiles: ${(data?.deletedProfileSections).join(", ")}`);
|
|
171
|
+
}
|
|
150
172
|
break;
|
|
151
173
|
case "doctor": {
|
|
152
174
|
const healthy = Boolean(data?.healthy);
|
package/dist/cli/prompt.js
CHANGED
|
@@ -1,110 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createPromptRuntime =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Creates the default prompt runtime backed by inquirer on the current process TTY.
|
|
11
|
-
*/
|
|
12
|
-
function createPromptRuntime() {
|
|
13
|
-
return {
|
|
14
|
-
isInteractive: () => Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
15
|
-
inputText: async (message, options) => {
|
|
16
|
-
return handlePromptCancellation(async () => {
|
|
17
|
-
const answer = await inquirer_1.default.prompt([
|
|
18
|
-
{
|
|
19
|
-
type: "input",
|
|
20
|
-
name: "value",
|
|
21
|
-
message,
|
|
22
|
-
default: options?.defaultValue ?? undefined,
|
|
23
|
-
},
|
|
24
|
-
]);
|
|
25
|
-
return String(answer.value ?? "");
|
|
26
|
-
});
|
|
27
|
-
},
|
|
28
|
-
inputSecret: async (message) => {
|
|
29
|
-
return handlePromptCancellation(async () => {
|
|
30
|
-
const answer = await inquirer_1.default.prompt([
|
|
31
|
-
{
|
|
32
|
-
type: "password",
|
|
33
|
-
name: "value",
|
|
34
|
-
message,
|
|
35
|
-
mask: "*",
|
|
36
|
-
},
|
|
37
|
-
]);
|
|
38
|
-
return String(answer.value ?? "");
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
selectOne: async (message, choices) => {
|
|
42
|
-
return handlePromptCancellation(async () => {
|
|
43
|
-
const answer = await inquirer_1.default.prompt([
|
|
44
|
-
{
|
|
45
|
-
type: "select",
|
|
46
|
-
name: "value",
|
|
47
|
-
message,
|
|
48
|
-
choices: choices.map((choice) => ({
|
|
49
|
-
value: choice.value,
|
|
50
|
-
name: choice.hint ? `${choice.label} (${choice.hint})` : choice.label,
|
|
51
|
-
})),
|
|
52
|
-
},
|
|
53
|
-
]);
|
|
54
|
-
return answer.value;
|
|
55
|
-
});
|
|
56
|
-
},
|
|
57
|
-
selectMany: async (message, choices, options) => {
|
|
58
|
-
return handlePromptCancellation(async () => {
|
|
59
|
-
const answer = await inquirer_1.default.prompt([
|
|
60
|
-
{
|
|
61
|
-
type: "checkbox",
|
|
62
|
-
name: "value",
|
|
63
|
-
message,
|
|
64
|
-
choices: choices.map((choice) => ({
|
|
65
|
-
value: choice.value,
|
|
66
|
-
name: choice.hint ? `${choice.label} (${choice.hint})` : choice.label,
|
|
67
|
-
checked: Boolean(options?.defaultValues?.includes(choice.value)),
|
|
68
|
-
})),
|
|
69
|
-
},
|
|
70
|
-
]);
|
|
71
|
-
return (Array.isArray(answer.value) ? answer.value : []);
|
|
72
|
-
});
|
|
73
|
-
},
|
|
74
|
-
confirmAction: async (message, options) => {
|
|
75
|
-
return handlePromptCancellation(async () => {
|
|
76
|
-
const answer = await inquirer_1.default.prompt([
|
|
77
|
-
{
|
|
78
|
-
type: "confirm",
|
|
79
|
-
name: "value",
|
|
80
|
-
message,
|
|
81
|
-
default: options?.defaultValue ?? false,
|
|
82
|
-
},
|
|
83
|
-
]);
|
|
84
|
-
return Boolean(answer.value);
|
|
85
|
-
});
|
|
86
|
-
},
|
|
87
|
-
writeLine: (message) => {
|
|
88
|
-
process.stdout.write(`${message}\n`);
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
async function handlePromptCancellation(run) {
|
|
93
|
-
try {
|
|
94
|
-
return await run();
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
if (isPromptCancellation(error)) {
|
|
98
|
-
throw (0, errors_1.cliError)("PROMPT_CANCELLED", "Interactive prompt was cancelled.");
|
|
99
|
-
}
|
|
100
|
-
throw (0, errors_1.cliError)("INVALID_ARGUMENT", "Interactive prompt failed.", {
|
|
101
|
-
cause: error instanceof Error ? error.message : String(error),
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
function isPromptCancellation(error) {
|
|
106
|
-
if (!(error instanceof Error)) {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
return error.name === "ExitPromptError" || error.message.includes("force closed");
|
|
110
|
-
}
|
|
3
|
+
exports.createPromptRuntime = void 0;
|
|
4
|
+
var prompt_1 = require("../interaction/prompt");
|
|
5
|
+
Object.defineProperty(exports, "createPromptRuntime", { enumerable: true, get: function () { return prompt_1.createPromptRuntime; } });
|