@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/lib/panel.mjs ADDED
@@ -0,0 +1,311 @@
1
+ // 向导的面板:扫描服务器与本机各平台的现状,排成几行文字,再按缺什么列出可做的动作。
2
+ // 只读:不写文件、不签发访问密钥。查不了的项写「无法判断」,不猜
3
+
4
+ import { stat } from 'node:fs/promises'
5
+
6
+ import { KeyRejected, whoami } from './api.mjs'
7
+ import { hasCommand } from './command.mjs'
8
+ import { conflictToolsText, scanConflicts } from './conflicts.mjs'
9
+ import { failureText, fetchFailure, isRedirect, KiokuFailure } from './http.mjs'
10
+ import { countLocal } from './import.mjs'
11
+ import { PLATFORMS } from './platforms.mjs'
12
+ import { serverUrlProblem } from './profile.mjs'
13
+ import { plain, shownUrl } from './text.mjs'
14
+
15
+ const TIMEOUT = 5000
16
+
17
+ async function getJson(url, path) {
18
+ let res
19
+ let data
20
+ try {
21
+ res = await fetch(`${url}${path}`, { redirect: 'manual', signal: AbortSignal.timeout(TIMEOUT) })
22
+ data = await res.json().catch(() => null)
23
+ } catch (err) {
24
+ throw new KiokuFailure(fetchFailure(err, TIMEOUT))
25
+ }
26
+ if (isRedirect(res.status)) throw new KiokuFailure(`返回了跳转(${res.status})`)
27
+ return { status: res.status, data }
28
+ }
29
+
30
+ // 服务器的现状:{ reachable, version, problem, needsSetup }。不要访问密钥
31
+ export async function serverHealth(url) {
32
+ let answer
33
+ try {
34
+ answer = await getJson(url, '/v1/health')
35
+ } catch (err) {
36
+ return { reachable: false, problem: failureText(err) }
37
+ }
38
+ const version = typeof answer.data?.version === 'string' ? plain(answer.data.version) : null
39
+ if (answer.status === 503) {
40
+ return { reachable: true, version, problem: '数据库暂时无法连接' }
41
+ }
42
+ if (answer.status !== 200 || answer.data?.status !== 'ok') {
43
+ return { reachable: false, problem: `不像 Kioku(HTTP ${answer.status})` }
44
+ }
45
+ let needsSetup = false
46
+ try {
47
+ const setup = await getJson(url, '/v1/setup/status')
48
+ needsSetup = setup.status === 200 && setup.data?.needsSetup === true
49
+ } catch {
50
+ // 查不到按已初始化算
51
+ }
52
+ return { reachable: true, version, problem: null, needsSetup }
53
+ }
54
+
55
+ async function isDir(path) {
56
+ return Boolean((await stat(path).catch(() => null))?.isDirectory())
57
+ }
58
+
59
+ // 各平台写下的服务地址(按平台的顺序,同一个只留一次)
60
+ export async function knownServers(env) {
61
+ const urls = []
62
+ for (const platform of Object.values(PLATFORMS)) {
63
+ const config = await Promise.resolve(platform.readConfig?.(env)).catch(() => null)
64
+ if (config?.url && !urls.includes(config.url)) urls.push(config.url)
65
+ }
66
+ return urls
67
+ }
68
+
69
+ // 没有指明时用哪个服务地址:KIOKU_SERVER_URL,否则各平台写下的里面最先找到的
70
+ export async function defaultServerUrl(env) {
71
+ const fromEnv = (env.KIOKU_SERVER_URL ?? '').trim().replace(/\/+$/, '')
72
+ if (fromEnv && !serverUrlProblem(fromEnv)) return fromEnv
73
+ return (await knownServers(env))[0] ?? null
74
+ }
75
+
76
+ // 一个平台的现状。connection:
77
+ // - ok:访问密钥可用;none:没配过;invalid:服务端说访问密钥无效或已吊销
78
+ // - unknown:连不上、响应不对,查不了;broken:配置文件读不懂
79
+ // - manual:Claude Code,访问密钥在它的 /plugin 里填,这里读不到
80
+ export async function scanPlatform(id, { env, cwd, url }) {
81
+ const platform = PLATFORMS[id]
82
+ const present = hasCommand(platform.command(env), env) || (await isDir(platform.home(env)))
83
+ const row = { id, name: platform.name, present, connection: 'none' }
84
+
85
+ let config = null
86
+ if (!platform.readConfig) row.connection = 'manual'
87
+ else {
88
+ try {
89
+ config = await platform.readConfig(env)
90
+ } catch (err) {
91
+ row.connection = 'broken'
92
+ row.reason = failureText(err)
93
+ }
94
+ }
95
+ if (config) {
96
+ row.url = config.url
97
+ row.otherServer = Boolean(url && config.url !== url)
98
+ try {
99
+ row.who = await whoami(config)
100
+ row.connection = 'ok'
101
+ } catch (err) {
102
+ row.connection = err instanceof KeyRejected ? 'invalid' : 'unknown'
103
+ row.reason = failureText(err)
104
+ }
105
+ }
106
+
107
+ const status = await platform.status({ env, cwd }).catch(() => ({ plugin: null, memory: null }))
108
+ row.plugin = status.plugin
109
+ row.memory = status.memory
110
+ if (status.reenabledIn) row.reenabledIn = status.reenabledIn
111
+
112
+ // 只数本地有几条;和 Kioku 比(没迁的有几条)要一条一条地问,选了迁移再比
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
116
+ return row
117
+ }
118
+
119
+ // 面板的全部现状。url 为空时只扫本机
120
+ export async function scan({ env, cwd, url }) {
121
+ const server = url ? { url, ...(await serverHealth(url)) } : null
122
+ const platforms = await Promise.all(
123
+ Object.keys(PLATFORMS).map((id) => scanPlatform(id, { env, cwd, url })),
124
+ )
125
+ return { server, platforms }
126
+ }
127
+
128
+ const PLUGIN_NAMES = new Map([
129
+ [true, '已安装'],
130
+ [false, '未安装'],
131
+ [null, '无法判断'],
132
+ ])
133
+ const MEMORY_NAMES = { off: '已停用', on: '未停用', none: '无' }
134
+
135
+ // 访问密钥属于哪个空间:服务端给了空间名就用名字,否则用 id 的前 8 位
136
+ function spaceText(who) {
137
+ if (typeof who.spaceName === 'string' && who.spaceName) return plain(who.spaceName)
138
+ return typeof who.spaceId === 'string' ? plain(who.spaceId).slice(0, 8) : null
139
+ }
140
+
141
+ // 能不能停用:配过(不管现在能不能用),或者 Claude Code 的自动记忆停着
142
+ export function canDisable(row) {
143
+ return (
144
+ ['ok', 'invalid', 'unknown', 'broken'].includes(row.connection) ||
145
+ (row.connection === 'manual' && row.memory === 'off')
146
+ )
147
+ }
148
+
149
+ // 平台接到哪一步,一个短词
150
+ export function connectionText(row) {
151
+ if (row.connection === 'manual') return row.plugin ? '插件已启用' : '未接入'
152
+ if (row.connection === 'ok' && row.otherServer) return '接到另一台服务器'
153
+ return (
154
+ {
155
+ ok: '已接入',
156
+ none: row.present ? '未接入' : '未安装',
157
+ invalid: '已失效',
158
+ unknown: '无法判断',
159
+ broken: '配置有误',
160
+ }[row.connection] ?? '无法判断'
161
+ )
162
+ }
163
+
164
+ function platformLines(row) {
165
+ const head = connectionText(row)
166
+ const facts = []
167
+ if (row.connection === 'ok') {
168
+ const app = row.who.app
169
+ facts.push(`应用 ${plain(app.name)}(${plain(app.slug)})`)
170
+ const space = spaceText(row.who)
171
+ if (space) facts.push(`空间 ${space}`)
172
+ if (typeof row.who.accountName === 'string' && row.who.accountName) {
173
+ facts.push(`账号 ${plain(row.who.accountName)}`)
174
+ }
175
+ if (app.runtimeFamily !== PLATFORMS[row.id].runtimeFamily) facts.push('应用的运行时不对')
176
+ }
177
+ if (row.otherServer) facts.push(shownUrl(row.url))
178
+ if (row.reason) facts.push(row.reason)
179
+ const first = [`${row.name}:${head}`, ...facts].join(' · ')
180
+ // 没装、也没配过且没有冲突的平台只写一行
181
+ if (!row.present && row.connection === 'none' && !row.conflicts?.length) return [first]
182
+ const details = []
183
+ if (row.connection === 'manual') details.push('访问密钥 无法判断(在 /plugin 里填)')
184
+ details.push(`插件 ${PLUGIN_NAMES.get(row.plugin) ?? '无法判断'}`)
185
+ const reenabled = row.reenabledIn ? `(被 ./${row.reenabledIn} 重新启用)` : ''
186
+ details.push(`自带记忆 ${MEMORY_NAMES[row.memory] ?? '无法判断'}${reenabled}`)
187
+ if (row.local) {
188
+ // 未迁移的条数只在选过迁移、和 Kioku 比过之后才有
189
+ const pending = !row.pending
190
+ ? ''
191
+ : row.pending.pending === null
192
+ ? '(未迁移 无法判断)'
193
+ : `(未迁移 ${row.pending.pending} 条)`
194
+ details.push(`本地记忆 ${row.local} 条${pending}`)
195
+ }
196
+ if (row.conflicts?.length) {
197
+ details.push(`冲突 ${conflictToolsText(row.conflicts)}`)
198
+ }
199
+ return [first, ` ${details.join(' · ')}`]
200
+ }
201
+
202
+ // 面板的文字
203
+ export function renderPanel(state) {
204
+ const lines = []
205
+ const { server } = state
206
+ if (!server) lines.push('服务器:未设置')
207
+ else {
208
+ const facts = []
209
+ if (!server.reachable) facts.push(`无法连接(${server.problem})`)
210
+ else {
211
+ facts.push(server.problem ?? '可连接')
212
+ if (server.version) facts.push(`版本 ${server.version}`)
213
+ if (server.needsSetup) facts.push('未初始化')
214
+ }
215
+ lines.push(`服务器:${shownUrl(server.url)}(${facts.join(' · ')})`)
216
+ const spaces = [
217
+ ...new Set(
218
+ state.platforms
219
+ .filter((row) => row.connection === 'ok')
220
+ .map((row) => spaceText(row.who))
221
+ .filter(Boolean),
222
+ ),
223
+ ]
224
+ if (spaces.length > 1) lines.push(`访问密钥分属 ${spaces.length} 个空间:${spaces.join('、')}`)
225
+ }
226
+ lines.push('')
227
+ for (const row of state.platforms) lines.push(...platformLines(row))
228
+ return lines.join('\n')
229
+ }
230
+
231
+ // 要接入的候选:有自己的配置、还没接到这台服务器的(失效的另算)
232
+ export function connectCandidates(state) {
233
+ return state.platforms.filter(
234
+ (row) =>
235
+ PLATFORMS[row.id].setup &&
236
+ row.connection !== 'invalid' &&
237
+ !(row.connection === 'ok' && !row.otherServer),
238
+ )
239
+ }
240
+
241
+ const names = (rows) => rows.map((row) => row.name).join('、')
242
+
243
+ // 面板下面列出的动作:{ value, label, hint? },按缺什么排在前面
244
+ export function actionsFor(state) {
245
+ const actions = []
246
+ const { server } = state
247
+ const ready = Boolean(server?.reachable && !server.problem && !server.needsSetup)
248
+ if (!server || !server.reachable) {
249
+ actions.push({ value: 'local', label: '本机起一个 Kioku', hint: '用 Docker' })
250
+ }
251
+ if (!server) actions.push({ value: 'server', label: '填写服务器地址' })
252
+ if (server?.needsSetup) {
253
+ actions.push({ value: 'open', label: '打开管理界面初始化', hint: '建第一个管理员' })
254
+ }
255
+ if (ready) {
256
+ const candidates = connectCandidates(state)
257
+ const present = candidates.filter((row) => row.present)
258
+ if (present.length) {
259
+ actions.push({
260
+ value: 'connect',
261
+ label: `接入 ${names(present)}(${present.length} 个未接入)`,
262
+ })
263
+ } else if (candidates.length) {
264
+ actions.push({ value: 'connect', label: '接入其他平台', hint: '本机没发现的' })
265
+ }
266
+ const invalid = state.platforms.filter((row) => row.connection === 'invalid')
267
+ if (invalid.length) {
268
+ actions.push({ value: 'reauth', label: `重新授权 ${names(invalid)}(访问密钥已失效)` })
269
+ }
270
+ }
271
+ // Claude Code 的访问密钥在它的 /plugin 里填,浏览器授权不给它发:插件没启用时列出安装与要填的地址,
272
+ // 顺带停用自动记忆;插件启用了、自动记忆还开着时只停用自动记忆。项目设置又启用了的,停用也没用,不提供
273
+ const claude = state.platforms.find((row) => row.id === 'claude-code')
274
+ if (claude?.present && server && claude.plugin === false) {
275
+ actions.push({ value: 'claude-connect', label: '接入 Claude Code', hint: '在 /plugin 里填' })
276
+ } else if (claude?.present && claude.memory === 'on' && !claude.reenabledIn) {
277
+ actions.push({ value: 'claude-memory', label: '停用 Claude Code 的自动记忆' })
278
+ }
279
+ if (ready) {
280
+ for (const row of state.platforms) {
281
+ if (!row.local) continue
282
+ // 迁移要这个平台的访问密钥(Claude Code 的另外问)
283
+ if (row.connection !== 'manual' && !(row.connection === 'ok' && !row.otherServer)) continue
284
+ // 比过、确实都迁了的不再提供
285
+ if (row.pending?.pending === 0) continue
286
+ const count =
287
+ typeof row.pending?.pending === 'number'
288
+ ? `未迁移 ${row.pending.pending} 条`
289
+ : `${row.local} 条`
290
+ actions.push({ value: `import:${row.id}`, label: `迁移 ${row.name} 的本地记忆(${count})` })
291
+ }
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
+ }
303
+ if (state.platforms.some(canDisable)) {
304
+ actions.push({ value: 'disable', label: '停用某个平台', hint: '恢复自带记忆、清掉配置' })
305
+ }
306
+ actions.push({ value: 'doctor', label: '检查(doctor)' })
307
+ if (server) actions.push({ value: 'server', label: '更换服务器地址' })
308
+ actions.push({ value: 'refresh', label: '刷新' })
309
+ actions.push({ value: 'exit', label: '退出' })
310
+ return actions
311
+ }
package/lib/pi.mjs CHANGED
@@ -45,7 +45,9 @@ export async function setupPi(options, io) {
45
45
  if (!same) await writeProfile('pi', { url, key }, env)
46
46
  const { settings } = await readSettings(join(piHome(env), 'settings.json')).catch(() => ({}))
47
47
  out.write('pi 已配好,新开会话(或 /reload)生效。\n')
48
- if (!installed(settings)) out.write(`接下来装上扩展:pi install ${SOURCE}\n`)
48
+ if (!installed(settings) && io.hints !== false) {
49
+ out.write(`接下来装上扩展:pi install ${SOURCE}\n`)
50
+ }
49
51
  return 0
50
52
  }
