@cortexkit/pi-magic-context 0.22.2 → 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 +496 -444
- package/dist/subagent-entry.js +341 -271
- package/package.json +1 -1
package/dist/subagent-entry.js
CHANGED
|
@@ -46,167 +46,6 @@ var __export = (target, all) => {
|
|
|
46
46
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
47
47
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
48
48
|
|
|
49
|
-
// ../plugin/src/shared/harness.ts
|
|
50
|
-
function setHarness(value) {
|
|
51
|
-
if (harnessLocked && currentHarness !== value) {
|
|
52
|
-
throw new Error(`Magic Context: harness already locked to "${currentHarness}"; cannot change to "${value}"`);
|
|
53
|
-
}
|
|
54
|
-
currentHarness = value;
|
|
55
|
-
harnessLocked = true;
|
|
56
|
-
}
|
|
57
|
-
function getHarness() {
|
|
58
|
-
return currentHarness;
|
|
59
|
-
}
|
|
60
|
-
var currentHarness = "opencode", harnessLocked = false;
|
|
61
|
-
|
|
62
|
-
// ../plugin/src/shared/data-path.ts
|
|
63
|
-
import * as os from "node:os";
|
|
64
|
-
import * as path from "node:path";
|
|
65
|
-
function getDataDir() {
|
|
66
|
-
return process.env.XDG_DATA_HOME ?? path.join(os.homedir(), ".local", "share");
|
|
67
|
-
}
|
|
68
|
-
function getMagicContextTempDir(harness = getHarness()) {
|
|
69
|
-
return path.join(os.tmpdir(), harness, "magic-context");
|
|
70
|
-
}
|
|
71
|
-
function getMagicContextLogPath(harness = getHarness()) {
|
|
72
|
-
return path.join(getMagicContextTempDir(harness), "magic-context.log");
|
|
73
|
-
}
|
|
74
|
-
function getProjectMagicContextDir(directory) {
|
|
75
|
-
return path.join(directory, ".opencode", "magic-context");
|
|
76
|
-
}
|
|
77
|
-
function getProjectMagicContextHistorianDir(directory) {
|
|
78
|
-
return path.join(getProjectMagicContextDir(directory), "historian");
|
|
79
|
-
}
|
|
80
|
-
function getOpenCodeStorageDir() {
|
|
81
|
-
return path.join(getDataDir(), "opencode", "storage");
|
|
82
|
-
}
|
|
83
|
-
function getMagicContextStorageDir() {
|
|
84
|
-
return path.join(getDataDir(), "cortexkit", "magic-context");
|
|
85
|
-
}
|
|
86
|
-
function getLegacyOpenCodeMagicContextStorageDir() {
|
|
87
|
-
return path.join(getOpenCodeStorageDir(), "plugin", "magic-context");
|
|
88
|
-
}
|
|
89
|
-
var init_data_path = () => {};
|
|
90
|
-
|
|
91
|
-
// ../plugin/src/shared/logger.ts
|
|
92
|
-
import * as fs from "node:fs";
|
|
93
|
-
import * as path2 from "node:path";
|
|
94
|
-
function ensureDir(filePath) {
|
|
95
|
-
const dir = path2.dirname(filePath);
|
|
96
|
-
if (dir === lastEnsuredDir)
|
|
97
|
-
return;
|
|
98
|
-
try {
|
|
99
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
100
|
-
lastEnsuredDir = dir;
|
|
101
|
-
} catch {}
|
|
102
|
-
}
|
|
103
|
-
function flush() {
|
|
104
|
-
if (flushTimer) {
|
|
105
|
-
clearTimeout(flushTimer);
|
|
106
|
-
flushTimer = null;
|
|
107
|
-
}
|
|
108
|
-
if (buffer.length === 0)
|
|
109
|
-
return;
|
|
110
|
-
const data = buffer.join("");
|
|
111
|
-
buffer = [];
|
|
112
|
-
try {
|
|
113
|
-
const logFile = getMagicContextLogPath();
|
|
114
|
-
ensureDir(logFile);
|
|
115
|
-
fs.appendFileSync(logFile, data);
|
|
116
|
-
} catch {}
|
|
117
|
-
}
|
|
118
|
-
function scheduleFlush() {
|
|
119
|
-
if (flushTimer)
|
|
120
|
-
return;
|
|
121
|
-
flushTimer = setTimeout(() => {
|
|
122
|
-
flushTimer = null;
|
|
123
|
-
flush();
|
|
124
|
-
}, FLUSH_INTERVAL_MS);
|
|
125
|
-
}
|
|
126
|
-
function log(message, data) {
|
|
127
|
-
if (isTestEnv)
|
|
128
|
-
return;
|
|
129
|
-
try {
|
|
130
|
-
const timestamp = new Date().toISOString();
|
|
131
|
-
const serialized = data === undefined ? "" : data instanceof Error ? ` ${data.message}${data.stack ? `
|
|
132
|
-
${data.stack}` : ""}` : ` ${JSON.stringify(data)}`;
|
|
133
|
-
buffer.push(`[${timestamp}] ${message}${serialized}
|
|
134
|
-
`);
|
|
135
|
-
if (buffer.length >= BUFFER_SIZE_LIMIT) {
|
|
136
|
-
flush();
|
|
137
|
-
} else {
|
|
138
|
-
scheduleFlush();
|
|
139
|
-
}
|
|
140
|
-
} catch {}
|
|
141
|
-
}
|
|
142
|
-
function sessionLog(sessionId, message, data) {
|
|
143
|
-
log(`[magic-context][${sessionId}] ${message}`, data);
|
|
144
|
-
}
|
|
145
|
-
var isTestEnv = false, buffer, flushTimer = null, FLUSH_INTERVAL_MS = 500, BUFFER_SIZE_LIMIT = 50, lastEnsuredDir = null;
|
|
146
|
-
var init_logger = __esm(() => {
|
|
147
|
-
init_data_path();
|
|
148
|
-
buffer = [];
|
|
149
|
-
if (!isTestEnv) {
|
|
150
|
-
process.on("exit", flush);
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// ../plugin/src/shared/sqlite.ts
|
|
155
|
-
function buildNodeSqliteDatabaseClass(DatabaseSync) {
|
|
156
|
-
const SAVEPOINT = "mc_tx_sp";
|
|
157
|
-
|
|
158
|
-
class NodeSqliteDatabase extends DatabaseSync {
|
|
159
|
-
constructor(filename, options) {
|
|
160
|
-
const translated = { ...options };
|
|
161
|
-
if (options && "readonly" in options) {
|
|
162
|
-
translated.readOnly = options.readonly;
|
|
163
|
-
delete translated.readonly;
|
|
164
|
-
}
|
|
165
|
-
super(typeof filename === "string" ? filename : ":memory:", translated);
|
|
166
|
-
}
|
|
167
|
-
transaction(fn) {
|
|
168
|
-
const self = this;
|
|
169
|
-
const wrapped = function(...args) {
|
|
170
|
-
const nested = self.isTransaction === true;
|
|
171
|
-
self.exec(nested ? `SAVEPOINT ${SAVEPOINT}` : "BEGIN");
|
|
172
|
-
try {
|
|
173
|
-
const result = fn.apply(this, args);
|
|
174
|
-
self.exec(nested ? `RELEASE ${SAVEPOINT}` : "COMMIT");
|
|
175
|
-
return result;
|
|
176
|
-
} catch (error) {
|
|
177
|
-
if (nested) {
|
|
178
|
-
self.exec(`ROLLBACK TO ${SAVEPOINT}`);
|
|
179
|
-
self.exec(`RELEASE ${SAVEPOINT}`);
|
|
180
|
-
} else {
|
|
181
|
-
self.exec("ROLLBACK");
|
|
182
|
-
}
|
|
183
|
-
throw error;
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
return wrapped;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return NodeSqliteDatabase;
|
|
190
|
-
}
|
|
191
|
-
var isBun, bunSpec, nodeSpec, sqliteModule, DatabaseImpl, Database;
|
|
192
|
-
var init_sqlite = __esm(async () => {
|
|
193
|
-
isBun = typeof process !== "undefined" && typeof process.versions?.bun === "string";
|
|
194
|
-
bunSpec = "bun:" + "sqlite";
|
|
195
|
-
nodeSpec = "node:" + "sqlite";
|
|
196
|
-
sqliteModule = isBun ? await import(bunSpec) : await import(nodeSpec);
|
|
197
|
-
DatabaseImpl = isBun ? sqliteModule.Database : buildNodeSqliteDatabaseClass(sqliteModule.DatabaseSync);
|
|
198
|
-
Database = DatabaseImpl;
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
// ../plugin/src/shared/sqlite-helpers.ts
|
|
202
|
-
function closeQuietly(db) {
|
|
203
|
-
if (!db)
|
|
204
|
-
return;
|
|
205
|
-
try {
|
|
206
|
-
db.close();
|
|
207
|
-
} catch {}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
49
|
// ../../node_modules/.bun/esprima@4.0.1/node_modules/esprima/dist/esprima.js
|
|
211
50
|
var require_esprima = __commonJS((exports, module) => {
|
|
212
51
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
@@ -7964,57 +7803,53 @@ var require_src2 = __commonJS((exports, module) => {
|
|
|
7964
7803
|
};
|
|
7965
7804
|
});
|
|
7966
7805
|
|
|
7967
|
-
// ../plugin/src/
|
|
7968
|
-
import { existsSync as
|
|
7969
|
-
import { join as
|
|
7970
|
-
|
|
7971
|
-
|
|
7806
|
+
// ../plugin/src/features/magic-context/storage-db.ts
|
|
7807
|
+
import { copyFileSync, cpSync, existsSync as existsSync3, mkdirSync as mkdirSync2 } from "node:fs";
|
|
7808
|
+
import { dirname as dirname2, join as join4 } from "node:path";
|
|
7809
|
+
|
|
7810
|
+
// ../plugin/src/shared/data-path.ts
|
|
7811
|
+
import * as os from "node:os";
|
|
7812
|
+
import * as path from "node:path";
|
|
7813
|
+
|
|
7814
|
+
// ../plugin/src/shared/harness.ts
|
|
7815
|
+
var currentHarness = "opencode";
|
|
7816
|
+
var harnessLocked = false;
|
|
7817
|
+
function setHarness(value) {
|
|
7818
|
+
if (harnessLocked && currentHarness !== value) {
|
|
7819
|
+
throw new Error(`Magic Context: harness already locked to "${currentHarness}"; cannot change to "${value}"`);
|
|
7820
|
+
}
|
|
7821
|
+
currentHarness = value;
|
|
7822
|
+
harnessLocked = true;
|
|
7972
7823
|
}
|
|
7973
|
-
function
|
|
7974
|
-
return
|
|
7824
|
+
function getHarness() {
|
|
7825
|
+
return currentHarness;
|
|
7975
7826
|
}
|
|
7976
|
-
|
|
7977
|
-
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
try {
|
|
7981
|
-
closeQuietly(cachedReadOnlyDb.db);
|
|
7982
|
-
} catch (error51) {
|
|
7983
|
-
log("[magic-context] failed to close cached OpenCode read-only DB:", error51);
|
|
7984
|
-
} finally {
|
|
7985
|
-
cachedReadOnlyDb = null;
|
|
7986
|
-
}
|
|
7827
|
+
|
|
7828
|
+
// ../plugin/src/shared/data-path.ts
|
|
7829
|
+
function getDataDir() {
|
|
7830
|
+
return process.env.XDG_DATA_HOME ?? path.join(os.homedir(), ".local", "share");
|
|
7987
7831
|
}
|
|
7988
|
-
function
|
|
7989
|
-
|
|
7990
|
-
if (cachedReadOnlyDb?.path === dbPath) {
|
|
7991
|
-
return cachedReadOnlyDb.db;
|
|
7992
|
-
}
|
|
7993
|
-
closeCachedReadOnlyDb();
|
|
7994
|
-
const db = new Database(dbPath, { readonly: true });
|
|
7995
|
-
cachedReadOnlyDb = { path: dbPath, db };
|
|
7996
|
-
return db;
|
|
7832
|
+
function getMagicContextTempDir(harness = getHarness()) {
|
|
7833
|
+
return path.join(os.tmpdir(), harness, "magic-context");
|
|
7997
7834
|
}
|
|
7998
|
-
function
|
|
7999
|
-
return
|
|
7835
|
+
function getMagicContextLogPath(harness = getHarness()) {
|
|
7836
|
+
return path.join(getMagicContextTempDir(harness), "magic-context.log");
|
|
8000
7837
|
}
|
|
8001
|
-
function
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
|
|
8005
|
-
return
|
|
7838
|
+
function getProjectMagicContextDir(directory) {
|
|
7839
|
+
return path.join(directory, ".opencode", "magic-context");
|
|
7840
|
+
}
|
|
7841
|
+
function getProjectMagicContextHistorianDir(directory) {
|
|
7842
|
+
return path.join(getProjectMagicContextDir(directory), "historian");
|
|
7843
|
+
}
|
|
7844
|
+
function getOpenCodeStorageDir() {
|
|
7845
|
+
return path.join(getDataDir(), "opencode", "storage");
|
|
7846
|
+
}
|
|
7847
|
+
function getMagicContextStorageDir() {
|
|
7848
|
+
return path.join(getDataDir(), "cortexkit", "magic-context");
|
|
7849
|
+
}
|
|
7850
|
+
function getLegacyOpenCodeMagicContextStorageDir() {
|
|
7851
|
+
return path.join(getOpenCodeStorageDir(), "plugin", "magic-context");
|
|
8006
7852
|
}
|
|
8007
|
-
var cachedReadOnlyDb = null;
|
|
8008
|
-
var init_read_session_db = __esm(async () => {
|
|
8009
|
-
init_data_path();
|
|
8010
|
-
init_logger();
|
|
8011
|
-
await init_sqlite();
|
|
8012
|
-
});
|
|
8013
|
-
|
|
8014
|
-
// ../plugin/src/features/magic-context/storage-db.ts
|
|
8015
|
-
init_data_path();
|
|
8016
|
-
import { copyFileSync, cpSync, existsSync as existsSync3, mkdirSync as mkdirSync2 } from "node:fs";
|
|
8017
|
-
import { dirname as dirname2, join as join4 } from "node:path";
|
|
8018
7853
|
|
|
8019
7854
|
// ../plugin/src/shared/error-message.ts
|
|
8020
7855
|
function getErrorMessage(error) {
|
|
@@ -8092,12 +7927,124 @@ function safeString(value) {
|
|
|
8092
7927
|
}
|
|
8093
7928
|
}
|
|
8094
7929
|
|
|
8095
|
-
// ../plugin/src/
|
|
8096
|
-
|
|
8097
|
-
|
|
7930
|
+
// ../plugin/src/shared/logger.ts
|
|
7931
|
+
import * as fs from "node:fs";
|
|
7932
|
+
import * as path2 from "node:path";
|
|
7933
|
+
var isTestEnv = false;
|
|
7934
|
+
var buffer = [];
|
|
7935
|
+
var flushTimer = null;
|
|
7936
|
+
var FLUSH_INTERVAL_MS = 500;
|
|
7937
|
+
var BUFFER_SIZE_LIMIT = 50;
|
|
7938
|
+
var lastEnsuredDir = null;
|
|
7939
|
+
function ensureDir(filePath) {
|
|
7940
|
+
const dir = path2.dirname(filePath);
|
|
7941
|
+
if (dir === lastEnsuredDir)
|
|
7942
|
+
return;
|
|
7943
|
+
try {
|
|
7944
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
7945
|
+
lastEnsuredDir = dir;
|
|
7946
|
+
} catch {}
|
|
7947
|
+
}
|
|
7948
|
+
function flush() {
|
|
7949
|
+
if (flushTimer) {
|
|
7950
|
+
clearTimeout(flushTimer);
|
|
7951
|
+
flushTimer = null;
|
|
7952
|
+
}
|
|
7953
|
+
if (buffer.length === 0)
|
|
7954
|
+
return;
|
|
7955
|
+
const data = buffer.join("");
|
|
7956
|
+
buffer = [];
|
|
7957
|
+
try {
|
|
7958
|
+
const logFile = getMagicContextLogPath();
|
|
7959
|
+
ensureDir(logFile);
|
|
7960
|
+
fs.appendFileSync(logFile, data);
|
|
7961
|
+
} catch {}
|
|
7962
|
+
}
|
|
7963
|
+
function scheduleFlush() {
|
|
7964
|
+
if (flushTimer)
|
|
7965
|
+
return;
|
|
7966
|
+
flushTimer = setTimeout(() => {
|
|
7967
|
+
flushTimer = null;
|
|
7968
|
+
flush();
|
|
7969
|
+
}, FLUSH_INTERVAL_MS);
|
|
7970
|
+
}
|
|
7971
|
+
function log(message, data) {
|
|
7972
|
+
if (isTestEnv)
|
|
7973
|
+
return;
|
|
7974
|
+
try {
|
|
7975
|
+
const timestamp = new Date().toISOString();
|
|
7976
|
+
const serialized = data === undefined ? "" : data instanceof Error ? ` ${data.message}${data.stack ? `
|
|
7977
|
+
${data.stack}` : ""}` : ` ${JSON.stringify(data)}`;
|
|
7978
|
+
buffer.push(`[${timestamp}] ${message}${serialized}
|
|
7979
|
+
`);
|
|
7980
|
+
if (buffer.length >= BUFFER_SIZE_LIMIT) {
|
|
7981
|
+
flush();
|
|
7982
|
+
} else {
|
|
7983
|
+
scheduleFlush();
|
|
7984
|
+
}
|
|
7985
|
+
} catch {}
|
|
7986
|
+
}
|
|
7987
|
+
function sessionLog(sessionId, message, data) {
|
|
7988
|
+
log(`[magic-context][${sessionId}] ${message}`, data);
|
|
7989
|
+
}
|
|
7990
|
+
if (!isTestEnv) {
|
|
7991
|
+
process.on("exit", flush);
|
|
7992
|
+
}
|
|
7993
|
+
|
|
7994
|
+
// ../plugin/src/shared/sqlite.ts
|
|
7995
|
+
var isBun = typeof process !== "undefined" && typeof process.versions?.bun === "string";
|
|
7996
|
+
var bunSpec = "bun:" + "sqlite";
|
|
7997
|
+
var nodeSpec = "node:" + "sqlite";
|
|
7998
|
+
var sqliteModule = isBun ? await import(bunSpec) : await import(nodeSpec);
|
|
7999
|
+
var DatabaseImpl = isBun ? sqliteModule.Database : buildNodeSqliteDatabaseClass(sqliteModule.DatabaseSync);
|
|
8000
|
+
function buildNodeSqliteDatabaseClass(DatabaseSync) {
|
|
8001
|
+
const SAVEPOINT = "mc_tx_sp";
|
|
8002
|
+
|
|
8003
|
+
class NodeSqliteDatabase extends DatabaseSync {
|
|
8004
|
+
constructor(filename, options) {
|
|
8005
|
+
const translated = { ...options };
|
|
8006
|
+
if (options && "readonly" in options) {
|
|
8007
|
+
translated.readOnly = options.readonly;
|
|
8008
|
+
delete translated.readonly;
|
|
8009
|
+
}
|
|
8010
|
+
super(typeof filename === "string" ? filename : ":memory:", translated);
|
|
8011
|
+
}
|
|
8012
|
+
transaction(fn) {
|
|
8013
|
+
const self = this;
|
|
8014
|
+
const wrapped = function(...args) {
|
|
8015
|
+
const nested = self.isTransaction === true;
|
|
8016
|
+
self.exec(nested ? `SAVEPOINT ${SAVEPOINT}` : "BEGIN");
|
|
8017
|
+
try {
|
|
8018
|
+
const result = fn.apply(this, args);
|
|
8019
|
+
self.exec(nested ? `RELEASE ${SAVEPOINT}` : "COMMIT");
|
|
8020
|
+
return result;
|
|
8021
|
+
} catch (error) {
|
|
8022
|
+
if (nested) {
|
|
8023
|
+
self.exec(`ROLLBACK TO ${SAVEPOINT}`);
|
|
8024
|
+
self.exec(`RELEASE ${SAVEPOINT}`);
|
|
8025
|
+
} else {
|
|
8026
|
+
self.exec("ROLLBACK");
|
|
8027
|
+
}
|
|
8028
|
+
throw error;
|
|
8029
|
+
}
|
|
8030
|
+
};
|
|
8031
|
+
return wrapped;
|
|
8032
|
+
}
|
|
8033
|
+
}
|
|
8034
|
+
return NodeSqliteDatabase;
|
|
8035
|
+
}
|
|
8036
|
+
var Database = DatabaseImpl;
|
|
8037
|
+
|
|
8038
|
+
// ../plugin/src/shared/sqlite-helpers.ts
|
|
8039
|
+
function closeQuietly(db) {
|
|
8040
|
+
if (!db)
|
|
8041
|
+
return;
|
|
8042
|
+
try {
|
|
8043
|
+
db.close();
|
|
8044
|
+
} catch {}
|
|
8045
|
+
}
|
|
8098
8046
|
|
|
8099
8047
|
// ../plugin/src/features/magic-context/key-files/project-key-files.ts
|
|
8100
|
-
init_logger();
|
|
8101
8048
|
import { createHash } from "node:crypto";
|
|
8102
8049
|
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
8103
8050
|
import { join as join2, resolve, sep } from "node:path";
|
|
@@ -8214,7 +8161,6 @@ function isRelativeProjectFile(projectPath, relativePath) {
|
|
|
8214
8161
|
}
|
|
8215
8162
|
|
|
8216
8163
|
// ../plugin/src/features/magic-context/migrations.ts
|
|
8217
|
-
init_logger();
|
|
8218
8164
|
function tableExists(db, name) {
|
|
8219
8165
|
return Boolean(db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = ?").get(name));
|
|
8220
8166
|
}
|
|
@@ -8948,6 +8894,28 @@ var MIGRATIONS = [
|
|
|
8948
8894
|
db.exec("ALTER TABLE notes ADD COLUMN anchor_ordinal INTEGER");
|
|
8949
8895
|
}
|
|
8950
8896
|
}
|
|
8897
|
+
},
|
|
8898
|
+
{
|
|
8899
|
+
version: 30,
|
|
8900
|
+
description: "HARD-bust m[0] markers: cached system/tool-set/model identity",
|
|
8901
|
+
up: (db) => {
|
|
8902
|
+
const hasSessionMeta = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='session_meta' LIMIT 1").get();
|
|
8903
|
+
if (!hasSessionMeta)
|
|
8904
|
+
return;
|
|
8905
|
+
ensureColumn(db, "session_meta", "cached_m0_system_hash", "TEXT");
|
|
8906
|
+
ensureColumn(db, "session_meta", "cached_m0_tool_set_hash", "TEXT");
|
|
8907
|
+
ensureColumn(db, "session_meta", "cached_m0_model_key", "TEXT");
|
|
8908
|
+
const columns = new Set(db.prepare("PRAGMA table_info(session_meta)").all().map((column) => column.name));
|
|
8909
|
+
if (columns.has("cached_m0_bytes")) {
|
|
8910
|
+
db.prepare(`UPDATE session_meta SET
|
|
8911
|
+
cached_m0_bytes = NULL,
|
|
8912
|
+
cached_m1_bytes = NULL,
|
|
8913
|
+
cached_m0_materialized_at = NULL,
|
|
8914
|
+
cached_m0_system_hash = NULL,
|
|
8915
|
+
cached_m0_tool_set_hash = NULL,
|
|
8916
|
+
cached_m0_model_key = NULL`).run();
|
|
8917
|
+
}
|
|
8918
|
+
}
|
|
8951
8919
|
}
|
|
8952
8920
|
];
|
|
8953
8921
|
var LATEST_MIGRATION_VERSION = MIGRATIONS.reduce((max, m) => Math.max(max, m.version), 0);
|
|
@@ -141663,8 +141631,6 @@ function loadToolDefinitionMeasurements(db) {
|
|
|
141663
141631
|
}
|
|
141664
141632
|
|
|
141665
141633
|
// ../plugin/src/features/magic-context/tool-owner-backfill.ts
|
|
141666
|
-
init_data_path();
|
|
141667
|
-
init_logger();
|
|
141668
141634
|
import { existsSync as existsSync2 } from "node:fs";
|
|
141669
141635
|
import { join as join3 } from "node:path";
|
|
141670
141636
|
var LEASE_DURATION_MS = 5 * 60 * 1000;
|
|
@@ -141912,7 +141878,7 @@ var databases = new Map;
|
|
|
141912
141878
|
var persistenceByDatabase = new WeakMap;
|
|
141913
141879
|
var persistenceErrorByDatabase = new WeakMap;
|
|
141914
141880
|
var lastSchemaFenceRejection = null;
|
|
141915
|
-
var LATEST_SUPPORTED_VERSION =
|
|
141881
|
+
var LATEST_SUPPORTED_VERSION = 30;
|
|
141916
141882
|
function resolveDatabasePath(dbPathOverride) {
|
|
141917
141883
|
if (dbPathOverride) {
|
|
141918
141884
|
return { dbDir: dirname2(dbPathOverride), dbPath: dbPathOverride };
|
|
@@ -142377,6 +142343,9 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
142377
142343
|
cached_m0_materialized_at INTEGER,
|
|
142378
142344
|
cached_m0_session_facts_version INTEGER,
|
|
142379
142345
|
cached_m0_upgrade_state TEXT,
|
|
142346
|
+
cached_m0_system_hash TEXT,
|
|
142347
|
+
cached_m0_tool_set_hash TEXT,
|
|
142348
|
+
cached_m0_model_key TEXT,
|
|
142380
142349
|
cached_m0_last_baseline_end_message_id TEXT,
|
|
142381
142350
|
upgrade_reminded_at INTEGER,
|
|
142382
142351
|
pi_stable_id_scheme INTEGER
|
|
@@ -142568,6 +142537,9 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
142568
142537
|
ensureColumn(db, "session_meta", "cached_m0_materialized_at", "INTEGER");
|
|
142569
142538
|
ensureColumn(db, "session_meta", "cached_m0_session_facts_version", "INTEGER");
|
|
142570
142539
|
ensureColumn(db, "session_meta", "cached_m0_upgrade_state", "TEXT");
|
|
142540
|
+
ensureColumn(db, "session_meta", "cached_m0_system_hash", "TEXT");
|
|
142541
|
+
ensureColumn(db, "session_meta", "cached_m0_tool_set_hash", "TEXT");
|
|
142542
|
+
ensureColumn(db, "session_meta", "cached_m0_model_key", "TEXT");
|
|
142571
142543
|
ensureColumn(db, "session_meta", "cached_m0_last_baseline_end_message_id", "TEXT");
|
|
142572
142544
|
ensureColumn(db, "session_meta", "upgrade_reminded_at", "INTEGER");
|
|
142573
142545
|
db.exec(`
|
|
@@ -142763,9 +142735,6 @@ function openDatabase(dbPathOrOptions) {
|
|
|
142763
142735
|
}
|
|
142764
142736
|
}
|
|
142765
142737
|
|
|
142766
|
-
// src/subagent-entry.ts
|
|
142767
|
-
init_logger();
|
|
142768
|
-
|
|
142769
142738
|
// src/config/index.ts
|
|
142770
142739
|
import { existsSync as existsSync5, readFileSync as readFileSync3 } from "node:fs";
|
|
142771
142740
|
import { homedir as homedir3 } from "node:os";
|
|
@@ -157347,6 +157316,7 @@ var MagicContextConfigSchema = exports_external.object({
|
|
|
157347
157316
|
model: DEFAULT_LOCAL_EMBEDDING_MODEL
|
|
157348
157317
|
}).describe("Embedding provider configuration"),
|
|
157349
157318
|
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).'),
|
|
157319
|
+
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."),
|
|
157350
157320
|
caveman_text_compression: exports_external.object({
|
|
157351
157321
|
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%)."),
|
|
157352
157322
|
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.")
|
|
@@ -157756,9 +157726,6 @@ function loadPiConfigDetailed(opts = {}) {
|
|
|
157756
157726
|
};
|
|
157757
157727
|
}
|
|
157758
157728
|
|
|
157759
|
-
// ../plugin/src/features/magic-context/memory/embedding.ts
|
|
157760
|
-
init_logger();
|
|
157761
|
-
|
|
157762
157729
|
// ../plugin/src/features/magic-context/memory/cosine-similarity.ts
|
|
157763
157730
|
function cosineSimilarity(a, b) {
|
|
157764
157731
|
if (a.length !== b.length) {
|
|
@@ -157814,8 +157781,6 @@ import { mkdirSync as mkdirSync3 } from "node:fs";
|
|
|
157814
157781
|
import { open, stat, unlink, writeFile } from "node:fs/promises";
|
|
157815
157782
|
import { dirname as dirname4, join as join6 } from "node:path";
|
|
157816
157783
|
import { pathToFileURL } from "node:url";
|
|
157817
|
-
init_data_path();
|
|
157818
|
-
init_logger();
|
|
157819
157784
|
var LOCK_POLL_MS = 150;
|
|
157820
157785
|
var STALE_LOCK_MS = 3 * 60000;
|
|
157821
157786
|
var MAX_LOCK_WAIT_MS = 5 * 60000;
|
|
@@ -158151,7 +158116,6 @@ class LocalEmbeddingProvider {
|
|
|
158151
158116
|
}
|
|
158152
158117
|
|
|
158153
158118
|
// ../plugin/src/features/magic-context/memory/embedding-openai.ts
|
|
158154
|
-
init_logger();
|
|
158155
158119
|
function normalizeEndpoint2(endpoint) {
|
|
158156
158120
|
return endpoint?.trim().replace(/\/+$/, "") ?? "";
|
|
158157
158121
|
}
|
|
@@ -158442,7 +158406,6 @@ function getDistinctStoredModelIds(db, projectPath) {
|
|
|
158442
158406
|
|
|
158443
158407
|
// ../plugin/src/features/magic-context/project-embedding-registry.ts
|
|
158444
158408
|
import { createHash as createHash3, randomUUID } from "node:crypto";
|
|
158445
|
-
init_logger();
|
|
158446
158409
|
|
|
158447
158410
|
// ../plugin/src/features/magic-context/git-commits/storage-git-commit-embeddings.ts
|
|
158448
158411
|
var saveStatements = new WeakMap;
|
|
@@ -159180,7 +159143,6 @@ function hasGitDir(canonical) {
|
|
|
159180
159143
|
|
|
159181
159144
|
// ../plugin/src/plugin/embedding-bootstrap-helpers.ts
|
|
159182
159145
|
import { createHash as createHash5 } from "node:crypto";
|
|
159183
|
-
init_logger();
|
|
159184
159146
|
var EMBEDDING_AFFECTING_KEYS = new Set([
|
|
159185
159147
|
"embedding.api_key",
|
|
159186
159148
|
"embedding.endpoint",
|
|
@@ -159268,6 +159230,7 @@ async function ensureProjectRegisteredFromPiDirectory(directory, db) {
|
|
|
159268
159230
|
};
|
|
159269
159231
|
registerProjectEmbeddingAndMaybeWipe(db, projectIdentity, detailed.config.embedding, features, directory);
|
|
159270
159232
|
}
|
|
159233
|
+
|
|
159271
159234
|
// ../plugin/src/features/magic-context/compartment-lease.ts
|
|
159272
159235
|
var COMPARTMENT_LEASE_TTL_MS = 5 * 60 * 1000;
|
|
159273
159236
|
var COMPARTMENT_LEASE_RENEWAL_MS = 60 * 1000;
|
|
@@ -159361,6 +159324,9 @@ var SESSION_META_SELECT_COLUMNS = [
|
|
|
159361
159324
|
"cached_m0_materialized_at",
|
|
159362
159325
|
"cached_m0_session_facts_version",
|
|
159363
159326
|
"cached_m0_upgrade_state",
|
|
159327
|
+
"cached_m0_system_hash",
|
|
159328
|
+
"cached_m0_tool_set_hash",
|
|
159329
|
+
"cached_m0_model_key",
|
|
159364
159330
|
"last_observed_model_key",
|
|
159365
159331
|
"upgrade_reminded_at",
|
|
159366
159332
|
"pi_stable_id_scheme"
|
|
@@ -159397,6 +159363,9 @@ var META_COLUMNS = {
|
|
|
159397
159363
|
cachedM0MaterializedAt: "cached_m0_materialized_at",
|
|
159398
159364
|
cachedM0SessionFactsVersion: "cached_m0_session_facts_version",
|
|
159399
159365
|
cachedM0UpgradeState: "cached_m0_upgrade_state",
|
|
159366
|
+
cachedM0SystemHash: "cached_m0_system_hash",
|
|
159367
|
+
cachedM0ToolSetHash: "cached_m0_tool_set_hash",
|
|
159368
|
+
cachedM0ModelKey: "cached_m0_model_key",
|
|
159400
159369
|
lastObservedModelKey: "last_observed_model_key",
|
|
159401
159370
|
upgradeRemindedAt: "upgrade_reminded_at",
|
|
159402
159371
|
piStableIdScheme: "pi_stable_id_scheme"
|
|
@@ -159439,7 +159408,7 @@ function isSessionMetaRow(row) {
|
|
|
159439
159408
|
if (row === null || typeof row !== "object")
|
|
159440
159409
|
return false;
|
|
159441
159410
|
const r = row;
|
|
159442
|
-
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);
|
|
159411
|
+
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);
|
|
159443
159412
|
}
|
|
159444
159413
|
function getDefaultSessionMeta(sessionId) {
|
|
159445
159414
|
return {
|
|
@@ -159475,6 +159444,9 @@ function getDefaultSessionMeta(sessionId) {
|
|
|
159475
159444
|
cachedM0MaterializedAt: null,
|
|
159476
159445
|
cachedM0SessionFactsVersion: null,
|
|
159477
159446
|
cachedM0UpgradeState: null,
|
|
159447
|
+
cachedM0SystemHash: null,
|
|
159448
|
+
cachedM0ToolSetHash: null,
|
|
159449
|
+
cachedM0ModelKey: null,
|
|
159478
159450
|
lastObservedModelKey: null,
|
|
159479
159451
|
upgradeRemindedAt: null,
|
|
159480
159452
|
piStableIdScheme: null
|
|
@@ -159526,6 +159498,9 @@ function toSessionMeta(row) {
|
|
|
159526
159498
|
cachedM0MaterializedAt: numOrNull(row.cached_m0_materialized_at),
|
|
159527
159499
|
cachedM0SessionFactsVersion: numOrNull(row.cached_m0_session_facts_version),
|
|
159528
159500
|
cachedM0UpgradeState: stringOrNull(row.cached_m0_upgrade_state),
|
|
159501
|
+
cachedM0SystemHash: stringOrNull(row.cached_m0_system_hash),
|
|
159502
|
+
cachedM0ToolSetHash: stringOrNull(row.cached_m0_tool_set_hash),
|
|
159503
|
+
cachedM0ModelKey: stringOrNull(row.cached_m0_model_key),
|
|
159529
159504
|
lastObservedModelKey: stringOrNull(row.last_observed_model_key),
|
|
159530
159505
|
upgradeRemindedAt: numOrNull(row.upgrade_reminded_at),
|
|
159531
159506
|
piStableIdScheme: numOrNull(row.pi_stable_id_scheme)
|
|
@@ -159545,8 +159520,11 @@ function persistCachedM0(db, sessionId, payload) {
|
|
|
159545
159520
|
cached_m0_project_docs_hash = ?,
|
|
159546
159521
|
cached_m0_materialized_at = ?,
|
|
159547
159522
|
cached_m0_session_facts_version = ?,
|
|
159548
|
-
cached_m0_upgrade_state =
|
|
159549
|
-
|
|
159523
|
+
cached_m0_upgrade_state = ?,
|
|
159524
|
+
cached_m0_system_hash = ?,
|
|
159525
|
+
cached_m0_tool_set_hash = ?,
|
|
159526
|
+
cached_m0_model_key = ?
|
|
159527
|
+
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);
|
|
159550
159528
|
}
|
|
159551
159529
|
function clearCachedM0M1(db, sessionId) {
|
|
159552
159530
|
ensureSessionMetaRow(db, sessionId);
|
|
@@ -159564,6 +159542,9 @@ function clearCachedM0M1(db, sessionId) {
|
|
|
159564
159542
|
["cached_m0_materialized_at", null],
|
|
159565
159543
|
["cached_m0_session_facts_version", null],
|
|
159566
159544
|
["cached_m0_upgrade_state", null],
|
|
159545
|
+
["cached_m0_system_hash", null],
|
|
159546
|
+
["cached_m0_tool_set_hash", null],
|
|
159547
|
+
["cached_m0_model_key", null],
|
|
159567
159548
|
["cached_m0_last_baseline_end_message_id", null],
|
|
159568
159549
|
["memory_block_cache", ""],
|
|
159569
159550
|
["memory_block_count", 0],
|
|
@@ -159770,8 +159751,47 @@ function escapeXmlContent(s) {
|
|
|
159770
159751
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
159771
159752
|
}
|
|
159772
159753
|
|
|
159773
|
-
// ../plugin/src/hooks/magic-context/read-session-
|
|
159774
|
-
|
|
159754
|
+
// ../plugin/src/hooks/magic-context/read-session-db.ts
|
|
159755
|
+
import { existsSync as existsSync6 } from "node:fs";
|
|
159756
|
+
import { join as join7 } from "node:path";
|
|
159757
|
+
function getOpenCodeDbPath() {
|
|
159758
|
+
return join7(getDataDir(), "opencode", "opencode.db");
|
|
159759
|
+
}
|
|
159760
|
+
function openCodeDbExists() {
|
|
159761
|
+
return existsSync6(getOpenCodeDbPath());
|
|
159762
|
+
}
|
|
159763
|
+
var cachedReadOnlyDb = null;
|
|
159764
|
+
function closeCachedReadOnlyDb() {
|
|
159765
|
+
if (!cachedReadOnlyDb) {
|
|
159766
|
+
return;
|
|
159767
|
+
}
|
|
159768
|
+
try {
|
|
159769
|
+
closeQuietly(cachedReadOnlyDb.db);
|
|
159770
|
+
} catch (error51) {
|
|
159771
|
+
log("[magic-context] failed to close cached OpenCode read-only DB:", error51);
|
|
159772
|
+
} finally {
|
|
159773
|
+
cachedReadOnlyDb = null;
|
|
159774
|
+
}
|
|
159775
|
+
}
|
|
159776
|
+
function getReadOnlySessionDb() {
|
|
159777
|
+
const dbPath = getOpenCodeDbPath();
|
|
159778
|
+
if (cachedReadOnlyDb?.path === dbPath) {
|
|
159779
|
+
return cachedReadOnlyDb.db;
|
|
159780
|
+
}
|
|
159781
|
+
closeCachedReadOnlyDb();
|
|
159782
|
+
const db = new Database(dbPath, { readonly: true });
|
|
159783
|
+
cachedReadOnlyDb = { path: dbPath, db };
|
|
159784
|
+
return db;
|
|
159785
|
+
}
|
|
159786
|
+
function withReadOnlySessionDb(fn) {
|
|
159787
|
+
return fn(getReadOnlySessionDb());
|
|
159788
|
+
}
|
|
159789
|
+
function getRawSessionMessageCountFromDb(db, sessionId) {
|
|
159790
|
+
const row = db.prepare(`SELECT COUNT(*) as count FROM message WHERE session_id = ?
|
|
159791
|
+
AND NOT (COALESCE(json_extract(data, '$.summary'), 0) = 1
|
|
159792
|
+
AND COALESCE(json_extract(data, '$.finish'), '') = 'stop')`).get(sessionId);
|
|
159793
|
+
return typeof row?.count === "number" ? row.count : 0;
|
|
159794
|
+
}
|
|
159775
159795
|
|
|
159776
159796
|
// ../plugin/src/hooks/magic-context/read-session-raw.ts
|
|
159777
159797
|
function isRawMessageRow(row) {
|
|
@@ -159835,14 +159855,48 @@ function readRawSessionMessagesFromDb(db, sessionId) {
|
|
|
159835
159855
|
var encoder = new TextEncoder;
|
|
159836
159856
|
var TAG_PREFIX_REGEX = /^(?:§\d+§\s*)+/;
|
|
159837
159857
|
var MALFORMED_TAG_PREFIX_REGEX = /^(?:§\d+">§(?:\d+§)?\s*)+/;
|
|
159858
|
+
var COMPLETE_TAG_PAIR_GLOBAL_REGEX = /\u00a7\d+\u00a7/g;
|
|
159859
|
+
var MALFORMED_TAG_GLOBAL_REGEX = /\u00a7\d+">(?:\u00a7(?:\d+\u00a7)?)?/g;
|
|
159860
|
+
var STRAY_SECTION_CHAR_REGEX = /\u00a7/g;
|
|
159861
|
+
function stripWellFormedLeadingTagPrefix(value) {
|
|
159862
|
+
return value.replace(/^(\u00a7\d+\u00a7\s*)+/, "");
|
|
159863
|
+
}
|
|
159864
|
+
function stripCompleteTagPairsGlobally(value) {
|
|
159865
|
+
return value.replace(COMPLETE_TAG_PAIR_GLOBAL_REGEX, "");
|
|
159866
|
+
}
|
|
159867
|
+
function stripMalformedTagNotationGlobally(value) {
|
|
159868
|
+
return value.replace(MALFORMED_TAG_GLOBAL_REGEX, "");
|
|
159869
|
+
}
|
|
159870
|
+
function stripTagSectionCharacters(value) {
|
|
159871
|
+
return value.replace(STRAY_SECTION_CHAR_REGEX, "");
|
|
159872
|
+
}
|
|
159873
|
+
function stripPersistedAssistantText(value) {
|
|
159874
|
+
let text = stripWellFormedLeadingTagPrefix(value);
|
|
159875
|
+
text = stripCompleteTagPairsGlobally(text);
|
|
159876
|
+
text = stripMalformedTagNotationGlobally(text);
|
|
159877
|
+
text = stripTagSectionCharacters(text);
|
|
159878
|
+
return text.trim();
|
|
159879
|
+
}
|
|
159838
159880
|
function byteSize(value) {
|
|
159839
159881
|
return encoder.encode(value).length;
|
|
159840
159882
|
}
|
|
159841
159883
|
function stripTagPrefix(value) {
|
|
159842
|
-
let stripped = value
|
|
159843
|
-
|
|
159884
|
+
let stripped = value;
|
|
159885
|
+
for (let pass = 0;pass < 8; pass++) {
|
|
159886
|
+
const prev = stripped;
|
|
159887
|
+
stripped = stripped.replace(MALFORMED_TAG_PREFIX_REGEX, "");
|
|
159888
|
+
stripped = stripped.replace(TAG_PREFIX_REGEX, "");
|
|
159889
|
+
if (stripped === prev)
|
|
159890
|
+
break;
|
|
159891
|
+
}
|
|
159844
159892
|
return stripped;
|
|
159845
159893
|
}
|
|
159894
|
+
function peelLeadingMcTagNotation(value) {
|
|
159895
|
+
const body = stripTagPrefix(value);
|
|
159896
|
+
if (body === value)
|
|
159897
|
+
return { tagPrefix: "", body };
|
|
159898
|
+
return { tagPrefix: value.slice(0, value.length - body.length), body };
|
|
159899
|
+
}
|
|
159846
159900
|
function prependTag(tagId, value) {
|
|
159847
159901
|
const stripped = stripTagPrefix(value);
|
|
159848
159902
|
return `§${tagId}§ ${stripped}`;
|
|
@@ -159884,7 +159938,9 @@ function hasMeaningfulPart(part) {
|
|
|
159884
159938
|
return false;
|
|
159885
159939
|
const type = part.type;
|
|
159886
159940
|
if (type === "text") {
|
|
159887
|
-
|
|
159941
|
+
if (typeof part.text !== "string")
|
|
159942
|
+
return false;
|
|
159943
|
+
return stripTagPrefix(part.text).trim().length > 0;
|
|
159888
159944
|
}
|
|
159889
159945
|
if (typeof type !== "string")
|
|
159890
159946
|
return false;
|
|
@@ -164630,7 +164686,6 @@ var CATEGORY_DEFAULT_TTL = {
|
|
|
164630
164686
|
KNOWN_ISSUES: 30 * 24 * 60 * 60 * 1000
|
|
164631
164687
|
};
|
|
164632
164688
|
// ../plugin/src/features/magic-context/memory/embedding-backfill.ts
|
|
164633
|
-
init_logger();
|
|
164634
164689
|
async function ensureMemoryEmbeddings(args) {
|
|
164635
164690
|
const snapshot = getProjectEmbeddingSnapshot(args.projectIdentity);
|
|
164636
164691
|
if (!snapshot?.enabled) {
|
|
@@ -164668,9 +164723,6 @@ async function ensureMemoryEmbeddings(args) {
|
|
|
164668
164723
|
}
|
|
164669
164724
|
return args.existingEmbeddings;
|
|
164670
164725
|
}
|
|
164671
|
-
// ../plugin/src/features/magic-context/memory/promotion.ts
|
|
164672
|
-
init_logger();
|
|
164673
|
-
|
|
164674
164726
|
// ../plugin/src/features/magic-context/memory/storage-memory.ts
|
|
164675
164727
|
var COLUMN_MAP = {
|
|
164676
164728
|
id: "id",
|
|
@@ -165570,7 +165622,6 @@ function getMaxMemoryMutationId(db, projectPath) {
|
|
|
165570
165622
|
return row?.max_id ?? null;
|
|
165571
165623
|
}
|
|
165572
165624
|
// ../plugin/src/features/magic-context/storage-meta-persisted.ts
|
|
165573
|
-
init_logger();
|
|
165574
165625
|
var CAS_RETRY_LIMIT = 5;
|
|
165575
165626
|
var AUTO_SEARCH_NO_HINT_REASONS = new Set([
|
|
165576
165627
|
"below-threshold",
|
|
@@ -166033,8 +166084,6 @@ function setSessionWorkMetrics(db, sessionId, newWorkTokens, totalInputTokens) {
|
|
|
166033
166084
|
import { Buffer as Buffer3 } from "node:buffer";
|
|
166034
166085
|
|
|
166035
166086
|
// ../plugin/src/features/magic-context/resolve-subagent-fallback.ts
|
|
166036
|
-
init_logger();
|
|
166037
|
-
await init_read_session_db();
|
|
166038
166087
|
function resolveIsSubagentFromOpenCodeDb(sessionId) {
|
|
166039
166088
|
try {
|
|
166040
166089
|
return withReadOnlySessionDb((openCodeDb) => {
|
|
@@ -166068,6 +166117,9 @@ var SESSION_META_FALLBACK_SELECTS = {
|
|
|
166068
166117
|
cached_m0_materialized_at: "NULL AS cached_m0_materialized_at",
|
|
166069
166118
|
cached_m0_session_facts_version: "NULL AS cached_m0_session_facts_version",
|
|
166070
166119
|
cached_m0_upgrade_state: "NULL AS cached_m0_upgrade_state",
|
|
166120
|
+
cached_m0_system_hash: "NULL AS cached_m0_system_hash",
|
|
166121
|
+
cached_m0_tool_set_hash: "NULL AS cached_m0_tool_set_hash",
|
|
166122
|
+
cached_m0_model_key: "NULL AS cached_m0_model_key",
|
|
166071
166123
|
last_observed_model_key: "NULL AS last_observed_model_key",
|
|
166072
166124
|
upgrade_reminded_at: "NULL AS upgrade_reminded_at"
|
|
166073
166125
|
};
|
|
@@ -166300,7 +166352,6 @@ function markNoteChecked(db, noteId) {
|
|
|
166300
166352
|
db.prepare("UPDATE notes SET last_checked_at = ?, updated_at = ? WHERE id = ? AND type = 'smart'").run(now, now, noteId);
|
|
166301
166353
|
}
|
|
166302
166354
|
// ../plugin/src/features/magic-context/storage-ops.ts
|
|
166303
|
-
init_logger();
|
|
166304
166355
|
var queuePendingOpStatements = new WeakMap;
|
|
166305
166356
|
var getPendingOpsStatements = new WeakMap;
|
|
166306
166357
|
var clearPendingOpsStatements = new WeakMap;
|
|
@@ -166702,7 +166753,6 @@ var ERROR_CLASSES = new Set([
|
|
|
166702
166753
|
"unknown"
|
|
166703
166754
|
]);
|
|
166704
166755
|
// src/tools/ctx-memory.ts
|
|
166705
|
-
init_logger();
|
|
166706
166756
|
var DEFAULT_LIST_LIMIT = 10;
|
|
166707
166757
|
var VALID_CATEGORIES = new Set(CATEGORY_PRIORITY);
|
|
166708
166758
|
function isMemoryCategory2(value) {
|
|
@@ -167419,11 +167469,7 @@ function createCtxReduceTool(deps) {
|
|
|
167419
167469
|
};
|
|
167420
167470
|
}
|
|
167421
167471
|
|
|
167422
|
-
// ../plugin/src/features/magic-context/search.ts
|
|
167423
|
-
init_logger();
|
|
167424
|
-
|
|
167425
167472
|
// ../plugin/src/features/magic-context/git-commits/git-log-reader.ts
|
|
167426
|
-
init_logger();
|
|
167427
167473
|
import { execFile } from "node:child_process";
|
|
167428
167474
|
import { promisify } from "node:util";
|
|
167429
167475
|
var execFileAsync = promisify(execFile);
|
|
@@ -167436,6 +167482,7 @@ async function readGitCommits(directory, options3 = {}) {
|
|
|
167436
167482
|
if (revision.startsWith("-")) {
|
|
167437
167483
|
throw new Error(`readGitCommits: refusing revision that looks like an option: "${revision}"`);
|
|
167438
167484
|
}
|
|
167485
|
+
const projectLabel = options3.projectIdentity ?? "<project>";
|
|
167439
167486
|
const args = [
|
|
167440
167487
|
"log",
|
|
167441
167488
|
revision,
|
|
@@ -167458,11 +167505,11 @@ async function readGitCommits(directory, options3 = {}) {
|
|
|
167458
167505
|
stdout = result.stdout;
|
|
167459
167506
|
} catch (error51) {
|
|
167460
167507
|
const message = error51 instanceof Error ? error51.message : String(error51);
|
|
167461
|
-
log(`[git-commits] readGitCommits failed
|
|
167508
|
+
log(`[git-commits] readGitCommits failed for ${projectLabel}: ${message.slice(0, 500)}`);
|
|
167462
167509
|
return [];
|
|
167463
167510
|
}
|
|
167464
167511
|
if (stdout.trim().length === 0) {
|
|
167465
|
-
log(`[git-commits] readGitCommits returned empty stdout
|
|
167512
|
+
log(`[git-commits] readGitCommits returned empty stdout for ${projectLabel} (sinceMs=${options3.sinceMs ?? "none"} args=${args.slice(0, 4).join(" ")})`);
|
|
167466
167513
|
}
|
|
167467
167514
|
return parseGitLogOutput(stdout);
|
|
167468
167515
|
}
|
|
@@ -167506,11 +167553,7 @@ ${body}` : subject;
|
|
|
167506
167553
|
}
|
|
167507
167554
|
return commits;
|
|
167508
167555
|
}
|
|
167509
|
-
// ../plugin/src/features/magic-context/git-commits/indexer.ts
|
|
167510
|
-
init_logger();
|
|
167511
|
-
|
|
167512
167556
|
// ../plugin/src/features/magic-context/git-commits/storage-git-commits.ts
|
|
167513
|
-
init_logger();
|
|
167514
167557
|
var insertStatements = new WeakMap;
|
|
167515
167558
|
var existingShasStatements = new WeakMap;
|
|
167516
167559
|
var projectCountStatements = new WeakMap;
|
|
@@ -167646,7 +167689,8 @@ async function indexCommitsForProject(db, projectPath, directory, options3) {
|
|
|
167646
167689
|
const sinceMs = latestIndexed !== null ? Math.max(latestIndexed - 60000, Date.now() - options3.sinceDays * MS_PER_DAY) : Date.now() - options3.sinceDays * MS_PER_DAY;
|
|
167647
167690
|
const commits = await readGitCommits(directory, {
|
|
167648
167691
|
sinceMs,
|
|
167649
|
-
maxCommits: options3.maxCommits
|
|
167692
|
+
maxCommits: options3.maxCommits,
|
|
167693
|
+
projectIdentity: projectPath
|
|
167650
167694
|
});
|
|
167651
167695
|
result.scanned = commits.length;
|
|
167652
167696
|
if (commits.length === 0) {
|
|
@@ -167722,7 +167766,6 @@ async function embedUnembeddedCommits(db, projectPath) {
|
|
|
167722
167766
|
}
|
|
167723
167767
|
}
|
|
167724
167768
|
// ../plugin/src/features/magic-context/git-commits/search-git-commits.ts
|
|
167725
|
-
init_logger();
|
|
167726
167769
|
var ftsStatements = new WeakMap;
|
|
167727
167770
|
var ftsPlainStatements = new WeakMap;
|
|
167728
167771
|
var getBySHAStatements = new WeakMap;
|
|
@@ -168393,9 +168436,6 @@ class BoundedSessionMap {
|
|
|
168393
168436
|
}
|
|
168394
168437
|
}
|
|
168395
168438
|
|
|
168396
|
-
// ../plugin/src/hooks/magic-context/inject-compartments.ts
|
|
168397
|
-
init_logger();
|
|
168398
|
-
|
|
168399
168439
|
// ../plugin/src/hooks/magic-context/decay-curve.ts
|
|
168400
168440
|
var H50 = 24;
|
|
168401
168441
|
var D = 25;
|
|
@@ -168570,26 +168610,58 @@ import { join as join9, sep as sep2 } from "node:path";
|
|
|
168570
168610
|
var import_comment_json2 = __toESM(require_src2(), 1);
|
|
168571
168611
|
import { existsSync as existsSync7, readFileSync as readFileSync5 } from "node:fs";
|
|
168572
168612
|
import { homedir as homedir4 } from "node:os";
|
|
168573
|
-
import { join as join8 } from "node:path";
|
|
168613
|
+
import { isAbsolute as isAbsolute2, join as join8, resolve as resolve3 } from "node:path";
|
|
168614
|
+
import { fileURLToPath } from "node:url";
|
|
168574
168615
|
var overrideAvailability = null;
|
|
168575
168616
|
function parseConfig(path5) {
|
|
168576
168617
|
if (!existsSync7(path5))
|
|
168577
168618
|
return null;
|
|
168578
168619
|
return import_comment_json2.parse(readFileSync5(path5, "utf-8"));
|
|
168579
168620
|
}
|
|
168580
|
-
|
|
168621
|
+
var AFT_NAME_NEEDLES = ["@cortexkit/aft", "aft-opencode", "aft-pi"];
|
|
168622
|
+
function stringMentionsAft(value) {
|
|
168623
|
+
return AFT_NAME_NEEDLES.some((needle) => value.includes(needle));
|
|
168624
|
+
}
|
|
168625
|
+
function resolveLocalEntryPackageName(value, configDir) {
|
|
168626
|
+
let dir = null;
|
|
168627
|
+
if (value.startsWith("file://")) {
|
|
168628
|
+
try {
|
|
168629
|
+
dir = fileURLToPath(value);
|
|
168630
|
+
} catch {
|
|
168631
|
+
return null;
|
|
168632
|
+
}
|
|
168633
|
+
} else if (value.startsWith("~/")) {
|
|
168634
|
+
dir = join8(homedir4(), value.slice(2));
|
|
168635
|
+
} else if (value.startsWith("/") || value.startsWith("./") || value.startsWith("../")) {
|
|
168636
|
+
dir = isAbsolute2(value) ? value : resolve3(configDir, value);
|
|
168637
|
+
} else {
|
|
168638
|
+
return null;
|
|
168639
|
+
}
|
|
168640
|
+
try {
|
|
168641
|
+
const pkg = JSON.parse(readFileSync5(join8(dir, "package.json"), "utf-8"));
|
|
168642
|
+
return typeof pkg.name === "string" ? pkg.name : null;
|
|
168643
|
+
} catch {
|
|
168644
|
+
return null;
|
|
168645
|
+
}
|
|
168646
|
+
}
|
|
168647
|
+
function entryMatchesAft(entry, configDir) {
|
|
168581
168648
|
const value = Array.isArray(entry) ? entry[0] : entry;
|
|
168582
|
-
|
|
168649
|
+
if (typeof value !== "string")
|
|
168650
|
+
return false;
|
|
168651
|
+
if (stringMentionsAft(value))
|
|
168652
|
+
return true;
|
|
168653
|
+
const name2 = resolveLocalEntryPackageName(value, configDir);
|
|
168654
|
+
return name2 != null && stringMentionsAft(name2);
|
|
168583
168655
|
}
|
|
168584
|
-
function hasAftInArray(value) {
|
|
168585
|
-
return Array.isArray(value) && value.some(entryMatchesAft);
|
|
168656
|
+
function hasAftInArray(value, configDir) {
|
|
168657
|
+
return Array.isArray(value) && value.some((entry) => entryMatchesAft(entry, configDir));
|
|
168586
168658
|
}
|
|
168587
|
-
function hasAftAtKeys(value, keys2) {
|
|
168659
|
+
function hasAftAtKeys(value, keys2, configDir) {
|
|
168588
168660
|
if (!value || typeof value !== "object")
|
|
168589
168661
|
return false;
|
|
168590
168662
|
const record4 = value;
|
|
168591
168663
|
for (const key of keys2) {
|
|
168592
|
-
if (hasAftInArray(record4[key]))
|
|
168664
|
+
if (hasAftInArray(record4[key], configDir))
|
|
168593
168665
|
return true;
|
|
168594
168666
|
}
|
|
168595
168667
|
return false;
|
|
@@ -168606,7 +168678,8 @@ function getAftAvailability() {
|
|
|
168606
168678
|
for (const path5 of opencodePaths) {
|
|
168607
168679
|
try {
|
|
168608
168680
|
const config2 = parseConfig(path5);
|
|
168609
|
-
|
|
168681
|
+
const configDir = join8(path5, "..");
|
|
168682
|
+
if (hasAftAtKeys(config2, ["plugin", "plugins", "mcp", "mcp_servers"], configDir)) {
|
|
168610
168683
|
opencode = true;
|
|
168611
168684
|
break;
|
|
168612
168685
|
}
|
|
@@ -168616,12 +168689,13 @@ function getAftAvailability() {
|
|
|
168616
168689
|
for (const path5 of piPaths) {
|
|
168617
168690
|
try {
|
|
168618
168691
|
const config2 = parseConfig(path5);
|
|
168619
|
-
|
|
168692
|
+
const configDir = join8(path5, "..");
|
|
168693
|
+
if (hasAftAtKeys(config2, ["packages", "extensions"], configDir)) {
|
|
168620
168694
|
pi = true;
|
|
168621
168695
|
break;
|
|
168622
168696
|
}
|
|
168623
168697
|
const agent = config2?.agent;
|
|
168624
|
-
if (hasAftAtKeys(agent, ["packages", "extensions"])) {
|
|
168698
|
+
if (hasAftAtKeys(agent, ["packages", "extensions"], configDir)) {
|
|
168625
168699
|
pi = true;
|
|
168626
168700
|
break;
|
|
168627
168701
|
}
|
|
@@ -168640,7 +168714,6 @@ function isAftAvailable() {
|
|
|
168640
168714
|
}
|
|
168641
168715
|
|
|
168642
168716
|
// ../plugin/src/hooks/magic-context/key-files-block.ts
|
|
168643
|
-
init_logger();
|
|
168644
168717
|
var cachedKeyFilesBySession = new Map;
|
|
168645
168718
|
var staleUpdates = new Map;
|
|
168646
168719
|
function staleKey(update2) {
|
|
@@ -168738,9 +168811,6 @@ ${blocks.join(`
|
|
|
168738
168811
|
return rendered;
|
|
168739
168812
|
}
|
|
168740
168813
|
|
|
168741
|
-
// ../plugin/src/hooks/magic-context/inject-compartments.ts
|
|
168742
|
-
await init_read_session_db();
|
|
168743
|
-
|
|
168744
168814
|
// ../plugin/src/hooks/magic-context/temporal-awareness.ts
|
|
168745
168815
|
var TEMPORAL_AWARENESS_THRESHOLD_SECONDS = 300;
|
|
168746
168816
|
var SECONDS_PER_MINUTE = 60;
|