mino-connector-wechat 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +9 -2
- package/cordis.patch.yml +5 -0
- package/hostdeps.mjs +39 -0
- package/index.js +209 -0
- package/package.json +43 -4
- package/skill-provider.mjs +131 -0
- package/skills/wechat-local-export/SKILL.md +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wuyangji
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# mino-connector-wechat
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
微信本地库解密导出连接器。
|
|
4
|
+
|
|
5
|
+
wechat_dirs 侦察数据目录→配导出引擎(wechat-dump-rs/PyWxDump 到 connector-wechat.json 的 dumper)→wechat_decrypt 解密入聊天库。
|
|
6
|
+
|
|
7
|
+
## 原则
|
|
8
|
+
|
|
9
|
+
- 特区深侧:只读你自己设备上你自己的数据
|
|
10
|
+
- 引擎由用户配置,本体不含取钥逻辑
|
package/cordis.patch.yml
ADDED
package/hostdeps.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Canonical host API loader. Generate packaged copies with scripts/sync-hostdeps.mjs.
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
import { join, resolve } from 'node:path'
|
|
4
|
+
import { pathToFileURL } from 'node:url'
|
|
5
|
+
|
|
6
|
+
function resolverOrigins(name) {
|
|
7
|
+
const origins = []
|
|
8
|
+
// An explicit development host and the current Electron installation own these APIs.
|
|
9
|
+
if (process.env.DSH_HOST_MODULES) origins.push(join(process.env.DSH_HOST_MODULES, name, 'package.json'))
|
|
10
|
+
if (process.resourcesPath) origins.push(join(process.resourcesPath, 'app.asar', 'dsh', 'node_modules', '@deepseek-ai', name, 'package.json'))
|
|
11
|
+
if (process.argv[1]) origins.push(resolve(process.argv[1]))
|
|
12
|
+
origins.push(import.meta.url)
|
|
13
|
+
return [...new Set(origins)]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function loadLibrary(name, notes) {
|
|
17
|
+
const failures = []
|
|
18
|
+
for (const origin of resolverOrigins(name)) {
|
|
19
|
+
try {
|
|
20
|
+
const entry = createRequire(origin).resolve(`@deepseek-ai/${name}`)
|
|
21
|
+
const module = await import(pathToFileURL(entry).href)
|
|
22
|
+
notes.push(`${name}: ${entry}`)
|
|
23
|
+
return module
|
|
24
|
+
} catch (error) { failures.push(error) }
|
|
25
|
+
}
|
|
26
|
+
throw new AggregateError(failures, `Host API @deepseek-ai/${name} is unavailable`)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function loadHostDeps() {
|
|
30
|
+
const notes = []
|
|
31
|
+
const tools = await loadLibrary('dsh-tools', notes)
|
|
32
|
+
if (typeof tools.defineTool !== 'function') throw new Error('Required host API @deepseek-ai/dsh-tools.defineTool is unavailable')
|
|
33
|
+
let z = null
|
|
34
|
+
try {
|
|
35
|
+
const schema = await loadLibrary('schemastery', notes)
|
|
36
|
+
z = schema.default ?? schema
|
|
37
|
+
} catch (error) { notes.push(error.message) }
|
|
38
|
+
return { z, defineTool: tools.defineTool, notes }
|
|
39
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mino-connector-wechat —— 微信本地语料连接器(特区深侧)。
|
|
3
|
+
* wechat_dirs:定位 WeChat 进程 + 数据目录(3.x WeChat Files / 4.x xwechat_files)。
|
|
4
|
+
* wechat_decrypt:封装解密导出引擎(wechat-dump-rs / PyWxDump 等单文件 exe,
|
|
5
|
+
* 引擎路径在 ~/.dsh/connector-wechat.json 配 dumper,或 dumperUrl 按需下载)——
|
|
6
|
+
* 引擎做内存取钥+SQLCipher 解密,产出明文 sqlite 后直接收进
|
|
7
|
+
* connector-chat-export 的 chat.db(source=wechat-local),chat_search 可查。
|
|
8
|
+
* 只读本机自己的数据;取钥靠引擎完成,本体不含密钥提取逻辑。
|
|
9
|
+
*/
|
|
10
|
+
import { execFile } from 'node:child_process'
|
|
11
|
+
import { promisify } from 'node:util'
|
|
12
|
+
import { existsSync, readFileSync, readdirSync, statSync, mkdirSync, writeFileSync } from 'node:fs'
|
|
13
|
+
import { join, dirname } from 'node:path'
|
|
14
|
+
import { homedir } from 'node:os'
|
|
15
|
+
import { fileURLToPath } from 'node:url'
|
|
16
|
+
import { loadHostDeps } from './hostdeps.mjs'
|
|
17
|
+
import { createSkillProvider } from './skill-provider.mjs'
|
|
18
|
+
|
|
19
|
+
const execFileP = promisify(execFile)
|
|
20
|
+
const PKG_DIR = dirname(fileURLToPath(import.meta.url))
|
|
21
|
+
const PKG = JSON.parse(readFileSync(join(PKG_DIR, 'package.json'), 'utf8'))
|
|
22
|
+
const DSH_HOME = process.env.DSH_HOME || join(homedir(), '.dsh')
|
|
23
|
+
const STORE = join(DSH_HOME, 'connector-wechat')
|
|
24
|
+
const CFG_PATH = join(DSH_HOME, 'connector-wechat.json')
|
|
25
|
+
const CHAT_DB = join(DSH_HOME, 'connector-chat-export', 'chat.db')
|
|
26
|
+
|
|
27
|
+
export const name = PKG.name
|
|
28
|
+
export const inject = ['skills', 'tools']
|
|
29
|
+
const defineTool = (await loadHostDeps()).defineTool
|
|
30
|
+
|
|
31
|
+
const DOCS = join(homedir(), 'Documents')
|
|
32
|
+
|
|
33
|
+
function* findDataDirs() {
|
|
34
|
+
// 4.x:Documents/xwechat_files/<wxid>/... 3.x:Documents/WeChat Files/<wxid>/...
|
|
35
|
+
for (const base of [join(DOCS, 'xwechat_files'), join(DOCS, 'WeChat Files'),
|
|
36
|
+
join(DOCS, 'wxid_'), join(process.env.USERPROFILE || '', 'AppData', 'Roaming', 'Tencent', 'xwechat_files')]) {
|
|
37
|
+
if (!existsSync(base)) continue
|
|
38
|
+
try {
|
|
39
|
+
for (const e of readdirSync(base, { withFileTypes: true })) {
|
|
40
|
+
if (!e.isDirectory()) continue
|
|
41
|
+
const p = join(base, e.name)
|
|
42
|
+
const hasDb = (d, depth) => {
|
|
43
|
+
if (depth > 3) return false
|
|
44
|
+
try {
|
|
45
|
+
for (const x of readdirSync(d, { withFileTypes: true })) {
|
|
46
|
+
if (x.isDirectory() && hasDb(join(d, x.name), depth + 1)) return true
|
|
47
|
+
if (/(MSG|MicroMsg|message|chat)[^/]*\.db$/i.test(x.name)) return true
|
|
48
|
+
}
|
|
49
|
+
} catch { }
|
|
50
|
+
return false
|
|
51
|
+
}
|
|
52
|
+
if (hasDb(p, 0)) yield { account: e.name, dir: p }
|
|
53
|
+
}
|
|
54
|
+
} catch { }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function running() {
|
|
59
|
+
if (process.platform !== 'win32') return []
|
|
60
|
+
try {
|
|
61
|
+
const { stdout } = await execFileP('tasklist', ['/FO', 'CSV', '/NH'], { timeout: 15000, windowsHide: true })
|
|
62
|
+
return stdout.split('\n').filter(l => /wechat|weixin|wechatapp/i.test(l)).map(l => l.split(',')[0].replace(/"/g, ''))
|
|
63
|
+
} catch { return [] }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function cfg() { try { return JSON.parse(readFileSync(CFG_PATH, 'utf8')) } catch { return {} } }
|
|
67
|
+
|
|
68
|
+
export function apply(ctx) {
|
|
69
|
+
ctx.tools.register(defineTool({
|
|
70
|
+
name: 'wechat_dirs',
|
|
71
|
+
description: '定位本机微信:数据目录(按账号)、进程是否在跑、库里有什么 .db。解密前置侦察。',
|
|
72
|
+
parameters: {},
|
|
73
|
+
output: { schema: { type: 'object', additionalProperties: false, properties: {
|
|
74
|
+
accounts: { type: 'array', items: { type: 'object', additionalProperties: true } },
|
|
75
|
+
running: { type: 'array', items: { type: 'string' } } } },
|
|
76
|
+
render: (_a, v) => [{ type: 'text', text: `${v.accounts.length} 个账号数据目录;进程:${v.running.join('/') || '未运行'}` }] },
|
|
77
|
+
isConcurrencySafe: () => true,
|
|
78
|
+
async execute() {
|
|
79
|
+
const accounts = [...findDataDirs()].map(a => {
|
|
80
|
+
const dbs = []
|
|
81
|
+
const walk = (d, depth) => {
|
|
82
|
+
if (depth > 4 || dbs.length > 50) return
|
|
83
|
+
try {
|
|
84
|
+
for (const e of readdirSync(d, { withFileTypes: true })) {
|
|
85
|
+
const p = join(d, e.name)
|
|
86
|
+
if (e.isDirectory()) walk(p, depth + 1)
|
|
87
|
+
else if (/\.db$/i.test(e.name)) dbs.push(p)
|
|
88
|
+
}
|
|
89
|
+
} catch { }
|
|
90
|
+
}
|
|
91
|
+
walk(a.dir, 0)
|
|
92
|
+
return { ...a, dbCount: dbs.length, sample: dbs.slice(0, 5).map(x => x.split(/[\\/]/).pop()) }
|
|
93
|
+
})
|
|
94
|
+
return { accounts, running: await running() }
|
|
95
|
+
},
|
|
96
|
+
presentCall: (a) => ({ card: 'generic', title: '找微信数据', kind: 'other', rawInput: a }),
|
|
97
|
+
}))
|
|
98
|
+
|
|
99
|
+
ctx.tools.register(defineTool({
|
|
100
|
+
name: 'wechat_decrypt',
|
|
101
|
+
description:
|
|
102
|
+
'解密导出微信本地库:调用配置的导出引擎(~/.dsh/connector-wechat.json 的 ' +
|
|
103
|
+
'dumper=引擎exe路径 或 dumperUrl=下载地址;推荐 wechat-dump-rs/PyWxDump exe),' +
|
|
104
|
+
'产出明文 sqlite 并把消息行收进聊天库(chat_search 可查)。微信需在运行且已登录。',
|
|
105
|
+
parameters: {
|
|
106
|
+
account: { type: 'string', description: '指定账号目录名(wxid_),默认全部' },
|
|
107
|
+
out: { type: 'string', description: '解密输出目录(默认 ~/.dsh/connector-wechat/out)' },
|
|
108
|
+
dumperArgs: { type: 'string', description: '引擎参数模板,占位 {dir} {out}(默认引擎自选)' },
|
|
109
|
+
},
|
|
110
|
+
output: { schema: { type: 'object', additionalProperties: false, properties: {
|
|
111
|
+
decrypted: { type: 'integer' }, imported: { type: 'integer' }, out: { type: 'string' } } },
|
|
112
|
+
render: (_a, v) => [{ type: 'text', text: `解密 ${v.decrypted} 库,入库消息 ${v.imported} 条` }] },
|
|
113
|
+
isConcurrencySafe: () => false,
|
|
114
|
+
async execute(args) {
|
|
115
|
+
const c = cfg()
|
|
116
|
+
let dumper = c.dumper
|
|
117
|
+
// engine-assist 共享注册表兜底(engine_register wechat-dump 登记的也认)
|
|
118
|
+
if (!dumper) {
|
|
119
|
+
try {
|
|
120
|
+
const reg = JSON.parse(readFileSync(join(homedir(), '.dsh', 'engines.json'), 'utf8'))['wechat-dump']
|
|
121
|
+
if (reg && existsSync(reg)) dumper = reg
|
|
122
|
+
} catch { }
|
|
123
|
+
if (!dumper) {
|
|
124
|
+
const edir = join(homedir(), '.dsh', 'engines', 'wechat-dump')
|
|
125
|
+
if (existsSync(edir)) {
|
|
126
|
+
for (const f of readdirSync(edir)) if (/\.exe$/i.test(f)) { dumper = join(edir, f); break }
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (!dumper && c.dumperUrl) {
|
|
131
|
+
mkdirSync(STORE, { recursive: true })
|
|
132
|
+
dumper = join(STORE, 'dumper.exe')
|
|
133
|
+
if (!existsSync(dumper)) {
|
|
134
|
+
const res = await fetch(c.dumperUrl, { signal: AbortSignal.timeout(180000), redirect: 'follow' })
|
|
135
|
+
if (!res.ok) throw new Error(`引擎下载失败 HTTP ${res.status}`)
|
|
136
|
+
writeFileSync(dumper, Buffer.from(await res.arrayBuffer()))
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (!dumper || !existsSync(dumper)) throw new Error(
|
|
140
|
+
`没配导出引擎:在 ${CFG_PATH} 填 {"dumper":"D:/路径/wechat-dump-rs.exe"} 或 {"dumperUrl":"https://.../exe"}。` +
|
|
141
|
+
`本工具不自带取钥逻辑,靠这些开源引擎:wechat-dump-rs(单 exe)、PyWxDump(pip+exe)、WeChatMsg(GUI)。`)
|
|
142
|
+
const procs = await running()
|
|
143
|
+
if (!procs.length) throw new Error('微信没在运行——解密引擎要从进程内存取钥,先登录微信再跑')
|
|
144
|
+
const out = args.out ? String(args.out) : join(STORE, 'out')
|
|
145
|
+
mkdirSync(out, { recursive: true })
|
|
146
|
+
const dirs = [...findDataDirs()].filter(d => !args.account || d.account.includes(String(args.account)))
|
|
147
|
+
if (!dirs.length) throw new Error('没找到微信数据目录(先 wechat_dirs 侦察)')
|
|
148
|
+
let decrypted = 0
|
|
149
|
+
const dbs = []
|
|
150
|
+
for (const d of dirs) {
|
|
151
|
+
const argv = (args.dumperArgs || c.dumperArgs || '--all --data-dir {dir} --output {out}')
|
|
152
|
+
.replace(/\{dir\}/g, d.dir).replace(/\{out\}/g, join(out, d.account)).split(/\s+/).filter(Boolean)
|
|
153
|
+
try { await execFileP(dumper, argv, { timeout: 600000, windowsHide: true, maxBuffer: 4 * 1024 * 1024 }) }
|
|
154
|
+
catch (e) { throw new Error(`引擎报错:${String(e?.stderr || e?.message).slice(-300)}`) }
|
|
155
|
+
const odir = join(out, d.account)
|
|
156
|
+
if (existsSync(odir)) {
|
|
157
|
+
const walk = (p, depth) => {
|
|
158
|
+
if (depth > 4) return
|
|
159
|
+
for (const e of readdirSync(p, { withFileTypes: true })) {
|
|
160
|
+
const fp = join(p, e.name)
|
|
161
|
+
if (e.isDirectory()) walk(fp, depth + 1)
|
|
162
|
+
else if (/\.(db|sqlite)$/i.test(e.name)) dbs.push(fp)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
walk(odir, 0)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
decrypted = dbs.length
|
|
169
|
+
// 明文库 → chat.db(消息表容错:MSG/message/chat_*,列名 StrContent/content/text)
|
|
170
|
+
let imported = 0
|
|
171
|
+
const { DatabaseSync } = await import('node:sqlite')
|
|
172
|
+
const chatDbDir = join(DSH_HOME, 'connector-chat-export')
|
|
173
|
+
mkdirSync(chatDbDir, { recursive: true })
|
|
174
|
+
const chatDb = new DatabaseSync(CHAT_DB)
|
|
175
|
+
chatDb.exec('CREATE TABLE IF NOT EXISTS messages(source TEXT, file TEXT, time TEXT, sender TEXT, text TEXT)')
|
|
176
|
+
const ins = chatDb.prepare('INSERT INTO messages(source,file,time,sender,text) VALUES(?,?,?,?,?)')
|
|
177
|
+
chatDb.exec('BEGIN')
|
|
178
|
+
try {
|
|
179
|
+
for (const f of dbs) {
|
|
180
|
+
let sdb
|
|
181
|
+
try { sdb = new DatabaseSync(f, { readOnly: true }) } catch { continue }
|
|
182
|
+
try {
|
|
183
|
+
const tables = sdb.prepare("SELECT name FROM sqlite_master WHERE type='table' AND (name LIKE '%MSG%' OR name LIKE '%message%' OR name LIKE '%chat%')").all()
|
|
184
|
+
for (const t of tables) {
|
|
185
|
+
const cols = sdb.prepare(`PRAGMA table_info("${t.name}")`).all().map(c => c.name)
|
|
186
|
+
const textCol = cols.find(c => /StrContent|content|text|msg/i.test(c))
|
|
187
|
+
const timeCol = cols.find(c => /CreateTime|time|timestamp/i.test(c))
|
|
188
|
+
const senderCol = cols.find(c => /StrTalker|talker|sender|from/i.test(c))
|
|
189
|
+
if (!textCol) continue
|
|
190
|
+
const rows = sdb.prepare(`SELECT ${timeCol || 'rowid'} t, ${senderCol || "''"} s, ${textCol} x FROM "${t.name}" LIMIT 500000`).all()
|
|
191
|
+
for (const r of rows) {
|
|
192
|
+
const txt = String(r.x || '').replace(/<[^>]+>/g, ' ').trim()
|
|
193
|
+
if (!txt || txt.length < 2) continue
|
|
194
|
+
const tm = /^\d{10}$/.test(String(r.t)) ? new Date(+r.t * 1000).toISOString().slice(0, 19).replace('T', ' ') : String(r.t || '').slice(0, 19)
|
|
195
|
+
ins.run('wechat-local', f.split(/[\\/]/).pop(), tm, String(r.s || ''), txt.slice(0, 2000))
|
|
196
|
+
imported++
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
} finally { sdb.close() }
|
|
200
|
+
}
|
|
201
|
+
chatDb.exec('COMMIT')
|
|
202
|
+
} finally { chatDb.close() }
|
|
203
|
+
return { decrypted, imported, out }
|
|
204
|
+
},
|
|
205
|
+
presentCall: (a) => ({ card: 'generic', title: '解密微信', kind: 'other', rawInput: a }),
|
|
206
|
+
}))
|
|
207
|
+
|
|
208
|
+
ctx.effect(() => ctx.skills.registerProvider(() => createSkillProvider(ctx)))
|
|
209
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mino-connector-wechat",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "微信本地语料连接器:定位 WeChat 数据目录/进程,封装导出引擎(wechat-dump-rs/PyWxDump)做内存取钥+库解密,明文落 chat.db 检索。特区解封,用户自己的数据。",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"dsh",
|
|
7
|
+
"dsh-plugin",
|
|
8
|
+
"mino-connector",
|
|
9
|
+
"wechat"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "index.js",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./index.js",
|
|
15
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"index.js",
|
|
20
|
+
"hostdeps.mjs",
|
|
21
|
+
"skill-provider.mjs",
|
|
22
|
+
"skills",
|
|
23
|
+
"cordis.patch.yml",
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE"
|
|
26
|
+
],
|
|
27
|
+
"dsh": {
|
|
28
|
+
"bundle": {
|
|
29
|
+
"patch": "./cordis.patch.yml"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"dsh": ">=0.2.2-alpha.1 <0.3.0",
|
|
34
|
+
"node": ">=20.18"
|
|
35
|
+
},
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/694410194/mino-plugins.git",
|
|
40
|
+
"directory": "packages/wechat"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/694410194/mino-plugins/issues"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* skill-provider.mjs —— ctx.skills.registerProvider 的标准实现。
|
|
3
|
+
* 与 templates/skill-pack/index.js 的 provider 逻辑一致(D42 纪律:逐字用,勿手写变形)。
|
|
4
|
+
* 用法:import { createSkillProvider } from './skill-provider.mjs'
|
|
5
|
+
* ctx.effect(() => ctx.skills.registerProvider(() => createSkillProvider(ctx)))
|
|
6
|
+
* 约定:包根有 package.json(取 name)和 skills/ 目录。
|
|
7
|
+
*/
|
|
8
|
+
import { readFileSync } from 'node:fs'
|
|
9
|
+
import { readdir, readFile } from 'node:fs/promises'
|
|
10
|
+
import { fileURLToPath } from 'node:url'
|
|
11
|
+
import { dirname, join } from 'node:path'
|
|
12
|
+
|
|
13
|
+
const PKG_DIR = dirname(fileURLToPath(import.meta.url))
|
|
14
|
+
const PKG = JSON.parse(readFileSync(join(PKG_DIR, 'package.json'), 'utf8'))
|
|
15
|
+
const SKILLS_DIR = join(PKG_DIR, 'skills')
|
|
16
|
+
const RANK = 650
|
|
17
|
+
const NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
|
|
18
|
+
|
|
19
|
+
export function createSkillProvider(ctx) {
|
|
20
|
+
const warn = (msg) => ctx.logger?.warn(msg)
|
|
21
|
+
return {
|
|
22
|
+
name: PKG.name,
|
|
23
|
+
async list(options = {}) {
|
|
24
|
+
let entries
|
|
25
|
+
try { entries = await readdir(SKILLS_DIR, { withFileTypes: true }) }
|
|
26
|
+
catch (e) { if (e?.code === 'ENOENT') return []; throw e }
|
|
27
|
+
const candidates = []
|
|
28
|
+
for (const entry of entries) {
|
|
29
|
+
options.signal?.throwIfAborted?.()
|
|
30
|
+
const file = entry.isDirectory() ? join(SKILLS_DIR, entry.name, 'SKILL.md')
|
|
31
|
+
: entry.isFile() && entry.name.endsWith('.md') ? join(SKILLS_DIR, entry.name) : undefined
|
|
32
|
+
if (!file) continue
|
|
33
|
+
const parsed = await parseSkillFile(file, options.signal, warn)
|
|
34
|
+
if (parsed) candidates.push(toCandidate(parsed, file))
|
|
35
|
+
}
|
|
36
|
+
return candidates
|
|
37
|
+
},
|
|
38
|
+
async get(candidate, options = {}) {
|
|
39
|
+
const parsed = await parseSkillFile(candidate.locator, options.signal, warn)
|
|
40
|
+
if (!parsed || parsed.name !== candidate.name) return undefined
|
|
41
|
+
return {
|
|
42
|
+
name: parsed.name,
|
|
43
|
+
description: parsed.description,
|
|
44
|
+
...(parsed.whenToUse !== undefined ? { whenToUse: parsed.whenToUse } : {}),
|
|
45
|
+
invocation: parsed.invocation,
|
|
46
|
+
source: 'market',
|
|
47
|
+
provider: PKG.name,
|
|
48
|
+
resourceBase: { kind: 'directory', path: dirname(candidate.locator) },
|
|
49
|
+
...(parsed.metadata !== undefined ? { metadata: parsed.metadata } : {}),
|
|
50
|
+
content: parsed.content,
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function toCandidate(parsed, file) {
|
|
57
|
+
return {
|
|
58
|
+
name: parsed.name,
|
|
59
|
+
description: parsed.description,
|
|
60
|
+
...(parsed.whenToUse !== undefined ? { whenToUse: parsed.whenToUse } : {}),
|
|
61
|
+
invocation: parsed.invocation,
|
|
62
|
+
source: 'market',
|
|
63
|
+
provider: PKG.name,
|
|
64
|
+
resourceBase: { kind: 'directory', path: dirname(file) },
|
|
65
|
+
...(parsed.metadata !== undefined ? { metadata: parsed.metadata } : {}),
|
|
66
|
+
rank: RANK,
|
|
67
|
+
locator: file,
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function parseSkillFile(file, signal, warn) {
|
|
72
|
+
let raw
|
|
73
|
+
try { raw = await readFile(file, 'utf8') } catch { return undefined }
|
|
74
|
+
signal?.throwIfAborted?.()
|
|
75
|
+
const parsed = parseFrontmatter(raw)
|
|
76
|
+
if (!parsed) { warn(`skill file ${file} ignored: missing frontmatter`); return undefined }
|
|
77
|
+
const { data, body } = parsed
|
|
78
|
+
const name = str(data.name)
|
|
79
|
+
const description = str(data.description)
|
|
80
|
+
if (!name || !description) { warn(`skill file ${file} ignored: frontmatter requires name and description`); return undefined }
|
|
81
|
+
if (!NAME_RE.test(name)) { warn(`skill file ${file} ignored: invalid skill name "${name}"`); return undefined }
|
|
82
|
+
return {
|
|
83
|
+
name,
|
|
84
|
+
description,
|
|
85
|
+
...(str(data.whenToUse) !== undefined ? { whenToUse: str(data.whenToUse) } : {}),
|
|
86
|
+
invocation: { modelInvocable: !(data['disable-model-invocation'] === true), userInvocable: data['user-invocable'] !== false },
|
|
87
|
+
...(data.metadata && typeof data.metadata === 'object' ? { metadata: data.metadata } : {}),
|
|
88
|
+
content: body.trim(),
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const str = (v) => typeof v === 'string' && v.trim() ? v : undefined
|
|
93
|
+
|
|
94
|
+
function parseFrontmatter(text) {
|
|
95
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(text)
|
|
96
|
+
if (!match) return undefined
|
|
97
|
+
return { data: parseFlatYaml(match[1]), body: text.slice(match[0].length) }
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function parseFlatYaml(src) {
|
|
101
|
+
const data = {}
|
|
102
|
+
let section
|
|
103
|
+
for (const line of src.split(/\r?\n/)) {
|
|
104
|
+
if (!line.trim() || line.trimStart().startsWith('#')) continue
|
|
105
|
+
const indent = line.length - line.trimStart().length
|
|
106
|
+
const match = /^([A-Za-z0-9_-]+)\s*:\s*(.*)$/.exec(line.trim())
|
|
107
|
+
if (!match) continue
|
|
108
|
+
const [, key, raw] = match
|
|
109
|
+
const value = parseScalar(raw)
|
|
110
|
+
if (indent > 0 && section) {
|
|
111
|
+
if (typeof data[section] !== 'object' || data[section] === null) data[section] = {}
|
|
112
|
+
data[section][key] = value
|
|
113
|
+
continue
|
|
114
|
+
}
|
|
115
|
+
if (value === undefined) { section = key; data[key] = {} }
|
|
116
|
+
else { data[key] = value; section = undefined }
|
|
117
|
+
}
|
|
118
|
+
return data
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function parseScalar(raw) {
|
|
122
|
+
const value = raw.trim()
|
|
123
|
+
if (value === '') return undefined
|
|
124
|
+
if (value.startsWith('"') && value.endsWith('"') && value.length >= 2) return value.slice(1, -1)
|
|
125
|
+
if (value.startsWith("'") && value.endsWith("'") && value.length >= 2) return value.slice(1, -1)
|
|
126
|
+
const bare = value.replace(/\s+#.*$/, '')
|
|
127
|
+
if (bare === 'true') return true
|
|
128
|
+
if (bare === 'false') return false
|
|
129
|
+
if (bare === 'null' || bare === '~') return null
|
|
130
|
+
return bare
|
|
131
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: wechat-local-export
|
|
3
|
+
description: 微信本地库解密导出。wechat_dirs 侦察数据目录→配导出引擎(wechat-dump-rs/PyWxDump 到 connector-wechat.json 的 dumper)→wechat_decrypt 解密入聊天库。
|
|
4
|
+
---
|
|
5
|
+
# 微信本地库解密导出
|
|
6
|
+
|
|
7
|
+
wechat_dirs 侦察数据目录→配导出引擎(wechat-dump-rs/PyWxDump 到 connector-wechat.json 的 dumper)→wechat_decrypt 解密入聊天库。
|
|
8
|
+
|
|
9
|
+
## 边界
|
|
10
|
+
|
|
11
|
+
- 只读本机自己的数据,数据不出本机
|
|
12
|
+
- 取钥/解密由用户配置的开源引擎完成,本体不含密钥提取逻辑
|
|
13
|
+
- 微信/QQ 须运行且已登录(取钥依赖进程内存)
|
|
14
|
+
- 加密域打不开时给白话指引,不硬解
|