Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions scripts/session-analysis/episode-contract.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ export const EVENT_SCHEMA_VERSION = 2;
export const TASK_EPISODE_SCHEMA_VERSION = 3;
export const DEFAULT_EPISODE_GAP_MS = 30 * 60 * 1000;

// Tool-name matching is case-insensitive: providers differ in casing
// (Claude Code emits "Edit"/"Write", pi emits "edit"/"write"), so entries
// are stored lowercase and compared against the lowercased tool name.
const EDIT_TOOL_NAMES = new Set([
"Edit",
"MultiEdit",
"NotebookEdit",
"NotebookWrite",
"SearchReplace",
"Write",
"edit",
"multiedit",
"notebookedit",
"notebookwrite",
"searchreplace",
"write",
]);
const PATHLESS_EDIT_TOOL_NAMES = new Set(["apply_patch"]);
const LIFECYCLE_USER_EVENT_TYPES = new Set(["user", "last-prompt", "UserPromptSubmit"]);
Expand Down Expand Up @@ -131,7 +134,7 @@ export function isEditEvent(event) {
if (event?.type === "event.patch_apply_end") return true;
if (PATHLESS_EDIT_TOOL_NAMES.has(String(event?.toolName ?? event?.functionCallName ?? "").toLowerCase())) return true;
if (/^\s*apply_patch(?:\s|$)/u.test(String(event?.commandText ?? ""))) return true;
return targetPaths.length > 0 && EDIT_TOOL_NAMES.has(event?.toolName);
return targetPaths.length > 0 && EDIT_TOOL_NAMES.has(String(event?.toolName ?? "").toLowerCase());
}

export function validationCategory(event) {
Expand Down
5 changes: 3 additions & 2 deletions scripts/session-analysis/insights.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const FRICTION_TYPE_PATTERNS = Object.freeze([
{ name: "aborted-event", pattern: /\b(?:abort|aborted|cancel|cancelled|interrupted)\b/i },
]);

const EDIT_TOOL_NAMES = new Set(["Edit", "MultiEdit", "NotebookEdit", "Write"]);
// Case-insensitive: providers differ in casing (Claude Code "Edit", pi "edit").
const EDIT_TOOL_NAMES = new Set(["edit", "multiedit", "notebookedit", "write"]);

const EDIT_COMMAND_PATTERNS = Object.freeze([
{ name: "apply_patch", pattern: /\bapply_patch\b|\*\*\*\s+Begin Patch/i },
Expand Down Expand Up @@ -724,7 +725,7 @@ function longSessionRows(rows = []) {
}

function isEditEvent(event) {
if (EDIT_TOOL_NAMES.has(event.toolName)) {
if (EDIT_TOOL_NAMES.has(String(event?.toolName ?? "").toLowerCase())) {
return true;
}
const commandText = event.commandText ?? "";
Expand Down
Loading