@cortexkit/magic-context 0.22.5 → 0.23.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/index.js +129 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -145068,6 +145068,11 @@ function markSessionCompleted(db, sessionId, now) {
|
|
|
145068
145068
|
SET status = 'completed', completed_at = ?, lease_expires_at = NULL, last_error = NULL
|
|
145069
145069
|
WHERE session_id = ?`).run(now, sessionId);
|
|
145070
145070
|
}
|
|
145071
|
+
function markSessionPendingRetry(db, sessionId) {
|
|
145072
|
+
db.prepare(`UPDATE tool_owner_backfill_state
|
|
145073
|
+
SET status = 'pending', completed_at = NULL, lease_expires_at = NULL, last_error = NULL
|
|
145074
|
+
WHERE session_id = ?`).run(sessionId);
|
|
145075
|
+
}
|
|
145071
145076
|
function markSessionSkipped(db, sessionId, now, reason) {
|
|
145072
145077
|
db.prepare(`INSERT INTO tool_owner_backfill_state(session_id, status, completed_at, last_error)
|
|
145073
145078
|
VALUES (?, 'skipped', ?, ?)
|
|
@@ -145144,12 +145149,18 @@ function applyOwnersForSession(db, sessionId, ownersByCallId) {
|
|
|
145144
145149
|
const updateRowStmt = db.prepare(`UPDATE tags
|
|
145145
145150
|
SET tool_owner_message_id = ?
|
|
145146
145151
|
WHERE id = ? AND tool_owner_message_id IS NULL`);
|
|
145152
|
+
const existingOwnerStmt = db.prepare(`SELECT 1 AS hit FROM tags
|
|
145153
|
+
WHERE session_id = ? AND message_id = ? AND type = 'tool'
|
|
145154
|
+
AND tool_owner_message_id = ?
|
|
145155
|
+
LIMIT 1`);
|
|
145147
145156
|
let rowsUpdated = 0;
|
|
145148
145157
|
db.transaction(() => {
|
|
145149
145158
|
for (const [callId, ownerId] of ownersByCallId) {
|
|
145150
145159
|
const orphan = findOrphanStmt.get(sessionId, callId);
|
|
145151
145160
|
if (!orphan)
|
|
145152
145161
|
continue;
|
|
145162
|
+
if (existingOwnerStmt.get(sessionId, callId, ownerId))
|
|
145163
|
+
continue;
|
|
145153
145164
|
const result = updateRowStmt.run(ownerId, orphan.id);
|
|
145154
145165
|
rowsUpdated += result.changes ?? 0;
|
|
145155
145166
|
}
|
|
@@ -145178,6 +145189,8 @@ function backfillToolOwnersInChunks(db, result) {
|
|
|
145178
145189
|
if (owners.size === 0) {
|
|
145179
145190
|
markSessionSkipped(db, sessionId, Date.now(), "no_oc_matches");
|
|
145180
145191
|
result.sessionsSkippedNoMatches += 1;
|
|
145192
|
+
} else if (rowsLeftNull > 0) {
|
|
145193
|
+
markSessionPendingRetry(db, sessionId);
|
|
145181
145194
|
} else {
|
|
145182
145195
|
markSessionCompleted(db, sessionId, Date.now());
|
|
145183
145196
|
result.sessionsCompleted += 1;
|
|
@@ -145293,9 +145306,9 @@ function applySqliteTuningPragmas(db) {
|
|
|
145293
145306
|
db.exec("PRAGMA analysis_limit=400");
|
|
145294
145307
|
}
|
|
145295
145308
|
function initializeDatabase(db) {
|
|
145309
|
+
db.exec("PRAGMA busy_timeout=5000");
|
|
145296
145310
|
db.exec("PRAGMA foreign_keys=ON");
|
|
145297
145311
|
db.exec("PRAGMA journal_mode=WAL");
|
|
145298
|
-
db.exec("PRAGMA busy_timeout=5000");
|
|
145299
145312
|
applySqliteTuningPragmas(db);
|
|
145300
145313
|
db.exec(`
|
|
145301
145314
|
CREATE TABLE IF NOT EXISTS tags (
|
|
@@ -145308,6 +145321,9 @@ function initializeDatabase(db) {
|
|
|
145308
145321
|
tag_number INTEGER,
|
|
145309
145322
|
harness TEXT NOT NULL DEFAULT 'opencode',
|
|
145310
145323
|
entry_fingerprint TEXT,
|
|
145324
|
+
token_count INTEGER,
|
|
145325
|
+
input_token_count INTEGER,
|
|
145326
|
+
reasoning_token_count INTEGER,
|
|
145311
145327
|
UNIQUE(session_id, tag_number)
|
|
145312
145328
|
);
|
|
145313
145329
|
|
|
@@ -145597,6 +145613,11 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
145597
145613
|
counter INTEGER DEFAULT 0,
|
|
145598
145614
|
last_nudge_tokens INTEGER DEFAULT 0,
|
|
145599
145615
|
last_nudge_band TEXT DEFAULT '',
|
|
145616
|
+
last_nudge_undropped INTEGER DEFAULT 0,
|
|
145617
|
+
last_nudge_level TEXT DEFAULT '',
|
|
145618
|
+
channel2_nudge_state TEXT DEFAULT '',
|
|
145619
|
+
channel2_nudge_claimed_at INTEGER DEFAULT 0,
|
|
145620
|
+
last_emergency_input_sample INTEGER DEFAULT 0,
|
|
145600
145621
|
last_transform_error TEXT DEFAULT '',
|
|
145601
145622
|
nudge_anchor_message_id TEXT DEFAULT '',
|
|
145602
145623
|
nudge_anchor_text TEXT DEFAULT '',
|
|
@@ -145653,6 +145674,14 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
145653
145674
|
cached_m0_project_docs_hash TEXT,
|
|
145654
145675
|
cached_m1_bytes BLOB,
|
|
145655
145676
|
last_observed_model_key TEXT,
|
|
145677
|
+
last_usage_context_limit INTEGER NOT NULL DEFAULT 0,
|
|
145678
|
+
prior_boundary_ordinal INTEGER NOT NULL DEFAULT 1,
|
|
145679
|
+
protected_tail_policy_version INTEGER NOT NULL DEFAULT 0,
|
|
145680
|
+
protected_tail_drain_window_started_at INTEGER NOT NULL DEFAULT 0,
|
|
145681
|
+
protected_tail_drain_tokens INTEGER NOT NULL DEFAULT 0,
|
|
145682
|
+
recovery_no_eligible_head_count INTEGER NOT NULL DEFAULT 0,
|
|
145683
|
+
force_emergency_bypass_window_start INTEGER NOT NULL DEFAULT 0,
|
|
145684
|
+
force_emergency_bypass_used INTEGER NOT NULL DEFAULT 0,
|
|
145656
145685
|
cached_m0_materialized_at INTEGER,
|
|
145657
145686
|
cached_m0_session_facts_version INTEGER,
|
|
145658
145687
|
cached_m0_upgrade_state TEXT,
|
|
@@ -145763,6 +145792,11 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
145763
145792
|
CREATE INDEX IF NOT EXISTS idx_message_history_index_updated_at ON message_history_index(updated_at);
|
|
145764
145793
|
`);
|
|
145765
145794
|
ensureColumn(db, "session_meta", "last_nudge_band", "TEXT DEFAULT ''");
|
|
145795
|
+
ensureColumn(db, "session_meta", "last_nudge_undropped", "INTEGER DEFAULT 0");
|
|
145796
|
+
ensureColumn(db, "session_meta", "last_nudge_level", "TEXT DEFAULT ''");
|
|
145797
|
+
ensureColumn(db, "session_meta", "channel2_nudge_state", "TEXT DEFAULT ''");
|
|
145798
|
+
ensureColumn(db, "session_meta", "channel2_nudge_claimed_at", "INTEGER DEFAULT 0");
|
|
145799
|
+
ensureColumn(db, "session_meta", "last_emergency_input_sample", "INTEGER DEFAULT 0");
|
|
145766
145800
|
ensureColumn(db, "session_meta", "last_transform_error", "TEXT DEFAULT ''");
|
|
145767
145801
|
ensureColumn(db, "session_meta", "nudge_anchor_message_id", "TEXT DEFAULT ''");
|
|
145768
145802
|
ensureColumn(db, "session_meta", "nudge_anchor_text", "TEXT DEFAULT ''");
|
|
@@ -145808,6 +145842,9 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
145808
145842
|
db.exec(`CREATE INDEX IF NOT EXISTS idx_tags_pi_adopt
|
|
145809
145843
|
ON tags(session_id, entry_fingerprint)
|
|
145810
145844
|
WHERE type='message' AND entry_fingerprint IS NOT NULL`);
|
|
145845
|
+
ensureColumn(db, "tags", "token_count", "INTEGER");
|
|
145846
|
+
ensureColumn(db, "tags", "input_token_count", "INTEGER");
|
|
145847
|
+
ensureColumn(db, "tags", "reasoning_token_count", "INTEGER");
|
|
145811
145848
|
ensureColumn(db, "session_meta", "system_prompt_tokens", "INTEGER DEFAULT 0");
|
|
145812
145849
|
ensureColumn(db, "session_meta", "compaction_marker_state", "TEXT DEFAULT ''");
|
|
145813
145850
|
ensureColumn(db, "session_meta", "key_files", "TEXT DEFAULT ''");
|
|
@@ -145848,6 +145885,14 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
145848
145885
|
ensureColumn(db, "session_meta", "cached_m0_project_docs_hash", "TEXT");
|
|
145849
145886
|
ensureColumn(db, "session_meta", "cached_m1_bytes", "BLOB");
|
|
145850
145887
|
ensureColumn(db, "session_meta", "last_observed_model_key", "TEXT");
|
|
145888
|
+
ensureColumn(db, "session_meta", "last_usage_context_limit", "INTEGER NOT NULL DEFAULT 0");
|
|
145889
|
+
ensureColumn(db, "session_meta", "prior_boundary_ordinal", "INTEGER NOT NULL DEFAULT 1");
|
|
145890
|
+
ensureColumn(db, "session_meta", "protected_tail_policy_version", "INTEGER NOT NULL DEFAULT 0");
|
|
145891
|
+
ensureColumn(db, "session_meta", "protected_tail_drain_window_started_at", "INTEGER NOT NULL DEFAULT 0");
|
|
145892
|
+
ensureColumn(db, "session_meta", "protected_tail_drain_tokens", "INTEGER NOT NULL DEFAULT 0");
|
|
145893
|
+
ensureColumn(db, "session_meta", "recovery_no_eligible_head_count", "INTEGER NOT NULL DEFAULT 0");
|
|
145894
|
+
ensureColumn(db, "session_meta", "force_emergency_bypass_window_start", "INTEGER NOT NULL DEFAULT 0");
|
|
145895
|
+
ensureColumn(db, "session_meta", "force_emergency_bypass_used", "INTEGER NOT NULL DEFAULT 0");
|
|
145851
145896
|
ensureColumn(db, "session_meta", "cached_m0_materialized_at", "INTEGER");
|
|
145852
145897
|
ensureColumn(db, "session_meta", "cached_m0_session_facts_version", "INTEGER");
|
|
145853
145898
|
ensureColumn(db, "session_meta", "cached_m0_upgrade_state", "TEXT");
|
|
@@ -145917,6 +145962,12 @@ function healAllNullColumns(db) {
|
|
|
145917
145962
|
healNullIntegerColumns(db);
|
|
145918
145963
|
healMissingMemoryBlockIds(db);
|
|
145919
145964
|
}
|
|
145965
|
+
function healWedgedChannel2Claims(db) {
|
|
145966
|
+
try {
|
|
145967
|
+
const staleBefore = Date.now() - CHANNEL2_CLAIM_TTL_MS;
|
|
145968
|
+
db.prepare("UPDATE session_meta SET channel2_nudge_state = 'pending', channel2_nudge_claimed_at = 0 WHERE channel2_nudge_state = 'claimed' AND (channel2_nudge_claimed_at IS NULL OR channel2_nudge_claimed_at = 0 OR channel2_nudge_claimed_at <= ?)").run(staleBefore);
|
|
145969
|
+
} catch {}
|
|
145970
|
+
}
|
|
145920
145971
|
function healMissingMemoryBlockIds(db) {
|
|
145921
145972
|
try {
|
|
145922
145973
|
db.prepare("UPDATE session_meta SET memory_block_cache = '' WHERE memory_block_cache != '' AND (memory_block_ids IS NULL OR memory_block_ids = '') AND memory_block_count > 0").run();
|
|
@@ -145926,6 +145977,7 @@ function healNullTextColumns(db) {
|
|
|
145926
145977
|
const columns = [
|
|
145927
145978
|
["cache_ttl", ""],
|
|
145928
145979
|
["last_nudge_band", ""],
|
|
145980
|
+
["last_nudge_level", ""],
|
|
145929
145981
|
["last_transform_error", ""],
|
|
145930
145982
|
["nudge_anchor_message_id", ""],
|
|
145931
145983
|
["nudge_anchor_text", ""],
|
|
@@ -145966,7 +146018,17 @@ function healNullIntegerColumns(db) {
|
|
|
145966
146018
|
["observed_safe_input_tokens", 0],
|
|
145967
146019
|
["cache_alert_sent", 0],
|
|
145968
146020
|
["new_work_tokens", 0],
|
|
145969
|
-
["total_input_tokens", 0]
|
|
146021
|
+
["total_input_tokens", 0],
|
|
146022
|
+
["last_emergency_input_sample", 0],
|
|
146023
|
+
["channel2_nudge_claimed_at", 0],
|
|
146024
|
+
["last_usage_context_limit", 0],
|
|
146025
|
+
["prior_boundary_ordinal", 1],
|
|
146026
|
+
["protected_tail_policy_version", 0],
|
|
146027
|
+
["protected_tail_drain_window_started_at", 0],
|
|
146028
|
+
["protected_tail_drain_tokens", 0],
|
|
146029
|
+
["recovery_no_eligible_head_count", 0],
|
|
146030
|
+
["force_emergency_bypass_window_start", 0],
|
|
146031
|
+
["force_emergency_bypass_used", 0]
|
|
145970
146032
|
];
|
|
145971
146033
|
for (const [column, fallback] of columns) {
|
|
145972
146034
|
try {
|
|
@@ -146005,6 +146067,7 @@ function openDatabase(dbPathOrOptions) {
|
|
|
146005
146067
|
if (!persistenceByDatabase.has(existing)) {
|
|
146006
146068
|
persistenceByDatabase.set(existing, true);
|
|
146007
146069
|
}
|
|
146070
|
+
healWedgedChannel2Claims(existing);
|
|
146008
146071
|
return existing;
|
|
146009
146072
|
}
|
|
146010
146073
|
try {
|
|
@@ -146030,6 +146093,7 @@ function openDatabase(dbPathOrOptions) {
|
|
|
146030
146093
|
log2(`[magic-context] key-files orphan GC failed: ${getErrorMessage(error)}`);
|
|
146031
146094
|
}
|
|
146032
146095
|
}
|
|
146096
|
+
healWedgedChannel2Claims(db);
|
|
146033
146097
|
if (!explicitDbPath) {
|
|
146034
146098
|
try {
|
|
146035
146099
|
runToolOwnerBackfill(db);
|
|
@@ -146065,7 +146129,7 @@ function closeDatabase() {
|
|
|
146065
146129
|
}
|
|
146066
146130
|
}
|
|
146067
146131
|
}
|
|
146068
|
-
var databases, persistenceByDatabase, persistenceErrorByDatabase, lastSchemaFenceRejection = null, LATEST_SUPPORTED_VERSION =
|
|
146132
|
+
var databases, persistenceByDatabase, persistenceErrorByDatabase, lastSchemaFenceRejection = null, LATEST_SUPPORTED_VERSION = 32, sqlitePragmaConfig, CHANNEL2_CLAIM_TTL_MS = 120000;
|
|
146069
146133
|
var init_storage_db = __esm(async () => {
|
|
146070
146134
|
init_data_path();
|
|
146071
146135
|
init_logger();
|
|
@@ -146910,6 +146974,50 @@ var init_migrations = __esm(async () => {
|
|
|
146910
146974
|
cached_m0_model_key = NULL`).run();
|
|
146911
146975
|
}
|
|
146912
146976
|
}
|
|
146977
|
+
},
|
|
146978
|
+
{
|
|
146979
|
+
version: 31,
|
|
146980
|
+
description: "Nudge redesign: Channel 1 cadence (last_nudge_undropped) + Channel 2 ceiling lease " + "(channel2_nudge_state); zero legacy ctx_reduce-nudge sticky/anchor state (startup heal)",
|
|
146981
|
+
up: (db) => {
|
|
146982
|
+
const hasSessionMeta = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='session_meta' LIMIT 1").get();
|
|
146983
|
+
if (!hasSessionMeta)
|
|
146984
|
+
return;
|
|
146985
|
+
ensureColumn(db, "session_meta", "last_nudge_undropped", "INTEGER DEFAULT 0");
|
|
146986
|
+
ensureColumn(db, "session_meta", "channel2_nudge_state", "TEXT DEFAULT ''");
|
|
146987
|
+
const columns = new Set(db.prepare("PRAGMA table_info(session_meta)").all().map((column) => column.name));
|
|
146988
|
+
if (columns.has("sticky_turn_reminder_text")) {
|
|
146989
|
+
db.prepare(`UPDATE session_meta SET
|
|
146990
|
+
sticky_turn_reminder_text = '',
|
|
146991
|
+
sticky_turn_reminder_message_id = '',
|
|
146992
|
+
nudge_anchor_message_id = '',
|
|
146993
|
+
nudge_anchor_text = ''`).run();
|
|
146994
|
+
}
|
|
146995
|
+
}
|
|
146996
|
+
},
|
|
146997
|
+
{
|
|
146998
|
+
version: 32,
|
|
146999
|
+
description: "Protected tail boundary state, usage resolver fields, recovery escape, and drain quota",
|
|
147000
|
+
up: (db) => {
|
|
147001
|
+
const hasSessionMeta = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='session_meta' LIMIT 1").get();
|
|
147002
|
+
if (!hasSessionMeta)
|
|
147003
|
+
return;
|
|
147004
|
+
ensureColumn(db, "session_meta", "prior_boundary_ordinal", "INTEGER NOT NULL DEFAULT 1");
|
|
147005
|
+
ensureColumn(db, "session_meta", "protected_tail_policy_version", "INTEGER NOT NULL DEFAULT 0");
|
|
147006
|
+
ensureColumn(db, "session_meta", "protected_tail_drain_window_started_at", "INTEGER NOT NULL DEFAULT 0");
|
|
147007
|
+
ensureColumn(db, "session_meta", "protected_tail_drain_tokens", "INTEGER NOT NULL DEFAULT 0");
|
|
147008
|
+
ensureColumn(db, "session_meta", "recovery_no_eligible_head_count", "INTEGER NOT NULL DEFAULT 0");
|
|
147009
|
+
ensureColumn(db, "session_meta", "force_emergency_bypass_window_start", "INTEGER NOT NULL DEFAULT 0");
|
|
147010
|
+
ensureColumn(db, "session_meta", "force_emergency_bypass_used", "INTEGER NOT NULL DEFAULT 0");
|
|
147011
|
+
ensureColumn(db, "session_meta", "last_usage_context_limit", "INTEGER NOT NULL DEFAULT 0");
|
|
147012
|
+
db.prepare("UPDATE session_meta SET prior_boundary_ordinal = 1 WHERE prior_boundary_ordinal IS NULL OR prior_boundary_ordinal < 1").run();
|
|
147013
|
+
db.prepare("UPDATE session_meta SET protected_tail_policy_version = 0 WHERE protected_tail_policy_version IS NULL").run();
|
|
147014
|
+
db.prepare("UPDATE session_meta SET protected_tail_drain_window_started_at = 0 WHERE protected_tail_drain_window_started_at IS NULL").run();
|
|
147015
|
+
db.prepare("UPDATE session_meta SET protected_tail_drain_tokens = 0 WHERE protected_tail_drain_tokens IS NULL").run();
|
|
147016
|
+
db.prepare("UPDATE session_meta SET recovery_no_eligible_head_count = 0 WHERE recovery_no_eligible_head_count IS NULL").run();
|
|
147017
|
+
db.prepare("UPDATE session_meta SET force_emergency_bypass_window_start = 0 WHERE force_emergency_bypass_window_start IS NULL").run();
|
|
147018
|
+
db.prepare("UPDATE session_meta SET force_emergency_bypass_used = 0 WHERE force_emergency_bypass_used IS NULL").run();
|
|
147019
|
+
db.prepare("UPDATE session_meta SET last_usage_context_limit = 0 WHERE last_usage_context_limit IS NULL").run();
|
|
147020
|
+
}
|
|
146913
147021
|
}
|
|
146914
147022
|
];
|
|
146915
147023
|
LATEST_MIGRATION_VERSION = MIGRATIONS.reduce((max, m) => Math.max(max, m.version), 0);
|
|
@@ -147112,7 +147220,7 @@ var init_storage_memory_mutation_log = __esm(() => {
|
|
|
147112
147220
|
});
|
|
147113
147221
|
|
|
147114
147222
|
// ../plugin/src/features/magic-context/storage-meta-persisted.ts
|
|
147115
|
-
var AUTO_SEARCH_NO_HINT_REASONS;
|
|
147223
|
+
var AUTO_SEARCH_NO_HINT_REASONS, DRAIN_WINDOW_MS;
|
|
147116
147224
|
var init_storage_meta_persisted = __esm(() => {
|
|
147117
147225
|
init_logger();
|
|
147118
147226
|
init_storage_meta_shared();
|
|
@@ -147124,6 +147232,7 @@ var init_storage_meta_persisted = __esm(() => {
|
|
|
147124
147232
|
"stacked",
|
|
147125
147233
|
"too-short"
|
|
147126
147234
|
]);
|
|
147235
|
+
DRAIN_WINDOW_MS = 10 * 60 * 1000;
|
|
147127
147236
|
});
|
|
147128
147237
|
|
|
147129
147238
|
// ../plugin/src/features/magic-context/resolve-subagent-fallback.ts
|
|
@@ -147170,7 +147279,7 @@ var init_storage_ops = __esm(() => {
|
|
|
147170
147279
|
// ../plugin/src/features/magic-context/storage-source.ts
|
|
147171
147280
|
var init_storage_source = () => {};
|
|
147172
147281
|
// ../plugin/src/features/magic-context/storage-tags.ts
|
|
147173
|
-
var insertTagStatements, updateTagStatusStatements, updateTagDropModeStatements, updateTagMessageIdStatements, getTagNumbersByMessageIdStatements, deleteTagsByMessageIdStatements, getMaxTagNumberBySessionStatements, getTagNumberByMessageIdStatements, updateTagByteSizeStatements, updateTagInputByteSizeStatements, getOwnerScopedToolTagNumbersStatements, getActiveTagsBySessionStatements, getMaxDroppedTagNumberStatements, getToolTagNumberByOwnerStatements, getNullOwnerToolTagStatements, adoptNullOwnerToolTagStatements, deleteToolTagsByOwnerStatements;
|
|
147282
|
+
var insertTagStatements, updateTagStatusStatements, updateTagDropModeStatements, updateTagMessageIdStatements, getTagNumbersByMessageIdStatements, deleteTagsByMessageIdStatements, getMaxTagNumberBySessionStatements, getTagNumberByMessageIdStatements, updateTagByteSizeStatements, updateTagInputByteSizeStatements, updateTagTokenCountStatements, updateTagInputTokenCountStatements, getOwnerScopedToolTagNumbersStatements, getActiveTagsBySessionStatements, getMaxDroppedTagNumberStatements, getToolTagNumberByOwnerStatements, getNullOwnerToolTagStatements, adoptNullOwnerToolTagStatements, deleteToolTagsByOwnerStatements;
|
|
147174
147283
|
var init_storage_tags = __esm(() => {
|
|
147175
147284
|
insertTagStatements = new WeakMap;
|
|
147176
147285
|
updateTagStatusStatements = new WeakMap;
|
|
@@ -147182,6 +147291,8 @@ var init_storage_tags = __esm(() => {
|
|
|
147182
147291
|
getTagNumberByMessageIdStatements = new WeakMap;
|
|
147183
147292
|
updateTagByteSizeStatements = new WeakMap;
|
|
147184
147293
|
updateTagInputByteSizeStatements = new WeakMap;
|
|
147294
|
+
updateTagTokenCountStatements = new WeakMap;
|
|
147295
|
+
updateTagInputTokenCountStatements = new WeakMap;
|
|
147185
147296
|
getOwnerScopedToolTagNumbersStatements = new WeakMap;
|
|
147186
147297
|
getActiveTagsBySessionStatements = new WeakMap;
|
|
147187
147298
|
getMaxDroppedTagNumberStatements = new WeakMap;
|
|
@@ -147608,6 +147719,10 @@ function stripUnsafeProjectConfigFields(projectRaw) {
|
|
|
147608
147719
|
delete projectRaw.auto_update;
|
|
147609
147720
|
warnings.push("Ignoring auto_update from project config (security: this setting only honors user-level config).");
|
|
147610
147721
|
}
|
|
147722
|
+
if ("sqlite" in projectRaw) {
|
|
147723
|
+
delete projectRaw.sqlite;
|
|
147724
|
+
warnings.push("Ignoring sqlite.* from project config (security: SQLite cache/mmap PRAGMAs apply to the " + "process-global shared database handle; only user-level config may set them).");
|
|
147725
|
+
}
|
|
147611
147726
|
for (const agentKey of HIDDEN_AGENT_KEYS) {
|
|
147612
147727
|
const block = projectRaw[agentKey];
|
|
147613
147728
|
if (!isPlainObject(block))
|
|
@@ -162349,7 +162464,7 @@ var init_agent_overrides = __esm(() => {
|
|
|
162349
162464
|
});
|
|
162350
162465
|
|
|
162351
162466
|
// ../plugin/src/config/schema/magic-context.ts
|
|
162352
|
-
var
|
|
162467
|
+
var DEFAULT_EXECUTE_THRESHOLD_PERCENTAGE = 65, EXECUTE_THRESHOLD_CAP_MESSAGE = "execute_threshold is capped at 80% for cache safety: a single large agent step can overflow the context window before Magic Context can compact between turns, forcing OpenCode's native compaction (hard to recover from). 80% also leaves headroom below the 85%/95% emergency bands. Use a value between 20 and 80.", DEFAULT_HISTORIAN_TIMEOUT_MS = 300000, DEFAULT_HISTORY_BUDGET_PERCENTAGE = 0.15, DEFAULT_LOCAL_EMBEDDING_MODEL = "Xenova/all-MiniLM-L6-v2", DREAMER_TASKS, DreamingTaskSchema, DEFAULT_DREAMER_TASKS, PiThinkingLevelSchema, DreamerConfigSchema, SidekickConfigSchema, HistorianConfigSchema, BaseEmbeddingConfigSchema, EmbeddingConfigSchema, MagicContextConfigSchema;
|
|
162353
162468
|
var init_magic_context = __esm(() => {
|
|
162354
162469
|
init_zod();
|
|
162355
162470
|
init_agent_overrides();
|
|
@@ -162446,7 +162561,6 @@ var init_magic_context = __esm(() => {
|
|
|
162446
162561
|
historian: HistorianConfigSchema.describe("Historian agent configuration (model, fallback_models, variant, temperature, maxTokens, permission, two_pass, etc.)"),
|
|
162447
162562
|
dreamer: DreamerConfigSchema.optional().describe("Dreamer agent + scheduling configuration (model, fallback_models, disable, schedule, tasks, etc.)"),
|
|
162448
162563
|
cache_ttl: exports_external.union([exports_external.string(), exports_external.object({ default: exports_external.string() }).catchall(exports_external.string())]).default("5m").describe('Cache TTL: string (e.g. "5m") or per-model object ({ default: "5m", "model-id": "10m" })'),
|
|
162449
|
-
nudge_interval_tokens: exports_external.number().min(1000).default(DEFAULT_NUDGE_INTERVAL_TOKENS).describe("Minimum token growth between low-priority rolling nudges (default: DEFAULT_NUDGE_INTERVAL_TOKENS)"),
|
|
162450
162564
|
execute_threshold_percentage: exports_external.union([
|
|
162451
162565
|
exports_external.number().min(20).max(80, EXECUTE_THRESHOLD_CAP_MESSAGE),
|
|
162452
162566
|
exports_external.object({ default: exports_external.number().min(20).max(80, EXECUTE_THRESHOLD_CAP_MESSAGE) }).catchall(exports_external.number().min(20).max(80, EXECUTE_THRESHOLD_CAP_MESSAGE))
|
|
@@ -162455,10 +162569,7 @@ var init_magic_context = __esm(() => {
|
|
|
162455
162569
|
default: exports_external.number().min(5000).max(2000000).optional()
|
|
162456
162570
|
}).catchall(exports_external.number().min(5000).max(2000000)).optional().describe("Absolute token thresholds per model. When matched, overrides execute_threshold_percentage for that model. Accepts `default` for all models or per-model keys. Values above 80% × context_limit are clamped with a warning log. Min 5_000, max 2_000_000."),
|
|
162457
162571
|
protected_tags: exports_external.number().min(1).max(100).optional().describe("Number of recent tags to protect from dropping (min: 1, max: 100, default: 20)"),
|
|
162458
|
-
auto_drop_tool_age: exports_external.number().min(10).default(100).describe("Auto-drop tool outputs older than N tags during queue execution (default: 100)"),
|
|
162459
|
-
drop_tool_structure: exports_external.boolean().default(true).describe("When true, dropped tool parts are fully removed instead of truncated in place (default: true)"),
|
|
162460
162572
|
clear_reasoning_age: exports_external.number().min(10).default(50).describe("Clear reasoning/thinking blocks older than N tags (default: 50)"),
|
|
162461
|
-
iteration_nudge_threshold: exports_external.number().min(5).default(15).describe("Number of consecutive assistant messages without user input to trigger iteration nudge (default: 15)"),
|
|
162462
162573
|
history_budget_percentage: exports_external.number().min(0.05).max(0.5).default(DEFAULT_HISTORY_BUDGET_PERCENTAGE).describe("Fraction of usable context (context_limit × execute_threshold) reserved for the session history block (default: 0.15)"),
|
|
162463
162574
|
historian_timeout_ms: exports_external.number().min(60000).default(DEFAULT_HISTORIAN_TIMEOUT_MS).describe("Timeout for each historian prompt call in milliseconds (default: 300000)"),
|
|
162464
162575
|
commit_cluster_trigger: exports_external.object({
|
|
@@ -164473,6 +164584,14 @@ async function runDoctor(options = {}) {
|
|
|
164473
164584
|
log.success("Removed deprecated compaction_markers (always-on since v0.21.4)");
|
|
164474
164585
|
fixed++;
|
|
164475
164586
|
}
|
|
164587
|
+
for (const deadKey of ["auto_drop_tool_age", "drop_tool_structure"]) {
|
|
164588
|
+
if (deadKey in mcConfig) {
|
|
164589
|
+
delete mcConfig[deadKey];
|
|
164590
|
+
mcChanged = true;
|
|
164591
|
+
log.success(`Removed deprecated ${deadKey} (replaced by tiered emergency drop)`);
|
|
164592
|
+
fixed++;
|
|
164593
|
+
}
|
|
164594
|
+
}
|
|
164476
164595
|
const agentEnabledMigration = migrateLegacyAgentEnabledConfigForDoctor(mcConfig, log);
|
|
164477
164596
|
if (agentEnabledMigration.changed) {
|
|
164478
164597
|
mcChanged = true;
|