@slashml/memory 1.0.12 → 1.0.13
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/bin/cli.js +157 -15
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -10,7 +10,8 @@ const readline = require("readline");
|
|
|
10
10
|
|
|
11
11
|
const DEFAULT_BASE_URL = "https://api.slashml.ai";
|
|
12
12
|
const DEFAULT_CONSOLE_URL = "https://app.slashml.ai";
|
|
13
|
-
const PACKAGE_VERSION = "1.0.
|
|
13
|
+
const PACKAGE_VERSION = "1.0.13";
|
|
14
|
+
const MAX_STOP_BLOCKS_PER_PROMPT = 3;
|
|
14
15
|
|
|
15
16
|
function printHelp() {
|
|
16
17
|
console.log(`@slashml/memory v${PACKAGE_VERSION} -- Official CLI & MCP Stdio Server for / ml (SlashML · https://slashml.ai)
|
|
@@ -1208,6 +1209,22 @@ async function runStatusCommand(opts) {
|
|
|
1208
1209
|
noiseFilteredPct = Number((Math.max(tokRatio, evRatio) * 100.0).toFixed(1));
|
|
1209
1210
|
}
|
|
1210
1211
|
|
|
1212
|
+
const objectionsRepeatSuppressed = Number(
|
|
1213
|
+
(serverStatus && serverStatus.objections_repeat_suppressed) || 0
|
|
1214
|
+
);
|
|
1215
|
+
const objectionsChainedBlocks = Number(
|
|
1216
|
+
(serverStatus && serverStatus.objections_chained_distinct_blocks) || 0
|
|
1217
|
+
);
|
|
1218
|
+
const objectionsResolvedOnRetry = Number(
|
|
1219
|
+
(serverStatus && serverStatus.objections_resolved_on_retry) || 0
|
|
1220
|
+
);
|
|
1221
|
+
const memoriesAutoDowngraded = Number(
|
|
1222
|
+
(serverStatus && serverStatus.memories_auto_downgraded) || 0
|
|
1223
|
+
);
|
|
1224
|
+
const flaggedNoisyMemories = Array.isArray(serverStatus && serverStatus.flagged_noisy_memories)
|
|
1225
|
+
? serverStatus.flagged_noisy_memories
|
|
1226
|
+
: [];
|
|
1227
|
+
|
|
1211
1228
|
const summaryLine =
|
|
1212
1229
|
(serverStatus && serverStatus.summary_line) ||
|
|
1213
1230
|
`${memoriesAssimilated} rules learned passively • ${amnesiaIntercepted} amnesia episodes intercepted • ${Math.round(noiseFilteredPct)}% stream noise filtered`;
|
|
@@ -1217,6 +1234,11 @@ async function runStatusCommand(opts) {
|
|
|
1217
1234
|
memories_assimilated: memoriesAssimilated,
|
|
1218
1235
|
memories_superseded: memoriesSuperseded,
|
|
1219
1236
|
amnesia_episodes_intercepted: amnesiaIntercepted,
|
|
1237
|
+
objections_chained_distinct_blocks: objectionsChainedBlocks,
|
|
1238
|
+
objections_repeat_suppressed: objectionsRepeatSuppressed,
|
|
1239
|
+
objections_resolved_on_retry: objectionsResolvedOnRetry,
|
|
1240
|
+
memories_auto_downgraded: memoriesAutoDowngraded,
|
|
1241
|
+
flagged_noisy_memories: flaggedNoisyMemories,
|
|
1220
1242
|
events_processed: eventsProcessed,
|
|
1221
1243
|
events_filtered_noise: eventsFiltered,
|
|
1222
1244
|
summary_line: summaryLine,
|
|
@@ -1237,6 +1259,18 @@ async function runStatusCommand(opts) {
|
|
|
1237
1259
|
` # New Memories Assimilated : ${memoriesAssimilated}${memoriesSuperseded > 0 ? ` (${memoriesSuperseded} superseded)` : ""}`
|
|
1238
1260
|
);
|
|
1239
1261
|
console.log(` # Amnesia Episodes Intercepted : ${amnesiaIntercepted}`);
|
|
1262
|
+
if (
|
|
1263
|
+
objectionsRepeatSuppressed > 0 ||
|
|
1264
|
+
objectionsResolvedOnRetry > 0 ||
|
|
1265
|
+
memoriesAutoDowngraded > 0
|
|
1266
|
+
) {
|
|
1267
|
+
console.log(
|
|
1268
|
+
` # Objections Resolved on Retry : ${objectionsResolvedOnRetry}${objectionsChainedBlocks > 0 ? ` (${objectionsChainedBlocks} chained distinct)` : ""}`
|
|
1269
|
+
);
|
|
1270
|
+
console.log(
|
|
1271
|
+
` # Repeat Objections Suppressed : ${objectionsRepeatSuppressed}${memoriesAutoDowngraded > 0 ? ` (${memoriesAutoDowngraded} noisy memories auto-downgraded)` : ""}`
|
|
1272
|
+
);
|
|
1273
|
+
}
|
|
1240
1274
|
}
|
|
1241
1275
|
|
|
1242
1276
|
function extractLastPlannerResponseFromTranscript(transcriptPath) {
|
|
@@ -1437,7 +1471,9 @@ async function runAmbientHookMode(opts) {
|
|
|
1437
1471
|
payload.terminationReason !== undefined ||
|
|
1438
1472
|
payload.workspacePaths !== undefined ||
|
|
1439
1473
|
payload.artifactDirectoryPath !== undefined ||
|
|
1440
|
-
payload.conversationId !== undefined
|
|
1474
|
+
payload.conversationId !== undefined ||
|
|
1475
|
+
(payload.conversation_id !== undefined &&
|
|
1476
|
+
(cliEvent === "Stop" || payload.transcript_path !== undefined))
|
|
1441
1477
|
);
|
|
1442
1478
|
|
|
1443
1479
|
let rawEventName = String(
|
|
@@ -1495,8 +1531,8 @@ async function runAmbientHookMode(opts) {
|
|
|
1495
1531
|
}
|
|
1496
1532
|
}
|
|
1497
1533
|
|
|
1498
|
-
//
|
|
1499
|
-
if (
|
|
1534
|
+
// Enforce hard 3-retry safety ceiling locally if harness passes an explicit loop_count >= 3
|
|
1535
|
+
if (hookEvent === "Stop" && Number(payload.loop_count || 0) >= MAX_STOP_BLOCKS_PER_PROMPT) {
|
|
1500
1536
|
writeDefaultHookOutput(isGeminiHook, rawEventName, isCursorHook);
|
|
1501
1537
|
return;
|
|
1502
1538
|
}
|
|
@@ -1692,6 +1728,30 @@ async function runAmbientHookMode(opts) {
|
|
|
1692
1728
|
.trim()
|
|
1693
1729
|
.slice(0, 1024);
|
|
1694
1730
|
|
|
1731
|
+
const whisperKey = sessionKey || scopeStateKey;
|
|
1732
|
+
const isMidTurnContinuation =
|
|
1733
|
+
rawEventName === "PreInvocation" &&
|
|
1734
|
+
(Number(payload.invocationNum || 1) > 1 || Number(payload.executionNum || 1) > 1);
|
|
1735
|
+
if (!dedupState.stop_turn_by_session || typeof dedupState.stop_turn_by_session !== "object") {
|
|
1736
|
+
dedupState.stop_turn_by_session = {};
|
|
1737
|
+
}
|
|
1738
|
+
if (hookEvent === "UserPromptSubmit" && !isMidTurnContinuation && whisperKey) {
|
|
1739
|
+
const existingStopTurn = dedupState.stop_turn_by_session[whisperKey];
|
|
1740
|
+
if (
|
|
1741
|
+
existingStopTurn &&
|
|
1742
|
+
((Array.isArray(existingStopTurn.blocked_ids) && existingStopTurn.blocked_ids.length > 0) ||
|
|
1743
|
+
Number(existingStopTurn.retry_count || 0) > 0)
|
|
1744
|
+
) {
|
|
1745
|
+
dedupState.stop_turn_by_session[whisperKey] = { blocked_ids: [], retry_count: 0 };
|
|
1746
|
+
try {
|
|
1747
|
+
fs.mkdirSync(path.dirname(dedupPath), { recursive: true });
|
|
1748
|
+
fs.writeFileSync(dedupPath, JSON.stringify(dedupState), "utf8");
|
|
1749
|
+
} catch {
|
|
1750
|
+
// ignore state persistence errors
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1695
1755
|
if (
|
|
1696
1756
|
!deltaText ||
|
|
1697
1757
|
deltaText.length < 4 ||
|
|
@@ -1702,6 +1762,21 @@ async function runAmbientHookMode(opts) {
|
|
|
1702
1762
|
return;
|
|
1703
1763
|
}
|
|
1704
1764
|
|
|
1765
|
+
const activeStopTurn =
|
|
1766
|
+
whisperKey &&
|
|
1767
|
+
dedupState.stop_turn_by_session[whisperKey] &&
|
|
1768
|
+
typeof dedupState.stop_turn_by_session[whisperKey] === "object"
|
|
1769
|
+
? dedupState.stop_turn_by_session[whisperKey]
|
|
1770
|
+
: { blocked_ids: [], retry_count: 0 };
|
|
1771
|
+
const turnBlockedIds = Array.isArray(activeStopTurn.blocked_ids)
|
|
1772
|
+
? activeStopTurn.blocked_ids.map(String).filter(Boolean)
|
|
1773
|
+
: [];
|
|
1774
|
+
const turnStopRetries = Number(activeStopTurn.retry_count || 0);
|
|
1775
|
+
if (hookEvent === "Stop" && turnStopRetries >= MAX_STOP_BLOCKS_PER_PROMPT) {
|
|
1776
|
+
writeDefaultHookOutput(isGeminiHook, rawEventName, isCursorHook);
|
|
1777
|
+
return;
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1705
1780
|
// Event deduplication (scoped to project/session/step and only persisted for non-actionable noise)
|
|
1706
1781
|
const stepKey = String(
|
|
1707
1782
|
payload.stepIdx ?? payload.invocationNum ?? payload.executionNum ?? ""
|
|
@@ -1743,9 +1818,6 @@ async function runAmbientHookMode(opts) {
|
|
|
1743
1818
|
if (!dedupState.blocked_actions_by_session || typeof dedupState.blocked_actions_by_session !== "object") {
|
|
1744
1819
|
dedupState.blocked_actions_by_session = {};
|
|
1745
1820
|
}
|
|
1746
|
-
const whisperKey = sessionKey || scopeStateKey;
|
|
1747
|
-
const isMidTurnContinuation =
|
|
1748
|
-
rawEventName === "PreInvocation" && Number(payload.invocationNum || 1) > 1;
|
|
1749
1821
|
const targetSig = toolIn
|
|
1750
1822
|
? String(
|
|
1751
1823
|
toolIn.file_path ||
|
|
@@ -1838,8 +1910,11 @@ async function runAmbientHookMode(opts) {
|
|
|
1838
1910
|
? {
|
|
1839
1911
|
last_assistant_message: deltaText,
|
|
1840
1912
|
stop_hook_active: Boolean(payload.stop_hook_active),
|
|
1913
|
+
turn_blocked_memory_ids: turnBlockedIds,
|
|
1914
|
+
stop_retry_count: turnStopRetries,
|
|
1841
1915
|
}
|
|
1842
1916
|
: {}),
|
|
1917
|
+
...(isMidTurnContinuation ? { is_mid_turn_continuation: true } : {}),
|
|
1843
1918
|
tool_name: toolName,
|
|
1844
1919
|
tool_input: effectiveToolIn,
|
|
1845
1920
|
tool_response: payload.tool_response || payload.toolResponse || null,
|
|
@@ -1849,11 +1924,46 @@ async function runAmbientHookMode(opts) {
|
|
|
1849
1924
|
model: process.env.SLASHML_MODEL || undefined,
|
|
1850
1925
|
user_id: opts.userId,
|
|
1851
1926
|
...(projectId ? { project_id: projectId } : {}),
|
|
1852
|
-
|
|
1927
|
+
session_id: whisperKey,
|
|
1853
1928
|
client_raw_tokens_delta: (telem.pending_raw_tokens_delta || 0) + strippedTokens,
|
|
1854
1929
|
client_dropped_tokens_delta: (telem.pending_dropped_tokens_delta || 0) + strippedTokens,
|
|
1855
1930
|
client_dropped_events_delta: telem.pending_dropped_events_delta || 0,
|
|
1856
1931
|
});
|
|
1932
|
+
// Client-side per-memory Stop circuit breaker (defense-in-depth across server restarts/versions):
|
|
1933
|
+
// at most 1 Stop block per memory_id per user prompt, and at most MAX_STOP_BLOCKS_PER_PROMPT total.
|
|
1934
|
+
if (
|
|
1935
|
+
hookEvent === "Stop" &&
|
|
1936
|
+
resp &&
|
|
1937
|
+
resp.should_intervene &&
|
|
1938
|
+
(resp.intervention_severity === "BLOCK" || resp.action === "BLOCK")
|
|
1939
|
+
) {
|
|
1940
|
+
const respTriggered = Array.from(
|
|
1941
|
+
new Set(
|
|
1942
|
+
[
|
|
1943
|
+
...(Array.isArray(resp.violated_memory_ids) ? resp.violated_memory_ids : []),
|
|
1944
|
+
...(resp.violated_memory_id ? [resp.violated_memory_id] : []),
|
|
1945
|
+
...(resp.triggered_memory_id ? [resp.triggered_memory_id] : []),
|
|
1946
|
+
]
|
|
1947
|
+
.map(String)
|
|
1948
|
+
.filter(Boolean)
|
|
1949
|
+
)
|
|
1950
|
+
);
|
|
1951
|
+
const novelStopIds = respTriggered.filter((id) => !turnBlockedIds.includes(id));
|
|
1952
|
+
if (
|
|
1953
|
+
turnStopRetries >= MAX_STOP_BLOCKS_PER_PROMPT ||
|
|
1954
|
+
(respTriggered.length > 0 && novelStopIds.length === 0)
|
|
1955
|
+
) {
|
|
1956
|
+
resp.should_intervene = false;
|
|
1957
|
+
resp.intervention_severity = "NONE";
|
|
1958
|
+
resp.intervention_message = null;
|
|
1959
|
+
resp.hook_output = {};
|
|
1960
|
+
} else if (whisperKey) {
|
|
1961
|
+
dedupState.stop_turn_by_session[whisperKey] = {
|
|
1962
|
+
blocked_ids: Array.from(new Set([...turnBlockedIds, ...novelStopIds])).slice(-16),
|
|
1963
|
+
retry_count: turnStopRetries + 1,
|
|
1964
|
+
};
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1857
1967
|
telem.pending_raw_tokens_delta = 0;
|
|
1858
1968
|
telem.pending_dropped_tokens_delta = 0;
|
|
1859
1969
|
telem.pending_dropped_events_delta = 0;
|
|
@@ -1916,10 +2026,18 @@ async function runAmbientHookMode(opts) {
|
|
|
1916
2026
|
} else {
|
|
1917
2027
|
telem.noise_tokens_filtered = (telem.noise_tokens_filtered || 0) + rawEventTokens;
|
|
1918
2028
|
telem.events_filtered_noise = (telem.events_filtered_noise || 0) + 1;
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
2029
|
+
const wasRepeatSuppressed = Boolean(
|
|
2030
|
+
resp &&
|
|
2031
|
+
((Array.isArray(resp.repeat_suppressed_memory_ids) &&
|
|
2032
|
+
resp.repeat_suppressed_memory_ids.length > 0) ||
|
|
2033
|
+
resp.objection_outcome === "SAFETY_CEILING_SUPPRESSED")
|
|
2034
|
+
);
|
|
2035
|
+
if (!wasRepeatSuppressed && hookEvent !== "Stop" && hookEvent !== "PreToolUse") {
|
|
2036
|
+
dedupState.hashes = [
|
|
2037
|
+
...(Array.isArray(dedupState.hashes) ? dedupState.hashes.slice(-63) : []),
|
|
2038
|
+
deltaHash,
|
|
2039
|
+
];
|
|
2040
|
+
}
|
|
1923
2041
|
}
|
|
1924
2042
|
try {
|
|
1925
2043
|
fs.mkdirSync(path.dirname(dedupPath), { recursive: true });
|
|
@@ -2684,10 +2802,34 @@ function makeMigrationDocId(prefix, text, userId = "default") {
|
|
|
2684
2802
|
return `mig_${prefix}_${digest}`;
|
|
2685
2803
|
}
|
|
2686
2804
|
|
|
2805
|
+
function stripCommentMarkerBlock(input, startSuffix, endSuffix) {
|
|
2806
|
+
let out = String(input || "");
|
|
2807
|
+
while (true) {
|
|
2808
|
+
const mid = out.indexOf(startSuffix);
|
|
2809
|
+
if (mid === -1) break;
|
|
2810
|
+
const blockStart = out.lastIndexOf("<!--", mid);
|
|
2811
|
+
if (blockStart === -1) break;
|
|
2812
|
+
const endMid = out.indexOf(endSuffix, mid + startSuffix.length);
|
|
2813
|
+
if (endMid === -1) break;
|
|
2814
|
+
const blockEnd = out.indexOf("-->", endMid + endSuffix.length);
|
|
2815
|
+
if (blockEnd === -1) break;
|
|
2816
|
+
out = out.slice(0, blockStart) + out.slice(blockEnd + 3);
|
|
2817
|
+
}
|
|
2818
|
+
return out;
|
|
2819
|
+
}
|
|
2820
|
+
|
|
2687
2821
|
function stripSlashmlInjectedBlocks(rawMarkdown) {
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2822
|
+
const withoutRules = stripCommentMarkerBlock(
|
|
2823
|
+
rawMarkdown,
|
|
2824
|
+
"-MEMORY-RULE:START",
|
|
2825
|
+
"-MEMORY-RULE:END"
|
|
2826
|
+
);
|
|
2827
|
+
const withoutAmbient = stripCommentMarkerBlock(
|
|
2828
|
+
withoutRules,
|
|
2829
|
+
"SLASHML-AMBIENT-MEMORY:START",
|
|
2830
|
+
"SLASHML-AMBIENT-MEMORY:END"
|
|
2831
|
+
);
|
|
2832
|
+
return withoutAmbient
|
|
2691
2833
|
.replace(/^---[\r\n]+[\s\S]*?[\r\n]+---[\r\n]*/m, "")
|
|
2692
2834
|
.trim();
|
|
2693
2835
|
}
|