@causyne/agent 1.20.100 → 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.
@@ -1,38 +1,36 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
-
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
4
3
  import { COMPILED_SKILLS } from './compiledSkills.js';
5
4
  import { loadUserSkills } from './userSkills.js';
6
5
  import { getPluginSkills } from './plugins/pluginManager.js';
7
-
6
+ const compiledSkillsCatalog = COMPILED_SKILLS;
8
7
  // User skills are read from disk, and the disk is slow relative to how often
9
8
  // these functions are called (every completion keystroke asks for the
10
9
  // catalogue). Cache for a moment so typing stays instant, but keep the window
11
10
  // short enough that a skill the agent just wrote shows up without a restart.
12
11
  const USER_CACHE_MS = 2000;
13
12
  let userCache = { at: 0, skills: [], problems: [] };
14
-
15
13
  export function invalidateUserSkills() {
16
- userCache = { at: 0, skills: [], problems: [] };
14
+ userCache = { at: 0, skills: [], problems: [] };
17
15
  }
18
-
19
16
  function userSkills() {
20
- const now = Date.now();
21
- if (now - userCache.at < USER_CACHE_MS) return userCache;
22
- try {
23
- const loaded = loadUserSkills();
24
- userCache = { at: now, skills: loaded.skills, problems: loaded.problems };
25
- } catch (e) {
26
- // A broken skills directory must never stop a session from starting.
27
- userCache = { at: now, skills: [], problems: [`user skills unavailable: ${e.message}`] };
28
- }
29
- return userCache;
17
+ const now = Date.now();
18
+ if (now - userCache.at < USER_CACHE_MS)
19
+ return userCache;
20
+ try {
21
+ const loaded = loadUserSkills();
22
+ userCache = { at: now, skills: loaded.skills, problems: loaded.problems };
23
+ }
24
+ catch (e) {
25
+ // A broken skills directory must never stop a session from starting.
26
+ const msg = e instanceof Error ? e.message : String(e);
27
+ userCache = { at: now, skills: [], problems: [`user skills unavailable: ${msg}`] };
28
+ }
29
+ return userCache;
30
30
  }
31
-
32
31
  export function userSkillProblems() {
33
- return userSkills().problems;
32
+ return userSkills().problems;
34
33
  }
35
-
36
34
  // What a workspace looks like from the outside.
37
35
  //
38
36
  // This used to name four domains, which meant that of the compiled skills only
