@atbash/sdk 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.d.mts +199 -21
- package/dist/browser.mjs +753 -318
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts +199 -21
- package/dist/index.d.ts +199 -21
- package/dist/index.js +457 -68
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +446 -68
- package/dist/index.mjs.map +1 -1
- package/index.js +52 -52
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -2860,14 +2860,23 @@ __export(src_ts_exports, {
|
|
|
2860
2860
|
DEFAULT_CHROMIA_NODE_URLS: () => DEFAULT_CHROMIA_NODE_URLS,
|
|
2861
2861
|
DEFAULT_ENDPOINT: () => DEFAULT_ENDPOINT,
|
|
2862
2862
|
DEFAULT_MEMORY_PATH_PATTERNS: () => DEFAULT_MEMORY_PATH_PATTERNS,
|
|
2863
|
+
DEFAULT_MEMORY_READ_TOOL_NAMES: () => DEFAULT_MEMORY_READ_TOOL_NAMES,
|
|
2863
2864
|
DEFAULT_MEMORY_WRITE_TOOL_NAMES: () => DEFAULT_MEMORY_WRITE_TOOL_NAMES,
|
|
2865
|
+
MemoryGuardManager: () => MemoryGuardManager,
|
|
2866
|
+
MemoryIntegrityError: () => MemoryIntegrityError,
|
|
2867
|
+
PointerStore: () => PointerStore,
|
|
2864
2868
|
SignatureVerificationError: () => SignatureVerificationError,
|
|
2869
|
+
classifyMemoryRead: () => classifyMemoryRead,
|
|
2865
2870
|
classifyMemoryWrite: () => classifyMemoryWrite,
|
|
2866
2871
|
commitMemoryVersion: () => commitMemoryVersion,
|
|
2867
2872
|
containsEvasionCharacters: () => containsEvasionCharacters,
|
|
2868
2873
|
containsSecret: () => containsSecret,
|
|
2874
|
+
createFileLogger: () => createFileLogger,
|
|
2875
|
+
createMemoryGuardManager: () => createMemoryGuardManager,
|
|
2869
2876
|
createMemorySnapshot: () => createMemorySnapshot,
|
|
2870
2877
|
decryptMemoryContent: () => decryptMemoryContent,
|
|
2878
|
+
defaultPluginLogPath: () => defaultPluginLogPath,
|
|
2879
|
+
defaultPointerPath: () => defaultPointerPath,
|
|
2871
2880
|
deriveMemoryKey: () => deriveMemoryKey,
|
|
2872
2881
|
derivePublicKey: () => derivePublicKey,
|
|
2873
2882
|
diffMemorySnapshots: () => diffMemorySnapshots,
|
|
@@ -2875,6 +2884,7 @@ __export(src_ts_exports, {
|
|
|
2875
2884
|
flushTelemetry: () => flushTelemetry,
|
|
2876
2885
|
generateKeypair: () => generateKeypair,
|
|
2877
2886
|
getActiveMemory: () => getActiveMemory,
|
|
2887
|
+
getActiveMemoryId: () => getActiveMemoryId,
|
|
2878
2888
|
getAllAgentMemory: () => getAllAgentMemory,
|
|
2879
2889
|
getConfigDir: () => getConfigDir,
|
|
2880
2890
|
getConfigPath: () => getConfigPath,
|
|
@@ -2904,6 +2914,7 @@ __export(src_ts_exports, {
|
|
|
2904
2914
|
shutdownTelemetry: () => shutdownTelemetry,
|
|
2905
2915
|
signJudgeAction: () => signJudgeAction,
|
|
2906
2916
|
signLogToolCall: () => signLogToolCall,
|
|
2917
|
+
syncLocalMemory: () => syncLocalMemory,
|
|
2907
2918
|
validateJudgeEndpoint: () => validateJudgeEndpoint,
|
|
2908
2919
|
verifyJudgeResponseSignature: () => verifyJudgeResponseSignature,
|
|
2909
2920
|
verifySignature: () => verifySignature
|
|
@@ -3054,8 +3065,8 @@ var HttpClient = class {
|
|
|
3054
3065
|
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
3055
3066
|
this.timeoutMs = timeoutMs;
|
|
3056
3067
|
}
|
|
3057
|
-
buildUrl(
|
|
3058
|
-
const url = new URL(this.baseUrl +
|
|
3068
|
+
buildUrl(path6, query) {
|
|
3069
|
+
const url = new URL(this.baseUrl + path6);
|
|
3059
3070
|
if (query) {
|
|
3060
3071
|
for (const [k, v] of Object.entries(query)) {
|
|
3061
3072
|
if (v !== void 0 && v !== null && v !== "") {
|
|
@@ -3065,14 +3076,14 @@ var HttpClient = class {
|
|
|
3065
3076
|
}
|
|
3066
3077
|
return url.toString();
|
|
3067
3078
|
}
|
|
3068
|
-
async get(
|
|
3069
|
-
return this.fetch(this.buildUrl(
|
|
3079
|
+
async get(path6, query, headers) {
|
|
3080
|
+
return this.fetch(this.buildUrl(path6, query), {
|
|
3070
3081
|
method: "GET",
|
|
3071
3082
|
...headers && { headers }
|
|
3072
3083
|
});
|
|
3073
3084
|
}
|
|
3074
|
-
async post(
|
|
3075
|
-
return this.fetch(this.buildUrl(
|
|
3085
|
+
async post(path6, body, headers) {
|
|
3086
|
+
return this.fetch(this.buildUrl(path6), {
|
|
3076
3087
|
method: "POST",
|
|
3077
3088
|
headers: { "Content-Type": "application/json", ...headers },
|
|
3078
3089
|
body: JSON.stringify(body)
|
|
@@ -3376,13 +3387,22 @@ var Atbash = class _Atbash {
|
|
|
3376
3387
|
return this.auth.privkey;
|
|
3377
3388
|
}
|
|
3378
3389
|
/* ── agent existence (/api/ai/exists) ──────────────────────────────────── */
|
|
3379
|
-
/**
|
|
3380
|
-
|
|
3390
|
+
/**
|
|
3391
|
+
* `GET /api/ai/exists?pubkey=…[&network=…]` — defaults to this client's
|
|
3392
|
+
* pubkey. Pass `opts.network` when the caller already knows which
|
|
3393
|
+
* network the agent lives on (e.g. after resolving via `orgName`) so
|
|
3394
|
+
* the dashboard queries that chain directly instead of falling back
|
|
3395
|
+
* across public → private, which double-round-trips and can return
|
|
3396
|
+
* false negatives when the fallback chain client is misconfigured.
|
|
3397
|
+
*/
|
|
3398
|
+
async checkAgentExists(pubkey, opts) {
|
|
3381
3399
|
const pk = pubkey ?? this.auth.pubkey;
|
|
3382
3400
|
return this.track("checkAgentExists", pk, async () => {
|
|
3401
|
+
const query = { pubkey: pk };
|
|
3402
|
+
if (opts?.network) query.network = opts.network;
|
|
3383
3403
|
const resp = await this.http.get(
|
|
3384
3404
|
"/api/ai/exists",
|
|
3385
|
-
|
|
3405
|
+
query,
|
|
3386
3406
|
this.authHeaders()
|
|
3387
3407
|
);
|
|
3388
3408
|
await this.raiseIfError(resp);
|
|
@@ -3400,7 +3420,9 @@ var Atbash = class _Atbash {
|
|
|
3400
3420
|
recordCall("logToolCall", void 0, this.auth.pubkey);
|
|
3401
3421
|
let exists;
|
|
3402
3422
|
try {
|
|
3403
|
-
exists = await this.checkAgentExists(
|
|
3423
|
+
exists = await this.checkAgentExists(this.auth.pubkey, {
|
|
3424
|
+
network: options.chainOpts?.network
|
|
3425
|
+
});
|
|
3404
3426
|
} catch (err) {
|
|
3405
3427
|
recordDuration("logToolCall", performance.now() - start, "error");
|
|
3406
3428
|
return { success: false, toolCallId: null, error: errorMessage(err) };
|
|
@@ -3414,7 +3436,7 @@ var Atbash = class _Atbash {
|
|
|
3414
3436
|
};
|
|
3415
3437
|
}
|
|
3416
3438
|
const toolCallId = generateToolCallId();
|
|
3417
|
-
const brid = options.chainOpts
|
|
3439
|
+
const brid = this.bridFromChainOpts(options.chainOpts);
|
|
3418
3440
|
try {
|
|
3419
3441
|
const signedHex = native.signLogToolCall(
|
|
3420
3442
|
toolCallId,
|
|
@@ -3525,6 +3547,8 @@ var Atbash = class _Atbash {
|
|
|
3525
3547
|
}
|
|
3526
3548
|
}
|
|
3527
3549
|
const data = parseJson(bodyBytes);
|
|
3550
|
+
const rawScore = data.score;
|
|
3551
|
+
const score = typeof rawScore === "number" && Number.isInteger(rawScore) && rawScore >= 1 && rawScore <= 10 ? rawScore : void 0;
|
|
3528
3552
|
return {
|
|
3529
3553
|
verdict: normalizeVerdict(data.verdict),
|
|
3530
3554
|
actionType: String(data.action_type ?? ""),
|
|
@@ -3535,7 +3559,8 @@ var Atbash = class _Atbash {
|
|
|
3535
3559
|
toolCallId: String(data.tool_call_id ?? logResult.toolCallId),
|
|
3536
3560
|
onChain: Boolean(data.on_chain),
|
|
3537
3561
|
enforced: Boolean(data.enforced),
|
|
3538
|
-
enforcementMode: String(data.enforcement_mode ?? "")
|
|
3562
|
+
enforcementMode: String(data.enforcement_mode ?? ""),
|
|
3563
|
+
score
|
|
3539
3564
|
};
|
|
3540
3565
|
}
|
|
3541
3566
|
/* ── audit_tool_call (redact → judge → decision) ───────────────────────── */
|
|
@@ -4163,13 +4188,13 @@ function verifyJudgeResponseSignature(bodyBytes, signatureHex, pubKeyHex) {
|
|
|
4163
4188
|
}
|
|
4164
4189
|
|
|
4165
4190
|
// src-ts/memory/crypto.ts
|
|
4166
|
-
function deriveMemoryKey(privkey) {
|
|
4191
|
+
async function deriveMemoryKey(privkey) {
|
|
4167
4192
|
return native.deriveMemoryKey(privkey);
|
|
4168
4193
|
}
|
|
4169
|
-
function encryptMemoryContent(plaintext, key3) {
|
|
4194
|
+
async function encryptMemoryContent(plaintext, key3) {
|
|
4170
4195
|
return native.encryptMemoryContent(plaintext, key3);
|
|
4171
4196
|
}
|
|
4172
|
-
function decryptMemoryContent(ciphertext, nonce, key3) {
|
|
4197
|
+
async function decryptMemoryContent(ciphertext, nonce, key3) {
|
|
4173
4198
|
return native.decryptMemoryContent(ciphertext, nonce, key3);
|
|
4174
4199
|
}
|
|
4175
4200
|
|
|
@@ -4263,7 +4288,7 @@ async function scanMemory(entry, auth, opts) {
|
|
|
4263
4288
|
});
|
|
4264
4289
|
const verdict = mapVerdict(result.actionType, result.confidence, threshold);
|
|
4265
4290
|
const { score: parsedScore, cleanReason } = parseScoreFromReason(result.reason);
|
|
4266
|
-
const score = parsedScore ?? defaultScoreForVerdict(verdict);
|
|
4291
|
+
const score = result.score ?? parsedScore ?? defaultScoreForVerdict(verdict);
|
|
4267
4292
|
if (prefilter && prefilter.verdict === "yellow" && verdict === "green") {
|
|
4268
4293
|
return {
|
|
4269
4294
|
safe: false,
|
|
@@ -9177,8 +9202,8 @@ Reporter$3.prototype.wrapResult = function wrapResult(result) {
|
|
|
9177
9202
|
errors: state2.errors
|
|
9178
9203
|
};
|
|
9179
9204
|
};
|
|
9180
|
-
function ReporterError$1(
|
|
9181
|
-
this.path =
|
|
9205
|
+
function ReporterError$1(path6, msg) {
|
|
9206
|
+
this.path = path6;
|
|
9182
9207
|
this.rethrow(msg);
|
|
9183
9208
|
}
|
|
9184
9209
|
inherits$v(ReporterError$1, Error);
|
|
@@ -29399,8 +29424,8 @@ Reporter.prototype.wrapResult = function wrapResult2(result) {
|
|
|
29399
29424
|
errors: state2.errors
|
|
29400
29425
|
};
|
|
29401
29426
|
};
|
|
29402
|
-
function ReporterError(
|
|
29403
|
-
this.path =
|
|
29427
|
+
function ReporterError(path6, msg) {
|
|
29428
|
+
this.path = path6;
|
|
29404
29429
|
this.rethrow(msg);
|
|
29405
29430
|
}
|
|
29406
29431
|
inherits(ReporterError, Error);
|
|
@@ -32430,8 +32455,8 @@ var parseUtil = {};
|
|
|
32430
32455
|
const errors_js_12 = errors$3;
|
|
32431
32456
|
const en_js_12 = __importDefault2(en);
|
|
32432
32457
|
const makeIssue = (params) => {
|
|
32433
|
-
const { data, path:
|
|
32434
|
-
const fullPath = [...
|
|
32458
|
+
const { data, path: path6, errorMaps, issueData } = params;
|
|
32459
|
+
const fullPath = [...path6, ...issueData.path || []];
|
|
32435
32460
|
const fullIssue = {
|
|
32436
32461
|
...issueData,
|
|
32437
32462
|
path: fullPath
|
|
@@ -32568,11 +32593,11 @@ var errorUtil_js_1 = errorUtil$1;
|
|
|
32568
32593
|
var parseUtil_js_1 = parseUtil;
|
|
32569
32594
|
var util_js_1 = util;
|
|
32570
32595
|
var ParseInputLazyPath = class {
|
|
32571
|
-
constructor(parent, value,
|
|
32596
|
+
constructor(parent, value, path6, key3) {
|
|
32572
32597
|
this._cachedPath = [];
|
|
32573
32598
|
this.parent = parent;
|
|
32574
32599
|
this.data = value;
|
|
32575
|
-
this._path =
|
|
32600
|
+
this._path = path6;
|
|
32576
32601
|
this._key = key3;
|
|
32577
32602
|
}
|
|
32578
32603
|
get path() {
|
|
@@ -39478,21 +39503,21 @@ function createTimeoutController(timeout) {
|
|
|
39478
39503
|
const timeoutId = setTimeout(() => controller.abort(timeoutError), timeout);
|
|
39479
39504
|
return { controller, timeoutId };
|
|
39480
39505
|
}
|
|
39481
|
-
function handleRequest(method,
|
|
39506
|
+
function handleRequest(method, path6, endpoint, timeout, postObject) {
|
|
39482
39507
|
return __awaiter$2(this, void 0, void 0, function* () {
|
|
39483
39508
|
if (method == enums_1$2.Method.GET) {
|
|
39484
|
-
return yield get(
|
|
39509
|
+
return yield get(path6, endpoint, timeout);
|
|
39485
39510
|
} else {
|
|
39486
|
-
return yield post(
|
|
39511
|
+
return yield post(path6, endpoint, timeout, postObject);
|
|
39487
39512
|
}
|
|
39488
39513
|
});
|
|
39489
39514
|
}
|
|
39490
|
-
function get(
|
|
39515
|
+
function get(path6, endpoint, timeout) {
|
|
39491
39516
|
return __awaiter$2(this, void 0, void 0, function* () {
|
|
39492
|
-
logger.debug(`GET URL ${new URL(
|
|
39517
|
+
logger.debug(`GET URL ${new URL(path6, endpoint).href}`);
|
|
39493
39518
|
try {
|
|
39494
39519
|
const { controller, timeoutId } = createTimeoutController(timeout);
|
|
39495
|
-
const response = yield fetch(new URL(
|
|
39520
|
+
const response = yield fetch(new URL(path6, endpoint).href, {
|
|
39496
39521
|
signal: controller === null || controller === void 0 ? void 0 : controller.signal
|
|
39497
39522
|
});
|
|
39498
39523
|
if (timeoutId)
|
|
@@ -39530,9 +39555,9 @@ function constructBufferResponseBody(response) {
|
|
|
39530
39555
|
return responseText ? responseText : response.statusText;
|
|
39531
39556
|
});
|
|
39532
39557
|
}
|
|
39533
|
-
function post(
|
|
39558
|
+
function post(path6, endpoint, timeout, requestBody) {
|
|
39534
39559
|
return __awaiter$2(this, void 0, void 0, function* () {
|
|
39535
|
-
logger.debug(`POST URL ${new URL(
|
|
39560
|
+
logger.debug(`POST URL ${new URL(path6, endpoint).href}`);
|
|
39536
39561
|
logger.debug(`POST body ${JSON.stringify(requestBody)}`);
|
|
39537
39562
|
if (buffer_1.Buffer.isBuffer(requestBody)) {
|
|
39538
39563
|
try {
|
|
@@ -39546,7 +39571,7 @@ function post(path3, endpoint, timeout, requestBody) {
|
|
|
39546
39571
|
},
|
|
39547
39572
|
signal: controller === null || controller === void 0 ? void 0 : controller.signal
|
|
39548
39573
|
};
|
|
39549
|
-
const response = yield fetch(new URL(
|
|
39574
|
+
const response = yield fetch(new URL(path6, endpoint).href, requestOptions);
|
|
39550
39575
|
if (timeoutId)
|
|
39551
39576
|
clearTimeout(timeoutId);
|
|
39552
39577
|
const transactionTimestamp = response.headers.get("X-Transaction-Timestamp");
|
|
@@ -39557,7 +39582,7 @@ function post(path3, endpoint, timeout, requestBody) {
|
|
|
39557
39582
|
} else {
|
|
39558
39583
|
try {
|
|
39559
39584
|
const { controller, timeoutId } = createTimeoutController(timeout);
|
|
39560
|
-
const response = yield fetch(new URL(
|
|
39585
|
+
const response = yield fetch(new URL(path6, endpoint).href, {
|
|
39561
39586
|
method: "post",
|
|
39562
39587
|
body: JSON.stringify(requestBody),
|
|
39563
39588
|
headers: {
|
|
@@ -39737,10 +39762,10 @@ function requireFailoverStrategies() {
|
|
|
39737
39762
|
}
|
|
39738
39763
|
}
|
|
39739
39764
|
function abortOnError(_a2) {
|
|
39740
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
39765
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path6, config: config2, postObject, timeoutOverride }) {
|
|
39741
39766
|
return yield retryRequest({
|
|
39742
39767
|
method,
|
|
39743
|
-
path:
|
|
39768
|
+
path: path6,
|
|
39744
39769
|
config: config2,
|
|
39745
39770
|
postObject,
|
|
39746
39771
|
timeoutOverride,
|
|
@@ -39751,10 +39776,10 @@ function requireFailoverStrategies() {
|
|
|
39751
39776
|
});
|
|
39752
39777
|
}
|
|
39753
39778
|
function tryNextOnError(_a2) {
|
|
39754
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
39779
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path6, config: config2, postObject, timeoutOverride }) {
|
|
39755
39780
|
return yield retryRequest({
|
|
39756
39781
|
method,
|
|
39757
|
-
path:
|
|
39782
|
+
path: path6,
|
|
39758
39783
|
config: config2,
|
|
39759
39784
|
postObject,
|
|
39760
39785
|
timeoutOverride,
|
|
@@ -39770,7 +39795,7 @@ function requireFailoverStrategies() {
|
|
|
39770
39795
|
return endpointPoolLength - (endpointPoolLength - 1) / 3;
|
|
39771
39796
|
}
|
|
39772
39797
|
function queryMajority(_a2) {
|
|
39773
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
39798
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path6, config: config2, postObject, timeoutOverride }) {
|
|
39774
39799
|
var _b;
|
|
39775
39800
|
const bftMajorityThreshold = calculateBftMajorityThreshold(config2.endpointPool.length);
|
|
39776
39801
|
const failureThreshold = config2.endpointPool.length - bftMajorityThreshold + 1;
|
|
@@ -39781,7 +39806,7 @@ function requireFailoverStrategies() {
|
|
|
39781
39806
|
const promises = availableNodes.map((node2) => __awaiter2(this, void 0, void 0, function* () {
|
|
39782
39807
|
try {
|
|
39783
39808
|
const requestTimeout = timeoutOverride !== null && timeoutOverride !== void 0 ? timeoutOverride : config2.responseTimeout;
|
|
39784
|
-
const response = yield (0, httpUtil_1.handleRequest)(method,
|
|
39809
|
+
const response = yield (0, httpUtil_1.handleRequest)(method, path6, node2.url, requestTimeout, postObject);
|
|
39785
39810
|
const { statusCode } = response;
|
|
39786
39811
|
if (statusCode && (0, http_utils_1.isSuccessfulStatusCode)(statusCode)) {
|
|
39787
39812
|
outcomes.push({ type: "SUCCESS", result: response });
|
|
@@ -39828,7 +39853,7 @@ function requireFailoverStrategies() {
|
|
|
39828
39853
|
});
|
|
39829
39854
|
}
|
|
39830
39855
|
function singleEndpoint(_a2) {
|
|
39831
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
39856
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path6, config: config2, postObject, timeoutOverride }) {
|
|
39832
39857
|
let statusCode = null;
|
|
39833
39858
|
let rspBody = null;
|
|
39834
39859
|
let error4 = null;
|
|
@@ -39839,7 +39864,7 @@ function requireFailoverStrategies() {
|
|
|
39839
39864
|
}
|
|
39840
39865
|
for (let attempt = 0; attempt < config2.attemptsPerEndpoint; attempt++) {
|
|
39841
39866
|
const requestTimeout = timeoutOverride !== null && timeoutOverride !== void 0 ? timeoutOverride : config2.responseTimeout;
|
|
39842
|
-
const response = yield (0, httpUtil_1.handleRequest)(method,
|
|
39867
|
+
const response = yield (0, httpUtil_1.handleRequest)(method, path6, endpoint.url, requestTimeout, postObject);
|
|
39843
39868
|
if (response) {
|
|
39844
39869
|
({ error: error4, statusCode, rspBody, transactionTimestamp } = response);
|
|
39845
39870
|
}
|
|
@@ -39854,7 +39879,7 @@ function requireFailoverStrategies() {
|
|
|
39854
39879
|
});
|
|
39855
39880
|
}
|
|
39856
39881
|
function retryRequest(_a2) {
|
|
39857
|
-
return __awaiter2(this, arguments, void 0, function* ({ method, path:
|
|
39882
|
+
return __awaiter2(this, arguments, void 0, function* ({ method, path: path6, config: config2, postObject, useNextNodeOnError, recoveryThreshold, timeoutOverride }) {
|
|
39858
39883
|
var _b, _c, _d;
|
|
39859
39884
|
let statusCode = null;
|
|
39860
39885
|
let rspBody = null;
|
|
@@ -39865,7 +39890,7 @@ function requireFailoverStrategies() {
|
|
|
39865
39890
|
for (const node2 of availableNodes) {
|
|
39866
39891
|
for (let attempt = 0; attempt < config2.attemptsPerEndpoint; attempt++) {
|
|
39867
39892
|
const requestTimeout = timeoutOverride !== null && timeoutOverride !== void 0 ? timeoutOverride : config2.responseTimeout;
|
|
39868
|
-
const response = yield (0, httpUtil_1.handleRequest)(method,
|
|
39893
|
+
const response = yield (0, httpUtil_1.handleRequest)(method, path6, node2.url, requestTimeout, postObject);
|
|
39869
39894
|
error4 = (_b = response === null || response === void 0 ? void 0 : response.error) !== null && _b !== void 0 ? _b : null;
|
|
39870
39895
|
statusCode = (_c = response === null || response === void 0 ? void 0 : response.statusCode) !== null && _c !== void 0 ? _c : null;
|
|
39871
39896
|
rspBody = (_d = response === null || response === void 0 ? void 0 : response.rspBody) !== null && _d !== void 0 ? _d : null;
|
|
@@ -40008,19 +40033,19 @@ function requireRequestWithFailoverStrategy() {
|
|
|
40008
40033
|
const enums_12 = enums;
|
|
40009
40034
|
const failoverStrategies_1 = requireFailoverStrategies();
|
|
40010
40035
|
function requestWithFailoverStrategy$1(method_1, path_1, config_1, postObject_1) {
|
|
40011
|
-
return __awaiter2(this, arguments, void 0, function* (method,
|
|
40036
|
+
return __awaiter2(this, arguments, void 0, function* (method, path6, config2, postObject, forceSingleEndpoint = false, timeoutOverride) {
|
|
40012
40037
|
switch (config2.failoverStrategy) {
|
|
40013
40038
|
case enums_12.FailoverStrategy.AbortOnError:
|
|
40014
|
-
return yield (0, failoverStrategies_1.abortOnError)({ method, path:
|
|
40039
|
+
return yield (0, failoverStrategies_1.abortOnError)({ method, path: path6, config: config2, postObject, timeoutOverride });
|
|
40015
40040
|
case enums_12.FailoverStrategy.TryNextOnError:
|
|
40016
|
-
return yield (0, failoverStrategies_1.tryNextOnError)({ method, path:
|
|
40041
|
+
return yield (0, failoverStrategies_1.tryNextOnError)({ method, path: path6, config: config2, postObject, timeoutOverride });
|
|
40017
40042
|
case enums_12.FailoverStrategy.SingleEndpoint:
|
|
40018
|
-
return yield (0, failoverStrategies_1.singleEndpoint)({ method, path:
|
|
40043
|
+
return yield (0, failoverStrategies_1.singleEndpoint)({ method, path: path6, config: config2, postObject, timeoutOverride });
|
|
40019
40044
|
case enums_12.FailoverStrategy.QueryMajority:
|
|
40020
40045
|
if (forceSingleEndpoint) {
|
|
40021
|
-
return yield (0, failoverStrategies_1.singleEndpoint)({ method, path:
|
|
40046
|
+
return yield (0, failoverStrategies_1.singleEndpoint)({ method, path: path6, config: config2, postObject, timeoutOverride });
|
|
40022
40047
|
}
|
|
40023
|
-
return yield (0, failoverStrategies_1.queryMajority)({ method, path:
|
|
40048
|
+
return yield (0, failoverStrategies_1.queryMajority)({ method, path: path6, config: config2, postObject, timeoutOverride });
|
|
40024
40049
|
default:
|
|
40025
40050
|
throw new Error(`Unsupported failover strategy: ${config2.failoverStrategy}`);
|
|
40026
40051
|
}
|
|
@@ -41219,7 +41244,7 @@ var networkSettings = {};
|
|
|
41219
41244
|
const restNetworkSettingsValidationContext = RestNetworkSettingsSchema.safeParse(networkSettings2);
|
|
41220
41245
|
if ("error" in restNetworkSettingsValidationContext) {
|
|
41221
41246
|
const { error: { issues } = {} } = restNetworkSettingsValidationContext;
|
|
41222
|
-
const errorMessage2 = issues === null || issues === void 0 ? void 0 : issues.map(({ message, path:
|
|
41247
|
+
const errorMessage2 = issues === null || issues === void 0 ? void 0 : issues.map(({ message, path: path6 }) => `${path6[0]}: ${message}`).join(", ");
|
|
41223
41248
|
if (throwOnError) {
|
|
41224
41249
|
throw new Error(errorMessage2);
|
|
41225
41250
|
}
|
|
@@ -42464,8 +42489,8 @@ async function commitMemoryVersion(plaintext, auth, opts) {
|
|
|
42464
42489
|
"commitMemoryVersion: score must be an integer in [1, 10]"
|
|
42465
42490
|
);
|
|
42466
42491
|
}
|
|
42467
|
-
const key3 = deriveMemoryKey(auth.privkey);
|
|
42468
|
-
const { ciphertext, nonce } = encryptMemoryContent(plaintext, key3);
|
|
42492
|
+
const key3 = await deriveMemoryKey(auth.privkey);
|
|
42493
|
+
const { ciphertext, nonce } = await encryptMemoryContent(plaintext, key3);
|
|
42469
42494
|
const chainOpts = await resolveChainOptsForOrg(opts, auth);
|
|
42470
42495
|
const client = await buildChainClient(chainOpts);
|
|
42471
42496
|
const { keyPair, sigProvider } = buildSigner(auth);
|
|
@@ -42491,13 +42516,13 @@ function toBuf(val) {
|
|
|
42491
42516
|
}
|
|
42492
42517
|
throw new Error("toBuf: unsupported byte_array shape from chain");
|
|
42493
42518
|
}
|
|
42494
|
-
function decryptRow(row, key3) {
|
|
42519
|
+
async function decryptRow(row, key3) {
|
|
42495
42520
|
const ciphertext = toBuf(row.content_cipher);
|
|
42496
42521
|
const nonce = toBuf(row.nonce);
|
|
42497
42522
|
let content;
|
|
42498
42523
|
let decryptError;
|
|
42499
42524
|
try {
|
|
42500
|
-
content = decryptMemoryContent(ciphertext, nonce, key3);
|
|
42525
|
+
content = await decryptMemoryContent(ciphertext, nonce, key3);
|
|
42501
42526
|
} catch (err) {
|
|
42502
42527
|
content = "";
|
|
42503
42528
|
decryptError = err instanceof Error ? err.message : String(err);
|
|
@@ -42514,36 +42539,43 @@ function decryptRow(row, key3) {
|
|
|
42514
42539
|
updatedAt: row.updated_at ?? row.created_at
|
|
42515
42540
|
};
|
|
42516
42541
|
}
|
|
42542
|
+
async function getActiveMemoryId(auth, chainOpts) {
|
|
42543
|
+
const client = await buildChainClient(chainOpts);
|
|
42544
|
+
const raw2 = await client.query("get_active_memory_id", {
|
|
42545
|
+
agent_pubkey: auth.pubkey
|
|
42546
|
+
});
|
|
42547
|
+
return raw2 ?? null;
|
|
42548
|
+
}
|
|
42517
42549
|
async function getActiveMemory(auth, chainOpts) {
|
|
42518
42550
|
const client = await buildChainClient(chainOpts);
|
|
42519
|
-
const key3 = deriveMemoryKey(auth.privkey);
|
|
42551
|
+
const key3 = await deriveMemoryKey(auth.privkey);
|
|
42520
42552
|
const rows = await client.query("get_agent_memory", {
|
|
42521
42553
|
agent_pubkey: auth.pubkey
|
|
42522
42554
|
});
|
|
42523
|
-
return rows.map((r2) => decryptRow(r2, key3));
|
|
42555
|
+
return Promise.all(rows.map((r2) => decryptRow(r2, key3)));
|
|
42524
42556
|
}
|
|
42525
42557
|
async function getAllAgentMemory(auth, chainOpts) {
|
|
42526
42558
|
const client = await buildChainClient(chainOpts);
|
|
42527
|
-
const key3 = deriveMemoryKey(auth.privkey);
|
|
42559
|
+
const key3 = await deriveMemoryKey(auth.privkey);
|
|
42528
42560
|
const rows = await client.query("get_all_agent_memory", {
|
|
42529
42561
|
agent_pubkey: auth.pubkey
|
|
42530
42562
|
});
|
|
42531
|
-
return rows.map((r2) => decryptRow(r2, key3));
|
|
42563
|
+
return Promise.all(rows.map((r2) => decryptRow(r2, key3)));
|
|
42532
42564
|
}
|
|
42533
42565
|
async function getMemoryHistory(auth, chainOpts) {
|
|
42534
42566
|
const client = await buildChainClient(chainOpts);
|
|
42535
|
-
const key3 = deriveMemoryKey(auth.privkey);
|
|
42567
|
+
const key3 = await deriveMemoryKey(auth.privkey);
|
|
42536
42568
|
const rows = await client.query("get_agent_memory_history", {
|
|
42537
42569
|
agent_pubkey: auth.pubkey
|
|
42538
42570
|
});
|
|
42539
|
-
return rows.map((r2) => decryptRow(r2, key3));
|
|
42571
|
+
return Promise.all(rows.map((r2) => decryptRow(r2, key3)));
|
|
42540
42572
|
}
|
|
42541
42573
|
async function getMemoryById(id, auth, chainOpts) {
|
|
42542
42574
|
if (!Number.isInteger(id) || id < 1) {
|
|
42543
42575
|
throw new Error("getMemoryById: id must be a positive integer");
|
|
42544
42576
|
}
|
|
42545
42577
|
const client = await buildChainClient(chainOpts);
|
|
42546
|
-
const key3 = deriveMemoryKey(auth.privkey);
|
|
42578
|
+
const key3 = await deriveMemoryKey(auth.privkey);
|
|
42547
42579
|
const row = await client.query("get_agent_memory_by_id", {
|
|
42548
42580
|
agent_pubkey: auth.pubkey,
|
|
42549
42581
|
id
|
|
@@ -42593,7 +42625,10 @@ var DEFAULT_MEMORY_PATH_PATTERNS = [
|
|
|
42593
42625
|
"/.openclaw/memory/",
|
|
42594
42626
|
"/.claude/projects/",
|
|
42595
42627
|
"/memory/",
|
|
42628
|
+
// Also match workspace-relative writes like `memory/2026-07-29.md`.
|
|
42629
|
+
"memory/",
|
|
42596
42630
|
"Memory.md",
|
|
42631
|
+
"DREAMS.md",
|
|
42597
42632
|
"CLAUDE.md",
|
|
42598
42633
|
"AGENTS.md"
|
|
42599
42634
|
];
|
|
@@ -42643,8 +42678,8 @@ function pickContent(toolName, args) {
|
|
|
42643
42678
|
}
|
|
42644
42679
|
return "";
|
|
42645
42680
|
}
|
|
42646
|
-
function matchesMemoryPath(
|
|
42647
|
-
const pLower =
|
|
42681
|
+
function matchesMemoryPath(path6, patterns) {
|
|
42682
|
+
const pLower = path6.toLowerCase();
|
|
42648
42683
|
for (const p of patterns) {
|
|
42649
42684
|
if (p && pLower.includes(p.toLowerCase())) return true;
|
|
42650
42685
|
}
|
|
@@ -42660,13 +42695,13 @@ function classifyMemoryWrite(event, ctx, opts = {}) {
|
|
|
42660
42695
|
const toolNamesLower = toolNames.map((t) => t.toLowerCase());
|
|
42661
42696
|
if (!toolNamesLower.includes(toolNameLower)) return null;
|
|
42662
42697
|
const args = ev.params ?? c.params ?? ev.args ?? c.args ?? ev.arguments ?? c.arguments;
|
|
42663
|
-
const
|
|
42664
|
-
if (!
|
|
42665
|
-
if (!matchesMemoryPath(
|
|
42698
|
+
const path6 = pickPath(args);
|
|
42699
|
+
if (!path6) return null;
|
|
42700
|
+
if (!matchesMemoryPath(path6, patterns)) return null;
|
|
42666
42701
|
const value = pickContent(toolName, args);
|
|
42667
42702
|
if (!value) return null;
|
|
42668
42703
|
return {
|
|
42669
|
-
key:
|
|
42704
|
+
key: path6,
|
|
42670
42705
|
value,
|
|
42671
42706
|
source: `plugin:${toolName}`
|
|
42672
42707
|
};
|
|
@@ -42768,6 +42803,349 @@ async function guardMemoryWrite(input) {
|
|
|
42768
42803
|
};
|
|
42769
42804
|
}
|
|
42770
42805
|
|
|
42806
|
+
// src-ts/memory/sync.ts
|
|
42807
|
+
var MemoryIntegrityError = class extends Error {
|
|
42808
|
+
constructor(id, reason) {
|
|
42809
|
+
super(`memory integrity check failed on id ${id}: ${reason}`);
|
|
42810
|
+
this.id = id;
|
|
42811
|
+
this.name = "MemoryIntegrityError";
|
|
42812
|
+
}
|
|
42813
|
+
id;
|
|
42814
|
+
};
|
|
42815
|
+
var DEFAULT_TTL_MS = 3e4;
|
|
42816
|
+
async function syncLocalMemory(auth, pointer, opts = {}) {
|
|
42817
|
+
const ttl = opts.ttlMs ?? DEFAULT_TTL_MS;
|
|
42818
|
+
const now = Date.now();
|
|
42819
|
+
const withinTtl = !opts.force && now - pointer.checkedAt < ttl;
|
|
42820
|
+
if (withinTtl) {
|
|
42821
|
+
return { drifted: false, pointer };
|
|
42822
|
+
}
|
|
42823
|
+
const currentId = await getActiveMemoryId(auth, opts.chainOpts);
|
|
42824
|
+
const nextPointer = { activeId: currentId, checkedAt: now };
|
|
42825
|
+
if (currentId === pointer.activeId) {
|
|
42826
|
+
return { drifted: false, pointer: nextPointer };
|
|
42827
|
+
}
|
|
42828
|
+
if (currentId === null) {
|
|
42829
|
+
return { drifted: true, current: null, pointer: nextPointer };
|
|
42830
|
+
}
|
|
42831
|
+
const row = await getMemoryById(currentId, auth, opts.chainOpts);
|
|
42832
|
+
if (row.decryptError) {
|
|
42833
|
+
throw new MemoryIntegrityError(currentId, row.decryptError);
|
|
42834
|
+
}
|
|
42835
|
+
return { drifted: true, current: row, pointer: nextPointer };
|
|
42836
|
+
}
|
|
42837
|
+
|
|
42838
|
+
// src-ts/memory/pointer-store.ts
|
|
42839
|
+
var import_node_fs4 = require("fs");
|
|
42840
|
+
var import_node_path4 = __toESM(require("path"));
|
|
42841
|
+
var EMPTY = { version: 1, agents: {} };
|
|
42842
|
+
var PointerStore = class {
|
|
42843
|
+
constructor(filePath) {
|
|
42844
|
+
this.filePath = filePath;
|
|
42845
|
+
}
|
|
42846
|
+
filePath;
|
|
42847
|
+
cache = null;
|
|
42848
|
+
loading = null;
|
|
42849
|
+
/** Resolves the pointer for `agentPubkeyHex`, or a zero-pointer that will force a sync on first use. */
|
|
42850
|
+
async get(agentPubkeyHex) {
|
|
42851
|
+
await this.ensureLoaded();
|
|
42852
|
+
return this.cache.agents[agentPubkeyHex] ?? { activeId: null, checkedAt: 0 };
|
|
42853
|
+
}
|
|
42854
|
+
/** Persists an updated pointer. Failures are swallowed to a logger callback (if provided) so sync never blocks the caller. */
|
|
42855
|
+
async set(agentPubkeyHex, pointer, onError) {
|
|
42856
|
+
await this.ensureLoaded();
|
|
42857
|
+
this.cache.agents[agentPubkeyHex] = pointer;
|
|
42858
|
+
try {
|
|
42859
|
+
await this.persist(this.cache);
|
|
42860
|
+
} catch (err) {
|
|
42861
|
+
onError?.(err instanceof Error ? err : new Error(String(err)));
|
|
42862
|
+
}
|
|
42863
|
+
}
|
|
42864
|
+
async ensureLoaded() {
|
|
42865
|
+
if (this.cache) return;
|
|
42866
|
+
if (!this.loading) this.loading = this.loadOnce();
|
|
42867
|
+
await this.loading;
|
|
42868
|
+
}
|
|
42869
|
+
async loadOnce() {
|
|
42870
|
+
try {
|
|
42871
|
+
const raw2 = await import_node_fs4.promises.readFile(this.filePath, "utf8");
|
|
42872
|
+
const parsed = JSON.parse(raw2);
|
|
42873
|
+
if (parsed && parsed.version === 1 && parsed.agents && typeof parsed.agents === "object") {
|
|
42874
|
+
this.cache = parsed;
|
|
42875
|
+
return;
|
|
42876
|
+
}
|
|
42877
|
+
} catch {
|
|
42878
|
+
}
|
|
42879
|
+
this.cache = { ...EMPTY, agents: {} };
|
|
42880
|
+
}
|
|
42881
|
+
async persist(file) {
|
|
42882
|
+
await import_node_fs4.promises.mkdir(import_node_path4.default.dirname(this.filePath), { recursive: true });
|
|
42883
|
+
const tmp = `${this.filePath}.${process.pid}.tmp`;
|
|
42884
|
+
await import_node_fs4.promises.writeFile(tmp, JSON.stringify(file, null, 2), "utf8");
|
|
42885
|
+
await import_node_fs4.promises.rename(tmp, this.filePath);
|
|
42886
|
+
}
|
|
42887
|
+
};
|
|
42888
|
+
function defaultPointerPath(workspaceDir = process.cwd()) {
|
|
42889
|
+
return import_node_path4.default.join(workspaceDir, ".atbash", "memory-pointer.json");
|
|
42890
|
+
}
|
|
42891
|
+
|
|
42892
|
+
// src-ts/memory/file-logger.ts
|
|
42893
|
+
var import_node_fs5 = require("fs");
|
|
42894
|
+
var import_node_path5 = __toESM(require("path"));
|
|
42895
|
+
function formatMeta(meta) {
|
|
42896
|
+
if (!meta || Object.keys(meta).length === 0) return "";
|
|
42897
|
+
try {
|
|
42898
|
+
return " " + JSON.stringify(meta);
|
|
42899
|
+
} catch {
|
|
42900
|
+
return "";
|
|
42901
|
+
}
|
|
42902
|
+
}
|
|
42903
|
+
function createFileLogger(filePath, upstream) {
|
|
42904
|
+
let queue = Promise.resolve();
|
|
42905
|
+
async function ensureDir() {
|
|
42906
|
+
await import_node_fs5.promises.mkdir(import_node_path5.default.dirname(filePath), { recursive: true });
|
|
42907
|
+
}
|
|
42908
|
+
function append(level, message, meta) {
|
|
42909
|
+
const line = `${(/* @__PURE__ */ new Date()).toISOString()} [${level}] ${message}${formatMeta(meta)}
|
|
42910
|
+
`;
|
|
42911
|
+
queue = queue.then(ensureDir).then(() => import_node_fs5.promises.appendFile(filePath, line, "utf8")).catch(() => {
|
|
42912
|
+
});
|
|
42913
|
+
}
|
|
42914
|
+
return {
|
|
42915
|
+
info(message, meta) {
|
|
42916
|
+
upstream?.info(message, meta ?? {});
|
|
42917
|
+
append("info", message, meta);
|
|
42918
|
+
},
|
|
42919
|
+
warn(message, meta) {
|
|
42920
|
+
upstream?.warn(message, meta ?? {});
|
|
42921
|
+
append("warn", message, meta);
|
|
42922
|
+
}
|
|
42923
|
+
};
|
|
42924
|
+
}
|
|
42925
|
+
function defaultPluginLogPath(workspaceDir = process.cwd()) {
|
|
42926
|
+
return import_node_path5.default.join(workspaceDir, ".atbash", "plugin.log");
|
|
42927
|
+
}
|
|
42928
|
+
|
|
42929
|
+
// src-ts/memory/read-classifier.ts
|
|
42930
|
+
var DEFAULT_MEMORY_READ_TOOL_NAMES = [
|
|
42931
|
+
"memory_search",
|
|
42932
|
+
"memory_get"
|
|
42933
|
+
];
|
|
42934
|
+
var DEFAULT_READ_TOOL_NAMES = [
|
|
42935
|
+
"read",
|
|
42936
|
+
"read_file"
|
|
42937
|
+
];
|
|
42938
|
+
function extractToolName(event, ctx) {
|
|
42939
|
+
const ev = event ?? {};
|
|
42940
|
+
const c = ctx ?? {};
|
|
42941
|
+
return (ev.toolName ?? c.tool?.name ?? c.toolName ?? c.name ?? "").toString();
|
|
42942
|
+
}
|
|
42943
|
+
function extractPath(event, ctx) {
|
|
42944
|
+
const ev = event ?? {};
|
|
42945
|
+
const c = ctx ?? {};
|
|
42946
|
+
const args = ev.args ?? ev.params ?? ev.arguments ?? c.args ?? c.params ?? {};
|
|
42947
|
+
for (const k of ["path", "file_path", "filePath", "target", "file"]) {
|
|
42948
|
+
const v = args[k];
|
|
42949
|
+
if (typeof v === "string" && v.length > 0) return v;
|
|
42950
|
+
}
|
|
42951
|
+
return "";
|
|
42952
|
+
}
|
|
42953
|
+
function matchesMemoryPath2(path6, patterns) {
|
|
42954
|
+
const p = path6.toLowerCase();
|
|
42955
|
+
for (const pat of patterns) {
|
|
42956
|
+
if (pat && p.includes(pat.toLowerCase())) return true;
|
|
42957
|
+
}
|
|
42958
|
+
return false;
|
|
42959
|
+
}
|
|
42960
|
+
function classifyMemoryRead(event, ctx, opts = {}) {
|
|
42961
|
+
const toolName = extractToolName(event, ctx).toLowerCase();
|
|
42962
|
+
if (!toolName) return false;
|
|
42963
|
+
const readTools = new Set(
|
|
42964
|
+
(opts.readToolNames ?? DEFAULT_MEMORY_READ_TOOL_NAMES).map((s2) => s2.toLowerCase())
|
|
42965
|
+
);
|
|
42966
|
+
if (readTools.has(toolName)) return true;
|
|
42967
|
+
const genericReadTools = new Set(
|
|
42968
|
+
(opts.genericReadToolNames ?? DEFAULT_READ_TOOL_NAMES).map((s2) => s2.toLowerCase())
|
|
42969
|
+
);
|
|
42970
|
+
if (genericReadTools.has(toolName)) {
|
|
42971
|
+
const path6 = extractPath(event, ctx);
|
|
42972
|
+
if (!path6) return false;
|
|
42973
|
+
const patterns = opts.patterns ? [...DEFAULT_MEMORY_PATH_PATTERNS, ...opts.patterns] : DEFAULT_MEMORY_PATH_PATTERNS;
|
|
42974
|
+
return matchesMemoryPath2(path6, patterns);
|
|
42975
|
+
}
|
|
42976
|
+
return false;
|
|
42977
|
+
}
|
|
42978
|
+
|
|
42979
|
+
// src-ts/memory/guard-manager.ts
|
|
42980
|
+
var import_node_fs6 = require("fs");
|
|
42981
|
+
var import_node_path6 = __toESM(require("path"));
|
|
42982
|
+
var DEFAULT_SYNC_TTL_MS = 3e4;
|
|
42983
|
+
var MemoryGuardManager = class {
|
|
42984
|
+
constructor(opts) {
|
|
42985
|
+
this.opts = opts;
|
|
42986
|
+
const workspaceDir = opts.workspaceDir;
|
|
42987
|
+
this.memoryFilePath = opts.memoryFilePath ?? import_node_path6.default.join(workspaceDir, "MEMORY.md");
|
|
42988
|
+
this.pointerStore = new PointerStore(opts.pointerFilePath ?? defaultPointerPath(workspaceDir));
|
|
42989
|
+
this.logger = createFileLogger(
|
|
42990
|
+
opts.logFilePath ?? defaultPluginLogPath(workspaceDir),
|
|
42991
|
+
opts.hostLogger
|
|
42992
|
+
);
|
|
42993
|
+
this.ttlMs = opts.ttlMs ?? DEFAULT_SYNC_TTL_MS;
|
|
42994
|
+
this.rollbackMinScore = opts.rollbackMinScore ?? 1;
|
|
42995
|
+
this.enforce = opts.enforce !== false;
|
|
42996
|
+
this.agentPubkeyHex = opts.auth.pubkey;
|
|
42997
|
+
this.logger.info(
|
|
42998
|
+
`[atbash] guard manager ready \u2014 agent=${this.agentPubkeyHex.slice(0, 16)}\u2026 org=${opts.orgName ?? "(none)"} memoryFilePath=${this.memoryFilePath} ttl=${this.ttlMs}ms minScore=${this.rollbackMinScore}`
|
|
42999
|
+
);
|
|
43000
|
+
}
|
|
43001
|
+
opts;
|
|
43002
|
+
pointerStore;
|
|
43003
|
+
logger;
|
|
43004
|
+
memoryFilePath;
|
|
43005
|
+
ttlMs;
|
|
43006
|
+
rollbackMinScore;
|
|
43007
|
+
enforce;
|
|
43008
|
+
agentPubkeyHex;
|
|
43009
|
+
/**
|
|
43010
|
+
* One-shot chain probe at plugin registration. Refreshes MEMORY.md
|
|
43011
|
+
* from chain when drifted and score passes threshold. Fire-and-forget
|
|
43012
|
+
* — errors are logged, never thrown.
|
|
43013
|
+
*/
|
|
43014
|
+
async runBootProbe() {
|
|
43015
|
+
try {
|
|
43016
|
+
const seed = { activeId: null, checkedAt: 0 };
|
|
43017
|
+
const result = await syncLocalMemory(this.opts.auth, seed, { ttlMs: 0, force: true });
|
|
43018
|
+
if (!result.drifted && result.pointer.activeId == null) {
|
|
43019
|
+
this.logger.info(
|
|
43020
|
+
`[atbash] no active memory on chain for agent=${this.agentPubkeyHex.slice(0, 16)}\u2026 org=${this.opts.orgName ?? "(none)"} \u2014 either the agent isn't registered on this chain or hasn't written any memory. Sync will remain a no-op until a write lands.`
|
|
43021
|
+
);
|
|
43022
|
+
} else if (result.drifted && result.current) {
|
|
43023
|
+
if (result.current.score < this.rollbackMinScore) {
|
|
43024
|
+
this.logger.warn(
|
|
43025
|
+
`[atbash] boot sync REFUSED refresh \u2014 id=${result.current.id} score=${result.current.score} below threshold ${this.rollbackMinScore}. Leaving MEMORY.md and pointer untouched; next memory read will be blocked.`
|
|
43026
|
+
);
|
|
43027
|
+
return;
|
|
43028
|
+
}
|
|
43029
|
+
this.logger.info(
|
|
43030
|
+
`[atbash] boot sync: refreshing local memory \u2014 id=${result.current.id} score=${result.current.score}`
|
|
43031
|
+
);
|
|
43032
|
+
try {
|
|
43033
|
+
await this.writeMemoryAtomic(result.current.content);
|
|
43034
|
+
} catch (err) {
|
|
43035
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
43036
|
+
this.logger.warn("[atbash] boot sync write failed (serving whatever's on disk)", { error: msg });
|
|
43037
|
+
}
|
|
43038
|
+
}
|
|
43039
|
+
await this.pointerStore.set(this.agentPubkeyHex, result.pointer);
|
|
43040
|
+
} catch (err) {
|
|
43041
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
43042
|
+
this.logger.warn("[atbash] boot memory sync failed \u2014 check chain endpoint / orgName", { error: msg });
|
|
43043
|
+
}
|
|
43044
|
+
}
|
|
43045
|
+
/**
|
|
43046
|
+
* Returns a `HookDecision` when the event is a memory read or write
|
|
43047
|
+
* (host returns it verbatim to its runtime). Returns `null` when the
|
|
43048
|
+
* event isn't memory-related — host falls through to its own audit.
|
|
43049
|
+
*/
|
|
43050
|
+
async handleBeforeToolCall(event, ctx) {
|
|
43051
|
+
if (classifyMemoryRead(event, ctx, this.opts.memoryReadClassifier)) {
|
|
43052
|
+
this.logger.info("[atbash] memory read intercepted \u2014 running sync check");
|
|
43053
|
+
return this.handleMemoryRead();
|
|
43054
|
+
}
|
|
43055
|
+
const guardLogger = {
|
|
43056
|
+
info: (msg, meta) => this.logger.info(msg, meta && typeof meta === "object" ? meta : void 0),
|
|
43057
|
+
warn: (msg, meta) => this.logger.warn(msg, meta && typeof meta === "object" ? meta : void 0)
|
|
43058
|
+
};
|
|
43059
|
+
const guard = await guardMemoryWrite({
|
|
43060
|
+
event,
|
|
43061
|
+
ctx,
|
|
43062
|
+
auth: this.opts.auth,
|
|
43063
|
+
endpoint: this.opts.judgeEndpoint,
|
|
43064
|
+
verifyPubKey: this.opts.judgeVerifyPubKey,
|
|
43065
|
+
orgName: this.opts.orgName,
|
|
43066
|
+
patterns: this.opts.memoryPathPatterns,
|
|
43067
|
+
toolNames: this.opts.memoryWriteToolNames,
|
|
43068
|
+
enforce: this.enforce,
|
|
43069
|
+
debug: this.opts.debug,
|
|
43070
|
+
logger: guardLogger
|
|
43071
|
+
});
|
|
43072
|
+
return this.mapGuardResult(guard);
|
|
43073
|
+
}
|
|
43074
|
+
mapGuardResult(guard) {
|
|
43075
|
+
if (!guard.handled) return null;
|
|
43076
|
+
const d = guard.decision;
|
|
43077
|
+
const sr2 = guard.scanResult;
|
|
43078
|
+
const verdict = sr2?.verdict ?? "?";
|
|
43079
|
+
const score = sr2?.score ?? "?";
|
|
43080
|
+
if (d.block) {
|
|
43081
|
+
this.logger.warn(
|
|
43082
|
+
`[atbash] guardMemoryWrite BLOCKED \u2014 verdict=${verdict} score=${score} reason=${(d.reason ?? "").slice(0, 200)}`
|
|
43083
|
+
);
|
|
43084
|
+
return {
|
|
43085
|
+
block: true,
|
|
43086
|
+
blockReason: d.reason ?? "",
|
|
43087
|
+
allow: false,
|
|
43088
|
+
reason: d.reason
|
|
43089
|
+
};
|
|
43090
|
+
}
|
|
43091
|
+
this.logger.info(
|
|
43092
|
+
`[atbash] guardMemoryWrite ALLOWED \u2014 verdict=${verdict} score=${score} committed=${guard.committed === true}`
|
|
43093
|
+
);
|
|
43094
|
+
return { allow: true };
|
|
43095
|
+
}
|
|
43096
|
+
async handleMemoryRead() {
|
|
43097
|
+
const pointer = await this.pointerStore.get(this.agentPubkeyHex);
|
|
43098
|
+
let result;
|
|
43099
|
+
try {
|
|
43100
|
+
result = await syncLocalMemory(this.opts.auth, pointer, { ttlMs: this.ttlMs });
|
|
43101
|
+
} catch (err) {
|
|
43102
|
+
if (err instanceof MemoryIntegrityError) {
|
|
43103
|
+
const reason = `Memory integrity check failed on id ${err.id} \u2014 read blocked.`;
|
|
43104
|
+
this.logger.warn("[atbash] MEMORY INTEGRITY FAILURE", { id: err.id, error: err.message });
|
|
43105
|
+
if (!this.enforce) return null;
|
|
43106
|
+
return { block: true, blockReason: reason, allow: false, reason };
|
|
43107
|
+
}
|
|
43108
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
43109
|
+
this.logger.warn("[atbash] memory sync failed (serving local copy)", { error: msg });
|
|
43110
|
+
return null;
|
|
43111
|
+
}
|
|
43112
|
+
if (result.drifted) {
|
|
43113
|
+
const fresh = result.current;
|
|
43114
|
+
if (fresh) {
|
|
43115
|
+
if (fresh.score < this.rollbackMinScore) {
|
|
43116
|
+
const reason = `Rolled-back memory version #${fresh.id} scored ${fresh.score} (below threshold ${this.rollbackMinScore}) \u2014 read blocked.`;
|
|
43117
|
+
this.logger.warn("[atbash] blocking read on low-score rollback", { id: fresh.id, score: fresh.score });
|
|
43118
|
+
if (!this.enforce) return null;
|
|
43119
|
+
return { block: true, blockReason: reason, allow: false, reason };
|
|
43120
|
+
}
|
|
43121
|
+
this.logger.info("[atbash] memory drift detected \u2014 refreshing local file", {
|
|
43122
|
+
id: fresh.id,
|
|
43123
|
+
score: fresh.score
|
|
43124
|
+
});
|
|
43125
|
+
try {
|
|
43126
|
+
await this.writeMemoryAtomic(fresh.content);
|
|
43127
|
+
} catch (err) {
|
|
43128
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
43129
|
+
this.logger.warn("[atbash] failed to write refreshed memory (serving old)", { error: msg });
|
|
43130
|
+
}
|
|
43131
|
+
} else {
|
|
43132
|
+
this.logger.info("[atbash] active memory removed on chain", { pubkey: this.agentPubkeyHex });
|
|
43133
|
+
}
|
|
43134
|
+
}
|
|
43135
|
+
await this.pointerStore.set(this.agentPubkeyHex, result.pointer);
|
|
43136
|
+
return null;
|
|
43137
|
+
}
|
|
43138
|
+
async writeMemoryAtomic(content) {
|
|
43139
|
+
await import_node_fs6.promises.mkdir(import_node_path6.default.dirname(this.memoryFilePath), { recursive: true });
|
|
43140
|
+
const tmp = `${this.memoryFilePath}.${process.pid}.tmp`;
|
|
43141
|
+
await import_node_fs6.promises.writeFile(tmp, content, "utf8");
|
|
43142
|
+
await import_node_fs6.promises.rename(tmp, this.memoryFilePath);
|
|
43143
|
+
}
|
|
43144
|
+
};
|
|
43145
|
+
function createMemoryGuardManager(opts) {
|
|
43146
|
+
return new MemoryGuardManager(opts);
|
|
43147
|
+
}
|
|
43148
|
+
|
|
42771
43149
|
// src-ts/index.ts
|
|
42772
43150
|
function isValidPrivateKey(hex) {
|
|
42773
43151
|
return native.isValidPrivateKey(hex);
|
|
@@ -42831,14 +43209,23 @@ function diffMemorySnapshots(before, after) {
|
|
|
42831
43209
|
DEFAULT_CHROMIA_NODE_URLS,
|
|
42832
43210
|
DEFAULT_ENDPOINT,
|
|
42833
43211
|
DEFAULT_MEMORY_PATH_PATTERNS,
|
|
43212
|
+
DEFAULT_MEMORY_READ_TOOL_NAMES,
|
|
42834
43213
|
DEFAULT_MEMORY_WRITE_TOOL_NAMES,
|
|
43214
|
+
MemoryGuardManager,
|
|
43215
|
+
MemoryIntegrityError,
|
|
43216
|
+
PointerStore,
|
|
42835
43217
|
SignatureVerificationError,
|
|
43218
|
+
classifyMemoryRead,
|
|
42836
43219
|
classifyMemoryWrite,
|
|
42837
43220
|
commitMemoryVersion,
|
|
42838
43221
|
containsEvasionCharacters,
|
|
42839
43222
|
containsSecret,
|
|
43223
|
+
createFileLogger,
|
|
43224
|
+
createMemoryGuardManager,
|
|
42840
43225
|
createMemorySnapshot,
|
|
42841
43226
|
decryptMemoryContent,
|
|
43227
|
+
defaultPluginLogPath,
|
|
43228
|
+
defaultPointerPath,
|
|
42842
43229
|
deriveMemoryKey,
|
|
42843
43230
|
derivePublicKey,
|
|
42844
43231
|
diffMemorySnapshots,
|
|
@@ -42846,6 +43233,7 @@ function diffMemorySnapshots(before, after) {
|
|
|
42846
43233
|
flushTelemetry,
|
|
42847
43234
|
generateKeypair,
|
|
42848
43235
|
getActiveMemory,
|
|
43236
|
+
getActiveMemoryId,
|
|
42849
43237
|
getAllAgentMemory,
|
|
42850
43238
|
getConfigDir,
|
|
42851
43239
|
getConfigPath,
|
|
@@ -42875,6 +43263,7 @@ function diffMemorySnapshots(before, after) {
|
|
|
42875
43263
|
shutdownTelemetry,
|
|
42876
43264
|
signJudgeAction,
|
|
42877
43265
|
signLogToolCall,
|
|
43266
|
+
syncLocalMemory,
|
|
42878
43267
|
validateJudgeEndpoint,
|
|
42879
43268
|
verifyJudgeResponseSignature,
|
|
42880
43269
|
verifySignature
|