@leviyuan/lodestar 0.21.16 → 0.21.18
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/lodestar-agent.js +50 -50
- package/dist/lodestar-claude.js +20 -20
- package/dist/lodestar-setup.js +52 -52
- package/dist/lodestar-stop.js +3 -3
- package/dist/lodestar-update.js +49 -49
- package/dist/lodestar-version.js +12 -12
- package/dist/lodestar.js +244 -243
- package/docs/claude-agent-backend.md +4 -0
- package/docs/models.md +2 -2
- package/docs/usage.md +2 -0
- package/package.json +14 -9
- package/scripts/postinstall.cjs +4 -2
- package/src/codex-plugin-cache.cjs +188 -0
- package/src/data-dir.cjs +5 -1
|
@@ -38,6 +38,10 @@ Claude 订阅统一由 `claude-sub` 管理登录验证、模型目录和额度
|
|
|
38
38
|
|
|
39
39
|
`claude-accounts.ts` 管理默认及按 `hi 备注` 首次收录的账号元数据,原生登录由用户手动完成;来源内部使用独立账号视图、模型目录和额度缓存。MD 汇总可用账号目录,启动时再校验实际选中的账号;默认账号未登录不会遮住已收录的可用账号。`claude-account-selection.ts` 只在启动时选号,不负责耗尽轮换。主会话首次提交输入前完成原生身份验证,账号实际变化会使旧模型/额度缓存失效。
|
|
40
40
|
|
|
41
|
+
新增备注账号持久化经过 `authenticating`、`syncing`,首次 Skills/插件同步及共享历史准备完成后才进入 `ready`。认证后保留同一个 control-only 进程等待同步,最长 120 秒;普通模型、额度查询和任务启动只接受 ready 账号,已有默认账号会话继续运行。失败记录为 `sync_failed`,保留原因和重试时间,用户通过 `hi 备注` 显式重试;不随每分钟额度刷新重启同步进程。中断后保留未完成状态,旧版 `enrolling` 记录仍可通过显式收录恢复。原生控制查询不提交用户输入,但初始化仍会触发云同步,因此不能在首次认证完成后立即关闭进程。
|
|
42
|
+
|
|
43
|
+
`claude-sync-warmup.ts` 核对原生身份对应的账号桶,要求 Skills 和插件各自有成功轮次标记、清单所列文件落地、待处理项和暂存目录清空,且连续两次间隔至少 5 秒的检查保持一致。原生复用此前成功轮次时,允许认证桶与启动前已完成快照完全一致;空远端集合有成功标记即可完成,不要求与默认账号技能集合相同。用户设置或本次启动设置显式关闭相应云同步时跳过该通道;缺目录、服务端未开放同步或未知文件格式不能推断为关闭,缺少完成证据仍超时报错。当前 SDK 无公开同步完成事件,检测依赖原生落盘标记,后续原生格式变化需适配。
|
|
44
|
+
|
|
41
45
|
`session-activity.ts` 按实际存活的 Claude 订阅进程与账号绑定统计会话:执行中或最近 30 分钟收到用户消息即为活跃,启动、等待回答、排队和后台任务也计入;同群去重,当前待启动群排除后再加一。消息时间持久化,重启后可恢复近期活跃判断,不保存消息内容。
|
|
42
46
|
|
|
43
47
|
`claude-quota.ts` 以完整 5h 额度为一份,所有账号统一:普通完整周窗口为 10 份,Fable 总周为 5 份、专属周为 10 份。5h、总周及实际返回的 OAuth、当前模型专属窗口均参与约束;缺值、重复、无效或过期重置时间均为 `MISS`,Fable 缺少唯一专属周也不参与选号。真实窗口耗尽与预测不足分别处理。
|
package/docs/models.md
CHANGED
|
@@ -72,7 +72,7 @@ lodestar-claude 工作号 auth login
|
|
|
72
72
|
|
|
73
73
|
该入口仅供用户本机终端使用,受管 Agent 上下文中拒绝启动;使用 Lodestar 当前选中的已安装 Claude 运行时,缺失时报错,不自动安装或回退。它保留终端的 `HOME` 和工作目录;`default` 保留终端 `CLAUDE_CONFIG_DIR` 的未设置状态或原始路径,不读取 `[claude.env]`。
|
|
74
74
|
|
|
75
|
-
在 Claude Code 会话发送 `hi 工作号`,Lodestar
|
|
75
|
+
在 Claude Code 会话发送 `hi 工作号`,Lodestar 只检查这个备注对应的目录。新增备注账号通过原生订阅身份验证后,卡片显示“已登录,正在完成首次同步”,保留认证进程等待 Skills 和插件云同步完成,再收录并启动;不会扫描其他目录或代办登录。首次同步最长等待 120 秒,期间不查询该账号的模型或额度、不参与自动选号,也不能启动任务或切换到该账号。失败保留账号和原因,按提示稍后再次发送 `hi 工作号` 重试;连续失败的重试间隔依次为 1、2、4、5 分钟,不由后台额度轮询自动重试。`hi default` 指定原生默认账号。指定账号只影响本次启动;同号正在运行时显示状态,忙碌时不能切换其他号,空闲时可用 `hi 另一备注` 切换并恢复原会话。
|
|
76
76
|
|
|
77
77
|
不指定账号时,启动从默认及已收录账号的模型和额度缓存中选择。5 小时、总周以及接口实际返回的 OAuth 应用周窗口、当前模型专属窗口都必须可用:已用百分比须在 `0%` 到 `100%` 之间(不含 `100%`),重置时间须有效且尚未到期。缺值、无效或已过期的重置时间,以及同模型匹配多个专属周窗口,都按 `MISS` 排除;任一适用窗口耗尽也不能入选。
|
|
78
78
|
|
|
@@ -94,7 +94,7 @@ lodestar-claude 工作号 auth login
|
|
|
94
94
|
|
|
95
95
|
账号和模型目录通过 Claude Code 原生 SDK 查询,模型与 effort 随目录更新;未登录会显示启用引导,查询失败显示 `MISS`。可选配置节为 `[token_source.claude-sub]`,支持 `enabled`、`display`、`model`、`effort`、`hidden_models` 和 `custom_models`。`enabled = false` 禁用,`enabled = true` 或省略时沿用本机登录检测;群命令更新该字段。
|
|
96
96
|
|
|
97
|
-
订阅额度通过原生 `/usage`
|
|
97
|
+
订阅额度通过原生 `/usage` 控制接口读取,无需发送模型对话;每次实际查询仍会启动一个独立的 control-only Claude Code 进程,并执行原生启动初始化,查询后关闭。首次同步完成前不会为新增备注账号启动这些短命查询进程。`hi` 展示 5 小时、总周额度和接口返回的模型专属周额度及重置倒计时。回复底部同时显示 5 小时额度与周额度:本轮所选模型有专属周额度时显示该模型的额度,否则显示总周额度,沿用紧凑格式。后台瞬态查询失败保留成功缓存;没有缓存、认证失效或专属窗口缺数值时显示 `MISS`,不将缺失的专属额度改成总额度。此 SDK 查询接口仍属实验接口,版本不支持或接口变化时明确报错。
|
|
98
98
|
|
|
99
99
|
订阅进程保留本机和项目的 Claude 设置,并在进程内清除其他来源的 API key、模型映射和中转路由。发送任务前会再次核对实际账号是否为第一方订阅。Claude 订阅统一使用“Claude Code 订阅”来源,`md`、`hi` 和回复底部共用该来源的账号与额度。
|
|
100
100
|
|
package/docs/usage.md
CHANGED
|
@@ -37,6 +37,8 @@ Codex 和 Claude 执行任务时,可以直接发消息补充要求或纠正方
|
|
|
37
37
|
|
|
38
38
|
默认账号沿用设备上直接执行 `codex` 的登录态:使用 daemon 原始环境中的 `CODEX_HOME`,未设置时为 `~/.codex`。`codex-account` 只改变当前群后续 Codex 进程的认证选择,不覆盖默认账号,也不改变其他群。额外账号的备注名可包含中文和空格,不能包含换行或路径分隔符;`default`、`默认` 为保留名称。
|
|
39
39
|
|
|
40
|
+
每个 Codex 账号的 `plugins` 目录及插件缓存独立,避免不同安装清单在同步时互相删包;会话历史、Skill 和公共配置仍按原规则共享。安装或更新 Lodestar 时会自动把旧的共享插件链接迁为独立副本,保留默认缓存、各账号登录状态和安装清单,无需重新登录。跳过 npm 安装脚本或直接使用源码时,额外账号下次启动前也会自动迁移。安装命令须使用与 daemon 相同的 `LODESTAR_DATA_DIR` / `XDG_DATA_HOME` 和自定义 `CODEX_HOME`;迁移失败会明确报错。安装不会重启 daemon;仍在运行的旧版会把独立插件目录视为共享路径异常,升级后须按正常流程重启 daemon,再新建或切换额外账号会话。
|
|
41
|
+
|
|
40
42
|
发送 `codex-reset` 直接为当前运行的 Codex 账号使用一次重置卡;`codex-reset 工作` 为指定账号使用,`codex-reset default` 为设备默认账号使用。当前没有运行的 Codex 账号或正在等待选号时,必须带备注。命令不会切换账号或重启会话,额度不足时也不会自动使用重置卡。回执区分已重置、本次请求此前已完成、没有可重置窗口、没有可用卡,并重新读取剩余卡数和额度;查询失败显示 `MISS`,已确认的扣卡结果仍保留。同一消息的网络重试复用幂等标识,重新发送命令则是新的一次使用请求。接口失败或结果未知时,先用 `hi` 核对卡数、`codex-accounts` 核对额度。
|
|
41
43
|
|
|
42
44
|
额外账号不再使用时,发送 `codex-account-delete 工作`。删除会移除该账号的本地记录、独立认证目录和额度缓存,并清除所有群对它的指定,这些群下次启动恢复自动选号;共享会话历史、配置和其他账号保留。正在被会话、委派任务、额度或模型查询使用的账号不能删除;登录中的账号先用 `codex-login-cancel 工作` 取消。备注必填,设备默认账号不能通过此命令删除。需要重新添加时使用 `codex-login 工作`;本地删除不会注销 OpenAI 账号或取消订阅。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leviyuan/lodestar",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.18",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
"docs/",
|
|
62
62
|
"scripts/postinstall.cjs",
|
|
63
63
|
"src/data-dir.cjs",
|
|
64
|
+
"src/codex-plugin-cache.cjs",
|
|
64
65
|
"src/managed-skill-cleanup.cjs",
|
|
65
66
|
"README.md",
|
|
66
67
|
"LICENSE"
|
|
@@ -75,8 +76,9 @@
|
|
|
75
76
|
"@resvg/resvg-js": "^2.6.2",
|
|
76
77
|
"@xmldom/xmldom": "0.9.12",
|
|
77
78
|
"axios": "1.20.0",
|
|
79
|
+
"body-parser": "2.4.0",
|
|
78
80
|
"cross-spawn": "^7.0.6",
|
|
79
|
-
"fast-uri": "3.1.
|
|
81
|
+
"fast-uri": "3.1.9",
|
|
80
82
|
"fflate": "0.8.3",
|
|
81
83
|
"follow-redirects": "1.16.1",
|
|
82
84
|
"hono": "4.13.12",
|
|
@@ -87,9 +89,9 @@
|
|
|
87
89
|
"node-fetch": "^3.3.2",
|
|
88
90
|
"protobufjs": "7.6.5",
|
|
89
91
|
"proxy-addr": "2.0.8",
|
|
90
|
-
"qs": "6.16.
|
|
92
|
+
"qs": "6.16.1",
|
|
91
93
|
"ws": "8.21.3",
|
|
92
|
-
"zod": "
|
|
94
|
+
"zod": "4.6.6"
|
|
93
95
|
},
|
|
94
96
|
"bundleDependencies": [
|
|
95
97
|
"mathjax-full"
|
|
@@ -99,15 +101,17 @@
|
|
|
99
101
|
"@modelcontextprotocol/sdk": "1.32.1",
|
|
100
102
|
"@xmldom/xmldom": "0.9.12",
|
|
101
103
|
"axios": "1.20.0",
|
|
102
|
-
"fast-uri": "3.1.
|
|
104
|
+
"fast-uri": "3.1.9",
|
|
103
105
|
"fflate": "0.8.3",
|
|
104
106
|
"hono": "4.13.12",
|
|
105
107
|
"ip-address": "10.7.4",
|
|
106
108
|
"protobufjs": "7.6.5",
|
|
107
109
|
"proxy-addr": "2.0.8",
|
|
108
|
-
"qs": "6.16.
|
|
110
|
+
"qs": "6.16.1",
|
|
109
111
|
"ws": "8.21.3",
|
|
110
|
-
"follow-redirects": "1.16.1"
|
|
112
|
+
"follow-redirects": "1.16.1",
|
|
113
|
+
"body-parser": "2.4.0",
|
|
114
|
+
"zod": "4.6.6"
|
|
111
115
|
},
|
|
112
116
|
"devDependencies": {
|
|
113
117
|
"@anthropic-ai/claude-agent-sdk": "latest",
|
|
@@ -356,12 +360,13 @@
|
|
|
356
360
|
"koffi"
|
|
357
361
|
],
|
|
358
362
|
"optionalDependencies": {
|
|
359
|
-
"undici": "^6.
|
|
363
|
+
"undici": "^6.29.1"
|
|
360
364
|
},
|
|
361
365
|
"agentRuntimeOverrides": {
|
|
362
366
|
"dsh": {
|
|
363
367
|
"@modelcontextprotocol/client": "2.3.1",
|
|
364
|
-
"@modelcontextprotocol/core": "2.3.1"
|
|
368
|
+
"@modelcontextprotocol/core": "2.3.1",
|
|
369
|
+
"undici": "8.12.2"
|
|
365
370
|
}
|
|
366
371
|
}
|
|
367
372
|
}
|
package/scripts/postinstall.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
//
|
|
2
|
+
// 迁移账号插件缓存、清理废弃的受管 Skill 并提示下一步,不启动 Agent 或 daemon。
|
|
3
3
|
//
|
|
4
4
|
// 为什么不自动拉向导: npm 7+ pipe 了 postinstall 的 stdio, 自动拉向导只能
|
|
5
5
|
// 靠接管 /dev/tty 把终端塞给子进程 —— 这套机制脆弱 (作者原注 "Tricky")。
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
//
|
|
10
10
|
// 稳的做法是 trigger-on-first-run: 用户在真终端首跑 lodestar-daemon 时,
|
|
11
11
|
// cli.ts 发现没 config + isTTY 就自动进入向导 (真 TTY, readline 一定正常)。
|
|
12
|
-
//
|
|
12
|
+
// 迁移与清理仅操作本地插件和 Skill 文件,不读凭据,也不启动子进程。
|
|
13
13
|
|
|
14
14
|
const fs = require('fs')
|
|
15
15
|
|
|
@@ -29,6 +29,8 @@ function termWrite (msg) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
async function main () {
|
|
32
|
+
const { migrateCodexPluginCaches } = require('../src/codex-plugin-cache.cjs')
|
|
33
|
+
migrateCodexPluginCaches()
|
|
32
34
|
const { removeManagedSkill } = require('../src/managed-skill-cleanup.cjs')
|
|
33
35
|
removeManagedSkill('lodestar-files')
|
|
34
36
|
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// Shared by account startup and npm postinstall. No config, auth or Agent imports.
|
|
2
|
+
const fs = require('node:fs')
|
|
3
|
+
const { homedir } = require('node:os')
|
|
4
|
+
const { dirname, isAbsolute, join, relative, resolve, sep } = require('node:path')
|
|
5
|
+
const { randomUUID } = require('node:crypto')
|
|
6
|
+
const { codexAccountsDir } = require('./data-dir.cjs')
|
|
7
|
+
|
|
8
|
+
const BACKUP = '.lodestar-plugins-shared-link'
|
|
9
|
+
const LOCK = '.lodestar-plugins-migration.lock'
|
|
10
|
+
|
|
11
|
+
function stat (path) {
|
|
12
|
+
try { return fs.lstatSync(path) } catch (error) {
|
|
13
|
+
if (error.code === 'ENOENT') return undefined
|
|
14
|
+
throw error
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Resolve existing ancestors too, so relative links, home aliases and missing
|
|
19
|
+
// legacy targets can all be checked without creating anything at the target.
|
|
20
|
+
function canonical (path) {
|
|
21
|
+
try { return fs.realpathSync(path) } catch (error) {
|
|
22
|
+
if (error.code !== 'ENOENT') throw error
|
|
23
|
+
const parent = dirname(path)
|
|
24
|
+
if (parent === path) throw error
|
|
25
|
+
return resolve(canonical(parent), relative(parent, path))
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isWithin (root, path) {
|
|
30
|
+
const rel = relative(root, path)
|
|
31
|
+
return rel === '' || (!isAbsolute(rel) && rel !== '..' && !rel.startsWith(`..${sep}`))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function assertLegacyLink (path, source) {
|
|
35
|
+
const info = stat(path)
|
|
36
|
+
if (!info?.isSymbolicLink()) throw new Error(`Codex 插件迁移路径不是旧共享链接:${path}`)
|
|
37
|
+
const target = resolve(dirname(path), fs.readlinkSync(path))
|
|
38
|
+
if (canonical(target) !== canonical(source)) throw new Error(`Codex 插件共享链接指向未知位置:${path}`)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function assertHome (home, defaultHome) {
|
|
42
|
+
const info = stat(home)
|
|
43
|
+
if (!info || !info.isDirectory() || info.isSymbolicLink()) throw new Error(`Codex 账号目录不是独立目录:${home}`)
|
|
44
|
+
if (canonical(home) === canonical(defaultHome)) throw new Error('额外账号不能使用默认认证目录')
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function preflight (home, defaultHome) {
|
|
48
|
+
assertHome(home, defaultHome)
|
|
49
|
+
const source = join(defaultHome, 'plugins')
|
|
50
|
+
const plugins = join(home, 'plugins')
|
|
51
|
+
const backup = join(home, BACKUP)
|
|
52
|
+
if (stat(backup)) assertLegacyLink(backup, source)
|
|
53
|
+
const current = stat(plugins)
|
|
54
|
+
if (current?.isSymbolicLink()) assertLegacyLink(plugins, source)
|
|
55
|
+
else if (current && !current.isDirectory()) throw new Error(`Codex 插件路径不是目录:${plugins}`)
|
|
56
|
+
// A custom data directory may sit under the native plugin directory. Copying
|
|
57
|
+
// that source would also copy this account and its newly created staging tree.
|
|
58
|
+
if ((current?.isSymbolicLink() || (!current && stat(backup))) && isWithin(canonical(source), canonical(home))) {
|
|
59
|
+
throw new Error(`Codex 账号目录位于默认插件目录内,拒绝递归复制:${home}`)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function acquireLock (home) {
|
|
64
|
+
const path = join(home, LOCK)
|
|
65
|
+
// A hard link publishes the complete owner atomically; observers never see
|
|
66
|
+
// an empty PID file. A live owner fails visibly instead of blocking startup.
|
|
67
|
+
const candidate = join(home, `${LOCK}.${randomUUID()}`)
|
|
68
|
+
fs.writeFileSync(candidate, JSON.stringify({ pid: process.pid }), { flag: 'wx', mode: 0o600 })
|
|
69
|
+
try {
|
|
70
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
71
|
+
try {
|
|
72
|
+
fs.linkSync(candidate, path)
|
|
73
|
+
const owned = fs.lstatSync(path)
|
|
74
|
+
return () => {
|
|
75
|
+
const current = stat(path)
|
|
76
|
+
if (current && current.ino === owned.ino && current.dev === owned.dev) fs.unlinkSync(path)
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error.code !== 'EEXIST') throw error
|
|
80
|
+
const before = stat(path)
|
|
81
|
+
if (!before) continue
|
|
82
|
+
if (!before.isFile() || before.isSymbolicLink()) throw new Error(`Codex 插件迁移锁无效:${path}`)
|
|
83
|
+
const owner = JSON.parse(fs.readFileSync(path, 'utf8'))
|
|
84
|
+
if (!Number.isSafeInteger(owner.pid) || owner.pid <= 0) throw new Error(`Codex 插件迁移锁无效:${path}`)
|
|
85
|
+
try {
|
|
86
|
+
process.kill(owner.pid, 0)
|
|
87
|
+
throw new Error('Codex 插件目录正在迁移,请稍后重试')
|
|
88
|
+
} catch (status) {
|
|
89
|
+
if (status.code !== 'ESRCH') throw status
|
|
90
|
+
}
|
|
91
|
+
const after = stat(path)
|
|
92
|
+
if (after && before.ino === after.ino && before.dev === after.dev) fs.unlinkSync(path)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
throw new Error('Codex 插件迁移锁持续变化,请稍后重试')
|
|
96
|
+
} finally {
|
|
97
|
+
fs.unlinkSync(candidate)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function copyTree (source, target, sourceRoot, targetRoot, finalRoot) {
|
|
102
|
+
const info = fs.lstatSync(source)
|
|
103
|
+
if (info.isSymbolicLink()) {
|
|
104
|
+
const linked = canonical(resolve(dirname(source), fs.readlinkSync(source)))
|
|
105
|
+
if (!isWithin(sourceRoot, linked)) throw new Error(`Codex 插件缓存包含目录外链接,拒绝复制:${source}`)
|
|
106
|
+
const isolated = join(targetRoot, relative(sourceRoot, linked))
|
|
107
|
+
let directory = false
|
|
108
|
+
try { directory = fs.statSync(source).isDirectory() } catch (error) { if (error.code !== 'ENOENT') throw error }
|
|
109
|
+
fs.symlinkSync(process.platform === 'win32' && directory ? join(finalRoot, relative(sourceRoot, linked)) : relative(dirname(target), isolated),
|
|
110
|
+
target, directory && process.platform === 'win32' ? 'junction' : directory ? 'dir' : 'file')
|
|
111
|
+
} else if (info.isDirectory()) {
|
|
112
|
+
fs.mkdirSync(target, { mode: 0o700 })
|
|
113
|
+
for (const child of fs.readdirSync(source)) copyTree(join(source, child), join(target, child), sourceRoot, targetRoot, finalRoot)
|
|
114
|
+
} else if (info.isFile()) {
|
|
115
|
+
fs.copyFileSync(source, target, fs.constants.COPYFILE_EXCL)
|
|
116
|
+
} else {
|
|
117
|
+
throw new Error(`Codex 插件缓存包含不支持的文件类型:${source}`)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function prepareCodexPluginDirectory (home, defaultHome) {
|
|
122
|
+
home = resolve(home)
|
|
123
|
+
defaultHome = resolve(defaultHome)
|
|
124
|
+
preflight(home, defaultHome)
|
|
125
|
+
const plugins = join(home, 'plugins')
|
|
126
|
+
const source = join(defaultHome, 'plugins')
|
|
127
|
+
const backup = join(home, BACKUP)
|
|
128
|
+
// Keep existing independent directories completely untouched.
|
|
129
|
+
if (stat(plugins)?.isDirectory() && !stat(backup)) return
|
|
130
|
+
const release = acquireLock(home)
|
|
131
|
+
try {
|
|
132
|
+
preflight(home, defaultHome)
|
|
133
|
+
if (stat(backup)) {
|
|
134
|
+
// A crash before publication leaves the old link here; a crash after
|
|
135
|
+
// publication leaves an independent directory plus this redundant link.
|
|
136
|
+
if (!stat(plugins)) fs.renameSync(backup, plugins)
|
|
137
|
+
else if (stat(plugins).isDirectory()) fs.unlinkSync(backup)
|
|
138
|
+
else throw new Error(`Codex 插件迁移存在冲突链接:${backup}`)
|
|
139
|
+
}
|
|
140
|
+
const current = stat(plugins)
|
|
141
|
+
if (!current) {
|
|
142
|
+
fs.mkdirSync(plugins, { mode: 0o700 })
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
if (current.isDirectory()) return
|
|
146
|
+
assertLegacyLink(plugins, source)
|
|
147
|
+
const temporary = fs.mkdtempSync(join(home, '.lodestar-plugins-copy-'))
|
|
148
|
+
const staged = join(temporary, 'plugins')
|
|
149
|
+
try {
|
|
150
|
+
let sourceRoot
|
|
151
|
+
try { sourceRoot = fs.realpathSync(source) } catch (error) { if (error.code !== 'ENOENT') throw error }
|
|
152
|
+
if (sourceRoot) {
|
|
153
|
+
if (!fs.statSync(sourceRoot).isDirectory()) throw new Error(`Codex 默认插件路径不是目录:${source}`)
|
|
154
|
+
copyTree(sourceRoot, staged, sourceRoot, staged, plugins)
|
|
155
|
+
} else fs.mkdirSync(staged, { mode: 0o700 })
|
|
156
|
+
// Copy failure never removes the old link. Recheck immediately before
|
|
157
|
+
// swapping; an unexpected path is not overwritten or recursively removed.
|
|
158
|
+
assertLegacyLink(plugins, source)
|
|
159
|
+
fs.renameSync(plugins, backup)
|
|
160
|
+
try {
|
|
161
|
+
fs.renameSync(staged, plugins)
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (!stat(plugins)) fs.renameSync(backup, plugins)
|
|
164
|
+
throw error
|
|
165
|
+
}
|
|
166
|
+
fs.unlinkSync(backup)
|
|
167
|
+
} finally {
|
|
168
|
+
fs.rmSync(temporary, { recursive: true, force: true })
|
|
169
|
+
}
|
|
170
|
+
} finally {
|
|
171
|
+
release()
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function migrateCodexPluginCaches (options = {}) {
|
|
176
|
+
const defaultHome = resolve(options.defaultHome || process.env.CODEX_HOME || join(homedir(), '.codex'))
|
|
177
|
+
const root = resolve(options.accountsRoot || codexAccountsDir())
|
|
178
|
+
const info = stat(root)
|
|
179
|
+
if (!info) return
|
|
180
|
+
if (!info.isDirectory() || info.isSymbolicLink()) throw new Error(`Codex 账号根目录不是独立目录:${root}`)
|
|
181
|
+
// Do not read credentials or infer arbitrary homes from names. Unregistered
|
|
182
|
+
// UUID homes from an interrupted account creation need the same repair.
|
|
183
|
+
const homes = fs.readdirSync(root).filter(name => /^[a-f0-9-]{36}$/.test(name)).map(name => join(root, name))
|
|
184
|
+
for (const home of homes) preflight(home, defaultHome)
|
|
185
|
+
for (const home of homes) prepareCodexPluginDirectory(home, defaultHome)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
module.exports = { prepareCodexPluginDirectory, migrateCodexPluginCaches }
|
package/src/data-dir.cjs
CHANGED
|
@@ -15,4 +15,8 @@ function managedClaudePluginDir () {
|
|
|
15
15
|
return join(lodestarDataDir(), 'managed-claude-plugin')
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
function codexAccountsDir () {
|
|
19
|
+
return join(lodestarDataDir(), 'codex-accounts')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = { lodestarDataDir, managedClaudePluginDir, codexAccountsDir }
|