@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/cli.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { promoteCanonicalMemoryEvent } from "./write";
|
|
2
|
-
import { type MemoryEventInput, type MemoryQueryResult } from "@rig/contracts";
|
|
3
|
-
import type { RuntimeTaskContext } from "@rig/runtime/control-plane/runtime/context";
|
|
4
|
-
import type { ExecuteMemoryCommandOptions } from "@rig/runtime/control-plane/memory-service-port";
|
|
2
|
+
import { type ExecuteMemoryCommandOptions, type MemoryEventInput, type MemoryQueryResult, type RuntimeTaskContext } from "@rig/contracts";
|
|
5
3
|
export type { ExecuteMemoryCommandOptions };
|
|
6
4
|
type ExecuteMemoryCommandDeps = {
|
|
7
5
|
currentBranch: (projectRoot: string) => string;
|
package/dist/src/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/memory-plugin/src/cli.ts
|
|
3
|
-
import { existsSync } from "fs";
|
|
3
|
+
import { existsSync as existsSync3 } from "fs";
|
|
4
4
|
import { randomUUID } from "crypto";
|
|
5
5
|
|
|
6
6
|
// packages/memory-plugin/src/db.ts
|
|
@@ -153,11 +153,12 @@ function eventFeedbackOutcome(event) {
|
|
|
153
153
|
}
|
|
154
154
|
function normalizeStatement(statement, args) {
|
|
155
155
|
if (typeof statement === "string") {
|
|
156
|
-
return { sql: statement, args };
|
|
156
|
+
return { sql: statement, ...args !== undefined ? { args } : {} };
|
|
157
157
|
}
|
|
158
|
+
const resolvedArgs = statement.args ?? args;
|
|
158
159
|
return {
|
|
159
160
|
sql: statement.sql,
|
|
160
|
-
args:
|
|
161
|
+
...resolvedArgs !== undefined ? { args: resolvedArgs } : {}
|
|
161
162
|
};
|
|
162
163
|
}
|
|
163
164
|
function normalizeBindings(bindings) {
|
|
@@ -192,7 +193,7 @@ function executeSqlite(sqlite, statement, args) {
|
|
|
192
193
|
const normalized = normalizeStatement(statement, args);
|
|
193
194
|
const bindings = normalizeBindings(normalized.args);
|
|
194
195
|
if (isMutationStatement(normalized.sql)) {
|
|
195
|
-
const result = bindings.length > 0 ? sqlite.run(normalized.sql,
|
|
196
|
+
const result = bindings.length > 0 ? sqlite.run(normalized.sql, bindings) : sqlite.run(normalized.sql);
|
|
196
197
|
return {
|
|
197
198
|
rows: [],
|
|
198
199
|
rowsAffected: Number(result.changes)
|
|
@@ -850,7 +851,7 @@ function createConfiguredMemoryEmbedder(options = {}) {
|
|
|
850
851
|
apiKey,
|
|
851
852
|
model: env.RIG_MEMORY_EMBEDDING_MODEL?.trim() || DEFAULT_EMBEDDING_MODEL,
|
|
852
853
|
apiBaseUrl: options.apiBaseUrl ?? env.RIG_MEMORY_EMBEDDING_API_BASE_URL?.trim() ?? DEFAULT_EMBEDDING_API_BASE_URL,
|
|
853
|
-
fetchImpl: options.fetchImpl
|
|
854
|
+
...options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}
|
|
854
855
|
});
|
|
855
856
|
}
|
|
856
857
|
function warnMissingMemoryEmbedderOnce(warn) {
|
|
@@ -922,7 +923,7 @@ async function embedChangedMemoryItems(db, event, embedder) {
|
|
|
922
923
|
// packages/memory-plugin/src/query.ts
|
|
923
924
|
import {
|
|
924
925
|
DEFAULT_RUNTIME_MEMORY_RETRIEVAL
|
|
925
|
-
} from "@rig/runtime
|
|
926
|
+
} from "@rig/core/runtime-context";
|
|
926
927
|
var DEFAULT_RESULT_LIMIT = DEFAULT_RUNTIME_MEMORY_RETRIEVAL.topK;
|
|
927
928
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
928
929
|
var MIN_VECTOR_MATCH_SCORE = 0.2;
|
|
@@ -1021,22 +1022,417 @@ function formatMemoryQueryResults(results) {
|
|
|
1021
1022
|
`);
|
|
1022
1023
|
}
|
|
1023
1024
|
|
|
1024
|
-
// packages/memory-plugin/src/
|
|
1025
|
-
import {
|
|
1025
|
+
// packages/memory-plugin/src/native-git.ts
|
|
1026
|
+
import { chmodSync, copyFileSync, existsSync as existsSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync2, renameSync as renameSync2, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
1027
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
1028
|
+
import { dirname as dirname2, isAbsolute, resolve as resolve2 } from "path";
|
|
1029
|
+
import { createHash as createHash2 } from "crypto";
|
|
1026
1030
|
|
|
1027
|
-
// packages/memory-plugin/src/
|
|
1028
|
-
import {
|
|
1031
|
+
// packages/memory-plugin/src/native-extract.ts
|
|
1032
|
+
import { existsSync, mkdirSync as mkdirSync2, readFileSync, renameSync, statSync, writeFileSync } from "fs";
|
|
1029
1033
|
import { tmpdir } from "os";
|
|
1034
|
+
import { resolve } from "path";
|
|
1035
|
+
|
|
1036
|
+
// packages/memory-plugin/src/embedded-native-assets.ts
|
|
1037
|
+
var embeddedNatives = null;
|
|
1038
|
+
|
|
1039
|
+
// packages/memory-plugin/src/native-extract.ts
|
|
1040
|
+
var sharedNativeOutputDir = resolve(tmpdir(), "rig-native");
|
|
1041
|
+
var extractionCache = {};
|
|
1042
|
+
function extractEmbeddedNative(name) {
|
|
1043
|
+
if (name in extractionCache) {
|
|
1044
|
+
return extractionCache[name] ?? null;
|
|
1045
|
+
}
|
|
1046
|
+
const entry = embeddedNatives?.[name];
|
|
1047
|
+
if (!entry) {
|
|
1048
|
+
extractionCache[name] = null;
|
|
1049
|
+
return null;
|
|
1050
|
+
}
|
|
1051
|
+
try {
|
|
1052
|
+
const targetPath = resolve(sharedNativeOutputDir, entry.fileName);
|
|
1053
|
+
mkdirSync2(sharedNativeOutputDir, { recursive: true });
|
|
1054
|
+
const upToDate = existsSync(targetPath) && statSync(targetPath).size === entry.size;
|
|
1055
|
+
if (!upToDate) {
|
|
1056
|
+
const bytes = readFileSync(entry.filePath);
|
|
1057
|
+
const tempPath = `${targetPath}.${process.pid}.${Date.now()}.tmp`;
|
|
1058
|
+
writeFileSync(tempPath, bytes, { mode: 493 });
|
|
1059
|
+
renameSync(tempPath, targetPath);
|
|
1060
|
+
}
|
|
1061
|
+
extractionCache[name] = targetPath;
|
|
1062
|
+
} catch {
|
|
1063
|
+
extractionCache[name] = null;
|
|
1064
|
+
}
|
|
1065
|
+
return extractionCache[name] ?? null;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
// packages/memory-plugin/src/native-git.ts
|
|
1069
|
+
function isTextTreeCommitUpdate(update) {
|
|
1070
|
+
return typeof update.content === "string";
|
|
1071
|
+
}
|
|
1072
|
+
var sharedGitNativeOutputDir = resolve2(tmpdir2(), "rig-native");
|
|
1073
|
+
var sharedGitNativeOutputPath = resolve2(sharedGitNativeOutputDir, `rig-git-${process.platform}-${process.arch}${process.platform === "win32" ? ".exe" : ""}`);
|
|
1074
|
+
var trackerCommandUsageProbe = "usage: rig-git fetch-ref <repo-path> <remote> <branch>";
|
|
1075
|
+
function temporaryGitBinaryOutputPath(outputPath) {
|
|
1076
|
+
const suffix = process.platform === "win32" ? ".exe" : "";
|
|
1077
|
+
return resolve2(dirname2(outputPath), `.rig-git-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}${suffix}`);
|
|
1078
|
+
}
|
|
1079
|
+
function publishGitBinary(tempOutputPath, outputPath) {
|
|
1080
|
+
try {
|
|
1081
|
+
renameSync2(tempOutputPath, outputPath);
|
|
1082
|
+
} catch (error) {
|
|
1083
|
+
if (process.platform === "win32" && existsSync2(outputPath)) {
|
|
1084
|
+
rmSync(outputPath, { force: true });
|
|
1085
|
+
renameSync2(tempOutputPath, outputPath);
|
|
1086
|
+
return;
|
|
1087
|
+
}
|
|
1088
|
+
throw error;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
function isSharedGitNativeOutputPath(outputPath) {
|
|
1092
|
+
return resolve2(outputPath) === sharedGitNativeOutputPath;
|
|
1093
|
+
}
|
|
1094
|
+
function materializeFromSharedGitBinarySync(outputPath, buildKey) {
|
|
1095
|
+
if (isSharedGitNativeOutputPath(outputPath))
|
|
1096
|
+
return null;
|
|
1097
|
+
const sharedManifest = nativeBuildManifestPath(sharedGitNativeOutputPath);
|
|
1098
|
+
if (!existsSync2(sharedGitNativeOutputPath) || !hasMatchingNativeBuildManifestSync(sharedManifest, buildKey) || !binarySupportsTrackerCommandsSync(sharedGitNativeOutputPath)) {
|
|
1099
|
+
return null;
|
|
1100
|
+
}
|
|
1101
|
+
mkdirSync3(dirname2(outputPath), { recursive: true });
|
|
1102
|
+
copyFileSync(sharedGitNativeOutputPath, outputPath);
|
|
1103
|
+
chmodSync(outputPath, 493);
|
|
1104
|
+
writeFileSync2(nativeBuildManifestPath(outputPath), `${JSON.stringify({ version: 1, buildKey }, null, 2)}
|
|
1105
|
+
`, "utf8");
|
|
1106
|
+
return outputPath;
|
|
1107
|
+
}
|
|
1108
|
+
function runtimeRigGitFileName() {
|
|
1109
|
+
return `rig-git${process.platform === "win32" ? ".exe" : ""}`;
|
|
1110
|
+
}
|
|
1111
|
+
function rigGitSourceCandidates() {
|
|
1112
|
+
const execDir = process.execPath?.trim() ? dirname2(process.execPath.trim()) : "";
|
|
1113
|
+
const cwd = process.cwd()?.trim() || "";
|
|
1114
|
+
const projectRoot = process.env.PROJECT_RIG_ROOT?.trim() || "";
|
|
1115
|
+
const hostProjectRoot = process.env.RIG_HOST_PROJECT_ROOT?.trim() || "";
|
|
1116
|
+
const moduleRelativeSource = resolve2(import.meta.dir, "../native/rig-git.zig");
|
|
1117
|
+
return [...new Set([
|
|
1118
|
+
process.env.RIG_NATIVE_GIT_SOURCE?.trim() || "",
|
|
1119
|
+
moduleRelativeSource,
|
|
1120
|
+
projectRoot ? resolve2(projectRoot, "packages/memory-plugin/native/rig-git.zig") : "",
|
|
1121
|
+
hostProjectRoot ? resolve2(hostProjectRoot, "packages/memory-plugin/native/rig-git.zig") : "",
|
|
1122
|
+
cwd ? resolve2(cwd, "packages/memory-plugin/native/rig-git.zig") : "",
|
|
1123
|
+
execDir ? resolve2(execDir, "..", "..", "packages/memory-plugin/native/rig-git.zig") : "",
|
|
1124
|
+
execDir ? resolve2(execDir, "..", "native", "rig-git.zig") : ""
|
|
1125
|
+
].filter(Boolean))];
|
|
1126
|
+
}
|
|
1127
|
+
function nativePackageBinaryCandidates(fromDir, fileName) {
|
|
1128
|
+
const candidates = [];
|
|
1129
|
+
let cursor = resolve2(fromDir);
|
|
1130
|
+
for (let index = 0;index < 8; index += 1) {
|
|
1131
|
+
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));
|
|
1132
|
+
const parent = dirname2(cursor);
|
|
1133
|
+
if (parent === cursor)
|
|
1134
|
+
break;
|
|
1135
|
+
cursor = parent;
|
|
1136
|
+
}
|
|
1137
|
+
return candidates;
|
|
1138
|
+
}
|
|
1139
|
+
function rigGitBinaryCandidates() {
|
|
1140
|
+
const execDir = process.execPath?.trim() ? dirname2(process.execPath.trim()) : "";
|
|
1141
|
+
const fileName = runtimeRigGitFileName();
|
|
1142
|
+
const explicit = process.env.RIG_NATIVE_GIT_BIN?.trim() || "";
|
|
1143
|
+
return [...new Set([
|
|
1144
|
+
explicit,
|
|
1145
|
+
...nativePackageBinaryCandidates(import.meta.dir, fileName),
|
|
1146
|
+
execDir ? resolve2(execDir, fileName) : "",
|
|
1147
|
+
execDir ? resolve2(execDir, "..", fileName) : "",
|
|
1148
|
+
execDir ? resolve2(execDir, "..", "bin", fileName) : "",
|
|
1149
|
+
sharedGitNativeOutputPath
|
|
1150
|
+
].filter(Boolean))];
|
|
1151
|
+
}
|
|
1152
|
+
function resolveGitSourcePath() {
|
|
1153
|
+
for (const candidate of rigGitSourceCandidates()) {
|
|
1154
|
+
if (candidate && existsSync2(candidate)) {
|
|
1155
|
+
return candidate;
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
return null;
|
|
1159
|
+
}
|
|
1160
|
+
function resolveGitBinaryPath() {
|
|
1161
|
+
if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
|
|
1162
|
+
return null;
|
|
1163
|
+
}
|
|
1164
|
+
for (const candidate of rigGitBinaryCandidates()) {
|
|
1165
|
+
if (candidate && existsSync2(candidate)) {
|
|
1166
|
+
return candidate;
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
return null;
|
|
1170
|
+
}
|
|
1171
|
+
function preferredGitBinaryOutputPath() {
|
|
1172
|
+
const explicit = process.env.RIG_NATIVE_GIT_BIN?.trim() || "";
|
|
1173
|
+
return explicit || sharedGitNativeOutputPath;
|
|
1174
|
+
}
|
|
1175
|
+
function binarySupportsTrackerCommandsSync(binaryPath) {
|
|
1176
|
+
try {
|
|
1177
|
+
const probe = Bun.spawnSync([binaryPath, "fetch-ref", "."], {
|
|
1178
|
+
stdout: "pipe",
|
|
1179
|
+
stderr: "pipe"
|
|
1180
|
+
});
|
|
1181
|
+
const stdout = probe.stdout.toString().trim();
|
|
1182
|
+
const stderr = probe.stderr.toString().trim();
|
|
1183
|
+
if (stdout.includes('"error":"unknown command"')) {
|
|
1184
|
+
return false;
|
|
1185
|
+
}
|
|
1186
|
+
return probe.exitCode === 2 && stderr.includes(trackerCommandUsageProbe);
|
|
1187
|
+
} catch {
|
|
1188
|
+
return false;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
function nativeBuildManifestPath(outputPath) {
|
|
1192
|
+
return `${outputPath}.build-manifest.json`;
|
|
1193
|
+
}
|
|
1194
|
+
function hasMatchingNativeBuildManifestSync(manifestPath, buildKey) {
|
|
1195
|
+
if (!existsSync2(manifestPath)) {
|
|
1196
|
+
return false;
|
|
1197
|
+
}
|
|
1198
|
+
try {
|
|
1199
|
+
const manifest = JSON.parse(readFileSync2(manifestPath, "utf8"));
|
|
1200
|
+
return manifest.version === 1 && manifest.buildKey === buildKey;
|
|
1201
|
+
} catch {
|
|
1202
|
+
return false;
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
function sha256FileSync(path) {
|
|
1206
|
+
return createHash2("sha256").update(readFileSync2(path)).digest("hex");
|
|
1207
|
+
}
|
|
1208
|
+
function ensureRigGitBinaryPathSync(outputPath = preferredGitBinaryOutputPath()) {
|
|
1209
|
+
if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
|
|
1210
|
+
throw new Error("Zig native git is disabled via RIG_DISABLE_ZIG_NATIVE=1");
|
|
1211
|
+
}
|
|
1212
|
+
const explicitBin = process.env.RIG_NATIVE_GIT_BIN?.trim();
|
|
1213
|
+
if (explicitBin && existsSync2(explicitBin)) {
|
|
1214
|
+
return explicitBin;
|
|
1215
|
+
}
|
|
1216
|
+
const embedded = extractEmbeddedNative("rig-git");
|
|
1217
|
+
if (embedded) {
|
|
1218
|
+
return embedded;
|
|
1219
|
+
}
|
|
1220
|
+
const sourcePath = resolveGitSourcePath();
|
|
1221
|
+
if (!sourcePath) {
|
|
1222
|
+
const binaryPath = resolveGitBinaryPath();
|
|
1223
|
+
if (binaryPath) {
|
|
1224
|
+
return binaryPath;
|
|
1225
|
+
}
|
|
1226
|
+
throw new Error("rig-git.zig source file not found.");
|
|
1227
|
+
}
|
|
1228
|
+
const zigBinary = Bun.which("zig");
|
|
1229
|
+
if (!zigBinary) {
|
|
1230
|
+
throw new Error("zig is required to build native Rig git tools.");
|
|
1231
|
+
}
|
|
1232
|
+
mkdirSync3(dirname2(outputPath), { recursive: true });
|
|
1233
|
+
const sourceDigest = sha256FileSync(sourcePath);
|
|
1234
|
+
const buildKey = JSON.stringify({
|
|
1235
|
+
version: 1,
|
|
1236
|
+
zigBinary,
|
|
1237
|
+
platform: process.platform,
|
|
1238
|
+
arch: process.arch,
|
|
1239
|
+
sourcePath,
|
|
1240
|
+
sourceDigest
|
|
1241
|
+
});
|
|
1242
|
+
const manifestPath = nativeBuildManifestPath(outputPath);
|
|
1243
|
+
const needsBuild = !existsSync2(outputPath) || !hasMatchingNativeBuildManifestSync(manifestPath, buildKey) || !binarySupportsTrackerCommandsSync(outputPath);
|
|
1244
|
+
if (!needsBuild) {
|
|
1245
|
+
chmodSync(outputPath, 493);
|
|
1246
|
+
return outputPath;
|
|
1247
|
+
}
|
|
1248
|
+
const materialized = materializeFromSharedGitBinarySync(outputPath, buildKey);
|
|
1249
|
+
if (materialized)
|
|
1250
|
+
return materialized;
|
|
1251
|
+
const tempOutputPath = temporaryGitBinaryOutputPath(outputPath);
|
|
1252
|
+
const build = Bun.spawnSync([
|
|
1253
|
+
zigBinary,
|
|
1254
|
+
"build-exe",
|
|
1255
|
+
sourcePath,
|
|
1256
|
+
"-O",
|
|
1257
|
+
"ReleaseFast",
|
|
1258
|
+
`-femit-bin=${tempOutputPath}`
|
|
1259
|
+
], {
|
|
1260
|
+
cwd: dirname2(sourcePath),
|
|
1261
|
+
stdout: "pipe",
|
|
1262
|
+
stderr: "pipe"
|
|
1263
|
+
});
|
|
1264
|
+
if (build.exitCode !== 0 || !existsSync2(tempOutputPath)) {
|
|
1265
|
+
const stderr = build.stderr.toString().trim();
|
|
1266
|
+
const stdout = build.stdout.toString().trim();
|
|
1267
|
+
const details = [stderr, stdout].filter(Boolean).join(`
|
|
1268
|
+
`);
|
|
1269
|
+
throw new Error(`Failed to build native Rig git tools: ${details || `zig exited with code ${build.exitCode}`}`);
|
|
1270
|
+
}
|
|
1271
|
+
chmodSync(tempOutputPath, 493);
|
|
1272
|
+
if (existsSync2(outputPath) && hasMatchingNativeBuildManifestSync(manifestPath, buildKey)) {
|
|
1273
|
+
rmSync(tempOutputPath, { force: true });
|
|
1274
|
+
chmodSync(outputPath, 493);
|
|
1275
|
+
return outputPath;
|
|
1276
|
+
}
|
|
1277
|
+
publishGitBinary(tempOutputPath, outputPath);
|
|
1278
|
+
if (!binarySupportsTrackerCommandsSync(outputPath)) {
|
|
1279
|
+
rmSync(outputPath, { force: true });
|
|
1280
|
+
throw new Error("Failed to build native Rig git tools: tracker command probe failed");
|
|
1281
|
+
}
|
|
1282
|
+
writeFileSync2(manifestPath, `${JSON.stringify({ version: 1, buildKey }, null, 2)}
|
|
1283
|
+
`, "utf8");
|
|
1284
|
+
return outputPath;
|
|
1285
|
+
}
|
|
1286
|
+
function gitNativeEnv() {
|
|
1287
|
+
const env = { ...process.env };
|
|
1288
|
+
const token = env.GITHUB_TOKEN?.trim() || env.GH_TOKEN?.trim() || env.RIG_GITHUB_TOKEN?.trim() || "";
|
|
1289
|
+
if (token) {
|
|
1290
|
+
env.RIG_GITHUB_TOKEN = env.RIG_GITHUB_TOKEN || token;
|
|
1291
|
+
env.GITHUB_TOKEN = env.GITHUB_TOKEN || token;
|
|
1292
|
+
env.GH_TOKEN = env.GH_TOKEN || token;
|
|
1293
|
+
env.GIT_TERMINAL_PROMPT = "0";
|
|
1294
|
+
env.GIT_CONFIG_COUNT = "2";
|
|
1295
|
+
env.GIT_CONFIG_KEY_0 = "credential.helper";
|
|
1296
|
+
env.GIT_CONFIG_VALUE_0 = "";
|
|
1297
|
+
env.GIT_CONFIG_KEY_1 = "credential.helper";
|
|
1298
|
+
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';
|
|
1299
|
+
}
|
|
1300
|
+
return env;
|
|
1301
|
+
}
|
|
1302
|
+
function runGitNative(command, args) {
|
|
1303
|
+
if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
|
|
1304
|
+
return { ok: false, error: "rig-git native disabled" };
|
|
1305
|
+
}
|
|
1306
|
+
const trackerCommand = command === "fetch-ref" || command === "read-blob-at-ref" || command === "write-tree-commit" || command === "push-ref-with-lease";
|
|
1307
|
+
let binaryPath = null;
|
|
1308
|
+
if (trackerCommand) {
|
|
1309
|
+
try {
|
|
1310
|
+
binaryPath = ensureRigGitBinaryPathSync(preferredGitBinaryOutputPath());
|
|
1311
|
+
} catch (error) {
|
|
1312
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1313
|
+
if (message.includes("rig-git.zig source file not found")) {
|
|
1314
|
+
return { ok: false, error: "rig-git binary not found" };
|
|
1315
|
+
}
|
|
1316
|
+
return { ok: false, error: message };
|
|
1317
|
+
}
|
|
1318
|
+
} else {
|
|
1319
|
+
const explicitBinaryPath = process.env.RIG_NATIVE_GIT_BIN?.trim() || "";
|
|
1320
|
+
binaryPath = explicitBinaryPath && existsSync2(explicitBinaryPath) ? explicitBinaryPath : !explicitBinaryPath ? resolveGitBinaryPath() : null;
|
|
1321
|
+
if (!binaryPath) {
|
|
1322
|
+
try {
|
|
1323
|
+
binaryPath = ensureRigGitBinaryPathSync(preferredGitBinaryOutputPath());
|
|
1324
|
+
} catch (error) {
|
|
1325
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1326
|
+
if (message.includes("rig-git.zig source file not found")) {
|
|
1327
|
+
return { ok: false, error: "rig-git binary not found" };
|
|
1328
|
+
}
|
|
1329
|
+
return { ok: false, error: message };
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
try {
|
|
1334
|
+
const proc = Bun.spawnSync([binaryPath, command, ...args], {
|
|
1335
|
+
stdout: "pipe",
|
|
1336
|
+
stderr: "pipe",
|
|
1337
|
+
env: gitNativeEnv()
|
|
1338
|
+
});
|
|
1339
|
+
if (proc.exitCode !== 0) {
|
|
1340
|
+
const stdoutText = proc.stdout.toString().trim();
|
|
1341
|
+
if (stdoutText) {
|
|
1342
|
+
try {
|
|
1343
|
+
const parsed = JSON.parse(stdoutText);
|
|
1344
|
+
if (!parsed.ok) {
|
|
1345
|
+
return parsed;
|
|
1346
|
+
}
|
|
1347
|
+
} catch {}
|
|
1348
|
+
}
|
|
1349
|
+
const errText = proc.stderr.toString().trim() || `exit code ${proc.exitCode}`;
|
|
1350
|
+
return { ok: false, error: errText };
|
|
1351
|
+
}
|
|
1352
|
+
const output = proc.stdout.toString().trim();
|
|
1353
|
+
return JSON.parse(output);
|
|
1354
|
+
} catch (err) {
|
|
1355
|
+
return { ok: false, error: String(err) };
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
function requireGitNative(command, args) {
|
|
1359
|
+
const result = runGitNative(command, args);
|
|
1360
|
+
if (result.ok === false) {
|
|
1361
|
+
throw new Error(`rig-git ${command} failed: ${result.error}`);
|
|
1362
|
+
}
|
|
1363
|
+
return result;
|
|
1364
|
+
}
|
|
1365
|
+
function requireGitNativeString(command, args) {
|
|
1366
|
+
const result = requireGitNative(command, args);
|
|
1367
|
+
if ("value" in result && typeof result.value === "string") {
|
|
1368
|
+
return result.value;
|
|
1369
|
+
}
|
|
1370
|
+
throw new Error(`rig-git ${command} returned an unexpected result payload`);
|
|
1371
|
+
}
|
|
1372
|
+
function nativeFetchRef(repoPath, remote, branch) {
|
|
1373
|
+
return requireGitNativeString("fetch-ref", [repoPath, remote, branch]);
|
|
1374
|
+
}
|
|
1375
|
+
function nativeReadBlobBytesAtRef(repoPath, ref, path) {
|
|
1376
|
+
const requestDir = resolve2(sharedGitNativeOutputDir, "reads", `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`);
|
|
1377
|
+
mkdirSync3(requestDir, { recursive: true });
|
|
1378
|
+
const outputPath = resolve2(requestDir, "blob.bin");
|
|
1379
|
+
try {
|
|
1380
|
+
requireGitNative("read-blob-at-ref", [repoPath, ref, path, outputPath]);
|
|
1381
|
+
return readFileSync2(outputPath);
|
|
1382
|
+
} finally {
|
|
1383
|
+
rmSync(requestDir, { recursive: true, force: true });
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
function serializeTreeCommitUpdates(updates) {
|
|
1387
|
+
return updates.map((update) => {
|
|
1388
|
+
if (isTextTreeCommitUpdate(update)) {
|
|
1389
|
+
return { path: update.path, kind: "text", content: update.content };
|
|
1390
|
+
}
|
|
1391
|
+
if (!isAbsolute(update.sourceFilePath)) {
|
|
1392
|
+
throw new Error("tree commit binary updates require an absolute sourceFilePath");
|
|
1393
|
+
}
|
|
1394
|
+
return { path: update.path, kind: "file", sourceFilePath: update.sourceFilePath };
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
function buildTreeCommitUpdatesJson(updates) {
|
|
1398
|
+
return `${JSON.stringify(serializeTreeCommitUpdates(updates), null, 2)}
|
|
1399
|
+
`;
|
|
1400
|
+
}
|
|
1401
|
+
function nativeWriteTreeCommit(repoPath, baseRef, updates, message) {
|
|
1402
|
+
const requestDir = resolve2(sharedGitNativeOutputDir, "requests", `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`);
|
|
1403
|
+
mkdirSync3(requestDir, { recursive: true });
|
|
1404
|
+
const messagePath = resolve2(requestDir, "message.txt");
|
|
1405
|
+
const updatesPath = resolve2(requestDir, "updates.json");
|
|
1406
|
+
try {
|
|
1407
|
+
writeFileSync2(messagePath, message, "utf8");
|
|
1408
|
+
writeFileSync2(updatesPath, buildTreeCommitUpdatesJson(updates), "utf8");
|
|
1409
|
+
return requireGitNativeString("write-tree-commit", [repoPath, baseRef, messagePath, updatesPath]);
|
|
1410
|
+
} finally {
|
|
1411
|
+
rmSync(requestDir, { recursive: true, force: true });
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
function nativePushRefWithLease(repoPath, localOid, remoteRef, expectedOldOid, remote = "origin") {
|
|
1415
|
+
return requireGitNativeString("push-ref-with-lease", [
|
|
1416
|
+
repoPath,
|
|
1417
|
+
localOid,
|
|
1418
|
+
remoteRef,
|
|
1419
|
+
expectedOldOid,
|
|
1420
|
+
remote
|
|
1421
|
+
]);
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
// packages/memory-plugin/src/read.ts
|
|
1425
|
+
import { mkdtempSync, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
1426
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
1030
1427
|
import { join } from "path";
|
|
1031
|
-
import {
|
|
1032
|
-
import { resolveMonorepoRoot } from "@rig/runtime/control-plane/native/utils";
|
|
1428
|
+
import { resolveCheckoutRoot as resolveMonorepoRoot } from "@rig/core/checkout-root";
|
|
1033
1429
|
var CANONICAL_MEMORY_DB_PATH = "rig/memory/project-memory.db";
|
|
1034
1430
|
var DEFAULT_READ_DEPS = {
|
|
1035
1431
|
fetchRef: nativeFetchRef,
|
|
1036
1432
|
readBlobBytesAtRef: nativeReadBlobBytesAtRef,
|
|
1037
1433
|
openMemoryDb,
|
|
1038
|
-
makeTempDir: () => mkdtempSync(join(
|
|
1039
|
-
removeDir: (path) =>
|
|
1434
|
+
makeTempDir: () => mkdtempSync(join(tmpdir3(), "memory-sync-read-")),
|
|
1435
|
+
removeDir: (path) => rmSync2(path, { recursive: true, force: true })
|
|
1040
1436
|
};
|
|
1041
1437
|
function isMissingCanonicalMemoryBlobError(error) {
|
|
1042
1438
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -1074,7 +1470,7 @@ async function readCanonicalMemoryDb(projectRoot, deps = {}) {
|
|
|
1074
1470
|
} else {
|
|
1075
1471
|
try {
|
|
1076
1472
|
const bytes = readDeps.readBlobBytesAtRef(repoPath, baseOid, CANONICAL_MEMORY_DB_PATH);
|
|
1077
|
-
|
|
1473
|
+
writeFileSync3(dbPath, bytes);
|
|
1078
1474
|
} catch (error) {
|
|
1079
1475
|
if (!isMissingCanonicalMemoryBlobError(error)) {
|
|
1080
1476
|
throw error;
|
|
@@ -1160,7 +1556,9 @@ async function promoteCanonicalMemoryEvent(projectRoot, input, deps = {}) {
|
|
|
1160
1556
|
}
|
|
1161
1557
|
|
|
1162
1558
|
// packages/memory-plugin/src/cli.ts
|
|
1163
|
-
import {
|
|
1559
|
+
import {
|
|
1560
|
+
NO_MATCH_RETRIEVAL_CANONICAL_KEY as NO_MATCH_RETRIEVAL_CANONICAL_KEY2
|
|
1561
|
+
} from "@rig/contracts";
|
|
1164
1562
|
function takeOption(args, option) {
|
|
1165
1563
|
const rest = [];
|
|
1166
1564
|
let value;
|
|
@@ -1182,7 +1580,7 @@ function takeOption(args, option) {
|
|
|
1182
1580
|
rest.push(current);
|
|
1183
1581
|
}
|
|
1184
1582
|
}
|
|
1185
|
-
return { value, rest };
|
|
1583
|
+
return { ...value !== undefined ? { value } : {}, rest };
|
|
1186
1584
|
}
|
|
1187
1585
|
function usage(verb) {
|
|
1188
1586
|
switch (verb) {
|
|
@@ -1234,7 +1632,7 @@ function requireRuntimeMemoryContext(runtimeContext) {
|
|
|
1234
1632
|
}
|
|
1235
1633
|
async function ensureRuntimeMemoryUsable(runtimeContext) {
|
|
1236
1634
|
const memory = requireRuntimeMemoryContext(runtimeContext);
|
|
1237
|
-
if (!
|
|
1635
|
+
if (!existsSync3(memory.hydratedPath)) {
|
|
1238
1636
|
throw new Error(`Shared memory database is missing: ${memory.hydratedPath}`);
|
|
1239
1637
|
}
|
|
1240
1638
|
const db = await openMemoryDb(memory.hydratedPath);
|
|
@@ -1310,7 +1708,7 @@ function requestedPayload(verb, mutationKind, canonicalKey, extra) {
|
|
|
1310
1708
|
return {
|
|
1311
1709
|
command: verb,
|
|
1312
1710
|
mutationKind,
|
|
1313
|
-
canonicalKey,
|
|
1711
|
+
...canonicalKey !== undefined ? { canonicalKey } : {},
|
|
1314
1712
|
...extra
|
|
1315
1713
|
};
|
|
1316
1714
|
}
|
package/dist/src/db.js
CHANGED
|
@@ -149,11 +149,12 @@ function eventFeedbackOutcome(event) {
|
|
|
149
149
|
}
|
|
150
150
|
function normalizeStatement(statement, args) {
|
|
151
151
|
if (typeof statement === "string") {
|
|
152
|
-
return { sql: statement, args };
|
|
152
|
+
return { sql: statement, ...args !== undefined ? { args } : {} };
|
|
153
153
|
}
|
|
154
|
+
const resolvedArgs = statement.args ?? args;
|
|
154
155
|
return {
|
|
155
156
|
sql: statement.sql,
|
|
156
|
-
args:
|
|
157
|
+
...resolvedArgs !== undefined ? { args: resolvedArgs } : {}
|
|
157
158
|
};
|
|
158
159
|
}
|
|
159
160
|
function normalizeBindings(bindings) {
|
|
@@ -188,7 +189,7 @@ function executeSqlite(sqlite, statement, args) {
|
|
|
188
189
|
const normalized = normalizeStatement(statement, args);
|
|
189
190
|
const bindings = normalizeBindings(normalized.args);
|
|
190
191
|
if (isMutationStatement(normalized.sql)) {
|
|
191
|
-
const result = bindings.length > 0 ? sqlite.run(normalized.sql,
|
|
192
|
+
const result = bindings.length > 0 ? sqlite.run(normalized.sql, bindings) : sqlite.run(normalized.sql);
|
|
192
193
|
return {
|
|
193
194
|
rows: [],
|
|
194
195
|
rowsAffected: Number(result.changes)
|
package/dist/src/embed.js
CHANGED
|
@@ -201,7 +201,7 @@ function createConfiguredMemoryEmbedder(options = {}) {
|
|
|
201
201
|
apiKey,
|
|
202
202
|
model: env.RIG_MEMORY_EMBEDDING_MODEL?.trim() || DEFAULT_EMBEDDING_MODEL,
|
|
203
203
|
apiBaseUrl: options.apiBaseUrl ?? env.RIG_MEMORY_EMBEDDING_API_BASE_URL?.trim() ?? DEFAULT_EMBEDDING_API_BASE_URL,
|
|
204
|
-
fetchImpl: options.fetchImpl
|
|
204
|
+
...options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}
|
|
205
205
|
});
|
|
206
206
|
}
|
|
207
207
|
function warnMissingMemoryEmbedderOnce(warn) {
|