Skip to content

Commit 547599d

Browse files
author
Tehan
committed
chore(skill-memory): rebase onto upstream v0.34.0 (migrations v75/76/77)
Upstream v0.34.0 claimed v73 (todowrite permission verdict) and v74 (detected context-limit provenance), so the three skill-memory migrations renumber v73/74/75 -> v75/76/77 and LATEST_SUPPORTED_VERSION follows to 77. Their test files move with them; upstream's own migrations-v73/74.test.ts are taken as-is. Adapts to four upstream changes: - executeStatus grew a `dreamer` parameter. Ours added `directory` for the skill-memory section; both are kept, dreamer first (upstream's position), directory appended. - The tool.execute.after hook now awaits flushIgnoredMessages and reads `agent` off the input; the skill-memory branch and the callID field are additive alongside it. - getDreamTaskBacklog's switch is exhaustive over DreamTaskName, so distill-skill-memory needed an arm. Returns 0/0 to match its always-eligible gate — the distill pass is whole-corpus maintenance with no per-item queue, and reaching into skill_memory internals would couple the scheduler to a table it does not otherwise touch. - promotion.test.ts: upstream fixed the mock.module bleed itself (7eb943e, our issue cortexkit#279) using the same provider-factory seam, so upstream's file is taken verbatim and our now-redundant version dropped. The three skill-memory test files keep their seam conversions. Two fence assertions relaxed from equality to a floor: migrations-v72 and -v74 asserted LATEST_SUPPORTED_VERSION was exactly their own version, which cannot hold once any migration is appended above them. The lockstep assertion (LATEST_SUPPORTED_VERSION === LATEST_MIGRATION_VERSION) is the invariant that matters and is kept in both.
1 parent be685d3 commit 547599d

11 files changed

Lines changed: 105 additions & 99 deletions

File tree

