@cortexkit/opencode-magic-context 0.42.5 → 0.42.6
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 +2 -2
- package/dist/config/index.d.ts +9 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/schema/magic-context.d.ts +1 -0
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-jyj54gbe.js → conflict-warning-hook-aktepwpz.js} +3 -3
- package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
- package/dist/features/magic-context/context-authority.d.ts +28 -1
- package/dist/features/magic-context/context-authority.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/open-opencode-db.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-local.d.ts +1 -0
- package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding.d.ts +1 -1
- package/dist/features/magic-context/memory/embedding.d.ts.map +1 -1
- package/dist/features/magic-context/message-index.d.ts.map +1 -1
- package/dist/features/magic-context/migrations.d.ts +12 -0
- package/dist/features/magic-context/migrations.d.ts.map +1 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts +1 -0
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/session-project-backfill.d.ts.map +1 -1
- package/dist/features/magic-context/storage-db.d.ts +1 -1
- package/dist/features/magic-context/tool-owner-backfill.d.ts.map +1 -1
- package/dist/hooks/auto-update-checker/index.d.ts.map +1 -1
- package/dist/hooks/magic-context/cache-busting-signals.d.ts +0 -1
- package/dist/hooks/magic-context/cache-busting-signals.d.ts.map +1 -1
- package/dist/hooks/magic-context/channel2-delivery.d.ts +8 -0
- package/dist/hooks/magic-context/channel2-delivery.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts +12 -0
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts +4 -4
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/module-state-sync.d.ts +3 -0
- package/dist/hooks/magic-context/module-state-sync.d.ts.map +1 -1
- package/dist/hooks/magic-context/module-transport.d.ts +24 -2
- package/dist/hooks/magic-context/module-transport.d.ts.map +1 -1
- package/dist/hooks/magic-context/module-wire.d.ts +1 -1
- package/dist/hooks/magic-context/module-wire.d.ts.map +1 -1
- package/dist/hooks/magic-context/producer-window-guard.d.ts +31 -1
- package/dist/hooks/magic-context/producer-window-guard.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-chunk.d.ts +6 -0
- package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-db.d.ts +8 -0
- package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-formatting.d.ts +6 -0
- package/dist/hooks/magic-context/read-session-formatting.d.ts.map +1 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts +30 -0
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/rust-refusal-recovery.d.ts +28 -0
- package/dist/hooks/magic-context/rust-refusal-recovery.d.ts.map +1 -0
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +7 -0
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-jkrqhc7y.js → index-a9ssj59b.js} +94 -15
- package/dist/{index-3wbd8sdq.js → index-djp6rwz6.js} +455 -46
- package/dist/{index-p474rw9p.js → index-ngjmj6xx.js} +1 -1
- package/dist/{index-d8mgqezq.js → index-s61hh7gv.js} +50 -17
- package/dist/{index-1ar7b3e9.js → index-znraa0kv.js} +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1485 -360
- package/dist/plugin/embedding-bootstrap.d.ts.map +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/memory-id-translation.d.ts +23 -0
- package/dist/plugin/memory-id-translation.d.ts.map +1 -0
- package/dist/plugin/rust-tool-backends.d.ts +1 -1
- package/dist/plugin/rust-tool-backends.d.ts.map +1 -1
- package/dist/{recomp-orchestrator-k20sfpm2.js → recomp-orchestrator-0xx1364v.js} +4 -4
- package/dist/{send-session-notification-xnypkxpx.js → send-session-notification-jbxknvar.js} +2 -2
- package/dist/shared/auto-update-provenance.d.ts +9 -0
- package/dist/shared/auto-update-provenance.d.ts.map +1 -0
- package/dist/shared/conflict-detector.d.ts +5 -1
- package/dist/shared/conflict-detector.d.ts.map +1 -1
- package/dist/shared/opencode-db-path.d.ts +31 -2
- package/dist/shared/opencode-db-path.d.ts.map +1 -1
- package/dist/shared/prompt-surface-runtime.d.ts +3 -3
- package/dist/shared/prompt-surface-runtime.d.ts.map +1 -1
- package/dist/{storage-meta-session-x3j0q9qy.js → storage-meta-session-z818pn1e.js} +2 -2
- package/dist/tools/ctx-expand/mode.d.ts +31 -0
- package/dist/tools/ctx-expand/mode.d.ts.map +1 -0
- package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
- package/dist/tools/ctx-memory/tools.d.ts.map +1 -1
- package/dist/tools/ctx-note/constants.d.ts +1 -1
- package/dist/tools/ctx-note/constants.d.ts.map +1 -1
- package/dist/tools/ctx-note/tools.d.ts.map +1 -1
- package/dist/tools/ctx-note/types.d.ts +1 -1
- package/dist/tools/ctx-note/types.d.ts.map +1 -1
- package/dist/tools/ctx-reduce/constants.d.ts +1 -1
- package/dist/tools/ctx-reduce/constants.d.ts.map +1 -1
- package/dist/tools/ctx-search/types.d.ts +1 -1
- package/dist/tools/ctx-search/types.d.ts.map +1 -1
- package/dist/tools/light-descriptions.d.ts +2 -2
- package/dist/tools/light-descriptions.d.ts.map +1 -1
- package/dist/v2/hidden-completion.d.ts +69 -13
- package/dist/v2/hidden-completion.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts +13 -1
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/hidden-child.d.ts +31 -0
- package/dist/v2/hooks/hidden-child.d.ts.map +1 -0
- package/dist/v2/hooks/store.d.ts.map +1 -1
- package/dist/v2/hooks/types.d.ts +99 -19
- package/dist/v2/hooks/types.d.ts.map +1 -1
- package/dist/v2/server.d.ts +19 -0
- package/dist/v2/server.d.ts.map +1 -1
- package/dist/v2/server.js +1781 -253
- package/dist/v2/store-reader.d.ts +11 -5
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/tui/index.d.ts +10 -0
- package/dist/v2/tui/index.d.ts.map +1 -0
- package/dist/v2/tui/types.d.ts +80 -0
- package/dist/v2/tui/types.d.ts.map +1 -0
- package/package.json +5 -4
- package/src/agents/magic-context-prompt.ts +1 -1
- package/src/config/index.ts +31 -1
- package/src/config/protected-tokens.test.ts +40 -0
- package/src/config/schema/magic-context.ts +8 -3
- package/src/shared/auto-update-provenance.ts +42 -0
- package/src/shared/conflict-detector.test.ts +53 -0
- package/src/shared/conflict-detector.ts +88 -19
- package/src/shared/models-dev-cache.test.ts +25 -0
- package/src/shared/opencode-db-path.test.ts +96 -0
- package/src/shared/opencode-db-path.ts +146 -15
- package/src/shared/prompt-surface-a1-golden.md +12 -16
- package/src/shared/prompt-surface-runtime.test.ts +20 -0
- package/src/shared/prompt-surface-runtime.ts +7 -5
- package/src/tui/entry.mjs +11 -1
- package/src/v2/tui/host-contract.test.ts +202 -0
- package/src/v2/tui/index.ts +270 -0
- package/src/v2/tui/types.ts +67 -0
|
@@ -9,15 +9,16 @@ import { isAbsolute, join } from "node:path";
|
|
|
9
9
|
var cachedResolution = null;
|
|
10
10
|
var lastReadFailure = null;
|
|
11
11
|
var claimedDiagnostics = new Set;
|
|
12
|
-
function openCodeDataDir() {
|
|
13
|
-
return join(
|
|
12
|
+
function openCodeDataDir(env = process.env, dataHome) {
|
|
13
|
+
return join(dataHome ?? env.XDG_DATA_HOME ?? join(homedir(), ".local", "share"), "opencode");
|
|
14
14
|
}
|
|
15
|
-
function environmentKey(dataDir) {
|
|
15
|
+
function environmentKey(dataDir, hostGeneration, channel, env) {
|
|
16
16
|
return [
|
|
17
|
+
hostGeneration,
|
|
17
18
|
dataDir,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
env.OPENCODE_DB ?? "",
|
|
20
|
+
env.OPENCODE_DISABLE_CHANNEL_DB ?? "",
|
|
21
|
+
channel ?? env.OPENCODE_CHANNEL ?? ""
|
|
21
22
|
].join("\x00");
|
|
22
23
|
}
|
|
23
24
|
function channelPath(dataDir, channel) {
|
|
@@ -49,8 +50,8 @@ function discoverOpenCodeDb(dataDir) {
|
|
|
49
50
|
const channel = name === "opencode.db" ? null : name.slice("opencode-".length, -".db".length) || null;
|
|
50
51
|
return { path: existing.path, source: "discovered", channel };
|
|
51
52
|
}
|
|
52
|
-
function
|
|
53
|
-
const explicit =
|
|
53
|
+
function resolveV1Fresh(dataDir, env = process.env) {
|
|
54
|
+
const explicit = env.OPENCODE_DB;
|
|
54
55
|
if (explicit !== undefined && explicit.length > 0) {
|
|
55
56
|
if (explicit === ":memory:") {
|
|
56
57
|
return { path: explicit, source: "OPENCODE_DB", channel: null };
|
|
@@ -61,24 +62,47 @@ function resolveFresh(dataDir) {
|
|
|
61
62
|
channel: null
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
|
-
const disableChannelDb =
|
|
65
|
+
const disableChannelDb = env.OPENCODE_DISABLE_CHANNEL_DB;
|
|
65
66
|
if (disableChannelDb === "1" || disableChannelDb === "true") {
|
|
66
67
|
return { path: join(dataDir, "opencode.db"), source: "default", channel: null };
|
|
67
68
|
}
|
|
68
|
-
const channel =
|
|
69
|
+
const channel = env.OPENCODE_CHANNEL;
|
|
69
70
|
if (channel !== undefined && channel.length > 0) {
|
|
70
71
|
return { path: channelPath(dataDir, channel), source: "channel", channel };
|
|
71
72
|
}
|
|
72
73
|
return discoverOpenCodeDb(dataDir);
|
|
73
74
|
}
|
|
74
|
-
function
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
function sourceOpenCodeDatabaseFilename(hostGeneration, channel, env = process.env) {
|
|
76
|
+
if (hostGeneration === "v1") {
|
|
77
|
+
const explicit = env.OPENCODE_DB;
|
|
78
|
+
if (explicit !== undefined && explicit.length > 0)
|
|
79
|
+
return explicit;
|
|
80
|
+
if (env.OPENCODE_DISABLE_CHANNEL_DB === "1" || env.OPENCODE_DISABLE_CHANNEL_DB === "true") {
|
|
81
|
+
return "opencode.db";
|
|
82
|
+
}
|
|
83
|
+
return ["latest", "beta", "prod"].includes(channel) ? "opencode.db" : `opencode-${channel}.db`;
|
|
84
|
+
}
|
|
85
|
+
return env.OPENCODE_DB ?? (["latest", "dev", "beta", "next", "prod"].includes(channel) || env.OPENCODE_DISABLE_CHANNEL_DB === "1" || env.OPENCODE_DISABLE_CHANNEL_DB === "true" ? "opencode.db" : `opencode-${channel.replace(/[^a-zA-Z0-9._-]/g, "")}.db`);
|
|
86
|
+
}
|
|
87
|
+
function resolveV2Fresh(dataDir, channel, env) {
|
|
88
|
+
const filename = sourceOpenCodeDatabaseFilename("v2", channel, env);
|
|
89
|
+
const explicit = env.OPENCODE_DB !== undefined;
|
|
90
|
+
return {
|
|
91
|
+
path: filename === ":memory:" ? filename : join(dataDir, filename),
|
|
92
|
+
source: explicit ? "OPENCODE_DB" : env.OPENCODE_CHANNEL ? "channel" : "default",
|
|
93
|
+
channel: explicit ? null : channel
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function resolveOpenCodeDbPath(hostGeneration = "v1", options = {}) {
|
|
97
|
+
const env = options.env ?? process.env;
|
|
98
|
+
const dataDir = openCodeDataDir(env, options.dataHome);
|
|
99
|
+
const channel = options.channel ?? env.OPENCODE_CHANNEL;
|
|
100
|
+
const key = environmentKey(dataDir, hostGeneration, channel, env);
|
|
77
101
|
if (cachedResolution?.key === key && (!cachedResolution.existed || existsSync(cachedResolution.resolution.path))) {
|
|
78
102
|
if (cachedResolution.existed)
|
|
79
103
|
return cachedResolution.resolution;
|
|
80
104
|
}
|
|
81
|
-
const resolution =
|
|
105
|
+
const resolution = hostGeneration === "v2" ? resolveV2Fresh(dataDir, channel ?? "latest", env) : resolveV1Fresh(dataDir, env);
|
|
82
106
|
cachedResolution = {
|
|
83
107
|
key,
|
|
84
108
|
resolution,
|
|
@@ -86,6 +110,29 @@ function resolveOpenCodeDbPath() {
|
|
|
86
110
|
};
|
|
87
111
|
return resolution;
|
|
88
112
|
}
|
|
113
|
+
function schemaTableNames(db, schema = "main") {
|
|
114
|
+
const rows = db.prepare(`SELECT name FROM ${schema}.sqlite_master WHERE type = 'table' AND name IN ('message', 'part', 'session', 'project', 'session_message')`).all();
|
|
115
|
+
return new Set(rows.flatMap((row) => typeof row.name === "string" ? [row.name] : []));
|
|
116
|
+
}
|
|
117
|
+
function detectOpenCodeStoreGeneration(db, schema = "main") {
|
|
118
|
+
const tables = schemaTableNames(db, schema);
|
|
119
|
+
const hasV1Messages = tables.has("message") && tables.has("part");
|
|
120
|
+
if (hasV1Messages)
|
|
121
|
+
return "v1";
|
|
122
|
+
if (tables.has("session_message"))
|
|
123
|
+
return "v2";
|
|
124
|
+
if (tables.has("session") || tables.has("project"))
|
|
125
|
+
return "v1";
|
|
126
|
+
return "unknown";
|
|
127
|
+
}
|
|
128
|
+
function assertOpenCodeStoreGeneration(db, expected, path, schema = "main") {
|
|
129
|
+
const actual = detectOpenCodeStoreGeneration(db, schema);
|
|
130
|
+
if (actual === expected)
|
|
131
|
+
return;
|
|
132
|
+
if (actual === "unknown")
|
|
133
|
+
return;
|
|
134
|
+
throw new Error(`OpenCode store generation mismatch at ${path}: expected ${expected}, found ${actual}; refusing generation-specific database access`);
|
|
135
|
+
}
|
|
89
136
|
function openCodeDbPathExists(resolution = resolveOpenCodeDbPath()) {
|
|
90
137
|
return resolution.path !== ":memory:" && existsSync(resolution.path);
|
|
91
138
|
}
|
|
@@ -450,6 +497,12 @@ function getReadOnlySessionDb() {
|
|
|
450
497
|
}
|
|
451
498
|
closeCachedReadOnlyDb();
|
|
452
499
|
const db = new Database(dbPath, { readonly: true });
|
|
500
|
+
try {
|
|
501
|
+
assertOpenCodeStoreGeneration(db, "v1", dbPath);
|
|
502
|
+
} catch (error) {
|
|
503
|
+
closeQuietly(db);
|
|
504
|
+
throw error;
|
|
505
|
+
}
|
|
453
506
|
cachedReadOnlyDb = { path: dbPath, db };
|
|
454
507
|
clearOpenCodeDbReadFailure();
|
|
455
508
|
return db;
|
|
@@ -687,6 +740,32 @@ function assistantAwaitingToolsFromOpenCodeDb(db, sessionId) {
|
|
|
687
740
|
}
|
|
688
741
|
});
|
|
689
742
|
}
|
|
743
|
+
function latestPersistedMessageForRecovery(sessionId) {
|
|
744
|
+
return withReadOnlySessionDb((db) => {
|
|
745
|
+
const row = db.prepare(`SELECT id, data
|
|
746
|
+
FROM message
|
|
747
|
+
WHERE session_id = ?
|
|
748
|
+
ORDER BY time_created DESC, id DESC
|
|
749
|
+
LIMIT 1`).get(sessionId);
|
|
750
|
+
if (typeof row?.id !== "string" || typeof row.data !== "string")
|
|
751
|
+
return null;
|
|
752
|
+
try {
|
|
753
|
+
const data = JSON.parse(row.data);
|
|
754
|
+
if (typeof data.role !== "string")
|
|
755
|
+
return null;
|
|
756
|
+
const time = data.time && typeof data.time === "object" ? data.time : null;
|
|
757
|
+
return {
|
|
758
|
+
id: row.id,
|
|
759
|
+
role: data.role,
|
|
760
|
+
...typeof data.parentID === "string" ? { parentID: data.parentID } : {},
|
|
761
|
+
...typeof time?.completed === "number" ? { completedAt: time.completed } : {},
|
|
762
|
+
...data.error === undefined ? {} : { error: data.error }
|
|
763
|
+
};
|
|
764
|
+
} catch {
|
|
765
|
+
return null;
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
}
|
|
690
769
|
function hasNewerRealUserMessage(db, sessionId, latestAssistantTimeCreated) {
|
|
691
770
|
if (typeof latestAssistantTimeCreated !== "number")
|
|
692
771
|
return false;
|
|
@@ -780,4 +859,4 @@ function findLastAssistantModelFromOpenCodeDb(sessionId) {
|
|
|
780
859
|
}
|
|
781
860
|
}
|
|
782
861
|
|
|
783
|
-
export { resolveOpenCodeDbPath, openCodeDbPathExists, formatOpenCodeDbMissingBanner, formatOpenCodeDbMissingStatusLine, formatOpenCodeDbReadFailureStatusLine, recordOpenCodeDbReadFailure, clearOpenCodeDbReadFailure, getOpenCodeDbReadFailure, claimOpenCodeDbDiagnosticOnce, registerSlowWriteReporter, detectSqliteRuntime, Database, getSqliteMemoryStats, withPrivilegedWriter, closeQuietly, openCodeDbExists, withReadOnlySessionDb, getRawSessionMessageCountFromDb, observeOpenCodeTurnEvent, clearTrackedOpenCodeSession, assistantAwaitingTools, shouldHoldIgnoredNotification, getMessageTimesFromOpenCodeDb, findLastAssistantModelFromOpenCodeDb };
|
|
862
|
+
export { resolveOpenCodeDbPath, assertOpenCodeStoreGeneration, openCodeDbPathExists, formatOpenCodeDbMissingBanner, formatOpenCodeDbMissingStatusLine, formatOpenCodeDbReadFailureStatusLine, recordOpenCodeDbReadFailure, clearOpenCodeDbReadFailure, getOpenCodeDbReadFailure, claimOpenCodeDbDiagnosticOnce, registerSlowWriteReporter, detectSqliteRuntime, Database, getSqliteMemoryStats, withPrivilegedWriter, closeQuietly, openCodeDbExists, withReadOnlySessionDb, getRawSessionMessageCountFromDb, observeOpenCodeTurnEvent, clearTrackedOpenCodeSession, assistantAwaitingTools, shouldHoldIgnoredNotification, latestPersistedMessageForRecovery, getMessageTimesFromOpenCodeDb, findLastAssistantModelFromOpenCodeDb };
|