@cortexkit/opencode-magic-context 0.14.0 → 0.14.2
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 +11 -5
- package/dist/cli/diagnostics.d.ts +38 -5
- package/dist/cli/diagnostics.d.ts.map +1 -1
- package/dist/cli/logs.d.ts.map +1 -1
- package/dist/cli.js +158 -7
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/hooks/magic-context/compaction-marker-manager.d.ts +29 -0
- package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-partial-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-types.d.ts +9 -0
- package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
- package/dist/hooks/magic-context/drop-stale-reduce-calls.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook-handlers.d.ts +0 -2
- package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/nudger.d.ts +1 -4
- package/dist/hooks/magic-context/nudger.d.ts.map +1 -1
- package/dist/hooks/magic-context/sentinel.d.ts +53 -0
- package/dist/hooks/magic-context/sentinel.d.ts.map +1 -0
- package/dist/hooks/magic-context/strip-content.d.ts +63 -13
- package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
- package/dist/hooks/magic-context/strip-structural-noise.d.ts +14 -0
- package/dist/hooks/magic-context/strip-structural-noise.d.ts.map +1 -1
- package/dist/hooks/magic-context/system-prompt-hash.d.ts +18 -5
- package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +2 -0
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/index.js +321 -180
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/shared/error-message.d.ts +30 -0
- package/dist/shared/error-message.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/shared/error-message.test.ts +94 -0
- package/src/shared/error-message.ts +112 -0
package/README.md
CHANGED
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
|
|
31
31
|
## What is Magic Context?
|
|
32
32
|
|
|
33
|
-
Your agent should never stop working to manage its own context. Magic Context is an OpenCode plugin that handles context and memory management entirely in the background:
|
|
33
|
+
Your agent **should never stop working** to manage its own context. Magic Context is an OpenCode plugin that handles context and memory management entirely in the background:
|
|
34
34
|
|
|
35
|
-
**1.** Transparent context compaction via a background historian — the main agent keeps working while a separate model compresses older conversation. All operations are **cache-aware** and deferred to avoid wasting cached prefixes.
|
|
35
|
+
**1.** Transparent context compaction via a **background historian** — the main agent keeps working while a separate model compresses older conversation. All operations are **cache-aware** and deferred to avoid wasting cached prefixes.
|
|
36
36
|
|
|
37
|
-
**2.** Cross-session project memory — architecture decisions, constraints, and preferences persist across conversations.
|
|
37
|
+
**2.** **Cross-session project memory** — architecture decisions, constraints, and preferences persist across conversations.
|
|
38
38
|
|
|
39
39
|
**3.** Overnight dreamer agent that consolidates, deduplicates, and promotes memories into canonical facts, plus maintains codebase documentation.
|
|
40
40
|
|
|
@@ -42,7 +42,13 @@ Your agent should never stop working to manage its own context. Magic Context is
|
|
|
42
42
|
|
|
43
43
|
**5.** TUI sidebar with live context breakdown, token usage, historian status, and memory counts — right inside the terminal.
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
## Best way to use Magic Context?
|
|
46
|
+
|
|
47
|
+
Keep using the **same session** for **weeks**, **months**, or even **years**. **One session** per **project**!
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
### ✨ New Features Graduated in v0.14
|
|
46
52
|
|
|
47
53
|
**User Memories** — now enabled by default under `dreamer.user_memories`. Historian extracts behavioral observations about you alongside its normal compartment output (communication style, expertise level, review focus, working patterns). Recurring observations are promoted by the dreamer to stable user memories that appear in all sessions via `<user-profile>`. Set `dreamer.user_memories.enabled: false` to opt out. Requires dreamer.
|
|
48
54
|
|
|
@@ -341,7 +347,7 @@ On startup, Magic Context checks for common configuration problems — OpenCode'
|
|
|
341
347
|
A companion desktop app for browsing and managing Magic Context state outside of OpenCode.
|
|
342
348
|
|
|
343
349
|
<p align="center">
|
|
344
|
-
<a href="https://github.com/cortexkit/opencode-magic-context/releases/tag/dashboard-v0.3.
|
|
350
|
+
<a href="https://github.com/cortexkit/opencode-magic-context/releases/tag/dashboard-v0.3.1"><strong>⬇️ Download for macOS · Windows · Linux</strong></a></p>
|
|
345
351
|
|
|
346
352
|
**Features:**
|
|
347
353
|
- **Memory Browser** — search, filter, and edit project memories with category and project filtering
|
|
@@ -37,12 +37,45 @@ export interface DiagnosticReport {
|
|
|
37
37
|
historianDumps: {
|
|
38
38
|
dir: string;
|
|
39
39
|
count: number;
|
|
40
|
-
recent:
|
|
41
|
-
name: string;
|
|
42
|
-
ageMinutes: number;
|
|
43
|
-
sizeKb: number;
|
|
44
|
-
}[];
|
|
40
|
+
recent: HistorianDumpSummary[];
|
|
45
41
|
};
|
|
42
|
+
/** Most recent historian-failure rows from session_meta across all sessions. */
|
|
43
|
+
historianFailures: HistorianFailureSummary[];
|
|
44
|
+
}
|
|
45
|
+
export interface HistorianDumpSummary {
|
|
46
|
+
name: string;
|
|
47
|
+
ageMinutes: number;
|
|
48
|
+
sizeKb: number;
|
|
49
|
+
/** Parsed metadata — only structural fields, never raw XML content. */
|
|
50
|
+
meta?: HistorianDumpMeta;
|
|
51
|
+
/** If the XML could not be parsed, reason for failure. */
|
|
52
|
+
parseError?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface HistorianDumpMeta {
|
|
55
|
+
/** Number of <compartment> elements found. */
|
|
56
|
+
compartmentCount: number;
|
|
57
|
+
/** Smallest start ordinal across compartments, or null if none. */
|
|
58
|
+
minStart: number | null;
|
|
59
|
+
/** Largest end ordinal across compartments, or null if none. */
|
|
60
|
+
maxEnd: number | null;
|
|
61
|
+
/** Value of <unprocessed_from> tag, if present. */
|
|
62
|
+
unprocessedFrom: number | null;
|
|
63
|
+
/** Number of <fact> items grouped by category. */
|
|
64
|
+
factCountByCategory: Record<string, number>;
|
|
65
|
+
/** Number of <user_observations> items. */
|
|
66
|
+
userObservationCount: number;
|
|
67
|
+
/** Total number of compartment ordinal gaps (missing ranges between consecutive compartments). */
|
|
68
|
+
ordinalGapCount: number;
|
|
69
|
+
/** Total number of overlapping compartment ranges. */
|
|
70
|
+
ordinalOverlapCount: number;
|
|
71
|
+
}
|
|
72
|
+
export interface HistorianFailureSummary {
|
|
73
|
+
sessionId: string;
|
|
74
|
+
failureCount: number;
|
|
75
|
+
/** Sanitized truncated last-error text. May be empty if never set. */
|
|
76
|
+
lastError: string;
|
|
77
|
+
/** ISO timestamp of last failure, or empty if never failed. */
|
|
78
|
+
lastFailureAt: string;
|
|
46
79
|
}
|
|
47
80
|
export declare function collectDiagnostics(): Promise<DiagnosticReport>;
|
|
48
81
|
export declare function renderDiagnosticsMarkdown(report: DiagnosticReport): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/cli/diagnostics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/cli/diagnostics.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,WAAW,EAAqB,MAAM,gBAAgB,CAAC;AAMrE,MAAM,WAAW,gBAAgB;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,aAA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,WAAW,iBAAiB;IAC9B,8CAA8C;IAC9C,gBAAgB,EAAE,MAAM,CAAC;IACzB,mEAAmE;IACnE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,gEAAgE;IAChE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,mDAAmD;IACnD,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,kDAAkD;IAClD,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,2CAA2C;IAC3C,oBAAoB,EAAE,MAAM,CAAC;IAC7B,kGAAkG;IAClG,eAAe,EAAE,MAAM,CAAC;IACxB,sDAAsD;IACtD,mBAAmB,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,uBAAuB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,aAAa,EAAE,MAAM,CAAC;CACzB;AA+OD,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAgDpE;AASD,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CA8E1E"}
|
package/dist/cli/logs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../../src/cli/logs.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,gBAAgB,EAA6B,MAAM,eAAe,CAAC;AAMjF;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAe1D;AAeD,MAAM,WAAW,kBAAkB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;CACxB;
|
|
1
|
+
{"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../../src/cli/logs.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,gBAAgB,EAA6B,MAAM,eAAe,CAAC;AAMjF;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAe1D;AAeD,MAAM,WAAW,kBAAkB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;CACxB;AA0CD,wBAAsB,iBAAiB,CACnC,MAAM,EAAE,gBAAgB,EACxB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,GACf,OAAO,CAAC,kBAAkB,CAAC,CAkD7B"}
|
package/dist/cli.js
CHANGED
|
@@ -8656,11 +8656,59 @@ function detectConfigPaths() {
|
|
|
8656
8656
|
|
|
8657
8657
|
// src/cli/diagnostics.ts
|
|
8658
8658
|
var import_comment_json2 = __toESM(require_src2(), 1);
|
|
8659
|
+
import { Database } from "bun:sqlite";
|
|
8659
8660
|
import { existsSync as existsSync6, readdirSync, readFileSync as readFileSync4, statSync } from "node:fs";
|
|
8660
8661
|
import { createRequire as createRequire2 } from "node:module";
|
|
8661
8662
|
import { homedir as homedir4, tmpdir as tmpdir2, userInfo } from "node:os";
|
|
8662
8663
|
import { join as join7 } from "node:path";
|
|
8663
8664
|
|
|
8665
|
+
// src/hooks/magic-context/compartment-parser.ts
|
|
8666
|
+
var COMPARTMENT_REGEX = /<compartment\s+(?:id="[^"]*"\s+)?start="(\d+)"\s+end="(\d+)"\s+title="([^"]+)"\s*>(.*?)<\/compartment>/gs;
|
|
8667
|
+
var CATEGORY_BLOCK_REGEX = /<(WORKFLOW_RULES|ARCHITECTURE_DECISIONS|CONSTRAINTS|CONFIG_DEFAULTS|KNOWN_ISSUES|ENVIRONMENT|NAMING|USER_PREFERENCES|USER_DIRECTIVES)>(.*?)<\/\1>/gs;
|
|
8668
|
+
var FACT_ITEM_REGEX = /^\s*\*\s*(.+)$/gm;
|
|
8669
|
+
var UNPROCESSED_REGEX = /<unprocessed_from>(\d+)<\/unprocessed_from>/;
|
|
8670
|
+
var USER_OBSERVATIONS_REGEX = /<user_observations>(.*?)<\/user_observations>/s;
|
|
8671
|
+
var USER_OBS_ITEM_REGEX = /^\s*\*\s*(.+)$/gm;
|
|
8672
|
+
function parseCompartmentOutput(text) {
|
|
8673
|
+
const compartments = [];
|
|
8674
|
+
const facts = [];
|
|
8675
|
+
for (const match of text.matchAll(COMPARTMENT_REGEX)) {
|
|
8676
|
+
const startMessage = parseInt(match[1], 10);
|
|
8677
|
+
const endMessage = parseInt(match[2], 10);
|
|
8678
|
+
const title = unescapeXml(match[3]);
|
|
8679
|
+
const content = unescapeXml(match[4].trim());
|
|
8680
|
+
if (!Number.isNaN(startMessage) && !Number.isNaN(endMessage) && title && content) {
|
|
8681
|
+
compartments.push({ startMessage, endMessage, title, content });
|
|
8682
|
+
}
|
|
8683
|
+
}
|
|
8684
|
+
for (const categoryMatch of text.matchAll(CATEGORY_BLOCK_REGEX)) {
|
|
8685
|
+
const category = categoryMatch[1];
|
|
8686
|
+
const blockContent = categoryMatch[2];
|
|
8687
|
+
for (const itemMatch of blockContent.matchAll(FACT_ITEM_REGEX)) {
|
|
8688
|
+
const content = unescapeXml(itemMatch[1].trim());
|
|
8689
|
+
if (content) {
|
|
8690
|
+
facts.push({ category, content });
|
|
8691
|
+
}
|
|
8692
|
+
}
|
|
8693
|
+
}
|
|
8694
|
+
const unprocessedMatch = text.match(UNPROCESSED_REGEX);
|
|
8695
|
+
const unprocessedFrom = unprocessedMatch ? parseInt(unprocessedMatch[1], 10) : null;
|
|
8696
|
+
const userObservations = [];
|
|
8697
|
+
const userObsMatch = text.match(USER_OBSERVATIONS_REGEX);
|
|
8698
|
+
if (userObsMatch) {
|
|
8699
|
+
for (const itemMatch of userObsMatch[1].matchAll(USER_OBS_ITEM_REGEX)) {
|
|
8700
|
+
const obs = unescapeXml(itemMatch[1].trim());
|
|
8701
|
+
if (obs)
|
|
8702
|
+
userObservations.push(obs);
|
|
8703
|
+
}
|
|
8704
|
+
}
|
|
8705
|
+
compartments.sort((a, b) => a.startMessage - b.startMessage);
|
|
8706
|
+
return { compartments, facts, unprocessedFrom, userObservations };
|
|
8707
|
+
}
|
|
8708
|
+
function unescapeXml(s) {
|
|
8709
|
+
return s.replace(/&/g, "&").replace(/'/g, "'").replace(/"/g, '"').replace(/</g, "<").replace(/>/g, ">");
|
|
8710
|
+
}
|
|
8711
|
+
|
|
8664
8712
|
// src/cli/opencode-helpers.ts
|
|
8665
8713
|
import { execSync } from "node:child_process";
|
|
8666
8714
|
function isOpenCodeInstalled() {
|
|
@@ -8840,6 +8888,40 @@ function configHasPluginEntry(config) {
|
|
|
8840
8888
|
return false;
|
|
8841
8889
|
});
|
|
8842
8890
|
}
|
|
8891
|
+
function parseHistorianDumpMeta(path2) {
|
|
8892
|
+
try {
|
|
8893
|
+
const xml = readFileSync4(path2, "utf-8");
|
|
8894
|
+
const parsed = parseCompartmentOutput(xml);
|
|
8895
|
+
const factCountByCategory = {};
|
|
8896
|
+
for (const fact of parsed.facts) {
|
|
8897
|
+
factCountByCategory[fact.category] = (factCountByCategory[fact.category] ?? 0) + 1;
|
|
8898
|
+
}
|
|
8899
|
+
const starts = parsed.compartments.map((c) => c.startMessage);
|
|
8900
|
+
const ends = parsed.compartments.map((c) => c.endMessage);
|
|
8901
|
+
let gaps = 0;
|
|
8902
|
+
let overlaps = 0;
|
|
8903
|
+
for (let i = 1;i < parsed.compartments.length; i++) {
|
|
8904
|
+
const prev = parsed.compartments[i - 1];
|
|
8905
|
+
const curr = parsed.compartments[i];
|
|
8906
|
+
if (curr.startMessage > prev.endMessage + 1)
|
|
8907
|
+
gaps += 1;
|
|
8908
|
+
else if (curr.startMessage <= prev.endMessage)
|
|
8909
|
+
overlaps += 1;
|
|
8910
|
+
}
|
|
8911
|
+
return {
|
|
8912
|
+
compartmentCount: parsed.compartments.length,
|
|
8913
|
+
minStart: starts.length > 0 ? Math.min(...starts) : null,
|
|
8914
|
+
maxEnd: ends.length > 0 ? Math.max(...ends) : null,
|
|
8915
|
+
unprocessedFrom: parsed.unprocessedFrom,
|
|
8916
|
+
factCountByCategory,
|
|
8917
|
+
userObservationCount: parsed.userObservations.length,
|
|
8918
|
+
ordinalGapCount: gaps,
|
|
8919
|
+
ordinalOverlapCount: overlaps
|
|
8920
|
+
};
|
|
8921
|
+
} catch (error) {
|
|
8922
|
+
return { error: error instanceof Error ? error.message : String(error) };
|
|
8923
|
+
}
|
|
8924
|
+
}
|
|
8843
8925
|
function collectHistorianDumps() {
|
|
8844
8926
|
const dir = join7(tmpdir2(), "magic-context-historian");
|
|
8845
8927
|
if (!existsSync6(dir)) {
|
|
@@ -8855,16 +8937,49 @@ function collectHistorianDumps() {
|
|
|
8855
8937
|
};
|
|
8856
8938
|
}).sort((a, b) => b.mtime - a.mtime);
|
|
8857
8939
|
const now = Date.now();
|
|
8858
|
-
const recent = entries.slice(0,
|
|
8859
|
-
|
|
8860
|
-
|
|
8861
|
-
|
|
8862
|
-
|
|
8940
|
+
const recent = entries.slice(0, 5).map((entry) => {
|
|
8941
|
+
const meta = parseHistorianDumpMeta(join7(dir, entry.name));
|
|
8942
|
+
const summary = {
|
|
8943
|
+
name: entry.name,
|
|
8944
|
+
ageMinutes: Math.round((now - entry.mtime) / 60000),
|
|
8945
|
+
sizeKb: entry.sizeKb
|
|
8946
|
+
};
|
|
8947
|
+
if ("error" in meta) {
|
|
8948
|
+
summary.parseError = meta.error;
|
|
8949
|
+
} else {
|
|
8950
|
+
summary.meta = meta;
|
|
8951
|
+
}
|
|
8952
|
+
return summary;
|
|
8953
|
+
});
|
|
8863
8954
|
return { dir, count: entries.length, recent };
|
|
8864
8955
|
} catch {
|
|
8865
8956
|
return { dir, count: 0, recent: [] };
|
|
8866
8957
|
}
|
|
8867
8958
|
}
|
|
8959
|
+
function collectHistorianFailures(storageDirPath) {
|
|
8960
|
+
const contextDbPath = join7(storageDirPath, "context.db");
|
|
8961
|
+
if (!existsSync6(contextDbPath))
|
|
8962
|
+
return [];
|
|
8963
|
+
let db = null;
|
|
8964
|
+
try {
|
|
8965
|
+
db = new Database(contextDbPath, { readonly: true });
|
|
8966
|
+
const rows = db.prepare("SELECT session_id, historian_failure_count, historian_last_error, historian_last_failure_at FROM session_meta WHERE historian_failure_count > 0 ORDER BY historian_last_failure_at DESC LIMIT 10").all();
|
|
8967
|
+
return rows.map((row) => {
|
|
8968
|
+
const sessionId = typeof row.session_id === "string" ? row.session_id : "<unknown>";
|
|
8969
|
+
const failureCount = typeof row.historian_failure_count === "number" ? row.historian_failure_count : 0;
|
|
8970
|
+
const rawError = typeof row.historian_last_error === "string" ? row.historian_last_error : "";
|
|
8971
|
+
const lastAt = typeof row.historian_last_failure_at === "number" ? new Date(row.historian_last_failure_at).toISOString() : "";
|
|
8972
|
+
const lastError = sanitizeString(rawError.replace(/\s+/g, " ").trim().slice(0, 400));
|
|
8973
|
+
return { sessionId, failureCount, lastError, lastFailureAt: lastAt };
|
|
8974
|
+
});
|
|
8975
|
+
} catch {
|
|
8976
|
+
return [];
|
|
8977
|
+
} finally {
|
|
8978
|
+
try {
|
|
8979
|
+
db?.close();
|
|
8980
|
+
} catch {}
|
|
8981
|
+
}
|
|
8982
|
+
}
|
|
8868
8983
|
async function collectDiagnostics() {
|
|
8869
8984
|
const pluginVersion = getSelfVersion();
|
|
8870
8985
|
const configPaths = detectConfigPaths();
|
|
@@ -8907,7 +9022,8 @@ async function collectDiagnostics() {
|
|
|
8907
9022
|
exists: existsSync6(logPath),
|
|
8908
9023
|
sizeKb: Math.round(logFileSize / 1024)
|
|
8909
9024
|
},
|
|
8910
|
-
historianDumps: collectHistorianDumps()
|
|
9025
|
+
historianDumps: collectHistorianDumps(),
|
|
9026
|
+
historianFailures: collectHistorianFailures(storageDirPath)
|
|
8911
9027
|
};
|
|
8912
9028
|
}
|
|
8913
9029
|
function formatBytes(bytes) {
|
|
@@ -8976,9 +9092,14 @@ function renderDiagnosticsMarkdown(report) {
|
|
|
8976
9092
|
"```",
|
|
8977
9093
|
"",
|
|
8978
9094
|
"### Historian dumps",
|
|
9095
|
+
"(Metadata only — XML content is not included in this report.)",
|
|
8979
9096
|
"```json",
|
|
8980
9097
|
JSON.stringify(historianDumps, null, 2),
|
|
8981
9098
|
"```",
|
|
9099
|
+
"",
|
|
9100
|
+
"### Historian failures (session_meta)",
|
|
9101
|
+
report.historianFailures.length === 0 ? "_No sessions with historian failures._" : ["```json", JSON.stringify(report.historianFailures, null, 2), "```"].join(`
|
|
9102
|
+
`),
|
|
8982
9103
|
"",
|
|
8983
9104
|
"### Log file",
|
|
8984
9105
|
`- Path: ${sanitizeString(report.logFile.path)}`,
|
|
@@ -9022,11 +9143,36 @@ function formatTimestamp(date) {
|
|
|
9022
9143
|
pad(date.getSeconds())
|
|
9023
9144
|
].join("");
|
|
9024
9145
|
}
|
|
9146
|
+
var HISTORIAN_LOG_PATTERNS = [
|
|
9147
|
+
/historian failure:/,
|
|
9148
|
+
/historian failure recorded:/,
|
|
9149
|
+
/historian prompt failed:/,
|
|
9150
|
+
/## Historian alert/,
|
|
9151
|
+
/historian alert suppressed/,
|
|
9152
|
+
/EMERGENCY: aborting session/,
|
|
9153
|
+
/historian: prompt attempt \d+ failed:/
|
|
9154
|
+
];
|
|
9155
|
+
function isHistorianLogLine(line) {
|
|
9156
|
+
return HISTORIAN_LOG_PATTERNS.some((rx) => rx.test(line));
|
|
9157
|
+
}
|
|
9158
|
+
function extractHistorianFailureLines(sanitized, limit = 30) {
|
|
9159
|
+
const matches = [];
|
|
9160
|
+
const lines = sanitized.split(/\r?\n/);
|
|
9161
|
+
for (let i = lines.length - 1;i >= 0 && matches.length < limit; i -= 1) {
|
|
9162
|
+
if (isHistorianLogLine(lines[i])) {
|
|
9163
|
+
matches.push(lines[i]);
|
|
9164
|
+
}
|
|
9165
|
+
}
|
|
9166
|
+
return matches.reverse();
|
|
9167
|
+
}
|
|
9025
9168
|
async function bundleIssueReport(report, description, _title) {
|
|
9026
|
-
const LOG_TAIL_LINES =
|
|
9169
|
+
const LOG_TAIL_LINES = 400;
|
|
9027
9170
|
const logLines = report.logFile.exists ? readFileSync5(report.logFile.path, "utf-8").split(/\r?\n/) : [];
|
|
9028
9171
|
const recentLog = sanitizeLogContent(logLines.slice(-LOG_TAIL_LINES).join(`
|
|
9029
9172
|
`)).trim();
|
|
9173
|
+
const historianScanWindow = sanitizeLogContent(logLines.slice(-4000).join(`
|
|
9174
|
+
`));
|
|
9175
|
+
const historianFailureLines = extractHistorianFailureLines(historianScanWindow, 30);
|
|
9030
9176
|
const configBody = JSON.stringify(report.magicContextConfig.flags, null, 2);
|
|
9031
9177
|
const sanitizedConfigPath = report.configPaths.magicContextConfig.replace(homedir5(), "~");
|
|
9032
9178
|
const bodyMarkdown = [
|
|
@@ -9047,6 +9193,11 @@ async function bundleIssueReport(report, description, _title) {
|
|
|
9047
9193
|
"",
|
|
9048
9194
|
"## Diagnostics",
|
|
9049
9195
|
renderDiagnosticsMarkdown(report),
|
|
9196
|
+
"",
|
|
9197
|
+
"## Historian failure signals (log, sanitized)",
|
|
9198
|
+
historianFailureLines.length === 0 ? "_No historian failure log lines found in recent history._" : ["```", historianFailureLines.join(`
|
|
9199
|
+
`), "```"].join(`
|
|
9200
|
+
`),
|
|
9050
9201
|
"",
|
|
9051
9202
|
`## Log (last ${LOG_TAIL_LINES} lines, sanitized)`,
|
|
9052
9203
|
"```",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-meta-persisted.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/storage-meta-persisted.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"storage-meta-persisted.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/storage-meta-persisted.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAmC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C,IAAI,CAON;AAID,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CActF;AAED,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAOjG;AAED,wBAAgB,2BAA2B,CACvC,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAClB,OAAO,CAQT"}
|
|
@@ -24,4 +24,33 @@ export declare function removeCompactionMarkerForSession(db: Database, sessionId
|
|
|
24
24
|
* Close the writable OpenCode DB connection used for marker injection.
|
|
25
25
|
*/
|
|
26
26
|
export declare function closeCompactionMarkerConnection(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Startup consistency check for compaction markers.
|
|
29
|
+
*
|
|
30
|
+
* Magic Context persists marker state in context.db's `session_meta`, while the
|
|
31
|
+
* actual marker rows (compaction part + summary message + summary part) live in
|
|
32
|
+
* OpenCode's separate `opencode.db`. There is no cross-DB transaction between
|
|
33
|
+
* the two stores, so a crash between writes — or any external cleanup of
|
|
34
|
+
* OpenCode's DB — can leave the two in an inconsistent state:
|
|
35
|
+
*
|
|
36
|
+
* - Phantom state: persisted in context.db but the referenced rows no longer
|
|
37
|
+
* exist in opencode.db. On next publication, the manager tries to remove a
|
|
38
|
+
* marker that isn't there, ignores the failure, and re-injects, but the
|
|
39
|
+
* stale persisted state can also confuse readers that trust it.
|
|
40
|
+
* - Orphaned rows: rows in opencode.db exist without matching context.db
|
|
41
|
+
* state. Those can't be surfaced from here (we don't track them), but the
|
|
42
|
+
* natural-healing path already handles them: the next historian publication
|
|
43
|
+
* moves the boundary forward and the new injection replaces the orphans by
|
|
44
|
+
* moving filterCompacted past them.
|
|
45
|
+
*
|
|
46
|
+
* This function scans all persisted marker states and, for each one, verifies
|
|
47
|
+
* that the referenced rows still exist in opencode.db. If any referenced row
|
|
48
|
+
* is missing, it treats the marker as inconsistent, attempts to remove
|
|
49
|
+
* whatever rows ARE still present (best-effort cleanup of half-written
|
|
50
|
+
* markers), and clears the persisted state so the next publication can
|
|
51
|
+
* re-inject cleanly.
|
|
52
|
+
*
|
|
53
|
+
* Called once at plugin startup. Safe to call multiple times (idempotent).
|
|
54
|
+
*/
|
|
55
|
+
export declare function checkCompactionMarkerConsistency(db: Database): void;
|
|
27
56
|
//# sourceMappingURL=compaction-marker-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compaction-marker-manager.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/compaction-marker-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"compaction-marker-manager.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/compaction-marker-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAmB3C;;;GAGG;AACH,wBAAgB,sCAAsC,CAClD,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,EACjB,kBAAkB,EAAE,MAAM,EAC1B,SAAS,CAAC,EAAE,MAAM,GACnB,IAAI,CA6CN;AAED;;GAEG;AACH,wBAAgB,gCAAgC,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAmBtF;AAED;;GAEG;AACH,wBAAgB,+BAA+B,IAAI,IAAI,CAEtD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,gCAAgC,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAmGnE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compartment-runner-incremental.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/compartment-runner-incremental.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAoBxE,+DAA+D;AAC/D,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAEhE;AAED,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"compartment-runner-incremental.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/compartment-runner-incremental.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAoBxE,+DAA+D;AAC/D,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAEhE;AAED,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAoQpF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compartment-runner-partial-recomp.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/compartment-runner-partial-recomp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,WAAW,EAEd,MAAM,kDAAkD,CAAC;AAqB1D,OAAO,KAAK,EAAwB,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAU9F,MAAM,WAAW,kBAAkB;IAC/B,8DAA8D;IAC9D,KAAK,EAAE,MAAM,CAAC;IACd,2DAA2D;IAC3D,GAAG,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IAChC,kEAAkE;IAClE,SAAS,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,WAAW,EAAE,CAAC;IACjC,iBAAiB,EAAE,WAAW,EAAE,CAAC;IACjC,gBAAgB,EAAE,WAAW,EAAE,CAAC;CACnC;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACnC,YAAY,EAAE,WAAW,EAAE,EAC3B,KAAK,EAAE,kBAAkB,GAC1B,mBAAmB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CA2CzC;AAcD,wBAAsB,4BAA4B,CAC9C,IAAI,EAAE,qBAAqB,EAC3B,KAAK,EAAE,kBAAkB,GAC1B,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"compartment-runner-partial-recomp.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/compartment-runner-partial-recomp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,WAAW,EAEd,MAAM,kDAAkD,CAAC;AAqB1D,OAAO,KAAK,EAAwB,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAU9F,MAAM,WAAW,kBAAkB;IAC/B,8DAA8D;IAC9D,KAAK,EAAE,MAAM,CAAC;IACd,2DAA2D;IAC3D,GAAG,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IAChC,kEAAkE;IAClE,SAAS,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,WAAW,EAAE,CAAC;IACjC,iBAAiB,EAAE,WAAW,EAAE,CAAC;IACjC,gBAAgB,EAAE,WAAW,EAAE,CAAC;CACnC;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACnC,YAAY,EAAE,WAAW,EAAE,EAC3B,KAAK,EAAE,kBAAkB,GAC1B,mBAAmB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CA2CzC;AAcD,wBAAsB,4BAA4B,CAC9C,IAAI,EAAE,qBAAqB,EAC3B,KAAK,EAAE,kBAAkB,GAC1B,OAAO,CAAC,MAAM,CAAC,CAqWjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compartment-runner-recomp.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/compartment-runner-recomp.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAwB,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAc9F,wBAAsB,4BAA4B,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"compartment-runner-recomp.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/compartment-runner-recomp.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAwB,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAc9F,wBAAsB,4BAA4B,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CAiU/F"}
|
|
@@ -29,6 +29,15 @@ export interface CompartmentRunnerDeps {
|
|
|
29
29
|
compressorMinCompartmentRatio?: number;
|
|
30
30
|
/** Compressor max merge depth (1-5). Compartments at or above this depth are skipped. */
|
|
31
31
|
compressorMaxMergeDepth?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Called after the runner invalidates the in-memory injection cache
|
|
34
|
+
* (post-historian publication, post-recomp promotion, post-partial-recomp
|
|
35
|
+
* promotion). The caller should register the session as flush-pending so
|
|
36
|
+
* the very next transform pass is treated as cache-busting. Without this
|
|
37
|
+
* signal, background historian work can rebuild <session-history> on a
|
|
38
|
+
* defer pass and silently bust provider cache. See council Finding #9.
|
|
39
|
+
*/
|
|
40
|
+
onInjectionCacheCleared?: (sessionId: string) => void;
|
|
32
41
|
}
|
|
33
42
|
export interface CandidateCompartment {
|
|
34
43
|
sequence: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compartment-runner-types.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/compartment-runner-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,MAAM,WAAW,qBAAqB;IAClC,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChC,EAAE,EAAE,QAAQ,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,qBAAqB,CAAC,EAAE,MAAM,kBAAkB,CAAC;IACjD,gFAAgF;IAChF,6BAA6B,CAAC,EAAE,OAAO,CAAC;IACxC,0EAA0E;IAC1E,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,+EAA+E;IAC/E,6BAA6B,CAAC,EAAE,OAAO,CAAC;IACxC;gEAC4D;IAC5D,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kFAAkF;IAClF,6BAA6B,CAAC,EAAE,MAAM,CAAC;IACvC,yFAAyF;IACzF,uBAAuB,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"compartment-runner-types.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/compartment-runner-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,MAAM,WAAW,qBAAqB;IAClC,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChC,EAAE,EAAE,QAAQ,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B,kBAAkB,CAAC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E,MAAM,EAAE,CAAC;CAC/B,GACD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnC,MAAM,WAAW,sBAAsB;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,0BAA0B;IACvC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACpD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drop-stale-reduce-calls.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/drop-stale-reduce-calls.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"drop-stale-reduce-calls.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/drop-stale-reduce-calls.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIlD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAoBvD;AAoBD,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,cAAc,GAAE,MAAU,GAAG,OAAO,CAiCjG"}
|
|
@@ -10,7 +10,6 @@ export type RecentReduceBySession = Map<string, number>;
|
|
|
10
10
|
export type ToolUsageSinceUserTurn = Map<string, number>;
|
|
11
11
|
export type FlushedSessions = Set<string>;
|
|
12
12
|
export type LastHeuristicsTurnId = Map<string, string>;
|
|
13
|
-
export type EmergencyNudgeFired = Set<string>;
|
|
14
13
|
export declare function getLiveNotificationParams(sessionId: string, liveModelBySession: LiveModelBySession, variantBySession: VariantBySession, agentBySession?: AgentBySession): {
|
|
15
14
|
agent?: string;
|
|
16
15
|
variant?: string;
|
|
@@ -56,7 +55,6 @@ export declare function createEventHook(args: {
|
|
|
56
55
|
agentBySession: AgentBySession;
|
|
57
56
|
recentReduceBySession: RecentReduceBySession;
|
|
58
57
|
toolUsageSinceUserTurn: ToolUsageSinceUserTurn;
|
|
59
|
-
emergencyNudgeFired: EmergencyNudgeFired;
|
|
60
58
|
flushedSessions: FlushedSessions;
|
|
61
59
|
lastHeuristicsTurnId: LastHeuristicsTurnId;
|
|
62
60
|
commitSeenLastPass?: Map<string, boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook-handlers.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/hook-handlers.ts"],"names":[],"mappings":"AAKA,OAAO,EACH,sBAAsB,EAEzB,MAAM,2CAA2C,CAAC;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"hook-handlers.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/hook-handlers.ts"],"names":[],"mappings":"AAKA,OAAO,EACH,sBAAsB,EAEzB,MAAM,2CAA2C,CAAC;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAWxD,MAAM,MAAM,kBAAkB,GAAG,GAAG,CAAC,MAAM,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AACtF,MAAM,MAAM,gBAAgB,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAC/D,MAAM,MAAM,cAAc,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACjD,MAAM,MAAM,qBAAqB,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACxD,MAAM,MAAM,sBAAsB,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACzD,MAAM,MAAM,eAAe,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;AAC1C,MAAM,MAAM,oBAAoB,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;A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,CAAC,CAAC,CAAC,CAAC;IACjD,qBAAqB,EAAE,qBAAqB,CAAC;IAC7C,sBAAsB,EAAE,sBAAsB,CAAC;CAClD,IACiB,OAAO,OAAO,mBA4B/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,cAAc,EACtB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAOvF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAMxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAElE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAaxD,YAAY,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,cAAc,EACtB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAOvF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAMxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAElE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAaxD,YAAY,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAWnF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAQ7D,MAAM,WAAW,gBAAgB;IAC7B,MAAM,EAAE,aAAa,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AAC,EAAE,cAAc,CAAC;QAC1B,OAAO,CAAC,EAAE,aAAa,CAAC;QACxB,sBAAsB,CAAC,EAAE;YAAE,OAAO,EAAE,OAAO,CAAC;YAAC,YAAY,EAAE,MAAM,CAAA;SAAE,CAAC;QACpE,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAC7B,UAAU,CAAC,EAAE;YACT,OAAO,EAAE,OAAO,CAAC;YACjB,qBAAqB,EAAE,MAAM,CAAC;YAC9B,eAAe,EAAE,MAAM,CAAC;YACxB,WAAW,EAAE,MAAM,CAAC;SACvB,CAAC;QACF,YAAY,CAAC,EAAE;YACX,kBAAkB,CAAC,EAAE,OAAO,CAAC;YAC7B,mBAAmB,CAAC,EAAE;gBAAE,OAAO,EAAE,OAAO,CAAC;gBAAC,UAAU,EAAE,MAAM,CAAC;gBAAC,WAAW,EAAE,MAAM,CAAA;aAAE,CAAC;YACpF,WAAW,CAAC,EAAE;gBACV,OAAO,EAAE,OAAO,CAAC;gBACjB,eAAe,EAAE,MAAM,CAAC;gBACxB,gBAAgB,EAAE,MAAM,CAAC;aAC5B,CAAC;SACL,CAAC;KACL,CAAC;CACL;AAqCD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,gBAAgB;;;;;iBA5BzC,CAAb;;;;;;;;;;;;iBAzDa,CAAC;eAEjB,CAAA;aACA,CAAF;aAAuB,CAAC;sBAAc,CAAC;mBAAiB,CAAC;;;mBAmd9B;QAAE,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,UAAU,CAAC,EAAE,OAAO,CAAA;SAAE,CAAA;KAAE;;;SAa7E"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getOrCreateSessionMeta, getTopNBySize } from "../../features/magic-context/storage";
|
|
1
|
+
import { getOrCreateSessionMeta, type getTopNBySize } from "../../features/magic-context/storage";
|
|
2
2
|
import type { ContextUsage, SessionMeta, TagEntry } from "../../features/magic-context/types";
|
|
3
3
|
type ContextDatabase = Parameters<typeof getOrCreateSessionMeta>[0];
|
|
4
4
|
export type ContextNudge = {
|
|
@@ -17,8 +17,5 @@ export declare function createNudger(config: {
|
|
|
17
17
|
now?: () => number;
|
|
18
18
|
recentReduceBySession?: Map<string, number>;
|
|
19
19
|
}): (sessionId: string, contextUsage: ContextUsage, db: ContextDatabase, topNFn: typeof getTopNBySize, preloadedTags?: TagEntry[], messagesSinceLastUser?: number, preloadedSessionMeta?: SessionMeta) => ContextNudge | null;
|
|
20
|
-
export declare function generateEmergencyNudgeText(db: ContextDatabase, sessionId: string, contextUsage: ContextUsage, config: {
|
|
21
|
-
protected_tags: number;
|
|
22
|
-
}): string;
|
|
23
20
|
export {};
|
|
24
21
|
//# sourceMappingURL=nudger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nudger.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/nudger.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,sBAAsB,EAGtB,aAAa,
|
|
1
|
+
{"version":3,"file":"nudger.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/nudger.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,sBAAsB,EAGtB,KAAK,aAAa,EAErB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAY9F,KAAK,eAAe,GAAG,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC;AACpE,MAAM,MAAM,YAAY,GAAG;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAC/D,eAAO,MAAM,2BAA2B,QAAgB,CAAC;AA+BzD,wBAAgB,YAAY,CAAC,MAAM,EAAE;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,yBAAyB,EAAE,MAAM,CAAC;IAClC,4BAA4B,EAAE,MAAM,GAAG;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACvF,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,qBAAqB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/C,IAIO,WAAW,MAAM,EACjB,cAAc,YAAY,EAC1B,IAAI,eAAe,EACnB,QAAQ,OAAO,aAAa,EAC5B,gBAAgB,QAAQ,EAAE,EAC1B,wBAAwB,MAAM,EAC9B,uBAAuB,WAAW,KACnC,YAAY,GAAG,IAAI,CAyIzB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create an empty-text sentinel to replace a stripped message part while
|
|
3
|
+
* preserving the array's length and index positions across passes.
|
|
4
|
+
*
|
|
5
|
+
* Why sentinels exist: some providers (Antigravity/Gemini-routed-Claude,
|
|
6
|
+
* some OpenRouter configs) hash the full serialized messages[] array as
|
|
7
|
+
* their prompt-cache key. Any array-length change between turns busts the
|
|
8
|
+
* cache. Replacing removed parts with inert `{type:"text", text:""}`
|
|
9
|
+
* placeholders keeps the array shape stable so subsequent turns can hit
|
|
10
|
+
* cache on the unchanged prefix.
|
|
11
|
+
*
|
|
12
|
+
* For Anthropic/Bedrock/Google-SDK providers, `provider/transform.ts:55-73`
|
|
13
|
+
* (or the SDK itself) filters out parts where `text === ""`, so the
|
|
14
|
+
* sentinel never reaches the wire. Wire behavior stays identical to the
|
|
15
|
+
* previous `.filter()`/`.splice()` behavior.
|
|
16
|
+
*
|
|
17
|
+
* `cache_control` inheritance: if the original part carried provider-side
|
|
18
|
+
* cache-breakpoint metadata (`cache_control` / `cacheControl`), the
|
|
19
|
+
* sentinel inherits it. OpenCode currently only sets cache markers on the
|
|
20
|
+
* last two system+non-system messages (never on mid-history parts we
|
|
21
|
+
* strip), so this is defensive, but cheap.
|
|
22
|
+
*/
|
|
23
|
+
export declare function makeSentinel(originalPart: unknown): {
|
|
24
|
+
type: "text";
|
|
25
|
+
text: "";
|
|
26
|
+
} & Record<string, unknown>;
|
|
27
|
+
/**
|
|
28
|
+
* Detect whether a part is already an empty-text sentinel produced by
|
|
29
|
+
* `makeSentinel`. Used by strip functions to stay idempotent — don't
|
|
30
|
+
* re-count or re-mutate a sentinel we already installed.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isSentinel(part: unknown): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Replay a previously-persisted set of message IDs by replacing each
|
|
35
|
+
* matching message's parts with a single empty-text sentinel. Used to keep
|
|
36
|
+
* the wire shape stable across defer passes when OpenCode rebuilds messages
|
|
37
|
+
* from its DB — any message whose ID is in `ids` was neutralized on a prior
|
|
38
|
+
* bust pass and should be neutralized again now.
|
|
39
|
+
*
|
|
40
|
+
* Returns the number of messages replayed + the set of IDs that were NOT
|
|
41
|
+
* found in the current message array (caller can prune them from the
|
|
42
|
+
* persisted set so we stop carrying stale IDs forever).
|
|
43
|
+
*/
|
|
44
|
+
export declare function replaySentinelByMessageIds(messages: Array<{
|
|
45
|
+
info: {
|
|
46
|
+
id?: string;
|
|
47
|
+
};
|
|
48
|
+
parts: unknown[];
|
|
49
|
+
}>, ids: Set<string>): {
|
|
50
|
+
replayed: number;
|
|
51
|
+
missingIds: string[];
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=sentinel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sentinel.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/sentinel.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CACxB,YAAY,EAAE,OAAO,GACtB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,EAAE,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CActD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAIjD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACtC,QAAQ,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,KAAK,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC,EAC5D,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,GACjB;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,EAAE,CAAA;CAAE,CAoB5C"}
|