@krisada-m/ksd-intelligence 0.0.0-stage → 1.0.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 +21 -0
- package/README.md +167 -2
- package/dist/adapters/agy/skills.js +252 -0
- package/dist/adapters/cli/check-changed.js +3 -0
- package/dist/adapters/cli/main.js +1002 -0
- package/dist/adapters/cli/policy-bin.js +10 -0
- package/dist/adapters/cli/review-verdict.js +3 -0
- package/dist/adapters/omp/extension.js +893 -0
- package/dist/adapters/omp/skills.js +130 -0
- package/dist/adapters/ui/hud.js +318 -0
- package/dist/adapters/ui/tree.js +460 -0
- package/dist/core/audit/index.js +2 -0
- package/dist/core/audit/log.js +505 -0
- package/dist/core/audit/summary.js +188 -0
- package/dist/core/changes/changes.js +591 -0
- package/dist/core/changes/git.js +266 -0
- package/dist/core/changes/plan.js +109 -0
- package/dist/core/changes/render.js +356 -0
- package/dist/core/engine/build.js +178 -0
- package/dist/core/engine/child.js +389 -0
- package/dist/core/engine/host.js +206 -0
- package/dist/core/engine/lock.js +133 -0
- package/dist/core/engine/protocol.js +43 -0
- package/dist/core/engine/runtime.js +44 -0
- package/dist/core/engine/status.js +381 -0
- package/dist/core/engine/typescript.js +194 -0
- package/dist/core/engine/workspace.js +72 -0
- package/dist/core/graph/graph.js +127 -0
- package/dist/core/graph/limits.js +16 -0
- package/dist/core/impact/query.js +1292 -0
- package/dist/core/impact/render.js +590 -0
- package/dist/core/impact/session.js +694 -0
- package/dist/core/indexing/declarations.js +455 -0
- package/dist/core/indexing/differential.js +345 -0
- package/dist/core/indexing/doctor.js +120 -0
- package/dist/core/indexing/indexer.js +792 -0
- package/dist/core/indexing/keys.js +451 -0
- package/dist/core/indexing/lexical.js +212 -0
- package/dist/core/indexing/packages.js +57 -0
- package/dist/core/indexing/program.js +171 -0
- package/dist/core/indexing/resolve.js +1004 -0
- package/dist/core/indexing/stamp.js +52 -0
- package/dist/core/indexing/surface.js +335 -0
- package/dist/core/indexing/ui-progress.js +37 -0
- package/dist/core/indexing/verify.js +76 -0
- package/dist/core/kernel/config.js +383 -0
- package/dist/core/kernel/glob.js +105 -0
- package/dist/core/kernel/guards.js +4 -0
- package/dist/core/kernel/types.js +3 -0
- package/dist/core/kernel/verdict.js +142 -0
- package/dist/core/knowledge/anchors.js +139 -0
- package/dist/core/knowledge/knowledge.js +95 -0
- package/dist/core/knowledge/learning.js +102 -0
- package/dist/core/knowledge/render.js +76 -0
- package/dist/core/knowledge/store.js +109 -0
- package/dist/core/knowledge/yaml.js +87 -0
- package/dist/core/search/lexical.js +382 -0
- package/dist/core/search/render.js +98 -0
- package/dist/core/search/segments.js +118 -0
- package/dist/core/verify/parse.js +127 -0
- package/dist/core/verify/render.js +67 -0
- package/dist/core/verify/report.js +40 -0
- package/dist/core/verify/revision.js +79 -0
- package/dist/core/verify/run.js +117 -0
- package/dist/core/verify/store.js +66 -0
- package/dist/core/verify/verify.js +173 -0
- package/dist/core/workspace/init.js +267 -0
- package/dist/core/workspace/probe.js +56 -0
- package/dist/core/workspace/scan.js +420 -0
- package/dist/index.js +20 -0
- package/dist/policy/change-scope.js +500 -0
- package/dist/policy/check-changed.js +40 -0
- package/dist/policy/config.js +106 -0
- package/dist/policy/dist/policy.d.ts +17 -0
- package/dist/policy/dist/policy.js +147 -0
- package/dist/policy/dist/runtime.d.ts +40 -0
- package/dist/policy/dist/runtime.js +75 -0
- package/dist/policy/dist/sdlc.d.ts +7 -0
- package/dist/policy/dist/sdlc.js +27 -0
- package/dist/policy/eslint-rules/index.js +107 -0
- package/dist/policy/index.d.ts +2 -0
- package/dist/policy/index.js +241 -0
- package/dist/policy/package.json +33 -0
- package/dist/policy/policy.d.ts +2 -0
- package/dist/policy/policy.js +2 -0
- package/dist/policy/review-verdict.js +262 -0
- package/dist/policy/sdlc.js +2 -0
- package/dist/storage/records.js +245 -0
- package/dist/storage/sqlite.js +314 -0
- package/dist/workflow/catalog.js +69 -0
- package/dist/workflow/classify.js +55 -0
- package/dist/workflow/loader.js +140 -0
- package/dist/workflow/packs.js +469 -0
- package/dist/workflow/registry.js +359 -0
- package/dist/workflow/render.js +61 -0
- package/dist/workflow/router.js +141 -0
- package/dist/workflow/sources.js +229 -0
- package/dist/workflow/types.js +44 -0
- package/dist/workflow/updates.js +532 -0
- package/package.json +74 -4
- package/scripts/agy-mcp.mjs +27 -0
- package/scripts/mcp/stdio.mjs +304 -0
- package/scripts/mcp/tools.mjs +451 -0
- package/skills/ksd-intelligence/SKILL.md +54 -0
- package/skills/matt-sdlc/SKILL.md +42 -0
- package/skills/osmani-quality/SKILL.md +38 -0
- package/skills/poteto-mode/SKILL.md +40 -0
- package/skills/pstack-analysis/SKILL.md +36 -0
- package/skills.lock.json +71 -0
- package/skills.registry.json +181 -0
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { readdir, readFile, realpath, stat } from 'node:fs/promises';
|
|
3
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { PROVIDERS } from './catalog.js';
|
|
6
|
+
import { CATALOG_SKILL_NAMES, ORCHESTRATOR_SKILL_ID, SKILL_PACK_IDS, } from './types.js';
|
|
7
|
+
export const SKILL_PACKS = {
|
|
8
|
+
'matt-sdlc': {
|
|
9
|
+
id: 'matt-sdlc',
|
|
10
|
+
owner: 'matt',
|
|
11
|
+
provider: 'matt',
|
|
12
|
+
summary: 'Requirements, specifications, TDD, implementation, debugging, and REQ compliance audit',
|
|
13
|
+
activation: 'auto',
|
|
14
|
+
disableModelInvocation: false,
|
|
15
|
+
skillFile: 'skills/matt-sdlc/SKILL.md',
|
|
16
|
+
primaryDomains: [
|
|
17
|
+
'requirements',
|
|
18
|
+
'specs',
|
|
19
|
+
'domain-modeling',
|
|
20
|
+
'tdd',
|
|
21
|
+
'implementation',
|
|
22
|
+
'debugging',
|
|
23
|
+
'req-audit',
|
|
24
|
+
],
|
|
25
|
+
allowlistedLeafSkills: [
|
|
26
|
+
'matt:diagnosing-bugs',
|
|
27
|
+
'matt:codebase-design',
|
|
28
|
+
'matt:tdd',
|
|
29
|
+
'matt:code-review',
|
|
30
|
+
],
|
|
31
|
+
upstream: {
|
|
32
|
+
repo: PROVIDERS.matt.repo,
|
|
33
|
+
rootSubpath: PROVIDERS.matt.rootSubpath,
|
|
34
|
+
license: 'MIT',
|
|
35
|
+
attribution: 'Matt Pocock',
|
|
36
|
+
skills: [
|
|
37
|
+
'grill-with-docs',
|
|
38
|
+
'to-spec',
|
|
39
|
+
'domain-modeling',
|
|
40
|
+
'implement',
|
|
41
|
+
'implement-spec',
|
|
42
|
+
'tdd',
|
|
43
|
+
'diagnosing-bugs',
|
|
44
|
+
'code-review',
|
|
45
|
+
'codebase-design',
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
'pstack-analysis': {
|
|
50
|
+
id: 'pstack-analysis',
|
|
51
|
+
owner: 'pstack',
|
|
52
|
+
provider: 'poteto',
|
|
53
|
+
summary: 'Architecture analysis, code investigation, root cause analysis, and blast radius',
|
|
54
|
+
activation: 'auto',
|
|
55
|
+
disableModelInvocation: false,
|
|
56
|
+
skillFile: 'skills/pstack-analysis/SKILL.md',
|
|
57
|
+
primaryDomains: [
|
|
58
|
+
'architecture',
|
|
59
|
+
'investigation',
|
|
60
|
+
'root-cause',
|
|
61
|
+
'blast-radius',
|
|
62
|
+
'alternatives',
|
|
63
|
+
'design-rationale',
|
|
64
|
+
],
|
|
65
|
+
allowlistedLeafSkills: ['poteto:how', 'poteto:why', 'poteto:blast-radius'],
|
|
66
|
+
upstream: {
|
|
67
|
+
repo: PROVIDERS.poteto.repo,
|
|
68
|
+
rootSubpath: PROVIDERS.poteto.rootSubpath,
|
|
69
|
+
license: 'MIT',
|
|
70
|
+
attribution: 'Lauren Tan (poteto / pstack)',
|
|
71
|
+
skills: [
|
|
72
|
+
'how',
|
|
73
|
+
'why',
|
|
74
|
+
'architect',
|
|
75
|
+
'arena',
|
|
76
|
+
'blast-radius',
|
|
77
|
+
'figure-it-out',
|
|
78
|
+
'interrogate',
|
|
79
|
+
'show-me-your-work',
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
'poteto-mode': {
|
|
84
|
+
id: 'poteto-mode',
|
|
85
|
+
owner: 'poteto',
|
|
86
|
+
provider: 'poteto',
|
|
87
|
+
summary: 'Explicit opt-in deep engineering mode for complex multi-phase workflows',
|
|
88
|
+
activation: 'opt-in',
|
|
89
|
+
disableModelInvocation: true,
|
|
90
|
+
skillFile: 'skills/poteto-mode/SKILL.md',
|
|
91
|
+
primaryDomains: ['deep-engineering', 'multi-phase-execution'],
|
|
92
|
+
// Never auto-routed into pinned leaf skills; activated only by explicit opt-in.
|
|
93
|
+
allowlistedLeafSkills: [],
|
|
94
|
+
upstream: {
|
|
95
|
+
repo: PROVIDERS.poteto.repo,
|
|
96
|
+
rootSubpath: PROVIDERS.poteto.rootSubpath,
|
|
97
|
+
license: 'MIT',
|
|
98
|
+
attribution: 'Lauren Tan (poteto / pstack)',
|
|
99
|
+
skills: ['poteto-mode'],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
'osmani-quality': {
|
|
103
|
+
id: 'osmani-quality',
|
|
104
|
+
owner: 'osmani',
|
|
105
|
+
provider: 'osmani',
|
|
106
|
+
summary: 'UI verification, security hardening, performance, quality gates, and release readiness',
|
|
107
|
+
activation: 'auto',
|
|
108
|
+
disableModelInvocation: false,
|
|
109
|
+
skillFile: 'skills/osmani-quality/SKILL.md',
|
|
110
|
+
primaryDomains: [
|
|
111
|
+
'ui-verification',
|
|
112
|
+
'accessibility',
|
|
113
|
+
'api-contracts',
|
|
114
|
+
'security',
|
|
115
|
+
'performance',
|
|
116
|
+
'observability',
|
|
117
|
+
'quality-gates',
|
|
118
|
+
'release',
|
|
119
|
+
],
|
|
120
|
+
allowlistedLeafSkills: [
|
|
121
|
+
'osmani:spec-driven-development',
|
|
122
|
+
'osmani:incremental-implementation',
|
|
123
|
+
'osmani:code-review-and-quality',
|
|
124
|
+
'osmani:security-and-hardening',
|
|
125
|
+
'osmani:performance-optimization',
|
|
126
|
+
'osmani:frontend-ui-engineering',
|
|
127
|
+
'osmani:browser-testing-with-devtools',
|
|
128
|
+
'osmani:shipping-and-launch',
|
|
129
|
+
],
|
|
130
|
+
upstream: {
|
|
131
|
+
repo: PROVIDERS.osmani.repo,
|
|
132
|
+
rootSubpath: PROVIDERS.osmani.rootSubpath,
|
|
133
|
+
license: 'MIT',
|
|
134
|
+
attribution: 'Addy Osmani',
|
|
135
|
+
skills: [
|
|
136
|
+
'spec-driven-development',
|
|
137
|
+
'incremental-implementation',
|
|
138
|
+
'code-review-and-quality',
|
|
139
|
+
'frontend-ui-engineering',
|
|
140
|
+
'browser-testing-with-devtools',
|
|
141
|
+
'accessibility-engineering',
|
|
142
|
+
'api-and-interface-design',
|
|
143
|
+
'security-and-hardening',
|
|
144
|
+
'performance-optimization',
|
|
145
|
+
'observability-and-instrumentation',
|
|
146
|
+
'shipping-and-launch',
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
// Resolves to <repo>/skills from src/workflow, dist/workflow, and dist-test/src/workflow
|
|
152
|
+
// without depending on user-home paths or process.cwd().
|
|
153
|
+
export function defaultSkillsDir() {
|
|
154
|
+
const fallback = fileURLToPath(new URL('../../skills', import.meta.url));
|
|
155
|
+
let dir = dirname(fileURLToPath(import.meta.url));
|
|
156
|
+
for (let depth = 0; depth < 5; depth += 1) {
|
|
157
|
+
const candidate = join(dir, 'skills');
|
|
158
|
+
if (existsSync(join(dir, 'package.json')) && existsSync(candidate)) {
|
|
159
|
+
return candidate;
|
|
160
|
+
}
|
|
161
|
+
const parent = dirname(dir);
|
|
162
|
+
if (parent === dir)
|
|
163
|
+
break;
|
|
164
|
+
dir = parent;
|
|
165
|
+
}
|
|
166
|
+
return fallback;
|
|
167
|
+
}
|
|
168
|
+
export function packForSkillId(id) {
|
|
169
|
+
if (id.startsWith('matt:'))
|
|
170
|
+
return 'matt-sdlc';
|
|
171
|
+
if (id.startsWith('poteto:'))
|
|
172
|
+
return 'pstack-analysis';
|
|
173
|
+
return 'osmani-quality';
|
|
174
|
+
}
|
|
175
|
+
export function listSkillPacks(options = {}) {
|
|
176
|
+
const includeOptIn = options.includeOptIn ?? true;
|
|
177
|
+
return SKILL_PACK_IDS.map((id) => SKILL_PACKS[id]).filter((pack) => includeOptIn || pack.activation === 'auto');
|
|
178
|
+
}
|
|
179
|
+
const FRONTMATTER_BLOCK = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
|
|
180
|
+
export function parseSkillFrontmatter(text) {
|
|
181
|
+
const match = FRONTMATTER_BLOCK.exec(text);
|
|
182
|
+
if (!match)
|
|
183
|
+
return null;
|
|
184
|
+
const block = match[1] ?? '';
|
|
185
|
+
const raw = {};
|
|
186
|
+
const lines = block.split(/\r?\n/);
|
|
187
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
188
|
+
const line = lines[i] ?? '';
|
|
189
|
+
const kv = /^([A-Za-z0-9_-]+)\s*:\s*(.*)$/.exec(line);
|
|
190
|
+
if (!kv)
|
|
191
|
+
continue;
|
|
192
|
+
const key = kv[1] ?? '';
|
|
193
|
+
let value = (kv[2] ?? '').trim();
|
|
194
|
+
if (value === '' || value === '>' || value === '>-' || value === '|' || value === '|-') {
|
|
195
|
+
const parts = [];
|
|
196
|
+
let j = i;
|
|
197
|
+
while (j + 1 < lines.length && /^[ \t]+/.test(lines[j + 1] ?? '')) {
|
|
198
|
+
const nextLine = (lines[j + 1] ?? '').trim();
|
|
199
|
+
// Do not consume nested YAML mapping keys (e.g. `metadata:\n author: ...`) as scalar text.
|
|
200
|
+
if (value === '' && /^[A-Za-z0-9_-]+\s*:/.test(nextLine))
|
|
201
|
+
break;
|
|
202
|
+
j += 1;
|
|
203
|
+
parts.push(nextLine);
|
|
204
|
+
}
|
|
205
|
+
if (parts.length > 0) {
|
|
206
|
+
i = j;
|
|
207
|
+
value = parts.join(' ');
|
|
208
|
+
}
|
|
209
|
+
else if (value !== '') {
|
|
210
|
+
value = '';
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
214
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
215
|
+
value = value.slice(1, -1);
|
|
216
|
+
}
|
|
217
|
+
raw[key] = value;
|
|
218
|
+
}
|
|
219
|
+
const disableRaw = raw['disable-model-invocation'] ?? raw['disableModelInvocation'];
|
|
220
|
+
const hideRaw = raw['hide'];
|
|
221
|
+
return {
|
|
222
|
+
name: raw['name'] || undefined,
|
|
223
|
+
description: raw['description'] || undefined,
|
|
224
|
+
disableModelInvocation: disableRaw === 'true',
|
|
225
|
+
hide: hideRaw === 'true',
|
|
226
|
+
raw,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
const MAX_PACK_SKILL_BYTES = 64 * 1024;
|
|
230
|
+
const USER_HOME_PATH_RE = /(?:\/Users\/[A-Za-z0-9._-]+|\/home\/[A-Za-z0-9._-]+|[A-Za-z]:\\Users\\[^\s"'`]+)/;
|
|
231
|
+
const INCOMPATIBLE_DIRECTIVES = [
|
|
232
|
+
[/subagent_type\s*:\s*["']poteto-agent["']/i, 'Cursor-only subagent_type "poteto-agent"'],
|
|
233
|
+
[
|
|
234
|
+
/\bclaude-opus-5-5-|\bclaude-fable-5-2-|\bgemini-4-carbon-high\b/i,
|
|
235
|
+
'hardcoded Cursor model slug',
|
|
236
|
+
],
|
|
237
|
+
[/\benvironment\s*:\s*["']cloud["']/i, 'Cursor-only cloud Task parameter'],
|
|
238
|
+
[/\brun_in_background\s*:\s*true\b/i, 'Cursor-only Task parameter run_in_background'],
|
|
239
|
+
[/\bAskQuestion\b/, 'Cursor-only AskQuestion tool reference'],
|
|
240
|
+
];
|
|
241
|
+
const RECURSIVE_PATTERNS = [
|
|
242
|
+
[
|
|
243
|
+
/^(?!.*(?:do\s+\*{0,2}not\*{0,2}|don't|never|forbid|must\s+\*{0,2}not\*{0,2})).*\b(?:enable|auto-start|automatically start|invoke)\b.*\b(?:ask-matt|using-agent-skills|poteto-mode|swarm)\b/i,
|
|
244
|
+
'attempts to auto-enable a competing or recursive orchestrator',
|
|
245
|
+
],
|
|
246
|
+
[
|
|
247
|
+
/^(?!.*(?:do\s+\*{0,2}not\*{0,2}|don't|never|forbid|must\s+\*{0,2}not\*{0,2})).*\bcall\s+ei_workflow\b.*\brecursiv/i,
|
|
248
|
+
'recursive ei_workflow orchestration directive',
|
|
249
|
+
],
|
|
250
|
+
];
|
|
251
|
+
function isContained(root, target) {
|
|
252
|
+
const rel = relative(root, target);
|
|
253
|
+
return rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);
|
|
254
|
+
}
|
|
255
|
+
function matchesAny(value, patterns) {
|
|
256
|
+
return patterns.some((pattern) => {
|
|
257
|
+
try {
|
|
258
|
+
return new RegExp(`^(?:${pattern})$`).test(value);
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
return value === pattern;
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
export function auditSkillContent(name, file, text, frontmatter) {
|
|
266
|
+
const issues = [];
|
|
267
|
+
if (USER_HOME_PATH_RE.test(text)) {
|
|
268
|
+
issues.push({
|
|
269
|
+
code: 'USER_HOME_PATH',
|
|
270
|
+
skill: name,
|
|
271
|
+
file,
|
|
272
|
+
message: `${name}: contains a hardcoded user-home path`,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
if (name === 'poteto-mode' && !frontmatter.disableModelInvocation) {
|
|
276
|
+
issues.push({
|
|
277
|
+
code: 'AUTO_OPT_IN_VIOLATION',
|
|
278
|
+
skill: name,
|
|
279
|
+
file,
|
|
280
|
+
message: `${name}: must declare disable-model-invocation: true to remain explicit opt-in`,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
for (const [pattern, detail] of INCOMPATIBLE_DIRECTIVES) {
|
|
284
|
+
if (pattern.test(text)) {
|
|
285
|
+
issues.push({
|
|
286
|
+
code: 'INCOMPATIBLE_TOOL_CALL',
|
|
287
|
+
skill: name,
|
|
288
|
+
file,
|
|
289
|
+
message: `${name}: contains incompatible directive (${detail})`,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
for (const line of text.split(/\r?\n/)) {
|
|
294
|
+
for (const [pattern, detail] of RECURSIVE_PATTERNS) {
|
|
295
|
+
if (pattern.test(line)) {
|
|
296
|
+
issues.push({
|
|
297
|
+
code: 'RECURSIVE_ORCHESTRATION',
|
|
298
|
+
skill: name,
|
|
299
|
+
file,
|
|
300
|
+
message: `${name}: ${detail}`,
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return issues;
|
|
306
|
+
}
|
|
307
|
+
async function scanSingleRoot(root) {
|
|
308
|
+
const found = [];
|
|
309
|
+
const issues = [];
|
|
310
|
+
let realRoot;
|
|
311
|
+
try {
|
|
312
|
+
realRoot = await realpath(root.path);
|
|
313
|
+
const info = await stat(realRoot);
|
|
314
|
+
if (!info.isDirectory()) {
|
|
315
|
+
issues.push({
|
|
316
|
+
code: 'ROOT_NOT_FOUND',
|
|
317
|
+
file: root.path,
|
|
318
|
+
message: `${root.label}: ${root.path} is not a directory`,
|
|
319
|
+
});
|
|
320
|
+
return { found, issues };
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
catch {
|
|
324
|
+
if (!root.optional) {
|
|
325
|
+
issues.push({
|
|
326
|
+
code: 'ROOT_NOT_FOUND',
|
|
327
|
+
file: root.path,
|
|
328
|
+
message: `${root.label}: directory ${root.path} does not exist`,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
return { found, issues };
|
|
332
|
+
}
|
|
333
|
+
const entries = (await readdir(realRoot, { withFileTypes: true })).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
334
|
+
const seenInRoot = new Set();
|
|
335
|
+
for (const entry of entries) {
|
|
336
|
+
if (!entry.isDirectory() && !entry.isSymbolicLink())
|
|
337
|
+
continue;
|
|
338
|
+
if (root.includeOnly &&
|
|
339
|
+
root.includeOnly.length > 0 &&
|
|
340
|
+
!matchesAny(entry.name, root.includeOnly)) {
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
if (root.exclude && root.exclude.length > 0 && matchesAny(entry.name, root.exclude)) {
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
const candidate = resolve(realRoot, entry.name, 'SKILL.md');
|
|
347
|
+
let realFile;
|
|
348
|
+
try {
|
|
349
|
+
realFile = await realpath(candidate);
|
|
350
|
+
}
|
|
351
|
+
catch {
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (!root.allowExternalSymlinks && !isContained(realRoot, realFile)) {
|
|
355
|
+
issues.push({
|
|
356
|
+
code: 'PATH_ESCAPE',
|
|
357
|
+
skill: entry.name,
|
|
358
|
+
file: candidate,
|
|
359
|
+
message: `${entry.name}: resolves to ${realFile}, outside root ${realRoot}`,
|
|
360
|
+
});
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
const fileInfo = await stat(realFile);
|
|
364
|
+
if (!fileInfo.isFile() || fileInfo.size > MAX_PACK_SKILL_BYTES) {
|
|
365
|
+
issues.push({
|
|
366
|
+
code: 'INVALID_SKILL',
|
|
367
|
+
skill: entry.name,
|
|
368
|
+
file: realFile,
|
|
369
|
+
message: `${entry.name}: SKILL.md is not a regular file within ${MAX_PACK_SKILL_BYTES} bytes`,
|
|
370
|
+
});
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
const text = await readFile(realFile, 'utf8');
|
|
374
|
+
const frontmatter = parseSkillFrontmatter(text);
|
|
375
|
+
if (!frontmatter || !frontmatter.name || !frontmatter.description) {
|
|
376
|
+
issues.push({
|
|
377
|
+
code: 'INVALID_SKILL',
|
|
378
|
+
skill: entry.name,
|
|
379
|
+
file: realFile,
|
|
380
|
+
message: `${entry.name}: SKILL.md missing valid frontmatter with name and description`,
|
|
381
|
+
});
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (seenInRoot.has(frontmatter.name)) {
|
|
385
|
+
issues.push({
|
|
386
|
+
code: 'DUPLICATE_SKILL',
|
|
387
|
+
skill: frontmatter.name,
|
|
388
|
+
file: realFile,
|
|
389
|
+
message: `${frontmatter.name}: duplicate skill name inside ${root.label}`,
|
|
390
|
+
});
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
seenInRoot.add(frontmatter.name);
|
|
394
|
+
if (root.auditContent !== false) {
|
|
395
|
+
issues.push(...auditSkillContent(frontmatter.name, realFile, text, frontmatter));
|
|
396
|
+
}
|
|
397
|
+
const explicitOnly = frontmatter.disableModelInvocation || frontmatter.hide;
|
|
398
|
+
found.push({
|
|
399
|
+
name: frontmatter.name,
|
|
400
|
+
description: frontmatter.description,
|
|
401
|
+
file: realFile,
|
|
402
|
+
dir: dirname(realFile),
|
|
403
|
+
sourceLabel: root.label,
|
|
404
|
+
disableModelInvocation: frontmatter.disableModelInvocation,
|
|
405
|
+
hide: frontmatter.hide,
|
|
406
|
+
explicitOnly,
|
|
407
|
+
inCatalog: CATALOG_SKILL_NAMES.includes(frontmatter.name),
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
return { found, issues };
|
|
411
|
+
}
|
|
412
|
+
// Discovers skills across ordered roots (highest priority first).
|
|
413
|
+
// Earlier roots win on name collisions, preserving user customizations without overwriting them.
|
|
414
|
+
export async function discoverSkillsForPlatform(options) {
|
|
415
|
+
const byName = new Map();
|
|
416
|
+
const shadowed = [];
|
|
417
|
+
const issues = [];
|
|
418
|
+
const seenIssues = new Set();
|
|
419
|
+
for (const root of options.roots) {
|
|
420
|
+
const { found, issues: rootIssues } = await scanSingleRoot(root);
|
|
421
|
+
for (const issue of rootIssues) {
|
|
422
|
+
const key = `${issue.code}|${issue.file ?? ''}|${issue.message}`;
|
|
423
|
+
if (seenIssues.has(key))
|
|
424
|
+
continue;
|
|
425
|
+
seenIssues.add(key);
|
|
426
|
+
issues.push(issue);
|
|
427
|
+
}
|
|
428
|
+
for (const skill of found) {
|
|
429
|
+
const existing = byName.get(skill.name);
|
|
430
|
+
if (existing) {
|
|
431
|
+
shadowed.push({
|
|
432
|
+
name: skill.name,
|
|
433
|
+
keptFrom: existing.sourceLabel,
|
|
434
|
+
shadowedFrom: skill.sourceLabel,
|
|
435
|
+
});
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
438
|
+
byName.set(skill.name, skill);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (options.requireCatalog) {
|
|
442
|
+
for (const requiredName of CATALOG_SKILL_NAMES) {
|
|
443
|
+
if (!byName.has(requiredName)) {
|
|
444
|
+
issues.push({
|
|
445
|
+
code: 'MISSING_CATALOG_SKILL',
|
|
446
|
+
skill: requiredName,
|
|
447
|
+
message: `required KSD catalog skill ${requiredName} was not discovered`,
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
const skills = [...byName.values()];
|
|
453
|
+
const autoVisible = skills.filter((skill) => !skill.explicitOnly);
|
|
454
|
+
const explicitOnly = skills.filter((skill) => skill.explicitOnly);
|
|
455
|
+
return {
|
|
456
|
+
platform: options.platform,
|
|
457
|
+
skills,
|
|
458
|
+
autoVisible,
|
|
459
|
+
explicitOnly,
|
|
460
|
+
shadowed,
|
|
461
|
+
issues,
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
export function packSkillPath(packId, skillsDir = defaultSkillsDir()) {
|
|
465
|
+
return join(skillsDir, packId, 'SKILL.md');
|
|
466
|
+
}
|
|
467
|
+
export function orchestratorSkillPath(skillsDir = defaultSkillsDir()) {
|
|
468
|
+
return join(skillsDir, ORCHESTRATOR_SKILL_ID, 'SKILL.md');
|
|
469
|
+
}
|