@cortexkit/opencode-magic-context 0.34.2 → 0.35.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 (109) hide show
  1. package/README.md +3 -1
  2. package/dist/agents/hidden-agent-registrations.d.ts +10 -2
  3. package/dist/agents/hidden-agent-registrations.d.ts.map +1 -1
  4. package/dist/agents/magic-context-prompt.d.ts +2 -1
  5. package/dist/agents/magic-context-prompt.d.ts.map +1 -1
  6. package/dist/agents/permissions.d.ts +4 -3
  7. package/dist/agents/permissions.d.ts.map +1 -1
  8. package/dist/config/index.d.ts +3 -0
  9. package/dist/config/index.d.ts.map +1 -1
  10. package/dist/config/project-security.d.ts +3 -0
  11. package/dist/config/project-security.d.ts.map +1 -1
  12. package/dist/config/schema/agent-overrides.d.ts +1 -1
  13. package/dist/config/schema/magic-context.d.ts +51 -10
  14. package/dist/config/schema/magic-context.d.ts.map +1 -1
  15. package/dist/{conflict-warning-hook-fvpfvt0w.js → conflict-warning-hook-p2pmhvn7.js} +2 -1
  16. package/dist/features/magic-context/context-authority.d.ts.map +1 -1
  17. package/dist/features/magic-context/dreamer/provider-output-failure.d.ts +15 -0
  18. package/dist/features/magic-context/dreamer/provider-output-failure.d.ts.map +1 -0
  19. package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
  20. package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
  21. package/dist/features/magic-context/mural/compress-cues.d.ts +6 -2
  22. package/dist/features/magic-context/mural/compress-cues.d.ts.map +1 -1
  23. package/dist/features/magic-context/mural/storage-mural-cues.d.ts +4 -4
  24. package/dist/hooks/magic-context/compartment-prompt.d.ts +6 -6
  25. package/dist/hooks/magic-context/compartment-prompt.d.ts.map +1 -1
  26. package/dist/hooks/magic-context/compartment-runner-historian.d.ts +2 -14
  27. package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
  28. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
  29. package/dist/hooks/magic-context/compartment-runner-validation.d.ts +16 -2
  30. package/dist/hooks/magic-context/compartment-runner-validation.d.ts.map +1 -1
  31. package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
  32. package/dist/hooks/magic-context/hook.d.ts +10 -3
  33. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  34. package/dist/hooks/magic-context/module-state-sync.d.ts +1 -1
  35. package/dist/hooks/magic-context/module-state-sync.d.ts.map +1 -1
  36. package/dist/hooks/magic-context/module-transport.d.ts +2 -1
  37. package/dist/hooks/magic-context/module-transport.d.ts.map +1 -1
  38. package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
  39. package/dist/hooks/magic-context/read-session-chunk.d.ts +5 -0
  40. package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
  41. package/dist/hooks/magic-context/read-session-formatting.d.ts.map +1 -1
  42. package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts +2 -0
  43. package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
  44. package/dist/hooks/magic-context/rust-mode-transform.d.ts +6 -0
  45. package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
  46. package/dist/hooks/magic-context/system-prompt-hash.d.ts +19 -5
  47. package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
  48. package/dist/hooks/magic-context/transform.d.ts +3 -0
  49. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  50. package/dist/index-0c9dmw9m.js +116 -0
  51. package/dist/{index-dtas91s5.js → index-8aaadh98.js} +7 -119
  52. package/dist/index-dpdnjawy.js +2892 -0
  53. package/dist/{index-z70pxrq1.js → index-fkyamz2w.js} +732 -613
  54. package/dist/{index-cn960ffd.js → index-h5zjfesc.js} +1 -1
  55. package/dist/{index-fcyvznch.js → index-w0nygb4p.js} +45 -2
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +843 -818
  58. package/dist/plugin/hooks/create-session-hooks.d.ts +12 -0
  59. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  60. package/dist/plugin/rpc-handlers.d.ts +1 -0
  61. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  62. package/dist/plugin/tool-registry.d.ts +4 -0
  63. package/dist/plugin/tool-registry.d.ts.map +1 -1
  64. package/dist/{recomp-orchestrator-6cd3nrt7.js → recomp-orchestrator-29f4rqax.js} +5 -4
  65. package/dist/{send-session-notification-6njqewzk.js → send-session-notification-sr5g06hz.js} +2 -2
  66. package/dist/shared/index.d.ts +2 -0
  67. package/dist/shared/index.d.ts.map +1 -1
  68. package/dist/shared/prompt-surface-a1-golden.d.ts +28 -0
  69. package/dist/shared/prompt-surface-a1-golden.d.ts.map +1 -0
  70. package/dist/shared/prompt-surface-runtime.d.ts +43 -0
  71. package/dist/shared/prompt-surface-runtime.d.ts.map +1 -0
  72. package/dist/shared/prompt-surface.d.ts +49 -0
  73. package/dist/shared/prompt-surface.d.ts.map +1 -0
  74. package/dist/shared/sqlite.d.ts +13 -0
  75. package/dist/shared/sqlite.d.ts.map +1 -1
  76. package/dist/{storage-meta-session-xt41zbw4.js → storage-meta-session-ev8b55a9.js} +2 -2
  77. package/dist/tools/ctx-expand/tools.d.ts +1 -0
  78. package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
  79. package/dist/tools/ctx-memory/tools.d.ts +1 -0
  80. package/dist/tools/ctx-memory/tools.d.ts.map +1 -1
  81. package/dist/tools/ctx-note/tools.d.ts +1 -0
  82. package/dist/tools/ctx-note/tools.d.ts.map +1 -1
  83. package/dist/tools/ctx-reduce/tools.d.ts +1 -0
  84. package/dist/tools/ctx-reduce/tools.d.ts.map +1 -1
  85. package/dist/tools/ctx-search/tools.d.ts +1 -0
  86. package/dist/tools/ctx-search/tools.d.ts.map +1 -1
  87. package/dist/tools/light-descriptions.d.ts +6 -0
  88. package/dist/tools/light-descriptions.d.ts.map +1 -0
  89. package/package.json +1 -1
  90. package/src/agents/hidden-agent-registrations.ts +49 -1
  91. package/src/agents/magic-context-prompt.test.ts +144 -0
  92. package/src/agents/magic-context-prompt.ts +53 -2
  93. package/src/agents/permissions.ts +4 -3
  94. package/src/config/index.test.ts +53 -0
  95. package/src/config/index.ts +4 -0
  96. package/src/config/project-security.test.ts +20 -0
  97. package/src/config/project-security.ts +23 -0
  98. package/src/config/schema/magic-context.test.ts +58 -0
  99. package/src/config/schema/magic-context.ts +61 -1
  100. package/src/shared/index.ts +2 -0
  101. package/src/shared/prompt-surface-a1-golden.md +458 -0
  102. package/src/shared/prompt-surface-a1-golden.ts +41 -0
  103. package/src/shared/prompt-surface-runtime.test.ts +141 -0
  104. package/src/shared/prompt-surface-runtime.ts +250 -0
  105. package/src/shared/prompt-surface.test.ts +109 -0
  106. package/src/shared/prompt-surface.ts +138 -0
  107. package/src/shared/sqlite.test.ts +32 -0
  108. package/src/shared/sqlite.ts +85 -9
  109. package/dist/index-b563sga5.js +0 -134784
