@massa-ai/mcp-client 1.36.0 → 1.38.0
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/config-cli.js +688 -562
- package/dist/index.js +335 -274
- package/package.json +3 -3
package/dist/config-cli.js
CHANGED
|
@@ -1162,7 +1162,8 @@ var init_config = __esm(() => {
|
|
|
1162
1162
|
},
|
|
1163
1163
|
logging: {
|
|
1164
1164
|
level: process.env.LOG_LEVEL || fileConfig.logging?.level || "info",
|
|
1165
|
-
enableMetrics: process.env.ENABLE_METRICS === "true" || process.env.ENABLE_METRICS === undefined && !!fileConfig.logging?.enableMetrics
|
|
1165
|
+
enableMetrics: process.env.ENABLE_METRICS === "true" || process.env.ENABLE_METRICS === undefined && !!fileConfig.logging?.enableMetrics,
|
|
1166
|
+
file: process.env.MASSA_AI_LOG_FILE || fileConfig.logging?.file || undefined
|
|
1166
1167
|
},
|
|
1167
1168
|
synapse: {
|
|
1168
1169
|
enabled: process.env.SYNAPSE_ENABLED !== "false",
|
|
@@ -1316,20 +1317,25 @@ var init_types = __esm(() => {
|
|
|
1316
1317
|
var init_interfaces = () => {};
|
|
1317
1318
|
|
|
1318
1319
|
// ../../packages/shared/dist/utils/logger.js
|
|
1320
|
+
import fs2 from "fs";
|
|
1321
|
+
|
|
1319
1322
|
class Logger {
|
|
1320
1323
|
_level;
|
|
1321
1324
|
_enableMetrics;
|
|
1325
|
+
_logFilePath;
|
|
1322
1326
|
_initialized = false;
|
|
1323
1327
|
constructor() {}
|
|
1324
1328
|
ensureInitialized() {
|
|
1325
1329
|
if (!this._initialized) {
|
|
1326
1330
|
try {
|
|
1327
|
-
const
|
|
1328
|
-
this._level = this.parseLogLevel(
|
|
1329
|
-
this._enableMetrics =
|
|
1331
|
+
const loggingConfig = config.get("logging");
|
|
1332
|
+
this._level = this.parseLogLevel(loggingConfig.level);
|
|
1333
|
+
this._enableMetrics = loggingConfig.enableMetrics;
|
|
1334
|
+
this._logFilePath = loggingConfig.file;
|
|
1330
1335
|
} catch {
|
|
1331
1336
|
this._level = LogLevel.INFO;
|
|
1332
1337
|
this._enableMetrics = false;
|
|
1338
|
+
this._logFilePath = undefined;
|
|
1333
1339
|
}
|
|
1334
1340
|
this._initialized = true;
|
|
1335
1341
|
}
|
|
@@ -1342,6 +1348,10 @@ class Logger {
|
|
|
1342
1348
|
this.ensureInitialized();
|
|
1343
1349
|
return this._enableMetrics;
|
|
1344
1350
|
}
|
|
1351
|
+
get logFilePath() {
|
|
1352
|
+
this.ensureInitialized();
|
|
1353
|
+
return this._logFilePath;
|
|
1354
|
+
}
|
|
1345
1355
|
parseLogLevel(level) {
|
|
1346
1356
|
const levels = {
|
|
1347
1357
|
debug: LogLevel.DEBUG,
|
|
@@ -1361,6 +1371,13 @@ class Logger {
|
|
|
1361
1371
|
}
|
|
1362
1372
|
write(message, _level) {
|
|
1363
1373
|
console.error(message);
|
|
1374
|
+
const filePath = this.logFilePath;
|
|
1375
|
+
if (filePath) {
|
|
1376
|
+
try {
|
|
1377
|
+
fs2.appendFileSync(filePath, message + `
|
|
1378
|
+
`);
|
|
1379
|
+
} catch {}
|
|
1380
|
+
}
|
|
1364
1381
|
}
|
|
1365
1382
|
debug(message, meta) {
|
|
1366
1383
|
if (this.shouldLog(LogLevel.DEBUG)) {
|
|
@@ -1770,7 +1787,7 @@ var init_hosts = __esm(() => {
|
|
|
1770
1787
|
});
|
|
1771
1788
|
|
|
1772
1789
|
// ../../packages/shared/dist/profile-switch/state.js
|
|
1773
|
-
import
|
|
1790
|
+
import fs3 from "fs";
|
|
1774
1791
|
import path6 from "path";
|
|
1775
1792
|
function namedError(name, message) {
|
|
1776
1793
|
const err = new InstallStateError(message);
|
|
@@ -1797,7 +1814,7 @@ function validateShape(raw2, filePath) {
|
|
|
1797
1814
|
function readInstallState(filePath) {
|
|
1798
1815
|
let text;
|
|
1799
1816
|
try {
|
|
1800
|
-
text =
|
|
1817
|
+
text = fs3.readFileSync(filePath, "utf-8");
|
|
1801
1818
|
} catch (err) {
|
|
1802
1819
|
const code = err.code;
|
|
1803
1820
|
if (code === "ENOENT")
|
|
@@ -1817,8 +1834,8 @@ function writeInstallState(filePath, state) {
|
|
|
1817
1834
|
const text = `${JSON.stringify(validated, null, 2)}
|
|
1818
1835
|
`;
|
|
1819
1836
|
try {
|
|
1820
|
-
|
|
1821
|
-
|
|
1837
|
+
fs3.mkdirSync(path6.dirname(filePath), { recursive: true });
|
|
1838
|
+
fs3.writeFileSync(filePath, text);
|
|
1822
1839
|
} catch (err) {
|
|
1823
1840
|
throw UnwritableInstallStateError(filePath, err.message);
|
|
1824
1841
|
}
|
|
@@ -1845,7 +1862,7 @@ var init_state = __esm(() => {
|
|
|
1845
1862
|
});
|
|
1846
1863
|
|
|
1847
1864
|
// ../../packages/shared/dist/profile-switch/lock.js
|
|
1848
|
-
import
|
|
1865
|
+
import fs4 from "fs";
|
|
1849
1866
|
import path7 from "path";
|
|
1850
1867
|
import os4 from "os";
|
|
1851
1868
|
import crypto3 from "crypto";
|
|
@@ -1858,7 +1875,7 @@ function namedError2(name, message) {
|
|
|
1858
1875
|
function readOwner(ownerPath) {
|
|
1859
1876
|
let raw2;
|
|
1860
1877
|
try {
|
|
1861
|
-
raw2 = JSON.parse(
|
|
1878
|
+
raw2 = JSON.parse(fs4.readFileSync(ownerPath, "utf-8"));
|
|
1862
1879
|
} catch {
|
|
1863
1880
|
return null;
|
|
1864
1881
|
}
|
|
@@ -1874,7 +1891,7 @@ function releaseIfOwned(lockDir, ownerPath, token) {
|
|
|
1874
1891
|
const owner = readOwner(ownerPath);
|
|
1875
1892
|
if (owner === null || owner.token !== token)
|
|
1876
1893
|
return;
|
|
1877
|
-
|
|
1894
|
+
fs4.rmSync(lockDir, { recursive: true, force: true });
|
|
1878
1895
|
}
|
|
1879
1896
|
function acquireLock(stateFilePath, options = {}) {
|
|
1880
1897
|
const lockDir = `${stateFilePath}.switch.lock`;
|
|
@@ -1883,11 +1900,11 @@ function acquireLock(stateFilePath, options = {}) {
|
|
|
1883
1900
|
const identity = options.identity ?? DEFAULT_IDENTITY;
|
|
1884
1901
|
const staleAfterMs = options.staleAfterMs ?? DEFAULT_STALE_AFTER_MS;
|
|
1885
1902
|
const createFresh = () => {
|
|
1886
|
-
|
|
1903
|
+
fs4.mkdirSync(lockDir);
|
|
1887
1904
|
const pid = identity.pid();
|
|
1888
1905
|
const startedAt = identity.processStart(pid);
|
|
1889
1906
|
if (startedAt == null) {
|
|
1890
|
-
|
|
1907
|
+
fs4.rmSync(lockDir, { recursive: true, force: true });
|
|
1891
1908
|
throw LockAcquireError(lockDir, "could not determine this process's start-time identity");
|
|
1892
1909
|
}
|
|
1893
1910
|
const token = crypto3.randomUUID();
|
|
@@ -1898,8 +1915,8 @@ function acquireLock(stateFilePath, options = {}) {
|
|
|
1898
1915
|
token,
|
|
1899
1916
|
timestamp: clock.now()
|
|
1900
1917
|
};
|
|
1901
|
-
|
|
1902
|
-
|
|
1918
|
+
fs4.mkdirSync(path7.dirname(ownerPath), { recursive: true });
|
|
1919
|
+
fs4.writeFileSync(ownerPath, JSON.stringify(record));
|
|
1903
1920
|
return { lockDir, release: () => releaseIfOwned(lockDir, ownerPath, token) };
|
|
1904
1921
|
};
|
|
1905
1922
|
try {
|
|
@@ -1914,11 +1931,11 @@ function acquireLock(stateFilePath, options = {}) {
|
|
|
1914
1931
|
throw LockHeldError(lockDir);
|
|
1915
1932
|
const reclaimDir = `${lockDir}.reclaim.${owner.token}`;
|
|
1916
1933
|
try {
|
|
1917
|
-
|
|
1934
|
+
fs4.renameSync(lockDir, reclaimDir);
|
|
1918
1935
|
} catch {
|
|
1919
1936
|
throw LockHeldError(lockDir);
|
|
1920
1937
|
}
|
|
1921
|
-
|
|
1938
|
+
fs4.rmSync(reclaimDir, { recursive: true, force: true });
|
|
1922
1939
|
try {
|
|
1923
1940
|
return createFresh();
|
|
1924
1941
|
} catch {
|
|
@@ -1952,7 +1969,7 @@ var init_lock = __esm(() => {
|
|
|
1952
1969
|
});
|
|
1953
1970
|
|
|
1954
1971
|
// ../../packages/shared/dist/profile-switch/engine.js
|
|
1955
|
-
import
|
|
1972
|
+
import fs5 from "fs";
|
|
1956
1973
|
import path8 from "path";
|
|
1957
1974
|
import os5 from "os";
|
|
1958
1975
|
import crypto4 from "crypto";
|
|
@@ -1986,7 +2003,7 @@ function listProfiles(opts = {}) {
|
|
|
1986
2003
|
availableProfiles: []
|
|
1987
2004
|
};
|
|
1988
2005
|
}
|
|
1989
|
-
const installed =
|
|
2006
|
+
const installed = fs5.existsSync(layout.activeDir);
|
|
1990
2007
|
const availableProfiles = listVariantProfiles(layout);
|
|
1991
2008
|
const platform = state.platforms[host];
|
|
1992
2009
|
return {
|
|
@@ -2002,9 +2019,9 @@ function listProfiles(opts = {}) {
|
|
|
2002
2019
|
return { hosts };
|
|
2003
2020
|
}
|
|
2004
2021
|
function listVariantProfiles(layout) {
|
|
2005
|
-
if (!
|
|
2022
|
+
if (!fs5.existsSync(layout.variantsRoot))
|
|
2006
2023
|
return [];
|
|
2007
|
-
return
|
|
2024
|
+
return fs5.readdirSync(layout.variantsRoot, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort();
|
|
2008
2025
|
}
|
|
2009
2026
|
function matchesGlob(filename, glob) {
|
|
2010
2027
|
const starIdx = glob.indexOf("*");
|
|
@@ -2017,32 +2034,32 @@ function matchesGlob(filename, glob) {
|
|
|
2017
2034
|
function assertStateWritable(stateFilePath) {
|
|
2018
2035
|
const dir = path8.dirname(stateFilePath);
|
|
2019
2036
|
try {
|
|
2020
|
-
|
|
2037
|
+
fs5.mkdirSync(dir, { recursive: true });
|
|
2021
2038
|
} catch (err) {
|
|
2022
2039
|
throw UnwritableInstallStateError(stateFilePath, err.message);
|
|
2023
2040
|
}
|
|
2024
|
-
const checkPath =
|
|
2041
|
+
const checkPath = fs5.existsSync(stateFilePath) ? stateFilePath : dir;
|
|
2025
2042
|
try {
|
|
2026
|
-
|
|
2043
|
+
fs5.accessSync(checkPath, fs5.constants.W_OK);
|
|
2027
2044
|
} catch (err) {
|
|
2028
2045
|
throw UnwritableInstallStateError(stateFilePath, err.message);
|
|
2029
2046
|
}
|
|
2030
2047
|
}
|
|
2031
2048
|
function copyFileRouteVariant(layout, variantDir) {
|
|
2032
|
-
|
|
2049
|
+
fs5.mkdirSync(layout.activeDir, { recursive: true });
|
|
2033
2050
|
let changed = 0;
|
|
2034
|
-
for (const entry of
|
|
2051
|
+
for (const entry of fs5.readdirSync(variantDir, { withFileTypes: true })) {
|
|
2035
2052
|
if (!entry.isFile() || !matchesGlob(entry.name, layout.activeGlob))
|
|
2036
2053
|
continue;
|
|
2037
|
-
|
|
2054
|
+
fs5.copyFileSync(path8.join(variantDir, entry.name), path8.join(layout.activeDir, entry.name));
|
|
2038
2055
|
changed++;
|
|
2039
2056
|
}
|
|
2040
2057
|
return changed;
|
|
2041
2058
|
}
|
|
2042
2059
|
function repointOpencodeVariant(layout, variantDir) {
|
|
2043
|
-
|
|
2060
|
+
fs5.mkdirSync(layout.activeDir, { recursive: true });
|
|
2044
2061
|
let changed = 0;
|
|
2045
|
-
for (const entry of
|
|
2062
|
+
for (const entry of fs5.readdirSync(variantDir, { withFileTypes: true })) {
|
|
2046
2063
|
if (!entry.isFile() || !matchesGlob(entry.name, layout.activeGlob))
|
|
2047
2064
|
continue;
|
|
2048
2065
|
const dest = path8.join(layout.activeDir, entry.name);
|
|
@@ -2050,15 +2067,15 @@ function repointOpencodeVariant(layout, variantDir) {
|
|
|
2050
2067
|
let destExists = true;
|
|
2051
2068
|
let destIsSymlink = false;
|
|
2052
2069
|
try {
|
|
2053
|
-
destIsSymlink =
|
|
2070
|
+
destIsSymlink = fs5.lstatSync(dest).isSymbolicLink();
|
|
2054
2071
|
} catch {
|
|
2055
2072
|
destExists = false;
|
|
2056
2073
|
}
|
|
2057
2074
|
if (destExists && !destIsSymlink)
|
|
2058
2075
|
continue;
|
|
2059
2076
|
const tmp = `${dest}.massa-ai-switch.${crypto4.randomUUID()}`;
|
|
2060
|
-
|
|
2061
|
-
|
|
2077
|
+
fs5.symlinkSync(target, tmp);
|
|
2078
|
+
fs5.renameSync(tmp, dest);
|
|
2062
2079
|
changed++;
|
|
2063
2080
|
}
|
|
2064
2081
|
return changed;
|
|
@@ -2080,13 +2097,13 @@ function switchProfile(opts) {
|
|
|
2080
2097
|
if (fileHosts.length === 0) {
|
|
2081
2098
|
return { profile: opts.profile, dryRun, hosts: orderRows(universe, skipRows), restartRequired: false };
|
|
2082
2099
|
}
|
|
2083
|
-
const installedFileHosts = fileHosts.filter((h) =>
|
|
2100
|
+
const installedFileHosts = fileHosts.filter((h) => fs5.existsSync(h.layout.activeDir));
|
|
2084
2101
|
if (installedFileHosts.length === 0)
|
|
2085
2102
|
throw NoHostsDetectedError();
|
|
2086
2103
|
const withAvailability = fileHosts.map((h) => {
|
|
2087
|
-
const variantsRootExists =
|
|
2104
|
+
const variantsRootExists = fs5.existsSync(h.layout.variantsRoot);
|
|
2088
2105
|
const variantDir = h.layout.variantDir(opts.profile);
|
|
2089
|
-
const available = variantsRootExists &&
|
|
2106
|
+
const available = variantsRootExists && fs5.existsSync(variantDir) && fs5.statSync(variantDir).isDirectory();
|
|
2090
2107
|
return { ...h, variantsRootExists, variantDir, available };
|
|
2091
2108
|
});
|
|
2092
2109
|
if (!withAvailability.some((h) => h.available)) {
|
|
@@ -6300,8 +6317,8 @@ var init_esm4 = __esm(() => {
|
|
|
6300
6317
|
#children;
|
|
6301
6318
|
nocase;
|
|
6302
6319
|
#fs;
|
|
6303
|
-
constructor(cwd = process.cwd(), pathImpl, sep2, { nocase, childrenCacheSize = 16 * 1024, fs:
|
|
6304
|
-
this.#fs = fsFromOption(
|
|
6320
|
+
constructor(cwd = process.cwd(), pathImpl, sep2, { nocase, childrenCacheSize = 16 * 1024, fs: fs6 = defaultFS } = {}) {
|
|
6321
|
+
this.#fs = fsFromOption(fs6);
|
|
6305
6322
|
if (cwd instanceof URL || cwd.startsWith("file://")) {
|
|
6306
6323
|
cwd = fileURLToPath(cwd);
|
|
6307
6324
|
}
|
|
@@ -6776,8 +6793,8 @@ var init_esm4 = __esm(() => {
|
|
|
6776
6793
|
parseRootPath(dir) {
|
|
6777
6794
|
return win32.parse(dir).root.toUpperCase();
|
|
6778
6795
|
}
|
|
6779
|
-
newRoot(
|
|
6780
|
-
return new PathWin32(this.rootPath, IFDIR, undefined, this.roots, this.nocase, this.childrenCache(), { fs:
|
|
6796
|
+
newRoot(fs6) {
|
|
6797
|
+
return new PathWin32(this.rootPath, IFDIR, undefined, this.roots, this.nocase, this.childrenCache(), { fs: fs6 });
|
|
6781
6798
|
}
|
|
6782
6799
|
isAbsolute(p) {
|
|
6783
6800
|
return p.startsWith("/") || p.startsWith("\\") || /^[a-z]:(\/|\\)/i.test(p);
|
|
@@ -6793,8 +6810,8 @@ var init_esm4 = __esm(() => {
|
|
|
6793
6810
|
parseRootPath(_dir) {
|
|
6794
6811
|
return "/";
|
|
6795
6812
|
}
|
|
6796
|
-
newRoot(
|
|
6797
|
-
return new PathPosix(this.rootPath, IFDIR, undefined, this.roots, this.nocase, this.childrenCache(), { fs:
|
|
6813
|
+
newRoot(fs6) {
|
|
6814
|
+
return new PathPosix(this.rootPath, IFDIR, undefined, this.roots, this.nocase, this.childrenCache(), { fs: fs6 });
|
|
6798
6815
|
}
|
|
6799
6816
|
isAbsolute(p) {
|
|
6800
6817
|
return p.startsWith("/");
|
|
@@ -8200,7 +8217,7 @@ var init_capture_policy = __esm(() => {
|
|
|
8200
8217
|
});
|
|
8201
8218
|
|
|
8202
8219
|
// ../../packages/core/dist/services/search/ignore-patterns.js
|
|
8203
|
-
import
|
|
8220
|
+
import fs6 from "fs/promises";
|
|
8204
8221
|
import path10 from "path";
|
|
8205
8222
|
function buildExtensionGlob(extensions) {
|
|
8206
8223
|
return extensions.map((ext2) => `**/*${ext2}`);
|
|
@@ -8225,7 +8242,7 @@ async function loadProjectIgnore(projectPath) {
|
|
|
8225
8242
|
ig.add(DEFAULT_IGNORES);
|
|
8226
8243
|
try {
|
|
8227
8244
|
const gitignorePath = path10.join(projectPath, ".gitignore");
|
|
8228
|
-
const gitignoreContent = await
|
|
8245
|
+
const gitignoreContent = await fs6.readFile(gitignorePath, "utf8");
|
|
8229
8246
|
const rules = gitignoreContent.split(`
|
|
8230
8247
|
`).map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
|
|
8231
8248
|
ig.add(rules);
|
|
@@ -9821,15 +9838,15 @@ var require_pg_connection_string = __commonJS((exports, module) => {
|
|
|
9821
9838
|
if (config2.sslnegotiation === "direct" && config2.ssl === undefined) {
|
|
9822
9839
|
config2.ssl = true;
|
|
9823
9840
|
}
|
|
9824
|
-
const
|
|
9841
|
+
const fs7 = config2.sslcert || config2.sslkey || config2.sslrootcert ? __require("fs") : null;
|
|
9825
9842
|
if (config2.sslcert) {
|
|
9826
|
-
config2.ssl.cert =
|
|
9843
|
+
config2.ssl.cert = fs7.readFileSync(config2.sslcert).toString();
|
|
9827
9844
|
}
|
|
9828
9845
|
if (config2.sslkey) {
|
|
9829
|
-
config2.ssl.key =
|
|
9846
|
+
config2.ssl.key = fs7.readFileSync(config2.sslkey).toString();
|
|
9830
9847
|
}
|
|
9831
9848
|
if (config2.sslrootcert) {
|
|
9832
|
-
config2.ssl.ca =
|
|
9849
|
+
config2.ssl.ca = fs7.readFileSync(config2.sslrootcert).toString();
|
|
9833
9850
|
}
|
|
9834
9851
|
if (options.useLibpqCompat && config2.uselibpqcompat) {
|
|
9835
9852
|
throw new Error("Both useLibpqCompat and uselibpqcompat are set. Please use only one of them.");
|
|
@@ -11708,15 +11725,15 @@ var require_helper = __commonJS((exports, module) => {
|
|
|
11708
11725
|
// ../../node_modules/pgpass/lib/index.js
|
|
11709
11726
|
var require_lib = __commonJS((exports, module) => {
|
|
11710
11727
|
var path11 = __require("path");
|
|
11711
|
-
var
|
|
11728
|
+
var fs7 = __require("fs");
|
|
11712
11729
|
var helper = require_helper();
|
|
11713
11730
|
module.exports = function(connInfo, cb) {
|
|
11714
11731
|
var file = helper.getFileName();
|
|
11715
|
-
|
|
11732
|
+
fs7.stat(file, function(err, stat) {
|
|
11716
11733
|
if (err || !helper.usePgPass(stat, file)) {
|
|
11717
11734
|
return cb(undefined);
|
|
11718
11735
|
}
|
|
11719
|
-
var st =
|
|
11736
|
+
var st = fs7.createReadStream(file);
|
|
11720
11737
|
helper.getPassword(connInfo, st, cb);
|
|
11721
11738
|
});
|
|
11722
11739
|
};
|
|
@@ -13246,6 +13263,89 @@ var init_db_connection = __esm(() => {
|
|
|
13246
13263
|
init_config();
|
|
13247
13264
|
});
|
|
13248
13265
|
|
|
13266
|
+
// ../../packages/core/dist/kernel/sanitize/credential-scrub.js
|
|
13267
|
+
function markerFor(id) {
|
|
13268
|
+
return `[REDACTED:${id}]`;
|
|
13269
|
+
}
|
|
13270
|
+
function fullMatchRule(id, pattern) {
|
|
13271
|
+
const marker = markerFor(id);
|
|
13272
|
+
return {
|
|
13273
|
+
id,
|
|
13274
|
+
replace(text) {
|
|
13275
|
+
let count = 0;
|
|
13276
|
+
const replaced = text.replace(pattern, () => {
|
|
13277
|
+
count++;
|
|
13278
|
+
return marker;
|
|
13279
|
+
});
|
|
13280
|
+
return { text: replaced, count };
|
|
13281
|
+
}
|
|
13282
|
+
};
|
|
13283
|
+
}
|
|
13284
|
+
function scrubCredentials(payloadJson) {
|
|
13285
|
+
const redactions = {};
|
|
13286
|
+
for (const id of RULE_IDS)
|
|
13287
|
+
redactions[id] = 0;
|
|
13288
|
+
let text = payloadJson;
|
|
13289
|
+
for (const rule of RULES) {
|
|
13290
|
+
const { text: next, count } = rule.replace(text);
|
|
13291
|
+
text = next;
|
|
13292
|
+
redactions[rule.id] += count;
|
|
13293
|
+
}
|
|
13294
|
+
const total = Object.values(redactions).reduce((sum, n) => sum + n, 0);
|
|
13295
|
+
return {
|
|
13296
|
+
sanitized: text,
|
|
13297
|
+
redactions,
|
|
13298
|
+
total
|
|
13299
|
+
};
|
|
13300
|
+
}
|
|
13301
|
+
var PEM_PATTERN, JWT_PATTERN, AWS_KEY_PATTERN, SK_KEY_PATTERN, GITHUB_TOKEN_PATTERN, SLACK_TOKEN_PATTERN, BEARER_PATTERN, RULES, RULE_IDS;
|
|
13302
|
+
var init_credential_scrub = __esm(() => {
|
|
13303
|
+
PEM_PATTERN = /-----BEGIN [A-Z ]{0,32}PRIVATE KEY-----[\s\S]{0,8192}?-----END [A-Z ]{0,32}PRIVATE KEY-----/g;
|
|
13304
|
+
JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g;
|
|
13305
|
+
AWS_KEY_PATTERN = /\b(?:AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}\b/g;
|
|
13306
|
+
SK_KEY_PATTERN = /\bsk-[A-Za-z0-9_-]{20,}\b/g;
|
|
13307
|
+
GITHUB_TOKEN_PATTERN = /\bgh[pousr]_[A-Za-z0-9]{36,}\b|\bgithub_pat_[A-Za-z0-9_]{22,}\b/g;
|
|
13308
|
+
SLACK_TOKEN_PATTERN = /\bxox[baprs]-[A-Za-z0-9-]{18,}\b/g;
|
|
13309
|
+
BEARER_PATTERN = /(Bearer\s+)([A-Za-z0-9._~+/=-]{20,})/g;
|
|
13310
|
+
RULES = [
|
|
13311
|
+
fullMatchRule("pem", PEM_PATTERN),
|
|
13312
|
+
fullMatchRule("jwt", JWT_PATTERN),
|
|
13313
|
+
fullMatchRule("aws-key", AWS_KEY_PATTERN),
|
|
13314
|
+
fullMatchRule("sk-key", SK_KEY_PATTERN),
|
|
13315
|
+
fullMatchRule("github-token", GITHUB_TOKEN_PATTERN),
|
|
13316
|
+
fullMatchRule("slack-token", SLACK_TOKEN_PATTERN),
|
|
13317
|
+
{
|
|
13318
|
+
id: "bearer",
|
|
13319
|
+
replace(text) {
|
|
13320
|
+
let count = 0;
|
|
13321
|
+
const replaced = text.replace(BEARER_PATTERN, (_m, prefix) => {
|
|
13322
|
+
count++;
|
|
13323
|
+
return `${prefix}${markerFor("bearer")}`;
|
|
13324
|
+
});
|
|
13325
|
+
return { text: replaced, count };
|
|
13326
|
+
}
|
|
13327
|
+
}
|
|
13328
|
+
];
|
|
13329
|
+
RULE_IDS = RULES.map((r) => r.id);
|
|
13330
|
+
});
|
|
13331
|
+
|
|
13332
|
+
// ../../packages/core/dist/kernel/sanitize/safe-error-summary.js
|
|
13333
|
+
function safeErrorSummary(error) {
|
|
13334
|
+
if (error instanceof Error) {
|
|
13335
|
+
return {
|
|
13336
|
+
name: error.name,
|
|
13337
|
+
message: scrubCredentials(error.message).sanitized
|
|
13338
|
+
};
|
|
13339
|
+
}
|
|
13340
|
+
return {
|
|
13341
|
+
name: "UnknownError",
|
|
13342
|
+
message: scrubCredentials(String(error)).sanitized
|
|
13343
|
+
};
|
|
13344
|
+
}
|
|
13345
|
+
var init_safe_error_summary = __esm(() => {
|
|
13346
|
+
init_credential_scrub();
|
|
13347
|
+
});
|
|
13348
|
+
|
|
13249
13349
|
// ../../packages/core/dist/kernel/alias-resolver.js
|
|
13250
13350
|
class ProjectIdentityAliasResolver {
|
|
13251
13351
|
ttlMs;
|
|
@@ -13271,9 +13371,7 @@ class ProjectIdentityAliasResolver {
|
|
|
13271
13371
|
this.cache.set(projectId, { canonical, expiresAt: this.now() + this.ttlMs });
|
|
13272
13372
|
return canonical;
|
|
13273
13373
|
} catch (error) {
|
|
13274
|
-
logger.warn("[project-identity] alias resolution failed; using original id (
|
|
13275
|
-
name: error instanceof Error ? error.name : "unknown"
|
|
13276
|
-
});
|
|
13374
|
+
logger.warn("[project-identity] alias resolution failed; using original id", safeErrorSummary(error));
|
|
13277
13375
|
return projectId;
|
|
13278
13376
|
}
|
|
13279
13377
|
}
|
|
@@ -13330,10 +13428,11 @@ var DEFAULT_TTL_MS = 30000, DEFAULT_RESOLVE_TIMEOUT_MS = 250, sharedResolver = n
|
|
|
13330
13428
|
var init_alias_resolver = __esm(() => {
|
|
13331
13429
|
init_dist();
|
|
13332
13430
|
init_db_connection();
|
|
13431
|
+
init_safe_error_summary();
|
|
13333
13432
|
});
|
|
13334
13433
|
|
|
13335
13434
|
// ../../packages/core/dist/services/search/index-manager.js
|
|
13336
|
-
import
|
|
13435
|
+
import fs7 from "fs";
|
|
13337
13436
|
import path11 from "path";
|
|
13338
13437
|
|
|
13339
13438
|
class IndexManager {
|
|
@@ -13429,7 +13528,7 @@ class IndexManager {
|
|
|
13429
13528
|
for (const filePath of indexedFiles) {
|
|
13430
13529
|
const fullPath = path11.join(projectPath, filePath);
|
|
13431
13530
|
try {
|
|
13432
|
-
const stat = await
|
|
13531
|
+
const stat = await fs7.promises.stat(fullPath);
|
|
13433
13532
|
fileMetadata[filePath] = {
|
|
13434
13533
|
path: filePath,
|
|
13435
13534
|
mtime: stat.mtimeMs,
|
|
@@ -13482,7 +13581,7 @@ class IndexManager {
|
|
|
13482
13581
|
}
|
|
13483
13582
|
const fullPath = path11.join(projectPath, match2);
|
|
13484
13583
|
try {
|
|
13485
|
-
const stat = await
|
|
13584
|
+
const stat = await fs7.promises.stat(fullPath);
|
|
13486
13585
|
files.set(match2, {
|
|
13487
13586
|
path: match2,
|
|
13488
13587
|
mtime: stat.mtimeMs,
|
|
@@ -35173,7 +35272,7 @@ var require_auth_config = __commonJS((exports, module) => {
|
|
|
35173
35272
|
writeAuthConfig: () => writeAuthConfig
|
|
35174
35273
|
});
|
|
35175
35274
|
module.exports = __toCommonJS2(auth_config_exports);
|
|
35176
|
-
var
|
|
35275
|
+
var fs8 = __toESM2(__require("fs"));
|
|
35177
35276
|
var path12 = __toESM2(__require("path"));
|
|
35178
35277
|
var import_token_util = require_token_util();
|
|
35179
35278
|
function getAuthConfigPath() {
|
|
@@ -35186,10 +35285,10 @@ var require_auth_config = __commonJS((exports, module) => {
|
|
|
35186
35285
|
function readAuthConfig() {
|
|
35187
35286
|
try {
|
|
35188
35287
|
const authPath = getAuthConfigPath();
|
|
35189
|
-
if (!
|
|
35288
|
+
if (!fs8.existsSync(authPath)) {
|
|
35190
35289
|
return null;
|
|
35191
35290
|
}
|
|
35192
|
-
const content =
|
|
35291
|
+
const content = fs8.readFileSync(authPath, "utf8");
|
|
35193
35292
|
if (!content) {
|
|
35194
35293
|
return null;
|
|
35195
35294
|
}
|
|
@@ -35201,10 +35300,10 @@ var require_auth_config = __commonJS((exports, module) => {
|
|
|
35201
35300
|
function writeAuthConfig(config3) {
|
|
35202
35301
|
const authPath = getAuthConfigPath();
|
|
35203
35302
|
const authDir = path12.dirname(authPath);
|
|
35204
|
-
if (!
|
|
35205
|
-
|
|
35303
|
+
if (!fs8.existsSync(authDir)) {
|
|
35304
|
+
fs8.mkdirSync(authDir, { mode: 504, recursive: true });
|
|
35206
35305
|
}
|
|
35207
|
-
|
|
35306
|
+
fs8.writeFileSync(authPath, JSON.stringify(config3, null, 2), { mode: 384 });
|
|
35208
35307
|
}
|
|
35209
35308
|
function isValidAccessToken(authConfig, expirationBufferMs = 0) {
|
|
35210
35309
|
if (!authConfig.token)
|
|
@@ -35380,7 +35479,7 @@ var require_token_util = __commonJS((exports, module) => {
|
|
|
35380
35479
|
});
|
|
35381
35480
|
module.exports = __toCommonJS2(token_util_exports);
|
|
35382
35481
|
var path12 = __toESM2(__require("path"));
|
|
35383
|
-
var
|
|
35482
|
+
var fs8 = __toESM2(__require("fs"));
|
|
35384
35483
|
var import_token_error = require_token_error();
|
|
35385
35484
|
var import_token_io = require_token_io();
|
|
35386
35485
|
var import_auth_config = require_auth_config();
|
|
@@ -35461,10 +35560,10 @@ var require_token_util = __commonJS((exports, module) => {
|
|
|
35461
35560
|
throw new import_token_error.VercelOidcTokenError("Unable to find project root directory. Have you linked your project with `vc link?`");
|
|
35462
35561
|
}
|
|
35463
35562
|
const prjPath = path12.join(dir, ".vercel", "project.json");
|
|
35464
|
-
if (!
|
|
35563
|
+
if (!fs8.existsSync(prjPath)) {
|
|
35465
35564
|
throw new import_token_error.VercelOidcTokenError("project.json not found, have you linked your project with `vc link?`");
|
|
35466
35565
|
}
|
|
35467
|
-
const prj = JSON.parse(
|
|
35566
|
+
const prj = JSON.parse(fs8.readFileSync(prjPath, "utf8"));
|
|
35468
35567
|
if (typeof prj.projectId !== "string" && typeof prj.orgId !== "string") {
|
|
35469
35568
|
throw new TypeError("Expected a string-valued projectId property. Try running `vc link` to re-link your project.");
|
|
35470
35569
|
}
|
|
@@ -35477,9 +35576,9 @@ var require_token_util = __commonJS((exports, module) => {
|
|
|
35477
35576
|
}
|
|
35478
35577
|
const tokenPath = path12.join(dir, "com.vercel.token", `${projectId}.json`);
|
|
35479
35578
|
const tokenJson = JSON.stringify(token);
|
|
35480
|
-
|
|
35481
|
-
|
|
35482
|
-
|
|
35579
|
+
fs8.mkdirSync(path12.dirname(tokenPath), { mode: 504, recursive: true });
|
|
35580
|
+
fs8.writeFileSync(tokenPath, tokenJson);
|
|
35581
|
+
fs8.chmodSync(tokenPath, 432);
|
|
35483
35582
|
return;
|
|
35484
35583
|
}
|
|
35485
35584
|
function loadToken(projectId) {
|
|
@@ -35488,10 +35587,10 @@ var require_token_util = __commonJS((exports, module) => {
|
|
|
35488
35587
|
throw new import_token_error.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");
|
|
35489
35588
|
}
|
|
35490
35589
|
const tokenPath = path12.join(dir, "com.vercel.token", `${projectId}.json`);
|
|
35491
|
-
if (!
|
|
35590
|
+
if (!fs8.existsSync(tokenPath)) {
|
|
35492
35591
|
return null;
|
|
35493
35592
|
}
|
|
35494
|
-
const token = JSON.parse(
|
|
35593
|
+
const token = JSON.parse(fs8.readFileSync(tokenPath, "utf8"));
|
|
35495
35594
|
assertVercelOidcTokenResponse(token);
|
|
35496
35595
|
return token;
|
|
35497
35596
|
}
|
|
@@ -62921,26 +63020,26 @@ var require_process = __commonJS((exports, module) => {
|
|
|
62921
63020
|
|
|
62922
63021
|
// ../../node_modules/detect-libc/lib/filesystem.js
|
|
62923
63022
|
var require_filesystem = __commonJS((exports, module) => {
|
|
62924
|
-
var
|
|
63023
|
+
var fs8 = __require("fs");
|
|
62925
63024
|
var LDD_PATH = "/usr/bin/ldd";
|
|
62926
63025
|
var SELF_PATH = "/proc/self/exe";
|
|
62927
63026
|
var MAX_LENGTH = 2048;
|
|
62928
63027
|
var readFileSync2 = (path12) => {
|
|
62929
|
-
const fd =
|
|
63028
|
+
const fd = fs8.openSync(path12, "r");
|
|
62930
63029
|
const buffer = Buffer.alloc(MAX_LENGTH);
|
|
62931
|
-
const bytesRead =
|
|
62932
|
-
|
|
63030
|
+
const bytesRead = fs8.readSync(fd, buffer, 0, MAX_LENGTH, 0);
|
|
63031
|
+
fs8.close(fd, () => {});
|
|
62933
63032
|
return buffer.subarray(0, bytesRead);
|
|
62934
63033
|
};
|
|
62935
63034
|
var readFile = (path12) => new Promise((resolve4, reject) => {
|
|
62936
|
-
|
|
63035
|
+
fs8.open(path12, "r", (err, fd) => {
|
|
62937
63036
|
if (err) {
|
|
62938
63037
|
reject(err);
|
|
62939
63038
|
} else {
|
|
62940
63039
|
const buffer = Buffer.alloc(MAX_LENGTH);
|
|
62941
|
-
|
|
63040
|
+
fs8.read(fd, buffer, 0, MAX_LENGTH, 0, (_, bytesRead) => {
|
|
62942
63041
|
resolve4(buffer.subarray(0, bytesRead));
|
|
62943
|
-
|
|
63042
|
+
fs8.close(fd, () => {});
|
|
62944
63043
|
});
|
|
62945
63044
|
}
|
|
62946
63045
|
});
|
|
@@ -99603,10 +99702,10 @@ Note that ${s.bold("include")} statements only accept relation fields.`, a;
|
|
|
99603
99702
|
super(t, "P2023", r);
|
|
99604
99703
|
}
|
|
99605
99704
|
};
|
|
99606
|
-
var
|
|
99705
|
+
var fs8 = new WeakMap;
|
|
99607
99706
|
function Ep(e) {
|
|
99608
|
-
let t =
|
|
99609
|
-
return t || (t = Object.entries(e),
|
|
99707
|
+
let t = fs8.get(e);
|
|
99708
|
+
return t || (t = Object.entries(e), fs8.set(e, t)), t;
|
|
99610
99709
|
}
|
|
99611
99710
|
function hs(e, t, r) {
|
|
99612
99711
|
switch (t.type) {
|
|
@@ -108132,6 +108231,7 @@ var init_registry = __esm(() => {
|
|
|
108132
108231
|
search_analytics: { storeId: "search_analytics", identityColumn: "project_id", mutable: true },
|
|
108133
108232
|
search_events: { storeId: "search_events", identityColumn: "project_id", mutable: true },
|
|
108134
108233
|
synapse_sessions: { storeId: "synapse_sessions", identityColumn: "workspace_id", mutable: true },
|
|
108234
|
+
managed_runs: { storeId: "managed_runs", identityColumn: "project_id", mutable: true },
|
|
108135
108235
|
operation_log: { storeId: "operation_log", identityColumn: "project_id", mutable: false },
|
|
108136
108236
|
project_identity_operations: {
|
|
108137
108237
|
storeId: "project_identity_operations",
|
|
@@ -114415,6 +114515,89 @@ var init_reranker = __esm(() => {
|
|
|
114415
114515
|
});
|
|
114416
114516
|
});
|
|
114417
114517
|
|
|
114518
|
+
// ../../packages/core/dist/kernel/search-diagnostics.js
|
|
114519
|
+
function searchBackendUnavailable(component, cause) {
|
|
114520
|
+
return cause instanceof SearchServiceError ? cause : new SearchServiceError("SEARCH_BACKEND_UNAVAILABLE", component, { cause });
|
|
114521
|
+
}
|
|
114522
|
+
function storeCorruption(component, cause) {
|
|
114523
|
+
return cause instanceof SearchServiceError ? cause : new SearchServiceError("STORE_CORRUPTION", component, {
|
|
114524
|
+
cause,
|
|
114525
|
+
statusCode: 500
|
|
114526
|
+
});
|
|
114527
|
+
}
|
|
114528
|
+
function projectNotIndexed(projectId, message) {
|
|
114529
|
+
return new SearchServiceError("PROJECT_NOT_INDEXED", projectId, {
|
|
114530
|
+
message,
|
|
114531
|
+
statusCode: 404
|
|
114532
|
+
});
|
|
114533
|
+
}
|
|
114534
|
+
function recordSearchDegradation(code, component, projectId) {
|
|
114535
|
+
const degradation = {
|
|
114536
|
+
code,
|
|
114537
|
+
component,
|
|
114538
|
+
message: DEGRADATION_MESSAGES[code]
|
|
114539
|
+
};
|
|
114540
|
+
diagnostics.push({
|
|
114541
|
+
kind: "degradation",
|
|
114542
|
+
...degradation,
|
|
114543
|
+
projectId,
|
|
114544
|
+
timestamp: new Date().toISOString()
|
|
114545
|
+
});
|
|
114546
|
+
if (diagnostics.length > MAX_DIAGNOSTICS) {
|
|
114547
|
+
diagnostics.splice(0, diagnostics.length - MAX_DIAGNOSTICS);
|
|
114548
|
+
}
|
|
114549
|
+
return degradation;
|
|
114550
|
+
}
|
|
114551
|
+
function recordSearchFailure(error51, projectId) {
|
|
114552
|
+
if (recordedFailures.has(error51))
|
|
114553
|
+
return;
|
|
114554
|
+
recordedFailures.add(error51);
|
|
114555
|
+
diagnostics.push({
|
|
114556
|
+
kind: "failure",
|
|
114557
|
+
code: error51.code,
|
|
114558
|
+
component: error51.component,
|
|
114559
|
+
message: error51.message,
|
|
114560
|
+
projectId,
|
|
114561
|
+
timestamp: new Date().toISOString()
|
|
114562
|
+
});
|
|
114563
|
+
if (diagnostics.length > MAX_DIAGNOSTICS) {
|
|
114564
|
+
diagnostics.splice(0, diagnostics.length - MAX_DIAGNOSTICS);
|
|
114565
|
+
}
|
|
114566
|
+
}
|
|
114567
|
+
function getSearchDiagnostics() {
|
|
114568
|
+
return diagnostics.map((diagnostic) => ({ ...diagnostic }));
|
|
114569
|
+
}
|
|
114570
|
+
function resetSearchDiagnosticsForTests() {
|
|
114571
|
+
diagnostics.length = 0;
|
|
114572
|
+
}
|
|
114573
|
+
var MAX_DIAGNOSTICS = 100, diagnostics, recordedFailures, DEGRADATION_MESSAGES, SearchServiceError;
|
|
114574
|
+
var init_search_diagnostics = __esm(() => {
|
|
114575
|
+
diagnostics = [];
|
|
114576
|
+
recordedFailures = new WeakSet;
|
|
114577
|
+
DEGRADATION_MESSAGES = {
|
|
114578
|
+
QUERY_UNDERSTANDING_UNAVAILABLE: "Query understanding was unavailable; original query used",
|
|
114579
|
+
TRIGRAM_UNAVAILABLE: "Trigram enrichment was unavailable",
|
|
114580
|
+
FUZZY_SEARCH_UNAVAILABLE: "Fuzzy enrichment was unavailable",
|
|
114581
|
+
PROXIMITY_RERANK_UNAVAILABLE: "Proximity reranking was unavailable; fused order preserved",
|
|
114582
|
+
GRAPH_AUGMENTATION_UNAVAILABLE: "Graph augmentation was unavailable",
|
|
114583
|
+
SYNAPSE_UNAVAILABLE: "Synapse enrichment was unavailable; stateless results used",
|
|
114584
|
+
SEARCH_AUDIT_UNAVAILABLE: "Search event auditing was unavailable",
|
|
114585
|
+
SEARCH_ANALYTICS_UNAVAILABLE: "Search analytics were unavailable"
|
|
114586
|
+
};
|
|
114587
|
+
SearchServiceError = class SearchServiceError extends Error {
|
|
114588
|
+
code;
|
|
114589
|
+
component;
|
|
114590
|
+
statusCode;
|
|
114591
|
+
constructor(code, component, options) {
|
|
114592
|
+
super(options?.message ?? (code === "STORE_CORRUPTION" ? "Stored data is invalid" : "A required search backend is unavailable"), options?.cause === undefined ? undefined : { cause: options.cause });
|
|
114593
|
+
this.code = code;
|
|
114594
|
+
this.component = component;
|
|
114595
|
+
this.name = "SearchServiceError";
|
|
114596
|
+
this.statusCode = options?.statusCode ?? 503;
|
|
114597
|
+
}
|
|
114598
|
+
};
|
|
114599
|
+
});
|
|
114600
|
+
|
|
114418
114601
|
// ../../packages/core/dist/kernel/enum-validation.js
|
|
114419
114602
|
function validateEnum(paramName, value, validValues) {
|
|
114420
114603
|
if (typeof value !== "string" || !validValues.includes(value)) {
|
|
@@ -114523,7 +114706,7 @@ class SearchController {
|
|
|
114523
114706
|
});
|
|
114524
114707
|
const admission = await this.contextualSearch.checkSearchAdmission(projectId, projectPath);
|
|
114525
114708
|
if (!admission.admitted) {
|
|
114526
|
-
throw
|
|
114709
|
+
throw projectNotIndexed(projectId, admission.error ?? `Project '${projectId}' is not indexed`);
|
|
114527
114710
|
}
|
|
114528
114711
|
const staleWarning = admission.stale ?? null;
|
|
114529
114712
|
let reindexInfo = null;
|
|
@@ -114747,6 +114930,7 @@ var init_search_controller = __esm(() => {
|
|
|
114747
114930
|
init_contextual_search_rlm();
|
|
114748
114931
|
init_event_bus();
|
|
114749
114932
|
init_reranker();
|
|
114933
|
+
init_search_diagnostics();
|
|
114750
114934
|
init_esm();
|
|
114751
114935
|
init_filter_validation();
|
|
114752
114936
|
});
|
|
@@ -115232,83 +115416,6 @@ var init_session_bias = __esm(() => {
|
|
|
115232
115416
|
init_synapse();
|
|
115233
115417
|
});
|
|
115234
115418
|
|
|
115235
|
-
// ../../packages/core/dist/kernel/search-diagnostics.js
|
|
115236
|
-
function searchBackendUnavailable(component, cause) {
|
|
115237
|
-
return cause instanceof SearchServiceError ? cause : new SearchServiceError("SEARCH_BACKEND_UNAVAILABLE", component, { cause });
|
|
115238
|
-
}
|
|
115239
|
-
function storeCorruption(component, cause) {
|
|
115240
|
-
return cause instanceof SearchServiceError ? cause : new SearchServiceError("STORE_CORRUPTION", component, {
|
|
115241
|
-
cause,
|
|
115242
|
-
statusCode: 500
|
|
115243
|
-
});
|
|
115244
|
-
}
|
|
115245
|
-
function recordSearchDegradation(code, component, projectId) {
|
|
115246
|
-
const degradation = {
|
|
115247
|
-
code,
|
|
115248
|
-
component,
|
|
115249
|
-
message: DEGRADATION_MESSAGES[code]
|
|
115250
|
-
};
|
|
115251
|
-
diagnostics.push({
|
|
115252
|
-
kind: "degradation",
|
|
115253
|
-
...degradation,
|
|
115254
|
-
projectId,
|
|
115255
|
-
timestamp: new Date().toISOString()
|
|
115256
|
-
});
|
|
115257
|
-
if (diagnostics.length > MAX_DIAGNOSTICS) {
|
|
115258
|
-
diagnostics.splice(0, diagnostics.length - MAX_DIAGNOSTICS);
|
|
115259
|
-
}
|
|
115260
|
-
return degradation;
|
|
115261
|
-
}
|
|
115262
|
-
function recordSearchFailure(error51, projectId) {
|
|
115263
|
-
if (recordedFailures.has(error51))
|
|
115264
|
-
return;
|
|
115265
|
-
recordedFailures.add(error51);
|
|
115266
|
-
diagnostics.push({
|
|
115267
|
-
kind: "failure",
|
|
115268
|
-
code: error51.code,
|
|
115269
|
-
component: error51.component,
|
|
115270
|
-
message: error51.message,
|
|
115271
|
-
projectId,
|
|
115272
|
-
timestamp: new Date().toISOString()
|
|
115273
|
-
});
|
|
115274
|
-
if (diagnostics.length > MAX_DIAGNOSTICS) {
|
|
115275
|
-
diagnostics.splice(0, diagnostics.length - MAX_DIAGNOSTICS);
|
|
115276
|
-
}
|
|
115277
|
-
}
|
|
115278
|
-
function getSearchDiagnostics() {
|
|
115279
|
-
return diagnostics.map((diagnostic) => ({ ...diagnostic }));
|
|
115280
|
-
}
|
|
115281
|
-
function resetSearchDiagnosticsForTests() {
|
|
115282
|
-
diagnostics.length = 0;
|
|
115283
|
-
}
|
|
115284
|
-
var MAX_DIAGNOSTICS = 100, diagnostics, recordedFailures, DEGRADATION_MESSAGES, SearchServiceError;
|
|
115285
|
-
var init_search_diagnostics = __esm(() => {
|
|
115286
|
-
diagnostics = [];
|
|
115287
|
-
recordedFailures = new WeakSet;
|
|
115288
|
-
DEGRADATION_MESSAGES = {
|
|
115289
|
-
QUERY_UNDERSTANDING_UNAVAILABLE: "Query understanding was unavailable; original query used",
|
|
115290
|
-
TRIGRAM_UNAVAILABLE: "Trigram enrichment was unavailable",
|
|
115291
|
-
FUZZY_SEARCH_UNAVAILABLE: "Fuzzy enrichment was unavailable",
|
|
115292
|
-
PROXIMITY_RERANK_UNAVAILABLE: "Proximity reranking was unavailable; fused order preserved",
|
|
115293
|
-
GRAPH_AUGMENTATION_UNAVAILABLE: "Graph augmentation was unavailable",
|
|
115294
|
-
SYNAPSE_UNAVAILABLE: "Synapse enrichment was unavailable; stateless results used",
|
|
115295
|
-
SEARCH_AUDIT_UNAVAILABLE: "Search event auditing was unavailable",
|
|
115296
|
-
SEARCH_ANALYTICS_UNAVAILABLE: "Search analytics were unavailable"
|
|
115297
|
-
};
|
|
115298
|
-
SearchServiceError = class SearchServiceError extends Error {
|
|
115299
|
-
code;
|
|
115300
|
-
component;
|
|
115301
|
-
statusCode;
|
|
115302
|
-
constructor(code, component, options) {
|
|
115303
|
-
super(code === "STORE_CORRUPTION" ? "Stored data is invalid" : "A required search backend is unavailable", options?.cause === undefined ? undefined : { cause: options.cause });
|
|
115304
|
-
this.code = code;
|
|
115305
|
-
this.component = component;
|
|
115306
|
-
this.name = "SearchServiceError";
|
|
115307
|
-
this.statusCode = options?.statusCode ?? 503;
|
|
115308
|
-
}
|
|
115309
|
-
};
|
|
115310
|
-
});
|
|
115311
|
-
|
|
115312
115419
|
// ../../packages/core/dist/services/search/hybrid-search.js
|
|
115313
115420
|
async function search(deps, query, projectId, options = {}) {
|
|
115314
115421
|
const maxResults = options.maxResults ?? 10;
|
|
@@ -116665,7 +116772,7 @@ var init_managed_run_repository_pg = __esm(() => {
|
|
|
116665
116772
|
});
|
|
116666
116773
|
|
|
116667
116774
|
// ../../packages/core/dist/services/search/project-indexer.js
|
|
116668
|
-
import
|
|
116775
|
+
import fs8 from "fs/promises";
|
|
116669
116776
|
import path13 from "path";
|
|
116670
116777
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
116671
116778
|
async function runWithIndexLock(lockMap, projectId, work) {
|
|
@@ -116925,7 +117032,7 @@ async function checkSearchAdmission(deps, projectId, projectPath) {
|
|
|
116925
117032
|
}
|
|
116926
117033
|
async function indexFile(deps, filePath, projectId, projectRoot, centralityMap) {
|
|
116927
117034
|
projectId = await getProjectIdentityAliasResolver().resolve(projectId);
|
|
116928
|
-
const content = await
|
|
117035
|
+
const content = await fs8.readFile(filePath, "utf-8");
|
|
116929
117036
|
const relativePath = path13.relative(projectRoot, filePath);
|
|
116930
117037
|
const maxFileSize = config.get("security").maxFileSize || 1024 * 1024;
|
|
116931
117038
|
if (content.length > maxFileSize) {
|
|
@@ -120524,7 +120631,7 @@ __export(exports_symbol_graph_service, {
|
|
|
120524
120631
|
SymbolGraphService: () => SymbolGraphService
|
|
120525
120632
|
});
|
|
120526
120633
|
import path14 from "path";
|
|
120527
|
-
import
|
|
120634
|
+
import fs9 from "fs/promises";
|
|
120528
120635
|
|
|
120529
120636
|
class SymbolGraphService {
|
|
120530
120637
|
identityLookup;
|
|
@@ -120852,7 +120959,7 @@ class SymbolGraphService {
|
|
|
120852
120959
|
async readSnippet(relativePath, lineStart, lineEnd, projectId) {
|
|
120853
120960
|
try {
|
|
120854
120961
|
const absolutePath = await this.resolveToAbsolute(relativePath, projectId);
|
|
120855
|
-
const content = await
|
|
120962
|
+
const content = await fs9.readFile(absolutePath, "utf-8");
|
|
120856
120963
|
const lines = content.split(`
|
|
120857
120964
|
`);
|
|
120858
120965
|
return lines.slice(Math.max(0, lineStart - 1), Math.min(lines.length, lineEnd)).join(`
|
|
@@ -120864,7 +120971,7 @@ class SymbolGraphService {
|
|
|
120864
120971
|
async readContext(relativePath, lineNumber, contextLines, projectId) {
|
|
120865
120972
|
try {
|
|
120866
120973
|
const absolutePath = await this.resolveToAbsolute(relativePath, projectId);
|
|
120867
|
-
const content = await
|
|
120974
|
+
const content = await fs9.readFile(absolutePath, "utf-8");
|
|
120868
120975
|
const lines = content.split(`
|
|
120869
120976
|
`);
|
|
120870
120977
|
const start = Math.max(0, lineNumber - contextLines - 1);
|
|
@@ -124673,7 +124780,7 @@ var init_l1_memory_cache = __esm(() => {
|
|
|
124673
124780
|
});
|
|
124674
124781
|
|
|
124675
124782
|
// ../../packages/core/dist/services/health/local-health-checker.js
|
|
124676
|
-
import
|
|
124783
|
+
import fs10 from "fs/promises";
|
|
124677
124784
|
import { existsSync as existsSync3 } from "fs";
|
|
124678
124785
|
import path15 from "path";
|
|
124679
124786
|
|
|
@@ -124709,10 +124816,10 @@ class LocalHealthChecker {
|
|
|
124709
124816
|
const start = Date.now();
|
|
124710
124817
|
try {
|
|
124711
124818
|
if (!existsSync3(this.dataDir))
|
|
124712
|
-
await
|
|
124819
|
+
await fs10.mkdir(this.dataDir, { recursive: true });
|
|
124713
124820
|
const probe = path15.join(this.dataDir, ".health-check-test");
|
|
124714
|
-
await
|
|
124715
|
-
await
|
|
124821
|
+
await fs10.writeFile(probe, "ok");
|
|
124822
|
+
await fs10.unlink(probe);
|
|
124716
124823
|
return { available: true, latency: Date.now() - start, details: { path: this.dataDir, writable: true } };
|
|
124717
124824
|
} catch (error51) {
|
|
124718
124825
|
return { available: false, latency: Date.now() - start, error: `Data directory error: ${error51.message}` };
|
|
@@ -127280,6 +127387,391 @@ var init_observation_consolidation_job = __esm(() => {
|
|
|
127280
127387
|
observationConsolidationJob = new ObservationConsolidationJob;
|
|
127281
127388
|
});
|
|
127282
127389
|
|
|
127390
|
+
// ../../packages/core/dist/services/checkpoint/checkpoint-store-pg.js
|
|
127391
|
+
function toNum4(v) {
|
|
127392
|
+
if (v == null)
|
|
127393
|
+
return null;
|
|
127394
|
+
return typeof v === "bigint" ? Number(v) : v;
|
|
127395
|
+
}
|
|
127396
|
+
function compressState(state) {
|
|
127397
|
+
const json3 = JSON.stringify(state);
|
|
127398
|
+
return Buffer.from(Bun.deflateSync(Buffer.from(json3, "utf-8")));
|
|
127399
|
+
}
|
|
127400
|
+
function decompressState(data) {
|
|
127401
|
+
const buf = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
127402
|
+
const inflated = Bun.inflateSync(new Uint8Array(buf));
|
|
127403
|
+
return JSON.parse(Buffer.from(inflated).toString("utf-8"));
|
|
127404
|
+
}
|
|
127405
|
+
|
|
127406
|
+
class PgCheckpointStore {
|
|
127407
|
+
prisma;
|
|
127408
|
+
mirror = new Map;
|
|
127409
|
+
hydrated = false;
|
|
127410
|
+
hydrating = null;
|
|
127411
|
+
hydrateFailedAt = 0;
|
|
127412
|
+
static HYDRATE_RETRY_MS = 30000;
|
|
127413
|
+
inflight = new Map;
|
|
127414
|
+
getClient() {
|
|
127415
|
+
if (!this.prisma)
|
|
127416
|
+
this.prisma = getPrismaClient2();
|
|
127417
|
+
return this.prisma;
|
|
127418
|
+
}
|
|
127419
|
+
ensureHydrated() {
|
|
127420
|
+
if (this.hydrated)
|
|
127421
|
+
return Promise.resolve();
|
|
127422
|
+
if (this.hydrating)
|
|
127423
|
+
return this.hydrating;
|
|
127424
|
+
if (this.hydrateFailedAt > 0 && Date.now() - this.hydrateFailedAt < PgCheckpointStore.HYDRATE_RETRY_MS) {
|
|
127425
|
+
return Promise.resolve();
|
|
127426
|
+
}
|
|
127427
|
+
this.hydrating = (async () => {
|
|
127428
|
+
try {
|
|
127429
|
+
const prisma2 = this.getClient();
|
|
127430
|
+
const rows = await prisma2.$queryRaw`
|
|
127431
|
+
SELECT * FROM task_checkpoints
|
|
127432
|
+
`;
|
|
127433
|
+
const next = new Map;
|
|
127434
|
+
const dbIds = new Set;
|
|
127435
|
+
for (const row of rows) {
|
|
127436
|
+
dbIds.add(row.id);
|
|
127437
|
+
next.set(row.id, this.rowToCheckpoint(row));
|
|
127438
|
+
}
|
|
127439
|
+
for (const [id, existing] of this.mirror) {
|
|
127440
|
+
if (!dbIds.has(id))
|
|
127441
|
+
next.set(id, existing);
|
|
127442
|
+
}
|
|
127443
|
+
this.mirror = next;
|
|
127444
|
+
this.hydrated = true;
|
|
127445
|
+
this.hydrateFailedAt = 0;
|
|
127446
|
+
logger.info("PgCheckpointStore hydrated", {
|
|
127447
|
+
rows: this.mirror.size
|
|
127448
|
+
});
|
|
127449
|
+
} catch (e) {
|
|
127450
|
+
this.hydrateFailedAt = Date.now();
|
|
127451
|
+
logger.warn("PgCheckpointStore hydrate failed (best-effort)", {
|
|
127452
|
+
error: e.message
|
|
127453
|
+
});
|
|
127454
|
+
} finally {
|
|
127455
|
+
this.hydrating = null;
|
|
127456
|
+
}
|
|
127457
|
+
})();
|
|
127458
|
+
return this.hydrating;
|
|
127459
|
+
}
|
|
127460
|
+
rowToCheckpoint(row) {
|
|
127461
|
+
const state = decompressState(row.state);
|
|
127462
|
+
const storedSchemaVersion = toNum4(row.state_schema_version);
|
|
127463
|
+
if (storedSchemaVersion != null) {
|
|
127464
|
+
const storedVersionString = String(storedSchemaVersion);
|
|
127465
|
+
const normalized = /^\d+$/u.test(storedVersionString) ? `${storedVersionString}.0.0` : storedVersionString;
|
|
127466
|
+
assertSchemaSupported("checkpoint", normalized, SUPPORTED_CHECKPOINT_STATE_SCHEMA_VERSION);
|
|
127467
|
+
}
|
|
127468
|
+
return {
|
|
127469
|
+
id: row.id,
|
|
127470
|
+
taskId: row.task_id,
|
|
127471
|
+
taskDescription: row.task_description ?? undefined,
|
|
127472
|
+
agentId: row.agent_id ?? undefined,
|
|
127473
|
+
projectId: row.project_id ?? undefined,
|
|
127474
|
+
state,
|
|
127475
|
+
memoryIds: row.memory_ids ? JSON.parse(row.memory_ids) : [],
|
|
127476
|
+
fileChanges: row.file_changes ? JSON.parse(row.file_changes) : [],
|
|
127477
|
+
checkpointType: row.checkpoint_type,
|
|
127478
|
+
parentCheckpointId: row.parent_checkpoint_id ?? undefined,
|
|
127479
|
+
createdAt: toNum4(row.created_at) ?? Date.now(),
|
|
127480
|
+
expiresAt: toNum4(row.expires_at) ?? undefined
|
|
127481
|
+
};
|
|
127482
|
+
}
|
|
127483
|
+
createCheckpoint(state, options = {}) {
|
|
127484
|
+
const {
|
|
127485
|
+
agentId,
|
|
127486
|
+
projectId,
|
|
127487
|
+
checkpointType = CheckpointType.MANUAL,
|
|
127488
|
+
memoryIds = [],
|
|
127489
|
+
fileChanges = [],
|
|
127490
|
+
parentCheckpointId,
|
|
127491
|
+
ttlMs = 7 * 24 * 60 * 60 * 1000
|
|
127492
|
+
} = options;
|
|
127493
|
+
const id = `ckpt_${checkpointType}_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
|
|
127494
|
+
const now2 = Date.now();
|
|
127495
|
+
const expiresAt = now2 + ttlMs;
|
|
127496
|
+
const checkpoint = {
|
|
127497
|
+
id,
|
|
127498
|
+
taskId: state.taskId,
|
|
127499
|
+
taskDescription: state.description,
|
|
127500
|
+
agentId,
|
|
127501
|
+
projectId,
|
|
127502
|
+
state,
|
|
127503
|
+
memoryIds,
|
|
127504
|
+
fileChanges,
|
|
127505
|
+
checkpointType,
|
|
127506
|
+
parentCheckpointId,
|
|
127507
|
+
createdAt: now2,
|
|
127508
|
+
expiresAt
|
|
127509
|
+
};
|
|
127510
|
+
this.mirror.set(id, checkpoint);
|
|
127511
|
+
this.ensureHydrated();
|
|
127512
|
+
this.chainWrite(id, async () => {
|
|
127513
|
+
const prisma2 = this.getClient();
|
|
127514
|
+
const canonicalProjectId = projectId ? await getProjectIdentityAliasResolver().resolve(projectId) : projectId;
|
|
127515
|
+
const compressed = compressState(state);
|
|
127516
|
+
await prisma2.$executeRaw`
|
|
127517
|
+
INSERT INTO task_checkpoints (
|
|
127518
|
+
id, task_id, task_description, agent_id, project_id,
|
|
127519
|
+
state, state_schema_version,
|
|
127520
|
+
memory_ids, file_changes,
|
|
127521
|
+
checkpoint_type, parent_checkpoint_id,
|
|
127522
|
+
created_at, expires_at
|
|
127523
|
+
) VALUES (
|
|
127524
|
+
${id},
|
|
127525
|
+
${state.taskId},
|
|
127526
|
+
${state.description ?? null},
|
|
127527
|
+
${agentId ?? null},
|
|
127528
|
+
${canonicalProjectId ?? null},
|
|
127529
|
+
${compressed},
|
|
127530
|
+
1,
|
|
127531
|
+
${JSON.stringify(memoryIds)},
|
|
127532
|
+
${JSON.stringify(fileChanges)},
|
|
127533
|
+
${checkpointType},
|
|
127534
|
+
${parentCheckpointId ?? null},
|
|
127535
|
+
${now2}::bigint,
|
|
127536
|
+
${expiresAt}::bigint
|
|
127537
|
+
)
|
|
127538
|
+
ON CONFLICT (id) DO UPDATE SET
|
|
127539
|
+
task_id = EXCLUDED.task_id,
|
|
127540
|
+
task_description = EXCLUDED.task_description,
|
|
127541
|
+
agent_id = EXCLUDED.agent_id,
|
|
127542
|
+
project_id = EXCLUDED.project_id,
|
|
127543
|
+
state = EXCLUDED.state,
|
|
127544
|
+
state_schema_version = EXCLUDED.state_schema_version,
|
|
127545
|
+
memory_ids = EXCLUDED.memory_ids,
|
|
127546
|
+
file_changes = EXCLUDED.file_changes,
|
|
127547
|
+
checkpoint_type = EXCLUDED.checkpoint_type,
|
|
127548
|
+
parent_checkpoint_id = EXCLUDED.parent_checkpoint_id,
|
|
127549
|
+
created_at = EXCLUDED.created_at,
|
|
127550
|
+
expires_at = EXCLUDED.expires_at
|
|
127551
|
+
`;
|
|
127552
|
+
});
|
|
127553
|
+
logger.info("Checkpoint created (PG)", {
|
|
127554
|
+
id,
|
|
127555
|
+
taskId: state.taskId,
|
|
127556
|
+
type: checkpointType,
|
|
127557
|
+
compressedBytes: compressState(state).byteLength
|
|
127558
|
+
});
|
|
127559
|
+
return checkpoint;
|
|
127560
|
+
}
|
|
127561
|
+
getCheckpoint(checkpointId) {
|
|
127562
|
+
this.ensureHydrated();
|
|
127563
|
+
return this.mirror.get(checkpointId) ?? null;
|
|
127564
|
+
}
|
|
127565
|
+
listCheckpoints(options = {}) {
|
|
127566
|
+
this.ensureHydrated();
|
|
127567
|
+
return this.applyFilters(this.mirror.values(), options);
|
|
127568
|
+
}
|
|
127569
|
+
listCheckpointsMetadata(options = {}) {
|
|
127570
|
+
this.ensureHydrated();
|
|
127571
|
+
const filtered = this.applyFilters(this.mirror.values(), options);
|
|
127572
|
+
return filtered.map((c) => this.checkpointToMetadata(c));
|
|
127573
|
+
}
|
|
127574
|
+
getCheckpointState(checkpointId) {
|
|
127575
|
+
this.ensureHydrated();
|
|
127576
|
+
const ckpt = this.mirror.get(checkpointId);
|
|
127577
|
+
return ckpt ? ckpt.state : null;
|
|
127578
|
+
}
|
|
127579
|
+
getLatestCheckpoint(taskId) {
|
|
127580
|
+
this.ensureHydrated();
|
|
127581
|
+
const now2 = Date.now();
|
|
127582
|
+
let latest = null;
|
|
127583
|
+
for (const ckpt of this.mirror.values()) {
|
|
127584
|
+
if (ckpt.taskId === taskId && (ckpt.expiresAt == null || ckpt.expiresAt > now2)) {
|
|
127585
|
+
if (!latest || ckpt.createdAt > latest.createdAt) {
|
|
127586
|
+
latest = ckpt;
|
|
127587
|
+
}
|
|
127588
|
+
}
|
|
127589
|
+
}
|
|
127590
|
+
return latest;
|
|
127591
|
+
}
|
|
127592
|
+
deleteCheckpoint(checkpointId) {
|
|
127593
|
+
const existed = this.mirror.has(checkpointId);
|
|
127594
|
+
this.mirror.delete(checkpointId);
|
|
127595
|
+
this.ensureHydrated();
|
|
127596
|
+
this.chainWrite(checkpointId, async () => {
|
|
127597
|
+
const prisma2 = this.getClient();
|
|
127598
|
+
await prisma2.$executeRaw`
|
|
127599
|
+
DELETE FROM task_checkpoints WHERE id = ${checkpointId}
|
|
127600
|
+
`;
|
|
127601
|
+
});
|
|
127602
|
+
return existed;
|
|
127603
|
+
}
|
|
127604
|
+
purgeExpired() {
|
|
127605
|
+
const now2 = Date.now();
|
|
127606
|
+
let count = 0;
|
|
127607
|
+
const toRemove = [];
|
|
127608
|
+
for (const ckpt of this.mirror.values()) {
|
|
127609
|
+
if (ckpt.expiresAt != null && ckpt.expiresAt < now2) {
|
|
127610
|
+
toRemove.push(ckpt.id);
|
|
127611
|
+
count++;
|
|
127612
|
+
}
|
|
127613
|
+
}
|
|
127614
|
+
for (const id of toRemove)
|
|
127615
|
+
this.mirror.delete(id);
|
|
127616
|
+
if (count > 0) {
|
|
127617
|
+
this.chainWrite("__purge__", async () => {
|
|
127618
|
+
const prisma2 = this.getClient();
|
|
127619
|
+
await prisma2.$executeRaw`
|
|
127620
|
+
DELETE FROM task_checkpoints
|
|
127621
|
+
WHERE expires_at IS NOT NULL AND expires_at < ${now2}::bigint
|
|
127622
|
+
`;
|
|
127623
|
+
});
|
|
127624
|
+
logger.info("Expired checkpoints purged (PG)", { count });
|
|
127625
|
+
}
|
|
127626
|
+
return count;
|
|
127627
|
+
}
|
|
127628
|
+
async countExistingMemoryIds(memoryIds) {
|
|
127629
|
+
if (memoryIds.length === 0)
|
|
127630
|
+
return [];
|
|
127631
|
+
this.ensureHydrated();
|
|
127632
|
+
const BATCH_SIZE = 1000;
|
|
127633
|
+
const existing = [];
|
|
127634
|
+
try {
|
|
127635
|
+
const prisma2 = this.getClient();
|
|
127636
|
+
for (let i = 0;i < memoryIds.length; i += BATCH_SIZE) {
|
|
127637
|
+
const batch = memoryIds.slice(i, i + BATCH_SIZE);
|
|
127638
|
+
const rows = await prisma2.$queryRaw`
|
|
127639
|
+
SELECT id FROM memories WHERE id IN (${import_prisma4.Prisma.join(batch)})
|
|
127640
|
+
`;
|
|
127641
|
+
for (const row of rows)
|
|
127642
|
+
existing.push(row.id);
|
|
127643
|
+
}
|
|
127644
|
+
return existing;
|
|
127645
|
+
} catch (e) {
|
|
127646
|
+
logger.warn("countExistingMemoryIds failed (best-effort: assuming all exist)", {
|
|
127647
|
+
error: e.message
|
|
127648
|
+
});
|
|
127649
|
+
return memoryIds;
|
|
127650
|
+
}
|
|
127651
|
+
}
|
|
127652
|
+
getStats() {
|
|
127653
|
+
this.ensureHydrated();
|
|
127654
|
+
const checkpoints = Array.from(this.mirror.values());
|
|
127655
|
+
const byType = {};
|
|
127656
|
+
let totalSizeBytes = 0;
|
|
127657
|
+
let oldest;
|
|
127658
|
+
for (const c of checkpoints) {
|
|
127659
|
+
byType[c.checkpointType] = (byType[c.checkpointType] ?? 0) + 1;
|
|
127660
|
+
totalSizeBytes += compressState(c.state).byteLength;
|
|
127661
|
+
if (oldest == null || c.createdAt < oldest)
|
|
127662
|
+
oldest = c.createdAt;
|
|
127663
|
+
}
|
|
127664
|
+
return {
|
|
127665
|
+
totalCheckpoints: checkpoints.length,
|
|
127666
|
+
byType,
|
|
127667
|
+
totalSizeBytes,
|
|
127668
|
+
oldestCheckpointAge: oldest != null ? Date.now() - oldest : undefined
|
|
127669
|
+
};
|
|
127670
|
+
}
|
|
127671
|
+
ensureReady() {
|
|
127672
|
+
return this.ensureHydrated();
|
|
127673
|
+
}
|
|
127674
|
+
close() {}
|
|
127675
|
+
applyFilters(iter, options) {
|
|
127676
|
+
const { taskId, projectId, checkpointType, includeExpired = false, limit = 20, offset = 0 } = options;
|
|
127677
|
+
const now2 = Date.now();
|
|
127678
|
+
const out = [];
|
|
127679
|
+
for (const c of iter) {
|
|
127680
|
+
if (taskId && c.taskId !== taskId)
|
|
127681
|
+
continue;
|
|
127682
|
+
if (projectId && c.projectId !== projectId)
|
|
127683
|
+
continue;
|
|
127684
|
+
if (checkpointType && c.checkpointType !== checkpointType)
|
|
127685
|
+
continue;
|
|
127686
|
+
if (!includeExpired && c.expiresAt != null && c.expiresAt <= now2)
|
|
127687
|
+
continue;
|
|
127688
|
+
out.push(c);
|
|
127689
|
+
}
|
|
127690
|
+
out.sort((a, b) => b.createdAt - a.createdAt);
|
|
127691
|
+
return out.slice(offset, offset + limit);
|
|
127692
|
+
}
|
|
127693
|
+
checkpointToMetadata(c) {
|
|
127694
|
+
return {
|
|
127695
|
+
id: c.id,
|
|
127696
|
+
taskId: c.taskId,
|
|
127697
|
+
taskDescription: c.taskDescription,
|
|
127698
|
+
agentId: c.agentId,
|
|
127699
|
+
projectId: c.projectId,
|
|
127700
|
+
checkpointType: c.checkpointType,
|
|
127701
|
+
parentCheckpointId: c.parentCheckpointId,
|
|
127702
|
+
createdAt: c.createdAt,
|
|
127703
|
+
expiresAt: c.expiresAt,
|
|
127704
|
+
compressedSizeBytes: compressState(c.state).byteLength,
|
|
127705
|
+
memoryCount: c.memoryIds.length,
|
|
127706
|
+
fileChangeCount: c.fileChanges.length
|
|
127707
|
+
};
|
|
127708
|
+
}
|
|
127709
|
+
chainWrite(key, fn) {
|
|
127710
|
+
const prev = this.inflight.get(key) ?? Promise.resolve();
|
|
127711
|
+
const next = prev.then(fn).catch((e) => {
|
|
127712
|
+
logger.warn("PgCheckpointStore write failed (best-effort)", {
|
|
127713
|
+
key,
|
|
127714
|
+
error: e.message
|
|
127715
|
+
});
|
|
127716
|
+
});
|
|
127717
|
+
this.inflight.set(key, next);
|
|
127718
|
+
next.then(() => {
|
|
127719
|
+
if (this.inflight.get(key) === next)
|
|
127720
|
+
this.inflight.delete(key);
|
|
127721
|
+
});
|
|
127722
|
+
}
|
|
127723
|
+
async __drain() {
|
|
127724
|
+
const pending = Array.from(this.inflight.values());
|
|
127725
|
+
if (pending.length > 0)
|
|
127726
|
+
await Promise.allSettled(pending);
|
|
127727
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
127728
|
+
}
|
|
127729
|
+
async __hydrate() {
|
|
127730
|
+
await this.ensureHydrated();
|
|
127731
|
+
}
|
|
127732
|
+
}
|
|
127733
|
+
var import_prisma4, SUPPORTED_CHECKPOINT_STATE_SCHEMA_VERSION = "1.0.0";
|
|
127734
|
+
var init_checkpoint_store_pg = __esm(() => {
|
|
127735
|
+
init_dist();
|
|
127736
|
+
init_prisma_client();
|
|
127737
|
+
init_alias_resolver();
|
|
127738
|
+
init_schema_version();
|
|
127739
|
+
import_prisma4 = __toESM(require_prisma(), 1);
|
|
127740
|
+
});
|
|
127741
|
+
|
|
127742
|
+
// ../../packages/core/dist/services/checkpoint/checkpoint-manager.js
|
|
127743
|
+
var exports_checkpoint_manager = {};
|
|
127744
|
+
__export(exports_checkpoint_manager, {
|
|
127745
|
+
CheckpointManager: () => CheckpointManager
|
|
127746
|
+
});
|
|
127747
|
+
var CheckpointManager;
|
|
127748
|
+
var init_checkpoint_manager = __esm(() => {
|
|
127749
|
+
init_config();
|
|
127750
|
+
init_checkpoint_store_pg();
|
|
127751
|
+
CheckpointManager = class CheckpointManager extends PgCheckpointStore {
|
|
127752
|
+
static instance = null;
|
|
127753
|
+
static getInstance() {
|
|
127754
|
+
requirePostgresDatabaseUrl();
|
|
127755
|
+
return this.instance ??= new CheckpointManager;
|
|
127756
|
+
}
|
|
127757
|
+
async restoreCheckpoint(checkpointId) {
|
|
127758
|
+
const checkpoint = this.getCheckpoint(checkpointId);
|
|
127759
|
+
if (!checkpoint)
|
|
127760
|
+
return null;
|
|
127761
|
+
const existing = new Set(await this.countExistingMemoryIds(checkpoint.memoryIds));
|
|
127762
|
+
const validMemoryIds = checkpoint.memoryIds.filter((id) => existing.has(id));
|
|
127763
|
+
const missingMemoryIds = checkpoint.memoryIds.filter((id) => !existing.has(id));
|
|
127764
|
+
const fileConflicts = [];
|
|
127765
|
+
const restoreInstructions = [
|
|
127766
|
+
`Restore checkpoint ${checkpoint.id} for task ${checkpoint.taskId}.`,
|
|
127767
|
+
missingMemoryIds.length ? `Missing memories: ${missingMemoryIds.join(", ")}.` : "All referenced memories are available."
|
|
127768
|
+
].join(`
|
|
127769
|
+
`);
|
|
127770
|
+
return { checkpoint, validMemoryIds, missingMemoryIds, fileConflicts, restoreInstructions };
|
|
127771
|
+
}
|
|
127772
|
+
};
|
|
127773
|
+
});
|
|
127774
|
+
|
|
127283
127775
|
// ../../packages/core/dist/services/scheduler/scheduler-defaults.js
|
|
127284
127776
|
function envBool2(key, fallback) {
|
|
127285
127777
|
const raw2 = process.env[key];
|
|
@@ -127337,6 +127829,11 @@ function registerDefaultJobs(scheduler) {
|
|
|
127337
127829
|
const projectId = job.payload?.projectId ?? "default";
|
|
127338
127830
|
await observationConsolidationJob2.runOnce(projectId);
|
|
127339
127831
|
});
|
|
127832
|
+
scheduler.registerHandler("checkpoint-purge", async () => {
|
|
127833
|
+
const { CheckpointManager: CheckpointManager2 } = await Promise.resolve().then(() => (init_checkpoint_manager(), exports_checkpoint_manager));
|
|
127834
|
+
const count = CheckpointManager2.getInstance().purgeExpired();
|
|
127835
|
+
logger.info("Scheduled checkpoint purge completed", { count });
|
|
127836
|
+
});
|
|
127340
127837
|
for (const rawDef of DEFAULT_SCHEDULED_JOBS) {
|
|
127341
127838
|
const def = applySafeDefaults(rawDef);
|
|
127342
127839
|
const enabled = envBool2(def.enableEnvVar, def.defaultEnabled);
|
|
@@ -127398,6 +127895,15 @@ var init_scheduler_defaults = __esm(() => {
|
|
|
127398
127895
|
defaultEnabled: false,
|
|
127399
127896
|
enableEnvVar: "MASSA_AI_SCHEDULER_OBSERVATION_BRIDGE_ENABLED",
|
|
127400
127897
|
intervalEnvVar: "MASSA_AI_SCHEDULER_OBSERVATION_BRIDGE_INTERVAL_MS"
|
|
127898
|
+
},
|
|
127899
|
+
{
|
|
127900
|
+
id: "scheduled-checkpoint-purge",
|
|
127901
|
+
name: "Checkpoint Purge (clock)",
|
|
127902
|
+
jobKind: "checkpoint-purge",
|
|
127903
|
+
schedule: { type: "interval", intervalMs: ONE_HOUR },
|
|
127904
|
+
defaultEnabled: false,
|
|
127905
|
+
enableEnvVar: "MASSA_AI_SCHEDULER_CHECKPOINT_PURGE_ENABLED",
|
|
127906
|
+
intervalEnvVar: "MASSA_AI_SCHEDULER_CHECKPOINT_PURGE_INTERVAL_MS"
|
|
127401
127907
|
}
|
|
127402
127908
|
];
|
|
127403
127909
|
});
|
|
@@ -127412,7 +127918,7 @@ var init_scheduler2 = __esm(() => {
|
|
|
127412
127918
|
});
|
|
127413
127919
|
|
|
127414
127920
|
// ../../packages/core/dist/services/pricing/models-dev-client.js
|
|
127415
|
-
import
|
|
127921
|
+
import fs11 from "fs/promises";
|
|
127416
127922
|
import { existsSync as existsSync4 } from "fs";
|
|
127417
127923
|
import path16 from "path";
|
|
127418
127924
|
function getModelsDevClient() {
|
|
@@ -127442,7 +127948,7 @@ var init_models_dev_client = __esm(() => {
|
|
|
127442
127948
|
if (!existsSync4(cachePath)) {
|
|
127443
127949
|
return null;
|
|
127444
127950
|
}
|
|
127445
|
-
const content = await
|
|
127951
|
+
const content = await fs11.readFile(cachePath, "utf-8");
|
|
127446
127952
|
const data = JSON.parse(content);
|
|
127447
127953
|
const age = Date.now() - data.timestamp;
|
|
127448
127954
|
if (age > ModelsDevClient.LOCAL_CACHE_TTL) {
|
|
@@ -127470,13 +127976,13 @@ var init_models_dev_client = __esm(() => {
|
|
|
127470
127976
|
const cachePath = this.getLocalCachePath();
|
|
127471
127977
|
try {
|
|
127472
127978
|
const dir = path16.dirname(cachePath);
|
|
127473
|
-
await
|
|
127979
|
+
await fs11.mkdir(dir, { recursive: true });
|
|
127474
127980
|
const data = {
|
|
127475
127981
|
timestamp: Date.now(),
|
|
127476
127982
|
version: "1.0.0",
|
|
127477
127983
|
models: Object.fromEntries(models)
|
|
127478
127984
|
};
|
|
127479
|
-
await
|
|
127985
|
+
await fs11.writeFile(cachePath, JSON.stringify(data), "utf-8");
|
|
127480
127986
|
logger.debug("Saved pricing to local cache", {
|
|
127481
127987
|
models: models.size,
|
|
127482
127988
|
path: cachePath
|
|
@@ -127805,7 +128311,7 @@ var init_models_dev_client = __esm(() => {
|
|
|
127805
128311
|
const cachePath = this.getLocalCachePath();
|
|
127806
128312
|
try {
|
|
127807
128313
|
if (existsSync4(cachePath)) {
|
|
127808
|
-
await
|
|
128314
|
+
await fs11.unlink(cachePath);
|
|
127809
128315
|
logger.debug("Local pricing cache file deleted");
|
|
127810
128316
|
}
|
|
127811
128317
|
} catch (error51) {
|
|
@@ -128304,387 +128810,6 @@ var init_memory_clustering = __esm(() => {
|
|
|
128304
128810
|
init_prisma_client();
|
|
128305
128811
|
});
|
|
128306
128812
|
|
|
128307
|
-
// ../../packages/core/dist/services/checkpoint/checkpoint-store-pg.js
|
|
128308
|
-
function toNum4(v) {
|
|
128309
|
-
if (v == null)
|
|
128310
|
-
return null;
|
|
128311
|
-
return typeof v === "bigint" ? Number(v) : v;
|
|
128312
|
-
}
|
|
128313
|
-
function compressState(state) {
|
|
128314
|
-
const json3 = JSON.stringify(state);
|
|
128315
|
-
return Buffer.from(Bun.deflateSync(Buffer.from(json3, "utf-8")));
|
|
128316
|
-
}
|
|
128317
|
-
function decompressState(data) {
|
|
128318
|
-
const buf = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
128319
|
-
const inflated = Bun.inflateSync(new Uint8Array(buf));
|
|
128320
|
-
return JSON.parse(Buffer.from(inflated).toString("utf-8"));
|
|
128321
|
-
}
|
|
128322
|
-
|
|
128323
|
-
class PgCheckpointStore {
|
|
128324
|
-
prisma;
|
|
128325
|
-
mirror = new Map;
|
|
128326
|
-
hydrated = false;
|
|
128327
|
-
hydrating = null;
|
|
128328
|
-
hydrateFailedAt = 0;
|
|
128329
|
-
static HYDRATE_RETRY_MS = 30000;
|
|
128330
|
-
inflight = new Map;
|
|
128331
|
-
getClient() {
|
|
128332
|
-
if (!this.prisma)
|
|
128333
|
-
this.prisma = getPrismaClient2();
|
|
128334
|
-
return this.prisma;
|
|
128335
|
-
}
|
|
128336
|
-
ensureHydrated() {
|
|
128337
|
-
if (this.hydrated)
|
|
128338
|
-
return Promise.resolve();
|
|
128339
|
-
if (this.hydrating)
|
|
128340
|
-
return this.hydrating;
|
|
128341
|
-
if (this.hydrateFailedAt > 0 && Date.now() - this.hydrateFailedAt < PgCheckpointStore.HYDRATE_RETRY_MS) {
|
|
128342
|
-
return Promise.resolve();
|
|
128343
|
-
}
|
|
128344
|
-
this.hydrating = (async () => {
|
|
128345
|
-
try {
|
|
128346
|
-
const prisma2 = this.getClient();
|
|
128347
|
-
const rows = await prisma2.$queryRaw`
|
|
128348
|
-
SELECT * FROM task_checkpoints
|
|
128349
|
-
`;
|
|
128350
|
-
const next = new Map;
|
|
128351
|
-
const dbIds = new Set;
|
|
128352
|
-
for (const row of rows) {
|
|
128353
|
-
dbIds.add(row.id);
|
|
128354
|
-
next.set(row.id, this.rowToCheckpoint(row));
|
|
128355
|
-
}
|
|
128356
|
-
for (const [id, existing] of this.mirror) {
|
|
128357
|
-
if (!dbIds.has(id))
|
|
128358
|
-
next.set(id, existing);
|
|
128359
|
-
}
|
|
128360
|
-
this.mirror = next;
|
|
128361
|
-
this.hydrated = true;
|
|
128362
|
-
this.hydrateFailedAt = 0;
|
|
128363
|
-
logger.info("PgCheckpointStore hydrated", {
|
|
128364
|
-
rows: this.mirror.size
|
|
128365
|
-
});
|
|
128366
|
-
} catch (e) {
|
|
128367
|
-
this.hydrateFailedAt = Date.now();
|
|
128368
|
-
logger.warn("PgCheckpointStore hydrate failed (best-effort)", {
|
|
128369
|
-
error: e.message
|
|
128370
|
-
});
|
|
128371
|
-
} finally {
|
|
128372
|
-
this.hydrating = null;
|
|
128373
|
-
}
|
|
128374
|
-
})();
|
|
128375
|
-
return this.hydrating;
|
|
128376
|
-
}
|
|
128377
|
-
rowToCheckpoint(row) {
|
|
128378
|
-
const state = decompressState(row.state);
|
|
128379
|
-
const storedSchemaVersion = toNum4(row.state_schema_version);
|
|
128380
|
-
if (storedSchemaVersion != null) {
|
|
128381
|
-
const storedVersionString = String(storedSchemaVersion);
|
|
128382
|
-
const normalized = /^\d+$/u.test(storedVersionString) ? `${storedVersionString}.0.0` : storedVersionString;
|
|
128383
|
-
assertSchemaSupported("checkpoint", normalized, SUPPORTED_CHECKPOINT_STATE_SCHEMA_VERSION);
|
|
128384
|
-
}
|
|
128385
|
-
return {
|
|
128386
|
-
id: row.id,
|
|
128387
|
-
taskId: row.task_id,
|
|
128388
|
-
taskDescription: row.task_description ?? undefined,
|
|
128389
|
-
agentId: row.agent_id ?? undefined,
|
|
128390
|
-
projectId: row.project_id ?? undefined,
|
|
128391
|
-
state,
|
|
128392
|
-
memoryIds: row.memory_ids ? JSON.parse(row.memory_ids) : [],
|
|
128393
|
-
fileChanges: row.file_changes ? JSON.parse(row.file_changes) : [],
|
|
128394
|
-
checkpointType: row.checkpoint_type,
|
|
128395
|
-
parentCheckpointId: row.parent_checkpoint_id ?? undefined,
|
|
128396
|
-
createdAt: toNum4(row.created_at) ?? Date.now(),
|
|
128397
|
-
expiresAt: toNum4(row.expires_at) ?? undefined
|
|
128398
|
-
};
|
|
128399
|
-
}
|
|
128400
|
-
createCheckpoint(state, options = {}) {
|
|
128401
|
-
const {
|
|
128402
|
-
agentId,
|
|
128403
|
-
projectId,
|
|
128404
|
-
checkpointType = CheckpointType.MANUAL,
|
|
128405
|
-
memoryIds = [],
|
|
128406
|
-
fileChanges = [],
|
|
128407
|
-
parentCheckpointId,
|
|
128408
|
-
ttlMs = 7 * 24 * 60 * 60 * 1000
|
|
128409
|
-
} = options;
|
|
128410
|
-
const id = `ckpt_${checkpointType}_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
|
|
128411
|
-
const now2 = Date.now();
|
|
128412
|
-
const expiresAt = now2 + ttlMs;
|
|
128413
|
-
const checkpoint = {
|
|
128414
|
-
id,
|
|
128415
|
-
taskId: state.taskId,
|
|
128416
|
-
taskDescription: state.description,
|
|
128417
|
-
agentId,
|
|
128418
|
-
projectId,
|
|
128419
|
-
state,
|
|
128420
|
-
memoryIds,
|
|
128421
|
-
fileChanges,
|
|
128422
|
-
checkpointType,
|
|
128423
|
-
parentCheckpointId,
|
|
128424
|
-
createdAt: now2,
|
|
128425
|
-
expiresAt
|
|
128426
|
-
};
|
|
128427
|
-
this.mirror.set(id, checkpoint);
|
|
128428
|
-
this.ensureHydrated();
|
|
128429
|
-
this.chainWrite(id, async () => {
|
|
128430
|
-
const prisma2 = this.getClient();
|
|
128431
|
-
const canonicalProjectId = projectId ? await getProjectIdentityAliasResolver().resolve(projectId) : projectId;
|
|
128432
|
-
const compressed = compressState(state);
|
|
128433
|
-
await prisma2.$executeRaw`
|
|
128434
|
-
INSERT INTO task_checkpoints (
|
|
128435
|
-
id, task_id, task_description, agent_id, project_id,
|
|
128436
|
-
state, state_schema_version,
|
|
128437
|
-
memory_ids, file_changes,
|
|
128438
|
-
checkpoint_type, parent_checkpoint_id,
|
|
128439
|
-
created_at, expires_at
|
|
128440
|
-
) VALUES (
|
|
128441
|
-
${id},
|
|
128442
|
-
${state.taskId},
|
|
128443
|
-
${state.description ?? null},
|
|
128444
|
-
${agentId ?? null},
|
|
128445
|
-
${canonicalProjectId ?? null},
|
|
128446
|
-
${compressed},
|
|
128447
|
-
1,
|
|
128448
|
-
${JSON.stringify(memoryIds)},
|
|
128449
|
-
${JSON.stringify(fileChanges)},
|
|
128450
|
-
${checkpointType},
|
|
128451
|
-
${parentCheckpointId ?? null},
|
|
128452
|
-
${now2}::bigint,
|
|
128453
|
-
${expiresAt}::bigint
|
|
128454
|
-
)
|
|
128455
|
-
ON CONFLICT (id) DO UPDATE SET
|
|
128456
|
-
task_id = EXCLUDED.task_id,
|
|
128457
|
-
task_description = EXCLUDED.task_description,
|
|
128458
|
-
agent_id = EXCLUDED.agent_id,
|
|
128459
|
-
project_id = EXCLUDED.project_id,
|
|
128460
|
-
state = EXCLUDED.state,
|
|
128461
|
-
state_schema_version = EXCLUDED.state_schema_version,
|
|
128462
|
-
memory_ids = EXCLUDED.memory_ids,
|
|
128463
|
-
file_changes = EXCLUDED.file_changes,
|
|
128464
|
-
checkpoint_type = EXCLUDED.checkpoint_type,
|
|
128465
|
-
parent_checkpoint_id = EXCLUDED.parent_checkpoint_id,
|
|
128466
|
-
created_at = EXCLUDED.created_at,
|
|
128467
|
-
expires_at = EXCLUDED.expires_at
|
|
128468
|
-
`;
|
|
128469
|
-
});
|
|
128470
|
-
logger.info("Checkpoint created (PG)", {
|
|
128471
|
-
id,
|
|
128472
|
-
taskId: state.taskId,
|
|
128473
|
-
type: checkpointType,
|
|
128474
|
-
compressedBytes: compressState(state).byteLength
|
|
128475
|
-
});
|
|
128476
|
-
return checkpoint;
|
|
128477
|
-
}
|
|
128478
|
-
getCheckpoint(checkpointId) {
|
|
128479
|
-
this.ensureHydrated();
|
|
128480
|
-
return this.mirror.get(checkpointId) ?? null;
|
|
128481
|
-
}
|
|
128482
|
-
listCheckpoints(options = {}) {
|
|
128483
|
-
this.ensureHydrated();
|
|
128484
|
-
return this.applyFilters(this.mirror.values(), options);
|
|
128485
|
-
}
|
|
128486
|
-
listCheckpointsMetadata(options = {}) {
|
|
128487
|
-
this.ensureHydrated();
|
|
128488
|
-
const filtered = this.applyFilters(this.mirror.values(), options);
|
|
128489
|
-
return filtered.map((c) => this.checkpointToMetadata(c));
|
|
128490
|
-
}
|
|
128491
|
-
getCheckpointState(checkpointId) {
|
|
128492
|
-
this.ensureHydrated();
|
|
128493
|
-
const ckpt = this.mirror.get(checkpointId);
|
|
128494
|
-
return ckpt ? ckpt.state : null;
|
|
128495
|
-
}
|
|
128496
|
-
getLatestCheckpoint(taskId) {
|
|
128497
|
-
this.ensureHydrated();
|
|
128498
|
-
const now2 = Date.now();
|
|
128499
|
-
let latest = null;
|
|
128500
|
-
for (const ckpt of this.mirror.values()) {
|
|
128501
|
-
if (ckpt.taskId === taskId && (ckpt.expiresAt == null || ckpt.expiresAt > now2)) {
|
|
128502
|
-
if (!latest || ckpt.createdAt > latest.createdAt) {
|
|
128503
|
-
latest = ckpt;
|
|
128504
|
-
}
|
|
128505
|
-
}
|
|
128506
|
-
}
|
|
128507
|
-
return latest;
|
|
128508
|
-
}
|
|
128509
|
-
deleteCheckpoint(checkpointId) {
|
|
128510
|
-
const existed = this.mirror.has(checkpointId);
|
|
128511
|
-
this.mirror.delete(checkpointId);
|
|
128512
|
-
this.ensureHydrated();
|
|
128513
|
-
this.chainWrite(checkpointId, async () => {
|
|
128514
|
-
const prisma2 = this.getClient();
|
|
128515
|
-
await prisma2.$executeRaw`
|
|
128516
|
-
DELETE FROM task_checkpoints WHERE id = ${checkpointId}
|
|
128517
|
-
`;
|
|
128518
|
-
});
|
|
128519
|
-
return existed;
|
|
128520
|
-
}
|
|
128521
|
-
purgeExpired() {
|
|
128522
|
-
const now2 = Date.now();
|
|
128523
|
-
let count = 0;
|
|
128524
|
-
const toRemove = [];
|
|
128525
|
-
for (const ckpt of this.mirror.values()) {
|
|
128526
|
-
if (ckpt.expiresAt != null && ckpt.expiresAt < now2) {
|
|
128527
|
-
toRemove.push(ckpt.id);
|
|
128528
|
-
count++;
|
|
128529
|
-
}
|
|
128530
|
-
}
|
|
128531
|
-
for (const id of toRemove)
|
|
128532
|
-
this.mirror.delete(id);
|
|
128533
|
-
if (count > 0) {
|
|
128534
|
-
this.chainWrite("__purge__", async () => {
|
|
128535
|
-
const prisma2 = this.getClient();
|
|
128536
|
-
await prisma2.$executeRaw`
|
|
128537
|
-
DELETE FROM task_checkpoints
|
|
128538
|
-
WHERE expires_at IS NOT NULL AND expires_at < ${now2}::bigint
|
|
128539
|
-
`;
|
|
128540
|
-
});
|
|
128541
|
-
logger.info("Expired checkpoints purged (PG)", { count });
|
|
128542
|
-
}
|
|
128543
|
-
return count;
|
|
128544
|
-
}
|
|
128545
|
-
async countExistingMemoryIds(memoryIds) {
|
|
128546
|
-
if (memoryIds.length === 0)
|
|
128547
|
-
return [];
|
|
128548
|
-
this.ensureHydrated();
|
|
128549
|
-
const BATCH_SIZE = 1000;
|
|
128550
|
-
const existing = [];
|
|
128551
|
-
try {
|
|
128552
|
-
const prisma2 = this.getClient();
|
|
128553
|
-
for (let i = 0;i < memoryIds.length; i += BATCH_SIZE) {
|
|
128554
|
-
const batch = memoryIds.slice(i, i + BATCH_SIZE);
|
|
128555
|
-
const rows = await prisma2.$queryRaw`
|
|
128556
|
-
SELECT id FROM memories WHERE id IN (${import_prisma4.Prisma.join(batch)})
|
|
128557
|
-
`;
|
|
128558
|
-
for (const row of rows)
|
|
128559
|
-
existing.push(row.id);
|
|
128560
|
-
}
|
|
128561
|
-
return existing;
|
|
128562
|
-
} catch (e) {
|
|
128563
|
-
logger.warn("countExistingMemoryIds failed (best-effort: assuming all exist)", {
|
|
128564
|
-
error: e.message
|
|
128565
|
-
});
|
|
128566
|
-
return memoryIds;
|
|
128567
|
-
}
|
|
128568
|
-
}
|
|
128569
|
-
getStats() {
|
|
128570
|
-
this.ensureHydrated();
|
|
128571
|
-
const checkpoints = Array.from(this.mirror.values());
|
|
128572
|
-
const byType = {};
|
|
128573
|
-
let totalSizeBytes = 0;
|
|
128574
|
-
let oldest;
|
|
128575
|
-
for (const c of checkpoints) {
|
|
128576
|
-
byType[c.checkpointType] = (byType[c.checkpointType] ?? 0) + 1;
|
|
128577
|
-
totalSizeBytes += compressState(c.state).byteLength;
|
|
128578
|
-
if (oldest == null || c.createdAt < oldest)
|
|
128579
|
-
oldest = c.createdAt;
|
|
128580
|
-
}
|
|
128581
|
-
return {
|
|
128582
|
-
totalCheckpoints: checkpoints.length,
|
|
128583
|
-
byType,
|
|
128584
|
-
totalSizeBytes,
|
|
128585
|
-
oldestCheckpointAge: oldest != null ? Date.now() - oldest : undefined
|
|
128586
|
-
};
|
|
128587
|
-
}
|
|
128588
|
-
ensureReady() {
|
|
128589
|
-
return this.ensureHydrated();
|
|
128590
|
-
}
|
|
128591
|
-
close() {}
|
|
128592
|
-
applyFilters(iter, options) {
|
|
128593
|
-
const { taskId, projectId, checkpointType, includeExpired = false, limit = 20, offset = 0 } = options;
|
|
128594
|
-
const now2 = Date.now();
|
|
128595
|
-
const out = [];
|
|
128596
|
-
for (const c of iter) {
|
|
128597
|
-
if (taskId && c.taskId !== taskId)
|
|
128598
|
-
continue;
|
|
128599
|
-
if (projectId && c.projectId !== projectId)
|
|
128600
|
-
continue;
|
|
128601
|
-
if (checkpointType && c.checkpointType !== checkpointType)
|
|
128602
|
-
continue;
|
|
128603
|
-
if (!includeExpired && c.expiresAt != null && c.expiresAt <= now2)
|
|
128604
|
-
continue;
|
|
128605
|
-
out.push(c);
|
|
128606
|
-
}
|
|
128607
|
-
out.sort((a, b) => b.createdAt - a.createdAt);
|
|
128608
|
-
return out.slice(offset, offset + limit);
|
|
128609
|
-
}
|
|
128610
|
-
checkpointToMetadata(c) {
|
|
128611
|
-
return {
|
|
128612
|
-
id: c.id,
|
|
128613
|
-
taskId: c.taskId,
|
|
128614
|
-
taskDescription: c.taskDescription,
|
|
128615
|
-
agentId: c.agentId,
|
|
128616
|
-
projectId: c.projectId,
|
|
128617
|
-
checkpointType: c.checkpointType,
|
|
128618
|
-
parentCheckpointId: c.parentCheckpointId,
|
|
128619
|
-
createdAt: c.createdAt,
|
|
128620
|
-
expiresAt: c.expiresAt,
|
|
128621
|
-
compressedSizeBytes: compressState(c.state).byteLength,
|
|
128622
|
-
memoryCount: c.memoryIds.length,
|
|
128623
|
-
fileChangeCount: c.fileChanges.length
|
|
128624
|
-
};
|
|
128625
|
-
}
|
|
128626
|
-
chainWrite(key, fn) {
|
|
128627
|
-
const prev = this.inflight.get(key) ?? Promise.resolve();
|
|
128628
|
-
const next = prev.then(fn).catch((e) => {
|
|
128629
|
-
logger.warn("PgCheckpointStore write failed (best-effort)", {
|
|
128630
|
-
key,
|
|
128631
|
-
error: e.message
|
|
128632
|
-
});
|
|
128633
|
-
});
|
|
128634
|
-
this.inflight.set(key, next);
|
|
128635
|
-
next.then(() => {
|
|
128636
|
-
if (this.inflight.get(key) === next)
|
|
128637
|
-
this.inflight.delete(key);
|
|
128638
|
-
});
|
|
128639
|
-
}
|
|
128640
|
-
async __drain() {
|
|
128641
|
-
const pending = Array.from(this.inflight.values());
|
|
128642
|
-
if (pending.length > 0)
|
|
128643
|
-
await Promise.allSettled(pending);
|
|
128644
|
-
await new Promise((r) => setTimeout(r, 10));
|
|
128645
|
-
}
|
|
128646
|
-
async __hydrate() {
|
|
128647
|
-
await this.ensureHydrated();
|
|
128648
|
-
}
|
|
128649
|
-
}
|
|
128650
|
-
var import_prisma4, SUPPORTED_CHECKPOINT_STATE_SCHEMA_VERSION = "1.0.0";
|
|
128651
|
-
var init_checkpoint_store_pg = __esm(() => {
|
|
128652
|
-
init_dist();
|
|
128653
|
-
init_prisma_client();
|
|
128654
|
-
init_alias_resolver();
|
|
128655
|
-
init_schema_version();
|
|
128656
|
-
import_prisma4 = __toESM(require_prisma(), 1);
|
|
128657
|
-
});
|
|
128658
|
-
|
|
128659
|
-
// ../../packages/core/dist/services/checkpoint/checkpoint-manager.js
|
|
128660
|
-
var CheckpointManager;
|
|
128661
|
-
var init_checkpoint_manager = __esm(() => {
|
|
128662
|
-
init_config();
|
|
128663
|
-
init_checkpoint_store_pg();
|
|
128664
|
-
CheckpointManager = class CheckpointManager extends PgCheckpointStore {
|
|
128665
|
-
static instance = null;
|
|
128666
|
-
static getInstance() {
|
|
128667
|
-
requirePostgresDatabaseUrl();
|
|
128668
|
-
return this.instance ??= new CheckpointManager;
|
|
128669
|
-
}
|
|
128670
|
-
async restoreCheckpoint(checkpointId) {
|
|
128671
|
-
const checkpoint = this.getCheckpoint(checkpointId);
|
|
128672
|
-
if (!checkpoint)
|
|
128673
|
-
return null;
|
|
128674
|
-
const existing = new Set(await this.countExistingMemoryIds(checkpoint.memoryIds));
|
|
128675
|
-
const validMemoryIds = checkpoint.memoryIds.filter((id) => existing.has(id));
|
|
128676
|
-
const missingMemoryIds = checkpoint.memoryIds.filter((id) => !existing.has(id));
|
|
128677
|
-
const fileConflicts = [];
|
|
128678
|
-
const restoreInstructions = [
|
|
128679
|
-
`Restore checkpoint ${checkpoint.id} for task ${checkpoint.taskId}.`,
|
|
128680
|
-
missingMemoryIds.length ? `Missing memories: ${missingMemoryIds.join(", ")}.` : "All referenced memories are available."
|
|
128681
|
-
].join(`
|
|
128682
|
-
`);
|
|
128683
|
-
return { checkpoint, validMemoryIds, missingMemoryIds, fileConflicts, restoreInstructions };
|
|
128684
|
-
}
|
|
128685
|
-
};
|
|
128686
|
-
});
|
|
128687
|
-
|
|
128688
128813
|
// ../../packages/core/dist/services/checkpoint/auto-checkpointer.js
|
|
128689
128814
|
class AutoCheckpointer {
|
|
128690
128815
|
operationCount = 0;
|
|
@@ -128789,7 +128914,7 @@ function stripNul(content) {
|
|
|
128789
128914
|
}
|
|
128790
128915
|
|
|
128791
128916
|
// ../../packages/core/dist/services/etl/stages/discover.js
|
|
128792
|
-
import
|
|
128917
|
+
import fs12 from "fs/promises";
|
|
128793
128918
|
import path17 from "path";
|
|
128794
128919
|
import { createHash as createHash8 } from "crypto";
|
|
128795
128920
|
|
|
@@ -128877,8 +129002,8 @@ class DiscoverStage {
|
|
|
128877
129002
|
async processFile(ctx, relativePath, forceReindex) {
|
|
128878
129003
|
const absolutePath = path17.join(ctx.projectPath, relativePath);
|
|
128879
129004
|
try {
|
|
128880
|
-
const stat = await
|
|
128881
|
-
const content = stripNul(await
|
|
129005
|
+
const stat = await fs12.stat(absolutePath);
|
|
129006
|
+
const content = stripNul(await fs12.readFile(absolutePath, "utf-8"));
|
|
128882
129007
|
const contentHash = createHash8("sha256").update(content).digest("hex");
|
|
128883
129008
|
let needsReparse = forceReindex;
|
|
128884
129009
|
if (!forceReindex) {
|
|
@@ -128922,7 +129047,7 @@ class DiscoverStage {
|
|
|
128922
129047
|
}
|
|
128923
129048
|
try {
|
|
128924
129049
|
const gitignorePath = path17.join(projectPath, ".gitignore");
|
|
128925
|
-
const gitignoreContent = await
|
|
129050
|
+
const gitignoreContent = await fs12.readFile(gitignorePath, "utf8");
|
|
128926
129051
|
const rules = gitignoreContent.split(`
|
|
128927
129052
|
`).map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
|
|
128928
129053
|
ig.add(rules);
|
|
@@ -131251,7 +131376,7 @@ var init_structural_runtime = __esm(() => {
|
|
|
131251
131376
|
|
|
131252
131377
|
// ../../packages/core/dist/services/etl/stages/parse.js
|
|
131253
131378
|
import path18 from "path";
|
|
131254
|
-
import
|
|
131379
|
+
import fs13 from "fs/promises";
|
|
131255
131380
|
function resolveChunkerMaxChars() {
|
|
131256
131381
|
const global2 = Number(process.env.EMBEDDING_MAX_CHARS);
|
|
131257
131382
|
if (Number.isFinite(global2) && global2 > 0)
|
|
@@ -131343,7 +131468,7 @@ class ParseStage {
|
|
|
131343
131468
|
if (!file2.needsReparse) {
|
|
131344
131469
|
const extension = path18.extname(file2.relativePath).toLowerCase();
|
|
131345
131470
|
if ([".c", ".cpp", ".hpp"].includes(extension)) {
|
|
131346
|
-
const content = file2.snapshotContent ?? await
|
|
131471
|
+
const content = file2.snapshotContent ?? await fs13.readFile(file2.absolutePath, "utf8");
|
|
131347
131472
|
const outcome = await this.runtime.parse({ extension, source: Buffer.from(content) });
|
|
131348
131473
|
if (outcome.status === "failed")
|
|
131349
131474
|
throw new StructuralEtlParseError(file2.relativePath, outcome.failureKind, `Structural evidence parse failed (${outcome.failureKind})`, outcome.diagnosticCount, outcome.diagnostics.slice(0, 10));
|
|
@@ -131355,7 +131480,7 @@ class ParseStage {
|
|
|
131355
131480
|
return { file: file2, chunks: [], symbols: [], rawImports: [], rawEdges: [] };
|
|
131356
131481
|
}
|
|
131357
131482
|
try {
|
|
131358
|
-
const content = file2.snapshotContent ?? await
|
|
131483
|
+
const content = file2.snapshotContent ?? await fs13.readFile(file2.absolutePath, "utf-8");
|
|
131359
131484
|
const ext2 = path18.extname(file2.relativePath).toLowerCase();
|
|
131360
131485
|
const chunkerMaxChars = resolveChunkerMaxChars();
|
|
131361
131486
|
const chunks = smartChunk(content, file2.relativePath, chunkerMaxChars ? { maxChunkChars: chunkerMaxChars } : {});
|
|
@@ -132396,7 +132521,7 @@ var init_data_document2 = __esm(() => {
|
|
|
132396
132521
|
|
|
132397
132522
|
// ../../packages/core/dist/services/etl/stages/resolve.js
|
|
132398
132523
|
import path21 from "path";
|
|
132399
|
-
import
|
|
132524
|
+
import fs14 from "fs";
|
|
132400
132525
|
|
|
132401
132526
|
class ResolveStage {
|
|
132402
132527
|
symbolRepository;
|
|
@@ -132713,7 +132838,7 @@ class ResolveStage {
|
|
|
132713
132838
|
const aliases = [];
|
|
132714
132839
|
const tsconfigPath = path21.join(projectPath, "tsconfig.json");
|
|
132715
132840
|
try {
|
|
132716
|
-
const raw2 =
|
|
132841
|
+
const raw2 = fs14.readFileSync(tsconfigPath, "utf-8");
|
|
132717
132842
|
const stripped = raw2.replace(/\/\/[^\n]*/g, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
132718
132843
|
const tsconfig = JSON.parse(stripped);
|
|
132719
132844
|
const paths = tsconfig?.compilerOptions?.paths ?? {};
|
|
@@ -151921,6 +152046,7 @@ var init_services = __esm(() => {
|
|
|
151921
152046
|
init_search_analytics_pg();
|
|
151922
152047
|
init_index_manager();
|
|
151923
152048
|
init_search_diagnostics();
|
|
152049
|
+
init_safe_error_summary();
|
|
151924
152050
|
init_memory_controller();
|
|
151925
152051
|
init_llm_client();
|
|
151926
152052
|
init_search_controller();
|