your-cto-jev 0.2.0 → 0.2.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/README.md +2 -1
- package/dist/hooks.js +11 -2
- package/dist/i18n.js +26 -10
- package/dist/index.js +19 -4
- package/dist/setup.js +2 -3
- package/dist/update.js +57 -0
- package/dist/wizard.js +57 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ cd your-project
|
|
|
75
75
|
cto setup
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
To update later, run `cto update`. Projects you already set up pick up the new version automatically: every hook only calls `cto`, and all the logic lives in the package. `cto` checks npm for a new version at most once a day and mentions it in its once-per-session notice, never on its own.
|
|
79
79
|
|
|
80
80
|
`cto setup` walks you through it in the terminal:
|
|
81
81
|
|
|
@@ -180,6 +180,7 @@ Nothing else is uploaded, and nothing is logged unless you set `CTO_DEBUG=1`. Th
|
|
|
180
180
|
| `CTO_FAILOVER=0` | Never switch providers |
|
|
181
181
|
| `CTO_LANG` | `en` or `zh-TW` (default: your locale) |
|
|
182
182
|
| `CTO_DEBUG=1` | Write masked hook input to `debug_stdin.json` |
|
|
183
|
+
| `CTO_NO_UPDATE_CHECK=1` | Never check npm for a new version |
|
|
183
184
|
|
|
184
185
|
## Known limitations
|
|
185
186
|
|
package/dist/hooks.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
1
2
|
import { styleText } from 'node:util';
|
|
3
|
+
import { checkUpdate, currentVersion } from './update.js';
|
|
2
4
|
import { evaluate, providerOrder, providers } from './api.js';
|
|
3
5
|
import { freshErrors, loadBrain, loadConfig, saveBrain } from './brain.js';
|
|
4
6
|
import { chunkDiff, filterDiff, pool } from './diff.js';
|
|
@@ -79,6 +81,9 @@ function verdict(lang, signal, v, cfg, color) {
|
|
|
79
81
|
// Test files, snapshots, test runner configs and package.json (test script). Matched on diff headers.
|
|
80
82
|
const TESTISH = /^diff --git a\/.+? b\/(?:.*\/)?(?:(?:tests?|__tests__|spec)\/.*|[^/]*\.(?:test|spec)\.[cm]?[jt]sx?|test_[^/]*\.py|[^/]*_test\.(?:py|go)|[^/]*\.snap|(?:jest|vitest|karma|playwright)\.config\.[^/]*|pytest\.ini|conftest\.py|tox\.ini|package\.json)$/m;
|
|
81
83
|
export const touchesTests = (diff) => TESTISH.test(diff);
|
|
84
|
+
// Pinned diff format: user config (noprefix, color.diff=always, external diff, textconv) would break parsing and masking.
|
|
85
|
+
export const DIFF_ARGS = ['diff', '--cached', '--no-color', '--no-ext-diff', '--no-textconv', '--src-prefix=a/', '--dst-prefix=b/'];
|
|
86
|
+
export const stagedDiff = (cwd) => execFileSync('git', DIFF_ARGS, { cwd, encoding: 'utf8', maxBuffer: 256 * 1024 * 1024, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
82
87
|
// ---------- git-commit ----------
|
|
83
88
|
export async function gitCommit(rawDiff, { root, lang, now }) {
|
|
84
89
|
const cfg = loadConfig(root);
|
|
@@ -134,9 +139,13 @@ export async function gitCommit(rawDiff, { root, lang, now }) {
|
|
|
134
139
|
return out;
|
|
135
140
|
}
|
|
136
141
|
// ---------- pre (Bash / shell command gate, any agent) ----------
|
|
137
|
-
function sessionNotice(brain, sessionId, lang, r, notices) {
|
|
142
|
+
async function sessionNotice(brain, sessionId, lang, r, notices) {
|
|
138
143
|
if (!sessionId || brain.notified_sessions.includes(sessionId))
|
|
139
144
|
return;
|
|
145
|
+
// Piggyback on the once-per-session notice: at most one registry call a day, never extra noise.
|
|
146
|
+
const latest = await checkUpdate();
|
|
147
|
+
if (latest)
|
|
148
|
+
notices.add(t(lang, 'update_available', { latest, current: currentVersion() }));
|
|
140
149
|
brain.notified_sessions = [...brain.notified_sessions, sessionId].slice(-20);
|
|
141
150
|
if (r.ok)
|
|
142
151
|
notices.add(t(lang, 'using', { name: providers[r.provider].label }));
|
|
@@ -165,7 +174,7 @@ export async function agentPre(agent, input, { root, lang, now }) {
|
|
|
165
174
|
const r = await evaluate({ state, questions, ...(sessionId && { session_id: sessionId }) }, { brain, lang, timeoutMs: 2000, notices, now });
|
|
166
175
|
if (!r.ok)
|
|
167
176
|
brain.skipped_attempts++;
|
|
168
|
-
sessionNotice(brain, sessionId, lang, r, notices);
|
|
177
|
+
await sessionNotice(brain, sessionId, lang, r, notices);
|
|
169
178
|
let out = { code: 0, stderr: [] };
|
|
170
179
|
if (r.ok) {
|
|
171
180
|
for (const s of ['destructive_command', 'infinite_loop']) {
|
package/dist/i18n.js
CHANGED
|
@@ -62,11 +62,17 @@ const messages = {
|
|
|
62
62
|
setup_agent: (v) => `[cto] ${v.label} hooks 已寫入 ${v.path}`,
|
|
63
63
|
uninstall_agent: (v) => `[cto] 已從 ${v.path} 移除 ${v.label} hooks`,
|
|
64
64
|
note_codex_trust: () => '[cto] 注意:Codex 只在專案被信任後才執行 .codex/ 的 hook,第一次在此目錄開 codex 時請選擇信任。',
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
wiz_intro: () => '\ncto 設定共兩步:1. 選擇要保護的 coding agent 2. 設定 Jev API key\n(git commit 檢查一律安裝,所有 agent 和手動 commit 共用)',
|
|
66
|
+
wiz_step_agents: () => '\n步驟 1/2:要攔截哪些 coding agent 的指令?',
|
|
67
|
+
wiz_agents_hint: () => '輸入編號切換勾選(例如 3 或 1,3),直接 Enter 確認:',
|
|
68
|
+
wiz_invalid: () => ' 看不懂這個輸入,請輸入清單上的編號,例如 1 或 1,3。',
|
|
67
69
|
wiz_found: () => '(已偵測到)',
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
wiz_step_keys: () => '\n步驟 2/2:Jev API key',
|
|
71
|
+
wiz_keys_present: () => '[cto] 已從環境變數或憑證檔找到 Jev API key,略過這步。要重設請執行 cto setup --keys',
|
|
72
|
+
wiz_keys: (v) => `可用的 provider 如下,至少要設定一個 cto 才會開始檢查。key 存在 ${v.path},只有你的帳號可讀,不會進 git。`,
|
|
73
|
+
wiz_provider_openrouter: () => 'OpenRouter:最簡單,只要一組 API key(openrouter.ai)',
|
|
74
|
+
wiz_provider_cloudflare: () => 'Cloudflare Workers AI:需要 Account ID 與 API token,且帳號的 AI Gateway 要開啟 Authenticated Gateway',
|
|
75
|
+
wiz_providers_hint: () => '要設定哪些?輸入編號(例如 1 或 1,2),直接 Enter 先跳過:',
|
|
70
76
|
wiz_or_key: () => ' OpenRouter API key: ',
|
|
71
77
|
wiz_cf_account: () => ' Cloudflare Account ID: ',
|
|
72
78
|
wiz_cf_token: () => ' Cloudflare API token: ',
|
|
@@ -76,7 +82,9 @@ const messages = {
|
|
|
76
82
|
wiz_save_anyway: () => ' 仍要儲存這組 key 嗎?[y/N] ',
|
|
77
83
|
wiz_saved: (v) => `[cto] key 已儲存到 ${v.path}`,
|
|
78
84
|
wiz_no_keys: () => '[cto] 沒有設定任何 key,cto 會全部放行,之後可執行 cto setup --keys 補上。',
|
|
79
|
-
|
|
85
|
+
update_available: (v) => `[cto] 有新版 ${v.latest}(目前 ${v.current}),執行 cto update 更新`,
|
|
86
|
+
update_done: () => '[cto] 已更新。已設定過的專案不用重跑 cto setup。',
|
|
87
|
+
usage: () => '用法:cto update | cto --version | cto setup [--agents claude,cursor,gemini,codex] [--keys] [--yes] [--uninstall] | cto --hook <git-commit|AGENT-pre|AGENT-post>',
|
|
80
88
|
},
|
|
81
89
|
en: {
|
|
82
90
|
reason_402: () => 'out of credits',
|
|
@@ -110,11 +118,17 @@ const messages = {
|
|
|
110
118
|
setup_agent: (v) => `[cto] ${v.label} hooks written to ${v.path}`,
|
|
111
119
|
uninstall_agent: (v) => `[cto] Removed ${v.label} hooks from ${v.path}`,
|
|
112
120
|
note_codex_trust: () => '[cto] Note: Codex only runs .codex/ hooks once the project is trusted. Trust it the first time you open codex here.',
|
|
113
|
-
|
|
114
|
-
|
|
121
|
+
wiz_intro: () => '\ncto setup has two steps: 1. pick the coding agents to protect 2. set up a Jev API key\n(the git commit check is always installed and covers every agent and manual commits)',
|
|
122
|
+
wiz_step_agents: () => '\nStep 1/2: Which coding agents should have their commands checked?',
|
|
123
|
+
wiz_agents_hint: () => 'Type numbers to toggle (e.g. 3 or 1,3), or press Enter to confirm: ',
|
|
124
|
+
wiz_invalid: () => ' Did not understand that. Type numbers from the list, e.g. 1 or 1,3.',
|
|
115
125
|
wiz_found: () => ' (detected)',
|
|
116
|
-
|
|
117
|
-
|
|
126
|
+
wiz_step_keys: () => '\nStep 2/2: Jev API key',
|
|
127
|
+
wiz_keys_present: () => '[cto] Found a Jev API key in env or the credentials file, skipping this step. Run cto setup --keys to change it.',
|
|
128
|
+
wiz_keys: (v) => `These providers are available. Set up at least one, or cto checks nothing. Keys are stored in ${v.path}, readable only by you, never in git.`,
|
|
129
|
+
wiz_provider_openrouter: () => 'OpenRouter: easiest, one API key (openrouter.ai)',
|
|
130
|
+
wiz_provider_cloudflare: () => 'Cloudflare Workers AI: Account ID plus API token, and Authenticated Gateway must be on in your AI Gateway',
|
|
131
|
+
wiz_providers_hint: () => 'Which ones? Type numbers (e.g. 1 or 1,2), or press Enter to skip for now: ',
|
|
118
132
|
wiz_or_key: () => ' OpenRouter API key: ',
|
|
119
133
|
wiz_cf_account: () => ' Cloudflare Account ID: ',
|
|
120
134
|
wiz_cf_token: () => ' Cloudflare API token: ',
|
|
@@ -124,7 +138,9 @@ const messages = {
|
|
|
124
138
|
wiz_save_anyway: () => ' Save this key anyway? [y/N] ',
|
|
125
139
|
wiz_saved: (v) => `[cto] Keys saved to ${v.path}`,
|
|
126
140
|
wiz_no_keys: () => '[cto] No key set, so cto lets everything through. Run cto setup --keys later.',
|
|
127
|
-
|
|
141
|
+
update_available: (v) => `[cto] Version ${v.latest} is available (you have ${v.current}). Run cto update`,
|
|
142
|
+
update_done: () => '[cto] Updated. Projects already set up do not need cto setup again.',
|
|
143
|
+
usage: () => 'Usage: cto update | cto --version | cto setup [--agents claude,cursor,gemini,codex] [--keys] [--yes] [--uninstall] | cto --hook <git-commit|AGENT-pre|AGENT-post>',
|
|
128
144
|
},
|
|
129
145
|
};
|
|
130
146
|
export function t(lang, key, vars = {}) {
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,8 @@ import { writeFileSync } from 'node:fs';
|
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { agentNames, agents } from './agents.js';
|
|
5
5
|
import { applyCredentials, findRoot } from './brain.js';
|
|
6
|
-
import { agentPost, agentPre, gitCommit } from './hooks.js';
|
|
6
|
+
import { agentPost, agentPre, gitCommit, stagedDiff } from './hooks.js';
|
|
7
|
+
import { checkUpdate, currentVersion, runUpdate } from './update.js';
|
|
7
8
|
import { detectLang, t } from './i18n.js';
|
|
8
9
|
import { maskDiff, maskSensitiveState } from './masker.js';
|
|
9
10
|
import { detectAgents, setup } from './setup.js';
|
|
@@ -25,17 +26,20 @@ function emit(out) {
|
|
|
25
26
|
process.exitCode = out.code;
|
|
26
27
|
}
|
|
27
28
|
async function runHook(name) {
|
|
28
|
-
const raw = await readStdin();
|
|
29
29
|
const lang = detectLang();
|
|
30
30
|
const debug = (root, text) => {
|
|
31
31
|
if (process.env.CTO_DEBUG === '1')
|
|
32
32
|
writeFileSync(join(root, 'debug_stdin.json'), text);
|
|
33
33
|
};
|
|
34
34
|
if (name === 'git-commit') {
|
|
35
|
+
// Read the staged diff ourselves with pinned args. Never touch stdin here: older hook blocks still pipe a diff
|
|
36
|
+
// (ignored, harmless), and an agent's shell may hand us a pipe that never closes.
|
|
35
37
|
const root = findRoot();
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
const diff = stagedDiff(process.cwd());
|
|
39
|
+
debug(root, maskDiff(diff));
|
|
40
|
+
return gitCommit(diff, { root, lang });
|
|
38
41
|
}
|
|
42
|
+
const raw = await readStdin();
|
|
39
43
|
const m = /^(claude|cursor|gemini|codex)-(pre|post)$/.exec(name);
|
|
40
44
|
if (!m)
|
|
41
45
|
return { code: 0, stderr: [] };
|
|
@@ -96,9 +100,20 @@ else if (args[0] === 'setup') {
|
|
|
96
100
|
chosen = detectAgents();
|
|
97
101
|
}
|
|
98
102
|
const r = setup(process.cwd(), lang, { uninstall, agents: chosen });
|
|
103
|
+
const latest = r.code ? undefined : await checkUpdate();
|
|
104
|
+
if (latest)
|
|
105
|
+
r.lines.push(t(lang, 'update_available', { latest, current: currentVersion() }));
|
|
99
106
|
(r.code ? process.stderr : process.stdout).write(r.lines.join('\n') + '\n');
|
|
100
107
|
process.exitCode = r.code;
|
|
101
108
|
}
|
|
109
|
+
else if (args[0] === 'update') {
|
|
110
|
+
process.exitCode = runUpdate();
|
|
111
|
+
if (!process.exitCode)
|
|
112
|
+
console.log(t(lang, 'update_done'));
|
|
113
|
+
}
|
|
114
|
+
else if (args[0] === '--version' || args[0] === '-v') {
|
|
115
|
+
console.log(currentVersion());
|
|
116
|
+
}
|
|
102
117
|
else {
|
|
103
118
|
process.stderr.write(t(lang, 'usage') + '\n');
|
|
104
119
|
process.exitCode = args.length ? 1 : 0;
|
package/dist/setup.js
CHANGED
|
@@ -7,9 +7,8 @@ import { DEFAULT_CONFIG } from './brain.js';
|
|
|
7
7
|
import { t } from './i18n.js';
|
|
8
8
|
const START = '# >>> YOUR CTO JEV START >>>';
|
|
9
9
|
const END = '# <<< YOUR CTO JEV END <<<';
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
const HOOK_BODY = `if command -v cto >/dev/null 2>&1; then\n ${DIFF_CMD} | cto --hook git-commit || exit 1\nfi\n`;
|
|
10
|
+
// Keep the block minimal: all logic (including the git diff call) lives in the package, so npm update upgrades every repo.
|
|
11
|
+
const HOOK_BODY = 'if command -v cto >/dev/null 2>&1; then\n cto --hook git-commit || exit 1\nfi\n';
|
|
13
12
|
const IGNORE_BODY = '.cto-brain.json\n.cto-brain.json.*tmp\ndebug_stdin.json\n';
|
|
14
13
|
const OURS = (cmd) => typeof cmd === 'string' && cmd.startsWith('cto --hook ');
|
|
15
14
|
const block = (body) => `${START}\n${body}${END}\n`;
|
package/dist/update.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { credentialsPath } from './brain.js';
|
|
5
|
+
const PKG = 'your-cto-jev';
|
|
6
|
+
const DAY = 86_400_000;
|
|
7
|
+
export const currentVersion = () => JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
8
|
+
/** a > b for plain x.y.z versions. */
|
|
9
|
+
export function newer(a, b) {
|
|
10
|
+
const pa = a.split('.').map(Number), pb = b.split('.').map(Number);
|
|
11
|
+
for (let i = 0; i < 3; i++)
|
|
12
|
+
if ((pa[i] ?? 0) !== (pb[i] ?? 0))
|
|
13
|
+
return (pa[i] ?? 0) > (pb[i] ?? 0);
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const cachePath = () => join(dirname(credentialsPath()), 'update-check.json');
|
|
17
|
+
/**
|
|
18
|
+
* Latest version if it is newer than this one, else undefined.
|
|
19
|
+
* Hits the npm registry at most once a day (cached next to the credentials file); every failure is silent.
|
|
20
|
+
* CTO_NO_UPDATE_CHECK=1 turns it off.
|
|
21
|
+
*/
|
|
22
|
+
export async function checkUpdate(timeoutMs = 1000, now = Date.now()) {
|
|
23
|
+
if (process.env.CTO_NO_UPDATE_CHECK === '1')
|
|
24
|
+
return undefined;
|
|
25
|
+
let latest;
|
|
26
|
+
try {
|
|
27
|
+
const c = JSON.parse(readFileSync(cachePath(), 'utf8'));
|
|
28
|
+
if (now - c.checked_at < DAY && typeof c.latest === 'string')
|
|
29
|
+
latest = c.latest;
|
|
30
|
+
}
|
|
31
|
+
catch { /* no cache yet */ }
|
|
32
|
+
if (!latest) {
|
|
33
|
+
try {
|
|
34
|
+
const r = await fetch(`https://registry.npmjs.org/${PKG}/latest`, { signal: AbortSignal.timeout(timeoutMs) });
|
|
35
|
+
const v = (await r.json())?.version;
|
|
36
|
+
if (typeof v !== 'string' || !/^\d+\.\d+\.\d+$/.test(v))
|
|
37
|
+
return undefined;
|
|
38
|
+
latest = v;
|
|
39
|
+
mkdirSync(dirname(cachePath()), { recursive: true });
|
|
40
|
+
writeFileSync(cachePath(), JSON.stringify({ checked_at: now, latest }) + '\n');
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return newer(latest, currentVersion()) ? latest : undefined;
|
|
47
|
+
}
|
|
48
|
+
/** npm install -g your-cto-jev@latest, output streamed to the terminal. */
|
|
49
|
+
export function runUpdate() {
|
|
50
|
+
// npm is npm.cmd on Windows, which needs a shell. One constant command string: nothing user-supplied is interpolated.
|
|
51
|
+
const r = spawnSync(`npm install -g ${PKG}@latest`, { stdio: 'inherit', shell: true });
|
|
52
|
+
try {
|
|
53
|
+
writeFileSync(cachePath(), JSON.stringify({ checked_at: 0 }) + '\n');
|
|
54
|
+
}
|
|
55
|
+
catch { /* cache is optional */ }
|
|
56
|
+
return r.status ?? 1;
|
|
57
|
+
}
|
package/dist/wizard.js
CHANGED
|
@@ -56,19 +56,48 @@ export function terminalAsk() {
|
|
|
56
56
|
return { ask, close: () => process.stdin.pause() };
|
|
57
57
|
}
|
|
58
58
|
const yes = (ans, def) => (ans ? /^y/i.test(ans) : def);
|
|
59
|
+
/** Parse "1,3" or "1 3" into 0-based indexes; null if anything is not a number in range. */
|
|
60
|
+
export function parsePicks(input, n) {
|
|
61
|
+
const idx = input.split(/[\s,]+/).filter(Boolean).map((p) => Number(p) - 1);
|
|
62
|
+
return idx.every((i) => Number.isInteger(i) && i >= 0 && i < n) ? [...new Set(idx)] : null;
|
|
63
|
+
}
|
|
64
|
+
const PROVIDER_OPTIONS = ['openrouter', 'cloudflare'];
|
|
59
65
|
/**
|
|
60
|
-
* Interactive setup
|
|
66
|
+
* Interactive setup in two announced steps. Each step shows its full checklist first, so nobody misses an option:
|
|
67
|
+
* 1. Agents: detected ones pre-checked; type numbers to toggle, Enter to confirm.
|
|
68
|
+
* 2. API providers: type numbers to pick, Enter to skip. Keys are asked only for picked providers, then verified.
|
|
61
69
|
* Keys already present in env are kept as-is unless forceKeys.
|
|
62
70
|
*/
|
|
63
71
|
export async function wizard(ask, lang, detected, log, forceKeys = false) {
|
|
64
|
-
log(t(lang, '
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
log(t(lang, 'wiz_intro'));
|
|
73
|
+
// Step 1: agents checklist
|
|
74
|
+
log(t(lang, 'wiz_step_agents'));
|
|
75
|
+
const picked = new Set(detected);
|
|
76
|
+
for (;;) {
|
|
77
|
+
agentNames.forEach((name, i) => {
|
|
78
|
+
const box = picked.has(name) ? '[x]' : '[ ]';
|
|
79
|
+
const found = detected.includes(name) ? t(lang, 'wiz_found') : '';
|
|
80
|
+
log(` ${box} ${i + 1}. ${agents[name].label}${found}`);
|
|
81
|
+
});
|
|
82
|
+
const ans = await ask(t(lang, 'wiz_agents_hint'));
|
|
83
|
+
if (!ans)
|
|
84
|
+
break;
|
|
85
|
+
const idx = parsePicks(ans, agentNames.length);
|
|
86
|
+
if (!idx) {
|
|
87
|
+
log(t(lang, 'wiz_invalid'));
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
for (const i of idx) {
|
|
91
|
+
const n = agentNames[i];
|
|
92
|
+
if (picked.has(n))
|
|
93
|
+
picked.delete(n);
|
|
94
|
+
else
|
|
95
|
+
picked.add(n);
|
|
96
|
+
}
|
|
71
97
|
}
|
|
98
|
+
const chosen = agentNames.filter((n) => picked.has(n));
|
|
99
|
+
// Step 2: API providers checklist
|
|
100
|
+
log(t(lang, 'wiz_step_keys'));
|
|
72
101
|
const env = process.env;
|
|
73
102
|
const hasKey = !!(env.OPENROUTER_API_KEY || (env.CLOUDFLARE_API_TOKEN && env.CLOUDFLARE_ACCOUNT_ID));
|
|
74
103
|
if (hasKey && !forceKeys) {
|
|
@@ -76,6 +105,14 @@ export async function wizard(ask, lang, detected, log, forceKeys = false) {
|
|
|
76
105
|
return chosen;
|
|
77
106
|
}
|
|
78
107
|
log(t(lang, 'wiz_keys', { path: credentialsPath() }));
|
|
108
|
+
PROVIDER_OPTIONS.forEach((p, i) => log(` ${i + 1}. ${t(lang, 'wiz_provider_' + p)}`));
|
|
109
|
+
let which = null;
|
|
110
|
+
while (!which) {
|
|
111
|
+
const ans = await ask(t(lang, 'wiz_providers_hint'));
|
|
112
|
+
which = ans ? parsePicks(ans, PROVIDER_OPTIONS.length) : [];
|
|
113
|
+
if (!which)
|
|
114
|
+
log(t(lang, 'wiz_invalid'));
|
|
115
|
+
}
|
|
79
116
|
const creds = { ...loadCredentials() };
|
|
80
117
|
const tryKey = async (provider, set) => {
|
|
81
118
|
const saved = { ...env };
|
|
@@ -98,14 +135,18 @@ export async function wizard(ask, lang, detected, log, forceKeys = false) {
|
|
|
98
135
|
env[k] = saved[k];
|
|
99
136
|
}
|
|
100
137
|
};
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
138
|
+
for (const i of which) {
|
|
139
|
+
if (PROVIDER_OPTIONS[i] === 'openrouter') {
|
|
140
|
+
const key = await ask(t(lang, 'wiz_or_key'), true);
|
|
141
|
+
if (key)
|
|
142
|
+
await tryKey('openrouter', { OPENROUTER_API_KEY: key });
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
const acc = await ask(t(lang, 'wiz_cf_account'));
|
|
146
|
+
const tok = acc ? await ask(t(lang, 'wiz_cf_token'), true) : '';
|
|
147
|
+
if (acc && tok)
|
|
148
|
+
await tryKey('cloudflare', { CLOUDFLARE_ACCOUNT_ID: acc, CLOUDFLARE_API_TOKEN: tok });
|
|
149
|
+
}
|
|
109
150
|
}
|
|
110
151
|
if (Object.keys(creds).length)
|
|
111
152
|
log(t(lang, 'wiz_saved', { path: saveCredentials(creds) }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "your-cto-jev",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "A sharp-tongued CTO gatekeeper for AI coding agents: blocks leaked secrets in git commits and destructive shell commands in Claude Code, Cursor, Gemini CLI and Codex, using TypeSafe Jev.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|