@cortexkit/magic-context 0.42.3 → 0.42.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +385 -330
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -13147,6 +13147,8 @@ var init_jsonc_config = __esm(() => {
|
|
|
13147
13147
|
});
|
|
13148
13148
|
|
|
13149
13149
|
// src/lib/pi-package-entry.ts
|
|
13150
|
+
import { existsSync as existsSync10, readFileSync as readFileSync7 } from "node:fs";
|
|
13151
|
+
import { isAbsolute as isAbsolute4, join as join10 } from "node:path";
|
|
13150
13152
|
function stripNpmPrefix(value) {
|
|
13151
13153
|
return value.startsWith("npm:") ? value.slice("npm:".length) : value;
|
|
13152
13154
|
}
|
|
@@ -13197,8 +13199,31 @@ function getPiMagicContextPackageSpecifier(entry) {
|
|
|
13197
13199
|
}
|
|
13198
13200
|
return null;
|
|
13199
13201
|
}
|
|
13200
|
-
function hasPiMagicContextPackage(entries) {
|
|
13201
|
-
return entries.some(
|
|
13202
|
+
function hasPiMagicContextPackage(entries, agentDir = getPiAgentConfigDir()) {
|
|
13203
|
+
return entries.some((entry) => isConfiguredPiMagicContextEntry(entry, agentDir));
|
|
13204
|
+
}
|
|
13205
|
+
function isPiMagicContextPackageDir(dir) {
|
|
13206
|
+
const packageJson = join10(dir, "package.json");
|
|
13207
|
+
if (!existsSync10(packageJson))
|
|
13208
|
+
return false;
|
|
13209
|
+
try {
|
|
13210
|
+
const pkg = JSON.parse(readFileSync7(packageJson, "utf-8"));
|
|
13211
|
+
return typeof pkg.name === "string" && pkg.name === PI_MAGIC_CONTEXT_PACKAGE_NAME;
|
|
13212
|
+
} catch {
|
|
13213
|
+
return false;
|
|
13214
|
+
}
|
|
13215
|
+
}
|
|
13216
|
+
function localPiMagicContextPackageDir(entry, agentDir) {
|
|
13217
|
+
const source = typeof entry === "string" ? entry : entry && typeof entry === "object" && ("source" in entry) ? entry.source : null;
|
|
13218
|
+
const spec = typeof source === "string" ? source.trim() : "";
|
|
13219
|
+
if (!spec || spec.startsWith("npm:"))
|
|
13220
|
+
return null;
|
|
13221
|
+
const path = spec.startsWith("file:") ? spec.slice("file:".length) : spec;
|
|
13222
|
+
const dir = isAbsolute4(path) ? path : join10(agentDir, path);
|
|
13223
|
+
return isPiMagicContextPackageDir(dir) ? dir : null;
|
|
13224
|
+
}
|
|
13225
|
+
function isConfiguredPiMagicContextEntry(entry, agentDir) {
|
|
13226
|
+
return isPiMagicContextPackageEntry(entry) || localPiMagicContextPackageDir(entry, agentDir) !== null;
|
|
13202
13227
|
}
|
|
13203
13228
|
function describePiPackageEntry(entry) {
|
|
13204
13229
|
if (typeof entry === "string")
|
|
@@ -13213,9 +13238,12 @@ function describePiPackageEntry(entry) {
|
|
|
13213
13238
|
}
|
|
13214
13239
|
}
|
|
13215
13240
|
var PI_MAGIC_CONTEXT_PACKAGE_NAME = "@cortexkit/pi-magic-context";
|
|
13241
|
+
var init_pi_package_entry = __esm(() => {
|
|
13242
|
+
init_paths();
|
|
13243
|
+
});
|
|
13216
13244
|
|
|
13217
13245
|
// src/adapters/pi.ts
|
|
13218
|
-
import { existsSync as
|
|
13246
|
+
import { existsSync as existsSync11 } from "node:fs";
|
|
13219
13247
|
import { dirname as dirname5 } from "node:path";
|
|
13220
13248
|
|
|
13221
13249
|
class PiAdapter {
|
|
@@ -13230,7 +13258,8 @@ class PiAdapter {
|
|
|
13230
13258
|
if (!settings)
|
|
13231
13259
|
return false;
|
|
13232
13260
|
const packages = settings.packages ?? [];
|
|
13233
|
-
|
|
13261
|
+
const agentDir = getPiAgentConfigDir();
|
|
13262
|
+
return packages.some((entry) => isConfiguredPiMagicContextEntry(entry, agentDir));
|
|
13234
13263
|
}
|
|
13235
13264
|
getConfigPaths() {
|
|
13236
13265
|
const dir = getPiAgentConfigDir();
|
|
@@ -13246,7 +13275,8 @@ class PiAdapter {
|
|
|
13246
13275
|
try {
|
|
13247
13276
|
const settings = readPiSettingsForUpdate();
|
|
13248
13277
|
const packages = Array.isArray(settings.packages) ? settings.packages : [];
|
|
13249
|
-
const
|
|
13278
|
+
const agentDir = getPiAgentConfigDir();
|
|
13279
|
+
const idx = packages.findIndex((entry) => isConfiguredPiMagicContextEntry(entry, agentDir));
|
|
13250
13280
|
if (idx === -1) {
|
|
13251
13281
|
packages.push(PI_PACKAGE_SOURCE);
|
|
13252
13282
|
settings.packages = packages;
|
|
@@ -13352,7 +13382,7 @@ function writePiSettings(settings) {
|
|
|
13352
13382
|
}
|
|
13353
13383
|
function ensureDir2(filePath) {
|
|
13354
13384
|
const dir = dirname5(filePath);
|
|
13355
|
-
if (!
|
|
13385
|
+
if (!existsSync11(dir)) {
|
|
13356
13386
|
const { mkdirSync } = __require("node:fs");
|
|
13357
13387
|
mkdirSync(dir, { recursive: true });
|
|
13358
13388
|
}
|
|
@@ -13363,6 +13393,7 @@ var init_pi = __esm(() => {
|
|
|
13363
13393
|
init_jsonc_config();
|
|
13364
13394
|
init_paths();
|
|
13365
13395
|
init_pi_helpers();
|
|
13396
|
+
init_pi_package_entry();
|
|
13366
13397
|
import_comment_json3 = __toESM(require_src3(), 1);
|
|
13367
13398
|
});
|
|
13368
13399
|
|
|
@@ -13481,16 +13512,16 @@ var init_harness_provider_map = __esm(() => {
|
|
|
13481
13512
|
// ../plugin/src/config/raw-loader.ts
|
|
13482
13513
|
import {
|
|
13483
13514
|
closeSync as closeSync2,
|
|
13484
|
-
existsSync as
|
|
13515
|
+
existsSync as existsSync12,
|
|
13485
13516
|
linkSync,
|
|
13486
13517
|
openSync as openSync2,
|
|
13487
|
-
readFileSync as
|
|
13518
|
+
readFileSync as readFileSync8,
|
|
13488
13519
|
renameSync as renameSync3,
|
|
13489
13520
|
statSync as statSync6,
|
|
13490
13521
|
unlinkSync as unlinkSync2,
|
|
13491
13522
|
writeFileSync as writeFileSync3
|
|
13492
13523
|
} from "node:fs";
|
|
13493
|
-
import { basename as basename2, dirname as dirname6, join as
|
|
13524
|
+
import { basename as basename2, dirname as dirname6, join as join11 } from "node:path";
|
|
13494
13525
|
function isRecord(value) {
|
|
13495
13526
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13496
13527
|
}
|
|
@@ -13684,7 +13715,7 @@ function writeExclusiveBackup(backupPath, bytes, mode) {
|
|
|
13684
13715
|
if (error.code !== "EEXIST")
|
|
13685
13716
|
throw error;
|
|
13686
13717
|
}
|
|
13687
|
-
const existingBytes =
|
|
13718
|
+
const existingBytes = readFileSync8(backupPath);
|
|
13688
13719
|
if (existingBytes.equals(bytes))
|
|
13689
13720
|
return;
|
|
13690
13721
|
if (bytes.subarray(0, existingBytes.length).equals(existingBytes)) {
|
|
@@ -13702,7 +13733,7 @@ function writeTemporaryCandidate(configPath, bytes, mode) {
|
|
|
13702
13733
|
const stem = basename2(configPath);
|
|
13703
13734
|
for (let attempt = 0;attempt < 32; attempt++) {
|
|
13704
13735
|
temporaryFileSequence += 1;
|
|
13705
|
-
const path =
|
|
13736
|
+
const path = join11(directory, `.${stem}.per-harness-${process.pid}-${temporaryFileSequence}.tmp`);
|
|
13706
13737
|
let descriptor;
|
|
13707
13738
|
try {
|
|
13708
13739
|
descriptor = openSync2(path, "wx", mode);
|
|
@@ -13728,11 +13759,11 @@ function migrationWarning(diagnostic) {
|
|
|
13728
13759
|
return diagnostic.message;
|
|
13729
13760
|
}
|
|
13730
13761
|
function loadRawConfigFile(options) {
|
|
13731
|
-
if (!
|
|
13762
|
+
if (!existsSync12(options.configPath))
|
|
13732
13763
|
return null;
|
|
13733
13764
|
let observedBytes;
|
|
13734
13765
|
try {
|
|
13735
|
-
observedBytes =
|
|
13766
|
+
observedBytes = readFileSync8(options.configPath);
|
|
13736
13767
|
} catch (error) {
|
|
13737
13768
|
throw new Error(`failed to read config: ${error instanceof Error ? error.message : String(error)}`);
|
|
13738
13769
|
}
|
|
@@ -13776,7 +13807,7 @@ function loadRawConfigFile(options) {
|
|
|
13776
13807
|
writeExclusiveBackup(backupPath, observedBytes, mode);
|
|
13777
13808
|
temporaryPath = writeTemporaryCandidate(options.configPath, migration.bytes, mode);
|
|
13778
13809
|
options.afterTemporaryWrite?.();
|
|
13779
|
-
const currentBytes =
|
|
13810
|
+
const currentBytes = readFileSync8(options.configPath);
|
|
13780
13811
|
if (!hasFlatKeys(currentBytes)) {
|
|
13781
13812
|
unlinkSync2(temporaryPath);
|
|
13782
13813
|
return {
|
|
@@ -14148,10 +14179,10 @@ var init_dreamer_setup = __esm(() => {
|
|
|
14148
14179
|
});
|
|
14149
14180
|
|
|
14150
14181
|
// src/commands/setup-pi.ts
|
|
14151
|
-
import { existsSync as
|
|
14182
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync3 } from "node:fs";
|
|
14152
14183
|
import { dirname as dirname7 } from "node:path";
|
|
14153
14184
|
function ensureDir3(path) {
|
|
14154
|
-
if (!
|
|
14185
|
+
if (!existsSync13(path))
|
|
14155
14186
|
mkdirSync3(path, { recursive: true });
|
|
14156
14187
|
}
|
|
14157
14188
|
async function getDefaultPrompts() {
|
|
@@ -14457,6 +14488,7 @@ var init_setup_pi = __esm(() => {
|
|
|
14457
14488
|
init_model_picker();
|
|
14458
14489
|
init_paths();
|
|
14459
14490
|
init_pi_helpers();
|
|
14491
|
+
init_pi_package_entry();
|
|
14460
14492
|
import_comment_json4 = __toESM(require_src3(), 1);
|
|
14461
14493
|
DEFAULT_ENV = {
|
|
14462
14494
|
detectPiBinary,
|
|
@@ -21506,9 +21538,9 @@ function resolveTransformMode(args) {
|
|
|
21506
21538
|
var RUST_COMPACTION_OFF_WARNING = "compaction-off mode does not support rust transform mode; using the TypeScript transform.", RUST_REQUIRES_USER_SUBC_WARNING = "rust mode requires user-level subc configuration; running ts.";
|
|
21507
21539
|
|
|
21508
21540
|
// ../plugin/src/config/variable.ts
|
|
21509
|
-
import { existsSync as
|
|
21541
|
+
import { existsSync as existsSync14, readFileSync as readFileSync9 } from "node:fs";
|
|
21510
21542
|
import { homedir as homedir9 } from "node:os";
|
|
21511
|
-
import { dirname as dirname9, isAbsolute as
|
|
21543
|
+
import { dirname as dirname9, isAbsolute as isAbsolute5, resolve as resolve4 } from "node:path";
|
|
21512
21544
|
function sensitiveFilePathReason(resolvedPath) {
|
|
21513
21545
|
const home = homedir9();
|
|
21514
21546
|
const sensitiveDirs = [
|
|
@@ -21574,20 +21606,20 @@ function substituteConfigVariables(input) {
|
|
|
21574
21606
|
let filePath = rawPath.trim();
|
|
21575
21607
|
if (filePath.startsWith("~/")) {
|
|
21576
21608
|
filePath = resolve4(homedir9(), filePath.slice(2));
|
|
21577
|
-
} else if (!
|
|
21609
|
+
} else if (!isAbsolute5(filePath)) {
|
|
21578
21610
|
filePath = resolve4(configDir, filePath);
|
|
21579
21611
|
}
|
|
21580
21612
|
const sensitiveReason = sensitiveFilePathReason(filePath);
|
|
21581
21613
|
if (sensitiveReason) {
|
|
21582
21614
|
warnings.push(`${token} resolves to a sensitive path (${sensitiveReason}: ${filePath}); ` + "inlining its contents into config — make sure this is intentional.");
|
|
21583
21615
|
}
|
|
21584
|
-
if (!
|
|
21616
|
+
if (!existsSync14(filePath)) {
|
|
21585
21617
|
warnings.push(`File not found for ${token} (resolved to ${filePath}); using empty string`);
|
|
21586
21618
|
continue;
|
|
21587
21619
|
}
|
|
21588
21620
|
let contents;
|
|
21589
21621
|
try {
|
|
21590
|
-
contents =
|
|
21622
|
+
contents = readFileSync9(filePath, "utf-8").trim();
|
|
21591
21623
|
} catch (error) {
|
|
21592
21624
|
const message = error instanceof Error ? error.message : String(error);
|
|
21593
21625
|
warnings.push(`Failed to read file for ${token} (${filePath}): ${message}; using empty string`);
|
|
@@ -21606,7 +21638,7 @@ var init_variable = __esm(() => {
|
|
|
21606
21638
|
});
|
|
21607
21639
|
|
|
21608
21640
|
// ../plugin/src/config/index.ts
|
|
21609
|
-
import { existsSync as
|
|
21641
|
+
import { existsSync as existsSync15 } from "node:fs";
|
|
21610
21642
|
function getUserConfigBasePath() {
|
|
21611
21643
|
return cortexKitUserConfigBasePath();
|
|
21612
21644
|
}
|
|
@@ -21614,10 +21646,10 @@ function getProjectConfigBasePath(directory) {
|
|
|
21614
21646
|
return cortexKitProjectConfigBasePath(directory);
|
|
21615
21647
|
}
|
|
21616
21648
|
function resolveLegacyReadFallback(sources) {
|
|
21617
|
-
return { source: sources.find((s) =>
|
|
21649
|
+
return { source: sources.find((s) => existsSync15(s.path)) ?? null };
|
|
21618
21650
|
}
|
|
21619
21651
|
function loadConfigFileDetailed(configPath, source) {
|
|
21620
|
-
if (!
|
|
21652
|
+
if (!existsSync15(configPath)) {
|
|
21621
21653
|
return null;
|
|
21622
21654
|
}
|
|
21623
21655
|
let rawText;
|
|
@@ -21922,8 +21954,8 @@ function loadPluginConfigDetailed(directory) {
|
|
|
21922
21954
|
const harnessLegacy = resolveLegacyConfigSourcesForHarness(directory, "opencode");
|
|
21923
21955
|
const userLegacyFallback = userDetected.format === "none" ? resolveLegacyReadFallback(harnessLegacy.user) : { source: null };
|
|
21924
21956
|
const projectLegacyFallback = projectDetected.format === "none" ? resolveLegacyReadFallback(harnessLegacy.project) : { source: null };
|
|
21925
|
-
const legacyUserUnmigrated = userDetected.format === "none" && !userLegacyFallback.source && legacySources.user.some((source) =>
|
|
21926
|
-
const legacyProjectUnmigrated = projectDetected.format === "none" && !projectLegacyFallback.source && legacySources.project.some((source) =>
|
|
21957
|
+
const legacyUserUnmigrated = userDetected.format === "none" && !userLegacyFallback.source && legacySources.user.some((source) => existsSync15(source.path));
|
|
21958
|
+
const legacyProjectUnmigrated = projectDetected.format === "none" && !projectLegacyFallback.source && legacySources.project.some((source) => existsSync15(source.path));
|
|
21927
21959
|
const userLoaded = userDetected.format !== "none" ? loadConfigFileDetailed(userDetected.path, "user") : userLegacyFallback.source ? loadConfigFileDetailed(userLegacyFallback.source.path, "user") : null;
|
|
21928
21960
|
const projectLoaded = projectDetected.format !== "none" ? loadConfigFileDetailed(projectDetected.path, "project") : projectLegacyFallback.source ? loadConfigFileDetailed(projectLegacyFallback.source.path, "project") : null;
|
|
21929
21961
|
const allWarnings = [];
|
|
@@ -22059,16 +22091,16 @@ var init_config = __esm(() => {
|
|
|
22059
22091
|
|
|
22060
22092
|
// ../plugin/src/shared/opencode-config-dir.ts
|
|
22061
22093
|
import { homedir as homedir10 } from "node:os";
|
|
22062
|
-
import { join as
|
|
22094
|
+
import { join as join12, resolve as resolve5 } from "node:path";
|
|
22063
22095
|
function getCliConfigDir() {
|
|
22064
22096
|
const envConfigDir = process.env.OPENCODE_CONFIG_DIR?.trim();
|
|
22065
22097
|
if (envConfigDir) {
|
|
22066
22098
|
return resolve5(envConfigDir);
|
|
22067
22099
|
}
|
|
22068
22100
|
if (process.platform === "win32") {
|
|
22069
|
-
return
|
|
22101
|
+
return join12(homedir10(), ".config", "opencode");
|
|
22070
22102
|
}
|
|
22071
|
-
return
|
|
22103
|
+
return join12(process.env.XDG_CONFIG_HOME || join12(homedir10(), ".config"), "opencode");
|
|
22072
22104
|
}
|
|
22073
22105
|
function getOpenCodeConfigDir2(_options) {
|
|
22074
22106
|
return getCliConfigDir();
|
|
@@ -22077,17 +22109,17 @@ function getOpenCodeConfigPaths(options) {
|
|
|
22077
22109
|
const configDir = getOpenCodeConfigDir2(options);
|
|
22078
22110
|
return {
|
|
22079
22111
|
configDir,
|
|
22080
|
-
configJson:
|
|
22081
|
-
configJsonc:
|
|
22082
|
-
packageJson:
|
|
22083
|
-
omoConfig:
|
|
22112
|
+
configJson: join12(configDir, "opencode.json"),
|
|
22113
|
+
configJsonc: join12(configDir, "opencode.jsonc"),
|
|
22114
|
+
packageJson: join12(configDir, "package.json"),
|
|
22115
|
+
omoConfig: join12(configDir, "magic-context.jsonc")
|
|
22084
22116
|
};
|
|
22085
22117
|
}
|
|
22086
22118
|
var init_opencode_config_dir = () => {};
|
|
22087
22119
|
|
|
22088
22120
|
// ../plugin/src/shared/conflict-detector.ts
|
|
22089
22121
|
import { homedir as homedir11 } from "node:os";
|
|
22090
|
-
import { join as
|
|
22122
|
+
import { join as join13 } from "node:path";
|
|
22091
22123
|
function detectConflicts(directory, options) {
|
|
22092
22124
|
const compactionEnabled = options?.compactionEnabled ?? true;
|
|
22093
22125
|
const conflicts = {
|
|
@@ -22149,8 +22181,8 @@ function checkCompaction(directory) {
|
|
|
22149
22181
|
return { auto: true, prune: false };
|
|
22150
22182
|
}
|
|
22151
22183
|
function readProjectCompaction(directory) {
|
|
22152
|
-
const dotOcJsonc =
|
|
22153
|
-
const dotOcJson =
|
|
22184
|
+
const dotOcJsonc = join13(directory, ".opencode", "opencode.jsonc");
|
|
22185
|
+
const dotOcJson = join13(directory, ".opencode", "opencode.json");
|
|
22154
22186
|
const dotOcConfig = readJsoncFile(dotOcJsonc) ?? readJsoncFile(dotOcJson);
|
|
22155
22187
|
if (dotOcConfig?.compaction) {
|
|
22156
22188
|
const c = dotOcConfig.compaction;
|
|
@@ -22158,8 +22190,8 @@ function readProjectCompaction(directory) {
|
|
|
22158
22190
|
return { auto: c.auto === true, prune: c.prune === true, resolved: true };
|
|
22159
22191
|
}
|
|
22160
22192
|
}
|
|
22161
|
-
const rootJsonc =
|
|
22162
|
-
const rootJson =
|
|
22193
|
+
const rootJsonc = join13(directory, "opencode.jsonc");
|
|
22194
|
+
const rootJson = join13(directory, "opencode.json");
|
|
22163
22195
|
const rootConfig = readJsoncFile(rootJsonc) ?? readJsoncFile(rootJson);
|
|
22164
22196
|
if (rootConfig?.compaction) {
|
|
22165
22197
|
const c = rootConfig.compaction;
|
|
@@ -22213,10 +22245,10 @@ function collectPluginEntries(directory) {
|
|
|
22213
22245
|
}
|
|
22214
22246
|
};
|
|
22215
22247
|
for (const configPath of [
|
|
22216
|
-
|
|
22217
|
-
|
|
22218
|
-
|
|
22219
|
-
|
|
22248
|
+
join13(directory, ".opencode", "opencode.jsonc"),
|
|
22249
|
+
join13(directory, ".opencode", "opencode.json"),
|
|
22250
|
+
join13(directory, "opencode.jsonc"),
|
|
22251
|
+
join13(directory, "opencode.json")
|
|
22220
22252
|
]) {
|
|
22221
22253
|
const config = readJsoncFile(configPath);
|
|
22222
22254
|
pushFrom(config?.plugin);
|
|
@@ -22257,7 +22289,7 @@ function readOmoDisabledHooks(directory) {
|
|
|
22257
22289
|
try {
|
|
22258
22290
|
const paths = getOpenCodeConfigPaths({ binary: "opencode" });
|
|
22259
22291
|
for (const name of configNames) {
|
|
22260
|
-
const configPath =
|
|
22292
|
+
const configPath = join13(paths.configDir, name);
|
|
22261
22293
|
const config = readJsoncFile(configPath);
|
|
22262
22294
|
if (config?.disabled_hooks) {
|
|
22263
22295
|
for (const hook of config.disabled_hooks) {
|
|
@@ -22267,7 +22299,7 @@ function readOmoDisabledHooks(directory) {
|
|
|
22267
22299
|
}
|
|
22268
22300
|
} catch {}
|
|
22269
22301
|
for (const name of configNames) {
|
|
22270
|
-
const config = readJsoncFile(
|
|
22302
|
+
const config = readJsoncFile(join13(directory, name));
|
|
22271
22303
|
if (config?.disabled_hooks) {
|
|
22272
22304
|
for (const hook of config.disabled_hooks) {
|
|
22273
22305
|
disabled.add(hook);
|
|
@@ -22275,9 +22307,9 @@ function readOmoDisabledHooks(directory) {
|
|
|
22275
22307
|
}
|
|
22276
22308
|
}
|
|
22277
22309
|
const homeDir = process.env.HOME || homedir11();
|
|
22278
|
-
const omoHomeDir =
|
|
22310
|
+
const omoHomeDir = join13(homeDir, ".omo");
|
|
22279
22311
|
for (const name of ["omo.jsonc", "omo.json"]) {
|
|
22280
|
-
const config = readJsoncFile(
|
|
22312
|
+
const config = readJsoncFile(join13(omoHomeDir, name));
|
|
22281
22313
|
if (config?.["[opencode]"]?.disabled_hooks) {
|
|
22282
22314
|
for (const hook of config["[opencode]"].disabled_hooks) {
|
|
22283
22315
|
disabled.add(hook);
|
|
@@ -22285,7 +22317,7 @@ function readOmoDisabledHooks(directory) {
|
|
|
22285
22317
|
}
|
|
22286
22318
|
}
|
|
22287
22319
|
for (const name of ["omo.jsonc", "omo.json"]) {
|
|
22288
|
-
const config = readJsoncFile(
|
|
22320
|
+
const config = readJsoncFile(join13(directory, ".omo", name));
|
|
22289
22321
|
if (config?.["[opencode]"]?.disabled_hooks) {
|
|
22290
22322
|
for (const hook of config["[opencode]"].disabled_hooks) {
|
|
22291
22323
|
disabled.add(hook);
|
|
@@ -22304,9 +22336,9 @@ var init_conflict_detector = __esm(() => {
|
|
|
22304
22336
|
});
|
|
22305
22337
|
|
|
22306
22338
|
// ../plugin/src/shared/conflict-fixer.ts
|
|
22307
|
-
import { existsSync as
|
|
22339
|
+
import { existsSync as existsSync16, readFileSync as readFileSync10, writeFileSync as writeFileSync4 } from "node:fs";
|
|
22308
22340
|
import { homedir as homedir12 } from "node:os";
|
|
22309
|
-
import { join as
|
|
22341
|
+
import { join as join14 } from "node:path";
|
|
22310
22342
|
function isRecord2(value) {
|
|
22311
22343
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22312
22344
|
}
|
|
@@ -22314,11 +22346,11 @@ function asStringArray(value) {
|
|
|
22314
22346
|
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
22315
22347
|
}
|
|
22316
22348
|
function readConfig(filePath) {
|
|
22317
|
-
if (!
|
|
22349
|
+
if (!existsSync16(filePath)) {
|
|
22318
22350
|
return null;
|
|
22319
22351
|
}
|
|
22320
22352
|
try {
|
|
22321
|
-
const text =
|
|
22353
|
+
const text = readFileSync10(filePath, "utf-8");
|
|
22322
22354
|
const parsed = import_comment_json5.parse(text);
|
|
22323
22355
|
return isRecord2(parsed) ? { config: parsed, text } : null;
|
|
22324
22356
|
} catch {
|
|
@@ -22330,23 +22362,23 @@ function writeConfig(filePath, text) {
|
|
|
22330
22362
|
}
|
|
22331
22363
|
function resolveUserOpenCodeConfigPath() {
|
|
22332
22364
|
const paths = getOpenCodeConfigPaths({ binary: "opencode" });
|
|
22333
|
-
if (
|
|
22365
|
+
if (existsSync16(paths.configJsonc))
|
|
22334
22366
|
return paths.configJsonc;
|
|
22335
22367
|
return paths.configJson;
|
|
22336
22368
|
}
|
|
22337
22369
|
function collectOpenCodeConfigPaths(directory) {
|
|
22338
22370
|
const paths = new Set;
|
|
22339
22371
|
const userConfig = resolveUserOpenCodeConfigPath();
|
|
22340
|
-
if (
|
|
22372
|
+
if (existsSync16(userConfig)) {
|
|
22341
22373
|
paths.add(userConfig);
|
|
22342
22374
|
}
|
|
22343
22375
|
for (const filePath of [
|
|
22344
|
-
|
|
22345
|
-
|
|
22346
|
-
|
|
22347
|
-
|
|
22376
|
+
join14(directory, ".opencode", "opencode.jsonc"),
|
|
22377
|
+
join14(directory, ".opencode", "opencode.json"),
|
|
22378
|
+
join14(directory, "opencode.jsonc"),
|
|
22379
|
+
join14(directory, "opencode.json")
|
|
22348
22380
|
]) {
|
|
22349
|
-
if (
|
|
22381
|
+
if (existsSync16(filePath)) {
|
|
22350
22382
|
paths.add(filePath);
|
|
22351
22383
|
}
|
|
22352
22384
|
}
|
|
@@ -22356,26 +22388,26 @@ function collectOmoConfigPaths(directory) {
|
|
|
22356
22388
|
const paths = new Set;
|
|
22357
22389
|
const configDir = getOpenCodeConfigPaths({ binary: "opencode" }).configDir;
|
|
22358
22390
|
for (const fileName of OMO_CONFIG_NAMES) {
|
|
22359
|
-
const userPath =
|
|
22360
|
-
const projectPath =
|
|
22361
|
-
if (
|
|
22391
|
+
const userPath = join14(configDir, fileName);
|
|
22392
|
+
const projectPath = join14(directory, fileName);
|
|
22393
|
+
if (existsSync16(userPath)) {
|
|
22362
22394
|
paths.add(userPath);
|
|
22363
22395
|
}
|
|
22364
|
-
if (
|
|
22396
|
+
if (existsSync16(projectPath)) {
|
|
22365
22397
|
paths.add(projectPath);
|
|
22366
22398
|
}
|
|
22367
22399
|
}
|
|
22368
22400
|
const homeDir = process.env.HOME || homedir12();
|
|
22369
|
-
const omoHomeDir =
|
|
22401
|
+
const omoHomeDir = join14(homeDir, ".omo");
|
|
22370
22402
|
for (const name of OMO_UNIFIED_NAMES) {
|
|
22371
|
-
const userPath =
|
|
22372
|
-
if (
|
|
22403
|
+
const userPath = join14(omoHomeDir, name);
|
|
22404
|
+
if (existsSync16(userPath)) {
|
|
22373
22405
|
paths.add(userPath);
|
|
22374
22406
|
}
|
|
22375
22407
|
}
|
|
22376
22408
|
for (const name of OMO_UNIFIED_NAMES) {
|
|
22377
|
-
const projectPath =
|
|
22378
|
-
if (
|
|
22409
|
+
const projectPath = join14(directory, ".omo", name);
|
|
22410
|
+
if (existsSync16(projectPath)) {
|
|
22379
22411
|
paths.add(projectPath);
|
|
22380
22412
|
}
|
|
22381
22413
|
}
|
|
@@ -22557,7 +22589,7 @@ var OPENCODE_BINARY_ENV = "MAGIC_CONTEXT_OPENCODE_BINARY", OPENCODE_VERSION_PROB
|
|
|
22557
22589
|
var init_opencode_helpers = () => {};
|
|
22558
22590
|
|
|
22559
22591
|
// src/commands/setup-opencode.ts
|
|
22560
|
-
import { existsSync as
|
|
22592
|
+
import { existsSync as existsSync17, mkdirSync as mkdirSync5, readFileSync as readFileSync11 } from "node:fs";
|
|
22561
22593
|
import { basename as basename3, dirname as dirname10 } from "node:path";
|
|
22562
22594
|
function resolveCompactionEnabledForWriter() {
|
|
22563
22595
|
try {
|
|
@@ -22569,7 +22601,7 @@ function resolveCompactionEnabledForWriter() {
|
|
|
22569
22601
|
}
|
|
22570
22602
|
}
|
|
22571
22603
|
function ensureDir5(dir) {
|
|
22572
|
-
if (!
|
|
22604
|
+
if (!existsSync17(dir)) {
|
|
22573
22605
|
mkdirSync5(dir, { recursive: true });
|
|
22574
22606
|
}
|
|
22575
22607
|
}
|
|
@@ -22597,7 +22629,7 @@ function readMagicContextConfigForSetup2(configPath) {
|
|
|
22597
22629
|
}
|
|
22598
22630
|
}
|
|
22599
22631
|
function addPluginToOpenCodeConfig(configPath, _format, removeDcp = false, compactionEnabled = true) {
|
|
22600
|
-
const existsAtCommit =
|
|
22632
|
+
const existsAtCommit = existsSync17(configPath);
|
|
22601
22633
|
const existing = existsAtCommit ? readJsoncConfigForUpdate(configPath) : {};
|
|
22602
22634
|
if (!existsAtCommit) {
|
|
22603
22635
|
ensureDir5(dirname10(configPath));
|
|
@@ -22609,7 +22641,7 @@ function addPluginToOpenCodeConfig(configPath, _format, removeDcp = false, compa
|
|
|
22609
22641
|
`);
|
|
22610
22642
|
return;
|
|
22611
22643
|
}
|
|
22612
|
-
let text =
|
|
22644
|
+
let text = readFileSync11(configPath, "utf-8");
|
|
22613
22645
|
let changed = false;
|
|
22614
22646
|
const rawPlugins = Array.isArray(existing.plugin) ? existing.plugin : [];
|
|
22615
22647
|
const retainedPlugins = removeDcp ? rawPlugins.filter((plugin) => !matchesPluginEntry(plugin, DCP_PLUGIN_NAME)) : rawPlugins;
|
|
@@ -22656,7 +22688,7 @@ function addPluginToOpenCodeConfig(configPath, _format, removeDcp = false, compa
|
|
|
22656
22688
|
writeFileAtomic(configPath, text);
|
|
22657
22689
|
}
|
|
22658
22690
|
function addPluginToTuiConfig(configPath, _format) {
|
|
22659
|
-
const existsAtCommit =
|
|
22691
|
+
const existsAtCommit = existsSync17(configPath);
|
|
22660
22692
|
const existing = existsAtCommit ? readJsoncConfigForUpdate(configPath) : {};
|
|
22661
22693
|
if (!existsAtCommit) {
|
|
22662
22694
|
ensureDir5(dirname10(configPath));
|
|
@@ -22672,7 +22704,7 @@ function addPluginToTuiConfig(configPath, _format) {
|
|
|
22672
22704
|
const hasDevEntry = rawPlugins.some((plugin) => isDevPathPluginEntry(plugin));
|
|
22673
22705
|
if (hasNpmEntry || hasDevEntry)
|
|
22674
22706
|
return;
|
|
22675
|
-
const text = Array.isArray(existing.plugin) ? appendJsoncArrayValues(
|
|
22707
|
+
const text = Array.isArray(existing.plugin) ? appendJsoncArrayValues(readFileSync11(configPath, "utf-8"), ["plugin"], [OPENCODE_PLUGIN_ENTRY_WITH_VERSION]) : setJsoncValue(readFileSync11(configPath, "utf-8"), ["plugin"], [OPENCODE_PLUGIN_ENTRY_WITH_VERSION]);
|
|
22676
22708
|
writeFileAtomic(configPath, text);
|
|
22677
22709
|
}
|
|
22678
22710
|
function findDcpPluginIndexes(plugins) {
|
|
@@ -22780,7 +22812,7 @@ async function runSetup3(dryRun = false) {
|
|
|
22780
22812
|
log2.warn("You can configure models manually in magic-context.jsonc later");
|
|
22781
22813
|
}
|
|
22782
22814
|
const paths = detectConfigPaths();
|
|
22783
|
-
const hadExistingSetup = paths.opencodeConfigFormat !== "none" ||
|
|
22815
|
+
const hadExistingSetup = paths.opencodeConfigFormat !== "none" || existsSync17(paths.magicContextConfig) || paths.tuiConfigFormat !== "none";
|
|
22784
22816
|
if (!dryRun) {
|
|
22785
22817
|
try {
|
|
22786
22818
|
assertJsoncConfigsParseable([
|
|
@@ -23261,6 +23293,11 @@ async function drainAuthority(args) {
|
|
|
23261
23293
|
if (finished.state !== "TS") {
|
|
23262
23294
|
throw new Error("memory authority drain did not reactivate TypeScript ownership");
|
|
23263
23295
|
}
|
|
23296
|
+
if (args.domain === "memories") {
|
|
23297
|
+
withPrivilegedWriter(args.db, () => {
|
|
23298
|
+
args.db.prepare("DELETE FROM mirror_live_memory_rows WHERE module_project = ?").run(args.projectPath);
|
|
23299
|
+
});
|
|
23300
|
+
}
|
|
23264
23301
|
const remaining = await Promise.all(AUTHORITY_DOMAINS.map((domain) => args.module.authorityStatus({
|
|
23265
23302
|
context_store_uuid: contextStoreUuid,
|
|
23266
23303
|
project: args.projectPath,
|
|
@@ -24043,7 +24080,7 @@ var init_context_authority = __esm(async () => {
|
|
|
24043
24080
|
// ../plugin/src/features/magic-context/memory/project-identity.ts
|
|
24044
24081
|
import { execFileSync as execFileSync3 } from "node:child_process";
|
|
24045
24082
|
import { createHash as createHash2 } from "node:crypto";
|
|
24046
|
-
import { existsSync as
|
|
24083
|
+
import { existsSync as existsSync18, realpathSync as realpathSync2, statSync as statSync8 } from "node:fs";
|
|
24047
24084
|
import path3 from "node:path";
|
|
24048
24085
|
function asError(error) {
|
|
24049
24086
|
return error instanceof Error ? error : undefined;
|
|
@@ -24281,7 +24318,7 @@ function hasGitDir(canonical) {
|
|
|
24281
24318
|
function gitRootInAncestorChain(startDirectory) {
|
|
24282
24319
|
let current = startDirectory;
|
|
24283
24320
|
while (true) {
|
|
24284
|
-
if (
|
|
24321
|
+
if (existsSync18(path3.join(current, ".git"))) {
|
|
24285
24322
|
try {
|
|
24286
24323
|
return realpathSync2.native(current);
|
|
24287
24324
|
} catch {
|
|
@@ -25960,9 +25997,9 @@ function isRecord3(value) {
|
|
|
25960
25997
|
|
|
25961
25998
|
// ../plugin/src/hooks/magic-context/module-transport.ts
|
|
25962
25999
|
import { realpathSync as realpathSync3 } from "node:fs";
|
|
25963
|
-
import { join as
|
|
25964
|
-
function
|
|
25965
|
-
return
|
|
26000
|
+
import { join as join15 } from "node:path";
|
|
26001
|
+
function getDefaultSubcConnectionFile() {
|
|
26002
|
+
return join15(getDataDir(), "cortexkit", "run", "subc-connection.json");
|
|
25966
26003
|
}
|
|
25967
26004
|
function errorChainSome(error, predicate) {
|
|
25968
26005
|
let current = error;
|
|
@@ -26073,7 +26110,7 @@ class SubcModuleTransport {
|
|
|
26073
26110
|
return capabilities;
|
|
26074
26111
|
}
|
|
26075
26112
|
constructor(connectionFile, moduleId = DEFAULT_MODULE_ID, requestTimeoutMs = MODULE_SEND_TIMEOUT_MS, routeSessionPrefix = "") {
|
|
26076
|
-
this.connectionFile = connectionFile
|
|
26113
|
+
this.connectionFile = connectionFile;
|
|
26077
26114
|
this.moduleId = moduleId;
|
|
26078
26115
|
this.requestTimeoutMs = requestTimeoutMs;
|
|
26079
26116
|
this.routeSessionPrefix = routeSessionPrefix;
|
|
@@ -26351,8 +26388,8 @@ class SubcModuleTransport {
|
|
|
26351
26388
|
}
|
|
26352
26389
|
async authorityStatus(args) {
|
|
26353
26390
|
this.authorityProjectRoot = args.project;
|
|
26354
|
-
const { projectRoot, ...body } = args;
|
|
26355
|
-
const response = await this.authorityRequest(args.project, projectRoot ?? this.bindRootForAuthority(), "authority.status", body);
|
|
26391
|
+
const { projectRoot, sessionId, ...body } = args;
|
|
26392
|
+
const response = await this.authorityRequest(sessionId ?? args.project, projectRoot ?? this.bindRootForAuthority(), "authority.status", body);
|
|
26356
26393
|
return { authority: response.authority ?? null };
|
|
26357
26394
|
}
|
|
26358
26395
|
async authorityPrepare(args) {
|
|
@@ -26599,7 +26636,7 @@ var init_pi_executable = __esm(() => {
|
|
|
26599
26636
|
|
|
26600
26637
|
// ../plugin/src/shared/rpc-utils.ts
|
|
26601
26638
|
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
26602
|
-
import { readFileSync as
|
|
26639
|
+
import { readFileSync as readFileSync12 } from "node:fs";
|
|
26603
26640
|
function isPidAlive(pid) {
|
|
26604
26641
|
if (!Number.isInteger(pid) || pid <= 0)
|
|
26605
26642
|
return "dead";
|
|
@@ -27135,7 +27172,7 @@ var init_rpc_utils = __esm(() => {
|
|
|
27135
27172
|
"cljs/dist",
|
|
27136
27173
|
"dist/bundle/cli"
|
|
27137
27174
|
];
|
|
27138
|
-
rpcIdentityReadFileSync =
|
|
27175
|
+
rpcIdentityReadFileSync = readFileSync12;
|
|
27139
27176
|
rpcIdentityExecFileSync = execFileSync4;
|
|
27140
27177
|
rpcIdentityProcessKill = process.kill;
|
|
27141
27178
|
rpcProcessListExecFileSync = execFileSync4;
|
|
@@ -30014,11 +30051,11 @@ var init_tool_definition_tokens = __esm(() => {
|
|
|
30014
30051
|
});
|
|
30015
30052
|
|
|
30016
30053
|
// ../plugin/src/shared/opencode-db-path.ts
|
|
30017
|
-
import { existsSync as
|
|
30054
|
+
import { existsSync as existsSync19, readdirSync as readdirSync2, statSync as statSync9 } from "node:fs";
|
|
30018
30055
|
import { homedir as homedir13 } from "node:os";
|
|
30019
|
-
import { isAbsolute as
|
|
30056
|
+
import { isAbsolute as isAbsolute6, join as join16 } from "node:path";
|
|
30020
30057
|
function openCodeDataDir() {
|
|
30021
|
-
return
|
|
30058
|
+
return join16(process.env.XDG_DATA_HOME ?? join16(homedir13(), ".local", "share"), "opencode");
|
|
30022
30059
|
}
|
|
30023
30060
|
function environmentKey(dataDir) {
|
|
30024
30061
|
return [
|
|
@@ -30029,7 +30066,7 @@ function environmentKey(dataDir) {
|
|
|
30029
30066
|
].join("\x00");
|
|
30030
30067
|
}
|
|
30031
30068
|
function channelPath(dataDir, channel) {
|
|
30032
|
-
return ["latest", "beta", "prod"].includes(channel) ?
|
|
30069
|
+
return ["latest", "beta", "prod"].includes(channel) ? join16(dataDir, "opencode.db") : join16(dataDir, `opencode-${channel}.db`);
|
|
30033
30070
|
}
|
|
30034
30071
|
function discoveredCandidateNames(dataDir) {
|
|
30035
30072
|
const names = ["opencode.db", "opencode-local.db", "opencode-dev.db"];
|
|
@@ -30041,7 +30078,7 @@ function discoveredCandidateNames(dataDir) {
|
|
|
30041
30078
|
}
|
|
30042
30079
|
function discoverOpenCodeDb(dataDir) {
|
|
30043
30080
|
const candidates = discoveredCandidateNames(dataDir).map((name, order) => {
|
|
30044
|
-
const path =
|
|
30081
|
+
const path = join16(dataDir, name);
|
|
30045
30082
|
try {
|
|
30046
30083
|
const metadata = statSync9(path);
|
|
30047
30084
|
return metadata.isFile() ? { path, order, mtimeMs: metadata.mtimeMs } : null;
|
|
@@ -30051,7 +30088,7 @@ function discoverOpenCodeDb(dataDir) {
|
|
|
30051
30088
|
});
|
|
30052
30089
|
const existing = candidates.filter((candidate) => candidate !== null).sort((left, right) => right.mtimeMs - left.mtimeMs || left.order - right.order)[0];
|
|
30053
30090
|
if (!existing) {
|
|
30054
|
-
return { path:
|
|
30091
|
+
return { path: join16(dataDir, "opencode.db"), source: "default", channel: null };
|
|
30055
30092
|
}
|
|
30056
30093
|
const name = existing.path.slice(dataDir.length + 1);
|
|
30057
30094
|
const channel = name === "opencode.db" ? null : name.slice("opencode-".length, -".db".length) || null;
|
|
@@ -30064,14 +30101,14 @@ function resolveFresh(dataDir) {
|
|
|
30064
30101
|
return { path: explicit, source: "OPENCODE_DB", channel: null };
|
|
30065
30102
|
}
|
|
30066
30103
|
return {
|
|
30067
|
-
path:
|
|
30104
|
+
path: isAbsolute6(explicit) ? explicit : join16(dataDir, explicit),
|
|
30068
30105
|
source: "OPENCODE_DB",
|
|
30069
30106
|
channel: null
|
|
30070
30107
|
};
|
|
30071
30108
|
}
|
|
30072
30109
|
const disableChannelDb = process.env.OPENCODE_DISABLE_CHANNEL_DB;
|
|
30073
30110
|
if (disableChannelDb === "1" || disableChannelDb === "true") {
|
|
30074
|
-
return { path:
|
|
30111
|
+
return { path: join16(dataDir, "opencode.db"), source: "default", channel: null };
|
|
30075
30112
|
}
|
|
30076
30113
|
const channel = process.env.OPENCODE_CHANNEL;
|
|
30077
30114
|
if (channel !== undefined && channel.length > 0) {
|
|
@@ -30082,7 +30119,7 @@ function resolveFresh(dataDir) {
|
|
|
30082
30119
|
function resolveOpenCodeDbPath() {
|
|
30083
30120
|
const dataDir = openCodeDataDir();
|
|
30084
30121
|
const key = environmentKey(dataDir);
|
|
30085
|
-
if (cachedResolution?.key === key && (!cachedResolution.existed ||
|
|
30122
|
+
if (cachedResolution?.key === key && (!cachedResolution.existed || existsSync19(cachedResolution.resolution.path))) {
|
|
30086
30123
|
if (cachedResolution.existed)
|
|
30087
30124
|
return cachedResolution.resolution;
|
|
30088
30125
|
}
|
|
@@ -30090,12 +30127,12 @@ function resolveOpenCodeDbPath() {
|
|
|
30090
30127
|
cachedResolution = {
|
|
30091
30128
|
key,
|
|
30092
30129
|
resolution,
|
|
30093
|
-
existed: resolution.path !== ":memory:" &&
|
|
30130
|
+
existed: resolution.path !== ":memory:" && existsSync19(resolution.path)
|
|
30094
30131
|
};
|
|
30095
30132
|
return resolution;
|
|
30096
30133
|
}
|
|
30097
30134
|
function openCodeDbPathExists(resolution = resolveOpenCodeDbPath()) {
|
|
30098
|
-
return resolution.path !== ":memory:" &&
|
|
30135
|
+
return resolution.path !== ":memory:" && existsSync19(resolution.path);
|
|
30099
30136
|
}
|
|
30100
30137
|
function getOpenCodeDbProbeDescriptions(resolution = resolveOpenCodeDbPath()) {
|
|
30101
30138
|
if (resolution.source === "OPENCODE_DB")
|
|
@@ -30105,10 +30142,10 @@ function getOpenCodeDbProbeDescriptions(resolution = resolveOpenCodeDbPath()) {
|
|
|
30105
30142
|
}
|
|
30106
30143
|
const dataDir = openCodeDataDir();
|
|
30107
30144
|
return [
|
|
30108
|
-
|
|
30109
|
-
|
|
30110
|
-
|
|
30111
|
-
|
|
30145
|
+
join16(dataDir, "opencode.db"),
|
|
30146
|
+
join16(dataDir, "opencode-local.db"),
|
|
30147
|
+
join16(dataDir, "opencode-dev.db"),
|
|
30148
|
+
join16(dataDir, "opencode-<channel>.db")
|
|
30112
30149
|
];
|
|
30113
30150
|
}
|
|
30114
30151
|
function lookedForText(resolution) {
|
|
@@ -30136,14 +30173,14 @@ import {
|
|
|
30136
30173
|
chmodSync as chmodSync3,
|
|
30137
30174
|
copyFileSync,
|
|
30138
30175
|
cpSync,
|
|
30139
|
-
existsSync as
|
|
30176
|
+
existsSync as existsSync20,
|
|
30140
30177
|
mkdirSync as mkdirSync6,
|
|
30141
30178
|
readdirSync as readdirSync3,
|
|
30142
|
-
readFileSync as
|
|
30179
|
+
readFileSync as readFileSync13,
|
|
30143
30180
|
statSync as statSync10,
|
|
30144
30181
|
unlinkSync as unlinkSync3
|
|
30145
30182
|
} from "node:fs";
|
|
30146
|
-
import { basename as basename4, dirname as dirname11, join as
|
|
30183
|
+
import { basename as basename4, dirname as dirname11, join as join17, resolve as resolve6 } from "node:path";
|
|
30147
30184
|
function resolveBootBusyTimeoutMs(value) {
|
|
30148
30185
|
if (value === undefined)
|
|
30149
30186
|
return BOOT_SQLITE_BUSY_TIMEOUT_MS;
|
|
@@ -30223,7 +30260,7 @@ function classifyJunkDiscovery(portFile, raw, staleFiles) {
|
|
|
30223
30260
|
return null;
|
|
30224
30261
|
}
|
|
30225
30262
|
function inspectRpcServerDiscovery(storageDir) {
|
|
30226
|
-
const rpcRoot =
|
|
30263
|
+
const rpcRoot = join17(storageDir, "rpc");
|
|
30227
30264
|
let projectEntries;
|
|
30228
30265
|
try {
|
|
30229
30266
|
projectEntries = rpcDiscoveryFs.readdirSync(rpcRoot, { withFileTypes: true });
|
|
@@ -30237,7 +30274,7 @@ function inspectRpcServerDiscovery(storageDir) {
|
|
|
30237
30274
|
for (const projectEntry of projectEntries) {
|
|
30238
30275
|
if (!projectEntry.isDirectory())
|
|
30239
30276
|
continue;
|
|
30240
|
-
const projectDir =
|
|
30277
|
+
const projectDir = join17(rpcRoot, projectEntry.name);
|
|
30241
30278
|
let entries;
|
|
30242
30279
|
try {
|
|
30243
30280
|
entries = rpcDiscoveryFs.readdirSync(projectDir);
|
|
@@ -30248,7 +30285,7 @@ function inspectRpcServerDiscovery(storageDir) {
|
|
|
30248
30285
|
}
|
|
30249
30286
|
for (const entry of entries) {
|
|
30250
30287
|
if (entry === "port" || entry.startsWith("port-") && entry.endsWith(".json")) {
|
|
30251
|
-
portFiles.push(
|
|
30288
|
+
portFiles.push(join17(projectDir, entry));
|
|
30252
30289
|
}
|
|
30253
30290
|
}
|
|
30254
30291
|
}
|
|
@@ -31514,7 +31551,7 @@ var init_storage_db = __esm(async () => {
|
|
|
31514
31551
|
RPC_DISCOVERY_PARSE_GRACE_MS = 10 * 60 * 1000;
|
|
31515
31552
|
defaultRpcDiscoveryFs = {
|
|
31516
31553
|
readdirSync: (path, options) => options?.withFileTypes ? readdirSync3(path, { withFileTypes: true }) : readdirSync3(path),
|
|
31517
|
-
readFileSync: (path, encoding) => String(
|
|
31554
|
+
readFileSync: (path, encoding) => String(readFileSync13(path, encoding)),
|
|
31518
31555
|
statSync: (path) => ({ mtimeMs: statSync10(path).mtimeMs }),
|
|
31519
31556
|
unlinkSync: (path) => unlinkSync3(path)
|
|
31520
31557
|
};
|
|
@@ -31527,13 +31564,13 @@ var init_storage_db = __esm(async () => {
|
|
|
31527
31564
|
});
|
|
31528
31565
|
|
|
31529
31566
|
// src/lib/database-access.ts
|
|
31530
|
-
import { existsSync as
|
|
31567
|
+
import { existsSync as existsSync21, writeFileSync as writeFileSync5 } from "node:fs";
|
|
31531
31568
|
import { pathToFileURL } from "node:url";
|
|
31532
31569
|
function getPersistedSchemaVersion2(db) {
|
|
31533
31570
|
return getPersistedSchemaVersion(db);
|
|
31534
31571
|
}
|
|
31535
31572
|
function openExistingDatabase(path, options) {
|
|
31536
|
-
if (!
|
|
31573
|
+
if (!existsSync21(path))
|
|
31537
31574
|
return null;
|
|
31538
31575
|
if (options.readonly) {
|
|
31539
31576
|
const db = new Database(path, { readonly: true });
|
|
@@ -31691,7 +31728,8 @@ async function reportAuthorityMarkers(args) {
|
|
|
31691
31728
|
try {
|
|
31692
31729
|
currentIdentity = resolveProjectIdentity(process.cwd());
|
|
31693
31730
|
} catch {}
|
|
31694
|
-
const
|
|
31731
|
+
const loaded = loadPluginConfig(process.cwd());
|
|
31732
|
+
const transport = new SubcModuleTransport(loaded.subc?.connection_file ?? getDefaultSubcConnectionFile());
|
|
31695
31733
|
for (const marker of markers) {
|
|
31696
31734
|
if (marker.project_path !== currentIdentity) {
|
|
31697
31735
|
args.warn(` ${marker.project_path}: module state unavailable outside its project root — writes fenced; run with rust mode or restore subc connectivity`);
|
|
@@ -31722,7 +31760,8 @@ async function runDoctorDrainAuthority(projectRoot, dbPath) {
|
|
|
31722
31760
|
console.log(`No authority_managed marker exists for ${projectPath}.`);
|
|
31723
31761
|
return 0;
|
|
31724
31762
|
}
|
|
31725
|
-
const
|
|
31763
|
+
const loaded = loadPluginConfig(projectRoot);
|
|
31764
|
+
const module = authorityClient(new SubcModuleTransport(loaded.subc?.connection_file ?? getDefaultSubcConnectionFile()), projectRoot);
|
|
31726
31765
|
let drainedAny = false;
|
|
31727
31766
|
for (const domain of AUTHORITY_DOMAINS) {
|
|
31728
31767
|
const status = await module.authorityStatus({
|
|
@@ -31769,6 +31808,7 @@ async function runDoctorDrainAuthority(projectRoot, dbPath) {
|
|
|
31769
31808
|
}
|
|
31770
31809
|
}
|
|
31771
31810
|
var init_doctor_authority = __esm(async () => {
|
|
31811
|
+
init_config();
|
|
31772
31812
|
init_project_identity();
|
|
31773
31813
|
init_storage_project_state();
|
|
31774
31814
|
init_module_transport();
|
|
@@ -32060,7 +32100,7 @@ var init_storage_identity_merge = __esm(() => {
|
|
|
32060
32100
|
});
|
|
32061
32101
|
|
|
32062
32102
|
// src/commands/doctor-merge-identity.ts
|
|
32063
|
-
import { join as
|
|
32103
|
+
import { join as join18 } from "node:path";
|
|
32064
32104
|
function valueAfter(args, flag) {
|
|
32065
32105
|
const index = args.indexOf(flag);
|
|
32066
32106
|
if (index < 0)
|
|
@@ -32122,7 +32162,7 @@ function runMergeIdentityCli(args) {
|
|
|
32122
32162
|
console.error("Refusing to mutate context.db without explicit --yes. Re-run with --yes, or use --dry-run to preview.");
|
|
32123
32163
|
return 2;
|
|
32124
32164
|
}
|
|
32125
|
-
const dbPath = options.dbPath ??
|
|
32165
|
+
const dbPath = options.dbPath ?? join18(getMagicContextStorageDir(), "context.db");
|
|
32126
32166
|
const db = openMergeDatabase(dbPath, !options.dryRun);
|
|
32127
32167
|
try {
|
|
32128
32168
|
const report = mergeProjectIdentities(db, options.from, options.to, {
|
|
@@ -32147,13 +32187,13 @@ import {
|
|
|
32147
32187
|
closeSync as closeSync4,
|
|
32148
32188
|
constants as constants2,
|
|
32149
32189
|
copyFileSync as copyFileSync2,
|
|
32150
|
-
existsSync as
|
|
32190
|
+
existsSync as existsSync22,
|
|
32151
32191
|
openSync as openSync4,
|
|
32152
32192
|
renameSync as renameSync4,
|
|
32153
32193
|
rmSync as rmSync2,
|
|
32154
32194
|
statSync as statSync11
|
|
32155
32195
|
} from "node:fs";
|
|
32156
|
-
import { dirname as dirname12, join as
|
|
32196
|
+
import { dirname as dirname12, join as join19 } from "node:path";
|
|
32157
32197
|
function defaultInspectHolders(storageDir) {
|
|
32158
32198
|
const rpc = inspectRpcServerDiscovery(storageDir);
|
|
32159
32199
|
if (rpc.state === "unreadable") {
|
|
@@ -32161,7 +32201,7 @@ function defaultInspectHolders(storageDir) {
|
|
|
32161
32201
|
return {
|
|
32162
32202
|
safe: false,
|
|
32163
32203
|
blockers: [],
|
|
32164
|
-
uncertainty: `RPC discovery ${rpc.unreadableFile ??
|
|
32204
|
+
uncertainty: `RPC discovery ${rpc.unreadableFile ?? join19(storageDir, "rpc")} ${arm}`
|
|
32165
32205
|
};
|
|
32166
32206
|
}
|
|
32167
32207
|
const blockers = rpc.state === "live" ? rpc.serverPids.map((pid) => `OpenCode server (PID ${pid})`) : [];
|
|
@@ -32183,11 +32223,11 @@ function timestamp(date) {
|
|
|
32183
32223
|
return date.toISOString().replaceAll("-", "").replaceAll(":", "").replace(".", "");
|
|
32184
32224
|
}
|
|
32185
32225
|
function uniqueBase(preferred) {
|
|
32186
|
-
if (!DATABASE_SUFFIXES.some((suffix) =>
|
|
32226
|
+
if (!DATABASE_SUFFIXES.some((suffix) => existsSync22(`${preferred}${suffix}`)))
|
|
32187
32227
|
return preferred;
|
|
32188
32228
|
for (let attempt = 1;attempt < 1e4; attempt++) {
|
|
32189
32229
|
const candidate = `${preferred}-${attempt}`;
|
|
32190
|
-
if (!DATABASE_SUFFIXES.some((suffix) =>
|
|
32230
|
+
if (!DATABASE_SUFFIXES.some((suffix) => existsSync22(`${candidate}${suffix}`)))
|
|
32191
32231
|
return candidate;
|
|
32192
32232
|
}
|
|
32193
32233
|
throw new Error(`Could not allocate a unique recovery path beside ${preferred}`);
|
|
@@ -32201,7 +32241,7 @@ function copyDatabaseBundle(sourceBase, destinationBase) {
|
|
|
32201
32241
|
const copiedPaths = [];
|
|
32202
32242
|
for (const suffix of DATABASE_SUFFIXES) {
|
|
32203
32243
|
const source = `${sourceBase}${suffix}`;
|
|
32204
|
-
if (!
|
|
32244
|
+
if (!existsSync22(source))
|
|
32205
32245
|
continue;
|
|
32206
32246
|
const destination = `${destinationBase}${suffix}`;
|
|
32207
32247
|
copyFileSync2(source, destination, constants2.COPYFILE_EXCL);
|
|
@@ -32401,7 +32441,7 @@ function activateReplacement(dbPath, replacementPath, originalAsidePath) {
|
|
|
32401
32441
|
try {
|
|
32402
32442
|
for (const suffix of DATABASE_SUFFIXES) {
|
|
32403
32443
|
const from = `${dbPath}${suffix}`;
|
|
32404
|
-
if (!
|
|
32444
|
+
if (!existsSync22(from))
|
|
32405
32445
|
continue;
|
|
32406
32446
|
const to = `${originalAsidePath}${suffix}`;
|
|
32407
32447
|
renameSync4(from, to);
|
|
@@ -32411,7 +32451,7 @@ function activateReplacement(dbPath, replacementPath, originalAsidePath) {
|
|
|
32411
32451
|
return movedOriginals.map(({ to }) => to);
|
|
32412
32452
|
} catch (error) {
|
|
32413
32453
|
for (const moved of movedOriginals.reverse()) {
|
|
32414
|
-
if (
|
|
32454
|
+
if (existsSync22(moved.to) && !existsSync22(moved.from))
|
|
32415
32455
|
renameSync4(moved.to, moved.from);
|
|
32416
32456
|
}
|
|
32417
32457
|
throw error;
|
|
@@ -32442,12 +32482,12 @@ function printHelp() {
|
|
|
32442
32482
|
async function runRepairDb(options = {}) {
|
|
32443
32483
|
const prompts = options.prompts ?? promptIO;
|
|
32444
32484
|
const deps = { ...DEFAULT_DEPS3, ...options.deps };
|
|
32445
|
-
const storageDir = options.storageDir ?? dirname12(options.dbPath ??
|
|
32446
|
-
const dbPath = options.dbPath ??
|
|
32485
|
+
const storageDir = options.storageDir ?? dirname12(options.dbPath ?? join19(getMagicContextStorageDir(), "context.db"));
|
|
32486
|
+
const dbPath = options.dbPath ?? join19(storageDir, "context.db");
|
|
32447
32487
|
const stamp = timestamp(deps.now());
|
|
32448
32488
|
prompts.intro("Magic Context — Repair shared database");
|
|
32449
32489
|
prompts.log.info(`Database: ${dbPath}`);
|
|
32450
|
-
if (!
|
|
32490
|
+
if (!existsSync22(dbPath)) {
|
|
32451
32491
|
prompts.log.error(`Database not found: ${dbPath}`);
|
|
32452
32492
|
prompts.log.info("Backup: not created (database does not exist)");
|
|
32453
32493
|
prompts.outro("Database repair failed");
|
|
@@ -32659,19 +32699,19 @@ var init_migration_paths = __esm(() => {
|
|
|
32659
32699
|
|
|
32660
32700
|
// src/commands/migrate.ts
|
|
32661
32701
|
import { createHash as createHash4, randomBytes as randomBytes2 } from "node:crypto";
|
|
32662
|
-
import { existsSync as
|
|
32663
|
-
import { dirname as dirname13, join as
|
|
32702
|
+
import { existsSync as existsSync23, mkdirSync as mkdirSync7, renameSync as renameSync5, unlinkSync as unlinkSync4 } from "node:fs";
|
|
32703
|
+
import { dirname as dirname13, join as join20 } from "node:path";
|
|
32664
32704
|
function defaultOpenCodeDbPath() {
|
|
32665
32705
|
return getOpenCodeDatabasePath();
|
|
32666
32706
|
}
|
|
32667
32707
|
function defaultCortexkitDbPath() {
|
|
32668
|
-
return
|
|
32708
|
+
return join20(getMagicContextStorageDir(), "context.db");
|
|
32669
32709
|
}
|
|
32670
32710
|
function defaultPiSessionsRoot() {
|
|
32671
32711
|
return getPiSessionsRoot();
|
|
32672
32712
|
}
|
|
32673
32713
|
function defaultFs() {
|
|
32674
|
-
return { writeFileAtomic, unlinkSync: unlinkSync4, existsSync:
|
|
32714
|
+
return { writeFileAtomic, unlinkSync: unlinkSync4, existsSync: existsSync23, renameSync: renameSync5, mkdirSync: mkdirSync7 };
|
|
32675
32715
|
}
|
|
32676
32716
|
function stmt(db, sql) {
|
|
32677
32717
|
return db.prepare(sql);
|
|
@@ -32767,7 +32807,7 @@ function claimJournalIdentity(args) {
|
|
|
32767
32807
|
migration_key, source_session_id, target_harness, pi_session_id,
|
|
32768
32808
|
final_path, stage_path, content_sha256, phase, created_at
|
|
32769
32809
|
) VALUES (?, ?, ?, ?, ?, ?, '', 'staged', ?)
|
|
32770
|
-
ON CONFLICT(migration_key) DO NOTHING`).run(args.migrationKey, args.sourceSessionId, args.targetHarness, piSessionId, args.finalPathFor(piSessionId),
|
|
32810
|
+
ON CONFLICT(migration_key) DO NOTHING`).run(args.migrationKey, args.sourceSessionId, args.targetHarness, piSessionId, args.finalPathFor(piSessionId), join20(args.stageDir, `${args.migrationKey}.jsonl`), args.now);
|
|
32771
32811
|
const row = readPendingMigration(args.db, args.migrationKey);
|
|
32772
32812
|
if (!row) {
|
|
32773
32813
|
throw new Error("migration journal row disappeared during insert; aborting migration");
|
|
@@ -33271,7 +33311,7 @@ function migrateOpenCodeSessionToPi(opts) {
|
|
|
33271
33311
|
const provider = opts.provider ?? model.provider;
|
|
33272
33312
|
const modelId = opts.modelId ?? model.modelId;
|
|
33273
33313
|
const cwd = session.directory ?? session.path ?? process.cwd();
|
|
33274
|
-
const outputDir =
|
|
33314
|
+
const outputDir = join20(piSessionsRoot, projectPathToPiDirSlug(cwd));
|
|
33275
33315
|
const targetHarness = opts.targetHarness ?? "pi";
|
|
33276
33316
|
const moduleManagedProject = cortexkitDb === null ? null : moduleManagedProjectForSession(cortexkitDb, session.id);
|
|
33277
33317
|
if (moduleManagedProject) {
|
|
@@ -33295,8 +33335,8 @@ function migrateOpenCodeSessionToPi(opts) {
|
|
|
33295
33335
|
migrationKey,
|
|
33296
33336
|
sourceSessionId: session.id,
|
|
33297
33337
|
targetHarness,
|
|
33298
|
-
finalPathFor: (id) =>
|
|
33299
|
-
stageDir:
|
|
33338
|
+
finalPathFor: (id) => join20(outputDir, `${formatPiFilenameTimestamp(now)}_${id}.jsonl`),
|
|
33339
|
+
stageDir: join20(dirname13(piSessionsRoot), MIGRATION_STAGE_DIRNAME),
|
|
33300
33340
|
now: now.getTime()
|
|
33301
33341
|
});
|
|
33302
33342
|
piSessionId = claimed.row.pi_session_id;
|
|
@@ -33305,7 +33345,7 @@ function migrateOpenCodeSessionToPi(opts) {
|
|
|
33305
33345
|
journalResumed = claimed.resumed;
|
|
33306
33346
|
} else {
|
|
33307
33347
|
piSessionId = generateUuidV7(now);
|
|
33308
|
-
finalPath =
|
|
33348
|
+
finalPath = join20(outputDir, `${formatPiFilenameTimestamp(now)}_${piSessionId}.jsonl`);
|
|
33309
33349
|
stagePath = "";
|
|
33310
33350
|
}
|
|
33311
33351
|
const buildResult = buildPiEntries({
|
|
@@ -33617,9 +33657,9 @@ var init_relocate_memory = __esm(() => {
|
|
|
33617
33657
|
});
|
|
33618
33658
|
|
|
33619
33659
|
// src/commands/migrate-session.ts
|
|
33620
|
-
import { existsSync as
|
|
33660
|
+
import { existsSync as existsSync24, realpathSync as realpathSync4 } from "node:fs";
|
|
33621
33661
|
import { homedir as homedir14 } from "node:os";
|
|
33622
|
-
import path4, { join as
|
|
33662
|
+
import path4, { join as join21 } from "node:path";
|
|
33623
33663
|
function existingSessionColumns(db) {
|
|
33624
33664
|
const rows = db.prepare("PRAGMA table_info(session)").all();
|
|
33625
33665
|
return new Set(rows.map((r) => r.name).filter((n) => typeof n === "string"));
|
|
@@ -33829,14 +33869,14 @@ function defaultOpenCodeDbPath2() {
|
|
|
33829
33869
|
return getOpenCodeDatabasePath();
|
|
33830
33870
|
}
|
|
33831
33871
|
function defaultContextDbPath() {
|
|
33832
|
-
return
|
|
33872
|
+
return join21(getMagicContextStorageDir(), "context.db");
|
|
33833
33873
|
}
|
|
33834
33874
|
function realDeps(opencodeDb, contextDb) {
|
|
33835
33875
|
return {
|
|
33836
33876
|
opencodeDb,
|
|
33837
33877
|
contextDb,
|
|
33838
33878
|
resolveIdentity: resolveProjectIdentity,
|
|
33839
|
-
hasGitDir: (dir) =>
|
|
33879
|
+
hasGitDir: (dir) => existsSync24(join21(dir, ".git")),
|
|
33840
33880
|
realpath: (p) => realpathSync4(p)
|
|
33841
33881
|
};
|
|
33842
33882
|
}
|
|
@@ -33914,8 +33954,8 @@ async function runMigrateSessionCli(args) {
|
|
|
33914
33954
|
printMigrateSessionHelp();
|
|
33915
33955
|
return 1;
|
|
33916
33956
|
}
|
|
33917
|
-
const expandedTo = toDir.startsWith("~") ?
|
|
33918
|
-
if (!
|
|
33957
|
+
const expandedTo = toDir.startsWith("~") ? join21(homedir14(), toDir.slice(1).replace(/^[/\\]/, "")) : toDir;
|
|
33958
|
+
if (!existsSync24(expandedTo)) {
|
|
33919
33959
|
console.error(`Target directory does not exist: ${expandedTo}`);
|
|
33920
33960
|
return 1;
|
|
33921
33961
|
}
|
|
@@ -33941,7 +33981,8 @@ async function runMigrateSessionCli(args) {
|
|
|
33941
33981
|
} catch {}
|
|
33942
33982
|
const deps = realDeps(opencodeDb, contextDb);
|
|
33943
33983
|
const plan = planMigrateSession(sessionId, expandedTo, deps);
|
|
33944
|
-
const
|
|
33984
|
+
const loaded = loadPluginConfig(plan.currentDirectory ?? plan.targetDirectory);
|
|
33985
|
+
const transport = new SubcModuleTransport(loaded.subc?.connection_file ?? getDefaultSubcConnectionFile());
|
|
33945
33986
|
const safety = await assertMigrateSessionIsSafeToRehome({
|
|
33946
33987
|
plan,
|
|
33947
33988
|
contextDb,
|
|
@@ -34042,6 +34083,7 @@ async function runMigrateSessionCli(args) {
|
|
|
34042
34083
|
}
|
|
34043
34084
|
var VALID_MEMORY_ACTIONS;
|
|
34044
34085
|
var init_migrate_session = __esm(async () => {
|
|
34086
|
+
init_config();
|
|
34045
34087
|
init_project_identity();
|
|
34046
34088
|
init_relocate_memory();
|
|
34047
34089
|
init_storage_project_state();
|
|
@@ -34297,7 +34339,7 @@ var init_v22_backfill_commands = __esm(async () => {
|
|
|
34297
34339
|
});
|
|
34298
34340
|
|
|
34299
34341
|
// ../pi-plugin/src/config/index.ts
|
|
34300
|
-
import { existsSync as
|
|
34342
|
+
import { existsSync as existsSync25 } from "node:fs";
|
|
34301
34343
|
function getProjectConfigPaths(cwd) {
|
|
34302
34344
|
const basePath = cortexKitProjectConfigBasePath(cwd);
|
|
34303
34345
|
return [`${basePath}.jsonc`, `${basePath}.json`];
|
|
@@ -34307,10 +34349,10 @@ function getUserConfigPaths() {
|
|
|
34307
34349
|
return [`${basePath}.jsonc`, `${basePath}.json`];
|
|
34308
34350
|
}
|
|
34309
34351
|
function resolveFirstExisting(paths) {
|
|
34310
|
-
return paths.find((path) =>
|
|
34352
|
+
return paths.find((path) => existsSync25(path));
|
|
34311
34353
|
}
|
|
34312
34354
|
function resolvePiLegacyFallback(sources) {
|
|
34313
|
-
return sources.find((source) =>
|
|
34355
|
+
return sources.find((source) => existsSync25(source.path)) ?? null;
|
|
34314
34356
|
}
|
|
34315
34357
|
function loadConfigFile(path, scope) {
|
|
34316
34358
|
let raw;
|
|
@@ -34600,7 +34642,7 @@ function loadPiConfigDetailed(opts = {}) {
|
|
|
34600
34642
|
if (loaded)
|
|
34601
34643
|
loadedFiles.push(loaded);
|
|
34602
34644
|
}
|
|
34603
|
-
const legacyProjectUnmigrated = !projectPath && !projectLegacyFallback && legacySources.project.some((source) =>
|
|
34645
|
+
const legacyProjectUnmigrated = !projectPath && !projectLegacyFallback && legacySources.project.some((source) => existsSync25(source.path));
|
|
34604
34646
|
const userPath = resolveFirstExisting(getUserConfigPaths());
|
|
34605
34647
|
const userLegacyFallback = userPath ? null : resolvePiLegacyFallback(harnessLegacy.user);
|
|
34606
34648
|
const userReadPath = userPath ?? userLegacyFallback?.path;
|
|
@@ -34609,7 +34651,7 @@ function loadPiConfigDetailed(opts = {}) {
|
|
|
34609
34651
|
if (loaded)
|
|
34610
34652
|
loadedFiles.push(loaded);
|
|
34611
34653
|
}
|
|
34612
|
-
const legacyUserUnmigrated = !userPath && !userLegacyFallback && legacySources.user.some((source) =>
|
|
34654
|
+
const legacyUserUnmigrated = !userPath && !userLegacyFallback && legacySources.user.some((source) => existsSync25(source.path));
|
|
34613
34655
|
if (userLegacyFallback) {
|
|
34614
34656
|
warnings.push(`[user config] reading legacy config from ${userLegacyFallback.path} until migration completes; run \`npx @cortexkit/magic-context doctor\` to consolidate into the shared CortexKit location.`);
|
|
34615
34657
|
} else if (legacyUserUnmigrated) {
|
|
@@ -34729,7 +34771,7 @@ var DATABASE_REPAIR_COMMAND = "bunx @cortexkit/magic-context@latest doctor repai
|
|
|
34729
34771
|
|
|
34730
34772
|
// src/lib/github-issue.ts
|
|
34731
34773
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
34732
|
-
import { readFileSync as
|
|
34774
|
+
import { readFileSync as readFileSync14 } from "node:fs";
|
|
34733
34775
|
function runGhCommand(args) {
|
|
34734
34776
|
try {
|
|
34735
34777
|
const result = spawnSync4("gh", args, {
|
|
@@ -34755,7 +34797,7 @@ function failed(result) {
|
|
|
34755
34797
|
function submitGithubIssue(title, bodyPath, runner = runGhCommand) {
|
|
34756
34798
|
let body;
|
|
34757
34799
|
try {
|
|
34758
|
-
body =
|
|
34800
|
+
body = readFileSync14(bodyPath, "utf-8");
|
|
34759
34801
|
} catch (error) {
|
|
34760
34802
|
return {
|
|
34761
34803
|
ok: false,
|
|
@@ -34813,9 +34855,9 @@ var MAX_GITHUB_ISSUE_BODY_CHARS = 65536;
|
|
|
34813
34855
|
var init_github_issue = () => {};
|
|
34814
34856
|
|
|
34815
34857
|
// src/lib/log-lines.ts
|
|
34816
|
-
import { existsSync as
|
|
34858
|
+
import { existsSync as existsSync26, readFileSync as readFileSync15, statSync as statSync12 } from "node:fs";
|
|
34817
34859
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
34818
|
-
import { join as
|
|
34860
|
+
import { join as join22 } from "node:path";
|
|
34819
34861
|
function tokenize(input, limit) {
|
|
34820
34862
|
const tokens = [];
|
|
34821
34863
|
let index = 0;
|
|
@@ -34987,20 +35029,20 @@ function parseLogLine(line) {
|
|
|
34987
35029
|
}
|
|
34988
35030
|
function getMagicContextLogPaths(harness, options = {}) {
|
|
34989
35031
|
const override = options.override === undefined ? process.env.MAGIC_CONTEXT_LOG_PATH?.trim() : options.override?.trim();
|
|
34990
|
-
const storageLogs =
|
|
35032
|
+
const storageLogs = join22(options.storageDir ?? getMagicContextStorageDir(), "logs");
|
|
34991
35033
|
return [
|
|
34992
35034
|
...override ? [override] : [],
|
|
34993
|
-
|
|
34994
|
-
|
|
34995
|
-
|
|
35035
|
+
join22(options.tempDir ?? tmpdir2(), harness, "magic-context", "magic-context.log"),
|
|
35036
|
+
join22(storageLogs, `magic-context.${harness}.log`),
|
|
35037
|
+
join22(storageLogs, "magic-context.log")
|
|
34996
35038
|
].filter((path, index, paths) => paths.indexOf(path) === index);
|
|
34997
35039
|
}
|
|
34998
35040
|
function inspectLogFile(path) {
|
|
34999
|
-
if (!
|
|
35041
|
+
if (!existsSync26(path)) {
|
|
35000
35042
|
return { path, exists: false, sizeKb: 0, lineCount: 0, grammar: "unknown" };
|
|
35001
35043
|
}
|
|
35002
35044
|
try {
|
|
35003
|
-
const content =
|
|
35045
|
+
const content = readFileSync15(path, "utf8");
|
|
35004
35046
|
const lines = content.split(/\r?\n/).filter((line) => line.length > 0);
|
|
35005
35047
|
const grammars = new Set(lines.flatMap((line) => {
|
|
35006
35048
|
const parsed = parseLogLine(line);
|
|
@@ -35027,7 +35069,7 @@ function readLogLines(files) {
|
|
|
35027
35069
|
return [];
|
|
35028
35070
|
try {
|
|
35029
35071
|
let precedingTimestamp = "";
|
|
35030
|
-
return
|
|
35072
|
+
return readFileSync15(file.path, "utf8").split(/\r?\n/).filter((line) => line.length > 0).map((line, lineIndex) => {
|
|
35031
35073
|
precedingTimestamp = parseLogLine(line)?.ts ?? precedingTimestamp;
|
|
35032
35074
|
return { line, timestamp: precedingTimestamp, fileIndex, lineIndex };
|
|
35033
35075
|
});
|
|
@@ -35073,9 +35115,9 @@ var init_redaction2 = __esm(() => {
|
|
|
35073
35115
|
|
|
35074
35116
|
// src/commands/doctor-omp.ts
|
|
35075
35117
|
import { execFileSync as execFileSync5, spawnSync as spawnSync5 } from "node:child_process";
|
|
35076
|
-
import { existsSync as
|
|
35118
|
+
import { existsSync as existsSync27, mkdirSync as mkdirSync8, readFileSync as readFileSync16 } from "node:fs";
|
|
35077
35119
|
import { createRequire as createRequire3 } from "node:module";
|
|
35078
|
-
import { dirname as dirname14, join as
|
|
35120
|
+
import { dirname as dirname14, join as join23, resolve as resolve7 } from "node:path";
|
|
35079
35121
|
function parseSemver(value) {
|
|
35080
35122
|
const match = value?.match(/(\d+)\.(\d+)\.(\d+)/);
|
|
35081
35123
|
return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
|
|
@@ -35117,10 +35159,10 @@ function selfVersion() {
|
|
|
35117
35159
|
return "unknown";
|
|
35118
35160
|
}
|
|
35119
35161
|
function readConfig2(path) {
|
|
35120
|
-
if (!
|
|
35162
|
+
if (!existsSync27(path))
|
|
35121
35163
|
return {};
|
|
35122
35164
|
try {
|
|
35123
|
-
const parsed = import_comment_json7.parse(
|
|
35165
|
+
const parsed = import_comment_json7.parse(readFileSync16(path, "utf-8"));
|
|
35124
35166
|
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? {} : { error: "top level is not an object" };
|
|
35125
35167
|
} catch (error) {
|
|
35126
35168
|
return { error: error instanceof Error ? error.message : String(error) };
|
|
@@ -35130,7 +35172,7 @@ function pluginDeclaresOmp(path) {
|
|
|
35130
35172
|
if (!path)
|
|
35131
35173
|
return null;
|
|
35132
35174
|
try {
|
|
35133
|
-
const pkg = JSON.parse(
|
|
35175
|
+
const pkg = JSON.parse(readFileSync16(join23(path, "package.json"), "utf-8"));
|
|
35134
35176
|
return Array.isArray(pkg.omp?.extensions) || Array.isArray(pkg.pi?.extensions);
|
|
35135
35177
|
} catch {
|
|
35136
35178
|
return null;
|
|
@@ -35211,7 +35253,7 @@ async function runHealthChecks(options) {
|
|
|
35211
35253
|
}
|
|
35212
35254
|
}
|
|
35213
35255
|
const userConfigPath = getOmpUserConfigPath();
|
|
35214
|
-
if (!
|
|
35256
|
+
if (!existsSync27(userConfigPath)) {
|
|
35215
35257
|
add(results, "warn", `No Magic Context user config at ${userConfigPath}`);
|
|
35216
35258
|
repairPlan.writeUserConfig = true;
|
|
35217
35259
|
} else {
|
|
@@ -35228,9 +35270,9 @@ async function runHealthChecks(options) {
|
|
|
35228
35270
|
for (const warning of loaded.warnings.slice(0, 5))
|
|
35229
35271
|
add(results, "warn", warning);
|
|
35230
35272
|
const storage = getMagicContextStorageResolution();
|
|
35231
|
-
const dbPath =
|
|
35273
|
+
const dbPath = join23(storage.path, "context.db");
|
|
35232
35274
|
add(results, "info", `Shared storage: ${storage.path} (source: ${storage.source})`);
|
|
35233
|
-
if (!
|
|
35275
|
+
if (!existsSync27(dbPath))
|
|
35234
35276
|
add(results, "info", `Shared context DB will be created at ${dbPath}`);
|
|
35235
35277
|
else {
|
|
35236
35278
|
let db = null;
|
|
@@ -35289,7 +35331,7 @@ function writeDefaultConfig(path) {
|
|
|
35289
35331
|
}
|
|
35290
35332
|
async function repair(plan, deps, prompts, cwd) {
|
|
35291
35333
|
let fixed = 0;
|
|
35292
|
-
if (plan.writeUserConfig && !
|
|
35334
|
+
if (plan.writeUserConfig && !existsSync27(getOmpUserConfigPath())) {
|
|
35293
35335
|
writeDefaultConfig(getOmpUserConfigPath());
|
|
35294
35336
|
prompts.log.success(`Wrote default Magic Context config to ${getOmpUserConfigPath()}`);
|
|
35295
35337
|
fixed += 1;
|
|
@@ -35374,7 +35416,7 @@ async function runIssueFlow(options) {
|
|
|
35374
35416
|
...report.results.map((result) => `- ${result.status.toUpperCase()}: ${sanitizeDiagnosticText(result.message)}`)
|
|
35375
35417
|
].join(`
|
|
35376
35418
|
`);
|
|
35377
|
-
const path =
|
|
35419
|
+
const path = join23(options.cwd, `magic-context-omp-issue-${timestamp2(options.deps.now())}.md`);
|
|
35378
35420
|
writeFileAtomic(path, `${body}
|
|
35379
35421
|
`);
|
|
35380
35422
|
options.prompts.log.success(`Sanitized report written to ${path}`);
|
|
@@ -36345,14 +36387,14 @@ var SHADOW_BACKFILL_PROVENANCE_KEY = "_magicContextShadowBackfill";
|
|
|
36345
36387
|
// ../plugin/src/shared/tui-config.ts
|
|
36346
36388
|
import {
|
|
36347
36389
|
chmodSync as chmodSync5,
|
|
36348
|
-
existsSync as
|
|
36390
|
+
existsSync as existsSync28,
|
|
36349
36391
|
mkdirSync as mkdirSync9,
|
|
36350
|
-
readFileSync as
|
|
36392
|
+
readFileSync as readFileSync17,
|
|
36351
36393
|
renameSync as renameSync6,
|
|
36352
36394
|
statSync as statSync13,
|
|
36353
36395
|
writeFileSync as writeFileSync6
|
|
36354
36396
|
} from "node:fs";
|
|
36355
|
-
import { dirname as dirname15, join as
|
|
36397
|
+
import { dirname as dirname15, join as join24 } from "node:path";
|
|
36356
36398
|
function pluginEntryId(entry) {
|
|
36357
36399
|
if (typeof entry === "string")
|
|
36358
36400
|
return entry;
|
|
@@ -36393,11 +36435,11 @@ function writeTuiConfigAtomic(configPath, config) {
|
|
|
36393
36435
|
}
|
|
36394
36436
|
function resolveTuiConfigPath(configDirOverride) {
|
|
36395
36437
|
const configDir = configDirOverride ?? getOpenCodeConfigPaths({ binary: "opencode" }).configDir;
|
|
36396
|
-
const jsoncPath =
|
|
36397
|
-
const jsonPath =
|
|
36398
|
-
if (
|
|
36438
|
+
const jsoncPath = join24(configDir, "tui.jsonc");
|
|
36439
|
+
const jsonPath = join24(configDir, "tui.json");
|
|
36440
|
+
if (existsSync28(jsoncPath))
|
|
36399
36441
|
return jsoncPath;
|
|
36400
|
-
if (
|
|
36442
|
+
if (existsSync28(jsonPath))
|
|
36401
36443
|
return jsonPath;
|
|
36402
36444
|
return jsoncPath;
|
|
36403
36445
|
}
|
|
@@ -36405,8 +36447,8 @@ function ensureTuiPluginEntry(options = {}) {
|
|
|
36405
36447
|
try {
|
|
36406
36448
|
const configPath = resolveTuiConfigPath(options.configDir);
|
|
36407
36449
|
let config = {};
|
|
36408
|
-
if (
|
|
36409
|
-
const raw =
|
|
36450
|
+
if (existsSync28(configPath)) {
|
|
36451
|
+
const raw = readFileSync17(configPath, "utf-8");
|
|
36410
36452
|
config = import_comment_json8.parse(raw) ?? {};
|
|
36411
36453
|
}
|
|
36412
36454
|
const plugins = Array.isArray(config.plugin) ? [...config.plugin] : [];
|
|
@@ -36458,9 +36500,9 @@ var init_tui_config = __esm(() => {
|
|
|
36458
36500
|
});
|
|
36459
36501
|
|
|
36460
36502
|
// src/lib/diagnostics-opencode.ts
|
|
36461
|
-
import { existsSync as
|
|
36503
|
+
import { existsSync as existsSync29, readdirSync as readdirSync4, readFileSync as readFileSync18, statSync as statSync14 } from "node:fs";
|
|
36462
36504
|
import { createRequire as createRequire4 } from "node:module";
|
|
36463
|
-
import { join as
|
|
36505
|
+
import { join as join25 } from "node:path";
|
|
36464
36506
|
function getSelfVersion() {
|
|
36465
36507
|
const require2 = createRequire4(import.meta.url);
|
|
36466
36508
|
for (const relPath of ["../../package.json", "../package.json"]) {
|
|
@@ -36478,8 +36520,8 @@ function getPluginCacheInfo() {
|
|
|
36478
36520
|
let cached;
|
|
36479
36521
|
for (const installedPkgPath of getOpenCodePluginPackageJsonPaths()) {
|
|
36480
36522
|
try {
|
|
36481
|
-
if (
|
|
36482
|
-
const pkg = JSON.parse(
|
|
36523
|
+
if (existsSync29(installedPkgPath)) {
|
|
36524
|
+
const pkg = JSON.parse(readFileSync18(installedPkgPath, "utf-8"));
|
|
36483
36525
|
cached = typeof pkg.version === "string" ? pkg.version : undefined;
|
|
36484
36526
|
if (cached)
|
|
36485
36527
|
break;
|
|
@@ -36495,7 +36537,7 @@ function getStorageResolution() {
|
|
|
36495
36537
|
}
|
|
36496
36538
|
function fileSize(path) {
|
|
36497
36539
|
try {
|
|
36498
|
-
return
|
|
36540
|
+
return existsSync29(path) ? statSync14(path).size : 0;
|
|
36499
36541
|
} catch {
|
|
36500
36542
|
return 0;
|
|
36501
36543
|
}
|
|
@@ -36507,10 +36549,10 @@ function sanitizeValue(value) {
|
|
|
36507
36549
|
return sanitizeConfigValue(value);
|
|
36508
36550
|
}
|
|
36509
36551
|
function readConfig3(path) {
|
|
36510
|
-
if (!
|
|
36552
|
+
if (!existsSync29(path))
|
|
36511
36553
|
return { value: null };
|
|
36512
36554
|
try {
|
|
36513
|
-
const raw =
|
|
36555
|
+
const raw = readFileSync18(path, "utf-8");
|
|
36514
36556
|
const value = import_comment_json9.parse(raw);
|
|
36515
36557
|
return { value };
|
|
36516
36558
|
} catch (error) {
|
|
@@ -36535,7 +36577,7 @@ function configHasPluginEntry(config) {
|
|
|
36535
36577
|
}
|
|
36536
36578
|
function parseHistorianDumpMeta(path) {
|
|
36537
36579
|
try {
|
|
36538
|
-
const xml =
|
|
36580
|
+
const xml = readFileSync18(path, "utf-8");
|
|
36539
36581
|
const parsed = parseCompartmentOutput(xml);
|
|
36540
36582
|
const factCountByCategory = {};
|
|
36541
36583
|
for (const fact of parsed.facts) {
|
|
@@ -36568,11 +36610,11 @@ function parseHistorianDumpMeta(path) {
|
|
|
36568
36610
|
}
|
|
36569
36611
|
}
|
|
36570
36612
|
function listDumpsInDir(dir, limit) {
|
|
36571
|
-
if (!
|
|
36613
|
+
if (!existsSync29(dir))
|
|
36572
36614
|
return { count: 0, recent: [] };
|
|
36573
36615
|
try {
|
|
36574
36616
|
const entries = readdirSync4(dir).filter((name) => name.endsWith(".xml")).map((name) => {
|
|
36575
|
-
const stat = statSync14(
|
|
36617
|
+
const stat = statSync14(join25(dir, name));
|
|
36576
36618
|
return {
|
|
36577
36619
|
name,
|
|
36578
36620
|
mtime: stat.mtimeMs,
|
|
@@ -36581,7 +36623,7 @@ function listDumpsInDir(dir, limit) {
|
|
|
36581
36623
|
}).sort((a, b) => b.mtime - a.mtime);
|
|
36582
36624
|
const now = Date.now();
|
|
36583
36625
|
const recent = entries.slice(0, limit).map((entry) => {
|
|
36584
|
-
const meta = parseHistorianDumpMeta(
|
|
36626
|
+
const meta = parseHistorianDumpMeta(join25(dir, entry.name));
|
|
36585
36627
|
const summary = {
|
|
36586
36628
|
name: entry.name,
|
|
36587
36629
|
ageMinutes: Math.round((now - entry.mtime) / 60000),
|
|
@@ -36718,8 +36760,8 @@ async function collectRecentSessions(resolution) {
|
|
|
36718
36760
|
}
|
|
36719
36761
|
}
|
|
36720
36762
|
async function collectHistorianFailures(storageDirPath) {
|
|
36721
|
-
const contextDbPath =
|
|
36722
|
-
if (!
|
|
36763
|
+
const contextDbPath = join25(storageDirPath, "context.db");
|
|
36764
|
+
if (!existsSync29(contextDbPath))
|
|
36723
36765
|
return [];
|
|
36724
36766
|
if (typeof globalThis.Bun === "undefined") {
|
|
36725
36767
|
return [];
|
|
@@ -36752,8 +36794,8 @@ async function collectHistorianFailures(storageDirPath) {
|
|
|
36752
36794
|
}
|
|
36753
36795
|
}
|
|
36754
36796
|
async function collectHistorianRuns(storageDirPath) {
|
|
36755
|
-
const contextDbPath =
|
|
36756
|
-
if (!
|
|
36797
|
+
const contextDbPath = join25(storageDirPath, "context.db");
|
|
36798
|
+
if (!existsSync29(contextDbPath))
|
|
36757
36799
|
return [];
|
|
36758
36800
|
if (typeof globalThis.Bun === "undefined")
|
|
36759
36801
|
return [];
|
|
@@ -36823,7 +36865,7 @@ async function collectDiagnostics() {
|
|
|
36823
36865
|
const magicContextConfig = readConfig3(configPaths.magicContextConfig);
|
|
36824
36866
|
const storageResolution = getStorageResolution();
|
|
36825
36867
|
const storageDirPath = storageResolution.path;
|
|
36826
|
-
const contextDbPath =
|
|
36868
|
+
const contextDbPath = join25(storageDirPath, "context.db");
|
|
36827
36869
|
const logFiles = inspectMagicContextLogs("opencode");
|
|
36828
36870
|
const primaryLog = logFiles.find((file) => file.exists) ?? logFiles[0];
|
|
36829
36871
|
let compactionEnabled = false;
|
|
@@ -36854,7 +36896,7 @@ async function collectDiagnostics() {
|
|
|
36854
36896
|
opencodeConfigHasPlugin: configHasPluginEntry(opencodeConfig.value),
|
|
36855
36897
|
tuiConfigHasPlugin: configHasPluginEntry(tuiConfig.value),
|
|
36856
36898
|
magicContextConfig: {
|
|
36857
|
-
exists:
|
|
36899
|
+
exists: existsSync29(configPaths.magicContextConfig),
|
|
36858
36900
|
...magicContextConfig.error ? { parseError: magicContextConfig.error } : {},
|
|
36859
36901
|
flags: sanitizeValue(magicContextConfig.value ?? {}) ?? {}
|
|
36860
36902
|
},
|
|
@@ -36862,7 +36904,7 @@ async function collectDiagnostics() {
|
|
|
36862
36904
|
storageDir: {
|
|
36863
36905
|
path: storageDirPath,
|
|
36864
36906
|
source: storageResolution.source,
|
|
36865
|
-
exists:
|
|
36907
|
+
exists: existsSync29(storageDirPath),
|
|
36866
36908
|
contextDbSizeBytes: fileSize(contextDbPath)
|
|
36867
36909
|
},
|
|
36868
36910
|
openCodeDatabase: {
|
|
@@ -37089,9 +37131,9 @@ var init_embedding_local = __esm(() => {
|
|
|
37089
37131
|
|
|
37090
37132
|
// src/lib/embedding-runtime.ts
|
|
37091
37133
|
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
37092
|
-
import { existsSync as
|
|
37134
|
+
import { existsSync as existsSync30, readFileSync as readFileSync19 } from "node:fs";
|
|
37093
37135
|
import { createRequire as createRequire5 } from "node:module";
|
|
37094
|
-
import { dirname as dirname16, join as
|
|
37136
|
+
import { dirname as dirname16, join as join26, sep } from "node:path";
|
|
37095
37137
|
function describeError(error) {
|
|
37096
37138
|
const message = error instanceof Error ? error.message : String(error ?? "unknown error");
|
|
37097
37139
|
const code = error?.code;
|
|
@@ -37232,11 +37274,11 @@ function expectedBinaryRelPath(platform, arch) {
|
|
|
37232
37274
|
const supportedArch = arch === "x64" || arch === "arm64";
|
|
37233
37275
|
if (!supportedPlatform || !supportedArch)
|
|
37234
37276
|
return null;
|
|
37235
|
-
return
|
|
37277
|
+
return join26("bin", "napi-v6", platform, arch, "onnxruntime_binding.node");
|
|
37236
37278
|
}
|
|
37237
37279
|
function onnxRuntimeNodeVersion(packageDir) {
|
|
37238
37280
|
try {
|
|
37239
|
-
const parsed = JSON.parse(
|
|
37281
|
+
const parsed = JSON.parse(readFileSync19(join26(packageDir, "package.json"), "utf8"));
|
|
37240
37282
|
return typeof parsed.version === "string" ? parsed.version : undefined;
|
|
37241
37283
|
} catch {
|
|
37242
37284
|
return;
|
|
@@ -37285,7 +37327,7 @@ function formatLocalEmbeddingRuntimeWasmSelected(status) {
|
|
|
37285
37327
|
function requireNodeWasmBundle(probe, candidates) {
|
|
37286
37328
|
if (probe.state === "failed")
|
|
37287
37329
|
return probe;
|
|
37288
|
-
const bundlePath = candidates.find((candidate) =>
|
|
37330
|
+
const bundlePath = candidates.find((candidate) => existsSync30(candidate));
|
|
37289
37331
|
return bundlePath ? probe : {
|
|
37290
37332
|
state: "failed",
|
|
37291
37333
|
reason: `functional Node WASM Transformers bundle is missing (checked ${candidates.join(", ")})`
|
|
@@ -37293,13 +37335,13 @@ function requireNodeWasmBundle(probe, candidates) {
|
|
|
37293
37335
|
}
|
|
37294
37336
|
function nodeWasmBundleCandidates(installRoot) {
|
|
37295
37337
|
return [
|
|
37296
|
-
|
|
37297
|
-
|
|
37298
|
-
|
|
37338
|
+
join26(installRoot, "dist", "transformers-node-wasm.js"),
|
|
37339
|
+
join26(installRoot, "node_modules", "@cortexkit", "opencode-magic-context", "dist", "transformers-node-wasm.js"),
|
|
37340
|
+
join26(installRoot, "node_modules", "@cortexkit", "pi-magic-context", "dist", "transformers-node-wasm.js")
|
|
37299
37341
|
];
|
|
37300
37342
|
}
|
|
37301
37343
|
function probeWasmRuntimeAt(installRoot) {
|
|
37302
|
-
const requireFn = createRequire5(
|
|
37344
|
+
const requireFn = createRequire5(join26(installRoot, "package.json"));
|
|
37303
37345
|
return requireNodeWasmBundle(probeWasmRuntimeFromRequire(requireFn), nodeWasmBundleCandidates(installRoot));
|
|
37304
37346
|
}
|
|
37305
37347
|
function checkLocalEmbeddingRuntimeAt(installRoot, platform = process.platform, arch = process.arch, runtimePreference = "auto", host) {
|
|
@@ -37308,9 +37350,9 @@ function checkLocalEmbeddingRuntimeAt(installRoot, platform = process.platform,
|
|
|
37308
37350
|
const wasm = probeWasmRuntimeAt(installRoot);
|
|
37309
37351
|
return wasm.state === "ok" ? { state: "wasm-selected", wasmPath: wasm.wasmPath } : { state: "wasm-broken", wasmReason: wasm.reason };
|
|
37310
37352
|
}
|
|
37311
|
-
const packageDir =
|
|
37353
|
+
const packageDir = join26(installRoot, "node_modules", "onnxruntime-node");
|
|
37312
37354
|
let native;
|
|
37313
|
-
if (!
|
|
37355
|
+
if (!existsSync30(join26(packageDir, "package.json"))) {
|
|
37314
37356
|
native = { state: "package-missing", packageDir };
|
|
37315
37357
|
} else {
|
|
37316
37358
|
const rel = expectedBinaryRelPath(platform, arch);
|
|
@@ -37320,8 +37362,8 @@ function checkLocalEmbeddingRuntimeAt(installRoot, platform = process.platform,
|
|
|
37320
37362
|
binaryPath: packageDir
|
|
37321
37363
|
};
|
|
37322
37364
|
} else {
|
|
37323
|
-
const binaryPath =
|
|
37324
|
-
native =
|
|
37365
|
+
const binaryPath = join26(packageDir, rel);
|
|
37366
|
+
native = existsSync30(binaryPath) ? probeOnnxRuntimeNodeLoad(packageDir) ?? { state: "ok", binaryPath } : {
|
|
37325
37367
|
state: "binary-missing",
|
|
37326
37368
|
packageDir,
|
|
37327
37369
|
expectedBinary: binaryPath,
|
|
@@ -37332,7 +37374,7 @@ function checkLocalEmbeddingRuntimeAt(installRoot, platform = process.platform,
|
|
|
37332
37374
|
return withWasmFallback(native, () => probeWasmRuntimeAt(installRoot));
|
|
37333
37375
|
}
|
|
37334
37376
|
function checkLocalEmbeddingRuntime(installRoots, platform = process.platform, arch = process.arch, runtimePreference = "auto", host) {
|
|
37335
|
-
const existing = installRoots.filter((root) =>
|
|
37377
|
+
const existing = installRoots.filter((root) => existsSync30(root));
|
|
37336
37378
|
if (existing.length === 0) {
|
|
37337
37379
|
return {
|
|
37338
37380
|
state: "unknown",
|
|
@@ -37362,15 +37404,15 @@ function packageDirFromResolved(resolvedPath, packageName) {
|
|
|
37362
37404
|
}
|
|
37363
37405
|
function probeWasmRuntimeByResolution(pluginDir) {
|
|
37364
37406
|
try {
|
|
37365
|
-
const reqPlugin = createRequire5(
|
|
37407
|
+
const reqPlugin = createRequire5(join26(pluginDir, "package.json"));
|
|
37366
37408
|
const direct = probeWasmRuntimeFromRequire(reqPlugin);
|
|
37367
37409
|
let probe = direct;
|
|
37368
37410
|
if (direct.state === "failed" && direct.reason.startsWith("onnxruntime-web is not resolvable")) {
|
|
37369
37411
|
const tfResolved = reqPlugin.resolve("@huggingface/transformers");
|
|
37370
37412
|
const tfDir = packageDirFromResolved(tfResolved, "@huggingface/transformers");
|
|
37371
|
-
probe = probeWasmRuntimeFromRequire(createRequire5(
|
|
37413
|
+
probe = probeWasmRuntimeFromRequire(createRequire5(join26(tfDir, "package.json")));
|
|
37372
37414
|
}
|
|
37373
|
-
return requireNodeWasmBundle(probe, [
|
|
37415
|
+
return requireNodeWasmBundle(probe, [join26(pluginDir, "dist", "transformers-node-wasm.js")]);
|
|
37374
37416
|
} catch (error) {
|
|
37375
37417
|
return {
|
|
37376
37418
|
state: "failed",
|
|
@@ -37379,7 +37421,7 @@ function probeWasmRuntimeByResolution(pluginDir) {
|
|
|
37379
37421
|
}
|
|
37380
37422
|
}
|
|
37381
37423
|
function checkLocalEmbeddingRuntimeByResolution(pluginDir, platform = process.platform, arch = process.arch, runtimePreference = "auto", host) {
|
|
37382
|
-
if (!
|
|
37424
|
+
if (!existsSync30(join26(pluginDir, "package.json"))) {
|
|
37383
37425
|
return { state: "unknown", reason: "plugin package dir not found" };
|
|
37384
37426
|
}
|
|
37385
37427
|
const selectedRuntime = resolveLocalEmbeddingRuntime(runtimePreference, host);
|
|
@@ -37390,13 +37432,13 @@ function checkLocalEmbeddingRuntimeByResolution(pluginDir, platform = process.pl
|
|
|
37390
37432
|
let onnxDir = null;
|
|
37391
37433
|
let resolveError;
|
|
37392
37434
|
try {
|
|
37393
|
-
const reqPlugin = createRequire5(
|
|
37435
|
+
const reqPlugin = createRequire5(join26(pluginDir, "package.json"));
|
|
37394
37436
|
try {
|
|
37395
37437
|
onnxDir = packageDirFromResolved(reqPlugin.resolve("onnxruntime-node"), "onnxruntime-node");
|
|
37396
37438
|
} catch {
|
|
37397
37439
|
const tfResolved = reqPlugin.resolve("@huggingface/transformers");
|
|
37398
37440
|
const tfDir = packageDirFromResolved(tfResolved, "@huggingface/transformers");
|
|
37399
|
-
const reqTf = createRequire5(
|
|
37441
|
+
const reqTf = createRequire5(join26(tfDir, "package.json"));
|
|
37400
37442
|
onnxDir = packageDirFromResolved(reqTf.resolve("onnxruntime-node"), "onnxruntime-node");
|
|
37401
37443
|
}
|
|
37402
37444
|
} catch (error) {
|
|
@@ -37404,7 +37446,7 @@ function checkLocalEmbeddingRuntimeByResolution(pluginDir, platform = process.pl
|
|
|
37404
37446
|
if (resolveError === "ERR_MODULE_NOT_FOUND" || resolveError === "MODULE_NOT_FOUND") {
|
|
37405
37447
|
return withWasmFallback({
|
|
37406
37448
|
state: "package-missing",
|
|
37407
|
-
packageDir:
|
|
37449
|
+
packageDir: join26(pluginDir, "node_modules", "onnxruntime-node")
|
|
37408
37450
|
}, () => probeWasmRuntimeByResolution(pluginDir));
|
|
37409
37451
|
}
|
|
37410
37452
|
return {
|
|
@@ -37420,8 +37462,8 @@ function checkLocalEmbeddingRuntimeByResolution(pluginDir, platform = process.pl
|
|
|
37420
37462
|
if (rel === null) {
|
|
37421
37463
|
native = probeOnnxRuntimeNodeLoad(onnxDir) ?? { state: "ok", binaryPath: onnxDir };
|
|
37422
37464
|
} else {
|
|
37423
|
-
const binaryPath =
|
|
37424
|
-
native =
|
|
37465
|
+
const binaryPath = join26(onnxDir, rel);
|
|
37466
|
+
native = existsSync30(binaryPath) ? probeOnnxRuntimeNodeLoad(onnxDir) ?? { state: "ok", binaryPath } : {
|
|
37425
37467
|
state: "binary-missing",
|
|
37426
37468
|
packageDir: onnxDir,
|
|
37427
37469
|
expectedBinary: binaryPath,
|
|
@@ -37564,7 +37606,7 @@ var init_issue_body = __esm(() => {
|
|
|
37564
37606
|
|
|
37565
37607
|
// src/lib/logs-opencode.ts
|
|
37566
37608
|
import { writeFileSync as writeFileSync7 } from "node:fs";
|
|
37567
|
-
import { join as
|
|
37609
|
+
import { join as join27 } from "node:path";
|
|
37568
37610
|
function sanitizeLogContent(content) {
|
|
37569
37611
|
return sanitizeDiagnosticText(content);
|
|
37570
37612
|
}
|
|
@@ -37671,10 +37713,10 @@ async function bundleIssueReport(report, description, title, sessionFilter = nul
|
|
|
37671
37713
|
const bodyMarkdown = capBodyToGithubLimit(rawBodyMarkdown);
|
|
37672
37714
|
const truncated = bodyMarkdown !== rawBodyMarkdown;
|
|
37673
37715
|
const timestamp = formatTimestamp(new Date);
|
|
37674
|
-
const path =
|
|
37716
|
+
const path = join27(process.cwd(), `magic-context-issue-${timestamp}.md`);
|
|
37675
37717
|
writeFileSync7(path, `${bodyMarkdown}
|
|
37676
37718
|
`);
|
|
37677
|
-
const fullPath = truncated ?
|
|
37719
|
+
const fullPath = truncated ? join27(process.cwd(), `magic-context-issue-${timestamp}-full.md`) : undefined;
|
|
37678
37720
|
if (fullPath)
|
|
37679
37721
|
writeFileSync7(fullPath, `${rawBodyMarkdown}
|
|
37680
37722
|
`);
|
|
@@ -37941,24 +37983,24 @@ function migrateExperimentalPinKeyFilesForDoctor(mcConfig) {
|
|
|
37941
37983
|
|
|
37942
37984
|
// ../plugin/src/hooks/auto-update-checker/constants.ts
|
|
37943
37985
|
import { homedir as homedir15, platform } from "node:os";
|
|
37944
|
-
import { join as
|
|
37986
|
+
import { join as join28 } from "node:path";
|
|
37945
37987
|
function getOpenCodeCacheRoot() {
|
|
37946
37988
|
if (platform() === "win32") {
|
|
37947
|
-
return
|
|
37989
|
+
return join28(process.env.LOCALAPPDATA ?? homedir15(), "opencode");
|
|
37948
37990
|
}
|
|
37949
|
-
return
|
|
37991
|
+
return join28(homedir15(), ".cache", "opencode");
|
|
37950
37992
|
}
|
|
37951
37993
|
function getOpenCodeConfigRoot() {
|
|
37952
37994
|
if (platform() === "win32") {
|
|
37953
|
-
return
|
|
37995
|
+
return join28(process.env.APPDATA ?? join28(homedir15(), "AppData", "Roaming"), "opencode");
|
|
37954
37996
|
}
|
|
37955
|
-
return
|
|
37997
|
+
return join28(process.env.XDG_CONFIG_HOME ?? join28(homedir15(), ".config"), "opencode");
|
|
37956
37998
|
}
|
|
37957
37999
|
var PACKAGE_NAME = "@cortexkit/opencode-magic-context", CACHE_DIR, USER_OPENCODE_CONFIG, USER_OPENCODE_CONFIG_JSONC;
|
|
37958
38000
|
var init_constants2 = __esm(() => {
|
|
37959
|
-
CACHE_DIR =
|
|
37960
|
-
USER_OPENCODE_CONFIG =
|
|
37961
|
-
USER_OPENCODE_CONFIG_JSONC =
|
|
38001
|
+
CACHE_DIR = join28(getOpenCodeCacheRoot(), "packages");
|
|
38002
|
+
USER_OPENCODE_CONFIG = join28(getOpenCodeConfigRoot(), "opencode.json");
|
|
38003
|
+
USER_OPENCODE_CONFIG_JSONC = join28(getOpenCodeConfigRoot(), "opencode.jsonc");
|
|
37962
38004
|
});
|
|
37963
38005
|
// ../plugin/src/hooks/auto-update-checker/types.ts
|
|
37964
38006
|
var NpmPackageEnvelopeSchema, OpencodePluginTupleSchema, OpencodeConfigSchema, PackageJsonSchema;
|
|
@@ -37981,14 +38023,14 @@ var init_types = __esm(() => {
|
|
|
37981
38023
|
// ../plugin/src/hooks/auto-update-checker/checker.ts
|
|
37982
38024
|
import {
|
|
37983
38025
|
accessSync as accessSync2,
|
|
37984
|
-
existsSync as
|
|
38026
|
+
existsSync as existsSync31,
|
|
37985
38027
|
constants as fsConstants,
|
|
37986
|
-
readFileSync as
|
|
38028
|
+
readFileSync as readFileSync20,
|
|
37987
38029
|
renameSync as renameSync7,
|
|
37988
38030
|
statSync as statSync15,
|
|
37989
38031
|
writeFileSync as writeFileSync8
|
|
37990
38032
|
} from "node:fs";
|
|
37991
|
-
import { dirname as dirname17, isAbsolute as
|
|
38033
|
+
import { dirname as dirname17, isAbsolute as isAbsolute7, join as join29, resolve as resolve8 } from "node:path";
|
|
37992
38034
|
function warn(message) {
|
|
37993
38035
|
log3(`WARN: ${message}`);
|
|
37994
38036
|
}
|
|
@@ -38018,13 +38060,13 @@ function getSurfaceConfigPaths(directory, surface) {
|
|
|
38018
38060
|
const dirs = [
|
|
38019
38061
|
globalDir,
|
|
38020
38062
|
directory,
|
|
38021
|
-
|
|
38063
|
+
join29(directory, ".opencode"),
|
|
38022
38064
|
process.env.OPENCODE_CONFIG_DIR
|
|
38023
38065
|
].filter((value) => Boolean(value));
|
|
38024
38066
|
const paths = [];
|
|
38025
38067
|
for (const dir of dirs) {
|
|
38026
38068
|
for (const extension of ["json", "jsonc"]) {
|
|
38027
|
-
const path =
|
|
38069
|
+
const path = join29(dir, `${name}.${extension}`);
|
|
38028
38070
|
if (!paths.includes(path))
|
|
38029
38071
|
paths.push(path);
|
|
38030
38072
|
}
|
|
@@ -38035,9 +38077,9 @@ function getWinningConfig(directory, surface) {
|
|
|
38035
38077
|
let winner = null;
|
|
38036
38078
|
for (const path of getSurfaceConfigPaths(directory, surface)) {
|
|
38037
38079
|
try {
|
|
38038
|
-
if (!
|
|
38080
|
+
if (!existsSync31(path))
|
|
38039
38081
|
continue;
|
|
38040
|
-
const parsed = parseJsonConfig(
|
|
38082
|
+
const parsed = parseJsonConfig(readFileSync20(path, "utf-8"));
|
|
38041
38083
|
const entries = getPluginEntries(parsed);
|
|
38042
38084
|
if (entries.some((entry) => entry === PACKAGE_NAME || entry.startsWith(`${PACKAGE_NAME}@`))) {
|
|
38043
38085
|
if (winner) {
|
|
@@ -38073,14 +38115,14 @@ var init_checker = __esm(() => {
|
|
|
38073
38115
|
});
|
|
38074
38116
|
|
|
38075
38117
|
// src/lib/opencode-plugin-schema-fence.ts
|
|
38076
|
-
import { existsSync as
|
|
38077
|
-
import { join as
|
|
38118
|
+
import { existsSync as existsSync32, readdirSync as readdirSync5, readFileSync as readFileSync21 } from "node:fs";
|
|
38119
|
+
import { join as join30 } from "node:path";
|
|
38078
38120
|
import { gunzipSync } from "node:zlib";
|
|
38079
38121
|
function readPackageVersion(packageJsonPath) {
|
|
38080
38122
|
try {
|
|
38081
|
-
if (!
|
|
38123
|
+
if (!existsSync32(packageJsonPath))
|
|
38082
38124
|
return null;
|
|
38083
|
-
const packageJson = JSON.parse(
|
|
38125
|
+
const packageJson = JSON.parse(readFileSync21(packageJsonPath, "utf-8"));
|
|
38084
38126
|
if (packageJson.name !== OPENCODE_PLUGIN_NAME || typeof packageJson.version !== "string") {
|
|
38085
38127
|
return null;
|
|
38086
38128
|
}
|
|
@@ -38099,8 +38141,8 @@ function readFenceValue(text) {
|
|
|
38099
38141
|
return values.size === 1 ? [...values][0] ?? null : null;
|
|
38100
38142
|
}
|
|
38101
38143
|
function readFenceFromDist(packageDirectory) {
|
|
38102
|
-
const distDirectory =
|
|
38103
|
-
if (!
|
|
38144
|
+
const distDirectory = join30(packageDirectory, "dist");
|
|
38145
|
+
if (!existsSync32(distDirectory))
|
|
38104
38146
|
return null;
|
|
38105
38147
|
const pending = [distDirectory];
|
|
38106
38148
|
const fenceValues = new Set;
|
|
@@ -38110,14 +38152,14 @@ function readFenceFromDist(packageDirectory) {
|
|
|
38110
38152
|
continue;
|
|
38111
38153
|
try {
|
|
38112
38154
|
for (const entry of readdirSync5(directory, { withFileTypes: true })) {
|
|
38113
|
-
const path =
|
|
38155
|
+
const path = join30(directory, entry.name);
|
|
38114
38156
|
if (entry.isDirectory()) {
|
|
38115
38157
|
pending.push(path);
|
|
38116
38158
|
continue;
|
|
38117
38159
|
}
|
|
38118
38160
|
if (!entry.isFile() || !/\.(?:[cm]?js|ts)$/.test(entry.name))
|
|
38119
38161
|
continue;
|
|
38120
|
-
const fence = readFenceValue(
|
|
38162
|
+
const fence = readFenceValue(readFileSync21(path, "utf-8"));
|
|
38121
38163
|
if (fence !== null)
|
|
38122
38164
|
fenceValues.add(fence);
|
|
38123
38165
|
}
|
|
@@ -38128,20 +38170,20 @@ function readFenceFromDist(packageDirectory) {
|
|
|
38128
38170
|
return fenceValues.size === 1 ? [...fenceValues][0] ?? null : null;
|
|
38129
38171
|
}
|
|
38130
38172
|
function findInstalledPluginPackage(cacheDirectory, specifier, requestedVersion) {
|
|
38131
|
-
const directCacheRoot =
|
|
38173
|
+
const directCacheRoot = join30(cacheDirectory, specifier);
|
|
38132
38174
|
const candidates = [directCacheRoot];
|
|
38133
38175
|
try {
|
|
38134
38176
|
for (const entry of readdirSync5(cacheDirectory, { withFileTypes: true })) {
|
|
38135
38177
|
if (!entry.isDirectory())
|
|
38136
38178
|
continue;
|
|
38137
|
-
const candidate =
|
|
38179
|
+
const candidate = join30(cacheDirectory, entry.name);
|
|
38138
38180
|
if (!candidates.includes(candidate))
|
|
38139
38181
|
candidates.push(candidate);
|
|
38140
38182
|
}
|
|
38141
38183
|
} catch {}
|
|
38142
38184
|
for (const cacheRoot of candidates) {
|
|
38143
|
-
const directory =
|
|
38144
|
-
const version = readPackageVersion(
|
|
38185
|
+
const directory = join30(cacheRoot, "node_modules", ...PACKAGE_PATH_SEGMENTS);
|
|
38186
|
+
const version = readPackageVersion(join30(directory, "package.json"));
|
|
38145
38187
|
if (!version)
|
|
38146
38188
|
continue;
|
|
38147
38189
|
if (cacheRoot === directCacheRoot || EXACT_VERSION_PATTERN.test(requestedVersion) && version === requestedVersion) {
|
|
@@ -38335,13 +38377,13 @@ var init_storage_versions = __esm(async () => {
|
|
|
38335
38377
|
});
|
|
38336
38378
|
|
|
38337
38379
|
// src/commands/doctor-opencode-cache.ts
|
|
38338
|
-
import { existsSync as
|
|
38380
|
+
import { existsSync as existsSync33, readFileSync as readFileSync22, rmSync as rmSync3 } from "node:fs";
|
|
38339
38381
|
function readCachedPluginVersion(pluginCacheDir) {
|
|
38340
38382
|
try {
|
|
38341
38383
|
const installedPkgPath = getOpenCodePluginPackageJsonPath(pluginCacheDir);
|
|
38342
|
-
if (!
|
|
38384
|
+
if (!existsSync33(installedPkgPath))
|
|
38343
38385
|
return;
|
|
38344
|
-
const pkg = JSON.parse(
|
|
38386
|
+
const pkg = JSON.parse(readFileSync22(installedPkgPath, "utf-8"));
|
|
38345
38387
|
return typeof pkg.version === "string" ? pkg.version : undefined;
|
|
38346
38388
|
} catch {
|
|
38347
38389
|
return;
|
|
@@ -38350,7 +38392,7 @@ function readCachedPluginVersion(pluginCacheDir) {
|
|
|
38350
38392
|
async function clearPluginCache(options = {}, deps = {}) {
|
|
38351
38393
|
const remove = deps.remove ?? ((path) => rmSync3(path, { recursive: true, force: true }));
|
|
38352
38394
|
const pluginCacheRoots = getOpenCodePluginCacheRoots();
|
|
38353
|
-
const existingRoots = pluginCacheRoots.filter((root) =>
|
|
38395
|
+
const existingRoots = pluginCacheRoots.filter((root) => existsSync33(root));
|
|
38354
38396
|
if (existingRoots.length === 0) {
|
|
38355
38397
|
return { action: "not_found", path: pluginCacheRoots[0] ?? "" };
|
|
38356
38398
|
}
|
|
@@ -38418,10 +38460,10 @@ var init_doctor_opencode_cache = __esm(() => {
|
|
|
38418
38460
|
|
|
38419
38461
|
// src/commands/doctor-opencode.ts
|
|
38420
38462
|
import { spawnSync as spawnSync7 } from "node:child_process";
|
|
38421
|
-
import { existsSync as
|
|
38463
|
+
import { existsSync as existsSync34, readFileSync as readFileSync23 } from "node:fs";
|
|
38422
38464
|
import { createRequire as createRequire6 } from "node:module";
|
|
38423
38465
|
import { homedir as homedir16 } from "node:os";
|
|
38424
|
-
import { join as
|
|
38466
|
+
import { join as join31 } from "node:path";
|
|
38425
38467
|
function describeOpenCodeDatabaseDoctorCheck(resolution, exists = openCodeDbPathExists(resolution)) {
|
|
38426
38468
|
if (!exists)
|
|
38427
38469
|
return { ok: false, message: formatOpenCodeDbDoctorLine(resolution) };
|
|
@@ -38529,15 +38571,15 @@ function getUserNpmrcPath() {
|
|
|
38529
38571
|
if (custom)
|
|
38530
38572
|
return custom;
|
|
38531
38573
|
const home = process.env.HOME?.trim();
|
|
38532
|
-
return
|
|
38574
|
+
return join31(home || homedir16(), ".npmrc");
|
|
38533
38575
|
}
|
|
38534
38576
|
function collectNpmReleaseAgeWarnings() {
|
|
38535
38577
|
const ageWarnings = [];
|
|
38536
38578
|
const npmrcPath = getUserNpmrcPath();
|
|
38537
|
-
if (!
|
|
38579
|
+
if (!existsSync34(npmrcPath))
|
|
38538
38580
|
return ageWarnings;
|
|
38539
38581
|
try {
|
|
38540
|
-
const npmrc =
|
|
38582
|
+
const npmrc = readFileSync23(npmrcPath, "utf-8");
|
|
38541
38583
|
for (const line of npmrc.split(`
|
|
38542
38584
|
`)) {
|
|
38543
38585
|
const trimmed = line.trim();
|
|
@@ -38671,7 +38713,7 @@ function checkLocalEmbeddingRuntimeForDoctor(runtimePreference = "auto") {
|
|
|
38671
38713
|
return { issues: 0 };
|
|
38672
38714
|
}
|
|
38673
38715
|
async function checkEmbeddingConfig(magicContextConfigPath) {
|
|
38674
|
-
if (!
|
|
38716
|
+
if (!existsSync34(magicContextConfigPath)) {
|
|
38675
38717
|
return checkLocalEmbeddingRuntimeForDoctor();
|
|
38676
38718
|
}
|
|
38677
38719
|
let rawText;
|
|
@@ -38828,7 +38870,7 @@ async function runDoctor2(options = {}) {
|
|
|
38828
38870
|
const v22Result = await runV22BackfillCommands({
|
|
38829
38871
|
name: "OpenCode",
|
|
38830
38872
|
openDatabase: (readonly = true) => {
|
|
38831
|
-
const dbPath =
|
|
38873
|
+
const dbPath = join31(getMagicContextStorageDir(), "context.db");
|
|
38832
38874
|
v22Db = readonly ? openExistingContextDatabase(dbPath, { readonly: true }) : openExistingContextDatabaseForMutation(dbPath);
|
|
38833
38875
|
return v22Db;
|
|
38834
38876
|
},
|
|
@@ -38860,7 +38902,7 @@ async function runDoctor2(options = {}) {
|
|
|
38860
38902
|
failCount++;
|
|
38861
38903
|
issues++;
|
|
38862
38904
|
};
|
|
38863
|
-
const authorityDbPath =
|
|
38905
|
+
const authorityDbPath = join31(getMagicContextStorageDir(), "context.db");
|
|
38864
38906
|
let authorityDb = null;
|
|
38865
38907
|
try {
|
|
38866
38908
|
authorityDb = openExistingContextDatabase(authorityDbPath, { readonly: true });
|
|
@@ -38916,7 +38958,7 @@ async function runDoctor2(options = {}) {
|
|
|
38916
38958
|
} else {
|
|
38917
38959
|
pass(`OpenCode config: ${paths.opencodeConfig}`);
|
|
38918
38960
|
}
|
|
38919
|
-
if (
|
|
38961
|
+
if (existsSync34(paths.magicContextConfig)) {
|
|
38920
38962
|
pass(`Magic Context config: ${paths.magicContextConfig}`);
|
|
38921
38963
|
try {
|
|
38922
38964
|
const raw = loadRawConfigFile({ configPath: paths.magicContextConfig, tier: "user" });
|
|
@@ -38950,7 +38992,7 @@ async function runDoctor2(options = {}) {
|
|
|
38950
38992
|
warn(`No magic-context.jsonc found — using defaults`);
|
|
38951
38993
|
log2.info(" Run 'setup' to create one with model recommendations");
|
|
38952
38994
|
}
|
|
38953
|
-
if (
|
|
38995
|
+
if (existsSync34(paths.magicContextConfig)) {
|
|
38954
38996
|
try {
|
|
38955
38997
|
const raw = loadRawConfigFile({ configPath: paths.magicContextConfig, tier: "user" });
|
|
38956
38998
|
if (!raw)
|
|
@@ -39072,7 +39114,7 @@ async function runDoctor2(options = {}) {
|
|
|
39072
39114
|
}
|
|
39073
39115
|
if (paths.opencodeConfigFormat !== "none") {
|
|
39074
39116
|
try {
|
|
39075
|
-
const raw =
|
|
39117
|
+
const raw = readFileSync23(paths.opencodeConfig, "utf-8");
|
|
39076
39118
|
const config = import_comment_json11.parse(raw);
|
|
39077
39119
|
const rawPlugins = Array.isArray(config?.plugin) ? config.plugin : [];
|
|
39078
39120
|
const existingIdx = rawPlugins.findIndex((entry) => matchesPluginEntry(entry, OPENCODE_PLUGIN_NAME) || isDevPathPluginEntry(entry));
|
|
@@ -39157,9 +39199,9 @@ async function runDoctor2(options = {}) {
|
|
|
39157
39199
|
pass("Added TUI sidebar plugin to tui.json");
|
|
39158
39200
|
warn("Restart OpenCode to see the sidebar");
|
|
39159
39201
|
fixed++;
|
|
39160
|
-
} else if (
|
|
39202
|
+
} else if (existsSync34(paths.tuiConfig)) {
|
|
39161
39203
|
try {
|
|
39162
|
-
const tuiRaw =
|
|
39204
|
+
const tuiRaw = readFileSync23(paths.tuiConfig, "utf-8");
|
|
39163
39205
|
const tuiConfig = import_comment_json11.parse(tuiRaw);
|
|
39164
39206
|
const tuiRawPlugins = Array.isArray(tuiConfig?.plugin) ? tuiConfig.plugin : [];
|
|
39165
39207
|
const tuiIdx = tuiRawPlugins.findIndex((entry) => matchesPluginEntry(entry, OPENCODE_PLUGIN_NAME) || isDevPathPluginEntry(entry));
|
|
@@ -39208,7 +39250,7 @@ async function runDoctor2(options = {}) {
|
|
|
39208
39250
|
} else {
|
|
39209
39251
|
fail("Could not create or verify the TUI sidebar config");
|
|
39210
39252
|
}
|
|
39211
|
-
if (
|
|
39253
|
+
if (existsSync34(paths.magicContextConfig)) {
|
|
39212
39254
|
try {
|
|
39213
39255
|
const raw = loadRawConfigFile({ configPath: paths.magicContextConfig, tier: "user" });
|
|
39214
39256
|
if (!raw)
|
|
@@ -39230,9 +39272,9 @@ async function runDoctor2(options = {}) {
|
|
|
39230
39272
|
else
|
|
39231
39273
|
passCount++;
|
|
39232
39274
|
const storage = getMagicContextStorageResolution();
|
|
39233
|
-
const dbPath =
|
|
39275
|
+
const dbPath = join31(storage.path, "context.db");
|
|
39234
39276
|
log2.info(`Shared storage: ${storage.path} (source: ${storage.source})`);
|
|
39235
|
-
if (!
|
|
39277
|
+
if (!existsSync34(dbPath)) {
|
|
39236
39278
|
log2.info(`Shared context DB not yet created at ${dbPath} (will be created on first run)`);
|
|
39237
39279
|
} else {
|
|
39238
39280
|
log2.info(`Shared context DB exists at ${dbPath}`);
|
|
@@ -39446,9 +39488,9 @@ var init_doctor_opencode = __esm(async () => {
|
|
|
39446
39488
|
});
|
|
39447
39489
|
|
|
39448
39490
|
// src/lib/diagnostics-pi.ts
|
|
39449
|
-
import { existsSync as
|
|
39491
|
+
import { existsSync as existsSync35, readdirSync as readdirSync6, readFileSync as readFileSync24, statSync as statSync16 } from "node:fs";
|
|
39450
39492
|
import { createRequire as createRequire7 } from "node:module";
|
|
39451
|
-
import { join as
|
|
39493
|
+
import { join as join32 } from "node:path";
|
|
39452
39494
|
function getSelfVersion3() {
|
|
39453
39495
|
const req = createRequire7(import.meta.url);
|
|
39454
39496
|
for (const relPath of ["../../package.json", "../package.json"]) {
|
|
@@ -39463,7 +39505,7 @@ function getSelfVersion3() {
|
|
|
39463
39505
|
}
|
|
39464
39506
|
function fileSize2(path) {
|
|
39465
39507
|
try {
|
|
39466
|
-
return
|
|
39508
|
+
return existsSync35(path) ? statSync16(path).size : 0;
|
|
39467
39509
|
} catch {
|
|
39468
39510
|
return 0;
|
|
39469
39511
|
}
|
|
@@ -39475,11 +39517,11 @@ function sanitizeValue2(value) {
|
|
|
39475
39517
|
return sanitizeConfigValue(value);
|
|
39476
39518
|
}
|
|
39477
39519
|
function readJsonc(path) {
|
|
39478
|
-
if (!
|
|
39520
|
+
if (!existsSync35(path))
|
|
39479
39521
|
return { value: {} };
|
|
39480
39522
|
try {
|
|
39481
39523
|
return {
|
|
39482
|
-
value: import_comment_json12.parse(
|
|
39524
|
+
value: import_comment_json12.parse(readFileSync24(path, "utf-8"))
|
|
39483
39525
|
};
|
|
39484
39526
|
} catch (error) {
|
|
39485
39527
|
return {
|
|
@@ -39495,7 +39537,7 @@ function readConfigDiagnostic(path) {
|
|
|
39495
39537
|
const parsed = readJsonc(path);
|
|
39496
39538
|
return {
|
|
39497
39539
|
path,
|
|
39498
|
-
exists:
|
|
39540
|
+
exists: existsSync35(path),
|
|
39499
39541
|
...parsed.parseError ? { parseError: parsed.parseError } : {},
|
|
39500
39542
|
flags: sanitizeValue2(parsed.value)
|
|
39501
39543
|
};
|
|
@@ -39513,7 +39555,7 @@ function reverseSlugToDirectory(slug) {
|
|
|
39513
39555
|
}
|
|
39514
39556
|
function collectPiRecentSessions() {
|
|
39515
39557
|
const sessionsRoot = getPiSessionsRoot();
|
|
39516
|
-
if (!
|
|
39558
|
+
if (!existsSync35(sessionsRoot))
|
|
39517
39559
|
return [];
|
|
39518
39560
|
try {
|
|
39519
39561
|
const slugs = readdirSync6(sessionsRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
@@ -39522,7 +39564,7 @@ function collectPiRecentSessions() {
|
|
|
39522
39564
|
const directory = reverseSlugToDirectory(slug);
|
|
39523
39565
|
if (!directory)
|
|
39524
39566
|
continue;
|
|
39525
|
-
const slugDir =
|
|
39567
|
+
const slugDir = join32(sessionsRoot, slug);
|
|
39526
39568
|
let files;
|
|
39527
39569
|
try {
|
|
39528
39570
|
files = readdirSync6(slugDir).filter((name) => name.endsWith(".jsonl"));
|
|
@@ -39531,7 +39573,7 @@ function collectPiRecentSessions() {
|
|
|
39531
39573
|
}
|
|
39532
39574
|
for (const file of files) {
|
|
39533
39575
|
try {
|
|
39534
|
-
const mtime = statSync16(
|
|
39576
|
+
const mtime = statSync16(join32(slugDir, file)).mtimeMs;
|
|
39535
39577
|
const sessionId = file.replace(/\.jsonl$/, "");
|
|
39536
39578
|
candidates.push({ sessionId, directory, mtime });
|
|
39537
39579
|
} catch {}
|
|
@@ -39549,7 +39591,7 @@ function collectPiRecentSessions() {
|
|
|
39549
39591
|
}
|
|
39550
39592
|
function parseHistorianDumpMeta2(path) {
|
|
39551
39593
|
try {
|
|
39552
|
-
const xml =
|
|
39594
|
+
const xml = readFileSync24(path, "utf-8");
|
|
39553
39595
|
const parsed = parseCompartmentOutput(xml);
|
|
39554
39596
|
const factCountByCategory = {};
|
|
39555
39597
|
for (const fact of parsed.facts) {
|
|
@@ -39582,11 +39624,11 @@ function parseHistorianDumpMeta2(path) {
|
|
|
39582
39624
|
}
|
|
39583
39625
|
}
|
|
39584
39626
|
function listDumpsInDir2(dir, limit) {
|
|
39585
|
-
if (!
|
|
39627
|
+
if (!existsSync35(dir))
|
|
39586
39628
|
return { count: 0, recent: [] };
|
|
39587
39629
|
try {
|
|
39588
39630
|
const entries = readdirSync6(dir).filter((name) => name.endsWith(".xml")).map((name) => {
|
|
39589
|
-
const stat = statSync16(
|
|
39631
|
+
const stat = statSync16(join32(dir, name));
|
|
39590
39632
|
return {
|
|
39591
39633
|
name,
|
|
39592
39634
|
mtime: stat.mtimeMs,
|
|
@@ -39595,7 +39637,7 @@ function listDumpsInDir2(dir, limit) {
|
|
|
39595
39637
|
}).sort((a, b) => b.mtime - a.mtime);
|
|
39596
39638
|
const now = Date.now();
|
|
39597
39639
|
const recent = entries.slice(0, limit).map((entry) => {
|
|
39598
|
-
const meta = parseHistorianDumpMeta2(
|
|
39640
|
+
const meta = parseHistorianDumpMeta2(join32(dir, entry.name));
|
|
39599
39641
|
const summary = {
|
|
39600
39642
|
name: entry.name,
|
|
39601
39643
|
ageMinutes: Math.round((now - entry.mtime) / 60000),
|
|
@@ -39659,7 +39701,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
|
|
|
39659
39701
|
const loaded = loadPiConfig({ cwd });
|
|
39660
39702
|
const storageResolution = getMagicContextStorageResolution();
|
|
39661
39703
|
const storageDirPath = storageResolution.path;
|
|
39662
|
-
const dbPath =
|
|
39704
|
+
const dbPath = join32(storageDirPath, "context.db");
|
|
39663
39705
|
const logFiles = inspectMagicContextLogs("pi");
|
|
39664
39706
|
const primaryLog = logFiles.find((file) => file.exists) ?? logFiles[0];
|
|
39665
39707
|
const otherPiExtensions = packages.filter((entry) => !isPiMagicContextPackageEntry(entry)).map(describePiPackageEntry);
|
|
@@ -39676,7 +39718,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
|
|
|
39676
39718
|
piVersion: pi ? getPiVersion(pi.path) : null,
|
|
39677
39719
|
settings: {
|
|
39678
39720
|
path: settingsPath,
|
|
39679
|
-
exists:
|
|
39721
|
+
exists: existsSync35(settingsPath),
|
|
39680
39722
|
...settingsParsed.parseError ? { parseError: settingsParsed.parseError } : {},
|
|
39681
39723
|
hasMagicContextPackage: hasPiMagicContextPackage(packages),
|
|
39682
39724
|
packages: sanitizeValue2(packages)
|
|
@@ -39693,7 +39735,7 @@ async function collectDiagnostics2(cwd = process.cwd()) {
|
|
|
39693
39735
|
storageDir: {
|
|
39694
39736
|
path: storageDirPath,
|
|
39695
39737
|
source: storageResolution.source,
|
|
39696
|
-
exists:
|
|
39738
|
+
exists: existsSync35(storageDirPath),
|
|
39697
39739
|
contextDbSizeBytes: fileSize2(dbPath)
|
|
39698
39740
|
},
|
|
39699
39741
|
conflicts: {
|
|
@@ -39792,13 +39834,14 @@ var init_diagnostics_pi = __esm(() => {
|
|
|
39792
39834
|
init_log_lines();
|
|
39793
39835
|
init_paths();
|
|
39794
39836
|
init_pi_helpers();
|
|
39837
|
+
init_pi_package_entry();
|
|
39795
39838
|
init_redaction2();
|
|
39796
39839
|
import_comment_json12 = __toESM(require_src3(), 1);
|
|
39797
39840
|
});
|
|
39798
39841
|
|
|
39799
39842
|
// src/lib/logs-pi.ts
|
|
39800
39843
|
import { mkdirSync as mkdirSync10, writeFileSync as writeFileSync9 } from "node:fs";
|
|
39801
|
-
import { dirname as dirname18, join as
|
|
39844
|
+
import { dirname as dirname18, join as join33 } from "node:path";
|
|
39802
39845
|
function sanitizeLogContent2(content) {
|
|
39803
39846
|
return sanitizeString2(content);
|
|
39804
39847
|
}
|
|
@@ -39868,11 +39911,11 @@ async function bundleIssueReport2(report, description, title, options = {}) {
|
|
|
39868
39911
|
const truncated = bodyMarkdown !== rawBodyMarkdown;
|
|
39869
39912
|
const cwd = options.cwd ?? process.cwd();
|
|
39870
39913
|
const timestamp = formatTimestamp2(options.now ?? new Date);
|
|
39871
|
-
const path = options.outputPath ??
|
|
39914
|
+
const path = options.outputPath ?? join33(cwd, `magic-context-pi-issue-${timestamp}.md`);
|
|
39872
39915
|
mkdirSync10(dirname18(path), { recursive: true });
|
|
39873
39916
|
writeFileSync9(path, `${bodyMarkdown}
|
|
39874
39917
|
`);
|
|
39875
|
-
const fullPath = truncated ? options.outputPath ? `${options.outputPath}.full.md` :
|
|
39918
|
+
const fullPath = truncated ? options.outputPath ? `${options.outputPath}.full.md` : join33(cwd, `magic-context-pi-issue-${timestamp}-full.md`) : undefined;
|
|
39876
39919
|
if (fullPath)
|
|
39877
39920
|
writeFileSync9(fullPath, `${rawBodyMarkdown}
|
|
39878
39921
|
`);
|
|
@@ -39886,10 +39929,10 @@ var init_logs_pi = __esm(() => {
|
|
|
39886
39929
|
|
|
39887
39930
|
// src/commands/doctor-pi.ts
|
|
39888
39931
|
import { execFileSync as execFileSync6, spawnSync as spawnSync8 } from "node:child_process";
|
|
39889
|
-
import { existsSync as
|
|
39932
|
+
import { existsSync as existsSync36, mkdirSync as mkdirSync11, readdirSync as readdirSync7, readFileSync as readFileSync25, rmSync as rmSync4, statSync as statSync17 } from "node:fs";
|
|
39890
39933
|
import { createRequire as createRequire8 } from "node:module";
|
|
39891
39934
|
import { homedir as homedir17 } from "node:os";
|
|
39892
|
-
import { dirname as dirname19, isAbsolute as
|
|
39935
|
+
import { dirname as dirname19, isAbsolute as isAbsolute8, join as join34 } from "node:path";
|
|
39893
39936
|
function depsFrom(options) {
|
|
39894
39937
|
return {
|
|
39895
39938
|
...DEFAULT_DEPS5,
|
|
@@ -39980,7 +40023,7 @@ function summarize(results) {
|
|
|
39980
40023
|
function readJsonc2(path) {
|
|
39981
40024
|
try {
|
|
39982
40025
|
return {
|
|
39983
|
-
value: import_comment_json13.parse(
|
|
40026
|
+
value: import_comment_json13.parse(readFileSync25(path, "utf-8"))
|
|
39984
40027
|
};
|
|
39985
40028
|
} catch (error) {
|
|
39986
40029
|
return {
|
|
@@ -40016,25 +40059,29 @@ function readMagicContextJsonc(path, tier) {
|
|
|
40016
40059
|
function packagesFrom(settings) {
|
|
40017
40060
|
return Array.isArray(settings.packages) ? settings.packages : [];
|
|
40018
40061
|
}
|
|
40062
|
+
function localPiMagicContextPackageDir2(entry) {
|
|
40063
|
+
return localPiMagicContextPackageDir(entry, getPiAgentConfigDir());
|
|
40064
|
+
}
|
|
40065
|
+
function isConfiguredPiMagicContextEntry2(entry) {
|
|
40066
|
+
return isConfiguredPiMagicContextEntry(entry, getPiAgentConfigDir());
|
|
40067
|
+
}
|
|
40019
40068
|
function piPluginDirCandidates(packages, cwd) {
|
|
40020
40069
|
const dirs = [];
|
|
40021
40070
|
const agentDir = getPiAgentConfigDir();
|
|
40022
40071
|
for (const entry of packages) {
|
|
40023
|
-
const
|
|
40024
|
-
if (
|
|
40025
|
-
|
|
40026
|
-
const resolved = isAbsolute7(spec) ? spec : join33(agentDir, spec);
|
|
40027
|
-
dirs.push(resolved);
|
|
40072
|
+
const resolved = localPiMagicContextPackageDir2(entry);
|
|
40073
|
+
if (resolved)
|
|
40074
|
+
dirs.push(resolved);
|
|
40028
40075
|
}
|
|
40029
|
-
dirs.push(
|
|
40030
|
-
dirs.push(
|
|
40031
|
-
return dirs.filter((dir) =>
|
|
40076
|
+
dirs.push(join34(agentDir, "npm", "node_modules", PACKAGE_NAME2));
|
|
40077
|
+
dirs.push(join34(cwd, ".pi", "npm", "node_modules", PACKAGE_NAME2));
|
|
40078
|
+
return dirs.filter((dir) => existsSync36(join34(dir, "package.json")));
|
|
40032
40079
|
}
|
|
40033
40080
|
function projectConfigPath(cwd) {
|
|
40034
40081
|
return resolveCortexKitProjectConfigPath(cwd);
|
|
40035
40082
|
}
|
|
40036
40083
|
function readConfigForEmbedding(path, isProjectConfig) {
|
|
40037
|
-
if (!
|
|
40084
|
+
if (!existsSync36(path))
|
|
40038
40085
|
return null;
|
|
40039
40086
|
try {
|
|
40040
40087
|
const raw = loadRawConfigFile({
|
|
@@ -40120,22 +40167,22 @@ function pinnedVersionFromPackageSpecifier(specifier) {
|
|
|
40120
40167
|
}
|
|
40121
40168
|
function cacheRoots(cwd) {
|
|
40122
40169
|
const home = process.env.HOME?.trim();
|
|
40123
|
-
const cacheHome = process.env.XDG_CACHE_HOME ||
|
|
40170
|
+
const cacheHome = process.env.XDG_CACHE_HOME || join34(home || homedir17(), ".cache");
|
|
40124
40171
|
const piCacheRoot = getPiCacheRoot();
|
|
40125
40172
|
return [
|
|
40126
|
-
|
|
40127
|
-
|
|
40128
|
-
|
|
40129
|
-
|
|
40130
|
-
|
|
40131
|
-
|
|
40132
|
-
|
|
40173
|
+
join34(piCacheRoot, "extensions"),
|
|
40174
|
+
join34(piCacheRoot, "packages"),
|
|
40175
|
+
join34(cacheHome, "pi", "extensions"),
|
|
40176
|
+
join34(cacheHome, "pi", "packages"),
|
|
40177
|
+
join34(getPiAgentConfigDir(), "cache", "extensions"),
|
|
40178
|
+
join34(getPiAgentConfigDir(), "npm", "node_modules", PACKAGE_NAME2),
|
|
40179
|
+
join34(cwd, ".pi", "npm", "node_modules", PACKAGE_NAME2)
|
|
40133
40180
|
];
|
|
40134
40181
|
}
|
|
40135
40182
|
function findPiMagicContextCacheDirs(cwd, expectedVersion, force = false) {
|
|
40136
40183
|
const found = new Map;
|
|
40137
40184
|
const visit = (path, depth) => {
|
|
40138
|
-
if (depth < 0 || !
|
|
40185
|
+
if (depth < 0 || !existsSync36(path))
|
|
40139
40186
|
return;
|
|
40140
40187
|
let stat;
|
|
40141
40188
|
try {
|
|
@@ -40145,10 +40192,10 @@ function findPiMagicContextCacheDirs(cwd, expectedVersion, force = false) {
|
|
|
40145
40192
|
}
|
|
40146
40193
|
if (!stat.isDirectory())
|
|
40147
40194
|
return;
|
|
40148
|
-
const packageJson =
|
|
40149
|
-
if (
|
|
40195
|
+
const packageJson = join34(path, "package.json");
|
|
40196
|
+
if (existsSync36(packageJson)) {
|
|
40150
40197
|
try {
|
|
40151
|
-
const pkg = JSON.parse(
|
|
40198
|
+
const pkg = JSON.parse(readFileSync25(packageJson, "utf-8"));
|
|
40152
40199
|
const name = typeof pkg.name === "string" ? pkg.name : "";
|
|
40153
40200
|
const version = typeof pkg.version === "string" ? pkg.version : undefined;
|
|
40154
40201
|
if (name === PACKAGE_NAME2) {
|
|
@@ -40168,7 +40215,7 @@ function findPiMagicContextCacheDirs(cwd, expectedVersion, force = false) {
|
|
|
40168
40215
|
return;
|
|
40169
40216
|
}
|
|
40170
40217
|
for (const entry of entries)
|
|
40171
|
-
visit(
|
|
40218
|
+
visit(join34(path, entry), depth - 1);
|
|
40172
40219
|
};
|
|
40173
40220
|
for (const root of cacheRoots(cwd))
|
|
40174
40221
|
visit(root, 5);
|
|
@@ -40213,7 +40260,7 @@ async function runHealthChecks2(options) {
|
|
|
40213
40260
|
}
|
|
40214
40261
|
const settingsPath = getPiUserExtensionsPath();
|
|
40215
40262
|
let packages = [];
|
|
40216
|
-
if (!
|
|
40263
|
+
if (!existsSync36(settingsPath)) {
|
|
40217
40264
|
add2(results, "fail", `Pi settings not found at ${settingsPath}`);
|
|
40218
40265
|
repairPlan.addPackageEntry = true;
|
|
40219
40266
|
} else {
|
|
@@ -40237,7 +40284,7 @@ async function runHealthChecks2(options) {
|
|
|
40237
40284
|
["user", userConfigPath, true],
|
|
40238
40285
|
["project", projectPath, false]
|
|
40239
40286
|
]) {
|
|
40240
|
-
if (!
|
|
40287
|
+
if (!existsSync36(path)) {
|
|
40241
40288
|
if (required) {
|
|
40242
40289
|
add2(results, "warn", `No ${label} magic-context.jsonc found at ${path}`);
|
|
40243
40290
|
if (userConfigMigrationRefused) {
|
|
@@ -40277,9 +40324,9 @@ async function runHealthChecks2(options) {
|
|
|
40277
40324
|
}
|
|
40278
40325
|
const storage = getMagicContextStorageResolution();
|
|
40279
40326
|
const storageDir = storage.path;
|
|
40280
|
-
const dbPath =
|
|
40327
|
+
const dbPath = join34(storageDir, "context.db");
|
|
40281
40328
|
add2(results, "info", `Shared storage: ${storageDir} (source: ${storage.source})`);
|
|
40282
|
-
const existedBeforeOpen =
|
|
40329
|
+
const existedBeforeOpen = existsSync36(dbPath);
|
|
40283
40330
|
if (existedBeforeOpen)
|
|
40284
40331
|
add2(results, "pass", `Shared context DB exists at ${dbPath}`);
|
|
40285
40332
|
else
|
|
@@ -40394,6 +40441,8 @@ ${formatDatabaseRepairGuidance(dbPath)}`);
|
|
|
40394
40441
|
add2(results, "info", "Embedding provider disabled");
|
|
40395
40442
|
} else {
|
|
40396
40443
|
let runtimeReported = false;
|
|
40444
|
+
let firstFallback = null;
|
|
40445
|
+
const brokenWarnings = [];
|
|
40397
40446
|
let runtimeUnverifiedReason = "no installed plugin tree found to inspect";
|
|
40398
40447
|
for (const pluginDir of piPluginDirCandidates(packages, options.cwd)) {
|
|
40399
40448
|
const runtime = checkLocalEmbeddingRuntimeByResolution(pluginDir, process.platform, process.arch, loadedConfig.config.embedding.provider === "local" ? loadedConfig.config.embedding.local_runtime : "auto", { isBun: false, isElectron: false });
|
|
@@ -40408,29 +40457,34 @@ ${formatDatabaseRepairGuidance(dbPath)}`);
|
|
|
40408
40457
|
break;
|
|
40409
40458
|
}
|
|
40410
40459
|
if (runtime.state === "wasm-fallback") {
|
|
40411
|
-
|
|
40412
|
-
|
|
40413
|
-
break;
|
|
40460
|
+
firstFallback ??= runtime;
|
|
40461
|
+
continue;
|
|
40414
40462
|
}
|
|
40415
40463
|
if (isLocalEmbeddingRuntimeBroken(runtime)) {
|
|
40416
|
-
|
|
40417
|
-
|
|
40418
|
-
break;
|
|
40464
|
+
brokenWarnings.push(`${formatLocalEmbeddingRuntimeDoctorWarning(runtime)} Candidate: ${pluginDir}`);
|
|
40465
|
+
continue;
|
|
40419
40466
|
}
|
|
40420
40467
|
if (runtime.state === "unknown")
|
|
40421
40468
|
runtimeUnverifiedReason = runtime.reason;
|
|
40422
40469
|
}
|
|
40423
40470
|
if (!runtimeReported) {
|
|
40424
|
-
|
|
40471
|
+
if (firstFallback) {
|
|
40472
|
+
add2(results, "warn", formatLocalEmbeddingRuntimeWasmFallback(firstFallback));
|
|
40473
|
+
} else if (brokenWarnings.length > 0) {
|
|
40474
|
+
for (const warning of brokenWarnings)
|
|
40475
|
+
add2(results, "warn", warning);
|
|
40476
|
+
} else {
|
|
40477
|
+
add2(results, "warn", `Embedding provider ${loadedConfig.config.embedding.provider}: selected runtime unverified (${runtimeUnverifiedReason})`);
|
|
40478
|
+
}
|
|
40425
40479
|
}
|
|
40426
40480
|
}
|
|
40427
|
-
const piEntries = packages.filter(
|
|
40481
|
+
const piEntries = packages.filter(isConfiguredPiMagicContextEntry2).map(describePiPackageEntry);
|
|
40428
40482
|
if (piEntries.length > 1) {
|
|
40429
40483
|
add2(results, "fail", `Multiple magic-context entries in Pi packages[] — this loads the plugin twice: ${piEntries.join(", ")}`);
|
|
40430
40484
|
} else {
|
|
40431
40485
|
add2(results, "pass", "No conflicting magic-context entries in Pi packages[]");
|
|
40432
40486
|
}
|
|
40433
|
-
const otherExtensions = packages.filter((entry) => !
|
|
40487
|
+
const otherExtensions = packages.filter((entry) => !isConfiguredPiMagicContextEntry2(entry)).map(describePiPackageEntry);
|
|
40434
40488
|
if (otherExtensions.length > 0) {
|
|
40435
40489
|
add2(results, "info", `Other Pi extensions registered: ${otherExtensions.join(", ")}`);
|
|
40436
40490
|
} else {
|
|
@@ -40507,7 +40561,7 @@ function repair2(plan, prompts) {
|
|
|
40507
40561
|
}
|
|
40508
40562
|
if (plan.writeUserConfig) {
|
|
40509
40563
|
const configPath = getPiUserConfigPath();
|
|
40510
|
-
if (!
|
|
40564
|
+
if (!existsSync36(configPath)) {
|
|
40511
40565
|
try {
|
|
40512
40566
|
writeDefaultMagicContextConfig(configPath);
|
|
40513
40567
|
prompts.log.success(`Wrote default Magic Context config to ${configPath}`);
|
|
@@ -40559,7 +40613,7 @@ async function runIssueFlow3(options) {
|
|
|
40559
40613
|
if (options.reportPath) {
|
|
40560
40614
|
try {
|
|
40561
40615
|
const report = await options.deps.collectDiagnostics(options.cwd);
|
|
40562
|
-
const outputPath =
|
|
40616
|
+
const outputPath = isAbsolute8(options.reportPath) ? options.reportPath : join34(options.cwd, options.reportPath);
|
|
40563
40617
|
const bundled = await bundleIssueReport2(report, "Generated non-interactively by `doctor --issue --report`.", "Magic Context diagnostic report", { cwd: options.cwd, now: options.deps.now(), outputPath });
|
|
40564
40618
|
options.prompts.log.info(`Report written to ${bundled.path}`);
|
|
40565
40619
|
return 0;
|
|
@@ -40643,7 +40697,7 @@ async function runDoctor3(options = {}) {
|
|
|
40643
40697
|
const v22Result = await runV22BackfillCommands({
|
|
40644
40698
|
name: "Pi",
|
|
40645
40699
|
openDatabase: (readonly = true) => {
|
|
40646
|
-
const dbPath =
|
|
40700
|
+
const dbPath = join34(getMagicContextStorageDir(), "context.db");
|
|
40647
40701
|
v22Db = readonly ? openExistingContextDatabase(dbPath, { readonly: true }) : openExistingContextDatabaseForMutation(dbPath);
|
|
40648
40702
|
return v22Db;
|
|
40649
40703
|
},
|
|
@@ -40730,6 +40784,7 @@ var init_doctor_pi = __esm(async () => {
|
|
|
40730
40784
|
init_logs_pi();
|
|
40731
40785
|
init_paths();
|
|
40732
40786
|
init_pi_helpers();
|
|
40787
|
+
init_pi_package_entry();
|
|
40733
40788
|
init_prompts();
|
|
40734
40789
|
init_redaction2();
|
|
40735
40790
|
init_setup_pi();
|
|
@@ -40757,8 +40812,8 @@ var init_doctor_pi = __esm(async () => {
|
|
|
40757
40812
|
});
|
|
40758
40813
|
|
|
40759
40814
|
// src/commands/doctor.ts
|
|
40760
|
-
import { existsSync as
|
|
40761
|
-
import { join as
|
|
40815
|
+
import { existsSync as existsSync37, rmSync as rmSync5 } from "node:fs";
|
|
40816
|
+
import { join as join35 } from "node:path";
|
|
40762
40817
|
async function runDoctor4(options) {
|
|
40763
40818
|
if (options.clear)
|
|
40764
40819
|
return runClear();
|
|
@@ -40776,7 +40831,7 @@ async function runDoctor4(options) {
|
|
|
40776
40831
|
const result = await runV22BackfillCommands({
|
|
40777
40832
|
name: "Magic Context",
|
|
40778
40833
|
openDatabase: (readonly = true) => {
|
|
40779
|
-
const dbPath =
|
|
40834
|
+
const dbPath = join35(getMagicContextStorageDir(), "context.db");
|
|
40780
40835
|
v22Db = readonly ? openExistingContextDatabase(dbPath, { readonly: true }) : openExistingContextDatabaseForMutation(dbPath);
|
|
40781
40836
|
return v22Db;
|
|
40782
40837
|
},
|
|
@@ -40790,7 +40845,7 @@ async function runDoctor4(options) {
|
|
|
40790
40845
|
return result.exitCode;
|
|
40791
40846
|
}
|
|
40792
40847
|
await init_migrate();
|
|
40793
|
-
const sweepDbPath =
|
|
40848
|
+
const sweepDbPath = join35(getMagicContextStorageDir(), "context.db");
|
|
40794
40849
|
let sweepDb = null;
|
|
40795
40850
|
try {
|
|
40796
40851
|
sweepDb = openExistingContextDatabaseForMutation(sweepDbPath);
|
|
@@ -40888,7 +40943,7 @@ async function runClear() {
|
|
|
40888
40943
|
const s = spinner2();
|
|
40889
40944
|
s.start(`Clearing ${item.path}`);
|
|
40890
40945
|
try {
|
|
40891
|
-
if (
|
|
40946
|
+
if (existsSync37(item.path)) {
|
|
40892
40947
|
rmSync5(item.path, { recursive: true, force: true });
|
|
40893
40948
|
}
|
|
40894
40949
|
s.stop(`Cleared ${item.path}`);
|