@dsh-plugin/dsh-pack-plugin 0.0.0-stage → 0.0.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.
Files changed (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +178 -3
  3. package/cordis.patch.yml +9 -0
  4. package/icons/folder-zip-line.svg +1 -0
  5. package/lib/ball.js +597 -0
  6. package/lib/client.js +2934 -0
  7. package/lib/host.js +51745 -0
  8. package/lib/migrate-helper.js +35346 -0
  9. package/lib/progress-main.cjs +79 -0
  10. package/lib/progress-window.ps1 +114 -0
  11. package/lib/progress.html +126 -0
  12. package/lib/publish-to-github/SKILL.md +132 -0
  13. package/package.json +77 -4
  14. package/src/ball-entry.js +5 -0
  15. package/src/ball-host.js +99 -0
  16. package/src/ball-settings.js +352 -0
  17. package/src/ball.js +418 -0
  18. package/src/channel.js +12 -0
  19. package/src/client-plugin.js +58 -0
  20. package/src/client-rpc.js +14 -0
  21. package/src/client.js +5 -0
  22. package/src/core/discovery.js +192 -0
  23. package/src/core/dspack.js +93 -0
  24. package/src/core/extension-files.js +102 -0
  25. package/src/core/extension-install.js +295 -0
  26. package/src/core/extension-patch.js +369 -0
  27. package/src/core/extension-skills.js +164 -0
  28. package/src/core/extension-validate.js +127 -0
  29. package/src/core/extensions.js +207 -0
  30. package/src/core/home-store.js +32 -0
  31. package/src/core/host.js +149 -0
  32. package/src/core/index.js +59 -0
  33. package/src/core/inspect.js +162 -0
  34. package/src/core/install.js +775 -0
  35. package/src/core/managed-install.js +84 -0
  36. package/src/core/manifest.js +717 -0
  37. package/src/core/market.js +268 -0
  38. package/src/core/mcp-composition.js +189 -0
  39. package/src/core/mcp-install.js +112 -0
  40. package/src/core/mcp-transport.js +116 -0
  41. package/src/core/pack.js +371 -0
  42. package/src/core/plugin-metadata.js +355 -0
  43. package/src/core/registry.js +316 -0
  44. package/src/core/repo.js +339 -0
  45. package/src/core/scan.js +78 -0
  46. package/src/core/security.js +101 -0
  47. package/src/core/special.js +50 -0
  48. package/src/core/tar.js +103 -0
  49. package/src/core/update-config.js +234 -0
  50. package/src/core/update.js +792 -0
  51. package/src/core/vendored.js +715 -0
  52. package/src/core/workspace.js +95 -0
  53. package/src/endpoints.js +455 -0
  54. package/src/ensure-manager.js +186 -0
  55. package/src/host-node.js +625 -0
  56. package/src/host.js +17 -0
  57. package/src/index.d.ts +7 -0
  58. package/src/index.js +39 -0
  59. package/src/junction.js +142 -0
  60. package/src/migrate-helper.js +225 -0
  61. package/src/migrate.js +56 -0
  62. package/src/packaged.js +9 -0
  63. package/src/profiles.js +106 -0
  64. package/src/progress-main.cjs +79 -0
  65. package/src/progress-window.ps1 +114 -0
  66. package/src/progress.html +126 -0
  67. package/src/progress.js +132 -0
  68. package/src/rpc.js +157 -0
  69. package/src/runtime.js +43 -0
  70. package/src/section-gate.js +50 -0
  71. package/src/settings-nav-icon.js +188 -0
  72. package/src/settings.js +1611 -0
  73. package/src/skills/index.js +90 -0
  74. package/src/skills/publish-to-github/SKILL.md +132 -0
  75. package/src/tasks.js +145 -0
  76. package/src/v6-dialogs.js +312 -0
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Host —— core 的唯一 I/O 依赖(依赖注入边界)。
3
+ *
4
+ * core 自身不 import node:fs / node:crypto / child_process 等 Node 内建,
5
+ * 全部通过 Host 注入,使同一份逻辑可同时跑在:
6
+ * - Node 宿主(CLI / Electron / server) → @dsh-packforge/host-node
7
+ * - DSH 客户端插件(浏览器 + DSH 文件系统桥)→ @dsh-packforge/host-dsh-plugin
8
+ *
9
+ * 约定:
10
+ * - 所有方法返回 Promise(joinPath/resolvePath/cwd 是纯函数,同步返回);
11
+ * - 读方法在「不存在 / 无权」时返回 null(不抛),写方法抛错;
12
+ * - 绝对路径:整体交给方法的参数,连接/解析用 joinPath/resolvePath,**绝不在 core 里手拼系统路径分隔符**;
13
+ * - 相对路径(rel)一律用 '/' 分隔(对齐格式规范 pack-structure)。
14
+ */
15
+ export class Host {
16
+ /** 连接路径片段为绝对路径(Node: path.join)。 */
17
+ joinPath(..._parts) {
18
+ throw new Error('Host.joinPath 未实现');
19
+ }
20
+
21
+ /** 解析路径为绝对路径(Node: path.resolve;相对片段基于 cwd)。 */
22
+ resolvePath(..._parts) {
23
+ throw new Error('Host.resolvePath 未实现');
24
+ }
25
+
26
+ /** 进程当前工作目录。 */
27
+ cwd() {
28
+ throw new Error('Host.cwd 未实现');
29
+ }
30
+
31
+ /** 用户主目录(如 '~')。 */
32
+ homedir() {
33
+ throw new Error('Host.homedir 未实现');
34
+ }
35
+
36
+ /** 读环境变量;未设置 → null。 */
37
+ env(_name) {
38
+ throw new Error('Host.env 未实现');
39
+ }
40
+
41
+ /** 路径最后一段(Node: path.basename)。 */
42
+ basename(_abs) {
43
+ throw new Error('Host.basename 未实现');
44
+ }
45
+
46
+ /** 读文本(UTF-8);不存在/无权 → null。 */
47
+ async readTextFile(_abs) {
48
+ throw new Error('Host.readTextFile 未实现');
49
+ }
50
+
51
+ /** 写文本(UTF-8,无 BOM);自动建父目录。 */
52
+ async writeTextFile(_abs, _text) {
53
+ throw new Error('Host.writeTextFile 未实现');
54
+ }
55
+
56
+ /** 读二进制;不存在/无权 → null。 */
57
+ async readFile(_abs) {
58
+ throw new Error('Host.readFile 未实现');
59
+ }
60
+
61
+ /** 写二进制;自动建父目录。 */
62
+ async writeFile(_abs, _data) {
63
+ throw new Error('Host.writeFile 未实现');
64
+ }
65
+
66
+ /** 单路径元信息;不存在/无权 → null。返回 { size, isFile, isDirectory, isSymbolicLink }。 */
67
+ async stat(_abs) {
68
+ throw new Error('Host.stat 未实现');
69
+ }
70
+
71
+ /** 读取普通文件的 POSIX 访问位,宿主不支持时返回 null。 */
72
+ async packFileMode(_abs) {
73
+ throw new Error('Host.packFileMode 未实现');
74
+ }
75
+
76
+ /** 使用 Cordis 组合从低到高排列的补丁副本,返回配置行数组。 */
77
+ async composePackEntries(_patches) {
78
+ throw new Error('Host.composePackEntries 未实现');
79
+ }
80
+
81
+ /** 为普通文件设置 POSIX 访问位,宿主不支持时保留默认权限。 */
82
+ async chmodPackFile(_abs, _mode) {
83
+ throw new Error('Host.chmodPackFile 未实现');
84
+ }
85
+
86
+ /** 读目录条目;不存在/无权 → null。返回 [{ name, abs, type }],type ∈ file|dir|symlink|other。 */
87
+ async readdir(_abs) {
88
+ throw new Error('Host.readdir 未实现');
89
+ }
90
+
91
+ /** 递归创建目录。 */
92
+ async mkdir(_abs) {
93
+ throw new Error('Host.mkdir 未实现');
94
+ }
95
+
96
+ /** 删除(opts: { recursive?, force? })。 */
97
+ async rm(_abs, _opts) {
98
+ throw new Error('Host.rm 未实现');
99
+ }
100
+
101
+ /** 建临时目录,返回其绝对路径。 */
102
+ async mkdtemp(_prefix) {
103
+ throw new Error('Host.mkdtemp 未实现');
104
+ }
105
+
106
+ /** 对一段字节求 sha256,返回 64 位十六进制。 */
107
+ async sha256(_data) {
108
+ throw new Error('Host.sha256 未实现');
109
+ }
110
+
111
+ /** 对文件求 sha256(建议流式,避免大文件整读进内存)。 */
112
+ async sha256File(_abs) {
113
+ throw new Error('Host.sha256File 未实现');
114
+ }
115
+
116
+ /** 执行外部命令,返回 { status, error? }(Node: spawnSync 继承 stdio;插件/浏览器宿主另议)。 */
117
+ async exec(_cmd, _args, _opts) {
118
+ throw new Error('Host.exec 未实现');
119
+ }
120
+
121
+ /**
122
+ * 运行 pnpm install(可选能力)。默认回退到 `exec('pnpm', …)`(依赖 PATH);宿主可覆盖为
123
+ * 「复用自带 node+pnpm 运行时」(如 DSH 桌面端的 `resources/runtime/`),从而不依赖用户机器 PATH。
124
+ * 返回与 exec 相同的 { status, error? }。
125
+ */
126
+ async pnpm(_args, _opts) {
127
+ return this.exec('pnpm', _args, _opts);
128
+ }
129
+
130
+ /** 下载 http(s) URL 到本地文件。 */
131
+ async download(_url, _destAbs) {
132
+ throw new Error('Host.download 未实现');
133
+ }
134
+
135
+ /**
136
+ * 描述当前代理来源(可选能力,供安装日志展示「走了哪个代理 / 还是直连」)。
137
+ * 返回 `{ kind, url }`,kind ∈ 'manual'(手动配置)| 'direct'(用户强制直连)|
138
+ * 'auto-env'(环境变量)| 'auto-system'(系统代理)| 'auto-direct'(自动但未检测到代理);
139
+ * 默认返回 null(宿主不提供该信息,core 侧跳过该行日志)。
140
+ */
141
+ proxyStatus(_target) {
142
+ return null;
143
+ }
144
+
145
+ /** 移动/重命名文件(跨目录),自动建目标父目录。 */
146
+ async move(_from, _to) {
147
+ throw new Error('Host.move 未实现');
148
+ }
149
+ }
@@ -0,0 +1,59 @@
1
+ // DSH-PackForge core 公共 API(供 CLI / GUI / 插件以编程方式调用)。
2
+ export { Host } from './host.js';
3
+ export { isExcluded } from './security.js';
4
+ export { scanProfile, selectFiles } from './scan.js';
5
+ export { summarizeSpecial } from './special.js';
6
+ export {
7
+ buildManifest,
8
+ buildHomeManifest,
9
+ validateManifest,
10
+ validateFileEntry,
11
+ coordsToPkgDeps,
12
+ pkgDepsToCoords,
13
+ coordinatesFromProfileDeps,
14
+ gitCommitFromLock,
15
+ isExactSemver,
16
+ parseGitCoord,
17
+ parsePkgGitSpec,
18
+ resolveLocale,
19
+ isLocaleString,
20
+ extractBundles,
21
+ extractDependencies,
22
+ sanitizeSlug,
23
+ normalizeLaunchers,
24
+ compareLauncherVersions,
25
+ } from './manifest.js';
26
+ export {
27
+ discoverProfiles,
28
+ discoverHomes,
29
+ listInstalledDshVersions,
30
+ resolveProfileInput,
31
+ skipProfileDir,
32
+ compareVersions,
33
+ sortVersionsDesc,
34
+ } from './discovery.js';
35
+ export { buildDspack, parseDspack, encodeText, decodeText, dspackMarker, DSPACK_FORMAT, DSPACK_CONTAINER_VERSION } from './dspack.js';
36
+ export { packProfile, packHome, dspackEntryPath, summarizeHome } from './pack.js';
37
+ export { exportRepo, ReleaseConflictError, renderReadme, renderDspackIgnore, renderGitignore, REPO_CONTENT_LEVELS, REPO_CONTENT_LABEL } from './repo.js';
38
+ export { loadWorkspaceConfig, saveWorkspaceConfig, WORKSPACE_KEYS, exportFromWorkspace, exportHomeFromWorkspace } from './workspace.js';
39
+ export { inspectProfile, inspectHome, inspectPack } from './inspect.js';
40
+ export { installPack, verifyIntegrity, reconcileProfile, resolvePackSource, resolveDshVersion, judgeLaunchers } from './install.js';
41
+ export {
42
+ resolveVendoredPlan,
43
+ isDialectSpec,
44
+ directMount,
45
+ materializeVendorBlobs,
46
+ blobRelPath,
47
+ coordDirName,
48
+ allDependencyCoords,
49
+ lockfilePackageNames,
50
+ computeOfflineCoverage,
51
+ listProfileDependencies,
52
+ collectVendoredForExport,
53
+ coordFromDirName,
54
+ repackageFromNodeModules,
55
+ } from './vendored.js';
56
+ export { untar, buildTarball } from './tar.js';
57
+ export { readMarketIndex, fetchMarketPackDetail, normalizeMarketPack, packDirId, DEFAULT_MARKET_INDEX, pickR2Fields, r2Badges, parseLaunchersRegistry, fetchLaunchersRegistry, DEFAULT_LAUNCHERS_REGISTRY_URL, BUILTIN_LAUNCHERS } from './market.js';
58
+ export { discoverExtensions } from './extensions.js';
59
+ export { exportChoices } from './inspect.js';
@@ -0,0 +1,162 @@
1
+ import { collectPluginMetadata } from './plugin-metadata.js';
2
+ import { collectExtensions, discoverExtensions } from './extensions.js';
3
+ import { scanProfile, selectFiles } from './scan.js';
4
+ import { buildManifest, buildHomeManifest } from './manifest.js';
5
+ import { validateManifest } from './manifest.js';
6
+ import { parseDspack, decodeText } from './dspack.js';
7
+ import { summarizeSpecial } from './special.js';
8
+ import { summarizeHome, profileHome } from './pack.js';
9
+
10
+ /** 干跑检查:返回扫描结果 + manifest v5 预览 + 特殊目录摘要,不写任何文件。
11
+ * opts.include(rel 白名单)给定则 files/special 只取选中项,allFiles 保留全量。 */
12
+ export async function inspectProfile(host, profile, opts = {}) {
13
+ const scan = await scanProfile(host, profile.dir);
14
+ const files = selectFiles(scan.files, opts.include);
15
+ const manifest = await buildManifest(host, profile, opts, scan);
16
+ // home 级候选(上一级目录):供 GUI 勾选,勾选项打包进 home/ 目录。
17
+ const homeDir = profileHome(host, profile, opts.home);
18
+ await collectPluginMetadata(host, profile.dir, manifest, { plugins: opts.plugins, entries: {} });
19
+ await collectExtensions(host, { home: homeDir, profiles: [profile], manifest, entries: {}, selection: {} });
20
+ const homeFiles = homeDir ? (await scanProfile(host, homeDir)).files.filter((f) => !f.rel.startsWith('profiles/')) : [];
21
+ return {
22
+ profile,
23
+ files,
24
+ allFiles: scan.files,
25
+ excluded: scan.excluded,
26
+ manifest,
27
+ special: summarizeSpecial(files),
28
+ homeFiles,
29
+ homeDir,
30
+ };
31
+ }
32
+
33
+ /** 干跑检查(dshhome):扫描整个 home → 识别四类单元 → 预览 manifest v5,不写任何文件。 */
34
+ export async function inspectHome(host, home, opts = {}) {
35
+ const scan = await scanProfile(host, home.dir);
36
+ const files = selectFiles(scan.files, opts.include);
37
+ const summary = summarizeHome(files);
38
+ const profiles = [...summary.profiles.keys()]
39
+ .filter((n) => n !== 'web' && n !== 'headless')
40
+ .map((n) => ({ name: n, dir: host.joinPath(home.dir, 'profiles', n) }));
41
+ const presets = {};
42
+ for (const [id, path] of summary.presets) presets[id] = { path };
43
+ const manifest = await buildHomeManifest(host, home, {
44
+ name: opts.name,
45
+ displayName: opts.displayName,
46
+ version: opts.version,
47
+ description: opts.description,
48
+ author: opts.author,
49
+ icon: opts.icon,
50
+ dshVersion: opts.dshVersion,
51
+ defaultProfile: opts.defaultProfile,
52
+ profiles,
53
+ presets,
54
+ skills: summary.skills,
55
+ instructions: summary.instructions || 'AGENTS.md',
56
+ files: opts.files ?? [],
57
+ });
58
+ for (const profile of profiles) {
59
+ await collectPluginMetadata(host, profile.dir, manifest.profiles[profile.name], { plugins: opts.profilePlugins?.[profile.name], entries: {} });
60
+ }
61
+ await collectExtensions(host, { home: home.dir, profiles, manifest, entries: {}, selection: {} });
62
+ return { home, files, allFiles: scan.files, excluded: scan.excluded, manifest, summary };
63
+ }
64
+
65
+ /**
66
+ * 查看一个已有的 `.dspack` 整合包(不解压到磁盘):容器版本、全包 sha256/size、
67
+ * manifest 校验结果、根机器文件 / overrides/ / 其它条目的目录树。
68
+ * 供 GUI「查看整合包」与 CLI `view` 复用;纯内存,宿主无关。
69
+ *
70
+ * @param {Host} host
71
+ * @param {string|Uint8Array} source 本地 .dspack 路径或已在内存中的字节
72
+ * @returns {Promise<{sha256,size,containerVersion,valid,validation,manifest,machine,overrides,other,totalEntries}>}
73
+ */
74
+ export async function inspectPack(host, source, { includeIcons = false } = {}) {
75
+ const bytes = source instanceof Uint8Array ? source : await host.readFile(host.resolvePath(source));
76
+ if (!bytes) throw new Error('无法读取整合包文件');
77
+ const { entries, marker } = parseDspack(bytes);
78
+
79
+ let manifest = null;
80
+ let validation;
81
+ if (entries['manifest.json']) {
82
+ manifest = parseJson(decodeText(entries['manifest.json']));
83
+ validation = manifest ? validateManifest(manifest) : ['manifest.json 无法解析'];
84
+ } else {
85
+ validation = ['缺少 manifest.json'];
86
+ }
87
+
88
+ if (manifest?.manifestVersion === 6) {
89
+ for (const [path, data] of Object.entries(entries)) {
90
+ if (path.startsWith('extension-data/') && await host.sha256(data) !== path.split('/').pop()) {
91
+ validation.push('扩展文件 SHA-256 不符:' + path);
92
+ }
93
+ }
94
+ }
95
+
96
+ const machine = [];
97
+ const overrides = [];
98
+ const home = [];
99
+ const other = [];
100
+ for (const [p, data] of Object.entries(entries)) {
101
+ if (p === 'manifest.json') continue;
102
+ const size = data?.byteLength ?? data?.length ?? 0;
103
+ const rec = { path: p, size };
104
+ if (p === 'dspack.json' || p === 'package.json' || p === 'pnpm-workspace.yaml' || p === 'pnpm-lock.yaml') machine.push(rec);
105
+ else if (p.startsWith('overrides/')) overrides.push(rec);
106
+ else if (p.startsWith('home/')) home.push(rec);
107
+ else other.push(rec);
108
+ }
109
+ const byPath = (a, b) => a.path.localeCompare(b.path);
110
+ machine.sort(byPath);
111
+ overrides.sort(byPath);
112
+ home.sort(byPath);
113
+ other.sort(byPath);
114
+
115
+ const icons = Object.create(null);
116
+ if (includeIcons && !validation.length && manifest?.manifestVersion === 6) {
117
+ const units = manifest.type === 'dshhome' ? Object.values(manifest.profiles || {}) : [manifest];
118
+ for (const unit of units) {
119
+ for (const { icon } of Object.values(unit.plugins || {})) {
120
+ if (icon?.startsWith('assets/plugins/') && entries[icon]) icons[icon] = entries[icon];
121
+ }
122
+ }
123
+ }
124
+ return {
125
+ ...(includeIcons ? {icons} : {}),
126
+ sha256: await host.sha256(bytes),
127
+ size: bytes.byteLength,
128
+ containerVersion: marker?.version ?? null,
129
+ valid: validation.length === 0,
130
+ validation,
131
+ manifest,
132
+ machine,
133
+ overrides,
134
+ home,
135
+ other,
136
+ totalEntries: Object.keys(entries).length,
137
+ };
138
+ }
139
+
140
+ function parseJson(raw) {
141
+ if (raw == null || raw === '') return null;
142
+ try {
143
+ return JSON.parse(raw);
144
+ } catch {
145
+ return null;
146
+ }
147
+ }
148
+
149
+ /** 列出资源选择框需要的插件描述和资源标识,避免向界面发送原始补丁。 */
150
+ export async function exportChoices(host, { profile, home, plugins, profilePlugins }) {
151
+ const dir = home?.dir || profileHome(host, profile);
152
+ const profiles = profile ? [profile] : (await host.readdir(host.joinPath(dir, 'profiles')) || [])
153
+ .filter((entry) => entry.type === 'dir' && !['web', 'headless'].includes(entry.name))
154
+ .map((entry) => ({ name: entry.name, dir: entry.abs }));
155
+ const units = Object.create(null);
156
+ for (const item of profiles) {
157
+ const unit = await buildManifest(host, item);
158
+ await collectPluginMetadata(host, item.dir, unit, { plugins: profile ? plugins : profilePlugins?.[item.name], entries: {} });
159
+ units[item.name] = { plugins: unit.plugins, bundles: unit.bundles, dependencies: unit.dependencies };
160
+ }
161
+ return { candidates: await discoverExtensions(host, { home: dir, profiles, wholeHome: !profile }), units };
162
+ }