@slashml/memory 1.0.5 → 1.0.6

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.5";
13
+ const PACKAGE_VERSION = "1.0.6";
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)
@@ -527,12 +527,12 @@ function installAmbientHooks(apiKey) {
527
527
  fs.writeFileSync(claudeSettingsPath, JSON.stringify(settings, null, 2) + "\n", "utf8");
528
528
  console.log(`Configured / ml ambient lifecycle hooks in ${claudeSettingsPath}`);
529
529
 
530
- // Also configure Antigravity (agy) plugin hooks if ~/.gemini/config exists
531
- const agyPluginDir = path.join(home, ".gemini", "config", "plugins", "slashml-memory");
532
- if (fs.existsSync(path.join(home, ".gemini", "config")) || fs.existsSync(agyPluginDir)) {
533
- fs.mkdirSync(agyPluginDir, { recursive: true });
534
- const agyHooksPath = path.join(agyPluginDir, "hooks.json");
535
- const agyHooks = {
530
+ // Also configure Gemini CLI plugin hooks if ~/.gemini/config exists
531
+ const geminiPluginDir = path.join(home, ".gemini", "config", "plugins", "slashml-memory");
532
+ if (fs.existsSync(path.join(home, ".gemini", "config")) || fs.existsSync(geminiPluginDir)) {
533
+ fs.mkdirSync(geminiPluginDir, { recursive: true });
534
+ const geminiHooksPath = path.join(geminiPluginDir, "hooks.json");
535
+ const geminiHooks = {
536
536
  "slashml-ambient-memory": {
537
537
  PreInvocation: [
538
538
  {
@@ -574,8 +574,8 @@ function installAmbientHooks(apiKey) {
574
574
  ],
575
575
  },
576
576
  };
577
- fs.writeFileSync(agyHooksPath, JSON.stringify(agyHooks, null, 2) + "\n", "utf8");
578
- console.log(`Configured / ml ambient lifecycle hooks in ${agyHooksPath}`);
577
+ fs.writeFileSync(geminiHooksPath, JSON.stringify(geminiHooks, null, 2) + "\n", "utf8");
578
+ console.log(`Configured / ml ambient lifecycle hooks in ${geminiHooksPath}`);
579
579
  }
580
580
  }
581
581
 
@@ -769,9 +769,25 @@ function extractLastPlannerResponseFromTranscript(transcriptPath) {
769
769
  if (!line || !line.startsWith("{")) continue;
770
770
  try {
771
771
  const entry = JSON.parse(line);
772
- if (entry && entry.type === "PLANNER_RESPONSE" && typeof entry.content === "string" && entry.content.trim()) {
772
+ if (!entry) continue;
773
+ if (entry.type === "PLANNER_RESPONSE" && typeof entry.content === "string" && entry.content.trim()) {
773
774
  return entry.content.trim();
774
775
  }
776
+ const msgObj = entry.message && typeof entry.message === "object" ? entry.message : entry;
777
+ if (msgObj && msgObj.role === "assistant") {
778
+ if (typeof msgObj.content === "string" && msgObj.content.trim()) {
779
+ return msgObj.content.trim();
780
+ }
781
+ if (Array.isArray(msgObj.content)) {
782
+ const textParts = msgObj.content
783
+ .filter((b) => b && (b.type === "text" || typeof b.text === "string"))
784
+ .map((b) => String(b.text || "").trim())
785
+ .filter(Boolean);
786
+ if (textParts.length > 0) {
787
+ return textParts.join("\n").trim();
788
+ }
789
+ }
790
+ }
775
791
  } catch {
776
792
  // ignore partial line at start of buffer
777
793
  }
@@ -831,8 +847,8 @@ function extractWhisperedContextFromCurrentTurn(transcriptPath) {
831
847
  return { ids: Array.from(ids), blocks: Array.from(blocks) };
832
848
  }
833
849
 
834
- function writeDefaultHookOutput(isAntigravity, rawEventName) {
835
- if (isAntigravity && rawEventName === "PreToolUse") {
850
+ function writeDefaultHookOutput(isGeminiHook, rawEventName) {
851
+ if (isGeminiHook && rawEventName === "PreToolUse") {
836
852
  process.stdout.write(JSON.stringify({ decision: "allow" }) + "\n");
837
853
  } else {
838
854
  process.stdout.write("{}\n");
@@ -889,7 +905,7 @@ async function runAmbientHookMode(opts) {
889
905
  payload = { hook_event_name: cliEvent || "UserPromptSubmit", prompt: rawInput };
890
906
  }
891
907
 
892
- const isAntigravity = Boolean(
908
+ const isGeminiHook = Boolean(
893
909
  cliEvent === "PreInvocation" ||
894
910
  payload.invocationNum !== undefined ||
895
911
  payload.toolCall !== undefined ||
@@ -903,7 +919,7 @@ async function runAmbientHookMode(opts) {
903
919
  cliEvent || payload.hook_event_name || payload.hook_event || payload.event || ""
904
920
  ).trim();
905
921
  if (!rawEventName) {
906
- if (isAntigravity) {
922
+ if (isGeminiHook) {
907
923
  if (payload.toolCall !== undefined) {
908
924
  rawEventName =
909
925
  payload.toolResponse !== undefined || payload.toolResult !== undefined
@@ -921,14 +937,20 @@ async function runAmbientHookMode(opts) {
921
937
 
922
938
  const hookEvent = rawEventName === "PreInvocation" ? "UserPromptSubmit" : rawEventName;
923
939
 
924
- // On Antigravity Stop, only evaluate normal completion turns (NO_TOOL_CALL)
925
- if (isAntigravity && rawEventName === "Stop") {
940
+ // On Gemini CLI Stop, only evaluate normal completion turns (NO_TOOL_CALL)
941
+ if (isGeminiHook && rawEventName === "Stop") {
926
942
  if (payload.terminationReason && payload.terminationReason !== "NO_TOOL_CALL") {
927
- writeDefaultHookOutput(isAntigravity, rawEventName);
943
+ writeDefaultHookOutput(isGeminiHook, rawEventName);
928
944
  return;
929
945
  }
930
946
  }
931
947
 
948
+ // On Claude Code Stop, never re-block if stop_hook_active is already true
949
+ if (!isGeminiHook && rawEventName === "Stop" && payload.stop_hook_active) {
950
+ writeDefaultHookOutput(isGeminiHook, rawEventName);
951
+ return;
952
+ }
953
+
932
954
  const toolCallObj =
933
955
  payload.toolCall && typeof payload.toolCall === "object" ? payload.toolCall : null;
934
956
  const toolName =
@@ -991,7 +1013,7 @@ async function runAmbientHookMode(opts) {
991
1013
  if (HOOK_READ_ONLY_TOOLS.has(toolName.toLowerCase())) {
992
1014
  persistPendingToolContext();
993
1015
  recordLocalHookDrop(rawEventTokens);
994
- writeDefaultHookOutput(isAntigravity, rawEventName);
1016
+ writeDefaultHookOutput(isGeminiHook, rawEventName);
995
1017
  return;
996
1018
  }
997
1019
  }
@@ -1023,7 +1045,7 @@ async function runAmbientHookMode(opts) {
1023
1045
  if (isReadOnlyCmd) {
1024
1046
  persistPendingToolContext();
1025
1047
  recordLocalHookDrop(rawEventTokens);
1026
- writeDefaultHookOutput(isAntigravity, rawEventName);
1048
+ writeDefaultHookOutput(isGeminiHook, rawEventName);
1027
1049
  return;
1028
1050
  }
1029
1051
  }
@@ -1039,11 +1061,12 @@ async function runAmbientHookMode(opts) {
1039
1061
  ""
1040
1062
  );
1041
1063
  } else if (hookEvent === "Stop") {
1064
+ const transcriptFile = payload.transcriptPath || payload.transcript_path;
1042
1065
  rawCandidateText = String(
1043
1066
  payload.last_assistant_message ||
1044
1067
  payload.assistant_message ||
1045
1068
  payload.response ||
1046
- extractLastPlannerResponseFromTranscript(payload.transcriptPath) ||
1069
+ extractLastPlannerResponseFromTranscript(transcriptFile) ||
1047
1070
  ""
1048
1071
  );
1049
1072
  } else {
@@ -1065,7 +1088,7 @@ async function runAmbientHookMode(opts) {
1065
1088
  /^(ok|okay|thanks|thank you|yes|no|sure|cool|lgtm)[.!]*$/i.test(deltaText)
1066
1089
  ) {
1067
1090
  recordLocalHookDrop(rawEventTokens);
1068
- writeDefaultHookOutput(isAntigravity, rawEventName);
1091
+ writeDefaultHookOutput(isGeminiHook, rawEventName);
1069
1092
  return;
1070
1093
  }
1071
1094
 
@@ -1082,13 +1105,13 @@ async function runAmbientHookMode(opts) {
1082
1105
  .slice(0, 16);
1083
1106
  if (Array.isArray(dedupState.hashes) && dedupState.hashes.includes(deltaHash)) {
1084
1107
  recordLocalHookDrop(rawEventTokens);
1085
- writeDefaultHookOutput(isAntigravity, rawEventName);
1108
+ writeDefaultHookOutput(isGeminiHook, rawEventName);
1086
1109
  return;
1087
1110
  }
1088
1111
 
1089
1112
  if (!opts.apiKey) {
1090
1113
  recordLocalHookDrop(rawEventTokens);
1091
- writeDefaultHookOutput(isAntigravity, rawEventName);
1114
+ writeDefaultHookOutput(isGeminiHook, rawEventName);
1092
1115
  return;
1093
1116
  }
1094
1117
 
@@ -1101,20 +1124,23 @@ async function runAmbientHookMode(opts) {
1101
1124
  if (!dedupState.whispered_blocks_by_session || typeof dedupState.whispered_blocks_by_session !== "object") {
1102
1125
  dedupState.whispered_blocks_by_session = {};
1103
1126
  }
1127
+ const whisperKey = sessionKey || scopeStateKey;
1104
1128
  const isMidTurnContinuation =
1105
1129
  rawEventName === "PreInvocation" && Number(payload.invocationNum || 1) > 1;
1106
- if (hookEvent === "UserPromptSubmit" && !isMidTurnContinuation && sessionKey) {
1107
- dedupState.whispered_by_session[sessionKey] = [];
1108
- dedupState.whispered_blocks_by_session[sessionKey] = [];
1130
+ if (hookEvent === "UserPromptSubmit" && !isMidTurnContinuation && whisperKey) {
1131
+ dedupState.whispered_by_session[whisperKey] = [];
1132
+ dedupState.whispered_blocks_by_session[whisperKey] = [];
1109
1133
  }
1110
- const transcriptWhispered = extractWhisperedContextFromCurrentTurn(payload.transcriptPath);
1134
+ const transcriptWhispered = extractWhisperedContextFromCurrentTurn(
1135
+ payload.transcriptPath || payload.transcript_path
1136
+ );
1111
1137
  const sessionWhispered =
1112
- sessionKey && Array.isArray(dedupState.whispered_by_session[sessionKey])
1113
- ? dedupState.whispered_by_session[sessionKey]
1138
+ whisperKey && Array.isArray(dedupState.whispered_by_session[whisperKey])
1139
+ ? dedupState.whispered_by_session[whisperKey]
1114
1140
  : [];
1115
1141
  const sessionWhisperedBlocks =
1116
- sessionKey && Array.isArray(dedupState.whispered_blocks_by_session[sessionKey])
1117
- ? dedupState.whispered_blocks_by_session[sessionKey]
1142
+ whisperKey && Array.isArray(dedupState.whispered_blocks_by_session[whisperKey])
1143
+ ? dedupState.whispered_blocks_by_session[whisperKey]
1118
1144
  : [];
1119
1145
  const whisperedMemoryIds = Array.from(new Set([...transcriptWhispered.ids, ...sessionWhispered]));
1120
1146
  const whisperedBlocks = Array.from(new Set([...transcriptWhispered.blocks, ...sessionWhisperedBlocks]));
@@ -1147,6 +1173,12 @@ async function runAmbientHookMode(opts) {
1147
1173
  hook_event_name: hookEvent,
1148
1174
  prompt: payload.prompt || payload.lastUserInput || deltaText,
1149
1175
  text: streamTextForIntervene,
1176
+ ...(hookEvent === "Stop"
1177
+ ? {
1178
+ last_assistant_message: deltaText,
1179
+ stop_hook_active: Boolean(payload.stop_hook_active),
1180
+ }
1181
+ : {}),
1150
1182
  tool_name: toolName,
1151
1183
  tool_input: effectiveToolIn,
1152
1184
  tool_response: payload.tool_response || payload.toolResponse || null,
@@ -1179,22 +1211,26 @@ async function runAmbientHookMode(opts) {
1179
1211
  }
1180
1212
  if (resp.should_intervene) {
1181
1213
  telem.amnesia_episodes_intercepted = (telem.amnesia_episodes_intercepted || 0) + 1;
1182
- if (sessionKey && resp.triggered_memory_id) {
1183
- const prev = Array.isArray(dedupState.whispered_by_session[sessionKey])
1184
- ? dedupState.whispered_by_session[sessionKey]
1214
+ const triggeredIds = [
1215
+ ...(Array.isArray(resp.violated_memory_ids) ? resp.violated_memory_ids : []),
1216
+ ...(resp.violated_memory_id ? [resp.violated_memory_id] : []),
1217
+ ...(resp.triggered_memory_id ? [resp.triggered_memory_id] : []),
1218
+ ].filter(Boolean);
1219
+ if (whisperKey && triggeredIds.length > 0) {
1220
+ const prev = Array.isArray(dedupState.whispered_by_session[whisperKey])
1221
+ ? dedupState.whispered_by_session[whisperKey]
1185
1222
  : [];
1186
- if (!prev.includes(resp.triggered_memory_id)) {
1187
- dedupState.whispered_by_session[sessionKey] = [...prev.slice(-15), resp.triggered_memory_id];
1188
- }
1223
+ const merged = Array.from(new Set([...prev, ...triggeredIds]));
1224
+ dedupState.whispered_by_session[whisperKey] = merged.slice(-16);
1189
1225
  }
1190
- if (sessionKey && resp.intervention_message) {
1226
+ if (whisperKey && resp.intervention_message) {
1191
1227
  const msgTags = String(resp.intervention_message).match(/<memory>[\s\S]*?<\/memory>/gi);
1192
1228
  if (msgTags) {
1193
- const prevBlocks = Array.isArray(dedupState.whispered_blocks_by_session[sessionKey])
1194
- ? dedupState.whispered_blocks_by_session[sessionKey]
1229
+ const prevBlocks = Array.isArray(dedupState.whispered_blocks_by_session[whisperKey])
1230
+ ? dedupState.whispered_blocks_by_session[whisperKey]
1195
1231
  : [];
1196
1232
  const nextBlocks = Array.from(new Set([...prevBlocks, ...msgTags.map((t) => t.trim())]));
1197
- dedupState.whispered_blocks_by_session[sessionKey] = nextBlocks.slice(-8);
1233
+ dedupState.whispered_blocks_by_session[whisperKey] = nextBlocks.slice(-8);
1198
1234
  }
1199
1235
  }
1200
1236
  }
@@ -1215,7 +1251,7 @@ async function runAmbientHookMode(opts) {
1215
1251
  saveHookTelemetry(telem);
1216
1252
 
1217
1253
  let out = {};
1218
- if (isAntigravity) {
1254
+ if (isGeminiHook) {
1219
1255
  if (rawEventName === "PreInvocation") {
1220
1256
  if (resp && resp.should_intervene && resp.intervention_message) {
1221
1257
  out = {
@@ -1261,7 +1297,7 @@ async function runAmbientHookMode(opts) {
1261
1297
  process.stdout.write(JSON.stringify(out) + "\n");
1262
1298
  } catch {
1263
1299
  // Fail-open on network errors so the IDE is never blocked
1264
- writeDefaultHookOutput(isAntigravity, rawEventName);
1300
+ writeDefaultHookOutput(isGeminiHook, rawEventName);
1265
1301
  }
1266
1302
  }
1267
1303
 
package/dist/index.d.ts CHANGED
@@ -65,6 +65,12 @@ export interface InterveneOptions {
65
65
  hookEventName?: string;
66
66
  prompt?: string;
67
67
  text?: string;
68
+ last_assistant_message?: string | null;
69
+ lastAssistantMessage?: string | null;
70
+ stop_hook_active?: boolean;
71
+ stopHookActive?: boolean;
72
+ whispered_memory_ids?: string[] | null;
73
+ whisperedMemoryIds?: string[] | null;
68
74
  tool_name?: string | null;
69
75
  toolName?: string | null;
70
76
  tool_input?: Record<string, unknown> | null;
package/dist/index.js CHANGED
@@ -182,7 +182,7 @@ class MemoryClient {
182
182
  const headers = {
183
183
  Accept: "application/json",
184
184
  "Content-Type": "application/json",
185
- "User-Agent": "slashml-memory-ts/1.0.0",
185
+ "User-Agent": "slashml-memory-ts/1.0.6",
186
186
  };
187
187
  if (this.apiKey) {
188
188
  headers.Authorization = `Bearer ${this.apiKey}`;
@@ -279,11 +279,20 @@ class MemoryClient {
279
279
  const resolvedModel = opts.model ?? this.model;
280
280
  const resolvedProjectId = opts.project_id ?? opts.projectId ?? this.projectId ?? null;
281
281
  const resolvedSessionId = opts.session_id ?? opts.sessionId ?? null;
282
+ const lastAssistantMsg =
283
+ opts.last_assistant_message ?? opts.lastAssistantMessage ?? undefined;
284
+ const stopHookActive =
285
+ opts.stop_hook_active ?? opts.stopHookActive ?? undefined;
286
+ const whisperedIds =
287
+ opts.whispered_memory_ids ?? opts.whisperedMemoryIds ?? undefined;
282
288
  return this.request("POST", "/v1/memory/intervene", {
283
289
  jsonBody: {
284
290
  hook_event_name: opts.hook_event_name ?? opts.hookEventName ?? "UserPromptSubmit",
285
291
  prompt: opts.prompt ?? resolvedText,
286
292
  text: resolvedText,
293
+ ...(lastAssistantMsg !== undefined ? { last_assistant_message: lastAssistantMsg } : {}),
294
+ ...(stopHookActive !== undefined ? { stop_hook_active: Boolean(stopHookActive) } : {}),
295
+ ...(whisperedIds && whisperedIds.length > 0 ? { whispered_memory_ids: whisperedIds } : {}),
287
296
  tool_name: opts.tool_name ?? opts.toolName ?? null,
288
297
  tool_input: opts.tool_input ?? opts.toolInput ?? null,
289
298
  tool_response: opts.tool_response ?? opts.toolResponse ?? null,
package/dist/index.mjs CHANGED
@@ -184,7 +184,7 @@ export class MemoryClient {
184
184
  const headers = {
185
185
  Accept: "application/json",
186
186
  "Content-Type": "application/json",
187
- "User-Agent": "slashml-memory-ts/1.0.0",
187
+ "User-Agent": "slashml-memory-ts/1.0.6",
188
188
  };
189
189
  if (this.apiKey) {
190
190
  headers.Authorization = `Bearer ${this.apiKey}`;
@@ -281,11 +281,20 @@ export class MemoryClient {
281
281
  const resolvedModel = opts.model ?? this.model;
282
282
  const resolvedProjectId = opts.project_id ?? opts.projectId ?? this.projectId ?? null;
283
283
  const resolvedSessionId = opts.session_id ?? opts.sessionId ?? null;
284
+ const lastAssistantMsg =
285
+ opts.last_assistant_message ?? opts.lastAssistantMessage ?? undefined;
286
+ const stopHookActive =
287
+ opts.stop_hook_active ?? opts.stopHookActive ?? undefined;
288
+ const whisperedIds =
289
+ opts.whispered_memory_ids ?? opts.whisperedMemoryIds ?? undefined;
284
290
  return this.request("POST", "/v1/memory/intervene", {
285
291
  jsonBody: {
286
292
  hook_event_name: opts.hook_event_name ?? opts.hookEventName ?? "UserPromptSubmit",
287
293
  prompt: opts.prompt ?? resolvedText,
288
294
  text: resolvedText,
295
+ ...(lastAssistantMsg !== undefined ? { last_assistant_message: lastAssistantMsg } : {}),
296
+ ...(stopHookActive !== undefined ? { stop_hook_active: Boolean(stopHookActive) } : {}),
297
+ ...(whisperedIds && whisperedIds.length > 0 ? { whispered_memory_ids: whisperedIds } : {}),
289
298
  tool_name: opts.tool_name ?? opts.toolName ?? null,
290
299
  tool_input: opts.tool_input ?? opts.toolInput ?? null,
291
300
  tool_response: opts.tool_response ?? opts.toolResponse ?? null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slashml/memory",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "/ ml (SlashML): Sub-Millisecond Stateful Agent & Code Memory SDK for TypeScript & Node.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://slashml.ai",
package/src/index.ts CHANGED
@@ -72,6 +72,12 @@ export interface InterveneOptions {
72
72
  hookEventName?: string;
73
73
  prompt?: string;
74
74
  text?: string;
75
+ last_assistant_message?: string | null;
76
+ lastAssistantMessage?: string | null;
77
+ stop_hook_active?: boolean;
78
+ stopHookActive?: boolean;
79
+ whispered_memory_ids?: string[] | null;
80
+ whisperedMemoryIds?: string[] | null;
75
81
  tool_name?: string | null;
76
82
  toolName?: string | null;
77
83
  tool_input?: Record<string, unknown> | null;
@@ -324,7 +330,7 @@ export class MemoryClient {
324
330
  const headers: Record<string, string> = {
325
331
  Accept: "application/json",
326
332
  "Content-Type": "application/json",
327
- "User-Agent": "slashml-memory-ts/1.0.0",
333
+ "User-Agent": "slashml-memory-ts/1.0.6",
328
334
  };
329
335
  if (this.apiKey) {
330
336
  headers.Authorization = `Bearer ${this.apiKey}`;
@@ -437,11 +443,20 @@ export class MemoryClient {
437
443
  const resolvedModel = opts.model ?? this.model;
438
444
  const resolvedProjectId = opts.project_id ?? opts.projectId ?? this.projectId ?? null;
439
445
  const resolvedSessionId = opts.session_id ?? opts.sessionId ?? null;
446
+ const lastAssistantMsg =
447
+ opts.last_assistant_message ?? opts.lastAssistantMessage ?? undefined;
448
+ const stopHookActive =
449
+ opts.stop_hook_active ?? opts.stopHookActive ?? undefined;
450
+ const whisperedIds =
451
+ opts.whispered_memory_ids ?? opts.whisperedMemoryIds ?? undefined;
440
452
  return this.request("POST", "/v1/memory/intervene", {
441
453
  jsonBody: {
442
454
  hook_event_name: opts.hook_event_name ?? opts.hookEventName ?? "UserPromptSubmit",
443
455
  prompt: opts.prompt ?? resolvedText,
444
456
  text: resolvedText,
457
+ ...(lastAssistantMsg !== undefined ? { last_assistant_message: lastAssistantMsg } : {}),
458
+ ...(stopHookActive !== undefined ? { stop_hook_active: Boolean(stopHookActive) } : {}),
459
+ ...(whisperedIds && whisperedIds.length > 0 ? { whispered_memory_ids: whisperedIds } : {}),
445
460
  tool_name: opts.tool_name ?? opts.toolName ?? null,
446
461
  tool_input: opts.tool_input ?? opts.toolInput ?? null,
447
462
  tool_response: opts.tool_response ?? opts.toolResponse ?? null,