You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(insights): accurate paste detection via Claude Code history.jsonl + hook ground truth #801
Polylogue's detect_paste() uses pure heuristics: text >4000 chars, chatlog forwarding patterns, >70% code fence ratio. Two bugs:
Runs on all messages, not just user messages (materialization_runtime.py:258). Assistant code blocks incorrectly flagged as paste. Explains inflated 92% Codex paste rate.
No provider awareness: Codex has no paste tracking at all. The code-fence heuristic is especially wrong for Codex.
The heuristics themselves need calibration: the 4000-char threshold, the code-fence ratio, and the forwarding patterns were chosen without ground truth validation. Claude Code's history.jsonl provides explicit [Pasted text #N +M lines] markers with pastedContents — this is ground truth data that can be used to measure false positive/negative rates and tune thresholds per provider.
Ground truth available
Claude Code history.jsonl: LogEntry records with [Pasted text #N +M lines] markers and pastedContents map (content hashes, types, filenames). 4.6% of records contain pastes. 79% session coverage overall, ~92% for interactive sessions.
Hook integration (UserPromptSubmit): fires on every prompt before paste expansion, 100% session coverage vs 79% from history.jsonl.
Bug: detect_paste(msg.text) at materialization_runtime.py:258 runs on ALL messages regardless of role. Assistant messages with code blocks are incorrectly flagged. Production DB shows Codex 92% paste rate — almost entirely assistant code blocks misclassified. One-line fix: has_paste = detect_paste(msg.text) if msg.role == "user" else 0.
Codex note: Codex has no paste tracking at all — no [Pasted text #N] markers, no pastedContents map in session files. The upstream source only has "paste burst" detection at the TUI level for coalescing rapid keystrokes during paste operations into fewer redraws. Not stored anywhere.
Implementation sketch (~330 LOC)
Phase 1 — history.jsonl ingestion:
New acquisition source reading ~/.claude/history.jsonl
Classify as ArtifactKind.PROMPT_HISTORY (new variant in artifact taxonomy)
Match history records to sessions by sessionId + project fields (both present in history.jsonl and session JSONL)
Parse display field for [Pasted text #N +M lines] markers
Correction to the 29.9% figure in the issue body: the actual coverage is 79% (5,723 of 7,233 sessions with sessionId), not 29.9%. The earlier analysis contained a bug — comparing history.jsonl sessionIds against JSONL filenames (slugs) instead of the sessionId field inside the files.
The 20% gap (1,510 sessions) breaks down as:
1,023 (68%): queue-operation automated batch sessions — no user prompts to record
284 (19%): pre-history era, versions 1.0.x from May-Aug 2025, before history.jsonl existed
199 (13%): user/assistant sessions from the history era — tiny sessions (example: 2 lines), likely interrupted or abandoned
For real interactive sessions, effective coverage is ~92%. This makes history.jsonl MORE viable as a paste detection ground truth source, not less.
Correction: current Codex paste rate is ~23% all messages, ~10% user messages (production DB). The 92% figure cited was inflated by the no-role-guard bug — assistant code blocks were being counted. The one-line fix (msg.role == 'user' guard) corrects this.
Related:#827 (session intelligence umbrella), #804 (temporal analysis), #803 (cost tracking), #801 (paste detection). These four insight features share infrastructure (session_profiles, action_events, day_session_summaries) and should be sequenced together.
Activity
Sinity commentedon May 4, 2026
Current heuristic analysis
archive/message/paste_detection.pyuses three heuristics, any one setshas_paste=1:Bug:
detect_paste(msg.text)atmaterialization_runtime.py:258runs on ALL messages regardless of role. Assistant messages with code blocks are incorrectly flagged. Production DB shows Codex 92% paste rate — almost entirely assistant code blocks misclassified. One-line fix:has_paste = detect_paste(msg.text) if msg.role == "user" else 0.Codex note: Codex has no paste tracking at all — no
[Pasted text #N]markers, nopastedContentsmap in session files. The upstream source only has "paste burst" detection at the TUI level for coalescing rapid keystrokes during paste operations into fewer redraws. Not stored anywhere.Implementation sketch (~330 LOC)
Phase 1 — history.jsonl ingestion:
~/.claude/history.jsonlArtifactKind.PROMPT_HISTORY(new variant in artifact taxonomy)sessionId+projectfields (both present in history.jsonl and session JSONL)displayfield for[Pasted text #N +M lines]markerspastedContentsmap: content hashes (SHA-256), types (text/image), filenamesmessage_pastestable:conversation_id,message_id,content_hash,paste_type,filename,start_offset,end_offsetdetect_paste()call with explicit marker lookupPhase 2 — hook integration:
UserPromptSubmithook captures prompt BEFORE paste expansion for 100% of sessionsCross-session dedup query:
Sinity commentedon May 4, 2026
Correction to the 29.9% figure in the issue body: the actual coverage is 79% (5,723 of 7,233 sessions with sessionId), not 29.9%. The earlier analysis contained a bug — comparing history.jsonl sessionIds against JSONL filenames (slugs) instead of the sessionId field inside the files.
The 20% gap (1,510 sessions) breaks down as:
For real interactive sessions, effective coverage is ~92%. This makes history.jsonl MORE viable as a paste detection ground truth source, not less.
Sinity commentedon May 4, 2026
Sinity commentedon May 4, 2026
Acceptance Criteria
detect_paste(msg.text)guarded bymsg.role == "user"— Codex paste rate drops from 92% to actualArtifactKind.PROMPT_HISTORYmessage_pastestable populated with content hashes, types, filenames from matched history recordsWhen closing: comment on this issue or the PR explicitly stating how each criterion was satisfied, deferred, or found misframed.
Sinity commentedon May 4, 2026
Correction: current Codex paste rate is ~23% all messages, ~10% user messages (production DB). The 92% figure cited was inflated by the no-role-guard bug — assistant code blocks were being counted. The one-line fix (msg.role == 'user' guard) corrects this.
fix: datetime UTC, MCP filter wiring, export fields, paste role guard
Sinity commentedon May 4, 2026
Related: #827 (session intelligence umbrella), #804 (temporal analysis), #803 (cost tracking), #801 (paste detection). These four insight features share infrastructure (session_profiles, action_events, day_session_summaries) and should be sequenced together.
Sinity commentedon May 4, 2026
Fixed in 4d60bde. paste_detection.py now only runs on user messages (role guard added at materialization_runtime.py:258).
fix: datetime UTC, MCP filter wiring, export fields, paste role guard