51
53
 
@@ -79,3 +81,10 @@ export async function inspectPi({ env, cwd }, { ok, warn }) {
79
81
  } else ok('MCP 服务由扩展在会话开始时注册')
80
82
  ok('pi 没有自带的长期记忆要停用')
81
83
  }
84
+
85
+ // 给向导的面板:扩展装没装(用户级或当前项目里),pi 没有自带的长期记忆
86
+ export async function statusPi({ env, cwd }) {
87
+ const user = await readSettings(join(piHome(env), 'settings.json')).catch(() => ({}))
88
+ const local = await readSettings(join(cwd, '.pi', 'settings.json')).catch(() => ({}))
89
+ return { plugin: installed(user.settings) || installed(local.settings), memory: 'none' }
90
+ }
package/lib/platforms.mjs CHANGED
@@ -5,11 +5,28 @@ import { readFile } from 'node:fs/promises'
5
5
  import { homedir } from 'node:os'
6
6
  import { join } from 'node:path'
7
7
 
8
- import { inspectCodex, preflightCodex, setupCodex } from './codex.mjs'
9
- import { inspectDsh, setupDsh } from './dsh.mjs'
10
- import { inspectHermes, preflightHermes, readHermesConfig, setupHermes } from './hermes.mjs'
11
- import { inspectOpenclaw, setupOpenclaw } from './openclaw.mjs'
12
- import { inspectPi, setupPi } from './pi.mjs'
8
+ import { agyHome, inspectAgy, preflightAgy, setupAgy, statusAgy } from './agy.mjs'
9
+ import { codexHome, inspectCodex, preflightCodex, setupCodex, statusCodex } from './codex.mjs'
10
+ import { dshHome, inspectDsh, setupDsh, statusDsh } from './dsh.mjs'
11
+ import { geminiHome, inspectGemini, preflightGemini, setupGemini, statusGemini } from './gemini.mjs'
12
+ import {
13
+ hermesHome,
14
+ inspectHermes,
15
+ preflightHermes,
16
+ readHermesConfig,
17
+ setupHermes,
18
+ statusHermes,
19
+ } from './hermes.mjs'
20
+ import { inspectOpenclaw, setupOpenclaw, statusOpenclaw } from './openclaw.mjs'
21
+ import {
22
+ inspectOpenCode,
23
+ opencodeHome,
24
+ preflightOpenCode,
25
+ setupOpenCode,
26
+ statusOpenCode,
27
+ } from './opencode.mjs'
28
+ import { inspectPi, piHome, setupPi, statusPi } from './pi.mjs'
29
+ import { readSettings } from './files.mjs'
13
30
  import { readProfile } from './profile.mjs'
