@minniexcode/codex-switch 0.0.4 → 0.0.5
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/dist/app/add-provider.js +32 -1
- package/dist/app/edit-provider.js +74 -1
- package/dist/app/get-status.js +9 -2
- package/dist/app/import-providers.js +37 -1
- package/dist/app/list-config-profiles.js +29 -0
- package/dist/app/remove-provider.js +34 -2
- package/dist/app/run-doctor.js +22 -21
- package/dist/app/setup-codex.js +33 -16
- package/dist/app/show-config.js +34 -0
- package/dist/app/switch-provider.js +5 -2
- package/dist/cli/args.js +13 -2
- package/dist/cli/help.js +42 -5
- package/dist/cli/interactive.js +56 -0
- package/dist/cli/output.js +22 -0
- package/dist/cli.js +101 -12
- package/dist/domain/config.js +471 -39
- package/dist/infra/codex-cli.js +18 -3
- package/dist/infra/codex-discovery.js +3 -41
- package/dist/infra/codex-paths.js +1 -1
- package/dist/infra/config-repo.js +102 -9
- package/docs/Design/codex-switch-v0.0.5-design.md +922 -0
- package/docs/PRD/codex-switch-prd-v0.0.5-to-v0.1.0.md +308 -0
- package/docs/PRD/codex-switch-prd-v0.1.0.md +210 -260
- package/package.json +1 -1
- /package/docs/{codex-switch-v0.0.4-design.md → Design/codex-switch-v0.0.4-design.md} +0 -0
|
@@ -1,12 +1,53 @@
|
|
|
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
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.readConfigFile = readConfigFile;
|
|
37
|
+
exports.readStructuredConfig = readStructuredConfig;
|
|
4
38
|
exports.readCurrentProfile = readCurrentProfile;
|
|
5
39
|
exports.listConfigProfiles = listConfigProfiles;
|
|
6
40
|
exports.ensureProfileExists = ensureProfileExists;
|
|
7
41
|
exports.updateTopLevelProfile = updateTopLevelProfile;
|
|
8
|
-
|
|
42
|
+
exports.createConfigMutationPlan = createConfigMutationPlan;
|
|
43
|
+
exports.applyConfigMutation = applyConfigMutation;
|
|
44
|
+
exports.findCodexDirCandidates = findCodexDirCandidates;
|
|
45
|
+
const fs = __importStar(require("node:fs"));
|
|
46
|
+
const os = __importStar(require("node:os"));
|
|
47
|
+
const path = __importStar(require("node:path"));
|
|
9
48
|
const config_1 = require("../domain/config");
|
|
49
|
+
const errors_1 = require("../domain/errors");
|
|
50
|
+
const codex_paths_1 = require("./codex-paths");
|
|
10
51
|
const fs_utils_1 = require("./fs-utils");
|
|
11
52
|
/**
|
|
12
53
|
* Reads config.toml and throws a typed error when the file is missing.
|
|
@@ -14,12 +55,26 @@ const fs_utils_1 = require("./fs-utils");
|
|
|
14
55
|
function readConfigFile(configPath) {
|
|
15
56
|
return (0, fs_utils_1.readRequiredFile)(configPath, "CONFIG_NOT_FOUND", "config.toml");
|
|
16
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Reads and parses config.toml into the managed structured document shape.
|
|
60
|
+
*/
|
|
61
|
+
function readStructuredConfig(configPath) {
|
|
62
|
+
const content = readConfigFile(configPath);
|
|
63
|
+
try {
|
|
64
|
+
return (0, config_1.parseStructuredConfig)(content);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
throw (0, errors_1.cliError)("CONFIG_PARSE_ERROR", "Failed to parse config.toml.", {
|
|
68
|
+
file: configPath,
|
|
69
|
+
cause: (0, errors_1.normalizeError)(error).message,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
17
73
|
/**
|
|
18
74
|
* Reads the active top-level profile from config.toml.
|
|
19
75
|
*/
|
|
20
76
|
function readCurrentProfile(configPath) {
|
|
21
|
-
const
|
|
22
|
-
const profile = (0, config_1.parseTopLevelProfile)(content);
|
|
77
|
+
const profile = readStructuredConfig(configPath).activeProfile ?? (0, config_1.parseTopLevelProfile)(readConfigFile(configPath));
|
|
23
78
|
if (!profile) {
|
|
24
79
|
throw (0, errors_1.cliError)("PROFILE_NOT_FOUND", "No top-level profile is set in config.toml.", {
|
|
25
80
|
file: configPath,
|
|
@@ -31,26 +86,64 @@ function readCurrentProfile(configPath) {
|
|
|
31
86
|
* Lists all named profile sections declared in config.toml.
|
|
32
87
|
*/
|
|
33
88
|
function listConfigProfiles(configPath) {
|
|
34
|
-
return
|
|
89
|
+
return new Set(readStructuredConfig(configPath).profiles.map((profile) => profile.name));
|
|
35
90
|
}
|
|
36
91
|
/**
|
|
37
92
|
* Verifies that a provider's target profile exists before a switch operation proceeds.
|
|
38
93
|
*/
|
|
39
94
|
function ensureProfileExists(configPath, profile, provider) {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
if (!profiles.has(profile)) {
|
|
95
|
+
const document = readStructuredConfig(configPath);
|
|
96
|
+
if (!document.profiles.some((entry) => entry.name === profile)) {
|
|
43
97
|
throw (0, errors_1.cliError)("PROFILE_NOT_FOUND", `Profile "${profile}" does not exist in config.toml.`, {
|
|
44
98
|
file: configPath,
|
|
45
99
|
provider,
|
|
46
100
|
profile,
|
|
47
101
|
});
|
|
48
102
|
}
|
|
49
|
-
return
|
|
103
|
+
return document;
|
|
50
104
|
}
|
|
51
105
|
/**
|
|
52
106
|
* Rewrites config.toml so the requested profile becomes the active top-level profile.
|
|
53
107
|
*/
|
|
54
108
|
function updateTopLevelProfile(configPath, configContent, profile) {
|
|
55
|
-
(0, fs_utils_1.writeTextFileAtomic)(configPath, (0, config_1.
|
|
109
|
+
(0, fs_utils_1.writeTextFileAtomic)(configPath, (0, config_1.applyPatchOperations)(configContent, (0, config_1.planConfigMutation)((0, config_1.parseStructuredConfig)(configContent), {
|
|
110
|
+
setActiveProfile: profile,
|
|
111
|
+
}).operations));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Exposes the config mutation planner to application services.
|
|
115
|
+
*/
|
|
116
|
+
function createConfigMutationPlan(document, args) {
|
|
117
|
+
return (0, config_1.planConfigMutation)(document, args);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Applies a previously generated mutation plan to config.toml in one write.
|
|
121
|
+
*/
|
|
122
|
+
function applyConfigMutation(configPath, document, plan) {
|
|
123
|
+
(0, fs_utils_1.writeTextFileAtomic)(configPath, (0, config_1.applyPatchOperations)(document.rawText, plan.operations));
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Finds candidate Codex directories in a stable, non-recursive order.
|
|
127
|
+
*/
|
|
128
|
+
function findCodexDirCandidates(explicitCodexDir) {
|
|
129
|
+
if (explicitCodexDir) {
|
|
130
|
+
return [(0, codex_paths_1.resolveCodexDir)(explicitCodexDir)];
|
|
131
|
+
}
|
|
132
|
+
const candidates = new Set();
|
|
133
|
+
const ordered = [];
|
|
134
|
+
const envCandidate = process.env[codex_paths_1.CODEX_DIR_ENV_NAME];
|
|
135
|
+
if (envCandidate) {
|
|
136
|
+
ordered.push((0, codex_paths_1.resolveCodexDir)(envCandidate));
|
|
137
|
+
}
|
|
138
|
+
if (process.env.NODE_ENV === "development") {
|
|
139
|
+
ordered.push(path.resolve(process.cwd(), "dev-codex", "local-sandbox"));
|
|
140
|
+
}
|
|
141
|
+
ordered.push(path.join(os.homedir(), ".codex"));
|
|
142
|
+
for (const candidate of ordered) {
|
|
143
|
+
if (!candidate || candidates.has(candidate) || !fs.existsSync(candidate)) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
candidates.add(candidate);
|
|
147
|
+
}
|
|
148
|
+
return [...candidates];
|
|
56
149
|
}
|