@h-rig/memory-plugin 0.0.6-alpha.156 → 0.0.6-alpha.158
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/src/cli.d.ts +1 -3
- package/dist/src/cli.js +417 -19
- package/dist/src/db.js +4 -3
- package/dist/src/embed.js +1 -1
- package/dist/src/embedded-native-assets.d.ts +7 -0
- package/dist/src/embedded-native-assets.js +6 -0
- package/dist/src/index.js +428 -24
- package/dist/src/native-extract.d.ts +2 -0
- package/dist/src/native-extract.js +44 -0
- package/dist/src/native-git.d.ts +28 -0
- package/dist/src/native-git.js +598 -0
- package/dist/src/plugin.d.ts +2 -2
- package/dist/src/plugin.js +428 -24
- package/dist/src/query.d.ts +1 -1
- package/dist/src/query.js +2 -2
- package/dist/src/read.d.ts +1 -1
- package/dist/src/read.js +374 -13
- package/dist/src/service.d.ts +1 -1
- package/dist/src/service.js +417 -19
- package/dist/src/write.d.ts +1 -1
- package/dist/src/write.js +414 -18
- package/package.json +3 -4
package/dist/src/read.js
CHANGED
|
@@ -1,15 +1,375 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/memory-plugin/src/read.ts
|
|
3
|
-
import { mkdtempSync, rmSync, writeFileSync } from "fs";
|
|
4
|
-
import { tmpdir } from "os";
|
|
3
|
+
import { mkdtempSync, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
4
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
5
5
|
import { join } from "path";
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
|
|
7
|
+
// packages/memory-plugin/src/native-git.ts
|
|
8
|
+
import { chmodSync, copyFileSync, existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, renameSync as renameSync2, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
9
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
10
|
+
import { dirname, isAbsolute, resolve as resolve2 } from "path";
|
|
11
|
+
import { createHash } from "crypto";
|
|
12
|
+
|
|
13
|
+
// packages/memory-plugin/src/native-extract.ts
|
|
14
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "fs";
|
|
15
|
+
import { tmpdir } from "os";
|
|
16
|
+
import { resolve } from "path";
|
|
17
|
+
|
|
18
|
+
// packages/memory-plugin/src/embedded-native-assets.ts
|
|
19
|
+
var embeddedNatives = null;
|
|
20
|
+
|
|
21
|
+
// packages/memory-plugin/src/native-extract.ts
|
|
22
|
+
var sharedNativeOutputDir = resolve(tmpdir(), "rig-native");
|
|
23
|
+
var extractionCache = {};
|
|
24
|
+
function extractEmbeddedNative(name) {
|
|
25
|
+
if (name in extractionCache) {
|
|
26
|
+
return extractionCache[name] ?? null;
|
|
27
|
+
}
|
|
28
|
+
const entry = embeddedNatives?.[name];
|
|
29
|
+
if (!entry) {
|
|
30
|
+
extractionCache[name] = null;
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const targetPath = resolve(sharedNativeOutputDir, entry.fileName);
|
|
35
|
+
mkdirSync(sharedNativeOutputDir, { recursive: true });
|
|
36
|
+
const upToDate = existsSync(targetPath) && statSync(targetPath).size === entry.size;
|
|
37
|
+
if (!upToDate) {
|
|
38
|
+
const bytes = readFileSync(entry.filePath);
|
|
39
|
+
const tempPath = `${targetPath}.${process.pid}.${Date.now()}.tmp`;
|
|
40
|
+
writeFileSync(tempPath, bytes, { mode: 493 });
|
|
41
|
+
renameSync(tempPath, targetPath);
|
|
42
|
+
}
|
|
43
|
+
extractionCache[name] = targetPath;
|
|
44
|
+
} catch {
|
|
45
|
+
extractionCache[name] = null;
|
|
46
|
+
}
|
|
47
|
+
return extractionCache[name] ?? null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// packages/memory-plugin/src/native-git.ts
|
|
51
|
+
var sharedGitNativeOutputDir = resolve2(tmpdir2(), "rig-native");
|
|
52
|
+
var sharedGitNativeOutputPath = resolve2(sharedGitNativeOutputDir, `rig-git-${process.platform}-${process.arch}${process.platform === "win32" ? ".exe" : ""}`);
|
|
53
|
+
var trackerCommandUsageProbe = "usage: rig-git fetch-ref <repo-path> <remote> <branch>";
|
|
54
|
+
function temporaryGitBinaryOutputPath(outputPath) {
|
|
55
|
+
const suffix = process.platform === "win32" ? ".exe" : "";
|
|
56
|
+
return resolve2(dirname(outputPath), `.rig-git-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}${suffix}`);
|
|
57
|
+
}
|
|
58
|
+
function publishGitBinary(tempOutputPath, outputPath) {
|
|
59
|
+
try {
|
|
60
|
+
renameSync2(tempOutputPath, outputPath);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (process.platform === "win32" && existsSync2(outputPath)) {
|
|
63
|
+
rmSync(outputPath, { force: true });
|
|
64
|
+
renameSync2(tempOutputPath, outputPath);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function isSharedGitNativeOutputPath(outputPath) {
|
|
71
|
+
return resolve2(outputPath) === sharedGitNativeOutputPath;
|
|
72
|
+
}
|
|
73
|
+
function materializeFromSharedGitBinarySync(outputPath, buildKey) {
|
|
74
|
+
if (isSharedGitNativeOutputPath(outputPath))
|
|
75
|
+
return null;
|
|
76
|
+
const sharedManifest = nativeBuildManifestPath(sharedGitNativeOutputPath);
|
|
77
|
+
if (!existsSync2(sharedGitNativeOutputPath) || !hasMatchingNativeBuildManifestSync(sharedManifest, buildKey) || !binarySupportsTrackerCommandsSync(sharedGitNativeOutputPath)) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
mkdirSync2(dirname(outputPath), { recursive: true });
|
|
81
|
+
copyFileSync(sharedGitNativeOutputPath, outputPath);
|
|
82
|
+
chmodSync(outputPath, 493);
|
|
83
|
+
writeFileSync2(nativeBuildManifestPath(outputPath), `${JSON.stringify({ version: 1, buildKey }, null, 2)}
|
|
84
|
+
`, "utf8");
|
|
85
|
+
return outputPath;
|
|
86
|
+
}
|
|
87
|
+
function runtimeRigGitFileName() {
|
|
88
|
+
return `rig-git${process.platform === "win32" ? ".exe" : ""}`;
|
|
89
|
+
}
|
|
90
|
+
function rigGitSourceCandidates() {
|
|
91
|
+
const execDir = process.execPath?.trim() ? dirname(process.execPath.trim()) : "";
|
|
92
|
+
const cwd = process.cwd()?.trim() || "";
|
|
93
|
+
const projectRoot = process.env.PROJECT_RIG_ROOT?.trim() || "";
|
|
94
|
+
const hostProjectRoot = process.env.RIG_HOST_PROJECT_ROOT?.trim() || "";
|
|
95
|
+
const moduleRelativeSource = resolve2(import.meta.dir, "../native/rig-git.zig");
|
|
96
|
+
return [...new Set([
|
|
97
|
+
process.env.RIG_NATIVE_GIT_SOURCE?.trim() || "",
|
|
98
|
+
moduleRelativeSource,
|
|
99
|
+
projectRoot ? resolve2(projectRoot, "packages/memory-plugin/native/rig-git.zig") : "",
|
|
100
|
+
hostProjectRoot ? resolve2(hostProjectRoot, "packages/memory-plugin/native/rig-git.zig") : "",
|
|
101
|
+
cwd ? resolve2(cwd, "packages/memory-plugin/native/rig-git.zig") : "",
|
|
102
|
+
execDir ? resolve2(execDir, "..", "..", "packages/memory-plugin/native/rig-git.zig") : "",
|
|
103
|
+
execDir ? resolve2(execDir, "..", "native", "rig-git.zig") : ""
|
|
104
|
+
].filter(Boolean))];
|
|
105
|
+
}
|
|
106
|
+
function nativePackageBinaryCandidates(fromDir, fileName) {
|
|
107
|
+
const candidates = [];
|
|
108
|
+
let cursor = resolve2(fromDir);
|
|
109
|
+
for (let index = 0;index < 8; index += 1) {
|
|
110
|
+
candidates.push(resolve2(cursor, "native", `${process.platform}-${process.arch}`, fileName), resolve2(cursor, "native", `${process.platform}-${process.arch}`, "bin", fileName), resolve2(cursor, "native", fileName), resolve2(cursor, "native", "bin", fileName));
|
|
111
|
+
const parent = dirname(cursor);
|
|
112
|
+
if (parent === cursor)
|
|
113
|
+
break;
|
|
114
|
+
cursor = parent;
|
|
115
|
+
}
|
|
116
|
+
return candidates;
|
|
117
|
+
}
|
|
118
|
+
function rigGitBinaryCandidates() {
|
|
119
|
+
const execDir = process.execPath?.trim() ? dirname(process.execPath.trim()) : "";
|
|
120
|
+
const fileName = runtimeRigGitFileName();
|
|
121
|
+
const explicit = process.env.RIG_NATIVE_GIT_BIN?.trim() || "";
|
|
122
|
+
return [...new Set([
|
|
123
|
+
explicit,
|
|
124
|
+
...nativePackageBinaryCandidates(import.meta.dir, fileName),
|
|
125
|
+
execDir ? resolve2(execDir, fileName) : "",
|
|
126
|
+
execDir ? resolve2(execDir, "..", fileName) : "",
|
|
127
|
+
execDir ? resolve2(execDir, "..", "bin", fileName) : "",
|
|
128
|
+
sharedGitNativeOutputPath
|
|
129
|
+
].filter(Boolean))];
|
|
130
|
+
}
|
|
131
|
+
function resolveGitSourcePath() {
|
|
132
|
+
for (const candidate of rigGitSourceCandidates()) {
|
|
133
|
+
if (candidate && existsSync2(candidate)) {
|
|
134
|
+
return candidate;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
function resolveGitBinaryPath() {
|
|
140
|
+
if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
for (const candidate of rigGitBinaryCandidates()) {
|
|
144
|
+
if (candidate && existsSync2(candidate)) {
|
|
145
|
+
return candidate;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
function preferredGitBinaryOutputPath() {
|
|
151
|
+
const explicit = process.env.RIG_NATIVE_GIT_BIN?.trim() || "";
|
|
152
|
+
return explicit || sharedGitNativeOutputPath;
|
|
153
|
+
}
|
|
154
|
+
function binarySupportsTrackerCommandsSync(binaryPath) {
|
|
155
|
+
try {
|
|
156
|
+
const probe = Bun.spawnSync([binaryPath, "fetch-ref", "."], {
|
|
157
|
+
stdout: "pipe",
|
|
158
|
+
stderr: "pipe"
|
|
159
|
+
});
|
|
160
|
+
const stdout = probe.stdout.toString().trim();
|
|
161
|
+
const stderr = probe.stderr.toString().trim();
|
|
162
|
+
if (stdout.includes('"error":"unknown command"')) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
return probe.exitCode === 2 && stderr.includes(trackerCommandUsageProbe);
|
|
166
|
+
} catch {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function nativeBuildManifestPath(outputPath) {
|
|
171
|
+
return `${outputPath}.build-manifest.json`;
|
|
172
|
+
}
|
|
173
|
+
function hasMatchingNativeBuildManifestSync(manifestPath, buildKey) {
|
|
174
|
+
if (!existsSync2(manifestPath)) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
const manifest = JSON.parse(readFileSync2(manifestPath, "utf8"));
|
|
179
|
+
return manifest.version === 1 && manifest.buildKey === buildKey;
|
|
180
|
+
} catch {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function sha256FileSync(path) {
|
|
185
|
+
return createHash("sha256").update(readFileSync2(path)).digest("hex");
|
|
186
|
+
}
|
|
187
|
+
function ensureRigGitBinaryPathSync(outputPath = preferredGitBinaryOutputPath()) {
|
|
188
|
+
if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
|
|
189
|
+
throw new Error("Zig native git is disabled via RIG_DISABLE_ZIG_NATIVE=1");
|
|
190
|
+
}
|
|
191
|
+
const explicitBin = process.env.RIG_NATIVE_GIT_BIN?.trim();
|
|
192
|
+
if (explicitBin && existsSync2(explicitBin)) {
|
|
193
|
+
return explicitBin;
|
|
194
|
+
}
|
|
195
|
+
const embedded = extractEmbeddedNative("rig-git");
|
|
196
|
+
if (embedded) {
|
|
197
|
+
return embedded;
|
|
198
|
+
}
|
|
199
|
+
const sourcePath = resolveGitSourcePath();
|
|
200
|
+
if (!sourcePath) {
|
|
201
|
+
const binaryPath = resolveGitBinaryPath();
|
|
202
|
+
if (binaryPath) {
|
|
203
|
+
return binaryPath;
|
|
204
|
+
}
|
|
205
|
+
throw new Error("rig-git.zig source file not found.");
|
|
206
|
+
}
|
|
207
|
+
const zigBinary = Bun.which("zig");
|
|
208
|
+
if (!zigBinary) {
|
|
209
|
+
throw new Error("zig is required to build native Rig git tools.");
|
|
210
|
+
}
|
|
211
|
+
mkdirSync2(dirname(outputPath), { recursive: true });
|
|
212
|
+
const sourceDigest = sha256FileSync(sourcePath);
|
|
213
|
+
const buildKey = JSON.stringify({
|
|
214
|
+
version: 1,
|
|
215
|
+
zigBinary,
|
|
216
|
+
platform: process.platform,
|
|
217
|
+
arch: process.arch,
|
|
218
|
+
sourcePath,
|
|
219
|
+
sourceDigest
|
|
220
|
+
});
|
|
221
|
+
const manifestPath = nativeBuildManifestPath(outputPath);
|
|
222
|
+
const needsBuild = !existsSync2(outputPath) || !hasMatchingNativeBuildManifestSync(manifestPath, buildKey) || !binarySupportsTrackerCommandsSync(outputPath);
|
|
223
|
+
if (!needsBuild) {
|
|
224
|
+
chmodSync(outputPath, 493);
|
|
225
|
+
return outputPath;
|
|
226
|
+
}
|
|
227
|
+
const materialized = materializeFromSharedGitBinarySync(outputPath, buildKey);
|
|
228
|
+
if (materialized)
|
|
229
|
+
return materialized;
|
|
230
|
+
const tempOutputPath = temporaryGitBinaryOutputPath(outputPath);
|
|
231
|
+
const build = Bun.spawnSync([
|
|
232
|
+
zigBinary,
|
|
233
|
+
"build-exe",
|
|
234
|
+
sourcePath,
|
|
235
|
+
"-O",
|
|
236
|
+
"ReleaseFast",
|
|
237
|
+
`-femit-bin=${tempOutputPath}`
|
|
238
|
+
], {
|
|
239
|
+
cwd: dirname(sourcePath),
|
|
240
|
+
stdout: "pipe",
|
|
241
|
+
stderr: "pipe"
|
|
242
|
+
});
|
|
243
|
+
if (build.exitCode !== 0 || !existsSync2(tempOutputPath)) {
|
|
244
|
+
const stderr = build.stderr.toString().trim();
|
|
245
|
+
const stdout = build.stdout.toString().trim();
|
|
246
|
+
const details = [stderr, stdout].filter(Boolean).join(`
|
|
247
|
+
`);
|
|
248
|
+
throw new Error(`Failed to build native Rig git tools: ${details || `zig exited with code ${build.exitCode}`}`);
|
|
249
|
+
}
|
|
250
|
+
chmodSync(tempOutputPath, 493);
|
|
251
|
+
if (existsSync2(outputPath) && hasMatchingNativeBuildManifestSync(manifestPath, buildKey)) {
|
|
252
|
+
rmSync(tempOutputPath, { force: true });
|
|
253
|
+
chmodSync(outputPath, 493);
|
|
254
|
+
return outputPath;
|
|
255
|
+
}
|
|
256
|
+
publishGitBinary(tempOutputPath, outputPath);
|
|
257
|
+
if (!binarySupportsTrackerCommandsSync(outputPath)) {
|
|
258
|
+
rmSync(outputPath, { force: true });
|
|
259
|
+
throw new Error("Failed to build native Rig git tools: tracker command probe failed");
|
|
260
|
+
}
|
|
261
|
+
writeFileSync2(manifestPath, `${JSON.stringify({ version: 1, buildKey }, null, 2)}
|
|
262
|
+
`, "utf8");
|
|
263
|
+
return outputPath;
|
|
264
|
+
}
|
|
265
|
+
function gitNativeEnv() {
|
|
266
|
+
const env = { ...process.env };
|
|
267
|
+
const token = env.GITHUB_TOKEN?.trim() || env.GH_TOKEN?.trim() || env.RIG_GITHUB_TOKEN?.trim() || "";
|
|
268
|
+
if (token) {
|
|
269
|
+
env.RIG_GITHUB_TOKEN = env.RIG_GITHUB_TOKEN || token;
|
|
270
|
+
env.GITHUB_TOKEN = env.GITHUB_TOKEN || token;
|
|
271
|
+
env.GH_TOKEN = env.GH_TOKEN || token;
|
|
272
|
+
env.GIT_TERMINAL_PROMPT = "0";
|
|
273
|
+
env.GIT_CONFIG_COUNT = "2";
|
|
274
|
+
env.GIT_CONFIG_KEY_0 = "credential.helper";
|
|
275
|
+
env.GIT_CONFIG_VALUE_0 = "";
|
|
276
|
+
env.GIT_CONFIG_KEY_1 = "credential.helper";
|
|
277
|
+
env.GIT_CONFIG_VALUE_1 = '!f() { test "$1" = get || exit 0; token="${GITHUB_TOKEN:-${GH_TOKEN:-${RIG_GITHUB_TOKEN:-}}}"; test -n "$token" || exit 0; echo username=x-access-token; echo password="$token"; }; f';
|
|
278
|
+
}
|
|
279
|
+
return env;
|
|
280
|
+
}
|
|
281
|
+
function runGitNative(command, args) {
|
|
282
|
+
if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
|
|
283
|
+
return { ok: false, error: "rig-git native disabled" };
|
|
284
|
+
}
|
|
285
|
+
const trackerCommand = command === "fetch-ref" || command === "read-blob-at-ref" || command === "write-tree-commit" || command === "push-ref-with-lease";
|
|
286
|
+
let binaryPath = null;
|
|
287
|
+
if (trackerCommand) {
|
|
288
|
+
try {
|
|
289
|
+
binaryPath = ensureRigGitBinaryPathSync(preferredGitBinaryOutputPath());
|
|
290
|
+
} catch (error) {
|
|
291
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
292
|
+
if (message.includes("rig-git.zig source file not found")) {
|
|
293
|
+
return { ok: false, error: "rig-git binary not found" };
|
|
294
|
+
}
|
|
295
|
+
return { ok: false, error: message };
|
|
296
|
+
}
|
|
297
|
+
} else {
|
|
298
|
+
const explicitBinaryPath = process.env.RIG_NATIVE_GIT_BIN?.trim() || "";
|
|
299
|
+
binaryPath = explicitBinaryPath && existsSync2(explicitBinaryPath) ? explicitBinaryPath : !explicitBinaryPath ? resolveGitBinaryPath() : null;
|
|
300
|
+
if (!binaryPath) {
|
|
301
|
+
try {
|
|
302
|
+
binaryPath = ensureRigGitBinaryPathSync(preferredGitBinaryOutputPath());
|
|
303
|
+
} catch (error) {
|
|
304
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
305
|
+
if (message.includes("rig-git.zig source file not found")) {
|
|
306
|
+
return { ok: false, error: "rig-git binary not found" };
|
|
307
|
+
}
|
|
308
|
+
return { ok: false, error: message };
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
try {
|
|
313
|
+
const proc = Bun.spawnSync([binaryPath, command, ...args], {
|
|
314
|
+
stdout: "pipe",
|
|
315
|
+
stderr: "pipe",
|
|
316
|
+
env: gitNativeEnv()
|
|
317
|
+
});
|
|
318
|
+
if (proc.exitCode !== 0) {
|
|
319
|
+
const stdoutText = proc.stdout.toString().trim();
|
|
320
|
+
if (stdoutText) {
|
|
321
|
+
try {
|
|
322
|
+
const parsed = JSON.parse(stdoutText);
|
|
323
|
+
if (!parsed.ok) {
|
|
324
|
+
return parsed;
|
|
325
|
+
}
|
|
326
|
+
} catch {}
|
|
327
|
+
}
|
|
328
|
+
const errText = proc.stderr.toString().trim() || `exit code ${proc.exitCode}`;
|
|
329
|
+
return { ok: false, error: errText };
|
|
330
|
+
}
|
|
331
|
+
const output = proc.stdout.toString().trim();
|
|
332
|
+
return JSON.parse(output);
|
|
333
|
+
} catch (err) {
|
|
334
|
+
return { ok: false, error: String(err) };
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function requireGitNative(command, args) {
|
|
338
|
+
const result = runGitNative(command, args);
|
|
339
|
+
if (result.ok === false) {
|
|
340
|
+
throw new Error(`rig-git ${command} failed: ${result.error}`);
|
|
341
|
+
}
|
|
342
|
+
return result;
|
|
343
|
+
}
|
|
344
|
+
function requireGitNativeString(command, args) {
|
|
345
|
+
const result = requireGitNative(command, args);
|
|
346
|
+
if ("value" in result && typeof result.value === "string") {
|
|
347
|
+
return result.value;
|
|
348
|
+
}
|
|
349
|
+
throw new Error(`rig-git ${command} returned an unexpected result payload`);
|
|
350
|
+
}
|
|
351
|
+
function nativeFetchRef(repoPath, remote, branch) {
|
|
352
|
+
return requireGitNativeString("fetch-ref", [repoPath, remote, branch]);
|
|
353
|
+
}
|
|
354
|
+
function nativeReadBlobBytesAtRef(repoPath, ref, path) {
|
|
355
|
+
const requestDir = resolve2(sharedGitNativeOutputDir, "reads", `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`);
|
|
356
|
+
mkdirSync2(requestDir, { recursive: true });
|
|
357
|
+
const outputPath = resolve2(requestDir, "blob.bin");
|
|
358
|
+
try {
|
|
359
|
+
requireGitNative("read-blob-at-ref", [repoPath, ref, path, outputPath]);
|
|
360
|
+
return readFileSync2(outputPath);
|
|
361
|
+
} finally {
|
|
362
|
+
rmSync(requestDir, { recursive: true, force: true });
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// packages/memory-plugin/src/read.ts
|
|
367
|
+
import { resolveCheckoutRoot as resolveMonorepoRoot } from "@rig/core/checkout-root";
|
|
8
368
|
|
|
9
369
|
// packages/memory-plugin/src/db.ts
|
|
10
370
|
import { Database } from "bun:sqlite";
|
|
11
|
-
import { mkdirSync } from "fs";
|
|
12
|
-
import { dirname } from "path";
|
|
371
|
+
import { mkdirSync as mkdirSync3 } from "fs";
|
|
372
|
+
import { dirname as dirname2 } from "path";
|
|
13
373
|
import {
|
|
14
374
|
NO_MATCH_RETRIEVAL_CANONICAL_KEY
|
|
15
375
|
} from "@rig/contracts";
|
|
@@ -104,11 +464,12 @@ var MEMORY_ITEM_COLUMNS = [
|
|
|
104
464
|
];
|
|
105
465
|
function normalizeStatement(statement, args) {
|
|
106
466
|
if (typeof statement === "string") {
|
|
107
|
-
return { sql: statement, args };
|
|
467
|
+
return { sql: statement, ...args !== undefined ? { args } : {} };
|
|
108
468
|
}
|
|
469
|
+
const resolvedArgs = statement.args ?? args;
|
|
109
470
|
return {
|
|
110
471
|
sql: statement.sql,
|
|
111
|
-
args:
|
|
472
|
+
...resolvedArgs !== undefined ? { args: resolvedArgs } : {}
|
|
112
473
|
};
|
|
113
474
|
}
|
|
114
475
|
function normalizeBindings(bindings) {
|
|
@@ -143,7 +504,7 @@ function executeSqlite(sqlite, statement, args) {
|
|
|
143
504
|
const normalized = normalizeStatement(statement, args);
|
|
144
505
|
const bindings = normalizeBindings(normalized.args);
|
|
145
506
|
if (isMutationStatement(normalized.sql)) {
|
|
146
|
-
const result = bindings.length > 0 ? sqlite.run(normalized.sql,
|
|
507
|
+
const result = bindings.length > 0 ? sqlite.run(normalized.sql, bindings) : sqlite.run(normalized.sql);
|
|
147
508
|
return {
|
|
148
509
|
rows: [],
|
|
149
510
|
rowsAffected: Number(result.changes)
|
|
@@ -225,7 +586,7 @@ async function ensureSchema(db) {
|
|
|
225
586
|
await ensureColumns(db.client, "memory_items", MEMORY_ITEM_COLUMNS);
|
|
226
587
|
}
|
|
227
588
|
async function openMemoryDb(dbPath) {
|
|
228
|
-
|
|
589
|
+
mkdirSync3(dirname2(dbPath), { recursive: true });
|
|
229
590
|
const sqlite = new Database(dbPath, { create: true, strict: true });
|
|
230
591
|
const client = createMemoryDbClient(sqlite);
|
|
231
592
|
const db = {
|
|
@@ -245,8 +606,8 @@ var DEFAULT_READ_DEPS = {
|
|
|
245
606
|
fetchRef: nativeFetchRef,
|
|
246
607
|
readBlobBytesAtRef: nativeReadBlobBytesAtRef,
|
|
247
608
|
openMemoryDb,
|
|
248
|
-
makeTempDir: () => mkdtempSync(join(
|
|
249
|
-
removeDir: (path) =>
|
|
609
|
+
makeTempDir: () => mkdtempSync(join(tmpdir3(), "memory-sync-read-")),
|
|
610
|
+
removeDir: (path) => rmSync2(path, { recursive: true, force: true })
|
|
250
611
|
};
|
|
251
612
|
function isMissingCanonicalMemoryBlobError(error) {
|
|
252
613
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -284,7 +645,7 @@ async function readCanonicalMemoryDb(projectRoot, deps = {}) {
|
|
|
284
645
|
} else {
|
|
285
646
|
try {
|
|
286
647
|
const bytes = readDeps.readBlobBytesAtRef(repoPath, baseOid, CANONICAL_MEMORY_DB_PATH);
|
|
287
|
-
|
|
648
|
+
writeFileSync3(dbPath, bytes);
|
|
288
649
|
} catch (error) {
|
|
289
650
|
if (!isMissingCanonicalMemoryBlobError(error)) {
|
|
290
651
|
throw error;
|
package/dist/src/service.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* capability `run()` in plugin.ts (`(await import("./service")).svc`), so merely
|
|
8
8
|
* evaluating rig.config.ts never drags the memory impl into scope.
|
|
9
9
|
*/
|
|
10
|
-
import type { MemoryService } from "@rig/
|
|
10
|
+
import type { MemoryService } from "@rig/contracts";
|
|
11
11
|
/** The concrete shared-memory service the runtime port resolves and consumes. */
|
|
12
12
|
export declare const svc: MemoryService;
|
|
13
13
|
/** Back-compat alias. */
|