@cortexkit/opencode-magic-context 0.35.0 → 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.
- package/dist/agents/hidden-agent-registrations.d.ts +10 -2
- package/dist/agents/hidden-agent-registrations.d.ts.map +1 -1
- package/dist/agents/permissions.d.ts +4 -3
- package/dist/agents/permissions.d.ts.map +1 -1
- package/dist/config/schema/agent-overrides.d.ts +1 -1
- package/dist/config/schema/magic-context.d.ts +9 -9
- package/dist/hooks/magic-context/compartment-prompt.d.ts +6 -6
- package/dist/hooks/magic-context/compartment-prompt.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-formatting.d.ts.map +1 -1
- package/dist/index-dpdnjawy.js +2892 -0
- package/dist/{index-4anesz49.js → index-fkyamz2w.js} +7 -3
- package/dist/{index-cn960ffd.js → index-h5zjfesc.js} +1 -1
- package/dist/{index-fcyvznch.js → index-w0nygb4p.js} +45 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -14
- package/dist/{recomp-orchestrator-zc915ceq.js → recomp-orchestrator-29f4rqax.js} +4 -4
- package/dist/{send-session-notification-6njqewzk.js → send-session-notification-sr5g06hz.js} +2 -2
- package/dist/shared/prompt-surface-a1-golden.d.ts +28 -0
- package/dist/shared/prompt-surface-a1-golden.d.ts.map +1 -0
- package/dist/shared/sqlite.d.ts +13 -0
- package/dist/shared/sqlite.d.ts.map +1 -1
- package/dist/{storage-meta-session-53cjs6mr.js → storage-meta-session-ev8b55a9.js} +2 -2
- package/package.json +1 -1
- package/src/agents/hidden-agent-registrations.ts +49 -1
- package/src/agents/permissions.ts +4 -3
- package/src/shared/prompt-surface-a1-golden.ts +41 -0
- package/src/shared/sqlite.test.ts +32 -0
- package/src/shared/sqlite.ts +85 -9
- package/dist/index-h8mk7vpa.js +0 -135318
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import { loadSqliteModule, SqliteRuntimeUnavailableError } from "./sqlite";
|
|
3
|
+
|
|
4
|
+
describe("SQLite runtime selector", () => {
|
|
5
|
+
it("wraps a missing node:sqlite module with the detected runtime and cause", async () => {
|
|
6
|
+
const cause = Object.assign(new Error("No such built-in module: node:sqlite"), {
|
|
7
|
+
code: "ERR_UNKNOWN_BUILTIN_MODULE",
|
|
8
|
+
name: "ResolveMessage",
|
|
9
|
+
});
|
|
10
|
+
let requestedSpecifier = "";
|
|
11
|
+
let thrown: unknown;
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
await loadSqliteModule("Node.js", async (specifier) => {
|
|
15
|
+
requestedSpecifier = specifier;
|
|
16
|
+
throw cause;
|
|
17
|
+
});
|
|
18
|
+
} catch (error) {
|
|
19
|
+
thrown = error;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
expect(requestedSpecifier).toBe("node:sqlite");
|
|
23
|
+
expect(thrown).toBeInstanceOf(SqliteRuntimeUnavailableError);
|
|
24
|
+
const compatibilityError = thrown as SqliteRuntimeUnavailableError;
|
|
25
|
+
expect(compatibilityError.runtime).toBe("Node.js");
|
|
26
|
+
expect(compatibilityError.specifier).toBe("node:sqlite");
|
|
27
|
+
expect(compatibilityError.message).toContain("Node.js >= 24");
|
|
28
|
+
expect(compatibilityError.message).toContain("Bun with bun:sqlite");
|
|
29
|
+
expect(compatibilityError.message).toContain("node:sqlite");
|
|
30
|
+
expect(compatibilityError.cause).toBe(cause);
|
|
31
|
+
});
|
|
32
|
+
});
|
package/src/shared/sqlite.ts
CHANGED
|
@@ -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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|