mino-connector-backup 0.0.0-stage → 0.1.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/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,11 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # mino-connector-backup
2
+
3
+ 手机备份盘点连接器。
4
+
5
+ backup_dirs 枚举 iTunes/HiSuite/小米备份目录;backup_itunes 读 Manifest.db 看备份内容按域统计。
6
+
7
+ ## 原则
8
+
9
+ - 只读/本地:数据不出本机
10
+ - 用户主动:导入动作都由用户发起
11
+ - 只读 Manifest.db 不解密内容。
@@ -0,0 +1,5 @@
1
+ # mino-connector-backup — bundle patch
2
+ - insert:
3
+ - id: connector-backup
4
+ name: 'mino-connector-backup'
5
+ config: {}
package/hostdeps.mjs ADDED
@@ -0,0 +1,74 @@
1
+ /**
2
+ * hostdeps.mjs —— 从宿主那棵树里取 `defineTool`(拿不到就退到自己的依赖,再不行用本地等价实现)。
3
+ * 与 fish-memory/lib/hostdeps.mjs 同一策略:桌面版 profile `autoInstallPeers: false`
4
+ * 时裸 import `@deepseek-ai/dsh-tools` 会让整条插件不激活,所以优先从宿主树解析。
5
+ * 本包只需要 defineTool 一个件。
6
+ */
7
+ import { existsSync, readFileSync, readdirSync } from 'node:fs'
8
+ import { join, dirname } from 'node:path'
9
+ import { homedir } from 'node:os'
10
+ import { fileURLToPath, pathToFileURL } from 'node:url'
11
+
12
+ const SELF_MODULES = join(dirname(fileURLToPath(import.meta.url)), 'node_modules', '@deepseek-ai')
13
+
14
+ function candidateRoots() {
15
+ const out = []
16
+ const push = (p) => { if (p && !out.includes(p)) out.push(p) }
17
+ push(process.env.DSH_HOST_MODULES)
18
+ const appdata = process.env.APPDATA
19
+ if (appdata) {
20
+ const npm = join(appdata, 'npm', 'node_modules')
21
+ push(join(npm, '@deepseek-ai'))
22
+ try {
23
+ for (const n of readdirSync(join(npm, '@deepseek-ai'))) {
24
+ push(join(npm, '@deepseek-ai', n, 'node_modules', '@deepseek-ai'))
25
+ }
26
+ } catch { /* 没有就算了 */ }
27
+ }
28
+ try {
29
+ const dshHome = process.env.DSH_HOME || join(homedir(), '.dsh')
30
+ for (const p of readdirSync(join(dshHome, 'profiles'))) {
31
+ push(join(dshHome, 'profiles', p, 'node_modules', '@deepseek-ai'))
32
+ }
33
+ } catch { /* 没有就算了 */ }
34
+ push(SELF_MODULES)
35
+ return out
36
+ }
37
+
38
+ function entryUrlFor(root, name) {
39
+ try {
40
+ const dir = join(root, name)
41
+ const pkgFile = join(dir, 'package.json')
42
+ if (!existsSync(pkgFile)) return null
43
+ const pkg = JSON.parse(readFileSync(pkgFile, 'utf8'))
44
+ const dot = pkg.exports?.['.']
45
+ const rel = typeof dot === 'string' ? dot : (dot?.import || dot?.default || pkg.module || pkg.main)
46
+ if (!rel) return null
47
+ const file = join(dir, String(rel).replace(/^\.\//, ''))
48
+ return existsSync(file) ? pathToFileURL(file).href : null
49
+ } catch { return null }
50
+ }
51
+
52
+ function localDefineTool(options) {
53
+ return options
54
+ }
55
+
56
+ export async function loadHostDeps() {
57
+ const notes = []
58
+ const log = (m) => notes.push(m)
59
+ let defineTool = null
60
+ let dtMod = null
61
+ for (const root of candidateRoots()) {
62
+ if (root === SELF_MODULES) continue
63
+ const url = entryUrlFor(root, 'dsh-tools')
64
+ if (!url) continue
65
+ try { dtMod = await import(url); log(`dsh-tools:宿主树取到(${url})`); break }
66
+ catch { /* try next root */ }
67
+ }
68
+ if (!dtMod) {
69
+ try { dtMod = await import('@deepseek-ai/dsh-tools'); log('dsh-tools:用自己依赖里那份') }
70
+ catch (e) { log(`dsh-tools 拿不到(${e?.code || ''})—— 用本地等价实现顶上`); dtMod = null }
71
+ }
72
+ defineTool = dtMod?.defineTool || ((options) => localDefineTool(options))
73
+ return { defineTool, notes }
74
+ }
package/index.js ADDED
@@ -0,0 +1,109 @@
1
+ /**
2
+ * mino-connector-backup —— 手机备份连接器(域 17 扩面)。
3
+ * backup_itunes:读 iTunes 备份目录的 Manifest.db(sqlite),列出备份里
4
+ * 有什么数据(按域统计:照片/短信/通讯录/WhatsApp/健康…),只读。
5
+ * backup_dirs:枚举各备份工具的备份目录(iTunes/华为HiSuite/小米)。
6
+ */
7
+ import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
8
+ import { join, dirname } from 'node:path'
9
+ import { homedir } from 'node:os'
10
+ import { fileURLToPath } from 'node:url'
11
+ import { loadHostDeps } from './hostdeps.mjs'
12
+ import { createSkillProvider } from './skill-provider.mjs'
13
+
14
+ const PKG_DIR = dirname(fileURLToPath(import.meta.url))
15
+ const PKG = JSON.parse(readFileSync(join(PKG_DIR, 'package.json'), 'utf8'))
16
+ const APPDATA = process.env.APPDATA || join(homedir(), 'AppData', 'Roaming')
17
+
18
+ export const name = PKG.name
19
+ export const inject = ['skills', 'tools']
20
+ const defineTool = (await loadHostDeps()).defineTool
21
+
22
+ let DatabaseSync = null
23
+ try { ({ DatabaseSync } = await import('node:sqlite')) } catch { }
24
+
25
+ const DOMAIN_HINT = {
26
+ 'CameraRollDomain': '照片/视频', 'MediaDomain': '媒体', 'HomeDomain': '应用数据',
27
+ 'WirelessDomain': '无线', 'SystemPreferencesDomain': '系统设置', 'AppDomain': '应用',
28
+ 'DatabaseDomain': '数据库', 'HealthDomain': '健康', 'KeychainDomain': '钥匙串',
29
+ }
30
+
31
+ export function apply(ctx) {
32
+ ctx.tools.register(defineTool({
33
+ name: 'backup_dirs',
34
+ description: '枚举本机各手机备份工具的备份目录(iTunes/华为HiSuite/小米助手)。',
35
+ parameters: {},
36
+ output: { schema: { type: 'object', additionalProperties: false, properties: {
37
+ dirs: { type: 'array', items: { type: 'object', additionalProperties: true } } } },
38
+ render: (_a, v) => [{ type: 'text', text: `${v.dirs.length} 个备份目录` }] },
39
+ isConcurrencySafe: () => true,
40
+ async execute() {
41
+ const spots = [
42
+ { tool: 'iTunes', dir: join(APPDATA, 'Apple Computer', 'MobileSync', 'Backup') },
43
+ { tool: 'iTunes(新Apple Devices)', dir: join(homedir(), 'Apple', 'MobileSync', 'Backup') },
44
+ { tool: '华为HiSuite', dir: join(homedir(), 'Documents', 'Hisuite', 'backup') },
45
+ { tool: '小米助手', dir: join(homedir(), 'Documents', 'MIUI', 'backup') },
46
+ ]
47
+ const dirs = []
48
+ for (const s of spots) {
49
+ if (!existsSync(s.dir)) continue
50
+ try {
51
+ const subs = readdirSync(s.dir, { withFileTypes: true }).filter(e => e.isDirectory())
52
+ dirs.push({ ...s, 备份数: subs.length, 最新: subs.map(e => { try { return statSync(join(s.dir, e.name)).mtime.toISOString().slice(0, 10) } catch { return '' } }).sort().pop() })
53
+ } catch { }
54
+ }
55
+ return { dirs }
56
+ },
57
+ presentCall: (a) => ({ card: 'generic', title: '找备份目录', kind: 'other', rawInput: a }),
58
+ }))
59
+
60
+ ctx.tools.register(defineTool({
61
+ name: 'backup_itunes',
62
+ description:
63
+ '读 iTunes 备份的 Manifest.db,列出这个备份里有什么数据' +
64
+ '(按域统计照片/短信/通讯录/健康/WhatsApp 等条目数)。只读不解密。',
65
+ parameters: {
66
+ dir: { type: 'string', description: '备份目录(默认自动找最新一个 iTunes 备份)' },
67
+ },
68
+ output: { schema: { type: 'object', additionalProperties: false, properties: {
69
+ files: { type: 'integer' }, domains: { type: 'object', additionalProperties: true }, encrypted: { type: 'boolean' } } },
70
+ render: (_a, v) => [{ type: 'text', text:
71
+ `备份含 ${v.files} 个文件:` + Object.entries(v.domains).slice(0, 10).map(([k, n]) => `${k}:${n}`).join(';') +
72
+ (v.encrypted ? '(加密备份)' : '') }] },
73
+ isConcurrencySafe: () => true,
74
+ async execute(args) {
75
+ if (!DatabaseSync) throw new Error('backup_itunes: 运行时缺 node:sqlite')
76
+ let dir = args.dir ? String(args.dir) : null
77
+ if (!dir) {
78
+ const base = join(APPDATA, 'Apple Computer', 'MobileSync', 'Backup')
79
+ if (existsSync(base)) {
80
+ const subs = readdirSync(base, { withFileTypes: true }).filter(e => e.isDirectory())
81
+ .map(e => ({ p: join(base, e.name), t: statSync(join(base, e.name)).mtimeMs })).sort((a, b) => b.t - a.t)
82
+ dir = subs[0]?.p
83
+ }
84
+ }
85
+ if (!dir || !existsSync(dir)) throw new Error('backup_itunes: 没找到备份目录,用 dir 指定')
86
+ const manifest = join(dir, 'Manifest.db')
87
+ if (!existsSync(manifest)) throw new Error('backup_itunes: 目录里没有 Manifest.db(不是 iTunes 备份?)')
88
+ const info = join(dir, 'Info.plist')
89
+ const encrypted = existsSync(info) && readFileSync(info, 'latin1').includes('<key>IsEncrypted</key>')
90
+ const db = new DatabaseSync(manifest, { readOnly: true })
91
+ try {
92
+ let files = 0
93
+ const domains = {}
94
+ try {
95
+ const rows = db.prepare('SELECT domain, COUNT(*) c FROM Files GROUP BY domain ORDER BY c DESC').all()
96
+ files = rows.reduce((a, r) => a + r.c, 0)
97
+ for (const r of rows) {
98
+ const label = Object.entries(DOMAIN_HINT).find(([k]) => r.domain.includes(k))?.[1] || r.domain.replace(/^(App|Media|Wireless)?Domain-?/i, '').slice(0, 30)
99
+ domains[label] = (domains[label] || 0) + r.c
100
+ }
101
+ } catch { domains['(Manifest 结构未识别)'] = 0 }
102
+ return { files, domains, encrypted }
103
+ } finally { db.close() }
104
+ },
105
+ presentCall: (a) => ({ card: 'generic', title: '看备份内容', kind: 'other', rawInput: a }),
106
+ }))
107
+
108
+ ctx.effect(() => ctx.skills.registerProvider(() => createSkillProvider(ctx)))
109
+ }
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
- {
2
- "name": "mino-connector-backup",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
1
+ {
2
+ "name": "mino-connector-backup",
3
+ "version": "0.1.0",
4
+ "description": "手机备份连接器:读 iTunes 备份 Manifest.db 列内容清单 + 华为备份目录枚举。只读。",
5
+ "keywords": [
6
+ "dsh",
7
+ "dsh-plugin",
8
+ "mino-connector",
9
+ "backup"
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/backup"
41
+ },
42
+ "bugs": {
43
+ "url": "https://github.com/694410194/mino-plugins/issues"
44
+ }
6
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,28 @@
1
+ ---
2
+ name: backup-annual-report
3
+ description: 备份年度体检。备份够不够,产出可晒的年度总结 markdown。涉及"年度报告/年终总结/年度盘点"请求时适用。
4
+ metadata:
5
+ author: mino
6
+ version: "0.1.0"
7
+ ---
8
+
9
+ # 备份年度体检
10
+
11
+ 用本域连接器把备份够不够整理成一份年度总结。数据全程本地,产物写用户目录。
12
+
13
+ ## 流程
14
+
15
+ 0. **可选出图**:把报告要点按 `poster-design` 技能写成自包含 HTML,调 `poster_render` 出 PNG 晒图。
16
+
17
+ 1. **确认数据**:相关工具(backup_dirs/backup_itunes)有数据才做;没有先引导导入。
18
+ 2. **取数**:调对应工具拉统计和明细。
19
+ 3. **写报告**:在数据同目录写 `<年份>-backup报告.md`,结构:
20
+ - 总览(区间/总量/来源)
21
+ - 各设备最近备份时间、内容域分布、风险提示
22
+ - 值得记住的几条(选有故事感的明细)
23
+ - 结语一句
24
+
25
+ ## 纪律
26
+
27
+ - 数字必须来自工具返回,不估不编
28
+ - 数据缺口直说,不补假数
@@ -0,0 +1,13 @@
1
+ ---
2
+ name: backup-audit
3
+ description: 手机备份盘点。backup_dirs 枚举 iTunes/HiSuite/小米备份目录;backup_itunes 读 Manifest.db 看备份内容按域统计。
4
+ ---
5
+ # 手机备份盘点
6
+
7
+ ## 用法
8
+
9
+ iTunes 加密备份只报域分布不解密。
10
+
11
+ ## 边界
12
+
13
+ 只读 Manifest.db 不解密内容。