@cortexkit/pi-magic-context 0.49.11 → 0.49.12
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/auto-search-worker.js +4 -4
- package/dist/{compaction-marker-candidates-n4dphyz4.js → compaction-marker-candidates-k4tqg4jb.js} +2 -2
- package/dist/compaction-marker-candidates-worker.js +1 -1
- package/dist/embedding-backfill-14tqcfrn.js +20 -0
- package/dist/embedding-worker-process.js +1 -1
- package/dist/embedding-worker.js +5 -5
- package/dist/historian-calibration-extension.js +1 -1
- package/dist/{index-ta0ed2nc.js → index-1k729e4f.js} +15 -15
- package/dist/{index-g13fb2sj.js → index-3cnarwf8.js} +4 -4
- package/dist/{index-729kkhmf.js → index-46q4e104.js} +1 -1
- package/dist/{index-m8aaepft.js → index-53xdqb3d.js} +7 -7
- package/dist/{index-szh001qb.js → index-6dz2ed1v.js} +2 -2
- package/dist/{index-gqxsds3q.js → index-6ex901g3.js} +187 -27
- package/dist/{index-s3c9dskk.js → index-6hex51s9.js} +8 -8
- package/dist/{index-gycf3sp7.js → index-7bqrfyny.js} +46 -2
- package/dist/{index-drah07tf.js → index-af9nb5db.js} +5 -5
- package/dist/{index-3veejgp8.js → index-apgwdby5.js} +1 -1
- package/dist/{index-43zqh10z.js → index-d4dt19md.js} +1 -1
- package/dist/{index-fdxzpnbj.js → index-djxc8w8c.js} +1 -1
- package/dist/{index-x7426vy4.js → index-ed9d2ded.js} +18 -5
- package/dist/{index-kh3jt7t9.js → index-f18ec69t.js} +1 -1
- package/dist/{index-78c864c8.js → index-f6e8jsrh.js} +140 -17
- package/dist/{index-4pxydwvg.js → index-g4jf772p.js} +1 -1
- package/dist/{index-2df03yc3.js → index-gykw2zhn.js} +8 -8
- package/dist/{index-4vj37yw9.js → index-he9s4qsj.js} +16 -6
- package/dist/{index-8yjhda46.js → index-j24916mq.js} +3 -3
- package/dist/{index-ttxsmaj5.js → index-jrap43gc.js} +1 -1
- package/dist/{index-s9kwv5pp.js → index-xpsht877.js} +5 -5
- package/dist/{index-9azmm7cg.js → index-z5ftst3e.js} +9 -9
- package/dist/{index-0vq6ebae.js → index-zapgkmp7.js} +29 -24
- package/dist/index.js +340 -203
- package/dist/{logger-qg51hmp7.js → logger-dygt96rn.js} +1 -1
- package/dist/{message-index-bounded-chgr6dn3.js → message-index-bounded-ws37m1nt.js} +13 -13
- package/dist/{message-index-5zjmsg57.js → message-index-dfs6k35a.js} +13 -13
- package/dist/{message-time-backfill-q9s88zdv.js → message-time-backfill-r2ar1qvk.js} +2 -2
- package/dist/migration-worker.js +9 -9
- package/dist/{project-embedding-registry-dk5axctd.js → project-embedding-registry-ymvne11v.js} +10 -10
- package/dist/raw-ordinal-warmup-worker.js +12 -7
- package/dist/{read-session-chunk-3kb7r5pq.js → read-session-chunk-83864b37.js} +8 -8
- package/dist/{read-session-raw-hm7ptnrh.js → read-session-raw-azkqjgzg.js} +6 -2
- package/dist/{safe-notification-target-62ty6rvp.js → safe-notification-target-2rkvkmw8.js} +2 -2
- package/dist/{search-8pczyejh.js → search-85e21wb8.js} +19 -19
- package/dist/{storage-tags-zh23ynsh.js → storage-tags-zmf30zqp.js} +6 -4
- package/dist/subagent-entry.js +22 -22
- package/package.json +1 -1
- package/dist/embedding-backfill-1tknh2jn.js +0 -20
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getMagicContextStorageDir,
|
|
3
3
|
log2
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-7bqrfyny.js";
|
|
5
5
|
import {
|
|
6
6
|
inRootAsyncContext2
|
|
7
7
|
} from "./index-asrxgdt4.js";
|
|
8
8
|
import {
|
|
9
9
|
projectDirectoryKey
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-djxc8w8c.js";
|
|
11
11
|
import {
|
|
12
12
|
writeStorageFileAtomicSync
|
|
13
13
|
} from "./index-81nthk8j.js";
|
|
@@ -15,9 +15,9 @@ import {
|
|
|
15
15
|
// ../plugin/src/features/magic-context/memory/project-identity.ts
|
|
16
16
|
import { execFileSync } from "node:child_process";
|
|
17
17
|
import { createHash as createHash2 } from "node:crypto";
|
|
18
|
-
import { existsSync, realpathSync, statSync } from "node:fs";
|
|
18
|
+
import { existsSync, realpathSync as realpathSync2, statSync as statSync2 } from "node:fs";
|
|
19
19
|
import { homedir } from "node:os";
|
|
20
|
-
import
|
|
20
|
+
import path3 from "node:path";
|
|
21
21
|
|
|
22
22
|
// ../plugin/src/features/magic-context/memory/project-identity-cache.ts
|
|
23
23
|
import { createHash } from "node:crypto";
|
|
@@ -42,6 +42,162 @@ function readRememberedGitIdentity(directory, storageDir) {
|
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
// ../plugin/src/features/magic-context/memory/unborn-head.ts
|
|
46
|
+
import { readFileSync as readFileSync2, realpathSync, statSync } from "node:fs";
|
|
47
|
+
import path2 from "node:path";
|
|
48
|
+
var GIT_LOCATION_ENV_VARS = [
|
|
49
|
+
"GIT_DIR",
|
|
50
|
+
"GIT_COMMON_DIR",
|
|
51
|
+
"GIT_WORK_TREE",
|
|
52
|
+
"GIT_CEILING_DIRECTORIES"
|
|
53
|
+
];
|
|
54
|
+
function errorCode(error) {
|
|
55
|
+
if (error === null || typeof error !== "object" || !("code" in error))
|
|
56
|
+
return;
|
|
57
|
+
const code = error.code;
|
|
58
|
+
return typeof code === "string" ? code : undefined;
|
|
59
|
+
}
|
|
60
|
+
function readText(file) {
|
|
61
|
+
try {
|
|
62
|
+
return { ok: true, text: readFileSync2(file, "utf8") };
|
|
63
|
+
} catch (error) {
|
|
64
|
+
return { ok: false, missing: errorCode(error) === "ENOENT" };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function entryKind(entry) {
|
|
68
|
+
try {
|
|
69
|
+
const stat = statSync(entry);
|
|
70
|
+
if (stat.isFile())
|
|
71
|
+
return "file";
|
|
72
|
+
if (stat.isDirectory())
|
|
73
|
+
return "directory";
|
|
74
|
+
return "other";
|
|
75
|
+
} catch (error) {
|
|
76
|
+
return errorCode(error) === "ENOENT" ? "missing" : "error";
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function stripLineEnding(text) {
|
|
80
|
+
return text.replace(/\r?\n$/u, "");
|
|
81
|
+
}
|
|
82
|
+
function resolveMetadataPath(baseDirectory, value) {
|
|
83
|
+
return path2.resolve(baseDirectory, value);
|
|
84
|
+
}
|
|
85
|
+
function isPlainBranchName(name) {
|
|
86
|
+
if (name.length === 0 || name.endsWith("/") || name.endsWith("."))
|
|
87
|
+
return false;
|
|
88
|
+
if (name.includes("..") || name.includes("//") || name.includes("@{"))
|
|
89
|
+
return false;
|
|
90
|
+
for (const character of name) {
|
|
91
|
+
const code = character.charCodeAt(0);
|
|
92
|
+
if (code <= 32 || code === 127 || "~^:?*[\\".includes(character))
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return name.split("/").every((component) => !component.startsWith(".") && !component.endsWith(".lock"));
|
|
96
|
+
}
|
|
97
|
+
function findGitDirectory(start) {
|
|
98
|
+
let current = start;
|
|
99
|
+
while (true) {
|
|
100
|
+
const dotGit = path2.join(current, ".git");
|
|
101
|
+
const kind = entryKind(dotGit);
|
|
102
|
+
if (kind === "directory")
|
|
103
|
+
return dotGit;
|
|
104
|
+
if (kind === "file") {
|
|
105
|
+
const read = readText(dotGit);
|
|
106
|
+
if (!read.ok)
|
|
107
|
+
return;
|
|
108
|
+
const match = /^gitdir: (.+)$/u.exec(stripLineEnding(read.text));
|
|
109
|
+
if (!match?.[1] || match[1].includes(`
|
|
110
|
+
`))
|
|
111
|
+
return;
|
|
112
|
+
return resolveMetadataPath(current, match[1]);
|
|
113
|
+
}
|
|
114
|
+
if (kind !== "missing")
|
|
115
|
+
return;
|
|
116
|
+
const parent = path2.dirname(current);
|
|
117
|
+
if (parent === current)
|
|
118
|
+
return;
|
|
119
|
+
current = parent;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function packedRefsList(text, ref) {
|
|
123
|
+
for (const rawLine of text.split(`
|
|
124
|
+
`)) {
|
|
125
|
+
const line = rawLine.replace(/\r$/u, "");
|
|
126
|
+
if (line === "" || line.startsWith("#") || line.startsWith("^"))
|
|
127
|
+
continue;
|
|
128
|
+
const match = /^[0-9a-f]{40,64} (\S+)$/u.exec(line);
|
|
129
|
+
if (!match)
|
|
130
|
+
return;
|
|
131
|
+
if (match[1] === ref)
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
function isUnbornHeadInLayout(directory) {
|
|
137
|
+
const gitDirectory = findGitDirectory(directory);
|
|
138
|
+
if (gitDirectory === undefined)
|
|
139
|
+
return false;
|
|
140
|
+
let commonDirectory = gitDirectory;
|
|
141
|
+
const commondir = readText(path2.join(gitDirectory, "commondir"));
|
|
142
|
+
if (commondir.ok) {
|
|
143
|
+
const value = stripLineEnding(commondir.text);
|
|
144
|
+
if (value === "" || value.includes(`
|
|
145
|
+
`))
|
|
146
|
+
return false;
|
|
147
|
+
commonDirectory = resolveMetadataPath(gitDirectory, value);
|
|
148
|
+
} else if (!commondir.missing) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
if (entryKind(path2.join(gitDirectory, "HEAD")) !== "file")
|
|
152
|
+
return false;
|
|
153
|
+
if (entryKind(path2.join(commonDirectory, "objects")) !== "directory")
|
|
154
|
+
return false;
|
|
155
|
+
if (entryKind(path2.join(commonDirectory, "refs")) !== "directory")
|
|
156
|
+
return false;
|
|
157
|
+
if (entryKind(path2.join(commonDirectory, "reftable")) !== "missing")
|
|
158
|
+
return false;
|
|
159
|
+
const config = readText(path2.join(commonDirectory, "config"));
|
|
160
|
+
if (config.ok) {
|
|
161
|
+
if (/refstorage/iu.test(config.text))
|
|
162
|
+
return false;
|
|
163
|
+
} else if (!config.missing) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
const head = readText(path2.join(gitDirectory, "HEAD"));
|
|
167
|
+
if (!head.ok)
|
|
168
|
+
return false;
|
|
169
|
+
const headMatch = /^ref: (refs\/heads\/(.+))$/u.exec(head.text.replace(/\s+$/u, ""));
|
|
170
|
+
const ref = headMatch?.[1];
|
|
171
|
+
const branch = headMatch?.[2];
|
|
172
|
+
if (!ref || branch === undefined || !isPlainBranchName(branch))
|
|
173
|
+
return false;
|
|
174
|
+
const refSegments = ref.split("/");
|
|
175
|
+
for (const base of new Set([commonDirectory, gitDirectory])) {
|
|
176
|
+
if (entryKind(path2.join(base, ...refSegments)) !== "missing")
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
const packed = readText(path2.join(commonDirectory, "packed-refs"));
|
|
180
|
+
if (packed.ok) {
|
|
181
|
+
if (packedRefsList(packed.text, ref) !== false)
|
|
182
|
+
return false;
|
|
183
|
+
} else if (!packed.missing) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
function isUnbornHeadOnDisk(directory, env = process.env) {
|
|
189
|
+
if (GIT_LOCATION_ENV_VARS.some((name) => env[name] !== undefined && env[name] !== "")) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
let realDirectory;
|
|
193
|
+
try {
|
|
194
|
+
realDirectory = realpathSync.native(path2.resolve(directory));
|
|
195
|
+
} catch {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
return isUnbornHeadInLayout(realDirectory);
|
|
199
|
+
}
|
|
200
|
+
|
|
45
201
|
// ../plugin/src/features/magic-context/memory/project-identity.ts
|
|
46
202
|
var GIT_TIMEOUT_MS = 5000;
|
|
47
203
|
var TRANSIENT_FAILURE_COOLDOWN_MS = 5 * 60 * 1000;
|
|
@@ -62,6 +218,7 @@ function setHomeProjectPermission(allowed) {
|
|
|
62
218
|
homeProjectPermission = allowed;
|
|
63
219
|
}
|
|
64
220
|
var execFileSyncForIdentity = execFileSync;
|
|
221
|
+
var gitTimeoutMs = GIT_TIMEOUT_MS;
|
|
65
222
|
var userHomeDirectoryForIdentity = () => homedir();
|
|
66
223
|
var nowMs = () => Date.now();
|
|
67
224
|
var filesystemProbeObserverForTests;
|
|
@@ -116,7 +273,7 @@ function getErrorStderr(error) {
|
|
|
116
273
|
return "";
|
|
117
274
|
}
|
|
118
275
|
function directoryFallback(directory) {
|
|
119
|
-
const canonical =
|
|
276
|
+
const canonical = path3.resolve(directory);
|
|
120
277
|
const hash = createHash2("md5").update(canonical, "utf8").digest("hex").slice(0, 12);
|
|
121
278
|
return `dir:${hash}`;
|
|
122
279
|
}
|
|
@@ -125,7 +282,7 @@ function rememberedIdentityOrDirectoryFallback(canonical) {
|
|
|
125
282
|
}
|
|
126
283
|
function assertDirectoryUsable(canonicalDirectory, rawDirectory) {
|
|
127
284
|
try {
|
|
128
|
-
const stat =
|
|
285
|
+
const stat = statSync2(canonicalDirectory);
|
|
129
286
|
if (!stat.isDirectory()) {
|
|
130
287
|
throw new ProjectIdentityError("unknown", rawDirectory, `Project path is not a directory: ${canonicalDirectory}`);
|
|
131
288
|
}
|
|
@@ -151,7 +308,7 @@ function hasUnbornHead(directory) {
|
|
|
151
308
|
encoding: "utf8",
|
|
152
309
|
env: { ...process.env, LC_ALL: "C", LANG: "C" },
|
|
153
310
|
stdio: ["ignore", "pipe", "pipe"],
|
|
154
|
-
timeout:
|
|
311
|
+
timeout: gitTimeoutMs,
|
|
155
312
|
windowsHide: true
|
|
156
313
|
};
|
|
157
314
|
try {
|
|
@@ -168,7 +325,7 @@ function hasUnbornHead(directory) {
|
|
|
168
325
|
}
|
|
169
326
|
function classifyGitError(error, rawDirectory) {
|
|
170
327
|
if (isGitTimeoutError(error)) {
|
|
171
|
-
return new ProjectIdentityError("git_timeout", rawDirectory, `git rev-list timed out after ${
|
|
328
|
+
return new ProjectIdentityError("git_timeout", rawDirectory, `git rev-list timed out after ${gitTimeoutMs}ms`, asError(error));
|
|
172
329
|
}
|
|
173
330
|
const code = getErrorCode(error);
|
|
174
331
|
if (code === "ENOENT") {
|
|
@@ -188,7 +345,7 @@ function classifyGitError(error, rawDirectory) {
|
|
|
188
345
|
}
|
|
189
346
|
function resolveProjectIdentityStrict(directory, allowHomeProject = homeProjectPermission, options = {}) {
|
|
190
347
|
assertProjectAllowed(directory, allowHomeProject);
|
|
191
|
-
const canonical =
|
|
348
|
+
const canonical = path3.resolve(directory);
|
|
192
349
|
const cached = options.cache === false ? undefined : identityCache.get(canonical);
|
|
193
350
|
if (cached !== undefined) {
|
|
194
351
|
return cached;
|
|
@@ -197,6 +354,9 @@ function resolveProjectIdentityStrict(directory, allowHomeProject = homeProjectP
|
|
|
197
354
|
if (!hasGitDir(canonical)) {
|
|
198
355
|
throw new ProjectIdentityError("not_git_repo", directory, "Directory has no git metadata; caller may use directory fallback");
|
|
199
356
|
}
|
|
357
|
+
if (isUnbornHeadOnDisk(canonical)) {
|
|
358
|
+
throw new ProjectIdentityError("no_commits", directory, "Git repository has no commits yet");
|
|
359
|
+
}
|
|
200
360
|
let output;
|
|
201
361
|
try {
|
|
202
362
|
output = execFileSyncForIdentity("git", ["rev-list", "--max-parents=0", "HEAD"], {
|
|
@@ -204,7 +364,7 @@ function resolveProjectIdentityStrict(directory, allowHomeProject = homeProjectP
|
|
|
204
364
|
encoding: "utf8",
|
|
205
365
|
env: { ...process.env, LC_ALL: "C", LANG: "C" },
|
|
206
366
|
stdio: ["ignore", "pipe", "pipe"],
|
|
207
|
-
timeout:
|
|
367
|
+
timeout: gitTimeoutMs,
|
|
208
368
|
windowsHide: true
|
|
209
369
|
});
|
|
210
370
|
} catch (error) {
|
|
@@ -257,9 +417,9 @@ function nearestLastKnownGitIdentity(canonical) {
|
|
|
257
417
|
const cached = lastKnownGitIdentity(current);
|
|
258
418
|
if (cached !== undefined)
|
|
259
419
|
return { identity: cached, source: current };
|
|
260
|
-
if (existsSync(
|
|
420
|
+
if (existsSync(path3.join(current, ".git")))
|
|
261
421
|
break;
|
|
262
|
-
const parent =
|
|
422
|
+
const parent = path3.dirname(current);
|
|
263
423
|
if (parent === current)
|
|
264
424
|
break;
|
|
265
425
|
current = parent;
|
|
@@ -270,7 +430,7 @@ function nearestLastKnownGitIdentity(canonical) {
|
|
|
270
430
|
if (exactOrAncestor)
|
|
271
431
|
return exactOrAncestor;
|
|
272
432
|
try {
|
|
273
|
-
const realCanonical =
|
|
433
|
+
const realCanonical = realpathSync2.native(canonical);
|
|
274
434
|
if (realCanonical !== canonical)
|
|
275
435
|
return walk(realCanonical);
|
|
276
436
|
} catch {}
|
|
@@ -300,7 +460,7 @@ function recordDubiousOwnershipFallback(canonical) {
|
|
|
300
460
|
function canonicalUserHomeDirectory() {
|
|
301
461
|
const homeDirectory = userHomeDirectoryForIdentity();
|
|
302
462
|
try {
|
|
303
|
-
return
|
|
463
|
+
return realpathSync2.native(homeDirectory);
|
|
304
464
|
} catch {
|
|
305
465
|
return homeDirectory;
|
|
306
466
|
}
|
|
@@ -309,20 +469,20 @@ function isUserHomeDirectory(directory) {
|
|
|
309
469
|
if (projectDirectoryKey(directory) === projectDirectoryKey(userHomeDirectoryForIdentity()))
|
|
310
470
|
return true;
|
|
311
471
|
try {
|
|
312
|
-
return projectDirectoryKey(
|
|
472
|
+
return projectDirectoryKey(realpathSync2.native(path3.resolve(directory))) === projectDirectoryKey(canonicalUserHomeDirectory());
|
|
313
473
|
} catch {
|
|
314
474
|
return false;
|
|
315
475
|
}
|
|
316
476
|
}
|
|
317
477
|
function assertProjectAllowed(directory, allowHomeProject) {
|
|
318
|
-
const canonical =
|
|
478
|
+
const canonical = path3.resolve(directory);
|
|
319
479
|
if (!allowHomeProject && (isUserHomeDirectory(directory) || isUserHomeDirectory(gitRootDirectory(canonical) ?? canonical))) {
|
|
320
480
|
throw new ProjectIdentityError("home_project_disabled", directory, "Home project memory is disabled; set allow_home_project to opt in");
|
|
321
481
|
}
|
|
322
482
|
}
|
|
323
483
|
function resolveProjectIdentity(directory, allowHomeProject = homeProjectPermission) {
|
|
324
484
|
assertProjectAllowed(directory, allowHomeProject);
|
|
325
|
-
const canonical =
|
|
485
|
+
const canonical = path3.resolve(directory);
|
|
326
486
|
const cachedFallback = directoryFallbackCache.get(canonical);
|
|
327
487
|
if (cachedFallback !== undefined) {
|
|
328
488
|
if (!hasGitDir(canonical)) {
|
|
@@ -370,7 +530,7 @@ function resolveProjectIdentityOrFallback(directory, allowHomeProject = homeProj
|
|
|
370
530
|
try {
|
|
371
531
|
return resolveProjectIdentity(directory, allowHomeProject);
|
|
372
532
|
} catch (error) {
|
|
373
|
-
const canonical =
|
|
533
|
+
const canonical = path3.resolve(directory);
|
|
374
534
|
if (hasGitDir(canonical) || error instanceof ProjectIdentityError && error.errorClass === "home_project_disabled")
|
|
375
535
|
throw error;
|
|
376
536
|
const fallback = rememberedIdentityOrDirectoryFallback(canonical);
|
|
@@ -384,7 +544,7 @@ function hasGitDir(canonical) {
|
|
|
384
544
|
return true;
|
|
385
545
|
}
|
|
386
546
|
try {
|
|
387
|
-
const realCanonical =
|
|
547
|
+
const realCanonical = realpathSync2.native(canonical);
|
|
388
548
|
return realCanonical !== canonical && hasGitDirInAncestorChain(realCanonical);
|
|
389
549
|
} catch {
|
|
390
550
|
return false;
|
|
@@ -393,14 +553,14 @@ function hasGitDir(canonical) {
|
|
|
393
553
|
function gitRootInAncestorChain(startDirectory) {
|
|
394
554
|
let current = startDirectory;
|
|
395
555
|
while (true) {
|
|
396
|
-
if (existsSync(
|
|
556
|
+
if (existsSync(path3.join(current, ".git"))) {
|
|
397
557
|
try {
|
|
398
|
-
return
|
|
558
|
+
return realpathSync2.native(current);
|
|
399
559
|
} catch {
|
|
400
|
-
return
|
|
560
|
+
return path3.resolve(current);
|
|
401
561
|
}
|
|
402
562
|
}
|
|
403
|
-
const parent =
|
|
563
|
+
const parent = path3.dirname(current);
|
|
404
564
|
if (parent === current) {
|
|
405
565
|
return null;
|
|
406
566
|
}
|
|
@@ -415,20 +575,20 @@ function gitRootDirectory(canonical) {
|
|
|
415
575
|
if (direct)
|
|
416
576
|
return direct;
|
|
417
577
|
try {
|
|
418
|
-
const realCanonical =
|
|
578
|
+
const realCanonical = realpathSync2.native(canonical);
|
|
419
579
|
return realCanonical === canonical ? null : gitRootInAncestorChain(realCanonical);
|
|
420
580
|
} catch {
|
|
421
581
|
return null;
|
|
422
582
|
}
|
|
423
583
|
}
|
|
424
584
|
function directoryHasGitMetadata(directory) {
|
|
425
|
-
return gitRootDirectory(
|
|
585
|
+
return gitRootDirectory(path3.resolve(directory)) !== null;
|
|
426
586
|
}
|
|
427
587
|
function isUsableProjectIdentity(identity) {
|
|
428
588
|
return typeof identity === "string" && identity.trim().length > 0;
|
|
429
589
|
}
|
|
430
590
|
function resolveProjectIdentityForSession(directory, allowHomeProject = homeProjectPermission) {
|
|
431
|
-
const resolvedDirectory =
|
|
591
|
+
const resolvedDirectory = path3.resolve(directory);
|
|
432
592
|
const cacheKey = `${allowHomeProject ? "1" : "0"}\x00${resolvedDirectory}`;
|
|
433
593
|
const cached = sessionIdentityCache.get(cacheKey);
|
|
434
594
|
if (cached && (cached.revalidateAt === null || nowMs() < cached.revalidateAt) && !(cached.identity?.startsWith("dir:") && hasGitDir(resolvedDirectory))) {
|
|
@@ -439,7 +599,7 @@ function resolveProjectIdentityForSession(directory, allowHomeProject = homeProj
|
|
|
439
599
|
const canonicalDirectory = (() => {
|
|
440
600
|
try {
|
|
441
601
|
filesystemProbeObserverForTests?.();
|
|
442
|
-
return
|
|
602
|
+
return realpathSync2.native(resolvedDirectory);
|
|
443
603
|
} catch {
|
|
444
604
|
return resolvedDirectory;
|
|
445
605
|
}
|
|
@@ -3,16 +3,16 @@ import {
|
|
|
3
3
|
} from "./index-0h2mkab2.js";
|
|
4
4
|
import {
|
|
5
5
|
getMagicContextStorageDir
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-7bqrfyny.js";
|
|
7
7
|
import {
|
|
8
8
|
isPidAlive,
|
|
9
9
|
readProcessStartTime
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-apgwdby5.js";
|
|
11
11
|
import {
|
|
12
12
|
removeSystemReminders,
|
|
13
13
|
hasMeaningfulUserText2,
|
|
14
14
|
extractTexts2
|
|
15
|
-
} from "./index-
|
|
15
|
+
} from "./index-g4jf772p.js";
|
|
16
16
|
import {
|
|
17
17
|
withSqliteBackgroundWriter2,
|
|
18
18
|
withoutSqliteTransformPass2
|
|
@@ -22,10 +22,10 @@ import {
|
|
|
22
22
|
recordIndexedMessageTime,
|
|
23
23
|
messageFtsOrdinalRangeIsMapped,
|
|
24
24
|
deleteUnmappedMessageFtsRows
|
|
25
|
-
} from "./index-
|
|
25
|
+
} from "./index-djxc8w8c.js";
|
|
26
26
|
import {
|
|
27
27
|
deleteChunkEmbedBackoffForSession
|
|
28
|
-
} from "./index-
|
|
28
|
+
} from "./index-af9nb5db.js";
|
|
29
29
|
import {
|
|
30
30
|
closeQuietly,
|
|
31
31
|
TAG_TOMBSTONE_OWNER_PREFIX,
|
|
@@ -34,13 +34,13 @@ import {
|
|
|
34
34
|
tagRevisionKey,
|
|
35
35
|
tagIdentityRevisionKey,
|
|
36
36
|
deleteTagIdentityRevisions
|
|
37
|
-
} from "./index-
|
|
37
|
+
} from "./index-jrap43gc.js";
|
|
38
38
|
import {
|
|
39
39
|
cleanUserText2
|
|
40
|
-
} from "./index-
|
|
40
|
+
} from "./index-53xdqb3d.js";
|
|
41
41
|
import {
|
|
42
42
|
logSlowWriteTransaction
|
|
43
|
-
} from "./index-
|
|
43
|
+
} from "./index-d4dt19md.js";
|
|
44
44
|
import {
|
|
45
45
|
ensurePrivateStorageDirectorySync,
|
|
46
46
|
writeStorageFileSync,
|
|
@@ -7,7 +7,15 @@ import * as fs from "node:fs";
|
|
|
7
7
|
import * as path2 from "node:path";
|
|
8
8
|
|
|
9
9
|
// ../plugin/src/shared/data-path.ts
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
existsSync,
|
|
12
|
+
lstatSync,
|
|
13
|
+
mkdirSync,
|
|
14
|
+
readFileSync,
|
|
15
|
+
readlinkSync,
|
|
16
|
+
realpathSync,
|
|
17
|
+
writeFileSync
|
|
18
|
+
} from "node:fs";
|
|
11
19
|
import * as os from "node:os";
|
|
12
20
|
import * as path from "node:path";
|
|
13
21
|
|
|
@@ -99,6 +107,42 @@ function getMagicContextStorageResolution() {
|
|
|
99
107
|
function getMagicContextStorageDir() {
|
|
100
108
|
return getMagicContextStorageResolution().path;
|
|
101
109
|
}
|
|
110
|
+
function canonicalizeStoragePath(value, seen = new Set) {
|
|
111
|
+
const absolute = path.resolve(value);
|
|
112
|
+
if (seen.has(absolute))
|
|
113
|
+
return absolute;
|
|
114
|
+
seen.add(absolute);
|
|
115
|
+
try {
|
|
116
|
+
return realpathSync.native(absolute);
|
|
117
|
+
} catch {
|
|
118
|
+
try {
|
|
119
|
+
if (lstatSync(absolute).isSymbolicLink()) {
|
|
120
|
+
const target = readlinkSync(absolute);
|
|
121
|
+
const resolvedTarget = path.isAbsolute(target) ? target : path.resolve(path.dirname(absolute), target);
|
|
122
|
+
return canonicalizeStoragePath(resolvedTarget, seen);
|
|
123
|
+
}
|
|
124
|
+
} catch {}
|
|
125
|
+
const parent = path.dirname(absolute);
|
|
126
|
+
if (parent === absolute)
|
|
127
|
+
return absolute;
|
|
128
|
+
const resolvedParent = canonicalizeStoragePath(parent, seen);
|
|
129
|
+
return path.resolve(resolvedParent, path.basename(absolute));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function isMagicContextStorageOutsideEngram(storageDir = getMagicContextStorageDir(), backupDir = path.join(os.homedir(), ".local", "share", "cortexkit", "magic-context")) {
|
|
133
|
+
const resolvedStorageDir = canonicalizeStoragePath(storageDir);
|
|
134
|
+
const resolvedBackupDir = canonicalizeStoragePath(backupDir);
|
|
135
|
+
const relative2 = path.relative(resolvedBackupDir, resolvedStorageDir);
|
|
136
|
+
return path.isAbsolute(relative2) || relative2 === ".." || relative2.startsWith(`..${path.sep}`);
|
|
137
|
+
}
|
|
138
|
+
var STORAGE_BACKUP_WARNING_CHECKED = Symbol.for("magic-context.storage-backup-warning-checked");
|
|
139
|
+
function claimStorageBackupWarningCheck() {
|
|
140
|
+
const processState = globalThis;
|
|
141
|
+
if (processState[STORAGE_BACKUP_WARNING_CHECKED])
|
|
142
|
+
return false;
|
|
143
|
+
processState[STORAGE_BACKUP_WARNING_CHECKED] = true;
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
102
146
|
function getLegacyOpenCodeMagicContextStorageDir() {
|
|
103
147
|
return path.join(getOpenCodeStorageDir(), "plugin", "magic-context");
|
|
104
148
|
}
|
|
@@ -655,4 +699,4 @@ if (!isTestEnv) {
|
|
|
655
699
|
process.on("exit", flush);
|
|
656
700
|
}
|
|
657
701
|
|
|
658
|
-
export { getDataDir, ensureCortexKitArtifactGitignore, getProjectMagicContextHistorianDir, getMagicContextStorageDir, getLegacyOpenCodeMagicContextStorageDir, sanitizeDiagnosticText, hasShareabilitySensitiveText, registerStalePluginBuildHost, classifyStalePluginBuild, importPluginModule, setLogLineForwarder2, writeForwardedLogLine2, log2, sessionLog2, getLoggerDiagnostics2, flushLogger2, getLogFilePath2 };
|
|
702
|
+
export { getDataDir, ensureCortexKitArtifactGitignore, getProjectMagicContextHistorianDir, getMagicContextStorageDir, isMagicContextStorageOutsideEngram, claimStorageBackupWarningCheck, getLegacyOpenCodeMagicContextStorageDir, sanitizeDiagnosticText, hasShareabilitySensitiveText, registerStalePluginBuildHost, classifyStalePluginBuild, importPluginModule, setLogLineForwarder2, writeForwardedLogLine2, log2, sessionLog2, getLoggerDiagnostics2, flushLogger2, getLogFilePath2 };
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getTokenEstimatorFingerprint,
|
|
3
3
|
estimateTokens
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-g4jf772p.js";
|
|
5
5
|
import {
|
|
6
6
|
getHarness2
|
|
7
7
|
} from "./index-0h2mkab2.js";
|
|
8
8
|
import {
|
|
9
9
|
log2
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-7bqrfyny.js";
|
|
11
11
|
import {
|
|
12
12
|
isSynapseEmbeddingTruncated
|
|
13
|
-
} from "./index-
|
|
13
|
+
} from "./index-6dz2ed1v.js";
|
|
14
14
|
import {
|
|
15
15
|
messageFtsOrdinalRangeIsMapped
|
|
16
|
-
} from "./index-
|
|
16
|
+
} from "./index-djxc8w8c.js";
|
|
17
17
|
|
|
18
18
|
// ../plugin/src/features/magic-context/compartment-chunk-embedding.ts
|
|
19
19
|
import { createHash } from "node:crypto";
|
|
@@ -1165,4 +1165,4 @@ async function countUnembeddedSessionCompartmentsPolite(db, projectPath, session
|
|
|
1165
1165
|
return count;
|
|
1166
1166
|
}
|
|
1167
1167
|
|
|
1168
|
-
export { CHUNK_WINDOW_SAFETY_RATIO, normalizeCompartmentChunkMaxInputTokens, buildCanonicalChunkTextFromFts, buildCompartmentSummaryFallbackText, canonicalizeInMemoryChunkTextForEmbedding, chunkCanonicalText, chunkEmbeddingWindowsAreCurrent, replaceCompartmentChunkEmbeddings, loadCompartmentChunkEmbeddingsForSearch, loadUnembeddedShadowChunkCandidates, loadUnembeddedCompartmentChunkCandidatesPolite, deleteChunkEmbedBackoffForSession, recordChunkEmbedBackoff, chunkWindowSourceKey, loadUnembeddedSessionChunkCandidatesPolite, countSessionCompartmentEmbedCoverage, countSessionCompartmentEmbedCoveragePolite, countUnembeddedSessionCompartmentsPolite };
|
|
1168
|
+
export { DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS, CHUNK_WINDOW_SAFETY_RATIO, normalizeCompartmentChunkMaxInputTokens, buildCanonicalChunkTextFromFts, buildCompartmentSummaryFallbackText, canonicalizeInMemoryChunkTextForEmbedding, chunkCanonicalText, chunkEmbeddingWindowsAreCurrent, replaceCompartmentChunkEmbeddings, loadCompartmentChunkEmbeddingsForSearch, loadUnembeddedShadowChunkCandidates, loadUnembeddedCompartmentChunkCandidatesPolite, deleteChunkEmbedBackoffForSession, recordChunkEmbedBackoff, chunkWindowSourceKey, loadUnembeddedSessionChunkCandidatesPolite, countSessionCompartmentEmbedCoverage, countSessionCompartmentEmbedCoveragePolite, countUnembeddedSessionCompartmentsPolite };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
estimateTokens
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-g4jf772p.js";
|
|
4
4
|
import {
|
|
5
5
|
getHarness2
|
|
6
6
|
} from "./index-0h2mkab2.js";
|
|
7
7
|
import {
|
|
8
8
|
sessionLog2
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-7bqrfyny.js";
|
|
10
10
|
import {
|
|
11
11
|
getTagIdentityWriteGeneration2,
|
|
12
12
|
getSqliteDatabasePath2
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
jsonHashSink,
|
|
16
16
|
tagOrderConstraintIndex,
|
|
17
17
|
tagIdentityRevisionKey
|
|
18
|
-
} from "./index-
|
|
18
|
+
} from "./index-jrap43gc.js";
|
|
19
19
|
import {
|
|
20
20
|
DEFAULT_PROTECTED_TOOLS,
|
|
21
21
|
normalizeProtectedToolName,
|
|
@@ -2533,6 +2533,19 @@ function insertTag2(db, sessionId, messageId, type, byteSize, tagNumber, reasoni
|
|
|
2533
2533
|
function updateTagStatus2(db, sessionId, tagId, status) {
|
|
2534
2534
|
getUpdateTagStatusStatement(db).run(status, sessionId, tagId);
|
|
2535
2535
|
}
|
|
2536
|
+
var droppedTagStatements = new WeakMap;
|
|
2537
|
+
function markTagDropped2(db, sessionId, tagId, mode) {
|
|
2538
|
+
if (!mode) {
|
|
2539
|
+
updateTagStatus2(db, sessionId, tagId, "dropped");
|
|
2540
|
+
return;
|
|
2541
|
+
}
|
|
2542
|
+
let statement = droppedTagStatements.get(db);
|
|
2543
|
+
if (!statement) {
|
|
2544
|
+
statement = db.prepare("UPDATE tags SET status = ?, drop_mode = ? WHERE session_id = ? AND tag_number = ?");
|
|
2545
|
+
droppedTagStatements.set(db, statement);
|
|
2546
|
+
}
|
|
2547
|
+
statement.run("dropped", mode, sessionId, tagId);
|
|
2548
|
+
}
|
|
2536
2549
|
var inertWhitespaceStatements = new WeakMap;
|
|
2537
2550
|
var inertWhitespaceByNumberStatements = new WeakMap;
|
|
2538
2551
|
function getInertWhitespaceAssistantTagsByNumbers2(db, sessionId, tagNumbers) {
|
|
@@ -3197,7 +3210,7 @@ function getNewestToolTagNumbers2(db, sessionId, limit) {
|
|
|
3197
3210
|
let statement = newestToolTagNumberStatements.get(db);
|
|
3198
3211
|
if (!statement) {
|
|
3199
3212
|
statement = db.prepare(`SELECT tag_number FROM tags
|
|
3200
|
-
WHERE session_id = ? AND type = 'tool'
|
|
3213
|
+
WHERE session_id = ? AND +type = 'tool'
|
|
3201
3214
|
AND typeof(message_id) = 'text'
|
|
3202
3215
|
AND typeof(status) = 'text'
|
|
3203
3216
|
AND typeof(byte_size) IN ('integer', 'real')
|
|
@@ -3367,4 +3380,4 @@ function deleteToolTagsByOwner(db, sessionId, ownerMsgId) {
|
|
|
3367
3380
|
return getDeleteToolTagsByOwnerStatement(db).all(sessionId, ownerMsgId).length;
|
|
3368
3381
|
}
|
|
3369
3382
|
|
|
3370
|
-
export { UNKNOWN_FIT_RATIO, resolveDecisionCalibration, hasMeasuredDecisionCalibration, providerMass, localBudget, calibrationForModelKey, historyLocalBudget, adoptedProtectedToolsPolicy, protectedToolTagNumbers, protectedToolTokenCount, stripWellFormedLeadingTagPrefix, stripPersistedAssistantText, byteSize, stripTagPrefix, peelLeadingMcTagNotation, prependTag, rememberCurrentToolOutputCount, currentReclaimableToolOutputCount, isRecord, TEXT_TAG_IDENTITY_MARKER, PI_FALLBACK_PREFIXES_JSON, contentTagOwnerMessageId, TailHygieneJsonMemo, piJsonHash, estimateImageTokensFromDataUrl, estimateToolAttachmentImageTokens, providerVisiblePart, providerVisibleMessage, TODO_STATUSES, TODO_PRIORITIES, TITLE_DONE_STATUSES, normalizeTodoStateJson, buildSyntheticTodoPart, stripChannel1ReminderSpans, compareMeasuredTailPrefix, formatTailHygienePrefixMismatch, freezeTailHygieneMeasurement, effectiveTailHygiene, CHANNEL1_SENTINEL, CHANNEL1_FLOOR_TOKENS, decideChannel1, evaluateChannel2, buildChannel2Reminder, buildChannel1Reminder, planEmergencyDrop, measureEmergencyTag, queuePendingOp, queuePendingDropForUnchangedTag, getPendingOps, getPendingOpsCount, clearPendingOps, removePendingOp, updateTagByteSize2, getRecentTagOwnerMessageIds2, getActiveTagTokenAggregate2, AGE_RECLAIM_MIN_TOKENS2, getOldestActiveUnprotectedToolTags2, getActiveToolTagsForAgeReclaim2, getTriggerTagTokenUpperBound2, getActiveTagTokenTotalsByMessage2, updateTagInputByteSize2, updateTagTokenCount2, getPersistedToolTagAccounting2, getAllStatusTagTokenTotalsFlat2, getReasoningTokenEstimatesByMessage2, tryGetReasoningTokenEstimatesByMessage2, getMaxTagNumberByOwnerMessage2, scanTagOwnerSummary2, scanTagOwnerDelta2, updateTagInputTokenCount2, tagTokenCountIsNull2, backfillTagTokenCounts2, insertTag2, updateTagStatus2, getInertWhitespaceAssistantTagsByNumbers2, updateTagDropMode2, updateCavemanDepth2, updateTagMessageId2, hasPiFallbackMessageTags2, findAdoptableFallbackTags2, adoptFallbackTagMessageId2, foldShrunkPartTags2, hasPiFallbackToolOwnerTags2, findPiFallbackToolOwnerTags2, PiTagIdentityConflictError2, getPiMessageTagCandidates2, findPiTagIdentityConflict2, adoptPiFallbackToolOwnerTag2, adoptPiFallbackMessageTag2, markTagsCompactedByMessageIds2, deleteTagsByMessageId2, getMaxTagNumberBySession2, getTagNumberByMessageId2, getAssignableTagNumberByMessageId2, getMinMessageTagNumberForRawId2, deriveTagLoadFloor2, TAG_SELECT_COLUMNS2, getTagsBySession2, getActiveTagsBySession2, getTagsForPendingOperations2, getTagsByNumbers2, getNewestToolTagNumbers2, getDroppedTagsByNumbers2, getMaxDroppedTagNumber2, getTagById2, getTopNBySize2, getToolTagNumberByOwner2, getNullOwnerToolTag2, adoptNullOwnerToolTag2, getCandidateToolOwners2, pickNearestPriorOwner2 };
|
|
3383
|
+
export { UNKNOWN_FIT_RATIO, resolveDecisionCalibration, hasMeasuredDecisionCalibration, providerMass, localBudget, calibrationForModelKey, historyLocalBudget, adoptedProtectedToolsPolicy, protectedToolTagNumbers, protectedToolTokenCount, stripWellFormedLeadingTagPrefix, stripPersistedAssistantText, byteSize, stripTagPrefix, peelLeadingMcTagNotation, prependTag, rememberCurrentToolOutputCount, currentReclaimableToolOutputCount, isRecord, TEXT_TAG_IDENTITY_MARKER, PI_FALLBACK_PREFIXES_JSON, contentTagOwnerMessageId, TailHygieneJsonMemo, piJsonHash, estimateImageTokensFromDataUrl, estimateToolAttachmentImageTokens, providerVisiblePart, providerVisibleMessage, TODO_STATUSES, TODO_PRIORITIES, TITLE_DONE_STATUSES, normalizeTodoStateJson, buildSyntheticTodoPart, stripChannel1ReminderSpans, compareMeasuredTailPrefix, formatTailHygienePrefixMismatch, freezeTailHygieneMeasurement, effectiveTailHygiene, CHANNEL1_SENTINEL, CHANNEL1_FLOOR_TOKENS, decideChannel1, evaluateChannel2, buildChannel2Reminder, buildChannel1Reminder, planEmergencyDrop, measureEmergencyTag, queuePendingOp, queuePendingDropForUnchangedTag, getPendingOps, getPendingOpsCount, clearPendingOps, removePendingOp, updateTagByteSize2, getRecentTagOwnerMessageIds2, getActiveTagTokenAggregate2, AGE_RECLAIM_MIN_TOKENS2, getOldestActiveUnprotectedToolTags2, getActiveToolTagsForAgeReclaim2, getTriggerTagTokenUpperBound2, getActiveTagTokenTotalsByMessage2, updateTagInputByteSize2, updateTagTokenCount2, getPersistedToolTagAccounting2, getAllStatusTagTokenTotalsFlat2, getReasoningTokenEstimatesByMessage2, tryGetReasoningTokenEstimatesByMessage2, getMaxTagNumberByOwnerMessage2, scanTagOwnerSummary2, scanTagOwnerDelta2, updateTagInputTokenCount2, tagTokenCountIsNull2, backfillTagTokenCounts2, insertTag2, updateTagStatus2, markTagDropped2, getInertWhitespaceAssistantTagsByNumbers2, updateTagDropMode2, updateCavemanDepth2, updateTagMessageId2, hasPiFallbackMessageTags2, findAdoptableFallbackTags2, adoptFallbackTagMessageId2, foldShrunkPartTags2, hasPiFallbackToolOwnerTags2, findPiFallbackToolOwnerTags2, PiTagIdentityConflictError2, getPiMessageTagCandidates2, findPiTagIdentityConflict2, adoptPiFallbackToolOwnerTag2, adoptPiFallbackMessageTag2, markTagsCompactedByMessageIds2, deleteTagsByMessageId2, getMaxTagNumberBySession2, getTagNumberByMessageId2, getAssignableTagNumberByMessageId2, getMinMessageTagNumberForRawId2, deriveTagLoadFloor2, TAG_SELECT_COLUMNS2, getTagsBySession2, getActiveTagsBySession2, getTagsForPendingOperations2, getTagsByNumbers2, getNewestToolTagNumbers2, getDroppedTagsByNumbers2, getMaxDroppedTagNumber2, getTagById2, getTopNBySize2, getToolTagNumberByOwner2, getNullOwnerToolTag2, adoptNullOwnerToolTag2, getCandidateToolOwners2, pickNearestPriorOwner2 };
|