@cortexkit/opencode-magic-context 0.15.0 → 0.15.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/cli/diagnostics.d.ts.map +1 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli.js +71 -82
- package/dist/features/magic-context/tool-definition-tokens.d.ts +45 -0
- package/dist/features/magic-context/tool-definition-tokens.d.ts.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3333 -3273
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/shared/data-path.d.ts +12 -0
- package/dist/shared/data-path.d.ts.map +1 -1
- package/dist/shared/models-dev-cache.d.ts.map +1 -1
- package/dist/shared/rpc-types.d.ts +15 -5
- package/dist/shared/rpc-types.d.ts.map +1 -1
- package/dist/tui/data/context-db.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/shared/data-path.test.ts +69 -0
- package/src/shared/data-path.ts +18 -0
- package/src/shared/models-dev-cache.ts +5 -10
- package/src/shared/rpc-types.ts +15 -5
- package/src/tui/data/context-db.ts +1 -0
- package/src/tui/index.tsx +13 -4
- package/src/tui/slots/sidebar-content.tsx +33 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/cli/diagnostics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../../src/cli/diagnostics.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,WAAW,EAAqB,MAAM,gBAAgB,CAAC;AAMrE,MAAM,WAAW,gBAAgB;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,WAAW,EAAE,WAAW,CAAC;IACzB,uBAAuB,EAAE,OAAO,CAAC;IACjC,kBAAkB,EAAE,OAAO,CAAC;IAC5B,kBAAkB,EAAE;QAChB,MAAM,EAAE,OAAO,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAClC,CAAC;IACF,WAAW,EAAE;QACT,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,UAAU,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,OAAO,CAAC;QAChB,kBAAkB,EAAE,MAAM,CAAC;KAC9B,CAAC;IACF,SAAS,EAAE;QACP,WAAW,EAAE,OAAO,CAAC;QACrB,OAAO,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;IACF,OAAO,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,OAAO,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,cAAc,EAAE;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,oBAAoB,EAAE,CAAC;KAClC,CAAC;IACF,gFAAgF;IAChF,iBAAiB,EAAE,uBAAuB,EAAE,CAAC;CAChD;AAED,MAAM,WAAW,oBAAoB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAC9B,8CAA8C;IAC9C,gBAAgB,EAAE,MAAM,CAAC;IACzB,mEAAmE;IACnE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,gEAAgE;IAChE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,mDAAmD;IACnD,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,kDAAkD;IAClD,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,2CAA2C;IAC3C,oBAAoB,EAAE,MAAM,CAAC;IAC7B,kGAAkG;IAClG,eAAe,EAAE,MAAM,CAAC;IACxB,sDAAsD;IACtD,mBAAmB,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,uBAAuB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,aAAa,EAAE,MAAM,CAAC;CACzB;AAoOD,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAgDpE;AASD,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CA8E1E"}
|
package/dist/cli/doctor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/cli/doctor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/cli/doctor.ts"],"names":[],"mappings":"AA4WA,wBAAsB,SAAS,CAC3B,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GACnD,OAAO,CAAC,MAAM,CAAC,CAyejB"}
|
package/dist/cli.js
CHANGED
|
@@ -7853,8 +7853,8 @@ var import_comment_json3 = __toESM(require_src2(), 1);
|
|
|
7853
7853
|
import { execSync as execSync2, spawnSync } from "node:child_process";
|
|
7854
7854
|
import { existsSync as existsSync7, readdirSync as readdirSync2, readFileSync as readFileSync6, rmSync, statSync as statSync2, writeFileSync as writeFileSync4 } from "node:fs";
|
|
7855
7855
|
import { createRequire as createRequire3 } from "node:module";
|
|
7856
|
-
import { homedir as
|
|
7857
|
-
import { join as
|
|
7856
|
+
import { homedir as homedir7, tmpdir as tmpdir3 } from "node:os";
|
|
7857
|
+
import { join as join10 } from "node:path";
|
|
7858
7858
|
|
|
7859
7859
|
// src/config/variable.ts
|
|
7860
7860
|
import { existsSync, readFileSync } from "node:fs";
|
|
@@ -8482,16 +8482,26 @@ function fixConflicts(directory, conflicts) {
|
|
|
8482
8482
|
return actions;
|
|
8483
8483
|
}
|
|
8484
8484
|
|
|
8485
|
+
// src/shared/data-path.ts
|
|
8486
|
+
import * as os from "node:os";
|
|
8487
|
+
import * as path from "node:path";
|
|
8488
|
+
function getCacheDir() {
|
|
8489
|
+
return process.env.XDG_CACHE_HOME ?? path.join(os.homedir(), ".cache");
|
|
8490
|
+
}
|
|
8491
|
+
function getOpenCodeCacheDir() {
|
|
8492
|
+
return path.join(getCacheDir(), "opencode");
|
|
8493
|
+
}
|
|
8494
|
+
|
|
8485
8495
|
// src/shared/tui-config.ts
|
|
8486
8496
|
var import_comment_json = __toESM(require_src2(), 1);
|
|
8487
8497
|
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
8488
|
-
import { dirname as dirname3, join as
|
|
8498
|
+
import { dirname as dirname3, join as join6 } from "node:path";
|
|
8489
8499
|
|
|
8490
8500
|
// src/shared/logger.ts
|
|
8491
8501
|
import * as fs from "node:fs";
|
|
8492
|
-
import * as
|
|
8493
|
-
import * as
|
|
8494
|
-
var logFile =
|
|
8502
|
+
import * as os2 from "node:os";
|
|
8503
|
+
import * as path2 from "node:path";
|
|
8504
|
+
var logFile = path2.join(os2.tmpdir(), "magic-context.log");
|
|
8495
8505
|
var isTestEnv = false;
|
|
8496
8506
|
var buffer = [];
|
|
8497
8507
|
var flushTimer = null;
|
|
@@ -8543,8 +8553,8 @@ var PLUGIN_NAME = "@cortexkit/opencode-magic-context";
|
|
|
8543
8553
|
var PLUGIN_ENTRY = `${PLUGIN_NAME}@latest`;
|
|
8544
8554
|
function resolveTuiConfigPath() {
|
|
8545
8555
|
const configDir = getOpenCodeConfigPaths({ binary: "opencode" }).configDir;
|
|
8546
|
-
const jsoncPath =
|
|
8547
|
-
const jsonPath =
|
|
8556
|
+
const jsoncPath = join6(configDir, "tui.jsonc");
|
|
8557
|
+
const jsonPath = join6(configDir, "tui.json");
|
|
8548
8558
|
if (existsSync4(jsoncPath))
|
|
8549
8559
|
return jsoncPath;
|
|
8550
8560
|
if (existsSync4(jsonPath))
|
|
@@ -8588,24 +8598,24 @@ function ensureTuiPluginEntry() {
|
|
|
8588
8598
|
|
|
8589
8599
|
// src/cli/config-paths.ts
|
|
8590
8600
|
import { existsSync as existsSync5 } from "node:fs";
|
|
8591
|
-
import { homedir as
|
|
8592
|
-
import { join as
|
|
8601
|
+
import { homedir as homedir4 } from "node:os";
|
|
8602
|
+
import { join as join7 } from "node:path";
|
|
8593
8603
|
function getConfigDir() {
|
|
8594
8604
|
const envDir = process.env.OPENCODE_CONFIG_DIR?.trim();
|
|
8595
8605
|
if (envDir)
|
|
8596
8606
|
return envDir;
|
|
8597
8607
|
if (process.platform === "win32") {
|
|
8598
|
-
return
|
|
8608
|
+
return join7(homedir4(), ".config", "opencode");
|
|
8599
8609
|
}
|
|
8600
|
-
const xdgConfig = process.env.XDG_CONFIG_HOME ||
|
|
8601
|
-
return
|
|
8610
|
+
const xdgConfig = process.env.XDG_CONFIG_HOME || join7(homedir4(), ".config");
|
|
8611
|
+
return join7(xdgConfig, "opencode");
|
|
8602
8612
|
}
|
|
8603
8613
|
function findOmoConfig(configDir) {
|
|
8604
8614
|
const locations = [
|
|
8605
|
-
|
|
8606
|
-
|
|
8607
|
-
|
|
8608
|
-
|
|
8615
|
+
join7(configDir, "oh-my-openagent.jsonc"),
|
|
8616
|
+
join7(configDir, "oh-my-openagent.json"),
|
|
8617
|
+
join7(configDir, "oh-my-opencode.jsonc"),
|
|
8618
|
+
join7(configDir, "oh-my-opencode.json")
|
|
8609
8619
|
];
|
|
8610
8620
|
for (const loc of locations) {
|
|
8611
8621
|
if (existsSync5(loc))
|
|
@@ -8619,8 +8629,8 @@ function detectConfigPaths() {
|
|
|
8619
8629
|
let opencodeConfigFormat;
|
|
8620
8630
|
let tuiConfig;
|
|
8621
8631
|
let tuiConfigFormat;
|
|
8622
|
-
const jsoncPath =
|
|
8623
|
-
const jsonPath =
|
|
8632
|
+
const jsoncPath = join7(configDir, "opencode.jsonc");
|
|
8633
|
+
const jsonPath = join7(configDir, "opencode.json");
|
|
8624
8634
|
if (existsSync5(jsoncPath)) {
|
|
8625
8635
|
opencodeConfig = jsoncPath;
|
|
8626
8636
|
opencodeConfigFormat = "jsonc";
|
|
@@ -8631,8 +8641,8 @@ function detectConfigPaths() {
|
|
|
8631
8641
|
opencodeConfig = jsonPath;
|
|
8632
8642
|
opencodeConfigFormat = "none";
|
|
8633
8643
|
}
|
|
8634
|
-
const tuiJsoncPath =
|
|
8635
|
-
const tuiJsonPath =
|
|
8644
|
+
const tuiJsoncPath = join7(configDir, "tui.jsonc");
|
|
8645
|
+
const tuiJsonPath = join7(configDir, "tui.json");
|
|
8636
8646
|
if (existsSync5(tuiJsoncPath)) {
|
|
8637
8647
|
tuiConfig = tuiJsoncPath;
|
|
8638
8648
|
tuiConfigFormat = "jsonc";
|
|
@@ -8647,7 +8657,7 @@ function detectConfigPaths() {
|
|
|
8647
8657
|
configDir,
|
|
8648
8658
|
opencodeConfig,
|
|
8649
8659
|
opencodeConfigFormat,
|
|
8650
|
-
magicContextConfig:
|
|
8660
|
+
magicContextConfig: join7(configDir, "magic-context.jsonc"),
|
|
8651
8661
|
omoConfig: findOmoConfig(configDir),
|
|
8652
8662
|
tuiConfig,
|
|
8653
8663
|
tuiConfigFormat
|
|
@@ -8659,8 +8669,8 @@ var import_comment_json2 = __toESM(require_src2(), 1);
|
|
|
8659
8669
|
import { Database } from "bun:sqlite";
|
|
8660
8670
|
import { existsSync as existsSync6, readdirSync, readFileSync as readFileSync4, statSync } from "node:fs";
|
|
8661
8671
|
import { createRequire as createRequire2 } from "node:module";
|
|
8662
|
-
import { homedir as
|
|
8663
|
-
import { join as
|
|
8672
|
+
import { homedir as homedir5, tmpdir as tmpdir2, userInfo } from "node:os";
|
|
8673
|
+
import { join as join8 } from "node:path";
|
|
8664
8674
|
|
|
8665
8675
|
// src/hooks/magic-context/compartment-parser.ts
|
|
8666
8676
|
var COMPARTMENT_REGEX = /<compartment\s+(?:id="[^"]*"\s+)?start="(\d+)"\s+end="(\d+)"\s+title="([^"]+)"\s*>(.*?)<\/compartment>/gs;
|
|
@@ -8800,21 +8810,11 @@ function getSelfVersion() {
|
|
|
8800
8810
|
}
|
|
8801
8811
|
return "unknown";
|
|
8802
8812
|
}
|
|
8803
|
-
function getOpenCodeCacheDir() {
|
|
8804
|
-
const xdgCache = process.env.XDG_CACHE_HOME;
|
|
8805
|
-
if (xdgCache)
|
|
8806
|
-
return join7(xdgCache, "opencode");
|
|
8807
|
-
if (process.platform === "win32") {
|
|
8808
|
-
const localAppData = process.env.LOCALAPPDATA ?? join7(homedir4(), "AppData", "Local");
|
|
8809
|
-
return join7(localAppData, "opencode");
|
|
8810
|
-
}
|
|
8811
|
-
return join7(homedir4(), ".cache", "opencode");
|
|
8812
|
-
}
|
|
8813
8813
|
function getPluginCacheInfo() {
|
|
8814
|
-
const
|
|
8814
|
+
const path3 = join8(getOpenCodeCacheDir(), "packages", PLUGIN_ENTRY_WITH_VERSION);
|
|
8815
8815
|
let cached;
|
|
8816
8816
|
try {
|
|
8817
|
-
const installedPkgPath =
|
|
8817
|
+
const installedPkgPath = join8(path3, "node_modules", "@cortexkit", "opencode-magic-context", "package.json");
|
|
8818
8818
|
if (existsSync6(installedPkgPath)) {
|
|
8819
8819
|
const pkg = JSON.parse(readFileSync4(installedPkgPath, "utf-8"));
|
|
8820
8820
|
cached = typeof pkg.version === "string" ? pkg.version : undefined;
|
|
@@ -8822,15 +8822,15 @@ function getPluginCacheInfo() {
|
|
|
8822
8822
|
} catch {
|
|
8823
8823
|
cached = undefined;
|
|
8824
8824
|
}
|
|
8825
|
-
return { path:
|
|
8825
|
+
return { path: path3, cached, latest: getSelfVersion() };
|
|
8826
8826
|
}
|
|
8827
8827
|
function getStorageDir() {
|
|
8828
|
-
const dataHome = process.env.XDG_DATA_HOME ||
|
|
8829
|
-
return
|
|
8828
|
+
const dataHome = process.env.XDG_DATA_HOME || join8(homedir5(), ".local", "share");
|
|
8829
|
+
return join8(dataHome, "opencode", "storage", "plugin", "magic-context");
|
|
8830
8830
|
}
|
|
8831
|
-
function fileSize(
|
|
8831
|
+
function fileSize(path3) {
|
|
8832
8832
|
try {
|
|
8833
|
-
return existsSync6(
|
|
8833
|
+
return existsSync6(path3) ? statSync(path3).size : 0;
|
|
8834
8834
|
} catch {
|
|
8835
8835
|
return 0;
|
|
8836
8836
|
}
|
|
@@ -8839,7 +8839,7 @@ function escapeRegex(value) {
|
|
|
8839
8839
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
8840
8840
|
}
|
|
8841
8841
|
function sanitizeString(value) {
|
|
8842
|
-
const home =
|
|
8842
|
+
const home = homedir5();
|
|
8843
8843
|
const username = userInfo().username;
|
|
8844
8844
|
let sanitized = value;
|
|
8845
8845
|
if (home) {
|
|
@@ -8863,11 +8863,11 @@ function sanitizeValue(value) {
|
|
|
8863
8863
|
}
|
|
8864
8864
|
return value;
|
|
8865
8865
|
}
|
|
8866
|
-
function readConfig2(
|
|
8867
|
-
if (!existsSync6(
|
|
8866
|
+
function readConfig2(path3) {
|
|
8867
|
+
if (!existsSync6(path3))
|
|
8868
8868
|
return { value: null };
|
|
8869
8869
|
try {
|
|
8870
|
-
const raw = readFileSync4(
|
|
8870
|
+
const raw = readFileSync4(path3, "utf-8");
|
|
8871
8871
|
const value = import_comment_json2.parse(raw);
|
|
8872
8872
|
return { value };
|
|
8873
8873
|
} catch (error) {
|
|
@@ -8888,9 +8888,9 @@ function configHasPluginEntry(config) {
|
|
|
8888
8888
|
return false;
|
|
8889
8889
|
});
|
|
8890
8890
|
}
|
|
8891
|
-
function parseHistorianDumpMeta(
|
|
8891
|
+
function parseHistorianDumpMeta(path3) {
|
|
8892
8892
|
try {
|
|
8893
|
-
const xml = readFileSync4(
|
|
8893
|
+
const xml = readFileSync4(path3, "utf-8");
|
|
8894
8894
|
const parsed = parseCompartmentOutput(xml);
|
|
8895
8895
|
const factCountByCategory = {};
|
|
8896
8896
|
for (const fact of parsed.facts) {
|
|
@@ -8923,13 +8923,13 @@ function parseHistorianDumpMeta(path2) {
|
|
|
8923
8923
|
}
|
|
8924
8924
|
}
|
|
8925
8925
|
function collectHistorianDumps() {
|
|
8926
|
-
const dir =
|
|
8926
|
+
const dir = join8(tmpdir2(), "magic-context-historian");
|
|
8927
8927
|
if (!existsSync6(dir)) {
|
|
8928
8928
|
return { dir, count: 0, recent: [] };
|
|
8929
8929
|
}
|
|
8930
8930
|
try {
|
|
8931
8931
|
const entries = readdirSync(dir).filter((name) => name.endsWith(".xml")).map((name) => {
|
|
8932
|
-
const stat = statSync(
|
|
8932
|
+
const stat = statSync(join8(dir, name));
|
|
8933
8933
|
return {
|
|
8934
8934
|
name,
|
|
8935
8935
|
mtime: stat.mtimeMs,
|
|
@@ -8938,7 +8938,7 @@ function collectHistorianDumps() {
|
|
|
8938
8938
|
}).sort((a, b) => b.mtime - a.mtime);
|
|
8939
8939
|
const now = Date.now();
|
|
8940
8940
|
const recent = entries.slice(0, 5).map((entry) => {
|
|
8941
|
-
const meta = parseHistorianDumpMeta(
|
|
8941
|
+
const meta = parseHistorianDumpMeta(join8(dir, entry.name));
|
|
8942
8942
|
const summary = {
|
|
8943
8943
|
name: entry.name,
|
|
8944
8944
|
ageMinutes: Math.round((now - entry.mtime) / 60000),
|
|
@@ -8957,7 +8957,7 @@ function collectHistorianDumps() {
|
|
|
8957
8957
|
}
|
|
8958
8958
|
}
|
|
8959
8959
|
function collectHistorianFailures(storageDirPath) {
|
|
8960
|
-
const contextDbPath =
|
|
8960
|
+
const contextDbPath = join8(storageDirPath, "context.db");
|
|
8961
8961
|
if (!existsSync6(contextDbPath))
|
|
8962
8962
|
return [];
|
|
8963
8963
|
let db = null;
|
|
@@ -8987,8 +8987,8 @@ async function collectDiagnostics() {
|
|
|
8987
8987
|
const tuiConfig = readConfig2(configPaths.tuiConfig);
|
|
8988
8988
|
const magicContextConfig = readConfig2(configPaths.magicContextConfig);
|
|
8989
8989
|
const storageDirPath = getStorageDir();
|
|
8990
|
-
const contextDbPath =
|
|
8991
|
-
const logPath =
|
|
8990
|
+
const contextDbPath = join8(storageDirPath, "context.db");
|
|
8991
|
+
const logPath = join8(tmpdir2(), "magic-context.log");
|
|
8992
8992
|
const logFileSize = existsSync6(logPath) ? statSync(logPath).size : 0;
|
|
8993
8993
|
const conflictResult = detectConflicts(process.cwd());
|
|
8994
8994
|
return {
|
|
@@ -9111,13 +9111,13 @@ function renderDiagnosticsMarkdown(report) {
|
|
|
9111
9111
|
|
|
9112
9112
|
// src/cli/logs.ts
|
|
9113
9113
|
import { readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "node:fs";
|
|
9114
|
-
import { homedir as
|
|
9115
|
-
import { join as
|
|
9114
|
+
import { homedir as homedir6, userInfo as userInfo2 } from "node:os";
|
|
9115
|
+
import { join as join9 } from "node:path";
|
|
9116
9116
|
function escapeRegex2(value) {
|
|
9117
9117
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
9118
9118
|
}
|
|
9119
9119
|
function sanitizeLogContent(content) {
|
|
9120
|
-
const home =
|
|
9120
|
+
const home = homedir6();
|
|
9121
9121
|
const username = userInfo2().username;
|
|
9122
9122
|
let sanitized = content;
|
|
9123
9123
|
if (home) {
|
|
@@ -9174,7 +9174,7 @@ async function bundleIssueReport(report, description, _title) {
|
|
|
9174
9174
|
`));
|
|
9175
9175
|
const historianFailureLines = extractHistorianFailureLines(historianScanWindow, 30);
|
|
9176
9176
|
const configBody = JSON.stringify(report.magicContextConfig.flags, null, 2);
|
|
9177
|
-
const sanitizedConfigPath = report.configPaths.magicContextConfig.replace(
|
|
9177
|
+
const sanitizedConfigPath = report.configPaths.magicContextConfig.replace(homedir6(), "~");
|
|
9178
9178
|
const bodyMarkdown = [
|
|
9179
9179
|
"## Description",
|
|
9180
9180
|
description,
|
|
@@ -9205,10 +9205,10 @@ async function bundleIssueReport(report, description, _title) {
|
|
|
9205
9205
|
"```"
|
|
9206
9206
|
].join(`
|
|
9207
9207
|
`);
|
|
9208
|
-
const
|
|
9209
|
-
writeFileSync3(
|
|
9208
|
+
const path3 = join9(process.cwd(), `magic-context-issue-${formatTimestamp(new Date)}.md`);
|
|
9209
|
+
writeFileSync3(path3, `${bodyMarkdown}
|
|
9210
9210
|
`);
|
|
9211
|
-
return { path:
|
|
9211
|
+
return { path: path3, bodyMarkdown };
|
|
9212
9212
|
}
|
|
9213
9213
|
|
|
9214
9214
|
// ../../node_modules/.bun/@clack+core@1.1.0/node_modules/@clack/core/dist/index.mjs
|
|
@@ -10323,26 +10323,15 @@ async function selectOne(message, options) {
|
|
|
10323
10323
|
// src/cli/doctor.ts
|
|
10324
10324
|
var PLUGIN_NAME3 = "@cortexkit/opencode-magic-context";
|
|
10325
10325
|
var PLUGIN_ENTRY_WITH_VERSION2 = `${PLUGIN_NAME3}@latest`;
|
|
10326
|
-
function getOpenCodeCacheDir2() {
|
|
10327
|
-
const xdgCache = process.env.XDG_CACHE_HOME;
|
|
10328
|
-
if (xdgCache)
|
|
10329
|
-
return join9(xdgCache, "opencode");
|
|
10330
|
-
const os2 = platform();
|
|
10331
|
-
if (os2 === "win32") {
|
|
10332
|
-
const localAppData = process.env.LOCALAPPDATA ?? join9(homedir6(), "AppData", "Local");
|
|
10333
|
-
return join9(localAppData, "opencode");
|
|
10334
|
-
}
|
|
10335
|
-
return join9(homedir6(), ".cache", "opencode");
|
|
10336
|
-
}
|
|
10337
10326
|
async function clearPluginCache(force = false) {
|
|
10338
|
-
const cacheDir =
|
|
10339
|
-
const pluginCacheDir =
|
|
10327
|
+
const cacheDir = getOpenCodeCacheDir();
|
|
10328
|
+
const pluginCacheDir = join10(cacheDir, "packages", PLUGIN_ENTRY_WITH_VERSION2);
|
|
10340
10329
|
if (!existsSync7(pluginCacheDir)) {
|
|
10341
10330
|
return { action: "not_found", path: pluginCacheDir };
|
|
10342
10331
|
}
|
|
10343
10332
|
let cachedVersion;
|
|
10344
10333
|
try {
|
|
10345
|
-
const installedPkgPath =
|
|
10334
|
+
const installedPkgPath = join10(pluginCacheDir, "node_modules", "@cortexkit", "opencode-magic-context", "package.json");
|
|
10346
10335
|
if (existsSync7(installedPkgPath)) {
|
|
10347
10336
|
const pkg = JSON.parse(readFileSync6(installedPkgPath, "utf-8"));
|
|
10348
10337
|
if (typeof pkg?.version === "string") {
|
|
@@ -10797,7 +10786,7 @@ async function runDoctor(options = {}) {
|
|
|
10797
10786
|
}
|
|
10798
10787
|
{
|
|
10799
10788
|
const ageWarnings = [];
|
|
10800
|
-
const npmrcPath =
|
|
10789
|
+
const npmrcPath = join10(homedir7(), ".npmrc");
|
|
10801
10790
|
if (existsSync7(npmrcPath)) {
|
|
10802
10791
|
try {
|
|
10803
10792
|
const npmrc = readFileSync6(npmrcPath, "utf-8");
|
|
@@ -10813,7 +10802,7 @@ async function runDoctor(options = {}) {
|
|
|
10813
10802
|
}
|
|
10814
10803
|
} catch {}
|
|
10815
10804
|
}
|
|
10816
|
-
const bunfigPath =
|
|
10805
|
+
const bunfigPath = join10(homedir7(), ".bunfig.toml");
|
|
10817
10806
|
if (existsSync7(bunfigPath)) {
|
|
10818
10807
|
try {
|
|
10819
10808
|
const bunfig = readFileSync6(bunfigPath, "utf-8");
|
|
@@ -10838,7 +10827,7 @@ async function runDoctor(options = {}) {
|
|
|
10838
10827
|
issues++;
|
|
10839
10828
|
}
|
|
10840
10829
|
}
|
|
10841
|
-
const logPath =
|
|
10830
|
+
const logPath = join10(tmpdir3(), "magic-context.log");
|
|
10842
10831
|
if (existsSync7(logPath)) {
|
|
10843
10832
|
const logStat = statSync2(logPath);
|
|
10844
10833
|
const sizeKb = (logStat.size / 1024).toFixed(0);
|
|
@@ -10846,12 +10835,12 @@ async function runDoctor(options = {}) {
|
|
|
10846
10835
|
} else {
|
|
10847
10836
|
R2.info(`Log file: ${logPath} (not yet created)`);
|
|
10848
10837
|
}
|
|
10849
|
-
const historianDumpDir =
|
|
10838
|
+
const historianDumpDir = join10(tmpdir3(), "magic-context-historian");
|
|
10850
10839
|
if (existsSync7(historianDumpDir)) {
|
|
10851
10840
|
try {
|
|
10852
10841
|
const dumps = readdirSync2(historianDumpDir).filter((f) => f.endsWith(".xml")).map((f) => ({
|
|
10853
10842
|
name: f,
|
|
10854
|
-
mtime: statSync2(
|
|
10843
|
+
mtime: statSync2(join10(historianDumpDir, f)).mtimeMs
|
|
10855
10844
|
})).sort((a, b) => b.mtime - a.mtime);
|
|
10856
10845
|
if (dumps.length > 0) {
|
|
10857
10846
|
R2.warn(`Historian debug dumps: ${dumps.length} file(s) in ${historianDumpDir}`);
|
|
@@ -10894,12 +10883,12 @@ function ensureDir(dir) {
|
|
|
10894
10883
|
mkdirSync3(dir, { recursive: true });
|
|
10895
10884
|
}
|
|
10896
10885
|
}
|
|
10897
|
-
function readJsonc(
|
|
10898
|
-
const content = readFileSync7(
|
|
10886
|
+
function readJsonc(path3) {
|
|
10887
|
+
const content = readFileSync7(path3, "utf-8");
|
|
10899
10888
|
try {
|
|
10900
10889
|
return import_comment_json4.parse(content);
|
|
10901
10890
|
} catch (err) {
|
|
10902
|
-
console.error(` ⚠ Failed to parse ${
|
|
10891
|
+
console.error(` ⚠ Failed to parse ${path3}: ${err instanceof Error ? err.message : err}`);
|
|
10903
10892
|
return null;
|
|
10904
10893
|
}
|
|
10905
10894
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-definition token measurement store.
|
|
3
|
+
*
|
|
4
|
+
* OpenCode's `tool.definition` hook fires once per tool per
|
|
5
|
+
* `ToolRegistry.tools()` call, with `{ toolID }` as input and
|
|
6
|
+
* `{ description, parameters }` as output. Crucially the hook input does NOT
|
|
7
|
+
* carry `sessionID` — the tool set is computed per
|
|
8
|
+
* `{providerID, modelID, agent}` combination, independent of session.
|
|
9
|
+
*
|
|
10
|
+
* We measure each tool's description + JSON-schema parameters, tokenize with
|
|
11
|
+
* the same Claude tokenizer used everywhere else in the plugin, and store
|
|
12
|
+
* per-tool totals keyed by `${providerID}/${modelID}/${agentName}`. Inner map
|
|
13
|
+
* keys on `toolID` so every hook fire idempotently overwrites its own slot
|
|
14
|
+
* (same tool set on each turn → same key → same measured total).
|
|
15
|
+
*
|
|
16
|
+
* Consumers (RPC sidebar/status handlers) look up the active session's
|
|
17
|
+
* measurement via `getMeasuredToolDefinitionTokens(providerID, modelID,
|
|
18
|
+
* agentName)`. Returns `undefined` when the key has never been measured — the
|
|
19
|
+
* caller is expected to fall back to residual math or show zero.
|
|
20
|
+
*
|
|
21
|
+
* The store lives entirely in-memory. A process restart re-measures on the
|
|
22
|
+
* first turn, which is essentially free; persisting these values across
|
|
23
|
+
* restarts would add schema/migration cost for no user-visible benefit.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Tokenize a single tool's schema and store it under the given key. Called
|
|
27
|
+
* from the `tool.definition` plugin hook once per tool per flight. Same
|
|
28
|
+
* toolID on a later flight overwrites its slot — the total for the key stays
|
|
29
|
+
* consistent even if descriptions or parameters drift between turns.
|
|
30
|
+
*/
|
|
31
|
+
export declare function recordToolDefinition(providerID: string, modelID: string, agentName: string | undefined, toolID: string, description: string, parameters: unknown): void;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the summed measured tokens for a `{provider, model, agent}` key,
|
|
34
|
+
* or `undefined` when never measured (e.g. fresh session before first turn).
|
|
35
|
+
*/
|
|
36
|
+
export declare function getMeasuredToolDefinitionTokens(providerID: string, modelID: string, agentName: string | undefined): number | undefined;
|
|
37
|
+
/** Test helper: reset the store so suites don't leak measurements. */
|
|
38
|
+
export declare function __resetToolDefinitionMeasurements(): void;
|
|
39
|
+
/** Inspection helper: snapshot the current store (for debug logging/tests). */
|
|
40
|
+
export declare function getToolDefinitionSnapshot(): Array<{
|
|
41
|
+
key: string;
|
|
42
|
+
totalTokens: number;
|
|
43
|
+
toolCount: number;
|
|
44
|
+
}>;
|
|
45
|
+
//# sourceMappingURL=tool-definition-tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-definition-tokens.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/tool-definition-tokens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAaH;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAChC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,OAAO,GACpB,IAAI,CA0BN;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAC3C,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAAG,SAAS,GAC9B,MAAM,GAAG,SAAS,CAOpB;AAED,sEAAsE;AACtE,wBAAgB,iCAAiC,IAAI,IAAI,CAExD;AAED,+EAA+E;AAC/E,wBAAgB,yBAAyB,IAAI,KAAK,CAAC;IAC/C,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACrB,CAAC,CAMD"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AA6BlD,QAAA,MAAM,MAAM,EAAE,MAsUb,CAAC;AAEF,eAAe,MAAM,CAAC"}
|