@slashml/memory 1.0.9 → 1.0.10

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 CHANGED
@@ -10,7 +10,7 @@ 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.9";
13
+ const PACKAGE_VERSION = "1.0.10";
14
14
 
15
15
  function printHelp() {
16
16
  console.log(`@slashml/memory v${PACKAGE_VERSION} -- Official CLI & MCP Stdio Server for / ml (SlashML · https://slashml.ai)
@@ -1157,13 +1157,52 @@ async function runAmbientHookMode(opts) {
1157
1157
  if (!dedupState.whispered_blocks_by_session || typeof dedupState.whispered_blocks_by_session !== "object") {
1158
1158
  dedupState.whispered_blocks_by_session = {};
1159
1159
  }
1160
+ if (!dedupState.blocked_by_session || typeof dedupState.blocked_by_session !== "object") {
1161
+ dedupState.blocked_by_session = {};
1162
+ }
1163
+ if (!dedupState.overridden_by_session || typeof dedupState.overridden_by_session !== "object") {
1164
+ dedupState.overridden_by_session = {};
1165
+ }
1166
+ if (!dedupState.blocked_actions_by_session || typeof dedupState.blocked_actions_by_session !== "object") {
1167
+ dedupState.blocked_actions_by_session = {};
1168
+ }
1160
1169
  const whisperKey = sessionKey || scopeStateKey;
1161
1170
  const isMidTurnContinuation =
1162
1171
  rawEventName === "PreInvocation" && Number(payload.invocationNum || 1) > 1;
1172
+ const targetSig = toolIn
1173
+ ? String(
1174
+ toolIn.file_path ||
1175
+ toolIn.path ||
1176
+ toolIn.Path ||
1177
+ toolIn.command ||
1178
+ toolIn.CommandLine ||
1179
+ deltaText.slice(0, 120)
1180
+ )
1181
+ .trim()
1182
+ .toLowerCase()
1183
+ : deltaText.slice(0, 120).toLowerCase();
1184
+
1163
1185
  if (hookEvent === "UserPromptSubmit" && !isMidTurnContinuation && whisperKey) {
1164
- dedupState.whispered_by_session[whisperKey] = [];
1165
1186
  dedupState.whispered_blocks_by_session[whisperKey] = [];
1166
1187
  }
1188
+ if (hookEvent === "PreToolUse" && whisperKey) {
1189
+ const prevAct = Array.isArray(dedupState.blocked_actions_by_session[whisperKey])
1190
+ ? dedupState.blocked_actions_by_session[whisperKey]
1191
+ : [];
1192
+ const prevOv = Array.isArray(dedupState.overridden_by_session[whisperKey])
1193
+ ? dedupState.overridden_by_session[whisperKey]
1194
+ : [];
1195
+ const suffix = `:${toolName || ""}:${targetSig}`;
1196
+ const matchedIds = prevAct
1197
+ .filter((entry) => typeof entry === "string" && entry.endsWith(suffix))
1198
+ .map((entry) => entry.slice(0, entry.length - suffix.length))
1199
+ .filter(Boolean);
1200
+ if (matchedIds.length > 0) {
1201
+ dedupState.overridden_by_session[whisperKey] = Array.from(
1202
+ new Set([...prevOv, ...matchedIds])
1203
+ ).slice(-32);
1204
+ }
1205
+ }
1167
1206
  const transcriptWhispered = extractWhisperedContextFromCurrentTurn(
1168
1207
  payload.transcriptPath || payload.transcript_path
1169
1208
  );
@@ -1175,6 +1214,18 @@ async function runAmbientHookMode(opts) {
1175
1214
  whisperKey && Array.isArray(dedupState.whispered_blocks_by_session[whisperKey])
1176
1215
  ? dedupState.whispered_blocks_by_session[whisperKey]
1177
1216
  : [];
1217
+ const sessionOverridden = [
1218
+ ...(whisperKey && Array.isArray(dedupState.overridden_by_session[whisperKey])
1219
+ ? dedupState.overridden_by_session[whisperKey]
1220
+ : []),
1221
+ ...(Array.isArray(dedupState.overridden_by_session._global)
1222
+ ? dedupState.overridden_by_session._global
1223
+ : []),
1224
+ ...(Array.isArray(payload.overridden_memory_ids) ? payload.overridden_memory_ids : []),
1225
+ ...(toolIn && Array.isArray(toolIn.override_memory_ids) ? toolIn.override_memory_ids : []),
1226
+ ...(toolIn && Array.isArray(toolIn.overridden_memory_ids) ? toolIn.overridden_memory_ids : []),
1227
+ ];
1228
+ const overriddenMemoryIds = Array.from(new Set(sessionOverridden.map(String).filter(Boolean)));
1178
1229
  const whisperedMemoryIds = Array.from(new Set([...transcriptWhispered.ids, ...sessionWhispered]));
1179
1230
  const whisperedBlocks = Array.from(new Set([...transcriptWhispered.blocks, ...sessionWhisperedBlocks]));
1180
1231
  const streamTextForIntervene =
@@ -1216,6 +1267,7 @@ async function runAmbientHookMode(opts) {
1216
1267
  tool_input: effectiveToolIn,
1217
1268
  tool_response: payload.tool_response || payload.toolResponse || null,
1218
1269
  whispered_memory_ids: whisperedMemoryIds,
1270
+ ...(overriddenMemoryIds.length > 0 ? { overridden_memory_ids: overriddenMemoryIds } : {}),
1219
1271
  commit_writes: isMidTurnContinuation ? false : true,
1220
1272
  model: process.env.SLASHML_MODEL || undefined,
1221
1273
  user_id: opts.userId,
@@ -1255,6 +1307,23 @@ async function runAmbientHookMode(opts) {
1255
1307
  : [];
1256
1308
  const merged = Array.from(new Set([...prev, ...triggeredIds]));
1257
1309
  dedupState.whispered_by_session[whisperKey] = merged.slice(-16);
1310
+ if (resp.intervention_severity === "BLOCK") {
1311
+ const prevBlk = Array.isArray(dedupState.blocked_by_session[whisperKey])
1312
+ ? dedupState.blocked_by_session[whisperKey]
1313
+ : [];
1314
+ dedupState.blocked_by_session[whisperKey] = Array.from(
1315
+ new Set([...prevBlk, ...triggeredIds])
1316
+ ).slice(-16);
1317
+ if (hookEvent === "PreToolUse") {
1318
+ const prevAct = Array.isArray(dedupState.blocked_actions_by_session[whisperKey])
1319
+ ? dedupState.blocked_actions_by_session[whisperKey]
1320
+ : [];
1321
+ const actKeys = triggeredIds.map((id) => `${id}:${toolName || ""}:${targetSig}`);
1322
+ dedupState.blocked_actions_by_session[whisperKey] = Array.from(
1323
+ new Set([...prevAct, ...actKeys])
1324
+ ).slice(-32);
1325
+ }
1326
+ }
1258
1327
  }
1259
1328
  if (whisperKey && resp.intervention_message) {
1260
1329
  const msgTags = String(resp.intervention_message).match(/<memory>[\s\S]*?<\/memory>/gi);
@@ -2211,6 +2280,7 @@ const CODE_MODE_TOOLS = [
2211
2280
  "search_code_by_behavior",
2212
2281
  "find_bug_candidates",
2213
2282
  "intervene_memory",
2283
+ "dismiss_intervention",
2214
2284
  ],
2215
2285
  },
2216
2286
  params: { type: "object" },
@@ -2623,6 +2693,11 @@ async function dispatchTool(opts, name, args = {}) {
2623
2693
  args.project_id || args.projectId || process.env.SLASHML_PROJECT_ID || undefined;
2624
2694
  const resolvedSessionId =
2625
2695
  args.session_id || args.sessionId || process.env.SLASHML_SESSION_ID || undefined;
2696
+ const overriddenIds = [
2697
+ ...(Array.isArray(args.overridden_memory_ids) ? args.overridden_memory_ids : []),
2698
+ ...(Array.isArray(args.dismiss_memory_ids) ? args.dismiss_memory_ids : []),
2699
+ ...(args.override_memory_id ? [String(args.override_memory_id)] : []),
2700
+ ].filter(Boolean);
2626
2701
  return apiRequest(opts, "POST", "/v1/memory/intervene", {
2627
2702
  hook_event_name: args.hook_event_name || "UserPromptSubmit",
2628
2703
  prompt: args.prompt || rawText,
@@ -2630,6 +2705,7 @@ async function dispatchTool(opts, name, args = {}) {
2630
2705
  tool_name: args.tool_name || null,
2631
2706
  tool_input: args.tool_input || null,
2632
2707
  tool_response: args.tool_response || null,
2708
+ ...(overriddenIds.length > 0 ? { overridden_memory_ids: overriddenIds } : {}),
2633
2709
  model: args.model || process.env.SLASHML_MODEL || undefined,
2634
2710
  user_id: uid,
2635
2711
  ...(resolvedProjectId ? { project_id: String(resolvedProjectId) } : {}),
@@ -2638,6 +2714,72 @@ async function dispatchTool(opts, name, args = {}) {
2638
2714
  top_k: Number(args.top_k || args.limit || 5),
2639
2715
  });
2640
2716
  }
2717
+ if (name === "dismiss_intervention") {
2718
+ const memIds = [
2719
+ ...(args.memory_id ? [String(args.memory_id)] : []),
2720
+ ...(Array.isArray(args.memory_ids) ? args.memory_ids.map(String) : []),
2721
+ ...(Array.isArray(args.overridden_memory_ids) ? args.overridden_memory_ids.map(String) : []),
2722
+ ].filter(Boolean);
2723
+ if (memIds.length === 0) {
2724
+ throw new Error("dismiss_intervention requires memory_id or memory_ids");
2725
+ }
2726
+ const reason = String(args.reason || "Dismissed false-positive intervention for session");
2727
+ const dedupPath =
2728
+ process.env.SLASHML_HOOK_STATE_PATH ||
2729
+ path.join(os.homedir(), ".slashml", "hook_state.json");
2730
+ try {
2731
+ let dedupState = { hashes: [] };
2732
+ if (fs.existsSync(dedupPath)) {
2733
+ dedupState = JSON.parse(fs.readFileSync(dedupPath, "utf8")) || { hashes: [] };
2734
+ }
2735
+ if (!dedupState.overridden_by_session || typeof dedupState.overridden_by_session !== "object") {
2736
+ dedupState.overridden_by_session = {};
2737
+ }
2738
+ const prevGlobal = Array.isArray(dedupState.overridden_by_session._global)
2739
+ ? dedupState.overridden_by_session._global
2740
+ : [];
2741
+ dedupState.overridden_by_session._global = Array.from(
2742
+ new Set([...prevGlobal, ...memIds])
2743
+ ).slice(-64);
2744
+ const sessKey = String(args.session_id || args.sessionId || process.env.SLASHML_SESSION_ID || "").trim();
2745
+ if (sessKey) {
2746
+ const prevSess = Array.isArray(dedupState.overridden_by_session[sessKey])
2747
+ ? dedupState.overridden_by_session[sessKey]
2748
+ : [];
2749
+ dedupState.overridden_by_session[sessKey] = Array.from(
2750
+ new Set([...prevSess, ...memIds])
2751
+ ).slice(-64);
2752
+ }
2753
+ fs.mkdirSync(path.dirname(dedupPath), { recursive: true });
2754
+ fs.writeFileSync(dedupPath, JSON.stringify(dedupState), "utf8");
2755
+ } catch {
2756
+ // ignore local state persistence error
2757
+ }
2758
+ const resolvedProjectId =
2759
+ args.project_id || args.projectId || process.env.SLASHML_PROJECT_ID || undefined;
2760
+ const resolvedSessionId =
2761
+ args.session_id || args.sessionId || process.env.SLASHML_SESSION_ID || undefined;
2762
+ try {
2763
+ await apiRequest(opts, "POST", "/v1/memory/intervene", {
2764
+ hook_event_name: "UserPromptSubmit",
2765
+ prompt: `Dismiss intervention for ${memIds.join(", ")}: ${reason}`,
2766
+ text: `Dismiss intervention for ${memIds.join(", ")}: ${reason}`,
2767
+ overridden_memory_ids: memIds,
2768
+ dismiss_memory_ids: memIds,
2769
+ commit_writes: false,
2770
+ user_id: uid,
2771
+ ...(resolvedProjectId ? { project_id: String(resolvedProjectId) } : {}),
2772
+ ...(resolvedSessionId ? { session_id: String(resolvedSessionId) } : {}),
2773
+ });
2774
+ } catch {
2775
+ // local hook_state override is already persisted
2776
+ }
2777
+ return {
2778
+ status: "dismissed",
2779
+ overridden_memory_ids: memIds,
2780
+ reason,
2781
+ };
2782
+ }
2641
2783
  throw new Error(`Unknown MCP tool: ${name}`);
2642
2784
  }
2643
2785
 
package/dist/index.js CHANGED
@@ -315,7 +315,7 @@ class MemoryClient {
315
315
  const headers = {
316
316
  Accept: "application/json",
317
317
  "Content-Type": "application/json",
318
- "User-Agent": "slashml-memory-ts/1.0.9",
318
+ "User-Agent": "slashml-memory-ts/1.0.10",
319
319
  };
320
320
  if (this.apiKey) {
321
321
  headers.Authorization = `Bearer ${this.apiKey}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slashml/memory",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Official HTTP TypeScript & Node.js SDK for / ml (https://api.slashml.ai)",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://slashml.ai",
package/src/index.ts CHANGED
@@ -531,7 +531,7 @@ export class MemoryClient {
531
531
  const headers: Record<string, string> = {
532
532
  Accept: "application/json",
533
533
  "Content-Type": "application/json",
534
- "User-Agent": "slashml-memory-ts/1.0.9",
534
+ "User-Agent": "slashml-memory-ts/1.0.10",
535
535
  };
536
536
  if (this.apiKey) {
537
537
  headers.Authorization = `Bearer ${this.apiKey}`;