@minniexcode/codex-switch 0.0.9 → 0.0.11
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.AI.md +52 -13
- package/README.CN.md +94 -39
- package/README.md +75 -33
- package/dist/app/add-provider.js +29 -26
- package/dist/app/bridge.js +15 -15
- package/dist/app/edit-provider.js +2 -18
- package/dist/app/get-status.js +35 -13
- package/dist/app/import-providers.js +1 -1
- package/dist/app/init-codex.js +13 -14
- package/dist/app/list-providers.js +0 -1
- package/dist/app/remove-provider.js +1 -1
- package/dist/app/run-doctor.js +21 -39
- package/dist/app/run-mutation.js +3 -2
- package/dist/app/setup-codex.js +30 -18
- package/dist/app/show-config.js +1 -5
- package/dist/app/switch-provider.js +16 -33
- package/dist/cli/output.js +4 -6
- package/dist/cli.js +35 -3
- package/dist/commands/args.js +2 -2
- package/dist/commands/dispatch.js +40 -0
- package/dist/commands/handlers.js +202 -84
- package/dist/commands/help.js +2 -0
- package/dist/commands/registry.js +33 -12
- package/dist/domain/backups.js +4 -4
- package/dist/domain/config.js +102 -61
- package/dist/domain/providers.js +12 -5
- package/dist/domain/runtime-state.js +81 -4
- package/dist/domain/setup.js +58 -3
- package/dist/interaction/add-interactive.js +55 -1
- package/dist/interaction/interactive.js +1 -5
- package/dist/runtime/copilot-adapter.js +56 -13
- package/dist/runtime/copilot-bridge.js +392 -44
- package/dist/runtime/copilot-cli.js +142 -0
- package/dist/runtime/copilot-installer.js +59 -11
- package/dist/runtime/copilot-sdk-loader.js +5 -5
- package/dist/storage/auth-repo.js +28 -77
- package/dist/storage/backup-repo.js +4 -4
- package/dist/storage/codex-paths.js +34 -8
- package/dist/storage/config-repo.js +1 -36
- package/dist/storage/lock-repo.js +2 -4
- package/dist/storage/runtime-state-repo.js +43 -10
- package/dist/storage/tool-config-repo.js +111 -0
- package/docs/Design/codex-switch-copilot-integration-design.md +517 -0
- package/docs/Design/codex-switch-v0.0.10-design.md +669 -0
- package/docs/Design/codex-switch-v0.0.11-design.md +824 -0
- package/docs/PRD/codex-switch-prd-v0.0.10.md +406 -0
- package/docs/PRD/codex-switch-prd-v0.0.11.md +577 -0
- package/docs/cli-usage.md +166 -271
- package/docs/codex-switch-product-overview.md +2 -2
- package/docs/codex-switch-technical-architecture.md +6 -5
- package/package.json +1 -1
|
@@ -35,45 +35,78 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.getCopilotBridgeStatePath = getCopilotBridgeStatePath;
|
|
37
37
|
exports.readCopilotBridgeState = readCopilotBridgeState;
|
|
38
|
+
exports.inspectCopilotBridgeState = inspectCopilotBridgeState;
|
|
38
39
|
exports.writeCopilotBridgeState = writeCopilotBridgeState;
|
|
39
40
|
exports.clearCopilotBridgeState = clearCopilotBridgeState;
|
|
40
41
|
const fs = __importStar(require("node:fs"));
|
|
41
|
-
const os = __importStar(require("node:os"));
|
|
42
42
|
const path = __importStar(require("node:path"));
|
|
43
|
+
const errors_1 = require("../domain/errors");
|
|
44
|
+
const codex_paths_1 = require("./codex-paths");
|
|
43
45
|
const fs_utils_1 = require("./fs-utils");
|
|
44
46
|
/**
|
|
45
|
-
* Returns the
|
|
47
|
+
* Returns the tool-home runtime state file used by Copilot bridge helpers.
|
|
46
48
|
*/
|
|
47
|
-
function getCopilotBridgeStatePath() {
|
|
49
|
+
function getCopilotBridgeStatePath(runtimeDir) {
|
|
48
50
|
const override = process.env.CODEX_SWITCH_RUNTIME_STATE_DIR;
|
|
49
51
|
if (override && override.trim() !== "") {
|
|
50
52
|
return path.join(path.resolve(override), "copilot-bridge-state.json");
|
|
51
53
|
}
|
|
52
|
-
|
|
54
|
+
const baseRuntimeDir = runtimeDir ? path.resolve(runtimeDir) : path.join((0, codex_paths_1.resolveCodexSwitchHome)(), "runtime");
|
|
55
|
+
return path.join(baseRuntimeDir, "copilot-bridge-state.json");
|
|
53
56
|
}
|
|
54
57
|
/**
|
|
55
58
|
* Reads the Copilot bridge state manifest when present.
|
|
56
59
|
*/
|
|
57
|
-
function readCopilotBridgeState() {
|
|
58
|
-
const statePath = getCopilotBridgeStatePath();
|
|
60
|
+
function readCopilotBridgeState(runtimeDir) {
|
|
61
|
+
const statePath = getCopilotBridgeStatePath(runtimeDir);
|
|
59
62
|
if (!fs.existsSync(statePath)) {
|
|
60
63
|
return null;
|
|
61
64
|
}
|
|
62
65
|
return JSON.parse(fs.readFileSync(statePath, "utf8"));
|
|
63
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Safely inspects the runtime-state file for status/doctor style read paths.
|
|
69
|
+
*/
|
|
70
|
+
function inspectCopilotBridgeState(runtimeDir) {
|
|
71
|
+
const statePath = getCopilotBridgeStatePath(runtimeDir);
|
|
72
|
+
if (!fs.existsSync(statePath)) {
|
|
73
|
+
return {
|
|
74
|
+
exists: false,
|
|
75
|
+
valid: false,
|
|
76
|
+
parseError: null,
|
|
77
|
+
state: null,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
return {
|
|
82
|
+
exists: true,
|
|
83
|
+
valid: true,
|
|
84
|
+
parseError: null,
|
|
85
|
+
state: readCopilotBridgeState(runtimeDir),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
return {
|
|
90
|
+
exists: true,
|
|
91
|
+
valid: false,
|
|
92
|
+
parseError: (0, errors_1.normalizeError)(error).message,
|
|
93
|
+
state: null,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
64
97
|
/**
|
|
65
98
|
* Persists the Copilot bridge state manifest.
|
|
66
99
|
*/
|
|
67
|
-
function writeCopilotBridgeState(state) {
|
|
68
|
-
const statePath = getCopilotBridgeStatePath();
|
|
100
|
+
function writeCopilotBridgeState(state, runtimeDir) {
|
|
101
|
+
const statePath = getCopilotBridgeStatePath(runtimeDir);
|
|
69
102
|
(0, fs_utils_1.ensureDir)(path.dirname(statePath));
|
|
70
103
|
(0, fs_utils_1.writeTextFileAtomic)(statePath, `${JSON.stringify(state, null, 2)}\n`);
|
|
71
104
|
}
|
|
72
105
|
/**
|
|
73
106
|
* Deletes the Copilot bridge state manifest when present.
|
|
74
107
|
*/
|
|
75
|
-
function clearCopilotBridgeState() {
|
|
76
|
-
const statePath = getCopilotBridgeStatePath();
|
|
108
|
+
function clearCopilotBridgeState(runtimeDir) {
|
|
109
|
+
const statePath = getCopilotBridgeStatePath(runtimeDir);
|
|
77
110
|
if (fs.existsSync(statePath)) {
|
|
78
111
|
fs.rmSync(statePath, { force: true });
|
|
79
112
|
}
|
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.readToolConfigIfExists = readToolConfigIfExists;
|
|
37
|
+
exports.ensureToolConfig = ensureToolConfig;
|
|
38
|
+
exports.writeToolConfig = writeToolConfig;
|
|
39
|
+
const fs = __importStar(require("node:fs"));
|
|
40
|
+
const errors_1 = require("../domain/errors");
|
|
41
|
+
const fs_utils_1 = require("./fs-utils");
|
|
42
|
+
/**
|
|
43
|
+
* Reads the optional tool-level codex-switch config file when present.
|
|
44
|
+
*/
|
|
45
|
+
function readToolConfigIfExists(toolConfigPath) {
|
|
46
|
+
if (!fs.existsSync(toolConfigPath)) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const parsed = JSON.parse(fs.readFileSync(toolConfigPath, "utf8"));
|
|
51
|
+
return validateToolConfig(parsed, toolConfigPath);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
throw (0, errors_1.cliError)("INVALID_CONFIG", "codex-switch.json is invalid.", {
|
|
55
|
+
file: toolConfigPath,
|
|
56
|
+
cause: error instanceof Error ? error.message : String(error),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Ensures the tool-level config file exists with the minimum stable fields.
|
|
62
|
+
*/
|
|
63
|
+
function ensureToolConfig(toolConfigPath, version, defaultCodexDir) {
|
|
64
|
+
const current = readToolConfigIfExists(toolConfigPath);
|
|
65
|
+
if (current) {
|
|
66
|
+
return {
|
|
67
|
+
created: false,
|
|
68
|
+
config: current,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const next = {
|
|
72
|
+
version,
|
|
73
|
+
};
|
|
74
|
+
if (defaultCodexDir) {
|
|
75
|
+
next.defaultCodexDir = defaultCodexDir;
|
|
76
|
+
}
|
|
77
|
+
(0, fs_utils_1.ensureDir)(require("node:path").dirname(toolConfigPath));
|
|
78
|
+
(0, fs_utils_1.writeTextFileAtomic)(toolConfigPath, `${JSON.stringify(next, null, 2)}\n`);
|
|
79
|
+
return {
|
|
80
|
+
created: true,
|
|
81
|
+
config: next,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Writes the tool-level config file with a normalized shape.
|
|
86
|
+
*/
|
|
87
|
+
function writeToolConfig(toolConfigPath, config) {
|
|
88
|
+
const normalized = validateToolConfig(config, toolConfigPath);
|
|
89
|
+
(0, fs_utils_1.writeTextFileAtomic)(toolConfigPath, `${JSON.stringify(normalized, null, 2)}\n`);
|
|
90
|
+
}
|
|
91
|
+
function validateToolConfig(config, toolConfigPath) {
|
|
92
|
+
if (!config || typeof config !== "object") {
|
|
93
|
+
throw (0, errors_1.cliError)("INVALID_CONFIG", "codex-switch.json must contain a JSON object.", {
|
|
94
|
+
file: toolConfigPath,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (typeof config.version !== "string" || config.version.trim() === "") {
|
|
98
|
+
throw (0, errors_1.cliError)("INVALID_CONFIG", "codex-switch.json requires a non-empty version field.", {
|
|
99
|
+
file: toolConfigPath,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (config.defaultCodexDir !== undefined && typeof config.defaultCodexDir !== "string") {
|
|
103
|
+
throw (0, errors_1.cliError)("INVALID_CONFIG", "codex-switch.json.defaultCodexDir must be a string when provided.", {
|
|
104
|
+
file: toolConfigPath,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
version: config.version,
|
|
109
|
+
defaultCodexDir: config.defaultCodexDir,
|
|
110
|
+
};
|
|
111
|
+
}
|