@walkhi/code-relax 0.1.0-beta.32 → 0.1.0-beta.33
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/build-platform.json +1 -1
- package/package.json +4 -4
- package/tools/postinstall.mjs +58 -4
package/dist/build-platform.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"layout":"npm-platform-packages","version":"0.1.0-beta.
|
|
1
|
+
{"layout":"npm-platform-packages","version":"0.1.0-beta.33"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@walkhi/code-relax",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.33",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"tag": "beta"
|
|
42
42
|
},
|
|
43
43
|
"optionalDependencies": {
|
|
44
|
-
"@walkhi/code-relax-native-win32-x64": "0.1.0-beta.
|
|
45
|
-
"@walkhi/code-relax-native-darwin-arm64": "0.1.0-beta.
|
|
46
|
-
"@walkhi/code-relax-native-darwin-x64": "0.1.0-beta.
|
|
44
|
+
"@walkhi/code-relax-native-win32-x64": "0.1.0-beta.33",
|
|
45
|
+
"@walkhi/code-relax-native-darwin-arm64": "0.1.0-beta.33",
|
|
46
|
+
"@walkhi/code-relax-native-darwin-x64": "0.1.0-beta.33"
|
|
47
47
|
}
|
|
48
48
|
}
|
package/tools/postinstall.mjs
CHANGED
|
@@ -53,14 +53,52 @@ export function formatSetupOutput(output) {
|
|
|
53
53
|
try {
|
|
54
54
|
const result = JSON.parse(output);
|
|
55
55
|
const migration = result.managedAppServerMigration || {};
|
|
56
|
-
return `Code Relax ${result.version || '未知版本'}
|
|
56
|
+
return `Code Relax ${result.version || '未知版本'} 服务安装完成。\n`
|
|
57
57
|
+ '工作站服务和 Codex 内核已就绪,已启用登录自启。\n'
|
|
58
58
|
+ (migration.restarted ? 'Codex 内核已更新并重启;请检查安装前正在进行的任务。\n' : '')
|
|
59
|
-
+ (result.desktopRestartRecommended ? 'Codex Desktop:请完全退出后重新打开。\n' : '')
|
|
60
|
-
+ '生成配对二维码:relax pair\n';
|
|
59
|
+
+ (result.desktopRestartRecommended ? 'Codex Desktop:请完全退出后重新打开。\n' : '');
|
|
61
60
|
} catch { return output; }
|
|
62
61
|
}
|
|
63
62
|
|
|
63
|
+
// npm owns command links. Inspect them without changing the user's shell configuration.
|
|
64
|
+
export function commandDiagnostics(entry, { prefix, env = process.env, platform = process.platform } = {}) {
|
|
65
|
+
const windows = platform === 'win32';
|
|
66
|
+
const bin = windows ? prefix : path.join(prefix, 'bin');
|
|
67
|
+
const command = path.join(bin, windows ? 'relax.cmd' : 'relax');
|
|
68
|
+
const lines = [`命令入口:${command}`];
|
|
69
|
+
let linkReady = false;
|
|
70
|
+
try {
|
|
71
|
+
if (windows) {
|
|
72
|
+
const shim = fs.readFileSync(command, 'utf8');
|
|
73
|
+
linkReady = shim.replaceAll('\\', '/').includes('node_modules/@walkhi/code-relax/dist/bin/codex-remote.mjs') && fs.existsSync(entry);
|
|
74
|
+
} else {
|
|
75
|
+
linkReady = fs.realpathSync(command) === fs.realpathSync(entry);
|
|
76
|
+
fs.accessSync(command, fs.constants.X_OK);
|
|
77
|
+
}
|
|
78
|
+
lines.push(linkReady ? '命令链接:正常' : '命令链接:目标与本次安装不一致');
|
|
79
|
+
} catch (error) {
|
|
80
|
+
linkReady = false;
|
|
81
|
+
lines.push(`命令链接:不可用(${error.code || error.message})`);
|
|
82
|
+
}
|
|
83
|
+
const normalize = value => {
|
|
84
|
+
let resolved;
|
|
85
|
+
try { resolved = fs.realpathSync(value); } catch { resolved = path.resolve(value); }
|
|
86
|
+
return windows ? resolved.toLowerCase() : resolved;
|
|
87
|
+
};
|
|
88
|
+
const pathValue = Object.entries(env).find(([key]) => key.toLowerCase() === 'path')?.[1] || '';
|
|
89
|
+
const onPath = pathValue.split(windows ? ';' : ':').filter(Boolean)
|
|
90
|
+
.some(value => normalize(value.replace(/^"|"$/g, '')) === normalize(bin));
|
|
91
|
+
lines.push(`安装进程 PATH:${onPath ? '包含' : '未包含'}全局命令目录`);
|
|
92
|
+
lines.push('注:npm 会调整安装进程 PATH;当前终端能否直接找到命令仍以终端为准。');
|
|
93
|
+
if (!linkReady) lines.push('CLI 入口异常;服务状态请以上方健康检查为准,请保留本次诊断输出。');
|
|
94
|
+
else if (!onPath) lines.push('全局命令目录未在 PATH 中,可先使用下方完整路径命令。');
|
|
95
|
+
const quote = value => "'" + value.replaceAll("'", windows ? "''" : "'\"'\"'") + "'";
|
|
96
|
+
const direct = `${windows ? '& ' : ''}${quote(process.execPath)} ${quote(entry)}`;
|
|
97
|
+
lines.push(`无需依赖 relax 命令的检查入口${windows ? '(PowerShell)' : ''}:`, `${direct} doctor`);
|
|
98
|
+
lines.push('生成配对二维码:', `${direct} pair`);
|
|
99
|
+
return lines.join('\n') + '\n';
|
|
100
|
+
}
|
|
101
|
+
|
|
64
102
|
function installationSnapshot() {
|
|
65
103
|
const recordPath = path.join(serviceRoot, 'installation.json');
|
|
66
104
|
if (!fs.existsSync(serviceRoot)) return { exists: false, valid: false };
|
|
@@ -113,8 +151,13 @@ if (invokedDirectly && process.env.npm_config_global === 'true') {
|
|
|
113
151
|
prepareNativePackage(fileURLToPath(new URL('../', import.meta.url)));
|
|
114
152
|
setupStarted = true;
|
|
115
153
|
runStage(entry, 'setup', ['setup', '--json'], output => formatSetupOutput(output));
|
|
154
|
+
try { runStage(entry, 'doctor', ['doctor']); }
|
|
155
|
+
catch (error) {
|
|
156
|
+
console.error('服务安装已完成,但安装后健康检查未通过;请查看上方诊断与安装日志。');
|
|
157
|
+
process.exitCode = 1;
|
|
158
|
+
}
|
|
116
159
|
console.log(`安装日志:${installLog}`);
|
|
117
|
-
appendLog('[postinstall] success');
|
|
160
|
+
appendLog(process.exitCode ? '[postinstall] failed stage=doctor' : '[postinstall] success');
|
|
118
161
|
} catch (error) {
|
|
119
162
|
const current = installationSnapshot();
|
|
120
163
|
if (!setupStarted) console.error(`平台组件检查失败:${error.message}`);
|
|
@@ -123,5 +166,16 @@ if (invokedDirectly && process.env.npm_config_global === 'true') {
|
|
|
123
166
|
console.error(`安装日志:${installLog}`);
|
|
124
167
|
appendLog('[postinstall] failed stage=setup');
|
|
125
168
|
process.exitCode = Number.isInteger(error?.status) && error.status > 0 ? error.status : 1;
|
|
169
|
+
} finally {
|
|
170
|
+
try {
|
|
171
|
+
const prefix = execFileSync(process.execPath, [process.env.npm_execpath, 'prefix', '--global'],
|
|
172
|
+
{ encoding: 'utf8', windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] }).trim();
|
|
173
|
+
const output = commandDiagnostics(entry, { prefix });
|
|
174
|
+
process.stdout.write(output);
|
|
175
|
+
appendLog(`[command-diagnostics]\n${output}`);
|
|
176
|
+
} catch (error) {
|
|
177
|
+
console.error(`命令入口诊断失败:${error.message}`);
|
|
178
|
+
appendLog(`[command-diagnostics] failed: ${error.message}`);
|
|
179
|
+
}
|
|
126
180
|
}
|
|
127
181
|
}
|