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
@@ -77,10 +77,73 @@ describe('SkillPublisher', () => {
77
77
  const playbook = createSamplePlaybook();
78
78
  const skill = convertPlaybookToSkill(playbook);
79
79
 
80
- expect(skill.description).toBe('TypeScript import fails with TS2307');
80
+ expect(skill.description).toContain('TypeScript import fails with TS2307');
81
81
  expect(skill.instructions).toContain('TypeScript import fails with TS2307');
82
82
  });
83
83
 
84
+ it('should surface trigger phrases inline in description for lightweight matching', () => {
85
+ const playbook = createSamplePlaybook();
86
+ const skill = convertPlaybookToSkill(playbook);
87
+
88
+ // Lead situation still present.
89
+ expect(skill.description).toContain('TypeScript import fails with TS2307');
90
+ // Explicit "Use when" clause listing each trigger phrase, quoted.
91
+ expect(skill.description).toContain('Use when');
92
+ expect(skill.description).toContain('"TS2307"');
93
+ expect(skill.description).toContain('"Cannot find module"');
94
+ });
95
+
96
+ it('should omit trigger clause when no triggers are declared', () => {
97
+ const playbook = createSamplePlaybook({
98
+ applicability: {
99
+ situations: ['Some situation'],
100
+ triggers: [],
101
+ antiPatterns: [],
102
+ domains: [],
103
+ },
104
+ });
105
+ const skill = convertPlaybookToSkill(playbook);
106
+
107
+ expect(skill.description).toBe('Some situation.');
108
+ expect(skill.description).not.toContain('Use when');
109
+ });
110
+
111
+ it('should cap description at 1024 chars', () => {
112
+ const playbook = createSamplePlaybook({
113
+ applicability: {
114
+ situations: ['X'.repeat(500)],
115
+ // Many long triggers would push past 1024 chars combined.
116
+ triggers: Array.from({ length: 20 }, (_, i) => 'trigger-phrase-' + 'y'.repeat(50) + `-${i}`),
117
+ antiPatterns: [],
118
+ domains: [],
119
+ },
120
+ });
121
+ const skill = convertPlaybookToSkill(playbook);
122
+
123
+ expect(skill.description.length).toBeLessThanOrEqual(1024);
124
+ expect(skill.description).toMatch(/\.\.\.$/);
125
+ });
126
+
127
+ it('should use provenance.curatedBy as author when set', () => {
128
+ const playbook = createSamplePlaybook({
129
+ provenance: {
130
+ origin: 'curated',
131
+ curatedBy: 'swarmkit-skills',
132
+ recordedAt: new Date(),
133
+ },
134
+ });
135
+ const skill = convertPlaybookToSkill(playbook);
136
+
137
+ expect(skill.author).toBe('swarmkit-skills');
138
+ });
139
+
140
+ it('should fall back to cognitive-core as author when provenance.curatedBy is absent', () => {
141
+ const playbook = createSamplePlaybook();
142
+ const skill = convertPlaybookToSkill(playbook);
143
+
144
+ expect(skill.author).toBe('cognitive-core');
145
+ });
146
+
84
147
  it('should build instructions from strategy, tactics, and steps', () => {
85
148
  const playbook = createSamplePlaybook();
86
149
  const skill = convertPlaybookToSkill(playbook);
@@ -92,27 +155,31 @@ describe('SkillPublisher', () => {
92
155
  expect(skill.instructions).toContain('Verify with tsc --noEmit');
93
156
  });
94
157
 
95
- it('should include verification and notes in instructions', () => {
158
+ it('should include structured verification, when-to-use, and when-not-to-use sections', () => {
96
159
  const playbook = createSamplePlaybook();
97
160
  const skill = convertPlaybookToSkill(playbook);
98
161
 
99
- expect(skill.instructions).toContain('Build passes');
100
- expect(skill.instructions).toContain('Do NOT use when:');
101
- expect(skill.instructions).toContain('Watch for:');
102
- expect(skill.instructions).toContain('Refinements:');
162
+ // Verification indicators rendered as bulleted lists
163
+ expect(skill.instructions).toContain('Success:\n- Build passes');
164
+ expect(skill.instructions).toContain('Failure:\n- Same error persists');
103
165
  expect(skill.instructions).toContain('Rollback:');
104
- });
105
166
 
106
- it('should compute metrics from evolution data', () => {
107
- const playbook = createSamplePlaybook();
108
- const skill = convertPlaybookToSkill(playbook);
167
+ // Anti-patterns now live in their own section, not in Notes
168
+ expect(skill.instructions).toContain('## When not to use');
169
+ expect(skill.instructions).toContain('- Module genuinely does not exist');
170
+
171
+ // Situations get their own section
172
+ expect(skill.instructions).toContain('## When to use');
173
+ expect(skill.instructions).toContain('- TypeScript import fails with TS2307');
109
174
 
110
- expect(skill.metrics.usageCount).toBe(10); // 8 + 2
111
- expect(skill.metrics.successRate).toBe(0.8); // 8/10
112
- expect(skill.metrics.averageConfidence).toBe(0.85);
113
- expect(skill.metrics.lastUsed).toBeDefined();
175
+ // Refinements remain in Notes
176
+ expect(skill.instructions).toContain('Refinements:');
114
177
  });
115
178
 
179
+ // skill-tree >= 0.2 dropped Skill.metrics — usage data lives on
180
+ // playbook.evolution.* in cognitive-core. The publisher no longer
181
+ // emits a metrics snapshot. See SKILL_TREE_METRICS_DEPRECATION plan.
182
+
116
183
  it('should include code example in instructions', () => {
117
184
  const playbook = createSamplePlaybook();
118
185
  const skill = convertPlaybookToSkill(playbook);
@@ -277,12 +344,12 @@ describe('SkillPublisher', () => {
277
344
  expect(result.error).toContain('not found');
278
345
  });
279
346
 
280
- it('should preserve existing notes when deprecating', async () => {
347
+ it('should preserve existing content when deprecating', async () => {
281
348
  const publisher = new SkillPublisher(storage);
282
349
  await publisher.publishPlaybook(createSamplePlaybook({ id: 'notes-1' }));
283
350
 
284
351
  const before = await storage.getSkill('notes-1');
285
- expect(before!.instructions).toContain('Do NOT use when:');
352
+ expect(before!.instructions).toContain('## When not to use');
286
353
 
287
354
  await publisher.deprecateSkill('notes-1', 'Superseded');
288
355
 
@@ -357,8 +424,9 @@ describe('SkillPublisher', () => {
357
424
 
358
425
  skill = await storage.getSkill('evolve-1');
359
426
  expect(skill!.version).toBe('2.0.0');
360
- expect(skill!.metrics.usageCount).toBe(22);
361
- expect(skill!.metrics.averageConfidence).toBe(0.95);
427
+ // Live evolution data (usageCount, confidence) stays on the
428
+ // playbook in cognitive-core; the published Skill no longer
429
+ // carries metrics snapshots.
362
430
  });
363
431
  });
364
432
  });
@@ -16,13 +16,6 @@ function createSampleSkill(overrides?: Partial<Skill>): Skill {
16
16
  author: 'cognitive-core',
17
17
  status: 'active',
18
18
  tags: ['typescript', 'nodejs'],
19
- metrics: {
20
- usageCount: 8,
21
- successRate: 0.9,
22
- lastUsed: now,
23
- feedbackScores: [],
24
- averageConfidence: 0.85,
25
- },
26
19
  source: {
27
20
  type: 'extracted',
28
21
  sessionId: 'session-abc',
@@ -126,8 +119,6 @@ describe('SqliteStorageAdapter', () => {
126
119
 
127
120
  const retrieved = await adapter.getSkill('skill-json');
128
121
  expect(retrieved!.tags).toEqual(['typescript', 'nodejs']);
129
- expect(retrieved!.metrics.usageCount).toBe(8);
130
- expect(retrieved!.metrics.successRate).toBe(0.9);
131
122
  expect(retrieved!.source!.type).toBe('extracted');
132
123
  expect(retrieved!.serving!.tokenEstimate).toBe(150);
133
124
  });