@@ -43,48 +41,46 @@ export function userSkillProblems() {
43
41
  // Marker files only; no globbing and no directory walking, so detection stays a
44
42
  // handful of stat calls whatever the size of the repository.
45
43
  const DOMAIN_INDICATORS = {
46
- android: ['build.gradle', 'build.gradle.kts', 'app/build.gradle', 'app/build.gradle.kts',
47
- 'app/src/main/AndroidManifest.xml', 'settings.gradle.kts', 'gradlew'],
48
- mobile: ['pubspec.yaml', 'ios/Podfile', 'Podfile', 'app.json', 'metro.config.js',
49
- 'react-native.config.js', 'expo.json'],
50
- web: ['next.config.js', 'next.config.mjs', 'next.config.ts', 'nuxt.config.ts',
44
+ android: ['build.gradle', 'build.gradle.kts', 'app/build.gradle', 'app/build.gradle.kts',
45
+ 'app/src/main/AndroidManifest.xml', 'settings.gradle.kts', 'gradlew'],
46
+ mobile: ['pubspec.yaml', 'ios/Podfile', 'Podfile', 'app.json', 'metro.config.js',
47
+ 'react-native.config.js', 'expo.json'],
48
+ web: ['next.config.js', 'next.config.mjs', 'next.config.ts', 'nuxt.config.ts',
51
49
  'svelte.config.js', 'vue.config.js', 'astro.config.mjs', 'vite.config.js',
52
50
  'vite.config.ts', 'angular.json', 'index.html', 'tailwind.config.js'],
53
- backend: ['package.json', 'go.mod', 'Cargo.toml', 'pom.xml', 'build.sbt',
54
- 'Gemfile', 'composer.json', 'nest-cli.json'],
55
- python: ['requirements.txt', 'pyproject.toml', 'Pipfile', 'setup.py', 'setup.cfg',
56
- 'uv.lock', 'poetry.lock', 'environment.yml'],
57
- devops: ['Dockerfile', 'docker-compose.yml', 'docker-compose.yaml', '.github/workflows',
58
- '.gitlab-ci.yml', 'Jenkinsfile', 'Makefile', '.circleci/config.yml'],
59
- cloud: ['main.tf', 'terraform.tf', 'serverless.yml', 'template.yaml', 'Pulumi.yaml',
60
- 'cdk.json', 'k8s', 'kubernetes', 'helm', 'skaffold.yaml'],
61
- database: ['prisma/schema.prisma', 'migrations', 'alembic.ini', 'knexfile.js',
62
- 'schema.sql', 'db/schema.rb', 'drizzle.config.ts', 'flyway.conf'],
63
- testing: ['jest.config.js', 'jest.config.ts', 'vitest.config.ts', 'playwright.config.ts',
64
- 'cypress.config.js', 'pytest.ini', 'tox.ini', 'tests', 'test', '__tests__'],
65
- security: ['.github/dependabot.yml', 'SECURITY.md', '.snyk', 'socket.yml', 'socket.json'],
66
- design: ['tailwind.config.js', 'tailwind.config.ts', 'styles', 'src/styles',
67
- 'theme.js', 'theme.ts', 'tokens.json', 'postcss.config.js'],
68
- // A 3D/video workspace. Without a rule here the media skills compile into
69
- // the artefact and are unreachable by domain detection — tool_search still
70
- // finds them, but the workspace never volunteers them.
71
- media: ['.blend', 'assets/3d', 'renders', 'blender', 'shots', 'Resolve Projects'],
72
- git: ['.git', '.gitignore', '.gitattributes'],
73
- performance: ['lighthouserc.js', 'lighthouserc.json', '.lighthouserc.yml', 'k6.js',
74
- 'benchmark', 'benchmarks'],
75
- 'ai-engineering': ['.env.example', 'prompts', 'evals', 'langchain.json',
76
- 'llm.config.js', 'openai.json'],
77
- data: ['dbt_project.yml', 'airflow.cfg', 'dags', 'notebooks', '*.ipynb',
78
- 'dvc.yaml', 'great_expectations']
51
+ backend: ['package.json', 'go.mod', 'Cargo.toml', 'pom.xml', 'build.sbt',
52
+ 'Gemfile', 'composer.json', 'nest-cli.json'],
53
+ python: ['requirements.txt', 'pyproject.toml', 'Pipfile', 'setup.py', 'setup.cfg',
54
+ 'uv.lock', 'poetry.lock', 'environment.yml'],
55
+ devops: ['Dockerfile', 'docker-compose.yml', 'docker-compose.yaml', '.github/workflows',
56
+ '.gitlab-ci.yml', 'Jenkinsfile', 'Makefile', '.circleci/config.yml'],
57
+ cloud: ['main.tf', 'terraform.tf', 'serverless.yml', 'template.yaml', 'Pulumi.yaml',
58
+ 'cdk.json', 'k8s', 'kubernetes', 'helm', 'skaffold.yaml'],
59
+ database: ['prisma/schema.prisma', 'migrations', 'alembic.ini', 'knexfile.js',
60
+ 'schema.sql', 'db/schema.rb', 'drizzle.config.ts', 'flyway.conf'],
61
+ testing: ['jest.config.js', 'jest.config.ts', 'vitest.config.ts', 'playwright.config.ts',
62
+ 'cypress.config.js', 'pytest.ini', 'tox.ini', 'tests', 'test', '__tests__'],
63
+ security: ['.github/dependabot.yml', 'SECURITY.md', '.snyk', 'socket.yml', 'socket.json'],
64
+ design: ['tailwind.config.js', 'tailwind.config.ts', 'styles', 'src/styles',
65
+ 'theme.js', 'theme.ts', 'tokens.json', 'postcss.config.js'],
66
+ // A 3D/video workspace. Without a rule here the media skills compile into
67
+ // the artefact and are unreachable by domain detection — tool_search still
68
+ // finds them, but the workspace never volunteers them.
69
+ media: ['.blend', 'assets/3d', 'renders', 'blender', 'shots', 'Resolve Projects'],
70
+ git: ['.git', '.gitignore', '.gitattributes'],
71
+ performance: ['lighthouserc.js', 'lighthouserc.json', '.lighthouserc.yml', 'k6.js',
72
+ 'benchmark', 'benchmarks'],
73
+ 'ai-engineering': ['.env.example', 'prompts', 'evals', 'langchain.json',
74
+ 'llm.config.js', 'openai.json'],
75
+ data: ['dbt_project.yml', 'airflow.cfg', 'dags', 'notebooks', '*.ipynb',
76
+ 'dvc.yaml', 'great_expectations']
79
77
  };
80
-
81
78
  // Domains that apply to every task regardless of what the workspace looks like.
82
79
  //
83
80
  // Design and security are not properties of a file layout — an agent writing a
84
81
  // UI needs the anti-slop direction whether or not a tailwind config exists, and
85
82
  // input validation matters whether or not the repository has a SECURITY.md.
86
83
  const UNIVERSAL_DOMAINS = ['design', 'security'];
87
-
88
84
  // Ceiling on how many skill descriptions may enter the system prompt.
89
85
  //
90
86
  // With 100 skills, injecting every description of every detected domain would
@@ -92,72 +88,66 @@ const UNIVERSAL_DOMAINS = ['design', 'security'];
92
88
  // This is the progressive-disclosure contract: the model sees names and routing
93
89
  // conditions, and pulls a body with fs_read_skill only when one is relevant.
94
90
  const MAX_INDEXED_SKILLS = 40;
95
-
96
91
  export function detectWorkspaceDomains(workspaceRoot) {
97
- if (!workspaceRoot || !fs.existsSync(workspaceRoot)) return UNIVERSAL_DOMAINS.slice();
98
-
99
- const detectedDomains = [];
100
-
101
- for (const [domain, indicators] of Object.entries(DOMAIN_INDICATORS)) {
102
- for (const indicator of indicators) {
103
- // A glob marker means "any file with this extension at the root". Kept to
104
- // one readdir rather than a walk — a recursive search of a large monorepo
105
- // on every task start is not worth one extra domain.
106
- if (indicator.startsWith('*.')) {
92
+ if (!workspaceRoot || !fs.existsSync(workspaceRoot))
93
+ return UNIVERSAL_DOMAINS.slice();
94
+ const detectedDomains = [];
95
+ for (const [domain, indicators] of Object.entries(DOMAIN_INDICATORS)) {
96
+ for (const indicator of indicators) {
97
+ // A glob marker means "any file with this extension at the root". Kept to
98
+ // one readdir rather than a walk — a recursive search of a large monorepo
99
+ // on every task start is not worth one extra domain.
100
+ if (indicator.startsWith('*.')) {
101
+ try {
102
+ const extension = indicator.slice(1);
103
+ if (fs.readdirSync(workspaceRoot).some((name) => name.endsWith(extension))) {
104
+ detectedDomains.push(domain);
105
+ break;
106
+ }
107
+ }
108
+ catch { /* unreadable directory is simply not a match */ }
109
+ continue;
110
+ }
111
+ if (fs.existsSync(path.join(workspaceRoot, indicator))) {
112
+ detectedDomains.push(domain);
113
+ break;
114
+ }
115
+ }
116
+ }
117
+ // Shallow check of immediate subdirectories for Android projects located in subfolders
118
+ if (!detectedDomains.includes('android')) {
107
119
  try {
108
- const extension = indicator.slice(1);
109
- if (fs.readdirSync(workspaceRoot).some((name) => name.endsWith(extension))) {
120
+ const entries = fs.readdirSync(workspaceRoot, { withFileTypes: true });
121
+ for (const entry of entries) {
122
+ if (entry.isDirectory() && !entry.name.startsWith('.') && entry.name !== 'node_modules' && entry.name !== 'Library') {
123
+ const subDir = path.join(workspaceRoot, entry.name);
124
+ if (fs.existsSync(path.join(subDir, 'build.gradle')) ||
125
+ fs.existsSync(path.join(subDir, 'build.gradle.kts')) ||
126
+ fs.existsSync(path.join(subDir, 'gradlew')) ||
127
+ fs.existsSync(path.join(subDir, 'app/build.gradle')) ||
128
+ fs.existsSync(path.join(subDir, 'app/build.gradle.kts')) ||
129
+ fs.existsSync(path.join(subDir, 'app/src/main/AndroidManifest.xml'))) {
130
+ detectedDomains.push('android');
131
+ break;
132
+ }
133
+ }
134
+ }
135
+ }
136
+ catch { /* unreadable directory is simply skipped */ }
137
+ }
138
+ for (const domain of UNIVERSAL_DOMAINS) {
139
+ if (!detectedDomains.includes(domain))
110
140
  detectedDomains.push(domain);
111
- break;
112
- }
113
- } catch (e) { /* unreadable directory is simply not a match */ }
114
- continue;
115
- }
116
- if (fs.existsSync(path.join(workspaceRoot, indicator))) {
117
- detectedDomains.push(domain);
118
- break;
119
- }
120
141
  }
121
- }
122
-
123
- // Shallow check of immediate subdirectories for Android projects located in subfolders
124
- if (!detectedDomains.includes('android')) {
125
- try {
126
- const entries = fs.readdirSync(workspaceRoot, { withFileTypes: true });
127
- for (const entry of entries) {
128
- if (entry.isDirectory() && !entry.name.startsWith('.') && entry.name !== 'node_modules' && entry.name !== 'Library') {
129
- const subDir = path.join(workspaceRoot, entry.name);
130
- if (fs.existsSync(path.join(subDir, 'build.gradle')) ||
131
- fs.existsSync(path.join(subDir, 'build.gradle.kts')) ||
132
- fs.existsSync(path.join(subDir, 'gradlew')) ||
133
- fs.existsSync(path.join(subDir, 'app/build.gradle')) ||
134
- fs.existsSync(path.join(subDir, 'app/build.gradle.kts')) ||
135
- fs.existsSync(path.join(subDir, 'app/src/main/AndroidManifest.xml'))) {
136
- detectedDomains.push('android');
137
- break;
138
- }
139
- }
140
- }
141
- } catch (e) { /* unreadable directory is simply skipped */ }
142
- }
143
-
144
- for (const domain of UNIVERSAL_DOMAINS) {
145
- if (!detectedDomains.includes(domain)) detectedDomains.push(domain);
146
- }
147
-
148
- return detectedDomains;
142
+ return detectedDomains;
149
143
  }
150
-
151
144
  export { MAX_INDEXED_SKILLS, UNIVERSAL_DOMAINS };
152
-
153
145
  export function ensureSkillRepo(domain) {
154
-
155
- if (COMPILED_SKILLS[domain]) {
156
- return true;
157
- }
158
- return false;
146
+ if (compiledSkillsCatalog[domain]) {
147
+ return true;
148
+ }
149
+ return false;
159
150
  }
160
-
161
151
  /**
162
152
  * The index the model sees: names and routing conditions, never bodies.
163
153
  *
@@ -173,54 +163,49 @@ export function ensureSkillRepo(domain) {
173
163
  * the cut falls on the least relevant.
174
164
  */
175
165
  export function getUniversalSkillsIndex(domains) {
176
- let indexText = '';
177
- let totalSkillsCount = 0;
178
-
179
- // One catalogue, so a user skill is as visible to the agent as a compiled one.
180
- const catalogue = new Map();
181
- for (const skill of listCompiledSkills()) {
182
- if (!catalogue.has(skill.domain)) catalogue.set(skill.domain, []);
183
- catalogue.get(skill.domain).push(skill);
184
- }
185
-
186
- // A user's own domains are always offered: someone who wrote a `team/` skill
187
- // wants it considered, and no marker file in the workspace announces it.
188
- const ownDomains = [...new Set(userSkills().skills.map((skill) => skill.domain))];
189
- const wanted = [...new Set([...ownDomains, ...domains])];
190
-
191
- for (const domain of wanted) {
192
- const domainSkills = catalogue.get(domain);
193
- if (!domainSkills || domainSkills.length === 0) continue;
194
- if (totalSkillsCount >= MAX_INDEXED_SKILLS) break;
195
-
196
- let domainSkillsCount = 0;
197
- let domainIndexText = `### ${domain.toUpperCase()} SKILLS\n`;
198
-
199
- for (const skill of domainSkills) {
200
- if (totalSkillsCount + domainSkillsCount >= MAX_INDEXED_SKILLS) break;
201
- const mark = skill.source === 'user' ? ' [your own]' : '';
202
- const safeName = String(skill.name || skill.id).replace(/[<>]/g, '');
203
- const safeDesc = String(skill.description || '').replace(/[<>]/g, '');
204
- domainIndexText += `- **${safeName}**${mark} (ID: ${domain}/${skill.id}): ${safeDesc}\n`;
205
- domainSkillsCount++;
166
+ let indexText = '';
167
+ let totalSkillsCount = 0;
168
+ // One catalogue, so a user skill is as visible to the agent as a compiled one.
169
+ const catalogue = new Map();
170
+ for (const skill of listCompiledSkills()) {
171
+ if (!catalogue.has(skill.domain))
172
+ catalogue.set(skill.domain, []);
173
+ catalogue.get(skill.domain).push(skill);
206
174
  }
207
-
208
- if (domainSkillsCount > 0) {
209
- indexText += domainIndexText + '\n';
210
- totalSkillsCount += domainSkillsCount;
175
+ // A user's own domains are always offered: someone who wrote a `team/` skill
176
+ // wants it considered, and no marker file in the workspace announces it.
177
+ const ownDomains = [...new Set(userSkills().skills.map((skill) => skill.domain))];
178
+ const wanted = [...new Set([...ownDomains, ...domains])];
179
+ for (const domain of wanted) {
180
+ const domainSkills = catalogue.get(domain);
181
+ if (!domainSkills || domainSkills.length === 0)
182
+ continue;
183
+ if (totalSkillsCount >= MAX_INDEXED_SKILLS)
184
+ break;
185
+ let domainSkillsCount = 0;
186
+ let domainIndexText = `### ${domain.toUpperCase()} SKILLS\n`;
187
+ for (const skill of domainSkills) {
188
+ if (totalSkillsCount + domainSkillsCount >= MAX_INDEXED_SKILLS)
189
+ break;
190
+ const mark = skill.source === 'user' ? ' [your own]' : '';
191
+ const safeName = String(skill.name || skill.id).replace(/[<>]/g, '');
192
+ const safeDesc = String(skill.description || '').replace(/[<>]/g, '');
193
+ domainIndexText += `- **${safeName}**${mark} (ID: ${domain}/${skill.id}): ${safeDesc}\n`;
194
+ domainSkillsCount++;
195
+ }
196
+ if (domainSkillsCount > 0) {
197
+ indexText += domainIndexText + '\n';
198
+ totalSkillsCount += domainSkillsCount;
199
+ }
211
200
  }
212
- }
213
-
214
- if (totalSkillsCount === 0) return '';
215
-
216
- let finalOutput = `\n<causyne_universal_skills>\n`;
217
- 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`;
218
- finalOutput += indexText;
219
- finalOutput += `</causyne_universal_skills>\n`;
220
-
221
- return finalOutput;
201
+ if (totalSkillsCount === 0)
202
+ return '';
203
+ let finalOutput = `\n<causyne_universal_skills>\n`;
204
+ 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`;
205
+ finalOutput += indexText;
206
+ finalOutput += `</causyne_universal_skills>\n`;
207
+ return finalOutput;
222
208
  }
223
-
224
209
  /**
225
210
  * The compact form of the skills index: what domains exist and how to search
226
211
  * them, instead of forty name-and-description lines.
@@ -235,30 +220,28 @@ export function getUniversalSkillsIndex(domains) {
235
220
  * a capability regression wearing an optimisation's clothes. Retrieval replaces
236
221
  * a catalogue only once the retrieval exists.
237
222
  *
238
- * @param {Set|Array} domains Workspace domains detected for this task.
239
- * @returns {string} System-prompt fragment, '' when nothing exists.
223
+ * @param domains Workspace domains detected for this task.
224
+ * @returns System-prompt fragment, '' when nothing exists.
240
225
  */
241
226
  export function getSkillDomainHeader(domains) {
242
- const catalogue = new Map();
243
- for (const skill of listCompiledSkills()) {
244
- catalogue.set(skill.domain, (catalogue.get(skill.domain) || 0) + 1);
245
- }
246
- if (catalogue.size === 0) return '';
247
-
248
- const total = [...catalogue.values()].reduce((sum, n) => sum + n, 0);
249
- const relevant = [...new Set(domains || [])].filter(d => catalogue.has(d));
250
- const all = [...catalogue.keys()].sort();
251
-
252
- let out = `\n<causyne_universal_skills>\n`;
253
- out += `${total} curated engineering skills are compiled into you, across: ${all.join(', ')}.\n`;
254
- if (relevant.length > 0) {
255
- out += `This workspace looks like: ${relevant.join(', ')}.\n`;
256
- }
257
- 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`;
258
- out += `</causyne_universal_skills>\n`;
259
- return out;
227
+ const catalogue = new Map();
228
+ for (const skill of listCompiledSkills()) {
229
+ catalogue.set(skill.domain, (catalogue.get(skill.domain) || 0) + 1);
230
+ }
231
+ if (catalogue.size === 0)
232
+ return '';
233
+ const total = [...catalogue.values()].reduce((sum, n) => sum + n, 0);
234
+ const relevant = [...new Set(domains || [])].filter((d) => catalogue.has(d));
235
+ const all = [...catalogue.keys()].sort();
236
+ let out = `\n<causyne_universal_skills>\n`;
237
+ out += `${total} curated engineering skills are compiled into you, across: ${all.join(', ')}.\n`;
238
+ if (relevant.length > 0) {
239
+ out += `This workspace looks like: ${relevant.join(', ')}.\n`;
240
+ }
241
+ 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`;
242
+ out += `</causyne_universal_skills>\n`;
243
+ return out;
260
244
  }
261
-
262
245
  /**
263
246
  * The whole catalogue as a flat list, for the picker and for `/skills`.
264
247
  *
@@ -266,64 +249,71 @@ export function getSkillDomainHeader(domains) {
266
249
  * never disagree about what exists.
267
250
  */
268
251
  export function listCompiledSkills() {
269
- const out = [];
270
- const seen = new Set();
271
-
272
- // The user's own skills come first and SHADOW a compiled skill of the same
273
- // id. That is the customisation: someone whose deployment genuinely differs
274
- // from the shipped procedure writes their own `devops/zero-downtime-deploys`
275
- // and theirs is the one the agent reads. Shipping a library that cannot be
276
- // corrected is shipping an opinion.
277
- for (const skill of userSkills().skills) {
278
- const key = `${skill.domain}/${skill.id}`;
279
- seen.add(key);
280
- out.push({
281
- domain: skill.domain, id: skill.id, name: skill.name,
282
- description: skill.description, source: 'user'
283
- });
284
- }
285
-
286
- // Plugin skills live in a plugin-owned namespace (`plugin-<name>/...`) and
287
- // appear only after explicit digest-pinned enablement. A user's own skill can
288
- // still shadow one, which preserves local authority over every instruction.
289
- for (const skill of getPluginSkills()) {
290
- const key = `${skill.domain}/${skill.id}`;
291
- if (seen.has(key)) continue;
292
- seen.add(key);
293
- out.push({
294
- domain: skill.domain, id: skill.id, name: skill.name,
295
- description: skill.description, source: 'plugin'
296
- });
297
- }
298
-
299
- for (const [domain, skills] of Object.entries(COMPILED_SKILLS)) {
300
- for (const [id, data] of Object.entries(skills)) {
301
- if (seen.has(`${domain}/${id}`)) continue;
302
- out.push({
303
- domain, id, name: data.name || id,
304
- description: data.description || '', source: 'native'
305
- });
252
+ const out = [];
253
+ const seen = new Set();
254
+ // The user's own skills come first and SHADOW a compiled skill of the same
255
+ // id. That is the customisation: someone whose deployment genuinely differs
256
+ // from the shipped procedure writes their own `devops/zero-downtime-deploys`
257
+ // and theirs is the one the agent reads. Shipping a library that cannot be
258
+ // corrected is shipping an opinion.
259
+ for (const skill of userSkills().skills) {
260
+ const key = `${skill.domain}/${skill.id}`;
261
+ seen.add(key);
262
+ out.push({
263
+ domain: skill.domain,
264
+ id: skill.id,
265
+ name: skill.name,
266
+ description: skill.description,
267
+ source: 'user'
268
+ });
269
+ }
270
+ // Plugin skills live in a plugin-owned namespace (`plugin-<name>/...`) and
271
+ // appear only after explicit digest-pinned enablement. A user's own skill can
272
+ // still shadow one, which preserves local authority over every instruction.
273
+ for (const skill of getPluginSkills()) {
274
+ const key = `${skill.domain}/${skill.id}`;
275
+ if (seen.has(key))
276
+ continue;
277
+ seen.add(key);
278
+ out.push({
279
+ domain: skill.domain,
280
+ id: skill.id,
281
+ name: skill.name || skill.id,
282
+ description: skill.description || '',
283
+ source: 'plugin'
284
+ });
285
+ }
286
+ for (const [domain, skills] of Object.entries(compiledSkillsCatalog)) {
287
+ for (const [id, data] of Object.entries(skills)) {
288
+ if (seen.has(`${domain}/${id}`))
289
+ continue;
290
+ out.push({
291
+ domain,
292
+ id,
293
+ name: data.name || id,
294
+ description: data.description || '',
295
+ source: 'native'
296
+ });
297
+ }
306
298
  }
307
- }
308
- return out;
299
+ return out;
309
300
  }
310
-
311
301
  export function readCompiledSkill(domain, skillId) {
312
- // A user skill of the same id wins, for the same reason it does in the
313
- // listing: the user's version is the corrected one.
314
- const own = userSkills().skills
315
- .find((skill) => skill.domain === domain && skill.id === skillId);
316
- if (own) return own.content;
317
-
318
- const pluginSkill = getPluginSkills()
319
- .find((skill) => skill.domain === domain && skill.id === skillId);
320
- if (pluginSkill) return pluginSkill.content;
321
-
322
- const domainSkills = COMPILED_SKILLS[domain];
323
- if (!domainSkills) return `Error: Domain ${domain} not found in compiled skills.`;
324
-
325
- const skillData = domainSkills[skillId];
326
- if (!skillData) return `Error: Skill ${skillId} not found in domain ${domain}.`;
327
-
328
- return skillData.content;
302
+ // A user skill of the same id wins, for the same reason it does in the
303
+ // listing: the user's version is the corrected one.
304
+ const own = userSkills().skills
305
+ .find((skill) => skill.domain === domain && skill.id === skillId);
306
+ if (own)
307
+ return own.content;
308
+ const pluginSkill = getPluginSkills()
309
+ .find((skill) => skill.domain === domain && skill.id === skillId);
310
+ if (pluginSkill)
311
+ return pluginSkill.content;
312
+ const domainSkills = compiledSkillsCatalog[domain];
313
+ if (!domainSkills)
314
+ return `Error: Domain ${domain} not found in compiled skills.`;
315
+ const skillData = domainSkills[skillId];
316
+ if (!skillData)
317
+ return `Error: Skill ${skillId} not found in domain ${domain}.`;
318
+ return skillData.content;
329
319
  }