@cortexkit/pi-magic-context 0.30.3 → 0.30.5
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/README.md +1 -1
- package/dist/index.js +129 -64
- package/dist/subagent-entry.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -147,7 +147,7 @@ This package is part of the [magic-context monorepo](https://github.com/cortexki
|
|
|
147
147
|
| Pi-specific module | Responsibility |
|
|
148
148
|
|---|---|
|
|
149
149
|
| `context-handler.ts` | Pi `pi.on("context", ...)` adapter — tags, drops, runs nudges and auto-search |
|
|
150
|
-
| `subagent-runner.ts` | Spawns `pi --print --mode json --no-
|
|
150
|
+
| `subagent-runner.ts` | Spawns `pi --print --mode json --no-session ...` for historian/sidekick/dreamer subagents, keeps extension discovery on for provider/AFT extensions, sets `MAGIC_CONTEXT_PI_SUBAGENT=1` so the full Magic Context entry no-ops, and applies a per-agent `--tools`/`--no-tools` allow-list plus a 2-second terminal drain |
|
|
151
151
|
| `tools/` | Pi `pi.registerTool` wrappers around the shared tool implementations |
|
|
152
152
|
| `commands/` | Pi `pi.registerCommand` wrappers for the five `/ctx-*` slash commands |
|
|
153
153
|
| `dreamer/` | Pi-side adapter for the shared dreamer scheduler |
|
package/dist/index.js
CHANGED
|
@@ -156487,9 +156487,11 @@ function compareSemverCore(a, b) {
|
|
|
156487
156487
|
|
|
156488
156488
|
// ../plugin/src/shared/announcement.ts
|
|
156489
156489
|
init_data_path();
|
|
156490
|
-
var ANNOUNCEMENT_VERSION = "0.30.
|
|
156490
|
+
var ANNOUNCEMENT_VERSION = "0.30.4";
|
|
156491
156491
|
var ANNOUNCEMENT_FEATURES = [
|
|
156492
|
-
"
|
|
156492
|
+
"Pi: fixed historian and dreamer failing when your model comes from a provider extension (Antigravity, Anthropic OAuth, etc.). Subagents now load your extensions.",
|
|
156493
|
+
"Pi: fixed the retrospective and refresh-primers dreamer tasks reading sessions through the wrong API.",
|
|
156494
|
+
"OpenCode: the plugin no longer re-adds its TUI sidebar entry on startup, so removing it from tui.jsonc now sticks."
|
|
156493
156495
|
];
|
|
156494
156496
|
var ANNOUNCEMENT_FOOTER = "Join us on Discord: https://discord.gg/F2uWxjGnU";
|
|
156495
156497
|
var STATE_FILENAME = "last_announced_version";
|
|
@@ -156665,8 +156667,9 @@ init_logger();
|
|
|
156665
156667
|
|
|
156666
156668
|
// src/subagent-runner.ts
|
|
156667
156669
|
import * as childProcess from "node:child_process";
|
|
156668
|
-
import { existsSync as existsSync7 } from "node:fs";
|
|
156670
|
+
import { existsSync as existsSync7, mkdtempSync as mkdtempSync2, rmSync as rmSync2, writeFileSync as writeFileSync5 } from "node:fs";
|
|
156669
156671
|
import { createRequire as createRequire2 } from "node:module";
|
|
156672
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
156670
156673
|
import { basename as basename2, dirname as dirname4, join as join8, resolve as resolvePath } from "node:path";
|
|
156671
156674
|
import { createInterface } from "node:readline";
|
|
156672
156675
|
import { fileURLToPath } from "node:url";
|
|
@@ -156833,6 +156836,10 @@ function resolveSubagentEntryPath() {
|
|
|
156833
156836
|
}
|
|
156834
156837
|
var SUBAGENT_ENTRY_PATH = resolveSubagentEntryPath();
|
|
156835
156838
|
var TERMINAL_DRAIN_GRACE_MS = 2000;
|
|
156839
|
+
var MAGIC_CONTEXT_PI_SUBAGENT_ENV = "MAGIC_CONTEXT_PI_SUBAGENT";
|
|
156840
|
+
var PI_READ_ONLY_BUILTINS = ["read", "grep", "find", "ls"];
|
|
156841
|
+
var PI_AFT_READ_TOOLS = ["aft_outline", "aft_zoom", "aft_search"];
|
|
156842
|
+
var PI_HISTORIAN_TOOLS = [...PI_READ_ONLY_BUILTINS, "aft_search"];
|
|
156836
156843
|
var DREAMER_ACTION_AGENTS = new Set([
|
|
156837
156844
|
"dreamer",
|
|
156838
156845
|
"magic-context-dreamer"
|
|
@@ -156842,17 +156849,29 @@ var SEARCH_ONLY_SUBAGENT_TOOL_AGENTS = new Set([
|
|
|
156842
156849
|
"dreamer-retrospective",
|
|
156843
156850
|
"dreamer-primer-investigator"
|
|
156844
156851
|
]);
|
|
156845
|
-
var
|
|
156852
|
+
var STRICT_TOOL_ALLOWLIST_ENTRIES = [
|
|
156846
156853
|
["dreamer-retrospective", ["ctx_search"]],
|
|
156847
156854
|
["smart-note-compiler", []],
|
|
156855
|
+
["magic-context-historian", PI_HISTORIAN_TOOLS],
|
|
156856
|
+
["historian", PI_HISTORIAN_TOOLS],
|
|
156857
|
+
["historian-recomp", PI_HISTORIAN_TOOLS],
|
|
156858
|
+
["historian-editor", PI_HISTORIAN_TOOLS],
|
|
156859
|
+
["sidekick", [...PI_READ_ONLY_BUILTINS, "ctx_search"]],
|
|
156848
156860
|
["dreamer-classifier", []],
|
|
156849
156861
|
["dreamer-reviewer", []],
|
|
156850
|
-
[
|
|
156851
|
-
|
|
156852
|
-
|
|
156862
|
+
[
|
|
156863
|
+
"dreamer-primer-investigator",
|
|
156864
|
+
[...PI_READ_ONLY_BUILTINS, ...PI_AFT_READ_TOOLS, "ctx_search"]
|
|
156865
|
+
],
|
|
156866
|
+
["dreamer-memory-mapper", [...PI_READ_ONLY_BUILTINS, ...PI_AFT_READ_TOOLS]],
|
|
156867
|
+
[
|
|
156868
|
+
"dreamer-docs",
|
|
156869
|
+
[...PI_READ_ONLY_BUILTINS, "bash", "write", "edit", ...PI_AFT_READ_TOOLS]
|
|
156870
|
+
],
|
|
156853
156871
|
["dreamer", ["ctx_memory"]],
|
|
156854
156872
|
["magic-context-dreamer", ["ctx_memory"]]
|
|
156855
|
-
]
|
|
156873
|
+
];
|
|
156874
|
+
var STRICT_TOOL_ALLOWLIST = new Map(STRICT_TOOL_ALLOWLIST_ENTRIES);
|
|
156856
156875
|
function inferAccountingSubagent(agent) {
|
|
156857
156876
|
if (agent.includes("sidekick"))
|
|
156858
156877
|
return "sidekick";
|
|
@@ -156871,9 +156890,11 @@ class PiSubagentRunner {
|
|
|
156871
156890
|
harness = "pi";
|
|
156872
156891
|
invocation;
|
|
156873
156892
|
spawnImpl;
|
|
156893
|
+
platform;
|
|
156874
156894
|
constructor(options = {}) {
|
|
156875
156895
|
this.invocation = options.piBinary ? { command: options.piBinary, prefixArgs: [] } : resolvePiInvocation();
|
|
156876
156896
|
this.spawnImpl = options.spawnImpl ?? childProcess.spawn;
|
|
156897
|
+
this.platform = options.platform ?? process.platform;
|
|
156877
156898
|
}
|
|
156878
156899
|
async run(options) {
|
|
156879
156900
|
const models = [options.model, ...options.fallbackModels ?? []].filter((model) => typeof model === "string" && model.length > 0);
|
|
@@ -156932,10 +156953,47 @@ class PiSubagentRunner {
|
|
|
156932
156953
|
}
|
|
156933
156954
|
return result;
|
|
156934
156955
|
}
|
|
156956
|
+
const failBeforeSpawn = (reason, error) => {
|
|
156957
|
+
const result = {
|
|
156958
|
+
ok: false,
|
|
156959
|
+
reason,
|
|
156960
|
+
error,
|
|
156961
|
+
durationMs: Date.now() - startTime
|
|
156962
|
+
};
|
|
156963
|
+
try {
|
|
156964
|
+
recordAccounting(result);
|
|
156965
|
+
} catch (err) {
|
|
156966
|
+
sessionLog(options.accountingSessionId ?? "subagent", `subagent accounting failed (continuing): ${err instanceof Error ? err.message : String(err)}`);
|
|
156967
|
+
}
|
|
156968
|
+
return result;
|
|
156969
|
+
};
|
|
156935
156970
|
const promptBytes = Buffer.byteLength(options.userMessage, "utf8");
|
|
156936
|
-
const deliverViaStdin = promptBytes > PROMPT_ARGV_MAX_BYTES;
|
|
156971
|
+
const deliverViaStdin = promptBytes > PROMPT_ARGV_MAX_BYTES || this.platform === "win32";
|
|
156972
|
+
let systemPromptTempDir;
|
|
156973
|
+
let systemPromptPath;
|
|
156974
|
+
const cleanupSystemPromptFile = () => {
|
|
156975
|
+
if (!systemPromptTempDir)
|
|
156976
|
+
return;
|
|
156977
|
+
const tempDir = systemPromptTempDir;
|
|
156978
|
+
systemPromptTempDir = undefined;
|
|
156979
|
+
systemPromptPath = undefined;
|
|
156980
|
+
try {
|
|
156981
|
+
rmSync2(tempDir, { recursive: true, force: true });
|
|
156982
|
+
} catch {}
|
|
156983
|
+
};
|
|
156984
|
+
if (options.systemPrompt.length > 0) {
|
|
156985
|
+
try {
|
|
156986
|
+
systemPromptTempDir = mkdtempSync2(join8(tmpdir2(), "mc-pi-prompt-"));
|
|
156987
|
+
systemPromptPath = join8(systemPromptTempDir, "system-prompt.txt");
|
|
156988
|
+
writeFileSync5(systemPromptPath, options.systemPrompt, "utf8");
|
|
156989
|
+
} catch (error) {
|
|
156990
|
+
cleanupSystemPromptFile();
|
|
156991
|
+
return failBeforeSpawn("spawn_failed", `failed to prepare pi system prompt file: ${error instanceof Error ? error.message : String(error)}`);
|
|
156992
|
+
}
|
|
156993
|
+
}
|
|
156937
156994
|
const args = buildArgs(options, {
|
|
156938
|
-
omitPositionalMessage: deliverViaStdin
|
|
156995
|
+
omitPositionalMessage: deliverViaStdin,
|
|
156996
|
+
systemPromptPath
|
|
156939
156997
|
});
|
|
156940
156998
|
return new Promise((resolve) => {
|
|
156941
156999
|
let accountingMessages = [];
|
|
@@ -156944,6 +157002,7 @@ class PiSubagentRunner {
|
|
|
156944
157002
|
if (settled)
|
|
156945
157003
|
return;
|
|
156946
157004
|
settled = true;
|
|
157005
|
+
cleanupSystemPromptFile();
|
|
156947
157006
|
try {
|
|
156948
157007
|
recordAccounting(result, accountingMessages);
|
|
156949
157008
|
} catch (err) {
|
|
@@ -156962,10 +157021,14 @@ class PiSubagentRunner {
|
|
|
156962
157021
|
try {
|
|
156963
157022
|
child = this.spawnImpl(this.invocation.command, [...this.invocation.prefixArgs, ...args], {
|
|
156964
157023
|
cwd: options.cwd,
|
|
156965
|
-
env:
|
|
157024
|
+
env: {
|
|
157025
|
+
...process.env,
|
|
157026
|
+
[MAGIC_CONTEXT_PI_SUBAGENT_ENV]: "1"
|
|
157027
|
+
},
|
|
156966
157028
|
stdio: [deliverViaStdin ? "pipe" : "ignore", "pipe", "pipe"]
|
|
156967
157029
|
});
|
|
156968
157030
|
} catch (error) {
|
|
157031
|
+
cleanupSystemPromptFile();
|
|
156969
157032
|
settle({
|
|
156970
157033
|
ok: false,
|
|
156971
157034
|
reason: "spawn_failed",
|
|
@@ -157258,9 +157321,9 @@ function buildArgs(options, opts) {
|
|
|
157258
157321
|
"--mode",
|
|
157259
157322
|
"json",
|
|
157260
157323
|
"--no-session",
|
|
157261
|
-
"--no-extensions",
|
|
157262
157324
|
"--no-skills",
|
|
157263
|
-
"--no-prompt-templates"
|
|
157325
|
+
"--no-prompt-templates",
|
|
157326
|
+
"--no-context-files"
|
|
157264
157327
|
];
|
|
157265
157328
|
const shouldLoadSubagentExtension = SUBAGENT_ENTRY_PATH && (SEARCH_ONLY_SUBAGENT_TOOL_AGENTS.has(options.agent) || DREAMER_ACTION_AGENTS.has(options.agent));
|
|
157266
157329
|
if (shouldLoadSubagentExtension) {
|
|
@@ -157270,15 +157333,18 @@ function buildArgs(options, opts) {
|
|
|
157270
157333
|
}
|
|
157271
157334
|
}
|
|
157272
157335
|
const strictTools = STRICT_TOOL_ALLOWLIST.get(options.agent);
|
|
157273
|
-
if (strictTools) {
|
|
157336
|
+
if (strictTools === undefined) {
|
|
157337
|
+
sessionLog(options.accountingSessionId ?? "pi-subagent", `Pi subagent agent "${options.agent}" has no strict tool allow-list; forcing --no-tools`);
|
|
157338
|
+
args.push("--no-tools");
|
|
157339
|
+
} else {
|
|
157274
157340
|
if (strictTools.length > 0) {
|
|
157275
157341
|
args.push("--tools", strictTools.join(","));
|
|
157276
157342
|
} else {
|
|
157277
157343
|
args.push("--no-tools");
|
|
157278
157344
|
}
|
|
157279
157345
|
}
|
|
157280
|
-
if (
|
|
157281
|
-
args.push("--system-prompt",
|
|
157346
|
+
if (opts?.systemPromptPath) {
|
|
157347
|
+
args.push("--system-prompt", opts.systemPromptPath);
|
|
157282
157348
|
}
|
|
157283
157349
|
if (typeof options.model === "string" && options.model.length > 0) {
|
|
157284
157350
|
args.push("--model", resolveModelRefForPi(options.model));
|
|
@@ -172515,7 +172581,7 @@ var DreamTasksSchema = exports_external.object({
|
|
|
172515
172581
|
}).describe("Per-task scheduling + model config. Each task has its own cron schedule and may override the dreamer-level model.");
|
|
172516
172582
|
var DreamerConfigSchema = AgentOverrideConfigSchema.merge(exports_external.object({
|
|
172517
172583
|
tasks: DreamTasksSchema.default(() => DreamTasksSchema.parse({})),
|
|
172518
|
-
inject_docs: exports_external.boolean().default(true).describe("Inject ARCHITECTURE.md and STRUCTURE.md into
|
|
172584
|
+
inject_docs: exports_external.boolean().default(true).describe("Inject ARCHITECTURE.md and STRUCTURE.md into the m[0] `<project-docs>` block (default true)"),
|
|
172519
172585
|
thinking_level: PiThinkingLevelSchema.describe("Pi only: default thinking level for dreamer subagent invocations. See historian.thinking_level.")
|
|
172520
172586
|
}));
|
|
172521
172587
|
var SidekickConfigSchema = AgentOverrideConfigSchema.extend({
|
|
@@ -179021,7 +179087,7 @@ Output exactly JSON: {"met": false}`;
|
|
|
179021
179087
|
|
|
179022
179088
|
// ../plugin/src/features/magic-context/dreamer/maintain-docs-protected-enforcement.ts
|
|
179023
179089
|
init_logger();
|
|
179024
|
-
import { existsSync as existsSync10, readFileSync as readFileSync6, writeFileSync as
|
|
179090
|
+
import { existsSync as existsSync10, readFileSync as readFileSync6, writeFileSync as writeFileSync6 } from "node:fs";
|
|
179025
179091
|
import { join as join11 } from "node:path";
|
|
179026
179092
|
|
|
179027
179093
|
// ../plugin/src/features/magic-context/dreamer/protected-regions.ts
|
|
@@ -179141,7 +179207,7 @@ function enforceMaintainDocsProtectedRegions(args) {
|
|
|
179141
179207
|
if (!violated) {
|
|
179142
179208
|
continue;
|
|
179143
179209
|
}
|
|
179144
|
-
|
|
179210
|
+
writeFileSync6(path9, text, "utf8");
|
|
179145
179211
|
log(`[dreamer] maintain-docs altered a protected region in ${fileName} — restored from pre-task snapshot`);
|
|
179146
179212
|
} catch (error51) {
|
|
179147
179213
|
log(`[dreamer] maintain-docs protected-region enforcement failed for ${fileName}: ${error51}`);
|
|
@@ -183682,8 +183748,26 @@ function synthesizeToolResultParts(msg) {
|
|
|
183682
183748
|
];
|
|
183683
183749
|
}
|
|
183684
183750
|
|
|
183685
|
-
// src/dreamer/
|
|
183751
|
+
// src/dreamer/pi-session-api.ts
|
|
183752
|
+
import { readFileSync as readFileSync9 } from "node:fs";
|
|
183686
183753
|
var PI_CODING_AGENT_MODULE = "@earendil-works/pi-coding-agent";
|
|
183754
|
+
async function loadDefaultPiSessionApi() {
|
|
183755
|
+
const mod = await import(PI_CODING_AGENT_MODULE);
|
|
183756
|
+
const listSessions = mod.SessionManager?.listAll;
|
|
183757
|
+
if (typeof listSessions !== "function") {
|
|
183758
|
+
throw new Error("Pi session APIs unavailable: expected SessionManager.listAll on pi-coding-agent");
|
|
183759
|
+
}
|
|
183760
|
+
const loadEntriesFromFile = mod.loadEntriesFromFile ?? ((filePath) => {
|
|
183761
|
+
const content = readFileSync9(filePath, "utf8");
|
|
183762
|
+
return mod.parseSessionEntries?.(content) ?? [];
|
|
183763
|
+
});
|
|
183764
|
+
return {
|
|
183765
|
+
listSessions: listSessions.bind(mod.SessionManager),
|
|
183766
|
+
loadEntriesFromFile
|
|
183767
|
+
};
|
|
183768
|
+
}
|
|
183769
|
+
|
|
183770
|
+
// src/dreamer/primer-raw-provider-pi.ts
|
|
183687
183771
|
function createPiPrimerRawProviderFactory(deps = {}) {
|
|
183688
183772
|
let resolved = null;
|
|
183689
183773
|
const resolveDeps = async () => {
|
|
@@ -183693,7 +183777,7 @@ function createPiPrimerRawProviderFactory(deps = {}) {
|
|
|
183693
183777
|
loadEntriesFromFile: deps.loadEntriesFromFile
|
|
183694
183778
|
};
|
|
183695
183779
|
}
|
|
183696
|
-
resolved ??=
|
|
183780
|
+
resolved ??= loadDefaultPiSessionApi();
|
|
183697
183781
|
return resolved;
|
|
183698
183782
|
};
|
|
183699
183783
|
return async (sessionId) => {
|
|
@@ -183720,24 +183804,9 @@ function createPiPrimerRawProviderFactory(deps = {}) {
|
|
|
183720
183804
|
}
|
|
183721
183805
|
};
|
|
183722
183806
|
}
|
|
183723
|
-
async function loadDefaultPiSessionDeps() {
|
|
183724
|
-
const mod = await import(PI_CODING_AGENT_MODULE);
|
|
183725
|
-
const listSessions = mod.SessionManager?.listSessions;
|
|
183726
|
-
const loadEntriesFromFile = mod.loadEntriesFromFile;
|
|
183727
|
-
if (typeof listSessions !== "function" || typeof loadEntriesFromFile !== "function") {
|
|
183728
|
-
throw new Error("Pi session APIs unavailable: expected SessionManager.listSessions and loadEntriesFromFile");
|
|
183729
|
-
}
|
|
183730
|
-
return {
|
|
183731
|
-
listSessions: listSessions.bind(mod.SessionManager),
|
|
183732
|
-
loadEntriesFromFile
|
|
183733
|
-
};
|
|
183734
|
-
}
|
|
183735
183807
|
|
|
183736
183808
|
// src/dreamer/retrospective-raw-provider-pi.ts
|
|
183737
|
-
import { readFileSync as readFileSync9 } from "node:fs";
|
|
183738
183809
|
import { resolve as resolve2 } from "node:path";
|
|
183739
|
-
var PI_CODING_AGENT_MODULE2 = "@earendil-works/pi-coding-agent";
|
|
183740
|
-
|
|
183741
183810
|
class PiRetrospectiveRawProvider {
|
|
183742
183811
|
deps;
|
|
183743
183812
|
sessionPathById = new Map;
|
|
@@ -183803,7 +183872,7 @@ class PiRetrospectiveRawProvider {
|
|
|
183803
183872
|
loadEntriesFromFile: this.deps.loadEntriesFromFile
|
|
183804
183873
|
};
|
|
183805
183874
|
}
|
|
183806
|
-
this.resolvedDefaultDeps ??=
|
|
183875
|
+
this.resolvedDefaultDeps ??= loadDefaultPiSessionApi();
|
|
183807
183876
|
return this.resolvedDefaultDeps;
|
|
183808
183877
|
}
|
|
183809
183878
|
}
|
|
@@ -183840,21 +183909,6 @@ function extractPiTextContent(content) {
|
|
|
183840
183909
|
}).join(`
|
|
183841
183910
|
`);
|
|
183842
183911
|
}
|
|
183843
|
-
async function loadDefaultPiSessionDeps2() {
|
|
183844
|
-
const mod = await import(PI_CODING_AGENT_MODULE2);
|
|
183845
|
-
const listSessions = mod.SessionManager?.listAll;
|
|
183846
|
-
if (typeof listSessions !== "function") {
|
|
183847
|
-
throw new Error("Pi session APIs unavailable: expected SessionManager.listAll on pi-coding-agent");
|
|
183848
|
-
}
|
|
183849
|
-
const loadEntriesFromFile = mod.loadEntriesFromFile ?? ((filePath) => {
|
|
183850
|
-
const content = readFileSync9(filePath, "utf8");
|
|
183851
|
-
return mod.parseSessionEntries?.(content) ?? [];
|
|
183852
|
-
});
|
|
183853
|
-
return {
|
|
183854
|
-
listSessions: listSessions.bind(mod.SessionManager),
|
|
183855
|
-
loadEntriesFromFile
|
|
183856
|
-
};
|
|
183857
|
-
}
|
|
183858
183912
|
|
|
183859
183913
|
// src/dreamer/index.ts
|
|
183860
183914
|
var registeredProjects2 = new Map;
|
|
@@ -189857,6 +189911,13 @@ function safeGetActiveUserMemoriesPi(db) {
|
|
|
189857
189911
|
throw error51;
|
|
189858
189912
|
}
|
|
189859
189913
|
}
|
|
189914
|
+
var EMPTY_PI_PROJECT_DOCS = {
|
|
189915
|
+
renderedBlock: "",
|
|
189916
|
+
canonicalHash: ""
|
|
189917
|
+
};
|
|
189918
|
+
function readProjectDocsForPiM0(state) {
|
|
189919
|
+
return state.injectDocs !== false ? readProjectDocsCanonical(state.projectDirectory) : EMPTY_PI_PROJECT_DOCS;
|
|
189920
|
+
}
|
|
189860
189921
|
function memoryProjectPath(state) {
|
|
189861
189922
|
return state.memoryEnabled === false ? undefined : state.projectIdentity;
|
|
189862
189923
|
}
|
|
@@ -189983,7 +190044,7 @@ function readCurrentMarkersFromCompartments(db, state, compartments, projectDocs
|
|
|
189983
190044
|
projectMemoryEpoch: projectState?.projectMemoryEpoch ?? 0,
|
|
189984
190045
|
workspaceFingerprint: workspace.isWorkspaced ? computeWorkspaceEpochFingerprint(db, workspace.identities) : null,
|
|
189985
190046
|
projectUserProfileVersion: globalState?.projectUserProfileVersion ?? 0,
|
|
189986
|
-
projectDocsHash: projectDocsHash ??
|
|
190047
|
+
projectDocsHash: projectDocsHash ?? readProjectDocsForPiM0(state).canonicalHash,
|
|
189987
190048
|
sessionFactsVersion: getSessionFactsVersion(db, state.sessionId),
|
|
189988
190049
|
materializedAt: Date.now(),
|
|
189989
190050
|
upgradeState: `${PI_M0_UPGRADE_STATE}:${compartments.some((c) => c.legacy === 1) ? "legacy" : "ready"}`,
|
|
@@ -190044,7 +190105,7 @@ ${memories.map((memory) => `- ${escapeXmlContent(memory.content)}`).join(`
|
|
|
190044
190105
|
`)}
|
|
190045
190106
|
</${wrapper}>`;
|
|
190046
190107
|
}
|
|
190047
|
-
function renderM0Pi(state, db, projectDocs =
|
|
190108
|
+
function renderM0Pi(state, db, projectDocs = readProjectDocsForPiM0(state).renderedBlock, decayPressureMultiplier = 1, memoriesOverride, compartmentsOverride, userProfileOverride, workspaceOverride) {
|
|
190048
190109
|
const memPath = memoryProjectPath(state);
|
|
190049
190110
|
const workspace = workspaceOverride ?? resolveWorkspaceRenderContextPi(state, db);
|
|
190050
190111
|
const allMemories = memoriesOverride ?? (memPath ? workspace.isWorkspaced ? getMemoriesByProjects(db, workspace.expandedIdentities, ["active", "permanent"], Date.now(), workspace.ownIdentities, workspace.shareCategories) : getMemoriesByProject(db, memPath, ["active", "permanent"]) : []);
|
|
@@ -190112,7 +190173,7 @@ class PiMaterializeContentionError extends Error {
|
|
|
190112
190173
|
this.name = "PiMaterializeContentionError";
|
|
190113
190174
|
}
|
|
190114
190175
|
}
|
|
190115
|
-
function readFrozenM0InputsPi(state, db, docs =
|
|
190176
|
+
function readFrozenM0InputsPi(state, db, docs = readProjectDocsForPiM0(state), memoryCutoff) {
|
|
190116
190177
|
const memPath = memoryProjectPath(state);
|
|
190117
190178
|
const read = db.transaction(() => {
|
|
190118
190179
|
const workspace = resolveWorkspaceRenderContextPi(state, db);
|
|
@@ -190143,7 +190204,7 @@ function readFrozenM0InputsPi(state, db, docs = readProjectDocsCanonical(state.p
|
|
|
190143
190204
|
return read();
|
|
190144
190205
|
}
|
|
190145
190206
|
function renderFreshM0PiNonPersisted(state, db) {
|
|
190146
|
-
const docs =
|
|
190207
|
+
const docs = readProjectDocsForPiM0(state);
|
|
190147
190208
|
const cachedMaterializedAt = getOrCreateSessionMeta(db, state.sessionId).cachedM0MaterializedAt ?? 0;
|
|
190148
190209
|
const frozen = readFrozenM0InputsPi(state, db, docs, cachedMaterializedAt);
|
|
190149
190210
|
frozen.markers.materializedAt = cachedMaterializedAt;
|
|
@@ -190163,7 +190224,7 @@ function renderFreshM0PiNonPersisted(state, db) {
|
|
|
190163
190224
|
};
|
|
190164
190225
|
}
|
|
190165
190226
|
function materializeM0Pi(state, db) {
|
|
190166
|
-
const docs =
|
|
190227
|
+
const docs = readProjectDocsForPiM0(state);
|
|
190167
190228
|
const foldMaterializedAt = Date.now();
|
|
190168
190229
|
const frozen = readFrozenM0InputsPi(state, db, docs, foldMaterializedAt);
|
|
190169
190230
|
const snapshotMarkers = frozen.markers;
|
|
@@ -190181,7 +190242,7 @@ function materializeM0Pi(state, db) {
|
|
|
190181
190242
|
attempts += 1;
|
|
190182
190243
|
}
|
|
190183
190244
|
const m0Bytes = Buffer.from(m0, "utf8");
|
|
190184
|
-
const phase3ProjectDocsHash =
|
|
190245
|
+
const phase3ProjectDocsHash = readProjectDocsForPiM0(state).canonicalHash;
|
|
190185
190246
|
try {
|
|
190186
190247
|
db.exec("BEGIN IMMEDIATE");
|
|
190187
190248
|
} catch (error51) {
|
|
@@ -197312,6 +197373,7 @@ async function runPipeline(args) {
|
|
|
197312
197373
|
projectIdentity: args.projectIdentity,
|
|
197313
197374
|
projectDirectory: args.projectDirectory,
|
|
197314
197375
|
memoryEnabled: args.injection.memoryEnabled,
|
|
197376
|
+
injectDocs: args.injection.injectDocs,
|
|
197315
197377
|
injectionBudgetTokens: args.injection.injectionBudgetTokens,
|
|
197316
197378
|
historyBudgetTokens: args.injection.historyBudgetTokens,
|
|
197317
197379
|
hardSignals: piHardSignals
|
|
@@ -197623,7 +197685,7 @@ ${result}`;
|
|
|
197623
197685
|
init_logger();
|
|
197624
197686
|
|
|
197625
197687
|
// ../plugin/src/hooks/magic-context/historian-state-file.ts
|
|
197626
|
-
import { mkdirSync as mkdirSync8, unlinkSync as unlinkSync2, writeFileSync as
|
|
197688
|
+
import { mkdirSync as mkdirSync8, unlinkSync as unlinkSync2, writeFileSync as writeFileSync7 } from "node:fs";
|
|
197627
197689
|
init_data_path();
|
|
197628
197690
|
function cleanupHistorianStateFile(path11) {
|
|
197629
197691
|
if (!path11)
|
|
@@ -197716,7 +197778,7 @@ function updateCompactionMarkerAfterPublication(db, sessionId, lastCompartmentEn
|
|
|
197716
197778
|
}
|
|
197717
197779
|
|
|
197718
197780
|
// ../plugin/src/hooks/magic-context/compartment-runner-historian.ts
|
|
197719
|
-
import { mkdirSync as mkdirSync9, unlinkSync as unlinkSync3, writeFileSync as
|
|
197781
|
+
import { mkdirSync as mkdirSync9, unlinkSync as unlinkSync3, writeFileSync as writeFileSync8 } from "node:fs";
|
|
197720
197782
|
import { join as join12 } from "node:path";
|
|
197721
197783
|
|
|
197722
197784
|
// ../plugin/src/agents/historian.ts
|
|
@@ -198036,7 +198098,7 @@ function dumpHistorianResponse(sessionId, directory, label, text) {
|
|
|
198036
198098
|
const safeSessionId = sanitizeDumpName(sessionId);
|
|
198037
198099
|
const safeLabel = sanitizeDumpName(label);
|
|
198038
198100
|
const dumpPath = join12(dumpDir, `${safeSessionId}-${safeLabel}-${Date.now()}.xml`);
|
|
198039
|
-
|
|
198101
|
+
writeFileSync8(dumpPath, text, "utf8");
|
|
198040
198102
|
sessionLog(sessionId, "compartment agent: historian response dumped", {
|
|
198041
198103
|
label,
|
|
198042
198104
|
dumpPath
|
|
@@ -200001,7 +200063,7 @@ function formatThresholdPercent(value) {
|
|
|
200001
200063
|
// package.json
|
|
200002
200064
|
var package_default = {
|
|
200003
200065
|
name: "@cortexkit/pi-magic-context",
|
|
200004
|
-
version: "0.30.
|
|
200066
|
+
version: "0.30.5",
|
|
200005
200067
|
type: "module",
|
|
200006
200068
|
description: "Pi coding agent extension for Magic Context — cross-session memory and context management",
|
|
200007
200069
|
main: "dist/index.js",
|
|
@@ -206350,6 +206412,10 @@ function resolveDreamerFromConfig(config2) {
|
|
|
206350
206412
|
return config2.dreamer?.disable === true ? undefined : config2.dreamer;
|
|
206351
206413
|
}
|
|
206352
206414
|
async function src_default2(pi) {
|
|
206415
|
+
if (process.env[MAGIC_CONTEXT_PI_SUBAGENT_ENV] === "1") {
|
|
206416
|
+
log(`${PREFIX} subagent child detected (${MAGIC_CONTEXT_PI_SUBAGENT_ENV}=1); skipping full extension registration`);
|
|
206417
|
+
return;
|
|
206418
|
+
}
|
|
206353
206419
|
const storageDir = getMagicContextStorageDir();
|
|
206354
206420
|
const dbPath = join13(storageDir, "context.db");
|
|
206355
206421
|
let db;
|
|
@@ -206443,6 +206509,7 @@ async function src_default2(pi) {
|
|
|
206443
206509
|
},
|
|
206444
206510
|
injection: {
|
|
206445
206511
|
memoryEnabled: cfg.memory.enabled,
|
|
206512
|
+
injectDocs: cfg.dreamer?.inject_docs !== false,
|
|
206446
206513
|
injectionBudgetTokens: cfg.memory.injection_budget_tokens,
|
|
206447
206514
|
temporalAwareness: cfg.temporal_awareness === true
|
|
206448
206515
|
},
|
|
@@ -206671,13 +206738,11 @@ async function src_default2(pi) {
|
|
|
206671
206738
|
}
|
|
206672
206739
|
const isCacheBusting = sessionId ? hasSystemPromptRefresh(sessionId) : true;
|
|
206673
206740
|
const effectiveDreamerRunnable = switchedProject ? isDreamerRunnable(effectiveConfig) : isDreamerRunnable(config2);
|
|
206674
|
-
const injectDocs = switchedProject ? effectiveDreamerRunnable && (effectiveConfig.dreamer?.inject_docs ?? true) : isDreamerRunnable(config2) && (config2.dreamer?.inject_docs ?? true);
|
|
206675
206741
|
const block = buildMagicContextBlock({
|
|
206676
206742
|
db,
|
|
206677
206743
|
cwd: currentProject.projectDir,
|
|
206678
206744
|
sessionId,
|
|
206679
206745
|
memoryEnabled: effectiveConfig.memory.enabled,
|
|
206680
|
-
injectDocs,
|
|
206681
206746
|
includeGuidance: true,
|
|
206682
206747
|
protectedTags: effectiveConfig.protected_tags,
|
|
206683
206748
|
ctxReduceEnabled: effectiveConfig.ctx_reduce_enabled,
|
package/dist/subagent-entry.js
CHANGED
|
@@ -159656,7 +159656,7 @@ var DreamTasksSchema = exports_external.object({
|
|
|
159656
159656
|
}).describe("Per-task scheduling + model config. Each task has its own cron schedule and may override the dreamer-level model.");
|
|
159657
159657
|
var DreamerConfigSchema = AgentOverrideConfigSchema.merge(exports_external.object({
|
|
159658
159658
|
tasks: DreamTasksSchema.default(() => DreamTasksSchema.parse({})),
|
|
159659
|
-
inject_docs: exports_external.boolean().default(true).describe("Inject ARCHITECTURE.md and STRUCTURE.md into
|
|
159659
|
+
inject_docs: exports_external.boolean().default(true).describe("Inject ARCHITECTURE.md and STRUCTURE.md into the m[0] `<project-docs>` block (default true)"),
|
|
159660
159660
|
thinking_level: PiThinkingLevelSchema.describe("Pi only: default thinking level for dreamer subagent invocations. See historian.thinking_level.")
|
|
159661
159661
|
}));
|
|
159662
159662
|
var SidekickConfigSchema = AgentOverrideConfigSchema.extend({
|
package/package.json
CHANGED