@slashml/memory 1.1.0 → 1.1.1
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 +258 -12
- package/package.json +1 -1
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.1.
|
|
13
|
+
const PACKAGE_VERSION = "1.1.1";
|
|
14
14
|
const MAX_STOP_BLOCKS_PER_PROMPT = 3;
|
|
15
15
|
let lastObservedVaultRevision = 0;
|
|
16
16
|
|
|
@@ -48,6 +48,7 @@ Options:
|
|
|
48
48
|
--code-only Expose only code & bug-localization MCP tools
|
|
49
49
|
--code-mode Expose compact single meta-tool (execute_memory_code)
|
|
50
50
|
--init Write ml-memory MCP entry to Cursor, Windsurf, or .mcp.json
|
|
51
|
+
--ellipsis With --init / init, scaffold .ellipsis/environments/slashml.yaml & PR review agent YAML
|
|
51
52
|
--skill <name> Filter IDE config target during --init (default: ml-memory)
|
|
52
53
|
--write-env Save SLASHML_API_KEY to .env in the current directory
|
|
53
54
|
--hook Run as an ambient IDE/agent lifecycle hook (reads hook JSON from stdin)
|
|
@@ -226,6 +227,7 @@ function parseCliArgs(argv) {
|
|
|
226
227
|
let isStatus = false;
|
|
227
228
|
let jsonOutput = false;
|
|
228
229
|
let isSyncRules = false;
|
|
230
|
+
let isEllipsis = false;
|
|
229
231
|
let isWatchSandbox = false;
|
|
230
232
|
let isDaemon = false;
|
|
231
233
|
let isOnce = false;
|
|
@@ -346,6 +348,8 @@ function parseCliArgs(argv) {
|
|
|
346
348
|
isVersion = true;
|
|
347
349
|
} else if (arg === "init" || arg === "--init") {
|
|
348
350
|
isInit = true;
|
|
351
|
+
} else if (arg === "--ellipsis") {
|
|
352
|
+
isEllipsis = true;
|
|
349
353
|
} else if (arg === "mint-token" || arg === "--mint-token") {
|
|
350
354
|
isMintToken = true;
|
|
351
355
|
} else if (arg === "revoke-token" || arg === "--revoke-token") {
|
|
@@ -504,6 +508,7 @@ function parseCliArgs(argv) {
|
|
|
504
508
|
isStatus,
|
|
505
509
|
jsonOutput,
|
|
506
510
|
isSyncRules,
|
|
511
|
+
isEllipsis,
|
|
507
512
|
isWatchSandbox,
|
|
508
513
|
isDaemon,
|
|
509
514
|
isOnce,
|
|
@@ -780,7 +785,117 @@ if (parsed.verifyEmail) {
|
|
|
780
785
|
return;
|
|
781
786
|
}
|
|
782
787
|
|
|
788
|
+
function initEllipsisWorkspace(opts) {
|
|
789
|
+
const workspaceDir = path.resolve(opts.repo || process.cwd());
|
|
790
|
+
const repoName = path.basename(workspaceDir.replace(/[\\/]+$/, "")) || "repo";
|
|
791
|
+
const userId = opts.userId || process.env.SLASHML_USER_ID || `${repoName}-org`;
|
|
792
|
+
const projectId = opts.projectId || process.env.SLASHML_PROJECT_ID || repoName;
|
|
793
|
+
const hasPkgJson = fs.existsSync(path.join(workspaceDir, "package.json"));
|
|
794
|
+
|
|
795
|
+
const envDir = path.join(workspaceDir, ".ellipsis", "environments");
|
|
796
|
+
const agentsDir = path.join(workspaceDir, ".ellipsis", "agents");
|
|
797
|
+
fs.mkdirSync(envDir, { recursive: true });
|
|
798
|
+
fs.mkdirSync(agentsDir, { recursive: true });
|
|
799
|
+
|
|
800
|
+
const envYamlPath = path.join(envDir, "slashml.yaml");
|
|
801
|
+
const agentYamlPath = path.join(agentsDir, "slashml-pr-review.yaml");
|
|
802
|
+
|
|
803
|
+
const buildBaseInputs = hasPkgJson ? ` inputs:\n - ${repoName}/package.json\n` : ` inputs: []\n`;
|
|
804
|
+
const npmInstallLine = hasPkgJson ? `\n cd /sandbox/${repoName}\n npm install` : "";
|
|
805
|
+
const envYaml = `ellipsis:
|
|
806
|
+
kind: environment
|
|
807
|
+
name: slashml
|
|
808
|
+
|
|
809
|
+
repositories:
|
|
810
|
+
- name: ${repoName}
|
|
811
|
+
|
|
812
|
+
variables:
|
|
813
|
+
- name: SLASHML_API_KEY
|
|
814
|
+
- name: SLASHML_USER_ID
|
|
815
|
+
value: ${userId}
|
|
816
|
+
- name: SLASHML_PROJECT_ID
|
|
817
|
+
value: ${projectId}
|
|
818
|
+
|
|
819
|
+
hooks:
|
|
820
|
+
build_base:
|
|
821
|
+
${buildBaseInputs} run: |
|
|
822
|
+
npm install -g @slashml/mcp || sudo npm install -g @slashml/mcp${npmInstallLine}
|
|
823
|
+
before_start: |
|
|
824
|
+
cd /sandbox/${repoName}
|
|
825
|
+
slashml-mcp sync-rules
|
|
826
|
+
slashml-mcp watch-sandbox --daemon
|
|
827
|
+
validate: |
|
|
828
|
+
command -v slashml-mcp
|
|
829
|
+
|
|
830
|
+
compute:
|
|
831
|
+
cpu: 2
|
|
832
|
+
memory: 8GB
|
|
833
|
+
timeout: 30m
|
|
834
|
+
|
|
835
|
+
mcp_servers:
|
|
836
|
+
- name: ml-memory
|
|
837
|
+
command: slashml-mcp
|
|
838
|
+
env:
|
|
839
|
+
SLASHML_API_KEY: \${SLASHML_API_KEY}
|
|
840
|
+
SLASHML_USER_ID: ${userId}
|
|
841
|
+
SLASHML_PROJECT_ID: ${projectId}
|
|
842
|
+
`;
|
|
843
|
+
|
|
844
|
+
const agentYaml = `ellipsis:
|
|
845
|
+
kind: agent
|
|
846
|
+
name: slashml-pr-review
|
|
847
|
+
description: Stateful PR review agent powered by / ml persistent memory
|
|
848
|
+
|
|
849
|
+
trigger:
|
|
850
|
+
type: react
|
|
851
|
+
pull_request:
|
|
852
|
+
on: [pushed]
|
|
853
|
+
repositories: [${repoName}]
|
|
854
|
+
draft: false
|
|
855
|
+
|
|
856
|
+
session:
|
|
857
|
+
claude_code:
|
|
858
|
+
model: claude-opus-5-5
|
|
859
|
+
effort: high
|
|
860
|
+
prompt: |
|
|
861
|
+
Review the pull request diff against the architectural rules synced in CLAUDE.md
|
|
862
|
+
and query \`ml-memory\` (\`search_memories\` and \`find_bug_candidates\`) for any domain
|
|
863
|
+
invariants touching the modified files. If a rule is violated, explain the violation
|
|
864
|
+
citing the \`/ ml\` memory ID and push a fix or comment on the PR.
|
|
865
|
+
environment: slashml
|
|
866
|
+
budget:
|
|
867
|
+
session: 5
|
|
868
|
+
day: 25
|
|
869
|
+
`;
|
|
870
|
+
|
|
871
|
+
fs.writeFileSync(envYamlPath, envYaml, "utf8");
|
|
872
|
+
fs.writeFileSync(agentYamlPath, agentYaml, "utf8");
|
|
873
|
+
if (opts.jsonOutput) {
|
|
874
|
+
process.stdout.write(
|
|
875
|
+
JSON.stringify(
|
|
876
|
+
{
|
|
877
|
+
status: "initialized",
|
|
878
|
+
target: "ellipsis",
|
|
879
|
+
repo: repoName,
|
|
880
|
+
files: [envYamlPath, agentYamlPath],
|
|
881
|
+
},
|
|
882
|
+
null,
|
|
883
|
+
2
|
|
884
|
+
) + "\n"
|
|
885
|
+
);
|
|
886
|
+
} else {
|
|
887
|
+
console.log(`[/ ml] Scaffolded Ellipsis configs for "${repoName}":`);
|
|
888
|
+
console.log(` - ${envYamlPath}`);
|
|
889
|
+
console.log(` - ${agentYamlPath}`);
|
|
890
|
+
console.log("Next: add SLASHML_API_KEY in Ellipsis -> Secrets, then commit & push .ellipsis/.");
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
|
|
783
894
|
if (parsed.isInit) {
|
|
895
|
+
if (parsed.isEllipsis) {
|
|
896
|
+
initEllipsisWorkspace(parsed);
|
|
897
|
+
process.exit(0);
|
|
898
|
+
}
|
|
784
899
|
nativeNodeInit(parsed.skill, parsed.apiKey, parsed.repo, parsed.writeEnv, {
|
|
785
900
|
agentId: parsed.agentId,
|
|
786
901
|
redactPolicy: parsed.redactPolicy,
|
|
@@ -2819,18 +2934,26 @@ async function runSyncRulesCommand(opts) {
|
|
|
2819
2934
|
}
|
|
2820
2935
|
|
|
2821
2936
|
function collectSandboxTranscriptFiles(extraDir) {
|
|
2822
|
-
const
|
|
2937
|
+
const rawRoots = [];
|
|
2823
2938
|
const onlyExplicitDir = Boolean(extraDir && String(extraDir).trim());
|
|
2824
2939
|
if (onlyExplicitDir) {
|
|
2825
|
-
|
|
2940
|
+
rawRoots.push(path.resolve(String(extraDir).trim()));
|
|
2826
2941
|
} else {
|
|
2827
2942
|
const home = os.homedir();
|
|
2828
|
-
|
|
2943
|
+
if (process.env.CLAUDE_CONFIG_DIR && String(process.env.CLAUDE_CONFIG_DIR).trim()) {
|
|
2944
|
+
rawRoots.push(path.join(String(process.env.CLAUDE_CONFIG_DIR).trim(), "projects"));
|
|
2945
|
+
}
|
|
2946
|
+
if (process.env.CODEX_HOME && String(process.env.CODEX_HOME).trim()) {
|
|
2947
|
+
rawRoots.push(path.join(String(process.env.CODEX_HOME).trim(), "sessions"));
|
|
2948
|
+
}
|
|
2949
|
+
rawRoots.push(
|
|
2950
|
+
"/ellipsis/cc-config/projects",
|
|
2829
2951
|
path.join(home, ".claude", "projects"),
|
|
2830
2952
|
path.join(home, ".codex", "sessions"),
|
|
2831
2953
|
"/tmp/slashml-transcripts"
|
|
2832
2954
|
);
|
|
2833
2955
|
}
|
|
2956
|
+
const roots = Array.from(new Set(rawRoots.filter(Boolean).map((r) => path.resolve(r))));
|
|
2834
2957
|
const nowMs = Date.now();
|
|
2835
2958
|
const maxAgeMs = 30 * 60 * 1000;
|
|
2836
2959
|
const found = [];
|
|
@@ -2865,7 +2988,42 @@ function collectSandboxTranscriptFiles(extraDir) {
|
|
|
2865
2988
|
return found;
|
|
2866
2989
|
}
|
|
2867
2990
|
|
|
2868
|
-
function
|
|
2991
|
+
function extractToolResultText(content) {
|
|
2992
|
+
if (typeof content === "string") return content;
|
|
2993
|
+
if (Array.isArray(content)) {
|
|
2994
|
+
return content
|
|
2995
|
+
.map((item) => {
|
|
2996
|
+
if (typeof item === "string") return item;
|
|
2997
|
+
if (item && typeof item === "object" && typeof item.text === "string") return item.text;
|
|
2998
|
+
return "";
|
|
2999
|
+
})
|
|
3000
|
+
.filter(Boolean)
|
|
3001
|
+
.join("\n");
|
|
3002
|
+
}
|
|
3003
|
+
if (content && typeof content === "object") {
|
|
3004
|
+
if (typeof content.output === "string") return content.output;
|
|
3005
|
+
if (typeof content.stdout === "string" || typeof content.stderr === "string") {
|
|
3006
|
+
return [content.stderr, content.stdout].filter(Boolean).join("\n");
|
|
3007
|
+
}
|
|
3008
|
+
}
|
|
3009
|
+
return "";
|
|
3010
|
+
}
|
|
3011
|
+
|
|
3012
|
+
function recordSessionToolUse(toolUsesMap, toolUseId, name, input) {
|
|
3013
|
+
if (!toolUsesMap || !toolUseId || !name) return;
|
|
3014
|
+
toolUsesMap[String(toolUseId)] = {
|
|
3015
|
+
name: String(name),
|
|
3016
|
+
input: input && typeof input === "object" ? input : {},
|
|
3017
|
+
};
|
|
3018
|
+
const keys = Object.keys(toolUsesMap);
|
|
3019
|
+
if (keys.length > 64) {
|
|
3020
|
+
for (const oldKey of keys.slice(0, keys.length - 64)) {
|
|
3021
|
+
delete toolUsesMap[oldKey];
|
|
3022
|
+
}
|
|
3023
|
+
}
|
|
3024
|
+
}
|
|
3025
|
+
|
|
3026
|
+
function extractEventsFromTranscriptEntry(entry, toolUsesMap = null) {
|
|
2869
3027
|
const events = [];
|
|
2870
3028
|
if (!entry || typeof entry !== "object") return events;
|
|
2871
3029
|
|
|
@@ -2876,6 +3034,7 @@ function extractEventsFromTranscriptEntry(entry) {
|
|
|
2876
3034
|
prompt: String(entry.prompt || entry.text || ""),
|
|
2877
3035
|
tool_name: entry.tool_name || entry.toolName || null,
|
|
2878
3036
|
tool_input: entry.tool_input || entry.toolInput || null,
|
|
3037
|
+
tool_response: entry.tool_response || entry.toolResponse || null,
|
|
2879
3038
|
});
|
|
2880
3039
|
return events;
|
|
2881
3040
|
}
|
|
@@ -2894,6 +3053,44 @@ function extractEventsFromTranscriptEntry(entry) {
|
|
|
2894
3053
|
.filter((b) => b && (b.type === "text" || typeof b.text === "string"))
|
|
2895
3054
|
.map((b) => String(b.text || ""))
|
|
2896
3055
|
.join("\n");
|
|
3056
|
+
for (const b of msg.content) {
|
|
3057
|
+
if (!b || typeof b !== "object" || b.type !== "tool_result") continue;
|
|
3058
|
+
const toolUseId = b.tool_use_id || b.toolUseId || "";
|
|
3059
|
+
const prior = toolUsesMap && toolUseId ? toolUsesMap[String(toolUseId)] : null;
|
|
3060
|
+
if (!prior || !prior.name) continue;
|
|
3061
|
+
const resMeta =
|
|
3062
|
+
entry.toolUseResult && typeof entry.toolUseResult === "object"
|
|
3063
|
+
? entry.toolUseResult
|
|
3064
|
+
: null;
|
|
3065
|
+
const rawOut =
|
|
3066
|
+
extractToolResultText(b.content) ||
|
|
3067
|
+
extractToolResultText(resMeta);
|
|
3068
|
+
const explicitCode =
|
|
3069
|
+
resMeta && typeof resMeta.exitCode === "number"
|
|
3070
|
+
? resMeta.exitCode
|
|
3071
|
+
: resMeta && typeof resMeta.exit_code === "number"
|
|
3072
|
+
? resMeta.exit_code
|
|
3073
|
+
: null;
|
|
3074
|
+
const isErr = Boolean(
|
|
3075
|
+
b.is_error ||
|
|
3076
|
+
b.isError ||
|
|
3077
|
+
(resMeta && (resMeta.interrupted || resMeta.is_error)) ||
|
|
3078
|
+
(explicitCode !== null && explicitCode !== 0)
|
|
3079
|
+
);
|
|
3080
|
+
const exitCode = explicitCode !== null ? explicitCode : isErr ? 1 : 0;
|
|
3081
|
+
const outputSlice = String(rawOut || "").trim().slice(0, 1024);
|
|
3082
|
+
events.push({
|
|
3083
|
+
hook_event_name: "PostToolUse",
|
|
3084
|
+
text: outputSlice,
|
|
3085
|
+
tool_name: String(prior.name),
|
|
3086
|
+
tool_input: prior.input || {},
|
|
3087
|
+
tool_response: {
|
|
3088
|
+
is_error: isErr,
|
|
3089
|
+
exit_code: exitCode,
|
|
3090
|
+
output: outputSlice,
|
|
3091
|
+
},
|
|
3092
|
+
});
|
|
3093
|
+
}
|
|
2897
3094
|
}
|
|
2898
3095
|
if (text && text.trim()) {
|
|
2899
3096
|
events.push({
|
|
@@ -2902,6 +3099,7 @@ function extractEventsFromTranscriptEntry(entry) {
|
|
|
2902
3099
|
prompt: text.trim(),
|
|
2903
3100
|
tool_name: null,
|
|
2904
3101
|
tool_input: null,
|
|
3102
|
+
tool_response: null,
|
|
2905
3103
|
});
|
|
2906
3104
|
}
|
|
2907
3105
|
return events;
|
|
@@ -2920,6 +3118,9 @@ function extractEventsFromTranscriptEntry(entry) {
|
|
|
2920
3118
|
textParts.push(b.text.trim());
|
|
2921
3119
|
} else if (b.type === "tool_use" && b.name) {
|
|
2922
3120
|
const toolIn = b.input && typeof b.input === "object" ? b.input : {};
|
|
3121
|
+
if (b.id) {
|
|
3122
|
+
recordSessionToolUse(toolUsesMap, b.id, b.name, toolIn);
|
|
3123
|
+
}
|
|
2923
3124
|
const toolSummary =
|
|
2924
3125
|
toolIn.command ||
|
|
2925
3126
|
toolIn.CommandLine ||
|
|
@@ -2933,6 +3134,7 @@ function extractEventsFromTranscriptEntry(entry) {
|
|
|
2933
3134
|
text: String(toolSummary || ""),
|
|
2934
3135
|
tool_name: String(b.name),
|
|
2935
3136
|
tool_input: toolIn,
|
|
3137
|
+
tool_response: null,
|
|
2936
3138
|
});
|
|
2937
3139
|
}
|
|
2938
3140
|
}
|
|
@@ -2953,6 +3155,9 @@ function extractEventsFromTranscriptEntry(entry) {
|
|
|
2953
3155
|
}
|
|
2954
3156
|
})()
|
|
2955
3157
|
: toolIn;
|
|
3158
|
+
if (tc.id) {
|
|
3159
|
+
recordSessionToolUse(toolUsesMap, tc.id, name, parsedIn);
|
|
3160
|
+
}
|
|
2956
3161
|
const toolSummary =
|
|
2957
3162
|
parsedIn.command ||
|
|
2958
3163
|
parsedIn.CommandLine ||
|
|
@@ -2966,6 +3171,7 @@ function extractEventsFromTranscriptEntry(entry) {
|
|
|
2966
3171
|
text: String(toolSummary || ""),
|
|
2967
3172
|
tool_name: String(name),
|
|
2968
3173
|
tool_input: parsedIn,
|
|
3174
|
+
tool_response: null,
|
|
2969
3175
|
});
|
|
2970
3176
|
}
|
|
2971
3177
|
}
|
|
@@ -2976,6 +3182,7 @@ function extractEventsFromTranscriptEntry(entry) {
|
|
|
2976
3182
|
text: textParts.join("\n"),
|
|
2977
3183
|
tool_name: null,
|
|
2978
3184
|
tool_input: null,
|
|
3185
|
+
tool_response: null,
|
|
2979
3186
|
});
|
|
2980
3187
|
}
|
|
2981
3188
|
}
|
|
@@ -2984,6 +3191,7 @@ function extractEventsFromTranscriptEntry(entry) {
|
|
|
2984
3191
|
|
|
2985
3192
|
async function scanSandboxTranscriptsOnce(opts, state) {
|
|
2986
3193
|
state.whisperedBySession = state.whisperedBySession || {};
|
|
3194
|
+
state.toolUsesBySession = state.toolUsesBySession || {};
|
|
2987
3195
|
const files = collectSandboxTranscriptFiles(opts.transcriptDir);
|
|
2988
3196
|
const targets = resolveSandboxTargets(opts.repo);
|
|
2989
3197
|
const primaryDir = targets[0] || process.cwd();
|
|
@@ -3024,6 +3232,7 @@ async function scanSandboxTranscriptsOnce(opts, state) {
|
|
|
3024
3232
|
state.offsets[filePath] = startOffset + Buffer.byteLength(completeStr, "utf8");
|
|
3025
3233
|
|
|
3026
3234
|
const sessionId = path.basename(filePath, ".jsonl");
|
|
3235
|
+
state.toolUsesBySession[sessionId] = state.toolUsesBySession[sessionId] || {};
|
|
3027
3236
|
const lines = completeStr.split(/\r?\n/);
|
|
3028
3237
|
for (const rawLine of lines) {
|
|
3029
3238
|
const line = rawLine.trim();
|
|
@@ -3034,21 +3243,35 @@ async function scanSandboxTranscriptsOnce(opts, state) {
|
|
|
3034
3243
|
} catch {
|
|
3035
3244
|
continue;
|
|
3036
3245
|
}
|
|
3037
|
-
const evList = extractEventsFromTranscriptEntry(entry);
|
|
3246
|
+
const evList = extractEventsFromTranscriptEntry(entry, state.toolUsesBySession[sessionId]);
|
|
3038
3247
|
for (const ev of evList) {
|
|
3039
3248
|
if (ev.hook_event_name === "UserPromptSubmit" && ev.prompt) {
|
|
3040
3249
|
state.lastPromptBySession[sessionId] = ev.prompt;
|
|
3041
3250
|
}
|
|
3251
|
+
const toolNameLower = ev.tool_name ? String(ev.tool_name).toLowerCase() : "";
|
|
3042
3252
|
if (
|
|
3043
|
-
ev.hook_event_name === "PreToolUse" &&
|
|
3044
|
-
|
|
3045
|
-
HOOK_READ_ONLY_TOOLS.has(
|
|
3253
|
+
(ev.hook_event_name === "PreToolUse" || ev.hook_event_name === "PostToolUse") &&
|
|
3254
|
+
toolNameLower &&
|
|
3255
|
+
(HOOK_READ_ONLY_TOOLS.has(toolNameLower) || toolNameLower.startsWith("mcp__ml-memory__"))
|
|
3046
3256
|
) {
|
|
3047
3257
|
recordLocalHookDrop(estimateTokens(ev.text));
|
|
3048
3258
|
continue;
|
|
3049
3259
|
}
|
|
3050
|
-
|
|
3051
|
-
if (
|
|
3260
|
+
let deltaText = String(ev.text || "").trim().slice(0, 1024);
|
|
3261
|
+
if (ev.hook_event_name === "PostToolUse" && deltaText.length < 4) {
|
|
3262
|
+
const fallbackCmd =
|
|
3263
|
+
ev.tool_input && typeof ev.tool_input === "object"
|
|
3264
|
+
? ev.tool_input.command ||
|
|
3265
|
+
ev.tool_input.CommandLine ||
|
|
3266
|
+
ev.tool_input.file_path ||
|
|
3267
|
+
ev.tool_input.path ||
|
|
3268
|
+
""
|
|
3269
|
+
: "";
|
|
3270
|
+
deltaText = String(deltaText || fallbackCmd || ev.tool_name || "ok")
|
|
3271
|
+
.trim()
|
|
3272
|
+
.slice(0, 1024);
|
|
3273
|
+
}
|
|
3274
|
+
if (!deltaText || (ev.hook_event_name !== "PostToolUse" && deltaText.length < 4)) continue;
|
|
3052
3275
|
if (!opts.apiKey) continue;
|
|
3053
3276
|
|
|
3054
3277
|
const promptContext = state.lastPromptBySession[sessionId] || deltaText;
|
|
@@ -3069,6 +3292,9 @@ async function scanSandboxTranscriptsOnce(opts, state) {
|
|
|
3069
3292
|
: {}),
|
|
3070
3293
|
tool_name: ev.tool_name || null,
|
|
3071
3294
|
tool_input: ev.tool_input || null,
|
|
3295
|
+
...(ev.tool_response !== undefined && ev.tool_response !== null
|
|
3296
|
+
? { tool_response: ev.tool_response }
|
|
3297
|
+
: {}),
|
|
3072
3298
|
commit_writes: true,
|
|
3073
3299
|
user_id: opts.userId || "default",
|
|
3074
3300
|
project_id: projectId,
|
|
@@ -3152,7 +3378,9 @@ async function scanSandboxTranscriptsOnce(opts, state) {
|
|
|
3152
3378
|
const ellipsisToken =
|
|
3153
3379
|
process.env.ELLIPSIS_API_TOKEN || process.env.ELLIPSIS_SESSION_TOKEN;
|
|
3154
3380
|
const ellipsisBase = (
|
|
3155
|
-
process.env.
|
|
3381
|
+
process.env.ELLIPSIS_API_BASE_URL ||
|
|
3382
|
+
process.env.ELLIPSIS_API_URL ||
|
|
3383
|
+
"https://api.ellipsis.dev"
|
|
3156
3384
|
).replace(/\/+$/, "");
|
|
3157
3385
|
state.notifiedRulesBySession = state.notifiedRulesBySession || {};
|
|
3158
3386
|
const notifiedRuleSet = new Set(
|
|
@@ -3170,6 +3398,7 @@ async function scanSandboxTranscriptsOnce(opts, state) {
|
|
|
3170
3398
|
state.notifiedRulesBySession[sessionId] = Array.from(notifiedRuleSet).slice(-64);
|
|
3171
3399
|
state.notifiedSessions[sessionId] = true;
|
|
3172
3400
|
try {
|
|
3401
|
+
const idempKey = `slashml_${String(ellipsisSessionId).slice(-16)}_${String(ruleFingerprints[0] || "rule").replace(/[^a-zA-Z0-9_-]/g, "").slice(0, 32)}`;
|
|
3173
3402
|
await fetch(`${ellipsisBase}/v1/sessions/${ellipsisSessionId}/messages`, {
|
|
3174
3403
|
method: "POST",
|
|
3175
3404
|
headers: {
|
|
@@ -3178,6 +3407,7 @@ async function scanSandboxTranscriptsOnce(opts, state) {
|
|
|
3178
3407
|
},
|
|
3179
3408
|
body: JSON.stringify({
|
|
3180
3409
|
message: resp.intervention_message,
|
|
3410
|
+
idempotency_key: idempKey,
|
|
3181
3411
|
}),
|
|
3182
3412
|
});
|
|
3183
3413
|
} catch {
|
|
@@ -3229,6 +3459,20 @@ async function scanSandboxTranscriptsOnce(opts, state) {
|
|
|
3229
3459
|
|
|
3230
3460
|
async function runWatchSandboxCommand(opts) {
|
|
3231
3461
|
if (opts.isDaemon) {
|
|
3462
|
+
try {
|
|
3463
|
+
if (fs.existsSync(SANDBOX_PID_PATH)) {
|
|
3464
|
+
const prevPid = Number(String(fs.readFileSync(SANDBOX_PID_PATH, "utf8")).trim());
|
|
3465
|
+
if (Number.isInteger(prevPid) && prevPid > 1 && prevPid !== process.pid) {
|
|
3466
|
+
try {
|
|
3467
|
+
process.kill(prevPid, "SIGTERM");
|
|
3468
|
+
} catch {
|
|
3469
|
+
// ignore if previous daemon already exited
|
|
3470
|
+
}
|
|
3471
|
+
}
|
|
3472
|
+
}
|
|
3473
|
+
} catch {
|
|
3474
|
+
// ignore pid read error
|
|
3475
|
+
}
|
|
3232
3476
|
const { spawn } = require("child_process");
|
|
3233
3477
|
const forwarded = process.argv
|
|
3234
3478
|
.slice(2)
|
|
@@ -3258,6 +3502,7 @@ async function runWatchSandboxCommand(opts) {
|
|
|
3258
3502
|
offsets: {},
|
|
3259
3503
|
lastPromptBySession: {},
|
|
3260
3504
|
whisperedBySession: {},
|
|
3505
|
+
toolUsesBySession: {},
|
|
3261
3506
|
notifiedSessions: {},
|
|
3262
3507
|
notifiedRulesBySession: {},
|
|
3263
3508
|
lastSyncedVaultRevision: 0,
|
|
@@ -3270,6 +3515,7 @@ async function runWatchSandboxCommand(opts) {
|
|
|
3270
3515
|
offsets: loaded.offsets || {},
|
|
3271
3516
|
lastPromptBySession: loaded.lastPromptBySession || {},
|
|
3272
3517
|
whisperedBySession: loaded.whisperedBySession || {},
|
|
3518
|
+
toolUsesBySession: loaded.toolUsesBySession || {},
|
|
3273
3519
|
notifiedSessions: loaded.notifiedSessions || {},
|
|
3274
3520
|
notifiedRulesBySession: loaded.notifiedRulesBySession || {},
|
|
3275
3521
|
lastSyncedVaultRevision: Number(loaded.lastSyncedVaultRevision || 0),
|