@cortexkit/magic-context 0.21.6 → 0.21.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +162 -38
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10987,25 +10987,28 @@ function writeMagicContextConfig(configPath, options) {
|
|
|
10987
10987
|
historian.model = options.historianModel;
|
|
10988
10988
|
config.historian = historian;
|
|
10989
10989
|
}
|
|
10990
|
+
const dreamer = config.dreamer ?? {};
|
|
10991
|
+
delete dreamer.enabled;
|
|
10990
10992
|
if (options.dreamerEnabled) {
|
|
10991
|
-
|
|
10992
|
-
dreamer.enabled = true;
|
|
10993
|
+
delete dreamer.disable;
|
|
10993
10994
|
if (options.dreamerModel) {
|
|
10994
10995
|
dreamer.model = options.dreamerModel;
|
|
10995
10996
|
}
|
|
10996
|
-
config.dreamer = dreamer;
|
|
10997
10997
|
} else {
|
|
10998
|
-
|
|
10999
|
-
dreamer.enabled = false;
|
|
11000
|
-
config.dreamer = dreamer;
|
|
10998
|
+
dreamer.disable = true;
|
|
11001
10999
|
}
|
|
11000
|
+
config.dreamer = dreamer;
|
|
11001
|
+
const sidekick = config.sidekick ?? {};
|
|
11002
|
+
delete sidekick.enabled;
|
|
11002
11003
|
if (options.sidekickEnabled) {
|
|
11003
|
-
|
|
11004
|
-
sidekick.enabled = true;
|
|
11004
|
+
delete sidekick.disable;
|
|
11005
11005
|
if (options.sidekickModel) {
|
|
11006
11006
|
sidekick.model = options.sidekickModel;
|
|
11007
11007
|
}
|
|
11008
11008
|
config.sidekick = sidekick;
|
|
11009
|
+
} else {
|
|
11010
|
+
sidekick.disable = true;
|
|
11011
|
+
config.sidekick = sidekick;
|
|
11009
11012
|
}
|
|
11010
11013
|
if (options.claudeMax) {
|
|
11011
11014
|
const cacheTtl = config.cache_ttl ?? {};
|
|
@@ -11311,23 +11314,20 @@ function writeMagicContextConfig2(configPath, options) {
|
|
|
11311
11314
|
model: options.historianModel,
|
|
11312
11315
|
thinking_level: options.historianThinkingLevel
|
|
11313
11316
|
});
|
|
11314
|
-
|
|
11317
|
+
const dreamer = {
|
|
11315
11318
|
...config.dreamer ?? {},
|
|
11316
|
-
|
|
11317
|
-
|
|
11319
|
+
model: options.dreamerModel,
|
|
11320
|
+
disable: options.dreamerEnabled ? undefined : true,
|
|
11321
|
+
enabled: undefined
|
|
11318
11322
|
};
|
|
11319
|
-
|
|
11320
|
-
|
|
11321
|
-
|
|
11322
|
-
|
|
11323
|
-
|
|
11324
|
-
|
|
11325
|
-
}
|
|
11326
|
-
|
|
11327
|
-
...config.sidekick ?? {},
|
|
11328
|
-
enabled: false
|
|
11329
|
-
};
|
|
11330
|
-
}
|
|
11323
|
+
config.dreamer = compactObject(dreamer);
|
|
11324
|
+
const sidekick = {
|
|
11325
|
+
...config.sidekick ?? {},
|
|
11326
|
+
model: options.sidekickEnabled ? options.sidekickModel : undefined,
|
|
11327
|
+
disable: options.sidekickEnabled ? undefined : true,
|
|
11328
|
+
enabled: undefined
|
|
11329
|
+
};
|
|
11330
|
+
config.sidekick = compactObject(sidekick);
|
|
11331
11331
|
config.embedding = options.embedding;
|
|
11332
11332
|
writeFileSync5(configPath, `${import_comment_json5.stringify(config, null, 2)}
|
|
11333
11333
|
`);
|
|
@@ -12532,6 +12532,53 @@ var init_migrate = __esm(async () => {
|
|
|
12532
12532
|
await init_sqlite();
|
|
12533
12533
|
});
|
|
12534
12534
|
|
|
12535
|
+
// ../plugin/src/config/agent-disable.ts
|
|
12536
|
+
function clonePlainObject(value) {
|
|
12537
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
12538
|
+
return;
|
|
12539
|
+
}
|
|
12540
|
+
return { ...value };
|
|
12541
|
+
}
|
|
12542
|
+
function migrateLegacyEnabledForAgent(args) {
|
|
12543
|
+
const agent = clonePlainObject(args.patched[args.agentName]);
|
|
12544
|
+
if (!agent || !("enabled" in agent))
|
|
12545
|
+
return;
|
|
12546
|
+
const enabled = agent.enabled;
|
|
12547
|
+
const disable = agent.disable;
|
|
12548
|
+
delete agent.enabled;
|
|
12549
|
+
if (args.agentName === "historian") {
|
|
12550
|
+
args.warnings.push('Removed invalid "historian.enabled" in-memory (run doctor to persist).');
|
|
12551
|
+
args.patched.historian = agent;
|
|
12552
|
+
return;
|
|
12553
|
+
}
|
|
12554
|
+
if (args.agentName === "dreamer") {
|
|
12555
|
+
if (disable !== true && enabled === false) {
|
|
12556
|
+
agent.disable = true;
|
|
12557
|
+
args.warnings.push('Migrated "dreamer.enabled=false" → "dreamer.disable=true" in-memory (run doctor to persist). This now also disables manual /ctx-dream; for manual-only remove disable and set schedule="".');
|
|
12558
|
+
}
|
|
12559
|
+
args.patched.dreamer = agent;
|
|
12560
|
+
return;
|
|
12561
|
+
}
|
|
12562
|
+
if (disable !== true && enabled === false) {
|
|
12563
|
+
agent.disable = true;
|
|
12564
|
+
args.warnings.push('Migrated "sidekick.enabled=false" → "sidekick.disable=true" in-memory (run doctor to persist).');
|
|
12565
|
+
}
|
|
12566
|
+
args.patched.sidekick = agent;
|
|
12567
|
+
}
|
|
12568
|
+
function migrateLegacyAgentEnabledInMemory(rawConfig, warnings) {
|
|
12569
|
+
const shouldPatch = ["dreamer", "sidekick", "historian"].some((key) => {
|
|
12570
|
+
const agent = rawConfig[key];
|
|
12571
|
+
return typeof agent === "object" && agent !== null && !Array.isArray(agent) && "enabled" in agent;
|
|
12572
|
+
});
|
|
12573
|
+
if (!shouldPatch)
|
|
12574
|
+
return rawConfig;
|
|
12575
|
+
const patched = { ...rawConfig };
|
|
12576
|
+
migrateLegacyEnabledForAgent({ patched, agentName: "dreamer", warnings });
|
|
12577
|
+
migrateLegacyEnabledForAgent({ patched, agentName: "sidekick", warnings });
|
|
12578
|
+
migrateLegacyEnabledForAgent({ patched, agentName: "historian", warnings });
|
|
12579
|
+
return patched;
|
|
12580
|
+
}
|
|
12581
|
+
|
|
12535
12582
|
// ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/core/core.js
|
|
12536
12583
|
function $constructor(name, initializer, params) {
|
|
12537
12584
|
function init(inst, def) {
|
|
@@ -27211,7 +27258,6 @@ var init_magic_context = __esm(() => {
|
|
|
27211
27258
|
];
|
|
27212
27259
|
PiThinkingLevelSchema = exports_external.enum(["off", "minimal", "low", "medium", "high", "xhigh"]).optional();
|
|
27213
27260
|
DreamerConfigSchema = AgentOverrideConfigSchema.merge(exports_external.object({
|
|
27214
|
-
enabled: exports_external.boolean().default(false),
|
|
27215
27261
|
schedule: exports_external.string().default("02:00-06:00"),
|
|
27216
27262
|
max_runtime_minutes: exports_external.number().min(10).default(120),
|
|
27217
27263
|
tasks: exports_external.array(DreamingTaskSchema).default(DEFAULT_DREAMER_TASKS),
|
|
@@ -27229,7 +27275,6 @@ var init_magic_context = __esm(() => {
|
|
|
27229
27275
|
thinking_level: PiThinkingLevelSchema
|
|
27230
27276
|
}));
|
|
27231
27277
|
SidekickConfigSchema = AgentOverrideConfigSchema.extend({
|
|
27232
|
-
enabled: exports_external.boolean().default(false),
|
|
27233
27278
|
timeout_ms: exports_external.number().default(30000),
|
|
27234
27279
|
system_prompt: exports_external.string().optional(),
|
|
27235
27280
|
thinking_level: PiThinkingLevelSchema
|
|
@@ -27579,7 +27624,8 @@ function migrateLegacyExperimental(rawConfig, warnings) {
|
|
|
27579
27624
|
}
|
|
27580
27625
|
function parsePluginConfig(rawConfig, recoveredTopLevelKeys = []) {
|
|
27581
27626
|
const preMigrationWarnings = [];
|
|
27582
|
-
const
|
|
27627
|
+
const migratedExperimental = migrateLegacyExperimental(rawConfig, preMigrationWarnings);
|
|
27628
|
+
const migrated = migrateLegacyAgentEnabledInMemory(migratedExperimental, preMigrationWarnings);
|
|
27583
27629
|
const parsed = MagicContextConfigSchema.safeParse(migrated);
|
|
27584
27630
|
const disabledHooks = Array.isArray(rawConfig.disabled_hooks) ? rawConfig.disabled_hooks.filter((value) => typeof value === "string") : undefined;
|
|
27585
27631
|
const command = typeof rawConfig.command === "object" && rawConfig.command !== null ? rawConfig.command : undefined;
|
|
@@ -28768,6 +28814,43 @@ import { existsSync as existsSync17, readFileSync as readFileSync13, rmSync, sta
|
|
|
28768
28814
|
import { createRequire as createRequire4 } from "node:module";
|
|
28769
28815
|
import { homedir as homedir13 } from "node:os";
|
|
28770
28816
|
import { join as join16 } from "node:path";
|
|
28817
|
+
function migrateLegacyAgentEnabledConfigForDoctor(mcConfig, logs) {
|
|
28818
|
+
let changed = false;
|
|
28819
|
+
let fixes = 0;
|
|
28820
|
+
const migrateLegacyAgentEnabled = (agentName) => {
|
|
28821
|
+
const agent = mcConfig[agentName];
|
|
28822
|
+
if (!agent || typeof agent !== "object" || !("enabled" in agent))
|
|
28823
|
+
return;
|
|
28824
|
+
const enabled = agent.enabled;
|
|
28825
|
+
const disable = agent.disable;
|
|
28826
|
+
delete agent.enabled;
|
|
28827
|
+
changed = true;
|
|
28828
|
+
fixes++;
|
|
28829
|
+
if (agentName === "historian") {
|
|
28830
|
+
logs.success("Removed invalid historian.enabled (historian uses disable=true to turn off).");
|
|
28831
|
+
return;
|
|
28832
|
+
}
|
|
28833
|
+
if (agentName === "dreamer") {
|
|
28834
|
+
if (disable !== true && enabled === false) {
|
|
28835
|
+
agent.disable = true;
|
|
28836
|
+
logs.warn("Migrated dreamer.enabled=false → dreamer.disable=true. This now also disables manual /ctx-dream. To keep manual dreaming, remove disable=true and set schedule to empty string.");
|
|
28837
|
+
} else {
|
|
28838
|
+
logs.success('Removed deprecated dreamer.enabled (use dreamer.disable=true to turn off the Dreamer agent; use schedule="" for manual-only dreaming).');
|
|
28839
|
+
}
|
|
28840
|
+
return;
|
|
28841
|
+
}
|
|
28842
|
+
if (disable !== true && enabled === false) {
|
|
28843
|
+
agent.disable = true;
|
|
28844
|
+
logs.success("Migrated sidekick.enabled=false → sidekick.disable=true.");
|
|
28845
|
+
} else {
|
|
28846
|
+
logs.success("Removed deprecated sidekick.enabled (use sidekick.disable=true to turn off Sidekick).");
|
|
28847
|
+
}
|
|
28848
|
+
};
|
|
28849
|
+
migrateLegacyAgentEnabled("dreamer");
|
|
28850
|
+
migrateLegacyAgentEnabled("sidekick");
|
|
28851
|
+
migrateLegacyAgentEnabled("historian");
|
|
28852
|
+
return { changed, fixes };
|
|
28853
|
+
}
|
|
28771
28854
|
async function fetchNpmLatest(pkg, timeoutMs = 5000) {
|
|
28772
28855
|
try {
|
|
28773
28856
|
const controller = new AbortController;
|
|
@@ -29158,6 +29241,11 @@ async function runDoctor(options = {}) {
|
|
|
29158
29241
|
log.success("Removed deprecated compaction_markers (always-on since v0.21.4)");
|
|
29159
29242
|
fixed++;
|
|
29160
29243
|
}
|
|
29244
|
+
const agentEnabledMigration = migrateLegacyAgentEnabledConfigForDoctor(mcConfig, log);
|
|
29245
|
+
if (agentEnabledMigration.changed) {
|
|
29246
|
+
mcChanged = true;
|
|
29247
|
+
fixed += agentEnabledMigration.fixes;
|
|
29248
|
+
}
|
|
29161
29249
|
if (experimental && "user_memories" in experimental) {
|
|
29162
29250
|
const dreamer = mcConfig.dreamer ?? {};
|
|
29163
29251
|
const oldUM = experimental.user_memories;
|
|
@@ -29355,11 +29443,11 @@ async function runDoctor(options = {}) {
|
|
|
29355
29443
|
const mcRaw = readFileSync13(paths.magicContextConfig, "utf-8");
|
|
29356
29444
|
const mcConfig = import_comment_json9.parse(mcRaw);
|
|
29357
29445
|
const dreamerObj = mcConfig?.dreamer;
|
|
29358
|
-
const
|
|
29446
|
+
const dreamerDisabled = dreamerObj?.disable === true;
|
|
29359
29447
|
const userMemObj = dreamerObj?.user_memories;
|
|
29360
29448
|
const userMemEnabled = userMemObj?.enabled !== false;
|
|
29361
|
-
if (userMemEnabled &&
|
|
29362
|
-
log.warn("dreamer.user_memories is enabled
|
|
29449
|
+
if (userMemEnabled && dreamerDisabled) {
|
|
29450
|
+
log.warn("dreamer.user_memories is enabled but dreamer.disable=true, so new promotions will not run. Remove dreamer.disable or set dreamer.user_memories.enabled=false.");
|
|
29363
29451
|
issues++;
|
|
29364
29452
|
}
|
|
29365
29453
|
const pinKeyFilesObj = dreamerObj?.pin_key_files;
|
|
@@ -29534,11 +29622,11 @@ var init_doctor_opencode = __esm(async () => {
|
|
|
29534
29622
|
PLUGIN_ENTRY_WITH_VERSION2 = `${PLUGIN_NAME6}@latest`;
|
|
29535
29623
|
});
|
|
29536
29624
|
|
|
29537
|
-
// ../plugin/src/features/magic-context/compartment-
|
|
29538
|
-
var
|
|
29539
|
-
var
|
|
29540
|
-
|
|
29541
|
-
|
|
29625
|
+
// ../plugin/src/features/magic-context/compartment-lease.ts
|
|
29626
|
+
var COMPARTMENT_LEASE_TTL_MS, COMPARTMENT_LEASE_RENEWAL_MS;
|
|
29627
|
+
var init_compartment_lease = __esm(() => {
|
|
29628
|
+
COMPARTMENT_LEASE_TTL_MS = 5 * 60 * 1000;
|
|
29629
|
+
COMPARTMENT_LEASE_RENEWAL_MS = 60 * 1000;
|
|
29542
29630
|
});
|
|
29543
29631
|
|
|
29544
29632
|
// ../plugin/src/features/magic-context/compression-depth-storage.ts
|
|
@@ -29549,6 +29637,15 @@ var init_compression_depth_storage = __esm(() => {
|
|
|
29549
29637
|
maxDepthStatements = new WeakMap;
|
|
29550
29638
|
clearDepthStatements = new WeakMap;
|
|
29551
29639
|
});
|
|
29640
|
+
|
|
29641
|
+
// ../plugin/src/features/magic-context/compartment-storage.ts
|
|
29642
|
+
var insertCompartmentStatements, insertFactStatements;
|
|
29643
|
+
var init_compartment_storage = __esm(() => {
|
|
29644
|
+
init_compartment_lease();
|
|
29645
|
+
init_compression_depth_storage();
|
|
29646
|
+
insertCompartmentStatements = new WeakMap;
|
|
29647
|
+
insertFactStatements = new WeakMap;
|
|
29648
|
+
});
|
|
29552
29649
|
// ../plugin/src/shared/sqlite-helpers.ts
|
|
29553
29650
|
function closeQuietly(db) {
|
|
29554
29651
|
if (!db)
|
|
@@ -162611,6 +162708,22 @@ var init_migrations = __esm(async () => {
|
|
|
162611
162708
|
db.exec("ALTER TABLE session_meta ADD COLUMN pending_pi_compaction_marker_state TEXT");
|
|
162612
162709
|
}
|
|
162613
162710
|
}
|
|
162711
|
+
},
|
|
162712
|
+
{
|
|
162713
|
+
version: 19,
|
|
162714
|
+
description: "Add compartment state lease table",
|
|
162715
|
+
up: (db) => {
|
|
162716
|
+
db.exec(`
|
|
162717
|
+
CREATE TABLE IF NOT EXISTS compartment_state_lease (
|
|
162718
|
+
session_id TEXT PRIMARY KEY NOT NULL,
|
|
162719
|
+
holder_id TEXT NOT NULL,
|
|
162720
|
+
acquired_at INTEGER NOT NULL,
|
|
162721
|
+
expires_at INTEGER NOT NULL
|
|
162722
|
+
);
|
|
162723
|
+
CREATE INDEX IF NOT EXISTS idx_compartment_state_lease_expires
|
|
162724
|
+
ON compartment_state_lease(expires_at);
|
|
162725
|
+
`);
|
|
162726
|
+
}
|
|
162614
162727
|
}
|
|
162615
162728
|
];
|
|
162616
162729
|
});
|
|
@@ -162983,6 +163096,15 @@ function initializeDatabase(db) {
|
|
|
162983
163096
|
);
|
|
162984
163097
|
CREATE INDEX IF NOT EXISTS idx_compartments_session ON compartments(session_id);
|
|
162985
163098
|
|
|
163099
|
+
CREATE TABLE IF NOT EXISTS compartment_state_lease (
|
|
163100
|
+
session_id TEXT PRIMARY KEY NOT NULL,
|
|
163101
|
+
holder_id TEXT NOT NULL,
|
|
163102
|
+
acquired_at INTEGER NOT NULL,
|
|
163103
|
+
expires_at INTEGER NOT NULL
|
|
163104
|
+
);
|
|
163105
|
+
CREATE INDEX IF NOT EXISTS idx_compartment_state_lease_expires
|
|
163106
|
+
ON compartment_state_lease(expires_at);
|
|
163107
|
+
|
|
162986
163108
|
CREATE TABLE IF NOT EXISTS compression_depth (
|
|
162987
163109
|
session_id TEXT NOT NULL,
|
|
162988
163110
|
message_ordinal INTEGER NOT NULL,
|
|
@@ -163607,9 +163729,11 @@ function mergeRawConfigs(base, override) {
|
|
|
163607
163729
|
return merged;
|
|
163608
163730
|
}
|
|
163609
163731
|
function parsePiConfig(rawConfig, recoveredTopLevelKeys = []) {
|
|
163610
|
-
const
|
|
163732
|
+
const preMigrationWarnings = [];
|
|
163733
|
+
const migrated = migrateLegacyAgentEnabledInMemory(rawConfig, preMigrationWarnings);
|
|
163734
|
+
const parsed = MagicContextConfigSchema.safeParse(migrated);
|
|
163611
163735
|
if (parsed.success) {
|
|
163612
|
-
return { config: parsed.data, warnings:
|
|
163736
|
+
return { config: parsed.data, warnings: preMigrationWarnings };
|
|
163613
163737
|
}
|
|
163614
163738
|
const defaults = MagicContextConfigSchema.parse({});
|
|
163615
163739
|
const errorPaths = new Set;
|
|
@@ -163619,8 +163743,8 @@ function parsePiConfig(rawConfig, recoveredTopLevelKeys = []) {
|
|
|
163619
163743
|
errorPaths.add(String(topKey));
|
|
163620
163744
|
}
|
|
163621
163745
|
}
|
|
163622
|
-
const patched = { ...
|
|
163623
|
-
const warnings = [];
|
|
163746
|
+
const patched = { ...migrated };
|
|
163747
|
+
const warnings = [...preMigrationWarnings];
|
|
163624
163748
|
for (const key of errorPaths) {
|
|
163625
163749
|
recoveredTopLevelKeys.push(key);
|
|
163626
163750
|
const isAgentConfig = key === "historian" || key === "dreamer" || key === "sidekick";
|