@kioku-memory/cli 0.2.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/README.md +48 -8
- package/lib/agy.mjs +181 -0
- package/lib/clean.mjs +96 -0
- package/lib/codex.mjs +2 -2
- package/lib/conflicts.mjs +1303 -0
- package/lib/doctor.mjs +17 -4
- package/lib/gemini.mjs +199 -0
- package/lib/hermes.mjs +1 -1
- package/lib/install.mjs +55 -5
- package/lib/kioku.mjs +3 -0
- package/lib/lifecycle.mjs +13 -3
- package/lib/login.mjs +15 -3
- package/lib/opencode.mjs +144 -0
- package/lib/panel.mjs +18 -2
- package/lib/platforms.mjs +78 -1
- package/lib/setup.mjs +33 -6
- package/lib/wizard.mjs +105 -18
- 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/README.md
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
[Kioku](https://github.com/lonelyman0108/kioku) 是自托管的长期记忆服务。这个包提供 `kioku` 命令,要 Node 18 或更新的版本:
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
+
npx @kioku-memory/cli
|
|
7
|
+
# 检查已有配置,或装到全局
|
|
6
8
|
npx @kioku-memory/cli doctor
|
|
7
|
-
# 或者装到全局
|
|
8
9
|
npm install -g @kioku-memory/cli
|
|
9
10
|
```
|
|
10
11
|
|
|
@@ -30,13 +31,14 @@ Claude Code 的 kioku 插件自带同一个命令,启用插件后在它的 Bas
|
|
|
30
31
|
| 子命令 | 作用 |
|
|
31
32
|
|---|---|
|
|
32
33
|
| `kioku install --platforms <平台,…>` | 几个平台一起接入,访问密钥从环境变量读(给脚本用) |
|
|
33
|
-
| `kioku setup <平台>` | 把平台交给 Kioku 接管:停用平台自带的长期记忆;Codex、pi、Hermes、OpenClaw、DeepSeek Harness
|
|
34
|
+
| `kioku setup <平台>` | 把平台交给 Kioku 接管:停用平台自带的长期记忆;Codex、Gemini CLI、Antigravity、OpenCode、pi、Hermes、OpenClaw、DeepSeek Harness 再写下服务地址与访问密钥,其中 Codex、Gemini CLI、Antigravity 还配好 MCP 服务 |
|
|
34
35
|
| `kioku login <平台>` | 用浏览器授权签发访问密钥并配好这个平台,不用手动复制 |
|
|
35
36
|
| `kioku doctor [平台]` | 检查地址、访问密钥与平台的配置 |
|
|
37
|
+
| `kioku clean [平台]` | 检测并卸载冲突的记忆工具(Lore 及常见记忆 MCP) |
|
|
36
38
|
| `kioku import --from <来源>` | 把平台自带的本地长期记忆迁进 Kioku |
|
|
37
39
|
| `kioku run -e 变量=<标识>#<字段> -- <命令>` | 向 Kioku 取凭据的值,放进环境变量交给命令 |
|
|
38
40
|
|
|
39
|
-
每个子命令的完整说明:`kioku <子命令> --help`。现在认得的平台:`claude-code`、`codex`、`pi`、`hermes`、`openclaw`、`dsh`。
|
|
41
|
+
每个子命令的完整说明:`kioku <子命令> --help`。现在认得的平台:`claude-code`、`codex`、`gemini`、`agy`、`opencode`、`pi`、`hermes`、`openclaw`、`dsh`。
|
|
40
42
|
|
|
41
43
|
## login
|
|
42
44
|
|
|
@@ -44,7 +46,7 @@ Claude Code 的 kioku 插件自带同一个命令,启用插件后在它的 Bas
|
|
|
44
46
|
kioku login codex --server-url https://kioku.example.com
|
|
45
47
|
```
|
|
46
48
|
|
|
47
|
-
终端显示一个确认码并打开 Kioku 管理界面的确认页(`--no-browser` 时只显示地址)。登录后在页面上输入确认码,选空间、应用与权限范围,点确认;命令行取到访问密钥后接着做 `kioku setup` 的事:核对、写下配置。访问密钥全程不显示。认得 `codex`、`pi`、`hermes`、`openclaw`、`dsh`;Claude Code 的访问密钥在它的 `/plugin` 里填。
|
|
49
|
+
终端显示一个确认码并打开 Kioku 管理界面的确认页(`--no-browser` 时只显示地址)。登录后在页面上输入确认码,选空间、应用与权限范围,点确认;命令行取到访问密钥后接着做 `kioku setup` 的事:核对、写下配置。访问密钥全程不显示。认得 `codex`、`gemini`、`agy`、`opencode`、`pi`、`hermes`、`openclaw`、`dsh`;Claude Code 的访问密钥在它的 `/plugin` 里填。
|
|
48
50
|
|
|
49
51
|
- 确认码不在打开的地址里,要照着终端输入:只在自己刚运行了这条命令时确认。别人发来一个确认码让你去确认的,不要确认,那样对方的机器会拿到能读写你的记忆的访问密钥。
|
|
50
52
|
- 申请 10 分钟内有效。被拒绝、过期,或者确认之后确认人的角色变了,都拿不到访问密钥,重新运行即可。
|
|
@@ -62,7 +64,7 @@ export KIOKU_API_KEY_CODEX=… KIOKU_API_KEY_PI=…
|
|
|
62
64
|
kioku install --platforms codex,pi --server-url https://kioku.example.com -y
|
|
63
65
|
```
|
|
64
66
|
|
|
65
|
-
每个平台的访问密钥放在 `KIOKU_API_KEY_<平台>` 里(平台名大写、连字符换成下划线:`KIOKU_API_KEY_CLAUDE_CODE`、`KIOKU_API_KEY_CODEX`、`KIOKU_API_KEY_PI`、`KIOKU_API_KEY_HERMES`、`KIOKU_API_KEY_OPENCLAW`、`KIOKU_API_KEY_DSH`),没给的平台跳过并在结果里列出。各平台照 `kioku setup` 核对、写下配置、停用自带的长期记忆;Claude Code 只核对访问密钥、停用自动记忆,地址与访问密钥要在它的 `/plugin` 里填。
|
|
67
|
+
每个平台的访问密钥放在 `KIOKU_API_KEY_<平台>` 里(平台名大写、连字符换成下划线:`KIOKU_API_KEY_CLAUDE_CODE`、`KIOKU_API_KEY_CODEX`、`KIOKU_API_KEY_GEMINI`、`KIOKU_API_KEY_AGY`、`KIOKU_API_KEY_OPENCODE`、`KIOKU_API_KEY_PI`、`KIOKU_API_KEY_HERMES`、`KIOKU_API_KEY_OPENCLAW`、`KIOKU_API_KEY_DSH`),没给的平台跳过并在结果里列出。各平台照 `kioku setup` 核对、写下配置、停用自带的长期记忆;Claude Code 只核对访问密钥、停用自动记忆,地址与访问密钥要在它的 `/plugin` 里填。
|
|
66
68
|
|
|
67
69
|
- 在终端里运行、没带 `-y` 时先列计划再确认;`--dry-run` 只列计划。
|
|
68
70
|
- 最后列出要自己运行的插件安装命令。有平台失败时退出码为 1。
|
|
@@ -122,13 +124,51 @@ kioku setup dsh --server-url https://kioku.example.com
|
|
|
122
124
|
|
|
123
125
|
核对后写下 `~/.config/kioku/dsh.json`,不改 dsh 的设置(它没有自带的长期记忆)。插件按 profile 装:`dsh plugin --profile <profile> add github:lonelyman0108/kioku-plugins`,装完重启 dsh。
|
|
124
126
|
|
|
127
|
+
### Gemini CLI
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
kioku setup gemini --server-url https://kioku.example.com
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
核对后写下 `~/.config/kioku/gemini.json`,在 `~/.gemini/settings.json` 里加上 `mcpServers.kioku` 并把自带的 `save_memory` 加入 `excludeTools`。扩展按源码链接:`git clone https://github.com/lonelyman0108/kioku-plugins` 后 `gemini extensions link kioku-plugins/plugins/gemini`。
|
|
134
|
+
|
|
135
|
+
### Antigravity
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
kioku setup agy --server-url https://kioku.example.com
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
核对后写下 `~/.config/kioku/agy.json`,并在 `~/.gemini/config/mcp_config.json` 里加上 `mcpServers.kioku`(Antigravity 没有自带的长期记忆)。插件放到 `~/.gemini/config/plugins/kioku` 后新开会话生效。
|
|
142
|
+
|
|
143
|
+
### OpenCode
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
kioku setup opencode --server-url https://kioku.example.com
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
核对后写下 `~/.config/kioku/opencode.json`,并在 `~/.config/opencode/opencode.json` 的 `plugin` 列表里加上 `@kioku-memory/plugin-opencode`(原文件备份成 `opencode.json.kioku-backup`;OpenCode 没有自带的长期记忆,MCP 由插件在 `config` 钩子里注册)。
|
|
150
|
+
|
|
125
151
|
## doctor
|
|
126
152
|
|
|
127
153
|
```bash
|
|
128
154
|
kioku doctor claude-code
|
|
129
155
|
```
|
|
130
156
|
|
|
131
|
-
每项一行:`✓` 正常,`!` 要留意,`✗` 有问题(这时退出码为 1
|
|
157
|
+
每项一行:`✓` 正常,`!` 要留意,`✗` 有问题(这时退出码为 1)。查的是:地址连不连得上、访问密钥是否有效、它属于哪个应用、能读写哪些归属、最高敏感级与凭据能力,以及平台这一边插件是否启用、自带的长期记忆是否已停用、是否有冲突的记忆工具(如 Lore)。不写平台时按当前所在的会话认。
|
|
158
|
+
|
|
159
|
+
## clean
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
kioku clean --dry-run # 扫描全部平台,只列发现的冲突
|
|
163
|
+
kioku clean agy # 清理 Antigravity 上的冲突(交互确认)
|
|
164
|
+
kioku clean agy --tool lore -y # 非交互下只清理 Lore
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
检测并卸载与 Kioku 冲突的记忆工具(完整覆盖 Lore 的插件、MCP、钩子、环境变量与兼容状态,以及 Mem0、Supermemory、MCP 官方 Memory Server、Cipher、Claude-Mem 等常见记忆 MCP):
|
|
168
|
+
|
|
169
|
+
- **只清理目标平台侧的配置与插件挂载**:不会跨平台清理,也不会删除 `~/.lore/docker`、`~/.lore/config.json` 等服务端或用户本地数据。
|
|
170
|
+
- **接入前自动检查**:`kioku setup`、`kioku login`、`kioku install` 与交互向导在发现冲突时都会先提示。交互模式下询问是否先卸载;非交互模式下默认阻断,传入 `--remove-conflicts` 后先卸载再继续接入。
|
|
171
|
+
- **保守处理非托管文件**:非符号链接或缺少托管标记的插件目录、泛用名称 `memory` 但特征不明的 MCP 条目、`CLAUDE.md` 里的手写指引只告警提示、不自动删改(仅精确移除 Lore 托管的 `@~/.claude/lore-guidance.md` 导入行与 `lore-guidance.md`)。
|
|
132
172
|
|
|
133
173
|
## import
|
|
134
174
|
|
|
@@ -155,7 +195,7 @@ kioku import --from claude-code # 列出计划,确认后写入
|
|
|
155
195
|
- 只读普通的文本文件:符号链接不跟(它可以指到记忆目录之外的文件),太大的、不是文本的不读。
|
|
156
196
|
- 写到一半连不上时停下来,说明写了多少、还剩多少;重新运行会接着写。
|
|
157
197
|
- 不在终端里运行时要带 `--yes` 才写。`--path` 指明不在默认位置的目录。
|
|
158
|
-
- 地址与访问密钥读环境变量(Claude Code 的会话里已经配好);`--platform codex`、`--platform pi`、`--platform hermes`、`--platform openclaw` 或 `--platform dsh` 改用 `kioku setup` 给那个平台写下的。记忆迁进这个访问密钥所属的应用。
|
|
198
|
+
- 地址与访问密钥读环境变量(Claude Code 的会话里已经配好);`--platform codex`、`--platform gemini`、`--platform agy`、`--platform opencode`、`--platform pi`、`--platform hermes`、`--platform openclaw` 或 `--platform dsh` 改用 `kioku setup` 给那个平台写下的。记忆迁进这个访问密钥所属的应用。
|
|
159
199
|
- 指令文件(`AGENTS.md`、`CLAUDE.md`)不是记忆,不迁。Codex 自带的 Memories 存在它自己的数据库里、格式没有公开,迁不了。
|
|
160
200
|
|
|
161
201
|
迁完之后用 `kioku setup <平台>` 停用平台自带的记忆,免得两边接着各记一份。
|
|
@@ -170,7 +210,7 @@ macOS 与 Linux 上各平台都用真实的模型实测过。Windows 上跑过
|
|
|
170
210
|
|
|
171
211
|
## 地址与访问密钥
|
|
172
212
|
|
|
173
|
-
`kioku doctor codex`、`kioku doctor pi`、`kioku doctor hermes`、`kioku doctor openclaw`、`kioku doctor dsh` 读 `kioku setup` 写下的配置。别的情况下 `doctor` 与 `run` 从环境变量读:
|
|
213
|
+
`kioku doctor codex`、`kioku doctor gemini`、`kioku doctor agy`、`kioku doctor opencode`、`kioku doctor pi`、`kioku doctor hermes`、`kioku doctor openclaw`、`kioku doctor dsh` 读 `kioku setup` 写下的配置。别的情况下 `doctor` 与 `run` 从环境变量读:
|
|
174
214
|
|
|
175
215
|
- `KIOKU_SERVER_URL`:例如 `https://kioku.example.com`,不带 `/v1`
|
|
176
216
|
- `KIOKU_API_KEY`:在 Kioku 管理界面的「应用」页签发的访问密钥;或者用 `KIOKU_API_KEY_FILE` 指向只含访问密钥的文件
|
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/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
|
}
|