cognitive-core 0.2.3 → 0.2.5

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.
Files changed (30) hide show
  1. package/dist/surfacing/skill-publisher.d.ts +3 -3
  2. package/dist/surfacing/skill-publisher.d.ts.map +1 -1
  3. package/dist/surfacing/skill-publisher.js +90 -41
  4. package/dist/surfacing/skill-publisher.js.map +1 -1
  5. package/dist/surfacing/sqlite-storage-adapter.d.ts +2 -2
  6. package/dist/surfacing/sqlite-storage-adapter.d.ts.map +1 -1
  7. package/dist/surfacing/sqlite-storage-adapter.js +15 -10
  8. package/dist/surfacing/sqlite-storage-adapter.js.map +1 -1
  9. package/dist/types/playbook.d.ts +11 -0
  10. package/dist/types/playbook.d.ts.map +1 -1
  11. package/dist/types/playbook.js +2 -0
  12. package/dist/types/playbook.js.map +1 -1
  13. package/dist/workspace/templates/index.d.ts +1 -0
  14. package/dist/workspace/templates/index.d.ts.map +1 -1
  15. package/dist/workspace/templates/index.js +2 -0
  16. package/dist/workspace/templates/index.js.map +1 -1
  17. package/dist/workspace/templates/skill-enrichment.d.ts +48 -0
  18. package/dist/workspace/templates/skill-enrichment.d.ts.map +1 -0
  19. package/dist/workspace/templates/skill-enrichment.js +175 -0
  20. package/dist/workspace/templates/skill-enrichment.js.map +1 -0
  21. package/package.json +4 -4
  22. package/src/surfacing/skill-publisher.ts +116 -49
  23. package/src/surfacing/sqlite-storage-adapter.ts +14 -12
  24. package/src/types/playbook.ts +15 -0
  25. package/src/workspace/templates/index.ts +7 -0
  26. package/src/workspace/templates/skill-enrichment.ts +275 -0
  27. package/tests/integration/ranking-driven-loadout-e2e.test.ts +185 -0
  28. package/tests/integration/skill-publishing-filesystem-e2e.test.ts +216 -0
  29. package/tests/surfacing/skill-publisher.test.ts +86 -18
  30. package/tests/surfacing/sqlite-storage-adapter.test.ts +0 -9
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Skill Enrichment Template
3
+ *
4
+ * Agent-in-the-loop step between playbook extraction and skill publishing.
5
+ * Given a Playbook and its procedurally generated SKILL.md skeleton, an agent
6
+ * enriches the skill with narrative prose, worked examples, cross-references,
7
+ * and a trigger-rich description — things a procedural converter cannot produce.
8
+ *
9
+ * Complexity routing:
10
+ * - Simple playbooks (<=3 tactics, low complexity) → heuristic: keep procedural output as-is
11
+ * - Standard/complex playbooks → agent enrichment
12
+ */
13
+ import { convertPlaybookToSkill } from '../../surfacing/skill-publisher.js';
14
+ // ============================================================
15
+ // Template Implementation
16
+ // ============================================================
17
+ export const skillEnrichmentTemplate = {
18
+ taskType: 'skill-enrichment',
19
+ domain: 'skill-publishing',
20
+ description: 'Enrich a procedurally generated SKILL.md with narrative prose, examples, and cross-references',
21
+ assessComplexity(input) {
22
+ const pb = input.playbook;
23
+ const tacticCount = pb.guidance.tactics.length;
24
+ const hasSteps = (pb.guidance.steps?.length ?? 0) > 0;
25
+ const isComplex = pb.complexity === 'complex';
26
+ if (tacticCount <= 3 && !hasSteps && !isComplex)
27
+ return 'heuristic';
28
+ if (isComplex || tacticCount > 8)
29
+ return 'thorough';
30
+ return 'standard';
31
+ },
32
+ async heuristicFallback(input) {
33
+ const skill = convertPlaybookToSkill(input.playbook);
34
+ return {
35
+ description: skill.description,
36
+ instructions: skill.instructions,
37
+ examples: [],
38
+ seeAlso: (input.relatedSkills ?? []).map((r) => ({
39
+ name: r.name,
40
+ relation: `Related: ${r.description}`,
41
+ })),
42
+ gaps: [],
43
+ };
44
+ },
45
+ async prepareWorkspace(input, handle) {
46
+ // Write the playbook as structured JSON
47
+ await handle.writeJson('input', 'playbook.json', {
48
+ name: input.playbook.name,
49
+ applicability: input.playbook.applicability,
50
+ guidance: input.playbook.guidance,
51
+ verification: input.playbook.verification,
52
+ complexity: input.playbook.complexity,
53
+ confidence: input.playbook.confidence,
54
+ evolution: {
55
+ version: input.playbook.evolution.version,
56
+ successCount: input.playbook.evolution.successCount,
57
+ failureCount: input.playbook.evolution.failureCount,
58
+ refinements: input.playbook.evolution.refinements,
59
+ },
60
+ provenance: input.playbook.provenance,
61
+ userInvocable: input.playbook.userInvocable,
62
+ publishMetadata: input.playbook.publishMetadata,
63
+ });
64
+ // Write the procedural skeleton for the agent to improve upon
65
+ const skill = convertPlaybookToSkill(input.playbook);
66
+ await handle.writeRaw('input', 'skeleton.md', skill.instructions);
67
+ await handle.writeRaw('input', 'skeleton-description.txt', skill.description);
68
+ // Style reference (if provided)
69
+ if (input.styleReference) {
70
+ await handle.writeRaw('input', 'style-reference.md', input.styleReference);
71
+ }
72
+ // Related skills for cross-referencing
73
+ if (input.relatedSkills && input.relatedSkills.length > 0) {
74
+ await handle.writeJson('input', 'related-skills.json', input.relatedSkills);
75
+ }
76
+ // Domain context
77
+ if (input.domainContext) {
78
+ await handle.writeRaw('input', 'domain-context.txt', input.domainContext);
79
+ }
80
+ },
81
+ buildTaskPrompt(input) {
82
+ const parts = [
83
+ `Enrich the skill "${input.playbook.name}" into a high-quality SKILL.md that an AI agent will load and follow.`,
84
+ '',
85
+ '## Inputs',
86
+ '',
87
+ '- `input/playbook.json` — the structured playbook (applicability, guidance, verification)',
88
+ '- `input/skeleton.md` — procedurally generated markdown body (your starting point)',
89
+ '- `input/skeleton-description.txt` — procedurally generated frontmatter description',
90
+ ];
91
+ if (input.styleReference) {
92
+ parts.push('- `input/style-reference.md` — a hand-written SKILL.md to match in tone and structure');
93
+ }
94
+ if (input.relatedSkills && input.relatedSkills.length > 0) {
95
+ parts.push('- `input/related-skills.json` — related skills to cross-reference');
96
+ }
97
+ if (input.domainContext) {
98
+ parts.push('- `input/domain-context.txt` — domain context for accurate terminology');
99
+ }
100
+ parts.push('', '## What to produce', '', 'Read all inputs, then write `output/enrichment.json` with this schema:', '', '```json', '{', ' "description": "Trigger-rich frontmatter description, under 1024 chars. Structure: [What it does] + [Use when ...trigger phrases...]. Include concrete phrases users would say.",', ' "instructions": "Full markdown body. Must include:\\n- ## When to use (bulleted)\\n- ## When not to use (bulleted)\\n- ## Workflow (numbered tactics expanded into full prose — explain WHY each step matters, not just WHAT to do)\\n- ## Inputs / ## Outputs\\n- ## Verification (bulleted success/failure indicators)\\n- ## Edge cases (narrative, with recovery paths)\\n- ## Examples (2-3 worked scenarios with concrete commands)\\n- ## See also (cross-references)",', ' "examples": [{"title": "...", "scenario": "...", "steps": "..."}],', ' "seeAlso": [{"name": "skill-name", "relation": "why it is related"}],', ' "gaps": ["anything missing from the playbook that the skill should cover but cannot without more data"]', '}', '```', '', '## Guidelines', '', '- The skeleton is your starting point — improve it, do not discard it.', '- Expand each tactic in the Workflow section into a paragraph that explains the rationale, not just the command.', '- Generate 2-3 realistic examples with concrete tool calls (MCP tools, CLI commands, or library calls as appropriate for the domain).', '- Cross-reference related skills by name in the See Also section.', '- Flag gaps honestly — if the playbook is missing triggers, anti-patterns, or verification criteria, say so in the gaps array.', '- Keep the description under 1024 characters. It must include trigger phrases users would actually say.', '- Do not invent capabilities the playbook does not describe. Enrich what is there; do not fabricate.');
101
+ if (input.styleReference) {
102
+ parts.push('- Match the tone, section structure, and level of detail from the style reference.');
103
+ }
104
+ return parts.join('\n');
105
+ },
106
+ getSkills() { return []; },
107
+ getResources(input) {
108
+ const resources = [];
109
+ if (input.domainContext) {
110
+ resources.push({
111
+ type: 'file',
112
+ path: 'domain-context.txt',
113
+ source: input.domainContext,
114
+ description: 'Domain context for accurate terminology',
115
+ });
116
+ }
117
+ return resources;
118
+ },
119
+ outputConfig: {
120
+ files: [
121
+ {
122
+ path: 'enrichment.json',
123
+ format: 'json',
124
+ required: true,
125
+ description: 'Enriched skill content with description, instructions, examples, cross-refs, and gaps',
126
+ },
127
+ ],
128
+ },
129
+ async collectOutput(handle) {
130
+ const raw = await handle.readJson('output', 'enrichment.json');
131
+ return {
132
+ description: typeof raw.description === 'string'
133
+ ? raw.description.slice(0, 1024)
134
+ : '',
135
+ instructions: typeof raw.instructions === 'string'
136
+ ? raw.instructions
137
+ : '',
138
+ examples: Array.isArray(raw.examples)
139
+ ? raw.examples.map((e) => ({
140
+ title: String(e.title ?? ''),
141
+ scenario: String(e.scenario ?? ''),
142
+ steps: String(e.steps ?? ''),
143
+ }))
144
+ : [],
145
+ seeAlso: Array.isArray(raw.seeAlso)
146
+ ? raw.seeAlso.map((s) => ({
147
+ name: String(s.name ?? ''),
148
+ relation: String(s.relation ?? ''),
149
+ }))
150
+ : [],
151
+ gaps: Array.isArray(raw.gaps)
152
+ ? raw.gaps.map(String)
153
+ : [],
154
+ };
155
+ },
156
+ async processOutput() {
157
+ // Caller handles merging the enriched output back into the Skill
158
+ // and publishing via SkillPublisher.
159
+ },
160
+ computeRequirements: {
161
+ mode: 'local',
162
+ complexity: 'standard',
163
+ },
164
+ getComputeRequirements(_input, complexity) {
165
+ return {
166
+ mode: 'local',
167
+ complexity,
168
+ timeout: complexity === 'thorough' ? 300_000 : 180_000,
169
+ };
170
+ },
171
+ agentType: 'claude-code',
172
+ timeout: 180_000,
173
+ captureToolCalls: true,
174
+ };
175
+ //# sourceMappingURL=skill-enrichment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-enrichment.js","sourceRoot":"","sources":["../../../src/workspace/templates/skill-enrichment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AA2C5E,+DAA+D;AAC/D,0BAA0B;AAC1B,+DAA+D;AAE/D,MAAM,CAAC,MAAM,uBAAuB,GAGhC;IACF,QAAQ,EAAE,kBAAkB;IAC5B,MAAM,EAAE,kBAAkB;IAC1B,WAAW,EAAE,+FAA+F;IAE5G,gBAAgB,CAAC,KAA2B;QAC1C,MAAM,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC1B,MAAM,WAAW,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC;QAC/C,MAAM,QAAQ,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,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AO,CAAC;gBACjC,CAAC,CAAE,GAAG,CAAC,OAA0C,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;oBAC5D,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;oBAC1B,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC;iBACnC,CAAC,CAAC;gBACH,CAAC,CAAC,EAAE;YACN,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;gBAC3B,CAAC,CAAE,GAAG,CAAC,IAAuB,CAAC,GAAG,CAAC,MAAM,CAAC;gBAC1C,CAAC,CAAC,EAAE;SACP,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,iEAAiE;QACjE,qCAAqC;IACvC,CAAC;IAED,mBAAmB,EAAE;QACnB,IAAI,EAAE,OAAO;QACb,UAAU,EAAE,UAAU;KACvB;IAED,sBAAsB,CACpB,MAA4B,EAC5B,UAA8B;QAE9B,OAAO;YACL,IAAI,EAAE,OAAO;YACb,UAAU;YACV,OAAO,EAAE,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO;SACvD,CAAC;IACJ,CAAC;IAED,SAAS,EAAE,aAAa;IACxB,OAAO,EAAE,OAAO;IAChB,gBAAgB,EAAE,IAAI;CACvB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cognitive-core",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "TypeScript-native cognitive core for adaptive learning and abstraction",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -65,7 +65,7 @@
65
65
  "author": "Alex Ngai",
