@venturewild/workspace 0.6.0 → 0.6.2
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 -21
- package/README.md +112 -112
- package/package.json +85 -85
- package/server/bin/wild-workspace.mjs +1096 -1096
- package/server/src/account.mjs +114 -114
- package/server/src/agent-login.mjs +146 -146
- package/server/src/agent-readiness.mjs +200 -200
- package/server/src/agent.mjs +468 -468
- package/server/src/bazaar/core.mjs +974 -974
- package/server/src/bazaar/index.mjs +88 -88
- package/server/src/bazaar/mcp-server.mjs +429 -429
- package/server/src/bazaar/mock-tickup.mjs +97 -97
- package/server/src/bazaar/preview-server.mjs +95 -95
- package/server/src/bazaar/seed-recipes/customer-feedback-form/know-how.md +23 -23
- package/server/src/bazaar/seed-recipes/customer-feedback-form/recipe.json +24 -24
- package/server/src/bazaar/seed-recipes/landing-page-launch/know-how.md +29 -29
- package/server/src/bazaar/seed-recipes/landing-page-launch/recipe.json +25 -25
- package/server/src/bazaar/seed-recipes/personal-portfolio/know-how.md +21 -21
- package/server/src/bazaar/seed-recipes/personal-portfolio/recipe.json +24 -24
- package/server/src/bazaar/seed-recipes/receipt-sorter/know-how.md +31 -31
- package/server/src/bazaar/seed-recipes/receipt-sorter/recipe.json +25 -25
- package/server/src/bazaar/seed-recipes/tickup-hr-matching/know-how.md +79 -79
- package/server/src/bazaar/seed-recipes/tickup-hr-matching/recipe.json +40 -40
- package/server/src/canvas/core.mjs +446 -446
- package/server/src/canvas/index.mjs +42 -42
- package/server/src/canvas/mcp-server.mjs +253 -253
- package/server/src/canvas-rails.mjs +108 -108
- package/server/src/config.mjs +404 -404
- package/server/src/daemon-bin.mjs +110 -110
- package/server/src/daemon-supervisor.mjs +285 -285
- package/server/src/doctor.mjs +375 -375
- package/server/src/inbox.mjs +86 -86
- package/server/src/index.mjs +3332 -3322
- package/server/src/listings-rails.mjs +156 -156
- package/server/src/logpaths.mjs +98 -98
- package/server/src/observability.mjs +45 -45
- package/server/src/operator.mjs +92 -92
- package/server/src/pairing.mjs +137 -137
- package/server/src/service.mjs +515 -515
- package/server/src/session-reporter.mjs +201 -201
- package/server/src/settings.mjs +145 -145
- package/server/src/share.mjs +182 -182
- package/server/src/skills.mjs +213 -213
- package/server/src/supervisor.mjs +647 -647
- package/server/src/support-consent.mjs +133 -133
- package/server/src/sync.mjs +248 -248
- package/server/src/transcript.mjs +121 -121
- package/server/src/turn-mcp.mjs +46 -46
- package/server/src/usage.mjs +405 -405
- package/server/src/workspace-registry.mjs +295 -295
- package/server/src/workspaces.mjs +145 -145
- package/web/dist/assets/index-BgFan7ls.js +131 -0
- package/web/dist/assets/index-DHts78rO.css +32 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-CSWkWdtM.js +0 -131
- package/web/dist/assets/index-CzUrGoMW.css +0 -32
package/server/src/skills.mjs
CHANGED
|
@@ -1,213 +1,213 @@
|
|
|
1
|
-
// Skill discovery + the Powers-block curation store (§7/§8). There is NO native
|
|
2
|
-
// "list commands" API in Claude Code, so we discover the user's skills the cleanest
|
|
3
|
-
// way the design settled on: SCAN the skill directories and parse YAML frontmatter.
|
|
4
|
-
//
|
|
5
|
-
// - project skills: <workspace>/.claude/skills/<name>/SKILL.md
|
|
6
|
-
// - project commands: <workspace>/.claude/commands/<name>.md
|
|
7
|
-
// - user skills: ~/.claude/skills/<name>/SKILL.md
|
|
8
|
-
//
|
|
9
|
-
// Precedence (per §2): project > user. The Powers block is USER-CURATED — we surface
|
|
10
|
-
// what the user has (their own + a teammate's, both trusted by membership) with NO
|
|
11
|
-
// VW-prescribed core forced. The "─ from Bazaar ─" zone stays empty/LOCKED until the
|
|
12
|
-
// Shelf trust/provenance Class-D gate ships (a tap runs third-party instructions with
|
|
13
|
-
// bypassPermissions), so this module never returns Bazaar skills.
|
|
14
|
-
//
|
|
15
|
-
// Invocation is NOT done here: a Powers tap injects `/<name>` as a chat message, which
|
|
16
|
-
// Claude Code expands+runs headless (verified §2) — the same stdin path we already use.
|
|
17
|
-
//
|
|
18
|
-
// Curation (which skills are pinned/hidden + their order) lives under
|
|
19
|
-
// ~/.wild-workspace/powers/ (CLAUDE.md #1 — never the synced repo, never localStorage).
|
|
20
|
-
|
|
21
|
-
import fs from 'node:fs';
|
|
22
|
-
import path from 'node:path';
|
|
23
|
-
import os from 'node:os';
|
|
24
|
-
|
|
25
|
-
// Bounds so a workspace stuffed with skills can't bloat the store/UI.
|
|
26
|
-
const CAP = { skills: 80, name: 64, desc: 280 };
|
|
27
|
-
|
|
28
|
-
// --- frontmatter parse -----------------------------------------------------
|
|
29
|
-
// Minimal, dependency-free. We only need a few scalar keys; the description often
|
|
30
|
-
// CONTAINS colons ("Usage: /foo"), so we split on the FIRST colon only. Never throws.
|
|
31
|
-
|
|
32
|
-
export function parseFrontmatter(text = '') {
|
|
33
|
-
const out = {};
|
|
34
|
-
if (typeof text !== 'string') return out;
|
|
35
|
-
// Frontmatter is the block between the first two `---` fences at the top.
|
|
36
|
-
const m = text.match(/^?---\s*\r?\n([\s\S]*?)\r?\n---/);
|
|
37
|
-
if (!m) return out;
|
|
38
|
-
for (const rawLine of m[1].split(/\r?\n/)) {
|
|
39
|
-
const line = rawLine.trim();
|
|
40
|
-
if (!line || line.startsWith('#')) continue;
|
|
41
|
-
const i = line.indexOf(':');
|
|
42
|
-
if (i < 0) continue;
|
|
43
|
-
const key = line.slice(0, i).trim();
|
|
44
|
-
let val = line.slice(i + 1).trim();
|
|
45
|
-
// strip matching surrounding quotes
|
|
46
|
-
if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
|
|
47
|
-
val = val.slice(1, -1);
|
|
48
|
-
}
|
|
49
|
-
out[key] = val;
|
|
50
|
-
}
|
|
51
|
-
return out;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function asBool(v, dflt) {
|
|
55
|
-
if (v === undefined) return dflt;
|
|
56
|
-
const s = String(v).trim().toLowerCase();
|
|
57
|
-
if (s === 'true' || s === 'yes' || s === '1') return true;
|
|
58
|
-
if (s === 'false' || s === 'no' || s === '0') return false;
|
|
59
|
-
return dflt;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function clip(s, n) {
|
|
63
|
-
return String(s || '').slice(0, n);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Build one skill record from a parsed frontmatter + its fallback name.
|
|
67
|
-
function toSkill(fm, fallbackName, source) {
|
|
68
|
-
const name = clip(fm.name || fallbackName, CAP.name).trim();
|
|
69
|
-
if (!name) return null;
|
|
70
|
-
return {
|
|
71
|
-
name,
|
|
72
|
-
description: clip(fm.description || '', CAP.desc).trim(),
|
|
73
|
-
source, // 'project' | 'user'
|
|
74
|
-
// user-invocable defaults TRUE (most skills can be run as /name); only an explicit
|
|
75
|
-
// `user-invocable: false` opts out of being a tappable Power.
|
|
76
|
-
userInvocable: asBool(fm['user-invocable'], true),
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function readFileSafe(file) {
|
|
81
|
-
try { return fs.readFileSync(file, 'utf8'); } catch { return null; }
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function listDirs(dir) {
|
|
85
|
-
try {
|
|
86
|
-
return fs.readdirSync(dir, { withFileTypes: true })
|
|
87
|
-
.filter((e) => e.isDirectory())
|
|
88
|
-
.map((e) => e.name);
|
|
89
|
-
} catch { return []; }
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function listFiles(dir, ext) {
|
|
93
|
-
try {
|
|
94
|
-
return fs.readdirSync(dir, { withFileTypes: true })
|
|
95
|
-
.filter((e) => e.isFile() && e.name.endsWith(ext))
|
|
96
|
-
.map((e) => e.name);
|
|
97
|
-
} catch { return []; }
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Scan one skills root (<root>/<name>/SKILL.md) → skill records.
|
|
101
|
-
function scanSkillsRoot(root, source) {
|
|
102
|
-
const out = [];
|
|
103
|
-
for (const name of listDirs(root)) {
|
|
104
|
-
const text = readFileSafe(path.join(root, name, 'SKILL.md'));
|
|
105
|
-
if (text == null) continue;
|
|
106
|
-
const s = toSkill(parseFrontmatter(text), name, source);
|
|
107
|
-
if (s) out.push(s);
|
|
108
|
-
}
|
|
109
|
-
return out;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Scan a commands root (<root>/<name>.md) → skill records.
|
|
113
|
-
function scanCommandsRoot(root, source) {
|
|
114
|
-
const out = [];
|
|
115
|
-
for (const file of listFiles(root, '.md')) {
|
|
116
|
-
const text = readFileSafe(path.join(root, file));
|
|
117
|
-
if (text == null) continue;
|
|
118
|
-
const s = toSkill(parseFrontmatter(text), file.replace(/\.md$/, ''), source);
|
|
119
|
-
if (s) out.push(s);
|
|
120
|
-
}
|
|
121
|
-
return out;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Discover the workspace's skills. Project entries take precedence over same-named
|
|
126
|
-
* user entries (§2). Returns ONLY user-invocable skills (the Powers block taps run
|
|
127
|
-
* them as /name), capped. Never throws — a missing dir just yields fewer skills.
|
|
128
|
-
*/
|
|
129
|
-
export function discoverSkills({ workspaceDir = process.cwd(), home = os.homedir() } = {}) {
|
|
130
|
-
const project = [
|
|
131
|
-
...scanSkillsRoot(path.join(workspaceDir, '.claude', 'skills'), 'project'),
|
|
132
|
-
...scanCommandsRoot(path.join(workspaceDir, '.claude', 'commands'), 'project'),
|
|
133
|
-
];
|
|
134
|
-
const user = scanSkillsRoot(path.join(home, '.claude', 'skills'), 'user');
|
|
135
|
-
|
|
136
|
-
// Dedup by name, project wins.
|
|
137
|
-
const byName = new Map();
|
|
138
|
-
for (const s of user) byName.set(s.name, s);
|
|
139
|
-
for (const s of project) byName.set(s.name, s); // overrides user
|
|
140
|
-
return [...byName.values()]
|
|
141
|
-
.filter((s) => s.userInvocable)
|
|
142
|
-
.sort((a, b) => a.name.localeCompare(b.name))
|
|
143
|
-
.slice(0, CAP.skills);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// --- curation store --------------------------------------------------------
|
|
147
|
-
// The user's arrangement: `order` (pinned, in display order) + `hidden` (subtracted).
|
|
148
|
-
// A discovered skill not in either is shown after the pinned ones (so a NEW skill
|
|
149
|
-
// appears without the user having to add it — "add/subtract/arrange", subtract is opt-in).
|
|
150
|
-
|
|
151
|
-
export function defaultPowersDir(env = process.env, home = os.homedir()) {
|
|
152
|
-
const base = env.WILD_WORKSPACE_GLOBAL_DIR || path.join(home, '.wild-workspace');
|
|
153
|
-
return path.join(base, 'powers');
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function readJsonSafe(file, fallback) {
|
|
157
|
-
try { return JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return fallback; }
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export function createPowers({ baseDir, workspaceDir, home = os.homedir(), env = process.env } = {}) {
|
|
161
|
-
const dir = baseDir || defaultPowersDir(env, home);
|
|
162
|
-
const curationFile = path.join(dir, 'curation.json');
|
|
163
|
-
|
|
164
|
-
function getCuration() {
|
|
165
|
-
const v = readJsonSafe(curationFile, null);
|
|
166
|
-
const order = Array.isArray(v?.order) ? v.order.filter((s) => typeof s === 'string') : [];
|
|
167
|
-
const hidden = Array.isArray(v?.hidden) ? v.hidden.filter((s) => typeof s === 'string') : [];
|
|
168
|
-
return { order, hidden };
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function saveCuration(raw = {}) {
|
|
172
|
-
const order = Array.isArray(raw.order)
|
|
173
|
-
? [...new Set(raw.order.filter((s) => typeof s === 'string').map((s) => s.slice(0, CAP.name)))].slice(0, CAP.skills)
|
|
174
|
-
: [];
|
|
175
|
-
const hidden = Array.isArray(raw.hidden)
|
|
176
|
-
? [...new Set(raw.hidden.filter((s) => typeof s === 'string').map((s) => s.slice(0, CAP.name)))].slice(0, CAP.skills)
|
|
177
|
-
: [];
|
|
178
|
-
const data = { order, hidden, ts: Date.now() };
|
|
179
|
-
try {
|
|
180
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
181
|
-
const tmp = `${curationFile}.${process.pid}.tmp`;
|
|
182
|
-
fs.writeFileSync(tmp, JSON.stringify(data, null, 2));
|
|
183
|
-
fs.renameSync(tmp, curationFile);
|
|
184
|
-
} catch { /* read-only fs — degrade to not-persisted */ }
|
|
185
|
-
return data;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// The merged view the UI renders: discovered skills, ordered by curation, with a
|
|
189
|
-
// `hidden` flag. Pinned (in `order`) first, then the rest alphabetically.
|
|
190
|
-
function state() {
|
|
191
|
-
const discovered = discoverSkills({ workspaceDir, home });
|
|
192
|
-
const { order, hidden } = getCuration();
|
|
193
|
-
const hiddenSet = new Set(hidden);
|
|
194
|
-
const rank = new Map(order.map((n, i) => [n, i]));
|
|
195
|
-
const skills = discovered
|
|
196
|
-
.map((s) => ({ ...s, hidden: hiddenSet.has(s.name) }))
|
|
197
|
-
.sort((a, b) => {
|
|
198
|
-
const ra = rank.has(a.name) ? rank.get(a.name) : Infinity;
|
|
199
|
-
const rb = rank.has(b.name) ? rank.get(b.name) : Infinity;
|
|
200
|
-
if (ra !== rb) return ra - rb;
|
|
201
|
-
return a.name.localeCompare(b.name);
|
|
202
|
-
});
|
|
203
|
-
return {
|
|
204
|
-
skills,
|
|
205
|
-
curation: { order, hidden },
|
|
206
|
-
// The marketplace zone is specified but GATED (Class-D, not built) — always
|
|
207
|
-
// empty + locked here so the UI can render the "─ from Bazaar ─" boundary.
|
|
208
|
-
bazaar: { locked: true, skills: [] },
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return { dir, curationFile, getCuration, saveCuration, state };
|
|
213
|
-
}
|
|
1
|
+
// Skill discovery + the Powers-block curation store (§7/§8). There is NO native
|
|
2
|
+
// "list commands" API in Claude Code, so we discover the user's skills the cleanest
|
|
3
|
+
// way the design settled on: SCAN the skill directories and parse YAML frontmatter.
|
|
4
|
+
//
|
|
5
|
+
// - project skills: <workspace>/.claude/skills/<name>/SKILL.md
|
|
6
|
+
// - project commands: <workspace>/.claude/commands/<name>.md
|
|
7
|
+
// - user skills: ~/.claude/skills/<name>/SKILL.md
|
|
8
|
+
//
|
|
9
|
+
// Precedence (per §2): project > user. The Powers block is USER-CURATED — we surface
|
|
10
|
+
// what the user has (their own + a teammate's, both trusted by membership) with NO
|
|
11
|
+
// VW-prescribed core forced. The "─ from Bazaar ─" zone stays empty/LOCKED until the
|
|
12
|
+
// Shelf trust/provenance Class-D gate ships (a tap runs third-party instructions with
|
|
13
|
+
// bypassPermissions), so this module never returns Bazaar skills.
|
|
14
|
+
//
|
|
15
|
+
// Invocation is NOT done here: a Powers tap injects `/<name>` as a chat message, which
|
|
16
|
+
// Claude Code expands+runs headless (verified §2) — the same stdin path we already use.
|
|
17
|
+
//
|
|
18
|
+
// Curation (which skills are pinned/hidden + their order) lives under
|
|
19
|
+
// ~/.wild-workspace/powers/ (CLAUDE.md #1 — never the synced repo, never localStorage).
|
|
20
|
+
|
|
21
|
+
import fs from 'node:fs';
|
|
22
|
+
import path from 'node:path';
|
|
23
|
+
import os from 'node:os';
|
|
24
|
+
|
|
25
|
+
// Bounds so a workspace stuffed with skills can't bloat the store/UI.
|
|
26
|
+
const CAP = { skills: 80, name: 64, desc: 280 };
|
|
27
|
+
|
|
28
|
+
// --- frontmatter parse -----------------------------------------------------
|
|
29
|
+
// Minimal, dependency-free. We only need a few scalar keys; the description often
|
|
30
|
+
// CONTAINS colons ("Usage: /foo"), so we split on the FIRST colon only. Never throws.
|
|
31
|
+
|
|
32
|
+
export function parseFrontmatter(text = '') {
|
|
33
|
+
const out = {};
|
|
34
|
+
if (typeof text !== 'string') return out;
|
|
35
|
+
// Frontmatter is the block between the first two `---` fences at the top.
|
|
36
|
+
const m = text.match(/^?---\s*\r?\n([\s\S]*?)\r?\n---/);
|
|
37
|
+
if (!m) return out;
|
|
38
|
+
for (const rawLine of m[1].split(/\r?\n/)) {
|
|
39
|
+
const line = rawLine.trim();
|
|
40
|
+
if (!line || line.startsWith('#')) continue;
|
|
41
|
+
const i = line.indexOf(':');
|
|
42
|
+
if (i < 0) continue;
|
|
43
|
+
const key = line.slice(0, i).trim();
|
|
44
|
+
let val = line.slice(i + 1).trim();
|
|
45
|
+
// strip matching surrounding quotes
|
|
46
|
+
if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
|
|
47
|
+
val = val.slice(1, -1);
|
|
48
|
+
}
|
|
49
|
+
out[key] = val;
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function asBool(v, dflt) {
|
|
55
|
+
if (v === undefined) return dflt;
|
|
56
|
+
const s = String(v).trim().toLowerCase();
|
|
57
|
+
if (s === 'true' || s === 'yes' || s === '1') return true;
|
|
58
|
+
if (s === 'false' || s === 'no' || s === '0') return false;
|
|
59
|
+
return dflt;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function clip(s, n) {
|
|
63
|
+
return String(s || '').slice(0, n);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Build one skill record from a parsed frontmatter + its fallback name.
|
|
67
|
+
function toSkill(fm, fallbackName, source) {
|
|
68
|
+
const name = clip(fm.name || fallbackName, CAP.name).trim();
|
|
69
|
+
if (!name) return null;
|
|
70
|
+
return {
|
|
71
|
+
name,
|
|
72
|
+
description: clip(fm.description || '', CAP.desc).trim(),
|
|
73
|
+
source, // 'project' | 'user'
|
|
74
|
+
// user-invocable defaults TRUE (most skills can be run as /name); only an explicit
|
|
75
|
+
// `user-invocable: false` opts out of being a tappable Power.
|
|
76
|
+
userInvocable: asBool(fm['user-invocable'], true),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function readFileSafe(file) {
|
|
81
|
+
try { return fs.readFileSync(file, 'utf8'); } catch { return null; }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function listDirs(dir) {
|
|
85
|
+
try {
|
|
86
|
+
return fs.readdirSync(dir, { withFileTypes: true })
|
|
87
|
+
.filter((e) => e.isDirectory())
|
|
88
|
+
.map((e) => e.name);
|
|
89
|
+
} catch { return []; }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function listFiles(dir, ext) {
|
|
93
|
+
try {
|
|
94
|
+
return fs.readdirSync(dir, { withFileTypes: true })
|
|
95
|
+
.filter((e) => e.isFile() && e.name.endsWith(ext))
|
|
96
|
+
.map((e) => e.name);
|
|
97
|
+
} catch { return []; }
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Scan one skills root (<root>/<name>/SKILL.md) → skill records.
|
|
101
|
+
function scanSkillsRoot(root, source) {
|
|
102
|
+
const out = [];
|
|
103
|
+
for (const name of listDirs(root)) {
|
|
104
|
+
const text = readFileSafe(path.join(root, name, 'SKILL.md'));
|
|
105
|
+
if (text == null) continue;
|
|
106
|
+
const s = toSkill(parseFrontmatter(text), name, source);
|
|
107
|
+
if (s) out.push(s);
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Scan a commands root (<root>/<name>.md) → skill records.
|
|
113
|
+
function scanCommandsRoot(root, source) {
|
|
114
|
+
const out = [];
|
|
115
|
+
for (const file of listFiles(root, '.md')) {
|
|
116
|
+
const text = readFileSafe(path.join(root, file));
|
|
117
|
+
if (text == null) continue;
|
|
118
|
+
const s = toSkill(parseFrontmatter(text), file.replace(/\.md$/, ''), source);
|
|
119
|
+
if (s) out.push(s);
|
|
120
|
+
}
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Discover the workspace's skills. Project entries take precedence over same-named
|
|
126
|
+
* user entries (§2). Returns ONLY user-invocable skills (the Powers block taps run
|
|
127
|
+
* them as /name), capped. Never throws — a missing dir just yields fewer skills.
|
|
128
|
+
*/
|
|
129
|
+
export function discoverSkills({ workspaceDir = process.cwd(), home = os.homedir() } = {}) {
|
|
130
|
+
const project = [
|
|
131
|
+
...scanSkillsRoot(path.join(workspaceDir, '.claude', 'skills'), 'project'),
|
|
132
|
+
...scanCommandsRoot(path.join(workspaceDir, '.claude', 'commands'), 'project'),
|
|
133
|
+
];
|
|
134
|
+
const user = scanSkillsRoot(path.join(home, '.claude', 'skills'), 'user');
|
|
135
|
+
|
|
136
|
+
// Dedup by name, project wins.
|
|
137
|
+
const byName = new Map();
|
|
138
|
+
for (const s of user) byName.set(s.name, s);
|
|
139
|
+
for (const s of project) byName.set(s.name, s); // overrides user
|
|
140
|
+
return [...byName.values()]
|
|
141
|
+
.filter((s) => s.userInvocable)
|
|
142
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
143
|
+
.slice(0, CAP.skills);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// --- curation store --------------------------------------------------------
|
|
147
|
+
// The user's arrangement: `order` (pinned, in display order) + `hidden` (subtracted).
|
|
148
|
+
// A discovered skill not in either is shown after the pinned ones (so a NEW skill
|
|
149
|
+
// appears without the user having to add it — "add/subtract/arrange", subtract is opt-in).
|
|
150
|
+
|
|
151
|
+
export function defaultPowersDir(env = process.env, home = os.homedir()) {
|
|
152
|
+
const base = env.WILD_WORKSPACE_GLOBAL_DIR || path.join(home, '.wild-workspace');
|
|
153
|
+
return path.join(base, 'powers');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function readJsonSafe(file, fallback) {
|
|
157
|
+
try { return JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return fallback; }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function createPowers({ baseDir, workspaceDir, home = os.homedir(), env = process.env } = {}) {
|
|
161
|
+
const dir = baseDir || defaultPowersDir(env, home);
|
|
162
|
+
const curationFile = path.join(dir, 'curation.json');
|
|
163
|
+
|
|
164
|
+
function getCuration() {
|
|
165
|
+
const v = readJsonSafe(curationFile, null);
|
|
166
|
+
const order = Array.isArray(v?.order) ? v.order.filter((s) => typeof s === 'string') : [];
|
|
167
|
+
const hidden = Array.isArray(v?.hidden) ? v.hidden.filter((s) => typeof s === 'string') : [];
|
|
168
|
+
return { order, hidden };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function saveCuration(raw = {}) {
|
|
172
|
+
const order = Array.isArray(raw.order)
|
|
173
|
+
? [...new Set(raw.order.filter((s) => typeof s === 'string').map((s) => s.slice(0, CAP.name)))].slice(0, CAP.skills)
|
|
174
|
+
: [];
|
|
175
|
+
const hidden = Array.isArray(raw.hidden)
|
|
176
|
+
? [...new Set(raw.hidden.filter((s) => typeof s === 'string').map((s) => s.slice(0, CAP.name)))].slice(0, CAP.skills)
|
|
177
|
+
: [];
|
|
178
|
+
const data = { order, hidden, ts: Date.now() };
|
|
179
|
+
try {
|
|
180
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
181
|
+
const tmp = `${curationFile}.${process.pid}.tmp`;
|
|
182
|
+
fs.writeFileSync(tmp, JSON.stringify(data, null, 2));
|
|
183
|
+
fs.renameSync(tmp, curationFile);
|
|
184
|
+
} catch { /* read-only fs — degrade to not-persisted */ }
|
|
185
|
+
return data;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// The merged view the UI renders: discovered skills, ordered by curation, with a
|
|
189
|
+
// `hidden` flag. Pinned (in `order`) first, then the rest alphabetically.
|
|
190
|
+
function state() {
|
|
191
|
+
const discovered = discoverSkills({ workspaceDir, home });
|
|
192
|
+
const { order, hidden } = getCuration();
|
|
193
|
+
const hiddenSet = new Set(hidden);
|
|
194
|
+
const rank = new Map(order.map((n, i) => [n, i]));
|
|
195
|
+
const skills = discovered
|
|
196
|
+
.map((s) => ({ ...s, hidden: hiddenSet.has(s.name) }))
|
|
197
|
+
.sort((a, b) => {
|
|
198
|
+
const ra = rank.has(a.name) ? rank.get(a.name) : Infinity;
|
|
199
|
+
const rb = rank.has(b.name) ? rank.get(b.name) : Infinity;
|
|
200
|
+
if (ra !== rb) return ra - rb;
|
|
201
|
+
return a.name.localeCompare(b.name);
|
|
202
|
+
});
|
|
203
|
+
return {
|
|
204
|
+
skills,
|
|
205
|
+
curation: { order, hidden },
|
|
206
|
+
// The marketplace zone is specified but GATED (Class-D, not built) — always
|
|
207
|
+
// empty + locked here so the UI can render the "─ from Bazaar ─" boundary.
|
|
208
|
+
bazaar: { locked: true, skills: [] },
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return { dir, curationFile, getCuration, saveCuration, state };
|
|
213
|
+
}
|