Skip to content

feat(insights): session timeline renderer with fidelity tags (#1135) - #1165

Merged
Sinity merged 1 commit into
masterfrom
feature/feat/insights-timeline-renderer-v2
May 17, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/feat/insights-timeline-renderer-v2

Conversation

@Sinity

@Sinity Sinity commented May 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds a per-session timeline view that merges already-materialized work events and session phases for one conversation, and tags every entry with a user-visible fidelity label distinguishing hook-precise timing (hook) from sort-key-reconstructed timing (sort_key).

Closes #1135.

Problem

Issue #1135 (carry-over from #804 / parent #994) calls for a usable surface over the per-session timeline data already materialized as session_work_event and session_phase insights. Without a renderer, the durable rows are only reachable through generic list commands and JSON dumps. The issue also requires that each rendered timestamp carry a fidelity tag so consumers can tell whether timing came from a precise recorded range or was reconstructed from message sort-key order.

Solution

  • polylogue/insights/timeline_renderer.py (new) — pure renderer. fidelity_for(timing_provenance) maps the existing WorkEventEvidencePayload.timing_provenance / SessionPhaseEvidencePayload.timing_provenance to "hook" when it equals timestamped_range and "sort_key" otherwise (including unknown values, since the precise branch is the explicitly-recognized one). build_session_timeline() merges the two insight streams into a chronologically ordered SessionTimeline; render_plain() and render_markdown() emit human-readable surfaces with a legend; SessionTimeline.to_dict() provides the JSON contract that preserves both the user-visible tag and the raw timing_provenance for downstream consumers.
  • polylogue/cli/commands/insights.py — adds polylogue insights timeline <conversation-id> with --format plain|markdown|json (inherits root --format). Reads from env.operations.get_session_work_event_insights and get_session_phase_insights, then delegates to the renderer.
  • tests/unit/insights/test_timeline_renderer.py (new, 21 cases) — pins the fidelity-tag invariant (parametrized over the full set of recognized provenance strings), hook-vs-sort_key precedence on the same session, chronological ordering across sources, untimed-entry placement, plain/markdown surface contracts, empty-timeline message, and JSON serializability.
  • tests/unit/cli/test_insights.py — adds two CLI cases against the seeded cli_workspace: JSON envelope contract (every entry has fidelity in {"hook","sort_key"} and a timing_provenance field) and plain output includes the legend.

The renderer is deliberately a pure function over insight payloads: it does not query storage, does not recompute timing, and does not introduce a new persistence shape. Hook-event integration (#802) will land precise timestamps in the existing timing_provenance field; the renderer's fidelity-tag contract already covers that path without further code changes.

Verification

Exact commands run inside nix develop -c:

  • pytest tests/unit/insights/test_timeline_renderer.py -q — 21 passed in 12.88s
  • pytest tests/unit/insights/ tests/unit/cli/test_insights.py -q — 76 passed in 16.70s
  • mypy polylogue/insights/timeline_renderer.py polylogue/cli/commands/insights.py tests/unit/insights/test_timeline_renderer.py — Success: no issues found in 3 source files
  • devtools verify --quick — exit_code: 0 (also re-run automatically by the pre-push hook, exit 0)
  • devtools build-topology-projection — refreshed docs/plans/topology-target.yaml to register the new module; verify-topology then passes.

Acceptance criteria mapping (#1135)

AC Status Evidence
Each timeline entry carries an explicit fidelity tag (hook or sort_key) satisfied TimelineEntry.fidelity; test_non_hook_provenances_are_sort_key (parametrized)
Hook timing takes precedence when present; precedence invariant tested satisfied test_hook_and_sort_key_remain_distinct_on_same_session
CLI bar renderer + --json mode both consume the stored timeline (no recomputation) satisfied (plain + markdown + json) insights_timeline_command reads get_session_work_event_insights / get_session_phase_insights; test_insights_timeline_json_emits_fidelity_tags
Dedicated tests: CLI snapshot, fidelity precedence, gap classification satisfied tests/unit/insights/test_timeline_renderer.py + tests/unit/cli/test_insights.py
Reader panel renders the timeline using the shared API deferred (reader-UI lane, not owned here) follow-up issue should consume build_session_timeline
MCP tool envelope consistent with other session-insight MCP tools deferred (MCP lane, not owned here) follow-up issue should expose SessionTimeline.to_dict()

The reader-panel and MCP-tool ACs are deliberately out of scope of this PR (other agents own those surfaces under #1135's sibling issues). The renderer is the shared API both surfaces will consume; this PR makes that API committed and tested.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added polylogue insights timeline command to display conversation work events and session phases in chronological order. Supports JSON, Markdown, and plain-text output formats.
  • Documentation

    • Updated CLI reference and topology documentation to reflect the new timeline feature.

Review Change Stack

Adds a per-session timeline view that merges materialized work events
and session phases for one conversation and tags every entry with a
user-visible fidelity label.

- polylogue/insights/timeline_renderer.py: pure renderer over
  SessionWorkEventInsight / SessionPhaseInsight payloads. Builds a
  chronological SessionTimeline, derives fidelity_for() from raw
  timing_provenance (timestamped_range -> hook, anything else ->
  sort_key), and renders plain-text and Markdown surfaces with an
  explicit legend.
- polylogue/cli/commands/insights.py: new `polylogue insights timeline
  <conversation-id>` subcommand with --format plain|markdown|json
  reading from env.operations.get_session_{work_event,phase}_insights.
- tests/unit/insights/test_timeline_renderer.py: contract tests pinning
  the fidelity-tag invariant, hook-vs-sort_key precedence, ordering,
  empty handling, and JSON serializability.
- tests/unit/cli/test_insights.py: CLI integration tests for plain and
  JSON timeline output against the seeded workspace.

Closes #1135

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented May 17, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 81bade15-6d47-4edf-970e-e8cc4c47b322

📥 Commits

Reviewing files that changed from the base of the PR and between 7d6dd65 and 0730ed7.

📒 Files selected for processing (9)
  • docs/cli-reference.md
  • docs/plans/topology-target.yaml
  • docs/test-quality-workflows.md
  • docs/topology-status.md
  • docs/verification-catalog.md
  • polylogue/cli/commands/insights.py
  • polylogue/insights/timeline_renderer.py
  • tests/unit/cli/test_insights.py
  • tests/unit/insights/test_timeline_renderer.py

📝 Walkthrough

Walkthrough

This PR introduces a session timeline renderer for the CLI insights tool. The new polylogue/insights/timeline_renderer.py module merges work events and session phases into chronologically ordered entries, tags each by fidelity (hook vs. sort-key reconstruction), and renders them as plain text, Markdown, or JSON. The CLI command insights timeline <conversation_id> integrates the renderer and supports multiple output formats via a --format flag.

Changes

Timeline Renderer & CLI Integration

Layer / File(s) Summary
Timeline renderer data contract & builders
polylogue/insights/timeline_renderer.py
FidelityTag maps timing_provenance to "hook" or "sort_key". TimelineEntry and SessionTimeline are frozen dataclasses with to_dict() serialization. Builder functions merge work events and phases, sort chronologically by start_time, place untimed entries last (preserving input order), and compute fidelity_counts.
Timeline renderers & output formats
polylogue/insights/timeline_renderer.py
render_plain() produces fixed-width tables with fidelity markers and legend; render_markdown() outputs GitHub-flavored tables with | escaping and fidelity columns. render() dispatches by format. Both handle empty timelines with dedicated messaging.
Timeline renderer comprehensive test suite
tests/unit/insights/test_timeline_renderer.py
291 lines validating fidelity-tag invariants, chronological/untimed ordering, fidelity_counts aggregation, plain-text/Markdown rendering with markers and escaping, JSON serialization, and frozen dataclass immutability.
CLI timeline command & documentation
polylogue/cli/commands/insights.py, docs/cli-reference.md, docs/plans/topology-target.yaml, docs/test-quality-workflows.md, docs/topology-status.md, docs/verification-catalog.md, tests/unit/cli/test_insights.py
insights_timeline_command() fetches work events and phases from env.operations, dispatches rendering format (JSON, Markdown, or plain), and catches ArchiveInsightUnavailableError. Two CLI tests verify JSON output includes fidelity tags and plain output includes legend. Documentation metadata (topology, verification catalog, test quality) incremented to reflect new module and CLI command.

🎯 3 (Moderate) | ⏱️ ~25 minutes

area:cli, type:test, area:qa

🐰 Timeline threads now weave through session logs,
Hook-precise moments marked in fidelity tags,
Sort-keys fill the gaps with gentle reconstruction—
A bunny's patchwork quilt of what was said.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/insights-timeline-renderer-v2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Sinity
Sinity merged commit c7fc08a into master May 17, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the feature/feat/insights-timeline-renderer-v2 branch May 17, 2026 09:31

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0730ed74ac

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread polylogue/insights/timeline_renderer.py Resolved
@Sinity

Sinity commented Sep 30, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

Only the rows listed above are dispositioned. Held findings remain open.

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.

feat(insights): session timeline renderer with provenance and hook-vs-sortkey distinction

1 participant