‎assets/magic-context.schema.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,8 @@
11011101
"low",
11021102
"medium",
11031103
"high",
1104-
"xhigh"
1104+
"xhigh",
1105+
"max"
11051106
]
11061107
},
11071108
"timeout_minutes": {

‎packages/cli/src/lib/dreamer-setup.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ describe("runDreamerSetup", () => {
7777
const prompts = new MockPrompts({
7878
confirms: [false],
7979
autos: ["x/y"],
80-
selects: Array(12).fill("cron:0 3 * * *"),
80+
selects: Array(13).fill("cron:0 3 * * *"),
8181
});
8282
const result = await runDreamerSetup(prompts, ["x/y"]);
8383
expect(result.tasks).toBeDefined();
84-
expect(Object.keys(result.tasks ?? {}).length).toBe(12);
84+
expect(Object.keys(result.tasks ?? {}).length).toBe(13);
8585
expect(result.tasks?.verify.schedule).toBe("0 3 * * *");
8686
expect(result.tasks?.curate.schedule).toBe("0 3 * * *");
8787
expect(result.tasks?.["classify-memories"].schedule).toBe("0 3 * * *");

‎packages/docs/src/content/docs/reference/configuration.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Off-hours maintenance (Dreamer) and on-demand prompt augmentation (Sidekick).
216216
| `dreamer.tasks.distill-skill-memory.schedule` | string | `""` | 5-field cron schedule (e.g. "0 3 * * *"), or "" to disable this task. |
217217
| `dreamer.tasks.distill-skill-memory.model` | string | — | Per-task model override (inherits dreamer.model) |
218218
| `dreamer.tasks.distill-skill-memory.fallback_models` | string \\| string[] | — | Per-task fallback chain (inherits dreamer.fallback_models) |
219-
| `dreamer.tasks.distill-skill-memory.thinking_level` | `"off"` \\| `"minimal"` \\| `"low"` \\| `"medium"` \\| `"high"` \\| `"xhigh"` | — | Pi only: per-task thinking level |
219+
| `dreamer.tasks.distill-skill-memory.thinking_level` | `"off"` \\| `"minimal"` \\| `"low"` \\| `"medium"` \\| `"high"` \\| `"xhigh"` \\| `"max"` | — | Pi only: per-task thinking level |
220220
| `dreamer.tasks.distill-skill-memory.timeout_minutes` | number (5–) | `20` | Minutes allowed for this task before it is aborted |
221221
| `dreamer.inject_docs` | boolean | `true` | Inject ARCHITECTURE.md and STRUCTURE.md into the m[0] `<project-docs>` block (default true) |
222222
| `dreamer.thinking_level` | `"off"` \\| `"minimal"` \\| `"low"` \\| `"medium"` \\| `"high"` \\| `"xhigh"` \\| `"max"` | — | Pi only: default thinking level for dreamer subagent invocations. See historian.thinking_level. |

‎packages/plugin/src/config/schema/distill-skill-memory-enum.test.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
AGENTIC_DREAM_TASKS,
44
CANONICAL_DREAM_TASKS,
55
} from "../../features/magic-context/dreamer/task-registry";
6-
import { DREAMER_TASKS, DreamingTaskSchema, DreamTasksSchema } from "./magic-context";
6+
import { DreamTasksSchema } from "./magic-context";
77

88
describe("distill-skill-memory dreamer task", () => {
99
test("distill-skill-memory is a canonical dream task", () => {
@@ -12,12 +12,15 @@ describe("distill-skill-memory dreamer task", () => {
1212

1313
test("distill-skill-memory is agentic (prompt-driven)", () => {
1414
expect(AGENTIC_DREAM_TASKS).toContain("distill-skill-memory");
15-
// DREAMER_TASKS (the schema enum) re-exports AGENTIC_DREAM_TASKS.
16-
expect(DREAMER_TASKS).toContain("distill-skill-memory");
1715
});
1816

19-
test("DreamingTaskSchema accepts distill-skill-memory", () => {
20-
expect(() => DreamingTaskSchema.parse("distill-skill-memory")).not.toThrow();
17+
test("DreamTasksSchema accepts a distill-skill-memory config", () => {
18+
// v2 model: tasks are per-key objects on DreamTasksSchema, not a string
19+
// enum. Validity is "the key parses with a schedule", not enum membership.
20+
const parsed = DreamTasksSchema.parse({
21+
"distill-skill-memory": { schedule: "0 4 * * *" },
22+
});
23+
expect(parsed["distill-skill-memory"].schedule).toBe("0 4 * * *");
2124
});
2225

2326
test("distill-skill-memory defaults to OFF (empty schedule = opt-in)", () => {

‎packages/plugin/src/features/magic-context/dreamer/task-gates.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,14 @@ export function getDreamTaskBacklog(
292292
const total = countActivePrimers(db, projectPath);
293293
return { pending: countStalePrimers(db, projectPath), total };
294294
}
295+
case "distill-skill-memory": {
296+
// Mirrors the always-eligible gate in evaluateTaskGate: the distill
297+
// pass is whole-corpus maintenance with no per-item queue, so there
298+
// is no meaningful pending count to surface. Reported as 0/0 rather
299+
// than reaching into skill_memory internals the scheduler does not
300+
// otherwise depend on.
301+
return { pending: 0, total: 0 };
302+
}
295303
default: {
296304
const _exhaustive: never = task;
297305
return _exhaustive;

‎packages/plugin/src/features/magic-context/memory/promotion.test.ts‎

Lines changed: 69 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/// <reference types="bun-types" />
22

33
import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from "bun:test";
4+
45
import { Database } from "../../../shared/sqlite";
56
import { closeQuietly } from "../../../shared/sqlite-helpers";
67
import { CATEGORY_DEFAULT_TTL } from "./constants";
78
import type { EmbeddingProvider } from "./embedding-provider";
89
import { computeNormalizedHash } from "./normalize-hash";
910

11+
const mockEmbedText = mock(async (): Promise<{ vector: Float32Array } | null> => null);
1012
const mockLog = mock(() => {});
1113

1214
mock.module("../../../shared/logger", () => ({
@@ -15,6 +17,11 @@ mock.module("../../../shared/logger", () => ({
1517
getLogFilePath: () => "/tmp/test.log",
1618
}));
1719

20+
const {
21+
_resetProjectEmbeddingRegistryForTests,
22+
_setTestProviderFactoryForProject,
23+
registerProjectEmbedding,
24+
} = await import("../project-embedding-registry");
1825
const {
1926
archiveMemory,
2027
getMemoryByHash,
@@ -24,16 +31,32 @@ const {
2431
insertMemory,
2532
} = await import("./storage-memory");
2633
const { embedPromotedFacts, promoteSessionFactsDurable } = await import("./promotion");
27-
const {
28-
_resetProjectEmbeddingRegistryForTests,
29-
_setTestProviderFactoryForProject,
30-
registerProjectEmbedding,
31-
} = await import("./embedding");
32-
const { runMigrations } = await import("../migrations");
33-
const { initializeDatabase } = await import("../storage-db");
3434

35+
const TEST_PROJECT_PATH = "/repo/project";
3536
let db: Database | null = null;
3637

38+
class TestEmbeddingProvider implements EmbeddingProvider {
39+
readonly modelId = "mock:model";
40+
41+
async initialize(): Promise<boolean> {
42+
return true;
43+
}
44+
45+
async embed(text: string): Promise<Float32Array | null> {
46+
return (await mockEmbedText(text))?.vector ?? null;
47+
}
48+
49+
async embedBatch(texts: string[]): Promise<(Float32Array | null)[]> {
50+
return Promise.all(texts.map((text) => this.embed(text)));
51+
}
52+
53+
async dispose(): Promise<void> {}
54+
55+
isLoaded(): boolean {
56+
return true;
57+
}
58+
}
59+
3760
function makeMemoryDatabase(): Database {
3861
const database = new Database(":memory:");
3962
database.exec(`
@@ -93,12 +116,26 @@ function makeMemoryDatabase(): Database {
93116
return database;
94117
}
95118

119+
function registerTestEmbeddingProvider(database: Database): string {
120+
return registerProjectEmbedding(
121+
database,
122+
TEST_PROJECT_PATH,
123+
{ provider: "local", model: "mock:model" },
124+
{ memoryEnabled: false, gitCommitEnabled: false },
125+
TEST_PROJECT_PATH,
126+
).modelId;
127+
}
128+
96129
beforeEach(() => {
130+
_setTestProviderFactoryForProject(() => new TestEmbeddingProvider());
131+
mockEmbedText.mockReset();
132+
mockEmbedText.mockImplementation(async () => null);
97133
mockLog.mockReset();
98134
mockLog.mockImplementation(() => {});
99135
});
100136

101137
afterEach(() => {
138+
_resetProjectEmbeddingRegistryForTests();
102139
if (db) {
103140
try {
104141
closeQuietly(db);
@@ -107,8 +144,6 @@ afterEach(() => {
107144
db = null;
108145
}
109146
}
110-
_resetProjectEmbeddingRegistryForTests();
111-
_setTestProviderFactoryForProject(null);
112147
});
113148

114149
describe("promotion", () => {
@@ -395,92 +430,50 @@ describe("promotion", () => {
395430

396431
describe("#given best-effort embedding of promoted facts", () => {
397432
it("stores the vector under the registered model when the memory is unchanged", async () => {
398-
_resetProjectEmbeddingRegistryForTests();
399-
400-
db = new Database(":memory:");
401-
initializeDatabase(db);
402-
runMigrations(db);
403-
const snapshot = registerProjectEmbedding(
404-
db,
405-
"/repo/project",
406-
{ provider: "local", model: "mock-model" },
407-
{ memoryEnabled: true, gitCommitEnabled: false },
408-
"/repo/project",
409-
);
410-
_setTestProviderFactoryForProject(
411-
(): EmbeddingProvider => ({
412-
modelId: "mock:model",
413-
initialize: async () => true,
414-
embed: async (_text: string) => new Float32Array([1, 2]),
415-
embedBatch: async (texts: string[]) =>
416-
texts.map(() => new Float32Array([1, 2])),
417-
dispose: async () => {},
418-
isLoaded: () => true,
419-
}),
420-
);
421-
433+
db = makeMemoryDatabase();
422434
const memory = insertMemory(db, {
423-
projectPath: "/repo/project",
435+
projectPath: TEST_PROJECT_PATH,
424436
category: "ARCHITECTURE_DECISIONS",
425437
content: "Embed promoted facts eagerly",
426438
});
439+
const registeredModelId = registerTestEmbeddingProvider(db);
440+
mockEmbedText.mockImplementation(async () => ({
441+
vector: new Float32Array([1, 2]),
442+
}));
427443

428-
await embedPromotedFacts(db, "ses-1", "/repo/project", [
444+
await embedPromotedFacts(db, "ses-1", TEST_PROJECT_PATH, [
429445
{ memoryId: memory.id, content: memory.content },
430446
]);
431447

432448
const rows = db.prepare("SELECT model_id FROM memory_embeddings").all() as Array<{
433449
model_id: string;
434450
}>;
435451
expect(rows).toHaveLength(1);
436-
expect(rows[0].model_id).toBe(snapshot.modelId);
452+
expect(rows[0].model_id).toBe(registeredModelId);
437453
});
438454

439455
it("discards the stale vector when the memory is edited while embedding is in flight", async () => {
440-
_resetProjectEmbeddingRegistryForTests();
441-
442-
db = new Database(":memory:");
443-
initializeDatabase(db);
444-
runMigrations(db);
445-
registerProjectEmbedding(
446-
db,
447-
"/repo/project",
448-
{ provider: "local", model: "mock-model" },
449-
{ memoryEnabled: true, gitCommitEnabled: false },
450-
"/repo/project",
451-
);
452-
453-
let resolveStarted: (() => void) | undefined;
454-
const started = new Promise<void>((resolve) => {
455-
resolveStarted = resolve;
456-
});
457-
let releaseBlocker: (() => void) | undefined;
458-
const blocker = new Promise<void>((resolve) => {
459-
releaseBlocker = resolve;
460-
});
461-
_setTestProviderFactoryForProject(
462-
(): EmbeddingProvider => ({
463-
modelId: "mock:model",
464-
initialize: async () => true,
465-
embed: async (_text: string): Promise<Float32Array> => {
466-
resolveStarted?.();
467-
await blocker;
468-
return new Float32Array([1, 2]);
469-
},
470-
embedBatch: async (texts: string[]) =>
471-
texts.map(() => new Float32Array([1, 2])),
472-
dispose: async () => {},
473-
isLoaded: () => true,
474-
}),
475-
);
476-
456+
db = makeMemoryDatabase();
477457
const memory = insertMemory(db, {
478-
projectPath: "/repo/project",
458+
projectPath: TEST_PROJECT_PATH,
479459
category: "ARCHITECTURE_DECISIONS",
480460
content: "Original promoted content",
481461
});
462+
registerTestEmbeddingProvider(db);
463+
let release: (() => void) | undefined;
464+
const started = new Promise<void>((resolve) => {
465+
mockEmbedText.mockImplementation(async () => {
466+
resolve();
467+
await new Promise<void>((done) => {
468+
release = done;
469+
});
470+
return {
471+
vector: new Float32Array([1, 2]),
472+
};
473+
});
474+
});
482475

483-
const inFlight = embedPromotedFacts(db, "ses-1", "/repo/project", [
476+
const inFlight = embedPromotedFacts(db, "ses-1", TEST_PROJECT_PATH, [
484477
{ memoryId: memory.id, content: memory.content },
485478
]);
486479
await started;
@@ -489,7 +482,7 @@ describe("promotion", () => {
489482
db.prepare(
490483
"UPDATE memories SET content = ?, normalized_hash = ?, updated_at = ? WHERE id = ?",
491484
).run("Edited promoted content", "edited-hash", Date.now(), memory.id);
492-
releaseBlocker?.();
485+
release?.();
493486
await inFlight;
494487

495488
const count = (

‎packages/plugin/src/features/magic-context/migrations-v74.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ describe("migration v74: detected context-limit provenance", () => {
3636
runMigrations(db);
3737

3838
expect(columnNames(db, "session_meta")).toContain("detected_context_limit_provenance");
39-
expect(LATEST_SUPPORTED_VERSION).toBe(75);
39+
// v74 is a floor, not a ceiling: downstream migrations append above it.
40+
// The lockstep assertion below is the invariant that actually matters.
41+
expect(LATEST_SUPPORTED_VERSION).toBeGreaterThanOrEqual(74);
4042
expect(LATEST_SUPPORTED_VERSION).toBe(LATEST_MIGRATION_VERSION);
4143
} finally {
4244
closeQuietly(db);

‎packages/plugin/src/features/magic-context/migrations-v76.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe("migration v76 — skill_memory embeddings + FTS", () => {
9292
Date.now(),
9393
);
9494
// Apply ONLY v40's up() — its body must ALTER + create the FTS table + BACKFILL the pre-existing row.
95-
const v76 = MIGRATIONS.find((m) => m.version === 74);
95+
const v76 = MIGRATIONS.find((m) => m.version === 76);
9696
if (!v76) throw new Error("v40 migration not found");
9797
v76.up(db);
9898
const hit = db
@@ -108,6 +108,6 @@ describe("migration v76 — skill_memory embeddings + FTS", () => {
108108

109109
test("LATEST_SUPPORTED_VERSION equals LATEST_MIGRATION_VERSION after v76", () => {
110110
expect(LATEST_SUPPORTED_VERSION).toBe(LATEST_MIGRATION_VERSION);
111-
expect(LATEST_SUPPORTED_VERSION).toBe(75);
111+
expect(LATEST_SUPPORTED_VERSION).toBe(LATEST_MIGRATION_VERSION);
112112
});
113113
});

‎packages/plugin/src/features/magic-context/migrations-v77.test.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ function insertGlobal(
3535

3636
describe("migration v77 — origin_project + source_type + global '*' unification", () => {
3737
test("LATEST_SUPPORTED_VERSION equals LATEST_MIGRATION_VERSION after v77", () => {
38-
expect(LATEST_SUPPORTED_VERSION).toBe(75);
39-
expect(LATEST_MIGRATION_VERSION).toBe(75);
38+
expect(LATEST_SUPPORTED_VERSION).toBe(LATEST_MIGRATION_VERSION);
4039
});
4140

4241
test("fresh DB has origin_project + source_type columns", () => {
@@ -59,7 +58,7 @@ describe("migration v77 — origin_project + source_type + global '*' unificatio
5958
for (const m of MIGRATIONS.filter((m) => m.version <= 40)) m.up(db);
6059
insertGlobal(db, "council", "git:repoA", "h1");
6160

62-
const v77 = MIGRATIONS.find((m) => m.version === 75);
61+
const v77 = MIGRATIONS.find((m) => m.version === 77);
6362
expect(v77).toBeDefined();
6463
v77?.up(db);
6564

@@ -93,7 +92,7 @@ describe("migration v77 — origin_project + source_type + global '*' unificatio
9392
createdAt: 800,
9493
});
9594

96-
MIGRATIONS.find((m) => m.version === 75)?.up(db);
95+
MIGRATIONS.find((m) => m.version === 77)?.up(db);
9796

9897
const rows = db
9998
.prepare(
@@ -124,7 +123,7 @@ describe("migration v77 — origin_project + source_type + global '*' unificatio
124123
for (const m of MIGRATIONS.filter((m) => m.version <= 40)) m.up(db);
125124
insertGlobal(db, "council", "git:repoA", "h1", { hit: 1 });
126125

127-
const v77 = MIGRATIONS.find((m) => m.version === 75);
126+
const v77 = MIGRATIONS.find((m) => m.version === 77);
128127
v77?.up(db);
129128
v77?.up(db);
130129

@@ -146,7 +145,7 @@ describe("migration v77 — origin_project + source_type + global '*' unificatio
146145
insertGlobal(db, "council", "git:repoA", "dup");
147146
insertGlobal(db, "council", "git:repoB", "dup");
148147

149-
MIGRATIONS.find((m) => m.version === 75)?.up(db);
148+
MIGRATIONS.find((m) => m.version === 77)?.up(db);
150149

151150
const ftsCount = db.prepare("SELECT COUNT(*) AS n FROM skill_memory_fts").get() as {
152151
n: number;
@@ -172,7 +171,7 @@ describe("migration v77 — origin_project + source_type + global '*' unificatio
172171
`INSERT INTO skill_memory (skill_id, resolved_path, tier, project_identity, intent, kind, delta, normalized_hash, created_at) VALUES ('s', '/p', 'project', 'git:repoA', 'i', 'fix', 'd', 'ph', 1)`,
173172
).run();
174173

175-
MIGRATIONS.find((m) => m.version === 75)?.up(db);
174+
MIGRATIONS.find((m) => m.version === 77)?.up(db);
176175

177176
const row = db
178177
.prepare("SELECT project_identity FROM skill_memory WHERE normalized_hash='ph'")

‎packages/plugin/src/features/magic-context/migrations.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2853,8 +2853,8 @@ export const MIGRATIONS: Migration[] = [
28532853
},
28542854
},
28552855
{
2856-
// Skill-memory historian extraction: was v41/v44/v56/v75 across earlier
2857-
// rebases; renumbered across upstream migrations — now v77 after
2856+
// Skill-memory historian extraction: was v41/v44/v56/v72/v75 across
2857+
// earlier rebases; renumbered across upstream migrations — now v77 after
28582858
// upstream v0.34.0 took v73-v74 (skill is now v75/76/77).
28592859
version: 77,
28602860
description:

0 commit comments

Comments
 (0)