66
66
  "license": "MIT",
67
67
  "devDependencies": {
68
- "@types/better-sqlite3": "^7.6.8",
68
+ "@types/better-sqlite3": "^7.6.12",
69
69
  "@types/node": "^20.10.0",
70
70
  "eslint": "^8.55.0",
71
71
  "typescript": "^5.3.0",
@@ -74,10 +74,10 @@
74
74
  "dependencies": {
75
75
  "acp-factory": "^0.1.14",
76
76
  "agent-workspace": "^0.1.5",
77
- "better-sqlite3": "^9.0.0",
77
+ "better-sqlite3": "^12.0.0",
78
78
  "minimem": "^0.1.0",
79
79
  "sessionlog": "^0.0.4",
80
- "skill-tree": "^0.1.5",
80
+ "skill-tree": "^0.2.0",
81
81
  "sqlite-vec": "^0.1.6",
82
82
  "yaml": "^2.8.2",
83
83
  "zod": "^3.22.0"
@@ -6,64 +6,130 @@
6
6
  * conversion at the publish boundary.
7
7
  */
8
8
 
9
- import type { Skill, StorageAdapter } from 'skill-tree';
10
- import type { Playbook } from '../types/index.js';
11
- import type { PublishResult, DeprecateResult } from './publisher.js';
12
- import { getPlaybookSuccessRate } from '../types/playbook.js';
9
+ import type { Skill, StorageAdapter } from "skill-tree";
10
+ import type { Playbook } from "../types/index.js";
11
+ import type { PublishResult, DeprecateResult } from "./publisher.js";
12
+
13
+ /**
14
+ * Maximum length for the generated `description` field.
15
+ * Claude Code's skill format caps description at 1024 chars, so we truncate
16
+ * to stay safely within that boundary.
17
+ */
18
+ const MAX_DESCRIPTION_LENGTH = 1024;
19
+
20
+ /**
21
+ * Build the `description` field for a published Skill.
22
+ *
23
+ * The description is what lightweight trigger matchers — notably Claude Code's
24
+ * skill loader — key off to decide whether to load a skill. It needs two things:
25
+ *
26
+ * 1. A short "what it does" lead (pulled from the first situation, or the
27
+ * strategy if no situation is set).
28
+ * 2. The concrete trigger phrases, surfaced inline so substring/keyword
29
+ * matchers catch them. These live in `applicability.triggers` on the
30
+ * playbook but are invisible to downstream consumers unless we lift them.
31
+ *
32
+ * Shape: `<lead>. Use when "<t1>", "<t2>", ..., "<tN>".`
33
+ */
34
+ function buildDescription(playbook: Playbook): string {
35
+ let lead = playbook.applicability.situations[0]
36
+ ?? `${playbook.name}: ${playbook.guidance.strategy.slice(0, 100)}`;
37
+
38
+ // Ensure a sentence terminator before appending the trigger clause.
39
+ if (lead.length > 0 && !/[.!?]$/.test(lead)) {
40
+ lead += '.';
41
+ }
42
+
43
+ const triggers = playbook.applicability.triggers;
44
+ const triggerClause = triggers.length > 0
45
+ ? ` Use when ${triggers.map((t) => `"${t}"`).join(', ')}.`
46
+ : '';
47
+
48
+ const full = lead + triggerClause;
49
+ if (full.length <= MAX_DESCRIPTION_LENGTH) return full;
50
+ return full.slice(0, MAX_DESCRIPTION_LENGTH - 3) + '...';
51
+ }
13
52
 
14
53
  /**
15
54
  * Convert a Playbook to a Skill
16
55
  */
17
56
  export function convertPlaybookToSkill(playbook: Playbook): Skill {
18
- const totalUses = playbook.evolution.successCount + playbook.evolution.failureCount;
19
- const successRate = getPlaybookSuccessRate(playbook);
20
-
21
57
  // Build solution text from guidance
22
58
  let solution = playbook.guidance.strategy;
23
59
  if (playbook.guidance.tactics.length > 0) {
24
- solution += '\n\nTactics:\n' + playbook.guidance.tactics.map((t, i) => `${i + 1}. ${t}`).join('\n');
60
+ solution +=
61
+ "\n\nTactics:\n" +
62
+ playbook.guidance.tactics.map((t, i) => `${i + 1}. ${t}`).join("\n");
25
63
  }
26
64
  if (playbook.guidance.steps?.length) {
27
- solution += '\n\nSteps:\n' + playbook.guidance.steps.map((s, i) => `${i + 1}. ${s}`).join('\n');
65
+ solution +=
66
+ "\n\nSteps:\n" +
67
+ playbook.guidance.steps.map((s, i) => `${i + 1}. ${s}`).join("\n");
28
68
  }
29
69
 
30
- // Build verification text
31
- const verification = playbook.verification.successIndicators.length > 0
32
- ? playbook.verification.successIndicators.join('. ')
33
- : 'Verify the approach worked as expected.';
70
+ // Build description for semantic matching and lightweight trigger routing
71
+ const description = buildDescription(playbook);
34
72
 
35
- // Build notes from anti-patterns and refinements
36
- const notesParts: string[] = [];
73
+ // Build structured instructions body
74
+ const instructionParts: string[] = [];
75
+
76
+ // --- When to use / When not to use (Change A) ---
77
+ if (playbook.applicability.situations.length > 0) {
78
+ instructionParts.push(
79
+ '## When to use\n\n'
80
+ + playbook.applicability.situations.map((s) => `- ${s}`).join('\n'),
81
+ );
82
+ }
37
83
  if (playbook.applicability.antiPatterns.length > 0) {
38
- notesParts.push('Do NOT use when: ' + playbook.applicability.antiPatterns.join('; '));
84
+ instructionParts.push(
85
+ '## When not to use\n\n'
86
+ + playbook.applicability.antiPatterns.map((a) => `- ${a}`).join('\n'),
87
+ );
39
88
  }
40
- if (playbook.verification.failureIndicators.length > 0) {
41
- notesParts.push('Watch for: ' + playbook.verification.failureIndicators.join('; '));
89
+
90
+ // --- Solution ---
91
+ instructionParts.push(`## Solution\n\n${solution}`);
92
+
93
+ // --- Verification with bulleted indicators (Change B) ---
94
+ const verificationParts: string[] = [];
95
+ if (playbook.verification.successIndicators.length > 0) {
96
+ verificationParts.push(
97
+ 'Success:\n'
98
+ + playbook.verification.successIndicators.map((s) => `- ${s}`).join('\n'),
99
+ );
42
100
  }
43
- if (playbook.evolution.refinements.length > 0) {
44
- notesParts.push('Refinements:\n' + playbook.evolution.refinements.map(
45
- r => `- In ${r.context}: ${r.addition}`
46
- ).join('\n'));
101
+ if (playbook.verification.failureIndicators.length > 0) {
102
+ verificationParts.push(
103
+ 'Failure:\n'
104
+ + playbook.verification.failureIndicators.map((f) => `- ${f}`).join('\n'),
105
+ );
47
106
  }
48
107
  if (playbook.verification.rollbackStrategy) {
49
- notesParts.push('Rollback: ' + playbook.verification.rollbackStrategy);
108
+ verificationParts.push(`Rollback: ${playbook.verification.rollbackStrategy}`);
109
+ }
110
+ if (verificationParts.length > 0) {
111
+ instructionParts.push(`## Verification\n\n${verificationParts.join('\n\n')}`);
112
+ } else {
113
+ instructionParts.push('## Verification\n\nVerify the approach worked as expected.');
50
114
  }
51
115
 
52
- // Build description for semantic matching
53
- const description = playbook.applicability.situations[0]
54
- ?? `${playbook.name}: ${playbook.guidance.strategy.slice(0, 100)}`;
55
-
56
- // Build instructions as structured markdown combining all content
57
- const instructionParts: string[] = [];
58
- instructionParts.push(`## Problem\n${playbook.applicability.situations.join('. ')}`);
59
- instructionParts.push(`## Solution\n${solution}`);
60
- instructionParts.push(`## Verification\n${verification}`);
116
+ // --- Notes (refinements only — anti-patterns now in their own section) ---
117
+ const notesParts: string[] = [];
118
+ if (playbook.evolution.refinements.length > 0) {
119
+ notesParts.push(
120
+ 'Refinements:\n'
121
+ + playbook.evolution.refinements.map((r) => `- In ${r.context}: ${r.addition}`).join('\n'),
122
+ );
123
+ }
61
124
  if (notesParts.length > 0) {
62
- instructionParts.push(`## Notes\n${notesParts.join('\n\n')}`);
125
+ instructionParts.push(`## Notes\n\n${notesParts.join('\n\n')}`);
63
126
  }
127
+
128
+ // --- Example ---
64
129
  if (playbook.guidance.codeExample) {
65
- instructionParts.push(`## Example\n\`\`\`\n${playbook.guidance.codeExample}\n\`\`\``);
130
+ instructionParts.push(`## Example\n\n\`\`\`\n${playbook.guidance.codeExample}\n\`\`\``);
66
131
  }
132
+
67
133
  const instructions = instructionParts.join('\n\n');
68
134
 
69
135
  // Estimate tokens (rough: 4 chars per token)
@@ -75,23 +141,19 @@ export function convertPlaybookToSkill(playbook: Playbook): Skill {
75
141
  version: playbook.evolution.version,
76
142
  description,
77
143
  instructions,
78
- author: 'cognitive-core',
144
+ author: playbook.provenance?.curatedBy ?? 'cognitive-core',
79
145
  tags: playbook.applicability.domains,
80
- status: 'active',
81
- metrics: {
82
- usageCount: totalUses,
83
- successRate,
84
- lastUsed: playbook.evolution.lastUsed,
85
- feedbackScores: [],
86
- averageConfidence: playbook.confidence,
87
- },
146
+ status: "active",
88
147
  source: {
89
- type: 'extracted',
148
+ type: "extracted",
90
149
  sessionId: playbook.evolution.createdFrom[0],
91
150
  importedAt: playbook.createdAt,
92
151
  },
93
152
  serving: {
94
- summary: description.length > 150 ? description.slice(0, 147) + '...' : description,
153
+ summary:
154
+ description.length > 150
155
+ ? description.slice(0, 147) + "..."
156
+ : description,
95
157
  tokenEstimate,
96
158
  },
97
159
  createdAt: playbook.createdAt,
@@ -152,15 +214,20 @@ export class SkillPublisher {
152
214
  /**
153
215
  * Deprecate a skill in storage
154
216
  */
155
- async deprecateSkill(skillId: string, reason: string): Promise<DeprecateResult> {
217
+ async deprecateSkill(
218
+ skillId: string,
219
+ reason: string,
220
+ ): Promise<DeprecateResult> {
156
221
  try {
157
222
  const existing = await this.storage.getSkill(skillId);
158
223
  if (!existing) {
159
- return { deprecated: false, skillId, error: 'Skill not found' };
224
+ return { deprecated: false, skillId, error: "Skill not found" };
160
225
  }
161
226
 
162
- existing.status = 'deprecated';
163
- existing.description = (existing.description ? existing.description + ' ' : '') + `[Deprecated: ${reason}]`;
227
+ existing.status = "deprecated";
228
+ existing.description =
229
+ (existing.description ? existing.description + " " : "") +
230
+ `[Deprecated: ${reason}]`;
164
231
  existing.updatedAt = new Date();
165
232
  await this.storage.saveSkill(existing);
166
233
 
@@ -23,7 +23,6 @@ interface SkillRow {
23
23
  author: string | null;
24
24
  status: string;
25
25
  tags: string;
26
- metrics: string;
27
26
  source: string;
28
27
  serving: string;
29
28
  related: string;
@@ -44,8 +43,8 @@ interface VersionRow {
44
43
  * SQLite-backed StorageAdapter for skill-tree.
45
44
  *
46
45
  * Stores skills in a `skills` table with JSON columns for nested objects
47
- * (tags, metrics, triggerConditions, etc.). Version history is tracked in
48
- * a separate `skill_versions` table. Dates are stored as ISO strings.
46
+ * (tags, namespace, taxonomy, lineage, etc.). Version history is tracked
47
+ * in a separate `skill_versions` table. Dates are stored as ISO strings.
49
48
  */
50
49
  export class SqliteStorageAdapter implements StorageAdapter {
51
50
  private db: Database.Database;
@@ -79,6 +78,16 @@ export class SqliteStorageAdapter implements StorageAdapter {
79
78
  )
80
79
  `);
81
80
 
81
+ // Backwards-compat: drop the legacy metrics column on existing
82
+ // installs. skill-tree 0.2 dropped Skill.metrics; the column is no
83
+ // longer read or written. SQLite >= 3.35 supports DROP COLUMN; older
84
+ // versions silently fail and leave the column as harmless dead weight.
85
+ try {
86
+ this.db.exec('ALTER TABLE skills DROP COLUMN metrics');
87
+ } catch {
88
+ // Column already absent or SQLite version doesn't support DROP COLUMN.
89
+ }
90
+
82
91
  this.db.exec(`
83
92
  CREATE TABLE IF NOT EXISTS skill_versions (
84
93
  skill_id TEXT NOT NULL,
@@ -113,10 +122,10 @@ export class SqliteStorageAdapter implements StorageAdapter {
113
122
  const stmt = this.db.prepare(`
114
123
  INSERT OR REPLACE INTO skills
115
124
  (id, name, version, description, instructions,
116
- author, status, tags, metrics, source,
125
+ author, status, tags, source,
117
126
  serving, related, created_at, updated_at)
118
127
  VALUES
119
- (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
128
+ (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
120
129
  `);
121
130
 
122
131
  stmt.run(
@@ -128,7 +137,6 @@ export class SqliteStorageAdapter implements StorageAdapter {
128
137
  skill.author ?? null,
129
138
  skill.status,
130
139
  JSON.stringify(skill.tags ?? []),
131
- JSON.stringify(skill.metrics ?? {}),
132
140
  JSON.stringify(skill.source ?? {}),
133
141
  JSON.stringify(skill.serving ?? {}),
134
142
  JSON.stringify(skill.related ?? []),
@@ -237,8 +245,6 @@ export class SqliteStorageAdapter implements StorageAdapter {
237
245
  * Convert a database row to a Skill object, parsing JSON columns and dates.
238
246
  */
239
247
  private rowToSkill(row: SkillRow): Skill {
240
- const metrics = JSON.parse(row.metrics);
241
-
242
248
  return {
243
249
  id: row.id,
244
250
  name: row.name,
@@ -249,10 +255,6 @@ export class SqliteStorageAdapter implements StorageAdapter {
249
255
  status: row.status as Skill['status'],
250
256
  tags: JSON.parse(row.tags),
251
257
  related: JSON.parse(row.related),
252
- metrics: {
253
- ...metrics,
254
- lastUsed: metrics.lastUsed ? new Date(metrics.lastUsed) : undefined,
255
- },
256
258
  source: JSON.parse(row.source),
257
259
  serving: JSON.parse(row.serving),
258
260
  createdAt: new Date(row.created_at),
@@ -35,6 +35,19 @@ export interface Playbook {
35
35
  embedding?: number[]; // For semantic search
36
36
  createdAt: Date;
37
37
  updatedAt: Date;
38
+
39
+ // === PUBLISH HINTS (optional, used by SkillPublisher) ===
40
+ /**
41
+ * Whether end-users can invoke this skill directly (e.g. via /slash-command).
42
+ * Propagated into the published SKILL.md frontmatter as `user-invocable`.
43
+ */
44
+ userInvocable?: boolean;
45
+ /**
46
+ * Arbitrary key-value metadata propagated verbatim into the published
47
+ * SKILL.md frontmatter `metadata:` block. Use for ecosystem-specific
48
+ * fields (audience, component, ecosystem) without changing the core schema.
49
+ */
50
+ publishMetadata?: Record<string, unknown>;
38
51
  }
39
52
 
40
53
  /**
@@ -159,6 +172,8 @@ export function createPlaybook(
159
172
  complexity: input.complexity ?? 'moderate',
160
173
  estimatedEffort: input.estimatedEffort ?? 3,
161
174
  embedding: input.embedding,
175
+ userInvocable: input.userInvocable,
176
+ publishMetadata: input.publishMetadata,
162
177
  createdAt: input.createdAt ?? now,
163
178
  updatedAt: input.updatedAt ?? now,
164
179
  };
@@ -86,3 +86,10 @@ export {
86
86
  type PlaybookLifecycleReviewOutput,
87
87
  type LifecycleRecommendation,
88
88
  } from './playbook-lifecycle-review.js';
89
+
90
+ // Skill Enrichment (publish pipeline — agent-enriched SKILL.md generation)
91
+ export {
92
+ skillEnrichmentTemplate,
93
+ type SkillEnrichmentInput,
94
+ type SkillEnrichmentOutput,
95
+ } from './skill-enrichment.js';