@leviyuan/lodestar 0.21.16 → 0.21.17
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 +18 -18
- 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 +237 -237
- 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
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.17",
|
|
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 }
|