@wolfx/pi-magic-context 0.22.3 → 0.22.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/dist/index.js +439 -413
- package/dist/subagent-entry.js +297 -265
- package/package.json +1 -1
package/dist/subagent-entry.js
CHANGED
|
@@ -46,167 +46,6 @@ var __export = (target, all) => {
|
|
|
46
46
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
47
47
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
48
48
|
|
|
49
|
-
// ../plugin/src/shared/harness.ts
|
|
50
|
-
function setHarness(value) {
|
|
51
|
-
if (harnessLocked && currentHarness !== value) {
|
|
52
|
-
throw new Error(`Magic Context: harness already locked to "${currentHarness}"; cannot change to "${value}"`);
|
|
53
|
-
}
|
|
54
|
-
currentHarness = value;
|
|
55
|
-
harnessLocked = true;
|
|
56
|
-
}
|
|
57
|
-
function getHarness() {
|
|
58
|
-
return currentHarness;
|
|
59
|
-
}
|
|
60
|
-
var currentHarness = "opencode", harnessLocked = false;
|
|
61
|
-
|
|
62
|
-
// ../plugin/src/shared/data-path.ts
|
|
63
|
-
import * as os from "node:os";
|
|
64
|
-
import * as path from "node:path";
|
|
65
|
-
function getDataDir() {
|
|
66
|
-
return process.env.XDG_DATA_HOME ?? path.join(os.homedir(), ".local", "share");
|
|
67
|
-
}
|
|
68
|
-
function getMagicContextTempDir(harness = getHarness()) {
|
|
69
|
-
return path.join(os.tmpdir(), harness, "magic-context");
|
|
70
|
-
}
|
|
71
|
-
function getMagicContextLogPath(harness = getHarness()) {
|
|
72
|
-
return path.join(getMagicContextTempDir(harness), "magic-context.log");
|
|
73
|
-
}
|
|
74
|
-
function getProjectMagicContextDir(directory) {
|
|
75
|
-
return path.join(directory, ".magic-context");
|
|
76
|
-
}
|
|
77
|
-
function getProjectMagicContextHistorianDir(directory) {
|
|
78
|
-
return path.join(getProjectMagicContextDir(directory), "historian");
|
|
79
|
-
}
|
|
80
|
-
function getOpenCodeStorageDir() {
|
|
81
|
-
return path.join(getDataDir(), "opencode", "storage");
|
|
82
|
-
}
|
|
83
|
-
function getMagicContextStorageDir() {
|
|
84
|
-
return path.join(getDataDir(), "cortexkit", "magic-context");
|
|
85
|
-
}
|
|
86
|
-
function getLegacyOpenCodeMagicContextStorageDir() {
|
|
87
|
-
return path.join(getOpenCodeStorageDir(), "plugin", "magic-context");
|
|
88
|
-
}
|
|
89
|
-
var init_data_path = () => {};
|
|
90
|
-
|
|
91
|
-
// ../plugin/src/shared/logger.ts
|
|
92
|
-
import * as fs from "node:fs";
|
|
93
|
-
import * as path2 from "node:path";
|
|
94
|
-
function ensureDir(filePath) {
|
|
95
|
-
const dir = path2.dirname(filePath);
|
|
96
|
-
if (dir === lastEnsuredDir)
|
|
97
|
-
return;
|
|
98
|
-
try {
|
|
99
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
100
|
-
lastEnsuredDir = dir;
|
|
101
|
-
} catch {}
|
|
102
|
-
}
|
|
103
|
-
function flush() {
|
|
104
|
-
if (flushTimer) {
|
|
105
|
-
clearTimeout(flushTimer);
|
|
106
|
-
flushTimer = null;
|
|
107
|
-
}
|
|
108
|
-
if (buffer.length === 0)
|
|
109
|
-
return;
|
|
110
|
-
const data = buffer.join("");
|
|
111
|
-
buffer = [];
|
|
112
|
-
try {
|
|
113
|
-
const logFile = getMagicContextLogPath();
|
|
114
|
-
ensureDir(logFile);
|
|
115
|
-
fs.appendFileSync(logFile, data);
|
|
116
|
-
} catch {}
|
|
117
|
-
}
|
|
118
|
-
function scheduleFlush() {
|
|
119
|
-
if (flushTimer)
|
|
120
|
-
return;
|
|
121
|
-
flushTimer = setTimeout(() => {
|
|
122
|
-
flushTimer = null;
|
|
123
|
-
flush();
|
|
124
|
-
}, FLUSH_INTERVAL_MS);
|
|
125
|
-
}
|
|
126
|
-
function log(message, data) {
|
|
127
|
-
if (isTestEnv)
|
|
128
|
-
return;
|
|
129
|
-
try {
|
|
130
|
-
const timestamp = new Date().toISOString();
|
|
131
|
-
const serialized = data === undefined ? "" : data instanceof Error ? ` ${data.message}${data.stack ? `
|
|
132
|
-
${data.stack}` : ""}` : ` ${JSON.stringify(data)}`;
|
|
133
|
-
buffer.push(`[${timestamp}] ${message}${serialized}
|
|
134
|
-
`);
|
|
135
|
-
if (buffer.length >= BUFFER_SIZE_LIMIT) {
|
|
136
|
-
flush();
|
|
137
|
-
} else {
|
|
138
|
-
scheduleFlush();
|
|
139
|
-
}
|
|
140
|
-
} catch {}
|
|
141
|
-
}
|
|
142
|
-
function sessionLog(sessionId, message, data) {
|
|
143
|
-
log(`[magic-context][${sessionId}] ${message}`, data);
|
|
144
|
-
}
|
|
145
|
-
var isTestEnv = false, buffer, flushTimer = null, FLUSH_INTERVAL_MS = 500, BUFFER_SIZE_LIMIT = 50, lastEnsuredDir = null;
|
|
146
|
-
var init_logger = __esm(() => {
|
|
147
|
-
init_data_path();
|
|
148
|
-
buffer = [];
|
|
149
|
-
if (!isTestEnv) {
|
|
150
|
-
process.on("exit", flush);
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// ../plugin/src/shared/sqlite.ts
|
|
155
|
-
function buildNodeSqliteDatabaseClass(DatabaseSync) {
|
|
156
|
-
const SAVEPOINT = "mc_tx_sp";
|
|
157
|
-
|
|
158
|
-
class NodeSqliteDatabase extends DatabaseSync {
|
|
159
|
-
constructor(filename, options) {
|
|
160
|
-
const translated = { ...options };
|
|
161
|
-
if (options && "readonly" in options) {
|
|
162
|
-
translated.readOnly = options.readonly;
|
|
163
|
-
delete translated.readonly;
|
|
164
|
-
}
|
|
165
|
-
super(typeof filename === "string" ? filename : ":memory:", translated);
|
|
166
|
-
}
|
|
167
|
-
transaction(fn) {
|
|
168
|
-
const self = this;
|
|
169
|
-
const wrapped = function(...args) {
|
|
170
|
-
const nested = self.isTransaction === true;
|
|
171
|
-
self.exec(nested ? `SAVEPOINT ${SAVEPOINT}` : "BEGIN");
|
|
172
|
-
try {
|
|
173
|
-
const result = fn.apply(this, args);
|
|
174
|
-
self.exec(nested ? `RELEASE ${SAVEPOINT}` : "COMMIT");
|
|
175
|
-
return result;
|
|
176
|
-
} catch (error) {
|
|
177
|
-
if (nested) {
|
|
178
|
-
self.exec(`ROLLBACK TO ${SAVEPOINT}`);
|
|
179
|
-
self.exec(`RELEASE ${SAVEPOINT}`);
|
|
180
|
-
} else {
|
|
181
|
-
self.exec("ROLLBACK");
|
|
182
|
-
}
|
|
183
|
-
throw error;
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
return wrapped;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return NodeSqliteDatabase;
|
|
190
|
-
}
|
|
191
|
-
var isBun, bunSpec, nodeSpec, sqliteModule, DatabaseImpl, Database;
|
|
192
|
-
var init_sqlite = __esm(async () => {
|
|
193
|
-
isBun = typeof process !== "undefined" && typeof process.versions?.bun === "string";
|
|
194
|
-
bunSpec = "bun:" + "sqlite";
|
|
195
|
-
nodeSpec = "node:" + "sqlite";
|
|
196
|
-
sqliteModule = isBun ? await import(bunSpec) : await import(nodeSpec);
|
|
197
|
-
DatabaseImpl = isBun ? sqliteModule.Database : buildNodeSqliteDatabaseClass(sqliteModule.DatabaseSync);
|
|
198
|
-
Database = DatabaseImpl;
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
// ../plugin/src/shared/sqlite-helpers.ts
|
|
202
|
-
function closeQuietly(db) {
|
|
203
|
-
if (!db)
|
|
204
|
-
return;
|
|
205
|
-
try {
|
|
206
|
-
db.close();
|
|
207
|
-
} catch {}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
49
|
// ../../node_modules/.bun/esprima@4.0.1/node_modules/esprima/dist/esprima.js
|
|
211
50
|
var require_esprima = __commonJS((exports, module) => {
|
|
212
51
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
@@ -7964,57 +7803,53 @@ var require_src2 = __commonJS((exports, module) => {
|
|
|
7964
7803
|
};
|
|
7965
7804
|
});
|
|
7966
7805
|
|
|
7967
|
-
// ../plugin/src/
|
|
7968
|
-
import { existsSync as
|
|
7969
|
-
import { join as
|
|
7970
|
-
|
|
7971
|
-
|
|
7806
|
+
// ../plugin/src/features/magic-context/storage-db.ts
|
|
7807
|
+
import { copyFileSync, cpSync, existsSync as existsSync3, mkdirSync as mkdirSync2 } from "node:fs";
|
|
7808
|
+
import { dirname as dirname2, join as join4 } from "node:path";
|
|
7809
|
+
|
|
7810
|
+
// ../plugin/src/shared/data-path.ts
|
|
7811
|
+
import * as os from "node:os";
|
|
7812
|
+
import * as path from "node:path";
|
|
7813
|
+
|
|
7814
|
+
// ../plugin/src/shared/harness.ts
|
|
7815
|
+
var currentHarness = "opencode";
|
|
7816
|
+
var harnessLocked = false;
|
|
7817
|
+
function setHarness(value) {
|
|
7818
|
+
if (harnessLocked && currentHarness !== value) {
|
|
7819
|
+
throw new Error(`Magic Context: harness already locked to "${currentHarness}"; cannot change to "${value}"`);
|
|
7820
|
+
}
|
|
7821
|
+
currentHarness = value;
|
|
7822
|
+
harnessLocked = true;
|
|
7972
7823
|
}
|
|
7973
|
-
function
|
|
7974
|
-
return
|
|
7824
|
+
function getHarness() {
|
|
7825
|
+
return currentHarness;
|
|
7975
7826
|
}
|
|
7976
|
-
|
|
7977
|
-
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
try {
|
|
7981
|
-
closeQuietly(cachedReadOnlyDb.db);
|
|
7982
|
-
} catch (error51) {
|
|
7983
|
-
log("[magic-context] failed to close cached OpenCode read-only DB:", error51);
|
|
7984
|
-
} finally {
|
|
7985
|
-
cachedReadOnlyDb = null;
|
|
7986
|
-
}
|
|
7827
|
+
|
|
7828
|
+
// ../plugin/src/shared/data-path.ts
|
|
7829
|
+
function getDataDir() {
|
|
7830
|
+
return process.env.XDG_DATA_HOME ?? path.join(os.homedir(), ".local", "share");
|
|
7987
7831
|
}
|
|
7988
|
-
function
|
|
7989
|
-
|
|
7990
|
-
if (cachedReadOnlyDb?.path === dbPath) {
|
|
7991
|
-
return cachedReadOnlyDb.db;
|
|
7992
|
-
}
|
|
7993
|
-
closeCachedReadOnlyDb();
|
|
7994
|
-
const db = new Database(dbPath, { readonly: true });
|
|
7995
|
-
cachedReadOnlyDb = { path: dbPath, db };
|
|
7996
|
-
return db;
|
|
7832
|
+
function getMagicContextTempDir(harness = getHarness()) {
|
|
7833
|
+
return path.join(os.tmpdir(), harness, "magic-context");
|
|
7997
7834
|
}
|
|
7998
|
-
function
|
|
7999
|
-
return
|
|
7835
|
+
function getMagicContextLogPath(harness = getHarness()) {
|
|
7836
|
+
return path.join(getMagicContextTempDir(harness), "magic-context.log");
|
|
8000
7837
|
}
|
|
8001
|
-
function
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
|
|
8005
|
-
return
|
|
7838
|
+
function getProjectMagicContextDir(directory) {
|
|
7839
|
+
return path.join(directory, ".magic-context");
|
|
7840
|
+
}
|
|
7841
|
+
function getProjectMagicContextHistorianDir(directory) {
|
|
7842
|
+
return path.join(getProjectMagicContextDir(directory), "historian");
|
|
7843
|
+
}
|
|
7844
|
+
function getOpenCodeStorageDir() {
|
|
7845
|
+
return path.join(getDataDir(), "opencode", "storage");
|
|
7846
|
+
}
|
|
7847
|
+
function getMagicContextStorageDir() {
|
|
7848
|
+
return path.join(getDataDir(), "cortexkit", "magic-context");
|
|
7849
|
+
}
|
|
7850
|
+
function getLegacyOpenCodeMagicContextStorageDir() {
|
|
7851
|
+
return path.join(getOpenCodeStorageDir(), "plugin", "magic-context");
|
|
8006
7852
|
}
|
|
8007
|
-
var cachedReadOnlyDb = null;
|
|
8008
|
-
var init_read_session_db = __esm(async () => {
|
|
8009
|
-
init_data_path();
|
|
8010
|
-
init_logger();
|
|
8011
|
-
await init_sqlite();
|
|
8012
|
-
});
|
|
8013
|
-
|
|
8014
|
-
// ../plugin/src/features/magic-context/storage-db.ts
|
|
8015
|
-
init_data_path();
|
|
8016
|
-
import { copyFileSync, cpSync, existsSync as existsSync3, mkdirSync as mkdirSync2 } from "node:fs";
|
|
8017
|
-
import { dirname as dirname2, join as join4 } from "node:path";
|
|
8018
7853
|
|
|
8019
7854
|
// ../plugin/src/shared/error-message.ts
|
|
8020
7855
|
function getErrorMessage(error) {
|
|
@@ -8092,12 +7927,124 @@ function safeString(value) {
|
|
|
8092
7927
|
}
|
|
8093
7928
|
}
|
|
8094
7929
|
|
|
8095
|
-
// ../plugin/src/
|
|
8096
|
-
|
|
8097
|
-
|
|
7930
|
+
// ../plugin/src/shared/logger.ts
|
|
7931
|
+
import * as fs from "node:fs";
|
|
7932
|
+
import * as path2 from "node:path";
|
|
7933
|
+
var isTestEnv = false;
|
|
7934
|
+
var buffer = [];
|
|
7935
|
+
var flushTimer = null;
|
|
7936
|
+
var FLUSH_INTERVAL_MS = 500;
|
|
7937
|
+
var BUFFER_SIZE_LIMIT = 50;
|
|
7938
|
+
var lastEnsuredDir = null;
|
|
7939
|
+
function ensureDir(filePath) {
|
|
7940
|
+
const dir = path2.dirname(filePath);
|
|
7941
|
+
if (dir === lastEnsuredDir)
|
|
7942
|
+
return;
|
|
7943
|
+
try {
|
|
7944
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
7945
|
+
lastEnsuredDir = dir;
|
|
7946
|
+
} catch {}
|
|
7947
|
+
}
|
|
7948
|
+
function flush() {
|
|
7949
|
+
if (flushTimer) {
|
|
7950
|
+
clearTimeout(flushTimer);
|
|
7951
|
+
flushTimer = null;
|
|
7952
|
+
}
|
|
7953
|
+
if (buffer.length === 0)
|
|
7954
|
+
return;
|
|
7955
|
+
const data = buffer.join("");
|
|
7956
|
+
buffer = [];
|
|
7957
|
+
try {
|
|
7958
|
+
const logFile = getMagicContextLogPath();
|
|
7959
|
+
ensureDir(logFile);
|
|
7960
|
+
fs.appendFileSync(logFile, data);
|
|
7961
|
+
} catch {}
|
|
7962
|
+
}
|
|
7963
|
+
function scheduleFlush() {
|
|
7964
|
+
if (flushTimer)
|
|
7965
|
+
return;
|
|
7966
|
+
flushTimer = setTimeout(() => {
|
|
7967
|
+
flushTimer = null;
|
|
7968
|
+
flush();
|
|
7969
|
+
}, FLUSH_INTERVAL_MS);
|
|
7970
|
+
}
|
|
7971
|
+
function log(message, data) {
|
|
7972
|
+
if (isTestEnv)
|
|
7973
|
+
return;
|
|
7974
|
+
try {
|
|
7975
|
+
const timestamp = new Date().toISOString();
|
|
7976
|
+
const serialized = data === undefined ? "" : data instanceof Error ? ` ${data.message}${data.stack ? `
|
|
7977
|
+
${data.stack}` : ""}` : ` ${JSON.stringify(data)}`;
|
|
7978
|
+
buffer.push(`[${timestamp}] ${message}${serialized}
|
|
7979
|
+
`);
|
|
7980
|
+
if (buffer.length >= BUFFER_SIZE_LIMIT) {
|
|
7981
|
+
flush();
|
|
7982
|
+
} else {
|
|
7983
|
+
scheduleFlush();
|
|
7984
|
+
}
|
|
7985
|
+
} catch {}
|
|
7986
|
+
}
|
|
7987
|
+
function sessionLog(sessionId, message, data) {
|
|
7988
|
+
log(`[magic-context][${sessionId}] ${message}`, data);
|
|
7989
|
+
}
|
|
7990
|
+
if (!isTestEnv) {
|
|
7991
|
+
process.on("exit", flush);
|
|
7992
|
+
}
|
|
7993
|
+
|
|
7994
|
+
// ../plugin/src/shared/sqlite.ts
|
|
7995
|
+
var isBun = typeof process !== "undefined" && typeof process.versions?.bun === "string";
|
|
7996
|
+
var bunSpec = "bun:" + "sqlite";
|
|
7997
|
+
var nodeSpec = "node:" + "sqlite";
|
|
7998
|
+
var sqliteModule = isBun ? await import(bunSpec) : await import(nodeSpec);
|
|
7999
|
+
var DatabaseImpl = isBun ? sqliteModule.Database : buildNodeSqliteDatabaseClass(sqliteModule.DatabaseSync);
|
|
8000
|
+
function buildNodeSqliteDatabaseClass(DatabaseSync) {
|
|
8001
|
+
const SAVEPOINT = "mc_tx_sp";
|
|
8002
|
+
|
|
8003
|
+
class NodeSqliteDatabase extends DatabaseSync {
|
|
8004
|
+
constructor(filename, options) {
|
|
8005
|
+
const translated = { ...options };
|
|
8006
|
+
if (options && "readonly" in options) {
|
|
8007
|
+
translated.readOnly = options.readonly;
|
|
8008
|
+
delete translated.readonly;
|
|
8009
|
+
}
|
|
8010
|
+
super(typeof filename === "string" ? filename : ":memory:", translated);
|
|
8011
|
+
}
|
|
8012
|
+
transaction(fn) {
|
|
8013
|
+
const self = this;
|
|
8014
|
+
const wrapped = function(...args) {
|
|
8015
|
+
const nested = self.isTransaction === true;
|
|
8016
|
+
self.exec(nested ? `SAVEPOINT ${SAVEPOINT}` : "BEGIN");
|
|
8017
|
+
try {
|
|
8018
|
+
const result = fn.apply(this, args);
|
|
8019
|
+
self.exec(nested ? `RELEASE ${SAVEPOINT}` : "COMMIT");
|
|
8020
|
+
return result;
|
|
8021
|
+
} catch (error) {
|
|
8022
|
+
if (nested) {
|
|
8023
|
+
self.exec(`ROLLBACK TO ${SAVEPOINT}`);
|
|
8024
|
+
self.exec(`RELEASE ${SAVEPOINT}`);
|
|
8025
|
+
} else {
|
|
8026
|
+
self.exec("ROLLBACK");
|
|
8027
|
+
}
|
|
8028
|
+
throw error;
|
|
8029
|
+
}
|
|
8030
|
+
};
|
|
8031
|
+
return wrapped;
|
|
8032
|
+
}
|
|
8033
|
+
}
|
|
8034
|
+
return NodeSqliteDatabase;
|
|
8035
|
+
}
|
|
8036
|
+
var Database = DatabaseImpl;
|
|
8037
|
+
|
|
8038
|
+
// ../plugin/src/shared/sqlite-helpers.ts
|
|
8039
|
+
function closeQuietly(db) {
|
|
8040
|
+
if (!db)
|
|
8041
|
+
return;
|
|
8042
|
+
try {
|
|
8043
|
+
db.close();
|
|
8044
|
+
} catch {}
|
|
8045
|
+
}
|
|
8098
8046
|
|
|
8099
8047
|
// ../plugin/src/features/magic-context/key-files/project-key-files.ts
|
|
8100
|
-
init_logger();
|
|
8101
8048
|
import { createHash } from "node:crypto";
|
|
8102
8049
|
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
8103
8050
|
import { join as join2, resolve, sep } from "node:path";
|
|
@@ -8214,7 +8161,6 @@ function isRelativeProjectFile(projectPath, relativePath) {
|
|
|
8214
8161
|
}
|
|
8215
8162
|
|
|
8216
8163
|
// ../plugin/src/features/magic-context/migrations.ts
|
|
8217
|
-
init_logger();
|
|
8218
8164
|
function tableExists(db, name) {
|
|
8219
8165
|
return Boolean(db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = ?").get(name));
|
|
8220
8166
|
}
|
|
@@ -8948,6 +8894,28 @@ var MIGRATIONS = [
|
|
|
8948
8894
|
db.exec("ALTER TABLE notes ADD COLUMN anchor_ordinal INTEGER");
|
|
8949
8895
|
}
|
|
8950
8896
|
}
|
|
8897
|
+
},
|
|
8898
|
+
{
|
|
8899
|
+
version: 30,
|
|
8900
|
+
description: "HARD-bust m[0] markers: cached system/tool-set/model identity",
|
|
8901
|
+
up: (db) => {
|
|
8902
|
+
const hasSessionMeta = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='session_meta' LIMIT 1").get();
|
|
8903
|
+
if (!hasSessionMeta)
|
|
8904
|
+
return;
|
|
8905
|
+
ensureColumn(db, "session_meta", "cached_m0_system_hash", "TEXT");
|
|
8906
|
+
ensureColumn(db, "session_meta", "cached_m0_tool_set_hash", "TEXT");
|
|
8907
|
+
ensureColumn(db, "session_meta", "cached_m0_model_key", "TEXT");
|
|
8908
|
+
const columns = new Set(db.prepare("PRAGMA table_info(session_meta)").all().map((column) => column.name));
|
|
8909
|
+
if (columns.has("cached_m0_bytes")) {
|
|
8910
|
+
db.prepare(`UPDATE session_meta SET
|
|
8911
|
+
cached_m0_bytes = NULL,
|
|
8912
|
+
cached_m1_bytes = NULL,
|
|
8913
|
+
cached_m0_materialized_at = NULL,
|
|
8914
|
+
cached_m0_system_hash = NULL,
|
|
8915
|
+
cached_m0_tool_set_hash = NULL,
|
|
8916
|
+
cached_m0_model_key = NULL`).run();
|
|
8917
|
+
}
|
|
8918
|
+
}
|
|
8951
8919
|
}
|
|
8952
8920
|
];
|
|
8953
8921
|
var LATEST_MIGRATION_VERSION = MIGRATIONS.reduce((max, m) => Math.max(max, m.version), 0);
|
|
@@ -141663,8 +141631,6 @@ function loadToolDefinitionMeasurements(db) {
|
|
|
141663
141631
|
}
|
|
141664
141632
|
|
|
141665
141633
|
// ../plugin/src/features/magic-context/tool-owner-backfill.ts
|
|
141666
|
-
init_data_path();
|
|
141667
|
-
init_logger();
|
|
141668
141634
|
import { existsSync as existsSync2 } from "node:fs";
|
|
141669
141635
|
import { join as join3 } from "node:path";
|
|
141670
141636
|
var LEASE_DURATION_MS = 5 * 60 * 1000;
|
|
@@ -141912,7 +141878,7 @@ var databases = new Map;
|
|
|
141912
141878
|
var persistenceByDatabase = new WeakMap;
|
|
141913
141879
|
var persistenceErrorByDatabase = new WeakMap;
|
|
141914
141880
|
var lastSchemaFenceRejection = null;
|
|
141915
|
-
var LATEST_SUPPORTED_VERSION =
|
|
141881
|
+
var LATEST_SUPPORTED_VERSION = 30;
|
|
141916
141882
|
function resolveDatabasePath(dbPathOverride) {
|
|
141917
141883
|
if (dbPathOverride) {
|
|
141918
141884
|
return { dbDir: dirname2(dbPathOverride), dbPath: dbPathOverride };
|
|
@@ -142377,6 +142343,9 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
142377
142343
|
cached_m0_materialized_at INTEGER,
|
|
142378
142344
|
cached_m0_session_facts_version INTEGER,
|
|
142379
142345
|
cached_m0_upgrade_state TEXT,
|
|
142346
|
+
cached_m0_system_hash TEXT,
|
|
142347
|
+
cached_m0_tool_set_hash TEXT,
|
|
142348
|
+
cached_m0_model_key TEXT,
|
|
142380
142349
|
cached_m0_last_baseline_end_message_id TEXT,
|
|
142381
142350
|
upgrade_reminded_at INTEGER,
|
|
142382
142351
|
pi_stable_id_scheme INTEGER
|
|
@@ -142568,6 +142537,9 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
142568
142537
|
ensureColumn(db, "session_meta", "cached_m0_materialized_at", "INTEGER");
|
|
142569
142538
|
ensureColumn(db, "session_meta", "cached_m0_session_facts_version", "INTEGER");
|
|
142570
142539
|
ensureColumn(db, "session_meta", "cached_m0_upgrade_state", "TEXT");
|
|
142540
|
+
ensureColumn(db, "session_meta", "cached_m0_system_hash", "TEXT");
|
|
142541
|
+
ensureColumn(db, "session_meta", "cached_m0_tool_set_hash", "TEXT");
|
|
142542
|
+
ensureColumn(db, "session_meta", "cached_m0_model_key", "TEXT");
|
|
142571
142543
|
ensureColumn(db, "session_meta", "cached_m0_last_baseline_end_message_id", "TEXT");
|
|
142572
142544
|
ensureColumn(db, "session_meta", "upgrade_reminded_at", "INTEGER");
|
|
142573
142545
|
db.exec(`
|
|
@@ -142763,9 +142735,6 @@ function openDatabase(dbPathOrOptions) {
|
|
|
142763
142735
|
}
|
|
142764
142736
|
}
|
|
142765
142737
|
|
|
142766
|
-
// src/subagent-entry.ts
|
|
142767
|
-
init_logger();
|
|
142768
|
-
|
|
142769
142738
|
// src/config/index.ts
|
|
142770
142739
|
import { existsSync as existsSync5, readFileSync as readFileSync3 } from "node:fs";
|
|
142771
142740
|
import { homedir as homedir3 } from "node:os";
|
|
@@ -157350,6 +157319,7 @@ var MagicContextConfigSchema = exports_external.object({
|
|
|
157350
157319
|
model: DEFAULT_LOCAL_EMBEDDING_MODEL
|
|
157351
157320
|
}).describe("Embedding provider configuration"),
|
|
157352
157321
|
temporal_awareness: exports_external.boolean().default(true).describe('Inject wall-clock gap markers (<!-- +Xm -->) between user messages where > 5 min elapsed since the previous message, and add start/end date attributes on compartments. Gives the agent a sense of session pacing and "how long ago" across multi-day sessions. Graduated from experimental.temporal_awareness; default: true (set false to opt out).'),
|
|
157322
|
+
keep_subagents: exports_external.boolean().default(false).describe("Debug: keep the child sessions Magic Context spawns for its own subagents (historian, dreamer, sidekick, memory-migration) instead of deleting them on success. Useful for short-term inspection/data collection — their full transcript (prompt, tool calls, token usage, output) stays in the host session store. Kept sessions accumulate until manually cleared; leave false for normal use. Requires a restart to take effect."),
|
|
157353
157323
|
caveman_text_compression: exports_external.object({
|
|
157354
157324
|
enabled: exports_external.boolean().default(false).describe("Apply deterministic caveman-style text compression to old conversation text. Only active when ctx_reduce_enabled=false. Compresses user/assistant text in oldest-first tiers: ultra (oldest 20%), full, lite, untouched (newest 40%)."),
|
|
157355
157325
|
min_chars: exports_external.number().min(100).max(1e4).default(500).describe("Text parts shorter than this (characters) stay untouched. Min 100, max 10000. Default: 500.")
|
|
@@ -157763,9 +157733,6 @@ function loadPiConfigDetailed(opts = {}) {
|
|
|
157763
157733
|
};
|
|
157764
157734
|
}
|
|
157765
157735
|
|
|
157766
|
-
// ../plugin/src/features/magic-context/memory/embedding.ts
|
|
157767
|
-
init_logger();
|
|
157768
|
-
|
|
157769
157736
|
// ../plugin/src/features/magic-context/memory/cosine-similarity.ts
|
|
157770
157737
|
function cosineSimilarity(a, b) {
|
|
157771
157738
|
if (a.length !== b.length) {
|
|
@@ -157821,8 +157788,6 @@ import { mkdirSync as mkdirSync3 } from "node:fs";
|
|
|
157821
157788
|
import { open, stat, unlink, writeFile } from "node:fs/promises";
|
|
157822
157789
|
import { dirname as dirname4, join as join6 } from "node:path";
|
|
157823
157790
|
import { pathToFileURL } from "node:url";
|
|
157824
|
-
init_data_path();
|
|
157825
|
-
init_logger();
|
|
157826
157791
|
var LOCK_POLL_MS = 150;
|
|
157827
157792
|
var STALE_LOCK_MS = 3 * 60000;
|
|
157828
157793
|
var MAX_LOCK_WAIT_MS = 5 * 60000;
|
|
@@ -158158,7 +158123,6 @@ class LocalEmbeddingProvider {
|
|
|
158158
158123
|
}
|
|
158159
158124
|
|
|
158160
158125
|
// ../plugin/src/features/magic-context/memory/embedding-openai.ts
|
|
158161
|
-
init_logger();
|
|
158162
158126
|
function normalizeEndpoint2(endpoint) {
|
|
158163
158127
|
return endpoint?.trim().replace(/\/+$/, "") ?? "";
|
|
158164
158128
|
}
|
|
@@ -158449,7 +158413,6 @@ function getDistinctStoredModelIds(db, projectPath) {
|
|
|
158449
158413
|
|
|
158450
158414
|
// ../plugin/src/features/magic-context/project-embedding-registry.ts
|
|
158451
158415
|
import { createHash as createHash3, randomUUID } from "node:crypto";
|
|
158452
|
-
init_logger();
|
|
158453
158416
|
|
|
158454
158417
|
// ../plugin/src/features/magic-context/git-commits/storage-git-commit-embeddings.ts
|
|
158455
158418
|
var saveStatements = new WeakMap;
|
|
@@ -159187,7 +159150,6 @@ function hasGitDir(canonical) {
|
|
|
159187
159150
|
|
|
159188
159151
|
// ../plugin/src/plugin/embedding-bootstrap-helpers.ts
|
|
159189
159152
|
import { createHash as createHash5 } from "node:crypto";
|
|
159190
|
-
init_logger();
|
|
159191
159153
|
var EMBEDDING_AFFECTING_KEYS = new Set([
|
|
159192
159154
|
"embedding.api_key",
|
|
159193
159155
|
"embedding.endpoint",
|
|
@@ -159275,6 +159237,7 @@ async function ensureProjectRegisteredFromPiDirectory(directory, db) {
|
|
|
159275
159237
|
};
|
|
159276
159238
|
registerProjectEmbeddingAndMaybeWipe(db, projectIdentity, detailed.config.embedding, features, directory);
|
|
159277
159239
|
}
|
|
159240
|
+
|
|
159278
159241
|
// ../plugin/src/features/magic-context/compartment-lease.ts
|
|
159279
159242
|
var COMPARTMENT_LEASE_TTL_MS = 5 * 60 * 1000;
|
|
159280
159243
|
var COMPARTMENT_LEASE_RENEWAL_MS = 60 * 1000;
|
|
@@ -159368,6 +159331,9 @@ var SESSION_META_SELECT_COLUMNS = [
|
|
|
159368
159331
|
"cached_m0_materialized_at",
|
|
159369
159332
|
"cached_m0_session_facts_version",
|
|
159370
159333
|
"cached_m0_upgrade_state",
|
|
159334
|
+
"cached_m0_system_hash",
|
|
159335
|
+
"cached_m0_tool_set_hash",
|
|
159336
|
+
"cached_m0_model_key",
|
|
159371
159337
|
"last_observed_model_key",
|
|
159372
159338
|
"upgrade_reminded_at",
|
|
159373
159339
|
"pi_stable_id_scheme"
|
|
@@ -159404,6 +159370,9 @@ var META_COLUMNS = {
|
|
|
159404
159370
|
cachedM0MaterializedAt: "cached_m0_materialized_at",
|
|
159405
159371
|
cachedM0SessionFactsVersion: "cached_m0_session_facts_version",
|
|
159406
159372
|
cachedM0UpgradeState: "cached_m0_upgrade_state",
|
|
159373
|
+
cachedM0SystemHash: "cached_m0_system_hash",
|
|
159374
|
+
cachedM0ToolSetHash: "cached_m0_tool_set_hash",
|
|
159375
|
+
cachedM0ModelKey: "cached_m0_model_key",
|
|
159407
159376
|
lastObservedModelKey: "last_observed_model_key",
|
|
159408
159377
|
upgradeRemindedAt: "upgrade_reminded_at",
|
|
159409
159378
|
piStableIdScheme: "pi_stable_id_scheme"
|
|
@@ -159446,7 +159415,7 @@ function isSessionMetaRow(row) {
|
|
|
159446
159415
|
if (row === null || typeof row !== "object")
|
|
159447
159416
|
return false;
|
|
159448
159417
|
const r = row;
|
|
159449
|
-
return typeof r.session_id === "string" && typeof r.last_response_time === "number" && isStringOrNull(r.cache_ttl) && typeof r.counter === "number" && typeof r.last_nudge_tokens === "number" && isStringOrNull(r.last_nudge_band) && isStringOrNull(r.last_transform_error) && typeof r.is_subagent === "number" && typeof r.last_context_percentage === "number" && typeof r.last_input_tokens === "number" && isNumberOrNull(r.observed_safe_input_tokens) && isNumberOrNull(r.cache_alert_sent) && isNumberOrNull(r.times_execute_threshold_reached) && isNumberOrNull(r.compartment_in_progress) && (r.system_prompt_hash === null || typeof r.system_prompt_hash === "string" || typeof r.system_prompt_hash === "number") && isNumberOrNull(r.system_prompt_tokens) && isNumberOrNull(r.conversation_tokens) && isNumberOrNull(r.tool_call_tokens) && isNumberOrNull(r.cleared_reasoning_through_tag) && isStringOrNull(r.last_todo_state) && isBlobOrNull(r.cached_m0_bytes) && isBlobOrNull(r.cached_m1_bytes) && isNumberOrNull(r.cached_m0_project_memory_epoch) && isNumberOrNull(r.cached_m0_project_user_profile_version) && isNumberOrNull(r.cached_m0_max_compartment_seq) && isNumberOrNull(r.cached_m0_max_memory_id) && isNumberOrNull(r.cached_m0_max_mutation_id) && isNumberOrNull(r.cached_m0_max_memory_mutation_id) && isStringOrNull(r.cached_m0_project_docs_hash) && isNumberOrNull(r.cached_m0_materialized_at) && isNumberOrNull(r.cached_m0_session_facts_version) && isStringOrNull(r.cached_m0_upgrade_state) && isStringOrNull(r.last_observed_model_key) && isNumberOrNull(r.upgrade_reminded_at) && isNumberOrNull(r.pi_stable_id_scheme);
|
|
159418
|
+
return typeof r.session_id === "string" && typeof r.last_response_time === "number" && isStringOrNull(r.cache_ttl) && typeof r.counter === "number" && typeof r.last_nudge_tokens === "number" && isStringOrNull(r.last_nudge_band) && isStringOrNull(r.last_transform_error) && typeof r.is_subagent === "number" && typeof r.last_context_percentage === "number" && typeof r.last_input_tokens === "number" && isNumberOrNull(r.observed_safe_input_tokens) && isNumberOrNull(r.cache_alert_sent) && isNumberOrNull(r.times_execute_threshold_reached) && isNumberOrNull(r.compartment_in_progress) && (r.system_prompt_hash === null || typeof r.system_prompt_hash === "string" || typeof r.system_prompt_hash === "number") && isNumberOrNull(r.system_prompt_tokens) && isNumberOrNull(r.conversation_tokens) && isNumberOrNull(r.tool_call_tokens) && isNumberOrNull(r.cleared_reasoning_through_tag) && isStringOrNull(r.last_todo_state) && isBlobOrNull(r.cached_m0_bytes) && isBlobOrNull(r.cached_m1_bytes) && isNumberOrNull(r.cached_m0_project_memory_epoch) && isNumberOrNull(r.cached_m0_project_user_profile_version) && isNumberOrNull(r.cached_m0_max_compartment_seq) && isNumberOrNull(r.cached_m0_max_memory_id) && isNumberOrNull(r.cached_m0_max_mutation_id) && isNumberOrNull(r.cached_m0_max_memory_mutation_id) && isStringOrNull(r.cached_m0_project_docs_hash) && isNumberOrNull(r.cached_m0_materialized_at) && isNumberOrNull(r.cached_m0_session_facts_version) && isStringOrNull(r.cached_m0_upgrade_state) && isStringOrNull(r.cached_m0_system_hash) && isStringOrNull(r.cached_m0_tool_set_hash) && isStringOrNull(r.cached_m0_model_key) && isStringOrNull(r.last_observed_model_key) && isNumberOrNull(r.upgrade_reminded_at) && isNumberOrNull(r.pi_stable_id_scheme);
|
|
159450
159419
|
}
|
|
159451
159420
|
function getDefaultSessionMeta(sessionId) {
|
|
159452
159421
|
return {
|
|
@@ -159482,6 +159451,9 @@ function getDefaultSessionMeta(sessionId) {
|
|
|
159482
159451
|
cachedM0MaterializedAt: null,
|
|
159483
159452
|
cachedM0SessionFactsVersion: null,
|
|
159484
159453
|
cachedM0UpgradeState: null,
|
|
159454
|
+
cachedM0SystemHash: null,
|
|
159455
|
+
cachedM0ToolSetHash: null,
|
|
159456
|
+
cachedM0ModelKey: null,
|
|
159485
159457
|
lastObservedModelKey: null,
|
|
159486
159458
|
upgradeRemindedAt: null,
|
|
159487
159459
|
piStableIdScheme: null
|
|
@@ -159533,6 +159505,9 @@ function toSessionMeta(row) {
|
|
|
159533
159505
|
cachedM0MaterializedAt: numOrNull(row.cached_m0_materialized_at),
|
|
159534
159506
|
cachedM0SessionFactsVersion: numOrNull(row.cached_m0_session_facts_version),
|
|
159535
159507
|
cachedM0UpgradeState: stringOrNull(row.cached_m0_upgrade_state),
|
|
159508
|
+
cachedM0SystemHash: stringOrNull(row.cached_m0_system_hash),
|
|
159509
|
+
cachedM0ToolSetHash: stringOrNull(row.cached_m0_tool_set_hash),
|
|
159510
|
+
cachedM0ModelKey: stringOrNull(row.cached_m0_model_key),
|
|
159536
159511
|
lastObservedModelKey: stringOrNull(row.last_observed_model_key),
|
|
159537
159512
|
upgradeRemindedAt: numOrNull(row.upgrade_reminded_at),
|
|
159538
159513
|
piStableIdScheme: numOrNull(row.pi_stable_id_scheme)
|
|
@@ -159552,8 +159527,11 @@ function persistCachedM0(db, sessionId, payload) {
|
|
|
159552
159527
|
cached_m0_project_docs_hash = ?,
|
|
159553
159528
|
cached_m0_materialized_at = ?,
|
|
159554
159529
|
cached_m0_session_facts_version = ?,
|
|
159555
|
-
cached_m0_upgrade_state =
|
|
159556
|
-
|
|
159530
|
+
cached_m0_upgrade_state = ?,
|
|
159531
|
+
cached_m0_system_hash = ?,
|
|
159532
|
+
cached_m0_tool_set_hash = ?,
|
|
159533
|
+
cached_m0_model_key = ?
|
|
159534
|
+
WHERE session_id = ?`).run(Buffer2.from(payload.m0Bytes), payload.projectMemoryEpoch, payload.projectUserProfileVersion, payload.maxCompartmentSeq, payload.maxMemoryId, payload.maxMutationId, payload.maxMemoryMutationId ?? null, payload.m1Bytes ? Buffer2.from(payload.m1Bytes) : null, payload.projectDocsHash, payload.materializedAt, payload.sessionFactsVersion, payload.upgradeState, payload.systemHash ?? "", payload.toolSetHash ?? "", payload.modelKey ?? "", sessionId);
|
|
159557
159535
|
}
|
|
159558
159536
|
function clearCachedM0M1(db, sessionId) {
|
|
159559
159537
|
ensureSessionMetaRow(db, sessionId);
|
|
@@ -159571,6 +159549,9 @@ function clearCachedM0M1(db, sessionId) {
|
|
|
159571
159549
|
["cached_m0_materialized_at", null],
|
|
159572
159550
|
["cached_m0_session_facts_version", null],
|
|
159573
159551
|
["cached_m0_upgrade_state", null],
|
|
159552
|
+
["cached_m0_system_hash", null],
|
|
159553
|
+
["cached_m0_tool_set_hash", null],
|
|
159554
|
+
["cached_m0_model_key", null],
|
|
159574
159555
|
["cached_m0_last_baseline_end_message_id", null],
|
|
159575
159556
|
["memory_block_cache", ""],
|
|
159576
159557
|
["memory_block_count", 0],
|
|
@@ -159777,8 +159758,47 @@ function escapeXmlContent(s) {
|
|
|
159777
159758
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
159778
159759
|
}
|
|
159779
159760
|
|
|
159780
|
-
// ../plugin/src/hooks/magic-context/read-session-
|
|
159781
|
-
|
|
159761
|
+
// ../plugin/src/hooks/magic-context/read-session-db.ts
|
|
159762
|
+
import { existsSync as existsSync6 } from "node:fs";
|
|
159763
|
+
import { join as join7 } from "node:path";
|
|
159764
|
+
function getOpenCodeDbPath() {
|
|
159765
|
+
return join7(getDataDir(), "opencode", "opencode.db");
|
|
159766
|
+
}
|
|
159767
|
+
function openCodeDbExists() {
|
|
159768
|
+
return existsSync6(getOpenCodeDbPath());
|
|
159769
|
+
}
|
|
159770
|
+
var cachedReadOnlyDb = null;
|
|
159771
|
+
function closeCachedReadOnlyDb() {
|
|
159772
|
+
if (!cachedReadOnlyDb) {
|
|
159773
|
+
return;
|
|
159774
|
+
}
|
|
159775
|
+
try {
|
|
159776
|
+
closeQuietly(cachedReadOnlyDb.db);
|
|
159777
|
+
} catch (error51) {
|
|
159778
|
+
log("[magic-context] failed to close cached OpenCode read-only DB:", error51);
|
|
159779
|
+
} finally {
|
|
159780
|
+
cachedReadOnlyDb = null;
|
|
159781
|
+
}
|
|
159782
|
+
}
|
|
159783
|
+
function getReadOnlySessionDb() {
|
|
159784
|
+
const dbPath = getOpenCodeDbPath();
|
|
159785
|
+
if (cachedReadOnlyDb?.path === dbPath) {
|
|
159786
|
+
return cachedReadOnlyDb.db;
|
|
159787
|
+
}
|
|
159788
|
+
closeCachedReadOnlyDb();
|
|
159789
|
+
const db = new Database(dbPath, { readonly: true });
|
|
159790
|
+
cachedReadOnlyDb = { path: dbPath, db };
|
|
159791
|
+
return db;
|
|
159792
|
+
}
|
|
159793
|
+
function withReadOnlySessionDb(fn) {
|
|
159794
|
+
return fn(getReadOnlySessionDb());
|
|
159795
|
+
}
|
|
159796
|
+
function getRawSessionMessageCountFromDb(db, sessionId) {
|
|
159797
|
+
const row = db.prepare(`SELECT COUNT(*) as count FROM message WHERE session_id = ?
|
|
159798
|
+
AND NOT (COALESCE(json_extract(data, '$.summary'), 0) = 1
|
|
159799
|
+
AND COALESCE(json_extract(data, '$.finish'), '') = 'stop')`).get(sessionId);
|
|
159800
|
+
return typeof row?.count === "number" ? row.count : 0;
|
|
159801
|
+
}
|
|
159782
159802
|
|
|
159783
159803
|
// ../plugin/src/hooks/magic-context/read-session-raw.ts
|
|
159784
159804
|
function isRawMessageRow(row) {
|
|
@@ -164673,7 +164693,6 @@ var CATEGORY_DEFAULT_TTL = {
|
|
|
164673
164693
|
KNOWN_ISSUES: 30 * 24 * 60 * 60 * 1000
|
|
164674
164694
|
};
|
|
164675
164695
|
// ../plugin/src/features/magic-context/memory/embedding-backfill.ts
|
|
164676
|
-
init_logger();
|
|
164677
164696
|
async function ensureMemoryEmbeddings(args) {
|
|
164678
164697
|
const snapshot = getProjectEmbeddingSnapshot(args.projectIdentity);
|
|
164679
164698
|
if (!snapshot?.enabled) {
|
|
@@ -164711,9 +164730,6 @@ async function ensureMemoryEmbeddings(args) {
|
|
|
164711
164730
|
}
|
|
164712
164731
|
return args.existingEmbeddings;
|
|
164713
164732
|
}
|
|
164714
|
-
// ../plugin/src/features/magic-context/memory/promotion.ts
|
|
164715
|
-
init_logger();
|
|
164716
|
-
|
|
164717
164733
|
// ../plugin/src/features/magic-context/memory/storage-memory.ts
|
|
164718
164734
|
var COLUMN_MAP = {
|
|
164719
164735
|
id: "id",
|
|
@@ -165613,7 +165629,6 @@ function getMaxMemoryMutationId(db, projectPath) {
|
|
|
165613
165629
|
return row?.max_id ?? null;
|
|
165614
165630
|
}
|
|
165615
165631
|
// ../plugin/src/features/magic-context/storage-meta-persisted.ts
|
|
165616
|
-
init_logger();
|
|
165617
165632
|
var CAS_RETRY_LIMIT = 5;
|
|
165618
165633
|
var AUTO_SEARCH_NO_HINT_REASONS = new Set([
|
|
165619
165634
|
"below-threshold",
|
|
@@ -166076,8 +166091,6 @@ function setSessionWorkMetrics(db, sessionId, newWorkTokens, totalInputTokens) {
|
|
|
166076
166091
|
import { Buffer as Buffer3 } from "node:buffer";
|
|
166077
166092
|
|
|
166078
166093
|
// ../plugin/src/features/magic-context/resolve-subagent-fallback.ts
|
|
166079
|
-
init_logger();
|
|
166080
|
-
await init_read_session_db();
|
|
166081
166094
|
function resolveIsSubagentFromOpenCodeDb(sessionId) {
|
|
166082
166095
|
try {
|
|
166083
166096
|
return withReadOnlySessionDb((openCodeDb) => {
|
|
@@ -166111,6 +166124,9 @@ var SESSION_META_FALLBACK_SELECTS = {
|
|
|
166111
166124
|
cached_m0_materialized_at: "NULL AS cached_m0_materialized_at",
|
|
166112
166125
|
cached_m0_session_facts_version: "NULL AS cached_m0_session_facts_version",
|
|
166113
166126
|
cached_m0_upgrade_state: "NULL AS cached_m0_upgrade_state",
|
|
166127
|
+
cached_m0_system_hash: "NULL AS cached_m0_system_hash",
|
|
166128
|
+
cached_m0_tool_set_hash: "NULL AS cached_m0_tool_set_hash",
|
|
166129
|
+
cached_m0_model_key: "NULL AS cached_m0_model_key",
|
|
166114
166130
|
last_observed_model_key: "NULL AS last_observed_model_key",
|
|
166115
166131
|
upgrade_reminded_at: "NULL AS upgrade_reminded_at"
|
|
166116
166132
|
};
|
|
@@ -166343,7 +166359,6 @@ function markNoteChecked(db, noteId) {
|
|
|
166343
166359
|
db.prepare("UPDATE notes SET last_checked_at = ?, updated_at = ? WHERE id = ? AND type = 'smart'").run(now, now, noteId);
|
|
166344
166360
|
}
|
|
166345
166361
|
// ../plugin/src/features/magic-context/storage-ops.ts
|
|
166346
|
-
init_logger();
|
|
166347
166362
|
var queuePendingOpStatements = new WeakMap;
|
|
166348
166363
|
var getPendingOpsStatements = new WeakMap;
|
|
166349
166364
|
var clearPendingOpsStatements = new WeakMap;
|
|
@@ -166745,7 +166760,6 @@ var ERROR_CLASSES = new Set([
|
|
|
166745
166760
|
"unknown"
|
|
166746
166761
|
]);
|
|
166747
166762
|
// src/tools/ctx-memory.ts
|
|
166748
|
-
init_logger();
|
|
166749
166763
|
var DEFAULT_LIST_LIMIT = 10;
|
|
166750
166764
|
var VALID_CATEGORIES = new Set(CATEGORY_PRIORITY);
|
|
166751
166765
|
function isMemoryCategory2(value) {
|
|
@@ -167462,11 +167476,7 @@ function createCtxReduceTool(deps) {
|
|
|
167462
167476
|
};
|
|
167463
167477
|
}
|
|
167464
167478
|
|
|
167465
|
-
// ../plugin/src/features/magic-context/search.ts
|
|
167466
|
-
init_logger();
|
|
167467
|
-
|
|
167468
167479
|
// ../plugin/src/features/magic-context/git-commits/git-log-reader.ts
|
|
167469
|
-
init_logger();
|
|
167470
167480
|
import { execFile } from "node:child_process";
|
|
167471
167481
|
import { promisify } from "node:util";
|
|
167472
167482
|
var execFileAsync = promisify(execFile);
|
|
@@ -167550,11 +167560,7 @@ ${body}` : subject;
|
|
|
167550
167560
|
}
|
|
167551
167561
|
return commits;
|
|
167552
167562
|
}
|
|
167553
|
-
// ../plugin/src/features/magic-context/git-commits/indexer.ts
|
|
167554
|
-
init_logger();
|
|
167555
|
-
|
|
167556
167563
|
// ../plugin/src/features/magic-context/git-commits/storage-git-commits.ts
|
|
167557
|
-
init_logger();
|
|
167558
167564
|
var insertStatements = new WeakMap;
|
|
167559
167565
|
var existingShasStatements = new WeakMap;
|
|
167560
167566
|
var projectCountStatements = new WeakMap;
|
|
@@ -167767,7 +167773,6 @@ async function embedUnembeddedCommits(db, projectPath) {
|
|
|
167767
167773
|
}
|
|
167768
167774
|
}
|
|
167769
167775
|
// ../plugin/src/features/magic-context/git-commits/search-git-commits.ts
|
|
167770
|
-
init_logger();
|
|
167771
167776
|
var ftsStatements = new WeakMap;
|
|
167772
167777
|
var ftsPlainStatements = new WeakMap;
|
|
167773
167778
|
var getBySHAStatements = new WeakMap;
|
|
@@ -168438,9 +168443,6 @@ class BoundedSessionMap {
|
|
|
168438
168443
|
}
|
|
168439
168444
|
}
|
|
168440
168445
|
|
|
168441
|
-
// ../plugin/src/hooks/magic-context/inject-compartments.ts
|
|
168442
|
-
init_logger();
|
|
168443
|
-
|
|
168444
168446
|
// ../plugin/src/hooks/magic-context/decay-curve.ts
|
|
168445
168447
|
var H50 = 24;
|
|
168446
168448
|
var D = 25;
|
|
@@ -168615,26 +168617,58 @@ import { join as join9, sep as sep2 } from "node:path";
|
|
|
168615
168617
|
var import_comment_json2 = __toESM(require_src2(), 1);
|
|
168616
168618
|
import { existsSync as existsSync7, readFileSync as readFileSync5 } from "node:fs";
|
|
168617
168619
|
import { homedir as homedir4 } from "node:os";
|
|
168618
|
-
import { join as join8 } from "node:path";
|
|
168620
|
+
import { isAbsolute as isAbsolute2, join as join8, resolve as resolve3 } from "node:path";
|
|
168621
|
+
import { fileURLToPath } from "node:url";
|
|
168619
168622
|
var overrideAvailability = null;
|
|
168620
168623
|
function parseConfig(path5) {
|
|
168621
168624
|
if (!existsSync7(path5))
|
|
168622
168625
|
return null;
|
|
168623
168626
|
return import_comment_json2.parse(readFileSync5(path5, "utf-8"));
|
|
168624
168627
|
}
|
|
168625
|
-
|
|
168628
|
+
var AFT_NAME_NEEDLES = ["@cortexkit/aft", "aft-opencode", "aft-pi"];
|
|
168629
|
+
function stringMentionsAft(value) {
|
|
168630
|
+
return AFT_NAME_NEEDLES.some((needle) => value.includes(needle));
|
|
168631
|
+
}
|
|
168632
|
+
function resolveLocalEntryPackageName(value, configDir) {
|
|
168633
|
+
let dir = null;
|
|
168634
|
+
if (value.startsWith("file://")) {
|
|
168635
|
+
try {
|
|
168636
|
+
dir = fileURLToPath(value);
|
|
168637
|
+
} catch {
|
|
168638
|
+
return null;
|
|
168639
|
+
}
|
|
168640
|
+
} else if (value.startsWith("~/")) {
|
|
168641
|
+
dir = join8(homedir4(), value.slice(2));
|
|
168642
|
+
} else if (value.startsWith("/") || value.startsWith("./") || value.startsWith("../")) {
|
|
168643
|
+
dir = isAbsolute2(value) ? value : resolve3(configDir, value);
|
|
168644
|
+
} else {
|
|
168645
|
+
return null;
|
|
168646
|
+
}
|
|
168647
|
+
try {
|
|
168648
|
+
const pkg = JSON.parse(readFileSync5(join8(dir, "package.json"), "utf-8"));
|
|
168649
|
+
return typeof pkg.name === "string" ? pkg.name : null;
|
|
168650
|
+
} catch {
|
|
168651
|
+
return null;
|
|
168652
|
+
}
|
|
168653
|
+
}
|
|
168654
|
+
function entryMatchesAft(entry, configDir) {
|
|
168626
168655
|
const value = Array.isArray(entry) ? entry[0] : entry;
|
|
168627
|
-
|
|
168656
|
+
if (typeof value !== "string")
|
|
168657
|
+
return false;
|
|
168658
|
+
if (stringMentionsAft(value))
|
|
168659
|
+
return true;
|
|
168660
|
+
const name2 = resolveLocalEntryPackageName(value, configDir);
|
|
168661
|
+
return name2 != null && stringMentionsAft(name2);
|
|
168628
168662
|
}
|
|
168629
|
-
function hasAftInArray(value) {
|
|
168630
|
-
return Array.isArray(value) && value.some(entryMatchesAft);
|
|
168663
|
+
function hasAftInArray(value, configDir) {
|
|
168664
|
+
return Array.isArray(value) && value.some((entry) => entryMatchesAft(entry, configDir));
|
|
168631
168665
|
}
|
|
168632
|
-
function hasAftAtKeys(value, keys2) {
|
|
168666
|
+
function hasAftAtKeys(value, keys2, configDir) {
|
|
168633
168667
|
if (!value || typeof value !== "object")
|
|
168634
168668
|
return false;
|
|
168635
168669
|
const record4 = value;
|
|
168636
168670
|
for (const key of keys2) {
|
|
168637
|
-
if (hasAftInArray(record4[key]))
|
|
168671
|
+
if (hasAftInArray(record4[key], configDir))
|
|
168638
168672
|
return true;
|
|
168639
168673
|
}
|
|
168640
168674
|
return false;
|
|
@@ -168651,7 +168685,8 @@ function getAftAvailability() {
|
|
|
168651
168685
|
for (const path5 of opencodePaths) {
|
|
168652
168686
|
try {
|
|
168653
168687
|
const config2 = parseConfig(path5);
|
|
168654
|
-
|
|
168688
|
+
const configDir = join8(path5, "..");
|
|
168689
|
+
if (hasAftAtKeys(config2, ["plugin", "plugins", "mcp", "mcp_servers"], configDir)) {
|
|
168655
168690
|
opencode = true;
|
|
168656
168691
|
break;
|
|
168657
168692
|
}
|
|
@@ -168661,12 +168696,13 @@ function getAftAvailability() {
|
|
|
168661
168696
|
for (const path5 of piPaths) {
|
|
168662
168697
|
try {
|
|
168663
168698
|
const config2 = parseConfig(path5);
|
|
168664
|
-
|
|
168699
|
+
const configDir = join8(path5, "..");
|
|
168700
|
+
if (hasAftAtKeys(config2, ["packages", "extensions"], configDir)) {
|
|
168665
168701
|
pi = true;
|
|
168666
168702
|
break;
|
|
168667
168703
|
}
|
|
168668
168704
|
const agent = config2?.agent;
|
|
168669
|
-
if (hasAftAtKeys(agent, ["packages", "extensions"])) {
|
|
168705
|
+
if (hasAftAtKeys(agent, ["packages", "extensions"], configDir)) {
|
|
168670
168706
|
pi = true;
|
|
168671
168707
|
break;
|
|
168672
168708
|
}
|
|
@@ -168685,7 +168721,6 @@ function isAftAvailable() {
|
|
|
168685
168721
|
}
|
|
168686
168722
|
|
|
168687
168723
|
// ../plugin/src/hooks/magic-context/key-files-block.ts
|
|
168688
|
-
init_logger();
|
|
168689
168724
|
var cachedKeyFilesBySession = new Map;
|
|
168690
168725
|
var staleUpdates = new Map;
|
|
168691
168726
|
function staleKey(update2) {
|
|
@@ -168783,9 +168818,6 @@ ${blocks.join(`
|
|
|
168783
168818
|
return rendered;
|
|
168784
168819
|
}
|
|
168785
168820
|
|
|
168786
|
-
// ../plugin/src/hooks/magic-context/inject-compartments.ts
|
|
168787
|
-
await init_read_session_db();
|
|
168788
|
-
|
|
168789
168821
|
// ../plugin/src/hooks/magic-context/temporal-awareness.ts
|
|
168790
168822
|
var TEMPORAL_AWARENESS_THRESHOLD_SECONDS = 300;
|
|
168791
168823
|
var SECONDS_PER_MINUTE = 60;
|