cognitive-core 0.2.3 → 0.2.4

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.
@@ -0,0 +1,48 @@
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 type { Playbook } from '../../types/index.js';
14
+ import type { AgenticTaskTemplate } from '../types.js';
15
+ export interface SkillEnrichmentInput {
16
+ /** The playbook to enrich into a skill */
17
+ playbook: Playbook;
18
+ /** Optional: existing hand-written SKILL.md to use as style reference */
19
+ styleReference?: string;
20
+ /** Optional: related skill names for cross-referencing */
21
+ relatedSkills?: Array<{
22
+ name: string;
23
+ description: string;
24
+ }>;
25
+ /** Optional: domain context (e.g. "swarmkit ecosystem", "TypeScript tooling") */
26
+ domainContext?: string;
27
+ }
28
+ export interface SkillEnrichmentOutput {
29
+ /** Enriched SKILL.md frontmatter description (trigger-rich, under 1024 chars) */
30
+ description: string;
31
+ /** Enriched markdown body (replaces the procedural instructions) */
32
+ instructions: string;
33
+ /** Worked examples the agent generated */
34
+ examples: Array<{
35
+ title: string;
36
+ scenario: string;
37
+ steps: string;
38
+ }>;
39
+ /** Cross-references to related skills */
40
+ seeAlso: Array<{
41
+ name: string;
42
+ relation: string;
43
+ }>;
44
+ /** Agent's assessment of the playbook's completeness */
45
+ gaps: string[];
46
+ }
47
+ export declare const skillEnrichmentTemplate: AgenticTaskTemplate<SkillEnrichmentInput, SkillEnrichmentOutput>;
48
+ //# sourceMappingURL=skill-enrichment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-enrichment.d.ts","sourceRoot":"","sources":["../../../src/workspace/templates/skill-enrichment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,KAAK,EACV,mBAAmB,EAGpB,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,oBAAoB;IACnC,0CAA0C;IAC1C,QAAQ,EAAE,QAAQ,CAAC;IACnB,yEAAyE;IACzE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,0DAA0D;IAC1D,aAAa,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7D,iFAAiF;IACjF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,qBAAqB;IACpC,iFAAiF;IACjF,WAAW,EAAE,MAAM,CAAC;IACpB,oEAAoE;IACpE,YAAY,EAAE,MAAM,CAAC;IACrB,0CAA0C;IAC1C,QAAQ,EAAE,KAAK,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;IACH,yCAAyC;IACzC,OAAO,EAAE,KAAK,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC,CAAC;IACH,wDAAwD;IACxD,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAMD,eAAO,MAAM,uBAAuB,EAAE,mBAAmB,CACvD,oBAAoB,EACpB,qBAAqB,CAkNtB,CAAC"}
@@ -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,CAAC,GAAG,CAAC,CAAC;QACtD,MAAM,SAAS,GAAG,EAAE,CAAC,UAAU,KAAK,SAAS,CAAC;QAE9C,IAAI,WAAW,IAAI,CAAC,IAA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AE,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.4",
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,7 +74,7 @@
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
80
  "skill-tree": "^0.1.5",
@@ -11,6 +11,46 @@ import type { Playbook } from '../types/index.js';
11
11
  import type { PublishResult, DeprecateResult } from './publisher.js';
12
12
  import { getPlaybookSuccessRate } from '../types/playbook.js';
13
13
 
14
+ /**
15
+ * Maximum length for the generated `description` field.
16
+ * Claude Code's skill format caps description at 1024 chars, so we truncate
17
+ * to stay safely within that boundary.
18
+ */
19
+ const MAX_DESCRIPTION_LENGTH = 1024;
20
+
21
+ /**
22
+ * Build the `description` field for a published Skill.
23
+ *
24
+ * The description is what lightweight trigger matchers — notably Claude Code's
25
+ * skill loader — key off to decide whether to load a skill. It needs two things:
26
+ *
27
+ * 1. A short "what it does" lead (pulled from the first situation, or the
28
+ * strategy if no situation is set).
29
+ * 2. The concrete trigger phrases, surfaced inline so substring/keyword
30
+ * matchers catch them. These live in `applicability.triggers` on the
31
+ * playbook but are invisible to downstream consumers unless we lift them.
32
+ *
33
+ * Shape: `<lead>. Use when "<t1>", "<t2>", ..., "<tN>".`
34
+ */
35
+ function buildDescription(playbook: Playbook): string {
36
+ let lead = playbook.applicability.situations[0]
37
+ ?? `${playbook.name}: ${playbook.guidance.strategy.slice(0, 100)}`;
38
+
39
+ // Ensure a sentence terminator before appending the trigger clause.
40
+ if (lead.length > 0 && !/[.!?]$/.test(lead)) {
41
+ lead += '.';
42
+ }
43
+
44
+ const triggers = playbook.applicability.triggers;
45
+ const triggerClause = triggers.length > 0
46
+ ? ` Use when ${triggers.map((t) => `"${t}"`).join(', ')}.`
47
+ : '';
48
+
49
+ const full = lead + triggerClause;
50
+ if (full.length <= MAX_DESCRIPTION_LENGTH) return full;
51
+ return full.slice(0, MAX_DESCRIPTION_LENGTH - 3) + '...';
52
+ }
53
+
14
54
  /**
15
55
  * Convert a Playbook to a Skill
16
56
  */
@@ -27,43 +67,69 @@ export function convertPlaybookToSkill(playbook: Playbook): Skill {
27
67
  solution += '\n\nSteps:\n' + 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,7 +141,7 @@ 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
146
  status: 'active',
81
147
  metrics: {
@@ -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';