@@ -45,12 +45,25 @@
45
45
  // node:sqlite at runtime (both expose prepare/run/get/all/exec/close).
46
46
  import type BetterSqlite3 from "better-sqlite3";
47
47
 
48
- // Detect Bun via process.versions.bun. Both globalThis.Bun and
49
- // process.versions.bun are set by the Bun runtime, but process.versions
50
- // is a lower-level surface less likely to be sandboxed by host runtimes
51
- // (e.g. Electron in OpenCode desktop apps that re-expose a Bun-flavored
52
- // environment). Real Node and Electron never set this field.
53
- const isBun = typeof process !== "undefined" && typeof process.versions?.bun === "string";
48
+ export type SqliteRuntime = "Bun" | "Node.js";
49
+
50
+ type SqliteModule = {
51
+ Database?: unknown;
52
+ DatabaseSync?: unknown;
53
+ };
54
+
55
+ export function detectSqliteRuntime(): SqliteRuntime {
56
+ // process.versions.bun is the least ambiguous marker, but some launchers
57
+ // proxy or partially sandbox process. Keep globalThis.Bun as a fallback so
58
+ // a Bun process does not accidentally select node:sqlite just because its
59
+ // process compatibility surface was trimmed.
60
+ const hasBunVersion =
61
+ typeof process !== "undefined" && typeof process.versions?.bun === "string";
62
+ const hasBunGlobal =
63
+ typeof globalThis !== "undefined" &&
64
+ typeof (globalThis as { Bun?: unknown }).Bun !== "undefined";
65
+ return hasBunVersion || hasBunGlobal ? "Bun" : "Node.js";
66
+ }
54
67
 
