memorix 1.6.3 → 1.7.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/CHANGELOG.md +31 -0
- package/dist/cli/index.js +1029 -643
- package/dist/cli/memcode.js +0 -0
- package/dist/dashboard/static/app.js +298 -37
- package/dist/dashboard/static/index.html +17 -0
- package/dist/dashboard/static/style.css +328 -0
- package/dist/index.js +902 -394
- package/dist/memcode-runtime/CHANGELOG.md +31 -0
- package/dist/sdk.js +901 -393
- package/docs/ARCHITECTURE.md +3 -0
- package/docs/DASHBOARD.md +54 -0
- package/docs/README.md +2 -0
- package/package.json +1 -1
- package/plugins/claude/memorix/.claude-plugin/plugin.json +1 -1
- package/plugins/codebuddy/memorix/.codebuddy-plugin/plugin.json +1 -1
- package/plugins/codex/memorix/.codex-plugin/plugin.json +1 -1
- package/plugins/copilot/memorix/plugin.json +1 -1
- package/plugins/gemini/memorix/gemini-extension.json +1 -1
- package/plugins/omp/memorix/package.json +1 -1
- package/plugins/openclaw/memorix/.codex-plugin/plugin.json +1 -1
- package/plugins/pi/memorix/package.json +1 -1
- package/server.json +2 -2
- package/src/cli/commands/cleanup.ts +13 -114
- package/src/cli/commands/memory.ts +12 -43
- package/src/dashboard/maintenance.ts +303 -0
- package/src/dashboard/server.ts +100 -2
- package/src/dashboard/static/index.html +17 -0
- package/src/dashboard/static/style.css +328 -0
- package/src/memory/cleanup.ts +143 -0
- package/src/memory/deduplication.ts +178 -0
- package/src/server.ts +12 -46
package/dist/cli/index.js
CHANGED
|
@@ -3232,7 +3232,7 @@ ${import_picocolors.default.gray(m3)} ${s4}
|
|
|
3232
3232
|
|
|
3233
3233
|
// src/cli/version.ts
|
|
3234
3234
|
function getCliVersion() {
|
|
3235
|
-
return true ? "1.
|
|
3235
|
+
return true ? "1.7.1" : pkg.version;
|
|
3236
3236
|
}
|
|
3237
3237
|
var init_version = __esm({
|
|
3238
3238
|
"src/cli/version.ts"() {
|
|
@@ -13242,29 +13242,29 @@ function sharedAgentIds(record2) {
|
|
|
13242
13242
|
return [];
|
|
13243
13243
|
}
|
|
13244
13244
|
}
|
|
13245
|
-
function canReadObservation(record2,
|
|
13246
|
-
if (!
|
|
13247
|
-
const sameProject =
|
|
13245
|
+
function canReadObservation(record2, reader2) {
|
|
13246
|
+
if (!reader2) return true;
|
|
13247
|
+
const sameProject = reader2.projectId === record2.projectId;
|
|
13248
13248
|
const visibility = resolveObservationVisibility(record2);
|
|
13249
|
-
if (visibility === "project") return !
|
|
13250
|
-
if (!sameProject || !
|
|
13251
|
-
if (visibility === "team") return
|
|
13252
|
-
return record2.createdByAgentId ===
|
|
13253
|
-
}
|
|
13254
|
-
function canManageObservation(record2,
|
|
13255
|
-
if (!
|
|
13256
|
-
if (!
|
|
13249
|
+
if (visibility === "project") return !reader2.projectId || sameProject;
|
|
13250
|
+
if (!sameProject || !reader2.agentId) return false;
|
|
13251
|
+
if (visibility === "team") return reader2.isTeamMember === true;
|
|
13252
|
+
return record2.createdByAgentId === reader2.agentId || sharedAgentIds(record2).includes(reader2.agentId);
|
|
13253
|
+
}
|
|
13254
|
+
function canManageObservation(record2, reader2) {
|
|
13255
|
+
if (!reader2) return true;
|
|
13256
|
+
if (!reader2.projectId || reader2.projectId !== record2.projectId) return false;
|
|
13257
13257
|
switch (resolveObservationVisibility(record2)) {
|
|
13258
13258
|
case "project":
|
|
13259
13259
|
return true;
|
|
13260
13260
|
case "team":
|
|
13261
|
-
return
|
|
13261
|
+
return reader2.isTeamMember === true;
|
|
13262
13262
|
case "personal":
|
|
13263
|
-
return Boolean(
|
|
13263
|
+
return Boolean(reader2.agentId && record2.createdByAgentId === reader2.agentId);
|
|
13264
13264
|
}
|
|
13265
13265
|
}
|
|
13266
|
-
function filterReadableObservations(observations2,
|
|
13267
|
-
return
|
|
13266
|
+
function filterReadableObservations(observations2, reader2) {
|
|
13267
|
+
return reader2 ? observations2.filter((observation) => canReadObservation(observation, reader2)) : [...observations2];
|
|
13268
13268
|
}
|
|
13269
13269
|
var init_visibility = __esm({
|
|
13270
13270
|
"src/memory/visibility.ts"() {
|
|
@@ -16171,8 +16171,8 @@ var require_int2 = __commonJS({
|
|
|
16171
16171
|
var stringifyNumber = require_stringifyNumber();
|
|
16172
16172
|
var intIdentify = (value) => typeof value === "bigint" || Number.isInteger(value);
|
|
16173
16173
|
function intResolve(str2, offset, radix, { intAsBigInt }) {
|
|
16174
|
-
const
|
|
16175
|
-
if (
|
|
16174
|
+
const sign2 = str2[0];
|
|
16175
|
+
if (sign2 === "-" || sign2 === "+")
|
|
16176
16176
|
offset += 1;
|
|
16177
16177
|
str2 = str2.substring(offset).replace(/_/g, "");
|
|
16178
16178
|
if (intAsBigInt) {
|
|
@@ -16188,10 +16188,10 @@ var require_int2 = __commonJS({
|
|
|
16188
16188
|
break;
|
|
16189
16189
|
}
|
|
16190
16190
|
const n4 = BigInt(str2);
|
|
16191
|
-
return
|
|
16191
|
+
return sign2 === "-" ? BigInt(-1) * n4 : n4;
|
|
16192
16192
|
}
|
|
16193
16193
|
const n3 = parseInt(str2, radix);
|
|
16194
|
-
return
|
|
16194
|
+
return sign2 === "-" ? -1 * n3 : n3;
|
|
16195
16195
|
}
|
|
16196
16196
|
function intStringify(node, radix, prefix) {
|
|
16197
16197
|
const { value } = node;
|
|
@@ -16340,11 +16340,11 @@ var require_timestamp = __commonJS({
|
|
|
16340
16340
|
init_esm_shims();
|
|
16341
16341
|
var stringifyNumber = require_stringifyNumber();
|
|
16342
16342
|
function parseSexagesimal(str2, asBigInt) {
|
|
16343
|
-
const
|
|
16344
|
-
const parts =
|
|
16343
|
+
const sign2 = str2[0];
|
|
16344
|
+
const parts = sign2 === "-" || sign2 === "+" ? str2.substring(1) : str2;
|
|
16345
16345
|
const num = (n3) => asBigInt ? BigInt(n3) : Number(n3);
|
|
16346
16346
|
const res = parts.replace(/_/g, "").split(":").reduce((res2, p3) => res2 * num(60) + num(p3), num(0));
|
|
16347
|
-
return
|
|
16347
|
+
return sign2 === "-" ? num(-1) * res : res;
|
|
16348
16348
|
}
|
|
16349
16349
|
function stringifySexagesimal(node) {
|
|
16350
16350
|
let { value } = node;
|
|
@@ -16353,9 +16353,9 @@ var require_timestamp = __commonJS({
|
|
|
16353
16353
|
num = (n3) => BigInt(n3);
|
|
16354
16354
|
else if (isNaN(value) || !isFinite(value))
|
|
16355
16355
|
return stringifyNumber.stringifyNumber(node);
|
|
16356
|
-
let
|
|
16356
|
+
let sign2 = "";
|
|
16357
16357
|
if (value < 0) {
|
|
16358
|
-
|
|
16358
|
+
sign2 = "-";
|
|
16359
16359
|
value *= num(-1);
|
|
16360
16360
|
}
|
|
16361
16361
|
const _60 = num(60);
|
|
@@ -16370,7 +16370,7 @@ var require_timestamp = __commonJS({
|
|
|
16370
16370
|
parts.unshift(value);
|
|
16371
16371
|
}
|
|
16372
16372
|
}
|
|
16373
|
-
return
|
|
16373
|
+
return sign2 + parts.map((n3) => String(n3).padStart(2, "0")).join(":").replace(/000000\d*$/, "");
|
|
16374
16374
|
}
|
|
16375
16375
|
var intTime = {
|
|
16376
16376
|
identify: (value) => typeof value === "bigint" || Number.isInteger(value),
|
|
@@ -24056,8 +24056,8 @@ async function readResponseText(response, signal, maxBytes = MAX_LLM_RESPONSE_BY
|
|
|
24056
24056
|
if (contentLength && Number(contentLength) > maxBytes) {
|
|
24057
24057
|
throw new Error(`LLM response too large (${contentLength} bytes)`);
|
|
24058
24058
|
}
|
|
24059
|
-
const
|
|
24060
|
-
if (!
|
|
24059
|
+
const reader2 = response.body?.getReader();
|
|
24060
|
+
if (!reader2) {
|
|
24061
24061
|
signal?.throwIfAborted();
|
|
24062
24062
|
return response.text();
|
|
24063
24063
|
}
|
|
@@ -24065,19 +24065,19 @@ async function readResponseText(response, signal, maxBytes = MAX_LLM_RESPONSE_BY
|
|
|
24065
24065
|
const chunks = [];
|
|
24066
24066
|
let bytesRead = 0;
|
|
24067
24067
|
const abortReader = () => {
|
|
24068
|
-
void
|
|
24068
|
+
void reader2.cancel(signal?.reason).catch(() => void 0);
|
|
24069
24069
|
};
|
|
24070
24070
|
signal?.addEventListener("abort", abortReader, { once: true });
|
|
24071
24071
|
try {
|
|
24072
24072
|
while (true) {
|
|
24073
24073
|
signal?.throwIfAborted();
|
|
24074
|
-
const { value, done } = await
|
|
24074
|
+
const { value, done } = await reader2.read();
|
|
24075
24075
|
if (done) break;
|
|
24076
24076
|
signal?.throwIfAborted();
|
|
24077
24077
|
if (!value) continue;
|
|
24078
24078
|
bytesRead += value.byteLength;
|
|
24079
24079
|
if (bytesRead > maxBytes) {
|
|
24080
|
-
await
|
|
24080
|
+
await reader2.cancel("response too large").catch(() => void 0);
|
|
24081
24081
|
throw new Error(`LLM response exceeded ${maxBytes} bytes`);
|
|
24082
24082
|
}
|
|
24083
24083
|
chunks.push(decoder2.decode(value, { stream: true }));
|
|
@@ -24087,7 +24087,7 @@ async function readResponseText(response, signal, maxBytes = MAX_LLM_RESPONSE_BY
|
|
|
24087
24087
|
return chunks.join("");
|
|
24088
24088
|
} finally {
|
|
24089
24089
|
signal?.removeEventListener("abort", abortReader);
|
|
24090
|
-
|
|
24090
|
+
reader2.releaseLock();
|
|
24091
24091
|
}
|
|
24092
24092
|
}
|
|
24093
24093
|
async function readResponseJson(response, signal, maxBytes = MAX_LLM_RESPONSE_BYTES) {
|
|
@@ -24417,8 +24417,8 @@ async function* callOpenAIWithToolsStream(messages, tools) {
|
|
|
24417
24417
|
const error40 = await response.text().catch(() => "unknown error");
|
|
24418
24418
|
throw new Error(`LLM streaming API error (${response.status}): ${error40}`);
|
|
24419
24419
|
}
|
|
24420
|
-
const
|
|
24421
|
-
if (!
|
|
24420
|
+
const reader2 = response.body?.getReader();
|
|
24421
|
+
if (!reader2) throw new Error("No response body for streaming");
|
|
24422
24422
|
const decoder2 = new TextDecoder();
|
|
24423
24423
|
let fullContent = "";
|
|
24424
24424
|
const toolCallMap = /* @__PURE__ */ new Map();
|
|
@@ -24426,7 +24426,7 @@ async function* callOpenAIWithToolsStream(messages, tools) {
|
|
|
24426
24426
|
let buffer = "";
|
|
24427
24427
|
try {
|
|
24428
24428
|
while (true) {
|
|
24429
|
-
const { done, value } = await
|
|
24429
|
+
const { done, value } = await reader2.read();
|
|
24430
24430
|
if (done) break;
|
|
24431
24431
|
buffer += decoder2.decode(value, { stream: true });
|
|
24432
24432
|
const lines = buffer.split("\n");
|
|
@@ -24468,7 +24468,7 @@ async function* callOpenAIWithToolsStream(messages, tools) {
|
|
|
24468
24468
|
}
|
|
24469
24469
|
}
|
|
24470
24470
|
} finally {
|
|
24471
|
-
|
|
24471
|
+
reader2.releaseLock();
|
|
24472
24472
|
}
|
|
24473
24473
|
const toolCalls = [...toolCallMap.values()].map((tc2) => ({
|
|
24474
24474
|
id: tc2.id,
|
|
@@ -24549,8 +24549,8 @@ async function* callAnthropicWithToolsStream(messages, tools) {
|
|
|
24549
24549
|
const error40 = await response.text().catch(() => "unknown error");
|
|
24550
24550
|
throw new Error(`Anthropic streaming API error (${response.status}): ${error40}`);
|
|
24551
24551
|
}
|
|
24552
|
-
const
|
|
24553
|
-
if (!
|
|
24552
|
+
const reader2 = response.body?.getReader();
|
|
24553
|
+
if (!reader2) throw new Error("No response body for streaming");
|
|
24554
24554
|
const decoder2 = new TextDecoder();
|
|
24555
24555
|
let fullContent = "";
|
|
24556
24556
|
const toolCalls = [];
|
|
@@ -24561,7 +24561,7 @@ async function* callAnthropicWithToolsStream(messages, tools) {
|
|
|
24561
24561
|
let buffer = "";
|
|
24562
24562
|
try {
|
|
24563
24563
|
while (true) {
|
|
24564
|
-
const { done, value } = await
|
|
24564
|
+
const { done, value } = await reader2.read();
|
|
24565
24565
|
if (done) break;
|
|
24566
24566
|
buffer += decoder2.decode(value, { stream: true });
|
|
24567
24567
|
const lines = buffer.split("\n");
|
|
@@ -24609,7 +24609,7 @@ async function* callAnthropicWithToolsStream(messages, tools) {
|
|
|
24609
24609
|
}
|
|
24610
24610
|
}
|
|
24611
24611
|
} finally {
|
|
24612
|
-
|
|
24612
|
+
reader2.releaseLock();
|
|
24613
24613
|
}
|
|
24614
24614
|
const mappedStopReason = stopReason === "tool_use" ? "tool_use" : stopReason === "end_turn" ? "end_turn" : "unknown";
|
|
24615
24615
|
yield {
|
|
@@ -36248,12 +36248,12 @@ async function readBoundedImageResponse(response) {
|
|
|
36248
36248
|
}
|
|
36249
36249
|
if (!response.body)
|
|
36250
36250
|
throw new Error("MiniMax image generation returned an empty image response");
|
|
36251
|
-
const
|
|
36251
|
+
const reader2 = response.body.getReader();
|
|
36252
36252
|
const chunks = [];
|
|
36253
36253
|
let total = 0;
|
|
36254
36254
|
try {
|
|
36255
36255
|
while (true) {
|
|
36256
|
-
const { done, value } = await
|
|
36256
|
+
const { done, value } = await reader2.read();
|
|
36257
36257
|
if (done)
|
|
36258
36258
|
break;
|
|
36259
36259
|
if (!value)
|
|
@@ -36265,7 +36265,7 @@ async function readBoundedImageResponse(response) {
|
|
|
36265
36265
|
chunks.push(value);
|
|
36266
36266
|
}
|
|
36267
36267
|
} finally {
|
|
36268
|
-
|
|
36268
|
+
reader2.releaseLock();
|
|
36269
36269
|
}
|
|
36270
36270
|
return Buffer.concat(chunks);
|
|
36271
36271
|
}
|
|
@@ -36789,22 +36789,22 @@ function ReadableStreamFrom(iterable) {
|
|
|
36789
36789
|
function ReadableStreamToAsyncIterable(stream2) {
|
|
36790
36790
|
if (stream2[Symbol.asyncIterator])
|
|
36791
36791
|
return stream2;
|
|
36792
|
-
const
|
|
36792
|
+
const reader2 = stream2.getReader();
|
|
36793
36793
|
return {
|
|
36794
36794
|
async next() {
|
|
36795
36795
|
try {
|
|
36796
|
-
const result = await
|
|
36796
|
+
const result = await reader2.read();
|
|
36797
36797
|
if (result?.done)
|
|
36798
|
-
|
|
36798
|
+
reader2.releaseLock();
|
|
36799
36799
|
return result;
|
|
36800
36800
|
} catch (e5) {
|
|
36801
|
-
|
|
36801
|
+
reader2.releaseLock();
|
|
36802
36802
|
throw e5;
|
|
36803
36803
|
}
|
|
36804
36804
|
},
|
|
36805
36805
|
async return() {
|
|
36806
|
-
const cancelPromise =
|
|
36807
|
-
|
|
36806
|
+
const cancelPromise = reader2.cancel();
|
|
36807
|
+
reader2.releaseLock();
|
|
36808
36808
|
await cancelPromise;
|
|
36809
36809
|
return { done: true, value: void 0 };
|
|
36810
36810
|
},
|
|
@@ -36820,9 +36820,9 @@ async function CancelReadableStream(stream2) {
|
|
|
36820
36820
|
await stream2[Symbol.asyncIterator]().return?.();
|
|
36821
36821
|
return;
|
|
36822
36822
|
}
|
|
36823
|
-
const
|
|
36824
|
-
const cancelPromise =
|
|
36825
|
-
|
|
36823
|
+
const reader2 = stream2.getReader();
|
|
36824
|
+
const cancelPromise = reader2.cancel();
|
|
36825
|
+
reader2.releaseLock();
|
|
36826
36826
|
await cancelPromise;
|
|
36827
36827
|
}
|
|
36828
36828
|
var init_shims = __esm({
|
|
@@ -39561,31 +39561,31 @@ var init_ChatCompletionStream = __esm({
|
|
|
39561
39561
|
const readQueue = [];
|
|
39562
39562
|
let done = false;
|
|
39563
39563
|
this.on("chunk", (chunk) => {
|
|
39564
|
-
const
|
|
39565
|
-
if (
|
|
39566
|
-
|
|
39564
|
+
const reader2 = readQueue.shift();
|
|
39565
|
+
if (reader2) {
|
|
39566
|
+
reader2.resolve(chunk);
|
|
39567
39567
|
} else {
|
|
39568
39568
|
pushQueue.push(chunk);
|
|
39569
39569
|
}
|
|
39570
39570
|
});
|
|
39571
39571
|
this.on("end", () => {
|
|
39572
39572
|
done = true;
|
|
39573
|
-
for (const
|
|
39574
|
-
|
|
39573
|
+
for (const reader2 of readQueue) {
|
|
39574
|
+
reader2.resolve(void 0);
|
|
39575
39575
|
}
|
|
39576
39576
|
readQueue.length = 0;
|
|
39577
39577
|
});
|
|
39578
39578
|
this.on("abort", (err) => {
|
|
39579
39579
|
done = true;
|
|
39580
|
-
for (const
|
|
39581
|
-
|
|
39580
|
+
for (const reader2 of readQueue) {
|
|
39581
|
+
reader2.reject(err);
|
|
39582
39582
|
}
|
|
39583
39583
|
readQueue.length = 0;
|
|
39584
39584
|
});
|
|
39585
39585
|
this.on("error", (err) => {
|
|
39586
39586
|
done = true;
|
|
39587
|
-
for (const
|
|
39588
|
-
|
|
39587
|
+
for (const reader2 of readQueue) {
|
|
39588
|
+
reader2.reject(err);
|
|
39589
39589
|
}
|
|
39590
39590
|
readQueue.length = 0;
|
|
39591
39591
|
});
|
|
@@ -40544,31 +40544,31 @@ var init_AssistantStream = __esm({
|
|
|
40544
40544
|
const readQueue = [];
|
|
40545
40545
|
let done = false;
|
|
40546
40546
|
this.on("event", (event) => {
|
|
40547
|
-
const
|
|
40548
|
-
if (
|
|
40549
|
-
|
|
40547
|
+
const reader2 = readQueue.shift();
|
|
40548
|
+
if (reader2) {
|
|
40549
|
+
reader2.resolve(event);
|
|
40550
40550
|
} else {
|
|
40551
40551
|
pushQueue.push(event);
|
|
40552
40552
|
}
|
|
40553
40553
|
});
|
|
40554
40554
|
this.on("end", () => {
|
|
40555
40555
|
done = true;
|
|
40556
|
-
for (const
|
|
40557
|
-
|
|
40556
|
+
for (const reader2 of readQueue) {
|
|
40557
|
+
reader2.resolve(void 0);
|
|
40558
40558
|
}
|
|
40559
40559
|
readQueue.length = 0;
|
|
40560
40560
|
});
|
|
40561
40561
|
this.on("abort", (err) => {
|
|
40562
40562
|
done = true;
|
|
40563
|
-
for (const
|
|
40564
|
-
|
|
40563
|
+
for (const reader2 of readQueue) {
|
|
40564
|
+
reader2.reject(err);
|
|
40565
40565
|
}
|
|
40566
40566
|
readQueue.length = 0;
|
|
40567
40567
|
});
|
|
40568
40568
|
this.on("error", (err) => {
|
|
40569
40569
|
done = true;
|
|
40570
|
-
for (const
|
|
40571
|
-
|
|
40570
|
+
for (const reader2 of readQueue) {
|
|
40571
|
+
reader2.reject(err);
|
|
40572
40572
|
}
|
|
40573
40573
|
readQueue.length = 0;
|
|
40574
40574
|
});
|
|
@@ -42833,31 +42833,31 @@ var init_ResponseStream = __esm({
|
|
|
42833
42833
|
const readQueue = [];
|
|
42834
42834
|
let done = false;
|
|
42835
42835
|
this.on("event", (event) => {
|
|
42836
|
-
const
|
|
42837
|
-
if (
|
|
42838
|
-
|
|
42836
|
+
const reader2 = readQueue.shift();
|
|
42837
|
+
if (reader2) {
|
|
42838
|
+
reader2.resolve(event);
|
|
42839
42839
|
} else {
|
|
42840
42840
|
pushQueue.push(event);
|
|
42841
42841
|
}
|
|
42842
42842
|
});
|
|
42843
42843
|
this.on("end", () => {
|
|
42844
42844
|
done = true;
|
|
42845
|
-
for (const
|
|
42846
|
-
|
|
42845
|
+
for (const reader2 of readQueue) {
|
|
42846
|
+
reader2.resolve(void 0);
|
|
42847
42847
|
}
|
|
42848
42848
|
readQueue.length = 0;
|
|
42849
42849
|
});
|
|
42850
42850
|
this.on("abort", (err) => {
|
|
42851
42851
|
done = true;
|
|
42852
|
-
for (const
|
|
42853
|
-
|
|
42852
|
+
for (const reader2 of readQueue) {
|
|
42853
|
+
reader2.reject(err);
|
|
42854
42854
|
}
|
|
42855
42855
|
readQueue.length = 0;
|
|
42856
42856
|
});
|
|
42857
42857
|
this.on("error", (err) => {
|
|
42858
42858
|
done = true;
|
|
42859
|
-
for (const
|
|
42860
|
-
|
|
42859
|
+
for (const reader2 of readQueue) {
|
|
42860
|
+
reader2.reject(err);
|
|
42861
42861
|
}
|
|
42862
42862
|
readQueue.length = 0;
|
|
42863
42863
|
});
|
|
@@ -63573,22 +63573,22 @@ function ReadableStreamFrom2(iterable) {
|
|
|
63573
63573
|
function ReadableStreamToAsyncIterable2(stream2) {
|
|
63574
63574
|
if (stream2[Symbol.asyncIterator])
|
|
63575
63575
|
return stream2;
|
|
63576
|
-
const
|
|
63576
|
+
const reader2 = stream2.getReader();
|
|
63577
63577
|
return {
|
|
63578
63578
|
async next() {
|
|
63579
63579
|
try {
|
|
63580
|
-
const result = await
|
|
63580
|
+
const result = await reader2.read();
|
|
63581
63581
|
if (result?.done)
|
|
63582
|
-
|
|
63582
|
+
reader2.releaseLock();
|
|
63583
63583
|
return result;
|
|
63584
63584
|
} catch (e5) {
|
|
63585
|
-
|
|
63585
|
+
reader2.releaseLock();
|
|
63586
63586
|
throw e5;
|
|
63587
63587
|
}
|
|
63588
63588
|
},
|
|
63589
63589
|
async return() {
|
|
63590
|
-
const cancelPromise =
|
|
63591
|
-
|
|
63590
|
+
const cancelPromise = reader2.cancel();
|
|
63591
|
+
reader2.releaseLock();
|
|
63592
63592
|
await cancelPromise;
|
|
63593
63593
|
return { done: true, value: void 0 };
|
|
63594
63594
|
},
|
|
@@ -63604,9 +63604,9 @@ async function CancelReadableStream2(stream2) {
|
|
|
63604
63604
|
await stream2[Symbol.asyncIterator]().return?.();
|
|
63605
63605
|
return;
|
|
63606
63606
|
}
|
|
63607
|
-
const
|
|
63608
|
-
const cancelPromise =
|
|
63609
|
-
|
|
63607
|
+
const reader2 = stream2.getReader();
|
|
63608
|
+
const cancelPromise = reader2.cancel();
|
|
63609
|
+
reader2.releaseLock();
|
|
63610
63610
|
await cancelPromise;
|
|
63611
63611
|
}
|
|
63612
63612
|
var init_shims2 = __esm({
|
|
@@ -66633,31 +66633,31 @@ var init_BetaMessageStream = __esm({
|
|
|
66633
66633
|
const readQueue = [];
|
|
66634
66634
|
let done = false;
|
|
66635
66635
|
this.on("streamEvent", (event) => {
|
|
66636
|
-
const
|
|
66637
|
-
if (
|
|
66638
|
-
|
|
66636
|
+
const reader2 = readQueue.shift();
|
|
66637
|
+
if (reader2) {
|
|
66638
|
+
reader2.resolve(event);
|
|
66639
66639
|
} else {
|
|
66640
66640
|
pushQueue.push(event);
|
|
66641
66641
|
}
|
|
66642
66642
|
});
|
|
66643
66643
|
this.on("end", () => {
|
|
66644
66644
|
done = true;
|
|
66645
|
-
for (const
|
|
66646
|
-
|
|
66645
|
+
for (const reader2 of readQueue) {
|
|
66646
|
+
reader2.resolve(void 0);
|
|
66647
66647
|
}
|
|
66648
66648
|
readQueue.length = 0;
|
|
66649
66649
|
});
|
|
66650
66650
|
this.on("abort", (err) => {
|
|
66651
66651
|
done = true;
|
|
66652
|
-
for (const
|
|
66653
|
-
|
|
66652
|
+
for (const reader2 of readQueue) {
|
|
66653
|
+
reader2.reject(err);
|
|
66654
66654
|
}
|
|
66655
66655
|
readQueue.length = 0;
|
|
66656
66656
|
});
|
|
66657
66657
|
this.on("error", (err) => {
|
|
66658
66658
|
done = true;
|
|
66659
|
-
for (const
|
|
66660
|
-
|
|
66659
|
+
for (const reader2 of readQueue) {
|
|
66660
|
+
reader2.reject(err);
|
|
66661
66661
|
}
|
|
66662
66662
|
readQueue.length = 0;
|
|
66663
66663
|
});
|
|
@@ -69069,31 +69069,31 @@ var init_MessageStream = __esm({
|
|
|
69069
69069
|
const readQueue = [];
|
|
69070
69070
|
let done = false;
|
|
69071
69071
|
this.on("streamEvent", (event) => {
|
|
69072
|
-
const
|
|
69073
|
-
if (
|
|
69074
|
-
|
|
69072
|
+
const reader2 = readQueue.shift();
|
|
69073
|
+
if (reader2) {
|
|
69074
|
+
reader2.resolve(event);
|
|
69075
69075
|
} else {
|
|
69076
69076
|
pushQueue.push(event);
|
|
69077
69077
|
}
|
|
69078
69078
|
});
|
|
69079
69079
|
this.on("end", () => {
|
|
69080
69080
|
done = true;
|
|
69081
|
-
for (const
|
|
69082
|
-
|
|
69081
|
+
for (const reader2 of readQueue) {
|
|
69082
|
+
reader2.resolve(void 0);
|
|
69083
69083
|
}
|
|
69084
69084
|
readQueue.length = 0;
|
|
69085
69085
|
});
|
|
69086
69086
|
this.on("abort", (err) => {
|
|
69087
69087
|
done = true;
|
|
69088
|
-
for (const
|
|
69089
|
-
|
|
69088
|
+
for (const reader2 of readQueue) {
|
|
69089
|
+
reader2.reject(err);
|
|
69090
69090
|
}
|
|
69091
69091
|
readQueue.length = 0;
|
|
69092
69092
|
});
|
|
69093
69093
|
this.on("error", (err) => {
|
|
69094
69094
|
done = true;
|
|
69095
|
-
for (const
|
|
69096
|
-
|
|
69095
|
+
for (const reader2 of readQueue) {
|
|
69096
|
+
reader2.reject(err);
|
|
69097
69097
|
}
|
|
69098
69098
|
readQueue.length = 0;
|
|
69099
69099
|
});
|
|
@@ -70763,7 +70763,7 @@ function consumeLine(text2) {
|
|
|
70763
70763
|
};
|
|
70764
70764
|
}
|
|
70765
70765
|
async function* iterateSseMessages(body, signal) {
|
|
70766
|
-
const
|
|
70766
|
+
const reader2 = body.getReader();
|
|
70767
70767
|
const decoder2 = new TextDecoder();
|
|
70768
70768
|
const state = { event: null, data: [], raw: [] };
|
|
70769
70769
|
let buffer = "";
|
|
@@ -70772,7 +70772,7 @@ async function* iterateSseMessages(body, signal) {
|
|
|
70772
70772
|
if (signal?.aborted) {
|
|
70773
70773
|
throw new Error("Request was aborted");
|
|
70774
70774
|
}
|
|
70775
|
-
const { value, done } = await
|
|
70775
|
+
const { value, done } = await reader2.read();
|
|
70776
70776
|
if (done) {
|
|
70777
70777
|
break;
|
|
70778
70778
|
}
|
|
@@ -70808,7 +70808,7 @@ async function* iterateSseMessages(body, signal) {
|
|
|
70808
70808
|
yield trailingEvent;
|
|
70809
70809
|
}
|
|
70810
70810
|
} finally {
|
|
70811
|
-
|
|
70811
|
+
reader2.releaseLock();
|
|
70812
70812
|
}
|
|
70813
70813
|
}
|
|
70814
70814
|
async function* iterateAnthropicEvents(response, signal) {
|
|
@@ -73651,7 +73651,7 @@ var require_supports_color = __commonJS({
|
|
|
73651
73651
|
return 1;
|
|
73652
73652
|
}
|
|
73653
73653
|
if ("CI" in env3) {
|
|
73654
|
-
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE", "DRONE"].some((
|
|
73654
|
+
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE", "DRONE"].some((sign2) => sign2 in env3) || env3.CI_NAME === "codeship") {
|
|
73655
73655
|
return 1;
|
|
73656
73656
|
}
|
|
73657
73657
|
return min;
|
|
@@ -74580,68 +74580,68 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
74580
74580
|
const CancelSteps = /* @__PURE__ */ Symbol("[[CancelSteps]]");
|
|
74581
74581
|
const PullSteps = /* @__PURE__ */ Symbol("[[PullSteps]]");
|
|
74582
74582
|
const ReleaseSteps = /* @__PURE__ */ Symbol("[[ReleaseSteps]]");
|
|
74583
|
-
function ReadableStreamReaderGenericInitialize(
|
|
74584
|
-
|
|
74585
|
-
stream2._reader =
|
|
74583
|
+
function ReadableStreamReaderGenericInitialize(reader2, stream2) {
|
|
74584
|
+
reader2._ownerReadableStream = stream2;
|
|
74585
|
+
stream2._reader = reader2;
|
|
74586
74586
|
if (stream2._state === "readable") {
|
|
74587
|
-
defaultReaderClosedPromiseInitialize(
|
|
74587
|
+
defaultReaderClosedPromiseInitialize(reader2);
|
|
74588
74588
|
} else if (stream2._state === "closed") {
|
|
74589
|
-
defaultReaderClosedPromiseInitializeAsResolved(
|
|
74589
|
+
defaultReaderClosedPromiseInitializeAsResolved(reader2);
|
|
74590
74590
|
} else {
|
|
74591
|
-
defaultReaderClosedPromiseInitializeAsRejected(
|
|
74591
|
+
defaultReaderClosedPromiseInitializeAsRejected(reader2, stream2._storedError);
|
|
74592
74592
|
}
|
|
74593
74593
|
}
|
|
74594
|
-
function ReadableStreamReaderGenericCancel(
|
|
74595
|
-
const stream2 =
|
|
74594
|
+
function ReadableStreamReaderGenericCancel(reader2, reason) {
|
|
74595
|
+
const stream2 = reader2._ownerReadableStream;
|
|
74596
74596
|
return ReadableStreamCancel(stream2, reason);
|
|
74597
74597
|
}
|
|
74598
|
-
function ReadableStreamReaderGenericRelease(
|
|
74599
|
-
const stream2 =
|
|
74598
|
+
function ReadableStreamReaderGenericRelease(reader2) {
|
|
74599
|
+
const stream2 = reader2._ownerReadableStream;
|
|
74600
74600
|
if (stream2._state === "readable") {
|
|
74601
|
-
defaultReaderClosedPromiseReject(
|
|
74601
|
+
defaultReaderClosedPromiseReject(reader2, new TypeError(`Reader was released and can no longer be used to monitor the stream's closedness`));
|
|
74602
74602
|
} else {
|
|
74603
|
-
defaultReaderClosedPromiseResetToRejected(
|
|
74603
|
+
defaultReaderClosedPromiseResetToRejected(reader2, new TypeError(`Reader was released and can no longer be used to monitor the stream's closedness`));
|
|
74604
74604
|
}
|
|
74605
74605
|
stream2._readableStreamController[ReleaseSteps]();
|
|
74606
74606
|
stream2._reader = void 0;
|
|
74607
|
-
|
|
74607
|
+
reader2._ownerReadableStream = void 0;
|
|
74608
74608
|
}
|
|
74609
74609
|
function readerLockException(name) {
|
|
74610
74610
|
return new TypeError("Cannot " + name + " a stream using a released reader");
|
|
74611
74611
|
}
|
|
74612
|
-
function defaultReaderClosedPromiseInitialize(
|
|
74613
|
-
|
|
74614
|
-
|
|
74615
|
-
|
|
74612
|
+
function defaultReaderClosedPromiseInitialize(reader2) {
|
|
74613
|
+
reader2._closedPromise = newPromise((resolve6, reject) => {
|
|
74614
|
+
reader2._closedPromise_resolve = resolve6;
|
|
74615
|
+
reader2._closedPromise_reject = reject;
|
|
74616
74616
|
});
|
|
74617
74617
|
}
|
|
74618
|
-
function defaultReaderClosedPromiseInitializeAsRejected(
|
|
74619
|
-
defaultReaderClosedPromiseInitialize(
|
|
74620
|
-
defaultReaderClosedPromiseReject(
|
|
74618
|
+
function defaultReaderClosedPromiseInitializeAsRejected(reader2, reason) {
|
|
74619
|
+
defaultReaderClosedPromiseInitialize(reader2);
|
|
74620
|
+
defaultReaderClosedPromiseReject(reader2, reason);
|
|
74621
74621
|
}
|
|
74622
|
-
function defaultReaderClosedPromiseInitializeAsResolved(
|
|
74623
|
-
defaultReaderClosedPromiseInitialize(
|
|
74624
|
-
defaultReaderClosedPromiseResolve(
|
|
74622
|
+
function defaultReaderClosedPromiseInitializeAsResolved(reader2) {
|
|
74623
|
+
defaultReaderClosedPromiseInitialize(reader2);
|
|
74624
|
+
defaultReaderClosedPromiseResolve(reader2);
|
|
74625
74625
|
}
|
|
74626
|
-
function defaultReaderClosedPromiseReject(
|
|
74627
|
-
if (
|
|
74626
|
+
function defaultReaderClosedPromiseReject(reader2, reason) {
|
|
74627
|
+
if (reader2._closedPromise_reject === void 0) {
|
|
74628
74628
|
return;
|
|
74629
74629
|
}
|
|
74630
|
-
setPromiseIsHandledToTrue(
|
|
74631
|
-
|
|
74632
|
-
|
|
74633
|
-
|
|
74630
|
+
setPromiseIsHandledToTrue(reader2._closedPromise);
|
|
74631
|
+
reader2._closedPromise_reject(reason);
|
|
74632
|
+
reader2._closedPromise_resolve = void 0;
|
|
74633
|
+
reader2._closedPromise_reject = void 0;
|
|
74634
74634
|
}
|
|
74635
|
-
function defaultReaderClosedPromiseResetToRejected(
|
|
74636
|
-
defaultReaderClosedPromiseInitializeAsRejected(
|
|
74635
|
+
function defaultReaderClosedPromiseResetToRejected(reader2, reason) {
|
|
74636
|
+
defaultReaderClosedPromiseInitializeAsRejected(reader2, reason);
|
|
74637
74637
|
}
|
|
74638
|
-
function defaultReaderClosedPromiseResolve(
|
|
74639
|
-
if (
|
|
74638
|
+
function defaultReaderClosedPromiseResolve(reader2) {
|
|
74639
|
+
if (reader2._closedPromise_resolve === void 0) {
|
|
74640
74640
|
return;
|
|
74641
74641
|
}
|
|
74642
|
-
|
|
74643
|
-
|
|
74644
|
-
|
|
74642
|
+
reader2._closedPromise_resolve(void 0);
|
|
74643
|
+
reader2._closedPromise_resolve = void 0;
|
|
74644
|
+
reader2._closedPromise_reject = void 0;
|
|
74645
74645
|
}
|
|
74646
74646
|
const NumberIsFinite = Number.isFinite || function(x5) {
|
|
74647
74647
|
return typeof x5 === "number" && isFinite(x5);
|
|
@@ -74718,8 +74718,8 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
74718
74718
|
stream2._reader._readRequests.push(readRequest);
|
|
74719
74719
|
}
|
|
74720
74720
|
function ReadableStreamFulfillReadRequest(stream2, chunk, done) {
|
|
74721
|
-
const
|
|
74722
|
-
const readRequest =
|
|
74721
|
+
const reader2 = stream2._reader;
|
|
74722
|
+
const readRequest = reader2._readRequests.shift();
|
|
74723
74723
|
if (done) {
|
|
74724
74724
|
readRequest._closeSteps();
|
|
74725
74725
|
} else {
|
|
@@ -74730,11 +74730,11 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
74730
74730
|
return stream2._reader._readRequests.length;
|
|
74731
74731
|
}
|
|
74732
74732
|
function ReadableStreamHasDefaultReader(stream2) {
|
|
74733
|
-
const
|
|
74734
|
-
if (
|
|
74733
|
+
const reader2 = stream2._reader;
|
|
74734
|
+
if (reader2 === void 0) {
|
|
74735
74735
|
return false;
|
|
74736
74736
|
}
|
|
74737
|
-
if (!IsReadableStreamDefaultReader(
|
|
74737
|
+
if (!IsReadableStreamDefaultReader(reader2)) {
|
|
74738
74738
|
return false;
|
|
74739
74739
|
}
|
|
74740
74740
|
return true;
|
|
@@ -74840,8 +74840,8 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
74840
74840
|
}
|
|
74841
74841
|
return x5 instanceof ReadableStreamDefaultReader;
|
|
74842
74842
|
}
|
|
74843
|
-
function ReadableStreamDefaultReaderRead(
|
|
74844
|
-
const stream2 =
|
|
74843
|
+
function ReadableStreamDefaultReaderRead(reader2, readRequest) {
|
|
74844
|
+
const stream2 = reader2._ownerReadableStream;
|
|
74845
74845
|
stream2._disturbed = true;
|
|
74846
74846
|
if (stream2._state === "closed") {
|
|
74847
74847
|
readRequest._closeSteps();
|
|
@@ -74851,14 +74851,14 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
74851
74851
|
stream2._readableStreamController[PullSteps](readRequest);
|
|
74852
74852
|
}
|
|
74853
74853
|
}
|
|
74854
|
-
function ReadableStreamDefaultReaderRelease(
|
|
74855
|
-
ReadableStreamReaderGenericRelease(
|
|
74854
|
+
function ReadableStreamDefaultReaderRelease(reader2) {
|
|
74855
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
74856
74856
|
const e5 = new TypeError("Reader was released");
|
|
74857
|
-
ReadableStreamDefaultReaderErrorReadRequests(
|
|
74857
|
+
ReadableStreamDefaultReaderErrorReadRequests(reader2, e5);
|
|
74858
74858
|
}
|
|
74859
|
-
function ReadableStreamDefaultReaderErrorReadRequests(
|
|
74860
|
-
const readRequests =
|
|
74861
|
-
|
|
74859
|
+
function ReadableStreamDefaultReaderErrorReadRequests(reader2, e5) {
|
|
74860
|
+
const readRequests = reader2._readRequests;
|
|
74861
|
+
reader2._readRequests = new SimpleQueue();
|
|
74862
74862
|
readRequests.forEach((readRequest) => {
|
|
74863
74863
|
readRequest._errorSteps(e5);
|
|
74864
74864
|
});
|
|
@@ -74869,10 +74869,10 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
74869
74869
|
const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async function* () {
|
|
74870
74870
|
}).prototype);
|
|
74871
74871
|
class ReadableStreamAsyncIteratorImpl {
|
|
74872
|
-
constructor(
|
|
74872
|
+
constructor(reader2, preventCancel) {
|
|
74873
74873
|
this._ongoingPromise = void 0;
|
|
74874
74874
|
this._isFinished = false;
|
|
74875
|
-
this._reader =
|
|
74875
|
+
this._reader = reader2;
|
|
74876
74876
|
this._preventCancel = preventCancel;
|
|
74877
74877
|
}
|
|
74878
74878
|
next() {
|
|
@@ -74888,7 +74888,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
74888
74888
|
if (this._isFinished) {
|
|
74889
74889
|
return Promise.resolve({ value: void 0, done: true });
|
|
74890
74890
|
}
|
|
74891
|
-
const
|
|
74891
|
+
const reader2 = this._reader;
|
|
74892
74892
|
let resolvePromise;
|
|
74893
74893
|
let rejectPromise;
|
|
74894
74894
|
const promise2 = newPromise((resolve6, reject) => {
|
|
@@ -74903,17 +74903,17 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
74903
74903
|
_closeSteps: () => {
|
|
74904
74904
|
this._ongoingPromise = void 0;
|
|
74905
74905
|
this._isFinished = true;
|
|
74906
|
-
ReadableStreamReaderGenericRelease(
|
|
74906
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
74907
74907
|
resolvePromise({ value: void 0, done: true });
|
|
74908
74908
|
},
|
|
74909
74909
|
_errorSteps: (reason) => {
|
|
74910
74910
|
this._ongoingPromise = void 0;
|
|
74911
74911
|
this._isFinished = true;
|
|
74912
|
-
ReadableStreamReaderGenericRelease(
|
|
74912
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
74913
74913
|
rejectPromise(reason);
|
|
74914
74914
|
}
|
|
74915
74915
|
};
|
|
74916
|
-
ReadableStreamDefaultReaderRead(
|
|
74916
|
+
ReadableStreamDefaultReaderRead(reader2, readRequest);
|
|
74917
74917
|
return promise2;
|
|
74918
74918
|
}
|
|
74919
74919
|
_returnSteps(value) {
|
|
@@ -74921,13 +74921,13 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
74921
74921
|
return Promise.resolve({ value, done: true });
|
|
74922
74922
|
}
|
|
74923
74923
|
this._isFinished = true;
|
|
74924
|
-
const
|
|
74924
|
+
const reader2 = this._reader;
|
|
74925
74925
|
if (!this._preventCancel) {
|
|
74926
|
-
const result = ReadableStreamReaderGenericCancel(
|
|
74927
|
-
ReadableStreamReaderGenericRelease(
|
|
74926
|
+
const result = ReadableStreamReaderGenericCancel(reader2, value);
|
|
74927
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
74928
74928
|
return transformPromiseWith(result, () => ({ value, done: true }));
|
|
74929
74929
|
}
|
|
74930
|
-
ReadableStreamReaderGenericRelease(
|
|
74930
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
74931
74931
|
return promiseResolvedWith({ value, done: true });
|
|
74932
74932
|
}
|
|
74933
74933
|
}
|
|
@@ -74947,8 +74947,8 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
74947
74947
|
};
|
|
74948
74948
|
Object.setPrototypeOf(ReadableStreamAsyncIteratorPrototype, AsyncIteratorPrototype);
|
|
74949
74949
|
function AcquireReadableStreamAsyncIterator(stream2, preventCancel) {
|
|
74950
|
-
const
|
|
74951
|
-
const impl = new ReadableStreamAsyncIteratorImpl(
|
|
74950
|
+
const reader2 = AcquireReadableStreamDefaultReader(stream2);
|
|
74951
|
+
const impl = new ReadableStreamAsyncIteratorImpl(reader2, preventCancel);
|
|
74952
74952
|
const iterator = Object.create(ReadableStreamAsyncIteratorPrototype);
|
|
74953
74953
|
iterator._asyncIteratorImpl = impl;
|
|
74954
74954
|
return iterator;
|
|
@@ -75452,12 +75452,12 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
75452
75452
|
}
|
|
75453
75453
|
}
|
|
75454
75454
|
function ReadableByteStreamControllerProcessReadRequestsUsingQueue(controller) {
|
|
75455
|
-
const
|
|
75456
|
-
while (
|
|
75455
|
+
const reader2 = controller._controlledReadableByteStream._reader;
|
|
75456
|
+
while (reader2._readRequests.length > 0) {
|
|
75457
75457
|
if (controller._queueTotalSize === 0) {
|
|
75458
75458
|
return;
|
|
75459
75459
|
}
|
|
75460
|
-
const readRequest =
|
|
75460
|
+
const readRequest = reader2._readRequests.shift();
|
|
75461
75461
|
ReadableByteStreamControllerFillReadRequestFromQueue(controller, readRequest);
|
|
75462
75462
|
}
|
|
75463
75463
|
}
|
|
@@ -75817,8 +75817,8 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
75817
75817
|
stream2._reader._readIntoRequests.push(readIntoRequest);
|
|
75818
75818
|
}
|
|
75819
75819
|
function ReadableStreamFulfillReadIntoRequest(stream2, chunk, done) {
|
|
75820
|
-
const
|
|
75821
|
-
const readIntoRequest =
|
|
75820
|
+
const reader2 = stream2._reader;
|
|
75821
|
+
const readIntoRequest = reader2._readIntoRequests.shift();
|
|
75822
75822
|
if (done) {
|
|
75823
75823
|
readIntoRequest._closeSteps(chunk);
|
|
75824
75824
|
} else {
|
|
@@ -75829,11 +75829,11 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
75829
75829
|
return stream2._reader._readIntoRequests.length;
|
|
75830
75830
|
}
|
|
75831
75831
|
function ReadableStreamHasBYOBReader(stream2) {
|
|
75832
|
-
const
|
|
75833
|
-
if (
|
|
75832
|
+
const reader2 = stream2._reader;
|
|
75833
|
+
if (reader2 === void 0) {
|
|
75834
75834
|
return false;
|
|
75835
75835
|
}
|
|
75836
|
-
if (!IsReadableStreamBYOBReader(
|
|
75836
|
+
if (!IsReadableStreamBYOBReader(reader2)) {
|
|
75837
75837
|
return false;
|
|
75838
75838
|
}
|
|
75839
75839
|
return true;
|
|
@@ -75966,8 +75966,8 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
75966
75966
|
}
|
|
75967
75967
|
return x5 instanceof ReadableStreamBYOBReader;
|
|
75968
75968
|
}
|
|
75969
|
-
function ReadableStreamBYOBReaderRead(
|
|
75970
|
-
const stream2 =
|
|
75969
|
+
function ReadableStreamBYOBReaderRead(reader2, view, min, readIntoRequest) {
|
|
75970
|
+
const stream2 = reader2._ownerReadableStream;
|
|
75971
75971
|
stream2._disturbed = true;
|
|
75972
75972
|
if (stream2._state === "errored") {
|
|
75973
75973
|
readIntoRequest._errorSteps(stream2._storedError);
|
|
@@ -75975,14 +75975,14 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
75975
75975
|
ReadableByteStreamControllerPullInto(stream2._readableStreamController, view, min, readIntoRequest);
|
|
75976
75976
|
}
|
|
75977
75977
|
}
|
|
75978
|
-
function ReadableStreamBYOBReaderRelease(
|
|
75979
|
-
ReadableStreamReaderGenericRelease(
|
|
75978
|
+
function ReadableStreamBYOBReaderRelease(reader2) {
|
|
75979
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
75980
75980
|
const e5 = new TypeError("Reader was released");
|
|
75981
|
-
ReadableStreamBYOBReaderErrorReadIntoRequests(
|
|
75981
|
+
ReadableStreamBYOBReaderErrorReadIntoRequests(reader2, e5);
|
|
75982
75982
|
}
|
|
75983
|
-
function ReadableStreamBYOBReaderErrorReadIntoRequests(
|
|
75984
|
-
const readIntoRequests =
|
|
75985
|
-
|
|
75983
|
+
function ReadableStreamBYOBReaderErrorReadIntoRequests(reader2, e5) {
|
|
75984
|
+
const readIntoRequests = reader2._readIntoRequests;
|
|
75985
|
+
reader2._readIntoRequests = new SimpleQueue();
|
|
75986
75986
|
readIntoRequests.forEach((readIntoRequest) => {
|
|
75987
75987
|
readIntoRequest._errorSteps(e5);
|
|
75988
75988
|
});
|
|
@@ -76997,7 +76997,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
76997
76997
|
}
|
|
76998
76998
|
const DOMException3 = getFromGlobal() || createPolyfill();
|
|
76999
76999
|
function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventCancel, signal) {
|
|
77000
|
-
const
|
|
77000
|
+
const reader2 = AcquireReadableStreamDefaultReader(source);
|
|
77001
77001
|
const writer = AcquireWritableStreamDefaultWriter(dest);
|
|
77002
77002
|
source._disturbed = true;
|
|
77003
77003
|
let shuttingDown = false;
|
|
@@ -77050,7 +77050,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
77050
77050
|
}
|
|
77051
77051
|
return PerformPromiseThen(writer._readyPromise, () => {
|
|
77052
77052
|
return newPromise((resolveRead, rejectRead) => {
|
|
77053
|
-
ReadableStreamDefaultReaderRead(
|
|
77053
|
+
ReadableStreamDefaultReaderRead(reader2, {
|
|
77054
77054
|
_chunkSteps: (chunk) => {
|
|
77055
77055
|
currentWrite = PerformPromiseThen(WritableStreamDefaultWriterWrite(writer, chunk), void 0, noop5);
|
|
77056
77056
|
resolveRead(false);
|
|
@@ -77061,7 +77061,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
77061
77061
|
});
|
|
77062
77062
|
});
|
|
77063
77063
|
}
|
|
77064
|
-
isOrBecomesErrored(source,
|
|
77064
|
+
isOrBecomesErrored(source, reader2._closedPromise, (storedError) => {
|
|
77065
77065
|
if (!preventAbort) {
|
|
77066
77066
|
shutdownWithAction(() => WritableStreamAbort(dest, storedError), true, storedError);
|
|
77067
77067
|
} else {
|
|
@@ -77077,7 +77077,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
77077
77077
|
}
|
|
77078
77078
|
return null;
|
|
77079
77079
|
});
|
|
77080
|
-
isOrBecomesClosed(source,
|
|
77080
|
+
isOrBecomesClosed(source, reader2._closedPromise, () => {
|
|
77081
77081
|
if (!preventClose) {
|
|
77082
77082
|
shutdownWithAction(() => WritableStreamDefaultWriterCloseWithErrorPropagation(writer));
|
|
77083
77083
|
} else {
|
|
@@ -77140,7 +77140,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
77140
77140
|
}
|
|
77141
77141
|
function finalize(isError, error40) {
|
|
77142
77142
|
WritableStreamDefaultWriterRelease(writer);
|
|
77143
|
-
ReadableStreamReaderGenericRelease(
|
|
77143
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
77144
77144
|
if (signal !== void 0) {
|
|
77145
77145
|
signal.removeEventListener("abort", abortAlgorithm);
|
|
77146
77146
|
}
|
|
@@ -77418,7 +77418,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
77418
77418
|
return ReadableStreamDefaultTee(stream2);
|
|
77419
77419
|
}
|
|
77420
77420
|
function ReadableStreamDefaultTee(stream2, cloneForBranch2) {
|
|
77421
|
-
const
|
|
77421
|
+
const reader2 = AcquireReadableStreamDefaultReader(stream2);
|
|
77422
77422
|
let reading = false;
|
|
77423
77423
|
let readAgain = false;
|
|
77424
77424
|
let canceled1 = false;
|
|
@@ -77471,7 +77471,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
77471
77471
|
reading = false;
|
|
77472
77472
|
}
|
|
77473
77473
|
};
|
|
77474
|
-
ReadableStreamDefaultReaderRead(
|
|
77474
|
+
ReadableStreamDefaultReaderRead(reader2, readRequest);
|
|
77475
77475
|
return promiseResolvedWith(void 0);
|
|
77476
77476
|
}
|
|
77477
77477
|
function cancel1Algorithm(reason) {
|
|
@@ -77498,7 +77498,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
77498
77498
|
}
|
|
77499
77499
|
branch1 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancel1Algorithm);
|
|
77500
77500
|
branch2 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancel2Algorithm);
|
|
77501
|
-
uponRejection(
|
|
77501
|
+
uponRejection(reader2._closedPromise, (r6) => {
|
|
77502
77502
|
ReadableStreamDefaultControllerError(branch1._readableStreamController, r6);
|
|
77503
77503
|
ReadableStreamDefaultControllerError(branch2._readableStreamController, r6);
|
|
77504
77504
|
if (!canceled1 || !canceled2) {
|
|
@@ -77509,7 +77509,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
77509
77509
|
return [branch1, branch2];
|
|
77510
77510
|
}
|
|
77511
77511
|
function ReadableByteStreamTee(stream2) {
|
|
77512
|
-
let
|
|
77512
|
+
let reader2 = AcquireReadableStreamDefaultReader(stream2);
|
|
77513
77513
|
let reading = false;
|
|
77514
77514
|
let readAgainForBranch1 = false;
|
|
77515
77515
|
let readAgainForBranch2 = false;
|
|
@@ -77525,7 +77525,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
77525
77525
|
});
|
|
77526
77526
|
function forwardReaderError(thisReader) {
|
|
77527
77527
|
uponRejection(thisReader._closedPromise, (r6) => {
|
|
77528
|
-
if (thisReader !==
|
|
77528
|
+
if (thisReader !== reader2) {
|
|
77529
77529
|
return null;
|
|
77530
77530
|
}
|
|
77531
77531
|
ReadableByteStreamControllerError(branch1._readableStreamController, r6);
|
|
@@ -77537,10 +77537,10 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
77537
77537
|
});
|
|
77538
77538
|
}
|
|
77539
77539
|
function pullWithDefaultReader() {
|
|
77540
|
-
if (IsReadableStreamBYOBReader(
|
|
77541
|
-
ReadableStreamReaderGenericRelease(
|
|
77542
|
-
|
|
77543
|
-
forwardReaderError(
|
|
77540
|
+
if (IsReadableStreamBYOBReader(reader2)) {
|
|
77541
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
77542
|
+
reader2 = AcquireReadableStreamDefaultReader(stream2);
|
|
77543
|
+
forwardReaderError(reader2);
|
|
77544
77544
|
}
|
|
77545
77545
|
const readRequest = {
|
|
77546
77546
|
_chunkSteps: (chunk) => {
|
|
@@ -77595,13 +77595,13 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
77595
77595
|
reading = false;
|
|
77596
77596
|
}
|
|
77597
77597
|
};
|
|
77598
|
-
ReadableStreamDefaultReaderRead(
|
|
77598
|
+
ReadableStreamDefaultReaderRead(reader2, readRequest);
|
|
77599
77599
|
}
|
|
77600
77600
|
function pullWithBYOBReader(view, forBranch2) {
|
|
77601
|
-
if (IsReadableStreamDefaultReader(
|
|
77602
|
-
ReadableStreamReaderGenericRelease(
|
|
77603
|
-
|
|
77604
|
-
forwardReaderError(
|
|
77601
|
+
if (IsReadableStreamDefaultReader(reader2)) {
|
|
77602
|
+
ReadableStreamReaderGenericRelease(reader2);
|
|
77603
|
+
reader2 = AcquireReadableStreamBYOBReader(stream2);
|
|
77604
|
+
forwardReaderError(reader2);
|
|
77605
77605
|
}
|
|
77606
77606
|
const byobBranch = forBranch2 ? branch2 : branch1;
|
|
77607
77607
|
const otherBranch = forBranch2 ? branch1 : branch2;
|
|
@@ -77663,7 +77663,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
77663
77663
|
reading = false;
|
|
77664
77664
|
}
|
|
77665
77665
|
};
|
|
77666
|
-
ReadableStreamBYOBReaderRead(
|
|
77666
|
+
ReadableStreamBYOBReaderRead(reader2, view, 1, readIntoRequest);
|
|
77667
77667
|
}
|
|
77668
77668
|
function pull1Algorithm() {
|
|
77669
77669
|
if (reading) {
|
|
@@ -77718,7 +77718,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
77718
77718
|
}
|
|
77719
77719
|
branch1 = CreateReadableByteStream(startAlgorithm, pull1Algorithm, cancel1Algorithm);
|
|
77720
77720
|
branch2 = CreateReadableByteStream(startAlgorithm, pull2Algorithm, cancel2Algorithm);
|
|
77721
|
-
forwardReaderError(
|
|
77721
|
+
forwardReaderError(reader2);
|
|
77722
77722
|
return [branch1, branch2];
|
|
77723
77723
|
}
|
|
77724
77724
|
function isReadableStreamLike(stream2) {
|
|
@@ -77783,13 +77783,13 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
77783
77783
|
stream2 = CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, 0);
|
|
77784
77784
|
return stream2;
|
|
77785
77785
|
}
|
|
77786
|
-
function ReadableStreamFromDefaultReader(
|
|
77786
|
+
function ReadableStreamFromDefaultReader(reader2) {
|
|
77787
77787
|
let stream2;
|
|
77788
77788
|
const startAlgorithm = noop5;
|
|
77789
77789
|
function pullAlgorithm() {
|
|
77790
77790
|
let readPromise;
|
|
77791
77791
|
try {
|
|
77792
|
-
readPromise =
|
|
77792
|
+
readPromise = reader2.read();
|
|
77793
77793
|
} catch (e5) {
|
|
77794
77794
|
return promiseRejectedWith(e5);
|
|
77795
77795
|
}
|
|
@@ -77807,7 +77807,7 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
77807
77807
|
}
|
|
77808
77808
|
function cancelAlgorithm(reason) {
|
|
77809
77809
|
try {
|
|
77810
|
-
return promiseResolvedWith(
|
|
77810
|
+
return promiseResolvedWith(reader2.cancel(reason));
|
|
77811
77811
|
} catch (e5) {
|
|
77812
77812
|
return promiseRejectedWith(e5);
|
|
77813
77813
|
}
|
|
@@ -78095,10 +78095,10 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
78095
78095
|
return promiseRejectedWith(stream2._storedError);
|
|
78096
78096
|
}
|
|
78097
78097
|
ReadableStreamClose(stream2);
|
|
78098
|
-
const
|
|
78099
|
-
if (
|
|
78100
|
-
const readIntoRequests =
|
|
78101
|
-
|
|
78098
|
+
const reader2 = stream2._reader;
|
|
78099
|
+
if (reader2 !== void 0 && IsReadableStreamBYOBReader(reader2)) {
|
|
78100
|
+
const readIntoRequests = reader2._readIntoRequests;
|
|
78101
|
+
reader2._readIntoRequests = new SimpleQueue();
|
|
78102
78102
|
readIntoRequests.forEach((readIntoRequest) => {
|
|
78103
78103
|
readIntoRequest._closeSteps(void 0);
|
|
78104
78104
|
});
|
|
@@ -78108,14 +78108,14 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
78108
78108
|
}
|
|
78109
78109
|
function ReadableStreamClose(stream2) {
|
|
78110
78110
|
stream2._state = "closed";
|
|
78111
|
-
const
|
|
78112
|
-
if (
|
|
78111
|
+
const reader2 = stream2._reader;
|
|
78112
|
+
if (reader2 === void 0) {
|
|
78113
78113
|
return;
|
|
78114
78114
|
}
|
|
78115
|
-
defaultReaderClosedPromiseResolve(
|
|
78116
|
-
if (IsReadableStreamDefaultReader(
|
|
78117
|
-
const readRequests =
|
|
78118
|
-
|
|
78115
|
+
defaultReaderClosedPromiseResolve(reader2);
|
|
78116
|
+
if (IsReadableStreamDefaultReader(reader2)) {
|
|
78117
|
+
const readRequests = reader2._readRequests;
|
|
78118
|
+
reader2._readRequests = new SimpleQueue();
|
|
78119
78119
|
readRequests.forEach((readRequest) => {
|
|
78120
78120
|
readRequest._closeSteps();
|
|
78121
78121
|
});
|
|
@@ -78124,15 +78124,15 @@ var require_ponyfill_es2018 = __commonJS({
|
|
|
78124
78124
|
function ReadableStreamError(stream2, e5) {
|
|
78125
78125
|
stream2._state = "errored";
|
|
78126
78126
|
stream2._storedError = e5;
|
|
78127
|
-
const
|
|
78128
|
-
if (
|
|
78127
|
+
const reader2 = stream2._reader;
|
|
78128
|
+
if (reader2 === void 0) {
|
|
78129
78129
|
return;
|
|
78130
78130
|
}
|
|
78131
|
-
defaultReaderClosedPromiseReject(
|
|
78132
|
-
if (IsReadableStreamDefaultReader(
|
|
78133
|
-
ReadableStreamDefaultReaderErrorReadRequests(
|
|
78131
|
+
defaultReaderClosedPromiseReject(reader2, e5);
|
|
78132
|
+
if (IsReadableStreamDefaultReader(reader2)) {
|
|
78133
|
+
ReadableStreamDefaultReaderErrorReadRequests(reader2, e5);
|
|
78134
78134
|
} else {
|
|
78135
|
-
ReadableStreamBYOBReaderErrorReadIntoRequests(
|
|
78135
|
+
ReadableStreamBYOBReaderErrorReadIntoRequests(reader2, e5);
|
|
78136
78136
|
}
|
|
78137
78137
|
}
|
|
78138
78138
|
function streamBrandCheckException$1(name) {
|
|
@@ -81772,7 +81772,7 @@ var require_bignumber = __commonJS({
|
|
|
81772
81772
|
}
|
|
81773
81773
|
return arr.reverse();
|
|
81774
81774
|
}
|
|
81775
|
-
return function(str2, baseIn, baseOut,
|
|
81775
|
+
return function(str2, baseIn, baseOut, sign2, callerIsToString) {
|
|
81776
81776
|
var alphabet, d4, e5, k6, r6, x5, xc, y6, i4 = str2.indexOf("."), dp = DECIMAL_PLACES, rm3 = ROUNDING_MODE;
|
|
81777
81777
|
if (i4 >= 0) {
|
|
81778
81778
|
k6 = POW_PRECISION;
|
|
@@ -81798,7 +81798,7 @@ var require_bignumber = __commonJS({
|
|
|
81798
81798
|
} else {
|
|
81799
81799
|
x5.c = xc;
|
|
81800
81800
|
x5.e = e5;
|
|
81801
|
-
x5.s =
|
|
81801
|
+
x5.s = sign2;
|
|
81802
81802
|
x5 = div(x5, y6, dp, rm3, baseOut);
|
|
81803
81803
|
xc = x5.c;
|
|
81804
81804
|
r6 = x5.r;
|
|
@@ -86017,7 +86017,7 @@ var require_jwa = __commonJS({
|
|
|
86017
86017
|
return thing;
|
|
86018
86018
|
}
|
|
86019
86019
|
function createHmacSigner(bits) {
|
|
86020
|
-
return function
|
|
86020
|
+
return function sign2(thing, secret) {
|
|
86021
86021
|
checkIsSecretKey(secret);
|
|
86022
86022
|
thing = normalizeInput(thing);
|
|
86023
86023
|
var hmac = crypto2.createHmac("sha" + bits, secret);
|
|
@@ -86026,25 +86026,25 @@ var require_jwa = __commonJS({
|
|
|
86026
86026
|
};
|
|
86027
86027
|
}
|
|
86028
86028
|
var bufferEqual;
|
|
86029
|
-
var
|
|
86029
|
+
var timingSafeEqual2 = "timingSafeEqual" in crypto2 ? function timingSafeEqual3(a4, b4) {
|
|
86030
86030
|
if (a4.byteLength !== b4.byteLength) {
|
|
86031
86031
|
return false;
|
|
86032
86032
|
}
|
|
86033
86033
|
return crypto2.timingSafeEqual(a4, b4);
|
|
86034
|
-
} : function
|
|
86034
|
+
} : function timingSafeEqual3(a4, b4) {
|
|
86035
86035
|
if (!bufferEqual) {
|
|
86036
86036
|
bufferEqual = require_buffer_equal_constant_time();
|
|
86037
86037
|
}
|
|
86038
86038
|
return bufferEqual(a4, b4);
|
|
86039
86039
|
};
|
|
86040
86040
|
function createHmacVerifier(bits) {
|
|
86041
|
-
return function
|
|
86041
|
+
return function verify2(thing, signature, secret) {
|
|
86042
86042
|
var computedSig = createHmacSigner(bits)(thing, secret);
|
|
86043
|
-
return
|
|
86043
|
+
return timingSafeEqual2(Buffer5.from(signature), Buffer5.from(computedSig));
|
|
86044
86044
|
};
|
|
86045
86045
|
}
|
|
86046
86046
|
function createKeySigner(bits) {
|
|
86047
|
-
return function
|
|
86047
|
+
return function sign2(thing, privateKey) {
|
|
86048
86048
|
checkIsPrivateKey(privateKey);
|
|
86049
86049
|
thing = normalizeInput(thing);
|
|
86050
86050
|
var signer = crypto2.createSign("RSA-SHA" + bits);
|
|
@@ -86053,7 +86053,7 @@ var require_jwa = __commonJS({
|
|
|
86053
86053
|
};
|
|
86054
86054
|
}
|
|
86055
86055
|
function createKeyVerifier(bits) {
|
|
86056
|
-
return function
|
|
86056
|
+
return function verify2(thing, signature, publicKey) {
|
|
86057
86057
|
checkIsPublicKey(publicKey);
|
|
86058
86058
|
thing = normalizeInput(thing);
|
|
86059
86059
|
signature = toBase64(signature);
|
|
@@ -86063,7 +86063,7 @@ var require_jwa = __commonJS({
|
|
|
86063
86063
|
};
|
|
86064
86064
|
}
|
|
86065
86065
|
function createPSSKeySigner(bits) {
|
|
86066
|
-
return function
|
|
86066
|
+
return function sign2(thing, privateKey) {
|
|
86067
86067
|
checkIsPrivateKey(privateKey);
|
|
86068
86068
|
thing = normalizeInput(thing);
|
|
86069
86069
|
var signer = crypto2.createSign("RSA-SHA" + bits);
|
|
@@ -86076,7 +86076,7 @@ var require_jwa = __commonJS({
|
|
|
86076
86076
|
};
|
|
86077
86077
|
}
|
|
86078
86078
|
function createPSSKeyVerifier(bits) {
|
|
86079
|
-
return function
|
|
86079
|
+
return function verify2(thing, signature, publicKey) {
|
|
86080
86080
|
checkIsPublicKey(publicKey);
|
|
86081
86081
|
thing = normalizeInput(thing);
|
|
86082
86082
|
signature = toBase64(signature);
|
|
@@ -86091,7 +86091,7 @@ var require_jwa = __commonJS({
|
|
|
86091
86091
|
}
|
|
86092
86092
|
function createECDSASigner(bits) {
|
|
86093
86093
|
var inner = createKeySigner(bits);
|
|
86094
|
-
return function
|
|
86094
|
+
return function sign2() {
|
|
86095
86095
|
var signature = inner.apply(null, arguments);
|
|
86096
86096
|
signature = formatEcdsa.derToJose(signature, "ES" + bits);
|
|
86097
86097
|
return signature;
|
|
@@ -86099,19 +86099,19 @@ var require_jwa = __commonJS({
|
|
|
86099
86099
|
}
|
|
86100
86100
|
function createECDSAVerifer(bits) {
|
|
86101
86101
|
var inner = createKeyVerifier(bits);
|
|
86102
|
-
return function
|
|
86102
|
+
return function verify2(thing, signature, publicKey) {
|
|
86103
86103
|
signature = formatEcdsa.joseToDer(signature, "ES" + bits).toString("base64");
|
|
86104
86104
|
var result = inner(thing, signature, publicKey);
|
|
86105
86105
|
return result;
|
|
86106
86106
|
};
|
|
86107
86107
|
}
|
|
86108
86108
|
function createNoneSigner() {
|
|
86109
|
-
return function
|
|
86109
|
+
return function sign2() {
|
|
86110
86110
|
return "";
|
|
86111
86111
|
};
|
|
86112
86112
|
}
|
|
86113
86113
|
function createNoneVerifier() {
|
|
86114
|
-
return function
|
|
86114
|
+
return function verify2(thing, signature) {
|
|
86115
86115
|
return signature === "";
|
|
86116
86116
|
};
|
|
86117
86117
|
}
|
|
@@ -86212,7 +86212,7 @@ var require_sign_stream = __commonJS({
|
|
|
86212
86212
|
}.bind(this));
|
|
86213
86213
|
}
|
|
86214
86214
|
util2.inherits(SignStream, Stream7);
|
|
86215
|
-
SignStream.prototype.sign = function
|
|
86215
|
+
SignStream.prototype.sign = function sign2() {
|
|
86216
86216
|
try {
|
|
86217
86217
|
var signature = jwsSign({
|
|
86218
86218
|
header: this.header,
|
|
@@ -86331,7 +86331,7 @@ var require_verify_stream = __commonJS({
|
|
|
86331
86331
|
}.bind(this));
|
|
86332
86332
|
}
|
|
86333
86333
|
util2.inherits(VerifyStream, Stream7);
|
|
86334
|
-
VerifyStream.prototype.verify = function
|
|
86334
|
+
VerifyStream.prototype.verify = function verify2() {
|
|
86335
86335
|
try {
|
|
86336
86336
|
var valid = jwsVerify(this.signature.buffer, this.algorithm, this.key.buffer);
|
|
86337
86337
|
var obj = jwsDecode(this.signature.buffer, this.encoding);
|
|
@@ -88688,14 +88688,14 @@ var require_awsrequestsigner = __commonJS({
|
|
|
88688
88688
|
}
|
|
88689
88689
|
};
|
|
88690
88690
|
exports.AwsRequestSigner = AwsRequestSigner;
|
|
88691
|
-
async function
|
|
88691
|
+
async function sign2(crypto2, key, msg) {
|
|
88692
88692
|
return await crypto2.signWithHmacSha256(key, msg);
|
|
88693
88693
|
}
|
|
88694
88694
|
async function getSigningKey(crypto2, key, dateStamp, region, serviceName) {
|
|
88695
|
-
const kDate = await
|
|
88696
|
-
const kRegion = await
|
|
88697
|
-
const kService = await
|
|
88698
|
-
const kSigning = await
|
|
88695
|
+
const kDate = await sign2(crypto2, `AWS4${key}`, dateStamp);
|
|
88696
|
+
const kRegion = await sign2(crypto2, kDate, region);
|
|
88697
|
+
const kService = await sign2(crypto2, kRegion, serviceName);
|
|
88698
|
+
const kSigning = await sign2(crypto2, kService, "aws4_request");
|
|
88699
88699
|
return kSigning;
|
|
88700
88700
|
}
|
|
88701
88701
|
async function generateAuthenticationHeaderMap(options) {
|
|
@@ -88739,7 +88739,7 @@ ${amzDate}
|
|
|
88739
88739
|
${credentialScope}
|
|
88740
88740
|
` + await options.crypto.sha256DigestHex(canonicalRequest);
|
|
88741
88741
|
const signingKey = await getSigningKey(options.crypto, options.securityCredentials.secretAccessKey, dateStamp, options.region, serviceName);
|
|
88742
|
-
const signature = await
|
|
88742
|
+
const signature = await sign2(options.crypto, signingKey, stringToSign);
|
|
88743
88743
|
const authorizationHeader = `${AWS_ALGORITHM} Credential=${options.securityCredentials.accessKeyId}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${(0, crypto_1.fromArrayBufferToHex)(signature)}`;
|
|
88744
88744
|
return {
|
|
88745
88745
|
// Do not return x-amz-date if date is available.
|
|
@@ -90724,8 +90724,8 @@ var require_googleauth = __commonJS({
|
|
|
90724
90724
|
}
|
|
90725
90725
|
const crypto2 = (0, crypto_1.createCrypto)();
|
|
90726
90726
|
if (client instanceof jwtclient_1.JWT && client.key) {
|
|
90727
|
-
const
|
|
90728
|
-
return
|
|
90727
|
+
const sign2 = await crypto2.sign(client.key, data);
|
|
90728
|
+
return sign2;
|
|
90729
90729
|
}
|
|
90730
90730
|
const creds = await this.getCredentials();
|
|
90731
90731
|
if (!creds.client_email) {
|
|
@@ -93408,7 +93408,7 @@ var require_websocket = __commonJS({
|
|
|
93408
93408
|
var http3 = __require("http");
|
|
93409
93409
|
var net = __require("net");
|
|
93410
93410
|
var tls = __require("tls");
|
|
93411
|
-
var { randomBytes:
|
|
93411
|
+
var { randomBytes: randomBytes3, createHash: createHash20 } = __require("crypto");
|
|
93412
93412
|
var { Duplex, Readable: Readable3 } = __require("stream");
|
|
93413
93413
|
var { URL: URL2 } = __require("url");
|
|
93414
93414
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -93946,7 +93946,7 @@ var require_websocket = __commonJS({
|
|
|
93946
93946
|
}
|
|
93947
93947
|
}
|
|
93948
93948
|
const defaultPort = isSecure ? 443 : 80;
|
|
93949
|
-
const key =
|
|
93949
|
+
const key = randomBytes3(16).toString("base64");
|
|
93950
93950
|
const request = isSecure ? https2.request : http3.request;
|
|
93951
93951
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
93952
93952
|
let perMessageDeflate;
|
|
@@ -104257,22 +104257,22 @@ function ReadableStreamFrom3(iterable) {
|
|
|
104257
104257
|
function ReadableStreamToAsyncIterable3(stream2) {
|
|
104258
104258
|
if (stream2[Symbol.asyncIterator])
|
|
104259
104259
|
return stream2;
|
|
104260
|
-
const
|
|
104260
|
+
const reader2 = stream2.getReader();
|
|
104261
104261
|
return {
|
|
104262
104262
|
async next() {
|
|
104263
104263
|
try {
|
|
104264
|
-
const result = await
|
|
104264
|
+
const result = await reader2.read();
|
|
104265
104265
|
if (result === null || result === void 0 ? void 0 : result.done)
|
|
104266
|
-
|
|
104266
|
+
reader2.releaseLock();
|
|
104267
104267
|
return result;
|
|
104268
104268
|
} catch (e5) {
|
|
104269
|
-
|
|
104269
|
+
reader2.releaseLock();
|
|
104270
104270
|
throw e5;
|
|
104271
104271
|
}
|
|
104272
104272
|
},
|
|
104273
104273
|
async return() {
|
|
104274
|
-
const cancelPromise =
|
|
104275
|
-
|
|
104274
|
+
const cancelPromise = reader2.cancel();
|
|
104275
|
+
reader2.releaseLock();
|
|
104276
104276
|
await cancelPromise;
|
|
104277
104277
|
return { done: true, value: void 0 };
|
|
104278
104278
|
},
|
|
@@ -104289,9 +104289,9 @@ async function CancelReadableStream3(stream2) {
|
|
|
104289
104289
|
await ((_b = (_a6 = stream2[Symbol.asyncIterator]()).return) === null || _b === void 0 ? void 0 : _b.call(_a6));
|
|
104290
104290
|
return;
|
|
104291
104291
|
}
|
|
104292
|
-
const
|
|
104293
|
-
const cancelPromise =
|
|
104294
|
-
|
|
104292
|
+
const reader2 = stream2.getReader();
|
|
104293
|
+
const cancelPromise = reader2.cancel();
|
|
104294
|
+
reader2.releaseLock();
|
|
104295
104295
|
await cancelPromise;
|
|
104296
104296
|
}
|
|
104297
104297
|
function stringifyQuery3(query) {
|
|
@@ -108165,9 +108165,9 @@ var init_node = __esm({
|
|
|
108165
108165
|
processStreamResponse(response) {
|
|
108166
108166
|
return __asyncGenerator(this, arguments, function* processStreamResponse_1() {
|
|
108167
108167
|
var _a6;
|
|
108168
|
-
const
|
|
108168
|
+
const reader2 = (_a6 = response === null || response === void 0 ? void 0 : response.body) === null || _a6 === void 0 ? void 0 : _a6.getReader();
|
|
108169
108169
|
const decoder2 = new TextDecoder("utf-8");
|
|
108170
|
-
if (!
|
|
108170
|
+
if (!reader2) {
|
|
108171
108171
|
throw new Error("Response body is empty");
|
|
108172
108172
|
}
|
|
108173
108173
|
try {
|
|
@@ -108175,7 +108175,7 @@ var init_node = __esm({
|
|
|
108175
108175
|
const dataPrefix = "data:";
|
|
108176
108176
|
const delimiters = ["\n\n", "\r\r", "\r\n\r\n"];
|
|
108177
108177
|
while (true) {
|
|
108178
|
-
const { done, value } = yield __await(
|
|
108178
|
+
const { done, value } = yield __await(reader2.read());
|
|
108179
108179
|
if (done) {
|
|
108180
108180
|
if (buffer.trim().length > 0) {
|
|
108181
108181
|
throw new Error("Incomplete JSON segment at the end");
|
|
@@ -108239,7 +108239,7 @@ var init_node = __esm({
|
|
|
108239
108239
|
}
|
|
108240
108240
|
}
|
|
108241
108241
|
} finally {
|
|
108242
|
-
|
|
108242
|
+
reader2.releaseLock();
|
|
108243
108243
|
}
|
|
108244
108244
|
});
|
|
108245
108245
|
}
|
|
@@ -113947,12 +113947,12 @@ var init_config3 = __esm({
|
|
|
113947
113947
|
|
|
113948
113948
|
// node_modules/@mistralai/mistralai/esm/lib/files.js
|
|
113949
113949
|
async function readableStreamToArrayBuffer(readable) {
|
|
113950
|
-
const
|
|
113950
|
+
const reader2 = readable.getReader();
|
|
113951
113951
|
const chunks = [];
|
|
113952
113952
|
let totalLength = 0;
|
|
113953
113953
|
let done = false;
|
|
113954
113954
|
while (!done) {
|
|
113955
|
-
const { value, done: doneReading } = await
|
|
113955
|
+
const { value, done: doneReading } = await reader2.read();
|
|
113956
113956
|
if (doneReading) {
|
|
113957
113957
|
done = true;
|
|
113958
113958
|
} else {
|
|
@@ -140774,24 +140774,24 @@ var init_event_streams = __esm({
|
|
|
140774
140774
|
const fn2 = ReadableStream.prototype[Symbol.asyncIterator];
|
|
140775
140775
|
if (typeof fn2 === "function")
|
|
140776
140776
|
return fn2.call(this);
|
|
140777
|
-
const
|
|
140777
|
+
const reader2 = this.getReader();
|
|
140778
140778
|
return {
|
|
140779
140779
|
next: async () => {
|
|
140780
|
-
const r6 = await
|
|
140780
|
+
const r6 = await reader2.read();
|
|
140781
140781
|
if (r6.done) {
|
|
140782
|
-
|
|
140782
|
+
reader2.releaseLock();
|
|
140783
140783
|
return { done: true, value: void 0 };
|
|
140784
140784
|
}
|
|
140785
140785
|
return { done: false, value: r6.value };
|
|
140786
140786
|
},
|
|
140787
140787
|
throw: async (e5) => {
|
|
140788
|
-
await
|
|
140789
|
-
|
|
140788
|
+
await reader2.cancel(e5);
|
|
140789
|
+
reader2.releaseLock();
|
|
140790
140790
|
return { done: true, value: void 0 };
|
|
140791
140791
|
},
|
|
140792
140792
|
return: async () => {
|
|
140793
|
-
await
|
|
140794
|
-
|
|
140793
|
+
await reader2.cancel("done");
|
|
140794
|
+
reader2.releaseLock();
|
|
140795
140795
|
return { done: true, value: void 0 };
|
|
140796
140796
|
},
|
|
140797
140797
|
[Symbol.asyncIterator]() {
|
|
@@ -168438,11 +168438,11 @@ function normalizeCodexStatus(status) {
|
|
|
168438
168438
|
async function* parseSSE(response, signal) {
|
|
168439
168439
|
if (!response.body)
|
|
168440
168440
|
return;
|
|
168441
|
-
const
|
|
168441
|
+
const reader2 = response.body.getReader();
|
|
168442
168442
|
const decoder2 = new TextDecoder();
|
|
168443
168443
|
let buffer = "";
|
|
168444
168444
|
const onAbort = () => {
|
|
168445
|
-
void
|
|
168445
|
+
void reader2.cancel().catch(() => {
|
|
168446
168446
|
});
|
|
168447
168447
|
};
|
|
168448
168448
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
@@ -168451,7 +168451,7 @@ async function* parseSSE(response, signal) {
|
|
|
168451
168451
|
if (signal?.aborted) {
|
|
168452
168452
|
throw new Error("Request was aborted");
|
|
168453
168453
|
}
|
|
168454
|
-
const { done, value } = await
|
|
168454
|
+
const { done, value } = await reader2.read();
|
|
168455
168455
|
if (signal?.aborted) {
|
|
168456
168456
|
throw new Error("Request was aborted");
|
|
168457
168457
|
}
|
|
@@ -168482,11 +168482,11 @@ async function* parseSSE(response, signal) {
|
|
|
168482
168482
|
} finally {
|
|
168483
168483
|
signal?.removeEventListener("abort", onAbort);
|
|
168484
168484
|
try {
|
|
168485
|
-
await
|
|
168485
|
+
await reader2.cancel();
|
|
168486
168486
|
} catch {
|
|
168487
168487
|
}
|
|
168488
168488
|
try {
|
|
168489
|
-
|
|
168489
|
+
reader2.releaseLock();
|
|
168490
168490
|
} catch {
|
|
168491
168491
|
}
|
|
168492
168492
|
}
|
|
@@ -177249,12 +177249,12 @@ async function readBoundedBody(response, maxBytes) {
|
|
|
177249
177249
|
throw new Error(`Provider media download exceeds the ${maxBytes}-byte limit`);
|
|
177250
177250
|
}
|
|
177251
177251
|
if (!response.body) throw new Error("Provider media download returned an empty response");
|
|
177252
|
-
const
|
|
177252
|
+
const reader2 = response.body.getReader();
|
|
177253
177253
|
const chunks = [];
|
|
177254
177254
|
let total = 0;
|
|
177255
177255
|
try {
|
|
177256
177256
|
while (true) {
|
|
177257
|
-
const { done, value } = await
|
|
177257
|
+
const { done, value } = await reader2.read();
|
|
177258
177258
|
if (done) break;
|
|
177259
177259
|
if (!value) continue;
|
|
177260
177260
|
total += value.byteLength;
|
|
@@ -177262,7 +177262,7 @@ async function readBoundedBody(response, maxBytes) {
|
|
|
177262
177262
|
chunks.push(value);
|
|
177263
177263
|
}
|
|
177264
177264
|
} finally {
|
|
177265
|
-
|
|
177265
|
+
reader2.releaseLock();
|
|
177266
177266
|
}
|
|
177267
177267
|
if (total === 0) throw new Error("Provider media download returned an empty response");
|
|
177268
177268
|
return Buffer.concat(chunks);
|
|
@@ -178111,7 +178111,7 @@ async function archiveExpiredBatch(_projectDir, options) {
|
|
|
178111
178111
|
const nextCursor = hasMore && scanned.length > 0 ? scanned[scanned.length - 1].id : void 0;
|
|
178112
178112
|
return nextCursor === void 0 ? { archived, scanned: scanned.length } : { archived, scanned: scanned.length, nextCursor };
|
|
178113
178113
|
}
|
|
178114
|
-
async function archiveExpired(projectDir2, referenceTime, accessMap, projectId,
|
|
178114
|
+
async function archiveExpired(projectDir2, referenceTime, accessMap, projectId, reader2) {
|
|
178115
178115
|
const store2 = getObservationStore();
|
|
178116
178116
|
if (projectId) {
|
|
178117
178117
|
let afterId;
|
|
@@ -178122,13 +178122,13 @@ async function archiveExpired(projectDir2, referenceTime, accessMap, projectId,
|
|
|
178122
178122
|
afterId,
|
|
178123
178123
|
referenceTime,
|
|
178124
178124
|
accessMap,
|
|
178125
|
-
reader
|
|
178125
|
+
reader: reader2
|
|
178126
178126
|
});
|
|
178127
178127
|
archived += batch.archived;
|
|
178128
178128
|
afterId = batch.nextCursor;
|
|
178129
178129
|
} while (afterId !== void 0);
|
|
178130
178130
|
const remainingObservations = await store2.loadByProject(projectId, { status: "active" });
|
|
178131
|
-
const remaining =
|
|
178131
|
+
const remaining = reader2 ? remainingObservations.filter((observation) => canManageObservation(observation, reader2)).length : remainingObservations.length;
|
|
178132
178132
|
return { archived, remaining };
|
|
178133
178133
|
}
|
|
178134
178134
|
return await store2.atomic(async (tx) => {
|
|
@@ -178588,21 +178588,21 @@ function assertPortableEvidence(scope, portability, evidence) {
|
|
|
178588
178588
|
throw new Error("Portable user memory may only use manual or user-confirmed evidence; project code, Git, observation, test, session, claim, and workflow evidence must remain project-bound.");
|
|
178589
178589
|
}
|
|
178590
178590
|
}
|
|
178591
|
-
function requireTeamReader(scope,
|
|
178592
|
-
if (scope === "team" &&
|
|
178591
|
+
function requireTeamReader(scope, reader2) {
|
|
178592
|
+
if (scope === "team" && reader2?.isTeamMember !== true) {
|
|
178593
178593
|
throw new Error("Team long-term memory requires an explicit active team identity for this project.");
|
|
178594
178594
|
}
|
|
178595
178595
|
}
|
|
178596
|
-
function matchesScope(memory,
|
|
178597
|
-
if (memory.scope === "project") return memory.originProjectId ===
|
|
178596
|
+
function matchesScope(memory, reader2) {
|
|
178597
|
+
if (memory.scope === "project") return memory.originProjectId === reader2.projectId;
|
|
178598
178598
|
if (memory.scope === "team") {
|
|
178599
|
-
return memory.originProjectId ===
|
|
178599
|
+
return memory.originProjectId === reader2.projectId && reader2.isTeamMember === true;
|
|
178600
178600
|
}
|
|
178601
|
-
if (!
|
|
178602
|
-
return memory.portability === "portable" || memory.originProjectId ===
|
|
178601
|
+
if (!reader2.ownerId || memory.ownerId !== reader2.ownerId) return false;
|
|
178602
|
+
return memory.portability === "portable" || memory.originProjectId === reader2.projectId;
|
|
178603
178603
|
}
|
|
178604
|
-
function canReadLongTermMemory(memory,
|
|
178605
|
-
return matchesScope(memory,
|
|
178604
|
+
function canReadLongTermMemory(memory, reader2) {
|
|
178605
|
+
return matchesScope(memory, reader2);
|
|
178606
178606
|
}
|
|
178607
178607
|
function isEligibleLongTermMemory(memory) {
|
|
178608
178608
|
return memory.state === "qualified" || memory.state === "approved";
|
|
@@ -178988,14 +178988,14 @@ async function selectLongTermMemoriesForTask(input) {
|
|
|
178988
178988
|
const task = input.task?.trim();
|
|
178989
178989
|
if (!task) return [];
|
|
178990
178990
|
const owner = await resolveLocalMemoryOwner(input.dataDir, { create: false });
|
|
178991
|
-
const
|
|
178991
|
+
const reader2 = {
|
|
178992
178992
|
projectId: input.projectId,
|
|
178993
178993
|
...owner ? { ownerId: owner.id } : {},
|
|
178994
178994
|
...input.agentId ? { agentId: input.agentId } : {},
|
|
178995
178995
|
...input.isTeamMember ? { isTeamMember: true } : {}
|
|
178996
178996
|
};
|
|
178997
178997
|
const store2 = await createStore(input.dataDir);
|
|
178998
|
-
const eligible = store2.list({ limit: 1e3 }).filter((memory) => isEligibleLongTermMemory(memory) && canReadLongTermMemory(memory,
|
|
178998
|
+
const eligible = store2.list({ limit: 1e3 }).filter((memory) => isEligibleLongTermMemory(memory) && canReadLongTermMemory(memory, reader2));
|
|
178999
178999
|
let selected = eligible.map((memory) => {
|
|
179000
179000
|
const ranked = scoreForTask(memory, task);
|
|
179001
179001
|
return ranked ? {
|
|
@@ -185899,11 +185899,11 @@ async function getObservationsByIds(ids, projectId) {
|
|
|
185899
185899
|
}
|
|
185900
185900
|
return results;
|
|
185901
185901
|
}
|
|
185902
|
-
async function getTimeline(anchorId, projectId, depthBefore = 3, depthAfter = 3,
|
|
185902
|
+
async function getTimeline(anchorId, projectId, depthBefore = 3, depthAfter = 3, reader2) {
|
|
185903
185903
|
const { withFreshIndex: withFreshIndex2 } = await Promise.resolve().then(() => (init_freshness(), freshness_exports));
|
|
185904
185904
|
const { getAllObservations: getAllObservations2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
|
|
185905
185905
|
const rawObs = await withFreshIndex2(() => getAllObservations2());
|
|
185906
|
-
const allObs = (projectId ? rawObs.filter((o4) => o4.projectId === projectId) : rawObs).filter((observation) => canReadObservation(observation,
|
|
185906
|
+
const allObs = (projectId ? rawObs.filter((o4) => o4.projectId === projectId) : rawObs).filter((observation) => canReadObservation(observation, reader2));
|
|
185907
185907
|
const sorted = allObs.sort((a4, b4) => a4.createdAt.localeCompare(b4.createdAt));
|
|
185908
185908
|
const anchorIndex = sorted.findIndex((o4) => o4.id === anchorId);
|
|
185909
185909
|
if (anchorIndex === -1) {
|
|
@@ -186410,8 +186410,8 @@ This project does have stored Memorix memories, but none matched the current que
|
|
|
186410
186410
|
const totalTokens = countTextTokens(formatted);
|
|
186411
186411
|
return { entries, formatted, totalTokens };
|
|
186412
186412
|
}
|
|
186413
|
-
async function compactTimeline(anchorId, projectId, depthBefore = 3, depthAfter = 3,
|
|
186414
|
-
const result = await getTimeline(anchorId, projectId, depthBefore, depthAfter,
|
|
186413
|
+
async function compactTimeline(anchorId, projectId, depthBefore = 3, depthAfter = 3, reader2, surface = "mcp") {
|
|
186414
|
+
const result = await getTimeline(anchorId, projectId, depthBefore, depthAfter, reader2);
|
|
186415
186415
|
const timeline = {
|
|
186416
186416
|
anchorId,
|
|
186417
186417
|
anchorEntry: result.anchor,
|
|
@@ -188058,7 +188058,7 @@ async function askMemoryQuestion(question, history = []) {
|
|
|
188058
188058
|
warning: "No project detected \u2014 memory tools unavailable."
|
|
188059
188059
|
};
|
|
188060
188060
|
}
|
|
188061
|
-
const { project, dataDir, reader, identity } = operatorContext;
|
|
188061
|
+
const { project, dataDir, reader: reader2, identity } = operatorContext;
|
|
188062
188062
|
loadDotenv(project.rootPath);
|
|
188063
188063
|
initLLM({ scope: "agent" });
|
|
188064
188064
|
await prepareProjectSearch(project.id, dataDir);
|
|
@@ -188069,11 +188069,11 @@ async function askMemoryQuestion(question, history = []) {
|
|
|
188069
188069
|
limit: SEARCH_LIMIT,
|
|
188070
188070
|
projectId: project.id,
|
|
188071
188071
|
status: "active",
|
|
188072
|
-
reader
|
|
188072
|
+
reader: reader2
|
|
188073
188073
|
});
|
|
188074
188074
|
const topEntries = searchResult.entries.slice(0, DETAIL_LIMIT);
|
|
188075
188075
|
const detailRefs = topEntries.map((entry) => ({ id: entry.id, projectId: project.id }));
|
|
188076
|
-
const detailResult = detailRefs.length > 0 ? await compactDetail(detailRefs, { reader }) : { documents: [], formatted: "", totalTokens: 0 };
|
|
188076
|
+
const detailResult = detailRefs.length > 0 ? await compactDetail(detailRefs, { reader: reader2 }) : { documents: [], formatted: "", totalTokens: 0 };
|
|
188077
188077
|
const sources2 = detailResult.documents.map((doc, index) => toSource(doc, topEntries[index]?.score ?? 0));
|
|
188078
188078
|
return {
|
|
188079
188079
|
question: trimmedQuestion,
|
|
@@ -188094,7 +188094,7 @@ async function askMemoryQuestion(question, history = []) {
|
|
|
188094
188094
|
messages.push({ role: "user", content: trimmedQuestion });
|
|
188095
188095
|
const ctx = {
|
|
188096
188096
|
projectId: project.id,
|
|
188097
|
-
reader,
|
|
188097
|
+
reader: reader2,
|
|
188098
188098
|
...identity ? { writerAgentId: identity.agentId } : {},
|
|
188099
188099
|
collectedSources: []
|
|
188100
188100
|
};
|
|
@@ -188190,7 +188190,7 @@ async function askMemoryQuestionStream(question, history = [], callbacks, signal
|
|
|
188190
188190
|
warning: "No project detected \u2014 memory tools unavailable."
|
|
188191
188191
|
};
|
|
188192
188192
|
}
|
|
188193
|
-
const { project, dataDir, reader, identity } = operatorContext;
|
|
188193
|
+
const { project, dataDir, reader: reader2, identity } = operatorContext;
|
|
188194
188194
|
loadDotenv(project.rootPath);
|
|
188195
188195
|
initLLM({ scope: "agent" });
|
|
188196
188196
|
await prepareProjectSearch(project.id, dataDir);
|
|
@@ -188201,11 +188201,11 @@ async function askMemoryQuestionStream(question, history = [], callbacks, signal
|
|
|
188201
188201
|
limit: SEARCH_LIMIT,
|
|
188202
188202
|
projectId: project.id,
|
|
188203
188203
|
status: "active",
|
|
188204
|
-
reader
|
|
188204
|
+
reader: reader2
|
|
188205
188205
|
});
|
|
188206
188206
|
const topEntries = searchResult.entries.slice(0, DETAIL_LIMIT);
|
|
188207
188207
|
const detailRefs = topEntries.map((entry) => ({ id: entry.id, projectId: project.id }));
|
|
188208
|
-
const detailResult = detailRefs.length > 0 ? await compactDetail(detailRefs, { reader }) : { documents: [], formatted: "", totalTokens: 0 };
|
|
188208
|
+
const detailResult = detailRefs.length > 0 ? await compactDetail(detailRefs, { reader: reader2 }) : { documents: [], formatted: "", totalTokens: 0 };
|
|
188209
188209
|
const sources2 = detailResult.documents.map((doc, index) => toSource(doc, topEntries[index]?.score ?? 0));
|
|
188210
188210
|
return {
|
|
188211
188211
|
question: trimmedQuestion,
|
|
@@ -188226,7 +188226,7 @@ async function askMemoryQuestionStream(question, history = [], callbacks, signal
|
|
|
188226
188226
|
messages.push({ role: "user", content: trimmedQuestion });
|
|
188227
188227
|
const ctx = {
|
|
188228
188228
|
projectId: project.id,
|
|
188229
|
-
reader,
|
|
188229
|
+
reader: reader2,
|
|
188230
188230
|
...identity ? { writerAgentId: identity.agentId } : {},
|
|
188231
188231
|
collectedSources: []
|
|
188232
188232
|
};
|
|
@@ -188445,7 +188445,7 @@ function auditMemoryQuality(observations2, options) {
|
|
|
188445
188445
|
const lowEvidence = active.filter((obs) => evidenceScore(obs) <= 2).map((obs) => makeEntry(obs, `Low evidence score (${evidenceScore(obs)}/5)`));
|
|
188446
188446
|
const hookNoise = active.filter((obs) => isHookNoise(obs) || isCommandLog(obs)).map((obs) => makeEntry(obs, isCommandLog(obs) ? "Command log noise" : "Hook-generated noise"));
|
|
188447
188447
|
const orphans = active.filter((obs) => isOrphan(obs)).map((obs) => makeEntry(obs, "Weakly connected or isolated memory"));
|
|
188448
|
-
const
|
|
188448
|
+
const retentionCandidates2 = active.filter((obs) => getRetentionZone({
|
|
188449
188449
|
id: `obs-${obs.id}`,
|
|
188450
188450
|
observationId: obs.id,
|
|
188451
188451
|
entityName: obs.entityName,
|
|
@@ -188485,7 +188485,7 @@ function auditMemoryQuality(observations2, options) {
|
|
|
188485
188485
|
if (orphans.length > 0) {
|
|
188486
188486
|
recommendations.push("Promote or attach isolated memories only if they have clear evidence value.");
|
|
188487
188487
|
}
|
|
188488
|
-
if (
|
|
188488
|
+
if (retentionCandidates2.length > 0) {
|
|
188489
188489
|
recommendations.push("Run `memorix retention stale` or `memorix retention archive` to inspect aged memories.");
|
|
188490
188490
|
}
|
|
188491
188491
|
if (recommendations.length === 0) {
|
|
@@ -188499,7 +188499,7 @@ function auditMemoryQuality(observations2, options) {
|
|
|
188499
188499
|
lowEvidence,
|
|
188500
188500
|
hookNoise,
|
|
188501
188501
|
orphans,
|
|
188502
|
-
retentionCandidates
|
|
188502
|
+
retentionCandidates: retentionCandidates2
|
|
188503
188503
|
},
|
|
188504
188504
|
recommendations
|
|
188505
188505
|
};
|
|
@@ -189011,6 +189011,125 @@ var init_graph_context = __esm({
|
|
|
189011
189011
|
}
|
|
189012
189012
|
});
|
|
189013
189013
|
|
|
189014
|
+
// src/memory/deduplication.ts
|
|
189015
|
+
function chronological(left, right) {
|
|
189016
|
+
const byTime = new Date(left.createdAt).getTime() - new Date(right.createdAt).getTime();
|
|
189017
|
+
return byTime || left.id - right.id;
|
|
189018
|
+
}
|
|
189019
|
+
function actionFromDecision(older, newer, decision) {
|
|
189020
|
+
let resolveId;
|
|
189021
|
+
let keepId;
|
|
189022
|
+
if (decision.action === "NONE") {
|
|
189023
|
+
resolveId = newer.id;
|
|
189024
|
+
keepId = older.id;
|
|
189025
|
+
} else if (decision.action === "UPDATE") {
|
|
189026
|
+
resolveId = decision.targetId ?? older.id;
|
|
189027
|
+
keepId = resolveId === newer.id ? older.id : newer.id;
|
|
189028
|
+
} else if (decision.action === "DELETE") {
|
|
189029
|
+
resolveId = decision.targetId ?? older.id;
|
|
189030
|
+
keepId = resolveId === newer.id ? older.id : newer.id;
|
|
189031
|
+
} else {
|
|
189032
|
+
return null;
|
|
189033
|
+
}
|
|
189034
|
+
const records = /* @__PURE__ */ new Map([[older.id, older], [newer.id, newer]]);
|
|
189035
|
+
const resolved = records.get(resolveId);
|
|
189036
|
+
const kept = records.get(keepId);
|
|
189037
|
+
if (!resolved || !kept || resolved.id === kept.id) return null;
|
|
189038
|
+
return {
|
|
189039
|
+
resolveId,
|
|
189040
|
+
keepId,
|
|
189041
|
+
entityName: newer.entityName,
|
|
189042
|
+
resolveTitle: resolved.title,
|
|
189043
|
+
keepTitle: kept.title,
|
|
189044
|
+
reason: decision.reason,
|
|
189045
|
+
decision: decision.action,
|
|
189046
|
+
usedLLM: decision.usedLLM
|
|
189047
|
+
};
|
|
189048
|
+
}
|
|
189049
|
+
async function planMemoryDeduplication(observations2, options = {}) {
|
|
189050
|
+
const limit2 = Math.min(100, Math.max(2, Math.floor(options.limit ?? 20)));
|
|
189051
|
+
const candidates = observations2.filter((observation) => (observation.status ?? "active") === "active").sort(chronological).slice(-limit2);
|
|
189052
|
+
const byEntity = /* @__PURE__ */ new Map();
|
|
189053
|
+
for (const observation of candidates) {
|
|
189054
|
+
const group = byEntity.get(observation.entityName) ?? [];
|
|
189055
|
+
group.push(observation);
|
|
189056
|
+
byEntity.set(observation.entityName, group);
|
|
189057
|
+
}
|
|
189058
|
+
const decide = options.decide ?? deduplicateMemory;
|
|
189059
|
+
const actions = /* @__PURE__ */ new Map();
|
|
189060
|
+
let comparisons = 0;
|
|
189061
|
+
let failedComparisons = 0;
|
|
189062
|
+
for (const group of byEntity.values()) {
|
|
189063
|
+
if (group.length < 2) continue;
|
|
189064
|
+
group.sort(chronological);
|
|
189065
|
+
for (let index = 0; index < group.length; index += 1) {
|
|
189066
|
+
for (let compareIndex = index + 1; compareIndex < group.length; compareIndex += 1) {
|
|
189067
|
+
const older = group[index];
|
|
189068
|
+
const newer = group[compareIndex];
|
|
189069
|
+
comparisons += 1;
|
|
189070
|
+
let decision;
|
|
189071
|
+
try {
|
|
189072
|
+
decision = await decide(
|
|
189073
|
+
{ title: newer.title, narrative: newer.narrative, facts: newer.facts },
|
|
189074
|
+
[{ id: older.id, title: older.title, narrative: older.narrative, facts: older.facts.join("\n") }]
|
|
189075
|
+
);
|
|
189076
|
+
} catch {
|
|
189077
|
+
failedComparisons += 1;
|
|
189078
|
+
continue;
|
|
189079
|
+
}
|
|
189080
|
+
if (!decision) continue;
|
|
189081
|
+
const action = actionFromDecision(older, newer, decision);
|
|
189082
|
+
if (action && !actions.has(action.resolveId)) actions.set(action.resolveId, action);
|
|
189083
|
+
}
|
|
189084
|
+
}
|
|
189085
|
+
}
|
|
189086
|
+
const planned = [...actions.values()];
|
|
189087
|
+
for (const [entityName, group] of byEntity) {
|
|
189088
|
+
const resolvedIds = new Set(
|
|
189089
|
+
planned.filter((action) => action.entityName === entityName).map((action) => action.resolveId)
|
|
189090
|
+
);
|
|
189091
|
+
if (group.length > 0 && group.every((observation) => resolvedIds.has(observation.id))) {
|
|
189092
|
+
const survivor = group[group.length - 1];
|
|
189093
|
+
const unsafeIndex = planned.findIndex((action) => action.resolveId === survivor.id);
|
|
189094
|
+
if (unsafeIndex >= 0) planned.splice(unsafeIndex, 1);
|
|
189095
|
+
}
|
|
189096
|
+
}
|
|
189097
|
+
return {
|
|
189098
|
+
scanned: candidates.length,
|
|
189099
|
+
entities: byEntity.size,
|
|
189100
|
+
comparisons,
|
|
189101
|
+
failedComparisons,
|
|
189102
|
+
actions: planned,
|
|
189103
|
+
resolveIds: planned.map((action) => action.resolveId)
|
|
189104
|
+
};
|
|
189105
|
+
}
|
|
189106
|
+
async function applyDeduplicationPlan(store2, projectId, resolveIds, reader2 = { projectId }) {
|
|
189107
|
+
const uniqueIds = [...new Set(resolveIds)];
|
|
189108
|
+
const manageable = [];
|
|
189109
|
+
const skipped = [];
|
|
189110
|
+
for (const id of uniqueIds) {
|
|
189111
|
+
const observation = await store2.getById(id);
|
|
189112
|
+
if (observation && observation.projectId === projectId && (observation.status ?? "active") === "active" && canManageObservation(observation, reader2)) {
|
|
189113
|
+
manageable.push(id);
|
|
189114
|
+
} else {
|
|
189115
|
+
skipped.push(id);
|
|
189116
|
+
}
|
|
189117
|
+
}
|
|
189118
|
+
const resolved = skipped.length > 0 || manageable.length === 0 ? [] : await store2.atomic(async (tx) => {
|
|
189119
|
+
const updates = await Promise.all(manageable.map((id) => tx.setStatus(id, "resolved", "active")));
|
|
189120
|
+
return manageable.filter((_5, index) => updates[index]);
|
|
189121
|
+
});
|
|
189122
|
+
return { resolved, skipped };
|
|
189123
|
+
}
|
|
189124
|
+
var init_deduplication = __esm({
|
|
189125
|
+
"src/memory/deduplication.ts"() {
|
|
189126
|
+
"use strict";
|
|
189127
|
+
init_esm_shims();
|
|
189128
|
+
init_memory_manager();
|
|
189129
|
+
init_visibility();
|
|
189130
|
+
}
|
|
189131
|
+
});
|
|
189132
|
+
|
|
189014
189133
|
// src/store/session-store.ts
|
|
189015
189134
|
var session_store_exports = {};
|
|
189016
189135
|
__export(session_store_exports, {
|
|
@@ -189538,7 +189657,9 @@ var init_memory3 = __esm({
|
|
|
189538
189657
|
init_freshness();
|
|
189539
189658
|
init_observations();
|
|
189540
189659
|
init_graph_context();
|
|
189660
|
+
init_deduplication();
|
|
189541
189661
|
init_visibility();
|
|
189662
|
+
init_obs_store();
|
|
189542
189663
|
init_operator_shared();
|
|
189543
189664
|
memory_default = defineCommand({
|
|
189544
189665
|
meta: {
|
|
@@ -189595,7 +189716,7 @@ var init_memory3 = __esm({
|
|
|
189595
189716
|
const needsSearchIndex = action === "search" || action === "detail" || action === "timeline";
|
|
189596
189717
|
const longTermReadOnly = longTermAction === "list" || longTermAction === "show";
|
|
189597
189718
|
const context = readOnlyActions.has(action) || longTermReadOnly ? await getCliReadContext({ searchIndex: needsSearchIndex }) : await getCliProjectContext({ searchIndex: true });
|
|
189598
|
-
const { project, dataDir, reader, identity } = context;
|
|
189719
|
+
const { project, dataDir, reader: reader2, identity } = context;
|
|
189599
189720
|
switch (action) {
|
|
189600
189721
|
case "search": {
|
|
189601
189722
|
const query = getStringArg(args.query, positional);
|
|
@@ -189605,7 +189726,7 @@ var init_memory3 = __esm({
|
|
|
189605
189726
|
}
|
|
189606
189727
|
const limit2 = parsePositiveInt(args.limit, 10);
|
|
189607
189728
|
const quality = coerceRetrievalQuality(args.quality);
|
|
189608
|
-
const result = await compactSearch({ query, limit: limit2, quality, projectId: project.id, reader }, "cli");
|
|
189729
|
+
const result = await compactSearch({ query, limit: limit2, quality, projectId: project.id, reader: reader2 }, "cli");
|
|
189609
189730
|
emitResult({ project, entries: result.entries }, result.formatted, asJson);
|
|
189610
189731
|
return;
|
|
189611
189732
|
}
|
|
@@ -189615,7 +189736,7 @@ var init_memory3 = __esm({
|
|
|
189615
189736
|
emitError('query is required for "memorix memory graph-context"', asJson);
|
|
189616
189737
|
return;
|
|
189617
189738
|
}
|
|
189618
|
-
const observations2 = filterReadableObservations(getAllObservations(),
|
|
189739
|
+
const observations2 = filterReadableObservations(getAllObservations(), reader2);
|
|
189619
189740
|
const packet = buildGraphContextPacket(observations2, {
|
|
189620
189741
|
projectId: project.id,
|
|
189621
189742
|
query,
|
|
@@ -189637,7 +189758,7 @@ var init_memory3 = __esm({
|
|
|
189637
189758
|
}
|
|
189638
189759
|
case "recent": {
|
|
189639
189760
|
const limit2 = parsePositiveInt(args.limit, 10);
|
|
189640
|
-
const observations2 = filterReadableObservations(getProjectObservations(project.id),
|
|
189761
|
+
const observations2 = filterReadableObservations(getProjectObservations(project.id), reader2).filter((obs) => (obs.status ?? "active") === "active").slice(-limit2).reverse();
|
|
189641
189762
|
emitResult(
|
|
189642
189763
|
{ project, observations: observations2 },
|
|
189643
189764
|
observations2.length === 0 ? "No active observations." : observations2.map((obs) => `- #${obs.id} ${obs.title}`).join("\n"),
|
|
@@ -189655,7 +189776,7 @@ var init_memory3 = __esm({
|
|
|
189655
189776
|
const type = coerceObservationType(args.type);
|
|
189656
189777
|
const topicKey = asStringArg(args.topicKey) || suggestTopicKey(type, title) || void 0;
|
|
189657
189778
|
const writeScope = resolveCliWriteScope(
|
|
189658
|
-
{ reader, identity },
|
|
189779
|
+
{ reader: reader2, identity },
|
|
189659
189780
|
args.visibility
|
|
189660
189781
|
);
|
|
189661
189782
|
const result = await storeObservation({
|
|
@@ -189703,7 +189824,7 @@ var init_memory3 = __esm({
|
|
|
189703
189824
|
const numericId = Number.parseInt(ref, 10);
|
|
189704
189825
|
return Number.isFinite(numericId) && String(numericId) === ref.trim() ? `obs:${numericId}@${project.id}` : ref;
|
|
189705
189826
|
});
|
|
189706
|
-
const result = await compactDetail(scopedRefs, { reader });
|
|
189827
|
+
const result = await compactDetail(scopedRefs, { reader: reader2 });
|
|
189707
189828
|
if (scopedRefs.length === 1 && result.documents.length === 0) {
|
|
189708
189829
|
emitError(`No readable memory found for ${scopedRefs[0]}.`, asJson);
|
|
189709
189830
|
return;
|
|
@@ -189725,7 +189846,7 @@ var init_memory3 = __esm({
|
|
|
189725
189846
|
project.id,
|
|
189726
189847
|
parsePositiveInt(args.before, 3),
|
|
189727
189848
|
parsePositiveInt(args.after, 3),
|
|
189728
|
-
|
|
189849
|
+
reader2,
|
|
189729
189850
|
"cli"
|
|
189730
189851
|
);
|
|
189731
189852
|
if (!result.timeline.anchorEntry) {
|
|
@@ -189744,7 +189865,7 @@ var init_memory3 = __esm({
|
|
|
189744
189865
|
const status = coerceObservationStatus(args.status);
|
|
189745
189866
|
const authorizedIds = ids.filter((id) => {
|
|
189746
189867
|
const observation = getObservation(id, project.id);
|
|
189747
|
-
return observation ? canManageObservation(observation,
|
|
189868
|
+
return observation ? canManageObservation(observation, reader2) : false;
|
|
189748
189869
|
});
|
|
189749
189870
|
if (authorizedIds.length === 0) {
|
|
189750
189871
|
emitError("No requested observations are manageable with the active CLI scope.", asJson);
|
|
@@ -189780,12 +189901,11 @@ var init_memory3 = __esm({
|
|
|
189780
189901
|
);
|
|
189781
189902
|
return;
|
|
189782
189903
|
}
|
|
189783
|
-
const { deduplicateMemory: deduplicateMemory2 } = await Promise.resolve().then(() => (init_memory_manager(), memory_manager_exports));
|
|
189784
189904
|
const allObs = await withFreshIndex(
|
|
189785
189905
|
() => filterReadableObservations(
|
|
189786
189906
|
getAllObservations().filter((obs) => (obs.status ?? "active") === "active" && obs.projectId === project.id),
|
|
189787
|
-
|
|
189788
|
-
)
|
|
189907
|
+
reader2
|
|
189908
|
+
).filter((observation) => canManageObservation(observation, reader2))
|
|
189789
189909
|
);
|
|
189790
189910
|
if (allObs.length < 2) {
|
|
189791
189911
|
emitResult({ project, actions: [], resolved: [] }, "Not enough active memories to deduplicate.", asJson);
|
|
@@ -189793,57 +189913,27 @@ var init_memory3 = __esm({
|
|
|
189793
189913
|
}
|
|
189794
189914
|
let candidates = allObs;
|
|
189795
189915
|
if (query) {
|
|
189796
|
-
const searchResult = await compactSearch({ query, limit: 20, projectId: project.id, status: "active", reader });
|
|
189916
|
+
const searchResult = await compactSearch({ query, limit: 20, projectId: project.id, status: "active", reader: reader2 });
|
|
189797
189917
|
const ids = new Set(searchResult.entries.map((entry) => entry.id));
|
|
189798
189918
|
candidates = allObs.filter((obs) => ids.has(obs.id));
|
|
189799
189919
|
} else {
|
|
189800
189920
|
candidates = allObs.slice(-20);
|
|
189801
189921
|
}
|
|
189802
|
-
const
|
|
189803
|
-
|
|
189804
|
-
|
|
189805
|
-
|
|
189806
|
-
|
|
189807
|
-
}
|
|
189808
|
-
const actions = [];
|
|
189809
|
-
const toResolve = [];
|
|
189810
|
-
for (const [, group] of byEntity) {
|
|
189811
|
-
if (group.length < 2) continue;
|
|
189812
|
-
for (let index = 0; index < group.length; index += 1) {
|
|
189813
|
-
for (let compareIndex = index + 1; compareIndex < group.length; compareIndex += 1) {
|
|
189814
|
-
const newer = group[compareIndex];
|
|
189815
|
-
const older = group[index];
|
|
189816
|
-
try {
|
|
189817
|
-
const decision = await deduplicateMemory2(
|
|
189818
|
-
{ title: newer.title, narrative: newer.narrative, facts: newer.facts },
|
|
189819
|
-
[{ id: older.id, title: older.title, narrative: older.narrative, facts: older.facts.join("\n") }]
|
|
189820
|
-
);
|
|
189821
|
-
if (decision && (decision.action === "DELETE" || decision.action === "UPDATE" || decision.action === "NONE")) {
|
|
189822
|
-
actions.push(`Resolve #${older.id} because it duplicates newer #${newer.id}`);
|
|
189823
|
-
toResolve.push(older.id);
|
|
189824
|
-
}
|
|
189825
|
-
} catch {
|
|
189826
|
-
}
|
|
189827
|
-
}
|
|
189828
|
-
}
|
|
189829
|
-
}
|
|
189830
|
-
if (dryRun || toResolve.length === 0) {
|
|
189922
|
+
const plan = await planMemoryDeduplication(candidates);
|
|
189923
|
+
const actionLines = plan.actions.map(
|
|
189924
|
+
(item) => `Resolve #${item.resolveId} "${item.resolveTitle}"; keep #${item.keepId} "${item.keepTitle}" (${item.reason})`
|
|
189925
|
+
);
|
|
189926
|
+
if (dryRun || plan.resolveIds.length === 0) {
|
|
189831
189927
|
emitResult(
|
|
189832
|
-
{ project,
|
|
189833
|
-
|
|
189928
|
+
{ project, plan, resolved: [], dryRun: true },
|
|
189929
|
+
actionLines.length === 0 ? "No duplicate candidates found." : actionLines.join("\n"),
|
|
189834
189930
|
asJson
|
|
189835
189931
|
);
|
|
189836
189932
|
return;
|
|
189837
189933
|
}
|
|
189838
|
-
const result = await
|
|
189839
|
-
[...new Set(toResolve)].filter((id) => {
|
|
189840
|
-
const observation = getObservation(id, project.id);
|
|
189841
|
-
return observation ? canManageObservation(observation, reader) : false;
|
|
189842
|
-
}),
|
|
189843
|
-
"resolved"
|
|
189844
|
-
);
|
|
189934
|
+
const result = await applyDeduplicationPlan(getObservationStore(), project.id, plan.resolveIds, reader2);
|
|
189845
189935
|
emitResult(
|
|
189846
|
-
{ project,
|
|
189936
|
+
{ project, plan, resolved: result.resolved, skipped: result.skipped, dryRun: false },
|
|
189847
189937
|
`Resolved ${result.resolved.length} duplicate observation(s).`,
|
|
189848
189938
|
asJson
|
|
189849
189939
|
);
|
|
@@ -189910,7 +190000,7 @@ var init_memory3 = __esm({
|
|
|
189910
190000
|
const observations2 = await withFreshIndex(() => getAllObservations());
|
|
189911
190001
|
const matched = filterReadableObservations(
|
|
189912
190002
|
observations2.filter((obs) => obs.projectId === project.id && ids.includes(obs.id)),
|
|
189913
|
-
|
|
190003
|
+
reader2
|
|
189914
190004
|
).filter((observation) => resolveObservationVisibility(observation) === "project");
|
|
189915
190005
|
if (matched.length === 0) {
|
|
189916
190006
|
emitError(`No project-visible observations found for IDs: ${ids.join(", ")}. Private and team records cannot be promoted into shared skills.`, asJson);
|
|
@@ -189947,8 +190037,8 @@ var init_memory3 = __esm({
|
|
|
189947
190037
|
const longTermReader = {
|
|
189948
190038
|
projectId: project.id,
|
|
189949
190039
|
...owner ? { ownerId: owner.id } : {},
|
|
189950
|
-
...
|
|
189951
|
-
...
|
|
190040
|
+
...reader2.agentId ? { agentId: reader2.agentId } : {},
|
|
190041
|
+
...reader2.isTeamMember ? { isTeamMember: true } : {}
|
|
189952
190042
|
};
|
|
189953
190043
|
const memoryId = () => {
|
|
189954
190044
|
const id = asStringArg(args.id) || asStringArg(args.fromObservation) || longTermPositional[0]?.trim();
|
|
@@ -190028,7 +190118,7 @@ var init_memory3 = __esm({
|
|
|
190028
190118
|
return;
|
|
190029
190119
|
}
|
|
190030
190120
|
const observation = getObservation(observationId2, project.id);
|
|
190031
|
-
if (!observation || !canManageObservation(observation,
|
|
190121
|
+
if (!observation || !canManageObservation(observation, reader2)) {
|
|
190032
190122
|
emitError("Observation was not found or is outside the active write scope.", asJson);
|
|
190033
190123
|
return;
|
|
190034
190124
|
}
|
|
@@ -197160,14 +197250,14 @@ function isSystemSelfObservation(obs) {
|
|
|
197160
197250
|
const text2 = stringifyObservation(obs, false);
|
|
197161
197251
|
return SYSTEM_SELF_PATTERNS.some((pattern) => pattern.test(text2));
|
|
197162
197252
|
}
|
|
197163
|
-
function readerForAlias(
|
|
197164
|
-
if (!
|
|
197165
|
-
return
|
|
197253
|
+
function readerForAlias(reader2, aliases, observation) {
|
|
197254
|
+
if (!reader2) return void 0;
|
|
197255
|
+
return reader2.projectId && aliases.has(observation.projectId) ? { ...reader2, projectId: observation.projectId } : reader2;
|
|
197166
197256
|
}
|
|
197167
|
-
function readableAliasObservations(observations2, aliases,
|
|
197168
|
-
return
|
|
197257
|
+
function readableAliasObservations(observations2, aliases, reader2) {
|
|
197258
|
+
return reader2 ? observations2.filter((observation) => canReadObservation(
|
|
197169
197259
|
observation,
|
|
197170
|
-
readerForAlias(
|
|
197260
|
+
readerForAlias(reader2, aliases, observation)
|
|
197171
197261
|
)) : observations2;
|
|
197172
197262
|
}
|
|
197173
197263
|
function isUsefulSessionSummary(summary) {
|
|
@@ -197186,13 +197276,13 @@ function continuationScore(observation, projectTokens, task) {
|
|
|
197186
197276
|
score += Math.min(matches, 2) * 2;
|
|
197187
197277
|
return score;
|
|
197188
197278
|
}
|
|
197189
|
-
async function getSessionResumeBrief(projectId, task,
|
|
197279
|
+
async function getSessionResumeBrief(projectId, task, reader2) {
|
|
197190
197280
|
const aliasSet = await resolveProjectIds(projectId);
|
|
197191
197281
|
const [sessions, allObs] = await Promise.all([
|
|
197192
197282
|
loadAliasSessions(aliasSet),
|
|
197193
197283
|
loadAliasActiveObservations(aliasSet)
|
|
197194
197284
|
]);
|
|
197195
|
-
const readableObs = readableAliasObservations(allObs, aliasSet,
|
|
197285
|
+
const readableObs = readableAliasObservations(allObs, aliasSet, reader2);
|
|
197196
197286
|
const previous = sessions.filter((session) => session.status === "completed").sort((a4, b4) => new Date(b4.endedAt || b4.startedAt).getTime() - new Date(a4.endedAt || a4.startedAt).getTime()).find((session) => session.summary && session.summary !== "(session ended implicitly by new session start)" && isUsefulSessionSummary(session.summary));
|
|
197197
197287
|
const projectTokens = tokenizeProjectId(projectId);
|
|
197198
197288
|
const memories = readableObs.filter((observation) => RESUME_TYPES.has(observation.type)).filter((observation) => classifyLayer(observation) === "L2").filter((observation) => !isNoiseObservation(observation) && !isSystemSelfObservation(observation)).map((observation) => ({
|
|
@@ -197303,13 +197393,13 @@ async function endSession(projectDir2, sessionId, summary) {
|
|
|
197303
197393
|
await sessionStore.update(session);
|
|
197304
197394
|
return session;
|
|
197305
197395
|
}
|
|
197306
|
-
async function getSessionContext(projectDir2, projectId, limit2 = 3,
|
|
197396
|
+
async function getSessionContext(projectDir2, projectId, limit2 = 3, reader2) {
|
|
197307
197397
|
const aliasSet = await resolveProjectIds(projectId);
|
|
197308
197398
|
const [sessions, allObs] = await Promise.all([
|
|
197309
197399
|
loadAliasSessions(aliasSet),
|
|
197310
197400
|
loadAliasActiveObservations(aliasSet, SESSION_CONTEXT_OBSERVATION_LIMIT)
|
|
197311
197401
|
]);
|
|
197312
|
-
const readableObs = readableAliasObservations(allObs, aliasSet,
|
|
197402
|
+
const readableObs = readableAliasObservations(allObs, aliasSet, reader2);
|
|
197313
197403
|
const isNoisySummary = (summary) => {
|
|
197314
197404
|
if (!summary) return false;
|
|
197315
197405
|
return NOISE_PATTERNS.some((p3) => p3.test(summary)) || SYSTEM_SELF_PATTERNS.some((p3) => p3.test(summary));
|
|
@@ -197346,7 +197436,7 @@ async function getSessionContext(projectDir2, projectId, limit2 = 3, reader) {
|
|
|
197346
197436
|
const hasL1Content = l1HookObs.length > 0 || l3GitCount > 0;
|
|
197347
197437
|
if (hasL1Content) {
|
|
197348
197438
|
let graphNeighbors = [];
|
|
197349
|
-
if (!
|
|
197439
|
+
if (!reader2 && activeEntities.length > 0) {
|
|
197350
197440
|
try {
|
|
197351
197441
|
const graphMgr = new KnowledgeGraphManager(projectDir2);
|
|
197352
197442
|
await graphMgr.init();
|
|
@@ -198534,15 +198624,15 @@ var init_context2 = __esm({
|
|
|
198534
198624
|
const asJson = !!args.json || !!args.briefJson;
|
|
198535
198625
|
const task = args.task?.trim() || args.input?.trim() || void 0;
|
|
198536
198626
|
try {
|
|
198537
|
-
const { project, dataDir, reader } = await getCliProjectContext();
|
|
198627
|
+
const { project, dataDir, reader: reader2 } = await getCliProjectContext();
|
|
198538
198628
|
const context = await buildAutoProjectContext({
|
|
198539
198629
|
project,
|
|
198540
198630
|
dataDir,
|
|
198541
|
-
observations: filterReadableObservations(getAllObservations(),
|
|
198631
|
+
observations: filterReadableObservations(getAllObservations(), reader2),
|
|
198542
198632
|
task,
|
|
198543
198633
|
agent: coerceAgentTarget(args.agent),
|
|
198544
198634
|
refresh: coerceRefreshMode(args.refresh),
|
|
198545
|
-
reader,
|
|
198635
|
+
reader: reader2,
|
|
198546
198636
|
...args.resume ? { continuation: "always" } : {}
|
|
198547
198637
|
});
|
|
198548
198638
|
const detailed = {
|
|
@@ -198704,11 +198794,11 @@ var init_explain = __esm({
|
|
|
198704
198794
|
run: async ({ args }) => {
|
|
198705
198795
|
const asJson = !!args.json;
|
|
198706
198796
|
try {
|
|
198707
|
-
const { project, dataDir, reader } = await getCliProjectContext();
|
|
198797
|
+
const { project, dataDir, reader: reader2 } = await getCliProjectContext();
|
|
198708
198798
|
const context = await buildAutoProjectContext({
|
|
198709
198799
|
project,
|
|
198710
198800
|
dataDir,
|
|
198711
|
-
observations: filterReadableObservations(getAllObservations(),
|
|
198801
|
+
observations: filterReadableObservations(getAllObservations(), reader2),
|
|
198712
198802
|
refresh: coerceRefreshMode2(args.refresh)
|
|
198713
198803
|
});
|
|
198714
198804
|
emitResult(
|
|
@@ -199103,7 +199193,7 @@ var init_codegraph = __esm({
|
|
|
199103
199193
|
const action = (positional[0] || args.action || "status").toLowerCase();
|
|
199104
199194
|
const asJson = !!args.json || !!args.briefJson;
|
|
199105
199195
|
try {
|
|
199106
|
-
const { project, dataDir, reader } = await getCliProjectContext();
|
|
199196
|
+
const { project, dataDir, reader: reader2 } = await getCliProjectContext();
|
|
199107
199197
|
const store2 = new CodeGraphStore();
|
|
199108
199198
|
await store2.init(dataDir);
|
|
199109
199199
|
const explicitAction = Boolean(positional[0] || args.action);
|
|
@@ -199232,7 +199322,7 @@ ${formatUsageHint()}`;
|
|
|
199232
199322
|
const limit2 = parsePositiveInt(args.limit, 20);
|
|
199233
199323
|
const observations2 = filterReadableObservations(
|
|
199234
199324
|
getAllObservations().filter((obs) => obs.projectId === project.id && (obs.status ?? "active") === "active"),
|
|
199235
|
-
|
|
199325
|
+
reader2
|
|
199236
199326
|
).reverse();
|
|
199237
199327
|
const basePack = assembleContextPackForTask({
|
|
199238
199328
|
store: store2,
|
|
@@ -199272,7 +199362,7 @@ ${formatUsageHint()}`;
|
|
|
199272
199362
|
...external.outline ? { semanticCode: external.outline } : {},
|
|
199273
199363
|
providerQuality: external.quality,
|
|
199274
199364
|
...external.caution ? { runtimeCautions: [{ kind: "external-codegraph-fallback", message: external.caution }] } : {},
|
|
199275
|
-
reader,
|
|
199365
|
+
reader: reader2,
|
|
199276
199366
|
agent: coerceAgentTarget2(args.agent)
|
|
199277
199367
|
});
|
|
199278
199368
|
emitResult(
|
|
@@ -199899,7 +199989,7 @@ var init_reasoning = __esm({
|
|
|
199899
199989
|
const action = args._?.[0] || "";
|
|
199900
199990
|
const asJson = !!args.json;
|
|
199901
199991
|
try {
|
|
199902
|
-
const { project, reader, identity } = await getCliProjectContext({ searchIndex: action === "search" });
|
|
199992
|
+
const { project, reader: reader2, identity } = await getCliProjectContext({ searchIndex: action === "search" });
|
|
199903
199993
|
switch (action) {
|
|
199904
199994
|
case "store": {
|
|
199905
199995
|
const entityName = args.entity?.trim();
|
|
@@ -199930,7 +200020,7 @@ var init_reasoning = __esm({
|
|
|
199930
200020
|
narrativeParts.push(`Risks: ${risks.join("; ")}`);
|
|
199931
200021
|
}
|
|
199932
200022
|
const writeScope = resolveCliWriteScope(
|
|
199933
|
-
{ reader, identity },
|
|
200023
|
+
{ reader: reader2, identity },
|
|
199934
200024
|
args.visibility
|
|
199935
200025
|
);
|
|
199936
200026
|
const result = await storeObservation({
|
|
@@ -199976,7 +200066,7 @@ var init_reasoning = __esm({
|
|
|
199976
200066
|
type: "reasoning",
|
|
199977
200067
|
projectId: scope === "global" ? void 0 : project.id,
|
|
199978
200068
|
status: "active",
|
|
199979
|
-
reader: scope === "global" ? {} :
|
|
200069
|
+
reader: scope === "global" ? {} : reader2
|
|
199980
200070
|
});
|
|
199981
200071
|
emitResult(
|
|
199982
200072
|
{ project, scope, entries: result.entries },
|
|
@@ -200052,10 +200142,10 @@ var init_retention2 = __esm({
|
|
|
200052
200142
|
const action = args._?.[0] || "";
|
|
200053
200143
|
const asJson = !!args.json;
|
|
200054
200144
|
try {
|
|
200055
|
-
const { project, dataDir, reader } = await getCliProjectContext();
|
|
200145
|
+
const { project, dataDir, reader: reader2 } = await getCliProjectContext();
|
|
200056
200146
|
const activeDocs = filterReadableObservations(
|
|
200057
200147
|
getAllObservations().filter((obs) => obs.projectId === project.id && (obs.status ?? "active") === "active"),
|
|
200058
|
-
|
|
200148
|
+
reader2
|
|
200059
200149
|
).map(toDocument);
|
|
200060
200150
|
switch (action) {
|
|
200061
200151
|
case "status": {
|
|
@@ -200076,7 +200166,7 @@ var init_retention2 = __esm({
|
|
|
200076
200166
|
return;
|
|
200077
200167
|
}
|
|
200078
200168
|
case "archive": {
|
|
200079
|
-
const result = await archiveExpired(dataDir, void 0, void 0, project.id,
|
|
200169
|
+
const result = await archiveExpired(dataDir, void 0, void 0, project.id, reader2);
|
|
200080
200170
|
emitResult(
|
|
200081
200171
|
{ project, result },
|
|
200082
200172
|
result.archived === 0 ? "No expired observations to archive." : `Archived ${result.archived} expired observation(s); ${result.remaining} active observation(s) remain.`,
|
|
@@ -201241,8 +201331,8 @@ var init_audit2 = __esm({
|
|
|
201241
201331
|
try {
|
|
201242
201332
|
switch (action) {
|
|
201243
201333
|
case "memory": {
|
|
201244
|
-
const { project, reader } = await getCliProjectContext();
|
|
201245
|
-
const report = auditMemoryQuality(filterReadableObservations(getAllObservations(),
|
|
201334
|
+
const { project, reader: reader2 } = await getCliProjectContext();
|
|
201335
|
+
const report = auditMemoryQuality(filterReadableObservations(getAllObservations(), reader2), {
|
|
201246
201336
|
projectId: project.id
|
|
201247
201337
|
});
|
|
201248
201338
|
emitResult(
|
|
@@ -201279,11 +201369,11 @@ var init_audit2 = __esm({
|
|
|
201279
201369
|
return;
|
|
201280
201370
|
}
|
|
201281
201371
|
case "project": {
|
|
201282
|
-
const { project, reader } = await getCliProjectContext();
|
|
201372
|
+
const { project, reader: reader2 } = await getCliProjectContext();
|
|
201283
201373
|
const threshold = Number.parseInt(String(args.threshold ?? "2"), 10) || 2;
|
|
201284
201374
|
const entries = await auditProjectObservations(
|
|
201285
201375
|
project.id,
|
|
201286
|
-
filterReadableObservations(getAllObservations(),
|
|
201376
|
+
filterReadableObservations(getAllObservations(), reader2),
|
|
201287
201377
|
threshold
|
|
201288
201378
|
);
|
|
201289
201379
|
emitResult(
|
|
@@ -201316,13 +201406,13 @@ __export(export_import_exports, {
|
|
|
201316
201406
|
exportAsMarkdown: () => exportAsMarkdown,
|
|
201317
201407
|
importFromJson: () => importFromJson
|
|
201318
201408
|
});
|
|
201319
|
-
async function exportAsJson(projectDir2, projectId,
|
|
201409
|
+
async function exportAsJson(projectDir2, projectId, reader2) {
|
|
201320
201410
|
const store2 = getObservationStore();
|
|
201321
201411
|
const allObs = await store2.loadAll();
|
|
201322
201412
|
const allSessions = await getSessionStore().loadAll();
|
|
201323
201413
|
const projectObs = filterReadableObservations(
|
|
201324
201414
|
allObs.filter((o4) => o4.projectId === projectId),
|
|
201325
|
-
|
|
201415
|
+
reader2
|
|
201326
201416
|
);
|
|
201327
201417
|
const projectSessions = allSessions.filter((s4) => s4.projectId === projectId);
|
|
201328
201418
|
const typeBreakdown = {};
|
|
@@ -201342,8 +201432,8 @@ async function exportAsJson(projectDir2, projectId, reader) {
|
|
|
201342
201432
|
}
|
|
201343
201433
|
};
|
|
201344
201434
|
}
|
|
201345
|
-
async function exportAsMarkdown(projectDir2, projectId,
|
|
201346
|
-
const data = await exportAsJson(projectDir2, projectId,
|
|
201435
|
+
async function exportAsMarkdown(projectDir2, projectId, reader2) {
|
|
201436
|
+
const data = await exportAsJson(projectDir2, projectId, reader2);
|
|
201347
201437
|
const lines = [];
|
|
201348
201438
|
lines.push(`# Memorix Export: ${projectId}`);
|
|
201349
201439
|
lines.push(`Exported: ${data.exportedAt}`);
|
|
@@ -201523,12 +201613,12 @@ var init_transfer = __esm({
|
|
|
201523
201613
|
const action = args._?.[0] || "";
|
|
201524
201614
|
const asJson = !!args.json;
|
|
201525
201615
|
try {
|
|
201526
|
-
const { project, dataDir, reader } = await getCliProjectContext();
|
|
201616
|
+
const { project, dataDir, reader: reader2 } = await getCliProjectContext();
|
|
201527
201617
|
switch (action) {
|
|
201528
201618
|
case "export": {
|
|
201529
201619
|
const format = args.format === "markdown" ? "markdown" : "json";
|
|
201530
201620
|
if (format === "markdown") {
|
|
201531
|
-
const markdown = await exportAsMarkdown(dataDir, project.id,
|
|
201621
|
+
const markdown = await exportAsMarkdown(dataDir, project.id, reader2);
|
|
201532
201622
|
const output2 = args.out?.trim();
|
|
201533
201623
|
if (output2) {
|
|
201534
201624
|
const outputPath = await writeExportPayload(project.rootPath, output2, markdown);
|
|
@@ -201538,7 +201628,7 @@ var init_transfer = __esm({
|
|
|
201538
201628
|
emitResult({ project, format, markdown }, markdown, asJson);
|
|
201539
201629
|
return;
|
|
201540
201630
|
}
|
|
201541
|
-
const exported = await exportAsJson(dataDir, project.id,
|
|
201631
|
+
const exported = await exportAsJson(dataDir, project.id, reader2);
|
|
201542
201632
|
const serialized = JSON.stringify(exported, null, 2);
|
|
201543
201633
|
const output = args.out?.trim();
|
|
201544
201634
|
if (output) {
|
|
@@ -201987,7 +202077,7 @@ var init_skills3 = __esm({
|
|
|
201987
202077
|
const action = args._?.[0] || "";
|
|
201988
202078
|
const asJson = !!args.json;
|
|
201989
202079
|
try {
|
|
201990
|
-
const { project, reader } = await getCliProjectContext();
|
|
202080
|
+
const { project, reader: reader2 } = await getCliProjectContext();
|
|
201991
202081
|
const { SkillsEngine: SkillsEngine2 } = await Promise.resolve().then(() => (init_engine4(), engine_exports2));
|
|
201992
202082
|
const engine = new SkillsEngine2(project.rootPath);
|
|
201993
202083
|
switch (action) {
|
|
@@ -202003,7 +202093,7 @@ var init_skills3 = __esm({
|
|
|
202003
202093
|
case "generate": {
|
|
202004
202094
|
const observations2 = filterReadableObservations(
|
|
202005
202095
|
await getObservationStore().loadAll(),
|
|
202006
|
-
|
|
202096
|
+
reader2
|
|
202007
202097
|
).filter((observation) => resolveObservationVisibility(observation) === "project").map((obs) => ({
|
|
202008
202098
|
id: obs.id,
|
|
202009
202099
|
entityName: obs.entityName,
|
|
@@ -202045,7 +202135,7 @@ var init_skills3 = __esm({
|
|
|
202045
202135
|
}
|
|
202046
202136
|
const observations2 = filterReadableObservations(
|
|
202047
202137
|
await getObservationStore().loadAll(),
|
|
202048
|
-
|
|
202138
|
+
reader2
|
|
202049
202139
|
).filter((observation) => resolveObservationVisibility(observation) === "project").map((obs) => ({
|
|
202050
202140
|
id: obs.id,
|
|
202051
202141
|
entityName: obs.entityName,
|
|
@@ -202121,7 +202211,7 @@ var init_identity2 = __esm({
|
|
|
202121
202211
|
const action = (args._?.[0] || "status").toLowerCase();
|
|
202122
202212
|
const asJson = !!args.json;
|
|
202123
202213
|
try {
|
|
202124
|
-
const { project, dataDir, teamStore, identity, reader, identityWarning } = await getCliProjectContext();
|
|
202214
|
+
const { project, dataDir, teamStore, identity, reader: reader2, identityWarning } = await getCliProjectContext();
|
|
202125
202215
|
switch (action) {
|
|
202126
202216
|
case "status": {
|
|
202127
202217
|
const saved = await loadCliIdentity(dataDir, project.id);
|
|
@@ -202132,7 +202222,7 @@ var init_identity2 = __esm({
|
|
|
202132
202222
|
identity,
|
|
202133
202223
|
savedIdentity: saved,
|
|
202134
202224
|
agent: agent ?? null,
|
|
202135
|
-
reader,
|
|
202225
|
+
reader: reader2,
|
|
202136
202226
|
...identityWarning ? { warning: identityWarning } : {}
|
|
202137
202227
|
},
|
|
202138
202228
|
identity ? `CLI identity: ${agent?.name ?? identity.agentId} (${identity.agentId})` : identityWarning ?? 'CLI identity: project-scoped only. Use "memorix identity join" or "memorix identity use --agent-id <id>" for private/team operations.',
|
|
@@ -202298,7 +202388,7 @@ var init_session2 = __esm({
|
|
|
202298
202388
|
const action = args._?.[0] || "";
|
|
202299
202389
|
const asJson = !!args.json;
|
|
202300
202390
|
try {
|
|
202301
|
-
const { project, dataDir, teamStore, reader } = await getCliProjectContext({
|
|
202391
|
+
const { project, dataDir, teamStore, reader: reader2 } = await getCliProjectContext({
|
|
202302
202392
|
projectRoot: args.projectRoot
|
|
202303
202393
|
});
|
|
202304
202394
|
switch (action) {
|
|
@@ -202332,7 +202422,7 @@ var init_session2 = __esm({
|
|
|
202332
202422
|
projectId: project.id,
|
|
202333
202423
|
agentId: agentRecord.agent_id,
|
|
202334
202424
|
isTeamMember: agentRecord.status === "active"
|
|
202335
|
-
} :
|
|
202425
|
+
} : reader2;
|
|
202336
202426
|
const result = await startSession(dataDir, project.id, {
|
|
202337
202427
|
sessionId: args.sessionId,
|
|
202338
202428
|
agent: args.agent,
|
|
@@ -202427,7 +202517,7 @@ var init_session2 = __esm({
|
|
|
202427
202517
|
case "context": {
|
|
202428
202518
|
const limit2 = parsePositiveInt(args.limit, 3);
|
|
202429
202519
|
const [context, sessions] = await Promise.all([
|
|
202430
|
-
getSessionContext(dataDir, project.id, limit2,
|
|
202520
|
+
getSessionContext(dataDir, project.id, limit2, reader2),
|
|
202431
202521
|
listSessions(dataDir, project.id)
|
|
202432
202522
|
]);
|
|
202433
202523
|
const active = sessions.filter((session) => session.status === "active").length;
|
|
@@ -203981,7 +204071,7 @@ var init_poll2 = __esm({
|
|
|
203981
204071
|
try {
|
|
203982
204072
|
const { project, teamStore, identity, reader: activeReader } = await getCliProjectContext();
|
|
203983
204073
|
const agentId = resolveCliActorId(args.agentId, identity);
|
|
203984
|
-
let
|
|
204074
|
+
let reader2 = activeReader;
|
|
203985
204075
|
let watermark = computeWatermark(0, 0, 0);
|
|
203986
204076
|
if (agentId) {
|
|
203987
204077
|
const agent = teamStore.getAgent(agentId);
|
|
@@ -203989,7 +204079,7 @@ var init_poll2 = __esm({
|
|
|
203989
204079
|
emitError(`Unknown agent "${agentId}"`, asJson);
|
|
203990
204080
|
return;
|
|
203991
204081
|
}
|
|
203992
|
-
|
|
204082
|
+
reader2 = {
|
|
203993
204083
|
projectId: project.id,
|
|
203994
204084
|
agentId,
|
|
203995
204085
|
isTeamMember: agent.status === "active"
|
|
@@ -204001,7 +204091,7 @@ var init_poll2 = __esm({
|
|
|
204001
204091
|
getAllObservations().filter(
|
|
204002
204092
|
(obs) => obs.projectId === project.id && (obs.writeGeneration ?? 0) > lastSeen
|
|
204003
204093
|
),
|
|
204004
|
-
|
|
204094
|
+
reader2
|
|
204005
204095
|
)
|
|
204006
204096
|
);
|
|
204007
204097
|
watermark = computeWatermark(lastSeen, currentGen, projectObs.length);
|
|
@@ -217817,6 +217907,350 @@ var init_behavior = __esm({
|
|
|
217817
217907
|
}
|
|
217818
217908
|
});
|
|
217819
217909
|
|
|
217910
|
+
// src/memory/cleanup.ts
|
|
217911
|
+
function isLowQualityObservation(title) {
|
|
217912
|
+
return LOW_QUALITY_PATTERNS.some((pattern) => pattern.test(title.trim()));
|
|
217913
|
+
}
|
|
217914
|
+
function classifyNoiseObservation(observation) {
|
|
217915
|
+
const title = observation.title?.trim() ?? "";
|
|
217916
|
+
const entityName = observation.entityName?.trim().toLowerCase() ?? "";
|
|
217917
|
+
const concepts = (observation.concepts ?? []).map((concept) => concept.trim().toLowerCase());
|
|
217918
|
+
if (entityName === "memorix.demo" || entityName.startsWith("for_memmcp_test") || concepts.some((concept) => EXPLICIT_NOISE_MARKERS.has(concept))) {
|
|
217919
|
+
return { isNoise: true, reason: "system-self" };
|
|
217920
|
+
}
|
|
217921
|
+
if (EXPLICIT_NOISE_TITLE_PATTERNS.some((pattern) => pattern.test(title))) {
|
|
217922
|
+
return { isNoise: true, reason: "demo/test/noise" };
|
|
217923
|
+
}
|
|
217924
|
+
return { isNoise: false };
|
|
217925
|
+
}
|
|
217926
|
+
function analyzeCleanupObservations(observations2, options = {}) {
|
|
217927
|
+
const active = observations2.filter((observation) => (observation.status ?? "active") === "active");
|
|
217928
|
+
const lowQuality = active.filter((observation) => isLowQualityObservation(observation.title ?? ""));
|
|
217929
|
+
const lowQualityIds = new Set(lowQuality.map((observation) => observation.id));
|
|
217930
|
+
const highQuality = active.filter((observation) => !lowQualityIds.has(observation.id));
|
|
217931
|
+
const groups = /* @__PURE__ */ new Map();
|
|
217932
|
+
for (const observation of highQuality) {
|
|
217933
|
+
const key = `${observation.type}|${observation.title}|${observation.entityName}`;
|
|
217934
|
+
const existing = groups.get(key);
|
|
217935
|
+
if (existing) existing.duplicates.push(observation);
|
|
217936
|
+
else groups.set(key, { canonical: observation, duplicates: [] });
|
|
217937
|
+
}
|
|
217938
|
+
const duplicateGroups = [...groups.values()].filter((group) => group.duplicates.length > 0);
|
|
217939
|
+
const duplicates = duplicateGroups.flatMap((group) => group.duplicates);
|
|
217940
|
+
const excludedIds = new Set([...lowQuality, ...duplicates].map((observation) => observation.id));
|
|
217941
|
+
const noise = [];
|
|
217942
|
+
if (options.includeNoise) {
|
|
217943
|
+
for (const observation of active) {
|
|
217944
|
+
if (excludedIds.has(observation.id)) continue;
|
|
217945
|
+
const classification = classifyNoiseObservation(observation);
|
|
217946
|
+
if (classification.isNoise && classification.reason) {
|
|
217947
|
+
noise.push({ observation, reason: classification.reason });
|
|
217948
|
+
}
|
|
217949
|
+
}
|
|
217950
|
+
}
|
|
217951
|
+
const toRemove = [...lowQuality, ...duplicates];
|
|
217952
|
+
const toArchive = noise.map((hit) => hit.observation);
|
|
217953
|
+
return {
|
|
217954
|
+
totalActive: active.length,
|
|
217955
|
+
highQuality: highQuality.length - duplicates.length - toArchive.length,
|
|
217956
|
+
lowQuality,
|
|
217957
|
+
duplicateGroups,
|
|
217958
|
+
duplicates,
|
|
217959
|
+
noise,
|
|
217960
|
+
toRemove,
|
|
217961
|
+
toArchive
|
|
217962
|
+
};
|
|
217963
|
+
}
|
|
217964
|
+
function requireObservationIds(observations2, action) {
|
|
217965
|
+
const ids = observations2.map((observation) => observation.id);
|
|
217966
|
+
if (ids.some((id) => typeof id !== "number")) {
|
|
217967
|
+
throw new Error(`Cannot ${action}: an observation has no persisted ID.`);
|
|
217968
|
+
}
|
|
217969
|
+
return ids;
|
|
217970
|
+
}
|
|
217971
|
+
async function applyCleanupMutations(store2, toArchive, toRemove) {
|
|
217972
|
+
const archiveIds = requireObservationIds(toArchive, "archive");
|
|
217973
|
+
const removeIds = requireObservationIds(toRemove, "delete");
|
|
217974
|
+
const removals = new Set(removeIds);
|
|
217975
|
+
if (archiveIds.some((id) => removals.has(id))) {
|
|
217976
|
+
throw new Error("Cleanup cannot archive and delete the same observation.");
|
|
217977
|
+
}
|
|
217978
|
+
await store2.atomic(async (tx) => {
|
|
217979
|
+
await Promise.all(archiveIds.map((id) => tx.setStatus(id, "archived", "active")));
|
|
217980
|
+
await Promise.all(removeIds.map((id) => tx.remove(id)));
|
|
217981
|
+
});
|
|
217982
|
+
return { archived: archiveIds.length, removed: removeIds.length };
|
|
217983
|
+
}
|
|
217984
|
+
var LOW_QUALITY_PATTERNS, EXPLICIT_NOISE_TITLE_PATTERNS, EXPLICIT_NOISE_MARKERS;
|
|
217985
|
+
var init_cleanup = __esm({
|
|
217986
|
+
"src/memory/cleanup.ts"() {
|
|
217987
|
+
"use strict";
|
|
217988
|
+
init_esm_shims();
|
|
217989
|
+
LOW_QUALITY_PATTERNS = [
|
|
217990
|
+
/^Session activity/i,
|
|
217991
|
+
/^Updated \S+\.\w+$/i,
|
|
217992
|
+
/^Created \S+\.\w+$/i,
|
|
217993
|
+
/^Deleted \S+\.\w+$/i,
|
|
217994
|
+
/^Modified \S+\.\w+$/i,
|
|
217995
|
+
/^Ran command:/i,
|
|
217996
|
+
/^Read file:/i
|
|
217997
|
+
];
|
|
217998
|
+
EXPLICIT_NOISE_TITLE_PATTERNS = [
|
|
217999
|
+
/^\s*\[(?:test|demo|benchmark|sandbox|playground|测试|演示)\]/i,
|
|
218000
|
+
/^\s*(?:Used\s+(?:mcp__\S+|apply_patch)|Ran:)\s*/i
|
|
218001
|
+
];
|
|
218002
|
+
EXPLICIT_NOISE_MARKERS = /* @__PURE__ */ new Set([
|
|
218003
|
+
"test-fixture",
|
|
218004
|
+
"demo-fixture",
|
|
218005
|
+
"benchmark-fixture",
|
|
218006
|
+
"sandbox-fixture",
|
|
218007
|
+
"cleanup-noise"
|
|
218008
|
+
]);
|
|
218009
|
+
}
|
|
218010
|
+
});
|
|
218011
|
+
|
|
218012
|
+
// src/dashboard/maintenance.ts
|
|
218013
|
+
import { createHmac, randomBytes, timingSafeEqual } from "crypto";
|
|
218014
|
+
function reader(projectId) {
|
|
218015
|
+
return { projectId };
|
|
218016
|
+
}
|
|
218017
|
+
function summarize(observation) {
|
|
218018
|
+
return {
|
|
218019
|
+
id: observation.id,
|
|
218020
|
+
title: observation.title,
|
|
218021
|
+
type: observation.type,
|
|
218022
|
+
entityName: observation.entityName
|
|
218023
|
+
};
|
|
218024
|
+
}
|
|
218025
|
+
function normalizeIds(ids) {
|
|
218026
|
+
return [...new Set(ids)].sort((left, right) => left - right);
|
|
218027
|
+
}
|
|
218028
|
+
function normalizeClusters(clusters) {
|
|
218029
|
+
return clusters.map((ids) => normalizeIds(ids)).sort((left, right) => left.join(",").localeCompare(right.join(",")));
|
|
218030
|
+
}
|
|
218031
|
+
function payloadRecord(payload) {
|
|
218032
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
218033
|
+
throw new DashboardMaintenanceError("The maintenance preview payload is missing.", 400);
|
|
218034
|
+
}
|
|
218035
|
+
return payload;
|
|
218036
|
+
}
|
|
218037
|
+
function payloadIds(value, field) {
|
|
218038
|
+
if (!Array.isArray(value) || value.some((id) => !Number.isSafeInteger(id) || Number(id) <= 0)) {
|
|
218039
|
+
throw new DashboardMaintenanceError(`Invalid ${field} in maintenance preview.`, 400);
|
|
218040
|
+
}
|
|
218041
|
+
return normalizeIds(value);
|
|
218042
|
+
}
|
|
218043
|
+
function sign(action, projectId, payload) {
|
|
218044
|
+
return createHmac("sha256", previewSecret).update(JSON.stringify({ action, projectId, payload })).digest("hex");
|
|
218045
|
+
}
|
|
218046
|
+
function verify(action, projectId, payload, token) {
|
|
218047
|
+
if (typeof token !== "string" || !/^[a-f0-9]{64}$/.test(token)) {
|
|
218048
|
+
throw new DashboardMaintenanceError("Preview this maintenance action before executing it.", 400);
|
|
218049
|
+
}
|
|
218050
|
+
const expected = Buffer.from(sign(action, projectId, payload), "hex");
|
|
218051
|
+
const received = Buffer.from(token, "hex");
|
|
218052
|
+
if (!timingSafeEqual(expected, received)) {
|
|
218053
|
+
throw new DashboardMaintenanceError("The maintenance preview is invalid or belongs to another project.", 409);
|
|
218054
|
+
}
|
|
218055
|
+
}
|
|
218056
|
+
function assertCurrent(expected, actual) {
|
|
218057
|
+
if (JSON.stringify(normalizeIds(expected)) !== JSON.stringify(normalizeIds(actual))) {
|
|
218058
|
+
throw new DashboardMaintenanceError("Memory changed after the preview. Refresh the preview before executing.", 409);
|
|
218059
|
+
}
|
|
218060
|
+
}
|
|
218061
|
+
async function manageableActiveObservations(context) {
|
|
218062
|
+
const scope = reader(context.projectId);
|
|
218063
|
+
return filterReadableObservations(
|
|
218064
|
+
await context.store.loadByProject(context.projectId, { status: "active" }),
|
|
218065
|
+
scope
|
|
218066
|
+
).filter((observation) => canManageObservation(observation, scope));
|
|
218067
|
+
}
|
|
218068
|
+
function cleanupPayload(includeNoise, analysis) {
|
|
218069
|
+
return {
|
|
218070
|
+
includeNoise,
|
|
218071
|
+
removeIds: normalizeIds(analysis.toRemove.map((observation) => observation.id)),
|
|
218072
|
+
archiveIds: normalizeIds(analysis.toArchive.map((observation) => observation.id))
|
|
218073
|
+
};
|
|
218074
|
+
}
|
|
218075
|
+
async function previewCleanup(context, includeNoise) {
|
|
218076
|
+
const analysis = analyzeCleanupObservations(await manageableActiveObservations(context), { includeNoise });
|
|
218077
|
+
const payload = cleanupPayload(includeNoise, analysis);
|
|
218078
|
+
return {
|
|
218079
|
+
action: "cleanup",
|
|
218080
|
+
projectId: context.projectId,
|
|
218081
|
+
includeNoise,
|
|
218082
|
+
summary: {
|
|
218083
|
+
totalActive: analysis.totalActive,
|
|
218084
|
+
highQuality: analysis.highQuality,
|
|
218085
|
+
lowQuality: analysis.lowQuality.length,
|
|
218086
|
+
duplicates: analysis.duplicates.length,
|
|
218087
|
+
noise: analysis.noise.length,
|
|
218088
|
+
delete: analysis.toRemove.length,
|
|
218089
|
+
archive: analysis.toArchive.length
|
|
218090
|
+
},
|
|
218091
|
+
lowQuality: analysis.lowQuality.map(summarize),
|
|
218092
|
+
duplicateGroups: analysis.duplicateGroups.map((group) => ({
|
|
218093
|
+
canonical: summarize(group.canonical),
|
|
218094
|
+
duplicates: group.duplicates.map(summarize)
|
|
218095
|
+
})),
|
|
218096
|
+
noise: analysis.noise.map((hit) => ({ ...summarize(hit.observation), reason: hit.reason })),
|
|
218097
|
+
payload,
|
|
218098
|
+
token: sign("cleanup", context.projectId, payload)
|
|
218099
|
+
};
|
|
218100
|
+
}
|
|
218101
|
+
async function executeCleanup(context, payload, token) {
|
|
218102
|
+
const record2 = payloadRecord(payload);
|
|
218103
|
+
const normalized = {
|
|
218104
|
+
includeNoise: record2.includeNoise === true,
|
|
218105
|
+
removeIds: payloadIds(record2.removeIds, "removeIds"),
|
|
218106
|
+
archiveIds: payloadIds(record2.archiveIds, "archiveIds")
|
|
218107
|
+
};
|
|
218108
|
+
verify("cleanup", context.projectId, normalized, token);
|
|
218109
|
+
const observations2 = await manageableActiveObservations(context);
|
|
218110
|
+
const analysis = analyzeCleanupObservations(observations2, { includeNoise: normalized.includeNoise });
|
|
218111
|
+
const current = cleanupPayload(normalized.includeNoise, analysis);
|
|
218112
|
+
assertCurrent(normalized.removeIds, current.removeIds);
|
|
218113
|
+
assertCurrent(normalized.archiveIds, current.archiveIds);
|
|
218114
|
+
const result = await applyCleanupMutations(context.store, analysis.toArchive, analysis.toRemove);
|
|
218115
|
+
return { action: "cleanup", projectId: context.projectId, ...result };
|
|
218116
|
+
}
|
|
218117
|
+
async function previewDeduplicate(context) {
|
|
218118
|
+
if (!isLLMEnabled()) {
|
|
218119
|
+
return {
|
|
218120
|
+
action: "deduplicate",
|
|
218121
|
+
projectId: context.projectId,
|
|
218122
|
+
available: false,
|
|
218123
|
+
reason: "Intelligent deduplication requires a configured memory LLM."
|
|
218124
|
+
};
|
|
218125
|
+
}
|
|
218126
|
+
const plan = await planMemoryDeduplication(await manageableActiveObservations(context));
|
|
218127
|
+
const payload = { resolveIds: normalizeIds(plan.resolveIds) };
|
|
218128
|
+
return {
|
|
218129
|
+
action: "deduplicate",
|
|
218130
|
+
projectId: context.projectId,
|
|
218131
|
+
available: true,
|
|
218132
|
+
summary: {
|
|
218133
|
+
scanned: plan.scanned,
|
|
218134
|
+
entities: plan.entities,
|
|
218135
|
+
comparisons: plan.comparisons,
|
|
218136
|
+
failedComparisons: plan.failedComparisons,
|
|
218137
|
+
resolve: payload.resolveIds.length
|
|
218138
|
+
},
|
|
218139
|
+
actions: plan.actions,
|
|
218140
|
+
payload,
|
|
218141
|
+
token: sign("deduplicate", context.projectId, payload)
|
|
218142
|
+
};
|
|
218143
|
+
}
|
|
218144
|
+
async function executeDeduplicate(context, payload, token) {
|
|
218145
|
+
const record2 = payloadRecord(payload);
|
|
218146
|
+
const normalized = { resolveIds: payloadIds(record2.resolveIds, "resolveIds") };
|
|
218147
|
+
verify("deduplicate", context.projectId, normalized, token);
|
|
218148
|
+
const result = await applyDeduplicationPlan(
|
|
218149
|
+
context.store,
|
|
218150
|
+
context.projectId,
|
|
218151
|
+
normalized.resolveIds,
|
|
218152
|
+
reader(context.projectId)
|
|
218153
|
+
);
|
|
218154
|
+
if (result.skipped.length > 0) {
|
|
218155
|
+
throw new DashboardMaintenanceError("Memory changed after the preview. Refresh before applying deduplication.", 409);
|
|
218156
|
+
}
|
|
218157
|
+
return { action: "deduplicate", projectId: context.projectId, ...result };
|
|
218158
|
+
}
|
|
218159
|
+
async function previewConsolidate(context) {
|
|
218160
|
+
const clusters = await findConsolidationCandidates(
|
|
218161
|
+
context.projectRoot ?? context.dataDir,
|
|
218162
|
+
context.projectId
|
|
218163
|
+
);
|
|
218164
|
+
const payload = { clusterIds: normalizeClusters(clusters.map((cluster) => cluster.ids)) };
|
|
218165
|
+
return {
|
|
218166
|
+
action: "consolidate",
|
|
218167
|
+
projectId: context.projectId,
|
|
218168
|
+
summary: {
|
|
218169
|
+
clusters: clusters.length,
|
|
218170
|
+
observations: normalizeIds(clusters.flatMap((cluster) => cluster.ids)).length
|
|
218171
|
+
},
|
|
218172
|
+
clusters,
|
|
218173
|
+
payload,
|
|
218174
|
+
token: sign("consolidate", context.projectId, payload)
|
|
218175
|
+
};
|
|
218176
|
+
}
|
|
218177
|
+
async function executeConsolidate(context, payload, token) {
|
|
218178
|
+
const record2 = payloadRecord(payload);
|
|
218179
|
+
if (!Array.isArray(record2.clusterIds)) {
|
|
218180
|
+
throw new DashboardMaintenanceError("Invalid clusterIds in maintenance preview.", 400);
|
|
218181
|
+
}
|
|
218182
|
+
const clusterIds = record2.clusterIds.map((ids, index) => payloadIds(ids, `clusterIds[${index}]`));
|
|
218183
|
+
const normalized = { clusterIds: normalizeClusters(clusterIds) };
|
|
218184
|
+
verify("consolidate", context.projectId, normalized, token);
|
|
218185
|
+
const current = await findConsolidationCandidates(context.projectRoot ?? context.dataDir, context.projectId);
|
|
218186
|
+
if (JSON.stringify(normalized.clusterIds) !== JSON.stringify(normalizeClusters(current.map((cluster) => cluster.ids)))) {
|
|
218187
|
+
throw new DashboardMaintenanceError("Memory changed after the preview. Refresh before consolidating.", 409);
|
|
218188
|
+
}
|
|
218189
|
+
const result = await executeConsolidation(context.projectRoot ?? context.dataDir, context.projectId);
|
|
218190
|
+
return { action: "consolidate", projectId: context.projectId, ...result };
|
|
218191
|
+
}
|
|
218192
|
+
async function retentionCandidates(context) {
|
|
218193
|
+
return (await manageableActiveObservations(context)).map((observation) => ({
|
|
218194
|
+
observation,
|
|
218195
|
+
retention: projectObservationRetention(observation)
|
|
218196
|
+
})).filter((row) => row.retention.zone === "archive-candidate");
|
|
218197
|
+
}
|
|
218198
|
+
async function previewRetentionArchive(context) {
|
|
218199
|
+
const candidates = await retentionCandidates(context);
|
|
218200
|
+
const payload = {
|
|
218201
|
+
archiveIds: normalizeIds(candidates.map((candidate2) => candidate2.observation.id))
|
|
218202
|
+
};
|
|
218203
|
+
return {
|
|
218204
|
+
action: "retention-archive",
|
|
218205
|
+
projectId: context.projectId,
|
|
218206
|
+
summary: { archive: payload.archiveIds.length },
|
|
218207
|
+
candidates: candidates.map(({ observation, retention }) => ({
|
|
218208
|
+
...summarize(observation),
|
|
218209
|
+
score: retention.displayScore,
|
|
218210
|
+
zone: retention.zone,
|
|
218211
|
+
ageHours: retention.ageHours
|
|
218212
|
+
})),
|
|
218213
|
+
payload,
|
|
218214
|
+
token: sign("retention-archive", context.projectId, payload)
|
|
218215
|
+
};
|
|
218216
|
+
}
|
|
218217
|
+
async function executeRetentionArchive(context, payload, token) {
|
|
218218
|
+
const record2 = payloadRecord(payload);
|
|
218219
|
+
const normalized = { archiveIds: payloadIds(record2.archiveIds, "archiveIds") };
|
|
218220
|
+
verify("retention-archive", context.projectId, normalized, token);
|
|
218221
|
+
const current = await retentionCandidates(context);
|
|
218222
|
+
assertCurrent(normalized.archiveIds, current.map((candidate2) => candidate2.observation.id));
|
|
218223
|
+
const result = await archiveExpired(
|
|
218224
|
+
context.dataDir,
|
|
218225
|
+
void 0,
|
|
218226
|
+
void 0,
|
|
218227
|
+
context.projectId,
|
|
218228
|
+
reader(context.projectId)
|
|
218229
|
+
);
|
|
218230
|
+
return { action: "retention-archive", projectId: context.projectId, ...result };
|
|
218231
|
+
}
|
|
218232
|
+
var previewSecret, DashboardMaintenanceError;
|
|
218233
|
+
var init_maintenance = __esm({
|
|
218234
|
+
"src/dashboard/maintenance.ts"() {
|
|
218235
|
+
"use strict";
|
|
218236
|
+
init_esm_shims();
|
|
218237
|
+
init_provider2();
|
|
218238
|
+
init_cleanup();
|
|
218239
|
+
init_consolidation();
|
|
218240
|
+
init_deduplication();
|
|
218241
|
+
init_retention();
|
|
218242
|
+
init_visibility();
|
|
218243
|
+
previewSecret = randomBytes(32);
|
|
218244
|
+
DashboardMaintenanceError = class extends Error {
|
|
218245
|
+
constructor(message, status) {
|
|
218246
|
+
super(message);
|
|
218247
|
+
this.status = status;
|
|
218248
|
+
}
|
|
218249
|
+
status;
|
|
218250
|
+
};
|
|
218251
|
+
}
|
|
218252
|
+
});
|
|
218253
|
+
|
|
217820
218254
|
// src/dashboard/project-classification.ts
|
|
217821
218255
|
var project_classification_exports = {};
|
|
217822
218256
|
__export(project_classification_exports, {
|
|
@@ -218419,6 +218853,56 @@ function filterDashboardObservations(observations2, projectId) {
|
|
|
218419
218853
|
function isActiveStatus(status) {
|
|
218420
218854
|
return (status ?? "active") === "active";
|
|
218421
218855
|
}
|
|
218856
|
+
async function handleMaintenanceMutation(apiPath, req, res, context) {
|
|
218857
|
+
if (req.method !== "POST") {
|
|
218858
|
+
throw new DashboardMaintenanceError("Maintenance actions require POST.", 405);
|
|
218859
|
+
}
|
|
218860
|
+
let body = {};
|
|
218861
|
+
const raw = await readBody(req);
|
|
218862
|
+
if (raw.trim()) {
|
|
218863
|
+
try {
|
|
218864
|
+
const parsed = JSON.parse(raw);
|
|
218865
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("object required");
|
|
218866
|
+
body = parsed;
|
|
218867
|
+
} catch {
|
|
218868
|
+
throw new DashboardMaintenanceError("Invalid maintenance request body.", 400);
|
|
218869
|
+
}
|
|
218870
|
+
}
|
|
218871
|
+
const maintenanceContext = {
|
|
218872
|
+
...context,
|
|
218873
|
+
store: getObservationStore()
|
|
218874
|
+
};
|
|
218875
|
+
let result;
|
|
218876
|
+
switch (apiPath) {
|
|
218877
|
+
case "/maintenance/cleanup/preview":
|
|
218878
|
+
result = await previewCleanup(maintenanceContext, body.includeNoise === true);
|
|
218879
|
+
break;
|
|
218880
|
+
case "/maintenance/cleanup/execute":
|
|
218881
|
+
result = await executeCleanup(maintenanceContext, body.payload, body.token);
|
|
218882
|
+
break;
|
|
218883
|
+
case "/maintenance/deduplicate/preview":
|
|
218884
|
+
result = await previewDeduplicate(maintenanceContext);
|
|
218885
|
+
break;
|
|
218886
|
+
case "/maintenance/deduplicate/execute":
|
|
218887
|
+
result = await executeDeduplicate(maintenanceContext, body.payload, body.token);
|
|
218888
|
+
break;
|
|
218889
|
+
case "/maintenance/consolidate/preview":
|
|
218890
|
+
result = await previewConsolidate(maintenanceContext);
|
|
218891
|
+
break;
|
|
218892
|
+
case "/maintenance/consolidate/execute":
|
|
218893
|
+
result = await executeConsolidate(maintenanceContext, body.payload, body.token);
|
|
218894
|
+
break;
|
|
218895
|
+
case "/maintenance/retention/preview":
|
|
218896
|
+
result = await previewRetentionArchive(maintenanceContext);
|
|
218897
|
+
break;
|
|
218898
|
+
case "/maintenance/retention/execute":
|
|
218899
|
+
result = await executeRetentionArchive(maintenanceContext, body.payload, body.token);
|
|
218900
|
+
break;
|
|
218901
|
+
default:
|
|
218902
|
+
throw new DashboardMaintenanceError("Unknown maintenance action.", 404);
|
|
218903
|
+
}
|
|
218904
|
+
sendJson(res, result);
|
|
218905
|
+
}
|
|
218422
218906
|
function prepareDashboardConfig(projectRoot) {
|
|
218423
218907
|
if (!projectRoot) {
|
|
218424
218908
|
if (preparedDashboardProjectRoot !== null) {
|
|
@@ -218461,6 +218945,21 @@ async function handleApi(req, res, dataDir, projectId, projectName, baseDir, pro
|
|
|
218461
218945
|
prepareDashboardConfig(effectiveProjectRoot);
|
|
218462
218946
|
try {
|
|
218463
218947
|
switch (apiPath) {
|
|
218948
|
+
case "/maintenance/cleanup/preview":
|
|
218949
|
+
case "/maintenance/cleanup/execute":
|
|
218950
|
+
case "/maintenance/deduplicate/preview":
|
|
218951
|
+
case "/maintenance/deduplicate/execute":
|
|
218952
|
+
case "/maintenance/consolidate/preview":
|
|
218953
|
+
case "/maintenance/consolidate/execute":
|
|
218954
|
+
case "/maintenance/retention/preview":
|
|
218955
|
+
case "/maintenance/retention/execute": {
|
|
218956
|
+
await handleMaintenanceMutation(apiPath, req, res, {
|
|
218957
|
+
dataDir: effectiveDataDir,
|
|
218958
|
+
projectId: effectiveProjectId,
|
|
218959
|
+
projectRoot: effectiveProjectRoot
|
|
218960
|
+
});
|
|
218961
|
+
break;
|
|
218962
|
+
}
|
|
218464
218963
|
case "/projects": {
|
|
218465
218964
|
try {
|
|
218466
218965
|
const allObs = filterReadableObservations(
|
|
@@ -218984,7 +219483,8 @@ async function handleApi(req, res, dataDir, projectId, projectName, baseDir, pro
|
|
|
218984
219483
|
}
|
|
218985
219484
|
} catch (err) {
|
|
218986
219485
|
const message = err instanceof Error ? err.message : "Unknown error";
|
|
218987
|
-
|
|
219486
|
+
const status = err instanceof DashboardMaintenanceError ? err.status : 500;
|
|
219487
|
+
sendError(res, message, status);
|
|
218988
219488
|
}
|
|
218989
219489
|
}
|
|
218990
219490
|
async function serveStatic(req, res, staticDir) {
|
|
@@ -219155,7 +219655,15 @@ async function buildTeamSnapshot(dataDir, projectId, scope, mode) {
|
|
|
219155
219655
|
function readBody(req) {
|
|
219156
219656
|
return new Promise((resolve6, reject) => {
|
|
219157
219657
|
const chunks = [];
|
|
219158
|
-
|
|
219658
|
+
let size = 0;
|
|
219659
|
+
req.on("data", (c6) => {
|
|
219660
|
+
size += c6.length;
|
|
219661
|
+
if (size > 64 * 1024) {
|
|
219662
|
+
reject(new DashboardMaintenanceError("Request body is too large.", 413));
|
|
219663
|
+
return;
|
|
219664
|
+
}
|
|
219665
|
+
chunks.push(c6);
|
|
219666
|
+
});
|
|
219159
219667
|
req.on("end", () => resolve6(Buffer.concat(chunks).toString("utf-8")));
|
|
219160
219668
|
req.on("error", reject);
|
|
219161
219669
|
});
|
|
@@ -219288,6 +219796,7 @@ var init_server3 = __esm({
|
|
|
219288
219796
|
init_graph_scope();
|
|
219289
219797
|
init_retention();
|
|
219290
219798
|
init_visibility();
|
|
219799
|
+
init_maintenance();
|
|
219291
219800
|
MIME_TYPES = {
|
|
219292
219801
|
".html": "text/html; charset=utf-8",
|
|
219293
219802
|
".css": "text/css; charset=utf-8",
|
|
@@ -259694,7 +260203,7 @@ The path should point to a directory containing a .git folder.`
|
|
|
259694
260203
|
};
|
|
259695
260204
|
const server = existingServer ?? new McpServer({
|
|
259696
260205
|
name: "memorix",
|
|
259697
|
-
version: true ? "1.
|
|
260206
|
+
version: true ? "1.7.1" : "1.0.1"
|
|
259698
260207
|
});
|
|
259699
260208
|
const originalRegisterTool = server.registerTool.bind(server);
|
|
259700
260209
|
server.registerTool = ((name, ...args) => {
|
|
@@ -259824,20 +260333,20 @@ The path should point to a directory containing a .git folder.`
|
|
|
259824
260333
|
if (readOnlyBoundary) return readOnlyBoundary;
|
|
259825
260334
|
const requestedVisibility = longTerm?.scope === "user" ? "personal" : longTerm?.scope === "team" ? "team" : visibility;
|
|
259826
260335
|
const effectiveVisibility = requestedVisibility ?? "project";
|
|
259827
|
-
const
|
|
260336
|
+
const reader2 = getObservationReader();
|
|
259828
260337
|
if (effectiveVisibility !== "project" && !currentAgentId) {
|
|
259829
260338
|
return {
|
|
259830
260339
|
content: [{ type: "text", text: "Personal or team memory requires memorix_session_start with joinTeam=true so Memorix can bind an owner." }],
|
|
259831
260340
|
isError: true
|
|
259832
260341
|
};
|
|
259833
260342
|
}
|
|
259834
|
-
if (effectiveVisibility === "team" && !
|
|
260343
|
+
if (effectiveVisibility === "team" && !reader2.isTeamMember) {
|
|
259835
260344
|
return {
|
|
259836
260345
|
content: [{ type: "text", text: "Team memory requires an active coordination membership in the current project." }],
|
|
259837
260346
|
isError: true
|
|
259838
260347
|
};
|
|
259839
260348
|
}
|
|
259840
|
-
if (longTerm?.scope === "team" && !
|
|
260349
|
+
if (longTerm?.scope === "team" && !reader2.isTeamMember) {
|
|
259841
260350
|
return {
|
|
259842
260351
|
content: [{ type: "text", text: "Team long-term memory requires an active coordination membership in the current project." }],
|
|
259843
260352
|
isError: true
|
|
@@ -259884,9 +260393,9 @@ The path should point to a directory containing a .git folder.`
|
|
|
259884
260393
|
useLLM: isLLMEnabled(),
|
|
259885
260394
|
minValueScore: 0.3,
|
|
259886
260395
|
searchMemories: async (q4, limit2, pid, signal) => {
|
|
259887
|
-
const result = await compactSearch({ query: q4, limit: limit2, projectId: pid, status: "active", reader, signal });
|
|
260396
|
+
const result = await compactSearch({ query: q4, limit: limit2, projectId: pid, status: "active", reader: reader2, signal });
|
|
259888
260397
|
if (result.entries.length === 0) return [];
|
|
259889
|
-
const details = await compactDetail(result.entries.map((e5) => e5.id), { reader });
|
|
260398
|
+
const details = await compactDetail(result.entries.map((e5) => e5.id), { reader: reader2 });
|
|
259890
260399
|
return details.documents.map((d4, i4) => ({
|
|
259891
260400
|
id: Number(d4.id.replace("obs-", "")),
|
|
259892
260401
|
observationId: d4.observationId,
|
|
@@ -259900,7 +260409,7 @@ The path should point to a directory containing a .git folder.`
|
|
|
259900
260409
|
},
|
|
259901
260410
|
getObservation: (id) => {
|
|
259902
260411
|
const o4 = getObservation(id);
|
|
259903
|
-
if (!o4 || o4.projectId !== project.id || !canReadObservation(o4,
|
|
260412
|
+
if (!o4 || o4.projectId !== project.id || !canReadObservation(o4, reader2)) return null;
|
|
259904
260413
|
return {
|
|
259905
260414
|
id: o4.id,
|
|
259906
260415
|
entityName: o4.entityName,
|
|
@@ -259957,7 +260466,7 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
259957
260466
|
const { action: action2, targetId, reason } = formationResult.resolution;
|
|
259958
260467
|
if (action2 === "merge" && targetId) {
|
|
259959
260468
|
const targetObs = getObservation(targetId);
|
|
259960
|
-
if (targetObs && targetObs.projectId === project.id && canReadObservation(targetObs,
|
|
260469
|
+
if (targetObs && targetObs.projectId === project.id && canReadObservation(targetObs, reader2)) {
|
|
259961
260470
|
await storeObservation({
|
|
259962
260471
|
entityName: targetObs.entityName,
|
|
259963
260472
|
type: targetObs.type,
|
|
@@ -259972,7 +260481,7 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
259972
260481
|
sourceDetail: "explicit",
|
|
259973
260482
|
createdByAgentId: currentAgentId,
|
|
259974
260483
|
visibility,
|
|
259975
|
-
visibilityReader:
|
|
260484
|
+
visibilityReader: reader2
|
|
259976
260485
|
});
|
|
259977
260486
|
return {
|
|
259978
260487
|
content: [{
|
|
@@ -259983,7 +260492,7 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
259983
260492
|
}
|
|
259984
260493
|
} else if (action2 === "evolve" && targetId) {
|
|
259985
260494
|
const targetObs = getObservation(targetId);
|
|
259986
|
-
if (targetObs && targetObs.projectId === project.id && canReadObservation(targetObs,
|
|
260495
|
+
if (targetObs && targetObs.projectId === project.id && canReadObservation(targetObs, reader2)) {
|
|
259987
260496
|
await storeObservation({
|
|
259988
260497
|
entityName: targetObs.entityName,
|
|
259989
260498
|
type: targetObs.type,
|
|
@@ -259998,7 +260507,7 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
259998
260507
|
sourceDetail: "explicit",
|
|
259999
260508
|
createdByAgentId: currentAgentId,
|
|
260000
260509
|
visibility,
|
|
260001
|
-
visibilityReader:
|
|
260510
|
+
visibilityReader: reader2
|
|
260002
260511
|
});
|
|
260003
260512
|
return {
|
|
260004
260513
|
content: [{
|
|
@@ -260025,12 +260534,12 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
260025
260534
|
limit: 5,
|
|
260026
260535
|
projectId: project.id,
|
|
260027
260536
|
status: "active",
|
|
260028
|
-
reader
|
|
260537
|
+
reader: reader2
|
|
260029
260538
|
});
|
|
260030
260539
|
const similarEntries = searchResult.entries.map((e5) => e5);
|
|
260031
260540
|
if (similarEntries.length > 0) {
|
|
260032
260541
|
const similarIds = similarEntries.map((e5) => e5.id);
|
|
260033
|
-
const details = await compactDetail(similarIds, { reader });
|
|
260542
|
+
const details = await compactDetail(similarIds, { reader: reader2 });
|
|
260034
260543
|
const existingMemories = details.documents.map((d4, i4) => ({
|
|
260035
260544
|
id: d4.observationId,
|
|
260036
260545
|
title: d4.title,
|
|
@@ -260048,7 +260557,7 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
260048
260557
|
);
|
|
260049
260558
|
if (decision.action === "UPDATE" && decision.targetId) {
|
|
260050
260559
|
const targetObs = getObservation(decision.targetId);
|
|
260051
|
-
if (targetObs && targetObs.projectId === project.id && canReadObservation(targetObs,
|
|
260560
|
+
if (targetObs && targetObs.projectId === project.id && canReadObservation(targetObs, reader2)) {
|
|
260052
260561
|
await storeObservation({
|
|
260053
260562
|
entityName: targetObs.entityName,
|
|
260054
260563
|
type: targetObs.type,
|
|
@@ -260063,7 +260572,7 @@ ${modeIcon} Formation[active]: ${formationResult.evaluation.category} (${formati
|
|
|
260063
260572
|
sourceDetail: "explicit",
|
|
260064
260573
|
createdByAgentId: currentAgentId,
|
|
260065
260574
|
visibility,
|
|
260066
|
-
visibilityReader:
|
|
260575
|
+
visibilityReader: reader2
|
|
260067
260576
|
});
|
|
260068
260577
|
compactAction = `[UPDATED] Compact UPDATE: merged into #${decision.targetId} (${decision.reason})`;
|
|
260069
260578
|
compactMerged = true;
|
|
@@ -260150,7 +260659,7 @@ Mode: ${decision.usedLLM ? "LLM" : "heuristic"}`
|
|
|
260150
260659
|
const attrCheck = await checkProjectAttribution(
|
|
260151
260660
|
entityName,
|
|
260152
260661
|
project.id,
|
|
260153
|
-
filterReadableObservations(getAllObservations(),
|
|
260662
|
+
filterReadableObservations(getAllObservations(), reader2)
|
|
260154
260663
|
);
|
|
260155
260664
|
if (attrCheck.suspicious) {
|
|
260156
260665
|
attributionWarning = `
|
|
@@ -260177,7 +260686,7 @@ Mode: ${decision.usedLLM ? "LLM" : "heuristic"}`
|
|
|
260177
260686
|
valueCategory: formationResult?.evaluation.category,
|
|
260178
260687
|
createdByAgentId: currentAgentId,
|
|
260179
260688
|
visibility: requestedVisibility,
|
|
260180
|
-
visibilityReader:
|
|
260689
|
+
visibilityReader: reader2
|
|
260181
260690
|
});
|
|
260182
260691
|
let longTermNote = "";
|
|
260183
260692
|
if (longTerm) {
|
|
@@ -260192,8 +260701,8 @@ Mode: ${decision.usedLLM ? "LLM" : "heuristic"}`
|
|
|
260192
260701
|
applicability: longTerm.applicability,
|
|
260193
260702
|
reader: {
|
|
260194
260703
|
projectId: project.id,
|
|
260195
|
-
...
|
|
260196
|
-
...
|
|
260704
|
+
...reader2.agentId ? { agentId: reader2.agentId } : {},
|
|
260705
|
+
...reader2.isTeamMember ? { isTeamMember: true } : {}
|
|
260197
260706
|
}
|
|
260198
260707
|
});
|
|
260199
260708
|
const autoQualified = await maybeAutoQualifyLongTermMemory2({
|
|
@@ -260246,12 +260755,12 @@ Auto-enriched: ${enrichmentParts.join(", ")}` : "";
|
|
|
260246
260755
|
limit: 5,
|
|
260247
260756
|
projectId: project.id,
|
|
260248
260757
|
status: "active",
|
|
260249
|
-
reader
|
|
260758
|
+
reader: reader2
|
|
260250
260759
|
});
|
|
260251
260760
|
const similarEntries = searchResult.entries.map((e5) => e5);
|
|
260252
260761
|
if (similarEntries.length > 0) {
|
|
260253
260762
|
const similarIds = similarEntries.map((e5) => e5.id);
|
|
260254
|
-
const details = await compactDetail(similarIds, { reader });
|
|
260763
|
+
const details = await compactDetail(similarIds, { reader: reader2 });
|
|
260255
260764
|
const existingMemories = details.documents.map((d4, i4) => ({
|
|
260256
260765
|
id: d4.observationId,
|
|
260257
260766
|
title: d4.title,
|
|
@@ -260277,9 +260786,9 @@ Auto-enriched: ${enrichmentParts.join(", ")}` : "";
|
|
|
260277
260786
|
useLLM: isLLMEnabled(),
|
|
260278
260787
|
minValueScore: 0.3,
|
|
260279
260788
|
searchMemories: async (q4, limit2, pid, signal) => {
|
|
260280
|
-
const result = await compactSearch({ query: q4, limit: limit2, projectId: pid, status: "active", reader, signal });
|
|
260789
|
+
const result = await compactSearch({ query: q4, limit: limit2, projectId: pid, status: "active", reader: reader2, signal });
|
|
260281
260790
|
if (result.entries.length === 0) return [];
|
|
260282
|
-
const details = await compactDetail(result.entries.map((e5) => e5.id), { reader });
|
|
260791
|
+
const details = await compactDetail(result.entries.map((e5) => e5.id), { reader: reader2 });
|
|
260283
260792
|
return details.documents.map((d4, i4) => ({
|
|
260284
260793
|
id: Number(d4.id.replace("obs-", "")),
|
|
260285
260794
|
observationId: d4.observationId,
|
|
@@ -260293,7 +260802,7 @@ Auto-enriched: ${enrichmentParts.join(", ")}` : "";
|
|
|
260293
260802
|
},
|
|
260294
260803
|
getObservation: (id) => {
|
|
260295
260804
|
const o4 = getObservation(id);
|
|
260296
|
-
if (!o4 || o4.projectId !== project.id || !canReadObservation(o4,
|
|
260805
|
+
if (!o4 || o4.projectId !== project.id || !canReadObservation(o4, reader2)) return null;
|
|
260297
260806
|
return { id: o4.id, entityName: o4.entityName, type: o4.type, title: o4.title, narrative: o4.narrative, facts: o4.facts, topicKey: o4.topicKey };
|
|
260298
260807
|
},
|
|
260299
260808
|
getEntityNames: () => graphManager.getEntityNames()
|
|
@@ -261061,10 +261570,10 @@ _Search mode: ${getLastSearchMode2(project.id)}_`;
|
|
|
261061
261570
|
async ({ ids, status }) => {
|
|
261062
261571
|
const { resolveObservations: resolveObservations2, getObservation: getObservation2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
|
|
261063
261572
|
const safeIds = (Array.isArray(ids) ? ids : [ids]).map((id) => coerceNumber(id, 0)).filter((id) => id > 0);
|
|
261064
|
-
const
|
|
261573
|
+
const reader2 = getObservationReader();
|
|
261065
261574
|
const authorizedIds = safeIds.filter((id) => {
|
|
261066
261575
|
const observation = getObservation2(id, project.id);
|
|
261067
|
-
return observation ? canManageObservation(observation,
|
|
261576
|
+
return observation ? canManageObservation(observation, reader2) : false;
|
|
261068
261577
|
});
|
|
261069
261578
|
const result = await resolveObservations2(authorizedIds, status ?? "resolved");
|
|
261070
261579
|
const deniedCount = safeIds.length - authorizedIds.length;
|
|
@@ -261107,7 +261616,7 @@ _Search mode: ${getLastSearchMode2(project.id)}_`;
|
|
|
261107
261616
|
async ({ entityName, decision, alternatives, rationale, constraints, expectedOutcome, risks, concepts, filesModified, relatedCommits, relatedEntities }) => {
|
|
261108
261617
|
const unresolved = requireResolvedProject("store reasoning in the current project");
|
|
261109
261618
|
if (unresolved) return unresolved;
|
|
261110
|
-
const
|
|
261619
|
+
const reader2 = getObservationReader();
|
|
261111
261620
|
return withFreshIndex(async () => {
|
|
261112
261621
|
const narrativeParts = [rationale];
|
|
261113
261622
|
if (alternatives && alternatives.length > 0) {
|
|
@@ -261133,7 +261642,7 @@ _Search mode: ${getLastSearchMode2(project.id)}_`;
|
|
|
261133
261642
|
const attrCheck = await checkProjectAttribution(
|
|
261134
261643
|
entityName,
|
|
261135
261644
|
project.id,
|
|
261136
|
-
filterReadableObservations(getAllObservations(),
|
|
261645
|
+
filterReadableObservations(getAllObservations(), reader2)
|
|
261137
261646
|
);
|
|
261138
261647
|
if (attrCheck.suspicious) {
|
|
261139
261648
|
reasoningAttributionWarning = `
|
|
@@ -261282,11 +261791,11 @@ ${result.formatted}` }]
|
|
|
261282
261791
|
},
|
|
261283
261792
|
async ({ query, dryRun }) => {
|
|
261284
261793
|
const { getAllObservations: getAllObservations2, resolveObservations: resolveObservations2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
|
|
261285
|
-
const
|
|
261794
|
+
const reader2 = getObservationReader();
|
|
261286
261795
|
const allObs = await withFreshIndex(() => filterReadableObservations(
|
|
261287
261796
|
getAllObservations2().filter((o4) => (o4.status ?? "active") === "active" && o4.projectId === project.id),
|
|
261288
|
-
|
|
261289
|
-
).filter((observation) => canManageObservation(observation,
|
|
261797
|
+
reader2
|
|
261798
|
+
).filter((observation) => canManageObservation(observation, reader2)));
|
|
261290
261799
|
if (allObs.length < 2) {
|
|
261291
261800
|
return { content: [{ type: "text", text: "Not enough active memories to deduplicate." }] };
|
|
261292
261801
|
}
|
|
@@ -261300,7 +261809,7 @@ ${result.formatted}` }]
|
|
|
261300
261809
|
}
|
|
261301
261810
|
let candidates;
|
|
261302
261811
|
if (query) {
|
|
261303
|
-
const searchResult = await compactSearch({ query, limit: 20, projectId: project.id, status: "active", reader });
|
|
261812
|
+
const searchResult = await compactSearch({ query, limit: 20, projectId: project.id, status: "active", reader: reader2 });
|
|
261304
261813
|
const idSet = new Set(searchResult.entries.map((e5) => e5.id));
|
|
261305
261814
|
candidates = allObs.filter((o4) => idSet.has(o4.id));
|
|
261306
261815
|
} else {
|
|
@@ -261309,64 +261818,33 @@ ${result.formatted}` }]
|
|
|
261309
261818
|
if (candidates.length < 2) {
|
|
261310
261819
|
return { content: [{ type: "text", text: "Not enough memories in scope to deduplicate." }] };
|
|
261311
261820
|
}
|
|
261312
|
-
const
|
|
261313
|
-
|
|
261314
|
-
|
|
261315
|
-
|
|
261316
|
-
|
|
261317
|
-
|
|
261318
|
-
|
|
261319
|
-
const toResolve = [];
|
|
261320
|
-
for (const [entity, group] of byEntity) {
|
|
261321
|
-
if (group.length < 2) continue;
|
|
261322
|
-
for (let i4 = 0; i4 < group.length; i4++) {
|
|
261323
|
-
for (let j4 = i4 + 1; j4 < group.length; j4++) {
|
|
261324
|
-
const newer = group[j4];
|
|
261325
|
-
const older = group[i4];
|
|
261326
|
-
try {
|
|
261327
|
-
const decision = await deduplicateMemory(
|
|
261328
|
-
{ title: newer.title, narrative: newer.narrative, facts: newer.facts },
|
|
261329
|
-
[{ id: older.id, title: older.title, narrative: older.narrative, facts: older.facts.join("\n") }]
|
|
261330
|
-
);
|
|
261331
|
-
if (decision && decision.action === "UPDATE" && decision.targetId) {
|
|
261332
|
-
actions.push(`[UPDATED] #${older.id} "${older.title}" \u2192 superseded by #${newer.id} (${decision.reason})${decision.usedLLM ? " [LLM]" : " [heuristic]"}`);
|
|
261333
|
-
toResolve.push(older.id);
|
|
261334
|
-
} else if (decision && decision.action === "NONE") {
|
|
261335
|
-
actions.push(`[DELETE] #${newer.id} "${newer.title}" \u2192 redundant (${decision.reason})${decision.usedLLM ? " [LLM]" : " [heuristic]"}`);
|
|
261336
|
-
toResolve.push(newer.id);
|
|
261337
|
-
} else if (decision && decision.action === "DELETE") {
|
|
261338
|
-
actions.push(`[ERROR] #${decision.targetId ?? older.id} \u2192 outdated (${decision.reason})${decision.usedLLM ? " [LLM]" : " [heuristic]"}`);
|
|
261339
|
-
toResolve.push(decision.targetId ?? older.id);
|
|
261340
|
-
}
|
|
261341
|
-
} catch (dedupErr) {
|
|
261342
|
-
actions.push(`[WARN] comparison failed: ${dedupErr?.message ?? dedupErr}`);
|
|
261343
|
-
}
|
|
261344
|
-
}
|
|
261345
|
-
}
|
|
261346
|
-
}
|
|
261347
|
-
if (actions.length === 0) {
|
|
261348
|
-
return { content: [{ type: "text", text: `[OK] Scanned ${candidates.length} memories across ${byEntity.size} entities \u2014 no duplicates found.` }] };
|
|
261821
|
+
const manageableCandidates = candidates.filter((observation) => canManageObservation(observation, reader2));
|
|
261822
|
+
const plan = await planMemoryDeduplication(manageableCandidates);
|
|
261823
|
+
const actionLines = plan.actions.map(
|
|
261824
|
+
(item) => `Resolve #${item.resolveId} "${item.resolveTitle}"; keep #${item.keepId} "${item.keepTitle}" (${item.reason})${item.usedLLM ? " [LLM]" : " [heuristic]"}`
|
|
261825
|
+
);
|
|
261826
|
+
if (actionLines.length === 0) {
|
|
261827
|
+
return { content: [{ type: "text", text: `[OK] Scanned ${plan.scanned} memories across ${plan.entities} entities \u2014 no duplicates found.` }] };
|
|
261349
261828
|
}
|
|
261350
261829
|
if (dryRun) {
|
|
261351
261830
|
return {
|
|
261352
261831
|
content: [{
|
|
261353
261832
|
type: "text",
|
|
261354
|
-
text: `[SEARCH] DRY RUN \u2014 ${
|
|
261833
|
+
text: `[SEARCH] DRY RUN \u2014 ${actionLines.length} action(s) found:
|
|
261355
261834
|
|
|
261356
|
-
${
|
|
261835
|
+
${actionLines.join("\n")}
|
|
261357
261836
|
|
|
261358
261837
|
Run with dryRun=false to apply.`
|
|
261359
261838
|
}]
|
|
261360
261839
|
};
|
|
261361
261840
|
}
|
|
261362
|
-
const
|
|
261363
|
-
await resolveObservations2(unique3, "resolved");
|
|
261841
|
+
const result = await applyDeduplicationPlan(getObservationStore(), project.id, plan.resolveIds, reader2);
|
|
261364
261842
|
return {
|
|
261365
261843
|
content: [{
|
|
261366
261844
|
type: "text",
|
|
261367
|
-
text: `[CLEANUP] Deduplicated: resolved ${
|
|
261845
|
+
text: `[CLEANUP] Deduplicated: resolved ${result.resolved.length} memory(ies)
|
|
261368
261846
|
|
|
261369
|
-
${
|
|
261847
|
+
${actionLines.join("\n")}`
|
|
261370
261848
|
}]
|
|
261371
261849
|
};
|
|
261372
261850
|
}
|
|
@@ -261474,8 +261952,8 @@ ${actions.join("\n")}`
|
|
|
261474
261952
|
formatted.push(JSON.stringify({ durableMemory: details }, null, 2));
|
|
261475
261953
|
}
|
|
261476
261954
|
if (observationTypedRefs.length > 0 || safeRefs.length > 0 || safeIds.length > 0) {
|
|
261477
|
-
const
|
|
261478
|
-
const result = observationTypedRefs.length > 0 ? await compactDetail(observationTypedRefs, { reader }) : safeRefs.length > 0 ? await compactDetail(safeRefs, { reader }) : await compactDetail(safeIds.map((id) => ({ id, projectId: project.id })), { reader });
|
|
261955
|
+
const reader2 = getObservationReader(hasCrossProjectRef ? "global" : "project");
|
|
261956
|
+
const result = observationTypedRefs.length > 0 ? await compactDetail(observationTypedRefs, { reader: reader2 }) : safeRefs.length > 0 ? await compactDetail(safeRefs, { reader: reader2 }) : await compactDetail(safeIds.map((id) => ({ id, projectId: project.id })), { reader: reader2 });
|
|
261479
261957
|
formatted.push(
|
|
261480
261958
|
result.documents.length > 0 ? result.formatted : observationTypedRefs.length > 0 ? `No memories found for refs: ${observationTypedRefs.join(", ")}` : safeRefs.length > 0 ? `No memories found for refs: ${safeRefs.map((ref) => `${ref.projectId ?? "current"}#${ref.id}`).join(", ")}` : `No memories found for IDs: ${safeIds.join(", ")}`
|
|
261481
261959
|
);
|
|
@@ -261508,10 +261986,10 @@ ${actions.join("\n")}`
|
|
|
261508
261986
|
const { getDb: getDb2 } = await Promise.resolve().then(() => (init_orama_store(), orama_store_exports));
|
|
261509
261987
|
const { search: search3 } = await Promise.resolve().then(() => (init_esm(), esm_exports));
|
|
261510
261988
|
const { getAllObservations: getAllObservations2, resolveObservations: resolveObservations2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
|
|
261511
|
-
const
|
|
261989
|
+
const reader2 = getObservationReader();
|
|
261512
261990
|
const allObs = await withFreshIndex(() => filterReadableObservations(
|
|
261513
261991
|
getAllObservations2().filter((observation) => observation.projectId === project.id),
|
|
261514
|
-
|
|
261992
|
+
reader2
|
|
261515
261993
|
));
|
|
261516
261994
|
const accessMap = /* @__PURE__ */ new Map();
|
|
261517
261995
|
try {
|
|
@@ -261561,7 +262039,7 @@ ${actions.join("\n")}`
|
|
|
261561
262039
|
}
|
|
261562
262040
|
if (action === "archive") {
|
|
261563
262041
|
const managedIds = new Set(
|
|
261564
|
-
allObs.filter((observation) => canManageObservation(observation,
|
|
262042
|
+
allObs.filter((observation) => canManageObservation(observation, reader2)).map((observation) => observation.id)
|
|
261565
262043
|
);
|
|
261566
262044
|
const candidates2 = getArchiveCandidates2(docs).filter((document2) => managedIds.has(document2.observationId));
|
|
261567
262045
|
if (candidates2.length === 0) {
|
|
@@ -262275,10 +262753,10 @@ ${skill2.content}` }]
|
|
|
262275
262753
|
}
|
|
262276
262754
|
const { getAllObservations: getAllObservations2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
|
|
262277
262755
|
const allObs = await withFreshIndex(() => getAllObservations2());
|
|
262278
|
-
const
|
|
262756
|
+
const reader2 = getObservationReader();
|
|
262279
262757
|
const matched = filterReadableObservations(
|
|
262280
262758
|
allObs.filter((observation) => observation.projectId === project.id && observationIds.includes(observation.id)),
|
|
262281
|
-
|
|
262759
|
+
reader2
|
|
262282
262760
|
);
|
|
262283
262761
|
if (matched.length === 0) {
|
|
262284
262762
|
return { content: [{ type: "text", text: `No observations found for IDs: [${observationIds.join(", ")}]. Use \`memorix_search\` to find valid IDs.` }], isError: true };
|
|
@@ -263988,6 +264466,7 @@ var init_server4 = __esm({
|
|
|
263988
264466
|
init_tool_profile();
|
|
263989
264467
|
init_provider2();
|
|
263990
264468
|
init_memory_manager();
|
|
264469
|
+
init_deduplication();
|
|
263991
264470
|
init_formation();
|
|
263992
264471
|
init_formation_timeout();
|
|
263993
264472
|
init_timeout();
|
|
@@ -264545,15 +265024,15 @@ import { Readable as Readable2 } from "stream";
|
|
|
264545
265024
|
async function readWithoutBlocking(readPromise) {
|
|
264546
265025
|
return Promise.race([readPromise, Promise.resolve().then(() => Promise.resolve(void 0))]);
|
|
264547
265026
|
}
|
|
264548
|
-
function writeFromReadableStreamDefaultReader(
|
|
265027
|
+
function writeFromReadableStreamDefaultReader(reader2, writable, currentReadPromise) {
|
|
264549
265028
|
const cancel = (error40) => {
|
|
264550
|
-
|
|
265029
|
+
reader2.cancel(error40).catch(() => {
|
|
264551
265030
|
});
|
|
264552
265031
|
};
|
|
264553
265032
|
writable.on("close", cancel);
|
|
264554
265033
|
writable.on("error", cancel);
|
|
264555
|
-
(currentReadPromise ??
|
|
264556
|
-
return
|
|
265034
|
+
(currentReadPromise ?? reader2.read()).then(flow, handleStreamError);
|
|
265035
|
+
return reader2.closed.finally(() => {
|
|
264557
265036
|
writable.off("close", cancel);
|
|
264558
265037
|
writable.off("error", cancel);
|
|
264559
265038
|
});
|
|
@@ -264561,13 +265040,13 @@ function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromi
|
|
|
264561
265040
|
if (error40) writable.destroy(error40);
|
|
264562
265041
|
}
|
|
264563
265042
|
function onDrain() {
|
|
264564
|
-
|
|
265043
|
+
reader2.read().then(flow, handleStreamError);
|
|
264565
265044
|
}
|
|
264566
265045
|
function flow({ done, value }) {
|
|
264567
265046
|
try {
|
|
264568
265047
|
if (done) writable.end();
|
|
264569
265048
|
else if (!writable.write(value)) writable.once("drain", onDrain);
|
|
264570
|
-
else return
|
|
265049
|
+
else return reader2.read().then(flow, handleStreamError);
|
|
264571
265050
|
} catch (e5) {
|
|
264572
265051
|
handleStreamError(e5);
|
|
264573
265052
|
}
|
|
@@ -264700,18 +265179,18 @@ var init_dist8 = __esm({
|
|
|
264700
265179
|
controller.close();
|
|
264701
265180
|
} });
|
|
264702
265181
|
else if (incoming[wrapBodyStream]) {
|
|
264703
|
-
let
|
|
265182
|
+
let reader2;
|
|
264704
265183
|
init2.body = new ReadableStream({ async pull(controller) {
|
|
264705
265184
|
try {
|
|
264706
|
-
if (!
|
|
265185
|
+
if (!reader2) {
|
|
264707
265186
|
const buffered = readBodyBufferedBeforeDisconnect(incoming);
|
|
264708
265187
|
if (buffered !== void 0) {
|
|
264709
265188
|
enqueueBufferedBody(controller, buffered);
|
|
264710
265189
|
return;
|
|
264711
265190
|
}
|
|
264712
265191
|
}
|
|
264713
|
-
|
|
264714
|
-
const { done, value } = await
|
|
265192
|
+
reader2 ||= Readable2.toWeb(incoming).getReader();
|
|
265193
|
+
const { done, value } = await reader2.read();
|
|
264715
265194
|
if (done) controller.close();
|
|
264716
265195
|
else controller.enqueue(value);
|
|
264717
265196
|
} catch (error40) {
|
|
@@ -265336,14 +265815,14 @@ var init_dist8 = __esm({
|
|
|
265336
265815
|
if (cacheKey in res) return responseViaCache(res, outgoing);
|
|
265337
265816
|
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers, res.body === null ? void 0 : defaultContentType);
|
|
265338
265817
|
if (res.body) {
|
|
265339
|
-
const
|
|
265818
|
+
const reader2 = res.body.getReader();
|
|
265340
265819
|
const values = [];
|
|
265341
265820
|
let done = false;
|
|
265342
265821
|
let currentReadPromise = void 0;
|
|
265343
265822
|
if (resHeaderRecord["transfer-encoding"] !== "chunked") {
|
|
265344
265823
|
let maxReadCount = 2;
|
|
265345
265824
|
for (let i4 = 0; i4 < maxReadCount; i4++) {
|
|
265346
|
-
currentReadPromise ||=
|
|
265825
|
+
currentReadPromise ||= reader2.read();
|
|
265347
265826
|
const chunk = await readWithoutBlocking(currentReadPromise).catch((e5) => {
|
|
265348
265827
|
console.error(e5);
|
|
265349
265828
|
done = true;
|
|
@@ -265372,7 +265851,7 @@ var init_dist8 = __esm({
|
|
|
265372
265851
|
if (done) outgoing.end();
|
|
265373
265852
|
else {
|
|
265374
265853
|
if (values.length === 0) flushHeaders(outgoing);
|
|
265375
|
-
await writeFromReadableStreamDefaultReader(
|
|
265854
|
+
await writeFromReadableStreamDefaultReader(reader2, outgoing, currentReadPromise);
|
|
265376
265855
|
}
|
|
265377
265856
|
} else if (resHeaderRecord[X_ALREADY_SENT]) {
|
|
265378
265857
|
} else {
|
|
@@ -271500,7 +271979,7 @@ var init_ingest_image = __esm({
|
|
|
271500
271979
|
emitError('path is required for "memorix ingest image"', asJson);
|
|
271501
271980
|
return;
|
|
271502
271981
|
}
|
|
271503
|
-
const { project, dataDir, reader, identity } = await getCliProjectContext();
|
|
271982
|
+
const { project, dataDir, reader: reader2, identity } = await getCliProjectContext();
|
|
271504
271983
|
const resolvedPath = path43.resolve(project.rootPath, imagePath);
|
|
271505
271984
|
const filename = path43.basename(resolvedPath);
|
|
271506
271985
|
const imported = await importMediaFile({
|
|
@@ -271549,7 +272028,7 @@ var init_ingest_image = __esm({
|
|
|
271549
272028
|
narrative: analysis.description,
|
|
271550
272029
|
concepts: analysis.tags,
|
|
271551
272030
|
facts: analysis.entities,
|
|
271552
|
-
...resolveCliWriteScope({ reader, identity }, args.visibility)
|
|
272031
|
+
...resolveCliWriteScope({ reader: reader2, identity }, args.visibility)
|
|
271553
272032
|
});
|
|
271554
272033
|
emitResult(
|
|
271555
272034
|
{ project, asset: imported.asset, deduplicated: imported.deduplicated, analysis, analysisWarning, observation },
|
|
@@ -271926,7 +272405,7 @@ var init_media = __esm({
|
|
|
271926
272405
|
}
|
|
271927
272406
|
const prompt2 = getValue(args.prompt, positional);
|
|
271928
272407
|
if (!prompt2) throw new Error(`prompt is required for "memorix media generate ${target}"`);
|
|
271929
|
-
const { project, dataDir, reader, identity } = await getCliProjectContext();
|
|
272408
|
+
const { project, dataDir, reader: reader2, identity } = await getCliProjectContext();
|
|
271930
272409
|
loadDotenv(project.rootPath);
|
|
271931
272410
|
if (target === "video") {
|
|
271932
272411
|
const queued = queueMiniMaxVideoGeneration({
|
|
@@ -271979,7 +272458,7 @@ var init_media = __esm({
|
|
|
271979
272458
|
title: `MiniMax image: ${asset.sourceLabel ?? asset.id}`,
|
|
271980
272459
|
narrative: `Generated with ${generated.provider}/${generated.model}. Prompt: ${prompt2}`,
|
|
271981
272460
|
concepts: ["generated-image", "minimax", generated.model],
|
|
271982
|
-
...resolveCliWriteScope({ reader, identity }, args.visibility)
|
|
272461
|
+
...resolveCliWriteScope({ reader: reader2, identity }, args.visibility)
|
|
271983
272462
|
}))) : [];
|
|
271984
272463
|
emitResult(
|
|
271985
272464
|
{ project, ...generated, observations: observations2 },
|
|
@@ -272040,7 +272519,7 @@ var init_media = __esm({
|
|
|
272040
272519
|
case "derive-pdf": {
|
|
272041
272520
|
const assetId = getValue(args.asset, positional);
|
|
272042
272521
|
if (!assetId) throw new Error('asset is required for "memorix media derive-pdf"');
|
|
272043
|
-
const { project, dataDir, reader, identity } = await getCliProjectContext();
|
|
272522
|
+
const { project, dataDir, reader: reader2, identity } = await getCliProjectContext();
|
|
272044
272523
|
const maxChars = parseOptionalInteger(args.maxChars ?? args["max-chars"], "maxChars", 1, 1e6);
|
|
272045
272524
|
const requestedChunkChars = parseOptionalInteger(args.chunkChars ?? args["chunk-chars"], "chunkChars", 1, 12e4);
|
|
272046
272525
|
const derived = await derivePdfText({
|
|
@@ -272063,7 +272542,7 @@ var init_media = __esm({
|
|
|
272063
272542
|
narrative: chunk.text,
|
|
272064
272543
|
facts: [`PDF pages: ${chunk.pageStart}-${chunk.pageEnd}`, "Derived with explicit PDF text extraction."],
|
|
272065
272544
|
concepts: ["pdf", "pdf-text", "media-derivation"],
|
|
272066
|
-
...resolveCliWriteScope({ reader, identity }, args.visibility)
|
|
272545
|
+
...resolveCliWriteScope({ reader: reader2, identity }, args.visibility)
|
|
272067
272546
|
}));
|
|
272068
272547
|
}
|
|
272069
272548
|
}
|
|
@@ -272142,7 +272621,7 @@ ${asset.mimeType}, ${asset.byteSize} bytes, ${links.length} link(s)`,
|
|
|
272142
272621
|
case "attach": {
|
|
272143
272622
|
const assetId = getValue(args.asset, positional);
|
|
272144
272623
|
if (!assetId) throw new Error('asset is required for "memorix media attach"');
|
|
272145
|
-
const { project, dataDir, reader, identity } = await getCliProjectContext();
|
|
272624
|
+
const { project, dataDir, reader: reader2, identity } = await getCliProjectContext();
|
|
272146
272625
|
const store2 = new MediaStore(dataDir);
|
|
272147
272626
|
const asset = store2.getAsset(project.id, assetId);
|
|
272148
272627
|
if (!asset) throw new Error(`Media asset not found: ${assetId}`);
|
|
@@ -272156,7 +272635,7 @@ ${asset.mimeType}, ${asset.byteSize} bytes, ${links.length} link(s)`,
|
|
|
272156
272635
|
narrative: args.text?.trim() || description,
|
|
272157
272636
|
entityName: args.entity?.trim(),
|
|
272158
272637
|
concepts,
|
|
272159
|
-
...resolveCliWriteScope({ reader, identity }, args.visibility)
|
|
272638
|
+
...resolveCliWriteScope({ reader: reader2, identity }, args.visibility)
|
|
272160
272639
|
});
|
|
272161
272640
|
emitResult(
|
|
272162
272641
|
{ project, asset, observation },
|
|
@@ -272426,7 +272905,7 @@ import * as fs26 from "fs";
|
|
|
272426
272905
|
import path44 from "path";
|
|
272427
272906
|
import { fileURLToPath as fileURLToPath8 } from "url";
|
|
272428
272907
|
import { spawn as spawn6, execFileSync as execFileSync4 } from "child_process";
|
|
272429
|
-
import { randomBytes } from "crypto";
|
|
272908
|
+
import { randomBytes as randomBytes2 } from "crypto";
|
|
272430
272909
|
import os7 from "os";
|
|
272431
272910
|
function resolveBackgroundCwd(cwd, homeDir = os7.homedir()) {
|
|
272432
272911
|
if (!isHomeDirectory(cwd, homeDir)) return cwd;
|
|
@@ -272731,7 +273210,7 @@ async function doStart(port) {
|
|
|
272731
273210
|
process.exitCode = 1;
|
|
272732
273211
|
return;
|
|
272733
273212
|
}
|
|
272734
|
-
const instanceToken =
|
|
273213
|
+
const instanceToken = randomBytes2(8).toString("hex");
|
|
272735
273214
|
saveState({
|
|
272736
273215
|
pid,
|
|
272737
273216
|
port,
|
|
@@ -274661,41 +275140,8 @@ __export(cleanup_exports, {
|
|
|
274661
275140
|
applyCleanupMutations: () => applyCleanupMutations,
|
|
274662
275141
|
default: () => cleanup_default
|
|
274663
275142
|
});
|
|
274664
|
-
|
|
274665
|
-
|
|
274666
|
-
}
|
|
274667
|
-
function isNoisePollution(obs) {
|
|
274668
|
-
const text2 = [obs.title, obs.narrative, obs.entityName, ...obs.facts ?? [], ...obs.concepts ?? []].filter(Boolean).join("\n");
|
|
274669
|
-
for (const p3 of SYSTEM_SELF_PATTERNS2) {
|
|
274670
|
-
if (p3.test(text2)) return { isNoise: true, reason: "system-self" };
|
|
274671
|
-
}
|
|
274672
|
-
for (const p3 of NOISE_PATTERNS3) {
|
|
274673
|
-
if (p3.test(text2)) return { isNoise: true, reason: "demo/test/noise" };
|
|
274674
|
-
}
|
|
274675
|
-
return { isNoise: false, reason: "" };
|
|
274676
|
-
}
|
|
274677
|
-
function requireObservationIds(observations2, action) {
|
|
274678
|
-
const ids = observations2.map((observation) => observation.id);
|
|
274679
|
-
if (ids.some((id) => typeof id !== "number")) {
|
|
274680
|
-
throw new Error(`Cannot ${action}: an observation has no persisted ID.`);
|
|
274681
|
-
}
|
|
274682
|
-
return ids;
|
|
274683
|
-
}
|
|
274684
|
-
async function applyCleanupMutations(store2, toArchive, toRemove) {
|
|
274685
|
-
const archiveIds = requireObservationIds(toArchive, "archive");
|
|
274686
|
-
const removeIds = requireObservationIds(toRemove, "delete");
|
|
274687
|
-
const removals = new Set(removeIds);
|
|
274688
|
-
if (archiveIds.some((id) => removals.has(id))) {
|
|
274689
|
-
throw new Error("Cleanup cannot archive and delete the same observation.");
|
|
274690
|
-
}
|
|
274691
|
-
await store2.atomic(async (tx) => {
|
|
274692
|
-
await Promise.all(archiveIds.map((id) => tx.setStatus(id, "archived")));
|
|
274693
|
-
await Promise.all(removeIds.map((id) => tx.remove(id)));
|
|
274694
|
-
});
|
|
274695
|
-
return { archived: archiveIds.length, removed: removeIds.length };
|
|
274696
|
-
}
|
|
274697
|
-
var LOW_QUALITY_PATTERNS, NOISE_PATTERNS3, SYSTEM_SELF_PATTERNS2, cleanup_default;
|
|
274698
|
-
var init_cleanup = __esm({
|
|
275143
|
+
var cleanup_default;
|
|
275144
|
+
var init_cleanup2 = __esm({
|
|
274699
275145
|
"src/cli/commands/cleanup.ts"() {
|
|
274700
275146
|
"use strict";
|
|
274701
275147
|
init_esm_shims();
|
|
@@ -274704,46 +275150,8 @@ var init_cleanup = __esm({
|
|
|
274704
275150
|
init_persistence();
|
|
274705
275151
|
init_obs_store();
|
|
274706
275152
|
init_visibility();
|
|
274707
|
-
|
|
274708
|
-
|
|
274709
|
-
/^Updated \S+\.\w+$/i,
|
|
274710
|
-
/^Created \S+\.\w+$/i,
|
|
274711
|
-
/^Deleted \S+\.\w+$/i,
|
|
274712
|
-
/^Modified \S+\.\w+$/i,
|
|
274713
|
-
/^Ran command:/i,
|
|
274714
|
-
/^Read file:/i
|
|
274715
|
-
];
|
|
274716
|
-
NOISE_PATTERNS3 = [
|
|
274717
|
-
/\[测试\]/i,
|
|
274718
|
-
/\[test\]/i,
|
|
274719
|
-
/验证/i,
|
|
274720
|
-
/兼容/i,
|
|
274721
|
-
/\bcompat(?:ibility)?\b/i,
|
|
274722
|
-
/\bdemo\b/i,
|
|
274723
|
-
/展示/i,
|
|
274724
|
-
/全能力/i,
|
|
274725
|
-
/handoff/i,
|
|
274726
|
-
/交接/i,
|
|
274727
|
-
/for_memmcp_test/i,
|
|
274728
|
-
/\bbenchmark\b/i,
|
|
274729
|
-
/\bsandbox\b/i,
|
|
274730
|
-
/\bplayground\b/i
|
|
274731
|
-
];
|
|
274732
|
-
SYSTEM_SELF_PATTERNS2 = [
|
|
274733
|
-
/memorix.demo/i,
|
|
274734
|
-
/memorix.*全能力/i,
|
|
274735
|
-
/memorix.*工具.*能力/i,
|
|
274736
|
-
/memorix.*runtime.*mode/i,
|
|
274737
|
-
/memorix.*运行模式/i,
|
|
274738
|
-
/memorix.*control.plane/i,
|
|
274739
|
-
/session.*inject(?:ion)?/i,
|
|
274740
|
-
/注入.*逻辑/i,
|
|
274741
|
-
/\b22\s*(?:个|tools?).*(?:工具|能力|capabilit)/i,
|
|
274742
|
-
/memorix.*(?:v\d|版本|version)/i,
|
|
274743
|
-
/memorix.*(?:兼容|compat)/i,
|
|
274744
|
-
/memorix.*(?:测试|test)/i,
|
|
274745
|
-
/memmcp/i
|
|
274746
|
-
];
|
|
275153
|
+
init_cleanup();
|
|
275154
|
+
init_cleanup();
|
|
274747
275155
|
cleanup_default = defineCommand({
|
|
274748
275156
|
meta: {
|
|
274749
275157
|
name: "cleanup",
|
|
@@ -274800,33 +275208,11 @@ Project: ${projectName} (${projectId})
|
|
|
274800
275208
|
console.log("[OK] No observations found - nothing to clean up.");
|
|
274801
275209
|
return;
|
|
274802
275210
|
}
|
|
274803
|
-
const
|
|
274804
|
-
const
|
|
274805
|
-
const seen = /* @__PURE__ */ new Set();
|
|
274806
|
-
const duplicates = [];
|
|
274807
|
-
const unique3 = [];
|
|
274808
|
-
for (const obs of highQuality) {
|
|
274809
|
-
const key = `${obs.type}|${obs.title}|${obs.entityName}`;
|
|
274810
|
-
if (seen.has(key)) {
|
|
274811
|
-
duplicates.push(obs);
|
|
274812
|
-
} else {
|
|
274813
|
-
seen.add(key);
|
|
274814
|
-
unique3.push(obs);
|
|
274815
|
-
}
|
|
274816
|
-
}
|
|
274817
|
-
const noiseHits = [];
|
|
274818
|
-
if (args.noise) {
|
|
274819
|
-
for (const obs of projectObs) {
|
|
274820
|
-
if (lowQuality.includes(obs) || duplicates.includes(obs)) continue;
|
|
274821
|
-
const { isNoise, reason } = isNoisePollution(obs);
|
|
274822
|
-
if (isNoise) noiseHits.push({ obs, reason });
|
|
274823
|
-
}
|
|
274824
|
-
}
|
|
274825
|
-
const toRemove = [...lowQuality, ...duplicates];
|
|
274826
|
-
const toArchive = noiseHits.map((h5) => h5.obs);
|
|
275211
|
+
const analysis = analyzeCleanupObservations(projectObs, { includeNoise: args.noise });
|
|
275212
|
+
const { lowQuality, duplicates, noise: noiseHits, toRemove, toArchive } = analysis;
|
|
274827
275213
|
console.log(`Analysis (active observations for ${projectId}):`);
|
|
274828
|
-
console.log(` Total active: ${
|
|
274829
|
-
console.log(` High quality: ${
|
|
275214
|
+
console.log(` Total active: ${analysis.totalActive}`);
|
|
275215
|
+
console.log(` High quality: ${analysis.highQuality}`);
|
|
274830
275216
|
console.log(` Low quality: ${lowQuality.length}`);
|
|
274831
275217
|
console.log(` Duplicates: ${duplicates.length}`);
|
|
274832
275218
|
if (args.noise) {
|
|
@@ -274844,7 +275230,7 @@ Project: ${projectName} (${projectId})
|
|
|
274844
275230
|
if (toRemove.length > 0) {
|
|
274845
275231
|
console.log("Items to DELETE:");
|
|
274846
275232
|
toRemove.slice(0, 10).forEach((o4) => {
|
|
274847
|
-
const tag =
|
|
275233
|
+
const tag = isLowQualityObservation(o4.title ?? "") ? "(low-quality)" : "(duplicate)";
|
|
274848
275234
|
console.log(` ${tag} #${o4.id ?? "?"} "${o4.title}" [${o4.type}]`);
|
|
274849
275235
|
});
|
|
274850
275236
|
if (toRemove.length > 10) {
|
|
@@ -274854,8 +275240,8 @@ Project: ${projectName} (${projectId})
|
|
|
274854
275240
|
}
|
|
274855
275241
|
if (toArchive.length > 0) {
|
|
274856
275242
|
console.log("Items to ARCHIVE (noise pollution):");
|
|
274857
|
-
noiseHits.slice(0, 15).forEach(({
|
|
274858
|
-
console.log(` (${reason}) #${
|
|
275243
|
+
noiseHits.slice(0, 15).forEach(({ observation, reason }) => {
|
|
275244
|
+
console.log(` (${reason}) #${observation.id ?? "?"} "${observation.title}" [${observation.type}] entity=${observation.entityName}`);
|
|
274859
275245
|
});
|
|
274860
275246
|
if (toArchive.length > 15) {
|
|
274861
275247
|
console.log(` ... and ${toArchive.length - 15} more`);
|
|
@@ -280585,11 +280971,11 @@ async function getSessionState(projectId) {
|
|
|
280585
280971
|
async function bindSession() {
|
|
280586
280972
|
try {
|
|
280587
280973
|
const { getTuiOperatorContext: getTuiOperatorContext2 } = await Promise.resolve().then(() => (init_operator_context(), operator_context_exports));
|
|
280588
|
-
const { project: proj, reader } = await getTuiOperatorContext2();
|
|
280974
|
+
const { project: proj, reader: reader2 } = await getTuiOperatorContext2();
|
|
280589
280975
|
const { startSession: startSession2 } = await Promise.resolve().then(() => (init_session(), session_exports));
|
|
280590
280976
|
const { session, previousContext } = await startSession2(proj.rootPath, proj.id, {
|
|
280591
280977
|
agent: "memorix-tui",
|
|
280592
|
-
reader
|
|
280978
|
+
reader: reader2
|
|
280593
280979
|
});
|
|
280594
280980
|
return {
|
|
280595
280981
|
status: "bound",
|
|
@@ -280681,7 +281067,7 @@ async function getHealthInfo(projectId) {
|
|
|
280681
281067
|
};
|
|
280682
281068
|
try {
|
|
280683
281069
|
const { initObservationStore: initStore, getObservationStore: getStore } = await Promise.resolve().then(() => (init_obs_store(), obs_store_exports));
|
|
280684
|
-
const { project: proj, dataDir, reader } = await getTuiOperatorContext();
|
|
281070
|
+
const { project: proj, dataDir, reader: reader2 } = await getTuiOperatorContext();
|
|
280685
281071
|
try {
|
|
280686
281072
|
const { loadDotenv: loadDotenv2 } = await Promise.resolve().then(() => (init_dotenv_loader(), dotenv_loader_exports));
|
|
280687
281073
|
loadDotenv2(proj.rootPath);
|
|
@@ -280692,7 +281078,7 @@ async function getHealthInfo(projectId) {
|
|
|
280692
281078
|
await initStore(dataDir);
|
|
280693
281079
|
const allObs = await getStore().loadAll();
|
|
280694
281080
|
const { filterReadableObservations: filterReadableObservations2 } = await Promise.resolve().then(() => (init_visibility(), visibility_exports));
|
|
280695
|
-
const obs = filterReadableObservations2(allObs,
|
|
281081
|
+
const obs = filterReadableObservations2(allObs, reader2);
|
|
280696
281082
|
const active = obs.filter((o4) => (o4.status ?? "active") === "active");
|
|
280697
281083
|
defaults2.totalMemories = obs.length;
|
|
280698
281084
|
defaults2.activeMemories = active.length;
|
|
@@ -280758,13 +281144,13 @@ async function getHealthInfo(projectId) {
|
|
|
280758
281144
|
async function getRecentMemories(limit2 = 8, projectId) {
|
|
280759
281145
|
try {
|
|
280760
281146
|
const { initObservationStore: initStore, getObservationStore: getStore } = await Promise.resolve().then(() => (init_obs_store(), obs_store_exports));
|
|
280761
|
-
const { project: proj, dataDir, reader } = await getTuiOperatorContext();
|
|
281147
|
+
const { project: proj, dataDir, reader: reader2 } = await getTuiOperatorContext();
|
|
280762
281148
|
const effectiveProjectId = projectId || proj.id;
|
|
280763
281149
|
if (effectiveProjectId !== proj.id) return [];
|
|
280764
281150
|
await initStore(dataDir);
|
|
280765
281151
|
const allObs = await getStore().loadAll();
|
|
280766
281152
|
const { filterReadableObservations: filterReadableObservations2 } = await Promise.resolve().then(() => (init_visibility(), visibility_exports));
|
|
280767
|
-
const projectObs = filterReadableObservations2(allObs,
|
|
281153
|
+
const projectObs = filterReadableObservations2(allObs, reader2);
|
|
280768
281154
|
const active = projectObs.filter((o4) => (o4.status ?? "active") === "active");
|
|
280769
281155
|
const filtered = active.filter((o4) => !/^(Ran:|Command:|Executed:)\s/i.test(o4.title || ""));
|
|
280770
281156
|
return filtered.slice(-limit2).reverse().map((o4) => ({
|
|
@@ -280783,10 +281169,10 @@ async function searchMemories(query, limit2 = 10) {
|
|
|
280783
281169
|
try {
|
|
280784
281170
|
const { searchObservations: searchObservations2 } = await Promise.resolve().then(() => (init_orama_store(), orama_store_exports));
|
|
280785
281171
|
const { initObservations: initObservations2, prepareSearchIndex: prepareSearchIndex2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
|
|
280786
|
-
const { project: proj, dataDir, reader } = await getTuiOperatorContext();
|
|
281172
|
+
const { project: proj, dataDir, reader: reader2 } = await getTuiOperatorContext();
|
|
280787
281173
|
await initObservations2(dataDir);
|
|
280788
281174
|
await prepareSearchIndex2();
|
|
280789
|
-
const results = await searchObservations2({ query, limit: limit2, projectId: proj.id, reader });
|
|
281175
|
+
const results = await searchObservations2({ query, limit: limit2, projectId: proj.id, reader: reader2 });
|
|
280790
281176
|
const typeIcons = {
|
|
280791
281177
|
gotcha: "!",
|
|
280792
281178
|
decision: "D",
|
|
@@ -280813,7 +281199,7 @@ async function storeQuickMemory(text2) {
|
|
|
280813
281199
|
try {
|
|
280814
281200
|
const { initObservations: initObservations2, storeObservation: storeObservation2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
|
|
280815
281201
|
const { initObservationStore: initObservationStore2 } = await Promise.resolve().then(() => (init_obs_store(), obs_store_exports));
|
|
280816
|
-
const { project: proj, dataDir, reader, identity } = await getTuiOperatorContext();
|
|
281202
|
+
const { project: proj, dataDir, reader: reader2, identity } = await getTuiOperatorContext();
|
|
280817
281203
|
await initObservationStore2(dataDir);
|
|
280818
281204
|
await initObservations2(dataDir);
|
|
280819
281205
|
const result = await storeObservation2({
|
|
@@ -280824,7 +281210,7 @@ async function storeQuickMemory(text2) {
|
|
|
280824
281210
|
facts: [],
|
|
280825
281211
|
projectId: proj.id,
|
|
280826
281212
|
sourceDetail: "explicit",
|
|
280827
|
-
visibilityReader:
|
|
281213
|
+
visibilityReader: reader2,
|
|
280828
281214
|
...identity ? { createdByAgentId: identity.agentId } : {}
|
|
280829
281215
|
});
|
|
280830
281216
|
return { id: result.observation.id, title: text2.slice(0, 100) };
|
|
@@ -280968,13 +281354,13 @@ async function getKnowledgeGraph(projectId) {
|
|
|
280968
281354
|
const { filterReadableObservations: filterReadableObservations2 } = await Promise.resolve().then(() => (init_visibility(), visibility_exports));
|
|
280969
281355
|
const { initMiniSkillStore: initMiniSkillStore2, getMiniSkillStore: getMiniSkillStore2 } = await Promise.resolve().then(() => (init_mini_skill_store(), mini_skill_store_exports));
|
|
280970
281356
|
const { generateKnowledgeGraph: generateKnowledgeGraph2 } = await Promise.resolve().then(() => (init_knowledge_graph(), knowledge_graph_exports));
|
|
280971
|
-
const { project: proj, dataDir, reader } = await getTuiOperatorContext();
|
|
281357
|
+
const { project: proj, dataDir, reader: reader2 } = await getTuiOperatorContext();
|
|
280972
281358
|
const effectiveProjectId = projectId || proj.id;
|
|
280973
281359
|
if (effectiveProjectId !== proj.id) return null;
|
|
280974
281360
|
await initObservationStore2(dataDir);
|
|
280975
281361
|
await initObservations2(dataDir);
|
|
280976
281362
|
await initMiniSkillStore2(dataDir);
|
|
280977
|
-
const observations2 = filterReadableObservations2(getAllObservations2(),
|
|
281363
|
+
const observations2 = filterReadableObservations2(getAllObservations2(), reader2);
|
|
280978
281364
|
const skills = await getMiniSkillStore2().loadByProject(effectiveProjectId);
|
|
280979
281365
|
return generateKnowledgeGraph2({
|
|
280980
281366
|
projectId: effectiveProjectId,
|
|
@@ -280992,13 +281378,13 @@ async function getKnowledgeBase(projectId) {
|
|
|
280992
281378
|
const { filterReadableObservations: filterReadableObservations2 } = await Promise.resolve().then(() => (init_visibility(), visibility_exports));
|
|
280993
281379
|
const { initMiniSkillStore: initMiniSkillStore2, getMiniSkillStore: getMiniSkillStore2 } = await Promise.resolve().then(() => (init_mini_skill_store(), mini_skill_store_exports));
|
|
280994
281380
|
const { generateKnowledgeBase: generateKnowledgeBase2 } = await Promise.resolve().then(() => (init_generator(), generator_exports));
|
|
280995
|
-
const { project: proj, dataDir, reader } = await getTuiOperatorContext();
|
|
281381
|
+
const { project: proj, dataDir, reader: reader2 } = await getTuiOperatorContext();
|
|
280996
281382
|
const effectiveProjectId = projectId || proj.id;
|
|
280997
281383
|
if (effectiveProjectId !== proj.id) return null;
|
|
280998
281384
|
await initObservationStore2(dataDir);
|
|
280999
281385
|
await initObservations2(dataDir);
|
|
281000
281386
|
await initMiniSkillStore2(dataDir);
|
|
281001
|
-
const observations2 = filterReadableObservations2(getAllObservations2(),
|
|
281387
|
+
const observations2 = filterReadableObservations2(getAllObservations2(), reader2);
|
|
281002
281388
|
const skills = await getMiniSkillStore2().loadByProject(effectiveProjectId);
|
|
281003
281389
|
return generateKnowledgeBase2({
|
|
281004
281390
|
projectId: effectiveProjectId,
|
|
@@ -281058,7 +281444,7 @@ function MemoryView({ projectId, focusRefId, selectedIdx, onNavigateKnowledge, i
|
|
|
281058
281444
|
const { filterReadableObservations: filterReadableObservations2 } = await Promise.resolve().then(() => (init_visibility(), visibility_exports));
|
|
281059
281445
|
const { initObservationStore: initObservationStore2 } = await Promise.resolve().then(() => (init_obs_store(), obs_store_exports));
|
|
281060
281446
|
const { getTuiOperatorContext: getTuiOperatorContext2 } = await Promise.resolve().then(() => (init_operator_context(), operator_context_exports));
|
|
281061
|
-
const { project: proj, dataDir, reader } = await getTuiOperatorContext2();
|
|
281447
|
+
const { project: proj, dataDir, reader: reader2 } = await getTuiOperatorContext2();
|
|
281062
281448
|
const effectiveProjectId = projectId || proj.id;
|
|
281063
281449
|
if (effectiveProjectId !== proj.id) return;
|
|
281064
281450
|
await initObservationStore2(dataDir);
|
|
@@ -281066,7 +281452,7 @@ function MemoryView({ projectId, focusRefId, selectedIdx, onNavigateKnowledge, i
|
|
|
281066
281452
|
const obsId = parseInt(idMatch[1], 10);
|
|
281067
281453
|
const obs = filterReadableObservations2(
|
|
281068
281454
|
getAllObservations2().filter((observation) => observation.projectId === effectiveProjectId),
|
|
281069
|
-
|
|
281455
|
+
reader2
|
|
281070
281456
|
).find((observation) => observation.id === obsId);
|
|
281071
281457
|
if (obs) {
|
|
281072
281458
|
setDetailItem({
|
|
@@ -283906,7 +284292,7 @@ var main2 = defineCommand({
|
|
|
283906
284292
|
doctor: () => Promise.resolve().then(() => (init_doctor(), doctor_exports)).then((m6) => m6.default),
|
|
283907
284293
|
repair: () => Promise.resolve().then(() => (init_repair3(), repair_exports)).then((m6) => m6.default),
|
|
283908
284294
|
dashboard: () => Promise.resolve().then(() => (init_dashboard(), dashboard_exports)).then((m6) => m6.default),
|
|
283909
|
-
cleanup: () => Promise.resolve().then(() => (
|
|
284295
|
+
cleanup: () => Promise.resolve().then(() => (init_cleanup2(), cleanup_exports)).then((m6) => m6.default),
|
|
283910
284296
|
purge: () => Promise.resolve().then(() => (init_purge(), purge_exports)).then((m6) => m6.default),
|
|
283911
284297
|
uninstall: () => Promise.resolve().then(() => (init_uninstall(), uninstall_exports)).then((m6) => m6.default),
|
|
283912
284298
|
orchestrate: () => Promise.resolve().then(() => (init_orchestrate(), orchestrate_exports)).then((m6) => m6.default),
|