@causyne/agent 1.20.99 → 1.20.103
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/bin/causyne.js +18 -1
- package/package.json +1 -1
- package/src/agentLoop.js +81 -21
- package/src/agentLoop.ts +78 -21
- package/src/autoUpdate.js +4 -4
- package/src/autoUpdate.ts +4 -4
- package/src/cliMode.js +2 -0
- package/src/compiledSkills.d.ts +5 -0
- package/src/launchIntent.js +52 -1
- package/src/launchIntent.ts +56 -1
- package/src/plugins/pluginManager.d.ts +7 -0
- package/src/plugins/pluginSkills.js +1 -0
- package/src/plugins/pluginSkills.ts +1 -0
- package/src/promptMentions.js +1 -1
- package/src/promptMentions.ts +1 -1
- package/src/skills/skillResourceSafety.js +38 -2
- package/src/skills/skillResourceSafety.ts +39 -2
- package/src/skillsManager.js +224 -232
- package/src/skillsManager.ts +354 -0
- package/src/tools/createSkill.js +92 -104
- package/src/tools/createSkill.ts +142 -0
- package/src/tools/fsEdit.js +104 -91
- package/src/tools/fsEdit.ts +144 -0
- package/src/tools/multiEdit.js +105 -93
- package/src/tools/multiEdit.ts +145 -0
- package/src/tools/readNativeSkill.js +2 -1
- package/src/tools/readNativeSkill.ts +2 -1
- package/src/tui/mouseHover.js +0 -4
- package/src/tui/mouseHover.ts +0 -4
- package/src/tui/prompt.js +12 -0
- package/src/tui/stageSurface.js +12 -13
- package/src/userSkills.js +5 -4
- package/src/userSkills.ts +6 -4
- package/src/skillsManager.d.ts +0 -7
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import { COMPILED_SKILLS } from './compiledSkills.js';
|
|
5
|
+
import { loadUserSkills, type UserSkill } from './userSkills.js';
|
|
6
|
+
import { getPluginSkills } from './plugins/pluginManager.js';
|
|
7
|
+
|
|
8
|
+
export interface SkillDescriptor {
|
|
9
|
+
domain: string;
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
source: 'native' | 'user' | 'plugin';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface CompiledSkillItem {
|
|
17
|
+
name?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
content: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const compiledSkillsCatalog = COMPILED_SKILLS as unknown as Record<string, Record<string, CompiledSkillItem>>;
|
|
23
|
+
|
|
24
|
+
// User skills are read from disk, and the disk is slow relative to how often
|
|
25
|
+
// these functions are called (every completion keystroke asks for the
|
|
26
|
+
// catalogue). Cache for a moment so typing stays instant, but keep the window
|
|
27
|
+
// short enough that a skill the agent just wrote shows up without a restart.
|
|
28
|
+
const USER_CACHE_MS = 2000;
|
|
29
|
+
let userCache: { at: number; skills: UserSkill[]; problems: string[] } = { at: 0, skills: [], problems: [] };
|
|
30
|
+
|
|
31
|
+
export function invalidateUserSkills(): void {
|
|
32
|
+
userCache = { at: 0, skills: [], problems: [] };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function userSkills(): { at: number; skills: UserSkill[]; problems: string[] } {
|
|
36
|
+
const now = Date.now();
|
|
37
|
+
if (now - userCache.at < USER_CACHE_MS) return userCache;
|
|
38
|
+
try {
|
|
39
|
+
const loaded = loadUserSkills();
|
|
40
|
+
userCache = { at: now, skills: loaded.skills, problems: loaded.problems };
|
|
41
|
+
} catch (e: unknown) {
|
|
42
|
+
// A broken skills directory must never stop a session from starting.
|
|
43
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
44
|
+
userCache = { at: now, skills: [], problems: [`user skills unavailable: ${msg}`] };
|
|
45
|
+
}
|
|
46
|
+
return userCache;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function userSkillProblems(): string[] {
|
|
50
|
+
return userSkills().problems;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// What a workspace looks like from the outside.
|
|
54
|
+
//
|
|
55
|
+
// This used to name four domains, which meant that of the compiled skills only
|
|
56
|
+
// android, web, python and devops could EVER be surfaced — every other one was
|
|
57
|
+
// compiled into the artefact and unreachable. Detection is what decides whether
|
|
58
|
+
// a skill exists as far as the model is concerned.
|
|
59
|
+
//
|
|
60
|
+
// Marker files only; no globbing and no directory walking, so detection stays a
|
|
61
|
+
// handful of stat calls whatever the size of the repository.
|
|
62
|
+
const DOMAIN_INDICATORS: Record<string, string[]> = {
|
|
63
|
+
android: ['build.gradle', 'build.gradle.kts', 'app/build.gradle', 'app/build.gradle.kts',
|
|
64
|
+
'app/src/main/AndroidManifest.xml', 'settings.gradle.kts', 'gradlew'],
|
|
65
|
+
mobile: ['pubspec.yaml', 'ios/Podfile', 'Podfile', 'app.json', 'metro.config.js',
|
|
66
|
+
'react-native.config.js', 'expo.json'],
|
|
67
|
+
web: ['next.config.js', 'next.config.mjs', 'next.config.ts', 'nuxt.config.ts',
|
|
68
|
+
'svelte.config.js', 'vue.config.js', 'astro.config.mjs', 'vite.config.js',
|
|
69
|
+
'vite.config.ts', 'angular.json', 'index.html', 'tailwind.config.js'],
|
|
70
|
+
backend: ['package.json', 'go.mod', 'Cargo.toml', 'pom.xml', 'build.sbt',
|
|
71
|
+
'Gemfile', 'composer.json', 'nest-cli.json'],
|
|
72
|
+
python: ['requirements.txt', 'pyproject.toml', 'Pipfile', 'setup.py', 'setup.cfg',
|
|
73
|
+
'uv.lock', 'poetry.lock', 'environment.yml'],
|
|
74
|
+
devops: ['Dockerfile', 'docker-compose.yml', 'docker-compose.yaml', '.github/workflows',
|
|
75
|
+
'.gitlab-ci.yml', 'Jenkinsfile', 'Makefile', '.circleci/config.yml'],
|
|
76
|
+
cloud: ['main.tf', 'terraform.tf', 'serverless.yml', 'template.yaml', 'Pulumi.yaml',
|
|
77
|
+
'cdk.json', 'k8s', 'kubernetes', 'helm', 'skaffold.yaml'],
|
|
78
|
+
database: ['prisma/schema.prisma', 'migrations', 'alembic.ini', 'knexfile.js',
|
|
79
|
+
'schema.sql', 'db/schema.rb', 'drizzle.config.ts', 'flyway.conf'],
|
|
80
|
+
testing: ['jest.config.js', 'jest.config.ts', 'vitest.config.ts', 'playwright.config.ts',
|
|
81
|
+
'cypress.config.js', 'pytest.ini', 'tox.ini', 'tests', 'test', '__tests__'],
|
|
82
|
+
security: ['.github/dependabot.yml', 'SECURITY.md', '.snyk', 'socket.yml', 'socket.json'],
|
|
83
|
+
design: ['tailwind.config.js', 'tailwind.config.ts', 'styles', 'src/styles',
|
|
84
|
+
'theme.js', 'theme.ts', 'tokens.json', 'postcss.config.js'],
|
|
85
|
+
// A 3D/video workspace. Without a rule here the media skills compile into
|
|
86
|
+
// the artefact and are unreachable by domain detection — tool_search still
|
|
87
|
+
// finds them, but the workspace never volunteers them.
|
|
88
|
+
media: ['.blend', 'assets/3d', 'renders', 'blender', 'shots', 'Resolve Projects'],
|
|
89
|
+
git: ['.git', '.gitignore', '.gitattributes'],
|
|
90
|
+
performance: ['lighthouserc.js', 'lighthouserc.json', '.lighthouserc.yml', 'k6.js',
|
|
91
|
+
'benchmark', 'benchmarks'],
|
|
92
|
+
'ai-engineering': ['.env.example', 'prompts', 'evals', 'langchain.json',
|
|
93
|
+
'llm.config.js', 'openai.json'],
|
|
94
|
+
data: ['dbt_project.yml', 'airflow.cfg', 'dags', 'notebooks', '*.ipynb',
|
|
95
|
+
'dvc.yaml', 'great_expectations']
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// Domains that apply to every task regardless of what the workspace looks like.
|
|
99
|
+
//
|
|
100
|
+
// Design and security are not properties of a file layout — an agent writing a
|
|
101
|
+
// UI needs the anti-slop direction whether or not a tailwind config exists, and
|
|
102
|
+
// input validation matters whether or not the repository has a SECURITY.md.
|
|
103
|
+
const UNIVERSAL_DOMAINS = ['design', 'security'];
|
|
104
|
+
|
|
105
|
+
// Ceiling on how many skill descriptions may enter the system prompt.
|
|
106
|
+
//
|
|
107
|
+
// With 100 skills, injecting every description of every detected domain would
|
|
108
|
+
// spend thousands of tokens on an index before the task has even been read.
|
|
109
|
+
// This is the progressive-disclosure contract: the model sees names and routing
|
|
110
|
+
// conditions, and pulls a body with fs_read_skill only when one is relevant.
|
|
111
|
+
const MAX_INDEXED_SKILLS = 40;
|
|
112
|
+
|
|
113
|
+
export function detectWorkspaceDomains(workspaceRoot?: string): string[] {
|
|
114
|
+
if (!workspaceRoot || !fs.existsSync(workspaceRoot)) return UNIVERSAL_DOMAINS.slice();
|
|
115
|
+
|
|
116
|
+
const detectedDomains: string[] = [];
|
|
117
|
+
|
|
118
|
+
for (const [domain, indicators] of Object.entries(DOMAIN_INDICATORS)) {
|
|
119
|
+
for (const indicator of indicators) {
|
|
120
|
+
// A glob marker means "any file with this extension at the root". Kept to
|
|
121
|
+
// one readdir rather than a walk — a recursive search of a large monorepo
|
|
122
|
+
// on every task start is not worth one extra domain.
|
|
123
|
+
if (indicator.startsWith('*.')) {
|
|
124
|
+
try {
|
|
125
|
+
const extension = indicator.slice(1);
|
|
126
|
+
if (fs.readdirSync(workspaceRoot).some((name) => name.endsWith(extension))) {
|
|
127
|
+
detectedDomains.push(domain);
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
} catch { /* unreadable directory is simply not a match */ }
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (fs.existsSync(path.join(workspaceRoot, indicator))) {
|
|
134
|
+
detectedDomains.push(domain);
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Shallow check of immediate subdirectories for Android projects located in subfolders
|
|
141
|
+
if (!detectedDomains.includes('android')) {
|
|
142
|
+
try {
|
|
143
|
+
const entries = fs.readdirSync(workspaceRoot, { withFileTypes: true });
|
|
144
|
+
for (const entry of entries) {
|
|
145
|
+
if (entry.isDirectory() && !entry.name.startsWith('.') && entry.name !== 'node_modules' && entry.name !== 'Library') {
|
|
146
|
+
const subDir = path.join(workspaceRoot, entry.name);
|
|
147
|
+
if (fs.existsSync(path.join(subDir, 'build.gradle')) ||
|
|
148
|
+
fs.existsSync(path.join(subDir, 'build.gradle.kts')) ||
|
|
149
|
+
fs.existsSync(path.join(subDir, 'gradlew')) ||
|
|
150
|
+
fs.existsSync(path.join(subDir, 'app/build.gradle')) ||
|
|
151
|
+
fs.existsSync(path.join(subDir, 'app/build.gradle.kts')) ||
|
|
152
|
+
fs.existsSync(path.join(subDir, 'app/src/main/AndroidManifest.xml'))) {
|
|
153
|
+
detectedDomains.push('android');
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
} catch { /* unreadable directory is simply skipped */ }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
for (const domain of UNIVERSAL_DOMAINS) {
|
|
162
|
+
if (!detectedDomains.includes(domain)) detectedDomains.push(domain);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return detectedDomains;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export { MAX_INDEXED_SKILLS, UNIVERSAL_DOMAINS };
|
|
169
|
+
|
|
170
|
+
export function ensureSkillRepo(domain: string): boolean {
|
|
171
|
+
if (compiledSkillsCatalog[domain]) {
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The index the model sees: names and routing conditions, never bodies.
|
|
179
|
+
*
|
|
180
|
+
* Progressive disclosure. 100 skills is roughly 250 KB of markdown; injecting it
|
|
181
|
+
* would consume the context window before the task was read. What goes in is one
|
|
182
|
+
* line per skill — the name and WHEN TO USE IT — and the model pulls the body
|
|
183
|
+
* with fs_read_skill only for the one it needs. This is the same contract
|
|
184
|
+
* claude-code and openclaw use, and it is what makes a large skill library
|
|
185
|
+
* possible at all.
|
|
186
|
+
*
|
|
187
|
+
* Capped at MAX_INDEXED_SKILLS. A workspace matching eight domains would
|
|
188
|
+
* otherwise inject fifty-odd descriptions; the detected domains come first so
|
|
189
|
+
* the cut falls on the least relevant.
|
|
190
|
+
*/
|
|
191
|
+
export function getUniversalSkillsIndex(domains: string[]): string {
|
|
192
|
+
let indexText = '';
|
|
193
|
+
let totalSkillsCount = 0;
|
|
194
|
+
|
|
195
|
+
// One catalogue, so a user skill is as visible to the agent as a compiled one.
|
|
196
|
+
const catalogue = new Map<string, SkillDescriptor[]>();
|
|
197
|
+
for (const skill of listCompiledSkills()) {
|
|
198
|
+
if (!catalogue.has(skill.domain)) catalogue.set(skill.domain, []);
|
|
199
|
+
catalogue.get(skill.domain)!.push(skill);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// A user's own domains are always offered: someone who wrote a `team/` skill
|
|
203
|
+
// wants it considered, and no marker file in the workspace announces it.
|
|
204
|
+
const ownDomains = [...new Set(userSkills().skills.map((skill) => skill.domain))];
|
|
205
|
+
const wanted = [...new Set([...ownDomains, ...domains])];
|
|
206
|
+
|
|
207
|
+
for (const domain of wanted) {
|
|
208
|
+
const domainSkills = catalogue.get(domain);
|
|
209
|
+
if (!domainSkills || domainSkills.length === 0) continue;
|
|
210
|
+
if (totalSkillsCount >= MAX_INDEXED_SKILLS) break;
|
|
211
|
+
|
|
212
|
+
let domainSkillsCount = 0;
|
|
213
|
+
let domainIndexText = `### ${domain.toUpperCase()} SKILLS\n`;
|
|
214
|
+
|
|
215
|
+
for (const skill of domainSkills) {
|
|
216
|
+
if (totalSkillsCount + domainSkillsCount >= MAX_INDEXED_SKILLS) break;
|
|
217
|
+
const mark = skill.source === 'user' ? ' [your own]' : '';
|
|
218
|
+
const safeName = String(skill.name || skill.id).replace(/[<>]/g, '');
|
|
219
|
+
const safeDesc = String(skill.description || '').replace(/[<>]/g, '');
|
|
220
|
+
domainIndexText += `- **${safeName}**${mark} (ID: ${domain}/${skill.id}): ${safeDesc}\n`;
|
|
221
|
+
domainSkillsCount++;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (domainSkillsCount > 0) {
|
|
225
|
+
indexText += domainIndexText + '\n';
|
|
226
|
+
totalSkillsCount += domainSkillsCount;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (totalSkillsCount === 0) return '';
|
|
231
|
+
|
|
232
|
+
let finalOutput = `\n<causyne_universal_skills>\n`;
|
|
233
|
+
finalOutput += `You have access to highly-curated, domain-specific intelligence skills provided as readable local skill data. If a skill is relevant to the user's task, you MUST use the \`fs_read_skill\` tool (passing the ID) to read its full instruction BEFORE proceeding with your plan. NEVER guess syntax if a skill exists for it.\n\n`;
|
|
234
|
+
finalOutput += indexText;
|
|
235
|
+
finalOutput += `</causyne_universal_skills>\n`;
|
|
236
|
+
|
|
237
|
+
return finalOutput;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* The compact form of the skills index: what domains exist and how to search
|
|
242
|
+
* them, instead of forty name-and-description lines.
|
|
243
|
+
*
|
|
244
|
+
* WHY: `getUniversalSkillsIndex()` costs ~841 tokens for two domains and ~1,092
|
|
245
|
+
* for web+android, injected into a cached system block on EVERY request of
|
|
246
|
+
* EVERY task — a bare "hi" paid for a catalogue of skills it would never read.
|
|
247
|
+
*
|
|
248
|
+
* WHY IT IS SAFE NOW AND WAS NOT BEFORE: until `tool_search` learned to score
|
|
249
|
+
* the skill catalogue, this index was the ONLY way a model could discover a
|
|
250
|
+
* skill id. Shrinking it would have made 100 compiled skills unreachable —
|
|
251
|
+
* a capability regression wearing an optimisation's clothes. Retrieval replaces
|
|
252
|
+
* a catalogue only once the retrieval exists.
|
|
253
|
+
*
|
|
254
|
+
* @param domains Workspace domains detected for this task.
|
|
255
|
+
* @returns System-prompt fragment, '' when nothing exists.
|
|
256
|
+
*/
|
|
257
|
+
export function getSkillDomainHeader(domains?: Iterable<string> | string[]): string {
|
|
258
|
+
const catalogue = new Map<string, number>();
|
|
259
|
+
for (const skill of listCompiledSkills()) {
|
|
260
|
+
catalogue.set(skill.domain, (catalogue.get(skill.domain) || 0) + 1);
|
|
261
|
+
}
|
|
262
|
+
if (catalogue.size === 0) return '';
|
|
263
|
+
|
|
264
|
+
const total = [...catalogue.values()].reduce((sum, n) => sum + n, 0);
|
|
265
|
+
const relevant = [...new Set(domains || [])].filter((d) => catalogue.has(d));
|
|
266
|
+
const all = [...catalogue.keys()].sort();
|
|
267
|
+
|
|
268
|
+
let out = `\n<causyne_universal_skills>\n`;
|
|
269
|
+
out += `${total} curated engineering skills are compiled into you, across: ${all.join(', ')}.\n`;
|
|
270
|
+
if (relevant.length > 0) {
|
|
271
|
+
out += `This workspace looks like: ${relevant.join(', ')}.\n`;
|
|
272
|
+
}
|
|
273
|
+
out += `Call \`tool_search\` with what you are trying to do to find the relevant skill ids, then read one with \`fs_read_skill\`. Do this BEFORE planning anything the skills cover. NEVER guess syntax a skill documents.\n`;
|
|
274
|
+
out += `</causyne_universal_skills>\n`;
|
|
275
|
+
return out;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* The whole catalogue as a flat list, for the picker and for `/skills`.
|
|
280
|
+
*
|
|
281
|
+
* One shape for every consumer, so the terminal picker and the text listing can
|
|
282
|
+
* never disagree about what exists.
|
|
283
|
+
*/
|
|
284
|
+
export function listCompiledSkills(): SkillDescriptor[] {
|
|
285
|
+
const out: SkillDescriptor[] = [];
|
|
286
|
+
const seen = new Set<string>();
|
|
287
|
+
|
|
288
|
+
// The user's own skills come first and SHADOW a compiled skill of the same
|
|
289
|
+
// id. That is the customisation: someone whose deployment genuinely differs
|
|
290
|
+
// from the shipped procedure writes their own `devops/zero-downtime-deploys`
|
|
291
|
+
// and theirs is the one the agent reads. Shipping a library that cannot be
|
|
292
|
+
// corrected is shipping an opinion.
|
|
293
|
+
for (const skill of userSkills().skills) {
|
|
294
|
+
const key = `${skill.domain}/${skill.id}`;
|
|
295
|
+
seen.add(key);
|
|
296
|
+
out.push({
|
|
297
|
+
domain: skill.domain,
|
|
298
|
+
id: skill.id,
|
|
299
|
+
name: skill.name,
|
|
300
|
+
description: skill.description,
|
|
301
|
+
source: 'user'
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Plugin skills live in a plugin-owned namespace (`plugin-<name>/...`) and
|
|
306
|
+
// appear only after explicit digest-pinned enablement. A user's own skill can
|
|
307
|
+
// still shadow one, which preserves local authority over every instruction.
|
|
308
|
+
for (const skill of getPluginSkills() as Array<{ domain: string; id: string; name?: string; description?: string; content: string }>) {
|
|
309
|
+
const key = `${skill.domain}/${skill.id}`;
|
|
310
|
+
if (seen.has(key)) continue;
|
|
311
|
+
seen.add(key);
|
|
312
|
+
out.push({
|
|
313
|
+
domain: skill.domain,
|
|
314
|
+
id: skill.id,
|
|
315
|
+
name: skill.name || skill.id,
|
|
316
|
+
description: skill.description || '',
|
|
317
|
+
source: 'plugin'
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
for (const [domain, skills] of Object.entries(compiledSkillsCatalog)) {
|
|
322
|
+
for (const [id, data] of Object.entries(skills)) {
|
|
323
|
+
if (seen.has(`${domain}/${id}`)) continue;
|
|
324
|
+
out.push({
|
|
325
|
+
domain,
|
|
326
|
+
id,
|
|
327
|
+
name: data.name || id,
|
|
328
|
+
description: data.description || '',
|
|
329
|
+
source: 'native'
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return out;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export function readCompiledSkill(domain: string, skillId: string): string {
|
|
337
|
+
// A user skill of the same id wins, for the same reason it does in the
|
|
338
|
+
// listing: the user's version is the corrected one.
|
|
339
|
+
const own = userSkills().skills
|
|
340
|
+
.find((skill) => skill.domain === domain && skill.id === skillId);
|
|
341
|
+
if (own) return own.content;
|
|
342
|
+
|
|
343
|
+
const pluginSkill = (getPluginSkills() as Array<{ domain: string; id: string; content: string }>)
|
|
344
|
+
.find((skill) => skill.domain === domain && skill.id === skillId);
|
|
345
|
+
if (pluginSkill) return pluginSkill.content;
|
|
346
|
+
|
|
347
|
+
const domainSkills = compiledSkillsCatalog[domain];
|
|
348
|
+
if (!domainSkills) return `Error: Domain ${domain} not found in compiled skills.`;
|
|
349
|
+
|
|
350
|
+
const skillData = domainSkills[skillId];
|
|
351
|
+
if (!skillData) return `Error: Skill ${skillId} not found in domain ${domain}.`;
|
|
352
|
+
|
|
353
|
+
return skillData.content;
|
|
354
|
+
}
|
package/src/tools/createSkill.js
CHANGED
|
@@ -14,116 +14,104 @@
|
|
|
14
14
|
//
|
|
15
15
|
// Path safety, size limits and sanitising all live in userSkills.js, and this
|
|
16
16
|
// tool cannot reach the filesystem except through it.
|
|
17
|
-
|
|
18
|
-
import {
|
|
19
|
-
parseSkillId, writeUserSkill, userSkillsRoot, MAX_SKILL_BYTES
|
|
20
|
-
} from '../userSkills.js';
|
|
17
|
+
import { parseSkillId, writeUserSkill, userSkillsRoot, MAX_SKILL_BYTES } from '../userSkills.js';
|
|
21
18
|
import { invalidateUserSkills } from '../skillsManager.js';
|
|
22
|
-
|
|
23
19
|
/** Everything the contract requires, reported at once rather than one at a time. */
|
|
24
20
|
function contractProblems(content) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
if (!/^description:\s*\S/m.test(content)) {
|
|
30
|
-
problems.push("frontmatter needs a `description:` — it is the ONLY thing the agent reads when deciding whether this skill applies, so write it as \"what this does. Use when …\"");
|
|
31
|
-
}
|
|
32
|
-
if (!/^name:\s*\S/m.test(content)) {
|
|
33
|
-
problems.push('frontmatter needs a `name:`');
|
|
34
|
-
}
|
|
35
|
-
if (!/\*\*Done when:\*\*/.test(content)) {
|
|
36
|
-
problems.push("no step ends with a `**Done when:**` criterion — without one this is a description of a task, not a procedure someone can follow to a known end");
|
|
37
|
-
}
|
|
38
|
-
if (!/##\s+Verification/i.test(content)) {
|
|
39
|
-
problems.push('no `## Verification` section — a skill has to say how to confirm it worked');
|
|
40
|
-
}
|
|
41
|
-
return problems;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export const createSkill = {
|
|
45
|
-
schema: {
|
|
46
|
-
name: 'skill_create',
|
|
47
|
-
description:
|
|
48
|
-
"Write a reusable skill into the user's own skill library so it is available in every future session. Use when the user describes a procedure specific to them — their "
|
|
49
|
-
+ 'deployment steps, their review checklist, their project conventions — that would '
|
|
50
|
-
+ 'otherwise have to be explained again next time. Ask the user before writing one they '
|
|
51
|
-
+ 'did not request. The body must follow the skill contract: frontmatter with name and a '
|
|
52
|
-
+ '"Use when ..." description, numbered steps each ending with a "**Done when:**" line, '
|
|
53
|
-
+ 'and a closing "## Verification" section.',
|
|
54
|
-
parameters: {
|
|
55
|
-
type: 'object',
|
|
56
|
-
properties: {
|
|
57
|
-
skill_id: {
|
|
58
|
-
type: 'string',
|
|
59
|
-
description:
|
|
60
|
-
"Where it lives, as \"domain/name\". Both are lowercase letters, digits and hyphens. Use an existing domain (web, devops, python, testing, security, design, …) when the "
|
|
61
|
-
+ 'skill belongs to one, or a new domain of the user\'s own such as "team" or the '
|
|
62
|
-
+ 'project name. Example: team/release-checklist'
|
|
63
|
-
},
|
|
64
|
-
content: {
|
|
65
|
-
type: 'string',
|
|
66
|
-
description:
|
|
67
|
-
"The complete SKILL.md, starting with the --- frontmatter block. Write the procedure, not an essay: the steps someone would actually take, in order, each with a "
|
|
68
|
-
+ 'checkable "**Done when:**" line, closing with "## Verification".'
|
|
69
|
-
},
|
|
70
|
-
overwrite: {
|
|
71
|
-
type: 'boolean',
|
|
72
|
-
description:
|
|
73
|
-
"Replace an existing skill of the same id. Defaults to false. Only set this when the user has asked for that specific skill to be rewritten."
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
required: ['skill_id', 'content']
|
|
21
|
+
const problems = [];
|
|
22
|
+
if (!/^---\r?\n[\s\S]*?\r?\n---/.test(content)) {
|
|
23
|
+
problems.push('missing the `---` frontmatter block at the very top');
|
|
77
24
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
execute: async (args = {}) => {
|
|
81
|
-
const parsed = parseSkillId(args.skill_id);
|
|
82
|
-
if (parsed.error) return { success: false, error: parsed.error };
|
|
83
|
-
|
|
84
|
-
const content = typeof args.content === 'string' ? args.content : '';
|
|
85
|
-
if (!content.trim()) {
|
|
86
|
-
return { success: false, error: 'content is required — write the whole SKILL.md' };
|
|
25
|
+
if (!/^description:\s*\S/m.test(content)) {
|
|
26
|
+
problems.push("frontmatter needs a `description:` — it is the ONLY thing the agent reads when deciding whether this skill applies, so write it as \"what this does. Use when …\"");
|
|
87
27
|
}
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
success: false,
|
|
91
|
-
error: `the skill is larger than the ${MAX_SKILL_BYTES / 1024} KB limit. A skill this long `
|
|
92
|
-
+ 'will crowd out the task it is meant to help with — split it, or move the detail into '
|
|
93
|
-
+ 'the step that needs it.'
|
|
94
|
-
};
|
|
28
|
+
if (!/^name:\s*\S/m.test(content)) {
|
|
29
|
+
problems.push('frontmatter needs a `name:`');
|
|
95
30
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
31
|
+
if (!/\*\*Done when:\*\*/.test(content)) {
|
|
32
|
+
problems.push("no step ends with a `**Done when:**` criterion — without one this is a description of a task, not a procedure someone can follow to a known end");
|
|
33
|
+
}
|
|
34
|
+
if (!/##\s+Verification/i.test(content)) {
|
|
35
|
+
problems.push('no `## Verification` section — a skill has to say how to confirm it worked');
|
|
36
|
+
}
|
|
37
|
+
return problems;
|
|
38
|
+
}
|
|
39
|
+
export const createSkill = {
|
|
40
|
+
schema: {
|
|
41
|
+
name: 'skill_create',
|
|
42
|
+
description: "Write a reusable skill into the user's own skill library so it is available in every future session. Use when the user describes a procedure specific to them — their "
|
|
43
|
+
+ 'deployment steps, their review checklist, their project conventions — that would '
|
|
44
|
+
+ 'otherwise have to be explained again next time. Ask the user before writing one they '
|
|
45
|
+
+ 'did not request. The body must follow the skill contract: frontmatter with name and a '
|
|
46
|
+
+ '"Use when ..." description, numbered steps each ending with a "**Done when:**" line, '
|
|
47
|
+
+ 'and a closing "## Verification" section.',
|
|
48
|
+
parameters: {
|
|
49
|
+
type: 'object',
|
|
50
|
+
properties: {
|
|
51
|
+
skill_id: {
|
|
52
|
+
type: 'string',
|
|
53
|
+
description: "Where it lives, as \"domain/name\". Both are lowercase letters, digits and hyphens. Use an existing domain (web, devops, python, testing, security, design, …) when the "
|
|
54
|
+
+ 'skill belongs to one, or a new domain of the user\'s own such as "team" or the '
|
|
55
|
+
+ 'project name. Example: team/release-checklist'
|
|
56
|
+
},
|
|
57
|
+
content: {
|
|
58
|
+
type: 'string',
|
|
59
|
+
description: "The complete SKILL.md, starting with the --- frontmatter block. Write the procedure, not an essay: the steps someone would actually take, in order, each with a "
|
|
60
|
+
+ 'checkable "**Done when:**" line, closing with "## Verification".'
|
|
61
|
+
},
|
|
62
|
+
overwrite: {
|
|
63
|
+
type: 'boolean',
|
|
64
|
+
description: "Replace an existing skill of the same id. Defaults to false. Only set this when the user has asked for that specific skill to be rewritten."
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
required: ['skill_id', 'content']
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
execute: async (args = {}) => {
|
|
71
|
+
const parsed = parseSkillId(args.skill_id);
|
|
72
|
+
if ('error' in parsed && parsed.error)
|
|
73
|
+
return { success: false, error: parsed.error };
|
|
74
|
+
if (!parsed.domain || !parsed.name)
|
|
75
|
+
return { success: false, error: 'Invalid skill id' };
|
|
76
|
+
const content = typeof args.content === 'string' ? args.content : '';
|
|
77
|
+
if (!content.trim()) {
|
|
78
|
+
return { success: false, error: 'content is required — write the whole SKILL.md' };
|
|
79
|
+
}
|
|
80
|
+
if (Buffer.byteLength(content, 'utf8') > MAX_SKILL_BYTES) {
|
|
81
|
+
return {
|
|
82
|
+
success: false,
|
|
83
|
+
error: `the skill is larger than the ${MAX_SKILL_BYTES / 1024} KB limit. A skill this long `
|
|
84
|
+
+ 'will crowd out the task it is meant to help with — split it, or move the detail into '
|
|
85
|
+
+ 'the step that needs it.'
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const problems = contractProblems(content);
|
|
89
|
+
if (problems.length > 0) {
|
|
90
|
+
return {
|
|
91
|
+
success: false,
|
|
92
|
+
error: 'the skill does not meet the contract:\n'
|
|
93
|
+
+ problems.map((problem) => ` - ${problem}`).join('\n')
|
|
94
|
+
+ '\n\nRewrite it with those fixed and call skill_create again.'
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const written = writeUserSkill({
|
|
98
|
+
domain: parsed.domain,
|
|
99
|
+
name: parsed.name,
|
|
100
|
+
content,
|
|
101
|
+
overwrite: args.overwrite === true
|
|
102
|
+
});
|
|
103
|
+
if (!written.ok)
|
|
104
|
+
return { success: false, error: written.error ?? 'could not write skill' };
|
|
105
|
+
// The catalogue is cached; a skill written now must be visible now.
|
|
106
|
+
invalidateUserSkills();
|
|
107
|
+
return {
|
|
108
|
+
success: true,
|
|
109
|
+
result: `Wrote ${parsed.domain}/${parsed.name} to ${written.path}\n\n`
|
|
110
|
+
+ `It is now in the user's library alongside the built-in skills, and it shadows a `
|
|
111
|
+
+ `built-in of the same id. They can see it with /skill mine, read it with `
|
|
112
|
+
+ `/skills ${parsed.domain}/${parsed.name}, and edit the file directly at `
|
|
113
|
+
+ `${userSkillsRoot()}.`
|
|
114
|
+
};
|
|
105
115
|
}
|
|
106
|
-
|
|
107
|
-
const written = writeUserSkill({
|
|
108
|
-
domain: parsed.domain,
|
|
109
|
-
name: parsed.name,
|
|
110
|
-
content,
|
|
111
|
-
overwrite: args.overwrite === true
|
|
112
|
-
});
|
|
113
|
-
if (!written.ok) return { success: false, error: written.error };
|
|
114
|
-
|
|
115
|
-
// The catalogue is cached; a skill written now must be visible now.
|
|
116
|
-
invalidateUserSkills();
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
success: true,
|
|
120
|
-
result: `Wrote ${parsed.domain}/${parsed.name} to ${written.path}\n\n`
|
|
121
|
-
+ `It is now in the user's library alongside the built-in skills, and it shadows a `
|
|
122
|
-
+ `built-in of the same id. They can see it with /skill mine, read it with `
|
|
123
|
-
+ `/skills ${parsed.domain}/${parsed.name}, and edit the file directly at `
|
|
124
|
-
+ `${userSkillsRoot()}.`
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
116
|
};
|
|
128
|
-
|
|
129
117
|
export default createSkill;
|