@cortexkit/opencode-magic-context 0.8.9 → 0.8.10

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 CHANGED
@@ -30221,28 +30221,60 @@ function getModelsJsonPath() {
30221
30221
  }
30222
30222
  return join11(cacheBase, "opencode", "models.json");
30223
30223
  }
30224
+ function getOpencodeConfigPath() {
30225
+ const envDir = process.env.OPENCODE_CONFIG_DIR?.trim();
30226
+ const configDir = envDir ? envDir : platform2() === "win32" ? join11(homedir5(), ".config", "opencode") : join11(process.env.XDG_CONFIG_HOME || join11(homedir5(), ".config"), "opencode");
30227
+ const jsonc = join11(configDir, "opencode.jsonc");
30228
+ if (existsSync5(jsonc))
30229
+ return jsonc;
30230
+ const json2 = join11(configDir, "opencode.json");
30231
+ if (existsSync5(json2))
30232
+ return json2;
30233
+ return null;
30234
+ }
30224
30235
  function loadModelsDevLimits() {
30225
30236
  const limits = new Map;
30226
- const filePath = getModelsJsonPath();
30237
+ const modelsJsonPath = getModelsJsonPath();
30227
30238
  try {
30228
- if (!existsSync5(filePath)) {
30229
- return limits;
30230
- }
30231
- const raw = readFileSync4(filePath, "utf-8");
30232
- const data = JSON.parse(raw);
30233
- for (const [providerId, provider2] of Object.entries(data)) {
30234
- if (!provider2?.models || typeof provider2.models !== "object")
30235
- continue;
30236
- for (const [modelId, model] of Object.entries(provider2.models)) {
30237
- const context = model?.limit?.context;
30238
- if (typeof context === "number" && context > 0) {
30239
- limits.set(`${providerId}/${modelId}`, context);
30239
+ if (existsSync5(modelsJsonPath)) {
30240
+ const raw = readFileSync4(modelsJsonPath, "utf-8");
30241
+ const data = JSON.parse(raw);
30242
+ for (const [providerId, provider2] of Object.entries(data)) {
30243
+ if (!provider2?.models || typeof provider2.models !== "object")
30244
+ continue;
30245
+ for (const [modelId, model] of Object.entries(provider2.models)) {
30246
+ const context = model?.limit?.context;
30247
+ if (typeof context === "number" && context > 0) {
30248
+ limits.set(`${providerId}/${modelId}`, context);
30249
+ }
30240
30250
  }
30241
30251
  }
30242
30252
  }
30243
30253
  } catch (error48) {
30244
30254
  sessionLog("global", "models-dev-cache: failed to read models.json:", error48 instanceof Error ? error48.message : String(error48));
30245
30255
  }
30256
+ try {
30257
+ const configPath = getOpencodeConfigPath();
30258
+ if (configPath && existsSync5(configPath)) {
30259
+ let raw = readFileSync4(configPath, "utf-8");
30260
+ raw = raw.replace(/\/\/.*$/gm, "");
30261
+ const config2 = JSON.parse(raw);
30262
+ if (config2.provider && typeof config2.provider === "object") {
30263
+ for (const [providerId, provider2] of Object.entries(config2.provider)) {
30264
+ if (!provider2?.models || typeof provider2.models !== "object")
30265
+ continue;
30266
+ for (const [modelId, model] of Object.entries(provider2.models)) {
30267
+ const context = model?.limit?.context;
30268
+ if (typeof context === "number" && context > 0) {
30269
+ limits.set(`${providerId}/${modelId}`, context);
30270
+ }
30271
+ }
30272
+ }
30273
+ }
30274
+ }
30275
+ } catch (error48) {
30276
+ sessionLog("global", "models-dev-cache: failed to read opencode config for custom models:", error48 instanceof Error ? error48.message : String(error48));
30277
+ }
30246
30278
  return limits;
30247
30279
  }
30248
30280
  function getModelsDevContextLimit(providerID, modelID) {
@@ -1 +1 @@
1
- {"version":3,"file":"models-dev-cache.d.ts","sourceRoot":"","sources":["../../src/shared/models-dev-cache.ts"],"names":[],"mappings":"AAuEA;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAShG;AAED,8CAA8C;AAC9C,wBAAgB,mBAAmB,IAAI,IAAI,CAG1C"}
1
+ {"version":3,"file":"models-dev-cache.d.ts","sourceRoot":"","sources":["../../src/shared/models-dev-cache.ts"],"names":[],"mappings":"AA0HA;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAShG;AAED,8CAA8C;AAC9C,wBAAgB,mBAAmB,IAAI,IAAI,CAG1C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/opencode-magic-context",
3
- "version": "0.8.9",
3
+ "version": "0.8.10",
4
4
  "type": "module",
5
5
  "description": "OpenCode plugin for Magic Context — cross-session memory and context management",
6
6
  "main": "dist/index.js",
@@ -34,27 +34,42 @@ function getModelsJsonPath(): string {
34
34
  return join(cacheBase, "opencode", "models.json");
35
35
  }
36
36
 
37
+ function getOpencodeConfigPath(): string | null {
38
+ const envDir = process.env.OPENCODE_CONFIG_DIR?.trim();
39
+ const configDir = envDir
40
+ ? envDir
41
+ : platform() === "win32"
42
+ ? join(homedir(), ".config", "opencode")
43
+ : join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "opencode");
44
+
45
+ // Check jsonc first, then json (matches OpenCode's own lookup order)
46
+ const jsonc = join(configDir, "opencode.jsonc");
47
+ if (existsSync(jsonc)) return jsonc;
48
+ const json = join(configDir, "opencode.json");
49
+ if (existsSync(json)) return json;
50
+ return null;
51
+ }
52
+
37
53
  function loadModelsDevLimits(): Map<string, number> {
38
54
  const limits = new Map<string, number>();
39
- const filePath = getModelsJsonPath();
40
55
 
56
+ // 1. Load from OpenCode's models.dev cache (base layer — all known public models)
57
+ const modelsJsonPath = getModelsJsonPath();
41
58
  try {
42
- if (!existsSync(filePath)) {
43
- return limits;
44
- }
59
+ if (existsSync(modelsJsonPath)) {
60
+ const raw = readFileSync(modelsJsonPath, "utf-8");
61
+ const data = JSON.parse(raw) as Record<
62
+ string,
63
+ { models?: Record<string, { limit?: { context?: number } }> }
64
+ >;
45
65
 
46
- const raw = readFileSync(filePath, "utf-8");
47
- const data = JSON.parse(raw) as Record<
48
- string,
49
- { models?: Record<string, { limit?: { context?: number } }> }
50
- >;
51
-
52
- for (const [providerId, provider] of Object.entries(data)) {
53
- if (!provider?.models || typeof provider.models !== "object") continue;
54
- for (const [modelId, model] of Object.entries(provider.models)) {
55
- const context = model?.limit?.context;
56
- if (typeof context === "number" && context > 0) {
57
- limits.set(`${providerId}/${modelId}`, context);
66
+ for (const [providerId, provider] of Object.entries(data)) {
67
+ if (!provider?.models || typeof provider.models !== "object") continue;
68
+ for (const [modelId, model] of Object.entries(provider.models)) {
69
+ const context = model?.limit?.context;
70
+ if (typeof context === "number" && context > 0) {
71
+ limits.set(`${providerId}/${modelId}`, context);
72
+ }
58
73
  }
59
74
  }
60
75
  }
@@ -66,6 +81,42 @@ function loadModelsDevLimits(): Map<string, number> {
66
81
  );
67
82
  }
68
83
 
84
+ // 2. Overlay custom provider models from OpenCode config (higher priority).
85
+ // Users define custom/proxy models via provider.<id>.models.<name>.limit.context
86
+ // in opencode.json(c). These override models.dev entries for the same key.
87
+ try {
88
+ const configPath = getOpencodeConfigPath();
89
+ if (configPath && existsSync(configPath)) {
90
+ let raw = readFileSync(configPath, "utf-8");
91
+ // Strip JSONC comments (single-line only — sufficient for OpenCode configs)
92
+ raw = raw.replace(/\/\/.*$/gm, "");
93
+ const config = JSON.parse(raw) as {
94
+ provider?: Record<
95
+ string,
96
+ { models?: Record<string, { limit?: { context?: number } }> }
97
+ >;
98
+ };
99
+
100
+ if (config.provider && typeof config.provider === "object") {
101
+ for (const [providerId, provider] of Object.entries(config.provider)) {
102
+ if (!provider?.models || typeof provider.models !== "object") continue;
103
+ for (const [modelId, model] of Object.entries(provider.models)) {
104
+ const context = model?.limit?.context;
105
+ if (typeof context === "number" && context > 0) {
106
+ limits.set(`${providerId}/${modelId}`, context);
107
+ }
108
+ }
109
+ }
110
+ }
111
+ }
112
+ } catch (error) {
113
+ sessionLog(
114
+ "global",
115
+ "models-dev-cache: failed to read opencode config for custom models:",
116
+ error instanceof Error ? error.message : String(error),
117
+ );
118
+ }
119
+
69
120
  return limits;
70
121
  }
71
122