base_parts_ai 1.0.46 → 1.0.47
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/lib/ai_utils.js +48 -4
- package/lib/setapi_cx.js +21 -8
- package/package.json +1 -1
- package/test_home/.codex/config.toml +0 -3
- package/test_jcx.js +7 -8
package/lib/ai_utils.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
var fs = require('fs');
|
|
9
9
|
var path = require('path');
|
|
10
10
|
var http = require('http');
|
|
11
|
-
var { execSync } = require('child_process');
|
|
11
|
+
var { execSync, spawnSync } = require('child_process');
|
|
12
12
|
|
|
13
13
|
// ============================================================
|
|
14
14
|
// AI 渠道列表(运行时由 fetchConfig 从服务端拉取填充)
|
|
@@ -24,6 +24,51 @@ var noticeList = [];
|
|
|
24
24
|
// jcc.json 中保存最后一次手动输入 Token 的内部字段名
|
|
25
25
|
var LAST_MANUAL_AUTH_TOKEN_KEY = '__lastManualAuthToken';
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* 从当前入口文件名推断正在运行的 CLI 命令名
|
|
29
|
+
* @returns {string} jcc、jcx 或空字符串
|
|
30
|
+
*/
|
|
31
|
+
function getCurrentCliName() {
|
|
32
|
+
var entryName = path.basename(process.argv[1] || '').toLowerCase();
|
|
33
|
+
if (entryName === 'jcx' || entryName === 'jcx.js') return 'jcx';
|
|
34
|
+
if (entryName === 'jcc' || entryName === 'jcc.js') return 'jcc';
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 升级完成后重新运行当前 CLI,并保留本次传入的全部参数
|
|
40
|
+
* @returns {void}
|
|
41
|
+
*/
|
|
42
|
+
function rerunCurrentCli() {
|
|
43
|
+
var cliName = getCurrentCliName();
|
|
44
|
+
if (!cliName) {
|
|
45
|
+
console.log('[fetchConfig] 升级完成,未识别当前 CLI,请重新运行');
|
|
46
|
+
process.exit(0);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 传递临时环境变量,避免新进程在版本缓存异常时反复触发升级。
|
|
50
|
+
var childEnv = Object.assign({}, process.env, {
|
|
51
|
+
BASE_PARTS_AI_SKIP_SELF_UPDATE: '1',
|
|
52
|
+
});
|
|
53
|
+
var args = process.argv.slice(2);
|
|
54
|
+
console.log('[fetchConfig] 升级完成,正在重新运行: ' + cliName + (args.length ? ' ' + args.join(' ') : ''));
|
|
55
|
+
var result = spawnSync(cliName, args, {
|
|
56
|
+
stdio: 'inherit',
|
|
57
|
+
shell: process.platform === 'win32',
|
|
58
|
+
env: childEnv,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (result.error) {
|
|
62
|
+
console.warn('[fetchConfig] 重新运行失败:', result.error.message);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
if (result.signal) {
|
|
66
|
+
console.warn('[fetchConfig] 重新运行被信号中断:', result.signal);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
process.exit(typeof result.status === 'number' ? result.status : 0);
|
|
70
|
+
}
|
|
71
|
+
|
|
27
72
|
/**
|
|
28
73
|
* 从服务端拉取渠道配置,并检查 jcc 自身是否需要升级
|
|
29
74
|
* @param {object} buildCfg getBuildCfg 返回的配置对象
|
|
@@ -76,7 +121,7 @@ function fetchConfig(buildCfg) {
|
|
|
76
121
|
}
|
|
77
122
|
return false;
|
|
78
123
|
}
|
|
79
|
-
if (newVer && semverGt(newVer, currentVer)) {
|
|
124
|
+
if (newVer && process.env.BASE_PARTS_AI_SKIP_SELF_UPDATE !== '1' && semverGt(newVer, currentVer)) {
|
|
80
125
|
console.log('[fetchConfig] 检测到新版本 jcc: ' + newVer + '(当前 ' + currentVer + ')');
|
|
81
126
|
var confirmed = "yes"
|
|
82
127
|
// confirmed = await select({
|
|
@@ -93,8 +138,7 @@ function fetchConfig(buildCfg) {
|
|
|
93
138
|
try {
|
|
94
139
|
var tgzUrl = 'https://jdwfiles.oss-cn-hangzhou.aliyuncs.com/npm_pkg/base_parts_ai-' + newVer + '.tgz';
|
|
95
140
|
execSync('npm install -g ' + tgzUrl + ' --force --registry=https://registry.npmmirror.com', { stdio: 'inherit' });
|
|
96
|
-
|
|
97
|
-
process.exit(0);
|
|
141
|
+
rerunCurrentCli();
|
|
98
142
|
} catch (e) {
|
|
99
143
|
console.warn('[fetchConfig] 自动升级失败:', e.message);
|
|
100
144
|
}
|
package/lib/setapi_cx.js
CHANGED
|
@@ -152,16 +152,29 @@ function ensureSandboxMode(toml) {
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
/**
|
|
155
|
-
*
|
|
155
|
+
* 强制删除 Codex TUI 编辑器 insert_newline 配置,交给官方默认行为处理
|
|
156
156
|
* @param {string} toml TOML 内容
|
|
157
157
|
* @returns {string}
|
|
158
158
|
*/
|
|
159
|
-
function
|
|
159
|
+
function removeEditorInsertNewlineKeymap(toml) {
|
|
160
160
|
var config = parseTomlConfig(toml);
|
|
161
|
-
var tui =
|
|
162
|
-
var keymap =
|
|
163
|
-
var editor =
|
|
164
|
-
|
|
161
|
+
var tui = config.tui;
|
|
162
|
+
var keymap = tui && typeof tui === 'object' && !Array.isArray(tui) ? tui.keymap : null;
|
|
163
|
+
var editor = keymap && typeof keymap === 'object' && !Array.isArray(keymap) ? keymap.editor : null;
|
|
164
|
+
|
|
165
|
+
// 只删除官方已支持的 insert_newline,保留用户其它 TUI 快捷键配置。
|
|
166
|
+
if (editor && typeof editor === 'object' && !Array.isArray(editor)) {
|
|
167
|
+
delete editor.insert_newline;
|
|
168
|
+
if (isEmptyObject(editor)) {
|
|
169
|
+
delete keymap.editor;
|
|
170
|
+
}
|
|
171
|
+
if (isEmptyObject(keymap)) {
|
|
172
|
+
delete tui.keymap;
|
|
173
|
+
}
|
|
174
|
+
if (isEmptyObject(tui)) {
|
|
175
|
+
delete config.tui;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
165
178
|
return stringifyTomlConfig(config);
|
|
166
179
|
}
|
|
167
180
|
|
|
@@ -432,7 +445,7 @@ async function setapiCx(cmd, buildCfg) {
|
|
|
432
445
|
toml = wireApi ? setJcodexWireApi(toml, wireApi) : removeJcodexWireApi(toml);
|
|
433
446
|
}
|
|
434
447
|
toml = ensureSandboxMode(toml);
|
|
435
|
-
toml =
|
|
448
|
+
toml = removeEditorInsertNewlineKeymap(toml);
|
|
436
449
|
writeTextFile(buildCfg.codexConfigPath, toml);
|
|
437
450
|
|
|
438
451
|
await refreshAgentsFile(buildCfg.codexAgentsPath);
|
|
@@ -452,7 +465,7 @@ setapiCx._private = {
|
|
|
452
465
|
escapeTomlString: escapeTomlString,
|
|
453
466
|
hasTopLevelKey: hasTopLevelKey,
|
|
454
467
|
ensureSandboxMode: ensureSandboxMode,
|
|
455
|
-
|
|
468
|
+
removeEditorInsertNewlineKeymap: removeEditorInsertNewlineKeymap,
|
|
456
469
|
removeTopLevelModelProvider: removeTopLevelModelProvider,
|
|
457
470
|
removeJcodexProviderBlock: removeJcodexProviderBlock,
|
|
458
471
|
removeJcodexWireApi: removeJcodexWireApi,
|
package/package.json
CHANGED
package/test_jcx.js
CHANGED
|
@@ -173,18 +173,18 @@ async function runTests() {
|
|
|
173
173
|
})();
|
|
174
174
|
|
|
175
175
|
// ============================================================
|
|
176
|
-
// 测试 2.2
|
|
176
|
+
// 测试 2.2:强制删除 TUI 编辑器换行快捷键
|
|
177
177
|
// ============================================================
|
|
178
|
-
console.log('\n======= jcx Test 2.2:
|
|
178
|
+
console.log('\n======= jcx Test 2.2: 强制删除 TUI keymap insert_newline =======');
|
|
179
179
|
(function () {
|
|
180
|
-
var original = '[tui]\ntheme = "dark"\n\n[tui.keymap.editor]\ninsert_newline = "enter"\n';
|
|
181
|
-
var updated = privateApi.
|
|
180
|
+
var original = '[tui]\ntheme = "dark"\n\n[tui.keymap.editor]\ninsert_newline = "enter"\naccept_completion = "tab"\n';
|
|
181
|
+
var updated = privateApi.removeEditorInsertNewlineKeymap(original);
|
|
182
182
|
var ok = true;
|
|
183
183
|
ok = ok && updated.indexOf('[tui]') !== -1;
|
|
184
184
|
ok = ok && updated.indexOf('theme = "dark"') !== -1;
|
|
185
185
|
ok = ok && updated.indexOf('[tui.keymap.editor]') !== -1;
|
|
186
|
-
ok = ok && updated.indexOf('
|
|
187
|
-
ok = ok && updated.indexOf('insert_newline
|
|
186
|
+
ok = ok && updated.indexOf('accept_completion = "tab"') !== -1;
|
|
187
|
+
ok = ok && updated.indexOf('insert_newline') === -1;
|
|
188
188
|
console.log('✅ Test 2.2 通过:', ok);
|
|
189
189
|
if (!ok) { process.exit(1); }
|
|
190
190
|
})();
|
|
@@ -235,8 +235,7 @@ async function runTests() {
|
|
|
235
235
|
ok = ok && toml.indexOf('sandbox_mode = "danger-full-access"') !== -1;
|
|
236
236
|
ok = ok && toml.indexOf('base_url = "https://forced.example.com/v1"') !== -1;
|
|
237
237
|
ok = ok && toml.indexOf('wire_api = "wire-forced-provider-key"') !== -1;
|
|
238
|
-
ok = ok && toml.indexOf('
|
|
239
|
-
ok = ok && toml.indexOf('insert_newline = "alt-enter"') !== -1;
|
|
238
|
+
ok = ok && toml.indexOf('insert_newline') === -1;
|
|
240
239
|
ok = ok && agents.indexOf('cli=cx') !== -1;
|
|
241
240
|
ok = ok && agents.indexOf('cli=cx-' + utils.getAiTipOsParam()) !== -1;
|
|
242
241
|
console.log('✅ Test 4 通过:', ok);
|