@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/lib/panel.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { stat } from 'node:fs/promises'
|
|
|
5
5
|
|
|
6
6
|
import { KeyRejected, whoami } from './api.mjs'
|
|
7
7
|
import { hasCommand } from './command.mjs'
|
|
8
|
+
import { conflictToolsText, scanConflicts } from './conflicts.mjs'
|
|
8
9
|
import { failureText, fetchFailure, isRedirect, KiokuFailure } from './http.mjs'
|
|
9
10
|
import { countLocal } from './import.mjs'
|
|
10
11
|
import { PLATFORMS } from './platforms.mjs'
|
|
@@ -110,6 +111,8 @@ export async function scanPlatform(id, { env, cwd, url }) {
|
|
|
110
111
|
|
|
111
112
|
// 只数本地有几条;和 Kioku 比(没迁的有几条)要一条一条地问,选了迁移再比
|
|
112
113
|
if (platform.source) row.local = await countLocal(platform.source, { env }).catch(() => null)
|
|
114
|
+
const conflicts = await scanConflicts(id, { env, cwd }).catch(() => [])
|
|
115
|
+
if (conflicts.length) row.conflicts = conflicts
|
|
113
116
|
return row
|
|
114
117
|
}
|
|
115
118
|
|
|
@@ -174,8 +177,8 @@ function platformLines(row) {
|
|
|
174
177
|
if (row.otherServer) facts.push(shownUrl(row.url))
|
|
175
178
|
if (row.reason) facts.push(row.reason)
|
|
176
179
|
const first = [`${row.name}:${head}`, ...facts].join(' · ')
|
|
177
|
-
//
|
|
178
|
-
if (!row.present && row.connection === 'none') return [first]
|
|
180
|
+
// 没装、也没配过且没有冲突的平台只写一行
|
|
181
|
+
if (!row.present && row.connection === 'none' && !row.conflicts?.length) return [first]
|
|
179
182
|
const details = []
|
|
180
183
|
if (row.connection === 'manual') details.push('访问密钥 无法判断(在 /plugin 里填)')
|
|
181
184
|
details.push(`插件 ${PLUGIN_NAMES.get(row.plugin) ?? '无法判断'}`)
|
|
@@ -190,6 +193,9 @@ function platformLines(row) {
|
|
|
190
193
|
: `(未迁移 ${row.pending.pending} 条)`
|
|
191
194
|
details.push(`本地记忆 ${row.local} 条${pending}`)
|
|
192
195
|
}
|
|
196
|
+
if (row.conflicts?.length) {
|
|
197
|
+
details.push(`冲突 ${conflictToolsText(row.conflicts)}`)
|
|
198
|
+
}
|
|
193
199
|
return [first, ` ${details.join(' · ')}`]
|
|
194
200
|
}
|
|
195
201
|
|
|
@@ -284,6 +290,16 @@ export function actionsFor(state) {
|
|
|
284
290
|
actions.push({ value: `import:${row.id}`, label: `迁移 ${row.name} 的本地记忆(${count})` })
|
|
285
291
|
}
|
|
286
292
|
}
|
|
293
|
+
const conflicted = state.platforms.filter((row) => row.conflicts?.some((c) => c.removable))
|
|
294
|
+
if (conflicted.length) {
|
|
295
|
+
actions.push({
|
|
296
|
+
value: 'clean',
|
|
297
|
+
label: '清理冲突的记忆工具',
|
|
298
|
+
hint: conflictToolsText(
|
|
299
|
+
conflicted.flatMap((row) => row.conflicts.filter((c) => c.removable)),
|
|
300
|
+
),
|
|
301
|
+
})
|
|
302
|
+
}
|
|
287
303
|
if (state.platforms.some(canDisable)) {
|
|
288
304
|
actions.push({ value: 'disable', label: '停用某个平台', hint: '恢复自带记忆、清掉配置' })
|
|
289
305
|
}
|
package/lib/platforms.mjs
CHANGED
|
@@ -5,8 +5,10 @@ import { readFile } from 'node:fs/promises'
|
|
|
5
5
|
import { homedir } from 'node:os'
|
|
6
6
|
import { join } from 'node:path'
|
|
7
7
|
|
|
8
|
+
import { agyHome, inspectAgy, preflightAgy, setupAgy, statusAgy } from './agy.mjs'
|
|
8
9
|
import { codexHome, inspectCodex, preflightCodex, setupCodex, statusCodex } from './codex.mjs'
|
|
9
10
|
import { dshHome, inspectDsh, setupDsh, statusDsh } from './dsh.mjs'
|
|
11
|
+
import { geminiHome, inspectGemini, preflightGemini, setupGemini, statusGemini } from './gemini.mjs'
|
|
10
12
|
import {
|
|
11
13
|
hermesHome,
|
|
12
14
|
inspectHermes,
|
|
@@ -16,6 +18,13 @@ import {
|
|
|
16
18
|
statusHermes,
|
|
17
19
|
} from './hermes.mjs'
|
|
18
20
|
import { inspectOpenclaw, setupOpenclaw, statusOpenclaw } from './openclaw.mjs'
|
|
21
|
+
import {
|
|
22
|
+
inspectOpenCode,
|
|
23
|
+
opencodeHome,
|
|
24
|
+
preflightOpenCode,
|
|
25
|
+
setupOpenCode,
|
|
26
|
+
statusOpenCode,
|
|
27
|
+
} from './opencode.mjs'
|
|
19
28
|
import { inspectPi, piHome, setupPi, statusPi } from './pi.mjs'
|
|
20
29
|
import { readSettings } from './files.mjs'
|
|
21
30
|
import { readProfile } from './profile.mjs'
|
|
@@ -208,7 +217,75 @@ const dsh = {
|
|
|
208
217
|
inspect: inspectDsh,
|
|
209
218
|
}
|
|
210
219
|
|
|
211
|
-
|
|
220
|
+
const opencode = {
|
|
221
|
+
name: 'OpenCode',
|
|
222
|
+
runtimeFamily: 'opencode',
|
|
223
|
+
command: () => 'opencode',
|
|
224
|
+
home: opencodeHome,
|
|
225
|
+
status: statusOpenCode,
|
|
226
|
+
install: {
|
|
227
|
+
commands: ['opencode'],
|
|
228
|
+
after:
|
|
229
|
+
'确认 opencode.json 的 plugin 已包含 @kioku-memory/plugin-opencode(kioku setup opencode 会写入),新开会话生效',
|
|
230
|
+
},
|
|
231
|
+
detect: (env) => Boolean(env.OPENCODE),
|
|
232
|
+
readConfig: (env) => readProfile('opencode', env),
|
|
233
|
+
preflight: preflightOpenCode,
|
|
234
|
+
setup: setupOpenCode,
|
|
235
|
+
inspect: inspectOpenCode,
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const gemini = {
|
|
239
|
+
name: 'Gemini CLI',
|
|
240
|
+
runtimeFamily: 'gemini',
|
|
241
|
+
command: () => 'gemini',
|
|
242
|
+
home: geminiHome,
|
|
243
|
+
status: statusGemini,
|
|
244
|
+
install: {
|
|
245
|
+
commands: [
|
|
246
|
+
'git clone https://github.com/lonelyman0108/kioku-plugins',
|
|
247
|
+
'gemini extensions link kioku-plugins/plugins/gemini',
|
|
248
|
+
],
|
|
249
|
+
after: '重启 Gemini CLI 生效(MCP 与停用 save_memory 已由 kioku setup gemini 配好)',
|
|
250
|
+
},
|
|
251
|
+
detect: (env) => Boolean(env.GEMINI_CLI),
|
|
252
|
+
readConfig: (env) => readProfile('gemini', env),
|
|
253
|
+
preflight: preflightGemini,
|
|
254
|
+
setup: setupGemini,
|
|
255
|
+
inspect: inspectGemini,
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const agy = {
|
|
259
|
+
name: 'Antigravity',
|
|
260
|
+
runtimeFamily: 'agy',
|
|
261
|
+
command: () => 'agy',
|
|
262
|
+
home: agyHome,
|
|
263
|
+
status: statusAgy,
|
|
264
|
+
install: {
|
|
265
|
+
commands: [
|
|
266
|
+
'git clone https://github.com/lonelyman0108/kioku-plugins',
|
|
267
|
+
'mkdir -p ~/.gemini/config/plugins && cp -r kioku-plugins/plugins/agy ~/.gemini/config/plugins/kioku',
|
|
268
|
+
],
|
|
269
|
+
after: '新开会话生效(MCP 服务已由 kioku setup agy 写进 mcp_config.json)',
|
|
270
|
+
},
|
|
271
|
+
detect: (env) => Boolean(env.ANTIGRAVITY_AGENT || env.AGY_SESSION_ID),
|
|
272
|
+
readConfig: (env) => readProfile('agy', env),
|
|
273
|
+
preflight: preflightAgy,
|
|
274
|
+
setup: setupAgy,
|
|
275
|
+
inspect: inspectAgy,
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export const PLATFORMS = {
|
|
279
|
+
'claude-code': claudeCode,
|
|
280
|
+
codex,
|
|
281
|
+
pi,
|
|
282
|
+
hermes,
|
|
283
|
+
openclaw,
|
|
284
|
+
dsh,
|
|
285
|
+
opencode,
|
|
286
|
+
gemini,
|
|
287
|
+
agy,
|
|
288
|
+
}
|
|
212
289
|
|
|
213
290
|
export function platformNames() {
|
|
214
291
|
return Object.keys(PLATFORMS).join('、')
|
package/lib/setup.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// 停用平台自带的长期记忆,只改平台的用户设置里的那几项,
|
|
3
3
|
// 改之前显示要改什么、留一份备份;--undo 只把这几项改回去,不动设置里的其他内容(文件会按 JSON 重新排版)
|
|
4
4
|
|
|
5
|
+
import { ensureNoConflicts } from './conflicts.mjs'
|
|
5
6
|
import { readSettings, writeSettings } from './files.mjs'
|
|
6
7
|
import { deviceLogin } from './login.mjs'
|
|
7
8
|
import { plain } from './text.mjs'
|
|
@@ -11,15 +12,21 @@ import { UsageError } from './usage.mjs'
|
|
|
11
12
|
|
|
12
13
|
export { readSettings, writeSettings }
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
const setupPlatformNames = () =>
|
|
16
|
+
Object.keys(PLATFORMS)
|
|
17
|
+
.filter((id) => PLATFORMS[id].setup)
|
|
18
|
+
.join('、')
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
export const SETUP_USAGE = `用法:kioku setup <平台> [--dry-run] [--undo] [--server-url <地址>] [--no-check] [--remove-conflicts]
|
|
21
|
+
|
|
22
|
+
把平台交给 Kioku 接管:停用平台自带的长期记忆;没有自己的密钥存储的平台(${setupPlatformNames()})再写下服务地址与访问密钥。
|
|
17
23
|
|
|
18
24
|
<平台> ${platformNames()}
|
|
19
25
|
--dry-run 只显示要改什么,不写文件
|
|
20
26
|
--undo 改回去:重新启用平台自带的长期记忆,删掉写下的地址与访问密钥
|
|
21
|
-
--server-url <地址> Kioku 的服务地址,例如 https://kioku.example.com
|
|
22
|
-
--no-check 不先连一次 Kioku
|
|
27
|
+
--server-url <地址> Kioku 的服务地址,例如 https://kioku.example.com(${setupPlatformNames()} 用;也可以用 KIOKU_SERVER_URL)
|
|
28
|
+
--no-check 不先连一次 Kioku 核对地址与访问密钥(${setupPlatformNames()} 用)
|
|
29
|
+
--remove-conflicts 先卸载平台上已有的冲突记忆工具(Lore 及常见记忆 MCP)再继续
|
|
23
30
|
|
|
24
31
|
访问密钥不写在命令行上:从 KIOKU_API_KEY 读,或者从标准输入读;在终端里运行时会提示输入(不回显),
|
|
25
32
|
直接回车就改用浏览器授权(同 kioku login)。
|
|
@@ -33,13 +40,20 @@ function browserLogin(out) {
|
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
export function parseSetupArgs(argv) {
|
|
36
|
-
const options = {
|
|
43
|
+
const options = {
|
|
44
|
+
dryRun: false,
|
|
45
|
+
undo: false,
|
|
46
|
+
check: true,
|
|
47
|
+
serverUrl: undefined,
|
|
48
|
+
removeConflicts: false,
|
|
49
|
+
}
|
|
37
50
|
const names = []
|
|
38
51
|
for (let i = 0; i < argv.length; i++) {
|
|
39
52
|
const arg = argv[i]
|
|
40
53
|
if (arg === '--dry-run') options.dryRun = true
|
|
41
54
|
else if (arg === '--undo') options.undo = true
|
|
42
55
|
else if (arg === '--no-check') options.check = false
|
|
56
|
+
else if (arg === '--remove-conflicts') options.removeConflicts = true
|
|
43
57
|
else if (arg === '--server-url') {
|
|
44
58
|
options.serverUrl = argv[++i]
|
|
45
59
|
if (!options.serverUrl) throw new UsageError('--server-url 后面要写地址')
|
|
@@ -69,14 +83,27 @@ export async function setup(
|
|
|
69
83
|
env = process.env,
|
|
70
84
|
out = process.stdout,
|
|
71
85
|
cwd = process.cwd(),
|
|
86
|
+
stdin = process.stdin,
|
|
72
87
|
readKey = readSecret,
|
|
88
|
+
skipConflicts = false,
|
|
73
89
|
// 在终端里运行、没给访问密钥时可以改用浏览器授权;不在终端里(管道、agent 的命令)时没有;传 null 是明说不要
|
|
74
90
|
login = process.stdin.isTTY ? browserLogin(out) : null,
|
|
75
91
|
} = {},
|
|
76
92
|
) {
|
|
77
93
|
const options = parseSetupArgs(argv)
|
|
78
|
-
const { platform: id, dryRun, undo } = options
|
|
94
|
+
const { platform: id, dryRun, undo, removeConflicts } = options
|
|
79
95
|
const platform = PLATFORMS[id]
|
|
96
|
+
if (!undo && !skipConflicts) {
|
|
97
|
+
const status = await ensureNoConflicts(id, platform.name, {
|
|
98
|
+
env,
|
|
99
|
+
cwd,
|
|
100
|
+
out,
|
|
101
|
+
stdin,
|
|
102
|
+
remove: removeConflicts,
|
|
103
|
+
dryRun,
|
|
104
|
+
})
|
|
105
|
+
if (status === 'cancelled') return 0
|
|
106
|
+
}
|
|
80
107
|
// 有自己的一套步骤的平台
|
|
81
108
|
if (platform.setup) return platform.setup(options, { env, out, cwd, readKey, plain, login })
|
|
82
109
|
const { memory } = platform
|
package/lib/wizard.mjs
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// 各动作的实际步骤都是别的子命令已有的那一套(setup、login、import、doctor)
|
|
5
5
|
|
|
6
6
|
import { loadConfig } from './config.mjs'
|
|
7
|
+
import { conflictToolsText, formatConflicts, removeConflicts } from './conflicts.mjs'
|
|
7
8
|
import { connectPlatforms, pluginSteps, resultsText } from './connect.mjs'
|
|
8
9
|
import { doctor } from './doctor.mjs'
|
|
9
10
|
import { keyFormatError, KiokuFailure } from './http.mjs'
|
|
@@ -79,6 +80,7 @@ const DEPS = {
|
|
|
79
80
|
doctor,
|
|
80
81
|
planImport,
|
|
81
82
|
writeImport,
|
|
83
|
+
removeConflicts,
|
|
82
84
|
loadConfig,
|
|
83
85
|
open: openBrowser,
|
|
84
86
|
local: {
|
|
@@ -135,8 +137,10 @@ async function connect(ctx, rows, { reauth = false } = {}) {
|
|
|
135
137
|
const plan = picked.map((id) => {
|
|
136
138
|
const row = rows.find((item) => item.id === id)
|
|
137
139
|
const memory = row.memory === 'none' ? '' : ',停用自带的长期记忆'
|
|
140
|
+
const conflicts = row.conflicts?.filter((c) => c.removable) ?? []
|
|
141
|
+
const clean = conflicts.length ? `,先清理 ${conflictToolsText(conflicts)}` : ''
|
|
138
142
|
const moved = row.otherServer ? `;原来接到 ${shownUrl(row.url)}` : ''
|
|
139
|
-
return `${PLATFORMS[id].name}:签发访问密钥,写下配置${memory}${moved}`
|
|
143
|
+
return `${PLATFORMS[id].name}:签发访问密钥,写下配置${memory}${clean}${moved}`
|
|
140
144
|
})
|
|
141
145
|
ui.note(
|
|
142
146
|
[`服务器 ${shownUrl(ctx.url)}`, ...plan, '', '浏览器里确认一次,访问密钥不显示'].join('\n'),
|
|
@@ -144,10 +148,30 @@ async function connect(ctx, rows, { reauth = false } = {}) {
|
|
|
144
148
|
)
|
|
145
149
|
const ok = await ui.confirm({ message: '开始?' })
|
|
146
150
|
if (cancelled(ui, ok) || !ok) return
|
|
147
|
-
|
|
148
|
-
const
|
|
151
|
+
|
|
152
|
+
const readyIds = []
|
|
153
|
+
const preFailed = []
|
|
154
|
+
for (const id of picked) {
|
|
155
|
+
const row = rows.find((item) => item.id === id)
|
|
156
|
+
const conflicts = row.conflicts?.filter((c) => c.removable) ?? []
|
|
157
|
+
if (!conflicts.length) {
|
|
158
|
+
readyIds.push(id)
|
|
159
|
+
continue
|
|
160
|
+
}
|
|
161
|
+
const cleanRes = await deps.removeConflicts(conflicts, { env, cwd, out })
|
|
162
|
+
if (cleanRes.some((r) => !r.ok)) {
|
|
163
|
+
preFailed.push({ id, status: 'failed', reason: '清理冲突没有全部成功' })
|
|
164
|
+
} else {
|
|
165
|
+
readyIds.push(id)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const results = readyIds.length
|
|
169
|
+
? await deps.connectPlatforms({ url: ctx.url, ids: readyIds }, { env, out, cwd })
|
|
170
|
+
: []
|
|
171
|
+
const allResults = [...preFailed, ...results]
|
|
172
|
+
const done = allResults.filter((item) => item.status === 'connected').map((item) => item.id)
|
|
149
173
|
ui.note(
|
|
150
|
-
done.length ? resultsText(
|
|
174
|
+
done.length ? resultsText(allResults) : `一个平台都没有接上\n${resultsText(allResults)}`,
|
|
151
175
|
'结果',
|
|
152
176
|
)
|
|
153
177
|
const steps = await deps.pluginSteps(done, { env, cwd })
|
|
@@ -157,29 +181,54 @@ async function connect(ctx, rows, { reauth = false } = {}) {
|
|
|
157
181
|
// 接入 Claude Code:它的访问密钥只认 /plugin 里填的,浏览器授权不给它发。列出安装命令与要填的服务地址,
|
|
158
182
|
// 顺带停用自动记忆(项目设置又启用了的,说明要在那里改)
|
|
159
183
|
async function connectClaude(ctx, row) {
|
|
160
|
-
const { ui, deps, env, cwd } = ctx
|
|
184
|
+
const { ui, deps, env, cwd, out } = ctx
|
|
161
185
|
const steps = await deps.pluginSteps(['claude-code'], { env, cwd, url: ctx.url })
|
|
162
186
|
const memory = row.memory === 'on' && !row.reenabledIn
|
|
187
|
+
const conflicts = row.conflicts?.filter((c) => c.removable) ?? []
|
|
163
188
|
if (row.reenabledIn) {
|
|
164
189
|
ui.log.warn(
|
|
165
190
|
`Claude Code 的自动记忆被 ./${row.reenabledIn} 重新启用:要在那里把 autoMemoryEnabled 去掉`,
|
|
166
191
|
)
|
|
167
192
|
}
|
|
168
|
-
if (memory) {
|
|
193
|
+
if (memory || conflicts.length) {
|
|
169
194
|
const preview = bufferOut()
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
195
|
+
if (memory) {
|
|
196
|
+
await deps.setup(['claude-code', '--dry-run'], {
|
|
197
|
+
env,
|
|
198
|
+
out: preview,
|
|
199
|
+
cwd,
|
|
200
|
+
login: null,
|
|
201
|
+
skipConflicts: true,
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
const lines = []
|
|
205
|
+
if (conflicts.length) {
|
|
206
|
+
lines.push('清理冲突的记忆工具', ...formatConflicts(conflicts, PLATFORMS), '')
|
|
207
|
+
}
|
|
208
|
+
if (memory) {
|
|
209
|
+
lines.push('停用自动记忆', preview.text().replace(/\n?没有写入(--dry-run)$/, ''), '')
|
|
210
|
+
}
|
|
211
|
+
lines.push(
|
|
212
|
+
'插件与访问密钥在 Claude Code 的 /plugin 里装、填(浏览器授权不给它发访问密钥),做完列出步骤',
|
|
179
213
|
)
|
|
214
|
+
ui.note(lines.join('\n'), '计划')
|
|
180
215
|
const ok = await ui.confirm({ message: '开始?' })
|
|
181
216
|
if (cancelled(ui, ok) || !ok) return
|
|
182
|
-
|
|
217
|
+
if (conflicts.length) {
|
|
218
|
+
const cleanRes = await deps.removeConflicts(conflicts, { env, cwd, out })
|
|
219
|
+
if (cleanRes.some((r) => !r.ok)) {
|
|
220
|
+
throw new KiokuFailure('清理 Claude Code 上的冲突没有全部成功,已停下')
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (memory) {
|
|
224
|
+
await deps.setup(['claude-code'], {
|
|
225
|
+
env,
|
|
226
|
+
out: ctx.out,
|
|
227
|
+
cwd,
|
|
228
|
+
login: null,
|
|
229
|
+
skipConflicts: true,
|
|
230
|
+
})
|
|
231
|
+
}
|
|
183
232
|
}
|
|
184
233
|
if (steps) ui.note(steps, '装插件')
|
|
185
234
|
}
|
|
@@ -188,11 +237,17 @@ async function connectClaude(ctx, row) {
|
|
|
188
237
|
async function previewThenRun(ctx, args, question) {
|
|
189
238
|
const { ui, deps, env, cwd } = ctx
|
|
190
239
|
const preview = bufferOut()
|
|
191
|
-
await deps.setup([...args, '--dry-run'], {
|
|
240
|
+
await deps.setup([...args, '--dry-run'], {
|
|
241
|
+
env,
|
|
242
|
+
out: preview,
|
|
243
|
+
cwd,
|
|
244
|
+
login: null,
|
|
245
|
+
skipConflicts: true,
|
|
246
|
+
})
|
|
192
247
|
ui.note(preview.text().replace(/\n?没有写入(--dry-run)$/, ''), '计划')
|
|
193
248
|
const ok = await ui.confirm({ message: question })
|
|
194
249
|
if (cancelled(ui, ok) || !ok) return
|
|
195
|
-
await deps.setup(args, { env, out: ctx.out, cwd, login: null })
|
|
250
|
+
await deps.setup(args, { env, out: ctx.out, cwd, login: null, skipConflicts: true })
|
|
196
251
|
}
|
|
197
252
|
|
|
198
253
|
// 迁移一个平台的本地记忆:照 kioku import 列计划(这时才和 Kioku 逐条比对)、确认后写入。
|
|
@@ -231,6 +286,37 @@ async function migrate(ctx, id) {
|
|
|
231
286
|
await deps.writeImport(config, plan, { out })
|
|
232
287
|
}
|
|
233
288
|
|
|
289
|
+
async function cleanConflictsAction(ctx, state) {
|
|
290
|
+
const { ui, deps, env, cwd, out } = ctx
|
|
291
|
+
const rows = state.platforms.filter((row) => row.conflicts?.some((c) => c.removable))
|
|
292
|
+
if (!rows.length) return
|
|
293
|
+
let ids = rows.map((row) => row.id)
|
|
294
|
+
if (rows.length > 1) {
|
|
295
|
+
const picked = await ui.multiselect({
|
|
296
|
+
message: '清理哪些平台上的冲突记忆工具',
|
|
297
|
+
options: rows.map((row) => ({
|
|
298
|
+
value: row.id,
|
|
299
|
+
label: row.name,
|
|
300
|
+
hint: conflictToolsText(row.conflicts.filter((c) => c.removable)),
|
|
301
|
+
})),
|
|
302
|
+
initialValues: ids,
|
|
303
|
+
})
|
|
304
|
+
if (cancelled(ui, picked) || !picked.length) return
|
|
305
|
+
ids = picked
|
|
306
|
+
}
|
|
307
|
+
const items = rows
|
|
308
|
+
.filter((row) => ids.includes(row.id))
|
|
309
|
+
.flatMap((row) => row.conflicts.filter((c) => c.removable))
|
|
310
|
+
ui.note(formatConflicts(items, PLATFORMS).join('\n'), '计划')
|
|
311
|
+
const ok = await ui.confirm({ message: `清理这 ${items.length} 项冲突?` })
|
|
312
|
+
if (cancelled(ui, ok) || !ok) return
|
|
313
|
+
const results = await deps.removeConflicts(items, { env, cwd, out })
|
|
314
|
+
if (results.some((r) => !r.ok)) {
|
|
315
|
+
throw new KiokuFailure('部分冲突没有清理成功,请查看上面的输出')
|
|
316
|
+
}
|
|
317
|
+
ui.log.success('冲突已清理,重启对应平台后生效')
|
|
318
|
+
}
|
|
319
|
+
|
|
234
320
|
async function disable(ctx, state) {
|
|
235
321
|
const { ui } = ctx
|
|
236
322
|
const rows = state.platforms.filter(canDisable)
|
|
@@ -410,6 +496,7 @@ async function perform(ctx, choice, state) {
|
|
|
410
496
|
return previewThenRun(ctx, ['claude-code'], '停用 Claude Code 的自动记忆?')
|
|
411
497
|
}
|
|
412
498
|
if (choice.startsWith('import:')) return migrate(ctx, choice.slice('import:'.length))
|
|
499
|
+
if (choice === 'clean') return cleanConflictsAction(ctx, state)
|
|
413
500
|
if (choice === 'disable') return disable(ctx, state)
|
|
414
501
|
if (choice === 'doctor') return check(ctx)
|
|
415
502
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kioku-memory/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Kioku 的命令行:接入各平台的向导、把凭据交给命令(kioku run)、停用各平台自带的长期记忆(kioku setup)、检查配置(kioku doctor)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/lonelyman0108/kioku-plugins/tree/main/packages/cli",
|