@syengup/fridaynext-codex-channel 0.1.0-beta.4 → 0.1.0-beta.5
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 +13 -10
- package/package.json +1 -1
- package/provider.mjs +94 -3
- package/release.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
# FridayNext Codex 插件 · Beta
|
|
1
|
+
# FridayNext Codex 插件 · Beta 5
|
|
2
2
|
|
|
3
3
|
在要连接的项目目录打开终端,执行:
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
|
-
npx -y @syengup/fridaynext-codex-channel@0.1.0-beta.
|
|
6
|
+
npx -y @syengup/fridaynext-codex-channel@0.1.0-beta.5
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
安装器依次安装官方标准插件、配置连接、启动网关、校验网关并显示二维码。用 Friday Next 扫码即可配对,无需另开终端运行 configure、activate 或 pair。关闭安装终端后专用进程继续运行,电脑重启后重新执行同一命令。
|
|
@@ -17,7 +17,7 @@ npx -y @syengup/fridaynext-codex-channel@0.1.0-beta.4
|
|
|
17
17
|
也可以显式选择:
|
|
18
18
|
|
|
19
19
|
```sh
|
|
20
|
-
npx -y @syengup/fridaynext-codex-channel@0.1.0-beta.
|
|
20
|
+
npx -y @syengup/fridaynext-codex-channel@0.1.0-beta.5 --workspace /绝对路径/项目 --lan-host 192.168.1.10
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## 服务与数据
|
|
@@ -31,18 +31,21 @@ npx -y @syengup/fridaynext-codex-channel@0.1.0-beta.4 --workspace /绝对路径/
|
|
|
31
31
|
## 常用操作
|
|
32
32
|
|
|
33
33
|
```sh
|
|
34
|
-
npx -y @syengup/fridaynext-codex-channel@0.1.0-beta.
|
|
35
|
-
npx -y @syengup/fridaynext-codex-channel@0.1.0-beta.
|
|
36
|
-
npx -y @syengup/fridaynext-codex-channel@0.1.0-beta.
|
|
34
|
+
npx -y @syengup/fridaynext-codex-channel@0.1.0-beta.5 status
|
|
35
|
+
npx -y @syengup/fridaynext-codex-channel@0.1.0-beta.5 pair
|
|
36
|
+
npx -y @syengup/fridaynext-codex-channel@0.1.0-beta.5 stop
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
`stop`只作用于本安装器登记的工作进程,等待原生执行空闲后关闭专用宿主;不停止外部已有宿主。重跑默认命令可恢复。单独pair保留原CLI的完整资料及0600 PNG/文本输出;二维码十分钟有效,重出作废旧券,已配对手机不受影响。不要公开配对资料。
|
|
40
40
|
|
|
41
41
|
自动化只安装不启动时用 `install --only --json`;原configure/roots/permissions/sessions入口继续保留。卸载使用官方 `codex plugin remove fridaynext-codex@fridaynext-local` 和 `codex plugin marketplace remove fridaynext-local`,先正常停止自有服务,不删除私有数据。
|
|
42
42
|
|
|
43
|
-
本包内置适配器 0.1.103,依赖精确 registry Kit 0.2.0-beta.9
|
|
43
|
+
本包内置适配器 0.1.103,依赖精确 registry Kit 0.2.0-beta.9,运行载荷与 beta.4 逐字节相同。beta.4 在 beta.3 的工作目录持久卷身份、队列删除及语音输入基础上,新增连接器 Provider 入口,并按本机实际 CLI 能力安装插件;beta.5 只更新安装器与 Provider,使 App 添加时可自动升级旧运行代码。专用宿主经标准插件见证后才可使用。安装只创建连接所需状态,首次模型请求由用户发起。
|
|
44
44
|
|
|
45
|
-
从较早的 beta
|
|
45
|
+
从较早的 beta 升级时,安装器会校验原代码来源。beta.4 升级到 beta.5 复用同一运行载荷,原地升级安装器并继续使用已有服务。不同运行版本共用同一代码目录时,npx 安装器返回 `INSTALL_VERSION_CONFLICT`;beta.3(适配器 0.1.102)升级到 beta.5(0.1.103)属于这种情况。
|
|
46
|
+
|
|
47
|
+
- 在 Friday App 中添加 Codex 时,连接器调用 Provider 的 `enable` 自动完成升级(FN-663):先经本组件登记的 worker 正常停止旧专用宿主并等待执行空闲,再用官方命令移除旧插件登记和 marketplace,把旧代码目录移到同级 `plugin.backup-<UTC时间>`(不删除),最后安装新代码并重新登记。数据目录、`integration.json`、安装器登记、serverInstanceId、token、TLS 及已授权目录保持不变。旧代码来源被改动、已装版本更新、登记指向其他来源或旧服务不由本组件 worker 管理时,返回结构化错误且不做改动。
|
|
48
|
+
- 只用 npx 时,请先使用原版的 stop 停止该安装器管理的服务,通过上面的官方命令移除其插件登记和 marketplace,移走原代码目录作为备份,再执行新版安装。保留原数据目录、工作目录及配置以继续使用原有身份和历史。
|
|
46
49
|
|
|
47
50
|
## 安装器行为 · FN-519
|
|
48
51
|
|
|
@@ -55,7 +58,7 @@ node packages/codex-channel/scripts/build-release.mjs --output /全新候选目
|
|
|
55
58
|
npm pack /全新候选目录
|
|
56
59
|
```
|
|
57
60
|
|
|
58
|
-
|
|
61
|
+
运行源不变、只升级安装器时(beta.5 即按此生成),将已发布 beta.4 的包解出到独立目录,使用原 `plugin.tgz` 生成新安装器候选。脚本对照本仓的适配器源码摘要、Kit 版本及原压缩包 SHA,新版本须晚于已发行版本,新输出目录必须为空缺。
|
|
59
62
|
|
|
60
63
|
```sh
|
|
61
64
|
node packages/codex-channel/scripts/build-release.mjs \
|
|
@@ -67,4 +70,4 @@ npx -y --package /本地候选.tgz -- fridaynext-codex-channel
|
|
|
67
70
|
|
|
68
71
|
## 连接器 Provider · FN-654
|
|
69
72
|
|
|
70
|
-
beta.4 起同包提供 `provider.mjs`(bin `fridaynext-codex-provider`),供 Friday 连接器检测、启用、启动和铸券;不交互、不授权目录、不输出永久凭据。接管旧 npx
|
|
73
|
+
beta.4 起同包提供 `provider.mjs`(bin `fridaynext-codex-provider`),供 Friday 连接器检测、启用、启动和铸券;不交互、不授权目录、不输出永久凭据。接管旧 npx 安装时复用原数据目录与配置;beta.5 起已装本组件更旧运行代码时,`probe` 报告 `upgradeAvailable:true` 与 `installedAdapterVersion`,`enable` 按上文流程自动升级。命令与限制见 [API](../API.md#connector-provider-合同-v1--fn-654)。
|
package/package.json
CHANGED
package/provider.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import net from 'node:net';
|
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
import { createHash } from 'node:crypto';
|
|
11
11
|
import { pathToFileURL } from 'node:url';
|
|
12
|
+
import { spawnSync } from 'node:child_process';
|
|
12
13
|
import { installRelease, verify, cli, installRoot as root, codexBinary as binary, packageRoot as pkg, pluginId } from './install.mjs';
|
|
13
14
|
import { codexOnboarding } from './onboarding.mjs';
|
|
14
15
|
import { stopManaged, verifyHealth, readPrivate, until } from './installer-process.mjs';
|
|
@@ -53,6 +54,83 @@ function versionAtLeast(value, minimum) {
|
|
|
53
54
|
return !a.pre || b.pre;
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
// FN-663:已装运行代码是否为本组件更旧的发行。只读文件,不调用宿主;无法确认时抛出结构化内部错误码。
|
|
58
|
+
const semver = value => typeof value === 'string' && /^\d+\.\d+\.\d+$/.test(value) ? value.split('.').map(Number) : undefined;
|
|
59
|
+
const internal = code => Object.assign(new Error(code), { code });
|
|
60
|
+
function legacyRelease() {
|
|
61
|
+
if (!fs.lstatSync(root, { throwIfNoEntry: false })) return undefined;
|
|
62
|
+
const release = read(path.join(pkg, 'release.json'));
|
|
63
|
+
let old;
|
|
64
|
+
try { old = read(path.join(root, 'release.json')); } catch { throw internal('INSTALLED_RELEASE_UNKNOWN'); }
|
|
65
|
+
if (old.payloadSHA256 === release.payloadSHA256) return undefined;
|
|
66
|
+
const from = semver(old.adapterVersion), to = semver(release.adapterVersion);
|
|
67
|
+
if (!from || !to) throw internal('INSTALLED_RELEASE_UNKNOWN');
|
|
68
|
+
const order = from.findIndex((part, i) => part !== to[i]);
|
|
69
|
+
// 同一适配器版本的不同载荷交给安装器既有规则(仅安装器升级或 INSTALL_VERSION_CONFLICT)。
|
|
70
|
+
if (order < 0) return undefined;
|
|
71
|
+
if (from[order] > to[order]) throw internal('INSTALLED_VERSION_NEWER');
|
|
72
|
+
verify(old); // 旧代码须仍是本组件原样发行(私有根、来源摘要一致)。
|
|
73
|
+
return old;
|
|
74
|
+
}
|
|
75
|
+
// 官方登记须为空缺或指向本安装根;返回现有登记,冲突时抛出。
|
|
76
|
+
async function legacyRegistration(installed) {
|
|
77
|
+
installed ??= (await cli(['plugin', 'list', '--json'])).installed;
|
|
78
|
+
const markets = (await cli(['plugin', 'marketplace', 'list', '--json'])).marketplaces;
|
|
79
|
+
if (!Array.isArray(installed) || !Array.isArray(markets)) throw internal('MARKETPLACE_RESPONSE_UNKNOWN');
|
|
80
|
+
const market = markets.find(value => value?.name === 'fridaynext-local');
|
|
81
|
+
if (market && realpath(market.root) !== realpath(root)) throw internal('MARKETPLACE_SOURCE_CONFLICT');
|
|
82
|
+
if (installed.some(value => value?.name === 'fridaynext-codex' && value.pluginId !== pluginId)) throw internal('PLUGIN_SOURCE_CONFLICT');
|
|
83
|
+
const current = installed.find(value => value?.pluginId === pluginId);
|
|
84
|
+
if (current && realpath(current.source?.path) !== realpath(plugin)) throw internal('PLUGIN_SOURCE_CONFLICT');
|
|
85
|
+
return { market: !!market, plugin: !!current };
|
|
86
|
+
}
|
|
87
|
+
// 旧代码的连接配置在独立子进程中用旧代码自身读取,避免本进程缓存旧模块后再加载同路径的新代码。
|
|
88
|
+
function legacyConfiguration() {
|
|
89
|
+
const script = `import(${JSON.stringify(pathToFileURL(path.join(plugin, 'src/private-state.mjs')).href)}).then(({ readConfiguration }) => {
|
|
90
|
+
try { const c = readConfiguration(); console.log(JSON.stringify({ dataRoot: c.dataRoot, nativeSocket: c.nativeSocket })); }
|
|
91
|
+
catch (error) { if (error.code === 'CODEX_PLUGIN_NOT_CONFIGURED') console.log('null'); else process.exit(3); } });`;
|
|
92
|
+
const result = spawnSync(process.execPath, ['--input-type=module', '-e', script], { encoding: 'utf8', env: process.env, timeout: 30000 });
|
|
93
|
+
if (result.status !== 0) throw internal('INSTALLED_CONFIG_UNKNOWN');
|
|
94
|
+
try { return JSON.parse(result.stdout); } catch { throw internal('INSTALLED_CONFIG_UNKNOWN'); }
|
|
95
|
+
}
|
|
96
|
+
const pidAlive = pid => { if (!Number.isInteger(pid) || pid <= 0) return false; try { process.kill(pid, 0); return true; } catch (error) { return error.code === 'EPERM'; } };
|
|
97
|
+
const ownerAlive = config => { try { return pidAlive(readPrivate(path.join(config.dataRoot, 'service-owner', 'owner.json')).pid); } catch { return false; } };
|
|
98
|
+
const stamp = () => new Date().toISOString().replace(/[-:]/g, '').replace(/\.\d+Z$/, 'Z');
|
|
99
|
+
|
|
100
|
+
// 按 distribution/README 的升级流程:停本组件旧 worker → 移除官方登记 → 旧代码移到备份 → 安装新代码并重新登记。
|
|
101
|
+
// 数据根、连接配置与安装器登记一律不动;任何前置核对失败都在改动之前返回。
|
|
102
|
+
async function upgradeLegacy(old) {
|
|
103
|
+
const registration = await legacyRegistration();
|
|
104
|
+
const config = legacyConfiguration();
|
|
105
|
+
if (config) {
|
|
106
|
+
const record = path.join(config.dataRoot, 'installer-worker.json');
|
|
107
|
+
if (!fs.existsSync(record) && ownerAlive(config)) throw internal('EXISTING_SERVICE_NOT_OWNED');
|
|
108
|
+
await stopOwnWorker(config, 'PROVIDER_INTERNAL');
|
|
109
|
+
try { await until(() => !ownerAlive(config), 30000); }
|
|
110
|
+
catch { throw new ProviderFailure('PROVIDER_INTERNAL', 'Codex Provider 执行失败:OLD_SERVICE_STILL_RUNNING', true); }
|
|
111
|
+
}
|
|
112
|
+
if (registration.plugin) await cli(['plugin', 'remove', pluginId], false);
|
|
113
|
+
if (registration.market) await cli(['plugin', 'marketplace', 'remove', 'fridaynext-local'], false);
|
|
114
|
+
const left = await legacyRegistration();
|
|
115
|
+
if (left.plugin || left.market) throw internal('LEGACY_REGISTRATION_REMAINS');
|
|
116
|
+
const backup = path.join(path.dirname(root), path.basename(root) + '.backup-' + stamp());
|
|
117
|
+
if (fs.existsSync(backup)) throw new ProviderFailure('PROVIDER_INTERNAL', 'Codex Provider 执行失败:BACKUP_EXISTS', true);
|
|
118
|
+
fs.renameSync(root, backup);
|
|
119
|
+
try { await installRelease(); }
|
|
120
|
+
catch (error) {
|
|
121
|
+
// 回滚:删除本次新解出的代码,恢复旧代码目录与原官方登记;原错误照常返回。
|
|
122
|
+
try {
|
|
123
|
+
if (fs.existsSync(root)) fs.rmSync(root, { recursive: true, force: true });
|
|
124
|
+
fs.renameSync(backup, root);
|
|
125
|
+
const now = await legacyRegistration();
|
|
126
|
+
if (registration.market && !now.market) await cli(['plugin', 'marketplace', 'add', root, '--json']);
|
|
127
|
+
if (registration.plugin && !now.plugin) await cli(['plugin', 'add', pluginId, '--json']);
|
|
128
|
+
} catch { /* 回滚尽力而为,备份目录保留供人工恢复。 */ }
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
return { upgradedFrom: old.adapterVersion, backupRoot: backup };
|
|
132
|
+
}
|
|
133
|
+
|
|
56
134
|
async function hostVersion() {
|
|
57
135
|
let output;
|
|
58
136
|
try { output = await cli(['--version'], false); }
|
|
@@ -83,6 +161,14 @@ async function snapshot() {
|
|
|
83
161
|
throw error;
|
|
84
162
|
}
|
|
85
163
|
if (!Array.isArray(installed)) return { ...state, compatible: false };
|
|
164
|
+
// FN-663:本安装根是本组件更旧的运行代码时如实上报可升级;仍按未启用处理,连接器据此视为可添加,enable 负责升级。
|
|
165
|
+
try {
|
|
166
|
+
const old = legacyRelease();
|
|
167
|
+
if (old) {
|
|
168
|
+
await legacyRegistration(installed);
|
|
169
|
+
return { ...state, upgradeAvailable: true, installedAdapterVersion: old.adapterVersion };
|
|
170
|
+
}
|
|
171
|
+
} catch { return state; }
|
|
86
172
|
const current = installed.find(value => value?.pluginId === pluginId);
|
|
87
173
|
if (current?.enabled !== true || !realpath(plugin) || realpath(current.source?.path) !== realpath(plugin)) return state;
|
|
88
174
|
// 已安装代码须与本发行运行载荷一致并通过来源摘要核验后,才加载其中模块。
|
|
@@ -211,12 +297,17 @@ const handlers = {
|
|
|
211
297
|
async probe() {
|
|
212
298
|
const s = await snapshot();
|
|
213
299
|
return { installed: s.installed, hostVersion: s.hostVersion, compatible: s.compatible, pluginEnabled: s.pluginEnabled, running: s.running,
|
|
214
|
-
needsHostRestartToEnable: false, state: stateOf(s),
|
|
300
|
+
needsHostRestartToEnable: false, state: stateOf(s), upgradeAvailable: s.upgradeAvailable === true,
|
|
301
|
+
...(s.upgradeAvailable ? { installedAdapterVersion: s.installedAdapterVersion } : {}),
|
|
302
|
+
...(s.installed ? {} : { installGuide: INSTALL_GUIDE }) };
|
|
215
303
|
},
|
|
216
304
|
async enable(input) {
|
|
217
305
|
const before = await hostVersion();
|
|
218
306
|
requireEnabled({ ...before, pluginEnabled: true });
|
|
219
|
-
|
|
307
|
+
// FN-663:本组件更旧的运行代码先按升级流程替换;数据根与连接配置保持,随后沿既有配置判断。
|
|
308
|
+
const old = legacyRelease();
|
|
309
|
+
const upgrade = old ? await upgradeLegacy(old) : undefined;
|
|
310
|
+
const { changed: installed } = upgrade ? { changed: true } : await installRelease();
|
|
220
311
|
const { readConfiguration } = await load('private-state');
|
|
221
312
|
let configured = false;
|
|
222
313
|
try { readConfiguration(); }
|
|
@@ -226,7 +317,7 @@ const handlers = {
|
|
|
226
317
|
await onboarding(input).configure();
|
|
227
318
|
configured = true;
|
|
228
319
|
}
|
|
229
|
-
return { changed: installed || configured, hostRestarted: false, state: stateOf(await snapshot()) };
|
|
320
|
+
return { changed: installed || configured, hostRestarted: false, state: stateOf(await snapshot()), ...(upgrade ?? {}) };
|
|
230
321
|
},
|
|
231
322
|
start,
|
|
232
323
|
async restart(input) {
|