@cortexkit/opencode-magic-context 0.7.4 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +25 -0
  2. package/dist/agents/magic-context-prompt.d.ts +1 -1
  3. package/dist/agents/magic-context-prompt.d.ts.map +1 -1
  4. package/dist/cli/config-paths.d.ts.map +1 -1
  5. package/dist/cli/doctor.d.ts.map +1 -1
  6. package/dist/cli.js +105 -3
  7. package/dist/config/schema/magic-context.d.ts +3 -0
  8. package/dist/config/schema/magic-context.d.ts.map +1 -1
  9. package/dist/features/magic-context/dreamer/runner.d.ts.map +1 -1
  10. package/dist/features/magic-context/dreamer/task-prompts.d.ts.map +1 -1
  11. package/dist/features/magic-context/memory/embedding.d.ts +5 -0
  12. package/dist/features/magic-context/memory/embedding.d.ts.map +1 -1
  13. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  14. package/dist/features/magic-context/storage-meta-persisted.d.ts +8 -0
  15. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  16. package/dist/features/magic-context/storage-meta.d.ts +1 -1
  17. package/dist/features/magic-context/storage-meta.d.ts.map +1 -1
  18. package/dist/features/magic-context/storage-tags.d.ts +2 -1
  19. package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
  20. package/dist/features/magic-context/storage.d.ts +2 -2
  21. package/dist/features/magic-context/storage.d.ts.map +1 -1
  22. package/dist/features/magic-context/tagger.d.ts +1 -1
  23. package/dist/features/magic-context/tagger.d.ts.map +1 -1
  24. package/dist/features/magic-context/types.d.ts +3 -0
  25. package/dist/features/magic-context/types.d.ts.map +1 -1
  26. package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
  27. package/dist/hooks/magic-context/compartment-runner-compressor.d.ts.map +1 -1
  28. package/dist/hooks/magic-context/compartment-runner-historian.d.ts +1 -0
  29. package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
  30. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts +2 -0
  31. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
  32. package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
  33. package/dist/hooks/magic-context/compartment-runner-types.d.ts +1 -0
  34. package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
  35. package/dist/hooks/magic-context/compartment-runner.d.ts.map +1 -1
  36. package/dist/hooks/magic-context/compartment-trigger.d.ts +1 -1
  37. package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
  38. package/dist/hooks/magic-context/event-handler.d.ts +2 -0
  39. package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
  40. package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
  41. package/dist/hooks/magic-context/heuristic-cleanup.d.ts +1 -0
  42. package/dist/hooks/magic-context/heuristic-cleanup.d.ts.map +1 -1
  43. package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
  44. package/dist/hooks/magic-context/hook.d.ts +1 -0
  45. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  46. package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
  47. package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
  48. package/dist/hooks/magic-context/system-prompt-hash.d.ts +1 -0
  49. package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
  50. package/dist/hooks/magic-context/tag-messages.d.ts +1 -0
  51. package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
  52. package/dist/hooks/magic-context/tool-drop-target.d.ts +2 -1
  53. package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -1
  54. package/dist/hooks/magic-context/transform-compartment-phase.d.ts +4 -0
  55. package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
  56. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +3 -4
  57. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  58. package/dist/hooks/magic-context/transform.d.ts +4 -0
  59. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  60. package/dist/index.js +2492 -1836
  61. package/dist/plugin/dream-timer.d.ts.map +1 -1
  62. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  63. package/dist/shared/models-dev-cache.d.ts +9 -0
  64. package/dist/shared/models-dev-cache.d.ts.map +1 -0
  65. package/package.json +2 -2
  66. package/src/shared/models-dev-cache.ts +92 -0
