@cortexkit/magic-context 0.33.0 → 0.33.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 +294 -217
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11535,6 +11535,7 @@ function getOpenCodeConfigPaths(options) {
|
|
|
11535
11535
|
var init_opencode_config_dir = () => {};
|
|
11536
11536
|
|
|
11537
11537
|
// ../plugin/src/shared/conflict-detector.ts
|
|
11538
|
+
import { homedir as homedir7 } from "node:os";
|
|
11538
11539
|
import { join as join9 } from "node:path";
|
|
11539
11540
|
function detectConflicts(directory) {
|
|
11540
11541
|
const conflicts = {
|
|
@@ -11717,6 +11718,24 @@ function readOmoDisabledHooks(directory) {
|
|
|
11717
11718
|
}
|
|
11718
11719
|
}
|
|
11719
11720
|
}
|
|
11721
|
+
const homeDir2 = process.env.HOME || homedir7();
|
|
11722
|
+
const omoHomeDir = join9(homeDir2, ".omo");
|
|
11723
|
+
for (const name of ["omo.jsonc", "omo.json"]) {
|
|
11724
|
+
const config = readJsoncFile(join9(omoHomeDir, name));
|
|
11725
|
+
if (config?.["[opencode]"]?.disabled_hooks) {
|
|
11726
|
+
for (const hook of config["[opencode]"].disabled_hooks) {
|
|
11727
|
+
disabled.add(hook);
|
|
11728
|
+
}
|
|
11729
|
+
}
|
|
11730
|
+
}
|
|
11731
|
+
for (const name of ["omo.jsonc", "omo.json"]) {
|
|
11732
|
+
const config = readJsoncFile(join9(directory, ".omo", name));
|
|
11733
|
+
if (config?.["[opencode]"]?.disabled_hooks) {
|
|
11734
|
+
for (const hook of config["[opencode]"].disabled_hooks) {
|
|
11735
|
+
disabled.add(hook);
|
|
11736
|
+
}
|
|
11737
|
+
}
|
|
11738
|
+
}
|
|
11720
11739
|
return disabled;
|
|
11721
11740
|
}
|
|
11722
11741
|
var DCP_PACKAGE_NAMES, OMO_PACKAGE_NAMES;
|
|
@@ -12014,7 +12033,7 @@ var init_cron = __esm(() => {
|
|
|
12014
12033
|
});
|
|
12015
12034
|
|
|
12016
12035
|
// ../plugin/src/features/magic-context/dreamer/task-registry.ts
|
|
12017
|
-
var CANONICAL_DREAM_TASKS,
|
|
12036
|
+
var CANONICAL_DREAM_TASKS, MEMORY_DOMAIN_TASKS, MEMORY_DOMAIN_SET;
|
|
12018
12037
|
var init_task_registry = __esm(() => {
|
|
12019
12038
|
CANONICAL_DREAM_TASKS = [
|
|
12020
12039
|
"map-memories",
|
|
@@ -12030,7 +12049,6 @@ var init_task_registry = __esm(() => {
|
|
|
12030
12049
|
"promote-primers",
|
|
12031
12050
|
"refresh-primers"
|
|
12032
12051
|
];
|
|
12033
|
-
AGENTIC_DREAM_TASKS = ["curate", "maintain-docs"];
|
|
12034
12052
|
MEMORY_DOMAIN_TASKS = [
|
|
12035
12053
|
"map-memories",
|
|
12036
12054
|
"verify",
|
|
@@ -12190,11 +12208,31 @@ var init_dreamer_setup = __esm(() => {
|
|
|
12190
12208
|
|
|
12191
12209
|
// src/lib/opencode-helpers.ts
|
|
12192
12210
|
import { execFileSync as execFileSync2, execSync } from "node:child_process";
|
|
12211
|
+
import { extname as extname2 } from "node:path";
|
|
12212
|
+
function getOpenCodeCommandInvocation(binary, args) {
|
|
12213
|
+
const extension = extname2(binary).toLowerCase();
|
|
12214
|
+
if (extension !== ".cmd" && extension !== ".bat") {
|
|
12215
|
+
return { command: binary, args };
|
|
12216
|
+
}
|
|
12217
|
+
const command = process.env.ComSpec?.trim() || process.env.COMSPEC?.trim() || "cmd.exe";
|
|
12218
|
+
const commandLine = [`%${OPENCODE_BINARY_ENV}%`, ...args].map((part) => `"${part}"`).join(" ");
|
|
12219
|
+
return {
|
|
12220
|
+
command,
|
|
12221
|
+
args: ["/d", "/s", "/v:off", "/c", `"${commandLine}"`],
|
|
12222
|
+
env: { [OPENCODE_BINARY_ENV]: binary },
|
|
12223
|
+
windowsVerbatimArguments: true
|
|
12224
|
+
};
|
|
12225
|
+
}
|
|
12193
12226
|
function runOpenCode(args, binary, timeoutMs) {
|
|
12194
12227
|
try {
|
|
12195
12228
|
const options = { stdio: "pipe", ...timeoutMs ? { timeout: timeoutMs } : {} };
|
|
12196
12229
|
if (binary) {
|
|
12197
|
-
|
|
12230
|
+
const invocation = getOpenCodeCommandInvocation(binary, args);
|
|
12231
|
+
return execFileSync2(invocation.command, invocation.args, {
|
|
12232
|
+
...options,
|
|
12233
|
+
...invocation.env ? { env: { ...process.env, ...invocation.env } } : {},
|
|
12234
|
+
...invocation.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}
|
|
12235
|
+
}).toString().trim();
|
|
12198
12236
|
}
|
|
12199
12237
|
return execSync(`opencode ${args.join(" ")}`, options).toString().trim();
|
|
12200
12238
|
} catch {
|
|
@@ -12218,7 +12256,7 @@ function getAvailableModels2(binary) {
|
|
|
12218
12256
|
return output.split(`
|
|
12219
12257
|
`).map((l2) => l2.trim()).filter(Boolean);
|
|
12220
12258
|
}
|
|
12221
|
-
var OPENCODE_VERSION_PROBE_TIMEOUT_MS = 2000;
|
|
12259
|
+
var OPENCODE_BINARY_ENV = "MAGIC_CONTEXT_OPENCODE_BINARY", OPENCODE_VERSION_PROBE_TIMEOUT_MS = 2000;
|
|
12222
12260
|
var init_opencode_helpers = () => {};
|
|
12223
12261
|
|
|
12224
12262
|
// src/commands/setup-opencode.ts
|
|
@@ -13032,28 +13070,11 @@ function buildNodeSqliteDatabaseClass(DatabaseSync) {
|
|
|
13032
13070
|
}
|
|
13033
13071
|
return NodeSqliteDatabase;
|
|
13034
13072
|
}
|
|
13035
|
-
function registerPrivilegedWriter(db) {
|
|
13036
|
-
if (registeredPrivilegeFunctions.has(db))
|
|
13037
|
-
return;
|
|
13038
|
-
const native = db;
|
|
13039
|
-
const implementation = () => (privilegeDepth.get(db) ?? 0) > 0 ? 1 : 0;
|
|
13040
|
-
if (typeof native.function === "function") {
|
|
13041
|
-
native.function("mc_privileged_writer", implementation);
|
|
13042
|
-
} else if (typeof native.createFunction === "function") {
|
|
13043
|
-
native.createFunction("mc_privileged_writer", implementation);
|
|
13044
|
-
} else {
|
|
13045
|
-
registeredPrivilegeFunctions.add(db);
|
|
13046
|
-
return;
|
|
13047
|
-
}
|
|
13048
|
-
privilegeUdfAvailable.add(db);
|
|
13049
|
-
registeredPrivilegeFunctions.add(db);
|
|
13050
|
-
}
|
|
13051
13073
|
function isInTransaction(db) {
|
|
13052
13074
|
const candidate = db;
|
|
13053
13075
|
return candidate.inTransaction === true || candidate.isTransaction === true;
|
|
13054
13076
|
}
|
|
13055
13077
|
function withPrivilegedWriter(db, operation) {
|
|
13056
|
-
registerPrivilegedWriter(db);
|
|
13057
13078
|
const previousDepth = privilegeDepth.get(db) ?? 0;
|
|
13058
13079
|
const nested = isInTransaction(db);
|
|
13059
13080
|
const savepoint = "mc_privilege_scope";
|
|
@@ -13064,11 +13085,9 @@ function withPrivilegedWriter(db, operation) {
|
|
|
13064
13085
|
}
|
|
13065
13086
|
privilegeDepth.set(db, previousDepth + 1);
|
|
13066
13087
|
try {
|
|
13067
|
-
|
|
13068
|
-
db.prepare("INSERT INTO context_privilege_state(id, enabled) VALUES (1, 1) ON CONFLICT(id) DO UPDATE SET enabled = 1").run();
|
|
13069
|
-
}
|
|
13088
|
+
db.prepare("INSERT INTO context_privilege_state(id, enabled) VALUES (1, 1) ON CONFLICT(id) DO UPDATE SET enabled = 1").run();
|
|
13070
13089
|
const result = operation();
|
|
13071
|
-
if (
|
|
13090
|
+
if (previousDepth === 0) {
|
|
13072
13091
|
db.prepare("UPDATE context_privilege_state SET enabled = 0 WHERE id = 1").run();
|
|
13073
13092
|
}
|
|
13074
13093
|
if (nested) {
|
|
@@ -13098,7 +13117,7 @@ function withPrivilegedWriter(db, operation) {
|
|
|
13098
13117
|
throw error;
|
|
13099
13118
|
}
|
|
13100
13119
|
}
|
|
13101
|
-
var isBun, bunSpec, nodeSpec, sqliteModule, DatabaseImpl, Database, privilegeDepth
|
|
13120
|
+
var isBun, bunSpec, nodeSpec, sqliteModule, DatabaseImpl, Database, privilegeDepth;
|
|
13102
13121
|
var init_sqlite = __esm(async () => {
|
|
13103
13122
|
isBun = typeof process !== "undefined" && typeof process.versions?.bun === "string";
|
|
13104
13123
|
bunSpec = "bun:" + "sqlite";
|
|
@@ -13107,8 +13126,6 @@ var init_sqlite = __esm(async () => {
|
|
|
13107
13126
|
DatabaseImpl = isBun ? sqliteModule.Database : buildNodeSqliteDatabaseClass(sqliteModule.DatabaseSync);
|
|
13108
13127
|
Database = DatabaseImpl;
|
|
13109
13128
|
privilegeDepth = new WeakMap;
|
|
13110
|
-
registeredPrivilegeFunctions = new WeakSet;
|
|
13111
|
-
privilegeUdfAvailable = new WeakSet;
|
|
13112
13129
|
});
|
|
13113
13130
|
|
|
13114
13131
|
// ../plugin/src/features/magic-context/context-authority.ts
|
|
@@ -16784,6 +16801,187 @@ var init_module_transport = __esm(() => {
|
|
|
16784
16801
|
init_dist5();
|
|
16785
16802
|
init_data_path();
|
|
16786
16803
|
});
|
|
16804
|
+
// ../plugin/src/hooks/magic-context/compartment-parser.ts
|
|
16805
|
+
function makeTierOpenRegex(n2) {
|
|
16806
|
+
return new RegExp(`<p${n2}\\s*(/?)>`);
|
|
16807
|
+
}
|
|
16808
|
+
function extractTier(inner, index) {
|
|
16809
|
+
const openMatch = TIER_OPEN_REGEXES[index].exec(inner);
|
|
16810
|
+
if (!openMatch)
|
|
16811
|
+
return;
|
|
16812
|
+
if (openMatch[1] === "/")
|
|
16813
|
+
return "";
|
|
16814
|
+
const rest = inner.slice(openMatch.index + openMatch[0].length);
|
|
16815
|
+
const closeAt = rest.search(TIER_CLOSE_ANY_REGEX);
|
|
16816
|
+
let body = closeAt === -1 ? rest : rest.slice(0, closeAt);
|
|
16817
|
+
const openInside = body.search(TIER_OPEN_ANY_REGEX);
|
|
16818
|
+
if (openInside !== -1)
|
|
16819
|
+
body = body.slice(0, openInside);
|
|
16820
|
+
return unescapeXml(body.trim());
|
|
16821
|
+
}
|
|
16822
|
+
function extractTiersFromInner(inner) {
|
|
16823
|
+
return {
|
|
16824
|
+
p1: extractTier(inner, 0),
|
|
16825
|
+
p2: extractTier(inner, 1),
|
|
16826
|
+
p3: extractTier(inner, 2),
|
|
16827
|
+
p4: extractTier(inner, 3)
|
|
16828
|
+
};
|
|
16829
|
+
}
|
|
16830
|
+
function parseCompartmentOutput(text3) {
|
|
16831
|
+
const compartments = [];
|
|
16832
|
+
const facts = [];
|
|
16833
|
+
for (const match of text3.matchAll(COMPARTMENT_REGEX)) {
|
|
16834
|
+
const attrs = match[1];
|
|
16835
|
+
const inner = match[2];
|
|
16836
|
+
const startMatch = attrs.match(ATTR_START_REGEX);
|
|
16837
|
+
const endMatch = attrs.match(ATTR_END_REGEX);
|
|
16838
|
+
const titleMatch = attrs.match(ATTR_TITLE_REGEX);
|
|
16839
|
+
if (!startMatch || !endMatch || !titleMatch)
|
|
16840
|
+
continue;
|
|
16841
|
+
const startMessage = parseInt(startMatch[1], 10);
|
|
16842
|
+
const endMessage = parseInt(endMatch[1], 10);
|
|
16843
|
+
const title = unescapeXml(titleMatch[1]);
|
|
16844
|
+
if (Number.isNaN(startMessage) || Number.isNaN(endMessage) || !title)
|
|
16845
|
+
continue;
|
|
16846
|
+
const episodeMatch = attrs.match(ATTR_EPISODE_REGEX);
|
|
16847
|
+
const importanceMatch = attrs.match(ATTR_IMPORTANCE_REGEX);
|
|
16848
|
+
const episodeType = episodeMatch ? unescapeXml(episodeMatch[1]) : undefined;
|
|
16849
|
+
const importance = importanceMatch ? parseInt(importanceMatch[1], 10) : undefined;
|
|
16850
|
+
const p1 = extractTier(inner, 0);
|
|
16851
|
+
if (typeof p1 === "string" && p1.length > 0) {
|
|
16852
|
+
const p2 = extractTier(inner, 1);
|
|
16853
|
+
const p3 = extractTier(inner, 2);
|
|
16854
|
+
const p4 = extractTier(inner, 3);
|
|
16855
|
+
compartments.push({
|
|
16856
|
+
startMessage,
|
|
16857
|
+
endMessage,
|
|
16858
|
+
title,
|
|
16859
|
+
content: p1,
|
|
16860
|
+
p1,
|
|
16861
|
+
p2: typeof p2 === "string" ? p2 : p1,
|
|
16862
|
+
p3: typeof p3 === "string" ? p3 : typeof p2 === "string" ? p2 : p1,
|
|
16863
|
+
p4: typeof p4 === "string" ? p4 : "",
|
|
16864
|
+
importance,
|
|
16865
|
+
episodeType
|
|
16866
|
+
});
|
|
16867
|
+
continue;
|
|
16868
|
+
}
|
|
16869
|
+
const content = unescapeXml(inner.trim());
|
|
16870
|
+
if (content) {
|
|
16871
|
+
compartments.push({
|
|
16872
|
+
startMessage,
|
|
16873
|
+
endMessage,
|
|
16874
|
+
title,
|
|
16875
|
+
content,
|
|
16876
|
+
importance,
|
|
16877
|
+
episodeType
|
|
16878
|
+
});
|
|
16879
|
+
}
|
|
16880
|
+
}
|
|
16881
|
+
const factsBlockMatch = text3.match(FACTS_BLOCK_REGEX);
|
|
16882
|
+
const factsScope = factsBlockMatch ? factsBlockMatch[1] : text3.replace(EVENTS_BLOCK_REGEX, "").replace(/<compartment\s+[^>]*?\s*>.*?<\/compartment>/gs, "");
|
|
16883
|
+
for (const categoryMatch of factsScope.matchAll(CATEGORY_BLOCK_REGEX)) {
|
|
16884
|
+
const category = categoryMatch[1];
|
|
16885
|
+
const blockContent = categoryMatch[2];
|
|
16886
|
+
for (const itemMatch of blockContent.matchAll(FACT_ITEM_REGEX)) {
|
|
16887
|
+
const content = unescapeXml(itemMatch[1].trim());
|
|
16888
|
+
if (content) {
|
|
16889
|
+
facts.push({ category, content });
|
|
16890
|
+
}
|
|
16891
|
+
}
|
|
16892
|
+
}
|
|
16893
|
+
const unprocessedMatch = text3.match(UNPROCESSED_REGEX);
|
|
16894
|
+
const unprocessedFrom = unprocessedMatch ? parseInt(unprocessedMatch[1], 10) : null;
|
|
16895
|
+
const userObservations = [];
|
|
16896
|
+
const userObsMatch = text3.match(USER_OBSERVATIONS_REGEX);
|
|
16897
|
+
if (userObsMatch) {
|
|
16898
|
+
for (const itemMatch of userObsMatch[1].matchAll(USER_OBS_ITEM_REGEX)) {
|
|
16899
|
+
const obs = unescapeXml(itemMatch[1].trim());
|
|
16900
|
+
if (obs)
|
|
16901
|
+
userObservations.push(obs);
|
|
16902
|
+
}
|
|
16903
|
+
}
|
|
16904
|
+
const primerCandidates = [];
|
|
16905
|
+
const primerMatch = text3.match(PRIMER_CANDIDATES_REGEX);
|
|
16906
|
+
if (primerMatch) {
|
|
16907
|
+
const block2 = primerMatch[1];
|
|
16908
|
+
let sawElement = false;
|
|
16909
|
+
for (const el of block2.matchAll(PRIMER_ELEMENT_REGEX)) {
|
|
16910
|
+
sawElement = true;
|
|
16911
|
+
const question = unescapeXml(el[2].trim());
|
|
16912
|
+
if (question) {
|
|
16913
|
+
primerCandidates.push({
|
|
16914
|
+
question,
|
|
16915
|
+
originCompartmentIndex: Number.parseInt(el[1], 10)
|
|
16916
|
+
});
|
|
16917
|
+
}
|
|
16918
|
+
}
|
|
16919
|
+
if (!sawElement) {
|
|
16920
|
+
for (const itemMatch of block2.matchAll(PRIMER_ITEM_REGEX)) {
|
|
16921
|
+
const question = unescapeXml(itemMatch[1].trim());
|
|
16922
|
+
if (question)
|
|
16923
|
+
primerCandidates.push({ question });
|
|
16924
|
+
}
|
|
16925
|
+
}
|
|
16926
|
+
}
|
|
16927
|
+
const events = parseEvents(text3);
|
|
16928
|
+
compartments.sort((a3, b2) => a3.startMessage - b2.startMessage);
|
|
16929
|
+
return { compartments, facts, events, unprocessedFrom, userObservations, primerCandidates };
|
|
16930
|
+
}
|
|
16931
|
+
function parseEvents(text3) {
|
|
16932
|
+
const blockMatch = text3.match(EVENTS_BLOCK_REGEX);
|
|
16933
|
+
if (!blockMatch)
|
|
16934
|
+
return [];
|
|
16935
|
+
const block2 = blockMatch[1];
|
|
16936
|
+
const events = [];
|
|
16937
|
+
for (const elMatch of block2.matchAll(EVENT_ELEMENT_REGEX)) {
|
|
16938
|
+
const kind = elMatch[1];
|
|
16939
|
+
const atRaw = parseInt(elMatch[2], 10);
|
|
16940
|
+
const atCompartment = Number.isNaN(atRaw) ? null : atRaw;
|
|
16941
|
+
const fields = {};
|
|
16942
|
+
for (const fieldMatch of elMatch[3].matchAll(EVENT_FIELD_REGEX)) {
|
|
16943
|
+
const name = fieldMatch[1];
|
|
16944
|
+
const value = unescapeXml(fieldMatch[2].trim());
|
|
16945
|
+
if (value)
|
|
16946
|
+
fields[name] = value;
|
|
16947
|
+
}
|
|
16948
|
+
events.push({ kind, atCompartment, fields });
|
|
16949
|
+
}
|
|
16950
|
+
return events;
|
|
16951
|
+
}
|
|
16952
|
+
function unescapeXml(s) {
|
|
16953
|
+
return s.replace(/&/g, "&").replace(/'/g, "'").replace(/"/g, '"').replace(/</g, "<").replace(/>/g, ">");
|
|
16954
|
+
}
|
|
16955
|
+
var COMPARTMENT_REGEX, ATTR_START_REGEX, ATTR_END_REGEX, ATTR_TITLE_REGEX, ATTR_EPISODE_REGEX, ATTR_IMPORTANCE_REGEX, TIER_OPEN_REGEXES, TIER_CLOSE_ANY_REGEX, TIER_OPEN_ANY_REGEX, CATEGORY_BLOCK_REGEX, FACT_ITEM_REGEX, UNPROCESSED_REGEX, USER_OBSERVATIONS_REGEX, USER_OBS_ITEM_REGEX, PRIMER_CANDIDATES_REGEX, PRIMER_ELEMENT_REGEX, PRIMER_ITEM_REGEX, FACTS_BLOCK_REGEX, EVENTS_BLOCK_REGEX, EVENT_ELEMENT_REGEX, EVENT_FIELD_REGEX;
|
|
16956
|
+
var init_compartment_parser = __esm(() => {
|
|
16957
|
+
COMPARTMENT_REGEX = /<compartment\s+([^>]*?)\s*>(.*?)<\/compartment>/gs;
|
|
16958
|
+
ATTR_START_REGEX = /\bstart="(\d+)"/;
|
|
16959
|
+
ATTR_END_REGEX = /\bend="(\d+)"/;
|
|
16960
|
+
ATTR_TITLE_REGEX = /\btitle="([^"]*)"/;
|
|
16961
|
+
ATTR_EPISODE_REGEX = /\bepisode_type="([^"]*)"/;
|
|
16962
|
+
ATTR_IMPORTANCE_REGEX = /\bimportance="(\d+)"/;
|
|
16963
|
+
TIER_OPEN_REGEXES = [
|
|
16964
|
+
makeTierOpenRegex(1),
|
|
16965
|
+
makeTierOpenRegex(2),
|
|
16966
|
+
makeTierOpenRegex(3),
|
|
16967
|
+
makeTierOpenRegex(4)
|
|
16968
|
+
];
|
|
16969
|
+
TIER_CLOSE_ANY_REGEX = /<\/p\d/;
|
|
16970
|
+
TIER_OPEN_ANY_REGEX = /<p\d/;
|
|
16971
|
+
CATEGORY_BLOCK_REGEX = /<(PROJECT_RULES|ARCHITECTURE|CONSTRAINTS|CONFIG_VALUES|NAMING)>(.*?)<\/\1>/gs;
|
|
16972
|
+
FACT_ITEM_REGEX = /^\s*\*\s*(.+)$/gm;
|
|
16973
|
+
UNPROCESSED_REGEX = /<unprocessed_from>(\d+)<\/unprocessed_from>/;
|
|
16974
|
+
USER_OBSERVATIONS_REGEX = /<user_observations>(.*?)<\/user_observations>/s;
|
|
16975
|
+
USER_OBS_ITEM_REGEX = /^\s*\*\s*(.+)$/gm;
|
|
16976
|
+
PRIMER_CANDIDATES_REGEX = /<primer_candidates>(.*?)<\/primer_candidates>/s;
|
|
16977
|
+
PRIMER_ELEMENT_REGEX = /<primer\s+at_compartment="(\d+)"\s*>(.*?)<\/primer>/gs;
|
|
16978
|
+
PRIMER_ITEM_REGEX = /^\s*(?:\*|-|\d+\.)\s*(.+)$/gm;
|
|
16979
|
+
FACTS_BLOCK_REGEX = /<facts>(.*?)<\/facts>/s;
|
|
16980
|
+
EVENTS_BLOCK_REGEX = /<events>(.*?)<\/events>/s;
|
|
16981
|
+
EVENT_ELEMENT_REGEX = /<([a-z_]+)\s+at_compartment="(\d+)"\s*>(.*?)<\/\1>/gs;
|
|
16982
|
+
EVENT_FIELD_REGEX = /<([a-z_]+)\s*>(.*?)<\/\1>/gs;
|
|
16983
|
+
});
|
|
16984
|
+
|
|
16787
16985
|
// ../plugin/src/features/magic-context/storage-schema-helpers.ts
|
|
16788
16986
|
function ensureColumn(db, table, column, definition) {
|
|
16789
16987
|
if (!/^[a-z][a-z0-9_]*$/.test(table) || !/^[a-z][a-z0-9_]*$/.test(column) || !/^[A-Z0-9_"'(),[\]\s]+$/i.test(definition)) {
|
|
@@ -16963,15 +17161,38 @@ var init_workspaces = __esm(() => {
|
|
|
16963
17161
|
function tableExists(db, name) {
|
|
16964
17162
|
return Boolean(db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = ?").get(name));
|
|
16965
17163
|
}
|
|
17164
|
+
function healMismatchedTierClose(db, table, hasLegacy) {
|
|
17165
|
+
if (!tableExists(db, table))
|
|
17166
|
+
return;
|
|
17167
|
+
const columns = new Set(db.prepare(`PRAGMA table_info(${table})`).all().map((row) => row.name));
|
|
17168
|
+
for (const required of ["content", "p1", "p2", "p3", "p4"]) {
|
|
17169
|
+
if (!columns.has(required))
|
|
17170
|
+
return;
|
|
17171
|
+
}
|
|
17172
|
+
if (hasLegacy && !columns.has("legacy"))
|
|
17173
|
+
return;
|
|
17174
|
+
const predicate = hasLegacy ? "legacy = 1 AND p1 IS NULL AND content LIKE '%<p1%'" : "p1 IS NULL AND content LIKE '%<p1%'";
|
|
17175
|
+
const rows = db.prepare(`SELECT id, content FROM ${table} WHERE ${predicate}`).all();
|
|
17176
|
+
const update = db.prepare(`UPDATE ${table} SET p1 = ?, p2 = ?, p3 = ?, p4 = ?${hasLegacy ? ", legacy = 0" : ""} WHERE id = ?`);
|
|
17177
|
+
for (const row of rows) {
|
|
17178
|
+
const tiers = extractTiersFromInner(row.content);
|
|
17179
|
+
if (typeof tiers.p1 !== "string" || tiers.p1.length === 0)
|
|
17180
|
+
continue;
|
|
17181
|
+
const p1 = tiers.p1;
|
|
17182
|
+
const p2 = typeof tiers.p2 === "string" ? tiers.p2 : p1;
|
|
17183
|
+
const p3 = typeof tiers.p3 === "string" ? tiers.p3 : p2;
|
|
17184
|
+
const p4 = typeof tiers.p4 === "string" ? tiers.p4 : "";
|
|
17185
|
+
update.run(p1, p2, p3, p4, row.id);
|
|
17186
|
+
}
|
|
17187
|
+
}
|
|
16966
17188
|
function assertForeignKeyIntegrity(db, table) {
|
|
16967
17189
|
const rows = (table ? db.prepare(`PRAGMA foreign_key_check(${table})`) : db.prepare("PRAGMA foreign_key_check")).all();
|
|
16968
17190
|
if (rows.length > 0) {
|
|
16969
17191
|
throw new Error(`foreign_key_check failed after embedding table rebuild${table ? ` (${table})` : ""} (${rows.length} violation(s))`);
|
|
16970
17192
|
}
|
|
16971
17193
|
}
|
|
16972
|
-
function authorityPrivilegeCheck(
|
|
16973
|
-
|
|
16974
|
-
return typeof native.function === "function" || typeof native.createFunction === "function" ? "mc_privileged_writer() = 0" : "COALESCE((SELECT enabled FROM context_privilege_state WHERE id = 1), 0) = 0";
|
|
17194
|
+
function authorityPrivilegeCheck() {
|
|
17195
|
+
return "COALESCE((SELECT enabled FROM context_privilege_state WHERE id = 1), 0) = 0";
|
|
16975
17196
|
}
|
|
16976
17197
|
function managedAuthorityNoteRow(row) {
|
|
16977
17198
|
return `(
|
|
@@ -16990,7 +17211,7 @@ function managedAuthorityNoteRow(row) {
|
|
|
16990
17211
|
)`;
|
|
16991
17212
|
}
|
|
16992
17213
|
function installLatestAuthorityTriggers(db) {
|
|
16993
|
-
const privilegeCheck = authorityPrivilegeCheck(
|
|
17214
|
+
const privilegeCheck = authorityPrivilegeCheck();
|
|
16994
17215
|
if (tableExists(db, "memories")) {
|
|
16995
17216
|
db.exec(`
|
|
16996
17217
|
DROP TRIGGER IF EXISTS memories_authority_guard_insert;
|
|
@@ -17042,6 +17263,7 @@ function installLatestAuthorityTriggers(db) {
|
|
|
17042
17263
|
}
|
|
17043
17264
|
var MIGRATIONS, LATEST_MIGRATION_VERSION;
|
|
17044
17265
|
var init_migrations = __esm(() => {
|
|
17266
|
+
init_compartment_parser();
|
|
17045
17267
|
init_logger();
|
|
17046
17268
|
init_workspaces();
|
|
17047
17269
|
MIGRATIONS = [
|
|
@@ -18920,6 +19142,21 @@ var init_migrations = __esm(() => {
|
|
|
18920
19142
|
ON memory_mutation_log(project_path, target_memory_id, id);
|
|
18921
19143
|
`);
|
|
18922
19144
|
}
|
|
19145
|
+
},
|
|
19146
|
+
{
|
|
19147
|
+
version: 70,
|
|
19148
|
+
description: "heal legacy compartments stranded by mismatched tier closing tags (issue #246)",
|
|
19149
|
+
up(db) {
|
|
19150
|
+
healMismatchedTierClose(db, "compartments", true);
|
|
19151
|
+
healMismatchedTierClose(db, "recomp_compartments", false);
|
|
19152
|
+
}
|
|
19153
|
+
},
|
|
19154
|
+
{
|
|
19155
|
+
version: 71,
|
|
19156
|
+
description: "rebuild authority guard triggers to the durable state-table form (issue #253)",
|
|
19157
|
+
up(db) {
|
|
19158
|
+
installLatestAuthorityTriggers(db);
|
|
19159
|
+
}
|
|
18923
19160
|
}
|
|
18924
19161
|
];
|
|
18925
19162
|
LATEST_MIGRATION_VERSION = MIGRATIONS.reduce((max, m3) => Math.max(max, m3.version), 0);
|
|
@@ -151411,7 +151648,7 @@ function getPersistedSchemaVersion(db) {
|
|
|
151411
151648
|
const row = db.prepare("SELECT MAX(version) AS version FROM schema_migrations").get();
|
|
151412
151649
|
return row?.version ?? 0;
|
|
151413
151650
|
}
|
|
151414
|
-
var databases, pendingAsyncOpens, persistenceByDatabase, persistenceErrorByDatabase, pathByDatabase, LATEST_SUPPORTED_VERSION =
|
|
151651
|
+
var databases, pendingAsyncOpens, persistenceByDatabase, persistenceErrorByDatabase, pathByDatabase, LATEST_SUPPORTED_VERSION = 71, PERMISSIONS_ENFORCEABLE;
|
|
151415
151652
|
var init_storage_db = __esm(async () => {
|
|
151416
151653
|
init_data_path();
|
|
151417
151654
|
init_logger();
|
|
@@ -151961,11 +152198,11 @@ var init_doctor_merge_identity = __esm(async () => {
|
|
|
151961
152198
|
});
|
|
151962
152199
|
|
|
151963
152200
|
// src/lib/migration-paths.ts
|
|
151964
|
-
import { homedir as
|
|
152201
|
+
import { homedir as homedir8 } from "node:os";
|
|
151965
152202
|
import { join as join13 } from "node:path";
|
|
151966
152203
|
function getOpenCodeDatabasePath() {
|
|
151967
152204
|
const dataHome = process.env.XDG_DATA_HOME?.trim();
|
|
151968
|
-
return join13(dataHome || join13(
|
|
152205
|
+
return join13(dataHome || join13(homedir8(), ".local", "share"), "opencode", "opencode.db");
|
|
151969
152206
|
}
|
|
151970
152207
|
function projectPathToPiSessionSlug(projectPath, platform = process.platform) {
|
|
151971
152208
|
const separators = platform === "win32" ? /[:\\/]+/g : /\/+/g;
|
|
@@ -152732,7 +152969,7 @@ __export(exports_migrate_session, {
|
|
|
152732
152969
|
applyMigrateSession: () => applyMigrateSession
|
|
152733
152970
|
});
|
|
152734
152971
|
import { existsSync as existsSync15, realpathSync as realpathSync4 } from "node:fs";
|
|
152735
|
-
import { homedir as
|
|
152972
|
+
import { homedir as homedir9 } from "node:os";
|
|
152736
152973
|
import path4, { join as join15 } from "node:path";
|
|
152737
152974
|
function existingSessionColumns(db) {
|
|
152738
152975
|
const rows = db.prepare("PRAGMA table_info(session)").all();
|
|
@@ -152972,7 +153209,7 @@ async function runMigrateSessionCli(args) {
|
|
|
152972
153209
|
printMigrateSessionHelp();
|
|
152973
153210
|
return 1;
|
|
152974
153211
|
}
|
|
152975
|
-
const expandedTo = toDir.startsWith("~") ? join15(
|
|
153212
|
+
const expandedTo = toDir.startsWith("~") ? join15(homedir9(), toDir.slice(1).replace(/^[/\\]/, "")) : toDir;
|
|
152976
153213
|
if (!existsSync15(expandedTo)) {
|
|
152977
153214
|
console.error(`Target directory does not exist: ${expandedTo}`);
|
|
152978
153215
|
return 1;
|
|
@@ -168358,7 +168595,7 @@ var init_agent_overrides = __esm(() => {
|
|
|
168358
168595
|
});
|
|
168359
168596
|
|
|
168360
168597
|
// ../plugin/src/config/schema/magic-context.ts
|
|
168361
|
-
import { homedir as
|
|
168598
|
+
import { homedir as homedir10 } from "node:os";
|
|
168362
168599
|
function defaultTaskConfig(task) {
|
|
168363
168600
|
const base = { schedule: DEFAULT_TASK_SCHEDULES2[task] };
|
|
168364
168601
|
if (task === "review-user-memories")
|
|
@@ -168370,20 +168607,18 @@ function defaultTaskConfig(task) {
|
|
|
168370
168607
|
function expandConfigPath(value) {
|
|
168371
168608
|
const trimmed = value.trim();
|
|
168372
168609
|
if (trimmed === "~")
|
|
168373
|
-
return
|
|
168610
|
+
return homedir10();
|
|
168374
168611
|
if (trimmed.startsWith("~/"))
|
|
168375
|
-
return `${
|
|
168612
|
+
return `${homedir10()}/${trimmed.slice(2)}`;
|
|
168376
168613
|
return trimmed;
|
|
168377
168614
|
}
|
|
168378
|
-
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",
|
|
168615
|
+
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", PiThinkingLevelSchema, PiConfigSchema, CronScheduleSchema, DreamTaskBaseConfigSchema, PromotionThresholdSchema, PrimerPromotionThresholdSchema, DreamTaskConfigSchema, ReviewUserMemoriesTaskConfigSchema, PromotePrimersTaskConfigSchema, DEFAULT_TASK_SCHEDULES2, DreamTasksSchema, DreamerConfigSchema, SidekickConfigSchema, HistorianConfigSchema, EmbeddingFallbackProviderSchema, BaseEmbeddingConfigSchema, EmbeddingConfigSchema, MagicContextConfigSchema;
|
|
168379
168616
|
var init_magic_context = __esm(() => {
|
|
168380
168617
|
init_zod();
|
|
168381
168618
|
init_language_directive();
|
|
168382
168619
|
init_cron();
|
|
168383
|
-
init_task_registry();
|
|
168384
168620
|
init_agent_overrides();
|
|
168385
|
-
|
|
168386
|
-
PiThinkingLevelSchema = exports_external.enum(["off", "minimal", "low", "medium", "high", "xhigh"]).optional();
|
|
168621
|
+
PiThinkingLevelSchema = exports_external.enum(["off", "minimal", "low", "medium", "high", "xhigh", "max"]).optional();
|
|
168387
168622
|
PiConfigSchema = exports_external.object({
|
|
168388
168623
|
subagent_extensions: exports_external.array(exports_external.string().trim().min(1)).optional().describe("User-only allowlist of Pi extensions for Magic Context subagent children. When set, children use --no-extensions and load only these entries (plus Magic Context's scoped child extension where applicable). Relative paths resolve from ~/.pi/agent, matching Pi's settings.json package location. Unset preserves normal Pi extension discovery.")
|
|
168389
168624
|
}).optional();
|
|
@@ -168448,7 +168683,7 @@ var init_magic_context = __esm(() => {
|
|
|
168448
168683
|
}).optional();
|
|
168449
168684
|
HistorianConfigSchema = AgentOverrideConfigSchema.extend({
|
|
168450
168685
|
two_pass: exports_external.boolean().default(false).describe("Run a second editor pass over historian output to clean low-signal U: lines and cross-compartment duplicates. Adds ~1 extra API call and ~1.3x cost per historian run. Useful for models without extended thinking support. (default: false)"),
|
|
168451
|
-
thinking_level: PiThinkingLevelSchema.describe("Pi only: explicit thinking level passed as --thinking <level> to Pi historian subagent invocations. Required when using reasoning models (e.g. github-copilot/gpt-5.4) because Pi's default thinking-level resolution can pick a value the provider rejects. OpenCode users set variant instead. Valid: off | minimal | low | medium | high | xhigh"),
|
|
168686
|
+
thinking_level: PiThinkingLevelSchema.describe("Pi only: explicit thinking level passed as --thinking <level> to Pi historian subagent invocations. Required when using reasoning models (e.g. github-copilot/gpt-5.4) because Pi's default thinking-level resolution can pick a value the provider rejects. OpenCode users set variant instead. Valid: off | minimal | low | medium | high | xhigh | max"),
|
|
168452
168687
|
disallowed_tools: exports_external.array(exports_external.enum(["*", "read", "aft_outline", "aft_zoom", "aft_search"])).default([]).describe(`OpenCode only. Tools to REMOVE from the historian's default allow-list [read, aft_outline, aft_zoom, aft_search]. Applies to both historian and historian-editor agents. Use ["*"] to strip all tool definitions from the model request — this prevents weak instruction-following models (e.g. mistral-small-latest) from entering tool-calling loops. Individual tool names remove just that tool. Note: a user-supplied historian.permission override can re-allow a tool that disallowed_tools removed — disallowed_tools sets the baseline, permission overrides take precedence. (default: [])`)
|
|
168453
168688
|
}).optional();
|
|
168454
168689
|
EmbeddingFallbackProviderSchema = exports_external.enum(["local", "openai-compatible", "off"]);
|
|
@@ -168971,10 +169206,10 @@ var RUST_REQUIRES_USER_SUBC_WARNING = "rust mode requires user-level subc config
|
|
|
168971
169206
|
|
|
168972
169207
|
// ../plugin/src/config/variable.ts
|
|
168973
169208
|
import { existsSync as existsSync16, readFileSync as readFileSync7 } from "node:fs";
|
|
168974
|
-
import { homedir as
|
|
169209
|
+
import { homedir as homedir11 } from "node:os";
|
|
168975
169210
|
import { dirname as dirname9, isAbsolute as isAbsolute3, resolve as resolve3 } from "node:path";
|
|
168976
169211
|
function sensitiveFilePathReason(resolvedPath) {
|
|
168977
|
-
const home =
|
|
169212
|
+
const home = homedir11();
|
|
168978
169213
|
const sensitiveDirs = [
|
|
168979
169214
|
{ dir: resolve3(home, ".ssh"), label: "SSH keys" },
|
|
168980
169215
|
{ dir: resolve3(home, ".aws"), label: "AWS credentials" },
|
|
@@ -169037,7 +169272,7 @@ function substituteConfigVariables(input) {
|
|
|
169037
169272
|
}
|
|
169038
169273
|
let filePath = rawPath.trim();
|
|
169039
169274
|
if (filePath.startsWith("~/")) {
|
|
169040
|
-
filePath = resolve3(
|
|
169275
|
+
filePath = resolve3(homedir11(), filePath.slice(2));
|
|
169041
169276
|
} else if (!isAbsolute3(filePath)) {
|
|
169042
169277
|
filePath = resolve3(configDir, filePath);
|
|
169043
169278
|
}
|
|
@@ -169615,166 +169850,8 @@ var init_tui_config = __esm(() => {
|
|
|
169615
169850
|
PLUGIN_ENTRY = `${PLUGIN_NAME2}@latest`;
|
|
169616
169851
|
});
|
|
169617
169852
|
|
|
169618
|
-
// ../plugin/src/hooks/magic-context/compartment-parser.ts
|
|
169619
|
-
function makeTierRegex(n2) {
|
|
169620
|
-
return new RegExp(`<p${n2}\\s*/>|<p${n2}\\s*>(.*?)</p${n2}>`, "s");
|
|
169621
|
-
}
|
|
169622
|
-
function extractTier(inner, index) {
|
|
169623
|
-
const m3 = inner.match(TIER_REGEXES[index]);
|
|
169624
|
-
if (!m3)
|
|
169625
|
-
return;
|
|
169626
|
-
return unescapeXml((m3[1] ?? "").trim());
|
|
169627
|
-
}
|
|
169628
|
-
function parseCompartmentOutput(text3) {
|
|
169629
|
-
const compartments = [];
|
|
169630
|
-
const facts = [];
|
|
169631
|
-
for (const match of text3.matchAll(COMPARTMENT_REGEX)) {
|
|
169632
|
-
const attrs = match[1];
|
|
169633
|
-
const inner = match[2];
|
|
169634
|
-
const startMatch = attrs.match(ATTR_START_REGEX);
|
|
169635
|
-
const endMatch = attrs.match(ATTR_END_REGEX);
|
|
169636
|
-
const titleMatch = attrs.match(ATTR_TITLE_REGEX);
|
|
169637
|
-
if (!startMatch || !endMatch || !titleMatch)
|
|
169638
|
-
continue;
|
|
169639
|
-
const startMessage = parseInt(startMatch[1], 10);
|
|
169640
|
-
const endMessage = parseInt(endMatch[1], 10);
|
|
169641
|
-
const title = unescapeXml(titleMatch[1]);
|
|
169642
|
-
if (Number.isNaN(startMessage) || Number.isNaN(endMessage) || !title)
|
|
169643
|
-
continue;
|
|
169644
|
-
const episodeMatch = attrs.match(ATTR_EPISODE_REGEX);
|
|
169645
|
-
const importanceMatch = attrs.match(ATTR_IMPORTANCE_REGEX);
|
|
169646
|
-
const episodeType = episodeMatch ? unescapeXml(episodeMatch[1]) : undefined;
|
|
169647
|
-
const importance = importanceMatch ? parseInt(importanceMatch[1], 10) : undefined;
|
|
169648
|
-
const p1 = extractTier(inner, 0);
|
|
169649
|
-
if (typeof p1 === "string" && p1.length > 0) {
|
|
169650
|
-
const p2 = extractTier(inner, 1);
|
|
169651
|
-
const p3 = extractTier(inner, 2);
|
|
169652
|
-
const p4 = extractTier(inner, 3);
|
|
169653
|
-
compartments.push({
|
|
169654
|
-
startMessage,
|
|
169655
|
-
endMessage,
|
|
169656
|
-
title,
|
|
169657
|
-
content: p1,
|
|
169658
|
-
p1,
|
|
169659
|
-
p2: typeof p2 === "string" ? p2 : p1,
|
|
169660
|
-
p3: typeof p3 === "string" ? p3 : typeof p2 === "string" ? p2 : p1,
|
|
169661
|
-
p4: typeof p4 === "string" ? p4 : "",
|
|
169662
|
-
importance,
|
|
169663
|
-
episodeType
|
|
169664
|
-
});
|
|
169665
|
-
continue;
|
|
169666
|
-
}
|
|
169667
|
-
const content = unescapeXml(inner.trim());
|
|
169668
|
-
if (content) {
|
|
169669
|
-
compartments.push({
|
|
169670
|
-
startMessage,
|
|
169671
|
-
endMessage,
|
|
169672
|
-
title,
|
|
169673
|
-
content,
|
|
169674
|
-
importance,
|
|
169675
|
-
episodeType
|
|
169676
|
-
});
|
|
169677
|
-
}
|
|
169678
|
-
}
|
|
169679
|
-
const factsBlockMatch = text3.match(FACTS_BLOCK_REGEX);
|
|
169680
|
-
const factsScope = factsBlockMatch ? factsBlockMatch[1] : text3.replace(EVENTS_BLOCK_REGEX, "").replace(/<compartment\s+[^>]*?\s*>.*?<\/compartment>/gs, "");
|
|
169681
|
-
for (const categoryMatch of factsScope.matchAll(CATEGORY_BLOCK_REGEX)) {
|
|
169682
|
-
const category = categoryMatch[1];
|
|
169683
|
-
const blockContent = categoryMatch[2];
|
|
169684
|
-
for (const itemMatch of blockContent.matchAll(FACT_ITEM_REGEX)) {
|
|
169685
|
-
const content = unescapeXml(itemMatch[1].trim());
|
|
169686
|
-
if (content) {
|
|
169687
|
-
facts.push({ category, content });
|
|
169688
|
-
}
|
|
169689
|
-
}
|
|
169690
|
-
}
|
|
169691
|
-
const unprocessedMatch = text3.match(UNPROCESSED_REGEX);
|
|
169692
|
-
const unprocessedFrom = unprocessedMatch ? parseInt(unprocessedMatch[1], 10) : null;
|
|
169693
|
-
const userObservations = [];
|
|
169694
|
-
const userObsMatch = text3.match(USER_OBSERVATIONS_REGEX);
|
|
169695
|
-
if (userObsMatch) {
|
|
169696
|
-
for (const itemMatch of userObsMatch[1].matchAll(USER_OBS_ITEM_REGEX)) {
|
|
169697
|
-
const obs = unescapeXml(itemMatch[1].trim());
|
|
169698
|
-
if (obs)
|
|
169699
|
-
userObservations.push(obs);
|
|
169700
|
-
}
|
|
169701
|
-
}
|
|
169702
|
-
const primerCandidates = [];
|
|
169703
|
-
const primerMatch = text3.match(PRIMER_CANDIDATES_REGEX);
|
|
169704
|
-
if (primerMatch) {
|
|
169705
|
-
const block2 = primerMatch[1];
|
|
169706
|
-
let sawElement = false;
|
|
169707
|
-
for (const el of block2.matchAll(PRIMER_ELEMENT_REGEX)) {
|
|
169708
|
-
sawElement = true;
|
|
169709
|
-
const question = unescapeXml(el[2].trim());
|
|
169710
|
-
if (question) {
|
|
169711
|
-
primerCandidates.push({
|
|
169712
|
-
question,
|
|
169713
|
-
originCompartmentIndex: Number.parseInt(el[1], 10)
|
|
169714
|
-
});
|
|
169715
|
-
}
|
|
169716
|
-
}
|
|
169717
|
-
if (!sawElement) {
|
|
169718
|
-
for (const itemMatch of block2.matchAll(PRIMER_ITEM_REGEX)) {
|
|
169719
|
-
const question = unescapeXml(itemMatch[1].trim());
|
|
169720
|
-
if (question)
|
|
169721
|
-
primerCandidates.push({ question });
|
|
169722
|
-
}
|
|
169723
|
-
}
|
|
169724
|
-
}
|
|
169725
|
-
const events = parseEvents(text3);
|
|
169726
|
-
compartments.sort((a3, b2) => a3.startMessage - b2.startMessage);
|
|
169727
|
-
return { compartments, facts, events, unprocessedFrom, userObservations, primerCandidates };
|
|
169728
|
-
}
|
|
169729
|
-
function parseEvents(text3) {
|
|
169730
|
-
const blockMatch = text3.match(EVENTS_BLOCK_REGEX);
|
|
169731
|
-
if (!blockMatch)
|
|
169732
|
-
return [];
|
|
169733
|
-
const block2 = blockMatch[1];
|
|
169734
|
-
const events = [];
|
|
169735
|
-
for (const elMatch of block2.matchAll(EVENT_ELEMENT_REGEX)) {
|
|
169736
|
-
const kind = elMatch[1];
|
|
169737
|
-
const atRaw = parseInt(elMatch[2], 10);
|
|
169738
|
-
const atCompartment = Number.isNaN(atRaw) ? null : atRaw;
|
|
169739
|
-
const fields = {};
|
|
169740
|
-
for (const fieldMatch of elMatch[3].matchAll(EVENT_FIELD_REGEX)) {
|
|
169741
|
-
const name2 = fieldMatch[1];
|
|
169742
|
-
const value = unescapeXml(fieldMatch[2].trim());
|
|
169743
|
-
if (value)
|
|
169744
|
-
fields[name2] = value;
|
|
169745
|
-
}
|
|
169746
|
-
events.push({ kind, atCompartment, fields });
|
|
169747
|
-
}
|
|
169748
|
-
return events;
|
|
169749
|
-
}
|
|
169750
|
-
function unescapeXml(s) {
|
|
169751
|
-
return s.replace(/&/g, "&").replace(/'/g, "'").replace(/"/g, '"').replace(/</g, "<").replace(/>/g, ">");
|
|
169752
|
-
}
|
|
169753
|
-
var COMPARTMENT_REGEX, ATTR_START_REGEX, ATTR_END_REGEX, ATTR_TITLE_REGEX, ATTR_EPISODE_REGEX, ATTR_IMPORTANCE_REGEX, TIER_REGEXES, CATEGORY_BLOCK_REGEX, FACT_ITEM_REGEX, UNPROCESSED_REGEX, USER_OBSERVATIONS_REGEX, USER_OBS_ITEM_REGEX, PRIMER_CANDIDATES_REGEX, PRIMER_ELEMENT_REGEX, PRIMER_ITEM_REGEX, FACTS_BLOCK_REGEX, EVENTS_BLOCK_REGEX, EVENT_ELEMENT_REGEX, EVENT_FIELD_REGEX;
|
|
169754
|
-
var init_compartment_parser = __esm(() => {
|
|
169755
|
-
COMPARTMENT_REGEX = /<compartment\s+([^>]*?)\s*>(.*?)<\/compartment>/gs;
|
|
169756
|
-
ATTR_START_REGEX = /\bstart="(\d+)"/;
|
|
169757
|
-
ATTR_END_REGEX = /\bend="(\d+)"/;
|
|
169758
|
-
ATTR_TITLE_REGEX = /\btitle="([^"]*)"/;
|
|
169759
|
-
ATTR_EPISODE_REGEX = /\bepisode_type="([^"]*)"/;
|
|
169760
|
-
ATTR_IMPORTANCE_REGEX = /\bimportance="(\d+)"/;
|
|
169761
|
-
TIER_REGEXES = [makeTierRegex(1), makeTierRegex(2), makeTierRegex(3), makeTierRegex(4)];
|
|
169762
|
-
CATEGORY_BLOCK_REGEX = /<(PROJECT_RULES|ARCHITECTURE|CONSTRAINTS|CONFIG_VALUES|NAMING)>(.*?)<\/\1>/gs;
|
|
169763
|
-
FACT_ITEM_REGEX = /^\s*\*\s*(.+)$/gm;
|
|
169764
|
-
UNPROCESSED_REGEX = /<unprocessed_from>(\d+)<\/unprocessed_from>/;
|
|
169765
|
-
USER_OBSERVATIONS_REGEX = /<user_observations>(.*?)<\/user_observations>/s;
|
|
169766
|
-
USER_OBS_ITEM_REGEX = /^\s*\*\s*(.+)$/gm;
|
|
169767
|
-
PRIMER_CANDIDATES_REGEX = /<primer_candidates>(.*?)<\/primer_candidates>/s;
|
|
169768
|
-
PRIMER_ELEMENT_REGEX = /<primer\s+at_compartment="(\d+)"\s*>(.*?)<\/primer>/gs;
|
|
169769
|
-
PRIMER_ITEM_REGEX = /^\s*(?:\*|-|\d+\.)\s*(.+)$/gm;
|
|
169770
|
-
FACTS_BLOCK_REGEX = /<facts>(.*?)<\/facts>/s;
|
|
169771
|
-
EVENTS_BLOCK_REGEX = /<events>(.*?)<\/events>/s;
|
|
169772
|
-
EVENT_ELEMENT_REGEX = /<([a-z_]+)\s+at_compartment="(\d+)"\s*>(.*?)<\/\1>/gs;
|
|
169773
|
-
EVENT_FIELD_REGEX = /<([a-z_]+)\s*>(.*?)<\/\1>/gs;
|
|
169774
|
-
});
|
|
169775
|
-
|
|
169776
169853
|
// ../plugin/src/shared/redaction.ts
|
|
169777
|
-
import { homedir as
|
|
169854
|
+
import { homedir as homedir12, userInfo } from "node:os";
|
|
169778
169855
|
function escapeRegex3(value) {
|
|
169779
169856
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
169780
169857
|
}
|
|
@@ -169824,7 +169901,7 @@ function isSecretKey(key) {
|
|
|
169824
169901
|
return false;
|
|
169825
169902
|
}
|
|
169826
169903
|
function sanitizePathString(value) {
|
|
169827
|
-
const home =
|
|
169904
|
+
const home = homedir12();
|
|
169828
169905
|
const username = userInfo().username;
|
|
169829
169906
|
let sanitized = value;
|
|
169830
169907
|
if (home) {
|
|
@@ -169984,7 +170061,7 @@ var init_redaction2 = __esm(() => {
|
|
|
169984
170061
|
// src/lib/diagnostics-opencode.ts
|
|
169985
170062
|
import { existsSync as existsSync19, readdirSync as readdirSync2, readFileSync as readFileSync10, statSync as statSync8 } from "node:fs";
|
|
169986
170063
|
import { createRequire as createRequire2 } from "node:module";
|
|
169987
|
-
import { homedir as
|
|
170064
|
+
import { homedir as homedir13 } from "node:os";
|
|
169988
170065
|
import { join as join17 } from "node:path";
|
|
169989
170066
|
function getSelfVersion() {
|
|
169990
170067
|
const require2 = createRequire2(import.meta.url);
|
|
@@ -170016,7 +170093,7 @@ function getPluginCacheInfo() {
|
|
|
170016
170093
|
return { path: path6, cached: cached2, latest: getSelfVersion() };
|
|
170017
170094
|
}
|
|
170018
170095
|
function getStorageDir() {
|
|
170019
|
-
const dataHome = process.env.XDG_DATA_HOME || join17(
|
|
170096
|
+
const dataHome = process.env.XDG_DATA_HOME || join17(homedir13(), ".local", "share");
|
|
170020
170097
|
return join17(dataHome, "cortexkit", "magic-context");
|
|
170021
170098
|
}
|
|
170022
170099
|
function fileSize(path6) {
|
|
@@ -170162,7 +170239,7 @@ function collectHistorianDumps(recentSessions) {
|
|
|
170162
170239
|
};
|
|
170163
170240
|
}
|
|
170164
170241
|
async function collectRecentSessions() {
|
|
170165
|
-
const dataHome = process.env.XDG_DATA_HOME || join17(process.env.HOME ||
|
|
170242
|
+
const dataHome = process.env.XDG_DATA_HOME || join17(process.env.HOME || homedir13(), ".local", "share");
|
|
170166
170243
|
const opencodeDbPath = join17(dataHome, "opencode", "opencode.db");
|
|
170167
170244
|
if (!existsSync19(opencodeDbPath))
|
|
170168
170245
|
return [];
|
|
@@ -171251,7 +171328,7 @@ var init_doctor_opencode_cache = __esm(() => {
|
|
|
171251
171328
|
import { execSync as execSync2, spawnSync as spawnSync3 } from "node:child_process";
|
|
171252
171329
|
import { existsSync as existsSync22, readFileSync as readFileSync13, statSync as statSync9 } from "node:fs";
|
|
171253
171330
|
import { createRequire as createRequire4 } from "node:module";
|
|
171254
|
-
import { homedir as
|
|
171331
|
+
import { homedir as homedir14 } from "node:os";
|
|
171255
171332
|
import { join as join20 } from "node:path";
|
|
171256
171333
|
function migrateLegacyAgentEnabledConfigForDoctor(mcConfig, logs) {
|
|
171257
171334
|
let changed = false;
|
|
@@ -171342,7 +171419,7 @@ function getUserNpmrcPath() {
|
|
|
171342
171419
|
if (custom2)
|
|
171343
171420
|
return custom2;
|
|
171344
171421
|
const home = process.env.HOME?.trim();
|
|
171345
|
-
return join20(home ||
|
|
171422
|
+
return join20(home || homedir14(), ".npmrc");
|
|
171346
171423
|
}
|
|
171347
171424
|
function collectNpmReleaseAgeWarnings() {
|
|
171348
171425
|
const ageWarnings = [];
|
|
@@ -172381,7 +172458,7 @@ var init_config2 = __esm(() => {
|
|
|
172381
172458
|
import { createHash as createHash4 } from "node:crypto";
|
|
172382
172459
|
import { existsSync as existsSync24, readdirSync as readdirSync3, readFileSync as readFileSync15, statSync as statSync10 } from "node:fs";
|
|
172383
172460
|
import { createRequire as createRequire5 } from "node:module";
|
|
172384
|
-
import { homedir as
|
|
172461
|
+
import { homedir as homedir15, userInfo as userInfo2 } from "node:os";
|
|
172385
172462
|
import { join as join21 } from "node:path";
|
|
172386
172463
|
function getSelfVersion3() {
|
|
172387
172464
|
const req = createRequire5(import.meta.url);
|
|
@@ -172413,7 +172490,7 @@ function redactSecretString(value) {
|
|
|
172413
172490
|
return redactSecretText(value).replace(/Bearer\s+[A-Za-z0-9._~+\-/=]+/g, "Bearer <REDACTED>").replace(/sk-[A-Za-z0-9_-]{12,}/g, "sk-<REDACTED>").replace(/api[_-]?key=([^\s&]+)/gi, "api_key=<REDACTED>").replace(/token=([^\s&]+)/gi, "token=<REDACTED>");
|
|
172414
172491
|
}
|
|
172415
172492
|
function sanitizeString2(value) {
|
|
172416
|
-
const home = process.env.HOME ||
|
|
172493
|
+
const home = process.env.HOME || homedir15();
|
|
172417
172494
|
const username = userInfo2().username;
|
|
172418
172495
|
const userHash = `<USER:${currentUserHash()}>`;
|
|
172419
172496
|
let sanitized = redactSecretString(value);
|
|
@@ -172848,7 +172925,7 @@ var init_logs_pi = __esm(() => {
|
|
|
172848
172925
|
import { execFileSync as execFileSync4, spawnSync as spawnSync4 } from "node:child_process";
|
|
172849
172926
|
import { existsSync as existsSync25, mkdirSync as mkdirSync8, readdirSync as readdirSync4, readFileSync as readFileSync17, rmSync as rmSync3, statSync as statSync11 } from "node:fs";
|
|
172850
172927
|
import { createRequire as createRequire6 } from "node:module";
|
|
172851
|
-
import { homedir as
|
|
172928
|
+
import { homedir as homedir16 } from "node:os";
|
|
172852
172929
|
import { dirname as dirname12, isAbsolute as isAbsolute4, join as join23 } from "node:path";
|
|
172853
172930
|
function depsFrom(options) {
|
|
172854
172931
|
return {
|
|
@@ -173043,7 +173120,7 @@ function pinnedVersionFromPackageSpecifier(specifier) {
|
|
|
173043
173120
|
}
|
|
173044
173121
|
function cacheRoots(cwd) {
|
|
173045
173122
|
const home = process.env.HOME?.trim();
|
|
173046
|
-
const cacheHome = process.env.XDG_CACHE_HOME || join23(home ||
|
|
173123
|
+
const cacheHome = process.env.XDG_CACHE_HOME || join23(home || homedir16(), ".cache");
|
|
173047
173124
|
const piCacheRoot = getPiCacheRoot();
|
|
173048
173125
|
return [
|
|
173049
173126
|
join23(piCacheRoot, "extensions"),
|