@ailuntz/minilink 0.9.8 → 0.9.10
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 -0
- package/package.json +1 -1
- package/src/config.mjs +3 -3
- package/src/install.mjs +8 -8
- package/src/proxy.mjs +1 -1
package/README.md
CHANGED
|
@@ -26,6 +26,8 @@ minilink on
|
|
|
26
26
|
|
|
27
27
|
`npm install` 只安装命令;`minilink on` 才接入 Desktop。更新包后再次运行 `minilink on`。
|
|
28
28
|
|
|
29
|
+
MiniLink 始终调用 Desktop 自带的 Codex,不调用先前单独安装的 `codex` 命令。配置和会话仍使用官方的 `CODEX_HOME`(默认 `~/.codex`);MiniLink 自己的启动文件放在 `~/.local/share/minilink`。
|
|
30
|
+
|
|
29
31
|
## 命令
|
|
30
32
|
|
|
31
33
|
| 命令 | 用途 |
|
package/package.json
CHANGED
package/src/config.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync, readdirSync, mkdirSync, writeFileSync, renameSync, rmSync, existsSync, realpathSync, accessSync, constants, statSync, copyFileSync, mkdtempSync } from 'node:fs';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
|
-
import { resolve, join, dirname
|
|
3
|
+
import { resolve, join, dirname } from 'node:path';
|
|
4
4
|
import { randomUUID, createHash } from 'node:crypto';
|
|
5
5
|
import { execFileSync } from 'node:child_process';
|
|
6
6
|
import { parseEnv } from 'node:util';
|
|
@@ -104,8 +104,8 @@ export function findApp() {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
export function resolveRealCodex(selfPath) {
|
|
107
|
-
const candidate =
|
|
108
|
-
if (!candidate
|
|
107
|
+
const candidate = officialCodex();
|
|
108
|
+
if (!candidate) throw new Error('找不到 ChatGPT 内置 Codex。');
|
|
109
109
|
let actual;
|
|
110
110
|
try { actual = realpathSync(candidate); accessSync(actual, constants.X_OK); } catch { throw new Error('真正的 Codex 不存在或不可执行。'); }
|
|
111
111
|
if (actual === realpathSync(selfPath) || actual === realpathSync(process.execPath)) throw new Error('检测到路由递归调用。');
|
package/src/install.mjs
CHANGED
|
@@ -20,7 +20,7 @@ export function installation(root = installRoot()) {
|
|
|
20
20
|
|
|
21
21
|
export function ensureInstalled({ state = installation(), source = sourceRoot, activate = installDesktop } = {}) {
|
|
22
22
|
try {
|
|
23
|
-
if (state?.source === source && JSON.parse(readFileSync(join(state.runtime, 'package.json'), 'utf8')).version === VERSION) return state;
|
|
23
|
+
if (state?.source === source && state.packageVersion === VERSION && JSON.parse(readFileSync(join(state.runtime, 'package.json'), 'utf8')).version === VERSION) return state;
|
|
24
24
|
} catch {}
|
|
25
25
|
return activate();
|
|
26
26
|
}
|
|
@@ -89,7 +89,7 @@ function installLinux({ root = installRoot(), source = sourceRoot, home = codexH
|
|
|
89
89
|
const wrapper = join(root, 'minilink');
|
|
90
90
|
mkdirSync(root, { recursive: true, mode: 0o700 });
|
|
91
91
|
atomicFile(wrapper, `#!/bin/sh\nif [ ! -f ${shellQuote(join(source, 'package.json'))} ]; then exec ${shellQuote(native)} "$@"; fi\nexport CODEX_HOME=${shellQuote(home)}\nexport MINILINK_CONFIG=${shellQuote(config)}\nexec ${shellQuote(node)} ${shellQuote(join(source, 'bin/minilink.mjs'))} "$@"\n`, 0o755);
|
|
92
|
-
const state = { version: 3, platform: 'linux', source, runtime: source, wrapper, node, codexHome: home, configPath: config, installedAt: new Date().toISOString() };
|
|
92
|
+
const state = { version: 3, platform: 'linux', packageVersion: VERSION, source, runtime: source, wrapper, node, codexHome: home, configPath: config, installedAt: new Date().toISOString() };
|
|
93
93
|
atomicJSON(join(root, 'installation.json'), state);
|
|
94
94
|
return state;
|
|
95
95
|
}
|
|
@@ -107,20 +107,20 @@ function syncWindows({ state = installation(), enabled } = {}) {
|
|
|
107
107
|
if (enabled == null) enabled = readConfig(state.configPath).enabled;
|
|
108
108
|
const current = windowsEnvironment();
|
|
109
109
|
if (enabled) {
|
|
110
|
-
if (current && current !== state.wrapper) throw new Error('CODEX_CLI_PATH 已指向其他程序。');
|
|
111
|
-
if (
|
|
110
|
+
if (current && current !== state.wrapper && current !== state.previousWrapper) throw new Error('CODEX_CLI_PATH 已指向其他程序。');
|
|
111
|
+
if (current !== state.wrapper) setWindowsEnvironment(state.wrapper);
|
|
112
112
|
} else if (current === state.wrapper) setWindowsEnvironment(state.previousEnv || null);
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
function installWindows({ root = installRoot(), source = sourceRoot, home = codexHome(), config = configPath(), node = process.execPath } = {}) {
|
|
116
116
|
const native = resolveRealCodex(join(source, 'bin/minilink.mjs'));
|
|
117
|
-
const previous = installation(root), wrapper = join(root,
|
|
117
|
+
const previous = installation(root), wrapper = join(root, `MiniLinkLauncher-${VERSION}.exe`);
|
|
118
118
|
const current = windowsEnvironment();
|
|
119
|
-
if (current && current !== wrapper) throw new Error('CODEX_CLI_PATH 已指向其他程序。');
|
|
119
|
+
if (current && current !== wrapper && current !== previous?.wrapper) throw new Error('CODEX_CLI_PATH 已指向其他程序。');
|
|
120
120
|
mkdirSync(root, { recursive: true, mode: 0o700 });
|
|
121
121
|
if (!existsSync(wrapper)) powershell(`Add-Type -Path ${psQuote(join(source, 'src/platform/windows/MiniLinkLauncher.cs'))} -OutputAssembly ${psQuote(wrapper)} -OutputType ConsoleApplication`);
|
|
122
122
|
atomicFile(join(root, 'launcher.paths'), [node, join(source, 'bin/minilink.mjs'), native, home, config].join('\n') + '\n', 0o600);
|
|
123
|
-
const state = { version: 3, platform: 'win32', source, runtime: source, wrapper, node, codexHome: home, configPath: config, previousEnv: previous?.previousEnv || null, installedAt: new Date().toISOString() };
|
|
123
|
+
const state = { version: 3, platform: 'win32', packageVersion: VERSION, source, runtime: source, wrapper, node, codexHome: home, configPath: config, previousEnv: previous?.previousEnv || null, previousWrapper: current === previous?.wrapper ? current : null, installedAt: new Date().toISOString() };
|
|
124
124
|
atomicJSON(join(root, 'installation.json'), state);
|
|
125
125
|
return state;
|
|
126
126
|
}
|
|
@@ -161,7 +161,7 @@ export function install({ root = installRoot(), plist = defaultPlist(), source =
|
|
|
161
161
|
}
|
|
162
162
|
if (JSON.parse(readFileSync(join(dependency, 'package.json'), 'utf8')).name !== 'smol-toml') throw new Error('smol-toml 依赖路径无效。');
|
|
163
163
|
cpSync(dependency, join(runtime, 'node_modules/smol-toml'), { recursive: true });
|
|
164
|
-
const state = { version: 2, source, runtime, wrapper, node, npm: packageManager.npm || previous?.npm, prefix: packageManager.prefix || previous?.prefix, codexHome: home, configPath: config, previousEnv: previous?.previousEnv || legacy?.state.previousEnv || null, installedAt: new Date().toISOString() };
|
|
164
|
+
const state = { version: 2, packageVersion: VERSION, source, runtime, wrapper, node, npm: packageManager.npm || previous?.npm, prefix: packageManager.prefix || previous?.prefix, codexHome: home, configPath: config, previousEnv: previous?.previousEnv || legacy?.state.previousEnv || null, installedAt: new Date().toISOString() };
|
|
165
165
|
// A Desktop process can retain this launcher after npm removes the state.
|
|
166
166
|
const fallback = `if [ ! -f ${shellQuote(stateFile)} ]; then\n exec "\${CODEX_DESKTOP_APP:-/Applications/ChatGPT.app}/${bundledCodexRelativePath}" "$@"\nfi`;
|
|
167
167
|
atomicFile(wrapper, `#!/bin/sh\n${fallback}\nexport CODEX_HOME=${shellQuote(home)}\nexport MINILINK_CONFIG=${shellQuote(config)}\nexec ${shellQuote(node)} ${shellQuote(join(runtime, 'bin/minilink.mjs'))} "$@"\n`, 0o755);
|
package/src/proxy.mjs
CHANGED
|
@@ -32,7 +32,7 @@ export function isStdioServer(args) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export async function runProxy(args, selfPath) {
|
|
35
|
-
if ((Number.parseInt(setting('ACTIVE'), 10) || 0) >= 8) throw new Error('检测到 minilink
|
|
35
|
+
if ((Number.parseInt(setting('ACTIVE'), 10) || 0) >= 8) throw new Error('检测到 minilink 递归调用。');
|
|
36
36
|
const path = configPath();
|
|
37
37
|
const enabled = readConfig(path).enabled;
|
|
38
38
|
const hadConfig = existsSync(path);
|