@@ -1 +1 @@
1
- {"version":3,"file":"dream-timer.d.ts","sourceRoot":"","sources":["../../src/plugin/dream-timer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAMrF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAK7C;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,eAAe,EAAE,eAAe,CAAC;IACjC,aAAa,EAAE,OAAO,CAAC;IACvB,wBAAwB,CAAC,EAAE;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,kBAAkB,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5E,uBAAuB,CAAC,EAAE;QACtB,OAAO,EAAE,OAAO,CAAC;QACjB,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC;KACrB,CAAC;CACL,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAuE3B"}
1
+ {"version":3,"file":"dream-timer.d.ts","sourceRoot":"","sources":["../../src/plugin/dream-timer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAKrF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAS7C;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,eAAe,EAAE,eAAe,CAAC;IACjC,aAAa,EAAE,OAAO,CAAC;IACvB,wBAAwB,CAAC,EAAE;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,kBAAkB,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5E,uBAAuB,CAAC,EAAE;QACtB,OAAO,EAAE,OAAO,CAAC;QACjB,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC;KACrB,CAAC;CACL,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAoF3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"create-session-hooks.d.ts","sourceRoot":"","sources":["../../../src/plugin/hooks/create-session-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAU7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACrC,GAAG,EAAE,aAAa,CAAC;IACnB,YAAY,EAAE,wBAAwB,CAAC;CAC1C;;;;;;qBA4Cq4B,CAAC;;;;;;;;;;;;qBATv3B,CAAN;mBAAiB,CAAC;;;;;0BASwvY,CAAC;;;;;;EADpxY"}
1
+ {"version":3,"file":"create-session-hooks.d.ts","sourceRoot":"","sources":["../../../src/plugin/hooks/create-session-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAU7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACrC,GAAG,EAAE,aAAa,CAAC;IACnB,YAAY,EAAE,wBAAwB,CAAC;CAC1C;;;;;;qBA6C81B,CAAC;;;;;;;;;;;;qBAT5zB,CAAC;mBAAiB,CAAC;;;;;0BASiwZ,CAAC;;;;;;EADxzZ"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Get the context limit for a specific provider/model from OpenCode's models.dev cache.
3
+ * Returns undefined if the model is not found or the cache is unavailable.
4
+ * Results are cached in memory and refreshed every 5 minutes.
5
+ */
6
+ export declare function getModelsDevContextLimit(providerID: string, modelID: string): number | undefined;
7
+ /** Clear the in-memory cache (for testing) */
8
+ export declare function clearModelsDevCache(): void;
9
+ //# sourceMappingURL=models-dev-cache.d.ts.map
@@ -0,0 +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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/opencode-magic-context",
3
- "version": "0.7.4",
3
+ "version": "0.8.1",
4
4
  "type": "module",
5
5
  "description": "OpenCode plugin for Magic Context — cross-session memory and context management",
6
6
  "main": "dist/index.js",
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@clack/prompts": "^1.1.0",
47
- "@huggingface/transformers": "^3.5.1",
47
+ "@huggingface/transformers": "~3.7.6",
48
48
  "@opencode-ai/plugin": "^1.2.26",
49
49
  "@opencode-ai/sdk": "^1.2.26",
50
50
  "ai-tokenizer": "^1.0.6",
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Read model context limits from OpenCode's models.dev cache file.
3
+ *
4
+ * OpenCode fetches model metadata from models.dev and caches it at:
5
+ * <xdg_cache>/opencode/models.json
6
+ *
7
+ * This file contains per-provider, per-model data including `limit.context`.
8
+ * We read it lazily and refresh periodically to get accurate context limits
9
+ * without requiring user configuration.
10
+ */
11
+ import { existsSync, readFileSync } from "node:fs";
12
+ import { homedir, platform } from "node:os";
13
+ import { join } from "node:path";
14
+ import { sessionLog } from "./logger";
15
+
16
+ /** Resolved context limits keyed by "providerID/modelID" */
17
+ let cachedLimits: Map<string, number> | null = null;
18
+ let lastLoadAttempt = 0;
19
+ const RELOAD_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes, matches OpenCode's TTL
20
+
21
+ function getModelsJsonPath(): string {
22
+ const xdgCache = process.env.XDG_CACHE_HOME;
23
+ const os = platform();
24
+
25
+ let cacheBase: string;
26
+ if (xdgCache) {
27
+ cacheBase = xdgCache;
28
+ } else if (os === "win32") {
29
+ cacheBase = process.env.LOCALAPPDATA ?? join(homedir(), "AppData", "Local");
30
+ } else {
31
+ cacheBase = join(homedir(), ".cache");
32
+ }
33
+
34
+ return join(cacheBase, "opencode", "models.json");
35
+ }
36
+
37
+ function loadModelsDevLimits(): Map<string, number> {
38
+ const limits = new Map<string, number>();
39
+ const filePath = getModelsJsonPath();
40
+
41
+ try {
42
+ if (!existsSync(filePath)) {
43
+ return limits;
44
+ }
45
+
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);
58
+ }
59
+ }
60
+ }
61
+ } catch (error) {
62
+ sessionLog(
63
+ "global",
64
+ "models-dev-cache: failed to read models.json:",
65
+ error instanceof Error ? error.message : String(error),
66
+ );
67
+ }
68
+
69
+ return limits;
70
+ }
71
+
72
+ /**
73
+ * Get the context limit for a specific provider/model from OpenCode's models.dev cache.
74
+ * Returns undefined if the model is not found or the cache is unavailable.
75
+ * Results are cached in memory and refreshed every 5 minutes.
76
+ */
77
+ export function getModelsDevContextLimit(providerID: string, modelID: string): number | undefined {
78
+ const now = Date.now();
79
+
80
+ if (!cachedLimits || now - lastLoadAttempt > RELOAD_INTERVAL_MS) {
81
+ lastLoadAttempt = now;
82
+ cachedLimits = loadModelsDevLimits();
83
+ }
84
+
85
+ return cachedLimits.get(`${providerID}/${modelID}`);
86
+ }
87
+
88
+ /** Clear the in-memory cache (for testing) */
89
+ export function clearModelsDevCache(): void {
90
+ cachedLimits = null;
91
+ lastLoadAttempt = 0;
92
+ }