@praeviso/code-env-switch 0.1.0 → 0.1.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/.eslintrc.cjs +18 -0
- package/.github/workflows/npm-publish.yml +25 -0
- package/.vscode/settings.json +4 -0
- package/AGENTS.md +32 -0
- package/LICENSE +21 -0
- package/PLAN.md +33 -0
- package/README.md +208 -32
- package/README_zh.md +265 -0
- package/bin/cli/args.js +303 -0
- package/bin/cli/help.js +77 -0
- package/bin/cli/index.js +13 -0
- package/bin/commands/add.js +81 -0
- package/bin/commands/index.js +21 -0
- package/bin/commands/launch.js +330 -0
- package/bin/commands/list.js +57 -0
- package/bin/commands/show.js +10 -0
- package/bin/commands/statusline.js +12 -0
- package/bin/commands/unset.js +20 -0
- package/bin/commands/use.js +92 -0
- package/bin/config/defaults.js +85 -0
- package/bin/config/index.js +20 -0
- package/bin/config/io.js +72 -0
- package/bin/constants.js +27 -0
- package/bin/index.js +279 -0
- package/bin/profile/display.js +78 -0
- package/bin/profile/index.js +26 -0
- package/bin/profile/match.js +40 -0
- package/bin/profile/resolve.js +79 -0
- package/bin/profile/type.js +90 -0
- package/bin/shell/detect.js +40 -0
- package/bin/shell/index.js +18 -0
- package/bin/shell/snippet.js +92 -0
- package/bin/shell/utils.js +35 -0
- package/bin/statusline/claude.js +153 -0
- package/bin/statusline/codex.js +356 -0
- package/bin/statusline/index.js +469 -0
- package/bin/types.js +5 -0
- package/bin/ui/index.js +16 -0
- package/bin/ui/interactive.js +189 -0
- package/bin/ui/readline.js +76 -0
- package/bin/usage/index.js +709 -0
- package/code-env.example.json +36 -23
- package/package.json +14 -2
- package/src/cli/args.ts +318 -0
- package/src/cli/help.ts +75 -0
- package/src/cli/index.ts +5 -0
- package/src/commands/add.ts +91 -0
- package/src/commands/index.ts +10 -0
- package/src/commands/launch.ts +395 -0
- package/src/commands/list.ts +91 -0
- package/src/commands/show.ts +12 -0
- package/src/commands/statusline.ts +18 -0
- package/src/commands/unset.ts +19 -0
- package/src/commands/use.ts +121 -0
- package/src/config/defaults.ts +88 -0
- package/src/config/index.ts +19 -0
- package/src/config/io.ts +69 -0
- package/src/constants.ts +28 -0
- package/src/index.ts +359 -0
- package/src/profile/display.ts +77 -0
- package/src/profile/index.ts +12 -0
- package/src/profile/match.ts +41 -0
- package/src/profile/resolve.ts +84 -0
- package/src/profile/type.ts +83 -0
- package/src/shell/detect.ts +30 -0
- package/src/shell/index.ts +6 -0
- package/src/shell/snippet.ts +92 -0
- package/src/shell/utils.ts +30 -0
- package/src/statusline/claude.ts +172 -0
- package/src/statusline/codex.ts +393 -0
- package/src/statusline/index.ts +626 -0
- package/src/types.ts +95 -0
- package/src/ui/index.ts +5 -0
- package/src/ui/interactive.ts +220 -0
- package/src/ui/readline.ts +85 -0
- package/src/usage/index.ts +833 -0
- package/tsconfig.json +12 -0
- package/bin/codenv.js +0 -377
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createReadline = createReadline;
|
|
4
|
+
exports.ask = ask;
|
|
5
|
+
exports.askRequired = askRequired;
|
|
6
|
+
exports.askConfirm = askConfirm;
|
|
7
|
+
exports.askType = askType;
|
|
8
|
+
exports.askProfileName = askProfileName;
|
|
9
|
+
/**
|
|
10
|
+
* Readline utilities
|
|
11
|
+
*/
|
|
12
|
+
const readline = require("readline");
|
|
13
|
+
const match_1 = require("../profile/match");
|
|
14
|
+
function createReadline() {
|
|
15
|
+
return readline.createInterface({
|
|
16
|
+
input: process.stdin,
|
|
17
|
+
output: process.stdout,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function ask(rl, question) {
|
|
21
|
+
return new Promise((resolve) => {
|
|
22
|
+
rl.question(question, (answer) => resolve(answer));
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async function askRequired(rl, question) {
|
|
26
|
+
while (true) {
|
|
27
|
+
const answer = String(await ask(rl, question)).trim();
|
|
28
|
+
if (answer)
|
|
29
|
+
return answer;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function askConfirm(rl, question) {
|
|
33
|
+
const answer = String(await ask(rl, question)).trim().toLowerCase();
|
|
34
|
+
return answer === "y" || answer === "yes";
|
|
35
|
+
}
|
|
36
|
+
async function askType(rl) {
|
|
37
|
+
while (true) {
|
|
38
|
+
const answer = String(await ask(rl, "Select type (1=codex, 2=claude): "))
|
|
39
|
+
.trim()
|
|
40
|
+
.toLowerCase();
|
|
41
|
+
if (answer === "1")
|
|
42
|
+
return "codex";
|
|
43
|
+
if (answer === "2")
|
|
44
|
+
return "claude";
|
|
45
|
+
const normalized = answer.replace(/[\s-]+/g, "");
|
|
46
|
+
if (normalized === "codex")
|
|
47
|
+
return "codex";
|
|
48
|
+
if (normalized === "claude" ||
|
|
49
|
+
normalized === "claudecode" ||
|
|
50
|
+
normalized === "cc")
|
|
51
|
+
return "claude";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function askProfileName(rl, config, defaultName, type) {
|
|
55
|
+
while (true) {
|
|
56
|
+
const answer = String(await ask(rl, `Profile name (default: ${defaultName}): `)).trim();
|
|
57
|
+
const baseName = answer || defaultName;
|
|
58
|
+
if (!baseName)
|
|
59
|
+
continue;
|
|
60
|
+
const matches = (0, match_1.findProfileKeysByName)(config, baseName, type);
|
|
61
|
+
if (matches.length === 0) {
|
|
62
|
+
return { name: baseName, key: null };
|
|
63
|
+
}
|
|
64
|
+
if (matches.length === 1) {
|
|
65
|
+
const overwrite = String(await ask(rl, `Profile "${baseName}" exists. Overwrite? (y/N): `))
|
|
66
|
+
.trim()
|
|
67
|
+
.toLowerCase();
|
|
68
|
+
if (overwrite === "y" || overwrite === "yes") {
|
|
69
|
+
return { name: baseName, key: matches[0] };
|
|
70
|
+
}
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
console.log(`Multiple profiles named "${baseName}" for type "${type}". ` +
|
|
74
|
+
`Use a unique name or update by key in config.`);
|
|
75
|
+
}
|
|
76
|
+
}
|