@slashml/memory 1.0.12 → 1.0.14
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/README.md +29 -1
- package/bin/cli.js +362 -76
- package/dist/index.d.ts +188 -6
- package/dist/index.js +439 -76
- package/dist/index.mjs +1 -0
- package/package.json +2 -2
- package/src/index.ts +727 -89
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.14";
|
|
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)
|
|
@@ -30,6 +31,9 @@ Options:
|
|
|
30
31
|
--api-key <key> SlashML API key (or set SLASHML_API_KEY env var)
|
|
31
32
|
--workspace, --repo <path> Optional workspace directory to scope/index (defaults to process.cwd() at runtime)
|
|
32
33
|
--user-id <id> Default user/workspace namespace (default: SLASHML_USER_ID or "default")
|
|
34
|
+
--agent-id <id> Caller agent identity for per-agent access & redaction policies (or SLASHML_AGENT_ID)
|
|
35
|
+
--redact-policy <policy> Default redaction preset or comma-separated buckets (or SLASHML_REDACT_POLICY)
|
|
36
|
+
--redact-scope <scope> Default redaction scope: memorize_and_recall | recall_only (or SLASHML_REDACT_SCOPE)
|
|
33
37
|
--code-only Expose only code & bug-localization MCP tools
|
|
34
38
|
--code-mode Expose compact single meta-tool (execute_memory_code)
|
|
35
39
|
--init Write ml-memory MCP entry to Cursor, Windsurf, or .mcp.json
|
|
@@ -182,6 +186,9 @@ function parseCliArgs(argv) {
|
|
|
182
186
|
let baseUrl = (process.env.SLASHML_BASE_URL || DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
183
187
|
let consoleUrl = (process.env.SLASHML_CONSOLE_URL || DEFAULT_CONSOLE_URL).replace(/\/+$/, "");
|
|
184
188
|
let userId = process.env.SLASHML_USER_ID || "default";
|
|
189
|
+
let agentId = (process.env.SLASHML_AGENT_ID || "").trim() || null;
|
|
190
|
+
let redactPolicy = (process.env.SLASHML_REDACT_POLICY || "").trim() || null;
|
|
191
|
+
let redactScope = (process.env.SLASHML_REDACT_SCOPE || "").trim() || null;
|
|
185
192
|
let codeOnly = false;
|
|
186
193
|
let codeMode = false;
|
|
187
194
|
let passiveWrites = process.env.SLASHML_PASSIVE_WRITES === "1";
|
|
@@ -268,6 +275,12 @@ function parseCliArgs(argv) {
|
|
|
268
275
|
consoleUrl = argv[++i].replace(/\/+$/, "");
|
|
269
276
|
} else if (arg === "--user-id" && i + 1 < argv.length) {
|
|
270
277
|
userId = argv[++i];
|
|
278
|
+
} else if (arg === "--agent-id" && i + 1 < argv.length) {
|
|
279
|
+
agentId = argv[++i].trim() || null;
|
|
280
|
+
} else if (arg === "--redact-policy" && i + 1 < argv.length) {
|
|
281
|
+
redactPolicy = argv[++i].trim() || null;
|
|
282
|
+
} else if (arg === "--redact-scope" && i + 1 < argv.length) {
|
|
283
|
+
redactScope = argv[++i].trim() || null;
|
|
271
284
|
} else if ((arg === "--repo" || arg === "--workspace") && i + 1 < argv.length) {
|
|
272
285
|
repo = argv[++i];
|
|
273
286
|
} else if (arg === "--signup" && i + 1 < argv.length) {
|
|
@@ -301,6 +314,9 @@ function parseCliArgs(argv) {
|
|
|
301
314
|
baseUrl,
|
|
302
315
|
consoleUrl,
|
|
303
316
|
userId,
|
|
317
|
+
agentId,
|
|
318
|
+
redactPolicy,
|
|
319
|
+
redactScope,
|
|
304
320
|
codeOnly,
|
|
305
321
|
codeMode,
|
|
306
322
|
passiveWrites,
|
|
@@ -365,7 +381,7 @@ function saveApiKeyToEnvFile(apiKey, cwd = process.cwd()) {
|
|
|
365
381
|
|
|
366
382
|
const GENERIC_SKILL_NAMES = new Set(["ml-memory", "/ml-memory", "slashml", "all", "default"]);
|
|
367
383
|
|
|
368
|
-
function nativeNodeInit(skill, apiKey, repo = null, writeEnv = false) {
|
|
384
|
+
function nativeNodeInit(skill, apiKey, repo = null, writeEnv = false, extraEnv = {}) {
|
|
369
385
|
const home = os.homedir();
|
|
370
386
|
const cwd = process.cwd();
|
|
371
387
|
const targets = [
|
|
@@ -397,10 +413,21 @@ function nativeNodeInit(skill, apiKey, repo = null, writeEnv = false) {
|
|
|
397
413
|
args,
|
|
398
414
|
};
|
|
399
415
|
const resolvedKey = apiKey || process.env.SLASHML_API_KEY;
|
|
416
|
+
const envMap = {};
|
|
400
417
|
if (resolvedKey) {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
418
|
+
envMap.SLASHML_API_KEY = resolvedKey;
|
|
419
|
+
}
|
|
420
|
+
if (extraEnv.agentId) {
|
|
421
|
+
envMap.SLASHML_AGENT_ID = extraEnv.agentId;
|
|
422
|
+
}
|
|
423
|
+
if (extraEnv.redactPolicy) {
|
|
424
|
+
envMap.SLASHML_REDACT_POLICY = extraEnv.redactPolicy;
|
|
425
|
+
}
|
|
426
|
+
if (extraEnv.redactScope) {
|
|
427
|
+
envMap.SLASHML_REDACT_SCOPE = extraEnv.redactScope;
|
|
428
|
+
}
|
|
429
|
+
if (Object.keys(envMap).length > 0) {
|
|
430
|
+
serverEntry.env = envMap;
|
|
404
431
|
}
|
|
405
432
|
if (writeEnv && resolvedKey) {
|
|
406
433
|
saveApiKeyToEnvFile(resolvedKey, cwd);
|
|
@@ -497,7 +524,11 @@ async function runCliVerify(email, code, parsedArgs) {
|
|
|
497
524
|
envSavedPath = path.join(process.cwd(), ".env");
|
|
498
525
|
}
|
|
499
526
|
if (parsedArgs.isInit) {
|
|
500
|
-
nativeNodeInit(parsedArgs.skill, provisionedKey, parsedArgs.repo, false
|
|
527
|
+
nativeNodeInit(parsedArgs.skill, provisionedKey, parsedArgs.repo, false, {
|
|
528
|
+
agentId: parsedArgs.agentId,
|
|
529
|
+
redactPolicy: parsedArgs.redactPolicy,
|
|
530
|
+
redactScope: parsedArgs.redactScope,
|
|
531
|
+
});
|
|
501
532
|
}
|
|
502
533
|
console.log(
|
|
503
534
|
JSON.stringify({
|
|
@@ -543,7 +574,11 @@ if (parsed.verifyEmail) {
|
|
|
543
574
|
}
|
|
544
575
|
|
|
545
576
|
if (parsed.isInit) {
|
|
546
|
-
nativeNodeInit(parsed.skill, parsed.apiKey, parsed.repo, parsed.writeEnv
|
|
577
|
+
nativeNodeInit(parsed.skill, parsed.apiKey, parsed.repo, parsed.writeEnv, {
|
|
578
|
+
agentId: parsed.agentId,
|
|
579
|
+
redactPolicy: parsed.redactPolicy,
|
|
580
|
+
redactScope: parsed.redactScope,
|
|
581
|
+
});
|
|
547
582
|
if (process.env.SLASHML_DISABLE_AUTO_HOOKS !== "1") {
|
|
548
583
|
try {
|
|
549
584
|
installAmbientHooks(parsed.apiKey, { quiet: false, onlyIfDirExists: false });
|
|
@@ -781,7 +816,7 @@ function installAmbientHooks(apiKey, opts = {}) {
|
|
|
781
816
|
}
|
|
782
817
|
}
|
|
783
818
|
|
|
784
|
-
// 5. Gemini CLI
|
|
819
|
+
// 5. Gemini CLI (~/.gemini/config/plugins/slashml-memory + ~/.gemini/GEMINI.md)
|
|
785
820
|
const geminiConfigDir = path.join(home, ".gemini", "config");
|
|
786
821
|
const geminiPluginsRoot = path.join(geminiConfigDir, "plugins");
|
|
787
822
|
let geminiPluginDir = path.join(geminiPluginsRoot, "slashml-memory");
|
|
@@ -1208,6 +1243,22 @@ async function runStatusCommand(opts) {
|
|
|
1208
1243
|
noiseFilteredPct = Number((Math.max(tokRatio, evRatio) * 100.0).toFixed(1));
|
|
1209
1244
|
}
|
|
1210
1245
|
|
|
1246
|
+
const objectionsRepeatSuppressed = Number(
|
|
1247
|
+
(serverStatus && serverStatus.objections_repeat_suppressed) || 0
|
|
1248
|
+
);
|
|
1249
|
+
const objectionsChainedBlocks = Number(
|
|
1250
|
+
(serverStatus && serverStatus.objections_chained_distinct_blocks) || 0
|
|
1251
|
+
);
|
|
1252
|
+
const objectionsResolvedOnRetry = Number(
|
|
1253
|
+
(serverStatus && serverStatus.objections_resolved_on_retry) || 0
|
|
1254
|
+
);
|
|
1255
|
+
const memoriesAutoDowngraded = Number(
|
|
1256
|
+
(serverStatus && serverStatus.memories_auto_downgraded) || 0
|
|
1257
|
+
);
|
|
1258
|
+
const flaggedNoisyMemories = Array.isArray(serverStatus && serverStatus.flagged_noisy_memories)
|
|
1259
|
+
? serverStatus.flagged_noisy_memories
|
|
1260
|
+
: [];
|
|
1261
|
+
|
|
1211
1262
|
const summaryLine =
|
|
1212
1263
|
(serverStatus && serverStatus.summary_line) ||
|
|
1213
1264
|
`${memoriesAssimilated} rules learned passively • ${amnesiaIntercepted} amnesia episodes intercepted • ${Math.round(noiseFilteredPct)}% stream noise filtered`;
|
|
@@ -1217,6 +1268,11 @@ async function runStatusCommand(opts) {
|
|
|
1217
1268
|
memories_assimilated: memoriesAssimilated,
|
|
1218
1269
|
memories_superseded: memoriesSuperseded,
|
|
1219
1270
|
amnesia_episodes_intercepted: amnesiaIntercepted,
|
|
1271
|
+
objections_chained_distinct_blocks: objectionsChainedBlocks,
|
|
1272
|
+
objections_repeat_suppressed: objectionsRepeatSuppressed,
|
|
1273
|
+
objections_resolved_on_retry: objectionsResolvedOnRetry,
|
|
1274
|
+
memories_auto_downgraded: memoriesAutoDowngraded,
|
|
1275
|
+
flagged_noisy_memories: flaggedNoisyMemories,
|
|
1220
1276
|
events_processed: eventsProcessed,
|
|
1221
1277
|
events_filtered_noise: eventsFiltered,
|
|
1222
1278
|
summary_line: summaryLine,
|
|
@@ -1237,6 +1293,18 @@ async function runStatusCommand(opts) {
|
|
|
1237
1293
|
` # New Memories Assimilated : ${memoriesAssimilated}${memoriesSuperseded > 0 ? ` (${memoriesSuperseded} superseded)` : ""}`
|
|
1238
1294
|
);
|
|
1239
1295
|
console.log(` # Amnesia Episodes Intercepted : ${amnesiaIntercepted}`);
|
|
1296
|
+
if (
|
|
1297
|
+
objectionsRepeatSuppressed > 0 ||
|
|
1298
|
+
objectionsResolvedOnRetry > 0 ||
|
|
1299
|
+
memoriesAutoDowngraded > 0
|
|
1300
|
+
) {
|
|
1301
|
+
console.log(
|
|
1302
|
+
` # Objections Resolved on Retry : ${objectionsResolvedOnRetry}${objectionsChainedBlocks > 0 ? ` (${objectionsChainedBlocks} chained distinct)` : ""}`
|
|
1303
|
+
);
|
|
1304
|
+
console.log(
|
|
1305
|
+
` # Repeat Objections Suppressed : ${objectionsRepeatSuppressed}${memoriesAutoDowngraded > 0 ? ` (${memoriesAutoDowngraded} noisy memories auto-downgraded)` : ""}`
|
|
1306
|
+
);
|
|
1307
|
+
}
|
|
1240
1308
|
}
|
|
1241
1309
|
|
|
1242
1310
|
function extractLastPlannerResponseFromTranscript(transcriptPath) {
|
|
@@ -1437,7 +1505,9 @@ async function runAmbientHookMode(opts) {
|
|
|
1437
1505
|
payload.terminationReason !== undefined ||
|
|
1438
1506
|
payload.workspacePaths !== undefined ||
|
|
1439
1507
|
payload.artifactDirectoryPath !== undefined ||
|
|
1440
|
-
payload.conversationId !== undefined
|
|
1508
|
+
payload.conversationId !== undefined ||
|
|
1509
|
+
(payload.conversation_id !== undefined &&
|
|
1510
|
+
(cliEvent === "Stop" || payload.transcript_path !== undefined))
|
|
1441
1511
|
);
|
|
1442
1512
|
|
|
1443
1513
|
let rawEventName = String(
|
|
@@ -1495,8 +1565,8 @@ async function runAmbientHookMode(opts) {
|
|
|
1495
1565
|
}
|
|
1496
1566
|
}
|
|
1497
1567
|
|
|
1498
|
-
//
|
|
1499
|
-
if (
|
|
1568
|
+
// Enforce hard 3-retry safety ceiling locally if harness passes an explicit loop_count >= 3
|
|
1569
|
+
if (hookEvent === "Stop" && Number(payload.loop_count || 0) >= MAX_STOP_BLOCKS_PER_PROMPT) {
|
|
1500
1570
|
writeDefaultHookOutput(isGeminiHook, rawEventName, isCursorHook);
|
|
1501
1571
|
return;
|
|
1502
1572
|
}
|
|
@@ -1692,6 +1762,30 @@ async function runAmbientHookMode(opts) {
|
|
|
1692
1762
|
.trim()
|
|
1693
1763
|
.slice(0, 1024);
|
|
1694
1764
|
|
|
1765
|
+
const whisperKey = sessionKey || scopeStateKey;
|
|
1766
|
+
const isMidTurnContinuation =
|
|
1767
|
+
rawEventName === "PreInvocation" &&
|
|
1768
|
+
(Number(payload.invocationNum || 1) > 1 || Number(payload.executionNum || 1) > 1);
|
|
1769
|
+
if (!dedupState.stop_turn_by_session || typeof dedupState.stop_turn_by_session !== "object") {
|
|
1770
|
+
dedupState.stop_turn_by_session = {};
|
|
1771
|
+
}
|
|
1772
|
+
if (hookEvent === "UserPromptSubmit" && !isMidTurnContinuation && whisperKey) {
|
|
1773
|
+
const existingStopTurn = dedupState.stop_turn_by_session[whisperKey];
|
|
1774
|
+
if (
|
|
1775
|
+
existingStopTurn &&
|
|
1776
|
+
((Array.isArray(existingStopTurn.blocked_ids) && existingStopTurn.blocked_ids.length > 0) ||
|
|
1777
|
+
Number(existingStopTurn.retry_count || 0) > 0)
|
|
1778
|
+
) {
|
|
1779
|
+
dedupState.stop_turn_by_session[whisperKey] = { blocked_ids: [], retry_count: 0 };
|
|
1780
|
+
try {
|
|
1781
|
+
fs.mkdirSync(path.dirname(dedupPath), { recursive: true });
|
|
1782
|
+
fs.writeFileSync(dedupPath, JSON.stringify(dedupState), "utf8");
|
|
1783
|
+
} catch {
|
|
1784
|
+
// ignore state persistence errors
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1695
1789
|
if (
|
|
1696
1790
|
!deltaText ||
|
|
1697
1791
|
deltaText.length < 4 ||
|
|
@@ -1702,6 +1796,21 @@ async function runAmbientHookMode(opts) {
|
|
|
1702
1796
|
return;
|
|
1703
1797
|
}
|
|
1704
1798
|
|
|
1799
|
+
const activeStopTurn =
|
|
1800
|
+
whisperKey &&
|
|
1801
|
+
dedupState.stop_turn_by_session[whisperKey] &&
|
|
1802
|
+
typeof dedupState.stop_turn_by_session[whisperKey] === "object"
|
|
1803
|
+
? dedupState.stop_turn_by_session[whisperKey]
|
|
1804
|
+
: { blocked_ids: [], retry_count: 0 };
|
|
1805
|
+
const turnBlockedIds = Array.isArray(activeStopTurn.blocked_ids)
|
|
1806
|
+
? activeStopTurn.blocked_ids.map(String).filter(Boolean)
|
|
1807
|
+
: [];
|
|
1808
|
+
const turnStopRetries = Number(activeStopTurn.retry_count || 0);
|
|
1809
|
+
if (hookEvent === "Stop" && turnStopRetries >= MAX_STOP_BLOCKS_PER_PROMPT) {
|
|
1810
|
+
writeDefaultHookOutput(isGeminiHook, rawEventName, isCursorHook);
|
|
1811
|
+
return;
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1705
1814
|
// Event deduplication (scoped to project/session/step and only persisted for non-actionable noise)
|
|
1706
1815
|
const stepKey = String(
|
|
1707
1816
|
payload.stepIdx ?? payload.invocationNum ?? payload.executionNum ?? ""
|
|
@@ -1743,9 +1852,6 @@ async function runAmbientHookMode(opts) {
|
|
|
1743
1852
|
if (!dedupState.blocked_actions_by_session || typeof dedupState.blocked_actions_by_session !== "object") {
|
|
1744
1853
|
dedupState.blocked_actions_by_session = {};
|
|
1745
1854
|
}
|
|
1746
|
-
const whisperKey = sessionKey || scopeStateKey;
|
|
1747
|
-
const isMidTurnContinuation =
|
|
1748
|
-
rawEventName === "PreInvocation" && Number(payload.invocationNum || 1) > 1;
|
|
1749
1855
|
const targetSig = toolIn
|
|
1750
1856
|
? String(
|
|
1751
1857
|
toolIn.file_path ||
|
|
@@ -1838,8 +1944,11 @@ async function runAmbientHookMode(opts) {
|
|
|
1838
1944
|
? {
|
|
1839
1945
|
last_assistant_message: deltaText,
|
|
1840
1946
|
stop_hook_active: Boolean(payload.stop_hook_active),
|
|
1947
|
+
turn_blocked_memory_ids: turnBlockedIds,
|
|
1948
|
+
stop_retry_count: turnStopRetries,
|
|
1841
1949
|
}
|
|
1842
1950
|
: {}),
|
|
1951
|
+
...(isMidTurnContinuation ? { is_mid_turn_continuation: true } : {}),
|
|
1843
1952
|
tool_name: toolName,
|
|
1844
1953
|
tool_input: effectiveToolIn,
|
|
1845
1954
|
tool_response: payload.tool_response || payload.toolResponse || null,
|
|
@@ -1849,11 +1958,49 @@ async function runAmbientHookMode(opts) {
|
|
|
1849
1958
|
model: process.env.SLASHML_MODEL || undefined,
|
|
1850
1959
|
user_id: opts.userId,
|
|
1851
1960
|
...(projectId ? { project_id: projectId } : {}),
|
|
1852
|
-
|
|
1961
|
+
session_id: whisperKey,
|
|
1962
|
+
...(opts.redactPolicy ? { redact_policy: opts.redactPolicy } : {}),
|
|
1963
|
+
...(opts.redactScope ? { redact_scope: opts.redactScope } : {}),
|
|
1964
|
+
...(opts.agentId ? { caller_agent_id: opts.agentId } : {}),
|
|
1853
1965
|
client_raw_tokens_delta: (telem.pending_raw_tokens_delta || 0) + strippedTokens,
|
|
1854
1966
|
client_dropped_tokens_delta: (telem.pending_dropped_tokens_delta || 0) + strippedTokens,
|
|
1855
1967
|
client_dropped_events_delta: telem.pending_dropped_events_delta || 0,
|
|
1856
1968
|
});
|
|
1969
|
+
// Client-side per-memory Stop circuit breaker (defense-in-depth across server restarts/versions):
|
|
1970
|
+
// at most 1 Stop block per memory_id per user prompt, and at most MAX_STOP_BLOCKS_PER_PROMPT total.
|
|
1971
|
+
if (
|
|
1972
|
+
hookEvent === "Stop" &&
|
|
1973
|
+
resp &&
|
|
1974
|
+
resp.should_intervene &&
|
|
1975
|
+
(resp.intervention_severity === "BLOCK" || resp.action === "BLOCK")
|
|
1976
|
+
) {
|
|
1977
|
+
const respTriggered = Array.from(
|
|
1978
|
+
new Set(
|
|
1979
|
+
[
|
|
1980
|
+
...(Array.isArray(resp.violated_memory_ids) ? resp.violated_memory_ids : []),
|
|
1981
|
+
...(resp.violated_memory_id ? [resp.violated_memory_id] : []),
|
|
1982
|
+
...(resp.triggered_memory_id ? [resp.triggered_memory_id] : []),
|
|
1983
|
+
]
|
|
1984
|
+
.map(String)
|
|
1985
|
+
.filter(Boolean)
|
|
1986
|
+
)
|
|
1987
|
+
);
|
|
1988
|
+
const novelStopIds = respTriggered.filter((id) => !turnBlockedIds.includes(id));
|
|
1989
|
+
if (
|
|
1990
|
+
turnStopRetries >= MAX_STOP_BLOCKS_PER_PROMPT ||
|
|
1991
|
+
(respTriggered.length > 0 && novelStopIds.length === 0)
|
|
1992
|
+
) {
|
|
1993
|
+
resp.should_intervene = false;
|
|
1994
|
+
resp.intervention_severity = "NONE";
|
|
1995
|
+
resp.intervention_message = null;
|
|
1996
|
+
resp.hook_output = {};
|
|
1997
|
+
} else if (whisperKey) {
|
|
1998
|
+
dedupState.stop_turn_by_session[whisperKey] = {
|
|
1999
|
+
blocked_ids: Array.from(new Set([...turnBlockedIds, ...novelStopIds])).slice(-16),
|
|
2000
|
+
retry_count: turnStopRetries + 1,
|
|
2001
|
+
};
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
1857
2004
|
telem.pending_raw_tokens_delta = 0;
|
|
1858
2005
|
telem.pending_dropped_tokens_delta = 0;
|
|
1859
2006
|
telem.pending_dropped_events_delta = 0;
|
|
@@ -1916,10 +2063,18 @@ async function runAmbientHookMode(opts) {
|
|
|
1916
2063
|
} else {
|
|
1917
2064
|
telem.noise_tokens_filtered = (telem.noise_tokens_filtered || 0) + rawEventTokens;
|
|
1918
2065
|
telem.events_filtered_noise = (telem.events_filtered_noise || 0) + 1;
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
2066
|
+
const wasRepeatSuppressed = Boolean(
|
|
2067
|
+
resp &&
|
|
2068
|
+
((Array.isArray(resp.repeat_suppressed_memory_ids) &&
|
|
2069
|
+
resp.repeat_suppressed_memory_ids.length > 0) ||
|
|
2070
|
+
resp.objection_outcome === "SAFETY_CEILING_SUPPRESSED")
|
|
2071
|
+
);
|
|
2072
|
+
if (!wasRepeatSuppressed && hookEvent !== "Stop" && hookEvent !== "PreToolUse") {
|
|
2073
|
+
dedupState.hashes = [
|
|
2074
|
+
...(Array.isArray(dedupState.hashes) ? dedupState.hashes.slice(-63) : []),
|
|
2075
|
+
deltaHash,
|
|
2076
|
+
];
|
|
2077
|
+
}
|
|
1923
2078
|
}
|
|
1924
2079
|
try {
|
|
1925
2080
|
fs.mkdirSync(path.dirname(dedupPath), { recursive: true });
|
|
@@ -2483,6 +2638,9 @@ async function scanSandboxTranscriptsOnce(opts, state) {
|
|
|
2483
2638
|
user_id: opts.userId || "default",
|
|
2484
2639
|
project_id: projectId,
|
|
2485
2640
|
session_id: sessionId,
|
|
2641
|
+
...(opts.redactPolicy ? { redact_policy: opts.redactPolicy } : {}),
|
|
2642
|
+
...(opts.redactScope ? { redact_scope: opts.redactScope } : {}),
|
|
2643
|
+
...(opts.agentId ? { caller_agent_id: opts.agentId } : {}),
|
|
2486
2644
|
});
|
|
2487
2645
|
processedEvents += 1;
|
|
2488
2646
|
telem.conversation_tokens_processed = (telem.conversation_tokens_processed || 0) + rawTok;
|
|
@@ -2684,10 +2842,34 @@ function makeMigrationDocId(prefix, text, userId = "default") {
|
|
|
2684
2842
|
return `mig_${prefix}_${digest}`;
|
|
2685
2843
|
}
|
|
2686
2844
|
|
|
2845
|
+
function stripCommentMarkerBlock(input, startSuffix, endSuffix) {
|
|
2846
|
+
let out = String(input || "");
|
|
2847
|
+
while (true) {
|
|
2848
|
+
const mid = out.indexOf(startSuffix);
|
|
2849
|
+
if (mid === -1) break;
|
|
2850
|
+
const blockStart = out.lastIndexOf("<!--", mid);
|
|
2851
|
+
if (blockStart === -1) break;
|
|
2852
|
+
const endMid = out.indexOf(endSuffix, mid + startSuffix.length);
|
|
2853
|
+
if (endMid === -1) break;
|
|
2854
|
+
const blockEnd = out.indexOf("-->", endMid + endSuffix.length);
|
|
2855
|
+
if (blockEnd === -1) break;
|
|
2856
|
+
out = out.slice(0, blockStart) + out.slice(blockEnd + 3);
|
|
2857
|
+
}
|
|
2858
|
+
return out;
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2687
2861
|
function stripSlashmlInjectedBlocks(rawMarkdown) {
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2862
|
+
const withoutRules = stripCommentMarkerBlock(
|
|
2863
|
+
rawMarkdown,
|
|
2864
|
+
"-MEMORY-RULE:START",
|
|
2865
|
+
"-MEMORY-RULE:END"
|
|
2866
|
+
);
|
|
2867
|
+
const withoutAmbient = stripCommentMarkerBlock(
|
|
2868
|
+
withoutRules,
|
|
2869
|
+
"SLASHML-AMBIENT-MEMORY:START",
|
|
2870
|
+
"SLASHML-AMBIENT-MEMORY:END"
|
|
2871
|
+
);
|
|
2872
|
+
return withoutAmbient
|
|
2691
2873
|
.replace(/^---[\r\n]+[\s\S]*?[\r\n]+---[\r\n]*/m, "")
|
|
2692
2874
|
.trim();
|
|
2693
2875
|
}
|
|
@@ -3437,15 +3619,43 @@ const STANDARD_TOOLS = [
|
|
|
3437
3619
|
},
|
|
3438
3620
|
{
|
|
3439
3621
|
name: "forget_memory",
|
|
3440
|
-
description: "Delete a specific memory by ID.",
|
|
3622
|
+
description: "Delete or permanently purge a specific memory by ID.",
|
|
3441
3623
|
inputSchema: {
|
|
3442
3624
|
type: "object",
|
|
3443
3625
|
properties: {
|
|
3444
3626
|
memory_id: { type: "string" },
|
|
3627
|
+
purge: {
|
|
3628
|
+
type: "boolean",
|
|
3629
|
+
description: "When true, irreversibly purges the memory and returns a bounded undo_token.",
|
|
3630
|
+
default: false,
|
|
3631
|
+
},
|
|
3632
|
+
reason: { type: "string" },
|
|
3445
3633
|
},
|
|
3446
3634
|
required: ["memory_id"],
|
|
3447
3635
|
},
|
|
3448
3636
|
},
|
|
3637
|
+
{
|
|
3638
|
+
name: "redact_memory",
|
|
3639
|
+
description:
|
|
3640
|
+
"Redact sensitive spans (secrets, PCI/financial, PII, PHI, commercial MNPI, legal/HR, security exploits) from raw text or an existing stored memory.",
|
|
3641
|
+
inputSchema: {
|
|
3642
|
+
type: "object",
|
|
3643
|
+
properties: {
|
|
3644
|
+
text: { type: "string", description: "Raw text to redact (when not redacting an existing memory_id)." },
|
|
3645
|
+
memory_id: { type: "string", description: "Optional stored memory ID to redact in place." },
|
|
3646
|
+
redact_policy: {
|
|
3647
|
+
oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }],
|
|
3648
|
+
description:
|
|
3649
|
+
"Preset ('tier1_secrets', 'soc2_coding', 'gdpr', 'hipaa', 'enterprise_strict') or array of bucket names.",
|
|
3650
|
+
},
|
|
3651
|
+
dry_run: {
|
|
3652
|
+
type: "boolean",
|
|
3653
|
+
description: "Preview redacted_text and redacted_spans without mutating stored memory.",
|
|
3654
|
+
default: false,
|
|
3655
|
+
},
|
|
3656
|
+
},
|
|
3657
|
+
},
|
|
3658
|
+
},
|
|
3449
3659
|
{
|
|
3450
3660
|
name: "dismiss_intervention",
|
|
3451
3661
|
description:
|
|
@@ -3521,7 +3731,7 @@ const CODE_MODE_TOOLS = [
|
|
|
3521
3731
|
{
|
|
3522
3732
|
name: "execute_memory_code",
|
|
3523
3733
|
description:
|
|
3524
|
-
"Compact meta-tool (91% token savings) dispatching memory & code actions (`add_memory`, `search_memories`, `get_memories`, `forget_memory`, `index_repository`, `search_code_by_behavior`, `find_bug_candidates`, `intervene_memory`) to `/ ml` Cloud.",
|
|
3734
|
+
"Compact meta-tool (91% token savings) dispatching memory & code actions (`add_memory`, `search_memories`, `get_memories`, `forget_memory`, `redact_memory`, `index_repository`, `search_code_by_behavior`, `find_bug_candidates`, `intervene_memory`) to `/ ml` Cloud.",
|
|
3525
3735
|
inputSchema: {
|
|
3526
3736
|
type: "object",
|
|
3527
3737
|
properties: {
|
|
@@ -3532,6 +3742,7 @@ const CODE_MODE_TOOLS = [
|
|
|
3532
3742
|
"search_memories",
|
|
3533
3743
|
"get_memories",
|
|
3534
3744
|
"forget_memory",
|
|
3745
|
+
"redact_memory",
|
|
3535
3746
|
"index_repository",
|
|
3536
3747
|
"search_code_by_behavior",
|
|
3537
3748
|
"find_bug_candidates",
|
|
@@ -3552,13 +3763,17 @@ async function apiRequest(opts, method, urlPath, body) {
|
|
|
3552
3763
|
"SlashML API key is required. Set SLASHML_API_KEY in your environment or pass --api-key."
|
|
3553
3764
|
);
|
|
3554
3765
|
}
|
|
3766
|
+
const headers = {
|
|
3767
|
+
Authorization: `Bearer ${opts.apiKey}`,
|
|
3768
|
+
"Content-Type": "application/json",
|
|
3769
|
+
"User-Agent": `slashml-cli-node/${PACKAGE_VERSION}`,
|
|
3770
|
+
};
|
|
3771
|
+
if (opts.agentId) {
|
|
3772
|
+
headers["X-SlashML-Agent-Id"] = opts.agentId;
|
|
3773
|
+
}
|
|
3555
3774
|
const res = await fetch(`${opts.baseUrl}${urlPath}`, {
|
|
3556
3775
|
method,
|
|
3557
|
-
headers
|
|
3558
|
-
Authorization: `Bearer ${opts.apiKey}`,
|
|
3559
|
-
"Content-Type": "application/json",
|
|
3560
|
-
"User-Agent": "slashml-cli-node/1.0.0",
|
|
3561
|
-
},
|
|
3776
|
+
headers,
|
|
3562
3777
|
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
3563
3778
|
});
|
|
3564
3779
|
const text = await res.text();
|
|
@@ -3722,6 +3937,16 @@ async function dispatchTool(opts, name, args = {}) {
|
|
|
3722
3937
|
return dispatchTool(opts, args.action, args.params || {});
|
|
3723
3938
|
}
|
|
3724
3939
|
const uid = args.user_id || opts.userId;
|
|
3940
|
+
const effRedactPolicy = args.redact_policy !== undefined ? args.redact_policy : opts.redactPolicy;
|
|
3941
|
+
const effRedactScope = args.redact_scope !== undefined ? args.redact_scope : opts.redactScope;
|
|
3942
|
+
const effAgentId = args.caller_agent_id || opts.agentId || null;
|
|
3943
|
+
|
|
3944
|
+
function withLifecycle(payload) {
|
|
3945
|
+
if (effRedactPolicy) payload.redact_policy = effRedactPolicy;
|
|
3946
|
+
if (effRedactScope) payload.redact_scope = effRedactScope;
|
|
3947
|
+
if (effAgentId) payload.caller_agent_id = effAgentId;
|
|
3948
|
+
return payload;
|
|
3949
|
+
}
|
|
3725
3950
|
|
|
3726
3951
|
if (name === "add_memory") {
|
|
3727
3952
|
const rawText = args.text !== undefined ? args.text : args.messages;
|
|
@@ -3735,12 +3960,17 @@ async function dispatchTool(opts, name, args = {}) {
|
|
|
3735
3960
|
...(args.metadata ? { metadata: args.metadata } : {}),
|
|
3736
3961
|
},
|
|
3737
3962
|
];
|
|
3738
|
-
return apiRequest(
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3963
|
+
return apiRequest(
|
|
3964
|
+
opts,
|
|
3965
|
+
"POST",
|
|
3966
|
+
"/v1/memories",
|
|
3967
|
+
withLifecycle({
|
|
3968
|
+
messages: messagesPayload,
|
|
3969
|
+
user_id: uid,
|
|
3970
|
+
memory_id: args.memory_id,
|
|
3971
|
+
metadata: args.metadata || {},
|
|
3972
|
+
})
|
|
3973
|
+
);
|
|
3744
3974
|
}
|
|
3745
3975
|
if (name === "search_memories") {
|
|
3746
3976
|
const k = Number(args.limit || args.top_k || 5);
|
|
@@ -3749,24 +3979,55 @@ async function dispatchTool(opts, name, args = {}) {
|
|
|
3749
3979
|
...(args.include_code !== undefined ? { include_code: Boolean(args.include_code) } : {}),
|
|
3750
3980
|
...(args.kind ? { kind: String(args.kind) } : {}),
|
|
3751
3981
|
};
|
|
3752
|
-
return apiRequest(
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3982
|
+
return apiRequest(
|
|
3983
|
+
opts,
|
|
3984
|
+
"POST",
|
|
3985
|
+
"/v1/memories/search",
|
|
3986
|
+
withLifecycle({
|
|
3987
|
+
query: args.query,
|
|
3988
|
+
user_id: uid,
|
|
3989
|
+
limit: k,
|
|
3990
|
+
top_k: k,
|
|
3991
|
+
...(Object.keys(mergedFilters).length > 0 ? { filters: mergedFilters } : {}),
|
|
3992
|
+
})
|
|
3993
|
+
);
|
|
3759
3994
|
}
|
|
3760
3995
|
if (name === "get_memories") {
|
|
3761
3996
|
const paramsObj = { user_id: uid, limit: String(args.limit || 50) };
|
|
3762
3997
|
if (args.include_code !== undefined) paramsObj.include_code = String(Boolean(args.include_code));
|
|
3763
3998
|
if (args.kind) paramsObj.kind = String(args.kind);
|
|
3999
|
+
if (effRedactPolicy) {
|
|
4000
|
+
paramsObj.redact_policy = Array.isArray(effRedactPolicy)
|
|
4001
|
+
? effRedactPolicy.join(",")
|
|
4002
|
+
: String(effRedactPolicy);
|
|
4003
|
+
}
|
|
4004
|
+
if (effRedactScope) paramsObj.redact_scope = String(effRedactScope);
|
|
3764
4005
|
const q = new URLSearchParams(paramsObj);
|
|
3765
4006
|
return apiRequest(opts, "GET", `/v1/memories?${q.toString()}`);
|
|
3766
4007
|
}
|
|
3767
4008
|
if (name === "forget_memory") {
|
|
4009
|
+
if (args.purge) {
|
|
4010
|
+
return apiRequest(
|
|
4011
|
+
opts,
|
|
4012
|
+
"POST",
|
|
4013
|
+
"/v1/memory/purge",
|
|
4014
|
+
withLifecycle({
|
|
4015
|
+
memory_ids: [String(args.memory_id)],
|
|
4016
|
+
...(args.reason ? { reason: String(args.reason) } : {}),
|
|
4017
|
+
...(args.dry_run !== undefined ? { dry_run: Boolean(args.dry_run) } : {}),
|
|
4018
|
+
})
|
|
4019
|
+
);
|
|
4020
|
+
}
|
|
3768
4021
|
return apiRequest(opts, "DELETE", `/v1/memories/${encodeURIComponent(args.memory_id)}`);
|
|
3769
4022
|
}
|
|
4023
|
+
if (name === "redact_memory" || name === "sanitize_memory") {
|
|
4024
|
+
const body = {};
|
|
4025
|
+
if (args.text !== undefined) body.text = String(args.text);
|
|
4026
|
+
if (args.memory_id) body.memory_id = String(args.memory_id);
|
|
4027
|
+
if (args.explicit_spans !== undefined) body.explicit_spans = args.explicit_spans;
|
|
4028
|
+
if (args.dry_run !== undefined) body.dry_run = Boolean(args.dry_run);
|
|
4029
|
+
return apiRequest(opts, "POST", "/v1/memory/redact", withLifecycle(body));
|
|
4030
|
+
}
|
|
3770
4031
|
if (name === "index_repository") {
|
|
3771
4032
|
const rawPath = args.path || args.repo_path || opts.repo || ".";
|
|
3772
4033
|
const repoPath = path.resolve(rawPath);
|
|
@@ -3790,10 +4051,15 @@ async function dispatchTool(opts, name, args = {}) {
|
|
|
3790
4051
|
let lastRes = {};
|
|
3791
4052
|
for (let i = 0; i < documents.length; i += BATCH_SIZE) {
|
|
3792
4053
|
const batch = documents.slice(i, i + BATCH_SIZE);
|
|
3793
|
-
const res = await apiRequest(
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
4054
|
+
const res = await apiRequest(
|
|
4055
|
+
opts,
|
|
4056
|
+
"POST",
|
|
4057
|
+
"/v1/memory/ingest",
|
|
4058
|
+
withLifecycle({
|
|
4059
|
+
documents: batch,
|
|
4060
|
+
user_id: uid,
|
|
4061
|
+
})
|
|
4062
|
+
);
|
|
3797
4063
|
lastRes = res || {};
|
|
3798
4064
|
totalIngested += Number(res?.ingested_count ?? res?.count ?? batch.length);
|
|
3799
4065
|
totalTokens += Number(res?.tokens_processed ?? 0);
|
|
@@ -3813,26 +4079,36 @@ async function dispatchTool(opts, name, args = {}) {
|
|
|
3813
4079
|
}
|
|
3814
4080
|
if (name === "search_code_by_behavior") {
|
|
3815
4081
|
const k = Number(args.top_k || args.limit || 5);
|
|
3816
|
-
return apiRequest(
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
4082
|
+
return apiRequest(
|
|
4083
|
+
opts,
|
|
4084
|
+
"POST",
|
|
4085
|
+
"/v1/memories/search",
|
|
4086
|
+
withLifecycle({
|
|
4087
|
+
query: args.query,
|
|
4088
|
+
user_id: uid,
|
|
4089
|
+
limit: k,
|
|
4090
|
+
top_k: k,
|
|
4091
|
+
filters: { kind: "code_symbol", ...(args.language ? { language: args.language } : {}) },
|
|
4092
|
+
})
|
|
4093
|
+
);
|
|
3823
4094
|
}
|
|
3824
4095
|
if (name === "find_bug_candidates") {
|
|
3825
4096
|
const k = Number(args.top_k || args.limit || 5);
|
|
3826
4097
|
const combinedQuery = args.stack_trace
|
|
3827
4098
|
? `${args.bug_description}\n${args.stack_trace}`
|
|
3828
4099
|
: args.bug_description;
|
|
3829
|
-
return apiRequest(
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
4100
|
+
return apiRequest(
|
|
4101
|
+
opts,
|
|
4102
|
+
"POST",
|
|
4103
|
+
"/v1/memories/search",
|
|
4104
|
+
withLifecycle({
|
|
4105
|
+
query: combinedQuery,
|
|
4106
|
+
user_id: uid,
|
|
4107
|
+
limit: k,
|
|
4108
|
+
top_k: k,
|
|
4109
|
+
filters: { kind: "code_symbol" },
|
|
4110
|
+
})
|
|
4111
|
+
);
|
|
3836
4112
|
}
|
|
3837
4113
|
if (name === "intervene_memory") {
|
|
3838
4114
|
const rawText = String(args.text || args.prompt || "");
|
|
@@ -3845,21 +4121,26 @@ async function dispatchTool(opts, name, args = {}) {
|
|
|
3845
4121
|
...(Array.isArray(args.dismiss_memory_ids) ? args.dismiss_memory_ids : []),
|
|
3846
4122
|
...(args.override_memory_id ? [String(args.override_memory_id)] : []),
|
|
3847
4123
|
].filter(Boolean);
|
|
3848
|
-
return apiRequest(
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
4124
|
+
return apiRequest(
|
|
4125
|
+
opts,
|
|
4126
|
+
"POST",
|
|
4127
|
+
"/v1/memory/intervene",
|
|
4128
|
+
withLifecycle({
|
|
4129
|
+
hook_event_name: args.hook_event_name || "UserPromptSubmit",
|
|
4130
|
+
prompt: args.prompt || rawText,
|
|
4131
|
+
text: rawText,
|
|
4132
|
+
tool_name: args.tool_name || null,
|
|
4133
|
+
tool_input: args.tool_input || null,
|
|
4134
|
+
tool_response: args.tool_response || null,
|
|
4135
|
+
...(overriddenIds.length > 0 ? { overridden_memory_ids: overriddenIds } : {}),
|
|
4136
|
+
model: args.model || process.env.SLASHML_MODEL || undefined,
|
|
4137
|
+
user_id: uid,
|
|
4138
|
+
...(resolvedProjectId ? { project_id: String(resolvedProjectId) } : {}),
|
|
4139
|
+
...(resolvedSessionId ? { session_id: String(resolvedSessionId) } : {}),
|
|
4140
|
+
commit_writes: args.commit_writes !== undefined ? Boolean(args.commit_writes) : true,
|
|
4141
|
+
top_k: Number(args.top_k || args.limit || 5),
|
|
4142
|
+
})
|
|
4143
|
+
);
|
|
3863
4144
|
}
|
|
3864
4145
|
if (name === "dismiss_intervention") {
|
|
3865
4146
|
const memIds = [
|
|
@@ -4002,7 +4283,12 @@ rl.on("line", (line) => {
|
|
|
4002
4283
|
const tools = parsed.codeMode
|
|
4003
4284
|
? CODE_MODE_TOOLS
|
|
4004
4285
|
: parsed.codeOnly
|
|
4005
|
-
? STANDARD_TOOLS.
|
|
4286
|
+
? STANDARD_TOOLS.filter(
|
|
4287
|
+
(t) =>
|
|
4288
|
+
t.name === "index_repository" ||
|
|
4289
|
+
t.name === "search_code_by_behavior" ||
|
|
4290
|
+
t.name === "find_bug_candidates"
|
|
4291
|
+
)
|
|
4006
4292
|
: parsed.passiveWrites
|
|
4007
4293
|
? STANDARD_TOOLS.filter((t) => t.name !== "add_memory")
|
|
4008
4294
|
: STANDARD_TOOLS;
|