Skip to content

Add replay-ready interaction logging for session recording - #64

Merged
marota merged 7 commits into
mainfrom
claude/log-user-interactions-C7sgi
Mar 27, 2026
Merged

marota merged 7 commits into
mainfrom
claude/log-user-interactions-C7sgi

Conversation

@marota

@marota marota commented Mar 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR adds comprehensive interaction logging to ExpertAssist, enabling deterministic session replay. Every user action is recorded as a timestamped event with all parameters needed for an automated agent to reproduce the exact same session without human input.

Key Changes

  • New InteractionLogger utility (frontend/src/utils/interactionLogger.ts): Singleton class that records user interactions with monotonically increasing sequence numbers, ISO timestamps, and correlation IDs for async start/complete pairs. Includes unit tests.

  • Extended type system (frontend/src/types.ts): Added InteractionType enum covering 50+ event types across configuration, analysis, actions, visualization, and session management. Added InteractionLogEntry interface with seq, timestamp, type, details, correlation_id, and duration_ms fields.

  • Instrumented App.tsx handlers: Added interactionLogger.record() calls to all major user interaction handlers (settings, config loading, analysis steps, action selection, visualization controls, etc.). Async operations log both *_started and *_completed events with correlation IDs.

  • Session persistence: Modified buildSessionResult() to include interaction_log in saved sessions. Updated backend SaveSessionRequest to accept optional interaction_log field. Logs are saved alongside session.json as interaction_log.json.

  • Comprehensive documentation: Added .claude/plan.md (655 lines) with detailed design principles, event contracts, and replay agent specifications. Added docs/interaction-logging.md (456 lines) as user-facing documentation.

  • Standalone HTML support: Integrated InteractionLogger into standalone_interface.html with full event recording across all UI interactions.

Implementation Details

  • Replay contract: Each event's details field contains all parameters needed to reproduce the action (e.g., config_loaded includes all 13 configuration parameters). No inference required.

  • Async semantics: Events triggering API calls log both start and completion events linked by correlation_id. Replay agents wait for completion conditions (API response, UI state change) before proceeding.

  • Deterministic ordering: Events ordered by seq number (not just timestamp) to handle collisions. Each event is self-contained and maps to a specific UI gesture.

  • No performance impact: Logger is a simple in-memory array, cleared on new study load. No React state coupling, no re-renders triggered.

  • Test coverage: Added interactionLogger.test.ts with 8 test cases covering recording, correlation IDs, completion tracking, and log copying.

https://claude.ai/code/session_01P6uiNH28sCXf972sLBrvEJ

claude added 7 commits March 27, 2026 18:03
Add comprehensive replay agent contract with:
- Sequence numbers for deterministic ordering
- Correlation IDs linking async start/complete pairs
- Duration tracking for completed events
- Full details payload per event type for self-contained replay
- Wait-point semantics for async operations
- Extended event coverage (settings, path picker, confirm dialog,
  combine modal, zoom, voltage range, asset clicks, inspect query)

https://claude.ai/code/session_01P6uiNH28sCXf972sLBrvEJ
Log every user interaction as a timestamped event during a session and
save it as `interaction_log.json` alongside `session.json`. The log
captures enough data for an automated agent to deterministically replay
the exact same session.

New files:
- frontend/src/utils/interactionLogger.ts — singleton logger with
  correlation IDs and duration tracking for async operations
- frontend/src/utils/interactionLogger.test.ts — unit tests (8 tests)
- docs/interaction-logging.md — full documentation and replay contract

Changes:
- types.ts: add InteractionType (34 event types), InteractionLogEntry
- sessionUtils.ts: include interaction_log in SessionResult
- api.ts: pass interaction_log to saveSession endpoint
- main.py: write interaction_log.json in session folder
- App.tsx: instrument ~25 handlers with logger calls
- CombinedActionsModal.tsx: log modal open/close, pair toggle/estimate/simulate
- CLAUDE.md, docs/save-results.md: document new feature

All 243 existing tests pass. No new TypeScript errors introduced.

https://claude.ai/code/session_01P6uiNH28sCXf972sLBrvEJ
Port the InteractionLogger class and all handler instrumentation from
the React app to the standalone single-file interface. Same 34 event
types are logged: config, contingency, analysis step1/step2, actions
(select/favorite/reject/manual), combined actions (modal/toggle/
estimate/simulate), diagram tabs, zoom, SLD overlay, voltage range,
session save/reload.

The interaction log is included in session.json and passed as a
separate interaction_log field to POST /api/save-session, producing
interaction_log.json alongside the session snapshot.

https://claude.ai/code/session_01P6uiNH28sCXf972sLBrvEJ
After rebasing onto main's hook-based refactoring, re-add interaction
logging calls to the 5 custom hooks (useSettings, useActions, useAnalysis,
useDiagrams, useSession) and App.tsx. Fix broken CombinedActionsModal.tsx
merge artifacts (duplicate code, missing hasLS variable, async in
non-async useEffect).

https://claude.ai/code/session_01P6uiNH28sCXf972sLBrvEJ
- interactionLogger: concurrent correlations, all 34 event types, JSON
  serialization, complex details, duration tracking, seq continuity
- useActions: verify action_favorited, action_rejected, manual_action_simulated
- useAnalysis: verify step1/step2 start/complete with correlation IDs,
  overload_toggled, prioritized_actions_displayed, empty branch guard
- useDiagrams: verify zoom_in/out/reset, view_mode_changed,
  sld_overlay_opened/closed/tab_changed, asset_clicked,
  action_selected/deselected
- useSettings: verify settings_opened/cancelled, path_picked
- useSession: verify session_saved, session_reload_modal_opened,
  interaction_log passed to buildSessionResult and api.saveSession

https://claude.ai/code/session_01P6uiNH28sCXf972sLBrvEJ
@marota
marota merged commit 264ada4 into main Mar 27, 2026
2 checks passed
@marota marota mentioned this pull request Mar 27, 2026
5 tasks done
marota pushed a commit that referenced this pull request Apr 30, 2026
Reconciliation of section 2 (0.5.0):
- Drop misattributed PRs that were actually pre-rebrand: save/reload
  (#49/#52), MW Start (#62), interaction-logging (#64), SLD highlights
  (#63), load shedding initial integration (#61). All now properly
  cited in section 1.5–1.6.
- Disambiguate App.tsx refactor history: PR #56 (hooks, 2100 → 800,
  pre-rebrand) vs PR #74 (components, 1000 → 650, 0.5.0) vs PR #75
  (memoization Phase 2, same LoC).
- Add accurate 0.5.0 PRs: #66 (vectorization w/ benchmark table),
  #69/#70/#71 (UI polish), #72 (curtailment), #73 (loads_p/gens_p
  format + configurable MW), #74/#75 (App.tsx decomposition),
  #78 (PST tap re-simulation), #84/#86/#87/#90 (detachable tabs).
- Add a recap table summarizing what's truly new in 0.5.0.

Diagrams added (Mermaid, GitHub-rendered):
- Gantt timeline of all 4 phases (top of doc).
- High-level architecture (frontend / backend / data).
- Two-step analysis sequence diagram (section 1.6).
- App.tsx LoC evolution flow (section 2.4).
- Backend mixin decomposition before/after PR #104/#106 (section 3).
- PyPSA-EUR pipeline flowchart (section 4).

https://claude.ai/code/session_01Pg7fuCUG2edfm5PyHS6SbN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants