@cortexkit/opencode-magic-context 0.30.2 → 0.30.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.
- package/README.md +1 -1
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-openai.d.ts.map +1 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/recursive-text-splitter.d.ts +36 -0
- package/dist/features/magic-context/recursive-text-splitter.d.ts.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +190 -189
- package/dist/plugin/conflict-warning-hook.d.ts +0 -5
- package/dist/plugin/conflict-warning-hook.d.ts.map +1 -1
- package/dist/shared/announcement.d.ts +1 -1
- package/dist/shared/announcement.d.ts.map +1 -1
- package/dist/shared/data-path.d.ts.map +1 -1
- package/dist/shared/tui-config.d.ts +7 -2
- package/dist/shared/tui-config.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/shared/announcement.ts +4 -2
- package/src/shared/data-path.test.ts +28 -0
- package/src/shared/data-path.ts +5 -0
- package/src/shared/tui-config.ts +7 -2
- package/src/tui/index.tsx +0 -127
package/README.md
CHANGED
|
@@ -280,7 +280,7 @@ Magic Context also writes to a few other locations:
|
|
|
280
280
|
|---|---|---|
|
|
281
281
|
| `~/.local/share/cortexkit/magic-context/context.db` | SQLite database — tags, compartments, memories, all durable state (XDG-equivalent on Windows) | **Must persist.** Losing it loses your memory/history. |
|
|
282
282
|
| `~/.local/share/cortexkit/magic-context/models/` | Local embedding model cache (~90 MB `Xenova/all-MiniLM-L6-v2` ONNX), downloaded on first use when local embeddings are enabled | Should persist, else re-downloaded each run. Not used when `memory.enabled: false` or an `openai_compatible`/`ollama` embedding backend is configured. |
|
|
283
|
-
| `${TMPDIR}/opencode/magic-context/magic-context.log
|
|
283
|
+
| `$MAGIC_CONTEXT_LOG_PATH` (default: `${TMPDIR}/opencode/magic-context/magic-context.log`, `pi/` for Pi) | Diagnostic log. Set `MAGIC_CONTEXT_LOG_PATH` to redirect it (e.g. to a persistent path in a container). | Disposable. |
|
|
284
284
|
|
|
285
285
|
**Sandboxed / ephemeral environments (Docker, CI, disposable containers):** mount the `~/.local/share/cortexkit/magic-context/` directory on a persistent volume so the database and model cache survive between runs. If only the model cache is ephemeral, the model is simply re-downloaded; if the database is ephemeral, memory and history don't accumulate. To avoid the ~90 MB model download entirely, set `memory.enabled: false` or point `embedding` at a remote `openai_compatible`/`ollama` backend.
|
|
286
286
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compartment-chunk-embedding.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/compartment-chunk-embedding.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compartment-chunk-embedding.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/compartment-chunk-embedding.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAkC,MAAM,qBAAqB,CAAC;AAGpF,eAAO,MAAM,0CAA0C,MAAM,CAAC;AAE9D;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAwC7C,MAAM,WAAW,iCAAiC;IAC9C,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,sBAAsB;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,+BAA+B;IAC5C,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MA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O,CAAC,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE,CAAC;IAuL7B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,QAAQ,IAAI,OAAO;IAInB;;;;;;;;OAQG;IACH,OAAO,CAAC,wBAAwB;IAsBhC,OAAO,CAAC,aAAa;IAiCrB,OAAO,CAAC,aAAa;IAUrB,gBAAgB,IAAI,YAAY;IAQhC,gBAAgB,IAAI,MAAM;IAG1B,aAAa,IAAI,IAAI;CAMxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-embedding-registry.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/project-embedding-registry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAGzE,OAAO,KAAK,EAAE,QAAQ,EAAkC,MAAM,qBAAqB,CAAC;AAgCpF,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AA2DvF,MAAM,WAAW,iBAAiB;IAC9B,aAAa,EAAE,OAAO,CAAC;IACvB,gBAAgB,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,oCAAoC;IACjD,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB;6EACyE;IACzE,KAAK,EAAE,MAAM,CAAC;IACd,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,CAAC;CACpB;AAmDD,oFAAoF;AACpF,wBAAgB,wBAAwB,CAAC,eAAe,EAAE,MAAM,GAAG,IAA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E,MAAM,EAAE,EACf,MAAM,CAAC,EAAE,WAAW,EACpB,OAAO,GAAE,gBAA4B,GACtC,OAAO,CAAC;IAAE,OAAO,EAAE,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CA0B3F;
|
|
1
|
+
{"version":3,"file":"project-embedding-registry.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/project-embedding-registry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAGzE,OAAO,KAAK,EAAE,QAAQ,EAAkC,MAAM,qBAAqB,CAAC;AAgCpF,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AA2DvF,MAAM,WAAW,iBAAiB;IAC9B,aAAa,EAAE,OAAO,CAAC;IACvB,gBAAgB,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,oCAAoC;IACjD,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB;6EACyE;IACzE,KAAK,EAAE,MAAM,CAAC;IACd,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,CAAC;CACpB;AAmDD,oFAAoF;AACpF,wBAAgB,wBAAwB,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAEtE;AAyTD,MAAM,WAAW,yBAAyB;IACtC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE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AE,EAAE,QAAQ,EACZ,SAAS,SAAK,GACf,OAAO,CAAC;IACP,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAClF,CAAC,CAiED;AAED,wBAAgB,iCAAiC,CAC7C,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,eAAe,KAAK,iBAAiB,GAAG,IAAI,CAAC,GAAG,IAAI,GACxE,IAAI,CAEN;AAED,wBAAgB,sCAAsC,IAAI,IAAI,CAS7D"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal synchronous port of LangChain's `RecursiveCharacterTextSplitter`.
|
|
3
|
+
*
|
|
4
|
+
* Vendored (not depended on) so the plugin install stays lean and free of the
|
|
5
|
+
* supply-chain surface of the full `@langchain/textsplitters` package (whose
|
|
6
|
+
* bundled dist tripped an org Socket "obfuscated code" alert — a false positive
|
|
7
|
+
* on minified output, but a policy blocker). We only need the recursive
|
|
8
|
+
* character split for one job: cutting a single oversized canonical line down
|
|
9
|
+
* to a token budget. The Document/metadata/language-preset/token machinery in
|
|
10
|
+
* the upstream package is irrelevant here, so this keeps just the core
|
|
11
|
+
* algorithm (`splitOnSeparator` + `mergeSplits` + `_splitText`) and makes it
|
|
12
|
+
* synchronous (our `lengthFunction` is a sync tokenizer).
|
|
13
|
+
*
|
|
14
|
+
* Algorithm and separator hierarchy ported faithfully from
|
|
15
|
+
* `@langchain/textsplitters` v1.0.1 (`text_splitter.ts`), MIT-licensed
|
|
16
|
+
* (LangChain, Inc.). Behavior matches upstream for `keepSeparator: false`,
|
|
17
|
+
* `chunkOverlap: 0`, which is all this call site uses.
|
|
18
|
+
*/
|
|
19
|
+
/** Length of a piece of text, in whatever unit the caller measures (tokens). */
|
|
20
|
+
export type LengthFunction = (text: string) => number;
|
|
21
|
+
export interface RecursiveCharacterSplitOptions {
|
|
22
|
+
/** Max length (in `lengthFunction` units) of an emitted chunk. */
|
|
23
|
+
chunkSize: number;
|
|
24
|
+
/** Length function; defaults to character count. */
|
|
25
|
+
lengthFunction?: LengthFunction;
|
|
26
|
+
/** Separator hierarchy, tried in order; "" means split into characters. */
|
|
27
|
+
separators?: string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Recursively split `text` into chunks no larger than `chunkSize` (measured by
|
|
31
|
+
* `lengthFunction`), preferring the coarsest separator that keeps chunks under
|
|
32
|
+
* budget and falling back through the separator hierarchy down to characters.
|
|
33
|
+
* Synchronous.
|
|
34
|
+
*/
|
|
35
|
+
export declare function recursiveCharacterSplit(text: string, options: RecursiveCharacterSplitOptions): string[];
|
|
36
|
+
//# sourceMappingURL=recursive-text-splitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recursive-text-splitter.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/recursive-text-splitter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,gFAAgF;AAChF,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;AAEtD,MAAM,WAAW,8BAA8B;IAC3C,kEAAkE;IAClE,SAAS,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,2EAA2E;IAC3E,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAsGD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACnC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,8BAA8B,GACxC,MAAM,EAAE,CAMV"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAylBhE,QAAA,MAAM,MAAM,EAAE,YAGb,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -64,6 +64,9 @@ function getMagicContextTempDir(harness = getHarness()) {
|
|
|
64
64
|
return path.join(os.tmpdir(), harness, "magic-context");
|
|
65
65
|
}
|
|
66
66
|
function getMagicContextLogPath(harness = getHarness()) {
|
|
67
|
+
const envPath = process.env.MAGIC_CONTEXT_LOG_PATH?.trim();
|
|
68
|
+
if (envPath)
|
|
69
|
+
return envPath;
|
|
67
70
|
return path.join(getMagicContextTempDir(harness), "magic-context.log");
|
|
68
71
|
}
|
|
69
72
|
function getProjectMagicContextDir(directory) {
|
|
@@ -165584,7 +165587,6 @@ var init_rpc_notifications = __esm(() => {
|
|
|
165584
165587
|
// src/plugin/conflict-warning-hook.ts
|
|
165585
165588
|
var exports_conflict_warning_hook = {};
|
|
165586
165589
|
__export(exports_conflict_warning_hook, {
|
|
165587
|
-
sendTuiSetupNotification: () => sendTuiSetupNotification,
|
|
165588
165590
|
sendStartupAnnouncement: () => sendStartupAnnouncement,
|
|
165589
165591
|
sendSchemaFenceWarning: () => sendSchemaFenceWarning,
|
|
165590
165592
|
sendConflictWarning: () => sendConflictWarning,
|
|
@@ -165824,58 +165826,6 @@ async function cleanupEnabledMessages(messages, serverUrl, sessionId) {
|
|
|
165824
165826
|
}
|
|
165825
165827
|
}
|
|
165826
165828
|
}
|
|
165827
|
-
async function sendTuiSetupNotification(client, directory, serverUrl) {
|
|
165828
|
-
const { sessionId } = getDesktopState(directory);
|
|
165829
|
-
if (!sessionId)
|
|
165830
|
-
return;
|
|
165831
|
-
if (await waitForSafeNotificationTarget(client, sessionId) === "skip")
|
|
165832
|
-
return;
|
|
165833
|
-
const text = [
|
|
165834
|
-
`${TUI_SETUP_MARKER}`,
|
|
165835
|
-
"",
|
|
165836
|
-
"Magic Context added its TUI plugin to your tui.json.",
|
|
165837
|
-
"Restart OpenCode to see the sidebar with live context breakdown,",
|
|
165838
|
-
"token usage, historian status, memory counts, and more."
|
|
165839
|
-
].join(`
|
|
165840
|
-
`);
|
|
165841
|
-
try {
|
|
165842
|
-
const c = client;
|
|
165843
|
-
const promptInput = {
|
|
165844
|
-
path: { id: sessionId },
|
|
165845
|
-
body: {
|
|
165846
|
-
noReply: true,
|
|
165847
|
-
parts: [{ type: "text", text, ignored: true }]
|
|
165848
|
-
}
|
|
165849
|
-
};
|
|
165850
|
-
if (typeof c.session?.prompt === "function") {
|
|
165851
|
-
await Promise.resolve(c.session.prompt(promptInput));
|
|
165852
|
-
} else if (typeof c.session?.promptAsync === "function") {
|
|
165853
|
-
await c.session.promptAsync(promptInput);
|
|
165854
|
-
}
|
|
165855
|
-
} catch {
|
|
165856
|
-
return;
|
|
165857
|
-
}
|
|
165858
|
-
if (!serverUrl)
|
|
165859
|
-
return;
|
|
165860
|
-
setTimeout(async () => {
|
|
165861
|
-
try {
|
|
165862
|
-
const msgs = await getSessionMessages(client, sessionId);
|
|
165863
|
-
for (let i = msgs.length - 1;i >= 0; i--) {
|
|
165864
|
-
const msg = msgs[i];
|
|
165865
|
-
const msgId = msg.info?.id;
|
|
165866
|
-
if (!msgId || msg.info?.role !== "user")
|
|
165867
|
-
break;
|
|
165868
|
-
const parts = msg.parts ?? [];
|
|
165869
|
-
const isTuiSetup = parts.length > 0 && parts.every((p) => p.ignored === true && p.type === "text" && typeof p.text === "string" && p.text.startsWith(TUI_SETUP_MARKER));
|
|
165870
|
-
if (isTuiSetup) {
|
|
165871
|
-
await deleteMessage(serverUrl, sessionId, msgId);
|
|
165872
|
-
} else {
|
|
165873
|
-
break;
|
|
165874
|
-
}
|
|
165875
|
-
}
|
|
165876
|
-
} catch {}
|
|
165877
|
-
}, 1000);
|
|
165878
|
-
}
|
|
165879
165829
|
async function sendSchemaFenceWarning(client, directory, detail) {
|
|
165880
165830
|
const { sessionId } = getDesktopState(directory);
|
|
165881
165831
|
if (!sessionId)
|
|
@@ -165957,7 +165907,7 @@ async function sendStartupAnnouncement(client, directory, version2, features, fo
|
|
|
165957
165907
|
}
|
|
165958
165908
|
markSeen(version2);
|
|
165959
165909
|
}
|
|
165960
|
-
var CONFLICT_WARNING_MARKER = "⚠️ Magic Context is disabled due to conflicting configuration:", SCHEMA_FENCE_MARKER = "⚠️ Magic Context is disabled — database is newer than this version", ENABLED_MARKER = "✨ Magic Context is now enabled",
|
|
165910
|
+
var CONFLICT_WARNING_MARKER = "⚠️ Magic Context is disabled due to conflicting configuration:", SCHEMA_FENCE_MARKER = "⚠️ Magic Context is disabled — database is newer than this version", ENABLED_MARKER = "✨ Magic Context is now enabled", ANNOUNCEMENT_MARKER = "✨ Magic Context — what's new in", cachedDesktopStateByDir;
|
|
165961
165911
|
var init_conflict_warning_hook = __esm(() => {
|
|
165962
165912
|
init_conflict_detector();
|
|
165963
165913
|
init_logger();
|
|
@@ -166254,6 +166204,94 @@ function parseFields(json2) {
|
|
|
166254
166204
|
}
|
|
166255
166205
|
var init_compartment_events = () => {};
|
|
166256
166206
|
|
|
166207
|
+
// src/features/magic-context/recursive-text-splitter.ts
|
|
166208
|
+
function splitOnSeparator(text, separator) {
|
|
166209
|
+
const splits = separator ? text.split(separator) : text.split("");
|
|
166210
|
+
return splits.filter((s) => s !== "");
|
|
166211
|
+
}
|
|
166212
|
+
function mergeSplits(splits, separator, chunkSize, lengthFunction) {
|
|
166213
|
+
const docs = [];
|
|
166214
|
+
const currentDoc = [];
|
|
166215
|
+
let total = 0;
|
|
166216
|
+
const joinDocs = (docsToJoin) => {
|
|
166217
|
+
const joined = docsToJoin.join(separator).trim();
|
|
166218
|
+
return joined === "" ? null : joined;
|
|
166219
|
+
};
|
|
166220
|
+
for (const d of splits) {
|
|
166221
|
+
const len = lengthFunction(d);
|
|
166222
|
+
if (total + len + currentDoc.length * separator.length > chunkSize) {
|
|
166223
|
+
if (currentDoc.length > 0) {
|
|
166224
|
+
const doc3 = joinDocs(currentDoc);
|
|
166225
|
+
if (doc3 !== null)
|
|
166226
|
+
docs.push(doc3);
|
|
166227
|
+
while (total > 0 && currentDoc.length > 0) {
|
|
166228
|
+
total -= lengthFunction(currentDoc[0]);
|
|
166229
|
+
currentDoc.shift();
|
|
166230
|
+
}
|
|
166231
|
+
}
|
|
166232
|
+
}
|
|
166233
|
+
currentDoc.push(d);
|
|
166234
|
+
total += len;
|
|
166235
|
+
}
|
|
166236
|
+
const doc2 = joinDocs(currentDoc);
|
|
166237
|
+
if (doc2 !== null)
|
|
166238
|
+
docs.push(doc2);
|
|
166239
|
+
return docs;
|
|
166240
|
+
}
|
|
166241
|
+
function splitTextRecursive(text, separators, chunkSize, lengthFunction) {
|
|
166242
|
+
const finalChunks = [];
|
|
166243
|
+
let separator = separators[separators.length - 1];
|
|
166244
|
+
let newSeparators;
|
|
166245
|
+
for (let i = 0;i < separators.length; i += 1) {
|
|
166246
|
+
const s = separators[i];
|
|
166247
|
+
if (s === "") {
|
|
166248
|
+
separator = s;
|
|
166249
|
+
break;
|
|
166250
|
+
}
|
|
166251
|
+
if (text.includes(s)) {
|
|
166252
|
+
separator = s;
|
|
166253
|
+
newSeparators = separators.slice(i + 1);
|
|
166254
|
+
break;
|
|
166255
|
+
}
|
|
166256
|
+
}
|
|
166257
|
+
const splits = splitOnSeparator(text, separator);
|
|
166258
|
+
let goodSplits = [];
|
|
166259
|
+
for (const s of splits) {
|
|
166260
|
+
if (lengthFunction(s) < chunkSize) {
|
|
166261
|
+
goodSplits.push(s);
|
|
166262
|
+
} else {
|
|
166263
|
+
if (goodSplits.length) {
|
|
166264
|
+
finalChunks.push(...mergeSplits(goodSplits, separator, chunkSize, lengthFunction));
|
|
166265
|
+
goodSplits = [];
|
|
166266
|
+
}
|
|
166267
|
+
if (!newSeparators) {
|
|
166268
|
+
finalChunks.push(s);
|
|
166269
|
+
} else {
|
|
166270
|
+
finalChunks.push(...splitTextRecursive(s, newSeparators, chunkSize, lengthFunction));
|
|
166271
|
+
}
|
|
166272
|
+
}
|
|
166273
|
+
}
|
|
166274
|
+
if (goodSplits.length) {
|
|
166275
|
+
finalChunks.push(...mergeSplits(goodSplits, separator, chunkSize, lengthFunction));
|
|
166276
|
+
}
|
|
166277
|
+
return finalChunks;
|
|
166278
|
+
}
|
|
166279
|
+
function recursiveCharacterSplit(text, options) {
|
|
166280
|
+
const chunkSize = options.chunkSize;
|
|
166281
|
+
const lengthFunction = options.lengthFunction ?? ((t) => t.length);
|
|
166282
|
+
const separators = options.separators ?? DEFAULT_SEPARATORS;
|
|
166283
|
+
if (text.length === 0)
|
|
166284
|
+
return [];
|
|
166285
|
+
return splitTextRecursive(text, separators, chunkSize, lengthFunction);
|
|
166286
|
+
}
|
|
166287
|
+
var DEFAULT_SEPARATORS;
|
|
166288
|
+
var init_recursive_text_splitter = __esm(() => {
|
|
166289
|
+
DEFAULT_SEPARATORS = [`
|
|
166290
|
+
|
|
166291
|
+
`, `
|
|
166292
|
+
`, " ", ""];
|
|
166293
|
+
});
|
|
166294
|
+
|
|
166257
166295
|
// src/features/magic-context/compartment-chunk-embedding.ts
|
|
166258
166296
|
import { createHash as createHash6 } from "node:crypto";
|
|
166259
166297
|
function getLoadFtsRowsStatement(db) {
|
|
@@ -166521,6 +166559,19 @@ function chunkCanonicalText(canonicalText, startOrdinal, endOrdinal, maxInputTok
|
|
|
166521
166559
|
const lineStart = range?.start ?? startOrdinal;
|
|
166522
166560
|
const lineEnd = range?.end ?? lineStart;
|
|
166523
166561
|
const lineTokens = estimateTokens(line);
|
|
166562
|
+
if (lineTokens > effectiveMax) {
|
|
166563
|
+
flush2();
|
|
166564
|
+
for (const slice of splitOversizedLine(line, effectiveMax)) {
|
|
166565
|
+
windows.push({
|
|
166566
|
+
windowIndex: windows.length + 1,
|
|
166567
|
+
startOrdinal: lineStart,
|
|
166568
|
+
endOrdinal: lineEnd,
|
|
166569
|
+
text: slice,
|
|
166570
|
+
chunkHash: hashChunkText(slice)
|
|
166571
|
+
});
|
|
166572
|
+
}
|
|
166573
|
+
continue;
|
|
166574
|
+
}
|
|
166524
166575
|
if (currentLines.length > 0 && currentTokens + lineTokens > effectiveMax) {
|
|
166525
166576
|
flush2();
|
|
166526
166577
|
}
|
|
@@ -166534,6 +166585,56 @@ function chunkCanonicalText(canonicalText, startOrdinal, endOrdinal, maxInputTok
|
|
|
166534
166585
|
flush2();
|
|
166535
166586
|
return windows;
|
|
166536
166587
|
}
|
|
166588
|
+
function splitOversizedLine(line, effectiveMax) {
|
|
166589
|
+
let slices = [];
|
|
166590
|
+
try {
|
|
166591
|
+
slices = recursiveCharacterSplit(line, {
|
|
166592
|
+
chunkSize: effectiveMax,
|
|
166593
|
+
lengthFunction: estimateTokens
|
|
166594
|
+
});
|
|
166595
|
+
} catch (error51) {
|
|
166596
|
+
log("[magic-context] recursiveCharacterSplit failed; using char-budget fallback:", error51);
|
|
166597
|
+
slices = [];
|
|
166598
|
+
}
|
|
166599
|
+
if (slices.length === 0) {
|
|
166600
|
+
slices = charBudgetSplit(line, effectiveMax);
|
|
166601
|
+
}
|
|
166602
|
+
const safe = [];
|
|
166603
|
+
const pushChecked = (slice) => {
|
|
166604
|
+
if (estimateTokens(slice) > effectiveMax && slice.length > 1) {
|
|
166605
|
+
safe.push(...charBudgetSplit(slice, effectiveMax));
|
|
166606
|
+
return;
|
|
166607
|
+
}
|
|
166608
|
+
safe.push(slice);
|
|
166609
|
+
};
|
|
166610
|
+
for (const slice of slices) {
|
|
166611
|
+
if (estimateTokens(slice) <= effectiveMax) {
|
|
166612
|
+
safe.push(slice);
|
|
166613
|
+
} else {
|
|
166614
|
+
for (const sub of charBudgetSplit(slice, effectiveMax))
|
|
166615
|
+
pushChecked(sub);
|
|
166616
|
+
}
|
|
166617
|
+
}
|
|
166618
|
+
return safe.filter((s) => s.length > 0);
|
|
166619
|
+
}
|
|
166620
|
+
function charBudgetSplit(text, effectiveMax) {
|
|
166621
|
+
const totalTokens = Math.max(1, estimateTokens(text));
|
|
166622
|
+
const charsPerToken = Math.max(1, Math.floor(text.length / totalTokens));
|
|
166623
|
+
const sliceChars = Math.max(1, effectiveMax * charsPerToken);
|
|
166624
|
+
const out = [];
|
|
166625
|
+
let pos = 0;
|
|
166626
|
+
while (pos < text.length) {
|
|
166627
|
+
let end = Math.min(text.length, pos + sliceChars);
|
|
166628
|
+
let slice = text.slice(pos, end);
|
|
166629
|
+
while (slice.length > 1 && estimateTokens(slice) > effectiveMax) {
|
|
166630
|
+
end = pos + Math.max(1, Math.floor((end - pos) / 2));
|
|
166631
|
+
slice = text.slice(pos, end);
|
|
166632
|
+
}
|
|
166633
|
+
out.push(slice);
|
|
166634
|
+
pos = end;
|
|
166635
|
+
}
|
|
166636
|
+
return out;
|
|
166637
|
+
}
|
|
166537
166638
|
function getExistingChunkHashes(db, compartmentId, modelId, projectPath) {
|
|
166538
166639
|
const scoped = typeof projectPath === "string" && projectPath.length > 0;
|
|
166539
166640
|
const rows = scoped ? getExistingHashStatement(db, true).all(compartmentId, modelId, projectPath) : getExistingHashStatement(db, false).all(compartmentId, modelId);
|
|
@@ -166701,6 +166802,8 @@ function countSessionCompartmentEmbedCoverage(db, projectPath, sessionId, modelI
|
|
|
166701
166802
|
var DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS = 512, CHUNK_WINDOW_SAFETY_RATIO = 0.9, loadFtsRowsStatements, existingHashStatements, existingHashByProjectStatements, deleteByCompartmentStatements, insertEmbeddingStatements, distinctModelStatements, clearProjectStatements, clearProjectModelStatements, searchRowsStatements, searchRowsByModelStatements, backfillCandidateStatements, sessionBackfillCandidateStatements;
|
|
166702
166803
|
var init_compartment_chunk_embedding = __esm(() => {
|
|
166703
166804
|
init_read_session_formatting();
|
|
166805
|
+
init_logger();
|
|
166806
|
+
init_recursive_text_splitter();
|
|
166704
166807
|
loadFtsRowsStatements = new WeakMap;
|
|
166705
166808
|
existingHashStatements = new WeakMap;
|
|
166706
166809
|
existingHashByProjectStatements = new WeakMap;
|
|
@@ -167285,6 +167388,7 @@ class OpenAICompatibleEmbeddingProvider {
|
|
|
167285
167388
|
if (texts.length === 0) {
|
|
167286
167389
|
return [];
|
|
167287
167390
|
}
|
|
167391
|
+
const requestTexts = texts.map((t) => t.trim().length === 0 ? " " : t);
|
|
167288
167392
|
if (!await this.initialize()) {
|
|
167289
167393
|
return Array.from({ length: texts.length }, () => null);
|
|
167290
167394
|
}
|
|
@@ -167316,7 +167420,7 @@ class OpenAICompatibleEmbeddingProvider {
|
|
|
167316
167420
|
},
|
|
167317
167421
|
body: JSON.stringify({
|
|
167318
167422
|
model: this.model,
|
|
167319
|
-
input:
|
|
167423
|
+
input: requestTexts,
|
|
167320
167424
|
...inputTypeForRequest ? { input_type: inputTypeForRequest } : {},
|
|
167321
167425
|
...this.truncate ? { truncate: this.truncate } : {}
|
|
167322
167426
|
}),
|
|
@@ -168404,6 +168508,32 @@ async function embedBatchForProject(projectIdentity, texts, signal, purpose = "p
|
|
|
168404
168508
|
}
|
|
168405
168509
|
return { vectors, modelId, generation };
|
|
168406
168510
|
}
|
|
168511
|
+
async function embedTextsWindowBounded(projectIdentity, texts, signal) {
|
|
168512
|
+
if (texts.length <= MAX_WINDOWS_PER_EMBED_CALL) {
|
|
168513
|
+
return embedBatchForProject(projectIdentity, texts, signal);
|
|
168514
|
+
}
|
|
168515
|
+
const vectors = [];
|
|
168516
|
+
let modelId = null;
|
|
168517
|
+
let generation = null;
|
|
168518
|
+
for (let start = 0;start < texts.length; start += MAX_WINDOWS_PER_EMBED_CALL) {
|
|
168519
|
+
if (signal?.aborted)
|
|
168520
|
+
return null;
|
|
168521
|
+
const sub = texts.slice(start, start + MAX_WINDOWS_PER_EMBED_CALL);
|
|
168522
|
+
const result = await embedBatchForProject(projectIdentity, sub, signal);
|
|
168523
|
+
if (!result)
|
|
168524
|
+
return null;
|
|
168525
|
+
if (modelId === null) {
|
|
168526
|
+
modelId = result.modelId;
|
|
168527
|
+
generation = result.generation;
|
|
168528
|
+
} else if (result.modelId !== modelId || result.generation !== generation) {
|
|
168529
|
+
return null;
|
|
168530
|
+
}
|
|
168531
|
+
vectors.push(...result.vectors);
|
|
168532
|
+
}
|
|
168533
|
+
if (modelId === null || generation === null)
|
|
168534
|
+
return null;
|
|
168535
|
+
return { vectors, modelId, generation };
|
|
168536
|
+
}
|
|
168407
168537
|
function isUnembeddedMemoryRow(row) {
|
|
168408
168538
|
if (row === null || typeof row !== "object")
|
|
168409
168539
|
return false;
|
|
@@ -168537,7 +168667,7 @@ async function embedCandidateChunkBatch(db, projectIdentity, modelId, candidates
|
|
|
168537
168667
|
let result = null;
|
|
168538
168668
|
const attemptStart = Date.now();
|
|
168539
168669
|
try {
|
|
168540
|
-
result = await
|
|
168670
|
+
result = await embedTextsWindowBounded(projectIdentity, texts, signal);
|
|
168541
168671
|
} catch (error51) {
|
|
168542
168672
|
log("[magic-context] failed to proactively embed compartment chunks:", error51);
|
|
168543
168673
|
}
|
|
@@ -184740,133 +184870,16 @@ function shouldShowAnnouncement() {
|
|
|
184740
184870
|
}
|
|
184741
184871
|
return ordering > 0;
|
|
184742
184872
|
}
|
|
184743
|
-
var ANNOUNCEMENT_VERSION = "0.30.
|
|
184873
|
+
var ANNOUNCEMENT_VERSION = "0.30.4", ANNOUNCEMENT_FEATURES, ANNOUNCEMENT_FOOTER = "Join us on Discord: https://discord.gg/F2uWxjGnU", STATE_FILENAME = "last_announced_version";
|
|
184744
184874
|
var init_announcement = __esm(() => {
|
|
184745
184875
|
init_data_path();
|
|
184746
184876
|
ANNOUNCEMENT_FEATURES = [
|
|
184747
|
-
"
|
|
184877
|
+
"Pi: fixed historian and dreamer failing when your model comes from a provider extension (Antigravity, Anthropic OAuth, etc.). Subagents now load your extensions.",
|
|
184878
|
+
"Pi: fixed the retrospective and refresh-primers dreamer tasks reading sessions through the wrong API.",
|
|
184879
|
+
"OpenCode: the plugin no longer re-adds its TUI sidebar entry on startup, so removing it from tui.jsonc now sticks."
|
|
184748
184880
|
];
|
|
184749
184881
|
});
|
|
184750
184882
|
|
|
184751
|
-
// src/shared/tui-config.ts
|
|
184752
|
-
var exports_tui_config = {};
|
|
184753
|
-
__export(exports_tui_config, {
|
|
184754
|
-
ensureTuiPluginEntry: () => ensureTuiPluginEntry
|
|
184755
|
-
});
|
|
184756
|
-
import {
|
|
184757
|
-
chmodSync as chmodSync4,
|
|
184758
|
-
existsSync as existsSync19,
|
|
184759
|
-
mkdirSync as mkdirSync12,
|
|
184760
|
-
readFileSync as readFileSync15,
|
|
184761
|
-
renameSync as renameSync6,
|
|
184762
|
-
statSync as statSync8,
|
|
184763
|
-
writeFileSync as writeFileSync12
|
|
184764
|
-
} from "node:fs";
|
|
184765
|
-
import { dirname as dirname10, join as join21 } from "node:path";
|
|
184766
|
-
function pluginEntryId(entry) {
|
|
184767
|
-
if (typeof entry === "string")
|
|
184768
|
-
return entry;
|
|
184769
|
-
if (Array.isArray(entry) && typeof entry[0] === "string")
|
|
184770
|
-
return entry[0];
|
|
184771
|
-
return "";
|
|
184772
|
-
}
|
|
184773
|
-
function isLocalMagicContextDevEntry(entry) {
|
|
184774
|
-
const id = pluginEntryId(entry);
|
|
184775
|
-
if (!id)
|
|
184776
|
-
return false;
|
|
184777
|
-
if (id === PLUGIN_NAME || id.startsWith(`${PLUGIN_NAME}@`))
|
|
184778
|
-
return false;
|
|
184779
|
-
const isPath = id.startsWith("file://") || id.startsWith("/") || id.startsWith("./") || id.includes("\\");
|
|
184780
|
-
if (!isPath)
|
|
184781
|
-
return false;
|
|
184782
|
-
return id.includes("opencode-magic-context") || id.includes("magic-context");
|
|
184783
|
-
}
|
|
184784
|
-
function isMagicContextPluginEntry(entry) {
|
|
184785
|
-
const id = pluginEntryId(entry);
|
|
184786
|
-
if (!id)
|
|
184787
|
-
return false;
|
|
184788
|
-
if (id === PLUGIN_NAME || id.startsWith(`${PLUGIN_NAME}@`))
|
|
184789
|
-
return true;
|
|
184790
|
-
return isLocalMagicContextDevEntry(entry);
|
|
184791
|
-
}
|
|
184792
|
-
function writeTuiConfigAtomic(configPath, config2) {
|
|
184793
|
-
const body = `${import_comment_json3.stringify(config2, null, 2)}
|
|
184794
|
-
`;
|
|
184795
|
-
const tmpPath = `${configPath}.tmp`;
|
|
184796
|
-
writeFileSync12(tmpPath, body);
|
|
184797
|
-
try {
|
|
184798
|
-
if (statSync8(configPath, { throwIfNoEntry: false })?.isFile()) {
|
|
184799
|
-
chmodSync4(tmpPath, statSync8(configPath).mode & 511);
|
|
184800
|
-
}
|
|
184801
|
-
} catch {}
|
|
184802
|
-
renameSync6(tmpPath, configPath);
|
|
184803
|
-
}
|
|
184804
|
-
function resolveTuiConfigPath() {
|
|
184805
|
-
const configDir = getOpenCodeConfigPaths({ binary: "opencode" }).configDir;
|
|
184806
|
-
const jsoncPath = join21(configDir, "tui.jsonc");
|
|
184807
|
-
const jsonPath = join21(configDir, "tui.json");
|
|
184808
|
-
if (existsSync19(jsoncPath))
|
|
184809
|
-
return jsoncPath;
|
|
184810
|
-
if (existsSync19(jsonPath))
|
|
184811
|
-
return jsonPath;
|
|
184812
|
-
return jsoncPath;
|
|
184813
|
-
}
|
|
184814
|
-
function ensureTuiPluginEntry() {
|
|
184815
|
-
try {
|
|
184816
|
-
const configPath = resolveTuiConfigPath();
|
|
184817
|
-
let config2 = {};
|
|
184818
|
-
if (existsSync19(configPath)) {
|
|
184819
|
-
const raw = readFileSync15(configPath, "utf-8");
|
|
184820
|
-
config2 = import_comment_json3.parse(raw) ?? {};
|
|
184821
|
-
}
|
|
184822
|
-
const plugins = Array.isArray(config2.plugin) ? [...config2.plugin] : [];
|
|
184823
|
-
const existingIdx = plugins.findIndex(isMagicContextPluginEntry);
|
|
184824
|
-
if (existingIdx >= 0) {
|
|
184825
|
-
const existing = plugins[existingIdx];
|
|
184826
|
-
if (isLocalMagicContextDevEntry(existing)) {
|
|
184827
|
-
return false;
|
|
184828
|
-
}
|
|
184829
|
-
const id = pluginEntryId(existing);
|
|
184830
|
-
if (id === PLUGIN_ENTRY) {
|
|
184831
|
-
return false;
|
|
184832
|
-
}
|
|
184833
|
-
if (id === PLUGIN_NAME) {
|
|
184834
|
-
if (Array.isArray(existing) && existing.length >= 1) {
|
|
184835
|
-
const replacement = [...existing];
|
|
184836
|
-
replacement[0] = PLUGIN_ENTRY;
|
|
184837
|
-
plugins[existingIdx] = replacement;
|
|
184838
|
-
} else {
|
|
184839
|
-
plugins[existingIdx] = PLUGIN_ENTRY;
|
|
184840
|
-
}
|
|
184841
|
-
} else {
|
|
184842
|
-
return false;
|
|
184843
|
-
}
|
|
184844
|
-
} else {
|
|
184845
|
-
const hasDev = plugins.some(isLocalMagicContextDevEntry);
|
|
184846
|
-
if (!hasDev) {
|
|
184847
|
-
plugins.push(PLUGIN_ENTRY);
|
|
184848
|
-
} else {
|
|
184849
|
-
return false;
|
|
184850
|
-
}
|
|
184851
|
-
}
|
|
184852
|
-
config2.plugin = plugins;
|
|
184853
|
-
mkdirSync12(dirname10(configPath), { recursive: true });
|
|
184854
|
-
writeTuiConfigAtomic(configPath, config2);
|
|
184855
|
-
log(`[magic-context] updated TUI plugin entry in ${configPath}`);
|
|
184856
|
-
return true;
|
|
184857
|
-
} catch (error51) {
|
|
184858
|
-
log(`[magic-context] failed to update tui.json: ${error51 instanceof Error ? error51.message : String(error51)}`);
|
|
184859
|
-
return false;
|
|
184860
|
-
}
|
|
184861
|
-
}
|
|
184862
|
-
var import_comment_json3, PLUGIN_NAME = "@cortexkit/opencode-magic-context", PLUGIN_ENTRY;
|
|
184863
|
-
var init_tui_config = __esm(() => {
|
|
184864
|
-
init_logger();
|
|
184865
|
-
init_opencode_config_dir();
|
|
184866
|
-
import_comment_json3 = __toESM(require_src2(), 1);
|
|
184867
|
-
PLUGIN_ENTRY = `${PLUGIN_NAME}@latest`;
|
|
184868
|
-
});
|
|
184869
|
-
|
|
184870
184883
|
// src/agents/permissions.ts
|
|
184871
184884
|
init_logger();
|
|
184872
184885
|
function buildAllowOnlyPermission(allowedTools, agentLabel) {
|
|
@@ -204951,18 +204964,6 @@ var server = async (ctx) => {
|
|
|
204951
204964
|
const serverUrlStr = serverUrl instanceof URL ? serverUrl.toString().replace(/\/$/, "") : undefined;
|
|
204952
204965
|
cleanupConflictWarnings(ctx.client, ctx.directory, serverUrlStr);
|
|
204953
204966
|
}
|
|
204954
|
-
if (pluginConfig.enabled) {
|
|
204955
|
-
try {
|
|
204956
|
-
const { ensureTuiPluginEntry: ensureTuiPluginEntry2 } = await Promise.resolve().then(() => (init_tui_config(), exports_tui_config));
|
|
204957
|
-
const tuiAdded = ensureTuiPluginEntry2();
|
|
204958
|
-
if (tuiAdded) {
|
|
204959
|
-
const { sendTuiSetupNotification: sendTuiSetupNotification2 } = await Promise.resolve().then(() => (init_conflict_warning_hook(), exports_conflict_warning_hook));
|
|
204960
|
-
const serverUrl = ctx.serverUrl;
|
|
204961
|
-
const serverUrlStr = serverUrl instanceof URL ? serverUrl.toString().replace(/\/$/, "") : undefined;
|
|
204962
|
-
sendTuiSetupNotification2(ctx.client, ctx.directory, serverUrlStr);
|
|
204963
|
-
}
|
|
204964
|
-
} catch {}
|
|
204965
|
-
}
|
|
204966
204967
|
if (pluginConfig.enabled && !conflictResult?.hasConflict) {
|
|
204967
204968
|
try {
|
|
204968
204969
|
const {
|
|
@@ -16,11 +16,6 @@ export declare function sendConflictWarning(client: unknown, directory: string,
|
|
|
16
16
|
* Called at startup when no conflicts exist (plugin is enabled normally).
|
|
17
17
|
*/
|
|
18
18
|
export declare function cleanupConflictWarnings(client: unknown, directory: string, serverUrl?: string): Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* Notify the user that tui.json was configured with the sidebar plugin.
|
|
21
|
-
* Sends an ignored message that auto-deletes after 1 second.
|
|
22
|
-
*/
|
|
23
|
-
export declare function sendTuiSetupNotification(client: unknown, directory: string, serverUrl?: string): Promise<void>;
|
|
24
19
|
/**
|
|
25
20
|
* Desktop schema-fence warning. When OpenCode and Pi share context.db and one
|
|
26
21
|
* harness auto-updates first, it migrates the DB to a newer schema; the lagging
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conflict-warning-hook.d.ts","sourceRoot":"","sources":["../../src/plugin/conflict-warning-hook.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"conflict-warning-hook.d.ts","sourceRoot":"","sources":["../../src/plugin/conflict-warning-hook.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAqLlE;;GAEG;AACH,wBAAsB,mBAAmB,CACrC,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,cAAc,GAC/B,OAAO,CAAC,IAAI,CAAC,CAqDf;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CACzC,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC,CAwHf;AAkCD;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,CACxC,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE;IAAE,gBAAgB,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAA;CAAE,GAC/D,OAAO,CAAC,IAAI,CAAC,CA2Cf;AAED;;;;;;;;GAQG;AACH,wBAAsB,uBAAuB,CACzC,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,EAC/B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GACpC,OAAO,CAAC,IAAI,CAAC,CAkFf"}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* Bump only when there are user-visible changes worth a startup dialog.
|
|
19
19
|
* Does NOT need to match the published package version.
|
|
20
20
|
*/
|
|
21
|
-
export declare const ANNOUNCEMENT_VERSION = "0.30.
|
|
21
|
+
export declare const ANNOUNCEMENT_VERSION = "0.30.4";
|
|
22
22
|
/**
|
|
23
23
|
* Short, user-facing bullet strings. Keep each line ~80 chars or shorter so the
|
|
24
24
|
* TUI dialog renders cleanly without horizontal scroll on a typical terminal.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"announcement.d.ts","sourceRoot":"","sources":["../../src/shared/announcement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAOH;;;GAGG;AACH,eAAO,MAAM,oBAAoB,WAAW,CAAC;AAE7C;;;GAGG;AACH,eAAO,MAAM,qBAAqB,EAAE,aAAa,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"announcement.d.ts","sourceRoot":"","sources":["../../src/shared/announcement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAOH;;;GAGG;AACH,eAAO,MAAM,oBAAoB,WAAW,CAAC;AAE7C;;;GAGG;AACH,eAAO,MAAM,qBAAqB,EAAE,aAAa,CAAC,MAAM,CAIvD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,qDAAqD,CAAC;AAyBtF;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CAGjD;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAS1D;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,sBAAsB,IAAI,OAAO,CA0BhD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-path.d.ts","sourceRoot":"","sources":["../../src/shared/data-path.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAEvD,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,SAAwB,GAAG,MAAM,CAEhF;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,SAAwB,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"data-path.d.ts","sourceRoot":"","sources":["../../src/shared/data-path.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAEvD,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,SAAwB,GAAG,MAAM,CAEhF;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,SAAwB,GAAG,MAAM,CAOhF;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,GAAE,SAAwB,GAAG,MAAM,CAErF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEnE;AAKD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gCAAgC,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAkBxE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kCAAkC,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE5E;AAED,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,IAAI,MAAM,CAElD;AAED;;;;;;GAMG;AACH,wBAAgB,uCAAuC,IAAI,MAAM,CAEhE;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Configure tui.json with the magic-context TUI plugin entry.
|
|
3
|
+
*
|
|
4
|
+
* Called ONLY from the CLI setup wizard and `doctor` (via the core export) —
|
|
5
|
+
* never at plugin startup. Startup injection would re-add the entry on every
|
|
6
|
+
* launch, so a user who deliberately removed the sidebar could never keep it
|
|
7
|
+
* removed; opting in/out of the sidebar is the user's call, made explicitly
|
|
8
|
+
* through setup or doctor.
|
|
4
9
|
*/
|
|
5
10
|
/**
|
|
6
11
|
* Ensure tui.json has the magic-context TUI plugin entry.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tui-config.d.ts","sourceRoot":"","sources":["../../src/shared/tui-config.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"tui-config.d.ts","sourceRoot":"","sources":["../../src/shared/tui-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAyEH;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAqD9C"}
|
package/package.json
CHANGED
|
@@ -24,14 +24,16 @@ import { getMagicContextStorageDir } from "./data-path";
|
|
|
24
24
|
* Bump only when there are user-visible changes worth a startup dialog.
|
|
25
25
|
* Does NOT need to match the published package version.
|
|
26
26
|
*/
|
|
27
|
-
export const ANNOUNCEMENT_VERSION = "0.30.
|
|
27
|
+
export const ANNOUNCEMENT_VERSION = "0.30.4";
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Short, user-facing bullet strings. Keep each line ~80 chars or shorter so the
|
|
31
31
|
* TUI dialog renders cleanly without horizontal scroll on a typical terminal.
|
|
32
32
|
*/
|
|
33
33
|
export const ANNOUNCEMENT_FEATURES: ReadonlyArray<string> = [
|
|
34
|
-
"
|
|
34
|
+
"Pi: fixed historian and dreamer failing when your model comes from a provider extension (Antigravity, Anthropic OAuth, etc.). Subagents now load your extensions.",
|
|
35
|
+
"Pi: fixed the retrospective and refresh-primers dreamer tasks reading sessions through the wrong API.",
|
|
36
|
+
"OpenCode: the plugin no longer re-adds its TUI sidebar entry on startup, so removing it from tui.jsonc now sticks.",
|
|
35
37
|
];
|
|
36
38
|
|
|
37
39
|
/**
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
getCacheDir,
|
|
8
8
|
getDataDir,
|
|
9
9
|
getLegacyOpenCodeMagicContextStorageDir,
|
|
10
|
+
getMagicContextLogPath,
|
|
10
11
|
getMagicContextStorageDir,
|
|
11
12
|
getOpenCodeCacheDir,
|
|
12
13
|
getOpenCodeStorageDir,
|
|
@@ -18,6 +19,7 @@ const savedEnv = {
|
|
|
18
19
|
XDG_CACHE_HOME: process.env.XDG_CACHE_HOME,
|
|
19
20
|
XDG_DATA_HOME: process.env.XDG_DATA_HOME,
|
|
20
21
|
LOCALAPPDATA: process.env.LOCALAPPDATA,
|
|
22
|
+
MAGIC_CONTEXT_LOG_PATH: process.env.MAGIC_CONTEXT_LOG_PATH,
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
describe("data-path", () => {
|
|
@@ -25,10 +27,12 @@ describe("data-path", () => {
|
|
|
25
27
|
process.env.XDG_CACHE_HOME = undefined;
|
|
26
28
|
process.env.XDG_DATA_HOME = undefined;
|
|
27
29
|
process.env.LOCALAPPDATA = undefined;
|
|
30
|
+
process.env.MAGIC_CONTEXT_LOG_PATH = undefined;
|
|
28
31
|
// Bun's env handling: explicit delete for unset
|
|
29
32
|
delete process.env.XDG_CACHE_HOME;
|
|
30
33
|
delete process.env.XDG_DATA_HOME;
|
|
31
34
|
delete process.env.LOCALAPPDATA;
|
|
35
|
+
delete process.env.MAGIC_CONTEXT_LOG_PATH;
|
|
32
36
|
});
|
|
33
37
|
|
|
34
38
|
afterEach(() => {
|
|
@@ -37,6 +41,9 @@ describe("data-path", () => {
|
|
|
37
41
|
if (savedEnv.XDG_DATA_HOME !== undefined)
|
|
38
42
|
process.env.XDG_DATA_HOME = savedEnv.XDG_DATA_HOME;
|
|
39
43
|
if (savedEnv.LOCALAPPDATA !== undefined) process.env.LOCALAPPDATA = savedEnv.LOCALAPPDATA;
|
|
44
|
+
if (savedEnv.MAGIC_CONTEXT_LOG_PATH !== undefined)
|
|
45
|
+
process.env.MAGIC_CONTEXT_LOG_PATH = savedEnv.MAGIC_CONTEXT_LOG_PATH;
|
|
46
|
+
else delete process.env.MAGIC_CONTEXT_LOG_PATH;
|
|
40
47
|
});
|
|
41
48
|
|
|
42
49
|
test("getCacheDir falls back to <homedir>/.cache when XDG_CACHE_HOME is unset (all platforms)", () => {
|
|
@@ -158,6 +165,27 @@ describe("data-path", () => {
|
|
|
158
165
|
path.join("/some/project/", ".cortexkit", "magic-context"),
|
|
159
166
|
);
|
|
160
167
|
});
|
|
168
|
+
|
|
169
|
+
test("getMagicContextLogPath falls back to the harness temp dir when the env override is unset", () => {
|
|
170
|
+
expect(getMagicContextLogPath("opencode")).toBe(
|
|
171
|
+
path.join(os.tmpdir(), "opencode", "magic-context", "magic-context.log"),
|
|
172
|
+
);
|
|
173
|
+
expect(getMagicContextLogPath("pi")).toBe(
|
|
174
|
+
path.join(os.tmpdir(), "pi", "magic-context", "magic-context.log"),
|
|
175
|
+
);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test("getMagicContextLogPath honors MAGIC_CONTEXT_LOG_PATH", () => {
|
|
179
|
+
process.env.MAGIC_CONTEXT_LOG_PATH = "/tmp/custom/magic-context.log";
|
|
180
|
+
expect(getMagicContextLogPath("pi")).toBe("/tmp/custom/magic-context.log");
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test("getMagicContextLogPath ignores a blank MAGIC_CONTEXT_LOG_PATH", () => {
|
|
184
|
+
process.env.MAGIC_CONTEXT_LOG_PATH = " ";
|
|
185
|
+
expect(getMagicContextLogPath("pi")).toBe(
|
|
186
|
+
path.join(os.tmpdir(), "pi", "magic-context", "magic-context.log"),
|
|
187
|
+
);
|
|
188
|
+
});
|
|
161
189
|
});
|
|
162
190
|
|
|
163
191
|
describe("ensureCortexKitArtifactGitignore", () => {
|
package/src/shared/data-path.ts
CHANGED
|
@@ -46,6 +46,11 @@ export function getMagicContextTempDir(harness: HarnessId = getHarness()): strin
|
|
|
46
46
|
* reflected in the next flush.
|
|
47
47
|
*/
|
|
48
48
|
export function getMagicContextLogPath(harness: HarnessId = getHarness()): string {
|
|
49
|
+
// An explicit override wins over the harness temp-dir default, so users on
|
|
50
|
+
// sandboxed/ephemeral setups (Docker, CI) can point the diagnostic log at a
|
|
51
|
+
// persistent or shared path. Blank/whitespace is treated as unset.
|
|
52
|
+
const envPath = process.env.MAGIC_CONTEXT_LOG_PATH?.trim();
|
|
53
|
+
if (envPath) return envPath;
|
|
49
54
|
return path.join(getMagicContextTempDir(harness), "magic-context.log");
|
|
50
55
|
}
|
|
51
56
|
|
package/src/shared/tui-config.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Configure tui.json with the magic-context TUI plugin entry.
|
|
3
|
+
*
|
|
4
|
+
* Called ONLY from the CLI setup wizard and `doctor` (via the core export) —
|
|
5
|
+
* never at plugin startup. Startup injection would re-add the entry on every
|
|
6
|
+
* launch, so a user who deliberately removed the sidebar could never keep it
|
|
7
|
+
* removed; opting in/out of the sidebar is the user's call, made explicitly
|
|
8
|
+
* through setup or doctor.
|
|
4
9
|
*/
|
|
5
10
|
|
|
6
11
|
import {
|
package/src/tui/index.tsx
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/** @jsxImportSource @opentui/solid */
|
|
2
2
|
// @ts-nocheck
|
|
3
|
-
import { existsSync, mkdirSync, writeFileSync } from "node:fs"
|
|
4
|
-
import { dirname, join } from "node:path"
|
|
5
3
|
import { createMemo } from "solid-js"
|
|
6
4
|
import type { TuiPlugin, TuiPluginApi, TuiThemeCurrent } from "@opencode-ai/plugin/tui"
|
|
7
5
|
import { createSidebarContentSlot, kickRecompProgressRefresh } from "./slots/sidebar-content"
|
|
@@ -11,10 +9,7 @@ import { startNotificationSocket, stopNotificationSocket, type SocketNotificatio
|
|
|
11
9
|
import { formatThresholdPercent } from "../shared/format-threshold"
|
|
12
10
|
import { detectConflicts } from "../shared/conflict-detector"
|
|
13
11
|
import { fixConflicts } from "../shared/conflict-fixer"
|
|
14
|
-
import { readJsoncFile } from "../shared/jsonc-parser"
|
|
15
|
-
import { getOpenCodeConfigPaths } from "../shared/opencode-config-dir"
|
|
16
12
|
|
|
17
|
-
const PLUGIN_NAME = "@cortexkit/opencode-magic-context"
|
|
18
13
|
const DEFAULT_TOAST_DURATION_MS = 5000
|
|
19
14
|
let unifiedToastDurationMs = DEFAULT_TOAST_DURATION_MS
|
|
20
15
|
|
|
@@ -58,71 +53,6 @@ function showToast(
|
|
|
58
53
|
})
|
|
59
54
|
}
|
|
60
55
|
|
|
61
|
-
function ensureParentDir(filePath: string) {
|
|
62
|
-
mkdirSync(dirname(filePath), { recursive: true })
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function resolveTuiConfigPath() {
|
|
66
|
-
const configDir = getOpenCodeConfigPaths({ binary: "opencode" }).configDir
|
|
67
|
-
const jsoncPath = join(configDir, "tui.jsonc")
|
|
68
|
-
const jsonPath = join(configDir, "tui.json")
|
|
69
|
-
|
|
70
|
-
if (existsSync(jsoncPath)) {
|
|
71
|
-
return jsoncPath
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (existsSync(jsonPath)) {
|
|
75
|
-
return jsonPath
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return jsonPath
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function readTuiConfig(filePath: string): Record<string, unknown> | null {
|
|
82
|
-
if (!existsSync(filePath)) {
|
|
83
|
-
return {}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return readJsoncFile<Record<string, unknown>>(filePath)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function hasMagicContextTuiPlugin(): boolean {
|
|
90
|
-
const configPath = resolveTuiConfigPath()
|
|
91
|
-
const config = readTuiConfig(configPath)
|
|
92
|
-
if (!config) {
|
|
93
|
-
return false
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const plugins = Array.isArray(config.plugin)
|
|
97
|
-
? config.plugin.filter((plugin): plugin is string => typeof plugin === "string")
|
|
98
|
-
: []
|
|
99
|
-
|
|
100
|
-
return plugins.some((plugin) => plugin === PLUGIN_NAME || plugin.startsWith(`${PLUGIN_NAME}@`))
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function addMagicContextTuiPlugin(): { ok: boolean; updated: boolean } {
|
|
104
|
-
const configPath = resolveTuiConfigPath()
|
|
105
|
-
const config = readTuiConfig(configPath)
|
|
106
|
-
if (!config) {
|
|
107
|
-
return { ok: false, updated: false }
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const plugins = Array.isArray(config.plugin)
|
|
111
|
-
? config.plugin.filter((plugin): plugin is string => typeof plugin === "string")
|
|
112
|
-
: []
|
|
113
|
-
|
|
114
|
-
if (plugins.some((plugin) => plugin === PLUGIN_NAME || plugin.startsWith(`${PLUGIN_NAME}@`))) {
|
|
115
|
-
return { ok: true, updated: false }
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
plugins.push(PLUGIN_NAME)
|
|
119
|
-
config.plugin = plugins
|
|
120
|
-
|
|
121
|
-
ensureParentDir(configPath)
|
|
122
|
-
writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`)
|
|
123
|
-
return { ok: true, updated: true }
|
|
124
|
-
}
|
|
125
|
-
|
|
126
56
|
function showConflictDialog(api: TuiPluginApi, directory: string, reasons: string[], conflicts: ReturnType<typeof detectConflicts>["conflicts"]) {
|
|
127
57
|
api.ui.dialog.replace(() => (
|
|
128
58
|
<api.ui.DialogConfirm
|
|
@@ -157,59 +87,6 @@ function showConflictDialog(api: TuiPluginApi, directory: string, reasons: strin
|
|
|
157
87
|
))
|
|
158
88
|
}
|
|
159
89
|
|
|
160
|
-
function showTuiSetupDialog(api: TuiPluginApi) {
|
|
161
|
-
api.ui.dialog.replace(() => (
|
|
162
|
-
<api.ui.DialogConfirm
|
|
163
|
-
title="✨ Enable Magic Context Sidebar"
|
|
164
|
-
message={[
|
|
165
|
-
"Magic Context can show a sidebar with live context breakdown,",
|
|
166
|
-
"token usage, historian status, memory counts, and dreamer info.",
|
|
167
|
-
"",
|
|
168
|
-
"This requires adding the plugin to your tui.json config",
|
|
169
|
-
"(OpenCode's TUI plugin configuration file).",
|
|
170
|
-
"",
|
|
171
|
-
"Add it now?",
|
|
172
|
-
].join("\n")}
|
|
173
|
-
onConfirm={() => {
|
|
174
|
-
const result = addMagicContextTuiPlugin()
|
|
175
|
-
if (!result.ok) {
|
|
176
|
-
setTimeout(() => {
|
|
177
|
-
api.ui.dialog.replace(() => (
|
|
178
|
-
<api.ui.DialogAlert
|
|
179
|
-
title="❌ Setup Failed"
|
|
180
|
-
message={'Could not update tui.json automatically. Add the plugin manually:\n\n { "plugin": ["@cortexkit/opencode-magic-context"] }'}
|
|
181
|
-
onConfirm={() => {
|
|
182
|
-
showToast(api, { message: "Add plugin to tui.json manually", variant: "warning" })
|
|
183
|
-
}}
|
|
184
|
-
/>
|
|
185
|
-
))
|
|
186
|
-
}, 50)
|
|
187
|
-
return
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
setTimeout(() => {
|
|
191
|
-
api.ui.dialog.replace(() => (
|
|
192
|
-
<api.ui.DialogAlert
|
|
193
|
-
title="✅ Sidebar Enabled"
|
|
194
|
-
message="tui.json updated with Magic Context plugin.\n\nPlease restart OpenCode to see the sidebar."
|
|
195
|
-
onConfirm={() => {
|
|
196
|
-
showToast(api, {
|
|
197
|
-
message: "Restart OpenCode to see the sidebar",
|
|
198
|
-
variant: "warning",
|
|
199
|
-
durationOverrideMs: 10_000,
|
|
200
|
-
})
|
|
201
|
-
}}
|
|
202
|
-
/>
|
|
203
|
-
))
|
|
204
|
-
}, 50)
|
|
205
|
-
}}
|
|
206
|
-
onCancel={() => {
|
|
207
|
-
showToast(api, { message: "You can add the sidebar later via: npx @cortexkit/opencode-magic-context@latest doctor", variant: "info" })
|
|
208
|
-
}}
|
|
209
|
-
/>
|
|
210
|
-
))
|
|
211
|
-
}
|
|
212
|
-
|
|
213
90
|
function fmt(n: number): string {
|
|
214
91
|
if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`
|
|
215
92
|
if (n >= 1_000) return `${Math.round(n / 1_000)}K`
|
|
@@ -955,10 +832,6 @@ const tui: TuiPlugin = async (api, _options, meta) => {
|
|
|
955
832
|
// launch will retry. Dialog only appears once per ANNOUNCEMENT_VERSION
|
|
956
833
|
// (persisted via mark-announced RPC writing last_announced_version).
|
|
957
834
|
void showStartupAnnouncement(api)
|
|
958
|
-
|
|
959
|
-
// Note: if TUI plugin is loaded, tui.json already has our entry.
|
|
960
|
-
// But if the user added it manually and later removes it, or if they
|
|
961
|
-
// use setup/doctor which handles tui.json, this code is already running.
|
|
962
835
|
}
|
|
963
836
|
|
|
964
837
|
const id = "opencode-magic-context"
|