@codexa/cli 9.0.6 → 9.0.8

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.
@@ -2,6 +2,7 @@ import { describe, it, expect, beforeEach } from "bun:test";
2
2
  import { jaccardSimilarity, compactKnowledge } from "./knowledge";
3
3
  import { getDb } from "../db/connection";
4
4
  import { initSchema } from "../db/schema";
5
+ import { cleanDb } from "../db/test-helpers";
5
6
 
6
7
  describe("jaccardSimilarity", () => {
7
8
  it("returns 1 for identical strings", () => {
@@ -49,12 +50,7 @@ describe("jaccardSimilarity", () => {
49
50
  describe("compactKnowledge", () => {
50
51
  beforeEach(() => {
51
52
  initSchema();
52
- const db = getDb();
53
- db.run("DELETE FROM knowledge_graph");
54
- db.run("DELETE FROM knowledge");
55
- db.run("DELETE FROM tasks");
56
- db.run("DELETE FROM context");
57
- db.run("DELETE FROM specs");
53
+ cleanDb();
58
54
  });
59
55
 
60
56
  function createSpec(id: string, phase: string) {
@@ -170,9 +170,9 @@ export function acknowledgeKnowledge(knowledgeId: string, specId?: string): void
170
170
  export function getKnowledgeForTask(specId: string, taskId: number): any[] {
171
171
  const db = getDb();
172
172
 
173
- // Buscar todo knowledge da spec e filtrar em codigo
173
+ // Knowledge do spec atual (todas as severities)
174
174
  // Fix: LIKE '%taskId%' causava substring match (taskId=1 matchava "1,10,11")
175
- const knowledge = db
175
+ const specKnowledge = db
176
176
  .query(
177
177
  `SELECT * FROM knowledge
178
178
  WHERE spec_id = ?
@@ -181,11 +181,27 @@ export function getKnowledgeForTask(specId: string, taskId: number): any[] {
181
181
  )
182
182
  .all(specId) as any[];
183
183
 
184
- return knowledge.filter((k) => {
184
+ const filtered = specKnowledge.filter((k) => {
185
185
  if (k.broadcast_to === 'all') return true;
186
186
  const targets = k.broadcast_to.split(',').map((t: string) => parseInt(t.trim(), 10));
187
187
  return targets.includes(taskId);
188
- }).slice(0, 20);
188
+ });
189
+
190
+ // Cross-feature: knowledge critical de outros specs (aprendizado global)
191
+ const crossFeature = db
192
+ .query(
193
+ `SELECT * FROM knowledge
194
+ WHERE spec_id != ? AND severity = 'critical'
195
+ ORDER BY created_at DESC
196
+ LIMIT 10`
197
+ )
198
+ .all(specId) as any[];
199
+
200
+ // Deduplicar por content (priorizar o do spec atual)
201
+ const seenContent = new Set(filtered.map((k) => k.content));
202
+ const uniqueCross = crossFeature.filter((k) => !seenContent.has(k.content));
203
+
204
+ return [...filtered, ...uniqueCross].slice(0, 25);
189
205
  }
190
206
 
191
207
  export function getUnreadKnowledgeForTask(specId: string, taskId: number): any[] {