@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/index.js
CHANGED
|
@@ -46,214 +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 path2 from "node:path";
|
|
65
|
-
function getDataDir() {
|
|
66
|
-
return process.env.XDG_DATA_HOME ?? path2.join(os.homedir(), ".local", "share");
|
|
67
|
-
}
|
|
68
|
-
function getMagicContextTempDir(harness = getHarness()) {
|
|
69
|
-
return path2.join(os.tmpdir(), harness, "magic-context");
|
|
70
|
-
}
|
|
71
|
-
function getMagicContextLogPath(harness = getHarness()) {
|
|
72
|
-
return path2.join(getMagicContextTempDir(harness), "magic-context.log");
|
|
73
|
-
}
|
|
74
|
-
function getProjectMagicContextDir(directory) {
|
|
75
|
-
return path2.join(directory, ".magic-context");
|
|
76
|
-
}
|
|
77
|
-
function getProjectMagicContextHistorianDir(directory) {
|
|
78
|
-
return path2.join(getProjectMagicContextDir(directory), "historian");
|
|
79
|
-
}
|
|
80
|
-
function getOpenCodeStorageDir() {
|
|
81
|
-
return path2.join(getDataDir(), "opencode", "storage");
|
|
82
|
-
}
|
|
83
|
-
function getMagicContextStorageDir() {
|
|
84
|
-
return path2.join(getDataDir(), "cortexkit", "magic-context");
|
|
85
|
-
}
|
|
86
|
-
function getLegacyOpenCodeMagicContextStorageDir() {
|
|
87
|
-
return path2.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 path3 from "node:path";
|
|
94
|
-
function ensureDir(filePath) {
|
|
95
|
-
const dir = path3.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
|
-
// ../plugin/src/hooks/magic-context/read-session-db.ts
|
|
211
|
-
import { existsSync } from "node:fs";
|
|
212
|
-
import { join as join2 } from "node:path";
|
|
213
|
-
function getOpenCodeDbPath() {
|
|
214
|
-
return join2(getDataDir(), "opencode", "opencode.db");
|
|
215
|
-
}
|
|
216
|
-
function openCodeDbExists() {
|
|
217
|
-
return existsSync(getOpenCodeDbPath());
|
|
218
|
-
}
|
|
219
|
-
function closeCachedReadOnlyDb() {
|
|
220
|
-
if (!cachedReadOnlyDb) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
try {
|
|
224
|
-
closeQuietly(cachedReadOnlyDb.db);
|
|
225
|
-
} catch (error) {
|
|
226
|
-
log("[magic-context] failed to close cached OpenCode read-only DB:", error);
|
|
227
|
-
} finally {
|
|
228
|
-
cachedReadOnlyDb = null;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
function getReadOnlySessionDb() {
|
|
232
|
-
const dbPath = getOpenCodeDbPath();
|
|
233
|
-
if (cachedReadOnlyDb?.path === dbPath) {
|
|
234
|
-
return cachedReadOnlyDb.db;
|
|
235
|
-
}
|
|
236
|
-
closeCachedReadOnlyDb();
|
|
237
|
-
const db = new Database(dbPath, { readonly: true });
|
|
238
|
-
cachedReadOnlyDb = { path: dbPath, db };
|
|
239
|
-
return db;
|
|
240
|
-
}
|
|
241
|
-
function withReadOnlySessionDb(fn) {
|
|
242
|
-
return fn(getReadOnlySessionDb());
|
|
243
|
-
}
|
|
244
|
-
function getRawSessionMessageCountFromDb(db, sessionId) {
|
|
245
|
-
const row = db.prepare(`SELECT COUNT(*) as count FROM message WHERE session_id = ?
|
|
246
|
-
AND NOT (COALESCE(json_extract(data, '$.summary'), 0) = 1
|
|
247
|
-
AND COALESCE(json_extract(data, '$.finish'), '') = 'stop')`).get(sessionId);
|
|
248
|
-
return typeof row?.count === "number" ? row.count : 0;
|
|
249
|
-
}
|
|
250
|
-
var cachedReadOnlyDb = null;
|
|
251
|
-
var init_read_session_db = __esm(async () => {
|
|
252
|
-
init_data_path();
|
|
253
|
-
init_logger();
|
|
254
|
-
await init_sqlite();
|
|
255
|
-
});
|
|
256
|
-
|
|
257
49
|
// ../../node_modules/.bun/esprima@4.0.1/node_modules/esprima/dist/esprima.js
|
|
258
50
|
var require_esprima = __commonJS((exports, module) => {
|
|
259
51
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
@@ -8282,8 +8074,115 @@ function hasGitDir(canonical) {
|
|
|
8282
8074
|
}
|
|
8283
8075
|
}
|
|
8284
8076
|
|
|
8285
|
-
// ../plugin/src/
|
|
8286
|
-
|
|
8077
|
+
// ../plugin/src/shared/logger.ts
|
|
8078
|
+
import * as fs from "node:fs";
|
|
8079
|
+
import * as path3 from "node:path";
|
|
8080
|
+
|
|
8081
|
+
// ../plugin/src/shared/data-path.ts
|
|
8082
|
+
import * as os from "node:os";
|
|
8083
|
+
import * as path2 from "node:path";
|
|
8084
|
+
|
|
8085
|
+
// ../plugin/src/shared/harness.ts
|
|
8086
|
+
var currentHarness = "opencode";
|
|
8087
|
+
var harnessLocked = false;
|
|
8088
|
+
function setHarness(value) {
|
|
8089
|
+
if (harnessLocked && currentHarness !== value) {
|
|
8090
|
+
throw new Error(`Magic Context: harness already locked to "${currentHarness}"; cannot change to "${value}"`);
|
|
8091
|
+
}
|
|
8092
|
+
currentHarness = value;
|
|
8093
|
+
harnessLocked = true;
|
|
8094
|
+
}
|
|
8095
|
+
function getHarness() {
|
|
8096
|
+
return currentHarness;
|
|
8097
|
+
}
|
|
8098
|
+
|
|
8099
|
+
// ../plugin/src/shared/data-path.ts
|
|
8100
|
+
function getDataDir() {
|
|
8101
|
+
return process.env.XDG_DATA_HOME ?? path2.join(os.homedir(), ".local", "share");
|
|
8102
|
+
}
|
|
8103
|
+
function getMagicContextTempDir(harness = getHarness()) {
|
|
8104
|
+
return path2.join(os.tmpdir(), harness, "magic-context");
|
|
8105
|
+
}
|
|
8106
|
+
function getMagicContextLogPath(harness = getHarness()) {
|
|
8107
|
+
return path2.join(getMagicContextTempDir(harness), "magic-context.log");
|
|
8108
|
+
}
|
|
8109
|
+
function getProjectMagicContextDir(directory) {
|
|
8110
|
+
return path2.join(directory, ".magic-context");
|
|
8111
|
+
}
|
|
8112
|
+
function getProjectMagicContextHistorianDir(directory) {
|
|
8113
|
+
return path2.join(getProjectMagicContextDir(directory), "historian");
|
|
8114
|
+
}
|
|
8115
|
+
function getOpenCodeStorageDir() {
|
|
8116
|
+
return path2.join(getDataDir(), "opencode", "storage");
|
|
8117
|
+
}
|
|
8118
|
+
function getMagicContextStorageDir() {
|
|
8119
|
+
return path2.join(getDataDir(), "cortexkit", "magic-context");
|
|
8120
|
+
}
|
|
8121
|
+
function getLegacyOpenCodeMagicContextStorageDir() {
|
|
8122
|
+
return path2.join(getOpenCodeStorageDir(), "plugin", "magic-context");
|
|
8123
|
+
}
|
|
8124
|
+
|
|
8125
|
+
// ../plugin/src/shared/logger.ts
|
|
8126
|
+
var isTestEnv = false;
|
|
8127
|
+
var buffer = [];
|
|
8128
|
+
var flushTimer = null;
|
|
8129
|
+
var FLUSH_INTERVAL_MS = 500;
|
|
8130
|
+
var BUFFER_SIZE_LIMIT = 50;
|
|
8131
|
+
var lastEnsuredDir = null;
|
|
8132
|
+
function ensureDir(filePath) {
|
|
8133
|
+
const dir = path3.dirname(filePath);
|
|
8134
|
+
if (dir === lastEnsuredDir)
|
|
8135
|
+
return;
|
|
8136
|
+
try {
|
|
8137
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
8138
|
+
lastEnsuredDir = dir;
|
|
8139
|
+
} catch {}
|
|
8140
|
+
}
|
|
8141
|
+
function flush() {
|
|
8142
|
+
if (flushTimer) {
|
|
8143
|
+
clearTimeout(flushTimer);
|
|
8144
|
+
flushTimer = null;
|
|
8145
|
+
}
|
|
8146
|
+
if (buffer.length === 0)
|
|
8147
|
+
return;
|
|
8148
|
+
const data = buffer.join("");
|
|
8149
|
+
buffer = [];
|
|
8150
|
+
try {
|
|
8151
|
+
const logFile = getMagicContextLogPath();
|
|
8152
|
+
ensureDir(logFile);
|
|
8153
|
+
fs.appendFileSync(logFile, data);
|
|
8154
|
+
} catch {}
|
|
8155
|
+
}
|
|
8156
|
+
function scheduleFlush() {
|
|
8157
|
+
if (flushTimer)
|
|
8158
|
+
return;
|
|
8159
|
+
flushTimer = setTimeout(() => {
|
|
8160
|
+
flushTimer = null;
|
|
8161
|
+
flush();
|
|
8162
|
+
}, FLUSH_INTERVAL_MS);
|
|
8163
|
+
}
|
|
8164
|
+
function log(message, data) {
|
|
8165
|
+
if (isTestEnv)
|
|
8166
|
+
return;
|
|
8167
|
+
try {
|
|
8168
|
+
const timestamp = new Date().toISOString();
|
|
8169
|
+
const serialized = data === undefined ? "" : data instanceof Error ? ` ${data.message}${data.stack ? `
|
|
8170
|
+
${data.stack}` : ""}` : ` ${JSON.stringify(data)}`;
|
|
8171
|
+
buffer.push(`[${timestamp}] ${message}${serialized}
|
|
8172
|
+
`);
|
|
8173
|
+
if (buffer.length >= BUFFER_SIZE_LIMIT) {
|
|
8174
|
+
flush();
|
|
8175
|
+
} else {
|
|
8176
|
+
scheduleFlush();
|
|
8177
|
+
}
|
|
8178
|
+
} catch {}
|
|
8179
|
+
}
|
|
8180
|
+
function sessionLog(sessionId, message, data) {
|
|
8181
|
+
log(`[magic-context][${sessionId}] ${message}`, data);
|
|
8182
|
+
}
|
|
8183
|
+
if (!isTestEnv) {
|
|
8184
|
+
process.on("exit", flush);
|
|
8185
|
+
}
|
|
8287
8186
|
|
|
8288
8187
|
// ../plugin/src/shared/internal-initiator-marker.ts
|
|
8289
8188
|
var OMO_INTERNAL_INITIATOR_MARKER = "<!-- OMO_INTERNAL_INITIATOR -->";
|
|
@@ -8297,8 +8196,102 @@ function removeSystemReminders(text) {
|
|
|
8297
8196
|
return text.replace(/<system-reminder>[\s\S]*?<\/system-reminder>/gi, "").trim();
|
|
8298
8197
|
}
|
|
8299
8198
|
|
|
8300
|
-
// ../plugin/src/hooks/magic-context/read-session-
|
|
8301
|
-
|
|
8199
|
+
// ../plugin/src/hooks/magic-context/read-session-db.ts
|
|
8200
|
+
import { existsSync } from "node:fs";
|
|
8201
|
+
import { join as join2 } from "node:path";
|
|
8202
|
+
|
|
8203
|
+
// ../plugin/src/shared/sqlite.ts
|
|
8204
|
+
var isBun = typeof process !== "undefined" && typeof process.versions?.bun === "string";
|
|
8205
|
+
var bunSpec = "bun:" + "sqlite";
|
|
8206
|
+
var nodeSpec = "node:" + "sqlite";
|
|
8207
|
+
var sqliteModule = isBun ? await import(bunSpec) : await import(nodeSpec);
|
|
8208
|
+
var DatabaseImpl = isBun ? sqliteModule.Database : buildNodeSqliteDatabaseClass(sqliteModule.DatabaseSync);
|
|
8209
|
+
function buildNodeSqliteDatabaseClass(DatabaseSync) {
|
|
8210
|
+
const SAVEPOINT = "mc_tx_sp";
|
|
8211
|
+
|
|
8212
|
+
class NodeSqliteDatabase extends DatabaseSync {
|
|
8213
|
+
constructor(filename, options) {
|
|
8214
|
+
const translated = { ...options };
|
|
8215
|
+
if (options && "readonly" in options) {
|
|
8216
|
+
translated.readOnly = options.readonly;
|
|
8217
|
+
delete translated.readonly;
|
|
8218
|
+
}
|
|
8219
|
+
super(typeof filename === "string" ? filename : ":memory:", translated);
|
|
8220
|
+
}
|
|
8221
|
+
transaction(fn) {
|
|
8222
|
+
const self = this;
|
|
8223
|
+
const wrapped = function(...args) {
|
|
8224
|
+
const nested = self.isTransaction === true;
|
|
8225
|
+
self.exec(nested ? `SAVEPOINT ${SAVEPOINT}` : "BEGIN");
|
|
8226
|
+
try {
|
|
8227
|
+
const result = fn.apply(this, args);
|
|
8228
|
+
self.exec(nested ? `RELEASE ${SAVEPOINT}` : "COMMIT");
|
|
8229
|
+
return result;
|
|
8230
|
+
} catch (error) {
|
|
8231
|
+
if (nested) {
|
|
8232
|
+
self.exec(`ROLLBACK TO ${SAVEPOINT}`);
|
|
8233
|
+
self.exec(`RELEASE ${SAVEPOINT}`);
|
|
8234
|
+
} else {
|
|
8235
|
+
self.exec("ROLLBACK");
|
|
8236
|
+
}
|
|
8237
|
+
throw error;
|
|
8238
|
+
}
|
|
8239
|
+
};
|
|
8240
|
+
return wrapped;
|
|
8241
|
+
}
|
|
8242
|
+
}
|
|
8243
|
+
return NodeSqliteDatabase;
|
|
8244
|
+
}
|
|
8245
|
+
var Database = DatabaseImpl;
|
|
8246
|
+
|
|
8247
|
+
// ../plugin/src/shared/sqlite-helpers.ts
|
|
8248
|
+
function closeQuietly(db) {
|
|
8249
|
+
if (!db)
|
|
8250
|
+
return;
|
|
8251
|
+
try {
|
|
8252
|
+
db.close();
|
|
8253
|
+
} catch {}
|
|
8254
|
+
}
|
|
8255
|
+
|
|
8256
|
+
// ../plugin/src/hooks/magic-context/read-session-db.ts
|
|
8257
|
+
function getOpenCodeDbPath() {
|
|
8258
|
+
return join2(getDataDir(), "opencode", "opencode.db");
|
|
8259
|
+
}
|
|
8260
|
+
function openCodeDbExists() {
|
|
8261
|
+
return existsSync(getOpenCodeDbPath());
|
|
8262
|
+
}
|
|
8263
|
+
var cachedReadOnlyDb = null;
|
|
8264
|
+
function closeCachedReadOnlyDb() {
|
|
8265
|
+
if (!cachedReadOnlyDb) {
|
|
8266
|
+
return;
|
|
8267
|
+
}
|
|
8268
|
+
try {
|
|
8269
|
+
closeQuietly(cachedReadOnlyDb.db);
|
|
8270
|
+
} catch (error) {
|
|
8271
|
+
log("[magic-context] failed to close cached OpenCode read-only DB:", error);
|
|
8272
|
+
} finally {
|
|
8273
|
+
cachedReadOnlyDb = null;
|
|
8274
|
+
}
|
|
8275
|
+
}
|
|
8276
|
+
function getReadOnlySessionDb() {
|
|
8277
|
+
const dbPath = getOpenCodeDbPath();
|
|
8278
|
+
if (cachedReadOnlyDb?.path === dbPath) {
|
|
8279
|
+
return cachedReadOnlyDb.db;
|
|
8280
|
+
}
|
|
8281
|
+
closeCachedReadOnlyDb();
|
|
8282
|
+
const db = new Database(dbPath, { readonly: true });
|
|
8283
|
+
cachedReadOnlyDb = { path: dbPath, db };
|
|
8284
|
+
return db;
|
|
8285
|
+
}
|
|
8286
|
+
function withReadOnlySessionDb(fn) {
|
|
8287
|
+
return fn(getReadOnlySessionDb());
|
|
8288
|
+
}
|
|
8289
|
+
function getRawSessionMessageCountFromDb(db, sessionId) {
|
|
8290
|
+
const row = db.prepare(`SELECT COUNT(*) as count FROM message WHERE session_id = ?
|
|
8291
|
+
AND NOT (COALESCE(json_extract(data, '$.summary'), 0) = 1
|
|
8292
|
+
AND COALESCE(json_extract(data, '$.finish'), '') = 'stop')`).get(sessionId);
|
|
8293
|
+
return typeof row?.count === "number" ? row.count : 0;
|
|
8294
|
+
}
|
|
8302
8295
|
|
|
8303
8296
|
// ../../node_modules/.bun/ai-tokenizer@1.0.6/node_modules/ai-tokenizer/dist/index.js
|
|
8304
8297
|
function _typeof(o) {
|
|
@@ -141342,6 +141335,7 @@ function readSessionChunk(sessionId, tokenBudget, offset = 1, eligibleEndOrdinal
|
|
|
141342
141335
|
toolOnlyRanges
|
|
141343
141336
|
};
|
|
141344
141337
|
}
|
|
141338
|
+
|
|
141345
141339
|
// ../plugin/src/features/magic-context/compression-depth-storage.ts
|
|
141346
141340
|
var incrementDepthStatements = new WeakMap;
|
|
141347
141341
|
var totalDepthStatements = new WeakMap;
|
|
@@ -141745,6 +141739,7 @@ function parseReportedLimit(message) {
|
|
|
141745
141739
|
}
|
|
141746
141740
|
return;
|
|
141747
141741
|
}
|
|
141742
|
+
|
|
141748
141743
|
// ../plugin/src/features/magic-context/compartment-lease.ts
|
|
141749
141744
|
var COMPARTMENT_LEASE_TTL_MS = 5 * 60 * 1000;
|
|
141750
141745
|
var COMPARTMENT_LEASE_RENEWAL_MS = 60 * 1000;
|
|
@@ -141815,6 +141810,9 @@ var SESSION_META_SELECT_COLUMNS = [
|
|
|
141815
141810
|
"cached_m0_materialized_at",
|
|
141816
141811
|
"cached_m0_session_facts_version",
|
|
141817
141812
|
"cached_m0_upgrade_state",
|
|
141813
|
+
"cached_m0_system_hash",
|
|
141814
|
+
"cached_m0_tool_set_hash",
|
|
141815
|
+
"cached_m0_model_key",
|
|
141818
141816
|
"last_observed_model_key",
|
|
141819
141817
|
"upgrade_reminded_at",
|
|
141820
141818
|
"pi_stable_id_scheme"
|
|
@@ -141851,6 +141849,9 @@ var META_COLUMNS = {
|
|
|
141851
141849
|
cachedM0MaterializedAt: "cached_m0_materialized_at",
|
|
141852
141850
|
cachedM0SessionFactsVersion: "cached_m0_session_facts_version",
|
|
141853
141851
|
cachedM0UpgradeState: "cached_m0_upgrade_state",
|
|
141852
|
+
cachedM0SystemHash: "cached_m0_system_hash",
|
|
141853
|
+
cachedM0ToolSetHash: "cached_m0_tool_set_hash",
|
|
141854
|
+
cachedM0ModelKey: "cached_m0_model_key",
|
|
141854
141855
|
lastObservedModelKey: "last_observed_model_key",
|
|
141855
141856
|
upgradeRemindedAt: "upgrade_reminded_at",
|
|
141856
141857
|
piStableIdScheme: "pi_stable_id_scheme"
|
|
@@ -141893,7 +141894,7 @@ function isSessionMetaRow(row) {
|
|
|
141893
141894
|
if (row === null || typeof row !== "object")
|
|
141894
141895
|
return false;
|
|
141895
141896
|
const r = row;
|
|
141896
|
-
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);
|
|
141897
|
+
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);
|
|
141897
141898
|
}
|
|
141898
141899
|
function getDefaultSessionMeta(sessionId) {
|
|
141899
141900
|
return {
|
|
@@ -141929,6 +141930,9 @@ function getDefaultSessionMeta(sessionId) {
|
|
|
141929
141930
|
cachedM0MaterializedAt: null,
|
|
141930
141931
|
cachedM0SessionFactsVersion: null,
|
|
141931
141932
|
cachedM0UpgradeState: null,
|
|
141933
|
+
cachedM0SystemHash: null,
|
|
141934
|
+
cachedM0ToolSetHash: null,
|
|
141935
|
+
cachedM0ModelKey: null,
|
|
141932
141936
|
lastObservedModelKey: null,
|
|
141933
141937
|
upgradeRemindedAt: null,
|
|
141934
141938
|
piStableIdScheme: null
|
|
@@ -141980,6 +141984,9 @@ function toSessionMeta(row) {
|
|
|
141980
141984
|
cachedM0MaterializedAt: numOrNull(row.cached_m0_materialized_at),
|
|
141981
141985
|
cachedM0SessionFactsVersion: numOrNull(row.cached_m0_session_facts_version),
|
|
141982
141986
|
cachedM0UpgradeState: stringOrNull(row.cached_m0_upgrade_state),
|
|
141987
|
+
cachedM0SystemHash: stringOrNull(row.cached_m0_system_hash),
|
|
141988
|
+
cachedM0ToolSetHash: stringOrNull(row.cached_m0_tool_set_hash),
|
|
141989
|
+
cachedM0ModelKey: stringOrNull(row.cached_m0_model_key),
|
|
141983
141990
|
lastObservedModelKey: stringOrNull(row.last_observed_model_key),
|
|
141984
141991
|
upgradeRemindedAt: numOrNull(row.upgrade_reminded_at),
|
|
141985
141992
|
piStableIdScheme: numOrNull(row.pi_stable_id_scheme)
|
|
@@ -141999,8 +142006,11 @@ function persistCachedM0(db, sessionId, payload) {
|
|
|
141999
142006
|
cached_m0_project_docs_hash = ?,
|
|
142000
142007
|
cached_m0_materialized_at = ?,
|
|
142001
142008
|
cached_m0_session_facts_version = ?,
|
|
142002
|
-
cached_m0_upgrade_state =
|
|
142003
|
-
|
|
142009
|
+
cached_m0_upgrade_state = ?,
|
|
142010
|
+
cached_m0_system_hash = ?,
|
|
142011
|
+
cached_m0_tool_set_hash = ?,
|
|
142012
|
+
cached_m0_model_key = ?
|
|
142013
|
+
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);
|
|
142004
142014
|
}
|
|
142005
142015
|
function clearCachedM0M1(db, sessionId) {
|
|
142006
142016
|
ensureSessionMetaRow(db, sessionId);
|
|
@@ -142018,6 +142028,9 @@ function clearCachedM0M1(db, sessionId) {
|
|
|
142018
142028
|
["cached_m0_materialized_at", null],
|
|
142019
142029
|
["cached_m0_session_facts_version", null],
|
|
142020
142030
|
["cached_m0_upgrade_state", null],
|
|
142031
|
+
["cached_m0_system_hash", null],
|
|
142032
|
+
["cached_m0_tool_set_hash", null],
|
|
142033
|
+
["cached_m0_model_key", null],
|
|
142021
142034
|
["cached_m0_last_baseline_end_message_id", null],
|
|
142022
142035
|
["memory_block_cache", ""],
|
|
142023
142036
|
["memory_block_count", 0],
|
|
@@ -142223,11 +142236,7 @@ function escapeXmlAttr(s) {
|
|
|
142223
142236
|
function escapeXmlContent(s) {
|
|
142224
142237
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
142225
142238
|
}
|
|
142226
|
-
// ../plugin/src/features/magic-context/migrations.ts
|
|
142227
|
-
init_logger();
|
|
142228
|
-
|
|
142229
142239
|
// ../plugin/src/features/magic-context/storage-db.ts
|
|
142230
|
-
init_data_path();
|
|
142231
142240
|
import { copyFileSync, cpSync, existsSync as existsSync4, mkdirSync as mkdirSync2 } from "node:fs";
|
|
142232
142241
|
import { dirname as dirname2, join as join5 } from "node:path";
|
|
142233
142242
|
|
|
@@ -142307,12 +142316,7 @@ function safeString(value) {
|
|
|
142307
142316
|
}
|
|
142308
142317
|
}
|
|
142309
142318
|
|
|
142310
|
-
// ../plugin/src/features/magic-context/storage-db.ts
|
|
142311
|
-
init_logger();
|
|
142312
|
-
await init_sqlite();
|
|
142313
|
-
|
|
142314
142319
|
// ../plugin/src/features/magic-context/key-files/project-key-files.ts
|
|
142315
|
-
init_logger();
|
|
142316
142320
|
import { createHash as createHash2 } from "node:crypto";
|
|
142317
142321
|
import { existsSync as existsSync2, readFileSync, realpathSync } from "node:fs";
|
|
142318
142322
|
import { join as join3, resolve, sep } from "node:path";
|
|
@@ -142482,8 +142486,6 @@ function loadToolDefinitionMeasurements(db) {
|
|
|
142482
142486
|
}
|
|
142483
142487
|
|
|
142484
142488
|
// ../plugin/src/features/magic-context/tool-owner-backfill.ts
|
|
142485
|
-
init_data_path();
|
|
142486
|
-
init_logger();
|
|
142487
142489
|
import { existsSync as existsSync3 } from "node:fs";
|
|
142488
142490
|
import { join as join4 } from "node:path";
|
|
142489
142491
|
var LEASE_DURATION_MS = 5 * 60 * 1000;
|
|
@@ -142731,7 +142733,7 @@ var databases = new Map;
|
|
|
142731
142733
|
var persistenceByDatabase = new WeakMap;
|
|
142732
142734
|
var persistenceErrorByDatabase = new WeakMap;
|
|
142733
142735
|
var lastSchemaFenceRejection = null;
|
|
142734
|
-
var LATEST_SUPPORTED_VERSION =
|
|
142736
|
+
var LATEST_SUPPORTED_VERSION = 30;
|
|
142735
142737
|
function resolveDatabasePath(dbPathOverride) {
|
|
142736
142738
|
if (dbPathOverride) {
|
|
142737
142739
|
return { dbDir: dirname2(dbPathOverride), dbPath: dbPathOverride };
|
|
@@ -143196,6 +143198,9 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
143196
143198
|
cached_m0_materialized_at INTEGER,
|
|
143197
143199
|
cached_m0_session_facts_version INTEGER,
|
|
143198
143200
|
cached_m0_upgrade_state TEXT,
|
|
143201
|
+
cached_m0_system_hash TEXT,
|
|
143202
|
+
cached_m0_tool_set_hash TEXT,
|
|
143203
|
+
cached_m0_model_key TEXT,
|
|
143199
143204
|
cached_m0_last_baseline_end_message_id TEXT,
|
|
143200
143205
|
upgrade_reminded_at INTEGER,
|
|
143201
143206
|
pi_stable_id_scheme INTEGER
|
|
@@ -143387,6 +143392,9 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
143387
143392
|
ensureColumn(db, "session_meta", "cached_m0_materialized_at", "INTEGER");
|
|
143388
143393
|
ensureColumn(db, "session_meta", "cached_m0_session_facts_version", "INTEGER");
|
|
143389
143394
|
ensureColumn(db, "session_meta", "cached_m0_upgrade_state", "TEXT");
|
|
143395
|
+
ensureColumn(db, "session_meta", "cached_m0_system_hash", "TEXT");
|
|
143396
|
+
ensureColumn(db, "session_meta", "cached_m0_tool_set_hash", "TEXT");
|
|
143397
|
+
ensureColumn(db, "session_meta", "cached_m0_model_key", "TEXT");
|
|
143390
143398
|
ensureColumn(db, "session_meta", "cached_m0_last_baseline_end_message_id", "TEXT");
|
|
143391
143399
|
ensureColumn(db, "session_meta", "upgrade_reminded_at", "INTEGER");
|
|
143392
143400
|
db.exec(`
|
|
@@ -144316,6 +144324,28 @@ var MIGRATIONS = [
|
|
|
144316
144324
|
db.exec("ALTER TABLE notes ADD COLUMN anchor_ordinal INTEGER");
|
|
144317
144325
|
}
|
|
144318
144326
|
}
|
|
144327
|
+
},
|
|
144328
|
+
{
|
|
144329
|
+
version: 30,
|
|
144330
|
+
description: "HARD-bust m[0] markers: cached system/tool-set/model identity",
|
|
144331
|
+
up: (db) => {
|
|
144332
|
+
const hasSessionMeta = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='session_meta' LIMIT 1").get();
|
|
144333
|
+
if (!hasSessionMeta)
|
|
144334
|
+
return;
|
|
144335
|
+
ensureColumn(db, "session_meta", "cached_m0_system_hash", "TEXT");
|
|
144336
|
+
ensureColumn(db, "session_meta", "cached_m0_tool_set_hash", "TEXT");
|
|
144337
|
+
ensureColumn(db, "session_meta", "cached_m0_model_key", "TEXT");
|
|
144338
|
+
const columns = new Set(db.prepare("PRAGMA table_info(session_meta)").all().map((column) => column.name));
|
|
144339
|
+
if (columns.has("cached_m0_bytes")) {
|
|
144340
|
+
db.prepare(`UPDATE session_meta SET
|
|
144341
|
+
cached_m0_bytes = NULL,
|
|
144342
|
+
cached_m1_bytes = NULL,
|
|
144343
|
+
cached_m0_materialized_at = NULL,
|
|
144344
|
+
cached_m0_system_hash = NULL,
|
|
144345
|
+
cached_m0_tool_set_hash = NULL,
|
|
144346
|
+
cached_m0_model_key = NULL`).run();
|
|
144347
|
+
}
|
|
144348
|
+
}
|
|
144319
144349
|
}
|
|
144320
144350
|
];
|
|
144321
144351
|
var LATEST_MIGRATION_VERSION = MIGRATIONS.reduce((max, m) => Math.max(max, m.version), 0);
|
|
@@ -144614,7 +144644,6 @@ function getMaxMemoryMutationId(db, projectPath) {
|
|
|
144614
144644
|
return row?.max_id ?? null;
|
|
144615
144645
|
}
|
|
144616
144646
|
// ../plugin/src/features/magic-context/storage-meta-persisted.ts
|
|
144617
|
-
init_logger();
|
|
144618
144647
|
var CAS_RETRY_LIMIT = 5;
|
|
144619
144648
|
var AUTO_SEARCH_NO_HINT_REASONS = new Set([
|
|
144620
144649
|
"below-threshold",
|
|
@@ -145077,8 +145106,6 @@ function setSessionWorkMetrics(db, sessionId, newWorkTokens, totalInputTokens) {
|
|
|
145077
145106
|
import { Buffer as Buffer3 } from "node:buffer";
|
|
145078
145107
|
|
|
145079
145108
|
// ../plugin/src/features/magic-context/resolve-subagent-fallback.ts
|
|
145080
|
-
init_logger();
|
|
145081
|
-
await init_read_session_db();
|
|
145082
145109
|
function resolveIsSubagentFromOpenCodeDb(sessionId) {
|
|
145083
145110
|
try {
|
|
145084
145111
|
return withReadOnlySessionDb((openCodeDb) => {
|
|
@@ -145112,6 +145139,9 @@ var SESSION_META_FALLBACK_SELECTS = {
|
|
|
145112
145139
|
cached_m0_materialized_at: "NULL AS cached_m0_materialized_at",
|
|
145113
145140
|
cached_m0_session_facts_version: "NULL AS cached_m0_session_facts_version",
|
|
145114
145141
|
cached_m0_upgrade_state: "NULL AS cached_m0_upgrade_state",
|
|
145142
|
+
cached_m0_system_hash: "NULL AS cached_m0_system_hash",
|
|
145143
|
+
cached_m0_tool_set_hash: "NULL AS cached_m0_tool_set_hash",
|
|
145144
|
+
cached_m0_model_key: "NULL AS cached_m0_model_key",
|
|
145115
145145
|
last_observed_model_key: "NULL AS last_observed_model_key",
|
|
145116
145146
|
upgrade_reminded_at: "NULL AS upgrade_reminded_at"
|
|
145117
145147
|
};
|
|
@@ -145344,7 +145374,6 @@ function markNoteChecked(db, noteId) {
|
|
|
145344
145374
|
db.prepare("UPDATE notes SET last_checked_at = ?, updated_at = ? WHERE id = ? AND type = 'smart'").run(now, now, noteId);
|
|
145345
145375
|
}
|
|
145346
145376
|
// ../plugin/src/features/magic-context/storage-ops.ts
|
|
145347
|
-
init_logger();
|
|
145348
145377
|
var queuePendingOpStatements = new WeakMap;
|
|
145349
145378
|
var getPendingOpsStatements = new WeakMap;
|
|
145350
145379
|
var clearPendingOpsStatements = new WeakMap;
|
|
@@ -145746,7 +145775,6 @@ var ERROR_CLASSES = new Set([
|
|
|
145746
145775
|
"unknown"
|
|
145747
145776
|
]);
|
|
145748
145777
|
// ../plugin/src/features/magic-context/v22-deferred-backfill.ts
|
|
145749
|
-
init_logger();
|
|
145750
145778
|
import { createHash as createHash4 } from "node:crypto";
|
|
145751
145779
|
import { realpathSync as realpathSync2 } from "node:fs";
|
|
145752
145780
|
import path5 from "node:path";
|
|
@@ -146025,8 +146053,6 @@ function getAgentFallbackModels(agent) {
|
|
|
146025
146053
|
}
|
|
146026
146054
|
|
|
146027
146055
|
// ../plugin/src/shared/models-dev-cache.ts
|
|
146028
|
-
init_data_path();
|
|
146029
|
-
init_logger();
|
|
146030
146056
|
import { mkdirSync as mkdirSync3, readFileSync as readFileSync3, renameSync, writeFileSync } from "node:fs";
|
|
146031
146057
|
import { join as join6 } from "node:path";
|
|
146032
146058
|
var MIN_SANE_LIMIT = 20000;
|
|
@@ -146136,7 +146162,6 @@ function resolveHistorianContextLimit(historianModelOverride) {
|
|
|
146136
146162
|
}
|
|
146137
146163
|
|
|
146138
146164
|
// ../plugin/src/hooks/magic-context/event-resolvers.ts
|
|
146139
|
-
init_logger();
|
|
146140
146165
|
var DEFAULT_CONTEXT_LIMIT = 128000;
|
|
146141
146166
|
var MAX_EXECUTE_THRESHOLD = 80;
|
|
146142
146167
|
function resolveCacheTtl(cacheTtl, modelKey) {
|
|
@@ -146269,7 +146294,6 @@ function resolveTokensMatchWithKey(tokensConfig, modelKey) {
|
|
|
146269
146294
|
}
|
|
146270
146295
|
|
|
146271
146296
|
// ../plugin/src/hooks/magic-context/note-nudger.ts
|
|
146272
|
-
init_logger();
|
|
146273
146297
|
var NOTE_NUDGE_COOLDOWN_MS = 15 * 60 * 1000;
|
|
146274
146298
|
var lastDeliveredAt = new Map;
|
|
146275
146299
|
function getPersistedNoteNudgeDeliveredAt(_db, sessionId) {
|
|
@@ -146437,7 +146461,6 @@ function isTodoItem(value) {
|
|
|
146437
146461
|
}
|
|
146438
146462
|
|
|
146439
146463
|
// ../plugin/src/hooks/magic-context/upgrade-reminder.ts
|
|
146440
|
-
init_logger();
|
|
146441
146464
|
var remindedThisProcess = new Set;
|
|
146442
146465
|
var UPGRADE_REMINDER_TEXT = [
|
|
146443
146466
|
"\uD83C\uDF86 Historian V2 is released!",
|
|
@@ -146538,7 +146561,6 @@ async function maybeSendUpgradeReminder(deps, sessionId) {
|
|
|
146538
146561
|
}
|
|
146539
146562
|
|
|
146540
146563
|
// ../plugin/src/shared/announcement.ts
|
|
146541
|
-
init_data_path();
|
|
146542
146564
|
import * as fs2 from "node:fs";
|
|
146543
146565
|
import * as path6 from "node:path";
|
|
146544
146566
|
var ANNOUNCEMENT_VERSION = "0.22.0";
|
|
@@ -146584,9 +146606,14 @@ function shouldShowAnnouncement() {
|
|
|
146584
146606
|
return lastVersion !== ANNOUNCEMENT_VERSION;
|
|
146585
146607
|
}
|
|
146586
146608
|
|
|
146587
|
-
// src/
|
|
146588
|
-
|
|
146589
|
-
|
|
146609
|
+
// ../plugin/src/shared/keep-subagents.ts
|
|
146610
|
+
var keepSubagents = false;
|
|
146611
|
+
function setKeepSubagents(value) {
|
|
146612
|
+
keepSubagents = value === true;
|
|
146613
|
+
}
|
|
146614
|
+
function shouldKeepSubagents() {
|
|
146615
|
+
return keepSubagents;
|
|
146616
|
+
}
|
|
146590
146617
|
|
|
146591
146618
|
// ../plugin/src/shared/resolve-fallbacks.ts
|
|
146592
146619
|
function resolveFallbackChain(agentName, userFallbacks) {
|
|
@@ -146653,9 +146680,6 @@ function isEmptySidekickResult(text) {
|
|
|
146653
146680
|
return trimmed.length === 0 || trimmed === "no relevant memories found";
|
|
146654
146681
|
}
|
|
146655
146682
|
|
|
146656
|
-
// src/commands/ctx-aug.ts
|
|
146657
|
-
init_logger();
|
|
146658
|
-
|
|
146659
146683
|
// src/subagent-runner.ts
|
|
146660
146684
|
import * as childProcess from "node:child_process";
|
|
146661
146685
|
import { existsSync as existsSync6 } from "node:fs";
|
|
@@ -146665,7 +146689,6 @@ import { createInterface } from "node:readline";
|
|
|
146665
146689
|
import { fileURLToPath } from "node:url";
|
|
146666
146690
|
|
|
146667
146691
|
// ../plugin/src/features/magic-context/subagent-token-capture.ts
|
|
146668
|
-
init_logger();
|
|
146669
146692
|
function asNumber(value) {
|
|
146670
146693
|
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
146671
146694
|
}
|
|
@@ -146756,7 +146779,6 @@ function recordChildInvocation(input) {
|
|
|
146756
146779
|
}
|
|
146757
146780
|
|
|
146758
146781
|
// src/subagent-runner.ts
|
|
146759
|
-
init_logger();
|
|
146760
146782
|
function resolveBundledPiCli() {
|
|
146761
146783
|
try {
|
|
146762
146784
|
const require_ = createRequire2(import.meta.url);
|
|
@@ -147529,18 +147551,10 @@ function clearStaleEntries(db, maxAgeMs, projectIdentity) {
|
|
|
147529
147551
|
const result = projectIdentity ? db.prepare("DELETE FROM dream_queue WHERE project_path = ? AND started_at IS NOT NULL AND started_at < ?").run(projectIdentity, cutoff) : db.prepare("DELETE FROM dream_queue WHERE started_at IS NOT NULL AND started_at < ?").run(cutoff);
|
|
147530
147552
|
return result.changes;
|
|
147531
147553
|
}
|
|
147532
|
-
|
|
147533
|
-
// src/commands/ctx-dream.ts
|
|
147534
|
-
init_logger();
|
|
147535
147554
|
// ../plugin/src/features/magic-context/dreamer/runner.ts
|
|
147536
147555
|
import { existsSync as existsSync8 } from "node:fs";
|
|
147537
147556
|
import { join as join11 } from "node:path";
|
|
147538
|
-
|
|
147539
|
-
// ../plugin/src/shared/index.ts
|
|
147540
|
-
init_logger();
|
|
147541
|
-
|
|
147542
147557
|
// ../plugin/src/shared/model-suggestion-retry.ts
|
|
147543
|
-
init_logger();
|
|
147544
147558
|
function extractMessage(error) {
|
|
147545
147559
|
if (typeof error === "string")
|
|
147546
147560
|
return error;
|
|
@@ -147775,40 +147789,66 @@ function extractLatestAssistantText(messages) {
|
|
|
147775
147789
|
`) || null;
|
|
147776
147790
|
}
|
|
147777
147791
|
|
|
147778
|
-
// ../plugin/src/features/magic-context/dreamer/runner.ts
|
|
147779
|
-
init_data_path();
|
|
147780
|
-
init_logger();
|
|
147781
|
-
await init_sqlite();
|
|
147782
|
-
|
|
147783
147792
|
// ../plugin/src/features/magic-context/key-files/identify-key-files.ts
|
|
147784
147793
|
import { readFileSync as readFileSync6 } from "node:fs";
|
|
147785
|
-
import { isAbsolute, join as join10, relative as relative2 } from "node:path";
|
|
147786
|
-
init_logger();
|
|
147794
|
+
import { isAbsolute as isAbsolute2, join as join10, relative as relative2 } from "node:path";
|
|
147787
147795
|
|
|
147788
147796
|
// ../plugin/src/features/magic-context/key-files/aft-availability.ts
|
|
147789
147797
|
var import_comment_json = __toESM(require_src2(), 1);
|
|
147790
147798
|
import { existsSync as existsSync7, readFileSync as readFileSync5 } from "node:fs";
|
|
147791
147799
|
import { homedir as homedir2 } from "node:os";
|
|
147792
|
-
import { join as join9 } from "node:path";
|
|
147800
|
+
import { isAbsolute, join as join9, resolve as resolve2 } from "node:path";
|
|
147801
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
147793
147802
|
var overrideAvailability = null;
|
|
147794
147803
|
function parseConfig(path7) {
|
|
147795
147804
|
if (!existsSync7(path7))
|
|
147796
147805
|
return null;
|
|
147797
147806
|
return import_comment_json.parse(readFileSync5(path7, "utf-8"));
|
|
147798
147807
|
}
|
|
147799
|
-
|
|
147808
|
+
var AFT_NAME_NEEDLES = ["@cortexkit/aft", "aft-opencode", "aft-pi"];
|
|
147809
|
+
function stringMentionsAft(value) {
|
|
147810
|
+
return AFT_NAME_NEEDLES.some((needle) => value.includes(needle));
|
|
147811
|
+
}
|
|
147812
|
+
function resolveLocalEntryPackageName(value, configDir) {
|
|
147813
|
+
let dir = null;
|
|
147814
|
+
if (value.startsWith("file://")) {
|
|
147815
|
+
try {
|
|
147816
|
+
dir = fileURLToPath2(value);
|
|
147817
|
+
} catch {
|
|
147818
|
+
return null;
|
|
147819
|
+
}
|
|
147820
|
+
} else if (value.startsWith("~/")) {
|
|
147821
|
+
dir = join9(homedir2(), value.slice(2));
|
|
147822
|
+
} else if (value.startsWith("/") || value.startsWith("./") || value.startsWith("../")) {
|
|
147823
|
+
dir = isAbsolute(value) ? value : resolve2(configDir, value);
|
|
147824
|
+
} else {
|
|
147825
|
+
return null;
|
|
147826
|
+
}
|
|
147827
|
+
try {
|
|
147828
|
+
const pkg = JSON.parse(readFileSync5(join9(dir, "package.json"), "utf-8"));
|
|
147829
|
+
return typeof pkg.name === "string" ? pkg.name : null;
|
|
147830
|
+
} catch {
|
|
147831
|
+
return null;
|
|
147832
|
+
}
|
|
147833
|
+
}
|
|
147834
|
+
function entryMatchesAft(entry, configDir) {
|
|
147800
147835
|
const value = Array.isArray(entry) ? entry[0] : entry;
|
|
147801
|
-
|
|
147836
|
+
if (typeof value !== "string")
|
|
147837
|
+
return false;
|
|
147838
|
+
if (stringMentionsAft(value))
|
|
147839
|
+
return true;
|
|
147840
|
+
const name2 = resolveLocalEntryPackageName(value, configDir);
|
|
147841
|
+
return name2 != null && stringMentionsAft(name2);
|
|
147802
147842
|
}
|
|
147803
|
-
function hasAftInArray(value) {
|
|
147804
|
-
return Array.isArray(value) && value.some(entryMatchesAft);
|
|
147843
|
+
function hasAftInArray(value, configDir) {
|
|
147844
|
+
return Array.isArray(value) && value.some((entry) => entryMatchesAft(entry, configDir));
|
|
147805
147845
|
}
|
|
147806
|
-
function hasAftAtKeys(value, keys) {
|
|
147846
|
+
function hasAftAtKeys(value, keys, configDir) {
|
|
147807
147847
|
if (!value || typeof value !== "object")
|
|
147808
147848
|
return false;
|
|
147809
147849
|
const record = value;
|
|
147810
147850
|
for (const key of keys) {
|
|
147811
|
-
if (hasAftInArray(record[key]))
|
|
147851
|
+
if (hasAftInArray(record[key], configDir))
|
|
147812
147852
|
return true;
|
|
147813
147853
|
}
|
|
147814
147854
|
return false;
|
|
@@ -147825,7 +147865,8 @@ function getAftAvailability() {
|
|
|
147825
147865
|
for (const path7 of opencodePaths) {
|
|
147826
147866
|
try {
|
|
147827
147867
|
const config = parseConfig(path7);
|
|
147828
|
-
|
|
147868
|
+
const configDir = join9(path7, "..");
|
|
147869
|
+
if (hasAftAtKeys(config, ["plugin", "plugins", "mcp", "mcp_servers"], configDir)) {
|
|
147829
147870
|
opencode = true;
|
|
147830
147871
|
break;
|
|
147831
147872
|
}
|
|
@@ -147835,12 +147876,13 @@ function getAftAvailability() {
|
|
|
147835
147876
|
for (const path7 of piPaths) {
|
|
147836
147877
|
try {
|
|
147837
147878
|
const config = parseConfig(path7);
|
|
147838
|
-
|
|
147879
|
+
const configDir = join9(path7, "..");
|
|
147880
|
+
if (hasAftAtKeys(config, ["packages", "extensions"], configDir)) {
|
|
147839
147881
|
pi = true;
|
|
147840
147882
|
break;
|
|
147841
147883
|
}
|
|
147842
147884
|
const agent = config?.agent;
|
|
147843
|
-
if (hasAftAtKeys(agent, ["packages", "extensions"])) {
|
|
147885
|
+
if (hasAftAtKeys(agent, ["packages", "extensions"], configDir)) {
|
|
147844
147886
|
pi = true;
|
|
147845
147887
|
break;
|
|
147846
147888
|
}
|
|
@@ -147860,7 +147902,7 @@ function isAftAvailable() {
|
|
|
147860
147902
|
|
|
147861
147903
|
// ../plugin/src/features/magic-context/key-files/read-history.ts
|
|
147862
147904
|
import { realpathSync as realpathSync3 } from "node:fs";
|
|
147863
|
-
import { relative, resolve as
|
|
147905
|
+
import { relative, resolve as resolve3 } from "node:path";
|
|
147864
147906
|
function toMs(value) {
|
|
147865
147907
|
if (typeof value === "number" && Number.isFinite(value))
|
|
147866
147908
|
return value;
|
|
@@ -147897,7 +147939,7 @@ function coalesceRanges(ranges) {
|
|
|
147897
147939
|
}
|
|
147898
147940
|
function normalizeProjectRelativePath(projectPath, filePath) {
|
|
147899
147941
|
const root = realpathSync3(projectPath);
|
|
147900
|
-
const abs = filePath.startsWith("/") ?
|
|
147942
|
+
const abs = filePath.startsWith("/") ? resolve3(filePath) : resolve3(root, filePath);
|
|
147901
147943
|
let real = abs;
|
|
147902
147944
|
try {
|
|
147903
147945
|
real = realpathSync3(abs);
|
|
@@ -148040,9 +148082,6 @@ function collectKeyFileCandidates(args) {
|
|
|
148040
148082
|
})).sort((a, b) => b.totalReads - a.totalReads || b.lastReadAt - a.lastReadAt).slice(0, 200);
|
|
148041
148083
|
}
|
|
148042
148084
|
|
|
148043
|
-
// ../plugin/src/features/magic-context/key-files/storage-key-files.ts
|
|
148044
|
-
init_logger();
|
|
148045
|
-
|
|
148046
148085
|
// ../plugin/src/features/magic-context/key-files/identify-key-files.ts
|
|
148047
148086
|
var KEY_FILES_SYSTEM_PROMPT = "You are a file importance evaluator. Given read statistics about files in a coding session, identify which are core orientation files worth pinning in context. Return a JSON array.";
|
|
148048
148087
|
class KeyFilesValidationError extends Error {
|
|
@@ -148262,11 +148301,13 @@ async function runKeyFilesLlm(args) {
|
|
|
148262
148301
|
const text = extractLatestAssistantText(messages);
|
|
148263
148302
|
if (!text)
|
|
148264
148303
|
throw new Error("Dreamer returned no key-files output.");
|
|
148265
|
-
return text;
|
|
148304
|
+
return { text, messages };
|
|
148266
148305
|
} finally {
|
|
148267
|
-
|
|
148268
|
-
|
|
148269
|
-
|
|
148306
|
+
if (!shouldKeepSubagents()) {
|
|
148307
|
+
await args.client.session.delete({ path: { id: agentSessionId } }).catch(() => {
|
|
148308
|
+
return;
|
|
148309
|
+
});
|
|
148310
|
+
}
|
|
148270
148311
|
}
|
|
148271
148312
|
}
|
|
148272
148313
|
async function runKeyFilesTask(args) {
|
|
@@ -148312,9 +148353,27 @@ async function runKeyFilesTask(args) {
|
|
|
148312
148353
|
log(`[key-files] lease renewal threw: ${getErrorMessage(error)}`);
|
|
148313
148354
|
}
|
|
148314
148355
|
}, 60000);
|
|
148356
|
+
let invocationRecorded = false;
|
|
148357
|
+
const llmStartedAt = Date.now();
|
|
148358
|
+
const recordKeyFilesInvocation = (params) => {
|
|
148359
|
+
if (!args.parentSessionId || invocationRecorded)
|
|
148360
|
+
return;
|
|
148361
|
+
invocationRecorded = true;
|
|
148362
|
+
recordChildInvocation({
|
|
148363
|
+
db: args.db,
|
|
148364
|
+
parentSessionId: args.parentSessionId,
|
|
148365
|
+
harness: getHarness(),
|
|
148366
|
+
subagent: "dreamer",
|
|
148367
|
+
task: "key files",
|
|
148368
|
+
startedAt: llmStartedAt,
|
|
148369
|
+
status: params.status,
|
|
148370
|
+
messages: params.messages,
|
|
148371
|
+
error: params.error
|
|
148372
|
+
});
|
|
148373
|
+
};
|
|
148315
148374
|
try {
|
|
148316
148375
|
try {
|
|
148317
|
-
const raw = await runKeyFilesLlm({
|
|
148376
|
+
const { text: raw, messages: llmMessages } = await runKeyFilesLlm({
|
|
148318
148377
|
client: args.client,
|
|
148319
148378
|
parentSessionId: args.parentSessionId,
|
|
148320
148379
|
projectPath,
|
|
@@ -148322,8 +148381,10 @@ async function runKeyFilesTask(args) {
|
|
|
148322
148381
|
deadline: args.deadline,
|
|
148323
148382
|
fallbackModels: args.fallbackModels
|
|
148324
148383
|
});
|
|
148384
|
+
recordKeyFilesInvocation({ status: "completed", messages: llmMessages });
|
|
148325
148385
|
validated = validateLlmOutput(raw, args.config, projectPath, new Set(candidates.map((candidate) => candidate.path)));
|
|
148326
148386
|
} catch (error) {
|
|
148387
|
+
recordKeyFilesInvocation({ status: "failed", error });
|
|
148327
148388
|
log(`[key-files] LLM validation failed: ${getErrorMessage(error)}`);
|
|
148328
148389
|
throw error;
|
|
148329
148390
|
}
|
|
@@ -148917,9 +148978,6 @@ function getMemoryCountsByStatus(db, projectPath) {
|
|
|
148917
148978
|
return counts;
|
|
148918
148979
|
}
|
|
148919
148980
|
|
|
148920
|
-
// ../plugin/src/features/magic-context/user-memory/review-user-memories.ts
|
|
148921
|
-
init_logger();
|
|
148922
|
-
|
|
148923
148981
|
// ../plugin/src/features/magic-context/dreamer/task-prompts.ts
|
|
148924
148982
|
var DREAMER_SYSTEM_PROMPT = `You are a memory maintenance agent for the magic-context system.
|
|
148925
148983
|
You run during scheduled dream windows to maintain a project's cross-session memory store and codebase documentation.
|
|
@@ -149422,7 +149480,8 @@ If no promotions are warranted, return empty arrays. Always consume reviewed can
|
|
|
149422
149480
|
db: args.db,
|
|
149423
149481
|
parentSessionId: args.parentSessionId,
|
|
149424
149482
|
harness: "opencode",
|
|
149425
|
-
subagent: "
|
|
149483
|
+
subagent: "dreamer",
|
|
149484
|
+
task: "user memories",
|
|
149426
149485
|
startedAt,
|
|
149427
149486
|
status: params.status,
|
|
149428
149487
|
messages: params.messages,
|
|
@@ -149546,7 +149605,7 @@ If no promotions are warranted, return empty arrays. Always consume reviewed can
|
|
|
149546
149605
|
return result;
|
|
149547
149606
|
} finally {
|
|
149548
149607
|
clearInterval(leaseInterval);
|
|
149549
|
-
if (agentSessionId) {
|
|
149608
|
+
if (agentSessionId && !shouldKeepSubagents()) {
|
|
149550
149609
|
await args.client.session.delete({
|
|
149551
149610
|
path: { id: agentSessionId },
|
|
149552
149611
|
query: { directory: args.sessionDirectory }
|
|
@@ -149870,14 +149929,14 @@ async function runDream(args) {
|
|
|
149870
149929
|
}
|
|
149871
149930
|
} finally {
|
|
149872
149931
|
clearInterval(leaseRenewalInterval);
|
|
149873
|
-
if (agentSessionId && !taskFailed) {
|
|
149932
|
+
if (agentSessionId && !taskFailed && !shouldKeepSubagents()) {
|
|
149874
149933
|
await args.client.session.delete({
|
|
149875
149934
|
path: { id: agentSessionId }
|
|
149876
149935
|
}).catch((error) => {
|
|
149877
149936
|
log("[dreamer] failed to delete child session:", error);
|
|
149878
149937
|
});
|
|
149879
|
-
} else if (agentSessionId && taskFailed) {
|
|
149880
|
-
log(`[dreamer] KEEPING
|
|
149938
|
+
} else if (agentSessionId && (taskFailed || shouldKeepSubagents())) {
|
|
149939
|
+
log(`[dreamer] KEEPING child session ${agentSessionId} for task ${taskName} (${taskFailed ? "failed" : "keep_subagents"})`);
|
|
149881
149940
|
}
|
|
149882
149941
|
}
|
|
149883
149942
|
if (lostLease) {
|
|
@@ -150162,7 +150221,7 @@ Only include notes whose conditions you could definitively evaluate against exte
|
|
|
150162
150221
|
parts: [{ type: "text", text: evaluationPrompt, synthetic: true }]
|
|
150163
150222
|
}
|
|
150164
150223
|
}, {
|
|
150165
|
-
timeoutMs: Math.min(remainingMs,
|
|
150224
|
+
timeoutMs: Math.min(remainingMs, 5 * 60 * 1000),
|
|
150166
150225
|
signal: abortController.signal,
|
|
150167
150226
|
fallbackModels: args.fallbackModels,
|
|
150168
150227
|
callContext: "dreamer:smart-notes"
|
|
@@ -150238,7 +150297,7 @@ Only include notes whose conditions you could definitively evaluate against exte
|
|
|
150238
150297
|
});
|
|
150239
150298
|
} finally {
|
|
150240
150299
|
clearInterval(leaseInterval);
|
|
150241
|
-
if (agentSessionId) {
|
|
150300
|
+
if (agentSessionId && !shouldKeepSubagents()) {
|
|
150242
150301
|
await args.client.session.delete({
|
|
150243
150302
|
path: { id: agentSessionId }
|
|
150244
150303
|
}).catch(() => {});
|
|
@@ -150249,7 +150308,7 @@ var MAX_LEASE_RETRIES = 3;
|
|
|
150249
150308
|
async function processDreamQueue(args) {
|
|
150250
150309
|
const maxRuntimeMs = args.maxRuntimeMinutes * 60 * 1000;
|
|
150251
150310
|
if (!hasActiveDreamLease(args.db)) {
|
|
150252
|
-
clearStaleEntries(args.db, maxRuntimeMs +
|
|
150311
|
+
clearStaleEntries(args.db, maxRuntimeMs + 30 * 60 * 1000, args.projectIdentity);
|
|
150253
150312
|
}
|
|
150254
150313
|
const entry = dequeueNext(args.db, args.projectIdentity);
|
|
150255
150314
|
if (!entry) {
|
|
@@ -150292,7 +150351,6 @@ async function processDreamQueue(args) {
|
|
|
150292
150351
|
return result;
|
|
150293
150352
|
}
|
|
150294
150353
|
// ../plugin/src/features/magic-context/dreamer/scheduler.ts
|
|
150295
|
-
init_logger();
|
|
150296
150354
|
function parseScheduleWindow(schedule) {
|
|
150297
150355
|
const match = /^(\d{1,2}):(\d{2})-(\d{1,2}):(\d{2})$/.exec(schedule.trim());
|
|
150298
150356
|
if (!match)
|
|
@@ -150367,7 +150425,6 @@ function checkScheduleAndEnqueue(db, schedule, ownProjectIdentity) {
|
|
|
150367
150425
|
return enqueued;
|
|
150368
150426
|
}
|
|
150369
150427
|
// ../plugin/src/features/magic-context/git-commits/git-log-reader.ts
|
|
150370
|
-
init_logger();
|
|
150371
150428
|
import { execFile } from "node:child_process";
|
|
150372
150429
|
import { promisify } from "node:util";
|
|
150373
150430
|
var execFileAsync = promisify(execFile);
|
|
@@ -150451,9 +150508,6 @@ ${body}` : subject;
|
|
|
150451
150508
|
}
|
|
150452
150509
|
return commits;
|
|
150453
150510
|
}
|
|
150454
|
-
// ../plugin/src/features/magic-context/git-commits/indexer.ts
|
|
150455
|
-
init_logger();
|
|
150456
|
-
|
|
150457
150511
|
// ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/classic/external.js
|
|
150458
150512
|
var exports_external = {};
|
|
150459
150513
|
__export(exports_external, {
|
|
@@ -164893,6 +164947,7 @@ var MagicContextConfigSchema = exports_external.object({
|
|
|
164893
164947
|
model: DEFAULT_LOCAL_EMBEDDING_MODEL
|
|
164894
164948
|
}).describe("Embedding provider configuration"),
|
|
164895
164949
|
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).'),
|
|
164950
|
+
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."),
|
|
164896
164951
|
caveman_text_compression: exports_external.object({
|
|
164897
164952
|
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%)."),
|
|
164898
164953
|
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.")
|
|
@@ -164932,9 +164987,6 @@ var MagicContextConfigSchema = exports_external.object({
|
|
|
164932
164987
|
};
|
|
164933
164988
|
});
|
|
164934
164989
|
|
|
164935
|
-
// ../plugin/src/features/magic-context/memory/embedding.ts
|
|
164936
|
-
init_logger();
|
|
164937
|
-
|
|
164938
164990
|
// ../plugin/src/features/magic-context/memory/cosine-similarity.ts
|
|
164939
164991
|
function cosineSimilarity(a, b) {
|
|
164940
164992
|
if (a.length !== b.length) {
|
|
@@ -164980,8 +165032,6 @@ import { mkdirSync as mkdirSync5 } from "node:fs";
|
|
|
164980
165032
|
import { open, stat, unlink, writeFile } from "node:fs/promises";
|
|
164981
165033
|
import { dirname as dirname4, join as join12 } from "node:path";
|
|
164982
165034
|
import { pathToFileURL } from "node:url";
|
|
164983
|
-
init_data_path();
|
|
164984
|
-
init_logger();
|
|
164985
165035
|
var LOCK_POLL_MS = 150;
|
|
164986
165036
|
var STALE_LOCK_MS = 3 * 60000;
|
|
164987
165037
|
var MAX_LOCK_WAIT_MS = 5 * 60000;
|
|
@@ -165020,7 +165070,7 @@ async function acquireModelLoadLock(lockPath) {
|
|
|
165020
165070
|
if (Date.now() - waitStart > MAX_LOCK_WAIT_MS) {
|
|
165021
165071
|
throw new Error(`[magic-context] embedding-load lock wait exceeded ${MAX_LOCK_WAIT_MS}ms; another process is still loading the model. Skipping this init attempt to avoid an unsynchronized native load.`);
|
|
165022
165072
|
}
|
|
165023
|
-
await new Promise((
|
|
165073
|
+
await new Promise((resolve4) => setTimeout(resolve4, LOCK_POLL_MS));
|
|
165024
165074
|
}
|
|
165025
165075
|
}
|
|
165026
165076
|
}
|
|
@@ -165189,7 +165239,7 @@ class LocalEmbeddingProvider {
|
|
|
165189
165239
|
}
|
|
165190
165240
|
const delayMs = 300 * attempt + Math.floor(Math.random() * 200);
|
|
165191
165241
|
log(`[magic-context] embedding model load attempt ${attempt}/${MAX_ATTEMPTS} failed transiently, retrying in ${delayMs}ms`);
|
|
165192
|
-
await new Promise((
|
|
165242
|
+
await new Promise((resolve4) => setTimeout(resolve4, delayMs));
|
|
165193
165243
|
}
|
|
165194
165244
|
}
|
|
165195
165245
|
if (this.pipeline) {
|
|
@@ -165217,8 +165267,8 @@ class LocalEmbeddingProvider {
|
|
|
165217
165267
|
if (this.inFlight === 0) {
|
|
165218
165268
|
return Promise.resolve();
|
|
165219
165269
|
}
|
|
165220
|
-
return new Promise((
|
|
165221
|
-
this.inFlightWaiters.push(
|
|
165270
|
+
return new Promise((resolve4) => {
|
|
165271
|
+
this.inFlightWaiters.push(resolve4);
|
|
165222
165272
|
});
|
|
165223
165273
|
}
|
|
165224
165274
|
finishInFlight() {
|
|
@@ -165317,7 +165367,6 @@ class LocalEmbeddingProvider {
|
|
|
165317
165367
|
}
|
|
165318
165368
|
|
|
165319
165369
|
// ../plugin/src/features/magic-context/memory/embedding-openai.ts
|
|
165320
|
-
init_logger();
|
|
165321
165370
|
function normalizeEndpoint2(endpoint) {
|
|
165322
165371
|
return endpoint?.trim().replace(/\/+$/, "") ?? "";
|
|
165323
165372
|
}
|
|
@@ -165533,7 +165582,6 @@ class OpenAICompatibleEmbeddingProvider {
|
|
|
165533
165582
|
|
|
165534
165583
|
// ../plugin/src/features/magic-context/project-embedding-registry.ts
|
|
165535
165584
|
import { createHash as createHash7, randomUUID } from "node:crypto";
|
|
165536
|
-
init_logger();
|
|
165537
165585
|
|
|
165538
165586
|
// ../plugin/src/features/magic-context/git-commits/storage-git-commit-embeddings.ts
|
|
165539
165587
|
var saveStatements = new WeakMap;
|
|
@@ -166067,7 +166115,6 @@ async function embedText(text, signal) {
|
|
|
166067
166115
|
var SWEEP_MAX_WALL_CLOCK_MS2 = 10 * 60 * 1000;
|
|
166068
166116
|
|
|
166069
166117
|
// ../plugin/src/features/magic-context/git-commits/storage-git-commits.ts
|
|
166070
|
-
init_logger();
|
|
166071
166118
|
var insertStatements = new WeakMap;
|
|
166072
166119
|
var existingShasStatements = new WeakMap;
|
|
166073
166120
|
var projectCountStatements = new WeakMap;
|
|
@@ -166279,9 +166326,6 @@ async function embedUnembeddedCommits(db, projectPath) {
|
|
|
166279
166326
|
embedInProgress.delete(projectPath);
|
|
166280
166327
|
}
|
|
166281
166328
|
}
|
|
166282
|
-
// ../plugin/src/features/magic-context/git-commits/search-git-commits.ts
|
|
166283
|
-
init_logger();
|
|
166284
|
-
|
|
166285
166329
|
// ../plugin/src/features/magic-context/memory/storage-memory-fts.ts
|
|
166286
166330
|
var DEFAULT_SEARCH_LIMIT = 10;
|
|
166287
166331
|
var searchStatements = new WeakMap;
|
|
@@ -166444,7 +166488,6 @@ function searchGitCommitsSync(db, projectPath, query, options) {
|
|
|
166444
166488
|
return results.slice(0, options.limit);
|
|
166445
166489
|
}
|
|
166446
166490
|
// ../plugin/src/plugin/dream-timer.ts
|
|
166447
|
-
init_logger();
|
|
166448
166491
|
var DREAM_TIMER_INTERVAL_MS = 15 * 60 * 1000;
|
|
166449
166492
|
var activeTimer = null;
|
|
166450
166493
|
function openTimerDatabaseOrNull(context) {
|
|
@@ -166604,7 +166647,6 @@ async function sweepGitCommits(args) {
|
|
|
166604
166647
|
|
|
166605
166648
|
// ../plugin/src/plugin/embedding-bootstrap-helpers.ts
|
|
166606
166649
|
import { createHash as createHash8 } from "node:crypto";
|
|
166607
|
-
init_logger();
|
|
166608
166650
|
var EMBEDDING_AFFECTING_KEYS = new Set([
|
|
166609
166651
|
"embedding.api_key",
|
|
166610
166652
|
"embedding.endpoint",
|
|
@@ -166776,7 +166818,7 @@ function migrateLegacyExperimental(rawConfig, warnings) {
|
|
|
166776
166818
|
// ../plugin/src/config/variable.ts
|
|
166777
166819
|
import { existsSync as existsSync9, readFileSync as readFileSync7 } from "node:fs";
|
|
166778
166820
|
import { homedir as homedir3 } from "node:os";
|
|
166779
|
-
import { dirname as dirname5, isAbsolute as
|
|
166821
|
+
import { dirname as dirname5, isAbsolute as isAbsolute3, resolve as resolve4 } from "node:path";
|
|
166780
166822
|
|
|
166781
166823
|
// ../plugin/src/shared/jsonc-parser.ts
|
|
166782
166824
|
function stripJsonComments(content) {
|
|
@@ -166886,9 +166928,9 @@ function substituteConfigVariables(input) {
|
|
|
166886
166928
|
}
|
|
166887
166929
|
let filePath = rawPath.trim();
|
|
166888
166930
|
if (filePath.startsWith("~/")) {
|
|
166889
|
-
filePath =
|
|
166890
|
-
} else if (!
|
|
166891
|
-
filePath =
|
|
166931
|
+
filePath = resolve4(homedir3(), filePath.slice(2));
|
|
166932
|
+
} else if (!isAbsolute3(filePath)) {
|
|
166933
|
+
filePath = resolve4(configDir, filePath);
|
|
166892
166934
|
}
|
|
166893
166935
|
if (!existsSync9(filePath)) {
|
|
166894
166936
|
warnings.push(`File not found for ${token} (resolved to ${filePath}); using empty string`);
|
|
@@ -167503,7 +167545,6 @@ function registerCtxDreamCommand(pi, deps) {
|
|
|
167503
167545
|
}
|
|
167504
167546
|
|
|
167505
167547
|
// ../plugin/src/hooks/magic-context/execute-flush.ts
|
|
167506
|
-
init_logger();
|
|
167507
167548
|
function executeFlush(db, sessionId) {
|
|
167508
167549
|
try {
|
|
167509
167550
|
const pendingOps = getPendingOps(db, sessionId);
|
|
@@ -167535,7 +167576,6 @@ function executeFlush(db, sessionId) {
|
|
|
167535
167576
|
import * as crypto2 from "node:crypto";
|
|
167536
167577
|
|
|
167537
167578
|
// ../plugin/src/features/magic-context/scheduler.ts
|
|
167538
|
-
init_logger();
|
|
167539
167579
|
var TTL_PATTERN = /^(\d+)([smh])$/;
|
|
167540
167580
|
var NUMERIC_PATTERN = /^\d+$/;
|
|
167541
167581
|
var UNIT_TO_MS = {
|
|
@@ -167590,6 +167630,7 @@ function createScheduler(config2) {
|
|
|
167590
167630
|
}
|
|
167591
167631
|
};
|
|
167592
167632
|
}
|
|
167633
|
+
|
|
167593
167634
|
// ../plugin/src/features/magic-context/tagger.ts
|
|
167594
167635
|
var TOOL_COMPOSITE_KEY_SEP = "\x00";
|
|
167595
167636
|
function makeToolCompositeKey(ownerMsgId, callId) {
|
|
@@ -168349,7 +168390,6 @@ function replayCavemanCompression(sessionId, db, targets, tags) {
|
|
|
168349
168390
|
}
|
|
168350
168391
|
|
|
168351
168392
|
// ../plugin/src/hooks/magic-context/compartment-trigger.ts
|
|
168352
|
-
init_logger();
|
|
168353
168393
|
var PROACTIVE_TRIGGER_OFFSET_PERCENTAGE = 2;
|
|
168354
168394
|
var POST_DROP_TARGET_RATIO = 0.75;
|
|
168355
168395
|
var MIN_PROACTIVE_TAIL_TOKEN_ESTIMATE = 6000;
|
|
@@ -168586,9 +168626,6 @@ class BoundedSessionMap {
|
|
|
168586
168626
|
}
|
|
168587
168627
|
}
|
|
168588
168628
|
|
|
168589
|
-
// ../plugin/src/hooks/magic-context/inject-compartments.ts
|
|
168590
|
-
init_logger();
|
|
168591
|
-
|
|
168592
168629
|
// ../plugin/src/hooks/magic-context/decay-curve.ts
|
|
168593
168630
|
var H50 = 24;
|
|
168594
168631
|
var D = 25;
|
|
@@ -168758,7 +168795,6 @@ function extractM0Block(m0Text, tag) {
|
|
|
168758
168795
|
// ../plugin/src/hooks/magic-context/key-files-block.ts
|
|
168759
168796
|
import { readFileSync as readFileSync9, realpathSync as realpathSync4 } from "node:fs";
|
|
168760
168797
|
import { join as join14, sep as sep2 } from "node:path";
|
|
168761
|
-
init_logger();
|
|
168762
168798
|
var cachedKeyFilesBySession = new Map;
|
|
168763
168799
|
var staleUpdates = new Map;
|
|
168764
168800
|
function staleKey(update) {
|
|
@@ -168856,9 +168892,6 @@ ${blocks.join(`
|
|
|
168856
168892
|
return rendered;
|
|
168857
168893
|
}
|
|
168858
168894
|
|
|
168859
|
-
// ../plugin/src/hooks/magic-context/inject-compartments.ts
|
|
168860
|
-
await init_read_session_db();
|
|
168861
|
-
|
|
168862
168895
|
// ../plugin/src/hooks/magic-context/temporal-awareness.ts
|
|
168863
168896
|
var TEMPORAL_AWARENESS_THRESHOLD_SECONDS = 300;
|
|
168864
168897
|
var SECONDS_PER_MINUTE = 60;
|
|
@@ -169015,9 +169048,6 @@ function renderMemoryBlockV2(memories, wrapper = "project-memory") {
|
|
|
169015
169048
|
`);
|
|
169016
169049
|
}
|
|
169017
169050
|
|
|
169018
|
-
// ../plugin/src/hooks/magic-context/nudger.ts
|
|
169019
|
-
init_logger();
|
|
169020
|
-
|
|
169021
169051
|
// ../plugin/src/shared/format-bytes.ts
|
|
169022
169052
|
function formatBytes(bytes) {
|
|
169023
169053
|
if (bytes < 1024)
|
|
@@ -169219,9 +169249,6 @@ function estimateProjectedPercentage(db, sessionId, contextUsage, preloadedTags)
|
|
|
169219
169249
|
return contextUsage.percentage * (1 - dropRatio);
|
|
169220
169250
|
}
|
|
169221
169251
|
|
|
169222
|
-
// src/context-handler.ts
|
|
169223
|
-
init_logger();
|
|
169224
|
-
|
|
169225
169252
|
// ../plugin/src/shared/tag-transcript.ts
|
|
169226
169253
|
function tagTranscript(sessionId, transcript, tagger, db, options = {}) {
|
|
169227
169254
|
const skipPrefixInjection = options.skipPrefixInjection === true;
|
|
@@ -169523,9 +169550,6 @@ function buildToolTarget(part, message) {
|
|
|
169523
169550
|
};
|
|
169524
169551
|
}
|
|
169525
169552
|
|
|
169526
|
-
// ../plugin/src/features/magic-context/search.ts
|
|
169527
|
-
init_logger();
|
|
169528
|
-
|
|
169529
169553
|
// ../plugin/src/features/magic-context/literal-probes.ts
|
|
169530
169554
|
var MAX_PROBES = 5;
|
|
169531
169555
|
var MIN_PROBE_LENGTH = 3;
|
|
@@ -169582,7 +169606,6 @@ function containsProbeVerbatim(text, probes) {
|
|
|
169582
169606
|
return probes.some((probe) => haystack.includes(probe.toLowerCase()));
|
|
169583
169607
|
}
|
|
169584
169608
|
// ../plugin/src/features/magic-context/memory/embedding-backfill.ts
|
|
169585
|
-
init_logger();
|
|
169586
169609
|
async function ensureMemoryEmbeddings(args) {
|
|
169587
169610
|
const snapshot = getProjectEmbeddingSnapshot(args.projectIdentity);
|
|
169588
169611
|
if (!snapshot?.enabled) {
|
|
@@ -169621,7 +169644,6 @@ async function ensureMemoryEmbeddings(args) {
|
|
|
169621
169644
|
return args.existingEmbeddings;
|
|
169622
169645
|
}
|
|
169623
169646
|
// ../plugin/src/features/magic-context/memory/promotion.ts
|
|
169624
|
-
init_logger();
|
|
169625
169647
|
function isPromotableCategory(category) {
|
|
169626
169648
|
return PROMOTABLE_CATEGORIES.some((promotableCategory) => promotableCategory === category);
|
|
169627
169649
|
}
|
|
@@ -170123,17 +170145,16 @@ ${trimmedBody}…
|
|
|
170123
170145
|
}
|
|
170124
170146
|
|
|
170125
170147
|
// src/auto-search-pi.ts
|
|
170126
|
-
init_logger();
|
|
170127
170148
|
var AUTO_SEARCH_TIMEOUT_MS = 3000;
|
|
170128
170149
|
var DEFAULT_SCORE_THRESHOLD = 0.55;
|
|
170129
170150
|
var DEFAULT_MIN_PROMPT_CHARS = 20;
|
|
170130
170151
|
async function unifiedSearchWithTimeout(db, sessionId, projectPath, prompt, options, timeoutMs) {
|
|
170131
170152
|
const controller = new AbortController;
|
|
170132
170153
|
let timer;
|
|
170133
|
-
const timeoutPromise = new Promise((
|
|
170154
|
+
const timeoutPromise = new Promise((resolve5) => {
|
|
170134
170155
|
timer = setTimeout(() => {
|
|
170135
170156
|
controller.abort();
|
|
170136
|
-
|
|
170157
|
+
resolve5(null);
|
|
170137
170158
|
}, timeoutMs);
|
|
170138
170159
|
});
|
|
170139
170160
|
try {
|
|
@@ -170353,7 +170374,6 @@ ${hintText}`;
|
|
|
170353
170374
|
function clearAutoSearchForPiSession(_sessionId) {}
|
|
170354
170375
|
|
|
170355
170376
|
// src/compaction-marker-manager-pi.ts
|
|
170356
|
-
init_logger();
|
|
170357
170377
|
function applyDeferredPiCompactionMarker(deps, sessionId, pending) {
|
|
170358
170378
|
try {
|
|
170359
170379
|
const matches = getCompartmentsByEndMessageId(deps.db, sessionId, pending.endMessageId);
|
|
@@ -170495,7 +170515,6 @@ function stripSystemInjection(text) {
|
|
|
170495
170515
|
}
|
|
170496
170516
|
|
|
170497
170517
|
// src/heuristic-cleanup-pi.ts
|
|
170498
|
-
init_logger();
|
|
170499
170518
|
var DEDUP_SAFE_TOOLS = new Set([
|
|
170500
170519
|
"mcp_grep",
|
|
170501
170520
|
"mcp_read",
|
|
@@ -170745,9 +170764,6 @@ function buildMessageIdToMaxTagFromTargets(targets) {
|
|
|
170745
170764
|
return byMessage;
|
|
170746
170765
|
}
|
|
170747
170766
|
|
|
170748
|
-
// src/inject-compartments-pi.ts
|
|
170749
|
-
init_logger();
|
|
170750
|
-
|
|
170751
170767
|
// src/read-session-pi.ts
|
|
170752
170768
|
var SYNTH_USER_ID_PREFIX = "synth-user-";
|
|
170753
170769
|
function resolvePiStableId(msg, index, entryIds, entryIdByRef) {
|
|
@@ -171130,6 +171146,13 @@ function safeGetActiveUserMemoriesPi(db) {
|
|
|
171130
171146
|
throw error51;
|
|
171131
171147
|
}
|
|
171132
171148
|
}
|
|
171149
|
+
var EMPTY_PI_HARD_SIGNALS = {
|
|
171150
|
+
systemHash: "",
|
|
171151
|
+
toolSetHash: "",
|
|
171152
|
+
modelKey: "",
|
|
171153
|
+
cacheExpired: false,
|
|
171154
|
+
lastResponseTime: 0
|
|
171155
|
+
};
|
|
171133
171156
|
function decodeCachedM0(value) {
|
|
171134
171157
|
if (!value)
|
|
171135
171158
|
return null;
|
|
@@ -171176,7 +171199,10 @@ function getCachedMarkers(db, state, compartmentsForNormalization) {
|
|
|
171176
171199
|
sessionFactsVersion: meta3.cachedM0SessionFactsVersion,
|
|
171177
171200
|
materializedAt: meta3.cachedM0MaterializedAt,
|
|
171178
171201
|
upgradeState: meta3.cachedM0UpgradeState,
|
|
171179
|
-
lastBaselineEndMessageId: cachedBoundary
|
|
171202
|
+
lastBaselineEndMessageId: cachedBoundary,
|
|
171203
|
+
systemHash: meta3.cachedM0SystemHash ?? "",
|
|
171204
|
+
toolSetHash: meta3.cachedM0ToolSetHash ?? "",
|
|
171205
|
+
modelKey: meta3.cachedM0ModelKey ?? ""
|
|
171180
171206
|
};
|
|
171181
171207
|
}
|
|
171182
171208
|
function lastBaselineEndMessageId(compartments) {
|
|
@@ -171204,7 +171230,10 @@ function readCurrentMarkersFromCompartments(db, state, compartments, projectDocs
|
|
|
171204
171230
|
sessionFactsVersion: getSessionFactsVersion(db, state.sessionId),
|
|
171205
171231
|
materializedAt: Date.now(),
|
|
171206
171232
|
upgradeState: `${PI_M0_UPGRADE_STATE}:${compartments.some((c) => c.legacy === 1) ? "legacy" : "ready"}`,
|
|
171207
|
-
lastBaselineEndMessageId: lastBaselineEndMessageId(compartments)
|
|
171233
|
+
lastBaselineEndMessageId: lastBaselineEndMessageId(compartments),
|
|
171234
|
+
systemHash: (state.hardSignals ?? EMPTY_PI_HARD_SIGNALS).systemHash,
|
|
171235
|
+
toolSetHash: (state.hardSignals ?? EMPTY_PI_HARD_SIGNALS).toolSetHash,
|
|
171236
|
+
modelKey: (state.hardSignals ?? EMPTY_PI_HARD_SIGNALS).modelKey
|
|
171208
171237
|
};
|
|
171209
171238
|
}
|
|
171210
171239
|
function mustMaterializePi(state, db, currentCompartmentsOverride) {
|
|
@@ -171221,7 +171250,19 @@ function mustMaterializePi(state, db, currentCompartmentsOverride) {
|
|
|
171221
171250
|
if (getCachedMarkers(db, state, currentCompartments) === null) {
|
|
171222
171251
|
return { value: true, reason: "cache_invalid" };
|
|
171223
171252
|
}
|
|
171224
|
-
const
|
|
171253
|
+
const hard = state.hardSignals ?? EMPTY_PI_HARD_SIGNALS;
|
|
171254
|
+
if (hard.modelKey !== "" && hard.modelKey !== (meta3.cachedM0ModelKey ?? "")) {
|
|
171255
|
+
return { value: true, reason: "model_change" };
|
|
171256
|
+
}
|
|
171257
|
+
if (hard.systemHash !== "" && hard.systemHash !== (meta3.cachedM0SystemHash ?? "")) {
|
|
171258
|
+
return { value: true, reason: "system_hash" };
|
|
171259
|
+
}
|
|
171260
|
+
if (hard.toolSetHash !== "" && hard.toolSetHash !== (meta3.cachedM0ToolSetHash ?? "")) {
|
|
171261
|
+
return { value: true, reason: "tool_set_hash" };
|
|
171262
|
+
}
|
|
171263
|
+
if (hard.cacheExpired && hard.lastResponseTime > 0 && hard.lastResponseTime > (meta3.cachedM0MaterializedAt ?? 0)) {
|
|
171264
|
+
return { value: true, reason: "ttl_idle" };
|
|
171265
|
+
}
|
|
171225
171266
|
if (meta3.cachedM0UpgradeState !== current.upgradeState) {
|
|
171226
171267
|
return { value: true, reason: "renderer_upgrade" };
|
|
171227
171268
|
}
|
|
@@ -171231,15 +171272,9 @@ function mustMaterializePi(state, db, currentCompartmentsOverride) {
|
|
|
171231
171272
|
if (current.projectMemoryEpoch !== (meta3.cachedM0ProjectMemoryEpoch ?? 0)) {
|
|
171232
171273
|
return { value: true, reason: "project_memory_change" };
|
|
171233
171274
|
}
|
|
171234
|
-
if (current.projectUserProfileVersion !== (meta3.cachedM0ProjectUserProfileVersion ?? 0)) {
|
|
171235
|
-
return { value: true, reason: "user_profile_change" };
|
|
171236
|
-
}
|
|
171237
171275
|
if (current.maxMutationId !== (meta3.cachedM0MaxMutationId ?? 0)) {
|
|
171238
171276
|
return { value: true, reason: "pending_mutations" };
|
|
171239
171277
|
}
|
|
171240
|
-
if (current.maxCompartmentSeq !== cachedMaxCompartmentSeq) {
|
|
171241
|
-
return { value: true, reason: "new_compartment" };
|
|
171242
|
-
}
|
|
171243
171278
|
return { value: false, reason: null };
|
|
171244
171279
|
}
|
|
171245
171280
|
function renderUserProfileBlock(db, wrapper = "user-profile", memoriesOverride) {
|
|
@@ -171319,7 +171354,10 @@ function readFrozenM0InputsPi(state, db, docs = readProjectDocsCanonical(state.p
|
|
|
171319
171354
|
sessionFactsVersion: getSessionFactsVersion(db, state.sessionId),
|
|
171320
171355
|
materializedAt: Date.now(),
|
|
171321
171356
|
upgradeState: `${PI_M0_UPGRADE_STATE}:${compartments.some((c) => c.legacy === 1) ? "legacy" : "ready"}`,
|
|
171322
|
-
lastBaselineEndMessageId: lastBaselineEndMessageId(compartments)
|
|
171357
|
+
lastBaselineEndMessageId: lastBaselineEndMessageId(compartments),
|
|
171358
|
+
systemHash: (state.hardSignals ?? EMPTY_PI_HARD_SIGNALS).systemHash,
|
|
171359
|
+
toolSetHash: (state.hardSignals ?? EMPTY_PI_HARD_SIGNALS).toolSetHash,
|
|
171360
|
+
modelKey: (state.hardSignals ?? EMPTY_PI_HARD_SIGNALS).modelKey
|
|
171323
171361
|
};
|
|
171324
171362
|
return { docs, markers, compartments, memories, userProfile };
|
|
171325
171363
|
});
|
|
@@ -171395,7 +171433,10 @@ function materializeM0Pi(state, db) {
|
|
|
171395
171433
|
projectDocsHash: snapshotMarkers.projectDocsHash,
|
|
171396
171434
|
materializedAt: snapshotMarkers.materializedAt,
|
|
171397
171435
|
sessionFactsVersion: snapshotMarkers.sessionFactsVersion,
|
|
171398
|
-
upgradeState: snapshotMarkers.upgradeState
|
|
171436
|
+
upgradeState: snapshotMarkers.upgradeState,
|
|
171437
|
+
systemHash: snapshotMarkers.systemHash,
|
|
171438
|
+
toolSetHash: snapshotMarkers.toolSetHash,
|
|
171439
|
+
modelKey: snapshotMarkers.modelKey
|
|
171399
171440
|
});
|
|
171400
171441
|
db.prepare("UPDATE session_meta SET memory_block_count = ?, memory_block_ids = ? WHERE session_id = ?").run(renderedMemoryIds.length, JSON.stringify(renderedMemoryIds), state.sessionId);
|
|
171401
171442
|
setCachedBoundary(db, state.sessionId, snapshotMarkers.lastBaselineEndMessageId);
|
|
@@ -171561,6 +171602,9 @@ function readCachedPiM0M1Row(db, sessionId) {
|
|
|
171561
171602
|
cached_m0_materialized_at,
|
|
171562
171603
|
cached_m0_session_facts_version,
|
|
171563
171604
|
cached_m0_upgrade_state,
|
|
171605
|
+
cached_m0_system_hash,
|
|
171606
|
+
cached_m0_tool_set_hash,
|
|
171607
|
+
cached_m0_model_key,
|
|
171564
171608
|
cached_m0_last_baseline_end_message_id,
|
|
171565
171609
|
memory_block_ids
|
|
171566
171610
|
FROM session_meta
|
|
@@ -171598,14 +171642,17 @@ function markersFromCachedPiRow(row, compartmentsForNormalization) {
|
|
|
171598
171642
|
materializedAt: row.cached_m0_materialized_at,
|
|
171599
171643
|
sessionFactsVersion: row.cached_m0_session_facts_version,
|
|
171600
171644
|
upgradeState: row.cached_m0_upgrade_state,
|
|
171601
|
-
lastBaselineEndMessageId: typeof row.cached_m0_last_baseline_end_message_id === "string" && row.cached_m0_last_baseline_end_message_id.length > 0 ? row.cached_m0_last_baseline_end_message_id : null
|
|
171645
|
+
lastBaselineEndMessageId: typeof row.cached_m0_last_baseline_end_message_id === "string" && row.cached_m0_last_baseline_end_message_id.length > 0 ? row.cached_m0_last_baseline_end_message_id : null,
|
|
171646
|
+
systemHash: row.cached_m0_system_hash ?? "",
|
|
171647
|
+
toolSetHash: row.cached_m0_tool_set_hash ?? "",
|
|
171648
|
+
modelKey: row.cached_m0_model_key ?? ""
|
|
171602
171649
|
};
|
|
171603
171650
|
}
|
|
171604
171651
|
function cachedPiRowMatchesSnapshot(args) {
|
|
171605
171652
|
const rowMarkers = markersFromCachedPiRow(args.row, args.compartmentsForNormalization);
|
|
171606
171653
|
if (!rowMarkers)
|
|
171607
171654
|
return false;
|
|
171608
|
-
return bufferEqualsNullable(args.row.cached_m0_bytes, args.m0Bytes) && rowMarkers.projectMemoryEpoch === args.markers.projectMemoryEpoch && rowMarkers.projectUserProfileVersion === args.markers.projectUserProfileVersion && rowMarkers.maxCompartmentSeq === args.markers.maxCompartmentSeq && rowMarkers.maxMemoryId === args.markers.maxMemoryId && rowMarkers.maxMutationId === args.markers.maxMutationId && rowMarkers.maxMemoryMutationId === args.markers.maxMemoryMutationId && (rowMarkers.projectDocsHash ?? "") === (args.markers.projectDocsHash ?? "") && rowMarkers.materializedAt === args.markers.materializedAt && rowMarkers.sessionFactsVersion === args.markers.sessionFactsVersion && (rowMarkers.upgradeState ?? null) === (args.markers.upgradeState ?? null);
|
|
171655
|
+
return bufferEqualsNullable(args.row.cached_m0_bytes, args.m0Bytes) && rowMarkers.projectMemoryEpoch === args.markers.projectMemoryEpoch && rowMarkers.projectUserProfileVersion === args.markers.projectUserProfileVersion && rowMarkers.maxCompartmentSeq === args.markers.maxCompartmentSeq && rowMarkers.maxMemoryId === args.markers.maxMemoryId && rowMarkers.maxMutationId === args.markers.maxMutationId && rowMarkers.maxMemoryMutationId === args.markers.maxMemoryMutationId && (rowMarkers.projectDocsHash ?? "") === (args.markers.projectDocsHash ?? "") && rowMarkers.materializedAt === args.markers.materializedAt && rowMarkers.sessionFactsVersion === args.markers.sessionFactsVersion && (rowMarkers.upgradeState ?? null) === (args.markers.upgradeState ?? null) && (rowMarkers.systemHash ?? "") === (args.markers.systemHash ?? "") && (rowMarkers.toolSetHash ?? "") === (args.markers.toolSetHash ?? "") && (rowMarkers.modelKey ?? "") === (args.markers.modelKey ?? "");
|
|
171609
171656
|
}
|
|
171610
171657
|
function decodeCachedM1(row, sessionId) {
|
|
171611
171658
|
if (!row.cached_m1_bytes) {
|
|
@@ -171665,12 +171712,14 @@ function softRefreshCachedM1Pi(args) {
|
|
|
171665
171712
|
}
|
|
171666
171713
|
const rendered = renderM1PiWithMetadata(args.state, args.db, markers, parseMemoryBlockIds(row.memory_block_ids), preRenderedKeyFilesBlock);
|
|
171667
171714
|
const m1Bytes = Buffer.from(rendered.text, "utf8");
|
|
171668
|
-
|
|
171715
|
+
const latestCompartment = args.compartmentsForNormalization.at(-1);
|
|
171716
|
+
const advancedBoundary = latestCompartment?.endMessageId && latestCompartment.endMessageId.length > 0 ? latestCompartment.endMessageId : markers.lastBaselineEndMessageId;
|
|
171717
|
+
args.db.prepare("UPDATE session_meta SET cached_m1_bytes = ?, cached_m0_last_baseline_end_message_id = ? WHERE session_id = ?").run(m1Bytes, advancedBoundary, args.state.sessionId);
|
|
171669
171718
|
args.db.exec("COMMIT");
|
|
171670
171719
|
return {
|
|
171671
171720
|
m0: decodeCachedM0(row.cached_m0_bytes) ?? "",
|
|
171672
171721
|
m1: rendered.text,
|
|
171673
|
-
markers,
|
|
171722
|
+
markers: { ...markers, lastBaselineEndMessageId: advancedBoundary },
|
|
171674
171723
|
memoryUpdateCount: rendered.memoryUpdateCount,
|
|
171675
171724
|
recomputed: true
|
|
171676
171725
|
};
|
|
@@ -171790,7 +171839,10 @@ function injectM0M1Pi(state, db, piMessages, entryIds, recomputeM1ThisPass = fal
|
|
|
171790
171839
|
markers = replayed.markers;
|
|
171791
171840
|
}
|
|
171792
171841
|
const M0_DRIFT_RATIO_FLOOR = 2000;
|
|
171793
|
-
|
|
171842
|
+
const M1_ABSOLUTE_CAP_RATIO = 0.2;
|
|
171843
|
+
const m1AbsoluteBudget = (state.historyBudgetTokens ?? DEFAULT_HISTORY_BUDGET_TOKENS) * M1_ABSOLUTE_CAP_RATIO;
|
|
171844
|
+
const m1OverAbsoluteCap = m1 !== PI_M1_PLACEHOLDER && estimateTokens(m1) > m1AbsoluteBudget;
|
|
171845
|
+
if (!materialized && !contentionExhausted && m1Recomputed && recomputeM1ThisPass && (memoryUpdateCount > 40 || m1OverAbsoluteCap || m1 !== PI_M1_PLACEHOLDER && m0.length >= M0_DRIFT_RATIO_FLOOR && m1.length > m0.length * 0.15)) {
|
|
171794
171846
|
decision = { value: true, reason: "drift" };
|
|
171795
171847
|
try {
|
|
171796
171848
|
const result = materializeM0PiWithRetry(state, db);
|
|
@@ -171973,7 +172025,6 @@ function isRecord3(value) {
|
|
|
171973
172025
|
}
|
|
171974
172026
|
|
|
171975
172027
|
// ../plugin/src/features/magic-context/compartment-embedding.ts
|
|
171976
|
-
init_logger();
|
|
171977
172028
|
async function embedAndStoreCompartments(db, sessionId, projectPath, compartments) {
|
|
171978
172029
|
if (compartments.length === 0)
|
|
171979
172030
|
return;
|
|
@@ -172870,7 +172921,6 @@ Memory is disabled for this project: do NOT emit a <facts> block. Produce compar
|
|
|
172870
172921
|
}
|
|
172871
172922
|
|
|
172872
172923
|
// ../plugin/src/hooks/magic-context/compartment-runner-drop-queue.ts
|
|
172873
|
-
init_logger();
|
|
172874
172924
|
function queueDropsForCompartmentalizedMessages(db, sessionId, upToMessageIndex) {
|
|
172875
172925
|
const tags = getTagsBySession(db, sessionId);
|
|
172876
172926
|
const { messageFileKeys, toolObservations } = getRawSessionTagKeysThrough(sessionId, upToMessageIndex);
|
|
@@ -174994,7 +175044,6 @@ function buildReferenceBlocks(args) {
|
|
|
174994
175044
|
}
|
|
174995
175045
|
|
|
174996
175046
|
// src/pi-historian-runner.ts
|
|
174997
|
-
init_logger();
|
|
174998
175047
|
var HISTORIAN_AGENT_NAME = "magic-context-historian";
|
|
174999
175048
|
var DEFAULT_HISTORIAN_TIMEOUT_MS2 = 120000;
|
|
175000
175049
|
var HISTORIAN_ALERT_COOLDOWN_MS = 60 * 1000;
|
|
@@ -175777,7 +175826,6 @@ function replayStrippedInlineThinkingPi(args) {
|
|
|
175777
175826
|
}
|
|
175778
175827
|
|
|
175779
175828
|
// src/strip-placeholders-pi.ts
|
|
175780
|
-
init_logger();
|
|
175781
175829
|
var DROPPED_SEGMENT_PATTERN = /^\[dropped(?: §[^§]+§)?\]$/;
|
|
175782
175830
|
function isDroppedOnlyText(text) {
|
|
175783
175831
|
const trimmed = text.trim();
|
|
@@ -175981,7 +176029,6 @@ Prefer many small targeted operations over one large blanket operation, and keep
|
|
|
175981
176029
|
}
|
|
175982
176030
|
|
|
175983
176031
|
// src/system-prompt.ts
|
|
175984
|
-
init_logger();
|
|
175985
176032
|
var MAGIC_CONTEXT_MARKER = "## Magic Context";
|
|
175986
176033
|
var stickyDateBySession = new Map;
|
|
175987
176034
|
function buildMagicContextBlock(opts) {
|
|
@@ -176101,8 +176148,8 @@ function injectPiTemporalMarkers(messages) {
|
|
|
176101
176148
|
// src/timeout.ts
|
|
176102
176149
|
function withTimeout(p, ms) {
|
|
176103
176150
|
let handle;
|
|
176104
|
-
const timeout = new Promise((
|
|
176105
|
-
handle = setTimeout(() =>
|
|
176151
|
+
const timeout = new Promise((resolve5) => {
|
|
176152
|
+
handle = setTimeout(() => resolve5(undefined), ms);
|
|
176106
176153
|
handle.unref?.();
|
|
176107
176154
|
});
|
|
176108
176155
|
return Promise.race([p, timeout]).finally(() => {
|
|
@@ -177834,9 +177881,18 @@ async function runPipeline(args) {
|
|
|
177834
177881
|
if (args.injection) {
|
|
177835
177882
|
try {
|
|
177836
177883
|
const tInjection = performance.now();
|
|
177837
|
-
|
|
177838
|
-
|
|
177839
|
-
|
|
177884
|
+
const hardMeta = getOrCreateSessionMeta(args.db, args.sessionId);
|
|
177885
|
+
let piTtlMs = 5 * 60 * 1000;
|
|
177886
|
+
try {
|
|
177887
|
+
piTtlMs = parseCacheTtl(hardMeta.cacheTtl);
|
|
177888
|
+
} catch {}
|
|
177889
|
+
const piHardSignals = {
|
|
177890
|
+
systemHash: typeof hardMeta.systemPromptHash === "string" ? hardMeta.systemPromptHash : "",
|
|
177891
|
+
toolSetHash: "",
|
|
177892
|
+
modelKey: liveModelBySession.get(args.sessionId) ?? "",
|
|
177893
|
+
cacheExpired: hardMeta.lastResponseTime > 0 && Date.now() - hardMeta.lastResponseTime >= piTtlMs,
|
|
177894
|
+
lastResponseTime: hardMeta.lastResponseTime
|
|
177895
|
+
};
|
|
177840
177896
|
injectionResult = injectM0M1Pi({
|
|
177841
177897
|
sessionId: args.sessionId,
|
|
177842
177898
|
projectIdentity: args.projectIdentity,
|
|
@@ -177844,8 +177900,9 @@ async function runPipeline(args) {
|
|
|
177844
177900
|
injectionBudgetTokens: args.injection.injectionBudgetTokens,
|
|
177845
177901
|
historyBudgetTokens: args.injection.historyBudgetTokens,
|
|
177846
177902
|
keyFilesEnabled: args.injection.keyFilesEnabled,
|
|
177847
|
-
keyFilesTokenBudget: args.injection.keyFilesTokenBudget
|
|
177848
|
-
|
|
177903
|
+
keyFilesTokenBudget: args.injection.keyFilesTokenBudget,
|
|
177904
|
+
hardSignals: piHardSignals
|
|
177905
|
+
}, args.db, args.messages, args.entryIds, args.isCacheBusting || deferredHistoryRefresh || executedWorkThisPass);
|
|
177849
177906
|
if (args.isCacheBusting) {
|
|
177850
177907
|
historyRefreshSessions.delete(args.sessionId);
|
|
177851
177908
|
historyWasConsumedThisPass = true;
|
|
@@ -178198,12 +178255,8 @@ ${result}`;
|
|
|
178198
178255
|
});
|
|
178199
178256
|
}
|
|
178200
178257
|
|
|
178201
|
-
// ../plugin/src/hooks/magic-context/compartment-runner.ts
|
|
178202
|
-
init_logger();
|
|
178203
|
-
|
|
178204
178258
|
// ../plugin/src/hooks/magic-context/historian-state-file.ts
|
|
178205
178259
|
import { mkdirSync as mkdirSync6, unlinkSync, writeFileSync as writeFileSync3 } from "node:fs";
|
|
178206
|
-
init_data_path();
|
|
178207
178260
|
function cleanupHistorianStateFile(path7) {
|
|
178208
178261
|
if (!path7)
|
|
178209
178262
|
return;
|
|
@@ -178211,13 +178264,7 @@ function cleanupHistorianStateFile(path7) {
|
|
|
178211
178264
|
unlinkSync(path7);
|
|
178212
178265
|
} catch {}
|
|
178213
178266
|
}
|
|
178214
|
-
// ../plugin/src/hooks/magic-context/compartment-runner-incremental.ts
|
|
178215
|
-
init_logger();
|
|
178216
|
-
|
|
178217
178267
|
// ../plugin/src/features/magic-context/compaction-marker.ts
|
|
178218
|
-
init_data_path();
|
|
178219
|
-
init_logger();
|
|
178220
|
-
await init_sqlite();
|
|
178221
178268
|
import { join as join15 } from "node:path";
|
|
178222
178269
|
var BASE62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
178223
178270
|
function randomBase62(length) {
|
|
@@ -178372,9 +178419,6 @@ function removeCompactionMarker(state) {
|
|
|
178372
178419
|
}
|
|
178373
178420
|
|
|
178374
178421
|
// ../plugin/src/hooks/magic-context/compaction-marker-manager.ts
|
|
178375
|
-
init_data_path();
|
|
178376
|
-
init_logger();
|
|
178377
|
-
await init_sqlite();
|
|
178378
178422
|
var MARKER_SUMMARY_TEXT = "[Compacted by magic-context — session history is managed by the plugin]";
|
|
178379
178423
|
function updateCompactionMarkerAfterPublication(db, sessionId, lastCompartmentEnd, directory) {
|
|
178380
178424
|
const existing = getPersistedCompactionMarkerState(db, sessionId);
|
|
@@ -178408,7 +178452,6 @@ function updateCompactionMarkerAfterPublication(db, sessionId, lastCompartmentEn
|
|
|
178408
178452
|
// ../plugin/src/hooks/magic-context/compartment-runner-historian.ts
|
|
178409
178453
|
import { mkdirSync as mkdirSync7, unlinkSync as unlinkSync2, writeFileSync as writeFileSync4 } from "node:fs";
|
|
178410
178454
|
import { join as join16 } from "node:path";
|
|
178411
|
-
init_data_path();
|
|
178412
178455
|
function historianResponseDumpDir(directory) {
|
|
178413
178456
|
return getProjectMagicContextHistorianDir(directory);
|
|
178414
178457
|
}
|
|
@@ -178608,12 +178651,12 @@ async function runHistorianPrompt(args) {
|
|
|
178608
178651
|
error: `Historian failed while processing this session: ${desc.brief}`
|
|
178609
178652
|
};
|
|
178610
178653
|
} finally {
|
|
178611
|
-
if (agentSessionId && outcomeOk) {
|
|
178654
|
+
if (agentSessionId && outcomeOk && !shouldKeepSubagents()) {
|
|
178612
178655
|
await client.session.delete({ path: { id: agentSessionId } }).catch((e) => {
|
|
178613
178656
|
sessionLog(parentSessionId, "compartment agent: session cleanup failed", getErrorMessage(e));
|
|
178614
178657
|
});
|
|
178615
|
-
} else if (agentSessionId && !outcomeOk) {
|
|
178616
|
-
sessionLog(parentSessionId, `historian: KEEPING
|
|
178658
|
+
} else if (agentSessionId && (!outcomeOk || shouldKeepSubagents())) {
|
|
178659
|
+
sessionLog(parentSessionId, `historian: KEEPING child session ${agentSessionId} (${outcomeOk ? "keep_subagents" : "failed"}) — not deleted`);
|
|
178617
178660
|
}
|
|
178618
178661
|
}
|
|
178619
178662
|
}
|
|
@@ -178692,8 +178735,8 @@ function isTransientHistorianPromptError(message) {
|
|
|
178692
178735
|
].some((token) => normalized.includes(token));
|
|
178693
178736
|
}
|
|
178694
178737
|
function sleep(ms) {
|
|
178695
|
-
return new Promise((
|
|
178696
|
-
setTimeout(
|
|
178738
|
+
return new Promise((resolve5) => {
|
|
178739
|
+
setTimeout(resolve5, ms);
|
|
178697
178740
|
});
|
|
178698
178741
|
}
|
|
178699
178742
|
function cleanupHistorianDump(sessionId, dumpPath) {
|
|
@@ -178734,7 +178777,6 @@ function sanitizeDumpName(value) {
|
|
|
178734
178777
|
}
|
|
178735
178778
|
|
|
178736
178779
|
// ../plugin/src/hooks/magic-context/send-session-notification.ts
|
|
178737
|
-
init_logger();
|
|
178738
178780
|
function hasNotificationSessionClient(client) {
|
|
178739
178781
|
if (client === null || typeof client !== "object")
|
|
178740
178782
|
return false;
|
|
@@ -178833,11 +178875,7 @@ async function sendIgnoredMessage(client, sessionId, text, params, forcePersist
|
|
|
178833
178875
|
var HISTORIAN_ALERT_COOLDOWN_MS2 = 60 * 1000;
|
|
178834
178876
|
var lastHistorianAlertBySession2 = new Map;
|
|
178835
178877
|
|
|
178836
|
-
// ../plugin/src/hooks/magic-context/compartment-runner-partial-recomp.ts
|
|
178837
|
-
init_logger();
|
|
178838
|
-
|
|
178839
178878
|
// ../plugin/src/hooks/magic-context/compartment-runner-recomp.ts
|
|
178840
|
-
init_logger();
|
|
178841
178879
|
function insertRecompCompartmentRows(db, sessionId, compartments, now) {
|
|
178842
178880
|
const stmt = db.prepare("INSERT INTO compartments (session_id, sequence, start_message, end_message, start_message_id, end_message_id, title, content, p1, p2, p3, p4, importance, episode_type, legacy, created_at, harness) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
|
178843
178881
|
for (const c of compartments) {
|
|
@@ -179606,9 +179644,6 @@ async function executeContextRecompWithResult(deps, options = {}) {
|
|
|
179606
179644
|
}
|
|
179607
179645
|
}
|
|
179608
179646
|
|
|
179609
|
-
// src/commands/ctx-recomp.ts
|
|
179610
|
-
init_logger();
|
|
179611
|
-
|
|
179612
179647
|
// src/pi-recomp-client-shared.ts
|
|
179613
179648
|
function createPiHistorianClient(args) {
|
|
179614
179649
|
const sessions = new Map;
|
|
@@ -179740,9 +179775,6 @@ function resolvePiReadBranchEntries2(ctx) {
|
|
|
179740
179775
|
};
|
|
179741
179776
|
}
|
|
179742
179777
|
|
|
179743
|
-
// src/pi-recomp-runner.ts
|
|
179744
|
-
init_logger();
|
|
179745
|
-
|
|
179746
179778
|
// src/status-line.ts
|
|
179747
179779
|
var STATUS_KEY = "magic-context";
|
|
179748
179780
|
var RECENT_FAILURE_MS = 60000;
|
|
@@ -180071,7 +180103,6 @@ function inferLevel(text) {
|
|
|
180071
180103
|
}
|
|
180072
180104
|
|
|
180073
180105
|
// ../plugin/src/features/magic-context/memory/memory-migration.ts
|
|
180074
|
-
init_logger();
|
|
180075
180106
|
function memoryMigrationGuardKey(projectPath) {
|
|
180076
180107
|
return `memory_migration_5cat:${projectPath}`;
|
|
180077
180108
|
}
|
|
@@ -180181,11 +180212,7 @@ function contextualizeUpgradeReason(reason) {
|
|
|
180181
180212
|
return rewritten;
|
|
180182
180213
|
}
|
|
180183
180214
|
|
|
180184
|
-
// src/commands/ctx-session-upgrade.ts
|
|
180185
|
-
init_logger();
|
|
180186
|
-
|
|
180187
180215
|
// src/pi-memory-migration.ts
|
|
180188
|
-
init_logger();
|
|
180189
180216
|
var MIGRATION_SYSTEM_PROMPT2 = "You re-organize a software project's long-term memory into a stricter taxonomy. " + "Follow the user instructions exactly. Output ONLY the requested XML blocks, nothing else.";
|
|
180190
180217
|
async function runPiMemoryMigration(deps) {
|
|
180191
180218
|
const projectPath = resolveProjectIdentity(deps.directory);
|
|
@@ -180460,7 +180487,6 @@ ${migrationSummary}` : "",
|
|
|
180460
180487
|
}
|
|
180461
180488
|
|
|
180462
180489
|
// ../plugin/src/hooks/magic-context/execute-status.ts
|
|
180463
|
-
init_logger();
|
|
180464
180490
|
function formatExecuteThreshold(thresholdPercentage, mode, contextLimit) {
|
|
180465
180491
|
if (mode === "tokens" && contextLimit > 0) {
|
|
180466
180492
|
const tokens = Math.floor(thresholdPercentage / 100 * contextLimit);
|
|
@@ -180627,7 +180653,7 @@ function formatThresholdPercent(value) {
|
|
|
180627
180653
|
// package.json
|
|
180628
180654
|
var package_default = {
|
|
180629
180655
|
name: "@wolfx/pi-magic-context",
|
|
180630
|
-
version: "0.22.
|
|
180656
|
+
version: "0.22.4",
|
|
180631
180657
|
type: "module",
|
|
180632
180658
|
description: "Pi coding agent extension for Magic Context — cross-session memory and context management",
|
|
180633
180659
|
main: "dist/index.js",
|
|
@@ -185391,7 +185417,6 @@ function createCtxExpandTool(deps) {
|
|
|
185391
185417
|
}
|
|
185392
185418
|
|
|
185393
185419
|
// src/tools/ctx-memory.ts
|
|
185394
|
-
init_logger();
|
|
185395
185420
|
var DEFAULT_LIST_LIMIT = 10;
|
|
185396
185421
|
var VALID_CATEGORIES = new Set(CATEGORY_PRIORITY);
|
|
185397
185422
|
function isMemoryCategory2(value) {
|
|
@@ -186559,6 +186584,7 @@ async function src_default2(pi) {
|
|
|
186559
186584
|
mmapSizeMb: config2.sqlite.mmap_size_mb
|
|
186560
186585
|
});
|
|
186561
186586
|
applySqliteTuningPragmas(db);
|
|
186587
|
+
setKeepSubagents(config2.keep_subagents === true);
|
|
186562
186588
|
if (!config2.enabled) {
|
|
186563
186589
|
info("plugin DISABLED via config (enabled: false) — skipping registration");
|
|
186564
186590
|
return;
|