14
31
 
15
32
  // 真值的环境变量写法
@@ -27,14 +44,45 @@ async function settingOf(file, key) {
27
44
  }
28
45
  }
29
46
 
47
+ function claudeHome(env) {
48
+ return env.CLAUDE_CONFIG_DIR || join(homedir(), '.claude')
49
+ }
50
+
51
+ // 向导的面板里各平台共有的几项:
52
+ // - command、home:本机装没装这个平台,看命令在不在 PATH 里、配置目录在不在
53
+ // - status:插件装没装(plugin:true、false,null 是查不了)与自带的长期记忆停没停(memory:'off'、'on',
54
+ // 'none' 是没有自带的,null 是查不了);reenabledIn 是又启用了它、停用不了的那份设置
55
+ // - install:插件要用户自己装:在哪里运行(where,默认终端)、可以直接复制的命令与之后要做的事;向导不替用户装
56
+ // - source:kioku import 认得的本地记忆的来源
30
57
  const claudeCode = {
31
58
  name: 'Claude Code',
59
+ command: () => 'claude',
60
+ home: claudeHome,
61
+ // 项目的设置又启用了自动记忆时,停用用户设置也没用:reenabledIn 写明是哪份文件,向导据此不再提供停用
62
+ status: async ({ env, cwd }) => {
63
+ let settings
64
+ try {
65
+ ;({ settings } = await readSettings(claudeCode.settingsFile(env)))
66
+ } catch {
67
+ return { plugin: null, memory: null }
68
+ }
69
+ const plugin = claudeCode.pluginActive(settings, env)
70
+ const reenabledIn = await claudeCode.memory.enabledIn(env, cwd)
71
+ if (reenabledIn) return { plugin, memory: 'on', reenabledIn }
72
+ return { plugin, memory: claudeCode.memory.disabledBy(settings, env) ? 'off' : 'on' }
73
+ },
74
+ install: {
75
+ where: '在 Claude Code 里',
76
+ commands: ['/plugin install kioku --marketplace lonelyman0108/kioku-plugins'],
77
+ after: '启用时填 Kioku 的地址与访问密钥(管理界面的应用页签发),新开会话生效',
78
+ },
79
+ source: 'claude-code',
32
80
  // 应用的运行时要是这个,服务端才按这个平台给注入
33
81
  runtimeFamily: 'claudecode',
34
82
  // 这个平台的会话里有的环境变量,不写平台时靠它认出来
35
83
  detect: (env) => env.CLAUDECODE === '1',
36
84
  // 用户级的设置文件
37
- settingsFile: (env) => join(env.CLAUDE_CONFIG_DIR || join(homedir(), '.claude'), 'settings.json'),
85
+ settingsFile: (env) => join(claudeHome(env), 'settings.json'),
38
86
  memory: {
39
87
  name: '自动记忆(auto memory)',
40
88
  // 停用:用户设置里把 autoMemoryEnabled 设为 false
@@ -53,16 +101,20 @@ const claudeCode = {
53
101
  }
54
102
  return settings?.autoMemoryEnabled === false ? '用户设置' : null
55
103
  },
56
- // 又在哪里启用了:当前项目的设置优先于用户设置。别处(托管的设置)查不到
57
- enabledBy: async (env, cwd) => {
104
+ // 又在哪份项目设置里启用了(相对项目目录的路径):当前项目的设置优先于用户设置。别处(托管的设置)查不到
105
+ enabledIn: async (env, cwd) => {
58
106
  // 环境变量停用着时,设置里写什么都不生效
59
107
  if (TRUTHY.test((env.CLAUDE_CODE_DISABLE_AUTO_MEMORY ?? '').trim())) return null
60
108
  for (const name of PROJECT_SETTINGS) {
61
- if ((await settingOf(join(cwd, name), 'autoMemoryEnabled')) === true)
62
- return `项目的 ${name} `
109
+ if ((await settingOf(join(cwd, name), 'autoMemoryEnabled')) === true) return name
63
110
  }
64
111
  return null
65
112
  },
113
+ // 同上,给提示用的说法
114
+ enabledBy: async (env, cwd) => {
115
+ const name = await claudeCode.memory.enabledIn(env, cwd)
116
+ return name ? `项目的 ${name} ` : null
117
+ },
66
118
  },
67
119
  // 插件是否在用:这个会话里钩子已经配好了访问密钥文件,或者用户设置的 enabledPlugins 里有以「kioku@」开头、
68
120
  // 值为 true 的一项。项目级的设置里启用的认不出来,所以认不出时只提醒、不算有问题
@@ -77,6 +129,16 @@ const claudeCode = {
77
129
  const codex = {
78
130
  name: 'Codex',
79
131
  runtimeFamily: 'codex',
132
+ command: () => 'codex',
133
+ home: codexHome,
134
+ status: statusCodex,
135
+ install: {
136
+ commands: [
137
+ 'codex plugin marketplace add lonelyman0108/kioku-plugins',
138
+ 'codex plugin add kioku@kioku',
139
+ ],
140
+ after: '打开 codex,在 /hooks 里信任 kioku 的三个钩子,新开会话生效',
141
+ },
80
142
  // Codex 的会话里没有可靠的标记,要写明平台
81
143
  detect: () => false,
82
144
  // 地址与访问密钥放在本机的文件里(profile.mjs);readConfig 读出来给 doctor、login、import 用
@@ -90,6 +152,13 @@ const codex = {
90
152
  const pi = {
91
153
  name: 'pi',
92
154
  runtimeFamily: 'pi',
155
+ command: () => 'pi',
156
+ home: piHome,
157
+ status: statusPi,
158
+ install: {
159
+ commands: ['pi install git:github.com/lonelyman0108/kioku-plugins'],
160
+ after: '新开 pi 会话(或 /reload)生效',
161
+ },
93
162
  detect: () => false,
94
163
  readConfig: (env) => readProfile('pi', env),
95
164
  setup: setupPi,
@@ -99,6 +168,14 @@ const pi = {
99
168
  const hermes = {
100
169
  name: 'Hermes',
101
170
  runtimeFamily: 'hermes',
171
+ command: (env) => env.KIOKU_HERMES_BIN || 'hermes',
172
+ home: hermesHome,
173
+ status: statusHermes,
174
+ install: {
175
+ commands: ['hermes plugins install lonelyman0108/kioku-plugins/plugins/hermes --enable'],
176
+ after: '新开 Hermes 会话生效',
177
+ },
178
+ source: 'hermes',
102
179
  detect: () => false,
103
180
  // 地址与访问密钥在 Hermes 自己的 .env 里
104
181
  readConfig: readHermesConfig,
@@ -110,6 +187,14 @@ const hermes = {
110
187
  const openclaw = {
111
188
  name: 'OpenClaw',
112
189
  runtimeFamily: 'openclaw',
190
+ command: (env) => env.KIOKU_OPENCLAW_BIN || 'openclaw',
191
+ home: (env) => join(env.OPENCLAW_HOME || homedir(), '.openclaw'),
192
+ status: statusOpenclaw,
193
+ install: {
194
+ commands: ['openclaw plugins install npm:@kioku-memory/openclaw', 'openclaw gateway restart'],
195
+ after: '重启网关之后生效',
196
+ },
197
+ source: 'openclaw',
113
198
  detect: () => false,
114
199
  readConfig: (env) => readProfile('openclaw', env),
115
200
  setup: setupOpenclaw,
@@ -119,13 +204,88 @@ const openclaw = {
119
204
  const dsh = {
120
205
  name: 'DeepSeek Harness',
121
206
  runtimeFamily: 'dsh',
207
+ command: () => 'dsh',
208
+ home: dshHome,
209
+ status: statusDsh,
210
+ install: {
211
+ commands: ['dsh plugin --profile <profile> add github:lonelyman0108/kioku-plugins'],
212
+ after: '<profile> 换成要用的 profile(web、tui 这些各装一次),重启 dsh 生效',
213
+ },
122
214
  detect: () => false,
123
215
  readConfig: (env) => readProfile('dsh', env),
124
216
  setup: setupDsh,
125
217
  inspect: inspectDsh,
126
218
  }
127
219
 
128
- export const PLATFORMS = { 'claude-code': claudeCode, codex, pi, hermes, openclaw, dsh }
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
+ }
129
289
 
130
290
  export function platformNames() {
131
291
  return Object.keys(PLATFORMS).join('、')
@@ -0,0 +1,38 @@
1
+ // 向导的交互层:@clack/prompts。它只是 npm 上的 @kioku-memory/cli 的依赖:插件目录里的那几份 kioku
2
+ // 是复制进去的,带不了依赖,所以这里按需装载,装不到时返回 null,由调用方说明怎么装。别的子命令不经过这里
3
+
4
+ // @clack/prompts 要求的 Node 版本
5
+ const MIN_NODE = [20, 12]
6
+
7
+ export function nodeSupported(version = process.versions.node) {
8
+ const [major, minor] = version.split('.').map(Number)
9
+ return major > MIN_NODE[0] || (major === MIN_NODE[0] && minor >= MIN_NODE[1])
10
+ }
11
+
12
+ // 交互库自带的英文换成中文:操作说明不显示(多选的写进问题里),是与否、取消与出错的文字改掉
13
+ export function localized(clack) {
14
+ clack.updateSettings?.({ messages: { cancel: '已取消', error: '出错了' } })
15
+ return {
16
+ ...clack,
17
+ select: (options) => clack.select({ showInstructions: false, ...options }),
18
+ multiselect: (options) =>
19
+ clack.multiselect({
20
+ showInstructions: false,
21
+ required: false,
22
+ ...options,
23
+ message: `${options.message}(空格选中,回车确认)`,
24
+ }),
25
+ confirm: (options) => clack.confirm({ active: '是', inactive: '否', ...options }),
26
+ }
27
+ }
28
+
29
+ export async function loadPrompts() {
30
+ if (!nodeSupported()) return null
31
+ let clack
32
+ try {
33
+ clack = await import('@clack/prompts')
34
+ } catch {
35
+ return null
36
+ }
37
+ return localized(clack)
38
+ }