skalpel 4.0.7 → 4.0.8
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/package.json +1 -1
- package/skalpel-setup.mjs +21 -1
package/package.json
CHANGED
package/skalpel-setup.mjs
CHANGED
|
@@ -424,6 +424,26 @@ async function reportLiveAndLaunch(message) {
|
|
|
424
424
|
// arbitrary "cap to 100" that could upload fragments and MISS the real sessions.
|
|
425
425
|
const MIN_USER_TURNS = Math.max(1, Number.parseInt(process.env.SKALPEL_MIN_USER_TURNS || "5", 10));
|
|
426
426
|
|
|
427
|
+
// USER QUERIES ONLY. Claude Code logs every tool RESULT back as a role:"user" message
|
|
428
|
+
// (content = [{type:"tool_result"}]). Counting those as "user turns" is the bug that classified
|
|
429
|
+
// internal tool traffic as real intents and inflated "found N" so the client promised sessions the
|
|
430
|
+
// server then dropped (empty graphs for quiet/agentic users). This mirrors the server's
|
|
431
|
+
// engine._user_turn_count EXACTLY so the client's count == what the server ingests. One definition,
|
|
432
|
+
// two implementations kept in lockstep — see docs/SESSION-COUNTING.md.
|
|
433
|
+
const _HUMAN_PROMPT_SOURCES = new Set(["typed", "queued", "suggestion_accepted"]);
|
|
434
|
+
function isGenuineUserTurn(e) {
|
|
435
|
+
if (!(e?.type === "user" || e?.role === "user")) return false;
|
|
436
|
+
const ps = e?.promptSource;
|
|
437
|
+
if (ps != null) return _HUMAN_PROMPT_SOURCES.has(ps); // newer CLI: trust the source label
|
|
438
|
+
// older/current builds omit promptSource — a row is a tool RESULT (not a query) when its content
|
|
439
|
+
// is a block list carrying a tool_result. Everything else that's role:user is a genuine query.
|
|
440
|
+
const c = e?.message?.content;
|
|
441
|
+
if (Array.isArray(c) && c.some((b) => b && typeof b === "object" && b.type === "tool_result")) {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
return true;
|
|
445
|
+
}
|
|
446
|
+
|
|
427
447
|
export async function userTurnCount(path, cap = 5) {
|
|
428
448
|
let n = 0;
|
|
429
449
|
const input = createReadStream(path, { encoding: "utf8" });
|
|
@@ -437,7 +457,7 @@ export async function userTurnCount(path, cap = 5) {
|
|
|
437
457
|
} catch {
|
|
438
458
|
continue;
|
|
439
459
|
}
|
|
440
|
-
if (e
|
|
460
|
+
if (isGenuineUserTurn(e)) {
|
|
441
461
|
n++;
|
|
442
462
|
if (n >= cap) {
|
|
443
463
|
rl.close();
|