@h-rig/memory-plugin 0.0.6-alpha.157 → 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.
@@ -76,11 +76,12 @@ function eventFeedbackOutcome(event) {
76
76
  }
77
77
  function normalizeStatement(statement, args) {
78
78
  if (typeof statement === "string") {
79
- return { sql: statement, args };
79
+ return { sql: statement, ...args !== undefined ? { args } : {} };
80
80
  }
81
+ const resolvedArgs = statement.args ?? args;
81
82
  return {
82
83
  sql: statement.sql,
83
- args: statement.args ?? args
84
+ ...resolvedArgs !== undefined ? { args: resolvedArgs } : {}
84
85
  };
85
86
  }
86
87
  function normalizeBindings(bindings) {
@@ -115,7 +116,7 @@ function executeSqlite(sqlite, statement, args) {
115
116
  const normalized = normalizeStatement(statement, args);
116
117
  const bindings = normalizeBindings(normalized.args);
117
118
  if (isMutationStatement(normalized.sql)) {
118
- const result = bindings.length > 0 ? sqlite.run(normalized.sql, ...bindings) : sqlite.run(normalized.sql);
119
+ const result = bindings.length > 0 ? sqlite.run(normalized.sql, bindings) : sqlite.run(normalized.sql);
119
120
  return {
120
121
  rows: [],
121
122
  rowsAffected: Number(result.changes)
@@ -859,7 +860,7 @@ function createConfiguredMemoryEmbedder(options = {}) {
859
860
  apiKey,
860
861
  model: env.RIG_MEMORY_EMBEDDING_MODEL?.trim() || DEFAULT_EMBEDDING_MODEL,
861
862
  apiBaseUrl: options.apiBaseUrl ?? env.RIG_MEMORY_EMBEDDING_API_BASE_URL?.trim() ?? DEFAULT_EMBEDDING_API_BASE_URL,
862
- fetchImpl: options.fetchImpl
863
+ ...options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}
863
864
  });
864
865
  }
865
866
  function warnMissingMemoryEmbedderOnce(warn) {
@@ -935,7 +936,7 @@ var init_embed = __esm(() => {
935
936
  // packages/memory-plugin/src/query.ts
936
937
  import {
937
938
  DEFAULT_RUNTIME_MEMORY_RETRIEVAL
938
- } from "@rig/runtime/control-plane/runtime/context";
939
+ } from "@rig/core/runtime-context";
939
940
  function tokenize(text) {
940
941
  return (text.toLowerCase().match(/[a-z0-9_./:-]+/g) ?? []).flatMap((token) => {
941
942
  const split = token.split(/[./:_-]+/).filter(Boolean);
@@ -1038,12 +1039,412 @@ var init_query = __esm(() => {
1038
1039
  DAY_MS = 24 * 60 * 60 * 1000;
1039
1040
  });
1040
1041
 
1041
- // packages/memory-plugin/src/read.ts
1042
- import { mkdtempSync, rmSync, writeFileSync } from "fs";
1042
+ // packages/memory-plugin/src/embedded-native-assets.ts
1043
+ var embeddedNatives = null;
1044
+
1045
+ // packages/memory-plugin/src/native-extract.ts
1046
+ import { existsSync, mkdirSync as mkdirSync2, readFileSync, renameSync, statSync, writeFileSync } from "fs";
1043
1047
  import { tmpdir } from "os";
1048
+ import { resolve } from "path";
1049
+ function extractEmbeddedNative(name) {
1050
+ if (name in extractionCache) {
1051
+ return extractionCache[name] ?? null;
1052
+ }
1053
+ const entry = embeddedNatives?.[name];
1054
+ if (!entry) {
1055
+ extractionCache[name] = null;
1056
+ return null;
1057
+ }
1058
+ try {
1059
+ const targetPath = resolve(sharedNativeOutputDir, entry.fileName);
1060
+ mkdirSync2(sharedNativeOutputDir, { recursive: true });
1061
+ const upToDate = existsSync(targetPath) && statSync(targetPath).size === entry.size;
1062
+ if (!upToDate) {
1063
+ const bytes = readFileSync(entry.filePath);
1064
+ const tempPath = `${targetPath}.${process.pid}.${Date.now()}.tmp`;
1065
+ writeFileSync(tempPath, bytes, { mode: 493 });
1066
+ renameSync(tempPath, targetPath);
1067
+ }
1068
+ extractionCache[name] = targetPath;
1069
+ } catch {
1070
+ extractionCache[name] = null;
1071
+ }
1072
+ return extractionCache[name] ?? null;
1073
+ }
1074
+ var sharedNativeOutputDir, extractionCache;
1075
+ var init_native_extract = __esm(() => {
1076
+ sharedNativeOutputDir = resolve(tmpdir(), "rig-native");
1077
+ extractionCache = {};
1078
+ });
1079
+
1080
+ // packages/memory-plugin/src/native-git.ts
1081
+ import { chmodSync, copyFileSync, existsSync as existsSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync2, renameSync as renameSync2, rmSync, writeFileSync as writeFileSync2 } from "fs";
1082
+ import { tmpdir as tmpdir2 } from "os";
1083
+ import { dirname as dirname2, isAbsolute, resolve as resolve2 } from "path";
1084
+ import { createHash as createHash2 } from "crypto";
1085
+ function isTextTreeCommitUpdate(update) {
1086
+ return typeof update.content === "string";
1087
+ }
1088
+ function temporaryGitBinaryOutputPath(outputPath) {
1089
+ const suffix = process.platform === "win32" ? ".exe" : "";
1090
+ return resolve2(dirname2(outputPath), `.rig-git-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}${suffix}`);
1091
+ }
1092
+ function publishGitBinary(tempOutputPath, outputPath) {
1093
+ try {
1094
+ renameSync2(tempOutputPath, outputPath);
1095
+ } catch (error) {
1096
+ if (process.platform === "win32" && existsSync2(outputPath)) {
1097
+ rmSync(outputPath, { force: true });
1098
+ renameSync2(tempOutputPath, outputPath);
1099
+ return;
1100
+ }
1101
+ throw error;
1102
+ }
1103
+ }
1104
+ function isSharedGitNativeOutputPath(outputPath) {
1105
+ return resolve2(outputPath) === sharedGitNativeOutputPath;
1106
+ }
1107
+ function materializeFromSharedGitBinarySync(outputPath, buildKey) {
1108
+ if (isSharedGitNativeOutputPath(outputPath))
1109
+ return null;
1110
+ const sharedManifest = nativeBuildManifestPath(sharedGitNativeOutputPath);
1111
+ if (!existsSync2(sharedGitNativeOutputPath) || !hasMatchingNativeBuildManifestSync(sharedManifest, buildKey) || !binarySupportsTrackerCommandsSync(sharedGitNativeOutputPath)) {
1112
+ return null;
1113
+ }
1114
+ mkdirSync3(dirname2(outputPath), { recursive: true });
1115
+ copyFileSync(sharedGitNativeOutputPath, outputPath);
1116
+ chmodSync(outputPath, 493);
1117
+ writeFileSync2(nativeBuildManifestPath(outputPath), `${JSON.stringify({ version: 1, buildKey }, null, 2)}
1118
+ `, "utf8");
1119
+ return outputPath;
1120
+ }
1121
+ function runtimeRigGitFileName() {
1122
+ return `rig-git${process.platform === "win32" ? ".exe" : ""}`;
1123
+ }
1124
+ function rigGitSourceCandidates() {
1125
+ const execDir = process.execPath?.trim() ? dirname2(process.execPath.trim()) : "";
1126
+ const cwd = process.cwd()?.trim() || "";
1127
+ const projectRoot = process.env.PROJECT_RIG_ROOT?.trim() || "";
1128
+ const hostProjectRoot = process.env.RIG_HOST_PROJECT_ROOT?.trim() || "";
1129
+ const moduleRelativeSource = resolve2(import.meta.dir, "../native/rig-git.zig");
1130
+ return [...new Set([
1131
+ process.env.RIG_NATIVE_GIT_SOURCE?.trim() || "",
1132
+ moduleRelativeSource,
1133
+ projectRoot ? resolve2(projectRoot, "packages/memory-plugin/native/rig-git.zig") : "",
1134
+ hostProjectRoot ? resolve2(hostProjectRoot, "packages/memory-plugin/native/rig-git.zig") : "",
1135
+ cwd ? resolve2(cwd, "packages/memory-plugin/native/rig-git.zig") : "",
1136
+ execDir ? resolve2(execDir, "..", "..", "packages/memory-plugin/native/rig-git.zig") : "",
1137
+ execDir ? resolve2(execDir, "..", "native", "rig-git.zig") : ""
1138
+ ].filter(Boolean))];
1139
+ }
1140
+ function nativePackageBinaryCandidates(fromDir, fileName) {
1141
+ const candidates = [];
1142
+ let cursor = resolve2(fromDir);
1143
+ for (let index = 0;index < 8; index += 1) {
1144
+ 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));
1145
+ const parent = dirname2(cursor);
1146
+ if (parent === cursor)
1147
+ break;
1148
+ cursor = parent;
1149
+ }
1150
+ return candidates;
1151
+ }
1152
+ function rigGitBinaryCandidates() {
1153
+ const execDir = process.execPath?.trim() ? dirname2(process.execPath.trim()) : "";
1154
+ const fileName = runtimeRigGitFileName();
1155
+ const explicit = process.env.RIG_NATIVE_GIT_BIN?.trim() || "";
1156
+ return [...new Set([
1157
+ explicit,
1158
+ ...nativePackageBinaryCandidates(import.meta.dir, fileName),
1159
+ execDir ? resolve2(execDir, fileName) : "",
1160
+ execDir ? resolve2(execDir, "..", fileName) : "",
1161
+ execDir ? resolve2(execDir, "..", "bin", fileName) : "",
1162
+ sharedGitNativeOutputPath
1163
+ ].filter(Boolean))];
1164
+ }
1165
+ function resolveGitSourcePath() {
1166
+ for (const candidate of rigGitSourceCandidates()) {
1167
+ if (candidate && existsSync2(candidate)) {
1168
+ return candidate;
1169
+ }
1170
+ }
1171
+ return null;
1172
+ }
1173
+ function resolveGitBinaryPath() {
1174
+ if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
1175
+ return null;
1176
+ }
1177
+ for (const candidate of rigGitBinaryCandidates()) {
1178
+ if (candidate && existsSync2(candidate)) {
1179
+ return candidate;
1180
+ }
1181
+ }
1182
+ return null;
1183
+ }
1184
+ function preferredGitBinaryOutputPath() {
1185
+ const explicit = process.env.RIG_NATIVE_GIT_BIN?.trim() || "";
1186
+ return explicit || sharedGitNativeOutputPath;
1187
+ }
1188
+ function binarySupportsTrackerCommandsSync(binaryPath) {
1189
+ try {
1190
+ const probe = Bun.spawnSync([binaryPath, "fetch-ref", "."], {
1191
+ stdout: "pipe",
1192
+ stderr: "pipe"
1193
+ });
1194
+ const stdout = probe.stdout.toString().trim();
1195
+ const stderr = probe.stderr.toString().trim();
1196
+ if (stdout.includes('"error":"unknown command"')) {
1197
+ return false;
1198
+ }
1199
+ return probe.exitCode === 2 && stderr.includes(trackerCommandUsageProbe);
1200
+ } catch {
1201
+ return false;
1202
+ }
1203
+ }
1204
+ function nativeBuildManifestPath(outputPath) {
1205
+ return `${outputPath}.build-manifest.json`;
1206
+ }
1207
+ function hasMatchingNativeBuildManifestSync(manifestPath, buildKey) {
1208
+ if (!existsSync2(manifestPath)) {
1209
+ return false;
1210
+ }
1211
+ try {
1212
+ const manifest = JSON.parse(readFileSync2(manifestPath, "utf8"));
1213
+ return manifest.version === 1 && manifest.buildKey === buildKey;
1214
+ } catch {
1215
+ return false;
1216
+ }
1217
+ }
1218
+ function sha256FileSync(path) {
1219
+ return createHash2("sha256").update(readFileSync2(path)).digest("hex");
1220
+ }
1221
+ function ensureRigGitBinaryPathSync(outputPath = preferredGitBinaryOutputPath()) {
1222
+ if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
1223
+ throw new Error("Zig native git is disabled via RIG_DISABLE_ZIG_NATIVE=1");
1224
+ }
1225
+ const explicitBin = process.env.RIG_NATIVE_GIT_BIN?.trim();
1226
+ if (explicitBin && existsSync2(explicitBin)) {
1227
+ return explicitBin;
1228
+ }
1229
+ const embedded = extractEmbeddedNative("rig-git");
1230
+ if (embedded) {
1231
+ return embedded;
1232
+ }
1233
+ const sourcePath = resolveGitSourcePath();
1234
+ if (!sourcePath) {
1235
+ const binaryPath = resolveGitBinaryPath();
1236
+ if (binaryPath) {
1237
+ return binaryPath;
1238
+ }
1239
+ throw new Error("rig-git.zig source file not found.");
1240
+ }
1241
+ const zigBinary = Bun.which("zig");
1242
+ if (!zigBinary) {
1243
+ throw new Error("zig is required to build native Rig git tools.");
1244
+ }
1245
+ mkdirSync3(dirname2(outputPath), { recursive: true });
1246
+ const sourceDigest = sha256FileSync(sourcePath);
1247
+ const buildKey = JSON.stringify({
1248
+ version: 1,
1249
+ zigBinary,
1250
+ platform: process.platform,
1251
+ arch: process.arch,
1252
+ sourcePath,
1253
+ sourceDigest
1254
+ });
1255
+ const manifestPath = nativeBuildManifestPath(outputPath);
1256
+ const needsBuild = !existsSync2(outputPath) || !hasMatchingNativeBuildManifestSync(manifestPath, buildKey) || !binarySupportsTrackerCommandsSync(outputPath);
1257
+ if (!needsBuild) {
1258
+ chmodSync(outputPath, 493);
1259
+ return outputPath;
1260
+ }
1261
+ const materialized = materializeFromSharedGitBinarySync(outputPath, buildKey);
1262
+ if (materialized)
1263
+ return materialized;
1264
+ const tempOutputPath = temporaryGitBinaryOutputPath(outputPath);
1265
+ const build = Bun.spawnSync([
1266
+ zigBinary,
1267
+ "build-exe",
1268
+ sourcePath,
1269
+ "-O",
1270
+ "ReleaseFast",
1271
+ `-femit-bin=${tempOutputPath}`
1272
+ ], {
1273
+ cwd: dirname2(sourcePath),
1274
+ stdout: "pipe",
1275
+ stderr: "pipe"
1276
+ });
1277
+ if (build.exitCode !== 0 || !existsSync2(tempOutputPath)) {
1278
+ const stderr = build.stderr.toString().trim();
1279
+ const stdout = build.stdout.toString().trim();
1280
+ const details = [stderr, stdout].filter(Boolean).join(`
1281
+ `);
1282
+ throw new Error(`Failed to build native Rig git tools: ${details || `zig exited with code ${build.exitCode}`}`);
1283
+ }
1284
+ chmodSync(tempOutputPath, 493);
1285
+ if (existsSync2(outputPath) && hasMatchingNativeBuildManifestSync(manifestPath, buildKey)) {
1286
+ rmSync(tempOutputPath, { force: true });
1287
+ chmodSync(outputPath, 493);
1288
+ return outputPath;
1289
+ }
1290
+ publishGitBinary(tempOutputPath, outputPath);
1291
+ if (!binarySupportsTrackerCommandsSync(outputPath)) {
1292
+ rmSync(outputPath, { force: true });
1293
+ throw new Error("Failed to build native Rig git tools: tracker command probe failed");
1294
+ }
1295
+ writeFileSync2(manifestPath, `${JSON.stringify({ version: 1, buildKey }, null, 2)}
1296
+ `, "utf8");
1297
+ return outputPath;
1298
+ }
1299
+ function gitNativeEnv() {
1300
+ const env = { ...process.env };
1301
+ const token = env.GITHUB_TOKEN?.trim() || env.GH_TOKEN?.trim() || env.RIG_GITHUB_TOKEN?.trim() || "";
1302
+ if (token) {
1303
+ env.RIG_GITHUB_TOKEN = env.RIG_GITHUB_TOKEN || token;
1304
+ env.GITHUB_TOKEN = env.GITHUB_TOKEN || token;
1305
+ env.GH_TOKEN = env.GH_TOKEN || token;
1306
+ env.GIT_TERMINAL_PROMPT = "0";
1307
+ env.GIT_CONFIG_COUNT = "2";
1308
+ env.GIT_CONFIG_KEY_0 = "credential.helper";
1309
+ env.GIT_CONFIG_VALUE_0 = "";
1310
+ env.GIT_CONFIG_KEY_1 = "credential.helper";
1311
+ 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';
1312
+ }
1313
+ return env;
1314
+ }
1315
+ function runGitNative(command, args) {
1316
+ if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
1317
+ return { ok: false, error: "rig-git native disabled" };
1318
+ }
1319
+ const trackerCommand = command === "fetch-ref" || command === "read-blob-at-ref" || command === "write-tree-commit" || command === "push-ref-with-lease";
1320
+ let binaryPath = null;
1321
+ if (trackerCommand) {
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
+ } else {
1332
+ const explicitBinaryPath = process.env.RIG_NATIVE_GIT_BIN?.trim() || "";
1333
+ binaryPath = explicitBinaryPath && existsSync2(explicitBinaryPath) ? explicitBinaryPath : !explicitBinaryPath ? resolveGitBinaryPath() : null;
1334
+ if (!binaryPath) {
1335
+ try {
1336
+ binaryPath = ensureRigGitBinaryPathSync(preferredGitBinaryOutputPath());
1337
+ } catch (error) {
1338
+ const message = error instanceof Error ? error.message : String(error);
1339
+ if (message.includes("rig-git.zig source file not found")) {
1340
+ return { ok: false, error: "rig-git binary not found" };
1341
+ }
1342
+ return { ok: false, error: message };
1343
+ }
1344
+ }
1345
+ }
1346
+ try {
1347
+ const proc = Bun.spawnSync([binaryPath, command, ...args], {
1348
+ stdout: "pipe",
1349
+ stderr: "pipe",
1350
+ env: gitNativeEnv()
1351
+ });
1352
+ if (proc.exitCode !== 0) {
1353
+ const stdoutText = proc.stdout.toString().trim();
1354
+ if (stdoutText) {
1355
+ try {
1356
+ const parsed = JSON.parse(stdoutText);
1357
+ if (!parsed.ok) {
1358
+ return parsed;
1359
+ }
1360
+ } catch {}
1361
+ }
1362
+ const errText = proc.stderr.toString().trim() || `exit code ${proc.exitCode}`;
1363
+ return { ok: false, error: errText };
1364
+ }
1365
+ const output = proc.stdout.toString().trim();
1366
+ return JSON.parse(output);
1367
+ } catch (err) {
1368
+ return { ok: false, error: String(err) };
1369
+ }
1370
+ }
1371
+ function requireGitNative(command, args) {
1372
+ const result = runGitNative(command, args);
1373
+ if (result.ok === false) {
1374
+ throw new Error(`rig-git ${command} failed: ${result.error}`);
1375
+ }
1376
+ return result;
1377
+ }
1378
+ function requireGitNativeString(command, args) {
1379
+ const result = requireGitNative(command, args);
1380
+ if ("value" in result && typeof result.value === "string") {
1381
+ return result.value;
1382
+ }
1383
+ throw new Error(`rig-git ${command} returned an unexpected result payload`);
1384
+ }
1385
+ function nativeFetchRef(repoPath, remote, branch) {
1386
+ return requireGitNativeString("fetch-ref", [repoPath, remote, branch]);
1387
+ }
1388
+ function nativeReadBlobBytesAtRef(repoPath, ref, path) {
1389
+ const requestDir = resolve2(sharedGitNativeOutputDir, "reads", `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`);
1390
+ mkdirSync3(requestDir, { recursive: true });
1391
+ const outputPath = resolve2(requestDir, "blob.bin");
1392
+ try {
1393
+ requireGitNative("read-blob-at-ref", [repoPath, ref, path, outputPath]);
1394
+ return readFileSync2(outputPath);
1395
+ } finally {
1396
+ rmSync(requestDir, { recursive: true, force: true });
1397
+ }
1398
+ }
1399
+ function serializeTreeCommitUpdates(updates) {
1400
+ return updates.map((update) => {
1401
+ if (isTextTreeCommitUpdate(update)) {
1402
+ return { path: update.path, kind: "text", content: update.content };
1403
+ }
1404
+ if (!isAbsolute(update.sourceFilePath)) {
1405
+ throw new Error("tree commit binary updates require an absolute sourceFilePath");
1406
+ }
1407
+ return { path: update.path, kind: "file", sourceFilePath: update.sourceFilePath };
1408
+ });
1409
+ }
1410
+ function buildTreeCommitUpdatesJson(updates) {
1411
+ return `${JSON.stringify(serializeTreeCommitUpdates(updates), null, 2)}
1412
+ `;
1413
+ }
1414
+ function nativeWriteTreeCommit(repoPath, baseRef, updates, message) {
1415
+ const requestDir = resolve2(sharedGitNativeOutputDir, "requests", `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`);
1416
+ mkdirSync3(requestDir, { recursive: true });
1417
+ const messagePath = resolve2(requestDir, "message.txt");
1418
+ const updatesPath = resolve2(requestDir, "updates.json");
1419
+ try {
1420
+ writeFileSync2(messagePath, message, "utf8");
1421
+ writeFileSync2(updatesPath, buildTreeCommitUpdatesJson(updates), "utf8");
1422
+ return requireGitNativeString("write-tree-commit", [repoPath, baseRef, messagePath, updatesPath]);
1423
+ } finally {
1424
+ rmSync(requestDir, { recursive: true, force: true });
1425
+ }
1426
+ }
1427
+ function nativePushRefWithLease(repoPath, localOid, remoteRef, expectedOldOid, remote = "origin") {
1428
+ return requireGitNativeString("push-ref-with-lease", [
1429
+ repoPath,
1430
+ localOid,
1431
+ remoteRef,
1432
+ expectedOldOid,
1433
+ remote
1434
+ ]);
1435
+ }
1436
+ var sharedGitNativeOutputDir, sharedGitNativeOutputPath, trackerCommandUsageProbe = "usage: rig-git fetch-ref <repo-path> <remote> <branch>";
1437
+ var init_native_git = __esm(() => {
1438
+ init_native_extract();
1439
+ sharedGitNativeOutputDir = resolve2(tmpdir2(), "rig-native");
1440
+ sharedGitNativeOutputPath = resolve2(sharedGitNativeOutputDir, `rig-git-${process.platform}-${process.arch}${process.platform === "win32" ? ".exe" : ""}`);
1441
+ });
1442
+
1443
+ // packages/memory-plugin/src/read.ts
1444
+ import { mkdtempSync, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
1445
+ import { tmpdir as tmpdir3 } from "os";
1044
1446
  import { join } from "path";
1045
- import { nativeFetchRef, nativeReadBlobBytesAtRef } from "@rig/runtime/control-plane/native/git-native";
1046
- import { resolveMonorepoRoot } from "@rig/runtime/control-plane/native/utils";
1447
+ import { resolveCheckoutRoot as resolveMonorepoRoot } from "@rig/core/checkout-root";
1047
1448
  function isMissingCanonicalMemoryBlobError(error) {
1048
1449
  const message = error instanceof Error ? error.message : String(error);
1049
1450
  return message.includes(`path '${CANONICAL_MEMORY_DB_PATH}' does not exist in`) || message.includes(`path '${CANONICAL_MEMORY_DB_PATH}' exists on disk, but not in`) || message.includes(`pathspec '${CANONICAL_MEMORY_DB_PATH}' did not match any file(s) known to git`);
@@ -1080,7 +1481,7 @@ async function readCanonicalMemoryDb(projectRoot, deps = {}) {
1080
1481
  } else {
1081
1482
  try {
1082
1483
  const bytes = readDeps.readBlobBytesAtRef(repoPath, baseOid, CANONICAL_MEMORY_DB_PATH);
1083
- writeFileSync(dbPath, bytes);
1484
+ writeFileSync3(dbPath, bytes);
1084
1485
  } catch (error) {
1085
1486
  if (!isMissingCanonicalMemoryBlobError(error)) {
1086
1487
  throw error;
@@ -1107,18 +1508,18 @@ async function readCanonicalMemoryDb(projectRoot, deps = {}) {
1107
1508
  }
1108
1509
  var CANONICAL_MEMORY_DB_PATH = "rig/memory/project-memory.db", DEFAULT_READ_DEPS;
1109
1510
  var init_read = __esm(() => {
1511
+ init_native_git();
1110
1512
  init_db();
1111
1513
  DEFAULT_READ_DEPS = {
1112
1514
  fetchRef: nativeFetchRef,
1113
1515
  readBlobBytesAtRef: nativeReadBlobBytesAtRef,
1114
1516
  openMemoryDb,
1115
- makeTempDir: () => mkdtempSync(join(tmpdir(), "memory-sync-read-")),
1116
- removeDir: (path) => rmSync(path, { recursive: true, force: true })
1517
+ makeTempDir: () => mkdtempSync(join(tmpdir3(), "memory-sync-read-")),
1518
+ removeDir: (path) => rmSync2(path, { recursive: true, force: true })
1117
1519
  };
1118
1520
  });
1119
1521
 
1120
1522
  // packages/memory-plugin/src/write.ts
1121
- import { nativePushRefWithLease, nativeWriteTreeCommit } from "@rig/runtime/control-plane/native/git-native";
1122
1523
  async function promoteCanonicalMemoryEvent(projectRoot, input, deps = {}) {
1123
1524
  const writeDeps = { ...DEFAULT_WRITE_DEPS, ...deps };
1124
1525
  let lastError;
@@ -1167,6 +1568,7 @@ async function promoteCanonicalMemoryEvent(projectRoot, input, deps = {}) {
1167
1568
  }
1168
1569
  var CANONICAL_MEMORY_DB_PATH2 = "rig/memory/project-memory.db", MAX_PROMOTION_ATTEMPTS = 2, DEFAULT_WRITE_DEPS;
1169
1570
  var init_write = __esm(() => {
1571
+ init_native_git();
1170
1572
  init_db();
1171
1573
  init_embed();
1172
1574
  init_read();
@@ -1182,9 +1584,11 @@ var init_write = __esm(() => {
1182
1584
  });
1183
1585
 
1184
1586
  // packages/memory-plugin/src/cli.ts
1185
- import { existsSync } from "fs";
1587
+ import { existsSync as existsSync3 } from "fs";
1186
1588
  import { randomUUID } from "crypto";
1187
- import { NO_MATCH_RETRIEVAL_CANONICAL_KEY as NO_MATCH_RETRIEVAL_CANONICAL_KEY2 } from "@rig/contracts";
1589
+ import {
1590
+ NO_MATCH_RETRIEVAL_CANONICAL_KEY as NO_MATCH_RETRIEVAL_CANONICAL_KEY2
1591
+ } from "@rig/contracts";
1188
1592
  function takeOption(args, option) {
1189
1593
  const rest = [];
1190
1594
  let value;
@@ -1206,7 +1610,7 @@ function takeOption(args, option) {
1206
1610
  rest.push(current);
1207
1611
  }
1208
1612
  }
1209
- return { value, rest };
1613
+ return { ...value !== undefined ? { value } : {}, rest };
1210
1614
  }
1211
1615
  function usage(verb) {
1212
1616
  switch (verb) {
@@ -1258,7 +1662,7 @@ function requireRuntimeMemoryContext(runtimeContext) {
1258
1662
  }
1259
1663
  async function ensureRuntimeMemoryUsable(runtimeContext) {
1260
1664
  const memory = requireRuntimeMemoryContext(runtimeContext);
1261
- if (!existsSync(memory.hydratedPath)) {
1665
+ if (!existsSync3(memory.hydratedPath)) {
1262
1666
  throw new Error(`Shared memory database is missing: ${memory.hydratedPath}`);
1263
1667
  }
1264
1668
  const db = await openMemoryDb(memory.hydratedPath);
@@ -1334,7 +1738,7 @@ function requestedPayload(verb, mutationKind, canonicalKey, extra) {
1334
1738
  return {
1335
1739
  command: verb,
1336
1740
  mutationKind,
1337
- canonicalKey,
1741
+ ...canonicalKey !== undefined ? { canonicalKey } : {},
1338
1742
  ...extra
1339
1743
  };
1340
1744
  }
@@ -1551,19 +1955,19 @@ var init_service = __esm(() => {
1551
1955
 
1552
1956
  // packages/memory-plugin/src/plugin.ts
1553
1957
  import { definePlugin } from "@rig/core/config";
1554
- import { MEMORY_SERVICE_CAPABILITY_ID } from "@rig/contracts";
1958
+ import { defineCapability } from "@rig/core/capability";
1959
+ import { MEMORY } from "@rig/contracts";
1555
1960
  var MEMORY_PLUGIN_NAME = "@rig/memory-plugin";
1961
+ var MemoryCap = defineCapability(MEMORY);
1556
1962
  var memoryPlugin = definePlugin({
1557
1963
  name: MEMORY_PLUGIN_NAME,
1558
1964
  version: "0.0.0-alpha.1",
1559
1965
  contributes: {
1560
1966
  capabilities: [
1561
- {
1562
- id: MEMORY_SERVICE_CAPABILITY_ID,
1967
+ MemoryCap.provide(async () => (await Promise.resolve().then(() => (init_service(), exports_service))).svc, {
1563
1968
  title: "Shared project memory",
1564
- description: "Observe/recall/supersede shared project memory and hydrate runtime memory snapshots.",
1565
- run: async () => (await Promise.resolve().then(() => (init_service(), exports_service))).svc
1566
- }
1969
+ description: "Observe/recall/supersede shared project memory and hydrate runtime memory snapshots."
1970
+ })
1567
1971
  ]
1568
1972
  }
1569
1973
  });
@@ -1,5 +1,5 @@
1
1
  import type { MemoryDb, MemoryEmbedder, MemoryQueryResult } from "@rig/contracts";
2
- import { type RuntimeMemoryRetrievalConfig } from "@rig/runtime/control-plane/runtime/context";
2
+ import { type RuntimeMemoryRetrievalConfig } from "@rig/core/runtime-context";
3
3
  export type { MemoryQueryResult };
4
4
  export type MemoryQueryInput = {
5
5
  query: string;
package/dist/src/query.js CHANGED
@@ -180,14 +180,14 @@ function createConfiguredMemoryEmbedder(options = {}) {
180
180
  apiKey,
181
181
  model: env.RIG_MEMORY_EMBEDDING_MODEL?.trim() || DEFAULT_EMBEDDING_MODEL,
182
182
  apiBaseUrl: options.apiBaseUrl ?? env.RIG_MEMORY_EMBEDDING_API_BASE_URL?.trim() ?? DEFAULT_EMBEDDING_API_BASE_URL,
183
- fetchImpl: options.fetchImpl
183
+ ...options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}
184
184
  });
185
185
  }
186
186
 
187
187
  // packages/memory-plugin/src/query.ts
188
188
  import {
189
189
  DEFAULT_RUNTIME_MEMORY_RETRIEVAL
190
- } from "@rig/runtime/control-plane/runtime/context";
190
+ } from "@rig/core/runtime-context";
191
191
  var DEFAULT_RESULT_LIMIT = DEFAULT_RUNTIME_MEMORY_RETRIEVAL.topK;
192
192
  var DAY_MS = 24 * 60 * 60 * 1000;
193
193
  var MIN_VECTOR_MATCH_SCORE = 0.2;
@@ -1,4 +1,4 @@
1
- import { nativeFetchRef, nativeReadBlobBytesAtRef } from "@rig/runtime/control-plane/native/git-native";
1
+ import { nativeFetchRef, nativeReadBlobBytesAtRef } from "./native-git";
2
2
  import { openMemoryDb } from "./db";
3
3
  import type { CanonicalMemorySnapshot } from "@rig/contracts";
4
4
  export type { CanonicalMemorySnapshot };