@cortexkit/pi-magic-context 0.41.0 → 0.41.1
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/historian-calibration-extension.js +20 -14
- package/dist/{index-ts6nabp0.js → index-0jgz8yja.js} +553 -278
- package/dist/{index-3k71e196.js → index-q2vgz0j1.js} +87 -2
- package/dist/index.js +292 -59
- package/dist/{safe-notification-target-g8fx80va.js → safe-notification-target-hjcb423r.js} +1 -1
- package/dist/subagent-entry.js +2 -2
- package/dist/transformers-web.js +24570 -0
- package/dist/transformers.node-b1wa0hgx.js +28808 -0
- package/package.json +8 -3
- /package/dist/{index-wnrygn5h.js → index-y63nbvkk.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -190,6 +190,7 @@ import {
|
|
|
190
190
|
getOverflowState,
|
|
191
191
|
getPendingCompactionMarkerState,
|
|
192
192
|
getPendingOps,
|
|
193
|
+
getPendingOpsCount,
|
|
193
194
|
getPendingPiCompactionMarkerState,
|
|
194
195
|
getPendingSmartNotes,
|
|
195
196
|
getPersistedNoteNudge,
|
|
@@ -406,7 +407,7 @@ import {
|
|
|
406
407
|
withMigrationLanguageDirective,
|
|
407
408
|
withRawMessageProvider,
|
|
408
409
|
withRawSessionMessageCache
|
|
409
|
-
} from "./index-
|
|
410
|
+
} from "./index-0jgz8yja.js";
|
|
410
411
|
import {
|
|
411
412
|
pushNotification
|
|
412
413
|
} from "./index-hw34xmzk.js";
|
|
@@ -420,7 +421,7 @@ import {
|
|
|
420
421
|
log,
|
|
421
422
|
sessionLog,
|
|
422
423
|
setHarness
|
|
423
|
-
} from "./index-
|
|
424
|
+
} from "./index-q2vgz0j1.js";
|
|
424
425
|
import {
|
|
425
426
|
__require,
|
|
426
427
|
__toESM
|
|
@@ -2071,7 +2072,9 @@ import {
|
|
|
2071
2072
|
existsSync as existsSync3,
|
|
2072
2073
|
mkdtempSync,
|
|
2073
2074
|
readFileSync as readFileSync2,
|
|
2075
|
+
realpathSync as realpathSync2,
|
|
2074
2076
|
rmSync,
|
|
2077
|
+
statSync,
|
|
2075
2078
|
writeFileSync as writeFileSync2
|
|
2076
2079
|
} from "node:fs";
|
|
2077
2080
|
import { createRequire } from "node:module";
|
|
@@ -2081,7 +2084,8 @@ import {
|
|
|
2081
2084
|
dirname,
|
|
2082
2085
|
isAbsolute,
|
|
2083
2086
|
join as join2,
|
|
2084
|
-
resolve as resolvePath
|
|
2087
|
+
resolve as resolvePath,
|
|
2088
|
+
sep
|
|
2085
2089
|
} from "node:path";
|
|
2086
2090
|
import { createInterface } from "node:readline";
|
|
2087
2091
|
import { fileURLToPath } from "node:url";
|
|
@@ -2229,40 +2233,223 @@ function recordChildInvocation(input) {
|
|
|
2229
2233
|
}
|
|
2230
2234
|
|
|
2231
2235
|
// src/subagent-runner.ts
|
|
2232
|
-
|
|
2236
|
+
var PI_CODING_AGENT_MODULE = "@earendil-works/pi-coding-agent";
|
|
2237
|
+
var PI_CODING_AGENT_PACKAGE_NAMES = new Set([
|
|
2238
|
+
PI_CODING_AGENT_MODULE,
|
|
2239
|
+
"@oh-my-pi/pi-coding-agent"
|
|
2240
|
+
]);
|
|
2241
|
+
var BUN_VIRTUAL_SCRIPT_PREFIX = "/$bunfs/root/";
|
|
2242
|
+
var WINDOWS_PI_EXTENSIONS = [".EXE", ".COM", ".CMD", ".BAT", ".PS1"];
|
|
2243
|
+
var DEFAULT_PI_RESOLUTION_FS = {
|
|
2244
|
+
existsSync: existsSync3,
|
|
2245
|
+
statSync,
|
|
2246
|
+
realpathSync: realpathSync2,
|
|
2247
|
+
readFileSync: readFileSync2
|
|
2248
|
+
};
|
|
2249
|
+
function readPiManifest(packageJsonPath, fs2) {
|
|
2233
2250
|
try {
|
|
2234
|
-
const
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
if (existsSync3(cliPath))
|
|
2238
|
-
return cliPath;
|
|
2251
|
+
const manifest = JSON.parse(fs2.readFileSync(packageJsonPath, "utf8"));
|
|
2252
|
+
return manifest && typeof manifest === "object" ? manifest : null;
|
|
2253
|
+
} catch {
|
|
2239
2254
|
return null;
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
function findPiPackageRoot(startDir, fs2) {
|
|
2258
|
+
let dir = startDir;
|
|
2259
|
+
while (dir !== dirname(dir)) {
|
|
2260
|
+
const manifest = readPiManifest(join2(dir, "package.json"), fs2);
|
|
2261
|
+
if (manifest?.name && typeof manifest.name === "string" && PI_CODING_AGENT_PACKAGE_NAMES.has(manifest.name)) {
|
|
2262
|
+
if (basename(dir) === "dist") {
|
|
2263
|
+
const parentDir = dirname(dir);
|
|
2264
|
+
const parentManifest = readPiManifest(join2(parentDir, "package.json"), fs2);
|
|
2265
|
+
if (typeof parentManifest?.name === "string" && parentManifest.name === manifest.name) {
|
|
2266
|
+
return { dir: parentDir, manifest: parentManifest };
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
return { dir, manifest };
|
|
2270
|
+
}
|
|
2271
|
+
dir = dirname(dir);
|
|
2272
|
+
}
|
|
2273
|
+
return null;
|
|
2274
|
+
}
|
|
2275
|
+
function pathIsInside(root, candidate) {
|
|
2276
|
+
return candidate !== root && candidate.startsWith(`${root}${sep}`);
|
|
2277
|
+
}
|
|
2278
|
+
function resolvePiBin(found, fs2, checkedPaths) {
|
|
2279
|
+
const bin = found.manifest.bin;
|
|
2280
|
+
const binEntry = typeof bin === "string" ? bin : bin && typeof bin === "object" && typeof bin.pi === "string" ? bin.pi : undefined;
|
|
2281
|
+
if (!binEntry)
|
|
2282
|
+
return null;
|
|
2283
|
+
const packageRoot = resolvePath(found.dir);
|
|
2284
|
+
const candidate = resolvePath(packageRoot, binEntry);
|
|
2285
|
+
checkedPaths.push(candidate);
|
|
2286
|
+
if (isAbsolute(binEntry) || !pathIsInside(packageRoot, candidate)) {
|
|
2287
|
+
return null;
|
|
2288
|
+
}
|
|
2289
|
+
try {
|
|
2290
|
+
if (!fs2.existsSync(candidate) || !fs2.statSync(candidate).isFile()) {
|
|
2291
|
+
return null;
|
|
2292
|
+
}
|
|
2293
|
+
const realRoot = fs2.realpathSync(packageRoot);
|
|
2294
|
+
const realCandidate = fs2.realpathSync(candidate);
|
|
2295
|
+
return pathIsInside(realRoot, realCandidate) ? realCandidate : null;
|
|
2240
2296
|
} catch {
|
|
2241
2297
|
return null;
|
|
2242
2298
|
}
|
|
2243
2299
|
}
|
|
2244
|
-
function
|
|
2245
|
-
|
|
2246
|
-
|
|
2300
|
+
function resolvePiCliFromPackageJson(packageJsonPath, fs2, checkedPaths) {
|
|
2301
|
+
checkedPaths.push(packageJsonPath);
|
|
2302
|
+
const manifest = readPiManifest(packageJsonPath, fs2);
|
|
2303
|
+
if (typeof manifest?.name !== "string" || !PI_CODING_AGENT_PACKAGE_NAMES.has(manifest.name)) {
|
|
2304
|
+
return null;
|
|
2305
|
+
}
|
|
2306
|
+
return resolvePiBin({ dir: dirname(packageJsonPath), manifest }, fs2, checkedPaths);
|
|
2307
|
+
}
|
|
2308
|
+
function resolvePiCliFromRunningEntry(entry, fs2) {
|
|
2309
|
+
const checkedPaths = [entry ?? "process.argv[1] (missing)"];
|
|
2310
|
+
if (!entry || entry.startsWith(BUN_VIRTUAL_SCRIPT_PREFIX)) {
|
|
2311
|
+
return { cliPath: null, checkedPaths };
|
|
2312
|
+
}
|
|
2313
|
+
try {
|
|
2314
|
+
if (!fs2.existsSync(entry) || !fs2.statSync(entry).isFile()) {
|
|
2315
|
+
return { cliPath: null, checkedPaths };
|
|
2316
|
+
}
|
|
2317
|
+
const realEntry = fs2.realpathSync(entry);
|
|
2318
|
+
if (realEntry !== entry)
|
|
2319
|
+
checkedPaths.push(realEntry);
|
|
2320
|
+
const found = findPiPackageRoot(dirname(realEntry), fs2);
|
|
2321
|
+
if (!found)
|
|
2322
|
+
return { cliPath: null, checkedPaths };
|
|
2323
|
+
return {
|
|
2324
|
+
cliPath: resolvePiBin(found, fs2, checkedPaths),
|
|
2325
|
+
checkedPaths
|
|
2326
|
+
};
|
|
2327
|
+
} catch {
|
|
2328
|
+
return { cliPath: null, checkedPaths };
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
function defaultResolvePiPackageJson(from) {
|
|
2332
|
+
const requesters = [from, import.meta.url];
|
|
2333
|
+
for (const requester of requesters) {
|
|
2334
|
+
try {
|
|
2335
|
+
const require_ = requester ? createRequire(requester.startsWith("file:") ? requester : resolvePath(requester)) : createRequire(import.meta.url);
|
|
2336
|
+
return require_.resolve(`${PI_CODING_AGENT_MODULE}/package.json`);
|
|
2337
|
+
} catch {}
|
|
2338
|
+
}
|
|
2339
|
+
return null;
|
|
2340
|
+
}
|
|
2341
|
+
function resolveBundledPiCli(from, fs2, resolvePackageJson, checkedPaths) {
|
|
2342
|
+
const packageJsonPath = resolvePackageJson(from);
|
|
2343
|
+
if (!packageJsonPath) {
|
|
2344
|
+
checkedPaths.push(`${PI_CODING_AGENT_MODULE}/package.json (unresolvable from running module paths)`);
|
|
2345
|
+
return null;
|
|
2346
|
+
}
|
|
2347
|
+
return resolvePiCliFromPackageJson(packageJsonPath, fs2, checkedPaths);
|
|
2348
|
+
}
|
|
2349
|
+
function resolveWindowsPiCommand(env, fs2) {
|
|
2350
|
+
const pathValue = env.PATH ?? env.Path;
|
|
2351
|
+
if (!pathValue)
|
|
2352
|
+
return { path: null, extension: null, checkedPaths: [] };
|
|
2353
|
+
const pathExt = env.PATHEXT ?? env.PathExt ?? "";
|
|
2354
|
+
const extensions = [];
|
|
2355
|
+
for (const value of pathExt.split(";")) {
|
|
2356
|
+
const extension = value.trim().toUpperCase();
|
|
2357
|
+
if (WINDOWS_PI_EXTENSIONS.includes(extension) && !extensions.includes(extension)) {
|
|
2358
|
+
extensions.push(extension);
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
for (const extension of WINDOWS_PI_EXTENSIONS) {
|
|
2362
|
+
if (!extensions.includes(extension))
|
|
2363
|
+
extensions.push(extension);
|
|
2364
|
+
}
|
|
2365
|
+
const checkedPaths = [];
|
|
2366
|
+
for (const rawDir of pathValue.split(";")) {
|
|
2367
|
+
const dir = rawDir.trim().replace(/^"(.*)"$/, "$1");
|
|
2368
|
+
if (!dir)
|
|
2369
|
+
continue;
|
|
2370
|
+
for (const extension of extensions) {
|
|
2371
|
+
const candidate = join2(dir, `pi${extension.toLowerCase()}`);
|
|
2372
|
+
checkedPaths.push(candidate);
|
|
2373
|
+
try {
|
|
2374
|
+
if (fs2.existsSync(candidate) && fs2.statSync(candidate).isFile()) {
|
|
2375
|
+
return { path: candidate, extension, checkedPaths };
|
|
2376
|
+
}
|
|
2377
|
+
} catch {}
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
return { path: null, extension: null, checkedPaths };
|
|
2247
2381
|
}
|
|
2248
2382
|
function isGenericRuntimeExecutable(execPath) {
|
|
2249
2383
|
return /^(node(?:js)?\d*|bun)(\.exe)?$/.test(basename(execPath).toLowerCase());
|
|
2250
2384
|
}
|
|
2251
|
-
function
|
|
2252
|
-
const
|
|
2253
|
-
const
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2385
|
+
function formatCheckedPaths(checkedPaths) {
|
|
2386
|
+
const unique = [...new Set(checkedPaths)];
|
|
2387
|
+
const visible = unique.slice(0, 12);
|
|
2388
|
+
return unique.length > visible.length ? `${visible.join(", ")} (+${unique.length - visible.length} more)` : visible.join(", ");
|
|
2389
|
+
}
|
|
2390
|
+
function resolvePiInvocation(options = {}) {
|
|
2391
|
+
const fs2 = { ...DEFAULT_PI_RESOLUTION_FS, ...options.fs };
|
|
2392
|
+
const execPath = options.execPath ?? process.execPath;
|
|
2393
|
+
const currentScript = options.argv1 ?? process.argv[1];
|
|
2394
|
+
const platform = options.platform ?? process.platform;
|
|
2395
|
+
const env = options.env ?? process.env;
|
|
2396
|
+
const resolvePackageJson = options.resolvePackageJson ?? defaultResolvePiPackageJson;
|
|
2397
|
+
const running = resolvePiCliFromRunningEntry(currentScript, fs2);
|
|
2398
|
+
const checkedPaths = [...running.checkedPaths];
|
|
2399
|
+
if (running.cliPath) {
|
|
2400
|
+
return { command: execPath, prefixArgs: [running.cliPath] };
|
|
2257
2401
|
}
|
|
2258
2402
|
if (!isGenericRuntimeExecutable(execPath)) {
|
|
2259
2403
|
return { command: execPath, prefixArgs: [] };
|
|
2260
2404
|
}
|
|
2261
|
-
const bundled = resolveBundledPiCli();
|
|
2405
|
+
const bundled = resolveBundledPiCli(currentScript, fs2, resolvePackageJson, checkedPaths);
|
|
2262
2406
|
if (bundled) {
|
|
2263
2407
|
return { command: execPath, prefixArgs: [bundled] };
|
|
2264
2408
|
}
|
|
2265
|
-
|
|
2409
|
+
const detectionMiss = `script-detection miss on ${formatCheckedPaths(checkedPaths)}`;
|
|
2410
|
+
if (platform === "win32") {
|
|
2411
|
+
const resolved = resolveWindowsPiCommand(env, fs2);
|
|
2412
|
+
if (resolved.path && resolved.extension) {
|
|
2413
|
+
const diagnostic = `${detectionMiss}; Windows PATHEXT resolved ${resolved.path}`;
|
|
2414
|
+
if (resolved.extension === ".CMD" || resolved.extension === ".BAT") {
|
|
2415
|
+
const command = env.ComSpec?.trim() || env.COMSPEC?.trim() || "cmd.exe";
|
|
2416
|
+
return {
|
|
2417
|
+
command,
|
|
2418
|
+
prefixArgs: ["/d", "/s", "/c", resolved.path],
|
|
2419
|
+
fallbackDiagnostic: diagnostic
|
|
2420
|
+
};
|
|
2421
|
+
}
|
|
2422
|
+
if (resolved.extension === ".PS1") {
|
|
2423
|
+
const command = env.SystemRoot ? join2(env.SystemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe") : "powershell.exe";
|
|
2424
|
+
return {
|
|
2425
|
+
command,
|
|
2426
|
+
prefixArgs: [
|
|
2427
|
+
"-NoLogo",
|
|
2428
|
+
"-NoProfile",
|
|
2429
|
+
"-NonInteractive",
|
|
2430
|
+
"-File",
|
|
2431
|
+
resolved.path
|
|
2432
|
+
],
|
|
2433
|
+
fallbackDiagnostic: diagnostic
|
|
2434
|
+
};
|
|
2435
|
+
}
|
|
2436
|
+
return {
|
|
2437
|
+
command: resolved.path,
|
|
2438
|
+
prefixArgs: [],
|
|
2439
|
+
fallbackDiagnostic: diagnostic
|
|
2440
|
+
};
|
|
2441
|
+
}
|
|
2442
|
+
checkedPaths.push(...resolved.checkedPaths);
|
|
2443
|
+
}
|
|
2444
|
+
return {
|
|
2445
|
+
command: "pi",
|
|
2446
|
+
prefixArgs: [],
|
|
2447
|
+
fallbackDiagnostic: `script-detection miss on ${formatCheckedPaths(checkedPaths)}`
|
|
2448
|
+
};
|
|
2449
|
+
}
|
|
2450
|
+
function describeSpawnFailure(error, invocation) {
|
|
2451
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2452
|
+
return invocation.fallbackDiagnostic ? `${message} after ${invocation.fallbackDiagnostic}` : message;
|
|
2266
2453
|
}
|
|
2267
2454
|
function resolveSiblingEntryPath(fileName) {
|
|
2268
2455
|
try {
|
|
@@ -2445,7 +2632,7 @@ class PiSubagentRunner {
|
|
|
2445
2632
|
extraArgs;
|
|
2446
2633
|
subagentExtensions;
|
|
2447
2634
|
constructor(options = {}) {
|
|
2448
|
-
this.invocation = options.piBinary ? { command: options.piBinary, prefixArgs: [] } : resolvePiInvocation();
|
|
2635
|
+
this.invocation = options.invocation ?? (options.piBinary ? { command: options.piBinary, prefixArgs: [] } : resolvePiInvocation({ platform: options.platform }));
|
|
2449
2636
|
this.spawnImpl = options.spawnImpl ?? childProcess.spawn;
|
|
2450
2637
|
this.platform = options.platform ?? process.platform;
|
|
2451
2638
|
this.extraArgs = options.extraArgs ?? [];
|
|
@@ -2675,7 +2862,7 @@ class PiSubagentRunner {
|
|
|
2675
2862
|
settle({
|
|
2676
2863
|
ok: false,
|
|
2677
2864
|
reason: "spawn_failed",
|
|
2678
|
-
error: error
|
|
2865
|
+
error: describeSpawnFailure(error, this.invocation),
|
|
2679
2866
|
durationMs: Date.now() - startTime
|
|
2680
2867
|
});
|
|
2681
2868
|
return;
|
|
@@ -2864,7 +3051,7 @@ class PiSubagentRunner {
|
|
|
2864
3051
|
settle({
|
|
2865
3052
|
ok: false,
|
|
2866
3053
|
reason: "spawn_failed",
|
|
2867
|
-
error: error
|
|
3054
|
+
error: describeSpawnFailure(error, this.invocation),
|
|
2868
3055
|
durationMs: Date.now() - startTime
|
|
2869
3056
|
});
|
|
2870
3057
|
});
|
|
@@ -2885,10 +3072,11 @@ class PiSubagentRunner {
|
|
|
2885
3072
|
if (sawAgentEnd) {
|
|
2886
3073
|
const trimmedAssistantText = finalAssistantText?.trim() ?? null;
|
|
2887
3074
|
if (trimmedAssistantText === null || trimmedAssistantText.length === 0) {
|
|
3075
|
+
const emptyAssistantReason = trimmedAssistantText === null ? "pi agent_end did not include an assistant message" : "pi assistant produced empty text";
|
|
2888
3076
|
settle({
|
|
2889
3077
|
ok: false,
|
|
2890
3078
|
reason: "no_assistant",
|
|
2891
|
-
error:
|
|
3079
|
+
error: finalErrorMessage ? `${emptyAssistantReason} (provider error: ${finalErrorMessage})` : emptyAssistantReason,
|
|
2892
3080
|
durationMs: Date.now() - startTime,
|
|
2893
3081
|
meta: {
|
|
2894
3082
|
stderr: stderr.length > 0 ? stderr : undefined,
|
|
@@ -3798,7 +3986,7 @@ async function sendIgnoredMessageNow(client, sessionId, text, params, forcePersi
|
|
|
3798
3986
|
queueIgnoredNotification({ client, sessionId, text, params, forcePersist });
|
|
3799
3987
|
return "queued";
|
|
3800
3988
|
}
|
|
3801
|
-
const { waitForSafeNotificationTarget } = await import("./safe-notification-target-
|
|
3989
|
+
const { waitForSafeNotificationTarget } = await import("./safe-notification-target-hjcb423r.js");
|
|
3802
3990
|
if (await waitForSafeNotificationTarget(client, sessionId) === "skip") {
|
|
3803
3991
|
sessionLog(sessionId, "notification skipped (session not titled yet)");
|
|
3804
3992
|
return "skipped";
|
|
@@ -6746,7 +6934,7 @@ function getAsyncModule() {
|
|
|
6746
6934
|
asyncModulePromise ??= (async () => {
|
|
6747
6935
|
const [{ default: singlefileAsyncifyVariant }, { newQuickJSAsyncWASMModuleFromVariant }] = await Promise.all([
|
|
6748
6936
|
import("./index-rgdqj8nj.js").then((m)=>__toESM(m.default,1)),
|
|
6749
|
-
import("./index-
|
|
6937
|
+
import("./index-y63nbvkk.js")
|
|
6750
6938
|
]);
|
|
6751
6939
|
return newQuickJSAsyncWASMModuleFromVariant(singlefileAsyncifyVariant);
|
|
6752
6940
|
})();
|
|
@@ -7876,7 +8064,7 @@ function enforceMaintainDocsProtectedRegions(args) {
|
|
|
7876
8064
|
import { createHash as createHash6 } from "node:crypto";
|
|
7877
8065
|
|
|
7878
8066
|
// ../plugin/src/features/magic-context/dreamer/map-memories-prompt.ts
|
|
7879
|
-
import { existsSync as existsSync6, statSync } from "node:fs";
|
|
8067
|
+
import { existsSync as existsSync6, statSync as statSync2 } from "node:fs";
|
|
7880
8068
|
import path4 from "node:path";
|
|
7881
8069
|
var MAP_MEMORIES_SYSTEM_PROMPT = `You are a memory mapper for the magic-context system. You map project memories to the repository files that back them.
|
|
7882
8070
|
|
|
@@ -7914,7 +8102,7 @@ function extractMemoryCandidatePaths(content, repoDir) {
|
|
|
7914
8102
|
if (!abs.startsWith(`${root}/`))
|
|
7915
8103
|
continue;
|
|
7916
8104
|
try {
|
|
7917
|
-
if (existsSync6(abs) &&
|
|
8105
|
+
if (existsSync6(abs) && statSync2(abs).isFile())
|
|
7918
8106
|
found.add(rel);
|
|
7919
8107
|
} catch {}
|
|
7920
8108
|
if (found.size >= MAX_SEED_PATHS_PER_MEMORY)
|
|
@@ -11055,7 +11243,7 @@ async function runDueTasksForProject(deps) {
|
|
|
11055
11243
|
}
|
|
11056
11244
|
|
|
11057
11245
|
// ../plugin/src/plugin/dream-timer.ts
|
|
11058
|
-
import { statSync as
|
|
11246
|
+
import { statSync as statSync3 } from "node:fs";
|
|
11059
11247
|
|
|
11060
11248
|
// ../plugin/src/features/magic-context/dreamer/retrospective-orphan-sweep.ts
|
|
11061
11249
|
var HISTORIAN_CHILD_TITLE = "magic-context-compartment";
|
|
@@ -11165,7 +11353,7 @@ var startupJitters = new Map;
|
|
|
11165
11353
|
var nextStartupJitterSlot = 0;
|
|
11166
11354
|
function directoryStillExists(directory) {
|
|
11167
11355
|
try {
|
|
11168
|
-
return
|
|
11356
|
+
return statSync3(directory).isDirectory();
|
|
11169
11357
|
} catch {
|
|
11170
11358
|
return false;
|
|
11171
11359
|
}
|
|
@@ -11522,7 +11710,7 @@ async function sweepGitCommits(args) {
|
|
|
11522
11710
|
}
|
|
11523
11711
|
|
|
11524
11712
|
// src/dreamer/pi-session-api.ts
|
|
11525
|
-
import { existsSync as existsSync8, readFileSync as readFileSync4, realpathSync as
|
|
11713
|
+
import { existsSync as existsSync8, readFileSync as readFileSync4, realpathSync as realpathSync3, statSync as statSync4 } from "node:fs";
|
|
11526
11714
|
import {
|
|
11527
11715
|
basename as basename2,
|
|
11528
11716
|
dirname as dirname2,
|
|
@@ -11530,10 +11718,10 @@ import {
|
|
|
11530
11718
|
join as join4,
|
|
11531
11719
|
relative,
|
|
11532
11720
|
resolve,
|
|
11533
|
-
sep
|
|
11721
|
+
sep as sep2
|
|
11534
11722
|
} from "node:path";
|
|
11535
11723
|
import { pathToFileURL } from "node:url";
|
|
11536
|
-
var
|
|
11724
|
+
var PI_CODING_AGENT_MODULE2 = "@earendil-works/pi-coding-agent";
|
|
11537
11725
|
var SCRIPT_ENTRY_PATTERN = /\.(mjs|cjs|mts|cts|js|ts|tsx|jsx)$/i;
|
|
11538
11726
|
var TS_ENTRY_PATTERN = /\.(mts|cts|ts|tsx)$/i;
|
|
11539
11727
|
function isScriptEntry(filePath) {
|
|
@@ -11556,8 +11744,8 @@ function isCompiledBunBinary() {
|
|
|
11556
11744
|
}
|
|
11557
11745
|
function resolveRunningEntry() {
|
|
11558
11746
|
const argv1 = process.argv[1];
|
|
11559
|
-
if (argv1 && existsSync8(argv1) &&
|
|
11560
|
-
const real =
|
|
11747
|
+
if (argv1 && existsSync8(argv1) && statSync4(argv1).isFile()) {
|
|
11748
|
+
const real = realpathSync3(argv1);
|
|
11561
11749
|
if (isScriptEntry(real)) {
|
|
11562
11750
|
return real;
|
|
11563
11751
|
}
|
|
@@ -11568,11 +11756,11 @@ function findPackageRoot(startDir) {
|
|
|
11568
11756
|
let dir = startDir;
|
|
11569
11757
|
while (dir !== dirname2(dir)) {
|
|
11570
11758
|
const pkg = readManifest(join4(dir, "package.json"));
|
|
11571
|
-
if (pkg?.name ===
|
|
11759
|
+
if (pkg?.name === PI_CODING_AGENT_MODULE2) {
|
|
11572
11760
|
if (basename2(dir) === "dist") {
|
|
11573
11761
|
const parentDir = dirname2(dir);
|
|
11574
11762
|
const parentPkg = readManifest(join4(parentDir, "package.json"));
|
|
11575
|
-
if (parentPkg?.name ===
|
|
11763
|
+
if (parentPkg?.name === PI_CODING_AGENT_MODULE2) {
|
|
11576
11764
|
return { dir: parentDir, pkg: parentPkg };
|
|
11577
11765
|
}
|
|
11578
11766
|
}
|
|
@@ -11619,7 +11807,7 @@ function resolveManifestEntry(found) {
|
|
|
11619
11807
|
}
|
|
11620
11808
|
const root = resolve(found.dir);
|
|
11621
11809
|
const resolved = resolve(root, entryRel);
|
|
11622
|
-
if (resolved !== root && !resolved.startsWith(root +
|
|
11810
|
+
if (resolved !== root && !resolved.startsWith(root + sep2)) {
|
|
11623
11811
|
throw new Error(`Invalid entry "${entryRel}" in ${found.dir}/package.json: target escapes the package root`);
|
|
11624
11812
|
}
|
|
11625
11813
|
return resolved;
|
|
@@ -11645,7 +11833,7 @@ var defaultLoaders = [
|
|
|
11645
11833
|
}
|
|
11646
11834
|
const found = findPackageRoot(dirname2(entry));
|
|
11647
11835
|
if (!found) {
|
|
11648
|
-
throw new Error(`Could not locate ${
|
|
11836
|
+
throw new Error(`Could not locate ${PI_CODING_AGENT_MODULE2} package.json from ${entry}`);
|
|
11649
11837
|
}
|
|
11650
11838
|
const entryPath = resolveManifestEntry(found);
|
|
11651
11839
|
if (TS_ENTRY_PATTERN.test(entry)) {
|
|
@@ -11660,7 +11848,7 @@ var defaultLoaders = [
|
|
|
11660
11848
|
},
|
|
11661
11849
|
{
|
|
11662
11850
|
name: "Bare import",
|
|
11663
|
-
load: async () => await import(
|
|
11851
|
+
load: async () => await import(PI_CODING_AGENT_MODULE2)
|
|
11664
11852
|
}
|
|
11665
11853
|
];
|
|
11666
11854
|
var cachedModulePromise = null;
|
|
@@ -11678,7 +11866,7 @@ async function resolvePiCodingAgentModule(loaders) {
|
|
|
11678
11866
|
errors.push(err);
|
|
11679
11867
|
}
|
|
11680
11868
|
}
|
|
11681
|
-
throw new Error(`Failed to resolve ${
|
|
11869
|
+
throw new Error(`Failed to resolve ${PI_CODING_AGENT_MODULE2} via all strategies:
|
|
11682
11870
|
` + errors.map((e, i) => ` - ${activeLoaders[i].name}: ${e.message || e}`).join(`
|
|
11683
11871
|
`) + `
|
|
11684
11872
|
Likely cause: symlinked or nonstandard install layout.`);
|
|
@@ -11922,6 +12110,8 @@ function registerPiDreamerProject(opts) {
|
|
|
11922
12110
|
dreamerConfig: opts.config,
|
|
11923
12111
|
language: opts.language,
|
|
11924
12112
|
gitCommitIndexing: opts.gitCommitIndexing,
|
|
12113
|
+
memoryEnabled: opts.memoryEnabled,
|
|
12114
|
+
embeddingConfig: opts.embeddingConfig,
|
|
11925
12115
|
retinaHandoff: opts.retinaHandoff,
|
|
11926
12116
|
mural: opts.mural,
|
|
11927
12117
|
ensureRegistered: ensureProjectRegisteredFromPiDirectory,
|
|
@@ -12452,6 +12642,10 @@ function formatEmbedFailureSummary(embedded, remaining, failure) {
|
|
|
12452
12642
|
}
|
|
12453
12643
|
case "invalid_envelope":
|
|
12454
12644
|
return `Embedded ${embedded} ${compartment}; ${remaining} failed: ${failure.reason}. Fix: configure an OpenAI-compatible embedding endpoint that returns data[].embedding.`;
|
|
12645
|
+
case "certification_refusal":
|
|
12646
|
+
return `Embedded ${embedded} ${compartment}; ${remaining} rejected: ${failure.reason}. Fix: recertify SYNAPSE or configure embedding.fallback_provider, then run /ctx-embed start again.`;
|
|
12647
|
+
case "credential_required":
|
|
12648
|
+
return `Embedded ${embedded} ${compartment}; ${remaining} rejected: ${failure.reason}. Fix: reauthenticate SYNAPSE, then run /ctx-embed start again.`;
|
|
12455
12649
|
case "empty_result":
|
|
12456
12650
|
case "transport_error":
|
|
12457
12651
|
return `Embedded ${embedded} ${compartment}; ${remaining} failed: ${failure.reason}.${failure.retryable ? retry : ""}`;
|
|
@@ -13600,15 +13794,31 @@ function detectMidTurnBypassReason(input) {
|
|
|
13600
13794
|
}
|
|
13601
13795
|
function applyMidTurnDeferral(input) {
|
|
13602
13796
|
if (input.base === "defer") {
|
|
13603
|
-
return {
|
|
13797
|
+
return {
|
|
13798
|
+
midTurnAdjustedSchedulerDecision: "defer",
|
|
13799
|
+
sideEffect: "none",
|
|
13800
|
+
deferReason: "scheduler_defer"
|
|
13801
|
+
};
|
|
13604
13802
|
}
|
|
13605
13803
|
if (input.bypassReason !== "none") {
|
|
13606
|
-
return {
|
|
13804
|
+
return {
|
|
13805
|
+
midTurnAdjustedSchedulerDecision: "execute",
|
|
13806
|
+
sideEffect: "none",
|
|
13807
|
+
deferReason: null
|
|
13808
|
+
};
|
|
13607
13809
|
}
|
|
13608
13810
|
if (input.midTurn) {
|
|
13609
|
-
return {
|
|
13811
|
+
return {
|
|
13812
|
+
midTurnAdjustedSchedulerDecision: "defer",
|
|
13813
|
+
sideEffect: "set-flag",
|
|
13814
|
+
deferReason: "mid_turn_boundary"
|
|
13815
|
+
};
|
|
13610
13816
|
}
|
|
13611
|
-
return {
|
|
13817
|
+
return {
|
|
13818
|
+
midTurnAdjustedSchedulerDecision: "execute",
|
|
13819
|
+
sideEffect: "none",
|
|
13820
|
+
deferReason: null
|
|
13821
|
+
};
|
|
13612
13822
|
}
|
|
13613
13823
|
|
|
13614
13824
|
// ../plugin/src/hooks/magic-context/caveman.ts
|
|
@@ -14789,7 +14999,7 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
14789
14999
|
const forceMaterializationPercentage = escalationBands(executeThresholdPercentage).forceMaterializationPercentage;
|
|
14790
15000
|
if (usage.percentage >= forceMaterializationPercentage) {
|
|
14791
15001
|
if (projectedPostDropPercentage !== null && projectedPostDropPercentage <= relativePostDropTarget) {
|
|
14792
|
-
sessionLog(sessionId, `
|
|
15002
|
+
sessionLog(sessionId, `historian redundancy skip: summarizer not needed this pass — force band is ${forceMaterializationPercentage}%; queued/automatic drops are projected to reclaim to ${projectedPostDropPercentage.toFixed(1)}% (target ${relativePostDropTarget.toFixed(1)}%) on the next eligible execute pass`);
|
|
14793
15003
|
return { shouldFire: false };
|
|
14794
15004
|
}
|
|
14795
15005
|
sessionLog(sessionId, `compartment trigger: force-firing at ${usage.percentage.toFixed(1)}% (projected post-drop ${formatProjectedPostDropPercentage(projectedPostDropPercentage)})`);
|
|
@@ -14850,7 +15060,7 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
14850
15060
|
return { shouldFire: false };
|
|
14851
15061
|
}
|
|
14852
15062
|
if (projectedPostDropPercentage !== null && projectedPostDropPercentage <= relativePostDropTarget) {
|
|
14853
|
-
sessionLog(sessionId, `
|
|
15063
|
+
sessionLog(sessionId, `historian redundancy skip: summarizer not needed this pass — usage is ${usage.percentage.toFixed(1)}%; queued/automatic drops are projected to reclaim to ${projectedPostDropPercentage.toFixed(1)}% (target ${relativePostDropTarget.toFixed(1)}%) on the next eligible execute pass`);
|
|
14854
15064
|
return { shouldFire: false };
|
|
14855
15065
|
}
|
|
14856
15066
|
if (!tailInfo.hasProtectedEligibleHead || !tailInfo.isMeaningful) {
|
|
@@ -21600,7 +21810,7 @@ async function runPiHistorian(deps) {
|
|
|
21600
21810
|
refreshBoundarySnapshot,
|
|
21601
21811
|
currentContextLimit,
|
|
21602
21812
|
historianTimeoutMs = DEFAULT_HISTORIAN_TIMEOUT_MS2,
|
|
21603
|
-
temperature
|
|
21813
|
+
temperature,
|
|
21604
21814
|
maxOutputTokens = 32000,
|
|
21605
21815
|
signal,
|
|
21606
21816
|
retryBackoffMs,
|
|
@@ -23850,6 +24060,7 @@ var injectM0M1PiForRun = injectM0M1Pi;
|
|
|
23850
24060
|
var persistReasoningWatermarkForRun = updateSessionMeta;
|
|
23851
24061
|
var persistStableIdSchemeForRun = updateSessionMeta;
|
|
23852
24062
|
var afterFallbackAdoptionForTests;
|
|
24063
|
+
var pendingDecisionLogObserverForTests;
|
|
23853
24064
|
var mutationGateObserverForTests;
|
|
23854
24065
|
var DEFAULT_CLEAR_REASONING_AGE = 50;
|
|
23855
24066
|
var PI_STABLE_ID_SCHEME = 1;
|
|
@@ -24833,9 +25044,14 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
24833
25044
|
sessionId,
|
|
24834
25045
|
effectiveExecuteThresholdPercentage
|
|
24835
25046
|
});
|
|
24836
|
-
const {
|
|
25047
|
+
const {
|
|
25048
|
+
midTurnAdjustedSchedulerDecision,
|
|
25049
|
+
sideEffect,
|
|
25050
|
+
deferReason: schedulerDeferReason
|
|
25051
|
+
} = options.compactionOff ? {
|
|
24837
25052
|
midTurnAdjustedSchedulerDecision: "defer",
|
|
24838
|
-
sideEffect: "none"
|
|
25053
|
+
sideEffect: "none",
|
|
25054
|
+
deferReason: "scheduler_defer"
|
|
24839
25055
|
} : applyMidTurnDeferral({
|
|
24840
25056
|
base: schedulerDecisionEarly,
|
|
24841
25057
|
bypassReason,
|
|
@@ -24924,6 +25140,7 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
24924
25140
|
reusableMessageIds,
|
|
24925
25141
|
stableIdSchemeCutover,
|
|
24926
25142
|
schedulerDecision,
|
|
25143
|
+
schedulerDeferReason,
|
|
24927
25144
|
forceMaterialization: forceMaterialization || isEmergency,
|
|
24928
25145
|
forceMaterializationPercentage,
|
|
24929
25146
|
contextUsage: {
|
|
@@ -25821,7 +26038,10 @@ async function runPipeline(args) {
|
|
|
25821
26038
|
});
|
|
25822
26039
|
if (shouldApplyPendingOps) {
|
|
25823
26040
|
const applyReason = hasPendingMaterializeSignal ? "explicit_flush" : deferredMaterialize ? "deferred_publication" : args.forceMaterialization ? "force_materialization" : foldExecutedThisPass && args.schedulerDecision !== "execute" ? `m0_hard_fold (drain folded into executed m[0] bust, scheduler=${args.schedulerDecision})` : `scheduler_execute (scheduler=${args.schedulerDecision})`;
|
|
25824
|
-
|
|
26041
|
+
const pendingOpsDepth = getPendingOpsCount(args.db, args.sessionId);
|
|
26042
|
+
const pendingDecisionLog = `pending ops WILL APPLY — reason=${applyReason}, pendingOps=${pendingOpsDepth === null ? "not loaded (deferred pass)" : pendingOpsDepth} context=${args.contextUsage.percentage.toFixed(1)}%`;
|
|
26043
|
+
sessionLog(args.sessionId, pendingDecisionLog);
|
|
26044
|
+
pendingDecisionLogObserverForTests?.(pendingDecisionLog);
|
|
25825
26045
|
try {
|
|
25826
26046
|
const tApplyPending = performance.now();
|
|
25827
26047
|
pendingOpsDidMutate = applyPendingOperations(args.sessionId, args.db, targets, args.protectedTags, pendingOperationTags, pendingOps);
|
|
@@ -25842,7 +26062,11 @@ async function runPipeline(args) {
|
|
|
25842
26062
|
throw err;
|
|
25843
26063
|
}
|
|
25844
26064
|
} else {
|
|
25845
|
-
|
|
26065
|
+
const pendingOpsDepth = getPendingOpsCount(args.db, args.sessionId);
|
|
26066
|
+
const refusalReason = args.schedulerDeferReason ?? (historianRunning ? "historian_in_flight" : "scheduler_defer");
|
|
26067
|
+
const pendingDecisionLog = `pending ops WILL NOT APPLY — reason=${refusalReason} pendingOps=${pendingOpsDepth === null ? "not loaded (deferred pass)" : pendingOpsDepth} context=${args.contextUsage.percentage.toFixed(1)}%`;
|
|
26068
|
+
sessionLog(args.sessionId, pendingDecisionLog);
|
|
26069
|
+
pendingDecisionLogObserverForTests?.(pendingDecisionLog);
|
|
25846
26070
|
}
|
|
25847
26071
|
const targetTagNumbers = [...targets.keys()];
|
|
25848
26072
|
const tGetTags = performance.now();
|
|
@@ -25899,10 +26123,14 @@ async function runPipeline(args) {
|
|
|
25899
26123
|
logTransformTiming(args.sessionId, "getActiveTagsBySession", tActiveTags, `count=${activeTags.length}`);
|
|
25900
26124
|
if (shouldRunHeuristics) {
|
|
25901
26125
|
const reason = args.forceMaterialization ? "force_materialization" : foldExecutedThisPass && args.schedulerDecision !== "execute" ? `m0_hard_fold (drain folded into executed m[0] bust, scheduler=${args.schedulerDecision})` : `scheduler_execute (pendingOps=${pendingOps.length}, scheduler=${args.schedulerDecision})`;
|
|
25902
|
-
|
|
26126
|
+
const heuristicsDecisionLog = `heuristics WILL RUN — reason=${reason}, context=${args.contextUsage.percentage.toFixed(1)}%, turn=n/a`;
|
|
26127
|
+
sessionLog(args.sessionId, heuristicsDecisionLog);
|
|
26128
|
+
pendingDecisionLogObserverForTests?.(heuristicsDecisionLog);
|
|
25903
26129
|
} else {
|
|
25904
|
-
const reason = args.heuristics === undefined ? "disabled" : "scheduler_defer";
|
|
25905
|
-
|
|
26130
|
+
const reason = args.heuristics === undefined ? "disabled" : args.schedulerDeferReason ?? (historianRunning ? "historian_in_flight" : alreadyRanHeuristicsThisTurn ? "already_ran_this_turn" : "scheduler_defer");
|
|
26131
|
+
const heuristicsDecisionLog = `heuristics WILL NOT RUN — reason=${reason}`;
|
|
26132
|
+
sessionLog(args.sessionId, heuristicsDecisionLog);
|
|
26133
|
+
pendingDecisionLogObserverForTests?.(heuristicsDecisionLog);
|
|
25906
26134
|
}
|
|
25907
26135
|
if (shouldRunHeuristics && args.heuristics) {
|
|
25908
26136
|
try {
|
|
@@ -28973,7 +29201,7 @@ ${c.content}
|
|
|
28973
29201
|
// package.json
|
|
28974
29202
|
var package_default = {
|
|
28975
29203
|
name: "@cortexkit/pi-magic-context",
|
|
28976
|
-
version: "0.41.
|
|
29204
|
+
version: "0.41.1",
|
|
28977
29205
|
type: "module",
|
|
28978
29206
|
description: "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
|
|
28979
29207
|
main: "dist/index.js",
|
|
@@ -29001,7 +29229,7 @@ var package_default = {
|
|
|
29001
29229
|
"README.md"
|
|
29002
29230
|
],
|
|
29003
29231
|
scripts: {
|
|
29004
|
-
build: "tsc -p ../retina-local-fs/tsconfig.build.json && rm -f dist/index.js dist/subagent-entry.js dist/historian-calibration-extension.js dist/*-*.js && bun build src/index.ts src/subagent-entry.ts src/historian-calibration-extension.ts --outdir dist --target node --format esm --splitting --external @earendil-works/pi-coding-agent --external @earendil-works/pi-tui --external
|
|
29232
|
+
build: "tsc -p ../retina-local-fs/tsconfig.build.json && rm -f dist/index.js dist/subagent-entry.js dist/historian-calibration-extension.js dist/transformers-web.js dist/*-*.js && bun build ../plugin/src/features/magic-context/memory/transformers-web-entry.ts --outfile dist/transformers-web.js --target browser --format esm --external onnxruntime-web && bun build src/index.ts src/subagent-entry.ts src/historian-calibration-extension.ts --outdir dist --target node --format esm --splitting --external @earendil-works/pi-coding-agent --external @earendil-works/pi-tui --external onnxruntime-node --external onnxruntime-web --external sharp --external node:sqlite",
|
|
29005
29233
|
"build:e2e-argv": "bun build src/subagent-runner.ts --outfile ../../tests/docker/.generated/subagent-runner-e2e.mjs --target node --format esm --external node:sqlite",
|
|
29006
29234
|
typecheck: "tsc -p ../retina-local-fs/tsconfig.build.json && tsc --noEmit",
|
|
29007
29235
|
test: "bun install --frozen-lockfile && bun test",
|
|
@@ -29014,16 +29242,21 @@ var package_default = {
|
|
|
29014
29242
|
},
|
|
29015
29243
|
dependencies: {
|
|
29016
29244
|
"@cortexkit/subc-client": "0.4.1",
|
|
29017
|
-
"@huggingface/transformers": "^4.1.0",
|
|
29018
29245
|
"@jitl/quickjs-singlefile-cjs-release-asyncify": "0.32.0",
|
|
29019
29246
|
"ai-tokenizer": "^1.0.6",
|
|
29020
29247
|
"comment-json": "^5.0.0",
|
|
29248
|
+
"onnxruntime-web": "1.26.0-dev.20260416-b7804b056c",
|
|
29021
29249
|
"quickjs-emscripten": "^0.32.0",
|
|
29022
29250
|
typebox: "^1.3.1",
|
|
29023
29251
|
zod: "^4.1.8"
|
|
29024
29252
|
},
|
|
29253
|
+
optionalDependencies: {
|
|
29254
|
+
"onnxruntime-node": "1.24.3",
|
|
29255
|
+
sharp: "^0.34.5"
|
|
29256
|
+
},
|
|
29025
29257
|
devDependencies: {
|
|
29026
29258
|
"@biomejs/biome": "^2.5.1",
|
|
29259
|
+
"@huggingface/transformers": "^4.1.0",
|
|
29027
29260
|
"@earendil-works/pi-ai": "0.83.0",
|
|
29028
29261
|
"@earendil-works/pi-coding-agent": "0.83.0",
|
|
29029
29262
|
"@earendil-works/pi-tui": "0.83.0",
|
|
@@ -30352,7 +30585,7 @@ function resolveHistorianFromConfig(config) {
|
|
|
30352
30585
|
fallbackModels,
|
|
30353
30586
|
historianChunkTokens,
|
|
30354
30587
|
timeoutMs: config.historian_timeout_ms,
|
|
30355
|
-
temperature: historian?.temperature
|
|
30588
|
+
temperature: historian?.temperature,
|
|
30356
30589
|
maxOutputTokens: historian?.maxTokens ?? 32000,
|
|
30357
30590
|
twoPass: historian?.two_pass === true,
|
|
30358
30591
|
thinkingLevel: resolved.primary?.qualifier,
|