@kioku-memory/openclaw 0.1.0 → 0.3.0
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/NOTICE +3 -0
- package/kioku.js +19 -2
- package/lib/agy.mjs +181 -0
- package/lib/api.mjs +4 -1
- package/lib/clean.mjs +96 -0
- package/lib/codex.mjs +14 -3
- package/lib/command.mjs +19 -2
- package/lib/conflicts.mjs +1303 -0
- package/lib/connect.mjs +152 -0
- package/lib/doctor.mjs +17 -4
- package/lib/dsh.mjs +8 -1
- package/lib/gemini.mjs +199 -0
- package/lib/hermes.mjs +17 -2
- package/lib/import.mjs +81 -42
- package/lib/install.mjs +196 -0
- package/lib/kioku.mjs +33 -6
- package/lib/lifecycle.mjs +13 -3
- package/lib/local.mjs +294 -0
- package/lib/login.mjs +129 -27
- package/lib/openclaw.mjs +9 -1
- package/lib/opencode.mjs +144 -0
- package/lib/panel.mjs +311 -0
- package/lib/pi.mjs +10 -1
- package/lib/platforms.mjs +171 -11
- package/lib/prompts.mjs +38 -0
- package/lib/setup.mjs +33 -6
- package/lib/wizard.mjs +534 -0
- package/package.json +1 -1
package/NOTICE
CHANGED
|
@@ -5,3 +5,6 @@ This product is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
|
5
5
|
|
|
6
6
|
packages/core/lib/command.mjs 里给 cmd.exe 转义参数的规则改写自 cross-spawn
|
|
7
7
|
(https://github.com/moxystudio/node-cross-spawn),MIT License,Copyright (c) 2018 Made With MOXY Lda。
|
|
8
|
+
|
|
9
|
+
plugins/opencode/index.js 里的对话事件映射与系统提示标记做法参考自 Lore
|
|
10
|
+
(opencode-plugin),MIT License,Copyright (c) Lore contributors。
|
package/kioku.js
CHANGED
|
@@ -139,6 +139,22 @@ export function createKioku({ env = process.env, now = Date.now } = {}) {
|
|
|
139
139
|
const runs = new Map()
|
|
140
140
|
// 正在跑用户从本机入口发起的一轮的会话:会话键 → 运行 id。工具只在这样的运行里调得动
|
|
141
141
|
const approved = new Map()
|
|
142
|
+
// 在后台跑、谁也不等的事:工具工厂里读配置,取工具清单并写回本机
|
|
143
|
+
const background = new Set()
|
|
144
|
+
|
|
145
|
+
function detach(promise) {
|
|
146
|
+
const tracked = promise.then(
|
|
147
|
+
() => background.delete(tracked),
|
|
148
|
+
() => background.delete(tracked),
|
|
149
|
+
)
|
|
150
|
+
background.add(tracked)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// 等后台的事都落定,包括做的过程中又起的。给用例用:不等的话用例结束、删掉临时目录时
|
|
154
|
+
// 清单可能还在往里写,请求也会落进下一个用例
|
|
155
|
+
async function idle() {
|
|
156
|
+
while (background.size) await Promise.all(background)
|
|
157
|
+
}
|
|
142
158
|
|
|
143
159
|
function tell(text) {
|
|
144
160
|
if (told.has(text)) return
|
|
@@ -208,6 +224,7 @@ export function createKioku({ env = process.env, now = Date.now } = {}) {
|
|
|
208
224
|
.finally(() => {
|
|
209
225
|
refreshing = null
|
|
210
226
|
})
|
|
227
|
+
detach(refreshing)
|
|
211
228
|
}
|
|
212
229
|
|
|
213
230
|
// 把一个事件交给服务端,返回要注入的文本(没有时为空字符串);失败时说一次原因,返回 undefined
|
|
@@ -324,7 +341,7 @@ export function createKioku({ env = process.env, now = Date.now } = {}) {
|
|
|
324
341
|
function toolsFor(ctx) {
|
|
325
342
|
if (!localTools(ctx)) return null
|
|
326
343
|
// 顺便把配置读上、看清单要不要重新取;都不等
|
|
327
|
-
ready().then(refreshTools, () => {})
|
|
344
|
+
detach(ready().then(refreshTools, () => {}))
|
|
328
345
|
const list = tools.filter((tool) => TOOL_NAMES.includes(tool.name))
|
|
329
346
|
return list.length ? list.map((tool) => toTool(tool, ctx.sessionKey)) : null
|
|
330
347
|
}
|
|
@@ -361,5 +378,5 @@ export function createKioku({ env = process.env, now = Date.now } = {}) {
|
|
|
361
378
|
)
|
|
362
379
|
}
|
|
363
380
|
|
|
364
|
-
return { register, beforePrompt, agentEnd, toolsFor, ready }
|
|
381
|
+
return { register, beforePrompt, agentEnd, toolsFor, ready, idle }
|
|
365
382
|
}
|
package/lib/agy.mjs
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// Antigravity (agy) 这个平台的 kioku setup 与 kioku doctor。
|
|
2
|
+
// agy 没有自带的长期记忆要停用,setup 做两件事:
|
|
3
|
+
// 1. 把服务地址与访问密钥写进本机文件(只给本人读写,插件的 hooks.json 钩子读它);
|
|
4
|
+
// 2. 在 ~/.gemini/config/mcp_config.json 里写入 mcpServers.kioku(Streamable HTTP)
|
|
5
|
+
|
|
6
|
+
import { stat } from 'node:fs/promises'
|
|
7
|
+
import { homedir } from 'node:os'
|
|
8
|
+
import { join } from 'node:path'
|
|
9
|
+
|
|
10
|
+
import { readSettings, safeWrite, serialize } from './files.mjs'
|
|
11
|
+
import { KiokuFailure } from './http.mjs'
|
|
12
|
+
import { profileFile, readProfile, removeProfile, writeProfile } from './profile.mjs'
|
|
13
|
+
import { resolveTarget } from './target.mjs'
|
|
14
|
+
|
|
15
|
+
export function agyHome(env) {
|
|
16
|
+
if (env.AGY_HOME) return env.AGY_HOME
|
|
17
|
+
return join(env.HOME || homedir(), '.gemini', 'config')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function agyMcpFile(env) {
|
|
21
|
+
return join(agyHome(env), 'mcp_config.json')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function checkMcpShape(settings, file) {
|
|
25
|
+
if (
|
|
26
|
+
settings.mcpServers !== undefined &&
|
|
27
|
+
(settings.mcpServers === null ||
|
|
28
|
+
typeof settings.mcpServers !== 'object' ||
|
|
29
|
+
Array.isArray(settings.mcpServers))
|
|
30
|
+
) {
|
|
31
|
+
throw new KiokuFailure(`${file} 里的 mcpServers 不是对象,没有改动它`)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function mcpEntry(url, key) {
|
|
36
|
+
return {
|
|
37
|
+
url: `${url}/v1/mcp`,
|
|
38
|
+
headers: { Authorization: `Bearer ${key}` },
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function sameMcp(existing, wanted) {
|
|
43
|
+
return (
|
|
44
|
+
existing?.url === wanted.url &&
|
|
45
|
+
existing?.headers?.Authorization === wanted.headers.Authorization
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function hasStoredKey(settings) {
|
|
50
|
+
return Boolean(settings?.mcpServers?.kioku?.headers?.Authorization)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function buildMcp(settings, { url, key, undo }) {
|
|
54
|
+
const next = { ...settings }
|
|
55
|
+
if (undo) {
|
|
56
|
+
if (
|
|
57
|
+
settings.mcpServers &&
|
|
58
|
+
typeof settings.mcpServers === 'object' &&
|
|
59
|
+
Object.hasOwn(settings.mcpServers, 'kioku')
|
|
60
|
+
) {
|
|
61
|
+
const mcp = { ...settings.mcpServers }
|
|
62
|
+
delete mcp.kioku
|
|
63
|
+
if (Object.keys(mcp).length) next.mcpServers = mcp
|
|
64
|
+
else delete next.mcpServers
|
|
65
|
+
}
|
|
66
|
+
return next
|
|
67
|
+
}
|
|
68
|
+
next.mcpServers = { ...(settings.mcpServers ?? {}), kioku: mcpEntry(url, key) }
|
|
69
|
+
return next
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function pluginInstalled(env, cwd) {
|
|
73
|
+
for (const file of [
|
|
74
|
+
join(agyHome(env), 'plugins', 'kioku', 'plugin.json'),
|
|
75
|
+
join(cwd, '.agents', 'plugins', 'kioku', 'plugin.json'),
|
|
76
|
+
]) {
|
|
77
|
+
if ((await stat(file).catch(() => null))?.isFile()) return true
|
|
78
|
+
}
|
|
79
|
+
return false
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function preflightAgy({ env }) {
|
|
83
|
+
const file = agyMcpFile(env)
|
|
84
|
+
const { settings } = await readSettings(file)
|
|
85
|
+
checkMcpShape(settings, file)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function setupAgy(options, io) {
|
|
89
|
+
const { env, out, cwd } = io
|
|
90
|
+
const profile = profileFile('agy', env)
|
|
91
|
+
const file = agyMcpFile(env)
|
|
92
|
+
|
|
93
|
+
if (options.undo) {
|
|
94
|
+
const { settings, text } = await readSettings(file)
|
|
95
|
+
checkMcpShape(settings, file)
|
|
96
|
+
const next = buildMcp(settings, { undo: true })
|
|
97
|
+
if (JSON.stringify(settings) === JSON.stringify(next)) {
|
|
98
|
+
if (text !== null) out.write(`${file} 不用改\n`)
|
|
99
|
+
} else {
|
|
100
|
+
out.write(`${file}:去掉 mcpServers.kioku\n`)
|
|
101
|
+
if (!options.dryRun) {
|
|
102
|
+
// 原文件里带着访问密钥时不留备份
|
|
103
|
+
await safeWrite(file, serialize(next, text), text, { backup: !hasStoredKey(settings) })
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (options.dryRun) out.write(`${profile}:删掉\n没有写入(--dry-run)\n`)
|
|
108
|
+
else if (await removeProfile('agy', env)) out.write(`已删掉 ${profile}\n`)
|
|
109
|
+
else out.write(`${profile} 本来就没有\n`)
|
|
110
|
+
return 0
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
await preflightAgy({ env })
|
|
114
|
+
const { url, key, saved } = await resolveTarget({ id: 'agy', name: 'Antigravity' }, options, {
|
|
115
|
+
...io,
|
|
116
|
+
beforeLogin: () => preflightAgy({ env }),
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
const { settings, text } = await readSettings(file)
|
|
120
|
+
checkMcpShape(settings, file)
|
|
121
|
+
const next = buildMcp(settings, { url, key, undo: false })
|
|
122
|
+
const sameProfile = Boolean(saved && saved.url === url && saved.key === key)
|
|
123
|
+
const sameFile = JSON.stringify(settings) === JSON.stringify(next)
|
|
124
|
+
|
|
125
|
+
if (sameProfile) out.write(`${profile} 不用改\n`)
|
|
126
|
+
else out.write(`${profile}:写入服务地址与访问密钥(只给本人读写)\n`)
|
|
127
|
+
|
|
128
|
+
if (sameFile) out.write(`${file} 不用改\n`)
|
|
129
|
+
else out.write(`${file}:配置 mcpServers.kioku\n`)
|
|
130
|
+
|
|
131
|
+
if (options.dryRun) {
|
|
132
|
+
out.write('没有写入(--dry-run)\n')
|
|
133
|
+
return 0
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (!sameProfile) await writeProfile('agy', { url, key }, env)
|
|
137
|
+
if (!sameFile) {
|
|
138
|
+
const backedUp = await safeWrite(file, serialize(next, text), text, {
|
|
139
|
+
backup: !hasStoredKey(settings),
|
|
140
|
+
})
|
|
141
|
+
if (backedUp) out.write(`原配置已备份到 ${file}.kioku-backup\n`)
|
|
142
|
+
}
|
|
143
|
+
out.write('Antigravity 已配好,新开会话生效。\n')
|
|
144
|
+
if (!(await pluginInstalled(env, cwd)) && io.hints !== false) {
|
|
145
|
+
out.write(
|
|
146
|
+
`接下来安装插件以启用生命周期钩子:cp -r <仓库目录>/plugins/agy ${join(agyHome(env), 'plugins', 'kioku')}\n`,
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
return 0
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export async function inspectAgy({ env, cwd }, { ok, warn }) {
|
|
153
|
+
const profile = await readProfile('agy', env).catch(() => null)
|
|
154
|
+
if (!profile) {
|
|
155
|
+
warn('没有 kioku setup agy 写下的地址与访问密钥,插件钩子不会生效:运行 kioku setup agy')
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const file = agyMcpFile(env)
|
|
159
|
+
const { settings } = await readSettings(file)
|
|
160
|
+
const entry = settings?.mcpServers?.kioku
|
|
161
|
+
if (!entry) {
|
|
162
|
+
warn(`${file} 里没有 mcpServers.kioku:运行 kioku setup agy`)
|
|
163
|
+
} else if (!entry.url) {
|
|
164
|
+
warn(`${file} 里的 mcpServers.kioku 缺少 url:运行 kioku setup agy`)
|
|
165
|
+
} else if (profile && !sameMcp(entry, mcpEntry(profile.url, profile.key))) {
|
|
166
|
+
warn(`${file} 里的 mcpServers.kioku 与当前地址或访问密钥不一致:运行 kioku setup agy`)
|
|
167
|
+
} else {
|
|
168
|
+
ok(`${file} 里的 mcpServers.kioku 已配好`)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (await pluginInstalled(env, cwd)) ok('Antigravity 已安装 kioku 插件')
|
|
172
|
+
else
|
|
173
|
+
warn(
|
|
174
|
+
`Antigravity 未安装 kioku 插件:将 plugins/agy 放到 ${join(agyHome(env), 'plugins', 'kioku')}`,
|
|
175
|
+
)
|
|
176
|
+
ok('Antigravity 没有自带的长期记忆要停用')
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export async function statusAgy({ env, cwd }) {
|
|
180
|
+
return { plugin: await pluginInstalled(env, cwd), memory: 'none' }
|
|
181
|
+
}
|
package/lib/api.mjs
CHANGED
|
@@ -4,6 +4,9 @@ import { fetchFailure, isRedirect, KiokuFailure, redirectError } from './http.mj
|
|
|
4
4
|
|
|
5
5
|
const TIMEOUT = 8000
|
|
6
6
|
|
|
7
|
+
// 服务端明说访问密钥不能用(401):和连不上、响应不对分开,向导据此标「已失效」
|
|
8
|
+
export class KeyRejected extends KiokuFailure {}
|
|
9
|
+
|
|
7
10
|
// 这个访问密钥对应的应用与权限;连不上、跳转、访问密钥无效、响应不对都以 KiokuFailure 抛出
|
|
8
11
|
export async function whoami({ url, key }) {
|
|
9
12
|
let res
|
|
@@ -22,7 +25,7 @@ export async function whoami({ url, key }) {
|
|
|
22
25
|
if (isRedirect(res.status)) {
|
|
23
26
|
throw new KiokuFailure(redirectError(res.status, res.headers.get('location'), url))
|
|
24
27
|
}
|
|
25
|
-
if (res.status === 401) throw new
|
|
28
|
+
if (res.status === 401) throw new KeyRejected('访问密钥无效或已吊销')
|
|
26
29
|
if (!res.ok) throw new KiokuFailure(`Kioku 返回 HTTP ${res.status}`)
|
|
27
30
|
if (
|
|
28
31
|
typeof data?.app?.runtimeFamily !== 'string' ||
|
package/lib/clean.mjs
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// kioku clean:检测并卸载与 Kioku 冲突的记忆工具(Lore 及常见记忆 MCP)。
|
|
2
|
+
// 默认先列计划并询问确认(非终端运行需传 -y/--yes);只清理平台侧配置,不删服务端数据目录。
|
|
3
|
+
|
|
4
|
+
import { CONFLICT_TOOLS, formatConflicts, removeConflicts, scanAllConflicts } from './conflicts.mjs'
|
|
5
|
+
import { confirm } from './import.mjs'
|
|
6
|
+
import { KiokuFailure } from './http.mjs'
|
|
7
|
+
import { platformNames, PLATFORMS } from './platforms.mjs'
|
|
8
|
+
import { UsageError } from './usage.mjs'
|
|
9
|
+
|
|
10
|
+
const CLEANABLE_TOOLS = Object.keys(CONFLICT_TOOLS).filter((id) => id !== 'unknown-memory')
|
|
11
|
+
|
|
12
|
+
export const CLEAN_USAGE = `用法:kioku clean [平台] [--tool <工具>] [--dry-run] [-y|--yes]
|
|
13
|
+
|
|
14
|
+
检测并卸载与 Kioku 冲突的记忆工具(Lore 及常见记忆 MCP)。
|
|
15
|
+
只清理目标平台上的接入配置或插件挂载,不删服务端数据目录。
|
|
16
|
+
|
|
17
|
+
[平台] ${platformNames()};不写时扫描全部平台
|
|
18
|
+
--tool <工具> 只清理指定工具:${CLEANABLE_TOOLS.join('、')}
|
|
19
|
+
--dry-run 只列出发现的冲突,不修改文件
|
|
20
|
+
-y, --yes 不问,直接清理(不在终端里运行时要带上)
|
|
21
|
+
`
|
|
22
|
+
|
|
23
|
+
export function parseCleanArgs(argv) {
|
|
24
|
+
const options = { platform: null, tool: null, dryRun: false, yes: false }
|
|
25
|
+
for (let i = 0; i < argv.length; i++) {
|
|
26
|
+
const arg = argv[i]
|
|
27
|
+
if (arg === '--dry-run') options.dryRun = true
|
|
28
|
+
else if (arg === '-y' || arg === '--yes') options.yes = true
|
|
29
|
+
else if (arg === '--tool') {
|
|
30
|
+
const value = argv[++i]
|
|
31
|
+
if (!value) throw new UsageError('--tool 后面要写工具名')
|
|
32
|
+
if (!CLEANABLE_TOOLS.includes(value)) {
|
|
33
|
+
throw new UsageError(`不认识的工具 ${value},可以用的:${CLEANABLE_TOOLS.join('、')}`)
|
|
34
|
+
}
|
|
35
|
+
options.tool = value
|
|
36
|
+
} else if (arg.startsWith('-')) {
|
|
37
|
+
throw new UsageError(`不认识的选项 ${arg}`)
|
|
38
|
+
} else if (options.platform !== null) {
|
|
39
|
+
throw new UsageError('最多写一个平台')
|
|
40
|
+
} else {
|
|
41
|
+
if (!Object.hasOwn(PLATFORMS, arg)) {
|
|
42
|
+
throw new UsageError(`不认识的平台 ${arg},可以用的:${platformNames()}`)
|
|
43
|
+
}
|
|
44
|
+
options.platform = arg
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return options
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function clean(
|
|
51
|
+
argv,
|
|
52
|
+
{ env = process.env, out = process.stdout, cwd = process.cwd(), stdin = process.stdin } = {},
|
|
53
|
+
) {
|
|
54
|
+
const options = parseCleanArgs(argv)
|
|
55
|
+
const targetIds = options.platform ? [options.platform] : Object.keys(PLATFORMS)
|
|
56
|
+
const all = await scanAllConflicts(targetIds, { env, cwd })
|
|
57
|
+
const items = options.tool ? all.filter((item) => item.tool === options.tool) : all
|
|
58
|
+
|
|
59
|
+
if (!items.length) {
|
|
60
|
+
out.write(
|
|
61
|
+
options.platform
|
|
62
|
+
? `${PLATFORMS[options.platform].name}:没有发现冲突的记忆工具\n`
|
|
63
|
+
: '没有发现冲突的记忆工具\n',
|
|
64
|
+
)
|
|
65
|
+
return 0
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
out.write('发现以下冲突或疑似项:\n')
|
|
69
|
+
out.write(`${formatConflicts(items, PLATFORMS).join('\n')}\n`)
|
|
70
|
+
|
|
71
|
+
const removable = items.filter((item) => item.removable)
|
|
72
|
+
if (options.dryRun) {
|
|
73
|
+
out.write('没有改动(--dry-run)\n')
|
|
74
|
+
return 0
|
|
75
|
+
}
|
|
76
|
+
if (!removable.length) {
|
|
77
|
+
out.write('没有可自动卸载的项,请按上面的提示手动处理。\n')
|
|
78
|
+
return 0
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (!options.yes) {
|
|
82
|
+
if (!stdin.isTTY) {
|
|
83
|
+
throw new KiokuFailure('不在终端里运行时要带 --yes 才清理;先用 --dry-run 看计划')
|
|
84
|
+
}
|
|
85
|
+
if (!(await confirm(`清理以上 ${removable.length} 项冲突?[y/N] `, { stdin, out }))) {
|
|
86
|
+
out.write('没有改动\n')
|
|
87
|
+
return 0
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
out.write('\n')
|
|
92
|
+
const results = await removeConflicts(removable, { env, cwd, out })
|
|
93
|
+
const failed = results.some((r) => !r.ok)
|
|
94
|
+
if (!failed) out.write('清理完成,重启对应平台后生效。\n')
|
|
95
|
+
return failed ? 1 : 0
|
|
96
|
+
}
|
package/lib/codex.mjs
CHANGED
|
@@ -50,7 +50,7 @@ const HEADER = new RegExp(
|
|
|
50
50
|
|
|
51
51
|
// 段的标题:[a.b] 或 [[a.b]],返回里面的名字;不是标题时为 null。
|
|
52
52
|
// 名字规整成一种写法再比:点两边的空白去掉,只含普通字符的那一段去掉引号
|
|
53
|
-
function headerOf(line) {
|
|
53
|
+
export function headerOf(line) {
|
|
54
54
|
const name = HEADER.exec(line)?.[1]
|
|
55
55
|
if (name === undefined) return null
|
|
56
56
|
return name
|
|
@@ -59,7 +59,7 @@ function headerOf(line) {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
// 这一行让没有合上的方括号多了几层:多行的数组里,单独成行的 [1, 2] 不是标题。引号里的不算
|
|
62
|
-
function bracketDelta(line) {
|
|
62
|
+
export function bracketDelta(line) {
|
|
63
63
|
const bare = line.replace(/"(?:[^"\\]|\\.)*"|'[^']*'/g, '').replace(/#.*$/, '')
|
|
64
64
|
return (bare.match(/\[/g)?.length ?? 0) - (bare.match(/\]/g)?.length ?? 0)
|
|
65
65
|
}
|
|
@@ -262,7 +262,7 @@ export async function setupCodex(options, io) {
|
|
|
262
262
|
`! ${file} 里 features 的写法认不出来,没有核对 Memories:运行 codex features disable memories 关掉它\n`,
|
|
263
263
|
)
|
|
264
264
|
}
|
|
265
|
-
out.write(`Codex 已配好,新开会话生效。\n${found.plugin ? '' : NEXT_STEPS}`)
|
|
265
|
+
out.write(`Codex 已配好,新开会话生效。\n${found.plugin || io.hints === false ? '' : NEXT_STEPS}`)
|
|
266
266
|
return 0
|
|
267
267
|
}
|
|
268
268
|
|
|
@@ -307,3 +307,14 @@ export async function inspectCodex({ env }, { ok, warn, bad, note }) {
|
|
|
307
307
|
warn('Codex 自带的 Memories 开着,会和 Kioku 各记一份:运行 kioku setup codex 关掉它')
|
|
308
308
|
} else ok('Codex 自带的 Memories 没有启用')
|
|
309
309
|
}
|
|
310
|
+
|
|
311
|
+
// 给向导的面板:插件启用没有、自带的 Memories 关了没有(null 是认不出)
|
|
312
|
+
export async function statusCodex({ env }) {
|
|
313
|
+
const found = scanConfig(await readText(join(codexHome(env), 'config.toml')))
|
|
314
|
+
const memory = found.memories?.value
|
|
315
|
+
? 'on'
|
|
316
|
+
: found.memoriesUnknown && !found.memories
|
|
317
|
+
? null
|
|
318
|
+
: 'off'
|
|
319
|
+
return { plugin: found.plugin, memory }
|
|
320
|
+
}
|
package/lib/command.mjs
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// 转义的规则照 cross-spawn 的做法写(MIT,来源登记在 NOTICE)
|
|
6
6
|
|
|
7
7
|
import { execFile, spawn } from 'node:child_process'
|
|
8
|
-
import { statSync } from 'node:fs'
|
|
9
|
-
import { win32 } from 'node:path'
|
|
8
|
+
import { accessSync, constants, statSync } from 'node:fs'
|
|
9
|
+
import { join, win32 } from 'node:path'
|
|
10
10
|
|
|
11
11
|
import { KiokuFailure } from './http.mjs'
|
|
12
12
|
|
|
@@ -50,6 +50,23 @@ export function findCommand(name, env, { exists = isFile } = {}) {
|
|
|
50
50
|
return null
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
// PATH 里有没有这个命令(向导的面板用来看平台装没装)。Windows 上照 findCommand 的规则找;
|
|
54
|
+
// 别的系统上找能执行的普通文件
|
|
55
|
+
export function hasCommand(name, env, { platform = process.platform } = {}) {
|
|
56
|
+
if (platform === 'win32') return findCommand(name, env) !== null
|
|
57
|
+
if (typeof name !== 'string' || !name) return false
|
|
58
|
+
const dirs = /\//.test(name) ? [''] : (envValue(env, 'PATH') ?? '').split(':').filter(Boolean)
|
|
59
|
+
return dirs.some((dir) => {
|
|
60
|
+
const file = dir ? join(dir, name) : name
|
|
61
|
+
try {
|
|
62
|
+
accessSync(file, constants.X_OK)
|
|
63
|
+
return statSync(file).isFile()
|
|
64
|
+
} catch {
|
|
65
|
+
return false
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
53
70
|
// cmd.exe 认作有特殊含义的字符
|
|
54
71
|
const META = /([()\][%!^"`<>&|;, *?])/g
|
|
55
72
|
|