55
68
  // IMPORTANT: bundler-evading dynamic imports.
56
69
  //
@@ -69,9 +82,72 @@ const isBun = typeof process !== "undefined" && typeof process.versions?.bun ===
69
82
  const bunSpec = "bun:" + "sqlite";
70
83
  const nodeSpec = "node:" + "sqlite";
71
84
 
72
- const sqliteModule = isBun
73
- ? await import(/* @vite-ignore */ bunSpec)
74
- : await import(/* @vite-ignore */ nodeSpec);
85
+ async function importSqliteModule(specifier: string): Promise<SqliteModule> {
86
+ // The runtime chooses this specifier; Vite must not resolve it as a
87
+ // build-time dependency because the other runtime's backend is absent.
88
+ return (await import(
89
+ /* @vite-ignore -- keep the runtime-selected backend unresolved */ specifier
90
+ )) as SqliteModule;
91
+ }
92
+
93
+ function isModuleNotFoundError(error: unknown, specifier: string): boolean {
94
+ const candidate = error as { code?: unknown; name?: unknown } | null;
95
+ const code = typeof candidate?.code === "string" ? candidate.code : "";
96
+ const name = typeof candidate?.name === "string" ? candidate.name : "";
97
+ const message = error instanceof Error ? error.message : String(error ?? "");
98
+ const details = `${code} ${name} ${message}`.toLowerCase();
99
+ const mentionsSpecifier = details.includes(specifier.toLowerCase());
100
+ if (!mentionsSpecifier) return false;
101
+
102
+ return (
103
+ code === "ERR_MODULE_NOT_FOUND" ||
104
+ code === "ERR_UNKNOWN_BUILTIN_MODULE" ||
105
+ code === "MODULE_NOT_FOUND" ||
106
+ name === "ResolveMessage" ||
107
+ details.includes("module not found") ||
108
+ details.includes("cannot find module") ||
109
+ details.includes("cannot find package") ||
110
+ details.includes("no such built-in module")
111
+ );
112
+ }
113
+
114
+ export class SqliteRuntimeUnavailableError extends Error {
115
+ readonly runtime: SqliteRuntime;
116
+ readonly specifier: string;
117
+
118
+ constructor(runtime: SqliteRuntime, specifier: string, cause: unknown) {
119
+ const requirement =
120
+ specifier === nodeSpec
121
+ ? "Requires Node.js >= 24, or Bun with bun:sqlite — this Bun build lacks node:sqlite."
122
+ : "Requires Bun with bun:sqlite, or Node.js >= 24 — this Bun build lacks bun:sqlite.";
123
+ super(
124
+ `Magic Context detected ${runtime}, but could not load ${specifier}. ${requirement}`,
125
+ { cause },
126
+ );
127
+ this.name = "SqliteRuntimeUnavailableError";
128
+ this.runtime = runtime;
129
+ this.specifier = specifier;
130
+ }
131
+ }
132
+
133
+ export async function loadSqliteModule(
134
+ runtime: SqliteRuntime = detectSqliteRuntime(),
135
+ importer: (specifier: string) => Promise<SqliteModule> = importSqliteModule,
136
+ ): Promise<SqliteModule> {
137
+ const specifier = runtime === "Bun" ? bunSpec : nodeSpec;
138
+ try {
139
+ return await importer(specifier);
140
+ } catch (error) {
141
+ if (isModuleNotFoundError(error, specifier)) {
142
+ throw new SqliteRuntimeUnavailableError(runtime, specifier, error);
143
+ }
144
+ throw error;
145
+ }
146
+ }
147
+
148
+ const detectedRuntime = detectSqliteRuntime();
149
+ const isBun = detectedRuntime === "Bun";
150
+ const sqliteModule = await loadSqliteModule(detectedRuntime);
75
151
 
76
152
  // Different export shapes between the two backends:
77
153
  // - bun:sqlite → named export `Database` (has its own .transaction, accepts