@openchamber/web 1.19.0 → 1.20.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/dist/assets/{CodeMirrorCommentWidgets-DAvopJvy.js → CodeMirrorCommentWidgets-C36E738Y.js} +1 -1
- package/dist/assets/{CommitSection-D9cV-qR9.js → CommitSection-C-F3AX6D.js} +1 -1
- package/dist/assets/{DiagramEditor-B9NCadU7.js → DiagramEditor-BPECg1jS.js} +1 -1
- package/dist/assets/DiagramView-D0YNMix8.js +1 -0
- package/dist/assets/DiffView-BHWaMYCC.js +4 -0
- package/dist/assets/FilesView-NMBCW2Tm.js +14 -0
- package/dist/assets/{GitView-DsWXqWx3.js → GitView-Rp8P1KEI.js} +4 -4
- package/dist/assets/{JsonTreeView-h4dHASlq.js → JsonTreeView-KnXFN2A-.js} +1 -1
- package/dist/assets/{MarkdownImageGallery-n0ikH-xm.js → MarkdownImageGallery-BMn3mtor.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-kD6N03pH.js +12 -0
- package/dist/assets/{OnboardingScreen-CDjgzxEe.js → OnboardingScreen-CenIeD4v.js} +1 -1
- package/dist/assets/{PatchDiff-jPKTJje5.js → PatchDiff-BzVOVog8.js} +1 -1
- package/dist/assets/{PierreDiffViewer-D_Gt4A_6.js → PierreDiffViewer-Dlby4XqT.js} +2 -2
- package/dist/assets/PlanView-Czu1KMJa.js +4 -0
- package/dist/assets/SessionSwitcherDropdown-IETz58DB.js +1 -0
- package/dist/assets/SettingsView-B6vmuf-c.js +28 -0
- package/dist/assets/SettingsWindow-CauZpdD3.js +1 -0
- package/dist/assets/ToolOutputDialog-BB1c--Zr.js +15 -0
- package/dist/assets/ToolPartDiffPreview-DaOIDISD.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-B37yB9jZ.js → VirtualizedFileDiff-lESMT-2b.js} +4 -4
- package/dist/assets/{WalkthroughView-Bxun3k66.js → WalkthroughView-CaSYE0lw.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-DYFv_yZS.js → computeVirtualFileMetrics-DkRR5b75.js} +2 -2
- package/dist/assets/{contextPanelEmbeddedChat-BO1wRpaN.js → contextPanelEmbeddedChat-BEARQjgn.js} +1 -1
- package/dist/assets/de-DFdX3ABv.js +9 -0
- package/dist/assets/es-iC-FKvV9.js +15 -0
- package/dist/assets/fr-BBbi_1AL.js +13 -0
- package/dist/assets/{index-BSvmTvZl.js → index-BiEgzzkg.js} +1 -1
- package/dist/assets/index-Cwmuwk3V.js +7 -0
- package/dist/assets/index-GNm1wgUH.css +1 -0
- package/dist/assets/{isDiffPlainText-DwHKxDYc.js → isDiffPlainText-BG53Ixxy.js} +1 -1
- package/dist/assets/{isFilePlainText-Dwq6ILxo.js → isFilePlainText-BbV-39jl.js} +1 -1
- package/dist/assets/ja-DQLQJL2J.js +15 -0
- package/dist/assets/ko-BeElEB4Y.js +15 -0
- package/dist/assets/main-Dpzo18z7.js +2 -0
- package/dist/assets/main-WMjtYzJs.js +921 -0
- package/dist/assets/markdownCore--tDmyI_v.js +2 -0
- package/dist/assets/miniChat-ldEghBLB.js +2 -0
- package/dist/assets/mobile-Dk-VGreF.js +2 -0
- package/dist/assets/{patchFileDiff-BEDPDypx.js → patchFileDiff-BcFaMtMu.js} +2 -2
- package/dist/assets/pl-CLHt2_vV.js +15 -0
- package/dist/assets/pt-BR-C_MPUq7e.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-DIgCOmXY.js +2 -0
- package/dist/assets/{renderMobileApp-BiMbzPq9.js → renderMobileApp-CDfHS5rr.js} +7 -7
- package/dist/assets/runtimeEndpointReset-ovNbaZ-x.js +15 -0
- package/dist/assets/{scheduledTasksApi-01zzfzqH.js → scheduledTasksApi-BFSlqgnG.js} +1 -1
- package/dist/assets/{shikiHighlight-DXYW46vW.js → shikiHighlight-DCT2Sq_z.js} +1 -1
- package/dist/assets/uk-PhsC-c4-.js +15 -0
- package/dist/assets/{useAppFontEffects-CbzHzFop.js → useAppFontEffects-B53Rb6m7.js} +166 -159
- package/dist/assets/useInlineCommentController-DSfrIBKT.js +2 -0
- package/dist/assets/{vendor-base-ui-BYlZTzrw.js → vendor-base-ui-DsHmyMwp.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-CiAYDJXN.js → vendor-codemirror-language-data-vch3tJ4c.js} +2 -2
- package/dist/assets/vendor-zod-C9ioTTSo.js +39 -0
- package/dist/assets/{web-components-DCLjCO9n.js → web-components-pcwCTWjC.js} +4 -4
- package/dist/assets/zh-CN-wF-NOFHM.js +15 -0
- package/dist/assets/zh-TW-4m4-A7rT.js +15 -0
- package/dist/index.html +5 -4
- package/dist/mini-chat.html +4 -3
- package/dist/mobile.html +4 -3
- package/package.json +3 -5
- package/server/index.js +36 -0
- package/server/lib/agent-memory/project-resolution.js +10 -1
- package/server/lib/agent-memory/project-resolution.test.js +9 -0
- package/server/lib/agent-memory/runtime.js +7 -2
- package/server/lib/dictation/DOCUMENTATION.md +32 -8
- package/server/lib/dictation/local/sherpa-recognizer.js +35 -78
- package/server/lib/dictation/local/worker-process.js +2 -2
- package/server/lib/dictation/openai-compatible-session.js +3 -2
- package/server/lib/dictation/stream-manager.js +77 -34
- package/server/lib/dictation/stream-manager.test.js +60 -2
- package/server/lib/fs/routes.test.js +76 -0
- package/server/lib/git/routes.js +43 -0
- package/server/lib/git/service.js +85 -5
- package/server/lib/git/service.test.js +93 -0
- package/server/lib/opencode/DOCUMENTATION.md +6 -2
- package/server/lib/opencode/feature-routes-runtime.js +5 -9
- package/server/lib/opencode/lifecycle.js +202 -26
- package/server/lib/opencode/lifecycle.test.js +179 -1
- package/server/lib/opencode/providers.js +9 -4
- package/server/lib/opencode/providers.test.js +27 -0
- package/server/lib/opencode/restart-session-recovery.test.js +59 -0
- package/server/lib/opencode/session-runtime.js +39 -2
- package/server/lib/opencode/session-runtime.test.js +74 -0
- package/server/lib/opencode/settings-helpers.js +15 -0
- package/server/lib/opencode/settings-helpers.test.js +22 -0
- package/server/lib/opencode/settings-normalization-runtime.js +3 -0
- package/server/lib/opencode/settings-normalization-runtime.test.js +16 -0
- package/server/lib/opencode/settings-runtime.js +32 -10
- package/server/lib/opencode/settings-runtime.test.js +85 -0
- package/server/lib/opencode/skill-routes.js +29 -73
- package/server/lib/opencode/skill-routes.test.js +2 -5
- package/server/lib/project-context/DOCUMENTATION.md +2 -0
- package/server/lib/project-context/runtime.js +7 -2
- package/server/lib/projects/project-config.js +7 -2
- package/server/lib/quota/DOCUMENTATION.md +1 -1
- package/server/lib/quota/providers/claude/index.js +2 -2
- package/server/lib/quota/providers/command-code.js +1 -1
- package/server/lib/quota/providers/command-code.test.js +13 -0
- package/server/lib/quota/providers/index.js +12 -4
- package/server/lib/quota/providers/zai.js +26 -6
- package/server/lib/quota/providers/zai.test.js +33 -0
- package/server/lib/session-knowledge/DOCUMENTATION.md +2 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +18 -45
- package/server/lib/skills-catalog/cache.js +120 -1
- package/server/lib/skills-catalog/cache.test.js +77 -0
- package/server/lib/skills-catalog/curated-sources.js +21 -5
- package/server/lib/skills-catalog/curated-sources.test.js +4 -4
- package/server/lib/skills-catalog/disk-cache.js +52 -0
- package/server/lib/skills-catalog/github-meta.js +139 -0
- package/server/lib/skills-catalog/github-meta.test.js +71 -0
- package/server/lib/skills-catalog/source.js +0 -5
- package/server/lib/small-model/DOCUMENTATION.md +74 -6
- package/server/lib/small-model/call.js +46 -12
- package/server/lib/small-model/call.test.js +79 -0
- package/server/lib/small-model/index.js +51 -8
- package/server/lib/small-model/index.test.js +73 -3
- package/server/lib/small-model/routes.js +1 -1
- package/server/lib/small-model/runtime-providers.js +156 -0
- package/server/lib/small-model/runtime-providers.test.js +112 -0
- package/dist/assets/DiagramView-LKGBwf4G.js +0 -1
- package/dist/assets/DiffView-BWNq-0ov.js +0 -4
- package/dist/assets/FilesView-DB-Q0Gkz.js +0 -14
- package/dist/assets/MarkdownRendererImpl-CT2mjx-s.js +0 -12
- package/dist/assets/PlanView-UvuxIl9-.js +0 -4
- package/dist/assets/SessionSwitcherDropdown-xKU4LRuQ.js +0 -1
- package/dist/assets/SettingsView-3B9VN6Ys.js +0 -28
- package/dist/assets/SettingsWindow-CqQNDKNd.js +0 -1
- package/dist/assets/ToolOutputDialog-PmjlAxVE.js +0 -15
- package/dist/assets/ToolPartDiffPreview-B34Xw9wq.js +0 -8
- package/dist/assets/de-DbV6CLxv.js +0 -9
- package/dist/assets/es-CVDlyzZ4.js +0 -15
- package/dist/assets/fr-Czc-p0g-.js +0 -13
- package/dist/assets/index-1OhiMDBz.css +0 -1
- package/dist/assets/index-DzriVon2.js +0 -7
- package/dist/assets/ja-dwc9NM_S.js +0 -15
- package/dist/assets/ko-Ds1DZ8FX.js +0 -15
- package/dist/assets/main-BF51IOVF.js +0 -921
- package/dist/assets/main-D7UPARut.js +0 -2
- package/dist/assets/markdownCore-BgeBDwD3.js +0 -2
- package/dist/assets/miniChat-BISXSGOo.js +0 -2
- package/dist/assets/mobile-BnYxVuvw.js +0 -2
- package/dist/assets/pl-CLiTO7i-.js +0 -15
- package/dist/assets/pt-BR-GIimJgpK.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-BaOy72Gi.js +0 -2
- package/dist/assets/runtimeEndpointReset-BMBRhIbf.js +0 -15
- package/dist/assets/uk-DLfgD1ki.js +0 -15
- package/dist/assets/useInlineCommentController-CegKdDXi.js +0 -2
- package/dist/assets/vendor-zod-adaMkgkm.js +0 -39
- package/dist/assets/zh-CN-DkeP5awK.js +0 -15
- package/dist/assets/zh-TW-BocaFm3d.js +0 -15
- package/server/lib/skills-catalog/clawdhub/api.js +0 -126
- package/server/lib/skills-catalog/clawdhub/install.js +0 -238
- package/server/lib/skills-catalog/clawdhub/install.test.js +0 -100
- package/server/lib/skills-catalog/clawdhub/scan.js +0 -61
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ClawdHub API client
|
|
3
|
-
*
|
|
4
|
-
* ClawdHub is a public skill registry at https://clawdhub.com
|
|
5
|
-
* This client provides methods to fetch skills list and download skill packages.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const CLAWDHUB_API_BASE = 'https://clawdhub.com/api/v1';
|
|
9
|
-
const CLAWDHUB_PAGE_LIMIT = 25;
|
|
10
|
-
|
|
11
|
-
// Rate limiting: ClawdHub allows 120 requests/minute
|
|
12
|
-
const RATE_LIMIT_DELAY_MS = 100;
|
|
13
|
-
let lastRequestTime = 0;
|
|
14
|
-
|
|
15
|
-
async function rateLimitedFetch(url, options = {}) {
|
|
16
|
-
const maxAttempts = 10;
|
|
17
|
-
|
|
18
|
-
let lastResponse = null;
|
|
19
|
-
|
|
20
|
-
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
21
|
-
const now = Date.now();
|
|
22
|
-
const elapsed = now - lastRequestTime;
|
|
23
|
-
if (elapsed < RATE_LIMIT_DELAY_MS) {
|
|
24
|
-
await new Promise((resolve) => setTimeout(resolve, RATE_LIMIT_DELAY_MS - elapsed));
|
|
25
|
-
}
|
|
26
|
-
lastRequestTime = Date.now();
|
|
27
|
-
|
|
28
|
-
const response = await fetch(url, {
|
|
29
|
-
...options,
|
|
30
|
-
headers: {
|
|
31
|
-
Accept: 'application/json',
|
|
32
|
-
'User-Agent': 'OpenChamber/1.0',
|
|
33
|
-
...options.headers,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
lastResponse = response;
|
|
38
|
-
|
|
39
|
-
if (response.status === 429 || response.status >= 500) {
|
|
40
|
-
if (attempt < maxAttempts - 1) {
|
|
41
|
-
const waitMs = 50 * (attempt + 1);
|
|
42
|
-
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return response;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return lastResponse;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Fetch paginated list of skills from ClawdHub
|
|
55
|
-
* @param {Object} options
|
|
56
|
-
* @param {string} [options.cursor] - Pagination cursor from previous response
|
|
57
|
-
* @returns {Promise<{ items: Array, nextCursor?: string }>}
|
|
58
|
-
*/
|
|
59
|
-
export async function fetchClawdHubSkills({ cursor } = {}) {
|
|
60
|
-
const url = cursor
|
|
61
|
-
? `${CLAWDHUB_API_BASE}/skills?cursor=${encodeURIComponent(cursor)}&limit=${CLAWDHUB_PAGE_LIMIT}`
|
|
62
|
-
: `${CLAWDHUB_API_BASE}/skills?limit=${CLAWDHUB_PAGE_LIMIT}`;
|
|
63
|
-
|
|
64
|
-
const response = await rateLimitedFetch(url);
|
|
65
|
-
|
|
66
|
-
if (!response.ok) {
|
|
67
|
-
const text = await response.text().catch(() => '');
|
|
68
|
-
throw new Error(`ClawdHub API error (${response.status}): ${text || response.statusText}`);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const data = await response.json();
|
|
72
|
-
const nextCursor =
|
|
73
|
-
(typeof data.nextCursor === 'string' && data.nextCursor) ||
|
|
74
|
-
(typeof data.next_cursor === 'string' && data.next_cursor) ||
|
|
75
|
-
(typeof data.next === 'string' && data.next) ||
|
|
76
|
-
(typeof data.cursor === 'string' && data.cursor) ||
|
|
77
|
-
null;
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
items: data.items || [],
|
|
81
|
-
nextCursor,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Download a skill package as a ZIP buffer
|
|
87
|
-
* @param {string} slug - Skill slug/identifier
|
|
88
|
-
* @param {string} version - Specific version string
|
|
89
|
-
* @returns {Promise<ArrayBuffer>} - ZIP file contents
|
|
90
|
-
*/
|
|
91
|
-
export async function downloadClawdHubSkill(slug, version) {
|
|
92
|
-
const versionParam = typeof version === 'string' && version !== 'latest'
|
|
93
|
-
? `&version=${encodeURIComponent(version)}`
|
|
94
|
-
: '&tag=latest';
|
|
95
|
-
const url = `${CLAWDHUB_API_BASE}/download?slug=${encodeURIComponent(slug)}${versionParam}`;
|
|
96
|
-
|
|
97
|
-
const response = await rateLimitedFetch(url, {
|
|
98
|
-
headers: {
|
|
99
|
-
Accept: 'application/zip',
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
if (!response.ok) {
|
|
104
|
-
const text = await response.text().catch(() => '');
|
|
105
|
-
throw new Error(`ClawdHub download error (${response.status}): ${text || response.statusText}`);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return response.arrayBuffer();
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Get skill metadata without version details
|
|
113
|
-
* @param {string} slug - Skill slug/identifier
|
|
114
|
-
* @returns {Promise<Object>}
|
|
115
|
-
*/
|
|
116
|
-
export async function fetchClawdHubSkillInfo(slug) {
|
|
117
|
-
const url = `${CLAWDHUB_API_BASE}/skills/${encodeURIComponent(slug)}`;
|
|
118
|
-
const response = await rateLimitedFetch(url);
|
|
119
|
-
|
|
120
|
-
if (!response.ok) {
|
|
121
|
-
const text = await response.text().catch(() => '');
|
|
122
|
-
throw new Error(`ClawdHub skill error (${response.status}): ${text || response.statusText}`);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return response.json();
|
|
126
|
-
}
|
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ClawdHub skill installation
|
|
3
|
-
*
|
|
4
|
-
* Downloads skills from ClawdHub as ZIP files and extracts them
|
|
5
|
-
* to the appropriate skill directory.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import fs from 'fs';
|
|
9
|
-
import os from 'os';
|
|
10
|
-
import path from 'path';
|
|
11
|
-
import AdmZip from 'adm-zip';
|
|
12
|
-
|
|
13
|
-
import { downloadClawdHubSkill, fetchClawdHubSkillInfo } from './api.js';
|
|
14
|
-
|
|
15
|
-
const SKILL_NAME_PATTERN = /^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/;
|
|
16
|
-
|
|
17
|
-
function normalizeUserSkillDir(userSkillDir) {
|
|
18
|
-
if (!userSkillDir) return null;
|
|
19
|
-
const legacySkillDir = path.join(os.homedir(), '.config', 'opencode', 'skill');
|
|
20
|
-
const pluralSkillDir = path.join(os.homedir(), '.config', 'opencode', 'skills');
|
|
21
|
-
if (userSkillDir === legacySkillDir) {
|
|
22
|
-
if (fs.existsSync(legacySkillDir) && !fs.existsSync(pluralSkillDir)) return legacySkillDir;
|
|
23
|
-
return pluralSkillDir;
|
|
24
|
-
}
|
|
25
|
-
return userSkillDir;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function validateSkillName(skillName) {
|
|
29
|
-
if (typeof skillName !== 'string') return false;
|
|
30
|
-
if (skillName.length < 1 || skillName.length > 64) return false;
|
|
31
|
-
return SKILL_NAME_PATTERN.test(skillName);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async function safeRm(dir) {
|
|
35
|
-
try {
|
|
36
|
-
await fs.promises.rm(dir, { recursive: true, force: true });
|
|
37
|
-
} catch {
|
|
38
|
-
// ignore
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async function ensureDir(dirPath) {
|
|
43
|
-
await fs.promises.mkdir(dirPath, { recursive: true });
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function getTargetSkillDir({ scope, targetSource, workingDirectory, userSkillDir, skillName }) {
|
|
47
|
-
const source = targetSource === 'agents' ? 'agents' : 'opencode';
|
|
48
|
-
|
|
49
|
-
if (scope === 'user') {
|
|
50
|
-
if (source === 'agents') {
|
|
51
|
-
return path.join(os.homedir(), '.agents', 'skills', skillName);
|
|
52
|
-
}
|
|
53
|
-
return path.join(userSkillDir, skillName);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (!workingDirectory) {
|
|
57
|
-
throw new Error('workingDirectory is required for project installs');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (source === 'agents') {
|
|
61
|
-
return path.join(workingDirectory, '.agents', 'skills', skillName);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return path.join(workingDirectory, '.opencode', 'skills', skillName);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Install skills from ClawdHub registry
|
|
69
|
-
* @param {Object} options
|
|
70
|
-
* @param {string} options.scope - 'user' or 'project'
|
|
71
|
-
* @param {string} [options.targetSource] - 'opencode' or 'agents'
|
|
72
|
-
* @param {string} [options.workingDirectory] - Required for project scope
|
|
73
|
-
* @param {string} options.userSkillDir - User skills directory
|
|
74
|
-
* @param {Array} options.selections - Array of { skillDir, clawdhub: { slug, version } }
|
|
75
|
-
* @param {string} [options.conflictPolicy] - 'prompt', 'skipAll', or 'overwriteAll'
|
|
76
|
-
* @param {Object} [options.conflictDecisions] - Per-skill conflict decisions
|
|
77
|
-
* @returns {Promise<{ ok: boolean, installed?: Array, skipped?: Array, error?: Object }>}
|
|
78
|
-
*/
|
|
79
|
-
export async function installSkillsFromClawdHub({
|
|
80
|
-
scope,
|
|
81
|
-
targetSource,
|
|
82
|
-
workingDirectory,
|
|
83
|
-
userSkillDir,
|
|
84
|
-
selections,
|
|
85
|
-
conflictPolicy,
|
|
86
|
-
conflictDecisions,
|
|
87
|
-
} = {}) {
|
|
88
|
-
if (scope !== 'user' && scope !== 'project') {
|
|
89
|
-
return { ok: false, error: { kind: 'invalidSource', message: 'Invalid scope' } };
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (targetSource !== undefined && targetSource !== 'opencode' && targetSource !== 'agents') {
|
|
93
|
-
return { ok: false, error: { kind: 'invalidSource', message: 'Invalid target source' } };
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (!userSkillDir) {
|
|
97
|
-
return { ok: false, error: { kind: 'unknown', message: 'userSkillDir is required' } };
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const normalizedUserSkillDir = normalizeUserSkillDir(userSkillDir);
|
|
101
|
-
if (normalizedUserSkillDir) {
|
|
102
|
-
userSkillDir = normalizedUserSkillDir;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (scope === 'project' && !workingDirectory) {
|
|
106
|
-
return { ok: false, error: { kind: 'invalidSource', message: 'Project installs require a directory parameter' } };
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const requestedSkills = Array.isArray(selections) ? selections : [];
|
|
110
|
-
if (requestedSkills.length === 0) {
|
|
111
|
-
return { ok: false, error: { kind: 'invalidSource', message: 'No skills selected for installation' } };
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Build installation plans
|
|
115
|
-
const skillPlans = requestedSkills.map((sel) => {
|
|
116
|
-
const slug = sel.clawdhub?.slug || sel.skillDir;
|
|
117
|
-
const version = sel.clawdhub?.version || 'latest';
|
|
118
|
-
return {
|
|
119
|
-
slug,
|
|
120
|
-
version,
|
|
121
|
-
installable: validateSkillName(slug),
|
|
122
|
-
};
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
// Check for conflicts before downloading
|
|
126
|
-
const conflicts = [];
|
|
127
|
-
for (const plan of skillPlans) {
|
|
128
|
-
if (!plan.installable) {
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const targetDir = getTargetSkillDir({ scope, targetSource, workingDirectory, userSkillDir, skillName: plan.slug });
|
|
133
|
-
if (fs.existsSync(targetDir)) {
|
|
134
|
-
const decision = conflictDecisions?.[plan.slug];
|
|
135
|
-
const hasAutoPolicy = conflictPolicy === 'skipAll' || conflictPolicy === 'overwriteAll';
|
|
136
|
-
if (!decision && !hasAutoPolicy) {
|
|
137
|
-
conflicts.push({ skillName: plan.slug, scope, source: targetSource === 'agents' ? 'agents' : 'opencode' });
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (conflicts.length > 0) {
|
|
143
|
-
return {
|
|
144
|
-
ok: false,
|
|
145
|
-
error: {
|
|
146
|
-
kind: 'conflicts',
|
|
147
|
-
message: 'Some skills already exist in the selected scope',
|
|
148
|
-
conflicts,
|
|
149
|
-
},
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const installed = [];
|
|
154
|
-
const skipped = [];
|
|
155
|
-
|
|
156
|
-
for (const plan of skillPlans) {
|
|
157
|
-
if (!plan.installable) {
|
|
158
|
-
skipped.push({ skillName: plan.slug, reason: 'Invalid skill name' });
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
try {
|
|
163
|
-
// Resolve 'latest' version if needed
|
|
164
|
-
let resolvedVersion = plan.version;
|
|
165
|
-
if (resolvedVersion === 'latest') {
|
|
166
|
-
try {
|
|
167
|
-
const info = await fetchClawdHubSkillInfo(plan.slug);
|
|
168
|
-
const latest = info.skill?.tags?.latest || info.latestVersion?.version || null;
|
|
169
|
-
if (latest) {
|
|
170
|
-
resolvedVersion = latest;
|
|
171
|
-
}
|
|
172
|
-
} catch {
|
|
173
|
-
// ignore
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (resolvedVersion === 'latest') {
|
|
177
|
-
skipped.push({ skillName: plan.slug, reason: 'Unable to resolve latest version' });
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const targetDir = getTargetSkillDir({ scope, targetSource, workingDirectory, userSkillDir, skillName: plan.slug });
|
|
183
|
-
const exists = fs.existsSync(targetDir);
|
|
184
|
-
|
|
185
|
-
// Determine conflict resolution
|
|
186
|
-
let decision = conflictDecisions?.[plan.slug] || null;
|
|
187
|
-
if (!decision) {
|
|
188
|
-
if (exists && conflictPolicy === 'skipAll') decision = 'skip';
|
|
189
|
-
if (exists && conflictPolicy === 'overwriteAll') decision = 'overwrite';
|
|
190
|
-
if (!exists) decision = 'overwrite'; // No conflict, proceed
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (exists && decision === 'skip') {
|
|
194
|
-
skipped.push({ skillName: plan.slug, reason: 'Already installed (skipped)' });
|
|
195
|
-
continue;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (exists && decision === 'overwrite') {
|
|
199
|
-
await safeRm(targetDir);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Download the skill ZIP
|
|
203
|
-
const zipBuffer = await downloadClawdHubSkill(plan.slug, resolvedVersion);
|
|
204
|
-
|
|
205
|
-
// Extract to a temp directory first for validation
|
|
206
|
-
const tempDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), `clawdhub-${plan.slug}-`));
|
|
207
|
-
|
|
208
|
-
try {
|
|
209
|
-
const zip = new AdmZip(Buffer.from(zipBuffer));
|
|
210
|
-
zip.extractAllTo(tempDir, true);
|
|
211
|
-
|
|
212
|
-
// Verify SKILL.md exists
|
|
213
|
-
const skillMdPath = path.join(tempDir, 'SKILL.md');
|
|
214
|
-
if (!fs.existsSync(skillMdPath)) {
|
|
215
|
-
skipped.push({ skillName: plan.slug, reason: 'SKILL.md not found in downloaded package' });
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Move to target directory
|
|
220
|
-
await ensureDir(path.dirname(targetDir));
|
|
221
|
-
await fs.promises.rename(tempDir, targetDir);
|
|
222
|
-
|
|
223
|
-
installed.push({ skillName: plan.slug, scope, source: targetSource === 'agents' ? 'agents' : 'opencode' });
|
|
224
|
-
} catch (extractError) {
|
|
225
|
-
await safeRm(tempDir);
|
|
226
|
-
throw extractError;
|
|
227
|
-
}
|
|
228
|
-
} catch (error) {
|
|
229
|
-
console.error(`Failed to install ClawdHub skill "${plan.slug}":`, error);
|
|
230
|
-
skipped.push({
|
|
231
|
-
skillName: plan.slug,
|
|
232
|
-
reason: error instanceof Error ? error.message : 'Failed to download or extract skill',
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return { ok: true, installed, skipped };
|
|
238
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import os from 'node:os';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import AdmZip from 'adm-zip';
|
|
6
|
-
|
|
7
|
-
// Mock the ClawdHub network client so no real HTTP happens. The download
|
|
8
|
-
// function is what feeds the ZIP buffer into adm-zip inside install.js.
|
|
9
|
-
vi.mock('./api.js', () => ({
|
|
10
|
-
downloadClawdHubSkill: vi.fn(),
|
|
11
|
-
fetchClawdHubSkillInfo: vi.fn(),
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
const { downloadClawdHubSkill } = await import('./api.js');
|
|
15
|
-
const { installSkillsFromClawdHub } = await import('./install.js');
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Build a real ZIP archive with adm-zip (the dependency under test).
|
|
19
|
-
* Returns the raw Buffer, mirroring what downloadClawdHubSkill resolves to.
|
|
20
|
-
*/
|
|
21
|
-
function buildSkillZip(entries) {
|
|
22
|
-
const zip = new AdmZip();
|
|
23
|
-
for (const [entryName, content] of Object.entries(entries)) {
|
|
24
|
-
zip.addFile(entryName, Buffer.from(content, 'utf8'));
|
|
25
|
-
}
|
|
26
|
-
return zip.toBuffer();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
describe('installSkillsFromClawdHub (adm-zip extraction path)', () => {
|
|
30
|
-
let userSkillDir;
|
|
31
|
-
|
|
32
|
-
beforeEach(async () => {
|
|
33
|
-
// Keep the target dir under os.tmpdir() so the temp->target rename in
|
|
34
|
-
// install.js stays on one filesystem (avoids EXDEV cross-device errors).
|
|
35
|
-
userSkillDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'clawdhub-test-skills-'));
|
|
36
|
-
vi.clearAllMocks();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
afterEach(async () => {
|
|
40
|
-
await fs.promises.rm(userSkillDir, { recursive: true, force: true }).catch(() => {});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('extracts a real ZIP (incl. nested subdirectories) into the target skill dir', async () => {
|
|
44
|
-
const skillMd = 'name: demo-skill\ndescription: adm-zip extraction regression guard\n';
|
|
45
|
-
const nested = 'nested file content for subdirectory extraction check\n';
|
|
46
|
-
downloadClawdHubSkill.mockResolvedValue(
|
|
47
|
-
buildSkillZip({ 'SKILL.md': skillMd, 'nested/data.txt': nested }),
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const result = await installSkillsFromClawdHub({
|
|
51
|
-
scope: 'user',
|
|
52
|
-
targetSource: 'opencode',
|
|
53
|
-
userSkillDir,
|
|
54
|
-
// Non-'latest' version avoids the fetchClawdHubSkillInfo resolve branch.
|
|
55
|
-
selections: [{ clawdhub: { slug: 'demo-skill', version: '1.0.0' } }],
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
expect(result.ok).toBe(true);
|
|
59
|
-
expect(result.installed).toEqual([
|
|
60
|
-
{ skillName: 'demo-skill', scope: 'user', source: 'opencode' },
|
|
61
|
-
]);
|
|
62
|
-
expect(result.skipped).toEqual([]);
|
|
63
|
-
|
|
64
|
-
// downloadClawdHubSkill received the resolved (non-latest) version.
|
|
65
|
-
expect(downloadClawdHubSkill).toHaveBeenCalledWith('demo-skill', '1.0.0');
|
|
66
|
-
|
|
67
|
-
// adm-zip actually wrote the files, preserving the nested subdirectory.
|
|
68
|
-
const targetDir = path.join(userSkillDir, 'demo-skill');
|
|
69
|
-
const skillMdPath = path.join(targetDir, 'SKILL.md');
|
|
70
|
-
const nestedPath = path.join(targetDir, 'nested', 'data.txt');
|
|
71
|
-
|
|
72
|
-
expect(fs.existsSync(skillMdPath)).toBe(true);
|
|
73
|
-
expect(fs.existsSync(nestedPath)).toBe(true);
|
|
74
|
-
expect(fs.readFileSync(skillMdPath, 'utf8')).toBe(skillMd);
|
|
75
|
-
expect(fs.readFileSync(nestedPath, 'utf8')).toBe(nested);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('skips a package whose extracted contents lack SKILL.md', async () => {
|
|
79
|
-
// Valid ZIP, but no SKILL.md at the root -> install.js must skip it and
|
|
80
|
-
// must NOT create the target dir. This exercises the extractAllTo path
|
|
81
|
-
// followed by the post-extraction validation.
|
|
82
|
-
downloadClawdHubSkill.mockResolvedValue(
|
|
83
|
-
buildSkillZip({ 'README.md': 'no skill manifest here\n' }),
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
const result = await installSkillsFromClawdHub({
|
|
87
|
-
scope: 'user',
|
|
88
|
-
targetSource: 'opencode',
|
|
89
|
-
userSkillDir,
|
|
90
|
-
selections: [{ clawdhub: { slug: 'broken-skill', version: '1.0.0' } }],
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
expect(result.ok).toBe(true);
|
|
94
|
-
expect(result.installed).toEqual([]);
|
|
95
|
-
expect(result.skipped).toEqual([
|
|
96
|
-
{ skillName: 'broken-skill', reason: 'SKILL.md not found in downloaded package' },
|
|
97
|
-
]);
|
|
98
|
-
expect(fs.existsSync(path.join(userSkillDir, 'broken-skill'))).toBe(false);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ClawdHub skill scanning
|
|
3
|
-
*
|
|
4
|
-
* Fetches all available skills from the ClawdHub registry
|
|
5
|
-
* and transforms them into SkillsCatalogItem format.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { fetchClawdHubSkills } from './api.js';
|
|
9
|
-
|
|
10
|
-
const CLAWDHUB_PAGE_LIMIT = 25;
|
|
11
|
-
|
|
12
|
-
const mapClawdHubItem = (item) => {
|
|
13
|
-
const latestVersion = item.tags?.latest || item.latestVersion?.version || '1.0.0';
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
sourceId: 'clawdhub',
|
|
17
|
-
repoSource: 'clawdhub:registry',
|
|
18
|
-
repoSubpath: null,
|
|
19
|
-
gitIdentityId: null,
|
|
20
|
-
skillDir: item.slug,
|
|
21
|
-
skillName: item.slug,
|
|
22
|
-
frontmatterName: item.displayName || item.slug,
|
|
23
|
-
description: item.summary || null,
|
|
24
|
-
installable: true,
|
|
25
|
-
warnings: [],
|
|
26
|
-
// ClawdHub-specific metadata
|
|
27
|
-
clawdhub: {
|
|
28
|
-
slug: item.slug,
|
|
29
|
-
version: latestVersion,
|
|
30
|
-
displayName: item.displayName,
|
|
31
|
-
owner: item.owner?.handle || null,
|
|
32
|
-
downloads: item.stats?.downloads || 0,
|
|
33
|
-
stars: item.stats?.stars || 0,
|
|
34
|
-
versionsCount: item.stats?.versions || 1,
|
|
35
|
-
createdAt: item.createdAt,
|
|
36
|
-
updatedAt: item.updatedAt,
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Scan a single ClawdHub page (cursor-based)
|
|
43
|
-
* @returns {Promise<{ ok: boolean, items?: Array, nextCursor?: string | null, error?: Object }>}
|
|
44
|
-
*/
|
|
45
|
-
export async function scanClawdHubPage({ cursor } = {}) {
|
|
46
|
-
try {
|
|
47
|
-
const { items, nextCursor } = await fetchClawdHubSkills({ cursor });
|
|
48
|
-
const mapped = (items || []).map(mapClawdHubItem).slice(0, CLAWDHUB_PAGE_LIMIT);
|
|
49
|
-
mapped.sort((a, b) => (b.clawdhub?.downloads || 0) - (a.clawdhub?.downloads || 0));
|
|
50
|
-
return { ok: true, items: mapped, nextCursor: nextCursor || null };
|
|
51
|
-
} catch (error) {
|
|
52
|
-
console.error('ClawdHub page scan error:', error);
|
|
53
|
-
return {
|
|
54
|
-
ok: false,
|
|
55
|
-
error: {
|
|
56
|
-
kind: 'networkError',
|
|
57
|
-
message: error instanceof Error ? error.message : 'Failed to fetch skills from ClawdHub',
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|