-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (56 loc) · 2.62 KB
/
Copy pathindex.js
File metadata and controls
61 lines (56 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { readFileSync } from 'node:fs'
import { join, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import { spawnSync } from 'node:child_process'
const here = dirname(fileURLToPath(import.meta.url))
const SCRIPT = join(here, 'bin', 'prepare-codex-migration.sh')
const SUBCOMMANDS = ['prepare', 'verify', 'restore', 'restore-worktree']
export const name = 'migrate-codex'
export function apply(ctx) {
const commands = ctx.get('commands')
const skills = ctx.get('skills')
if (skills !== undefined) {
const disposeSkill = skills.register({
name: 'codex-migration',
description: 'Codex 环境安全迁移:打包、校验、恢复到新机器,以及 Codex 配置向 DeepSeek Harness 的迁移指导。',
whenToUse: '用户提到迁移 Codex、换电脑迁移 codex-migration 包、verify/restore/restore-worktree 迁移包,或想把 Codex 的 AGENTS.md / skills / 配置迁进 DeepSeek Harness 时使用。',
source: 'bundled',
resourceBase: { kind: 'directory', path: join(here, 'skills') },
content: readFileSync(join(here, 'skills', 'codex-migration.md'), 'utf8'),
})
ctx.on('dispose', disposeSkill)
}
if (commands !== undefined) {
const disposeCommand = commands.register({
name: 'migrate-codex',
description: '运行 Codex 迁移脚本:prepare 打包 / verify 校验 / restore 恢复 / restore-worktree 恢复单个脏工作树。',
input: { hint: 'prepare|verify|restore <迁移包目录>,或 restore-worktree <迁移包目录> <slug>' },
handler(invocation) {
const parts = invocation.rawInput.trim().split(/\s+/).filter((s) => s.length > 0)
const [sub, ...rest] = parts
if (sub === undefined || !SUBCOMMANDS.includes(sub)) {
return {
kind: 'error',
text: `用法:/migrate-codex <${SUBCOMMANDS.join('|')}> <迁移包目录> [slug]。未知子命令:${sub ?? '(空)'}`,
}
}
try {
const result = spawnSync('bash', [SCRIPT, sub, ...rest], {
encoding: 'utf8',
timeout: 10 * 60 * 1000,
maxBuffer: 16 * 1024 * 1024,
})
const text = `${result.stdout ?? ''}${result.stderr ?? ''}`.trim() || '(脚本无输出)'
if (result.status === 0) return { kind: 'success', text }
return { kind: 'error', text: `退出码 ${result.status}:\n${text}` }
} catch (error) {
return {
kind: 'error',
text: `执行失败:${error instanceof Error ? error.message : String(error)}`,
}
}
},
})
ctx.on('dispose', disposeCommand)
}
}