@cortexkit/opencode-magic-context 0.8.7 → 0.8.9
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.
- package/dist/features/magic-context/dreamer/runner.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-prompts.d.ts +8 -1
- package/dist/features/magic-context/dreamer/task-prompts.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/index.js +115 -70
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/dreamer/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/dreamer/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AA2C3D,UAAU,6BAA6B;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,6BAA6B,CAAC,eAAe,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAE9F;AAMD,MAAM,WAAW,cAAc;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,KAAK,EAAE;QACH,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,EAAE,OAAO,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB,EAAE,CAAC;CACP;AAiUD,wBAAsB,QAAQ,CAAC,IAAI,EAAE;IACjC,EAAE,EAAE,QAAQ,CAAC;IACb,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChC,6FAA6F;IAC7F,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,wBAAwB,CAAC,EAAE;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,kBAAkB,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5E,uBAAuB,CAAC,EAAE,6BAA6B,CAAC;CAC3D,GAAG,OAAO,CAAC,cAAc,CAAC,CA+U1B;AA0LD,wBAAsB,iBAAiB,CAAC,IAAI,EAAE;IAC1C,EAAE,EAAE,QAAQ,CAAC;IACb,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChC,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,wBAAwB,CAAC,EAAE;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,kBAAkB,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5E,uBAAuB,CAAC,EAAE,6BAA6B,CAAC;CAC3D,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAyDjC"}
|
|
@@ -2,7 +2,10 @@ import type { DreamingTask } from "../../../config/schema/magic-context";
|
|
|
2
2
|
export declare const DREAMER_SYSTEM_PROMPT = "You are a memory maintenance agent for the magic-context system.\nYou run during scheduled dream windows to maintain a project's cross-session memory store and codebase documentation.\n\n## Available Tools\n\n**Memory operations** (ctx_memory with extended dreamer actions):\n- `action=\"list\"` \u2014 browse all active memories, optionally filter by category\n- `action=\"update\", id=N, content=\"...\"` \u2014 rewrite a memory's content\n- `action=\"merge\", ids=[N,M,...], content=\"...\", category=\"...\"` \u2014 consolidate duplicates into one canonical memory\n- `action=\"archive\", id=N, reason=\"...\"` \u2014 archive a stale memory with provenance\n- `action=\"write\", category=\"...\", content=\"...\"` \u2014 create a new memory\n- `action=\"delete\", id=N` \u2014 permanently remove a memory\n\n**Codebase tools** (standard OpenCode tools):\n- Read files, grep, glob, bash \u2014 for verification against actual code\n\n## Rules\n\n1. **Work methodically.** Decide your own batch size based on the task \u2014 process as many items per round as makes sense.\n2. **Always verify against actual files** before declaring a memory stale or updating it.\n3. **Be conservative with archives.** Only archive when the codebase clearly contradicts the memory.\n4. **Explain reasoning briefly** before each action \u2014 one line is enough.\n5. **Use present-tense operational language** in all memory rewrites. \"X uses Y\" not \"X was changed to use Y.\"\n6. **One rule/fact per memory.** Split compound memories during improvement.\n7. **Never read or quote secrets** from .env, credentials, keys, or similar sensitive files.\n8. **Do not commit changes.** The user handles git operations.";
|
|
3
3
|
export declare function buildConsolidatePrompt(projectPath: string): string;
|
|
4
4
|
export declare function buildVerifyPrompt(projectPath: string): string;
|
|
5
|
-
export declare function buildArchiveStalePrompt(projectPath: string
|
|
5
|
+
export declare function buildArchiveStalePrompt(projectPath: string, userMemories?: Array<{
|
|
6
|
+
id: number;
|
|
7
|
+
content: string;
|
|
8
|
+
}>): string;
|
|
6
9
|
export declare function buildImprovePrompt(projectPath: string): string;
|
|
7
10
|
export declare function buildMaintainDocsPrompt(projectPath: string, lastDreamAt: string | null, existingDocs: {
|
|
8
11
|
architecture: boolean;
|
|
@@ -15,5 +18,9 @@ export declare function buildDreamTaskPrompt(task: DreamingTask, args: {
|
|
|
15
18
|
architecture: boolean;
|
|
16
19
|
structure: boolean;
|
|
17
20
|
};
|
|
21
|
+
userMemories?: Array<{
|
|
22
|
+
id: number;
|
|
23
|
+
content: string;
|
|
24
|
+
}>;
|
|
18
25
|
}): string;
|
|
19
26
|
//# sourceMappingURL=task-prompts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-prompts.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/dreamer/task-prompts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAIzE,eAAO,MAAM,qBAAqB,wqDAyB6B,CAAC;AAIhE,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CA+BlE;AAID,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAoC7D;AAID,wBAAgB,uBAAuB,
|
|
1
|
+
{"version":3,"file":"task-prompts.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/dreamer/task-prompts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAIzE,eAAO,MAAM,qBAAqB,wqDAyB6B,CAAC;AAIhE,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CA+BlE;AAID,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAoC7D;AAID,wBAAgB,uBAAuB,CACnC,WAAW,EAAE,MAAM,EACnB,YAAY,CAAC,EAAE,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,GACtD,MAAM,CA0ER;AAID,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CA0C9D;AAID,wBAAgB,uBAAuB,CACnC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GAAG,IAAI,EAC1B,YAAY,EAAE;IAAE,YAAY,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,GAC5D,MAAM,CA+CR;AA0GD,wBAAgB,oBAAoB,CAChC,IAAI,EAAE,YAAY,EAClB,IAAI,EAAE;IACF,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,YAAY,CAAC,EAAE;QAAE,YAAY,EAAE,OAAO,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;IAC7D,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACzD,GACF,MAAM,CAiBR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embedding-local.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/memory/embedding-local.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"embedding-local.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/memory/embedding-local.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAyH9D,qBAAa,sBAAuB,YAAW,iBAAiB;IAC5D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,WAAW,CAA8B;gBAErC,KAAK,SAAgC;IAK3C,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAqG9B,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAyBjD,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE,CAAC;IA6B7D,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAqB9B,QAAQ,IAAI,OAAO;CAGtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-compartments.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/inject-compartments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAS3C,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,2CAA2C,CAAC;AAExF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,MAAM,WAAW,4BAA4B;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,qBAAqB,EAAE,MAAM,CAAC;IAC9B,uBAAuB,EAAE,MAAM,CAAC;IAChC,gBAAgB,EAAE,MAAM,CAAC;IACzB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACvB;AAWD,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAE3D;AAED,MAAM,WAAW,0BAA0B;IACvC,QAAQ,EAAE,OAAO,CAAC;IAClB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,sBAAsB,EAAE,MAAM,CAAC;CAClC;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CA6BnE;
|
|
1
|
+
{"version":3,"file":"inject-compartments.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/inject-compartments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAS3C,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,2CAA2C,CAAC;AAExF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,MAAM,WAAW,4BAA4B;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,qBAAqB,EAAE,MAAM,CAAC;IAC9B,uBAAuB,EAAE,MAAM,CAAC;IAChC,gBAAgB,EAAE,MAAM,CAAC;IACzB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACvB;AAWD,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAE3D;AAED,MAAM,WAAW,0BAA0B;IACvC,QAAQ,EAAE,OAAO,CAAC;IAClB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,sBAAsB,EAAE,MAAM,CAAC;CAClC;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CA6BnE;AA8ED,wBAAgB,2BAA2B,CACvC,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,WAAW,EAAE,EACvB,cAAc,EAAE,OAAO,EACvB,WAAW,CAAC,EAAE,MAAM,EACpB,qBAAqB,CAAC,EAAE,MAAM,GAC/B,4BAA4B,GAAG,IAAI,CAkHrC;AAED,wBAAgB,0BAA0B,CACtC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,WAAW,EAAE,EACvB,QAAQ,EAAE,4BAA4B,GACvC,0BAA0B,CAyB5B"}
|
package/dist/index.js
CHANGED
|
@@ -16166,6 +16166,8 @@ function cosineSimilarity(a, b) {
|
|
|
16166
16166
|
}
|
|
16167
16167
|
|
|
16168
16168
|
// src/features/magic-context/memory/embedding-local.ts
|
|
16169
|
+
import { mkdirSync } from "fs";
|
|
16170
|
+
import { join as join9 } from "path";
|
|
16169
16171
|
async function withQuietConsole(fn) {
|
|
16170
16172
|
const origWarn = console.warn;
|
|
16171
16173
|
const origError = console.error;
|
|
@@ -16250,6 +16252,13 @@ class LocalEmbeddingProvider {
|
|
|
16250
16252
|
if (LogLevel && "ERROR" in LogLevel) {
|
|
16251
16253
|
env.logLevel = LogLevel.ERROR;
|
|
16252
16254
|
}
|
|
16255
|
+
const modelCacheDir = join9(getOpenCodeStorageDir(), "plugin", "magic-context", "models");
|
|
16256
|
+
try {
|
|
16257
|
+
mkdirSync(modelCacheDir, { recursive: true });
|
|
16258
|
+
env.cacheDir = modelCacheDir;
|
|
16259
|
+
} catch {
|
|
16260
|
+
log("[magic-context] could not create model cache dir, using library default");
|
|
16261
|
+
}
|
|
16253
16262
|
const createPipeline = transformersModule.pipeline;
|
|
16254
16263
|
const MAX_ATTEMPTS = 3;
|
|
16255
16264
|
let lastError;
|
|
@@ -16351,6 +16360,7 @@ class LocalEmbeddingProvider {
|
|
|
16351
16360
|
}
|
|
16352
16361
|
var init_embedding_local = __esm(() => {
|
|
16353
16362
|
init_magic_context();
|
|
16363
|
+
init_data_path();
|
|
16354
16364
|
init_logger();
|
|
16355
16365
|
});
|
|
16356
16366
|
|
|
@@ -17401,11 +17411,11 @@ var init_migrations = __esm(() => {
|
|
|
17401
17411
|
|
|
17402
17412
|
// src/features/magic-context/storage-db.ts
|
|
17403
17413
|
import { Database as Database3 } from "bun:sqlite";
|
|
17404
|
-
import { mkdirSync } from "fs";
|
|
17405
|
-
import { join as
|
|
17414
|
+
import { mkdirSync as mkdirSync2 } from "fs";
|
|
17415
|
+
import { join as join10 } from "path";
|
|
17406
17416
|
function resolveDatabasePath() {
|
|
17407
|
-
const dbDir =
|
|
17408
|
-
return { dbDir, dbPath:
|
|
17417
|
+
const dbDir = join10(getOpenCodeStorageDir(), "plugin", "magic-context");
|
|
17418
|
+
return { dbDir, dbPath: join10(dbDir, "context.db") };
|
|
17409
17419
|
}
|
|
17410
17420
|
function initializeDatabase(db) {
|
|
17411
17421
|
db.run("PRAGMA journal_mode=WAL");
|
|
@@ -17720,7 +17730,7 @@ function openDatabase() {
|
|
|
17720
17730
|
}
|
|
17721
17731
|
return existing;
|
|
17722
17732
|
}
|
|
17723
|
-
|
|
17733
|
+
mkdirSync2(dbDir, { recursive: true });
|
|
17724
17734
|
const db = new Database3(dbPath);
|
|
17725
17735
|
initializeDatabase(db);
|
|
17726
17736
|
runMigrations(db);
|
|
@@ -18559,7 +18569,7 @@ var init_send_session_notification = __esm(() => {
|
|
|
18559
18569
|
|
|
18560
18570
|
// src/features/magic-context/compaction-marker.ts
|
|
18561
18571
|
import { Database as Database4 } from "bun:sqlite";
|
|
18562
|
-
import { join as
|
|
18572
|
+
import { join as join12 } from "path";
|
|
18563
18573
|
function randomBase62(length) {
|
|
18564
18574
|
const chars = [];
|
|
18565
18575
|
for (let i = 0;i < length; i++) {
|
|
@@ -18579,7 +18589,7 @@ function generatePartId(timestampMs, counter = 0n) {
|
|
|
18579
18589
|
return generateId("prt", timestampMs, counter);
|
|
18580
18590
|
}
|
|
18581
18591
|
function getOpenCodeDbPath3() {
|
|
18582
|
-
return
|
|
18592
|
+
return join12(getDataDir(), "opencode", "opencode.db");
|
|
18583
18593
|
}
|
|
18584
18594
|
function getWritableOpenCodeDb() {
|
|
18585
18595
|
const dbPath = getOpenCodeDbPath3();
|
|
@@ -19472,9 +19482,9 @@ var init_compartment_runner_validation = __esm(() => {
|
|
|
19472
19482
|
});
|
|
19473
19483
|
|
|
19474
19484
|
// src/hooks/magic-context/compartment-runner-historian.ts
|
|
19475
|
-
import { mkdirSync as
|
|
19485
|
+
import { mkdirSync as mkdirSync3, unlinkSync, writeFileSync } from "fs";
|
|
19476
19486
|
import { tmpdir as tmpdir2 } from "os";
|
|
19477
|
-
import { join as
|
|
19487
|
+
import { join as join13 } from "path";
|
|
19478
19488
|
async function runValidatedHistorianPass(args) {
|
|
19479
19489
|
const firstRun = await runHistorianPrompt({
|
|
19480
19490
|
...args,
|
|
@@ -19677,10 +19687,10 @@ function cleanupHistorianDump(sessionId, dumpPath) {
|
|
|
19677
19687
|
}
|
|
19678
19688
|
function dumpHistorianResponse(sessionId, label, text) {
|
|
19679
19689
|
try {
|
|
19680
|
-
|
|
19690
|
+
mkdirSync3(HISTORIAN_RESPONSE_DUMP_DIR, { recursive: true });
|
|
19681
19691
|
const safeSessionId = sanitizeDumpName(sessionId);
|
|
19682
19692
|
const safeLabel = sanitizeDumpName(label);
|
|
19683
|
-
const dumpPath =
|
|
19693
|
+
const dumpPath = join13(HISTORIAN_RESPONSE_DUMP_DIR, `${safeSessionId}-${safeLabel}-${Date.now()}.xml`);
|
|
19684
19694
|
writeFileSync(dumpPath, text, "utf8");
|
|
19685
19695
|
sessionLog(sessionId, "compartment agent: historian response dumped", {
|
|
19686
19696
|
label,
|
|
@@ -19704,7 +19714,7 @@ var init_compartment_runner_historian = __esm(() => {
|
|
|
19704
19714
|
init_shared();
|
|
19705
19715
|
init_assistant_message_extractor();
|
|
19706
19716
|
init_compartment_runner_validation();
|
|
19707
|
-
HISTORIAN_RESPONSE_DUMP_DIR =
|
|
19717
|
+
HISTORIAN_RESPONSE_DUMP_DIR = join13(tmpdir2(), "magic-context-historian");
|
|
19708
19718
|
});
|
|
19709
19719
|
|
|
19710
19720
|
// src/hooks/magic-context/compartment-runner-state-xml.ts
|
|
@@ -19775,15 +19785,28 @@ ${sections.join(`
|
|
|
19775
19785
|
`)}
|
|
19776
19786
|
</project-memory>`;
|
|
19777
19787
|
}
|
|
19788
|
+
function utilityTier(m) {
|
|
19789
|
+
if (m.retrievalCount > 0)
|
|
19790
|
+
return 0;
|
|
19791
|
+
if (CONSTRAINT_KEYWORDS.test(m.content))
|
|
19792
|
+
return 1;
|
|
19793
|
+
return 2;
|
|
19794
|
+
}
|
|
19778
19795
|
function trimMemoriesToBudget(sessionId, memories, budgetTokens) {
|
|
19779
19796
|
const sorted = [...memories].sort((a, b) => {
|
|
19780
19797
|
if (a.status === "permanent" && b.status !== "permanent")
|
|
19781
19798
|
return -1;
|
|
19782
19799
|
if (b.status === "permanent" && a.status !== "permanent")
|
|
19783
19800
|
return 1;
|
|
19801
|
+
const tierDiff = utilityTier(a) - utilityTier(b);
|
|
19802
|
+
if (tierDiff !== 0)
|
|
19803
|
+
return tierDiff;
|
|
19784
19804
|
const seenDiff = b.seenCount - a.seenCount;
|
|
19785
19805
|
if (seenDiff !== 0)
|
|
19786
19806
|
return seenDiff;
|
|
19807
|
+
const lenDiff = a.content.length - b.content.length;
|
|
19808
|
+
if (lenDiff !== 0)
|
|
19809
|
+
return lenDiff;
|
|
19787
19810
|
return a.id - b.id;
|
|
19788
19811
|
});
|
|
19789
19812
|
const result = [];
|
|
@@ -19917,13 +19940,14 @@ function findFirstTextPart(parts) {
|
|
|
19917
19940
|
function isDroppedPlaceholder(text) {
|
|
19918
19941
|
return /^\[dropped \u00A7\d+\u00A7\]$/.test(text.trim());
|
|
19919
19942
|
}
|
|
19920
|
-
var injectionCache, CHARS_PER_TOKEN_ESTIMATE = 4;
|
|
19943
|
+
var injectionCache, CHARS_PER_TOKEN_ESTIMATE = 4, CONSTRAINT_KEYWORDS;
|
|
19921
19944
|
var init_inject_compartments = __esm(() => {
|
|
19922
19945
|
init_compartment_storage();
|
|
19923
19946
|
init_constants();
|
|
19924
19947
|
init_storage_memory();
|
|
19925
19948
|
init_logger();
|
|
19926
19949
|
injectionCache = new Map;
|
|
19950
|
+
CONSTRAINT_KEYWORDS = /\b(must|never|always|cannot|should not|must not)\b/i;
|
|
19927
19951
|
});
|
|
19928
19952
|
|
|
19929
19953
|
// src/hooks/magic-context/compartment-runner-incremental.ts
|
|
@@ -28023,10 +28047,10 @@ var require_stringify = __commonJS((exports, module) => {
|
|
|
28023
28047
|
replacer = null;
|
|
28024
28048
|
indent = EMPTY;
|
|
28025
28049
|
};
|
|
28026
|
-
var
|
|
28050
|
+
var join16 = (one, two, gap) => one ? two ? one + two.trim() + LF + gap : one.trimRight() + repeat_line_breaks(Math.max(1, count_trailing_line_breaks(one, gap)), gap) : two ? two.trimRight() + repeat_line_breaks(Math.max(1, count_trailing_line_breaks(two, gap)), gap) : EMPTY;
|
|
28027
28051
|
var join_content = (inside, value, gap) => {
|
|
28028
28052
|
const comment = process_comments(value, PREFIX_BEFORE, gap + indent, true);
|
|
28029
|
-
return
|
|
28053
|
+
return join16(comment, inside, gap);
|
|
28030
28054
|
};
|
|
28031
28055
|
var stringify_string = (holder, key, value) => {
|
|
28032
28056
|
const raw = get_raw_string_literal(holder, key);
|
|
@@ -28048,13 +28072,13 @@ var require_stringify = __commonJS((exports, module) => {
|
|
|
28048
28072
|
if (i !== 0) {
|
|
28049
28073
|
inside += COMMA;
|
|
28050
28074
|
}
|
|
28051
|
-
const before =
|
|
28075
|
+
const before = join16(after_comma, process_comments(value, BEFORE(i), deeper_gap), deeper_gap);
|
|
28052
28076
|
inside += before || LF + deeper_gap;
|
|
28053
28077
|
inside += stringify(i, value, deeper_gap) || STR_NULL;
|
|
28054
28078
|
inside += process_comments(value, AFTER_VALUE(i), deeper_gap);
|
|
28055
28079
|
after_comma = process_comments(value, AFTER(i), deeper_gap);
|
|
28056
28080
|
}
|
|
28057
|
-
inside +=
|
|
28081
|
+
inside += join16(after_comma, process_comments(value, PREFIX_AFTER, deeper_gap), deeper_gap);
|
|
28058
28082
|
return BRACKET_OPEN + join_content(inside, value, gap) + BRACKET_CLOSE;
|
|
28059
28083
|
};
|
|
28060
28084
|
var object_stringify = (value, gap) => {
|
|
@@ -28075,13 +28099,13 @@ var require_stringify = __commonJS((exports, module) => {
|
|
|
28075
28099
|
inside += COMMA;
|
|
28076
28100
|
}
|
|
28077
28101
|
first = false;
|
|
28078
|
-
const before =
|
|
28102
|
+
const before = join16(after_comma, process_comments(value, BEFORE(key), deeper_gap), deeper_gap);
|
|
28079
28103
|
inside += before || LF + deeper_gap;
|
|
28080
28104
|
inside += quote(key) + process_comments(value, AFTER_PROP(key), deeper_gap) + COLON + process_comments(value, AFTER_COLON(key), deeper_gap) + SPACE + sv + process_comments(value, AFTER_VALUE(key), deeper_gap);
|
|
28081
28105
|
after_comma = process_comments(value, AFTER(key), deeper_gap);
|
|
28082
28106
|
};
|
|
28083
28107
|
keys.forEach(iteratee);
|
|
28084
|
-
inside +=
|
|
28108
|
+
inside += join16(after_comma, process_comments(value, PREFIX_AFTER, deeper_gap), deeper_gap);
|
|
28085
28109
|
return CURLY_BRACKET_OPEN + join_content(inside, value, gap) + CURLY_BRACKET_CLOSE;
|
|
28086
28110
|
};
|
|
28087
28111
|
function stringify(key, holder, gap) {
|
|
@@ -28178,12 +28202,12 @@ var exports_tui_config = {};
|
|
|
28178
28202
|
__export(exports_tui_config, {
|
|
28179
28203
|
ensureTuiPluginEntry: () => ensureTuiPluginEntry
|
|
28180
28204
|
});
|
|
28181
|
-
import { existsSync as existsSync7, mkdirSync as
|
|
28182
|
-
import { dirname as dirname2, join as
|
|
28205
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync5, readFileSync as readFileSync6, writeFileSync as writeFileSync3 } from "fs";
|
|
28206
|
+
import { dirname as dirname2, join as join16 } from "path";
|
|
28183
28207
|
function resolveTuiConfigPath() {
|
|
28184
28208
|
const configDir = getOpenCodeConfigPaths({ binary: "opencode" }).configDir;
|
|
28185
|
-
const jsoncPath =
|
|
28186
|
-
const jsonPath =
|
|
28209
|
+
const jsoncPath = join16(configDir, "tui.jsonc");
|
|
28210
|
+
const jsonPath = join16(configDir, "tui.json");
|
|
28187
28211
|
if (existsSync7(jsoncPath))
|
|
28188
28212
|
return jsoncPath;
|
|
28189
28213
|
if (existsSync7(jsonPath))
|
|
@@ -28204,7 +28228,7 @@ function ensureTuiPluginEntry() {
|
|
|
28204
28228
|
}
|
|
28205
28229
|
plugins.push(PLUGIN_ENTRY);
|
|
28206
28230
|
config2.plugin = plugins;
|
|
28207
|
-
|
|
28231
|
+
mkdirSync5(dirname2(configPath), { recursive: true });
|
|
28208
28232
|
writeFileSync3(configPath, `${import_comment_json.stringify(config2, null, 2)}
|
|
28209
28233
|
`);
|
|
28210
28234
|
log(`[magic-context] added TUI plugin entry to ${configPath}`);
|
|
@@ -28469,58 +28493,75 @@ Check verifiable memories against actual repository state. Update stale wording,
|
|
|
28469
28493
|
- No memories reference files or paths that no longer exist.
|
|
28470
28494
|
- Updated memories use current naming and paths.`;
|
|
28471
28495
|
}
|
|
28472
|
-
function buildArchiveStalePrompt(projectPath) {
|
|
28496
|
+
function buildArchiveStalePrompt(projectPath, userMemories) {
|
|
28497
|
+
const userProfileBlock = userMemories && userMemories.length > 0 ? `
|
|
28498
|
+
### Global User Profile (already injected into ALL sessions across ALL projects)
|
|
28499
|
+
These user memories are ALREADY available to the agent globally. Project memories that merely restate the same preference/rule are redundant and should be archived \u2014 but ONLY if the project memory adds ZERO project-specific detail beyond what the global memory already says.
|
|
28500
|
+
|
|
28501
|
+
${userMemories.map((um) => `- [U${um.id}] ${um.content}`).join(`
|
|
28502
|
+
`)}
|
|
28503
|
+
` : "";
|
|
28473
28504
|
return `## Task: Archive Stale Memories
|
|
28474
28505
|
|
|
28475
28506
|
**Project:** ${projectPath}
|
|
28476
28507
|
|
|
28477
28508
|
### Goal
|
|
28478
|
-
Find and archive memories that
|
|
28509
|
+
Find and archive memories that waste the limited injection budget (~6000 tokens, fits ~150 memories).
|
|
28510
|
+
${userProfileBlock}
|
|
28511
|
+
### Archive criteria (archive IF any apply)
|
|
28512
|
+
|
|
28513
|
+
1. **Code restatement without rationale** \u2014 merely describes what code does without explaining WHY or what would break if changed.
|
|
28514
|
+
- Archive: "Tag assignment uses one DB transaction" (obvious from code)
|
|
28515
|
+
- Keep: "Tag assignment uses one DB transaction because tags rows and session_meta.counter must stay in sync" (explains the constraint)
|
|
28516
|
+
|
|
28517
|
+
2. **Redundant with other memories** \u2014 same information expressed differently. Keep the better-worded one.
|
|
28518
|
+
|
|
28519
|
+
3. **Stale implementation detail** \u2014 references specific functions, line numbers, or internal structures that change frequently and are better found by reading code.
|
|
28520
|
+
- Archive: "Function X is called at line 289 of file Y"
|
|
28521
|
+
- Keep: "Feature X requires Y to be initialized before Z" (design constraint)
|
|
28522
|
+
|
|
28523
|
+
4. **Low retrieval signal** \u2014 seen_count=1, retrieval_count=0, and no constraint language. These were promoted once but never needed again.
|
|
28524
|
+
|
|
28525
|
+
5. **Redundant with global user profile** \u2014 ONLY if the project memory adds ZERO project-specific detail beyond what the global memory already says. A project memory that applies a global principle to a specific context (e.g., "cache awareness is highest priority" applies a general principle to THIS project's north star) is NOT redundant \u2014 it narrows the global principle.
|
|
28526
|
+
|
|
28527
|
+
6. **Bare config defaults** \u2014 single-line values like \`enabled=true\` or \`experimental.X=false\` with no surrounding explanation or rationale.
|
|
28528
|
+
|
|
28529
|
+
7. **Completed one-time instructions** \u2014 imperative USER_DIRECTIVES like "Add X", "Create Y", "Publish as Z" where the action has clearly been done.
|
|
28530
|
+
|
|
28531
|
+
### Keep criteria (keep IF ANY apply \u2014 these OVERRIDE archive criteria)
|
|
28532
|
+
|
|
28533
|
+
1. **Contains constraint/rule** \u2014 uses "must", "never", "always", "cannot", "should not". CONSTRAINTS category gets extra protection: only archive if the EXACT same constraint exists word-for-word in another memory.
|
|
28534
|
+
2. **Captures non-obvious design reasoning** \u2014 explains WHY, not just WHAT. Look for "because", "so that", "to prevent", "to avoid".
|
|
28535
|
+
3. **Project-specific behavioral rule** \u2014 even if it sounds generic, if it's in USER_DIRECTIVES it was explicitly stated by the user for this project. Only archive if: (a) the action is clearly completed, or (b) it is 100% identical in scope to a global user memory.
|
|
28536
|
+
4. **Post-failure learning** \u2014 memories that encode lessons learned from real bugs, regressions, or user corrections. These prevent re-encountering the same problem.
|
|
28537
|
+
5. **Environment/path information** \u2014 saves agent from hunting for locations.
|
|
28538
|
+
6. **Config defaults with context** \u2014 prevents wrong assumptions. Archive ONLY bare values with no surrounding explanation.
|
|
28539
|
+
7. **Known issues** \u2014 prevents re-encountering solved problems. NEVER archive KNOWN_ISSUES.
|
|
28540
|
+
8. **High retrieval signal** \u2014 retrieval_count > 0 means the agent actually searched for this.
|
|
28541
|
+
9. **Priority/philosophy statements** \u2014 "X is the highest priority" or "north star" type directives that shape all decisions.
|
|
28479
28542
|
|
|
28480
28543
|
### Process
|
|
28481
28544
|
|
|
28482
28545
|
1. **List all active memories** with \`ctx_memory(action="list")\`.
|
|
28483
|
-
2. **
|
|
28484
|
-
- References to tools that no longer exist (grep the tool registry)
|
|
28485
|
-
- References to files or directories that were deleted or renamed
|
|
28486
|
-
- References to old repository names, branches, or workflows
|
|
28487
|
-
- References to features explicitly described as "removed" or "replaced"
|
|
28488
|
-
- References to config keys that no longer appear in the schema
|
|
28489
|
-
- Session-local context that has no ongoing value ("in this session", "earlier today")
|
|
28490
|
-
- **Completed one-time instructions** in USER_DIRECTIVES \u2014 imperative directives like "Add X", "Create Y", "License as MIT", "Publish as Z" where the action has clearly been done (check the codebase to confirm completion)
|
|
28491
|
-
- **Low-value implementation minutiae** in ARCHITECTURE_DECISIONS \u2014 single-line statements that merely restate what code does without explaining WHY or capturing a non-obvious constraint. Example: "Tag assignment uses one DB transaction" just restates code behavior \u2014 this belongs in source comments, not project memory. Keep memories that explain *why* a design choice was made, *what constraint* drove it, or *what would break* if it changed.
|
|
28546
|
+
2. **Apply the archive and keep criteria above to each memory.**
|
|
28492
28547
|
3. **Verify each candidate** against the codebase before archiving:
|
|
28493
28548
|
- Check if the file/tool/path actually exists
|
|
28494
|
-
-
|
|
28495
|
-
- For USER_DIRECTIVES: verify the instructed action was completed (e.g., "License as MIT" \u2192 check LICENSE file exists)
|
|
28549
|
+
- For USER_DIRECTIVES: verify the instructed action was completed
|
|
28496
28550
|
- If the reference is ambiguous, leave it alone
|
|
28497
28551
|
4. **Archive** with \`ctx_memory(action="archive", id=N, reason="...")\`. Always include a specific reason.
|
|
28498
28552
|
|
|
28499
|
-
###
|
|
28500
|
-
-
|
|
28501
|
-
-
|
|
28502
|
-
-
|
|
28503
|
-
-
|
|
28504
|
-
-
|
|
28505
|
-
- Completed setup/publishing/licensing instructions that are done and won't recur
|
|
28506
|
-
- Implementation details that simply restate code behavior without adding design rationale
|
|
28507
|
-
|
|
28508
|
-
### USER_DIRECTIVES handling
|
|
28509
|
-
- **Archive** completed one-time instructions: "License as MIT", "Publish as @cortexkit/...", "Add changelog to releases", "For the README animation, emphasize X"
|
|
28510
|
-
- **Keep** ongoing preferences and behavioral rules: "Ask before changing behavior when audit finding is ambiguous", "Cache awareness is the highest-priority feature"
|
|
28511
|
-
- **Keep** workflow preferences that apply to future work: "Always use scripts/release.sh for releases"
|
|
28512
|
-
- Rule of thumb: if the directive uses imperative "do this" language and the action is done, archive it. If it describes how to behave going forward, keep it.
|
|
28513
|
-
|
|
28514
|
-
### ARCHITECTURE_DECISIONS pruning
|
|
28515
|
-
- **Archive** memories that only restate what code does: "Function X calls Y", "Module A imports B"
|
|
28516
|
-
- **Keep** memories that explain constraints, tradeoffs, or non-obvious design reasoning: "X uses Y because Z would cause cache busts"
|
|
28517
|
-
- **Keep** memories that warn about gotchas: "Don't use cwd fallback because it causes cross-project contamination"
|
|
28518
|
-
- Rule of thumb: if removing the memory would cause someone to make a wrong design decision, keep it. If it's just restating navigable code structure, archive it \u2014 ARCHITECTURE.md covers that.
|
|
28553
|
+
### Category-specific rules
|
|
28554
|
+
- **CONSTRAINTS**: archive ONLY when provably redundant with another specific constraint (not just thematically similar). Each constraint typically guards against a specific bug \u2014 losing it means the bug can return.
|
|
28555
|
+
- **USER_DIRECTIVES**: archive ONLY completed one-time tasks or exact duplicates of global user profile entries. Keep ongoing behavioral rules even if they have low retrieval.
|
|
28556
|
+
- **KNOWN_ISSUES**: NEVER archive \u2014 these prevent re-encountering bugs.
|
|
28557
|
+
- **ARCHITECTURE_DECISIONS**: archive code restatements freely, keep anything with "because", "so that", "to prevent", "to avoid".
|
|
28558
|
+
- **CONFIG_DEFAULTS**: archive bare values with no context, keep values that include rationale or prevent wrong assumptions.
|
|
28519
28559
|
|
|
28520
28560
|
### Success criteria
|
|
28521
28561
|
- No active memories reference non-existent files, tools, or paths.
|
|
28522
28562
|
- No completed one-time instructions remain in USER_DIRECTIVES.
|
|
28523
28563
|
- ARCHITECTURE_DECISIONS contains design reasoning, not code restatements.
|
|
28564
|
+
- CONSTRAINTS are preserved unless provably duplicated.
|
|
28524
28565
|
- Every archived memory has a specific reason.
|
|
28525
28566
|
- Conservative \u2014 when in doubt, leave it active.`;
|
|
28526
28567
|
}
|
|
@@ -28714,7 +28755,7 @@ function buildDreamTaskPrompt(task, args) {
|
|
|
28714
28755
|
case "verify":
|
|
28715
28756
|
return buildVerifyPrompt(args.projectPath);
|
|
28716
28757
|
case "archive-stale":
|
|
28717
|
-
return buildArchiveStalePrompt(args.projectPath);
|
|
28758
|
+
return buildArchiveStalePrompt(args.projectPath, args.userMemories);
|
|
28718
28759
|
case "improve":
|
|
28719
28760
|
return buildImprovePrompt(args.projectPath);
|
|
28720
28761
|
case "maintain-docs":
|
|
@@ -29317,7 +29358,6 @@ If no promotions are warranted, return empty arrays. Always consume reviewed can
|
|
|
29317
29358
|
}
|
|
29318
29359
|
}
|
|
29319
29360
|
}
|
|
29320
|
-
|
|
29321
29361
|
// src/features/magic-context/dreamer/storage-dream-runs.ts
|
|
29322
29362
|
var insertDreamRunStatements = new WeakMap;
|
|
29323
29363
|
var getDreamRunsByProjectStatements = new Map;
|
|
@@ -29608,10 +29648,15 @@ async function runDream(args) {
|
|
|
29608
29648
|
architecture: existsSync4(join8(docsDir, "ARCHITECTURE.md")),
|
|
29609
29649
|
structure: existsSync4(join8(docsDir, "STRUCTURE.md"))
|
|
29610
29650
|
} : undefined;
|
|
29651
|
+
const userMemories = taskName === "archive-stale" ? getActiveUserMemories(args.db).map((um) => ({
|
|
29652
|
+
id: um.id,
|
|
29653
|
+
content: um.content
|
|
29654
|
+
})) : undefined;
|
|
29611
29655
|
const taskPrompt = buildDreamTaskPrompt(taskName, {
|
|
29612
29656
|
projectPath: args.projectIdentity,
|
|
29613
29657
|
lastDreamAt,
|
|
29614
|
-
existingDocs
|
|
29658
|
+
existingDocs,
|
|
29659
|
+
userMemories
|
|
29615
29660
|
});
|
|
29616
29661
|
const createResponse = await args.client.session.create({
|
|
29617
29662
|
body: {
|
|
@@ -30159,7 +30204,7 @@ function createCompactionHandler() {
|
|
|
30159
30204
|
init_logger();
|
|
30160
30205
|
import { existsSync as existsSync5, readFileSync as readFileSync4 } from "fs";
|
|
30161
30206
|
import { homedir as homedir5, platform as platform2 } from "os";
|
|
30162
|
-
import { join as
|
|
30207
|
+
import { join as join11 } from "path";
|
|
30163
30208
|
var cachedLimits = null;
|
|
30164
30209
|
var lastLoadAttempt = 0;
|
|
30165
30210
|
var RELOAD_INTERVAL_MS = 5 * 60 * 1000;
|
|
@@ -30170,11 +30215,11 @@ function getModelsJsonPath() {
|
|
|
30170
30215
|
if (xdgCache) {
|
|
30171
30216
|
cacheBase = xdgCache;
|
|
30172
30217
|
} else if (os3 === "win32") {
|
|
30173
|
-
cacheBase = process.env.LOCALAPPDATA ??
|
|
30218
|
+
cacheBase = process.env.LOCALAPPDATA ?? join11(homedir5(), "AppData", "Local");
|
|
30174
30219
|
} else {
|
|
30175
|
-
cacheBase =
|
|
30220
|
+
cacheBase = join11(homedir5(), ".cache");
|
|
30176
30221
|
}
|
|
30177
|
-
return
|
|
30222
|
+
return join11(cacheBase, "opencode", "models.json");
|
|
30178
30223
|
}
|
|
30179
30224
|
function loadModelsDevLimits() {
|
|
30180
30225
|
const limits = new Map;
|
|
@@ -33766,7 +33811,7 @@ init_send_session_notification();
|
|
|
33766
33811
|
|
|
33767
33812
|
// src/hooks/magic-context/system-prompt-hash.ts
|
|
33768
33813
|
import { existsSync as existsSync6, readFileSync as readFileSync5, realpathSync } from "fs";
|
|
33769
|
-
import { join as
|
|
33814
|
+
import { join as join14, resolve as resolve2, sep } from "path";
|
|
33770
33815
|
|
|
33771
33816
|
// src/agents/magic-context-prompt.ts
|
|
33772
33817
|
function getToolHistoryGuidance(dropToolStructure) {
|
|
@@ -33986,7 +34031,7 @@ var DOC_FILES = ["ARCHITECTURE.md", "STRUCTURE.md"];
|
|
|
33986
34031
|
function readProjectDocs(directory) {
|
|
33987
34032
|
const sections = [];
|
|
33988
34033
|
for (const filename of DOC_FILES) {
|
|
33989
|
-
const filePath =
|
|
34034
|
+
const filePath = join14(directory, filename);
|
|
33990
34035
|
try {
|
|
33991
34036
|
if (existsSync6(filePath)) {
|
|
33992
34037
|
const content = readFileSync5(filePath, "utf-8").trim();
|
|
@@ -36000,19 +36045,19 @@ init_model_requirements();
|
|
|
36000
36045
|
|
|
36001
36046
|
// src/shared/rpc-server.ts
|
|
36002
36047
|
init_logger();
|
|
36003
|
-
import { mkdirSync as
|
|
36048
|
+
import { mkdirSync as mkdirSync4, renameSync, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
36004
36049
|
import { createServer } from "http";
|
|
36005
36050
|
import { dirname } from "path";
|
|
36006
36051
|
|
|
36007
36052
|
// src/shared/rpc-utils.ts
|
|
36008
36053
|
import { createHash } from "crypto";
|
|
36009
|
-
import { join as
|
|
36054
|
+
import { join as join15 } from "path";
|
|
36010
36055
|
function projectHash(directory) {
|
|
36011
36056
|
const normalized = directory.replace(/\/+$/, "");
|
|
36012
36057
|
return createHash("sha256").update(normalized).digest("hex").slice(0, 16);
|
|
36013
36058
|
}
|
|
36014
36059
|
function rpcPortFilePath(storageDir, directory) {
|
|
36015
|
-
return
|
|
36060
|
+
return join15(storageDir, "rpc", projectHash(directory), "port");
|
|
36016
36061
|
}
|
|
36017
36062
|
|
|
36018
36063
|
// src/shared/rpc-server.ts
|
|
@@ -36044,7 +36089,7 @@ class MagicContextRpcServer {
|
|
|
36044
36089
|
this.server = server;
|
|
36045
36090
|
try {
|
|
36046
36091
|
const dir = dirname(this.portFilePath);
|
|
36047
|
-
|
|
36092
|
+
mkdirSync4(dir, { recursive: true });
|
|
36048
36093
|
const tmpPath = `${this.portFilePath}.tmp`;
|
|
36049
36094
|
writeFileSync2(tmpPath, String(this.port), "utf-8");
|
|
36050
36095
|
renameSync(tmpPath, this.portFilePath);
|
package/package.json
CHANGED