@slashml/memory 1.0.13 → 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 +206 -62
- 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/README.md
CHANGED
|
@@ -11,7 +11,7 @@ npm install @slashml/memory
|
|
|
11
11
|
Configure your API key in the environment:
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
export SLASHML_API_KEY="
|
|
14
|
+
export SLASHML_API_KEY="sml_live_..."
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## Quickstart (Mem0 Drop-in Replacement)
|
|
@@ -90,6 +90,34 @@ const decision = await client.intervene("aws ec2 run-instances --placement Avail
|
|
|
90
90
|
});
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
+
## Inline Redaction & Per-Agent Read/Write Access Control
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { Memory } from "@slashml/memory";
|
|
97
|
+
|
|
98
|
+
const admin = new Memory({ apiKey: process.env.SLASHML_API_KEY });
|
|
99
|
+
|
|
100
|
+
// Set workspace redaction defaults & configure a read-only agent policy
|
|
101
|
+
await admin.setRedactionPolicy({
|
|
102
|
+
redactPolicy: "tier1_secrets",
|
|
103
|
+
redactScope: "recall_only",
|
|
104
|
+
accessMode: "read_write",
|
|
105
|
+
});
|
|
106
|
+
await admin.agents.set("support_triage_bot", {
|
|
107
|
+
accessMode: "read_only",
|
|
108
|
+
redactPolicy: "gdpr",
|
|
109
|
+
redactScope: "recall_only",
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Scoped agent client attaches X-SlashML-Agent-Id automatically
|
|
113
|
+
const triage = new Memory({
|
|
114
|
+
apiKey: process.env.SLASHML_API_KEY,
|
|
115
|
+
agentId: "support_triage_bot",
|
|
116
|
+
});
|
|
117
|
+
const masked = await triage.redact({ text: "Contact alice@acme.io for billing" });
|
|
118
|
+
const hits = await triage.search("Who handles billing?", { userId: "alice" });
|
|
119
|
+
```
|
|
120
|
+
|
|
93
121
|
---
|
|
94
122
|
|
|
95
123
|
## License
|
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.
|
|
13
|
+
const PACKAGE_VERSION = "1.0.14";
|
|
14
14
|
const MAX_STOP_BLOCKS_PER_PROMPT = 3;
|
|
15
15
|
|
|
16
16
|
function printHelp() {
|
|
@@ -31,6 +31,9 @@ Options:
|
|
|
31
31
|
--api-key <key> SlashML API key (or set SLASHML_API_KEY env var)
|
|
32
32
|
--workspace, --repo <path> Optional workspace directory to scope/index (defaults to process.cwd() at runtime)
|
|
33
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)
|
|
34
37
|
--code-only Expose only code & bug-localization MCP tools
|
|
35
38
|
--code-mode Expose compact single meta-tool (execute_memory_code)
|
|
36
39
|
--init Write ml-memory MCP entry to Cursor, Windsurf, or .mcp.json
|
|
@@ -183,6 +186,9 @@ function parseCliArgs(argv) {
|
|
|
183
186
|
let baseUrl = (process.env.SLASHML_BASE_URL || DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
184
187
|
let consoleUrl = (process.env.SLASHML_CONSOLE_URL || DEFAULT_CONSOLE_URL).replace(/\/+$/, "");
|
|
185
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;
|
|
186
192
|
let codeOnly = false;
|
|
187
193
|
let codeMode = false;
|
|
188
194
|
let passiveWrites = process.env.SLASHML_PASSIVE_WRITES === "1";
|
|
@@ -269,6 +275,12 @@ function parseCliArgs(argv) {
|
|
|
269
275
|
consoleUrl = argv[++i].replace(/\/+$/, "");
|
|
270
276
|
} else if (arg === "--user-id" && i + 1 < argv.length) {
|
|
271
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;
|
|
272
284
|
} else if ((arg === "--repo" || arg === "--workspace") && i + 1 < argv.length) {
|
|
273
285
|
repo = argv[++i];
|
|
274
286
|
} else if (arg === "--signup" && i + 1 < argv.length) {
|
|
@@ -302,6 +314,9 @@ function parseCliArgs(argv) {
|
|
|
302
314
|
baseUrl,
|
|
303
315
|
consoleUrl,
|
|
304
316
|
userId,
|
|
317
|
+
agentId,
|
|
318
|
+
redactPolicy,
|
|
319
|
+
redactScope,
|
|
305
320
|
codeOnly,
|
|
306
321
|
codeMode,
|
|
307
322
|
passiveWrites,
|
|
@@ -366,7 +381,7 @@ function saveApiKeyToEnvFile(apiKey, cwd = process.cwd()) {
|
|
|
366
381
|
|
|
367
382
|
const GENERIC_SKILL_NAMES = new Set(["ml-memory", "/ml-memory", "slashml", "all", "default"]);
|
|
368
383
|
|
|
369
|
-
function nativeNodeInit(skill, apiKey, repo = null, writeEnv = false) {
|
|
384
|
+
function nativeNodeInit(skill, apiKey, repo = null, writeEnv = false, extraEnv = {}) {
|
|
370
385
|
const home = os.homedir();
|
|
371
386
|
const cwd = process.cwd();
|
|
372
387
|
const targets = [
|
|
@@ -398,10 +413,21 @@ function nativeNodeInit(skill, apiKey, repo = null, writeEnv = false) {
|
|
|
398
413
|
args,
|
|
399
414
|
};
|
|
400
415
|
const resolvedKey = apiKey || process.env.SLASHML_API_KEY;
|
|
416
|
+
const envMap = {};
|
|
401
417
|
if (resolvedKey) {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
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;
|
|
405
431
|
}
|
|
406
432
|
if (writeEnv && resolvedKey) {
|
|
407
433
|
saveApiKeyToEnvFile(resolvedKey, cwd);
|
|
@@ -498,7 +524,11 @@ async function runCliVerify(email, code, parsedArgs) {
|
|
|
498
524
|
envSavedPath = path.join(process.cwd(), ".env");
|
|
499
525
|
}
|
|
500
526
|
if (parsedArgs.isInit) {
|
|
501
|
-
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
|
+
});
|
|
502
532
|
}
|
|
503
533
|
console.log(
|
|
504
534
|
JSON.stringify({
|
|
@@ -544,7 +574,11 @@ if (parsed.verifyEmail) {
|
|
|
544
574
|
}
|
|
545
575
|
|
|
546
576
|
if (parsed.isInit) {
|
|
547
|
-
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
|
+
});
|
|
548
582
|
if (process.env.SLASHML_DISABLE_AUTO_HOOKS !== "1") {
|
|
549
583
|
try {
|
|
550
584
|
installAmbientHooks(parsed.apiKey, { quiet: false, onlyIfDirExists: false });
|
|
@@ -782,7 +816,7 @@ function installAmbientHooks(apiKey, opts = {}) {
|
|
|
782
816
|
}
|
|
783
817
|
}
|
|
784
818
|
|
|
785
|
-
// 5. Gemini CLI
|
|
819
|
+
// 5. Gemini CLI (~/.gemini/config/plugins/slashml-memory + ~/.gemini/GEMINI.md)
|
|
786
820
|
const geminiConfigDir = path.join(home, ".gemini", "config");
|
|
787
821
|
const geminiPluginsRoot = path.join(geminiConfigDir, "plugins");
|
|
788
822
|
let geminiPluginDir = path.join(geminiPluginsRoot, "slashml-memory");
|
|
@@ -1925,6 +1959,9 @@ async function runAmbientHookMode(opts) {
|
|
|
1925
1959
|
user_id: opts.userId,
|
|
1926
1960
|
...(projectId ? { project_id: projectId } : {}),
|
|
1927
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 } : {}),
|
|
1928
1965
|
client_raw_tokens_delta: (telem.pending_raw_tokens_delta || 0) + strippedTokens,
|
|
1929
1966
|
client_dropped_tokens_delta: (telem.pending_dropped_tokens_delta || 0) + strippedTokens,
|
|
1930
1967
|
client_dropped_events_delta: telem.pending_dropped_events_delta || 0,
|
|
@@ -2601,6 +2638,9 @@ async function scanSandboxTranscriptsOnce(opts, state) {
|
|
|
2601
2638
|
user_id: opts.userId || "default",
|
|
2602
2639
|
project_id: projectId,
|
|
2603
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 } : {}),
|
|
2604
2644
|
});
|
|
2605
2645
|
processedEvents += 1;
|
|
2606
2646
|
telem.conversation_tokens_processed = (telem.conversation_tokens_processed || 0) + rawTok;
|
|
@@ -3579,15 +3619,43 @@ const STANDARD_TOOLS = [
|
|
|
3579
3619
|
},
|
|
3580
3620
|
{
|
|
3581
3621
|
name: "forget_memory",
|
|
3582
|
-
description: "Delete a specific memory by ID.",
|
|
3622
|
+
description: "Delete or permanently purge a specific memory by ID.",
|
|
3583
3623
|
inputSchema: {
|
|
3584
3624
|
type: "object",
|
|
3585
3625
|
properties: {
|
|
3586
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" },
|
|
3587
3633
|
},
|
|
3588
3634
|
required: ["memory_id"],
|
|
3589
3635
|
},
|
|
3590
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
|
+
},
|
|
3591
3659
|
{
|
|
3592
3660
|
name: "dismiss_intervention",
|
|
3593
3661
|
description:
|
|
@@ -3663,7 +3731,7 @@ const CODE_MODE_TOOLS = [
|
|
|
3663
3731
|
{
|
|
3664
3732
|
name: "execute_memory_code",
|
|
3665
3733
|
description:
|
|
3666
|
-
"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.",
|
|
3667
3735
|
inputSchema: {
|
|
3668
3736
|
type: "object",
|
|
3669
3737
|
properties: {
|
|
@@ -3674,6 +3742,7 @@ const CODE_MODE_TOOLS = [
|
|
|
3674
3742
|
"search_memories",
|
|
3675
3743
|
"get_memories",
|
|
3676
3744
|
"forget_memory",
|
|
3745
|
+
"redact_memory",
|
|
3677
3746
|
"index_repository",
|
|
3678
3747
|
"search_code_by_behavior",
|
|
3679
3748
|
"find_bug_candidates",
|
|
@@ -3694,13 +3763,17 @@ async function apiRequest(opts, method, urlPath, body) {
|
|
|
3694
3763
|
"SlashML API key is required. Set SLASHML_API_KEY in your environment or pass --api-key."
|
|
3695
3764
|
);
|
|
3696
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
|
+
}
|
|
3697
3774
|
const res = await fetch(`${opts.baseUrl}${urlPath}`, {
|
|
3698
3775
|
method,
|
|
3699
|
-
headers
|
|
3700
|
-
Authorization: `Bearer ${opts.apiKey}`,
|
|
3701
|
-
"Content-Type": "application/json",
|
|
3702
|
-
"User-Agent": "slashml-cli-node/1.0.0",
|
|
3703
|
-
},
|
|
3776
|
+
headers,
|
|
3704
3777
|
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
3705
3778
|
});
|
|
3706
3779
|
const text = await res.text();
|
|
@@ -3864,6 +3937,16 @@ async function dispatchTool(opts, name, args = {}) {
|
|
|
3864
3937
|
return dispatchTool(opts, args.action, args.params || {});
|
|
3865
3938
|
}
|
|
3866
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
|
+
}
|
|
3867
3950
|
|
|
3868
3951
|
if (name === "add_memory") {
|
|
3869
3952
|
const rawText = args.text !== undefined ? args.text : args.messages;
|
|
@@ -3877,12 +3960,17 @@ async function dispatchTool(opts, name, args = {}) {
|
|
|
3877
3960
|
...(args.metadata ? { metadata: args.metadata } : {}),
|
|
3878
3961
|
},
|
|
3879
3962
|
];
|
|
3880
|
-
return apiRequest(
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
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
|
+
);
|
|
3886
3974
|
}
|
|
3887
3975
|
if (name === "search_memories") {
|
|
3888
3976
|
const k = Number(args.limit || args.top_k || 5);
|
|
@@ -3891,24 +3979,55 @@ async function dispatchTool(opts, name, args = {}) {
|
|
|
3891
3979
|
...(args.include_code !== undefined ? { include_code: Boolean(args.include_code) } : {}),
|
|
3892
3980
|
...(args.kind ? { kind: String(args.kind) } : {}),
|
|
3893
3981
|
};
|
|
3894
|
-
return apiRequest(
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
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
|
+
);
|
|
3901
3994
|
}
|
|
3902
3995
|
if (name === "get_memories") {
|
|
3903
3996
|
const paramsObj = { user_id: uid, limit: String(args.limit || 50) };
|
|
3904
3997
|
if (args.include_code !== undefined) paramsObj.include_code = String(Boolean(args.include_code));
|
|
3905
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);
|
|
3906
4005
|
const q = new URLSearchParams(paramsObj);
|
|
3907
4006
|
return apiRequest(opts, "GET", `/v1/memories?${q.toString()}`);
|
|
3908
4007
|
}
|
|
3909
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
|
+
}
|
|
3910
4021
|
return apiRequest(opts, "DELETE", `/v1/memories/${encodeURIComponent(args.memory_id)}`);
|
|
3911
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
|
+
}
|
|
3912
4031
|
if (name === "index_repository") {
|
|
3913
4032
|
const rawPath = args.path || args.repo_path || opts.repo || ".";
|
|
3914
4033
|
const repoPath = path.resolve(rawPath);
|
|
@@ -3932,10 +4051,15 @@ async function dispatchTool(opts, name, args = {}) {
|
|
|
3932
4051
|
let lastRes = {};
|
|
3933
4052
|
for (let i = 0; i < documents.length; i += BATCH_SIZE) {
|
|
3934
4053
|
const batch = documents.slice(i, i + BATCH_SIZE);
|
|
3935
|
-
const res = await apiRequest(
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
4054
|
+
const res = await apiRequest(
|
|
4055
|
+
opts,
|
|
4056
|
+
"POST",
|
|
4057
|
+
"/v1/memory/ingest",
|
|
4058
|
+
withLifecycle({
|
|
4059
|
+
documents: batch,
|
|
4060
|
+
user_id: uid,
|
|
4061
|
+
})
|
|
4062
|
+
);
|
|
3939
4063
|
lastRes = res || {};
|
|
3940
4064
|
totalIngested += Number(res?.ingested_count ?? res?.count ?? batch.length);
|
|
3941
4065
|
totalTokens += Number(res?.tokens_processed ?? 0);
|
|
@@ -3955,26 +4079,36 @@ async function dispatchTool(opts, name, args = {}) {
|
|
|
3955
4079
|
}
|
|
3956
4080
|
if (name === "search_code_by_behavior") {
|
|
3957
4081
|
const k = Number(args.top_k || args.limit || 5);
|
|
3958
|
-
return apiRequest(
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
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
|
+
);
|
|
3965
4094
|
}
|
|
3966
4095
|
if (name === "find_bug_candidates") {
|
|
3967
4096
|
const k = Number(args.top_k || args.limit || 5);
|
|
3968
4097
|
const combinedQuery = args.stack_trace
|
|
3969
4098
|
? `${args.bug_description}\n${args.stack_trace}`
|
|
3970
4099
|
: args.bug_description;
|
|
3971
|
-
return apiRequest(
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
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
|
+
);
|
|
3978
4112
|
}
|
|
3979
4113
|
if (name === "intervene_memory") {
|
|
3980
4114
|
const rawText = String(args.text || args.prompt || "");
|
|
@@ -3987,21 +4121,26 @@ async function dispatchTool(opts, name, args = {}) {
|
|
|
3987
4121
|
...(Array.isArray(args.dismiss_memory_ids) ? args.dismiss_memory_ids : []),
|
|
3988
4122
|
...(args.override_memory_id ? [String(args.override_memory_id)] : []),
|
|
3989
4123
|
].filter(Boolean);
|
|
3990
|
-
return apiRequest(
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
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
|
+
);
|
|
4005
4144
|
}
|
|
4006
4145
|
if (name === "dismiss_intervention") {
|
|
4007
4146
|
const memIds = [
|
|
@@ -4144,7 +4283,12 @@ rl.on("line", (line) => {
|
|
|
4144
4283
|
const tools = parsed.codeMode
|
|
4145
4284
|
? CODE_MODE_TOOLS
|
|
4146
4285
|
: parsed.codeOnly
|
|
4147
|
-
? 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
|
+
)
|
|
4148
4292
|
: parsed.passiveWrites
|
|
4149
4293
|
? STANDARD_TOOLS.filter((t) => t.name !== "add_memory")
|
|
4150
4294
|
: STANDARD_TOOLS;
|